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.

252118 lines
6.3MB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-9 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #ifdef __JUCE_JUCEHEADER__
  19. #error
  20. #endif
  21. /*** Start of inlined file: juce_TargetPlatform.h ***/
  22. #ifndef __JUCE_TARGETPLATFORM_JUCEHEADER__
  23. #define __JUCE_TARGETPLATFORM_JUCEHEADER__
  24. #if (defined (_WIN32) || defined (_WIN64))
  25. #define JUCE_WIN32 1
  26. #define JUCE_WINDOWS 1
  27. #elif defined (LINUX) || defined (__linux__)
  28. #define JUCE_LINUX 1
  29. #elif defined(__APPLE_CPP__) || defined(__APPLE_CC__)
  30. #include <CoreFoundation/CoreFoundation.h> // (needed to find out what platform we're using)
  31. #if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR
  32. #define JUCE_IPHONE 1
  33. #else
  34. #define JUCE_MAC 1
  35. #endif
  36. #else
  37. #error "Unknown platform!"
  38. #endif
  39. #if JUCE_WINDOWS
  40. #ifdef _MSC_VER
  41. #ifdef _WIN64
  42. #define JUCE_64BIT 1
  43. #else
  44. #define JUCE_32BIT 1
  45. #endif
  46. #endif
  47. #ifdef _DEBUG
  48. #define JUCE_DEBUG 1
  49. #endif
  50. #ifdef __MINGW32__
  51. #define JUCE_MINGW 1
  52. #endif
  53. #define JUCE_LITTLE_ENDIAN 1
  54. #define JUCE_INTEL 1
  55. #endif
  56. #if JUCE_MAC
  57. #ifndef NDEBUG
  58. #define JUCE_DEBUG 1
  59. #endif
  60. #ifdef __LITTLE_ENDIAN__
  61. #define JUCE_LITTLE_ENDIAN 1
  62. #else
  63. #define JUCE_BIG_ENDIAN 1
  64. #endif
  65. #if defined (__ppc__) || defined (__ppc64__)
  66. #define JUCE_PPC 1
  67. #undef MAC_OS_X_VERSION_MAX_ALLOWED
  68. #define MAC_OS_X_VERSION_MAX_ALLOWED MAC_OS_X_VERSION_10_4
  69. #else
  70. #define JUCE_INTEL 1
  71. #endif
  72. #ifdef __LP64__
  73. #define JUCE_64BIT 1
  74. #else
  75. #define JUCE_32BIT 1
  76. #endif
  77. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_4
  78. #error "Building for OSX 10.3 is no longer supported!"
  79. #endif
  80. #ifndef MAC_OS_X_VERSION_10_5
  81. #error "To build with 10.4 compatibility, use a 10.5 or 10.6 SDK and set the deployment target to 10.4"
  82. #endif
  83. #endif
  84. #if JUCE_IPHONE
  85. #ifndef NDEBUG
  86. #define JUCE_DEBUG 1
  87. #endif
  88. #ifdef __LITTLE_ENDIAN__
  89. #define JUCE_LITTLE_ENDIAN 1
  90. #else
  91. #define JUCE_BIG_ENDIAN 1
  92. #endif
  93. #endif
  94. #if JUCE_LINUX
  95. #ifdef _DEBUG
  96. #define JUCE_DEBUG 1
  97. #endif
  98. // Allow override for big-endian Linux platforms
  99. #ifndef JUCE_BIG_ENDIAN
  100. #define JUCE_LITTLE_ENDIAN 1
  101. #endif
  102. #if defined (__LP64__) || defined (_LP64)
  103. #define JUCE_64BIT 1
  104. #else
  105. #define JUCE_32BIT 1
  106. #endif
  107. #define JUCE_INTEL 1
  108. #endif
  109. // Compiler type macros.
  110. #ifdef __GNUC__
  111. #define JUCE_GCC 1
  112. #elif defined (_MSC_VER)
  113. #define JUCE_MSVC 1
  114. #if _MSC_VER >= 1400
  115. #define JUCE_USE_INTRINSICS 1
  116. #endif
  117. #else
  118. #error unknown compiler
  119. #endif
  120. #endif // __JUCE_TARGETPLATFORM_JUCEHEADER__
  121. /*** End of inlined file: juce_TargetPlatform.h ***/
  122. // FORCE_AMALGAMATOR_INCLUDE
  123. /*** Start of inlined file: juce_Config.h ***/
  124. #ifndef __JUCE_CONFIG_JUCEHEADER__
  125. #define __JUCE_CONFIG_JUCEHEADER__
  126. #ifndef JUCE_NAMESPACE
  127. #define JUCE_NAMESPACE juce
  128. #endif
  129. #ifndef JUCE_FORCE_DEBUG
  130. //#define JUCE_FORCE_DEBUG 1
  131. #endif
  132. #ifndef JUCE_LOG_ASSERTIONS
  133. // #define JUCE_LOG_ASSERTIONS 1
  134. #endif
  135. #ifndef JUCE_ASIO
  136. #define JUCE_ASIO 1
  137. #endif
  138. #ifndef JUCE_WASAPI
  139. // #define JUCE_WASAPI 1
  140. #endif
  141. #ifndef JUCE_DIRECTSOUND
  142. #define JUCE_DIRECTSOUND 1
  143. #endif
  144. #ifndef JUCE_ALSA
  145. #define JUCE_ALSA 1
  146. #endif
  147. #ifndef JUCE_JACK
  148. #define JUCE_JACK 1
  149. #endif
  150. #if ! (defined (JUCE_QUICKTIME) || JUCE_LINUX || JUCE_IPHONE || (JUCE_WINDOWS && ! JUCE_MSVC))
  151. #define JUCE_QUICKTIME 1
  152. #endif
  153. #ifndef JUCE_OPENGL
  154. #define JUCE_OPENGL 1
  155. #endif
  156. #ifndef JUCE_USE_FLAC
  157. #define JUCE_USE_FLAC 1
  158. #endif
  159. #ifndef JUCE_USE_OGGVORBIS
  160. #define JUCE_USE_OGGVORBIS 1
  161. #endif
  162. #if (! defined (JUCE_USE_CDBURNER)) && ! (JUCE_WINDOWS && ! JUCE_MSVC)
  163. #define JUCE_USE_CDBURNER 1
  164. #endif
  165. #ifndef JUCE_USE_CDREADER
  166. #define JUCE_USE_CDREADER 1
  167. #endif
  168. #if JUCE_QUICKTIME && ! defined (JUCE_USE_CAMERA)
  169. // #define JUCE_USE_CAMERA 1
  170. #endif
  171. #ifndef JUCE_ENABLE_REPAINT_DEBUGGING
  172. // #define JUCE_ENABLE_REPAINT_DEBUGGING 1
  173. #endif
  174. #ifndef JUCE_USE_XINERAMA
  175. #define JUCE_USE_XINERAMA 1
  176. #endif
  177. #ifndef JUCE_USE_XSHM
  178. #define JUCE_USE_XSHM 1
  179. #endif
  180. #ifndef JUCE_PLUGINHOST_VST
  181. // #define JUCE_PLUGINHOST_VST 1
  182. #endif
  183. #ifndef JUCE_PLUGINHOST_AU
  184. // #define JUCE_PLUGINHOST_AU 1
  185. #endif
  186. #ifndef JUCE_ONLY_BUILD_CORE_LIBRARY
  187. //#define JUCE_ONLY_BUILD_CORE_LIBRARY 1
  188. #endif
  189. #ifndef JUCE_WEB_BROWSER
  190. #define JUCE_WEB_BROWSER 1
  191. #endif
  192. #ifndef JUCE_SUPPORT_CARBON
  193. #define JUCE_SUPPORT_CARBON 1
  194. #endif
  195. #ifndef JUCE_INCLUDE_ZLIB_CODE
  196. #define JUCE_INCLUDE_ZLIB_CODE 1
  197. #endif
  198. #ifndef JUCE_INCLUDE_FLAC_CODE
  199. #define JUCE_INCLUDE_FLAC_CODE 1
  200. #endif
  201. #ifndef JUCE_INCLUDE_OGGVORBIS_CODE
  202. #define JUCE_INCLUDE_OGGVORBIS_CODE 1
  203. #endif
  204. #ifndef JUCE_INCLUDE_PNGLIB_CODE
  205. #define JUCE_INCLUDE_PNGLIB_CODE 1
  206. #endif
  207. #ifndef JUCE_INCLUDE_JPEGLIB_CODE
  208. #define JUCE_INCLUDE_JPEGLIB_CODE 1
  209. #endif
  210. #ifndef JUCE_CHECK_MEMORY_LEAKS
  211. #define JUCE_CHECK_MEMORY_LEAKS 1
  212. #endif
  213. #ifndef JUCE_CATCH_UNHANDLED_EXCEPTIONS
  214. #define JUCE_CATCH_UNHANDLED_EXCEPTIONS 1
  215. #endif
  216. #ifndef JUCE_STRINGS_ARE_UNICODE
  217. #define JUCE_STRINGS_ARE_UNICODE 1
  218. #endif
  219. // If only building the core classes, we can explicitly turn off some features to avoid including them:
  220. #if JUCE_ONLY_BUILD_CORE_LIBRARY
  221. #undef JUCE_QUICKTIME
  222. #define JUCE_QUICKTIME 0
  223. #undef JUCE_OPENGL
  224. #define JUCE_OPENGL 0
  225. #undef JUCE_USE_CDBURNER
  226. #define JUCE_USE_CDBURNER 0
  227. #undef JUCE_USE_CDREADER
  228. #define JUCE_USE_CDREADER 0
  229. #undef JUCE_WEB_BROWSER
  230. #define JUCE_WEB_BROWSER 0
  231. #undef JUCE_PLUGINHOST_AU
  232. #define JUCE_PLUGINHOST_AU 0
  233. #undef JUCE_PLUGINHOST_VST
  234. #define JUCE_PLUGINHOST_VST 0
  235. #endif
  236. #endif
  237. /*** End of inlined file: juce_Config.h ***/
  238. // FORCE_AMALGAMATOR_INCLUDE
  239. #ifndef JUCE_BUILD_CORE
  240. #define JUCE_BUILD_CORE 1
  241. #endif
  242. #ifndef JUCE_BUILD_MISC
  243. #define JUCE_BUILD_MISC 1
  244. #endif
  245. #ifndef JUCE_BUILD_GUI
  246. #define JUCE_BUILD_GUI 1
  247. #endif
  248. #ifndef JUCE_BUILD_NATIVE
  249. #define JUCE_BUILD_NATIVE 1
  250. #endif
  251. #if JUCE_ONLY_BUILD_CORE_LIBRARY
  252. #undef JUCE_BUILD_MISC
  253. #undef JUCE_BUILD_GUI
  254. #endif
  255. //==============================================================================
  256. #if JUCE_BUILD_NATIVE || JUCE_BUILD_CORE
  257. #if JUCE_WINDOWS
  258. /*** Start of inlined file: juce_win32_NativeIncludes.h ***/
  259. #ifndef __JUCE_WIN32_NATIVEINCLUDES_JUCEHEADER__
  260. #define __JUCE_WIN32_NATIVEINCLUDES_JUCEHEADER__
  261. #ifndef STRICT
  262. #define STRICT 1
  263. #endif
  264. #undef WIN32_LEAN_AND_MEAN
  265. #define WIN32_LEAN_AND_MEAN 1
  266. #ifdef _MSC_VER
  267. #pragma warning (push)
  268. #pragma warning (disable : 4100 4201 4514 4312 4995)
  269. #endif
  270. #define _WIN32_WINNT 0x0500
  271. #define _UNICODE 1
  272. #define UNICODE 1
  273. #ifndef _WIN32_IE
  274. #define _WIN32_IE 0x0400
  275. #endif
  276. #include <windows.h>
  277. #include <windowsx.h>
  278. #include <commdlg.h>
  279. #include <shellapi.h>
  280. #include <mmsystem.h>
  281. #include <vfw.h>
  282. #include <tchar.h>
  283. #include <stddef.h>
  284. #include <ctime>
  285. #include <wininet.h>
  286. #include <nb30.h>
  287. #include <iphlpapi.h>
  288. #include <mapi.h>
  289. #include <float.h>
  290. #include <process.h>
  291. #include <Exdisp.h>
  292. #include <exdispid.h>
  293. #include <shlobj.h>
  294. #if ! JUCE_MINGW
  295. #include <crtdbg.h>
  296. #include <comutil.h>
  297. #endif
  298. #if JUCE_OPENGL
  299. #include <gl/gl.h>
  300. #endif
  301. #undef PACKED
  302. #if JUCE_ASIO
  303. #include "iasiodrv.h"
  304. #endif
  305. #if JUCE_USE_CDBURNER
  306. #include <imapi.h>
  307. #include <imapierror.h>
  308. #endif
  309. #if JUCE_USE_CAMERA
  310. #include <dshow.h>
  311. #include <qedit.h>
  312. #endif
  313. #if JUCE_WASAPI
  314. #include <MMReg.h>
  315. #include <mmdeviceapi.h>
  316. #include <Audioclient.h>
  317. #include <Avrt.h>
  318. #include <functiondiscoverykeys.h>
  319. #endif
  320. #if JUCE_QUICKTIME
  321. #include <Movies.h>
  322. #include <QTML.h>
  323. #include <QuickTimeComponents.h>
  324. #include <MediaHandlers.h>
  325. #include <ImageCodec.h>
  326. #import <QTOLibrary.dll>
  327. #import <QTOControl.dll>
  328. #endif
  329. #ifdef _MSC_VER
  330. #pragma warning (pop)
  331. #endif
  332. template <class T>
  333. class ComSmartPtr
  334. {
  335. public:
  336. ComSmartPtr() throw() : p (0) {}
  337. ComSmartPtr (T* const p_) : p (p_) { if (p_ != 0) p_->AddRef(); }
  338. ComSmartPtr (const ComSmartPtr<T>& p_) : p (p_.p) { if (p != 0) p->AddRef(); }
  339. ~ComSmartPtr() { if (p != 0) p->Release(); }
  340. operator T*() const throw() { return p; }
  341. T& operator*() const throw() { return *p; }
  342. T** operator&() throw() { return &p; }
  343. T* operator->() const throw() { return p; }
  344. T* operator= (T* const newP)
  345. {
  346. if (newP != 0)
  347. newP->AddRef();
  348. if (p != 0)
  349. p->Release();
  350. p = newP;
  351. return newP;
  352. }
  353. T* operator= (const ComSmartPtr<T>& newP) { return operator= (newP.p); }
  354. HRESULT CoCreateInstance (REFCLSID rclsid, DWORD dwClsContext)
  355. {
  356. #ifndef __MINGW32__
  357. operator= (0);
  358. return ::CoCreateInstance (rclsid, 0, dwClsContext, __uuidof(T), (void**) &p);
  359. #else
  360. return S_FALSE;
  361. #endif
  362. }
  363. T* p;
  364. };
  365. #endif // __JUCE_WIN32_NATIVEINCLUDES_JUCEHEADER__
  366. /*** End of inlined file: juce_win32_NativeIncludes.h ***/
  367. #elif JUCE_LINUX
  368. /*** Start of inlined file: juce_linux_NativeIncludes.h ***/
  369. #ifndef __JUCE_LINUX_NATIVEINCLUDES_JUCEHEADER__
  370. #define __JUCE_LINUX_NATIVEINCLUDES_JUCEHEADER__
  371. #include <sched.h>
  372. #include <pthread.h>
  373. #include <sys/time.h>
  374. #include <errno.h>
  375. #include <sys/stat.h>
  376. #include <sys/dir.h>
  377. #include <sys/ptrace.h>
  378. #include <sys/vfs.h>
  379. #include <sys/wait.h>
  380. #include <fnmatch.h>
  381. #include <utime.h>
  382. #include <pwd.h>
  383. #include <fcntl.h>
  384. #include <dlfcn.h>
  385. #include <netdb.h>
  386. #include <arpa/inet.h>
  387. #include <netinet/in.h>
  388. #include <sys/types.h>
  389. #include <sys/ioctl.h>
  390. #include <sys/socket.h>
  391. #include <linux/if.h>
  392. #include <sys/sysinfo.h>
  393. #include <sys/file.h>
  394. #include <signal.h>
  395. #include <ft2build.h>
  396. #include FT_FREETYPE_H
  397. #include <X11/Xlib.h>
  398. #include <X11/Xatom.h>
  399. #include <X11/Xresource.h>
  400. #include <X11/Xutil.h>
  401. #include <X11/Xmd.h>
  402. #include <X11/keysym.h>
  403. #include <X11/cursorfont.h>
  404. #if JUCE_USE_XINERAMA
  405. #include <X11/extensions/Xinerama.h>
  406. #endif
  407. #if JUCE_USE_XSHM
  408. #include <X11/extensions/XShm.h>
  409. #include <sys/shm.h>
  410. #include <sys/ipc.h>
  411. #endif
  412. #if JUCE_OPENGL
  413. #include <GL/glx.h>
  414. #endif
  415. #undef KeyPress
  416. #if JUCE_ALSA
  417. #include <alsa/asoundlib.h>
  418. #endif
  419. #if JUCE_JACK
  420. #include <jack/jack.h>
  421. //#include <jack/transport.h>
  422. #endif
  423. #undef SIZEOF
  424. #endif // __JUCE_LINUX_NATIVEINCLUDES_JUCEHEADER__
  425. /*** End of inlined file: juce_linux_NativeIncludes.h ***/
  426. #elif JUCE_MAC || JUCE_IPHONE
  427. /*** Start of inlined file: juce_mac_NativeIncludes.h ***/
  428. #ifndef __JUCE_MAC_NATIVEINCLUDES_JUCEHEADER__
  429. #define __JUCE_MAC_NATIVEINCLUDES_JUCEHEADER__
  430. #define USE_COREGRAPHICS_RENDERING 1
  431. #if JUCE_IPHONE
  432. #import <Foundation/Foundation.h>
  433. #import <UIKit/UIKit.h>
  434. #import <AudioToolbox/AudioToolbox.h>
  435. #import <AVFoundation/AVFoundation.h>
  436. #import <CoreData/CoreData.h>
  437. #import <MobileCoreServices/MobileCoreServices.h>
  438. #include <sys/fcntl.h>
  439. #else
  440. #import <Cocoa/Cocoa.h>
  441. #import <CoreAudio/HostTime.h>
  442. #import <CoreAudio/AudioHardware.h>
  443. #import <CoreMIDI/MIDIServices.h>
  444. #import <QTKit/QTKit.h>
  445. #import <WebKit/WebKit.h>
  446. #import <DiscRecording/DiscRecording.h>
  447. #import <IOKit/IOKitLib.h>
  448. #import <IOKit/IOCFPlugIn.h>
  449. #import <IOKit/hid/IOHIDLib.h>
  450. #import <IOKit/hid/IOHIDKeys.h>
  451. #import <IOKit/pwr_mgt/IOPMLib.h>
  452. #include <Carbon/Carbon.h>
  453. #include <sys/dir.h>
  454. #include <sys/socket.h>
  455. #endif
  456. #include <sys/sysctl.h>
  457. #include <sys/stat.h>
  458. #include <sys/param.h>
  459. #include <sys/mount.h>
  460. #include <fnmatch.h>
  461. #include <utime.h>
  462. #include <dlfcn.h>
  463. #include <ifaddrs.h>
  464. #include <net/if_dl.h>
  465. #include <mach/mach_time.h>
  466. #if MACOS_10_4_OR_EARLIER
  467. #include <GLUT/glut.h>
  468. #endif
  469. #if ! CGFLOAT_DEFINED
  470. #define CGFloat float
  471. #endif
  472. #endif // __JUCE_MAC_NATIVEINCLUDES_JUCEHEADER__
  473. /*** End of inlined file: juce_mac_NativeIncludes.h ***/
  474. #else
  475. #error "Unknown platform!"
  476. #endif
  477. #endif
  478. //==============================================================================
  479. #define DONT_SET_USING_JUCE_NAMESPACE 1
  480. #undef max
  481. #undef min
  482. #define NO_DUMMY_DECL
  483. #if JUCE_BUILD_NATIVE
  484. #include "juce_amalgamated.h" // FORCE_AMALGAMATOR_INCLUDE
  485. #endif
  486. #if (defined(_MSC_VER) && (_MSC_VER <= 1200))
  487. #pragma warning (disable: 4309 4305)
  488. #endif
  489. #if JUCE_MAC && JUCE_32BIT && JUCE_SUPPORT_CARBON && JUCE_BUILD_NATIVE && ! JUCE_ONLY_BUILD_CORE_LIBRARY
  490. BEGIN_JUCE_NAMESPACE
  491. /*** Start of inlined file: juce_mac_CarbonViewWrapperComponent.h ***/
  492. #ifndef __JUCE_MAC_CARBONVIEWWRAPPERCOMPONENT_JUCEHEADER__
  493. #define __JUCE_MAC_CARBONVIEWWRAPPERCOMPONENT_JUCEHEADER__
  494. class CarbonViewWrapperComponent : public Component,
  495. public ComponentMovementWatcher,
  496. public Timer
  497. {
  498. public:
  499. CarbonViewWrapperComponent()
  500. : ComponentMovementWatcher (this),
  501. wrapperWindow (0),
  502. embeddedView (0),
  503. recursiveResize (false)
  504. {
  505. }
  506. virtual ~CarbonViewWrapperComponent()
  507. {
  508. jassert (embeddedView == 0); // must call deleteWindow() in the subclass's destructor!
  509. }
  510. virtual HIViewRef attachView (WindowRef windowRef, HIViewRef rootView) = 0;
  511. virtual void removeView (HIViewRef embeddedView) = 0;
  512. virtual void mouseDown (int x, int y) {}
  513. virtual void paint() {}
  514. virtual bool getEmbeddedViewSize (int& w, int& h)
  515. {
  516. if (embeddedView == 0)
  517. return false;
  518. HIRect bounds;
  519. HIViewGetBounds (embeddedView, &bounds);
  520. w = jmax (1, roundToInt (bounds.size.width));
  521. h = jmax (1, roundToInt (bounds.size.height));
  522. return true;
  523. }
  524. void createWindow()
  525. {
  526. if (wrapperWindow == 0)
  527. {
  528. Rect r;
  529. r.left = getScreenX();
  530. r.top = getScreenY();
  531. r.right = r.left + getWidth();
  532. r.bottom = r.top + getHeight();
  533. CreateNewWindow (kDocumentWindowClass,
  534. (WindowAttributes) (kWindowStandardHandlerAttribute | kWindowCompositingAttribute
  535. | kWindowNoShadowAttribute | kWindowNoTitleBarAttribute),
  536. &r, &wrapperWindow);
  537. jassert (wrapperWindow != 0);
  538. if (wrapperWindow == 0)
  539. return;
  540. NSWindow* carbonWindow = [[NSWindow alloc] initWithWindowRef: wrapperWindow];
  541. NSWindow* ownerWindow = [((NSView*) getWindowHandle()) window];
  542. [ownerWindow addChildWindow: carbonWindow
  543. ordered: NSWindowAbove];
  544. embeddedView = attachView (wrapperWindow, HIViewGetRoot (wrapperWindow));
  545. EventTypeSpec windowEventTypes[] = { { kEventClassWindow, kEventWindowGetClickActivation },
  546. { kEventClassWindow, kEventWindowHandleDeactivate } };
  547. EventHandlerUPP upp = NewEventHandlerUPP (carbonEventCallback);
  548. InstallWindowEventHandler (wrapperWindow, upp,
  549. sizeof (windowEventTypes) / sizeof (EventTypeSpec),
  550. windowEventTypes, this, &eventHandlerRef);
  551. setOurSizeToEmbeddedViewSize();
  552. setEmbeddedWindowToOurSize();
  553. creationTime = Time::getCurrentTime();
  554. }
  555. }
  556. void deleteWindow()
  557. {
  558. removeView (embeddedView);
  559. embeddedView = 0;
  560. if (wrapperWindow != 0)
  561. {
  562. RemoveEventHandler (eventHandlerRef);
  563. DisposeWindow (wrapperWindow);
  564. wrapperWindow = 0;
  565. }
  566. }
  567. void setOurSizeToEmbeddedViewSize()
  568. {
  569. int w, h;
  570. if (getEmbeddedViewSize (w, h))
  571. {
  572. if (w != getWidth() || h != getHeight())
  573. {
  574. startTimer (50);
  575. setSize (w, h);
  576. if (getParentComponent() != 0)
  577. getParentComponent()->setSize (w, h);
  578. }
  579. else
  580. {
  581. startTimer (jlimit (50, 500, getTimerInterval() + 20));
  582. }
  583. }
  584. else
  585. {
  586. stopTimer();
  587. }
  588. }
  589. void setEmbeddedWindowToOurSize()
  590. {
  591. if (! recursiveResize)
  592. {
  593. recursiveResize = true;
  594. if (embeddedView != 0)
  595. {
  596. HIRect r;
  597. r.origin.x = 0;
  598. r.origin.y = 0;
  599. r.size.width = (float) getWidth();
  600. r.size.height = (float) getHeight();
  601. HIViewSetFrame (embeddedView, &r);
  602. }
  603. if (wrapperWindow != 0)
  604. {
  605. Rect wr;
  606. wr.left = getScreenX();
  607. wr.top = getScreenY();
  608. wr.right = wr.left + getWidth();
  609. wr.bottom = wr.top + getHeight();
  610. SetWindowBounds (wrapperWindow, kWindowContentRgn, &wr);
  611. ShowWindow (wrapperWindow);
  612. }
  613. recursiveResize = false;
  614. }
  615. }
  616. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  617. {
  618. setEmbeddedWindowToOurSize();
  619. }
  620. void componentPeerChanged()
  621. {
  622. deleteWindow();
  623. createWindow();
  624. }
  625. void componentVisibilityChanged (Component&)
  626. {
  627. if (isShowing())
  628. createWindow();
  629. else
  630. deleteWindow();
  631. setEmbeddedWindowToOurSize();
  632. }
  633. static void recursiveHIViewRepaint (HIViewRef view)
  634. {
  635. HIViewSetNeedsDisplay (view, true);
  636. HIViewRef child = HIViewGetFirstSubview (view);
  637. while (child != 0)
  638. {
  639. recursiveHIViewRepaint (child);
  640. child = HIViewGetNextView (child);
  641. }
  642. }
  643. void timerCallback()
  644. {
  645. setOurSizeToEmbeddedViewSize();
  646. // To avoid strange overpainting problems when the UI is first opened, we'll
  647. // repaint it a few times during the first second that it's on-screen..
  648. if ((Time::getCurrentTime() - creationTime).inMilliseconds() < 1000)
  649. recursiveHIViewRepaint (HIViewGetRoot (wrapperWindow));
  650. }
  651. OSStatus carbonEventHandler (EventHandlerCallRef nextHandlerRef,
  652. EventRef event)
  653. {
  654. switch (GetEventKind (event))
  655. {
  656. case kEventWindowHandleDeactivate:
  657. ActivateWindow (wrapperWindow, TRUE);
  658. break;
  659. case kEventWindowGetClickActivation:
  660. {
  661. getTopLevelComponent()->toFront (false);
  662. ClickActivationResult howToHandleClick = kActivateAndHandleClick;
  663. SetEventParameter (event, kEventParamClickActivation, typeClickActivationResult,
  664. sizeof (ClickActivationResult), &howToHandleClick);
  665. HIViewSetNeedsDisplay (embeddedView, true);
  666. }
  667. break;
  668. }
  669. return noErr;
  670. }
  671. static pascal OSStatus carbonEventCallback (EventHandlerCallRef nextHandlerRef,
  672. EventRef event, void* userData)
  673. {
  674. return ((CarbonViewWrapperComponent*) userData)->carbonEventHandler (nextHandlerRef, event);
  675. }
  676. protected:
  677. WindowRef wrapperWindow;
  678. HIViewRef embeddedView;
  679. bool recursiveResize;
  680. Time creationTime;
  681. EventHandlerRef eventHandlerRef;
  682. };
  683. #endif // __JUCE_MAC_CARBONVIEWWRAPPERCOMPONENT_JUCEHEADER__
  684. /*** End of inlined file: juce_mac_CarbonViewWrapperComponent.h ***/
  685. END_JUCE_NAMESPACE
  686. #endif
  687. #define JUCE_AMALGAMATED_TEMPLATE 1
  688. //==============================================================================
  689. #if JUCE_BUILD_CORE
  690. /*** Start of inlined file: juce_FileLogger.cpp ***/
  691. BEGIN_JUCE_NAMESPACE
  692. FileLogger::FileLogger (const File& logFile_,
  693. const String& welcomeMessage,
  694. const int maxInitialFileSizeBytes)
  695. : logFile (logFile_)
  696. {
  697. if (maxInitialFileSizeBytes >= 0)
  698. trimFileSize (maxInitialFileSizeBytes);
  699. if (! logFile_.exists())
  700. {
  701. // do this so that the parent directories get created..
  702. logFile_.create();
  703. }
  704. logStream = logFile_.createOutputStream (256);
  705. jassert (logStream != 0);
  706. String welcome;
  707. welcome << "\r\n**********************************************************\r\n"
  708. << welcomeMessage
  709. << "\r\nLog started: " << Time::getCurrentTime().toString (true, true)
  710. << "\r\n";
  711. logMessage (welcome);
  712. }
  713. FileLogger::~FileLogger()
  714. {
  715. }
  716. void FileLogger::logMessage (const String& message)
  717. {
  718. if (logStream != 0)
  719. {
  720. DBG (message);
  721. const ScopedLock sl (logLock);
  722. (*logStream) << message << T("\r\n");
  723. logStream->flush();
  724. }
  725. }
  726. void FileLogger::trimFileSize (int maxFileSizeBytes) const
  727. {
  728. if (maxFileSizeBytes <= 0)
  729. {
  730. logFile.deleteFile();
  731. }
  732. else
  733. {
  734. const int64 fileSize = logFile.getSize();
  735. if (fileSize > maxFileSizeBytes)
  736. {
  737. ScopedPointer <FileInputStream> in (logFile.createInputStream());
  738. jassert (in != 0);
  739. if (in != 0)
  740. {
  741. in->setPosition (fileSize - maxFileSizeBytes);
  742. String content;
  743. {
  744. MemoryBlock contentToSave;
  745. contentToSave.setSize (maxFileSizeBytes + 4);
  746. contentToSave.fillWith (0);
  747. in->read (contentToSave.getData(), maxFileSizeBytes);
  748. in = 0;
  749. content = contentToSave.toString();
  750. }
  751. int newStart = 0;
  752. while (newStart < fileSize
  753. && content[newStart] != '\n'
  754. && content[newStart] != '\r')
  755. ++newStart;
  756. logFile.deleteFile();
  757. logFile.appendText (content.substring (newStart), false, false);
  758. }
  759. }
  760. }
  761. }
  762. FileLogger* FileLogger::createDefaultAppLogger (const String& logFileSubDirectoryName,
  763. const String& logFileName,
  764. const String& welcomeMessage,
  765. const int maxInitialFileSizeBytes)
  766. {
  767. #if JUCE_MAC
  768. File logFile ("~/Library/Logs");
  769. logFile = logFile.getChildFile (logFileSubDirectoryName)
  770. .getChildFile (logFileName);
  771. #else
  772. File logFile (File::getSpecialLocation (File::userApplicationDataDirectory));
  773. if (logFile.isDirectory())
  774. {
  775. logFile = logFile.getChildFile (logFileSubDirectoryName)
  776. .getChildFile (logFileName);
  777. }
  778. #endif
  779. return new FileLogger (logFile, welcomeMessage, maxInitialFileSizeBytes);
  780. }
  781. END_JUCE_NAMESPACE
  782. /*** End of inlined file: juce_FileLogger.cpp ***/
  783. /*** Start of inlined file: juce_Logger.cpp ***/
  784. BEGIN_JUCE_NAMESPACE
  785. Logger::Logger()
  786. {
  787. }
  788. Logger::~Logger()
  789. {
  790. }
  791. static Logger* currentLogger = 0;
  792. void Logger::setCurrentLogger (Logger* const newLogger,
  793. const bool deleteOldLogger)
  794. {
  795. Logger* const oldLogger = currentLogger;
  796. currentLogger = newLogger;
  797. if (deleteOldLogger)
  798. delete oldLogger;
  799. }
  800. void Logger::writeToLog (const String& message)
  801. {
  802. if (currentLogger != 0)
  803. currentLogger->logMessage (message);
  804. else
  805. outputDebugString (message);
  806. }
  807. #if JUCE_LOG_ASSERTIONS
  808. void JUCE_API juce_LogAssertion (const char* filename, const int lineNum) throw()
  809. {
  810. String m ("JUCE Assertion failure in ");
  811. m << filename << ", line " << lineNum;
  812. Logger::writeToLog (m);
  813. }
  814. #endif
  815. END_JUCE_NAMESPACE
  816. /*** End of inlined file: juce_Logger.cpp ***/
  817. /*** Start of inlined file: juce_Random.cpp ***/
  818. BEGIN_JUCE_NAMESPACE
  819. Random::Random (const int64 seedValue) throw()
  820. : seed (seedValue)
  821. {
  822. }
  823. Random::~Random() throw()
  824. {
  825. }
  826. void Random::setSeed (const int64 newSeed) throw()
  827. {
  828. seed = newSeed;
  829. }
  830. void Random::setSeedRandomly()
  831. {
  832. seed ^= (int64) (pointer_sized_int) this;
  833. seed ^= nextInt64() ^ Time::getMillisecondCounter();
  834. seed ^= nextInt64() ^ Time::getHighResolutionTicks();
  835. seed ^= nextInt64() ^ Time::getHighResolutionTicksPerSecond();
  836. seed ^= nextInt64() ^ Time::currentTimeMillis();
  837. }
  838. int Random::nextInt() throw()
  839. {
  840. seed = (seed * literal64bit (0x5deece66d) + 11) & literal64bit (0xffffffffffff);
  841. return (int) (seed >> 16);
  842. }
  843. int Random::nextInt (const int maxValue) throw()
  844. {
  845. jassert (maxValue > 0);
  846. return (nextInt() & 0x7fffffff) % maxValue;
  847. }
  848. int64 Random::nextInt64() throw()
  849. {
  850. return (((int64) nextInt()) << 32) | (int64) (uint64) (uint32) nextInt();
  851. }
  852. bool Random::nextBool() throw()
  853. {
  854. return (nextInt() & 0x80000000) != 0;
  855. }
  856. float Random::nextFloat() throw()
  857. {
  858. return ((uint32) nextInt()) / (float) 0xffffffff;
  859. }
  860. double Random::nextDouble() throw()
  861. {
  862. return ((uint32) nextInt()) / (double) 0xffffffff;
  863. }
  864. const BitArray Random::nextLargeNumber (const BitArray& maximumValue) throw()
  865. {
  866. BitArray n;
  867. do
  868. {
  869. fillBitsRandomly (n, 0, maximumValue.getHighestBit() + 1);
  870. }
  871. while (n.compare (maximumValue) >= 0);
  872. return n;
  873. }
  874. void Random::fillBitsRandomly (BitArray& arrayToChange, int startBit, int numBits) throw()
  875. {
  876. arrayToChange.setBit (startBit + numBits - 1, true); // to force the array to pre-allocate space
  877. while ((startBit & 31) != 0 && numBits > 0)
  878. {
  879. arrayToChange.setBit (startBit++, nextBool());
  880. --numBits;
  881. }
  882. while (numBits >= 32)
  883. {
  884. arrayToChange.setBitRangeAsInt (startBit, 32, (unsigned int) nextInt());
  885. startBit += 32;
  886. numBits -= 32;
  887. }
  888. while (--numBits >= 0)
  889. arrayToChange.setBit (startBit + numBits, nextBool());
  890. }
  891. Random& Random::getSystemRandom() throw()
  892. {
  893. static Random sysRand (1);
  894. return sysRand;
  895. }
  896. END_JUCE_NAMESPACE
  897. /*** End of inlined file: juce_Random.cpp ***/
  898. /*** Start of inlined file: juce_RelativeTime.cpp ***/
  899. BEGIN_JUCE_NAMESPACE
  900. RelativeTime::RelativeTime (const double seconds_) throw()
  901. : seconds (seconds_)
  902. {
  903. }
  904. RelativeTime::RelativeTime (const RelativeTime& other) throw()
  905. : seconds (other.seconds)
  906. {
  907. }
  908. RelativeTime::~RelativeTime() throw()
  909. {
  910. }
  911. const RelativeTime RelativeTime::milliseconds (const int milliseconds) throw()
  912. {
  913. return RelativeTime (milliseconds * 0.001);
  914. }
  915. const RelativeTime RelativeTime::milliseconds (const int64 milliseconds) throw()
  916. {
  917. return RelativeTime (milliseconds * 0.001);
  918. }
  919. const RelativeTime RelativeTime::minutes (const double numberOfMinutes) throw()
  920. {
  921. return RelativeTime (numberOfMinutes * 60.0);
  922. }
  923. const RelativeTime RelativeTime::hours (const double numberOfHours) throw()
  924. {
  925. return RelativeTime (numberOfHours * (60.0 * 60.0));
  926. }
  927. const RelativeTime RelativeTime::days (const double numberOfDays) throw()
  928. {
  929. return RelativeTime (numberOfDays * (60.0 * 60.0 * 24.0));
  930. }
  931. const RelativeTime RelativeTime::weeks (const double numberOfWeeks) throw()
  932. {
  933. return RelativeTime (numberOfWeeks * (60.0 * 60.0 * 24.0 * 7.0));
  934. }
  935. int64 RelativeTime::inMilliseconds() const throw()
  936. {
  937. return (int64)(seconds * 1000.0);
  938. }
  939. double RelativeTime::inMinutes() const throw()
  940. {
  941. return seconds / 60.0;
  942. }
  943. double RelativeTime::inHours() const throw()
  944. {
  945. return seconds / (60.0 * 60.0);
  946. }
  947. double RelativeTime::inDays() const throw()
  948. {
  949. return seconds / (60.0 * 60.0 * 24.0);
  950. }
  951. double RelativeTime::inWeeks() const throw()
  952. {
  953. return seconds / (60.0 * 60.0 * 24.0 * 7.0);
  954. }
  955. const String RelativeTime::getDescription (const String& returnValueForZeroTime) const throw()
  956. {
  957. if (seconds < 0.001 && seconds > -0.001)
  958. return returnValueForZeroTime;
  959. String result;
  960. if (seconds < 0)
  961. result = T("-");
  962. int fieldsShown = 0;
  963. int n = abs ((int) inWeeks());
  964. if (n > 0)
  965. {
  966. result << n << ((n == 1) ? TRANS(" week ")
  967. : TRANS(" weeks "));
  968. ++fieldsShown;
  969. }
  970. n = abs ((int) inDays()) % 7;
  971. if (n > 0)
  972. {
  973. result << n << ((n == 1) ? TRANS(" day ")
  974. : TRANS(" days "));
  975. ++fieldsShown;
  976. }
  977. if (fieldsShown < 2)
  978. {
  979. n = abs ((int) inHours()) % 24;
  980. if (n > 0)
  981. {
  982. result << n << ((n == 1) ? TRANS(" hr ")
  983. : TRANS(" hrs "));
  984. ++fieldsShown;
  985. }
  986. if (fieldsShown < 2)
  987. {
  988. n = abs ((int) inMinutes()) % 60;
  989. if (n > 0)
  990. {
  991. result << n << ((n == 1) ? TRANS(" min ")
  992. : TRANS(" mins "));
  993. ++fieldsShown;
  994. }
  995. if (fieldsShown < 2)
  996. {
  997. n = abs ((int) inSeconds()) % 60;
  998. if (n > 0)
  999. {
  1000. result << n << ((n == 1) ? TRANS(" sec ")
  1001. : TRANS(" secs "));
  1002. ++fieldsShown;
  1003. }
  1004. if (fieldsShown < 1)
  1005. {
  1006. n = abs ((int) inMilliseconds()) % 1000;
  1007. if (n > 0)
  1008. {
  1009. result << n << TRANS(" ms");
  1010. ++fieldsShown;
  1011. }
  1012. }
  1013. }
  1014. }
  1015. }
  1016. return result.trimEnd();
  1017. }
  1018. const RelativeTime& RelativeTime::operator= (const RelativeTime& other) throw()
  1019. {
  1020. seconds = other.seconds;
  1021. return *this;
  1022. }
  1023. bool RelativeTime::operator== (const RelativeTime& other) const throw()
  1024. {
  1025. return seconds == other.seconds;
  1026. }
  1027. bool RelativeTime::operator!= (const RelativeTime& other) const throw()
  1028. {
  1029. return seconds != other.seconds;
  1030. }
  1031. bool RelativeTime::operator> (const RelativeTime& other) const throw()
  1032. {
  1033. return seconds > other.seconds;
  1034. }
  1035. bool RelativeTime::operator< (const RelativeTime& other) const throw()
  1036. {
  1037. return seconds < other.seconds;
  1038. }
  1039. bool RelativeTime::operator>= (const RelativeTime& other) const throw()
  1040. {
  1041. return seconds >= other.seconds;
  1042. }
  1043. bool RelativeTime::operator<= (const RelativeTime& other) const throw()
  1044. {
  1045. return seconds <= other.seconds;
  1046. }
  1047. const RelativeTime RelativeTime::operator+ (const RelativeTime& timeToAdd) const throw()
  1048. {
  1049. return RelativeTime (seconds + timeToAdd.seconds);
  1050. }
  1051. const RelativeTime RelativeTime::operator- (const RelativeTime& timeToSubtract) const throw()
  1052. {
  1053. return RelativeTime (seconds - timeToSubtract.seconds);
  1054. }
  1055. const RelativeTime RelativeTime::operator+ (const double secondsToAdd) const throw()
  1056. {
  1057. return RelativeTime (seconds + secondsToAdd);
  1058. }
  1059. const RelativeTime RelativeTime::operator- (const double secondsToSubtract) const throw()
  1060. {
  1061. return RelativeTime (seconds - secondsToSubtract);
  1062. }
  1063. const RelativeTime& RelativeTime::operator+= (const RelativeTime& timeToAdd) throw()
  1064. {
  1065. seconds += timeToAdd.seconds;
  1066. return *this;
  1067. }
  1068. const RelativeTime& RelativeTime::operator-= (const RelativeTime& timeToSubtract) throw()
  1069. {
  1070. seconds -= timeToSubtract.seconds;
  1071. return *this;
  1072. }
  1073. const RelativeTime& RelativeTime::operator+= (const double secondsToAdd) throw()
  1074. {
  1075. seconds += secondsToAdd;
  1076. return *this;
  1077. }
  1078. const RelativeTime& RelativeTime::operator-= (const double secondsToSubtract) throw()
  1079. {
  1080. seconds -= secondsToSubtract;
  1081. return *this;
  1082. }
  1083. END_JUCE_NAMESPACE
  1084. /*** End of inlined file: juce_RelativeTime.cpp ***/
  1085. /*** Start of inlined file: juce_SystemStats.cpp ***/
  1086. BEGIN_JUCE_NAMESPACE
  1087. void juce_initialiseStrings();
  1088. const String SystemStats::getJUCEVersion() throw()
  1089. {
  1090. return "JUCE v" + String (JUCE_MAJOR_VERSION) + "." + String (JUCE_MINOR_VERSION);
  1091. }
  1092. static bool juceInitialisedNonGUI = false;
  1093. void JUCE_PUBLIC_FUNCTION initialiseJuce_NonGUI()
  1094. {
  1095. if (! juceInitialisedNonGUI)
  1096. {
  1097. #if JUCE_MAC || JUCE_IPHONE
  1098. const ScopedAutoReleasePool pool;
  1099. #endif
  1100. #ifdef JUCE_DEBUG
  1101. {
  1102. // Some simple test code to keep an eye on things and make sure these functions
  1103. // work ok on all platforms. Let me know if any of these assertions fail!
  1104. static_jassert (sizeof (pointer_sized_int) == sizeof (void*));
  1105. char a1[7];
  1106. jassert (numElementsInArray(a1) == 7);
  1107. int a2[3];
  1108. jassert (numElementsInArray(a2) == 3);
  1109. int n = 1;
  1110. Atomic::increment (n);
  1111. jassert (Atomic::incrementAndReturn (n) == 3);
  1112. Atomic::decrement (n);
  1113. jassert (Atomic::decrementAndReturn (n) == 1);
  1114. jassert (ByteOrder::swap ((uint16) 0x1122) == 0x2211);
  1115. jassert (ByteOrder::swap ((uint32) 0x11223344) == 0x44332211);
  1116. // Some quick stream tests..
  1117. int randomInt = Random::getSystemRandom().nextInt();
  1118. int64 randomInt64 = Random::getSystemRandom().nextInt64();
  1119. double randomDouble = Random::getSystemRandom().nextDouble();
  1120. String randomString;
  1121. for (int i = 50; --i >= 0;)
  1122. randomString << (juce_wchar) (Random::getSystemRandom().nextInt() & 0xffff);
  1123. MemoryOutputStream mo;
  1124. mo.writeInt (randomInt);
  1125. mo.writeIntBigEndian (randomInt);
  1126. mo.writeCompressedInt (randomInt);
  1127. mo.writeString (randomString);
  1128. mo.writeInt64 (randomInt64);
  1129. mo.writeInt64BigEndian (randomInt64);
  1130. mo.writeDouble (randomDouble);
  1131. mo.writeDoubleBigEndian (randomDouble);
  1132. MemoryInputStream mi (mo.getData(), mo.getDataSize(), false);
  1133. jassert (mi.readInt() == randomInt);
  1134. jassert (mi.readIntBigEndian() == randomInt);
  1135. jassert (mi.readCompressedInt() == randomInt);
  1136. jassert (mi.readString() == randomString);
  1137. jassert (mi.readInt64() == randomInt64);
  1138. jassert (mi.readInt64BigEndian() == randomInt64);
  1139. jassert (mi.readDouble() == randomDouble);
  1140. jassert (mi.readDoubleBigEndian() == randomDouble);
  1141. }
  1142. #endif
  1143. // Now the real initialisation..
  1144. juceInitialisedNonGUI = true;
  1145. DBG (SystemStats::getJUCEVersion());
  1146. juce_initialiseStrings();
  1147. SystemStats::initialiseStats();
  1148. Random::getSystemRandom().setSeedRandomly(); // (mustn't call this before initialiseStats() because it relies on the time being set up)
  1149. }
  1150. }
  1151. #if JUCE_WINDOWS
  1152. // This is imported from the sockets code..
  1153. typedef int (__stdcall juce_CloseWin32SocketLibCall) (void);
  1154. extern juce_CloseWin32SocketLibCall* juce_CloseWin32SocketLib;
  1155. #endif
  1156. #if JUCE_DEBUG
  1157. extern void juce_CheckForDanglingStreams();
  1158. #endif
  1159. void JUCE_PUBLIC_FUNCTION shutdownJuce_NonGUI()
  1160. {
  1161. if (juceInitialisedNonGUI)
  1162. {
  1163. #if JUCE_MAC || JUCE_IPHONE
  1164. const ScopedAutoReleasePool pool;
  1165. #endif
  1166. #if JUCE_WINDOWS
  1167. // need to shut down sockets if they were used..
  1168. if (juce_CloseWin32SocketLib != 0)
  1169. (*juce_CloseWin32SocketLib)();
  1170. #endif
  1171. LocalisedStrings::setCurrentMappings (0);
  1172. Thread::stopAllThreads (3000);
  1173. #if JUCE_DEBUG
  1174. juce_CheckForDanglingStreams();
  1175. #endif
  1176. juceInitialisedNonGUI = false;
  1177. }
  1178. }
  1179. #ifdef JUCE_DLL
  1180. void* juce_Malloc (const int size)
  1181. {
  1182. return malloc (size);
  1183. }
  1184. void* juce_Calloc (const int size)
  1185. {
  1186. return calloc (1, size);
  1187. }
  1188. void* juce_Realloc (void* const block, const int size)
  1189. {
  1190. return realloc (block, size);
  1191. }
  1192. void juce_Free (void* const block)
  1193. {
  1194. free (block);
  1195. }
  1196. #if defined (JUCE_DEBUG) && JUCE_MSVC && JUCE_CHECK_MEMORY_LEAKS
  1197. void* juce_DebugMalloc (const int size, const char* file, const int line)
  1198. {
  1199. return _malloc_dbg (size, _NORMAL_BLOCK, file, line);
  1200. }
  1201. void* juce_DebugCalloc (const int size, const char* file, const int line)
  1202. {
  1203. return _calloc_dbg (1, size, _NORMAL_BLOCK, file, line);
  1204. }
  1205. void* juce_DebugRealloc (void* const block, const int size, const char* file, const int line)
  1206. {
  1207. return _realloc_dbg (block, size, _NORMAL_BLOCK, file, line);
  1208. }
  1209. void juce_DebugFree (void* const block)
  1210. {
  1211. _free_dbg (block, _NORMAL_BLOCK);
  1212. }
  1213. #endif
  1214. #endif
  1215. END_JUCE_NAMESPACE
  1216. /*** End of inlined file: juce_SystemStats.cpp ***/
  1217. /*** Start of inlined file: juce_Time.cpp ***/
  1218. #ifdef _MSC_VER
  1219. #pragma warning (disable: 4514)
  1220. #pragma warning (push)
  1221. #endif
  1222. #ifndef JUCE_WINDOWS
  1223. #include <sys/time.h>
  1224. #else
  1225. #include <ctime>
  1226. #endif
  1227. #include <sys/timeb.h>
  1228. BEGIN_JUCE_NAMESPACE
  1229. #ifdef _MSC_VER
  1230. #pragma warning (pop)
  1231. #ifdef _INC_TIME_INL
  1232. #define USE_NEW_SECURE_TIME_FNS
  1233. #endif
  1234. #endif
  1235. static void millisToLocal (const int64 millis, struct tm& result) throw()
  1236. {
  1237. const int64 seconds = millis / 1000;
  1238. if (seconds < literal64bit (86400) || seconds >= literal64bit (2145916800))
  1239. {
  1240. // use extended maths for dates beyond 1970 to 2037..
  1241. const int timeZoneAdjustment = 31536000 - (int) (Time (1971, 0, 1, 0, 0).toMilliseconds() / 1000);
  1242. const int64 jdm = seconds + timeZoneAdjustment + literal64bit (210866803200);
  1243. const int days = (int) (jdm / literal64bit (86400));
  1244. const int a = 32044 + days;
  1245. const int b = (4 * a + 3) / 146097;
  1246. const int c = a - (b * 146097) / 4;
  1247. const int d = (4 * c + 3) / 1461;
  1248. const int e = c - (d * 1461) / 4;
  1249. const int m = (5 * e + 2) / 153;
  1250. result.tm_mday = e - (153 * m + 2) / 5 + 1;
  1251. result.tm_mon = m + 2 - 12 * (m / 10);
  1252. result.tm_year = b * 100 + d - 6700 + (m / 10);
  1253. result.tm_wday = (days + 1) % 7;
  1254. result.tm_yday = -1;
  1255. int t = (int) (jdm % literal64bit (86400));
  1256. result.tm_hour = t / 3600;
  1257. t %= 3600;
  1258. result.tm_min = t / 60;
  1259. result.tm_sec = t % 60;
  1260. result.tm_isdst = -1;
  1261. }
  1262. else
  1263. {
  1264. time_t now = (time_t) (seconds);
  1265. #if JUCE_WINDOWS
  1266. #ifdef USE_NEW_SECURE_TIME_FNS
  1267. if (now >= 0 && now <= 0x793406fff)
  1268. localtime_s (&result, &now);
  1269. else
  1270. zeromem (&result, sizeof (result));
  1271. #else
  1272. result = *localtime (&now);
  1273. #endif
  1274. #else
  1275. // more thread-safe
  1276. localtime_r (&now, &result);
  1277. #endif
  1278. }
  1279. }
  1280. Time::Time() throw()
  1281. : millisSinceEpoch (0)
  1282. {
  1283. }
  1284. Time::Time (const Time& other) throw()
  1285. : millisSinceEpoch (other.millisSinceEpoch)
  1286. {
  1287. }
  1288. Time::Time (const int64 ms) throw()
  1289. : millisSinceEpoch (ms)
  1290. {
  1291. }
  1292. Time::Time (const int year,
  1293. const int month,
  1294. const int day,
  1295. const int hours,
  1296. const int minutes,
  1297. const int seconds,
  1298. const int milliseconds,
  1299. const bool useLocalTime) throw()
  1300. {
  1301. jassert (year > 100); // year must be a 4-digit version
  1302. if (year < 1971 || year >= 2038 || ! useLocalTime)
  1303. {
  1304. // use extended maths for dates beyond 1970 to 2037..
  1305. const int timeZoneAdjustment = useLocalTime ? (31536000 - (int) (Time (1971, 0, 1, 0, 0).toMilliseconds() / 1000))
  1306. : 0;
  1307. const int a = (13 - month) / 12;
  1308. const int y = year + 4800 - a;
  1309. const int jd = day + (153 * (month + 12 * a - 2) + 2) / 5
  1310. + (y * 365) + (y / 4) - (y / 100) + (y / 400)
  1311. - 32045;
  1312. const int64 s = ((int64) jd) * literal64bit (86400) - literal64bit (210866803200);
  1313. millisSinceEpoch = 1000 * (s + (hours * 3600 + minutes * 60 + seconds - timeZoneAdjustment))
  1314. + milliseconds;
  1315. }
  1316. else
  1317. {
  1318. struct tm t;
  1319. t.tm_year = year - 1900;
  1320. t.tm_mon = month;
  1321. t.tm_mday = day;
  1322. t.tm_hour = hours;
  1323. t.tm_min = minutes;
  1324. t.tm_sec = seconds;
  1325. t.tm_isdst = -1;
  1326. millisSinceEpoch = 1000 * (int64) mktime (&t);
  1327. if (millisSinceEpoch < 0)
  1328. millisSinceEpoch = 0;
  1329. else
  1330. millisSinceEpoch += milliseconds;
  1331. }
  1332. }
  1333. Time::~Time() throw()
  1334. {
  1335. }
  1336. const Time& Time::operator= (const Time& other) throw()
  1337. {
  1338. millisSinceEpoch = other.millisSinceEpoch;
  1339. return *this;
  1340. }
  1341. int64 Time::currentTimeMillis() throw()
  1342. {
  1343. static uint32 lastCounterResult = 0xffffffff;
  1344. static int64 correction = 0;
  1345. const uint32 now = getMillisecondCounter();
  1346. // check the counter hasn't wrapped (also triggered the first time this function is called)
  1347. if (now < lastCounterResult)
  1348. {
  1349. // double-check it's actually wrapped, in case multi-cpu machines have timers that drift a bit.
  1350. if (lastCounterResult == 0xffffffff || now < lastCounterResult - 10)
  1351. {
  1352. // get the time once using normal library calls, and store the difference needed to
  1353. // turn the millisecond counter into a real time.
  1354. #if JUCE_WINDOWS
  1355. struct _timeb t;
  1356. #ifdef USE_NEW_SECURE_TIME_FNS
  1357. _ftime_s (&t);
  1358. #else
  1359. _ftime (&t);
  1360. #endif
  1361. correction = (((int64) t.time) * 1000 + t.millitm) - now;
  1362. #else
  1363. struct timeval tv;
  1364. struct timezone tz;
  1365. gettimeofday (&tv, &tz);
  1366. correction = (((int64) tv.tv_sec) * 1000 + tv.tv_usec / 1000) - now;
  1367. #endif
  1368. }
  1369. }
  1370. lastCounterResult = now;
  1371. return correction + now;
  1372. }
  1373. uint32 juce_millisecondsSinceStartup() throw();
  1374. static uint32 lastMSCounterValue = 0;
  1375. uint32 Time::getMillisecondCounter() throw()
  1376. {
  1377. const uint32 now = juce_millisecondsSinceStartup();
  1378. if (now < lastMSCounterValue)
  1379. {
  1380. // in multi-threaded apps this might be called concurrently, so
  1381. // make sure that our last counter value only increases and doesn't
  1382. // go backwards..
  1383. if (now < lastMSCounterValue - 1000)
  1384. lastMSCounterValue = now;
  1385. }
  1386. else
  1387. {
  1388. lastMSCounterValue = now;
  1389. }
  1390. return now;
  1391. }
  1392. uint32 Time::getApproximateMillisecondCounter() throw()
  1393. {
  1394. jassert (lastMSCounterValue != 0);
  1395. return lastMSCounterValue;
  1396. }
  1397. void Time::waitForMillisecondCounter (const uint32 targetTime) throw()
  1398. {
  1399. for (;;)
  1400. {
  1401. const uint32 now = getMillisecondCounter();
  1402. if (now >= targetTime)
  1403. break;
  1404. const int toWait = targetTime - now;
  1405. if (toWait > 2)
  1406. {
  1407. Thread::sleep (jmin (20, toWait >> 1));
  1408. }
  1409. else
  1410. {
  1411. // xxx should consider using mutex_pause on the mac as it apparently
  1412. // makes it seem less like a spinlock and avoids lowering the thread pri.
  1413. for (int i = 10; --i >= 0;)
  1414. Thread::yield();
  1415. }
  1416. }
  1417. }
  1418. double Time::highResolutionTicksToSeconds (const int64 ticks) throw()
  1419. {
  1420. return ticks / (double) getHighResolutionTicksPerSecond();
  1421. }
  1422. int64 Time::secondsToHighResolutionTicks (const double seconds) throw()
  1423. {
  1424. return (int64) (seconds * (double) getHighResolutionTicksPerSecond());
  1425. }
  1426. const Time JUCE_CALLTYPE Time::getCurrentTime() throw()
  1427. {
  1428. return Time (currentTimeMillis());
  1429. }
  1430. const String Time::toString (const bool includeDate,
  1431. const bool includeTime,
  1432. const bool includeSeconds,
  1433. const bool use24HourClock) const throw()
  1434. {
  1435. String result;
  1436. if (includeDate)
  1437. {
  1438. result << getDayOfMonth() << ' '
  1439. << getMonthName (true) << ' '
  1440. << getYear();
  1441. if (includeTime)
  1442. result << ' ';
  1443. }
  1444. if (includeTime)
  1445. {
  1446. if (includeSeconds)
  1447. {
  1448. result += String::formatted (T("%d:%02d:%02d "),
  1449. (use24HourClock) ? getHours()
  1450. : getHoursInAmPmFormat(),
  1451. getMinutes(),
  1452. getSeconds());
  1453. }
  1454. else
  1455. {
  1456. result += String::formatted (T("%d.%02d"),
  1457. (use24HourClock) ? getHours()
  1458. : getHoursInAmPmFormat(),
  1459. getMinutes());
  1460. }
  1461. if (! use24HourClock)
  1462. result << (isAfternoon() ? "pm" : "am");
  1463. }
  1464. return result.trimEnd();
  1465. }
  1466. const String Time::formatted (const tchar* const format) const throw()
  1467. {
  1468. String buffer;
  1469. int bufferSize = 128;
  1470. buffer.preallocateStorage (bufferSize);
  1471. struct tm t;
  1472. millisToLocal (millisSinceEpoch, t);
  1473. while (CharacterFunctions::ftime ((tchar*) (const tchar*) buffer, bufferSize, format, &t) <= 0)
  1474. {
  1475. bufferSize += 128;
  1476. buffer.preallocateStorage (bufferSize);
  1477. }
  1478. return buffer;
  1479. }
  1480. int Time::getYear() const throw()
  1481. {
  1482. struct tm t;
  1483. millisToLocal (millisSinceEpoch, t);
  1484. return t.tm_year + 1900;
  1485. }
  1486. int Time::getMonth() const throw()
  1487. {
  1488. struct tm t;
  1489. millisToLocal (millisSinceEpoch, t);
  1490. return t.tm_mon;
  1491. }
  1492. int Time::getDayOfMonth() const throw()
  1493. {
  1494. struct tm t;
  1495. millisToLocal (millisSinceEpoch, t);
  1496. return t.tm_mday;
  1497. }
  1498. int Time::getDayOfWeek() const throw()
  1499. {
  1500. struct tm t;
  1501. millisToLocal (millisSinceEpoch, t);
  1502. return t.tm_wday;
  1503. }
  1504. int Time::getHours() const throw()
  1505. {
  1506. struct tm t;
  1507. millisToLocal (millisSinceEpoch, t);
  1508. return t.tm_hour;
  1509. }
  1510. int Time::getHoursInAmPmFormat() const throw()
  1511. {
  1512. const int hours = getHours();
  1513. if (hours == 0)
  1514. return 12;
  1515. else if (hours <= 12)
  1516. return hours;
  1517. else
  1518. return hours - 12;
  1519. }
  1520. bool Time::isAfternoon() const throw()
  1521. {
  1522. return getHours() >= 12;
  1523. }
  1524. static int extendedModulo (const int64 value, const int modulo) throw()
  1525. {
  1526. return (int) (value >= 0 ? (value % modulo)
  1527. : (value - ((value / modulo) + 1) * modulo));
  1528. }
  1529. int Time::getMinutes() const throw()
  1530. {
  1531. struct tm t;
  1532. millisToLocal (millisSinceEpoch, t);
  1533. return t.tm_min;
  1534. }
  1535. int Time::getSeconds() const throw()
  1536. {
  1537. return extendedModulo (millisSinceEpoch / 1000, 60);
  1538. }
  1539. int Time::getMilliseconds() const throw()
  1540. {
  1541. return extendedModulo (millisSinceEpoch, 1000);
  1542. }
  1543. bool Time::isDaylightSavingTime() const throw()
  1544. {
  1545. struct tm t;
  1546. millisToLocal (millisSinceEpoch, t);
  1547. return t.tm_isdst != 0;
  1548. }
  1549. const String Time::getTimeZone() const throw()
  1550. {
  1551. String zone[2];
  1552. #if JUCE_WINDOWS
  1553. _tzset();
  1554. #ifdef USE_NEW_SECURE_TIME_FNS
  1555. {
  1556. char name [128];
  1557. size_t length;
  1558. for (int i = 0; i < 2; ++i)
  1559. {
  1560. zeromem (name, sizeof (name));
  1561. _get_tzname (&length, name, 127, i);
  1562. zone[i] = name;
  1563. }
  1564. }
  1565. #else
  1566. const char** const zonePtr = (const char**) _tzname;
  1567. zone[0] = zonePtr[0];
  1568. zone[1] = zonePtr[1];
  1569. #endif
  1570. #else
  1571. tzset();
  1572. const char** const zonePtr = (const char**) tzname;
  1573. zone[0] = zonePtr[0];
  1574. zone[1] = zonePtr[1];
  1575. #endif
  1576. if (isDaylightSavingTime())
  1577. {
  1578. zone[0] = zone[1];
  1579. if (zone[0].length() > 3
  1580. && zone[0].containsIgnoreCase (T("daylight"))
  1581. && zone[0].contains (T("GMT")))
  1582. zone[0] = "BST";
  1583. }
  1584. return zone[0].substring (0, 3);
  1585. }
  1586. const String Time::getMonthName (const bool threeLetterVersion) const throw()
  1587. {
  1588. return getMonthName (getMonth(), threeLetterVersion);
  1589. }
  1590. const String Time::getWeekdayName (const bool threeLetterVersion) const throw()
  1591. {
  1592. return getWeekdayName (getDayOfWeek(), threeLetterVersion);
  1593. }
  1594. const String Time::getMonthName (int monthNumber,
  1595. const bool threeLetterVersion) throw()
  1596. {
  1597. const char* const shortMonthNames[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
  1598. const char* const longMonthNames[] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
  1599. monthNumber %= 12;
  1600. return TRANS (threeLetterVersion ? shortMonthNames [monthNumber]
  1601. : longMonthNames [monthNumber]);
  1602. }
  1603. const String Time::getWeekdayName (int day,
  1604. const bool threeLetterVersion) throw()
  1605. {
  1606. const char* const shortDayNames[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
  1607. const char* const longDayNames[] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };
  1608. day %= 7;
  1609. return TRANS (threeLetterVersion ? shortDayNames [day]
  1610. : longDayNames [day]);
  1611. }
  1612. END_JUCE_NAMESPACE
  1613. /*** End of inlined file: juce_Time.cpp ***/
  1614. /*** Start of inlined file: juce_BitArray.cpp ***/
  1615. BEGIN_JUCE_NAMESPACE
  1616. BitArray::BitArray() throw()
  1617. : numValues (4),
  1618. highestBit (-1),
  1619. negative (false)
  1620. {
  1621. values.calloc (numValues + 1);
  1622. }
  1623. BitArray::BitArray (const int value) throw()
  1624. : numValues (4),
  1625. highestBit (31),
  1626. negative (value < 0)
  1627. {
  1628. values.calloc (numValues + 1);
  1629. values[0] = abs (value);
  1630. highestBit = getHighestBit();
  1631. }
  1632. BitArray::BitArray (int64 value) throw()
  1633. : numValues (4),
  1634. highestBit (63),
  1635. negative (value < 0)
  1636. {
  1637. values.calloc (numValues + 1);
  1638. if (value < 0)
  1639. value = -value;
  1640. values[0] = (unsigned int) value;
  1641. values[1] = (unsigned int) (value >> 32);
  1642. highestBit = getHighestBit();
  1643. }
  1644. BitArray::BitArray (const unsigned int value) throw()
  1645. : numValues (4),
  1646. highestBit (31),
  1647. negative (false)
  1648. {
  1649. values.calloc (numValues + 1);
  1650. values[0] = value;
  1651. highestBit = getHighestBit();
  1652. }
  1653. BitArray::BitArray (const BitArray& other) throw()
  1654. : numValues (jmax (4, (other.highestBit >> 5) + 1)),
  1655. highestBit (other.getHighestBit()),
  1656. negative (other.negative)
  1657. {
  1658. values.malloc (numValues + 1);
  1659. memcpy (values, other.values, sizeof (unsigned int) * (numValues + 1));
  1660. }
  1661. BitArray::~BitArray() throw()
  1662. {
  1663. }
  1664. BitArray& BitArray::operator= (const BitArray& other) throw()
  1665. {
  1666. if (this != &other)
  1667. {
  1668. highestBit = other.getHighestBit();
  1669. numValues = jmax (4, (highestBit >> 5) + 1);
  1670. negative = other.negative;
  1671. values.malloc (numValues + 1);
  1672. memcpy (values, other.values, sizeof (unsigned int) * (numValues + 1));
  1673. }
  1674. return *this;
  1675. }
  1676. // result == 0 = the same
  1677. // result < 0 = this number is smaller
  1678. // result > 0 = this number is bigger
  1679. int BitArray::compare (const BitArray& other) const throw()
  1680. {
  1681. if (isNegative() == other.isNegative())
  1682. {
  1683. const int absComp = compareAbsolute (other);
  1684. return isNegative() ? -absComp : absComp;
  1685. }
  1686. else
  1687. {
  1688. return isNegative() ? -1 : 1;
  1689. }
  1690. }
  1691. int BitArray::compareAbsolute (const BitArray& other) const throw()
  1692. {
  1693. const int h1 = getHighestBit();
  1694. const int h2 = other.getHighestBit();
  1695. if (h1 > h2)
  1696. return 1;
  1697. else if (h1 < h2)
  1698. return -1;
  1699. for (int i = (h1 >> 5) + 1; --i >= 0;)
  1700. if (values[i] != other.values[i])
  1701. return (values[i] > other.values[i]) ? 1 : -1;
  1702. return 0;
  1703. }
  1704. bool BitArray::operator== (const BitArray& other) const throw()
  1705. {
  1706. return compare (other) == 0;
  1707. }
  1708. bool BitArray::operator!= (const BitArray& other) const throw()
  1709. {
  1710. return compare (other) != 0;
  1711. }
  1712. bool BitArray::operator[] (const int bit) const throw()
  1713. {
  1714. return bit >= 0 && bit <= highestBit
  1715. && ((values [bit >> 5] & (1 << (bit & 31))) != 0);
  1716. }
  1717. bool BitArray::isEmpty() const throw()
  1718. {
  1719. return getHighestBit() < 0;
  1720. }
  1721. void BitArray::clear() throw()
  1722. {
  1723. if (numValues > 16)
  1724. {
  1725. numValues = 4;
  1726. values.calloc (numValues + 1);
  1727. }
  1728. else
  1729. {
  1730. zeromem (values, sizeof (unsigned int) * (numValues + 1));
  1731. }
  1732. highestBit = -1;
  1733. negative = false;
  1734. }
  1735. void BitArray::setBit (const int bit) throw()
  1736. {
  1737. if (bit >= 0)
  1738. {
  1739. if (bit > highestBit)
  1740. {
  1741. ensureSize (bit >> 5);
  1742. highestBit = bit;
  1743. }
  1744. values [bit >> 5] |= (1 << (bit & 31));
  1745. }
  1746. }
  1747. void BitArray::setBit (const int bit,
  1748. const bool shouldBeSet) throw()
  1749. {
  1750. if (shouldBeSet)
  1751. setBit (bit);
  1752. else
  1753. clearBit (bit);
  1754. }
  1755. void BitArray::clearBit (const int bit) throw()
  1756. {
  1757. if (bit >= 0 && bit <= highestBit)
  1758. values [bit >> 5] &= ~(1 << (bit & 31));
  1759. }
  1760. void BitArray::setRange (int startBit,
  1761. int numBits,
  1762. const bool shouldBeSet) throw()
  1763. {
  1764. while (--numBits >= 0)
  1765. setBit (startBit++, shouldBeSet);
  1766. }
  1767. void BitArray::insertBit (const int bit,
  1768. const bool shouldBeSet) throw()
  1769. {
  1770. if (bit >= 0)
  1771. shiftBits (1, bit);
  1772. setBit (bit, shouldBeSet);
  1773. }
  1774. void BitArray::andWith (const BitArray& other) throw()
  1775. {
  1776. // this operation will only work with the absolute values
  1777. jassert (isNegative() == other.isNegative());
  1778. int n = numValues;
  1779. while (n > other.numValues)
  1780. values[--n] = 0;
  1781. while (--n >= 0)
  1782. values[n] &= other.values[n];
  1783. if (other.highestBit < highestBit)
  1784. highestBit = other.highestBit;
  1785. highestBit = getHighestBit();
  1786. }
  1787. void BitArray::orWith (const BitArray& other) throw()
  1788. {
  1789. if (other.highestBit < 0)
  1790. return;
  1791. // this operation will only work with the absolute values
  1792. jassert (isNegative() == other.isNegative());
  1793. ensureSize (other.highestBit >> 5);
  1794. int n = (other.highestBit >> 5) + 1;
  1795. while (--n >= 0)
  1796. values[n] |= other.values[n];
  1797. if (other.highestBit > highestBit)
  1798. highestBit = other.highestBit;
  1799. highestBit = getHighestBit();
  1800. }
  1801. void BitArray::xorWith (const BitArray& other) throw()
  1802. {
  1803. if (other.highestBit < 0)
  1804. return;
  1805. // this operation will only work with the absolute values
  1806. jassert (isNegative() == other.isNegative());
  1807. ensureSize (other.highestBit >> 5);
  1808. int n = (other.highestBit >> 5) + 1;
  1809. while (--n >= 0)
  1810. values[n] ^= other.values[n];
  1811. if (other.highestBit > highestBit)
  1812. highestBit = other.highestBit;
  1813. highestBit = getHighestBit();
  1814. }
  1815. void BitArray::add (const BitArray& other) throw()
  1816. {
  1817. if (other.isNegative())
  1818. {
  1819. BitArray o (other);
  1820. o.negate();
  1821. subtract (o);
  1822. return;
  1823. }
  1824. if (isNegative())
  1825. {
  1826. if (compareAbsolute (other) < 0)
  1827. {
  1828. BitArray temp (*this);
  1829. temp.negate();
  1830. *this = other;
  1831. subtract (temp);
  1832. }
  1833. else
  1834. {
  1835. negate();
  1836. subtract (other);
  1837. negate();
  1838. }
  1839. return;
  1840. }
  1841. if (other.highestBit > highestBit)
  1842. highestBit = other.highestBit;
  1843. ++highestBit;
  1844. const int numInts = (highestBit >> 5) + 1;
  1845. ensureSize (numInts);
  1846. int64 remainder = 0;
  1847. for (int i = 0; i <= numInts; ++i)
  1848. {
  1849. if (i < numValues)
  1850. remainder += values[i];
  1851. if (i < other.numValues)
  1852. remainder += other.values[i];
  1853. values[i] = (unsigned int) remainder;
  1854. remainder >>= 32;
  1855. }
  1856. jassert (remainder == 0);
  1857. highestBit = getHighestBit();
  1858. }
  1859. void BitArray::subtract (const BitArray& other) throw()
  1860. {
  1861. if (other.isNegative())
  1862. {
  1863. BitArray o (other);
  1864. o.negate();
  1865. add (o);
  1866. return;
  1867. }
  1868. if (! isNegative())
  1869. {
  1870. if (compareAbsolute (other) < 0)
  1871. {
  1872. BitArray temp (*this);
  1873. *this = other;
  1874. subtract (temp);
  1875. negate();
  1876. return;
  1877. }
  1878. }
  1879. else
  1880. {
  1881. negate();
  1882. add (other);
  1883. negate();
  1884. return;
  1885. }
  1886. const int numInts = (highestBit >> 5) + 1;
  1887. const int maxOtherInts = (other.highestBit >> 5) + 1;
  1888. int64 amountToSubtract = 0;
  1889. for (int i = 0; i <= numInts; ++i)
  1890. {
  1891. if (i <= maxOtherInts)
  1892. amountToSubtract += (int64)other.values[i];
  1893. if (values[i] >= amountToSubtract)
  1894. {
  1895. values[i] = (unsigned int) (values[i] - amountToSubtract);
  1896. amountToSubtract = 0;
  1897. }
  1898. else
  1899. {
  1900. const int64 n = ((int64) values[i] + (((int64) 1) << 32)) - amountToSubtract;
  1901. values[i] = (unsigned int) n;
  1902. amountToSubtract = 1;
  1903. }
  1904. }
  1905. }
  1906. void BitArray::multiplyBy (const BitArray& other) throw()
  1907. {
  1908. BitArray total;
  1909. highestBit = getHighestBit();
  1910. const bool wasNegative = isNegative();
  1911. setNegative (false);
  1912. for (int i = 0; i <= highestBit; ++i)
  1913. {
  1914. if (operator[](i))
  1915. {
  1916. BitArray n (other);
  1917. n.setNegative (false);
  1918. n.shiftBits (i);
  1919. total.add (n);
  1920. }
  1921. }
  1922. *this = total;
  1923. negative = wasNegative ^ other.isNegative();
  1924. }
  1925. void BitArray::divideBy (const BitArray& divisor, BitArray& remainder) throw()
  1926. {
  1927. jassert (this != &remainder); // (can't handle passing itself in to get the remainder)
  1928. const int divHB = divisor.getHighestBit();
  1929. const int ourHB = getHighestBit();
  1930. if (divHB < 0 || ourHB < 0)
  1931. {
  1932. // division by zero
  1933. remainder.clear();
  1934. clear();
  1935. }
  1936. else
  1937. {
  1938. remainder = *this;
  1939. remainder.setNegative (false);
  1940. const bool wasNegative = isNegative();
  1941. clear();
  1942. BitArray temp (divisor);
  1943. temp.setNegative (false);
  1944. int leftShift = ourHB - divHB;
  1945. temp.shiftBits (leftShift);
  1946. while (leftShift >= 0)
  1947. {
  1948. if (remainder.compareAbsolute (temp) >= 0)
  1949. {
  1950. remainder.subtract (temp);
  1951. setBit (leftShift);
  1952. }
  1953. if (--leftShift >= 0)
  1954. temp.shiftBits (-1);
  1955. }
  1956. negative = wasNegative ^ divisor.isNegative();
  1957. remainder.setNegative (wasNegative);
  1958. }
  1959. }
  1960. void BitArray::modulo (const BitArray& divisor) throw()
  1961. {
  1962. BitArray remainder;
  1963. divideBy (divisor, remainder);
  1964. *this = remainder;
  1965. }
  1966. static const BitArray simpleGCD (BitArray* m, BitArray* n) throw()
  1967. {
  1968. while (! m->isEmpty())
  1969. {
  1970. if (n->compareAbsolute (*m) > 0)
  1971. swapVariables (m, n);
  1972. m->subtract (*n);
  1973. }
  1974. return *n;
  1975. }
  1976. const BitArray BitArray::findGreatestCommonDivisor (BitArray n) const throw()
  1977. {
  1978. BitArray m (*this);
  1979. while (! n.isEmpty())
  1980. {
  1981. if (abs (m.getHighestBit() - n.getHighestBit()) <= 16)
  1982. return simpleGCD (&m, &n);
  1983. BitArray temp1 (m), temp2;
  1984. temp1.divideBy (n, temp2);
  1985. m = n;
  1986. n = temp2;
  1987. }
  1988. return m;
  1989. }
  1990. void BitArray::exponentModulo (const BitArray& exponent,
  1991. const BitArray& modulus) throw()
  1992. {
  1993. BitArray exp (exponent);
  1994. exp.modulo (modulus);
  1995. BitArray value (*this);
  1996. value.modulo (modulus);
  1997. clear();
  1998. setBit (0);
  1999. while (! exp.isEmpty())
  2000. {
  2001. if (exp [0])
  2002. {
  2003. multiplyBy (value);
  2004. this->modulo (modulus);
  2005. }
  2006. value.multiplyBy (value);
  2007. value.modulo (modulus);
  2008. exp.shiftBits (-1);
  2009. }
  2010. }
  2011. void BitArray::inverseModulo (const BitArray& modulus) throw()
  2012. {
  2013. const BitArray one (1);
  2014. if (modulus == one || modulus.isNegative())
  2015. {
  2016. clear();
  2017. return;
  2018. }
  2019. if (isNegative() || compareAbsolute (modulus) >= 0)
  2020. this->modulo (modulus);
  2021. if (*this == one)
  2022. return;
  2023. if (! (*this)[0])
  2024. {
  2025. // not invertible
  2026. clear();
  2027. return;
  2028. }
  2029. BitArray a1 (modulus);
  2030. BitArray a2 (*this);
  2031. BitArray b1 (modulus);
  2032. BitArray b2 (1);
  2033. while (a2 != one)
  2034. {
  2035. BitArray temp1, temp2, multiplier (a1);
  2036. multiplier.divideBy (a2, temp1);
  2037. temp1 = a2;
  2038. temp1.multiplyBy (multiplier);
  2039. temp2 = a1;
  2040. temp2.subtract (temp1);
  2041. a1 = a2;
  2042. a2 = temp2;
  2043. temp1 = b2;
  2044. temp1.multiplyBy (multiplier);
  2045. temp2 = b1;
  2046. temp2.subtract (temp1);
  2047. b1 = b2;
  2048. b2 = temp2;
  2049. }
  2050. while (b2.isNegative())
  2051. b2.add (modulus);
  2052. b2.modulo (modulus);
  2053. *this = b2;
  2054. }
  2055. void BitArray::shiftBits (int bits, const int startBit) throw()
  2056. {
  2057. if (highestBit < 0)
  2058. return;
  2059. if (startBit > 0)
  2060. {
  2061. if (bits < 0)
  2062. {
  2063. // right shift
  2064. for (int i = startBit; i <= highestBit; ++i)
  2065. setBit (i, operator[] (i - bits));
  2066. highestBit = getHighestBit();
  2067. }
  2068. else if (bits > 0)
  2069. {
  2070. // left shift
  2071. for (int i = highestBit + 1; --i >= startBit;)
  2072. setBit (i + bits, operator[] (i));
  2073. while (--bits >= 0)
  2074. clearBit (bits + startBit);
  2075. }
  2076. }
  2077. else
  2078. {
  2079. if (bits < 0)
  2080. {
  2081. // right shift
  2082. bits = -bits;
  2083. if (bits > highestBit)
  2084. {
  2085. clear();
  2086. }
  2087. else
  2088. {
  2089. const int wordsToMove = bits >> 5;
  2090. int top = 1 + (highestBit >> 5) - wordsToMove;
  2091. highestBit -= bits;
  2092. if (wordsToMove > 0)
  2093. {
  2094. int i;
  2095. for (i = 0; i < top; ++i)
  2096. values [i] = values [i + wordsToMove];
  2097. for (i = 0; i < wordsToMove; ++i)
  2098. values [top + i] = 0;
  2099. bits &= 31;
  2100. }
  2101. if (bits != 0)
  2102. {
  2103. const int invBits = 32 - bits;
  2104. --top;
  2105. for (int i = 0; i < top; ++i)
  2106. values[i] = (values[i] >> bits) | (values [i + 1] << invBits);
  2107. values[top] = (values[top] >> bits);
  2108. }
  2109. highestBit = getHighestBit();
  2110. }
  2111. }
  2112. else if (bits > 0)
  2113. {
  2114. // left shift
  2115. ensureSize (((highestBit + bits) >> 5) + 1);
  2116. const int wordsToMove = bits >> 5;
  2117. int top = 1 + (highestBit >> 5);
  2118. highestBit += bits;
  2119. if (wordsToMove > 0)
  2120. {
  2121. int i;
  2122. for (i = top; --i >= 0;)
  2123. values [i + wordsToMove] = values [i];
  2124. for (i = 0; i < wordsToMove; ++i)
  2125. values [i] = 0;
  2126. bits &= 31;
  2127. }
  2128. if (bits != 0)
  2129. {
  2130. const int invBits = 32 - bits;
  2131. for (int i = top + 1 + wordsToMove; --i > wordsToMove;)
  2132. values[i] = (values[i] << bits) | (values [i - 1] >> invBits);
  2133. values [wordsToMove] = values [wordsToMove] << bits;
  2134. }
  2135. highestBit = getHighestBit();
  2136. }
  2137. }
  2138. }
  2139. const BitArray BitArray::getBitRange (int startBit, int numBits) const throw()
  2140. {
  2141. BitArray r;
  2142. numBits = jmin (numBits, getHighestBit() + 1 - startBit);
  2143. r.ensureSize (numBits >> 5);
  2144. r.highestBit = numBits;
  2145. int i = 0;
  2146. while (numBits > 0)
  2147. {
  2148. r.values[i++] = getBitRangeAsInt (startBit, jmin (32, numBits));
  2149. numBits -= 32;
  2150. startBit += 32;
  2151. }
  2152. r.highestBit = r.getHighestBit();
  2153. return r;
  2154. }
  2155. int BitArray::getBitRangeAsInt (const int startBit, int numBits) const throw()
  2156. {
  2157. if (numBits > 32)
  2158. {
  2159. jassertfalse // use getBitRange() if you need more than 32 bits..
  2160. numBits = 32;
  2161. }
  2162. numBits = jmin (numBits, highestBit + 1 - startBit);
  2163. if (numBits <= 0)
  2164. return 0;
  2165. const int pos = startBit >> 5;
  2166. const int offset = startBit & 31;
  2167. const int endSpace = 32 - numBits;
  2168. uint32 n = ((uint32) values [pos]) >> offset;
  2169. if (offset > endSpace)
  2170. n |= ((uint32) values [pos + 1]) << (32 - offset);
  2171. return (int) (n & (((uint32) 0xffffffff) >> endSpace));
  2172. }
  2173. void BitArray::setBitRangeAsInt (const int startBit, int numBits, unsigned int valueToSet) throw()
  2174. {
  2175. if (numBits > 32)
  2176. {
  2177. jassertfalse
  2178. numBits = 32;
  2179. }
  2180. for (int i = 0; i < numBits; ++i)
  2181. {
  2182. setBit (startBit + i, (valueToSet & 1) != 0);
  2183. valueToSet >>= 1;
  2184. }
  2185. }
  2186. bool BitArray::isNegative() const throw()
  2187. {
  2188. return negative && ! isEmpty();
  2189. }
  2190. void BitArray::setNegative (const bool neg) throw()
  2191. {
  2192. negative = neg;
  2193. }
  2194. void BitArray::negate() throw()
  2195. {
  2196. negative = (! negative) && ! isEmpty();
  2197. }
  2198. int BitArray::countNumberOfSetBits() const throw()
  2199. {
  2200. int total = 0;
  2201. for (int i = (highestBit >> 5) + 1; --i >= 0;)
  2202. {
  2203. unsigned int n = values[i];
  2204. if (n == 0xffffffff)
  2205. {
  2206. total += 32;
  2207. }
  2208. else
  2209. {
  2210. while (n != 0)
  2211. {
  2212. total += (n & 1);
  2213. n >>= 1;
  2214. }
  2215. }
  2216. }
  2217. return total;
  2218. }
  2219. int BitArray::getHighestBit() const throw()
  2220. {
  2221. for (int i = highestBit + 1; --i >= 0;)
  2222. if ((values [i >> 5] & (1 << (i & 31))) != 0)
  2223. return i;
  2224. return -1;
  2225. }
  2226. int BitArray::findNextSetBit (int i) const throw()
  2227. {
  2228. for (; i <= highestBit; ++i)
  2229. if ((values [i >> 5] & (1 << (i & 31))) != 0)
  2230. return i;
  2231. return -1;
  2232. }
  2233. int BitArray::findNextClearBit (int i) const throw()
  2234. {
  2235. for (; i <= highestBit; ++i)
  2236. if ((values [i >> 5] & (1 << (i & 31))) == 0)
  2237. break;
  2238. return i;
  2239. }
  2240. void BitArray::ensureSize (const int numVals) throw()
  2241. {
  2242. if (numVals + 2 >= numValues)
  2243. {
  2244. int oldSize = numValues;
  2245. numValues = ((numVals + 2) * 3) / 2;
  2246. values.realloc (numValues + 1);
  2247. while (oldSize < numValues)
  2248. values [oldSize++] = 0;
  2249. }
  2250. }
  2251. const String BitArray::toString (const int base, const int minimumNumCharacters) const throw()
  2252. {
  2253. String s;
  2254. BitArray v (*this);
  2255. if (base == 2 || base == 8 || base == 16)
  2256. {
  2257. const int bits = (base == 2) ? 1 : (base == 8 ? 3 : 4);
  2258. static const tchar* const hexDigits = T("0123456789abcdef");
  2259. for (;;)
  2260. {
  2261. const int remainder = v.getBitRangeAsInt (0, bits);
  2262. v.shiftBits (-bits);
  2263. if (remainder == 0 && v.isEmpty())
  2264. break;
  2265. s = String::charToString (hexDigits [remainder]) + s;
  2266. }
  2267. }
  2268. else if (base == 10)
  2269. {
  2270. const BitArray ten (10);
  2271. BitArray remainder;
  2272. for (;;)
  2273. {
  2274. v.divideBy (ten, remainder);
  2275. if (remainder.isEmpty() && v.isEmpty())
  2276. break;
  2277. s = String (remainder.getBitRangeAsInt (0, 8)) + s;
  2278. }
  2279. }
  2280. else
  2281. {
  2282. jassertfalse // can't do the specified base
  2283. return String::empty;
  2284. }
  2285. const int length = s.length();
  2286. if (length < minimumNumCharacters)
  2287. s = String::repeatedString (T("0"), minimumNumCharacters - length) + s;
  2288. return isNegative() ? T("-") + s : s;
  2289. }
  2290. void BitArray::parseString (const String& text,
  2291. const int base) throw()
  2292. {
  2293. clear();
  2294. const tchar* t = (const tchar*) text;
  2295. if (base == 2 || base == 8 || base == 16)
  2296. {
  2297. const int bits = (base == 2) ? 1 : (base == 8 ? 3 : 4);
  2298. for (;;)
  2299. {
  2300. const tchar c = *t++;
  2301. const int digit = CharacterFunctions::getHexDigitValue (c);
  2302. if (((unsigned int) digit) < (unsigned int) base)
  2303. {
  2304. shiftBits (bits);
  2305. add (digit);
  2306. }
  2307. else if (c == 0)
  2308. {
  2309. break;
  2310. }
  2311. }
  2312. }
  2313. else if (base == 10)
  2314. {
  2315. const BitArray ten ((unsigned int) 10);
  2316. for (;;)
  2317. {
  2318. const tchar c = *t++;
  2319. if (c >= T('0') && c <= T('9'))
  2320. {
  2321. multiplyBy (ten);
  2322. add ((int) (c - T('0')));
  2323. }
  2324. else if (c == 0)
  2325. {
  2326. break;
  2327. }
  2328. }
  2329. }
  2330. setNegative (text.trimStart().startsWithChar (T('-')));
  2331. }
  2332. const MemoryBlock BitArray::toMemoryBlock() const throw()
  2333. {
  2334. const int numBytes = (getHighestBit() + 8) >> 3;
  2335. MemoryBlock mb ((size_t) numBytes);
  2336. for (int i = 0; i < numBytes; ++i)
  2337. mb[i] = (uint8) getBitRangeAsInt (i << 3, 8);
  2338. return mb;
  2339. }
  2340. void BitArray::loadFromMemoryBlock (const MemoryBlock& data) throw()
  2341. {
  2342. clear();
  2343. for (int i = (int) data.getSize(); --i >= 0;)
  2344. this->setBitRangeAsInt ((int) (i << 3), 8, data [i]);
  2345. }
  2346. END_JUCE_NAMESPACE
  2347. /*** End of inlined file: juce_BitArray.cpp ***/
  2348. /*** Start of inlined file: juce_MemoryBlock.cpp ***/
  2349. BEGIN_JUCE_NAMESPACE
  2350. MemoryBlock::MemoryBlock() throw()
  2351. : size (0)
  2352. {
  2353. }
  2354. MemoryBlock::MemoryBlock (const size_t initialSize,
  2355. const bool initialiseToZero) throw()
  2356. {
  2357. if (initialSize > 0)
  2358. {
  2359. size = initialSize;
  2360. data.allocate (initialSize, initialiseToZero);
  2361. }
  2362. else
  2363. {
  2364. size = 0;
  2365. }
  2366. }
  2367. MemoryBlock::MemoryBlock (const MemoryBlock& other) throw()
  2368. : size (other.size)
  2369. {
  2370. if (size > 0)
  2371. {
  2372. jassert (other.data != 0);
  2373. data.malloc (size);
  2374. memcpy (data, other.data, size);
  2375. }
  2376. }
  2377. MemoryBlock::MemoryBlock (const void* const dataToInitialiseFrom,
  2378. const size_t sizeInBytes) throw()
  2379. : size (jmax ((size_t) 0, sizeInBytes))
  2380. {
  2381. jassert (sizeInBytes >= 0);
  2382. if (size > 0)
  2383. {
  2384. jassert (dataToInitialiseFrom != 0); // non-zero size, but a zero pointer passed-in?
  2385. data.malloc (size);
  2386. if (dataToInitialiseFrom != 0)
  2387. memcpy (data, dataToInitialiseFrom, size);
  2388. }
  2389. }
  2390. MemoryBlock::~MemoryBlock() throw()
  2391. {
  2392. jassert (size >= 0); // should never happen
  2393. jassert (size == 0 || data != 0); // non-zero size but no data allocated?
  2394. }
  2395. MemoryBlock& MemoryBlock::operator= (const MemoryBlock& other) throw()
  2396. {
  2397. if (this != &other)
  2398. {
  2399. setSize (other.size, false);
  2400. memcpy (data, other.data, size);
  2401. }
  2402. return *this;
  2403. }
  2404. bool MemoryBlock::operator== (const MemoryBlock& other) const throw()
  2405. {
  2406. return matches (other.data, other.size);
  2407. }
  2408. bool MemoryBlock::operator!= (const MemoryBlock& other) const throw()
  2409. {
  2410. return ! operator== (other);
  2411. }
  2412. bool MemoryBlock::matches (const void* dataToCompare, size_t dataSize) const throw()
  2413. {
  2414. return size == dataSize
  2415. && memcmp (data, dataToCompare, size) == 0;
  2416. }
  2417. // this will resize the block to this size
  2418. void MemoryBlock::setSize (const size_t newSize,
  2419. const bool initialiseToZero) throw()
  2420. {
  2421. if (size != newSize)
  2422. {
  2423. if (newSize <= 0)
  2424. {
  2425. data.free();
  2426. size = 0;
  2427. }
  2428. else
  2429. {
  2430. if (data != 0)
  2431. {
  2432. data.realloc (newSize);
  2433. if (initialiseToZero && (newSize > size))
  2434. zeromem (data + size, newSize - size);
  2435. }
  2436. else
  2437. {
  2438. data.allocate (newSize, initialiseToZero);
  2439. }
  2440. size = newSize;
  2441. }
  2442. }
  2443. }
  2444. void MemoryBlock::ensureSize (const size_t minimumSize,
  2445. const bool initialiseToZero) throw()
  2446. {
  2447. if (size < minimumSize)
  2448. setSize (minimumSize, initialiseToZero);
  2449. }
  2450. void MemoryBlock::swapWith (MemoryBlock& other) throw()
  2451. {
  2452. swapVariables (size, other.size);
  2453. data.swapWith (other.data);
  2454. }
  2455. void MemoryBlock::fillWith (const uint8 value) throw()
  2456. {
  2457. memset (data, (int) value, size);
  2458. }
  2459. void MemoryBlock::append (const void* const srcData,
  2460. const size_t numBytes) throw()
  2461. {
  2462. if (numBytes > 0)
  2463. {
  2464. const size_t oldSize = size;
  2465. setSize (size + numBytes);
  2466. memcpy (data + oldSize, srcData, numBytes);
  2467. }
  2468. }
  2469. void MemoryBlock::copyFrom (const void* const src, int offset, size_t num) throw()
  2470. {
  2471. const char* d = (const char*) src;
  2472. if (offset < 0)
  2473. {
  2474. d -= offset;
  2475. num -= offset;
  2476. offset = 0;
  2477. }
  2478. if (offset + num > size)
  2479. num = size - offset;
  2480. if (num > 0)
  2481. memcpy (data + offset, d, num);
  2482. }
  2483. void MemoryBlock::copyTo (void* const dst, int offset, size_t num) const throw()
  2484. {
  2485. char* d = (char*) dst;
  2486. if (offset < 0)
  2487. {
  2488. zeromem (d, -offset);
  2489. d -= offset;
  2490. num += offset;
  2491. offset = 0;
  2492. }
  2493. if (offset + num > size)
  2494. {
  2495. const size_t newNum = size - offset;
  2496. zeromem (d + newNum, num - newNum);
  2497. num = newNum;
  2498. }
  2499. if (num > 0)
  2500. memcpy (d, data + offset, num);
  2501. }
  2502. void MemoryBlock::removeSection (size_t startByte, size_t numBytesToRemove) throw()
  2503. {
  2504. if (startByte < 0)
  2505. {
  2506. numBytesToRemove += startByte;
  2507. startByte = 0;
  2508. }
  2509. if (startByte + numBytesToRemove >= size)
  2510. {
  2511. setSize (startByte);
  2512. }
  2513. else if (numBytesToRemove > 0)
  2514. {
  2515. memmove (data + startByte,
  2516. data + startByte + numBytesToRemove,
  2517. size - (startByte + numBytesToRemove));
  2518. setSize (size - numBytesToRemove);
  2519. }
  2520. }
  2521. const String MemoryBlock::toString() const throw()
  2522. {
  2523. return String ((const char*) data, size);
  2524. }
  2525. int MemoryBlock::getBitRange (const size_t bitRangeStart, size_t numBits) const throw()
  2526. {
  2527. int res = 0;
  2528. size_t byte = bitRangeStart >> 3;
  2529. int offsetInByte = bitRangeStart & 7;
  2530. size_t bitsSoFar = 0;
  2531. while (numBits > 0 && (size_t) byte < size)
  2532. {
  2533. const int bitsThisTime = jmin ((int) numBits, 8 - offsetInByte);
  2534. const int mask = (0xff >> (8 - bitsThisTime)) << offsetInByte;
  2535. res |= (((data[byte] & mask) >> offsetInByte) << bitsSoFar);
  2536. bitsSoFar += bitsThisTime;
  2537. numBits -= bitsThisTime;
  2538. ++byte;
  2539. offsetInByte = 0;
  2540. }
  2541. return res;
  2542. }
  2543. void MemoryBlock::setBitRange (const size_t bitRangeStart, size_t numBits, int bitsToSet) throw()
  2544. {
  2545. size_t byte = bitRangeStart >> 3;
  2546. int offsetInByte = bitRangeStart & 7;
  2547. unsigned int mask = ~((((unsigned int)0xffffffff) << (32 - numBits)) >> (32 - numBits));
  2548. while (numBits > 0 && (size_t) byte < size)
  2549. {
  2550. const int bitsThisTime = jmin ((int) numBits, 8 - offsetInByte);
  2551. const unsigned int tempMask = (mask << offsetInByte) | ~((((unsigned int)0xffffffff) >> offsetInByte) << offsetInByte);
  2552. const unsigned int tempBits = bitsToSet << offsetInByte;
  2553. data[byte] = (char)((data[byte] & tempMask) | tempBits);
  2554. ++byte;
  2555. numBits -= bitsThisTime;
  2556. bitsToSet >>= bitsThisTime;
  2557. mask >>= bitsThisTime;
  2558. offsetInByte = 0;
  2559. }
  2560. }
  2561. void MemoryBlock::loadFromHexString (const String& hex) throw()
  2562. {
  2563. ensureSize (hex.length() >> 1);
  2564. char* dest = data;
  2565. int i = 0;
  2566. for (;;)
  2567. {
  2568. int byte = 0;
  2569. for (int loop = 2; --loop >= 0;)
  2570. {
  2571. byte <<= 4;
  2572. for (;;)
  2573. {
  2574. const tchar c = hex [i++];
  2575. if (c >= T('0') && c <= T('9'))
  2576. {
  2577. byte |= c - T('0');
  2578. break;
  2579. }
  2580. else if (c >= T('a') && c <= T('z'))
  2581. {
  2582. byte |= c - (T('a') - 10);
  2583. break;
  2584. }
  2585. else if (c >= T('A') && c <= T('Z'))
  2586. {
  2587. byte |= c - (T('A') - 10);
  2588. break;
  2589. }
  2590. else if (c == 0)
  2591. {
  2592. setSize ((int) (dest - data));
  2593. return;
  2594. }
  2595. }
  2596. }
  2597. *dest++ = (char) byte;
  2598. }
  2599. }
  2600. static const char* const encodingTable
  2601. = ".ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+";
  2602. const String MemoryBlock::toBase64Encoding() const throw()
  2603. {
  2604. const size_t numChars = ((size << 3) + 5) / 6;
  2605. String destString ((unsigned int) size); // store the length, followed by a '.', and then the data.
  2606. const int initialLen = destString.length();
  2607. destString.preallocateStorage (initialLen + 2 + numChars);
  2608. tchar* d = const_cast <tchar*> (((const tchar*) destString) + initialLen);
  2609. *d++ = T('.');
  2610. for (size_t i = 0; i < numChars; ++i)
  2611. *d++ = encodingTable [getBitRange (i * 6, 6)];
  2612. *d++ = 0;
  2613. return destString;
  2614. }
  2615. bool MemoryBlock::fromBase64Encoding (const String& s) throw()
  2616. {
  2617. const int startPos = s.indexOfChar (T('.')) + 1;
  2618. if (startPos <= 0)
  2619. return false;
  2620. const int numBytesNeeded = s.substring (0, startPos - 1).getIntValue();
  2621. setSize (numBytesNeeded, true);
  2622. const int numChars = s.length() - startPos;
  2623. const tchar* const srcChars = ((const tchar*) s) + startPos;
  2624. int pos = 0;
  2625. for (int i = 0; i < numChars; ++i)
  2626. {
  2627. const char c = (char) srcChars[i];
  2628. for (int j = 0; j < 64; ++j)
  2629. {
  2630. if (encodingTable[j] == c)
  2631. {
  2632. setBitRange (pos, 6, j);
  2633. pos += 6;
  2634. break;
  2635. }
  2636. }
  2637. }
  2638. return true;
  2639. }
  2640. END_JUCE_NAMESPACE
  2641. /*** End of inlined file: juce_MemoryBlock.cpp ***/
  2642. /*** Start of inlined file: juce_PropertySet.cpp ***/
  2643. BEGIN_JUCE_NAMESPACE
  2644. PropertySet::PropertySet (const bool ignoreCaseOfKeyNames) throw()
  2645. : properties (ignoreCaseOfKeyNames),
  2646. fallbackProperties (0),
  2647. ignoreCaseOfKeys (ignoreCaseOfKeyNames)
  2648. {
  2649. }
  2650. PropertySet::PropertySet (const PropertySet& other) throw()
  2651. : properties (other.properties),
  2652. fallbackProperties (other.fallbackProperties),
  2653. ignoreCaseOfKeys (other.ignoreCaseOfKeys)
  2654. {
  2655. }
  2656. const PropertySet& PropertySet::operator= (const PropertySet& other) throw()
  2657. {
  2658. properties = other.properties;
  2659. fallbackProperties = other.fallbackProperties;
  2660. ignoreCaseOfKeys = other.ignoreCaseOfKeys;
  2661. propertyChanged();
  2662. return *this;
  2663. }
  2664. PropertySet::~PropertySet()
  2665. {
  2666. }
  2667. void PropertySet::clear()
  2668. {
  2669. const ScopedLock sl (lock);
  2670. if (properties.size() > 0)
  2671. {
  2672. properties.clear();
  2673. propertyChanged();
  2674. }
  2675. }
  2676. const String PropertySet::getValue (const String& keyName,
  2677. const String& defaultValue) const throw()
  2678. {
  2679. const ScopedLock sl (lock);
  2680. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2681. if (index >= 0)
  2682. return properties.getAllValues() [index];
  2683. return fallbackProperties != 0 ? fallbackProperties->getValue (keyName, defaultValue)
  2684. : defaultValue;
  2685. }
  2686. int PropertySet::getIntValue (const String& keyName,
  2687. const int defaultValue) const throw()
  2688. {
  2689. const ScopedLock sl (lock);
  2690. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2691. if (index >= 0)
  2692. return properties.getAllValues() [index].getIntValue();
  2693. return fallbackProperties != 0 ? fallbackProperties->getIntValue (keyName, defaultValue)
  2694. : defaultValue;
  2695. }
  2696. double PropertySet::getDoubleValue (const String& keyName,
  2697. const double defaultValue) const throw()
  2698. {
  2699. const ScopedLock sl (lock);
  2700. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2701. if (index >= 0)
  2702. return properties.getAllValues()[index].getDoubleValue();
  2703. return fallbackProperties != 0 ? fallbackProperties->getDoubleValue (keyName, defaultValue)
  2704. : defaultValue;
  2705. }
  2706. bool PropertySet::getBoolValue (const String& keyName,
  2707. const bool defaultValue) const throw()
  2708. {
  2709. const ScopedLock sl (lock);
  2710. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2711. if (index >= 0)
  2712. return properties.getAllValues() [index].getIntValue() != 0;
  2713. return fallbackProperties != 0 ? fallbackProperties->getBoolValue (keyName, defaultValue)
  2714. : defaultValue;
  2715. }
  2716. XmlElement* PropertySet::getXmlValue (const String& keyName) const
  2717. {
  2718. XmlDocument doc (getValue (keyName));
  2719. return doc.getDocumentElement();
  2720. }
  2721. void PropertySet::setValue (const String& keyName,
  2722. const String& value) throw()
  2723. {
  2724. jassert (keyName.isNotEmpty()); // shouldn't use an empty key name!
  2725. if (keyName.isNotEmpty())
  2726. {
  2727. const ScopedLock sl (lock);
  2728. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2729. if (index < 0 || properties.getAllValues() [index] != value)
  2730. {
  2731. properties.set (keyName, value);
  2732. propertyChanged();
  2733. }
  2734. }
  2735. }
  2736. void PropertySet::removeValue (const String& keyName) throw()
  2737. {
  2738. if (keyName.isNotEmpty())
  2739. {
  2740. const ScopedLock sl (lock);
  2741. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2742. if (index >= 0)
  2743. {
  2744. properties.remove (keyName);
  2745. propertyChanged();
  2746. }
  2747. }
  2748. }
  2749. void PropertySet::setValue (const String& keyName, const tchar* const value) throw()
  2750. {
  2751. setValue (keyName, String (value));
  2752. }
  2753. void PropertySet::setValue (const String& keyName, const int value) throw()
  2754. {
  2755. setValue (keyName, String (value));
  2756. }
  2757. void PropertySet::setValue (const String& keyName, const double value) throw()
  2758. {
  2759. setValue (keyName, String (value));
  2760. }
  2761. void PropertySet::setValue (const String& keyName, const bool value) throw()
  2762. {
  2763. setValue (keyName, String ((value) ? T("1") : T("0")));
  2764. }
  2765. void PropertySet::setValue (const String& keyName, const XmlElement* const xml)
  2766. {
  2767. setValue (keyName, (xml == 0) ? String::empty
  2768. : xml->createDocument (String::empty, true));
  2769. }
  2770. bool PropertySet::containsKey (const String& keyName) const throw()
  2771. {
  2772. const ScopedLock sl (lock);
  2773. return properties.getAllKeys().contains (keyName, ignoreCaseOfKeys);
  2774. }
  2775. void PropertySet::setFallbackPropertySet (PropertySet* fallbackProperties_) throw()
  2776. {
  2777. const ScopedLock sl (lock);
  2778. fallbackProperties = fallbackProperties_;
  2779. }
  2780. XmlElement* PropertySet::createXml (const String& nodeName) const throw()
  2781. {
  2782. const ScopedLock sl (lock);
  2783. XmlElement* const xml = new XmlElement (nodeName);
  2784. for (int i = 0; i < properties.getAllKeys().size(); ++i)
  2785. {
  2786. XmlElement* const e = xml->createNewChildElement ("VALUE");
  2787. e->setAttribute (T("name"), properties.getAllKeys()[i]);
  2788. e->setAttribute (T("val"), properties.getAllValues()[i]);
  2789. }
  2790. return xml;
  2791. }
  2792. void PropertySet::restoreFromXml (const XmlElement& xml) throw()
  2793. {
  2794. const ScopedLock sl (lock);
  2795. clear();
  2796. forEachXmlChildElementWithTagName (xml, e, T("VALUE"))
  2797. {
  2798. if (e->hasAttribute (T("name"))
  2799. && e->hasAttribute (T("val")))
  2800. {
  2801. properties.set (e->getStringAttribute (T("name")),
  2802. e->getStringAttribute (T("val")));
  2803. }
  2804. }
  2805. if (properties.size() > 0)
  2806. propertyChanged();
  2807. }
  2808. void PropertySet::propertyChanged()
  2809. {
  2810. }
  2811. END_JUCE_NAMESPACE
  2812. /*** End of inlined file: juce_PropertySet.cpp ***/
  2813. /*** Start of inlined file: juce_Variant.cpp ***/
  2814. BEGIN_JUCE_NAMESPACE
  2815. var::var() throw()
  2816. : type (voidType)
  2817. {
  2818. value.doubleValue = 0;
  2819. }
  2820. var::~var() throw()
  2821. {
  2822. if (type == stringType)
  2823. delete value.stringValue;
  2824. else if (type == objectType && value.objectValue != 0)
  2825. value.objectValue->decReferenceCount();
  2826. }
  2827. const var var::null;
  2828. var::var (const var& valueToCopy)
  2829. : type (valueToCopy.type),
  2830. value (valueToCopy.value)
  2831. {
  2832. if (type == stringType)
  2833. value.stringValue = new String (*(value.stringValue));
  2834. else if (type == objectType && value.objectValue != 0)
  2835. value.objectValue->incReferenceCount();
  2836. }
  2837. var::var (const int value_) throw()
  2838. : type (intType)
  2839. {
  2840. value.intValue = value_;
  2841. }
  2842. var::var (const bool value_) throw()
  2843. : type (boolType)
  2844. {
  2845. value.boolValue = value_;
  2846. }
  2847. var::var (const double value_) throw()
  2848. : type (doubleType)
  2849. {
  2850. value.doubleValue = value_;
  2851. }
  2852. var::var (const String& value_)
  2853. : type (stringType)
  2854. {
  2855. value.stringValue = new String (value_);
  2856. }
  2857. var::var (const char* const value_)
  2858. : type (stringType)
  2859. {
  2860. value.stringValue = new String (value_);
  2861. }
  2862. var::var (const juce_wchar* const value_)
  2863. : type (stringType)
  2864. {
  2865. value.stringValue = new String (value_);
  2866. }
  2867. var::var (DynamicObject* const object)
  2868. : type (objectType)
  2869. {
  2870. value.objectValue = object;
  2871. if (object != 0)
  2872. object->incReferenceCount();
  2873. }
  2874. var::var (MethodFunction method_) throw()
  2875. : type (methodType)
  2876. {
  2877. value.methodValue = method_;
  2878. }
  2879. void var::swapWith (var& other) throw()
  2880. {
  2881. swapVariables (type, other.type);
  2882. swapVariables (value, other.value);
  2883. }
  2884. var& var::operator= (const var& value_) { var newValue (value_); swapWith (newValue); return *this; }
  2885. var& var::operator= (int value_) { var newValue (value_); swapWith (newValue); return *this; }
  2886. var& var::operator= (bool value_) { var newValue (value_); swapWith (newValue); return *this; }
  2887. var& var::operator= (double value_) { var newValue (value_); swapWith (newValue); return *this; }
  2888. var& var::operator= (const char* value_) { var newValue (value_); swapWith (newValue); return *this; }
  2889. var& var::operator= (const juce_wchar* value_) { var newValue (value_); swapWith (newValue); return *this; }
  2890. var& var::operator= (const String& value_) { var newValue (value_); swapWith (newValue); return *this; }
  2891. var& var::operator= (DynamicObject* value_) { var newValue (value_); swapWith (newValue); return *this; }
  2892. var& var::operator= (MethodFunction value_) { var newValue (value_); swapWith (newValue); return *this; }
  2893. var::operator int() const
  2894. {
  2895. switch (type)
  2896. {
  2897. case voidType: break;
  2898. case intType: return value.intValue;
  2899. case boolType: return value.boolValue ? 1 : 0;
  2900. case doubleType: return (int) value.doubleValue;
  2901. case stringType: return value.stringValue->getIntValue();
  2902. case objectType: break;
  2903. default: jassertfalse; break;
  2904. }
  2905. return 0;
  2906. }
  2907. var::operator bool() const
  2908. {
  2909. switch (type)
  2910. {
  2911. case voidType: break;
  2912. case intType: return value.intValue != 0;
  2913. case boolType: return value.boolValue;
  2914. case doubleType: return value.doubleValue != 0;
  2915. case stringType: return value.stringValue->getIntValue() != 0
  2916. || value.stringValue->trim().equalsIgnoreCase (T("true"))
  2917. || value.stringValue->trim().equalsIgnoreCase (T("yes"));
  2918. case objectType: return value.objectValue != 0;
  2919. default: jassertfalse; break;
  2920. }
  2921. return false;
  2922. }
  2923. var::operator float() const
  2924. {
  2925. return (float) operator double();
  2926. }
  2927. var::operator double() const
  2928. {
  2929. switch (type)
  2930. {
  2931. case voidType: break;
  2932. case intType: return value.intValue;
  2933. case boolType: return value.boolValue ? 1.0 : 0.0;
  2934. case doubleType: return value.doubleValue;
  2935. case stringType: return value.stringValue->getDoubleValue();
  2936. case objectType: break;
  2937. default: jassertfalse; break;
  2938. }
  2939. return 0.0;
  2940. }
  2941. const String var::toString() const
  2942. {
  2943. switch (type)
  2944. {
  2945. case voidType: return String::empty;
  2946. case intType: return String (value.intValue);
  2947. case boolType: return value.boolValue ? T("1") : T("0");
  2948. case doubleType: return String (value.doubleValue);
  2949. case stringType: return *(value.stringValue);
  2950. case objectType: return "Object 0x" + String::toHexString ((int) (pointer_sized_int) value.objectValue);
  2951. case methodType: return "Method";
  2952. default: jassertfalse; break;
  2953. }
  2954. return String::empty;
  2955. }
  2956. var::operator const String() const
  2957. {
  2958. return toString();
  2959. }
  2960. DynamicObject* var::getObject() const
  2961. {
  2962. return type == objectType ? value.objectValue : 0;
  2963. }
  2964. bool var::operator== (const var& other) const throw()
  2965. {
  2966. switch (type)
  2967. {
  2968. case voidType: return other.isVoid();
  2969. case intType: return value.intValue == (int) other;
  2970. case boolType: return value.boolValue == (bool) other;
  2971. case doubleType: return value.doubleValue == (double) other;
  2972. case stringType: return (*(value.stringValue)) == other.toString();
  2973. case objectType: return value.objectValue == other.getObject();
  2974. case methodType: return value.methodValue == other.value.methodValue && other.isMethod();
  2975. default: jassertfalse; break;
  2976. }
  2977. return false;
  2978. }
  2979. bool var::operator!= (const var& other) const throw()
  2980. {
  2981. return ! operator== (other);
  2982. }
  2983. void var::writeToStream (OutputStream& output) const
  2984. {
  2985. switch (type)
  2986. {
  2987. case voidType: output.writeCompressedInt (0); break;
  2988. case intType: output.writeCompressedInt (5); output.writeByte (1); output.writeInt (value.intValue); break;
  2989. case boolType: output.writeCompressedInt (1); output.writeByte (value.boolValue ? 2 : 3); break;
  2990. case doubleType: output.writeCompressedInt (9); output.writeByte (4); output.writeDouble (value.doubleValue); break;
  2991. case stringType:
  2992. {
  2993. const int len = value.stringValue->copyToUTF8 (0);
  2994. output.writeCompressedInt (len + 1);
  2995. output.writeByte (5);
  2996. HeapBlock <uint8> temp (len);
  2997. value.stringValue->copyToUTF8 (temp);
  2998. output.write (temp, len);
  2999. break;
  3000. }
  3001. case objectType:
  3002. case methodType: output.writeCompressedInt (0); jassertfalse; break; // Can't write an object to a stream!
  3003. default: jassertfalse; break; // Is this a corrupted object?
  3004. }
  3005. }
  3006. const var var::readFromStream (InputStream& input)
  3007. {
  3008. const int numBytes = input.readCompressedInt();
  3009. if (numBytes > 0)
  3010. {
  3011. switch (input.readByte())
  3012. {
  3013. case 1: return var (input.readInt());
  3014. case 2: return var (true);
  3015. case 3: return var (false);
  3016. case 4: return var (input.readDouble());
  3017. case 5:
  3018. {
  3019. MemoryBlock mb;
  3020. input.readIntoMemoryBlock (mb, numBytes - 1);
  3021. return var (String::fromUTF8 ((const uint8*) mb.getData(), (int) mb.getSize()));
  3022. }
  3023. default: input.skipNextBytes (numBytes - 1); break;
  3024. }
  3025. }
  3026. return var::null;
  3027. }
  3028. const var var::operator[] (const var::identifier& propertyName) const
  3029. {
  3030. if (type == objectType && value.objectValue != 0)
  3031. return value.objectValue->getProperty (propertyName);
  3032. return var::null;
  3033. }
  3034. const var var::invoke (const var::identifier& method, const var* arguments, int numArguments) const
  3035. {
  3036. if (type == objectType && value.objectValue != 0)
  3037. return value.objectValue->invokeMethod (method, arguments, numArguments);
  3038. return var::null;
  3039. }
  3040. const var var::invoke (const var& targetObject, const var* arguments, int numArguments) const
  3041. {
  3042. if (isMethod())
  3043. {
  3044. DynamicObject* const target = targetObject.getObject();
  3045. if (target != 0)
  3046. return (target->*(value.methodValue)) (arguments, numArguments);
  3047. }
  3048. return var::null;
  3049. }
  3050. const var var::call (const var::identifier& method) const
  3051. {
  3052. return invoke (method, 0, 0);
  3053. }
  3054. const var var::call (const var::identifier& method, const var& arg1) const
  3055. {
  3056. return invoke (method, &arg1, 1);
  3057. }
  3058. const var var::call (const var::identifier& method, const var& arg1, const var& arg2) const
  3059. {
  3060. var args[] = { arg1, arg2 };
  3061. return invoke (method, args, 2);
  3062. }
  3063. const var var::call (const var::identifier& method, const var& arg1, const var& arg2, const var& arg3)
  3064. {
  3065. var args[] = { arg1, arg2, arg3 };
  3066. return invoke (method, args, 3);
  3067. }
  3068. const var var::call (const var::identifier& method, const var& arg1, const var& arg2, const var& arg3, const var& arg4) const
  3069. {
  3070. var args[] = { arg1, arg2, arg3, arg4 };
  3071. return invoke (method, args, 4);
  3072. }
  3073. const var var::call (const var::identifier& method, const var& arg1, const var& arg2, const var& arg3, const var& arg4, const var& arg5) const
  3074. {
  3075. var args[] = { arg1, arg2, arg3, arg4, arg5 };
  3076. return invoke (method, args, 5);
  3077. }
  3078. var::identifier::identifier() throw()
  3079. : hashCode (0)
  3080. {
  3081. }
  3082. var::identifier::identifier (const String& name_)
  3083. : name (name_),
  3084. hashCode (name_.hashCode())
  3085. {
  3086. /* An identifier string must be suitable for use as a script variable or XML
  3087. attribute, so it can only contain this limited set of characters.. */
  3088. jassert (name.containsOnly (T("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_")) && name.isNotEmpty());
  3089. }
  3090. var::identifier::identifier (const char* const name_)
  3091. : name (name_),
  3092. hashCode (name.hashCode())
  3093. {
  3094. /* An identifier string must be suitable for use as a script variable or XML
  3095. attribute, so it can only contain this limited set of characters.. */
  3096. jassert (name.containsOnly (T("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_")) && name.isNotEmpty());
  3097. }
  3098. var::identifier::~identifier()
  3099. {
  3100. }
  3101. END_JUCE_NAMESPACE
  3102. /*** End of inlined file: juce_Variant.cpp ***/
  3103. /*** Start of inlined file: juce_NamedValueSet.cpp ***/
  3104. BEGIN_JUCE_NAMESPACE
  3105. NamedValueSet::NamedValue::NamedValue() throw()
  3106. {
  3107. }
  3108. inline NamedValueSet::NamedValue::NamedValue (const var::identifier& name_, const var& value_)
  3109. : name (name_), value (value_)
  3110. {
  3111. }
  3112. NamedValueSet::NamedValueSet() throw()
  3113. {
  3114. }
  3115. NamedValueSet::NamedValueSet (const NamedValueSet& other)
  3116. : values (other.values)
  3117. {
  3118. }
  3119. NamedValueSet& NamedValueSet::operator= (const NamedValueSet& other)
  3120. {
  3121. values = other.values;
  3122. return *this;
  3123. }
  3124. NamedValueSet::~NamedValueSet()
  3125. {
  3126. }
  3127. int NamedValueSet::size() const throw()
  3128. {
  3129. return values.size();
  3130. }
  3131. const var& NamedValueSet::operator[] (const var::identifier& name) const
  3132. {
  3133. for (int i = values.size(); --i >= 0;)
  3134. {
  3135. const NamedValue& v = values.getReference(i);
  3136. if (v.name == name)
  3137. return v.value;
  3138. }
  3139. return var::null;
  3140. }
  3141. const var NamedValueSet::getWithDefault (const var::identifier& name, const var& defaultReturnValue) const
  3142. {
  3143. const var* v = getItem (name);
  3144. return v != 0 ? *v : defaultReturnValue;
  3145. }
  3146. var* NamedValueSet::getItem (const var::identifier& name) const
  3147. {
  3148. for (int i = values.size(); --i >= 0;)
  3149. {
  3150. NamedValue& v = values.getReference(i);
  3151. if (v.name == name)
  3152. return &(v.value);
  3153. }
  3154. return 0;
  3155. }
  3156. bool NamedValueSet::set (const var::identifier& name, const var& newValue)
  3157. {
  3158. for (int i = values.size(); --i >= 0;)
  3159. {
  3160. NamedValue& v = values.getReference(i);
  3161. if (v.name == name)
  3162. {
  3163. if (v.value == newValue)
  3164. return false;
  3165. v.value = newValue;
  3166. return true;
  3167. }
  3168. }
  3169. values.add (NamedValue (name, newValue));
  3170. return true;
  3171. }
  3172. bool NamedValueSet::contains (const var::identifier& name) const
  3173. {
  3174. return getItem (name) != 0;
  3175. }
  3176. bool NamedValueSet::remove (const var::identifier& name)
  3177. {
  3178. for (int i = values.size(); --i >= 0;)
  3179. {
  3180. if (values.getReference(i).name == name)
  3181. {
  3182. values.remove (i);
  3183. return true;
  3184. }
  3185. }
  3186. return false;
  3187. }
  3188. const var::identifier NamedValueSet::getName (int index) const
  3189. {
  3190. jassert (((unsigned int) index) < (unsigned int) values.size());
  3191. return values [index].name;
  3192. }
  3193. void NamedValueSet::clear()
  3194. {
  3195. values.clear();
  3196. }
  3197. END_JUCE_NAMESPACE
  3198. /*** End of inlined file: juce_NamedValueSet.cpp ***/
  3199. /*** Start of inlined file: juce_DynamicObject.cpp ***/
  3200. BEGIN_JUCE_NAMESPACE
  3201. DynamicObject::DynamicObject()
  3202. {
  3203. }
  3204. DynamicObject::~DynamicObject()
  3205. {
  3206. }
  3207. bool DynamicObject::hasProperty (const var::identifier& propertyName) const
  3208. {
  3209. var* const v = properties.getItem (propertyName);
  3210. return v != 0 && ! v->isMethod();
  3211. }
  3212. const var DynamicObject::getProperty (const var::identifier& propertyName) const
  3213. {
  3214. return properties [propertyName];
  3215. }
  3216. void DynamicObject::setProperty (const var::identifier& propertyName, const var& newValue)
  3217. {
  3218. properties.set (propertyName, newValue);
  3219. }
  3220. void DynamicObject::removeProperty (const var::identifier& propertyName)
  3221. {
  3222. properties.remove (propertyName);
  3223. }
  3224. bool DynamicObject::hasMethod (const var::identifier& methodName) const
  3225. {
  3226. return getProperty (methodName).isMethod();
  3227. }
  3228. const var DynamicObject::invokeMethod (const var::identifier& methodName,
  3229. const var* parameters,
  3230. int numParameters)
  3231. {
  3232. return properties [methodName].invoke (var (this), parameters, numParameters);
  3233. }
  3234. void DynamicObject::setMethod (const var::identifier& name,
  3235. var::MethodFunction methodFunction)
  3236. {
  3237. properties.set (name, var (methodFunction));
  3238. }
  3239. void DynamicObject::clear()
  3240. {
  3241. properties.clear();
  3242. }
  3243. END_JUCE_NAMESPACE
  3244. /*** End of inlined file: juce_DynamicObject.cpp ***/
  3245. /*** Start of inlined file: juce_BlowFish.cpp ***/
  3246. BEGIN_JUCE_NAMESPACE
  3247. static const uint32 initialPValues [18] =
  3248. {
  3249. 0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344,
  3250. 0xa4093822, 0x299f31d0, 0x082efa98, 0xec4e6c89,
  3251. 0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c,
  3252. 0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917,
  3253. 0x9216d5d9, 0x8979fb1b
  3254. };
  3255. static const uint32 initialSValues [4 * 256] =
  3256. {
  3257. 0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7,
  3258. 0xb8e1afed, 0x6a267e96, 0xba7c9045, 0xf12c7f99,
  3259. 0x24a19947, 0xb3916cf7, 0x0801f2e2, 0x858efc16,
  3260. 0x636920d8, 0x71574e69, 0xa458fea3, 0xf4933d7e,
  3261. 0x0d95748f, 0x728eb658, 0x718bcd58, 0x82154aee,
  3262. 0x7b54a41d, 0xc25a59b5, 0x9c30d539, 0x2af26013,
  3263. 0xc5d1b023, 0x286085f0, 0xca417918, 0xb8db38ef,
  3264. 0x8e79dcb0, 0x603a180e, 0x6c9e0e8b, 0xb01e8a3e,
  3265. 0xd71577c1, 0xbd314b27, 0x78af2fda, 0x55605c60,
  3266. 0xe65525f3, 0xaa55ab94, 0x57489862, 0x63e81440,
  3267. 0x55ca396a, 0x2aab10b6, 0xb4cc5c34, 0x1141e8ce,
  3268. 0xa15486af, 0x7c72e993, 0xb3ee1411, 0x636fbc2a,
  3269. 0x2ba9c55d, 0x741831f6, 0xce5c3e16, 0x9b87931e,
  3270. 0xafd6ba33, 0x6c24cf5c, 0x7a325381, 0x28958677,
  3271. 0x3b8f4898, 0x6b4bb9af, 0xc4bfe81b, 0x66282193,
  3272. 0x61d809cc, 0xfb21a991, 0x487cac60, 0x5dec8032,
  3273. 0xef845d5d, 0xe98575b1, 0xdc262302, 0xeb651b88,
  3274. 0x23893e81, 0xd396acc5, 0x0f6d6ff3, 0x83f44239,
  3275. 0x2e0b4482, 0xa4842004, 0x69c8f04a, 0x9e1f9b5e,
  3276. 0x21c66842, 0xf6e96c9a, 0x670c9c61, 0xabd388f0,
  3277. 0x6a51a0d2, 0xd8542f68, 0x960fa728, 0xab5133a3,
  3278. 0x6eef0b6c, 0x137a3be4, 0xba3bf050, 0x7efb2a98,
  3279. 0xa1f1651d, 0x39af0176, 0x66ca593e, 0x82430e88,
  3280. 0x8cee8619, 0x456f9fb4, 0x7d84a5c3, 0x3b8b5ebe,
  3281. 0xe06f75d8, 0x85c12073, 0x401a449f, 0x56c16aa6,
  3282. 0x4ed3aa62, 0x363f7706, 0x1bfedf72, 0x429b023d,
  3283. 0x37d0d724, 0xd00a1248, 0xdb0fead3, 0x49f1c09b,
  3284. 0x075372c9, 0x80991b7b, 0x25d479d8, 0xf6e8def7,
  3285. 0xe3fe501a, 0xb6794c3b, 0x976ce0bd, 0x04c006ba,
  3286. 0xc1a94fb6, 0x409f60c4, 0x5e5c9ec2, 0x196a2463,
  3287. 0x68fb6faf, 0x3e6c53b5, 0x1339b2eb, 0x3b52ec6f,
  3288. 0x6dfc511f, 0x9b30952c, 0xcc814544, 0xaf5ebd09,
  3289. 0xbee3d004, 0xde334afd, 0x660f2807, 0x192e4bb3,
  3290. 0xc0cba857, 0x45c8740f, 0xd20b5f39, 0xb9d3fbdb,
  3291. 0x5579c0bd, 0x1a60320a, 0xd6a100c6, 0x402c7279,
  3292. 0x679f25fe, 0xfb1fa3cc, 0x8ea5e9f8, 0xdb3222f8,
  3293. 0x3c7516df, 0xfd616b15, 0x2f501ec8, 0xad0552ab,
  3294. 0x323db5fa, 0xfd238760, 0x53317b48, 0x3e00df82,
  3295. 0x9e5c57bb, 0xca6f8ca0, 0x1a87562e, 0xdf1769db,
  3296. 0xd542a8f6, 0x287effc3, 0xac6732c6, 0x8c4f5573,
  3297. 0x695b27b0, 0xbbca58c8, 0xe1ffa35d, 0xb8f011a0,
  3298. 0x10fa3d98, 0xfd2183b8, 0x4afcb56c, 0x2dd1d35b,
  3299. 0x9a53e479, 0xb6f84565, 0xd28e49bc, 0x4bfb9790,
  3300. 0xe1ddf2da, 0xa4cb7e33, 0x62fb1341, 0xcee4c6e8,
  3301. 0xef20cada, 0x36774c01, 0xd07e9efe, 0x2bf11fb4,
  3302. 0x95dbda4d, 0xae909198, 0xeaad8e71, 0x6b93d5a0,
  3303. 0xd08ed1d0, 0xafc725e0, 0x8e3c5b2f, 0x8e7594b7,
  3304. 0x8ff6e2fb, 0xf2122b64, 0x8888b812, 0x900df01c,
  3305. 0x4fad5ea0, 0x688fc31c, 0xd1cff191, 0xb3a8c1ad,
  3306. 0x2f2f2218, 0xbe0e1777, 0xea752dfe, 0x8b021fa1,
  3307. 0xe5a0cc0f, 0xb56f74e8, 0x18acf3d6, 0xce89e299,
  3308. 0xb4a84fe0, 0xfd13e0b7, 0x7cc43b81, 0xd2ada8d9,
  3309. 0x165fa266, 0x80957705, 0x93cc7314, 0x211a1477,
  3310. 0xe6ad2065, 0x77b5fa86, 0xc75442f5, 0xfb9d35cf,
  3311. 0xebcdaf0c, 0x7b3e89a0, 0xd6411bd3, 0xae1e7e49,
  3312. 0x00250e2d, 0x2071b35e, 0x226800bb, 0x57b8e0af,
  3313. 0x2464369b, 0xf009b91e, 0x5563911d, 0x59dfa6aa,
  3314. 0x78c14389, 0xd95a537f, 0x207d5ba2, 0x02e5b9c5,
  3315. 0x83260376, 0x6295cfa9, 0x11c81968, 0x4e734a41,
  3316. 0xb3472dca, 0x7b14a94a, 0x1b510052, 0x9a532915,
  3317. 0xd60f573f, 0xbc9bc6e4, 0x2b60a476, 0x81e67400,
  3318. 0x08ba6fb5, 0x571be91f, 0xf296ec6b, 0x2a0dd915,
  3319. 0xb6636521, 0xe7b9f9b6, 0xff34052e, 0xc5855664,
  3320. 0x53b02d5d, 0xa99f8fa1, 0x08ba4799, 0x6e85076a,
  3321. 0x4b7a70e9, 0xb5b32944, 0xdb75092e, 0xc4192623,
  3322. 0xad6ea6b0, 0x49a7df7d, 0x9cee60b8, 0x8fedb266,
  3323. 0xecaa8c71, 0x699a17ff, 0x5664526c, 0xc2b19ee1,
  3324. 0x193602a5, 0x75094c29, 0xa0591340, 0xe4183a3e,
  3325. 0x3f54989a, 0x5b429d65, 0x6b8fe4d6, 0x99f73fd6,
  3326. 0xa1d29c07, 0xefe830f5, 0x4d2d38e6, 0xf0255dc1,
  3327. 0x4cdd2086, 0x8470eb26, 0x6382e9c6, 0x021ecc5e,
  3328. 0x09686b3f, 0x3ebaefc9, 0x3c971814, 0x6b6a70a1,
  3329. 0x687f3584, 0x52a0e286, 0xb79c5305, 0xaa500737,
  3330. 0x3e07841c, 0x7fdeae5c, 0x8e7d44ec, 0x5716f2b8,
  3331. 0xb03ada37, 0xf0500c0d, 0xf01c1f04, 0x0200b3ff,
  3332. 0xae0cf51a, 0x3cb574b2, 0x25837a58, 0xdc0921bd,
  3333. 0xd19113f9, 0x7ca92ff6, 0x94324773, 0x22f54701,
  3334. 0x3ae5e581, 0x37c2dadc, 0xc8b57634, 0x9af3dda7,
  3335. 0xa9446146, 0x0fd0030e, 0xecc8c73e, 0xa4751e41,
  3336. 0xe238cd99, 0x3bea0e2f, 0x3280bba1, 0x183eb331,
  3337. 0x4e548b38, 0x4f6db908, 0x6f420d03, 0xf60a04bf,
  3338. 0x2cb81290, 0x24977c79, 0x5679b072, 0xbcaf89af,
  3339. 0xde9a771f, 0xd9930810, 0xb38bae12, 0xdccf3f2e,
  3340. 0x5512721f, 0x2e6b7124, 0x501adde6, 0x9f84cd87,
  3341. 0x7a584718, 0x7408da17, 0xbc9f9abc, 0xe94b7d8c,
  3342. 0xec7aec3a, 0xdb851dfa, 0x63094366, 0xc464c3d2,
  3343. 0xef1c1847, 0x3215d908, 0xdd433b37, 0x24c2ba16,
  3344. 0x12a14d43, 0x2a65c451, 0x50940002, 0x133ae4dd,
  3345. 0x71dff89e, 0x10314e55, 0x81ac77d6, 0x5f11199b,
  3346. 0x043556f1, 0xd7a3c76b, 0x3c11183b, 0x5924a509,
  3347. 0xf28fe6ed, 0x97f1fbfa, 0x9ebabf2c, 0x1e153c6e,
  3348. 0x86e34570, 0xeae96fb1, 0x860e5e0a, 0x5a3e2ab3,
  3349. 0x771fe71c, 0x4e3d06fa, 0x2965dcb9, 0x99e71d0f,
  3350. 0x803e89d6, 0x5266c825, 0x2e4cc978, 0x9c10b36a,
  3351. 0xc6150eba, 0x94e2ea78, 0xa5fc3c53, 0x1e0a2df4,
  3352. 0xf2f74ea7, 0x361d2b3d, 0x1939260f, 0x19c27960,
  3353. 0x5223a708, 0xf71312b6, 0xebadfe6e, 0xeac31f66,
  3354. 0xe3bc4595, 0xa67bc883, 0xb17f37d1, 0x018cff28,
  3355. 0xc332ddef, 0xbe6c5aa5, 0x65582185, 0x68ab9802,
  3356. 0xeecea50f, 0xdb2f953b, 0x2aef7dad, 0x5b6e2f84,
  3357. 0x1521b628, 0x29076170, 0xecdd4775, 0x619f1510,
  3358. 0x13cca830, 0xeb61bd96, 0x0334fe1e, 0xaa0363cf,
  3359. 0xb5735c90, 0x4c70a239, 0xd59e9e0b, 0xcbaade14,
  3360. 0xeecc86bc, 0x60622ca7, 0x9cab5cab, 0xb2f3846e,
  3361. 0x648b1eaf, 0x19bdf0ca, 0xa02369b9, 0x655abb50,
  3362. 0x40685a32, 0x3c2ab4b3, 0x319ee9d5, 0xc021b8f7,
  3363. 0x9b540b19, 0x875fa099, 0x95f7997e, 0x623d7da8,
  3364. 0xf837889a, 0x97e32d77, 0x11ed935f, 0x16681281,
  3365. 0x0e358829, 0xc7e61fd6, 0x96dedfa1, 0x7858ba99,
  3366. 0x57f584a5, 0x1b227263, 0x9b83c3ff, 0x1ac24696,
  3367. 0xcdb30aeb, 0x532e3054, 0x8fd948e4, 0x6dbc3128,
  3368. 0x58ebf2ef, 0x34c6ffea, 0xfe28ed61, 0xee7c3c73,
  3369. 0x5d4a14d9, 0xe864b7e3, 0x42105d14, 0x203e13e0,
  3370. 0x45eee2b6, 0xa3aaabea, 0xdb6c4f15, 0xfacb4fd0,
  3371. 0xc742f442, 0xef6abbb5, 0x654f3b1d, 0x41cd2105,
  3372. 0xd81e799e, 0x86854dc7, 0xe44b476a, 0x3d816250,
  3373. 0xcf62a1f2, 0x5b8d2646, 0xfc8883a0, 0xc1c7b6a3,
  3374. 0x7f1524c3, 0x69cb7492, 0x47848a0b, 0x5692b285,
  3375. 0x095bbf00, 0xad19489d, 0x1462b174, 0x23820e00,
  3376. 0x58428d2a, 0x0c55f5ea, 0x1dadf43e, 0x233f7061,
  3377. 0x3372f092, 0x8d937e41, 0xd65fecf1, 0x6c223bdb,
  3378. 0x7cde3759, 0xcbee7460, 0x4085f2a7, 0xce77326e,
  3379. 0xa6078084, 0x19f8509e, 0xe8efd855, 0x61d99735,
  3380. 0xa969a7aa, 0xc50c06c2, 0x5a04abfc, 0x800bcadc,
  3381. 0x9e447a2e, 0xc3453484, 0xfdd56705, 0x0e1e9ec9,
  3382. 0xdb73dbd3, 0x105588cd, 0x675fda79, 0xe3674340,
  3383. 0xc5c43465, 0x713e38d8, 0x3d28f89e, 0xf16dff20,
  3384. 0x153e21e7, 0x8fb03d4a, 0xe6e39f2b, 0xdb83adf7,
  3385. 0xe93d5a68, 0x948140f7, 0xf64c261c, 0x94692934,
  3386. 0x411520f7, 0x7602d4f7, 0xbcf46b2e, 0xd4a20068,
  3387. 0xd4082471, 0x3320f46a, 0x43b7d4b7, 0x500061af,
  3388. 0x1e39f62e, 0x97244546, 0x14214f74, 0xbf8b8840,
  3389. 0x4d95fc1d, 0x96b591af, 0x70f4ddd3, 0x66a02f45,
  3390. 0xbfbc09ec, 0x03bd9785, 0x7fac6dd0, 0x31cb8504,
  3391. 0x96eb27b3, 0x55fd3941, 0xda2547e6, 0xabca0a9a,
  3392. 0x28507825, 0x530429f4, 0x0a2c86da, 0xe9b66dfb,
  3393. 0x68dc1462, 0xd7486900, 0x680ec0a4, 0x27a18dee,
  3394. 0x4f3ffea2, 0xe887ad8c, 0xb58ce006, 0x7af4d6b6,
  3395. 0xaace1e7c, 0xd3375fec, 0xce78a399, 0x406b2a42,
  3396. 0x20fe9e35, 0xd9f385b9, 0xee39d7ab, 0x3b124e8b,
  3397. 0x1dc9faf7, 0x4b6d1856, 0x26a36631, 0xeae397b2,
  3398. 0x3a6efa74, 0xdd5b4332, 0x6841e7f7, 0xca7820fb,
  3399. 0xfb0af54e, 0xd8feb397, 0x454056ac, 0xba489527,
  3400. 0x55533a3a, 0x20838d87, 0xfe6ba9b7, 0xd096954b,
  3401. 0x55a867bc, 0xa1159a58, 0xcca92963, 0x99e1db33,
  3402. 0xa62a4a56, 0x3f3125f9, 0x5ef47e1c, 0x9029317c,
  3403. 0xfdf8e802, 0x04272f70, 0x80bb155c, 0x05282ce3,
  3404. 0x95c11548, 0xe4c66d22, 0x48c1133f, 0xc70f86dc,
  3405. 0x07f9c9ee, 0x41041f0f, 0x404779a4, 0x5d886e17,
  3406. 0x325f51eb, 0xd59bc0d1, 0xf2bcc18f, 0x41113564,
  3407. 0x257b7834, 0x602a9c60, 0xdff8e8a3, 0x1f636c1b,
  3408. 0x0e12b4c2, 0x02e1329e, 0xaf664fd1, 0xcad18115,
  3409. 0x6b2395e0, 0x333e92e1, 0x3b240b62, 0xeebeb922,
  3410. 0x85b2a20e, 0xe6ba0d99, 0xde720c8c, 0x2da2f728,
  3411. 0xd0127845, 0x95b794fd, 0x647d0862, 0xe7ccf5f0,
  3412. 0x5449a36f, 0x877d48fa, 0xc39dfd27, 0xf33e8d1e,
  3413. 0x0a476341, 0x992eff74, 0x3a6f6eab, 0xf4f8fd37,
  3414. 0xa812dc60, 0xa1ebddf8, 0x991be14c, 0xdb6e6b0d,
  3415. 0xc67b5510, 0x6d672c37, 0x2765d43b, 0xdcd0e804,
  3416. 0xf1290dc7, 0xcc00ffa3, 0xb5390f92, 0x690fed0b,
  3417. 0x667b9ffb, 0xcedb7d9c, 0xa091cf0b, 0xd9155ea3,
  3418. 0xbb132f88, 0x515bad24, 0x7b9479bf, 0x763bd6eb,
  3419. 0x37392eb3, 0xcc115979, 0x8026e297, 0xf42e312d,
  3420. 0x6842ada7, 0xc66a2b3b, 0x12754ccc, 0x782ef11c,
  3421. 0x6a124237, 0xb79251e7, 0x06a1bbe6, 0x4bfb6350,
  3422. 0x1a6b1018, 0x11caedfa, 0x3d25bdd8, 0xe2e1c3c9,
  3423. 0x44421659, 0x0a121386, 0xd90cec6e, 0xd5abea2a,
  3424. 0x64af674e, 0xda86a85f, 0xbebfe988, 0x64e4c3fe,
  3425. 0x9dbc8057, 0xf0f7c086, 0x60787bf8, 0x6003604d,
  3426. 0xd1fd8346, 0xf6381fb0, 0x7745ae04, 0xd736fccc,
  3427. 0x83426b33, 0xf01eab71, 0xb0804187, 0x3c005e5f,
  3428. 0x77a057be, 0xbde8ae24, 0x55464299, 0xbf582e61,
  3429. 0x4e58f48f, 0xf2ddfda2, 0xf474ef38, 0x8789bdc2,
  3430. 0x5366f9c3, 0xc8b38e74, 0xb475f255, 0x46fcd9b9,
  3431. 0x7aeb2661, 0x8b1ddf84, 0x846a0e79, 0x915f95e2,
  3432. 0x466e598e, 0x20b45770, 0x8cd55591, 0xc902de4c,
  3433. 0xb90bace1, 0xbb8205d0, 0x11a86248, 0x7574a99e,
  3434. 0xb77f19b6, 0xe0a9dc09, 0x662d09a1, 0xc4324633,
  3435. 0xe85a1f02, 0x09f0be8c, 0x4a99a025, 0x1d6efe10,
  3436. 0x1ab93d1d, 0x0ba5a4df, 0xa186f20f, 0x2868f169,
  3437. 0xdcb7da83, 0x573906fe, 0xa1e2ce9b, 0x4fcd7f52,
  3438. 0x50115e01, 0xa70683fa, 0xa002b5c4, 0x0de6d027,
  3439. 0x9af88c27, 0x773f8641, 0xc3604c06, 0x61a806b5,
  3440. 0xf0177a28, 0xc0f586e0, 0x006058aa, 0x30dc7d62,
  3441. 0x11e69ed7, 0x2338ea63, 0x53c2dd94, 0xc2c21634,
  3442. 0xbbcbee56, 0x90bcb6de, 0xebfc7da1, 0xce591d76,
  3443. 0x6f05e409, 0x4b7c0188, 0x39720a3d, 0x7c927c24,
  3444. 0x86e3725f, 0x724d9db9, 0x1ac15bb4, 0xd39eb8fc,
  3445. 0xed545578, 0x08fca5b5, 0xd83d7cd3, 0x4dad0fc4,
  3446. 0x1e50ef5e, 0xb161e6f8, 0xa28514d9, 0x6c51133c,
  3447. 0x6fd5c7e7, 0x56e14ec4, 0x362abfce, 0xddc6c837,
  3448. 0xd79a3234, 0x92638212, 0x670efa8e, 0x406000e0,
  3449. 0x3a39ce37, 0xd3faf5cf, 0xabc27737, 0x5ac52d1b,
  3450. 0x5cb0679e, 0x4fa33742, 0xd3822740, 0x99bc9bbe,
  3451. 0xd5118e9d, 0xbf0f7315, 0xd62d1c7e, 0xc700c47b,
  3452. 0xb78c1b6b, 0x21a19045, 0xb26eb1be, 0x6a366eb4,
  3453. 0x5748ab2f, 0xbc946e79, 0xc6a376d2, 0x6549c2c8,
  3454. 0x530ff8ee, 0x468dde7d, 0xd5730a1d, 0x4cd04dc6,
  3455. 0x2939bbdb, 0xa9ba4650, 0xac9526e8, 0xbe5ee304,
  3456. 0xa1fad5f0, 0x6a2d519a, 0x63ef8ce2, 0x9a86ee22,
  3457. 0xc089c2b8, 0x43242ef6, 0xa51e03aa, 0x9cf2d0a4,
  3458. 0x83c061ba, 0x9be96a4d, 0x8fe51550, 0xba645bd6,
  3459. 0x2826a2f9, 0xa73a3ae1, 0x4ba99586, 0xef5562e9,
  3460. 0xc72fefd3, 0xf752f7da, 0x3f046f69, 0x77fa0a59,
  3461. 0x80e4a915, 0x87b08601, 0x9b09e6ad, 0x3b3ee593,
  3462. 0xe990fd5a, 0x9e34d797, 0x2cf0b7d9, 0x022b8b51,
  3463. 0x96d5ac3a, 0x017da67d, 0xd1cf3ed6, 0x7c7d2d28,
  3464. 0x1f9f25cf, 0xadf2b89b, 0x5ad6b472, 0x5a88f54c,
  3465. 0xe029ac71, 0xe019a5e6, 0x47b0acfd, 0xed93fa9b,
  3466. 0xe8d3c48d, 0x283b57cc, 0xf8d56629, 0x79132e28,
  3467. 0x785f0191, 0xed756055, 0xf7960e44, 0xe3d35e8c,
  3468. 0x15056dd4, 0x88f46dba, 0x03a16125, 0x0564f0bd,
  3469. 0xc3eb9e15, 0x3c9057a2, 0x97271aec, 0xa93a072a,
  3470. 0x1b3f6d9b, 0x1e6321f5, 0xf59c66fb, 0x26dcf319,
  3471. 0x7533d928, 0xb155fdf5, 0x03563482, 0x8aba3cbb,
  3472. 0x28517711, 0xc20ad9f8, 0xabcc5167, 0xccad925f,
  3473. 0x4de81751, 0x3830dc8e, 0x379d5862, 0x9320f991,
  3474. 0xea7a90c2, 0xfb3e7bce, 0x5121ce64, 0x774fbe32,
  3475. 0xa8b6e37e, 0xc3293d46, 0x48de5369, 0x6413e680,
  3476. 0xa2ae0810, 0xdd6db224, 0x69852dfd, 0x09072166,
  3477. 0xb39a460a, 0x6445c0dd, 0x586cdecf, 0x1c20c8ae,
  3478. 0x5bbef7dd, 0x1b588d40, 0xccd2017f, 0x6bb4e3bb,
  3479. 0xdda26a7e, 0x3a59ff45, 0x3e350a44, 0xbcb4cdd5,
  3480. 0x72eacea8, 0xfa6484bb, 0x8d6612ae, 0xbf3c6f47,
  3481. 0xd29be463, 0x542f5d9e, 0xaec2771b, 0xf64e6370,
  3482. 0x740e0d8d, 0xe75b1357, 0xf8721671, 0xaf537d5d,
  3483. 0x4040cb08, 0x4eb4e2cc, 0x34d2466a, 0x0115af84,
  3484. 0xe1b00428, 0x95983a1d, 0x06b89fb4, 0xce6ea048,
  3485. 0x6f3f3b82, 0x3520ab82, 0x011a1d4b, 0x277227f8,
  3486. 0x611560b1, 0xe7933fdc, 0xbb3a792b, 0x344525bd,
  3487. 0xa08839e1, 0x51ce794b, 0x2f32c9b7, 0xa01fbac9,
  3488. 0xe01cc87e, 0xbcc7d1f6, 0xcf0111c3, 0xa1e8aac7,
  3489. 0x1a908749, 0xd44fbd9a, 0xd0dadecb, 0xd50ada38,
  3490. 0x0339c32a, 0xc6913667, 0x8df9317c, 0xe0b12b4f,
  3491. 0xf79e59b7, 0x43f5bb3a, 0xf2d519ff, 0x27d9459c,
  3492. 0xbf97222c, 0x15e6fc2a, 0x0f91fc71, 0x9b941525,
  3493. 0xfae59361, 0xceb69ceb, 0xc2a86459, 0x12baa8d1,
  3494. 0xb6c1075e, 0xe3056a0c, 0x10d25065, 0xcb03a442,
  3495. 0xe0ec6e0e, 0x1698db3b, 0x4c98a0be, 0x3278e964,
  3496. 0x9f1f9532, 0xe0d392df, 0xd3a0342b, 0x8971f21e,
  3497. 0x1b0a7441, 0x4ba3348c, 0xc5be7120, 0xc37632d8,
  3498. 0xdf359f8d, 0x9b992f2e, 0xe60b6f47, 0x0fe3f11d,
  3499. 0xe54cda54, 0x1edad891, 0xce6279cf, 0xcd3e7e6f,
  3500. 0x1618b166, 0xfd2c1d05, 0x848fd2c5, 0xf6fb2299,
  3501. 0xf523f357, 0xa6327623, 0x93a83531, 0x56cccd02,
  3502. 0xacf08162, 0x5a75ebb5, 0x6e163697, 0x88d273cc,
  3503. 0xde966292, 0x81b949d0, 0x4c50901b, 0x71c65614,
  3504. 0xe6c6c7bd, 0x327a140a, 0x45e1d006, 0xc3f27b9a,
  3505. 0xc9aa53fd, 0x62a80f00, 0xbb25bfe2, 0x35bdd2f6,
  3506. 0x71126905, 0xb2040222, 0xb6cbcf7c, 0xcd769c2b,
  3507. 0x53113ec0, 0x1640e3d3, 0x38abbd60, 0x2547adf0,
  3508. 0xba38209c, 0xf746ce76, 0x77afa1c5, 0x20756060,
  3509. 0x85cbfe4e, 0x8ae88dd8, 0x7aaaf9b0, 0x4cf9aa7e,
  3510. 0x1948c25c, 0x02fb8a8c, 0x01c36ae4, 0xd6ebe1f9,
  3511. 0x90d4f869, 0xa65cdea0, 0x3f09252d, 0xc208e69f,
  3512. 0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6
  3513. };
  3514. BlowFish::BlowFish (const uint8* keyData, int keyBytes)
  3515. {
  3516. memcpy (p, initialPValues, sizeof (p));
  3517. int i, j;
  3518. for (i = 4; --i >= 0;)
  3519. {
  3520. s[i].malloc (256);
  3521. memcpy (s[i], initialSValues + i * 256, 256 * sizeof (uint32));
  3522. }
  3523. j = 0;
  3524. for (i = 0; i < 18; ++i)
  3525. {
  3526. uint32 d = 0;
  3527. for (int k = 0; k < 4; ++k)
  3528. {
  3529. d = (d << 8) | keyData[j];
  3530. if (++j >= keyBytes)
  3531. j = 0;
  3532. }
  3533. p[i] = initialPValues[i] ^ d;
  3534. }
  3535. uint32 l = 0, r = 0;
  3536. for (i = 0; i < 18; i += 2)
  3537. {
  3538. encrypt (l, r);
  3539. p[i] = l;
  3540. p[i + 1] = r;
  3541. }
  3542. for (i = 0; i < 4; ++i)
  3543. {
  3544. for (j = 0; j < 256; j += 2)
  3545. {
  3546. encrypt (l, r);
  3547. s[i][j] = l;
  3548. s[i][j + 1] = r;
  3549. }
  3550. }
  3551. }
  3552. BlowFish::BlowFish (const BlowFish& other)
  3553. {
  3554. for (int i = 4; --i >= 0;)
  3555. s[i].malloc (256);
  3556. operator= (other);
  3557. }
  3558. const BlowFish& BlowFish::operator= (const BlowFish& other)
  3559. {
  3560. memcpy (p, other.p, sizeof (p));
  3561. for (int i = 4; --i >= 0;)
  3562. memcpy (s[i], other.s[i], 256 * sizeof (uint32));
  3563. return *this;
  3564. }
  3565. BlowFish::~BlowFish()
  3566. {
  3567. }
  3568. uint32 BlowFish::F (uint32 x) const
  3569. {
  3570. uint16 a, b, c, d;
  3571. uint32 y;
  3572. d = (uint16) (x & 0xff);
  3573. x >>= 8;
  3574. c = (uint16) (x & 0xff);
  3575. x >>= 8;
  3576. b = (uint16) (x & 0xff);
  3577. x >>= 8;
  3578. a = (uint16) (x & 0xff);
  3579. y = s[0][a] + s[1][b];
  3580. y = y ^ s[2][c];
  3581. y = y + s[3][d];
  3582. return y;
  3583. }
  3584. void BlowFish::encrypt (uint32& data1,
  3585. uint32& data2) const
  3586. {
  3587. uint32 l = data1;
  3588. uint32 r = data2;
  3589. for (int i = 0; i < 16; ++i)
  3590. {
  3591. l = l ^ p[i];
  3592. r = F (l) ^ r;
  3593. const uint32 temp = l;
  3594. l = r;
  3595. r = temp;
  3596. }
  3597. const uint32 temp = l;
  3598. l = r;
  3599. r = temp;
  3600. r = r ^ p[16];
  3601. l = l ^ p[17];
  3602. data1 = l;
  3603. data2 = r;
  3604. }
  3605. void BlowFish::decrypt (uint32& data1,
  3606. uint32& data2) const
  3607. {
  3608. uint32 l = data1;
  3609. uint32 r = data2;
  3610. for (int i = 17; i > 1; --i)
  3611. {
  3612. l =l ^ p[i];
  3613. r = F (l) ^ r;
  3614. const uint32 temp = l;
  3615. l = r;
  3616. r = temp;
  3617. }
  3618. const uint32 temp = l;
  3619. l = r;
  3620. r = temp;
  3621. r = r ^ p[1];
  3622. l = l ^ p[0];
  3623. data1 = l;
  3624. data2 = r;
  3625. }
  3626. END_JUCE_NAMESPACE
  3627. /*** End of inlined file: juce_BlowFish.cpp ***/
  3628. /*** Start of inlined file: juce_MD5.cpp ***/
  3629. BEGIN_JUCE_NAMESPACE
  3630. MD5::MD5()
  3631. {
  3632. zeromem (result, sizeof (result));
  3633. }
  3634. MD5::MD5 (const MD5& other)
  3635. {
  3636. memcpy (result, other.result, sizeof (result));
  3637. }
  3638. const MD5& MD5::operator= (const MD5& other)
  3639. {
  3640. memcpy (result, other.result, sizeof (result));
  3641. return *this;
  3642. }
  3643. MD5::MD5 (const MemoryBlock& data)
  3644. {
  3645. ProcessContext context;
  3646. context.processBlock ((const uint8*) data.getData(), data.getSize());
  3647. context.finish (result);
  3648. }
  3649. MD5::MD5 (const char* data, const size_t numBytes)
  3650. {
  3651. ProcessContext context;
  3652. context.processBlock ((const uint8*) data, numBytes);
  3653. context.finish (result);
  3654. }
  3655. MD5::MD5 (const String& text)
  3656. {
  3657. ProcessContext context;
  3658. const int len = text.length();
  3659. const juce_wchar* const t = text;
  3660. for (int i = 0; i < len; ++i)
  3661. {
  3662. // force the string into integer-sized unicode characters, to try to make it
  3663. // get the same results on all platforms + compilers.
  3664. uint32 unicodeChar = (uint32) t[i];
  3665. ByteOrder::swapIfBigEndian (unicodeChar);
  3666. context.processBlock ((const uint8*) &unicodeChar,
  3667. sizeof (unicodeChar));
  3668. }
  3669. context.finish (result);
  3670. }
  3671. void MD5::processStream (InputStream& input, int64 numBytesToRead)
  3672. {
  3673. ProcessContext context;
  3674. if (numBytesToRead < 0)
  3675. numBytesToRead = std::numeric_limits<int64>::max();
  3676. while (numBytesToRead > 0)
  3677. {
  3678. char tempBuffer [512];
  3679. const int bytesRead = input.read (tempBuffer, (int) jmin (numBytesToRead, (int64) sizeof (tempBuffer)));
  3680. if (bytesRead <= 0)
  3681. break;
  3682. numBytesToRead -= bytesRead;
  3683. context.processBlock ((const uint8*) tempBuffer, bytesRead);
  3684. }
  3685. context.finish (result);
  3686. }
  3687. MD5::MD5 (InputStream& input, int64 numBytesToRead)
  3688. {
  3689. processStream (input, numBytesToRead);
  3690. }
  3691. MD5::MD5 (const File& file)
  3692. {
  3693. const ScopedPointer <FileInputStream> fin (file.createInputStream());
  3694. if (fin != 0)
  3695. processStream (*fin, -1);
  3696. else
  3697. zeromem (result, sizeof (result));
  3698. }
  3699. MD5::~MD5()
  3700. {
  3701. }
  3702. MD5::ProcessContext::ProcessContext()
  3703. {
  3704. state[0] = 0x67452301;
  3705. state[1] = 0xefcdab89;
  3706. state[2] = 0x98badcfe;
  3707. state[3] = 0x10325476;
  3708. count[0] = 0;
  3709. count[1] = 0;
  3710. }
  3711. void MD5::ProcessContext::processBlock (const uint8* const data, size_t dataSize)
  3712. {
  3713. int bufferPos = ((count[0] >> 3) & 0x3F);
  3714. count[0] += (uint32) (dataSize << 3);
  3715. if (count[0] < ((uint32) dataSize << 3))
  3716. count[1]++;
  3717. count[1] += (uint32) (dataSize >> 29);
  3718. const size_t spaceLeft = 64 - bufferPos;
  3719. size_t i = 0;
  3720. if (dataSize >= spaceLeft)
  3721. {
  3722. memcpy (buffer + bufferPos, data, spaceLeft);
  3723. transform (buffer);
  3724. i = spaceLeft;
  3725. while (i + 64 <= dataSize)
  3726. {
  3727. transform (data + i);
  3728. i += 64;
  3729. }
  3730. bufferPos = 0;
  3731. }
  3732. memcpy (buffer + bufferPos, data + i, dataSize - i);
  3733. }
  3734. static void encode (uint8* const output,
  3735. const uint32* const input,
  3736. const int numBytes)
  3737. {
  3738. uint32* const o = (uint32*) output;
  3739. for (int i = 0; i < (numBytes >> 2); ++i)
  3740. o[i] = ByteOrder::swapIfBigEndian (input [i]);
  3741. }
  3742. static void decode (uint32* const output,
  3743. const uint8* const input,
  3744. const int numBytes)
  3745. {
  3746. for (int i = 0; i < (numBytes >> 2); ++i)
  3747. output[i] = ByteOrder::littleEndianInt ((const char*) input + (i << 2));
  3748. }
  3749. void MD5::ProcessContext::finish (uint8* const result)
  3750. {
  3751. unsigned char encodedLength[8];
  3752. encode (encodedLength, count, 8);
  3753. // Pad out to 56 mod 64.
  3754. const int index = (uint32) ((count[0] >> 3) & 0x3f);
  3755. const int paddingLength = (index < 56) ? (56 - index)
  3756. : (120 - index);
  3757. uint8 paddingBuffer [64];
  3758. zeromem (paddingBuffer, paddingLength);
  3759. paddingBuffer [0] = 0x80;
  3760. processBlock (paddingBuffer, paddingLength);
  3761. processBlock (encodedLength, 8);
  3762. encode (result, state, 16);
  3763. zeromem (buffer, sizeof (buffer));
  3764. }
  3765. #define S11 7
  3766. #define S12 12
  3767. #define S13 17
  3768. #define S14 22
  3769. #define S21 5
  3770. #define S22 9
  3771. #define S23 14
  3772. #define S24 20
  3773. #define S31 4
  3774. #define S32 11
  3775. #define S33 16
  3776. #define S34 23
  3777. #define S41 6
  3778. #define S42 10
  3779. #define S43 15
  3780. #define S44 21
  3781. static inline uint32 F (const uint32 x, const uint32 y, const uint32 z) { return (x & y) | (~x & z); }
  3782. static inline uint32 G (const uint32 x, const uint32 y, const uint32 z) { return (x & z) | (y & ~z); }
  3783. static inline uint32 H (const uint32 x, const uint32 y, const uint32 z) { return x ^ y ^ z; }
  3784. static inline uint32 I (const uint32 x, const uint32 y, const uint32 z) { return y ^ (x | ~z); }
  3785. static inline uint32 rotateLeft (const uint32 x, const uint32 n) { return (x << n) | (x >> (32 - n)); }
  3786. static inline void FF (uint32& a, const uint32 b, const uint32 c, const uint32 d, const uint32 x, const uint32 s, const uint32 ac)
  3787. {
  3788. a += F (b, c, d) + x + ac;
  3789. a = rotateLeft (a, s) + b;
  3790. }
  3791. static inline void GG (uint32& a, const uint32 b, const uint32 c, const uint32 d, const uint32 x, const uint32 s, const uint32 ac)
  3792. {
  3793. a += G (b, c, d) + x + ac;
  3794. a = rotateLeft (a, s) + b;
  3795. }
  3796. static inline void HH (uint32& a, const uint32 b, const uint32 c, const uint32 d, const uint32 x, const uint32 s, const uint32 ac)
  3797. {
  3798. a += H (b, c, d) + x + ac;
  3799. a = rotateLeft (a, s) + b;
  3800. }
  3801. static inline void II (uint32& a, const uint32 b, const uint32 c, const uint32 d, const uint32 x, const uint32 s, const uint32 ac)
  3802. {
  3803. a += I (b, c, d) + x + ac;
  3804. a = rotateLeft (a, s) + b;
  3805. }
  3806. void MD5::ProcessContext::transform (const uint8* const bufferToTransform)
  3807. {
  3808. uint32 a = state[0];
  3809. uint32 b = state[1];
  3810. uint32 c = state[2];
  3811. uint32 d = state[3];
  3812. uint32 x[16];
  3813. decode (x, bufferToTransform, 64);
  3814. FF (a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */
  3815. FF (d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */
  3816. FF (c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */
  3817. FF (b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */
  3818. FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */
  3819. FF (d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */
  3820. FF (c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */
  3821. FF (b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */
  3822. FF (a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */
  3823. FF (d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */
  3824. FF (c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */
  3825. FF (b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */
  3826. FF (a, b, c, d, x[12], S11, 0x6b901122); /* 13 */
  3827. FF (d, a, b, c, x[13], S12, 0xfd987193); /* 14 */
  3828. FF (c, d, a, b, x[14], S13, 0xa679438e); /* 15 */
  3829. FF (b, c, d, a, x[15], S14, 0x49b40821); /* 16 */
  3830. GG (a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */
  3831. GG (d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */
  3832. GG (c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */
  3833. GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */
  3834. GG (a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */
  3835. GG (d, a, b, c, x[10], S22, 0x2441453); /* 22 */
  3836. GG (c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */
  3837. GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */
  3838. GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */
  3839. GG (d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */
  3840. GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */
  3841. GG (b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */
  3842. GG (a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */
  3843. GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */
  3844. GG (c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */
  3845. GG (b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */
  3846. HH (a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */
  3847. HH (d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */
  3848. HH (c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */
  3849. HH (b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */
  3850. HH (a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */
  3851. HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */
  3852. HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */
  3853. HH (b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */
  3854. HH (a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */
  3855. HH (d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */
  3856. HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */
  3857. HH (b, c, d, a, x[ 6], S34, 0x4881d05); /* 44 */
  3858. HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */
  3859. HH (d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */
  3860. HH (c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */
  3861. HH (b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */
  3862. II (a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */
  3863. II (d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */
  3864. II (c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */
  3865. II (b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */
  3866. II (a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */
  3867. II (d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */
  3868. II (c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */
  3869. II (b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */
  3870. II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */
  3871. II (d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */
  3872. II (c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */
  3873. II (b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */
  3874. II (a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */
  3875. II (d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */
  3876. II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */
  3877. II (b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */
  3878. state[0] += a;
  3879. state[1] += b;
  3880. state[2] += c;
  3881. state[3] += d;
  3882. zeromem (x, sizeof (x));
  3883. }
  3884. const MemoryBlock MD5::getRawChecksumData() const
  3885. {
  3886. return MemoryBlock (result, 16);
  3887. }
  3888. const String MD5::toHexString() const
  3889. {
  3890. return String::toHexString (result, 16, 0);
  3891. }
  3892. bool MD5::operator== (const MD5& other) const
  3893. {
  3894. return memcmp (result, other.result, 16) == 0;
  3895. }
  3896. bool MD5::operator!= (const MD5& other) const
  3897. {
  3898. return ! operator== (other);
  3899. }
  3900. END_JUCE_NAMESPACE
  3901. /*** End of inlined file: juce_MD5.cpp ***/
  3902. /*** Start of inlined file: juce_Primes.cpp ***/
  3903. BEGIN_JUCE_NAMESPACE
  3904. static void createSmallSieve (const int numBits, BitArray& result) throw()
  3905. {
  3906. result.setBit (numBits);
  3907. result.clearBit (numBits); // to enlarge the array
  3908. result.setBit (0);
  3909. int n = 2;
  3910. do
  3911. {
  3912. for (int i = n + n; i < numBits; i += n)
  3913. result.setBit (i);
  3914. n = result.findNextClearBit (n + 1);
  3915. }
  3916. while (n <= (numBits >> 1));
  3917. }
  3918. static void bigSieve (const BitArray& base,
  3919. const int numBits,
  3920. BitArray& result,
  3921. const BitArray& smallSieve,
  3922. const int smallSieveSize) throw()
  3923. {
  3924. jassert (! base[0]); // must be even!
  3925. result.setBit (numBits);
  3926. result.clearBit (numBits); // to enlarge the array
  3927. int index = smallSieve.findNextClearBit (0);
  3928. do
  3929. {
  3930. const int prime = (index << 1) + 1;
  3931. BitArray r (base);
  3932. BitArray remainder;
  3933. r.divideBy (prime, remainder);
  3934. int i = prime - remainder.getBitRangeAsInt (0, 32);
  3935. if (r.isEmpty())
  3936. i += prime;
  3937. if ((i & 1) == 0)
  3938. i += prime;
  3939. i = (i - 1) >> 1;
  3940. while (i < numBits)
  3941. {
  3942. result.setBit (i);
  3943. i += prime;
  3944. }
  3945. index = smallSieve.findNextClearBit (index + 1);
  3946. }
  3947. while (index < smallSieveSize);
  3948. }
  3949. static bool findCandidate (const BitArray& base,
  3950. const BitArray& sieve,
  3951. const int numBits,
  3952. BitArray& result,
  3953. const int certainty) throw()
  3954. {
  3955. for (int i = 0; i < numBits; ++i)
  3956. {
  3957. if (! sieve[i])
  3958. {
  3959. result = base;
  3960. result.add (BitArray ((unsigned int) ((i << 1) + 1)));
  3961. if (Primes::isProbablyPrime (result, certainty))
  3962. return true;
  3963. }
  3964. }
  3965. return false;
  3966. }
  3967. const BitArray Primes::createProbablePrime (const int bitLength,
  3968. const int certainty,
  3969. const int* randomSeeds,
  3970. int numRandomSeeds) throw()
  3971. {
  3972. int defaultSeeds [16];
  3973. if (numRandomSeeds <= 0)
  3974. {
  3975. randomSeeds = defaultSeeds;
  3976. numRandomSeeds = numElementsInArray (defaultSeeds);
  3977. Random r (0);
  3978. for (int j = 10; --j >= 0;)
  3979. {
  3980. r.setSeedRandomly();
  3981. for (int i = numRandomSeeds; --i >= 0;)
  3982. defaultSeeds[i] ^= r.nextInt() ^ Random::getSystemRandom().nextInt();
  3983. }
  3984. }
  3985. BitArray smallSieve;
  3986. const int smallSieveSize = 15000;
  3987. createSmallSieve (smallSieveSize, smallSieve);
  3988. BitArray p;
  3989. for (int i = numRandomSeeds; --i >= 0;)
  3990. {
  3991. BitArray p2;
  3992. Random r (randomSeeds[i]);
  3993. r.fillBitsRandomly (p2, 0, bitLength);
  3994. p.xorWith (p2);
  3995. }
  3996. p.setBit (bitLength - 1);
  3997. p.clearBit (0);
  3998. const int searchLen = jmax (1024, (bitLength / 20) * 64);
  3999. while (p.getHighestBit() < bitLength)
  4000. {
  4001. p.add (2 * searchLen);
  4002. BitArray sieve;
  4003. bigSieve (p, searchLen, sieve,
  4004. smallSieve, smallSieveSize);
  4005. BitArray candidate;
  4006. if (findCandidate (p, sieve, searchLen, candidate, certainty))
  4007. return candidate;
  4008. }
  4009. jassertfalse
  4010. return BitArray();
  4011. }
  4012. static bool passesMillerRabin (const BitArray& n, int iterations) throw()
  4013. {
  4014. const BitArray one (1);
  4015. const BitArray two (2);
  4016. BitArray nMinusOne (n);
  4017. nMinusOne.subtract (one);
  4018. BitArray d (nMinusOne);
  4019. const int s = d.findNextSetBit (0);
  4020. d.shiftBits (-s);
  4021. BitArray smallPrimes;
  4022. int numBitsInSmallPrimes = 0;
  4023. for (;;)
  4024. {
  4025. numBitsInSmallPrimes += 256;
  4026. createSmallSieve (numBitsInSmallPrimes, smallPrimes);
  4027. const int numPrimesFound = numBitsInSmallPrimes - smallPrimes.countNumberOfSetBits();
  4028. if (numPrimesFound > iterations + 1)
  4029. break;
  4030. }
  4031. int smallPrime = 2;
  4032. while (--iterations >= 0)
  4033. {
  4034. smallPrime = smallPrimes.findNextClearBit (smallPrime + 1);
  4035. BitArray r (smallPrime);
  4036. //r.createRandomNumber (nMinusOne);
  4037. r.exponentModulo (d, n);
  4038. if (! (r == one || r == nMinusOne))
  4039. {
  4040. for (int j = 0; j < s; ++j)
  4041. {
  4042. r.exponentModulo (two, n);
  4043. if (r == nMinusOne)
  4044. break;
  4045. }
  4046. if (r != nMinusOne)
  4047. return false;
  4048. }
  4049. }
  4050. return true;
  4051. }
  4052. bool Primes::isProbablyPrime (const BitArray& number,
  4053. const int certainty) throw()
  4054. {
  4055. if (! number[0])
  4056. return false;
  4057. if (number.getHighestBit() <= 10)
  4058. {
  4059. const int num = number.getBitRangeAsInt (0, 10);
  4060. for (int i = num / 2; --i > 1;)
  4061. if (num % i == 0)
  4062. return false;
  4063. return true;
  4064. }
  4065. else
  4066. {
  4067. const BitArray screen (2 * 3 * 5 * 7 * 11 * 13 * 17 * 19 * 23);
  4068. if (number.findGreatestCommonDivisor (screen) != BitArray (1))
  4069. return false;
  4070. return passesMillerRabin (number, certainty);
  4071. }
  4072. }
  4073. END_JUCE_NAMESPACE
  4074. /*** End of inlined file: juce_Primes.cpp ***/
  4075. /*** Start of inlined file: juce_RSAKey.cpp ***/
  4076. BEGIN_JUCE_NAMESPACE
  4077. RSAKey::RSAKey() throw()
  4078. {
  4079. }
  4080. RSAKey::RSAKey (const String& s) throw()
  4081. {
  4082. if (s.containsChar (T(',')))
  4083. {
  4084. part1.parseString (s.upToFirstOccurrenceOf (T(","), false, false), 16);
  4085. part2.parseString (s.fromFirstOccurrenceOf (T(","), false, false), 16);
  4086. }
  4087. else
  4088. {
  4089. // the string needs to be two hex numbers, comma-separated..
  4090. jassertfalse;
  4091. }
  4092. }
  4093. RSAKey::~RSAKey() throw()
  4094. {
  4095. }
  4096. const String RSAKey::toString() const throw()
  4097. {
  4098. return part1.toString (16) + T(",") + part2.toString (16);
  4099. }
  4100. bool RSAKey::applyToValue (BitArray& value) const throw()
  4101. {
  4102. if (part1.isEmpty() || part2.isEmpty()
  4103. || value.compare (0) <= 0)
  4104. {
  4105. jassertfalse // using an uninitialised key
  4106. value.clear();
  4107. return false;
  4108. }
  4109. BitArray result;
  4110. while (! value.isEmpty())
  4111. {
  4112. result.multiplyBy (part2);
  4113. BitArray remainder;
  4114. value.divideBy (part2, remainder);
  4115. remainder.exponentModulo (part1, part2);
  4116. result.add (remainder);
  4117. }
  4118. value = result;
  4119. return true;
  4120. }
  4121. static const BitArray findBestCommonDivisor (const BitArray& p,
  4122. const BitArray& q) throw()
  4123. {
  4124. const BitArray one (1);
  4125. // try 3, 5, 9, 17, etc first because these only contain 2 bits and so
  4126. // are fast to divide + multiply
  4127. for (int i = 2; i <= 65536; i *= 2)
  4128. {
  4129. const BitArray e (1 + i);
  4130. if (e.findGreatestCommonDivisor (p) == one
  4131. && e.findGreatestCommonDivisor (q) == one)
  4132. {
  4133. return e;
  4134. }
  4135. }
  4136. BitArray e (4);
  4137. while (! (e.findGreatestCommonDivisor (p) == one
  4138. && e.findGreatestCommonDivisor (q) == one))
  4139. {
  4140. e.add (one);
  4141. }
  4142. return e;
  4143. }
  4144. void RSAKey::createKeyPair (RSAKey& publicKey,
  4145. RSAKey& privateKey,
  4146. const int numBits,
  4147. const int* randomSeeds,
  4148. const int numRandomSeeds) throw()
  4149. {
  4150. jassert (numBits > 16); // not much point using less than this..
  4151. BitArray p (Primes::createProbablePrime (numBits / 2, 30, randomSeeds, numRandomSeeds));
  4152. BitArray q (Primes::createProbablePrime (numBits - numBits / 2, 30, randomSeeds, numRandomSeeds));
  4153. BitArray n (p);
  4154. n.multiplyBy (q); // n = pq
  4155. const BitArray one (1);
  4156. p.subtract (one);
  4157. q.subtract (one);
  4158. BitArray m (p);
  4159. m.multiplyBy (q); // m = (p - 1)(q - 1)
  4160. const BitArray e (findBestCommonDivisor (p, q));
  4161. BitArray d (e);
  4162. d.inverseModulo (m);
  4163. publicKey.part1 = e;
  4164. publicKey.part2 = n;
  4165. privateKey.part1 = d;
  4166. privateKey.part2 = n;
  4167. }
  4168. END_JUCE_NAMESPACE
  4169. /*** End of inlined file: juce_RSAKey.cpp ***/
  4170. /*** Start of inlined file: juce_InputStream.cpp ***/
  4171. BEGIN_JUCE_NAMESPACE
  4172. char InputStream::readByte()
  4173. {
  4174. char temp = 0;
  4175. read (&temp, 1);
  4176. return temp;
  4177. }
  4178. bool InputStream::readBool()
  4179. {
  4180. return readByte() != 0;
  4181. }
  4182. short InputStream::readShort()
  4183. {
  4184. char temp [2];
  4185. if (read (temp, 2) == 2)
  4186. return (short) ByteOrder::littleEndianShort (temp);
  4187. else
  4188. return 0;
  4189. }
  4190. short InputStream::readShortBigEndian()
  4191. {
  4192. char temp [2];
  4193. if (read (temp, 2) == 2)
  4194. return (short) ByteOrder::bigEndianShort (temp);
  4195. else
  4196. return 0;
  4197. }
  4198. int InputStream::readInt()
  4199. {
  4200. char temp [4];
  4201. if (read (temp, 4) == 4)
  4202. return (int) ByteOrder::littleEndianInt (temp);
  4203. else
  4204. return 0;
  4205. }
  4206. int InputStream::readIntBigEndian()
  4207. {
  4208. char temp [4];
  4209. if (read (temp, 4) == 4)
  4210. return (int) ByteOrder::bigEndianInt (temp);
  4211. else
  4212. return 0;
  4213. }
  4214. int InputStream::readCompressedInt()
  4215. {
  4216. const unsigned char sizeByte = readByte();
  4217. if (sizeByte == 0)
  4218. return 0;
  4219. const int numBytes = (sizeByte & 0x7f);
  4220. if (numBytes > 4)
  4221. {
  4222. jassertfalse // trying to read corrupt data - this method must only be used
  4223. // to read data that was written by OutputStream::writeCompressedInt()
  4224. return 0;
  4225. }
  4226. char bytes[4] = { 0, 0, 0, 0 };
  4227. if (read (bytes, numBytes) != numBytes)
  4228. return 0;
  4229. const int num = (int) ByteOrder::littleEndianInt (bytes);
  4230. return (sizeByte >> 7) ? -num : num;
  4231. }
  4232. int64 InputStream::readInt64()
  4233. {
  4234. char temp [8];
  4235. if (read (temp, 8) == 8)
  4236. return (int64) ByteOrder::swapIfBigEndian (*(uint64*) temp);
  4237. else
  4238. return 0;
  4239. }
  4240. int64 InputStream::readInt64BigEndian()
  4241. {
  4242. char temp [8];
  4243. if (read (temp, 8) == 8)
  4244. return (int64) ByteOrder::swapIfLittleEndian (*(uint64*) temp);
  4245. else
  4246. return 0;
  4247. }
  4248. float InputStream::readFloat()
  4249. {
  4250. union { int asInt; float asFloat; } n;
  4251. n.asInt = readInt();
  4252. return n.asFloat;
  4253. }
  4254. float InputStream::readFloatBigEndian()
  4255. {
  4256. union { int asInt; float asFloat; } n;
  4257. n.asInt = readIntBigEndian();
  4258. return n.asFloat;
  4259. }
  4260. double InputStream::readDouble()
  4261. {
  4262. union { int64 asInt; double asDouble; } n;
  4263. n.asInt = readInt64();
  4264. return n.asDouble;
  4265. }
  4266. double InputStream::readDoubleBigEndian()
  4267. {
  4268. union { int64 asInt; double asDouble; } n;
  4269. n.asInt = readInt64BigEndian();
  4270. return n.asDouble;
  4271. }
  4272. const String InputStream::readString()
  4273. {
  4274. MemoryBlock buffer (256);
  4275. uint8* data = (uint8*) buffer.getData();
  4276. size_t i = 0;
  4277. while ((data[i] = readByte()) != 0)
  4278. {
  4279. if (++i >= buffer.getSize())
  4280. {
  4281. buffer.setSize (buffer.getSize() + 512);
  4282. data = (uint8*) buffer.getData();
  4283. }
  4284. }
  4285. return String::fromUTF8 (data, (int) i);
  4286. }
  4287. const String InputStream::readNextLine()
  4288. {
  4289. MemoryBlock buffer (256);
  4290. uint8* data = (uint8*) buffer.getData();
  4291. size_t i = 0;
  4292. while ((data[i] = readByte()) != 0)
  4293. {
  4294. if (data[i] == '\n')
  4295. break;
  4296. if (data[i] == '\r')
  4297. {
  4298. const int64 lastPos = getPosition();
  4299. if (readByte() != '\n')
  4300. setPosition (lastPos);
  4301. break;
  4302. }
  4303. if (++i >= buffer.getSize())
  4304. {
  4305. buffer.setSize (buffer.getSize() + 512);
  4306. data = (uint8*) buffer.getData();
  4307. }
  4308. }
  4309. return String::fromUTF8 (data, (int) i);
  4310. }
  4311. int InputStream::readIntoMemoryBlock (MemoryBlock& block,
  4312. int numBytes)
  4313. {
  4314. const int64 totalLength = getTotalLength();
  4315. if (totalLength >= 0)
  4316. {
  4317. const int totalBytesRemaining = (int) jmin ((int64) 0x7fffffff,
  4318. totalLength - getPosition());
  4319. if (numBytes < 0)
  4320. numBytes = totalBytesRemaining;
  4321. else if (numBytes > 0)
  4322. numBytes = jmin (numBytes, totalBytesRemaining);
  4323. else
  4324. return 0;
  4325. }
  4326. const size_t originalBlockSize = block.getSize();
  4327. int totalBytesRead = 0;
  4328. if (numBytes > 0)
  4329. {
  4330. // know how many bytes we want, so we can resize the block first..
  4331. block.setSize (originalBlockSize + numBytes, false);
  4332. totalBytesRead = read (((char*) block.getData()) + originalBlockSize, numBytes);
  4333. }
  4334. else
  4335. {
  4336. // read until end of stram..
  4337. const int chunkSize = 32768;
  4338. for (;;)
  4339. {
  4340. block.ensureSize (originalBlockSize + totalBytesRead + chunkSize, false);
  4341. const int bytesJustIn = read (((char*) block.getData())
  4342. + originalBlockSize
  4343. + totalBytesRead,
  4344. chunkSize);
  4345. if (bytesJustIn == 0)
  4346. break;
  4347. totalBytesRead += bytesJustIn;
  4348. }
  4349. }
  4350. // trim off any excess left at the end
  4351. block.setSize (originalBlockSize + totalBytesRead, false);
  4352. return totalBytesRead;
  4353. }
  4354. const String InputStream::readEntireStreamAsString()
  4355. {
  4356. MemoryBlock mb;
  4357. const int size = readIntoMemoryBlock (mb);
  4358. return String::createStringFromData ((const char*) mb.getData(), size);
  4359. }
  4360. void InputStream::skipNextBytes (int64 numBytesToSkip)
  4361. {
  4362. if (numBytesToSkip > 0)
  4363. {
  4364. const int skipBufferSize = (int) jmin (numBytesToSkip, (int64) 16384);
  4365. HeapBlock <char> temp (skipBufferSize);
  4366. while (numBytesToSkip > 0 && ! isExhausted())
  4367. numBytesToSkip -= read (temp, (int) jmin (numBytesToSkip, (int64) skipBufferSize));
  4368. }
  4369. }
  4370. END_JUCE_NAMESPACE
  4371. /*** End of inlined file: juce_InputStream.cpp ***/
  4372. /*** Start of inlined file: juce_OutputStream.cpp ***/
  4373. BEGIN_JUCE_NAMESPACE
  4374. #if JUCE_DEBUG
  4375. static CriticalSection activeStreamLock;
  4376. static VoidArray activeStreams;
  4377. void juce_CheckForDanglingStreams()
  4378. {
  4379. /*
  4380. It's always a bad idea to leak any object, but if you're leaking output
  4381. streams, then there's a good chance that you're failing to flush a file
  4382. to disk properly, which could result in corrupted data and other similar
  4383. nastiness..
  4384. */
  4385. jassert (activeStreams.size() == 0);
  4386. };
  4387. #endif
  4388. OutputStream::OutputStream() throw()
  4389. {
  4390. #if JUCE_DEBUG
  4391. activeStreamLock.enter();
  4392. activeStreams.add (this);
  4393. activeStreamLock.exit();
  4394. #endif
  4395. }
  4396. OutputStream::~OutputStream()
  4397. {
  4398. #if JUCE_DEBUG
  4399. activeStreamLock.enter();
  4400. activeStreams.removeValue (this);
  4401. activeStreamLock.exit();
  4402. #endif
  4403. }
  4404. void OutputStream::writeBool (bool b)
  4405. {
  4406. writeByte ((b) ? (char) 1
  4407. : (char) 0);
  4408. }
  4409. void OutputStream::writeByte (char byte)
  4410. {
  4411. write (&byte, 1);
  4412. }
  4413. void OutputStream::writeShort (short value)
  4414. {
  4415. const unsigned short v = ByteOrder::swapIfBigEndian ((unsigned short) value);
  4416. write (&v, 2);
  4417. }
  4418. void OutputStream::writeShortBigEndian (short value)
  4419. {
  4420. const unsigned short v = ByteOrder::swapIfLittleEndian ((unsigned short) value);
  4421. write (&v, 2);
  4422. }
  4423. void OutputStream::writeInt (int value)
  4424. {
  4425. const unsigned int v = ByteOrder::swapIfBigEndian ((unsigned int) value);
  4426. write (&v, 4);
  4427. }
  4428. void OutputStream::writeIntBigEndian (int value)
  4429. {
  4430. const unsigned int v = ByteOrder::swapIfLittleEndian ((unsigned int) value);
  4431. write (&v, 4);
  4432. }
  4433. void OutputStream::writeCompressedInt (int value)
  4434. {
  4435. unsigned int un = (value < 0) ? (unsigned int) -value
  4436. : (unsigned int) value;
  4437. uint8 data[5];
  4438. int num = 0;
  4439. while (un > 0)
  4440. {
  4441. data[++num] = (uint8) un;
  4442. un >>= 8;
  4443. }
  4444. data[0] = (uint8) num;
  4445. if (value < 0)
  4446. data[0] |= 0x80;
  4447. write (data, num + 1);
  4448. }
  4449. void OutputStream::writeInt64 (int64 value)
  4450. {
  4451. const uint64 v = ByteOrder::swapIfBigEndian ((uint64) value);
  4452. write (&v, 8);
  4453. }
  4454. void OutputStream::writeInt64BigEndian (int64 value)
  4455. {
  4456. const uint64 v = ByteOrder::swapIfLittleEndian ((uint64) value);
  4457. write (&v, 8);
  4458. }
  4459. void OutputStream::writeFloat (float value)
  4460. {
  4461. union { int asInt; float asFloat; } n;
  4462. n.asFloat = value;
  4463. writeInt (n.asInt);
  4464. }
  4465. void OutputStream::writeFloatBigEndian (float value)
  4466. {
  4467. union { int asInt; float asFloat; } n;
  4468. n.asFloat = value;
  4469. writeIntBigEndian (n.asInt);
  4470. }
  4471. void OutputStream::writeDouble (double value)
  4472. {
  4473. union { int64 asInt; double asDouble; } n;
  4474. n.asDouble = value;
  4475. writeInt64 (n.asInt);
  4476. }
  4477. void OutputStream::writeDoubleBigEndian (double value)
  4478. {
  4479. union { int64 asInt; double asDouble; } n;
  4480. n.asDouble = value;
  4481. writeInt64BigEndian (n.asInt);
  4482. }
  4483. void OutputStream::writeString (const String& text)
  4484. {
  4485. const int numBytes = text.copyToUTF8 (0);
  4486. HeapBlock <uint8> temp (numBytes);
  4487. text.copyToUTF8 (temp);
  4488. write (temp, numBytes); // (numBytes includes the terminating null).
  4489. }
  4490. void OutputStream::printf (const char* pf, ...)
  4491. {
  4492. unsigned int bufSize = 256;
  4493. HeapBlock <char> buf (bufSize);
  4494. for (;;)
  4495. {
  4496. va_list list;
  4497. va_start (list, pf);
  4498. const int num = CharacterFunctions::vprintf (buf, bufSize, pf, list);
  4499. va_end (list);
  4500. if (num > 0)
  4501. {
  4502. write (buf, num);
  4503. break;
  4504. }
  4505. else if (num == 0)
  4506. {
  4507. break;
  4508. }
  4509. bufSize += 256;
  4510. buf.malloc (bufSize);
  4511. }
  4512. }
  4513. OutputStream& OutputStream::operator<< (const int number)
  4514. {
  4515. const String s (number);
  4516. write ((const char*) s, s.length());
  4517. return *this;
  4518. }
  4519. OutputStream& OutputStream::operator<< (const double number)
  4520. {
  4521. const String s (number);
  4522. write ((const char*) s, s.length());
  4523. return *this;
  4524. }
  4525. OutputStream& OutputStream::operator<< (const char character)
  4526. {
  4527. writeByte (character);
  4528. return *this;
  4529. }
  4530. OutputStream& OutputStream::operator<< (const char* const text)
  4531. {
  4532. write (text, (int) strlen (text));
  4533. return *this;
  4534. }
  4535. OutputStream& OutputStream::operator<< (const juce_wchar* const text)
  4536. {
  4537. const String s (text);
  4538. write ((const char*) s, s.length());
  4539. return *this;
  4540. }
  4541. OutputStream& OutputStream::operator<< (const String& text)
  4542. {
  4543. write ((const char*) text,
  4544. text.length());
  4545. return *this;
  4546. }
  4547. void OutputStream::writeText (const String& text,
  4548. const bool asUnicode,
  4549. const bool writeUnicodeHeaderBytes)
  4550. {
  4551. if (asUnicode)
  4552. {
  4553. if (writeUnicodeHeaderBytes)
  4554. write ("\x0ff\x0fe", 2);
  4555. const juce_wchar* src = (const juce_wchar*) text;
  4556. bool lastCharWasReturn = false;
  4557. while (*src != 0)
  4558. {
  4559. if (*src == L'\n' && ! lastCharWasReturn)
  4560. writeShort ((short) L'\r');
  4561. lastCharWasReturn = (*src == L'\r');
  4562. writeShort ((short) *src++);
  4563. }
  4564. }
  4565. else
  4566. {
  4567. const char* src = (const char*) text;
  4568. const char* t = src;
  4569. for (;;)
  4570. {
  4571. if (*t == '\n')
  4572. {
  4573. if (t > src)
  4574. write (src, (int) (t - src));
  4575. write ("\r\n", 2);
  4576. src = t + 1;
  4577. }
  4578. else if (*t == '\r')
  4579. {
  4580. if (t[1] == '\n')
  4581. ++t;
  4582. }
  4583. else if (*t == 0)
  4584. {
  4585. if (t > src)
  4586. write (src, (int) (t - src));
  4587. break;
  4588. }
  4589. ++t;
  4590. }
  4591. }
  4592. }
  4593. int OutputStream::writeFromInputStream (InputStream& source,
  4594. int numBytesToWrite)
  4595. {
  4596. if (numBytesToWrite < 0)
  4597. numBytesToWrite = 0x7fffffff;
  4598. int numWritten = 0;
  4599. while (numBytesToWrite > 0 && ! source.isExhausted())
  4600. {
  4601. char buffer [8192];
  4602. const int num = source.read (buffer, (int) jmin ((size_t) numBytesToWrite, sizeof (buffer)));
  4603. if (num == 0)
  4604. break;
  4605. write (buffer, num);
  4606. numBytesToWrite -= num;
  4607. numWritten += num;
  4608. }
  4609. return numWritten;
  4610. }
  4611. END_JUCE_NAMESPACE
  4612. /*** End of inlined file: juce_OutputStream.cpp ***/
  4613. /*** Start of inlined file: juce_DirectoryIterator.cpp ***/
  4614. BEGIN_JUCE_NAMESPACE
  4615. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  4616. bool* isDirectory, bool* isHidden, int64* fileSize,
  4617. Time* modTime, Time* creationTime, bool* isReadOnly);
  4618. bool juce_findFileNext (void* handle, String& resultFile,
  4619. bool* isDirectory, bool* isHidden, int64* fileSize,
  4620. Time* modTime, Time* creationTime, bool* isReadOnly);
  4621. void juce_findFileClose (void* handle);
  4622. DirectoryIterator::DirectoryIterator (const File& directory,
  4623. bool isRecursive,
  4624. const String& wc,
  4625. const int whatToLookFor_)
  4626. : wildCard (wc),
  4627. index (-1),
  4628. whatToLookFor (whatToLookFor_)
  4629. {
  4630. // you have to specify the type of files you're looking for!
  4631. jassert ((whatToLookFor_ & (File::findFiles | File::findDirectories)) != 0);
  4632. jassert (whatToLookFor_ > 0 && whatToLookFor_ <= 7);
  4633. String path (directory.getFullPathName());
  4634. if (! path.endsWithChar (File::separator))
  4635. path += File::separator;
  4636. String filename;
  4637. bool isDirectory, isHidden;
  4638. void* const handle = juce_findFileStart (path,
  4639. isRecursive ? T("*") : wc,
  4640. filename, &isDirectory, &isHidden, 0, 0, 0, 0);
  4641. if (handle != 0)
  4642. {
  4643. do
  4644. {
  4645. if (! filename.containsOnly (T(".")))
  4646. {
  4647. bool addToList = false;
  4648. if (isDirectory)
  4649. {
  4650. if (isRecursive
  4651. && ((whatToLookFor_ & File::ignoreHiddenFiles) == 0
  4652. || ! isHidden))
  4653. {
  4654. dirsFound.add (File (path + filename, 0));
  4655. }
  4656. addToList = (whatToLookFor_ & File::findDirectories) != 0;
  4657. }
  4658. else
  4659. {
  4660. addToList = (whatToLookFor_ & File::findFiles) != 0;
  4661. }
  4662. // if it's recursive, we're not relying on the OS iterator
  4663. // to do the wildcard match, so do it now..
  4664. if (isRecursive && addToList)
  4665. addToList = filename.matchesWildcard (wc, true);
  4666. if (addToList && (whatToLookFor_ & File::ignoreHiddenFiles) != 0)
  4667. addToList = ! isHidden;
  4668. if (addToList)
  4669. filesFound.add (File (path + filename, 0));
  4670. }
  4671. } while (juce_findFileNext (handle, filename, &isDirectory, &isHidden, 0, 0, 0, 0));
  4672. juce_findFileClose (handle);
  4673. }
  4674. }
  4675. DirectoryIterator::~DirectoryIterator()
  4676. {
  4677. }
  4678. bool DirectoryIterator::next()
  4679. {
  4680. if (subIterator != 0)
  4681. {
  4682. if (subIterator->next())
  4683. return true;
  4684. subIterator = 0;
  4685. }
  4686. if (index >= filesFound.size() + dirsFound.size() - 1)
  4687. return false;
  4688. ++index;
  4689. if (index >= filesFound.size())
  4690. {
  4691. subIterator = new DirectoryIterator (dirsFound.getReference (index - filesFound.size()),
  4692. true, wildCard, whatToLookFor);
  4693. return next();
  4694. }
  4695. return true;
  4696. }
  4697. const File DirectoryIterator::getFile() const
  4698. {
  4699. if (subIterator != 0)
  4700. return subIterator->getFile();
  4701. return filesFound [index];
  4702. }
  4703. float DirectoryIterator::getEstimatedProgress() const
  4704. {
  4705. if (filesFound.size() + dirsFound.size() == 0)
  4706. {
  4707. return 0.0f;
  4708. }
  4709. else
  4710. {
  4711. const float detailedIndex = (subIterator != 0) ? index + subIterator->getEstimatedProgress()
  4712. : (float) index;
  4713. return detailedIndex / (filesFound.size() + dirsFound.size());
  4714. }
  4715. }
  4716. END_JUCE_NAMESPACE
  4717. /*** End of inlined file: juce_DirectoryIterator.cpp ***/
  4718. /*** Start of inlined file: juce_File.cpp ***/
  4719. #ifdef _MSC_VER
  4720. #pragma warning (disable: 4514)
  4721. #pragma warning (push)
  4722. #endif
  4723. #if ! JUCE_WINDOWS
  4724. #include <pwd.h>
  4725. #endif
  4726. BEGIN_JUCE_NAMESPACE
  4727. #ifdef _MSC_VER
  4728. #pragma warning (pop)
  4729. #endif
  4730. void* juce_fileOpen (const String& path, bool forWriting);
  4731. void juce_fileClose (void* handle);
  4732. int juce_fileWrite (void* handle, const void* buffer, int size);
  4733. int64 juce_fileGetPosition (void* handle);
  4734. int64 juce_fileSetPosition (void* handle, int64 pos);
  4735. void juce_fileFlush (void* handle);
  4736. bool juce_fileExists (const String& fileName, const bool dontCountDirectories);
  4737. bool juce_isDirectory (const String& fileName);
  4738. int64 juce_getFileSize (const String& fileName);
  4739. bool juce_canWriteToFile (const String& fileName);
  4740. bool juce_setFileReadOnly (const String& fileName, bool isReadOnly);
  4741. void juce_getFileTimes (const String& fileName, int64& modificationTime, int64& accessTime, int64& creationTime);
  4742. bool juce_setFileTimes (const String& fileName, int64 modificationTime, int64 accessTime, int64 creationTime);
  4743. bool juce_deleteFile (const String& fileName);
  4744. bool juce_copyFile (const String& source, const String& dest);
  4745. bool juce_moveFile (const String& source, const String& dest);
  4746. // this must also create all paths involved in the directory.
  4747. void juce_createDirectory (const String& fileName);
  4748. bool juce_launchFile (const String& fileName, const String& parameters);
  4749. const StringArray juce_getFileSystemRoots();
  4750. const String juce_getVolumeLabel (const String& filenameOnVolume, int& volumeSerialNumber);
  4751. // starts a directory search operation with a wildcard, returning a handle for
  4752. // use in calls to juce_findFileNext.
  4753. // juce_firstResultFile gets the name of the file (not the whole pathname) and
  4754. // the other pointers, if non-null, are set based on the properties of the file.
  4755. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  4756. bool* isDirectory, bool* isHidden, int64* fileSize, Time* modTime,
  4757. Time* creationTime, bool* isReadOnly);
  4758. // returns false when no more files are found
  4759. bool juce_findFileNext (void* handle, String& resultFile,
  4760. bool* isDirectory, bool* isHidden, int64* fileSize,
  4761. Time* modTime, Time* creationTime, bool* isReadOnly);
  4762. void juce_findFileClose (void* handle);
  4763. static const String juce_addTrailingSeparator (const String& path)
  4764. {
  4765. return path.endsWithChar (File::separator) ? path
  4766. : path + File::separator;
  4767. }
  4768. static const String parseAbsolutePath (String path)
  4769. {
  4770. if (path.isEmpty())
  4771. return String::empty;
  4772. #if JUCE_WINDOWS
  4773. // Windows..
  4774. path = path.replaceCharacter (T('/'), T('\\'));
  4775. if (path.startsWithChar (File::separator))
  4776. {
  4777. if (path[1] != File::separator)
  4778. {
  4779. jassertfalse // using a filename that starts with a slash is a bit dodgy on
  4780. // Windows, because it needs a drive letter, which in this case
  4781. // we'll take from the CWD.. but this is a bit of an assumption that
  4782. // could be wrong..
  4783. path = File::getCurrentWorkingDirectory().getFullPathName().substring (0, 2) + path;
  4784. }
  4785. }
  4786. else if (path.indexOfChar (T(':')) < 0)
  4787. {
  4788. if (path.isEmpty())
  4789. return String::empty;
  4790. jassertfalse // using a partial filename is a bad way to initialise a file, because
  4791. // we don't know what directory to put it in.
  4792. // Here we'll assume it's in the CWD, but this might not be what was
  4793. // intended..
  4794. return File::getCurrentWorkingDirectory().getChildFile (path).getFullPathName();
  4795. }
  4796. #else
  4797. // Mac or Linux..
  4798. path = path.replaceCharacter (T('\\'), T('/'));
  4799. if (path.startsWithChar (T('~')))
  4800. {
  4801. const char* homeDir = 0;
  4802. if (path[1] == File::separator || path[1] == 0)
  4803. {
  4804. // expand a name of the form "~/abc"
  4805. path = File::getSpecialLocation (File::userHomeDirectory).getFullPathName()
  4806. + path.substring (1);
  4807. }
  4808. else
  4809. {
  4810. // expand a name of type "~dave/abc"
  4811. const String userName (path.substring (1)
  4812. .upToFirstOccurrenceOf (T("/"), false, false));
  4813. struct passwd* const pw = getpwnam (userName);
  4814. if (pw != 0)
  4815. {
  4816. String home (homeDir);
  4817. if (home.endsWithChar (File::separator))
  4818. home [home.length() - 1] = 0;
  4819. path = String (pw->pw_dir)
  4820. + path.substring (userName.length());
  4821. }
  4822. }
  4823. }
  4824. else if (! path.startsWithChar (File::separator))
  4825. {
  4826. while (path.startsWith (T("./")))
  4827. path = path.substring (2);
  4828. if (path.isEmpty())
  4829. return String::empty;
  4830. jassertfalse // using a partial filename is a bad way to initialise a file, because
  4831. // we don't know what directory to put it in.
  4832. // Here we'll assume it's in the CWD, but this might not be what was
  4833. // intended..
  4834. return File::getCurrentWorkingDirectory().getChildFile (path).getFullPathName();
  4835. }
  4836. #endif
  4837. int len = path.length();
  4838. while (--len > 0 && path [len] == File::separator)
  4839. path [len] = 0;
  4840. return path;
  4841. }
  4842. const File File::nonexistent;
  4843. File::File (const String& fullPathName)
  4844. : fullPath (parseAbsolutePath (fullPathName))
  4845. {
  4846. }
  4847. File::File (const String& path, int)
  4848. : fullPath (path)
  4849. {
  4850. }
  4851. const File File::createFileWithoutCheckingPath (const String& path)
  4852. {
  4853. return File (path, 0);
  4854. }
  4855. File::File (const File& other)
  4856. : fullPath (other.fullPath)
  4857. {
  4858. }
  4859. const File& File::operator= (const String& newPath)
  4860. {
  4861. fullPath = parseAbsolutePath (newPath);
  4862. return *this;
  4863. }
  4864. const File& File::operator= (const File& other)
  4865. {
  4866. fullPath = other.fullPath;
  4867. return *this;
  4868. }
  4869. #if JUCE_LINUX
  4870. #define NAMES_ARE_CASE_SENSITIVE 1
  4871. #endif
  4872. bool File::areFileNamesCaseSensitive()
  4873. {
  4874. #if NAMES_ARE_CASE_SENSITIVE
  4875. return true;
  4876. #else
  4877. return false;
  4878. #endif
  4879. }
  4880. bool File::operator== (const File& other) const
  4881. {
  4882. // case-insensitive on Windows, but not on linux.
  4883. #if NAMES_ARE_CASE_SENSITIVE
  4884. return fullPath == other.fullPath;
  4885. #else
  4886. return fullPath.equalsIgnoreCase (other.fullPath);
  4887. #endif
  4888. }
  4889. bool File::operator!= (const File& other) const
  4890. {
  4891. return ! operator== (other);
  4892. }
  4893. bool File::exists() const
  4894. {
  4895. return juce_fileExists (fullPath, false);
  4896. }
  4897. bool File::existsAsFile() const
  4898. {
  4899. return juce_fileExists (fullPath, true);
  4900. }
  4901. bool File::isDirectory() const
  4902. {
  4903. return juce_isDirectory (fullPath);
  4904. }
  4905. bool File::hasWriteAccess() const
  4906. {
  4907. if (exists())
  4908. return juce_canWriteToFile (fullPath);
  4909. #if ! JUCE_WINDOWS
  4910. else if ((! isDirectory()) && fullPath.containsChar (separator))
  4911. return getParentDirectory().hasWriteAccess();
  4912. else
  4913. return false;
  4914. #else
  4915. // on windows, it seems that even read-only directories can still be written into,
  4916. // so checking the parent directory's permissions would return the wrong result..
  4917. else
  4918. return true;
  4919. #endif
  4920. }
  4921. bool File::setReadOnly (const bool shouldBeReadOnly,
  4922. const bool applyRecursively) const
  4923. {
  4924. bool worked = true;
  4925. if (applyRecursively && isDirectory())
  4926. {
  4927. Array <File> subFiles;
  4928. findChildFiles (subFiles, File::findFilesAndDirectories, false);
  4929. for (int i = subFiles.size(); --i >= 0;)
  4930. worked = subFiles.getReference(i).setReadOnly (shouldBeReadOnly, true) && worked;
  4931. }
  4932. return juce_setFileReadOnly (fullPath, shouldBeReadOnly) && worked;
  4933. }
  4934. bool File::deleteFile() const
  4935. {
  4936. return (! exists())
  4937. || juce_deleteFile (fullPath);
  4938. }
  4939. bool File::deleteRecursively() const
  4940. {
  4941. bool worked = true;
  4942. if (isDirectory())
  4943. {
  4944. Array<File> subFiles;
  4945. findChildFiles (subFiles, File::findFilesAndDirectories, false);
  4946. for (int i = subFiles.size(); --i >= 0;)
  4947. worked = subFiles.getReference(i).deleteRecursively() && worked;
  4948. }
  4949. return deleteFile() && worked;
  4950. }
  4951. bool File::moveFileTo (const File& newFile) const
  4952. {
  4953. if (newFile.fullPath == fullPath)
  4954. return true;
  4955. #if ! NAMES_ARE_CASE_SENSITIVE
  4956. if (*this != newFile)
  4957. #endif
  4958. if (! newFile.deleteFile())
  4959. return false;
  4960. return juce_moveFile (fullPath, newFile.fullPath);
  4961. }
  4962. bool File::copyFileTo (const File& newFile) const
  4963. {
  4964. if (*this == newFile)
  4965. return true;
  4966. if (! newFile.deleteFile())
  4967. return false;
  4968. return juce_copyFile (fullPath, newFile.fullPath);
  4969. }
  4970. bool File::copyDirectoryTo (const File& newDirectory) const
  4971. {
  4972. if (isDirectory() && newDirectory.createDirectory())
  4973. {
  4974. Array<File> subFiles;
  4975. findChildFiles (subFiles, File::findFiles, false);
  4976. int i;
  4977. for (i = 0; i < subFiles.size(); ++i)
  4978. if (! subFiles.getReference(i).copyFileTo (newDirectory.getChildFile (subFiles.getReference(i).getFileName())))
  4979. return false;
  4980. subFiles.clear();
  4981. findChildFiles (subFiles, File::findDirectories, false);
  4982. for (i = 0; i < subFiles.size(); ++i)
  4983. if (! subFiles.getReference(i).copyDirectoryTo (newDirectory.getChildFile (subFiles.getReference(i).getFileName())))
  4984. return false;
  4985. return true;
  4986. }
  4987. return false;
  4988. }
  4989. const String File::getPathUpToLastSlash() const
  4990. {
  4991. const int lastSlash = fullPath.lastIndexOfChar (separator);
  4992. if (lastSlash > 0)
  4993. return fullPath.substring (0, lastSlash);
  4994. else if (lastSlash == 0)
  4995. return separatorString;
  4996. else
  4997. return fullPath;
  4998. }
  4999. const File File::getParentDirectory() const
  5000. {
  5001. return File (getPathUpToLastSlash());
  5002. }
  5003. const String File::getFileName() const
  5004. {
  5005. return fullPath.substring (fullPath.lastIndexOfChar (separator) + 1);
  5006. }
  5007. int File::hashCode() const
  5008. {
  5009. return fullPath.hashCode();
  5010. }
  5011. int64 File::hashCode64() const
  5012. {
  5013. return fullPath.hashCode64();
  5014. }
  5015. const String File::getFileNameWithoutExtension() const
  5016. {
  5017. const int lastSlash = fullPath.lastIndexOfChar (separator) + 1;
  5018. const int lastDot = fullPath.lastIndexOfChar (T('.'));
  5019. if (lastDot > lastSlash)
  5020. return fullPath.substring (lastSlash, lastDot);
  5021. else
  5022. return fullPath.substring (lastSlash);
  5023. }
  5024. bool File::isAChildOf (const File& potentialParent) const
  5025. {
  5026. if (potentialParent == File::nonexistent)
  5027. return false;
  5028. const String ourPath (getPathUpToLastSlash());
  5029. #if NAMES_ARE_CASE_SENSITIVE
  5030. if (potentialParent.fullPath == ourPath)
  5031. #else
  5032. if (potentialParent.fullPath.equalsIgnoreCase (ourPath))
  5033. #endif
  5034. {
  5035. return true;
  5036. }
  5037. else if (potentialParent.fullPath.length() >= ourPath.length())
  5038. {
  5039. return false;
  5040. }
  5041. else
  5042. {
  5043. return getParentDirectory().isAChildOf (potentialParent);
  5044. }
  5045. }
  5046. bool File::isAbsolutePath (const String& path)
  5047. {
  5048. return path.startsWithChar (T('/')) || path.startsWithChar (T('\\'))
  5049. #if JUCE_WINDOWS
  5050. || (path.isNotEmpty() && ((const String&) path)[1] == T(':'));
  5051. #else
  5052. || path.startsWithChar (T('~'));
  5053. #endif
  5054. }
  5055. const File File::getChildFile (String relativePath) const
  5056. {
  5057. if (isAbsolutePath (relativePath))
  5058. {
  5059. // the path is really absolute..
  5060. return File (relativePath);
  5061. }
  5062. else
  5063. {
  5064. // it's relative, so remove any ../ or ./ bits at the start.
  5065. String path (fullPath);
  5066. if (relativePath[0] == T('.'))
  5067. {
  5068. #if JUCE_WINDOWS
  5069. relativePath = relativePath.replaceCharacter (T('/'), T('\\')).trimStart();
  5070. #else
  5071. relativePath = relativePath.replaceCharacter (T('\\'), T('/')).trimStart();
  5072. #endif
  5073. while (relativePath[0] == T('.'))
  5074. {
  5075. if (relativePath[1] == T('.'))
  5076. {
  5077. if (relativePath [2] == 0 || relativePath[2] == separator)
  5078. {
  5079. const int lastSlash = path.lastIndexOfChar (separator);
  5080. if (lastSlash >= 0)
  5081. path = path.substring (0, lastSlash);
  5082. relativePath = relativePath.substring (3);
  5083. }
  5084. else
  5085. {
  5086. break;
  5087. }
  5088. }
  5089. else if (relativePath[1] == separator)
  5090. {
  5091. relativePath = relativePath.substring (2);
  5092. }
  5093. else
  5094. {
  5095. break;
  5096. }
  5097. }
  5098. }
  5099. return File (juce_addTrailingSeparator (path) + relativePath);
  5100. }
  5101. }
  5102. const File File::getSiblingFile (const String& fileName) const
  5103. {
  5104. return getParentDirectory().getChildFile (fileName);
  5105. }
  5106. int64 File::getSize() const
  5107. {
  5108. return juce_getFileSize (fullPath);
  5109. }
  5110. const String File::descriptionOfSizeInBytes (const int64 bytes)
  5111. {
  5112. if (bytes == 1)
  5113. {
  5114. return "1 byte";
  5115. }
  5116. else if (bytes < 1024)
  5117. {
  5118. return String ((int) bytes) + " bytes";
  5119. }
  5120. else if (bytes < 1024 * 1024)
  5121. {
  5122. return String (bytes / 1024.0, 1) + " KB";
  5123. }
  5124. else if (bytes < 1024 * 1024 * 1024)
  5125. {
  5126. return String (bytes / (1024.0 * 1024.0), 1) + " MB";
  5127. }
  5128. else
  5129. {
  5130. return String (bytes / (1024.0 * 1024.0 * 1024.0), 1) + " GB";
  5131. }
  5132. }
  5133. bool File::create() const
  5134. {
  5135. if (! exists())
  5136. {
  5137. const File parentDir (getParentDirectory());
  5138. if (parentDir == *this || ! parentDir.createDirectory())
  5139. return false;
  5140. void* const fh = juce_fileOpen (fullPath, true);
  5141. if (fh == 0)
  5142. return false;
  5143. juce_fileClose (fh);
  5144. }
  5145. return true;
  5146. }
  5147. bool File::createDirectory() const
  5148. {
  5149. if (! isDirectory())
  5150. {
  5151. const File parentDir (getParentDirectory());
  5152. if (parentDir == *this || ! parentDir.createDirectory())
  5153. return false;
  5154. String dir (fullPath);
  5155. while (dir.endsWithChar (separator))
  5156. dir [dir.length() - 1] = 0;
  5157. juce_createDirectory (dir);
  5158. return isDirectory();
  5159. }
  5160. return true;
  5161. }
  5162. const Time File::getCreationTime() const
  5163. {
  5164. int64 m, a, c;
  5165. juce_getFileTimes (fullPath, m, a, c);
  5166. return Time (c);
  5167. }
  5168. bool File::setCreationTime (const Time& t) const
  5169. {
  5170. return juce_setFileTimes (fullPath, 0, 0, t.toMilliseconds());
  5171. }
  5172. const Time File::getLastModificationTime() const
  5173. {
  5174. int64 m, a, c;
  5175. juce_getFileTimes (fullPath, m, a, c);
  5176. return Time (m);
  5177. }
  5178. bool File::setLastModificationTime (const Time& t) const
  5179. {
  5180. return juce_setFileTimes (fullPath, t.toMilliseconds(), 0, 0);
  5181. }
  5182. const Time File::getLastAccessTime() const
  5183. {
  5184. int64 m, a, c;
  5185. juce_getFileTimes (fullPath, m, a, c);
  5186. return Time (a);
  5187. }
  5188. bool File::setLastAccessTime (const Time& t) const
  5189. {
  5190. return juce_setFileTimes (fullPath, 0, t.toMilliseconds(), 0);
  5191. }
  5192. bool File::loadFileAsData (MemoryBlock& destBlock) const
  5193. {
  5194. if (! existsAsFile())
  5195. return false;
  5196. FileInputStream in (*this);
  5197. return getSize() == in.readIntoMemoryBlock (destBlock);
  5198. }
  5199. const String File::loadFileAsString() const
  5200. {
  5201. if (! existsAsFile())
  5202. return String::empty;
  5203. FileInputStream in (*this);
  5204. return in.readEntireStreamAsString();
  5205. }
  5206. static inline bool fileTypeMatches (const int whatToLookFor,
  5207. const bool isDir,
  5208. const bool isHidden)
  5209. {
  5210. return (whatToLookFor & (isDir ? File::findDirectories
  5211. : File::findFiles)) != 0
  5212. && ((! isHidden)
  5213. || (whatToLookFor & File::ignoreHiddenFiles) == 0);
  5214. }
  5215. int File::findChildFiles (Array<File>& results,
  5216. const int whatToLookFor,
  5217. const bool searchRecursively,
  5218. const String& wildCardPattern) const
  5219. {
  5220. // you have to specify the type of files you're looking for!
  5221. jassert ((whatToLookFor & (findFiles | findDirectories)) != 0);
  5222. int total = 0;
  5223. // find child files or directories in this directory first..
  5224. if (isDirectory())
  5225. {
  5226. const String path (juce_addTrailingSeparator (fullPath));
  5227. String filename;
  5228. bool itemIsDirectory, itemIsHidden;
  5229. void* const handle = juce_findFileStart (path, wildCardPattern, filename,
  5230. &itemIsDirectory, &itemIsHidden,
  5231. 0, 0, 0, 0);
  5232. if (handle != 0)
  5233. {
  5234. do
  5235. {
  5236. if (fileTypeMatches (whatToLookFor, itemIsDirectory, itemIsHidden)
  5237. && ! filename.containsOnly (T(".")))
  5238. {
  5239. results.add (File (path + filename, 0));
  5240. ++total;
  5241. }
  5242. } while (juce_findFileNext (handle, filename, &itemIsDirectory, &itemIsHidden, 0, 0, 0, 0));
  5243. juce_findFileClose (handle);
  5244. }
  5245. }
  5246. else
  5247. {
  5248. // trying to search for files inside a non-directory?
  5249. //jassertfalse
  5250. }
  5251. // and recurse down if required.
  5252. if (searchRecursively)
  5253. {
  5254. Array<File> subDirectories;
  5255. findChildFiles (subDirectories, File::findDirectories, false);
  5256. for (int i = 0; i < subDirectories.size(); ++i)
  5257. {
  5258. total += subDirectories.getReference(i).findChildFiles (results, whatToLookFor,
  5259. true, wildCardPattern);
  5260. }
  5261. }
  5262. return total;
  5263. }
  5264. int File::getNumberOfChildFiles (const int whatToLookFor,
  5265. const String& wildCardPattern) const
  5266. {
  5267. // you have to specify the type of files you're looking for!
  5268. jassert (whatToLookFor > 0 && whatToLookFor <= 3);
  5269. int count = 0;
  5270. if (isDirectory())
  5271. {
  5272. String filename;
  5273. bool itemIsDirectory, itemIsHidden;
  5274. void* const handle = juce_findFileStart (fullPath, wildCardPattern, filename,
  5275. &itemIsDirectory, &itemIsHidden,
  5276. 0, 0, 0, 0);
  5277. if (handle != 0)
  5278. {
  5279. do
  5280. {
  5281. if (fileTypeMatches (whatToLookFor, itemIsDirectory, itemIsHidden)
  5282. && ! filename.containsOnly (T(".")))
  5283. {
  5284. ++count;
  5285. }
  5286. } while (juce_findFileNext (handle, filename, &itemIsDirectory, &itemIsHidden, 0, 0, 0, 0));
  5287. juce_findFileClose (handle);
  5288. }
  5289. }
  5290. else
  5291. {
  5292. // trying to search for files inside a non-directory?
  5293. jassertfalse
  5294. }
  5295. return count;
  5296. }
  5297. bool File::containsSubDirectories() const
  5298. {
  5299. bool result = false;
  5300. if (isDirectory())
  5301. {
  5302. String filename;
  5303. bool itemIsDirectory, itemIsHidden;
  5304. void* const handle = juce_findFileStart (juce_addTrailingSeparator (fullPath),
  5305. T("*"), filename,
  5306. &itemIsDirectory, &itemIsHidden, 0, 0, 0, 0);
  5307. if (handle != 0)
  5308. {
  5309. do
  5310. {
  5311. if (itemIsDirectory)
  5312. {
  5313. result = true;
  5314. break;
  5315. }
  5316. } while (juce_findFileNext (handle, filename, &itemIsDirectory, &itemIsHidden, 0, 0, 0, 0));
  5317. juce_findFileClose (handle);
  5318. }
  5319. }
  5320. return result;
  5321. }
  5322. const File File::getNonexistentChildFile (const String& prefix_,
  5323. const String& suffix,
  5324. bool putNumbersInBrackets) const
  5325. {
  5326. File f (getChildFile (prefix_ + suffix));
  5327. if (f.exists())
  5328. {
  5329. int num = 2;
  5330. String prefix (prefix_);
  5331. // remove any bracketed numbers that may already be on the end..
  5332. if (prefix.trim().endsWithChar (T(')')))
  5333. {
  5334. putNumbersInBrackets = true;
  5335. const int openBracks = prefix.lastIndexOfChar (T('('));
  5336. const int closeBracks = prefix.lastIndexOfChar (T(')'));
  5337. if (openBracks > 0
  5338. && closeBracks > openBracks
  5339. && prefix.substring (openBracks + 1, closeBracks).containsOnly (T("0123456789")))
  5340. {
  5341. num = prefix.substring (openBracks + 1, closeBracks).getIntValue() + 1;
  5342. prefix = prefix.substring (0, openBracks);
  5343. }
  5344. }
  5345. // also use brackets if it ends in a digit.
  5346. putNumbersInBrackets = putNumbersInBrackets
  5347. || CharacterFunctions::isDigit (prefix.getLastCharacter());
  5348. do
  5349. {
  5350. if (putNumbersInBrackets)
  5351. f = getChildFile (prefix + T('(') + String (num++) + T(')') + suffix);
  5352. else
  5353. f = getChildFile (prefix + String (num++) + suffix);
  5354. } while (f.exists());
  5355. }
  5356. return f;
  5357. }
  5358. const File File::getNonexistentSibling (const bool putNumbersInBrackets) const
  5359. {
  5360. if (exists())
  5361. {
  5362. return getParentDirectory()
  5363. .getNonexistentChildFile (getFileNameWithoutExtension(),
  5364. getFileExtension(),
  5365. putNumbersInBrackets);
  5366. }
  5367. else
  5368. {
  5369. return *this;
  5370. }
  5371. }
  5372. const String File::getFileExtension() const
  5373. {
  5374. String ext;
  5375. if (! isDirectory())
  5376. {
  5377. const int indexOfDot = fullPath.lastIndexOfChar (T('.'));
  5378. if (indexOfDot > fullPath.lastIndexOfChar (separator))
  5379. ext = fullPath.substring (indexOfDot);
  5380. }
  5381. return ext;
  5382. }
  5383. bool File::hasFileExtension (const String& possibleSuffix) const
  5384. {
  5385. if (possibleSuffix.isEmpty())
  5386. return fullPath.lastIndexOfChar (T('.')) <= fullPath.lastIndexOfChar (separator);
  5387. const int semicolon = possibleSuffix.indexOfChar (0, T(';'));
  5388. if (semicolon >= 0)
  5389. {
  5390. return hasFileExtension (possibleSuffix.substring (0, semicolon).trimEnd())
  5391. || hasFileExtension (possibleSuffix.substring (semicolon + 1).trimStart());
  5392. }
  5393. else
  5394. {
  5395. if (fullPath.endsWithIgnoreCase (possibleSuffix))
  5396. {
  5397. if (possibleSuffix.startsWithChar (T('.')))
  5398. return true;
  5399. const int dotPos = fullPath.length() - possibleSuffix.length() - 1;
  5400. if (dotPos >= 0)
  5401. return fullPath [dotPos] == T('.');
  5402. }
  5403. }
  5404. return false;
  5405. }
  5406. const File File::withFileExtension (const String& newExtension) const
  5407. {
  5408. if (fullPath.isEmpty())
  5409. return File::nonexistent;
  5410. String filePart (getFileName());
  5411. int i = filePart.lastIndexOfChar (T('.'));
  5412. if (i < 0)
  5413. i = filePart.length();
  5414. String newExt (newExtension);
  5415. if (newExt.isNotEmpty() && ! newExt.startsWithChar (T('.')))
  5416. newExt = T(".") + newExt;
  5417. return getSiblingFile (filePart.substring (0, i) + newExt);
  5418. }
  5419. bool File::startAsProcess (const String& parameters) const
  5420. {
  5421. return exists()
  5422. && juce_launchFile (fullPath, parameters);
  5423. }
  5424. FileInputStream* File::createInputStream() const
  5425. {
  5426. if (existsAsFile())
  5427. return new FileInputStream (*this);
  5428. else
  5429. return 0;
  5430. }
  5431. FileOutputStream* File::createOutputStream (const int bufferSize) const
  5432. {
  5433. ScopedPointer <FileOutputStream> out (new FileOutputStream (*this, bufferSize));
  5434. if (out->failedToOpen())
  5435. return 0;
  5436. return out.release();
  5437. }
  5438. bool File::appendData (const void* const dataToAppend,
  5439. const int numberOfBytes) const
  5440. {
  5441. if (numberOfBytes > 0)
  5442. {
  5443. const ScopedPointer <FileOutputStream> out (createOutputStream());
  5444. if (out == 0)
  5445. return false;
  5446. out->write (dataToAppend, numberOfBytes);
  5447. }
  5448. return true;
  5449. }
  5450. bool File::replaceWithData (const void* const dataToWrite,
  5451. const int numberOfBytes) const
  5452. {
  5453. jassert (numberOfBytes >= 0); // a negative number of bytes??
  5454. if (numberOfBytes <= 0)
  5455. return deleteFile();
  5456. TemporaryFile tempFile (*this, TemporaryFile::useHiddenFile);
  5457. tempFile.getFile().appendData (dataToWrite, numberOfBytes);
  5458. return tempFile.overwriteTargetFileWithTemporary();
  5459. }
  5460. bool File::appendText (const String& text,
  5461. const bool asUnicode,
  5462. const bool writeUnicodeHeaderBytes) const
  5463. {
  5464. const ScopedPointer <FileOutputStream> out (createOutputStream());
  5465. if (out != 0)
  5466. {
  5467. out->writeText (text, asUnicode, writeUnicodeHeaderBytes);
  5468. return true;
  5469. }
  5470. return false;
  5471. }
  5472. bool File::replaceWithText (const String& textToWrite,
  5473. const bool asUnicode,
  5474. const bool writeUnicodeHeaderBytes) const
  5475. {
  5476. TemporaryFile tempFile (*this, TemporaryFile::useHiddenFile);
  5477. tempFile.getFile().appendText (textToWrite, asUnicode, writeUnicodeHeaderBytes);
  5478. return tempFile.overwriteTargetFileWithTemporary();
  5479. }
  5480. const String File::createLegalPathName (const String& original)
  5481. {
  5482. String s (original);
  5483. String start;
  5484. if (s[1] == T(':'))
  5485. {
  5486. start = s.substring (0, 2);
  5487. s = s.substring (2);
  5488. }
  5489. return start + s.removeCharacters (T("\"#@,;:<>*^|?"))
  5490. .substring (0, 1024);
  5491. }
  5492. const String File::createLegalFileName (const String& original)
  5493. {
  5494. String s (original.removeCharacters (T("\"#@,;:<>*^|?\\/")));
  5495. const int maxLength = 128; // only the length of the filename, not the whole path
  5496. const int len = s.length();
  5497. if (len > maxLength)
  5498. {
  5499. const int lastDot = s.lastIndexOfChar (T('.'));
  5500. if (lastDot > jmax (0, len - 12))
  5501. {
  5502. s = s.substring (0, maxLength - (len - lastDot))
  5503. + s.substring (lastDot);
  5504. }
  5505. else
  5506. {
  5507. s = s.substring (0, maxLength);
  5508. }
  5509. }
  5510. return s;
  5511. }
  5512. const String File::getRelativePathFrom (const File& dir) const
  5513. {
  5514. String thisPath (fullPath);
  5515. {
  5516. int len = thisPath.length();
  5517. while (--len >= 0 && thisPath [len] == File::separator)
  5518. thisPath [len] = 0;
  5519. }
  5520. String dirPath (juce_addTrailingSeparator ((dir.existsAsFile()) ? dir.getParentDirectory().getFullPathName()
  5521. : dir.fullPath));
  5522. const int len = jmin (thisPath.length(), dirPath.length());
  5523. int commonBitLength = 0;
  5524. for (int i = 0; i < len; ++i)
  5525. {
  5526. #if NAMES_ARE_CASE_SENSITIVE
  5527. if (thisPath[i] != dirPath[i])
  5528. #else
  5529. if (CharacterFunctions::toLowerCase (thisPath[i])
  5530. != CharacterFunctions::toLowerCase (dirPath[i]))
  5531. #endif
  5532. {
  5533. break;
  5534. }
  5535. ++commonBitLength;
  5536. }
  5537. while (commonBitLength > 0 && thisPath [commonBitLength - 1] != File::separator)
  5538. --commonBitLength;
  5539. // if the only common bit is the root, then just return the full path..
  5540. if (commonBitLength <= 0
  5541. || (commonBitLength == 1 && thisPath [1] == File::separator))
  5542. return fullPath;
  5543. thisPath = thisPath.substring (commonBitLength);
  5544. dirPath = dirPath.substring (commonBitLength);
  5545. while (dirPath.isNotEmpty())
  5546. {
  5547. #if JUCE_WINDOWS
  5548. thisPath = T("..\\") + thisPath;
  5549. #else
  5550. thisPath = T("../") + thisPath;
  5551. #endif
  5552. const int sep = dirPath.indexOfChar (separator);
  5553. if (sep >= 0)
  5554. dirPath = dirPath.substring (sep + 1);
  5555. else
  5556. dirPath = String::empty;
  5557. }
  5558. return thisPath;
  5559. }
  5560. void File::findFileSystemRoots (Array<File>& destArray)
  5561. {
  5562. const StringArray roots (juce_getFileSystemRoots());
  5563. for (int i = 0; i < roots.size(); ++i)
  5564. destArray.add (File (roots[i]));
  5565. }
  5566. const String File::getVolumeLabel() const
  5567. {
  5568. int serialNum;
  5569. return juce_getVolumeLabel (fullPath, serialNum);
  5570. }
  5571. int File::getVolumeSerialNumber() const
  5572. {
  5573. int serialNum;
  5574. juce_getVolumeLabel (fullPath, serialNum);
  5575. return serialNum;
  5576. }
  5577. const File File::createTempFile (const String& fileNameEnding)
  5578. {
  5579. const File tempFile (getSpecialLocation (tempDirectory)
  5580. .getChildFile (T("temp_") + String (Random::getSystemRandom().nextInt()))
  5581. .withFileExtension (fileNameEnding));
  5582. if (tempFile.exists())
  5583. return createTempFile (fileNameEnding);
  5584. else
  5585. return tempFile;
  5586. }
  5587. END_JUCE_NAMESPACE
  5588. /*** End of inlined file: juce_File.cpp ***/
  5589. /*** Start of inlined file: juce_FileInputStream.cpp ***/
  5590. BEGIN_JUCE_NAMESPACE
  5591. void* juce_fileOpen (const String& path, bool forWriting);
  5592. void juce_fileClose (void* handle);
  5593. int juce_fileRead (void* handle, void* buffer, int size);
  5594. int64 juce_fileSetPosition (void* handle, int64 pos);
  5595. FileInputStream::FileInputStream (const File& f)
  5596. : file (f),
  5597. currentPosition (0),
  5598. needToSeek (true)
  5599. {
  5600. totalSize = f.getSize();
  5601. fileHandle = juce_fileOpen (f.getFullPathName(), false);
  5602. }
  5603. FileInputStream::~FileInputStream()
  5604. {
  5605. juce_fileClose (fileHandle);
  5606. }
  5607. int64 FileInputStream::getTotalLength()
  5608. {
  5609. return totalSize;
  5610. }
  5611. int FileInputStream::read (void* buffer, int bytesToRead)
  5612. {
  5613. int num = 0;
  5614. if (needToSeek)
  5615. {
  5616. if (juce_fileSetPosition (fileHandle, currentPosition) < 0)
  5617. return 0;
  5618. needToSeek = false;
  5619. }
  5620. num = juce_fileRead (fileHandle, buffer, bytesToRead);
  5621. currentPosition += num;
  5622. return num;
  5623. }
  5624. bool FileInputStream::isExhausted()
  5625. {
  5626. return currentPosition >= totalSize;
  5627. }
  5628. int64 FileInputStream::getPosition()
  5629. {
  5630. return currentPosition;
  5631. }
  5632. bool FileInputStream::setPosition (int64 pos)
  5633. {
  5634. pos = jlimit ((int64) 0, totalSize, pos);
  5635. needToSeek |= (currentPosition != pos);
  5636. currentPosition = pos;
  5637. return true;
  5638. }
  5639. END_JUCE_NAMESPACE
  5640. /*** End of inlined file: juce_FileInputStream.cpp ***/
  5641. /*** Start of inlined file: juce_FileOutputStream.cpp ***/
  5642. BEGIN_JUCE_NAMESPACE
  5643. void* juce_fileOpen (const String& path, bool forWriting);
  5644. void juce_fileClose (void* handle);
  5645. int juce_fileWrite (void* handle, const void* buffer, int size);
  5646. void juce_fileFlush (void* handle);
  5647. int64 juce_fileGetPosition (void* handle);
  5648. int64 juce_fileSetPosition (void* handle, int64 pos);
  5649. FileOutputStream::FileOutputStream (const File& f,
  5650. const int bufferSize_)
  5651. : file (f),
  5652. bufferSize (bufferSize_),
  5653. bytesInBuffer (0)
  5654. {
  5655. fileHandle = juce_fileOpen (f.getFullPathName(), true);
  5656. if (fileHandle != 0)
  5657. {
  5658. currentPosition = juce_fileGetPosition (fileHandle);
  5659. if (currentPosition < 0)
  5660. {
  5661. jassertfalse
  5662. juce_fileClose (fileHandle);
  5663. fileHandle = 0;
  5664. }
  5665. }
  5666. buffer.malloc (jmax (bufferSize_, 16));
  5667. }
  5668. FileOutputStream::~FileOutputStream()
  5669. {
  5670. flush();
  5671. juce_fileClose (fileHandle);
  5672. }
  5673. int64 FileOutputStream::getPosition()
  5674. {
  5675. return currentPosition;
  5676. }
  5677. bool FileOutputStream::setPosition (int64 newPosition)
  5678. {
  5679. if (newPosition != currentPosition)
  5680. {
  5681. flush();
  5682. currentPosition = juce_fileSetPosition (fileHandle, newPosition);
  5683. }
  5684. return newPosition == currentPosition;
  5685. }
  5686. void FileOutputStream::flush()
  5687. {
  5688. if (bytesInBuffer > 0)
  5689. {
  5690. juce_fileWrite (fileHandle, buffer, bytesInBuffer);
  5691. bytesInBuffer = 0;
  5692. }
  5693. juce_fileFlush (fileHandle);
  5694. }
  5695. bool FileOutputStream::write (const void* const src, const int numBytes)
  5696. {
  5697. if (bytesInBuffer + numBytes < bufferSize)
  5698. {
  5699. memcpy (buffer + bytesInBuffer, src, numBytes);
  5700. bytesInBuffer += numBytes;
  5701. currentPosition += numBytes;
  5702. }
  5703. else
  5704. {
  5705. if (bytesInBuffer > 0)
  5706. {
  5707. // flush the reservoir
  5708. const bool wroteOk = (juce_fileWrite (fileHandle, buffer, bytesInBuffer) == bytesInBuffer);
  5709. bytesInBuffer = 0;
  5710. if (! wroteOk)
  5711. return false;
  5712. }
  5713. if (numBytes < bufferSize)
  5714. {
  5715. memcpy (buffer + bytesInBuffer, src, numBytes);
  5716. bytesInBuffer += numBytes;
  5717. currentPosition += numBytes;
  5718. }
  5719. else
  5720. {
  5721. const int bytesWritten = juce_fileWrite (fileHandle, src, numBytes);
  5722. currentPosition += bytesWritten;
  5723. return bytesWritten == numBytes;
  5724. }
  5725. }
  5726. return true;
  5727. }
  5728. END_JUCE_NAMESPACE
  5729. /*** End of inlined file: juce_FileOutputStream.cpp ***/
  5730. /*** Start of inlined file: juce_FileSearchPath.cpp ***/
  5731. BEGIN_JUCE_NAMESPACE
  5732. FileSearchPath::FileSearchPath()
  5733. {
  5734. }
  5735. FileSearchPath::FileSearchPath (const String& path)
  5736. {
  5737. init (path);
  5738. }
  5739. FileSearchPath::FileSearchPath (const FileSearchPath& other)
  5740. : directories (other.directories)
  5741. {
  5742. }
  5743. FileSearchPath::~FileSearchPath()
  5744. {
  5745. }
  5746. const FileSearchPath& FileSearchPath::operator= (const String& path)
  5747. {
  5748. init (path);
  5749. return *this;
  5750. }
  5751. void FileSearchPath::init (const String& path)
  5752. {
  5753. directories.clear();
  5754. directories.addTokens (path, T(";"), T("\""));
  5755. directories.trim();
  5756. directories.removeEmptyStrings();
  5757. for (int i = directories.size(); --i >= 0;)
  5758. directories.set (i, directories[i].unquoted());
  5759. }
  5760. int FileSearchPath::getNumPaths() const
  5761. {
  5762. return directories.size();
  5763. }
  5764. const File FileSearchPath::operator[] (const int index) const
  5765. {
  5766. return File (directories [index]);
  5767. }
  5768. const String FileSearchPath::toString() const
  5769. {
  5770. StringArray directories2 (directories);
  5771. for (int i = directories2.size(); --i >= 0;)
  5772. if (directories2[i].containsChar (T(';')))
  5773. directories2.set (i, directories2[i].quoted());
  5774. return directories2.joinIntoString (T(";"));
  5775. }
  5776. void FileSearchPath::add (const File& dir, const int insertIndex)
  5777. {
  5778. directories.insert (insertIndex, dir.getFullPathName());
  5779. }
  5780. void FileSearchPath::addIfNotAlreadyThere (const File& dir)
  5781. {
  5782. for (int i = 0; i < directories.size(); ++i)
  5783. if (File (directories[i]) == dir)
  5784. return;
  5785. add (dir);
  5786. }
  5787. void FileSearchPath::remove (const int index)
  5788. {
  5789. directories.remove (index);
  5790. }
  5791. void FileSearchPath::addPath (const FileSearchPath& other)
  5792. {
  5793. for (int i = 0; i < other.getNumPaths(); ++i)
  5794. addIfNotAlreadyThere (other[i]);
  5795. }
  5796. void FileSearchPath::removeRedundantPaths()
  5797. {
  5798. for (int i = directories.size(); --i >= 0;)
  5799. {
  5800. const File d1 (directories[i]);
  5801. for (int j = directories.size(); --j >= 0;)
  5802. {
  5803. const File d2 (directories[j]);
  5804. if ((i != j) && (d1.isAChildOf (d2) || d1 == d2))
  5805. {
  5806. directories.remove (i);
  5807. break;
  5808. }
  5809. }
  5810. }
  5811. }
  5812. void FileSearchPath::removeNonExistentPaths()
  5813. {
  5814. for (int i = directories.size(); --i >= 0;)
  5815. if (! File (directories[i]).isDirectory())
  5816. directories.remove (i);
  5817. }
  5818. int FileSearchPath::findChildFiles (Array<File>& results,
  5819. const int whatToLookFor,
  5820. const bool searchRecursively,
  5821. const String& wildCardPattern) const
  5822. {
  5823. int total = 0;
  5824. for (int i = 0; i < directories.size(); ++i)
  5825. total += operator[] (i).findChildFiles (results,
  5826. whatToLookFor,
  5827. searchRecursively,
  5828. wildCardPattern);
  5829. return total;
  5830. }
  5831. bool FileSearchPath::isFileInPath (const File& fileToCheck,
  5832. const bool checkRecursively) const
  5833. {
  5834. for (int i = directories.size(); --i >= 0;)
  5835. {
  5836. const File d (directories[i]);
  5837. if (checkRecursively)
  5838. {
  5839. if (fileToCheck.isAChildOf (d))
  5840. return true;
  5841. }
  5842. else
  5843. {
  5844. if (fileToCheck.getParentDirectory() == d)
  5845. return true;
  5846. }
  5847. }
  5848. return false;
  5849. }
  5850. END_JUCE_NAMESPACE
  5851. /*** End of inlined file: juce_FileSearchPath.cpp ***/
  5852. /*** Start of inlined file: juce_NamedPipe.cpp ***/
  5853. BEGIN_JUCE_NAMESPACE
  5854. NamedPipe::NamedPipe()
  5855. : internal (0)
  5856. {
  5857. }
  5858. NamedPipe::~NamedPipe()
  5859. {
  5860. close();
  5861. }
  5862. bool NamedPipe::openExisting (const String& pipeName)
  5863. {
  5864. currentPipeName = pipeName;
  5865. return openInternal (pipeName, false);
  5866. }
  5867. bool NamedPipe::createNewPipe (const String& pipeName)
  5868. {
  5869. currentPipeName = pipeName;
  5870. return openInternal (pipeName, true);
  5871. }
  5872. bool NamedPipe::isOpen() const
  5873. {
  5874. return internal != 0;
  5875. }
  5876. const String NamedPipe::getName() const
  5877. {
  5878. return currentPipeName;
  5879. }
  5880. // other methods for this class are implemented in the platform-specific files
  5881. END_JUCE_NAMESPACE
  5882. /*** End of inlined file: juce_NamedPipe.cpp ***/
  5883. /*** Start of inlined file: juce_TemporaryFile.cpp ***/
  5884. BEGIN_JUCE_NAMESPACE
  5885. TemporaryFile::TemporaryFile (const String& suffix, const int optionFlags)
  5886. {
  5887. createTempFile (File::getSpecialLocation (File::tempDirectory),
  5888. T("temp_") + String (Random::getSystemRandom().nextInt()),
  5889. suffix,
  5890. optionFlags);
  5891. }
  5892. TemporaryFile::TemporaryFile (const File& targetFile_, const int optionFlags)
  5893. : targetFile (targetFile_)
  5894. {
  5895. // If you use this constructor, you need to give it a valid target file!
  5896. jassert (targetFile != File::nonexistent);
  5897. createTempFile (targetFile.getParentDirectory(),
  5898. targetFile.getFileNameWithoutExtension() + T("_temp") + String (Random::getSystemRandom().nextInt()),
  5899. targetFile.getFileExtension(),
  5900. optionFlags);
  5901. }
  5902. void TemporaryFile::createTempFile (const File& parentDirectory, String name,
  5903. const String& suffix, const int optionFlags)
  5904. {
  5905. if ((optionFlags & useHiddenFile) != 0)
  5906. name = T(".") + name;
  5907. temporaryFile = parentDirectory.getNonexistentChildFile (name, suffix, (optionFlags & putNumbersInBrackets) != 0);
  5908. }
  5909. TemporaryFile::~TemporaryFile()
  5910. {
  5911. // Have a few attempts at deleting the file before giving up..
  5912. for (int i = 5; --i >= 0;)
  5913. {
  5914. if (temporaryFile.deleteFile())
  5915. return;
  5916. Thread::sleep (50);
  5917. }
  5918. // Failed to delete our temporary file! Check that you've deleted all the
  5919. // file output streams that were using it!
  5920. jassertfalse;
  5921. }
  5922. bool TemporaryFile::overwriteTargetFileWithTemporary() const
  5923. {
  5924. // This method only works if you created this object with the constructor
  5925. // that takes a target file!
  5926. jassert (targetFile != File::nonexistent);
  5927. if (temporaryFile.exists())
  5928. {
  5929. // Have a few attempts at overwriting the file before giving up..
  5930. for (int i = 5; --i >= 0;)
  5931. {
  5932. if (temporaryFile.moveFileTo (targetFile))
  5933. return true;
  5934. Thread::sleep (100);
  5935. }
  5936. // Failed to overwrite the new file! Make sure you've not left any
  5937. // file streams hanging around when you call this method!
  5938. jassertfalse
  5939. }
  5940. else
  5941. {
  5942. // There's no temporary file to use. If your write failed, you should
  5943. // probably check, and not bother calling this method.
  5944. jassertfalse
  5945. }
  5946. return false;
  5947. }
  5948. END_JUCE_NAMESPACE
  5949. /*** End of inlined file: juce_TemporaryFile.cpp ***/
  5950. /*** Start of inlined file: juce_Socket.cpp ***/
  5951. #if JUCE_WINDOWS
  5952. #include <winsock2.h>
  5953. #ifdef _MSC_VER
  5954. #pragma warning (disable : 4127 4389 4018)
  5955. #endif
  5956. #else
  5957. #if JUCE_LINUX
  5958. #include <sys/types.h>
  5959. #include <sys/socket.h>
  5960. #include <sys/errno.h>
  5961. #include <unistd.h>
  5962. #include <netinet/in.h>
  5963. #elif (MACOSX_DEPLOYMENT_TARGET <= MAC_OS_X_VERSION_10_4) && ! JUCE_IPHONE
  5964. #include <CoreServices/CoreServices.h>
  5965. #endif
  5966. #include <fcntl.h>
  5967. #include <netdb.h>
  5968. #include <arpa/inet.h>
  5969. #include <netinet/tcp.h>
  5970. #endif
  5971. BEGIN_JUCE_NAMESPACE
  5972. #if defined (JUCE_LINUX) || defined (JUCE_MAC) || defined (JUCE_IPHONE)
  5973. typedef socklen_t juce_socklen_t;
  5974. #else
  5975. typedef int juce_socklen_t;
  5976. #endif
  5977. #if JUCE_WINDOWS
  5978. typedef int (__stdcall juce_CloseWin32SocketLibCall) (void);
  5979. juce_CloseWin32SocketLibCall* juce_CloseWin32SocketLib = 0;
  5980. static void initWin32Sockets()
  5981. {
  5982. static CriticalSection lock;
  5983. const ScopedLock sl (lock);
  5984. if (juce_CloseWin32SocketLib == 0)
  5985. {
  5986. WSADATA wsaData;
  5987. const WORD wVersionRequested = MAKEWORD (1, 1);
  5988. WSAStartup (wVersionRequested, &wsaData);
  5989. juce_CloseWin32SocketLib = &WSACleanup;
  5990. }
  5991. }
  5992. #endif
  5993. static bool resetSocketOptions (const int handle, const bool isDatagram, const bool allowBroadcast) throw()
  5994. {
  5995. const int sndBufSize = 65536;
  5996. const int rcvBufSize = 65536;
  5997. const int one = 1;
  5998. return handle > 0
  5999. && setsockopt (handle, SOL_SOCKET, SO_RCVBUF, (const char*) &rcvBufSize, sizeof (rcvBufSize)) == 0
  6000. && setsockopt (handle, SOL_SOCKET, SO_SNDBUF, (const char*) &sndBufSize, sizeof (sndBufSize)) == 0
  6001. && (isDatagram ? ((! allowBroadcast) || setsockopt (handle, SOL_SOCKET, SO_BROADCAST, (const char*) &one, sizeof (one)) == 0)
  6002. : (setsockopt (handle, IPPROTO_TCP, TCP_NODELAY, (const char*) &one, sizeof (one)) == 0));
  6003. }
  6004. static bool bindSocketToPort (const int handle, const int port) throw()
  6005. {
  6006. if (handle <= 0 || port <= 0)
  6007. return false;
  6008. struct sockaddr_in servTmpAddr;
  6009. zerostruct (servTmpAddr);
  6010. servTmpAddr.sin_family = PF_INET;
  6011. servTmpAddr.sin_addr.s_addr = htonl (INADDR_ANY);
  6012. servTmpAddr.sin_port = htons ((uint16) port);
  6013. return bind (handle, (struct sockaddr*) &servTmpAddr, sizeof (struct sockaddr_in)) >= 0;
  6014. }
  6015. static int readSocket (const int handle,
  6016. void* const destBuffer, const int maxBytesToRead,
  6017. bool volatile& connected,
  6018. const bool blockUntilSpecifiedAmountHasArrived) throw()
  6019. {
  6020. int bytesRead = 0;
  6021. while (bytesRead < maxBytesToRead)
  6022. {
  6023. int bytesThisTime;
  6024. #if JUCE_WINDOWS
  6025. bytesThisTime = recv (handle, ((char*) destBuffer) + bytesRead, maxBytesToRead - bytesRead, 0);
  6026. #else
  6027. while ((bytesThisTime = (int) ::read (handle, ((char*) destBuffer) + bytesRead, maxBytesToRead - bytesRead)) < 0
  6028. && errno == EINTR
  6029. && connected)
  6030. {
  6031. }
  6032. #endif
  6033. if (bytesThisTime <= 0 || ! connected)
  6034. {
  6035. if (bytesRead == 0)
  6036. bytesRead = -1;
  6037. break;
  6038. }
  6039. bytesRead += bytesThisTime;
  6040. if (! blockUntilSpecifiedAmountHasArrived)
  6041. break;
  6042. }
  6043. return bytesRead;
  6044. }
  6045. static int waitForReadiness (const int handle, const bool forReading,
  6046. const int timeoutMsecs) throw()
  6047. {
  6048. struct timeval timeout;
  6049. struct timeval* timeoutp;
  6050. if (timeoutMsecs >= 0)
  6051. {
  6052. timeout.tv_sec = timeoutMsecs / 1000;
  6053. timeout.tv_usec = (timeoutMsecs % 1000) * 1000;
  6054. timeoutp = &timeout;
  6055. }
  6056. else
  6057. {
  6058. timeoutp = 0;
  6059. }
  6060. fd_set rset, wset;
  6061. FD_ZERO (&rset);
  6062. FD_SET (handle, &rset);
  6063. FD_ZERO (&wset);
  6064. FD_SET (handle, &wset);
  6065. fd_set* const prset = forReading ? &rset : 0;
  6066. fd_set* const pwset = forReading ? 0 : &wset;
  6067. #if JUCE_WINDOWS
  6068. if (select (handle + 1, prset, pwset, 0, timeoutp) < 0)
  6069. return -1;
  6070. #else
  6071. {
  6072. int result;
  6073. while ((result = select (handle + 1, prset, pwset, 0, timeoutp)) < 0
  6074. && errno == EINTR)
  6075. {
  6076. }
  6077. if (result < 0)
  6078. return -1;
  6079. }
  6080. #endif
  6081. {
  6082. int opt;
  6083. juce_socklen_t len = sizeof (opt);
  6084. if (getsockopt (handle, SOL_SOCKET, SO_ERROR, (char*) &opt, &len) < 0
  6085. || opt != 0)
  6086. return -1;
  6087. }
  6088. if ((forReading && FD_ISSET (handle, &rset))
  6089. || ((! forReading) && FD_ISSET (handle, &wset)))
  6090. return 1;
  6091. return 0;
  6092. }
  6093. static bool setSocketBlockingState (const int handle, const bool shouldBlock) throw()
  6094. {
  6095. #if JUCE_WINDOWS
  6096. u_long nonBlocking = shouldBlock ? 0 : 1;
  6097. if (ioctlsocket (handle, FIONBIO, &nonBlocking) != 0)
  6098. return false;
  6099. #else
  6100. int socketFlags = fcntl (handle, F_GETFL, 0);
  6101. if (socketFlags == -1)
  6102. return false;
  6103. if (shouldBlock)
  6104. socketFlags &= ~O_NONBLOCK;
  6105. else
  6106. socketFlags |= O_NONBLOCK;
  6107. if (fcntl (handle, F_SETFL, socketFlags) != 0)
  6108. return false;
  6109. #endif
  6110. return true;
  6111. }
  6112. static bool connectSocket (int volatile& handle,
  6113. const bool isDatagram,
  6114. void** serverAddress,
  6115. const String& hostName,
  6116. const int portNumber,
  6117. const int timeOutMillisecs) throw()
  6118. {
  6119. struct hostent* const hostEnt = gethostbyname (hostName);
  6120. if (hostEnt == 0)
  6121. return false;
  6122. struct in_addr targetAddress;
  6123. memcpy (&targetAddress.s_addr,
  6124. *(hostEnt->h_addr_list),
  6125. sizeof (targetAddress.s_addr));
  6126. struct sockaddr_in servTmpAddr;
  6127. zerostruct (servTmpAddr);
  6128. servTmpAddr.sin_family = PF_INET;
  6129. servTmpAddr.sin_addr = targetAddress;
  6130. servTmpAddr.sin_port = htons ((uint16) portNumber);
  6131. if (handle < 0)
  6132. handle = (int) socket (AF_INET, isDatagram ? SOCK_DGRAM : SOCK_STREAM, 0);
  6133. if (handle < 0)
  6134. return false;
  6135. if (isDatagram)
  6136. {
  6137. *serverAddress = new struct sockaddr_in();
  6138. *((struct sockaddr_in*) *serverAddress) = servTmpAddr;
  6139. return true;
  6140. }
  6141. setSocketBlockingState (handle, false);
  6142. const int result = ::connect (handle, (struct sockaddr*) &servTmpAddr, sizeof (struct sockaddr_in));
  6143. if (result < 0)
  6144. {
  6145. #if JUCE_WINDOWS
  6146. if (result == SOCKET_ERROR && WSAGetLastError() == WSAEWOULDBLOCK)
  6147. #else
  6148. if (errno == EINPROGRESS)
  6149. #endif
  6150. {
  6151. if (waitForReadiness (handle, false, timeOutMillisecs) != 1)
  6152. {
  6153. setSocketBlockingState (handle, true);
  6154. return false;
  6155. }
  6156. }
  6157. }
  6158. setSocketBlockingState (handle, true);
  6159. resetSocketOptions (handle, false, false);
  6160. return true;
  6161. }
  6162. StreamingSocket::StreamingSocket()
  6163. : portNumber (0),
  6164. handle (-1),
  6165. connected (false),
  6166. isListener (false)
  6167. {
  6168. #if JUCE_WINDOWS
  6169. initWin32Sockets();
  6170. #endif
  6171. }
  6172. StreamingSocket::StreamingSocket (const String& hostName_,
  6173. const int portNumber_,
  6174. const int handle_)
  6175. : hostName (hostName_),
  6176. portNumber (portNumber_),
  6177. handle (handle_),
  6178. connected (true),
  6179. isListener (false)
  6180. {
  6181. #if JUCE_WINDOWS
  6182. initWin32Sockets();
  6183. #endif
  6184. resetSocketOptions (handle_, false, false);
  6185. }
  6186. StreamingSocket::~StreamingSocket()
  6187. {
  6188. close();
  6189. }
  6190. int StreamingSocket::read (void* destBuffer, const int maxBytesToRead, const bool blockUntilSpecifiedAmountHasArrived)
  6191. {
  6192. return (connected && ! isListener) ? readSocket (handle, destBuffer, maxBytesToRead, connected, blockUntilSpecifiedAmountHasArrived)
  6193. : -1;
  6194. }
  6195. int StreamingSocket::write (const void* sourceBuffer, const int numBytesToWrite)
  6196. {
  6197. if (isListener || ! connected)
  6198. return -1;
  6199. #if JUCE_WINDOWS
  6200. return send (handle, (const char*) sourceBuffer, numBytesToWrite, 0);
  6201. #else
  6202. int result;
  6203. while ((result = (int) ::write (handle, sourceBuffer, numBytesToWrite)) < 0
  6204. && errno == EINTR)
  6205. {
  6206. }
  6207. return result;
  6208. #endif
  6209. }
  6210. int StreamingSocket::waitUntilReady (const bool readyForReading,
  6211. const int timeoutMsecs) const
  6212. {
  6213. return connected ? waitForReadiness (handle, readyForReading, timeoutMsecs)
  6214. : -1;
  6215. }
  6216. bool StreamingSocket::bindToPort (const int port)
  6217. {
  6218. return bindSocketToPort (handle, port);
  6219. }
  6220. bool StreamingSocket::connect (const String& remoteHostName,
  6221. const int remotePortNumber,
  6222. const int timeOutMillisecs)
  6223. {
  6224. if (isListener)
  6225. {
  6226. jassertfalse // a listener socket can't connect to another one!
  6227. return false;
  6228. }
  6229. if (connected)
  6230. close();
  6231. hostName = remoteHostName;
  6232. portNumber = remotePortNumber;
  6233. isListener = false;
  6234. connected = connectSocket (handle, false, 0, remoteHostName,
  6235. remotePortNumber, timeOutMillisecs);
  6236. if (! (connected && resetSocketOptions (handle, false, false)))
  6237. {
  6238. close();
  6239. return false;
  6240. }
  6241. return true;
  6242. }
  6243. void StreamingSocket::close()
  6244. {
  6245. #if JUCE_WINDOWS
  6246. closesocket (handle);
  6247. connected = false;
  6248. #else
  6249. if (connected)
  6250. {
  6251. connected = false;
  6252. if (isListener)
  6253. {
  6254. // need to do this to interrupt the accept() function..
  6255. StreamingSocket temp;
  6256. temp.connect ("localhost", portNumber, 1000);
  6257. }
  6258. }
  6259. ::close (handle);
  6260. #endif
  6261. hostName = String::empty;
  6262. portNumber = 0;
  6263. handle = -1;
  6264. isListener = false;
  6265. }
  6266. bool StreamingSocket::createListener (const int newPortNumber, const String& localHostName)
  6267. {
  6268. if (connected)
  6269. close();
  6270. hostName = "listener";
  6271. portNumber = newPortNumber;
  6272. isListener = true;
  6273. struct sockaddr_in servTmpAddr;
  6274. zerostruct (servTmpAddr);
  6275. servTmpAddr.sin_family = PF_INET;
  6276. servTmpAddr.sin_addr.s_addr = htonl (INADDR_ANY);
  6277. if (localHostName.isNotEmpty())
  6278. servTmpAddr.sin_addr.s_addr = ::inet_addr (localHostName.toUTF8());
  6279. servTmpAddr.sin_port = htons ((uint16) portNumber);
  6280. handle = (int) socket (AF_INET, SOCK_STREAM, 0);
  6281. if (handle < 0)
  6282. return false;
  6283. const int reuse = 1;
  6284. setsockopt (handle, SOL_SOCKET, SO_REUSEADDR, (const char*) &reuse, sizeof (reuse));
  6285. if (bind (handle, (struct sockaddr*) &servTmpAddr, sizeof (struct sockaddr_in)) < 0
  6286. || listen (handle, SOMAXCONN) < 0)
  6287. {
  6288. close();
  6289. return false;
  6290. }
  6291. connected = true;
  6292. return true;
  6293. }
  6294. StreamingSocket* StreamingSocket::waitForNextConnection() const
  6295. {
  6296. jassert (isListener || ! connected); // to call this method, you first have to use createListener() to
  6297. // prepare this socket as a listener.
  6298. if (connected && isListener)
  6299. {
  6300. struct sockaddr address;
  6301. juce_socklen_t len = sizeof (sockaddr);
  6302. const int newSocket = (int) accept (handle, &address, &len);
  6303. if (newSocket >= 0 && connected)
  6304. return new StreamingSocket (inet_ntoa (((struct sockaddr_in*) &address)->sin_addr),
  6305. portNumber, newSocket);
  6306. }
  6307. return 0;
  6308. }
  6309. bool StreamingSocket::isLocal() const throw()
  6310. {
  6311. return hostName == T("127.0.0.1");
  6312. }
  6313. DatagramSocket::DatagramSocket (const int localPortNumber, const bool allowBroadcast_)
  6314. : portNumber (0),
  6315. handle (-1),
  6316. connected (true),
  6317. allowBroadcast (allowBroadcast_),
  6318. serverAddress (0)
  6319. {
  6320. #if JUCE_WINDOWS
  6321. initWin32Sockets();
  6322. #endif
  6323. handle = (int) socket (AF_INET, SOCK_DGRAM, 0);
  6324. bindToPort (localPortNumber);
  6325. }
  6326. DatagramSocket::DatagramSocket (const String& hostName_, const int portNumber_,
  6327. const int handle_, const int localPortNumber)
  6328. : hostName (hostName_),
  6329. portNumber (portNumber_),
  6330. handle (handle_),
  6331. connected (true),
  6332. allowBroadcast (false),
  6333. serverAddress (0)
  6334. {
  6335. #if JUCE_WINDOWS
  6336. initWin32Sockets();
  6337. #endif
  6338. resetSocketOptions (handle_, true, allowBroadcast);
  6339. bindToPort (localPortNumber);
  6340. }
  6341. DatagramSocket::~DatagramSocket()
  6342. {
  6343. close();
  6344. delete ((struct sockaddr_in*) serverAddress);
  6345. serverAddress = 0;
  6346. }
  6347. void DatagramSocket::close()
  6348. {
  6349. #if JUCE_WINDOWS
  6350. closesocket (handle);
  6351. connected = false;
  6352. #else
  6353. connected = false;
  6354. ::close (handle);
  6355. #endif
  6356. hostName = String::empty;
  6357. portNumber = 0;
  6358. handle = -1;
  6359. }
  6360. bool DatagramSocket::bindToPort (const int port)
  6361. {
  6362. return bindSocketToPort (handle, port);
  6363. }
  6364. bool DatagramSocket::connect (const String& remoteHostName,
  6365. const int remotePortNumber,
  6366. const int timeOutMillisecs)
  6367. {
  6368. if (connected)
  6369. close();
  6370. hostName = remoteHostName;
  6371. portNumber = remotePortNumber;
  6372. connected = connectSocket (handle, true, &serverAddress,
  6373. remoteHostName, remotePortNumber,
  6374. timeOutMillisecs);
  6375. if (! (connected && resetSocketOptions (handle, true, allowBroadcast)))
  6376. {
  6377. close();
  6378. return false;
  6379. }
  6380. return true;
  6381. }
  6382. DatagramSocket* DatagramSocket::waitForNextConnection() const
  6383. {
  6384. struct sockaddr address;
  6385. juce_socklen_t len = sizeof (sockaddr);
  6386. while (waitUntilReady (true, -1) == 1)
  6387. {
  6388. char buf[1];
  6389. if (recvfrom (handle, buf, 0, 0, &address, &len) > 0)
  6390. {
  6391. return new DatagramSocket (inet_ntoa (((struct sockaddr_in*) &address)->sin_addr),
  6392. ntohs (((struct sockaddr_in*) &address)->sin_port),
  6393. -1, -1);
  6394. }
  6395. }
  6396. return 0;
  6397. }
  6398. int DatagramSocket::waitUntilReady (const bool readyForReading,
  6399. const int timeoutMsecs) const
  6400. {
  6401. return connected ? waitForReadiness (handle, readyForReading, timeoutMsecs)
  6402. : -1;
  6403. }
  6404. int DatagramSocket::read (void* destBuffer, const int maxBytesToRead, const bool blockUntilSpecifiedAmountHasArrived)
  6405. {
  6406. return connected ? readSocket (handle, destBuffer, maxBytesToRead, connected, blockUntilSpecifiedAmountHasArrived)
  6407. : -1;
  6408. }
  6409. int DatagramSocket::write (const void* sourceBuffer, const int numBytesToWrite)
  6410. {
  6411. // You need to call connect() first to set the server address..
  6412. jassert (serverAddress != 0 && connected);
  6413. return connected ? (int) sendto (handle, (const char*) sourceBuffer,
  6414. numBytesToWrite, 0,
  6415. (const struct sockaddr*) serverAddress,
  6416. sizeof (struct sockaddr_in))
  6417. : -1;
  6418. }
  6419. bool DatagramSocket::isLocal() const throw()
  6420. {
  6421. return hostName == T("127.0.0.1");
  6422. }
  6423. END_JUCE_NAMESPACE
  6424. /*** End of inlined file: juce_Socket.cpp ***/
  6425. /*** Start of inlined file: juce_URL.cpp ***/
  6426. BEGIN_JUCE_NAMESPACE
  6427. URL::URL()
  6428. {
  6429. }
  6430. URL::URL (const String& url_)
  6431. : url (url_)
  6432. {
  6433. int i = url.indexOfChar (T('?'));
  6434. if (i >= 0)
  6435. {
  6436. do
  6437. {
  6438. const int nextAmp = url.indexOfChar (i + 1, T('&'));
  6439. const int equalsPos = url.indexOfChar (i + 1, T('='));
  6440. if (equalsPos > i + 1)
  6441. {
  6442. if (nextAmp < 0)
  6443. {
  6444. parameters.set (removeEscapeChars (url.substring (i + 1, equalsPos)),
  6445. removeEscapeChars (url.substring (equalsPos + 1)));
  6446. }
  6447. else if (nextAmp > 0 && equalsPos < nextAmp)
  6448. {
  6449. parameters.set (removeEscapeChars (url.substring (i + 1, equalsPos)),
  6450. removeEscapeChars (url.substring (equalsPos + 1, nextAmp)));
  6451. }
  6452. }
  6453. i = nextAmp;
  6454. }
  6455. while (i >= 0);
  6456. url = url.upToFirstOccurrenceOf (T("?"), false, false);
  6457. }
  6458. }
  6459. URL::URL (const URL& other)
  6460. : url (other.url),
  6461. postData (other.postData),
  6462. parameters (other.parameters),
  6463. filesToUpload (other.filesToUpload),
  6464. mimeTypes (other.mimeTypes)
  6465. {
  6466. }
  6467. const URL& URL::operator= (const URL& other)
  6468. {
  6469. url = other.url;
  6470. postData = other.postData;
  6471. parameters = other.parameters;
  6472. filesToUpload = other.filesToUpload;
  6473. mimeTypes = other.mimeTypes;
  6474. return *this;
  6475. }
  6476. URL::~URL()
  6477. {
  6478. }
  6479. static const String getMangledParameters (const StringPairArray& parameters)
  6480. {
  6481. String p;
  6482. for (int i = 0; i < parameters.size(); ++i)
  6483. {
  6484. if (i > 0)
  6485. p += T("&");
  6486. p << URL::addEscapeChars (parameters.getAllKeys() [i], true)
  6487. << T("=")
  6488. << URL::addEscapeChars (parameters.getAllValues() [i], true);
  6489. }
  6490. return p;
  6491. }
  6492. const String URL::toString (const bool includeGetParameters) const
  6493. {
  6494. if (includeGetParameters && parameters.size() > 0)
  6495. return url + T("?") + getMangledParameters (parameters);
  6496. else
  6497. return url;
  6498. }
  6499. bool URL::isWellFormed() const
  6500. {
  6501. //xxx TODO
  6502. return url.isNotEmpty();
  6503. }
  6504. static int findStartOfDomain (const String& url)
  6505. {
  6506. int i = 0;
  6507. while (CharacterFunctions::isLetterOrDigit (url[i])
  6508. || CharacterFunctions::indexOfChar (T("+-."), url[i], false) >= 0)
  6509. ++i;
  6510. return url[i] == T(':') ? i + 1 : 0;
  6511. }
  6512. const String URL::getDomain() const
  6513. {
  6514. int start = findStartOfDomain (url);
  6515. while (url[start] == T('/'))
  6516. ++start;
  6517. const int end1 = url.indexOfChar (start, T('/'));
  6518. const int end2 = url.indexOfChar (start, T(':'));
  6519. const int end = (end1 < 0 || end2 < 0) ? jmax (end1, end2)
  6520. : jmin (end1, end2);
  6521. return url.substring (start, end);
  6522. }
  6523. const String URL::getSubPath() const
  6524. {
  6525. int start = findStartOfDomain (url);
  6526. while (url[start] == T('/'))
  6527. ++start;
  6528. const int startOfPath = url.indexOfChar (start, T('/')) + 1;
  6529. return startOfPath <= 0 ? String::empty
  6530. : url.substring (startOfPath);
  6531. }
  6532. const String URL::getScheme() const
  6533. {
  6534. return url.substring (0, findStartOfDomain (url) - 1);
  6535. }
  6536. const URL URL::withNewSubPath (const String& newPath) const
  6537. {
  6538. int start = findStartOfDomain (url);
  6539. while (url[start] == T('/'))
  6540. ++start;
  6541. const int startOfPath = url.indexOfChar (start, T('/')) + 1;
  6542. URL u (*this);
  6543. if (startOfPath > 0)
  6544. u.url = url.substring (0, startOfPath);
  6545. if (! u.url.endsWithChar (T('/')))
  6546. u.url << '/';
  6547. if (newPath.startsWithChar (T('/')))
  6548. u.url << newPath.substring (1);
  6549. else
  6550. u.url << newPath;
  6551. return u;
  6552. }
  6553. bool URL::isProbablyAWebsiteURL (const String& possibleURL)
  6554. {
  6555. if (possibleURL.startsWithIgnoreCase (T("http:"))
  6556. || possibleURL.startsWithIgnoreCase (T("ftp:")))
  6557. return true;
  6558. if (possibleURL.startsWithIgnoreCase (T("file:"))
  6559. || possibleURL.containsChar (T('@'))
  6560. || possibleURL.endsWithChar (T('.'))
  6561. || (! possibleURL.containsChar (T('.'))))
  6562. return false;
  6563. if (possibleURL.startsWithIgnoreCase (T("www."))
  6564. && possibleURL.substring (5).containsChar (T('.')))
  6565. return true;
  6566. const char* commonTLDs[] = { "com", "net", "org", "uk", "de", "fr", "jp" };
  6567. for (int i = 0; i < numElementsInArray (commonTLDs); ++i)
  6568. if ((possibleURL + T("/")).containsIgnoreCase (T(".") + String (commonTLDs[i]) + T("/")))
  6569. return true;
  6570. return false;
  6571. }
  6572. bool URL::isProbablyAnEmailAddress (const String& possibleEmailAddress)
  6573. {
  6574. const int atSign = possibleEmailAddress.indexOfChar (T('@'));
  6575. return atSign > 0
  6576. && possibleEmailAddress.lastIndexOfChar (T('.')) > (atSign + 1)
  6577. && (! possibleEmailAddress.endsWithChar (T('.')));
  6578. }
  6579. void* juce_openInternetFile (const String& url,
  6580. const String& headers,
  6581. const MemoryBlock& optionalPostData,
  6582. const bool isPost,
  6583. URL::OpenStreamProgressCallback* callback,
  6584. void* callbackContext,
  6585. int timeOutMs);
  6586. void juce_closeInternetFile (void* handle);
  6587. int juce_readFromInternetFile (void* handle, void* dest, int bytesToRead);
  6588. int juce_seekInInternetFile (void* handle, int newPosition);
  6589. int64 juce_getInternetFileContentLength (void* handle);
  6590. class WebInputStream : public InputStream
  6591. {
  6592. public:
  6593. WebInputStream (const URL& url,
  6594. const bool isPost_,
  6595. URL::OpenStreamProgressCallback* const progressCallback_,
  6596. void* const progressCallbackContext_,
  6597. const String& extraHeaders,
  6598. int timeOutMs_)
  6599. : position (0),
  6600. finished (false),
  6601. isPost (isPost_),
  6602. progressCallback (progressCallback_),
  6603. progressCallbackContext (progressCallbackContext_),
  6604. timeOutMs (timeOutMs_)
  6605. {
  6606. server = url.toString (! isPost);
  6607. if (isPost_)
  6608. createHeadersAndPostData (url);
  6609. headers += extraHeaders;
  6610. if (! headers.endsWithChar (T('\n')))
  6611. headers << "\r\n";
  6612. handle = juce_openInternetFile (server, headers, postData, isPost,
  6613. progressCallback_, progressCallbackContext_,
  6614. timeOutMs);
  6615. }
  6616. ~WebInputStream()
  6617. {
  6618. juce_closeInternetFile (handle);
  6619. }
  6620. bool isError() const
  6621. {
  6622. return handle == 0;
  6623. }
  6624. int64 getTotalLength()
  6625. {
  6626. return juce_getInternetFileContentLength (handle);
  6627. }
  6628. bool isExhausted()
  6629. {
  6630. return finished;
  6631. }
  6632. int read (void* dest, int bytes)
  6633. {
  6634. if (finished || isError())
  6635. {
  6636. return 0;
  6637. }
  6638. else
  6639. {
  6640. const int bytesRead = juce_readFromInternetFile (handle, dest, bytes);
  6641. position += bytesRead;
  6642. if (bytesRead == 0)
  6643. finished = true;
  6644. return bytesRead;
  6645. }
  6646. }
  6647. int64 getPosition()
  6648. {
  6649. return position;
  6650. }
  6651. bool setPosition (int64 wantedPos)
  6652. {
  6653. if (wantedPos != position)
  6654. {
  6655. finished = false;
  6656. const int actualPos = juce_seekInInternetFile (handle, (int) wantedPos);
  6657. if (actualPos == wantedPos)
  6658. {
  6659. position = wantedPos;
  6660. }
  6661. else
  6662. {
  6663. if (wantedPos < position)
  6664. {
  6665. juce_closeInternetFile (handle);
  6666. position = 0;
  6667. finished = false;
  6668. handle = juce_openInternetFile (server, headers, postData, isPost,
  6669. progressCallback, progressCallbackContext,
  6670. timeOutMs);
  6671. }
  6672. skipNextBytes (wantedPos - position);
  6673. }
  6674. }
  6675. return true;
  6676. }
  6677. juce_UseDebuggingNewOperator
  6678. private:
  6679. String server, headers;
  6680. MemoryBlock postData;
  6681. int64 position;
  6682. bool finished;
  6683. const bool isPost;
  6684. void* handle;
  6685. URL::OpenStreamProgressCallback* const progressCallback;
  6686. void* const progressCallbackContext;
  6687. const int timeOutMs;
  6688. void createHeadersAndPostData (const URL& url)
  6689. {
  6690. if (url.getFilesToUpload().size() > 0)
  6691. {
  6692. // need to upload some files, so do it as multi-part...
  6693. String boundary (String::toHexString (Random::getSystemRandom().nextInt64()));
  6694. headers << "Content-Type: multipart/form-data; boundary=" << boundary << "\r\n";
  6695. appendUTF8ToPostData ("--" + boundary);
  6696. int i;
  6697. for (i = 0; i < url.getParameters().size(); ++i)
  6698. {
  6699. String s;
  6700. s << "\r\nContent-Disposition: form-data; name=\""
  6701. << url.getParameters().getAllKeys() [i]
  6702. << "\"\r\n\r\n"
  6703. << url.getParameters().getAllValues() [i]
  6704. << "\r\n--"
  6705. << boundary;
  6706. appendUTF8ToPostData (s);
  6707. }
  6708. for (i = 0; i < url.getFilesToUpload().size(); ++i)
  6709. {
  6710. const File f (url.getFilesToUpload().getAllValues() [i]);
  6711. const String paramName (url.getFilesToUpload().getAllKeys() [i]);
  6712. String s;
  6713. s << "\r\nContent-Disposition: form-data; name=\""
  6714. << paramName
  6715. << "\"; filename=\""
  6716. << f.getFileName()
  6717. << "\"\r\n";
  6718. const String mimeType (url.getMimeTypesOfUploadFiles()
  6719. .getValue (paramName, String::empty));
  6720. if (mimeType.isNotEmpty())
  6721. s << "Content-Type: " << mimeType << "\r\n";
  6722. s << "Content-Transfer-Encoding: binary\r\n\r\n";
  6723. appendUTF8ToPostData (s);
  6724. f.loadFileAsData (postData);
  6725. s = "\r\n--" + boundary;
  6726. appendUTF8ToPostData (s);
  6727. }
  6728. appendUTF8ToPostData ("--\r\n");
  6729. }
  6730. else
  6731. {
  6732. appendUTF8ToPostData (getMangledParameters (url.getParameters()));
  6733. appendUTF8ToPostData (url.getPostData());
  6734. // just a short text attachment, so use simple url encoding..
  6735. headers = "Content-Type: application/x-www-form-urlencoded\r\nContent-length: "
  6736. + String ((unsigned int) postData.getSize())
  6737. + "\r\n";
  6738. }
  6739. }
  6740. void appendUTF8ToPostData (const String& text)
  6741. {
  6742. postData.append (text.toUTF8(),
  6743. (int) strlen (text.toUTF8()));
  6744. }
  6745. WebInputStream (const WebInputStream&);
  6746. const WebInputStream& operator= (const WebInputStream&);
  6747. };
  6748. InputStream* URL::createInputStream (const bool usePostCommand,
  6749. OpenStreamProgressCallback* const progressCallback,
  6750. void* const progressCallbackContext,
  6751. const String& extraHeaders,
  6752. const int timeOutMs) const
  6753. {
  6754. ScopedPointer <WebInputStream> wi (new WebInputStream (*this, usePostCommand,
  6755. progressCallback, progressCallbackContext,
  6756. extraHeaders,
  6757. timeOutMs));
  6758. return wi->isError() ? 0 : wi.release();
  6759. }
  6760. bool URL::readEntireBinaryStream (MemoryBlock& destData,
  6761. const bool usePostCommand) const
  6762. {
  6763. const ScopedPointer <InputStream> in (createInputStream (usePostCommand));
  6764. if (in != 0)
  6765. {
  6766. in->readIntoMemoryBlock (destData, -1);
  6767. return true;
  6768. }
  6769. return false;
  6770. }
  6771. const String URL::readEntireTextStream (const bool usePostCommand) const
  6772. {
  6773. const ScopedPointer <InputStream> in (createInputStream (usePostCommand));
  6774. if (in != 0)
  6775. return in->readEntireStreamAsString();
  6776. return String::empty;
  6777. }
  6778. XmlElement* URL::readEntireXmlStream (const bool usePostCommand) const
  6779. {
  6780. XmlDocument doc (readEntireTextStream (usePostCommand));
  6781. return doc.getDocumentElement();
  6782. }
  6783. const URL URL::withParameter (const String& parameterName,
  6784. const String& parameterValue) const
  6785. {
  6786. URL u (*this);
  6787. u.parameters.set (parameterName, parameterValue);
  6788. return u;
  6789. }
  6790. const URL URL::withFileToUpload (const String& parameterName,
  6791. const File& fileToUpload,
  6792. const String& mimeType) const
  6793. {
  6794. jassert (mimeType.isNotEmpty()); // You need to supply a mime type!
  6795. URL u (*this);
  6796. u.filesToUpload.set (parameterName, fileToUpload.getFullPathName());
  6797. u.mimeTypes.set (parameterName, mimeType);
  6798. return u;
  6799. }
  6800. const URL URL::withPOSTData (const String& postData_) const
  6801. {
  6802. URL u (*this);
  6803. u.postData = postData_;
  6804. return u;
  6805. }
  6806. const StringPairArray& URL::getParameters() const
  6807. {
  6808. return parameters;
  6809. }
  6810. const StringPairArray& URL::getFilesToUpload() const
  6811. {
  6812. return filesToUpload;
  6813. }
  6814. const StringPairArray& URL::getMimeTypesOfUploadFiles() const
  6815. {
  6816. return mimeTypes;
  6817. }
  6818. const String URL::removeEscapeChars (const String& s)
  6819. {
  6820. const int len = s.length();
  6821. HeapBlock <uint8> resultUTF8 (len * 4);
  6822. uint8* r = resultUTF8;
  6823. for (int i = 0; i < len; ++i)
  6824. {
  6825. char c = (char) s[i];
  6826. if (c == 0)
  6827. break;
  6828. if (c == '+')
  6829. {
  6830. c = ' ';
  6831. }
  6832. else if (c == '%')
  6833. {
  6834. c = (char) s.substring (i + 1, i + 3).getHexValue32();
  6835. i += 2;
  6836. }
  6837. *r++ = c;
  6838. }
  6839. return String::fromUTF8 (resultUTF8);
  6840. }
  6841. const String URL::addEscapeChars (const String& s, const bool isParameter)
  6842. {
  6843. String result;
  6844. result.preallocateStorage (s.length() + 8);
  6845. const char* utf8 = s.toUTF8();
  6846. const char* legalChars = isParameter ? "_-.*!'()"
  6847. : "_-$.*!'(),";
  6848. while (*utf8 != 0)
  6849. {
  6850. const char c = *utf8++;
  6851. if (CharacterFunctions::isLetterOrDigit (c)
  6852. || CharacterFunctions::indexOfChar (legalChars, c, false) >= 0)
  6853. {
  6854. result << c;
  6855. }
  6856. else
  6857. {
  6858. const int v = (int) (uint8) c;
  6859. if (v < 0x10)
  6860. result << T("%0");
  6861. else
  6862. result << T('%');
  6863. result << String::toHexString (v);
  6864. }
  6865. }
  6866. return result;
  6867. }
  6868. extern bool juce_launchFile (const String& fileName, const String& parameters);
  6869. bool URL::launchInDefaultBrowser() const
  6870. {
  6871. String u (toString (true));
  6872. if (u.contains (T("@")) && ! u.contains (T(":")))
  6873. u = "mailto:" + u;
  6874. return juce_launchFile (u, String::empty);
  6875. }
  6876. END_JUCE_NAMESPACE
  6877. /*** End of inlined file: juce_URL.cpp ***/
  6878. /*** Start of inlined file: juce_BufferedInputStream.cpp ***/
  6879. BEGIN_JUCE_NAMESPACE
  6880. BufferedInputStream::BufferedInputStream (InputStream* const source_,
  6881. const int bufferSize_,
  6882. const bool deleteSourceWhenDestroyed)
  6883. : source (source_),
  6884. sourceToDelete (deleteSourceWhenDestroyed ? source_ : 0),
  6885. bufferSize (jmax (256, bufferSize_)),
  6886. position (source_->getPosition()),
  6887. lastReadPos (0),
  6888. bufferOverlap (128)
  6889. {
  6890. const int sourceSize = (int) source_->getTotalLength();
  6891. if (sourceSize >= 0)
  6892. bufferSize = jmin (jmax (32, sourceSize), bufferSize);
  6893. bufferStart = position;
  6894. buffer.malloc (bufferSize);
  6895. }
  6896. BufferedInputStream::~BufferedInputStream()
  6897. {
  6898. }
  6899. int64 BufferedInputStream::getTotalLength()
  6900. {
  6901. return source->getTotalLength();
  6902. }
  6903. int64 BufferedInputStream::getPosition()
  6904. {
  6905. return position;
  6906. }
  6907. bool BufferedInputStream::setPosition (int64 newPosition)
  6908. {
  6909. position = jmax ((int64) 0, newPosition);
  6910. return true;
  6911. }
  6912. bool BufferedInputStream::isExhausted()
  6913. {
  6914. return (position >= lastReadPos)
  6915. && source->isExhausted();
  6916. }
  6917. void BufferedInputStream::ensureBuffered()
  6918. {
  6919. const int64 bufferEndOverlap = lastReadPos - bufferOverlap;
  6920. if (position < bufferStart || position >= bufferEndOverlap)
  6921. {
  6922. int bytesRead;
  6923. if (position < lastReadPos
  6924. && position >= bufferEndOverlap
  6925. && position >= bufferStart)
  6926. {
  6927. const int bytesToKeep = (int) (lastReadPos - position);
  6928. memmove (buffer, buffer + (int) (position - bufferStart), bytesToKeep);
  6929. bufferStart = position;
  6930. bytesRead = source->read (buffer + bytesToKeep,
  6931. bufferSize - bytesToKeep);
  6932. lastReadPos += bytesRead;
  6933. bytesRead += bytesToKeep;
  6934. }
  6935. else
  6936. {
  6937. bufferStart = position;
  6938. source->setPosition (bufferStart);
  6939. bytesRead = source->read (buffer, bufferSize);
  6940. lastReadPos = bufferStart + bytesRead;
  6941. }
  6942. while (bytesRead < bufferSize)
  6943. buffer [bytesRead++] = 0;
  6944. }
  6945. }
  6946. int BufferedInputStream::read (void* destBuffer, int maxBytesToRead)
  6947. {
  6948. if (position >= bufferStart
  6949. && position + maxBytesToRead <= lastReadPos)
  6950. {
  6951. memcpy (destBuffer, buffer + (int) (position - bufferStart), maxBytesToRead);
  6952. position += maxBytesToRead;
  6953. return maxBytesToRead;
  6954. }
  6955. else
  6956. {
  6957. if (position < bufferStart || position >= lastReadPos)
  6958. ensureBuffered();
  6959. int bytesRead = 0;
  6960. while (maxBytesToRead > 0)
  6961. {
  6962. const int bytesAvailable = jmin (maxBytesToRead, (int) (lastReadPos - position));
  6963. if (bytesAvailable > 0)
  6964. {
  6965. memcpy (destBuffer, buffer + (int) (position - bufferStart), bytesAvailable);
  6966. maxBytesToRead -= bytesAvailable;
  6967. bytesRead += bytesAvailable;
  6968. position += bytesAvailable;
  6969. destBuffer = (void*) (((char*) destBuffer) + bytesAvailable);
  6970. }
  6971. const int64 oldLastReadPos = lastReadPos;
  6972. ensureBuffered();
  6973. if (oldLastReadPos == lastReadPos)
  6974. break; // if ensureBuffered() failed to read any more data, bail out
  6975. if (isExhausted())
  6976. break;
  6977. }
  6978. return bytesRead;
  6979. }
  6980. }
  6981. const String BufferedInputStream::readString()
  6982. {
  6983. if (position >= bufferStart
  6984. && position < lastReadPos)
  6985. {
  6986. const int maxChars = (int) (lastReadPos - position);
  6987. const char* const src = buffer + (int) (position - bufferStart);
  6988. for (int i = 0; i < maxChars; ++i)
  6989. {
  6990. if (src[i] == 0)
  6991. {
  6992. position += i + 1;
  6993. return String::fromUTF8 ((const uint8*) src, i);
  6994. }
  6995. }
  6996. }
  6997. return InputStream::readString();
  6998. }
  6999. END_JUCE_NAMESPACE
  7000. /*** End of inlined file: juce_BufferedInputStream.cpp ***/
  7001. /*** Start of inlined file: juce_FileInputSource.cpp ***/
  7002. BEGIN_JUCE_NAMESPACE
  7003. FileInputSource::FileInputSource (const File& file_)
  7004. : file (file_)
  7005. {
  7006. }
  7007. FileInputSource::~FileInputSource()
  7008. {
  7009. }
  7010. InputStream* FileInputSource::createInputStream()
  7011. {
  7012. return file.createInputStream();
  7013. }
  7014. InputStream* FileInputSource::createInputStreamFor (const String& relatedItemPath)
  7015. {
  7016. return file.getSiblingFile (relatedItemPath).createInputStream();
  7017. }
  7018. int64 FileInputSource::hashCode() const
  7019. {
  7020. return file.hashCode();
  7021. }
  7022. END_JUCE_NAMESPACE
  7023. /*** End of inlined file: juce_FileInputSource.cpp ***/
  7024. /*** Start of inlined file: juce_MemoryInputStream.cpp ***/
  7025. BEGIN_JUCE_NAMESPACE
  7026. MemoryInputStream::MemoryInputStream (const void* const sourceData,
  7027. const size_t sourceDataSize,
  7028. const bool keepInternalCopy)
  7029. : data ((const char*) sourceData),
  7030. dataSize (sourceDataSize),
  7031. position (0)
  7032. {
  7033. if (keepInternalCopy)
  7034. {
  7035. internalCopy.append (data, sourceDataSize);
  7036. data = (const char*) internalCopy.getData();
  7037. }
  7038. }
  7039. MemoryInputStream::~MemoryInputStream()
  7040. {
  7041. }
  7042. int64 MemoryInputStream::getTotalLength()
  7043. {
  7044. return dataSize;
  7045. }
  7046. int MemoryInputStream::read (void* buffer, int howMany)
  7047. {
  7048. jassert (howMany >= 0);
  7049. const int num = jmin (howMany, (int) (dataSize - position));
  7050. memcpy (buffer, data + position, num);
  7051. position += num;
  7052. return (int) num;
  7053. }
  7054. bool MemoryInputStream::isExhausted()
  7055. {
  7056. return (position >= dataSize);
  7057. }
  7058. bool MemoryInputStream::setPosition (int64 pos)
  7059. {
  7060. position = (int) jlimit ((int64) 0, (int64) dataSize, pos);
  7061. return true;
  7062. }
  7063. int64 MemoryInputStream::getPosition()
  7064. {
  7065. return position;
  7066. }
  7067. END_JUCE_NAMESPACE
  7068. /*** End of inlined file: juce_MemoryInputStream.cpp ***/
  7069. /*** Start of inlined file: juce_MemoryOutputStream.cpp ***/
  7070. BEGIN_JUCE_NAMESPACE
  7071. MemoryOutputStream::MemoryOutputStream (const size_t initialSize,
  7072. const size_t blockSizeToIncreaseBy,
  7073. MemoryBlock* const memoryBlockToWriteTo) throw()
  7074. : data (memoryBlockToWriteTo),
  7075. position (0),
  7076. size (0),
  7077. blockSize (jmax ((size_t) 16, blockSizeToIncreaseBy))
  7078. {
  7079. if (data == 0)
  7080. dataToDelete = data = new MemoryBlock (initialSize);
  7081. else
  7082. data->setSize (initialSize, false);
  7083. }
  7084. MemoryOutputStream::~MemoryOutputStream() throw()
  7085. {
  7086. flush();
  7087. }
  7088. void MemoryOutputStream::flush()
  7089. {
  7090. if (dataToDelete == 0)
  7091. data->setSize (size, false);
  7092. }
  7093. void MemoryOutputStream::reset() throw()
  7094. {
  7095. position = 0;
  7096. size = 0;
  7097. }
  7098. bool MemoryOutputStream::write (const void* buffer, int howMany)
  7099. {
  7100. if (howMany > 0)
  7101. {
  7102. size_t storageNeeded = position + howMany;
  7103. if (storageNeeded >= data->getSize())
  7104. {
  7105. // if we need more space, increase the block by at least 10%..
  7106. storageNeeded += jmax (blockSize, storageNeeded / 10);
  7107. storageNeeded = storageNeeded - (storageNeeded % blockSize) + blockSize;
  7108. data->ensureSize (storageNeeded);
  7109. }
  7110. data->copyFrom (buffer, (int) position, howMany);
  7111. position += howMany;
  7112. size = jmax (size, position);
  7113. }
  7114. return true;
  7115. }
  7116. const char* MemoryOutputStream::getData() const throw()
  7117. {
  7118. if (data->getSize() > size)
  7119. ((char*) data->getData()) [size] = 0;
  7120. return (const char*) data->getData();
  7121. }
  7122. size_t MemoryOutputStream::getDataSize() const throw()
  7123. {
  7124. return size;
  7125. }
  7126. int64 MemoryOutputStream::getPosition()
  7127. {
  7128. return position;
  7129. }
  7130. bool MemoryOutputStream::setPosition (int64 newPosition)
  7131. {
  7132. if (newPosition <= (int64) size)
  7133. {
  7134. // ok to seek backwards
  7135. position = jlimit ((size_t) 0, size, (size_t) newPosition);
  7136. return true;
  7137. }
  7138. else
  7139. {
  7140. // trying to make it bigger isn't a good thing to do..
  7141. return false;
  7142. }
  7143. }
  7144. END_JUCE_NAMESPACE
  7145. /*** End of inlined file: juce_MemoryOutputStream.cpp ***/
  7146. /*** Start of inlined file: juce_SubregionStream.cpp ***/
  7147. BEGIN_JUCE_NAMESPACE
  7148. SubregionStream::SubregionStream (InputStream* const sourceStream,
  7149. const int64 startPositionInSourceStream_,
  7150. const int64 lengthOfSourceStream_,
  7151. const bool deleteSourceWhenDestroyed) throw()
  7152. : source (sourceStream),
  7153. startPositionInSourceStream (startPositionInSourceStream_),
  7154. lengthOfSourceStream (lengthOfSourceStream_)
  7155. {
  7156. if (deleteSourceWhenDestroyed)
  7157. sourceToDelete = source;
  7158. setPosition (0);
  7159. }
  7160. SubregionStream::~SubregionStream() throw()
  7161. {
  7162. }
  7163. int64 SubregionStream::getTotalLength()
  7164. {
  7165. const int64 srcLen = source->getTotalLength() - startPositionInSourceStream;
  7166. return (lengthOfSourceStream >= 0) ? jmin (lengthOfSourceStream, srcLen)
  7167. : srcLen;
  7168. }
  7169. int64 SubregionStream::getPosition()
  7170. {
  7171. return source->getPosition() - startPositionInSourceStream;
  7172. }
  7173. bool SubregionStream::setPosition (int64 newPosition)
  7174. {
  7175. return source->setPosition (jmax ((int64) 0, newPosition + startPositionInSourceStream));
  7176. }
  7177. int SubregionStream::read (void* destBuffer, int maxBytesToRead)
  7178. {
  7179. if (lengthOfSourceStream < 0)
  7180. {
  7181. return source->read (destBuffer, maxBytesToRead);
  7182. }
  7183. else
  7184. {
  7185. maxBytesToRead = (int) jmin ((int64) maxBytesToRead, lengthOfSourceStream - getPosition());
  7186. if (maxBytesToRead <= 0)
  7187. return 0;
  7188. return source->read (destBuffer, maxBytesToRead);
  7189. }
  7190. }
  7191. bool SubregionStream::isExhausted()
  7192. {
  7193. if (lengthOfSourceStream >= 0)
  7194. return (getPosition() >= lengthOfSourceStream) || source->isExhausted();
  7195. else
  7196. return source->isExhausted();
  7197. }
  7198. END_JUCE_NAMESPACE
  7199. /*** End of inlined file: juce_SubregionStream.cpp ***/
  7200. /*** Start of inlined file: juce_PerformanceCounter.cpp ***/
  7201. BEGIN_JUCE_NAMESPACE
  7202. PerformanceCounter::PerformanceCounter (const String& name_,
  7203. int runsPerPrintout,
  7204. const File& loggingFile)
  7205. : name (name_),
  7206. numRuns (0),
  7207. runsPerPrint (runsPerPrintout),
  7208. totalTime (0),
  7209. outputFile (loggingFile)
  7210. {
  7211. if (outputFile != File::nonexistent)
  7212. {
  7213. String s ("**** Counter for \"");
  7214. s << name_ << "\" started at: "
  7215. << Time::getCurrentTime().toString (true, true)
  7216. << "\r\n";
  7217. outputFile.appendText (s, false, false);
  7218. }
  7219. }
  7220. PerformanceCounter::~PerformanceCounter()
  7221. {
  7222. printStatistics();
  7223. }
  7224. void PerformanceCounter::start()
  7225. {
  7226. started = Time::getHighResolutionTicks();
  7227. }
  7228. void PerformanceCounter::stop()
  7229. {
  7230. const int64 now = Time::getHighResolutionTicks();
  7231. totalTime += 1000.0 * Time::highResolutionTicksToSeconds (now - started);
  7232. if (++numRuns == runsPerPrint)
  7233. printStatistics();
  7234. }
  7235. void PerformanceCounter::printStatistics()
  7236. {
  7237. if (numRuns > 0)
  7238. {
  7239. String s ("Performance count for \"");
  7240. s << name << "\" - average over " << numRuns << " run(s) = ";
  7241. const int micros = (int) (totalTime * (1000.0 / numRuns));
  7242. if (micros > 10000)
  7243. s << (micros/1000) << " millisecs";
  7244. else
  7245. s << micros << " microsecs";
  7246. s << ", total = " << String (totalTime / 1000, 5) << " seconds";
  7247. Logger::outputDebugString (s);
  7248. s << "\r\n";
  7249. if (outputFile != File::nonexistent)
  7250. outputFile.appendText (s, false, false);
  7251. numRuns = 0;
  7252. totalTime = 0;
  7253. }
  7254. }
  7255. END_JUCE_NAMESPACE
  7256. /*** End of inlined file: juce_PerformanceCounter.cpp ***/
  7257. /*** Start of inlined file: juce_Uuid.cpp ***/
  7258. BEGIN_JUCE_NAMESPACE
  7259. Uuid::Uuid()
  7260. {
  7261. // Mix up any available MAC addresses with some time-based pseudo-random numbers
  7262. // to make it very very unlikely that two UUIDs will ever be the same..
  7263. static int64 macAddresses[2];
  7264. static bool hasCheckedMacAddresses = false;
  7265. if (! hasCheckedMacAddresses)
  7266. {
  7267. hasCheckedMacAddresses = true;
  7268. SystemStats::getMACAddresses (macAddresses, 2);
  7269. }
  7270. value.asInt64[0] = macAddresses[0];
  7271. value.asInt64[1] = macAddresses[1];
  7272. // We'll use both a local RNG that is re-seeded, plus the shared RNG,
  7273. // whose seed will carry over between calls to this method.
  7274. Random r (macAddresses[0] ^ macAddresses[1]
  7275. ^ Random::getSystemRandom().nextInt64());
  7276. for (int i = 4; --i >= 0;)
  7277. {
  7278. r.setSeedRandomly(); // calling this repeatedly improves randomness
  7279. value.asInt[i] ^= r.nextInt();
  7280. value.asInt[i] ^= Random::getSystemRandom().nextInt();
  7281. }
  7282. }
  7283. Uuid::~Uuid() throw()
  7284. {
  7285. }
  7286. Uuid::Uuid (const Uuid& other)
  7287. : value (other.value)
  7288. {
  7289. }
  7290. Uuid& Uuid::operator= (const Uuid& other)
  7291. {
  7292. value = other.value;
  7293. return *this;
  7294. }
  7295. bool Uuid::operator== (const Uuid& other) const
  7296. {
  7297. return memcmp (value.asBytes, other.value.asBytes, 16) == 0;
  7298. }
  7299. bool Uuid::operator!= (const Uuid& other) const
  7300. {
  7301. return ! operator== (other);
  7302. }
  7303. bool Uuid::isNull() const throw()
  7304. {
  7305. return (value.asInt64 [0] == 0) && (value.asInt64 [1] == 0);
  7306. }
  7307. const String Uuid::toString() const
  7308. {
  7309. return String::toHexString (value.asBytes, 16, 0);
  7310. }
  7311. Uuid::Uuid (const String& uuidString)
  7312. {
  7313. operator= (uuidString);
  7314. }
  7315. Uuid& Uuid::operator= (const String& uuidString)
  7316. {
  7317. int destIndex = 0;
  7318. int i = 0;
  7319. for (;;)
  7320. {
  7321. int byte = 0;
  7322. for (int loop = 2; --loop >= 0;)
  7323. {
  7324. byte <<= 4;
  7325. for (;;)
  7326. {
  7327. const tchar c = uuidString [i++];
  7328. if (c >= T('0') && c <= T('9'))
  7329. {
  7330. byte |= c - T('0');
  7331. break;
  7332. }
  7333. else if (c >= T('a') && c <= T('z'))
  7334. {
  7335. byte |= c - (T('a') - 10);
  7336. break;
  7337. }
  7338. else if (c >= T('A') && c <= T('Z'))
  7339. {
  7340. byte |= c - (T('A') - 10);
  7341. break;
  7342. }
  7343. else if (c == 0)
  7344. {
  7345. while (destIndex < 16)
  7346. value.asBytes [destIndex++] = 0;
  7347. return *this;
  7348. }
  7349. }
  7350. }
  7351. value.asBytes [destIndex++] = (uint8) byte;
  7352. }
  7353. }
  7354. Uuid::Uuid (const uint8* const rawData)
  7355. {
  7356. operator= (rawData);
  7357. }
  7358. Uuid& Uuid::operator= (const uint8* const rawData)
  7359. {
  7360. if (rawData != 0)
  7361. memcpy (value.asBytes, rawData, 16);
  7362. else
  7363. zeromem (value.asBytes, 16);
  7364. return *this;
  7365. }
  7366. END_JUCE_NAMESPACE
  7367. /*** End of inlined file: juce_Uuid.cpp ***/
  7368. /*** Start of inlined file: juce_ZipFile.cpp ***/
  7369. BEGIN_JUCE_NAMESPACE
  7370. class ZipFile::ZipEntryInfo
  7371. {
  7372. public:
  7373. ZipFile::ZipEntry entry;
  7374. int streamOffset;
  7375. int compressedSize;
  7376. bool compressed;
  7377. };
  7378. class ZipFile::ZipInputStream : public InputStream
  7379. {
  7380. public:
  7381. ZipInputStream (ZipFile& file_, ZipFile::ZipEntryInfo& zei)
  7382. : file (file_),
  7383. zipEntryInfo (zei),
  7384. pos (0),
  7385. headerSize (0),
  7386. inputStream (0)
  7387. {
  7388. inputStream = file_.inputStream;
  7389. if (file_.inputSource != 0)
  7390. {
  7391. inputStream = file.inputSource->createInputStream();
  7392. }
  7393. else
  7394. {
  7395. #ifdef JUCE_DEBUG
  7396. file_.numOpenStreams++;
  7397. #endif
  7398. }
  7399. char buffer [30];
  7400. if (inputStream != 0
  7401. && inputStream->setPosition (zei.streamOffset)
  7402. && inputStream->read (buffer, 30) == 30
  7403. && ByteOrder::littleEndianInt (buffer) == 0x04034b50)
  7404. {
  7405. headerSize = 30 + ByteOrder::littleEndianShort (buffer + 26)
  7406. + ByteOrder::littleEndianShort (buffer + 28);
  7407. }
  7408. }
  7409. ~ZipInputStream() throw()
  7410. {
  7411. #ifdef JUCE_DEBUG
  7412. if (inputStream != 0 && inputStream == file.inputStream)
  7413. file.numOpenStreams--;
  7414. #endif
  7415. if (inputStream != file.inputStream)
  7416. delete inputStream;
  7417. }
  7418. int64 getTotalLength() throw()
  7419. {
  7420. return zipEntryInfo.compressedSize;
  7421. }
  7422. int read (void* buffer, int howMany) throw()
  7423. {
  7424. if (headerSize <= 0)
  7425. return 0;
  7426. howMany = (int) jmin ((int64) howMany, zipEntryInfo.compressedSize - pos);
  7427. if (inputStream == 0)
  7428. return 0;
  7429. int num;
  7430. if (inputStream == file.inputStream)
  7431. {
  7432. const ScopedLock sl (file.lock);
  7433. inputStream->setPosition (pos + zipEntryInfo.streamOffset + headerSize);
  7434. num = inputStream->read (buffer, howMany);
  7435. }
  7436. else
  7437. {
  7438. inputStream->setPosition (pos + zipEntryInfo.streamOffset + headerSize);
  7439. num = inputStream->read (buffer, howMany);
  7440. }
  7441. pos += num;
  7442. return num;
  7443. }
  7444. bool isExhausted() throw()
  7445. {
  7446. return headerSize <= 0 || pos >= zipEntryInfo.compressedSize;
  7447. }
  7448. int64 getPosition() throw()
  7449. {
  7450. return pos;
  7451. }
  7452. bool setPosition (int64 newPos) throw()
  7453. {
  7454. pos = jlimit ((int64) 0, (int64) zipEntryInfo.compressedSize, newPos);
  7455. return true;
  7456. }
  7457. private:
  7458. ZipFile& file;
  7459. ZipEntryInfo zipEntryInfo;
  7460. int64 pos;
  7461. int headerSize;
  7462. InputStream* inputStream;
  7463. ZipInputStream (const ZipInputStream&);
  7464. const ZipInputStream& operator= (const ZipInputStream&);
  7465. };
  7466. ZipFile::ZipFile (InputStream* const source_,
  7467. const bool deleteStreamWhenDestroyed) throw()
  7468. : inputStream (source_)
  7469. #ifdef JUCE_DEBUG
  7470. , numOpenStreams (0)
  7471. #endif
  7472. {
  7473. if (deleteStreamWhenDestroyed)
  7474. streamToDelete = inputStream;
  7475. init();
  7476. }
  7477. ZipFile::ZipFile (const File& file)
  7478. : inputStream (0)
  7479. #ifdef JUCE_DEBUG
  7480. , numOpenStreams (0)
  7481. #endif
  7482. {
  7483. inputSource = new FileInputSource (file);
  7484. init();
  7485. }
  7486. ZipFile::ZipFile (InputSource* const inputSource_)
  7487. : inputStream (0),
  7488. inputSource (inputSource_)
  7489. #ifdef JUCE_DEBUG
  7490. , numOpenStreams (0)
  7491. #endif
  7492. {
  7493. init();
  7494. }
  7495. ZipFile::~ZipFile() throw()
  7496. {
  7497. #ifdef JUCE_DEBUG
  7498. entries.clear();
  7499. // If you hit this assertion, it means you've created a stream to read
  7500. // one of the items in the zipfile, but you've forgotten to delete that
  7501. // stream object before deleting the file.. Streams can't be kept open
  7502. // after the file is deleted because they need to share the input
  7503. // stream that the file uses to read itself.
  7504. jassert (numOpenStreams == 0);
  7505. #endif
  7506. }
  7507. int ZipFile::getNumEntries() const throw()
  7508. {
  7509. return entries.size();
  7510. }
  7511. const ZipFile::ZipEntry* ZipFile::getEntry (const int index) const throw()
  7512. {
  7513. ZipEntryInfo* const zei = (ZipEntryInfo*) entries [index];
  7514. return (zei != 0) ? &(zei->entry)
  7515. : 0;
  7516. }
  7517. int ZipFile::getIndexOfFileName (const String& fileName) const throw()
  7518. {
  7519. for (int i = 0; i < entries.size(); ++i)
  7520. if (entries.getUnchecked (i)->entry.filename == fileName)
  7521. return i;
  7522. return -1;
  7523. }
  7524. const ZipFile::ZipEntry* ZipFile::getEntry (const String& fileName) const throw()
  7525. {
  7526. return getEntry (getIndexOfFileName (fileName));
  7527. }
  7528. InputStream* ZipFile::createStreamForEntry (const int index)
  7529. {
  7530. ZipEntryInfo* const zei = entries[index];
  7531. InputStream* stream = 0;
  7532. if (zei != 0)
  7533. {
  7534. stream = new ZipInputStream (*this, *zei);
  7535. if (zei->compressed)
  7536. {
  7537. stream = new GZIPDecompressorInputStream (stream, true, true,
  7538. zei->entry.uncompressedSize);
  7539. // (much faster to unzip in big blocks using a buffer..)
  7540. stream = new BufferedInputStream (stream, 32768, true);
  7541. }
  7542. }
  7543. return stream;
  7544. }
  7545. class ZipFile::ZipFilenameComparator
  7546. {
  7547. public:
  7548. int compareElements (const ZipFile::ZipEntryInfo* first, const ZipFile::ZipEntryInfo* second)
  7549. {
  7550. return first->entry.filename.compare (second->entry.filename);
  7551. }
  7552. };
  7553. void ZipFile::sortEntriesByFilename()
  7554. {
  7555. ZipFilenameComparator sorter;
  7556. entries.sort (sorter);
  7557. }
  7558. void ZipFile::init()
  7559. {
  7560. ScopedPointer <InputStream> toDelete;
  7561. InputStream* in = inputStream;
  7562. if (inputSource != 0)
  7563. {
  7564. in = inputSource->createInputStream();
  7565. toDelete = in;
  7566. }
  7567. if (in != 0)
  7568. {
  7569. int numEntries = 0;
  7570. int pos = findEndOfZipEntryTable (in, numEntries);
  7571. if (pos >= 0 && pos < in->getTotalLength())
  7572. {
  7573. const int size = (int) (in->getTotalLength() - pos);
  7574. in->setPosition (pos);
  7575. MemoryBlock headerData;
  7576. if (in->readIntoMemoryBlock (headerData, size) == size)
  7577. {
  7578. pos = 0;
  7579. for (int i = 0; i < numEntries; ++i)
  7580. {
  7581. if (pos + 46 > size)
  7582. break;
  7583. const char* const buffer = ((const char*) headerData.getData()) + pos;
  7584. const int fileNameLen = ByteOrder::littleEndianShort (buffer + 28);
  7585. if (pos + 46 + fileNameLen > size)
  7586. break;
  7587. ZipEntryInfo* const zei = new ZipEntryInfo();
  7588. zei->entry.filename = String::fromUTF8 ((const uint8*) buffer + 46, fileNameLen);
  7589. const int time = ByteOrder::littleEndianShort (buffer + 12);
  7590. const int date = ByteOrder::littleEndianShort (buffer + 14);
  7591. const int year = 1980 + (date >> 9);
  7592. const int month = ((date >> 5) & 15) - 1;
  7593. const int day = date & 31;
  7594. const int hours = time >> 11;
  7595. const int minutes = (time >> 5) & 63;
  7596. const int seconds = (time & 31) << 1;
  7597. zei->entry.fileTime = Time (year, month, day, hours, minutes, seconds);
  7598. zei->compressed = ByteOrder::littleEndianShort (buffer + 10) != 0;
  7599. zei->compressedSize = ByteOrder::littleEndianInt (buffer + 20);
  7600. zei->entry.uncompressedSize = ByteOrder::littleEndianInt (buffer + 24);
  7601. zei->streamOffset = ByteOrder::littleEndianInt (buffer + 42);
  7602. entries.add (zei);
  7603. pos += 46 + fileNameLen
  7604. + ByteOrder::littleEndianShort (buffer + 30)
  7605. + ByteOrder::littleEndianShort (buffer + 32);
  7606. }
  7607. }
  7608. }
  7609. }
  7610. }
  7611. int ZipFile::findEndOfZipEntryTable (InputStream* input, int& numEntries)
  7612. {
  7613. BufferedInputStream in (input, 8192, false);
  7614. in.setPosition (in.getTotalLength());
  7615. int64 pos = in.getPosition();
  7616. const int64 lowestPos = jmax ((int64) 0, pos - 1024);
  7617. char buffer [32];
  7618. zeromem (buffer, sizeof (buffer));
  7619. while (pos > lowestPos)
  7620. {
  7621. in.setPosition (pos - 22);
  7622. pos = in.getPosition();
  7623. memcpy (buffer + 22, buffer, 4);
  7624. if (in.read (buffer, 22) != 22)
  7625. return 0;
  7626. for (int i = 0; i < 22; ++i)
  7627. {
  7628. if (ByteOrder::littleEndianInt (buffer + i) == 0x06054b50)
  7629. {
  7630. in.setPosition (pos + i);
  7631. in.read (buffer, 22);
  7632. numEntries = ByteOrder::littleEndianShort (buffer + 10);
  7633. return ByteOrder::littleEndianInt (buffer + 16);
  7634. }
  7635. }
  7636. }
  7637. return 0;
  7638. }
  7639. void ZipFile::uncompressTo (const File& targetDirectory,
  7640. const bool shouldOverwriteFiles)
  7641. {
  7642. for (int i = 0; i < entries.size(); ++i)
  7643. {
  7644. const ZipEntry& zei = entries.getUnchecked(i)->entry;
  7645. const File targetFile (targetDirectory.getChildFile (zei.filename));
  7646. if (zei.filename.endsWithChar (T('/')))
  7647. {
  7648. targetFile.createDirectory(); // (entry is a directory, not a file)
  7649. }
  7650. else
  7651. {
  7652. ScopedPointer <InputStream> in (createStreamForEntry (i));
  7653. if (in != 0)
  7654. {
  7655. if (shouldOverwriteFiles)
  7656. targetFile.deleteFile();
  7657. if ((! targetFile.exists())
  7658. && targetFile.getParentDirectory().createDirectory())
  7659. {
  7660. ScopedPointer <FileOutputStream> out (targetFile.createOutputStream());
  7661. if (out != 0)
  7662. {
  7663. out->writeFromInputStream (*in, -1);
  7664. out = 0;
  7665. targetFile.setCreationTime (zei.fileTime);
  7666. targetFile.setLastModificationTime (zei.fileTime);
  7667. targetFile.setLastAccessTime (zei.fileTime);
  7668. }
  7669. }
  7670. }
  7671. }
  7672. }
  7673. }
  7674. END_JUCE_NAMESPACE
  7675. /*** End of inlined file: juce_ZipFile.cpp ***/
  7676. /*** Start of inlined file: juce_CharacterFunctions.cpp ***/
  7677. #ifdef _MSC_VER
  7678. #pragma warning (disable: 4514 4996)
  7679. #pragma warning (push)
  7680. #endif
  7681. #include <cwctype>
  7682. #include <cctype>
  7683. #include <ctime>
  7684. #ifdef _MSC_VER
  7685. #pragma warning (pop)
  7686. #endif
  7687. BEGIN_JUCE_NAMESPACE
  7688. int CharacterFunctions::length (const char* const s) throw()
  7689. {
  7690. return (int) strlen (s);
  7691. }
  7692. int CharacterFunctions::length (const juce_wchar* const s) throw()
  7693. {
  7694. return (int) wcslen (s);
  7695. }
  7696. void CharacterFunctions::copy (char* dest, const char* src, const int maxChars) throw()
  7697. {
  7698. strncpy (dest, src, maxChars);
  7699. }
  7700. void CharacterFunctions::copy (juce_wchar* dest, const juce_wchar* src, int maxChars) throw()
  7701. {
  7702. wcsncpy (dest, src, maxChars);
  7703. }
  7704. void CharacterFunctions::copy (juce_wchar* dest, const char* src, const int maxChars) throw()
  7705. {
  7706. mbstowcs (dest, src, maxChars);
  7707. }
  7708. void CharacterFunctions::copy (char* dest, const juce_wchar* src, const int maxChars) throw()
  7709. {
  7710. wcstombs (dest, src, maxChars);
  7711. }
  7712. int CharacterFunctions::bytesRequiredForCopy (const juce_wchar* src) throw()
  7713. {
  7714. return (int) wcstombs (0, src, 0);
  7715. }
  7716. void CharacterFunctions::append (char* dest, const char* src) throw()
  7717. {
  7718. strcat (dest, src);
  7719. }
  7720. void CharacterFunctions::append (juce_wchar* dest, const juce_wchar* src) throw()
  7721. {
  7722. wcscat (dest, src);
  7723. }
  7724. int CharacterFunctions::compare (const char* const s1, const char* const s2) throw()
  7725. {
  7726. return strcmp (s1, s2);
  7727. }
  7728. int CharacterFunctions::compare (const juce_wchar* s1, const juce_wchar* s2) throw()
  7729. {
  7730. jassert (s1 != 0 && s2 != 0);
  7731. return wcscmp (s1, s2);
  7732. }
  7733. int CharacterFunctions::compare (const char* const s1, const char* const s2, const int maxChars) throw()
  7734. {
  7735. jassert (s1 != 0 && s2 != 0);
  7736. return strncmp (s1, s2, maxChars);
  7737. }
  7738. int CharacterFunctions::compare (const juce_wchar* s1, const juce_wchar* s2, int maxChars) throw()
  7739. {
  7740. jassert (s1 != 0 && s2 != 0);
  7741. return wcsncmp (s1, s2, maxChars);
  7742. }
  7743. int CharacterFunctions::compareIgnoreCase (const char* const s1, const char* const s2) throw()
  7744. {
  7745. jassert (s1 != 0 && s2 != 0);
  7746. #if JUCE_WIN32
  7747. return stricmp (s1, s2);
  7748. #else
  7749. return strcasecmp (s1, s2);
  7750. #endif
  7751. }
  7752. int CharacterFunctions::compareIgnoreCase (const juce_wchar* s1, const juce_wchar* s2) throw()
  7753. {
  7754. jassert (s1 != 0 && s2 != 0);
  7755. #if JUCE_WIN32
  7756. return _wcsicmp (s1, s2);
  7757. #else
  7758. for (;;)
  7759. {
  7760. if (*s1 != *s2)
  7761. {
  7762. const int diff = toUpperCase (*s1) - toUpperCase (*s2);
  7763. if (diff != 0)
  7764. return diff < 0 ? -1 : 1;
  7765. }
  7766. else if (*s1 == 0)
  7767. break;
  7768. ++s1;
  7769. ++s2;
  7770. }
  7771. return 0;
  7772. #endif
  7773. }
  7774. int CharacterFunctions::compareIgnoreCase (const char* const s1, const char* const s2, const int maxChars) throw()
  7775. {
  7776. jassert (s1 != 0 && s2 != 0);
  7777. #if JUCE_WIN32
  7778. return strnicmp (s1, s2, maxChars);
  7779. #else
  7780. return strncasecmp (s1, s2, maxChars);
  7781. #endif
  7782. }
  7783. int CharacterFunctions::compareIgnoreCase (const juce_wchar* s1, const juce_wchar* s2, int maxChars) throw()
  7784. {
  7785. jassert (s1 != 0 && s2 != 0);
  7786. #if JUCE_WIN32
  7787. return _wcsnicmp (s1, s2, maxChars);
  7788. #else
  7789. while (--maxChars >= 0)
  7790. {
  7791. if (*s1 != *s2)
  7792. {
  7793. const int diff = toUpperCase (*s1) - toUpperCase (*s2);
  7794. if (diff != 0)
  7795. return diff < 0 ? -1 : 1;
  7796. }
  7797. else if (*s1 == 0)
  7798. break;
  7799. ++s1;
  7800. ++s2;
  7801. }
  7802. return 0;
  7803. #endif
  7804. }
  7805. const char* CharacterFunctions::find (const char* const haystack, const char* const needle) throw()
  7806. {
  7807. return strstr (haystack, needle);
  7808. }
  7809. const juce_wchar* CharacterFunctions::find (const juce_wchar* haystack, const juce_wchar* const needle) throw()
  7810. {
  7811. return wcsstr (haystack, needle);
  7812. }
  7813. int CharacterFunctions::indexOfChar (const char* const haystack, const char needle, const bool ignoreCase) throw()
  7814. {
  7815. if (haystack != 0)
  7816. {
  7817. int i = 0;
  7818. if (ignoreCase)
  7819. {
  7820. const char n1 = toLowerCase (needle);
  7821. const char n2 = toUpperCase (needle);
  7822. if (n1 != n2) // if the char is the same in upper/lower case, fall through to the normal search
  7823. {
  7824. while (haystack[i] != 0)
  7825. {
  7826. if (haystack[i] == n1 || haystack[i] == n2)
  7827. return i;
  7828. ++i;
  7829. }
  7830. return -1;
  7831. }
  7832. jassert (n1 == needle);
  7833. }
  7834. while (haystack[i] != 0)
  7835. {
  7836. if (haystack[i] == needle)
  7837. return i;
  7838. ++i;
  7839. }
  7840. }
  7841. return -1;
  7842. }
  7843. int CharacterFunctions::indexOfChar (const juce_wchar* const haystack, const juce_wchar needle, const bool ignoreCase) throw()
  7844. {
  7845. if (haystack != 0)
  7846. {
  7847. int i = 0;
  7848. if (ignoreCase)
  7849. {
  7850. const juce_wchar n1 = toLowerCase (needle);
  7851. const juce_wchar n2 = toUpperCase (needle);
  7852. if (n1 != n2) // if the char is the same in upper/lower case, fall through to the normal search
  7853. {
  7854. while (haystack[i] != 0)
  7855. {
  7856. if (haystack[i] == n1 || haystack[i] == n2)
  7857. return i;
  7858. ++i;
  7859. }
  7860. return -1;
  7861. }
  7862. jassert (n1 == needle);
  7863. }
  7864. while (haystack[i] != 0)
  7865. {
  7866. if (haystack[i] == needle)
  7867. return i;
  7868. ++i;
  7869. }
  7870. }
  7871. return -1;
  7872. }
  7873. int CharacterFunctions::indexOfCharFast (const char* const haystack, const char needle) throw()
  7874. {
  7875. jassert (haystack != 0);
  7876. int i = 0;
  7877. while (haystack[i] != 0)
  7878. {
  7879. if (haystack[i] == needle)
  7880. return i;
  7881. ++i;
  7882. }
  7883. return -1;
  7884. }
  7885. int CharacterFunctions::indexOfCharFast (const juce_wchar* const haystack, const juce_wchar needle) throw()
  7886. {
  7887. jassert (haystack != 0);
  7888. int i = 0;
  7889. while (haystack[i] != 0)
  7890. {
  7891. if (haystack[i] == needle)
  7892. return i;
  7893. ++i;
  7894. }
  7895. return -1;
  7896. }
  7897. int CharacterFunctions::getIntialSectionContainingOnly (const char* const text, const char* const allowedChars) throw()
  7898. {
  7899. return allowedChars == 0 ? 0 : (int) strspn (text, allowedChars);
  7900. }
  7901. int CharacterFunctions::getIntialSectionContainingOnly (const juce_wchar* const text, const juce_wchar* const allowedChars) throw()
  7902. {
  7903. if (allowedChars == 0)
  7904. return 0;
  7905. int i = 0;
  7906. for (;;)
  7907. {
  7908. if (indexOfCharFast (allowedChars, text[i]) < 0)
  7909. break;
  7910. ++i;
  7911. }
  7912. return i;
  7913. }
  7914. int CharacterFunctions::ftime (char* const dest, const int maxChars, const char* const format, const struct tm* const tm) throw()
  7915. {
  7916. return (int) strftime (dest, maxChars, format, tm);
  7917. }
  7918. int CharacterFunctions::ftime (juce_wchar* const dest, const int maxChars, const juce_wchar* const format, const struct tm* const tm) throw()
  7919. {
  7920. return (int) wcsftime (dest, maxChars, format, tm);
  7921. }
  7922. int CharacterFunctions::getIntValue (const char* const s) throw()
  7923. {
  7924. return atoi (s);
  7925. }
  7926. int CharacterFunctions::getIntValue (const juce_wchar* s) throw()
  7927. {
  7928. #if JUCE_WIN32
  7929. return _wtoi (s);
  7930. #else
  7931. int v = 0;
  7932. while (isWhitespace (*s))
  7933. ++s;
  7934. const bool isNeg = *s == T('-');
  7935. if (isNeg)
  7936. ++s;
  7937. for (;;)
  7938. {
  7939. const wchar_t c = *s++;
  7940. if (c >= T('0') && c <= T('9'))
  7941. v = v * 10 + (int) (c - T('0'));
  7942. else
  7943. break;
  7944. }
  7945. return isNeg ? -v : v;
  7946. #endif
  7947. }
  7948. int64 CharacterFunctions::getInt64Value (const char* s) throw()
  7949. {
  7950. #if JUCE_LINUX
  7951. return atoll (s);
  7952. #elif defined (JUCE_WIN32)
  7953. return _atoi64 (s);
  7954. #else
  7955. int64 v = 0;
  7956. while (isWhitespace (*s))
  7957. ++s;
  7958. const bool isNeg = *s == T('-');
  7959. if (isNeg)
  7960. ++s;
  7961. for (;;)
  7962. {
  7963. const char c = *s++;
  7964. if (c >= '0' && c <= '9')
  7965. v = v * 10 + (int64) (c - '0');
  7966. else
  7967. break;
  7968. }
  7969. return isNeg ? -v : v;
  7970. #endif
  7971. }
  7972. int64 CharacterFunctions::getInt64Value (const juce_wchar* s) throw()
  7973. {
  7974. #if JUCE_WIN32
  7975. return _wtoi64 (s);
  7976. #else
  7977. int64 v = 0;
  7978. while (isWhitespace (*s))
  7979. ++s;
  7980. const bool isNeg = *s == T('-');
  7981. if (isNeg)
  7982. ++s;
  7983. for (;;)
  7984. {
  7985. const juce_wchar c = *s++;
  7986. if (c >= T('0') && c <= T('9'))
  7987. v = v * 10 + (int64) (c - T('0'));
  7988. else
  7989. break;
  7990. }
  7991. return isNeg ? -v : v;
  7992. #endif
  7993. }
  7994. static double juce_mulexp10 (const double value, int exponent) throw()
  7995. {
  7996. if (exponent == 0)
  7997. return value;
  7998. if (value == 0)
  7999. return 0;
  8000. const bool negative = (exponent < 0);
  8001. if (negative)
  8002. exponent = -exponent;
  8003. double result = 1.0, power = 10.0;
  8004. for (int bit = 1; exponent != 0; bit <<= 1)
  8005. {
  8006. if ((exponent & bit) != 0)
  8007. {
  8008. exponent ^= bit;
  8009. result *= power;
  8010. if (exponent == 0)
  8011. break;
  8012. }
  8013. power *= power;
  8014. }
  8015. return negative ? (value / result) : (value * result);
  8016. }
  8017. template <class CharType>
  8018. double juce_atof (const CharType* const original) throw()
  8019. {
  8020. double result[3] = { 0, 0, 0 }, accumulator[2] = { 0, 0 };
  8021. int exponentAdjustment[2] = { 0, 0 }, exponentAccumulator[2] = { -1, -1 };
  8022. int exponent = 0, decPointIndex = 0, digit = 0;
  8023. int lastDigit = 0, numSignificantDigits = 0;
  8024. bool isNegative = false, digitsFound = false;
  8025. const int maxSignificantDigits = 15 + 2;
  8026. const CharType* s = original;
  8027. while (CharacterFunctions::isWhitespace (*s))
  8028. ++s;
  8029. switch (*s)
  8030. {
  8031. case '-': isNegative = true; // fall-through..
  8032. case '+': ++s;
  8033. }
  8034. if (*s == 'n' || *s == 'N' || *s == 'i' || *s == 'I')
  8035. return atof (String (original)); // Let the c library deal with NAN and INF
  8036. for (;;)
  8037. {
  8038. if (CharacterFunctions::isDigit (*s))
  8039. {
  8040. lastDigit = digit;
  8041. digit = *s++ - '0';
  8042. digitsFound = true;
  8043. if (decPointIndex != 0)
  8044. exponentAdjustment[1]++;
  8045. if (numSignificantDigits == 0 && digit == 0)
  8046. continue;
  8047. if (++numSignificantDigits > maxSignificantDigits)
  8048. {
  8049. if (digit > 5)
  8050. ++accumulator [decPointIndex];
  8051. else if (digit == 5 && (lastDigit & 1) != 0)
  8052. ++accumulator [decPointIndex];
  8053. if (decPointIndex > 0)
  8054. exponentAdjustment[1]--;
  8055. else
  8056. exponentAdjustment[0]++;
  8057. while (CharacterFunctions::isDigit (*s))
  8058. {
  8059. ++s;
  8060. if (decPointIndex == 0)
  8061. exponentAdjustment[0]++;
  8062. }
  8063. }
  8064. else
  8065. {
  8066. const double maxAccumulatorValue = (double) ((std::numeric_limits<unsigned int>::max() - 9) / 10);
  8067. if (accumulator [decPointIndex] > maxAccumulatorValue)
  8068. {
  8069. result [decPointIndex] = juce_mulexp10 (result [decPointIndex], exponentAccumulator [decPointIndex])
  8070. + accumulator [decPointIndex];
  8071. accumulator [decPointIndex] = 0;
  8072. exponentAccumulator [decPointIndex] = 0;
  8073. }
  8074. accumulator [decPointIndex] = accumulator[decPointIndex] * 10 + digit;
  8075. exponentAccumulator [decPointIndex]++;
  8076. }
  8077. }
  8078. else if (decPointIndex == 0 && *s == '.')
  8079. {
  8080. ++s;
  8081. decPointIndex = 1;
  8082. if (numSignificantDigits > maxSignificantDigits)
  8083. {
  8084. while (CharacterFunctions::isDigit (*s))
  8085. ++s;
  8086. break;
  8087. }
  8088. }
  8089. else
  8090. {
  8091. break;
  8092. }
  8093. }
  8094. result[0] = juce_mulexp10 (result[0], exponentAccumulator[0]) + accumulator[0];
  8095. if (decPointIndex != 0)
  8096. result[1] = juce_mulexp10 (result[1], exponentAccumulator[1]) + accumulator[1];
  8097. if ((*s == 'e' || *s == 'E') && digitsFound)
  8098. {
  8099. bool negativeExponent = false;
  8100. switch (*++s)
  8101. {
  8102. case '-': negativeExponent = true; // fall-through..
  8103. case '+': ++s;
  8104. }
  8105. while (CharacterFunctions::isDigit (*s))
  8106. exponent = (exponent * 10) + (*s++ - '0');
  8107. if (negativeExponent)
  8108. exponent = -exponent;
  8109. }
  8110. double r = juce_mulexp10 (result[0], exponent + exponentAdjustment[0]);
  8111. if (decPointIndex != 0)
  8112. r += juce_mulexp10 (result[1], exponent - exponentAdjustment[1]);
  8113. return isNegative ? -r : r;
  8114. }
  8115. double CharacterFunctions::getDoubleValue (const char* const s) throw()
  8116. {
  8117. return juce_atof <char> (s);
  8118. }
  8119. double CharacterFunctions::getDoubleValue (const juce_wchar* const s) throw()
  8120. {
  8121. return juce_atof <juce_wchar> (s);
  8122. }
  8123. char CharacterFunctions::toUpperCase (const char character) throw()
  8124. {
  8125. return (char) toupper (character);
  8126. }
  8127. juce_wchar CharacterFunctions::toUpperCase (const juce_wchar character) throw()
  8128. {
  8129. return towupper (character);
  8130. }
  8131. void CharacterFunctions::toUpperCase (char* s) throw()
  8132. {
  8133. #if JUCE_WIN32
  8134. strupr (s);
  8135. #else
  8136. while (*s != 0)
  8137. {
  8138. *s = toUpperCase (*s);
  8139. ++s;
  8140. }
  8141. #endif
  8142. }
  8143. void CharacterFunctions::toUpperCase (juce_wchar* s) throw()
  8144. {
  8145. #if JUCE_WIN32
  8146. _wcsupr (s);
  8147. #else
  8148. while (*s != 0)
  8149. {
  8150. *s = toUpperCase (*s);
  8151. ++s;
  8152. }
  8153. #endif
  8154. }
  8155. bool CharacterFunctions::isUpperCase (const char character) throw()
  8156. {
  8157. return isupper (character) != 0;
  8158. }
  8159. bool CharacterFunctions::isUpperCase (const juce_wchar character) throw()
  8160. {
  8161. #if JUCE_WIN32
  8162. return iswupper (character) != 0;
  8163. #else
  8164. return toLowerCase (character) != character;
  8165. #endif
  8166. }
  8167. char CharacterFunctions::toLowerCase (const char character) throw()
  8168. {
  8169. return (char) tolower (character);
  8170. }
  8171. juce_wchar CharacterFunctions::toLowerCase (const juce_wchar character) throw()
  8172. {
  8173. return towlower (character);
  8174. }
  8175. void CharacterFunctions::toLowerCase (char* s) throw()
  8176. {
  8177. #if JUCE_WIN32
  8178. strlwr (s);
  8179. #else
  8180. while (*s != 0)
  8181. {
  8182. *s = toLowerCase (*s);
  8183. ++s;
  8184. }
  8185. #endif
  8186. }
  8187. void CharacterFunctions::toLowerCase (juce_wchar* s) throw()
  8188. {
  8189. #if JUCE_WIN32
  8190. _wcslwr (s);
  8191. #else
  8192. while (*s != 0)
  8193. {
  8194. *s = toLowerCase (*s);
  8195. ++s;
  8196. }
  8197. #endif
  8198. }
  8199. bool CharacterFunctions::isLowerCase (const char character) throw()
  8200. {
  8201. return islower (character) != 0;
  8202. }
  8203. bool CharacterFunctions::isLowerCase (const juce_wchar character) throw()
  8204. {
  8205. #if JUCE_WIN32
  8206. return iswlower (character) != 0;
  8207. #else
  8208. return toUpperCase (character) != character;
  8209. #endif
  8210. }
  8211. bool CharacterFunctions::isWhitespace (const char character) throw()
  8212. {
  8213. return character == T(' ') || (character <= 13 && character >= 9);
  8214. }
  8215. bool CharacterFunctions::isWhitespace (const juce_wchar character) throw()
  8216. {
  8217. return iswspace (character) != 0;
  8218. }
  8219. bool CharacterFunctions::isDigit (const char character) throw()
  8220. {
  8221. return (character >= '0' && character <= '9');
  8222. }
  8223. bool CharacterFunctions::isDigit (const juce_wchar character) throw()
  8224. {
  8225. return iswdigit (character) != 0;
  8226. }
  8227. bool CharacterFunctions::isLetter (const char character) throw()
  8228. {
  8229. return (character >= 'a' && character <= 'z')
  8230. || (character >= 'A' && character <= 'Z');
  8231. }
  8232. bool CharacterFunctions::isLetter (const juce_wchar character) throw()
  8233. {
  8234. return iswalpha (character) != 0;
  8235. }
  8236. bool CharacterFunctions::isLetterOrDigit (const char character) throw()
  8237. {
  8238. return (character >= 'a' && character <= 'z')
  8239. || (character >= 'A' && character <= 'Z')
  8240. || (character >= '0' && character <= '9');
  8241. }
  8242. bool CharacterFunctions::isLetterOrDigit (const juce_wchar character) throw()
  8243. {
  8244. return iswalnum (character) != 0;
  8245. }
  8246. int CharacterFunctions::getHexDigitValue (const tchar digit) throw()
  8247. {
  8248. if (digit >= T('0') && digit <= T('9'))
  8249. return digit - T('0');
  8250. else if (digit >= T('a') && digit <= T('f'))
  8251. return digit - (T('a') - 10);
  8252. else if (digit >= T('A') && digit <= T('F'))
  8253. return digit - (T('A') - 10);
  8254. return -1;
  8255. }
  8256. int CharacterFunctions::printf (char* const dest, const int maxLength, const char* const format, ...) throw()
  8257. {
  8258. va_list list;
  8259. va_start (list, format);
  8260. return vprintf (dest, maxLength, format, list);
  8261. }
  8262. int CharacterFunctions::printf (juce_wchar* const dest, const int maxLength, const juce_wchar* const format, ...) throw()
  8263. {
  8264. va_list list;
  8265. va_start (list, format);
  8266. return vprintf (dest, maxLength, format, list);
  8267. }
  8268. int CharacterFunctions::vprintf (char* const dest, const int maxLength, const char* const format, va_list& args) throw()
  8269. {
  8270. #if JUCE_WIN32
  8271. return (int) _vsnprintf (dest, maxLength, format, args);
  8272. #else
  8273. return (int) vsnprintf (dest, maxLength, format, args);
  8274. #endif
  8275. }
  8276. int CharacterFunctions::vprintf (juce_wchar* const dest, const int maxLength, const juce_wchar* const format, va_list& args) throw()
  8277. {
  8278. #if defined (JUCE_WIN32)
  8279. return (int) _vsnwprintf (dest, maxLength, format, args);
  8280. #else
  8281. return (int) vswprintf (dest, maxLength, format, args);
  8282. #endif
  8283. }
  8284. END_JUCE_NAMESPACE
  8285. /*** End of inlined file: juce_CharacterFunctions.cpp ***/
  8286. /*** Start of inlined file: juce_LocalisedStrings.cpp ***/
  8287. BEGIN_JUCE_NAMESPACE
  8288. LocalisedStrings::LocalisedStrings (const String& fileContents)
  8289. {
  8290. loadFromText (fileContents);
  8291. }
  8292. LocalisedStrings::LocalisedStrings (const File& fileToLoad)
  8293. {
  8294. loadFromText (fileToLoad.loadFileAsString());
  8295. }
  8296. LocalisedStrings::~LocalisedStrings()
  8297. {
  8298. }
  8299. const String LocalisedStrings::translate (const String& text) const
  8300. {
  8301. return translations.getValue (text, text);
  8302. }
  8303. static int findCloseQuote (const String& text, int startPos)
  8304. {
  8305. tchar lastChar = 0;
  8306. for (;;)
  8307. {
  8308. const tchar c = text [startPos];
  8309. if (c == 0 || (c == T('"') && lastChar != T('\\')))
  8310. break;
  8311. lastChar = c;
  8312. ++startPos;
  8313. }
  8314. return startPos;
  8315. }
  8316. static const String unescapeString (const String& s)
  8317. {
  8318. return s.replace (T("\\\""), T("\""))
  8319. .replace (T("\\\'"), T("\'"))
  8320. .replace (T("\\t"), T("\t"))
  8321. .replace (T("\\r"), T("\r"))
  8322. .replace (T("\\n"), T("\n"));
  8323. }
  8324. void LocalisedStrings::loadFromText (const String& fileContents)
  8325. {
  8326. StringArray lines;
  8327. lines.addLines (fileContents);
  8328. for (int i = 0; i < lines.size(); ++i)
  8329. {
  8330. String line (lines[i].trim());
  8331. if (line.startsWithChar (T('"')))
  8332. {
  8333. int closeQuote = findCloseQuote (line, 1);
  8334. const String originalText (unescapeString (line.substring (1, closeQuote)));
  8335. if (originalText.isNotEmpty())
  8336. {
  8337. const int openingQuote = findCloseQuote (line, closeQuote + 1);
  8338. closeQuote = findCloseQuote (line, openingQuote + 1);
  8339. const String newText (unescapeString (line.substring (openingQuote + 1, closeQuote)));
  8340. if (newText.isNotEmpty())
  8341. translations.set (originalText, newText);
  8342. }
  8343. }
  8344. else if (line.startsWithIgnoreCase (T("language:")))
  8345. {
  8346. languageName = line.substring (9).trim();
  8347. }
  8348. else if (line.startsWithIgnoreCase (T("countries:")))
  8349. {
  8350. countryCodes.addTokens (line.substring (10).trim(), true);
  8351. countryCodes.trim();
  8352. countryCodes.removeEmptyStrings();
  8353. }
  8354. }
  8355. }
  8356. void LocalisedStrings::setIgnoresCase (const bool shouldIgnoreCase)
  8357. {
  8358. translations.setIgnoresCase (shouldIgnoreCase);
  8359. }
  8360. static CriticalSection currentMappingsLock;
  8361. static LocalisedStrings* currentMappings = 0;
  8362. void LocalisedStrings::setCurrentMappings (LocalisedStrings* newTranslations)
  8363. {
  8364. const ScopedLock sl (currentMappingsLock);
  8365. delete currentMappings;
  8366. currentMappings = newTranslations;
  8367. }
  8368. LocalisedStrings* LocalisedStrings::getCurrentMappings()
  8369. {
  8370. return currentMappings;
  8371. }
  8372. const String LocalisedStrings::translateWithCurrentMappings (const String& text)
  8373. {
  8374. const ScopedLock sl (currentMappingsLock);
  8375. if (currentMappings != 0)
  8376. return currentMappings->translate (text);
  8377. return text;
  8378. }
  8379. const String LocalisedStrings::translateWithCurrentMappings (const char* text)
  8380. {
  8381. return translateWithCurrentMappings (String (text));
  8382. }
  8383. END_JUCE_NAMESPACE
  8384. /*** End of inlined file: juce_LocalisedStrings.cpp ***/
  8385. /*** Start of inlined file: juce_String.cpp ***/
  8386. #ifdef _MSC_VER
  8387. #pragma warning (disable: 4514)
  8388. #pragma warning (push)
  8389. #endif
  8390. #include <locale>
  8391. #if JUCE_MSVC
  8392. #include <float.h>
  8393. #endif
  8394. BEGIN_JUCE_NAMESPACE
  8395. #ifdef _MSC_VER
  8396. #pragma warning (pop)
  8397. #endif
  8398. static const char* const emptyCharString = "\0\0\0\0JUCE";
  8399. static const int safeEmptyStringRefCount = 0x3fffffff;
  8400. String::InternalRefCountedStringHolder String::emptyString = { safeEmptyStringRefCount, 0, { 0 } };
  8401. static tchar decimalPoint = T('.');
  8402. void juce_initialiseStrings()
  8403. {
  8404. decimalPoint = String::fromUTF8 ((const uint8*) localeconv()->decimal_point) [0];
  8405. }
  8406. void String::createInternal (const int numChars) throw()
  8407. {
  8408. jassert (numChars > 0);
  8409. text = (InternalRefCountedStringHolder*) juce_malloc (sizeof (InternalRefCountedStringHolder)
  8410. + numChars * sizeof (tchar));
  8411. text->refCount = 1;
  8412. text->allocatedNumChars = numChars;
  8413. text->text[0] = 0;
  8414. }
  8415. void String::createInternal (const tchar* const t, const tchar* const textEnd) throw()
  8416. {
  8417. jassert (*(textEnd - 1) == 0); // must have a null terminator
  8418. const int numChars = (int) (textEnd - t);
  8419. createInternal (numChars - 1);
  8420. memcpy (text->text, t, numChars * sizeof (tchar));
  8421. }
  8422. void String::appendInternal (const tchar* const newText,
  8423. const int numExtraChars) throw()
  8424. {
  8425. if (numExtraChars > 0)
  8426. {
  8427. const int oldLen = CharacterFunctions::length (text->text);
  8428. const int newTotalLen = oldLen + numExtraChars;
  8429. if (text->refCount > 1)
  8430. {
  8431. // it's in use by other strings as well, so we need to make a private copy before messing with it..
  8432. InternalRefCountedStringHolder* const newTextHolder
  8433. = (InternalRefCountedStringHolder*) juce_malloc (sizeof (InternalRefCountedStringHolder)
  8434. + newTotalLen * sizeof (tchar));
  8435. newTextHolder->refCount = 1;
  8436. newTextHolder->allocatedNumChars = newTotalLen;
  8437. memcpy (newTextHolder->text, text->text, oldLen * sizeof (tchar));
  8438. memcpy (newTextHolder->text + oldLen, newText, numExtraChars * sizeof (tchar));
  8439. InternalRefCountedStringHolder* const old = text;
  8440. text = newTextHolder;
  8441. if (Atomic::decrementAndReturn (old->refCount) == 0)
  8442. juce_free (old);
  8443. }
  8444. else
  8445. {
  8446. // no other strings using it, so just expand it if needed..
  8447. if (newTotalLen > text->allocatedNumChars)
  8448. {
  8449. text = (InternalRefCountedStringHolder*)
  8450. juce_realloc (text, sizeof (InternalRefCountedStringHolder)
  8451. + newTotalLen * sizeof (tchar));
  8452. text->allocatedNumChars = newTotalLen;
  8453. }
  8454. memcpy (text->text + oldLen, newText, numExtraChars * sizeof (tchar));
  8455. }
  8456. text->text [newTotalLen] = 0;
  8457. }
  8458. }
  8459. void String::dupeInternalIfMultiplyReferenced() throw()
  8460. {
  8461. if (text->refCount > 1)
  8462. {
  8463. InternalRefCountedStringHolder* const old = text;
  8464. const int len = old->allocatedNumChars;
  8465. InternalRefCountedStringHolder* const newTextHolder
  8466. = (InternalRefCountedStringHolder*) juce_malloc (sizeof (InternalRefCountedStringHolder)
  8467. + len * sizeof (tchar));
  8468. newTextHolder->refCount = 1;
  8469. newTextHolder->allocatedNumChars = len;
  8470. memcpy (newTextHolder->text, old->text, (len + 1) * sizeof (tchar));
  8471. text = newTextHolder;
  8472. if (Atomic::decrementAndReturn (old->refCount) == 0)
  8473. juce_free (old);
  8474. }
  8475. }
  8476. const String String::empty;
  8477. String::String() throw()
  8478. : text (&emptyString)
  8479. {
  8480. }
  8481. String::String (const String& other) throw()
  8482. : text (other.text)
  8483. {
  8484. Atomic::increment (text->refCount);
  8485. }
  8486. String::String (const int numChars,
  8487. const int /*dummyVariable*/) throw()
  8488. {
  8489. createInternal (numChars);
  8490. }
  8491. String::String (const char* const t) throw()
  8492. {
  8493. if (t != 0 && *t != 0)
  8494. {
  8495. const int len = CharacterFunctions::length (t);
  8496. createInternal (len);
  8497. #if JUCE_STRINGS_ARE_UNICODE
  8498. CharacterFunctions::copy (text->text, t, len + 1);
  8499. #else
  8500. memcpy (text->text, t, len + 1);
  8501. #endif
  8502. }
  8503. else
  8504. {
  8505. text = &emptyString;
  8506. emptyString.refCount = safeEmptyStringRefCount;
  8507. }
  8508. }
  8509. String::String (const juce_wchar* const t) throw()
  8510. {
  8511. if (t != 0 && *t != 0)
  8512. {
  8513. #if JUCE_STRINGS_ARE_UNICODE
  8514. const int len = CharacterFunctions::length (t);
  8515. createInternal (len);
  8516. memcpy (text->text, t, (len + 1) * sizeof (tchar));
  8517. #else
  8518. const int len = CharacterFunctions::bytesRequiredForCopy (t);
  8519. createInternal (len);
  8520. CharacterFunctions::copy (text->text, t, len + 1);
  8521. #endif
  8522. }
  8523. else
  8524. {
  8525. text = &emptyString;
  8526. emptyString.refCount = safeEmptyStringRefCount;
  8527. }
  8528. }
  8529. String::String (const char* const t,
  8530. const size_t maxChars) throw()
  8531. {
  8532. int i;
  8533. for (i = 0; (size_t) i < maxChars; ++i)
  8534. if (t[i] == 0)
  8535. break;
  8536. if (i > 0)
  8537. {
  8538. createInternal (i);
  8539. #if JUCE_STRINGS_ARE_UNICODE
  8540. CharacterFunctions::copy (text->text, t, i);
  8541. #else
  8542. memcpy (text->text, t, i);
  8543. #endif
  8544. text->text [i] = 0;
  8545. }
  8546. else
  8547. {
  8548. text = &emptyString;
  8549. emptyString.refCount = safeEmptyStringRefCount;
  8550. }
  8551. }
  8552. String::String (const juce_wchar* const t,
  8553. const size_t maxChars) throw()
  8554. {
  8555. int i;
  8556. for (i = 0; (size_t) i < maxChars; ++i)
  8557. if (t[i] == 0)
  8558. break;
  8559. if (i > 0)
  8560. {
  8561. createInternal (i);
  8562. #if JUCE_STRINGS_ARE_UNICODE
  8563. memcpy (text->text, t, i * sizeof (tchar));
  8564. #else
  8565. CharacterFunctions::copy (text->text, t, i);
  8566. #endif
  8567. text->text [i] = 0;
  8568. }
  8569. else
  8570. {
  8571. text = &emptyString;
  8572. emptyString.refCount = safeEmptyStringRefCount;
  8573. }
  8574. }
  8575. const String String::charToString (const tchar character) throw()
  8576. {
  8577. tchar temp[2];
  8578. temp[0] = character;
  8579. temp[1] = 0;
  8580. return String (temp);
  8581. }
  8582. // pass in a pointer to the END of a buffer..
  8583. static tchar* int64ToCharString (tchar* t, const int64 n) throw()
  8584. {
  8585. *--t = 0;
  8586. int64 v = (n >= 0) ? n : -n;
  8587. do
  8588. {
  8589. *--t = (tchar) (T('0') + (int) (v % 10));
  8590. v /= 10;
  8591. } while (v > 0);
  8592. if (n < 0)
  8593. *--t = T('-');
  8594. return t;
  8595. }
  8596. static tchar* intToCharString (tchar* t, const int n) throw()
  8597. {
  8598. if (n == (int) 0x80000000) // (would cause an overflow)
  8599. return int64ToCharString (t, n);
  8600. *--t = 0;
  8601. int v = abs (n);
  8602. do
  8603. {
  8604. *--t = (tchar) (T('0') + (v % 10));
  8605. v /= 10;
  8606. } while (v > 0);
  8607. if (n < 0)
  8608. *--t = T('-');
  8609. return t;
  8610. }
  8611. static tchar* uintToCharString (tchar* t, unsigned int v) throw()
  8612. {
  8613. *--t = 0;
  8614. do
  8615. {
  8616. *--t = (tchar) (T('0') + (v % 10));
  8617. v /= 10;
  8618. } while (v > 0);
  8619. return t;
  8620. }
  8621. String::String (const int number) throw()
  8622. {
  8623. tchar buffer [16];
  8624. tchar* const end = buffer + 16;
  8625. createInternal (intToCharString (end, number), end);
  8626. }
  8627. String::String (const unsigned int number) throw()
  8628. {
  8629. tchar buffer [16];
  8630. tchar* const end = buffer + 16;
  8631. createInternal (uintToCharString (end, number), end);
  8632. }
  8633. String::String (const short number) throw()
  8634. {
  8635. tchar buffer [16];
  8636. tchar* const end = buffer + 16;
  8637. createInternal (intToCharString (end, (int) number), end);
  8638. }
  8639. String::String (const unsigned short number) throw()
  8640. {
  8641. tchar buffer [16];
  8642. tchar* const end = buffer + 16;
  8643. createInternal (uintToCharString (end, (unsigned int) number), end);
  8644. }
  8645. String::String (const int64 number) throw()
  8646. {
  8647. tchar buffer [32];
  8648. tchar* const end = buffer + 32;
  8649. createInternal (int64ToCharString (end, number), end);
  8650. }
  8651. String::String (const uint64 number) throw()
  8652. {
  8653. tchar buffer [32];
  8654. tchar* const end = buffer + 32;
  8655. tchar* t = end;
  8656. *--t = 0;
  8657. int64 v = number;
  8658. do
  8659. {
  8660. *--t = (tchar) (T('0') + (int) (v % 10));
  8661. v /= 10;
  8662. } while (v > 0);
  8663. createInternal (t, end);
  8664. }
  8665. // a double-to-string routine that actually uses the number of dec. places you asked for
  8666. // without resorting to exponent notation if the number's too big or small (which is what printf does).
  8667. void String::doubleToStringWithDecPlaces (double n, int numDecPlaces) throw()
  8668. {
  8669. const int bufSize = 80;
  8670. tchar buffer [bufSize];
  8671. int len;
  8672. tchar* t;
  8673. if (numDecPlaces > 0 && n > -1.0e20 && n < 1.0e20)
  8674. {
  8675. int64 v = (int64) (pow (10.0, numDecPlaces) * fabs (n) + 0.5);
  8676. t = buffer + bufSize;
  8677. *--t = (tchar) 0;
  8678. while (numDecPlaces >= 0 || v > 0)
  8679. {
  8680. if (numDecPlaces == 0)
  8681. *--t = decimalPoint;
  8682. *--t = (tchar) (T('0') + (v % 10));
  8683. v /= 10;
  8684. --numDecPlaces;
  8685. }
  8686. if (n < 0)
  8687. *--t = T('-');
  8688. len = (int) ((buffer + bufSize) - t);
  8689. }
  8690. else
  8691. {
  8692. len = CharacterFunctions::printf (buffer, bufSize, T("%.9g"), n) + 1;
  8693. t = buffer;
  8694. }
  8695. if (len > 1)
  8696. {
  8697. jassert (len < numElementsInArray (buffer));
  8698. createInternal (len - 1);
  8699. memcpy (text->text, t, len * sizeof (tchar));
  8700. }
  8701. else
  8702. {
  8703. jassert (*t == 0);
  8704. text = &emptyString;
  8705. emptyString.refCount = safeEmptyStringRefCount;
  8706. }
  8707. }
  8708. String::String (const float number,
  8709. const int numberOfDecimalPlaces) throw()
  8710. {
  8711. doubleToStringWithDecPlaces ((double) number,
  8712. numberOfDecimalPlaces);
  8713. }
  8714. String::String (const double number,
  8715. const int numberOfDecimalPlaces) throw()
  8716. {
  8717. doubleToStringWithDecPlaces (number,
  8718. numberOfDecimalPlaces);
  8719. }
  8720. String::~String() throw()
  8721. {
  8722. emptyString.refCount = safeEmptyStringRefCount;
  8723. if (Atomic::decrementAndReturn (text->refCount) == 0)
  8724. juce_free (text);
  8725. }
  8726. void String::preallocateStorage (const size_t numChars) throw()
  8727. {
  8728. if (numChars > (size_t) text->allocatedNumChars)
  8729. {
  8730. dupeInternalIfMultiplyReferenced();
  8731. text = (InternalRefCountedStringHolder*) juce_realloc (text, sizeof (InternalRefCountedStringHolder)
  8732. + numChars * sizeof (tchar));
  8733. text->allocatedNumChars = (int) numChars;
  8734. }
  8735. }
  8736. #if JUCE_STRINGS_ARE_UNICODE
  8737. String::operator const char*() const throw()
  8738. {
  8739. if (isEmpty())
  8740. {
  8741. return (const char*) emptyCharString;
  8742. }
  8743. else
  8744. {
  8745. String* const mutableThis = const_cast <String*> (this);
  8746. mutableThis->dupeInternalIfMultiplyReferenced();
  8747. int len = CharacterFunctions::bytesRequiredForCopy (text->text) + 1;
  8748. mutableThis->text = (InternalRefCountedStringHolder*)
  8749. juce_realloc (text, sizeof (InternalRefCountedStringHolder)
  8750. + (len * sizeof (juce_wchar) + len));
  8751. char* otherCopy = (char*) (text->text + len);
  8752. --len;
  8753. CharacterFunctions::copy (otherCopy, text->text, len);
  8754. otherCopy [len] = 0;
  8755. return otherCopy;
  8756. }
  8757. }
  8758. #else
  8759. String::operator const juce_wchar*() const throw()
  8760. {
  8761. if (isEmpty())
  8762. {
  8763. return (const juce_wchar*) emptyCharString;
  8764. }
  8765. else
  8766. {
  8767. String* const mutableThis = const_cast <String*> (this);
  8768. mutableThis->dupeInternalIfMultiplyReferenced();
  8769. int len = CharacterFunctions::length (text->text) + 1;
  8770. mutableThis->text = (InternalRefCountedStringHolder*)
  8771. juce_realloc (text, sizeof (InternalRefCountedStringHolder)
  8772. + (len * sizeof (juce_wchar) + len));
  8773. juce_wchar* otherCopy = (juce_wchar*) (text->text + len);
  8774. --len;
  8775. CharacterFunctions::copy (otherCopy, text->text, len);
  8776. otherCopy [len] = 0;
  8777. return otherCopy;
  8778. }
  8779. }
  8780. #endif
  8781. void String::copyToBuffer (char* const destBuffer,
  8782. const int bufferSizeBytes) const throw()
  8783. {
  8784. #if JUCE_STRINGS_ARE_UNICODE
  8785. const int len = jmin (bufferSizeBytes, CharacterFunctions::bytesRequiredForCopy (text->text));
  8786. CharacterFunctions::copy (destBuffer, text->text, len);
  8787. #else
  8788. const int len = jmin (bufferSizeBytes, length());
  8789. memcpy (destBuffer, text->text, len * sizeof (tchar));
  8790. #endif
  8791. destBuffer [len] = 0;
  8792. }
  8793. void String::copyToBuffer (juce_wchar* const destBuffer,
  8794. const int maxCharsToCopy) const throw()
  8795. {
  8796. const int len = jmin (maxCharsToCopy, length());
  8797. #if JUCE_STRINGS_ARE_UNICODE
  8798. memcpy (destBuffer, text->text, len * sizeof (juce_wchar));
  8799. #else
  8800. CharacterFunctions::copy (destBuffer, text->text, len);
  8801. #endif
  8802. destBuffer [len] = 0;
  8803. }
  8804. int String::length() const throw()
  8805. {
  8806. return CharacterFunctions::length (text->text);
  8807. }
  8808. int String::hashCode() const throw()
  8809. {
  8810. const tchar* t = text->text;
  8811. int result = 0;
  8812. while (*t != (tchar) 0)
  8813. result = 31 * result + *t++;
  8814. return result;
  8815. }
  8816. int64 String::hashCode64() const throw()
  8817. {
  8818. const tchar* t = text->text;
  8819. int64 result = 0;
  8820. while (*t != (tchar) 0)
  8821. result = 101 * result + *t++;
  8822. return result;
  8823. }
  8824. const String& String::operator= (const tchar* const otherText) throw()
  8825. {
  8826. operator= (String (otherText));
  8827. return *this;
  8828. }
  8829. const String& String::operator= (const String& other) throw()
  8830. {
  8831. if (this != &other)
  8832. {
  8833. InternalRefCountedStringHolder* newText = other.text;
  8834. Atomic::increment (newText->refCount);
  8835. InternalRefCountedStringHolder* oldText
  8836. = (InternalRefCountedStringHolder*) Atomic::swapPointers ((void* volatile*) &text, newText);
  8837. if (Atomic::decrementAndReturn (oldText->refCount) == 0)
  8838. juce_free (oldText);
  8839. }
  8840. return *this;
  8841. }
  8842. bool String::operator== (const String& other) const throw()
  8843. {
  8844. return text == other.text
  8845. || CharacterFunctions::compare (text->text, other.text->text) == 0;
  8846. }
  8847. bool String::operator== (const tchar* const t) const throw()
  8848. {
  8849. return t != 0 ? CharacterFunctions::compare (text->text, t) == 0
  8850. : isEmpty();
  8851. }
  8852. bool String::equalsIgnoreCase (const tchar* t) const throw()
  8853. {
  8854. return t != 0 ? CharacterFunctions::compareIgnoreCase (text->text, t) == 0
  8855. : isEmpty();
  8856. }
  8857. bool String::equalsIgnoreCase (const String& other) const throw()
  8858. {
  8859. return text == other.text
  8860. || CharacterFunctions::compareIgnoreCase (text->text, other.text->text) == 0;
  8861. }
  8862. bool String::operator!= (const String& other) const throw()
  8863. {
  8864. return text != other.text
  8865. && CharacterFunctions::compare (text->text, other.text->text) != 0;
  8866. }
  8867. bool String::operator!= (const tchar* const t) const throw()
  8868. {
  8869. return t != 0 ? (CharacterFunctions::compare (text->text, t) != 0)
  8870. : isNotEmpty();
  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. bool String::operator>= (const String& other) const throw()
  8881. {
  8882. return compare (other) >= 0;
  8883. }
  8884. bool String::operator<= (const tchar* const other) const throw()
  8885. {
  8886. return compare (other) <= 0;
  8887. }
  8888. int String::compare (const tchar* const other) const throw()
  8889. {
  8890. return other != 0 ? CharacterFunctions::compare (text->text, other)
  8891. : isEmpty();
  8892. }
  8893. int String::compareIgnoreCase (const tchar* const other) const throw()
  8894. {
  8895. return other != 0 ? CharacterFunctions::compareIgnoreCase (text->text, other)
  8896. : isEmpty();
  8897. }
  8898. int String::compareLexicographically (const tchar* other) const throw()
  8899. {
  8900. if (other == 0)
  8901. return isEmpty();
  8902. const tchar* s1 = text->text;
  8903. while (*s1 != 0 && ! CharacterFunctions::isLetterOrDigit (*s1))
  8904. ++s1;
  8905. while (*other != 0 && ! CharacterFunctions::isLetterOrDigit (*other))
  8906. ++other;
  8907. return CharacterFunctions::compareIgnoreCase (s1, other);
  8908. }
  8909. const String String::operator+ (const String& other) const throw()
  8910. {
  8911. if (*(other.text->text) == 0)
  8912. return *this;
  8913. if (isEmpty())
  8914. return other;
  8915. const int len = CharacterFunctions::length (text->text);
  8916. const int otherLen = CharacterFunctions::length (other.text->text);
  8917. String result (len + otherLen, (int) 0);
  8918. memcpy (result.text->text, text->text, len * sizeof (tchar));
  8919. memcpy (result.text->text + len, other.text->text, otherLen * sizeof (tchar));
  8920. result.text->text [len + otherLen] = 0;
  8921. return result;
  8922. }
  8923. const String String::operator+ (const tchar* const textToAppend) const throw()
  8924. {
  8925. if (textToAppend == 0 || *textToAppend == 0)
  8926. return *this;
  8927. const int len = CharacterFunctions::length (text->text);
  8928. const int otherLen = CharacterFunctions::length (textToAppend);
  8929. String result (len + otherLen, (int) 0);
  8930. memcpy (result.text->text, text->text, len * sizeof (tchar));
  8931. memcpy (result.text->text + len, textToAppend, otherLen * sizeof (tchar));
  8932. result.text->text [len + otherLen] = 0;
  8933. return result;
  8934. }
  8935. const String String::operator+ (const tchar characterToAppend) const throw()
  8936. {
  8937. if (characterToAppend == 0)
  8938. return *this;
  8939. const int len = CharacterFunctions::length (text->text);
  8940. String result ((int) (len + 1), (int) 0);
  8941. memcpy (result.text->text, text->text, len * sizeof (tchar));
  8942. result.text->text[len] = characterToAppend;
  8943. result.text->text[len + 1] = 0;
  8944. return result;
  8945. }
  8946. const String JUCE_PUBLIC_FUNCTION operator+ (const char* const string1,
  8947. const String& string2) throw()
  8948. {
  8949. String s (string1);
  8950. s += string2;
  8951. return s;
  8952. }
  8953. const String JUCE_PUBLIC_FUNCTION operator+ (const juce_wchar* const string1,
  8954. const String& string2) throw()
  8955. {
  8956. String s (string1);
  8957. s += string2;
  8958. return s;
  8959. }
  8960. const String& String::operator+= (const tchar* const t) throw()
  8961. {
  8962. if (t != 0)
  8963. appendInternal (t, CharacterFunctions::length (t));
  8964. return *this;
  8965. }
  8966. const String& String::operator+= (const String& other) throw()
  8967. {
  8968. if (isEmpty())
  8969. operator= (other);
  8970. else
  8971. appendInternal (other.text->text,
  8972. CharacterFunctions::length (other.text->text));
  8973. return *this;
  8974. }
  8975. const String& String::operator+= (const char ch) throw()
  8976. {
  8977. char asString[2];
  8978. asString[0] = ch;
  8979. asString[1] = 0;
  8980. #if JUCE_STRINGS_ARE_UNICODE
  8981. operator+= (String (asString));
  8982. #else
  8983. appendInternal (asString, 1);
  8984. #endif
  8985. return *this;
  8986. }
  8987. const String& String::operator+= (const juce_wchar ch) throw()
  8988. {
  8989. juce_wchar asString[2];
  8990. asString[0] = ch;
  8991. asString[1] = 0;
  8992. #if JUCE_STRINGS_ARE_UNICODE
  8993. appendInternal (asString, 1);
  8994. #else
  8995. operator+= (String (asString));
  8996. #endif
  8997. return *this;
  8998. }
  8999. void String::append (const tchar* const other,
  9000. const int howMany) throw()
  9001. {
  9002. if (howMany > 0)
  9003. {
  9004. int i;
  9005. for (i = 0; i < howMany; ++i)
  9006. if (other[i] == 0)
  9007. break;
  9008. appendInternal (other, i);
  9009. }
  9010. }
  9011. String& String::operator<< (const int number) throw()
  9012. {
  9013. tchar buffer [64];
  9014. tchar* const end = buffer + 64;
  9015. const tchar* const t = intToCharString (end, number);
  9016. appendInternal (t, (int) (end - t) - 1);
  9017. return *this;
  9018. }
  9019. String& String::operator<< (const unsigned int number) throw()
  9020. {
  9021. tchar buffer [64];
  9022. tchar* const end = buffer + 64;
  9023. const tchar* const t = uintToCharString (end, number);
  9024. appendInternal (t, (int) (end - t) - 1);
  9025. return *this;
  9026. }
  9027. String& String::operator<< (const short number) throw()
  9028. {
  9029. tchar buffer [64];
  9030. tchar* const end = buffer + 64;
  9031. const tchar* const t = intToCharString (end, (int) number);
  9032. appendInternal (t, (int) (end - t) - 1);
  9033. return *this;
  9034. }
  9035. String& String::operator<< (const long number) throw()
  9036. {
  9037. return operator<< ((int) number);
  9038. }
  9039. String& String::operator<< (const unsigned long number) throw()
  9040. {
  9041. return operator<< ((unsigned int) number);
  9042. }
  9043. String& String::operator<< (const double number) throw()
  9044. {
  9045. operator+= (String (number));
  9046. return *this;
  9047. }
  9048. String& String::operator<< (const float number) throw()
  9049. {
  9050. operator+= (String (number));
  9051. return *this;
  9052. }
  9053. String& String::operator<< (const char character) throw()
  9054. {
  9055. operator+= (character);
  9056. return *this;
  9057. }
  9058. String& String::operator<< (const juce_wchar character) throw()
  9059. {
  9060. operator+= (character);
  9061. return *this;
  9062. }
  9063. String& String::operator<< (const char* const t) throw()
  9064. {
  9065. #if JUCE_STRINGS_ARE_UNICODE
  9066. operator+= (String (t));
  9067. #else
  9068. operator+= (t);
  9069. #endif
  9070. return *this;
  9071. }
  9072. String& String::operator<< (const juce_wchar* const t) throw()
  9073. {
  9074. #if JUCE_STRINGS_ARE_UNICODE
  9075. operator+= (t);
  9076. #else
  9077. operator+= (String (t));
  9078. #endif
  9079. return *this;
  9080. }
  9081. String& String::operator<< (const String& t) throw()
  9082. {
  9083. operator+= (t);
  9084. return *this;
  9085. }
  9086. int String::indexOfChar (const tchar character) const throw()
  9087. {
  9088. const tchar* t = text->text;
  9089. for (;;)
  9090. {
  9091. if (*t == character)
  9092. return (int) (t - text->text);
  9093. if (*t++ == 0)
  9094. return -1;
  9095. }
  9096. }
  9097. int String::lastIndexOfChar (const tchar character) const throw()
  9098. {
  9099. for (int i = CharacterFunctions::length (text->text); --i >= 0;)
  9100. if (text->text[i] == character)
  9101. return i;
  9102. return -1;
  9103. }
  9104. int String::indexOf (const tchar* const t) const throw()
  9105. {
  9106. const tchar* const r = CharacterFunctions::find (text->text, t);
  9107. return (r == 0) ? -1
  9108. : (int) (r - text->text);
  9109. }
  9110. int String::indexOfChar (const int startIndex,
  9111. const tchar character) const throw()
  9112. {
  9113. if (startIndex >= 0 && startIndex >= CharacterFunctions::length (text->text))
  9114. return -1;
  9115. const tchar* t = text->text + jmax (0, startIndex);
  9116. for (;;)
  9117. {
  9118. if (*t == character)
  9119. return (int) (t - text->text);
  9120. if (*t++ == 0)
  9121. return -1;
  9122. }
  9123. }
  9124. int String::indexOfAnyOf (const tchar* const charactersToLookFor,
  9125. const int startIndex,
  9126. const bool ignoreCase) const throw()
  9127. {
  9128. if (charactersToLookFor == 0
  9129. || (startIndex >= 0 && startIndex >= CharacterFunctions::length (text->text)))
  9130. return -1;
  9131. const tchar* t = text->text + jmax (0, startIndex);
  9132. while (*t != 0)
  9133. {
  9134. if (CharacterFunctions::indexOfChar (charactersToLookFor, *t, ignoreCase) >= 0)
  9135. return (int) (t - text->text);
  9136. ++t;
  9137. }
  9138. return -1;
  9139. }
  9140. int String::indexOf (const int startIndex,
  9141. const tchar* const other) const throw()
  9142. {
  9143. if (other == 0 || startIndex >= CharacterFunctions::length (text->text))
  9144. return -1;
  9145. const tchar* const found = CharacterFunctions::find (text->text + jmax (0, startIndex),
  9146. other);
  9147. return (found == 0) ? -1
  9148. : (int) (found - text->text);
  9149. }
  9150. int String::indexOfIgnoreCase (const tchar* const other) const throw()
  9151. {
  9152. if (other != 0 && *other != 0)
  9153. {
  9154. const int len = CharacterFunctions::length (other);
  9155. const int end = CharacterFunctions::length (text->text) - len;
  9156. for (int i = 0; i <= end; ++i)
  9157. if (CharacterFunctions::compareIgnoreCase (text->text + i, other, len) == 0)
  9158. return i;
  9159. }
  9160. return -1;
  9161. }
  9162. int String::indexOfIgnoreCase (const int startIndex,
  9163. const tchar* const other) const throw()
  9164. {
  9165. if (other != 0 && *other != 0)
  9166. {
  9167. const int len = CharacterFunctions::length (other);
  9168. const int end = length() - len;
  9169. for (int i = jmax (0, startIndex); i <= end; ++i)
  9170. if (CharacterFunctions::compareIgnoreCase (text->text + i, other, len) == 0)
  9171. return i;
  9172. }
  9173. return -1;
  9174. }
  9175. int String::lastIndexOf (const tchar* const other) const throw()
  9176. {
  9177. if (other != 0 && *other != 0)
  9178. {
  9179. const int len = CharacterFunctions::length (other);
  9180. int i = length() - len;
  9181. if (i >= 0)
  9182. {
  9183. const tchar* n = text->text + i;
  9184. while (i >= 0)
  9185. {
  9186. if (CharacterFunctions::compare (n--, other, len) == 0)
  9187. return i;
  9188. --i;
  9189. }
  9190. }
  9191. }
  9192. return -1;
  9193. }
  9194. int String::lastIndexOfIgnoreCase (const tchar* const other) const throw()
  9195. {
  9196. if (other != 0 && *other != 0)
  9197. {
  9198. const int len = CharacterFunctions::length (other);
  9199. int i = length() - len;
  9200. if (i >= 0)
  9201. {
  9202. const tchar* n = text->text + i;
  9203. while (i >= 0)
  9204. {
  9205. if (CharacterFunctions::compareIgnoreCase (n--, other, len) == 0)
  9206. return i;
  9207. --i;
  9208. }
  9209. }
  9210. }
  9211. return -1;
  9212. }
  9213. int String::lastIndexOfAnyOf (const tchar* const charactersToLookFor,
  9214. const bool ignoreCase) const throw()
  9215. {
  9216. for (int i = CharacterFunctions::length (text->text); --i >= 0;)
  9217. if (CharacterFunctions::indexOfChar (charactersToLookFor, text->text [i], ignoreCase) >= 0)
  9218. return i;
  9219. return -1;
  9220. }
  9221. bool String::contains (const tchar* const other) const throw()
  9222. {
  9223. return indexOf (other) >= 0;
  9224. }
  9225. bool String::containsChar (const tchar character) const throw()
  9226. {
  9227. return indexOfChar (character) >= 0;
  9228. }
  9229. bool String::containsIgnoreCase (const tchar* const t) const throw()
  9230. {
  9231. return indexOfIgnoreCase (t) >= 0;
  9232. }
  9233. int String::indexOfWholeWord (const tchar* const word) const throw()
  9234. {
  9235. if (word != 0 && *word != 0)
  9236. {
  9237. const int wordLen = CharacterFunctions::length (word);
  9238. const int end = length() - wordLen;
  9239. const tchar* t = text->text;
  9240. for (int i = 0; i <= end; ++i)
  9241. {
  9242. if (CharacterFunctions::compare (t, word, wordLen) == 0
  9243. && (i == 0 || ! CharacterFunctions::isLetterOrDigit (* (t - 1)))
  9244. && ! CharacterFunctions::isLetterOrDigit (t [wordLen]))
  9245. {
  9246. return i;
  9247. }
  9248. ++t;
  9249. }
  9250. }
  9251. return -1;
  9252. }
  9253. int String::indexOfWholeWordIgnoreCase (const tchar* const word) const throw()
  9254. {
  9255. if (word != 0 && *word != 0)
  9256. {
  9257. const int wordLen = CharacterFunctions::length (word);
  9258. const int end = length() - wordLen;
  9259. const tchar* t = text->text;
  9260. for (int i = 0; i <= end; ++i)
  9261. {
  9262. if (CharacterFunctions::compareIgnoreCase (t, word, wordLen) == 0
  9263. && (i == 0 || ! CharacterFunctions::isLetterOrDigit (* (t - 1)))
  9264. && ! CharacterFunctions::isLetterOrDigit (t [wordLen]))
  9265. {
  9266. return i;
  9267. }
  9268. ++t;
  9269. }
  9270. }
  9271. return -1;
  9272. }
  9273. bool String::containsWholeWord (const tchar* const wordToLookFor) const throw()
  9274. {
  9275. return indexOfWholeWord (wordToLookFor) >= 0;
  9276. }
  9277. bool String::containsWholeWordIgnoreCase (const tchar* const wordToLookFor) const throw()
  9278. {
  9279. return indexOfWholeWordIgnoreCase (wordToLookFor) >= 0;
  9280. }
  9281. static int indexOfMatch (const tchar* const wildcard,
  9282. const tchar* const test,
  9283. const bool ignoreCase) throw()
  9284. {
  9285. int start = 0;
  9286. while (test [start] != 0)
  9287. {
  9288. int i = 0;
  9289. for (;;)
  9290. {
  9291. const tchar wc = wildcard [i];
  9292. const tchar c = test [i + start];
  9293. if (wc == c
  9294. || (ignoreCase && CharacterFunctions::toLowerCase (wc) == CharacterFunctions::toLowerCase (c))
  9295. || (wc == T('?') && c != 0))
  9296. {
  9297. if (wc == 0)
  9298. return start;
  9299. ++i;
  9300. }
  9301. else
  9302. {
  9303. if (wc == T('*') && (wildcard [i + 1] == 0
  9304. || indexOfMatch (wildcard + i + 1,
  9305. test + start + i,
  9306. ignoreCase) >= 0))
  9307. {
  9308. return start;
  9309. }
  9310. break;
  9311. }
  9312. }
  9313. ++start;
  9314. }
  9315. return -1;
  9316. }
  9317. bool String::matchesWildcard (const tchar* wildcard, const bool ignoreCase) const throw()
  9318. {
  9319. int i = 0;
  9320. for (;;)
  9321. {
  9322. const tchar wc = wildcard [i];
  9323. const tchar c = text->text [i];
  9324. if (wc == c
  9325. || (ignoreCase && CharacterFunctions::toLowerCase (wc) == CharacterFunctions::toLowerCase (c))
  9326. || (wc == T('?') && c != 0))
  9327. {
  9328. if (wc == 0)
  9329. return true;
  9330. ++i;
  9331. }
  9332. else
  9333. {
  9334. return wc == T('*') && (wildcard [i + 1] == 0
  9335. || indexOfMatch (wildcard + i + 1,
  9336. text->text + i,
  9337. ignoreCase) >= 0);
  9338. }
  9339. }
  9340. }
  9341. void String::printf (const tchar* const pf, ...) throw()
  9342. {
  9343. va_list list;
  9344. va_start (list, pf);
  9345. vprintf (pf, list);
  9346. }
  9347. const String String::formatted (const tchar* const pf, ...) throw()
  9348. {
  9349. va_list list;
  9350. va_start (list, pf);
  9351. String result;
  9352. result.vprintf (pf, list);
  9353. return result;
  9354. }
  9355. void String::vprintf (const tchar* const pf, va_list& args) throw()
  9356. {
  9357. int bufferSize = 256;
  9358. String result (bufferSize, 0);
  9359. do
  9360. {
  9361. #if JUCE_LINUX && JUCE_64BIT
  9362. va_list tempArgs;
  9363. va_copy (tempArgs, args);
  9364. const int num = CharacterFunctions::vprintf (result.text->text, bufferSize - 1, pf, tempArgs);
  9365. va_end (tempArgs);
  9366. #else
  9367. const int num = CharacterFunctions::vprintf (result.text->text, bufferSize - 1, pf, args);
  9368. #endif
  9369. if (num > 0)
  9370. {
  9371. *this = result;
  9372. break;
  9373. }
  9374. else if (num == 0)
  9375. {
  9376. *this = String::empty;
  9377. break;
  9378. }
  9379. bufferSize += 256;
  9380. result.preallocateStorage (bufferSize);
  9381. }
  9382. while (bufferSize < 65536); // this is a sanity check to avoid situations where vprintf repeatedly
  9383. // returns -1 because of an error rather than because it needs more space.
  9384. }
  9385. const String String::repeatedString (const tchar* const stringToRepeat,
  9386. int numberOfTimesToRepeat) throw()
  9387. {
  9388. const int len = CharacterFunctions::length (stringToRepeat);
  9389. String result ((int) (len * numberOfTimesToRepeat + 1), (int) 0);
  9390. tchar* n = result.text->text;
  9391. n[0] = 0;
  9392. while (--numberOfTimesToRepeat >= 0)
  9393. {
  9394. CharacterFunctions::append (n, stringToRepeat);
  9395. n += len;
  9396. }
  9397. return result;
  9398. }
  9399. const String String::replaceSection (int index,
  9400. int numCharsToReplace,
  9401. const tchar* const stringToInsert) const throw()
  9402. {
  9403. if (index < 0)
  9404. {
  9405. // a negative index to replace from?
  9406. jassertfalse
  9407. index = 0;
  9408. }
  9409. if (numCharsToReplace < 0)
  9410. {
  9411. // replacing a negative number of characters?
  9412. numCharsToReplace = 0;
  9413. jassertfalse;
  9414. }
  9415. const int len = length();
  9416. if (index + numCharsToReplace > len)
  9417. {
  9418. if (index > len)
  9419. {
  9420. // replacing beyond the end of the string?
  9421. index = len;
  9422. jassertfalse
  9423. }
  9424. numCharsToReplace = len - index;
  9425. }
  9426. const int newStringLen = (stringToInsert != 0) ? CharacterFunctions::length (stringToInsert) : 0;
  9427. const int newTotalLen = len + newStringLen - numCharsToReplace;
  9428. if (newTotalLen <= 0)
  9429. return String::empty;
  9430. String result (newTotalLen, (int) 0);
  9431. memcpy (result.text->text,
  9432. text->text,
  9433. index * sizeof (tchar));
  9434. if (newStringLen > 0)
  9435. memcpy (result.text->text + index,
  9436. stringToInsert,
  9437. newStringLen * sizeof (tchar));
  9438. const int endStringLen = newTotalLen - (index + newStringLen);
  9439. if (endStringLen > 0)
  9440. memcpy (result.text->text + (index + newStringLen),
  9441. text->text + (index + numCharsToReplace),
  9442. endStringLen * sizeof (tchar));
  9443. result.text->text [newTotalLen] = 0;
  9444. return result;
  9445. }
  9446. const String String::replace (const tchar* const stringToReplace,
  9447. const tchar* const stringToInsert,
  9448. const bool ignoreCase) const throw()
  9449. {
  9450. const int stringToReplaceLen = CharacterFunctions::length (stringToReplace);
  9451. const int stringToInsertLen = CharacterFunctions::length (stringToInsert);
  9452. int i = 0;
  9453. String result (*this);
  9454. while ((i = (ignoreCase ? result.indexOfIgnoreCase (i, stringToReplace)
  9455. : result.indexOf (i, stringToReplace))) >= 0)
  9456. {
  9457. result = result.replaceSection (i, stringToReplaceLen, stringToInsert);
  9458. i += stringToInsertLen;
  9459. }
  9460. return result;
  9461. }
  9462. const String String::replaceCharacter (const tchar charToReplace,
  9463. const tchar charToInsert) const throw()
  9464. {
  9465. const int index = indexOfChar (charToReplace);
  9466. if (index < 0)
  9467. return *this;
  9468. String result (*this);
  9469. result.dupeInternalIfMultiplyReferenced();
  9470. tchar* t = result.text->text + index;
  9471. while (*t != 0)
  9472. {
  9473. if (*t == charToReplace)
  9474. *t = charToInsert;
  9475. ++t;
  9476. }
  9477. return result;
  9478. }
  9479. const String String::replaceCharacters (const String& charactersToReplace,
  9480. const tchar* const charactersToInsertInstead) const throw()
  9481. {
  9482. String result (*this);
  9483. result.dupeInternalIfMultiplyReferenced();
  9484. tchar* t = result.text->text;
  9485. const int len2 = CharacterFunctions::length (charactersToInsertInstead);
  9486. // the two strings passed in are supposed to be the same length!
  9487. jassert (len2 == charactersToReplace.length());
  9488. while (*t != 0)
  9489. {
  9490. const int index = charactersToReplace.indexOfChar (*t);
  9491. if (((unsigned int) index) < (unsigned int) len2)
  9492. *t = charactersToInsertInstead [index];
  9493. ++t;
  9494. }
  9495. return result;
  9496. }
  9497. bool String::startsWith (const tchar* const other) const throw()
  9498. {
  9499. return other != 0
  9500. && CharacterFunctions::compare (text->text, other, CharacterFunctions::length (other)) == 0;
  9501. }
  9502. bool String::startsWithIgnoreCase (const tchar* const other) const throw()
  9503. {
  9504. return other != 0
  9505. && CharacterFunctions::compareIgnoreCase (text->text, other, CharacterFunctions::length (other)) == 0;
  9506. }
  9507. bool String::startsWithChar (const tchar character) const throw()
  9508. {
  9509. jassert (character != 0); // strings can't contain a null character!
  9510. return text->text[0] == character;
  9511. }
  9512. bool String::endsWithChar (const tchar character) const throw()
  9513. {
  9514. jassert (character != 0); // strings can't contain a null character!
  9515. return text->text[0] != 0
  9516. && text->text [length() - 1] == character;
  9517. }
  9518. bool String::endsWith (const tchar* const other) const throw()
  9519. {
  9520. if (other == 0)
  9521. return false;
  9522. const int thisLen = length();
  9523. const int otherLen = CharacterFunctions::length (other);
  9524. return thisLen >= otherLen
  9525. && CharacterFunctions::compare (text->text + thisLen - otherLen, other) == 0;
  9526. }
  9527. bool String::endsWithIgnoreCase (const tchar* const other) const throw()
  9528. {
  9529. if (other == 0)
  9530. return false;
  9531. const int thisLen = length();
  9532. const int otherLen = CharacterFunctions::length (other);
  9533. return thisLen >= otherLen
  9534. && CharacterFunctions::compareIgnoreCase (text->text + thisLen - otherLen, other) == 0;
  9535. }
  9536. const String String::toUpperCase() const throw()
  9537. {
  9538. String result (*this);
  9539. result.dupeInternalIfMultiplyReferenced();
  9540. CharacterFunctions::toUpperCase (result.text->text);
  9541. return result;
  9542. }
  9543. const String String::toLowerCase() const throw()
  9544. {
  9545. String result (*this);
  9546. result.dupeInternalIfMultiplyReferenced();
  9547. CharacterFunctions::toLowerCase (result.text->text);
  9548. return result;
  9549. }
  9550. tchar& String::operator[] (const int index) throw()
  9551. {
  9552. jassert (((unsigned int) index) <= (unsigned int) length());
  9553. dupeInternalIfMultiplyReferenced();
  9554. return text->text [index];
  9555. }
  9556. tchar String::getLastCharacter() const throw()
  9557. {
  9558. return (isEmpty()) ? ((tchar) 0)
  9559. : text->text [CharacterFunctions::length (text->text) - 1];
  9560. }
  9561. const String String::substring (int start, int end) const throw()
  9562. {
  9563. if (start < 0)
  9564. start = 0;
  9565. else if (end <= start)
  9566. return empty;
  9567. int len = 0;
  9568. const tchar* const t = text->text;
  9569. while (len <= end && t [len] != 0)
  9570. ++len;
  9571. if (end >= len)
  9572. {
  9573. if (start == 0)
  9574. return *this;
  9575. end = len;
  9576. }
  9577. return String (text->text + start,
  9578. end - start);
  9579. }
  9580. const String String::substring (const int start) const throw()
  9581. {
  9582. if (start <= 0)
  9583. return *this;
  9584. const int len = CharacterFunctions::length (text->text);
  9585. if (start >= len)
  9586. return empty;
  9587. else
  9588. return String (text->text + start,
  9589. len - start);
  9590. }
  9591. const String String::dropLastCharacters (const int numberToDrop) const throw()
  9592. {
  9593. return String (text->text,
  9594. jmax (0, CharacterFunctions::length (text->text) - numberToDrop));
  9595. }
  9596. const String String::getLastCharacters (const int numCharacters) const throw()
  9597. {
  9598. return String (text->text + jmax (0, CharacterFunctions::length (text->text) - jmax (0, numCharacters)));
  9599. }
  9600. const String String::fromFirstOccurrenceOf (const tchar* const sub,
  9601. const bool includeSubString,
  9602. const bool ignoreCase) const throw()
  9603. {
  9604. const int i = ignoreCase ? indexOfIgnoreCase (sub)
  9605. : indexOf (sub);
  9606. if (i < 0)
  9607. return empty;
  9608. else
  9609. return substring (includeSubString ? i : i + CharacterFunctions::length (sub));
  9610. }
  9611. const String String::fromLastOccurrenceOf (const tchar* const sub,
  9612. const bool includeSubString,
  9613. const bool ignoreCase) const throw()
  9614. {
  9615. const int i = ignoreCase ? lastIndexOfIgnoreCase (sub)
  9616. : lastIndexOf (sub);
  9617. if (i < 0)
  9618. return *this;
  9619. else
  9620. return substring (includeSubString ? i : i + CharacterFunctions::length (sub));
  9621. }
  9622. const String String::upToFirstOccurrenceOf (const tchar* const sub,
  9623. const bool includeSubString,
  9624. const bool ignoreCase) const throw()
  9625. {
  9626. const int i = ignoreCase ? indexOfIgnoreCase (sub)
  9627. : indexOf (sub);
  9628. if (i < 0)
  9629. return *this;
  9630. else
  9631. return substring (0, includeSubString ? i + CharacterFunctions::length (sub) : i);
  9632. }
  9633. const String String::upToLastOccurrenceOf (const tchar* const sub,
  9634. const bool includeSubString,
  9635. const bool ignoreCase) const throw()
  9636. {
  9637. const int i = ignoreCase ? lastIndexOfIgnoreCase (sub)
  9638. : lastIndexOf (sub);
  9639. if (i < 0)
  9640. return *this;
  9641. return substring (0, includeSubString ? i + CharacterFunctions::length (sub) : i);
  9642. }
  9643. bool String::isQuotedString() const throw()
  9644. {
  9645. const String trimmed (trimStart());
  9646. return trimmed[0] == T('"')
  9647. || trimmed[0] == T('\'');
  9648. }
  9649. const String String::unquoted() const throw()
  9650. {
  9651. String s (*this);
  9652. if (s[0] == T('"') || s[0] == T('\''))
  9653. s = s.substring (1);
  9654. const int lastCharIndex = s.length() - 1;
  9655. if (lastCharIndex >= 0
  9656. && (s [lastCharIndex] == T('"') || s[lastCharIndex] == T('\'')))
  9657. s [lastCharIndex] = 0;
  9658. return s;
  9659. }
  9660. const String String::quoted (const tchar quoteCharacter) const throw()
  9661. {
  9662. if (isEmpty())
  9663. return charToString (quoteCharacter) + quoteCharacter;
  9664. String t (*this);
  9665. if (! t.startsWithChar (quoteCharacter))
  9666. t = charToString (quoteCharacter) + t;
  9667. if (! t.endsWithChar (quoteCharacter))
  9668. t += quoteCharacter;
  9669. return t;
  9670. }
  9671. const String String::trim() const throw()
  9672. {
  9673. if (isEmpty())
  9674. return empty;
  9675. int start = 0;
  9676. while (CharacterFunctions::isWhitespace (text->text [start]))
  9677. ++start;
  9678. const int len = CharacterFunctions::length (text->text);
  9679. int end = len - 1;
  9680. while ((end >= start) && CharacterFunctions::isWhitespace (text->text [end]))
  9681. --end;
  9682. ++end;
  9683. if (end <= start)
  9684. return empty;
  9685. else if (start > 0 || end < len)
  9686. return String (text->text + start, end - start);
  9687. else
  9688. return *this;
  9689. }
  9690. const String String::trimStart() const throw()
  9691. {
  9692. if (isEmpty())
  9693. return empty;
  9694. const tchar* t = text->text;
  9695. while (CharacterFunctions::isWhitespace (*t))
  9696. ++t;
  9697. if (t == text->text)
  9698. return *this;
  9699. else
  9700. return String (t);
  9701. }
  9702. const String String::trimEnd() const throw()
  9703. {
  9704. if (isEmpty())
  9705. return empty;
  9706. const tchar* endT = text->text + (CharacterFunctions::length (text->text) - 1);
  9707. while ((endT >= text->text) && CharacterFunctions::isWhitespace (*endT))
  9708. --endT;
  9709. return String (text->text, (int) (++endT - text->text));
  9710. }
  9711. const String String::trimCharactersAtStart (const tchar* charactersToTrim) const throw()
  9712. {
  9713. jassert (charactersToTrim != 0);
  9714. if (isEmpty())
  9715. return empty;
  9716. const tchar* t = text->text;
  9717. while (CharacterFunctions::indexOfCharFast (charactersToTrim, *t) >= 0)
  9718. ++t;
  9719. if (t == text->text)
  9720. return *this;
  9721. else
  9722. return String (t);
  9723. }
  9724. const String String::trimCharactersAtEnd (const tchar* charactersToTrim) const throw()
  9725. {
  9726. jassert (charactersToTrim != 0);
  9727. if (isEmpty())
  9728. return empty;
  9729. const tchar* endT = text->text + (CharacterFunctions::length (text->text) - 1);
  9730. while ((endT >= text->text) && CharacterFunctions::indexOfCharFast (charactersToTrim, *endT) >= 0)
  9731. --endT;
  9732. return String (text->text, (int) (++endT - text->text));
  9733. }
  9734. const String String::retainCharacters (const tchar* const charactersToRetain) const throw()
  9735. {
  9736. jassert (charactersToRetain != 0);
  9737. if (isEmpty())
  9738. return empty;
  9739. String result (text->allocatedNumChars, (int) 0);
  9740. tchar* dst = result.text->text;
  9741. const tchar* src = text->text;
  9742. while (*src != 0)
  9743. {
  9744. if (CharacterFunctions::indexOfCharFast (charactersToRetain, *src) >= 0)
  9745. *dst++ = *src;
  9746. ++src;
  9747. }
  9748. *dst = 0;
  9749. return result;
  9750. }
  9751. const String String::removeCharacters (const tchar* const charactersToRemove) const throw()
  9752. {
  9753. jassert (charactersToRemove != 0);
  9754. if (isEmpty())
  9755. return empty;
  9756. String result (text->allocatedNumChars, (int) 0);
  9757. tchar* dst = result.text->text;
  9758. const tchar* src = text->text;
  9759. while (*src != 0)
  9760. {
  9761. if (CharacterFunctions::indexOfCharFast (charactersToRemove, *src) < 0)
  9762. *dst++ = *src;
  9763. ++src;
  9764. }
  9765. *dst = 0;
  9766. return result;
  9767. }
  9768. const String String::initialSectionContainingOnly (const tchar* const permittedCharacters) const throw()
  9769. {
  9770. return substring (0, CharacterFunctions::getIntialSectionContainingOnly (text->text, permittedCharacters));
  9771. }
  9772. const String String::initialSectionNotContaining (const tchar* const charactersToStopAt) const throw()
  9773. {
  9774. jassert (charactersToStopAt != 0);
  9775. const tchar* const t = text->text;
  9776. int i = 0;
  9777. while (t[i] != 0)
  9778. {
  9779. if (CharacterFunctions::indexOfCharFast (charactersToStopAt, t[i]) >= 0)
  9780. return String (text->text, i);
  9781. ++i;
  9782. }
  9783. return empty;
  9784. }
  9785. bool String::containsOnly (const tchar* const chars) const throw()
  9786. {
  9787. jassert (chars != 0);
  9788. const tchar* t = text->text;
  9789. while (*t != 0)
  9790. if (CharacterFunctions::indexOfCharFast (chars, *t++) < 0)
  9791. return false;
  9792. return true;
  9793. }
  9794. bool String::containsAnyOf (const tchar* const chars) const throw()
  9795. {
  9796. jassert (chars != 0);
  9797. const tchar* t = text->text;
  9798. while (*t != 0)
  9799. if (CharacterFunctions::indexOfCharFast (chars, *t++) >= 0)
  9800. return true;
  9801. return false;
  9802. }
  9803. bool String::containsNonWhitespaceChars() const throw()
  9804. {
  9805. const tchar* t = text->text;
  9806. while (*t != 0)
  9807. if (! CharacterFunctions::isWhitespace (*t++))
  9808. return true;
  9809. return false;
  9810. }
  9811. int String::getIntValue() const throw()
  9812. {
  9813. return CharacterFunctions::getIntValue (text->text);
  9814. }
  9815. int String::getTrailingIntValue() const throw()
  9816. {
  9817. int n = 0;
  9818. int mult = 1;
  9819. const tchar* t = text->text + length();
  9820. while (--t >= text->text)
  9821. {
  9822. const tchar c = *t;
  9823. if (! CharacterFunctions::isDigit (c))
  9824. {
  9825. if (c == T('-'))
  9826. n = -n;
  9827. break;
  9828. }
  9829. n += mult * (c - T('0'));
  9830. mult *= 10;
  9831. }
  9832. return n;
  9833. }
  9834. int64 String::getLargeIntValue() const throw()
  9835. {
  9836. return CharacterFunctions::getInt64Value (text->text);
  9837. }
  9838. float String::getFloatValue() const throw()
  9839. {
  9840. return (float) CharacterFunctions::getDoubleValue (text->text);
  9841. }
  9842. double String::getDoubleValue() const throw()
  9843. {
  9844. return CharacterFunctions::getDoubleValue (text->text);
  9845. }
  9846. static const tchar* const hexDigits = T("0123456789abcdef");
  9847. const String String::toHexString (const int number) throw()
  9848. {
  9849. tchar buffer[32];
  9850. tchar* const end = buffer + 32;
  9851. tchar* t = end;
  9852. *--t = 0;
  9853. unsigned int v = (unsigned int) number;
  9854. do
  9855. {
  9856. *--t = hexDigits [v & 15];
  9857. v >>= 4;
  9858. } while (v != 0);
  9859. return String (t, (int) (((char*) end) - (char*) t) - 1);
  9860. }
  9861. const String String::toHexString (const int64 number) throw()
  9862. {
  9863. tchar buffer[32];
  9864. tchar* const end = buffer + 32;
  9865. tchar* t = end;
  9866. *--t = 0;
  9867. uint64 v = (uint64) number;
  9868. do
  9869. {
  9870. *--t = hexDigits [(int) (v & 15)];
  9871. v >>= 4;
  9872. } while (v != 0);
  9873. return String (t, (int) (((char*) end) - (char*) t));
  9874. }
  9875. const String String::toHexString (const short number) throw()
  9876. {
  9877. return toHexString ((int) (unsigned short) number);
  9878. }
  9879. const String String::toHexString (const unsigned char* data,
  9880. const int size,
  9881. const int groupSize) throw()
  9882. {
  9883. if (size <= 0)
  9884. return empty;
  9885. int numChars = (size * 2) + 2;
  9886. if (groupSize > 0)
  9887. numChars += size / groupSize;
  9888. String s (numChars, (int) 0);
  9889. tchar* d = s.text->text;
  9890. for (int i = 0; i < size; ++i)
  9891. {
  9892. *d++ = hexDigits [(*data) >> 4];
  9893. *d++ = hexDigits [(*data) & 0xf];
  9894. ++data;
  9895. if (groupSize > 0 && (i % groupSize) == (groupSize - 1) && i < (size - 1))
  9896. *d++ = T(' ');
  9897. }
  9898. *d = 0;
  9899. return s;
  9900. }
  9901. int String::getHexValue32() const throw()
  9902. {
  9903. int result = 0;
  9904. const tchar* c = text->text;
  9905. for (;;)
  9906. {
  9907. const int hexValue = CharacterFunctions::getHexDigitValue (*c);
  9908. if (hexValue >= 0)
  9909. result = (result << 4) | hexValue;
  9910. else if (*c == 0)
  9911. break;
  9912. ++c;
  9913. }
  9914. return result;
  9915. }
  9916. int64 String::getHexValue64() const throw()
  9917. {
  9918. int64 result = 0;
  9919. const tchar* c = text->text;
  9920. for (;;)
  9921. {
  9922. const int hexValue = CharacterFunctions::getHexDigitValue (*c);
  9923. if (hexValue >= 0)
  9924. result = (result << 4) | hexValue;
  9925. else if (*c == 0)
  9926. break;
  9927. ++c;
  9928. }
  9929. return result;
  9930. }
  9931. const String String::createStringFromData (const void* const data_,
  9932. const int size) throw()
  9933. {
  9934. const char* const data = (const char*) data_;
  9935. if (size <= 0 || data == 0)
  9936. {
  9937. return empty;
  9938. }
  9939. else if (size < 2)
  9940. {
  9941. return charToString (data[0]);
  9942. }
  9943. else if ((data[0] == (char)-2 && data[1] == (char)-1)
  9944. || (data[0] == (char)-1 && data[1] == (char)-2))
  9945. {
  9946. // assume it's 16-bit unicode
  9947. const bool bigEndian = (data[0] == (char)-2);
  9948. const int numChars = size / 2 - 1;
  9949. String result;
  9950. result.preallocateStorage (numChars + 2);
  9951. const uint16* const src = (const uint16*) (data + 2);
  9952. tchar* const dst = const_cast <tchar*> ((const tchar*) result);
  9953. if (bigEndian)
  9954. {
  9955. for (int i = 0; i < numChars; ++i)
  9956. dst[i] = (tchar) ByteOrder::swapIfLittleEndian (src[i]);
  9957. }
  9958. else
  9959. {
  9960. for (int i = 0; i < numChars; ++i)
  9961. dst[i] = (tchar) ByteOrder::swapIfBigEndian (src[i]);
  9962. }
  9963. dst [numChars] = 0;
  9964. return result;
  9965. }
  9966. else
  9967. {
  9968. return String::fromUTF8 ((const uint8*) data, size);
  9969. }
  9970. }
  9971. const char* String::toUTF8() const throw()
  9972. {
  9973. if (isEmpty())
  9974. {
  9975. return (const char*) emptyCharString;
  9976. }
  9977. else
  9978. {
  9979. String* const mutableThis = const_cast <String*> (this);
  9980. mutableThis->dupeInternalIfMultiplyReferenced();
  9981. const int currentLen = CharacterFunctions::length (text->text) + 1;
  9982. const int utf8BytesNeeded = copyToUTF8 (0);
  9983. mutableThis->text = (InternalRefCountedStringHolder*)
  9984. juce_realloc (text, sizeof (InternalRefCountedStringHolder)
  9985. + (currentLen * sizeof (juce_wchar) + utf8BytesNeeded));
  9986. char* const otherCopy = (char*) (text->text + currentLen);
  9987. copyToUTF8 ((uint8*) otherCopy);
  9988. return otherCopy;
  9989. }
  9990. }
  9991. int String::copyToUTF8 (uint8* const buffer, const int maxBufferSizeBytes) const throw()
  9992. {
  9993. jassert (maxBufferSizeBytes >= 0); // keep this value positive, or no characters will be copied!
  9994. #if JUCE_STRINGS_ARE_UNICODE
  9995. int num = 0, index = 0;
  9996. for (;;)
  9997. {
  9998. const uint32 c = (uint32) text->text [index++];
  9999. if (c >= 0x80)
  10000. {
  10001. int numExtraBytes = 1;
  10002. if (c >= 0x800)
  10003. {
  10004. ++numExtraBytes;
  10005. if (c >= 0x10000)
  10006. {
  10007. ++numExtraBytes;
  10008. if (c >= 0x200000)
  10009. {
  10010. ++numExtraBytes;
  10011. if (c >= 0x4000000)
  10012. ++numExtraBytes;
  10013. }
  10014. }
  10015. }
  10016. if (buffer != 0)
  10017. {
  10018. if (num + numExtraBytes >= maxBufferSizeBytes)
  10019. {
  10020. buffer [num++] = 0;
  10021. break;
  10022. }
  10023. else
  10024. {
  10025. buffer [num++] = (uint8) ((0xff << (7 - numExtraBytes)) | (c >> (numExtraBytes * 6)));
  10026. while (--numExtraBytes >= 0)
  10027. buffer [num++] = (uint8) (0x80 | (0x3f & (c >> (numExtraBytes * 6))));
  10028. }
  10029. }
  10030. else
  10031. {
  10032. num += numExtraBytes + 1;
  10033. }
  10034. }
  10035. else
  10036. {
  10037. if (buffer != 0)
  10038. {
  10039. if (num + 1 >= maxBufferSizeBytes)
  10040. {
  10041. buffer [num++] = 0;
  10042. break;
  10043. }
  10044. buffer [num] = (uint8) c;
  10045. }
  10046. ++num;
  10047. }
  10048. if (c == 0)
  10049. break;
  10050. }
  10051. return num;
  10052. #else
  10053. const int numBytes = jmin (maxBufferSizeBytes, length() + 1);
  10054. if (buffer != 0)
  10055. copyToBuffer ((char*) buffer, maxBufferSizeBytes);
  10056. return numBytes;
  10057. #endif
  10058. }
  10059. const String String::fromUTF8 (const uint8* const buffer, int bufferSizeBytes) throw()
  10060. {
  10061. if (buffer == 0)
  10062. return empty;
  10063. if (bufferSizeBytes < 0)
  10064. bufferSizeBytes = std::numeric_limits<int>::max();
  10065. size_t numBytes;
  10066. for (numBytes = 0; numBytes < (size_t) bufferSizeBytes; ++numBytes)
  10067. if (buffer [numBytes] == 0)
  10068. break;
  10069. String result ((int) numBytes + 1, 0);
  10070. tchar* dest = result.text->text;
  10071. size_t i = 0;
  10072. while (i < numBytes)
  10073. {
  10074. const uint8 c = buffer [i++];
  10075. if ((c & 0x80) != 0)
  10076. {
  10077. int mask = 0x7f;
  10078. int bit = 0x40;
  10079. int numExtraValues = 0;
  10080. while (bit != 0 && (c & bit) != 0)
  10081. {
  10082. bit >>= 1;
  10083. mask >>= 1;
  10084. ++numExtraValues;
  10085. }
  10086. int n = (c & mask);
  10087. while (--numExtraValues >= 0 && i < (size_t) bufferSizeBytes)
  10088. {
  10089. const uint8 nextByte = buffer[i];
  10090. if ((nextByte & 0xc0) != 0x80)
  10091. break;
  10092. n <<= 6;
  10093. n |= (nextByte & 0x3f);
  10094. ++i;
  10095. }
  10096. *dest++ = (tchar) n;
  10097. }
  10098. else
  10099. {
  10100. *dest++ = (tchar) c;
  10101. }
  10102. }
  10103. *dest = 0;
  10104. return result;
  10105. }
  10106. String::Concatenator::Concatenator (String& stringToAppendTo)
  10107. : result (stringToAppendTo),
  10108. nextIndex (stringToAppendTo.length())
  10109. {
  10110. }
  10111. String::Concatenator::~Concatenator()
  10112. {
  10113. }
  10114. void String::Concatenator::append (const String& s)
  10115. {
  10116. const int len = s.length();
  10117. if (len > 0)
  10118. {
  10119. result.preallocateStorage (nextIndex + len);
  10120. s.copyToBuffer (const_cast <tchar*> ((const tchar*) result) + nextIndex, len);
  10121. nextIndex += len;
  10122. }
  10123. }
  10124. END_JUCE_NAMESPACE
  10125. /*** End of inlined file: juce_String.cpp ***/
  10126. /*** Start of inlined file: juce_StringArray.cpp ***/
  10127. BEGIN_JUCE_NAMESPACE
  10128. StringArray::StringArray() throw()
  10129. {
  10130. }
  10131. StringArray::StringArray (const StringArray& other)
  10132. : strings (other.strings)
  10133. {
  10134. }
  10135. StringArray::StringArray (const juce_wchar** const initialStrings,
  10136. const int numberOfStrings)
  10137. {
  10138. for (int i = 0; i < numberOfStrings; ++i)
  10139. add (initialStrings [i]);
  10140. }
  10141. StringArray::StringArray (const char** const initialStrings,
  10142. const int numberOfStrings)
  10143. {
  10144. for (int i = 0; i < numberOfStrings; ++i)
  10145. add (initialStrings [i]);
  10146. }
  10147. StringArray::StringArray (const juce_wchar** const initialStrings)
  10148. {
  10149. int i = 0;
  10150. while (initialStrings[i] != 0)
  10151. add (initialStrings [i++]);
  10152. }
  10153. StringArray::StringArray (const char** const initialStrings)
  10154. {
  10155. int i = 0;
  10156. while (initialStrings[i] != 0)
  10157. add (initialStrings [i++]);
  10158. }
  10159. const StringArray& StringArray::operator= (const StringArray& other)
  10160. {
  10161. strings = other.strings;
  10162. return *this;
  10163. }
  10164. StringArray::~StringArray()
  10165. {
  10166. }
  10167. bool StringArray::operator== (const StringArray& other) const
  10168. {
  10169. if (other.size() != size())
  10170. return false;
  10171. for (int i = size(); --i >= 0;)
  10172. if (other.strings.getReference(i) != strings.getReference(i))
  10173. return false;
  10174. return true;
  10175. }
  10176. bool StringArray::operator!= (const StringArray& other) const
  10177. {
  10178. return ! operator== (other);
  10179. }
  10180. void StringArray::clear()
  10181. {
  10182. strings.clear();
  10183. }
  10184. const String& StringArray::operator[] (const int index) const throw()
  10185. {
  10186. if (((unsigned int) index) < (unsigned int) strings.size())
  10187. return strings.getReference (index);
  10188. return String::empty;
  10189. }
  10190. void StringArray::add (const String& newString)
  10191. {
  10192. strings.add (newString);
  10193. }
  10194. void StringArray::insert (const int index, const String& newString)
  10195. {
  10196. strings.insert (index, newString);
  10197. }
  10198. void StringArray::addIfNotAlreadyThere (const String& newString, const bool ignoreCase)
  10199. {
  10200. if (! contains (newString, ignoreCase))
  10201. add (newString);
  10202. }
  10203. void StringArray::addArray (const StringArray& otherArray, int startIndex, int numElementsToAdd)
  10204. {
  10205. if (startIndex < 0)
  10206. {
  10207. jassertfalse
  10208. startIndex = 0;
  10209. }
  10210. if (numElementsToAdd < 0 || startIndex + numElementsToAdd > otherArray.size())
  10211. numElementsToAdd = otherArray.size() - startIndex;
  10212. while (--numElementsToAdd >= 0)
  10213. strings.add (otherArray.strings.getReference (startIndex++));
  10214. }
  10215. void StringArray::set (const int index, const String& newString)
  10216. {
  10217. strings.set (index, newString);
  10218. }
  10219. bool StringArray::contains (const String& stringToLookFor, const bool ignoreCase) const
  10220. {
  10221. if (ignoreCase)
  10222. {
  10223. for (int i = size(); --i >= 0;)
  10224. if (strings.getReference(i).equalsIgnoreCase (stringToLookFor))
  10225. return true;
  10226. }
  10227. else
  10228. {
  10229. for (int i = size(); --i >= 0;)
  10230. if (stringToLookFor == strings.getReference(i))
  10231. return true;
  10232. }
  10233. return false;
  10234. }
  10235. int StringArray::indexOf (const String& stringToLookFor, const bool ignoreCase, int i) const
  10236. {
  10237. if (i < 0)
  10238. i = 0;
  10239. const int numElements = size();
  10240. if (ignoreCase)
  10241. {
  10242. while (i < numElements)
  10243. {
  10244. if (strings.getReference(i).equalsIgnoreCase (stringToLookFor))
  10245. return i;
  10246. ++i;
  10247. }
  10248. }
  10249. else
  10250. {
  10251. while (i < numElements)
  10252. {
  10253. if (stringToLookFor == strings.getReference (i))
  10254. return i;
  10255. ++i;
  10256. }
  10257. }
  10258. return -1;
  10259. }
  10260. void StringArray::remove (const int index)
  10261. {
  10262. strings.remove (index);
  10263. }
  10264. void StringArray::removeString (const String& stringToRemove,
  10265. const bool ignoreCase)
  10266. {
  10267. if (ignoreCase)
  10268. {
  10269. for (int i = size(); --i >= 0;)
  10270. if (strings.getReference(i).equalsIgnoreCase (stringToRemove))
  10271. strings.remove (i);
  10272. }
  10273. else
  10274. {
  10275. for (int i = size(); --i >= 0;)
  10276. if (stringToRemove == strings.getReference (i))
  10277. strings.remove (i);
  10278. }
  10279. }
  10280. void StringArray::removeEmptyStrings (const bool removeWhitespaceStrings)
  10281. {
  10282. if (removeWhitespaceStrings)
  10283. {
  10284. for (int i = size(); --i >= 0;)
  10285. if (! strings.getReference(i).containsNonWhitespaceChars())
  10286. strings.remove (i);
  10287. }
  10288. else
  10289. {
  10290. for (int i = size(); --i >= 0;)
  10291. if (strings.getReference(i).isEmpty())
  10292. strings.remove (i);
  10293. }
  10294. }
  10295. void StringArray::trim()
  10296. {
  10297. for (int i = size(); --i >= 0;)
  10298. {
  10299. String& s = strings.getReference(i);
  10300. s = s.trim();
  10301. }
  10302. }
  10303. class InternalStringArrayComparator_CaseSensitive
  10304. {
  10305. public:
  10306. static int compareElements (String& first, String& second) { return first.compare (second); }
  10307. };
  10308. class InternalStringArrayComparator_CaseInsensitive
  10309. {
  10310. public:
  10311. static int compareElements (String& first, String& second) { return first.compareIgnoreCase (second); }
  10312. };
  10313. void StringArray::sort (const bool ignoreCase)
  10314. {
  10315. if (ignoreCase)
  10316. {
  10317. InternalStringArrayComparator_CaseInsensitive comp;
  10318. strings.sort (comp);
  10319. }
  10320. else
  10321. {
  10322. InternalStringArrayComparator_CaseSensitive comp;
  10323. strings.sort (comp);
  10324. }
  10325. }
  10326. void StringArray::move (const int currentIndex, int newIndex) throw()
  10327. {
  10328. strings.move (currentIndex, newIndex);
  10329. }
  10330. const String StringArray::joinIntoString (const String& separator, int start, int numberToJoin) const
  10331. {
  10332. const int last = (numberToJoin < 0) ? size()
  10333. : jmin (size(), start + numberToJoin);
  10334. if (start < 0)
  10335. start = 0;
  10336. if (start >= last)
  10337. return String::empty;
  10338. if (start == last - 1)
  10339. return strings.getReference (start);
  10340. const int separatorLen = separator.length();
  10341. int charsNeeded = separatorLen * (last - start - 1);
  10342. for (int i = start; i < last; ++i)
  10343. charsNeeded += strings.getReference(i).length();
  10344. String result;
  10345. result.preallocateStorage (charsNeeded);
  10346. tchar* dest = (tchar*) (const tchar*) result;
  10347. while (start < last)
  10348. {
  10349. const String& s = strings.getReference (start);
  10350. const int len = s.length();
  10351. if (len > 0)
  10352. {
  10353. s.copyToBuffer (dest, len);
  10354. dest += len;
  10355. }
  10356. if (++start < last && separatorLen > 0)
  10357. {
  10358. separator.copyToBuffer (dest, separatorLen);
  10359. dest += separatorLen;
  10360. }
  10361. }
  10362. *dest = 0;
  10363. return result;
  10364. }
  10365. int StringArray::addTokens (const tchar* const text, const bool preserveQuotedStrings)
  10366. {
  10367. return addTokens (text,
  10368. T(" \n\r\t"),
  10369. preserveQuotedStrings ? T("\"") : 0);
  10370. }
  10371. int StringArray::addTokens (const tchar* const text, const tchar* breakCharacters, const tchar* quoteCharacters)
  10372. {
  10373. int num = 0;
  10374. if (text != 0 && *text != 0)
  10375. {
  10376. if (breakCharacters == 0)
  10377. breakCharacters = T("");
  10378. if (quoteCharacters == 0)
  10379. quoteCharacters = T("");
  10380. bool insideQuotes = false;
  10381. tchar currentQuoteChar = 0;
  10382. int i = 0;
  10383. int tokenStart = 0;
  10384. for (;;)
  10385. {
  10386. const tchar c = text[i];
  10387. bool isBreak = (c == 0);
  10388. if (! (insideQuotes || isBreak))
  10389. {
  10390. const tchar* b = breakCharacters;
  10391. while (*b != 0)
  10392. {
  10393. if (*b++ == c)
  10394. {
  10395. isBreak = true;
  10396. break;
  10397. }
  10398. }
  10399. }
  10400. if (! isBreak)
  10401. {
  10402. bool isQuote = false;
  10403. const tchar* q = quoteCharacters;
  10404. while (*q != 0)
  10405. {
  10406. if (*q++ == c)
  10407. {
  10408. isQuote = true;
  10409. break;
  10410. }
  10411. }
  10412. if (isQuote)
  10413. {
  10414. if (insideQuotes)
  10415. {
  10416. // only break out of quotes-mode if we find a matching quote to the
  10417. // one that we opened with..
  10418. if (currentQuoteChar == c)
  10419. insideQuotes = false;
  10420. }
  10421. else
  10422. {
  10423. insideQuotes = true;
  10424. currentQuoteChar = c;
  10425. }
  10426. }
  10427. }
  10428. else
  10429. {
  10430. add (String (text + tokenStart, i - tokenStart));
  10431. ++num;
  10432. tokenStart = i + 1;
  10433. }
  10434. if (c == 0)
  10435. break;
  10436. ++i;
  10437. }
  10438. }
  10439. return num;
  10440. }
  10441. int StringArray::addLines (const tchar* text)
  10442. {
  10443. int numLines = 0;
  10444. if (text != 0)
  10445. {
  10446. while (*text != 0)
  10447. {
  10448. const tchar* const startOfLine = text;
  10449. while (*text != 0)
  10450. {
  10451. if (*text == T('\r'))
  10452. {
  10453. ++text;
  10454. if (*text == T('\n'))
  10455. ++text;
  10456. break;
  10457. }
  10458. if (*text == T('\n'))
  10459. {
  10460. ++text;
  10461. break;
  10462. }
  10463. ++text;
  10464. }
  10465. const tchar* endOfLine = text;
  10466. if (endOfLine > startOfLine && (*(endOfLine - 1) == T('\r') || *(endOfLine - 1) == T('\n')))
  10467. --endOfLine;
  10468. if (endOfLine > startOfLine && (*(endOfLine - 1) == T('\r') || *(endOfLine - 1) == T('\n')))
  10469. --endOfLine;
  10470. add (String (startOfLine, jmax (0, (int) (endOfLine - startOfLine))));
  10471. ++numLines;
  10472. }
  10473. }
  10474. return numLines;
  10475. }
  10476. void StringArray::removeDuplicates (const bool ignoreCase)
  10477. {
  10478. for (int i = 0; i < size() - 1; ++i)
  10479. {
  10480. const String s (strings.getReference(i));
  10481. int nextIndex = i + 1;
  10482. for (;;)
  10483. {
  10484. nextIndex = indexOf (s, ignoreCase, nextIndex);
  10485. if (nextIndex < 0)
  10486. break;
  10487. strings.remove (nextIndex);
  10488. }
  10489. }
  10490. }
  10491. void StringArray::appendNumbersToDuplicates (const bool ignoreCase,
  10492. const bool appendNumberToFirstInstance,
  10493. const tchar* const preNumberString,
  10494. const tchar* const postNumberString)
  10495. {
  10496. for (int i = 0; i < size() - 1; ++i)
  10497. {
  10498. String& s = strings.getReference(i);
  10499. int nextIndex = indexOf (s, ignoreCase, i + 1);
  10500. if (nextIndex >= 0)
  10501. {
  10502. const String original (s);
  10503. int number = 0;
  10504. if (appendNumberToFirstInstance)
  10505. s = original + preNumberString + String (++number) + postNumberString;
  10506. else
  10507. ++number;
  10508. while (nextIndex >= 0)
  10509. {
  10510. set (nextIndex, (*this)[nextIndex] + preNumberString + String (++number) + postNumberString);
  10511. nextIndex = indexOf (original, ignoreCase, nextIndex + 1);
  10512. }
  10513. }
  10514. }
  10515. }
  10516. void StringArray::minimiseStorageOverheads()
  10517. {
  10518. strings.minimiseStorageOverheads();
  10519. }
  10520. END_JUCE_NAMESPACE
  10521. /*** End of inlined file: juce_StringArray.cpp ***/
  10522. /*** Start of inlined file: juce_StringPairArray.cpp ***/
  10523. BEGIN_JUCE_NAMESPACE
  10524. StringPairArray::StringPairArray (const bool ignoreCase_) throw()
  10525. : ignoreCase (ignoreCase_)
  10526. {
  10527. }
  10528. StringPairArray::StringPairArray (const StringPairArray& other) throw()
  10529. : keys (other.keys),
  10530. values (other.values),
  10531. ignoreCase (other.ignoreCase)
  10532. {
  10533. }
  10534. StringPairArray::~StringPairArray() throw()
  10535. {
  10536. }
  10537. const StringPairArray& StringPairArray::operator= (const StringPairArray& other) throw()
  10538. {
  10539. keys = other.keys;
  10540. values = other.values;
  10541. return *this;
  10542. }
  10543. bool StringPairArray::operator== (const StringPairArray& other) const throw()
  10544. {
  10545. for (int i = keys.size(); --i >= 0;)
  10546. if (other [keys[i]] != values[i])
  10547. return false;
  10548. return true;
  10549. }
  10550. bool StringPairArray::operator!= (const StringPairArray& other) const throw()
  10551. {
  10552. return ! operator== (other);
  10553. }
  10554. const String& StringPairArray::operator[] (const String& key) const throw()
  10555. {
  10556. return values [keys.indexOf (key, ignoreCase)];
  10557. }
  10558. const String StringPairArray::getValue (const String& key, const String& defaultReturnValue) const
  10559. {
  10560. const int i = keys.indexOf (key, ignoreCase);
  10561. if (i >= 0)
  10562. return values[i];
  10563. return defaultReturnValue;
  10564. }
  10565. void StringPairArray::set (const String& key,
  10566. const String& value) throw()
  10567. {
  10568. const int i = keys.indexOf (key, ignoreCase);
  10569. if (i >= 0)
  10570. {
  10571. values.set (i, value);
  10572. }
  10573. else
  10574. {
  10575. keys.add (key);
  10576. values.add (value);
  10577. }
  10578. }
  10579. void StringPairArray::addArray (const StringPairArray& other)
  10580. {
  10581. for (int i = 0; i < other.size(); ++i)
  10582. set (other.keys[i], other.values[i]);
  10583. }
  10584. void StringPairArray::clear() throw()
  10585. {
  10586. keys.clear();
  10587. values.clear();
  10588. }
  10589. void StringPairArray::remove (const String& key) throw()
  10590. {
  10591. remove (keys.indexOf (key, ignoreCase));
  10592. }
  10593. void StringPairArray::remove (const int index) throw()
  10594. {
  10595. keys.remove (index);
  10596. values.remove (index);
  10597. }
  10598. void StringPairArray::setIgnoresCase (const bool shouldIgnoreCase) throw()
  10599. {
  10600. ignoreCase = shouldIgnoreCase;
  10601. }
  10602. const String StringPairArray::getDescription() const
  10603. {
  10604. String s;
  10605. for (int i = 0; i < keys.size(); ++i)
  10606. {
  10607. s << keys[i] << T(" = ") << values[i];
  10608. if (i < keys.size())
  10609. s << T(", ");
  10610. }
  10611. return s;
  10612. }
  10613. void StringPairArray::minimiseStorageOverheads() throw()
  10614. {
  10615. keys.minimiseStorageOverheads();
  10616. values.minimiseStorageOverheads();
  10617. }
  10618. END_JUCE_NAMESPACE
  10619. /*** End of inlined file: juce_StringPairArray.cpp ***/
  10620. /*** Start of inlined file: juce_XmlDocument.cpp ***/
  10621. BEGIN_JUCE_NAMESPACE
  10622. XmlDocument::XmlDocument (const String& documentText) throw()
  10623. : originalText (documentText),
  10624. ignoreEmptyTextElements (true)
  10625. {
  10626. }
  10627. XmlDocument::XmlDocument (const File& file)
  10628. {
  10629. inputSource = new FileInputSource (file);
  10630. }
  10631. XmlDocument::~XmlDocument() throw()
  10632. {
  10633. }
  10634. void XmlDocument::setInputSource (InputSource* const newSource) throw()
  10635. {
  10636. inputSource = newSource;
  10637. }
  10638. void XmlDocument::setEmptyTextElementsIgnored (const bool shouldBeIgnored) throw()
  10639. {
  10640. ignoreEmptyTextElements = shouldBeIgnored;
  10641. }
  10642. bool XmlDocument::isXmlIdentifierCharSlow (const tchar c) throw()
  10643. {
  10644. return CharacterFunctions::isLetterOrDigit (c)
  10645. || c == T('_')
  10646. || c == T('-')
  10647. || c == T(':')
  10648. || c == T('.');
  10649. }
  10650. inline bool XmlDocument::isXmlIdentifierChar (const tchar c) const throw()
  10651. {
  10652. return (c > 0 && c <= 127) ? identifierLookupTable [(int) c]
  10653. : isXmlIdentifierCharSlow (c);
  10654. }
  10655. XmlElement* XmlDocument::getDocumentElement (const bool onlyReadOuterDocumentElement)
  10656. {
  10657. String textToParse (originalText);
  10658. if (textToParse.isEmpty() && inputSource != 0)
  10659. {
  10660. ScopedPointer <InputStream> in (inputSource->createInputStream());
  10661. if (in != 0)
  10662. {
  10663. MemoryBlock data;
  10664. in->readIntoMemoryBlock (data, onlyReadOuterDocumentElement ? 8192 : -1);
  10665. if (data.getSize() >= 2
  10666. && ((data[0] == (char)-2 && data[1] == (char)-1)
  10667. || (data[0] == (char)-1 && data[1] == (char)-2)))
  10668. {
  10669. textToParse = String::createStringFromData ((const char*) data.getData(), (int) data.getSize());
  10670. }
  10671. else
  10672. {
  10673. textToParse = String::fromUTF8 ((const uint8*) data.getData(), (int) data.getSize());
  10674. }
  10675. if (! onlyReadOuterDocumentElement)
  10676. originalText = textToParse;
  10677. }
  10678. }
  10679. input = textToParse;
  10680. lastError = String::empty;
  10681. errorOccurred = false;
  10682. outOfData = false;
  10683. needToLoadDTD = true;
  10684. for (int i = 0; i < 128; ++i)
  10685. identifierLookupTable[i] = isXmlIdentifierCharSlow ((tchar) i);
  10686. if (textToParse.isEmpty())
  10687. {
  10688. lastError = "not enough input";
  10689. }
  10690. else
  10691. {
  10692. skipHeader();
  10693. if (input != 0)
  10694. {
  10695. ScopedPointer <XmlElement> result (readNextElement (! onlyReadOuterDocumentElement));
  10696. if (! errorOccurred)
  10697. return result.release();
  10698. }
  10699. else
  10700. {
  10701. lastError = "incorrect xml header";
  10702. }
  10703. }
  10704. return 0;
  10705. }
  10706. const String& XmlDocument::getLastParseError() const throw()
  10707. {
  10708. return lastError;
  10709. }
  10710. void XmlDocument::setLastError (const String& desc, const bool carryOn) throw()
  10711. {
  10712. lastError = desc;
  10713. errorOccurred = ! carryOn;
  10714. }
  10715. const String XmlDocument::getFileContents (const String& filename) const
  10716. {
  10717. if (inputSource != 0)
  10718. {
  10719. const ScopedPointer <InputStream> in (inputSource->createInputStreamFor (filename.trim().unquoted()));
  10720. if (in != 0)
  10721. return in->readEntireStreamAsString();
  10722. }
  10723. return String::empty;
  10724. }
  10725. tchar XmlDocument::readNextChar() throw()
  10726. {
  10727. if (*input != 0)
  10728. {
  10729. return *input++;
  10730. }
  10731. else
  10732. {
  10733. outOfData = true;
  10734. return 0;
  10735. }
  10736. }
  10737. int XmlDocument::findNextTokenLength() throw()
  10738. {
  10739. int len = 0;
  10740. tchar c = *input;
  10741. while (isXmlIdentifierChar (c))
  10742. c = input [++len];
  10743. return len;
  10744. }
  10745. void XmlDocument::skipHeader() throw()
  10746. {
  10747. const tchar* const found = CharacterFunctions::find (input, T("<?xml"));
  10748. if (found != 0)
  10749. {
  10750. input = found;
  10751. input = CharacterFunctions::find (input, T("?>"));
  10752. if (input == 0)
  10753. return;
  10754. input += 2;
  10755. }
  10756. skipNextWhiteSpace();
  10757. const tchar* docType = CharacterFunctions::find (input, T("<!DOCTYPE"));
  10758. if (docType == 0)
  10759. return;
  10760. input = docType + 9;
  10761. int n = 1;
  10762. while (n > 0)
  10763. {
  10764. const tchar c = readNextChar();
  10765. if (outOfData)
  10766. return;
  10767. if (c == T('<'))
  10768. ++n;
  10769. else if (c == T('>'))
  10770. --n;
  10771. }
  10772. docType += 9;
  10773. dtdText = String (docType, (int) (input - (docType + 1))).trim();
  10774. }
  10775. void XmlDocument::skipNextWhiteSpace() throw()
  10776. {
  10777. for (;;)
  10778. {
  10779. tchar c = *input;
  10780. while (CharacterFunctions::isWhitespace (c))
  10781. c = *++input;
  10782. if (c == 0)
  10783. {
  10784. outOfData = true;
  10785. break;
  10786. }
  10787. else if (c == T('<'))
  10788. {
  10789. if (input[1] == T('!')
  10790. && input[2] == T('-')
  10791. && input[3] == T('-'))
  10792. {
  10793. const tchar* const closeComment = CharacterFunctions::find (input, T("-->"));
  10794. if (closeComment == 0)
  10795. {
  10796. outOfData = true;
  10797. break;
  10798. }
  10799. input = closeComment + 3;
  10800. continue;
  10801. }
  10802. else if (input[1] == T('?'))
  10803. {
  10804. const tchar* const closeBracket = CharacterFunctions::find (input, T("?>"));
  10805. if (closeBracket == 0)
  10806. {
  10807. outOfData = true;
  10808. break;
  10809. }
  10810. input = closeBracket + 2;
  10811. continue;
  10812. }
  10813. }
  10814. break;
  10815. }
  10816. }
  10817. void XmlDocument::readQuotedString (String& result) throw()
  10818. {
  10819. const tchar quote = readNextChar();
  10820. while (! outOfData)
  10821. {
  10822. const tchar c = readNextChar();
  10823. if (c == quote)
  10824. break;
  10825. if (c == T('&'))
  10826. {
  10827. --input;
  10828. readEntity (result);
  10829. }
  10830. else
  10831. {
  10832. --input;
  10833. const tchar* const start = input;
  10834. for (;;)
  10835. {
  10836. const tchar character = *input;
  10837. if (character == quote)
  10838. {
  10839. result.append (start, (int) (input - start));
  10840. ++input;
  10841. return;
  10842. }
  10843. else if (character == T('&'))
  10844. {
  10845. result.append (start, (int) (input - start));
  10846. break;
  10847. }
  10848. else if (character == 0)
  10849. {
  10850. outOfData = true;
  10851. setLastError ("unmatched quotes", false);
  10852. break;
  10853. }
  10854. ++input;
  10855. }
  10856. }
  10857. }
  10858. }
  10859. XmlElement* XmlDocument::readNextElement (const bool alsoParseSubElements) throw()
  10860. {
  10861. XmlElement* node = 0;
  10862. skipNextWhiteSpace();
  10863. if (outOfData)
  10864. return 0;
  10865. input = CharacterFunctions::find (input, T("<"));
  10866. if (input != 0)
  10867. {
  10868. ++input;
  10869. int tagLen = findNextTokenLength();
  10870. if (tagLen == 0)
  10871. {
  10872. // no tag name - but allow for a gap after the '<' before giving an error
  10873. skipNextWhiteSpace();
  10874. tagLen = findNextTokenLength();
  10875. if (tagLen == 0)
  10876. {
  10877. setLastError ("tag name missing", false);
  10878. return node;
  10879. }
  10880. }
  10881. node = new XmlElement (String (input, tagLen));
  10882. input += tagLen;
  10883. XmlElement::XmlAttributeNode* lastAttribute = 0;
  10884. // look for attributes
  10885. for (;;)
  10886. {
  10887. skipNextWhiteSpace();
  10888. const tchar c = *input;
  10889. // empty tag..
  10890. if (c == T('/') && input[1] == T('>'))
  10891. {
  10892. input += 2;
  10893. break;
  10894. }
  10895. // parse the guts of the element..
  10896. if (c == T('>'))
  10897. {
  10898. ++input;
  10899. skipNextWhiteSpace();
  10900. if (alsoParseSubElements)
  10901. readChildElements (node);
  10902. break;
  10903. }
  10904. // get an attribute..
  10905. if (isXmlIdentifierChar (c))
  10906. {
  10907. const int attNameLen = findNextTokenLength();
  10908. if (attNameLen > 0)
  10909. {
  10910. const tchar* attNameStart = input;
  10911. input += attNameLen;
  10912. skipNextWhiteSpace();
  10913. if (readNextChar() == T('='))
  10914. {
  10915. skipNextWhiteSpace();
  10916. const tchar nextChar = *input;
  10917. if (nextChar == T('"') || nextChar == T('\''))
  10918. {
  10919. XmlElement::XmlAttributeNode* const newAtt
  10920. = new XmlElement::XmlAttributeNode (String (attNameStart, attNameLen),
  10921. String::empty);
  10922. readQuotedString (newAtt->value);
  10923. if (lastAttribute == 0)
  10924. node->attributes = newAtt;
  10925. else
  10926. lastAttribute->next = newAtt;
  10927. lastAttribute = newAtt;
  10928. continue;
  10929. }
  10930. }
  10931. }
  10932. }
  10933. else
  10934. {
  10935. if (! outOfData)
  10936. setLastError ("illegal character found in " + node->getTagName() + ": '" + c + "'", false);
  10937. }
  10938. break;
  10939. }
  10940. }
  10941. return node;
  10942. }
  10943. void XmlDocument::readChildElements (XmlElement* parent) throw()
  10944. {
  10945. XmlElement* lastChildNode = 0;
  10946. for (;;)
  10947. {
  10948. skipNextWhiteSpace();
  10949. if (outOfData)
  10950. {
  10951. setLastError ("unmatched tags", false);
  10952. break;
  10953. }
  10954. if (*input == T('<'))
  10955. {
  10956. if (input[1] == T('/'))
  10957. {
  10958. // our close tag..
  10959. input = CharacterFunctions::find (input, T(">"));
  10960. ++input;
  10961. break;
  10962. }
  10963. else if (input[1] == T('!')
  10964. && input[2] == T('[')
  10965. && input[3] == T('C')
  10966. && input[4] == T('D')
  10967. && input[5] == T('A')
  10968. && input[6] == T('T')
  10969. && input[7] == T('A')
  10970. && input[8] == T('['))
  10971. {
  10972. input += 9;
  10973. const tchar* const inputStart = input;
  10974. int len = 0;
  10975. for (;;)
  10976. {
  10977. if (*input == 0)
  10978. {
  10979. setLastError ("unterminated CDATA section", false);
  10980. outOfData = true;
  10981. break;
  10982. }
  10983. else if (input[0] == T(']')
  10984. && input[1] == T(']')
  10985. && input[2] == T('>'))
  10986. {
  10987. input += 3;
  10988. break;
  10989. }
  10990. ++input;
  10991. ++len;
  10992. }
  10993. XmlElement* const e = new XmlElement ((int) 0);
  10994. e->setText (String (inputStart, len));
  10995. if (lastChildNode != 0)
  10996. lastChildNode->nextElement = e;
  10997. else
  10998. parent->addChildElement (e);
  10999. lastChildNode = e;
  11000. }
  11001. else
  11002. {
  11003. // this is some other element, so parse and add it..
  11004. XmlElement* const n = readNextElement (true);
  11005. if (n != 0)
  11006. {
  11007. if (lastChildNode == 0)
  11008. parent->addChildElement (n);
  11009. else
  11010. lastChildNode->nextElement = n;
  11011. lastChildNode = n;
  11012. }
  11013. else
  11014. {
  11015. return;
  11016. }
  11017. }
  11018. }
  11019. else
  11020. {
  11021. // read character block..
  11022. XmlElement* const e = new XmlElement ((int)0);
  11023. if (lastChildNode != 0)
  11024. lastChildNode->nextElement = e;
  11025. else
  11026. parent->addChildElement (e);
  11027. lastChildNode = e;
  11028. String textElementContent;
  11029. for (;;)
  11030. {
  11031. const tchar c = *input;
  11032. if (c == T('<'))
  11033. break;
  11034. if (c == 0)
  11035. {
  11036. setLastError ("unmatched tags", false);
  11037. outOfData = true;
  11038. return;
  11039. }
  11040. if (c == T('&'))
  11041. {
  11042. String entity;
  11043. readEntity (entity);
  11044. if (entity.startsWithChar (T('<')) && entity [1] != 0)
  11045. {
  11046. const tchar* const oldInput = input;
  11047. const bool oldOutOfData = outOfData;
  11048. input = (const tchar*) entity;
  11049. outOfData = false;
  11050. for (;;)
  11051. {
  11052. XmlElement* const n = readNextElement (true);
  11053. if (n == 0)
  11054. break;
  11055. if (lastChildNode == 0)
  11056. parent->addChildElement (n);
  11057. else
  11058. lastChildNode->nextElement = n;
  11059. lastChildNode = n;
  11060. }
  11061. input = oldInput;
  11062. outOfData = oldOutOfData;
  11063. }
  11064. else
  11065. {
  11066. textElementContent += entity;
  11067. }
  11068. }
  11069. else
  11070. {
  11071. const tchar* start = input;
  11072. int len = 0;
  11073. for (;;)
  11074. {
  11075. const tchar nextChar = *input;
  11076. if (nextChar == T('<') || nextChar == T('&'))
  11077. {
  11078. break;
  11079. }
  11080. else if (nextChar == 0)
  11081. {
  11082. setLastError ("unmatched tags", false);
  11083. outOfData = true;
  11084. return;
  11085. }
  11086. ++input;
  11087. ++len;
  11088. }
  11089. textElementContent.append (start, len);
  11090. }
  11091. }
  11092. if (ignoreEmptyTextElements ? textElementContent.containsNonWhitespaceChars()
  11093. : textElementContent.isNotEmpty())
  11094. e->setText (textElementContent);
  11095. }
  11096. }
  11097. }
  11098. void XmlDocument::readEntity (String& result) throw()
  11099. {
  11100. // skip over the ampersand
  11101. ++input;
  11102. if (CharacterFunctions::compareIgnoreCase (input, T("amp;"), 4) == 0)
  11103. {
  11104. input += 4;
  11105. result += T("&");
  11106. }
  11107. else if (CharacterFunctions::compareIgnoreCase (input, T("quot;"), 5) == 0)
  11108. {
  11109. input += 5;
  11110. result += T("\"");
  11111. }
  11112. else if (CharacterFunctions::compareIgnoreCase (input, T("apos;"), 5) == 0)
  11113. {
  11114. input += 5;
  11115. result += T("\'");
  11116. }
  11117. else if (CharacterFunctions::compareIgnoreCase (input, T("lt;"), 3) == 0)
  11118. {
  11119. input += 3;
  11120. result += T("<");
  11121. }
  11122. else if (CharacterFunctions::compareIgnoreCase (input, T("gt;"), 3) == 0)
  11123. {
  11124. input += 3;
  11125. result += T(">");
  11126. }
  11127. else if (*input == T('#'))
  11128. {
  11129. int charCode = 0;
  11130. ++input;
  11131. if (*input == T('x') || *input == T('X'))
  11132. {
  11133. ++input;
  11134. int numChars = 0;
  11135. while (input[0] != T(';'))
  11136. {
  11137. const int hexValue = CharacterFunctions::getHexDigitValue (input[0]);
  11138. if (hexValue < 0 || ++numChars > 8)
  11139. {
  11140. setLastError ("illegal escape sequence", true);
  11141. break;
  11142. }
  11143. charCode = (charCode << 4) | hexValue;
  11144. ++input;
  11145. }
  11146. ++input;
  11147. }
  11148. else if (input[0] >= T('0') && input[0] <= T('9'))
  11149. {
  11150. int numChars = 0;
  11151. while (input[0] != T(';'))
  11152. {
  11153. if (++numChars > 12)
  11154. {
  11155. setLastError ("illegal escape sequence", true);
  11156. break;
  11157. }
  11158. charCode = charCode * 10 + (input[0] - T('0'));
  11159. ++input;
  11160. }
  11161. ++input;
  11162. }
  11163. else
  11164. {
  11165. setLastError ("illegal escape sequence", true);
  11166. result += T("&");
  11167. return;
  11168. }
  11169. result << (tchar) charCode;
  11170. }
  11171. else
  11172. {
  11173. const tchar* const entityNameStart = input;
  11174. const tchar* const closingSemiColon = CharacterFunctions::find (input, T(";"));
  11175. if (closingSemiColon == 0)
  11176. {
  11177. outOfData = true;
  11178. result += T("&");
  11179. }
  11180. else
  11181. {
  11182. input = closingSemiColon + 1;
  11183. result += expandExternalEntity (String (entityNameStart,
  11184. (int) (closingSemiColon - entityNameStart)));
  11185. }
  11186. }
  11187. }
  11188. const String XmlDocument::expandEntity (const String& ent)
  11189. {
  11190. if (ent.equalsIgnoreCase (T("amp")))
  11191. {
  11192. return T("&");
  11193. }
  11194. else if (ent.equalsIgnoreCase (T("quot")))
  11195. {
  11196. return T("\"");
  11197. }
  11198. else if (ent.equalsIgnoreCase (T("apos")))
  11199. {
  11200. return T("\'");
  11201. }
  11202. else if (ent.equalsIgnoreCase (T("lt")))
  11203. {
  11204. return T("<");
  11205. }
  11206. else if (ent.equalsIgnoreCase (T("gt")))
  11207. {
  11208. return T(">");
  11209. }
  11210. else if (ent[0] == T('#'))
  11211. {
  11212. if (ent[1] == T('x') || ent[1] == T('X'))
  11213. {
  11214. return String::charToString ((tchar) ent.substring (2).getHexValue32());
  11215. }
  11216. else if (ent[1] >= T('0') && ent[1] <= T('9'))
  11217. {
  11218. return String::charToString ((tchar) ent.substring (1).getIntValue());
  11219. }
  11220. setLastError ("illegal escape sequence", false);
  11221. return T("&");
  11222. }
  11223. else
  11224. {
  11225. return expandExternalEntity (ent);
  11226. }
  11227. }
  11228. const String XmlDocument::expandExternalEntity (const String& entity)
  11229. {
  11230. if (needToLoadDTD)
  11231. {
  11232. if (dtdText.isNotEmpty())
  11233. {
  11234. while (dtdText.endsWithChar (T('>')))
  11235. dtdText = dtdText.dropLastCharacters (1);
  11236. tokenisedDTD.addTokens (dtdText, true);
  11237. if (tokenisedDTD [tokenisedDTD.size() - 2].equalsIgnoreCase (T("system"))
  11238. && tokenisedDTD [tokenisedDTD.size() - 1].isQuotedString())
  11239. {
  11240. const String fn (tokenisedDTD [tokenisedDTD.size() - 1]);
  11241. tokenisedDTD.clear();
  11242. tokenisedDTD.addTokens (getFileContents (fn), true);
  11243. }
  11244. else
  11245. {
  11246. tokenisedDTD.clear();
  11247. const int openBracket = dtdText.indexOfChar (T('['));
  11248. if (openBracket > 0)
  11249. {
  11250. const int closeBracket = dtdText.lastIndexOfChar (T(']'));
  11251. if (closeBracket > openBracket)
  11252. tokenisedDTD.addTokens (dtdText.substring (openBracket + 1,
  11253. closeBracket), true);
  11254. }
  11255. }
  11256. for (int i = tokenisedDTD.size(); --i >= 0;)
  11257. {
  11258. if (tokenisedDTD[i].startsWithChar (T('%'))
  11259. && tokenisedDTD[i].endsWithChar (T(';')))
  11260. {
  11261. const String parsed (getParameterEntity (tokenisedDTD[i].substring (1, tokenisedDTD[i].length() - 1)));
  11262. StringArray newToks;
  11263. newToks.addTokens (parsed, true);
  11264. tokenisedDTD.remove (i);
  11265. for (int j = newToks.size(); --j >= 0;)
  11266. tokenisedDTD.insert (i, newToks[j]);
  11267. }
  11268. }
  11269. }
  11270. needToLoadDTD = false;
  11271. }
  11272. for (int i = 0; i < tokenisedDTD.size(); ++i)
  11273. {
  11274. if (tokenisedDTD[i] == entity)
  11275. {
  11276. if (tokenisedDTD[i - 1].equalsIgnoreCase (T("<!entity")))
  11277. {
  11278. String ent (tokenisedDTD [i + 1]);
  11279. while (ent.endsWithChar (T('>')))
  11280. ent = ent.dropLastCharacters (1);
  11281. ent = ent.trim().unquoted();
  11282. // check for sub-entities..
  11283. int ampersand = ent.indexOfChar (T('&'));
  11284. while (ampersand >= 0)
  11285. {
  11286. const int semiColon = ent.indexOf (i + 1, T(";"));
  11287. if (semiColon < 0)
  11288. {
  11289. setLastError ("entity without terminating semi-colon", false);
  11290. break;
  11291. }
  11292. const String resolved (expandEntity (ent.substring (i + 1, semiColon)));
  11293. ent = ent.substring (0, ampersand)
  11294. + resolved
  11295. + ent.substring (semiColon + 1);
  11296. ampersand = ent.indexOfChar (semiColon + 1, T('&'));
  11297. }
  11298. return ent;
  11299. }
  11300. }
  11301. }
  11302. setLastError ("unknown entity", true);
  11303. return entity;
  11304. }
  11305. const String XmlDocument::getParameterEntity (const String& entity)
  11306. {
  11307. for (int i = 0; i < tokenisedDTD.size(); ++i)
  11308. {
  11309. if (tokenisedDTD[i] == entity)
  11310. {
  11311. if (tokenisedDTD [i - 1] == T("%")
  11312. && tokenisedDTD [i - 2].equalsIgnoreCase (T("<!entity")))
  11313. {
  11314. String ent (tokenisedDTD [i + 1]);
  11315. while (ent.endsWithChar (T('>')))
  11316. ent = ent.dropLastCharacters (1);
  11317. if (ent.equalsIgnoreCase (T("system")))
  11318. {
  11319. String filename (tokenisedDTD [i + 2]);
  11320. while (filename.endsWithChar (T('>')))
  11321. filename = filename.dropLastCharacters (1);
  11322. return getFileContents (filename);
  11323. }
  11324. else
  11325. {
  11326. return ent.trim().unquoted();
  11327. }
  11328. }
  11329. }
  11330. }
  11331. return entity;
  11332. }
  11333. END_JUCE_NAMESPACE
  11334. /*** End of inlined file: juce_XmlDocument.cpp ***/
  11335. /*** Start of inlined file: juce_XmlElement.cpp ***/
  11336. BEGIN_JUCE_NAMESPACE
  11337. XmlElement::XmlAttributeNode::XmlAttributeNode (const XmlAttributeNode& other) throw()
  11338. : name (other.name),
  11339. value (other.value),
  11340. next (0)
  11341. {
  11342. }
  11343. XmlElement::XmlAttributeNode::XmlAttributeNode (const String& name_,
  11344. const String& value_) throw()
  11345. : name (name_),
  11346. value (value_),
  11347. next (0)
  11348. {
  11349. }
  11350. XmlElement::XmlElement (const String& tagName_) throw()
  11351. : tagName (tagName_),
  11352. firstChildElement (0),
  11353. nextElement (0),
  11354. attributes (0)
  11355. {
  11356. // the tag name mustn't be empty, or it'll look like a text element!
  11357. jassert (tagName_.containsNonWhitespaceChars())
  11358. }
  11359. XmlElement::XmlElement (int /*dummy*/) throw()
  11360. : firstChildElement (0),
  11361. nextElement (0),
  11362. attributes (0)
  11363. {
  11364. }
  11365. XmlElement::XmlElement (const XmlElement& other) throw()
  11366. : tagName (other.tagName),
  11367. firstChildElement (0),
  11368. nextElement (0),
  11369. attributes (0)
  11370. {
  11371. copyChildrenAndAttributesFrom (other);
  11372. }
  11373. const XmlElement& XmlElement::operator= (const XmlElement& other) throw()
  11374. {
  11375. if (this != &other)
  11376. {
  11377. removeAllAttributes();
  11378. deleteAllChildElements();
  11379. tagName = other.tagName;
  11380. copyChildrenAndAttributesFrom (other);
  11381. }
  11382. return *this;
  11383. }
  11384. void XmlElement::copyChildrenAndAttributesFrom (const XmlElement& other) throw()
  11385. {
  11386. XmlElement* child = other.firstChildElement;
  11387. XmlElement* lastChild = 0;
  11388. while (child != 0)
  11389. {
  11390. XmlElement* const copiedChild = new XmlElement (*child);
  11391. if (lastChild != 0)
  11392. lastChild->nextElement = copiedChild;
  11393. else
  11394. firstChildElement = copiedChild;
  11395. lastChild = copiedChild;
  11396. child = child->nextElement;
  11397. }
  11398. const XmlAttributeNode* att = other.attributes;
  11399. XmlAttributeNode* lastAtt = 0;
  11400. while (att != 0)
  11401. {
  11402. XmlAttributeNode* const newAtt = new XmlAttributeNode (*att);
  11403. if (lastAtt != 0)
  11404. lastAtt->next = newAtt;
  11405. else
  11406. attributes = newAtt;
  11407. lastAtt = newAtt;
  11408. att = att->next;
  11409. }
  11410. }
  11411. XmlElement::~XmlElement() throw()
  11412. {
  11413. XmlElement* child = firstChildElement;
  11414. while (child != 0)
  11415. {
  11416. XmlElement* const nextChild = child->nextElement;
  11417. delete child;
  11418. child = nextChild;
  11419. }
  11420. XmlAttributeNode* att = attributes;
  11421. while (att != 0)
  11422. {
  11423. XmlAttributeNode* const nextAtt = att->next;
  11424. delete att;
  11425. att = nextAtt;
  11426. }
  11427. }
  11428. static bool isLegalXmlChar (const juce_wchar character)
  11429. {
  11430. if ((character >= 'a' && character <= 'z')
  11431. || (character >= 'A' && character <= 'Z')
  11432. || (character >= '0' && character <= '9'))
  11433. return true;
  11434. const char* t = " .,;:-()_+=?!'#@[]/\\*%~{}";
  11435. do
  11436. {
  11437. if (((juce_wchar) (uint8) *t) == character)
  11438. return true;
  11439. }
  11440. while (*++t != 0);
  11441. return false;
  11442. }
  11443. static void escapeIllegalXmlChars (OutputStream& outputStream,
  11444. const String& text,
  11445. const bool changeNewLines) throw()
  11446. {
  11447. const juce_wchar* t = (const juce_wchar*) text;
  11448. for (;;)
  11449. {
  11450. const juce_wchar character = *t++;
  11451. if (character == 0)
  11452. {
  11453. break;
  11454. }
  11455. else if (isLegalXmlChar (character))
  11456. {
  11457. outputStream.writeByte ((char) character);
  11458. }
  11459. else
  11460. {
  11461. switch (character)
  11462. {
  11463. case '&':
  11464. outputStream.write ("&amp;", 5);
  11465. break;
  11466. case '"':
  11467. outputStream.write ("&quot;", 6);
  11468. break;
  11469. case '>':
  11470. outputStream.write ("&gt;", 4);
  11471. break;
  11472. case '<':
  11473. outputStream.write ("&lt;", 4);
  11474. break;
  11475. case '\n':
  11476. if (changeNewLines)
  11477. outputStream.write ("&#10;", 5);
  11478. else
  11479. outputStream.writeByte ((char) character);
  11480. break;
  11481. case '\r':
  11482. if (changeNewLines)
  11483. outputStream.write ("&#13;", 5);
  11484. else
  11485. outputStream.writeByte ((char) character);
  11486. break;
  11487. default:
  11488. {
  11489. String encoded (T("&#"));
  11490. encoded << String ((int) (unsigned int) character).trim()
  11491. << T(';');
  11492. outputStream.write ((const char*) encoded, encoded.length());
  11493. }
  11494. }
  11495. }
  11496. }
  11497. }
  11498. static void writeSpaces (OutputStream& out, int numSpaces) throw()
  11499. {
  11500. if (numSpaces > 0)
  11501. {
  11502. const char* const blanks = " ";
  11503. const int blankSize = (int) sizeof (blanks) - 1;
  11504. while (numSpaces > blankSize)
  11505. {
  11506. out.write (blanks, blankSize);
  11507. numSpaces -= blankSize;
  11508. }
  11509. out.write (blanks, numSpaces);
  11510. }
  11511. }
  11512. void XmlElement::writeElementAsText (OutputStream& outputStream,
  11513. const int indentationLevel,
  11514. const int lineWrapLength) const throw()
  11515. {
  11516. writeSpaces (outputStream, indentationLevel);
  11517. if (! isTextElement())
  11518. {
  11519. outputStream.writeByte ('<');
  11520. const int nameLen = tagName.length();
  11521. outputStream.write ((const char*) tagName, nameLen);
  11522. const int attIndent = indentationLevel + nameLen + 1;
  11523. int lineLen = 0;
  11524. const XmlAttributeNode* att = attributes;
  11525. while (att != 0)
  11526. {
  11527. if (lineLen > lineWrapLength && indentationLevel >= 0)
  11528. {
  11529. outputStream.write ("\r\n", 2);
  11530. writeSpaces (outputStream, attIndent);
  11531. lineLen = 0;
  11532. }
  11533. const int attNameLen = att->name.length();
  11534. outputStream.writeByte (' ');
  11535. outputStream.write ((const char*) (att->name), attNameLen);
  11536. outputStream.write ("=\"", 2);
  11537. escapeIllegalXmlChars (outputStream, att->value, true);
  11538. outputStream.writeByte ('"');
  11539. lineLen += 4 + attNameLen + att->value.length();
  11540. att = att->next;
  11541. }
  11542. if (firstChildElement != 0)
  11543. {
  11544. XmlElement* child = firstChildElement;
  11545. if (child->nextElement == 0 && child->isTextElement())
  11546. {
  11547. outputStream.writeByte ('>');
  11548. escapeIllegalXmlChars (outputStream, child->getText(), false);
  11549. }
  11550. else
  11551. {
  11552. if (indentationLevel >= 0)
  11553. outputStream.write (">\r\n", 3);
  11554. else
  11555. outputStream.writeByte ('>');
  11556. bool lastWasTextNode = false;
  11557. while (child != 0)
  11558. {
  11559. if (child->isTextElement())
  11560. {
  11561. if ((! lastWasTextNode) && (indentationLevel >= 0))
  11562. writeSpaces (outputStream, indentationLevel + 2);
  11563. escapeIllegalXmlChars (outputStream, child->getText(), false);
  11564. lastWasTextNode = true;
  11565. }
  11566. else
  11567. {
  11568. if (indentationLevel >= 0)
  11569. {
  11570. if (lastWasTextNode)
  11571. outputStream.write ("\r\n", 2);
  11572. child->writeElementAsText (outputStream, indentationLevel + 2, lineWrapLength);
  11573. }
  11574. else
  11575. {
  11576. child->writeElementAsText (outputStream, indentationLevel, lineWrapLength);
  11577. }
  11578. lastWasTextNode = false;
  11579. }
  11580. child = child->nextElement;
  11581. }
  11582. if (indentationLevel >= 0)
  11583. {
  11584. if (lastWasTextNode)
  11585. outputStream.write ("\r\n", 2);
  11586. writeSpaces (outputStream, indentationLevel);
  11587. }
  11588. }
  11589. outputStream.write ("</", 2);
  11590. outputStream.write ((const char*) tagName, nameLen);
  11591. if (indentationLevel >= 0)
  11592. outputStream.write (">\r\n", 3);
  11593. else
  11594. outputStream.writeByte ('>');
  11595. }
  11596. else
  11597. {
  11598. if (indentationLevel >= 0)
  11599. outputStream.write ("/>\r\n", 4);
  11600. else
  11601. outputStream.write ("/>", 2);
  11602. }
  11603. }
  11604. else
  11605. {
  11606. if (indentationLevel >= 0)
  11607. writeSpaces (outputStream, indentationLevel + 2);
  11608. escapeIllegalXmlChars (outputStream, getText(), false);
  11609. }
  11610. }
  11611. const String XmlElement::createDocument (const String& dtdToUse,
  11612. const bool allOnOneLine,
  11613. const bool includeXmlHeader,
  11614. const String& encodingType,
  11615. const int lineWrapLength) const throw()
  11616. {
  11617. MemoryOutputStream mem (2048, 4096);
  11618. writeToStream (mem, dtdToUse, allOnOneLine, includeXmlHeader, encodingType, lineWrapLength);
  11619. return String (mem.getData(), mem.getDataSize());
  11620. }
  11621. void XmlElement::writeToStream (OutputStream& output,
  11622. const String& dtdToUse,
  11623. const bool allOnOneLine,
  11624. const bool includeXmlHeader,
  11625. const String& encodingType,
  11626. const int lineWrapLength) const throw()
  11627. {
  11628. if (includeXmlHeader)
  11629. {
  11630. output << "<?xml version=\"1.0\" encoding=\"" << encodingType;
  11631. if (allOnOneLine)
  11632. output << "\"?> ";
  11633. else
  11634. output << "\"?>\r\n\r\n";
  11635. }
  11636. if (dtdToUse.isNotEmpty())
  11637. {
  11638. output << dtdToUse;
  11639. if (allOnOneLine)
  11640. output << " ";
  11641. else
  11642. output << "\r\n";
  11643. }
  11644. writeElementAsText (output, allOnOneLine ? -1 : 0, lineWrapLength);
  11645. }
  11646. bool XmlElement::writeToFile (const File& file,
  11647. const String& dtdToUse,
  11648. const String& encodingType,
  11649. const int lineWrapLength) const throw()
  11650. {
  11651. if (file.hasWriteAccess())
  11652. {
  11653. TemporaryFile tempFile (file);
  11654. ScopedPointer <FileOutputStream> out (tempFile.getFile().createOutputStream());
  11655. if (out != 0)
  11656. {
  11657. writeToStream (*out, dtdToUse, false, true, encodingType, lineWrapLength);
  11658. out = 0;
  11659. return tempFile.overwriteTargetFileWithTemporary();
  11660. }
  11661. }
  11662. return false;
  11663. }
  11664. bool XmlElement::hasTagName (const String& tagNameWanted) const throw()
  11665. {
  11666. #ifdef JUCE_DEBUG
  11667. // if debugging, check that the case is actually the same, because
  11668. // valid xml is case-sensitive, and although this lets it pass, it's
  11669. // better not to..
  11670. if (tagName.equalsIgnoreCase (tagNameWanted))
  11671. {
  11672. jassert (tagName == tagNameWanted);
  11673. return true;
  11674. }
  11675. else
  11676. {
  11677. return false;
  11678. }
  11679. #else
  11680. return tagName.equalsIgnoreCase (tagNameWanted);
  11681. #endif
  11682. }
  11683. XmlElement* XmlElement::getNextElementWithTagName (const String& requiredTagName) const
  11684. {
  11685. XmlElement* e = nextElement;
  11686. while (e != 0 && ! e->hasTagName (requiredTagName))
  11687. e = e->nextElement;
  11688. return e;
  11689. }
  11690. int XmlElement::getNumAttributes() const throw()
  11691. {
  11692. const XmlAttributeNode* att = attributes;
  11693. int count = 0;
  11694. while (att != 0)
  11695. {
  11696. att = att->next;
  11697. ++count;
  11698. }
  11699. return count;
  11700. }
  11701. const String& XmlElement::getAttributeName (const int index) const throw()
  11702. {
  11703. const XmlAttributeNode* att = attributes;
  11704. int count = 0;
  11705. while (att != 0)
  11706. {
  11707. if (count == index)
  11708. return att->name;
  11709. att = att->next;
  11710. ++count;
  11711. }
  11712. return String::empty;
  11713. }
  11714. const String& XmlElement::getAttributeValue (const int index) const throw()
  11715. {
  11716. const XmlAttributeNode* att = attributes;
  11717. int count = 0;
  11718. while (att != 0)
  11719. {
  11720. if (count == index)
  11721. return att->value;
  11722. att = att->next;
  11723. ++count;
  11724. }
  11725. return String::empty;
  11726. }
  11727. bool XmlElement::hasAttribute (const String& attributeName) const throw()
  11728. {
  11729. const XmlAttributeNode* att = attributes;
  11730. while (att != 0)
  11731. {
  11732. if (att->name.equalsIgnoreCase (attributeName))
  11733. return true;
  11734. att = att->next;
  11735. }
  11736. return false;
  11737. }
  11738. const String XmlElement::getStringAttribute (const String& attributeName,
  11739. const String& defaultReturnValue) const throw()
  11740. {
  11741. const XmlAttributeNode* att = attributes;
  11742. while (att != 0)
  11743. {
  11744. if (att->name.equalsIgnoreCase (attributeName))
  11745. return att->value;
  11746. att = att->next;
  11747. }
  11748. return defaultReturnValue;
  11749. }
  11750. int XmlElement::getIntAttribute (const String& attributeName,
  11751. const int defaultReturnValue) const throw()
  11752. {
  11753. const XmlAttributeNode* att = attributes;
  11754. while (att != 0)
  11755. {
  11756. if (att->name.equalsIgnoreCase (attributeName))
  11757. return att->value.getIntValue();
  11758. att = att->next;
  11759. }
  11760. return defaultReturnValue;
  11761. }
  11762. double XmlElement::getDoubleAttribute (const String& attributeName,
  11763. const double defaultReturnValue) const throw()
  11764. {
  11765. const XmlAttributeNode* att = attributes;
  11766. while (att != 0)
  11767. {
  11768. if (att->name.equalsIgnoreCase (attributeName))
  11769. return att->value.getDoubleValue();
  11770. att = att->next;
  11771. }
  11772. return defaultReturnValue;
  11773. }
  11774. bool XmlElement::getBoolAttribute (const String& attributeName,
  11775. const bool defaultReturnValue) const throw()
  11776. {
  11777. const XmlAttributeNode* att = attributes;
  11778. while (att != 0)
  11779. {
  11780. if (att->name.equalsIgnoreCase (attributeName))
  11781. {
  11782. tchar firstChar = att->value[0];
  11783. if (CharacterFunctions::isWhitespace (firstChar))
  11784. firstChar = att->value.trimStart() [0];
  11785. return firstChar == T('1')
  11786. || firstChar == T('t')
  11787. || firstChar == T('y')
  11788. || firstChar == T('T')
  11789. || firstChar == T('Y');
  11790. }
  11791. att = att->next;
  11792. }
  11793. return defaultReturnValue;
  11794. }
  11795. bool XmlElement::compareAttribute (const String& attributeName,
  11796. const String& stringToCompareAgainst,
  11797. const bool ignoreCase) const throw()
  11798. {
  11799. const XmlAttributeNode* att = attributes;
  11800. while (att != 0)
  11801. {
  11802. if (att->name.equalsIgnoreCase (attributeName))
  11803. {
  11804. if (ignoreCase)
  11805. return att->value.equalsIgnoreCase (stringToCompareAgainst);
  11806. else
  11807. return att->value == stringToCompareAgainst;
  11808. }
  11809. att = att->next;
  11810. }
  11811. return false;
  11812. }
  11813. void XmlElement::setAttribute (const String& attributeName,
  11814. const String& value) throw()
  11815. {
  11816. #ifdef JUCE_DEBUG
  11817. // check the identifier being passed in is legal..
  11818. const tchar* t = attributeName;
  11819. while (*t != 0)
  11820. {
  11821. jassert (CharacterFunctions::isLetterOrDigit (*t)
  11822. || *t == T('_')
  11823. || *t == T('-')
  11824. || *t == T(':'));
  11825. ++t;
  11826. }
  11827. #endif
  11828. if (attributes == 0)
  11829. {
  11830. attributes = new XmlAttributeNode (attributeName, value);
  11831. }
  11832. else
  11833. {
  11834. XmlAttributeNode* att = attributes;
  11835. for (;;)
  11836. {
  11837. if (att->name.equalsIgnoreCase (attributeName))
  11838. {
  11839. att->value = value;
  11840. break;
  11841. }
  11842. else if (att->next == 0)
  11843. {
  11844. att->next = new XmlAttributeNode (attributeName, value);
  11845. break;
  11846. }
  11847. att = att->next;
  11848. }
  11849. }
  11850. }
  11851. void XmlElement::setAttribute (const String& attributeName,
  11852. const int number) throw()
  11853. {
  11854. setAttribute (attributeName, String (number));
  11855. }
  11856. void XmlElement::setAttribute (const String& attributeName,
  11857. const double number) throw()
  11858. {
  11859. setAttribute (attributeName, String (number));
  11860. }
  11861. void XmlElement::removeAttribute (const String& attributeName) throw()
  11862. {
  11863. XmlAttributeNode* att = attributes;
  11864. XmlAttributeNode* lastAtt = 0;
  11865. while (att != 0)
  11866. {
  11867. if (att->name.equalsIgnoreCase (attributeName))
  11868. {
  11869. if (lastAtt == 0)
  11870. attributes = att->next;
  11871. else
  11872. lastAtt->next = att->next;
  11873. delete att;
  11874. break;
  11875. }
  11876. lastAtt = att;
  11877. att = att->next;
  11878. }
  11879. }
  11880. void XmlElement::removeAllAttributes() throw()
  11881. {
  11882. while (attributes != 0)
  11883. {
  11884. XmlAttributeNode* const nextAtt = attributes->next;
  11885. delete attributes;
  11886. attributes = nextAtt;
  11887. }
  11888. }
  11889. int XmlElement::getNumChildElements() const throw()
  11890. {
  11891. int count = 0;
  11892. const XmlElement* child = firstChildElement;
  11893. while (child != 0)
  11894. {
  11895. ++count;
  11896. child = child->nextElement;
  11897. }
  11898. return count;
  11899. }
  11900. XmlElement* XmlElement::getChildElement (const int index) const throw()
  11901. {
  11902. int count = 0;
  11903. XmlElement* child = firstChildElement;
  11904. while (child != 0 && count < index)
  11905. {
  11906. child = child->nextElement;
  11907. ++count;
  11908. }
  11909. return child;
  11910. }
  11911. XmlElement* XmlElement::getChildByName (const String& childName) const throw()
  11912. {
  11913. XmlElement* child = firstChildElement;
  11914. while (child != 0)
  11915. {
  11916. if (child->hasTagName (childName))
  11917. break;
  11918. child = child->nextElement;
  11919. }
  11920. return child;
  11921. }
  11922. void XmlElement::addChildElement (XmlElement* const newNode) throw()
  11923. {
  11924. if (newNode != 0)
  11925. {
  11926. if (firstChildElement == 0)
  11927. {
  11928. firstChildElement = newNode;
  11929. }
  11930. else
  11931. {
  11932. XmlElement* child = firstChildElement;
  11933. while (child->nextElement != 0)
  11934. child = child->nextElement;
  11935. child->nextElement = newNode;
  11936. // if this is non-zero, then something's probably
  11937. // gone wrong..
  11938. jassert (newNode->nextElement == 0);
  11939. }
  11940. }
  11941. }
  11942. void XmlElement::insertChildElement (XmlElement* const newNode,
  11943. int indexToInsertAt) throw()
  11944. {
  11945. if (newNode != 0)
  11946. {
  11947. removeChildElement (newNode, false);
  11948. if (indexToInsertAt == 0)
  11949. {
  11950. newNode->nextElement = firstChildElement;
  11951. firstChildElement = newNode;
  11952. }
  11953. else
  11954. {
  11955. if (firstChildElement == 0)
  11956. {
  11957. firstChildElement = newNode;
  11958. }
  11959. else
  11960. {
  11961. if (indexToInsertAt < 0)
  11962. indexToInsertAt = std::numeric_limits<int>::max();
  11963. XmlElement* child = firstChildElement;
  11964. while (child->nextElement != 0 && --indexToInsertAt > 0)
  11965. child = child->nextElement;
  11966. newNode->nextElement = child->nextElement;
  11967. child->nextElement = newNode;
  11968. }
  11969. }
  11970. }
  11971. }
  11972. XmlElement* XmlElement::createNewChildElement (const String& tagName)
  11973. {
  11974. XmlElement* const newElement = new XmlElement (tagName);
  11975. addChildElement (newElement);
  11976. return newElement;
  11977. }
  11978. bool XmlElement::replaceChildElement (XmlElement* const currentChildElement,
  11979. XmlElement* const newNode) throw()
  11980. {
  11981. if (newNode != 0)
  11982. {
  11983. XmlElement* child = firstChildElement;
  11984. XmlElement* previousNode = 0;
  11985. while (child != 0)
  11986. {
  11987. if (child == currentChildElement)
  11988. {
  11989. if (child != newNode)
  11990. {
  11991. if (previousNode == 0)
  11992. firstChildElement = newNode;
  11993. else
  11994. previousNode->nextElement = newNode;
  11995. newNode->nextElement = child->nextElement;
  11996. delete child;
  11997. }
  11998. return true;
  11999. }
  12000. previousNode = child;
  12001. child = child->nextElement;
  12002. }
  12003. }
  12004. return false;
  12005. }
  12006. void XmlElement::removeChildElement (XmlElement* const childToRemove,
  12007. const bool shouldDeleteTheChild) throw()
  12008. {
  12009. if (childToRemove != 0)
  12010. {
  12011. if (firstChildElement == childToRemove)
  12012. {
  12013. firstChildElement = childToRemove->nextElement;
  12014. childToRemove->nextElement = 0;
  12015. }
  12016. else
  12017. {
  12018. XmlElement* child = firstChildElement;
  12019. XmlElement* last = 0;
  12020. while (child != 0)
  12021. {
  12022. if (child == childToRemove)
  12023. {
  12024. if (last == 0)
  12025. firstChildElement = child->nextElement;
  12026. else
  12027. last->nextElement = child->nextElement;
  12028. childToRemove->nextElement = 0;
  12029. break;
  12030. }
  12031. last = child;
  12032. child = child->nextElement;
  12033. }
  12034. }
  12035. if (shouldDeleteTheChild)
  12036. delete childToRemove;
  12037. }
  12038. }
  12039. bool XmlElement::isEquivalentTo (const XmlElement* const other,
  12040. const bool ignoreOrderOfAttributes) const throw()
  12041. {
  12042. if (this != other)
  12043. {
  12044. if (other == 0 || tagName != other->tagName)
  12045. {
  12046. return false;
  12047. }
  12048. if (ignoreOrderOfAttributes)
  12049. {
  12050. int totalAtts = 0;
  12051. const XmlAttributeNode* att = attributes;
  12052. while (att != 0)
  12053. {
  12054. if (! other->compareAttribute (att->name, att->value))
  12055. return false;
  12056. att = att->next;
  12057. ++totalAtts;
  12058. }
  12059. if (totalAtts != other->getNumAttributes())
  12060. return false;
  12061. }
  12062. else
  12063. {
  12064. const XmlAttributeNode* thisAtt = attributes;
  12065. const XmlAttributeNode* otherAtt = other->attributes;
  12066. for (;;)
  12067. {
  12068. if (thisAtt == 0 || otherAtt == 0)
  12069. {
  12070. if (thisAtt == otherAtt) // both 0, so it's a match
  12071. break;
  12072. return false;
  12073. }
  12074. if (thisAtt->name != otherAtt->name
  12075. || thisAtt->value != otherAtt->value)
  12076. {
  12077. return false;
  12078. }
  12079. thisAtt = thisAtt->next;
  12080. otherAtt = otherAtt->next;
  12081. }
  12082. }
  12083. const XmlElement* thisChild = firstChildElement;
  12084. const XmlElement* otherChild = other->firstChildElement;
  12085. for (;;)
  12086. {
  12087. if (thisChild == 0 || otherChild == 0)
  12088. {
  12089. if (thisChild == otherChild) // both 0, so it's a match
  12090. break;
  12091. return false;
  12092. }
  12093. if (! thisChild->isEquivalentTo (otherChild, ignoreOrderOfAttributes))
  12094. return false;
  12095. thisChild = thisChild->nextElement;
  12096. otherChild = otherChild->nextElement;
  12097. }
  12098. }
  12099. return true;
  12100. }
  12101. void XmlElement::deleteAllChildElements() throw()
  12102. {
  12103. while (firstChildElement != 0)
  12104. {
  12105. XmlElement* const nextChild = firstChildElement->nextElement;
  12106. delete firstChildElement;
  12107. firstChildElement = nextChild;
  12108. }
  12109. }
  12110. void XmlElement::deleteAllChildElementsWithTagName (const String& name) throw()
  12111. {
  12112. XmlElement* child = firstChildElement;
  12113. while (child != 0)
  12114. {
  12115. if (child->hasTagName (name))
  12116. {
  12117. XmlElement* const nextChild = child->nextElement;
  12118. removeChildElement (child, true);
  12119. child = nextChild;
  12120. }
  12121. else
  12122. {
  12123. child = child->nextElement;
  12124. }
  12125. }
  12126. }
  12127. bool XmlElement::containsChildElement (const XmlElement* const possibleChild) const throw()
  12128. {
  12129. const XmlElement* child = firstChildElement;
  12130. while (child != 0)
  12131. {
  12132. if (child == possibleChild)
  12133. return true;
  12134. child = child->nextElement;
  12135. }
  12136. return false;
  12137. }
  12138. XmlElement* XmlElement::findParentElementOf (const XmlElement* const elementToLookFor) throw()
  12139. {
  12140. if (this == elementToLookFor || elementToLookFor == 0)
  12141. return 0;
  12142. XmlElement* child = firstChildElement;
  12143. while (child != 0)
  12144. {
  12145. if (elementToLookFor == child)
  12146. return this;
  12147. XmlElement* const found = child->findParentElementOf (elementToLookFor);
  12148. if (found != 0)
  12149. return found;
  12150. child = child->nextElement;
  12151. }
  12152. return 0;
  12153. }
  12154. void XmlElement::getChildElementsAsArray (XmlElement** elems) const throw()
  12155. {
  12156. XmlElement* e = firstChildElement;
  12157. while (e != 0)
  12158. {
  12159. *elems++ = e;
  12160. e = e->nextElement;
  12161. }
  12162. }
  12163. void XmlElement::reorderChildElements (XmlElement** const elems, const int num) throw()
  12164. {
  12165. XmlElement* e = firstChildElement = elems[0];
  12166. for (int i = 1; i < num; ++i)
  12167. {
  12168. e->nextElement = elems[i];
  12169. e = e->nextElement;
  12170. }
  12171. e->nextElement = 0;
  12172. }
  12173. bool XmlElement::isTextElement() const throw()
  12174. {
  12175. return tagName.isEmpty();
  12176. }
  12177. static const tchar* const juce_xmltextContentAttributeName = T("text");
  12178. const String XmlElement::getText() const throw()
  12179. {
  12180. jassert (isTextElement()); // you're trying to get the text from an element that
  12181. // isn't actually a text element.. If this contains text sub-nodes, you
  12182. // probably want to use getAllSubText instead.
  12183. return getStringAttribute (juce_xmltextContentAttributeName);
  12184. }
  12185. void XmlElement::setText (const String& newText) throw()
  12186. {
  12187. if (isTextElement())
  12188. {
  12189. setAttribute (juce_xmltextContentAttributeName, newText);
  12190. }
  12191. else
  12192. {
  12193. jassertfalse // you can only change the text in a text element, not a normal one.
  12194. }
  12195. }
  12196. const String XmlElement::getAllSubText() const throw()
  12197. {
  12198. String result;
  12199. String::Concatenator concatenator (result);
  12200. const XmlElement* child = firstChildElement;
  12201. while (child != 0)
  12202. {
  12203. if (child->isTextElement())
  12204. concatenator.append (child->getText());
  12205. child = child->nextElement;
  12206. }
  12207. return result;
  12208. }
  12209. const String XmlElement::getChildElementAllSubText (const String& childTagName,
  12210. const String& defaultReturnValue) const throw()
  12211. {
  12212. const XmlElement* const child = getChildByName (childTagName);
  12213. if (child != 0)
  12214. return child->getAllSubText();
  12215. return defaultReturnValue;
  12216. }
  12217. XmlElement* XmlElement::createTextElement (const String& text) throw()
  12218. {
  12219. XmlElement* const e = new XmlElement ((int) 0);
  12220. e->setAttribute (juce_xmltextContentAttributeName, text);
  12221. return e;
  12222. }
  12223. void XmlElement::addTextElement (const String& text) throw()
  12224. {
  12225. addChildElement (createTextElement (text));
  12226. }
  12227. void XmlElement::deleteAllTextElements() throw()
  12228. {
  12229. XmlElement* child = firstChildElement;
  12230. while (child != 0)
  12231. {
  12232. XmlElement* const next = child->nextElement;
  12233. if (child->isTextElement())
  12234. removeChildElement (child, true);
  12235. child = next;
  12236. }
  12237. }
  12238. END_JUCE_NAMESPACE
  12239. /*** End of inlined file: juce_XmlElement.cpp ***/
  12240. /*** Start of inlined file: juce_InterProcessLock.cpp ***/
  12241. BEGIN_JUCE_NAMESPACE
  12242. // (implemented in the platform-specific code files)
  12243. END_JUCE_NAMESPACE
  12244. /*** End of inlined file: juce_InterProcessLock.cpp ***/
  12245. /*** Start of inlined file: juce_ReadWriteLock.cpp ***/
  12246. BEGIN_JUCE_NAMESPACE
  12247. ReadWriteLock::ReadWriteLock() throw()
  12248. : numWaitingWriters (0),
  12249. numWriters (0),
  12250. writerThreadId (0)
  12251. {
  12252. }
  12253. ReadWriteLock::~ReadWriteLock() throw()
  12254. {
  12255. jassert (readerThreads.size() == 0);
  12256. jassert (numWriters == 0);
  12257. }
  12258. void ReadWriteLock::enterRead() const throw()
  12259. {
  12260. const Thread::ThreadID threadId = Thread::getCurrentThreadId();
  12261. const ScopedLock sl (accessLock);
  12262. for (;;)
  12263. {
  12264. jassert (readerThreads.size() % 2 == 0);
  12265. int i;
  12266. for (i = 0; i < readerThreads.size(); i += 2)
  12267. if (readerThreads.getUnchecked(i) == threadId)
  12268. break;
  12269. if (i < readerThreads.size()
  12270. || numWriters + numWaitingWriters == 0
  12271. || (threadId == writerThreadId && numWriters > 0))
  12272. {
  12273. if (i < readerThreads.size())
  12274. {
  12275. readerThreads.set (i + 1, (Thread::ThreadID) (1 + (pointer_sized_int) readerThreads.getUnchecked (i + 1)));
  12276. }
  12277. else
  12278. {
  12279. readerThreads.add (threadId);
  12280. readerThreads.add ((Thread::ThreadID) 1);
  12281. }
  12282. return;
  12283. }
  12284. const ScopedUnlock ul (accessLock);
  12285. waitEvent.wait (100);
  12286. }
  12287. }
  12288. void ReadWriteLock::exitRead() const throw()
  12289. {
  12290. const Thread::ThreadID threadId = Thread::getCurrentThreadId();
  12291. const ScopedLock sl (accessLock);
  12292. for (int i = 0; i < readerThreads.size(); i += 2)
  12293. {
  12294. if (readerThreads.getUnchecked(i) == threadId)
  12295. {
  12296. const pointer_sized_int newCount = ((pointer_sized_int) readerThreads.getUnchecked (i + 1)) - 1;
  12297. if (newCount == 0)
  12298. {
  12299. readerThreads.removeRange (i, 2);
  12300. waitEvent.signal();
  12301. }
  12302. else
  12303. {
  12304. readerThreads.set (i + 1, (Thread::ThreadID) newCount);
  12305. }
  12306. return;
  12307. }
  12308. }
  12309. jassertfalse // unlocking a lock that wasn't locked..
  12310. }
  12311. void ReadWriteLock::enterWrite() const throw()
  12312. {
  12313. const Thread::ThreadID threadId = Thread::getCurrentThreadId();
  12314. const ScopedLock sl (accessLock);
  12315. for (;;)
  12316. {
  12317. if (readerThreads.size() + numWriters == 0
  12318. || threadId == writerThreadId
  12319. || (readerThreads.size() == 2
  12320. && readerThreads.getUnchecked(0) == threadId))
  12321. {
  12322. writerThreadId = threadId;
  12323. ++numWriters;
  12324. break;
  12325. }
  12326. ++numWaitingWriters;
  12327. accessLock.exit();
  12328. waitEvent.wait (100);
  12329. accessLock.enter();
  12330. --numWaitingWriters;
  12331. }
  12332. }
  12333. bool ReadWriteLock::tryEnterWrite() const throw()
  12334. {
  12335. const Thread::ThreadID threadId = Thread::getCurrentThreadId();
  12336. const ScopedLock sl (accessLock);
  12337. if (readerThreads.size() + numWriters == 0
  12338. || threadId == writerThreadId
  12339. || (readerThreads.size() == 2
  12340. && readerThreads.getUnchecked(0) == threadId))
  12341. {
  12342. writerThreadId = threadId;
  12343. ++numWriters;
  12344. return true;
  12345. }
  12346. return false;
  12347. }
  12348. void ReadWriteLock::exitWrite() const throw()
  12349. {
  12350. const ScopedLock sl (accessLock);
  12351. // check this thread actually had the lock..
  12352. jassert (numWriters > 0 && writerThreadId == Thread::getCurrentThreadId());
  12353. if (--numWriters == 0)
  12354. {
  12355. writerThreadId = 0;
  12356. waitEvent.signal();
  12357. }
  12358. }
  12359. END_JUCE_NAMESPACE
  12360. /*** End of inlined file: juce_ReadWriteLock.cpp ***/
  12361. /*** Start of inlined file: juce_Thread.cpp ***/
  12362. BEGIN_JUCE_NAMESPACE
  12363. // these functions are implemented in the platform-specific code.
  12364. void* juce_createThread (void* userData);
  12365. void juce_killThread (void* handle);
  12366. bool juce_setThreadPriority (void* handle, int priority);
  12367. void juce_setCurrentThreadName (const String& name);
  12368. #if JUCE_WIN32
  12369. void juce_CloseThreadHandle (void* handle);
  12370. #endif
  12371. static VoidArray runningThreads;
  12372. static CriticalSection runningThreadsLock;
  12373. void Thread::threadEntryPoint (Thread* const thread)
  12374. {
  12375. {
  12376. const ScopedLock sl (runningThreadsLock);
  12377. runningThreads.add (thread);
  12378. }
  12379. JUCE_TRY
  12380. {
  12381. thread->threadId_ = Thread::getCurrentThreadId();
  12382. if (thread->threadName_.isNotEmpty())
  12383. juce_setCurrentThreadName (thread->threadName_);
  12384. if (thread->startSuspensionEvent_.wait (10000))
  12385. {
  12386. if (thread->affinityMask_ != 0)
  12387. setCurrentThreadAffinityMask (thread->affinityMask_);
  12388. thread->run();
  12389. }
  12390. }
  12391. JUCE_CATCH_ALL_ASSERT
  12392. {
  12393. const ScopedLock sl (runningThreadsLock);
  12394. jassert (runningThreads.contains (thread));
  12395. runningThreads.removeValue (thread);
  12396. }
  12397. #if JUCE_WIN32
  12398. juce_CloseThreadHandle (thread->threadHandle_);
  12399. #endif
  12400. thread->threadHandle_ = 0;
  12401. thread->threadId_ = 0;
  12402. }
  12403. // used to wrap the incoming call from the platform-specific code
  12404. void JUCE_API juce_threadEntryPoint (void* userData)
  12405. {
  12406. Thread::threadEntryPoint ((Thread*) userData);
  12407. }
  12408. Thread::Thread (const String& threadName)
  12409. : threadName_ (threadName),
  12410. threadHandle_ (0),
  12411. threadPriority_ (5),
  12412. threadId_ (0),
  12413. affinityMask_ (0),
  12414. threadShouldExit_ (false)
  12415. {
  12416. }
  12417. Thread::~Thread()
  12418. {
  12419. stopThread (100);
  12420. }
  12421. void Thread::startThread()
  12422. {
  12423. const ScopedLock sl (startStopLock);
  12424. threadShouldExit_ = false;
  12425. if (threadHandle_ == 0)
  12426. {
  12427. threadHandle_ = juce_createThread ((void*) this);
  12428. juce_setThreadPriority (threadHandle_, threadPriority_);
  12429. startSuspensionEvent_.signal();
  12430. }
  12431. }
  12432. void Thread::startThread (const int priority)
  12433. {
  12434. const ScopedLock sl (startStopLock);
  12435. if (threadHandle_ == 0)
  12436. {
  12437. threadPriority_ = priority;
  12438. startThread();
  12439. }
  12440. else
  12441. {
  12442. setPriority (priority);
  12443. }
  12444. }
  12445. bool Thread::isThreadRunning() const
  12446. {
  12447. return threadHandle_ != 0;
  12448. }
  12449. void Thread::signalThreadShouldExit()
  12450. {
  12451. threadShouldExit_ = true;
  12452. }
  12453. bool Thread::waitForThreadToExit (const int timeOutMilliseconds) const
  12454. {
  12455. // Doh! So how exactly do you expect this thread to wait for itself to stop??
  12456. jassert (getThreadId() != getCurrentThreadId());
  12457. const int sleepMsPerIteration = 5;
  12458. int count = timeOutMilliseconds / sleepMsPerIteration;
  12459. while (isThreadRunning())
  12460. {
  12461. if (timeOutMilliseconds > 0 && --count < 0)
  12462. return false;
  12463. sleep (sleepMsPerIteration);
  12464. }
  12465. return true;
  12466. }
  12467. void Thread::stopThread (const int timeOutMilliseconds)
  12468. {
  12469. // agh! You can't stop the thread that's calling this method! How on earth
  12470. // would that work??
  12471. jassert (getCurrentThreadId() != getThreadId());
  12472. const ScopedLock sl (startStopLock);
  12473. if (isThreadRunning())
  12474. {
  12475. signalThreadShouldExit();
  12476. notify();
  12477. if (timeOutMilliseconds != 0)
  12478. waitForThreadToExit (timeOutMilliseconds);
  12479. if (isThreadRunning())
  12480. {
  12481. // very bad karma if this point is reached, as
  12482. // there are bound to be locks and events left in
  12483. // silly states when a thread is killed by force..
  12484. jassertfalse
  12485. Logger::writeToLog ("!! killing thread by force !!");
  12486. juce_killThread (threadHandle_);
  12487. threadHandle_ = 0;
  12488. threadId_ = 0;
  12489. const ScopedLock sl2 (runningThreadsLock);
  12490. runningThreads.removeValue (this);
  12491. }
  12492. }
  12493. }
  12494. bool Thread::setPriority (const int priority)
  12495. {
  12496. const ScopedLock sl (startStopLock);
  12497. const bool worked = juce_setThreadPriority (threadHandle_, priority);
  12498. if (worked)
  12499. threadPriority_ = priority;
  12500. return worked;
  12501. }
  12502. bool Thread::setCurrentThreadPriority (const int priority)
  12503. {
  12504. return juce_setThreadPriority (0, priority);
  12505. }
  12506. void Thread::setAffinityMask (const uint32 affinityMask)
  12507. {
  12508. affinityMask_ = affinityMask;
  12509. }
  12510. bool Thread::wait (const int timeOutMilliseconds) const
  12511. {
  12512. return defaultEvent_.wait (timeOutMilliseconds);
  12513. }
  12514. void Thread::notify() const
  12515. {
  12516. defaultEvent_.signal();
  12517. }
  12518. int Thread::getNumRunningThreads()
  12519. {
  12520. return runningThreads.size();
  12521. }
  12522. Thread* Thread::getCurrentThread()
  12523. {
  12524. const ThreadID thisId = getCurrentThreadId();
  12525. const ScopedLock sl (runningThreadsLock);
  12526. for (int i = runningThreads.size(); --i >= 0;)
  12527. {
  12528. Thread* const t = (Thread*) runningThreads.getUnchecked(i);
  12529. if (t->threadId_ == thisId)
  12530. return t;
  12531. }
  12532. return 0;
  12533. }
  12534. void Thread::stopAllThreads (const int timeOutMilliseconds)
  12535. {
  12536. {
  12537. const ScopedLock sl (runningThreadsLock);
  12538. for (int i = runningThreads.size(); --i >= 0;)
  12539. ((Thread*) runningThreads.getUnchecked(i))->signalThreadShouldExit();
  12540. }
  12541. for (;;)
  12542. {
  12543. runningThreadsLock.enter();
  12544. Thread* const t = (Thread*) runningThreads[0];
  12545. runningThreadsLock.exit();
  12546. if (t == 0)
  12547. break;
  12548. t->stopThread (timeOutMilliseconds);
  12549. }
  12550. }
  12551. END_JUCE_NAMESPACE
  12552. /*** End of inlined file: juce_Thread.cpp ***/
  12553. /*** Start of inlined file: juce_ThreadPool.cpp ***/
  12554. BEGIN_JUCE_NAMESPACE
  12555. ThreadPoolJob::ThreadPoolJob (const String& name)
  12556. : jobName (name),
  12557. pool (0),
  12558. shouldStop (false),
  12559. isActive (false),
  12560. shouldBeDeleted (false)
  12561. {
  12562. }
  12563. ThreadPoolJob::~ThreadPoolJob()
  12564. {
  12565. // you mustn't delete a job while it's still in a pool! Use ThreadPool::removeJob()
  12566. // to remove it first!
  12567. jassert (pool == 0 || ! pool->contains (this));
  12568. }
  12569. const String ThreadPoolJob::getJobName() const
  12570. {
  12571. return jobName;
  12572. }
  12573. void ThreadPoolJob::setJobName (const String& newName)
  12574. {
  12575. jobName = newName;
  12576. }
  12577. void ThreadPoolJob::signalJobShouldExit()
  12578. {
  12579. shouldStop = true;
  12580. }
  12581. class ThreadPool::ThreadPoolThread : public Thread
  12582. {
  12583. public:
  12584. ThreadPoolThread (ThreadPool& pool_)
  12585. : Thread (T("Pool")),
  12586. pool (pool_),
  12587. busy (false)
  12588. {
  12589. }
  12590. ~ThreadPoolThread()
  12591. {
  12592. }
  12593. void run()
  12594. {
  12595. while (! threadShouldExit())
  12596. {
  12597. if (! pool.runNextJob())
  12598. wait (500);
  12599. }
  12600. }
  12601. private:
  12602. ThreadPool& pool;
  12603. bool volatile busy;
  12604. ThreadPoolThread (const ThreadPoolThread&);
  12605. ThreadPoolThread& operator= (const ThreadPoolThread&);
  12606. };
  12607. ThreadPool::ThreadPool (const int numThreads,
  12608. const bool startThreadsOnlyWhenNeeded,
  12609. const int stopThreadsWhenNotUsedTimeoutMs)
  12610. : threadStopTimeout (stopThreadsWhenNotUsedTimeoutMs),
  12611. priority (5)
  12612. {
  12613. jassert (numThreads > 0); // not much point having one of these with no threads in it.
  12614. for (int i = jmax (1, numThreads); --i >= 0;)
  12615. threads.add (new ThreadPoolThread (*this));
  12616. if (! startThreadsOnlyWhenNeeded)
  12617. for (int i = threads.size(); --i >= 0;)
  12618. threads.getUnchecked(i)->startThread (priority);
  12619. }
  12620. ThreadPool::~ThreadPool()
  12621. {
  12622. removeAllJobs (true, 4000);
  12623. int i;
  12624. for (i = threads.size(); --i >= 0;)
  12625. threads.getUnchecked(i)->signalThreadShouldExit();
  12626. for (i = threads.size(); --i >= 0;)
  12627. threads.getUnchecked(i)->stopThread (500);
  12628. }
  12629. void ThreadPool::addJob (ThreadPoolJob* const job)
  12630. {
  12631. jassert (job != 0);
  12632. jassert (job->pool == 0);
  12633. if (job->pool == 0)
  12634. {
  12635. job->pool = this;
  12636. job->shouldStop = false;
  12637. job->isActive = false;
  12638. {
  12639. const ScopedLock sl (lock);
  12640. jobs.add (job);
  12641. int numRunning = 0;
  12642. for (int i = threads.size(); --i >= 0;)
  12643. if (threads.getUnchecked(i)->isThreadRunning() && ! threads.getUnchecked(i)->threadShouldExit())
  12644. ++numRunning;
  12645. if (numRunning < threads.size())
  12646. {
  12647. bool startedOne = false;
  12648. int n = 1000;
  12649. while (--n >= 0 && ! startedOne)
  12650. {
  12651. for (int i = threads.size(); --i >= 0;)
  12652. {
  12653. if (! threads.getUnchecked(i)->isThreadRunning())
  12654. {
  12655. threads.getUnchecked(i)->startThread (priority);
  12656. startedOne = true;
  12657. break;
  12658. }
  12659. }
  12660. if (! startedOne)
  12661. Thread::sleep (2);
  12662. }
  12663. }
  12664. }
  12665. for (int i = threads.size(); --i >= 0;)
  12666. threads.getUnchecked(i)->notify();
  12667. }
  12668. }
  12669. int ThreadPool::getNumJobs() const
  12670. {
  12671. return jobs.size();
  12672. }
  12673. ThreadPoolJob* ThreadPool::getJob (const int index) const
  12674. {
  12675. const ScopedLock sl (lock);
  12676. return (ThreadPoolJob*) jobs [index];
  12677. }
  12678. bool ThreadPool::contains (const ThreadPoolJob* const job) const
  12679. {
  12680. const ScopedLock sl (lock);
  12681. return jobs.contains (const_cast <ThreadPoolJob*> (job));
  12682. }
  12683. bool ThreadPool::isJobRunning (const ThreadPoolJob* const job) const
  12684. {
  12685. const ScopedLock sl (lock);
  12686. return jobs.contains (const_cast <ThreadPoolJob*> (job)) && job->isActive;
  12687. }
  12688. bool ThreadPool::waitForJobToFinish (const ThreadPoolJob* const job,
  12689. const int timeOutMs) const
  12690. {
  12691. if (job != 0)
  12692. {
  12693. const uint32 start = Time::getMillisecondCounter();
  12694. while (contains (job))
  12695. {
  12696. if (timeOutMs >= 0 && Time::getMillisecondCounter() >= start + timeOutMs)
  12697. return false;
  12698. jobFinishedSignal.wait (2);
  12699. }
  12700. }
  12701. return true;
  12702. }
  12703. bool ThreadPool::removeJob (ThreadPoolJob* const job,
  12704. const bool interruptIfRunning,
  12705. const int timeOutMs)
  12706. {
  12707. if (job != 0)
  12708. {
  12709. lock.enter();
  12710. if (jobs.contains (job))
  12711. {
  12712. if (job->isActive)
  12713. {
  12714. if (interruptIfRunning)
  12715. job->signalJobShouldExit();
  12716. lock.exit();
  12717. return waitForJobToFinish (job, timeOutMs);
  12718. }
  12719. else
  12720. {
  12721. jobs.removeValue (job);
  12722. }
  12723. }
  12724. lock.exit();
  12725. }
  12726. return true;
  12727. }
  12728. bool ThreadPool::removeAllJobs (const bool interruptRunningJobs,
  12729. const int timeOutMs,
  12730. const bool deleteInactiveJobs,
  12731. ThreadPool::JobSelector* selectedJobsToRemove)
  12732. {
  12733. Array <ThreadPoolJob*> jobsToWaitFor;
  12734. {
  12735. const ScopedLock sl (lock);
  12736. for (int i = jobs.size(); --i >= 0;)
  12737. {
  12738. ThreadPoolJob* const job = jobs.getUnchecked(i);
  12739. if (selectedJobsToRemove == 0 || selectedJobsToRemove->isJobSuitable (job))
  12740. {
  12741. if (job->isActive)
  12742. {
  12743. jobsToWaitFor.add (job);
  12744. if (interruptRunningJobs)
  12745. job->signalJobShouldExit();
  12746. }
  12747. else
  12748. {
  12749. jobs.remove (i);
  12750. if (deleteInactiveJobs)
  12751. delete job;
  12752. }
  12753. }
  12754. }
  12755. }
  12756. const uint32 start = Time::getMillisecondCounter();
  12757. for (;;)
  12758. {
  12759. for (int i = jobsToWaitFor.size(); --i >= 0;)
  12760. if (! isJobRunning (jobsToWaitFor.getUnchecked (i)))
  12761. jobsToWaitFor.remove (i);
  12762. if (jobsToWaitFor.size() == 0)
  12763. break;
  12764. if (timeOutMs >= 0 && Time::getMillisecondCounter() >= start + timeOutMs)
  12765. return false;
  12766. jobFinishedSignal.wait (20);
  12767. }
  12768. return true;
  12769. }
  12770. const StringArray ThreadPool::getNamesOfAllJobs (const bool onlyReturnActiveJobs) const
  12771. {
  12772. StringArray s;
  12773. const ScopedLock sl (lock);
  12774. for (int i = 0; i < jobs.size(); ++i)
  12775. {
  12776. const ThreadPoolJob* const job = jobs.getUnchecked(i);
  12777. if (job->isActive || ! onlyReturnActiveJobs)
  12778. s.add (job->getJobName());
  12779. }
  12780. return s;
  12781. }
  12782. bool ThreadPool::setThreadPriorities (const int newPriority)
  12783. {
  12784. bool ok = true;
  12785. if (priority != newPriority)
  12786. {
  12787. priority = newPriority;
  12788. for (int i = threads.size(); --i >= 0;)
  12789. if (! threads.getUnchecked(i)->setPriority (newPriority))
  12790. ok = false;
  12791. }
  12792. return ok;
  12793. }
  12794. bool ThreadPool::runNextJob()
  12795. {
  12796. ThreadPoolJob* job = 0;
  12797. {
  12798. const ScopedLock sl (lock);
  12799. for (int i = 0; i < jobs.size(); ++i)
  12800. {
  12801. job = jobs[i];
  12802. if (job != 0 && ! (job->isActive || job->shouldStop))
  12803. break;
  12804. job = 0;
  12805. }
  12806. if (job != 0)
  12807. job->isActive = true;
  12808. }
  12809. if (job != 0)
  12810. {
  12811. JUCE_TRY
  12812. {
  12813. ThreadPoolJob::JobStatus result = job->runJob();
  12814. lastJobEndTime = Time::getApproximateMillisecondCounter();
  12815. const ScopedLock sl (lock);
  12816. if (jobs.contains (job))
  12817. {
  12818. job->isActive = false;
  12819. if (result != ThreadPoolJob::jobNeedsRunningAgain || job->shouldStop)
  12820. {
  12821. job->pool = 0;
  12822. job->shouldStop = true;
  12823. jobs.removeValue (job);
  12824. if (result == ThreadPoolJob::jobHasFinishedAndShouldBeDeleted)
  12825. delete job;
  12826. jobFinishedSignal.signal();
  12827. }
  12828. else
  12829. {
  12830. // move the job to the end of the queue if it wants another go
  12831. jobs.move (jobs.indexOf (job), -1);
  12832. }
  12833. }
  12834. }
  12835. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  12836. catch (...)
  12837. {
  12838. const ScopedLock sl (lock);
  12839. jobs.removeValue (job);
  12840. }
  12841. #endif
  12842. }
  12843. else
  12844. {
  12845. if (threadStopTimeout > 0
  12846. && Time::getApproximateMillisecondCounter() > lastJobEndTime + threadStopTimeout)
  12847. {
  12848. const ScopedLock sl (lock);
  12849. if (jobs.size() == 0)
  12850. for (int i = threads.size(); --i >= 0;)
  12851. threads.getUnchecked(i)->signalThreadShouldExit();
  12852. }
  12853. else
  12854. {
  12855. return false;
  12856. }
  12857. }
  12858. return true;
  12859. }
  12860. END_JUCE_NAMESPACE
  12861. /*** End of inlined file: juce_ThreadPool.cpp ***/
  12862. /*** Start of inlined file: juce_TimeSliceThread.cpp ***/
  12863. BEGIN_JUCE_NAMESPACE
  12864. TimeSliceThread::TimeSliceThread (const String& threadName)
  12865. : Thread (threadName),
  12866. index (0),
  12867. clientBeingCalled (0),
  12868. clientsChanged (false)
  12869. {
  12870. }
  12871. TimeSliceThread::~TimeSliceThread()
  12872. {
  12873. stopThread (2000);
  12874. }
  12875. void TimeSliceThread::addTimeSliceClient (TimeSliceClient* const client)
  12876. {
  12877. const ScopedLock sl (listLock);
  12878. clients.addIfNotAlreadyThere (client);
  12879. clientsChanged = true;
  12880. notify();
  12881. }
  12882. void TimeSliceThread::removeTimeSliceClient (TimeSliceClient* const client)
  12883. {
  12884. const ScopedLock sl1 (listLock);
  12885. clientsChanged = true;
  12886. // if there's a chance we're in the middle of calling this client, we need to
  12887. // also lock the outer lock..
  12888. if (clientBeingCalled == client)
  12889. {
  12890. const ScopedUnlock ul (listLock); // unlock first to get the order right..
  12891. const ScopedLock sl2 (callbackLock);
  12892. const ScopedLock sl3 (listLock);
  12893. clients.removeValue (client);
  12894. }
  12895. else
  12896. {
  12897. clients.removeValue (client);
  12898. }
  12899. }
  12900. int TimeSliceThread::getNumClients() const
  12901. {
  12902. return clients.size();
  12903. }
  12904. TimeSliceClient* TimeSliceThread::getClient (const int i) const
  12905. {
  12906. const ScopedLock sl (listLock);
  12907. return clients [i];
  12908. }
  12909. void TimeSliceThread::run()
  12910. {
  12911. int numCallsSinceBusy = 0;
  12912. while (! threadShouldExit())
  12913. {
  12914. int timeToWait = 500;
  12915. {
  12916. const ScopedLock sl (callbackLock);
  12917. {
  12918. const ScopedLock sl2 (listLock);
  12919. if (clients.size() > 0)
  12920. {
  12921. index = (index + 1) % clients.size();
  12922. clientBeingCalled = clients [index];
  12923. }
  12924. else
  12925. {
  12926. index = 0;
  12927. clientBeingCalled = 0;
  12928. }
  12929. if (clientsChanged)
  12930. {
  12931. clientsChanged = false;
  12932. numCallsSinceBusy = 0;
  12933. }
  12934. }
  12935. if (clientBeingCalled != 0)
  12936. {
  12937. if (clientBeingCalled->useTimeSlice())
  12938. numCallsSinceBusy = 0;
  12939. else
  12940. ++numCallsSinceBusy;
  12941. if (numCallsSinceBusy >= clients.size())
  12942. timeToWait = 500;
  12943. else if (index == 0)
  12944. timeToWait = 1; // throw in an occasional pause, to stop everything locking up
  12945. else
  12946. timeToWait = 0;
  12947. }
  12948. }
  12949. if (timeToWait > 0)
  12950. wait (timeToWait);
  12951. }
  12952. }
  12953. END_JUCE_NAMESPACE
  12954. /*** End of inlined file: juce_TimeSliceThread.cpp ***/
  12955. #endif
  12956. #if JUCE_BUILD_MISC
  12957. /*** Start of inlined file: juce_ValueTree.cpp ***/
  12958. BEGIN_JUCE_NAMESPACE
  12959. class ValueTreeSetPropertyAction : public UndoableAction
  12960. {
  12961. public:
  12962. ValueTreeSetPropertyAction (const ValueTree::SharedObjectPtr& target_, const var::identifier& name_,
  12963. const var& newValue_, const bool isAddingNewProperty_, const bool isDeletingProperty_)
  12964. : target (target_), name (name_), newValue (newValue_),
  12965. isAddingNewProperty (isAddingNewProperty_),
  12966. isDeletingProperty (isDeletingProperty_)
  12967. {
  12968. if (! isAddingNewProperty)
  12969. oldValue = target_->getProperty (name_);
  12970. }
  12971. ~ValueTreeSetPropertyAction() {}
  12972. bool perform()
  12973. {
  12974. jassert (! (isAddingNewProperty && target->hasProperty (name)));
  12975. if (isDeletingProperty)
  12976. target->removeProperty (name, 0);
  12977. else
  12978. target->setProperty (name, newValue, 0);
  12979. return true;
  12980. }
  12981. bool undo()
  12982. {
  12983. if (isAddingNewProperty)
  12984. target->removeProperty (name, 0);
  12985. else
  12986. target->setProperty (name, oldValue, 0);
  12987. return true;
  12988. }
  12989. int getSizeInUnits()
  12990. {
  12991. return (int) sizeof (*this); //xxx should be more accurate
  12992. }
  12993. private:
  12994. const ValueTree::SharedObjectPtr target;
  12995. const var::identifier name;
  12996. const var newValue;
  12997. var oldValue;
  12998. const bool isAddingNewProperty, isDeletingProperty;
  12999. ValueTreeSetPropertyAction (const ValueTreeSetPropertyAction&);
  13000. const ValueTreeSetPropertyAction& operator= (const ValueTreeSetPropertyAction&);
  13001. };
  13002. class ValueTreeChildChangeAction : public UndoableAction
  13003. {
  13004. public:
  13005. ValueTreeChildChangeAction (const ValueTree::SharedObjectPtr& target_, const int childIndex_,
  13006. const ValueTree::SharedObjectPtr& newChild_)
  13007. : target (target_),
  13008. child (newChild_ != 0 ? newChild_ : target_->children [childIndex_]),
  13009. childIndex (childIndex_),
  13010. isDeleting (newChild_ == 0)
  13011. {
  13012. jassert (child != 0);
  13013. }
  13014. ~ValueTreeChildChangeAction() {}
  13015. bool perform()
  13016. {
  13017. if (isDeleting)
  13018. target->removeChild (childIndex, 0);
  13019. else
  13020. target->addChild (child, childIndex, 0);
  13021. return true;
  13022. }
  13023. bool undo()
  13024. {
  13025. if (isDeleting)
  13026. target->addChild (child, childIndex, 0);
  13027. else
  13028. target->removeChild (childIndex, 0);
  13029. return true;
  13030. }
  13031. int getSizeInUnits()
  13032. {
  13033. return (int) sizeof (*this); //xxx should be more accurate
  13034. }
  13035. private:
  13036. const ValueTree::SharedObjectPtr target, child;
  13037. const int childIndex;
  13038. const bool isDeleting;
  13039. ValueTreeChildChangeAction (const ValueTreeChildChangeAction&);
  13040. const ValueTreeChildChangeAction& operator= (const ValueTreeChildChangeAction&);
  13041. };
  13042. ValueTree::SharedObject::SharedObject (const String& type_)
  13043. : type (type_), parent (0)
  13044. {
  13045. }
  13046. ValueTree::SharedObject::SharedObject (const SharedObject& other)
  13047. : type (other.type), properties (other.properties), parent (0)
  13048. {
  13049. for (int i = 0; i < other.children.size(); ++i)
  13050. children.add (new SharedObject (*other.children.getUnchecked(i)));
  13051. }
  13052. ValueTree::SharedObject::~SharedObject()
  13053. {
  13054. jassert (parent == 0); // this should never happen unless something isn't obeying the ref-counting!
  13055. for (int i = children.size(); --i >= 0;)
  13056. {
  13057. const SharedObjectPtr c (children.getUnchecked(i));
  13058. c->parent = 0;
  13059. children.remove (i);
  13060. c->sendParentChangeMessage();
  13061. }
  13062. }
  13063. void ValueTree::deliverPropertyChangeMessage (ValueTree& tree, const var::identifier& property)
  13064. {
  13065. for (int i = listeners.size(); --i >= 0;)
  13066. {
  13067. ValueTree::Listener* const l = listeners[i];
  13068. if (l != 0)
  13069. l->valueTreePropertyChanged (tree, property);
  13070. }
  13071. }
  13072. void ValueTree::SharedObject::sendPropertyChangeMessage (ValueTree& tree, const var::identifier& property)
  13073. {
  13074. for (int i = valueTreesWithListeners.size(); --i >= 0;)
  13075. {
  13076. ValueTree* const v = valueTreesWithListeners[i];
  13077. if (v != 0)
  13078. v->deliverPropertyChangeMessage (tree, property);
  13079. }
  13080. }
  13081. void ValueTree::SharedObject::sendPropertyChangeMessage (const var::identifier& property)
  13082. {
  13083. ValueTree tree (this);
  13084. ValueTree::SharedObject* t = this;
  13085. while (t != 0)
  13086. {
  13087. t->sendPropertyChangeMessage (tree, property);
  13088. t = t->parent;
  13089. }
  13090. }
  13091. void ValueTree::deliverChildChangeMessage (ValueTree& tree)
  13092. {
  13093. for (int i = listeners.size(); --i >= 0;)
  13094. {
  13095. ValueTree::Listener* const l = listeners[i];
  13096. if (l != 0)
  13097. l->valueTreeChildrenChanged (tree);
  13098. }
  13099. }
  13100. void ValueTree::SharedObject::sendChildChangeMessage (ValueTree& tree)
  13101. {
  13102. for (int i = valueTreesWithListeners.size(); --i >= 0;)
  13103. {
  13104. ValueTree* const v = valueTreesWithListeners[i];
  13105. if (v != 0)
  13106. v->deliverChildChangeMessage (tree);
  13107. }
  13108. }
  13109. void ValueTree::SharedObject::sendChildChangeMessage()
  13110. {
  13111. ValueTree tree (this);
  13112. ValueTree::SharedObject* t = this;
  13113. while (t != 0)
  13114. {
  13115. t->sendChildChangeMessage (tree);
  13116. t = t->parent;
  13117. }
  13118. }
  13119. void ValueTree::deliverParentChangeMessage (ValueTree& tree)
  13120. {
  13121. for (int i = listeners.size(); --i >= 0;)
  13122. {
  13123. ValueTree::Listener* const l = listeners[i];
  13124. if (l != 0)
  13125. l->valueTreeParentChanged (tree);
  13126. }
  13127. }
  13128. void ValueTree::SharedObject::sendParentChangeMessage()
  13129. {
  13130. ValueTree tree (this);
  13131. int i;
  13132. for (i = children.size(); --i >= 0;)
  13133. {
  13134. SharedObject* const t = children[i];
  13135. if (t != 0)
  13136. t->sendParentChangeMessage();
  13137. }
  13138. for (i = valueTreesWithListeners.size(); --i >= 0;)
  13139. {
  13140. ValueTree* const v = valueTreesWithListeners[i];
  13141. if (v != 0)
  13142. v->deliverParentChangeMessage (tree);
  13143. }
  13144. }
  13145. const var& ValueTree::SharedObject::getProperty (const var::identifier& name) const
  13146. {
  13147. return properties [name];
  13148. }
  13149. void ValueTree::SharedObject::setProperty (const var::identifier& name, const var& newValue, UndoManager* const undoManager)
  13150. {
  13151. if (undoManager == 0)
  13152. {
  13153. if (properties.set (name, newValue))
  13154. sendPropertyChangeMessage (name);
  13155. }
  13156. else
  13157. {
  13158. var* const existingValue = properties.getItem (name);
  13159. if (existingValue != 0)
  13160. {
  13161. if (*existingValue != newValue)
  13162. undoManager->perform (new ValueTreeSetPropertyAction (this, name, newValue, false, false));
  13163. }
  13164. else
  13165. {
  13166. undoManager->perform (new ValueTreeSetPropertyAction (this, name, newValue, true, false));
  13167. }
  13168. }
  13169. }
  13170. bool ValueTree::SharedObject::hasProperty (const var::identifier& name) const
  13171. {
  13172. return properties.contains (name);
  13173. }
  13174. void ValueTree::SharedObject::removeProperty (const var::identifier& name, UndoManager* const undoManager)
  13175. {
  13176. if (undoManager == 0)
  13177. {
  13178. if (properties.remove (name))
  13179. sendPropertyChangeMessage (name);
  13180. }
  13181. else
  13182. {
  13183. if (properties.contains (name))
  13184. undoManager->perform (new ValueTreeSetPropertyAction (this, name, var::null, false, true));
  13185. }
  13186. }
  13187. void ValueTree::SharedObject::removeAllProperties (UndoManager* const undoManager)
  13188. {
  13189. if (undoManager == 0)
  13190. {
  13191. while (properties.size() > 0)
  13192. {
  13193. const var::identifier name (properties.getName (properties.size() - 1));
  13194. properties.remove (name);
  13195. sendPropertyChangeMessage (name);
  13196. }
  13197. }
  13198. else
  13199. {
  13200. for (int i = properties.size(); --i >= 0;)
  13201. undoManager->perform (new ValueTreeSetPropertyAction (this, properties.getName(i), var::null, false, true));
  13202. }
  13203. }
  13204. ValueTree ValueTree::SharedObject::getChildWithName (const String& typeToMatch) const
  13205. {
  13206. for (int i = 0; i < children.size(); ++i)
  13207. if (children.getUnchecked(i)->type == typeToMatch)
  13208. return (SharedObject*) children.getUnchecked(i);
  13209. return (SharedObject*) 0;
  13210. }
  13211. ValueTree ValueTree::SharedObject::getChildWithProperty (const var::identifier& propertyName, const var& propertyValue) const
  13212. {
  13213. for (int i = 0; i < children.size(); ++i)
  13214. if (children.getUnchecked(i)->getProperty (propertyName) == propertyValue)
  13215. return (SharedObject*) children.getUnchecked(i);
  13216. return (SharedObject*) 0;
  13217. }
  13218. bool ValueTree::SharedObject::isAChildOf (const SharedObject* const possibleParent) const
  13219. {
  13220. const SharedObject* p = parent;
  13221. while (p != 0)
  13222. {
  13223. if (p == possibleParent)
  13224. return true;
  13225. p = p->parent;
  13226. }
  13227. return false;
  13228. }
  13229. void ValueTree::SharedObject::addChild (SharedObject* child, int index, UndoManager* const undoManager)
  13230. {
  13231. if (child != 0 && child->parent != this)
  13232. {
  13233. if (child != this && ! isAChildOf (child))
  13234. {
  13235. // You should always make sure that a child is removed from its previous parent before
  13236. // adding it somewhere else - otherwise, it's ambiguous as to whether a different
  13237. // undomanager should be used when removing it from its current parent..
  13238. jassert (child->parent == 0);
  13239. if (child->parent != 0)
  13240. {
  13241. jassert (child->parent->children.indexOf (child) >= 0);
  13242. child->parent->removeChild (child->parent->children.indexOf (child), undoManager);
  13243. }
  13244. if (undoManager == 0)
  13245. {
  13246. children.insert (index, child);
  13247. child->parent = this;
  13248. sendChildChangeMessage();
  13249. child->sendParentChangeMessage();
  13250. }
  13251. else
  13252. {
  13253. undoManager->perform (new ValueTreeChildChangeAction (this, index, child));
  13254. }
  13255. }
  13256. else
  13257. {
  13258. // You're attempting to create a recursive loop! A node
  13259. // can't be a child of one of its own children!
  13260. jassertfalse
  13261. }
  13262. }
  13263. }
  13264. void ValueTree::SharedObject::removeChild (const int childIndex, UndoManager* const undoManager)
  13265. {
  13266. const SharedObjectPtr child (children [childIndex]);
  13267. if (child != 0)
  13268. {
  13269. if (undoManager == 0)
  13270. {
  13271. children.remove (childIndex);
  13272. child->parent = 0;
  13273. sendChildChangeMessage();
  13274. child->sendParentChangeMessage();
  13275. }
  13276. else
  13277. {
  13278. undoManager->perform (new ValueTreeChildChangeAction (this, childIndex, 0));
  13279. }
  13280. }
  13281. }
  13282. void ValueTree::SharedObject::removeAllChildren (UndoManager* const undoManager)
  13283. {
  13284. while (children.size() > 0)
  13285. removeChild (children.size() - 1, undoManager);
  13286. }
  13287. ValueTree::ValueTree (const String& type_)
  13288. : object (new ValueTree::SharedObject (type_))
  13289. {
  13290. jassert (type_.isNotEmpty()); // All objects should be given a sensible type name!
  13291. }
  13292. ValueTree::ValueTree (SharedObject* const object_)
  13293. : object (object_)
  13294. {
  13295. }
  13296. ValueTree::ValueTree (const ValueTree& other)
  13297. : object (other.object)
  13298. {
  13299. }
  13300. const ValueTree& ValueTree::operator= (const ValueTree& other)
  13301. {
  13302. if (listeners.size() > 0)
  13303. {
  13304. if (object != 0)
  13305. object->valueTreesWithListeners.removeValue (this);
  13306. if (other.object != 0)
  13307. other.object->valueTreesWithListeners.add (this);
  13308. }
  13309. object = other.object;
  13310. return *this;
  13311. }
  13312. ValueTree::~ValueTree()
  13313. {
  13314. if (listeners.size() > 0 && object != 0)
  13315. object->valueTreesWithListeners.removeValue (this);
  13316. }
  13317. bool ValueTree::operator== (const ValueTree& other) const
  13318. {
  13319. return object == other.object;
  13320. }
  13321. bool ValueTree::operator!= (const ValueTree& other) const
  13322. {
  13323. return object != other.object;
  13324. }
  13325. ValueTree ValueTree::createCopy() const
  13326. {
  13327. return ValueTree (object != 0 ? new SharedObject (*object) : 0);
  13328. }
  13329. bool ValueTree::hasType (const String& typeName) const
  13330. {
  13331. return object != 0 && object->type == typeName;
  13332. }
  13333. const String ValueTree::getType() const
  13334. {
  13335. return object != 0 ? object->type : String::empty;
  13336. }
  13337. ValueTree ValueTree::getParent() const
  13338. {
  13339. return object != 0 ? ValueTree (object->parent) : ValueTree ((SharedObject*) 0);
  13340. }
  13341. const var& ValueTree::operator[] (const var::identifier& name) const
  13342. {
  13343. return object == 0 ? var::null : object->getProperty (name);
  13344. }
  13345. const var& ValueTree::getProperty (const var::identifier& name) const
  13346. {
  13347. return object == 0 ? var::null : object->getProperty (name);
  13348. }
  13349. void ValueTree::setProperty (const var::identifier& name, const var& newValue, UndoManager* const undoManager)
  13350. {
  13351. jassert (name.name.isNotEmpty());
  13352. if (object != 0 && name.name.isNotEmpty())
  13353. object->setProperty (name, newValue, undoManager);
  13354. }
  13355. bool ValueTree::hasProperty (const var::identifier& name) const
  13356. {
  13357. return object != 0 && object->hasProperty (name);
  13358. }
  13359. void ValueTree::removeProperty (const var::identifier& name, UndoManager* const undoManager)
  13360. {
  13361. if (object != 0)
  13362. object->removeProperty (name, undoManager);
  13363. }
  13364. void ValueTree::removeAllProperties (UndoManager* const undoManager)
  13365. {
  13366. if (object != 0)
  13367. object->removeAllProperties (undoManager);
  13368. }
  13369. int ValueTree::getNumProperties() const
  13370. {
  13371. return object == 0 ? 0 : object->properties.size();
  13372. }
  13373. const var::identifier ValueTree::getPropertyName (int index) const
  13374. {
  13375. return (object == 0) ? var::identifier()
  13376. : object->properties.getName (index);
  13377. }
  13378. class ValueTreePropertyValueSource : public Value::ValueSource,
  13379. public ValueTree::Listener
  13380. {
  13381. public:
  13382. ValueTreePropertyValueSource (const ValueTree& tree_,
  13383. const var::identifier& property_,
  13384. UndoManager* const undoManager_)
  13385. : tree (tree_),
  13386. property (property_),
  13387. undoManager (undoManager_)
  13388. {
  13389. tree.addListener (this);
  13390. }
  13391. ~ValueTreePropertyValueSource()
  13392. {
  13393. tree.removeListener (this);
  13394. }
  13395. const var getValue() const
  13396. {
  13397. return tree [property];
  13398. }
  13399. void setValue (const var& newValue)
  13400. {
  13401. tree.setProperty (property, newValue, undoManager);
  13402. }
  13403. void valueTreePropertyChanged (ValueTree& treeWhosePropertyHasChanged, const var::identifier& changedProperty)
  13404. {
  13405. if (tree == treeWhosePropertyHasChanged && property == changedProperty)
  13406. sendChangeMessage (false);
  13407. }
  13408. void valueTreeChildrenChanged (ValueTree&) {}
  13409. void valueTreeParentChanged (ValueTree&) {}
  13410. private:
  13411. ValueTree tree;
  13412. const var::identifier property;
  13413. UndoManager* const undoManager;
  13414. const ValueTreePropertyValueSource& operator= (const ValueTreePropertyValueSource&);
  13415. };
  13416. Value ValueTree::getPropertyAsValue (const var::identifier& name, UndoManager* const undoManager) const
  13417. {
  13418. return Value (new ValueTreePropertyValueSource (*this, name, undoManager));
  13419. }
  13420. int ValueTree::getNumChildren() const
  13421. {
  13422. return object == 0 ? 0 : object->children.size();
  13423. }
  13424. ValueTree ValueTree::getChild (int index) const
  13425. {
  13426. return object != 0 ? (SharedObject*) object->children [index] : ValueTree ((SharedObject*) 0);
  13427. }
  13428. ValueTree ValueTree::getChildWithName (const String& type) const
  13429. {
  13430. return object != 0 ? object->getChildWithName (type) : ValueTree ((SharedObject*) 0);
  13431. }
  13432. ValueTree ValueTree::getChildWithProperty (const var::identifier& propertyName, const var& propertyValue) const
  13433. {
  13434. return object != 0 ? object->getChildWithProperty (propertyName, propertyValue) : ValueTree ((SharedObject*) 0);
  13435. }
  13436. bool ValueTree::isAChildOf (const ValueTree& possibleParent) const
  13437. {
  13438. return object != 0 && object->isAChildOf (possibleParent.object);
  13439. }
  13440. void ValueTree::addChild (ValueTree child, int index, UndoManager* const undoManager)
  13441. {
  13442. if (object != 0)
  13443. object->addChild (child.object, index, undoManager);
  13444. }
  13445. void ValueTree::removeChild (const int childIndex, UndoManager* const undoManager)
  13446. {
  13447. if (object != 0)
  13448. object->removeChild (childIndex, undoManager);
  13449. }
  13450. void ValueTree::removeChild (ValueTree& child, UndoManager* const undoManager)
  13451. {
  13452. if (object != 0)
  13453. object->removeChild (object->children.indexOf (child.object), undoManager);
  13454. }
  13455. void ValueTree::removeAllChildren (UndoManager* const undoManager)
  13456. {
  13457. if (object != 0)
  13458. object->removeAllChildren (undoManager);
  13459. }
  13460. void ValueTree::addListener (Listener* listener)
  13461. {
  13462. if (listener != 0)
  13463. {
  13464. if (listeners.size() == 0 && object != 0)
  13465. object->valueTreesWithListeners.add (this);
  13466. listeners.add (listener);
  13467. }
  13468. }
  13469. void ValueTree::removeListener (Listener* listener)
  13470. {
  13471. listeners.removeValue (listener);
  13472. if (listeners.size() == 0 && object != 0)
  13473. object->valueTreesWithListeners.removeValue (this);
  13474. }
  13475. XmlElement* ValueTree::SharedObject::createXml() const
  13476. {
  13477. XmlElement* xml = new XmlElement (type);
  13478. int i;
  13479. for (i = 0; i < properties.size(); ++i)
  13480. {
  13481. var::identifier name (properties.getName(i));
  13482. const var& v = properties [name];
  13483. jassert (! v.isObject()); // DynamicObjects can't be stored as XML!
  13484. xml->setAttribute (name.name, v.toString());
  13485. }
  13486. for (i = 0; i < children.size(); ++i)
  13487. xml->addChildElement (children.getUnchecked(i)->createXml());
  13488. return xml;
  13489. }
  13490. XmlElement* ValueTree::createXml() const
  13491. {
  13492. return object != 0 ? object->createXml() : 0;
  13493. }
  13494. ValueTree ValueTree::fromXml (const XmlElement& xml)
  13495. {
  13496. ValueTree v (xml.getTagName());
  13497. const int numAtts = xml.getNumAttributes(); // xxx inefficient - should write an att iterator..
  13498. for (int i = 0; i < numAtts; ++i)
  13499. v.setProperty (xml.getAttributeName (i), var (xml.getAttributeValue (i)), 0);
  13500. forEachXmlChildElement (xml, e)
  13501. {
  13502. v.addChild (fromXml (*e), -1, 0);
  13503. }
  13504. return v;
  13505. }
  13506. void ValueTree::writeToStream (OutputStream& output)
  13507. {
  13508. output.writeString (getType());
  13509. const int numProps = getNumProperties();
  13510. output.writeCompressedInt (numProps);
  13511. int i;
  13512. for (i = 0; i < numProps; ++i)
  13513. {
  13514. const var::identifier name (getPropertyName(i));
  13515. output.writeString (name.name);
  13516. getProperty(name).writeToStream (output);
  13517. }
  13518. const int numChildren = getNumChildren();
  13519. output.writeCompressedInt (numChildren);
  13520. for (i = 0; i < numChildren; ++i)
  13521. getChild (i).writeToStream (output);
  13522. }
  13523. ValueTree ValueTree::readFromStream (InputStream& input)
  13524. {
  13525. String type (input.readString());
  13526. if (type.isEmpty())
  13527. return ValueTree ((SharedObject*) 0);
  13528. ValueTree v (type);
  13529. const int numProps = input.readCompressedInt();
  13530. if (numProps < 0)
  13531. {
  13532. jassertfalse // trying to read corrupted data!
  13533. return v;
  13534. }
  13535. int i;
  13536. for (i = 0; i < numProps; ++i)
  13537. {
  13538. const String name (input.readString());
  13539. jassert (name.isNotEmpty());
  13540. const var value (var::readFromStream (input));
  13541. v.setProperty (name, value, 0);
  13542. }
  13543. const int numChildren = input.readCompressedInt();
  13544. for (i = 0; i < numChildren; ++i)
  13545. v.addChild (readFromStream (input), -1, 0);
  13546. return v;
  13547. }
  13548. END_JUCE_NAMESPACE
  13549. /*** End of inlined file: juce_ValueTree.cpp ***/
  13550. /*** Start of inlined file: juce_Value.cpp ***/
  13551. BEGIN_JUCE_NAMESPACE
  13552. Value::ValueSource::ValueSource()
  13553. {
  13554. }
  13555. Value::ValueSource::~ValueSource()
  13556. {
  13557. }
  13558. void Value::ValueSource::sendChangeMessage (const bool synchronous)
  13559. {
  13560. if (synchronous)
  13561. {
  13562. for (int i = valuesWithListeners.size(); --i >= 0;)
  13563. {
  13564. Value* const v = valuesWithListeners[i];
  13565. if (v != 0)
  13566. v->callListeners();
  13567. }
  13568. }
  13569. else
  13570. {
  13571. triggerAsyncUpdate();
  13572. }
  13573. }
  13574. void Value::ValueSource::handleAsyncUpdate()
  13575. {
  13576. sendChangeMessage (true);
  13577. }
  13578. class SimpleValueSource : public Value::ValueSource
  13579. {
  13580. public:
  13581. SimpleValueSource()
  13582. {
  13583. }
  13584. SimpleValueSource (const var& initialValue)
  13585. : value (initialValue)
  13586. {
  13587. }
  13588. ~SimpleValueSource()
  13589. {
  13590. }
  13591. const var getValue() const
  13592. {
  13593. return value;
  13594. }
  13595. void setValue (const var& newValue)
  13596. {
  13597. if (newValue != value)
  13598. {
  13599. value = newValue;
  13600. sendChangeMessage (false);
  13601. }
  13602. }
  13603. private:
  13604. var value;
  13605. SimpleValueSource (const SimpleValueSource&);
  13606. const SimpleValueSource& operator= (const SimpleValueSource&);
  13607. };
  13608. Value::Value()
  13609. : value (new SimpleValueSource())
  13610. {
  13611. }
  13612. Value::Value (ValueSource* const value_)
  13613. : value (value_)
  13614. {
  13615. jassert (value_ != 0);
  13616. }
  13617. Value::Value (const var& initialValue)
  13618. : value (new SimpleValueSource (initialValue))
  13619. {
  13620. }
  13621. Value::Value (const Value& other)
  13622. : value (other.value)
  13623. {
  13624. }
  13625. const Value& Value::operator= (const Value& other)
  13626. {
  13627. value = other.value;
  13628. return *this;
  13629. }
  13630. Value::~Value()
  13631. {
  13632. if (listeners.size() > 0)
  13633. value->valuesWithListeners.removeValue (this);
  13634. }
  13635. const var Value::getValue() const
  13636. {
  13637. return value->getValue();
  13638. }
  13639. void Value::setValue (const var& newValue)
  13640. {
  13641. value->setValue (newValue);
  13642. }
  13643. const String Value::toString() const
  13644. {
  13645. return value->getValue().toString();
  13646. }
  13647. const Value& Value::operator= (const var& newValue)
  13648. {
  13649. value->setValue (newValue);
  13650. return *this;
  13651. }
  13652. void Value::referTo (const Value& valueToReferTo)
  13653. {
  13654. if (valueToReferTo.value != value)
  13655. {
  13656. if (listeners.size() > 0)
  13657. {
  13658. value->valuesWithListeners.removeValue (this);
  13659. valueToReferTo.value->valuesWithListeners.add (this);
  13660. }
  13661. value = valueToReferTo.value;
  13662. callListeners();
  13663. }
  13664. }
  13665. bool Value::refersToSameSourceAs (const Value& other) const
  13666. {
  13667. return value == other.value;
  13668. }
  13669. bool Value::operator== (const Value& other) const
  13670. {
  13671. return value == other.value || value->getValue() == other.getValue();
  13672. }
  13673. bool Value::operator!= (const Value& other) const
  13674. {
  13675. return value != other.value && value->getValue() != other.getValue();
  13676. }
  13677. void Value::addListener (Listener* const listener)
  13678. {
  13679. if (listener != 0)
  13680. {
  13681. if (listeners.size() == 0)
  13682. value->valuesWithListeners.add (this);
  13683. listeners.add (listener);
  13684. }
  13685. }
  13686. void Value::removeListener (Listener* const listener)
  13687. {
  13688. listeners.removeValue (listener);
  13689. if (listeners.size() == 0)
  13690. value->valuesWithListeners.removeValue (this);
  13691. }
  13692. void Value::callListeners()
  13693. {
  13694. Value valueCopy (*this); // Use a copy in case this object gets deleted by a callback
  13695. for (int i = listeners.size(); --i >= 0;)
  13696. {
  13697. Listener* const l = listeners[i];
  13698. if (l != 0)
  13699. l->valueChanged (valueCopy);
  13700. }
  13701. }
  13702. END_JUCE_NAMESPACE
  13703. /*** End of inlined file: juce_Value.cpp ***/
  13704. /*** Start of inlined file: juce_Application.cpp ***/
  13705. #if JUCE_MSVC
  13706. #pragma warning (push)
  13707. #pragma warning (disable: 4245 4514 4100)
  13708. #include <crtdbg.h>
  13709. #pragma warning (pop)
  13710. #endif
  13711. BEGIN_JUCE_NAMESPACE
  13712. void juce_setCurrentThreadName (const String& name);
  13713. static JUCEApplication* appInstance = 0;
  13714. JUCEApplication::JUCEApplication()
  13715. : appReturnValue (0),
  13716. stillInitialising (true),
  13717. appLock (0)
  13718. {
  13719. }
  13720. JUCEApplication::~JUCEApplication()
  13721. {
  13722. if (appLock != 0)
  13723. {
  13724. appLock->exit();
  13725. delete appLock;
  13726. }
  13727. }
  13728. JUCEApplication* JUCEApplication::getInstance() throw()
  13729. {
  13730. return appInstance;
  13731. }
  13732. bool JUCEApplication::isInitialising() const throw()
  13733. {
  13734. return stillInitialising;
  13735. }
  13736. const String JUCEApplication::getApplicationVersion()
  13737. {
  13738. return String::empty;
  13739. }
  13740. bool JUCEApplication::moreThanOneInstanceAllowed()
  13741. {
  13742. return true;
  13743. }
  13744. void JUCEApplication::anotherInstanceStarted (const String&)
  13745. {
  13746. }
  13747. void JUCEApplication::systemRequestedQuit()
  13748. {
  13749. quit();
  13750. }
  13751. void JUCEApplication::quit()
  13752. {
  13753. MessageManager::getInstance()->stopDispatchLoop();
  13754. }
  13755. void JUCEApplication::setApplicationReturnValue (const int newReturnValue) throw()
  13756. {
  13757. appReturnValue = newReturnValue;
  13758. }
  13759. void JUCEApplication::unhandledException (const std::exception*,
  13760. const String&,
  13761. const int)
  13762. {
  13763. jassertfalse
  13764. }
  13765. void JUCEApplication::sendUnhandledException (const std::exception* const e,
  13766. const char* const sourceFile,
  13767. const int lineNumber)
  13768. {
  13769. if (appInstance != 0)
  13770. appInstance->unhandledException (e, sourceFile, lineNumber);
  13771. }
  13772. ApplicationCommandTarget* JUCEApplication::getNextCommandTarget()
  13773. {
  13774. return 0;
  13775. }
  13776. void JUCEApplication::getAllCommands (Array <CommandID>& commands)
  13777. {
  13778. commands.add (StandardApplicationCommandIDs::quit);
  13779. }
  13780. void JUCEApplication::getCommandInfo (const CommandID commandID, ApplicationCommandInfo& result)
  13781. {
  13782. if (commandID == StandardApplicationCommandIDs::quit)
  13783. {
  13784. result.setInfo (TRANS("Quit"),
  13785. TRANS("Quits the application"),
  13786. "Application",
  13787. 0);
  13788. result.defaultKeypresses.add (KeyPress (T('q'), ModifierKeys::commandModifier, 0));
  13789. }
  13790. }
  13791. bool JUCEApplication::perform (const InvocationInfo& info)
  13792. {
  13793. if (info.commandID == StandardApplicationCommandIDs::quit)
  13794. {
  13795. systemRequestedQuit();
  13796. return true;
  13797. }
  13798. return false;
  13799. }
  13800. int JUCEApplication::main (String& commandLine, JUCEApplication* const app)
  13801. {
  13802. if (! app->initialiseApp (commandLine))
  13803. return 0;
  13804. // now loop until a quit message is received..
  13805. JUCE_TRY
  13806. {
  13807. MessageManager::getInstance()->runDispatchLoop();
  13808. }
  13809. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  13810. catch (const std::exception& e)
  13811. {
  13812. app->unhandledException (&e, __FILE__, __LINE__);
  13813. }
  13814. catch (...)
  13815. {
  13816. app->unhandledException (0, __FILE__, __LINE__);
  13817. }
  13818. #endif
  13819. return shutdownAppAndClearUp();
  13820. }
  13821. bool JUCEApplication::initialiseApp (String& commandLine)
  13822. {
  13823. jassert (appInstance == 0);
  13824. appInstance = this;
  13825. commandLineParameters = commandLine.trim();
  13826. commandLine = String::empty;
  13827. initialiseJuce_GUI();
  13828. #if ! JUCE_IPHONE
  13829. jassert (appLock == 0); // initialiseApp must only be called once!
  13830. if (! moreThanOneInstanceAllowed())
  13831. {
  13832. appLock = new InterProcessLock ("juceAppLock_" + getApplicationName());
  13833. if (! appLock->enter(0))
  13834. {
  13835. MessageManager::broadcastMessage (getApplicationName() + "/" + commandLineParameters);
  13836. delete appInstance;
  13837. appInstance = 0;
  13838. DBG ("Another instance is running - quitting...");
  13839. return false;
  13840. }
  13841. }
  13842. #endif
  13843. // let the app do its setting-up..
  13844. initialise (commandLineParameters);
  13845. // register for broadcast new app messages
  13846. MessageManager::getInstance()->registerBroadcastListener (this);
  13847. stillInitialising = false;
  13848. return true;
  13849. }
  13850. int JUCEApplication::shutdownAppAndClearUp()
  13851. {
  13852. jassert (appInstance != 0);
  13853. JUCEApplication* const app = appInstance;
  13854. int returnValue = 0;
  13855. MessageManager::getInstance()->deregisterBroadcastListener (app);
  13856. static bool reentrancyCheck = false;
  13857. if (! reentrancyCheck)
  13858. {
  13859. reentrancyCheck = true;
  13860. JUCE_TRY
  13861. {
  13862. // give the app a chance to clean up..
  13863. app->shutdown();
  13864. }
  13865. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  13866. catch (const std::exception& e)
  13867. {
  13868. app->unhandledException (&e, __FILE__, __LINE__);
  13869. }
  13870. catch (...)
  13871. {
  13872. app->unhandledException (0, __FILE__, __LINE__);
  13873. }
  13874. #endif
  13875. JUCE_TRY
  13876. {
  13877. shutdownJuce_GUI();
  13878. returnValue = app->getApplicationReturnValue();
  13879. appInstance = 0;
  13880. delete app;
  13881. }
  13882. JUCE_CATCH_ALL_ASSERT
  13883. reentrancyCheck = false;
  13884. }
  13885. return returnValue;
  13886. }
  13887. #if JUCE_IPHONE
  13888. extern int juce_IPhoneMain (int argc, char* argv[], JUCEApplication* app);
  13889. #endif
  13890. #if ! JUCE_WINDOWS
  13891. extern const char* juce_Argv0;
  13892. #endif
  13893. int JUCEApplication::main (int argc, char* argv[],
  13894. JUCEApplication* const newApp)
  13895. {
  13896. #if ! JUCE_WINDOWS
  13897. juce_Argv0 = argv[0];
  13898. #endif
  13899. #if JUCE_IPHONE
  13900. const ScopedAutoReleasePool pool;
  13901. return juce_IPhoneMain (argc, argv, newApp);
  13902. #else
  13903. #if JUCE_MAC
  13904. const ScopedAutoReleasePool pool;
  13905. #endif
  13906. String cmd;
  13907. for (int i = 1; i < argc; ++i)
  13908. cmd << String::fromUTF8 ((const uint8*) argv[i]) << T(' ');
  13909. return JUCEApplication::main (cmd, newApp);
  13910. #endif
  13911. }
  13912. void JUCEApplication::actionListenerCallback (const String& message)
  13913. {
  13914. if (message.startsWith (getApplicationName() + "/"))
  13915. anotherInstanceStarted (message.substring (getApplicationName().length() + 1));
  13916. }
  13917. static bool juceInitialisedGUI = false;
  13918. void JUCE_PUBLIC_FUNCTION initialiseJuce_GUI()
  13919. {
  13920. if (! juceInitialisedGUI)
  13921. {
  13922. #if JUCE_MAC || JUCE_IPHONE
  13923. const ScopedAutoReleasePool pool;
  13924. #endif
  13925. juceInitialisedGUI = true;
  13926. initialiseJuce_NonGUI();
  13927. MessageManager::getInstance();
  13928. LookAndFeel::setDefaultLookAndFeel (0);
  13929. juce_setCurrentThreadName ("Juce Message Thread");
  13930. #if JUCE_WINDOWS && JUCE_DEBUG
  13931. // This section is just for catching people who mess up their project settings and
  13932. // turn RTTI off..
  13933. try
  13934. {
  13935. TextButton tb (String::empty);
  13936. Component* c = &tb;
  13937. // Got an exception here? Then TURN ON RTTI in your compiler settings!!
  13938. c = dynamic_cast <Button*> (c);
  13939. }
  13940. catch (...)
  13941. {
  13942. // Ended up here? If so, TURN ON RTTI in your compiler settings!! And if you
  13943. // got as far as this catch statement, then why haven't you got exception catching
  13944. // turned on in the debugger???
  13945. jassertfalse
  13946. }
  13947. #endif
  13948. }
  13949. }
  13950. void JUCE_PUBLIC_FUNCTION shutdownJuce_GUI()
  13951. {
  13952. if (juceInitialisedGUI)
  13953. {
  13954. #if JUCE_MAC
  13955. const ScopedAutoReleasePool pool;
  13956. #endif
  13957. {
  13958. DeletedAtShutdown::deleteAll();
  13959. LookAndFeel::clearDefaultLookAndFeel();
  13960. }
  13961. delete MessageManager::getInstance();
  13962. shutdownJuce_NonGUI();
  13963. juceInitialisedGUI = false;
  13964. }
  13965. }
  13966. END_JUCE_NAMESPACE
  13967. /*** End of inlined file: juce_Application.cpp ***/
  13968. /*** Start of inlined file: juce_ApplicationCommandInfo.cpp ***/
  13969. BEGIN_JUCE_NAMESPACE
  13970. ApplicationCommandInfo::ApplicationCommandInfo (const CommandID commandID_) throw()
  13971. : commandID (commandID_),
  13972. flags (0)
  13973. {
  13974. }
  13975. void ApplicationCommandInfo::setInfo (const String& shortName_,
  13976. const String& description_,
  13977. const String& categoryName_,
  13978. const int flags_) throw()
  13979. {
  13980. shortName = shortName_;
  13981. description = description_;
  13982. categoryName = categoryName_;
  13983. flags = flags_;
  13984. }
  13985. void ApplicationCommandInfo::setActive (const bool b) throw()
  13986. {
  13987. if (b)
  13988. flags &= ~isDisabled;
  13989. else
  13990. flags |= isDisabled;
  13991. }
  13992. void ApplicationCommandInfo::setTicked (const bool b) throw()
  13993. {
  13994. if (b)
  13995. flags |= isTicked;
  13996. else
  13997. flags &= ~isTicked;
  13998. }
  13999. void ApplicationCommandInfo::addDefaultKeypress (const int keyCode, const ModifierKeys& modifiers) throw()
  14000. {
  14001. defaultKeypresses.add (KeyPress (keyCode, modifiers, 0));
  14002. }
  14003. END_JUCE_NAMESPACE
  14004. /*** End of inlined file: juce_ApplicationCommandInfo.cpp ***/
  14005. /*** Start of inlined file: juce_ApplicationCommandManager.cpp ***/
  14006. BEGIN_JUCE_NAMESPACE
  14007. ApplicationCommandManager::ApplicationCommandManager()
  14008. : firstTarget (0)
  14009. {
  14010. keyMappings = new KeyPressMappingSet (this);
  14011. Desktop::getInstance().addFocusChangeListener (this);
  14012. }
  14013. ApplicationCommandManager::~ApplicationCommandManager()
  14014. {
  14015. Desktop::getInstance().removeFocusChangeListener (this);
  14016. keyMappings = 0;
  14017. }
  14018. void ApplicationCommandManager::clearCommands()
  14019. {
  14020. commands.clear();
  14021. keyMappings->clearAllKeyPresses();
  14022. triggerAsyncUpdate();
  14023. }
  14024. void ApplicationCommandManager::registerCommand (const ApplicationCommandInfo& newCommand)
  14025. {
  14026. // zero isn't a valid command ID!
  14027. jassert (newCommand.commandID != 0);
  14028. // the name isn't optional!
  14029. jassert (newCommand.shortName.isNotEmpty());
  14030. if (getCommandForID (newCommand.commandID) == 0)
  14031. {
  14032. ApplicationCommandInfo* const newInfo = new ApplicationCommandInfo (newCommand);
  14033. newInfo->flags &= ~ApplicationCommandInfo::isTicked;
  14034. commands.add (newInfo);
  14035. keyMappings->resetToDefaultMapping (newCommand.commandID);
  14036. triggerAsyncUpdate();
  14037. }
  14038. else
  14039. {
  14040. // trying to re-register the same command with different parameters?
  14041. jassert (newCommand.shortName == getCommandForID (newCommand.commandID)->shortName
  14042. && (newCommand.description == getCommandForID (newCommand.commandID)->description || newCommand.description.isEmpty())
  14043. && newCommand.categoryName == getCommandForID (newCommand.commandID)->categoryName
  14044. && newCommand.defaultKeypresses == getCommandForID (newCommand.commandID)->defaultKeypresses
  14045. && (newCommand.flags & (ApplicationCommandInfo::wantsKeyUpDownCallbacks | ApplicationCommandInfo::hiddenFromKeyEditor | ApplicationCommandInfo::readOnlyInKeyEditor))
  14046. == (getCommandForID (newCommand.commandID)->flags & (ApplicationCommandInfo::wantsKeyUpDownCallbacks | ApplicationCommandInfo::hiddenFromKeyEditor | ApplicationCommandInfo::readOnlyInKeyEditor)));
  14047. }
  14048. }
  14049. void ApplicationCommandManager::registerAllCommandsForTarget (ApplicationCommandTarget* target)
  14050. {
  14051. if (target != 0)
  14052. {
  14053. Array <CommandID> commandIDs;
  14054. target->getAllCommands (commandIDs);
  14055. for (int i = 0; i < commandIDs.size(); ++i)
  14056. {
  14057. ApplicationCommandInfo info (commandIDs.getUnchecked(i));
  14058. target->getCommandInfo (info.commandID, info);
  14059. registerCommand (info);
  14060. }
  14061. }
  14062. }
  14063. void ApplicationCommandManager::removeCommand (const CommandID commandID)
  14064. {
  14065. for (int i = commands.size(); --i >= 0;)
  14066. {
  14067. if (commands.getUnchecked (i)->commandID == commandID)
  14068. {
  14069. commands.remove (i);
  14070. triggerAsyncUpdate();
  14071. const Array <KeyPress> keys (keyMappings->getKeyPressesAssignedToCommand (commandID));
  14072. for (int j = keys.size(); --j >= 0;)
  14073. keyMappings->removeKeyPress (keys.getReference (j));
  14074. }
  14075. }
  14076. }
  14077. void ApplicationCommandManager::commandStatusChanged()
  14078. {
  14079. triggerAsyncUpdate();
  14080. }
  14081. const ApplicationCommandInfo* ApplicationCommandManager::getCommandForID (const CommandID commandID) const throw()
  14082. {
  14083. for (int i = commands.size(); --i >= 0;)
  14084. if (commands.getUnchecked(i)->commandID == commandID)
  14085. return commands.getUnchecked(i);
  14086. return 0;
  14087. }
  14088. const String ApplicationCommandManager::getNameOfCommand (const CommandID commandID) const throw()
  14089. {
  14090. const ApplicationCommandInfo* const ci = getCommandForID (commandID);
  14091. return (ci != 0) ? ci->shortName : String::empty;
  14092. }
  14093. const String ApplicationCommandManager::getDescriptionOfCommand (const CommandID commandID) const throw()
  14094. {
  14095. const ApplicationCommandInfo* const ci = getCommandForID (commandID);
  14096. return (ci != 0) ? (ci->description.isNotEmpty() ? ci->description : ci->shortName)
  14097. : String::empty;
  14098. }
  14099. const StringArray ApplicationCommandManager::getCommandCategories() const throw()
  14100. {
  14101. StringArray s;
  14102. for (int i = 0; i < commands.size(); ++i)
  14103. s.addIfNotAlreadyThere (commands.getUnchecked(i)->categoryName, false);
  14104. return s;
  14105. }
  14106. const Array <CommandID> ApplicationCommandManager::getCommandsInCategory (const String& categoryName) const throw()
  14107. {
  14108. Array <CommandID> results;
  14109. for (int i = 0; i < commands.size(); ++i)
  14110. if (commands.getUnchecked(i)->categoryName == categoryName)
  14111. results.add (commands.getUnchecked(i)->commandID);
  14112. return results;
  14113. }
  14114. bool ApplicationCommandManager::invokeDirectly (const CommandID commandID, const bool asynchronously)
  14115. {
  14116. ApplicationCommandTarget::InvocationInfo info (commandID);
  14117. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::direct;
  14118. return invoke (info, asynchronously);
  14119. }
  14120. bool ApplicationCommandManager::invoke (const ApplicationCommandTarget::InvocationInfo& info_, const bool asynchronously)
  14121. {
  14122. // This call isn't thread-safe for use from a non-UI thread without locking the message
  14123. // manager first..
  14124. jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  14125. ApplicationCommandTarget* const target = getFirstCommandTarget (info_.commandID);
  14126. if (target == 0)
  14127. return false;
  14128. ApplicationCommandInfo commandInfo (0);
  14129. target->getCommandInfo (info_.commandID, commandInfo);
  14130. ApplicationCommandTarget::InvocationInfo info (info_);
  14131. info.commandFlags = commandInfo.flags;
  14132. sendListenerInvokeCallback (info);
  14133. const bool ok = target->invoke (info, asynchronously);
  14134. commandStatusChanged();
  14135. return ok;
  14136. }
  14137. ApplicationCommandTarget* ApplicationCommandManager::getFirstCommandTarget (const CommandID)
  14138. {
  14139. return firstTarget != 0 ? firstTarget
  14140. : findDefaultComponentTarget();
  14141. }
  14142. void ApplicationCommandManager::setFirstCommandTarget (ApplicationCommandTarget* const newTarget) throw()
  14143. {
  14144. firstTarget = newTarget;
  14145. }
  14146. ApplicationCommandTarget* ApplicationCommandManager::getTargetForCommand (const CommandID commandID,
  14147. ApplicationCommandInfo& upToDateInfo)
  14148. {
  14149. ApplicationCommandTarget* target = getFirstCommandTarget (commandID);
  14150. if (target == 0)
  14151. target = JUCEApplication::getInstance();
  14152. if (target != 0)
  14153. target = target->getTargetForCommand (commandID);
  14154. if (target != 0)
  14155. target->getCommandInfo (commandID, upToDateInfo);
  14156. return target;
  14157. }
  14158. ApplicationCommandTarget* ApplicationCommandManager::findTargetForComponent (Component* c)
  14159. {
  14160. ApplicationCommandTarget* target = dynamic_cast <ApplicationCommandTarget*> (c);
  14161. if (target == 0 && c != 0)
  14162. // (unable to use the syntax findParentComponentOfClass <ApplicationCommandTarget> () because of a VC6 compiler bug)
  14163. target = c->findParentComponentOfClass ((ApplicationCommandTarget*) 0);
  14164. return target;
  14165. }
  14166. ApplicationCommandTarget* ApplicationCommandManager::findDefaultComponentTarget()
  14167. {
  14168. Component* c = Component::getCurrentlyFocusedComponent();
  14169. if (c == 0)
  14170. {
  14171. TopLevelWindow* const activeWindow = TopLevelWindow::getActiveTopLevelWindow();
  14172. if (activeWindow != 0)
  14173. {
  14174. c = activeWindow->getPeer()->getLastFocusedSubcomponent();
  14175. if (c == 0)
  14176. c = activeWindow;
  14177. }
  14178. }
  14179. if (c == 0 && Process::isForegroundProcess())
  14180. {
  14181. // getting a bit desperate now - try all desktop comps..
  14182. for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
  14183. {
  14184. ApplicationCommandTarget* const target
  14185. = findTargetForComponent (Desktop::getInstance().getComponent (i)
  14186. ->getPeer()->getLastFocusedSubcomponent());
  14187. if (target != 0)
  14188. return target;
  14189. }
  14190. }
  14191. if (c != 0)
  14192. {
  14193. ResizableWindow* const resizableWindow = dynamic_cast <ResizableWindow*> (c);
  14194. // if we're focused on a ResizableWindow, chances are that it's the content
  14195. // component that really should get the event. And if not, the event will
  14196. // still be passed up to the top level window anyway, so let's send it to the
  14197. // content comp.
  14198. if (resizableWindow != 0 && resizableWindow->getContentComponent() != 0)
  14199. c = resizableWindow->getContentComponent();
  14200. ApplicationCommandTarget* const target = findTargetForComponent (c);
  14201. if (target != 0)
  14202. return target;
  14203. }
  14204. return JUCEApplication::getInstance();
  14205. }
  14206. void ApplicationCommandManager::addListener (ApplicationCommandManagerListener* const listener) throw()
  14207. {
  14208. jassert (listener != 0);
  14209. if (listener != 0)
  14210. listeners.add (listener);
  14211. }
  14212. void ApplicationCommandManager::removeListener (ApplicationCommandManagerListener* const listener) throw()
  14213. {
  14214. listeners.removeValue (listener);
  14215. }
  14216. void ApplicationCommandManager::sendListenerInvokeCallback (const ApplicationCommandTarget::InvocationInfo& info) const
  14217. {
  14218. for (int i = listeners.size(); --i >= 0;)
  14219. {
  14220. ((ApplicationCommandManagerListener*) listeners.getUnchecked (i))->applicationCommandInvoked (info);
  14221. i = jmin (i, listeners.size());
  14222. }
  14223. }
  14224. void ApplicationCommandManager::handleAsyncUpdate()
  14225. {
  14226. for (int i = listeners.size(); --i >= 0;)
  14227. {
  14228. ((ApplicationCommandManagerListener*) listeners.getUnchecked (i))->applicationCommandListChanged();
  14229. i = jmin (i, listeners.size());
  14230. }
  14231. }
  14232. void ApplicationCommandManager::globalFocusChanged (Component*)
  14233. {
  14234. commandStatusChanged();
  14235. }
  14236. END_JUCE_NAMESPACE
  14237. /*** End of inlined file: juce_ApplicationCommandManager.cpp ***/
  14238. /*** Start of inlined file: juce_ApplicationCommandTarget.cpp ***/
  14239. BEGIN_JUCE_NAMESPACE
  14240. ApplicationCommandTarget::ApplicationCommandTarget()
  14241. {
  14242. }
  14243. ApplicationCommandTarget::~ApplicationCommandTarget()
  14244. {
  14245. messageInvoker = 0;
  14246. }
  14247. bool ApplicationCommandTarget::tryToInvoke (const InvocationInfo& info, const bool async)
  14248. {
  14249. if (isCommandActive (info.commandID))
  14250. {
  14251. if (async)
  14252. {
  14253. if (messageInvoker == 0)
  14254. messageInvoker = new CommandTargetMessageInvoker (this);
  14255. messageInvoker->postMessage (new Message (0, 0, 0, new ApplicationCommandTarget::InvocationInfo (info)));
  14256. return true;
  14257. }
  14258. else
  14259. {
  14260. const bool success = perform (info);
  14261. jassert (success); // hmm - your target should have been able to perform this command. If it can't
  14262. // do it at the moment for some reason, it should clear the 'isActive' flag when it
  14263. // returns the command's info.
  14264. return success;
  14265. }
  14266. }
  14267. return false;
  14268. }
  14269. ApplicationCommandTarget* ApplicationCommandTarget::findFirstTargetParentComponent()
  14270. {
  14271. Component* c = dynamic_cast <Component*> (this);
  14272. if (c != 0)
  14273. // (unable to use the syntax findParentComponentOfClass <ApplicationCommandTarget> () because of a VC6 compiler bug)
  14274. return c->findParentComponentOfClass ((ApplicationCommandTarget*) 0);
  14275. return 0;
  14276. }
  14277. ApplicationCommandTarget* ApplicationCommandTarget::getTargetForCommand (const CommandID commandID)
  14278. {
  14279. ApplicationCommandTarget* target = this;
  14280. int depth = 0;
  14281. while (target != 0)
  14282. {
  14283. Array <CommandID> commandIDs;
  14284. target->getAllCommands (commandIDs);
  14285. if (commandIDs.contains (commandID))
  14286. return target;
  14287. target = target->getNextCommandTarget();
  14288. ++depth;
  14289. jassert (depth < 100); // could be a recursive command chain??
  14290. jassert (target != this); // definitely a recursive command chain!
  14291. if (depth > 100 || target == this)
  14292. break;
  14293. }
  14294. if (target == 0)
  14295. {
  14296. target = JUCEApplication::getInstance();
  14297. if (target != 0)
  14298. {
  14299. Array <CommandID> commandIDs;
  14300. target->getAllCommands (commandIDs);
  14301. if (commandIDs.contains (commandID))
  14302. return target;
  14303. }
  14304. }
  14305. return 0;
  14306. }
  14307. bool ApplicationCommandTarget::isCommandActive (const CommandID commandID)
  14308. {
  14309. ApplicationCommandInfo info (commandID);
  14310. info.flags = ApplicationCommandInfo::isDisabled;
  14311. getCommandInfo (commandID, info);
  14312. return (info.flags & ApplicationCommandInfo::isDisabled) == 0;
  14313. }
  14314. bool ApplicationCommandTarget::invoke (const InvocationInfo& info, const bool async)
  14315. {
  14316. ApplicationCommandTarget* target = this;
  14317. int depth = 0;
  14318. while (target != 0)
  14319. {
  14320. if (target->tryToInvoke (info, async))
  14321. return true;
  14322. target = target->getNextCommandTarget();
  14323. ++depth;
  14324. jassert (depth < 100); // could be a recursive command chain??
  14325. jassert (target != this); // definitely a recursive command chain!
  14326. if (depth > 100 || target == this)
  14327. break;
  14328. }
  14329. if (target == 0)
  14330. {
  14331. target = JUCEApplication::getInstance();
  14332. if (target != 0)
  14333. return target->tryToInvoke (info, async);
  14334. }
  14335. return false;
  14336. }
  14337. bool ApplicationCommandTarget::invokeDirectly (const CommandID commandID, const bool asynchronously)
  14338. {
  14339. ApplicationCommandTarget::InvocationInfo info (commandID);
  14340. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::direct;
  14341. return invoke (info, asynchronously);
  14342. }
  14343. ApplicationCommandTarget::InvocationInfo::InvocationInfo (const CommandID commandID_) throw()
  14344. : commandID (commandID_),
  14345. commandFlags (0),
  14346. invocationMethod (direct),
  14347. originatingComponent (0),
  14348. isKeyDown (false),
  14349. millisecsSinceKeyPressed (0)
  14350. {
  14351. }
  14352. ApplicationCommandTarget::CommandTargetMessageInvoker::CommandTargetMessageInvoker (ApplicationCommandTarget* const owner_)
  14353. : owner (owner_)
  14354. {
  14355. }
  14356. ApplicationCommandTarget::CommandTargetMessageInvoker::~CommandTargetMessageInvoker()
  14357. {
  14358. }
  14359. void ApplicationCommandTarget::CommandTargetMessageInvoker::handleMessage (const Message& message)
  14360. {
  14361. const ScopedPointer <InvocationInfo> info ((InvocationInfo*) message.pointerParameter);
  14362. owner->tryToInvoke (*info, false);
  14363. }
  14364. END_JUCE_NAMESPACE
  14365. /*** End of inlined file: juce_ApplicationCommandTarget.cpp ***/
  14366. /*** Start of inlined file: juce_ApplicationProperties.cpp ***/
  14367. BEGIN_JUCE_NAMESPACE
  14368. juce_ImplementSingleton (ApplicationProperties)
  14369. ApplicationProperties::ApplicationProperties() throw()
  14370. : msBeforeSaving (3000),
  14371. options (PropertiesFile::storeAsBinary),
  14372. commonSettingsAreReadOnly (0)
  14373. {
  14374. }
  14375. ApplicationProperties::~ApplicationProperties()
  14376. {
  14377. closeFiles();
  14378. clearSingletonInstance();
  14379. }
  14380. void ApplicationProperties::setStorageParameters (const String& applicationName,
  14381. const String& fileNameSuffix,
  14382. const String& folderName_,
  14383. const int millisecondsBeforeSaving,
  14384. const int propertiesFileOptions) throw()
  14385. {
  14386. appName = applicationName;
  14387. fileSuffix = fileNameSuffix;
  14388. folderName = folderName_;
  14389. msBeforeSaving = millisecondsBeforeSaving;
  14390. options = propertiesFileOptions;
  14391. }
  14392. bool ApplicationProperties::testWriteAccess (const bool testUserSettings,
  14393. const bool testCommonSettings,
  14394. const bool showWarningDialogOnFailure)
  14395. {
  14396. const bool userOk = (! testUserSettings) || getUserSettings()->save();
  14397. const bool commonOk = (! testCommonSettings) || getCommonSettings (false)->save();
  14398. if (! (userOk && commonOk))
  14399. {
  14400. if (showWarningDialogOnFailure)
  14401. {
  14402. String filenames;
  14403. if (userProps != 0 && ! userOk)
  14404. filenames << '\n' << userProps->getFile().getFullPathName();
  14405. if (commonProps != 0 && ! commonOk)
  14406. filenames << '\n' << commonProps->getFile().getFullPathName();
  14407. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  14408. appName + TRANS(" - Unable to save settings"),
  14409. TRANS("An error occurred when trying to save the application's settings file...\n\nIn order to save and restore its settings, ")
  14410. + appName + TRANS(" needs to be able to write to the following files:\n")
  14411. + filenames
  14412. + TRANS("\n\nMake sure that these files aren't read-only, and that the disk isn't full."));
  14413. }
  14414. return false;
  14415. }
  14416. return true;
  14417. }
  14418. void ApplicationProperties::openFiles() throw()
  14419. {
  14420. // You need to call setStorageParameters() before trying to get hold of the
  14421. // properties!
  14422. jassert (appName.isNotEmpty());
  14423. if (appName.isNotEmpty())
  14424. {
  14425. if (userProps == 0)
  14426. userProps = PropertiesFile::createDefaultAppPropertiesFile (appName, fileSuffix, folderName,
  14427. false, msBeforeSaving, options);
  14428. if (commonProps == 0)
  14429. commonProps = PropertiesFile::createDefaultAppPropertiesFile (appName, fileSuffix, folderName,
  14430. true, msBeforeSaving, options);
  14431. userProps->setFallbackPropertySet (commonProps);
  14432. }
  14433. }
  14434. PropertiesFile* ApplicationProperties::getUserSettings() throw()
  14435. {
  14436. if (userProps == 0)
  14437. openFiles();
  14438. return userProps;
  14439. }
  14440. PropertiesFile* ApplicationProperties::getCommonSettings (const bool returnUserPropsIfReadOnly) throw()
  14441. {
  14442. if (commonProps == 0)
  14443. openFiles();
  14444. if (returnUserPropsIfReadOnly)
  14445. {
  14446. if (commonSettingsAreReadOnly == 0)
  14447. commonSettingsAreReadOnly = commonProps->save() ? -1 : 1;
  14448. if (commonSettingsAreReadOnly > 0)
  14449. return userProps;
  14450. }
  14451. return commonProps;
  14452. }
  14453. bool ApplicationProperties::saveIfNeeded()
  14454. {
  14455. return (userProps == 0 || userProps->saveIfNeeded())
  14456. && (commonProps == 0 || commonProps->saveIfNeeded());
  14457. }
  14458. void ApplicationProperties::closeFiles()
  14459. {
  14460. userProps = 0;
  14461. commonProps = 0;
  14462. }
  14463. END_JUCE_NAMESPACE
  14464. /*** End of inlined file: juce_ApplicationProperties.cpp ***/
  14465. /*** Start of inlined file: juce_DeletedAtShutdown.cpp ***/
  14466. BEGIN_JUCE_NAMESPACE
  14467. static VoidArray objectsToDelete;
  14468. static CriticalSection lock;
  14469. DeletedAtShutdown::DeletedAtShutdown()
  14470. {
  14471. const ScopedLock sl (lock);
  14472. objectsToDelete.add (this);
  14473. }
  14474. DeletedAtShutdown::~DeletedAtShutdown()
  14475. {
  14476. const ScopedLock sl (lock);
  14477. objectsToDelete.removeValue (this);
  14478. }
  14479. void DeletedAtShutdown::deleteAll()
  14480. {
  14481. // make a local copy of the array, so it can't get into a loop if something
  14482. // creates another DeletedAtShutdown object during its destructor.
  14483. lock.enter();
  14484. const VoidArray localCopy (objectsToDelete);
  14485. lock.exit();
  14486. for (int i = localCopy.size(); --i >= 0;)
  14487. {
  14488. JUCE_TRY
  14489. {
  14490. DeletedAtShutdown* deletee = (DeletedAtShutdown*) localCopy.getUnchecked(i);
  14491. // double-check that it's not already been deleted during another object's destructor.
  14492. {
  14493. const ScopedLock sl (lock);
  14494. if (! objectsToDelete.contains (deletee))
  14495. deletee = 0;
  14496. }
  14497. delete deletee;
  14498. }
  14499. JUCE_CATCH_EXCEPTION
  14500. }
  14501. // if no objects got re-created during shutdown, this should have been emptied by their
  14502. // destructors
  14503. jassert (objectsToDelete.size() == 0);
  14504. objectsToDelete.clear(); // just to make sure the array doesn't have any memory still allocated
  14505. }
  14506. END_JUCE_NAMESPACE
  14507. /*** End of inlined file: juce_DeletedAtShutdown.cpp ***/
  14508. /*** Start of inlined file: juce_PropertiesFile.cpp ***/
  14509. BEGIN_JUCE_NAMESPACE
  14510. static const int propFileMagicNumber = ((int) ByteOrder::littleEndianInt ("PROP"));
  14511. static const int propFileMagicNumberCompressed = ((int) ByteOrder::littleEndianInt ("CPRP"));
  14512. static const tchar* const propertyFileXmlTag = T("PROPERTIES");
  14513. static const tchar* const propertyTagName = T("VALUE");
  14514. PropertiesFile::PropertiesFile (const File& f,
  14515. const int millisecondsBeforeSaving,
  14516. const int options_)
  14517. : PropertySet (ignoreCaseOfKeyNames),
  14518. file (f),
  14519. timerInterval (millisecondsBeforeSaving),
  14520. options (options_),
  14521. needsWriting (false)
  14522. {
  14523. // You need to correctly specify just one storage format for the file
  14524. jassert ((options_ & (storeAsBinary | storeAsCompressedBinary | storeAsXML)) == storeAsBinary
  14525. || (options_ & (storeAsBinary | storeAsCompressedBinary | storeAsXML)) == storeAsCompressedBinary
  14526. || (options_ & (storeAsBinary | storeAsCompressedBinary | storeAsXML)) == storeAsXML);
  14527. ScopedPointer <InputStream> fileStream (f.createInputStream());
  14528. if (fileStream != 0)
  14529. {
  14530. int magicNumber = fileStream->readInt();
  14531. if (magicNumber == propFileMagicNumberCompressed)
  14532. {
  14533. fileStream = new GZIPDecompressorInputStream (new SubregionStream (fileStream.release(), 4, -1, true),
  14534. true);
  14535. magicNumber = propFileMagicNumber;
  14536. }
  14537. if (magicNumber == propFileMagicNumber)
  14538. {
  14539. BufferedInputStream in (fileStream.release(), 2048, true);
  14540. int numValues = in.readInt();
  14541. while (--numValues >= 0 && ! in.isExhausted())
  14542. {
  14543. const String key (in.readString());
  14544. const String value (in.readString());
  14545. jassert (key.isNotEmpty());
  14546. if (key.isNotEmpty())
  14547. getAllProperties().set (key, value);
  14548. }
  14549. }
  14550. else
  14551. {
  14552. // Not a binary props file - let's see if it's XML..
  14553. fileStream = 0;
  14554. XmlDocument parser (f);
  14555. ScopedPointer <XmlElement> doc (parser.getDocumentElement (true));
  14556. if (doc != 0 && doc->hasTagName (propertyFileXmlTag))
  14557. {
  14558. doc = parser.getDocumentElement();
  14559. if (doc != 0)
  14560. {
  14561. forEachXmlChildElementWithTagName (*doc, e, propertyTagName)
  14562. {
  14563. const String name (e->getStringAttribute (T("name")));
  14564. if (name.isNotEmpty())
  14565. {
  14566. getAllProperties().set (name,
  14567. e->getFirstChildElement() != 0
  14568. ? e->getFirstChildElement()->createDocument (String::empty, true)
  14569. : e->getStringAttribute (T("val")));
  14570. }
  14571. }
  14572. }
  14573. else
  14574. {
  14575. // must be a pretty broken XML file we're trying to parse here!
  14576. jassertfalse
  14577. }
  14578. }
  14579. }
  14580. }
  14581. }
  14582. PropertiesFile::~PropertiesFile()
  14583. {
  14584. saveIfNeeded();
  14585. }
  14586. bool PropertiesFile::saveIfNeeded()
  14587. {
  14588. const ScopedLock sl (getLock());
  14589. return (! needsWriting) || save();
  14590. }
  14591. bool PropertiesFile::needsToBeSaved() const
  14592. {
  14593. const ScopedLock sl (getLock());
  14594. return needsWriting;
  14595. }
  14596. bool PropertiesFile::save()
  14597. {
  14598. const ScopedLock sl (getLock());
  14599. stopTimer();
  14600. if (file == File::nonexistent
  14601. || file.isDirectory()
  14602. || ! file.getParentDirectory().createDirectory())
  14603. return false;
  14604. if ((options & storeAsXML) != 0)
  14605. {
  14606. XmlElement doc (propertyFileXmlTag);
  14607. for (int i = 0; i < getAllProperties().size(); ++i)
  14608. {
  14609. XmlElement* const e = doc.createNewChildElement (propertyTagName);
  14610. e->setAttribute (T("name"), getAllProperties().getAllKeys() [i]);
  14611. // if the value seems to contain xml, store it as such..
  14612. XmlDocument xmlContent (getAllProperties().getAllValues() [i]);
  14613. XmlElement* const childElement = xmlContent.getDocumentElement();
  14614. if (childElement != 0)
  14615. e->addChildElement (childElement);
  14616. else
  14617. e->setAttribute (T("val"), getAllProperties().getAllValues() [i]);
  14618. }
  14619. return doc.writeToFile (file, String::empty);
  14620. }
  14621. else
  14622. {
  14623. TemporaryFile tempFile (file);
  14624. ScopedPointer <OutputStream> out (tempFile.getFile().createOutputStream());
  14625. if (out != 0)
  14626. {
  14627. if ((options & storeAsCompressedBinary) != 0)
  14628. {
  14629. out->writeInt (propFileMagicNumberCompressed);
  14630. out->flush();
  14631. out = new GZIPCompressorOutputStream (out.release(), 9, true);
  14632. }
  14633. else
  14634. {
  14635. // have you set up the storage option flags correctly?
  14636. jassert ((options & storeAsBinary) != 0);
  14637. out->writeInt (propFileMagicNumber);
  14638. }
  14639. const int numProperties = getAllProperties().size();
  14640. out->writeInt (numProperties);
  14641. for (int i = 0; i < numProperties; ++i)
  14642. {
  14643. out->writeString (getAllProperties().getAllKeys() [i]);
  14644. out->writeString (getAllProperties().getAllValues() [i]);
  14645. }
  14646. out = 0;
  14647. if (tempFile.overwriteTargetFileWithTemporary())
  14648. {
  14649. needsWriting = false;
  14650. return true;
  14651. }
  14652. }
  14653. }
  14654. return false;
  14655. }
  14656. void PropertiesFile::timerCallback()
  14657. {
  14658. saveIfNeeded();
  14659. }
  14660. void PropertiesFile::propertyChanged()
  14661. {
  14662. sendChangeMessage (this);
  14663. needsWriting = true;
  14664. if (timerInterval > 0)
  14665. startTimer (timerInterval);
  14666. else if (timerInterval == 0)
  14667. saveIfNeeded();
  14668. }
  14669. const File PropertiesFile::getDefaultAppSettingsFile (const String& applicationName,
  14670. const String& fileNameSuffix,
  14671. const String& folderName,
  14672. const bool commonToAllUsers)
  14673. {
  14674. // mustn't have illegal characters in this name..
  14675. jassert (applicationName == File::createLegalFileName (applicationName));
  14676. #if JUCE_MAC || JUCE_IPHONE
  14677. File dir (commonToAllUsers ? "/Library/Preferences"
  14678. : "~/Library/Preferences");
  14679. if (folderName.isNotEmpty())
  14680. dir = dir.getChildFile (folderName);
  14681. #endif
  14682. #ifdef JUCE_LINUX
  14683. const File dir ((commonToAllUsers ? T("/var/") : T("~/"))
  14684. + (folderName.isNotEmpty() ? folderName
  14685. : (T(".") + applicationName)));
  14686. #endif
  14687. #if JUCE_WIN32
  14688. File dir (File::getSpecialLocation (commonToAllUsers ? File::commonApplicationDataDirectory
  14689. : File::userApplicationDataDirectory));
  14690. if (dir == File::nonexistent)
  14691. return File::nonexistent;
  14692. dir = dir.getChildFile (folderName.isNotEmpty() ? folderName
  14693. : applicationName);
  14694. #endif
  14695. return dir.getChildFile (applicationName)
  14696. .withFileExtension (fileNameSuffix);
  14697. }
  14698. PropertiesFile* PropertiesFile::createDefaultAppPropertiesFile (const String& applicationName,
  14699. const String& fileNameSuffix,
  14700. const String& folderName,
  14701. const bool commonToAllUsers,
  14702. const int millisecondsBeforeSaving,
  14703. const int propertiesFileOptions)
  14704. {
  14705. const File file (getDefaultAppSettingsFile (applicationName,
  14706. fileNameSuffix,
  14707. folderName,
  14708. commonToAllUsers));
  14709. jassert (file != File::nonexistent);
  14710. if (file == File::nonexistent)
  14711. return 0;
  14712. return new PropertiesFile (file, millisecondsBeforeSaving, propertiesFileOptions);
  14713. }
  14714. END_JUCE_NAMESPACE
  14715. /*** End of inlined file: juce_PropertiesFile.cpp ***/
  14716. /*** Start of inlined file: juce_FileBasedDocument.cpp ***/
  14717. BEGIN_JUCE_NAMESPACE
  14718. FileBasedDocument::FileBasedDocument (const String& fileExtension_,
  14719. const String& fileWildcard_,
  14720. const String& openFileDialogTitle_,
  14721. const String& saveFileDialogTitle_)
  14722. : changedSinceSave (false),
  14723. fileExtension (fileExtension_),
  14724. fileWildcard (fileWildcard_),
  14725. openFileDialogTitle (openFileDialogTitle_),
  14726. saveFileDialogTitle (saveFileDialogTitle_)
  14727. {
  14728. }
  14729. FileBasedDocument::~FileBasedDocument()
  14730. {
  14731. }
  14732. void FileBasedDocument::setChangedFlag (const bool hasChanged)
  14733. {
  14734. changedSinceSave = hasChanged;
  14735. }
  14736. void FileBasedDocument::changed()
  14737. {
  14738. changedSinceSave = true;
  14739. sendChangeMessage (this);
  14740. }
  14741. void FileBasedDocument::setFile (const File& newFile)
  14742. {
  14743. if (documentFile != newFile)
  14744. {
  14745. documentFile = newFile;
  14746. changedSinceSave = true;
  14747. }
  14748. }
  14749. bool FileBasedDocument::loadFrom (const File& newFile,
  14750. const bool showMessageOnFailure)
  14751. {
  14752. MouseCursor::showWaitCursor();
  14753. const File oldFile (documentFile);
  14754. documentFile = newFile;
  14755. String error;
  14756. if (newFile.existsAsFile())
  14757. {
  14758. error = loadDocument (newFile);
  14759. if (error.isEmpty())
  14760. {
  14761. setChangedFlag (false);
  14762. MouseCursor::hideWaitCursor();
  14763. setLastDocumentOpened (newFile);
  14764. return true;
  14765. }
  14766. }
  14767. else
  14768. {
  14769. error = "The file doesn't exist";
  14770. }
  14771. documentFile = oldFile;
  14772. MouseCursor::hideWaitCursor();
  14773. if (showMessageOnFailure)
  14774. {
  14775. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  14776. TRANS("Failed to open file..."),
  14777. TRANS("There was an error while trying to load the file:\n\n")
  14778. + newFile.getFullPathName()
  14779. + T("\n\n")
  14780. + error);
  14781. }
  14782. return false;
  14783. }
  14784. bool FileBasedDocument::loadFromUserSpecifiedFile (const bool showMessageOnFailure)
  14785. {
  14786. FileChooser fc (openFileDialogTitle,
  14787. getLastDocumentOpened(),
  14788. fileWildcard);
  14789. if (fc.browseForFileToOpen())
  14790. return loadFrom (fc.getResult(), showMessageOnFailure);
  14791. return false;
  14792. }
  14793. FileBasedDocument::SaveResult FileBasedDocument::save (const bool askUserForFileIfNotSpecified,
  14794. const bool showMessageOnFailure)
  14795. {
  14796. return saveAs (documentFile,
  14797. false,
  14798. askUserForFileIfNotSpecified,
  14799. showMessageOnFailure);
  14800. }
  14801. FileBasedDocument::SaveResult FileBasedDocument::saveAs (const File& newFile,
  14802. const bool warnAboutOverwritingExistingFiles,
  14803. const bool askUserForFileIfNotSpecified,
  14804. const bool showMessageOnFailure)
  14805. {
  14806. if (newFile == File::nonexistent)
  14807. {
  14808. if (askUserForFileIfNotSpecified)
  14809. {
  14810. return saveAsInteractive (true);
  14811. }
  14812. else
  14813. {
  14814. // can't save to an unspecified file
  14815. jassertfalse
  14816. return failedToWriteToFile;
  14817. }
  14818. }
  14819. if (warnAboutOverwritingExistingFiles && newFile.exists())
  14820. {
  14821. if (! AlertWindow::showOkCancelBox (AlertWindow::WarningIcon,
  14822. TRANS("File already exists"),
  14823. TRANS("There's already a file called:\n\n")
  14824. + newFile.getFullPathName()
  14825. + TRANS("\n\nAre you sure you want to overwrite it?"),
  14826. TRANS("overwrite"),
  14827. TRANS("cancel")))
  14828. {
  14829. return userCancelledSave;
  14830. }
  14831. }
  14832. MouseCursor::showWaitCursor();
  14833. const File oldFile (documentFile);
  14834. documentFile = newFile;
  14835. String error (saveDocument (newFile));
  14836. if (error.isEmpty())
  14837. {
  14838. setChangedFlag (false);
  14839. MouseCursor::hideWaitCursor();
  14840. return savedOk;
  14841. }
  14842. documentFile = oldFile;
  14843. MouseCursor::hideWaitCursor();
  14844. if (showMessageOnFailure)
  14845. {
  14846. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  14847. TRANS("Error writing to file..."),
  14848. TRANS("An error occurred while trying to save \"")
  14849. + getDocumentTitle()
  14850. + TRANS("\" to the file:\n\n")
  14851. + newFile.getFullPathName()
  14852. + T("\n\n")
  14853. + error);
  14854. }
  14855. return failedToWriteToFile;
  14856. }
  14857. FileBasedDocument::SaveResult FileBasedDocument::saveIfNeededAndUserAgrees()
  14858. {
  14859. if (! hasChangedSinceSaved())
  14860. return savedOk;
  14861. const int r = AlertWindow::showYesNoCancelBox (AlertWindow::QuestionIcon,
  14862. TRANS("Closing document..."),
  14863. TRANS("Do you want to save the changes to \"")
  14864. + getDocumentTitle() + T("\"?"),
  14865. TRANS("save"),
  14866. TRANS("discard changes"),
  14867. TRANS("cancel"));
  14868. if (r == 1)
  14869. {
  14870. // save changes
  14871. return save (true, true);
  14872. }
  14873. else if (r == 2)
  14874. {
  14875. // discard changes
  14876. return savedOk;
  14877. }
  14878. return userCancelledSave;
  14879. }
  14880. FileBasedDocument::SaveResult FileBasedDocument::saveAsInteractive (const bool warnAboutOverwritingExistingFiles)
  14881. {
  14882. File f;
  14883. if (documentFile.existsAsFile())
  14884. f = documentFile;
  14885. else
  14886. f = getLastDocumentOpened();
  14887. String legalFilename (File::createLegalFileName (getDocumentTitle()));
  14888. if (legalFilename.isEmpty())
  14889. legalFilename = "unnamed";
  14890. if (f.existsAsFile() || f.getParentDirectory().isDirectory())
  14891. f = f.getSiblingFile (legalFilename);
  14892. else
  14893. f = File::getSpecialLocation (File::userDocumentsDirectory).getChildFile (legalFilename);
  14894. f = f.withFileExtension (fileExtension)
  14895. .getNonexistentSibling (true);
  14896. FileChooser fc (saveFileDialogTitle, f, fileWildcard);
  14897. if (fc.browseForFileToSave (warnAboutOverwritingExistingFiles))
  14898. {
  14899. setLastDocumentOpened (fc.getResult());
  14900. File chosen (fc.getResult());
  14901. if (chosen.getFileExtension().isEmpty())
  14902. {
  14903. chosen = chosen.withFileExtension (fileExtension);
  14904. if (chosen.exists())
  14905. {
  14906. if (! AlertWindow::showOkCancelBox (AlertWindow::WarningIcon,
  14907. TRANS("File already exists"),
  14908. TRANS("There's already a file called:\n\n")
  14909. + chosen.getFullPathName()
  14910. + T("\n\nAre you sure you want to overwrite it?"),
  14911. TRANS("overwrite"),
  14912. TRANS("cancel")))
  14913. {
  14914. return userCancelledSave;
  14915. }
  14916. }
  14917. }
  14918. return saveAs (chosen, false, false, true);
  14919. }
  14920. return userCancelledSave;
  14921. }
  14922. END_JUCE_NAMESPACE
  14923. /*** End of inlined file: juce_FileBasedDocument.cpp ***/
  14924. /*** Start of inlined file: juce_RecentlyOpenedFilesList.cpp ***/
  14925. BEGIN_JUCE_NAMESPACE
  14926. RecentlyOpenedFilesList::RecentlyOpenedFilesList()
  14927. : maxNumberOfItems (10)
  14928. {
  14929. }
  14930. RecentlyOpenedFilesList::~RecentlyOpenedFilesList()
  14931. {
  14932. }
  14933. void RecentlyOpenedFilesList::setMaxNumberOfItems (const int newMaxNumber)
  14934. {
  14935. maxNumberOfItems = jmax (1, newMaxNumber);
  14936. while (getNumFiles() > maxNumberOfItems)
  14937. files.remove (getNumFiles() - 1);
  14938. }
  14939. int RecentlyOpenedFilesList::getNumFiles() const
  14940. {
  14941. return files.size();
  14942. }
  14943. const File RecentlyOpenedFilesList::getFile (const int index) const
  14944. {
  14945. return File (files [index]);
  14946. }
  14947. void RecentlyOpenedFilesList::clear()
  14948. {
  14949. files.clear();
  14950. }
  14951. void RecentlyOpenedFilesList::addFile (const File& file)
  14952. {
  14953. const String path (file.getFullPathName());
  14954. files.removeString (path, true);
  14955. files.insert (0, path);
  14956. setMaxNumberOfItems (maxNumberOfItems);
  14957. }
  14958. void RecentlyOpenedFilesList::removeNonExistentFiles()
  14959. {
  14960. for (int i = getNumFiles(); --i >= 0;)
  14961. if (! getFile(i).exists())
  14962. files.remove (i);
  14963. }
  14964. int RecentlyOpenedFilesList::createPopupMenuItems (PopupMenu& menuToAddTo,
  14965. const int baseItemId,
  14966. const bool showFullPaths,
  14967. const bool dontAddNonExistentFiles,
  14968. const File** filesToAvoid)
  14969. {
  14970. int num = 0;
  14971. for (int i = 0; i < getNumFiles(); ++i)
  14972. {
  14973. const File f (getFile(i));
  14974. if ((! dontAddNonExistentFiles) || f.exists())
  14975. {
  14976. bool needsAvoiding = false;
  14977. if (filesToAvoid != 0)
  14978. {
  14979. const File** avoid = filesToAvoid;
  14980. while (*avoid != 0)
  14981. {
  14982. if (f == **avoid)
  14983. {
  14984. needsAvoiding = true;
  14985. break;
  14986. }
  14987. ++avoid;
  14988. }
  14989. }
  14990. if (! needsAvoiding)
  14991. {
  14992. menuToAddTo.addItem (baseItemId + i,
  14993. showFullPaths ? f.getFullPathName()
  14994. : f.getFileName());
  14995. ++num;
  14996. }
  14997. }
  14998. }
  14999. return num;
  15000. }
  15001. const String RecentlyOpenedFilesList::toString() const
  15002. {
  15003. return files.joinIntoString (T("\n"));
  15004. }
  15005. void RecentlyOpenedFilesList::restoreFromString (const String& stringifiedVersion)
  15006. {
  15007. clear();
  15008. files.addLines (stringifiedVersion);
  15009. setMaxNumberOfItems (maxNumberOfItems);
  15010. }
  15011. END_JUCE_NAMESPACE
  15012. /*** End of inlined file: juce_RecentlyOpenedFilesList.cpp ***/
  15013. /*** Start of inlined file: juce_UndoManager.cpp ***/
  15014. BEGIN_JUCE_NAMESPACE
  15015. UndoManager::UndoManager (const int maxNumberOfUnitsToKeep,
  15016. const int minimumTransactions)
  15017. : totalUnitsStored (0),
  15018. nextIndex (0),
  15019. newTransaction (true),
  15020. reentrancyCheck (false)
  15021. {
  15022. setMaxNumberOfStoredUnits (maxNumberOfUnitsToKeep,
  15023. minimumTransactions);
  15024. }
  15025. UndoManager::~UndoManager()
  15026. {
  15027. clearUndoHistory();
  15028. }
  15029. void UndoManager::clearUndoHistory()
  15030. {
  15031. transactions.clear();
  15032. transactionNames.clear();
  15033. totalUnitsStored = 0;
  15034. nextIndex = 0;
  15035. sendChangeMessage (this);
  15036. }
  15037. int UndoManager::getNumberOfUnitsTakenUpByStoredCommands() const
  15038. {
  15039. return totalUnitsStored;
  15040. }
  15041. void UndoManager::setMaxNumberOfStoredUnits (const int maxNumberOfUnitsToKeep,
  15042. const int minimumTransactions)
  15043. {
  15044. maxNumUnitsToKeep = jmax (1, maxNumberOfUnitsToKeep);
  15045. minimumTransactionsToKeep = jmax (1, minimumTransactions);
  15046. }
  15047. bool UndoManager::perform (UndoableAction* const command, const String& actionName)
  15048. {
  15049. if (command != 0)
  15050. {
  15051. if (actionName.isNotEmpty())
  15052. currentTransactionName = actionName;
  15053. if (reentrancyCheck)
  15054. {
  15055. jassertfalse // don't call perform() recursively from the UndoableAction::perform() or
  15056. // undo() methods, or else these actions won't actually get done.
  15057. return false;
  15058. }
  15059. else
  15060. {
  15061. bool success = false;
  15062. JUCE_TRY
  15063. {
  15064. success = command->perform();
  15065. }
  15066. JUCE_CATCH_EXCEPTION
  15067. jassert (success);
  15068. if (success)
  15069. {
  15070. if (nextIndex > 0 && ! newTransaction)
  15071. {
  15072. OwnedArray<UndoableAction>* commandSet = transactions [nextIndex - 1];
  15073. jassert (commandSet != 0);
  15074. if (commandSet == 0)
  15075. return false;
  15076. commandSet->add (command);
  15077. }
  15078. else
  15079. {
  15080. OwnedArray<UndoableAction>* commandSet = new OwnedArray<UndoableAction>();
  15081. commandSet->add (command);
  15082. transactions.insert (nextIndex, commandSet);
  15083. transactionNames.insert (nextIndex, currentTransactionName);
  15084. ++nextIndex;
  15085. }
  15086. totalUnitsStored += command->getSizeInUnits();
  15087. newTransaction = false;
  15088. }
  15089. while (nextIndex < transactions.size())
  15090. {
  15091. const OwnedArray <UndoableAction>* const lastSet = transactions.getLast();
  15092. for (int i = lastSet->size(); --i >= 0;)
  15093. totalUnitsStored -= lastSet->getUnchecked (i)->getSizeInUnits();
  15094. transactions.removeLast();
  15095. transactionNames.remove (transactionNames.size() - 1);
  15096. }
  15097. while (nextIndex > 0
  15098. && totalUnitsStored > maxNumUnitsToKeep
  15099. && transactions.size() > minimumTransactionsToKeep)
  15100. {
  15101. const OwnedArray <UndoableAction>* const firstSet = transactions.getFirst();
  15102. for (int i = firstSet->size(); --i >= 0;)
  15103. totalUnitsStored -= firstSet->getUnchecked (i)->getSizeInUnits();
  15104. jassert (totalUnitsStored >= 0); // something fishy going on if this fails!
  15105. transactions.remove (0);
  15106. transactionNames.remove (0);
  15107. --nextIndex;
  15108. }
  15109. sendChangeMessage (this);
  15110. return success;
  15111. }
  15112. }
  15113. return false;
  15114. }
  15115. void UndoManager::beginNewTransaction (const String& actionName)
  15116. {
  15117. newTransaction = true;
  15118. currentTransactionName = actionName;
  15119. }
  15120. void UndoManager::setCurrentTransactionName (const String& newName)
  15121. {
  15122. currentTransactionName = newName;
  15123. }
  15124. bool UndoManager::canUndo() const
  15125. {
  15126. return nextIndex > 0;
  15127. }
  15128. bool UndoManager::canRedo() const
  15129. {
  15130. return nextIndex < transactions.size();
  15131. }
  15132. const String UndoManager::getUndoDescription() const
  15133. {
  15134. return transactionNames [nextIndex - 1];
  15135. }
  15136. const String UndoManager::getRedoDescription() const
  15137. {
  15138. return transactionNames [nextIndex];
  15139. }
  15140. bool UndoManager::undo()
  15141. {
  15142. const OwnedArray<UndoableAction>* const commandSet = transactions [nextIndex - 1];
  15143. if (commandSet == 0)
  15144. return false;
  15145. reentrancyCheck = true;
  15146. bool failed = false;
  15147. for (int i = commandSet->size(); --i >= 0;)
  15148. {
  15149. if (! commandSet->getUnchecked(i)->undo())
  15150. {
  15151. jassertfalse
  15152. failed = true;
  15153. break;
  15154. }
  15155. }
  15156. reentrancyCheck = false;
  15157. if (failed)
  15158. {
  15159. clearUndoHistory();
  15160. }
  15161. else
  15162. {
  15163. --nextIndex;
  15164. }
  15165. beginNewTransaction();
  15166. sendChangeMessage (this);
  15167. return true;
  15168. }
  15169. bool UndoManager::redo()
  15170. {
  15171. const OwnedArray<UndoableAction>* const commandSet = transactions [nextIndex];
  15172. if (commandSet == 0)
  15173. return false;
  15174. reentrancyCheck = true;
  15175. bool failed = false;
  15176. for (int i = 0; i < commandSet->size(); ++i)
  15177. {
  15178. if (! commandSet->getUnchecked(i)->perform())
  15179. {
  15180. jassertfalse
  15181. failed = true;
  15182. break;
  15183. }
  15184. }
  15185. reentrancyCheck = false;
  15186. if (failed)
  15187. {
  15188. clearUndoHistory();
  15189. }
  15190. else
  15191. {
  15192. ++nextIndex;
  15193. }
  15194. beginNewTransaction();
  15195. sendChangeMessage (this);
  15196. return true;
  15197. }
  15198. bool UndoManager::undoCurrentTransactionOnly()
  15199. {
  15200. return newTransaction ? false
  15201. : undo();
  15202. }
  15203. void UndoManager::getActionsInCurrentTransaction (Array <const UndoableAction*>& actionsFound) const
  15204. {
  15205. const OwnedArray <UndoableAction>* const commandSet = transactions [nextIndex - 1];
  15206. if (commandSet != 0 && ! newTransaction)
  15207. {
  15208. for (int i = 0; i < commandSet->size(); ++i)
  15209. actionsFound.add (commandSet->getUnchecked(i));
  15210. }
  15211. }
  15212. int UndoManager::getNumActionsInCurrentTransaction() const
  15213. {
  15214. const OwnedArray <UndoableAction>* const commandSet = transactions [nextIndex - 1];
  15215. if (commandSet != 0 && ! newTransaction)
  15216. return commandSet->size();
  15217. return 0;
  15218. }
  15219. END_JUCE_NAMESPACE
  15220. /*** End of inlined file: juce_UndoManager.cpp ***/
  15221. /*** Start of inlined file: juce_AiffAudioFormat.cpp ***/
  15222. BEGIN_JUCE_NAMESPACE
  15223. static const char* const aiffFormatName = "AIFF file";
  15224. static const tchar* const aiffExtensions[] = { T(".aiff"), T(".aif"), 0 };
  15225. class AiffAudioFormatReader : public AudioFormatReader
  15226. {
  15227. public:
  15228. int bytesPerFrame;
  15229. int64 dataChunkStart;
  15230. bool littleEndian;
  15231. AiffAudioFormatReader (InputStream* in)
  15232. : AudioFormatReader (in, TRANS (aiffFormatName))
  15233. {
  15234. if (input->readInt() == chunkName ("FORM"))
  15235. {
  15236. const int len = input->readIntBigEndian();
  15237. const int64 end = input->getPosition() + len;
  15238. const int nextType = input->readInt();
  15239. if (nextType == chunkName ("AIFF") || nextType == chunkName ("AIFC"))
  15240. {
  15241. bool hasGotVer = false;
  15242. bool hasGotData = false;
  15243. bool hasGotType = false;
  15244. while (input->getPosition() < end)
  15245. {
  15246. const int type = input->readInt();
  15247. const uint32 length = (uint32) input->readIntBigEndian();
  15248. const int64 chunkEnd = input->getPosition() + length;
  15249. if (type == chunkName ("FVER"))
  15250. {
  15251. hasGotVer = true;
  15252. const int ver = input->readIntBigEndian();
  15253. if (ver != 0 && ver != (int)0xa2805140)
  15254. break;
  15255. }
  15256. else if (type == chunkName ("COMM"))
  15257. {
  15258. hasGotType = true;
  15259. numChannels = (unsigned int)input->readShortBigEndian();
  15260. lengthInSamples = input->readIntBigEndian();
  15261. bitsPerSample = input->readShortBigEndian();
  15262. bytesPerFrame = (numChannels * bitsPerSample) >> 3;
  15263. unsigned char sampleRateBytes[10];
  15264. input->read (sampleRateBytes, 10);
  15265. const int byte0 = sampleRateBytes[0];
  15266. if ((byte0 & 0x80) != 0
  15267. || byte0 <= 0x3F || byte0 > 0x40
  15268. || (byte0 == 0x40 && sampleRateBytes[1] > 0x1C))
  15269. break;
  15270. unsigned int sampRate = ByteOrder::bigEndianInt ((char*) sampleRateBytes + 2);
  15271. sampRate >>= (16414 - ByteOrder::bigEndianShort ((char*) sampleRateBytes));
  15272. sampleRate = (int) sampRate;
  15273. if (length <= 18)
  15274. {
  15275. // some types don't have a chunk large enough to include a compression
  15276. // type, so assume it's just big-endian pcm
  15277. littleEndian = false;
  15278. }
  15279. else
  15280. {
  15281. const int compType = input->readInt();
  15282. if (compType == chunkName ("NONE") || compType == chunkName ("twos"))
  15283. {
  15284. littleEndian = false;
  15285. }
  15286. else if (compType == chunkName ("sowt"))
  15287. {
  15288. littleEndian = true;
  15289. }
  15290. else
  15291. {
  15292. sampleRate = 0;
  15293. break;
  15294. }
  15295. }
  15296. }
  15297. else if (type == chunkName ("SSND"))
  15298. {
  15299. hasGotData = true;
  15300. const int offset = input->readIntBigEndian();
  15301. dataChunkStart = input->getPosition() + 4 + offset;
  15302. lengthInSamples = (bytesPerFrame > 0) ? jmin (lengthInSamples, (int64) (length / bytesPerFrame)) : 0;
  15303. }
  15304. else if ((hasGotVer && hasGotData && hasGotType)
  15305. || chunkEnd < input->getPosition()
  15306. || input->isExhausted())
  15307. {
  15308. break;
  15309. }
  15310. input->setPosition (chunkEnd);
  15311. }
  15312. }
  15313. }
  15314. }
  15315. ~AiffAudioFormatReader()
  15316. {
  15317. }
  15318. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  15319. int64 startSampleInFile, int numSamples)
  15320. {
  15321. const int64 samplesAvailable = lengthInSamples - startSampleInFile;
  15322. if (samplesAvailable < numSamples)
  15323. {
  15324. for (int i = numDestChannels; --i >= 0;)
  15325. if (destSamples[i] != 0)
  15326. zeromem (destSamples[i] + startOffsetInDestBuffer, sizeof (int) * numSamples);
  15327. numSamples = (int) samplesAvailable;
  15328. }
  15329. if (numSamples <= 0)
  15330. return true;
  15331. input->setPosition (dataChunkStart + startSampleInFile * bytesPerFrame);
  15332. const int tempBufSize = 480 * 3 * 4; // (keep this a multiple of 3)
  15333. char tempBuffer [tempBufSize];
  15334. while (numSamples > 0)
  15335. {
  15336. int* left = destSamples[0];
  15337. if (left != 0)
  15338. left += startOffsetInDestBuffer;
  15339. int* right = numDestChannels > 1 ? destSamples[1] : 0;
  15340. if (right != 0)
  15341. right += startOffsetInDestBuffer;
  15342. const int numThisTime = jmin (tempBufSize / bytesPerFrame, numSamples);
  15343. const int bytesRead = input->read (tempBuffer, numThisTime * bytesPerFrame);
  15344. if (bytesRead < numThisTime * bytesPerFrame)
  15345. zeromem (tempBuffer + bytesRead, numThisTime * bytesPerFrame - bytesRead);
  15346. if (bitsPerSample == 16)
  15347. {
  15348. if (littleEndian)
  15349. {
  15350. const short* src = (const short*) tempBuffer;
  15351. if (numChannels > 1)
  15352. {
  15353. if (left == 0)
  15354. {
  15355. for (int i = numThisTime; --i >= 0;)
  15356. {
  15357. *right++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15358. ++src;
  15359. }
  15360. }
  15361. else if (right == 0)
  15362. {
  15363. for (int i = numThisTime; --i >= 0;)
  15364. {
  15365. ++src;
  15366. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15367. }
  15368. }
  15369. else
  15370. {
  15371. for (int i = numThisTime; --i >= 0;)
  15372. {
  15373. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15374. *right++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15375. }
  15376. }
  15377. }
  15378. else
  15379. {
  15380. for (int i = numThisTime; --i >= 0;)
  15381. {
  15382. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15383. }
  15384. }
  15385. }
  15386. else
  15387. {
  15388. const char* src = (const char*) tempBuffer;
  15389. if (numChannels > 1)
  15390. {
  15391. if (left == 0)
  15392. {
  15393. for (int i = numThisTime; --i >= 0;)
  15394. {
  15395. *right++ = ByteOrder::bigEndianShort (src) << 16;
  15396. src += 4;
  15397. }
  15398. }
  15399. else if (right == 0)
  15400. {
  15401. for (int i = numThisTime; --i >= 0;)
  15402. {
  15403. src += 2;
  15404. *left++ = ByteOrder::bigEndianShort (src) << 16;
  15405. src += 2;
  15406. }
  15407. }
  15408. else
  15409. {
  15410. for (int i = numThisTime; --i >= 0;)
  15411. {
  15412. *left++ = ByteOrder::bigEndianShort (src) << 16;
  15413. src += 2;
  15414. *right++ = ByteOrder::bigEndianShort (src) << 16;
  15415. src += 2;
  15416. }
  15417. }
  15418. }
  15419. else
  15420. {
  15421. for (int i = numThisTime; --i >= 0;)
  15422. {
  15423. *left++ = ByteOrder::bigEndianShort (src) << 16;
  15424. src += 2;
  15425. }
  15426. }
  15427. }
  15428. }
  15429. else if (bitsPerSample == 24)
  15430. {
  15431. const char* src = (const char*)tempBuffer;
  15432. if (littleEndian)
  15433. {
  15434. if (numChannels > 1)
  15435. {
  15436. if (left == 0)
  15437. {
  15438. for (int i = numThisTime; --i >= 0;)
  15439. {
  15440. *right++ = ByteOrder::littleEndian24Bit (src) << 8;
  15441. src += 6;
  15442. }
  15443. }
  15444. else if (right == 0)
  15445. {
  15446. for (int i = numThisTime; --i >= 0;)
  15447. {
  15448. src += 3;
  15449. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  15450. src += 3;
  15451. }
  15452. }
  15453. else
  15454. {
  15455. for (int i = numThisTime; --i >= 0;)
  15456. {
  15457. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  15458. src += 3;
  15459. *right++ = ByteOrder::littleEndian24Bit (src) << 8;
  15460. src += 3;
  15461. }
  15462. }
  15463. }
  15464. else
  15465. {
  15466. for (int i = numThisTime; --i >= 0;)
  15467. {
  15468. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  15469. src += 3;
  15470. }
  15471. }
  15472. }
  15473. else
  15474. {
  15475. if (numChannels > 1)
  15476. {
  15477. if (left == 0)
  15478. {
  15479. for (int i = numThisTime; --i >= 0;)
  15480. {
  15481. *right++ = ByteOrder::bigEndian24Bit (src) << 8;
  15482. src += 6;
  15483. }
  15484. }
  15485. else if (right == 0)
  15486. {
  15487. for (int i = numThisTime; --i >= 0;)
  15488. {
  15489. src += 3;
  15490. *left++ = ByteOrder::bigEndian24Bit (src) << 8;
  15491. src += 3;
  15492. }
  15493. }
  15494. else
  15495. {
  15496. for (int i = numThisTime; --i >= 0;)
  15497. {
  15498. *left++ = ByteOrder::bigEndian24Bit (src) << 8;
  15499. src += 3;
  15500. *right++ = ByteOrder::bigEndian24Bit (src) << 8;
  15501. src += 3;
  15502. }
  15503. }
  15504. }
  15505. else
  15506. {
  15507. for (int i = numThisTime; --i >= 0;)
  15508. {
  15509. *left++ = ByteOrder::bigEndian24Bit (src) << 8;
  15510. src += 3;
  15511. }
  15512. }
  15513. }
  15514. }
  15515. else if (bitsPerSample == 32)
  15516. {
  15517. const unsigned int* src = (const unsigned int*) tempBuffer;
  15518. unsigned int* l = (unsigned int*) left;
  15519. unsigned int* r = (unsigned int*) right;
  15520. if (littleEndian)
  15521. {
  15522. if (numChannels > 1)
  15523. {
  15524. if (l == 0)
  15525. {
  15526. for (int i = numThisTime; --i >= 0;)
  15527. {
  15528. ++src;
  15529. *r++ = ByteOrder::swapIfBigEndian (*src++);
  15530. }
  15531. }
  15532. else if (r == 0)
  15533. {
  15534. for (int i = numThisTime; --i >= 0;)
  15535. {
  15536. *l++ = ByteOrder::swapIfBigEndian (*src++);
  15537. ++src;
  15538. }
  15539. }
  15540. else
  15541. {
  15542. for (int i = numThisTime; --i >= 0;)
  15543. {
  15544. *l++ = ByteOrder::swapIfBigEndian (*src++);
  15545. *r++ = ByteOrder::swapIfBigEndian (*src++);
  15546. }
  15547. }
  15548. }
  15549. else
  15550. {
  15551. for (int i = numThisTime; --i >= 0;)
  15552. {
  15553. *l++ = ByteOrder::swapIfBigEndian (*src++);
  15554. }
  15555. }
  15556. }
  15557. else
  15558. {
  15559. if (numChannels > 1)
  15560. {
  15561. if (l == 0)
  15562. {
  15563. for (int i = numThisTime; --i >= 0;)
  15564. {
  15565. ++src;
  15566. *r++ = ByteOrder::swapIfLittleEndian (*src++);
  15567. }
  15568. }
  15569. else if (r == 0)
  15570. {
  15571. for (int i = numThisTime; --i >= 0;)
  15572. {
  15573. *l++ = ByteOrder::swapIfLittleEndian (*src++);
  15574. ++src;
  15575. }
  15576. }
  15577. else
  15578. {
  15579. for (int i = numThisTime; --i >= 0;)
  15580. {
  15581. *l++ = ByteOrder::swapIfLittleEndian (*src++);
  15582. *r++ = ByteOrder::swapIfLittleEndian (*src++);
  15583. }
  15584. }
  15585. }
  15586. else
  15587. {
  15588. for (int i = numThisTime; --i >= 0;)
  15589. {
  15590. *l++ = ByteOrder::swapIfLittleEndian (*src++);
  15591. }
  15592. }
  15593. }
  15594. left = (int*) l;
  15595. right = (int*) r;
  15596. }
  15597. else if (bitsPerSample == 8)
  15598. {
  15599. const char* src = (const char*) tempBuffer;
  15600. if (numChannels > 1)
  15601. {
  15602. if (left == 0)
  15603. {
  15604. for (int i = numThisTime; --i >= 0;)
  15605. {
  15606. *right++ = ((int) *src++) << 24;
  15607. ++src;
  15608. }
  15609. }
  15610. else if (right == 0)
  15611. {
  15612. for (int i = numThisTime; --i >= 0;)
  15613. {
  15614. ++src;
  15615. *left++ = ((int) *src++) << 24;
  15616. }
  15617. }
  15618. else
  15619. {
  15620. for (int i = numThisTime; --i >= 0;)
  15621. {
  15622. *left++ = ((int) *src++) << 24;
  15623. *right++ = ((int) *src++) << 24;
  15624. }
  15625. }
  15626. }
  15627. else
  15628. {
  15629. for (int i = numThisTime; --i >= 0;)
  15630. {
  15631. *left++ = ((int) *src++) << 24;
  15632. }
  15633. }
  15634. }
  15635. startOffsetInDestBuffer += numThisTime;
  15636. numSamples -= numThisTime;
  15637. }
  15638. if (numSamples > 0)
  15639. {
  15640. for (int i = numDestChannels; --i >= 0;)
  15641. if (destSamples[i] != 0)
  15642. zeromem (destSamples[i] + startOffsetInDestBuffer,
  15643. sizeof (int) * numSamples);
  15644. }
  15645. return true;
  15646. }
  15647. juce_UseDebuggingNewOperator
  15648. private:
  15649. AiffAudioFormatReader (const AiffAudioFormatReader&);
  15650. const AiffAudioFormatReader& operator= (const AiffAudioFormatReader&);
  15651. static inline int chunkName (const char* const name) { return (int) ByteOrder::littleEndianInt (name); }
  15652. };
  15653. class AiffAudioFormatWriter : public AudioFormatWriter
  15654. {
  15655. MemoryBlock tempBlock;
  15656. uint32 lengthInSamples, bytesWritten;
  15657. int64 headerPosition;
  15658. bool writeFailed;
  15659. static inline int chunkName (const char* const name) { return (int) ByteOrder::littleEndianInt (name); }
  15660. AiffAudioFormatWriter (const AiffAudioFormatWriter&);
  15661. const AiffAudioFormatWriter& operator= (const AiffAudioFormatWriter&);
  15662. void writeHeader()
  15663. {
  15664. const bool couldSeekOk = output->setPosition (headerPosition);
  15665. (void) couldSeekOk;
  15666. // if this fails, you've given it an output stream that can't seek! It needs
  15667. // to be able to seek back to write the header
  15668. jassert (couldSeekOk);
  15669. const int headerLen = 54;
  15670. int audioBytes = lengthInSamples * ((bitsPerSample * numChannels) / 8);
  15671. audioBytes += (audioBytes & 1);
  15672. output->writeInt (chunkName ("FORM"));
  15673. output->writeIntBigEndian (headerLen + audioBytes - 8);
  15674. output->writeInt (chunkName ("AIFF"));
  15675. output->writeInt (chunkName ("COMM"));
  15676. output->writeIntBigEndian (18);
  15677. output->writeShortBigEndian ((short) numChannels);
  15678. output->writeIntBigEndian (lengthInSamples);
  15679. output->writeShortBigEndian ((short) bitsPerSample);
  15680. uint8 sampleRateBytes[10];
  15681. zeromem (sampleRateBytes, 10);
  15682. if (sampleRate <= 1)
  15683. {
  15684. sampleRateBytes[0] = 0x3f;
  15685. sampleRateBytes[1] = 0xff;
  15686. sampleRateBytes[2] = 0x80;
  15687. }
  15688. else
  15689. {
  15690. int mask = 0x40000000;
  15691. sampleRateBytes[0] = 0x40;
  15692. if (sampleRate >= mask)
  15693. {
  15694. jassertfalse
  15695. sampleRateBytes[1] = 0x1d;
  15696. }
  15697. else
  15698. {
  15699. int n = (int) sampleRate;
  15700. int i;
  15701. for (i = 0; i <= 32 ; ++i)
  15702. {
  15703. if ((n & mask) != 0)
  15704. break;
  15705. mask >>= 1;
  15706. }
  15707. n = n << (i + 1);
  15708. sampleRateBytes[1] = (uint8) (29 - i);
  15709. sampleRateBytes[2] = (uint8) ((n >> 24) & 0xff);
  15710. sampleRateBytes[3] = (uint8) ((n >> 16) & 0xff);
  15711. sampleRateBytes[4] = (uint8) ((n >> 8) & 0xff);
  15712. sampleRateBytes[5] = (uint8) (n & 0xff);
  15713. }
  15714. }
  15715. output->write (sampleRateBytes, 10);
  15716. output->writeInt (chunkName ("SSND"));
  15717. output->writeIntBigEndian (audioBytes + 8);
  15718. output->writeInt (0);
  15719. output->writeInt (0);
  15720. jassert (output->getPosition() == headerLen);
  15721. }
  15722. public:
  15723. AiffAudioFormatWriter (OutputStream* out,
  15724. const double sampleRate_,
  15725. const unsigned int chans,
  15726. const int bits)
  15727. : AudioFormatWriter (out,
  15728. TRANS (aiffFormatName),
  15729. sampleRate_,
  15730. chans,
  15731. bits),
  15732. lengthInSamples (0),
  15733. bytesWritten (0),
  15734. writeFailed (false)
  15735. {
  15736. headerPosition = out->getPosition();
  15737. writeHeader();
  15738. }
  15739. ~AiffAudioFormatWriter()
  15740. {
  15741. if ((bytesWritten & 1) != 0)
  15742. output->writeByte (0);
  15743. writeHeader();
  15744. }
  15745. bool write (const int** data, int numSamples)
  15746. {
  15747. if (writeFailed)
  15748. return false;
  15749. const int bytes = numChannels * numSamples * bitsPerSample / 8;
  15750. tempBlock.ensureSize (bytes, false);
  15751. char* buffer = (char*) tempBlock.getData();
  15752. const int* left = data[0];
  15753. const int* right = data[1];
  15754. if (right == 0)
  15755. right = left;
  15756. if (bitsPerSample == 16)
  15757. {
  15758. short* b = (short*) buffer;
  15759. if (numChannels > 1)
  15760. {
  15761. for (int i = numSamples; --i >= 0;)
  15762. {
  15763. *b++ = (short) ByteOrder::swapIfLittleEndian ((uint16) (*left++ >> 16));
  15764. *b++ = (short) ByteOrder::swapIfLittleEndian ((uint16) (*right++ >> 16));
  15765. }
  15766. }
  15767. else
  15768. {
  15769. for (int i = numSamples; --i >= 0;)
  15770. {
  15771. *b++ = (short) ByteOrder::swapIfLittleEndian ((uint16) (*left++ >> 16));
  15772. }
  15773. }
  15774. }
  15775. else if (bitsPerSample == 24)
  15776. {
  15777. char* b = (char*) buffer;
  15778. if (numChannels > 1)
  15779. {
  15780. for (int i = numSamples; --i >= 0;)
  15781. {
  15782. ByteOrder::bigEndian24BitToChars (*left++ >> 8, b);
  15783. b += 3;
  15784. ByteOrder::bigEndian24BitToChars (*right++ >> 8, b);
  15785. b += 3;
  15786. }
  15787. }
  15788. else
  15789. {
  15790. for (int i = numSamples; --i >= 0;)
  15791. {
  15792. ByteOrder::bigEndian24BitToChars (*left++ >> 8, b);
  15793. b += 3;
  15794. }
  15795. }
  15796. }
  15797. else if (bitsPerSample == 32)
  15798. {
  15799. uint32* b = (uint32*) buffer;
  15800. if (numChannels > 1)
  15801. {
  15802. for (int i = numSamples; --i >= 0;)
  15803. {
  15804. *b++ = ByteOrder::swapIfLittleEndian ((uint32) *left++);
  15805. *b++ = ByteOrder::swapIfLittleEndian ((uint32) *right++);
  15806. }
  15807. }
  15808. else
  15809. {
  15810. for (int i = numSamples; --i >= 0;)
  15811. {
  15812. *b++ = ByteOrder::swapIfLittleEndian ((uint32) *left++);
  15813. }
  15814. }
  15815. }
  15816. else if (bitsPerSample == 8)
  15817. {
  15818. char* b = (char*) buffer;
  15819. if (numChannels > 1)
  15820. {
  15821. for (int i = numSamples; --i >= 0;)
  15822. {
  15823. *b++ = (char) (*left++ >> 24);
  15824. *b++ = (char) (*right++ >> 24);
  15825. }
  15826. }
  15827. else
  15828. {
  15829. for (int i = numSamples; --i >= 0;)
  15830. {
  15831. *b++ = (char) (*left++ >> 24);
  15832. }
  15833. }
  15834. }
  15835. if (bytesWritten + bytes >= (uint32) 0xfff00000
  15836. || ! output->write (buffer, bytes))
  15837. {
  15838. // failed to write to disk, so let's try writing the header.
  15839. // If it's just run out of disk space, then if it does manage
  15840. // to write the header, we'll still have a useable file..
  15841. writeHeader();
  15842. writeFailed = true;
  15843. return false;
  15844. }
  15845. else
  15846. {
  15847. bytesWritten += bytes;
  15848. lengthInSamples += numSamples;
  15849. return true;
  15850. }
  15851. }
  15852. juce_UseDebuggingNewOperator
  15853. };
  15854. AiffAudioFormat::AiffAudioFormat()
  15855. : AudioFormat (TRANS (aiffFormatName), (const tchar**) aiffExtensions)
  15856. {
  15857. }
  15858. AiffAudioFormat::~AiffAudioFormat()
  15859. {
  15860. }
  15861. const Array <int> AiffAudioFormat::getPossibleSampleRates()
  15862. {
  15863. const int rates[] = { 22050, 32000, 44100, 48000, 88200, 96000, 176400, 192000, 0 };
  15864. return Array <int> (rates);
  15865. }
  15866. const Array <int> AiffAudioFormat::getPossibleBitDepths()
  15867. {
  15868. const int depths[] = { 8, 16, 24, 0 };
  15869. return Array <int> (depths);
  15870. }
  15871. bool AiffAudioFormat::canDoStereo()
  15872. {
  15873. return true;
  15874. }
  15875. bool AiffAudioFormat::canDoMono()
  15876. {
  15877. return true;
  15878. }
  15879. #if JUCE_MAC
  15880. bool AiffAudioFormat::canHandleFile (const File& f)
  15881. {
  15882. if (AudioFormat::canHandleFile (f))
  15883. return true;
  15884. const OSType type = PlatformUtilities::getTypeOfFile (f.getFullPathName());
  15885. return type == 'AIFF' || type == 'AIFC'
  15886. || type == 'aiff' || type == 'aifc';
  15887. }
  15888. #endif
  15889. AudioFormatReader* AiffAudioFormat::createReaderFor (InputStream* sourceStream,
  15890. const bool deleteStreamIfOpeningFails)
  15891. {
  15892. ScopedPointer <AiffAudioFormatReader> w (new AiffAudioFormatReader (sourceStream));
  15893. if (w->sampleRate != 0)
  15894. return w.release();
  15895. if (! deleteStreamIfOpeningFails)
  15896. w->input = 0;
  15897. return 0;
  15898. }
  15899. AudioFormatWriter* AiffAudioFormat::createWriterFor (OutputStream* out,
  15900. double sampleRate,
  15901. unsigned int chans,
  15902. int bitsPerSample,
  15903. const StringPairArray& /*metadataValues*/,
  15904. int /*qualityOptionIndex*/)
  15905. {
  15906. if (getPossibleBitDepths().contains (bitsPerSample))
  15907. {
  15908. return new AiffAudioFormatWriter (out,
  15909. sampleRate,
  15910. chans,
  15911. bitsPerSample);
  15912. }
  15913. return 0;
  15914. }
  15915. END_JUCE_NAMESPACE
  15916. /*** End of inlined file: juce_AiffAudioFormat.cpp ***/
  15917. /*** Start of inlined file: juce_AudioCDReader.cpp ***/
  15918. BEGIN_JUCE_NAMESPACE
  15919. #if JUCE_MAC && JUCE_USE_CDREADER
  15920. // Mac version doesn't need any native code because it's all done with files..
  15921. // Windows + Linux versions are in the platform-dependent code sections.
  15922. static void findCDs (Array<File>& cds)
  15923. {
  15924. File volumes ("/Volumes");
  15925. volumes.findChildFiles (cds, File::findDirectories, false);
  15926. for (int i = cds.size(); --i >= 0;)
  15927. if (! cds.getReference(i).getChildFile (".TOC.plist").exists())
  15928. cds.remove (i);
  15929. }
  15930. const StringArray AudioCDReader::getAvailableCDNames()
  15931. {
  15932. Array<File> cds;
  15933. findCDs (cds);
  15934. StringArray names;
  15935. for (int i = 0; i < cds.size(); ++i)
  15936. names.add (cds.getReference(i).getFileName());
  15937. return names;
  15938. }
  15939. AudioCDReader* AudioCDReader::createReaderForCD (const int index)
  15940. {
  15941. Array<File> cds;
  15942. findCDs (cds);
  15943. if (cds[index] != File::nonexistent)
  15944. return new AudioCDReader (cds[index]);
  15945. else
  15946. return 0;
  15947. }
  15948. AudioCDReader::AudioCDReader (const File& volume)
  15949. : AudioFormatReader (0, "CD Audio"),
  15950. volumeDir (volume),
  15951. currentReaderTrack (-1),
  15952. reader (0)
  15953. {
  15954. sampleRate = 44100.0;
  15955. bitsPerSample = 16;
  15956. numChannels = 2;
  15957. usesFloatingPointData = false;
  15958. refreshTrackLengths();
  15959. }
  15960. AudioCDReader::~AudioCDReader()
  15961. {
  15962. }
  15963. static int getTrackNumber (const File& file)
  15964. {
  15965. return file.getFileName()
  15966. .initialSectionContainingOnly (T("0123456789"))
  15967. .getIntValue();
  15968. }
  15969. int AudioCDReader::compareElements (const File& first, const File& second)
  15970. {
  15971. const int firstTrack = getTrackNumber (first);
  15972. const int secondTrack = getTrackNumber (second);
  15973. jassert (firstTrack > 0 && secondTrack > 0);
  15974. return firstTrack - secondTrack;
  15975. }
  15976. void AudioCDReader::refreshTrackLengths()
  15977. {
  15978. tracks.clear();
  15979. trackStartSamples.clear();
  15980. volumeDir.findChildFiles (tracks, File::findFiles | File::ignoreHiddenFiles, false, T("*.aiff"));
  15981. tracks.sort (*this);
  15982. AiffAudioFormat format;
  15983. int sample = 0;
  15984. for (int i = 0; i < tracks.size(); ++i)
  15985. {
  15986. trackStartSamples.add (sample);
  15987. FileInputStream* const in = tracks.getReference(i).createInputStream();
  15988. if (in != 0)
  15989. {
  15990. ScopedPointer <AudioFormatReader> r (format.createReaderFor (in, true));
  15991. if (r != 0)
  15992. sample += (int) r->lengthInSamples;
  15993. }
  15994. }
  15995. trackStartSamples.add (sample);
  15996. lengthInSamples = sample;
  15997. }
  15998. bool AudioCDReader::readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  15999. int64 startSampleInFile, int numSamples)
  16000. {
  16001. while (numSamples > 0)
  16002. {
  16003. int track = -1;
  16004. for (int i = 0; i < trackStartSamples.size() - 1; ++i)
  16005. {
  16006. if (startSampleInFile < trackStartSamples.getUnchecked (i + 1))
  16007. {
  16008. track = i;
  16009. break;
  16010. }
  16011. }
  16012. if (track < 0)
  16013. return false;
  16014. if (track != currentReaderTrack)
  16015. {
  16016. reader = 0;
  16017. FileInputStream* const in = tracks [track].createInputStream();
  16018. if (in != 0)
  16019. {
  16020. BufferedInputStream* const bin = new BufferedInputStream (in, 65536, true);
  16021. AiffAudioFormat format;
  16022. reader = format.createReaderFor (bin, true);
  16023. if (reader == 0)
  16024. currentReaderTrack = -1;
  16025. else
  16026. currentReaderTrack = track;
  16027. }
  16028. }
  16029. if (reader == 0)
  16030. return false;
  16031. const int startPos = (int) (startSampleInFile - trackStartSamples.getUnchecked (track));
  16032. const int numAvailable = (int) jmin ((int64) numSamples, reader->lengthInSamples - startPos);
  16033. reader->readSamples (destSamples, numDestChannels, startOffsetInDestBuffer, startPos, numAvailable);
  16034. numSamples -= numAvailable;
  16035. startSampleInFile += numAvailable;
  16036. }
  16037. return true;
  16038. }
  16039. bool AudioCDReader::isCDStillPresent() const
  16040. {
  16041. return volumeDir.exists();
  16042. }
  16043. int AudioCDReader::getNumTracks() const
  16044. {
  16045. return tracks.size();
  16046. }
  16047. int AudioCDReader::getPositionOfTrackStart (int trackNum) const
  16048. {
  16049. return trackStartSamples [trackNum];
  16050. }
  16051. bool AudioCDReader::isTrackAudio (int trackNum) const
  16052. {
  16053. return tracks [trackNum] != File::nonexistent;
  16054. }
  16055. void AudioCDReader::enableIndexScanning (bool b)
  16056. {
  16057. // any way to do this on a Mac??
  16058. }
  16059. int AudioCDReader::getLastIndex() const
  16060. {
  16061. return 0;
  16062. }
  16063. const Array <int> AudioCDReader::findIndexesInTrack (const int trackNumber)
  16064. {
  16065. return Array <int>();
  16066. }
  16067. int AudioCDReader::getCDDBId()
  16068. {
  16069. return 0; //xxx
  16070. }
  16071. #endif
  16072. END_JUCE_NAMESPACE
  16073. /*** End of inlined file: juce_AudioCDReader.cpp ***/
  16074. /*** Start of inlined file: juce_AudioFormat.cpp ***/
  16075. BEGIN_JUCE_NAMESPACE
  16076. AudioFormatReader::AudioFormatReader (InputStream* const in,
  16077. const String& formatName_)
  16078. : sampleRate (0),
  16079. bitsPerSample (0),
  16080. lengthInSamples (0),
  16081. numChannels (0),
  16082. usesFloatingPointData (false),
  16083. input (in),
  16084. formatName (formatName_)
  16085. {
  16086. }
  16087. AudioFormatReader::~AudioFormatReader()
  16088. {
  16089. delete input;
  16090. }
  16091. bool AudioFormatReader::read (int** destSamples,
  16092. int numDestChannels,
  16093. int64 startSampleInSource,
  16094. int numSamplesToRead,
  16095. const bool fillLeftoverChannelsWithCopies)
  16096. {
  16097. jassert (numDestChannels > 0); // you have to actually give this some channels to work with!
  16098. int startOffsetInDestBuffer = 0;
  16099. if (startSampleInSource < 0)
  16100. {
  16101. const int silence = (int) jmin (-startSampleInSource, (int64) numSamplesToRead);
  16102. for (int i = numDestChannels; --i >= 0;)
  16103. if (destSamples[i] != 0)
  16104. zeromem (destSamples[i], sizeof (int) * silence);
  16105. startOffsetInDestBuffer += silence;
  16106. numSamplesToRead -= silence;
  16107. startSampleInSource = 0;
  16108. }
  16109. if (numSamplesToRead <= 0)
  16110. return true;
  16111. if (! readSamples (destSamples, jmin ((int) numChannels, numDestChannels), startOffsetInDestBuffer,
  16112. startSampleInSource, numSamplesToRead))
  16113. return false;
  16114. if (numDestChannels > (int) numChannels)
  16115. {
  16116. if (fillLeftoverChannelsWithCopies)
  16117. {
  16118. int* lastFullChannel = destSamples[0];
  16119. for (int i = numDestChannels; --i > 0;)
  16120. {
  16121. if (destSamples[i] != 0)
  16122. {
  16123. lastFullChannel = destSamples[i];
  16124. break;
  16125. }
  16126. }
  16127. if (lastFullChannel != 0)
  16128. for (int i = numChannels; i < numDestChannels; ++i)
  16129. if (destSamples[i] != 0)
  16130. memcpy (destSamples[i], lastFullChannel, sizeof (int) * numSamplesToRead);
  16131. }
  16132. else
  16133. {
  16134. for (int i = numChannels; i < numDestChannels; ++i)
  16135. if (destSamples[i] != 0)
  16136. zeromem (destSamples[i], sizeof (int) * numSamplesToRead);
  16137. }
  16138. }
  16139. return true;
  16140. }
  16141. static void findMaxMin (const float* src, const int num,
  16142. float& maxVal, float& minVal)
  16143. {
  16144. float mn = src[0];
  16145. float mx = mn;
  16146. for (int i = 1; i < num; ++i)
  16147. {
  16148. const float s = src[i];
  16149. if (s > mx)
  16150. mx = s;
  16151. if (s < mn)
  16152. mn = s;
  16153. }
  16154. maxVal = mx;
  16155. minVal = mn;
  16156. }
  16157. void AudioFormatReader::readMaxLevels (int64 startSampleInFile,
  16158. int64 numSamples,
  16159. float& lowestLeft, float& highestLeft,
  16160. float& lowestRight, float& highestRight)
  16161. {
  16162. if (numSamples <= 0)
  16163. {
  16164. lowestLeft = 0;
  16165. lowestRight = 0;
  16166. highestLeft = 0;
  16167. highestRight = 0;
  16168. return;
  16169. }
  16170. const int bufferSize = (int) jmin (numSamples, (int64) 4096);
  16171. MemoryBlock tempSpace (bufferSize * sizeof (int) * 2 + 64);
  16172. int* tempBuffer[3];
  16173. tempBuffer[0] = (int*) tempSpace.getData();
  16174. tempBuffer[1] = ((int*) tempSpace.getData()) + bufferSize;
  16175. tempBuffer[2] = 0;
  16176. if (usesFloatingPointData)
  16177. {
  16178. float lmin = 1.0e6f;
  16179. float lmax = -lmin;
  16180. float rmin = lmin;
  16181. float rmax = lmax;
  16182. while (numSamples > 0)
  16183. {
  16184. const int numToDo = (int) jmin (numSamples, (int64) bufferSize);
  16185. read ((int**) tempBuffer, 2, startSampleInFile, numToDo, false);
  16186. numSamples -= numToDo;
  16187. startSampleInFile += numToDo;
  16188. float bufmin, bufmax;
  16189. findMaxMin ((float*) tempBuffer[0], numToDo, bufmax, bufmin);
  16190. lmin = jmin (lmin, bufmin);
  16191. lmax = jmax (lmax, bufmax);
  16192. if (numChannels > 1)
  16193. {
  16194. findMaxMin ((float*) tempBuffer[1], numToDo, bufmax, bufmin);
  16195. rmin = jmin (rmin, bufmin);
  16196. rmax = jmax (rmax, bufmax);
  16197. }
  16198. }
  16199. if (numChannels <= 1)
  16200. {
  16201. rmax = lmax;
  16202. rmin = lmin;
  16203. }
  16204. lowestLeft = lmin;
  16205. highestLeft = lmax;
  16206. lowestRight = rmin;
  16207. highestRight = rmax;
  16208. }
  16209. else
  16210. {
  16211. int lmax = std::numeric_limits<int>::min();
  16212. int lmin = std::numeric_limits<int>::max();
  16213. int rmax = std::numeric_limits<int>::min();
  16214. int rmin = std::numeric_limits<int>::max();
  16215. while (numSamples > 0)
  16216. {
  16217. const int numToDo = (int) jmin (numSamples, (int64) bufferSize);
  16218. read ((int**) tempBuffer, 2, startSampleInFile, numToDo, false);
  16219. numSamples -= numToDo;
  16220. startSampleInFile += numToDo;
  16221. for (int j = numChannels; --j >= 0;)
  16222. {
  16223. int bufMax = std::numeric_limits<int>::min();
  16224. int bufMin = std::numeric_limits<int>::max();
  16225. const int* const b = tempBuffer[j];
  16226. for (int i = 0; i < numToDo; ++i)
  16227. {
  16228. const int samp = b[i];
  16229. if (samp < bufMin)
  16230. bufMin = samp;
  16231. if (samp > bufMax)
  16232. bufMax = samp;
  16233. }
  16234. if (j == 0)
  16235. {
  16236. lmax = jmax (lmax, bufMax);
  16237. lmin = jmin (lmin, bufMin);
  16238. }
  16239. else
  16240. {
  16241. rmax = jmax (rmax, bufMax);
  16242. rmin = jmin (rmin, bufMin);
  16243. }
  16244. }
  16245. }
  16246. if (numChannels <= 1)
  16247. {
  16248. rmax = lmax;
  16249. rmin = lmin;
  16250. }
  16251. lowestLeft = lmin / (float) std::numeric_limits<int>::max();
  16252. highestLeft = lmax / (float) std::numeric_limits<int>::max();
  16253. lowestRight = rmin / (float) std::numeric_limits<int>::max();
  16254. highestRight = rmax / (float) std::numeric_limits<int>::max();
  16255. }
  16256. }
  16257. int64 AudioFormatReader::searchForLevel (int64 startSample,
  16258. int64 numSamplesToSearch,
  16259. const double magnitudeRangeMinimum,
  16260. const double magnitudeRangeMaximum,
  16261. const int minimumConsecutiveSamples)
  16262. {
  16263. if (numSamplesToSearch == 0)
  16264. return -1;
  16265. const int bufferSize = 4096;
  16266. MemoryBlock tempSpace (bufferSize * sizeof (int) * 2 + 64);
  16267. int* tempBuffer[3];
  16268. tempBuffer[0] = (int*) tempSpace.getData();
  16269. tempBuffer[1] = ((int*) tempSpace.getData()) + bufferSize;
  16270. tempBuffer[2] = 0;
  16271. int consecutive = 0;
  16272. int64 firstMatchPos = -1;
  16273. jassert (magnitudeRangeMaximum > magnitudeRangeMinimum);
  16274. const double doubleMin = jlimit (0.0, (double) std::numeric_limits<int>::max(), magnitudeRangeMinimum * std::numeric_limits<int>::max());
  16275. const double doubleMax = jlimit (doubleMin, (double) std::numeric_limits<int>::max(), magnitudeRangeMaximum * std::numeric_limits<int>::max());
  16276. const int intMagnitudeRangeMinimum = roundToInt (doubleMin);
  16277. const int intMagnitudeRangeMaximum = roundToInt (doubleMax);
  16278. while (numSamplesToSearch != 0)
  16279. {
  16280. const int numThisTime = (int) jmin (abs64 (numSamplesToSearch), (int64) bufferSize);
  16281. int64 bufferStart = startSample;
  16282. if (numSamplesToSearch < 0)
  16283. bufferStart -= numThisTime;
  16284. if (bufferStart >= (int) lengthInSamples)
  16285. break;
  16286. read ((int**) tempBuffer, 2, bufferStart, numThisTime, false);
  16287. int num = numThisTime;
  16288. while (--num >= 0)
  16289. {
  16290. if (numSamplesToSearch < 0)
  16291. --startSample;
  16292. bool matches = false;
  16293. const int index = (int) (startSample - bufferStart);
  16294. if (usesFloatingPointData)
  16295. {
  16296. const float sample1 = fabsf (((float*) tempBuffer[0]) [index]);
  16297. if (sample1 >= magnitudeRangeMinimum
  16298. && sample1 <= magnitudeRangeMaximum)
  16299. {
  16300. matches = true;
  16301. }
  16302. else if (numChannels > 1)
  16303. {
  16304. const float sample2 = fabsf (((float*) tempBuffer[1]) [index]);
  16305. matches = (sample2 >= magnitudeRangeMinimum
  16306. && sample2 <= magnitudeRangeMaximum);
  16307. }
  16308. }
  16309. else
  16310. {
  16311. const int sample1 = abs (tempBuffer[0] [index]);
  16312. if (sample1 >= intMagnitudeRangeMinimum
  16313. && sample1 <= intMagnitudeRangeMaximum)
  16314. {
  16315. matches = true;
  16316. }
  16317. else if (numChannels > 1)
  16318. {
  16319. const int sample2 = abs (tempBuffer[1][index]);
  16320. matches = (sample2 >= intMagnitudeRangeMinimum
  16321. && sample2 <= intMagnitudeRangeMaximum);
  16322. }
  16323. }
  16324. if (matches)
  16325. {
  16326. if (firstMatchPos < 0)
  16327. firstMatchPos = startSample;
  16328. if (++consecutive >= minimumConsecutiveSamples)
  16329. {
  16330. if (firstMatchPos < 0 || firstMatchPos >= lengthInSamples)
  16331. return -1;
  16332. return firstMatchPos;
  16333. }
  16334. }
  16335. else
  16336. {
  16337. consecutive = 0;
  16338. firstMatchPos = -1;
  16339. }
  16340. if (numSamplesToSearch > 0)
  16341. ++startSample;
  16342. }
  16343. if (numSamplesToSearch > 0)
  16344. numSamplesToSearch -= numThisTime;
  16345. else
  16346. numSamplesToSearch += numThisTime;
  16347. }
  16348. return -1;
  16349. }
  16350. AudioFormatWriter::AudioFormatWriter (OutputStream* const out,
  16351. const String& formatName_,
  16352. const double rate,
  16353. const unsigned int numChannels_,
  16354. const unsigned int bitsPerSample_)
  16355. : sampleRate (rate),
  16356. numChannels (numChannels_),
  16357. bitsPerSample (bitsPerSample_),
  16358. usesFloatingPointData (false),
  16359. output (out),
  16360. formatName (formatName_)
  16361. {
  16362. }
  16363. AudioFormatWriter::~AudioFormatWriter()
  16364. {
  16365. delete output;
  16366. }
  16367. bool AudioFormatWriter::writeFromAudioReader (AudioFormatReader& reader,
  16368. int64 startSample,
  16369. int64 numSamplesToRead)
  16370. {
  16371. const int bufferSize = 16384;
  16372. const int maxChans = 128;
  16373. AudioSampleBuffer tempBuffer (reader.numChannels, bufferSize);
  16374. int* buffers [maxChans];
  16375. for (int i = maxChans; --i >= 0;)
  16376. buffers[i] = 0;
  16377. if (numSamplesToRead < 0)
  16378. numSamplesToRead = reader.lengthInSamples;
  16379. while (numSamplesToRead > 0)
  16380. {
  16381. const int numToDo = (int) jmin (numSamplesToRead, (int64) bufferSize);
  16382. for (int i = tempBuffer.getNumChannels(); --i >= 0;)
  16383. buffers[i] = (int*) tempBuffer.getSampleData (i, 0);
  16384. if (! reader.read (buffers, maxChans, startSample, numToDo, false))
  16385. return false;
  16386. if (reader.usesFloatingPointData != isFloatingPoint())
  16387. {
  16388. int** bufferChan = buffers;
  16389. while (*bufferChan != 0)
  16390. {
  16391. int* b = *bufferChan++;
  16392. if (isFloatingPoint())
  16393. {
  16394. // int -> float
  16395. const double factor = 1.0 / std::numeric_limits<int>::max();
  16396. for (int i = 0; i < numToDo; ++i)
  16397. ((float*) b)[i] = (float) (factor * b[i]);
  16398. }
  16399. else
  16400. {
  16401. // float -> int
  16402. for (int i = 0; i < numToDo; ++i)
  16403. {
  16404. const double samp = *(const float*) b;
  16405. if (samp <= -1.0)
  16406. *b++ = std::numeric_limits<int>::min();
  16407. else if (samp >= 1.0)
  16408. *b++ = std::numeric_limits<int>::max();
  16409. else
  16410. *b++ = roundToInt (std::numeric_limits<int>::max() * samp);
  16411. }
  16412. }
  16413. }
  16414. }
  16415. if (! write ((const int**) buffers, numToDo))
  16416. return false;
  16417. numSamplesToRead -= numToDo;
  16418. startSample += numToDo;
  16419. }
  16420. return true;
  16421. }
  16422. bool AudioFormatWriter::writeFromAudioSource (AudioSource& source,
  16423. int numSamplesToRead,
  16424. const int samplesPerBlock)
  16425. {
  16426. const int maxChans = 128;
  16427. AudioSampleBuffer tempBuffer (getNumChannels(), samplesPerBlock);
  16428. int* buffers [maxChans];
  16429. while (numSamplesToRead > 0)
  16430. {
  16431. const int numToDo = jmin (numSamplesToRead, samplesPerBlock);
  16432. AudioSourceChannelInfo info;
  16433. info.buffer = &tempBuffer;
  16434. info.startSample = 0;
  16435. info.numSamples = numToDo;
  16436. info.clearActiveBufferRegion();
  16437. source.getNextAudioBlock (info);
  16438. int i;
  16439. for (i = maxChans; --i >= 0;)
  16440. buffers[i] = 0;
  16441. for (i = tempBuffer.getNumChannels(); --i >= 0;)
  16442. buffers[i] = (int*) tempBuffer.getSampleData (i, 0);
  16443. if (! isFloatingPoint())
  16444. {
  16445. int** bufferChan = buffers;
  16446. while (*bufferChan != 0)
  16447. {
  16448. int* b = *bufferChan++;
  16449. // float -> int
  16450. for (int j = numToDo; --j >= 0;)
  16451. {
  16452. const double samp = *(const float*) b;
  16453. if (samp <= -1.0)
  16454. *b++ = std::numeric_limits<int>::min();
  16455. else if (samp >= 1.0)
  16456. *b++ = std::numeric_limits<int>::max();
  16457. else
  16458. *b++ = roundToInt (std::numeric_limits<int>::max() * samp);
  16459. }
  16460. }
  16461. }
  16462. if (! write ((const int**) buffers, numToDo))
  16463. return false;
  16464. numSamplesToRead -= numToDo;
  16465. }
  16466. return true;
  16467. }
  16468. AudioFormat::AudioFormat (const String& name,
  16469. const tchar** const extensions)
  16470. : formatName (name),
  16471. fileExtensions (extensions)
  16472. {
  16473. }
  16474. AudioFormat::~AudioFormat()
  16475. {
  16476. }
  16477. const String& AudioFormat::getFormatName() const
  16478. {
  16479. return formatName;
  16480. }
  16481. const StringArray& AudioFormat::getFileExtensions() const
  16482. {
  16483. return fileExtensions;
  16484. }
  16485. bool AudioFormat::canHandleFile (const File& f)
  16486. {
  16487. for (int i = 0; i < fileExtensions.size(); ++i)
  16488. if (f.hasFileExtension (fileExtensions[i]))
  16489. return true;
  16490. return false;
  16491. }
  16492. bool AudioFormat::isCompressed()
  16493. {
  16494. return false;
  16495. }
  16496. const StringArray AudioFormat::getQualityOptions()
  16497. {
  16498. return StringArray();
  16499. }
  16500. END_JUCE_NAMESPACE
  16501. /*** End of inlined file: juce_AudioFormat.cpp ***/
  16502. /*** Start of inlined file: juce_AudioFormatManager.cpp ***/
  16503. BEGIN_JUCE_NAMESPACE
  16504. AudioFormatManager::AudioFormatManager()
  16505. : defaultFormatIndex (0)
  16506. {
  16507. }
  16508. AudioFormatManager::~AudioFormatManager()
  16509. {
  16510. clearFormats();
  16511. clearSingletonInstance();
  16512. }
  16513. juce_ImplementSingleton (AudioFormatManager);
  16514. void AudioFormatManager::registerFormat (AudioFormat* newFormat,
  16515. const bool makeThisTheDefaultFormat)
  16516. {
  16517. jassert (newFormat != 0);
  16518. if (newFormat != 0)
  16519. {
  16520. #ifdef JUCE_DEBUG
  16521. for (int i = getNumKnownFormats(); --i >= 0;)
  16522. {
  16523. if (getKnownFormat (i)->getFormatName() == newFormat->getFormatName())
  16524. {
  16525. jassertfalse // trying to add the same format twice!
  16526. }
  16527. }
  16528. #endif
  16529. if (makeThisTheDefaultFormat)
  16530. defaultFormatIndex = knownFormats.size();
  16531. knownFormats.add (newFormat);
  16532. }
  16533. }
  16534. void AudioFormatManager::registerBasicFormats()
  16535. {
  16536. #if JUCE_MAC
  16537. registerFormat (new AiffAudioFormat(), true);
  16538. registerFormat (new WavAudioFormat(), false);
  16539. #else
  16540. registerFormat (new WavAudioFormat(), true);
  16541. registerFormat (new AiffAudioFormat(), false);
  16542. #endif
  16543. #if JUCE_USE_FLAC
  16544. registerFormat (new FlacAudioFormat(), false);
  16545. #endif
  16546. #if JUCE_USE_OGGVORBIS
  16547. registerFormat (new OggVorbisAudioFormat(), false);
  16548. #endif
  16549. }
  16550. void AudioFormatManager::clearFormats()
  16551. {
  16552. for (int i = getNumKnownFormats(); --i >= 0;)
  16553. delete getKnownFormat(i);
  16554. knownFormats.clear();
  16555. defaultFormatIndex = 0;
  16556. }
  16557. int AudioFormatManager::getNumKnownFormats() const
  16558. {
  16559. return knownFormats.size();
  16560. }
  16561. AudioFormat* AudioFormatManager::getKnownFormat (const int index) const
  16562. {
  16563. return (AudioFormat*) knownFormats [index];
  16564. }
  16565. AudioFormat* AudioFormatManager::getDefaultFormat() const
  16566. {
  16567. return getKnownFormat (defaultFormatIndex);
  16568. }
  16569. AudioFormat* AudioFormatManager::findFormatForFileExtension (const String& fileExtension) const
  16570. {
  16571. String e (fileExtension);
  16572. if (! e.startsWithChar (T('.')))
  16573. e = T(".") + e;
  16574. for (int i = 0; i < getNumKnownFormats(); ++i)
  16575. if (getKnownFormat(i)->getFileExtensions().contains (e, true))
  16576. return getKnownFormat(i);
  16577. return 0;
  16578. }
  16579. const String AudioFormatManager::getWildcardForAllFormats() const
  16580. {
  16581. StringArray allExtensions;
  16582. int i;
  16583. for (i = 0; i < getNumKnownFormats(); ++i)
  16584. allExtensions.addArray (getKnownFormat (i)->getFileExtensions());
  16585. allExtensions.trim();
  16586. allExtensions.removeEmptyStrings();
  16587. String s;
  16588. for (i = 0; i < allExtensions.size(); ++i)
  16589. {
  16590. s << T('*');
  16591. if (! allExtensions[i].startsWithChar (T('.')))
  16592. s << T('.');
  16593. s << allExtensions[i];
  16594. if (i < allExtensions.size() - 1)
  16595. s << T(';');
  16596. }
  16597. return s;
  16598. }
  16599. AudioFormatReader* AudioFormatManager::createReaderFor (const File& file)
  16600. {
  16601. // you need to actually register some formats before the manager can
  16602. // use them to open a file!
  16603. jassert (knownFormats.size() > 0);
  16604. for (int i = 0; i < getNumKnownFormats(); ++i)
  16605. {
  16606. AudioFormat* const af = getKnownFormat(i);
  16607. if (af->canHandleFile (file))
  16608. {
  16609. InputStream* const in = file.createInputStream();
  16610. if (in != 0)
  16611. {
  16612. AudioFormatReader* const r = af->createReaderFor (in, true);
  16613. if (r != 0)
  16614. return r;
  16615. }
  16616. }
  16617. }
  16618. return 0;
  16619. }
  16620. AudioFormatReader* AudioFormatManager::createReaderFor (InputStream* audioFileStream)
  16621. {
  16622. // you need to actually register some formats before the manager can
  16623. // use them to open a file!
  16624. jassert (knownFormats.size() > 0);
  16625. ScopedPointer <InputStream> in (audioFileStream);
  16626. if (in != 0)
  16627. {
  16628. const int64 originalStreamPos = in->getPosition();
  16629. for (int i = 0; i < getNumKnownFormats(); ++i)
  16630. {
  16631. AudioFormatReader* const r = getKnownFormat(i)->createReaderFor (in, false);
  16632. if (r != 0)
  16633. {
  16634. in.release();
  16635. return r;
  16636. }
  16637. in->setPosition (originalStreamPos);
  16638. // the stream that is passed-in must be capable of being repositioned so
  16639. // that all the formats can have a go at opening it.
  16640. jassert (in->getPosition() == originalStreamPos);
  16641. }
  16642. }
  16643. return 0;
  16644. }
  16645. END_JUCE_NAMESPACE
  16646. /*** End of inlined file: juce_AudioFormatManager.cpp ***/
  16647. /*** Start of inlined file: juce_AudioSubsectionReader.cpp ***/
  16648. BEGIN_JUCE_NAMESPACE
  16649. AudioSubsectionReader::AudioSubsectionReader (AudioFormatReader* const source_,
  16650. const int64 startSample_,
  16651. const int64 length_,
  16652. const bool deleteSourceWhenDeleted_)
  16653. : AudioFormatReader (0, source_->getFormatName()),
  16654. source (source_),
  16655. startSample (startSample_),
  16656. deleteSourceWhenDeleted (deleteSourceWhenDeleted_)
  16657. {
  16658. length = jmin (jmax ((int64) 0, source->lengthInSamples - startSample), length_);
  16659. sampleRate = source->sampleRate;
  16660. bitsPerSample = source->bitsPerSample;
  16661. lengthInSamples = length;
  16662. numChannels = source->numChannels;
  16663. usesFloatingPointData = source->usesFloatingPointData;
  16664. }
  16665. AudioSubsectionReader::~AudioSubsectionReader()
  16666. {
  16667. if (deleteSourceWhenDeleted)
  16668. delete source;
  16669. }
  16670. bool AudioSubsectionReader::readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  16671. int64 startSampleInFile, int numSamples)
  16672. {
  16673. if (startSampleInFile + numSamples > length)
  16674. {
  16675. for (int i = numDestChannels; --i >= 0;)
  16676. if (destSamples[i] != 0)
  16677. zeromem (destSamples[i], sizeof (int) * numSamples);
  16678. numSamples = jmin (numSamples, (int) (length - startSampleInFile));
  16679. if (numSamples <= 0)
  16680. return true;
  16681. }
  16682. return source->readSamples (destSamples, numDestChannels, startOffsetInDestBuffer,
  16683. startSampleInFile + startSample, numSamples);
  16684. }
  16685. void AudioSubsectionReader::readMaxLevels (int64 startSampleInFile,
  16686. int64 numSamples,
  16687. float& lowestLeft,
  16688. float& highestLeft,
  16689. float& lowestRight,
  16690. float& highestRight)
  16691. {
  16692. startSampleInFile = jmax ((int64) 0, startSampleInFile);
  16693. numSamples = jmax ((int64) 0, jmin (numSamples, length - startSampleInFile));
  16694. source->readMaxLevels (startSampleInFile + startSample,
  16695. numSamples,
  16696. lowestLeft,
  16697. highestLeft,
  16698. lowestRight,
  16699. highestRight);
  16700. }
  16701. END_JUCE_NAMESPACE
  16702. /*** End of inlined file: juce_AudioSubsectionReader.cpp ***/
  16703. /*** Start of inlined file: juce_AudioThumbnail.cpp ***/
  16704. BEGIN_JUCE_NAMESPACE
  16705. const int timeBeforeDeletingReader = 2000;
  16706. struct AudioThumbnailDataFormat
  16707. {
  16708. char thumbnailMagic[4];
  16709. int samplesPerThumbSample;
  16710. int64 totalSamples; // source samples
  16711. int64 numFinishedSamples; // source samples
  16712. int numThumbnailSamples;
  16713. int numChannels;
  16714. int sampleRate;
  16715. char future[16];
  16716. char data[1];
  16717. };
  16718. #if JUCE_BIG_ENDIAN
  16719. static void swap (int& n) { n = (int) ByteOrder::swap ((uint32) n); }
  16720. static void swap (int64& n) { n = (int64) ByteOrder::swap ((uint64) n); }
  16721. #endif
  16722. static void swapEndiannessIfNeeded (AudioThumbnailDataFormat* const d)
  16723. {
  16724. (void) d;
  16725. #if JUCE_BIG_ENDIAN
  16726. swap (d->samplesPerThumbSample);
  16727. swap (d->totalSamples);
  16728. swap (d->numFinishedSamples);
  16729. swap (d->numThumbnailSamples);
  16730. swap (d->numChannels);
  16731. swap (d->sampleRate);
  16732. #endif
  16733. }
  16734. AudioThumbnail::AudioThumbnail (const int orginalSamplesPerThumbnailSample_,
  16735. AudioFormatManager& formatManagerToUse_,
  16736. AudioThumbnailCache& cacheToUse)
  16737. : formatManagerToUse (formatManagerToUse_),
  16738. cache (cacheToUse),
  16739. orginalSamplesPerThumbnailSample (orginalSamplesPerThumbnailSample_)
  16740. {
  16741. clear();
  16742. }
  16743. AudioThumbnail::~AudioThumbnail()
  16744. {
  16745. cache.removeThumbnail (this);
  16746. const ScopedLock sl (readerLock);
  16747. reader = 0;
  16748. }
  16749. void AudioThumbnail::setSource (InputSource* const newSource)
  16750. {
  16751. cache.removeThumbnail (this);
  16752. timerCallback(); // stops the timer and deletes the reader
  16753. source = newSource;
  16754. clear();
  16755. if (newSource != 0
  16756. && ! (cache.loadThumb (*this, newSource->hashCode())
  16757. && isFullyLoaded()))
  16758. {
  16759. {
  16760. const ScopedLock sl (readerLock);
  16761. reader = createReader();
  16762. }
  16763. if (reader != 0)
  16764. {
  16765. initialiseFromAudioFile (*reader);
  16766. cache.addThumbnail (this);
  16767. }
  16768. }
  16769. sendChangeMessage (this);
  16770. }
  16771. bool AudioThumbnail::useTimeSlice()
  16772. {
  16773. const ScopedLock sl (readerLock);
  16774. if (isFullyLoaded())
  16775. {
  16776. if (reader != 0)
  16777. startTimer (timeBeforeDeletingReader);
  16778. cache.removeThumbnail (this);
  16779. return false;
  16780. }
  16781. if (reader == 0)
  16782. reader = createReader();
  16783. if (reader != 0)
  16784. {
  16785. readNextBlockFromAudioFile (*reader);
  16786. stopTimer();
  16787. sendChangeMessage (this);
  16788. const bool justFinished = isFullyLoaded();
  16789. if (justFinished)
  16790. cache.storeThumb (*this, source->hashCode());
  16791. return ! justFinished;
  16792. }
  16793. return false;
  16794. }
  16795. AudioFormatReader* AudioThumbnail::createReader() const
  16796. {
  16797. if (source != 0)
  16798. {
  16799. InputStream* const audioFileStream = source->createInputStream();
  16800. if (audioFileStream != 0)
  16801. return formatManagerToUse.createReaderFor (audioFileStream);
  16802. }
  16803. return 0;
  16804. }
  16805. void AudioThumbnail::timerCallback()
  16806. {
  16807. stopTimer();
  16808. const ScopedLock sl (readerLock);
  16809. reader = 0;
  16810. }
  16811. void AudioThumbnail::clear()
  16812. {
  16813. data.setSize (sizeof (AudioThumbnailDataFormat) + 3);
  16814. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16815. d->thumbnailMagic[0] = 'j';
  16816. d->thumbnailMagic[1] = 'a';
  16817. d->thumbnailMagic[2] = 't';
  16818. d->thumbnailMagic[3] = 'm';
  16819. d->samplesPerThumbSample = orginalSamplesPerThumbnailSample;
  16820. d->totalSamples = 0;
  16821. d->numFinishedSamples = 0;
  16822. d->numThumbnailSamples = 0;
  16823. d->numChannels = 0;
  16824. d->sampleRate = 0;
  16825. numSamplesCached = 0;
  16826. cacheNeedsRefilling = true;
  16827. }
  16828. void AudioThumbnail::loadFrom (InputStream& input)
  16829. {
  16830. const ScopedLock sl (readerLock);
  16831. data.setSize (0);
  16832. input.readIntoMemoryBlock (data);
  16833. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16834. swapEndiannessIfNeeded (d);
  16835. if (! (d->thumbnailMagic[0] == 'j'
  16836. && d->thumbnailMagic[1] == 'a'
  16837. && d->thumbnailMagic[2] == 't'
  16838. && d->thumbnailMagic[3] == 'm'))
  16839. {
  16840. clear();
  16841. }
  16842. numSamplesCached = 0;
  16843. cacheNeedsRefilling = true;
  16844. }
  16845. void AudioThumbnail::saveTo (OutputStream& output) const
  16846. {
  16847. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16848. swapEndiannessIfNeeded (d);
  16849. output.write (data.getData(), (int) data.getSize());
  16850. swapEndiannessIfNeeded (d);
  16851. }
  16852. bool AudioThumbnail::initialiseFromAudioFile (AudioFormatReader& fileReader)
  16853. {
  16854. AudioThumbnailDataFormat* d = (AudioThumbnailDataFormat*) data.getData();
  16855. d->totalSamples = fileReader.lengthInSamples;
  16856. d->numChannels = jmin ((uint32) 2, fileReader.numChannels);
  16857. d->numFinishedSamples = 0;
  16858. d->sampleRate = roundToInt (fileReader.sampleRate);
  16859. d->numThumbnailSamples = (int) (d->totalSamples / d->samplesPerThumbSample) + 1;
  16860. data.setSize (sizeof (AudioThumbnailDataFormat) + 3 + d->numThumbnailSamples * d->numChannels * 2);
  16861. d = (AudioThumbnailDataFormat*) data.getData();
  16862. zeromem (&(d->data[0]), d->numThumbnailSamples * d->numChannels * 2);
  16863. return d->totalSamples > 0;
  16864. }
  16865. bool AudioThumbnail::readNextBlockFromAudioFile (AudioFormatReader& fileReader)
  16866. {
  16867. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16868. if (d->numFinishedSamples < d->totalSamples)
  16869. {
  16870. const int numToDo = (int) jmin ((int64) 65536, d->totalSamples - d->numFinishedSamples);
  16871. generateSection (fileReader,
  16872. d->numFinishedSamples,
  16873. numToDo);
  16874. d->numFinishedSamples += numToDo;
  16875. }
  16876. cacheNeedsRefilling = true;
  16877. return (d->numFinishedSamples < d->totalSamples);
  16878. }
  16879. int AudioThumbnail::getNumChannels() const throw()
  16880. {
  16881. const AudioThumbnailDataFormat* const d = (const AudioThumbnailDataFormat*) data.getData();
  16882. jassert (d != 0);
  16883. return d->numChannels;
  16884. }
  16885. double AudioThumbnail::getTotalLength() const throw()
  16886. {
  16887. const AudioThumbnailDataFormat* const d = (const AudioThumbnailDataFormat*) data.getData();
  16888. jassert (d != 0);
  16889. if (d->sampleRate > 0)
  16890. return d->totalSamples / (double)d->sampleRate;
  16891. else
  16892. return 0.0;
  16893. }
  16894. void AudioThumbnail::generateSection (AudioFormatReader& fileReader,
  16895. int64 startSample,
  16896. int numSamples)
  16897. {
  16898. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16899. jassert (d != 0);
  16900. int firstDataPos = (int) (startSample / d->samplesPerThumbSample);
  16901. int lastDataPos = (int) ((startSample + numSamples) / d->samplesPerThumbSample);
  16902. char* l = getChannelData (0);
  16903. char* r = getChannelData (1);
  16904. for (int i = firstDataPos; i < lastDataPos; ++i)
  16905. {
  16906. const int sourceStart = i * d->samplesPerThumbSample;
  16907. const int sourceEnd = sourceStart + d->samplesPerThumbSample;
  16908. float lowestLeft, highestLeft, lowestRight, highestRight;
  16909. fileReader.readMaxLevels (sourceStart,
  16910. sourceEnd - sourceStart,
  16911. lowestLeft,
  16912. highestLeft,
  16913. lowestRight,
  16914. highestRight);
  16915. int n = i * 2;
  16916. if (r != 0)
  16917. {
  16918. l [n] = (char) jlimit (-128.0f, 127.0f, lowestLeft * 127.0f);
  16919. r [n++] = (char) jlimit (-128.0f, 127.0f, lowestRight * 127.0f);
  16920. l [n] = (char) jlimit (-128.0f, 127.0f, highestLeft * 127.0f);
  16921. r [n++] = (char) jlimit (-128.0f, 127.0f, highestRight * 127.0f);
  16922. }
  16923. else
  16924. {
  16925. l [n++] = (char) jlimit (-128.0f, 127.0f, lowestLeft * 127.0f);
  16926. l [n++] = (char) jlimit (-128.0f, 127.0f, highestLeft * 127.0f);
  16927. }
  16928. }
  16929. }
  16930. char* AudioThumbnail::getChannelData (int channel) const
  16931. {
  16932. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16933. jassert (d != 0);
  16934. if (channel >= 0 && channel < d->numChannels)
  16935. return d->data + (channel * 2 * d->numThumbnailSamples);
  16936. return 0;
  16937. }
  16938. bool AudioThumbnail::isFullyLoaded() const throw()
  16939. {
  16940. const AudioThumbnailDataFormat* const d = (const AudioThumbnailDataFormat*) data.getData();
  16941. jassert (d != 0);
  16942. return d->numFinishedSamples >= d->totalSamples;
  16943. }
  16944. void AudioThumbnail::refillCache (const int numSamples,
  16945. double startTime,
  16946. const double timePerPixel)
  16947. {
  16948. const AudioThumbnailDataFormat* const d = (const AudioThumbnailDataFormat*) data.getData();
  16949. jassert (d != 0);
  16950. if (numSamples <= 0
  16951. || timePerPixel <= 0.0
  16952. || d->sampleRate <= 0)
  16953. {
  16954. numSamplesCached = 0;
  16955. cacheNeedsRefilling = true;
  16956. return;
  16957. }
  16958. if (numSamples == numSamplesCached
  16959. && numChannelsCached == d->numChannels
  16960. && startTime == cachedStart
  16961. && timePerPixel == cachedTimePerPixel
  16962. && ! cacheNeedsRefilling)
  16963. {
  16964. return;
  16965. }
  16966. numSamplesCached = numSamples;
  16967. numChannelsCached = d->numChannels;
  16968. cachedStart = startTime;
  16969. cachedTimePerPixel = timePerPixel;
  16970. cachedLevels.ensureSize (2 * numChannelsCached * numSamples);
  16971. const bool needExtraDetail = (timePerPixel * d->sampleRate <= d->samplesPerThumbSample);
  16972. const ScopedLock sl (readerLock);
  16973. cacheNeedsRefilling = false;
  16974. if (needExtraDetail && reader == 0)
  16975. reader = createReader();
  16976. if (reader != 0 && timePerPixel * d->sampleRate <= d->samplesPerThumbSample)
  16977. {
  16978. startTimer (timeBeforeDeletingReader);
  16979. char* cacheData = (char*) cachedLevels.getData();
  16980. int sample = roundToInt (startTime * d->sampleRate);
  16981. for (int i = numSamples; --i >= 0;)
  16982. {
  16983. const int nextSample = roundToInt ((startTime + timePerPixel) * d->sampleRate);
  16984. if (sample >= 0)
  16985. {
  16986. if (sample >= reader->lengthInSamples)
  16987. break;
  16988. float lmin, lmax, rmin, rmax;
  16989. reader->readMaxLevels (sample,
  16990. jmax (1, nextSample - sample),
  16991. lmin, lmax, rmin, rmax);
  16992. cacheData[0] = (char) jlimit (-128, 127, roundFloatToInt (lmin * 127.0f));
  16993. cacheData[1] = (char) jlimit (-128, 127, roundFloatToInt (lmax * 127.0f));
  16994. if (numChannelsCached > 1)
  16995. {
  16996. cacheData[2] = (char) jlimit (-128, 127, roundFloatToInt (rmin * 127.0f));
  16997. cacheData[3] = (char) jlimit (-128, 127, roundFloatToInt (rmax * 127.0f));
  16998. }
  16999. cacheData += 2 * numChannelsCached;
  17000. }
  17001. startTime += timePerPixel;
  17002. sample = nextSample;
  17003. }
  17004. }
  17005. else
  17006. {
  17007. for (int channelNum = 0; channelNum < numChannelsCached; ++channelNum)
  17008. {
  17009. char* const channelData = getChannelData (channelNum);
  17010. char* cacheData = ((char*) cachedLevels.getData()) + channelNum * 2;
  17011. const double timeToThumbSampleFactor = d->sampleRate / (double) d->samplesPerThumbSample;
  17012. startTime = cachedStart;
  17013. int sample = roundToInt (startTime * timeToThumbSampleFactor);
  17014. const int numFinished = (int) (d->numFinishedSamples / d->samplesPerThumbSample);
  17015. for (int i = numSamples; --i >= 0;)
  17016. {
  17017. const int nextSample = roundToInt ((startTime + timePerPixel) * timeToThumbSampleFactor);
  17018. if (sample >= 0 && channelData != 0)
  17019. {
  17020. char mx = -128;
  17021. char mn = 127;
  17022. while (sample <= nextSample)
  17023. {
  17024. if (sample >= numFinished)
  17025. break;
  17026. const int n = sample << 1;
  17027. const char sampMin = channelData [n];
  17028. const char sampMax = channelData [n + 1];
  17029. if (sampMin < mn)
  17030. mn = sampMin;
  17031. if (sampMax > mx)
  17032. mx = sampMax;
  17033. ++sample;
  17034. }
  17035. if (mn <= mx)
  17036. {
  17037. cacheData[0] = mn;
  17038. cacheData[1] = mx;
  17039. }
  17040. else
  17041. {
  17042. cacheData[0] = 1;
  17043. cacheData[1] = 0;
  17044. }
  17045. }
  17046. else
  17047. {
  17048. cacheData[0] = 1;
  17049. cacheData[1] = 0;
  17050. }
  17051. cacheData += numChannelsCached * 2;
  17052. startTime += timePerPixel;
  17053. sample = nextSample;
  17054. }
  17055. }
  17056. }
  17057. }
  17058. void AudioThumbnail::drawChannel (Graphics& g,
  17059. int x, int y, int w, int h,
  17060. double startTime,
  17061. double endTime,
  17062. int channelNum,
  17063. const float verticalZoomFactor)
  17064. {
  17065. refillCache (w, startTime, (endTime - startTime) / w);
  17066. if (numSamplesCached >= w
  17067. && channelNum >= 0
  17068. && channelNum < numChannelsCached)
  17069. {
  17070. const float topY = (float) y;
  17071. const float bottomY = topY + h;
  17072. const float midY = topY + h * 0.5f;
  17073. const float vscale = verticalZoomFactor * h / 256.0f;
  17074. const Rectangle<int> clip (g.getClipBounds());
  17075. const int skipLeft = jlimit (0, w, clip.getX() - x);
  17076. w -= skipLeft;
  17077. x += skipLeft;
  17078. const char* cacheData = ((const char*) cachedLevels.getData())
  17079. + (channelNum << 1)
  17080. + skipLeft * (numChannelsCached << 1);
  17081. while (--w >= 0)
  17082. {
  17083. const char mn = cacheData[0];
  17084. const char mx = cacheData[1];
  17085. cacheData += numChannelsCached << 1;
  17086. if (mn <= mx) // if the wrong way round, signifies that the sample's not yet known
  17087. g.drawLine ((float) x, jmax (midY - mx * vscale - 0.3f, topY),
  17088. (float) x, jmin (midY - mn * vscale + 0.3f, bottomY));
  17089. ++x;
  17090. if (x >= clip.getRight())
  17091. break;
  17092. }
  17093. }
  17094. }
  17095. END_JUCE_NAMESPACE
  17096. /*** End of inlined file: juce_AudioThumbnail.cpp ***/
  17097. /*** Start of inlined file: juce_AudioThumbnailCache.cpp ***/
  17098. BEGIN_JUCE_NAMESPACE
  17099. struct ThumbnailCacheEntry
  17100. {
  17101. int64 hash;
  17102. uint32 lastUsed;
  17103. MemoryBlock data;
  17104. juce_UseDebuggingNewOperator
  17105. };
  17106. AudioThumbnailCache::AudioThumbnailCache (const int maxNumThumbsToStore_)
  17107. : TimeSliceThread (T("thumb cache")),
  17108. maxNumThumbsToStore (maxNumThumbsToStore_)
  17109. {
  17110. startThread (2);
  17111. }
  17112. AudioThumbnailCache::~AudioThumbnailCache()
  17113. {
  17114. }
  17115. bool AudioThumbnailCache::loadThumb (AudioThumbnail& thumb, const int64 hashCode)
  17116. {
  17117. for (int i = thumbs.size(); --i >= 0;)
  17118. {
  17119. if (thumbs[i]->hash == hashCode)
  17120. {
  17121. MemoryInputStream in ((const char*) thumbs[i]->data.getData(),
  17122. thumbs[i]->data.getSize(),
  17123. false);
  17124. thumb.loadFrom (in);
  17125. thumbs[i]->lastUsed = Time::getMillisecondCounter();
  17126. return true;
  17127. }
  17128. }
  17129. return false;
  17130. }
  17131. void AudioThumbnailCache::storeThumb (const AudioThumbnail& thumb,
  17132. const int64 hashCode)
  17133. {
  17134. MemoryOutputStream out;
  17135. thumb.saveTo (out);
  17136. ThumbnailCacheEntry* te = 0;
  17137. for (int i = thumbs.size(); --i >= 0;)
  17138. {
  17139. if (thumbs[i]->hash == hashCode)
  17140. {
  17141. te = thumbs[i];
  17142. break;
  17143. }
  17144. }
  17145. if (te == 0)
  17146. {
  17147. te = new ThumbnailCacheEntry();
  17148. te->hash = hashCode;
  17149. if (thumbs.size() < maxNumThumbsToStore)
  17150. {
  17151. thumbs.add (te);
  17152. }
  17153. else
  17154. {
  17155. int oldest = 0;
  17156. unsigned int oldestTime = Time::getMillisecondCounter() + 1;
  17157. int i;
  17158. for (i = thumbs.size(); --i >= 0;)
  17159. if (thumbs[i]->lastUsed < oldestTime)
  17160. oldest = i;
  17161. thumbs.set (i, te);
  17162. }
  17163. }
  17164. te->lastUsed = Time::getMillisecondCounter();
  17165. te->data.setSize (0);
  17166. te->data.append (out.getData(), out.getDataSize());
  17167. }
  17168. void AudioThumbnailCache::clear()
  17169. {
  17170. thumbs.clear();
  17171. }
  17172. void AudioThumbnailCache::addThumbnail (AudioThumbnail* const thumb)
  17173. {
  17174. addTimeSliceClient (thumb);
  17175. }
  17176. void AudioThumbnailCache::removeThumbnail (AudioThumbnail* const thumb)
  17177. {
  17178. removeTimeSliceClient (thumb);
  17179. }
  17180. END_JUCE_NAMESPACE
  17181. /*** End of inlined file: juce_AudioThumbnailCache.cpp ***/
  17182. /*** Start of inlined file: juce_QuickTimeAudioFormat.cpp ***/
  17183. #if JUCE_QUICKTIME && ! (JUCE_64BIT || JUCE_IPHONE)
  17184. #if ! JUCE_WINDOWS
  17185. #include <QuickTime/Movies.h>
  17186. #include <QuickTime/QTML.h>
  17187. #include <QuickTime/QuickTimeComponents.h>
  17188. #include <QuickTime/MediaHandlers.h>
  17189. #include <QuickTime/ImageCodec.h>
  17190. #else
  17191. #if JUCE_MSVC
  17192. #pragma warning (push)
  17193. #pragma warning (disable : 4100)
  17194. #endif
  17195. #include <Movies.h>
  17196. #include <QTML.h>
  17197. #include <QuickTimeComponents.h>
  17198. #include <MediaHandlers.h>
  17199. #include <ImageCodec.h>
  17200. #if JUCE_MSVC
  17201. #pragma warning (pop)
  17202. #endif
  17203. #endif
  17204. BEGIN_JUCE_NAMESPACE
  17205. bool juce_OpenQuickTimeMovieFromStream (InputStream* input, Movie& movie, Handle& dataHandle);
  17206. static const char* const quickTimeFormatName = "QuickTime file";
  17207. static const tchar* const quickTimeExtensions[] = { T(".mov"), T(".mp3"), T(".mp4"), 0 };
  17208. class QTAudioReader : public AudioFormatReader
  17209. {
  17210. public:
  17211. QTAudioReader (InputStream* const input_, const int trackNum_)
  17212. : AudioFormatReader (input_, TRANS (quickTimeFormatName)),
  17213. ok (false),
  17214. movie (0),
  17215. trackNum (trackNum_),
  17216. lastSampleRead (0),
  17217. lastThreadId (0),
  17218. extractor (0),
  17219. dataHandle (0)
  17220. {
  17221. bufferList.calloc (256, 1);
  17222. #ifdef WIN32
  17223. if (InitializeQTML (0) != noErr)
  17224. return;
  17225. #endif
  17226. if (EnterMovies() != noErr)
  17227. return;
  17228. bool opened = juce_OpenQuickTimeMovieFromStream (input_, movie, dataHandle);
  17229. if (! opened)
  17230. return;
  17231. {
  17232. const int numTracks = GetMovieTrackCount (movie);
  17233. int trackCount = 0;
  17234. for (int i = 1; i <= numTracks; ++i)
  17235. {
  17236. track = GetMovieIndTrack (movie, i);
  17237. media = GetTrackMedia (track);
  17238. OSType mediaType;
  17239. GetMediaHandlerDescription (media, &mediaType, 0, 0);
  17240. if (mediaType == SoundMediaType
  17241. && trackCount++ == trackNum_)
  17242. {
  17243. ok = true;
  17244. break;
  17245. }
  17246. }
  17247. }
  17248. if (! ok)
  17249. return;
  17250. ok = false;
  17251. lengthInSamples = GetMediaDecodeDuration (media);
  17252. usesFloatingPointData = false;
  17253. samplesPerFrame = (int) (GetMediaDecodeDuration (media) / GetMediaSampleCount (media));
  17254. trackUnitsPerFrame = GetMovieTimeScale (movie) * samplesPerFrame
  17255. / GetMediaTimeScale (media);
  17256. OSStatus err = MovieAudioExtractionBegin (movie, 0, &extractor);
  17257. unsigned long output_layout_size;
  17258. err = MovieAudioExtractionGetPropertyInfo (extractor,
  17259. kQTPropertyClass_MovieAudioExtraction_Audio,
  17260. kQTMovieAudioExtractionAudioPropertyID_AudioChannelLayout,
  17261. 0, &output_layout_size, 0);
  17262. if (err != noErr)
  17263. return;
  17264. HeapBlock <AudioChannelLayout> qt_audio_channel_layout;
  17265. qt_audio_channel_layout.calloc (output_layout_size, 1);
  17266. err = MovieAudioExtractionGetProperty (extractor,
  17267. kQTPropertyClass_MovieAudioExtraction_Audio,
  17268. kQTMovieAudioExtractionAudioPropertyID_AudioChannelLayout,
  17269. output_layout_size, qt_audio_channel_layout, 0);
  17270. qt_audio_channel_layout[0].mChannelLayoutTag = kAudioChannelLayoutTag_Stereo;
  17271. err = MovieAudioExtractionSetProperty (extractor,
  17272. kQTPropertyClass_MovieAudioExtraction_Audio,
  17273. kQTMovieAudioExtractionAudioPropertyID_AudioChannelLayout,
  17274. output_layout_size,
  17275. qt_audio_channel_layout);
  17276. err = MovieAudioExtractionGetProperty (extractor,
  17277. kQTPropertyClass_MovieAudioExtraction_Audio,
  17278. kQTMovieAudioExtractionAudioPropertyID_AudioStreamBasicDescription,
  17279. sizeof (inputStreamDesc),
  17280. &inputStreamDesc, 0);
  17281. if (err != noErr)
  17282. return;
  17283. inputStreamDesc.mFormatFlags = kAudioFormatFlagIsSignedInteger
  17284. | kAudioFormatFlagIsPacked
  17285. | kAudioFormatFlagsNativeEndian;
  17286. inputStreamDesc.mBitsPerChannel = sizeof (SInt16) * 8;
  17287. inputStreamDesc.mChannelsPerFrame = jmin ((UInt32) 2, inputStreamDesc.mChannelsPerFrame);
  17288. inputStreamDesc.mBytesPerFrame = sizeof (SInt16) * inputStreamDesc.mChannelsPerFrame;
  17289. inputStreamDesc.mBytesPerPacket = inputStreamDesc.mBytesPerFrame;
  17290. err = MovieAudioExtractionSetProperty (extractor,
  17291. kQTPropertyClass_MovieAudioExtraction_Audio,
  17292. kQTMovieAudioExtractionAudioPropertyID_AudioStreamBasicDescription,
  17293. sizeof (inputStreamDesc),
  17294. &inputStreamDesc);
  17295. if (err != noErr)
  17296. return;
  17297. Boolean allChannelsDiscrete = false;
  17298. err = MovieAudioExtractionSetProperty (extractor,
  17299. kQTPropertyClass_MovieAudioExtraction_Movie,
  17300. kQTMovieAudioExtractionMoviePropertyID_AllChannelsDiscrete,
  17301. sizeof (allChannelsDiscrete),
  17302. &allChannelsDiscrete);
  17303. if (err != noErr)
  17304. return;
  17305. bufferList->mNumberBuffers = 1;
  17306. bufferList->mBuffers[0].mNumberChannels = inputStreamDesc.mChannelsPerFrame;
  17307. bufferList->mBuffers[0].mDataByteSize = (UInt32) (samplesPerFrame * inputStreamDesc.mBytesPerFrame) + 16;
  17308. bufferList->mBuffers[0].mData = malloc (bufferList->mBuffers[0].mDataByteSize);
  17309. sampleRate = inputStreamDesc.mSampleRate;
  17310. bitsPerSample = 16;
  17311. numChannels = inputStreamDesc.mChannelsPerFrame;
  17312. detachThread();
  17313. ok = true;
  17314. }
  17315. ~QTAudioReader()
  17316. {
  17317. if (dataHandle != 0)
  17318. DisposeHandle (dataHandle);
  17319. if (extractor != 0)
  17320. {
  17321. MovieAudioExtractionEnd (extractor);
  17322. extractor = 0;
  17323. }
  17324. checkThreadIsAttached();
  17325. DisposeMovie (movie);
  17326. juce_free (bufferList->mBuffers[0].mData);
  17327. #if JUCE_MAC
  17328. ExitMoviesOnThread ();
  17329. #endif
  17330. }
  17331. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  17332. int64 startSampleInFile, int numSamples)
  17333. {
  17334. checkThreadIsAttached();
  17335. while (numSamples > 0)
  17336. {
  17337. if (! loadFrame ((int) startSampleInFile))
  17338. return false;
  17339. const int numToDo = jmin (numSamples, samplesPerFrame);
  17340. for (int j = numDestChannels; --j >= 0;)
  17341. {
  17342. if (destSamples[j] != 0)
  17343. {
  17344. const short* const src = ((const short*) bufferList->mBuffers[0].mData) + j;
  17345. for (int i = 0; i < numToDo; ++i)
  17346. destSamples[j][startOffsetInDestBuffer + i] = src [i << 1] << 16;
  17347. }
  17348. }
  17349. startOffsetInDestBuffer += numToDo;
  17350. startSampleInFile += numToDo;
  17351. numSamples -= numToDo;
  17352. }
  17353. detachThread();
  17354. return true;
  17355. }
  17356. bool loadFrame (const int sampleNum)
  17357. {
  17358. if (lastSampleRead != sampleNum)
  17359. {
  17360. TimeRecord time;
  17361. time.scale = (TimeScale) inputStreamDesc.mSampleRate;
  17362. time.base = 0;
  17363. time.value.hi = 0;
  17364. time.value.lo = (UInt32) sampleNum;
  17365. OSStatus err = MovieAudioExtractionSetProperty (extractor,
  17366. kQTPropertyClass_MovieAudioExtraction_Movie,
  17367. kQTMovieAudioExtractionMoviePropertyID_CurrentTime,
  17368. sizeof (time), &time);
  17369. if (err != noErr)
  17370. return false;
  17371. }
  17372. bufferList->mBuffers[0].mDataByteSize = inputStreamDesc.mBytesPerFrame * samplesPerFrame;
  17373. UInt32 outFlags = 0;
  17374. UInt32 actualNumSamples = samplesPerFrame;
  17375. OSStatus err = MovieAudioExtractionFillBuffer (extractor, &actualNumSamples,
  17376. bufferList, &outFlags);
  17377. lastSampleRead = sampleNum + samplesPerFrame;
  17378. return err == noErr;
  17379. }
  17380. juce_UseDebuggingNewOperator
  17381. bool ok;
  17382. private:
  17383. Movie movie;
  17384. Media media;
  17385. Track track;
  17386. const int trackNum;
  17387. double trackUnitsPerFrame;
  17388. int samplesPerFrame;
  17389. int lastSampleRead;
  17390. Thread::ThreadID lastThreadId;
  17391. MovieAudioExtractionRef extractor;
  17392. AudioStreamBasicDescription inputStreamDesc;
  17393. HeapBlock <AudioBufferList> bufferList;
  17394. Handle dataHandle;
  17395. void checkThreadIsAttached()
  17396. {
  17397. #if JUCE_MAC
  17398. if (Thread::getCurrentThreadId() != lastThreadId)
  17399. EnterMoviesOnThread (0);
  17400. AttachMovieToCurrentThread (movie);
  17401. #endif
  17402. }
  17403. void detachThread()
  17404. {
  17405. #if JUCE_MAC
  17406. DetachMovieFromCurrentThread (movie);
  17407. #endif
  17408. }
  17409. };
  17410. QuickTimeAudioFormat::QuickTimeAudioFormat()
  17411. : AudioFormat (TRANS (quickTimeFormatName), (const tchar**) quickTimeExtensions)
  17412. {
  17413. }
  17414. QuickTimeAudioFormat::~QuickTimeAudioFormat()
  17415. {
  17416. }
  17417. const Array <int> QuickTimeAudioFormat::getPossibleSampleRates()
  17418. {
  17419. return Array<int>();
  17420. }
  17421. const Array <int> QuickTimeAudioFormat::getPossibleBitDepths()
  17422. {
  17423. return Array<int>();
  17424. }
  17425. bool QuickTimeAudioFormat::canDoStereo()
  17426. {
  17427. return true;
  17428. }
  17429. bool QuickTimeAudioFormat::canDoMono()
  17430. {
  17431. return true;
  17432. }
  17433. AudioFormatReader* QuickTimeAudioFormat::createReaderFor (InputStream* sourceStream,
  17434. const bool deleteStreamIfOpeningFails)
  17435. {
  17436. ScopedPointer <QTAudioReader> r (new QTAudioReader (sourceStream, 0));
  17437. if (r->ok)
  17438. return r.release();
  17439. if (! deleteStreamIfOpeningFails)
  17440. r->input = 0;
  17441. return 0;
  17442. }
  17443. AudioFormatWriter* QuickTimeAudioFormat::createWriterFor (OutputStream* /*streamToWriteTo*/,
  17444. double /*sampleRateToUse*/,
  17445. unsigned int /*numberOfChannels*/,
  17446. int /*bitsPerSample*/,
  17447. const StringPairArray& /*metadataValues*/,
  17448. int /*qualityOptionIndex*/)
  17449. {
  17450. jassertfalse // not yet implemented!
  17451. return 0;
  17452. }
  17453. END_JUCE_NAMESPACE
  17454. #endif
  17455. /*** End of inlined file: juce_QuickTimeAudioFormat.cpp ***/
  17456. /*** Start of inlined file: juce_WavAudioFormat.cpp ***/
  17457. BEGIN_JUCE_NAMESPACE
  17458. static const char* const wavFormatName = "WAV file";
  17459. static const tchar* const wavExtensions[] = { T(".wav"), T(".bwf"), 0 };
  17460. const tchar* const WavAudioFormat::bwavDescription = T("bwav description");
  17461. const tchar* const WavAudioFormat::bwavOriginator = T("bwav originator");
  17462. const tchar* const WavAudioFormat::bwavOriginatorRef = T("bwav originator ref");
  17463. const tchar* const WavAudioFormat::bwavOriginationDate = T("bwav origination date");
  17464. const tchar* const WavAudioFormat::bwavOriginationTime = T("bwav origination time");
  17465. const tchar* const WavAudioFormat::bwavTimeReference = T("bwav time reference");
  17466. const tchar* const WavAudioFormat::bwavCodingHistory = T("bwav coding history");
  17467. const StringPairArray WavAudioFormat::createBWAVMetadata (const String& description,
  17468. const String& originator,
  17469. const String& originatorRef,
  17470. const Time& date,
  17471. const int64 timeReferenceSamples,
  17472. const String& codingHistory)
  17473. {
  17474. StringPairArray m;
  17475. m.set (bwavDescription, description);
  17476. m.set (bwavOriginator, originator);
  17477. m.set (bwavOriginatorRef, originatorRef);
  17478. m.set (bwavOriginationDate, date.formatted (T("%Y-%m-%d")));
  17479. m.set (bwavOriginationTime, date.formatted (T("%H:%M:%S")));
  17480. m.set (bwavTimeReference, String (timeReferenceSamples));
  17481. m.set (bwavCodingHistory, codingHistory);
  17482. return m;
  17483. }
  17484. #if JUCE_MSVC
  17485. #pragma pack (push, 1)
  17486. #define PACKED
  17487. #elif JUCE_GCC
  17488. #define PACKED __attribute__((packed))
  17489. #else
  17490. #define PACKED
  17491. #endif
  17492. struct BWAVChunk
  17493. {
  17494. uint8 description [256];
  17495. uint8 originator [32];
  17496. uint8 originatorRef [32];
  17497. uint8 originationDate [10];
  17498. uint8 originationTime [8];
  17499. uint32 timeRefLow;
  17500. uint32 timeRefHigh;
  17501. uint16 version;
  17502. uint8 umid[64];
  17503. uint8 reserved[190];
  17504. uint8 codingHistory[1];
  17505. void copyTo (StringPairArray& values) const
  17506. {
  17507. values.set (WavAudioFormat::bwavDescription, String::fromUTF8 (description, 256));
  17508. values.set (WavAudioFormat::bwavOriginator, String::fromUTF8 (originator, 32));
  17509. values.set (WavAudioFormat::bwavOriginatorRef, String::fromUTF8 (originatorRef, 32));
  17510. values.set (WavAudioFormat::bwavOriginationDate, String::fromUTF8 (originationDate, 10));
  17511. values.set (WavAudioFormat::bwavOriginationTime, String::fromUTF8 (originationTime, 8));
  17512. const uint32 timeLow = ByteOrder::swapIfBigEndian (timeRefLow);
  17513. const uint32 timeHigh = ByteOrder::swapIfBigEndian (timeRefHigh);
  17514. const int64 time = (((int64)timeHigh) << 32) + timeLow;
  17515. values.set (WavAudioFormat::bwavTimeReference, String (time));
  17516. values.set (WavAudioFormat::bwavCodingHistory, String::fromUTF8 (codingHistory));
  17517. }
  17518. static MemoryBlock createFrom (const StringPairArray& values)
  17519. {
  17520. const size_t sizeNeeded = sizeof (BWAVChunk) + values [WavAudioFormat::bwavCodingHistory].copyToUTF8 (0) - 1;
  17521. MemoryBlock data ((sizeNeeded + 3) & ~3);
  17522. data.fillWith (0);
  17523. BWAVChunk* b = (BWAVChunk*) data.getData();
  17524. // Allow these calls to overwrite an extra byte at the end, which is fine as long
  17525. // as they get called in the right order..
  17526. values [WavAudioFormat::bwavDescription].copyToUTF8 (b->description, 257);
  17527. values [WavAudioFormat::bwavOriginator].copyToUTF8 (b->originator, 33);
  17528. values [WavAudioFormat::bwavOriginatorRef].copyToUTF8 (b->originatorRef, 33);
  17529. values [WavAudioFormat::bwavOriginationDate].copyToUTF8 (b->originationDate, 11);
  17530. values [WavAudioFormat::bwavOriginationTime].copyToUTF8 (b->originationTime, 9);
  17531. const int64 time = values [WavAudioFormat::bwavTimeReference].getLargeIntValue();
  17532. b->timeRefLow = ByteOrder::swapIfBigEndian ((uint32) (time & 0xffffffff));
  17533. b->timeRefHigh = ByteOrder::swapIfBigEndian ((uint32) (time >> 32));
  17534. values [WavAudioFormat::bwavCodingHistory].copyToUTF8 (b->codingHistory);
  17535. if (b->description[0] != 0
  17536. || b->originator[0] != 0
  17537. || b->originationDate[0] != 0
  17538. || b->originationTime[0] != 0
  17539. || b->codingHistory[0] != 0
  17540. || time != 0)
  17541. {
  17542. return data;
  17543. }
  17544. return MemoryBlock();
  17545. }
  17546. } PACKED;
  17547. struct SMPLChunk
  17548. {
  17549. struct SampleLoop
  17550. {
  17551. uint32 identifier;
  17552. uint32 type;
  17553. uint32 start;
  17554. uint32 end;
  17555. uint32 fraction;
  17556. uint32 playCount;
  17557. } PACKED;
  17558. uint32 manufacturer;
  17559. uint32 product;
  17560. uint32 samplePeriod;
  17561. uint32 midiUnityNote;
  17562. uint32 midiPitchFraction;
  17563. uint32 smpteFormat;
  17564. uint32 smpteOffset;
  17565. uint32 numSampleLoops;
  17566. uint32 samplerData;
  17567. SampleLoop loops[1];
  17568. void copyTo (StringPairArray& values, const int totalSize) const
  17569. {
  17570. values.set ("Manufacturer", String (ByteOrder::swapIfBigEndian (manufacturer)));
  17571. values.set ("Product", String (ByteOrder::swapIfBigEndian (product)));
  17572. values.set ("SamplePeriod", String (ByteOrder::swapIfBigEndian (samplePeriod)));
  17573. values.set ("MidiUnityNote", String (ByteOrder::swapIfBigEndian (midiUnityNote)));
  17574. values.set ("MidiPitchFraction", String (ByteOrder::swapIfBigEndian (midiPitchFraction)));
  17575. values.set ("SmpteFormat", String (ByteOrder::swapIfBigEndian (smpteFormat)));
  17576. values.set ("SmpteOffset", String (ByteOrder::swapIfBigEndian (smpteOffset)));
  17577. values.set ("NumSampleLoops", String (ByteOrder::swapIfBigEndian (numSampleLoops)));
  17578. values.set ("SamplerData", String (ByteOrder::swapIfBigEndian (samplerData)));
  17579. for (uint32 i = 0; i < numSampleLoops; ++i)
  17580. {
  17581. if ((uint8*) (loops + (i + 1)) > ((uint8*) this) + totalSize)
  17582. break;
  17583. const String prefix ("Loop" + String(i));
  17584. values.set (prefix + "Identifier", String (ByteOrder::swapIfBigEndian (loops[i].identifier)));
  17585. values.set (prefix + "Type", String (ByteOrder::swapIfBigEndian (loops[i].type)));
  17586. values.set (prefix + "Start", String (ByteOrder::swapIfBigEndian (loops[i].start)));
  17587. values.set (prefix + "End", String (ByteOrder::swapIfBigEndian (loops[i].end)));
  17588. values.set (prefix + "Fraction", String (ByteOrder::swapIfBigEndian (loops[i].fraction)));
  17589. values.set (prefix + "PlayCount", String (ByteOrder::swapIfBigEndian (loops[i].playCount)));
  17590. }
  17591. }
  17592. static MemoryBlock createFrom (const StringPairArray& values)
  17593. {
  17594. const int numLoops = jmin (64, values.getValue ("NumSampleLoops", "0").getIntValue());
  17595. if (numLoops <= 0)
  17596. return MemoryBlock();
  17597. const size_t sizeNeeded = sizeof (SMPLChunk) + (numLoops - 1) * sizeof (SampleLoop);
  17598. MemoryBlock data ((sizeNeeded + 3) & ~3);
  17599. data.fillWith (0);
  17600. SMPLChunk* s = (SMPLChunk*) data.getData();
  17601. // Allow these calls to overwrite an extra byte at the end, which is fine as long
  17602. // as they get called in the right order..
  17603. s->manufacturer = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("Manufacturer", "0").getIntValue());
  17604. s->product = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("Product", "0").getIntValue());
  17605. s->samplePeriod = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("SamplePeriod", "0").getIntValue());
  17606. s->midiUnityNote = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("MidiUnityNote", "60").getIntValue());
  17607. s->midiPitchFraction = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("MidiPitchFraction", "0").getIntValue());
  17608. s->smpteFormat = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("SmpteFormat", "0").getIntValue());
  17609. s->smpteOffset = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("SmpteOffset", "0").getIntValue());
  17610. s->numSampleLoops = ByteOrder::swapIfBigEndian ((uint32) numLoops);
  17611. s->samplerData = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("SamplerData", "0").getIntValue());
  17612. for (int i = 0; i < numLoops; ++i)
  17613. {
  17614. const String prefix ("Loop" + String(i));
  17615. s->loops[i].identifier = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "Identifier", "0").getIntValue());
  17616. s->loops[i].type = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "Type", "0").getIntValue());
  17617. s->loops[i].start = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "Start", "0").getIntValue());
  17618. s->loops[i].end = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "End", "0").getIntValue());
  17619. s->loops[i].fraction = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "Fraction", "0").getIntValue());
  17620. s->loops[i].playCount = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "PlayCount", "0").getIntValue());
  17621. }
  17622. return data;
  17623. }
  17624. } PACKED;
  17625. #if JUCE_MSVC
  17626. #pragma pack (pop)
  17627. #endif
  17628. #undef PACKED
  17629. class WavAudioFormatReader : public AudioFormatReader
  17630. {
  17631. int bytesPerFrame;
  17632. int64 dataChunkStart, dataLength;
  17633. static inline int chunkName (const char* const name) { return (int) ByteOrder::littleEndianInt (name); }
  17634. WavAudioFormatReader (const WavAudioFormatReader&);
  17635. const WavAudioFormatReader& operator= (const WavAudioFormatReader&);
  17636. public:
  17637. int64 bwavChunkStart, bwavSize;
  17638. WavAudioFormatReader (InputStream* const in)
  17639. : AudioFormatReader (in, TRANS (wavFormatName)),
  17640. dataLength (0),
  17641. bwavChunkStart (0),
  17642. bwavSize (0)
  17643. {
  17644. if (input->readInt() == chunkName ("RIFF"))
  17645. {
  17646. const uint32 len = (uint32) input->readInt();
  17647. const int64 end = input->getPosition() + len;
  17648. bool hasGotType = false;
  17649. bool hasGotData = false;
  17650. if (input->readInt() == chunkName ("WAVE"))
  17651. {
  17652. while (input->getPosition() < end
  17653. && ! input->isExhausted())
  17654. {
  17655. const int chunkType = input->readInt();
  17656. uint32 length = (uint32) input->readInt();
  17657. const int64 chunkEnd = input->getPosition() + length + (length & 1);
  17658. if (chunkType == chunkName ("fmt "))
  17659. {
  17660. // read the format chunk
  17661. const short format = input->readShort();
  17662. const short numChans = input->readShort();
  17663. sampleRate = input->readInt();
  17664. const int bytesPerSec = input->readInt();
  17665. numChannels = numChans;
  17666. bytesPerFrame = bytesPerSec / (int)sampleRate;
  17667. bitsPerSample = 8 * bytesPerFrame / numChans;
  17668. if (format == 3)
  17669. usesFloatingPointData = true;
  17670. else if (format != 1)
  17671. bytesPerFrame = 0;
  17672. hasGotType = true;
  17673. }
  17674. else if (chunkType == chunkName ("data"))
  17675. {
  17676. // get the data chunk's position
  17677. dataLength = length;
  17678. dataChunkStart = input->getPosition();
  17679. lengthInSamples = (bytesPerFrame > 0) ? (dataLength / bytesPerFrame) : 0;
  17680. hasGotData = true;
  17681. }
  17682. else if (chunkType == chunkName ("bext"))
  17683. {
  17684. bwavChunkStart = input->getPosition();
  17685. bwavSize = length;
  17686. // Broadcast-wav extension chunk..
  17687. HeapBlock <BWAVChunk> bwav;
  17688. bwav.calloc (jmax ((size_t) length + 1, sizeof (BWAVChunk)), 1);
  17689. input->read (bwav, length);
  17690. bwav->copyTo (metadataValues);
  17691. }
  17692. else if (chunkType == chunkName ("smpl"))
  17693. {
  17694. HeapBlock <SMPLChunk> smpl;
  17695. smpl.calloc (jmax ((size_t) length + 1, sizeof (SMPLChunk)), 1);
  17696. input->read (smpl, length);
  17697. smpl->copyTo (metadataValues, length);
  17698. }
  17699. else if (chunkEnd <= input->getPosition())
  17700. {
  17701. break;
  17702. }
  17703. input->setPosition (chunkEnd);
  17704. }
  17705. }
  17706. }
  17707. }
  17708. ~WavAudioFormatReader()
  17709. {
  17710. }
  17711. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  17712. int64 startSampleInFile, int numSamples)
  17713. {
  17714. const int64 samplesAvailable = lengthInSamples - startSampleInFile;
  17715. if (samplesAvailable < numSamples)
  17716. {
  17717. for (int i = numDestChannels; --i >= 0;)
  17718. if (destSamples[i] != 0)
  17719. zeromem (destSamples[i] + startOffsetInDestBuffer, sizeof (int) * numSamples);
  17720. numSamples = (int) samplesAvailable;
  17721. }
  17722. if (numSamples <= 0)
  17723. return true;
  17724. input->setPosition (dataChunkStart + startSampleInFile * bytesPerFrame);
  17725. const int tempBufSize = 480 * 3 * 4; // (keep this a multiple of 3)
  17726. char tempBuffer [tempBufSize];
  17727. while (numSamples > 0)
  17728. {
  17729. int* left = destSamples[0];
  17730. if (left != 0)
  17731. left += startOffsetInDestBuffer;
  17732. int* right = numDestChannels > 1 ? destSamples[1] : 0;
  17733. if (right != 0)
  17734. right += startOffsetInDestBuffer;
  17735. const int numThisTime = jmin (tempBufSize / bytesPerFrame, numSamples);
  17736. const int bytesRead = input->read (tempBuffer, numThisTime * bytesPerFrame);
  17737. if (bytesRead < numThisTime * bytesPerFrame)
  17738. zeromem (tempBuffer + bytesRead, numThisTime * bytesPerFrame - bytesRead);
  17739. if (bitsPerSample == 16)
  17740. {
  17741. const short* src = (const short*) tempBuffer;
  17742. if (numChannels > 1)
  17743. {
  17744. if (left == 0)
  17745. {
  17746. for (int i = numThisTime; --i >= 0;)
  17747. {
  17748. ++src;
  17749. *right++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17750. }
  17751. }
  17752. else if (right == 0)
  17753. {
  17754. for (int i = numThisTime; --i >= 0;)
  17755. {
  17756. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17757. ++src;
  17758. }
  17759. }
  17760. else
  17761. {
  17762. for (int i = numThisTime; --i >= 0;)
  17763. {
  17764. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17765. *right++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17766. }
  17767. }
  17768. }
  17769. else
  17770. {
  17771. for (int i = numThisTime; --i >= 0;)
  17772. {
  17773. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17774. }
  17775. }
  17776. }
  17777. else if (bitsPerSample == 24)
  17778. {
  17779. const char* src = (const char*) tempBuffer;
  17780. if (numChannels > 1)
  17781. {
  17782. if (left == 0)
  17783. {
  17784. for (int i = numThisTime; --i >= 0;)
  17785. {
  17786. src += 3;
  17787. *right++ = ByteOrder::littleEndian24Bit (src) << 8;
  17788. src += 3;
  17789. }
  17790. }
  17791. else if (right == 0)
  17792. {
  17793. for (int i = numThisTime; --i >= 0;)
  17794. {
  17795. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  17796. src += 6;
  17797. }
  17798. }
  17799. else
  17800. {
  17801. for (int i = 0; i < numThisTime; ++i)
  17802. {
  17803. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  17804. src += 3;
  17805. *right++ = ByteOrder::littleEndian24Bit (src) << 8;
  17806. src += 3;
  17807. }
  17808. }
  17809. }
  17810. else
  17811. {
  17812. for (int i = 0; i < numThisTime; ++i)
  17813. {
  17814. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  17815. src += 3;
  17816. }
  17817. }
  17818. }
  17819. else if (bitsPerSample == 32)
  17820. {
  17821. const unsigned int* src = (const unsigned int*) tempBuffer;
  17822. unsigned int* l = (unsigned int*) left;
  17823. unsigned int* r = (unsigned int*) right;
  17824. if (numChannels > 1)
  17825. {
  17826. if (l == 0)
  17827. {
  17828. for (int i = numThisTime; --i >= 0;)
  17829. {
  17830. ++src;
  17831. *r++ = ByteOrder::swapIfBigEndian (*src++);
  17832. }
  17833. }
  17834. else if (r == 0)
  17835. {
  17836. for (int i = numThisTime; --i >= 0;)
  17837. {
  17838. *l++ = ByteOrder::swapIfBigEndian (*src++);
  17839. ++src;
  17840. }
  17841. }
  17842. else
  17843. {
  17844. for (int i = numThisTime; --i >= 0;)
  17845. {
  17846. *l++ = ByteOrder::swapIfBigEndian (*src++);
  17847. *r++ = ByteOrder::swapIfBigEndian (*src++);
  17848. }
  17849. }
  17850. }
  17851. else
  17852. {
  17853. for (int i = numThisTime; --i >= 0;)
  17854. {
  17855. *l++ = ByteOrder::swapIfBigEndian (*src++);
  17856. }
  17857. }
  17858. left = (int*)l;
  17859. right = (int*)r;
  17860. }
  17861. else if (bitsPerSample == 8)
  17862. {
  17863. const unsigned char* src = (const unsigned char*) tempBuffer;
  17864. if (numChannels > 1)
  17865. {
  17866. if (left == 0)
  17867. {
  17868. for (int i = numThisTime; --i >= 0;)
  17869. {
  17870. ++src;
  17871. *right++ = ((int) *src++ - 128) << 24;
  17872. }
  17873. }
  17874. else if (right == 0)
  17875. {
  17876. for (int i = numThisTime; --i >= 0;)
  17877. {
  17878. *left++ = ((int) *src++ - 128) << 24;
  17879. ++src;
  17880. }
  17881. }
  17882. else
  17883. {
  17884. for (int i = numThisTime; --i >= 0;)
  17885. {
  17886. *left++ = ((int) *src++ - 128) << 24;
  17887. *right++ = ((int) *src++ - 128) << 24;
  17888. }
  17889. }
  17890. }
  17891. else
  17892. {
  17893. for (int i = numThisTime; --i >= 0;)
  17894. {
  17895. *left++ = ((int)*src++ - 128) << 24;
  17896. }
  17897. }
  17898. }
  17899. startOffsetInDestBuffer += numThisTime;
  17900. numSamples -= numThisTime;
  17901. }
  17902. if (numSamples > 0)
  17903. {
  17904. for (int i = numDestChannels; --i >= 0;)
  17905. if (destSamples[i] != 0)
  17906. zeromem (destSamples[i] + startOffsetInDestBuffer,
  17907. sizeof (int) * numSamples);
  17908. }
  17909. return true;
  17910. }
  17911. juce_UseDebuggingNewOperator
  17912. };
  17913. class WavAudioFormatWriter : public AudioFormatWriter
  17914. {
  17915. MemoryBlock tempBlock, bwavChunk, smplChunk;
  17916. uint32 lengthInSamples, bytesWritten;
  17917. int64 headerPosition;
  17918. bool writeFailed;
  17919. static inline int chunkName (const char* const name) { return (int) ByteOrder::littleEndianInt (name); }
  17920. WavAudioFormatWriter (const WavAudioFormatWriter&);
  17921. const WavAudioFormatWriter& operator= (const WavAudioFormatWriter&);
  17922. void writeHeader()
  17923. {
  17924. const bool seekedOk = output->setPosition (headerPosition);
  17925. (void) seekedOk;
  17926. // if this fails, you've given it an output stream that can't seek! It needs
  17927. // to be able to seek back to write the header
  17928. jassert (seekedOk);
  17929. const int bytesPerFrame = numChannels * bitsPerSample / 8;
  17930. output->writeInt (chunkName ("RIFF"));
  17931. output->writeInt ((int) (lengthInSamples * bytesPerFrame
  17932. + ((bwavChunk.getSize() > 0) ? (44 + bwavChunk.getSize()) : 36)));
  17933. output->writeInt (chunkName ("WAVE"));
  17934. output->writeInt (chunkName ("fmt "));
  17935. output->writeInt (16);
  17936. output->writeShort ((bitsPerSample < 32) ? (short) 1 /*WAVE_FORMAT_PCM*/
  17937. : (short) 3 /*WAVE_FORMAT_IEEE_FLOAT*/);
  17938. output->writeShort ((short) numChannels);
  17939. output->writeInt ((int) sampleRate);
  17940. output->writeInt (bytesPerFrame * (int) sampleRate);
  17941. output->writeShort ((short) bytesPerFrame);
  17942. output->writeShort ((short) bitsPerSample);
  17943. if (bwavChunk.getSize() > 0)
  17944. {
  17945. output->writeInt (chunkName ("bext"));
  17946. output->writeInt ((int) bwavChunk.getSize());
  17947. output->write (bwavChunk.getData(), (int) bwavChunk.getSize());
  17948. }
  17949. if (smplChunk.getSize() > 0)
  17950. {
  17951. output->writeInt (chunkName ("smpl"));
  17952. output->writeInt (smplChunk.getSize());
  17953. output->write (smplChunk.getData(), (int) smplChunk.getSize());
  17954. }
  17955. output->writeInt (chunkName ("data"));
  17956. output->writeInt (lengthInSamples * bytesPerFrame);
  17957. usesFloatingPointData = (bitsPerSample == 32);
  17958. }
  17959. public:
  17960. WavAudioFormatWriter (OutputStream* const out,
  17961. const double sampleRate_,
  17962. const unsigned int numChannels_,
  17963. const int bits,
  17964. const StringPairArray& metadataValues)
  17965. : AudioFormatWriter (out,
  17966. TRANS (wavFormatName),
  17967. sampleRate_,
  17968. numChannels_,
  17969. bits),
  17970. lengthInSamples (0),
  17971. bytesWritten (0),
  17972. writeFailed (false)
  17973. {
  17974. if (metadataValues.size() > 0)
  17975. {
  17976. bwavChunk = BWAVChunk::createFrom (metadataValues);
  17977. smplChunk = SMPLChunk::createFrom (metadataValues);
  17978. }
  17979. headerPosition = out->getPosition();
  17980. writeHeader();
  17981. }
  17982. ~WavAudioFormatWriter()
  17983. {
  17984. writeHeader();
  17985. }
  17986. bool write (const int** data, int numSamples)
  17987. {
  17988. if (writeFailed)
  17989. return false;
  17990. const int bytes = numChannels * numSamples * bitsPerSample / 8;
  17991. tempBlock.ensureSize (bytes, false);
  17992. char* buffer = (char*) tempBlock.getData();
  17993. const int* left = data[0];
  17994. const int* right = data[1];
  17995. if (right == 0)
  17996. right = left;
  17997. if (bitsPerSample == 16)
  17998. {
  17999. short* b = (short*) buffer;
  18000. if (numChannels > 1)
  18001. {
  18002. for (int i = numSamples; --i >= 0;)
  18003. {
  18004. *b++ = (short) ByteOrder::swapIfBigEndian ((unsigned short) (*left++ >> 16));
  18005. *b++ = (short) ByteOrder::swapIfBigEndian ((unsigned short) (*right++ >> 16));
  18006. }
  18007. }
  18008. else
  18009. {
  18010. for (int i = numSamples; --i >= 0;)
  18011. {
  18012. *b++ = (short) ByteOrder::swapIfBigEndian ((unsigned short) (*left++ >> 16));
  18013. }
  18014. }
  18015. }
  18016. else if (bitsPerSample == 24)
  18017. {
  18018. char* b = (char*) buffer;
  18019. if (numChannels > 1)
  18020. {
  18021. for (int i = numSamples; --i >= 0;)
  18022. {
  18023. ByteOrder::littleEndian24BitToChars ((*left++) >> 8, b);
  18024. b += 3;
  18025. ByteOrder::littleEndian24BitToChars ((*right++) >> 8, b);
  18026. b += 3;
  18027. }
  18028. }
  18029. else
  18030. {
  18031. for (int i = numSamples; --i >= 0;)
  18032. {
  18033. ByteOrder::littleEndian24BitToChars ((*left++) >> 8, b);
  18034. b += 3;
  18035. }
  18036. }
  18037. }
  18038. else if (bitsPerSample == 32)
  18039. {
  18040. unsigned int* b = (unsigned int*) buffer;
  18041. if (numChannels > 1)
  18042. {
  18043. for (int i = numSamples; --i >= 0;)
  18044. {
  18045. *b++ = ByteOrder::swapIfBigEndian ((unsigned int) *left++);
  18046. *b++ = ByteOrder::swapIfBigEndian ((unsigned int) *right++);
  18047. }
  18048. }
  18049. else
  18050. {
  18051. for (int i = numSamples; --i >= 0;)
  18052. {
  18053. *b++ = ByteOrder::swapIfBigEndian ((unsigned int) *left++);
  18054. }
  18055. }
  18056. }
  18057. else if (bitsPerSample == 8)
  18058. {
  18059. unsigned char* b = (unsigned char*) buffer;
  18060. if (numChannels > 1)
  18061. {
  18062. for (int i = numSamples; --i >= 0;)
  18063. {
  18064. *b++ = (unsigned char) (128 + (*left++ >> 24));
  18065. *b++ = (unsigned char) (128 + (*right++ >> 24));
  18066. }
  18067. }
  18068. else
  18069. {
  18070. for (int i = numSamples; --i >= 0;)
  18071. {
  18072. *b++ = (unsigned char) (128 + (*left++ >> 24));
  18073. }
  18074. }
  18075. }
  18076. if (bytesWritten + bytes >= (uint32) 0xfff00000
  18077. || ! output->write (buffer, bytes))
  18078. {
  18079. // failed to write to disk, so let's try writing the header.
  18080. // If it's just run out of disk space, then if it does manage
  18081. // to write the header, we'll still have a useable file..
  18082. writeHeader();
  18083. writeFailed = true;
  18084. return false;
  18085. }
  18086. else
  18087. {
  18088. bytesWritten += bytes;
  18089. lengthInSamples += numSamples;
  18090. return true;
  18091. }
  18092. }
  18093. juce_UseDebuggingNewOperator
  18094. };
  18095. WavAudioFormat::WavAudioFormat()
  18096. : AudioFormat (TRANS (wavFormatName), (const tchar**) wavExtensions)
  18097. {
  18098. }
  18099. WavAudioFormat::~WavAudioFormat()
  18100. {
  18101. }
  18102. const Array <int> WavAudioFormat::getPossibleSampleRates()
  18103. {
  18104. const int rates[] = { 22050, 32000, 44100, 48000, 88200, 96000, 176400, 192000, 0 };
  18105. return Array <int> (rates);
  18106. }
  18107. const Array <int> WavAudioFormat::getPossibleBitDepths()
  18108. {
  18109. const int depths[] = { 8, 16, 24, 32, 0 };
  18110. return Array <int> (depths);
  18111. }
  18112. bool WavAudioFormat::canDoStereo()
  18113. {
  18114. return true;
  18115. }
  18116. bool WavAudioFormat::canDoMono()
  18117. {
  18118. return true;
  18119. }
  18120. AudioFormatReader* WavAudioFormat::createReaderFor (InputStream* sourceStream,
  18121. const bool deleteStreamIfOpeningFails)
  18122. {
  18123. ScopedPointer <WavAudioFormatReader> r (new WavAudioFormatReader (sourceStream));
  18124. if (r->sampleRate != 0)
  18125. return r.release();
  18126. if (! deleteStreamIfOpeningFails)
  18127. r->input = 0;
  18128. return 0;
  18129. }
  18130. AudioFormatWriter* WavAudioFormat::createWriterFor (OutputStream* out,
  18131. double sampleRate,
  18132. unsigned int numChannels,
  18133. int bitsPerSample,
  18134. const StringPairArray& metadataValues,
  18135. int /*qualityOptionIndex*/)
  18136. {
  18137. if (getPossibleBitDepths().contains (bitsPerSample))
  18138. {
  18139. return new WavAudioFormatWriter (out,
  18140. sampleRate,
  18141. numChannels,
  18142. bitsPerSample,
  18143. metadataValues);
  18144. }
  18145. return 0;
  18146. }
  18147. static bool juce_slowCopyOfWavFileWithNewMetadata (const File& file, const StringPairArray& metadata)
  18148. {
  18149. TemporaryFile tempFile (file);
  18150. WavAudioFormat wav;
  18151. ScopedPointer <AudioFormatReader> reader (wav.createReaderFor (file.createInputStream(), true));
  18152. if (reader != 0)
  18153. {
  18154. ScopedPointer <OutputStream> outStream (tempFile.getFile().createOutputStream());
  18155. if (outStream != 0)
  18156. {
  18157. ScopedPointer <AudioFormatWriter> writer (wav.createWriterFor (outStream, reader->sampleRate,
  18158. reader->numChannels, reader->bitsPerSample,
  18159. metadata, 0));
  18160. if (writer != 0)
  18161. {
  18162. outStream.release();
  18163. bool ok = writer->writeFromAudioReader (*reader, 0, -1);
  18164. writer = 0;
  18165. reader = 0;
  18166. return ok && tempFile.overwriteTargetFileWithTemporary();
  18167. }
  18168. }
  18169. }
  18170. return false;
  18171. }
  18172. bool WavAudioFormat::replaceMetadataInFile (const File& wavFile, const StringPairArray& newMetadata)
  18173. {
  18174. ScopedPointer <WavAudioFormatReader> reader ((WavAudioFormatReader*) createReaderFor (wavFile.createInputStream(), true));
  18175. if (reader != 0)
  18176. {
  18177. const int64 bwavPos = reader->bwavChunkStart;
  18178. const int64 bwavSize = reader->bwavSize;
  18179. reader = 0;
  18180. if (bwavSize > 0)
  18181. {
  18182. MemoryBlock chunk = BWAVChunk::createFrom (newMetadata);
  18183. if (chunk.getSize() <= (size_t) bwavSize)
  18184. {
  18185. // the new one will fit in the space available, so write it directly..
  18186. const int64 oldSize = wavFile.getSize();
  18187. {
  18188. ScopedPointer <FileOutputStream> out (wavFile.createOutputStream());
  18189. out->setPosition (bwavPos);
  18190. out->write (chunk.getData(), (int) chunk.getSize());
  18191. out->setPosition (oldSize);
  18192. }
  18193. jassert (wavFile.getSize() == oldSize);
  18194. return true;
  18195. }
  18196. }
  18197. }
  18198. return juce_slowCopyOfWavFileWithNewMetadata (wavFile, newMetadata);
  18199. }
  18200. END_JUCE_NAMESPACE
  18201. /*** End of inlined file: juce_WavAudioFormat.cpp ***/
  18202. /*** Start of inlined file: juce_AudioFormatReaderSource.cpp ***/
  18203. BEGIN_JUCE_NAMESPACE
  18204. AudioFormatReaderSource::AudioFormatReaderSource (AudioFormatReader* const reader_,
  18205. const bool deleteReaderWhenThisIsDeleted)
  18206. : reader (reader_),
  18207. deleteReader (deleteReaderWhenThisIsDeleted),
  18208. nextPlayPos (0),
  18209. looping (false)
  18210. {
  18211. jassert (reader != 0);
  18212. }
  18213. AudioFormatReaderSource::~AudioFormatReaderSource()
  18214. {
  18215. releaseResources();
  18216. if (deleteReader)
  18217. delete reader;
  18218. }
  18219. void AudioFormatReaderSource::setNextReadPosition (int newPosition)
  18220. {
  18221. nextPlayPos = newPosition;
  18222. }
  18223. void AudioFormatReaderSource::setLooping (const bool shouldLoop) throw()
  18224. {
  18225. looping = shouldLoop;
  18226. }
  18227. int AudioFormatReaderSource::getNextReadPosition() const
  18228. {
  18229. return (looping) ? (nextPlayPos % (int) reader->lengthInSamples)
  18230. : nextPlayPos;
  18231. }
  18232. int AudioFormatReaderSource::getTotalLength() const
  18233. {
  18234. return (int) reader->lengthInSamples;
  18235. }
  18236. void AudioFormatReaderSource::prepareToPlay (int /*samplesPerBlockExpected*/,
  18237. double /*sampleRate*/)
  18238. {
  18239. }
  18240. void AudioFormatReaderSource::releaseResources()
  18241. {
  18242. }
  18243. void AudioFormatReaderSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  18244. {
  18245. if (info.numSamples > 0)
  18246. {
  18247. const int start = nextPlayPos;
  18248. if (looping)
  18249. {
  18250. const int newStart = start % (int) reader->lengthInSamples;
  18251. const int newEnd = (start + info.numSamples) % (int) reader->lengthInSamples;
  18252. if (newEnd > newStart)
  18253. {
  18254. info.buffer->readFromAudioReader (reader,
  18255. info.startSample,
  18256. newEnd - newStart,
  18257. newStart,
  18258. true, true);
  18259. }
  18260. else
  18261. {
  18262. const int endSamps = (int) reader->lengthInSamples - newStart;
  18263. info.buffer->readFromAudioReader (reader,
  18264. info.startSample,
  18265. endSamps,
  18266. newStart,
  18267. true, true);
  18268. info.buffer->readFromAudioReader (reader,
  18269. info.startSample + endSamps,
  18270. newEnd,
  18271. 0,
  18272. true, true);
  18273. }
  18274. nextPlayPos = newEnd;
  18275. }
  18276. else
  18277. {
  18278. info.buffer->readFromAudioReader (reader,
  18279. info.startSample,
  18280. info.numSamples,
  18281. start,
  18282. true, true);
  18283. nextPlayPos += info.numSamples;
  18284. }
  18285. }
  18286. }
  18287. END_JUCE_NAMESPACE
  18288. /*** End of inlined file: juce_AudioFormatReaderSource.cpp ***/
  18289. /*** Start of inlined file: juce_AudioSourcePlayer.cpp ***/
  18290. BEGIN_JUCE_NAMESPACE
  18291. AudioSourcePlayer::AudioSourcePlayer()
  18292. : source (0),
  18293. sampleRate (0),
  18294. bufferSize (0),
  18295. tempBuffer (2, 8),
  18296. lastGain (1.0f),
  18297. gain (1.0f)
  18298. {
  18299. }
  18300. AudioSourcePlayer::~AudioSourcePlayer()
  18301. {
  18302. setSource (0);
  18303. }
  18304. void AudioSourcePlayer::setSource (AudioSource* newSource)
  18305. {
  18306. if (source != newSource)
  18307. {
  18308. AudioSource* const oldSource = source;
  18309. if (newSource != 0 && bufferSize > 0 && sampleRate > 0)
  18310. newSource->prepareToPlay (bufferSize, sampleRate);
  18311. {
  18312. const ScopedLock sl (readLock);
  18313. source = newSource;
  18314. }
  18315. if (oldSource != 0)
  18316. oldSource->releaseResources();
  18317. }
  18318. }
  18319. void AudioSourcePlayer::setGain (const float newGain) throw()
  18320. {
  18321. gain = newGain;
  18322. }
  18323. void AudioSourcePlayer::audioDeviceIOCallback (const float** inputChannelData,
  18324. int totalNumInputChannels,
  18325. float** outputChannelData,
  18326. int totalNumOutputChannels,
  18327. int numSamples)
  18328. {
  18329. // these should have been prepared by audioDeviceAboutToStart()...
  18330. jassert (sampleRate > 0 && bufferSize > 0);
  18331. const ScopedLock sl (readLock);
  18332. if (source != 0)
  18333. {
  18334. AudioSourceChannelInfo info;
  18335. int i, numActiveChans = 0, numInputs = 0, numOutputs = 0;
  18336. // messy stuff needed to compact the channels down into an array
  18337. // of non-zero pointers..
  18338. for (i = 0; i < totalNumInputChannels; ++i)
  18339. {
  18340. if (inputChannelData[i] != 0)
  18341. {
  18342. inputChans [numInputs++] = inputChannelData[i];
  18343. if (numInputs >= numElementsInArray (inputChans))
  18344. break;
  18345. }
  18346. }
  18347. for (i = 0; i < totalNumOutputChannels; ++i)
  18348. {
  18349. if (outputChannelData[i] != 0)
  18350. {
  18351. outputChans [numOutputs++] = outputChannelData[i];
  18352. if (numOutputs >= numElementsInArray (outputChans))
  18353. break;
  18354. }
  18355. }
  18356. if (numInputs > numOutputs)
  18357. {
  18358. // if there aren't enough output channels for the number of
  18359. // inputs, we need to create some temporary extra ones (can't
  18360. // use the input data in case it gets written to)
  18361. tempBuffer.setSize (numInputs - numOutputs, numSamples,
  18362. false, false, true);
  18363. for (i = 0; i < numOutputs; ++i)
  18364. {
  18365. channels[numActiveChans] = outputChans[i];
  18366. memcpy (channels[numActiveChans], inputChans[i], sizeof (float) * numSamples);
  18367. ++numActiveChans;
  18368. }
  18369. for (i = numOutputs; i < numInputs; ++i)
  18370. {
  18371. channels[numActiveChans] = tempBuffer.getSampleData (i - numOutputs, 0);
  18372. memcpy (channels[numActiveChans], inputChans[i], sizeof (float) * numSamples);
  18373. ++numActiveChans;
  18374. }
  18375. }
  18376. else
  18377. {
  18378. for (i = 0; i < numInputs; ++i)
  18379. {
  18380. channels[numActiveChans] = outputChans[i];
  18381. memcpy (channels[numActiveChans], inputChans[i], sizeof (float) * numSamples);
  18382. ++numActiveChans;
  18383. }
  18384. for (i = numInputs; i < numOutputs; ++i)
  18385. {
  18386. channels[numActiveChans] = outputChans[i];
  18387. zeromem (channels[numActiveChans], sizeof (float) * numSamples);
  18388. ++numActiveChans;
  18389. }
  18390. }
  18391. AudioSampleBuffer buffer (channels, numActiveChans, numSamples);
  18392. info.buffer = &buffer;
  18393. info.startSample = 0;
  18394. info.numSamples = numSamples;
  18395. source->getNextAudioBlock (info);
  18396. for (i = info.buffer->getNumChannels(); --i >= 0;)
  18397. info.buffer->applyGainRamp (i, info.startSample, info.numSamples, lastGain, gain);
  18398. lastGain = gain;
  18399. }
  18400. else
  18401. {
  18402. for (int i = 0; i < totalNumOutputChannels; ++i)
  18403. if (outputChannelData[i] != 0)
  18404. zeromem (outputChannelData[i], sizeof (float) * numSamples);
  18405. }
  18406. }
  18407. void AudioSourcePlayer::audioDeviceAboutToStart (AudioIODevice* device)
  18408. {
  18409. sampleRate = device->getCurrentSampleRate();
  18410. bufferSize = device->getCurrentBufferSizeSamples();
  18411. zeromem (channels, sizeof (channels));
  18412. if (source != 0)
  18413. source->prepareToPlay (bufferSize, sampleRate);
  18414. }
  18415. void AudioSourcePlayer::audioDeviceStopped()
  18416. {
  18417. if (source != 0)
  18418. source->releaseResources();
  18419. sampleRate = 0.0;
  18420. bufferSize = 0;
  18421. tempBuffer.setSize (2, 8);
  18422. }
  18423. END_JUCE_NAMESPACE
  18424. /*** End of inlined file: juce_AudioSourcePlayer.cpp ***/
  18425. /*** Start of inlined file: juce_AudioTransportSource.cpp ***/
  18426. BEGIN_JUCE_NAMESPACE
  18427. AudioTransportSource::AudioTransportSource()
  18428. : source (0),
  18429. resamplerSource (0),
  18430. bufferingSource (0),
  18431. positionableSource (0),
  18432. masterSource (0),
  18433. gain (1.0f),
  18434. lastGain (1.0f),
  18435. playing (false),
  18436. stopped (true),
  18437. sampleRate (44100.0),
  18438. sourceSampleRate (0.0),
  18439. blockSize (128),
  18440. readAheadBufferSize (0),
  18441. isPrepared (false),
  18442. inputStreamEOF (false)
  18443. {
  18444. }
  18445. AudioTransportSource::~AudioTransportSource()
  18446. {
  18447. setSource (0);
  18448. releaseResources();
  18449. }
  18450. void AudioTransportSource::setSource (PositionableAudioSource* const newSource,
  18451. int readAheadBufferSize_,
  18452. double sourceSampleRateToCorrectFor)
  18453. {
  18454. if (source == newSource)
  18455. {
  18456. if (source == 0)
  18457. return;
  18458. setSource (0, 0, 0); // deselect and reselect to avoid releasing resources wrongly
  18459. }
  18460. readAheadBufferSize = readAheadBufferSize_;
  18461. sourceSampleRate = sourceSampleRateToCorrectFor;
  18462. ResamplingAudioSource* newResamplerSource = 0;
  18463. BufferingAudioSource* newBufferingSource = 0;
  18464. PositionableAudioSource* newPositionableSource = 0;
  18465. AudioSource* newMasterSource = 0;
  18466. ScopedPointer <ResamplingAudioSource> oldResamplerSource (resamplerSource);
  18467. ScopedPointer <BufferingAudioSource> oldBufferingSource (bufferingSource);
  18468. AudioSource* oldMasterSource = masterSource;
  18469. if (newSource != 0)
  18470. {
  18471. newPositionableSource = newSource;
  18472. if (readAheadBufferSize_ > 0)
  18473. newPositionableSource = newBufferingSource
  18474. = new BufferingAudioSource (newPositionableSource, false, readAheadBufferSize_);
  18475. newPositionableSource->setNextReadPosition (0);
  18476. if (sourceSampleRateToCorrectFor != 0)
  18477. newMasterSource = newResamplerSource
  18478. = new ResamplingAudioSource (newPositionableSource, false);
  18479. else
  18480. newMasterSource = newPositionableSource;
  18481. if (isPrepared)
  18482. {
  18483. if (newResamplerSource != 0 && sourceSampleRate > 0 && sampleRate > 0)
  18484. newResamplerSource->setResamplingRatio (sourceSampleRate / sampleRate);
  18485. newMasterSource->prepareToPlay (blockSize, sampleRate);
  18486. }
  18487. }
  18488. {
  18489. const ScopedLock sl (callbackLock);
  18490. source = newSource;
  18491. resamplerSource = newResamplerSource;
  18492. bufferingSource = newBufferingSource;
  18493. masterSource = newMasterSource;
  18494. positionableSource = newPositionableSource;
  18495. playing = false;
  18496. }
  18497. if (oldMasterSource != 0)
  18498. oldMasterSource->releaseResources();
  18499. }
  18500. void AudioTransportSource::start()
  18501. {
  18502. if ((! playing) && masterSource != 0)
  18503. {
  18504. callbackLock.enter();
  18505. playing = true;
  18506. stopped = false;
  18507. inputStreamEOF = false;
  18508. callbackLock.exit();
  18509. sendChangeMessage (this);
  18510. }
  18511. }
  18512. void AudioTransportSource::stop()
  18513. {
  18514. if (playing)
  18515. {
  18516. callbackLock.enter();
  18517. playing = false;
  18518. callbackLock.exit();
  18519. int n = 500;
  18520. while (--n >= 0 && ! stopped)
  18521. Thread::sleep (2);
  18522. sendChangeMessage (this);
  18523. }
  18524. }
  18525. void AudioTransportSource::setPosition (double newPosition)
  18526. {
  18527. if (sampleRate > 0.0)
  18528. setNextReadPosition (roundToInt (newPosition * sampleRate));
  18529. }
  18530. double AudioTransportSource::getCurrentPosition() const
  18531. {
  18532. if (sampleRate > 0.0)
  18533. return getNextReadPosition() / sampleRate;
  18534. else
  18535. return 0.0;
  18536. }
  18537. void AudioTransportSource::setNextReadPosition (int newPosition)
  18538. {
  18539. if (positionableSource != 0)
  18540. {
  18541. if (sampleRate > 0 && sourceSampleRate > 0)
  18542. newPosition = roundToInt (newPosition * sourceSampleRate / sampleRate);
  18543. positionableSource->setNextReadPosition (newPosition);
  18544. }
  18545. }
  18546. int AudioTransportSource::getNextReadPosition() const
  18547. {
  18548. if (positionableSource != 0)
  18549. {
  18550. const double ratio = (sampleRate > 0 && sourceSampleRate > 0) ? sampleRate / sourceSampleRate : 1.0;
  18551. return roundToInt (positionableSource->getNextReadPosition() * ratio);
  18552. }
  18553. return 0;
  18554. }
  18555. int AudioTransportSource::getTotalLength() const
  18556. {
  18557. const ScopedLock sl (callbackLock);
  18558. if (positionableSource != 0)
  18559. {
  18560. const double ratio = (sampleRate > 0 && sourceSampleRate > 0) ? sampleRate / sourceSampleRate : 1.0;
  18561. return roundToInt (positionableSource->getTotalLength() * ratio);
  18562. }
  18563. return 0;
  18564. }
  18565. bool AudioTransportSource::isLooping() const
  18566. {
  18567. const ScopedLock sl (callbackLock);
  18568. return positionableSource != 0
  18569. && positionableSource->isLooping();
  18570. }
  18571. void AudioTransportSource::setGain (const float newGain) throw()
  18572. {
  18573. gain = newGain;
  18574. }
  18575. void AudioTransportSource::prepareToPlay (int samplesPerBlockExpected,
  18576. double sampleRate_)
  18577. {
  18578. const ScopedLock sl (callbackLock);
  18579. sampleRate = sampleRate_;
  18580. blockSize = samplesPerBlockExpected;
  18581. if (masterSource != 0)
  18582. masterSource->prepareToPlay (samplesPerBlockExpected, sampleRate);
  18583. if (resamplerSource != 0 && sourceSampleRate != 0)
  18584. resamplerSource->setResamplingRatio (sourceSampleRate / sampleRate);
  18585. isPrepared = true;
  18586. }
  18587. void AudioTransportSource::releaseResources()
  18588. {
  18589. const ScopedLock sl (callbackLock);
  18590. if (masterSource != 0)
  18591. masterSource->releaseResources();
  18592. isPrepared = false;
  18593. }
  18594. void AudioTransportSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  18595. {
  18596. const ScopedLock sl (callbackLock);
  18597. inputStreamEOF = false;
  18598. if (masterSource != 0 && ! stopped)
  18599. {
  18600. masterSource->getNextAudioBlock (info);
  18601. if (! playing)
  18602. {
  18603. // just stopped playing, so fade out the last block..
  18604. for (int i = info.buffer->getNumChannels(); --i >= 0;)
  18605. info.buffer->applyGainRamp (i, info.startSample, jmin (256, info.numSamples), 1.0f, 0.0f);
  18606. if (info.numSamples > 256)
  18607. info.buffer->clear (info.startSample + 256, info.numSamples - 256);
  18608. }
  18609. if (positionableSource->getNextReadPosition() > positionableSource->getTotalLength() + 1
  18610. && ! positionableSource->isLooping())
  18611. {
  18612. playing = false;
  18613. inputStreamEOF = true;
  18614. sendChangeMessage (this);
  18615. }
  18616. stopped = ! playing;
  18617. for (int i = info.buffer->getNumChannels(); --i >= 0;)
  18618. {
  18619. info.buffer->applyGainRamp (i, info.startSample, info.numSamples,
  18620. lastGain, gain);
  18621. }
  18622. }
  18623. else
  18624. {
  18625. info.clearActiveBufferRegion();
  18626. stopped = true;
  18627. }
  18628. lastGain = gain;
  18629. }
  18630. END_JUCE_NAMESPACE
  18631. /*** End of inlined file: juce_AudioTransportSource.cpp ***/
  18632. /*** Start of inlined file: juce_BufferingAudioSource.cpp ***/
  18633. BEGIN_JUCE_NAMESPACE
  18634. class SharedBufferingAudioSourceThread : public DeletedAtShutdown,
  18635. public Thread,
  18636. private Timer
  18637. {
  18638. public:
  18639. SharedBufferingAudioSourceThread()
  18640. : Thread ("Audio Buffer")
  18641. {
  18642. }
  18643. ~SharedBufferingAudioSourceThread()
  18644. {
  18645. stopThread (10000);
  18646. clearSingletonInstance();
  18647. }
  18648. juce_DeclareSingleton (SharedBufferingAudioSourceThread, false)
  18649. void addSource (BufferingAudioSource* source)
  18650. {
  18651. const ScopedLock sl (lock);
  18652. if (! sources.contains ((void*) source))
  18653. {
  18654. sources.add ((void*) source);
  18655. startThread();
  18656. stopTimer();
  18657. }
  18658. notify();
  18659. }
  18660. void removeSource (BufferingAudioSource* source)
  18661. {
  18662. const ScopedLock sl (lock);
  18663. sources.removeValue ((void*) source);
  18664. if (sources.size() == 0)
  18665. startTimer (5000);
  18666. }
  18667. private:
  18668. VoidArray sources;
  18669. CriticalSection lock;
  18670. void run()
  18671. {
  18672. while (! threadShouldExit())
  18673. {
  18674. bool busy = false;
  18675. for (int i = sources.size(); --i >= 0;)
  18676. {
  18677. if (threadShouldExit())
  18678. return;
  18679. const ScopedLock sl (lock);
  18680. BufferingAudioSource* const b = (BufferingAudioSource*) sources[i];
  18681. if (b != 0 && b->readNextBufferChunk())
  18682. busy = true;
  18683. }
  18684. if (! busy)
  18685. wait (500);
  18686. }
  18687. }
  18688. void timerCallback()
  18689. {
  18690. stopTimer();
  18691. if (sources.size() == 0)
  18692. deleteInstance();
  18693. }
  18694. SharedBufferingAudioSourceThread (const SharedBufferingAudioSourceThread&);
  18695. const SharedBufferingAudioSourceThread& operator= (const SharedBufferingAudioSourceThread&);
  18696. };
  18697. juce_ImplementSingleton (SharedBufferingAudioSourceThread)
  18698. BufferingAudioSource::BufferingAudioSource (PositionableAudioSource* source_,
  18699. const bool deleteSourceWhenDeleted_,
  18700. int numberOfSamplesToBuffer_)
  18701. : source (source_),
  18702. deleteSourceWhenDeleted (deleteSourceWhenDeleted_),
  18703. numberOfSamplesToBuffer (jmax (1024, numberOfSamplesToBuffer_)),
  18704. buffer (2, 0),
  18705. bufferValidStart (0),
  18706. bufferValidEnd (0),
  18707. nextPlayPos (0),
  18708. wasSourceLooping (false)
  18709. {
  18710. jassert (source_ != 0);
  18711. jassert (numberOfSamplesToBuffer_ > 1024); // not much point using this class if you're
  18712. // not using a larger buffer..
  18713. }
  18714. BufferingAudioSource::~BufferingAudioSource()
  18715. {
  18716. SharedBufferingAudioSourceThread* const thread = SharedBufferingAudioSourceThread::getInstanceWithoutCreating();
  18717. if (thread != 0)
  18718. thread->removeSource (this);
  18719. if (deleteSourceWhenDeleted)
  18720. delete source;
  18721. }
  18722. void BufferingAudioSource::prepareToPlay (int samplesPerBlockExpected, double sampleRate_)
  18723. {
  18724. source->prepareToPlay (samplesPerBlockExpected, sampleRate_);
  18725. sampleRate = sampleRate_;
  18726. buffer.setSize (2, jmax (samplesPerBlockExpected * 2, numberOfSamplesToBuffer));
  18727. buffer.clear();
  18728. bufferValidStart = 0;
  18729. bufferValidEnd = 0;
  18730. SharedBufferingAudioSourceThread::getInstance()->addSource (this);
  18731. while (bufferValidEnd - bufferValidStart < jmin (((int) sampleRate_) / 4,
  18732. buffer.getNumSamples() / 2))
  18733. {
  18734. SharedBufferingAudioSourceThread::getInstance()->notify();
  18735. Thread::sleep (5);
  18736. }
  18737. }
  18738. void BufferingAudioSource::releaseResources()
  18739. {
  18740. SharedBufferingAudioSourceThread* const thread = SharedBufferingAudioSourceThread::getInstanceWithoutCreating();
  18741. if (thread != 0)
  18742. thread->removeSource (this);
  18743. buffer.setSize (2, 0);
  18744. source->releaseResources();
  18745. }
  18746. void BufferingAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  18747. {
  18748. const ScopedLock sl (bufferStartPosLock);
  18749. const int validStart = jlimit (bufferValidStart, bufferValidEnd, nextPlayPos) - nextPlayPos;
  18750. const int validEnd = jlimit (bufferValidStart, bufferValidEnd, nextPlayPos + info.numSamples) - nextPlayPos;
  18751. if (validStart == validEnd)
  18752. {
  18753. // total cache miss
  18754. info.clearActiveBufferRegion();
  18755. }
  18756. else
  18757. {
  18758. if (validStart > 0)
  18759. info.buffer->clear (info.startSample, validStart); // partial cache miss at start
  18760. if (validEnd < info.numSamples)
  18761. info.buffer->clear (info.startSample + validEnd,
  18762. info.numSamples - validEnd); // partial cache miss at end
  18763. if (validStart < validEnd)
  18764. {
  18765. for (int chan = jmin (2, info.buffer->getNumChannels()); --chan >= 0;)
  18766. {
  18767. const int startBufferIndex = (validStart + nextPlayPos) % buffer.getNumSamples();
  18768. const int endBufferIndex = (validEnd + nextPlayPos) % buffer.getNumSamples();
  18769. if (startBufferIndex < endBufferIndex)
  18770. {
  18771. info.buffer->copyFrom (chan, info.startSample + validStart,
  18772. buffer,
  18773. chan, startBufferIndex,
  18774. validEnd - validStart);
  18775. }
  18776. else
  18777. {
  18778. const int initialSize = buffer.getNumSamples() - startBufferIndex;
  18779. info.buffer->copyFrom (chan, info.startSample + validStart,
  18780. buffer,
  18781. chan, startBufferIndex,
  18782. initialSize);
  18783. info.buffer->copyFrom (chan, info.startSample + validStart + initialSize,
  18784. buffer,
  18785. chan, 0,
  18786. (validEnd - validStart) - initialSize);
  18787. }
  18788. }
  18789. }
  18790. nextPlayPos += info.numSamples;
  18791. if (source->isLooping() && nextPlayPos > 0)
  18792. nextPlayPos %= source->getTotalLength();
  18793. }
  18794. SharedBufferingAudioSourceThread* const thread = SharedBufferingAudioSourceThread::getInstanceWithoutCreating();
  18795. if (thread != 0)
  18796. thread->notify();
  18797. }
  18798. int BufferingAudioSource::getNextReadPosition() const
  18799. {
  18800. return (source->isLooping() && nextPlayPos > 0)
  18801. ? nextPlayPos % source->getTotalLength()
  18802. : nextPlayPos;
  18803. }
  18804. void BufferingAudioSource::setNextReadPosition (int newPosition)
  18805. {
  18806. const ScopedLock sl (bufferStartPosLock);
  18807. nextPlayPos = newPosition;
  18808. SharedBufferingAudioSourceThread* const thread = SharedBufferingAudioSourceThread::getInstanceWithoutCreating();
  18809. if (thread != 0)
  18810. thread->notify();
  18811. }
  18812. bool BufferingAudioSource::readNextBufferChunk()
  18813. {
  18814. bufferStartPosLock.enter();
  18815. if (wasSourceLooping != isLooping())
  18816. {
  18817. wasSourceLooping = isLooping();
  18818. bufferValidStart = 0;
  18819. bufferValidEnd = 0;
  18820. }
  18821. int newBVS = jmax (0, nextPlayPos);
  18822. int newBVE = newBVS + buffer.getNumSamples() - 4;
  18823. int sectionToReadStart = 0;
  18824. int sectionToReadEnd = 0;
  18825. const int maxChunkSize = 2048;
  18826. if (newBVS < bufferValidStart || newBVS >= bufferValidEnd)
  18827. {
  18828. newBVE = jmin (newBVE, newBVS + maxChunkSize);
  18829. sectionToReadStart = newBVS;
  18830. sectionToReadEnd = newBVE;
  18831. bufferValidStart = 0;
  18832. bufferValidEnd = 0;
  18833. }
  18834. else if (abs (newBVS - bufferValidStart) > 512
  18835. || abs (newBVE - bufferValidEnd) > 512)
  18836. {
  18837. newBVE = jmin (newBVE, bufferValidEnd + maxChunkSize);
  18838. sectionToReadStart = bufferValidEnd;
  18839. sectionToReadEnd = newBVE;
  18840. bufferValidStart = newBVS;
  18841. bufferValidEnd = jmin (bufferValidEnd, newBVE);
  18842. }
  18843. bufferStartPosLock.exit();
  18844. if (sectionToReadStart != sectionToReadEnd)
  18845. {
  18846. const int bufferIndexStart = sectionToReadStart % buffer.getNumSamples();
  18847. const int bufferIndexEnd = sectionToReadEnd % buffer.getNumSamples();
  18848. if (bufferIndexStart < bufferIndexEnd)
  18849. {
  18850. readBufferSection (sectionToReadStart,
  18851. sectionToReadEnd - sectionToReadStart,
  18852. bufferIndexStart);
  18853. }
  18854. else
  18855. {
  18856. const int initialSize = buffer.getNumSamples() - bufferIndexStart;
  18857. readBufferSection (sectionToReadStart,
  18858. initialSize,
  18859. bufferIndexStart);
  18860. readBufferSection (sectionToReadStart + initialSize,
  18861. (sectionToReadEnd - sectionToReadStart) - initialSize,
  18862. 0);
  18863. }
  18864. const ScopedLock sl2 (bufferStartPosLock);
  18865. bufferValidStart = newBVS;
  18866. bufferValidEnd = newBVE;
  18867. return true;
  18868. }
  18869. else
  18870. {
  18871. return false;
  18872. }
  18873. }
  18874. void BufferingAudioSource::readBufferSection (int start, int length, int bufferOffset)
  18875. {
  18876. if (source->getNextReadPosition() != start)
  18877. source->setNextReadPosition (start);
  18878. AudioSourceChannelInfo info;
  18879. info.buffer = &buffer;
  18880. info.startSample = bufferOffset;
  18881. info.numSamples = length;
  18882. source->getNextAudioBlock (info);
  18883. }
  18884. END_JUCE_NAMESPACE
  18885. /*** End of inlined file: juce_BufferingAudioSource.cpp ***/
  18886. /*** Start of inlined file: juce_ChannelRemappingAudioSource.cpp ***/
  18887. BEGIN_JUCE_NAMESPACE
  18888. ChannelRemappingAudioSource::ChannelRemappingAudioSource (AudioSource* const source_,
  18889. const bool deleteSourceWhenDeleted_)
  18890. : requiredNumberOfChannels (2),
  18891. source (source_),
  18892. deleteSourceWhenDeleted (deleteSourceWhenDeleted_),
  18893. buffer (2, 16)
  18894. {
  18895. remappedInfo.buffer = &buffer;
  18896. remappedInfo.startSample = 0;
  18897. }
  18898. ChannelRemappingAudioSource::~ChannelRemappingAudioSource()
  18899. {
  18900. if (deleteSourceWhenDeleted)
  18901. delete source;
  18902. }
  18903. void ChannelRemappingAudioSource::setNumberOfChannelsToProduce (const int requiredNumberOfChannels_) throw()
  18904. {
  18905. const ScopedLock sl (lock);
  18906. requiredNumberOfChannels = requiredNumberOfChannels_;
  18907. }
  18908. void ChannelRemappingAudioSource::clearAllMappings() throw()
  18909. {
  18910. const ScopedLock sl (lock);
  18911. remappedInputs.clear();
  18912. remappedOutputs.clear();
  18913. }
  18914. void ChannelRemappingAudioSource::setInputChannelMapping (const int destIndex, const int sourceIndex) throw()
  18915. {
  18916. const ScopedLock sl (lock);
  18917. while (remappedInputs.size() < destIndex)
  18918. remappedInputs.add (-1);
  18919. remappedInputs.set (destIndex, sourceIndex);
  18920. }
  18921. void ChannelRemappingAudioSource::setOutputChannelMapping (const int sourceIndex, const int destIndex) throw()
  18922. {
  18923. const ScopedLock sl (lock);
  18924. while (remappedOutputs.size() < sourceIndex)
  18925. remappedOutputs.add (-1);
  18926. remappedOutputs.set (sourceIndex, destIndex);
  18927. }
  18928. int ChannelRemappingAudioSource::getRemappedInputChannel (const int inputChannelIndex) const throw()
  18929. {
  18930. const ScopedLock sl (lock);
  18931. if (inputChannelIndex >= 0 && inputChannelIndex < remappedInputs.size())
  18932. return remappedInputs.getUnchecked (inputChannelIndex);
  18933. return -1;
  18934. }
  18935. int ChannelRemappingAudioSource::getRemappedOutputChannel (const int outputChannelIndex) const throw()
  18936. {
  18937. const ScopedLock sl (lock);
  18938. if (outputChannelIndex >= 0 && outputChannelIndex < remappedOutputs.size())
  18939. return remappedOutputs .getUnchecked (outputChannelIndex);
  18940. return -1;
  18941. }
  18942. void ChannelRemappingAudioSource::prepareToPlay (int samplesPerBlockExpected, double sampleRate)
  18943. {
  18944. source->prepareToPlay (samplesPerBlockExpected, sampleRate);
  18945. }
  18946. void ChannelRemappingAudioSource::releaseResources()
  18947. {
  18948. source->releaseResources();
  18949. }
  18950. void ChannelRemappingAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill)
  18951. {
  18952. const ScopedLock sl (lock);
  18953. buffer.setSize (requiredNumberOfChannels, bufferToFill.numSamples, false, false, true);
  18954. const int numChans = bufferToFill.buffer->getNumChannels();
  18955. int i;
  18956. for (i = 0; i < buffer.getNumChannels(); ++i)
  18957. {
  18958. const int remappedChan = getRemappedInputChannel (i);
  18959. if (remappedChan >= 0 && remappedChan < numChans)
  18960. {
  18961. buffer.copyFrom (i, 0, *bufferToFill.buffer,
  18962. remappedChan,
  18963. bufferToFill.startSample,
  18964. bufferToFill.numSamples);
  18965. }
  18966. else
  18967. {
  18968. buffer.clear (i, 0, bufferToFill.numSamples);
  18969. }
  18970. }
  18971. remappedInfo.numSamples = bufferToFill.numSamples;
  18972. source->getNextAudioBlock (remappedInfo);
  18973. bufferToFill.clearActiveBufferRegion();
  18974. for (i = 0; i < requiredNumberOfChannels; ++i)
  18975. {
  18976. const int remappedChan = getRemappedOutputChannel (i);
  18977. if (remappedChan >= 0 && remappedChan < numChans)
  18978. {
  18979. bufferToFill.buffer->addFrom (remappedChan, bufferToFill.startSample,
  18980. buffer, i, 0, bufferToFill.numSamples);
  18981. }
  18982. }
  18983. }
  18984. XmlElement* ChannelRemappingAudioSource::createXml() const throw()
  18985. {
  18986. XmlElement* e = new XmlElement (T("MAPPINGS"));
  18987. String ins, outs;
  18988. int i;
  18989. const ScopedLock sl (lock);
  18990. for (i = 0; i < remappedInputs.size(); ++i)
  18991. ins << remappedInputs.getUnchecked(i) << T(' ');
  18992. for (i = 0; i < remappedOutputs.size(); ++i)
  18993. outs << remappedOutputs.getUnchecked(i) << T(' ');
  18994. e->setAttribute (T("inputs"), ins.trimEnd());
  18995. e->setAttribute (T("outputs"), outs.trimEnd());
  18996. return e;
  18997. }
  18998. void ChannelRemappingAudioSource::restoreFromXml (const XmlElement& e) throw()
  18999. {
  19000. if (e.hasTagName (T("MAPPINGS")))
  19001. {
  19002. const ScopedLock sl (lock);
  19003. clearAllMappings();
  19004. StringArray ins, outs;
  19005. ins.addTokens (e.getStringAttribute (T("inputs")), false);
  19006. outs.addTokens (e.getStringAttribute (T("outputs")), false);
  19007. int i;
  19008. for (i = 0; i < ins.size(); ++i)
  19009. remappedInputs.add (ins[i].getIntValue());
  19010. for (i = 0; i < outs.size(); ++i)
  19011. remappedOutputs.add (outs[i].getIntValue());
  19012. }
  19013. }
  19014. END_JUCE_NAMESPACE
  19015. /*** End of inlined file: juce_ChannelRemappingAudioSource.cpp ***/
  19016. /*** Start of inlined file: juce_IIRFilterAudioSource.cpp ***/
  19017. BEGIN_JUCE_NAMESPACE
  19018. IIRFilterAudioSource::IIRFilterAudioSource (AudioSource* const inputSource,
  19019. const bool deleteInputWhenDeleted_)
  19020. : input (inputSource),
  19021. deleteInputWhenDeleted (deleteInputWhenDeleted_)
  19022. {
  19023. jassert (inputSource != 0);
  19024. for (int i = 2; --i >= 0;)
  19025. iirFilters.add (new IIRFilter());
  19026. }
  19027. IIRFilterAudioSource::~IIRFilterAudioSource()
  19028. {
  19029. if (deleteInputWhenDeleted)
  19030. delete input;
  19031. }
  19032. void IIRFilterAudioSource::setFilterParameters (const IIRFilter& newSettings)
  19033. {
  19034. for (int i = iirFilters.size(); --i >= 0;)
  19035. iirFilters.getUnchecked(i)->copyCoefficientsFrom (newSettings);
  19036. }
  19037. void IIRFilterAudioSource::prepareToPlay (int samplesPerBlockExpected, double sampleRate)
  19038. {
  19039. input->prepareToPlay (samplesPerBlockExpected, sampleRate);
  19040. for (int i = iirFilters.size(); --i >= 0;)
  19041. iirFilters.getUnchecked(i)->reset();
  19042. }
  19043. void IIRFilterAudioSource::releaseResources()
  19044. {
  19045. input->releaseResources();
  19046. }
  19047. void IIRFilterAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill)
  19048. {
  19049. input->getNextAudioBlock (bufferToFill);
  19050. const int numChannels = bufferToFill.buffer->getNumChannels();
  19051. while (numChannels > iirFilters.size())
  19052. iirFilters.add (new IIRFilter (*iirFilters.getUnchecked (0)));
  19053. for (int i = 0; i < numChannels; ++i)
  19054. iirFilters.getUnchecked(i)
  19055. ->processSamples (bufferToFill.buffer->getSampleData (i, bufferToFill.startSample),
  19056. bufferToFill.numSamples);
  19057. }
  19058. END_JUCE_NAMESPACE
  19059. /*** End of inlined file: juce_IIRFilterAudioSource.cpp ***/
  19060. /*** Start of inlined file: juce_MixerAudioSource.cpp ***/
  19061. BEGIN_JUCE_NAMESPACE
  19062. MixerAudioSource::MixerAudioSource()
  19063. : tempBuffer (2, 0),
  19064. currentSampleRate (0.0),
  19065. bufferSizeExpected (0)
  19066. {
  19067. }
  19068. MixerAudioSource::~MixerAudioSource()
  19069. {
  19070. removeAllInputs();
  19071. }
  19072. void MixerAudioSource::addInputSource (AudioSource* input, const bool deleteWhenRemoved)
  19073. {
  19074. if (input != 0 && ! inputs.contains (input))
  19075. {
  19076. lock.enter();
  19077. double localRate = currentSampleRate;
  19078. int localBufferSize = bufferSizeExpected;
  19079. lock.exit();
  19080. if (localRate != 0.0)
  19081. input->prepareToPlay (localBufferSize, localRate);
  19082. const ScopedLock sl (lock);
  19083. inputsToDelete.setBit (inputs.size(), deleteWhenRemoved);
  19084. inputs.add (input);
  19085. }
  19086. }
  19087. void MixerAudioSource::removeInputSource (AudioSource* input, const bool deleteInput)
  19088. {
  19089. if (input != 0)
  19090. {
  19091. lock.enter();
  19092. const int index = inputs.indexOf ((void*) input);
  19093. if (index >= 0)
  19094. {
  19095. inputsToDelete.shiftBits (index, 1);
  19096. inputs.remove (index);
  19097. }
  19098. lock.exit();
  19099. if (index >= 0)
  19100. {
  19101. input->releaseResources();
  19102. if (deleteInput)
  19103. delete input;
  19104. }
  19105. }
  19106. }
  19107. void MixerAudioSource::removeAllInputs()
  19108. {
  19109. lock.enter();
  19110. VoidArray inputsCopy (inputs);
  19111. BitArray inputsToDeleteCopy (inputsToDelete);
  19112. inputs.clear();
  19113. lock.exit();
  19114. for (int i = inputsCopy.size(); --i >= 0;)
  19115. if (inputsToDeleteCopy[i])
  19116. delete (AudioSource*) inputsCopy[i];
  19117. }
  19118. void MixerAudioSource::prepareToPlay (int samplesPerBlockExpected, double sampleRate)
  19119. {
  19120. tempBuffer.setSize (2, samplesPerBlockExpected);
  19121. const ScopedLock sl (lock);
  19122. currentSampleRate = sampleRate;
  19123. bufferSizeExpected = samplesPerBlockExpected;
  19124. for (int i = inputs.size(); --i >= 0;)
  19125. ((AudioSource*) inputs.getUnchecked(i))->prepareToPlay (samplesPerBlockExpected,
  19126. sampleRate);
  19127. }
  19128. void MixerAudioSource::releaseResources()
  19129. {
  19130. const ScopedLock sl (lock);
  19131. for (int i = inputs.size(); --i >= 0;)
  19132. ((AudioSource*) inputs.getUnchecked(i))->releaseResources();
  19133. tempBuffer.setSize (2, 0);
  19134. currentSampleRate = 0;
  19135. bufferSizeExpected = 0;
  19136. }
  19137. void MixerAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  19138. {
  19139. const ScopedLock sl (lock);
  19140. if (inputs.size() > 0)
  19141. {
  19142. ((AudioSource*) inputs.getUnchecked(0))->getNextAudioBlock (info);
  19143. if (inputs.size() > 1)
  19144. {
  19145. tempBuffer.setSize (jmax (1, info.buffer->getNumChannels()),
  19146. info.buffer->getNumSamples());
  19147. AudioSourceChannelInfo info2;
  19148. info2.buffer = &tempBuffer;
  19149. info2.numSamples = info.numSamples;
  19150. info2.startSample = 0;
  19151. for (int i = 1; i < inputs.size(); ++i)
  19152. {
  19153. ((AudioSource*) inputs.getUnchecked(i))->getNextAudioBlock (info2);
  19154. for (int chan = 0; chan < info.buffer->getNumChannels(); ++chan)
  19155. info.buffer->addFrom (chan, info.startSample, tempBuffer, chan, 0, info.numSamples);
  19156. }
  19157. }
  19158. }
  19159. else
  19160. {
  19161. info.clearActiveBufferRegion();
  19162. }
  19163. }
  19164. END_JUCE_NAMESPACE
  19165. /*** End of inlined file: juce_MixerAudioSource.cpp ***/
  19166. /*** Start of inlined file: juce_ResamplingAudioSource.cpp ***/
  19167. BEGIN_JUCE_NAMESPACE
  19168. ResamplingAudioSource::ResamplingAudioSource (AudioSource* const inputSource,
  19169. const bool deleteInputWhenDeleted_)
  19170. : input (inputSource),
  19171. deleteInputWhenDeleted (deleteInputWhenDeleted_),
  19172. ratio (1.0),
  19173. lastRatio (1.0),
  19174. buffer (2, 0),
  19175. sampsInBuffer (0)
  19176. {
  19177. jassert (input != 0);
  19178. }
  19179. ResamplingAudioSource::~ResamplingAudioSource()
  19180. {
  19181. if (deleteInputWhenDeleted)
  19182. delete input;
  19183. }
  19184. void ResamplingAudioSource::setResamplingRatio (const double samplesInPerOutputSample)
  19185. {
  19186. jassert (samplesInPerOutputSample > 0);
  19187. const ScopedLock sl (ratioLock);
  19188. ratio = jmax (0.0, samplesInPerOutputSample);
  19189. }
  19190. void ResamplingAudioSource::prepareToPlay (int samplesPerBlockExpected,
  19191. double sampleRate)
  19192. {
  19193. const ScopedLock sl (ratioLock);
  19194. input->prepareToPlay (samplesPerBlockExpected, sampleRate);
  19195. buffer.setSize (2, roundToInt (samplesPerBlockExpected * ratio) + 32);
  19196. buffer.clear();
  19197. sampsInBuffer = 0;
  19198. bufferPos = 0;
  19199. subSampleOffset = 0.0;
  19200. createLowPass (ratio);
  19201. resetFilters();
  19202. }
  19203. void ResamplingAudioSource::releaseResources()
  19204. {
  19205. input->releaseResources();
  19206. buffer.setSize (2, 0);
  19207. }
  19208. void ResamplingAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  19209. {
  19210. const ScopedLock sl (ratioLock);
  19211. if (lastRatio != ratio)
  19212. {
  19213. createLowPass (ratio);
  19214. lastRatio = ratio;
  19215. }
  19216. const int sampsNeeded = roundToInt (info.numSamples * ratio) + 2;
  19217. int bufferSize = buffer.getNumSamples();
  19218. if (bufferSize < sampsNeeded + 8)
  19219. {
  19220. bufferPos %= bufferSize;
  19221. bufferSize = sampsNeeded + 32;
  19222. buffer.setSize (buffer.getNumChannels(), bufferSize, true, true);
  19223. }
  19224. bufferPos %= bufferSize;
  19225. int endOfBufferPos = bufferPos + sampsInBuffer;
  19226. while (sampsNeeded > sampsInBuffer)
  19227. {
  19228. endOfBufferPos %= bufferSize;
  19229. int numToDo = jmin (sampsNeeded - sampsInBuffer,
  19230. bufferSize - endOfBufferPos);
  19231. AudioSourceChannelInfo readInfo;
  19232. readInfo.buffer = &buffer;
  19233. readInfo.numSamples = numToDo;
  19234. readInfo.startSample = endOfBufferPos;
  19235. input->getNextAudioBlock (readInfo);
  19236. if (ratio > 1.0001)
  19237. {
  19238. // for down-sampling, pre-apply the filter..
  19239. for (int i = jmin (2, info.buffer->getNumChannels()); --i >= 0;)
  19240. applyFilter (buffer.getSampleData (i, endOfBufferPos), numToDo, filterStates[i]);
  19241. }
  19242. sampsInBuffer += numToDo;
  19243. endOfBufferPos += numToDo;
  19244. }
  19245. float* dl = info.buffer->getSampleData (0, info.startSample);
  19246. float* dr = (info.buffer->getNumChannels() > 1) ? info.buffer->getSampleData (1, info.startSample) : 0;
  19247. const float* const bl = buffer.getSampleData (0, 0);
  19248. const float* const br = buffer.getSampleData (1, 0);
  19249. int nextPos = (bufferPos + 1) % bufferSize;
  19250. for (int m = info.numSamples; --m >= 0;)
  19251. {
  19252. const float alpha = (float) subSampleOffset;
  19253. const float invAlpha = 1.0f - alpha;
  19254. *dl++ = bl [bufferPos] * invAlpha + bl [nextPos] * alpha;
  19255. if (dr != 0)
  19256. *dr++ = br [bufferPos] * invAlpha + br [nextPos] * alpha;
  19257. subSampleOffset += ratio;
  19258. jassert (sampsInBuffer > 0);
  19259. while (subSampleOffset >= 1.0)
  19260. {
  19261. if (++bufferPos >= bufferSize)
  19262. bufferPos = 0;
  19263. --sampsInBuffer;
  19264. nextPos = (bufferPos + 1) % bufferSize;
  19265. subSampleOffset -= 1.0;
  19266. }
  19267. }
  19268. if (ratio < 0.9999)
  19269. {
  19270. // for up-sampling, apply the filter after transposing..
  19271. for (int i = jmin (2, info.buffer->getNumChannels()); --i >= 0;)
  19272. applyFilter (info.buffer->getSampleData (i, info.startSample), info.numSamples, filterStates[i]);
  19273. }
  19274. else if (ratio <= 1.0001)
  19275. {
  19276. // if the filter's not currently being applied, keep it stoked with the last couple of samples to avoid discontinuities
  19277. for (int i = jmin (2, info.buffer->getNumChannels()); --i >= 0;)
  19278. {
  19279. const float* const endOfBuffer = info.buffer->getSampleData (i, info.startSample + info.numSamples - 1);
  19280. FilterState& fs = filterStates[i];
  19281. if (info.numSamples > 1)
  19282. {
  19283. fs.y2 = fs.x2 = *(endOfBuffer - 1);
  19284. }
  19285. else
  19286. {
  19287. fs.y2 = fs.y1;
  19288. fs.x2 = fs.x1;
  19289. }
  19290. fs.y1 = fs.x1 = *endOfBuffer;
  19291. }
  19292. }
  19293. jassert (sampsInBuffer >= 0);
  19294. }
  19295. void ResamplingAudioSource::createLowPass (const double frequencyRatio)
  19296. {
  19297. const double proportionalRate = (frequencyRatio > 1.0) ? 0.5 / frequencyRatio
  19298. : 0.5 * frequencyRatio;
  19299. const double n = 1.0 / tan (double_Pi * jmax (0.001, proportionalRate));
  19300. const double nSquared = n * n;
  19301. const double c1 = 1.0 / (1.0 + sqrt (2.0) * n + nSquared);
  19302. setFilterCoefficients (c1,
  19303. c1 * 2.0f,
  19304. c1,
  19305. 1.0,
  19306. c1 * 2.0 * (1.0 - nSquared),
  19307. c1 * (1.0 - sqrt (2.0) * n + nSquared));
  19308. }
  19309. void ResamplingAudioSource::setFilterCoefficients (double c1, double c2, double c3, double c4, double c5, double c6)
  19310. {
  19311. const double a = 1.0 / c4;
  19312. c1 *= a;
  19313. c2 *= a;
  19314. c3 *= a;
  19315. c5 *= a;
  19316. c6 *= a;
  19317. coefficients[0] = c1;
  19318. coefficients[1] = c2;
  19319. coefficients[2] = c3;
  19320. coefficients[3] = c4;
  19321. coefficients[4] = c5;
  19322. coefficients[5] = c6;
  19323. }
  19324. void ResamplingAudioSource::resetFilters()
  19325. {
  19326. zeromem (filterStates, sizeof (filterStates));
  19327. }
  19328. void ResamplingAudioSource::applyFilter (float* samples, int num, FilterState& fs)
  19329. {
  19330. while (--num >= 0)
  19331. {
  19332. const double in = *samples;
  19333. double out = coefficients[0] * in
  19334. + coefficients[1] * fs.x1
  19335. + coefficients[2] * fs.x2
  19336. - coefficients[4] * fs.y1
  19337. - coefficients[5] * fs.y2;
  19338. #if JUCE_INTEL
  19339. if (! (out < -1.0e-8 || out > 1.0e-8))
  19340. out = 0;
  19341. #endif
  19342. fs.x2 = fs.x1;
  19343. fs.x1 = in;
  19344. fs.y2 = fs.y1;
  19345. fs.y1 = out;
  19346. *samples++ = (float) out;
  19347. }
  19348. }
  19349. END_JUCE_NAMESPACE
  19350. /*** End of inlined file: juce_ResamplingAudioSource.cpp ***/
  19351. /*** Start of inlined file: juce_ToneGeneratorAudioSource.cpp ***/
  19352. BEGIN_JUCE_NAMESPACE
  19353. ToneGeneratorAudioSource::ToneGeneratorAudioSource()
  19354. : frequency (1000.0),
  19355. sampleRate (44100.0),
  19356. currentPhase (0.0),
  19357. phasePerSample (0.0),
  19358. amplitude (0.5f)
  19359. {
  19360. }
  19361. ToneGeneratorAudioSource::~ToneGeneratorAudioSource()
  19362. {
  19363. }
  19364. void ToneGeneratorAudioSource::setAmplitude (const float newAmplitude)
  19365. {
  19366. amplitude = newAmplitude;
  19367. }
  19368. void ToneGeneratorAudioSource::setFrequency (const double newFrequencyHz)
  19369. {
  19370. frequency = newFrequencyHz;
  19371. phasePerSample = 0.0;
  19372. }
  19373. void ToneGeneratorAudioSource::prepareToPlay (int /*samplesPerBlockExpected*/,
  19374. double sampleRate_)
  19375. {
  19376. currentPhase = 0.0;
  19377. phasePerSample = 0.0;
  19378. sampleRate = sampleRate_;
  19379. }
  19380. void ToneGeneratorAudioSource::releaseResources()
  19381. {
  19382. }
  19383. void ToneGeneratorAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  19384. {
  19385. if (phasePerSample == 0.0)
  19386. phasePerSample = double_Pi * 2.0 / (sampleRate / frequency);
  19387. for (int i = 0; i < info.numSamples; ++i)
  19388. {
  19389. const float sample = amplitude * (float) sin (currentPhase);
  19390. currentPhase += phasePerSample;
  19391. for (int j = info.buffer->getNumChannels(); --j >= 0;)
  19392. *info.buffer->getSampleData (j, info.startSample + i) = sample;
  19393. }
  19394. }
  19395. END_JUCE_NAMESPACE
  19396. /*** End of inlined file: juce_ToneGeneratorAudioSource.cpp ***/
  19397. /*** Start of inlined file: juce_AudioDeviceManager.cpp ***/
  19398. BEGIN_JUCE_NAMESPACE
  19399. AudioDeviceManager::AudioDeviceSetup::AudioDeviceSetup()
  19400. : sampleRate (0),
  19401. bufferSize (0),
  19402. useDefaultInputChannels (true),
  19403. useDefaultOutputChannels (true)
  19404. {
  19405. }
  19406. bool AudioDeviceManager::AudioDeviceSetup::operator== (const AudioDeviceManager::AudioDeviceSetup& other) const
  19407. {
  19408. return outputDeviceName == other.outputDeviceName
  19409. && inputDeviceName == other.inputDeviceName
  19410. && sampleRate == other.sampleRate
  19411. && bufferSize == other.bufferSize
  19412. && inputChannels == other.inputChannels
  19413. && useDefaultInputChannels == other.useDefaultInputChannels
  19414. && outputChannels == other.outputChannels
  19415. && useDefaultOutputChannels == other.useDefaultOutputChannels;
  19416. }
  19417. AudioDeviceManager::AudioDeviceManager()
  19418. : currentAudioDevice (0),
  19419. numInputChansNeeded (0),
  19420. numOutputChansNeeded (2),
  19421. listNeedsScanning (true),
  19422. useInputNames (false),
  19423. inputLevelMeasurementEnabledCount (0),
  19424. inputLevel (0),
  19425. tempBuffer (2, 2),
  19426. defaultMidiOutput (0),
  19427. cpuUsageMs (0),
  19428. timeToCpuScale (0)
  19429. {
  19430. callbackHandler.owner = this;
  19431. }
  19432. AudioDeviceManager::~AudioDeviceManager()
  19433. {
  19434. currentAudioDevice = 0;
  19435. defaultMidiOutput = 0;
  19436. }
  19437. void AudioDeviceManager::createDeviceTypesIfNeeded()
  19438. {
  19439. if (availableDeviceTypes.size() == 0)
  19440. {
  19441. createAudioDeviceTypes (availableDeviceTypes);
  19442. while (lastDeviceTypeConfigs.size() < availableDeviceTypes.size())
  19443. lastDeviceTypeConfigs.add (new AudioDeviceSetup());
  19444. if (availableDeviceTypes.size() > 0)
  19445. currentDeviceType = availableDeviceTypes.getUnchecked(0)->getTypeName();
  19446. }
  19447. }
  19448. const OwnedArray <AudioIODeviceType>& AudioDeviceManager::getAvailableDeviceTypes()
  19449. {
  19450. scanDevicesIfNeeded();
  19451. return availableDeviceTypes;
  19452. }
  19453. AudioIODeviceType* juce_createAudioIODeviceType_CoreAudio();
  19454. AudioIODeviceType* juce_createAudioIODeviceType_iPhoneAudio();
  19455. AudioIODeviceType* juce_createAudioIODeviceType_WASAPI();
  19456. AudioIODeviceType* juce_createAudioIODeviceType_DirectSound();
  19457. AudioIODeviceType* juce_createAudioIODeviceType_ASIO();
  19458. AudioIODeviceType* juce_createAudioIODeviceType_ALSA();
  19459. AudioIODeviceType* juce_createAudioIODeviceType_JACK();
  19460. void AudioDeviceManager::createAudioDeviceTypes (OwnedArray <AudioIODeviceType>& list)
  19461. {
  19462. #if JUCE_WINDOWS
  19463. #if JUCE_WASAPI
  19464. if (SystemStats::getOperatingSystemType() >= SystemStats::WinVista)
  19465. list.add (juce_createAudioIODeviceType_WASAPI());
  19466. #endif
  19467. #if JUCE_DIRECTSOUND
  19468. list.add (juce_createAudioIODeviceType_DirectSound());
  19469. #endif
  19470. #if JUCE_ASIO
  19471. list.add (juce_createAudioIODeviceType_ASIO());
  19472. #endif
  19473. #endif
  19474. #if JUCE_MAC
  19475. list.add (juce_createAudioIODeviceType_CoreAudio());
  19476. #endif
  19477. #if JUCE_IPHONE
  19478. list.add (juce_createAudioIODeviceType_iPhoneAudio());
  19479. #endif
  19480. #if JUCE_LINUX && JUCE_ALSA
  19481. list.add (juce_createAudioIODeviceType_ALSA());
  19482. #endif
  19483. #if JUCE_LINUX && JUCE_JACK
  19484. list.add (juce_createAudioIODeviceType_JACK());
  19485. #endif
  19486. }
  19487. const String AudioDeviceManager::initialise (const int numInputChannelsNeeded,
  19488. const int numOutputChannelsNeeded,
  19489. const XmlElement* const e,
  19490. const bool selectDefaultDeviceOnFailure,
  19491. const String& preferredDefaultDeviceName,
  19492. const AudioDeviceSetup* preferredSetupOptions)
  19493. {
  19494. scanDevicesIfNeeded();
  19495. numInputChansNeeded = numInputChannelsNeeded;
  19496. numOutputChansNeeded = numOutputChannelsNeeded;
  19497. if (e != 0 && e->hasTagName (T("DEVICESETUP")))
  19498. {
  19499. lastExplicitSettings = new XmlElement (*e);
  19500. String error;
  19501. AudioDeviceSetup setup;
  19502. if (preferredSetupOptions != 0)
  19503. setup = *preferredSetupOptions;
  19504. if (e->getStringAttribute (T("audioDeviceName")).isNotEmpty())
  19505. {
  19506. setup.inputDeviceName = setup.outputDeviceName
  19507. = e->getStringAttribute (T("audioDeviceName"));
  19508. }
  19509. else
  19510. {
  19511. setup.inputDeviceName = e->getStringAttribute (T("audioInputDeviceName"));
  19512. setup.outputDeviceName = e->getStringAttribute (T("audioOutputDeviceName"));
  19513. }
  19514. currentDeviceType = e->getStringAttribute (T("deviceType"));
  19515. if (currentDeviceType.isEmpty())
  19516. {
  19517. AudioIODeviceType* const type = findType (setup.inputDeviceName, setup.outputDeviceName);
  19518. if (type != 0)
  19519. currentDeviceType = type->getTypeName();
  19520. else if (availableDeviceTypes.size() > 0)
  19521. currentDeviceType = availableDeviceTypes[0]->getTypeName();
  19522. }
  19523. setup.bufferSize = e->getIntAttribute (T("audioDeviceBufferSize"));
  19524. setup.sampleRate = e->getDoubleAttribute (T("audioDeviceRate"));
  19525. setup.inputChannels.parseString (e->getStringAttribute (T("audioDeviceInChans"), T("11")), 2);
  19526. setup.outputChannels.parseString (e->getStringAttribute (T("audioDeviceOutChans"), T("11")), 2);
  19527. setup.useDefaultInputChannels = ! e->hasAttribute (T("audioDeviceInChans"));
  19528. setup.useDefaultOutputChannels = ! e->hasAttribute (T("audioDeviceOutChans"));
  19529. error = setAudioDeviceSetup (setup, true);
  19530. midiInsFromXml.clear();
  19531. forEachXmlChildElementWithTagName (*e, c, T("MIDIINPUT"))
  19532. midiInsFromXml.add (c->getStringAttribute (T("name")));
  19533. const StringArray allMidiIns (MidiInput::getDevices());
  19534. for (int i = allMidiIns.size(); --i >= 0;)
  19535. setMidiInputEnabled (allMidiIns[i], midiInsFromXml.contains (allMidiIns[i]));
  19536. if (error.isNotEmpty() && selectDefaultDeviceOnFailure)
  19537. error = initialise (numInputChannelsNeeded, numOutputChannelsNeeded, 0,
  19538. false, preferredDefaultDeviceName);
  19539. setDefaultMidiOutput (e->getStringAttribute (T("defaultMidiOutput")));
  19540. return error;
  19541. }
  19542. else
  19543. {
  19544. AudioDeviceSetup setup;
  19545. if (preferredSetupOptions != 0)
  19546. {
  19547. setup = *preferredSetupOptions;
  19548. }
  19549. else if (preferredDefaultDeviceName.isNotEmpty())
  19550. {
  19551. for (int j = availableDeviceTypes.size(); --j >= 0;)
  19552. {
  19553. AudioIODeviceType* const type = availableDeviceTypes.getUnchecked(j);
  19554. StringArray outs (type->getDeviceNames (false));
  19555. int i;
  19556. for (i = 0; i < outs.size(); ++i)
  19557. {
  19558. if (outs[i].matchesWildcard (preferredDefaultDeviceName, true))
  19559. {
  19560. setup.outputDeviceName = outs[i];
  19561. break;
  19562. }
  19563. }
  19564. StringArray ins (type->getDeviceNames (true));
  19565. for (i = 0; i < ins.size(); ++i)
  19566. {
  19567. if (ins[i].matchesWildcard (preferredDefaultDeviceName, true))
  19568. {
  19569. setup.inputDeviceName = ins[i];
  19570. break;
  19571. }
  19572. }
  19573. }
  19574. }
  19575. insertDefaultDeviceNames (setup);
  19576. return setAudioDeviceSetup (setup, false);
  19577. }
  19578. }
  19579. void AudioDeviceManager::insertDefaultDeviceNames (AudioDeviceSetup& setup) const
  19580. {
  19581. AudioIODeviceType* type = getCurrentDeviceTypeObject();
  19582. if (type != 0)
  19583. {
  19584. if (setup.outputDeviceName.isEmpty())
  19585. setup.outputDeviceName = type->getDeviceNames (false) [type->getDefaultDeviceIndex (false)];
  19586. if (setup.inputDeviceName.isEmpty())
  19587. setup.inputDeviceName = type->getDeviceNames (true) [type->getDefaultDeviceIndex (true)];
  19588. }
  19589. }
  19590. XmlElement* AudioDeviceManager::createStateXml() const
  19591. {
  19592. return lastExplicitSettings != 0 ? new XmlElement (*lastExplicitSettings) : 0;
  19593. }
  19594. void AudioDeviceManager::scanDevicesIfNeeded()
  19595. {
  19596. if (listNeedsScanning)
  19597. {
  19598. listNeedsScanning = false;
  19599. createDeviceTypesIfNeeded();
  19600. for (int i = availableDeviceTypes.size(); --i >= 0;)
  19601. availableDeviceTypes.getUnchecked(i)->scanForDevices();
  19602. }
  19603. }
  19604. AudioIODeviceType* AudioDeviceManager::findType (const String& inputName, const String& outputName)
  19605. {
  19606. scanDevicesIfNeeded();
  19607. for (int i = availableDeviceTypes.size(); --i >= 0;)
  19608. {
  19609. AudioIODeviceType* const type = availableDeviceTypes.getUnchecked(i);
  19610. if ((inputName.isNotEmpty() && type->getDeviceNames (true).contains (inputName, true))
  19611. || (outputName.isNotEmpty() && type->getDeviceNames (false).contains (outputName, true)))
  19612. {
  19613. return type;
  19614. }
  19615. }
  19616. return 0;
  19617. }
  19618. void AudioDeviceManager::getAudioDeviceSetup (AudioDeviceSetup& setup)
  19619. {
  19620. setup = currentSetup;
  19621. }
  19622. void AudioDeviceManager::deleteCurrentDevice()
  19623. {
  19624. currentAudioDevice = 0;
  19625. currentSetup.inputDeviceName = String::empty;
  19626. currentSetup.outputDeviceName = String::empty;
  19627. }
  19628. void AudioDeviceManager::setCurrentAudioDeviceType (const String& type,
  19629. const bool treatAsChosenDevice)
  19630. {
  19631. for (int i = 0; i < availableDeviceTypes.size(); ++i)
  19632. {
  19633. if (availableDeviceTypes.getUnchecked(i)->getTypeName() == type
  19634. && currentDeviceType != type)
  19635. {
  19636. currentDeviceType = type;
  19637. AudioDeviceSetup s (*lastDeviceTypeConfigs.getUnchecked(i));
  19638. insertDefaultDeviceNames (s);
  19639. setAudioDeviceSetup (s, treatAsChosenDevice);
  19640. sendChangeMessage (this);
  19641. break;
  19642. }
  19643. }
  19644. }
  19645. AudioIODeviceType* AudioDeviceManager::getCurrentDeviceTypeObject() const
  19646. {
  19647. for (int i = 0; i < availableDeviceTypes.size(); ++i)
  19648. if (availableDeviceTypes[i]->getTypeName() == currentDeviceType)
  19649. return availableDeviceTypes[i];
  19650. return availableDeviceTypes[0];
  19651. }
  19652. const String AudioDeviceManager::setAudioDeviceSetup (const AudioDeviceSetup& newSetup,
  19653. const bool treatAsChosenDevice)
  19654. {
  19655. jassert (&newSetup != &currentSetup); // this will have no effect
  19656. if (newSetup == currentSetup && currentAudioDevice != 0)
  19657. return String::empty;
  19658. if (! (newSetup == currentSetup))
  19659. sendChangeMessage (this);
  19660. stopDevice();
  19661. const String newInputDeviceName (numInputChansNeeded == 0 ? String::empty : newSetup.inputDeviceName);
  19662. const String newOutputDeviceName (numOutputChansNeeded == 0 ? String::empty : newSetup.outputDeviceName);
  19663. String error;
  19664. AudioIODeviceType* type = getCurrentDeviceTypeObject();
  19665. if (type == 0 || (newInputDeviceName.isEmpty() && newOutputDeviceName.isEmpty()))
  19666. {
  19667. deleteCurrentDevice();
  19668. if (treatAsChosenDevice)
  19669. updateXml();
  19670. return String::empty;
  19671. }
  19672. if (currentSetup.inputDeviceName != newInputDeviceName
  19673. || currentSetup.outputDeviceName != newOutputDeviceName
  19674. || currentAudioDevice == 0)
  19675. {
  19676. deleteCurrentDevice();
  19677. scanDevicesIfNeeded();
  19678. if (newOutputDeviceName.isNotEmpty()
  19679. && ! type->getDeviceNames (false).contains (newOutputDeviceName))
  19680. {
  19681. return "No such device: " + newOutputDeviceName;
  19682. }
  19683. if (newInputDeviceName.isNotEmpty()
  19684. && ! type->getDeviceNames (true).contains (newInputDeviceName))
  19685. {
  19686. return "No such device: " + newInputDeviceName;
  19687. }
  19688. currentAudioDevice = type->createDevice (newOutputDeviceName, newInputDeviceName);
  19689. if (currentAudioDevice == 0)
  19690. 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!";
  19691. else
  19692. error = currentAudioDevice->getLastError();
  19693. if (error.isNotEmpty())
  19694. {
  19695. deleteCurrentDevice();
  19696. return error;
  19697. }
  19698. if (newSetup.useDefaultInputChannels)
  19699. {
  19700. inputChannels.clear();
  19701. inputChannels.setRange (0, numInputChansNeeded, true);
  19702. }
  19703. if (newSetup.useDefaultOutputChannels)
  19704. {
  19705. outputChannels.clear();
  19706. outputChannels.setRange (0, numOutputChansNeeded, true);
  19707. }
  19708. if (newInputDeviceName.isEmpty())
  19709. inputChannels.clear();
  19710. if (newOutputDeviceName.isEmpty())
  19711. outputChannels.clear();
  19712. }
  19713. if (! newSetup.useDefaultInputChannels)
  19714. inputChannels = newSetup.inputChannels;
  19715. if (! newSetup.useDefaultOutputChannels)
  19716. outputChannels = newSetup.outputChannels;
  19717. currentSetup = newSetup;
  19718. currentSetup.sampleRate = chooseBestSampleRate (newSetup.sampleRate);
  19719. error = currentAudioDevice->open (inputChannels,
  19720. outputChannels,
  19721. currentSetup.sampleRate,
  19722. currentSetup.bufferSize);
  19723. if (error.isEmpty())
  19724. {
  19725. currentDeviceType = currentAudioDevice->getTypeName();
  19726. currentAudioDevice->start (&callbackHandler);
  19727. currentSetup.sampleRate = currentAudioDevice->getCurrentSampleRate();
  19728. currentSetup.bufferSize = currentAudioDevice->getCurrentBufferSizeSamples();
  19729. currentSetup.inputChannels = currentAudioDevice->getActiveInputChannels();
  19730. currentSetup.outputChannels = currentAudioDevice->getActiveOutputChannels();
  19731. for (int i = 0; i < availableDeviceTypes.size(); ++i)
  19732. if (availableDeviceTypes.getUnchecked (i)->getTypeName() == currentDeviceType)
  19733. *(lastDeviceTypeConfigs.getUnchecked (i)) = currentSetup;
  19734. if (treatAsChosenDevice)
  19735. updateXml();
  19736. }
  19737. else
  19738. {
  19739. deleteCurrentDevice();
  19740. }
  19741. return error;
  19742. }
  19743. double AudioDeviceManager::chooseBestSampleRate (double rate) const
  19744. {
  19745. jassert (currentAudioDevice != 0);
  19746. if (rate > 0)
  19747. {
  19748. bool ok = false;
  19749. for (int i = currentAudioDevice->getNumSampleRates(); --i >= 0;)
  19750. {
  19751. const double sr = currentAudioDevice->getSampleRate (i);
  19752. if (sr == rate)
  19753. ok = true;
  19754. }
  19755. if (! ok)
  19756. rate = 0;
  19757. }
  19758. if (rate == 0)
  19759. {
  19760. double lowestAbove44 = 0.0;
  19761. for (int i = currentAudioDevice->getNumSampleRates(); --i >= 0;)
  19762. {
  19763. const double sr = currentAudioDevice->getSampleRate (i);
  19764. if (sr >= 44100.0 && (lowestAbove44 == 0 || sr < lowestAbove44))
  19765. lowestAbove44 = sr;
  19766. }
  19767. if (lowestAbove44 == 0.0)
  19768. rate = currentAudioDevice->getSampleRate (0);
  19769. else
  19770. rate = lowestAbove44;
  19771. }
  19772. return rate;
  19773. }
  19774. void AudioDeviceManager::stopDevice()
  19775. {
  19776. if (currentAudioDevice != 0)
  19777. currentAudioDevice->stop();
  19778. testSound = 0;
  19779. }
  19780. void AudioDeviceManager::closeAudioDevice()
  19781. {
  19782. stopDevice();
  19783. currentAudioDevice = 0;
  19784. }
  19785. void AudioDeviceManager::restartLastAudioDevice()
  19786. {
  19787. if (currentAudioDevice == 0)
  19788. {
  19789. if (currentSetup.inputDeviceName.isEmpty()
  19790. && currentSetup.outputDeviceName.isEmpty())
  19791. {
  19792. // This method will only reload the last device that was running
  19793. // before closeAudioDevice() was called - you need to actually open
  19794. // one first, with setAudioDevice().
  19795. jassertfalse
  19796. return;
  19797. }
  19798. AudioDeviceSetup s (currentSetup);
  19799. setAudioDeviceSetup (s, false);
  19800. }
  19801. }
  19802. void AudioDeviceManager::updateXml()
  19803. {
  19804. lastExplicitSettings = new XmlElement ("DEVICESETUP");
  19805. lastExplicitSettings->setAttribute ("deviceType", currentDeviceType);
  19806. lastExplicitSettings->setAttribute ("audioOutputDeviceName", currentSetup.outputDeviceName);
  19807. lastExplicitSettings->setAttribute ("audioInputDeviceName", currentSetup.inputDeviceName);
  19808. if (currentAudioDevice != 0)
  19809. {
  19810. lastExplicitSettings->setAttribute ("audioDeviceRate", currentAudioDevice->getCurrentSampleRate());
  19811. if (currentAudioDevice->getDefaultBufferSize() != currentAudioDevice->getCurrentBufferSizeSamples())
  19812. lastExplicitSettings->setAttribute ("audioDeviceBufferSize", currentAudioDevice->getCurrentBufferSizeSamples());
  19813. if (! currentSetup.useDefaultInputChannels)
  19814. lastExplicitSettings->setAttribute ("audioDeviceInChans", currentSetup.inputChannels.toString (2));
  19815. if (! currentSetup.useDefaultOutputChannels)
  19816. lastExplicitSettings->setAttribute ("audioDeviceOutChans", currentSetup.outputChannels.toString (2));
  19817. }
  19818. for (int i = 0; i < enabledMidiInputs.size(); ++i)
  19819. {
  19820. XmlElement* const m = lastExplicitSettings->createNewChildElement ("MIDIINPUT");
  19821. m->setAttribute ("name", enabledMidiInputs[i]->getName());
  19822. }
  19823. if (midiInsFromXml.size() > 0)
  19824. {
  19825. // Add any midi devices that have been enabled before, but which aren't currently
  19826. // open because the device has been disconnected.
  19827. const StringArray availableMidiDevices (MidiInput::getDevices());
  19828. for (int i = 0; i < midiInsFromXml.size(); ++i)
  19829. {
  19830. if (! availableMidiDevices.contains (midiInsFromXml[i], true))
  19831. {
  19832. XmlElement* const m = lastExplicitSettings->createNewChildElement ("MIDIINPUT");
  19833. m->setAttribute ("name", midiInsFromXml[i]);
  19834. }
  19835. }
  19836. }
  19837. if (defaultMidiOutputName.isNotEmpty())
  19838. lastExplicitSettings->setAttribute ("defaultMidiOutput", defaultMidiOutputName);
  19839. }
  19840. void AudioDeviceManager::addAudioCallback (AudioIODeviceCallback* newCallback)
  19841. {
  19842. {
  19843. const ScopedLock sl (audioCallbackLock);
  19844. if (callbacks.contains (newCallback))
  19845. return;
  19846. }
  19847. if (currentAudioDevice != 0 && newCallback != 0)
  19848. newCallback->audioDeviceAboutToStart (currentAudioDevice);
  19849. const ScopedLock sl (audioCallbackLock);
  19850. callbacks.add (newCallback);
  19851. }
  19852. void AudioDeviceManager::removeAudioCallback (AudioIODeviceCallback* callback)
  19853. {
  19854. if (callback != 0)
  19855. {
  19856. bool needsDeinitialising = currentAudioDevice != 0;
  19857. {
  19858. const ScopedLock sl (audioCallbackLock);
  19859. needsDeinitialising = needsDeinitialising && callbacks.contains (callback);
  19860. callbacks.removeValue (callback);
  19861. }
  19862. if (needsDeinitialising)
  19863. callback->audioDeviceStopped();
  19864. }
  19865. }
  19866. void AudioDeviceManager::audioDeviceIOCallbackInt (const float** inputChannelData,
  19867. int numInputChannels,
  19868. float** outputChannelData,
  19869. int numOutputChannels,
  19870. int numSamples)
  19871. {
  19872. const ScopedLock sl (audioCallbackLock);
  19873. if (inputLevelMeasurementEnabledCount > 0)
  19874. {
  19875. for (int j = 0; j < numSamples; ++j)
  19876. {
  19877. float s = 0;
  19878. for (int i = 0; i < numInputChannels; ++i)
  19879. s += fabsf (inputChannelData[i][j]);
  19880. s /= numInputChannels;
  19881. const double decayFactor = 0.99992;
  19882. if (s > inputLevel)
  19883. inputLevel = s;
  19884. else if (inputLevel > 0.001f)
  19885. inputLevel *= decayFactor;
  19886. else
  19887. inputLevel = 0;
  19888. }
  19889. }
  19890. if (callbacks.size() > 0)
  19891. {
  19892. const double callbackStartTime = Time::getMillisecondCounterHiRes();
  19893. tempBuffer.setSize (jmax (1, numOutputChannels), jmax (1, numSamples), false, false, true);
  19894. callbacks.getUnchecked(0)->audioDeviceIOCallback (inputChannelData, numInputChannels,
  19895. outputChannelData, numOutputChannels, numSamples);
  19896. float** const tempChans = tempBuffer.getArrayOfChannels();
  19897. for (int i = callbacks.size(); --i > 0;)
  19898. {
  19899. callbacks.getUnchecked(i)->audioDeviceIOCallback (inputChannelData, numInputChannels,
  19900. tempChans, numOutputChannels, numSamples);
  19901. for (int chan = 0; chan < numOutputChannels; ++chan)
  19902. {
  19903. const float* const src = tempChans [chan];
  19904. float* const dst = outputChannelData [chan];
  19905. if (src != 0 && dst != 0)
  19906. for (int j = 0; j < numSamples; ++j)
  19907. dst[j] += src[j];
  19908. }
  19909. }
  19910. const double msTaken = Time::getMillisecondCounterHiRes() - callbackStartTime;
  19911. const double filterAmount = 0.2;
  19912. cpuUsageMs += filterAmount * (msTaken - cpuUsageMs);
  19913. }
  19914. else
  19915. {
  19916. for (int i = 0; i < numOutputChannels; ++i)
  19917. zeromem (outputChannelData[i], sizeof (float) * numSamples);
  19918. }
  19919. if (testSound != 0)
  19920. {
  19921. const int numSamps = jmin (numSamples, testSound->getNumSamples() - testSoundPosition);
  19922. const float* const src = testSound->getSampleData (0, testSoundPosition);
  19923. for (int i = 0; i < numOutputChannels; ++i)
  19924. for (int j = 0; j < numSamps; ++j)
  19925. outputChannelData [i][j] += src[j];
  19926. testSoundPosition += numSamps;
  19927. if (testSoundPosition >= testSound->getNumSamples())
  19928. testSound = 0;
  19929. }
  19930. }
  19931. void AudioDeviceManager::audioDeviceAboutToStartInt (AudioIODevice* const device)
  19932. {
  19933. cpuUsageMs = 0;
  19934. const double sampleRate = device->getCurrentSampleRate();
  19935. const int blockSize = device->getCurrentBufferSizeSamples();
  19936. if (sampleRate > 0.0 && blockSize > 0)
  19937. {
  19938. const double msPerBlock = 1000.0 * blockSize / sampleRate;
  19939. timeToCpuScale = (msPerBlock > 0.0) ? (1.0 / msPerBlock) : 0.0;
  19940. }
  19941. {
  19942. const ScopedLock sl (audioCallbackLock);
  19943. for (int i = callbacks.size(); --i >= 0;)
  19944. callbacks.getUnchecked(i)->audioDeviceAboutToStart (device);
  19945. }
  19946. sendChangeMessage (this);
  19947. }
  19948. void AudioDeviceManager::audioDeviceStoppedInt()
  19949. {
  19950. cpuUsageMs = 0;
  19951. timeToCpuScale = 0;
  19952. sendChangeMessage (this);
  19953. const ScopedLock sl (audioCallbackLock);
  19954. for (int i = callbacks.size(); --i >= 0;)
  19955. callbacks.getUnchecked(i)->audioDeviceStopped();
  19956. }
  19957. double AudioDeviceManager::getCpuUsage() const
  19958. {
  19959. return jlimit (0.0, 1.0, timeToCpuScale * cpuUsageMs);
  19960. }
  19961. void AudioDeviceManager::setMidiInputEnabled (const String& name,
  19962. const bool enabled)
  19963. {
  19964. if (enabled != isMidiInputEnabled (name))
  19965. {
  19966. if (enabled)
  19967. {
  19968. const int index = MidiInput::getDevices().indexOf (name);
  19969. if (index >= 0)
  19970. {
  19971. MidiInput* const min = MidiInput::openDevice (index, &callbackHandler);
  19972. if (min != 0)
  19973. {
  19974. enabledMidiInputs.add (min);
  19975. min->start();
  19976. }
  19977. }
  19978. }
  19979. else
  19980. {
  19981. for (int i = enabledMidiInputs.size(); --i >= 0;)
  19982. if (enabledMidiInputs[i]->getName() == name)
  19983. enabledMidiInputs.remove (i);
  19984. }
  19985. updateXml();
  19986. sendChangeMessage (this);
  19987. }
  19988. }
  19989. bool AudioDeviceManager::isMidiInputEnabled (const String& name) const
  19990. {
  19991. for (int i = enabledMidiInputs.size(); --i >= 0;)
  19992. if (enabledMidiInputs[i]->getName() == name)
  19993. return true;
  19994. return false;
  19995. }
  19996. void AudioDeviceManager::addMidiInputCallback (const String& name,
  19997. MidiInputCallback* callback)
  19998. {
  19999. removeMidiInputCallback (name, callback);
  20000. if (name.isEmpty())
  20001. {
  20002. midiCallbacks.add (callback);
  20003. midiCallbackDevices.add (0);
  20004. }
  20005. else
  20006. {
  20007. for (int i = enabledMidiInputs.size(); --i >= 0;)
  20008. {
  20009. if (enabledMidiInputs[i]->getName() == name)
  20010. {
  20011. const ScopedLock sl (midiCallbackLock);
  20012. midiCallbacks.add (callback);
  20013. midiCallbackDevices.add (enabledMidiInputs[i]);
  20014. break;
  20015. }
  20016. }
  20017. }
  20018. }
  20019. void AudioDeviceManager::removeMidiInputCallback (const String& name,
  20020. MidiInputCallback* /*callback*/)
  20021. {
  20022. const ScopedLock sl (midiCallbackLock);
  20023. for (int i = midiCallbacks.size(); --i >= 0;)
  20024. {
  20025. String devName;
  20026. if (midiCallbackDevices.getUnchecked(i) != 0)
  20027. devName = midiCallbackDevices.getUnchecked(i)->getName();
  20028. if (devName == name)
  20029. {
  20030. midiCallbacks.remove (i);
  20031. midiCallbackDevices.remove (i);
  20032. }
  20033. }
  20034. }
  20035. void AudioDeviceManager::handleIncomingMidiMessageInt (MidiInput* source,
  20036. const MidiMessage& message)
  20037. {
  20038. if (! message.isActiveSense())
  20039. {
  20040. const bool isDefaultSource = (source == 0 || source == enabledMidiInputs.getFirst());
  20041. const ScopedLock sl (midiCallbackLock);
  20042. for (int i = midiCallbackDevices.size(); --i >= 0;)
  20043. {
  20044. MidiInput* const md = midiCallbackDevices.getUnchecked(i);
  20045. if (md == source || (md == 0 && isDefaultSource))
  20046. midiCallbacks.getUnchecked(i)->handleIncomingMidiMessage (source, message);
  20047. }
  20048. }
  20049. }
  20050. void AudioDeviceManager::setDefaultMidiOutput (const String& deviceName)
  20051. {
  20052. if (defaultMidiOutputName != deviceName)
  20053. {
  20054. SortedSet <AudioIODeviceCallback*> oldCallbacks;
  20055. {
  20056. const ScopedLock sl (audioCallbackLock);
  20057. oldCallbacks = callbacks;
  20058. callbacks.clear();
  20059. }
  20060. if (currentAudioDevice != 0)
  20061. for (int i = oldCallbacks.size(); --i >= 0;)
  20062. oldCallbacks.getUnchecked(i)->audioDeviceStopped();
  20063. defaultMidiOutput = 0;
  20064. defaultMidiOutputName = deviceName;
  20065. if (deviceName.isNotEmpty())
  20066. defaultMidiOutput = MidiOutput::openDevice (MidiOutput::getDevices().indexOf (deviceName));
  20067. if (currentAudioDevice != 0)
  20068. for (int i = oldCallbacks.size(); --i >= 0;)
  20069. oldCallbacks.getUnchecked(i)->audioDeviceAboutToStart (currentAudioDevice);
  20070. {
  20071. const ScopedLock sl (audioCallbackLock);
  20072. callbacks = oldCallbacks;
  20073. }
  20074. updateXml();
  20075. sendChangeMessage (this);
  20076. }
  20077. }
  20078. void AudioDeviceManager::CallbackHandler::audioDeviceIOCallback (const float** inputChannelData,
  20079. int numInputChannels,
  20080. float** outputChannelData,
  20081. int numOutputChannels,
  20082. int numSamples)
  20083. {
  20084. owner->audioDeviceIOCallbackInt (inputChannelData, numInputChannels, outputChannelData, numOutputChannels, numSamples);
  20085. }
  20086. void AudioDeviceManager::CallbackHandler::audioDeviceAboutToStart (AudioIODevice* device)
  20087. {
  20088. owner->audioDeviceAboutToStartInt (device);
  20089. }
  20090. void AudioDeviceManager::CallbackHandler::audioDeviceStopped()
  20091. {
  20092. owner->audioDeviceStoppedInt();
  20093. }
  20094. void AudioDeviceManager::CallbackHandler::handleIncomingMidiMessage (MidiInput* source, const MidiMessage& message)
  20095. {
  20096. owner->handleIncomingMidiMessageInt (source, message);
  20097. }
  20098. void AudioDeviceManager::playTestSound()
  20099. {
  20100. {
  20101. audioCallbackLock.enter();
  20102. ScopedPointer <AudioSampleBuffer> oldSound (testSound);
  20103. audioCallbackLock.exit();
  20104. }
  20105. testSoundPosition = 0;
  20106. if (currentAudioDevice != 0)
  20107. {
  20108. const double sampleRate = currentAudioDevice->getCurrentSampleRate();
  20109. const int soundLength = (int) sampleRate;
  20110. AudioSampleBuffer* const newSound = new AudioSampleBuffer (1, soundLength);
  20111. float* samples = newSound->getSampleData (0);
  20112. const double frequency = MidiMessage::getMidiNoteInHertz (80);
  20113. const float amplitude = 0.5f;
  20114. const double phasePerSample = double_Pi * 2.0 / (sampleRate / frequency);
  20115. for (int i = 0; i < soundLength; ++i)
  20116. samples[i] = amplitude * (float) sin (i * phasePerSample);
  20117. newSound->applyGainRamp (0, 0, soundLength / 10, 0.0f, 1.0f);
  20118. newSound->applyGainRamp (0, soundLength - soundLength / 4, soundLength / 4, 1.0f, 0.0f);
  20119. const ScopedLock sl (audioCallbackLock);
  20120. testSound = newSound;
  20121. }
  20122. }
  20123. void AudioDeviceManager::enableInputLevelMeasurement (const bool enableMeasurement)
  20124. {
  20125. const ScopedLock sl (audioCallbackLock);
  20126. if (enableMeasurement)
  20127. ++inputLevelMeasurementEnabledCount;
  20128. else
  20129. --inputLevelMeasurementEnabledCount;
  20130. inputLevel = 0;
  20131. }
  20132. double AudioDeviceManager::getCurrentInputLevel() const
  20133. {
  20134. jassert (inputLevelMeasurementEnabledCount > 0); // you need to call enableInputLevelMeasurement() before using this!
  20135. return inputLevel;
  20136. }
  20137. END_JUCE_NAMESPACE
  20138. /*** End of inlined file: juce_AudioDeviceManager.cpp ***/
  20139. /*** Start of inlined file: juce_AudioIODevice.cpp ***/
  20140. BEGIN_JUCE_NAMESPACE
  20141. AudioIODevice::AudioIODevice (const String& deviceName, const String& typeName_)
  20142. : name (deviceName),
  20143. typeName (typeName_)
  20144. {
  20145. }
  20146. AudioIODevice::~AudioIODevice()
  20147. {
  20148. }
  20149. bool AudioIODevice::hasControlPanel() const
  20150. {
  20151. return false;
  20152. }
  20153. bool AudioIODevice::showControlPanel()
  20154. {
  20155. jassertfalse // this should only be called for devices which return true from
  20156. // their hasControlPanel() method.
  20157. return false;
  20158. }
  20159. END_JUCE_NAMESPACE
  20160. /*** End of inlined file: juce_AudioIODevice.cpp ***/
  20161. /*** Start of inlined file: juce_AudioIODeviceType.cpp ***/
  20162. BEGIN_JUCE_NAMESPACE
  20163. AudioIODeviceType::AudioIODeviceType (const tchar* const name)
  20164. : typeName (name)
  20165. {
  20166. }
  20167. AudioIODeviceType::~AudioIODeviceType()
  20168. {
  20169. }
  20170. END_JUCE_NAMESPACE
  20171. /*** End of inlined file: juce_AudioIODeviceType.cpp ***/
  20172. /*** Start of inlined file: juce_MidiOutput.cpp ***/
  20173. BEGIN_JUCE_NAMESPACE
  20174. MidiOutput::MidiOutput() throw()
  20175. : Thread ("midi out"),
  20176. internal (0),
  20177. firstMessage (0)
  20178. {
  20179. }
  20180. MidiOutput::PendingMessage::PendingMessage (const uint8* const data,
  20181. const int len,
  20182. const double sampleNumber) throw()
  20183. : message (data, len, sampleNumber)
  20184. {
  20185. }
  20186. void MidiOutput::sendBlockOfMessages (const MidiBuffer& buffer,
  20187. const double millisecondCounterToStartAt,
  20188. double samplesPerSecondForBuffer) throw()
  20189. {
  20190. // You've got to call startBackgroundThread() for this to actually work..
  20191. jassert (isThreadRunning());
  20192. // this needs to be a value in the future - RTFM for this method!
  20193. jassert (millisecondCounterToStartAt > 0);
  20194. const double timeScaleFactor = 1000.0 / samplesPerSecondForBuffer;
  20195. MidiBuffer::Iterator i (buffer);
  20196. const uint8* data;
  20197. int len, time;
  20198. while (i.getNextEvent (data, len, time))
  20199. {
  20200. const double eventTime = millisecondCounterToStartAt + timeScaleFactor * time;
  20201. PendingMessage* const m
  20202. = new PendingMessage (data, len, eventTime);
  20203. const ScopedLock sl (lock);
  20204. if (firstMessage == 0 || firstMessage->message.getTimeStamp() > eventTime)
  20205. {
  20206. m->next = firstMessage;
  20207. firstMessage = m;
  20208. }
  20209. else
  20210. {
  20211. PendingMessage* mm = firstMessage;
  20212. while (mm->next != 0 && mm->next->message.getTimeStamp() <= eventTime)
  20213. mm = mm->next;
  20214. m->next = mm->next;
  20215. mm->next = m;
  20216. }
  20217. }
  20218. notify();
  20219. }
  20220. void MidiOutput::clearAllPendingMessages() throw()
  20221. {
  20222. const ScopedLock sl (lock);
  20223. while (firstMessage != 0)
  20224. {
  20225. PendingMessage* const m = firstMessage;
  20226. firstMessage = firstMessage->next;
  20227. delete m;
  20228. }
  20229. }
  20230. void MidiOutput::startBackgroundThread() throw()
  20231. {
  20232. startThread (9);
  20233. }
  20234. void MidiOutput::stopBackgroundThread() throw()
  20235. {
  20236. stopThread (5000);
  20237. }
  20238. void MidiOutput::run()
  20239. {
  20240. while (! threadShouldExit())
  20241. {
  20242. uint32 now = Time::getMillisecondCounter();
  20243. uint32 eventTime = 0;
  20244. uint32 timeToWait = 500;
  20245. lock.enter();
  20246. PendingMessage* message = firstMessage;
  20247. if (message != 0)
  20248. {
  20249. eventTime = roundToInt (message->message.getTimeStamp());
  20250. if (eventTime > now + 20)
  20251. {
  20252. timeToWait = eventTime - (now + 20);
  20253. message = 0;
  20254. }
  20255. else
  20256. {
  20257. firstMessage = message->next;
  20258. }
  20259. }
  20260. lock.exit();
  20261. if (message != 0)
  20262. {
  20263. if (eventTime > now)
  20264. {
  20265. Time::waitForMillisecondCounter (eventTime);
  20266. if (threadShouldExit())
  20267. break;
  20268. }
  20269. if (eventTime > now - 200)
  20270. sendMessageNow (message->message);
  20271. delete message;
  20272. }
  20273. else
  20274. {
  20275. jassert (timeToWait < 1000 * 30);
  20276. wait (timeToWait);
  20277. }
  20278. }
  20279. clearAllPendingMessages();
  20280. }
  20281. END_JUCE_NAMESPACE
  20282. /*** End of inlined file: juce_MidiOutput.cpp ***/
  20283. /*** Start of inlined file: juce_AudioDataConverters.cpp ***/
  20284. BEGIN_JUCE_NAMESPACE
  20285. void AudioDataConverters::convertFloatToInt16LE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20286. {
  20287. const double maxVal = (double) 0x7fff;
  20288. char* intData = (char*) dest;
  20289. if (dest != (void*) source || destBytesPerSample <= 4)
  20290. {
  20291. for (int i = 0; i < numSamples; ++i)
  20292. {
  20293. *(uint16*)intData = ByteOrder::swapIfBigEndian ((uint16) (short) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20294. intData += destBytesPerSample;
  20295. }
  20296. }
  20297. else
  20298. {
  20299. intData += destBytesPerSample * numSamples;
  20300. for (int i = numSamples; --i >= 0;)
  20301. {
  20302. intData -= destBytesPerSample;
  20303. *(uint16*)intData = ByteOrder::swapIfBigEndian ((uint16) (short) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20304. }
  20305. }
  20306. }
  20307. void AudioDataConverters::convertFloatToInt16BE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20308. {
  20309. const double maxVal = (double) 0x7fff;
  20310. char* intData = (char*) dest;
  20311. if (dest != (void*) source || destBytesPerSample <= 4)
  20312. {
  20313. for (int i = 0; i < numSamples; ++i)
  20314. {
  20315. *(uint16*) intData = ByteOrder::swapIfLittleEndian ((uint16) (short) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20316. intData += destBytesPerSample;
  20317. }
  20318. }
  20319. else
  20320. {
  20321. intData += destBytesPerSample * numSamples;
  20322. for (int i = numSamples; --i >= 0;)
  20323. {
  20324. intData -= destBytesPerSample;
  20325. *(uint16*)intData = ByteOrder::swapIfLittleEndian ((uint16) (short) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20326. }
  20327. }
  20328. }
  20329. void AudioDataConverters::convertFloatToInt24LE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20330. {
  20331. const double maxVal = (double) 0x7fffff;
  20332. char* intData = (char*) dest;
  20333. if (dest != (void*) source || destBytesPerSample <= 4)
  20334. {
  20335. for (int i = 0; i < numSamples; ++i)
  20336. {
  20337. ByteOrder::littleEndian24BitToChars ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])), intData);
  20338. intData += destBytesPerSample;
  20339. }
  20340. }
  20341. else
  20342. {
  20343. intData += destBytesPerSample * numSamples;
  20344. for (int i = numSamples; --i >= 0;)
  20345. {
  20346. intData -= destBytesPerSample;
  20347. ByteOrder::littleEndian24BitToChars ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])), intData);
  20348. }
  20349. }
  20350. }
  20351. void AudioDataConverters::convertFloatToInt24BE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20352. {
  20353. const double maxVal = (double) 0x7fffff;
  20354. char* intData = (char*) dest;
  20355. if (dest != (void*) source || destBytesPerSample <= 4)
  20356. {
  20357. for (int i = 0; i < numSamples; ++i)
  20358. {
  20359. ByteOrder::bigEndian24BitToChars ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])), intData);
  20360. intData += destBytesPerSample;
  20361. }
  20362. }
  20363. else
  20364. {
  20365. intData += destBytesPerSample * numSamples;
  20366. for (int i = numSamples; --i >= 0;)
  20367. {
  20368. intData -= destBytesPerSample;
  20369. ByteOrder::bigEndian24BitToChars ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])), intData);
  20370. }
  20371. }
  20372. }
  20373. void AudioDataConverters::convertFloatToInt32LE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20374. {
  20375. const double maxVal = (double) 0x7fffffff;
  20376. char* intData = (char*) dest;
  20377. if (dest != (void*) source || destBytesPerSample <= 4)
  20378. {
  20379. for (int i = 0; i < numSamples; ++i)
  20380. {
  20381. *(uint32*)intData = ByteOrder::swapIfBigEndian ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20382. intData += destBytesPerSample;
  20383. }
  20384. }
  20385. else
  20386. {
  20387. intData += destBytesPerSample * numSamples;
  20388. for (int i = numSamples; --i >= 0;)
  20389. {
  20390. intData -= destBytesPerSample;
  20391. *(uint32*)intData = ByteOrder::swapIfBigEndian ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20392. }
  20393. }
  20394. }
  20395. void AudioDataConverters::convertFloatToInt32BE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20396. {
  20397. const double maxVal = (double) 0x7fffffff;
  20398. char* intData = (char*) dest;
  20399. if (dest != (void*) source || destBytesPerSample <= 4)
  20400. {
  20401. for (int i = 0; i < numSamples; ++i)
  20402. {
  20403. *(uint32*)intData = ByteOrder::swapIfLittleEndian ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20404. intData += destBytesPerSample;
  20405. }
  20406. }
  20407. else
  20408. {
  20409. intData += destBytesPerSample * numSamples;
  20410. for (int i = numSamples; --i >= 0;)
  20411. {
  20412. intData -= destBytesPerSample;
  20413. *(uint32*)intData = ByteOrder::swapIfLittleEndian ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20414. }
  20415. }
  20416. }
  20417. void AudioDataConverters::convertFloatToFloat32LE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20418. {
  20419. jassert (dest != (void*) source || destBytesPerSample <= 4); // This op can't be performed on in-place data!
  20420. char* d = (char*) dest;
  20421. for (int i = 0; i < numSamples; ++i)
  20422. {
  20423. *(float*) d = source[i];
  20424. #if JUCE_BIG_ENDIAN
  20425. *(uint32*) d = ByteOrder::swap (*(uint32*) d);
  20426. #endif
  20427. d += destBytesPerSample;
  20428. }
  20429. }
  20430. void AudioDataConverters::convertFloatToFloat32BE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20431. {
  20432. jassert (dest != (void*) source || destBytesPerSample <= 4); // This op can't be performed on in-place data!
  20433. char* d = (char*) dest;
  20434. for (int i = 0; i < numSamples; ++i)
  20435. {
  20436. *(float*) d = source[i];
  20437. #if JUCE_LITTLE_ENDIAN
  20438. *(uint32*) d = ByteOrder::swap (*(uint32*) d);
  20439. #endif
  20440. d += destBytesPerSample;
  20441. }
  20442. }
  20443. void AudioDataConverters::convertInt16LEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20444. {
  20445. const float scale = 1.0f / 0x7fff;
  20446. const char* intData = (const char*) source;
  20447. if (source != (void*) dest || srcBytesPerSample >= 4)
  20448. {
  20449. for (int i = 0; i < numSamples; ++i)
  20450. {
  20451. dest[i] = scale * (short) ByteOrder::swapIfBigEndian (*(uint16*)intData);
  20452. intData += srcBytesPerSample;
  20453. }
  20454. }
  20455. else
  20456. {
  20457. intData += srcBytesPerSample * numSamples;
  20458. for (int i = numSamples; --i >= 0;)
  20459. {
  20460. intData -= srcBytesPerSample;
  20461. dest[i] = scale * (short) ByteOrder::swapIfBigEndian (*(uint16*)intData);
  20462. }
  20463. }
  20464. }
  20465. void AudioDataConverters::convertInt16BEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20466. {
  20467. const float scale = 1.0f / 0x7fff;
  20468. const char* intData = (const char*) source;
  20469. if (source != (void*) dest || srcBytesPerSample >= 4)
  20470. {
  20471. for (int i = 0; i < numSamples; ++i)
  20472. {
  20473. dest[i] = scale * (short) ByteOrder::swapIfLittleEndian (*(uint16*)intData);
  20474. intData += srcBytesPerSample;
  20475. }
  20476. }
  20477. else
  20478. {
  20479. intData += srcBytesPerSample * numSamples;
  20480. for (int i = numSamples; --i >= 0;)
  20481. {
  20482. intData -= srcBytesPerSample;
  20483. dest[i] = scale * (short) ByteOrder::swapIfLittleEndian (*(uint16*)intData);
  20484. }
  20485. }
  20486. }
  20487. void AudioDataConverters::convertInt24LEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20488. {
  20489. const float scale = 1.0f / 0x7fffff;
  20490. const char* intData = (const char*) source;
  20491. if (source != (void*) dest || srcBytesPerSample >= 4)
  20492. {
  20493. for (int i = 0; i < numSamples; ++i)
  20494. {
  20495. dest[i] = scale * (short) ByteOrder::littleEndian24Bit (intData);
  20496. intData += srcBytesPerSample;
  20497. }
  20498. }
  20499. else
  20500. {
  20501. intData += srcBytesPerSample * numSamples;
  20502. for (int i = numSamples; --i >= 0;)
  20503. {
  20504. intData -= srcBytesPerSample;
  20505. dest[i] = scale * (short) ByteOrder::littleEndian24Bit (intData);
  20506. }
  20507. }
  20508. }
  20509. void AudioDataConverters::convertInt24BEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20510. {
  20511. const float scale = 1.0f / 0x7fffff;
  20512. const char* intData = (const char*) source;
  20513. if (source != (void*) dest || srcBytesPerSample >= 4)
  20514. {
  20515. for (int i = 0; i < numSamples; ++i)
  20516. {
  20517. dest[i] = scale * (short) ByteOrder::bigEndian24Bit (intData);
  20518. intData += srcBytesPerSample;
  20519. }
  20520. }
  20521. else
  20522. {
  20523. intData += srcBytesPerSample * numSamples;
  20524. for (int i = numSamples; --i >= 0;)
  20525. {
  20526. intData -= srcBytesPerSample;
  20527. dest[i] = scale * (short) ByteOrder::bigEndian24Bit (intData);
  20528. }
  20529. }
  20530. }
  20531. void AudioDataConverters::convertInt32LEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20532. {
  20533. const float scale = 1.0f / 0x7fffffff;
  20534. const char* intData = (const char*) source;
  20535. if (source != (void*) dest || srcBytesPerSample >= 4)
  20536. {
  20537. for (int i = 0; i < numSamples; ++i)
  20538. {
  20539. dest[i] = scale * (int) ByteOrder::swapIfBigEndian (*(uint32*) intData);
  20540. intData += srcBytesPerSample;
  20541. }
  20542. }
  20543. else
  20544. {
  20545. intData += srcBytesPerSample * numSamples;
  20546. for (int i = numSamples; --i >= 0;)
  20547. {
  20548. intData -= srcBytesPerSample;
  20549. dest[i] = scale * (int) ByteOrder::swapIfBigEndian (*(uint32*) intData);
  20550. }
  20551. }
  20552. }
  20553. void AudioDataConverters::convertInt32BEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20554. {
  20555. const float scale = 1.0f / 0x7fffffff;
  20556. const char* intData = (const char*) source;
  20557. if (source != (void*) dest || srcBytesPerSample >= 4)
  20558. {
  20559. for (int i = 0; i < numSamples; ++i)
  20560. {
  20561. dest[i] = scale * (int) ByteOrder::swapIfLittleEndian (*(uint32*) intData);
  20562. intData += srcBytesPerSample;
  20563. }
  20564. }
  20565. else
  20566. {
  20567. intData += srcBytesPerSample * numSamples;
  20568. for (int i = numSamples; --i >= 0;)
  20569. {
  20570. intData -= srcBytesPerSample;
  20571. dest[i] = scale * (int) ByteOrder::swapIfLittleEndian (*(uint32*) intData);
  20572. }
  20573. }
  20574. }
  20575. void AudioDataConverters::convertFloat32LEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20576. {
  20577. const char* s = (const char*) source;
  20578. for (int i = 0; i < numSamples; ++i)
  20579. {
  20580. dest[i] = *(float*)s;
  20581. #if JUCE_BIG_ENDIAN
  20582. uint32* const d = (uint32*) (dest + i);
  20583. *d = ByteOrder::swap (*d);
  20584. #endif
  20585. s += srcBytesPerSample;
  20586. }
  20587. }
  20588. void AudioDataConverters::convertFloat32BEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20589. {
  20590. const char* s = (const char*) source;
  20591. for (int i = 0; i < numSamples; ++i)
  20592. {
  20593. dest[i] = *(float*)s;
  20594. #if JUCE_LITTLE_ENDIAN
  20595. uint32* const d = (uint32*) (dest + i);
  20596. *d = ByteOrder::swap (*d);
  20597. #endif
  20598. s += srcBytesPerSample;
  20599. }
  20600. }
  20601. void AudioDataConverters::convertFloatToFormat (const DataFormat destFormat,
  20602. const float* const source,
  20603. void* const dest,
  20604. const int numSamples)
  20605. {
  20606. switch (destFormat)
  20607. {
  20608. case int16LE:
  20609. convertFloatToInt16LE (source, dest, numSamples);
  20610. break;
  20611. case int16BE:
  20612. convertFloatToInt16BE (source, dest, numSamples);
  20613. break;
  20614. case int24LE:
  20615. convertFloatToInt24LE (source, dest, numSamples);
  20616. break;
  20617. case int24BE:
  20618. convertFloatToInt24BE (source, dest, numSamples);
  20619. break;
  20620. case int32LE:
  20621. convertFloatToInt32LE (source, dest, numSamples);
  20622. break;
  20623. case int32BE:
  20624. convertFloatToInt32BE (source, dest, numSamples);
  20625. break;
  20626. case float32LE:
  20627. convertFloatToFloat32LE (source, dest, numSamples);
  20628. break;
  20629. case float32BE:
  20630. convertFloatToFloat32BE (source, dest, numSamples);
  20631. break;
  20632. default:
  20633. jassertfalse
  20634. break;
  20635. }
  20636. }
  20637. void AudioDataConverters::convertFormatToFloat (const DataFormat sourceFormat,
  20638. const void* const source,
  20639. float* const dest,
  20640. const int numSamples)
  20641. {
  20642. switch (sourceFormat)
  20643. {
  20644. case int16LE:
  20645. convertInt16LEToFloat (source, dest, numSamples);
  20646. break;
  20647. case int16BE:
  20648. convertInt16BEToFloat (source, dest, numSamples);
  20649. break;
  20650. case int24LE:
  20651. convertInt24LEToFloat (source, dest, numSamples);
  20652. break;
  20653. case int24BE:
  20654. convertInt24BEToFloat (source, dest, numSamples);
  20655. break;
  20656. case int32LE:
  20657. convertInt32LEToFloat (source, dest, numSamples);
  20658. break;
  20659. case int32BE:
  20660. convertInt32BEToFloat (source, dest, numSamples);
  20661. break;
  20662. case float32LE:
  20663. convertFloat32LEToFloat (source, dest, numSamples);
  20664. break;
  20665. case float32BE:
  20666. convertFloat32BEToFloat (source, dest, numSamples);
  20667. break;
  20668. default:
  20669. jassertfalse
  20670. break;
  20671. }
  20672. }
  20673. void AudioDataConverters::interleaveSamples (const float** const source,
  20674. float* const dest,
  20675. const int numSamples,
  20676. const int numChannels)
  20677. {
  20678. for (int chan = 0; chan < numChannels; ++chan)
  20679. {
  20680. int i = chan;
  20681. const float* src = source [chan];
  20682. for (int j = 0; j < numSamples; ++j)
  20683. {
  20684. dest [i] = src [j];
  20685. i += numChannels;
  20686. }
  20687. }
  20688. }
  20689. void AudioDataConverters::deinterleaveSamples (const float* const source,
  20690. float** const dest,
  20691. const int numSamples,
  20692. const int numChannels)
  20693. {
  20694. for (int chan = 0; chan < numChannels; ++chan)
  20695. {
  20696. int i = chan;
  20697. float* dst = dest [chan];
  20698. for (int j = 0; j < numSamples; ++j)
  20699. {
  20700. dst [j] = source [i];
  20701. i += numChannels;
  20702. }
  20703. }
  20704. }
  20705. END_JUCE_NAMESPACE
  20706. /*** End of inlined file: juce_AudioDataConverters.cpp ***/
  20707. /*** Start of inlined file: juce_AudioSampleBuffer.cpp ***/
  20708. BEGIN_JUCE_NAMESPACE
  20709. AudioSampleBuffer::AudioSampleBuffer (const int numChannels_,
  20710. const int numSamples) throw()
  20711. : numChannels (numChannels_),
  20712. size (numSamples)
  20713. {
  20714. jassert (numSamples >= 0);
  20715. jassert (numChannels_ > 0);
  20716. allocateData();
  20717. }
  20718. AudioSampleBuffer::AudioSampleBuffer (const AudioSampleBuffer& other) throw()
  20719. : numChannels (other.numChannels),
  20720. size (other.size)
  20721. {
  20722. allocateData();
  20723. const size_t numBytes = size * sizeof (float);
  20724. for (int i = 0; i < numChannels; ++i)
  20725. memcpy (channels[i], other.channels[i], numBytes);
  20726. }
  20727. void AudioSampleBuffer::allocateData()
  20728. {
  20729. const size_t channelListSize = (numChannels + 1) * sizeof (float*);
  20730. allocatedBytes = (int) (numChannels * size * sizeof (float) + channelListSize + 32);
  20731. allocatedData.malloc (allocatedBytes);
  20732. channels = (float**) allocatedData;
  20733. float* chan = (float*) (allocatedData + channelListSize);
  20734. for (int i = 0; i < numChannels; ++i)
  20735. {
  20736. channels[i] = chan;
  20737. chan += size;
  20738. }
  20739. channels [numChannels] = 0;
  20740. }
  20741. AudioSampleBuffer::AudioSampleBuffer (float** dataToReferTo,
  20742. const int numChannels_,
  20743. const int numSamples) throw()
  20744. : numChannels (numChannels_),
  20745. size (numSamples),
  20746. allocatedBytes (0)
  20747. {
  20748. jassert (numChannels_ > 0);
  20749. allocateChannels (dataToReferTo);
  20750. }
  20751. void AudioSampleBuffer::setDataToReferTo (float** dataToReferTo,
  20752. const int newNumChannels,
  20753. const int newNumSamples) throw()
  20754. {
  20755. jassert (newNumChannels > 0);
  20756. allocatedBytes = 0;
  20757. allocatedData.free();
  20758. numChannels = newNumChannels;
  20759. size = newNumSamples;
  20760. allocateChannels (dataToReferTo);
  20761. }
  20762. void AudioSampleBuffer::allocateChannels (float** const dataToReferTo)
  20763. {
  20764. // (try to avoid doing a malloc here, as that'll blow up things like Pro-Tools)
  20765. if (numChannels < numElementsInArray (preallocatedChannelSpace))
  20766. {
  20767. channels = (float**) preallocatedChannelSpace;
  20768. }
  20769. else
  20770. {
  20771. allocatedData.malloc (numChannels + 1, sizeof (float*));
  20772. channels = (float**) allocatedData;
  20773. }
  20774. for (int i = 0; i < numChannels; ++i)
  20775. {
  20776. // you have to pass in the same number of valid pointers as numChannels
  20777. jassert (dataToReferTo[i] != 0);
  20778. channels[i] = dataToReferTo[i];
  20779. }
  20780. channels [numChannels] = 0;
  20781. }
  20782. const AudioSampleBuffer& AudioSampleBuffer::operator= (const AudioSampleBuffer& other) throw()
  20783. {
  20784. if (this != &other)
  20785. {
  20786. setSize (other.getNumChannels(), other.getNumSamples(), false, false, false);
  20787. const size_t numBytes = size * sizeof (float);
  20788. for (int i = 0; i < numChannels; ++i)
  20789. memcpy (channels[i], other.channels[i], numBytes);
  20790. }
  20791. return *this;
  20792. }
  20793. AudioSampleBuffer::~AudioSampleBuffer() throw()
  20794. {
  20795. }
  20796. void AudioSampleBuffer::setSize (const int newNumChannels,
  20797. const int newNumSamples,
  20798. const bool keepExistingContent,
  20799. const bool clearExtraSpace,
  20800. const bool avoidReallocating) throw()
  20801. {
  20802. jassert (newNumChannels > 0);
  20803. if (newNumSamples != size || newNumChannels != numChannels)
  20804. {
  20805. const size_t channelListSize = (newNumChannels + 1) * sizeof (float*);
  20806. const size_t newTotalBytes = (newNumChannels * newNumSamples * sizeof (float)) + channelListSize + 32;
  20807. if (keepExistingContent)
  20808. {
  20809. HeapBlock <char> newData;
  20810. newData.allocate (newTotalBytes, clearExtraSpace);
  20811. const int numChansToCopy = jmin (numChannels, newNumChannels);
  20812. const size_t numBytesToCopy = sizeof (float) * jmin (newNumSamples, size);
  20813. float** const newChannels = (float**) newData;
  20814. float* newChan = (float*) (newData + channelListSize);
  20815. for (int i = 0; i < numChansToCopy; ++i)
  20816. {
  20817. memcpy (newChan, channels[i], numBytesToCopy);
  20818. newChannels[i] = newChan;
  20819. newChan += newNumSamples;
  20820. }
  20821. allocatedData.swapWith (newData);
  20822. allocatedBytes = (int) newTotalBytes;
  20823. channels = (float**) allocatedData;
  20824. }
  20825. else
  20826. {
  20827. if (avoidReallocating && allocatedBytes >= newTotalBytes)
  20828. {
  20829. if (clearExtraSpace)
  20830. zeromem (allocatedData, newTotalBytes);
  20831. }
  20832. else
  20833. {
  20834. allocatedBytes = newTotalBytes;
  20835. allocatedData.allocate (newTotalBytes, clearExtraSpace);
  20836. channels = (float**) allocatedData;
  20837. }
  20838. float* chan = (float*) (allocatedData + channelListSize);
  20839. for (int i = 0; i < newNumChannels; ++i)
  20840. {
  20841. channels[i] = chan;
  20842. chan += newNumSamples;
  20843. }
  20844. }
  20845. channels [newNumChannels] = 0;
  20846. size = newNumSamples;
  20847. numChannels = newNumChannels;
  20848. }
  20849. }
  20850. void AudioSampleBuffer::clear() throw()
  20851. {
  20852. for (int i = 0; i < numChannels; ++i)
  20853. zeromem (channels[i], size * sizeof (float));
  20854. }
  20855. void AudioSampleBuffer::clear (const int startSample,
  20856. const int numSamples) throw()
  20857. {
  20858. jassert (startSample >= 0 && startSample + numSamples <= size);
  20859. for (int i = 0; i < numChannels; ++i)
  20860. zeromem (channels [i] + startSample, numSamples * sizeof (float));
  20861. }
  20862. void AudioSampleBuffer::clear (const int channel,
  20863. const int startSample,
  20864. const int numSamples) throw()
  20865. {
  20866. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20867. jassert (startSample >= 0 && startSample + numSamples <= size);
  20868. zeromem (channels [channel] + startSample, numSamples * sizeof (float));
  20869. }
  20870. void AudioSampleBuffer::applyGain (const int channel,
  20871. const int startSample,
  20872. int numSamples,
  20873. const float gain) throw()
  20874. {
  20875. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20876. jassert (startSample >= 0 && startSample + numSamples <= size);
  20877. if (gain != 1.0f)
  20878. {
  20879. float* d = channels [channel] + startSample;
  20880. if (gain == 0.0f)
  20881. {
  20882. zeromem (d, sizeof (float) * numSamples);
  20883. }
  20884. else
  20885. {
  20886. while (--numSamples >= 0)
  20887. *d++ *= gain;
  20888. }
  20889. }
  20890. }
  20891. void AudioSampleBuffer::applyGainRamp (const int channel,
  20892. const int startSample,
  20893. int numSamples,
  20894. float startGain,
  20895. float endGain) throw()
  20896. {
  20897. if (startGain == endGain)
  20898. {
  20899. applyGain (channel, startSample, numSamples, startGain);
  20900. }
  20901. else
  20902. {
  20903. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20904. jassert (startSample >= 0 && startSample + numSamples <= size);
  20905. const float increment = (endGain - startGain) / numSamples;
  20906. float* d = channels [channel] + startSample;
  20907. while (--numSamples >= 0)
  20908. {
  20909. *d++ *= startGain;
  20910. startGain += increment;
  20911. }
  20912. }
  20913. }
  20914. void AudioSampleBuffer::applyGain (const int startSample,
  20915. const int numSamples,
  20916. const float gain) throw()
  20917. {
  20918. for (int i = 0; i < numChannels; ++i)
  20919. applyGain (i, startSample, numSamples, gain);
  20920. }
  20921. void AudioSampleBuffer::addFrom (const int destChannel,
  20922. const int destStartSample,
  20923. const AudioSampleBuffer& source,
  20924. const int sourceChannel,
  20925. const int sourceStartSample,
  20926. int numSamples,
  20927. const float gain) throw()
  20928. {
  20929. jassert (&source != this || sourceChannel != destChannel);
  20930. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20931. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20932. jassert (((unsigned int) sourceChannel) < (unsigned int) source.numChannels);
  20933. jassert (sourceStartSample >= 0 && sourceStartSample + numSamples <= source.size);
  20934. if (gain != 0.0f && numSamples > 0)
  20935. {
  20936. float* d = channels [destChannel] + destStartSample;
  20937. const float* s = source.channels [sourceChannel] + sourceStartSample;
  20938. if (gain != 1.0f)
  20939. {
  20940. while (--numSamples >= 0)
  20941. *d++ += gain * *s++;
  20942. }
  20943. else
  20944. {
  20945. while (--numSamples >= 0)
  20946. *d++ += *s++;
  20947. }
  20948. }
  20949. }
  20950. void AudioSampleBuffer::addFrom (const int destChannel,
  20951. const int destStartSample,
  20952. const float* source,
  20953. int numSamples,
  20954. const float gain) throw()
  20955. {
  20956. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20957. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20958. jassert (source != 0);
  20959. if (gain != 0.0f && numSamples > 0)
  20960. {
  20961. float* d = channels [destChannel] + destStartSample;
  20962. if (gain != 1.0f)
  20963. {
  20964. while (--numSamples >= 0)
  20965. *d++ += gain * *source++;
  20966. }
  20967. else
  20968. {
  20969. while (--numSamples >= 0)
  20970. *d++ += *source++;
  20971. }
  20972. }
  20973. }
  20974. void AudioSampleBuffer::addFromWithRamp (const int destChannel,
  20975. const int destStartSample,
  20976. const float* source,
  20977. int numSamples,
  20978. float startGain,
  20979. const float endGain) throw()
  20980. {
  20981. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20982. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20983. jassert (source != 0);
  20984. if (startGain == endGain)
  20985. {
  20986. addFrom (destChannel,
  20987. destStartSample,
  20988. source,
  20989. numSamples,
  20990. startGain);
  20991. }
  20992. else
  20993. {
  20994. if (numSamples > 0 && (startGain != 0.0f || endGain != 0.0f))
  20995. {
  20996. const float increment = (endGain - startGain) / numSamples;
  20997. float* d = channels [destChannel] + destStartSample;
  20998. while (--numSamples >= 0)
  20999. {
  21000. *d++ += startGain * *source++;
  21001. startGain += increment;
  21002. }
  21003. }
  21004. }
  21005. }
  21006. void AudioSampleBuffer::copyFrom (const int destChannel,
  21007. const int destStartSample,
  21008. const AudioSampleBuffer& source,
  21009. const int sourceChannel,
  21010. const int sourceStartSample,
  21011. int numSamples) throw()
  21012. {
  21013. jassert (&source != this || sourceChannel != destChannel);
  21014. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  21015. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  21016. jassert (((unsigned int) sourceChannel) < (unsigned int) source.numChannels);
  21017. jassert (sourceStartSample >= 0 && sourceStartSample + numSamples <= source.size);
  21018. if (numSamples > 0)
  21019. {
  21020. memcpy (channels [destChannel] + destStartSample,
  21021. source.channels [sourceChannel] + sourceStartSample,
  21022. sizeof (float) * numSamples);
  21023. }
  21024. }
  21025. void AudioSampleBuffer::copyFrom (const int destChannel,
  21026. const int destStartSample,
  21027. const float* source,
  21028. int numSamples) throw()
  21029. {
  21030. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  21031. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  21032. jassert (source != 0);
  21033. if (numSamples > 0)
  21034. {
  21035. memcpy (channels [destChannel] + destStartSample,
  21036. source,
  21037. sizeof (float) * numSamples);
  21038. }
  21039. }
  21040. void AudioSampleBuffer::copyFrom (const int destChannel,
  21041. const int destStartSample,
  21042. const float* source,
  21043. int numSamples,
  21044. const float gain) throw()
  21045. {
  21046. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  21047. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  21048. jassert (source != 0);
  21049. if (numSamples > 0)
  21050. {
  21051. float* d = channels [destChannel] + destStartSample;
  21052. if (gain != 1.0f)
  21053. {
  21054. if (gain == 0)
  21055. {
  21056. zeromem (d, sizeof (float) * numSamples);
  21057. }
  21058. else
  21059. {
  21060. while (--numSamples >= 0)
  21061. *d++ = gain * *source++;
  21062. }
  21063. }
  21064. else
  21065. {
  21066. memcpy (d, source, sizeof (float) * numSamples);
  21067. }
  21068. }
  21069. }
  21070. void AudioSampleBuffer::copyFromWithRamp (const int destChannel,
  21071. const int destStartSample,
  21072. const float* source,
  21073. int numSamples,
  21074. float startGain,
  21075. float endGain) throw()
  21076. {
  21077. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  21078. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  21079. jassert (source != 0);
  21080. if (startGain == endGain)
  21081. {
  21082. copyFrom (destChannel,
  21083. destStartSample,
  21084. source,
  21085. numSamples,
  21086. startGain);
  21087. }
  21088. else
  21089. {
  21090. if (numSamples > 0 && (startGain != 0.0f || endGain != 0.0f))
  21091. {
  21092. const float increment = (endGain - startGain) / numSamples;
  21093. float* d = channels [destChannel] + destStartSample;
  21094. while (--numSamples >= 0)
  21095. {
  21096. *d++ = startGain * *source++;
  21097. startGain += increment;
  21098. }
  21099. }
  21100. }
  21101. }
  21102. void AudioSampleBuffer::findMinMax (const int channel,
  21103. const int startSample,
  21104. int numSamples,
  21105. float& minVal,
  21106. float& maxVal) const throw()
  21107. {
  21108. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  21109. jassert (startSample >= 0 && startSample + numSamples <= size);
  21110. if (numSamples <= 0)
  21111. {
  21112. minVal = 0.0f;
  21113. maxVal = 0.0f;
  21114. }
  21115. else
  21116. {
  21117. const float* d = channels [channel] + startSample;
  21118. float mn = *d++;
  21119. float mx = mn;
  21120. while (--numSamples > 0) // (> 0 rather than >= 0 because we've already taken the first sample)
  21121. {
  21122. const float samp = *d++;
  21123. if (samp > mx)
  21124. mx = samp;
  21125. if (samp < mn)
  21126. mn = samp;
  21127. }
  21128. maxVal = mx;
  21129. minVal = mn;
  21130. }
  21131. }
  21132. float AudioSampleBuffer::getMagnitude (const int channel,
  21133. const int startSample,
  21134. const int numSamples) const throw()
  21135. {
  21136. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  21137. jassert (startSample >= 0 && startSample + numSamples <= size);
  21138. float mn, mx;
  21139. findMinMax (channel, startSample, numSamples, mn, mx);
  21140. return jmax (mn, -mn, mx, -mx);
  21141. }
  21142. float AudioSampleBuffer::getMagnitude (const int startSample,
  21143. const int numSamples) const throw()
  21144. {
  21145. float mag = 0.0f;
  21146. for (int i = 0; i < numChannels; ++i)
  21147. mag = jmax (mag, getMagnitude (i, startSample, numSamples));
  21148. return mag;
  21149. }
  21150. float AudioSampleBuffer::getRMSLevel (const int channel,
  21151. const int startSample,
  21152. const int numSamples) const throw()
  21153. {
  21154. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  21155. jassert (startSample >= 0 && startSample + numSamples <= size);
  21156. if (numSamples <= 0 || channel < 0 || channel >= numChannels)
  21157. return 0.0f;
  21158. const float* const data = channels [channel] + startSample;
  21159. double sum = 0.0;
  21160. for (int i = 0; i < numSamples; ++i)
  21161. {
  21162. const float sample = data [i];
  21163. sum += sample * sample;
  21164. }
  21165. return (float) sqrt (sum / numSamples);
  21166. }
  21167. void AudioSampleBuffer::readFromAudioReader (AudioFormatReader* reader,
  21168. const int startSample,
  21169. const int numSamples,
  21170. const int readerStartSample,
  21171. const bool useLeftChan,
  21172. const bool useRightChan) throw()
  21173. {
  21174. jassert (reader != 0);
  21175. jassert (startSample >= 0 && startSample + numSamples <= size);
  21176. if (numSamples > 0)
  21177. {
  21178. int* chans[3];
  21179. if (useLeftChan == useRightChan)
  21180. {
  21181. chans[0] = (int*) getSampleData (0, startSample);
  21182. chans[1] = (reader->numChannels > 1 && getNumChannels() > 1) ? (int*) getSampleData (1, startSample) : 0;
  21183. }
  21184. else if (useLeftChan || (reader->numChannels == 1))
  21185. {
  21186. chans[0] = (int*) getSampleData (0, startSample);
  21187. chans[1] = 0;
  21188. }
  21189. else if (useRightChan)
  21190. {
  21191. chans[0] = 0;
  21192. chans[1] = (int*) getSampleData (0, startSample);
  21193. }
  21194. chans[2] = 0;
  21195. reader->read (chans, 2, readerStartSample, numSamples, true);
  21196. if (! reader->usesFloatingPointData)
  21197. {
  21198. for (int j = 0; j < 2; ++j)
  21199. {
  21200. float* const d = (float*) (chans[j]);
  21201. if (d != 0)
  21202. {
  21203. const float multiplier = 1.0f / 0x7fffffff;
  21204. for (int i = 0; i < numSamples; ++i)
  21205. d[i] = *(int*)(d + i) * multiplier;
  21206. }
  21207. }
  21208. }
  21209. if (numChannels > 1 && (chans[0] == 0 || chans[1] == 0))
  21210. {
  21211. // if this is a stereo buffer and the source was mono, dupe the first channel..
  21212. memcpy (getSampleData (1, startSample),
  21213. getSampleData (0, startSample),
  21214. sizeof (float) * numSamples);
  21215. }
  21216. }
  21217. }
  21218. void AudioSampleBuffer::writeToAudioWriter (AudioFormatWriter* writer,
  21219. const int startSample,
  21220. const int numSamples) const throw()
  21221. {
  21222. jassert (startSample >= 0 && startSample + numSamples <= size);
  21223. if (numSamples > 0)
  21224. {
  21225. int* chans [3];
  21226. if (writer->isFloatingPoint())
  21227. {
  21228. chans[0] = (int*) getSampleData (0, startSample);
  21229. if (numChannels > 1)
  21230. chans[1] = (int*) getSampleData (1, startSample);
  21231. else
  21232. chans[1] = 0;
  21233. chans[2] = 0;
  21234. writer->write ((const int**) chans, numSamples);
  21235. }
  21236. else
  21237. {
  21238. HeapBlock <int> tempBuffer (numSamples * 2);
  21239. chans[0] = tempBuffer;
  21240. if (numChannels > 1)
  21241. chans[1] = chans[0] + numSamples;
  21242. else
  21243. chans[1] = 0;
  21244. chans[2] = 0;
  21245. for (int j = 0; j < 2; ++j)
  21246. {
  21247. int* const dest = chans[j];
  21248. if (dest != 0)
  21249. {
  21250. const float* const src = channels [j] + startSample;
  21251. for (int i = 0; i < numSamples; ++i)
  21252. {
  21253. const double samp = src[i];
  21254. if (samp <= -1.0)
  21255. dest[i] = std::numeric_limits<int>::min();
  21256. else if (samp >= 1.0)
  21257. dest[i] = std::numeric_limits<int>::max();
  21258. else
  21259. dest[i] = roundToInt (std::numeric_limits<int>::max() * samp);
  21260. }
  21261. }
  21262. }
  21263. writer->write ((const int**) chans, numSamples);
  21264. }
  21265. }
  21266. }
  21267. END_JUCE_NAMESPACE
  21268. /*** End of inlined file: juce_AudioSampleBuffer.cpp ***/
  21269. /*** Start of inlined file: juce_IIRFilter.cpp ***/
  21270. BEGIN_JUCE_NAMESPACE
  21271. IIRFilter::IIRFilter() throw()
  21272. : active (false)
  21273. {
  21274. reset();
  21275. }
  21276. IIRFilter::IIRFilter (const IIRFilter& other) throw()
  21277. : active (other.active)
  21278. {
  21279. const ScopedLock sl (other.processLock);
  21280. memcpy (coefficients, other.coefficients, sizeof (coefficients));
  21281. reset();
  21282. }
  21283. IIRFilter::~IIRFilter() throw()
  21284. {
  21285. }
  21286. void IIRFilter::reset() throw()
  21287. {
  21288. const ScopedLock sl (processLock);
  21289. x1 = 0;
  21290. x2 = 0;
  21291. y1 = 0;
  21292. y2 = 0;
  21293. }
  21294. float IIRFilter::processSingleSampleRaw (const float in) throw()
  21295. {
  21296. float out = coefficients[0] * in
  21297. + coefficients[1] * x1
  21298. + coefficients[2] * x2
  21299. - coefficients[4] * y1
  21300. - coefficients[5] * y2;
  21301. #if JUCE_INTEL
  21302. if (! (out < -1.0e-8 || out > 1.0e-8))
  21303. out = 0;
  21304. #endif
  21305. x2 = x1;
  21306. x1 = in;
  21307. y2 = y1;
  21308. y1 = out;
  21309. return out;
  21310. }
  21311. void IIRFilter::processSamples (float* const samples,
  21312. const int numSamples) throw()
  21313. {
  21314. const ScopedLock sl (processLock);
  21315. if (active)
  21316. {
  21317. for (int i = 0; i < numSamples; ++i)
  21318. {
  21319. const float in = samples[i];
  21320. float out = coefficients[0] * in
  21321. + coefficients[1] * x1
  21322. + coefficients[2] * x2
  21323. - coefficients[4] * y1
  21324. - coefficients[5] * y2;
  21325. #if JUCE_INTEL
  21326. if (! (out < -1.0e-8 || out > 1.0e-8))
  21327. out = 0;
  21328. #endif
  21329. x2 = x1;
  21330. x1 = in;
  21331. y2 = y1;
  21332. y1 = out;
  21333. samples[i] = out;
  21334. }
  21335. }
  21336. }
  21337. void IIRFilter::makeLowPass (const double sampleRate,
  21338. const double frequency) throw()
  21339. {
  21340. jassert (sampleRate > 0);
  21341. const double n = 1.0 / tan (double_Pi * frequency / sampleRate);
  21342. const double nSquared = n * n;
  21343. const double c1 = 1.0 / (1.0 + sqrt (2.0) * n + nSquared);
  21344. setCoefficients (c1,
  21345. c1 * 2.0f,
  21346. c1,
  21347. 1.0,
  21348. c1 * 2.0 * (1.0 - nSquared),
  21349. c1 * (1.0 - sqrt (2.0) * n + nSquared));
  21350. }
  21351. void IIRFilter::makeHighPass (const double sampleRate,
  21352. const double frequency) throw()
  21353. {
  21354. const double n = tan (double_Pi * frequency / sampleRate);
  21355. const double nSquared = n * n;
  21356. const double c1 = 1.0 / (1.0 + sqrt (2.0) * n + nSquared);
  21357. setCoefficients (c1,
  21358. c1 * -2.0f,
  21359. c1,
  21360. 1.0,
  21361. c1 * 2.0 * (nSquared - 1.0),
  21362. c1 * (1.0 - sqrt (2.0) * n + nSquared));
  21363. }
  21364. void IIRFilter::makeLowShelf (const double sampleRate,
  21365. const double cutOffFrequency,
  21366. const double Q,
  21367. const float gainFactor) throw()
  21368. {
  21369. jassert (sampleRate > 0);
  21370. jassert (Q > 0);
  21371. const double A = jmax (0.0f, gainFactor);
  21372. const double aminus1 = A - 1.0;
  21373. const double aplus1 = A + 1.0;
  21374. const double omega = (double_Pi * 2.0 * jmax (cutOffFrequency, 2.0)) / sampleRate;
  21375. const double coso = cos (omega);
  21376. const double beta = sin (omega) * sqrt (A) / Q;
  21377. const double aminus1TimesCoso = aminus1 * coso;
  21378. setCoefficients (A * (aplus1 - aminus1TimesCoso + beta),
  21379. A * 2.0 * (aminus1 - aplus1 * coso),
  21380. A * (aplus1 - aminus1TimesCoso - beta),
  21381. aplus1 + aminus1TimesCoso + beta,
  21382. -2.0 * (aminus1 + aplus1 * coso),
  21383. aplus1 + aminus1TimesCoso - beta);
  21384. }
  21385. void IIRFilter::makeHighShelf (const double sampleRate,
  21386. const double cutOffFrequency,
  21387. const double Q,
  21388. const float gainFactor) throw()
  21389. {
  21390. jassert (sampleRate > 0);
  21391. jassert (Q > 0);
  21392. const double A = jmax (0.0f, gainFactor);
  21393. const double aminus1 = A - 1.0;
  21394. const double aplus1 = A + 1.0;
  21395. const double omega = (double_Pi * 2.0 * jmax (cutOffFrequency, 2.0)) / sampleRate;
  21396. const double coso = cos (omega);
  21397. const double beta = sin (omega) * sqrt (A) / Q;
  21398. const double aminus1TimesCoso = aminus1 * coso;
  21399. setCoefficients (A * (aplus1 + aminus1TimesCoso + beta),
  21400. A * -2.0 * (aminus1 + aplus1 * coso),
  21401. A * (aplus1 + aminus1TimesCoso - beta),
  21402. aplus1 - aminus1TimesCoso + beta,
  21403. 2.0 * (aminus1 - aplus1 * coso),
  21404. aplus1 - aminus1TimesCoso - beta);
  21405. }
  21406. void IIRFilter::makeBandPass (const double sampleRate,
  21407. const double centreFrequency,
  21408. const double Q,
  21409. const float gainFactor) throw()
  21410. {
  21411. jassert (sampleRate > 0);
  21412. jassert (Q > 0);
  21413. const double A = jmax (0.0f, gainFactor);
  21414. const double omega = (double_Pi * 2.0 * jmax (centreFrequency, 2.0)) / sampleRate;
  21415. const double alpha = 0.5 * sin (omega) / Q;
  21416. const double c2 = -2.0 * cos (omega);
  21417. const double alphaTimesA = alpha * A;
  21418. const double alphaOverA = alpha / A;
  21419. setCoefficients (1.0 + alphaTimesA,
  21420. c2,
  21421. 1.0 - alphaTimesA,
  21422. 1.0 + alphaOverA,
  21423. c2,
  21424. 1.0 - alphaOverA);
  21425. }
  21426. void IIRFilter::makeInactive() throw()
  21427. {
  21428. const ScopedLock sl (processLock);
  21429. active = false;
  21430. }
  21431. void IIRFilter::copyCoefficientsFrom (const IIRFilter& other) throw()
  21432. {
  21433. const ScopedLock sl (processLock);
  21434. memcpy (coefficients, other.coefficients, sizeof (coefficients));
  21435. active = other.active;
  21436. }
  21437. void IIRFilter::setCoefficients (double c1,
  21438. double c2,
  21439. double c3,
  21440. double c4,
  21441. double c5,
  21442. double c6) throw()
  21443. {
  21444. const double a = 1.0 / c4;
  21445. c1 *= a;
  21446. c2 *= a;
  21447. c3 *= a;
  21448. c5 *= a;
  21449. c6 *= a;
  21450. const ScopedLock sl (processLock);
  21451. coefficients[0] = (float) c1;
  21452. coefficients[1] = (float) c2;
  21453. coefficients[2] = (float) c3;
  21454. coefficients[3] = (float) c4;
  21455. coefficients[4] = (float) c5;
  21456. coefficients[5] = (float) c6;
  21457. active = true;
  21458. }
  21459. END_JUCE_NAMESPACE
  21460. /*** End of inlined file: juce_IIRFilter.cpp ***/
  21461. /*** Start of inlined file: juce_MidiBuffer.cpp ***/
  21462. BEGIN_JUCE_NAMESPACE
  21463. MidiBuffer::MidiBuffer() throw()
  21464. : bytesUsed (0)
  21465. {
  21466. }
  21467. MidiBuffer::MidiBuffer (const MidiMessage& message) throw()
  21468. : bytesUsed (0)
  21469. {
  21470. addEvent (message, 0);
  21471. }
  21472. MidiBuffer::MidiBuffer (const MidiBuffer& other) throw()
  21473. : data (other.data),
  21474. bytesUsed (other.bytesUsed)
  21475. {
  21476. }
  21477. const MidiBuffer& MidiBuffer::operator= (const MidiBuffer& other) throw()
  21478. {
  21479. bytesUsed = other.bytesUsed;
  21480. data = other.data;
  21481. return *this;
  21482. }
  21483. void MidiBuffer::swap (MidiBuffer& other)
  21484. {
  21485. data.swapWith (other.data);
  21486. swapVariables <int> (bytesUsed, other.bytesUsed);
  21487. }
  21488. MidiBuffer::~MidiBuffer() throw()
  21489. {
  21490. }
  21491. void MidiBuffer::clear() throw()
  21492. {
  21493. bytesUsed = 0;
  21494. }
  21495. void MidiBuffer::clear (const int startSample,
  21496. const int numSamples) throw()
  21497. {
  21498. uint8* const start = findEventAfter (data, startSample - 1);
  21499. uint8* const end = findEventAfter (start, startSample + numSamples - 1);
  21500. if (end > start)
  21501. {
  21502. const size_t bytesToMove = (size_t) (bytesUsed - (end - (uint8*) data.getData()));
  21503. if (bytesToMove > 0)
  21504. memmove (start, end, bytesToMove);
  21505. bytesUsed -= (int) (end - start);
  21506. }
  21507. }
  21508. void MidiBuffer::addEvent (const MidiMessage& m,
  21509. const int sampleNumber) throw()
  21510. {
  21511. addEvent (m.getRawData(), m.getRawDataSize(), sampleNumber);
  21512. }
  21513. static int findActualEventLength (const uint8* const data,
  21514. const int maxBytes) throw()
  21515. {
  21516. unsigned int byte = (unsigned int) *data;
  21517. int size = 0;
  21518. if (byte == 0xf0 || byte == 0xf7)
  21519. {
  21520. const uint8* d = data + 1;
  21521. while (d < data + maxBytes)
  21522. if (*d++ == 0xf7)
  21523. break;
  21524. size = (int) (d - data);
  21525. }
  21526. else if (byte == 0xff)
  21527. {
  21528. int n;
  21529. const int bytesLeft = MidiMessage::readVariableLengthVal (data + 1, n);
  21530. size = jmin (maxBytes, n + 2 + bytesLeft);
  21531. }
  21532. else if (byte >= 0x80)
  21533. {
  21534. size = jmin (maxBytes, MidiMessage::getMessageLengthFromFirstByte ((uint8) byte));
  21535. }
  21536. return size;
  21537. }
  21538. void MidiBuffer::addEvent (const uint8* const newData,
  21539. const int maxBytes,
  21540. const int sampleNumber) throw()
  21541. {
  21542. const int numBytes = findActualEventLength (newData, maxBytes);
  21543. if (numBytes > 0)
  21544. {
  21545. int spaceNeeded = bytesUsed + numBytes + 6;
  21546. data.ensureSize ((spaceNeeded + spaceNeeded / 2 + 8) & ~7);
  21547. uint8* d = findEventAfter ((uint8*) data.getData(), sampleNumber);
  21548. const size_t bytesToMove = (size_t) (bytesUsed - (d - (uint8*) data.getData()));
  21549. if (bytesToMove > 0)
  21550. memmove (d + numBytes + 6,
  21551. d,
  21552. bytesToMove);
  21553. *(int*) d = sampleNumber;
  21554. d += 4;
  21555. *(uint16*) d = (uint16) numBytes;
  21556. d += 2;
  21557. memcpy (d, newData, numBytes);
  21558. bytesUsed += numBytes + 6;
  21559. }
  21560. }
  21561. void MidiBuffer::addEvents (const MidiBuffer& otherBuffer,
  21562. const int startSample,
  21563. const int numSamples,
  21564. const int sampleDeltaToAdd) throw()
  21565. {
  21566. Iterator i (otherBuffer);
  21567. i.setNextSamplePosition (startSample);
  21568. const uint8* eventData;
  21569. int eventSize, position;
  21570. while (i.getNextEvent (eventData, eventSize, position)
  21571. && (position < startSample + numSamples || numSamples < 0))
  21572. {
  21573. addEvent (eventData, eventSize, position + sampleDeltaToAdd);
  21574. }
  21575. }
  21576. bool MidiBuffer::isEmpty() const throw()
  21577. {
  21578. return bytesUsed == 0;
  21579. }
  21580. int MidiBuffer::getNumEvents() const throw()
  21581. {
  21582. int n = 0;
  21583. const uint8* d = (uint8*) data.getData();
  21584. const uint8* const end = d + bytesUsed;
  21585. while (d < end)
  21586. {
  21587. d += 4;
  21588. d += 2 + *(const uint16*) d;
  21589. ++n;
  21590. }
  21591. return n;
  21592. }
  21593. int MidiBuffer::getFirstEventTime() const throw()
  21594. {
  21595. return (bytesUsed > 0) ? *(const int*) data.getData() : 0;
  21596. }
  21597. int MidiBuffer::getLastEventTime() const throw()
  21598. {
  21599. if (bytesUsed == 0)
  21600. return 0;
  21601. const uint8* d = (uint8*) data.getData();
  21602. const uint8* const endData = d + bytesUsed;
  21603. for (;;)
  21604. {
  21605. const uint8* nextOne = d + 6 + * (const uint16*) (d + 4);
  21606. if (nextOne >= endData)
  21607. return *(const int*) d;
  21608. d = nextOne;
  21609. }
  21610. }
  21611. uint8* MidiBuffer::findEventAfter (uint8* d, const int samplePosition) const throw()
  21612. {
  21613. const uint8* const endData = ((uint8*) data.getData()) + bytesUsed;
  21614. while (d < endData && *(int*) d <= samplePosition)
  21615. {
  21616. d += 4;
  21617. d += 2 + *(uint16*) d;
  21618. }
  21619. return d;
  21620. }
  21621. MidiBuffer::Iterator::Iterator (const MidiBuffer& buffer_) throw()
  21622. : buffer (buffer_),
  21623. data ((uint8*) buffer_.data.getData())
  21624. {
  21625. }
  21626. MidiBuffer::Iterator::~Iterator() throw()
  21627. {
  21628. }
  21629. void MidiBuffer::Iterator::setNextSamplePosition (const int samplePosition) throw()
  21630. {
  21631. data = buffer.data;
  21632. const uint8* dataEnd = ((uint8*) buffer.data.getData()) + buffer.bytesUsed;
  21633. while (data < dataEnd && *(int*) data < samplePosition)
  21634. {
  21635. data += 4;
  21636. data += 2 + *(uint16*) data;
  21637. }
  21638. }
  21639. bool MidiBuffer::Iterator::getNextEvent (const uint8* &midiData,
  21640. int& numBytes,
  21641. int& samplePosition) throw()
  21642. {
  21643. if (data >= ((uint8*) buffer.data.getData()) + buffer.bytesUsed)
  21644. return false;
  21645. samplePosition = *(int*) data;
  21646. data += 4;
  21647. numBytes = *(uint16*) data;
  21648. data += 2;
  21649. midiData = data;
  21650. data += numBytes;
  21651. return true;
  21652. }
  21653. bool MidiBuffer::Iterator::getNextEvent (MidiMessage& result,
  21654. int& samplePosition) throw()
  21655. {
  21656. if (data >= ((uint8*) buffer.data.getData()) + buffer.bytesUsed)
  21657. return false;
  21658. samplePosition = *(int*) data;
  21659. data += 4;
  21660. const int numBytes = *(uint16*) data;
  21661. data += 2;
  21662. result = MidiMessage (data, numBytes, samplePosition);
  21663. data += numBytes;
  21664. return true;
  21665. }
  21666. END_JUCE_NAMESPACE
  21667. /*** End of inlined file: juce_MidiBuffer.cpp ***/
  21668. /*** Start of inlined file: juce_MidiFile.cpp ***/
  21669. BEGIN_JUCE_NAMESPACE
  21670. struct TempoInfo
  21671. {
  21672. double bpm, timestamp;
  21673. };
  21674. struct TimeSigInfo
  21675. {
  21676. int numerator, denominator;
  21677. double timestamp;
  21678. };
  21679. MidiFile::MidiFile() throw()
  21680. : timeFormat ((short) (unsigned short) 0xe728)
  21681. {
  21682. }
  21683. MidiFile::~MidiFile() throw()
  21684. {
  21685. clear();
  21686. }
  21687. void MidiFile::clear() throw()
  21688. {
  21689. tracks.clear();
  21690. }
  21691. int MidiFile::getNumTracks() const throw()
  21692. {
  21693. return tracks.size();
  21694. }
  21695. const MidiMessageSequence* MidiFile::getTrack (const int index) const throw()
  21696. {
  21697. return tracks [index];
  21698. }
  21699. void MidiFile::addTrack (const MidiMessageSequence& trackSequence) throw()
  21700. {
  21701. tracks.add (new MidiMessageSequence (trackSequence));
  21702. }
  21703. short MidiFile::getTimeFormat() const throw()
  21704. {
  21705. return timeFormat;
  21706. }
  21707. void MidiFile::setTicksPerQuarterNote (const int ticks) throw()
  21708. {
  21709. timeFormat = (short)ticks;
  21710. }
  21711. void MidiFile::setSmpteTimeFormat (const int framesPerSecond,
  21712. const int subframeResolution) throw()
  21713. {
  21714. timeFormat = (short) (((-framesPerSecond) << 8) | subframeResolution);
  21715. }
  21716. void MidiFile::findAllTempoEvents (MidiMessageSequence& tempoChangeEvents) const
  21717. {
  21718. for (int i = tracks.size(); --i >= 0;)
  21719. {
  21720. const int numEvents = tracks.getUnchecked(i)->getNumEvents();
  21721. for (int j = 0; j < numEvents; ++j)
  21722. {
  21723. const MidiMessage& m = tracks.getUnchecked(i)->getEventPointer (j)->message;
  21724. if (m.isTempoMetaEvent())
  21725. tempoChangeEvents.addEvent (m);
  21726. }
  21727. }
  21728. }
  21729. void MidiFile::findAllTimeSigEvents (MidiMessageSequence& timeSigEvents) const
  21730. {
  21731. for (int i = tracks.size(); --i >= 0;)
  21732. {
  21733. const int numEvents = tracks.getUnchecked(i)->getNumEvents();
  21734. for (int j = 0; j < numEvents; ++j)
  21735. {
  21736. const MidiMessage& m = tracks.getUnchecked(i)->getEventPointer (j)->message;
  21737. if (m.isTimeSignatureMetaEvent())
  21738. timeSigEvents.addEvent (m);
  21739. }
  21740. }
  21741. }
  21742. double MidiFile::getLastTimestamp() const
  21743. {
  21744. double t = 0.0;
  21745. for (int i = tracks.size(); --i >= 0;)
  21746. t = jmax (t, tracks.getUnchecked(i)->getEndTime());
  21747. return t;
  21748. }
  21749. static bool parseMidiHeader (const char* &data,
  21750. short& timeFormat,
  21751. short& fileType,
  21752. short& numberOfTracks)
  21753. {
  21754. unsigned int ch = (int) ByteOrder::bigEndianInt (data);
  21755. data += 4;
  21756. if (ch != ByteOrder::bigEndianInt ("MThd"))
  21757. {
  21758. bool ok = false;
  21759. if (ch == ByteOrder::bigEndianInt ("RIFF"))
  21760. {
  21761. for (int i = 0; i < 8; ++i)
  21762. {
  21763. ch = ByteOrder::bigEndianInt (data);
  21764. data += 4;
  21765. if (ch == ByteOrder::bigEndianInt ("MThd"))
  21766. {
  21767. ok = true;
  21768. break;
  21769. }
  21770. }
  21771. }
  21772. if (! ok)
  21773. return false;
  21774. }
  21775. unsigned int bytesRemaining = ByteOrder::bigEndianInt (data);
  21776. data += 4;
  21777. fileType = (short) ByteOrder::bigEndianShort (data);
  21778. data += 2;
  21779. numberOfTracks = (short) ByteOrder::bigEndianShort (data);
  21780. data += 2;
  21781. timeFormat = (short) ByteOrder::bigEndianShort (data);
  21782. data += 2;
  21783. bytesRemaining -= 6;
  21784. data += bytesRemaining;
  21785. return true;
  21786. }
  21787. bool MidiFile::readFrom (InputStream& sourceStream)
  21788. {
  21789. clear();
  21790. MemoryBlock data;
  21791. const int maxSensibleMidiFileSize = 2 * 1024 * 1024;
  21792. // (put a sanity-check on the file size, as midi files are generally small)
  21793. if (sourceStream.readIntoMemoryBlock (data, maxSensibleMidiFileSize))
  21794. {
  21795. size_t size = data.getSize();
  21796. const char* d = (char*) data.getData();
  21797. short fileType, expectedTracks;
  21798. if (size > 16 && parseMidiHeader (d, timeFormat, fileType, expectedTracks))
  21799. {
  21800. size -= (int) (d - (char*) data.getData());
  21801. int track = 0;
  21802. while (size > 0 && track < expectedTracks)
  21803. {
  21804. const int chunkType = (int) ByteOrder::bigEndianInt (d);
  21805. d += 4;
  21806. const int chunkSize = (int) ByteOrder::bigEndianInt (d);
  21807. d += 4;
  21808. if (chunkSize <= 0)
  21809. break;
  21810. if (size < 0)
  21811. return false;
  21812. if (chunkType == (int) ByteOrder::bigEndianInt ("MTrk"))
  21813. {
  21814. readNextTrack (d, chunkSize);
  21815. }
  21816. size -= chunkSize + 8;
  21817. d += chunkSize;
  21818. ++track;
  21819. }
  21820. return true;
  21821. }
  21822. }
  21823. return false;
  21824. }
  21825. // a comparator that puts all the note-offs before note-ons that have the same time
  21826. int MidiFile::compareElements (const MidiMessageSequence::MidiEventHolder* const first,
  21827. const MidiMessageSequence::MidiEventHolder* const second) throw()
  21828. {
  21829. const double diff = (first->message.getTimeStamp() - second->message.getTimeStamp());
  21830. if (diff == 0)
  21831. {
  21832. if (first->message.isNoteOff() && second->message.isNoteOn())
  21833. return -1;
  21834. else if (first->message.isNoteOn() && second->message.isNoteOff())
  21835. return 1;
  21836. else
  21837. return 0;
  21838. }
  21839. else
  21840. {
  21841. return (diff > 0) ? 1 : -1;
  21842. }
  21843. }
  21844. void MidiFile::readNextTrack (const char* data, int size)
  21845. {
  21846. double time = 0;
  21847. char lastStatusByte = 0;
  21848. MidiMessageSequence result;
  21849. while (size > 0)
  21850. {
  21851. int bytesUsed;
  21852. const int delay = MidiMessage::readVariableLengthVal ((const uint8*) data, bytesUsed);
  21853. data += bytesUsed;
  21854. size -= bytesUsed;
  21855. time += delay;
  21856. int messSize = 0;
  21857. const MidiMessage mm ((const uint8*) data, size, messSize, lastStatusByte, time);
  21858. if (messSize <= 0)
  21859. break;
  21860. size -= messSize;
  21861. data += messSize;
  21862. result.addEvent (mm);
  21863. const char firstByte = *(mm.getRawData());
  21864. if ((firstByte & 0xf0) != 0xf0)
  21865. lastStatusByte = firstByte;
  21866. }
  21867. // use a sort that puts all the note-offs before note-ons that have the same time
  21868. result.list.sort (*this, true);
  21869. result.updateMatchedPairs();
  21870. addTrack (result);
  21871. }
  21872. static double convertTicksToSeconds (const double time,
  21873. const MidiMessageSequence& tempoEvents,
  21874. const int timeFormat)
  21875. {
  21876. if (timeFormat > 0)
  21877. {
  21878. int numer = 4, denom = 4;
  21879. double tempoTime = 0.0, correctedTempoTime = 0.0;
  21880. const double tickLen = 1.0 / (timeFormat & 0x7fff);
  21881. double secsPerTick = 0.5 * tickLen;
  21882. const int numEvents = tempoEvents.getNumEvents();
  21883. for (int i = 0; i < numEvents; ++i)
  21884. {
  21885. const MidiMessage& m = tempoEvents.getEventPointer(i)->message;
  21886. if (time <= m.getTimeStamp())
  21887. break;
  21888. if (timeFormat > 0)
  21889. {
  21890. correctedTempoTime = correctedTempoTime
  21891. + (m.getTimeStamp() - tempoTime) * secsPerTick;
  21892. }
  21893. else
  21894. {
  21895. correctedTempoTime = tickLen * m.getTimeStamp() / (((timeFormat & 0x7fff) >> 8) * (timeFormat & 0xff));
  21896. }
  21897. tempoTime = m.getTimeStamp();
  21898. if (m.isTempoMetaEvent())
  21899. secsPerTick = tickLen * m.getTempoSecondsPerQuarterNote();
  21900. else if (m.isTimeSignatureMetaEvent())
  21901. m.getTimeSignatureInfo (numer, denom);
  21902. while (i + 1 < numEvents)
  21903. {
  21904. const MidiMessage& m2 = tempoEvents.getEventPointer(i + 1)->message;
  21905. if (m2.getTimeStamp() == tempoTime)
  21906. {
  21907. ++i;
  21908. if (m2.isTempoMetaEvent())
  21909. secsPerTick = tickLen * m2.getTempoSecondsPerQuarterNote();
  21910. else if (m2.isTimeSignatureMetaEvent())
  21911. m2.getTimeSignatureInfo (numer, denom);
  21912. }
  21913. else
  21914. {
  21915. break;
  21916. }
  21917. }
  21918. }
  21919. return correctedTempoTime + (time - tempoTime) * secsPerTick;
  21920. }
  21921. else
  21922. {
  21923. return time / (((timeFormat & 0x7fff) >> 8) * (timeFormat & 0xff));
  21924. }
  21925. }
  21926. void MidiFile::convertTimestampTicksToSeconds()
  21927. {
  21928. MidiMessageSequence tempoEvents;
  21929. findAllTempoEvents (tempoEvents);
  21930. findAllTimeSigEvents (tempoEvents);
  21931. for (int i = 0; i < tracks.size(); ++i)
  21932. {
  21933. MidiMessageSequence& ms = *tracks.getUnchecked(i);
  21934. for (int j = ms.getNumEvents(); --j >= 0;)
  21935. {
  21936. MidiMessage& m = ms.getEventPointer(j)->message;
  21937. m.setTimeStamp (convertTicksToSeconds (m.getTimeStamp(),
  21938. tempoEvents,
  21939. timeFormat));
  21940. }
  21941. }
  21942. }
  21943. static void writeVariableLengthInt (OutputStream& out, unsigned int v)
  21944. {
  21945. unsigned int buffer = v & 0x7F;
  21946. while ((v >>= 7) != 0)
  21947. {
  21948. buffer <<= 8;
  21949. buffer |= ((v & 0x7F) | 0x80);
  21950. }
  21951. for (;;)
  21952. {
  21953. out.writeByte ((char) buffer);
  21954. if (buffer & 0x80)
  21955. buffer >>= 8;
  21956. else
  21957. break;
  21958. }
  21959. }
  21960. bool MidiFile::writeTo (OutputStream& out)
  21961. {
  21962. out.writeIntBigEndian ((int) ByteOrder::bigEndianInt ("MThd"));
  21963. out.writeIntBigEndian (6);
  21964. out.writeShortBigEndian (1); // type
  21965. out.writeShortBigEndian ((short) tracks.size());
  21966. out.writeShortBigEndian (timeFormat);
  21967. for (int i = 0; i < tracks.size(); ++i)
  21968. writeTrack (out, i);
  21969. out.flush();
  21970. return true;
  21971. }
  21972. void MidiFile::writeTrack (OutputStream& mainOut,
  21973. const int trackNum)
  21974. {
  21975. MemoryOutputStream out;
  21976. const MidiMessageSequence& ms = *tracks[trackNum];
  21977. int lastTick = 0;
  21978. char lastStatusByte = 0;
  21979. for (int i = 0; i < ms.getNumEvents(); ++i)
  21980. {
  21981. const MidiMessage& mm = ms.getEventPointer(i)->message;
  21982. const int tick = roundToInt (mm.getTimeStamp());
  21983. const int delta = jmax (0, tick - lastTick);
  21984. writeVariableLengthInt (out, delta);
  21985. lastTick = tick;
  21986. const char statusByte = *(mm.getRawData());
  21987. if ((statusByte == lastStatusByte)
  21988. && ((statusByte & 0xf0) != 0xf0)
  21989. && i > 0
  21990. && mm.getRawDataSize() > 1)
  21991. {
  21992. out.write (mm.getRawData() + 1, mm.getRawDataSize() - 1);
  21993. }
  21994. else
  21995. {
  21996. out.write (mm.getRawData(), mm.getRawDataSize());
  21997. }
  21998. lastStatusByte = statusByte;
  21999. }
  22000. out.writeByte (0);
  22001. const MidiMessage m (MidiMessage::endOfTrack());
  22002. out.write (m.getRawData(),
  22003. m.getRawDataSize());
  22004. mainOut.writeIntBigEndian ((int) ByteOrder::bigEndianInt ("MTrk"));
  22005. mainOut.writeIntBigEndian ((int) out.getDataSize());
  22006. mainOut.write (out.getData(), (int) out.getDataSize());
  22007. }
  22008. END_JUCE_NAMESPACE
  22009. /*** End of inlined file: juce_MidiFile.cpp ***/
  22010. /*** Start of inlined file: juce_MidiKeyboardState.cpp ***/
  22011. BEGIN_JUCE_NAMESPACE
  22012. MidiKeyboardState::MidiKeyboardState()
  22013. {
  22014. zeromem (noteStates, sizeof (noteStates));
  22015. }
  22016. MidiKeyboardState::~MidiKeyboardState()
  22017. {
  22018. }
  22019. void MidiKeyboardState::reset()
  22020. {
  22021. const ScopedLock sl (lock);
  22022. zeromem (noteStates, sizeof (noteStates));
  22023. eventsToAdd.clear();
  22024. }
  22025. bool MidiKeyboardState::isNoteOn (const int midiChannel, const int n) const throw()
  22026. {
  22027. jassert (midiChannel >= 0 && midiChannel <= 16);
  22028. return ((unsigned int) n) < 128
  22029. && (noteStates[n] & (1 << (midiChannel - 1))) != 0;
  22030. }
  22031. bool MidiKeyboardState::isNoteOnForChannels (const int midiChannelMask, const int n) const throw()
  22032. {
  22033. return ((unsigned int) n) < 128
  22034. && (noteStates[n] & midiChannelMask) != 0;
  22035. }
  22036. void MidiKeyboardState::noteOn (const int midiChannel, const int midiNoteNumber, const float velocity)
  22037. {
  22038. jassert (midiChannel >= 0 && midiChannel <= 16);
  22039. jassert (((unsigned int) midiNoteNumber) < 128);
  22040. const ScopedLock sl (lock);
  22041. if (((unsigned int) midiNoteNumber) < 128)
  22042. {
  22043. const int timeNow = (int) Time::getMillisecondCounter();
  22044. eventsToAdd.addEvent (MidiMessage::noteOn (midiChannel, midiNoteNumber, velocity), timeNow);
  22045. eventsToAdd.clear (0, timeNow - 500);
  22046. noteOnInternal (midiChannel, midiNoteNumber, velocity);
  22047. }
  22048. }
  22049. void MidiKeyboardState::noteOnInternal (const int midiChannel, const int midiNoteNumber, const float velocity)
  22050. {
  22051. if (((unsigned int) midiNoteNumber) < 128)
  22052. {
  22053. noteStates [midiNoteNumber] |= (1 << (midiChannel - 1));
  22054. for (int i = listeners.size(); --i >= 0;)
  22055. ((MidiKeyboardStateListener*) listeners.getUnchecked(i))
  22056. ->handleNoteOn (this, midiChannel, midiNoteNumber, velocity);
  22057. }
  22058. }
  22059. void MidiKeyboardState::noteOff (const int midiChannel, const int midiNoteNumber)
  22060. {
  22061. const ScopedLock sl (lock);
  22062. if (isNoteOn (midiChannel, midiNoteNumber))
  22063. {
  22064. const int timeNow = (int) Time::getMillisecondCounter();
  22065. eventsToAdd.addEvent (MidiMessage::noteOff (midiChannel, midiNoteNumber), timeNow);
  22066. eventsToAdd.clear (0, timeNow - 500);
  22067. noteOffInternal (midiChannel, midiNoteNumber);
  22068. }
  22069. }
  22070. void MidiKeyboardState::noteOffInternal (const int midiChannel, const int midiNoteNumber)
  22071. {
  22072. if (isNoteOn (midiChannel, midiNoteNumber))
  22073. {
  22074. noteStates [midiNoteNumber] &= ~(1 << (midiChannel - 1));
  22075. for (int i = listeners.size(); --i >= 0;)
  22076. ((MidiKeyboardStateListener*) listeners.getUnchecked(i))
  22077. ->handleNoteOff (this, midiChannel, midiNoteNumber);
  22078. }
  22079. }
  22080. void MidiKeyboardState::allNotesOff (const int midiChannel)
  22081. {
  22082. const ScopedLock sl (lock);
  22083. if (midiChannel <= 0)
  22084. {
  22085. for (int i = 1; i <= 16; ++i)
  22086. allNotesOff (i);
  22087. }
  22088. else
  22089. {
  22090. for (int i = 0; i < 128; ++i)
  22091. noteOff (midiChannel, i);
  22092. }
  22093. }
  22094. void MidiKeyboardState::processNextMidiEvent (const MidiMessage& message)
  22095. {
  22096. if (message.isNoteOn())
  22097. {
  22098. noteOnInternal (message.getChannel(), message.getNoteNumber(), message.getFloatVelocity());
  22099. }
  22100. else if (message.isNoteOff())
  22101. {
  22102. noteOffInternal (message.getChannel(), message.getNoteNumber());
  22103. }
  22104. else if (message.isAllNotesOff())
  22105. {
  22106. for (int i = 0; i < 128; ++i)
  22107. noteOffInternal (message.getChannel(), i);
  22108. }
  22109. }
  22110. void MidiKeyboardState::processNextMidiBuffer (MidiBuffer& buffer,
  22111. const int startSample,
  22112. const int numSamples,
  22113. const bool injectIndirectEvents)
  22114. {
  22115. MidiBuffer::Iterator i (buffer);
  22116. MidiMessage message (0xf4, 0.0);
  22117. int time;
  22118. const ScopedLock sl (lock);
  22119. while (i.getNextEvent (message, time))
  22120. processNextMidiEvent (message);
  22121. if (injectIndirectEvents)
  22122. {
  22123. MidiBuffer::Iterator i2 (eventsToAdd);
  22124. const int firstEventToAdd = eventsToAdd.getFirstEventTime();
  22125. const double scaleFactor = numSamples / (double) (eventsToAdd.getLastEventTime() + 1 - firstEventToAdd);
  22126. while (i2.getNextEvent (message, time))
  22127. {
  22128. const int pos = jlimit (0, numSamples - 1, roundToInt ((time - firstEventToAdd) * scaleFactor));
  22129. buffer.addEvent (message, startSample + pos);
  22130. }
  22131. }
  22132. eventsToAdd.clear();
  22133. }
  22134. void MidiKeyboardState::addListener (MidiKeyboardStateListener* const listener) throw()
  22135. {
  22136. const ScopedLock sl (lock);
  22137. listeners.addIfNotAlreadyThere (listener);
  22138. }
  22139. void MidiKeyboardState::removeListener (MidiKeyboardStateListener* const listener) throw()
  22140. {
  22141. const ScopedLock sl (lock);
  22142. listeners.removeValue (listener);
  22143. }
  22144. END_JUCE_NAMESPACE
  22145. /*** End of inlined file: juce_MidiKeyboardState.cpp ***/
  22146. /*** Start of inlined file: juce_MidiMessage.cpp ***/
  22147. BEGIN_JUCE_NAMESPACE
  22148. int MidiMessage::readVariableLengthVal (const uint8* data,
  22149. int& numBytesUsed) throw()
  22150. {
  22151. numBytesUsed = 0;
  22152. int v = 0;
  22153. int i;
  22154. do
  22155. {
  22156. i = (int) *data++;
  22157. if (++numBytesUsed > 6)
  22158. break;
  22159. v = (v << 7) + (i & 0x7f);
  22160. } while (i & 0x80);
  22161. return v;
  22162. }
  22163. int MidiMessage::getMessageLengthFromFirstByte (const uint8 firstByte) throw()
  22164. {
  22165. // this method only works for valid starting bytes of a short midi message
  22166. jassert (firstByte >= 0x80
  22167. && firstByte != 0xf0
  22168. && firstByte != 0xf7);
  22169. static const char messageLengths[] =
  22170. {
  22171. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  22172. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  22173. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  22174. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  22175. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  22176. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  22177. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  22178. 1, 2, 3, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
  22179. };
  22180. return messageLengths [firstByte & 0x7f];
  22181. }
  22182. MidiMessage::MidiMessage (const uint8* const d,
  22183. const int dataSize,
  22184. const double t) throw()
  22185. : timeStamp (t),
  22186. message (0),
  22187. size (dataSize)
  22188. {
  22189. jassert (dataSize > 0);
  22190. if (dataSize <= 4)
  22191. data = (uint8*) &message;
  22192. else
  22193. data = (uint8*) juce_malloc (dataSize);
  22194. memcpy (data, d, dataSize);
  22195. // check that the length matches the data..
  22196. jassert (size > 3 || *d >= 0xf0 || getMessageLengthFromFirstByte (*d) == size);
  22197. }
  22198. MidiMessage::MidiMessage (const int byte1,
  22199. const double t) throw()
  22200. : timeStamp (t),
  22201. data ((uint8*) &message),
  22202. size (1)
  22203. {
  22204. data[0] = (uint8) byte1;
  22205. // check that the length matches the data..
  22206. jassert (byte1 >= 0xf0 || getMessageLengthFromFirstByte ((uint8) byte1) == 1);
  22207. }
  22208. MidiMessage::MidiMessage (const int byte1,
  22209. const int byte2,
  22210. const double t) throw()
  22211. : timeStamp (t),
  22212. data ((uint8*) &message),
  22213. size (2)
  22214. {
  22215. data[0] = (uint8) byte1;
  22216. data[1] = (uint8) byte2;
  22217. // check that the length matches the data..
  22218. jassert (byte1 >= 0xf0 || getMessageLengthFromFirstByte ((uint8) byte1) == 2);
  22219. }
  22220. MidiMessage::MidiMessage (const int byte1,
  22221. const int byte2,
  22222. const int byte3,
  22223. const double t) throw()
  22224. : timeStamp (t),
  22225. data ((uint8*) &message),
  22226. size (3)
  22227. {
  22228. data[0] = (uint8) byte1;
  22229. data[1] = (uint8) byte2;
  22230. data[2] = (uint8) byte3;
  22231. // check that the length matches the data..
  22232. jassert (byte1 >= 0xf0 || getMessageLengthFromFirstByte ((uint8) byte1) == 3);
  22233. }
  22234. MidiMessage::MidiMessage (const MidiMessage& other) throw()
  22235. : timeStamp (other.timeStamp),
  22236. message (other.message),
  22237. size (other.size)
  22238. {
  22239. if (other.data != (uint8*) &other.message)
  22240. {
  22241. data = (uint8*) juce_malloc (size);
  22242. memcpy (data, other.data, size);
  22243. }
  22244. else
  22245. {
  22246. data = (uint8*) &message;
  22247. }
  22248. }
  22249. MidiMessage::MidiMessage (const MidiMessage& other,
  22250. const double newTimeStamp) throw()
  22251. : timeStamp (newTimeStamp),
  22252. message (other.message),
  22253. size (other.size)
  22254. {
  22255. if (other.data != (uint8*) &other.message)
  22256. {
  22257. data = (uint8*) juce_malloc (size);
  22258. memcpy (data, other.data, size);
  22259. }
  22260. else
  22261. {
  22262. data = (uint8*) &message;
  22263. }
  22264. }
  22265. MidiMessage::MidiMessage (const uint8* src,
  22266. int sz,
  22267. int& numBytesUsed,
  22268. const uint8 lastStatusByte,
  22269. double t) throw()
  22270. : timeStamp (t),
  22271. data ((uint8*) &message),
  22272. message (0)
  22273. {
  22274. unsigned int byte = (unsigned int) *src;
  22275. if (byte < 0x80)
  22276. {
  22277. byte = (unsigned int) (uint8) lastStatusByte;
  22278. numBytesUsed = -1;
  22279. }
  22280. else
  22281. {
  22282. numBytesUsed = 0;
  22283. --sz;
  22284. ++src;
  22285. }
  22286. if (byte >= 0x80)
  22287. {
  22288. if (byte == 0xf0)
  22289. {
  22290. const uint8* d = (const uint8*) src;
  22291. while (d < src + sz)
  22292. {
  22293. if (*d >= 0x80) // stop if we hit a status byte, and don't include it in this message
  22294. {
  22295. if (*d == 0xf7) // include an 0xf7 if we hit one
  22296. ++d;
  22297. break;
  22298. }
  22299. ++d;
  22300. }
  22301. size = 1 + (int) (d - src);
  22302. data = (uint8*) juce_malloc (size);
  22303. *data = (uint8) byte;
  22304. memcpy (data + 1, src, size - 1);
  22305. }
  22306. else if (byte == 0xff)
  22307. {
  22308. int n;
  22309. const int bytesLeft = readVariableLengthVal (src + 1, n);
  22310. size = jmin (sz + 1, n + 2 + bytesLeft);
  22311. data = (uint8*) juce_malloc (size);
  22312. *data = (uint8) byte;
  22313. memcpy (data + 1, src, size - 1);
  22314. }
  22315. else
  22316. {
  22317. size = getMessageLengthFromFirstByte ((uint8) byte);
  22318. *data = (uint8) byte;
  22319. if (size > 1)
  22320. {
  22321. data[1] = src[0];
  22322. if (size > 2)
  22323. data[2] = src[1];
  22324. }
  22325. }
  22326. numBytesUsed += size;
  22327. }
  22328. else
  22329. {
  22330. message = 0;
  22331. size = 0;
  22332. }
  22333. }
  22334. const MidiMessage& MidiMessage::operator= (const MidiMessage& other) throw()
  22335. {
  22336. if (this != &other)
  22337. {
  22338. timeStamp = other.timeStamp;
  22339. size = other.size;
  22340. message = other.message;
  22341. if (data != (uint8*) &message)
  22342. juce_free (data);
  22343. if (other.data != (uint8*) &other.message)
  22344. {
  22345. data = (uint8*) juce_malloc (size);
  22346. memcpy (data, other.data, size);
  22347. }
  22348. else
  22349. {
  22350. data = (uint8*) &message;
  22351. }
  22352. }
  22353. return *this;
  22354. }
  22355. MidiMessage::~MidiMessage() throw()
  22356. {
  22357. if (data != (uint8*) &message)
  22358. juce_free (data);
  22359. }
  22360. int MidiMessage::getChannel() const throw()
  22361. {
  22362. if ((data[0] & 0xf0) != 0xf0)
  22363. return (data[0] & 0xf) + 1;
  22364. else
  22365. return 0;
  22366. }
  22367. bool MidiMessage::isForChannel (const int channel) const throw()
  22368. {
  22369. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22370. return ((data[0] & 0xf) == channel - 1)
  22371. && ((data[0] & 0xf0) != 0xf0);
  22372. }
  22373. void MidiMessage::setChannel (const int channel) throw()
  22374. {
  22375. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22376. if ((data[0] & 0xf0) != (uint8) 0xf0)
  22377. data[0] = (uint8) ((data[0] & (uint8)0xf0)
  22378. | (uint8)(channel - 1));
  22379. }
  22380. bool MidiMessage::isNoteOn (const bool returnTrueForVelocity0) const throw()
  22381. {
  22382. return ((data[0] & 0xf0) == 0x90)
  22383. && (returnTrueForVelocity0 || data[2] != 0);
  22384. }
  22385. bool MidiMessage::isNoteOff (const bool returnTrueForNoteOnVelocity0) const throw()
  22386. {
  22387. return ((data[0] & 0xf0) == 0x80)
  22388. || (returnTrueForNoteOnVelocity0 && (data[2] == 0) && ((data[0] & 0xf0) == 0x90));
  22389. }
  22390. bool MidiMessage::isNoteOnOrOff() const throw()
  22391. {
  22392. const int d = data[0] & 0xf0;
  22393. return (d == 0x90) || (d == 0x80);
  22394. }
  22395. int MidiMessage::getNoteNumber() const throw()
  22396. {
  22397. return data[1];
  22398. }
  22399. void MidiMessage::setNoteNumber (const int newNoteNumber) throw()
  22400. {
  22401. if (isNoteOnOrOff())
  22402. data[1] = (uint8) jlimit (0, 127, newNoteNumber);
  22403. }
  22404. uint8 MidiMessage::getVelocity() const throw()
  22405. {
  22406. if (isNoteOnOrOff())
  22407. return data[2];
  22408. else
  22409. return 0;
  22410. }
  22411. float MidiMessage::getFloatVelocity() const throw()
  22412. {
  22413. return getVelocity() * (1.0f / 127.0f);
  22414. }
  22415. void MidiMessage::setVelocity (const float newVelocity) throw()
  22416. {
  22417. if (isNoteOnOrOff())
  22418. data[2] = (uint8) jlimit (0, 0x7f, roundToInt (newVelocity * 127.0f));
  22419. }
  22420. void MidiMessage::multiplyVelocity (const float scaleFactor) throw()
  22421. {
  22422. if (isNoteOnOrOff())
  22423. data[2] = (uint8) jlimit (0, 0x7f, roundToInt (scaleFactor * data[2]));
  22424. }
  22425. bool MidiMessage::isAftertouch() const throw()
  22426. {
  22427. return (data[0] & 0xf0) == 0xa0;
  22428. }
  22429. int MidiMessage::getAfterTouchValue() const throw()
  22430. {
  22431. return data[2];
  22432. }
  22433. const MidiMessage MidiMessage::aftertouchChange (const int channel,
  22434. const int noteNum,
  22435. const int aftertouchValue) throw()
  22436. {
  22437. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22438. jassert (((unsigned int) noteNum) <= 127);
  22439. jassert (((unsigned int) aftertouchValue) <= 127);
  22440. return MidiMessage (0xa0 | jlimit (0, 15, channel - 1),
  22441. noteNum & 0x7f,
  22442. aftertouchValue & 0x7f);
  22443. }
  22444. bool MidiMessage::isChannelPressure() const throw()
  22445. {
  22446. return (data[0] & 0xf0) == 0xd0;
  22447. }
  22448. int MidiMessage::getChannelPressureValue() const throw()
  22449. {
  22450. jassert (isChannelPressure());
  22451. return data[1];
  22452. }
  22453. const MidiMessage MidiMessage::channelPressureChange (const int channel,
  22454. const int pressure) throw()
  22455. {
  22456. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22457. jassert (((unsigned int) pressure) <= 127);
  22458. return MidiMessage (0xd0 | jlimit (0, 15, channel - 1),
  22459. pressure & 0x7f);
  22460. }
  22461. bool MidiMessage::isProgramChange() const throw()
  22462. {
  22463. return (data[0] & 0xf0) == 0xc0;
  22464. }
  22465. int MidiMessage::getProgramChangeNumber() const throw()
  22466. {
  22467. return data[1];
  22468. }
  22469. const MidiMessage MidiMessage::programChange (const int channel,
  22470. const int programNumber) throw()
  22471. {
  22472. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22473. return MidiMessage (0xc0 | jlimit (0, 15, channel - 1),
  22474. programNumber & 0x7f);
  22475. }
  22476. bool MidiMessage::isPitchWheel() const throw()
  22477. {
  22478. return (data[0] & 0xf0) == 0xe0;
  22479. }
  22480. int MidiMessage::getPitchWheelValue() const throw()
  22481. {
  22482. return data[1] | (data[2] << 7);
  22483. }
  22484. const MidiMessage MidiMessage::pitchWheel (const int channel,
  22485. const int position) throw()
  22486. {
  22487. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22488. jassert (((unsigned int) position) <= 0x3fff);
  22489. return MidiMessage (0xe0 | jlimit (0, 15, channel - 1),
  22490. position & 127,
  22491. (position >> 7) & 127);
  22492. }
  22493. bool MidiMessage::isController() const throw()
  22494. {
  22495. return (data[0] & 0xf0) == 0xb0;
  22496. }
  22497. int MidiMessage::getControllerNumber() const throw()
  22498. {
  22499. jassert (isController());
  22500. return data[1];
  22501. }
  22502. int MidiMessage::getControllerValue() const throw()
  22503. {
  22504. jassert (isController());
  22505. return data[2];
  22506. }
  22507. const MidiMessage MidiMessage::controllerEvent (const int channel,
  22508. const int controllerType,
  22509. const int value) throw()
  22510. {
  22511. // the channel must be between 1 and 16 inclusive
  22512. jassert (channel > 0 && channel <= 16);
  22513. return MidiMessage (0xb0 | jlimit (0, 15, channel - 1),
  22514. controllerType & 127,
  22515. value & 127);
  22516. }
  22517. const MidiMessage MidiMessage::noteOn (const int channel,
  22518. const int noteNumber,
  22519. const float velocity) throw()
  22520. {
  22521. return noteOn (channel, noteNumber, (uint8)(velocity * 127.0f));
  22522. }
  22523. const MidiMessage MidiMessage::noteOn (const int channel,
  22524. const int noteNumber,
  22525. const uint8 velocity) throw()
  22526. {
  22527. jassert (channel > 0 && channel <= 16);
  22528. jassert (((unsigned int) noteNumber) <= 127);
  22529. return MidiMessage (0x90 | jlimit (0, 15, channel - 1),
  22530. noteNumber & 127,
  22531. jlimit (0, 127, roundToInt (velocity)));
  22532. }
  22533. const MidiMessage MidiMessage::noteOff (const int channel,
  22534. const int noteNumber) throw()
  22535. {
  22536. jassert (channel > 0 && channel <= 16);
  22537. jassert (((unsigned int) noteNumber) <= 127);
  22538. return MidiMessage (0x80 | jlimit (0, 15, channel - 1), noteNumber & 127, 0);
  22539. }
  22540. const MidiMessage MidiMessage::allNotesOff (const int channel) throw()
  22541. {
  22542. jassert (channel > 0 && channel <= 16);
  22543. return controllerEvent (channel, 123, 0);
  22544. }
  22545. bool MidiMessage::isAllNotesOff() const throw()
  22546. {
  22547. return (data[0] & 0xf0) == 0xb0
  22548. && data[1] == 123;
  22549. }
  22550. const MidiMessage MidiMessage::allSoundOff (const int channel) throw()
  22551. {
  22552. return controllerEvent (channel, 120, 0);
  22553. }
  22554. bool MidiMessage::isAllSoundOff() const throw()
  22555. {
  22556. return (data[0] & 0xf0) == 0xb0
  22557. && data[1] == 120;
  22558. }
  22559. const MidiMessage MidiMessage::allControllersOff (const int channel) throw()
  22560. {
  22561. return controllerEvent (channel, 121, 0);
  22562. }
  22563. const MidiMessage MidiMessage::masterVolume (const float volume) throw()
  22564. {
  22565. const int vol = jlimit (0, 0x3fff, roundToInt (volume * 0x4000));
  22566. uint8 buf[8];
  22567. buf[0] = 0xf0;
  22568. buf[1] = 0x7f;
  22569. buf[2] = 0x7f;
  22570. buf[3] = 0x04;
  22571. buf[4] = 0x01;
  22572. buf[5] = (uint8) (vol & 0x7f);
  22573. buf[6] = (uint8) (vol >> 7);
  22574. buf[7] = 0xf7;
  22575. return MidiMessage (buf, 8);
  22576. }
  22577. bool MidiMessage::isSysEx() const throw()
  22578. {
  22579. return *data == 0xf0;
  22580. }
  22581. const MidiMessage MidiMessage::createSysExMessage (const uint8* sysexData,
  22582. const int dataSize) throw()
  22583. {
  22584. MemoryBlock mm (dataSize + 2);
  22585. uint8* const m = (uint8*) mm.getData();
  22586. m[0] = 0xf0;
  22587. memcpy (m + 1, sysexData, dataSize);
  22588. m[dataSize + 1] = 0xf7;
  22589. return MidiMessage (m, dataSize + 2);
  22590. }
  22591. const uint8* MidiMessage::getSysExData() const throw()
  22592. {
  22593. return (isSysEx()) ? getRawData() + 1
  22594. : 0;
  22595. }
  22596. int MidiMessage::getSysExDataSize() const throw()
  22597. {
  22598. return (isSysEx()) ? size - 2
  22599. : 0;
  22600. }
  22601. bool MidiMessage::isMetaEvent() const throw()
  22602. {
  22603. return *data == 0xff;
  22604. }
  22605. bool MidiMessage::isActiveSense() const throw()
  22606. {
  22607. return *data == 0xfe;
  22608. }
  22609. int MidiMessage::getMetaEventType() const throw()
  22610. {
  22611. if (*data != 0xff)
  22612. return -1;
  22613. else
  22614. return data[1];
  22615. }
  22616. int MidiMessage::getMetaEventLength() const throw()
  22617. {
  22618. if (*data == 0xff)
  22619. {
  22620. int n;
  22621. return jmin (size - 2, readVariableLengthVal (data + 2, n));
  22622. }
  22623. return 0;
  22624. }
  22625. const uint8* MidiMessage::getMetaEventData() const throw()
  22626. {
  22627. int n;
  22628. const uint8* d = data + 2;
  22629. readVariableLengthVal (d, n);
  22630. return d + n;
  22631. }
  22632. bool MidiMessage::isTrackMetaEvent() const throw()
  22633. {
  22634. return getMetaEventType() == 0;
  22635. }
  22636. bool MidiMessage::isEndOfTrackMetaEvent() const throw()
  22637. {
  22638. return getMetaEventType() == 47;
  22639. }
  22640. bool MidiMessage::isTextMetaEvent() const throw()
  22641. {
  22642. const int t = getMetaEventType();
  22643. return t > 0 && t < 16;
  22644. }
  22645. const String MidiMessage::getTextFromTextMetaEvent() const throw()
  22646. {
  22647. return String ((const char*) getMetaEventData(),
  22648. getMetaEventLength());
  22649. }
  22650. bool MidiMessage::isTrackNameEvent() const throw()
  22651. {
  22652. return (data[1] == 3)
  22653. && (*data == 0xff);
  22654. }
  22655. bool MidiMessage::isTempoMetaEvent() const throw()
  22656. {
  22657. return (data[1] == 81)
  22658. && (*data == 0xff);
  22659. }
  22660. bool MidiMessage::isMidiChannelMetaEvent() const throw()
  22661. {
  22662. return (data[1] == 0x20)
  22663. && (*data == 0xff)
  22664. && (data[2] == 1);
  22665. }
  22666. int MidiMessage::getMidiChannelMetaEventChannel() const throw()
  22667. {
  22668. return data[3] + 1;
  22669. }
  22670. double MidiMessage::getTempoSecondsPerQuarterNote() const throw()
  22671. {
  22672. if (! isTempoMetaEvent())
  22673. return 0.0;
  22674. const uint8* const d = getMetaEventData();
  22675. return (((unsigned int) d[0] << 16)
  22676. | ((unsigned int) d[1] << 8)
  22677. | d[2])
  22678. / 1000000.0;
  22679. }
  22680. double MidiMessage::getTempoMetaEventTickLength (const short timeFormat) const throw()
  22681. {
  22682. if (timeFormat > 0)
  22683. {
  22684. if (! isTempoMetaEvent())
  22685. return 0.5 / timeFormat;
  22686. return getTempoSecondsPerQuarterNote() / timeFormat;
  22687. }
  22688. else
  22689. {
  22690. const int frameCode = (-timeFormat) >> 8;
  22691. double framesPerSecond;
  22692. switch (frameCode)
  22693. {
  22694. case 24: framesPerSecond = 24.0; break;
  22695. case 25: framesPerSecond = 25.0; break;
  22696. case 29: framesPerSecond = 29.97; break;
  22697. case 30: framesPerSecond = 30.0; break;
  22698. default: framesPerSecond = 30.0; break;
  22699. }
  22700. return (1.0 / framesPerSecond) / (timeFormat & 0xff);
  22701. }
  22702. }
  22703. const MidiMessage MidiMessage::tempoMetaEvent (int microsecondsPerQuarterNote) throw()
  22704. {
  22705. uint8 d[8];
  22706. d[0] = 0xff;
  22707. d[1] = 81;
  22708. d[2] = 3;
  22709. d[3] = (uint8) (microsecondsPerQuarterNote >> 16);
  22710. d[4] = (uint8) ((microsecondsPerQuarterNote >> 8) & 0xff);
  22711. d[5] = (uint8) (microsecondsPerQuarterNote & 0xff);
  22712. return MidiMessage (d, 6, 0.0);
  22713. }
  22714. bool MidiMessage::isTimeSignatureMetaEvent() const throw()
  22715. {
  22716. return (data[1] == 0x58)
  22717. && (*data == (uint8) 0xff);
  22718. }
  22719. void MidiMessage::getTimeSignatureInfo (int& numerator,
  22720. int& denominator) const throw()
  22721. {
  22722. if (isTimeSignatureMetaEvent())
  22723. {
  22724. const uint8* const d = getMetaEventData();
  22725. numerator = d[0];
  22726. denominator = 1 << d[1];
  22727. }
  22728. else
  22729. {
  22730. numerator = 4;
  22731. denominator = 4;
  22732. }
  22733. }
  22734. const MidiMessage MidiMessage::timeSignatureMetaEvent (const int numerator,
  22735. const int denominator) throw()
  22736. {
  22737. uint8 d[8];
  22738. d[0] = 0xff;
  22739. d[1] = 0x58;
  22740. d[2] = 0x04;
  22741. d[3] = (uint8) numerator;
  22742. int n = 1;
  22743. int powerOfTwo = 0;
  22744. while (n < denominator)
  22745. {
  22746. n <<= 1;
  22747. ++powerOfTwo;
  22748. }
  22749. d[4] = (uint8) powerOfTwo;
  22750. d[5] = 0x01;
  22751. d[6] = 96;
  22752. return MidiMessage (d, 7, 0.0);
  22753. }
  22754. const MidiMessage MidiMessage::midiChannelMetaEvent (const int channel) throw()
  22755. {
  22756. uint8 d[8];
  22757. d[0] = 0xff;
  22758. d[1] = 0x20;
  22759. d[2] = 0x01;
  22760. d[3] = (uint8) jlimit (0, 0xff, channel - 1);
  22761. return MidiMessage (d, 4, 0.0);
  22762. }
  22763. bool MidiMessage::isKeySignatureMetaEvent() const throw()
  22764. {
  22765. return getMetaEventType() == 89;
  22766. }
  22767. int MidiMessage::getKeySignatureNumberOfSharpsOrFlats() const throw()
  22768. {
  22769. return (int) *getMetaEventData();
  22770. }
  22771. const MidiMessage MidiMessage::endOfTrack() throw()
  22772. {
  22773. return MidiMessage (0xff, 0x2f, 0, 0.0);
  22774. }
  22775. bool MidiMessage::isSongPositionPointer() const throw()
  22776. {
  22777. return *data == 0xf2;
  22778. }
  22779. int MidiMessage::getSongPositionPointerMidiBeat() const throw()
  22780. {
  22781. return data[1] | (data[2] << 7);
  22782. }
  22783. const MidiMessage MidiMessage::songPositionPointer (const int positionInMidiBeats) throw()
  22784. {
  22785. return MidiMessage (0xf2,
  22786. positionInMidiBeats & 127,
  22787. (positionInMidiBeats >> 7) & 127);
  22788. }
  22789. bool MidiMessage::isMidiStart() const throw()
  22790. {
  22791. return *data == 0xfa;
  22792. }
  22793. const MidiMessage MidiMessage::midiStart() throw()
  22794. {
  22795. return MidiMessage (0xfa);
  22796. }
  22797. bool MidiMessage::isMidiContinue() const throw()
  22798. {
  22799. return *data == 0xfb;
  22800. }
  22801. const MidiMessage MidiMessage::midiContinue() throw()
  22802. {
  22803. return MidiMessage (0xfb);
  22804. }
  22805. bool MidiMessage::isMidiStop() const throw()
  22806. {
  22807. return *data == 0xfc;
  22808. }
  22809. const MidiMessage MidiMessage::midiStop() throw()
  22810. {
  22811. return MidiMessage (0xfc);
  22812. }
  22813. bool MidiMessage::isMidiClock() const throw()
  22814. {
  22815. return *data == 0xf8;
  22816. }
  22817. const MidiMessage MidiMessage::midiClock() throw()
  22818. {
  22819. return MidiMessage (0xf8);
  22820. }
  22821. bool MidiMessage::isQuarterFrame() const throw()
  22822. {
  22823. return *data == 0xf1;
  22824. }
  22825. int MidiMessage::getQuarterFrameSequenceNumber() const throw()
  22826. {
  22827. return ((int) data[1]) >> 4;
  22828. }
  22829. int MidiMessage::getQuarterFrameValue() const throw()
  22830. {
  22831. return ((int) data[1]) & 0x0f;
  22832. }
  22833. const MidiMessage MidiMessage::quarterFrame (const int sequenceNumber,
  22834. const int value) throw()
  22835. {
  22836. return MidiMessage (0xf1, (sequenceNumber << 4) | value);
  22837. }
  22838. bool MidiMessage::isFullFrame() const throw()
  22839. {
  22840. return data[0] == 0xf0
  22841. && data[1] == 0x7f
  22842. && size >= 10
  22843. && data[3] == 0x01
  22844. && data[4] == 0x01;
  22845. }
  22846. void MidiMessage::getFullFrameParameters (int& hours,
  22847. int& minutes,
  22848. int& seconds,
  22849. int& frames,
  22850. MidiMessage::SmpteTimecodeType& timecodeType) const throw()
  22851. {
  22852. jassert (isFullFrame());
  22853. timecodeType = (SmpteTimecodeType) (data[5] >> 5);
  22854. hours = data[5] & 0x1f;
  22855. minutes = data[6];
  22856. seconds = data[7];
  22857. frames = data[8];
  22858. }
  22859. const MidiMessage MidiMessage::fullFrame (const int hours,
  22860. const int minutes,
  22861. const int seconds,
  22862. const int frames,
  22863. MidiMessage::SmpteTimecodeType timecodeType)
  22864. {
  22865. uint8 d[10];
  22866. d[0] = 0xf0;
  22867. d[1] = 0x7f;
  22868. d[2] = 0x7f;
  22869. d[3] = 0x01;
  22870. d[4] = 0x01;
  22871. d[5] = (uint8) ((hours & 0x01f) | (timecodeType << 5));
  22872. d[6] = (uint8) minutes;
  22873. d[7] = (uint8) seconds;
  22874. d[8] = (uint8) frames;
  22875. d[9] = 0xf7;
  22876. return MidiMessage (d, 10, 0.0);
  22877. }
  22878. bool MidiMessage::isMidiMachineControlMessage() const throw()
  22879. {
  22880. return data[0] == 0xf0
  22881. && data[1] == 0x7f
  22882. && data[3] == 0x06
  22883. && size > 5;
  22884. }
  22885. MidiMessage::MidiMachineControlCommand MidiMessage::getMidiMachineControlCommand() const throw()
  22886. {
  22887. jassert (isMidiMachineControlMessage());
  22888. return (MidiMachineControlCommand) data[4];
  22889. }
  22890. const MidiMessage MidiMessage::midiMachineControlCommand (MidiMessage::MidiMachineControlCommand command)
  22891. {
  22892. uint8 d[6];
  22893. d[0] = 0xf0;
  22894. d[1] = 0x7f;
  22895. d[2] = 0x00;
  22896. d[3] = 0x06;
  22897. d[4] = (uint8) command;
  22898. d[5] = 0xf7;
  22899. return MidiMessage (d, 6, 0.0);
  22900. }
  22901. bool MidiMessage::isMidiMachineControlGoto (int& hours,
  22902. int& minutes,
  22903. int& seconds,
  22904. int& frames) const throw()
  22905. {
  22906. if (size >= 12
  22907. && data[0] == 0xf0
  22908. && data[1] == 0x7f
  22909. && data[3] == 0x06
  22910. && data[4] == 0x44
  22911. && data[5] == 0x06
  22912. && data[6] == 0x01)
  22913. {
  22914. hours = data[7] % 24; // (that some machines send out hours > 24)
  22915. minutes = data[8];
  22916. seconds = data[9];
  22917. frames = data[10];
  22918. return true;
  22919. }
  22920. return false;
  22921. }
  22922. const MidiMessage MidiMessage::midiMachineControlGoto (int hours,
  22923. int minutes,
  22924. int seconds,
  22925. int frames)
  22926. {
  22927. uint8 d[12];
  22928. d[0] = 0xf0;
  22929. d[1] = 0x7f;
  22930. d[2] = 0x00;
  22931. d[3] = 0x06;
  22932. d[4] = 0x44;
  22933. d[5] = 0x06;
  22934. d[6] = 0x01;
  22935. d[7] = (uint8) hours;
  22936. d[8] = (uint8) minutes;
  22937. d[9] = (uint8) seconds;
  22938. d[10] = (uint8) frames;
  22939. d[11] = 0xf7;
  22940. return MidiMessage (d, 12, 0.0);
  22941. }
  22942. const String MidiMessage::getMidiNoteName (int note,
  22943. bool useSharps,
  22944. bool includeOctaveNumber,
  22945. int octaveNumForMiddleC) throw()
  22946. {
  22947. static const char* const sharpNoteNames[] = { "C", "C#", "D", "D#", "E",
  22948. "F", "F#", "G", "G#", "A",
  22949. "A#", "B" };
  22950. static const char* const flatNoteNames[] = { "C", "Db", "D", "Eb", "E",
  22951. "F", "Gb", "G", "Ab", "A",
  22952. "Bb", "B" };
  22953. if (((unsigned int) note) < 128)
  22954. {
  22955. const String s ((useSharps) ? sharpNoteNames [note % 12]
  22956. : flatNoteNames [note % 12]);
  22957. if (includeOctaveNumber)
  22958. return s + String (note / 12 + (octaveNumForMiddleC - 5));
  22959. else
  22960. return s;
  22961. }
  22962. return String::empty;
  22963. }
  22964. const double MidiMessage::getMidiNoteInHertz (int noteNumber) throw()
  22965. {
  22966. noteNumber -= 12 * 6 + 9; // now 0 = A440
  22967. return 440.0 * pow (2.0, noteNumber / 12.0);
  22968. }
  22969. const String MidiMessage::getGMInstrumentName (int n) throw()
  22970. {
  22971. const char *names[] =
  22972. {
  22973. "Acoustic Grand Piano", "Bright Acoustic Piano", "Electric Grand Piano", "Honky-tonk Piano",
  22974. "Electric Piano 1", "Electric Piano 2", "Harpsichord", "Clavinet", "Celesta", "Glockenspiel",
  22975. "Music Box", "Vibraphone", "Marimba", "Xylophone", "Tubular Bells", "Dulcimer", "Drawbar Organ",
  22976. "Percussive Organ", "Rock Organ", "Church Organ", "Reed Organ", "Accordion", "Harmonica",
  22977. "Tango Accordion", "Acoustic Guitar (nylon)", "Acoustic Guitar (steel)", "Electric Guitar (jazz)",
  22978. "Electric Guitar (clean)", "Electric Guitar (mute)", "Overdriven Guitar", "Distortion Guitar",
  22979. "Guitar Harmonics", "Acoustic Bass", "Electric Bass (finger)", "Electric Bass (pick)",
  22980. "Fretless Bass", "Slap Bass 1", "Slap Bass 2", "Synth Bass 1", "Synth Bass 2", "Violin",
  22981. "Viola", "Cello", "Contrabass", "Tremolo Strings", "Pizzicato Strings", "Orchestral Harp",
  22982. "Timpani", "String Ensemble 1", "String Ensemble 2", "SynthStrings 1", "SynthStrings 2",
  22983. "Choir Aahs", "Voice Oohs", "Synth Voice", "Orchestra Hit", "Trumpet", "Trombone", "Tuba",
  22984. "Muted Trumpet", "French Horn", "Brass Section", "SynthBrass 1", "SynthBrass 2", "Soprano Sax",
  22985. "Alto Sax", "Tenor Sax", "Baritone Sax", "Oboe", "English Horn", "Bassoon", "Clarinet",
  22986. "Piccolo", "Flute", "Recorder", "Pan Flute", "Blown Bottle", "Shakuhachi", "Whistle",
  22987. "Ocarina", "Lead 1 (square)", "Lead 2 (sawtooth)", "Lead 3 (calliope)", "Lead 4 (chiff)",
  22988. "Lead 5 (charang)", "Lead 6 (voice)", "Lead 7 (fifths)", "Lead 8 (bass+lead)", "Pad 1 (new age)",
  22989. "Pad 2 (warm)", "Pad 3 (polysynth)", "Pad 4 (choir)", "Pad 5 (bowed)", "Pad 6 (metallic)",
  22990. "Pad 7 (halo)", "Pad 8 (sweep)", "FX 1 (rain)", "FX 2 (soundtrack)", "FX 3 (crystal)",
  22991. "FX 4 (atmosphere)", "FX 5 (brightness)", "FX 6 (goblins)", "FX 7 (echoes)", "FX 8 (sci-fi)",
  22992. "Sitar", "Banjo", "Shamisen", "Koto", "Kalimba", "Bag pipe", "Fiddle", "Shanai", "Tinkle Bell",
  22993. "Agogo", "Steel Drums", "Woodblock", "Taiko Drum", "Melodic Tom", "Synth Drum", "Reverse Cymbal",
  22994. "Guitar Fret Noise", "Breath Noise", "Seashore", "Bird Tweet", "Telephone Ring", "Helicopter",
  22995. "Applause", "Gunshot"
  22996. };
  22997. return (((unsigned int) n) < 128) ? names[n]
  22998. : (const char*)0;
  22999. }
  23000. const String MidiMessage::getGMInstrumentBankName (int n) throw()
  23001. {
  23002. const char* names[] =
  23003. {
  23004. "Piano", "Chromatic Percussion", "Organ", "Guitar",
  23005. "Bass", "Strings", "Ensemble", "Brass",
  23006. "Reed", "Pipe", "Synth Lead", "Synth Pad",
  23007. "Synth Effects", "Ethnic", "Percussive", "Sound Effects"
  23008. };
  23009. return (((unsigned int) n) <= 15) ? names[n]
  23010. : (const char*)0;
  23011. }
  23012. const String MidiMessage::getRhythmInstrumentName (int n) throw()
  23013. {
  23014. const char* names[] =
  23015. {
  23016. "Acoustic Bass Drum", "Bass Drum 1", "Side Stick", "Acoustic Snare",
  23017. "Hand Clap", "Electric Snare", "Low Floor Tom", "Closed Hi-Hat", "High Floor Tom",
  23018. "Pedal Hi-Hat", "Low Tom", "Open Hi-Hat", "Low-Mid Tom", "Hi-Mid Tom", "Crash Cymbal 1",
  23019. "High Tom", "Ride Cymbal 1", "Chinese Cymbal", "Ride Bell", "Tambourine", "Splash Cymbal",
  23020. "Cowbell", "Crash Cymbal 2", "Vibraslap", "Ride Cymbal 2", "Hi Bongo", "Low Bongo",
  23021. "Mute Hi Conga", "Open Hi Conga", "Low Conga", "High Timbale", "Low Timbale", "High Agogo",
  23022. "Low Agogo", "Cabasa", "Maracas", "Short Whistle", "Long Whistle", "Short Guiro",
  23023. "Long Guiro", "Claves", "Hi Wood Block", "Low Wood Block", "Mute Cuica", "Open Cuica",
  23024. "Mute Triangle", "Open Triangle"
  23025. };
  23026. return (n >= 35 && n <= 81) ? names [n - 35]
  23027. : (const char*)0;
  23028. }
  23029. const String MidiMessage::getControllerName (int n) throw()
  23030. {
  23031. const char* names[] =
  23032. {
  23033. "Bank Select", "Modulation Wheel (coarse)", "Breath controller (coarse)",
  23034. 0, "Foot Pedal (coarse)", "Portamento Time (coarse)",
  23035. "Data Entry (coarse)", "Volume (coarse)", "Balance (coarse)",
  23036. 0, "Pan position (coarse)", "Expression (coarse)", "Effect Control 1 (coarse)",
  23037. "Effect Control 2 (coarse)", 0, 0, "General Purpose Slider 1", "General Purpose Slider 2",
  23038. "General Purpose Slider 3", "General Purpose Slider 4", 0, 0, 0, 0, 0, 0, 0, 0,
  23039. 0, 0, 0, 0, "Bank Select (fine)", "Modulation Wheel (fine)", "Breath controller (fine)",
  23040. 0, "Foot Pedal (fine)", "Portamento Time (fine)", "Data Entry (fine)", "Volume (fine)",
  23041. "Balance (fine)", 0, "Pan position (fine)", "Expression (fine)", "Effect Control 1 (fine)",
  23042. "Effect Control 2 (fine)", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  23043. "Hold Pedal (on/off)", "Portamento (on/off)", "Sustenuto Pedal (on/off)", "Soft Pedal (on/off)",
  23044. "Legato Pedal (on/off)", "Hold 2 Pedal (on/off)", "Sound Variation", "Sound Timbre",
  23045. "Sound Release Time", "Sound Attack Time", "Sound Brightness", "Sound Control 6",
  23046. "Sound Control 7", "Sound Control 8", "Sound Control 9", "Sound Control 10",
  23047. "General Purpose Button 1 (on/off)", "General Purpose Button 2 (on/off)",
  23048. "General Purpose Button 3 (on/off)", "General Purpose Button 4 (on/off)",
  23049. 0, 0, 0, 0, 0, 0, 0, "Reverb Level", "Tremolo Level", "Chorus Level", "Celeste Level",
  23050. "Phaser Level", "Data Button increment", "Data Button decrement", "Non-registered Parameter (fine)",
  23051. "Non-registered Parameter (coarse)", "Registered Parameter (fine)", "Registered Parameter (coarse)",
  23052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "All Sound Off", "All Controllers Off",
  23053. "Local Keyboard (on/off)", "All Notes Off", "Omni Mode Off", "Omni Mode On", "Mono Operation",
  23054. "Poly Operation"
  23055. };
  23056. return (((unsigned int) n) < 128) ? names[n]
  23057. : (const char*)0;
  23058. }
  23059. END_JUCE_NAMESPACE
  23060. /*** End of inlined file: juce_MidiMessage.cpp ***/
  23061. /*** Start of inlined file: juce_MidiMessageCollector.cpp ***/
  23062. BEGIN_JUCE_NAMESPACE
  23063. MidiMessageCollector::MidiMessageCollector()
  23064. : lastCallbackTime (0),
  23065. sampleRate (44100.0001)
  23066. {
  23067. }
  23068. MidiMessageCollector::~MidiMessageCollector()
  23069. {
  23070. }
  23071. void MidiMessageCollector::reset (const double sampleRate_)
  23072. {
  23073. jassert (sampleRate_ > 0);
  23074. const ScopedLock sl (midiCallbackLock);
  23075. sampleRate = sampleRate_;
  23076. incomingMessages.clear();
  23077. lastCallbackTime = Time::getMillisecondCounterHiRes();
  23078. }
  23079. void MidiMessageCollector::addMessageToQueue (const MidiMessage& message)
  23080. {
  23081. // you need to call reset() to set the correct sample rate before using this object
  23082. jassert (sampleRate != 44100.0001);
  23083. // the messages that come in here need to be time-stamped correctly - see MidiInput
  23084. // for details of what the number should be.
  23085. jassert (message.getTimeStamp() != 0);
  23086. const ScopedLock sl (midiCallbackLock);
  23087. const int sampleNumber
  23088. = (int) ((message.getTimeStamp() - 0.001 * lastCallbackTime) * sampleRate);
  23089. incomingMessages.addEvent (message, sampleNumber);
  23090. // if the messages don't get used for over a second, we'd better
  23091. // get rid of any old ones to avoid the queue getting too big
  23092. if (sampleNumber > sampleRate)
  23093. incomingMessages.clear (0, sampleNumber - (int) sampleRate);
  23094. }
  23095. void MidiMessageCollector::removeNextBlockOfMessages (MidiBuffer& destBuffer,
  23096. const int numSamples)
  23097. {
  23098. // you need to call reset() to set the correct sample rate before using this object
  23099. jassert (sampleRate != 44100.0001);
  23100. const double timeNow = Time::getMillisecondCounterHiRes();
  23101. const double msElapsed = timeNow - lastCallbackTime;
  23102. const ScopedLock sl (midiCallbackLock);
  23103. lastCallbackTime = timeNow;
  23104. if (! incomingMessages.isEmpty())
  23105. {
  23106. int numSourceSamples = jmax (1, roundToInt (msElapsed * 0.001 * sampleRate));
  23107. int startSample = 0;
  23108. int scale = 1 << 16;
  23109. const uint8* midiData;
  23110. int numBytes, samplePosition;
  23111. MidiBuffer::Iterator iter (incomingMessages);
  23112. if (numSourceSamples > numSamples)
  23113. {
  23114. // if our list of events is longer than the buffer we're being
  23115. // asked for, scale them down to squeeze them all in..
  23116. const int maxBlockLengthToUse = numSamples << 5;
  23117. if (numSourceSamples > maxBlockLengthToUse)
  23118. {
  23119. startSample = numSourceSamples - maxBlockLengthToUse;
  23120. numSourceSamples = maxBlockLengthToUse;
  23121. iter.setNextSamplePosition (startSample);
  23122. }
  23123. scale = (numSamples << 10) / numSourceSamples;
  23124. while (iter.getNextEvent (midiData, numBytes, samplePosition))
  23125. {
  23126. samplePosition = ((samplePosition - startSample) * scale) >> 10;
  23127. destBuffer.addEvent (midiData, numBytes,
  23128. jlimit (0, numSamples - 1, samplePosition));
  23129. }
  23130. }
  23131. else
  23132. {
  23133. // if our event list is shorter than the number we need, put them
  23134. // towards the end of the buffer
  23135. startSample = numSamples - numSourceSamples;
  23136. while (iter.getNextEvent (midiData, numBytes, samplePosition))
  23137. {
  23138. destBuffer.addEvent (midiData, numBytes,
  23139. jlimit (0, numSamples - 1, samplePosition + startSample));
  23140. }
  23141. }
  23142. incomingMessages.clear();
  23143. }
  23144. }
  23145. void MidiMessageCollector::handleNoteOn (MidiKeyboardState*, int midiChannel, int midiNoteNumber, float velocity)
  23146. {
  23147. MidiMessage m (MidiMessage::noteOn (midiChannel, midiNoteNumber, velocity));
  23148. m.setTimeStamp (Time::getMillisecondCounterHiRes() * 0.001);
  23149. addMessageToQueue (m);
  23150. }
  23151. void MidiMessageCollector::handleNoteOff (MidiKeyboardState*, int midiChannel, int midiNoteNumber)
  23152. {
  23153. MidiMessage m (MidiMessage::noteOff (midiChannel, midiNoteNumber));
  23154. m.setTimeStamp (Time::getMillisecondCounterHiRes() * 0.001);
  23155. addMessageToQueue (m);
  23156. }
  23157. void MidiMessageCollector::handleIncomingMidiMessage (MidiInput*, const MidiMessage& message)
  23158. {
  23159. addMessageToQueue (message);
  23160. }
  23161. END_JUCE_NAMESPACE
  23162. /*** End of inlined file: juce_MidiMessageCollector.cpp ***/
  23163. /*** Start of inlined file: juce_MidiMessageSequence.cpp ***/
  23164. BEGIN_JUCE_NAMESPACE
  23165. MidiMessageSequence::MidiMessageSequence()
  23166. {
  23167. }
  23168. MidiMessageSequence::MidiMessageSequence (const MidiMessageSequence& other)
  23169. {
  23170. list.ensureStorageAllocated (other.list.size());
  23171. for (int i = 0; i < other.list.size(); ++i)
  23172. list.add (new MidiEventHolder (other.list.getUnchecked(i)->message));
  23173. }
  23174. MidiMessageSequence& MidiMessageSequence::operator= (const MidiMessageSequence& other)
  23175. {
  23176. MidiMessageSequence otherCopy (other);
  23177. swapWith (otherCopy);
  23178. return *this;
  23179. }
  23180. void MidiMessageSequence::swapWith (MidiMessageSequence& other) throw()
  23181. {
  23182. list.swapWithArray (other.list);
  23183. }
  23184. MidiMessageSequence::~MidiMessageSequence()
  23185. {
  23186. }
  23187. void MidiMessageSequence::clear()
  23188. {
  23189. list.clear();
  23190. }
  23191. int MidiMessageSequence::getNumEvents() const
  23192. {
  23193. return list.size();
  23194. }
  23195. MidiMessageSequence::MidiEventHolder* MidiMessageSequence::getEventPointer (const int index) const
  23196. {
  23197. return list [index];
  23198. }
  23199. double MidiMessageSequence::getTimeOfMatchingKeyUp (const int index) const
  23200. {
  23201. const MidiEventHolder* const meh = list [index];
  23202. if (meh != 0 && meh->noteOffObject != 0)
  23203. return meh->noteOffObject->message.getTimeStamp();
  23204. else
  23205. return 0.0;
  23206. }
  23207. int MidiMessageSequence::getIndexOfMatchingKeyUp (const int index) const
  23208. {
  23209. const MidiEventHolder* const meh = list [index];
  23210. return (meh != 0) ? list.indexOf (meh->noteOffObject) : -1;
  23211. }
  23212. int MidiMessageSequence::getIndexOf (MidiEventHolder* const event) const
  23213. {
  23214. return list.indexOf (event);
  23215. }
  23216. int MidiMessageSequence::getNextIndexAtTime (const double timeStamp) const
  23217. {
  23218. const int numEvents = list.size();
  23219. int i;
  23220. for (i = 0; i < numEvents; ++i)
  23221. if (list.getUnchecked(i)->message.getTimeStamp() >= timeStamp)
  23222. break;
  23223. return i;
  23224. }
  23225. double MidiMessageSequence::getStartTime() const
  23226. {
  23227. if (list.size() > 0)
  23228. return list.getUnchecked(0)->message.getTimeStamp();
  23229. else
  23230. return 0;
  23231. }
  23232. double MidiMessageSequence::getEndTime() const
  23233. {
  23234. if (list.size() > 0)
  23235. return list.getLast()->message.getTimeStamp();
  23236. else
  23237. return 0;
  23238. }
  23239. double MidiMessageSequence::getEventTime (const int index) const
  23240. {
  23241. if (((unsigned int) index) < (unsigned int) list.size())
  23242. return list.getUnchecked (index)->message.getTimeStamp();
  23243. return 0.0;
  23244. }
  23245. void MidiMessageSequence::addEvent (const MidiMessage& newMessage,
  23246. double timeAdjustment)
  23247. {
  23248. MidiEventHolder* const newOne = new MidiEventHolder (newMessage);
  23249. timeAdjustment += newMessage.getTimeStamp();
  23250. newOne->message.setTimeStamp (timeAdjustment);
  23251. int i;
  23252. for (i = list.size(); --i >= 0;)
  23253. if (list.getUnchecked(i)->message.getTimeStamp() <= timeAdjustment)
  23254. break;
  23255. list.insert (i + 1, newOne);
  23256. }
  23257. void MidiMessageSequence::deleteEvent (const int index,
  23258. const bool deleteMatchingNoteUp)
  23259. {
  23260. if (((unsigned int) index) < (unsigned int) list.size())
  23261. {
  23262. if (deleteMatchingNoteUp)
  23263. deleteEvent (getIndexOfMatchingKeyUp (index), false);
  23264. list.remove (index);
  23265. }
  23266. }
  23267. void MidiMessageSequence::addSequence (const MidiMessageSequence& other,
  23268. double timeAdjustment,
  23269. double firstAllowableTime,
  23270. double endOfAllowableDestTimes)
  23271. {
  23272. firstAllowableTime -= timeAdjustment;
  23273. endOfAllowableDestTimes -= timeAdjustment;
  23274. for (int i = 0; i < other.list.size(); ++i)
  23275. {
  23276. const MidiMessage& m = other.list.getUnchecked(i)->message;
  23277. const double t = m.getTimeStamp();
  23278. if (t >= firstAllowableTime && t < endOfAllowableDestTimes)
  23279. {
  23280. MidiEventHolder* const newOne = new MidiEventHolder (m);
  23281. newOne->message.setTimeStamp (timeAdjustment + t);
  23282. list.add (newOne);
  23283. }
  23284. }
  23285. sort();
  23286. }
  23287. int MidiMessageSequence::compareElements (const MidiMessageSequence::MidiEventHolder* const first,
  23288. const MidiMessageSequence::MidiEventHolder* const second) throw()
  23289. {
  23290. const double diff = first->message.getTimeStamp()
  23291. - second->message.getTimeStamp();
  23292. return (diff > 0) - (diff < 0);
  23293. }
  23294. void MidiMessageSequence::sort()
  23295. {
  23296. list.sort (*this, true);
  23297. }
  23298. void MidiMessageSequence::updateMatchedPairs()
  23299. {
  23300. for (int i = 0; i < list.size(); ++i)
  23301. {
  23302. const MidiMessage& m1 = list.getUnchecked(i)->message;
  23303. if (m1.isNoteOn())
  23304. {
  23305. list.getUnchecked(i)->noteOffObject = 0;
  23306. const int note = m1.getNoteNumber();
  23307. const int chan = m1.getChannel();
  23308. const int len = list.size();
  23309. for (int j = i + 1; j < len; ++j)
  23310. {
  23311. const MidiMessage& m = list.getUnchecked(j)->message;
  23312. if (m.getNoteNumber() == note && m.getChannel() == chan)
  23313. {
  23314. if (m.isNoteOff())
  23315. {
  23316. list.getUnchecked(i)->noteOffObject = list[j];
  23317. break;
  23318. }
  23319. else if (m.isNoteOn())
  23320. {
  23321. list.insert (j, new MidiEventHolder (MidiMessage::noteOff (chan, note)));
  23322. list.getUnchecked(j)->message.setTimeStamp (m.getTimeStamp());
  23323. list.getUnchecked(i)->noteOffObject = list[j];
  23324. break;
  23325. }
  23326. }
  23327. }
  23328. }
  23329. }
  23330. }
  23331. void MidiMessageSequence::addTimeToMessages (const double delta)
  23332. {
  23333. for (int i = list.size(); --i >= 0;)
  23334. list.getUnchecked (i)->message.setTimeStamp (list.getUnchecked (i)->message.getTimeStamp()
  23335. + delta);
  23336. }
  23337. void MidiMessageSequence::extractMidiChannelMessages (const int channelNumberToExtract,
  23338. MidiMessageSequence& destSequence,
  23339. const bool alsoIncludeMetaEvents) const
  23340. {
  23341. for (int i = 0; i < list.size(); ++i)
  23342. {
  23343. const MidiMessage& mm = list.getUnchecked(i)->message;
  23344. if (mm.isForChannel (channelNumberToExtract)
  23345. || (alsoIncludeMetaEvents && mm.isMetaEvent()))
  23346. {
  23347. destSequence.addEvent (mm);
  23348. }
  23349. }
  23350. }
  23351. void MidiMessageSequence::extractSysExMessages (MidiMessageSequence& destSequence) const
  23352. {
  23353. for (int i = 0; i < list.size(); ++i)
  23354. {
  23355. const MidiMessage& mm = list.getUnchecked(i)->message;
  23356. if (mm.isSysEx())
  23357. destSequence.addEvent (mm);
  23358. }
  23359. }
  23360. void MidiMessageSequence::deleteMidiChannelMessages (const int channelNumberToRemove)
  23361. {
  23362. for (int i = list.size(); --i >= 0;)
  23363. if (list.getUnchecked(i)->message.isForChannel (channelNumberToRemove))
  23364. list.remove(i);
  23365. }
  23366. void MidiMessageSequence::deleteSysExMessages()
  23367. {
  23368. for (int i = list.size(); --i >= 0;)
  23369. if (list.getUnchecked(i)->message.isSysEx())
  23370. list.remove(i);
  23371. }
  23372. void MidiMessageSequence::createControllerUpdatesForTime (const int channelNumber,
  23373. const double time,
  23374. OwnedArray<MidiMessage>& dest)
  23375. {
  23376. bool doneProg = false;
  23377. bool donePitchWheel = false;
  23378. Array <int> doneControllers;
  23379. doneControllers.ensureStorageAllocated (32);
  23380. for (int i = list.size(); --i >= 0;)
  23381. {
  23382. const MidiMessage& mm = list.getUnchecked(i)->message;
  23383. if (mm.isForChannel (channelNumber)
  23384. && mm.getTimeStamp() <= time)
  23385. {
  23386. if (mm.isProgramChange())
  23387. {
  23388. if (! doneProg)
  23389. {
  23390. dest.add (new MidiMessage (mm, 0.0));
  23391. doneProg = true;
  23392. }
  23393. }
  23394. else if (mm.isController())
  23395. {
  23396. if (! doneControllers.contains (mm.getControllerNumber()))
  23397. {
  23398. dest.add (new MidiMessage (mm, 0.0));
  23399. doneControllers.add (mm.getControllerNumber());
  23400. }
  23401. }
  23402. else if (mm.isPitchWheel())
  23403. {
  23404. if (! donePitchWheel)
  23405. {
  23406. dest.add (new MidiMessage (mm, 0.0));
  23407. donePitchWheel = true;
  23408. }
  23409. }
  23410. }
  23411. }
  23412. }
  23413. MidiMessageSequence::MidiEventHolder::MidiEventHolder (const MidiMessage& message_)
  23414. : message (message_),
  23415. noteOffObject (0)
  23416. {
  23417. }
  23418. MidiMessageSequence::MidiEventHolder::~MidiEventHolder()
  23419. {
  23420. }
  23421. END_JUCE_NAMESPACE
  23422. /*** End of inlined file: juce_MidiMessageSequence.cpp ***/
  23423. /*** Start of inlined file: juce_AudioPluginFormat.cpp ***/
  23424. BEGIN_JUCE_NAMESPACE
  23425. AudioPluginFormat::AudioPluginFormat() throw()
  23426. {
  23427. }
  23428. AudioPluginFormat::~AudioPluginFormat()
  23429. {
  23430. }
  23431. END_JUCE_NAMESPACE
  23432. /*** End of inlined file: juce_AudioPluginFormat.cpp ***/
  23433. /*** Start of inlined file: juce_AudioPluginFormatManager.cpp ***/
  23434. BEGIN_JUCE_NAMESPACE
  23435. AudioPluginFormatManager::AudioPluginFormatManager() throw()
  23436. {
  23437. }
  23438. AudioPluginFormatManager::~AudioPluginFormatManager() throw()
  23439. {
  23440. clearSingletonInstance();
  23441. }
  23442. juce_ImplementSingleton_SingleThreaded (AudioPluginFormatManager);
  23443. void AudioPluginFormatManager::addDefaultFormats()
  23444. {
  23445. #ifdef JUCE_DEBUG
  23446. // you should only call this method once!
  23447. for (int i = formats.size(); --i >= 0;)
  23448. {
  23449. #if JUCE_PLUGINHOST_VST
  23450. jassert (dynamic_cast <VSTPluginFormat*> (formats[i]) == 0);
  23451. #endif
  23452. #if JUCE_PLUGINHOST_AU && JUCE_MAC
  23453. jassert (dynamic_cast <AudioUnitPluginFormat*> (formats[i]) == 0);
  23454. #endif
  23455. #if JUCE_PLUGINHOST_DX && JUCE_WIN32
  23456. jassert (dynamic_cast <DirectXPluginFormat*> (formats[i]) == 0);
  23457. #endif
  23458. #if JUCE_PLUGINHOST_LADSPA && JUCE_LINUX
  23459. jassert (dynamic_cast <LADSPAPluginFormat*> (formats[i]) == 0);
  23460. #endif
  23461. }
  23462. #endif
  23463. #if JUCE_PLUGINHOST_AU && JUCE_MAC
  23464. formats.add (new AudioUnitPluginFormat());
  23465. #endif
  23466. #if JUCE_PLUGINHOST_VST
  23467. formats.add (new VSTPluginFormat());
  23468. #endif
  23469. #if JUCE_PLUGINHOST_DX && JUCE_WIN32
  23470. formats.add (new DirectXPluginFormat());
  23471. #endif
  23472. #if JUCE_PLUGINHOST_LADSPA && JUCE_LINUX
  23473. formats.add (new LADSPAPluginFormat());
  23474. #endif
  23475. }
  23476. int AudioPluginFormatManager::getNumFormats() throw()
  23477. {
  23478. return formats.size();
  23479. }
  23480. AudioPluginFormat* AudioPluginFormatManager::getFormat (const int index) throw()
  23481. {
  23482. return formats [index];
  23483. }
  23484. void AudioPluginFormatManager::addFormat (AudioPluginFormat* const format) throw()
  23485. {
  23486. formats.add (format);
  23487. }
  23488. AudioPluginInstance* AudioPluginFormatManager::createPluginInstance (const PluginDescription& description,
  23489. String& errorMessage) const
  23490. {
  23491. AudioPluginInstance* result = 0;
  23492. for (int i = 0; i < formats.size(); ++i)
  23493. {
  23494. result = formats.getUnchecked(i)->createInstanceFromDescription (description);
  23495. if (result != 0)
  23496. break;
  23497. }
  23498. if (result == 0)
  23499. {
  23500. if (! doesPluginStillExist (description))
  23501. errorMessage = TRANS ("This plug-in file no longer exists");
  23502. else
  23503. errorMessage = TRANS ("This plug-in failed to load correctly");
  23504. }
  23505. return result;
  23506. }
  23507. bool AudioPluginFormatManager::doesPluginStillExist (const PluginDescription& description) const
  23508. {
  23509. for (int i = 0; i < formats.size(); ++i)
  23510. if (formats.getUnchecked(i)->getName() == description.pluginFormatName)
  23511. return formats.getUnchecked(i)->doesPluginStillExist (description);
  23512. return false;
  23513. }
  23514. END_JUCE_NAMESPACE
  23515. /*** End of inlined file: juce_AudioPluginFormatManager.cpp ***/
  23516. /*** Start of inlined file: juce_AudioPluginInstance.cpp ***/
  23517. #define JUCE_PLUGIN_HOST 1
  23518. BEGIN_JUCE_NAMESPACE
  23519. AudioPluginInstance::AudioPluginInstance()
  23520. {
  23521. }
  23522. AudioPluginInstance::~AudioPluginInstance()
  23523. {
  23524. }
  23525. END_JUCE_NAMESPACE
  23526. /*** End of inlined file: juce_AudioPluginInstance.cpp ***/
  23527. /*** Start of inlined file: juce_KnownPluginList.cpp ***/
  23528. BEGIN_JUCE_NAMESPACE
  23529. KnownPluginList::KnownPluginList()
  23530. {
  23531. }
  23532. KnownPluginList::~KnownPluginList()
  23533. {
  23534. }
  23535. void KnownPluginList::clear()
  23536. {
  23537. if (types.size() > 0)
  23538. {
  23539. types.clear();
  23540. sendChangeMessage (this);
  23541. }
  23542. }
  23543. PluginDescription* KnownPluginList::getTypeForFile (const String& fileOrIdentifier) const throw()
  23544. {
  23545. for (int i = 0; i < types.size(); ++i)
  23546. if (types.getUnchecked(i)->fileOrIdentifier == fileOrIdentifier)
  23547. return types.getUnchecked(i);
  23548. return 0;
  23549. }
  23550. PluginDescription* KnownPluginList::getTypeForIdentifierString (const String& identifierString) const throw()
  23551. {
  23552. for (int i = 0; i < types.size(); ++i)
  23553. if (types.getUnchecked(i)->createIdentifierString() == identifierString)
  23554. return types.getUnchecked(i);
  23555. return 0;
  23556. }
  23557. bool KnownPluginList::addType (const PluginDescription& type)
  23558. {
  23559. for (int i = types.size(); --i >= 0;)
  23560. {
  23561. if (types.getUnchecked(i)->isDuplicateOf (type))
  23562. {
  23563. // strange - found a duplicate plugin with different info..
  23564. jassert (types.getUnchecked(i)->name == type.name);
  23565. jassert (types.getUnchecked(i)->isInstrument == type.isInstrument);
  23566. *types.getUnchecked(i) = type;
  23567. return false;
  23568. }
  23569. }
  23570. types.add (new PluginDescription (type));
  23571. sendChangeMessage (this);
  23572. return true;
  23573. }
  23574. void KnownPluginList::removeType (const int index) throw()
  23575. {
  23576. types.remove (index);
  23577. sendChangeMessage (this);
  23578. }
  23579. static Time getFileModTime (const String& fileOrIdentifier) throw()
  23580. {
  23581. if (fileOrIdentifier.startsWithChar (T('/'))
  23582. || fileOrIdentifier[1] == T(':'))
  23583. {
  23584. return File (fileOrIdentifier).getLastModificationTime();
  23585. }
  23586. return Time (0);
  23587. }
  23588. static bool timesAreDifferent (const Time& t1, const Time& t2) throw()
  23589. {
  23590. return t1 != t2 || t1 == Time (0);
  23591. }
  23592. bool KnownPluginList::isListingUpToDate (const String& fileOrIdentifier) const throw()
  23593. {
  23594. if (getTypeForFile (fileOrIdentifier) == 0)
  23595. return false;
  23596. for (int i = types.size(); --i >= 0;)
  23597. {
  23598. const PluginDescription* const d = types.getUnchecked(i);
  23599. if (d->fileOrIdentifier == fileOrIdentifier
  23600. && timesAreDifferent (d->lastFileModTime, getFileModTime (fileOrIdentifier)))
  23601. {
  23602. return false;
  23603. }
  23604. }
  23605. return true;
  23606. }
  23607. bool KnownPluginList::scanAndAddFile (const String& fileOrIdentifier,
  23608. const bool dontRescanIfAlreadyInList,
  23609. OwnedArray <PluginDescription>& typesFound,
  23610. AudioPluginFormat& format)
  23611. {
  23612. bool addedOne = false;
  23613. if (dontRescanIfAlreadyInList
  23614. && getTypeForFile (fileOrIdentifier) != 0)
  23615. {
  23616. bool needsRescanning = false;
  23617. for (int i = types.size(); --i >= 0;)
  23618. {
  23619. const PluginDescription* const d = types.getUnchecked(i);
  23620. if (d->fileOrIdentifier == fileOrIdentifier)
  23621. {
  23622. if (timesAreDifferent (d->lastFileModTime, getFileModTime (fileOrIdentifier)))
  23623. needsRescanning = true;
  23624. else
  23625. typesFound.add (new PluginDescription (*d));
  23626. }
  23627. }
  23628. if (! needsRescanning)
  23629. return false;
  23630. }
  23631. OwnedArray <PluginDescription> found;
  23632. format.findAllTypesForFile (found, fileOrIdentifier);
  23633. for (int i = 0; i < found.size(); ++i)
  23634. {
  23635. PluginDescription* const desc = found.getUnchecked(i);
  23636. jassert (desc != 0);
  23637. if (addType (*desc))
  23638. addedOne = true;
  23639. typesFound.add (new PluginDescription (*desc));
  23640. }
  23641. return addedOne;
  23642. }
  23643. void KnownPluginList::scanAndAddDragAndDroppedFiles (const StringArray& files,
  23644. OwnedArray <PluginDescription>& typesFound)
  23645. {
  23646. for (int i = 0; i < files.size(); ++i)
  23647. {
  23648. bool loaded = false;
  23649. for (int j = 0; j < AudioPluginFormatManager::getInstance()->getNumFormats(); ++j)
  23650. {
  23651. AudioPluginFormat* const format = AudioPluginFormatManager::getInstance()->getFormat (j);
  23652. if (scanAndAddFile (files[i], true, typesFound, *format))
  23653. loaded = true;
  23654. }
  23655. if (! loaded)
  23656. {
  23657. const File f (files[i]);
  23658. if (f.isDirectory())
  23659. {
  23660. StringArray s;
  23661. {
  23662. Array<File> subFiles;
  23663. f.findChildFiles (subFiles, File::findFilesAndDirectories, false);
  23664. for (int j = 0; j < subFiles.size(); ++j)
  23665. s.add (subFiles.getReference(j).getFullPathName());
  23666. }
  23667. scanAndAddDragAndDroppedFiles (s, typesFound);
  23668. }
  23669. }
  23670. }
  23671. }
  23672. class PluginSorter
  23673. {
  23674. public:
  23675. KnownPluginList::SortMethod method;
  23676. PluginSorter() throw() {}
  23677. int compareElements (const PluginDescription* const first,
  23678. const PluginDescription* const second) const throw()
  23679. {
  23680. int diff = 0;
  23681. if (method == KnownPluginList::sortByCategory)
  23682. diff = first->category.compareLexicographically (second->category);
  23683. else if (method == KnownPluginList::sortByManufacturer)
  23684. diff = first->manufacturerName.compareLexicographically (second->manufacturerName);
  23685. else if (method == KnownPluginList::sortByFileSystemLocation)
  23686. diff = first->fileOrIdentifier.replaceCharacter (T('\\'), T('/'))
  23687. .upToLastOccurrenceOf (T("/"), false, false)
  23688. .compare (second->fileOrIdentifier.replaceCharacter (T('\\'), T('/'))
  23689. .upToLastOccurrenceOf (T("/"), false, false));
  23690. if (diff == 0)
  23691. diff = first->name.compareLexicographically (second->name);
  23692. return diff;
  23693. }
  23694. };
  23695. void KnownPluginList::sort (const SortMethod method)
  23696. {
  23697. if (method != defaultOrder)
  23698. {
  23699. PluginSorter sorter;
  23700. sorter.method = method;
  23701. types.sort (sorter, true);
  23702. sendChangeMessage (this);
  23703. }
  23704. }
  23705. XmlElement* KnownPluginList::createXml() const
  23706. {
  23707. XmlElement* const e = new XmlElement (T("KNOWNPLUGINS"));
  23708. for (int i = 0; i < types.size(); ++i)
  23709. e->addChildElement (types.getUnchecked(i)->createXml());
  23710. return e;
  23711. }
  23712. void KnownPluginList::recreateFromXml (const XmlElement& xml)
  23713. {
  23714. clear();
  23715. if (xml.hasTagName (T("KNOWNPLUGINS")))
  23716. {
  23717. forEachXmlChildElement (xml, e)
  23718. {
  23719. PluginDescription info;
  23720. if (info.loadFromXml (*e))
  23721. addType (info);
  23722. }
  23723. }
  23724. }
  23725. const int menuIdBase = 0x324503f4;
  23726. // This is used to turn a bunch of paths into a nested menu structure.
  23727. struct PluginFilesystemTree
  23728. {
  23729. private:
  23730. String folder;
  23731. OwnedArray <PluginFilesystemTree> subFolders;
  23732. Array <PluginDescription*> plugins;
  23733. void addPlugin (PluginDescription* const pd, const String& path)
  23734. {
  23735. if (path.isEmpty())
  23736. {
  23737. plugins.add (pd);
  23738. }
  23739. else
  23740. {
  23741. const String firstSubFolder (path.upToFirstOccurrenceOf (T("/"), false, false));
  23742. const String remainingPath (path.fromFirstOccurrenceOf (T("/"), false, false));
  23743. for (int i = subFolders.size(); --i >= 0;)
  23744. {
  23745. if (subFolders.getUnchecked(i)->folder.equalsIgnoreCase (firstSubFolder))
  23746. {
  23747. subFolders.getUnchecked(i)->addPlugin (pd, remainingPath);
  23748. return;
  23749. }
  23750. }
  23751. PluginFilesystemTree* const newFolder = new PluginFilesystemTree();
  23752. newFolder->folder = firstSubFolder;
  23753. subFolders.add (newFolder);
  23754. newFolder->addPlugin (pd, remainingPath);
  23755. }
  23756. }
  23757. // removes any deeply nested folders that don't contain any actual plugins
  23758. void optimise()
  23759. {
  23760. for (int i = subFolders.size(); --i >= 0;)
  23761. {
  23762. PluginFilesystemTree* const sub = subFolders.getUnchecked(i);
  23763. sub->optimise();
  23764. if (sub->plugins.size() == 0)
  23765. {
  23766. for (int j = 0; j < sub->subFolders.size(); ++j)
  23767. subFolders.add (sub->subFolders.getUnchecked(j));
  23768. sub->subFolders.clear (false);
  23769. subFolders.remove (i);
  23770. }
  23771. }
  23772. }
  23773. public:
  23774. void buildTree (const Array <PluginDescription*>& allPlugins)
  23775. {
  23776. for (int i = 0; i < allPlugins.size(); ++i)
  23777. {
  23778. String path (allPlugins.getUnchecked(i)
  23779. ->fileOrIdentifier.replaceCharacter (T('\\'), T('/'))
  23780. .upToLastOccurrenceOf (T("/"), false, false));
  23781. if (path.substring (1, 2) == T(":"))
  23782. path = path.substring (2);
  23783. addPlugin (allPlugins.getUnchecked(i), path);
  23784. }
  23785. optimise();
  23786. }
  23787. void addToMenu (PopupMenu& m, const OwnedArray <PluginDescription>& allPlugins) const
  23788. {
  23789. int i;
  23790. for (i = 0; i < subFolders.size(); ++i)
  23791. {
  23792. const PluginFilesystemTree* const sub = subFolders.getUnchecked(i);
  23793. PopupMenu subMenu;
  23794. sub->addToMenu (subMenu, allPlugins);
  23795. #if JUCE_MAC
  23796. // avoid the special AU formatting nonsense on Mac..
  23797. m.addSubMenu (sub->folder.fromFirstOccurrenceOf (T(":"), false, false), subMenu);
  23798. #else
  23799. m.addSubMenu (sub->folder, subMenu);
  23800. #endif
  23801. }
  23802. for (i = 0; i < plugins.size(); ++i)
  23803. {
  23804. PluginDescription* const plugin = plugins.getUnchecked(i);
  23805. m.addItem (allPlugins.indexOf (plugin) + menuIdBase,
  23806. plugin->name, true, false);
  23807. }
  23808. }
  23809. };
  23810. void KnownPluginList::addToMenu (PopupMenu& menu, const SortMethod sortMethod) const
  23811. {
  23812. Array <PluginDescription*> sorted;
  23813. {
  23814. PluginSorter sorter;
  23815. sorter.method = sortMethod;
  23816. for (int i = 0; i < types.size(); ++i)
  23817. sorted.addSorted (sorter, types.getUnchecked(i));
  23818. }
  23819. if (sortMethod == sortByCategory
  23820. || sortMethod == sortByManufacturer)
  23821. {
  23822. String lastSubMenuName;
  23823. PopupMenu sub;
  23824. for (int i = 0; i < sorted.size(); ++i)
  23825. {
  23826. const PluginDescription* const pd = sorted.getUnchecked(i);
  23827. String thisSubMenuName (sortMethod == sortByCategory ? pd->category
  23828. : pd->manufacturerName);
  23829. if (! thisSubMenuName.containsNonWhitespaceChars())
  23830. thisSubMenuName = T("Other");
  23831. if (thisSubMenuName != lastSubMenuName)
  23832. {
  23833. if (sub.getNumItems() > 0)
  23834. {
  23835. menu.addSubMenu (lastSubMenuName, sub);
  23836. sub.clear();
  23837. }
  23838. lastSubMenuName = thisSubMenuName;
  23839. }
  23840. sub.addItem (types.indexOf (pd) + menuIdBase, pd->name, true, false);
  23841. }
  23842. if (sub.getNumItems() > 0)
  23843. menu.addSubMenu (lastSubMenuName, sub);
  23844. }
  23845. else if (sortMethod == sortByFileSystemLocation)
  23846. {
  23847. PluginFilesystemTree root;
  23848. root.buildTree (sorted);
  23849. root.addToMenu (menu, types);
  23850. }
  23851. else
  23852. {
  23853. for (int i = 0; i < sorted.size(); ++i)
  23854. {
  23855. const PluginDescription* const pd = sorted.getUnchecked(i);
  23856. menu.addItem (types.indexOf (pd) + menuIdBase, pd->name, true, false);
  23857. }
  23858. }
  23859. }
  23860. int KnownPluginList::getIndexChosenByMenu (const int menuResultCode) const
  23861. {
  23862. const int i = menuResultCode - menuIdBase;
  23863. return (((unsigned int) i) < (unsigned int) types.size()) ? i : -1;
  23864. }
  23865. END_JUCE_NAMESPACE
  23866. /*** End of inlined file: juce_KnownPluginList.cpp ***/
  23867. /*** Start of inlined file: juce_PluginDescription.cpp ***/
  23868. BEGIN_JUCE_NAMESPACE
  23869. PluginDescription::PluginDescription() throw()
  23870. : uid (0),
  23871. isInstrument (false),
  23872. numInputChannels (0),
  23873. numOutputChannels (0)
  23874. {
  23875. }
  23876. PluginDescription::~PluginDescription() throw()
  23877. {
  23878. }
  23879. PluginDescription::PluginDescription (const PluginDescription& other) throw()
  23880. : name (other.name),
  23881. pluginFormatName (other.pluginFormatName),
  23882. category (other.category),
  23883. manufacturerName (other.manufacturerName),
  23884. version (other.version),
  23885. fileOrIdentifier (other.fileOrIdentifier),
  23886. lastFileModTime (other.lastFileModTime),
  23887. uid (other.uid),
  23888. isInstrument (other.isInstrument),
  23889. numInputChannels (other.numInputChannels),
  23890. numOutputChannels (other.numOutputChannels)
  23891. {
  23892. }
  23893. const PluginDescription& PluginDescription::operator= (const PluginDescription& other) throw()
  23894. {
  23895. name = other.name;
  23896. pluginFormatName = other.pluginFormatName;
  23897. category = other.category;
  23898. manufacturerName = other.manufacturerName;
  23899. version = other.version;
  23900. fileOrIdentifier = other.fileOrIdentifier;
  23901. uid = other.uid;
  23902. isInstrument = other.isInstrument;
  23903. lastFileModTime = other.lastFileModTime;
  23904. numInputChannels = other.numInputChannels;
  23905. numOutputChannels = other.numOutputChannels;
  23906. return *this;
  23907. }
  23908. bool PluginDescription::isDuplicateOf (const PluginDescription& other) const
  23909. {
  23910. return fileOrIdentifier == other.fileOrIdentifier
  23911. && uid == other.uid;
  23912. }
  23913. const String PluginDescription::createIdentifierString() const throw()
  23914. {
  23915. return pluginFormatName
  23916. + T("-") + name
  23917. + T("-") + String::toHexString (fileOrIdentifier.hashCode())
  23918. + T("-") + String::toHexString (uid);
  23919. }
  23920. XmlElement* PluginDescription::createXml() const
  23921. {
  23922. XmlElement* const e = new XmlElement (T("PLUGIN"));
  23923. e->setAttribute (T("name"), name);
  23924. e->setAttribute (T("format"), pluginFormatName);
  23925. e->setAttribute (T("category"), category);
  23926. e->setAttribute (T("manufacturer"), manufacturerName);
  23927. e->setAttribute (T("version"), version);
  23928. e->setAttribute (T("file"), fileOrIdentifier);
  23929. e->setAttribute (T("uid"), String::toHexString (uid));
  23930. e->setAttribute (T("isInstrument"), isInstrument);
  23931. e->setAttribute (T("fileTime"), String::toHexString (lastFileModTime.toMilliseconds()));
  23932. e->setAttribute (T("numInputs"), numInputChannels);
  23933. e->setAttribute (T("numOutputs"), numOutputChannels);
  23934. return e;
  23935. }
  23936. bool PluginDescription::loadFromXml (const XmlElement& xml)
  23937. {
  23938. if (xml.hasTagName (T("PLUGIN")))
  23939. {
  23940. name = xml.getStringAttribute (T("name"));
  23941. pluginFormatName = xml.getStringAttribute (T("format"));
  23942. category = xml.getStringAttribute (T("category"));
  23943. manufacturerName = xml.getStringAttribute (T("manufacturer"));
  23944. version = xml.getStringAttribute (T("version"));
  23945. fileOrIdentifier = xml.getStringAttribute (T("file"));
  23946. uid = xml.getStringAttribute (T("uid")).getHexValue32();
  23947. isInstrument = xml.getBoolAttribute (T("isInstrument"), false);
  23948. lastFileModTime = Time (xml.getStringAttribute (T("fileTime")).getHexValue64());
  23949. numInputChannels = xml.getIntAttribute (T("numInputs"));
  23950. numOutputChannels = xml.getIntAttribute (T("numOutputs"));
  23951. return true;
  23952. }
  23953. return false;
  23954. }
  23955. END_JUCE_NAMESPACE
  23956. /*** End of inlined file: juce_PluginDescription.cpp ***/
  23957. /*** Start of inlined file: juce_PluginDirectoryScanner.cpp ***/
  23958. BEGIN_JUCE_NAMESPACE
  23959. PluginDirectoryScanner::PluginDirectoryScanner (KnownPluginList& listToAddTo,
  23960. AudioPluginFormat& formatToLookFor,
  23961. FileSearchPath directoriesToSearch,
  23962. const bool recursive,
  23963. const File& deadMansPedalFile_)
  23964. : list (listToAddTo),
  23965. format (formatToLookFor),
  23966. deadMansPedalFile (deadMansPedalFile_),
  23967. nextIndex (0),
  23968. progress (0)
  23969. {
  23970. directoriesToSearch.removeRedundantPaths();
  23971. filesOrIdentifiersToScan = format.searchPathsForPlugins (directoriesToSearch, recursive);
  23972. // If any plugins have crashed recently when being loaded, move them to the
  23973. // end of the list to give the others a chance to load correctly..
  23974. const StringArray crashedPlugins (getDeadMansPedalFile());
  23975. for (int i = 0; i < crashedPlugins.size(); ++i)
  23976. {
  23977. const String f = crashedPlugins[i];
  23978. for (int j = filesOrIdentifiersToScan.size(); --j >= 0;)
  23979. if (f == filesOrIdentifiersToScan[j])
  23980. filesOrIdentifiersToScan.move (j, -1);
  23981. }
  23982. }
  23983. PluginDirectoryScanner::~PluginDirectoryScanner()
  23984. {
  23985. }
  23986. const String PluginDirectoryScanner::getNextPluginFileThatWillBeScanned() const throw()
  23987. {
  23988. return format.getNameOfPluginFromIdentifier (filesOrIdentifiersToScan [nextIndex]);
  23989. }
  23990. bool PluginDirectoryScanner::scanNextFile (const bool dontRescanIfAlreadyInList)
  23991. {
  23992. String file (filesOrIdentifiersToScan [nextIndex]);
  23993. if (file.isNotEmpty())
  23994. {
  23995. if (! list.isListingUpToDate (file))
  23996. {
  23997. OwnedArray <PluginDescription> typesFound;
  23998. // Add this plugin to the end of the dead-man's pedal list in case it crashes...
  23999. StringArray crashedPlugins (getDeadMansPedalFile());
  24000. crashedPlugins.removeString (file);
  24001. crashedPlugins.add (file);
  24002. setDeadMansPedalFile (crashedPlugins);
  24003. list.scanAndAddFile (file,
  24004. dontRescanIfAlreadyInList,
  24005. typesFound,
  24006. format);
  24007. // Managed to load without crashing, so remove it from the dead-man's-pedal..
  24008. crashedPlugins.removeString (file);
  24009. setDeadMansPedalFile (crashedPlugins);
  24010. if (typesFound.size() == 0)
  24011. failedFiles.add (file);
  24012. }
  24013. ++nextIndex;
  24014. progress = nextIndex / (float) filesOrIdentifiersToScan.size();
  24015. }
  24016. return nextIndex < filesOrIdentifiersToScan.size();
  24017. }
  24018. const StringArray PluginDirectoryScanner::getDeadMansPedalFile() throw()
  24019. {
  24020. StringArray lines;
  24021. if (deadMansPedalFile != File::nonexistent)
  24022. {
  24023. lines.addLines (deadMansPedalFile.loadFileAsString());
  24024. lines.removeEmptyStrings();
  24025. }
  24026. return lines;
  24027. }
  24028. void PluginDirectoryScanner::setDeadMansPedalFile (const StringArray& newContents) throw()
  24029. {
  24030. if (deadMansPedalFile != File::nonexistent)
  24031. deadMansPedalFile.replaceWithText (newContents.joinIntoString ("\n"), true, true);
  24032. }
  24033. END_JUCE_NAMESPACE
  24034. /*** End of inlined file: juce_PluginDirectoryScanner.cpp ***/
  24035. /*** Start of inlined file: juce_PluginListComponent.cpp ***/
  24036. BEGIN_JUCE_NAMESPACE
  24037. PluginListComponent::PluginListComponent (KnownPluginList& listToEdit,
  24038. const File& deadMansPedalFile_,
  24039. PropertiesFile* const propertiesToUse_)
  24040. : list (listToEdit),
  24041. deadMansPedalFile (deadMansPedalFile_),
  24042. propertiesToUse (propertiesToUse_)
  24043. {
  24044. addAndMakeVisible (listBox = new ListBox (String::empty, this));
  24045. addAndMakeVisible (optionsButton = new TextButton ("Options..."));
  24046. optionsButton->addButtonListener (this);
  24047. optionsButton->setTriggeredOnMouseDown (true);
  24048. setSize (400, 600);
  24049. list.addChangeListener (this);
  24050. }
  24051. PluginListComponent::~PluginListComponent()
  24052. {
  24053. list.removeChangeListener (this);
  24054. deleteAllChildren();
  24055. }
  24056. void PluginListComponent::resized()
  24057. {
  24058. listBox->setBounds (0, 0, getWidth(), getHeight() - 30);
  24059. optionsButton->changeWidthToFitText (24);
  24060. optionsButton->setTopLeftPosition (8, getHeight() - 28);
  24061. }
  24062. void PluginListComponent::changeListenerCallback (void*)
  24063. {
  24064. listBox->updateContent();
  24065. listBox->repaint();
  24066. }
  24067. int PluginListComponent::getNumRows()
  24068. {
  24069. return list.getNumTypes();
  24070. }
  24071. void PluginListComponent::paintListBoxItem (int row,
  24072. Graphics& g,
  24073. int width, int height,
  24074. bool rowIsSelected)
  24075. {
  24076. if (rowIsSelected)
  24077. g.fillAll (findColour (TextEditor::highlightColourId));
  24078. const PluginDescription* const pd = list.getType (row);
  24079. if (pd != 0)
  24080. {
  24081. GlyphArrangement ga;
  24082. ga.addCurtailedLineOfText (Font (height * 0.7f, Font::bold), pd->name, 8.0f, height * 0.8f, width - 10.0f, true);
  24083. g.setColour (Colours::black);
  24084. ga.draw (g);
  24085. float x, y, r, b;
  24086. ga.getBoundingBox (0, -1, x, y, r, b, false);
  24087. String desc;
  24088. desc << pd->pluginFormatName
  24089. << (pd->isInstrument ? " instrument" : " effect")
  24090. << " - "
  24091. << pd->numInputChannels << (pd->numInputChannels == 1 ? " in" : " ins")
  24092. << " / "
  24093. << pd->numOutputChannels << (pd->numOutputChannels == 1 ? " out" : " outs");
  24094. if (pd->manufacturerName.isNotEmpty())
  24095. desc << " - " << pd->manufacturerName;
  24096. if (pd->version.isNotEmpty())
  24097. desc << " - " << pd->version;
  24098. if (pd->category.isNotEmpty())
  24099. desc << " - category: '" << pd->category << '\'';
  24100. g.setColour (Colours::grey);
  24101. ga.clear();
  24102. ga.addCurtailedLineOfText (Font (height * 0.6f), desc, r + 10.0f, height * 0.8f, width - r - 12.0f, true);
  24103. ga.draw (g);
  24104. }
  24105. }
  24106. void PluginListComponent::deleteKeyPressed (int lastRowSelected)
  24107. {
  24108. list.removeType (lastRowSelected);
  24109. }
  24110. void PluginListComponent::buttonClicked (Button* b)
  24111. {
  24112. if (optionsButton == b)
  24113. {
  24114. PopupMenu menu;
  24115. menu.addItem (1, TRANS("Clear list"));
  24116. menu.addItem (5, TRANS("Remove selected plugin from list"), listBox->getNumSelectedRows() > 0);
  24117. menu.addItem (6, TRANS("Show folder containing selected plugin"), listBox->getNumSelectedRows() > 0);
  24118. menu.addItem (7, TRANS("Remove any plugins whose files no longer exist"));
  24119. menu.addSeparator();
  24120. menu.addItem (2, TRANS("Sort alphabetically"));
  24121. menu.addItem (3, TRANS("Sort by category"));
  24122. menu.addItem (4, TRANS("Sort by manufacturer"));
  24123. menu.addSeparator();
  24124. for (int i = 0; i < AudioPluginFormatManager::getInstance()->getNumFormats(); ++i)
  24125. {
  24126. AudioPluginFormat* const format = AudioPluginFormatManager::getInstance()->getFormat (i);
  24127. if (format->getDefaultLocationsToSearch().getNumPaths() > 0)
  24128. menu.addItem (10 + i, "Scan for new or updated " + format->getName() + " plugins...");
  24129. }
  24130. const int r = menu.showAt (optionsButton);
  24131. if (r == 1)
  24132. {
  24133. list.clear();
  24134. }
  24135. else if (r == 2)
  24136. {
  24137. list.sort (KnownPluginList::sortAlphabetically);
  24138. }
  24139. else if (r == 3)
  24140. {
  24141. list.sort (KnownPluginList::sortByCategory);
  24142. }
  24143. else if (r == 4)
  24144. {
  24145. list.sort (KnownPluginList::sortByManufacturer);
  24146. }
  24147. else if (r == 5)
  24148. {
  24149. const SparseSet <int> selected (listBox->getSelectedRows());
  24150. for (int i = list.getNumTypes(); --i >= 0;)
  24151. if (selected.contains (i))
  24152. list.removeType (i);
  24153. }
  24154. else if (r == 6)
  24155. {
  24156. const PluginDescription* const desc = list.getType (listBox->getSelectedRow());
  24157. if (desc != 0)
  24158. {
  24159. if (File (desc->fileOrIdentifier).existsAsFile())
  24160. File (desc->fileOrIdentifier).getParentDirectory().startAsProcess();
  24161. }
  24162. }
  24163. else if (r == 7)
  24164. {
  24165. for (int i = list.getNumTypes(); --i >= 0;)
  24166. {
  24167. if (! AudioPluginFormatManager::getInstance()->doesPluginStillExist (*list.getType (i)))
  24168. {
  24169. list.removeType (i);
  24170. }
  24171. }
  24172. }
  24173. else if (r != 0)
  24174. {
  24175. typeToScan = r - 10;
  24176. startTimer (1);
  24177. }
  24178. }
  24179. }
  24180. void PluginListComponent::timerCallback()
  24181. {
  24182. stopTimer();
  24183. scanFor (AudioPluginFormatManager::getInstance()->getFormat (typeToScan));
  24184. }
  24185. bool PluginListComponent::isInterestedInFileDrag (const StringArray& /*files*/)
  24186. {
  24187. return true;
  24188. }
  24189. void PluginListComponent::filesDropped (const StringArray& files, int, int)
  24190. {
  24191. OwnedArray <PluginDescription> typesFound;
  24192. list.scanAndAddDragAndDroppedFiles (files, typesFound);
  24193. }
  24194. void PluginListComponent::scanFor (AudioPluginFormat* format)
  24195. {
  24196. if (format == 0)
  24197. return;
  24198. FileSearchPath path (format->getDefaultLocationsToSearch());
  24199. if (propertiesToUse != 0)
  24200. path = propertiesToUse->getValue ("lastPluginScanPath_" + format->getName(), path.toString());
  24201. {
  24202. AlertWindow aw (TRANS("Select folders to scan..."), String::empty, AlertWindow::NoIcon);
  24203. FileSearchPathListComponent pathList;
  24204. pathList.setSize (500, 300);
  24205. pathList.setPath (path);
  24206. aw.addCustomComponent (&pathList);
  24207. aw.addButton (TRANS("Scan"), 1, KeyPress::returnKey);
  24208. aw.addButton (TRANS("Cancel"), 0, KeyPress (KeyPress::escapeKey));
  24209. if (aw.runModalLoop() == 0)
  24210. return;
  24211. path = pathList.getPath();
  24212. }
  24213. if (propertiesToUse != 0)
  24214. {
  24215. propertiesToUse->setValue ("lastPluginScanPath_" + format->getName(), path.toString());
  24216. propertiesToUse->saveIfNeeded();
  24217. }
  24218. double progress = 0.0;
  24219. AlertWindow aw (TRANS("Scanning for plugins..."),
  24220. TRANS("Searching for all possible plugin files..."), AlertWindow::NoIcon);
  24221. aw.addButton (TRANS("Cancel"), 0, KeyPress (KeyPress::escapeKey));
  24222. aw.addProgressBarComponent (progress);
  24223. aw.enterModalState();
  24224. MessageManager::getInstance()->runDispatchLoopUntil (300);
  24225. PluginDirectoryScanner scanner (list, *format, path, true, deadMansPedalFile);
  24226. for (;;)
  24227. {
  24228. aw.setMessage (TRANS("Testing:\n\n")
  24229. + scanner.getNextPluginFileThatWillBeScanned());
  24230. MessageManager::getInstance()->runDispatchLoopUntil (20);
  24231. if (! scanner.scanNextFile (true))
  24232. break;
  24233. if (! aw.isCurrentlyModal())
  24234. break;
  24235. progress = scanner.getProgress();
  24236. }
  24237. if (scanner.getFailedFiles().size() > 0)
  24238. {
  24239. StringArray shortNames;
  24240. for (int i = 0; i < scanner.getFailedFiles().size(); ++i)
  24241. shortNames.add (File (scanner.getFailedFiles()[i]).getFileName());
  24242. AlertWindow::showMessageBox (AlertWindow::InfoIcon,
  24243. TRANS("Scan complete"),
  24244. TRANS("Note that the following files appeared to be plugin files, but failed to load correctly:\n\n")
  24245. + shortNames.joinIntoString (", "));
  24246. }
  24247. }
  24248. END_JUCE_NAMESPACE
  24249. /*** End of inlined file: juce_PluginListComponent.cpp ***/
  24250. /*** Start of inlined file: juce_AudioUnitPluginFormat.mm ***/
  24251. #if JUCE_PLUGINHOST_AU && (! (defined (LINUX) || defined (_WIN32)))
  24252. #include <AudioUnit/AudioUnit.h>
  24253. #include <AudioUnit/AUCocoaUIView.h>
  24254. #include <CoreAudioKit/AUGenericView.h>
  24255. #if JUCE_SUPPORT_CARBON
  24256. #include <AudioToolbox/AudioUnitUtilities.h>
  24257. #include <AudioUnit/AudioUnitCarbonView.h>
  24258. #endif
  24259. BEGIN_JUCE_NAMESPACE
  24260. #if JUCE_MAC && JUCE_SUPPORT_CARBON
  24261. #endif
  24262. #if JUCE_MAC
  24263. // Change this to disable logging of various activities
  24264. #ifndef AU_LOGGING
  24265. #define AU_LOGGING 1
  24266. #endif
  24267. #if AU_LOGGING
  24268. #define log(a) Logger::writeToLog(a);
  24269. #else
  24270. #define log(a)
  24271. #endif
  24272. static int insideCallback = 0;
  24273. static const String osTypeToString (OSType type) throw()
  24274. {
  24275. char s[4];
  24276. s[0] = (char) (((uint32) type) >> 24);
  24277. s[1] = (char) (((uint32) type) >> 16);
  24278. s[2] = (char) (((uint32) type) >> 8);
  24279. s[3] = (char) ((uint32) type);
  24280. return String (s, 4);
  24281. }
  24282. static OSType stringToOSType (const String& s1) throw()
  24283. {
  24284. const String s (s1 + " ");
  24285. return (((OSType) (unsigned char) s[0]) << 24)
  24286. | (((OSType) (unsigned char) s[1]) << 16)
  24287. | (((OSType) (unsigned char) s[2]) << 8)
  24288. | ((OSType) (unsigned char) s[3]);
  24289. }
  24290. static const tchar* auIdentifierPrefix = T("AudioUnit:");
  24291. static const String createAUPluginIdentifier (const ComponentDescription& desc)
  24292. {
  24293. jassert (osTypeToString ('abcd') == T("abcd")); // agh, must have got the endianness wrong..
  24294. jassert (stringToOSType ("abcd") == (OSType) 'abcd'); // ditto
  24295. String s (auIdentifierPrefix);
  24296. if (desc.componentType == kAudioUnitType_MusicDevice)
  24297. s << "Synths/";
  24298. else if (desc.componentType == kAudioUnitType_MusicEffect
  24299. || desc.componentType == kAudioUnitType_Effect)
  24300. s << "Effects/";
  24301. else if (desc.componentType == kAudioUnitType_Generator)
  24302. s << "Generators/";
  24303. else if (desc.componentType == kAudioUnitType_Panner)
  24304. s << "Panners/";
  24305. s << osTypeToString (desc.componentType)
  24306. << T(",")
  24307. << osTypeToString (desc.componentSubType)
  24308. << T(",")
  24309. << osTypeToString (desc.componentManufacturer);
  24310. return s;
  24311. }
  24312. static void getAUDetails (ComponentRecord* comp, String& name, String& manufacturer)
  24313. {
  24314. Handle componentNameHandle = NewHandle (sizeof (void*));
  24315. Handle componentInfoHandle = NewHandle (sizeof (void*));
  24316. if (componentNameHandle != 0 && componentInfoHandle != 0)
  24317. {
  24318. ComponentDescription desc;
  24319. if (GetComponentInfo (comp, &desc, componentNameHandle, componentInfoHandle, 0) == noErr)
  24320. {
  24321. ConstStr255Param nameString = (ConstStr255Param) (*componentNameHandle);
  24322. ConstStr255Param infoString = (ConstStr255Param) (*componentInfoHandle);
  24323. if (nameString != 0 && nameString[0] != 0)
  24324. {
  24325. const String all ((const char*) nameString + 1, nameString[0]);
  24326. DBG ("name: "+ all);
  24327. manufacturer = all.upToFirstOccurrenceOf (T(":"), false, false).trim();
  24328. name = all.fromFirstOccurrenceOf (T(":"), false, false).trim();
  24329. }
  24330. if (infoString != 0 && infoString[0] != 0)
  24331. {
  24332. const String all ((const char*) infoString + 1, infoString[0]);
  24333. DBG ("info: " + all);
  24334. }
  24335. if (name.isEmpty())
  24336. name = "<Unknown>";
  24337. }
  24338. DisposeHandle (componentNameHandle);
  24339. DisposeHandle (componentInfoHandle);
  24340. }
  24341. }
  24342. static bool getComponentDescFromIdentifier (const String& fileOrIdentifier, ComponentDescription& desc,
  24343. String& name, String& version, String& manufacturer)
  24344. {
  24345. zerostruct (desc);
  24346. if (fileOrIdentifier.startsWithIgnoreCase (auIdentifierPrefix))
  24347. {
  24348. String s (fileOrIdentifier.substring (jmax (fileOrIdentifier.lastIndexOfChar (T(':')),
  24349. fileOrIdentifier.lastIndexOfChar (T('/'))) + 1));
  24350. StringArray tokens;
  24351. tokens.addTokens (s, T(","), 0);
  24352. tokens.trim();
  24353. tokens.removeEmptyStrings();
  24354. if (tokens.size() == 3)
  24355. {
  24356. desc.componentType = stringToOSType (tokens[0]);
  24357. desc.componentSubType = stringToOSType (tokens[1]);
  24358. desc.componentManufacturer = stringToOSType (tokens[2]);
  24359. ComponentRecord* comp = FindNextComponent (0, &desc);
  24360. if (comp != 0)
  24361. {
  24362. getAUDetails (comp, name, manufacturer);
  24363. return true;
  24364. }
  24365. }
  24366. }
  24367. return false;
  24368. }
  24369. class AudioUnitPluginWindowCarbon;
  24370. class AudioUnitPluginWindowCocoa;
  24371. class AudioUnitPluginInstance : public AudioPluginInstance
  24372. {
  24373. public:
  24374. ~AudioUnitPluginInstance();
  24375. // AudioPluginInstance methods:
  24376. void fillInPluginDescription (PluginDescription& desc) const
  24377. {
  24378. desc.name = pluginName;
  24379. desc.fileOrIdentifier = createAUPluginIdentifier (componentDesc);
  24380. desc.uid = ((int) componentDesc.componentType)
  24381. ^ ((int) componentDesc.componentSubType)
  24382. ^ ((int) componentDesc.componentManufacturer);
  24383. desc.lastFileModTime = 0;
  24384. desc.pluginFormatName = "AudioUnit";
  24385. desc.category = getCategory();
  24386. desc.manufacturerName = manufacturer;
  24387. desc.version = version;
  24388. desc.numInputChannels = getNumInputChannels();
  24389. desc.numOutputChannels = getNumOutputChannels();
  24390. desc.isInstrument = (componentDesc.componentType == kAudioUnitType_MusicDevice);
  24391. }
  24392. const String getName() const { return pluginName; }
  24393. bool acceptsMidi() const { return wantsMidiMessages; }
  24394. bool producesMidi() const { return false; }
  24395. // AudioProcessor methods:
  24396. void prepareToPlay (double sampleRate, int estimatedSamplesPerBlock);
  24397. void releaseResources();
  24398. void processBlock (AudioSampleBuffer& buffer,
  24399. MidiBuffer& midiMessages);
  24400. AudioProcessorEditor* createEditor();
  24401. const String getInputChannelName (const int index) const;
  24402. bool isInputChannelStereoPair (int index) const;
  24403. const String getOutputChannelName (const int index) const;
  24404. bool isOutputChannelStereoPair (int index) const;
  24405. int getNumParameters();
  24406. float getParameter (int index);
  24407. void setParameter (int index, float newValue);
  24408. const String getParameterName (int index);
  24409. const String getParameterText (int index);
  24410. bool isParameterAutomatable (int index) const;
  24411. int getNumPrograms();
  24412. int getCurrentProgram();
  24413. void setCurrentProgram (int index);
  24414. const String getProgramName (int index);
  24415. void changeProgramName (int index, const String& newName);
  24416. void getStateInformation (MemoryBlock& destData);
  24417. void getCurrentProgramStateInformation (MemoryBlock& destData);
  24418. void setStateInformation (const void* data, int sizeInBytes);
  24419. void setCurrentProgramStateInformation (const void* data, int sizeInBytes);
  24420. juce_UseDebuggingNewOperator
  24421. private:
  24422. friend class AudioUnitPluginWindowCarbon;
  24423. friend class AudioUnitPluginWindowCocoa;
  24424. friend class AudioUnitPluginFormat;
  24425. ComponentDescription componentDesc;
  24426. String pluginName, manufacturer, version;
  24427. String fileOrIdentifier;
  24428. CriticalSection lock;
  24429. bool initialised, wantsMidiMessages, wasPlaying;
  24430. HeapBlock <AudioBufferList> outputBufferList;
  24431. AudioTimeStamp timeStamp;
  24432. AudioSampleBuffer* currentBuffer;
  24433. AudioUnit audioUnit;
  24434. Array <int> parameterIds;
  24435. bool getComponentDescFromFile (const String& fileOrIdentifier);
  24436. void initialise();
  24437. OSStatus renderGetInput (AudioUnitRenderActionFlags* ioActionFlags,
  24438. const AudioTimeStamp* inTimeStamp,
  24439. UInt32 inBusNumber,
  24440. UInt32 inNumberFrames,
  24441. AudioBufferList* ioData) const;
  24442. static OSStatus renderGetInputCallback (void* inRefCon,
  24443. AudioUnitRenderActionFlags* ioActionFlags,
  24444. const AudioTimeStamp* inTimeStamp,
  24445. UInt32 inBusNumber,
  24446. UInt32 inNumberFrames,
  24447. AudioBufferList* ioData)
  24448. {
  24449. return ((AudioUnitPluginInstance*) inRefCon)
  24450. ->renderGetInput (ioActionFlags, inTimeStamp, inBusNumber, inNumberFrames, ioData);
  24451. }
  24452. OSStatus getBeatAndTempo (Float64* outCurrentBeat, Float64* outCurrentTempo) const;
  24453. OSStatus getMusicalTimeLocation (UInt32* outDeltaSampleOffsetToNextBeat, Float32* outTimeSig_Numerator,
  24454. UInt32* outTimeSig_Denominator, Float64* outCurrentMeasureDownBeat) const;
  24455. OSStatus getTransportState (Boolean* outIsPlaying, Boolean* outTransportStateChanged,
  24456. Float64* outCurrentSampleInTimeLine, Boolean* outIsCycling,
  24457. Float64* outCycleStartBeat, Float64* outCycleEndBeat);
  24458. static OSStatus getBeatAndTempoCallback (void* inHostUserData, Float64* outCurrentBeat, Float64* outCurrentTempo)
  24459. {
  24460. return ((AudioUnitPluginInstance*) inHostUserData)->getBeatAndTempo (outCurrentBeat, outCurrentTempo);
  24461. }
  24462. static OSStatus getMusicalTimeLocationCallback (void* inHostUserData, UInt32* outDeltaSampleOffsetToNextBeat,
  24463. Float32* outTimeSig_Numerator, UInt32* outTimeSig_Denominator,
  24464. Float64* outCurrentMeasureDownBeat)
  24465. {
  24466. return ((AudioUnitPluginInstance*) inHostUserData)
  24467. ->getMusicalTimeLocation (outDeltaSampleOffsetToNextBeat, outTimeSig_Numerator,
  24468. outTimeSig_Denominator, outCurrentMeasureDownBeat);
  24469. }
  24470. static OSStatus getTransportStateCallback (void* inHostUserData, Boolean* outIsPlaying, Boolean* outTransportStateChanged,
  24471. Float64* outCurrentSampleInTimeLine, Boolean* outIsCycling,
  24472. Float64* outCycleStartBeat, Float64* outCycleEndBeat)
  24473. {
  24474. return ((AudioUnitPluginInstance*) inHostUserData)
  24475. ->getTransportState (outIsPlaying, outTransportStateChanged,
  24476. outCurrentSampleInTimeLine, outIsCycling,
  24477. outCycleStartBeat, outCycleEndBeat);
  24478. }
  24479. void getNumChannels (int& numIns, int& numOuts)
  24480. {
  24481. numIns = 0;
  24482. numOuts = 0;
  24483. AUChannelInfo supportedChannels [128];
  24484. UInt32 supportedChannelsSize = sizeof (supportedChannels);
  24485. if (AudioUnitGetProperty (audioUnit, kAudioUnitProperty_SupportedNumChannels, kAudioUnitScope_Global,
  24486. 0, supportedChannels, &supportedChannelsSize) == noErr
  24487. && supportedChannelsSize > 0)
  24488. {
  24489. for (int i = 0; i < supportedChannelsSize / sizeof (AUChannelInfo); ++i)
  24490. {
  24491. numIns = jmax (numIns, (int) supportedChannels[i].inChannels);
  24492. numOuts = jmax (numOuts, (int) supportedChannels[i].outChannels);
  24493. }
  24494. }
  24495. else
  24496. {
  24497. // (this really means the plugin will take any number of ins/outs as long
  24498. // as they are the same)
  24499. numIns = numOuts = 2;
  24500. }
  24501. }
  24502. const String getCategory() const;
  24503. AudioUnitPluginInstance (const String& fileOrIdentifier);
  24504. };
  24505. AudioUnitPluginInstance::AudioUnitPluginInstance (const String& fileOrIdentifier)
  24506. : fileOrIdentifier (fileOrIdentifier),
  24507. initialised (false),
  24508. wantsMidiMessages (false),
  24509. audioUnit (0),
  24510. currentBuffer (0)
  24511. {
  24512. try
  24513. {
  24514. ++insideCallback;
  24515. log (T("Opening AU: ") + fileOrIdentifier);
  24516. if (getComponentDescFromFile (fileOrIdentifier))
  24517. {
  24518. ComponentRecord* const comp = FindNextComponent (0, &componentDesc);
  24519. if (comp != 0)
  24520. {
  24521. audioUnit = (AudioUnit) OpenComponent (comp);
  24522. wantsMidiMessages = componentDesc.componentType == kAudioUnitType_MusicDevice
  24523. || componentDesc.componentType == kAudioUnitType_MusicEffect;
  24524. }
  24525. }
  24526. --insideCallback;
  24527. }
  24528. catch (...)
  24529. {
  24530. --insideCallback;
  24531. }
  24532. }
  24533. AudioUnitPluginInstance::~AudioUnitPluginInstance()
  24534. {
  24535. {
  24536. const ScopedLock sl (lock);
  24537. jassert (insideCallback == 0);
  24538. if (audioUnit != 0)
  24539. {
  24540. AudioUnitUninitialize (audioUnit);
  24541. CloseComponent (audioUnit);
  24542. audioUnit = 0;
  24543. }
  24544. }
  24545. }
  24546. bool AudioUnitPluginInstance::getComponentDescFromFile (const String& fileOrIdentifier)
  24547. {
  24548. zerostruct (componentDesc);
  24549. if (getComponentDescFromIdentifier (fileOrIdentifier, componentDesc, pluginName, version, manufacturer))
  24550. return true;
  24551. const File file (fileOrIdentifier);
  24552. if (! file.hasFileExtension (T(".component")))
  24553. return false;
  24554. const char* const utf8 = fileOrIdentifier.toUTF8();
  24555. CFURLRef url = CFURLCreateFromFileSystemRepresentation (0, (const UInt8*) utf8,
  24556. strlen (utf8), file.isDirectory());
  24557. if (url != 0)
  24558. {
  24559. CFBundleRef bundleRef = CFBundleCreate (kCFAllocatorDefault, url);
  24560. CFRelease (url);
  24561. if (bundleRef != 0)
  24562. {
  24563. CFTypeRef name = CFBundleGetValueForInfoDictionaryKey (bundleRef, CFSTR("CFBundleName"));
  24564. if (name != 0 && CFGetTypeID (name) == CFStringGetTypeID())
  24565. pluginName = PlatformUtilities::cfStringToJuceString ((CFStringRef) name);
  24566. if (pluginName.isEmpty())
  24567. pluginName = file.getFileNameWithoutExtension();
  24568. CFTypeRef versionString = CFBundleGetValueForInfoDictionaryKey (bundleRef, CFSTR("CFBundleVersion"));
  24569. if (versionString != 0 && CFGetTypeID (versionString) == CFStringGetTypeID())
  24570. version = PlatformUtilities::cfStringToJuceString ((CFStringRef) versionString);
  24571. CFTypeRef manuString = CFBundleGetValueForInfoDictionaryKey (bundleRef, CFSTR("CFBundleGetInfoString"));
  24572. if (manuString != 0 && CFGetTypeID (manuString) == CFStringGetTypeID())
  24573. manufacturer = PlatformUtilities::cfStringToJuceString ((CFStringRef) manuString);
  24574. short resFileId = CFBundleOpenBundleResourceMap (bundleRef);
  24575. UseResFile (resFileId);
  24576. for (int i = 1; i <= Count1Resources ('thng'); ++i)
  24577. {
  24578. Handle h = Get1IndResource ('thng', i);
  24579. if (h != 0)
  24580. {
  24581. HLock (h);
  24582. const uint32* const types = (const uint32*) *h;
  24583. if (types[0] == kAudioUnitType_MusicDevice
  24584. || types[0] == kAudioUnitType_MusicEffect
  24585. || types[0] == kAudioUnitType_Effect
  24586. || types[0] == kAudioUnitType_Generator
  24587. || types[0] == kAudioUnitType_Panner)
  24588. {
  24589. componentDesc.componentType = types[0];
  24590. componentDesc.componentSubType = types[1];
  24591. componentDesc.componentManufacturer = types[2];
  24592. break;
  24593. }
  24594. HUnlock (h);
  24595. ReleaseResource (h);
  24596. }
  24597. }
  24598. CFBundleCloseBundleResourceMap (bundleRef, resFileId);
  24599. CFRelease (bundleRef);
  24600. }
  24601. }
  24602. return componentDesc.componentType != 0 && componentDesc.componentSubType != 0;
  24603. }
  24604. void AudioUnitPluginInstance::initialise()
  24605. {
  24606. if (initialised || audioUnit == 0)
  24607. return;
  24608. log (T("Initialising AU: ") + pluginName);
  24609. parameterIds.clear();
  24610. {
  24611. UInt32 paramListSize = 0;
  24612. AudioUnitGetProperty (audioUnit, kAudioUnitProperty_ParameterList, kAudioUnitScope_Global,
  24613. 0, 0, &paramListSize);
  24614. if (paramListSize > 0)
  24615. {
  24616. parameterIds.insertMultiple (0, 0, paramListSize / sizeof (int));
  24617. AudioUnitGetProperty (audioUnit, kAudioUnitProperty_ParameterList, kAudioUnitScope_Global,
  24618. 0, &parameterIds.getReference(0), &paramListSize);
  24619. }
  24620. }
  24621. {
  24622. AURenderCallbackStruct info;
  24623. zerostruct (info);
  24624. info.inputProcRefCon = this;
  24625. info.inputProc = renderGetInputCallback;
  24626. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input,
  24627. 0, &info, sizeof (info));
  24628. }
  24629. {
  24630. HostCallbackInfo info;
  24631. zerostruct (info);
  24632. info.hostUserData = this;
  24633. info.beatAndTempoProc = getBeatAndTempoCallback;
  24634. info.musicalTimeLocationProc = getMusicalTimeLocationCallback;
  24635. info.transportStateProc = getTransportStateCallback;
  24636. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_HostCallbacks, kAudioUnitScope_Global,
  24637. 0, &info, sizeof (info));
  24638. }
  24639. int numIns, numOuts;
  24640. getNumChannels (numIns, numOuts);
  24641. setPlayConfigDetails (numIns, numOuts, 0, 0);
  24642. initialised = AudioUnitInitialize (audioUnit) == noErr;
  24643. setLatencySamples (0);
  24644. }
  24645. void AudioUnitPluginInstance::prepareToPlay (double sampleRate_,
  24646. int samplesPerBlockExpected)
  24647. {
  24648. initialise();
  24649. if (initialised)
  24650. {
  24651. int numIns, numOuts;
  24652. getNumChannels (numIns, numOuts);
  24653. setPlayConfigDetails (numIns, numOuts, sampleRate_, samplesPerBlockExpected);
  24654. Float64 latencySecs = 0.0;
  24655. UInt32 latencySize = sizeof (latencySecs);
  24656. AudioUnitGetProperty (audioUnit, kAudioUnitProperty_Latency, kAudioUnitScope_Global,
  24657. 0, &latencySecs, &latencySize);
  24658. setLatencySamples (roundToInt (latencySecs * sampleRate_));
  24659. AudioUnitReset (audioUnit, kAudioUnitScope_Input, 0);
  24660. AudioUnitReset (audioUnit, kAudioUnitScope_Output, 0);
  24661. AudioUnitReset (audioUnit, kAudioUnitScope_Global, 0);
  24662. AudioStreamBasicDescription stream;
  24663. zerostruct (stream);
  24664. stream.mSampleRate = sampleRate_;
  24665. stream.mFormatID = kAudioFormatLinearPCM;
  24666. stream.mFormatFlags = kAudioFormatFlagsNativeFloatPacked | kAudioFormatFlagIsNonInterleaved;
  24667. stream.mFramesPerPacket = 1;
  24668. stream.mBytesPerPacket = 4;
  24669. stream.mBytesPerFrame = 4;
  24670. stream.mBitsPerChannel = 32;
  24671. stream.mChannelsPerFrame = numIns;
  24672. OSStatus err = AudioUnitSetProperty (audioUnit,
  24673. kAudioUnitProperty_StreamFormat,
  24674. kAudioUnitScope_Input,
  24675. 0, &stream, sizeof (stream));
  24676. stream.mChannelsPerFrame = numOuts;
  24677. err = AudioUnitSetProperty (audioUnit,
  24678. kAudioUnitProperty_StreamFormat,
  24679. kAudioUnitScope_Output,
  24680. 0, &stream, sizeof (stream));
  24681. outputBufferList.calloc (sizeof (AudioBufferList) + sizeof (AudioBuffer) * (numOuts + 1), 1);
  24682. outputBufferList->mNumberBuffers = numOuts;
  24683. for (int i = numOuts; --i >= 0;)
  24684. outputBufferList->mBuffers[i].mNumberChannels = 1;
  24685. zerostruct (timeStamp);
  24686. timeStamp.mSampleTime = 0;
  24687. timeStamp.mHostTime = AudioGetCurrentHostTime();
  24688. timeStamp.mFlags = kAudioTimeStampSampleTimeValid | kAudioTimeStampHostTimeValid;
  24689. currentBuffer = 0;
  24690. wasPlaying = false;
  24691. }
  24692. }
  24693. void AudioUnitPluginInstance::releaseResources()
  24694. {
  24695. if (initialised)
  24696. {
  24697. AudioUnitReset (audioUnit, kAudioUnitScope_Input, 0);
  24698. AudioUnitReset (audioUnit, kAudioUnitScope_Output, 0);
  24699. AudioUnitReset (audioUnit, kAudioUnitScope_Global, 0);
  24700. outputBufferList.free();
  24701. currentBuffer = 0;
  24702. }
  24703. }
  24704. OSStatus AudioUnitPluginInstance::renderGetInput (AudioUnitRenderActionFlags* ioActionFlags,
  24705. const AudioTimeStamp* inTimeStamp,
  24706. UInt32 inBusNumber,
  24707. UInt32 inNumberFrames,
  24708. AudioBufferList* ioData) const
  24709. {
  24710. if (inBusNumber == 0
  24711. && currentBuffer != 0)
  24712. {
  24713. jassert (inNumberFrames == currentBuffer->getNumSamples()); // if this ever happens, might need to add extra handling
  24714. for (int i = 0; i < ioData->mNumberBuffers; ++i)
  24715. {
  24716. if (i < currentBuffer->getNumChannels())
  24717. {
  24718. memcpy (ioData->mBuffers[i].mData,
  24719. currentBuffer->getSampleData (i, 0),
  24720. sizeof (float) * inNumberFrames);
  24721. }
  24722. else
  24723. {
  24724. zeromem (ioData->mBuffers[i].mData, sizeof (float) * inNumberFrames);
  24725. }
  24726. }
  24727. }
  24728. return noErr;
  24729. }
  24730. void AudioUnitPluginInstance::processBlock (AudioSampleBuffer& buffer,
  24731. MidiBuffer& midiMessages)
  24732. {
  24733. const int numSamples = buffer.getNumSamples();
  24734. if (initialised)
  24735. {
  24736. AudioUnitRenderActionFlags flags = 0;
  24737. timeStamp.mHostTime = AudioGetCurrentHostTime();
  24738. for (int i = getNumOutputChannels(); --i >= 0;)
  24739. {
  24740. outputBufferList->mBuffers[i].mDataByteSize = sizeof (float) * numSamples;
  24741. outputBufferList->mBuffers[i].mData = buffer.getSampleData (i, 0);
  24742. }
  24743. currentBuffer = &buffer;
  24744. if (wantsMidiMessages)
  24745. {
  24746. const uint8* midiEventData;
  24747. int midiEventSize, midiEventPosition;
  24748. MidiBuffer::Iterator i (midiMessages);
  24749. while (i.getNextEvent (midiEventData, midiEventSize, midiEventPosition))
  24750. {
  24751. if (midiEventSize <= 3)
  24752. MusicDeviceMIDIEvent (audioUnit,
  24753. midiEventData[0], midiEventData[1], midiEventData[2],
  24754. midiEventPosition);
  24755. else
  24756. MusicDeviceSysEx (audioUnit, midiEventData, midiEventSize);
  24757. }
  24758. midiMessages.clear();
  24759. }
  24760. AudioUnitRender (audioUnit, &flags, &timeStamp,
  24761. 0, numSamples, outputBufferList);
  24762. timeStamp.mSampleTime += numSamples;
  24763. }
  24764. else
  24765. {
  24766. // Not initialised, so just bypass..
  24767. for (int i = getNumInputChannels(); i < getNumOutputChannels(); ++i)
  24768. buffer.clear (i, 0, buffer.getNumSamples());
  24769. }
  24770. }
  24771. OSStatus AudioUnitPluginInstance::getBeatAndTempo (Float64* outCurrentBeat, Float64* outCurrentTempo) const
  24772. {
  24773. AudioPlayHead* const ph = getPlayHead();
  24774. AudioPlayHead::CurrentPositionInfo result;
  24775. if (ph != 0 && ph->getCurrentPosition (result))
  24776. {
  24777. if (outCurrentBeat != 0)
  24778. *outCurrentBeat = result.ppqPosition;
  24779. if (outCurrentTempo != 0)
  24780. *outCurrentTempo = result.bpm;
  24781. }
  24782. else
  24783. {
  24784. if (outCurrentBeat != 0)
  24785. *outCurrentBeat = 0;
  24786. if (outCurrentTempo != 0)
  24787. *outCurrentTempo = 120.0;
  24788. }
  24789. return noErr;
  24790. }
  24791. OSStatus AudioUnitPluginInstance::getMusicalTimeLocation (UInt32* outDeltaSampleOffsetToNextBeat,
  24792. Float32* outTimeSig_Numerator,
  24793. UInt32* outTimeSig_Denominator,
  24794. Float64* outCurrentMeasureDownBeat) const
  24795. {
  24796. AudioPlayHead* const ph = getPlayHead();
  24797. AudioPlayHead::CurrentPositionInfo result;
  24798. if (ph != 0 && ph->getCurrentPosition (result))
  24799. {
  24800. if (outTimeSig_Numerator != 0)
  24801. *outTimeSig_Numerator = result.timeSigNumerator;
  24802. if (outTimeSig_Denominator != 0)
  24803. *outTimeSig_Denominator = result.timeSigDenominator;
  24804. if (outDeltaSampleOffsetToNextBeat != 0)
  24805. *outDeltaSampleOffsetToNextBeat = 0; //xxx
  24806. if (outCurrentMeasureDownBeat != 0)
  24807. *outCurrentMeasureDownBeat = result.ppqPositionOfLastBarStart; //xxx wrong
  24808. }
  24809. else
  24810. {
  24811. if (outDeltaSampleOffsetToNextBeat != 0)
  24812. *outDeltaSampleOffsetToNextBeat = 0;
  24813. if (outTimeSig_Numerator != 0)
  24814. *outTimeSig_Numerator = 4;
  24815. if (outTimeSig_Denominator != 0)
  24816. *outTimeSig_Denominator = 4;
  24817. if (outCurrentMeasureDownBeat != 0)
  24818. *outCurrentMeasureDownBeat = 0;
  24819. }
  24820. return noErr;
  24821. }
  24822. OSStatus AudioUnitPluginInstance::getTransportState (Boolean* outIsPlaying,
  24823. Boolean* outTransportStateChanged,
  24824. Float64* outCurrentSampleInTimeLine,
  24825. Boolean* outIsCycling,
  24826. Float64* outCycleStartBeat,
  24827. Float64* outCycleEndBeat)
  24828. {
  24829. AudioPlayHead* const ph = getPlayHead();
  24830. AudioPlayHead::CurrentPositionInfo result;
  24831. if (ph != 0 && ph->getCurrentPosition (result))
  24832. {
  24833. if (outIsPlaying != 0)
  24834. *outIsPlaying = result.isPlaying;
  24835. if (outTransportStateChanged != 0)
  24836. {
  24837. *outTransportStateChanged = result.isPlaying != wasPlaying;
  24838. wasPlaying = result.isPlaying;
  24839. }
  24840. if (outCurrentSampleInTimeLine != 0)
  24841. *outCurrentSampleInTimeLine = roundToInt (result.timeInSeconds * getSampleRate());
  24842. if (outIsCycling != 0)
  24843. *outIsCycling = false;
  24844. if (outCycleStartBeat != 0)
  24845. *outCycleStartBeat = 0;
  24846. if (outCycleEndBeat != 0)
  24847. *outCycleEndBeat = 0;
  24848. }
  24849. else
  24850. {
  24851. if (outIsPlaying != 0)
  24852. *outIsPlaying = false;
  24853. if (outTransportStateChanged != 0)
  24854. *outTransportStateChanged = false;
  24855. if (outCurrentSampleInTimeLine != 0)
  24856. *outCurrentSampleInTimeLine = 0;
  24857. if (outIsCycling != 0)
  24858. *outIsCycling = false;
  24859. if (outCycleStartBeat != 0)
  24860. *outCycleStartBeat = 0;
  24861. if (outCycleEndBeat != 0)
  24862. *outCycleEndBeat = 0;
  24863. }
  24864. return noErr;
  24865. }
  24866. static VoidArray activeWindows;
  24867. class AudioUnitPluginWindowCocoa : public AudioProcessorEditor
  24868. {
  24869. public:
  24870. AudioUnitPluginWindowCocoa (AudioUnitPluginInstance& plugin_, const bool createGenericViewIfNeeded)
  24871. : AudioProcessorEditor (&plugin_),
  24872. plugin (plugin_),
  24873. wrapper (0)
  24874. {
  24875. addAndMakeVisible (wrapper = new NSViewComponent());
  24876. activeWindows.add (this);
  24877. setOpaque (true);
  24878. setVisible (true);
  24879. setSize (100, 100);
  24880. createView (createGenericViewIfNeeded);
  24881. }
  24882. ~AudioUnitPluginWindowCocoa()
  24883. {
  24884. const bool wasValid = isValid();
  24885. wrapper->setView (0);
  24886. activeWindows.removeValue (this);
  24887. if (wasValid)
  24888. plugin.editorBeingDeleted (this);
  24889. delete wrapper;
  24890. }
  24891. bool isValid() const { return wrapper->getView() != 0; }
  24892. void paint (Graphics& g)
  24893. {
  24894. g.fillAll (Colours::white);
  24895. }
  24896. void resized()
  24897. {
  24898. wrapper->setSize (getWidth(), getHeight());
  24899. }
  24900. private:
  24901. AudioUnitPluginInstance& plugin;
  24902. NSViewComponent* wrapper;
  24903. bool createView (const bool createGenericViewIfNeeded)
  24904. {
  24905. NSView* pluginView = 0;
  24906. UInt32 dataSize = 0;
  24907. Boolean isWritable = false;
  24908. if (AudioUnitGetPropertyInfo (plugin.audioUnit, kAudioUnitProperty_CocoaUI, kAudioUnitScope_Global,
  24909. 0, &dataSize, &isWritable) == noErr
  24910. && dataSize != 0
  24911. && AudioUnitGetPropertyInfo (plugin.audioUnit, kAudioUnitProperty_CocoaUI, kAudioUnitScope_Global,
  24912. 0, &dataSize, &isWritable) == noErr)
  24913. {
  24914. HeapBlock <AudioUnitCocoaViewInfo> info;
  24915. info.calloc (dataSize, 1);
  24916. if (AudioUnitGetProperty (plugin.audioUnit, kAudioUnitProperty_CocoaUI, kAudioUnitScope_Global,
  24917. 0, info, &dataSize) == noErr)
  24918. {
  24919. NSString* viewClassName = (NSString*) (info->mCocoaAUViewClass[0]);
  24920. NSString* path = (NSString*) CFURLCopyPath (info->mCocoaAUViewBundleLocation);
  24921. NSBundle* viewBundle = [NSBundle bundleWithPath: [path autorelease]];
  24922. Class viewClass = [viewBundle classNamed: viewClassName];
  24923. if ([viewClass conformsToProtocol: @protocol (AUCocoaUIBase)]
  24924. && [viewClass instancesRespondToSelector: @selector (interfaceVersion)]
  24925. && [viewClass instancesRespondToSelector: @selector (uiViewForAudioUnit: withSize:)])
  24926. {
  24927. id factory = [[[viewClass alloc] init] autorelease];
  24928. pluginView = [factory uiViewForAudioUnit: plugin.audioUnit
  24929. withSize: NSMakeSize (getWidth(), getHeight())];
  24930. }
  24931. for (int i = (dataSize - sizeof (CFURLRef)) / sizeof (CFStringRef); --i >= 0;)
  24932. {
  24933. CFRelease (info->mCocoaAUViewClass[i]);
  24934. CFRelease (info->mCocoaAUViewBundleLocation);
  24935. }
  24936. }
  24937. }
  24938. if (createGenericViewIfNeeded && (pluginView == 0))
  24939. pluginView = [[AUGenericView alloc] initWithAudioUnit: plugin.audioUnit];
  24940. wrapper->setView (pluginView);
  24941. if (pluginView != 0)
  24942. setSize ([pluginView frame].size.width,
  24943. [pluginView frame].size.height);
  24944. return pluginView != 0;
  24945. }
  24946. };
  24947. #if JUCE_SUPPORT_CARBON
  24948. class AudioUnitPluginWindowCarbon : public AudioProcessorEditor
  24949. {
  24950. public:
  24951. AudioUnitPluginWindowCarbon (AudioUnitPluginInstance& plugin_)
  24952. : AudioProcessorEditor (&plugin_),
  24953. plugin (plugin_),
  24954. viewComponent (0)
  24955. {
  24956. addAndMakeVisible (innerWrapper = new InnerWrapperComponent (this));
  24957. activeWindows.add (this);
  24958. setOpaque (true);
  24959. setVisible (true);
  24960. setSize (400, 300);
  24961. ComponentDescription viewList [16];
  24962. UInt32 viewListSize = sizeof (viewList);
  24963. AudioUnitGetProperty (plugin.audioUnit, kAudioUnitProperty_GetUIComponentList, kAudioUnitScope_Global,
  24964. 0, &viewList, &viewListSize);
  24965. componentRecord = FindNextComponent (0, &viewList[0]);
  24966. }
  24967. ~AudioUnitPluginWindowCarbon()
  24968. {
  24969. deleteAndZero (innerWrapper);
  24970. activeWindows.removeValue (this);
  24971. if (isValid())
  24972. plugin.editorBeingDeleted (this);
  24973. }
  24974. bool isValid() const throw() { return componentRecord != 0; }
  24975. void paint (Graphics& g)
  24976. {
  24977. g.fillAll (Colours::black);
  24978. }
  24979. void resized()
  24980. {
  24981. innerWrapper->setSize (getWidth(), getHeight());
  24982. }
  24983. bool keyStateChanged (const bool)
  24984. {
  24985. return false;
  24986. }
  24987. bool keyPressed (const KeyPress&)
  24988. {
  24989. return false;
  24990. }
  24991. void broughtToFront()
  24992. {
  24993. activeWindows.removeValue (this);
  24994. activeWindows.add (this);
  24995. }
  24996. AudioUnit getAudioUnit() const { return plugin.audioUnit; }
  24997. AudioUnitCarbonView getViewComponent()
  24998. {
  24999. if (viewComponent == 0 && componentRecord != 0)
  25000. viewComponent = (AudioUnitCarbonView) OpenComponent (componentRecord);
  25001. return viewComponent;
  25002. }
  25003. void closeViewComponent()
  25004. {
  25005. if (viewComponent != 0)
  25006. {
  25007. CloseComponent (viewComponent);
  25008. viewComponent = 0;
  25009. }
  25010. }
  25011. juce_UseDebuggingNewOperator
  25012. private:
  25013. AudioUnitPluginInstance& plugin;
  25014. ComponentRecord* componentRecord;
  25015. AudioUnitCarbonView viewComponent;
  25016. class InnerWrapperComponent : public CarbonViewWrapperComponent
  25017. {
  25018. public:
  25019. InnerWrapperComponent (AudioUnitPluginWindowCarbon* const owner_)
  25020. : owner (owner_)
  25021. {
  25022. }
  25023. ~InnerWrapperComponent()
  25024. {
  25025. deleteWindow();
  25026. }
  25027. HIViewRef attachView (WindowRef windowRef, HIViewRef rootView)
  25028. {
  25029. log (T("Opening AU GUI: ") + owner->plugin.getName());
  25030. AudioUnitCarbonView viewComponent = owner->getViewComponent();
  25031. if (viewComponent == 0)
  25032. return 0;
  25033. Float32Point pos = { 0, 0 };
  25034. Float32Point size = { 250, 200 };
  25035. HIViewRef pluginView = 0;
  25036. AudioUnitCarbonViewCreate (viewComponent,
  25037. owner->getAudioUnit(),
  25038. windowRef,
  25039. rootView,
  25040. &pos,
  25041. &size,
  25042. (ControlRef*) &pluginView);
  25043. return pluginView;
  25044. }
  25045. void removeView (HIViewRef)
  25046. {
  25047. log (T("Closing AU GUI: ") + owner->plugin.getName());
  25048. owner->closeViewComponent();
  25049. }
  25050. private:
  25051. AudioUnitPluginWindowCarbon* const owner;
  25052. };
  25053. friend class InnerWrapperComponent;
  25054. InnerWrapperComponent* innerWrapper;
  25055. };
  25056. #endif
  25057. AudioProcessorEditor* AudioUnitPluginInstance::createEditor()
  25058. {
  25059. ScopedPointer <AudioProcessorEditor> w (new AudioUnitPluginWindowCocoa (*this, false));
  25060. if (! ((AudioUnitPluginWindowCocoa*) w)->isValid())
  25061. w = 0;
  25062. #if JUCE_SUPPORT_CARBON
  25063. if (w == 0)
  25064. {
  25065. w = new AudioUnitPluginWindowCarbon (*this);
  25066. if (! ((AudioUnitPluginWindowCarbon*) w)->isValid())
  25067. w = 0;
  25068. }
  25069. #endif
  25070. if (w == 0)
  25071. w = new AudioUnitPluginWindowCocoa (*this, true); // use AUGenericView as a fallback
  25072. return w.release();
  25073. }
  25074. const String AudioUnitPluginInstance::getCategory() const
  25075. {
  25076. const char* result = 0;
  25077. switch (componentDesc.componentType)
  25078. {
  25079. case kAudioUnitType_Effect:
  25080. case kAudioUnitType_MusicEffect:
  25081. result = "Effect";
  25082. break;
  25083. case kAudioUnitType_MusicDevice:
  25084. result = "Synth";
  25085. break;
  25086. case kAudioUnitType_Generator:
  25087. result = "Generator";
  25088. break;
  25089. case kAudioUnitType_Panner:
  25090. result = "Panner";
  25091. break;
  25092. default:
  25093. break;
  25094. }
  25095. return result;
  25096. }
  25097. int AudioUnitPluginInstance::getNumParameters()
  25098. {
  25099. return parameterIds.size();
  25100. }
  25101. float AudioUnitPluginInstance::getParameter (int index)
  25102. {
  25103. const ScopedLock sl (lock);
  25104. Float32 value = 0.0f;
  25105. if (audioUnit != 0 && ((unsigned int) index) < (unsigned int) parameterIds.size())
  25106. {
  25107. AudioUnitGetParameter (audioUnit,
  25108. (UInt32) parameterIds.getUnchecked (index),
  25109. kAudioUnitScope_Global, 0,
  25110. &value);
  25111. }
  25112. return value;
  25113. }
  25114. void AudioUnitPluginInstance::setParameter (int index, float newValue)
  25115. {
  25116. const ScopedLock sl (lock);
  25117. if (audioUnit != 0 && ((unsigned int) index) < (unsigned int) parameterIds.size())
  25118. {
  25119. AudioUnitSetParameter (audioUnit,
  25120. (UInt32) parameterIds.getUnchecked (index),
  25121. kAudioUnitScope_Global, 0,
  25122. newValue, 0);
  25123. }
  25124. }
  25125. const String AudioUnitPluginInstance::getParameterName (int index)
  25126. {
  25127. AudioUnitParameterInfo info;
  25128. zerostruct (info);
  25129. UInt32 sz = sizeof (info);
  25130. String name;
  25131. if (AudioUnitGetProperty (audioUnit,
  25132. kAudioUnitProperty_ParameterInfo,
  25133. kAudioUnitScope_Global,
  25134. parameterIds [index], &info, &sz) == noErr)
  25135. {
  25136. if ((info.flags & kAudioUnitParameterFlag_HasCFNameString) != 0)
  25137. name = PlatformUtilities::cfStringToJuceString (info.cfNameString);
  25138. else
  25139. name = String (info.name, sizeof (info.name));
  25140. }
  25141. return name;
  25142. }
  25143. const String AudioUnitPluginInstance::getParameterText (int index)
  25144. {
  25145. return String (getParameter (index));
  25146. }
  25147. bool AudioUnitPluginInstance::isParameterAutomatable (int index) const
  25148. {
  25149. AudioUnitParameterInfo info;
  25150. UInt32 sz = sizeof (info);
  25151. if (AudioUnitGetProperty (audioUnit,
  25152. kAudioUnitProperty_ParameterInfo,
  25153. kAudioUnitScope_Global,
  25154. parameterIds [index], &info, &sz) == noErr)
  25155. {
  25156. return (info.flags & kAudioUnitParameterFlag_NonRealTime) == 0;
  25157. }
  25158. return true;
  25159. }
  25160. int AudioUnitPluginInstance::getNumPrograms()
  25161. {
  25162. CFArrayRef presets;
  25163. UInt32 sz = sizeof (CFArrayRef);
  25164. int num = 0;
  25165. if (AudioUnitGetProperty (audioUnit,
  25166. kAudioUnitProperty_FactoryPresets,
  25167. kAudioUnitScope_Global,
  25168. 0, &presets, &sz) == noErr)
  25169. {
  25170. num = (int) CFArrayGetCount (presets);
  25171. CFRelease (presets);
  25172. }
  25173. return num;
  25174. }
  25175. int AudioUnitPluginInstance::getCurrentProgram()
  25176. {
  25177. AUPreset current;
  25178. current.presetNumber = 0;
  25179. UInt32 sz = sizeof (AUPreset);
  25180. AudioUnitGetProperty (audioUnit,
  25181. kAudioUnitProperty_FactoryPresets,
  25182. kAudioUnitScope_Global,
  25183. 0, &current, &sz);
  25184. return current.presetNumber;
  25185. }
  25186. void AudioUnitPluginInstance::setCurrentProgram (int newIndex)
  25187. {
  25188. AUPreset current;
  25189. current.presetNumber = newIndex;
  25190. current.presetName = 0;
  25191. AudioUnitSetProperty (audioUnit,
  25192. kAudioUnitProperty_FactoryPresets,
  25193. kAudioUnitScope_Global,
  25194. 0, &current, sizeof (AUPreset));
  25195. }
  25196. const String AudioUnitPluginInstance::getProgramName (int index)
  25197. {
  25198. String s;
  25199. CFArrayRef presets;
  25200. UInt32 sz = sizeof (CFArrayRef);
  25201. if (AudioUnitGetProperty (audioUnit,
  25202. kAudioUnitProperty_FactoryPresets,
  25203. kAudioUnitScope_Global,
  25204. 0, &presets, &sz) == noErr)
  25205. {
  25206. for (CFIndex i = 0; i < CFArrayGetCount (presets); ++i)
  25207. {
  25208. const AUPreset* p = (const AUPreset*) CFArrayGetValueAtIndex (presets, i);
  25209. if (p != 0 && p->presetNumber == index)
  25210. {
  25211. s = PlatformUtilities::cfStringToJuceString (p->presetName);
  25212. break;
  25213. }
  25214. }
  25215. CFRelease (presets);
  25216. }
  25217. return s;
  25218. }
  25219. void AudioUnitPluginInstance::changeProgramName (int index, const String& newName)
  25220. {
  25221. jassertfalse // xxx not implemented!
  25222. }
  25223. const String AudioUnitPluginInstance::getInputChannelName (const int index) const
  25224. {
  25225. if (((unsigned int) index) < (unsigned int) getNumInputChannels())
  25226. return T("Input ") + String (index + 1);
  25227. return String::empty;
  25228. }
  25229. bool AudioUnitPluginInstance::isInputChannelStereoPair (int index) const
  25230. {
  25231. if (((unsigned int) index) >= (unsigned int) getNumInputChannels())
  25232. return false;
  25233. return true;
  25234. }
  25235. const String AudioUnitPluginInstance::getOutputChannelName (const int index) const
  25236. {
  25237. if (((unsigned int) index) < (unsigned int) getNumOutputChannels())
  25238. return T("Output ") + String (index + 1);
  25239. return String::empty;
  25240. }
  25241. bool AudioUnitPluginInstance::isOutputChannelStereoPair (int index) const
  25242. {
  25243. if (((unsigned int) index) >= (unsigned int) getNumOutputChannels())
  25244. return false;
  25245. return true;
  25246. }
  25247. void AudioUnitPluginInstance::getStateInformation (MemoryBlock& destData)
  25248. {
  25249. getCurrentProgramStateInformation (destData);
  25250. }
  25251. void AudioUnitPluginInstance::getCurrentProgramStateInformation (MemoryBlock& destData)
  25252. {
  25253. CFPropertyListRef propertyList = 0;
  25254. UInt32 sz = sizeof (CFPropertyListRef);
  25255. if (AudioUnitGetProperty (audioUnit,
  25256. kAudioUnitProperty_ClassInfo,
  25257. kAudioUnitScope_Global,
  25258. 0, &propertyList, &sz) == noErr)
  25259. {
  25260. CFWriteStreamRef stream = CFWriteStreamCreateWithAllocatedBuffers (kCFAllocatorDefault, kCFAllocatorDefault);
  25261. CFWriteStreamOpen (stream);
  25262. CFIndex bytesWritten = CFPropertyListWriteToStream (propertyList, stream, kCFPropertyListBinaryFormat_v1_0, 0);
  25263. CFWriteStreamClose (stream);
  25264. CFDataRef data = (CFDataRef) CFWriteStreamCopyProperty (stream, kCFStreamPropertyDataWritten);
  25265. destData.setSize (bytesWritten);
  25266. destData.copyFrom (CFDataGetBytePtr (data), 0, destData.getSize());
  25267. CFRelease (data);
  25268. CFRelease (stream);
  25269. CFRelease (propertyList);
  25270. }
  25271. }
  25272. void AudioUnitPluginInstance::setStateInformation (const void* data, int sizeInBytes)
  25273. {
  25274. setCurrentProgramStateInformation (data, sizeInBytes);
  25275. }
  25276. void AudioUnitPluginInstance::setCurrentProgramStateInformation (const void* data, int sizeInBytes)
  25277. {
  25278. CFReadStreamRef stream = CFReadStreamCreateWithBytesNoCopy (kCFAllocatorDefault,
  25279. (const UInt8*) data,
  25280. sizeInBytes,
  25281. kCFAllocatorNull);
  25282. CFReadStreamOpen (stream);
  25283. CFPropertyListFormat format = kCFPropertyListBinaryFormat_v1_0;
  25284. CFPropertyListRef propertyList = CFPropertyListCreateFromStream (kCFAllocatorDefault,
  25285. stream,
  25286. 0,
  25287. kCFPropertyListImmutable,
  25288. &format,
  25289. 0);
  25290. CFRelease (stream);
  25291. if (propertyList != 0)
  25292. AudioUnitSetProperty (audioUnit,
  25293. kAudioUnitProperty_ClassInfo,
  25294. kAudioUnitScope_Global,
  25295. 0, &propertyList, sizeof (propertyList));
  25296. }
  25297. AudioUnitPluginFormat::AudioUnitPluginFormat()
  25298. {
  25299. }
  25300. AudioUnitPluginFormat::~AudioUnitPluginFormat()
  25301. {
  25302. }
  25303. void AudioUnitPluginFormat::findAllTypesForFile (OwnedArray <PluginDescription>& results,
  25304. const String& fileOrIdentifier)
  25305. {
  25306. if (! fileMightContainThisPluginType (fileOrIdentifier))
  25307. return;
  25308. PluginDescription desc;
  25309. desc.fileOrIdentifier = fileOrIdentifier;
  25310. desc.uid = 0;
  25311. try
  25312. {
  25313. ScopedPointer <AudioPluginInstance> createdInstance (createInstanceFromDescription (desc));
  25314. AudioUnitPluginInstance* const auInstance = dynamic_cast <AudioUnitPluginInstance*> ((AudioPluginInstance*) createdInstance);
  25315. if (auInstance != 0)
  25316. {
  25317. auInstance->fillInPluginDescription (desc);
  25318. results.add (new PluginDescription (desc));
  25319. }
  25320. }
  25321. catch (...)
  25322. {
  25323. // crashed while loading...
  25324. }
  25325. }
  25326. AudioPluginInstance* AudioUnitPluginFormat::createInstanceFromDescription (const PluginDescription& desc)
  25327. {
  25328. if (fileMightContainThisPluginType (desc.fileOrIdentifier))
  25329. {
  25330. ScopedPointer <AudioUnitPluginInstance> result (new AudioUnitPluginInstance (desc.fileOrIdentifier));
  25331. if (result->audioUnit != 0)
  25332. {
  25333. result->initialise();
  25334. return result.release();
  25335. }
  25336. }
  25337. return 0;
  25338. }
  25339. const StringArray AudioUnitPluginFormat::searchPathsForPlugins (const FileSearchPath& /*directoriesToSearch*/,
  25340. const bool /*recursive*/)
  25341. {
  25342. StringArray result;
  25343. ComponentRecord* comp = 0;
  25344. ComponentDescription desc;
  25345. zerostruct (desc);
  25346. for (;;)
  25347. {
  25348. zerostruct (desc);
  25349. comp = FindNextComponent (comp, &desc);
  25350. if (comp == 0)
  25351. break;
  25352. GetComponentInfo (comp, &desc, 0, 0, 0);
  25353. if (desc.componentType == kAudioUnitType_MusicDevice
  25354. || desc.componentType == kAudioUnitType_MusicEffect
  25355. || desc.componentType == kAudioUnitType_Effect
  25356. || desc.componentType == kAudioUnitType_Generator
  25357. || desc.componentType == kAudioUnitType_Panner)
  25358. {
  25359. const String s (createAUPluginIdentifier (desc));
  25360. DBG (s);
  25361. result.add (s);
  25362. }
  25363. }
  25364. return result;
  25365. }
  25366. bool AudioUnitPluginFormat::fileMightContainThisPluginType (const String& fileOrIdentifier)
  25367. {
  25368. ComponentDescription desc;
  25369. String name, version, manufacturer;
  25370. if (getComponentDescFromIdentifier (fileOrIdentifier, desc, name, version, manufacturer))
  25371. return FindNextComponent (0, &desc) != 0;
  25372. const File f (fileOrIdentifier);
  25373. return f.hasFileExtension (T(".component"))
  25374. && f.isDirectory();
  25375. }
  25376. const String AudioUnitPluginFormat::getNameOfPluginFromIdentifier (const String& fileOrIdentifier)
  25377. {
  25378. ComponentDescription desc;
  25379. String name, version, manufacturer;
  25380. getComponentDescFromIdentifier (fileOrIdentifier, desc, name, version, manufacturer);
  25381. if (name.isEmpty())
  25382. name = fileOrIdentifier;
  25383. return name;
  25384. }
  25385. bool AudioUnitPluginFormat::doesPluginStillExist (const PluginDescription& desc)
  25386. {
  25387. if (desc.fileOrIdentifier.startsWithIgnoreCase (auIdentifierPrefix))
  25388. return fileMightContainThisPluginType (desc.fileOrIdentifier);
  25389. else
  25390. return File (desc.fileOrIdentifier).exists();
  25391. }
  25392. const FileSearchPath AudioUnitPluginFormat::getDefaultLocationsToSearch()
  25393. {
  25394. return FileSearchPath ("/(Default AudioUnit locations)");
  25395. }
  25396. #endif
  25397. END_JUCE_NAMESPACE
  25398. #undef log
  25399. #endif
  25400. /*** End of inlined file: juce_AudioUnitPluginFormat.mm ***/
  25401. /*** Start of inlined file: juce_VSTPluginFormat.mm ***/
  25402. // This file just wraps juce_VSTPluginFormat.cpp in an objective-C wrapper
  25403. #define JUCE_MAC_VST_INCLUDED 1
  25404. /*** Start of inlined file: juce_VSTPluginFormat.cpp ***/
  25405. #if JUCE_PLUGINHOST_VST
  25406. #if (defined (_WIN32) || defined (_WIN64))
  25407. #undef _WIN32_WINNT
  25408. #define _WIN32_WINNT 0x500
  25409. #undef STRICT
  25410. #define STRICT
  25411. #include <windows.h>
  25412. #include <float.h>
  25413. #pragma warning (disable : 4312 4355)
  25414. #elif defined (LINUX) || defined (__linux__)
  25415. #include <float.h>
  25416. #include <sys/time.h>
  25417. #include <X11/Xlib.h>
  25418. #include <X11/Xutil.h>
  25419. #include <X11/Xatom.h>
  25420. #undef Font
  25421. #undef KeyPress
  25422. #undef Drawable
  25423. #undef Time
  25424. #else
  25425. #ifndef JUCE_MAC_VST_INCLUDED
  25426. // On the mac, this file needs to be compiled indirectly, by using
  25427. // juce_VSTPluginFormat.mm instead - that wraps it as an objective-C file for cocoa
  25428. #error
  25429. #endif
  25430. #include <Cocoa/Cocoa.h>
  25431. #include <Carbon/Carbon.h>
  25432. #endif
  25433. #if ! (JUCE_MAC && JUCE_64BIT)
  25434. BEGIN_JUCE_NAMESPACE
  25435. #if JUCE_MAC && JUCE_SUPPORT_CARBON
  25436. #endif
  25437. #undef PRAGMA_ALIGN_SUPPORTED
  25438. #define VST_FORCE_DEPRECATED 0
  25439. #ifdef _MSC_VER
  25440. #pragma warning (push)
  25441. #pragma warning (disable: 4996)
  25442. #endif
  25443. #include "pluginterfaces/vst2.x/aeffectx.h"
  25444. #ifdef _MSC_VER
  25445. #pragma warning (pop)
  25446. #endif
  25447. #if JUCE_LINUX
  25448. #define Font JUCE_NAMESPACE::Font
  25449. #define KeyPress JUCE_NAMESPACE::KeyPress
  25450. #define Drawable JUCE_NAMESPACE::Drawable
  25451. #define Time JUCE_NAMESPACE::Time
  25452. #endif
  25453. /*** Start of inlined file: juce_VSTMidiEventList.h ***/
  25454. #ifdef __aeffect__
  25455. #ifndef __JUCE_VSTMIDIEVENTLIST_JUCEHEADER__
  25456. #define __JUCE_VSTMIDIEVENTLIST_JUCEHEADER__
  25457. class VSTMidiEventList
  25458. {
  25459. public:
  25460. VSTMidiEventList()
  25461. : numEventsUsed (0), numEventsAllocated (0)
  25462. {
  25463. }
  25464. ~VSTMidiEventList()
  25465. {
  25466. freeEvents();
  25467. }
  25468. void clear()
  25469. {
  25470. numEventsUsed = 0;
  25471. if (events != 0)
  25472. events->numEvents = 0;
  25473. }
  25474. void addEvent (const void* const midiData, const int numBytes, const int frameOffset)
  25475. {
  25476. ensureSize (numEventsUsed + 1);
  25477. VstMidiEvent* const e = (VstMidiEvent*) (events->events [numEventsUsed]);
  25478. events->numEvents = ++numEventsUsed;
  25479. if (numBytes <= 4)
  25480. {
  25481. if (e->type == kVstSysExType)
  25482. {
  25483. juce_free (((VstMidiSysexEvent*) e)->sysexDump);
  25484. e->type = kVstMidiType;
  25485. e->byteSize = sizeof (VstMidiEvent);
  25486. e->noteLength = 0;
  25487. e->noteOffset = 0;
  25488. e->detune = 0;
  25489. e->noteOffVelocity = 0;
  25490. }
  25491. e->deltaFrames = frameOffset;
  25492. memcpy (e->midiData, midiData, numBytes);
  25493. }
  25494. else
  25495. {
  25496. VstMidiSysexEvent* const se = (VstMidiSysexEvent*) e;
  25497. if (se->type == kVstSysExType)
  25498. se->sysexDump = (char*) juce_realloc (se->sysexDump, numBytes);
  25499. else
  25500. se->sysexDump = (char*) juce_malloc (numBytes);
  25501. memcpy (se->sysexDump, midiData, numBytes);
  25502. se->type = kVstSysExType;
  25503. se->byteSize = sizeof (VstMidiSysexEvent);
  25504. se->deltaFrames = frameOffset;
  25505. se->flags = 0;
  25506. se->dumpBytes = numBytes;
  25507. se->resvd1 = 0;
  25508. se->resvd2 = 0;
  25509. }
  25510. }
  25511. // Handy method to pull the events out of an event buffer supplied by the host
  25512. // or plugin.
  25513. static void addEventsToMidiBuffer (const VstEvents* events, MidiBuffer& dest)
  25514. {
  25515. for (int i = 0; i < events->numEvents; ++i)
  25516. {
  25517. const VstEvent* const e = events->events[i];
  25518. if (e != 0)
  25519. {
  25520. if (e->type == kVstMidiType)
  25521. {
  25522. dest.addEvent ((const JUCE_NAMESPACE::uint8*) ((const VstMidiEvent*) e)->midiData,
  25523. 4, e->deltaFrames);
  25524. }
  25525. else if (e->type == kVstSysExType)
  25526. {
  25527. dest.addEvent ((const JUCE_NAMESPACE::uint8*) ((const VstMidiSysexEvent*) e)->sysexDump,
  25528. (int) ((const VstMidiSysexEvent*) e)->dumpBytes,
  25529. e->deltaFrames);
  25530. }
  25531. }
  25532. }
  25533. }
  25534. void ensureSize (int numEventsNeeded)
  25535. {
  25536. if (numEventsNeeded > numEventsAllocated)
  25537. {
  25538. numEventsNeeded = (numEventsNeeded + 32) & ~31;
  25539. const int size = 20 + sizeof (VstEvent*) * numEventsNeeded;
  25540. if (events == 0)
  25541. events.calloc (size, 1);
  25542. else
  25543. events.realloc (size, 1);
  25544. for (int i = numEventsAllocated; i < numEventsNeeded; ++i)
  25545. {
  25546. VstMidiEvent* const e = (VstMidiEvent*) juce_calloc (jmax ((int) sizeof (VstMidiEvent),
  25547. (int) sizeof (VstMidiSysexEvent)));
  25548. e->type = kVstMidiType;
  25549. e->byteSize = sizeof (VstMidiEvent);
  25550. events->events[i] = (VstEvent*) e;
  25551. }
  25552. numEventsAllocated = numEventsNeeded;
  25553. }
  25554. }
  25555. void freeEvents()
  25556. {
  25557. if (events != 0)
  25558. {
  25559. for (int i = numEventsAllocated; --i >= 0;)
  25560. {
  25561. VstMidiEvent* const e = (VstMidiEvent*) (events->events[i]);
  25562. if (e->type == kVstSysExType)
  25563. juce_free (((VstMidiSysexEvent*) e)->sysexDump);
  25564. juce_free (e);
  25565. }
  25566. events.free();
  25567. numEventsUsed = 0;
  25568. numEventsAllocated = 0;
  25569. }
  25570. }
  25571. HeapBlock <VstEvents> events;
  25572. private:
  25573. int numEventsUsed, numEventsAllocated;
  25574. };
  25575. #endif // __JUCE_VSTMIDIEVENTLIST_JUCEHEADER__
  25576. #endif // __JUCE_VSTMIDIEVENTLIST_JUCEHEADER__
  25577. /*** End of inlined file: juce_VSTMidiEventList.h ***/
  25578. #if ! JUCE_WIN32
  25579. #define _fpreset()
  25580. #define _clearfp()
  25581. #endif
  25582. extern void juce_callAnyTimersSynchronously();
  25583. const int fxbVersionNum = 1;
  25584. struct fxProgram
  25585. {
  25586. long chunkMagic; // 'CcnK'
  25587. long byteSize; // of this chunk, excl. magic + byteSize
  25588. long fxMagic; // 'FxCk'
  25589. long version;
  25590. long fxID; // fx unique id
  25591. long fxVersion;
  25592. long numParams;
  25593. char prgName[28];
  25594. float params[1]; // variable no. of parameters
  25595. };
  25596. struct fxSet
  25597. {
  25598. long chunkMagic; // 'CcnK'
  25599. long byteSize; // of this chunk, excl. magic + byteSize
  25600. long fxMagic; // 'FxBk'
  25601. long version;
  25602. long fxID; // fx unique id
  25603. long fxVersion;
  25604. long numPrograms;
  25605. char future[128];
  25606. fxProgram programs[1]; // variable no. of programs
  25607. };
  25608. struct fxChunkSet
  25609. {
  25610. long chunkMagic; // 'CcnK'
  25611. long byteSize; // of this chunk, excl. magic + byteSize
  25612. long fxMagic; // 'FxCh', 'FPCh', or 'FBCh'
  25613. long version;
  25614. long fxID; // fx unique id
  25615. long fxVersion;
  25616. long numPrograms;
  25617. char future[128];
  25618. long chunkSize;
  25619. char chunk[8]; // variable
  25620. };
  25621. struct fxProgramSet
  25622. {
  25623. long chunkMagic; // 'CcnK'
  25624. long byteSize; // of this chunk, excl. magic + byteSize
  25625. long fxMagic; // 'FxCh', 'FPCh', or 'FBCh'
  25626. long version;
  25627. long fxID; // fx unique id
  25628. long fxVersion;
  25629. long numPrograms;
  25630. char name[28];
  25631. long chunkSize;
  25632. char chunk[8]; // variable
  25633. };
  25634. static long vst_swap (const long x) throw()
  25635. {
  25636. #ifdef JUCE_LITTLE_ENDIAN
  25637. return (long) ByteOrder::swap ((uint32) x);
  25638. #else
  25639. return x;
  25640. #endif
  25641. }
  25642. static float vst_swapFloat (const float x) throw()
  25643. {
  25644. #ifdef JUCE_LITTLE_ENDIAN
  25645. union { uint32 asInt; float asFloat; } n;
  25646. n.asFloat = x;
  25647. n.asInt = ByteOrder::swap (n.asInt);
  25648. return n.asFloat;
  25649. #else
  25650. return x;
  25651. #endif
  25652. }
  25653. typedef AEffect* (*MainCall) (audioMasterCallback);
  25654. static VstIntPtr VSTCALLBACK audioMaster (AEffect* effect, VstInt32 opcode, VstInt32 index, VstIntPtr value, void* ptr, float opt);
  25655. static int shellUIDToCreate = 0;
  25656. static int insideVSTCallback = 0;
  25657. class VSTPluginWindow;
  25658. // Change this to disable logging of various VST activities
  25659. #ifndef VST_LOGGING
  25660. #define VST_LOGGING 1
  25661. #endif
  25662. #if VST_LOGGING
  25663. #define log(a) Logger::writeToLog(a);
  25664. #else
  25665. #define log(a)
  25666. #endif
  25667. #if JUCE_MAC && JUCE_PPC
  25668. static void* NewCFMFromMachO (void* const machofp) throw()
  25669. {
  25670. void* result = juce_malloc (8);
  25671. ((void**) result)[0] = machofp;
  25672. ((void**) result)[1] = result;
  25673. return result;
  25674. }
  25675. #endif
  25676. #if JUCE_LINUX
  25677. extern Display* display;
  25678. extern XContext improbableNumber;
  25679. typedef void (*EventProcPtr) (XEvent* ev);
  25680. static bool xErrorTriggered;
  25681. static int temporaryErrorHandler (Display*, XErrorEvent*)
  25682. {
  25683. xErrorTriggered = true;
  25684. return 0;
  25685. }
  25686. static int getPropertyFromXWindow (Window handle, Atom atom)
  25687. {
  25688. XErrorHandler oldErrorHandler = XSetErrorHandler (temporaryErrorHandler);
  25689. xErrorTriggered = false;
  25690. int userSize;
  25691. unsigned long bytes, userCount;
  25692. unsigned char* data;
  25693. Atom userType;
  25694. XGetWindowProperty (display, handle, atom, 0, 1, false, AnyPropertyType,
  25695. &userType, &userSize, &userCount, &bytes, &data);
  25696. XSetErrorHandler (oldErrorHandler);
  25697. return (userCount == 1 && ! xErrorTriggered) ? *(int*) data
  25698. : 0;
  25699. }
  25700. static Window getChildWindow (Window windowToCheck)
  25701. {
  25702. Window rootWindow, parentWindow;
  25703. Window* childWindows;
  25704. unsigned int numChildren;
  25705. XQueryTree (display,
  25706. windowToCheck,
  25707. &rootWindow,
  25708. &parentWindow,
  25709. &childWindows,
  25710. &numChildren);
  25711. if (numChildren > 0)
  25712. return childWindows [0];
  25713. return 0;
  25714. }
  25715. static void translateJuceToXButtonModifiers (const MouseEvent& e, XEvent& ev) throw()
  25716. {
  25717. if (e.mods.isLeftButtonDown())
  25718. {
  25719. ev.xbutton.button = Button1;
  25720. ev.xbutton.state |= Button1Mask;
  25721. }
  25722. else if (e.mods.isRightButtonDown())
  25723. {
  25724. ev.xbutton.button = Button3;
  25725. ev.xbutton.state |= Button3Mask;
  25726. }
  25727. else if (e.mods.isMiddleButtonDown())
  25728. {
  25729. ev.xbutton.button = Button2;
  25730. ev.xbutton.state |= Button2Mask;
  25731. }
  25732. }
  25733. static void translateJuceToXMotionModifiers (const MouseEvent& e, XEvent& ev) throw()
  25734. {
  25735. if (e.mods.isLeftButtonDown())
  25736. ev.xmotion.state |= Button1Mask;
  25737. else if (e.mods.isRightButtonDown())
  25738. ev.xmotion.state |= Button3Mask;
  25739. else if (e.mods.isMiddleButtonDown())
  25740. ev.xmotion.state |= Button2Mask;
  25741. }
  25742. static void translateJuceToXCrossingModifiers (const MouseEvent& e, XEvent& ev) throw()
  25743. {
  25744. if (e.mods.isLeftButtonDown())
  25745. ev.xcrossing.state |= Button1Mask;
  25746. else if (e.mods.isRightButtonDown())
  25747. ev.xcrossing.state |= Button3Mask;
  25748. else if (e.mods.isMiddleButtonDown())
  25749. ev.xcrossing.state |= Button2Mask;
  25750. }
  25751. static void translateJuceToXMouseWheelModifiers (const MouseEvent& e, const float increment, XEvent& ev) throw()
  25752. {
  25753. if (increment < 0)
  25754. {
  25755. ev.xbutton.button = Button5;
  25756. ev.xbutton.state |= Button5Mask;
  25757. }
  25758. else if (increment > 0)
  25759. {
  25760. ev.xbutton.button = Button4;
  25761. ev.xbutton.state |= Button4Mask;
  25762. }
  25763. }
  25764. #endif
  25765. static VoidArray activeModules;
  25766. class ModuleHandle : public ReferenceCountedObject
  25767. {
  25768. public:
  25769. File file;
  25770. MainCall moduleMain;
  25771. String pluginName;
  25772. static ModuleHandle* findOrCreateModule (const File& file)
  25773. {
  25774. for (int i = activeModules.size(); --i >= 0;)
  25775. {
  25776. ModuleHandle* const module = (ModuleHandle*) activeModules.getUnchecked(i);
  25777. if (module->file == file)
  25778. return module;
  25779. }
  25780. _fpreset(); // (doesn't do any harm)
  25781. ++insideVSTCallback;
  25782. shellUIDToCreate = 0;
  25783. log ("Attempting to load VST: " + file.getFullPathName());
  25784. ScopedPointer <ModuleHandle> m (new ModuleHandle (file));
  25785. if (! m->open())
  25786. m = 0;
  25787. --insideVSTCallback;
  25788. _fpreset(); // (doesn't do any harm)
  25789. return m.release();
  25790. }
  25791. ModuleHandle (const File& file_)
  25792. : file (file_),
  25793. moduleMain (0),
  25794. #if JUCE_WIN32 || JUCE_LINUX
  25795. hModule (0)
  25796. #elif JUCE_MAC
  25797. fragId (0),
  25798. resHandle (0),
  25799. bundleRef (0),
  25800. resFileId (0)
  25801. #endif
  25802. {
  25803. activeModules.add (this);
  25804. #if JUCE_WIN32 || JUCE_LINUX
  25805. fullParentDirectoryPathName = file_.getParentDirectory().getFullPathName();
  25806. #elif JUCE_MAC
  25807. FSRef ref;
  25808. PlatformUtilities::makeFSRefFromPath (&ref, file_.getParentDirectory().getFullPathName());
  25809. FSGetCatalogInfo (&ref, kFSCatInfoNone, 0, 0, &parentDirFSSpec, 0);
  25810. #endif
  25811. }
  25812. ~ModuleHandle()
  25813. {
  25814. activeModules.removeValue (this);
  25815. close();
  25816. }
  25817. juce_UseDebuggingNewOperator
  25818. #if JUCE_WIN32 || JUCE_LINUX
  25819. void* hModule;
  25820. String fullParentDirectoryPathName;
  25821. bool open()
  25822. {
  25823. #if JUCE_WIN32
  25824. static bool timePeriodSet = false;
  25825. if (! timePeriodSet)
  25826. {
  25827. timePeriodSet = true;
  25828. timeBeginPeriod (2);
  25829. }
  25830. #endif
  25831. pluginName = file.getFileNameWithoutExtension();
  25832. hModule = PlatformUtilities::loadDynamicLibrary (file.getFullPathName());
  25833. moduleMain = (MainCall) PlatformUtilities::getProcedureEntryPoint (hModule, "VSTPluginMain");
  25834. if (moduleMain == 0)
  25835. moduleMain = (MainCall) PlatformUtilities::getProcedureEntryPoint (hModule, "main");
  25836. return moduleMain != 0;
  25837. }
  25838. void close()
  25839. {
  25840. _fpreset(); // (doesn't do any harm)
  25841. PlatformUtilities::freeDynamicLibrary (hModule);
  25842. }
  25843. void closeEffect (AEffect* eff)
  25844. {
  25845. eff->dispatcher (eff, effClose, 0, 0, 0, 0);
  25846. }
  25847. #else
  25848. CFragConnectionID fragId;
  25849. Handle resHandle;
  25850. CFBundleRef bundleRef;
  25851. FSSpec parentDirFSSpec;
  25852. short resFileId;
  25853. bool open()
  25854. {
  25855. bool ok = false;
  25856. const String filename (file.getFullPathName());
  25857. if (file.hasFileExtension (T(".vst")))
  25858. {
  25859. const char* const utf8 = filename.toUTF8();
  25860. CFURLRef url = CFURLCreateFromFileSystemRepresentation (0, (const UInt8*) utf8,
  25861. strlen (utf8), file.isDirectory());
  25862. if (url != 0)
  25863. {
  25864. bundleRef = CFBundleCreate (kCFAllocatorDefault, url);
  25865. CFRelease (url);
  25866. if (bundleRef != 0)
  25867. {
  25868. if (CFBundleLoadExecutable (bundleRef))
  25869. {
  25870. moduleMain = (MainCall) CFBundleGetFunctionPointerForName (bundleRef, CFSTR("main_macho"));
  25871. if (moduleMain == 0)
  25872. moduleMain = (MainCall) CFBundleGetFunctionPointerForName (bundleRef, CFSTR("VSTPluginMain"));
  25873. if (moduleMain != 0)
  25874. {
  25875. CFTypeRef name = CFBundleGetValueForInfoDictionaryKey (bundleRef, CFSTR("CFBundleName"));
  25876. if (name != 0)
  25877. {
  25878. if (CFGetTypeID (name) == CFStringGetTypeID())
  25879. {
  25880. char buffer[1024];
  25881. if (CFStringGetCString ((CFStringRef) name, buffer, sizeof (buffer), CFStringGetSystemEncoding()))
  25882. pluginName = buffer;
  25883. }
  25884. }
  25885. if (pluginName.isEmpty())
  25886. pluginName = file.getFileNameWithoutExtension();
  25887. resFileId = CFBundleOpenBundleResourceMap (bundleRef);
  25888. ok = true;
  25889. }
  25890. }
  25891. if (! ok)
  25892. {
  25893. CFBundleUnloadExecutable (bundleRef);
  25894. CFRelease (bundleRef);
  25895. bundleRef = 0;
  25896. }
  25897. }
  25898. }
  25899. }
  25900. #if JUCE_PPC
  25901. else
  25902. {
  25903. FSRef fn;
  25904. if (FSPathMakeRef ((UInt8*) (const char*) filename, &fn, 0) == noErr)
  25905. {
  25906. resFileId = FSOpenResFile (&fn, fsRdPerm);
  25907. if (resFileId != -1)
  25908. {
  25909. const int numEffs = Count1Resources ('aEff');
  25910. for (int i = 0; i < numEffs; ++i)
  25911. {
  25912. resHandle = Get1IndResource ('aEff', i + 1);
  25913. if (resHandle != 0)
  25914. {
  25915. OSType type;
  25916. Str255 name;
  25917. SInt16 id;
  25918. GetResInfo (resHandle, &id, &type, name);
  25919. pluginName = String ((const char*) name + 1, name[0]);
  25920. DetachResource (resHandle);
  25921. HLock (resHandle);
  25922. Ptr ptr;
  25923. Str255 errorText;
  25924. OSErr err = GetMemFragment (*resHandle, GetHandleSize (resHandle),
  25925. name, kPrivateCFragCopy,
  25926. &fragId, &ptr, errorText);
  25927. if (err == noErr)
  25928. {
  25929. moduleMain = (MainCall) newMachOFromCFM (ptr);
  25930. ok = true;
  25931. }
  25932. else
  25933. {
  25934. HUnlock (resHandle);
  25935. }
  25936. break;
  25937. }
  25938. }
  25939. if (! ok)
  25940. CloseResFile (resFileId);
  25941. }
  25942. }
  25943. }
  25944. #endif
  25945. return ok;
  25946. }
  25947. void close()
  25948. {
  25949. #if JUCE_PPC
  25950. if (fragId != 0)
  25951. {
  25952. if (moduleMain != 0)
  25953. disposeMachOFromCFM ((void*) moduleMain);
  25954. CloseConnection (&fragId);
  25955. HUnlock (resHandle);
  25956. if (resFileId != 0)
  25957. CloseResFile (resFileId);
  25958. }
  25959. else
  25960. #endif
  25961. if (bundleRef != 0)
  25962. {
  25963. CFBundleCloseBundleResourceMap (bundleRef, resFileId);
  25964. if (CFGetRetainCount (bundleRef) == 1)
  25965. CFBundleUnloadExecutable (bundleRef);
  25966. if (CFGetRetainCount (bundleRef) > 0)
  25967. CFRelease (bundleRef);
  25968. }
  25969. }
  25970. void closeEffect (AEffect* eff)
  25971. {
  25972. #if JUCE_PPC
  25973. if (fragId != 0)
  25974. {
  25975. VoidArray thingsToDelete;
  25976. thingsToDelete.add ((void*) eff->dispatcher);
  25977. thingsToDelete.add ((void*) eff->process);
  25978. thingsToDelete.add ((void*) eff->setParameter);
  25979. thingsToDelete.add ((void*) eff->getParameter);
  25980. thingsToDelete.add ((void*) eff->processReplacing);
  25981. eff->dispatcher (eff, effClose, 0, 0, 0, 0);
  25982. for (int i = thingsToDelete.size(); --i >= 0;)
  25983. disposeMachOFromCFM (thingsToDelete[i]);
  25984. }
  25985. else
  25986. #endif
  25987. {
  25988. eff->dispatcher (eff, effClose, 0, 0, 0, 0);
  25989. }
  25990. }
  25991. #if JUCE_PPC
  25992. static void* newMachOFromCFM (void* cfmfp)
  25993. {
  25994. if (cfmfp == 0)
  25995. return 0;
  25996. UInt32* const mfp = (UInt32*) juce_malloc (sizeof (UInt32) * 6);
  25997. mfp[0] = 0x3d800000 | ((UInt32) cfmfp >> 16);
  25998. mfp[1] = 0x618c0000 | ((UInt32) cfmfp & 0xffff);
  25999. mfp[2] = 0x800c0000;
  26000. mfp[3] = 0x804c0004;
  26001. mfp[4] = 0x7c0903a6;
  26002. mfp[5] = 0x4e800420;
  26003. MakeDataExecutable (mfp, sizeof (UInt32) * 6);
  26004. return mfp;
  26005. }
  26006. static void disposeMachOFromCFM (void* ptr)
  26007. {
  26008. juce_free (ptr);
  26009. }
  26010. void coerceAEffectFunctionCalls (AEffect* eff)
  26011. {
  26012. if (fragId != 0)
  26013. {
  26014. eff->dispatcher = (AEffectDispatcherProc) newMachOFromCFM ((void*) eff->dispatcher);
  26015. eff->process = (AEffectProcessProc) newMachOFromCFM ((void*) eff->process);
  26016. eff->setParameter = (AEffectSetParameterProc) newMachOFromCFM ((void*) eff->setParameter);
  26017. eff->getParameter = (AEffectGetParameterProc) newMachOFromCFM ((void*) eff->getParameter);
  26018. eff->processReplacing = (AEffectProcessProc) newMachOFromCFM ((void*) eff->processReplacing);
  26019. }
  26020. }
  26021. #endif
  26022. #endif
  26023. };
  26024. class VSTPluginInstance : public AudioPluginInstance,
  26025. private Timer,
  26026. private AsyncUpdater
  26027. {
  26028. public:
  26029. ~VSTPluginInstance();
  26030. // AudioPluginInstance methods:
  26031. void fillInPluginDescription (PluginDescription& desc) const
  26032. {
  26033. desc.name = name;
  26034. desc.fileOrIdentifier = module->file.getFullPathName();
  26035. desc.uid = getUID();
  26036. desc.lastFileModTime = module->file.getLastModificationTime();
  26037. desc.pluginFormatName = "VST";
  26038. desc.category = getCategory();
  26039. {
  26040. char buffer [kVstMaxVendorStrLen + 8];
  26041. zerostruct (buffer);
  26042. dispatch (effGetVendorString, 0, 0, buffer, 0);
  26043. desc.manufacturerName = buffer;
  26044. }
  26045. desc.version = getVersion();
  26046. desc.numInputChannels = getNumInputChannels();
  26047. desc.numOutputChannels = getNumOutputChannels();
  26048. desc.isInstrument = (effect != 0 && (effect->flags & effFlagsIsSynth) != 0);
  26049. }
  26050. const String getName() const { return name; }
  26051. int getUID() const throw();
  26052. bool acceptsMidi() const { return wantsMidiMessages; }
  26053. bool producesMidi() const { return dispatch (effCanDo, 0, 0, (void*) "sendVstMidiEvent", 0) > 0; }
  26054. // AudioProcessor methods:
  26055. void prepareToPlay (double sampleRate, int estimatedSamplesPerBlock);
  26056. void releaseResources();
  26057. void processBlock (AudioSampleBuffer& buffer,
  26058. MidiBuffer& midiMessages);
  26059. AudioProcessorEditor* createEditor();
  26060. const String getInputChannelName (const int index) const;
  26061. bool isInputChannelStereoPair (int index) const;
  26062. const String getOutputChannelName (const int index) const;
  26063. bool isOutputChannelStereoPair (int index) const;
  26064. int getNumParameters() { return effect != 0 ? effect->numParams : 0; }
  26065. float getParameter (int index);
  26066. void setParameter (int index, float newValue);
  26067. const String getParameterName (int index);
  26068. const String getParameterText (int index);
  26069. bool isParameterAutomatable (int index) const;
  26070. int getNumPrograms() { return effect != 0 ? effect->numPrograms : 0; }
  26071. int getCurrentProgram() { return dispatch (effGetProgram, 0, 0, 0, 0); }
  26072. void setCurrentProgram (int index);
  26073. const String getProgramName (int index);
  26074. void changeProgramName (int index, const String& newName);
  26075. void getStateInformation (MemoryBlock& destData);
  26076. void getCurrentProgramStateInformation (MemoryBlock& destData);
  26077. void setStateInformation (const void* data, int sizeInBytes);
  26078. void setCurrentProgramStateInformation (const void* data, int sizeInBytes);
  26079. void timerCallback();
  26080. void handleAsyncUpdate();
  26081. VstIntPtr handleCallback (VstInt32 opcode, VstInt32 index, VstInt32 value, void *ptr, float opt);
  26082. juce_UseDebuggingNewOperator
  26083. private:
  26084. friend class VSTPluginWindow;
  26085. friend class VSTPluginFormat;
  26086. AEffect* effect;
  26087. String name;
  26088. CriticalSection lock;
  26089. bool wantsMidiMessages, initialised, isPowerOn;
  26090. mutable StringArray programNames;
  26091. AudioSampleBuffer tempBuffer;
  26092. CriticalSection midiInLock;
  26093. MidiBuffer incomingMidi;
  26094. VSTMidiEventList midiEventsToSend;
  26095. VstTimeInfo vstHostTime;
  26096. HeapBlock <float*> channels;
  26097. ReferenceCountedObjectPtr <ModuleHandle> module;
  26098. int dispatch (const int opcode, const int index, const int value, void* const ptr, float opt) const;
  26099. bool restoreProgramSettings (const fxProgram* const prog);
  26100. const String getCurrentProgramName();
  26101. void setParamsInProgramBlock (fxProgram* const prog) throw();
  26102. void updateStoredProgramNames();
  26103. void initialise();
  26104. void handleMidiFromPlugin (const VstEvents* const events);
  26105. void createTempParameterStore (MemoryBlock& dest);
  26106. void restoreFromTempParameterStore (const MemoryBlock& mb);
  26107. const String getParameterLabel (int index) const;
  26108. bool usesChunks() const throw() { return effect != 0 && (effect->flags & effFlagsProgramChunks) != 0; }
  26109. void getChunkData (MemoryBlock& mb, bool isPreset, int maxSizeMB) const;
  26110. void setChunkData (const char* data, int size, bool isPreset);
  26111. bool loadFromFXBFile (const void* data, int numBytes);
  26112. bool saveToFXBFile (MemoryBlock& dest, bool isFXB, int maxSizeMB);
  26113. int getVersionNumber() const throw() { return effect != 0 ? effect->version : 0; }
  26114. const String getVersion() const throw();
  26115. const String getCategory() const throw();
  26116. bool hasEditor() const throw() { return effect != 0 && (effect->flags & effFlagsHasEditor) != 0; }
  26117. void setPower (const bool on);
  26118. VSTPluginInstance (const ReferenceCountedObjectPtr <ModuleHandle>& module);
  26119. };
  26120. VSTPluginInstance::VSTPluginInstance (const ReferenceCountedObjectPtr <ModuleHandle>& module_)
  26121. : effect (0),
  26122. wantsMidiMessages (false),
  26123. initialised (false),
  26124. isPowerOn (false),
  26125. tempBuffer (1, 1),
  26126. module (module_)
  26127. {
  26128. try
  26129. {
  26130. _fpreset();
  26131. ++insideVSTCallback;
  26132. name = module->pluginName;
  26133. log (T("Creating VST instance: ") + name);
  26134. #if JUCE_MAC
  26135. if (module->resFileId != 0)
  26136. UseResFile (module->resFileId);
  26137. #if JUCE_PPC
  26138. if (module->fragId != 0)
  26139. {
  26140. static void* audioMasterCoerced = 0;
  26141. if (audioMasterCoerced == 0)
  26142. audioMasterCoerced = NewCFMFromMachO ((void*) &audioMaster);
  26143. effect = module->moduleMain ((audioMasterCallback) audioMasterCoerced);
  26144. }
  26145. else
  26146. #endif
  26147. #endif
  26148. {
  26149. effect = module->moduleMain (&audioMaster);
  26150. }
  26151. --insideVSTCallback;
  26152. if (effect != 0 && effect->magic == kEffectMagic)
  26153. {
  26154. #if JUCE_PPC
  26155. module->coerceAEffectFunctionCalls (effect);
  26156. #endif
  26157. jassert (effect->resvd2 == 0);
  26158. jassert (effect->object != 0);
  26159. _fpreset(); // some dodgy plugs fuck around with this
  26160. }
  26161. else
  26162. {
  26163. effect = 0;
  26164. }
  26165. }
  26166. catch (...)
  26167. {
  26168. --insideVSTCallback;
  26169. }
  26170. }
  26171. VSTPluginInstance::~VSTPluginInstance()
  26172. {
  26173. {
  26174. const ScopedLock sl (lock);
  26175. jassert (insideVSTCallback == 0);
  26176. if (effect != 0 && effect->magic == kEffectMagic)
  26177. {
  26178. try
  26179. {
  26180. #if JUCE_MAC
  26181. if (module->resFileId != 0)
  26182. UseResFile (module->resFileId);
  26183. #endif
  26184. // Must delete any editors before deleting the plugin instance!
  26185. jassert (getActiveEditor() == 0);
  26186. _fpreset(); // some dodgy plugs fuck around with this
  26187. module->closeEffect (effect);
  26188. }
  26189. catch (...)
  26190. {}
  26191. }
  26192. module = 0;
  26193. effect = 0;
  26194. }
  26195. }
  26196. void VSTPluginInstance::initialise()
  26197. {
  26198. if (initialised || effect == 0)
  26199. return;
  26200. log (T("Initialising VST: ") + module->pluginName);
  26201. initialised = true;
  26202. dispatch (effIdentify, 0, 0, 0, 0);
  26203. // this code would ask the plugin for its name, but so few plugins
  26204. // actually bother implementing this correctly, that it's better to
  26205. // just ignore it and use the file name instead.
  26206. if (getSampleRate() > 0)
  26207. dispatch (effSetSampleRate, 0, 0, 0, (float) getSampleRate());
  26208. if (getBlockSize() > 0)
  26209. dispatch (effSetBlockSize, 0, jmax (32, getBlockSize()), 0, 0);
  26210. dispatch (effOpen, 0, 0, 0, 0);
  26211. setPlayConfigDetails (effect->numInputs, effect->numOutputs,
  26212. getSampleRate(), getBlockSize());
  26213. if (getNumPrograms() > 1)
  26214. setCurrentProgram (0);
  26215. else
  26216. dispatch (effSetProgram, 0, 0, 0, 0);
  26217. int i;
  26218. for (i = effect->numInputs; --i >= 0;)
  26219. dispatch (effConnectInput, i, 1, 0, 0);
  26220. for (i = effect->numOutputs; --i >= 0;)
  26221. dispatch (effConnectOutput, i, 1, 0, 0);
  26222. updateStoredProgramNames();
  26223. wantsMidiMessages = dispatch (effCanDo, 0, 0, (void*) "receiveVstMidiEvent", 0) > 0;
  26224. setLatencySamples (effect->initialDelay);
  26225. }
  26226. void VSTPluginInstance::prepareToPlay (double sampleRate_,
  26227. int samplesPerBlockExpected)
  26228. {
  26229. setPlayConfigDetails (effect->numInputs, effect->numOutputs,
  26230. sampleRate_, samplesPerBlockExpected);
  26231. setLatencySamples (effect->initialDelay);
  26232. channels.calloc (jmax (16, getNumOutputChannels(), getNumInputChannels()) + 2);
  26233. vstHostTime.tempo = 120.0;
  26234. vstHostTime.timeSigNumerator = 4;
  26235. vstHostTime.timeSigDenominator = 4;
  26236. vstHostTime.sampleRate = sampleRate_;
  26237. vstHostTime.samplePos = 0;
  26238. vstHostTime.flags = kVstNanosValid; /*| kVstTransportPlaying | kVstTempoValid | kVstTimeSigValid*/;
  26239. initialise();
  26240. if (initialised)
  26241. {
  26242. wantsMidiMessages = wantsMidiMessages
  26243. || (dispatch (effCanDo, 0, 0, (void*) "receiveVstMidiEvent", 0) > 0);
  26244. if (wantsMidiMessages)
  26245. midiEventsToSend.ensureSize (256);
  26246. else
  26247. midiEventsToSend.freeEvents();
  26248. incomingMidi.clear();
  26249. dispatch (effSetSampleRate, 0, 0, 0, (float) sampleRate_);
  26250. dispatch (effSetBlockSize, 0, jmax (16, samplesPerBlockExpected), 0, 0);
  26251. tempBuffer.setSize (jmax (1, effect->numOutputs), samplesPerBlockExpected);
  26252. if (! isPowerOn)
  26253. setPower (true);
  26254. // dodgy hack to force some plugins to initialise the sample rate..
  26255. if ((! hasEditor()) && getNumParameters() > 0)
  26256. {
  26257. const float old = getParameter (0);
  26258. setParameter (0, (old < 0.5f) ? 1.0f : 0.0f);
  26259. setParameter (0, old);
  26260. }
  26261. dispatch (effStartProcess, 0, 0, 0, 0);
  26262. }
  26263. }
  26264. void VSTPluginInstance::releaseResources()
  26265. {
  26266. if (initialised)
  26267. {
  26268. dispatch (effStopProcess, 0, 0, 0, 0);
  26269. setPower (false);
  26270. }
  26271. tempBuffer.setSize (1, 1);
  26272. incomingMidi.clear();
  26273. midiEventsToSend.freeEvents();
  26274. channels.free();
  26275. }
  26276. void VSTPluginInstance::processBlock (AudioSampleBuffer& buffer,
  26277. MidiBuffer& midiMessages)
  26278. {
  26279. const int numSamples = buffer.getNumSamples();
  26280. if (initialised)
  26281. {
  26282. AudioPlayHead* playHead = getPlayHead();
  26283. if (playHead != 0)
  26284. {
  26285. AudioPlayHead::CurrentPositionInfo position;
  26286. playHead->getCurrentPosition (position);
  26287. vstHostTime.tempo = position.bpm;
  26288. vstHostTime.timeSigNumerator = position.timeSigNumerator;
  26289. vstHostTime.timeSigDenominator = position.timeSigDenominator;
  26290. vstHostTime.ppqPos = position.ppqPosition;
  26291. vstHostTime.barStartPos = position.ppqPositionOfLastBarStart;
  26292. vstHostTime.flags |= kVstTempoValid | kVstTimeSigValid | kVstPpqPosValid | kVstBarsValid;
  26293. if (position.isPlaying)
  26294. vstHostTime.flags |= kVstTransportPlaying;
  26295. else
  26296. vstHostTime.flags &= ~kVstTransportPlaying;
  26297. }
  26298. #if JUCE_WIN32
  26299. vstHostTime.nanoSeconds = timeGetTime() * 1000000.0;
  26300. #elif JUCE_LINUX
  26301. timeval micro;
  26302. gettimeofday (&micro, 0);
  26303. vstHostTime.nanoSeconds = micro.tv_usec * 1000.0;
  26304. #elif JUCE_MAC
  26305. UnsignedWide micro;
  26306. Microseconds (&micro);
  26307. vstHostTime.nanoSeconds = micro.lo * 1000.0;
  26308. #endif
  26309. if (wantsMidiMessages)
  26310. {
  26311. midiEventsToSend.clear();
  26312. midiEventsToSend.ensureSize (1);
  26313. MidiBuffer::Iterator iter (midiMessages);
  26314. const uint8* midiData;
  26315. int numBytesOfMidiData, samplePosition;
  26316. while (iter.getNextEvent (midiData, numBytesOfMidiData, samplePosition))
  26317. {
  26318. midiEventsToSend.addEvent (midiData, numBytesOfMidiData,
  26319. jlimit (0, numSamples - 1, samplePosition));
  26320. }
  26321. try
  26322. {
  26323. effect->dispatcher (effect, effProcessEvents, 0, 0, midiEventsToSend.events, 0);
  26324. }
  26325. catch (...)
  26326. {}
  26327. }
  26328. int i;
  26329. const int maxChans = jmax (effect->numInputs, effect->numOutputs);
  26330. for (i = 0; i < maxChans; ++i)
  26331. channels[i] = buffer.getSampleData (i);
  26332. channels [maxChans] = 0;
  26333. _clearfp();
  26334. if ((effect->flags & effFlagsCanReplacing) != 0)
  26335. {
  26336. try
  26337. {
  26338. effect->processReplacing (effect, channels, channels, numSamples);
  26339. }
  26340. catch (...)
  26341. {}
  26342. }
  26343. else
  26344. {
  26345. tempBuffer.setSize (effect->numOutputs, numSamples);
  26346. tempBuffer.clear();
  26347. float* outs [64];
  26348. for (i = effect->numOutputs; --i >= 0;)
  26349. outs[i] = tempBuffer.getSampleData (i);
  26350. outs [effect->numOutputs] = 0;
  26351. try
  26352. {
  26353. effect->process (effect, channels, outs, numSamples);
  26354. }
  26355. catch (...)
  26356. {}
  26357. for (i = effect->numOutputs; --i >= 0;)
  26358. buffer.copyFrom (i, 0, outs[i], numSamples);
  26359. }
  26360. }
  26361. else
  26362. {
  26363. // Not initialised, so just bypass..
  26364. for (int i = getNumInputChannels(); i < getNumOutputChannels(); ++i)
  26365. buffer.clear (i, 0, buffer.getNumSamples());
  26366. }
  26367. {
  26368. // copy any incoming midi..
  26369. const ScopedLock sl (midiInLock);
  26370. midiMessages = incomingMidi;
  26371. incomingMidi.clear();
  26372. }
  26373. }
  26374. void VSTPluginInstance::handleMidiFromPlugin (const VstEvents* const events)
  26375. {
  26376. if (events != 0)
  26377. {
  26378. const ScopedLock sl (midiInLock);
  26379. VSTMidiEventList::addEventsToMidiBuffer (events, incomingMidi);
  26380. }
  26381. }
  26382. static Array <VSTPluginWindow*> activeVSTWindows;
  26383. class VSTPluginWindow : public AudioProcessorEditor,
  26384. #if ! JUCE_MAC
  26385. public ComponentMovementWatcher,
  26386. #endif
  26387. public Timer
  26388. {
  26389. public:
  26390. VSTPluginWindow (VSTPluginInstance& plugin_)
  26391. : AudioProcessorEditor (&plugin_),
  26392. #if ! JUCE_MAC
  26393. ComponentMovementWatcher (this),
  26394. #endif
  26395. plugin (plugin_),
  26396. isOpen (false),
  26397. wasShowing (false),
  26398. pluginRefusesToResize (false),
  26399. pluginWantsKeys (false),
  26400. alreadyInside (false),
  26401. recursiveResize (false)
  26402. {
  26403. #if JUCE_WIN32
  26404. sizeCheckCount = 0;
  26405. pluginHWND = 0;
  26406. #elif JUCE_LINUX
  26407. pluginWindow = None;
  26408. pluginProc = None;
  26409. #else
  26410. addAndMakeVisible (innerWrapper = new InnerWrapperComponent (this));
  26411. #endif
  26412. activeVSTWindows.add (this);
  26413. setSize (1, 1);
  26414. setOpaque (true);
  26415. setVisible (true);
  26416. }
  26417. ~VSTPluginWindow()
  26418. {
  26419. #if JUCE_MAC
  26420. innerWrapper = 0;
  26421. #else
  26422. closePluginWindow();
  26423. #endif
  26424. activeVSTWindows.removeValue (this);
  26425. plugin.editorBeingDeleted (this);
  26426. }
  26427. #if ! JUCE_MAC
  26428. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  26429. {
  26430. if (recursiveResize)
  26431. return;
  26432. Component* const topComp = getTopLevelComponent();
  26433. if (topComp->getPeer() != 0)
  26434. {
  26435. int x = 0, y = 0;
  26436. relativePositionToOtherComponent (topComp, x, y);
  26437. recursiveResize = true;
  26438. #if JUCE_WIN32
  26439. if (pluginHWND != 0)
  26440. MoveWindow (pluginHWND, x, y, getWidth(), getHeight(), TRUE);
  26441. #elif JUCE_LINUX
  26442. if (pluginWindow != 0)
  26443. {
  26444. XResizeWindow (display, pluginWindow, getWidth(), getHeight());
  26445. XMoveWindow (display, pluginWindow, x, y);
  26446. XMapRaised (display, pluginWindow);
  26447. }
  26448. #endif
  26449. recursiveResize = false;
  26450. }
  26451. }
  26452. void componentVisibilityChanged (Component&)
  26453. {
  26454. const bool isShowingNow = isShowing();
  26455. if (wasShowing != isShowingNow)
  26456. {
  26457. wasShowing = isShowingNow;
  26458. if (isShowingNow)
  26459. openPluginWindow();
  26460. else
  26461. closePluginWindow();
  26462. }
  26463. componentMovedOrResized (true, true);
  26464. }
  26465. void componentPeerChanged()
  26466. {
  26467. closePluginWindow();
  26468. openPluginWindow();
  26469. }
  26470. #endif
  26471. bool keyStateChanged (const bool)
  26472. {
  26473. return pluginWantsKeys;
  26474. }
  26475. bool keyPressed (const KeyPress&)
  26476. {
  26477. return pluginWantsKeys;
  26478. }
  26479. #if JUCE_MAC
  26480. void paint (Graphics& g)
  26481. {
  26482. g.fillAll (Colours::black);
  26483. }
  26484. #else
  26485. void paint (Graphics& g)
  26486. {
  26487. if (isOpen)
  26488. {
  26489. ComponentPeer* const peer = getPeer();
  26490. if (peer != 0)
  26491. {
  26492. peer->addMaskedRegion (getScreenX() - peer->getScreenX(),
  26493. getScreenY() - peer->getScreenY(),
  26494. getWidth(), getHeight());
  26495. #if JUCE_LINUX
  26496. if (pluginWindow != 0)
  26497. {
  26498. const Rectangle<int> clip (g.getClipBounds());
  26499. XEvent ev;
  26500. zerostruct (ev);
  26501. ev.xexpose.type = Expose;
  26502. ev.xexpose.display = display;
  26503. ev.xexpose.window = pluginWindow;
  26504. ev.xexpose.x = clip.getX();
  26505. ev.xexpose.y = clip.getY();
  26506. ev.xexpose.width = clip.getWidth();
  26507. ev.xexpose.height = clip.getHeight();
  26508. sendEventToChild (&ev);
  26509. }
  26510. #endif
  26511. }
  26512. }
  26513. else
  26514. {
  26515. g.fillAll (Colours::black);
  26516. }
  26517. }
  26518. #endif
  26519. void timerCallback()
  26520. {
  26521. #if JUCE_WIN32
  26522. if (--sizeCheckCount <= 0)
  26523. {
  26524. sizeCheckCount = 10;
  26525. checkPluginWindowSize();
  26526. }
  26527. #endif
  26528. try
  26529. {
  26530. static bool reentrant = false;
  26531. if (! reentrant)
  26532. {
  26533. reentrant = true;
  26534. plugin.dispatch (effEditIdle, 0, 0, 0, 0);
  26535. reentrant = false;
  26536. }
  26537. }
  26538. catch (...)
  26539. {}
  26540. }
  26541. void mouseDown (const MouseEvent& e)
  26542. {
  26543. #if JUCE_LINUX
  26544. if (pluginWindow == 0)
  26545. return;
  26546. toFront (true);
  26547. XEvent ev;
  26548. zerostruct (ev);
  26549. ev.xbutton.display = display;
  26550. ev.xbutton.type = ButtonPress;
  26551. ev.xbutton.window = pluginWindow;
  26552. ev.xbutton.root = RootWindow (display, DefaultScreen (display));
  26553. ev.xbutton.time = CurrentTime;
  26554. ev.xbutton.x = e.x;
  26555. ev.xbutton.y = e.y;
  26556. ev.xbutton.x_root = e.getScreenX();
  26557. ev.xbutton.y_root = e.getScreenY();
  26558. translateJuceToXButtonModifiers (e, ev);
  26559. sendEventToChild (&ev);
  26560. #elif JUCE_WIN32
  26561. (void) e;
  26562. toFront (true);
  26563. #endif
  26564. }
  26565. void broughtToFront()
  26566. {
  26567. activeVSTWindows.removeValue (this);
  26568. activeVSTWindows.add (this);
  26569. #if JUCE_MAC
  26570. dispatch (effEditTop, 0, 0, 0, 0);
  26571. #endif
  26572. }
  26573. juce_UseDebuggingNewOperator
  26574. private:
  26575. VSTPluginInstance& plugin;
  26576. bool isOpen, wasShowing, recursiveResize;
  26577. bool pluginWantsKeys, pluginRefusesToResize, alreadyInside;
  26578. #if JUCE_WIN32
  26579. HWND pluginHWND;
  26580. void* originalWndProc;
  26581. int sizeCheckCount;
  26582. #elif JUCE_LINUX
  26583. Window pluginWindow;
  26584. EventProcPtr pluginProc;
  26585. #endif
  26586. #if JUCE_MAC
  26587. void openPluginWindow (WindowRef parentWindow)
  26588. {
  26589. if (isOpen || parentWindow == 0)
  26590. return;
  26591. isOpen = true;
  26592. ERect* rect = 0;
  26593. dispatch (effEditGetRect, 0, 0, &rect, 0);
  26594. dispatch (effEditOpen, 0, 0, parentWindow, 0);
  26595. // do this before and after like in the steinberg example
  26596. dispatch (effEditGetRect, 0, 0, &rect, 0);
  26597. dispatch (effGetProgram, 0, 0, 0, 0); // also in steinberg code
  26598. // Install keyboard hooks
  26599. pluginWantsKeys = (dispatch (effKeysRequired, 0, 0, 0, 0) == 0);
  26600. // double-check it's not too tiny
  26601. int w = 250, h = 150;
  26602. if (rect != 0)
  26603. {
  26604. w = rect->right - rect->left;
  26605. h = rect->bottom - rect->top;
  26606. if (w == 0 || h == 0)
  26607. {
  26608. w = 250;
  26609. h = 150;
  26610. }
  26611. }
  26612. w = jmax (w, 32);
  26613. h = jmax (h, 32);
  26614. setSize (w, h);
  26615. startTimer (18 + JUCE_NAMESPACE::Random::getSystemRandom().nextInt (5));
  26616. repaint();
  26617. }
  26618. #else
  26619. void openPluginWindow()
  26620. {
  26621. if (isOpen || getWindowHandle() == 0)
  26622. return;
  26623. log (T("Opening VST UI: ") + plugin.name);
  26624. isOpen = true;
  26625. ERect* rect = 0;
  26626. dispatch (effEditGetRect, 0, 0, &rect, 0);
  26627. dispatch (effEditOpen, 0, 0, getWindowHandle(), 0);
  26628. // do this before and after like in the steinberg example
  26629. dispatch (effEditGetRect, 0, 0, &rect, 0);
  26630. dispatch (effGetProgram, 0, 0, 0, 0); // also in steinberg code
  26631. // Install keyboard hooks
  26632. pluginWantsKeys = (dispatch (effKeysRequired, 0, 0, 0, 0) == 0);
  26633. #if JUCE_WIN32
  26634. originalWndProc = 0;
  26635. pluginHWND = GetWindow ((HWND) getWindowHandle(), GW_CHILD);
  26636. if (pluginHWND == 0)
  26637. {
  26638. isOpen = false;
  26639. setSize (300, 150);
  26640. return;
  26641. }
  26642. #pragma warning (push)
  26643. #pragma warning (disable: 4244)
  26644. originalWndProc = (void*) GetWindowLongPtr (pluginHWND, GWL_WNDPROC);
  26645. if (! pluginWantsKeys)
  26646. SetWindowLongPtr (pluginHWND, GWL_WNDPROC, (LONG_PTR) vstHookWndProc);
  26647. #pragma warning (pop)
  26648. int w, h;
  26649. RECT r;
  26650. GetWindowRect (pluginHWND, &r);
  26651. w = r.right - r.left;
  26652. h = r.bottom - r.top;
  26653. if (rect != 0)
  26654. {
  26655. const int rw = rect->right - rect->left;
  26656. const int rh = rect->bottom - rect->top;
  26657. if ((rw > 50 && rh > 50 && rw < 2000 && rh < 2000 && rw != w && rh != h)
  26658. || ((w == 0 && rw > 0) || (h == 0 && rh > 0)))
  26659. {
  26660. // very dodgy logic to decide which size is right.
  26661. if (abs (rw - w) > 350 || abs (rh - h) > 350)
  26662. {
  26663. SetWindowPos (pluginHWND, 0,
  26664. 0, 0, rw, rh,
  26665. SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
  26666. GetWindowRect (pluginHWND, &r);
  26667. w = r.right - r.left;
  26668. h = r.bottom - r.top;
  26669. pluginRefusesToResize = (w != rw) || (h != rh);
  26670. w = rw;
  26671. h = rh;
  26672. }
  26673. }
  26674. }
  26675. #elif JUCE_LINUX
  26676. pluginWindow = getChildWindow ((Window) getWindowHandle());
  26677. if (pluginWindow != 0)
  26678. pluginProc = (EventProcPtr) getPropertyFromXWindow (pluginWindow,
  26679. XInternAtom (display, "_XEventProc", False));
  26680. int w = 250, h = 150;
  26681. if (rect != 0)
  26682. {
  26683. w = rect->right - rect->left;
  26684. h = rect->bottom - rect->top;
  26685. if (w == 0 || h == 0)
  26686. {
  26687. w = 250;
  26688. h = 150;
  26689. }
  26690. }
  26691. if (pluginWindow != 0)
  26692. XMapRaised (display, pluginWindow);
  26693. #endif
  26694. // double-check it's not too tiny
  26695. w = jmax (w, 32);
  26696. h = jmax (h, 32);
  26697. setSize (w, h);
  26698. #if JUCE_WIN32
  26699. checkPluginWindowSize();
  26700. #endif
  26701. startTimer (18 + JUCE_NAMESPACE::Random::getSystemRandom().nextInt (5));
  26702. repaint();
  26703. }
  26704. #endif
  26705. #if ! JUCE_MAC
  26706. void closePluginWindow()
  26707. {
  26708. if (isOpen)
  26709. {
  26710. log (T("Closing VST UI: ") + plugin.getName());
  26711. isOpen = false;
  26712. dispatch (effEditClose, 0, 0, 0, 0);
  26713. #if JUCE_WIN32
  26714. #pragma warning (push)
  26715. #pragma warning (disable: 4244)
  26716. if (pluginHWND != 0 && IsWindow (pluginHWND))
  26717. SetWindowLongPtr (pluginHWND, GWL_WNDPROC, (LONG_PTR) originalWndProc);
  26718. #pragma warning (pop)
  26719. stopTimer();
  26720. if (pluginHWND != 0 && IsWindow (pluginHWND))
  26721. DestroyWindow (pluginHWND);
  26722. pluginHWND = 0;
  26723. #elif JUCE_LINUX
  26724. stopTimer();
  26725. pluginWindow = 0;
  26726. pluginProc = 0;
  26727. #endif
  26728. }
  26729. }
  26730. #endif
  26731. int dispatch (const int opcode, const int index, const int value, void* const ptr, float opt)
  26732. {
  26733. return plugin.dispatch (opcode, index, value, ptr, opt);
  26734. }
  26735. #if JUCE_WIN32
  26736. void checkPluginWindowSize() throw()
  26737. {
  26738. RECT r;
  26739. GetWindowRect (pluginHWND, &r);
  26740. const int w = r.right - r.left;
  26741. const int h = r.bottom - r.top;
  26742. if (isShowing() && w > 0 && h > 0
  26743. && (w != getWidth() || h != getHeight())
  26744. && ! pluginRefusesToResize)
  26745. {
  26746. setSize (w, h);
  26747. sizeCheckCount = 0;
  26748. }
  26749. }
  26750. // hooks to get keyboard events from VST windows..
  26751. static LRESULT CALLBACK vstHookWndProc (HWND hW, UINT message, WPARAM wParam, LPARAM lParam)
  26752. {
  26753. for (int i = activeVSTWindows.size(); --i >= 0;)
  26754. {
  26755. const VSTPluginWindow* const w = (const VSTPluginWindow*) activeVSTWindows.getUnchecked (i);
  26756. if (w->pluginHWND == hW)
  26757. {
  26758. if (message == WM_CHAR
  26759. || message == WM_KEYDOWN
  26760. || message == WM_SYSKEYDOWN
  26761. || message == WM_KEYUP
  26762. || message == WM_SYSKEYUP
  26763. || message == WM_APPCOMMAND)
  26764. {
  26765. SendMessage ((HWND) w->getTopLevelComponent()->getWindowHandle(),
  26766. message, wParam, lParam);
  26767. }
  26768. return CallWindowProc ((WNDPROC) (w->originalWndProc),
  26769. (HWND) w->pluginHWND,
  26770. message,
  26771. wParam,
  26772. lParam);
  26773. }
  26774. }
  26775. return DefWindowProc (hW, message, wParam, lParam);
  26776. }
  26777. #endif
  26778. #if JUCE_LINUX
  26779. // overload mouse/keyboard events to forward them to the plugin's inner window..
  26780. void sendEventToChild (XEvent* event)
  26781. {
  26782. if (pluginProc != 0)
  26783. {
  26784. // if the plugin publishes an event procedure, pass the event directly..
  26785. pluginProc (event);
  26786. }
  26787. else if (pluginWindow != 0)
  26788. {
  26789. // if the plugin has a window, then send the event to the window so that
  26790. // its message thread will pick it up..
  26791. XSendEvent (display, pluginWindow, False, 0L, event);
  26792. XFlush (display);
  26793. }
  26794. }
  26795. void mouseEnter (const MouseEvent& e)
  26796. {
  26797. if (pluginWindow != 0)
  26798. {
  26799. XEvent ev;
  26800. zerostruct (ev);
  26801. ev.xcrossing.display = display;
  26802. ev.xcrossing.type = EnterNotify;
  26803. ev.xcrossing.window = pluginWindow;
  26804. ev.xcrossing.root = RootWindow (display, DefaultScreen (display));
  26805. ev.xcrossing.time = CurrentTime;
  26806. ev.xcrossing.x = e.x;
  26807. ev.xcrossing.y = e.y;
  26808. ev.xcrossing.x_root = e.getScreenX();
  26809. ev.xcrossing.y_root = e.getScreenY();
  26810. ev.xcrossing.mode = NotifyNormal; // NotifyGrab, NotifyUngrab
  26811. ev.xcrossing.detail = NotifyAncestor; // NotifyVirtual, NotifyInferior, NotifyNonlinear,NotifyNonlinearVirtual
  26812. translateJuceToXCrossingModifiers (e, ev);
  26813. sendEventToChild (&ev);
  26814. }
  26815. }
  26816. void mouseExit (const MouseEvent& e)
  26817. {
  26818. if (pluginWindow != 0)
  26819. {
  26820. XEvent ev;
  26821. zerostruct (ev);
  26822. ev.xcrossing.display = display;
  26823. ev.xcrossing.type = LeaveNotify;
  26824. ev.xcrossing.window = pluginWindow;
  26825. ev.xcrossing.root = RootWindow (display, DefaultScreen (display));
  26826. ev.xcrossing.time = CurrentTime;
  26827. ev.xcrossing.x = e.x;
  26828. ev.xcrossing.y = e.y;
  26829. ev.xcrossing.x_root = e.getScreenX();
  26830. ev.xcrossing.y_root = e.getScreenY();
  26831. ev.xcrossing.mode = NotifyNormal; // NotifyGrab, NotifyUngrab
  26832. ev.xcrossing.detail = NotifyAncestor; // NotifyVirtual, NotifyInferior, NotifyNonlinear,NotifyNonlinearVirtual
  26833. ev.xcrossing.focus = hasKeyboardFocus (true); // TODO - yes ?
  26834. translateJuceToXCrossingModifiers (e, ev);
  26835. sendEventToChild (&ev);
  26836. }
  26837. }
  26838. void mouseMove (const MouseEvent& e)
  26839. {
  26840. if (pluginWindow != 0)
  26841. {
  26842. XEvent ev;
  26843. zerostruct (ev);
  26844. ev.xmotion.display = display;
  26845. ev.xmotion.type = MotionNotify;
  26846. ev.xmotion.window = pluginWindow;
  26847. ev.xmotion.root = RootWindow (display, DefaultScreen (display));
  26848. ev.xmotion.time = CurrentTime;
  26849. ev.xmotion.is_hint = NotifyNormal;
  26850. ev.xmotion.x = e.x;
  26851. ev.xmotion.y = e.y;
  26852. ev.xmotion.x_root = e.getScreenX();
  26853. ev.xmotion.y_root = e.getScreenY();
  26854. sendEventToChild (&ev);
  26855. }
  26856. }
  26857. void mouseDrag (const MouseEvent& e)
  26858. {
  26859. if (pluginWindow != 0)
  26860. {
  26861. XEvent ev;
  26862. zerostruct (ev);
  26863. ev.xmotion.display = display;
  26864. ev.xmotion.type = MotionNotify;
  26865. ev.xmotion.window = pluginWindow;
  26866. ev.xmotion.root = RootWindow (display, DefaultScreen (display));
  26867. ev.xmotion.time = CurrentTime;
  26868. ev.xmotion.x = e.x ;
  26869. ev.xmotion.y = e.y;
  26870. ev.xmotion.x_root = e.getScreenX();
  26871. ev.xmotion.y_root = e.getScreenY();
  26872. ev.xmotion.is_hint = NotifyNormal;
  26873. translateJuceToXMotionModifiers (e, ev);
  26874. sendEventToChild (&ev);
  26875. }
  26876. }
  26877. void mouseUp (const MouseEvent& e)
  26878. {
  26879. if (pluginWindow != 0)
  26880. {
  26881. XEvent ev;
  26882. zerostruct (ev);
  26883. ev.xbutton.display = display;
  26884. ev.xbutton.type = ButtonRelease;
  26885. ev.xbutton.window = pluginWindow;
  26886. ev.xbutton.root = RootWindow (display, DefaultScreen (display));
  26887. ev.xbutton.time = CurrentTime;
  26888. ev.xbutton.x = e.x;
  26889. ev.xbutton.y = e.y;
  26890. ev.xbutton.x_root = e.getScreenX();
  26891. ev.xbutton.y_root = e.getScreenY();
  26892. translateJuceToXButtonModifiers (e, ev);
  26893. sendEventToChild (&ev);
  26894. }
  26895. }
  26896. void mouseWheelMove (const MouseEvent& e,
  26897. float incrementX,
  26898. float incrementY)
  26899. {
  26900. if (pluginWindow != 0)
  26901. {
  26902. XEvent ev;
  26903. zerostruct (ev);
  26904. ev.xbutton.display = display;
  26905. ev.xbutton.type = ButtonPress;
  26906. ev.xbutton.window = pluginWindow;
  26907. ev.xbutton.root = RootWindow (display, DefaultScreen (display));
  26908. ev.xbutton.time = CurrentTime;
  26909. ev.xbutton.x = e.x;
  26910. ev.xbutton.y = e.y;
  26911. ev.xbutton.x_root = e.getScreenX();
  26912. ev.xbutton.y_root = e.getScreenY();
  26913. translateJuceToXMouseWheelModifiers (e, incrementY, ev);
  26914. sendEventToChild (&ev);
  26915. // TODO - put a usleep here ?
  26916. ev.xbutton.type = ButtonRelease;
  26917. sendEventToChild (&ev);
  26918. }
  26919. }
  26920. #endif
  26921. #if JUCE_MAC
  26922. #if ! JUCE_SUPPORT_CARBON
  26923. #error "To build VSTs, you need to enable the JUCE_SUPPORT_CARBON flag in your config!"
  26924. #endif
  26925. class InnerWrapperComponent : public CarbonViewWrapperComponent
  26926. {
  26927. public:
  26928. InnerWrapperComponent (VSTPluginWindow* const owner_)
  26929. : owner (owner_),
  26930. alreadyInside (false)
  26931. {
  26932. }
  26933. ~InnerWrapperComponent()
  26934. {
  26935. deleteWindow();
  26936. }
  26937. HIViewRef attachView (WindowRef windowRef, HIViewRef rootView)
  26938. {
  26939. owner->openPluginWindow (windowRef);
  26940. return 0;
  26941. }
  26942. void removeView (HIViewRef)
  26943. {
  26944. owner->dispatch (effEditClose, 0, 0, 0, 0);
  26945. owner->dispatch (effEditSleep, 0, 0, 0, 0);
  26946. }
  26947. bool getEmbeddedViewSize (int& w, int& h)
  26948. {
  26949. ERect* rect = 0;
  26950. owner->dispatch (effEditGetRect, 0, 0, &rect, 0);
  26951. w = rect->right - rect->left;
  26952. h = rect->bottom - rect->top;
  26953. return true;
  26954. }
  26955. void mouseDown (int x, int y)
  26956. {
  26957. if (! alreadyInside)
  26958. {
  26959. alreadyInside = true;
  26960. getTopLevelComponent()->toFront (true);
  26961. owner->dispatch (effEditMouse, x, y, 0, 0);
  26962. alreadyInside = false;
  26963. }
  26964. else
  26965. {
  26966. PostEvent (::mouseDown, 0);
  26967. }
  26968. }
  26969. void paint()
  26970. {
  26971. ComponentPeer* const peer = getPeer();
  26972. if (peer != 0)
  26973. {
  26974. ERect r;
  26975. r.left = getScreenX() - peer->getScreenX();
  26976. r.right = r.left + getWidth();
  26977. r.top = getScreenY() - peer->getScreenY();
  26978. r.bottom = r.top + getHeight();
  26979. owner->dispatch (effEditDraw, 0, 0, &r, 0);
  26980. }
  26981. }
  26982. private:
  26983. VSTPluginWindow* const owner;
  26984. bool alreadyInside;
  26985. };
  26986. friend class InnerWrapperComponent;
  26987. ScopedPointer <InnerWrapperComponent> innerWrapper;
  26988. void resized()
  26989. {
  26990. innerWrapper->setSize (getWidth(), getHeight());
  26991. }
  26992. #endif
  26993. };
  26994. AudioProcessorEditor* VSTPluginInstance::createEditor()
  26995. {
  26996. if (hasEditor())
  26997. return new VSTPluginWindow (*this);
  26998. return 0;
  26999. }
  27000. void VSTPluginInstance::handleAsyncUpdate()
  27001. {
  27002. // indicates that something about the plugin has changed..
  27003. updateHostDisplay();
  27004. }
  27005. bool VSTPluginInstance::restoreProgramSettings (const fxProgram* const prog)
  27006. {
  27007. if (vst_swap (prog->chunkMagic) == 'CcnK' && vst_swap (prog->fxMagic) == 'FxCk')
  27008. {
  27009. changeProgramName (getCurrentProgram(), prog->prgName);
  27010. for (int i = 0; i < vst_swap (prog->numParams); ++i)
  27011. setParameter (i, vst_swapFloat (prog->params[i]));
  27012. return true;
  27013. }
  27014. return false;
  27015. }
  27016. bool VSTPluginInstance::loadFromFXBFile (const void* const data,
  27017. const int dataSize)
  27018. {
  27019. if (dataSize < 28)
  27020. return false;
  27021. const fxSet* const set = (const fxSet*) data;
  27022. if ((vst_swap (set->chunkMagic) != 'CcnK' && vst_swap (set->chunkMagic) != 'KncC')
  27023. || vst_swap (set->version) > fxbVersionNum)
  27024. return false;
  27025. if (vst_swap (set->fxMagic) == 'FxBk')
  27026. {
  27027. // bank of programs
  27028. if (vst_swap (set->numPrograms) >= 0)
  27029. {
  27030. const int oldProg = getCurrentProgram();
  27031. const int numParams = vst_swap (((const fxProgram*) (set->programs))->numParams);
  27032. const int progLen = sizeof (fxProgram) + (numParams - 1) * sizeof (float);
  27033. for (int i = 0; i < vst_swap (set->numPrograms); ++i)
  27034. {
  27035. if (i != oldProg)
  27036. {
  27037. const fxProgram* const prog = (const fxProgram*) (((const char*) (set->programs)) + i * progLen);
  27038. if (((const char*) prog) - ((const char*) set) >= dataSize)
  27039. return false;
  27040. if (vst_swap (set->numPrograms) > 0)
  27041. setCurrentProgram (i);
  27042. if (! restoreProgramSettings (prog))
  27043. return false;
  27044. }
  27045. }
  27046. if (vst_swap (set->numPrograms) > 0)
  27047. setCurrentProgram (oldProg);
  27048. const fxProgram* const prog = (const fxProgram*) (((const char*) (set->programs)) + oldProg * progLen);
  27049. if (((const char*) prog) - ((const char*) set) >= dataSize)
  27050. return false;
  27051. if (! restoreProgramSettings (prog))
  27052. return false;
  27053. }
  27054. }
  27055. else if (vst_swap (set->fxMagic) == 'FxCk')
  27056. {
  27057. // single program
  27058. const fxProgram* const prog = (const fxProgram*) data;
  27059. if (vst_swap (prog->chunkMagic) != 'CcnK')
  27060. return false;
  27061. changeProgramName (getCurrentProgram(), prog->prgName);
  27062. for (int i = 0; i < vst_swap (prog->numParams); ++i)
  27063. setParameter (i, vst_swapFloat (prog->params[i]));
  27064. }
  27065. else if (vst_swap (set->fxMagic) == 'FBCh' || vst_swap (set->fxMagic) == 'hCBF')
  27066. {
  27067. // non-preset chunk
  27068. const fxChunkSet* const cset = (const fxChunkSet*) data;
  27069. if (vst_swap (cset->chunkSize) + sizeof (fxChunkSet) - 8 > (unsigned int) dataSize)
  27070. return false;
  27071. setChunkData (cset->chunk, vst_swap (cset->chunkSize), false);
  27072. }
  27073. else if (vst_swap (set->fxMagic) == 'FPCh' || vst_swap (set->fxMagic) == 'hCPF')
  27074. {
  27075. // preset chunk
  27076. const fxProgramSet* const cset = (const fxProgramSet*) data;
  27077. if (vst_swap (cset->chunkSize) + sizeof (fxProgramSet) - 8 > (unsigned int) dataSize)
  27078. return false;
  27079. setChunkData (cset->chunk, vst_swap (cset->chunkSize), true);
  27080. changeProgramName (getCurrentProgram(), cset->name);
  27081. }
  27082. else
  27083. {
  27084. return false;
  27085. }
  27086. return true;
  27087. }
  27088. void VSTPluginInstance::setParamsInProgramBlock (fxProgram* const prog) throw()
  27089. {
  27090. const int numParams = getNumParameters();
  27091. prog->chunkMagic = vst_swap ('CcnK');
  27092. prog->byteSize = 0;
  27093. prog->fxMagic = vst_swap ('FxCk');
  27094. prog->version = vst_swap (fxbVersionNum);
  27095. prog->fxID = vst_swap (getUID());
  27096. prog->fxVersion = vst_swap (getVersionNumber());
  27097. prog->numParams = vst_swap (numParams);
  27098. getCurrentProgramName().copyToBuffer (prog->prgName, sizeof (prog->prgName) - 1);
  27099. for (int i = 0; i < numParams; ++i)
  27100. prog->params[i] = vst_swapFloat (getParameter (i));
  27101. }
  27102. bool VSTPluginInstance::saveToFXBFile (MemoryBlock& dest, bool isFXB, int maxSizeMB)
  27103. {
  27104. const int numPrograms = getNumPrograms();
  27105. const int numParams = getNumParameters();
  27106. if (usesChunks())
  27107. {
  27108. if (isFXB)
  27109. {
  27110. MemoryBlock chunk;
  27111. getChunkData (chunk, false, maxSizeMB);
  27112. const size_t totalLen = sizeof (fxChunkSet) + chunk.getSize() - 8;
  27113. dest.setSize (totalLen, true);
  27114. fxChunkSet* const set = (fxChunkSet*) dest.getData();
  27115. set->chunkMagic = vst_swap ('CcnK');
  27116. set->byteSize = 0;
  27117. set->fxMagic = vst_swap ('FBCh');
  27118. set->version = vst_swap (fxbVersionNum);
  27119. set->fxID = vst_swap (getUID());
  27120. set->fxVersion = vst_swap (getVersionNumber());
  27121. set->numPrograms = vst_swap (numPrograms);
  27122. set->chunkSize = vst_swap ((long) chunk.getSize());
  27123. chunk.copyTo (set->chunk, 0, chunk.getSize());
  27124. }
  27125. else
  27126. {
  27127. MemoryBlock chunk;
  27128. getChunkData (chunk, true, maxSizeMB);
  27129. const size_t totalLen = sizeof (fxProgramSet) + chunk.getSize() - 8;
  27130. dest.setSize (totalLen, true);
  27131. fxProgramSet* const set = (fxProgramSet*) dest.getData();
  27132. set->chunkMagic = vst_swap ('CcnK');
  27133. set->byteSize = 0;
  27134. set->fxMagic = vst_swap ('FPCh');
  27135. set->version = vst_swap (fxbVersionNum);
  27136. set->fxID = vst_swap (getUID());
  27137. set->fxVersion = vst_swap (getVersionNumber());
  27138. set->numPrograms = vst_swap (numPrograms);
  27139. set->chunkSize = vst_swap ((long) chunk.getSize());
  27140. getCurrentProgramName().copyToBuffer (set->name, sizeof (set->name) - 1);
  27141. chunk.copyTo (set->chunk, 0, chunk.getSize());
  27142. }
  27143. }
  27144. else
  27145. {
  27146. if (isFXB)
  27147. {
  27148. const int progLen = sizeof (fxProgram) + (numParams - 1) * sizeof (float);
  27149. const int len = (sizeof (fxSet) - sizeof (fxProgram)) + progLen * jmax (1, numPrograms);
  27150. dest.setSize (len, true);
  27151. fxSet* const set = (fxSet*) dest.getData();
  27152. set->chunkMagic = vst_swap ('CcnK');
  27153. set->byteSize = 0;
  27154. set->fxMagic = vst_swap ('FxBk');
  27155. set->version = vst_swap (fxbVersionNum);
  27156. set->fxID = vst_swap (getUID());
  27157. set->fxVersion = vst_swap (getVersionNumber());
  27158. set->numPrograms = vst_swap (numPrograms);
  27159. const int oldProgram = getCurrentProgram();
  27160. MemoryBlock oldSettings;
  27161. createTempParameterStore (oldSettings);
  27162. setParamsInProgramBlock ((fxProgram*) (((char*) (set->programs)) + oldProgram * progLen));
  27163. for (int i = 0; i < numPrograms; ++i)
  27164. {
  27165. if (i != oldProgram)
  27166. {
  27167. setCurrentProgram (i);
  27168. setParamsInProgramBlock ((fxProgram*) (((char*) (set->programs)) + i * progLen));
  27169. }
  27170. }
  27171. setCurrentProgram (oldProgram);
  27172. restoreFromTempParameterStore (oldSettings);
  27173. }
  27174. else
  27175. {
  27176. const int totalLen = sizeof (fxProgram) + (numParams - 1) * sizeof (float);
  27177. dest.setSize (totalLen, true);
  27178. setParamsInProgramBlock ((fxProgram*) dest.getData());
  27179. }
  27180. }
  27181. return true;
  27182. }
  27183. void VSTPluginInstance::getChunkData (MemoryBlock& mb, bool isPreset, int maxSizeMB) const
  27184. {
  27185. if (usesChunks())
  27186. {
  27187. void* data = 0;
  27188. const int bytes = dispatch (effGetChunk, isPreset ? 1 : 0, 0, &data, 0.0f);
  27189. if (data != 0 && bytes <= maxSizeMB * 1024 * 1024)
  27190. {
  27191. mb.setSize (bytes);
  27192. mb.copyFrom (data, 0, bytes);
  27193. }
  27194. }
  27195. }
  27196. void VSTPluginInstance::setChunkData (const char* data, int size, bool isPreset)
  27197. {
  27198. if (size > 0 && usesChunks())
  27199. {
  27200. dispatch (effSetChunk, isPreset ? 1 : 0, size, (void*) data, 0.0f);
  27201. if (! isPreset)
  27202. updateStoredProgramNames();
  27203. }
  27204. }
  27205. void VSTPluginInstance::timerCallback()
  27206. {
  27207. if (dispatch (effIdle, 0, 0, 0, 0) == 0)
  27208. stopTimer();
  27209. }
  27210. int VSTPluginInstance::dispatch (const int opcode, const int index, const int value, void* const ptr, float opt) const
  27211. {
  27212. const ScopedLock sl (lock);
  27213. ++insideVSTCallback;
  27214. int result = 0;
  27215. try
  27216. {
  27217. if (effect != 0)
  27218. {
  27219. #if JUCE_MAC
  27220. if (module->resFileId != 0)
  27221. UseResFile (module->resFileId);
  27222. CGrafPtr oldPort;
  27223. if (getActiveEditor() != 0)
  27224. {
  27225. int x = 0, y = 0;
  27226. getActiveEditor()->relativePositionToOtherComponent (getActiveEditor()->getTopLevelComponent(), x, y);
  27227. GetPort (&oldPort);
  27228. SetPortWindowPort ((WindowRef) getActiveEditor()->getWindowHandle());
  27229. SetOrigin (-x, -y);
  27230. }
  27231. #endif
  27232. result = effect->dispatcher (effect, opcode, index, value, ptr, opt);
  27233. #if JUCE_MAC
  27234. if (getActiveEditor() != 0)
  27235. SetPort (oldPort);
  27236. module->resFileId = CurResFile();
  27237. #endif
  27238. --insideVSTCallback;
  27239. return result;
  27240. }
  27241. }
  27242. catch (...)
  27243. {
  27244. //char s[512];
  27245. //sprintf (s, "dispatcher (%d, %d, %d, %x, %f)", opcode, index, value, (int)ptr, opt);
  27246. }
  27247. --insideVSTCallback;
  27248. return result;
  27249. }
  27250. // handles non plugin-specific callbacks..
  27251. static const int defaultVSTSampleRateValue = 16384;
  27252. static const int defaultVSTBlockSizeValue = 512;
  27253. static VstIntPtr handleGeneralCallback (VstInt32 opcode, VstInt32 index, VstInt32 value, void *ptr, float opt)
  27254. {
  27255. (void) index;
  27256. (void) value;
  27257. (void) opt;
  27258. switch (opcode)
  27259. {
  27260. case audioMasterCanDo:
  27261. {
  27262. static const char* canDos[] = { "supplyIdle",
  27263. "sendVstEvents",
  27264. "sendVstMidiEvent",
  27265. "sendVstTimeInfo",
  27266. "receiveVstEvents",
  27267. "receiveVstMidiEvent",
  27268. "supportShell",
  27269. "shellCategory" };
  27270. for (int i = 0; i < numElementsInArray (canDos); ++i)
  27271. if (strcmp (canDos[i], (const char*) ptr) == 0)
  27272. return 1;
  27273. return 0;
  27274. }
  27275. case audioMasterVersion:
  27276. return 0x2400;
  27277. case audioMasterCurrentId:
  27278. return shellUIDToCreate;
  27279. case audioMasterGetNumAutomatableParameters:
  27280. return 0;
  27281. case audioMasterGetAutomationState:
  27282. return 1;
  27283. case audioMasterGetVendorVersion:
  27284. return 0x0101;
  27285. case audioMasterGetVendorString:
  27286. case audioMasterGetProductString:
  27287. {
  27288. String hostName ("Juce VST Host");
  27289. if (JUCEApplication::getInstance() != 0)
  27290. hostName = JUCEApplication::getInstance()->getApplicationName();
  27291. hostName.copyToBuffer ((char*) ptr, jmin (kVstMaxVendorStrLen, kVstMaxProductStrLen) - 1);
  27292. }
  27293. break;
  27294. case audioMasterGetSampleRate:
  27295. return (VstIntPtr) defaultVSTSampleRateValue;
  27296. case audioMasterGetBlockSize:
  27297. return (VstIntPtr) defaultVSTBlockSizeValue;
  27298. case audioMasterSetOutputSampleRate:
  27299. return 0;
  27300. default:
  27301. DBG ("*** Unhandled VST Callback: " + String ((int) opcode));
  27302. break;
  27303. }
  27304. return 0;
  27305. }
  27306. // handles callbacks for a specific plugin
  27307. VstIntPtr VSTPluginInstance::handleCallback (VstInt32 opcode, VstInt32 index, VstInt32 value, void *ptr, float opt)
  27308. {
  27309. switch (opcode)
  27310. {
  27311. case audioMasterAutomate:
  27312. sendParamChangeMessageToListeners (index, opt);
  27313. break;
  27314. case audioMasterProcessEvents:
  27315. handleMidiFromPlugin ((const VstEvents*) ptr);
  27316. break;
  27317. case audioMasterGetTime:
  27318. #ifdef _MSC_VER
  27319. #pragma warning (push)
  27320. #pragma warning (disable: 4311)
  27321. #endif
  27322. return (VstIntPtr) &vstHostTime;
  27323. #ifdef _MSC_VER
  27324. #pragma warning (pop)
  27325. #endif
  27326. break;
  27327. case audioMasterIdle:
  27328. if (insideVSTCallback == 0 && MessageManager::getInstance()->isThisTheMessageThread())
  27329. {
  27330. ++insideVSTCallback;
  27331. #if JUCE_MAC
  27332. if (getActiveEditor() != 0)
  27333. dispatch (effEditIdle, 0, 0, 0, 0);
  27334. #endif
  27335. juce_callAnyTimersSynchronously();
  27336. handleUpdateNowIfNeeded();
  27337. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  27338. ComponentPeer::getPeer (i)->performAnyPendingRepaintsNow();
  27339. --insideVSTCallback;
  27340. }
  27341. break;
  27342. case audioMasterUpdateDisplay:
  27343. triggerAsyncUpdate();
  27344. break;
  27345. case audioMasterTempoAt:
  27346. // returns (10000 * bpm)
  27347. break;
  27348. case audioMasterNeedIdle:
  27349. startTimer (50);
  27350. break;
  27351. case audioMasterSizeWindow:
  27352. if (getActiveEditor() != 0)
  27353. getActiveEditor()->setSize (index, value);
  27354. return 1;
  27355. case audioMasterGetSampleRate:
  27356. return (VstIntPtr) (getSampleRate() > 0 ? getSampleRate() : defaultVSTSampleRateValue);
  27357. case audioMasterGetBlockSize:
  27358. return (VstIntPtr) (getBlockSize() > 0 ? getBlockSize() : defaultVSTBlockSizeValue);
  27359. case audioMasterWantMidi:
  27360. wantsMidiMessages = true;
  27361. break;
  27362. case audioMasterGetDirectory:
  27363. #if JUCE_MAC
  27364. return (VstIntPtr) (void*) &module->parentDirFSSpec;
  27365. #else
  27366. return (VstIntPtr) (pointer_sized_uint) (const char*) module->fullParentDirectoryPathName;
  27367. #endif
  27368. case audioMasterGetAutomationState:
  27369. // returns 0: not supported, 1: off, 2:read, 3:write, 4:read/write
  27370. break;
  27371. // none of these are handled (yet)..
  27372. case audioMasterBeginEdit:
  27373. case audioMasterEndEdit:
  27374. case audioMasterSetTime:
  27375. case audioMasterPinConnected:
  27376. case audioMasterGetParameterQuantization:
  27377. case audioMasterIOChanged:
  27378. case audioMasterGetInputLatency:
  27379. case audioMasterGetOutputLatency:
  27380. case audioMasterGetPreviousPlug:
  27381. case audioMasterGetNextPlug:
  27382. case audioMasterWillReplaceOrAccumulate:
  27383. case audioMasterGetCurrentProcessLevel:
  27384. case audioMasterOfflineStart:
  27385. case audioMasterOfflineRead:
  27386. case audioMasterOfflineWrite:
  27387. case audioMasterOfflineGetCurrentPass:
  27388. case audioMasterOfflineGetCurrentMetaPass:
  27389. case audioMasterVendorSpecific:
  27390. case audioMasterSetIcon:
  27391. case audioMasterGetLanguage:
  27392. case audioMasterOpenWindow:
  27393. case audioMasterCloseWindow:
  27394. break;
  27395. default:
  27396. return handleGeneralCallback (opcode, index, value, ptr, opt);
  27397. }
  27398. return 0;
  27399. }
  27400. // entry point for all callbacks from the plugin
  27401. static VstIntPtr VSTCALLBACK audioMaster (AEffect* effect, VstInt32 opcode, VstInt32 index, VstIntPtr value, void* ptr, float opt)
  27402. {
  27403. try
  27404. {
  27405. if (effect != 0 && effect->resvd2 != 0)
  27406. {
  27407. return ((VSTPluginInstance*)(effect->resvd2))
  27408. ->handleCallback (opcode, index, value, ptr, opt);
  27409. }
  27410. return handleGeneralCallback (opcode, index, value, ptr, opt);
  27411. }
  27412. catch (...)
  27413. {
  27414. return 0;
  27415. }
  27416. }
  27417. const String VSTPluginInstance::getVersion() const throw()
  27418. {
  27419. unsigned int v = dispatch (effGetVendorVersion, 0, 0, 0, 0);
  27420. String s;
  27421. if (v == 0 || v == -1)
  27422. v = getVersionNumber();
  27423. if (v != 0)
  27424. {
  27425. int versionBits[4];
  27426. int n = 0;
  27427. while (v != 0)
  27428. {
  27429. versionBits [n++] = (v & 0xff);
  27430. v >>= 8;
  27431. }
  27432. s << 'V';
  27433. while (n > 0)
  27434. {
  27435. s << versionBits [--n];
  27436. if (n > 0)
  27437. s << '.';
  27438. }
  27439. }
  27440. return s;
  27441. }
  27442. int VSTPluginInstance::getUID() const throw()
  27443. {
  27444. int uid = effect != 0 ? effect->uniqueID : 0;
  27445. if (uid == 0)
  27446. uid = module->file.hashCode();
  27447. return uid;
  27448. }
  27449. const String VSTPluginInstance::getCategory() const throw()
  27450. {
  27451. const char* result = 0;
  27452. switch (dispatch (effGetPlugCategory, 0, 0, 0, 0))
  27453. {
  27454. case kPlugCategEffect:
  27455. result = "Effect";
  27456. break;
  27457. case kPlugCategSynth:
  27458. result = "Synth";
  27459. break;
  27460. case kPlugCategAnalysis:
  27461. result = "Anaylsis";
  27462. break;
  27463. case kPlugCategMastering:
  27464. result = "Mastering";
  27465. break;
  27466. case kPlugCategSpacializer:
  27467. result = "Spacial";
  27468. break;
  27469. case kPlugCategRoomFx:
  27470. result = "Reverb";
  27471. break;
  27472. case kPlugSurroundFx:
  27473. result = "Surround";
  27474. break;
  27475. case kPlugCategRestoration:
  27476. result = "Restoration";
  27477. break;
  27478. case kPlugCategGenerator:
  27479. result = "Tone generation";
  27480. break;
  27481. default:
  27482. break;
  27483. }
  27484. return result;
  27485. }
  27486. float VSTPluginInstance::getParameter (int index)
  27487. {
  27488. if (effect != 0 && ((unsigned int) index) < (unsigned int) effect->numParams)
  27489. {
  27490. try
  27491. {
  27492. const ScopedLock sl (lock);
  27493. return effect->getParameter (effect, index);
  27494. }
  27495. catch (...)
  27496. {
  27497. }
  27498. }
  27499. return 0.0f;
  27500. }
  27501. void VSTPluginInstance::setParameter (int index, float newValue)
  27502. {
  27503. if (effect != 0 && ((unsigned int) index) < (unsigned int) effect->numParams)
  27504. {
  27505. try
  27506. {
  27507. const ScopedLock sl (lock);
  27508. if (effect->getParameter (effect, index) != newValue)
  27509. effect->setParameter (effect, index, newValue);
  27510. }
  27511. catch (...)
  27512. {
  27513. }
  27514. }
  27515. }
  27516. const String VSTPluginInstance::getParameterName (int index)
  27517. {
  27518. if (effect != 0)
  27519. {
  27520. jassert (index >= 0 && index < effect->numParams);
  27521. char nm [256];
  27522. zerostruct (nm);
  27523. dispatch (effGetParamName, index, 0, nm, 0);
  27524. return String (nm).trim();
  27525. }
  27526. return String::empty;
  27527. }
  27528. const String VSTPluginInstance::getParameterLabel (int index) const
  27529. {
  27530. if (effect != 0)
  27531. {
  27532. jassert (index >= 0 && index < effect->numParams);
  27533. char nm [256];
  27534. zerostruct (nm);
  27535. dispatch (effGetParamLabel, index, 0, nm, 0);
  27536. return String (nm).trim();
  27537. }
  27538. return String::empty;
  27539. }
  27540. const String VSTPluginInstance::getParameterText (int index)
  27541. {
  27542. if (effect != 0)
  27543. {
  27544. jassert (index >= 0 && index < effect->numParams);
  27545. char nm [256];
  27546. zerostruct (nm);
  27547. dispatch (effGetParamDisplay, index, 0, nm, 0);
  27548. return String (nm).trim();
  27549. }
  27550. return String::empty;
  27551. }
  27552. bool VSTPluginInstance::isParameterAutomatable (int index) const
  27553. {
  27554. if (effect != 0)
  27555. {
  27556. jassert (index >= 0 && index < effect->numParams);
  27557. return dispatch (effCanBeAutomated, index, 0, 0, 0) != 0;
  27558. }
  27559. return false;
  27560. }
  27561. void VSTPluginInstance::createTempParameterStore (MemoryBlock& dest)
  27562. {
  27563. dest.setSize (64 + 4 * getNumParameters());
  27564. dest.fillWith (0);
  27565. getCurrentProgramName().copyToBuffer ((char*) dest.getData(), 63);
  27566. float* const p = (float*) (((char*) dest.getData()) + 64);
  27567. for (int i = 0; i < getNumParameters(); ++i)
  27568. p[i] = getParameter(i);
  27569. }
  27570. void VSTPluginInstance::restoreFromTempParameterStore (const MemoryBlock& m)
  27571. {
  27572. changeProgramName (getCurrentProgram(), (const char*) m.getData());
  27573. float* p = (float*) (((char*) m.getData()) + 64);
  27574. for (int i = 0; i < getNumParameters(); ++i)
  27575. setParameter (i, p[i]);
  27576. }
  27577. void VSTPluginInstance::setCurrentProgram (int newIndex)
  27578. {
  27579. if (getNumPrograms() > 0 && newIndex != getCurrentProgram())
  27580. dispatch (effSetProgram, 0, jlimit (0, getNumPrograms() - 1, newIndex), 0, 0);
  27581. }
  27582. const String VSTPluginInstance::getProgramName (int index)
  27583. {
  27584. if (index == getCurrentProgram())
  27585. {
  27586. return getCurrentProgramName();
  27587. }
  27588. else if (effect != 0)
  27589. {
  27590. char nm [256];
  27591. zerostruct (nm);
  27592. if (dispatch (effGetProgramNameIndexed,
  27593. jlimit (0, getNumPrograms(), index),
  27594. -1, nm, 0) != 0)
  27595. {
  27596. return String (nm).trim();
  27597. }
  27598. }
  27599. return programNames [index];
  27600. }
  27601. void VSTPluginInstance::changeProgramName (int index, const String& newName)
  27602. {
  27603. if (index == getCurrentProgram())
  27604. {
  27605. if (getNumPrograms() > 0 && newName != getCurrentProgramName())
  27606. dispatch (effSetProgramName, 0, 0, (void*) (const char*) newName.substring (0, 24), 0.0f);
  27607. }
  27608. else
  27609. {
  27610. jassertfalse // xxx not implemented!
  27611. }
  27612. }
  27613. void VSTPluginInstance::updateStoredProgramNames()
  27614. {
  27615. if (effect != 0 && getNumPrograms() > 0)
  27616. {
  27617. char nm [256];
  27618. zerostruct (nm);
  27619. // only do this if the plugin can't use indexed names..
  27620. if (dispatch (effGetProgramNameIndexed, 0, -1, nm, 0) == 0)
  27621. {
  27622. const int oldProgram = getCurrentProgram();
  27623. MemoryBlock oldSettings;
  27624. createTempParameterStore (oldSettings);
  27625. for (int i = 0; i < getNumPrograms(); ++i)
  27626. {
  27627. setCurrentProgram (i);
  27628. getCurrentProgramName(); // (this updates the list)
  27629. }
  27630. setCurrentProgram (oldProgram);
  27631. restoreFromTempParameterStore (oldSettings);
  27632. }
  27633. }
  27634. }
  27635. const String VSTPluginInstance::getCurrentProgramName()
  27636. {
  27637. if (effect != 0)
  27638. {
  27639. char nm [256];
  27640. zerostruct (nm);
  27641. dispatch (effGetProgramName, 0, 0, nm, 0);
  27642. const int index = getCurrentProgram();
  27643. if (programNames[index].isEmpty())
  27644. {
  27645. while (programNames.size() < index)
  27646. programNames.add (String::empty);
  27647. programNames.set (index, String (nm).trim());
  27648. }
  27649. return String (nm).trim();
  27650. }
  27651. return String::empty;
  27652. }
  27653. const String VSTPluginInstance::getInputChannelName (const int index) const
  27654. {
  27655. if (index >= 0 && index < getNumInputChannels())
  27656. {
  27657. VstPinProperties pinProps;
  27658. if (dispatch (effGetInputProperties, index, 0, &pinProps, 0.0f) != 0)
  27659. return String (pinProps.label, sizeof (pinProps.label));
  27660. }
  27661. return String::empty;
  27662. }
  27663. bool VSTPluginInstance::isInputChannelStereoPair (int index) const
  27664. {
  27665. if (index < 0 || index >= getNumInputChannels())
  27666. return false;
  27667. VstPinProperties pinProps;
  27668. if (dispatch (effGetInputProperties, index, 0, &pinProps, 0.0f) != 0)
  27669. return (pinProps.flags & kVstPinIsStereo) != 0;
  27670. return true;
  27671. }
  27672. const String VSTPluginInstance::getOutputChannelName (const int index) const
  27673. {
  27674. if (index >= 0 && index < getNumOutputChannels())
  27675. {
  27676. VstPinProperties pinProps;
  27677. if (dispatch (effGetOutputProperties, index, 0, &pinProps, 0.0f) != 0)
  27678. return String (pinProps.label, sizeof (pinProps.label));
  27679. }
  27680. return String::empty;
  27681. }
  27682. bool VSTPluginInstance::isOutputChannelStereoPair (int index) const
  27683. {
  27684. if (index < 0 || index >= getNumOutputChannels())
  27685. return false;
  27686. VstPinProperties pinProps;
  27687. if (dispatch (effGetOutputProperties, index, 0, &pinProps, 0.0f) != 0)
  27688. return (pinProps.flags & kVstPinIsStereo) != 0;
  27689. return true;
  27690. }
  27691. void VSTPluginInstance::setPower (const bool on)
  27692. {
  27693. dispatch (effMainsChanged, 0, on ? 1 : 0, 0, 0);
  27694. isPowerOn = on;
  27695. }
  27696. const int defaultMaxSizeMB = 64;
  27697. void VSTPluginInstance::getStateInformation (MemoryBlock& destData)
  27698. {
  27699. saveToFXBFile (destData, true, defaultMaxSizeMB);
  27700. }
  27701. void VSTPluginInstance::getCurrentProgramStateInformation (MemoryBlock& destData)
  27702. {
  27703. saveToFXBFile (destData, false, defaultMaxSizeMB);
  27704. }
  27705. void VSTPluginInstance::setStateInformation (const void* data, int sizeInBytes)
  27706. {
  27707. loadFromFXBFile (data, sizeInBytes);
  27708. }
  27709. void VSTPluginInstance::setCurrentProgramStateInformation (const void* data, int sizeInBytes)
  27710. {
  27711. loadFromFXBFile (data, sizeInBytes);
  27712. }
  27713. VSTPluginFormat::VSTPluginFormat()
  27714. {
  27715. }
  27716. VSTPluginFormat::~VSTPluginFormat()
  27717. {
  27718. }
  27719. void VSTPluginFormat::findAllTypesForFile (OwnedArray <PluginDescription>& results,
  27720. const String& fileOrIdentifier)
  27721. {
  27722. if (! fileMightContainThisPluginType (fileOrIdentifier))
  27723. return;
  27724. PluginDescription desc;
  27725. desc.fileOrIdentifier = fileOrIdentifier;
  27726. desc.uid = 0;
  27727. ScopedPointer <VSTPluginInstance> instance (dynamic_cast <VSTPluginInstance*> (createInstanceFromDescription (desc)));
  27728. if (instance == 0)
  27729. return;
  27730. try
  27731. {
  27732. #if JUCE_MAC
  27733. if (instance->module->resFileId != 0)
  27734. UseResFile (instance->module->resFileId);
  27735. #endif
  27736. instance->fillInPluginDescription (desc);
  27737. VstPlugCategory category = (VstPlugCategory) instance->dispatch (effGetPlugCategory, 0, 0, 0, 0);
  27738. if (category != kPlugCategShell)
  27739. {
  27740. // Normal plugin...
  27741. results.add (new PluginDescription (desc));
  27742. ++insideVSTCallback;
  27743. instance->dispatch (effOpen, 0, 0, 0, 0);
  27744. --insideVSTCallback;
  27745. }
  27746. else
  27747. {
  27748. // It's a shell plugin, so iterate all the subtypes...
  27749. char shellEffectName [64];
  27750. for (;;)
  27751. {
  27752. zerostruct (shellEffectName);
  27753. const int uid = instance->dispatch (effShellGetNextPlugin, 0, 0, shellEffectName, 0);
  27754. if (uid == 0)
  27755. {
  27756. break;
  27757. }
  27758. else
  27759. {
  27760. desc.uid = uid;
  27761. desc.name = shellEffectName;
  27762. bool alreadyThere = false;
  27763. for (int i = results.size(); --i >= 0;)
  27764. {
  27765. PluginDescription* const d = results.getUnchecked(i);
  27766. if (d->isDuplicateOf (desc))
  27767. {
  27768. alreadyThere = true;
  27769. break;
  27770. }
  27771. }
  27772. if (! alreadyThere)
  27773. results.add (new PluginDescription (desc));
  27774. }
  27775. }
  27776. }
  27777. }
  27778. catch (...)
  27779. {
  27780. // crashed while loading...
  27781. }
  27782. }
  27783. AudioPluginInstance* VSTPluginFormat::createInstanceFromDescription (const PluginDescription& desc)
  27784. {
  27785. ScopedPointer <VSTPluginInstance> result;
  27786. if (fileMightContainThisPluginType (desc.fileOrIdentifier))
  27787. {
  27788. File file (desc.fileOrIdentifier);
  27789. const File previousWorkingDirectory (File::getCurrentWorkingDirectory());
  27790. file.getParentDirectory().setAsCurrentWorkingDirectory();
  27791. const ReferenceCountedObjectPtr <ModuleHandle> module (ModuleHandle::findOrCreateModule (file));
  27792. if (module != 0)
  27793. {
  27794. shellUIDToCreate = desc.uid;
  27795. result = new VSTPluginInstance (module);
  27796. if (result->effect != 0)
  27797. {
  27798. result->effect->resvd2 = (VstIntPtr) (pointer_sized_int) (VSTPluginInstance*) result;
  27799. result->initialise();
  27800. }
  27801. else
  27802. {
  27803. result = 0;
  27804. }
  27805. }
  27806. previousWorkingDirectory.setAsCurrentWorkingDirectory();
  27807. }
  27808. return result.release();
  27809. }
  27810. bool VSTPluginFormat::fileMightContainThisPluginType (const String& fileOrIdentifier)
  27811. {
  27812. const File f (fileOrIdentifier);
  27813. #if JUCE_MAC
  27814. if (f.isDirectory() && f.hasFileExtension (T(".vst")))
  27815. return true;
  27816. #if JUCE_PPC
  27817. FSRef fileRef;
  27818. if (PlatformUtilities::makeFSRefFromPath (&fileRef, f.getFullPathName()))
  27819. {
  27820. const short resFileId = FSOpenResFile (&fileRef, fsRdPerm);
  27821. if (resFileId != -1)
  27822. {
  27823. const int numEffects = Count1Resources ('aEff');
  27824. CloseResFile (resFileId);
  27825. if (numEffects > 0)
  27826. return true;
  27827. }
  27828. }
  27829. #endif
  27830. return false;
  27831. #elif JUCE_WIN32
  27832. return f.existsAsFile()
  27833. && f.hasFileExtension (T(".dll"));
  27834. #elif JUCE_LINUX
  27835. return f.existsAsFile()
  27836. && f.hasFileExtension (T(".so"));
  27837. #endif
  27838. }
  27839. const String VSTPluginFormat::getNameOfPluginFromIdentifier (const String& fileOrIdentifier)
  27840. {
  27841. return fileOrIdentifier;
  27842. }
  27843. bool VSTPluginFormat::doesPluginStillExist (const PluginDescription& desc)
  27844. {
  27845. return File (desc.fileOrIdentifier).exists();
  27846. }
  27847. const StringArray VSTPluginFormat::searchPathsForPlugins (const FileSearchPath& directoriesToSearch, const bool recursive)
  27848. {
  27849. StringArray results;
  27850. for (int j = 0; j < directoriesToSearch.getNumPaths(); ++j)
  27851. recursiveFileSearch (results, directoriesToSearch [j], recursive);
  27852. return results;
  27853. }
  27854. void VSTPluginFormat::recursiveFileSearch (StringArray& results, const File& dir, const bool recursive)
  27855. {
  27856. // avoid allowing the dir iterator to be recursive, because we want to avoid letting it delve inside
  27857. // .component or .vst directories.
  27858. DirectoryIterator iter (dir, false, "*", File::findFilesAndDirectories);
  27859. while (iter.next())
  27860. {
  27861. const File f (iter.getFile());
  27862. bool isPlugin = false;
  27863. if (fileMightContainThisPluginType (f.getFullPathName()))
  27864. {
  27865. isPlugin = true;
  27866. results.add (f.getFullPathName());
  27867. }
  27868. if (recursive && (! isPlugin) && f.isDirectory())
  27869. recursiveFileSearch (results, f, true);
  27870. }
  27871. }
  27872. const FileSearchPath VSTPluginFormat::getDefaultLocationsToSearch()
  27873. {
  27874. #if JUCE_MAC
  27875. return FileSearchPath ("~/Library/Audio/Plug-Ins/VST;/Library/Audio/Plug-Ins/VST");
  27876. #elif JUCE_WIN32
  27877. const String programFiles (File::getSpecialLocation (File::globalApplicationsDirectory).getFullPathName());
  27878. return FileSearchPath (programFiles + "\\Steinberg\\VstPlugins");
  27879. #elif JUCE_LINUX
  27880. return FileSearchPath ("/usr/lib/vst");
  27881. #endif
  27882. }
  27883. END_JUCE_NAMESPACE
  27884. #endif
  27885. #undef log
  27886. #endif
  27887. /*** End of inlined file: juce_VSTPluginFormat.cpp ***/
  27888. /*** End of inlined file: juce_VSTPluginFormat.mm ***/
  27889. /*** Start of inlined file: juce_AudioProcessor.cpp ***/
  27890. BEGIN_JUCE_NAMESPACE
  27891. AudioProcessor::AudioProcessor()
  27892. : playHead (0),
  27893. activeEditor (0),
  27894. sampleRate (0),
  27895. blockSize (0),
  27896. numInputChannels (0),
  27897. numOutputChannels (0),
  27898. latencySamples (0),
  27899. suspended (false),
  27900. nonRealtime (false)
  27901. {
  27902. }
  27903. AudioProcessor::~AudioProcessor()
  27904. {
  27905. // ooh, nasty - the editor should have been deleted before the filter
  27906. // that it refers to is deleted..
  27907. jassert (activeEditor == 0);
  27908. #ifdef JUCE_DEBUG
  27909. // This will fail if you've called beginParameterChangeGesture() for one
  27910. // or more parameters without having made a corresponding call to endParameterChangeGesture...
  27911. jassert (changingParams.countNumberOfSetBits() == 0);
  27912. #endif
  27913. }
  27914. void AudioProcessor::setPlayHead (AudioPlayHead* const newPlayHead) throw()
  27915. {
  27916. playHead = newPlayHead;
  27917. }
  27918. void AudioProcessor::addListener (AudioProcessorListener* const newListener) throw()
  27919. {
  27920. const ScopedLock sl (listenerLock);
  27921. listeners.addIfNotAlreadyThere (newListener);
  27922. }
  27923. void AudioProcessor::removeListener (AudioProcessorListener* const listenerToRemove) throw()
  27924. {
  27925. const ScopedLock sl (listenerLock);
  27926. listeners.removeValue (listenerToRemove);
  27927. }
  27928. void AudioProcessor::setPlayConfigDetails (const int numIns,
  27929. const int numOuts,
  27930. const double sampleRate_,
  27931. const int blockSize_) throw()
  27932. {
  27933. numInputChannels = numIns;
  27934. numOutputChannels = numOuts;
  27935. sampleRate = sampleRate_;
  27936. blockSize = blockSize_;
  27937. }
  27938. void AudioProcessor::setNonRealtime (const bool nonRealtime_) throw()
  27939. {
  27940. nonRealtime = nonRealtime_;
  27941. }
  27942. void AudioProcessor::setLatencySamples (const int newLatency)
  27943. {
  27944. if (latencySamples != newLatency)
  27945. {
  27946. latencySamples = newLatency;
  27947. updateHostDisplay();
  27948. }
  27949. }
  27950. void AudioProcessor::setParameterNotifyingHost (const int parameterIndex,
  27951. const float newValue)
  27952. {
  27953. setParameter (parameterIndex, newValue);
  27954. sendParamChangeMessageToListeners (parameterIndex, newValue);
  27955. }
  27956. void AudioProcessor::sendParamChangeMessageToListeners (const int parameterIndex, const float newValue)
  27957. {
  27958. jassert (((unsigned int) parameterIndex) < (unsigned int) getNumParameters());
  27959. for (int i = listeners.size(); --i >= 0;)
  27960. {
  27961. listenerLock.enter();
  27962. AudioProcessorListener* const l = (AudioProcessorListener*) listeners [i];
  27963. listenerLock.exit();
  27964. if (l != 0)
  27965. l->audioProcessorParameterChanged (this, parameterIndex, newValue);
  27966. }
  27967. }
  27968. void AudioProcessor::beginParameterChangeGesture (int parameterIndex)
  27969. {
  27970. jassert (((unsigned int) parameterIndex) < (unsigned int) getNumParameters());
  27971. #ifdef JUCE_DEBUG
  27972. // This means you've called beginParameterChangeGesture twice in succession without a matching
  27973. // call to endParameterChangeGesture. That might be fine in most hosts, but better to avoid doing it.
  27974. jassert (! changingParams [parameterIndex]);
  27975. changingParams.setBit (parameterIndex);
  27976. #endif
  27977. for (int i = listeners.size(); --i >= 0;)
  27978. {
  27979. listenerLock.enter();
  27980. AudioProcessorListener* const l = (AudioProcessorListener*) listeners [i];
  27981. listenerLock.exit();
  27982. if (l != 0)
  27983. l->audioProcessorParameterChangeGestureBegin (this, parameterIndex);
  27984. }
  27985. }
  27986. void AudioProcessor::endParameterChangeGesture (int parameterIndex)
  27987. {
  27988. jassert (((unsigned int) parameterIndex) < (unsigned int) getNumParameters());
  27989. #ifdef JUCE_DEBUG
  27990. // This means you've called endParameterChangeGesture without having previously called
  27991. // endParameterChangeGesture. That might be fine in most hosts, but better to keep the
  27992. // calls matched correctly.
  27993. jassert (changingParams [parameterIndex]);
  27994. changingParams.clearBit (parameterIndex);
  27995. #endif
  27996. for (int i = listeners.size(); --i >= 0;)
  27997. {
  27998. listenerLock.enter();
  27999. AudioProcessorListener* const l = (AudioProcessorListener*) listeners [i];
  28000. listenerLock.exit();
  28001. if (l != 0)
  28002. l->audioProcessorParameterChangeGestureEnd (this, parameterIndex);
  28003. }
  28004. }
  28005. void AudioProcessor::updateHostDisplay()
  28006. {
  28007. for (int i = listeners.size(); --i >= 0;)
  28008. {
  28009. listenerLock.enter();
  28010. AudioProcessorListener* const l = (AudioProcessorListener*) listeners [i];
  28011. listenerLock.exit();
  28012. if (l != 0)
  28013. l->audioProcessorChanged (this);
  28014. }
  28015. }
  28016. bool AudioProcessor::isParameterAutomatable (int /*parameterIndex*/) const
  28017. {
  28018. return true;
  28019. }
  28020. bool AudioProcessor::isMetaParameter (int /*parameterIndex*/) const
  28021. {
  28022. return false;
  28023. }
  28024. void AudioProcessor::suspendProcessing (const bool shouldBeSuspended)
  28025. {
  28026. const ScopedLock sl (callbackLock);
  28027. suspended = shouldBeSuspended;
  28028. }
  28029. void AudioProcessor::reset()
  28030. {
  28031. }
  28032. void AudioProcessor::editorBeingDeleted (AudioProcessorEditor* const editor) throw()
  28033. {
  28034. const ScopedLock sl (callbackLock);
  28035. jassert (activeEditor == editor);
  28036. if (activeEditor == editor)
  28037. activeEditor = 0;
  28038. }
  28039. AudioProcessorEditor* AudioProcessor::createEditorIfNeeded()
  28040. {
  28041. if (activeEditor != 0)
  28042. return activeEditor;
  28043. AudioProcessorEditor* const ed = createEditor();
  28044. if (ed != 0)
  28045. {
  28046. // you must give your editor comp a size before returning it..
  28047. jassert (ed->getWidth() > 0 && ed->getHeight() > 0);
  28048. const ScopedLock sl (callbackLock);
  28049. activeEditor = ed;
  28050. }
  28051. return ed;
  28052. }
  28053. void AudioProcessor::getCurrentProgramStateInformation (JUCE_NAMESPACE::MemoryBlock& destData)
  28054. {
  28055. getStateInformation (destData);
  28056. }
  28057. void AudioProcessor::setCurrentProgramStateInformation (const void* data, int sizeInBytes)
  28058. {
  28059. setStateInformation (data, sizeInBytes);
  28060. }
  28061. // magic number to identify memory blocks that we've stored as XML
  28062. const uint32 magicXmlNumber = 0x21324356;
  28063. void AudioProcessor::copyXmlToBinary (const XmlElement& xml,
  28064. JUCE_NAMESPACE::MemoryBlock& destData)
  28065. {
  28066. const String xmlString (xml.createDocument (String::empty, true, false));
  28067. const int stringLength = xmlString.length();
  28068. destData.setSize (stringLength + 10);
  28069. char* const d = (char*) destData.getData();
  28070. *(uint32*) d = ByteOrder::swapIfBigEndian ((const uint32) magicXmlNumber);
  28071. *(uint32*) (d + 4) = ByteOrder::swapIfBigEndian ((const uint32) stringLength);
  28072. xmlString.copyToBuffer (d + 8, stringLength);
  28073. }
  28074. XmlElement* AudioProcessor::getXmlFromBinary (const void* data,
  28075. const int sizeInBytes)
  28076. {
  28077. if (sizeInBytes > 8
  28078. && ByteOrder::littleEndianInt ((const char*) data) == magicXmlNumber)
  28079. {
  28080. const int stringLength = (int) ByteOrder::littleEndianInt (((const char*) data) + 4);
  28081. if (stringLength > 0)
  28082. {
  28083. XmlDocument doc (String (((const char*) data) + 8,
  28084. jmin ((sizeInBytes - 8), stringLength)));
  28085. return doc.getDocumentElement();
  28086. }
  28087. }
  28088. return 0;
  28089. }
  28090. void AudioProcessorListener::audioProcessorParameterChangeGestureBegin (AudioProcessor*, int)
  28091. {
  28092. }
  28093. void AudioProcessorListener::audioProcessorParameterChangeGestureEnd (AudioProcessor*, int)
  28094. {
  28095. }
  28096. END_JUCE_NAMESPACE
  28097. /*** End of inlined file: juce_AudioProcessor.cpp ***/
  28098. /*** Start of inlined file: juce_AudioProcessorEditor.cpp ***/
  28099. BEGIN_JUCE_NAMESPACE
  28100. AudioProcessorEditor::AudioProcessorEditor (AudioProcessor* const owner_)
  28101. : owner (owner_)
  28102. {
  28103. // the filter must be valid..
  28104. jassert (owner != 0);
  28105. }
  28106. AudioProcessorEditor::~AudioProcessorEditor()
  28107. {
  28108. // if this fails, then the wrapper hasn't called editorBeingDeleted() on the
  28109. // filter for some reason..
  28110. jassert (owner->getActiveEditor() != this);
  28111. }
  28112. END_JUCE_NAMESPACE
  28113. /*** End of inlined file: juce_AudioProcessorEditor.cpp ***/
  28114. /*** Start of inlined file: juce_AudioProcessorGraph.cpp ***/
  28115. BEGIN_JUCE_NAMESPACE
  28116. const int AudioProcessorGraph::midiChannelIndex = 0x1000;
  28117. AudioProcessorGraph::Node::Node (const uint32 id_, AudioProcessor* const processor_)
  28118. : id (id_),
  28119. processor (processor_),
  28120. isPrepared (false)
  28121. {
  28122. jassert (processor_ != 0);
  28123. }
  28124. AudioProcessorGraph::Node::~Node()
  28125. {
  28126. delete processor;
  28127. }
  28128. void AudioProcessorGraph::Node::prepare (const double sampleRate, const int blockSize,
  28129. AudioProcessorGraph* const graph)
  28130. {
  28131. if (! isPrepared)
  28132. {
  28133. isPrepared = true;
  28134. AudioProcessorGraph::AudioGraphIOProcessor* const ioProc
  28135. = dynamic_cast <AudioProcessorGraph::AudioGraphIOProcessor*> (processor);
  28136. if (ioProc != 0)
  28137. ioProc->setParentGraph (graph);
  28138. processor->setPlayConfigDetails (processor->getNumInputChannels(),
  28139. processor->getNumOutputChannels(),
  28140. sampleRate, blockSize);
  28141. processor->prepareToPlay (sampleRate, blockSize);
  28142. }
  28143. }
  28144. void AudioProcessorGraph::Node::unprepare()
  28145. {
  28146. if (isPrepared)
  28147. {
  28148. isPrepared = false;
  28149. processor->releaseResources();
  28150. }
  28151. }
  28152. AudioProcessorGraph::AudioProcessorGraph()
  28153. : lastNodeId (0),
  28154. renderingBuffers (1, 1),
  28155. currentAudioOutputBuffer (1, 1)
  28156. {
  28157. }
  28158. AudioProcessorGraph::~AudioProcessorGraph()
  28159. {
  28160. clearRenderingSequence();
  28161. clear();
  28162. }
  28163. const String AudioProcessorGraph::getName() const
  28164. {
  28165. return "Audio Graph";
  28166. }
  28167. void AudioProcessorGraph::clear()
  28168. {
  28169. nodes.clear();
  28170. connections.clear();
  28171. triggerAsyncUpdate();
  28172. }
  28173. AudioProcessorGraph::Node* AudioProcessorGraph::getNodeForId (const uint32 nodeId) const
  28174. {
  28175. for (int i = nodes.size(); --i >= 0;)
  28176. if (nodes.getUnchecked(i)->id == nodeId)
  28177. return nodes.getUnchecked(i);
  28178. return 0;
  28179. }
  28180. AudioProcessorGraph::Node* AudioProcessorGraph::addNode (AudioProcessor* const newProcessor,
  28181. uint32 nodeId)
  28182. {
  28183. if (newProcessor == 0)
  28184. {
  28185. jassertfalse
  28186. return 0;
  28187. }
  28188. if (nodeId == 0)
  28189. {
  28190. nodeId = ++lastNodeId;
  28191. }
  28192. else
  28193. {
  28194. // you can't add a node with an id that already exists in the graph..
  28195. jassert (getNodeForId (nodeId) == 0);
  28196. removeNode (nodeId);
  28197. }
  28198. lastNodeId = nodeId;
  28199. Node* const n = new Node (nodeId, newProcessor);
  28200. nodes.add (n);
  28201. triggerAsyncUpdate();
  28202. AudioProcessorGraph::AudioGraphIOProcessor* const ioProc
  28203. = dynamic_cast <AudioProcessorGraph::AudioGraphIOProcessor*> (n->processor);
  28204. if (ioProc != 0)
  28205. ioProc->setParentGraph (this);
  28206. return n;
  28207. }
  28208. bool AudioProcessorGraph::removeNode (const uint32 nodeId)
  28209. {
  28210. disconnectNode (nodeId);
  28211. for (int i = nodes.size(); --i >= 0;)
  28212. {
  28213. if (nodes.getUnchecked(i)->id == nodeId)
  28214. {
  28215. AudioProcessorGraph::AudioGraphIOProcessor* const ioProc
  28216. = dynamic_cast <AudioProcessorGraph::AudioGraphIOProcessor*> (nodes.getUnchecked(i)->processor);
  28217. if (ioProc != 0)
  28218. ioProc->setParentGraph (0);
  28219. nodes.remove (i);
  28220. triggerAsyncUpdate();
  28221. return true;
  28222. }
  28223. }
  28224. return false;
  28225. }
  28226. const AudioProcessorGraph::Connection* AudioProcessorGraph::getConnectionBetween (const uint32 sourceNodeId,
  28227. const int sourceChannelIndex,
  28228. const uint32 destNodeId,
  28229. const int destChannelIndex) const
  28230. {
  28231. for (int i = connections.size(); --i >= 0;)
  28232. {
  28233. const Connection* const c = connections.getUnchecked(i);
  28234. if (c->sourceNodeId == sourceNodeId
  28235. && c->destNodeId == destNodeId
  28236. && c->sourceChannelIndex == sourceChannelIndex
  28237. && c->destChannelIndex == destChannelIndex)
  28238. {
  28239. return c;
  28240. }
  28241. }
  28242. return 0;
  28243. }
  28244. bool AudioProcessorGraph::isConnected (const uint32 possibleSourceNodeId,
  28245. const uint32 possibleDestNodeId) const
  28246. {
  28247. for (int i = connections.size(); --i >= 0;)
  28248. {
  28249. const Connection* const c = connections.getUnchecked(i);
  28250. if (c->sourceNodeId == possibleSourceNodeId
  28251. && c->destNodeId == possibleDestNodeId)
  28252. {
  28253. return true;
  28254. }
  28255. }
  28256. return false;
  28257. }
  28258. bool AudioProcessorGraph::canConnect (const uint32 sourceNodeId,
  28259. const int sourceChannelIndex,
  28260. const uint32 destNodeId,
  28261. const int destChannelIndex) const
  28262. {
  28263. if (sourceChannelIndex < 0
  28264. || destChannelIndex < 0
  28265. || sourceNodeId == destNodeId
  28266. || (destChannelIndex == midiChannelIndex) != (sourceChannelIndex == midiChannelIndex))
  28267. return false;
  28268. const Node* const source = getNodeForId (sourceNodeId);
  28269. if (source == 0
  28270. || (sourceChannelIndex != midiChannelIndex && sourceChannelIndex >= source->processor->getNumOutputChannels())
  28271. || (sourceChannelIndex == midiChannelIndex && ! source->processor->producesMidi()))
  28272. return false;
  28273. const Node* const dest = getNodeForId (destNodeId);
  28274. if (dest == 0
  28275. || (destChannelIndex != midiChannelIndex && destChannelIndex >= dest->processor->getNumInputChannels())
  28276. || (destChannelIndex == midiChannelIndex && ! dest->processor->acceptsMidi()))
  28277. return false;
  28278. return getConnectionBetween (sourceNodeId, sourceChannelIndex,
  28279. destNodeId, destChannelIndex) == 0;
  28280. }
  28281. bool AudioProcessorGraph::addConnection (const uint32 sourceNodeId,
  28282. const int sourceChannelIndex,
  28283. const uint32 destNodeId,
  28284. const int destChannelIndex)
  28285. {
  28286. if (! canConnect (sourceNodeId, sourceChannelIndex, destNodeId, destChannelIndex))
  28287. return false;
  28288. Connection* const c = new Connection();
  28289. c->sourceNodeId = sourceNodeId;
  28290. c->sourceChannelIndex = sourceChannelIndex;
  28291. c->destNodeId = destNodeId;
  28292. c->destChannelIndex = destChannelIndex;
  28293. connections.add (c);
  28294. triggerAsyncUpdate();
  28295. return true;
  28296. }
  28297. void AudioProcessorGraph::removeConnection (const int index)
  28298. {
  28299. connections.remove (index);
  28300. triggerAsyncUpdate();
  28301. }
  28302. bool AudioProcessorGraph::removeConnection (const uint32 sourceNodeId, const int sourceChannelIndex,
  28303. const uint32 destNodeId, const int destChannelIndex)
  28304. {
  28305. bool doneAnything = false;
  28306. for (int i = connections.size(); --i >= 0;)
  28307. {
  28308. const Connection* const c = connections.getUnchecked(i);
  28309. if (c->sourceNodeId == sourceNodeId
  28310. && c->destNodeId == destNodeId
  28311. && c->sourceChannelIndex == sourceChannelIndex
  28312. && c->destChannelIndex == destChannelIndex)
  28313. {
  28314. removeConnection (i);
  28315. doneAnything = true;
  28316. triggerAsyncUpdate();
  28317. }
  28318. }
  28319. return doneAnything;
  28320. }
  28321. bool AudioProcessorGraph::disconnectNode (const uint32 nodeId)
  28322. {
  28323. bool doneAnything = false;
  28324. for (int i = connections.size(); --i >= 0;)
  28325. {
  28326. const Connection* const c = connections.getUnchecked(i);
  28327. if (c->sourceNodeId == nodeId || c->destNodeId == nodeId)
  28328. {
  28329. removeConnection (i);
  28330. doneAnything = true;
  28331. triggerAsyncUpdate();
  28332. }
  28333. }
  28334. return doneAnything;
  28335. }
  28336. bool AudioProcessorGraph::removeIllegalConnections()
  28337. {
  28338. bool doneAnything = false;
  28339. for (int i = connections.size(); --i >= 0;)
  28340. {
  28341. const Connection* const c = connections.getUnchecked(i);
  28342. const Node* const source = getNodeForId (c->sourceNodeId);
  28343. const Node* const dest = getNodeForId (c->destNodeId);
  28344. if (source == 0 || dest == 0
  28345. || (c->sourceChannelIndex != midiChannelIndex
  28346. && (((unsigned int) c->sourceChannelIndex) >= (unsigned int) source->processor->getNumOutputChannels()))
  28347. || (c->sourceChannelIndex == midiChannelIndex
  28348. && ! source->processor->producesMidi())
  28349. || (c->destChannelIndex != midiChannelIndex
  28350. && (((unsigned int) c->destChannelIndex) >= (unsigned int) dest->processor->getNumInputChannels()))
  28351. || (c->destChannelIndex == midiChannelIndex
  28352. && ! dest->processor->acceptsMidi()))
  28353. {
  28354. removeConnection (i);
  28355. doneAnything = true;
  28356. triggerAsyncUpdate();
  28357. }
  28358. }
  28359. return doneAnything;
  28360. }
  28361. namespace GraphRenderingOps
  28362. {
  28363. class AudioGraphRenderingOp
  28364. {
  28365. public:
  28366. AudioGraphRenderingOp() {}
  28367. virtual ~AudioGraphRenderingOp() {}
  28368. virtual void perform (AudioSampleBuffer& sharedBufferChans,
  28369. const OwnedArray <MidiBuffer>& sharedMidiBuffers,
  28370. const int numSamples) = 0;
  28371. juce_UseDebuggingNewOperator
  28372. };
  28373. class ClearChannelOp : public AudioGraphRenderingOp
  28374. {
  28375. public:
  28376. ClearChannelOp (const int channelNum_)
  28377. : channelNum (channelNum_)
  28378. {}
  28379. ~ClearChannelOp() {}
  28380. void perform (AudioSampleBuffer& sharedBufferChans, const OwnedArray <MidiBuffer>&, const int numSamples)
  28381. {
  28382. sharedBufferChans.clear (channelNum, 0, numSamples);
  28383. }
  28384. private:
  28385. const int channelNum;
  28386. ClearChannelOp (const ClearChannelOp&);
  28387. const ClearChannelOp& operator= (const ClearChannelOp&);
  28388. };
  28389. class CopyChannelOp : public AudioGraphRenderingOp
  28390. {
  28391. public:
  28392. CopyChannelOp (const int srcChannelNum_, const int dstChannelNum_)
  28393. : srcChannelNum (srcChannelNum_),
  28394. dstChannelNum (dstChannelNum_)
  28395. {}
  28396. ~CopyChannelOp() {}
  28397. void perform (AudioSampleBuffer& sharedBufferChans, const OwnedArray <MidiBuffer>&, const int numSamples)
  28398. {
  28399. sharedBufferChans.copyFrom (dstChannelNum, 0, sharedBufferChans, srcChannelNum, 0, numSamples);
  28400. }
  28401. private:
  28402. const int srcChannelNum, dstChannelNum;
  28403. CopyChannelOp (const CopyChannelOp&);
  28404. const CopyChannelOp& operator= (const CopyChannelOp&);
  28405. };
  28406. class AddChannelOp : public AudioGraphRenderingOp
  28407. {
  28408. public:
  28409. AddChannelOp (const int srcChannelNum_, const int dstChannelNum_)
  28410. : srcChannelNum (srcChannelNum_),
  28411. dstChannelNum (dstChannelNum_)
  28412. {}
  28413. ~AddChannelOp() {}
  28414. void perform (AudioSampleBuffer& sharedBufferChans, const OwnedArray <MidiBuffer>&, const int numSamples)
  28415. {
  28416. sharedBufferChans.addFrom (dstChannelNum, 0, sharedBufferChans, srcChannelNum, 0, numSamples);
  28417. }
  28418. private:
  28419. const int srcChannelNum, dstChannelNum;
  28420. AddChannelOp (const AddChannelOp&);
  28421. const AddChannelOp& operator= (const AddChannelOp&);
  28422. };
  28423. class ClearMidiBufferOp : public AudioGraphRenderingOp
  28424. {
  28425. public:
  28426. ClearMidiBufferOp (const int bufferNum_)
  28427. : bufferNum (bufferNum_)
  28428. {}
  28429. ~ClearMidiBufferOp() {}
  28430. void perform (AudioSampleBuffer&, const OwnedArray <MidiBuffer>& sharedMidiBuffers, const int)
  28431. {
  28432. sharedMidiBuffers.getUnchecked (bufferNum)->clear();
  28433. }
  28434. private:
  28435. const int bufferNum;
  28436. ClearMidiBufferOp (const ClearMidiBufferOp&);
  28437. const ClearMidiBufferOp& operator= (const ClearMidiBufferOp&);
  28438. };
  28439. class CopyMidiBufferOp : public AudioGraphRenderingOp
  28440. {
  28441. public:
  28442. CopyMidiBufferOp (const int srcBufferNum_, const int dstBufferNum_)
  28443. : srcBufferNum (srcBufferNum_),
  28444. dstBufferNum (dstBufferNum_)
  28445. {}
  28446. ~CopyMidiBufferOp() {}
  28447. void perform (AudioSampleBuffer&, const OwnedArray <MidiBuffer>& sharedMidiBuffers, const int)
  28448. {
  28449. *sharedMidiBuffers.getUnchecked (dstBufferNum) = *sharedMidiBuffers.getUnchecked (srcBufferNum);
  28450. }
  28451. private:
  28452. const int srcBufferNum, dstBufferNum;
  28453. CopyMidiBufferOp (const CopyMidiBufferOp&);
  28454. const CopyMidiBufferOp& operator= (const CopyMidiBufferOp&);
  28455. };
  28456. class AddMidiBufferOp : public AudioGraphRenderingOp
  28457. {
  28458. public:
  28459. AddMidiBufferOp (const int srcBufferNum_, const int dstBufferNum_)
  28460. : srcBufferNum (srcBufferNum_),
  28461. dstBufferNum (dstBufferNum_)
  28462. {}
  28463. ~AddMidiBufferOp() {}
  28464. void perform (AudioSampleBuffer&, const OwnedArray <MidiBuffer>& sharedMidiBuffers, const int numSamples)
  28465. {
  28466. sharedMidiBuffers.getUnchecked (dstBufferNum)
  28467. ->addEvents (*sharedMidiBuffers.getUnchecked (srcBufferNum), 0, numSamples, 0);
  28468. }
  28469. private:
  28470. const int srcBufferNum, dstBufferNum;
  28471. AddMidiBufferOp (const AddMidiBufferOp&);
  28472. const AddMidiBufferOp& operator= (const AddMidiBufferOp&);
  28473. };
  28474. class ProcessBufferOp : public AudioGraphRenderingOp
  28475. {
  28476. public:
  28477. ProcessBufferOp (const AudioProcessorGraph::Node::Ptr& node_,
  28478. const Array <int>& audioChannelsToUse_,
  28479. const int totalChans_,
  28480. const int midiBufferToUse_)
  28481. : node (node_),
  28482. processor (node_->processor),
  28483. audioChannelsToUse (audioChannelsToUse_),
  28484. totalChans (jmax (1, totalChans_)),
  28485. midiBufferToUse (midiBufferToUse_)
  28486. {
  28487. channels.calloc (totalChans);
  28488. while (audioChannelsToUse.size() < totalChans)
  28489. audioChannelsToUse.add (0);
  28490. }
  28491. ~ProcessBufferOp()
  28492. {
  28493. }
  28494. void perform (AudioSampleBuffer& sharedBufferChans, const OwnedArray <MidiBuffer>& sharedMidiBuffers, const int numSamples)
  28495. {
  28496. for (int i = totalChans; --i >= 0;)
  28497. channels[i] = sharedBufferChans.getSampleData (audioChannelsToUse.getUnchecked (i), 0);
  28498. AudioSampleBuffer buffer (channels, totalChans, numSamples);
  28499. processor->processBlock (buffer, *sharedMidiBuffers.getUnchecked (midiBufferToUse));
  28500. }
  28501. const AudioProcessorGraph::Node::Ptr node;
  28502. AudioProcessor* const processor;
  28503. private:
  28504. Array <int> audioChannelsToUse;
  28505. HeapBlock <float*> channels;
  28506. int totalChans;
  28507. int midiBufferToUse;
  28508. ProcessBufferOp (const ProcessBufferOp&);
  28509. const ProcessBufferOp& operator= (const ProcessBufferOp&);
  28510. };
  28511. class RenderingOpSequenceCalculator
  28512. {
  28513. public:
  28514. RenderingOpSequenceCalculator (AudioProcessorGraph& graph_,
  28515. const VoidArray& orderedNodes_,
  28516. VoidArray& renderingOps)
  28517. : graph (graph_),
  28518. orderedNodes (orderedNodes_)
  28519. {
  28520. nodeIds.add (-2); // first buffer is read-only zeros
  28521. channels.add (0);
  28522. midiNodeIds.add (-2);
  28523. for (int i = 0; i < orderedNodes.size(); ++i)
  28524. {
  28525. createRenderingOpsForNode ((AudioProcessorGraph::Node*) orderedNodes.getUnchecked(i),
  28526. renderingOps, i);
  28527. markAnyUnusedBuffersAsFree (i);
  28528. }
  28529. }
  28530. int getNumBuffersNeeded() const { return nodeIds.size(); }
  28531. int getNumMidiBuffersNeeded() const { return midiNodeIds.size(); }
  28532. juce_UseDebuggingNewOperator
  28533. private:
  28534. AudioProcessorGraph& graph;
  28535. const VoidArray& orderedNodes;
  28536. Array <int> nodeIds, channels, midiNodeIds;
  28537. void createRenderingOpsForNode (AudioProcessorGraph::Node* const node,
  28538. VoidArray& renderingOps,
  28539. const int ourRenderingIndex)
  28540. {
  28541. const int numIns = node->processor->getNumInputChannels();
  28542. const int numOuts = node->processor->getNumOutputChannels();
  28543. const int totalChans = jmax (numIns, numOuts);
  28544. Array <int> audioChannelsToUse;
  28545. int midiBufferToUse = -1;
  28546. for (int inputChan = 0; inputChan < numIns; ++inputChan)
  28547. {
  28548. // get a list of all the inputs to this node
  28549. Array <int> sourceNodes, sourceOutputChans;
  28550. for (int i = graph.getNumConnections(); --i >= 0;)
  28551. {
  28552. const AudioProcessorGraph::Connection* const c = graph.getConnection (i);
  28553. if (c->destNodeId == node->id && c->destChannelIndex == inputChan)
  28554. {
  28555. sourceNodes.add (c->sourceNodeId);
  28556. sourceOutputChans.add (c->sourceChannelIndex);
  28557. }
  28558. }
  28559. int bufIndex = -1;
  28560. if (sourceNodes.size() == 0)
  28561. {
  28562. // unconnected input channel
  28563. if (inputChan >= numOuts)
  28564. {
  28565. bufIndex = getReadOnlyEmptyBuffer();
  28566. jassert (bufIndex >= 0);
  28567. }
  28568. else
  28569. {
  28570. bufIndex = getFreeBuffer (false);
  28571. renderingOps.add (new ClearChannelOp (bufIndex));
  28572. }
  28573. }
  28574. else if (sourceNodes.size() == 1)
  28575. {
  28576. // channel with a straightforward single input..
  28577. const int srcNode = sourceNodes.getUnchecked(0);
  28578. const int srcChan = sourceOutputChans.getUnchecked(0);
  28579. bufIndex = getBufferContaining (srcNode, srcChan);
  28580. if (bufIndex < 0)
  28581. {
  28582. // if not found, this is probably a feedback loop
  28583. bufIndex = getReadOnlyEmptyBuffer();
  28584. jassert (bufIndex >= 0);
  28585. }
  28586. if (inputChan < numOuts
  28587. && isBufferNeededLater (ourRenderingIndex,
  28588. inputChan,
  28589. srcNode, srcChan))
  28590. {
  28591. // can't mess up this channel because it's needed later by another node, so we
  28592. // need to use a copy of it..
  28593. const int newFreeBuffer = getFreeBuffer (false);
  28594. renderingOps.add (new CopyChannelOp (bufIndex, newFreeBuffer));
  28595. bufIndex = newFreeBuffer;
  28596. }
  28597. }
  28598. else
  28599. {
  28600. // channel with a mix of several inputs..
  28601. // try to find a re-usable channel from our inputs..
  28602. int reusableInputIndex = -1;
  28603. for (int i = 0; i < sourceNodes.size(); ++i)
  28604. {
  28605. const int sourceBufIndex = getBufferContaining (sourceNodes.getUnchecked(i),
  28606. sourceOutputChans.getUnchecked(i));
  28607. if (sourceBufIndex >= 0
  28608. && ! isBufferNeededLater (ourRenderingIndex,
  28609. inputChan,
  28610. sourceNodes.getUnchecked(i),
  28611. sourceOutputChans.getUnchecked(i)))
  28612. {
  28613. // we've found one of our input chans that can be re-used..
  28614. reusableInputIndex = i;
  28615. bufIndex = sourceBufIndex;
  28616. break;
  28617. }
  28618. }
  28619. if (reusableInputIndex < 0)
  28620. {
  28621. // can't re-use any of our input chans, so get a new one and copy everything into it..
  28622. bufIndex = getFreeBuffer (false);
  28623. jassert (bufIndex != 0);
  28624. const int srcIndex = getBufferContaining (sourceNodes.getUnchecked (0),
  28625. sourceOutputChans.getUnchecked (0));
  28626. if (srcIndex < 0)
  28627. {
  28628. // if not found, this is probably a feedback loop
  28629. renderingOps.add (new ClearChannelOp (bufIndex));
  28630. }
  28631. else
  28632. {
  28633. renderingOps.add (new CopyChannelOp (srcIndex, bufIndex));
  28634. }
  28635. reusableInputIndex = 0;
  28636. }
  28637. for (int j = 0; j < sourceNodes.size(); ++j)
  28638. {
  28639. if (j != reusableInputIndex)
  28640. {
  28641. const int srcIndex = getBufferContaining (sourceNodes.getUnchecked(j),
  28642. sourceOutputChans.getUnchecked(j));
  28643. if (srcIndex >= 0)
  28644. renderingOps.add (new AddChannelOp (srcIndex, bufIndex));
  28645. }
  28646. }
  28647. }
  28648. jassert (bufIndex >= 0);
  28649. audioChannelsToUse.add (bufIndex);
  28650. if (inputChan < numOuts)
  28651. markBufferAsContaining (bufIndex, node->id, inputChan);
  28652. }
  28653. for (int outputChan = numIns; outputChan < numOuts; ++outputChan)
  28654. {
  28655. const int bufIndex = getFreeBuffer (false);
  28656. jassert (bufIndex != 0);
  28657. audioChannelsToUse.add (bufIndex);
  28658. markBufferAsContaining (bufIndex, node->id, outputChan);
  28659. }
  28660. // Now the same thing for midi..
  28661. Array <int> midiSourceNodes;
  28662. for (int i = graph.getNumConnections(); --i >= 0;)
  28663. {
  28664. const AudioProcessorGraph::Connection* const c = graph.getConnection (i);
  28665. if (c->destNodeId == node->id && c->destChannelIndex == AudioProcessorGraph::midiChannelIndex)
  28666. midiSourceNodes.add (c->sourceNodeId);
  28667. }
  28668. if (midiSourceNodes.size() == 0)
  28669. {
  28670. // No midi inputs..
  28671. midiBufferToUse = getFreeBuffer (true); // need to pick a buffer even if the processor doesn't use midi
  28672. if (node->processor->acceptsMidi() || node->processor->producesMidi())
  28673. renderingOps.add (new ClearMidiBufferOp (midiBufferToUse));
  28674. }
  28675. else if (midiSourceNodes.size() == 1)
  28676. {
  28677. // One midi input..
  28678. midiBufferToUse = getBufferContaining (midiSourceNodes.getUnchecked(0),
  28679. AudioProcessorGraph::midiChannelIndex);
  28680. if (midiBufferToUse >= 0)
  28681. {
  28682. if (isBufferNeededLater (ourRenderingIndex,
  28683. AudioProcessorGraph::midiChannelIndex,
  28684. midiSourceNodes.getUnchecked(0),
  28685. AudioProcessorGraph::midiChannelIndex))
  28686. {
  28687. // can't mess up this channel because it's needed later by another node, so we
  28688. // need to use a copy of it..
  28689. const int newFreeBuffer = getFreeBuffer (true);
  28690. renderingOps.add (new CopyMidiBufferOp (midiBufferToUse, newFreeBuffer));
  28691. midiBufferToUse = newFreeBuffer;
  28692. }
  28693. }
  28694. else
  28695. {
  28696. // probably a feedback loop, so just use an empty one..
  28697. midiBufferToUse = getFreeBuffer (true); // need to pick a buffer even if the processor doesn't use midi
  28698. }
  28699. }
  28700. else
  28701. {
  28702. // More than one midi input being mixed..
  28703. int reusableInputIndex = -1;
  28704. for (int i = 0; i < midiSourceNodes.size(); ++i)
  28705. {
  28706. const int sourceBufIndex = getBufferContaining (midiSourceNodes.getUnchecked(i),
  28707. AudioProcessorGraph::midiChannelIndex);
  28708. if (sourceBufIndex >= 0
  28709. && ! isBufferNeededLater (ourRenderingIndex,
  28710. AudioProcessorGraph::midiChannelIndex,
  28711. midiSourceNodes.getUnchecked(i),
  28712. AudioProcessorGraph::midiChannelIndex))
  28713. {
  28714. // we've found one of our input buffers that can be re-used..
  28715. reusableInputIndex = i;
  28716. midiBufferToUse = sourceBufIndex;
  28717. break;
  28718. }
  28719. }
  28720. if (reusableInputIndex < 0)
  28721. {
  28722. // can't re-use any of our input buffers, so get a new one and copy everything into it..
  28723. midiBufferToUse = getFreeBuffer (true);
  28724. jassert (midiBufferToUse >= 0);
  28725. const int srcIndex = getBufferContaining (midiSourceNodes.getUnchecked(0),
  28726. AudioProcessorGraph::midiChannelIndex);
  28727. if (srcIndex >= 0)
  28728. renderingOps.add (new CopyMidiBufferOp (srcIndex, midiBufferToUse));
  28729. else
  28730. renderingOps.add (new ClearMidiBufferOp (midiBufferToUse));
  28731. reusableInputIndex = 0;
  28732. }
  28733. for (int j = 0; j < midiSourceNodes.size(); ++j)
  28734. {
  28735. if (j != reusableInputIndex)
  28736. {
  28737. const int srcIndex = getBufferContaining (midiSourceNodes.getUnchecked(j),
  28738. AudioProcessorGraph::midiChannelIndex);
  28739. if (srcIndex >= 0)
  28740. renderingOps.add (new AddMidiBufferOp (srcIndex, midiBufferToUse));
  28741. }
  28742. }
  28743. }
  28744. if (node->processor->producesMidi())
  28745. markBufferAsContaining (midiBufferToUse, node->id,
  28746. AudioProcessorGraph::midiChannelIndex);
  28747. renderingOps.add (new ProcessBufferOp (node, audioChannelsToUse,
  28748. totalChans, midiBufferToUse));
  28749. }
  28750. int getFreeBuffer (const bool forMidi)
  28751. {
  28752. if (forMidi)
  28753. {
  28754. for (int i = 1; i < midiNodeIds.size(); ++i)
  28755. if (midiNodeIds.getUnchecked(i) < 0)
  28756. return i;
  28757. midiNodeIds.add (-1);
  28758. return midiNodeIds.size() - 1;
  28759. }
  28760. else
  28761. {
  28762. for (int i = 1; i < nodeIds.size(); ++i)
  28763. if (nodeIds.getUnchecked(i) < 0)
  28764. return i;
  28765. nodeIds.add (-1);
  28766. channels.add (0);
  28767. return nodeIds.size() - 1;
  28768. }
  28769. }
  28770. int getReadOnlyEmptyBuffer() const
  28771. {
  28772. return 0;
  28773. }
  28774. int getBufferContaining (const int nodeId, const int outputChannel) const
  28775. {
  28776. if (outputChannel == AudioProcessorGraph::midiChannelIndex)
  28777. {
  28778. for (int i = midiNodeIds.size(); --i >= 0;)
  28779. if (midiNodeIds.getUnchecked(i) == nodeId)
  28780. return i;
  28781. }
  28782. else
  28783. {
  28784. for (int i = nodeIds.size(); --i >= 0;)
  28785. if (nodeIds.getUnchecked(i) == nodeId
  28786. && channels.getUnchecked(i) == outputChannel)
  28787. return i;
  28788. }
  28789. return -1;
  28790. }
  28791. void markAnyUnusedBuffersAsFree (const int stepIndex)
  28792. {
  28793. int i;
  28794. for (i = 0; i < nodeIds.size(); ++i)
  28795. {
  28796. if (nodeIds.getUnchecked(i) >= 0
  28797. && ! isBufferNeededLater (stepIndex, -1,
  28798. nodeIds.getUnchecked(i),
  28799. channels.getUnchecked(i)))
  28800. {
  28801. nodeIds.set (i, -1);
  28802. }
  28803. }
  28804. for (i = 0; i < midiNodeIds.size(); ++i)
  28805. {
  28806. if (midiNodeIds.getUnchecked(i) >= 0
  28807. && ! isBufferNeededLater (stepIndex, -1,
  28808. midiNodeIds.getUnchecked(i),
  28809. AudioProcessorGraph::midiChannelIndex))
  28810. {
  28811. midiNodeIds.set (i, -1);
  28812. }
  28813. }
  28814. }
  28815. bool isBufferNeededLater (int stepIndexToSearchFrom,
  28816. int inputChannelOfIndexToIgnore,
  28817. const int nodeId,
  28818. const int outputChanIndex) const
  28819. {
  28820. while (stepIndexToSearchFrom < orderedNodes.size())
  28821. {
  28822. const AudioProcessorGraph::Node* const node = (const AudioProcessorGraph::Node*) orderedNodes.getUnchecked (stepIndexToSearchFrom);
  28823. if (outputChanIndex == AudioProcessorGraph::midiChannelIndex)
  28824. {
  28825. if (inputChannelOfIndexToIgnore != AudioProcessorGraph::midiChannelIndex
  28826. && graph.getConnectionBetween (nodeId, AudioProcessorGraph::midiChannelIndex,
  28827. node->id, AudioProcessorGraph::midiChannelIndex) != 0)
  28828. return true;
  28829. }
  28830. else
  28831. {
  28832. for (int i = 0; i < node->processor->getNumInputChannels(); ++i)
  28833. if (i != inputChannelOfIndexToIgnore
  28834. && graph.getConnectionBetween (nodeId, outputChanIndex,
  28835. node->id, i) != 0)
  28836. return true;
  28837. }
  28838. inputChannelOfIndexToIgnore = -1;
  28839. ++stepIndexToSearchFrom;
  28840. }
  28841. return false;
  28842. }
  28843. void markBufferAsContaining (int bufferNum, int nodeId, int outputIndex)
  28844. {
  28845. if (outputIndex == AudioProcessorGraph::midiChannelIndex)
  28846. {
  28847. jassert (bufferNum > 0 && bufferNum < midiNodeIds.size());
  28848. midiNodeIds.set (bufferNum, nodeId);
  28849. }
  28850. else
  28851. {
  28852. jassert (bufferNum >= 0 && bufferNum < nodeIds.size());
  28853. nodeIds.set (bufferNum, nodeId);
  28854. channels.set (bufferNum, outputIndex);
  28855. }
  28856. }
  28857. RenderingOpSequenceCalculator (const RenderingOpSequenceCalculator&);
  28858. const RenderingOpSequenceCalculator& operator= (const RenderingOpSequenceCalculator&);
  28859. };
  28860. }
  28861. void AudioProcessorGraph::clearRenderingSequence()
  28862. {
  28863. const ScopedLock sl (renderLock);
  28864. for (int i = renderingOps.size(); --i >= 0;)
  28865. {
  28866. GraphRenderingOps::AudioGraphRenderingOp* const r
  28867. = (GraphRenderingOps::AudioGraphRenderingOp*) renderingOps.getUnchecked(i);
  28868. renderingOps.remove (i);
  28869. delete r;
  28870. }
  28871. }
  28872. bool AudioProcessorGraph::isAnInputTo (const uint32 possibleInputId,
  28873. const uint32 possibleDestinationId,
  28874. const int recursionCheck) const
  28875. {
  28876. if (recursionCheck > 0)
  28877. {
  28878. for (int i = connections.size(); --i >= 0;)
  28879. {
  28880. const AudioProcessorGraph::Connection* const c = connections.getUnchecked (i);
  28881. if (c->destNodeId == possibleDestinationId
  28882. && (c->sourceNodeId == possibleInputId
  28883. || isAnInputTo (possibleInputId, c->sourceNodeId, recursionCheck - 1)))
  28884. return true;
  28885. }
  28886. }
  28887. return false;
  28888. }
  28889. void AudioProcessorGraph::buildRenderingSequence()
  28890. {
  28891. VoidArray newRenderingOps;
  28892. int numRenderingBuffersNeeded = 2;
  28893. int numMidiBuffersNeeded = 1;
  28894. {
  28895. MessageManagerLock mml;
  28896. VoidArray orderedNodes;
  28897. int i;
  28898. for (i = 0; i < nodes.size(); ++i)
  28899. {
  28900. Node* const node = nodes.getUnchecked(i);
  28901. node->prepare (getSampleRate(), getBlockSize(), this);
  28902. int j = 0;
  28903. for (; j < orderedNodes.size(); ++j)
  28904. if (isAnInputTo (node->id,
  28905. ((Node*) orderedNodes.getUnchecked (j))->id,
  28906. nodes.size() + 1))
  28907. break;
  28908. orderedNodes.insert (j, node);
  28909. }
  28910. GraphRenderingOps::RenderingOpSequenceCalculator calculator (*this, orderedNodes, newRenderingOps);
  28911. numRenderingBuffersNeeded = calculator.getNumBuffersNeeded();
  28912. numMidiBuffersNeeded = calculator.getNumMidiBuffersNeeded();
  28913. }
  28914. VoidArray oldRenderingOps (renderingOps);
  28915. {
  28916. // swap over to the new rendering sequence..
  28917. const ScopedLock sl (renderLock);
  28918. renderingBuffers.setSize (numRenderingBuffersNeeded, getBlockSize());
  28919. renderingBuffers.clear();
  28920. for (int i = midiBuffers.size(); --i >= 0;)
  28921. midiBuffers.getUnchecked(i)->clear();
  28922. while (midiBuffers.size() < numMidiBuffersNeeded)
  28923. midiBuffers.add (new MidiBuffer());
  28924. renderingOps = newRenderingOps;
  28925. }
  28926. for (int i = oldRenderingOps.size(); --i >= 0;)
  28927. delete (GraphRenderingOps::AudioGraphRenderingOp*) oldRenderingOps.getUnchecked(i);
  28928. }
  28929. void AudioProcessorGraph::handleAsyncUpdate()
  28930. {
  28931. buildRenderingSequence();
  28932. }
  28933. void AudioProcessorGraph::prepareToPlay (double /*sampleRate*/, int estimatedSamplesPerBlock)
  28934. {
  28935. currentAudioInputBuffer = 0;
  28936. currentAudioOutputBuffer.setSize (jmax (1, getNumOutputChannels()), estimatedSamplesPerBlock);
  28937. currentMidiInputBuffer = 0;
  28938. currentMidiOutputBuffer.clear();
  28939. clearRenderingSequence();
  28940. buildRenderingSequence();
  28941. }
  28942. void AudioProcessorGraph::releaseResources()
  28943. {
  28944. for (int i = 0; i < nodes.size(); ++i)
  28945. nodes.getUnchecked(i)->unprepare();
  28946. renderingBuffers.setSize (1, 1);
  28947. midiBuffers.clear();
  28948. currentAudioInputBuffer = 0;
  28949. currentAudioOutputBuffer.setSize (1, 1);
  28950. currentMidiInputBuffer = 0;
  28951. currentMidiOutputBuffer.clear();
  28952. }
  28953. void AudioProcessorGraph::processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages)
  28954. {
  28955. const int numSamples = buffer.getNumSamples();
  28956. const ScopedLock sl (renderLock);
  28957. currentAudioInputBuffer = &buffer;
  28958. currentAudioOutputBuffer.setSize (jmax (1, buffer.getNumChannels()), numSamples);
  28959. currentAudioOutputBuffer.clear();
  28960. currentMidiInputBuffer = &midiMessages;
  28961. currentMidiOutputBuffer.clear();
  28962. int i;
  28963. for (i = 0; i < renderingOps.size(); ++i)
  28964. {
  28965. GraphRenderingOps::AudioGraphRenderingOp* const op
  28966. = (GraphRenderingOps::AudioGraphRenderingOp*) renderingOps.getUnchecked(i);
  28967. op->perform (renderingBuffers, midiBuffers, numSamples);
  28968. }
  28969. for (i = 0; i < buffer.getNumChannels(); ++i)
  28970. buffer.copyFrom (i, 0, currentAudioOutputBuffer, i, 0, numSamples);
  28971. midiMessages.clear();
  28972. midiMessages.addEvents (currentMidiOutputBuffer, 0, buffer.getNumSamples(), 0);
  28973. }
  28974. const String AudioProcessorGraph::getInputChannelName (const int channelIndex) const
  28975. {
  28976. return "Input " + String (channelIndex + 1);
  28977. }
  28978. const String AudioProcessorGraph::getOutputChannelName (const int channelIndex) const
  28979. {
  28980. return "Output " + String (channelIndex + 1);
  28981. }
  28982. bool AudioProcessorGraph::isInputChannelStereoPair (int /*index*/) const
  28983. {
  28984. return true;
  28985. }
  28986. bool AudioProcessorGraph::isOutputChannelStereoPair (int /*index*/) const
  28987. {
  28988. return true;
  28989. }
  28990. bool AudioProcessorGraph::acceptsMidi() const
  28991. {
  28992. return true;
  28993. }
  28994. bool AudioProcessorGraph::producesMidi() const
  28995. {
  28996. return true;
  28997. }
  28998. void AudioProcessorGraph::getStateInformation (JUCE_NAMESPACE::MemoryBlock& /*destData*/)
  28999. {
  29000. }
  29001. void AudioProcessorGraph::setStateInformation (const void* /*data*/, int /*sizeInBytes*/)
  29002. {
  29003. }
  29004. AudioProcessorGraph::AudioGraphIOProcessor::AudioGraphIOProcessor (const IODeviceType type_)
  29005. : type (type_),
  29006. graph (0)
  29007. {
  29008. }
  29009. AudioProcessorGraph::AudioGraphIOProcessor::~AudioGraphIOProcessor()
  29010. {
  29011. }
  29012. const String AudioProcessorGraph::AudioGraphIOProcessor::getName() const
  29013. {
  29014. switch (type)
  29015. {
  29016. case audioOutputNode:
  29017. return "Audio Output";
  29018. case audioInputNode:
  29019. return "Audio Input";
  29020. case midiOutputNode:
  29021. return "Midi Output";
  29022. case midiInputNode:
  29023. return "Midi Input";
  29024. default:
  29025. break;
  29026. }
  29027. return String::empty;
  29028. }
  29029. void AudioProcessorGraph::AudioGraphIOProcessor::fillInPluginDescription (PluginDescription& d) const
  29030. {
  29031. d.name = getName();
  29032. d.uid = d.name.hashCode();
  29033. d.category = "I/O devices";
  29034. d.pluginFormatName = "Internal";
  29035. d.manufacturerName = "Raw Material Software";
  29036. d.version = "1.0";
  29037. d.isInstrument = false;
  29038. d.numInputChannels = getNumInputChannels();
  29039. if (type == audioOutputNode && graph != 0)
  29040. d.numInputChannels = graph->getNumInputChannels();
  29041. d.numOutputChannels = getNumOutputChannels();
  29042. if (type == audioInputNode && graph != 0)
  29043. d.numOutputChannels = graph->getNumOutputChannels();
  29044. }
  29045. void AudioProcessorGraph::AudioGraphIOProcessor::prepareToPlay (double, int)
  29046. {
  29047. jassert (graph != 0);
  29048. }
  29049. void AudioProcessorGraph::AudioGraphIOProcessor::releaseResources()
  29050. {
  29051. }
  29052. void AudioProcessorGraph::AudioGraphIOProcessor::processBlock (AudioSampleBuffer& buffer,
  29053. MidiBuffer& midiMessages)
  29054. {
  29055. jassert (graph != 0);
  29056. switch (type)
  29057. {
  29058. case audioOutputNode:
  29059. {
  29060. for (int i = jmin (graph->currentAudioOutputBuffer.getNumChannels(),
  29061. buffer.getNumChannels()); --i >= 0;)
  29062. {
  29063. graph->currentAudioOutputBuffer.addFrom (i, 0, buffer, i, 0, buffer.getNumSamples());
  29064. }
  29065. break;
  29066. }
  29067. case audioInputNode:
  29068. {
  29069. for (int i = jmin (graph->currentAudioInputBuffer->getNumChannels(),
  29070. buffer.getNumChannels()); --i >= 0;)
  29071. {
  29072. buffer.copyFrom (i, 0, *graph->currentAudioInputBuffer, i, 0, buffer.getNumSamples());
  29073. }
  29074. break;
  29075. }
  29076. case midiOutputNode:
  29077. graph->currentMidiOutputBuffer.addEvents (midiMessages, 0, buffer.getNumSamples(), 0);
  29078. break;
  29079. case midiInputNode:
  29080. midiMessages.addEvents (*graph->currentMidiInputBuffer, 0, buffer.getNumSamples(), 0);
  29081. break;
  29082. default:
  29083. break;
  29084. }
  29085. }
  29086. bool AudioProcessorGraph::AudioGraphIOProcessor::acceptsMidi() const
  29087. {
  29088. return type == midiOutputNode;
  29089. }
  29090. bool AudioProcessorGraph::AudioGraphIOProcessor::producesMidi() const
  29091. {
  29092. return type == midiInputNode;
  29093. }
  29094. const String AudioProcessorGraph::AudioGraphIOProcessor::getInputChannelName (const int channelIndex) const
  29095. {
  29096. switch (type)
  29097. {
  29098. case audioOutputNode:
  29099. return "Output " + String (channelIndex + 1);
  29100. case midiOutputNode:
  29101. return "Midi Output";
  29102. default:
  29103. break;
  29104. }
  29105. return String::empty;
  29106. }
  29107. const String AudioProcessorGraph::AudioGraphIOProcessor::getOutputChannelName (const int channelIndex) const
  29108. {
  29109. switch (type)
  29110. {
  29111. case audioInputNode:
  29112. return "Input " + String (channelIndex + 1);
  29113. case midiInputNode:
  29114. return "Midi Input";
  29115. default:
  29116. break;
  29117. }
  29118. return String::empty;
  29119. }
  29120. bool AudioProcessorGraph::AudioGraphIOProcessor::isInputChannelStereoPair (int /*index*/) const
  29121. {
  29122. return type == audioInputNode || type == audioOutputNode;
  29123. }
  29124. bool AudioProcessorGraph::AudioGraphIOProcessor::isOutputChannelStereoPair (int index) const
  29125. {
  29126. return isInputChannelStereoPair (index);
  29127. }
  29128. bool AudioProcessorGraph::AudioGraphIOProcessor::isInput() const
  29129. {
  29130. return type == audioInputNode || type == midiInputNode;
  29131. }
  29132. bool AudioProcessorGraph::AudioGraphIOProcessor::isOutput() const
  29133. {
  29134. return type == audioOutputNode || type == midiOutputNode;
  29135. }
  29136. AudioProcessorEditor* AudioProcessorGraph::AudioGraphIOProcessor::createEditor()
  29137. {
  29138. return 0;
  29139. }
  29140. int AudioProcessorGraph::AudioGraphIOProcessor::getNumParameters() { return 0; }
  29141. const String AudioProcessorGraph::AudioGraphIOProcessor::getParameterName (int) { return String::empty; }
  29142. float AudioProcessorGraph::AudioGraphIOProcessor::getParameter (int) { return 0.0f; }
  29143. const String AudioProcessorGraph::AudioGraphIOProcessor::getParameterText (int) { return String::empty; }
  29144. void AudioProcessorGraph::AudioGraphIOProcessor::setParameter (int, float) { }
  29145. int AudioProcessorGraph::AudioGraphIOProcessor::getNumPrograms() { return 0; }
  29146. int AudioProcessorGraph::AudioGraphIOProcessor::getCurrentProgram() { return 0; }
  29147. void AudioProcessorGraph::AudioGraphIOProcessor::setCurrentProgram (int) { }
  29148. const String AudioProcessorGraph::AudioGraphIOProcessor::getProgramName (int) { return String::empty; }
  29149. void AudioProcessorGraph::AudioGraphIOProcessor::changeProgramName (int, const String&) { }
  29150. void AudioProcessorGraph::AudioGraphIOProcessor::getStateInformation (JUCE_NAMESPACE::MemoryBlock&)
  29151. {
  29152. }
  29153. void AudioProcessorGraph::AudioGraphIOProcessor::setStateInformation (const void*, int)
  29154. {
  29155. }
  29156. void AudioProcessorGraph::AudioGraphIOProcessor::setParentGraph (AudioProcessorGraph* const newGraph)
  29157. {
  29158. graph = newGraph;
  29159. if (graph != 0)
  29160. {
  29161. setPlayConfigDetails (type == audioOutputNode ? graph->getNumOutputChannels() : 0,
  29162. type == audioInputNode ? graph->getNumInputChannels() : 0,
  29163. getSampleRate(),
  29164. getBlockSize());
  29165. updateHostDisplay();
  29166. }
  29167. }
  29168. END_JUCE_NAMESPACE
  29169. /*** End of inlined file: juce_AudioProcessorGraph.cpp ***/
  29170. /*** Start of inlined file: juce_AudioProcessorPlayer.cpp ***/
  29171. BEGIN_JUCE_NAMESPACE
  29172. AudioProcessorPlayer::AudioProcessorPlayer()
  29173. : processor (0),
  29174. sampleRate (0),
  29175. blockSize (0),
  29176. isPrepared (false),
  29177. numInputChans (0),
  29178. numOutputChans (0),
  29179. tempBuffer (1, 1)
  29180. {
  29181. }
  29182. AudioProcessorPlayer::~AudioProcessorPlayer()
  29183. {
  29184. setProcessor (0);
  29185. }
  29186. void AudioProcessorPlayer::setProcessor (AudioProcessor* const processorToPlay)
  29187. {
  29188. if (processor != processorToPlay)
  29189. {
  29190. if (processorToPlay != 0 && sampleRate > 0 && blockSize > 0)
  29191. {
  29192. processorToPlay->setPlayConfigDetails (numInputChans, numOutputChans,
  29193. sampleRate, blockSize);
  29194. processorToPlay->prepareToPlay (sampleRate, blockSize);
  29195. }
  29196. lock.enter();
  29197. AudioProcessor* const oldOne = isPrepared ? processor : 0;
  29198. processor = processorToPlay;
  29199. isPrepared = true;
  29200. lock.exit();
  29201. if (oldOne != 0)
  29202. oldOne->releaseResources();
  29203. }
  29204. }
  29205. void AudioProcessorPlayer::audioDeviceIOCallback (const float** inputChannelData,
  29206. int numInputChannels,
  29207. float** outputChannelData,
  29208. int numOutputChannels,
  29209. int numSamples)
  29210. {
  29211. // these should have been prepared by audioDeviceAboutToStart()...
  29212. jassert (sampleRate > 0 && blockSize > 0);
  29213. incomingMidi.clear();
  29214. messageCollector.removeNextBlockOfMessages (incomingMidi, numSamples);
  29215. int i, totalNumChans = 0;
  29216. if (numInputChannels > numOutputChannels)
  29217. {
  29218. // if there aren't enough output channels for the number of
  29219. // inputs, we need to create some temporary extra ones (can't
  29220. // use the input data in case it gets written to)
  29221. tempBuffer.setSize (numInputChannels - numOutputChannels, numSamples,
  29222. false, false, true);
  29223. for (i = 0; i < numOutputChannels; ++i)
  29224. {
  29225. channels[totalNumChans] = outputChannelData[i];
  29226. memcpy (channels[totalNumChans], inputChannelData[i], sizeof (float) * numSamples);
  29227. ++totalNumChans;
  29228. }
  29229. for (i = numOutputChannels; i < numInputChannels; ++i)
  29230. {
  29231. channels[totalNumChans] = tempBuffer.getSampleData (i - numOutputChannels, 0);
  29232. memcpy (channels[totalNumChans], inputChannelData[i], sizeof (float) * numSamples);
  29233. ++totalNumChans;
  29234. }
  29235. }
  29236. else
  29237. {
  29238. for (i = 0; i < numInputChannels; ++i)
  29239. {
  29240. channels[totalNumChans] = outputChannelData[i];
  29241. memcpy (channels[totalNumChans], inputChannelData[i], sizeof (float) * numSamples);
  29242. ++totalNumChans;
  29243. }
  29244. for (i = numInputChannels; i < numOutputChannels; ++i)
  29245. {
  29246. channels[totalNumChans] = outputChannelData[i];
  29247. zeromem (channels[totalNumChans], sizeof (float) * numSamples);
  29248. ++totalNumChans;
  29249. }
  29250. }
  29251. AudioSampleBuffer buffer (channels, totalNumChans, numSamples);
  29252. const ScopedLock sl (lock);
  29253. if (processor != 0)
  29254. processor->processBlock (buffer, incomingMidi);
  29255. }
  29256. void AudioProcessorPlayer::audioDeviceAboutToStart (AudioIODevice* device)
  29257. {
  29258. const ScopedLock sl (lock);
  29259. sampleRate = device->getCurrentSampleRate();
  29260. blockSize = device->getCurrentBufferSizeSamples();
  29261. numInputChans = device->getActiveInputChannels().countNumberOfSetBits();
  29262. numOutputChans = device->getActiveOutputChannels().countNumberOfSetBits();
  29263. messageCollector.reset (sampleRate);
  29264. zeromem (channels, sizeof (channels));
  29265. if (processor != 0)
  29266. {
  29267. if (isPrepared)
  29268. processor->releaseResources();
  29269. AudioProcessor* const oldProcessor = processor;
  29270. setProcessor (0);
  29271. setProcessor (oldProcessor);
  29272. }
  29273. }
  29274. void AudioProcessorPlayer::audioDeviceStopped()
  29275. {
  29276. const ScopedLock sl (lock);
  29277. if (processor != 0 && isPrepared)
  29278. processor->releaseResources();
  29279. sampleRate = 0.0;
  29280. blockSize = 0;
  29281. isPrepared = false;
  29282. tempBuffer.setSize (1, 1);
  29283. }
  29284. void AudioProcessorPlayer::handleIncomingMidiMessage (MidiInput*, const MidiMessage& message)
  29285. {
  29286. messageCollector.addMessageToQueue (message);
  29287. }
  29288. END_JUCE_NAMESPACE
  29289. /*** End of inlined file: juce_AudioProcessorPlayer.cpp ***/
  29290. /*** Start of inlined file: juce_GenericAudioProcessorEditor.cpp ***/
  29291. BEGIN_JUCE_NAMESPACE
  29292. class ProcessorParameterPropertyComp : public PropertyComponent,
  29293. public AudioProcessorListener,
  29294. public AsyncUpdater
  29295. {
  29296. public:
  29297. ProcessorParameterPropertyComp (const String& name,
  29298. AudioProcessor* const owner_,
  29299. const int index_)
  29300. : PropertyComponent (name),
  29301. owner (owner_),
  29302. index (index_)
  29303. {
  29304. addAndMakeVisible (slider = new ParamSlider (owner_, index_));
  29305. owner_->addListener (this);
  29306. }
  29307. ~ProcessorParameterPropertyComp()
  29308. {
  29309. owner->removeListener (this);
  29310. deleteAllChildren();
  29311. }
  29312. void refresh()
  29313. {
  29314. slider->setValue (owner->getParameter (index), false);
  29315. }
  29316. void audioProcessorChanged (AudioProcessor*) {}
  29317. void audioProcessorParameterChanged (AudioProcessor*, int parameterIndex, float)
  29318. {
  29319. if (parameterIndex == index)
  29320. triggerAsyncUpdate();
  29321. }
  29322. void handleAsyncUpdate()
  29323. {
  29324. refresh();
  29325. }
  29326. juce_UseDebuggingNewOperator
  29327. private:
  29328. AudioProcessor* const owner;
  29329. const int index;
  29330. Slider* slider;
  29331. class ParamSlider : public Slider
  29332. {
  29333. public:
  29334. ParamSlider (AudioProcessor* const owner_, const int index_)
  29335. : Slider (String::empty),
  29336. owner (owner_),
  29337. index (index_)
  29338. {
  29339. setRange (0.0, 1.0, 0.0);
  29340. setSliderStyle (Slider::LinearBar);
  29341. setTextBoxIsEditable (false);
  29342. setScrollWheelEnabled (false);
  29343. }
  29344. ~ParamSlider()
  29345. {
  29346. }
  29347. void valueChanged()
  29348. {
  29349. const float newVal = (float) getValue();
  29350. if (owner->getParameter (index) != newVal)
  29351. owner->setParameter (index, newVal);
  29352. }
  29353. const String getTextFromValue (double /*value*/)
  29354. {
  29355. return owner->getParameterText (index);
  29356. }
  29357. juce_UseDebuggingNewOperator
  29358. private:
  29359. AudioProcessor* const owner;
  29360. const int index;
  29361. ParamSlider (const ParamSlider&);
  29362. const ParamSlider& operator= (const ParamSlider&);
  29363. };
  29364. ProcessorParameterPropertyComp (const ProcessorParameterPropertyComp&);
  29365. const ProcessorParameterPropertyComp& operator= (const ProcessorParameterPropertyComp&);
  29366. };
  29367. GenericAudioProcessorEditor::GenericAudioProcessorEditor (AudioProcessor* const owner_)
  29368. : AudioProcessorEditor (owner_)
  29369. {
  29370. setOpaque (true);
  29371. addAndMakeVisible (panel = new PropertyPanel());
  29372. Array <PropertyComponent*> params;
  29373. const int numParams = owner_->getNumParameters();
  29374. int totalHeight = 0;
  29375. for (int i = 0; i < numParams; ++i)
  29376. {
  29377. String name (owner_->getParameterName (i));
  29378. if (name.trim().isEmpty())
  29379. name = "Unnamed";
  29380. ProcessorParameterPropertyComp* const pc = new ProcessorParameterPropertyComp (name, owner_, i);
  29381. params.add (pc);
  29382. totalHeight += pc->getPreferredHeight();
  29383. }
  29384. panel->addProperties (params);
  29385. setSize (400, jlimit (25, 400, totalHeight));
  29386. }
  29387. GenericAudioProcessorEditor::~GenericAudioProcessorEditor()
  29388. {
  29389. deleteAllChildren();
  29390. }
  29391. void GenericAudioProcessorEditor::paint (Graphics& g)
  29392. {
  29393. g.fillAll (Colours::white);
  29394. }
  29395. void GenericAudioProcessorEditor::resized()
  29396. {
  29397. panel->setSize (getWidth(), getHeight());
  29398. }
  29399. END_JUCE_NAMESPACE
  29400. /*** End of inlined file: juce_GenericAudioProcessorEditor.cpp ***/
  29401. /*** Start of inlined file: juce_Sampler.cpp ***/
  29402. BEGIN_JUCE_NAMESPACE
  29403. SamplerSound::SamplerSound (const String& name_,
  29404. AudioFormatReader& source,
  29405. const BitArray& midiNotes_,
  29406. const int midiNoteForNormalPitch,
  29407. const double attackTimeSecs,
  29408. const double releaseTimeSecs,
  29409. const double maxSampleLengthSeconds)
  29410. : name (name_),
  29411. midiNotes (midiNotes_),
  29412. midiRootNote (midiNoteForNormalPitch)
  29413. {
  29414. sourceSampleRate = source.sampleRate;
  29415. if (sourceSampleRate <= 0 || source.lengthInSamples <= 0)
  29416. {
  29417. length = 0;
  29418. attackSamples = 0;
  29419. releaseSamples = 0;
  29420. }
  29421. else
  29422. {
  29423. length = jmin ((int) source.lengthInSamples,
  29424. (int) (maxSampleLengthSeconds * sourceSampleRate));
  29425. data = new AudioSampleBuffer (jmin (2, (int) source.numChannels), length + 4);
  29426. data->readFromAudioReader (&source, 0, length + 4, 0, true, true);
  29427. attackSamples = roundToInt (attackTimeSecs * sourceSampleRate);
  29428. releaseSamples = roundToInt (releaseTimeSecs * sourceSampleRate);
  29429. }
  29430. }
  29431. SamplerSound::~SamplerSound()
  29432. {
  29433. }
  29434. bool SamplerSound::appliesToNote (const int midiNoteNumber)
  29435. {
  29436. return midiNotes [midiNoteNumber];
  29437. }
  29438. bool SamplerSound::appliesToChannel (const int /*midiChannel*/)
  29439. {
  29440. return true;
  29441. }
  29442. SamplerVoice::SamplerVoice()
  29443. : pitchRatio (0.0),
  29444. sourceSamplePosition (0.0),
  29445. lgain (0.0f),
  29446. rgain (0.0f),
  29447. isInAttack (false),
  29448. isInRelease (false)
  29449. {
  29450. }
  29451. SamplerVoice::~SamplerVoice()
  29452. {
  29453. }
  29454. bool SamplerVoice::canPlaySound (SynthesiserSound* sound)
  29455. {
  29456. return dynamic_cast <const SamplerSound*> (sound) != 0;
  29457. }
  29458. void SamplerVoice::startNote (const int midiNoteNumber,
  29459. const float velocity,
  29460. SynthesiserSound* s,
  29461. const int /*currentPitchWheelPosition*/)
  29462. {
  29463. const SamplerSound* const sound = dynamic_cast <const SamplerSound*> (s);
  29464. jassert (sound != 0); // this object can only play SamplerSounds!
  29465. if (sound != 0)
  29466. {
  29467. const double targetFreq = MidiMessage::getMidiNoteInHertz (midiNoteNumber);
  29468. const double naturalFreq = MidiMessage::getMidiNoteInHertz (sound->midiRootNote);
  29469. pitchRatio = (targetFreq * sound->sourceSampleRate) / (naturalFreq * getSampleRate());
  29470. sourceSamplePosition = 0.0;
  29471. lgain = velocity;
  29472. rgain = velocity;
  29473. isInAttack = (sound->attackSamples > 0);
  29474. isInRelease = false;
  29475. if (isInAttack)
  29476. {
  29477. attackReleaseLevel = 0.0f;
  29478. attackDelta = (float) (pitchRatio / sound->attackSamples);
  29479. }
  29480. else
  29481. {
  29482. attackReleaseLevel = 1.0f;
  29483. attackDelta = 0.0f;
  29484. }
  29485. if (sound->releaseSamples > 0)
  29486. {
  29487. releaseDelta = (float) (-pitchRatio / sound->releaseSamples);
  29488. }
  29489. else
  29490. {
  29491. releaseDelta = 0.0f;
  29492. }
  29493. }
  29494. }
  29495. void SamplerVoice::stopNote (const bool allowTailOff)
  29496. {
  29497. if (allowTailOff)
  29498. {
  29499. isInAttack = false;
  29500. isInRelease = true;
  29501. }
  29502. else
  29503. {
  29504. clearCurrentNote();
  29505. }
  29506. }
  29507. void SamplerVoice::pitchWheelMoved (const int /*newValue*/)
  29508. {
  29509. }
  29510. void SamplerVoice::controllerMoved (const int /*controllerNumber*/,
  29511. const int /*newValue*/)
  29512. {
  29513. }
  29514. void SamplerVoice::renderNextBlock (AudioSampleBuffer& outputBuffer, int startSample, int numSamples)
  29515. {
  29516. const SamplerSound* const playingSound = (SamplerSound*) (SynthesiserSound*) getCurrentlyPlayingSound();
  29517. if (playingSound != 0)
  29518. {
  29519. const float* const inL = playingSound->data->getSampleData (0, 0);
  29520. const float* const inR = playingSound->data->getNumChannels() > 1
  29521. ? playingSound->data->getSampleData (1, 0) : 0;
  29522. float* outL = outputBuffer.getSampleData (0, startSample);
  29523. float* outR = outputBuffer.getNumChannels() > 1 ? outputBuffer.getSampleData (1, startSample) : 0;
  29524. while (--numSamples >= 0)
  29525. {
  29526. const int pos = (int) sourceSamplePosition;
  29527. const float alpha = (float) (sourceSamplePosition - pos);
  29528. const float invAlpha = 1.0f - alpha;
  29529. // just using a very simple linear interpolation here..
  29530. float l = (inL [pos] * invAlpha + inL [pos + 1] * alpha);
  29531. float r = (inR != 0) ? (inR [pos] * invAlpha + inR [pos + 1] * alpha)
  29532. : l;
  29533. l *= lgain;
  29534. r *= rgain;
  29535. if (isInAttack)
  29536. {
  29537. l *= attackReleaseLevel;
  29538. r *= attackReleaseLevel;
  29539. attackReleaseLevel += attackDelta;
  29540. if (attackReleaseLevel >= 1.0f)
  29541. {
  29542. attackReleaseLevel = 1.0f;
  29543. isInAttack = false;
  29544. }
  29545. }
  29546. else if (isInRelease)
  29547. {
  29548. l *= attackReleaseLevel;
  29549. r *= attackReleaseLevel;
  29550. attackReleaseLevel += releaseDelta;
  29551. if (attackReleaseLevel <= 0.0f)
  29552. {
  29553. stopNote (false);
  29554. break;
  29555. }
  29556. }
  29557. if (outR != 0)
  29558. {
  29559. *outL++ += l;
  29560. *outR++ += r;
  29561. }
  29562. else
  29563. {
  29564. *outL++ += (l + r) * 0.5f;
  29565. }
  29566. sourceSamplePosition += pitchRatio;
  29567. if (sourceSamplePosition > playingSound->length)
  29568. {
  29569. stopNote (false);
  29570. break;
  29571. }
  29572. }
  29573. }
  29574. }
  29575. END_JUCE_NAMESPACE
  29576. /*** End of inlined file: juce_Sampler.cpp ***/
  29577. /*** Start of inlined file: juce_Synthesiser.cpp ***/
  29578. BEGIN_JUCE_NAMESPACE
  29579. SynthesiserSound::SynthesiserSound()
  29580. {
  29581. }
  29582. SynthesiserSound::~SynthesiserSound()
  29583. {
  29584. }
  29585. SynthesiserVoice::SynthesiserVoice()
  29586. : currentSampleRate (44100.0),
  29587. currentlyPlayingNote (-1),
  29588. noteOnTime (0),
  29589. currentlyPlayingSound (0)
  29590. {
  29591. }
  29592. SynthesiserVoice::~SynthesiserVoice()
  29593. {
  29594. }
  29595. bool SynthesiserVoice::isPlayingChannel (const int midiChannel) const
  29596. {
  29597. return currentlyPlayingSound != 0
  29598. && currentlyPlayingSound->appliesToChannel (midiChannel);
  29599. }
  29600. void SynthesiserVoice::setCurrentPlaybackSampleRate (const double newRate)
  29601. {
  29602. currentSampleRate = newRate;
  29603. }
  29604. void SynthesiserVoice::clearCurrentNote()
  29605. {
  29606. currentlyPlayingNote = -1;
  29607. currentlyPlayingSound = 0;
  29608. }
  29609. Synthesiser::Synthesiser()
  29610. : sampleRate (0),
  29611. lastNoteOnCounter (0),
  29612. shouldStealNotes (true)
  29613. {
  29614. for (int i = 0; i < numElementsInArray (lastPitchWheelValues); ++i)
  29615. lastPitchWheelValues[i] = 0x2000;
  29616. }
  29617. Synthesiser::~Synthesiser()
  29618. {
  29619. }
  29620. SynthesiserVoice* Synthesiser::getVoice (const int index) const
  29621. {
  29622. const ScopedLock sl (lock);
  29623. return voices [index];
  29624. }
  29625. void Synthesiser::clearVoices()
  29626. {
  29627. const ScopedLock sl (lock);
  29628. voices.clear();
  29629. }
  29630. void Synthesiser::addVoice (SynthesiserVoice* const newVoice)
  29631. {
  29632. const ScopedLock sl (lock);
  29633. voices.add (newVoice);
  29634. }
  29635. void Synthesiser::removeVoice (const int index)
  29636. {
  29637. const ScopedLock sl (lock);
  29638. voices.remove (index);
  29639. }
  29640. void Synthesiser::clearSounds()
  29641. {
  29642. const ScopedLock sl (lock);
  29643. sounds.clear();
  29644. }
  29645. void Synthesiser::addSound (const SynthesiserSound::Ptr& newSound)
  29646. {
  29647. const ScopedLock sl (lock);
  29648. sounds.add (newSound);
  29649. }
  29650. void Synthesiser::removeSound (const int index)
  29651. {
  29652. const ScopedLock sl (lock);
  29653. sounds.remove (index);
  29654. }
  29655. void Synthesiser::setNoteStealingEnabled (const bool shouldStealNotes_)
  29656. {
  29657. shouldStealNotes = shouldStealNotes_;
  29658. }
  29659. void Synthesiser::setCurrentPlaybackSampleRate (const double newRate)
  29660. {
  29661. if (sampleRate != newRate)
  29662. {
  29663. const ScopedLock sl (lock);
  29664. allNotesOff (0, false);
  29665. sampleRate = newRate;
  29666. for (int i = voices.size(); --i >= 0;)
  29667. voices.getUnchecked (i)->setCurrentPlaybackSampleRate (newRate);
  29668. }
  29669. }
  29670. void Synthesiser::renderNextBlock (AudioSampleBuffer& outputBuffer,
  29671. const MidiBuffer& midiData,
  29672. int startSample,
  29673. int numSamples)
  29674. {
  29675. // must set the sample rate before using this!
  29676. jassert (sampleRate != 0);
  29677. const ScopedLock sl (lock);
  29678. MidiBuffer::Iterator midiIterator (midiData);
  29679. midiIterator.setNextSamplePosition (startSample);
  29680. MidiMessage m (0xf4, 0.0);
  29681. while (numSamples > 0)
  29682. {
  29683. int midiEventPos;
  29684. const bool useEvent = midiIterator.getNextEvent (m, midiEventPos)
  29685. && midiEventPos < startSample + numSamples;
  29686. const int numThisTime = useEvent ? midiEventPos - startSample
  29687. : numSamples;
  29688. if (numThisTime > 0)
  29689. {
  29690. for (int i = voices.size(); --i >= 0;)
  29691. voices.getUnchecked (i)->renderNextBlock (outputBuffer, startSample, numThisTime);
  29692. }
  29693. if (useEvent)
  29694. {
  29695. if (m.isNoteOn())
  29696. {
  29697. const int channel = m.getChannel();
  29698. noteOn (channel,
  29699. m.getNoteNumber(),
  29700. m.getFloatVelocity());
  29701. }
  29702. else if (m.isNoteOff())
  29703. {
  29704. noteOff (m.getChannel(),
  29705. m.getNoteNumber(),
  29706. true);
  29707. }
  29708. else if (m.isAllNotesOff() || m.isAllSoundOff())
  29709. {
  29710. allNotesOff (m.getChannel(), true);
  29711. }
  29712. else if (m.isPitchWheel())
  29713. {
  29714. const int channel = m.getChannel();
  29715. const int wheelPos = m.getPitchWheelValue();
  29716. lastPitchWheelValues [channel - 1] = wheelPos;
  29717. handlePitchWheel (channel, wheelPos);
  29718. }
  29719. else if (m.isController())
  29720. {
  29721. handleController (m.getChannel(),
  29722. m.getControllerNumber(),
  29723. m.getControllerValue());
  29724. }
  29725. }
  29726. startSample += numThisTime;
  29727. numSamples -= numThisTime;
  29728. }
  29729. }
  29730. void Synthesiser::noteOn (const int midiChannel,
  29731. const int midiNoteNumber,
  29732. const float velocity)
  29733. {
  29734. const ScopedLock sl (lock);
  29735. for (int i = sounds.size(); --i >= 0;)
  29736. {
  29737. SynthesiserSound* const sound = sounds.getUnchecked(i);
  29738. if (sound->appliesToNote (midiNoteNumber)
  29739. && sound->appliesToChannel (midiChannel))
  29740. {
  29741. startVoice (findFreeVoice (sound, shouldStealNotes),
  29742. sound, midiChannel, midiNoteNumber, velocity);
  29743. }
  29744. }
  29745. }
  29746. void Synthesiser::startVoice (SynthesiserVoice* const voice,
  29747. SynthesiserSound* const sound,
  29748. const int midiChannel,
  29749. const int midiNoteNumber,
  29750. const float velocity)
  29751. {
  29752. if (voice != 0 && sound != 0)
  29753. {
  29754. if (voice->currentlyPlayingSound != 0)
  29755. voice->stopNote (false);
  29756. voice->startNote (midiNoteNumber,
  29757. velocity,
  29758. sound,
  29759. lastPitchWheelValues [midiChannel - 1]);
  29760. voice->currentlyPlayingNote = midiNoteNumber;
  29761. voice->noteOnTime = ++lastNoteOnCounter;
  29762. voice->currentlyPlayingSound = sound;
  29763. }
  29764. }
  29765. void Synthesiser::noteOff (const int midiChannel,
  29766. const int midiNoteNumber,
  29767. const bool allowTailOff)
  29768. {
  29769. const ScopedLock sl (lock);
  29770. for (int i = voices.size(); --i >= 0;)
  29771. {
  29772. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29773. if (voice->getCurrentlyPlayingNote() == midiNoteNumber)
  29774. {
  29775. SynthesiserSound* const sound = voice->getCurrentlyPlayingSound();
  29776. if (sound != 0
  29777. && sound->appliesToNote (midiNoteNumber)
  29778. && sound->appliesToChannel (midiChannel))
  29779. {
  29780. voice->stopNote (allowTailOff);
  29781. // the subclass MUST call clearCurrentNote() if it's not tailing off! RTFM for stopNote()!
  29782. jassert (allowTailOff || (voice->getCurrentlyPlayingNote() < 0 && voice->getCurrentlyPlayingSound() == 0));
  29783. }
  29784. }
  29785. }
  29786. }
  29787. void Synthesiser::allNotesOff (const int midiChannel,
  29788. const bool allowTailOff)
  29789. {
  29790. const ScopedLock sl (lock);
  29791. for (int i = voices.size(); --i >= 0;)
  29792. {
  29793. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29794. if (midiChannel <= 0 || voice->isPlayingChannel (midiChannel))
  29795. voice->stopNote (allowTailOff);
  29796. }
  29797. }
  29798. void Synthesiser::handlePitchWheel (const int midiChannel,
  29799. const int wheelValue)
  29800. {
  29801. const ScopedLock sl (lock);
  29802. for (int i = voices.size(); --i >= 0;)
  29803. {
  29804. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29805. if (midiChannel <= 0 || voice->isPlayingChannel (midiChannel))
  29806. {
  29807. voice->pitchWheelMoved (wheelValue);
  29808. }
  29809. }
  29810. }
  29811. void Synthesiser::handleController (const int midiChannel,
  29812. const int controllerNumber,
  29813. const int controllerValue)
  29814. {
  29815. const ScopedLock sl (lock);
  29816. for (int i = voices.size(); --i >= 0;)
  29817. {
  29818. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29819. if (midiChannel <= 0 || voice->isPlayingChannel (midiChannel))
  29820. voice->controllerMoved (controllerNumber, controllerValue);
  29821. }
  29822. }
  29823. SynthesiserVoice* Synthesiser::findFreeVoice (SynthesiserSound* soundToPlay,
  29824. const bool stealIfNoneAvailable) const
  29825. {
  29826. const ScopedLock sl (lock);
  29827. for (int i = voices.size(); --i >= 0;)
  29828. if (voices.getUnchecked (i)->getCurrentlyPlayingNote() < 0
  29829. && voices.getUnchecked (i)->canPlaySound (soundToPlay))
  29830. return voices.getUnchecked (i);
  29831. if (stealIfNoneAvailable)
  29832. {
  29833. // currently this just steals the one that's been playing the longest, but could be made a bit smarter..
  29834. SynthesiserVoice* oldest = 0;
  29835. for (int i = voices.size(); --i >= 0;)
  29836. {
  29837. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29838. if (voice->canPlaySound (soundToPlay)
  29839. && (oldest == 0 || oldest->noteOnTime > voice->noteOnTime))
  29840. oldest = voice;
  29841. }
  29842. jassert (oldest != 0);
  29843. return oldest;
  29844. }
  29845. return 0;
  29846. }
  29847. END_JUCE_NAMESPACE
  29848. /*** End of inlined file: juce_Synthesiser.cpp ***/
  29849. /*** Start of inlined file: juce_ActionBroadcaster.cpp ***/
  29850. BEGIN_JUCE_NAMESPACE
  29851. ActionBroadcaster::ActionBroadcaster() throw()
  29852. {
  29853. // are you trying to create this object before or after juce has been intialised??
  29854. jassert (MessageManager::instance != 0);
  29855. }
  29856. ActionBroadcaster::~ActionBroadcaster()
  29857. {
  29858. // all event-based objects must be deleted BEFORE juce is shut down!
  29859. jassert (MessageManager::instance != 0);
  29860. }
  29861. void ActionBroadcaster::addActionListener (ActionListener* const listener)
  29862. {
  29863. actionListenerList.addActionListener (listener);
  29864. }
  29865. void ActionBroadcaster::removeActionListener (ActionListener* const listener)
  29866. {
  29867. jassert (actionListenerList.isValidMessageListener());
  29868. if (actionListenerList.isValidMessageListener())
  29869. actionListenerList.removeActionListener (listener);
  29870. }
  29871. void ActionBroadcaster::removeAllActionListeners()
  29872. {
  29873. actionListenerList.removeAllActionListeners();
  29874. }
  29875. void ActionBroadcaster::sendActionMessage (const String& message) const
  29876. {
  29877. actionListenerList.sendActionMessage (message);
  29878. }
  29879. END_JUCE_NAMESPACE
  29880. /*** End of inlined file: juce_ActionBroadcaster.cpp ***/
  29881. /*** Start of inlined file: juce_ActionListenerList.cpp ***/
  29882. BEGIN_JUCE_NAMESPACE
  29883. // special message of our own with a string in it
  29884. class ActionMessage : public Message
  29885. {
  29886. public:
  29887. const String message;
  29888. ActionMessage (const String& messageText,
  29889. void* const listener_) throw()
  29890. : message (messageText)
  29891. {
  29892. pointerParameter = listener_;
  29893. }
  29894. ~ActionMessage() throw()
  29895. {
  29896. }
  29897. private:
  29898. ActionMessage (const ActionMessage&);
  29899. const ActionMessage& operator= (const ActionMessage&);
  29900. };
  29901. ActionListenerList::ActionListenerList() throw()
  29902. {
  29903. }
  29904. ActionListenerList::~ActionListenerList() throw()
  29905. {
  29906. }
  29907. void ActionListenerList::addActionListener (ActionListener* const listener) throw()
  29908. {
  29909. const ScopedLock sl (actionListenerLock_);
  29910. jassert (listener != 0);
  29911. jassert (! actionListeners_.contains (listener)); // trying to add a listener to the list twice!
  29912. if (listener != 0)
  29913. actionListeners_.add (listener);
  29914. }
  29915. void ActionListenerList::removeActionListener (ActionListener* const listener) throw()
  29916. {
  29917. const ScopedLock sl (actionListenerLock_);
  29918. jassert (actionListeners_.contains (listener)); // trying to remove a listener that isn't on the list!
  29919. actionListeners_.removeValue (listener);
  29920. }
  29921. void ActionListenerList::removeAllActionListeners() throw()
  29922. {
  29923. const ScopedLock sl (actionListenerLock_);
  29924. actionListeners_.clear();
  29925. }
  29926. void ActionListenerList::sendActionMessage (const String& message) const
  29927. {
  29928. const ScopedLock sl (actionListenerLock_);
  29929. for (int i = actionListeners_.size(); --i >= 0;)
  29930. {
  29931. postMessage (new ActionMessage (message,
  29932. (ActionListener*) actionListeners_.getUnchecked(i)));
  29933. }
  29934. }
  29935. void ActionListenerList::handleMessage (const Message& message)
  29936. {
  29937. const ActionMessage& am = (const ActionMessage&) message;
  29938. if (actionListeners_.contains (am.pointerParameter))
  29939. ((ActionListener*) am.pointerParameter)->actionListenerCallback (am.message);
  29940. }
  29941. END_JUCE_NAMESPACE
  29942. /*** End of inlined file: juce_ActionListenerList.cpp ***/
  29943. /*** Start of inlined file: juce_AsyncUpdater.cpp ***/
  29944. BEGIN_JUCE_NAMESPACE
  29945. AsyncUpdater::AsyncUpdater() throw()
  29946. : asyncMessagePending (false)
  29947. {
  29948. internalAsyncHandler.owner = this;
  29949. }
  29950. AsyncUpdater::~AsyncUpdater()
  29951. {
  29952. }
  29953. void AsyncUpdater::triggerAsyncUpdate() throw()
  29954. {
  29955. if (! asyncMessagePending)
  29956. {
  29957. asyncMessagePending = true;
  29958. internalAsyncHandler.postMessage (new Message());
  29959. }
  29960. }
  29961. void AsyncUpdater::cancelPendingUpdate() throw()
  29962. {
  29963. asyncMessagePending = false;
  29964. }
  29965. void AsyncUpdater::handleUpdateNowIfNeeded()
  29966. {
  29967. if (asyncMessagePending)
  29968. {
  29969. asyncMessagePending = false;
  29970. handleAsyncUpdate();
  29971. }
  29972. }
  29973. void AsyncUpdater::AsyncUpdaterInternal::handleMessage (const Message&)
  29974. {
  29975. owner->handleUpdateNowIfNeeded();
  29976. }
  29977. END_JUCE_NAMESPACE
  29978. /*** End of inlined file: juce_AsyncUpdater.cpp ***/
  29979. /*** Start of inlined file: juce_ChangeBroadcaster.cpp ***/
  29980. BEGIN_JUCE_NAMESPACE
  29981. ChangeBroadcaster::ChangeBroadcaster() throw()
  29982. {
  29983. // are you trying to create this object before or after juce has been intialised??
  29984. jassert (MessageManager::instance != 0);
  29985. }
  29986. ChangeBroadcaster::~ChangeBroadcaster()
  29987. {
  29988. // all event-based objects must be deleted BEFORE juce is shut down!
  29989. jassert (MessageManager::instance != 0);
  29990. }
  29991. void ChangeBroadcaster::addChangeListener (ChangeListener* const listener) throw()
  29992. {
  29993. changeListenerList.addChangeListener (listener);
  29994. }
  29995. void ChangeBroadcaster::removeChangeListener (ChangeListener* const listener) throw()
  29996. {
  29997. jassert (changeListenerList.isValidMessageListener());
  29998. if (changeListenerList.isValidMessageListener())
  29999. changeListenerList.removeChangeListener (listener);
  30000. }
  30001. void ChangeBroadcaster::removeAllChangeListeners() throw()
  30002. {
  30003. changeListenerList.removeAllChangeListeners();
  30004. }
  30005. void ChangeBroadcaster::sendChangeMessage (void* objectThatHasChanged) throw()
  30006. {
  30007. changeListenerList.sendChangeMessage (objectThatHasChanged);
  30008. }
  30009. void ChangeBroadcaster::sendSynchronousChangeMessage (void* objectThatHasChanged)
  30010. {
  30011. changeListenerList.sendSynchronousChangeMessage (objectThatHasChanged);
  30012. }
  30013. void ChangeBroadcaster::dispatchPendingMessages()
  30014. {
  30015. changeListenerList.dispatchPendingMessages();
  30016. }
  30017. END_JUCE_NAMESPACE
  30018. /*** End of inlined file: juce_ChangeBroadcaster.cpp ***/
  30019. /*** Start of inlined file: juce_ChangeListenerList.cpp ***/
  30020. BEGIN_JUCE_NAMESPACE
  30021. ChangeListenerList::ChangeListenerList() throw()
  30022. : lastChangedObject (0),
  30023. messagePending (false)
  30024. {
  30025. }
  30026. ChangeListenerList::~ChangeListenerList() throw()
  30027. {
  30028. }
  30029. void ChangeListenerList::addChangeListener (ChangeListener* const listener) throw()
  30030. {
  30031. const ScopedLock sl (lock);
  30032. jassert (listener != 0);
  30033. if (listener != 0)
  30034. listeners.add (listener);
  30035. }
  30036. void ChangeListenerList::removeChangeListener (ChangeListener* const listener) throw()
  30037. {
  30038. const ScopedLock sl (lock);
  30039. listeners.removeValue (listener);
  30040. }
  30041. void ChangeListenerList::removeAllChangeListeners() throw()
  30042. {
  30043. const ScopedLock sl (lock);
  30044. listeners.clear();
  30045. }
  30046. void ChangeListenerList::sendChangeMessage (void* const objectThatHasChanged) throw()
  30047. {
  30048. const ScopedLock sl (lock);
  30049. if ((! messagePending) && (listeners.size() > 0))
  30050. {
  30051. lastChangedObject = objectThatHasChanged;
  30052. postMessage (new Message (0, 0, 0, objectThatHasChanged));
  30053. messagePending = true;
  30054. }
  30055. }
  30056. void ChangeListenerList::handleMessage (const Message& message)
  30057. {
  30058. sendSynchronousChangeMessage (message.pointerParameter);
  30059. }
  30060. void ChangeListenerList::sendSynchronousChangeMessage (void* const objectThatHasChanged)
  30061. {
  30062. const ScopedLock sl (lock);
  30063. messagePending = false;
  30064. for (int i = listeners.size(); --i >= 0;)
  30065. {
  30066. ChangeListener* const l = (ChangeListener*) listeners.getUnchecked (i);
  30067. {
  30068. const ScopedUnlock tempUnlocker (lock);
  30069. l->changeListenerCallback (objectThatHasChanged);
  30070. }
  30071. i = jmin (i, listeners.size());
  30072. }
  30073. }
  30074. void ChangeListenerList::dispatchPendingMessages()
  30075. {
  30076. if (messagePending)
  30077. sendSynchronousChangeMessage (lastChangedObject);
  30078. }
  30079. END_JUCE_NAMESPACE
  30080. /*** End of inlined file: juce_ChangeListenerList.cpp ***/
  30081. /*** Start of inlined file: juce_InterprocessConnection.cpp ***/
  30082. BEGIN_JUCE_NAMESPACE
  30083. InterprocessConnection::InterprocessConnection (const bool callbacksOnMessageThread,
  30084. const uint32 magicMessageHeaderNumber)
  30085. : Thread ("Juce IPC connection"),
  30086. callbackConnectionState (false),
  30087. useMessageThread (callbacksOnMessageThread),
  30088. magicMessageHeader (magicMessageHeaderNumber),
  30089. pipeReceiveMessageTimeout (-1)
  30090. {
  30091. }
  30092. InterprocessConnection::~InterprocessConnection()
  30093. {
  30094. callbackConnectionState = false;
  30095. disconnect();
  30096. }
  30097. bool InterprocessConnection::connectToSocket (const String& hostName,
  30098. const int portNumber,
  30099. const int timeOutMillisecs)
  30100. {
  30101. disconnect();
  30102. const ScopedLock sl (pipeAndSocketLock);
  30103. socket = new StreamingSocket();
  30104. if (socket->connect (hostName, portNumber, timeOutMillisecs))
  30105. {
  30106. connectionMadeInt();
  30107. startThread();
  30108. return true;
  30109. }
  30110. else
  30111. {
  30112. socket = 0;
  30113. return false;
  30114. }
  30115. }
  30116. bool InterprocessConnection::connectToPipe (const String& pipeName,
  30117. const int pipeReceiveMessageTimeoutMs)
  30118. {
  30119. disconnect();
  30120. ScopedPointer <NamedPipe> newPipe (new NamedPipe());
  30121. if (newPipe->openExisting (pipeName))
  30122. {
  30123. const ScopedLock sl (pipeAndSocketLock);
  30124. pipeReceiveMessageTimeout = pipeReceiveMessageTimeoutMs;
  30125. initialiseWithPipe (newPipe.release());
  30126. return true;
  30127. }
  30128. return false;
  30129. }
  30130. bool InterprocessConnection::createPipe (const String& pipeName,
  30131. const int pipeReceiveMessageTimeoutMs)
  30132. {
  30133. disconnect();
  30134. ScopedPointer <NamedPipe> newPipe (new NamedPipe());
  30135. if (newPipe->createNewPipe (pipeName))
  30136. {
  30137. const ScopedLock sl (pipeAndSocketLock);
  30138. pipeReceiveMessageTimeout = pipeReceiveMessageTimeoutMs;
  30139. initialiseWithPipe (newPipe.release());
  30140. return true;
  30141. }
  30142. return false;
  30143. }
  30144. void InterprocessConnection::disconnect()
  30145. {
  30146. if (socket != 0)
  30147. socket->close();
  30148. if (pipe != 0)
  30149. {
  30150. pipe->cancelPendingReads();
  30151. pipe->close();
  30152. }
  30153. stopThread (4000);
  30154. {
  30155. const ScopedLock sl (pipeAndSocketLock);
  30156. socket = 0;
  30157. pipe = 0;
  30158. }
  30159. connectionLostInt();
  30160. }
  30161. bool InterprocessConnection::isConnected() const
  30162. {
  30163. const ScopedLock sl (pipeAndSocketLock);
  30164. return ((socket != 0 && socket->isConnected())
  30165. || (pipe != 0 && pipe->isOpen()))
  30166. && isThreadRunning();
  30167. }
  30168. const String InterprocessConnection::getConnectedHostName() const
  30169. {
  30170. if (pipe != 0)
  30171. {
  30172. return "localhost";
  30173. }
  30174. else if (socket != 0)
  30175. {
  30176. if (! socket->isLocal())
  30177. return socket->getHostName();
  30178. return "localhost";
  30179. }
  30180. return String::empty;
  30181. }
  30182. bool InterprocessConnection::sendMessage (const MemoryBlock& message)
  30183. {
  30184. uint32 messageHeader[2];
  30185. messageHeader [0] = ByteOrder::swapIfBigEndian (magicMessageHeader);
  30186. messageHeader [1] = ByteOrder::swapIfBigEndian ((uint32) message.getSize());
  30187. MemoryBlock messageData (sizeof (messageHeader) + message.getSize());
  30188. messageData.copyFrom (messageHeader, 0, sizeof (messageHeader));
  30189. messageData.copyFrom (message.getData(), sizeof (messageHeader), message.getSize());
  30190. size_t bytesWritten = 0;
  30191. const ScopedLock sl (pipeAndSocketLock);
  30192. if (socket != 0)
  30193. {
  30194. bytesWritten = socket->write (messageData.getData(), (int) messageData.getSize());
  30195. }
  30196. else if (pipe != 0)
  30197. {
  30198. bytesWritten = pipe->write (messageData.getData(), (int) messageData.getSize());
  30199. }
  30200. if (bytesWritten < 0)
  30201. {
  30202. // error..
  30203. return false;
  30204. }
  30205. return (bytesWritten == messageData.getSize());
  30206. }
  30207. void InterprocessConnection::initialiseWithSocket (StreamingSocket* const socket_)
  30208. {
  30209. jassert (socket == 0);
  30210. socket = socket_;
  30211. connectionMadeInt();
  30212. startThread();
  30213. }
  30214. void InterprocessConnection::initialiseWithPipe (NamedPipe* const pipe_)
  30215. {
  30216. jassert (pipe == 0);
  30217. pipe = pipe_;
  30218. connectionMadeInt();
  30219. startThread();
  30220. }
  30221. const int messageMagicNumber = 0xb734128b;
  30222. void InterprocessConnection::handleMessage (const Message& message)
  30223. {
  30224. if (message.intParameter1 == messageMagicNumber)
  30225. {
  30226. switch (message.intParameter2)
  30227. {
  30228. case 0:
  30229. {
  30230. ScopedPointer <MemoryBlock> data ((MemoryBlock*) message.pointerParameter);
  30231. messageReceived (*data);
  30232. break;
  30233. }
  30234. case 1:
  30235. connectionMade();
  30236. break;
  30237. case 2:
  30238. connectionLost();
  30239. break;
  30240. }
  30241. }
  30242. }
  30243. void InterprocessConnection::connectionMadeInt()
  30244. {
  30245. if (! callbackConnectionState)
  30246. {
  30247. callbackConnectionState = true;
  30248. if (useMessageThread)
  30249. postMessage (new Message (messageMagicNumber, 1, 0, 0));
  30250. else
  30251. connectionMade();
  30252. }
  30253. }
  30254. void InterprocessConnection::connectionLostInt()
  30255. {
  30256. if (callbackConnectionState)
  30257. {
  30258. callbackConnectionState = false;
  30259. if (useMessageThread)
  30260. postMessage (new Message (messageMagicNumber, 2, 0, 0));
  30261. else
  30262. connectionLost();
  30263. }
  30264. }
  30265. void InterprocessConnection::deliverDataInt (const MemoryBlock& data)
  30266. {
  30267. jassert (callbackConnectionState);
  30268. if (useMessageThread)
  30269. postMessage (new Message (messageMagicNumber, 0, 0, new MemoryBlock (data)));
  30270. else
  30271. messageReceived (data);
  30272. }
  30273. bool InterprocessConnection::readNextMessageInt()
  30274. {
  30275. const int maximumMessageSize = 1024 * 1024 * 10; // sanity check
  30276. uint32 messageHeader[2];
  30277. const int bytes = (socket != 0) ? socket->read (messageHeader, sizeof (messageHeader), true)
  30278. : pipe->read (messageHeader, sizeof (messageHeader), pipeReceiveMessageTimeout);
  30279. if (bytes == sizeof (messageHeader)
  30280. && ByteOrder::swapIfBigEndian (messageHeader[0]) == magicMessageHeader)
  30281. {
  30282. const int bytesInMessage = (int) ByteOrder::swapIfBigEndian (messageHeader[1]);
  30283. if (bytesInMessage > 0 && bytesInMessage < maximumMessageSize)
  30284. {
  30285. MemoryBlock messageData (bytesInMessage, true);
  30286. int bytesRead = 0;
  30287. while (bytesRead < bytesInMessage)
  30288. {
  30289. if (threadShouldExit())
  30290. return false;
  30291. const int numThisTime = jmin (bytesInMessage, 65536);
  30292. const int bytesIn = (socket != 0) ? socket->read (((char*) messageData.getData()) + bytesRead, numThisTime, true)
  30293. : pipe->read (((char*) messageData.getData()) + bytesRead, numThisTime,
  30294. pipeReceiveMessageTimeout);
  30295. if (bytesIn <= 0)
  30296. break;
  30297. bytesRead += bytesIn;
  30298. }
  30299. if (bytesRead >= 0)
  30300. deliverDataInt (messageData);
  30301. }
  30302. }
  30303. else if (bytes < 0)
  30304. {
  30305. {
  30306. const ScopedLock sl (pipeAndSocketLock);
  30307. socket = 0;
  30308. }
  30309. connectionLostInt();
  30310. return false;
  30311. }
  30312. return true;
  30313. }
  30314. void InterprocessConnection::run()
  30315. {
  30316. while (! threadShouldExit())
  30317. {
  30318. if (socket != 0)
  30319. {
  30320. const int ready = socket->waitUntilReady (true, 0);
  30321. if (ready < 0)
  30322. {
  30323. {
  30324. const ScopedLock sl (pipeAndSocketLock);
  30325. socket = 0;
  30326. }
  30327. connectionLostInt();
  30328. break;
  30329. }
  30330. else if (ready > 0)
  30331. {
  30332. if (! readNextMessageInt())
  30333. break;
  30334. }
  30335. else
  30336. {
  30337. Thread::sleep (2);
  30338. }
  30339. }
  30340. else if (pipe != 0)
  30341. {
  30342. if (! pipe->isOpen())
  30343. {
  30344. {
  30345. const ScopedLock sl (pipeAndSocketLock);
  30346. pipe = 0;
  30347. }
  30348. connectionLostInt();
  30349. break;
  30350. }
  30351. else
  30352. {
  30353. if (! readNextMessageInt())
  30354. break;
  30355. }
  30356. }
  30357. else
  30358. {
  30359. break;
  30360. }
  30361. }
  30362. }
  30363. END_JUCE_NAMESPACE
  30364. /*** End of inlined file: juce_InterprocessConnection.cpp ***/
  30365. /*** Start of inlined file: juce_InterprocessConnectionServer.cpp ***/
  30366. BEGIN_JUCE_NAMESPACE
  30367. InterprocessConnectionServer::InterprocessConnectionServer()
  30368. : Thread ("Juce IPC server")
  30369. {
  30370. }
  30371. InterprocessConnectionServer::~InterprocessConnectionServer()
  30372. {
  30373. stop();
  30374. }
  30375. bool InterprocessConnectionServer::beginWaitingForSocket (const int portNumber)
  30376. {
  30377. stop();
  30378. socket = new StreamingSocket();
  30379. if (socket->createListener (portNumber))
  30380. {
  30381. startThread();
  30382. return true;
  30383. }
  30384. socket = 0;
  30385. return false;
  30386. }
  30387. void InterprocessConnectionServer::stop()
  30388. {
  30389. signalThreadShouldExit();
  30390. if (socket != 0)
  30391. socket->close();
  30392. stopThread (4000);
  30393. socket = 0;
  30394. }
  30395. void InterprocessConnectionServer::run()
  30396. {
  30397. while ((! threadShouldExit()) && socket != 0)
  30398. {
  30399. ScopedPointer <StreamingSocket> clientSocket (socket->waitForNextConnection());
  30400. if (clientSocket != 0)
  30401. {
  30402. InterprocessConnection* newConnection = createConnectionObject();
  30403. if (newConnection != 0)
  30404. newConnection->initialiseWithSocket (clientSocket.release());
  30405. }
  30406. }
  30407. }
  30408. END_JUCE_NAMESPACE
  30409. /*** End of inlined file: juce_InterprocessConnectionServer.cpp ***/
  30410. /*** Start of inlined file: juce_Message.cpp ***/
  30411. BEGIN_JUCE_NAMESPACE
  30412. Message::Message() throw()
  30413. {
  30414. }
  30415. Message::~Message() throw()
  30416. {
  30417. }
  30418. Message::Message (const int intParameter1_,
  30419. const int intParameter2_,
  30420. const int intParameter3_,
  30421. void* const pointerParameter_) throw()
  30422. : intParameter1 (intParameter1_),
  30423. intParameter2 (intParameter2_),
  30424. intParameter3 (intParameter3_),
  30425. pointerParameter (pointerParameter_)
  30426. {
  30427. }
  30428. END_JUCE_NAMESPACE
  30429. /*** End of inlined file: juce_Message.cpp ***/
  30430. /*** Start of inlined file: juce_MessageListener.cpp ***/
  30431. BEGIN_JUCE_NAMESPACE
  30432. MessageListener::MessageListener() throw()
  30433. {
  30434. // are you trying to create a messagelistener before or after juce has been intialised??
  30435. jassert (MessageManager::instance != 0);
  30436. if (MessageManager::instance != 0)
  30437. MessageManager::instance->messageListeners.add (this);
  30438. }
  30439. MessageListener::~MessageListener()
  30440. {
  30441. if (MessageManager::instance != 0)
  30442. MessageManager::instance->messageListeners.removeValue (this);
  30443. }
  30444. void MessageListener::postMessage (Message* const message) const throw()
  30445. {
  30446. message->messageRecipient = const_cast <MessageListener*> (this);
  30447. if (MessageManager::instance == 0)
  30448. MessageManager::getInstance();
  30449. MessageManager::instance->postMessageToQueue (message);
  30450. }
  30451. bool MessageListener::isValidMessageListener() const throw()
  30452. {
  30453. return (MessageManager::instance != 0)
  30454. && MessageManager::instance->messageListeners.contains (this);
  30455. }
  30456. END_JUCE_NAMESPACE
  30457. /*** End of inlined file: juce_MessageListener.cpp ***/
  30458. /*** Start of inlined file: juce_MessageManager.cpp ***/
  30459. BEGIN_JUCE_NAMESPACE
  30460. // platform-specific functions..
  30461. bool juce_dispatchNextMessageOnSystemQueue (bool returnIfNoPendingMessages);
  30462. bool juce_postMessageToSystemQueue (void* message);
  30463. MessageManager* MessageManager::instance = 0;
  30464. static const int quitMessageId = 0xfffff321;
  30465. MessageManager::MessageManager() throw()
  30466. : quitMessagePosted (false),
  30467. quitMessageReceived (false),
  30468. threadWithLock (0)
  30469. {
  30470. messageThreadId = Thread::getCurrentThreadId();
  30471. }
  30472. MessageManager::~MessageManager() throw()
  30473. {
  30474. broadcastListeners = 0;
  30475. doPlatformSpecificShutdown();
  30476. jassert (instance == this);
  30477. instance = 0; // do this last in case this instance is still needed by doPlatformSpecificShutdown()
  30478. }
  30479. MessageManager* MessageManager::getInstance() throw()
  30480. {
  30481. if (instance == 0)
  30482. {
  30483. instance = new MessageManager();
  30484. doPlatformSpecificInitialisation();
  30485. }
  30486. return instance;
  30487. }
  30488. void MessageManager::postMessageToQueue (Message* const message)
  30489. {
  30490. if (quitMessagePosted || ! juce_postMessageToSystemQueue (message))
  30491. delete message;
  30492. }
  30493. CallbackMessage::CallbackMessage() throw() {}
  30494. CallbackMessage::~CallbackMessage() throw() {}
  30495. void CallbackMessage::post()
  30496. {
  30497. if (MessageManager::instance != 0)
  30498. MessageManager::instance->postCallbackMessage (this);
  30499. }
  30500. void MessageManager::postCallbackMessage (Message* const message)
  30501. {
  30502. message->messageRecipient = 0;
  30503. postMessageToQueue (message);
  30504. }
  30505. // not for public use..
  30506. void MessageManager::deliverMessage (void* message)
  30507. {
  30508. const ScopedPointer <Message> m ((Message*) message);
  30509. MessageListener* const recipient = m->messageRecipient;
  30510. JUCE_TRY
  30511. {
  30512. if (messageListeners.contains (recipient))
  30513. {
  30514. recipient->handleMessage (*m);
  30515. }
  30516. else if (recipient == 0)
  30517. {
  30518. if (m->intParameter1 == quitMessageId)
  30519. {
  30520. quitMessageReceived = true;
  30521. }
  30522. else
  30523. {
  30524. CallbackMessage* const cm = dynamic_cast <CallbackMessage*> ((Message*) m);
  30525. if (cm != 0)
  30526. cm->messageCallback();
  30527. }
  30528. }
  30529. }
  30530. JUCE_CATCH_EXCEPTION
  30531. }
  30532. #if ! (JUCE_MAC || JUCE_IPHONE)
  30533. void MessageManager::runDispatchLoop()
  30534. {
  30535. jassert (isThisTheMessageThread()); // must only be called by the message thread
  30536. runDispatchLoopUntil (-1);
  30537. }
  30538. void MessageManager::stopDispatchLoop()
  30539. {
  30540. Message* const m = new Message (quitMessageId, 0, 0, 0);
  30541. m->messageRecipient = 0;
  30542. postMessageToQueue (m);
  30543. quitMessagePosted = true;
  30544. }
  30545. bool MessageManager::runDispatchLoopUntil (int millisecondsToRunFor)
  30546. {
  30547. jassert (isThisTheMessageThread()); // must only be called by the message thread
  30548. const int64 endTime = Time::currentTimeMillis() + millisecondsToRunFor;
  30549. while ((millisecondsToRunFor < 0 || endTime > Time::currentTimeMillis())
  30550. && ! quitMessageReceived)
  30551. {
  30552. JUCE_TRY
  30553. {
  30554. if (! juce_dispatchNextMessageOnSystemQueue (millisecondsToRunFor >= 0))
  30555. {
  30556. const int msToWait = (int) (endTime - Time::currentTimeMillis());
  30557. if (msToWait > 0)
  30558. Thread::sleep (jmin (5, msToWait));
  30559. }
  30560. }
  30561. JUCE_CATCH_EXCEPTION
  30562. }
  30563. return ! quitMessageReceived;
  30564. }
  30565. #endif
  30566. void MessageManager::deliverBroadcastMessage (const String& value)
  30567. {
  30568. if (broadcastListeners != 0)
  30569. broadcastListeners->sendActionMessage (value);
  30570. }
  30571. void MessageManager::registerBroadcastListener (ActionListener* const listener) throw()
  30572. {
  30573. if (broadcastListeners == 0)
  30574. broadcastListeners = new ActionListenerList();
  30575. broadcastListeners->addActionListener (listener);
  30576. }
  30577. void MessageManager::deregisterBroadcastListener (ActionListener* const listener) throw()
  30578. {
  30579. if (broadcastListeners != 0)
  30580. broadcastListeners->removeActionListener (listener);
  30581. }
  30582. bool MessageManager::isThisTheMessageThread() const throw()
  30583. {
  30584. return Thread::getCurrentThreadId() == messageThreadId;
  30585. }
  30586. void MessageManager::setCurrentMessageThread (const Thread::ThreadID threadId) throw()
  30587. {
  30588. messageThreadId = threadId;
  30589. }
  30590. bool MessageManager::currentThreadHasLockedMessageManager() const throw()
  30591. {
  30592. const Thread::ThreadID thisThread = Thread::getCurrentThreadId();
  30593. return thisThread == messageThreadId || thisThread == threadWithLock;
  30594. }
  30595. class SharedLockingEvents : public ReferenceCountedObject
  30596. {
  30597. public:
  30598. SharedLockingEvents() throw() {}
  30599. ~SharedLockingEvents() {}
  30600. WaitableEvent lockedEvent, releaseEvent;
  30601. };
  30602. class MMLockMessage : public CallbackMessage
  30603. {
  30604. public:
  30605. MMLockMessage (SharedLockingEvents* const events_) throw()
  30606. : events (events_)
  30607. {}
  30608. ~MMLockMessage() throw() {}
  30609. ReferenceCountedObjectPtr <SharedLockingEvents> events;
  30610. void messageCallback()
  30611. {
  30612. events->lockedEvent.signal();
  30613. events->releaseEvent.wait();
  30614. }
  30615. juce_UseDebuggingNewOperator
  30616. MMLockMessage (const MMLockMessage&);
  30617. const MMLockMessage& operator= (const MMLockMessage&);
  30618. };
  30619. MessageManagerLock::MessageManagerLock (Thread* const threadToCheck) throw()
  30620. : locked (false),
  30621. needsUnlocking (false)
  30622. {
  30623. init (threadToCheck, 0);
  30624. }
  30625. MessageManagerLock::MessageManagerLock (ThreadPoolJob* const jobToCheckForExitSignal) throw()
  30626. : locked (false),
  30627. needsUnlocking (false)
  30628. {
  30629. init (0, jobToCheckForExitSignal);
  30630. }
  30631. void MessageManagerLock::init (Thread* const threadToCheck, ThreadPoolJob* const job) throw()
  30632. {
  30633. if (MessageManager::instance != 0)
  30634. {
  30635. if (MessageManager::instance->currentThreadHasLockedMessageManager())
  30636. {
  30637. locked = true; // either we're on the message thread, or this is a re-entrant call.
  30638. }
  30639. else
  30640. {
  30641. if (threadToCheck == 0 && job == 0)
  30642. {
  30643. MessageManager::instance->lockingLock.enter();
  30644. }
  30645. else
  30646. {
  30647. while (! MessageManager::instance->lockingLock.tryEnter())
  30648. {
  30649. if ((threadToCheck != 0 && threadToCheck->threadShouldExit())
  30650. || (job != 0 && job->shouldExit()))
  30651. return;
  30652. Thread::sleep (1);
  30653. }
  30654. }
  30655. SharedLockingEvents* const events = new SharedLockingEvents();
  30656. sharedEvents = events;
  30657. events->incReferenceCount();
  30658. (new MMLockMessage (events))->post();
  30659. while (! events->lockedEvent.wait (50))
  30660. {
  30661. if ((threadToCheck != 0 && threadToCheck->threadShouldExit())
  30662. || (job != 0 && job->shouldExit()))
  30663. {
  30664. events->releaseEvent.signal();
  30665. events->decReferenceCount();
  30666. MessageManager::instance->lockingLock.exit();
  30667. return;
  30668. }
  30669. }
  30670. jassert (MessageManager::instance->threadWithLock == 0);
  30671. MessageManager::instance->threadWithLock = Thread::getCurrentThreadId();
  30672. locked = true;
  30673. needsUnlocking = true;
  30674. }
  30675. }
  30676. }
  30677. MessageManagerLock::~MessageManagerLock() throw()
  30678. {
  30679. if (needsUnlocking && MessageManager::instance != 0)
  30680. {
  30681. jassert (MessageManager::instance->currentThreadHasLockedMessageManager());
  30682. ((SharedLockingEvents*) sharedEvents)->releaseEvent.signal();
  30683. ((SharedLockingEvents*) sharedEvents)->decReferenceCount();
  30684. MessageManager::instance->threadWithLock = 0;
  30685. MessageManager::instance->lockingLock.exit();
  30686. }
  30687. }
  30688. END_JUCE_NAMESPACE
  30689. /*** End of inlined file: juce_MessageManager.cpp ***/
  30690. /*** Start of inlined file: juce_MultiTimer.cpp ***/
  30691. BEGIN_JUCE_NAMESPACE
  30692. class MultiTimer::MultiTimerCallback : public Timer
  30693. {
  30694. public:
  30695. MultiTimerCallback (const int timerId_, MultiTimer& owner_)
  30696. : timerId (timerId_),
  30697. owner (owner_)
  30698. {
  30699. }
  30700. ~MultiTimerCallback()
  30701. {
  30702. }
  30703. void timerCallback()
  30704. {
  30705. owner.timerCallback (timerId);
  30706. }
  30707. const int timerId;
  30708. private:
  30709. MultiTimer& owner;
  30710. };
  30711. MultiTimer::MultiTimer() throw()
  30712. {
  30713. }
  30714. MultiTimer::MultiTimer (const MultiTimer&) throw()
  30715. {
  30716. }
  30717. MultiTimer::~MultiTimer()
  30718. {
  30719. const ScopedLock sl (timerListLock);
  30720. timers.clear();
  30721. }
  30722. void MultiTimer::startTimer (const int timerId, const int intervalInMilliseconds) throw()
  30723. {
  30724. const ScopedLock sl (timerListLock);
  30725. for (int i = timers.size(); --i >= 0;)
  30726. {
  30727. MultiTimerCallback* const t = timers.getUnchecked(i);
  30728. if (t->timerId == timerId)
  30729. {
  30730. t->startTimer (intervalInMilliseconds);
  30731. return;
  30732. }
  30733. }
  30734. MultiTimerCallback* const newTimer = new MultiTimerCallback (timerId, *this);
  30735. timers.add (newTimer);
  30736. newTimer->startTimer (intervalInMilliseconds);
  30737. }
  30738. void MultiTimer::stopTimer (const int timerId) throw()
  30739. {
  30740. const ScopedLock sl (timerListLock);
  30741. for (int i = timers.size(); --i >= 0;)
  30742. {
  30743. MultiTimerCallback* const t = timers.getUnchecked(i);
  30744. if (t->timerId == timerId)
  30745. t->stopTimer();
  30746. }
  30747. }
  30748. bool MultiTimer::isTimerRunning (const int timerId) const throw()
  30749. {
  30750. const ScopedLock sl (timerListLock);
  30751. for (int i = timers.size(); --i >= 0;)
  30752. {
  30753. const MultiTimerCallback* const t = timers.getUnchecked(i);
  30754. if (t->timerId == timerId)
  30755. return t->isTimerRunning();
  30756. }
  30757. return false;
  30758. }
  30759. int MultiTimer::getTimerInterval (const int timerId) const throw()
  30760. {
  30761. const ScopedLock sl (timerListLock);
  30762. for (int i = timers.size(); --i >= 0;)
  30763. {
  30764. const MultiTimerCallback* const t = timers.getUnchecked(i);
  30765. if (t->timerId == timerId)
  30766. return t->getTimerInterval();
  30767. }
  30768. return 0;
  30769. }
  30770. END_JUCE_NAMESPACE
  30771. /*** End of inlined file: juce_MultiTimer.cpp ***/
  30772. /*** Start of inlined file: juce_Timer.cpp ***/
  30773. BEGIN_JUCE_NAMESPACE
  30774. class InternalTimerThread : private Thread,
  30775. private MessageListener,
  30776. private DeletedAtShutdown,
  30777. private AsyncUpdater
  30778. {
  30779. public:
  30780. InternalTimerThread()
  30781. : Thread ("Juce Timer"),
  30782. firstTimer (0),
  30783. callbackNeeded (false)
  30784. {
  30785. triggerAsyncUpdate();
  30786. }
  30787. ~InternalTimerThread() throw()
  30788. {
  30789. stopThread (4000);
  30790. jassert (instance == this || instance == 0);
  30791. if (instance == this)
  30792. instance = 0;
  30793. }
  30794. void run()
  30795. {
  30796. uint32 lastTime = Time::getMillisecondCounter();
  30797. while (! threadShouldExit())
  30798. {
  30799. const uint32 now = Time::getMillisecondCounter();
  30800. if (now <= lastTime)
  30801. {
  30802. wait (2);
  30803. continue;
  30804. }
  30805. const int elapsed = now - lastTime;
  30806. lastTime = now;
  30807. lock.enter();
  30808. decrementAllCounters (elapsed);
  30809. const int timeUntilFirstTimer = (firstTimer != 0) ? firstTimer->countdownMs
  30810. : 1000;
  30811. lock.exit();
  30812. if (timeUntilFirstTimer <= 0)
  30813. {
  30814. if (callbackNeeded.set (true))
  30815. {
  30816. postMessage (new Message());
  30817. const uint32 messageDeliveryTimeout = now + 2000;
  30818. while (callbackNeeded.get())
  30819. {
  30820. wait (4);
  30821. if (threadShouldExit())
  30822. return;
  30823. if (Time::getMillisecondCounter() > messageDeliveryTimeout)
  30824. break;
  30825. }
  30826. }
  30827. }
  30828. else
  30829. {
  30830. // don't wait for too long because running this loop also helps keep the
  30831. // Time::getApproximateMillisecondTimer value stay up-to-date
  30832. wait (jlimit (1, 50, timeUntilFirstTimer));
  30833. }
  30834. }
  30835. }
  30836. void handleMessage (const Message&)
  30837. {
  30838. const ScopedLock sl (lock);
  30839. while (firstTimer != 0 && firstTimer->countdownMs <= 0)
  30840. {
  30841. Timer* const t = firstTimer;
  30842. t->countdownMs = t->periodMs;
  30843. removeTimer (t);
  30844. addTimer (t);
  30845. const ScopedUnlock ul (lock);
  30846. JUCE_TRY
  30847. {
  30848. t->timerCallback();
  30849. }
  30850. JUCE_CATCH_EXCEPTION
  30851. }
  30852. callbackNeeded.set (false);
  30853. }
  30854. static void callAnyTimersSynchronously()
  30855. {
  30856. if (InternalTimerThread::instance != 0)
  30857. {
  30858. const Message m;
  30859. InternalTimerThread::instance->handleMessage (m);
  30860. }
  30861. }
  30862. static inline void add (Timer* const tim) throw()
  30863. {
  30864. if (instance == 0)
  30865. instance = new InternalTimerThread();
  30866. const ScopedLock sl (instance->lock);
  30867. instance->addTimer (tim);
  30868. }
  30869. static inline void remove (Timer* const tim) throw()
  30870. {
  30871. if (instance != 0)
  30872. {
  30873. const ScopedLock sl (instance->lock);
  30874. instance->removeTimer (tim);
  30875. }
  30876. }
  30877. static inline void resetCounter (Timer* const tim,
  30878. const int newCounter) throw()
  30879. {
  30880. if (instance != 0)
  30881. {
  30882. tim->countdownMs = newCounter;
  30883. tim->periodMs = newCounter;
  30884. if ((tim->next != 0 && tim->next->countdownMs < tim->countdownMs)
  30885. || (tim->previous != 0 && tim->previous->countdownMs > tim->countdownMs))
  30886. {
  30887. const ScopedLock sl (instance->lock);
  30888. instance->removeTimer (tim);
  30889. instance->addTimer (tim);
  30890. }
  30891. }
  30892. }
  30893. private:
  30894. friend class Timer;
  30895. static InternalTimerThread* instance;
  30896. static CriticalSection lock;
  30897. Timer* volatile firstTimer;
  30898. class AtomicBool
  30899. {
  30900. public:
  30901. AtomicBool (const bool value) throw() : value (static_cast<int32> (value)) {}
  30902. ~AtomicBool() throw() {}
  30903. bool get() const throw() { return value != 0; }
  30904. bool set (const bool newValue) { return Atomic::compareAndExchange (value, newValue ? 1 : 0, value) != 0; }
  30905. private:
  30906. int32 value;
  30907. AtomicBool (const AtomicBool&);
  30908. AtomicBool& operator= (const AtomicBool&);
  30909. };
  30910. AtomicBool callbackNeeded;
  30911. void addTimer (Timer* const t) throw()
  30912. {
  30913. #ifdef JUCE_DEBUG
  30914. Timer* tt = firstTimer;
  30915. while (tt != 0)
  30916. {
  30917. // trying to add a timer that's already here - shouldn't get to this point,
  30918. // so if you get this assertion, let me know!
  30919. jassert (tt != t);
  30920. tt = tt->next;
  30921. }
  30922. jassert (t->previous == 0 && t->next == 0);
  30923. #endif
  30924. Timer* i = firstTimer;
  30925. if (i == 0 || i->countdownMs > t->countdownMs)
  30926. {
  30927. t->next = firstTimer;
  30928. firstTimer = t;
  30929. }
  30930. else
  30931. {
  30932. while (i->next != 0 && i->next->countdownMs <= t->countdownMs)
  30933. i = i->next;
  30934. jassert (i != 0);
  30935. t->next = i->next;
  30936. t->previous = i;
  30937. i->next = t;
  30938. }
  30939. if (t->next != 0)
  30940. t->next->previous = t;
  30941. jassert ((t->next == 0 || t->next->countdownMs >= t->countdownMs)
  30942. && (t->previous == 0 || t->previous->countdownMs <= t->countdownMs));
  30943. notify();
  30944. }
  30945. void removeTimer (Timer* const t) throw()
  30946. {
  30947. #ifdef JUCE_DEBUG
  30948. Timer* tt = firstTimer;
  30949. bool found = false;
  30950. while (tt != 0)
  30951. {
  30952. if (tt == t)
  30953. {
  30954. found = true;
  30955. break;
  30956. }
  30957. tt = tt->next;
  30958. }
  30959. // trying to remove a timer that's not here - shouldn't get to this point,
  30960. // so if you get this assertion, let me know!
  30961. jassert (found);
  30962. #endif
  30963. if (t->previous != 0)
  30964. {
  30965. jassert (firstTimer != t);
  30966. t->previous->next = t->next;
  30967. }
  30968. else
  30969. {
  30970. jassert (firstTimer == t);
  30971. firstTimer = t->next;
  30972. }
  30973. if (t->next != 0)
  30974. t->next->previous = t->previous;
  30975. t->next = 0;
  30976. t->previous = 0;
  30977. }
  30978. void decrementAllCounters (const int numMillisecs) const
  30979. {
  30980. Timer* t = firstTimer;
  30981. while (t != 0)
  30982. {
  30983. t->countdownMs -= numMillisecs;
  30984. t = t->next;
  30985. }
  30986. }
  30987. void handleAsyncUpdate()
  30988. {
  30989. startThread (7);
  30990. }
  30991. InternalTimerThread (const InternalTimerThread&);
  30992. InternalTimerThread& operator= (const InternalTimerThread&);
  30993. };
  30994. InternalTimerThread* InternalTimerThread::instance = 0;
  30995. CriticalSection InternalTimerThread::lock;
  30996. void juce_callAnyTimersSynchronously()
  30997. {
  30998. InternalTimerThread::callAnyTimersSynchronously();
  30999. }
  31000. #ifdef JUCE_DEBUG
  31001. static SortedSet <Timer*> activeTimers;
  31002. #endif
  31003. Timer::Timer() throw()
  31004. : countdownMs (0),
  31005. periodMs (0),
  31006. previous (0),
  31007. next (0)
  31008. {
  31009. #ifdef JUCE_DEBUG
  31010. activeTimers.add (this);
  31011. #endif
  31012. }
  31013. Timer::Timer (const Timer&) throw()
  31014. : countdownMs (0),
  31015. periodMs (0),
  31016. previous (0),
  31017. next (0)
  31018. {
  31019. #ifdef JUCE_DEBUG
  31020. activeTimers.add (this);
  31021. #endif
  31022. }
  31023. Timer::~Timer()
  31024. {
  31025. stopTimer();
  31026. #ifdef JUCE_DEBUG
  31027. activeTimers.removeValue (this);
  31028. #endif
  31029. }
  31030. void Timer::startTimer (const int interval) throw()
  31031. {
  31032. const ScopedLock sl (InternalTimerThread::lock);
  31033. #ifdef JUCE_DEBUG
  31034. // this isn't a valid object! Your timer might be a dangling pointer or something..
  31035. jassert (activeTimers.contains (this));
  31036. #endif
  31037. if (periodMs == 0)
  31038. {
  31039. countdownMs = interval;
  31040. periodMs = jmax (1, interval);
  31041. InternalTimerThread::add (this);
  31042. }
  31043. else
  31044. {
  31045. InternalTimerThread::resetCounter (this, interval);
  31046. }
  31047. }
  31048. void Timer::stopTimer() throw()
  31049. {
  31050. const ScopedLock sl (InternalTimerThread::lock);
  31051. #ifdef JUCE_DEBUG
  31052. // this isn't a valid object! Your timer might be a dangling pointer or something..
  31053. jassert (activeTimers.contains (this));
  31054. #endif
  31055. if (periodMs > 0)
  31056. {
  31057. InternalTimerThread::remove (this);
  31058. periodMs = 0;
  31059. }
  31060. }
  31061. END_JUCE_NAMESPACE
  31062. /*** End of inlined file: juce_Timer.cpp ***/
  31063. #endif
  31064. #if JUCE_BUILD_GUI
  31065. /*** Start of inlined file: juce_Component.cpp ***/
  31066. BEGIN_JUCE_NAMESPACE
  31067. Component* Component::componentUnderMouse = 0;
  31068. Component* Component::currentlyFocusedComponent = 0;
  31069. static Array <Component*> modalComponentStack, modalComponentReturnValueKeys;
  31070. static Array <int> modalReturnValues;
  31071. static const int customCommandMessage = 0x7fff0001;
  31072. static const int exitModalStateMessage = 0x7fff0002;
  31073. static int unboundedMouseOffsetX = 0;
  31074. static int unboundedMouseOffsetY = 0;
  31075. static bool isUnboundedMouseModeOn = false;
  31076. static bool isCursorVisibleUntilOffscreen;
  31077. #define checkMessageManagerIsLocked jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  31078. static uint32 nextComponentUID = 0;
  31079. Component::Component() throw()
  31080. : parentComponent_ (0),
  31081. componentUID (++nextComponentUID),
  31082. numDeepMouseListeners (0),
  31083. lookAndFeel_ (0),
  31084. effect_ (0),
  31085. bufferedImage_ (0),
  31086. mouseListeners_ (0),
  31087. keyListeners_ (0),
  31088. componentListeners_ (0),
  31089. componentFlags_ (0)
  31090. {
  31091. }
  31092. Component::Component (const String& name) throw()
  31093. : componentName_ (name),
  31094. parentComponent_ (0),
  31095. componentUID (++nextComponentUID),
  31096. numDeepMouseListeners (0),
  31097. lookAndFeel_ (0),
  31098. effect_ (0),
  31099. bufferedImage_ (0),
  31100. mouseListeners_ (0),
  31101. keyListeners_ (0),
  31102. componentListeners_ (0),
  31103. componentFlags_ (0)
  31104. {
  31105. }
  31106. Component::~Component()
  31107. {
  31108. if (parentComponent_ != 0)
  31109. {
  31110. parentComponent_->removeChildComponent (this);
  31111. }
  31112. else if ((currentlyFocusedComponent == this)
  31113. || isParentOf (currentlyFocusedComponent))
  31114. {
  31115. giveAwayFocus();
  31116. }
  31117. if (componentUnderMouse == this)
  31118. componentUnderMouse = 0;
  31119. if (flags.hasHeavyweightPeerFlag)
  31120. removeFromDesktop();
  31121. modalComponentStack.removeValue (this);
  31122. for (int i = childComponentList_.size(); --i >= 0;)
  31123. childComponentList_.getUnchecked(i)->parentComponent_ = 0;
  31124. delete bufferedImage_;
  31125. delete mouseListeners_;
  31126. delete keyListeners_;
  31127. delete componentListeners_;
  31128. }
  31129. void Component::setName (const String& name)
  31130. {
  31131. // if component methods are being called from threads other than the message
  31132. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31133. checkMessageManagerIsLocked
  31134. if (componentName_ != name)
  31135. {
  31136. componentName_ = name;
  31137. if (flags.hasHeavyweightPeerFlag)
  31138. {
  31139. ComponentPeer* const peer = getPeer();
  31140. jassert (peer != 0);
  31141. if (peer != 0)
  31142. peer->setTitle (name);
  31143. }
  31144. if (componentListeners_ != 0)
  31145. {
  31146. const ComponentDeletionWatcher deletionChecker (this);
  31147. for (int i = componentListeners_->size(); --i >= 0;)
  31148. {
  31149. ((ComponentListener*) componentListeners_->getUnchecked (i))
  31150. ->componentNameChanged (*this);
  31151. if (deletionChecker.hasBeenDeleted())
  31152. return;
  31153. i = jmin (i, componentListeners_->size());
  31154. }
  31155. }
  31156. }
  31157. }
  31158. void Component::setVisible (bool shouldBeVisible)
  31159. {
  31160. if (flags.visibleFlag != shouldBeVisible)
  31161. {
  31162. // if component methods are being called from threads other than the message
  31163. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31164. checkMessageManagerIsLocked
  31165. const ComponentDeletionWatcher deletionChecker (this);
  31166. flags.visibleFlag = shouldBeVisible;
  31167. internalRepaint (0, 0, getWidth(), getHeight());
  31168. sendFakeMouseMove();
  31169. if (! shouldBeVisible)
  31170. {
  31171. if (currentlyFocusedComponent == this
  31172. || isParentOf (currentlyFocusedComponent))
  31173. {
  31174. if (parentComponent_ != 0)
  31175. parentComponent_->grabKeyboardFocus();
  31176. else
  31177. giveAwayFocus();
  31178. }
  31179. }
  31180. sendVisibilityChangeMessage();
  31181. if ((! deletionChecker.hasBeenDeleted()) && flags.hasHeavyweightPeerFlag)
  31182. {
  31183. ComponentPeer* const peer = getPeer();
  31184. jassert (peer != 0);
  31185. if (peer != 0)
  31186. {
  31187. peer->setVisible (shouldBeVisible);
  31188. internalHierarchyChanged();
  31189. }
  31190. }
  31191. }
  31192. }
  31193. void Component::visibilityChanged()
  31194. {
  31195. }
  31196. void Component::sendVisibilityChangeMessage()
  31197. {
  31198. const ComponentDeletionWatcher deletionChecker (this);
  31199. visibilityChanged();
  31200. if ((! deletionChecker.hasBeenDeleted()) && componentListeners_ != 0)
  31201. {
  31202. for (int i = componentListeners_->size(); --i >= 0;)
  31203. {
  31204. ((ComponentListener*) componentListeners_->getUnchecked (i))
  31205. ->componentVisibilityChanged (*this);
  31206. if (deletionChecker.hasBeenDeleted())
  31207. return;
  31208. i = jmin (i, componentListeners_->size());
  31209. }
  31210. }
  31211. }
  31212. bool Component::isShowing() const throw()
  31213. {
  31214. if (flags.visibleFlag)
  31215. {
  31216. if (parentComponent_ != 0)
  31217. {
  31218. return parentComponent_->isShowing();
  31219. }
  31220. else
  31221. {
  31222. const ComponentPeer* const peer = getPeer();
  31223. return peer != 0 && ! peer->isMinimised();
  31224. }
  31225. }
  31226. return false;
  31227. }
  31228. class FadeOutProxyComponent : public Component,
  31229. public Timer
  31230. {
  31231. public:
  31232. FadeOutProxyComponent (Component* comp,
  31233. const int fadeLengthMs,
  31234. const int deltaXToMove,
  31235. const int deltaYToMove,
  31236. const float scaleFactorAtEnd)
  31237. : lastTime (0),
  31238. alpha (1.0f),
  31239. scale (1.0f)
  31240. {
  31241. image = comp->createComponentSnapshot (Rectangle<int> (0, 0, comp->getWidth(), comp->getHeight()));
  31242. setBounds (comp->getBounds());
  31243. comp->getParentComponent()->addAndMakeVisible (this);
  31244. toBehind (comp);
  31245. alphaChangePerMs = -1.0f / (float)fadeLengthMs;
  31246. centreX = comp->getX() + comp->getWidth() * 0.5f;
  31247. xChangePerMs = deltaXToMove / (float)fadeLengthMs;
  31248. centreY = comp->getY() + comp->getHeight() * 0.5f;
  31249. yChangePerMs = deltaYToMove / (float)fadeLengthMs;
  31250. scaleChangePerMs = (scaleFactorAtEnd - 1.0f) / (float)fadeLengthMs;
  31251. setInterceptsMouseClicks (false, false);
  31252. // 30 fps is enough for a fade, but we need a higher rate if it's moving as well..
  31253. startTimer (1000 / ((deltaXToMove == 0 && deltaYToMove == 0) ? 30 : 50));
  31254. }
  31255. ~FadeOutProxyComponent()
  31256. {
  31257. delete image;
  31258. }
  31259. void paint (Graphics& g)
  31260. {
  31261. g.setOpacity (alpha);
  31262. g.drawImage (image,
  31263. 0, 0, getWidth(), getHeight(),
  31264. 0, 0, image->getWidth(), image->getHeight());
  31265. }
  31266. void timerCallback()
  31267. {
  31268. const uint32 now = Time::getMillisecondCounter();
  31269. if (lastTime == 0)
  31270. lastTime = now;
  31271. const int msPassed = (now > lastTime) ? now - lastTime : 0;
  31272. lastTime = now;
  31273. alpha += alphaChangePerMs * msPassed;
  31274. if (alpha > 0)
  31275. {
  31276. if (xChangePerMs != 0.0f || yChangePerMs != 0.0f || scaleChangePerMs != 0.0f)
  31277. {
  31278. centreX += xChangePerMs * msPassed;
  31279. centreY += yChangePerMs * msPassed;
  31280. scale += scaleChangePerMs * msPassed;
  31281. const int w = roundToInt (image->getWidth() * scale);
  31282. const int h = roundToInt (image->getHeight() * scale);
  31283. setBounds (roundToInt (centreX) - w / 2,
  31284. roundToInt (centreY) - h / 2,
  31285. w, h);
  31286. }
  31287. repaint();
  31288. }
  31289. else
  31290. {
  31291. delete this;
  31292. }
  31293. }
  31294. juce_UseDebuggingNewOperator
  31295. private:
  31296. Image* image;
  31297. uint32 lastTime;
  31298. float alpha, alphaChangePerMs;
  31299. float centreX, xChangePerMs;
  31300. float centreY, yChangePerMs;
  31301. float scale, scaleChangePerMs;
  31302. FadeOutProxyComponent (const FadeOutProxyComponent&);
  31303. const FadeOutProxyComponent& operator= (const FadeOutProxyComponent&);
  31304. };
  31305. void Component::fadeOutComponent (const int millisecondsToFade,
  31306. const int deltaXToMove,
  31307. const int deltaYToMove,
  31308. const float scaleFactorAtEnd)
  31309. {
  31310. //xxx won't work for comps without parents
  31311. if (isShowing() && millisecondsToFade > 0)
  31312. new FadeOutProxyComponent (this, millisecondsToFade,
  31313. deltaXToMove, deltaYToMove, scaleFactorAtEnd);
  31314. setVisible (false);
  31315. }
  31316. bool Component::isValidComponent() const throw()
  31317. {
  31318. return (this != 0) && isValidMessageListener();
  31319. }
  31320. void* Component::getWindowHandle() const throw()
  31321. {
  31322. const ComponentPeer* const peer = getPeer();
  31323. if (peer != 0)
  31324. return peer->getNativeHandle();
  31325. return 0;
  31326. }
  31327. void Component::addToDesktop (int styleWanted, void* nativeWindowToAttachTo)
  31328. {
  31329. // if component methods are being called from threads other than the message
  31330. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31331. checkMessageManagerIsLocked
  31332. if (isOpaque())
  31333. styleWanted &= ~ComponentPeer::windowIsSemiTransparent;
  31334. else
  31335. styleWanted |= ComponentPeer::windowIsSemiTransparent;
  31336. int currentStyleFlags = 0;
  31337. // don't use getPeer(), so that we only get the peer that's specifically
  31338. // for this comp, and not for one of its parents.
  31339. ComponentPeer* peer = ComponentPeer::getPeerFor (this);
  31340. if (peer != 0)
  31341. currentStyleFlags = peer->getStyleFlags();
  31342. if (styleWanted != currentStyleFlags || ! flags.hasHeavyweightPeerFlag)
  31343. {
  31344. const ComponentDeletionWatcher deletionChecker (this);
  31345. #if JUCE_LINUX
  31346. // it's wise to give the component a non-zero size before
  31347. // putting it on the desktop, as X windows get confused by this, and
  31348. // a (1, 1) minimum size is enforced here.
  31349. setSize (jmax (1, getWidth()),
  31350. jmax (1, getHeight()));
  31351. #endif
  31352. int x = 0, y = 0;
  31353. relativePositionToGlobal (x, y);
  31354. bool wasFullscreen = false;
  31355. bool wasMinimised = false;
  31356. ComponentBoundsConstrainer* currentConstainer = 0;
  31357. Rectangle<int> oldNonFullScreenBounds;
  31358. if (peer != 0)
  31359. {
  31360. wasFullscreen = peer->isFullScreen();
  31361. wasMinimised = peer->isMinimised();
  31362. currentConstainer = peer->getConstrainer();
  31363. oldNonFullScreenBounds = peer->getNonFullScreenBounds();
  31364. removeFromDesktop();
  31365. setTopLeftPosition (x, y);
  31366. }
  31367. if (parentComponent_ != 0)
  31368. parentComponent_->removeChildComponent (this);
  31369. if (! deletionChecker.hasBeenDeleted())
  31370. {
  31371. flags.hasHeavyweightPeerFlag = true;
  31372. peer = createNewPeer (styleWanted, nativeWindowToAttachTo);
  31373. Desktop::getInstance().addDesktopComponent (this);
  31374. bounds_.setPosition (x, y);
  31375. peer->setBounds (x, y, getWidth(), getHeight(), false);
  31376. peer->setVisible (isVisible());
  31377. if (wasFullscreen)
  31378. {
  31379. peer->setFullScreen (true);
  31380. peer->setNonFullScreenBounds (oldNonFullScreenBounds);
  31381. }
  31382. if (wasMinimised)
  31383. peer->setMinimised (true);
  31384. if (isAlwaysOnTop())
  31385. peer->setAlwaysOnTop (true);
  31386. peer->setConstrainer (currentConstainer);
  31387. repaint();
  31388. }
  31389. internalHierarchyChanged();
  31390. }
  31391. }
  31392. void Component::removeFromDesktop()
  31393. {
  31394. // if component methods are being called from threads other than the message
  31395. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31396. checkMessageManagerIsLocked
  31397. if (flags.hasHeavyweightPeerFlag)
  31398. {
  31399. ComponentPeer* const peer = ComponentPeer::getPeerFor (this);
  31400. flags.hasHeavyweightPeerFlag = false;
  31401. jassert (peer != 0);
  31402. delete peer;
  31403. Desktop::getInstance().removeDesktopComponent (this);
  31404. }
  31405. }
  31406. bool Component::isOnDesktop() const throw()
  31407. {
  31408. return flags.hasHeavyweightPeerFlag;
  31409. }
  31410. void Component::userTriedToCloseWindow()
  31411. {
  31412. /* This means that the user's trying to get rid of your window with the 'close window' system
  31413. menu option (on windows) or possibly the task manager - you should really handle this
  31414. and delete or hide your component in an appropriate way.
  31415. If you want to ignore the event and don't want to trigger this assertion, just override
  31416. this method and do nothing.
  31417. */
  31418. jassertfalse
  31419. }
  31420. void Component::minimisationStateChanged (bool)
  31421. {
  31422. }
  31423. void Component::setOpaque (const bool shouldBeOpaque) throw()
  31424. {
  31425. if (shouldBeOpaque != flags.opaqueFlag)
  31426. {
  31427. flags.opaqueFlag = shouldBeOpaque;
  31428. if (flags.hasHeavyweightPeerFlag)
  31429. {
  31430. const ComponentPeer* const peer = ComponentPeer::getPeerFor (this);
  31431. if (peer != 0)
  31432. {
  31433. // to make it recreate the heavyweight window
  31434. addToDesktop (peer->getStyleFlags());
  31435. }
  31436. }
  31437. repaint();
  31438. }
  31439. }
  31440. bool Component::isOpaque() const throw()
  31441. {
  31442. return flags.opaqueFlag;
  31443. }
  31444. void Component::setBufferedToImage (const bool shouldBeBuffered) throw()
  31445. {
  31446. if (shouldBeBuffered != flags.bufferToImageFlag)
  31447. {
  31448. deleteAndZero (bufferedImage_);
  31449. flags.bufferToImageFlag = shouldBeBuffered;
  31450. }
  31451. }
  31452. void Component::toFront (const bool setAsForeground)
  31453. {
  31454. // if component methods are being called from threads other than the message
  31455. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31456. checkMessageManagerIsLocked
  31457. if (flags.hasHeavyweightPeerFlag)
  31458. {
  31459. ComponentPeer* const peer = getPeer();
  31460. if (peer != 0)
  31461. {
  31462. peer->toFront (setAsForeground);
  31463. if (setAsForeground && ! hasKeyboardFocus (true))
  31464. grabKeyboardFocus();
  31465. }
  31466. }
  31467. else if (parentComponent_ != 0)
  31468. {
  31469. if (parentComponent_->childComponentList_.getLast() != this)
  31470. {
  31471. const int index = parentComponent_->childComponentList_.indexOf (this);
  31472. if (index >= 0)
  31473. {
  31474. int insertIndex = -1;
  31475. if (! flags.alwaysOnTopFlag)
  31476. {
  31477. insertIndex = parentComponent_->childComponentList_.size() - 1;
  31478. while (insertIndex > 0
  31479. && parentComponent_->childComponentList_.getUnchecked (insertIndex)->isAlwaysOnTop())
  31480. {
  31481. --insertIndex;
  31482. }
  31483. }
  31484. if (index != insertIndex)
  31485. {
  31486. parentComponent_->childComponentList_.move (index, insertIndex);
  31487. sendFakeMouseMove();
  31488. repaintParent();
  31489. }
  31490. }
  31491. }
  31492. if (setAsForeground)
  31493. {
  31494. internalBroughtToFront();
  31495. grabKeyboardFocus();
  31496. }
  31497. }
  31498. }
  31499. void Component::toBehind (Component* const other)
  31500. {
  31501. if (other != 0)
  31502. {
  31503. // the two components must belong to the same parent..
  31504. jassert (parentComponent_ == other->parentComponent_);
  31505. if (parentComponent_ != 0)
  31506. {
  31507. const int index = parentComponent_->childComponentList_.indexOf (this);
  31508. int otherIndex = parentComponent_->childComponentList_.indexOf (other);
  31509. if (index >= 0
  31510. && otherIndex >= 0
  31511. && index != otherIndex - 1
  31512. && other != this)
  31513. {
  31514. if (index < otherIndex)
  31515. --otherIndex;
  31516. parentComponent_->childComponentList_.move (index, otherIndex);
  31517. sendFakeMouseMove();
  31518. repaintParent();
  31519. }
  31520. }
  31521. else if (isOnDesktop())
  31522. {
  31523. jassert (other->isOnDesktop());
  31524. if (other->isOnDesktop())
  31525. {
  31526. ComponentPeer* const us = getPeer();
  31527. ComponentPeer* const them = other->getPeer();
  31528. jassert (us != 0 && them != 0);
  31529. if (us != 0 && them != 0)
  31530. us->toBehind (them);
  31531. }
  31532. }
  31533. }
  31534. }
  31535. void Component::toBack()
  31536. {
  31537. if (isOnDesktop())
  31538. {
  31539. jassertfalse //xxx need to add this to native window
  31540. }
  31541. else if (parentComponent_ != 0
  31542. && parentComponent_->childComponentList_.getFirst() != this)
  31543. {
  31544. const int index = parentComponent_->childComponentList_.indexOf (this);
  31545. if (index > 0)
  31546. {
  31547. int insertIndex = 0;
  31548. if (flags.alwaysOnTopFlag)
  31549. {
  31550. while (insertIndex < parentComponent_->childComponentList_.size()
  31551. && ! parentComponent_->childComponentList_.getUnchecked (insertIndex)->isAlwaysOnTop())
  31552. {
  31553. ++insertIndex;
  31554. }
  31555. }
  31556. if (index != insertIndex)
  31557. {
  31558. parentComponent_->childComponentList_.move (index, insertIndex);
  31559. sendFakeMouseMove();
  31560. repaintParent();
  31561. }
  31562. }
  31563. }
  31564. }
  31565. void Component::setAlwaysOnTop (const bool shouldStayOnTop)
  31566. {
  31567. if (shouldStayOnTop != flags.alwaysOnTopFlag)
  31568. {
  31569. flags.alwaysOnTopFlag = shouldStayOnTop;
  31570. if (isOnDesktop())
  31571. {
  31572. ComponentPeer* const peer = getPeer();
  31573. jassert (peer != 0);
  31574. if (peer != 0)
  31575. {
  31576. if (! peer->setAlwaysOnTop (shouldStayOnTop))
  31577. {
  31578. // some kinds of peer can't change their always-on-top status, so
  31579. // for these, we'll need to create a new window
  31580. const int oldFlags = peer->getStyleFlags();
  31581. removeFromDesktop();
  31582. addToDesktop (oldFlags);
  31583. }
  31584. }
  31585. }
  31586. if (shouldStayOnTop)
  31587. toFront (false);
  31588. internalHierarchyChanged();
  31589. }
  31590. }
  31591. bool Component::isAlwaysOnTop() const throw()
  31592. {
  31593. return flags.alwaysOnTopFlag;
  31594. }
  31595. int Component::proportionOfWidth (const float proportion) const throw()
  31596. {
  31597. return roundToInt (proportion * bounds_.getWidth());
  31598. }
  31599. int Component::proportionOfHeight (const float proportion) const throw()
  31600. {
  31601. return roundToInt (proportion * bounds_.getHeight());
  31602. }
  31603. int Component::getParentWidth() const throw()
  31604. {
  31605. return (parentComponent_ != 0) ? parentComponent_->getWidth()
  31606. : getParentMonitorArea().getWidth();
  31607. }
  31608. int Component::getParentHeight() const throw()
  31609. {
  31610. return (parentComponent_ != 0) ? parentComponent_->getHeight()
  31611. : getParentMonitorArea().getHeight();
  31612. }
  31613. int Component::getScreenX() const throw()
  31614. {
  31615. return (parentComponent_ != 0) ? parentComponent_->getScreenX() + getX()
  31616. : (flags.hasHeavyweightPeerFlag ? getPeer()->getScreenX()
  31617. : getX());
  31618. }
  31619. int Component::getScreenY() const throw()
  31620. {
  31621. return (parentComponent_ != 0) ? parentComponent_->getScreenY() + getY()
  31622. : (flags.hasHeavyweightPeerFlag ? getPeer()->getScreenY()
  31623. : getY());
  31624. }
  31625. void Component::relativePositionToGlobal (int& x, int& y) const throw()
  31626. {
  31627. const Component* c = this;
  31628. do
  31629. {
  31630. if (c->flags.hasHeavyweightPeerFlag)
  31631. {
  31632. c->getPeer()->relativePositionToGlobal (x, y);
  31633. break;
  31634. }
  31635. x += c->getX();
  31636. y += c->getY();
  31637. c = c->parentComponent_;
  31638. }
  31639. while (c != 0);
  31640. }
  31641. void Component::globalPositionToRelative (int& x, int& y) const throw()
  31642. {
  31643. if (flags.hasHeavyweightPeerFlag)
  31644. {
  31645. getPeer()->globalPositionToRelative (x, y);
  31646. }
  31647. else
  31648. {
  31649. if (parentComponent_ != 0)
  31650. parentComponent_->globalPositionToRelative (x, y);
  31651. x -= getX();
  31652. y -= getY();
  31653. }
  31654. }
  31655. void Component::relativePositionToOtherComponent (const Component* const targetComponent, int& x, int& y) const throw()
  31656. {
  31657. if (targetComponent != 0)
  31658. {
  31659. const Component* c = this;
  31660. do
  31661. {
  31662. if (c == targetComponent)
  31663. return;
  31664. if (c->flags.hasHeavyweightPeerFlag)
  31665. {
  31666. c->getPeer()->relativePositionToGlobal (x, y);
  31667. break;
  31668. }
  31669. x += c->getX();
  31670. y += c->getY();
  31671. c = c->parentComponent_;
  31672. }
  31673. while (c != 0);
  31674. targetComponent->globalPositionToRelative (x, y);
  31675. }
  31676. }
  31677. void Component::setBounds (int x, int y, int w, int h)
  31678. {
  31679. // if component methods are being called from threads other than the message
  31680. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31681. checkMessageManagerIsLocked
  31682. if (w < 0) w = 0;
  31683. if (h < 0) h = 0;
  31684. const bool wasResized = (getWidth() != w || getHeight() != h);
  31685. const bool wasMoved = (getX() != x || getY() != y);
  31686. #ifdef JUCE_DEBUG
  31687. // It's a very bad idea to try to resize a window during its paint() method!
  31688. jassert (! (flags.isInsidePaintCall && wasResized && isOnDesktop()));
  31689. #endif
  31690. if (wasMoved || wasResized)
  31691. {
  31692. if (flags.visibleFlag)
  31693. {
  31694. // send a fake mouse move to trigger enter/exit messages if needed..
  31695. sendFakeMouseMove();
  31696. if (! flags.hasHeavyweightPeerFlag)
  31697. repaintParent();
  31698. }
  31699. bounds_.setBounds (x, y, w, h);
  31700. if (wasResized)
  31701. repaint();
  31702. else if (! flags.hasHeavyweightPeerFlag)
  31703. repaintParent();
  31704. if (flags.hasHeavyweightPeerFlag)
  31705. {
  31706. ComponentPeer* const peer = getPeer();
  31707. if (peer != 0)
  31708. {
  31709. if (wasMoved && wasResized)
  31710. peer->setBounds (getX(), getY(), getWidth(), getHeight(), false);
  31711. else if (wasMoved)
  31712. peer->setPosition (getX(), getY());
  31713. else if (wasResized)
  31714. peer->setSize (getWidth(), getHeight());
  31715. }
  31716. }
  31717. sendMovedResizedMessages (wasMoved, wasResized);
  31718. }
  31719. }
  31720. void Component::sendMovedResizedMessages (const bool wasMoved, const bool wasResized)
  31721. {
  31722. JUCE_TRY
  31723. {
  31724. if (wasMoved)
  31725. moved();
  31726. if (wasResized)
  31727. {
  31728. resized();
  31729. for (int i = childComponentList_.size(); --i >= 0;)
  31730. {
  31731. childComponentList_.getUnchecked(i)->parentSizeChanged();
  31732. i = jmin (i, childComponentList_.size());
  31733. }
  31734. }
  31735. if (parentComponent_ != 0)
  31736. parentComponent_->childBoundsChanged (this);
  31737. if (componentListeners_ != 0)
  31738. {
  31739. const ComponentDeletionWatcher deletionChecker (this);
  31740. for (int i = componentListeners_->size(); --i >= 0;)
  31741. {
  31742. ((ComponentListener*) componentListeners_->getUnchecked (i))
  31743. ->componentMovedOrResized (*this, wasMoved, wasResized);
  31744. if (deletionChecker.hasBeenDeleted())
  31745. return;
  31746. i = jmin (i, componentListeners_->size());
  31747. }
  31748. }
  31749. }
  31750. JUCE_CATCH_EXCEPTION
  31751. }
  31752. void Component::setSize (const int w, const int h)
  31753. {
  31754. setBounds (getX(), getY(), w, h);
  31755. }
  31756. void Component::setTopLeftPosition (const int x, const int y)
  31757. {
  31758. setBounds (x, y, getWidth(), getHeight());
  31759. }
  31760. void Component::setTopRightPosition (const int x, const int y)
  31761. {
  31762. setTopLeftPosition (x - getWidth(), y);
  31763. }
  31764. void Component::setBounds (const Rectangle<int>& r)
  31765. {
  31766. setBounds (r.getX(),
  31767. r.getY(),
  31768. r.getWidth(),
  31769. r.getHeight());
  31770. }
  31771. void Component::setBoundsRelative (const float x, const float y,
  31772. const float w, const float h)
  31773. {
  31774. const int pw = getParentWidth();
  31775. const int ph = getParentHeight();
  31776. setBounds (roundToInt (x * pw),
  31777. roundToInt (y * ph),
  31778. roundToInt (w * pw),
  31779. roundToInt (h * ph));
  31780. }
  31781. void Component::setCentrePosition (const int x, const int y)
  31782. {
  31783. setTopLeftPosition (x - getWidth() / 2,
  31784. y - getHeight() / 2);
  31785. }
  31786. void Component::setCentreRelative (const float x, const float y)
  31787. {
  31788. setCentrePosition (roundToInt (getParentWidth() * x),
  31789. roundToInt (getParentHeight() * y));
  31790. }
  31791. void Component::centreWithSize (const int width, const int height)
  31792. {
  31793. setBounds ((getParentWidth() - width) / 2,
  31794. (getParentHeight() - height) / 2,
  31795. width,
  31796. height);
  31797. }
  31798. void Component::setBoundsInset (const BorderSize& borders)
  31799. {
  31800. setBounds (borders.getLeft(),
  31801. borders.getTop(),
  31802. getParentWidth() - (borders.getLeftAndRight()),
  31803. getParentHeight() - (borders.getTopAndBottom()));
  31804. }
  31805. void Component::setBoundsToFit (int x, int y, int width, int height,
  31806. const Justification& justification,
  31807. const bool onlyReduceInSize)
  31808. {
  31809. // it's no good calling this method unless both the component and
  31810. // target rectangle have a finite size.
  31811. jassert (getWidth() > 0 && getHeight() > 0 && width > 0 && height > 0);
  31812. if (getWidth() > 0 && getHeight() > 0
  31813. && width > 0 && height > 0)
  31814. {
  31815. int newW, newH;
  31816. if (onlyReduceInSize && getWidth() <= width && getHeight() <= height)
  31817. {
  31818. newW = getWidth();
  31819. newH = getHeight();
  31820. }
  31821. else
  31822. {
  31823. const double imageRatio = getHeight() / (double) getWidth();
  31824. const double targetRatio = height / (double) width;
  31825. if (imageRatio <= targetRatio)
  31826. {
  31827. newW = width;
  31828. newH = jmin (height, roundToInt (newW * imageRatio));
  31829. }
  31830. else
  31831. {
  31832. newH = height;
  31833. newW = jmin (width, roundToInt (newH / imageRatio));
  31834. }
  31835. }
  31836. if (newW > 0 && newH > 0)
  31837. {
  31838. int newX, newY;
  31839. justification.applyToRectangle (newX, newY, newW, newH,
  31840. x, y, width, height);
  31841. setBounds (newX, newY, newW, newH);
  31842. }
  31843. }
  31844. }
  31845. bool Component::hitTest (int x, int y)
  31846. {
  31847. if (! flags.ignoresMouseClicksFlag)
  31848. return true;
  31849. if (flags.allowChildMouseClicksFlag)
  31850. {
  31851. for (int i = getNumChildComponents(); --i >= 0;)
  31852. {
  31853. Component* const c = getChildComponent (i);
  31854. if (c->isVisible()
  31855. && c->bounds_.contains (x, y)
  31856. && c->hitTest (x - c->getX(),
  31857. y - c->getY()))
  31858. {
  31859. return true;
  31860. }
  31861. }
  31862. }
  31863. return false;
  31864. }
  31865. void Component::setInterceptsMouseClicks (const bool allowClicks,
  31866. const bool allowClicksOnChildComponents) throw()
  31867. {
  31868. flags.ignoresMouseClicksFlag = ! allowClicks;
  31869. flags.allowChildMouseClicksFlag = allowClicksOnChildComponents;
  31870. }
  31871. void Component::getInterceptsMouseClicks (bool& allowsClicksOnThisComponent,
  31872. bool& allowsClicksOnChildComponents) const throw()
  31873. {
  31874. allowsClicksOnThisComponent = ! flags.ignoresMouseClicksFlag;
  31875. allowsClicksOnChildComponents = flags.allowChildMouseClicksFlag;
  31876. }
  31877. bool Component::contains (const int x, const int y)
  31878. {
  31879. if (((unsigned int) x) < (unsigned int) getWidth()
  31880. && ((unsigned int) y) < (unsigned int) getHeight()
  31881. && hitTest (x, y))
  31882. {
  31883. if (parentComponent_ != 0)
  31884. {
  31885. return parentComponent_->contains (x + getX(),
  31886. y + getY());
  31887. }
  31888. else if (flags.hasHeavyweightPeerFlag)
  31889. {
  31890. const ComponentPeer* const peer = getPeer();
  31891. if (peer != 0)
  31892. return peer->contains (x, y, true);
  31893. }
  31894. }
  31895. return false;
  31896. }
  31897. bool Component::reallyContains (int x, int y, const bool returnTrueIfWithinAChild)
  31898. {
  31899. if (! contains (x, y))
  31900. return false;
  31901. Component* p = this;
  31902. while (p->parentComponent_ != 0)
  31903. {
  31904. x += p->getX();
  31905. y += p->getY();
  31906. p = p->parentComponent_;
  31907. }
  31908. const Component* const c = p->getComponentAt (x, y);
  31909. return (c == this) || (returnTrueIfWithinAChild && isParentOf (c));
  31910. }
  31911. Component* Component::getComponentAt (const int x, const int y)
  31912. {
  31913. if (flags.visibleFlag
  31914. && ((unsigned int) x) < (unsigned int) getWidth()
  31915. && ((unsigned int) y) < (unsigned int) getHeight()
  31916. && hitTest (x, y))
  31917. {
  31918. for (int i = childComponentList_.size(); --i >= 0;)
  31919. {
  31920. Component* const child = childComponentList_.getUnchecked(i);
  31921. Component* const c = child->getComponentAt (x - child->getX(),
  31922. y - child->getY());
  31923. if (c != 0)
  31924. return c;
  31925. }
  31926. return this;
  31927. }
  31928. return 0;
  31929. }
  31930. void Component::addChildComponent (Component* const child, int zOrder)
  31931. {
  31932. // if component methods are being called from threads other than the message
  31933. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31934. checkMessageManagerIsLocked
  31935. if (child != 0 && child->parentComponent_ != this)
  31936. {
  31937. if (child->parentComponent_ != 0)
  31938. child->parentComponent_->removeChildComponent (child);
  31939. else
  31940. child->removeFromDesktop();
  31941. child->parentComponent_ = this;
  31942. if (child->isVisible())
  31943. child->repaintParent();
  31944. if (! child->isAlwaysOnTop())
  31945. {
  31946. if (zOrder < 0 || zOrder > childComponentList_.size())
  31947. zOrder = childComponentList_.size();
  31948. while (zOrder > 0)
  31949. {
  31950. if (! childComponentList_.getUnchecked (zOrder - 1)->isAlwaysOnTop())
  31951. break;
  31952. --zOrder;
  31953. }
  31954. }
  31955. childComponentList_.insert (zOrder, child);
  31956. child->internalHierarchyChanged();
  31957. internalChildrenChanged();
  31958. }
  31959. }
  31960. void Component::addAndMakeVisible (Component* const child, int zOrder)
  31961. {
  31962. if (child != 0)
  31963. {
  31964. child->setVisible (true);
  31965. addChildComponent (child, zOrder);
  31966. }
  31967. }
  31968. void Component::removeChildComponent (Component* const child)
  31969. {
  31970. removeChildComponent (childComponentList_.indexOf (child));
  31971. }
  31972. Component* Component::removeChildComponent (const int index)
  31973. {
  31974. // if component methods are being called from threads other than the message
  31975. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31976. checkMessageManagerIsLocked
  31977. Component* const child = childComponentList_ [index];
  31978. if (child != 0)
  31979. {
  31980. sendFakeMouseMove();
  31981. child->repaintParent();
  31982. childComponentList_.remove (index);
  31983. child->parentComponent_ = 0;
  31984. JUCE_TRY
  31985. {
  31986. if ((currentlyFocusedComponent == child)
  31987. || child->isParentOf (currentlyFocusedComponent))
  31988. {
  31989. // get rid first to force the grabKeyboardFocus to change to us.
  31990. giveAwayFocus();
  31991. grabKeyboardFocus();
  31992. }
  31993. }
  31994. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  31995. catch (const std::exception& e)
  31996. {
  31997. currentlyFocusedComponent = 0;
  31998. Desktop::getInstance().triggerFocusCallback();
  31999. JUCEApplication::sendUnhandledException (&e, __FILE__, __LINE__);
  32000. }
  32001. catch (...)
  32002. {
  32003. currentlyFocusedComponent = 0;
  32004. Desktop::getInstance().triggerFocusCallback();
  32005. JUCEApplication::sendUnhandledException (0, __FILE__, __LINE__);
  32006. }
  32007. #endif
  32008. child->internalHierarchyChanged();
  32009. internalChildrenChanged();
  32010. }
  32011. return child;
  32012. }
  32013. void Component::removeAllChildren()
  32014. {
  32015. for (int i = childComponentList_.size(); --i >= 0;)
  32016. removeChildComponent (i);
  32017. }
  32018. void Component::deleteAllChildren()
  32019. {
  32020. for (int i = childComponentList_.size(); --i >= 0;)
  32021. delete (removeChildComponent (i));
  32022. }
  32023. int Component::getNumChildComponents() const throw()
  32024. {
  32025. return childComponentList_.size();
  32026. }
  32027. Component* Component::getChildComponent (const int index) const throw()
  32028. {
  32029. return childComponentList_ [index];
  32030. }
  32031. int Component::getIndexOfChildComponent (const Component* const child) const throw()
  32032. {
  32033. return childComponentList_.indexOf (const_cast <Component*> (child));
  32034. }
  32035. Component* Component::getTopLevelComponent() const throw()
  32036. {
  32037. const Component* comp = this;
  32038. while (comp->parentComponent_ != 0)
  32039. comp = comp->parentComponent_;
  32040. return (Component*) comp;
  32041. }
  32042. bool Component::isParentOf (const Component* possibleChild) const throw()
  32043. {
  32044. while (possibleChild->isValidComponent())
  32045. {
  32046. possibleChild = possibleChild->parentComponent_;
  32047. if (possibleChild == this)
  32048. return true;
  32049. }
  32050. return false;
  32051. }
  32052. void Component::parentHierarchyChanged()
  32053. {
  32054. }
  32055. void Component::childrenChanged()
  32056. {
  32057. }
  32058. void Component::internalChildrenChanged()
  32059. {
  32060. const ComponentDeletionWatcher deletionChecker (this);
  32061. const bool hasListeners = componentListeners_ != 0;
  32062. childrenChanged();
  32063. if (hasListeners)
  32064. {
  32065. if (deletionChecker.hasBeenDeleted())
  32066. return;
  32067. for (int i = componentListeners_->size(); --i >= 0;)
  32068. {
  32069. ((ComponentListener*) componentListeners_->getUnchecked (i))
  32070. ->componentChildrenChanged (*this);
  32071. if (deletionChecker.hasBeenDeleted())
  32072. return;
  32073. i = jmin (i, componentListeners_->size());
  32074. }
  32075. }
  32076. }
  32077. void Component::internalHierarchyChanged()
  32078. {
  32079. parentHierarchyChanged();
  32080. const ComponentDeletionWatcher deletionChecker (this);
  32081. if (componentListeners_ != 0)
  32082. {
  32083. for (int i = componentListeners_->size(); --i >= 0;)
  32084. {
  32085. ((ComponentListener*) componentListeners_->getUnchecked (i))
  32086. ->componentParentHierarchyChanged (*this);
  32087. if (deletionChecker.hasBeenDeleted())
  32088. return;
  32089. i = jmin (i, componentListeners_->size());
  32090. }
  32091. }
  32092. for (int i = childComponentList_.size(); --i >= 0;)
  32093. {
  32094. childComponentList_.getUnchecked (i)->internalHierarchyChanged();
  32095. // you really shouldn't delete the parent component during a callback telling you
  32096. // that it's changed..
  32097. jassert (! deletionChecker.hasBeenDeleted());
  32098. if (deletionChecker.hasBeenDeleted())
  32099. return;
  32100. i = jmin (i, childComponentList_.size());
  32101. }
  32102. }
  32103. void* Component::runModalLoopCallback (void* userData)
  32104. {
  32105. return (void*) (pointer_sized_int) ((Component*) userData)->runModalLoop();
  32106. }
  32107. int Component::runModalLoop()
  32108. {
  32109. if (! MessageManager::getInstance()->isThisTheMessageThread())
  32110. {
  32111. // use a callback so this can be called from non-gui threads
  32112. return (int) (pointer_sized_int)
  32113. MessageManager::getInstance()
  32114. ->callFunctionOnMessageThread (&runModalLoopCallback, (void*) this);
  32115. }
  32116. Component* const prevFocused = getCurrentlyFocusedComponent();
  32117. ScopedPointer <ComponentDeletionWatcher> deletionChecker;
  32118. if (prevFocused != 0)
  32119. deletionChecker = new ComponentDeletionWatcher (prevFocused);
  32120. if (! isCurrentlyModal())
  32121. enterModalState();
  32122. JUCE_TRY
  32123. {
  32124. while (flags.currentlyModalFlag && flags.visibleFlag)
  32125. {
  32126. if (! MessageManager::getInstance()->runDispatchLoopUntil (20))
  32127. break;
  32128. // check whether this component was deleted during the last message
  32129. if (! isValidMessageListener())
  32130. break;
  32131. }
  32132. }
  32133. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  32134. catch (const std::exception& e)
  32135. {
  32136. JUCEApplication::sendUnhandledException (&e, __FILE__, __LINE__);
  32137. return 0;
  32138. }
  32139. catch (...)
  32140. {
  32141. JUCEApplication::sendUnhandledException (0, __FILE__, __LINE__);
  32142. return 0;
  32143. }
  32144. #endif
  32145. const int modalIndex = modalComponentReturnValueKeys.indexOf (this);
  32146. int returnValue = 0;
  32147. if (modalIndex >= 0)
  32148. {
  32149. modalComponentReturnValueKeys.remove (modalIndex);
  32150. returnValue = modalReturnValues.remove (modalIndex);
  32151. }
  32152. modalComponentStack.removeValue (this);
  32153. if (deletionChecker != 0 && ! deletionChecker->hasBeenDeleted())
  32154. prevFocused->grabKeyboardFocus();
  32155. return returnValue;
  32156. }
  32157. void Component::enterModalState (const bool takeKeyboardFocus_)
  32158. {
  32159. // if component methods are being called from threads other than the message
  32160. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  32161. checkMessageManagerIsLocked
  32162. // Check for an attempt to make a component modal when it already is!
  32163. // This can cause nasty problems..
  32164. jassert (! flags.currentlyModalFlag);
  32165. if (! isCurrentlyModal())
  32166. {
  32167. modalComponentStack.add (this);
  32168. modalComponentReturnValueKeys.add (this);
  32169. modalReturnValues.add (0);
  32170. flags.currentlyModalFlag = true;
  32171. setVisible (true);
  32172. if (takeKeyboardFocus_)
  32173. grabKeyboardFocus();
  32174. }
  32175. }
  32176. void Component::exitModalState (const int returnValue)
  32177. {
  32178. if (isCurrentlyModal())
  32179. {
  32180. if (MessageManager::getInstance()->isThisTheMessageThread())
  32181. {
  32182. const int modalIndex = modalComponentReturnValueKeys.indexOf (this);
  32183. if (modalIndex >= 0)
  32184. {
  32185. modalReturnValues.set (modalIndex, returnValue);
  32186. }
  32187. else
  32188. {
  32189. modalComponentReturnValueKeys.add (this);
  32190. modalReturnValues.add (returnValue);
  32191. }
  32192. modalComponentStack.removeValue (this);
  32193. flags.currentlyModalFlag = false;
  32194. bringModalComponentToFront();
  32195. }
  32196. else
  32197. {
  32198. postMessage (new Message (exitModalStateMessage, returnValue, 0, 0));
  32199. }
  32200. }
  32201. }
  32202. bool Component::isCurrentlyModal() const throw()
  32203. {
  32204. return flags.currentlyModalFlag
  32205. && getCurrentlyModalComponent() == this;
  32206. }
  32207. bool Component::isCurrentlyBlockedByAnotherModalComponent() const throw()
  32208. {
  32209. Component* const mc = getCurrentlyModalComponent();
  32210. return mc != 0
  32211. && mc != this
  32212. && (! mc->isParentOf (this))
  32213. && ! mc->canModalEventBeSentToComponent (this);
  32214. }
  32215. int JUCE_CALLTYPE Component::getNumCurrentlyModalComponents() throw()
  32216. {
  32217. return modalComponentStack.size();
  32218. }
  32219. Component* JUCE_CALLTYPE Component::getCurrentlyModalComponent (int index) throw()
  32220. {
  32221. Component* const c = (Component*) (modalComponentStack [modalComponentStack.size() - index - 1]);
  32222. return c->isValidComponent() ? c : 0;
  32223. }
  32224. void Component::bringModalComponentToFront()
  32225. {
  32226. ComponentPeer* lastOne = 0;
  32227. for (int i = 0; i < getNumCurrentlyModalComponents(); ++i)
  32228. {
  32229. Component* const c = getCurrentlyModalComponent (i);
  32230. if (c == 0)
  32231. break;
  32232. ComponentPeer* peer = c->getPeer();
  32233. if (peer != 0 && peer != lastOne)
  32234. {
  32235. if (lastOne == 0)
  32236. {
  32237. peer->toFront (true);
  32238. peer->grabFocus();
  32239. }
  32240. else
  32241. peer->toBehind (lastOne);
  32242. lastOne = peer;
  32243. }
  32244. }
  32245. }
  32246. void Component::setBroughtToFrontOnMouseClick (const bool shouldBeBroughtToFront) throw()
  32247. {
  32248. flags.bringToFrontOnClickFlag = shouldBeBroughtToFront;
  32249. }
  32250. bool Component::isBroughtToFrontOnMouseClick() const throw()
  32251. {
  32252. return flags.bringToFrontOnClickFlag;
  32253. }
  32254. void Component::setMouseCursor (const MouseCursor& cursor) throw()
  32255. {
  32256. cursor_ = cursor;
  32257. if (flags.visibleFlag)
  32258. {
  32259. int mx, my;
  32260. getMouseXYRelative (mx, my);
  32261. if (flags.draggingFlag || reallyContains (mx, my, false))
  32262. {
  32263. internalUpdateMouseCursor (false);
  32264. }
  32265. }
  32266. }
  32267. const MouseCursor Component::getMouseCursor()
  32268. {
  32269. return cursor_;
  32270. }
  32271. void Component::updateMouseCursor() const throw()
  32272. {
  32273. sendFakeMouseMove();
  32274. }
  32275. void Component::internalUpdateMouseCursor (bool forcedUpdate) throw()
  32276. {
  32277. ComponentPeer* const peer = getPeer();
  32278. if (peer != 0)
  32279. {
  32280. MouseCursor mc (getLookAndFeel().getMouseCursorFor (*this));
  32281. if (isUnboundedMouseModeOn && (unboundedMouseOffsetX != 0
  32282. || unboundedMouseOffsetY != 0
  32283. || ! isCursorVisibleUntilOffscreen))
  32284. {
  32285. mc = MouseCursor::NoCursor;
  32286. forcedUpdate = true;
  32287. }
  32288. static void* currentCursorHandle = 0;
  32289. if (forcedUpdate || mc.getHandle() != currentCursorHandle)
  32290. {
  32291. currentCursorHandle = mc.getHandle();
  32292. mc.showInWindow (peer);
  32293. }
  32294. }
  32295. }
  32296. void Component::setRepaintsOnMouseActivity (const bool shouldRepaint) throw()
  32297. {
  32298. flags.repaintOnMouseActivityFlag = shouldRepaint;
  32299. }
  32300. void Component::repaintParent() throw()
  32301. {
  32302. if (flags.visibleFlag)
  32303. internalRepaint (0, 0, getWidth(), getHeight());
  32304. }
  32305. void Component::repaint() throw()
  32306. {
  32307. repaint (0, 0, getWidth(), getHeight());
  32308. }
  32309. void Component::repaint (const int x, const int y,
  32310. const int w, const int h) throw()
  32311. {
  32312. deleteAndZero (bufferedImage_);
  32313. if (flags.visibleFlag)
  32314. internalRepaint (x, y, w, h);
  32315. }
  32316. void Component::internalRepaint (int x, int y, int w, int h)
  32317. {
  32318. // if component methods are being called from threads other than the message
  32319. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  32320. checkMessageManagerIsLocked
  32321. if (x < 0)
  32322. {
  32323. w += x;
  32324. x = 0;
  32325. }
  32326. if (x + w > getWidth())
  32327. w = getWidth() - x;
  32328. if (w > 0)
  32329. {
  32330. if (y < 0)
  32331. {
  32332. h += y;
  32333. y = 0;
  32334. }
  32335. if (y + h > getHeight())
  32336. h = getHeight() - y;
  32337. if (h > 0)
  32338. {
  32339. if (parentComponent_ != 0)
  32340. {
  32341. x += getX();
  32342. y += getY();
  32343. if (parentComponent_->flags.visibleFlag)
  32344. parentComponent_->internalRepaint (x, y, w, h);
  32345. }
  32346. else if (flags.hasHeavyweightPeerFlag)
  32347. {
  32348. ComponentPeer* const peer = getPeer();
  32349. if (peer != 0)
  32350. peer->repaint (x, y, w, h);
  32351. }
  32352. }
  32353. }
  32354. }
  32355. void Component::paintEntireComponent (Graphics& originalContext)
  32356. {
  32357. jassert (! originalContext.isClipEmpty());
  32358. #ifdef JUCE_DEBUG
  32359. flags.isInsidePaintCall = true;
  32360. #endif
  32361. Graphics* g = &originalContext;
  32362. Image* effectImage = 0;
  32363. if (effect_ != 0)
  32364. {
  32365. effectImage = Image::createNativeImage (flags.opaqueFlag ? Image::RGB : Image::ARGB,
  32366. getWidth(), getHeight(),
  32367. ! flags.opaqueFlag);
  32368. g = new Graphics (*effectImage);
  32369. }
  32370. g->saveState();
  32371. clipObscuredRegions (*g, g->getClipBounds(), 0, 0);
  32372. if (! g->isClipEmpty())
  32373. {
  32374. if (bufferedImage_ != 0)
  32375. {
  32376. g->setColour (Colours::black);
  32377. g->drawImageAt (bufferedImage_, 0, 0);
  32378. }
  32379. else
  32380. {
  32381. if (flags.bufferToImageFlag)
  32382. {
  32383. if (bufferedImage_ == 0)
  32384. {
  32385. bufferedImage_ = Image::createNativeImage (flags.opaqueFlag ? Image::RGB : Image::ARGB,
  32386. getWidth(), getHeight(), ! flags.opaqueFlag);
  32387. Graphics imG (*bufferedImage_);
  32388. paint (imG);
  32389. }
  32390. g->setColour (Colours::black);
  32391. g->drawImageAt (bufferedImage_, 0, 0);
  32392. }
  32393. else
  32394. {
  32395. paint (*g);
  32396. g->resetToDefaultState();
  32397. }
  32398. }
  32399. }
  32400. g->restoreState();
  32401. for (int i = 0; i < childComponentList_.size(); ++i)
  32402. {
  32403. Component* const child = childComponentList_.getUnchecked (i);
  32404. if (child->isVisible())
  32405. {
  32406. g->saveState();
  32407. if (g->reduceClipRegion (child->getX(), child->getY(),
  32408. child->getWidth(), child->getHeight()))
  32409. {
  32410. for (int j = i + 1; j < childComponentList_.size(); ++j)
  32411. {
  32412. const Component* const sibling = childComponentList_.getUnchecked (j);
  32413. if (sibling->flags.opaqueFlag && sibling->isVisible())
  32414. g->excludeClipRegion (sibling->getX(), sibling->getY(),
  32415. sibling->getWidth(), sibling->getHeight());
  32416. }
  32417. if (! g->isClipEmpty())
  32418. {
  32419. g->setOrigin (child->getX(), child->getY());
  32420. child->paintEntireComponent (*g);
  32421. }
  32422. }
  32423. g->restoreState();
  32424. }
  32425. }
  32426. JUCE_TRY
  32427. {
  32428. g->saveState();
  32429. paintOverChildren (*g);
  32430. g->restoreState();
  32431. }
  32432. JUCE_CATCH_EXCEPTION
  32433. if (effect_ != 0)
  32434. {
  32435. delete g;
  32436. effect_->applyEffect (*effectImage, originalContext);
  32437. delete effectImage;
  32438. }
  32439. #ifdef JUCE_DEBUG
  32440. flags.isInsidePaintCall = false;
  32441. #endif
  32442. }
  32443. Image* Component::createComponentSnapshot (const Rectangle<int>& areaToGrab,
  32444. const bool clipImageToComponentBounds)
  32445. {
  32446. Rectangle<int> r (areaToGrab);
  32447. if (clipImageToComponentBounds)
  32448. r = r.getIntersection (Rectangle<int> (0, 0, getWidth(), getHeight()));
  32449. Image* const componentImage = Image::createNativeImage (flags.opaqueFlag ? Image::RGB : Image::ARGB,
  32450. jmax (1, r.getWidth()),
  32451. jmax (1, r.getHeight()),
  32452. true);
  32453. Graphics imageContext (*componentImage);
  32454. imageContext.setOrigin (-r.getX(),
  32455. -r.getY());
  32456. paintEntireComponent (imageContext);
  32457. return componentImage;
  32458. }
  32459. void Component::setComponentEffect (ImageEffectFilter* const effect)
  32460. {
  32461. if (effect_ != effect)
  32462. {
  32463. effect_ = effect;
  32464. repaint();
  32465. }
  32466. }
  32467. LookAndFeel& Component::getLookAndFeel() const throw()
  32468. {
  32469. const Component* c = this;
  32470. do
  32471. {
  32472. if (c->lookAndFeel_ != 0)
  32473. return *(c->lookAndFeel_);
  32474. c = c->parentComponent_;
  32475. }
  32476. while (c != 0);
  32477. return LookAndFeel::getDefaultLookAndFeel();
  32478. }
  32479. void Component::setLookAndFeel (LookAndFeel* const newLookAndFeel)
  32480. {
  32481. if (lookAndFeel_ != newLookAndFeel)
  32482. {
  32483. lookAndFeel_ = newLookAndFeel;
  32484. sendLookAndFeelChange();
  32485. }
  32486. }
  32487. void Component::lookAndFeelChanged()
  32488. {
  32489. }
  32490. void Component::sendLookAndFeelChange()
  32491. {
  32492. repaint();
  32493. lookAndFeelChanged();
  32494. // (it's not a great idea to do anything that would delete this component
  32495. // during the lookAndFeelChanged() callback)
  32496. jassert (isValidComponent());
  32497. const ComponentDeletionWatcher deletionChecker (this);
  32498. for (int i = childComponentList_.size(); --i >= 0;)
  32499. {
  32500. childComponentList_.getUnchecked (i)->sendLookAndFeelChange();
  32501. if (deletionChecker.hasBeenDeleted())
  32502. return;
  32503. i = jmin (i, childComponentList_.size());
  32504. }
  32505. }
  32506. static const var::identifier getColourPropertyId (const int colourId)
  32507. {
  32508. String s;
  32509. s.preallocateStorage (18);
  32510. s << T("jcclr_") << colourId;
  32511. return s;
  32512. }
  32513. const Colour Component::findColour (const int colourId, const bool inheritFromParent) const throw()
  32514. {
  32515. var* v = properties.getItem (getColourPropertyId (colourId));
  32516. if (v != 0)
  32517. return Colour ((int) *v);
  32518. if (inheritFromParent && parentComponent_ != 0)
  32519. return parentComponent_->findColour (colourId, true);
  32520. return getLookAndFeel().findColour (colourId);
  32521. }
  32522. bool Component::isColourSpecified (const int colourId) const throw()
  32523. {
  32524. return properties.contains (getColourPropertyId (colourId));
  32525. }
  32526. void Component::removeColour (const int colourId)
  32527. {
  32528. if (properties.remove (getColourPropertyId (colourId)))
  32529. colourChanged();
  32530. }
  32531. void Component::setColour (const int colourId, const Colour& colour)
  32532. {
  32533. if (properties.set (getColourPropertyId (colourId), (int) colour.getARGB()))
  32534. colourChanged();
  32535. }
  32536. void Component::copyAllExplicitColoursTo (Component& target) const throw()
  32537. {
  32538. bool changed = false;
  32539. for (int i = properties.size(); --i >= 0;)
  32540. {
  32541. const var::identifier name (properties.getName(i));
  32542. if (name.name.startsWith (T("jcclr_")))
  32543. if (target.properties.set (name, properties [name]))
  32544. changed = true;
  32545. }
  32546. if (changed)
  32547. target.colourChanged();
  32548. }
  32549. void Component::colourChanged()
  32550. {
  32551. }
  32552. const Rectangle<int> Component::getUnclippedArea() const
  32553. {
  32554. int x = 0, y = 0, w = getWidth(), h = getHeight();
  32555. Component* p = parentComponent_;
  32556. int px = getX();
  32557. int py = getY();
  32558. while (p != 0)
  32559. {
  32560. if (! Rectangle<int>::intersectRectangles (x, y, w, h, -px, -py, p->getWidth(), p->getHeight()))
  32561. return Rectangle<int>();
  32562. px += p->getX();
  32563. py += p->getY();
  32564. p = p->parentComponent_;
  32565. }
  32566. return Rectangle<int> (x, y, w, h);
  32567. }
  32568. void Component::clipObscuredRegions (Graphics& g, const Rectangle<int>& clipRect,
  32569. const int deltaX, const int deltaY) const throw()
  32570. {
  32571. for (int i = childComponentList_.size(); --i >= 0;)
  32572. {
  32573. const Component* const c = childComponentList_.getUnchecked(i);
  32574. if (c->isVisible())
  32575. {
  32576. Rectangle<int> newClip (clipRect.getIntersection (c->bounds_));
  32577. if (! newClip.isEmpty())
  32578. {
  32579. if (c->isOpaque())
  32580. {
  32581. g.excludeClipRegion (deltaX + newClip.getX(),
  32582. deltaY + newClip.getY(),
  32583. newClip.getWidth(),
  32584. newClip.getHeight());
  32585. }
  32586. else
  32587. {
  32588. newClip.translate (-c->getX(), -c->getY());
  32589. c->clipObscuredRegions (g, newClip,
  32590. c->getX() + deltaX,
  32591. c->getY() + deltaY);
  32592. }
  32593. }
  32594. }
  32595. }
  32596. }
  32597. void Component::getVisibleArea (RectangleList& result,
  32598. const bool includeSiblings) const
  32599. {
  32600. result.clear();
  32601. const Rectangle<int> unclipped (getUnclippedArea());
  32602. if (! unclipped.isEmpty())
  32603. {
  32604. result.add (unclipped);
  32605. if (includeSiblings)
  32606. {
  32607. const Component* const c = getTopLevelComponent();
  32608. int x = 0, y = 0;
  32609. c->relativePositionToOtherComponent (this, x, y);
  32610. c->subtractObscuredRegions (result, x, y,
  32611. Rectangle<int> (0, 0, c->getWidth(), c->getHeight()),
  32612. this);
  32613. }
  32614. subtractObscuredRegions (result, 0, 0, unclipped, 0);
  32615. result.consolidate();
  32616. }
  32617. }
  32618. void Component::subtractObscuredRegions (RectangleList& result,
  32619. const int deltaX,
  32620. const int deltaY,
  32621. const Rectangle<int>& clipRect,
  32622. const Component* const compToAvoid) const throw()
  32623. {
  32624. for (int i = childComponentList_.size(); --i >= 0;)
  32625. {
  32626. const Component* const c = childComponentList_.getUnchecked(i);
  32627. if (c != compToAvoid && c->isVisible())
  32628. {
  32629. if (c->isOpaque())
  32630. {
  32631. Rectangle<int> childBounds (c->bounds_.getIntersection (clipRect));
  32632. childBounds.translate (deltaX, deltaY);
  32633. result.subtract (childBounds);
  32634. }
  32635. else
  32636. {
  32637. Rectangle<int> newClip (clipRect.getIntersection (c->bounds_));
  32638. newClip.translate (-c->getX(), -c->getY());
  32639. c->subtractObscuredRegions (result,
  32640. c->getX() + deltaX,
  32641. c->getY() + deltaY,
  32642. newClip,
  32643. compToAvoid);
  32644. }
  32645. }
  32646. }
  32647. }
  32648. void Component::mouseEnter (const MouseEvent&)
  32649. {
  32650. // base class does nothing
  32651. }
  32652. void Component::mouseExit (const MouseEvent&)
  32653. {
  32654. // base class does nothing
  32655. }
  32656. void Component::mouseDown (const MouseEvent&)
  32657. {
  32658. // base class does nothing
  32659. }
  32660. void Component::mouseUp (const MouseEvent&)
  32661. {
  32662. // base class does nothing
  32663. }
  32664. void Component::mouseDrag (const MouseEvent&)
  32665. {
  32666. // base class does nothing
  32667. }
  32668. void Component::mouseMove (const MouseEvent&)
  32669. {
  32670. // base class does nothing
  32671. }
  32672. void Component::mouseDoubleClick (const MouseEvent&)
  32673. {
  32674. // base class does nothing
  32675. }
  32676. void Component::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  32677. {
  32678. // the base class just passes this event up to its parent..
  32679. if (parentComponent_ != 0)
  32680. parentComponent_->mouseWheelMove (e.getEventRelativeTo (parentComponent_),
  32681. wheelIncrementX, wheelIncrementY);
  32682. }
  32683. void Component::resized()
  32684. {
  32685. // base class does nothing
  32686. }
  32687. void Component::moved()
  32688. {
  32689. // base class does nothing
  32690. }
  32691. void Component::childBoundsChanged (Component*)
  32692. {
  32693. // base class does nothing
  32694. }
  32695. void Component::parentSizeChanged()
  32696. {
  32697. // base class does nothing
  32698. }
  32699. void Component::addComponentListener (ComponentListener* const newListener) throw()
  32700. {
  32701. if (componentListeners_ == 0)
  32702. componentListeners_ = new VoidArray();
  32703. componentListeners_->addIfNotAlreadyThere (newListener);
  32704. }
  32705. void Component::removeComponentListener (ComponentListener* const listenerToRemove) throw()
  32706. {
  32707. jassert (isValidComponent());
  32708. if (componentListeners_ != 0)
  32709. componentListeners_->removeValue (listenerToRemove);
  32710. }
  32711. void Component::inputAttemptWhenModal()
  32712. {
  32713. bringModalComponentToFront();
  32714. getLookAndFeel().playAlertSound();
  32715. }
  32716. bool Component::canModalEventBeSentToComponent (const Component*)
  32717. {
  32718. return false;
  32719. }
  32720. void Component::internalModalInputAttempt()
  32721. {
  32722. Component* const current = getCurrentlyModalComponent();
  32723. if (current != 0)
  32724. current->inputAttemptWhenModal();
  32725. }
  32726. void Component::paint (Graphics&)
  32727. {
  32728. // all painting is done in the subclasses
  32729. jassert (! isOpaque()); // if your component's opaque, you've gotta paint it!
  32730. }
  32731. void Component::paintOverChildren (Graphics&)
  32732. {
  32733. // all painting is done in the subclasses
  32734. }
  32735. void Component::handleMessage (const Message& message)
  32736. {
  32737. if (message.intParameter1 == exitModalStateMessage)
  32738. {
  32739. exitModalState (message.intParameter2);
  32740. }
  32741. else if (message.intParameter1 == customCommandMessage)
  32742. {
  32743. handleCommandMessage (message.intParameter2);
  32744. }
  32745. }
  32746. void Component::postCommandMessage (const int commandId) throw()
  32747. {
  32748. postMessage (new Message (customCommandMessage, commandId, 0, 0));
  32749. }
  32750. void Component::handleCommandMessage (int)
  32751. {
  32752. // used by subclasses
  32753. }
  32754. void Component::addMouseListener (MouseListener* const newListener,
  32755. const bool wantsEventsForAllNestedChildComponents) throw()
  32756. {
  32757. // if component methods are being called from threads other than the message
  32758. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  32759. checkMessageManagerIsLocked
  32760. if (mouseListeners_ == 0)
  32761. mouseListeners_ = new VoidArray();
  32762. if (! mouseListeners_->contains (newListener))
  32763. {
  32764. if (wantsEventsForAllNestedChildComponents)
  32765. {
  32766. mouseListeners_->insert (0, newListener);
  32767. ++numDeepMouseListeners;
  32768. }
  32769. else
  32770. {
  32771. mouseListeners_->add (newListener);
  32772. }
  32773. }
  32774. }
  32775. void Component::removeMouseListener (MouseListener* const listenerToRemove) throw()
  32776. {
  32777. // if component methods are being called from threads other than the message
  32778. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  32779. checkMessageManagerIsLocked
  32780. if (mouseListeners_ != 0)
  32781. {
  32782. const int index = mouseListeners_->indexOf (listenerToRemove);
  32783. if (index >= 0)
  32784. {
  32785. if (index < numDeepMouseListeners)
  32786. --numDeepMouseListeners;
  32787. mouseListeners_->remove (index);
  32788. }
  32789. }
  32790. }
  32791. void Component::internalMouseEnter (int x, int y, int64 time)
  32792. {
  32793. if (isCurrentlyBlockedByAnotherModalComponent())
  32794. {
  32795. // if something else is modal, always just show a normal mouse cursor
  32796. if (componentUnderMouse == this)
  32797. {
  32798. ComponentPeer* const peer = getPeer();
  32799. if (peer != 0)
  32800. {
  32801. MouseCursor mc (MouseCursor::NormalCursor);
  32802. mc.showInWindow (peer);
  32803. }
  32804. }
  32805. return;
  32806. }
  32807. if (isValidComponent() && ! flags.mouseInsideFlag)
  32808. {
  32809. flags.mouseInsideFlag = true;
  32810. flags.mouseOverFlag = true;
  32811. flags.draggingFlag = false;
  32812. const ComponentDeletionWatcher deletionChecker (this);
  32813. if (flags.repaintOnMouseActivityFlag)
  32814. repaint();
  32815. const MouseEvent me (x, y,
  32816. ModifierKeys::getCurrentModifiers(),
  32817. this,
  32818. Time (time),
  32819. x, y,
  32820. Time (time),
  32821. 0, false);
  32822. mouseEnter (me);
  32823. if (deletionChecker.hasBeenDeleted())
  32824. return;
  32825. Desktop::getInstance().resetTimer();
  32826. for (int i = Desktop::getInstance().mouseListeners.size(); --i >= 0;)
  32827. {
  32828. ((MouseListener*) Desktop::getInstance().mouseListeners[i])->mouseEnter (me);
  32829. if (deletionChecker.hasBeenDeleted())
  32830. return;
  32831. i = jmin (i, Desktop::getInstance().mouseListeners.size());
  32832. }
  32833. if (mouseListeners_ != 0)
  32834. {
  32835. for (int i = mouseListeners_->size(); --i >= 0;)
  32836. {
  32837. ((MouseListener*) mouseListeners_->getUnchecked(i))->mouseEnter (me);
  32838. if (deletionChecker.hasBeenDeleted())
  32839. return;
  32840. i = jmin (i, mouseListeners_->size());
  32841. }
  32842. }
  32843. const Component* p = parentComponent_;
  32844. while (p != 0)
  32845. {
  32846. const ComponentDeletionWatcher parentDeletionChecker (p);
  32847. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32848. {
  32849. ((MouseListener*) (p->mouseListeners_->getUnchecked(i)))->mouseEnter (me);
  32850. if (deletionChecker.hasBeenDeleted() || parentDeletionChecker.hasBeenDeleted())
  32851. return;
  32852. i = jmin (i, p->numDeepMouseListeners);
  32853. }
  32854. p = p->parentComponent_;
  32855. }
  32856. }
  32857. if (componentUnderMouse == this)
  32858. internalUpdateMouseCursor (true);
  32859. }
  32860. void Component::internalMouseExit (int x, int y, int64 time)
  32861. {
  32862. const ComponentDeletionWatcher deletionChecker (this);
  32863. if (flags.draggingFlag)
  32864. {
  32865. internalMouseUp (ModifierKeys::getCurrentModifiers().getRawFlags(), x, y, time);
  32866. if (deletionChecker.hasBeenDeleted())
  32867. return;
  32868. }
  32869. enableUnboundedMouseMovement (false);
  32870. if (flags.mouseInsideFlag || flags.mouseOverFlag)
  32871. {
  32872. flags.mouseInsideFlag = false;
  32873. flags.mouseOverFlag = false;
  32874. flags.draggingFlag = false;
  32875. if (flags.repaintOnMouseActivityFlag)
  32876. repaint();
  32877. const MouseEvent me (x, y,
  32878. ModifierKeys::getCurrentModifiers(),
  32879. this,
  32880. Time (time),
  32881. x, y,
  32882. Time (time),
  32883. 0, false);
  32884. mouseExit (me);
  32885. if (deletionChecker.hasBeenDeleted())
  32886. return;
  32887. Desktop::getInstance().resetTimer();
  32888. for (int i = Desktop::getInstance().mouseListeners.size(); --i >= 0;)
  32889. {
  32890. ((MouseListener*) Desktop::getInstance().mouseListeners[i])->mouseExit (me);
  32891. if (deletionChecker.hasBeenDeleted())
  32892. return;
  32893. i = jmin (i, Desktop::getInstance().mouseListeners.size());
  32894. }
  32895. if (mouseListeners_ != 0)
  32896. {
  32897. for (int i = mouseListeners_->size(); --i >= 0;)
  32898. {
  32899. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseExit (me);
  32900. if (deletionChecker.hasBeenDeleted())
  32901. return;
  32902. i = jmin (i, mouseListeners_->size());
  32903. }
  32904. }
  32905. const Component* p = parentComponent_;
  32906. while (p != 0)
  32907. {
  32908. const ComponentDeletionWatcher parentDeletionChecker (p);
  32909. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32910. {
  32911. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseExit (me);
  32912. if (deletionChecker.hasBeenDeleted() || parentDeletionChecker.hasBeenDeleted())
  32913. return;
  32914. i = jmin (i, p->numDeepMouseListeners);
  32915. }
  32916. p = p->parentComponent_;
  32917. }
  32918. }
  32919. }
  32920. class InternalDragRepeater : public Timer
  32921. {
  32922. public:
  32923. InternalDragRepeater() {}
  32924. ~InternalDragRepeater() {}
  32925. void timerCallback()
  32926. {
  32927. Component* const c = Component::getComponentUnderMouse();
  32928. if (c != 0 && c->isMouseButtonDown())
  32929. {
  32930. int x, y;
  32931. c->getMouseXYRelative (x, y);
  32932. // the offsets have been added on, so must be taken off before calling the
  32933. // drag.. otherwise they'll be added twice
  32934. x -= unboundedMouseOffsetX;
  32935. y -= unboundedMouseOffsetY;
  32936. c->internalMouseDrag (x, y, Time::currentTimeMillis());
  32937. }
  32938. }
  32939. juce_UseDebuggingNewOperator
  32940. private:
  32941. InternalDragRepeater (const InternalDragRepeater&);
  32942. InternalDragRepeater& operator= (const InternalDragRepeater&);
  32943. };
  32944. static InternalDragRepeater* dragRepeater = 0;
  32945. void Component::beginDragAutoRepeat (const int interval)
  32946. {
  32947. if (interval > 0)
  32948. {
  32949. if (dragRepeater == 0)
  32950. dragRepeater = new InternalDragRepeater();
  32951. if (dragRepeater->getTimerInterval() != interval)
  32952. dragRepeater->startTimer (interval);
  32953. }
  32954. else
  32955. {
  32956. deleteAndZero (dragRepeater);
  32957. }
  32958. }
  32959. void Component::internalMouseDown (const int x, const int y, const int64 time)
  32960. {
  32961. Desktop& desktop = Desktop::getInstance();
  32962. int gx = x, gy = y;
  32963. relativePositionToGlobal (gx, gy);
  32964. desktop.registerMouseDown (Point<int> (gx, gy), time, this);
  32965. const ComponentDeletionWatcher deletionChecker (this);
  32966. if (isCurrentlyBlockedByAnotherModalComponent())
  32967. {
  32968. internalModalInputAttempt();
  32969. if (deletionChecker.hasBeenDeleted())
  32970. return;
  32971. // If processing the input attempt has exited the modal loop, we'll allow the event
  32972. // to be delivered..
  32973. if (isCurrentlyBlockedByAnotherModalComponent())
  32974. {
  32975. // allow blocked mouse-events to go to global listeners..
  32976. const MouseEvent me (x, y,
  32977. ModifierKeys::getCurrentModifiers(),
  32978. this,
  32979. Time (time),
  32980. x, y,
  32981. desktop.getLastMouseDownTime(),
  32982. desktop.getNumberOfMultipleClicks(),
  32983. false);
  32984. desktop.resetTimer();
  32985. for (int i = desktop.mouseListeners.size(); --i >= 0;)
  32986. {
  32987. ((MouseListener*) desktop.mouseListeners[i])->mouseDown (me);
  32988. if (deletionChecker.hasBeenDeleted())
  32989. return;
  32990. i = jmin (i, desktop.mouseListeners.size());
  32991. }
  32992. return;
  32993. }
  32994. }
  32995. {
  32996. Component* c = this;
  32997. while (c != 0)
  32998. {
  32999. if (c->isBroughtToFrontOnMouseClick())
  33000. {
  33001. c->toFront (true);
  33002. if (deletionChecker.hasBeenDeleted())
  33003. return;
  33004. }
  33005. c = c->parentComponent_;
  33006. }
  33007. }
  33008. if (! flags.dontFocusOnMouseClickFlag)
  33009. grabFocusInternal (focusChangedByMouseClick);
  33010. if (! deletionChecker.hasBeenDeleted())
  33011. {
  33012. flags.draggingFlag = true;
  33013. flags.mouseOverFlag = true;
  33014. if (flags.repaintOnMouseActivityFlag)
  33015. repaint();
  33016. const MouseEvent me (x, y,
  33017. ModifierKeys::getCurrentModifiers(),
  33018. this,
  33019. desktop.getLastMouseDownTime(),
  33020. x, y,
  33021. desktop.getLastMouseDownTime(),
  33022. desktop.getNumberOfMultipleClicks(),
  33023. false);
  33024. mouseDown (me);
  33025. if (deletionChecker.hasBeenDeleted())
  33026. return;
  33027. desktop.resetTimer();
  33028. for (int i = desktop.mouseListeners.size(); --i >= 0;)
  33029. {
  33030. ((MouseListener*) desktop.mouseListeners[i])->mouseDown (me);
  33031. if (deletionChecker.hasBeenDeleted())
  33032. return;
  33033. i = jmin (i, desktop.mouseListeners.size());
  33034. }
  33035. if (mouseListeners_ != 0)
  33036. {
  33037. for (int i = mouseListeners_->size(); --i >= 0;)
  33038. {
  33039. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseDown (me);
  33040. if (deletionChecker.hasBeenDeleted())
  33041. return;
  33042. i = jmin (i, mouseListeners_->size());
  33043. }
  33044. }
  33045. const Component* p = parentComponent_;
  33046. while (p != 0)
  33047. {
  33048. const ComponentDeletionWatcher parentDeletionChecker (p);
  33049. for (int i = p->numDeepMouseListeners; --i >= 0;)
  33050. {
  33051. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseDown (me);
  33052. if (deletionChecker.hasBeenDeleted() || parentDeletionChecker.hasBeenDeleted())
  33053. return;
  33054. i = jmin (i, p->numDeepMouseListeners);
  33055. }
  33056. p = p->parentComponent_;
  33057. }
  33058. }
  33059. }
  33060. void Component::internalMouseUp (const int oldModifiers, int x, int y, const int64 time)
  33061. {
  33062. if (isValidComponent() && flags.draggingFlag)
  33063. {
  33064. Desktop& desktop = Desktop::getInstance();
  33065. flags.draggingFlag = false;
  33066. deleteAndZero (dragRepeater);
  33067. x += unboundedMouseOffsetX;
  33068. y += unboundedMouseOffsetY;
  33069. int gx = x, gy = y;
  33070. relativePositionToGlobal (gx, gy);
  33071. desktop.registerMouseDrag (Point<int> (gx, gy));
  33072. const ComponentDeletionWatcher deletionChecker (this);
  33073. if (flags.repaintOnMouseActivityFlag)
  33074. repaint();
  33075. int mdx, mdy;
  33076. Desktop::getLastMouseDownPosition (mdx, mdy);
  33077. globalPositionToRelative (mdx, mdy);
  33078. const Time lastMouseDownTime (desktop.getLastMouseDownTime());
  33079. const MouseEvent me (x, y,
  33080. oldModifiers,
  33081. this,
  33082. Time (time),
  33083. mdx, mdy,
  33084. lastMouseDownTime,
  33085. desktop.getNumberOfMultipleClicks(),
  33086. desktop.mouseMovedSignificantlySincePressed
  33087. || time > lastMouseDownTime.toMilliseconds() + 300);
  33088. mouseUp (me);
  33089. if (deletionChecker.hasBeenDeleted())
  33090. return;
  33091. desktop.resetTimer();
  33092. for (int i = desktop.mouseListeners.size(); --i >= 0;)
  33093. {
  33094. ((MouseListener*) desktop.mouseListeners[i])->mouseUp (me);
  33095. if (deletionChecker.hasBeenDeleted())
  33096. return;
  33097. i = jmin (i, desktop.mouseListeners.size());
  33098. }
  33099. if (mouseListeners_ != 0)
  33100. {
  33101. for (int i = mouseListeners_->size(); --i >= 0;)
  33102. {
  33103. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseUp (me);
  33104. if (deletionChecker.hasBeenDeleted())
  33105. return;
  33106. i = jmin (i, mouseListeners_->size());
  33107. }
  33108. }
  33109. {
  33110. const Component* p = parentComponent_;
  33111. while (p != 0)
  33112. {
  33113. const ComponentDeletionWatcher parentDeletionChecker (p);
  33114. for (int i = p->numDeepMouseListeners; --i >= 0;)
  33115. {
  33116. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseUp (me);
  33117. if (deletionChecker.hasBeenDeleted() || parentDeletionChecker.hasBeenDeleted())
  33118. return;
  33119. i = jmin (i, p->numDeepMouseListeners);
  33120. }
  33121. p = p->parentComponent_;
  33122. }
  33123. }
  33124. // check for double-click
  33125. if (me.getNumberOfClicks() >= 2)
  33126. {
  33127. const int numListeners = (mouseListeners_ != 0) ? mouseListeners_->size() : 0;
  33128. mouseDoubleClick (me);
  33129. int i;
  33130. for (i = desktop.mouseListeners.size(); --i >= 0;)
  33131. {
  33132. ((MouseListener*) desktop.mouseListeners[i])->mouseDoubleClick (me);
  33133. if (deletionChecker.hasBeenDeleted())
  33134. return;
  33135. i = jmin (i, desktop.mouseListeners.size());
  33136. }
  33137. for (i = numListeners; --i >= 0;)
  33138. {
  33139. if (deletionChecker.hasBeenDeleted() || mouseListeners_ == 0)
  33140. return;
  33141. MouseListener* const ml = (MouseListener*)((*mouseListeners_)[i]);
  33142. if (ml != 0)
  33143. ml->mouseDoubleClick (me);
  33144. }
  33145. if (deletionChecker.hasBeenDeleted())
  33146. return;
  33147. const Component* p = parentComponent_;
  33148. while (p != 0)
  33149. {
  33150. const ComponentDeletionWatcher parentDeletionChecker (p);
  33151. for (i = p->numDeepMouseListeners; --i >= 0;)
  33152. {
  33153. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseDoubleClick (me);
  33154. if (deletionChecker.hasBeenDeleted() || parentDeletionChecker.hasBeenDeleted())
  33155. return;
  33156. i = jmin (i, p->numDeepMouseListeners);
  33157. }
  33158. p = p->parentComponent_;
  33159. }
  33160. }
  33161. }
  33162. enableUnboundedMouseMovement (false);
  33163. }
  33164. void Component::internalMouseDrag (int x, int y, const int64 time)
  33165. {
  33166. if (isValidComponent() && flags.draggingFlag)
  33167. {
  33168. Desktop& desktop = Desktop::getInstance();
  33169. flags.mouseOverFlag = reallyContains (x, y, false);
  33170. x += unboundedMouseOffsetX;
  33171. y += unboundedMouseOffsetY;
  33172. int gx = x, gy = y;
  33173. relativePositionToGlobal (gx, gy);
  33174. desktop.registerMouseDrag (Point<int> (gx, gy));
  33175. const ComponentDeletionWatcher deletionChecker (this);
  33176. int mdx, mdy;
  33177. Desktop::getLastMouseDownPosition (mdx, mdy);
  33178. globalPositionToRelative (mdx, mdy);
  33179. const Time lastMouseDownTime (desktop.getLastMouseDownTime());
  33180. const MouseEvent me (x, y,
  33181. ModifierKeys::getCurrentModifiers(),
  33182. this,
  33183. Time (time),
  33184. mdx, mdy,
  33185. lastMouseDownTime,
  33186. desktop.getNumberOfMultipleClicks(),
  33187. desktop.mouseMovedSignificantlySincePressed
  33188. || time > lastMouseDownTime.toMilliseconds() + 300);
  33189. mouseDrag (me);
  33190. if (deletionChecker.hasBeenDeleted())
  33191. return;
  33192. desktop.resetTimer();
  33193. for (int i = desktop.mouseListeners.size(); --i >= 0;)
  33194. {
  33195. ((MouseListener*) desktop.mouseListeners[i])->mouseDrag (me);
  33196. if (deletionChecker.hasBeenDeleted())
  33197. return;
  33198. i = jmin (i, desktop.mouseListeners.size());
  33199. }
  33200. if (mouseListeners_ != 0)
  33201. {
  33202. for (int i = mouseListeners_->size(); --i >= 0;)
  33203. {
  33204. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseDrag (me);
  33205. if (deletionChecker.hasBeenDeleted())
  33206. return;
  33207. i = jmin (i, mouseListeners_->size());
  33208. }
  33209. }
  33210. const Component* p = parentComponent_;
  33211. while (p != 0)
  33212. {
  33213. const ComponentDeletionWatcher parentDeletionChecker (p);
  33214. for (int i = p->numDeepMouseListeners; --i >= 0;)
  33215. {
  33216. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseDrag (me);
  33217. if (deletionChecker.hasBeenDeleted() || parentDeletionChecker.hasBeenDeleted())
  33218. return;
  33219. i = jmin (i, p->numDeepMouseListeners);
  33220. }
  33221. p = p->parentComponent_;
  33222. }
  33223. if (this == componentUnderMouse)
  33224. {
  33225. if (isUnboundedMouseModeOn)
  33226. {
  33227. Rectangle<int> screenArea (getParentMonitorArea().expanded (-2, -2));
  33228. int mx, my;
  33229. Desktop::getMousePosition (mx, my);
  33230. if (! screenArea.contains (mx, my))
  33231. {
  33232. int deltaX = 0, deltaY = 0;
  33233. if (mx <= screenArea.getX() || mx >= screenArea.getRight())
  33234. deltaX = getScreenX() + getWidth() / 2 - mx;
  33235. if (my <= screenArea.getY() || my >= screenArea.getBottom())
  33236. deltaY = getScreenY() + getHeight() / 2 - my;
  33237. unboundedMouseOffsetX -= deltaX;
  33238. unboundedMouseOffsetY -= deltaY;
  33239. Desktop::setMousePosition (mx + deltaX,
  33240. my + deltaY);
  33241. }
  33242. else if (isCursorVisibleUntilOffscreen
  33243. && (unboundedMouseOffsetX != 0 || unboundedMouseOffsetY != 0)
  33244. && screenArea.contains (mx + unboundedMouseOffsetX,
  33245. my + unboundedMouseOffsetY))
  33246. {
  33247. mx += unboundedMouseOffsetX;
  33248. my += unboundedMouseOffsetY;
  33249. unboundedMouseOffsetX = 0;
  33250. unboundedMouseOffsetY = 0;
  33251. Desktop::setMousePosition (mx, my);
  33252. }
  33253. }
  33254. internalUpdateMouseCursor (false);
  33255. }
  33256. }
  33257. }
  33258. void Component::internalMouseMove (const int x, const int y, const int64 time)
  33259. {
  33260. const ComponentDeletionWatcher deletionChecker (this);
  33261. if (isValidComponent())
  33262. {
  33263. Desktop& desktop = Desktop::getInstance();
  33264. const MouseEvent me (x, y,
  33265. ModifierKeys::getCurrentModifiers(),
  33266. this,
  33267. Time (time),
  33268. x, y,
  33269. Time (time),
  33270. 0, false);
  33271. if (isCurrentlyBlockedByAnotherModalComponent())
  33272. {
  33273. // allow blocked mouse-events to go to global listeners..
  33274. desktop.sendMouseMove();
  33275. }
  33276. else
  33277. {
  33278. if (this == componentUnderMouse)
  33279. internalUpdateMouseCursor (false);
  33280. flags.mouseOverFlag = true;
  33281. mouseMove (me);
  33282. if (deletionChecker.hasBeenDeleted())
  33283. return;
  33284. desktop.resetTimer();
  33285. for (int i = desktop.mouseListeners.size(); --i >= 0;)
  33286. {
  33287. ((MouseListener*) desktop.mouseListeners[i])->mouseMove (me);
  33288. if (deletionChecker.hasBeenDeleted())
  33289. return;
  33290. i = jmin (i, desktop.mouseListeners.size());
  33291. }
  33292. if (mouseListeners_ != 0)
  33293. {
  33294. for (int i = mouseListeners_->size(); --i >= 0;)
  33295. {
  33296. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseMove (me);
  33297. if (deletionChecker.hasBeenDeleted())
  33298. return;
  33299. i = jmin (i, mouseListeners_->size());
  33300. }
  33301. }
  33302. const Component* p = parentComponent_;
  33303. while (p != 0)
  33304. {
  33305. const ComponentDeletionWatcher parentDeletionChecker (p);
  33306. for (int i = p->numDeepMouseListeners; --i >= 0;)
  33307. {
  33308. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseMove (me);
  33309. if (deletionChecker.hasBeenDeleted() || parentDeletionChecker.hasBeenDeleted())
  33310. return;
  33311. i = jmin (i, p->numDeepMouseListeners);
  33312. }
  33313. p = p->parentComponent_;
  33314. }
  33315. }
  33316. }
  33317. }
  33318. void Component::internalMouseWheel (const int intAmountX, const int intAmountY, const int64 time)
  33319. {
  33320. Desktop& desktop = Desktop::getInstance();
  33321. const ComponentDeletionWatcher deletionChecker (this);
  33322. const float wheelIncrementX = intAmountX * (1.0f / 256.0f);
  33323. const float wheelIncrementY = intAmountY * (1.0f / 256.0f);
  33324. int mx, my;
  33325. getMouseXYRelative (mx, my);
  33326. const MouseEvent me (mx, my,
  33327. ModifierKeys::getCurrentModifiers(),
  33328. this,
  33329. Time (time),
  33330. mx, my,
  33331. Time (time),
  33332. 0, false);
  33333. if (isCurrentlyBlockedByAnotherModalComponent())
  33334. {
  33335. // allow blocked mouse-events to go to global listeners..
  33336. for (int i = desktop.mouseListeners.size(); --i >= 0;)
  33337. {
  33338. ((MouseListener*) desktop.mouseListeners[i])->mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
  33339. if (deletionChecker.hasBeenDeleted())
  33340. return;
  33341. i = jmin (i, desktop.mouseListeners.size());
  33342. }
  33343. }
  33344. else
  33345. {
  33346. mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
  33347. if (deletionChecker.hasBeenDeleted())
  33348. return;
  33349. for (int i = desktop.mouseListeners.size(); --i >= 0;)
  33350. {
  33351. ((MouseListener*) desktop.mouseListeners[i])->mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
  33352. if (deletionChecker.hasBeenDeleted())
  33353. return;
  33354. i = jmin (i, desktop.mouseListeners.size());
  33355. }
  33356. if (mouseListeners_ != 0)
  33357. {
  33358. for (int i = mouseListeners_->size(); --i >= 0;)
  33359. {
  33360. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
  33361. if (deletionChecker.hasBeenDeleted())
  33362. return;
  33363. i = jmin (i, mouseListeners_->size());
  33364. }
  33365. }
  33366. const Component* p = parentComponent_;
  33367. while (p != 0)
  33368. {
  33369. const ComponentDeletionWatcher parentDeletionChecker (p);
  33370. for (int i = p->numDeepMouseListeners; --i >= 0;)
  33371. {
  33372. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
  33373. if (deletionChecker.hasBeenDeleted() || parentDeletionChecker.hasBeenDeleted())
  33374. return;
  33375. i = jmin (i, p->numDeepMouseListeners);
  33376. }
  33377. p = p->parentComponent_;
  33378. }
  33379. sendFakeMouseMove();
  33380. }
  33381. }
  33382. void Component::sendFakeMouseMove() const
  33383. {
  33384. ComponentPeer* const peer = getPeer();
  33385. if (peer != 0)
  33386. peer->sendFakeMouseMove();
  33387. }
  33388. void Component::broughtToFront()
  33389. {
  33390. }
  33391. void Component::internalBroughtToFront()
  33392. {
  33393. if (isValidComponent())
  33394. {
  33395. if (flags.hasHeavyweightPeerFlag)
  33396. Desktop::getInstance().componentBroughtToFront (this);
  33397. const ComponentDeletionWatcher deletionChecker (this);
  33398. broughtToFront();
  33399. if (deletionChecker.hasBeenDeleted())
  33400. return;
  33401. if (componentListeners_ != 0)
  33402. {
  33403. for (int i = componentListeners_->size(); --i >= 0;)
  33404. {
  33405. ((ComponentListener*) componentListeners_->getUnchecked (i))
  33406. ->componentBroughtToFront (*this);
  33407. if (deletionChecker.hasBeenDeleted())
  33408. return;
  33409. i = jmin (i, componentListeners_->size());
  33410. }
  33411. }
  33412. // when brought to the front and there's a modal component blocking this one,
  33413. // we need to bring the modal one to the front instead..
  33414. Component* const cm = getCurrentlyModalComponent();
  33415. if (cm != 0 && cm->getTopLevelComponent() != getTopLevelComponent())
  33416. bringModalComponentToFront();
  33417. }
  33418. }
  33419. void Component::focusGained (FocusChangeType)
  33420. {
  33421. // base class does nothing
  33422. }
  33423. void Component::internalFocusGain (const FocusChangeType cause)
  33424. {
  33425. const ComponentDeletionWatcher deletionChecker (this);
  33426. focusGained (cause);
  33427. if (! deletionChecker.hasBeenDeleted())
  33428. internalChildFocusChange (cause);
  33429. }
  33430. void Component::focusLost (FocusChangeType)
  33431. {
  33432. // base class does nothing
  33433. }
  33434. void Component::internalFocusLoss (const FocusChangeType cause)
  33435. {
  33436. const ComponentDeletionWatcher deletionChecker (this);
  33437. focusLost (focusChangedDirectly);
  33438. if (! deletionChecker.hasBeenDeleted())
  33439. internalChildFocusChange (cause);
  33440. }
  33441. void Component::focusOfChildComponentChanged (FocusChangeType /*cause*/)
  33442. {
  33443. // base class does nothing
  33444. }
  33445. void Component::internalChildFocusChange (FocusChangeType cause)
  33446. {
  33447. const bool childIsNowFocused = hasKeyboardFocus (true);
  33448. if (flags.childCompFocusedFlag != childIsNowFocused)
  33449. {
  33450. flags.childCompFocusedFlag = childIsNowFocused;
  33451. const ComponentDeletionWatcher deletionChecker (this);
  33452. focusOfChildComponentChanged (cause);
  33453. if (deletionChecker.hasBeenDeleted())
  33454. return;
  33455. }
  33456. if (parentComponent_ != 0)
  33457. parentComponent_->internalChildFocusChange (cause);
  33458. }
  33459. bool Component::isEnabled() const throw()
  33460. {
  33461. return (! flags.isDisabledFlag)
  33462. && (parentComponent_ == 0 || parentComponent_->isEnabled());
  33463. }
  33464. void Component::setEnabled (const bool shouldBeEnabled)
  33465. {
  33466. if (flags.isDisabledFlag == shouldBeEnabled)
  33467. {
  33468. flags.isDisabledFlag = ! shouldBeEnabled;
  33469. // if any parent components are disabled, setting our flag won't make a difference,
  33470. // so no need to send a change message
  33471. if (parentComponent_ == 0 || parentComponent_->isEnabled())
  33472. sendEnablementChangeMessage();
  33473. }
  33474. }
  33475. void Component::sendEnablementChangeMessage()
  33476. {
  33477. const ComponentDeletionWatcher deletionChecker (this);
  33478. enablementChanged();
  33479. if (deletionChecker.hasBeenDeleted())
  33480. return;
  33481. for (int i = getNumChildComponents(); --i >= 0;)
  33482. {
  33483. Component* const c = getChildComponent (i);
  33484. if (c != 0)
  33485. {
  33486. c->sendEnablementChangeMessage();
  33487. if (deletionChecker.hasBeenDeleted())
  33488. return;
  33489. }
  33490. }
  33491. }
  33492. void Component::enablementChanged()
  33493. {
  33494. }
  33495. void Component::setWantsKeyboardFocus (const bool wantsFocus) throw()
  33496. {
  33497. flags.wantsFocusFlag = wantsFocus;
  33498. }
  33499. void Component::setMouseClickGrabsKeyboardFocus (const bool shouldGrabFocus)
  33500. {
  33501. flags.dontFocusOnMouseClickFlag = ! shouldGrabFocus;
  33502. }
  33503. bool Component::getMouseClickGrabsKeyboardFocus() const throw()
  33504. {
  33505. return ! flags.dontFocusOnMouseClickFlag;
  33506. }
  33507. bool Component::getWantsKeyboardFocus() const throw()
  33508. {
  33509. return flags.wantsFocusFlag && ! flags.isDisabledFlag;
  33510. }
  33511. void Component::setFocusContainer (const bool shouldBeFocusContainer) throw()
  33512. {
  33513. flags.isFocusContainerFlag = shouldBeFocusContainer;
  33514. }
  33515. bool Component::isFocusContainer() const throw()
  33516. {
  33517. return flags.isFocusContainerFlag;
  33518. }
  33519. int Component::getExplicitFocusOrder() const throw()
  33520. {
  33521. return properties ["_jexfo"];
  33522. }
  33523. void Component::setExplicitFocusOrder (const int newFocusOrderIndex) throw()
  33524. {
  33525. properties.set ("_jexfo", newFocusOrderIndex);
  33526. }
  33527. KeyboardFocusTraverser* Component::createFocusTraverser()
  33528. {
  33529. if (flags.isFocusContainerFlag || parentComponent_ == 0)
  33530. return new KeyboardFocusTraverser();
  33531. return parentComponent_->createFocusTraverser();
  33532. }
  33533. void Component::takeKeyboardFocus (const FocusChangeType cause)
  33534. {
  33535. // give the focus to this component
  33536. if (currentlyFocusedComponent != this)
  33537. {
  33538. JUCE_TRY
  33539. {
  33540. // get the focus onto our desktop window
  33541. ComponentPeer* const peer = getPeer();
  33542. if (peer != 0)
  33543. {
  33544. const ComponentDeletionWatcher deletionChecker (this);
  33545. peer->grabFocus();
  33546. if (peer->isFocused() && currentlyFocusedComponent != this)
  33547. {
  33548. Component* const componentLosingFocus = currentlyFocusedComponent;
  33549. currentlyFocusedComponent = this;
  33550. Desktop::getInstance().triggerFocusCallback();
  33551. // call this after setting currentlyFocusedComponent so that the one that's
  33552. // losing it has a chance to see where focus is going
  33553. if (componentLosingFocus->isValidComponent())
  33554. componentLosingFocus->internalFocusLoss (cause);
  33555. if (currentlyFocusedComponent == this)
  33556. {
  33557. focusGained (cause);
  33558. if (! deletionChecker.hasBeenDeleted())
  33559. internalChildFocusChange (cause);
  33560. }
  33561. }
  33562. }
  33563. }
  33564. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  33565. catch (const std::exception& e)
  33566. {
  33567. currentlyFocusedComponent = 0;
  33568. Desktop::getInstance().triggerFocusCallback();
  33569. JUCEApplication::sendUnhandledException (&e, __FILE__, __LINE__);
  33570. }
  33571. catch (...)
  33572. {
  33573. currentlyFocusedComponent = 0;
  33574. Desktop::getInstance().triggerFocusCallback();
  33575. JUCEApplication::sendUnhandledException (0, __FILE__, __LINE__);
  33576. }
  33577. #endif
  33578. }
  33579. }
  33580. void Component::grabFocusInternal (const FocusChangeType cause, const bool canTryParent)
  33581. {
  33582. if (isShowing())
  33583. {
  33584. if (flags.wantsFocusFlag && (isEnabled() || parentComponent_ == 0))
  33585. {
  33586. takeKeyboardFocus (cause);
  33587. }
  33588. else
  33589. {
  33590. if (isParentOf (currentlyFocusedComponent)
  33591. && currentlyFocusedComponent->isShowing())
  33592. {
  33593. // do nothing if the focused component is actually a child of ours..
  33594. }
  33595. else
  33596. {
  33597. // find the default child component..
  33598. ScopedPointer <KeyboardFocusTraverser> traverser (createFocusTraverser());
  33599. if (traverser != 0)
  33600. {
  33601. Component* const defaultComp = traverser->getDefaultComponent (this);
  33602. traverser = 0;
  33603. if (defaultComp != 0)
  33604. {
  33605. defaultComp->grabFocusInternal (cause, false);
  33606. return;
  33607. }
  33608. }
  33609. if (canTryParent && parentComponent_ != 0)
  33610. {
  33611. // if no children want it and we're allowed to try our parent comp,
  33612. // then pass up to parent, which will try our siblings.
  33613. parentComponent_->grabFocusInternal (cause, true);
  33614. }
  33615. }
  33616. }
  33617. }
  33618. }
  33619. void Component::grabKeyboardFocus()
  33620. {
  33621. // if component methods are being called from threads other than the message
  33622. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  33623. checkMessageManagerIsLocked
  33624. grabFocusInternal (focusChangedDirectly);
  33625. }
  33626. void Component::moveKeyboardFocusToSibling (const bool moveToNext)
  33627. {
  33628. // if component methods are being called from threads other than the message
  33629. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  33630. checkMessageManagerIsLocked
  33631. if (parentComponent_ != 0)
  33632. {
  33633. ScopedPointer <KeyboardFocusTraverser> traverser (createFocusTraverser());
  33634. if (traverser != 0)
  33635. {
  33636. Component* const nextComp = moveToNext ? traverser->getNextComponent (this)
  33637. : traverser->getPreviousComponent (this);
  33638. traverser = 0;
  33639. if (nextComp != 0)
  33640. {
  33641. if (nextComp->isCurrentlyBlockedByAnotherModalComponent())
  33642. {
  33643. const ComponentDeletionWatcher deletionChecker (nextComp);
  33644. internalModalInputAttempt();
  33645. if (deletionChecker.hasBeenDeleted()
  33646. || nextComp->isCurrentlyBlockedByAnotherModalComponent())
  33647. return;
  33648. }
  33649. nextComp->grabFocusInternal (focusChangedByTabKey);
  33650. return;
  33651. }
  33652. }
  33653. parentComponent_->moveKeyboardFocusToSibling (moveToNext);
  33654. }
  33655. }
  33656. bool Component::hasKeyboardFocus (const bool trueIfChildIsFocused) const throw()
  33657. {
  33658. return (currentlyFocusedComponent == this)
  33659. || (trueIfChildIsFocused && isParentOf (currentlyFocusedComponent));
  33660. }
  33661. Component* JUCE_CALLTYPE Component::getCurrentlyFocusedComponent() throw()
  33662. {
  33663. return currentlyFocusedComponent;
  33664. }
  33665. void Component::giveAwayFocus()
  33666. {
  33667. // use a copy so we can clear the value before the call
  33668. Component* const componentLosingFocus = currentlyFocusedComponent;
  33669. currentlyFocusedComponent = 0;
  33670. Desktop::getInstance().triggerFocusCallback();
  33671. if (componentLosingFocus->isValidComponent())
  33672. componentLosingFocus->internalFocusLoss (focusChangedDirectly);
  33673. }
  33674. bool Component::isMouseOver() const throw()
  33675. {
  33676. return flags.mouseOverFlag;
  33677. }
  33678. bool Component::isMouseButtonDown() const throw()
  33679. {
  33680. return flags.draggingFlag;
  33681. }
  33682. bool Component::isMouseOverOrDragging() const throw()
  33683. {
  33684. return flags.mouseOverFlag || flags.draggingFlag;
  33685. }
  33686. bool JUCE_CALLTYPE Component::isMouseButtonDownAnywhere() throw()
  33687. {
  33688. return ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown();
  33689. }
  33690. void Component::getMouseXYRelative (int& mx, int& my) const throw()
  33691. {
  33692. Desktop::getMousePosition (mx, my);
  33693. globalPositionToRelative (mx, my);
  33694. mx += unboundedMouseOffsetX;
  33695. my += unboundedMouseOffsetY;
  33696. }
  33697. void Component::enableUnboundedMouseMovement (bool enable,
  33698. bool keepCursorVisibleUntilOffscreen) throw()
  33699. {
  33700. enable = enable && isMouseButtonDown();
  33701. isCursorVisibleUntilOffscreen = keepCursorVisibleUntilOffscreen;
  33702. if (enable != isUnboundedMouseModeOn)
  33703. {
  33704. if ((! enable) && ((! isCursorVisibleUntilOffscreen)
  33705. || unboundedMouseOffsetX != 0
  33706. || unboundedMouseOffsetY != 0))
  33707. {
  33708. // when released, return the mouse to within the component's bounds
  33709. int mx, my;
  33710. getMouseXYRelative (mx, my);
  33711. mx = jlimit (0, getWidth(), mx);
  33712. my = jlimit (0, getHeight(), my);
  33713. relativePositionToGlobal (mx, my);
  33714. Desktop::setMousePosition (mx, my);
  33715. }
  33716. isUnboundedMouseModeOn = enable;
  33717. unboundedMouseOffsetX = 0;
  33718. unboundedMouseOffsetY = 0;
  33719. internalUpdateMouseCursor (true);
  33720. }
  33721. }
  33722. Component* JUCE_CALLTYPE Component::getComponentUnderMouse() throw()
  33723. {
  33724. return componentUnderMouse;
  33725. }
  33726. const Rectangle<int> Component::getParentMonitorArea() const throw()
  33727. {
  33728. int centreX = getWidth() / 2;
  33729. int centreY = getHeight() / 2;
  33730. relativePositionToGlobal (centreX, centreY);
  33731. return Desktop::getInstance().getMonitorAreaContaining (centreX, centreY);
  33732. }
  33733. void Component::addKeyListener (KeyListener* const newListener) throw()
  33734. {
  33735. if (keyListeners_ == 0)
  33736. keyListeners_ = new VoidArray();
  33737. keyListeners_->addIfNotAlreadyThere (newListener);
  33738. }
  33739. void Component::removeKeyListener (KeyListener* const listenerToRemove) throw()
  33740. {
  33741. if (keyListeners_ != 0)
  33742. keyListeners_->removeValue (listenerToRemove);
  33743. }
  33744. bool Component::keyPressed (const KeyPress&)
  33745. {
  33746. return false;
  33747. }
  33748. bool Component::keyStateChanged (const bool /*isKeyDown*/)
  33749. {
  33750. return false;
  33751. }
  33752. void Component::modifierKeysChanged (const ModifierKeys& modifiers)
  33753. {
  33754. if (parentComponent_ != 0)
  33755. parentComponent_->modifierKeysChanged (modifiers);
  33756. }
  33757. void Component::internalModifierKeysChanged()
  33758. {
  33759. sendFakeMouseMove();
  33760. modifierKeysChanged (ModifierKeys::getCurrentModifiers());
  33761. }
  33762. ComponentPeer* Component::getPeer() const throw()
  33763. {
  33764. if (flags.hasHeavyweightPeerFlag)
  33765. return ComponentPeer::getPeerFor (this);
  33766. else if (parentComponent_ != 0)
  33767. return parentComponent_->getPeer();
  33768. else
  33769. return 0;
  33770. }
  33771. ComponentDeletionWatcher::ComponentDeletionWatcher (const Component* const componentToWatch_) throw()
  33772. : componentToWatch (componentToWatch_),
  33773. componentUID (componentToWatch_->getComponentUID())
  33774. {
  33775. // not possible to check on an already-deleted object..
  33776. jassert (componentToWatch_->isValidComponent());
  33777. }
  33778. ComponentDeletionWatcher::~ComponentDeletionWatcher() throw() {}
  33779. bool ComponentDeletionWatcher::hasBeenDeleted() const throw()
  33780. {
  33781. return ! (componentToWatch->isValidComponent()
  33782. && componentToWatch->getComponentUID() == componentUID);
  33783. }
  33784. const Component* ComponentDeletionWatcher::getComponent() const throw()
  33785. {
  33786. return hasBeenDeleted() ? 0 : componentToWatch;
  33787. }
  33788. END_JUCE_NAMESPACE
  33789. /*** End of inlined file: juce_Component.cpp ***/
  33790. /*** Start of inlined file: juce_ComponentListener.cpp ***/
  33791. BEGIN_JUCE_NAMESPACE
  33792. void ComponentListener::componentMovedOrResized (Component&, bool, bool)
  33793. {
  33794. }
  33795. void ComponentListener::componentBroughtToFront (Component&)
  33796. {
  33797. }
  33798. void ComponentListener::componentVisibilityChanged (Component&)
  33799. {
  33800. }
  33801. void ComponentListener::componentChildrenChanged (Component&)
  33802. {
  33803. }
  33804. void ComponentListener::componentParentHierarchyChanged (Component&)
  33805. {
  33806. }
  33807. void ComponentListener::componentNameChanged (Component&)
  33808. {
  33809. }
  33810. END_JUCE_NAMESPACE
  33811. /*** End of inlined file: juce_ComponentListener.cpp ***/
  33812. /*** Start of inlined file: juce_Desktop.cpp ***/
  33813. BEGIN_JUCE_NAMESPACE
  33814. Desktop::Desktop() throw()
  33815. : lastFakeMouseMoveX (0),
  33816. lastFakeMouseMoveY (0),
  33817. mouseClickCounter (0),
  33818. mouseMovedSignificantlySincePressed (false),
  33819. kioskModeComponent (0)
  33820. {
  33821. zerostruct (mouseDowns);
  33822. refreshMonitorSizes();
  33823. }
  33824. Desktop::~Desktop() throw()
  33825. {
  33826. jassert (instance == this);
  33827. instance = 0;
  33828. // doh! If you don't delete all your windows before exiting, you're going to
  33829. // be leaking memory!
  33830. jassert (desktopComponents.size() == 0);
  33831. }
  33832. Desktop& JUCE_CALLTYPE Desktop::getInstance() throw()
  33833. {
  33834. if (instance == 0)
  33835. instance = new Desktop();
  33836. return *instance;
  33837. }
  33838. Desktop* Desktop::instance = 0;
  33839. extern void juce_updateMultiMonitorInfo (Array <Rectangle<int> >& monitorCoords,
  33840. const bool clipToWorkArea);
  33841. void Desktop::refreshMonitorSizes() throw()
  33842. {
  33843. const Array <Rectangle<int> > oldClipped (monitorCoordsClipped);
  33844. const Array <Rectangle<int> > oldUnclipped (monitorCoordsUnclipped);
  33845. monitorCoordsClipped.clear();
  33846. monitorCoordsUnclipped.clear();
  33847. juce_updateMultiMonitorInfo (monitorCoordsClipped, true);
  33848. juce_updateMultiMonitorInfo (monitorCoordsUnclipped, false);
  33849. jassert (monitorCoordsClipped.size() > 0
  33850. && monitorCoordsClipped.size() == monitorCoordsUnclipped.size());
  33851. if (oldClipped != monitorCoordsClipped
  33852. || oldUnclipped != monitorCoordsUnclipped)
  33853. {
  33854. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  33855. {
  33856. ComponentPeer* const p = ComponentPeer::getPeer (i);
  33857. if (p != 0)
  33858. p->handleScreenSizeChange();
  33859. }
  33860. }
  33861. }
  33862. int Desktop::getNumDisplayMonitors() const throw()
  33863. {
  33864. return monitorCoordsClipped.size();
  33865. }
  33866. const Rectangle<int> Desktop::getDisplayMonitorCoordinates (const int index, const bool clippedToWorkArea) const throw()
  33867. {
  33868. return clippedToWorkArea ? monitorCoordsClipped [index]
  33869. : monitorCoordsUnclipped [index];
  33870. }
  33871. const RectangleList Desktop::getAllMonitorDisplayAreas (const bool clippedToWorkArea) const throw()
  33872. {
  33873. RectangleList rl;
  33874. for (int i = 0; i < getNumDisplayMonitors(); ++i)
  33875. rl.addWithoutMerging (getDisplayMonitorCoordinates (i, clippedToWorkArea));
  33876. return rl;
  33877. }
  33878. const Rectangle<int> Desktop::getMainMonitorArea (const bool clippedToWorkArea) const throw()
  33879. {
  33880. return getDisplayMonitorCoordinates (0, clippedToWorkArea);
  33881. }
  33882. const Rectangle<int> Desktop::getMonitorAreaContaining (int cx, int cy, const bool clippedToWorkArea) const throw()
  33883. {
  33884. Rectangle<int> best (getMainMonitorArea (clippedToWorkArea));
  33885. double bestDistance = 1.0e10;
  33886. for (int i = getNumDisplayMonitors(); --i >= 0;)
  33887. {
  33888. const Rectangle<int> rect (getDisplayMonitorCoordinates (i, clippedToWorkArea));
  33889. if (rect.contains (cx, cy))
  33890. return rect;
  33891. const double distance = juce_hypot ((double) (rect.getCentreX() - cx),
  33892. (double) (rect.getCentreY() - cy));
  33893. if (distance < bestDistance)
  33894. {
  33895. bestDistance = distance;
  33896. best = rect;
  33897. }
  33898. }
  33899. return best;
  33900. }
  33901. int Desktop::getNumComponents() const throw()
  33902. {
  33903. return desktopComponents.size();
  33904. }
  33905. Component* Desktop::getComponent (const int index) const throw()
  33906. {
  33907. return desktopComponents [index];
  33908. }
  33909. Component* Desktop::findComponentAt (const int screenX,
  33910. const int screenY) const
  33911. {
  33912. for (int i = desktopComponents.size(); --i >= 0;)
  33913. {
  33914. Component* const c = desktopComponents.getUnchecked(i);
  33915. int x = screenX, y = screenY;
  33916. c->globalPositionToRelative (x, y);
  33917. if (c->contains (x, y))
  33918. return c->getComponentAt (x, y);
  33919. }
  33920. return 0;
  33921. }
  33922. void Desktop::addDesktopComponent (Component* const c) throw()
  33923. {
  33924. jassert (c != 0);
  33925. jassert (! desktopComponents.contains (c));
  33926. desktopComponents.addIfNotAlreadyThere (c);
  33927. }
  33928. void Desktop::removeDesktopComponent (Component* const c) throw()
  33929. {
  33930. desktopComponents.removeValue (c);
  33931. }
  33932. void Desktop::componentBroughtToFront (Component* const c) throw()
  33933. {
  33934. const int index = desktopComponents.indexOf (c);
  33935. jassert (index >= 0);
  33936. if (index >= 0)
  33937. {
  33938. int newIndex = -1;
  33939. if (! c->isAlwaysOnTop())
  33940. {
  33941. newIndex = desktopComponents.size();
  33942. while (newIndex > 0 && desktopComponents.getUnchecked (newIndex - 1)->isAlwaysOnTop())
  33943. --newIndex;
  33944. --newIndex;
  33945. }
  33946. desktopComponents.move (index, newIndex);
  33947. }
  33948. }
  33949. void Desktop::getLastMouseDownPosition (int& x, int& y) throw()
  33950. {
  33951. const Desktop& d = getInstance();
  33952. x = d.mouseDowns[0].position.getX();
  33953. y = d.mouseDowns[0].position.getY();
  33954. }
  33955. int Desktop::getMouseButtonClickCounter() throw()
  33956. {
  33957. return getInstance().mouseClickCounter;
  33958. }
  33959. void Desktop::incrementMouseClickCounter() throw()
  33960. {
  33961. ++mouseClickCounter;
  33962. }
  33963. const Time Desktop::getLastMouseDownTime() const throw()
  33964. {
  33965. return Time (mouseDowns[0].time);
  33966. }
  33967. void Desktop::registerMouseDown (const Point<int>& position, int64 time, Component* component) throw()
  33968. {
  33969. for (int i = numElementsInArray (mouseDowns); --i > 0;)
  33970. mouseDowns[i] = mouseDowns[i - 1];
  33971. mouseDowns[0].position = position;
  33972. mouseDowns[0].time = time;
  33973. mouseDowns[0].component = component;
  33974. mouseMovedSignificantlySincePressed = false;
  33975. }
  33976. void Desktop::registerMouseDrag (const Point<int>& position) throw()
  33977. {
  33978. mouseMovedSignificantlySincePressed
  33979. = mouseMovedSignificantlySincePressed
  33980. || abs (mouseDowns[0].position.getX() - position.getX()) >= 4
  33981. || abs (mouseDowns[0].position.getY() - position.getY()) >= 4;
  33982. }
  33983. int Desktop::getNumberOfMultipleClicks() const throw()
  33984. {
  33985. int numClicks = 0;
  33986. if (mouseDowns[0].time != 0)
  33987. {
  33988. if (! mouseMovedSignificantlySincePressed)
  33989. ++numClicks;
  33990. for (int i = 1; i < numElementsInArray (mouseDowns); ++i)
  33991. {
  33992. if (mouseDowns[0].time - mouseDowns[i].time
  33993. < (int) (MouseEvent::getDoubleClickTimeout() * (1.0 + 0.25 * (i - 1)))
  33994. && abs (mouseDowns[0].position.getX() - mouseDowns[i].position.getX()) < 8
  33995. && abs (mouseDowns[0].position.getY() - mouseDowns[i].position.getY()) < 8
  33996. && mouseDowns[0].component == mouseDowns[i].component)
  33997. {
  33998. ++numClicks;
  33999. }
  34000. else
  34001. {
  34002. break;
  34003. }
  34004. }
  34005. }
  34006. return numClicks;
  34007. }
  34008. void Desktop::addGlobalMouseListener (MouseListener* const listener) throw()
  34009. {
  34010. jassert (listener != 0);
  34011. if (listener != 0)
  34012. {
  34013. mouseListeners.add (listener);
  34014. resetTimer();
  34015. }
  34016. }
  34017. void Desktop::removeGlobalMouseListener (MouseListener* const listener) throw()
  34018. {
  34019. mouseListeners.removeValue (listener);
  34020. resetTimer();
  34021. }
  34022. void Desktop::addFocusChangeListener (FocusChangeListener* const listener) throw()
  34023. {
  34024. jassert (listener != 0);
  34025. if (listener != 0)
  34026. focusListeners.add (listener);
  34027. }
  34028. void Desktop::removeFocusChangeListener (FocusChangeListener* const listener) throw()
  34029. {
  34030. focusListeners.removeValue (listener);
  34031. }
  34032. void Desktop::triggerFocusCallback() throw()
  34033. {
  34034. triggerAsyncUpdate();
  34035. }
  34036. void Desktop::handleAsyncUpdate()
  34037. {
  34038. for (int i = focusListeners.size(); --i >= 0;)
  34039. {
  34040. ((FocusChangeListener*) focusListeners.getUnchecked (i))->globalFocusChanged (Component::getCurrentlyFocusedComponent());
  34041. i = jmin (i, focusListeners.size());
  34042. }
  34043. }
  34044. void Desktop::timerCallback()
  34045. {
  34046. int x, y;
  34047. getMousePosition (x, y);
  34048. if (lastFakeMouseMoveX != x || lastFakeMouseMoveY != y)
  34049. sendMouseMove();
  34050. }
  34051. void Desktop::sendMouseMove()
  34052. {
  34053. if (mouseListeners.size() > 0)
  34054. {
  34055. startTimer (20);
  34056. int x, y;
  34057. getMousePosition (x, y);
  34058. lastFakeMouseMoveX = x;
  34059. lastFakeMouseMoveY = y;
  34060. Component* const target = findComponentAt (x, y);
  34061. if (target != 0)
  34062. {
  34063. target->globalPositionToRelative (x, y);
  34064. ComponentDeletionWatcher deletionChecker (target);
  34065. const MouseEvent me (x, y,
  34066. ModifierKeys::getCurrentModifiers(),
  34067. target,
  34068. Time::getCurrentTime(),
  34069. x, y,
  34070. Time::getCurrentTime(),
  34071. 0, false);
  34072. for (int i = mouseListeners.size(); --i >= 0;)
  34073. {
  34074. if (ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown())
  34075. ((MouseListener*) mouseListeners[i])->mouseDrag (me);
  34076. else
  34077. ((MouseListener*) mouseListeners[i])->mouseMove (me);
  34078. if (deletionChecker.hasBeenDeleted())
  34079. return;
  34080. i = jmin (i, mouseListeners.size());
  34081. }
  34082. }
  34083. }
  34084. }
  34085. void Desktop::resetTimer() throw()
  34086. {
  34087. if (mouseListeners.size() == 0)
  34088. stopTimer();
  34089. else
  34090. startTimer (100);
  34091. getMousePosition (lastFakeMouseMoveX, lastFakeMouseMoveY);
  34092. }
  34093. extern void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars);
  34094. void Desktop::setKioskModeComponent (Component* componentToUse, const bool allowMenusAndBars)
  34095. {
  34096. if (kioskModeComponent != componentToUse)
  34097. {
  34098. // agh! Don't delete a component without first stopping it being the kiosk comp
  34099. jassert (kioskModeComponent == 0 || kioskModeComponent->isValidComponent());
  34100. // agh! Don't remove a component from the desktop if it's the kiosk comp!
  34101. jassert (kioskModeComponent == 0 || kioskModeComponent->isOnDesktop());
  34102. if (kioskModeComponent->isValidComponent())
  34103. {
  34104. juce_setKioskComponent (kioskModeComponent, false, allowMenusAndBars);
  34105. kioskModeComponent->setBounds (kioskComponentOriginalBounds);
  34106. }
  34107. kioskModeComponent = componentToUse;
  34108. if (kioskModeComponent != 0)
  34109. {
  34110. jassert (kioskModeComponent->isValidComponent());
  34111. // Only components that are already on the desktop can be put into kiosk mode!
  34112. jassert (kioskModeComponent->isOnDesktop());
  34113. kioskComponentOriginalBounds = kioskModeComponent->getBounds();
  34114. juce_setKioskComponent (kioskModeComponent, true, allowMenusAndBars);
  34115. }
  34116. }
  34117. }
  34118. END_JUCE_NAMESPACE
  34119. /*** End of inlined file: juce_Desktop.cpp ***/
  34120. /*** Start of inlined file: juce_ArrowButton.cpp ***/
  34121. BEGIN_JUCE_NAMESPACE
  34122. ArrowButton::ArrowButton (const String& name,
  34123. float arrowDirectionInRadians,
  34124. const Colour& arrowColour)
  34125. : Button (name),
  34126. colour (arrowColour)
  34127. {
  34128. path.lineTo (0.0f, 1.0f);
  34129. path.lineTo (1.0f, 0.5f);
  34130. path.closeSubPath();
  34131. path.applyTransform (AffineTransform::rotation (float_Pi * 2.0f * arrowDirectionInRadians,
  34132. 0.5f, 0.5f));
  34133. setComponentEffect (&shadow);
  34134. buttonStateChanged();
  34135. }
  34136. ArrowButton::~ArrowButton()
  34137. {
  34138. }
  34139. void ArrowButton::paintButton (Graphics& g,
  34140. bool /*isMouseOverButton*/,
  34141. bool /*isButtonDown*/)
  34142. {
  34143. g.setColour (colour);
  34144. g.fillPath (path, path.getTransformToScaleToFit ((float) offset,
  34145. (float) offset,
  34146. (float) (getWidth() - 3),
  34147. (float) (getHeight() - 3),
  34148. false));
  34149. }
  34150. void ArrowButton::buttonStateChanged()
  34151. {
  34152. offset = (isDown()) ? 1 : 0;
  34153. shadow.setShadowProperties ((isDown()) ? 1.2f : 3.0f,
  34154. 0.3f, -1, 0);
  34155. }
  34156. END_JUCE_NAMESPACE
  34157. /*** End of inlined file: juce_ArrowButton.cpp ***/
  34158. /*** Start of inlined file: juce_Button.cpp ***/
  34159. BEGIN_JUCE_NAMESPACE
  34160. class Button::RepeatTimer : public Timer
  34161. {
  34162. public:
  34163. RepeatTimer (Button& owner_) : owner (owner_) {}
  34164. void timerCallback() { owner.repeatTimerCallback(); }
  34165. juce_UseDebuggingNewOperator
  34166. private:
  34167. Button& owner;
  34168. RepeatTimer (const RepeatTimer&);
  34169. RepeatTimer& operator= (const RepeatTimer&);
  34170. };
  34171. Button::Button (const String& name)
  34172. : Component (name),
  34173. keySource (0),
  34174. text (name),
  34175. buttonPressTime (0),
  34176. lastTimeCallbackTime (0),
  34177. commandManagerToUse (0),
  34178. autoRepeatDelay (-1),
  34179. autoRepeatSpeed (0),
  34180. autoRepeatMinimumDelay (-1),
  34181. radioGroupId (0),
  34182. commandID (0),
  34183. connectedEdgeFlags (0),
  34184. buttonState (buttonNormal),
  34185. lastToggleState (false),
  34186. clickTogglesState (false),
  34187. needsToRelease (false),
  34188. needsRepainting (false),
  34189. isKeyDown (false),
  34190. triggerOnMouseDown (false),
  34191. generateTooltip (false)
  34192. {
  34193. setWantsKeyboardFocus (true);
  34194. isOn.addListener (this);
  34195. }
  34196. Button::~Button()
  34197. {
  34198. isOn.removeListener (this);
  34199. if (commandManagerToUse != 0)
  34200. commandManagerToUse->removeListener (this);
  34201. repeatTimer = 0;
  34202. clearShortcuts();
  34203. }
  34204. void Button::setButtonText (const String& newText)
  34205. {
  34206. if (text != newText)
  34207. {
  34208. text = newText;
  34209. repaint();
  34210. }
  34211. }
  34212. void Button::setTooltip (const String& newTooltip)
  34213. {
  34214. SettableTooltipClient::setTooltip (newTooltip);
  34215. generateTooltip = false;
  34216. }
  34217. const String Button::getTooltip()
  34218. {
  34219. if (generateTooltip && commandManagerToUse != 0 && commandID != 0)
  34220. {
  34221. String tt (commandManagerToUse->getDescriptionOfCommand (commandID));
  34222. Array <KeyPress> keyPresses (commandManagerToUse->getKeyMappings()->getKeyPressesAssignedToCommand (commandID));
  34223. for (int i = 0; i < keyPresses.size(); ++i)
  34224. {
  34225. const String key (keyPresses.getReference(i).getTextDescription());
  34226. tt << " [";
  34227. if (key.length() == 1)
  34228. tt << TRANS("shortcut") << ": '" << key << "']";
  34229. else
  34230. tt << key << ']';
  34231. }
  34232. return tt;
  34233. }
  34234. return SettableTooltipClient::getTooltip();
  34235. }
  34236. void Button::setConnectedEdges (const int connectedEdgeFlags_)
  34237. {
  34238. if (connectedEdgeFlags != connectedEdgeFlags_)
  34239. {
  34240. connectedEdgeFlags = connectedEdgeFlags_;
  34241. repaint();
  34242. }
  34243. }
  34244. void Button::setToggleState (const bool shouldBeOn,
  34245. const bool sendChangeNotification)
  34246. {
  34247. if (shouldBeOn != lastToggleState)
  34248. {
  34249. const ComponentDeletionWatcher deletionWatcher (this);
  34250. isOn = shouldBeOn;
  34251. lastToggleState = shouldBeOn;
  34252. repaint();
  34253. if (sendChangeNotification)
  34254. sendClickMessage (ModifierKeys());
  34255. if ((! deletionWatcher.hasBeenDeleted()) && lastToggleState)
  34256. turnOffOtherButtonsInGroup (sendChangeNotification);
  34257. }
  34258. }
  34259. void Button::setClickingTogglesState (const bool shouldToggle) throw()
  34260. {
  34261. clickTogglesState = shouldToggle;
  34262. // if you've got clickTogglesState turned on, you shouldn't also connect the button
  34263. // up to be a command invoker. Instead, your command handler must flip the state of whatever
  34264. // it is that this button represents, and the button will update its state to reflect this
  34265. // in the applicationCommandListChanged() method.
  34266. jassert (commandManagerToUse == 0 || ! clickTogglesState);
  34267. }
  34268. bool Button::getClickingTogglesState() const throw()
  34269. {
  34270. return clickTogglesState;
  34271. }
  34272. void Button::valueChanged (Value& value)
  34273. {
  34274. if (value.refersToSameSourceAs (isOn))
  34275. setToggleState (isOn.getValue(), true);
  34276. }
  34277. void Button::setRadioGroupId (const int newGroupId)
  34278. {
  34279. if (radioGroupId != newGroupId)
  34280. {
  34281. radioGroupId = newGroupId;
  34282. if (lastToggleState)
  34283. turnOffOtherButtonsInGroup (true);
  34284. }
  34285. }
  34286. void Button::turnOffOtherButtonsInGroup (const bool sendChangeNotification)
  34287. {
  34288. Component* const p = getParentComponent();
  34289. if (p != 0 && radioGroupId != 0)
  34290. {
  34291. const ComponentDeletionWatcher deletionWatcher (this);
  34292. for (int i = p->getNumChildComponents(); --i >= 0;)
  34293. {
  34294. Component* const c = p->getChildComponent (i);
  34295. if (c != this)
  34296. {
  34297. Button* const b = dynamic_cast <Button*> (c);
  34298. if (b != 0 && b->getRadioGroupId() == radioGroupId)
  34299. {
  34300. b->setToggleState (false, sendChangeNotification);
  34301. if (deletionWatcher.hasBeenDeleted())
  34302. return;
  34303. }
  34304. }
  34305. }
  34306. }
  34307. }
  34308. void Button::enablementChanged()
  34309. {
  34310. updateState (0);
  34311. repaint();
  34312. }
  34313. Button::ButtonState Button::updateState (const MouseEvent* const e)
  34314. {
  34315. ButtonState state = buttonNormal;
  34316. if (isEnabled() && isVisible() && ! isCurrentlyBlockedByAnotherModalComponent())
  34317. {
  34318. int mx, my;
  34319. if (e == 0)
  34320. {
  34321. getMouseXYRelative (mx, my);
  34322. }
  34323. else
  34324. {
  34325. const MouseEvent e2 (e->getEventRelativeTo (this));
  34326. mx = e2.x;
  34327. my = e2.y;
  34328. }
  34329. const bool over = reallyContains (mx, my, true);
  34330. const bool down = isMouseButtonDown();
  34331. if ((down && (over || (triggerOnMouseDown && buttonState == buttonDown))) || isKeyDown)
  34332. state = buttonDown;
  34333. else if (over)
  34334. state = buttonOver;
  34335. }
  34336. setState (state);
  34337. return state;
  34338. }
  34339. void Button::setState (const ButtonState newState)
  34340. {
  34341. if (buttonState != newState)
  34342. {
  34343. buttonState = newState;
  34344. repaint();
  34345. if (buttonState == buttonDown)
  34346. {
  34347. buttonPressTime = Time::getApproximateMillisecondCounter();
  34348. lastTimeCallbackTime = buttonPressTime;
  34349. }
  34350. sendStateMessage();
  34351. }
  34352. }
  34353. bool Button::isDown() const throw()
  34354. {
  34355. return buttonState == buttonDown;
  34356. }
  34357. bool Button::isOver() const throw()
  34358. {
  34359. return buttonState != buttonNormal;
  34360. }
  34361. void Button::buttonStateChanged()
  34362. {
  34363. }
  34364. uint32 Button::getMillisecondsSinceButtonDown() const throw()
  34365. {
  34366. const uint32 now = Time::getApproximateMillisecondCounter();
  34367. return now > buttonPressTime ? now - buttonPressTime : 0;
  34368. }
  34369. void Button::setTriggeredOnMouseDown (const bool isTriggeredOnMouseDown) throw()
  34370. {
  34371. triggerOnMouseDown = isTriggeredOnMouseDown;
  34372. }
  34373. void Button::clicked()
  34374. {
  34375. }
  34376. void Button::clicked (const ModifierKeys& /*modifiers*/)
  34377. {
  34378. clicked();
  34379. }
  34380. static const int clickMessageId = 0x2f3f4f99;
  34381. void Button::triggerClick()
  34382. {
  34383. postCommandMessage (clickMessageId);
  34384. }
  34385. void Button::internalClickCallback (const ModifierKeys& modifiers)
  34386. {
  34387. if (clickTogglesState)
  34388. setToggleState ((radioGroupId != 0) || ! lastToggleState, false);
  34389. sendClickMessage (modifiers);
  34390. }
  34391. void Button::flashButtonState()
  34392. {
  34393. if (isEnabled())
  34394. {
  34395. needsToRelease = true;
  34396. setState (buttonDown);
  34397. getRepeatTimer().startTimer (100);
  34398. }
  34399. }
  34400. void Button::handleCommandMessage (int commandId)
  34401. {
  34402. if (commandId == clickMessageId)
  34403. {
  34404. if (isEnabled())
  34405. {
  34406. flashButtonState();
  34407. internalClickCallback (ModifierKeys::getCurrentModifiers());
  34408. }
  34409. }
  34410. else
  34411. {
  34412. Component::handleCommandMessage (commandId);
  34413. }
  34414. }
  34415. void Button::addButtonListener (ButtonListener* const newListener)
  34416. {
  34417. jassert (newListener != 0);
  34418. jassert (! buttonListeners.contains (newListener)); // trying to add a listener to the list twice!
  34419. if (newListener != 0)
  34420. buttonListeners.add (newListener);
  34421. }
  34422. void Button::removeButtonListener (ButtonListener* const listener)
  34423. {
  34424. jassert (buttonListeners.contains (listener)); // trying to remove a listener that isn't on the list!
  34425. buttonListeners.removeValue (listener);
  34426. }
  34427. void Button::sendClickMessage (const ModifierKeys& modifiers)
  34428. {
  34429. const ComponentDeletionWatcher cdw (this);
  34430. if (commandManagerToUse != 0 && commandID != 0)
  34431. {
  34432. ApplicationCommandTarget::InvocationInfo info (commandID);
  34433. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromButton;
  34434. info.originatingComponent = this;
  34435. commandManagerToUse->invoke (info, true);
  34436. }
  34437. clicked (modifiers);
  34438. if (! cdw.hasBeenDeleted())
  34439. {
  34440. for (int i = buttonListeners.size(); --i >= 0;)
  34441. {
  34442. ButtonListener* const bl = (ButtonListener*) buttonListeners[i];
  34443. if (bl != 0)
  34444. {
  34445. bl->buttonClicked (this);
  34446. if (cdw.hasBeenDeleted())
  34447. return;
  34448. }
  34449. }
  34450. }
  34451. }
  34452. void Button::sendStateMessage()
  34453. {
  34454. const ComponentDeletionWatcher cdw (this);
  34455. buttonStateChanged();
  34456. if (cdw.hasBeenDeleted())
  34457. return;
  34458. for (int i = buttonListeners.size(); --i >= 0;)
  34459. {
  34460. ButtonListener* const bl = (ButtonListener*) buttonListeners[i];
  34461. if (bl != 0)
  34462. {
  34463. bl->buttonStateChanged (this);
  34464. if (cdw.hasBeenDeleted())
  34465. return;
  34466. }
  34467. }
  34468. }
  34469. void Button::paint (Graphics& g)
  34470. {
  34471. if (needsToRelease && isEnabled())
  34472. {
  34473. needsToRelease = false;
  34474. needsRepainting = true;
  34475. }
  34476. paintButton (g, isOver(), isDown());
  34477. }
  34478. void Button::mouseEnter (const MouseEvent& e)
  34479. {
  34480. updateState (&e);
  34481. }
  34482. void Button::mouseExit (const MouseEvent& e)
  34483. {
  34484. updateState (&e);
  34485. }
  34486. void Button::mouseDown (const MouseEvent& e)
  34487. {
  34488. updateState (&e);
  34489. if (isDown())
  34490. {
  34491. if (autoRepeatDelay >= 0)
  34492. getRepeatTimer().startTimer (autoRepeatDelay);
  34493. if (triggerOnMouseDown)
  34494. internalClickCallback (e.mods);
  34495. }
  34496. }
  34497. void Button::mouseUp (const MouseEvent& e)
  34498. {
  34499. const bool wasDown = isDown();
  34500. updateState (&e);
  34501. if (wasDown && isOver() && ! triggerOnMouseDown)
  34502. internalClickCallback (e.mods);
  34503. }
  34504. void Button::mouseDrag (const MouseEvent& e)
  34505. {
  34506. const ButtonState oldState = buttonState;
  34507. updateState (&e);
  34508. if (autoRepeatDelay >= 0 && buttonState != oldState && isDown())
  34509. getRepeatTimer().startTimer (autoRepeatSpeed);
  34510. }
  34511. void Button::focusGained (FocusChangeType)
  34512. {
  34513. updateState (0);
  34514. repaint();
  34515. }
  34516. void Button::focusLost (FocusChangeType)
  34517. {
  34518. updateState (0);
  34519. repaint();
  34520. }
  34521. void Button::setVisible (bool shouldBeVisible)
  34522. {
  34523. if (shouldBeVisible != isVisible())
  34524. {
  34525. Component::setVisible (shouldBeVisible);
  34526. if (! shouldBeVisible)
  34527. needsToRelease = false;
  34528. updateState (0);
  34529. }
  34530. else
  34531. {
  34532. Component::setVisible (shouldBeVisible);
  34533. }
  34534. }
  34535. void Button::parentHierarchyChanged()
  34536. {
  34537. Component* const newKeySource = (shortcuts.size() == 0) ? 0 : getTopLevelComponent();
  34538. if (newKeySource != keySource)
  34539. {
  34540. if (keySource->isValidComponent())
  34541. keySource->removeKeyListener (this);
  34542. keySource = newKeySource;
  34543. if (keySource->isValidComponent())
  34544. keySource->addKeyListener (this);
  34545. }
  34546. }
  34547. void Button::setCommandToTrigger (ApplicationCommandManager* const commandManagerToUse_,
  34548. const int commandID_,
  34549. const bool generateTooltip_)
  34550. {
  34551. commandID = commandID_;
  34552. generateTooltip = generateTooltip_;
  34553. if (commandManagerToUse != commandManagerToUse_)
  34554. {
  34555. if (commandManagerToUse != 0)
  34556. commandManagerToUse->removeListener (this);
  34557. commandManagerToUse = commandManagerToUse_;
  34558. if (commandManagerToUse != 0)
  34559. commandManagerToUse->addListener (this);
  34560. // if you've got clickTogglesState turned on, you shouldn't also connect the button
  34561. // up to be a command invoker. Instead, your command handler must flip the state of whatever
  34562. // it is that this button represents, and the button will update its state to reflect this
  34563. // in the applicationCommandListChanged() method.
  34564. jassert (commandManagerToUse == 0 || ! clickTogglesState);
  34565. }
  34566. if (commandManagerToUse != 0)
  34567. applicationCommandListChanged();
  34568. else
  34569. setEnabled (true);
  34570. }
  34571. void Button::applicationCommandInvoked (const ApplicationCommandTarget::InvocationInfo& info)
  34572. {
  34573. if (info.commandID == commandID
  34574. && (info.commandFlags & ApplicationCommandInfo::dontTriggerVisualFeedback) == 0)
  34575. {
  34576. flashButtonState();
  34577. }
  34578. }
  34579. void Button::applicationCommandListChanged()
  34580. {
  34581. if (commandManagerToUse != 0)
  34582. {
  34583. ApplicationCommandInfo info (0);
  34584. ApplicationCommandTarget* const target = commandManagerToUse->getTargetForCommand (commandID, info);
  34585. setEnabled (target != 0 && (info.flags & ApplicationCommandInfo::isDisabled) == 0);
  34586. if (target != 0)
  34587. setToggleState ((info.flags & ApplicationCommandInfo::isTicked) != 0, false);
  34588. }
  34589. }
  34590. void Button::addShortcut (const KeyPress& key)
  34591. {
  34592. if (key.isValid())
  34593. {
  34594. jassert (! isRegisteredForShortcut (key)); // already registered!
  34595. shortcuts.add (key);
  34596. parentHierarchyChanged();
  34597. }
  34598. }
  34599. void Button::clearShortcuts()
  34600. {
  34601. shortcuts.clear();
  34602. parentHierarchyChanged();
  34603. }
  34604. bool Button::isShortcutPressed() const
  34605. {
  34606. if (! isCurrentlyBlockedByAnotherModalComponent())
  34607. {
  34608. for (int i = shortcuts.size(); --i >= 0;)
  34609. if (shortcuts.getReference(i).isCurrentlyDown())
  34610. return true;
  34611. }
  34612. return false;
  34613. }
  34614. bool Button::isRegisteredForShortcut (const KeyPress& key) const
  34615. {
  34616. for (int i = shortcuts.size(); --i >= 0;)
  34617. if (key == shortcuts.getReference(i))
  34618. return true;
  34619. return false;
  34620. }
  34621. bool Button::keyStateChanged (const bool, Component*)
  34622. {
  34623. if (! isEnabled())
  34624. return false;
  34625. const bool wasDown = isKeyDown;
  34626. isKeyDown = isShortcutPressed();
  34627. if (autoRepeatDelay >= 0 && (isKeyDown && ! wasDown))
  34628. getRepeatTimer().startTimer (autoRepeatDelay);
  34629. updateState (0);
  34630. if (isEnabled() && wasDown && ! isKeyDown)
  34631. {
  34632. internalClickCallback (ModifierKeys::getCurrentModifiers());
  34633. // (return immediately - this button may now have been deleted)
  34634. return true;
  34635. }
  34636. return wasDown || isKeyDown;
  34637. }
  34638. bool Button::keyPressed (const KeyPress&, Component*)
  34639. {
  34640. // returning true will avoid forwarding events for keys that we're using as shortcuts
  34641. return isShortcutPressed();
  34642. }
  34643. bool Button::keyPressed (const KeyPress& key)
  34644. {
  34645. if (isEnabled() && key.isKeyCode (KeyPress::returnKey))
  34646. {
  34647. triggerClick();
  34648. return true;
  34649. }
  34650. return false;
  34651. }
  34652. void Button::setRepeatSpeed (const int initialDelayMillisecs,
  34653. const int repeatMillisecs,
  34654. const int minimumDelayInMillisecs) throw()
  34655. {
  34656. autoRepeatDelay = initialDelayMillisecs;
  34657. autoRepeatSpeed = repeatMillisecs;
  34658. autoRepeatMinimumDelay = jmin (autoRepeatSpeed, minimumDelayInMillisecs);
  34659. }
  34660. void Button::repeatTimerCallback()
  34661. {
  34662. if (needsRepainting)
  34663. {
  34664. getRepeatTimer().stopTimer();
  34665. updateState (0);
  34666. needsRepainting = false;
  34667. }
  34668. else if (autoRepeatSpeed > 0 && (isKeyDown || (updateState (0) == buttonDown)))
  34669. {
  34670. int repeatSpeed = autoRepeatSpeed;
  34671. if (autoRepeatMinimumDelay >= 0)
  34672. {
  34673. double timeHeldDown = jmin (1.0, getMillisecondsSinceButtonDown() / 4000.0);
  34674. timeHeldDown *= timeHeldDown;
  34675. repeatSpeed = repeatSpeed + (int) (timeHeldDown * (autoRepeatMinimumDelay - repeatSpeed));
  34676. }
  34677. repeatSpeed = jmax (1, repeatSpeed);
  34678. getRepeatTimer().startTimer (repeatSpeed);
  34679. const uint32 now = Time::getApproximateMillisecondCounter();
  34680. const int numTimesToCallback = (now > lastTimeCallbackTime) ? jmax (1, (int) (now - lastTimeCallbackTime) / repeatSpeed) : 1;
  34681. lastTimeCallbackTime = now;
  34682. const ComponentDeletionWatcher cdw (this);
  34683. for (int i = numTimesToCallback; --i >= 0;)
  34684. {
  34685. internalClickCallback (ModifierKeys::getCurrentModifiers());
  34686. if (cdw.hasBeenDeleted() || ! isDown())
  34687. return;
  34688. }
  34689. }
  34690. else if (! needsToRelease)
  34691. {
  34692. getRepeatTimer().stopTimer();
  34693. }
  34694. }
  34695. Button::RepeatTimer& Button::getRepeatTimer()
  34696. {
  34697. if (repeatTimer == 0)
  34698. repeatTimer = new RepeatTimer (*this);
  34699. return *repeatTimer;
  34700. }
  34701. END_JUCE_NAMESPACE
  34702. /*** End of inlined file: juce_Button.cpp ***/
  34703. /*** Start of inlined file: juce_DrawableButton.cpp ***/
  34704. BEGIN_JUCE_NAMESPACE
  34705. DrawableButton::DrawableButton (const String& name,
  34706. const DrawableButton::ButtonStyle buttonStyle)
  34707. : Button (name),
  34708. style (buttonStyle),
  34709. edgeIndent (3)
  34710. {
  34711. if (buttonStyle == ImageOnButtonBackground)
  34712. {
  34713. backgroundOff = Colour (0xffbbbbff);
  34714. backgroundOn = Colour (0xff3333ff);
  34715. }
  34716. else
  34717. {
  34718. backgroundOff = Colours::transparentBlack;
  34719. backgroundOn = Colour (0xaabbbbff);
  34720. }
  34721. }
  34722. DrawableButton::~DrawableButton()
  34723. {
  34724. deleteImages();
  34725. }
  34726. void DrawableButton::deleteImages()
  34727. {
  34728. }
  34729. void DrawableButton::setImages (const Drawable* normal,
  34730. const Drawable* over,
  34731. const Drawable* down,
  34732. const Drawable* disabled,
  34733. const Drawable* normalOn,
  34734. const Drawable* overOn,
  34735. const Drawable* downOn,
  34736. const Drawable* disabledOn)
  34737. {
  34738. deleteImages();
  34739. jassert (normal != 0); // you really need to give it at least a normal image..
  34740. if (normal != 0)
  34741. normalImage = normal->createCopy();
  34742. if (over != 0)
  34743. overImage = over->createCopy();
  34744. if (down != 0)
  34745. downImage = down->createCopy();
  34746. if (disabled != 0)
  34747. disabledImage = disabled->createCopy();
  34748. if (normalOn != 0)
  34749. normalImageOn = normalOn->createCopy();
  34750. if (overOn != 0)
  34751. overImageOn = overOn->createCopy();
  34752. if (downOn != 0)
  34753. downImageOn = downOn->createCopy();
  34754. if (disabledOn != 0)
  34755. disabledImageOn = disabledOn->createCopy();
  34756. repaint();
  34757. }
  34758. void DrawableButton::setButtonStyle (const DrawableButton::ButtonStyle newStyle)
  34759. {
  34760. if (style != newStyle)
  34761. {
  34762. style = newStyle;
  34763. repaint();
  34764. }
  34765. }
  34766. void DrawableButton::setBackgroundColours (const Colour& toggledOffColour,
  34767. const Colour& toggledOnColour)
  34768. {
  34769. if (backgroundOff != toggledOffColour
  34770. || backgroundOn != toggledOnColour)
  34771. {
  34772. backgroundOff = toggledOffColour;
  34773. backgroundOn = toggledOnColour;
  34774. repaint();
  34775. }
  34776. }
  34777. const Colour& DrawableButton::getBackgroundColour() const throw()
  34778. {
  34779. return getToggleState() ? backgroundOn
  34780. : backgroundOff;
  34781. }
  34782. void DrawableButton::setEdgeIndent (const int numPixelsIndent)
  34783. {
  34784. edgeIndent = numPixelsIndent;
  34785. repaint();
  34786. }
  34787. void DrawableButton::paintButton (Graphics& g,
  34788. bool isMouseOverButton,
  34789. bool isButtonDown)
  34790. {
  34791. Rectangle<int> imageSpace;
  34792. if (style == ImageOnButtonBackground)
  34793. {
  34794. const int insetX = getWidth() / 4;
  34795. const int insetY = getHeight() / 4;
  34796. imageSpace.setBounds (insetX, insetY, getWidth() - insetX * 2, getHeight() - insetY * 2);
  34797. getLookAndFeel().drawButtonBackground (g, *this,
  34798. getBackgroundColour(),
  34799. isMouseOverButton,
  34800. isButtonDown);
  34801. }
  34802. else
  34803. {
  34804. g.fillAll (getBackgroundColour());
  34805. const int textH = (style == ImageAboveTextLabel)
  34806. ? jmin (16, proportionOfHeight (0.25f))
  34807. : 0;
  34808. const int indentX = jmin (edgeIndent, proportionOfWidth (0.3f));
  34809. const int indentY = jmin (edgeIndent, proportionOfHeight (0.3f));
  34810. imageSpace.setBounds (indentX, indentY,
  34811. getWidth() - indentX * 2,
  34812. getHeight() - indentY * 2 - textH);
  34813. if (textH > 0)
  34814. {
  34815. g.setFont ((float) textH);
  34816. g.setColour (Colours::black.withAlpha (isEnabled() ? 1.0f : 0.4f));
  34817. g.drawFittedText (getButtonText(),
  34818. 2, getHeight() - textH - 1,
  34819. getWidth() - 4, textH,
  34820. Justification::centred, 1);
  34821. }
  34822. }
  34823. g.setImageResamplingQuality (Graphics::mediumResamplingQuality);
  34824. g.setOpacity (1.0f);
  34825. const Drawable* imageToDraw = 0;
  34826. if (isEnabled())
  34827. {
  34828. imageToDraw = getCurrentImage();
  34829. }
  34830. else
  34831. {
  34832. imageToDraw = getToggleState() ? disabledImageOn
  34833. : disabledImage;
  34834. if (imageToDraw == 0)
  34835. {
  34836. g.setOpacity (0.4f);
  34837. imageToDraw = getNormalImage();
  34838. }
  34839. }
  34840. if (imageToDraw != 0)
  34841. {
  34842. if (style == ImageRaw)
  34843. {
  34844. imageToDraw->draw (g, 1.0f);
  34845. }
  34846. else
  34847. {
  34848. imageToDraw->drawWithin (g,
  34849. imageSpace.getX(),
  34850. imageSpace.getY(),
  34851. imageSpace.getWidth(),
  34852. imageSpace.getHeight(),
  34853. RectanglePlacement::centred,
  34854. 1.0f);
  34855. }
  34856. }
  34857. }
  34858. const Drawable* DrawableButton::getCurrentImage() const throw()
  34859. {
  34860. if (isDown())
  34861. return getDownImage();
  34862. if (isOver())
  34863. return getOverImage();
  34864. return getNormalImage();
  34865. }
  34866. const Drawable* DrawableButton::getNormalImage() const throw()
  34867. {
  34868. return (getToggleState() && normalImageOn != 0) ? normalImageOn
  34869. : normalImage;
  34870. }
  34871. const Drawable* DrawableButton::getOverImage() const throw()
  34872. {
  34873. const Drawable* d = normalImage;
  34874. if (getToggleState())
  34875. {
  34876. if (overImageOn != 0)
  34877. d = overImageOn;
  34878. else if (normalImageOn != 0)
  34879. d = normalImageOn;
  34880. else if (overImage != 0)
  34881. d = overImage;
  34882. }
  34883. else
  34884. {
  34885. if (overImage != 0)
  34886. d = overImage;
  34887. }
  34888. return d;
  34889. }
  34890. const Drawable* DrawableButton::getDownImage() const throw()
  34891. {
  34892. const Drawable* d = normalImage;
  34893. if (getToggleState())
  34894. {
  34895. if (downImageOn != 0)
  34896. d = downImageOn;
  34897. else if (overImageOn != 0)
  34898. d = overImageOn;
  34899. else if (normalImageOn != 0)
  34900. d = normalImageOn;
  34901. else if (downImage != 0)
  34902. d = downImage;
  34903. else
  34904. d = getOverImage();
  34905. }
  34906. else
  34907. {
  34908. if (downImage != 0)
  34909. d = downImage;
  34910. else
  34911. d = getOverImage();
  34912. }
  34913. return d;
  34914. }
  34915. END_JUCE_NAMESPACE
  34916. /*** End of inlined file: juce_DrawableButton.cpp ***/
  34917. /*** Start of inlined file: juce_HyperlinkButton.cpp ***/
  34918. BEGIN_JUCE_NAMESPACE
  34919. HyperlinkButton::HyperlinkButton (const String& linkText,
  34920. const URL& linkURL)
  34921. : Button (linkText),
  34922. url (linkURL),
  34923. font (14.0f, Font::underlined),
  34924. resizeFont (true),
  34925. justification (Justification::centred)
  34926. {
  34927. setMouseCursor (MouseCursor::PointingHandCursor);
  34928. setTooltip (linkURL.toString (false));
  34929. }
  34930. HyperlinkButton::~HyperlinkButton()
  34931. {
  34932. }
  34933. void HyperlinkButton::setFont (const Font& newFont,
  34934. const bool resizeToMatchComponentHeight,
  34935. const Justification& justificationType)
  34936. {
  34937. font = newFont;
  34938. resizeFont = resizeToMatchComponentHeight;
  34939. justification = justificationType;
  34940. repaint();
  34941. }
  34942. void HyperlinkButton::setURL (const URL& newURL) throw()
  34943. {
  34944. url = newURL;
  34945. setTooltip (newURL.toString (false));
  34946. }
  34947. const Font HyperlinkButton::getFontToUse() const
  34948. {
  34949. Font f (font);
  34950. if (resizeFont)
  34951. f.setHeight (getHeight() * 0.7f);
  34952. return f;
  34953. }
  34954. void HyperlinkButton::changeWidthToFitText()
  34955. {
  34956. setSize (getFontToUse().getStringWidth (getName()) + 6, getHeight());
  34957. }
  34958. void HyperlinkButton::colourChanged()
  34959. {
  34960. repaint();
  34961. }
  34962. void HyperlinkButton::clicked()
  34963. {
  34964. if (url.isWellFormed())
  34965. url.launchInDefaultBrowser();
  34966. }
  34967. void HyperlinkButton::paintButton (Graphics& g,
  34968. bool isMouseOverButton,
  34969. bool isButtonDown)
  34970. {
  34971. const Colour textColour (findColour (textColourId));
  34972. if (isEnabled())
  34973. g.setColour ((isMouseOverButton) ? textColour.darker ((isButtonDown) ? 1.3f : 0.4f)
  34974. : textColour);
  34975. else
  34976. g.setColour (textColour.withMultipliedAlpha (0.4f));
  34977. g.setFont (getFontToUse());
  34978. g.drawText (getButtonText(),
  34979. 2, 0, getWidth() - 2, getHeight(),
  34980. justification.getOnlyHorizontalFlags() | Justification::verticallyCentred,
  34981. true);
  34982. }
  34983. END_JUCE_NAMESPACE
  34984. /*** End of inlined file: juce_HyperlinkButton.cpp ***/
  34985. /*** Start of inlined file: juce_ImageButton.cpp ***/
  34986. BEGIN_JUCE_NAMESPACE
  34987. ImageButton::ImageButton (const String& text_)
  34988. : Button (text_),
  34989. scaleImageToFit (true),
  34990. preserveProportions (true),
  34991. alphaThreshold (0),
  34992. imageX (0),
  34993. imageY (0),
  34994. imageW (0),
  34995. imageH (0),
  34996. normalImage (0),
  34997. overImage (0),
  34998. downImage (0)
  34999. {
  35000. }
  35001. ImageButton::~ImageButton()
  35002. {
  35003. deleteImages();
  35004. }
  35005. void ImageButton::deleteImages()
  35006. {
  35007. ImageCache::releaseOrDelete (normalImage);
  35008. ImageCache::releaseOrDelete (overImage);
  35009. ImageCache::releaseOrDelete (downImage);
  35010. }
  35011. void ImageButton::setImages (const bool resizeButtonNowToFitThisImage,
  35012. const bool rescaleImagesWhenButtonSizeChanges,
  35013. const bool preserveImageProportions,
  35014. Image* const normalImage_,
  35015. const float imageOpacityWhenNormal,
  35016. const Colour& overlayColourWhenNormal,
  35017. Image* const overImage_,
  35018. const float imageOpacityWhenOver,
  35019. const Colour& overlayColourWhenOver,
  35020. Image* const downImage_,
  35021. const float imageOpacityWhenDown,
  35022. const Colour& overlayColourWhenDown,
  35023. const float hitTestAlphaThreshold)
  35024. {
  35025. deleteImages();
  35026. normalImage = normalImage_;
  35027. overImage = overImage_;
  35028. downImage = downImage_;
  35029. if (resizeButtonNowToFitThisImage && normalImage != 0)
  35030. {
  35031. imageW = normalImage->getWidth();
  35032. imageH = normalImage->getHeight();
  35033. setSize (imageW, imageH);
  35034. }
  35035. scaleImageToFit = rescaleImagesWhenButtonSizeChanges;
  35036. preserveProportions = preserveImageProportions;
  35037. normalOpacity = imageOpacityWhenNormal;
  35038. normalOverlay = overlayColourWhenNormal;
  35039. overOpacity = imageOpacityWhenOver;
  35040. overOverlay = overlayColourWhenOver;
  35041. downOpacity = imageOpacityWhenDown;
  35042. downOverlay = overlayColourWhenDown;
  35043. alphaThreshold = (unsigned char) jlimit (0, 0xff, roundToInt (255.0f * hitTestAlphaThreshold));
  35044. repaint();
  35045. }
  35046. Image* ImageButton::getCurrentImage() const
  35047. {
  35048. if (isDown() || getToggleState())
  35049. return getDownImage();
  35050. if (isOver())
  35051. return getOverImage();
  35052. return getNormalImage();
  35053. }
  35054. Image* ImageButton::getNormalImage() const throw()
  35055. {
  35056. return normalImage;
  35057. }
  35058. Image* ImageButton::getOverImage() const throw()
  35059. {
  35060. return (overImage != 0) ? overImage
  35061. : normalImage;
  35062. }
  35063. Image* ImageButton::getDownImage() const throw()
  35064. {
  35065. return (downImage != 0) ? downImage
  35066. : getOverImage();
  35067. }
  35068. void ImageButton::paintButton (Graphics& g,
  35069. bool isMouseOverButton,
  35070. bool isButtonDown)
  35071. {
  35072. if (! isEnabled())
  35073. {
  35074. isMouseOverButton = false;
  35075. isButtonDown = false;
  35076. }
  35077. Image* const im = getCurrentImage();
  35078. if (im != 0)
  35079. {
  35080. const int iw = im->getWidth();
  35081. const int ih = im->getHeight();
  35082. imageW = getWidth();
  35083. imageH = getHeight();
  35084. imageX = (imageW - iw) >> 1;
  35085. imageY = (imageH - ih) >> 1;
  35086. if (scaleImageToFit)
  35087. {
  35088. if (preserveProportions)
  35089. {
  35090. int newW, newH;
  35091. const float imRatio = ih / (float)iw;
  35092. const float destRatio = imageH / (float)imageW;
  35093. if (imRatio > destRatio)
  35094. {
  35095. newW = roundToInt (imageH / imRatio);
  35096. newH = imageH;
  35097. }
  35098. else
  35099. {
  35100. newW = imageW;
  35101. newH = roundToInt (imageW * imRatio);
  35102. }
  35103. imageX = (imageW - newW) / 2;
  35104. imageY = (imageH - newH) / 2;
  35105. imageW = newW;
  35106. imageH = newH;
  35107. }
  35108. else
  35109. {
  35110. imageX = 0;
  35111. imageY = 0;
  35112. }
  35113. }
  35114. if (! scaleImageToFit)
  35115. {
  35116. imageW = iw;
  35117. imageH = ih;
  35118. }
  35119. getLookAndFeel().drawImageButton (g, im, imageX, imageY, imageW, imageH,
  35120. isButtonDown ? downOverlay
  35121. : (isMouseOverButton ? overOverlay
  35122. : normalOverlay),
  35123. isButtonDown ? downOpacity
  35124. : (isMouseOverButton ? overOpacity
  35125. : normalOpacity),
  35126. *this);
  35127. }
  35128. }
  35129. bool ImageButton::hitTest (int x, int y)
  35130. {
  35131. if (alphaThreshold == 0)
  35132. return true;
  35133. Image* const im = getCurrentImage();
  35134. return im == 0
  35135. || (imageW > 0 && imageH > 0
  35136. && alphaThreshold < im->getPixelAt (((x - imageX) * im->getWidth()) / imageW,
  35137. ((y - imageY) * im->getHeight()) / imageH).getAlpha());
  35138. }
  35139. END_JUCE_NAMESPACE
  35140. /*** End of inlined file: juce_ImageButton.cpp ***/
  35141. /*** Start of inlined file: juce_ShapeButton.cpp ***/
  35142. BEGIN_JUCE_NAMESPACE
  35143. ShapeButton::ShapeButton (const String& text_,
  35144. const Colour& normalColour_,
  35145. const Colour& overColour_,
  35146. const Colour& downColour_)
  35147. : Button (text_),
  35148. normalColour (normalColour_),
  35149. overColour (overColour_),
  35150. downColour (downColour_),
  35151. maintainShapeProportions (false),
  35152. outlineWidth (0.0f)
  35153. {
  35154. }
  35155. ShapeButton::~ShapeButton()
  35156. {
  35157. }
  35158. void ShapeButton::setColours (const Colour& newNormalColour,
  35159. const Colour& newOverColour,
  35160. const Colour& newDownColour)
  35161. {
  35162. normalColour = newNormalColour;
  35163. overColour = newOverColour;
  35164. downColour = newDownColour;
  35165. }
  35166. void ShapeButton::setOutline (const Colour& newOutlineColour,
  35167. const float newOutlineWidth)
  35168. {
  35169. outlineColour = newOutlineColour;
  35170. outlineWidth = newOutlineWidth;
  35171. }
  35172. void ShapeButton::setShape (const Path& newShape,
  35173. const bool resizeNowToFitThisShape,
  35174. const bool maintainShapeProportions_,
  35175. const bool hasShadow)
  35176. {
  35177. shape = newShape;
  35178. maintainShapeProportions = maintainShapeProportions_;
  35179. shadow.setShadowProperties (3.0f, 0.5f, 0, 0);
  35180. setComponentEffect ((hasShadow) ? &shadow : 0);
  35181. if (resizeNowToFitThisShape)
  35182. {
  35183. Rectangle<float> bounds (shape.getBounds());
  35184. if (hasShadow)
  35185. bounds.expand (4.0f, 4.0f);
  35186. shape.applyTransform (AffineTransform::translation (-bounds.getX(), -bounds.getY()));
  35187. setSize (1 + (int) (bounds.getWidth() + outlineWidth),
  35188. 1 + (int) (bounds.getHeight() + outlineWidth));
  35189. }
  35190. }
  35191. void ShapeButton::paintButton (Graphics& g, bool isMouseOverButton, bool isButtonDown)
  35192. {
  35193. if (! isEnabled())
  35194. {
  35195. isMouseOverButton = false;
  35196. isButtonDown = false;
  35197. }
  35198. g.setColour ((isButtonDown) ? downColour
  35199. : (isMouseOverButton) ? overColour
  35200. : normalColour);
  35201. int w = getWidth();
  35202. int h = getHeight();
  35203. if (getComponentEffect() != 0)
  35204. {
  35205. w -= 4;
  35206. h -= 4;
  35207. }
  35208. const float offset = (outlineWidth * 0.5f) + (isButtonDown ? 1.5f : 0.0f);
  35209. const AffineTransform trans (shape.getTransformToScaleToFit (offset, offset,
  35210. w - offset - outlineWidth,
  35211. h - offset - outlineWidth,
  35212. maintainShapeProportions));
  35213. g.fillPath (shape, trans);
  35214. if (outlineWidth > 0.0f)
  35215. {
  35216. g.setColour (outlineColour);
  35217. g.strokePath (shape, PathStrokeType (outlineWidth), trans);
  35218. }
  35219. }
  35220. END_JUCE_NAMESPACE
  35221. /*** End of inlined file: juce_ShapeButton.cpp ***/
  35222. /*** Start of inlined file: juce_TextButton.cpp ***/
  35223. BEGIN_JUCE_NAMESPACE
  35224. TextButton::TextButton (const String& name,
  35225. const String& toolTip)
  35226. : Button (name)
  35227. {
  35228. setTooltip (toolTip);
  35229. }
  35230. TextButton::~TextButton()
  35231. {
  35232. }
  35233. void TextButton::paintButton (Graphics& g,
  35234. bool isMouseOverButton,
  35235. bool isButtonDown)
  35236. {
  35237. getLookAndFeel().drawButtonBackground (g, *this,
  35238. findColour (getToggleState() ? buttonOnColourId
  35239. : buttonColourId),
  35240. isMouseOverButton,
  35241. isButtonDown);
  35242. getLookAndFeel().drawButtonText (g, *this,
  35243. isMouseOverButton,
  35244. isButtonDown);
  35245. }
  35246. void TextButton::colourChanged()
  35247. {
  35248. repaint();
  35249. }
  35250. const Font TextButton::getFont()
  35251. {
  35252. return Font (jmin (15.0f, getHeight() * 0.6f));
  35253. }
  35254. void TextButton::changeWidthToFitText (const int newHeight)
  35255. {
  35256. if (newHeight >= 0)
  35257. setSize (jmax (1, getWidth()), newHeight);
  35258. setSize (getFont().getStringWidth (getButtonText()) + getHeight(),
  35259. getHeight());
  35260. }
  35261. END_JUCE_NAMESPACE
  35262. /*** End of inlined file: juce_TextButton.cpp ***/
  35263. /*** Start of inlined file: juce_ToggleButton.cpp ***/
  35264. BEGIN_JUCE_NAMESPACE
  35265. ToggleButton::ToggleButton (const String& buttonText)
  35266. : Button (buttonText)
  35267. {
  35268. setClickingTogglesState (true);
  35269. }
  35270. ToggleButton::~ToggleButton()
  35271. {
  35272. }
  35273. void ToggleButton::paintButton (Graphics& g,
  35274. bool isMouseOverButton,
  35275. bool isButtonDown)
  35276. {
  35277. getLookAndFeel().drawToggleButton (g, *this,
  35278. isMouseOverButton,
  35279. isButtonDown);
  35280. }
  35281. void ToggleButton::changeWidthToFitText()
  35282. {
  35283. getLookAndFeel().changeToggleButtonWidthToFitText (*this);
  35284. }
  35285. void ToggleButton::colourChanged()
  35286. {
  35287. repaint();
  35288. }
  35289. END_JUCE_NAMESPACE
  35290. /*** End of inlined file: juce_ToggleButton.cpp ***/
  35291. /*** Start of inlined file: juce_ToolbarButton.cpp ***/
  35292. BEGIN_JUCE_NAMESPACE
  35293. ToolbarButton::ToolbarButton (const int itemId_,
  35294. const String& buttonText,
  35295. Drawable* const normalImage_,
  35296. Drawable* const toggledOnImage_)
  35297. : ToolbarItemComponent (itemId_, buttonText, true),
  35298. normalImage (normalImage_),
  35299. toggledOnImage (toggledOnImage_)
  35300. {
  35301. }
  35302. ToolbarButton::~ToolbarButton()
  35303. {
  35304. }
  35305. bool ToolbarButton::getToolbarItemSizes (int toolbarDepth,
  35306. bool /*isToolbarVertical*/,
  35307. int& preferredSize,
  35308. int& minSize, int& maxSize)
  35309. {
  35310. preferredSize = minSize = maxSize = toolbarDepth;
  35311. return true;
  35312. }
  35313. void ToolbarButton::paintButtonArea (Graphics& g,
  35314. int width, int height,
  35315. bool /*isMouseOver*/,
  35316. bool /*isMouseDown*/)
  35317. {
  35318. Drawable* d = normalImage;
  35319. if (getToggleState() && toggledOnImage != 0)
  35320. d = toggledOnImage;
  35321. if (! isEnabled())
  35322. {
  35323. Image im (Image::ARGB, width, height, true);
  35324. Graphics g2 (im);
  35325. d->drawWithin (g2, 0, 0, width, height, RectanglePlacement::centred, 1.0f);
  35326. im.desaturate();
  35327. g.drawImageAt (&im, 0, 0);
  35328. }
  35329. else
  35330. {
  35331. d->drawWithin (g, 0, 0, width, height, RectanglePlacement::centred, 1.0f);
  35332. }
  35333. }
  35334. void ToolbarButton::contentAreaChanged (const Rectangle<int>&)
  35335. {
  35336. }
  35337. END_JUCE_NAMESPACE
  35338. /*** End of inlined file: juce_ToolbarButton.cpp ***/
  35339. /*** Start of inlined file: juce_CodeDocument.cpp ***/
  35340. BEGIN_JUCE_NAMESPACE
  35341. class CodeDocumentLine
  35342. {
  35343. public:
  35344. CodeDocumentLine (const tchar* const line_,
  35345. const int lineLength_,
  35346. const int numNewLineChars,
  35347. const int lineStartInFile_)
  35348. : line (line_, lineLength_),
  35349. lineStartInFile (lineStartInFile_),
  35350. lineLength (lineLength_),
  35351. lineLengthWithoutNewLines (lineLength_ - numNewLineChars)
  35352. {
  35353. }
  35354. ~CodeDocumentLine()
  35355. {
  35356. }
  35357. static void createLines (Array <CodeDocumentLine*>& newLines, const String& text)
  35358. {
  35359. const tchar* const t = (const tchar*) text;
  35360. int pos = 0;
  35361. while (t [pos] != 0)
  35362. {
  35363. const int startOfLine = pos;
  35364. int numNewLineChars = 0;
  35365. while (t[pos] != 0)
  35366. {
  35367. if (t[pos] == T('\r'))
  35368. {
  35369. ++numNewLineChars;
  35370. ++pos;
  35371. if (t[pos] == T('\n'))
  35372. {
  35373. ++numNewLineChars;
  35374. ++pos;
  35375. }
  35376. break;
  35377. }
  35378. if (t[pos] == T('\n'))
  35379. {
  35380. ++numNewLineChars;
  35381. ++pos;
  35382. break;
  35383. }
  35384. ++pos;
  35385. }
  35386. newLines.add (new CodeDocumentLine (t + startOfLine, pos - startOfLine,
  35387. numNewLineChars, startOfLine));
  35388. }
  35389. jassert (pos == text.length());
  35390. }
  35391. bool endsWithLineBreak() const throw()
  35392. {
  35393. return lineLengthWithoutNewLines != lineLength;
  35394. }
  35395. void updateLength() throw()
  35396. {
  35397. lineLengthWithoutNewLines = lineLength = line.length();
  35398. while (lineLengthWithoutNewLines > 0
  35399. && (line [lineLengthWithoutNewLines - 1] == '\n'
  35400. || line [lineLengthWithoutNewLines - 1] == '\r'))
  35401. {
  35402. --lineLengthWithoutNewLines;
  35403. }
  35404. }
  35405. String line;
  35406. int lineStartInFile, lineLength, lineLengthWithoutNewLines;
  35407. };
  35408. CodeDocument::Iterator::Iterator (CodeDocument* const document_)
  35409. : document (document_),
  35410. currentLine (document_->lines[0]),
  35411. line (0),
  35412. position (0)
  35413. {
  35414. }
  35415. CodeDocument::Iterator::Iterator (const CodeDocument::Iterator& other)
  35416. : document (other.document),
  35417. currentLine (other.currentLine),
  35418. line (other.line),
  35419. position (other.position)
  35420. {
  35421. }
  35422. const CodeDocument::Iterator& CodeDocument::Iterator::operator= (const CodeDocument::Iterator& other) throw()
  35423. {
  35424. document = other.document;
  35425. currentLine = other.currentLine;
  35426. line = other.line;
  35427. position = other.position;
  35428. return *this;
  35429. }
  35430. CodeDocument::Iterator::~Iterator() throw()
  35431. {
  35432. }
  35433. juce_wchar CodeDocument::Iterator::nextChar()
  35434. {
  35435. if (currentLine == 0)
  35436. return 0;
  35437. jassert (currentLine == document->lines.getUnchecked (line));
  35438. const juce_wchar result = currentLine->line [position - currentLine->lineStartInFile];
  35439. skip();
  35440. return result;
  35441. }
  35442. void CodeDocument::Iterator::skip()
  35443. {
  35444. if (currentLine != 0)
  35445. {
  35446. jassert (currentLine == document->lines.getUnchecked (line));
  35447. if (++position >= currentLine->lineStartInFile + currentLine->lineLength)
  35448. {
  35449. ++line;
  35450. currentLine = document->lines [line];
  35451. }
  35452. }
  35453. }
  35454. void CodeDocument::Iterator::skipToEndOfLine()
  35455. {
  35456. if (currentLine != 0)
  35457. {
  35458. jassert (currentLine == document->lines.getUnchecked (line));
  35459. ++line;
  35460. currentLine = document->lines [line];
  35461. if (currentLine != 0)
  35462. position = currentLine->lineStartInFile;
  35463. else
  35464. position = document->getNumCharacters();
  35465. }
  35466. }
  35467. juce_wchar CodeDocument::Iterator::peekNextChar() const
  35468. {
  35469. if (currentLine == 0)
  35470. return 0;
  35471. jassert (currentLine == document->lines.getUnchecked (line));
  35472. return currentLine->line [position - currentLine->lineStartInFile];
  35473. }
  35474. void CodeDocument::Iterator::skipWhitespace()
  35475. {
  35476. while (CharacterFunctions::isWhitespace (peekNextChar()))
  35477. skip();
  35478. }
  35479. bool CodeDocument::Iterator::isEOF() const throw()
  35480. {
  35481. return currentLine == 0;
  35482. }
  35483. CodeDocument::Position::Position() throw()
  35484. : owner (0), characterPos (0), line (0),
  35485. indexInLine (0), positionMaintained (false)
  35486. {
  35487. }
  35488. CodeDocument::Position::Position (const CodeDocument* const ownerDocument,
  35489. const int line_, const int indexInLine_) throw()
  35490. : owner (const_cast <CodeDocument*> (ownerDocument)),
  35491. characterPos (0), line (line_),
  35492. indexInLine (indexInLine_), positionMaintained (false)
  35493. {
  35494. setLineAndIndex (line_, indexInLine_);
  35495. }
  35496. CodeDocument::Position::Position (const CodeDocument* const ownerDocument,
  35497. const int characterPos_) throw()
  35498. : owner (const_cast <CodeDocument*> (ownerDocument)),
  35499. positionMaintained (false)
  35500. {
  35501. setPosition (characterPos_);
  35502. }
  35503. CodeDocument::Position::Position (const Position& other) throw()
  35504. : owner (other.owner), characterPos (other.characterPos), line (other.line),
  35505. indexInLine (other.indexInLine), positionMaintained (false)
  35506. {
  35507. jassert (*this == other);
  35508. }
  35509. CodeDocument::Position::~Position() throw()
  35510. {
  35511. setPositionMaintained (false);
  35512. }
  35513. const CodeDocument::Position& CodeDocument::Position::operator= (const Position& other) throw()
  35514. {
  35515. if (this != &other)
  35516. {
  35517. const bool wasPositionMaintained = positionMaintained;
  35518. if (owner != other.owner)
  35519. setPositionMaintained (false);
  35520. owner = other.owner;
  35521. line = other.line;
  35522. indexInLine = other.indexInLine;
  35523. characterPos = other.characterPos;
  35524. setPositionMaintained (wasPositionMaintained);
  35525. jassert (*this == other);
  35526. }
  35527. return *this;
  35528. }
  35529. bool CodeDocument::Position::operator== (const Position& other) const throw()
  35530. {
  35531. jassert ((characterPos == other.characterPos)
  35532. == (line == other.line && indexInLine == other.indexInLine));
  35533. return characterPos == other.characterPos
  35534. && line == other.line
  35535. && indexInLine == other.indexInLine
  35536. && owner == other.owner;
  35537. }
  35538. bool CodeDocument::Position::operator!= (const Position& other) const throw()
  35539. {
  35540. return ! operator== (other);
  35541. }
  35542. void CodeDocument::Position::setLineAndIndex (const int newLine, const int newIndexInLine) throw()
  35543. {
  35544. jassert (owner != 0);
  35545. if (owner->lines.size() == 0)
  35546. {
  35547. line = 0;
  35548. indexInLine = 0;
  35549. characterPos = 0;
  35550. }
  35551. else
  35552. {
  35553. if (newLine >= owner->lines.size())
  35554. {
  35555. line = owner->lines.size() - 1;
  35556. CodeDocumentLine* const l = owner->lines.getUnchecked (line);
  35557. jassert (l != 0);
  35558. indexInLine = l->lineLengthWithoutNewLines;
  35559. characterPos = l->lineStartInFile + indexInLine;
  35560. }
  35561. else
  35562. {
  35563. line = jmax (0, newLine);
  35564. CodeDocumentLine* const l = owner->lines.getUnchecked (line);
  35565. jassert (l != 0);
  35566. if (l->lineLengthWithoutNewLines > 0)
  35567. indexInLine = jlimit (0, l->lineLengthWithoutNewLines, newIndexInLine);
  35568. else
  35569. indexInLine = 0;
  35570. characterPos = l->lineStartInFile + indexInLine;
  35571. }
  35572. }
  35573. }
  35574. void CodeDocument::Position::setPosition (const int newPosition) throw()
  35575. {
  35576. jassert (owner != 0);
  35577. line = 0;
  35578. indexInLine = 0;
  35579. characterPos = 0;
  35580. if (newPosition > 0)
  35581. {
  35582. int lineStart = 0;
  35583. int lineEnd = owner->lines.size();
  35584. for (;;)
  35585. {
  35586. if (lineEnd - lineStart < 4)
  35587. {
  35588. for (int i = lineStart; i < lineEnd; ++i)
  35589. {
  35590. CodeDocumentLine* const l = owner->lines.getUnchecked (i);
  35591. int index = newPosition - l->lineStartInFile;
  35592. if (index >= 0 && (index < l->lineLength || i == lineEnd - 1))
  35593. {
  35594. line = i;
  35595. indexInLine = jmin (l->lineLengthWithoutNewLines, index);
  35596. characterPos = l->lineStartInFile + indexInLine;
  35597. }
  35598. }
  35599. break;
  35600. }
  35601. else
  35602. {
  35603. const int midIndex = (lineStart + lineEnd + 1) / 2;
  35604. CodeDocumentLine* const mid = owner->lines.getUnchecked (midIndex);
  35605. if (newPosition >= mid->lineStartInFile)
  35606. lineStart = midIndex;
  35607. else
  35608. lineEnd = midIndex;
  35609. }
  35610. }
  35611. }
  35612. }
  35613. void CodeDocument::Position::moveBy (int characterDelta) throw()
  35614. {
  35615. jassert (owner != 0);
  35616. if (characterDelta == 1)
  35617. {
  35618. setPosition (getPosition());
  35619. // If moving right, make sure we don't get stuck between the \r and \n characters..
  35620. CodeDocumentLine* const l = owner->lines.getUnchecked (line);
  35621. if (indexInLine + characterDelta < l->lineLength
  35622. && indexInLine + characterDelta >= l->lineLengthWithoutNewLines + 1)
  35623. ++characterDelta;
  35624. }
  35625. setPosition (characterPos + characterDelta);
  35626. }
  35627. const CodeDocument::Position CodeDocument::Position::movedBy (const int characterDelta) const throw()
  35628. {
  35629. CodeDocument::Position p (*this);
  35630. p.moveBy (characterDelta);
  35631. return p;
  35632. }
  35633. const CodeDocument::Position CodeDocument::Position::movedByLines (const int deltaLines) const throw()
  35634. {
  35635. CodeDocument::Position p (*this);
  35636. p.setLineAndIndex (getLineNumber() + deltaLines, getIndexInLine());
  35637. return p;
  35638. }
  35639. const tchar CodeDocument::Position::getCharacter() const throw()
  35640. {
  35641. const CodeDocumentLine* const l = owner->lines [line];
  35642. return l == 0 ? 0 : l->line [getIndexInLine()];
  35643. }
  35644. const String CodeDocument::Position::getLineText() const throw()
  35645. {
  35646. const CodeDocumentLine* const l = owner->lines [line];
  35647. return l == 0 ? String::empty : l->line;
  35648. }
  35649. void CodeDocument::Position::setPositionMaintained (const bool isMaintained) throw()
  35650. {
  35651. if (isMaintained != positionMaintained)
  35652. {
  35653. positionMaintained = isMaintained;
  35654. if (owner != 0)
  35655. {
  35656. if (isMaintained)
  35657. {
  35658. jassert (! owner->positionsToMaintain.contains (this));
  35659. owner->positionsToMaintain.add (this);
  35660. }
  35661. else
  35662. {
  35663. jassert (owner->positionsToMaintain.contains (this));
  35664. owner->positionsToMaintain.removeValue (this);
  35665. }
  35666. }
  35667. }
  35668. }
  35669. CodeDocument::CodeDocument()
  35670. : undoManager (std::numeric_limits<int>::max(), 10000),
  35671. currentActionIndex (0),
  35672. indexOfSavedState (-1),
  35673. maximumLineLength (-1),
  35674. newLineChars ("\r\n")
  35675. {
  35676. }
  35677. CodeDocument::~CodeDocument()
  35678. {
  35679. }
  35680. const String CodeDocument::getAllContent() const throw()
  35681. {
  35682. return getTextBetween (Position (this, 0),
  35683. Position (this, lines.size(), 0));
  35684. }
  35685. const String CodeDocument::getTextBetween (const Position& start, const Position& end) const throw()
  35686. {
  35687. if (end.getPosition() <= start.getPosition())
  35688. return String::empty;
  35689. const int startLine = start.getLineNumber();
  35690. const int endLine = end.getLineNumber();
  35691. if (startLine == endLine)
  35692. {
  35693. CodeDocumentLine* const line = lines [startLine];
  35694. return (line == 0) ? String::empty : line->line.substring (start.getIndexInLine(), end.getIndexInLine());
  35695. }
  35696. String result;
  35697. result.preallocateStorage (end.getPosition() - start.getPosition() + 4);
  35698. String::Concatenator concatenator (result);
  35699. const int maxLine = jmin (lines.size() - 1, endLine);
  35700. for (int i = jmax (0, startLine); i <= maxLine; ++i)
  35701. {
  35702. const CodeDocumentLine* line = lines.getUnchecked(i);
  35703. int len = line->lineLength;
  35704. if (i == startLine)
  35705. {
  35706. const int index = start.getIndexInLine();
  35707. concatenator.append (line->line.substring (index, len));
  35708. }
  35709. else if (i == endLine)
  35710. {
  35711. len = end.getIndexInLine();
  35712. concatenator.append (line->line.substring (0, len));
  35713. }
  35714. else
  35715. {
  35716. concatenator.append (line->line);
  35717. }
  35718. }
  35719. return result;
  35720. }
  35721. int CodeDocument::getNumCharacters() const throw()
  35722. {
  35723. const CodeDocumentLine* const lastLine = lines.getLast();
  35724. return (lastLine == 0) ? 0 : lastLine->lineStartInFile + lastLine->lineLength;
  35725. }
  35726. const String CodeDocument::getLine (const int lineIndex) const throw()
  35727. {
  35728. const CodeDocumentLine* const line = lines [lineIndex];
  35729. return (line == 0) ? String::empty : line->line;
  35730. }
  35731. int CodeDocument::getMaximumLineLength() throw()
  35732. {
  35733. if (maximumLineLength < 0)
  35734. {
  35735. maximumLineLength = 0;
  35736. for (int i = lines.size(); --i >= 0;)
  35737. maximumLineLength = jmax (maximumLineLength, lines.getUnchecked(i)->lineLength);
  35738. }
  35739. return maximumLineLength;
  35740. }
  35741. void CodeDocument::deleteSection (const Position& startPosition, const Position& endPosition)
  35742. {
  35743. remove (startPosition.getPosition(), endPosition.getPosition(), true);
  35744. }
  35745. void CodeDocument::insertText (const Position& position, const String& text)
  35746. {
  35747. insert (text, position.getPosition(), true);
  35748. }
  35749. void CodeDocument::replaceAllContent (const String& newContent)
  35750. {
  35751. remove (0, getNumCharacters(), true);
  35752. insert (newContent, 0, true);
  35753. }
  35754. bool CodeDocument::loadFromStream (InputStream& stream)
  35755. {
  35756. replaceAllContent (stream.readEntireStreamAsString());
  35757. setSavePoint();
  35758. clearUndoHistory();
  35759. return true;
  35760. }
  35761. bool CodeDocument::writeToStream (OutputStream& stream)
  35762. {
  35763. for (int i = 0; i < lines.size(); ++i)
  35764. {
  35765. String temp (lines.getUnchecked(i)->line); // use a copy to avoid bloating the memory footprint of the stored string.
  35766. const char* utf8 = temp.toUTF8();
  35767. if (! stream.write (utf8, (int) strlen (utf8)))
  35768. return false;
  35769. }
  35770. return true;
  35771. }
  35772. void CodeDocument::setNewLineCharacters (const String& newLine) throw()
  35773. {
  35774. jassert (newLine == T("\r\n") || newLine == T("\n") || newLine == T("\r"));
  35775. newLineChars = newLine;
  35776. }
  35777. void CodeDocument::newTransaction()
  35778. {
  35779. undoManager.beginNewTransaction (String::empty);
  35780. }
  35781. void CodeDocument::undo()
  35782. {
  35783. newTransaction();
  35784. undoManager.undo();
  35785. }
  35786. void CodeDocument::redo()
  35787. {
  35788. undoManager.redo();
  35789. }
  35790. void CodeDocument::clearUndoHistory()
  35791. {
  35792. undoManager.clearUndoHistory();
  35793. }
  35794. void CodeDocument::setSavePoint() throw()
  35795. {
  35796. indexOfSavedState = currentActionIndex;
  35797. }
  35798. bool CodeDocument::hasChangedSinceSavePoint() const throw()
  35799. {
  35800. return currentActionIndex != indexOfSavedState;
  35801. }
  35802. static int getCodeCharacterCategory (const tchar character) throw()
  35803. {
  35804. return (CharacterFunctions::isLetterOrDigit (character) || character == '_')
  35805. ? 2 : (CharacterFunctions::isWhitespace (character) ? 0 : 1);
  35806. }
  35807. const CodeDocument::Position CodeDocument::findWordBreakAfter (const Position& position) const throw()
  35808. {
  35809. Position p (position);
  35810. const int maxDistance = 256;
  35811. int i = 0;
  35812. while (i < maxDistance
  35813. && CharacterFunctions::isWhitespace (p.getCharacter())
  35814. && (i == 0 || (p.getCharacter() != T('\n')
  35815. && p.getCharacter() != T('\r'))))
  35816. {
  35817. ++i;
  35818. p.moveBy (1);
  35819. }
  35820. if (i == 0)
  35821. {
  35822. const int type = getCodeCharacterCategory (p.getCharacter());
  35823. while (i < maxDistance && type == getCodeCharacterCategory (p.getCharacter()))
  35824. {
  35825. ++i;
  35826. p.moveBy (1);
  35827. }
  35828. while (i < maxDistance
  35829. && CharacterFunctions::isWhitespace (p.getCharacter())
  35830. && (i == 0 || (p.getCharacter() != T('\n')
  35831. && p.getCharacter() != T('\r'))))
  35832. {
  35833. ++i;
  35834. p.moveBy (1);
  35835. }
  35836. }
  35837. return p;
  35838. }
  35839. const CodeDocument::Position CodeDocument::findWordBreakBefore (const Position& position) const throw()
  35840. {
  35841. Position p (position);
  35842. const int maxDistance = 256;
  35843. int i = 0;
  35844. bool stoppedAtLineStart = false;
  35845. while (i < maxDistance)
  35846. {
  35847. const tchar c = p.movedBy (-1).getCharacter();
  35848. if (c == T('\r') || c == T('\n'))
  35849. {
  35850. stoppedAtLineStart = true;
  35851. if (i > 0)
  35852. break;
  35853. }
  35854. if (! CharacterFunctions::isWhitespace (c))
  35855. break;
  35856. p.moveBy (-1);
  35857. ++i;
  35858. }
  35859. if (i < maxDistance && ! stoppedAtLineStart)
  35860. {
  35861. const int type = getCodeCharacterCategory (p.movedBy (-1).getCharacter());
  35862. while (i < maxDistance && type == getCodeCharacterCategory (p.movedBy (-1).getCharacter()))
  35863. {
  35864. p.moveBy (-1);
  35865. ++i;
  35866. }
  35867. }
  35868. return p;
  35869. }
  35870. void CodeDocument::checkLastLineStatus()
  35871. {
  35872. while (lines.size() > 0
  35873. && lines.getLast()->lineLength == 0
  35874. && (lines.size() == 1 || ! lines.getUnchecked (lines.size() - 2)->endsWithLineBreak()))
  35875. {
  35876. // remove any empty lines at the end if the preceding line doesn't end in a newline.
  35877. lines.removeLast();
  35878. }
  35879. const CodeDocumentLine* const lastLine = lines.getLast();
  35880. if (lastLine != 0 && lastLine->endsWithLineBreak())
  35881. {
  35882. // check that there's an empty line at the end if the preceding one ends in a newline..
  35883. lines.add (new CodeDocumentLine (String::empty, 0, 0, lastLine->lineStartInFile + lastLine->lineLength));
  35884. }
  35885. }
  35886. void CodeDocument::addListener (CodeDocument::Listener* const listener) throw()
  35887. {
  35888. listeners.addIfNotAlreadyThere (listener);
  35889. }
  35890. void CodeDocument::removeListener (CodeDocument::Listener* const listener) throw()
  35891. {
  35892. listeners.removeValue (listener);
  35893. }
  35894. void CodeDocument::sendListenerChangeMessage (const int startLine, const int endLine)
  35895. {
  35896. const Position startPos (this, startLine, 0);
  35897. const Position endPos (this, endLine, 0);
  35898. for (int i = listeners.size(); --i >= 0;)
  35899. {
  35900. Listener* const l = (Listener*) listeners[i];
  35901. if (l != 0)
  35902. l->codeDocumentChanged (startPos, endPos);
  35903. }
  35904. }
  35905. class CodeDocumentInsertAction : public UndoableAction
  35906. {
  35907. CodeDocument& owner;
  35908. const String text;
  35909. int insertPos;
  35910. CodeDocumentInsertAction (const CodeDocumentInsertAction&);
  35911. const CodeDocumentInsertAction& operator= (const CodeDocumentInsertAction&);
  35912. public:
  35913. CodeDocumentInsertAction (CodeDocument& owner_, const String& text_, const int insertPos_) throw()
  35914. : owner (owner_),
  35915. text (text_),
  35916. insertPos (insertPos_)
  35917. {
  35918. }
  35919. ~CodeDocumentInsertAction() {}
  35920. bool perform()
  35921. {
  35922. owner.currentActionIndex++;
  35923. owner.insert (text, insertPos, false);
  35924. return true;
  35925. }
  35926. bool undo()
  35927. {
  35928. owner.currentActionIndex--;
  35929. owner.remove (insertPos, insertPos + text.length(), false);
  35930. return true;
  35931. }
  35932. int getSizeInUnits() { return text.length() + 32; }
  35933. };
  35934. void CodeDocument::insert (const String& text, const int insertPos, const bool undoable)
  35935. {
  35936. if (text.isEmpty())
  35937. return;
  35938. if (undoable)
  35939. {
  35940. undoManager.perform (new CodeDocumentInsertAction (*this, text, insertPos));
  35941. }
  35942. else
  35943. {
  35944. Position pos (this, insertPos);
  35945. const int firstAffectedLine = pos.getLineNumber();
  35946. int lastAffectedLine = firstAffectedLine + 1;
  35947. CodeDocumentLine* const firstLine = lines [firstAffectedLine];
  35948. String textInsideOriginalLine (text);
  35949. if (firstLine != 0)
  35950. {
  35951. const int index = pos.getIndexInLine();
  35952. textInsideOriginalLine = firstLine->line.substring (0, index)
  35953. + textInsideOriginalLine
  35954. + firstLine->line.substring (index);
  35955. }
  35956. maximumLineLength = -1;
  35957. Array <CodeDocumentLine*> newLines;
  35958. CodeDocumentLine::createLines (newLines, textInsideOriginalLine);
  35959. jassert (newLines.size() > 0);
  35960. CodeDocumentLine* const newFirstLine = newLines.getUnchecked (0);
  35961. newFirstLine->lineStartInFile = firstLine != 0 ? firstLine->lineStartInFile : 0;
  35962. lines.set (firstAffectedLine, newFirstLine);
  35963. if (newLines.size() > 1)
  35964. {
  35965. for (int i = 1; i < newLines.size(); ++i)
  35966. {
  35967. CodeDocumentLine* const l = newLines.getUnchecked (i);
  35968. lines.insert (firstAffectedLine + i, l);
  35969. }
  35970. lastAffectedLine = lines.size();
  35971. }
  35972. int i, lineStart = newFirstLine->lineStartInFile;
  35973. for (i = firstAffectedLine; i < lines.size(); ++i)
  35974. {
  35975. CodeDocumentLine* const l = lines.getUnchecked (i);
  35976. l->lineStartInFile = lineStart;
  35977. lineStart += l->lineLength;
  35978. }
  35979. checkLastLineStatus();
  35980. const int newTextLength = text.length();
  35981. for (i = 0; i < positionsToMaintain.size(); ++i)
  35982. {
  35983. CodeDocument::Position* const p = positionsToMaintain.getUnchecked(i);
  35984. if (p->getPosition() >= insertPos)
  35985. p->setPosition (p->getPosition() + newTextLength);
  35986. }
  35987. sendListenerChangeMessage (firstAffectedLine, lastAffectedLine);
  35988. }
  35989. }
  35990. class CodeDocumentDeleteAction : public UndoableAction
  35991. {
  35992. CodeDocument& owner;
  35993. int startPos, endPos;
  35994. String removedText;
  35995. CodeDocumentDeleteAction (const CodeDocumentDeleteAction&);
  35996. const CodeDocumentDeleteAction& operator= (const CodeDocumentDeleteAction&);
  35997. public:
  35998. CodeDocumentDeleteAction (CodeDocument& owner_, const int startPos_, const int endPos_) throw()
  35999. : owner (owner_),
  36000. startPos (startPos_),
  36001. endPos (endPos_)
  36002. {
  36003. removedText = owner.getTextBetween (CodeDocument::Position (&owner, startPos),
  36004. CodeDocument::Position (&owner, endPos));
  36005. }
  36006. ~CodeDocumentDeleteAction() {}
  36007. bool perform()
  36008. {
  36009. owner.currentActionIndex++;
  36010. owner.remove (startPos, endPos, false);
  36011. return true;
  36012. }
  36013. bool undo()
  36014. {
  36015. owner.currentActionIndex--;
  36016. owner.insert (removedText, startPos, false);
  36017. return true;
  36018. }
  36019. int getSizeInUnits() { return removedText.length() + 32; }
  36020. };
  36021. void CodeDocument::remove (const int startPos, const int endPos, const bool undoable)
  36022. {
  36023. if (endPos <= startPos)
  36024. return;
  36025. if (undoable)
  36026. {
  36027. undoManager.perform (new CodeDocumentDeleteAction (*this, startPos, endPos));
  36028. }
  36029. else
  36030. {
  36031. Position startPosition (this, startPos);
  36032. Position endPosition (this, endPos);
  36033. maximumLineLength = -1;
  36034. const int firstAffectedLine = startPosition.getLineNumber();
  36035. const int endLine = endPosition.getLineNumber();
  36036. int lastAffectedLine = firstAffectedLine + 1;
  36037. CodeDocumentLine* const firstLine = lines.getUnchecked (firstAffectedLine);
  36038. if (firstAffectedLine == endLine)
  36039. {
  36040. firstLine->line = firstLine->line.substring (0, startPosition.getIndexInLine())
  36041. + firstLine->line.substring (endPosition.getIndexInLine());
  36042. firstLine->updateLength();
  36043. }
  36044. else
  36045. {
  36046. lastAffectedLine = lines.size();
  36047. CodeDocumentLine* const lastLine = lines.getUnchecked (endLine);
  36048. jassert (lastLine != 0);
  36049. firstLine->line = firstLine->line.substring (0, startPosition.getIndexInLine())
  36050. + lastLine->line.substring (endPosition.getIndexInLine());
  36051. firstLine->updateLength();
  36052. int numLinesToRemove = endLine - firstAffectedLine;
  36053. lines.removeRange (firstAffectedLine + 1, numLinesToRemove);
  36054. }
  36055. int i;
  36056. for (i = firstAffectedLine + 1; i < lines.size(); ++i)
  36057. {
  36058. CodeDocumentLine* const l = lines.getUnchecked (i);
  36059. const CodeDocumentLine* const previousLine = lines.getUnchecked (i - 1);
  36060. l->lineStartInFile = previousLine->lineStartInFile + previousLine->lineLength;
  36061. }
  36062. checkLastLineStatus();
  36063. const int totalChars = getNumCharacters();
  36064. for (i = 0; i < positionsToMaintain.size(); ++i)
  36065. {
  36066. CodeDocument::Position* p = positionsToMaintain.getUnchecked(i);
  36067. if (p->getPosition() > startPosition.getPosition())
  36068. p->setPosition (jmax (startPos, p->getPosition() + startPos - endPos));
  36069. if (p->getPosition() > totalChars)
  36070. p->setPosition (totalChars);
  36071. }
  36072. sendListenerChangeMessage (firstAffectedLine, lastAffectedLine);
  36073. }
  36074. }
  36075. END_JUCE_NAMESPACE
  36076. /*** End of inlined file: juce_CodeDocument.cpp ***/
  36077. /*** Start of inlined file: juce_CodeEditorComponent.cpp ***/
  36078. BEGIN_JUCE_NAMESPACE
  36079. class CaretComponent : public Component,
  36080. public Timer
  36081. {
  36082. public:
  36083. CaretComponent()
  36084. {
  36085. setAlwaysOnTop (true);
  36086. setInterceptsMouseClicks (false, false);
  36087. }
  36088. ~CaretComponent()
  36089. {
  36090. }
  36091. void paint (Graphics& g)
  36092. {
  36093. if (getParentComponent()->hasKeyboardFocus (true))
  36094. g.fillAll (findColour (CodeEditorComponent::caretColourId));
  36095. }
  36096. void timerCallback()
  36097. {
  36098. setVisible (! isVisible());
  36099. }
  36100. void updatePosition (CodeEditorComponent& owner)
  36101. {
  36102. startTimer (400);
  36103. setVisible (true);
  36104. const Rectangle<int> pos (owner.getCharacterBounds (owner.getCaretPos()));
  36105. setBounds (pos.getX(), pos.getY(), 2, pos.getHeight());
  36106. }
  36107. };
  36108. class CodeEditorComponent::CodeEditorLine
  36109. {
  36110. public:
  36111. CodeEditorLine() throw()
  36112. {
  36113. }
  36114. ~CodeEditorLine() throw()
  36115. {
  36116. }
  36117. bool update (CodeDocument& document, int lineNum,
  36118. CodeDocument::Iterator& source,
  36119. CodeTokeniser* analyser, const int spacesPerTab,
  36120. const CodeDocument::Position& selectionStart,
  36121. const CodeDocument::Position& selectionEnd)
  36122. {
  36123. Array <SyntaxToken> newTokens;
  36124. newTokens.ensureStorageAllocated (8);
  36125. if (analyser == 0)
  36126. {
  36127. newTokens.add (SyntaxToken (document.getLine (lineNum), -1));
  36128. }
  36129. else if (lineNum < document.getNumLines())
  36130. {
  36131. const CodeDocument::Position pos (&document, lineNum, 0);
  36132. createTokens (pos.getPosition(), pos.getLineText(),
  36133. source, analyser, newTokens);
  36134. }
  36135. replaceTabsWithSpaces (newTokens, spacesPerTab);
  36136. int newHighlightStart = 0;
  36137. int newHighlightEnd = 0;
  36138. if (selectionStart.getLineNumber() <= lineNum && selectionEnd.getLineNumber() >= lineNum)
  36139. {
  36140. const String line (document.getLine (lineNum));
  36141. CodeDocument::Position lineStart (&document, lineNum, 0), lineEnd (&document, lineNum + 1, 0);
  36142. newHighlightStart = indexToColumn (jmax (0, selectionStart.getPosition() - lineStart.getPosition()),
  36143. line, spacesPerTab);
  36144. newHighlightEnd = indexToColumn (jmin (lineEnd.getPosition() - lineStart.getPosition(), selectionEnd.getPosition() - lineStart.getPosition()),
  36145. line, spacesPerTab);
  36146. }
  36147. if (newHighlightStart != highlightColumnStart || newHighlightEnd != highlightColumnEnd)
  36148. {
  36149. highlightColumnStart = newHighlightStart;
  36150. highlightColumnEnd = newHighlightEnd;
  36151. }
  36152. else
  36153. {
  36154. if (tokens.size() == newTokens.size())
  36155. {
  36156. bool allTheSame = true;
  36157. for (int i = newTokens.size(); --i >= 0;)
  36158. {
  36159. if (tokens.getReference(i) != newTokens.getReference(i))
  36160. {
  36161. allTheSame = false;
  36162. break;
  36163. }
  36164. }
  36165. if (allTheSame)
  36166. return false;
  36167. }
  36168. }
  36169. tokens.swapWithArray (newTokens);
  36170. return true;
  36171. }
  36172. void draw (CodeEditorComponent& owner, Graphics& g, const Font& font,
  36173. float x, const int y, const int baselineOffset, const int lineHeight,
  36174. const Colour& highlightColour) const throw()
  36175. {
  36176. if (highlightColumnStart < highlightColumnEnd)
  36177. {
  36178. g.setColour (highlightColour);
  36179. g.fillRect (roundToInt (x + highlightColumnStart * owner.getCharWidth()), y,
  36180. roundToInt ((highlightColumnEnd - highlightColumnStart) * owner.getCharWidth()), lineHeight);
  36181. }
  36182. int lastType = std::numeric_limits<int>::min();
  36183. for (int i = 0; i < tokens.size(); ++i)
  36184. {
  36185. SyntaxToken& token = tokens.getReference(i);
  36186. if (lastType != token.tokenType)
  36187. {
  36188. lastType = token.tokenType;
  36189. g.setColour (owner.getColourForTokenType (lastType));
  36190. }
  36191. g.drawSingleLineText (token.text, roundToInt (x), y + baselineOffset);
  36192. if (i < tokens.size() - 1)
  36193. {
  36194. if (token.width < 0)
  36195. token.width = font.getStringWidthFloat (token.text);
  36196. x += token.width;
  36197. }
  36198. }
  36199. }
  36200. private:
  36201. struct SyntaxToken
  36202. {
  36203. String text;
  36204. int tokenType;
  36205. float width;
  36206. SyntaxToken (const String& text_, const int type) throw()
  36207. : text (text_), tokenType (type), width (-1.0f)
  36208. {
  36209. }
  36210. bool operator!= (const SyntaxToken& other) const throw()
  36211. {
  36212. return text != other.text || tokenType != other.tokenType;
  36213. }
  36214. };
  36215. Array <SyntaxToken> tokens;
  36216. int highlightColumnStart, highlightColumnEnd;
  36217. static void createTokens (int startPosition, const String& lineText,
  36218. CodeDocument::Iterator& source,
  36219. CodeTokeniser* analyser,
  36220. Array <SyntaxToken>& newTokens)
  36221. {
  36222. CodeDocument::Iterator lastIterator (source);
  36223. const int lineLength = lineText.length();
  36224. for (;;)
  36225. {
  36226. int tokenType = analyser->readNextToken (source);
  36227. int tokenStart = lastIterator.getPosition();
  36228. int tokenEnd = source.getPosition();
  36229. if (tokenEnd <= tokenStart)
  36230. break;
  36231. tokenEnd -= startPosition;
  36232. if (tokenEnd > 0)
  36233. {
  36234. tokenStart -= startPosition;
  36235. newTokens.add (SyntaxToken (lineText.substring (jmax (0, tokenStart), tokenEnd),
  36236. tokenType));
  36237. if (tokenEnd >= lineLength)
  36238. break;
  36239. }
  36240. lastIterator = source;
  36241. }
  36242. source = lastIterator;
  36243. }
  36244. static void replaceTabsWithSpaces (Array <SyntaxToken>& tokens, const int spacesPerTab) throw()
  36245. {
  36246. int x = 0;
  36247. for (int i = 0; i < tokens.size(); ++i)
  36248. {
  36249. SyntaxToken& t = tokens.getReference(i);
  36250. for (;;)
  36251. {
  36252. int tabPos = t.text.indexOfChar (T('\t'));
  36253. if (tabPos < 0)
  36254. break;
  36255. const int spacesNeeded = spacesPerTab - ((tabPos + x) % spacesPerTab);
  36256. t.text = t.text.replaceSection (tabPos, 1, String::repeatedString (T(" "), spacesNeeded));
  36257. }
  36258. x += t.text.length();
  36259. }
  36260. }
  36261. int indexToColumn (int index, const String& line, int spacesPerTab) const throw()
  36262. {
  36263. jassert (index <= line.length());
  36264. int col = 0;
  36265. for (int i = 0; i < index; ++i)
  36266. {
  36267. if (line[i] != T('\t'))
  36268. ++col;
  36269. else
  36270. col += spacesPerTab - (col % spacesPerTab);
  36271. }
  36272. return col;
  36273. }
  36274. };
  36275. CodeEditorComponent::CodeEditorComponent (CodeDocument& document_,
  36276. CodeTokeniser* const codeTokeniser_)
  36277. : document (document_),
  36278. firstLineOnScreen (0),
  36279. gutter (5),
  36280. spacesPerTab (4),
  36281. lineHeight (0),
  36282. linesOnScreen (0),
  36283. columnsOnScreen (0),
  36284. scrollbarThickness (16),
  36285. columnToTryToMaintain (-1),
  36286. useSpacesForTabs (false),
  36287. xOffset (0),
  36288. codeTokeniser (codeTokeniser_)
  36289. {
  36290. caretPos = CodeDocument::Position (&document_, 0, 0);
  36291. caretPos.setPositionMaintained (true);
  36292. selectionStart = CodeDocument::Position (&document_, 0, 0);
  36293. selectionStart.setPositionMaintained (true);
  36294. selectionEnd = CodeDocument::Position (&document_, 0, 0);
  36295. selectionEnd.setPositionMaintained (true);
  36296. setOpaque (true);
  36297. setMouseCursor (MouseCursor (MouseCursor::IBeamCursor));
  36298. setWantsKeyboardFocus (true);
  36299. addAndMakeVisible (verticalScrollBar = new ScrollBar (true));
  36300. verticalScrollBar->setSingleStepSize (1.0);
  36301. addAndMakeVisible (horizontalScrollBar = new ScrollBar (false));
  36302. horizontalScrollBar->setSingleStepSize (1.0);
  36303. addAndMakeVisible (caret = new CaretComponent());
  36304. Font f (12.0f);
  36305. f.setTypefaceName (Font::getDefaultMonospacedFontName());
  36306. setFont (f);
  36307. resetToDefaultColours();
  36308. verticalScrollBar->addListener (this);
  36309. horizontalScrollBar->addListener (this);
  36310. document.addListener (this);
  36311. }
  36312. CodeEditorComponent::~CodeEditorComponent()
  36313. {
  36314. document.removeListener (this);
  36315. deleteAllChildren();
  36316. }
  36317. void CodeEditorComponent::loadContent (const String& newContent)
  36318. {
  36319. clearCachedIterators (0);
  36320. document.replaceAllContent (newContent);
  36321. document.clearUndoHistory();
  36322. document.setSavePoint();
  36323. caretPos.setPosition (0);
  36324. selectionStart.setPosition (0);
  36325. selectionEnd.setPosition (0);
  36326. scrollToLine (0);
  36327. }
  36328. void CodeEditorComponent::codeDocumentChanged (const CodeDocument::Position& affectedTextStart,
  36329. const CodeDocument::Position& affectedTextEnd)
  36330. {
  36331. clearCachedIterators (affectedTextStart.getLineNumber());
  36332. triggerAsyncUpdate();
  36333. ((CaretComponent*) caret)->updatePosition (*this);
  36334. columnToTryToMaintain = -1;
  36335. if (affectedTextEnd.getPosition() >= selectionStart.getPosition()
  36336. && affectedTextStart.getPosition() <= selectionEnd.getPosition())
  36337. deselectAll();
  36338. if (caretPos.getPosition() > affectedTextEnd.getPosition()
  36339. || caretPos.getPosition() < affectedTextStart.getPosition())
  36340. moveCaretTo (affectedTextStart, false);
  36341. updateScrollBars();
  36342. }
  36343. void CodeEditorComponent::resized()
  36344. {
  36345. linesOnScreen = (getHeight() - scrollbarThickness) / lineHeight;
  36346. columnsOnScreen = (int) ((getWidth() - scrollbarThickness) / charWidth);
  36347. lines.clear();
  36348. rebuildLineTokens();
  36349. ((CaretComponent*) caret)->updatePosition (*this);
  36350. verticalScrollBar->setBounds (getWidth() - scrollbarThickness, 0, scrollbarThickness, getHeight() - scrollbarThickness);
  36351. horizontalScrollBar->setBounds (gutter, getHeight() - scrollbarThickness, getWidth() - scrollbarThickness - gutter, scrollbarThickness);
  36352. updateScrollBars();
  36353. }
  36354. void CodeEditorComponent::paint (Graphics& g)
  36355. {
  36356. handleUpdateNowIfNeeded();
  36357. g.fillAll (findColour (CodeEditorComponent::backgroundColourId));
  36358. g.reduceClipRegion (gutter, 0, verticalScrollBar->getX() - gutter, horizontalScrollBar->getY());
  36359. g.setFont (font);
  36360. const int baselineOffset = (int) font.getAscent();
  36361. const Colour defaultColour (findColour (CodeEditorComponent::defaultTextColourId));
  36362. const Colour highlightColour (findColour (CodeEditorComponent::highlightColourId));
  36363. const Rectangle<int> clip (g.getClipBounds());
  36364. const int firstLineToDraw = jmax (0, clip.getY() / lineHeight);
  36365. const int lastLineToDraw = jmin (lines.size(), clip.getBottom() / lineHeight + 1);
  36366. for (int j = firstLineToDraw; j < lastLineToDraw; ++j)
  36367. {
  36368. lines.getUnchecked(j)->draw (*this, g, font,
  36369. (float) (gutter - xOffset * charWidth),
  36370. lineHeight * j, baselineOffset, lineHeight,
  36371. highlightColour);
  36372. }
  36373. }
  36374. void CodeEditorComponent::setScrollbarThickness (const int thickness) throw()
  36375. {
  36376. if (scrollbarThickness != thickness)
  36377. {
  36378. scrollbarThickness = thickness;
  36379. resized();
  36380. }
  36381. }
  36382. void CodeEditorComponent::handleAsyncUpdate()
  36383. {
  36384. rebuildLineTokens();
  36385. }
  36386. void CodeEditorComponent::rebuildLineTokens()
  36387. {
  36388. cancelPendingUpdate();
  36389. const int numNeeded = linesOnScreen + 1;
  36390. int minLineToRepaint = numNeeded;
  36391. int maxLineToRepaint = 0;
  36392. if (numNeeded != lines.size())
  36393. {
  36394. lines.clear();
  36395. for (int i = numNeeded; --i >= 0;)
  36396. lines.add (new CodeEditorLine());
  36397. minLineToRepaint = 0;
  36398. maxLineToRepaint = numNeeded;
  36399. }
  36400. jassert (numNeeded == lines.size());
  36401. CodeDocument::Iterator source (&document);
  36402. getIteratorForPosition (CodeDocument::Position (&document, firstLineOnScreen, 0).getPosition(), source);
  36403. for (int i = 0; i < numNeeded; ++i)
  36404. {
  36405. CodeEditorLine* const line = lines.getUnchecked(i);
  36406. if (line->update (document, firstLineOnScreen + i, source, codeTokeniser, spacesPerTab,
  36407. selectionStart, selectionEnd))
  36408. {
  36409. minLineToRepaint = jmin (minLineToRepaint, i);
  36410. maxLineToRepaint = jmax (maxLineToRepaint, i);
  36411. }
  36412. }
  36413. if (minLineToRepaint <= maxLineToRepaint)
  36414. {
  36415. repaint (gutter, lineHeight * minLineToRepaint - 1,
  36416. verticalScrollBar->getX() - gutter,
  36417. lineHeight * (1 + maxLineToRepaint - minLineToRepaint) + 2);
  36418. }
  36419. }
  36420. void CodeEditorComponent::moveCaretTo (const CodeDocument::Position& newPos, const bool highlighting)
  36421. {
  36422. caretPos = newPos;
  36423. columnToTryToMaintain = -1;
  36424. if (highlighting)
  36425. {
  36426. if (dragType == notDragging)
  36427. {
  36428. if (abs (caretPos.getPosition() - selectionStart.getPosition())
  36429. < abs (caretPos.getPosition() - selectionEnd.getPosition()))
  36430. dragType = draggingSelectionStart;
  36431. else
  36432. dragType = draggingSelectionEnd;
  36433. }
  36434. if (dragType == draggingSelectionStart)
  36435. {
  36436. selectionStart = caretPos;
  36437. if (selectionEnd.getPosition() < selectionStart.getPosition())
  36438. {
  36439. const CodeDocument::Position temp (selectionStart);
  36440. selectionStart = selectionEnd;
  36441. selectionEnd = temp;
  36442. dragType = draggingSelectionEnd;
  36443. }
  36444. }
  36445. else
  36446. {
  36447. selectionEnd = caretPos;
  36448. if (selectionEnd.getPosition() < selectionStart.getPosition())
  36449. {
  36450. const CodeDocument::Position temp (selectionStart);
  36451. selectionStart = selectionEnd;
  36452. selectionEnd = temp;
  36453. dragType = draggingSelectionStart;
  36454. }
  36455. }
  36456. triggerAsyncUpdate();
  36457. }
  36458. else
  36459. {
  36460. deselectAll();
  36461. }
  36462. ((CaretComponent*) caret)->updatePosition (*this);
  36463. scrollToKeepCaretOnScreen();
  36464. updateScrollBars();
  36465. }
  36466. void CodeEditorComponent::deselectAll()
  36467. {
  36468. if (selectionStart != selectionEnd)
  36469. triggerAsyncUpdate();
  36470. selectionStart = caretPos;
  36471. selectionEnd = caretPos;
  36472. }
  36473. void CodeEditorComponent::updateScrollBars()
  36474. {
  36475. verticalScrollBar->setRangeLimits (0, jmax (document.getNumLines(), firstLineOnScreen + linesOnScreen));
  36476. verticalScrollBar->setCurrentRange (firstLineOnScreen, linesOnScreen);
  36477. horizontalScrollBar->setRangeLimits (0, jmax ((double) document.getMaximumLineLength(), xOffset + columnsOnScreen));
  36478. horizontalScrollBar->setCurrentRange (xOffset, columnsOnScreen);
  36479. }
  36480. void CodeEditorComponent::scrollToLineInternal (int newFirstLineOnScreen)
  36481. {
  36482. newFirstLineOnScreen = jlimit (0, jmax (0, document.getNumLines() - 1),
  36483. newFirstLineOnScreen);
  36484. if (newFirstLineOnScreen != firstLineOnScreen)
  36485. {
  36486. firstLineOnScreen = newFirstLineOnScreen;
  36487. ((CaretComponent*) caret)->updatePosition (*this);
  36488. updateCachedIterators (firstLineOnScreen);
  36489. triggerAsyncUpdate();
  36490. }
  36491. }
  36492. void CodeEditorComponent::scrollToColumnInternal (double column)
  36493. {
  36494. const double newOffset = jlimit (0.0, document.getMaximumLineLength() + 3.0, column);
  36495. if (xOffset != newOffset)
  36496. {
  36497. xOffset = newOffset;
  36498. ((CaretComponent*) caret)->updatePosition (*this);
  36499. repaint();
  36500. }
  36501. }
  36502. void CodeEditorComponent::scrollToLine (int newFirstLineOnScreen)
  36503. {
  36504. scrollToLineInternal (newFirstLineOnScreen);
  36505. updateScrollBars();
  36506. }
  36507. void CodeEditorComponent::scrollToColumn (int newFirstColumnOnScreen)
  36508. {
  36509. scrollToColumnInternal (newFirstColumnOnScreen);
  36510. updateScrollBars();
  36511. }
  36512. void CodeEditorComponent::scrollBy (int deltaLines)
  36513. {
  36514. scrollToLine (firstLineOnScreen + deltaLines);
  36515. }
  36516. void CodeEditorComponent::scrollToKeepCaretOnScreen()
  36517. {
  36518. if (caretPos.getLineNumber() < firstLineOnScreen)
  36519. scrollBy (caretPos.getLineNumber() - firstLineOnScreen);
  36520. else if (caretPos.getLineNumber() >= firstLineOnScreen + linesOnScreen)
  36521. scrollBy (caretPos.getLineNumber() - (firstLineOnScreen + linesOnScreen - 1));
  36522. const int column = indexToColumn (caretPos.getLineNumber(), caretPos.getIndexInLine());
  36523. if (column >= xOffset + columnsOnScreen - 1)
  36524. scrollToColumn (column + 1 - columnsOnScreen);
  36525. else if (column < xOffset)
  36526. scrollToColumn (column);
  36527. }
  36528. const Rectangle<int> CodeEditorComponent::getCharacterBounds (const CodeDocument::Position& pos) const throw()
  36529. {
  36530. return Rectangle<int> (roundToInt ((gutter - xOffset * charWidth) + indexToColumn (pos.getLineNumber(), pos.getIndexInLine()) * charWidth),
  36531. (pos.getLineNumber() - firstLineOnScreen) * lineHeight,
  36532. roundToInt (charWidth),
  36533. lineHeight);
  36534. }
  36535. const CodeDocument::Position CodeEditorComponent::getPositionAt (int x, int y)
  36536. {
  36537. const int line = y / lineHeight + firstLineOnScreen;
  36538. const int column = roundToInt ((x - (gutter - xOffset * charWidth)) / charWidth);
  36539. const int index = columnToIndex (line, column);
  36540. return CodeDocument::Position (&document, line, index);
  36541. }
  36542. void CodeEditorComponent::insertTextAtCaret (const String& newText)
  36543. {
  36544. document.deleteSection (selectionStart, selectionEnd);
  36545. if (newText.isNotEmpty())
  36546. document.insertText (caretPos, newText);
  36547. scrollToKeepCaretOnScreen();
  36548. }
  36549. void CodeEditorComponent::insertTabAtCaret()
  36550. {
  36551. if (CharacterFunctions::isWhitespace (caretPos.getCharacter())
  36552. && caretPos.getLineNumber() == caretPos.movedBy (1).getLineNumber())
  36553. {
  36554. moveCaretTo (document.findWordBreakAfter (caretPos), false);
  36555. }
  36556. if (useSpacesForTabs)
  36557. {
  36558. const int caretCol = indexToColumn (caretPos.getLineNumber(), caretPos.getIndexInLine());
  36559. const int spacesNeeded = spacesPerTab - (caretCol % spacesPerTab);
  36560. insertTextAtCaret (String::repeatedString (T(" "), spacesNeeded));
  36561. }
  36562. else
  36563. {
  36564. insertTextAtCaret (T("\t"));
  36565. }
  36566. }
  36567. void CodeEditorComponent::cut()
  36568. {
  36569. insertTextAtCaret (String::empty);
  36570. }
  36571. void CodeEditorComponent::copy()
  36572. {
  36573. newTransaction();
  36574. const String selection (document.getTextBetween (selectionStart, selectionEnd));
  36575. if (selection.isNotEmpty())
  36576. SystemClipboard::copyTextToClipboard (selection);
  36577. }
  36578. void CodeEditorComponent::copyThenCut()
  36579. {
  36580. copy();
  36581. cut();
  36582. newTransaction();
  36583. }
  36584. void CodeEditorComponent::paste()
  36585. {
  36586. newTransaction();
  36587. const String clip (SystemClipboard::getTextFromClipboard());
  36588. if (clip.isNotEmpty())
  36589. insertTextAtCaret (clip);
  36590. newTransaction();
  36591. }
  36592. void CodeEditorComponent::cursorLeft (const bool moveInWholeWordSteps, const bool selecting)
  36593. {
  36594. newTransaction();
  36595. if (moveInWholeWordSteps)
  36596. moveCaretTo (document.findWordBreakBefore (caretPos), selecting);
  36597. else
  36598. moveCaretTo (caretPos.movedBy (-1), selecting);
  36599. }
  36600. void CodeEditorComponent::cursorRight (const bool moveInWholeWordSteps, const bool selecting)
  36601. {
  36602. newTransaction();
  36603. if (moveInWholeWordSteps)
  36604. moveCaretTo (document.findWordBreakAfter (caretPos), selecting);
  36605. else
  36606. moveCaretTo (caretPos.movedBy (1), selecting);
  36607. }
  36608. void CodeEditorComponent::moveLineDelta (const int delta, const bool selecting)
  36609. {
  36610. CodeDocument::Position pos (caretPos);
  36611. const int newLineNum = pos.getLineNumber() + delta;
  36612. if (columnToTryToMaintain < 0)
  36613. columnToTryToMaintain = indexToColumn (pos.getLineNumber(), pos.getIndexInLine());
  36614. pos.setLineAndIndex (newLineNum, columnToIndex (newLineNum, columnToTryToMaintain));
  36615. const int colToMaintain = columnToTryToMaintain;
  36616. moveCaretTo (pos, selecting);
  36617. columnToTryToMaintain = colToMaintain;
  36618. }
  36619. void CodeEditorComponent::cursorDown (const bool selecting)
  36620. {
  36621. newTransaction();
  36622. if (caretPos.getLineNumber() == document.getNumLines() - 1)
  36623. moveCaretTo (CodeDocument::Position (&document, std::numeric_limits<int>::max(), std::numeric_limits<int>::max()), selecting);
  36624. else
  36625. moveLineDelta (1, selecting);
  36626. }
  36627. void CodeEditorComponent::cursorUp (const bool selecting)
  36628. {
  36629. newTransaction();
  36630. if (caretPos.getLineNumber() == 0)
  36631. moveCaretTo (CodeDocument::Position (&document, 0, 0), selecting);
  36632. else
  36633. moveLineDelta (-1, selecting);
  36634. }
  36635. void CodeEditorComponent::pageDown (const bool selecting)
  36636. {
  36637. newTransaction();
  36638. scrollBy (jlimit (0, linesOnScreen, 1 + document.getNumLines() - firstLineOnScreen - linesOnScreen));
  36639. moveLineDelta (linesOnScreen, selecting);
  36640. }
  36641. void CodeEditorComponent::pageUp (const bool selecting)
  36642. {
  36643. newTransaction();
  36644. scrollBy (-linesOnScreen);
  36645. moveLineDelta (-linesOnScreen, selecting);
  36646. }
  36647. void CodeEditorComponent::scrollUp()
  36648. {
  36649. newTransaction();
  36650. scrollBy (1);
  36651. if (caretPos.getLineNumber() < firstLineOnScreen)
  36652. moveLineDelta (1, false);
  36653. }
  36654. void CodeEditorComponent::scrollDown()
  36655. {
  36656. newTransaction();
  36657. scrollBy (-1);
  36658. if (caretPos.getLineNumber() >= firstLineOnScreen + linesOnScreen)
  36659. moveLineDelta (-1, false);
  36660. }
  36661. void CodeEditorComponent::goToStartOfDocument (const bool selecting)
  36662. {
  36663. newTransaction();
  36664. moveCaretTo (CodeDocument::Position (&document, 0, 0), selecting);
  36665. }
  36666. static int findFirstNonWhitespaceChar (const String& line) throw()
  36667. {
  36668. const int len = line.length();
  36669. for (int i = 0; i < len; ++i)
  36670. if (! CharacterFunctions::isWhitespace (line [i]))
  36671. return i;
  36672. return 0;
  36673. }
  36674. void CodeEditorComponent::goToStartOfLine (const bool selecting)
  36675. {
  36676. newTransaction();
  36677. int index = findFirstNonWhitespaceChar (caretPos.getLineText());
  36678. if (index >= caretPos.getIndexInLine() && caretPos.getIndexInLine() > 0)
  36679. index = 0;
  36680. moveCaretTo (CodeDocument::Position (&document, caretPos.getLineNumber(), index), selecting);
  36681. }
  36682. void CodeEditorComponent::goToEndOfDocument (const bool selecting)
  36683. {
  36684. newTransaction();
  36685. moveCaretTo (CodeDocument::Position (&document, std::numeric_limits<int>::max(), std::numeric_limits<int>::max()), selecting);
  36686. }
  36687. void CodeEditorComponent::goToEndOfLine (const bool selecting)
  36688. {
  36689. newTransaction();
  36690. moveCaretTo (CodeDocument::Position (&document, caretPos.getLineNumber(), std::numeric_limits<int>::max()), selecting);
  36691. }
  36692. void CodeEditorComponent::backspace (const bool moveInWholeWordSteps)
  36693. {
  36694. if (moveInWholeWordSteps)
  36695. {
  36696. cut(); // in case something is already highlighted
  36697. moveCaretTo (document.findWordBreakBefore (caretPos), true);
  36698. }
  36699. else
  36700. {
  36701. if (selectionStart == selectionEnd)
  36702. selectionStart.moveBy (-1);
  36703. }
  36704. cut();
  36705. }
  36706. void CodeEditorComponent::deleteForward (const bool moveInWholeWordSteps)
  36707. {
  36708. if (moveInWholeWordSteps)
  36709. {
  36710. cut(); // in case something is already highlighted
  36711. moveCaretTo (document.findWordBreakAfter (caretPos), true);
  36712. }
  36713. else
  36714. {
  36715. if (selectionStart == selectionEnd)
  36716. selectionEnd.moveBy (1);
  36717. else
  36718. newTransaction();
  36719. }
  36720. cut();
  36721. }
  36722. void CodeEditorComponent::selectAll()
  36723. {
  36724. newTransaction();
  36725. moveCaretTo (CodeDocument::Position (&document, std::numeric_limits<int>::max(), std::numeric_limits<int>::max()), false);
  36726. moveCaretTo (CodeDocument::Position (&document, 0, 0), true);
  36727. }
  36728. void CodeEditorComponent::undo()
  36729. {
  36730. document.undo();
  36731. scrollToKeepCaretOnScreen();
  36732. }
  36733. void CodeEditorComponent::redo()
  36734. {
  36735. document.redo();
  36736. scrollToKeepCaretOnScreen();
  36737. }
  36738. void CodeEditorComponent::newTransaction()
  36739. {
  36740. document.newTransaction();
  36741. startTimer (600);
  36742. }
  36743. void CodeEditorComponent::timerCallback()
  36744. {
  36745. newTransaction();
  36746. }
  36747. const Range<int> CodeEditorComponent::getHighlightedRegion() const
  36748. {
  36749. return Range<int> (selectionStart.getPosition(), selectionEnd.getPosition());
  36750. }
  36751. void CodeEditorComponent::setHighlightedRegion (const Range<int>& newRange)
  36752. {
  36753. moveCaretTo (CodeDocument::Position (&document, newRange.getStart()), false);
  36754. moveCaretTo (CodeDocument::Position (&document, newRange.getEnd()), true);
  36755. }
  36756. const String CodeEditorComponent::getTextInRange (const Range<int>& range) const
  36757. {
  36758. return document.getTextBetween (CodeDocument::Position (&document, range.getStart()),
  36759. CodeDocument::Position (&document, range.getEnd()));
  36760. }
  36761. bool CodeEditorComponent::keyPressed (const KeyPress& key)
  36762. {
  36763. const bool moveInWholeWordSteps = key.getModifiers().isCtrlDown() || key.getModifiers().isAltDown();
  36764. const bool shiftDown = key.getModifiers().isShiftDown();
  36765. if (key.isKeyCode (KeyPress::leftKey))
  36766. {
  36767. cursorLeft (moveInWholeWordSteps, shiftDown);
  36768. }
  36769. else if (key.isKeyCode (KeyPress::rightKey))
  36770. {
  36771. cursorRight (moveInWholeWordSteps, shiftDown);
  36772. }
  36773. else if (key.isKeyCode (KeyPress::upKey))
  36774. {
  36775. if (key.getModifiers().isCtrlDown() && ! shiftDown)
  36776. scrollDown();
  36777. #if JUCE_MAC
  36778. else if (key.getModifiers().isCommandDown())
  36779. goToStartOfDocument (shiftDown);
  36780. #endif
  36781. else
  36782. cursorUp (shiftDown);
  36783. }
  36784. else if (key.isKeyCode (KeyPress::downKey))
  36785. {
  36786. if (key.getModifiers().isCtrlDown() && ! shiftDown)
  36787. scrollUp();
  36788. #if JUCE_MAC
  36789. else if (key.getModifiers().isCommandDown())
  36790. goToEndOfDocument (shiftDown);
  36791. #endif
  36792. else
  36793. cursorDown (shiftDown);
  36794. }
  36795. else if (key.isKeyCode (KeyPress::pageDownKey))
  36796. {
  36797. pageDown (shiftDown);
  36798. }
  36799. else if (key.isKeyCode (KeyPress::pageUpKey))
  36800. {
  36801. pageUp (shiftDown);
  36802. }
  36803. else if (key.isKeyCode (KeyPress::homeKey))
  36804. {
  36805. if (moveInWholeWordSteps)
  36806. goToStartOfDocument (shiftDown);
  36807. else
  36808. goToStartOfLine (shiftDown);
  36809. }
  36810. else if (key.isKeyCode (KeyPress::endKey))
  36811. {
  36812. if (moveInWholeWordSteps)
  36813. goToEndOfDocument (shiftDown);
  36814. else
  36815. goToEndOfLine (shiftDown);
  36816. }
  36817. else if (key.isKeyCode (KeyPress::backspaceKey))
  36818. {
  36819. backspace (moveInWholeWordSteps);
  36820. }
  36821. else if (key.isKeyCode (KeyPress::deleteKey))
  36822. {
  36823. deleteForward (moveInWholeWordSteps);
  36824. }
  36825. else if (key == KeyPress (T('c'), ModifierKeys::commandModifier, 0))
  36826. {
  36827. copy();
  36828. }
  36829. else if (key == KeyPress (T('x'), ModifierKeys::commandModifier, 0))
  36830. {
  36831. copyThenCut();
  36832. }
  36833. else if (key == KeyPress (T('v'), ModifierKeys::commandModifier, 0))
  36834. {
  36835. paste();
  36836. }
  36837. else if (key == KeyPress (T('z'), ModifierKeys::commandModifier, 0))
  36838. {
  36839. undo();
  36840. }
  36841. else if (key == KeyPress (T('y'), ModifierKeys::commandModifier, 0)
  36842. || key == KeyPress (T('z'), ModifierKeys::commandModifier | ModifierKeys::shiftModifier, 0))
  36843. {
  36844. redo();
  36845. }
  36846. else if (key == KeyPress (T('a'), ModifierKeys::commandModifier, 0))
  36847. {
  36848. selectAll();
  36849. }
  36850. else if (key == KeyPress::tabKey || key.getTextCharacter() == '\t')
  36851. {
  36852. insertTabAtCaret();
  36853. }
  36854. else if (key == KeyPress::returnKey)
  36855. {
  36856. newTransaction();
  36857. insertTextAtCaret (document.getNewLineCharacters());
  36858. }
  36859. else if (key.isKeyCode (KeyPress::escapeKey))
  36860. {
  36861. newTransaction();
  36862. }
  36863. else if (key.getTextCharacter() >= ' ')
  36864. {
  36865. insertTextAtCaret (String::charToString (key.getTextCharacter()));
  36866. }
  36867. else
  36868. {
  36869. return false;
  36870. }
  36871. return true;
  36872. }
  36873. void CodeEditorComponent::mouseDown (const MouseEvent& e)
  36874. {
  36875. newTransaction();
  36876. dragType = notDragging;
  36877. if (! e.mods.isPopupMenu())
  36878. {
  36879. beginDragAutoRepeat (100);
  36880. moveCaretTo (getPositionAt (e.x, e.y), e.mods.isShiftDown());
  36881. }
  36882. else
  36883. {
  36884. }
  36885. }
  36886. void CodeEditorComponent::mouseDrag (const MouseEvent& e)
  36887. {
  36888. if (! e.mods.isPopupMenu())
  36889. moveCaretTo (getPositionAt (e.x, e.y), true);
  36890. }
  36891. void CodeEditorComponent::mouseUp (const MouseEvent&)
  36892. {
  36893. newTransaction();
  36894. beginDragAutoRepeat (0);
  36895. dragType = notDragging;
  36896. }
  36897. void CodeEditorComponent::mouseDoubleClick (const MouseEvent& e)
  36898. {
  36899. CodeDocument::Position tokenStart (getPositionAt (e.x, e.y));
  36900. CodeDocument::Position tokenEnd (tokenStart);
  36901. if (e.getNumberOfClicks() > 2)
  36902. {
  36903. tokenStart.setLineAndIndex (tokenStart.getLineNumber(), 0);
  36904. tokenEnd.setLineAndIndex (tokenStart.getLineNumber() + 1, 0);
  36905. }
  36906. else
  36907. {
  36908. while (CharacterFunctions::isLetterOrDigit (tokenEnd.getCharacter()))
  36909. tokenEnd.moveBy (1);
  36910. tokenStart = tokenEnd;
  36911. while (tokenStart.getIndexInLine() > 0
  36912. && CharacterFunctions::isLetterOrDigit (tokenStart.movedBy (-1).getCharacter()))
  36913. tokenStart.moveBy (-1);
  36914. }
  36915. moveCaretTo (tokenEnd, false);
  36916. moveCaretTo (tokenStart, true);
  36917. }
  36918. void CodeEditorComponent::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  36919. {
  36920. verticalScrollBar->mouseWheelMove (e, 0, wheelIncrementY);
  36921. horizontalScrollBar->mouseWheelMove (e, wheelIncrementX, 0);
  36922. }
  36923. void CodeEditorComponent::scrollBarMoved (ScrollBar* scrollBarThatHasMoved, const double newRangeStart)
  36924. {
  36925. if (scrollBarThatHasMoved == verticalScrollBar)
  36926. scrollToLineInternal ((int) newRangeStart);
  36927. else
  36928. scrollToColumnInternal (newRangeStart);
  36929. }
  36930. void CodeEditorComponent::setTabSize (const int numSpaces, const bool insertSpaces) throw()
  36931. {
  36932. useSpacesForTabs = insertSpaces;
  36933. if (spacesPerTab != numSpaces)
  36934. {
  36935. spacesPerTab = numSpaces;
  36936. triggerAsyncUpdate();
  36937. }
  36938. }
  36939. int CodeEditorComponent::indexToColumn (int lineNum, int index) const throw()
  36940. {
  36941. const String line (document.getLine (lineNum));
  36942. jassert (index <= line.length());
  36943. int col = 0;
  36944. for (int i = 0; i < index; ++i)
  36945. {
  36946. if (line[i] != T('\t'))
  36947. ++col;
  36948. else
  36949. col += getTabSize() - (col % getTabSize());
  36950. }
  36951. return col;
  36952. }
  36953. int CodeEditorComponent::columnToIndex (int lineNum, int column) const throw()
  36954. {
  36955. const String line (document.getLine (lineNum));
  36956. const int lineLength = line.length();
  36957. int i, col = 0;
  36958. for (i = 0; i < lineLength; ++i)
  36959. {
  36960. if (line[i] != T('\t'))
  36961. ++col;
  36962. else
  36963. col += getTabSize() - (col % getTabSize());
  36964. if (col > column)
  36965. break;
  36966. }
  36967. return i;
  36968. }
  36969. void CodeEditorComponent::setFont (const Font& newFont)
  36970. {
  36971. font = newFont;
  36972. charWidth = font.getStringWidthFloat (T("0"));
  36973. lineHeight = roundToInt (font.getHeight());
  36974. resized();
  36975. }
  36976. void CodeEditorComponent::resetToDefaultColours()
  36977. {
  36978. coloursForTokenCategories.clear();
  36979. if (codeTokeniser != 0)
  36980. {
  36981. for (int i = codeTokeniser->getTokenTypes().size(); --i >= 0;)
  36982. setColourForTokenType (i, codeTokeniser->getDefaultColour (i));
  36983. }
  36984. }
  36985. void CodeEditorComponent::setColourForTokenType (const int tokenType, const Colour& colour)
  36986. {
  36987. jassert (tokenType < 256);
  36988. while (coloursForTokenCategories.size() < tokenType)
  36989. coloursForTokenCategories.add (Colours::black);
  36990. coloursForTokenCategories.set (tokenType, colour);
  36991. repaint();
  36992. }
  36993. const Colour CodeEditorComponent::getColourForTokenType (const int tokenType) const throw()
  36994. {
  36995. if (((unsigned int) tokenType) >= (unsigned int) coloursForTokenCategories.size())
  36996. return findColour (CodeEditorComponent::defaultTextColourId);
  36997. return coloursForTokenCategories.getReference (tokenType);
  36998. }
  36999. void CodeEditorComponent::clearCachedIterators (const int firstLineToBeInvalid) throw()
  37000. {
  37001. int i;
  37002. for (i = cachedIterators.size(); --i >= 0;)
  37003. if (cachedIterators.getUnchecked (i)->getLine() < firstLineToBeInvalid)
  37004. break;
  37005. cachedIterators.removeRange (jmax (0, i - 1), cachedIterators.size());
  37006. }
  37007. void CodeEditorComponent::updateCachedIterators (int maxLineNum)
  37008. {
  37009. const int maxNumCachedPositions = 5000;
  37010. const int linesBetweenCachedSources = jmax (10, document.getNumLines() / maxNumCachedPositions);
  37011. if (cachedIterators.size() == 0)
  37012. cachedIterators.add (new CodeDocument::Iterator (&document));
  37013. if (codeTokeniser == 0)
  37014. return;
  37015. for (;;)
  37016. {
  37017. CodeDocument::Iterator* last = cachedIterators.getLast();
  37018. if (last->getLine() >= maxLineNum)
  37019. break;
  37020. CodeDocument::Iterator* t = new CodeDocument::Iterator (*last);
  37021. cachedIterators.add (t);
  37022. const int targetLine = last->getLine() + linesBetweenCachedSources;
  37023. for (;;)
  37024. {
  37025. codeTokeniser->readNextToken (*t);
  37026. if (t->getLine() >= targetLine)
  37027. break;
  37028. if (t->isEOF())
  37029. return;
  37030. }
  37031. }
  37032. }
  37033. void CodeEditorComponent::getIteratorForPosition (int position, CodeDocument::Iterator& source)
  37034. {
  37035. if (codeTokeniser == 0)
  37036. return;
  37037. for (int i = cachedIterators.size(); --i >= 0;)
  37038. {
  37039. CodeDocument::Iterator* t = cachedIterators.getUnchecked (i);
  37040. if (t->getPosition() <= position)
  37041. {
  37042. source = *t;
  37043. break;
  37044. }
  37045. }
  37046. while (source.getPosition() < position)
  37047. {
  37048. const CodeDocument::Iterator original (source);
  37049. codeTokeniser->readNextToken (source);
  37050. if (source.getPosition() > position || source.isEOF())
  37051. {
  37052. source = original;
  37053. break;
  37054. }
  37055. }
  37056. }
  37057. END_JUCE_NAMESPACE
  37058. /*** End of inlined file: juce_CodeEditorComponent.cpp ***/
  37059. /*** Start of inlined file: juce_CPlusPlusCodeTokeniser.cpp ***/
  37060. BEGIN_JUCE_NAMESPACE
  37061. CPlusPlusCodeTokeniser::CPlusPlusCodeTokeniser()
  37062. {
  37063. }
  37064. CPlusPlusCodeTokeniser::~CPlusPlusCodeTokeniser()
  37065. {
  37066. }
  37067. namespace CppTokeniser
  37068. {
  37069. static bool isIdentifierStart (const tchar c) throw()
  37070. {
  37071. return CharacterFunctions::isLetter (c)
  37072. || c == T('_') || c == T('@');
  37073. }
  37074. static bool isIdentifierBody (const tchar c) throw()
  37075. {
  37076. return CharacterFunctions::isLetter (c)
  37077. || CharacterFunctions::isDigit (c)
  37078. || c == T('_') || c == T('@');
  37079. }
  37080. static int parseIdentifier (CodeDocument::Iterator& source) throw()
  37081. {
  37082. static const tchar* keywords2Char[] =
  37083. { T("if"), T("do"), T("or"), 0 };
  37084. static const tchar* keywords3Char[] =
  37085. { T("for"), T("int"), T("new"), T("try"), T("xor"), T("and"), T("asm"), T("not"), 0 };
  37086. static const tchar* keywords4Char[] =
  37087. { T("bool"), T("void"), T("this"), T("true"), T("long"), T("else"), T("char"),
  37088. T("enum"), T("case"), T("goto"), T("auto"), 0 };
  37089. static const tchar* keywords5Char[] =
  37090. { T("while"), T("bitor"), T("break"), T("catch"), T("class"), T("compl"), T("const"), T("false"),
  37091. T("float"), T("short"), T("throw"), T("union"), T("using"), T("or_eq"), 0 };
  37092. static const tchar* keywords6Char[] =
  37093. { T("return"), T("struct"), T("and_eq"), T("bitand"), T("delete"), T("double"), T("extern"),
  37094. T("friend"), T("inline"), T("not_eq"), T("public"), T("sizeof"), T("static"), T("signed"),
  37095. T("switch"), T("typeid"), T("wchar_t"), T("xor_eq"), 0};
  37096. static const tchar* keywordsOther[] =
  37097. { T("const_cast"), T("continue"), T("default"), T("explicit"), T("mutable"), T("namespace"),
  37098. T("operator"), T("private"), T("protected"), T("register"), T("reinterpret_cast"), T("static_cast"),
  37099. T("template"), T("typedef"), T("typename"), T("unsigned"), T("virtual"), T("volatile"),
  37100. T("@implementation"), T("@interface"), T("@end"), T("@synthesize"), T("@dynamic"), T("@public"),
  37101. T("@private"), T("@property"), T("@protected"), T("@class"), 0 };
  37102. int tokenLength = 0;
  37103. tchar possibleIdentifier [19];
  37104. while (isIdentifierBody (source.peekNextChar()))
  37105. {
  37106. const tchar c = source.nextChar();
  37107. if (tokenLength < numElementsInArray (possibleIdentifier) - 1)
  37108. possibleIdentifier [tokenLength] = c;
  37109. ++tokenLength;
  37110. }
  37111. if (tokenLength > 1 && tokenLength <= 16)
  37112. {
  37113. possibleIdentifier [tokenLength] = 0;
  37114. const tchar** k;
  37115. switch (tokenLength)
  37116. {
  37117. case 2: k = keywords2Char; break;
  37118. case 3: k = keywords3Char; break;
  37119. case 4: k = keywords4Char; break;
  37120. case 5: k = keywords5Char; break;
  37121. case 6: k = keywords6Char; break;
  37122. default: k = keywordsOther; break;
  37123. }
  37124. int i = 0;
  37125. while (k[i] != 0)
  37126. {
  37127. if (k[i][0] == possibleIdentifier[0] && CharacterFunctions::compare (k[i], possibleIdentifier) == 0)
  37128. return CPlusPlusCodeTokeniser::tokenType_builtInKeyword;
  37129. ++i;
  37130. }
  37131. }
  37132. return CPlusPlusCodeTokeniser::tokenType_identifier;
  37133. }
  37134. static bool skipNumberSuffix (CodeDocument::Iterator& source)
  37135. {
  37136. const juce_wchar c = source.peekNextChar();
  37137. if (c == 'l' || c == 'L' || c == 'u' || c == 'U')
  37138. source.skip();
  37139. if (CharacterFunctions::isLetterOrDigit (source.peekNextChar()))
  37140. return false;
  37141. return true;
  37142. }
  37143. static bool isHexDigit (const juce_wchar c) throw()
  37144. {
  37145. return (c >= '0' && c <= '9')
  37146. || (c >= 'a' && c <= 'f')
  37147. || (c >= 'A' && c <= 'F');
  37148. }
  37149. static bool parseHexLiteral (CodeDocument::Iterator& source) throw()
  37150. {
  37151. if (source.nextChar() != '0')
  37152. return false;
  37153. juce_wchar c = source.nextChar();
  37154. if (c != 'x' && c != 'X')
  37155. return false;
  37156. int numDigits = 0;
  37157. while (isHexDigit (source.peekNextChar()))
  37158. {
  37159. ++numDigits;
  37160. source.skip();
  37161. }
  37162. if (numDigits == 0)
  37163. return false;
  37164. return skipNumberSuffix (source);
  37165. }
  37166. static bool isOctalDigit (const juce_wchar c) throw()
  37167. {
  37168. return c >= '0' && c <= '7';
  37169. }
  37170. static bool parseOctalLiteral (CodeDocument::Iterator& source) throw()
  37171. {
  37172. if (source.nextChar() != '0')
  37173. return false;
  37174. if (! isOctalDigit (source.nextChar()))
  37175. return false;
  37176. while (isOctalDigit (source.peekNextChar()))
  37177. source.skip();
  37178. return skipNumberSuffix (source);
  37179. }
  37180. static bool isDecimalDigit (const juce_wchar c) throw()
  37181. {
  37182. return c >= '0' && c <= '9';
  37183. }
  37184. static bool parseDecimalLiteral (CodeDocument::Iterator& source) throw()
  37185. {
  37186. int numChars = 0;
  37187. while (isDecimalDigit (source.peekNextChar()))
  37188. {
  37189. ++numChars;
  37190. source.skip();
  37191. }
  37192. if (numChars == 0)
  37193. return false;
  37194. return skipNumberSuffix (source);
  37195. }
  37196. static bool parseFloatLiteral (CodeDocument::Iterator& source) throw()
  37197. {
  37198. int numDigits = 0;
  37199. while (isDecimalDigit (source.peekNextChar()))
  37200. {
  37201. source.skip();
  37202. ++numDigits;
  37203. }
  37204. const bool hasPoint = (source.peekNextChar() == '.');
  37205. if (hasPoint)
  37206. {
  37207. source.skip();
  37208. while (isDecimalDigit (source.peekNextChar()))
  37209. {
  37210. source.skip();
  37211. ++numDigits;
  37212. }
  37213. }
  37214. if (numDigits == 0)
  37215. return false;
  37216. juce_wchar c = source.peekNextChar();
  37217. const bool hasExponent = (c == 'e' || c == 'E');
  37218. if (hasExponent)
  37219. {
  37220. source.skip();
  37221. c = source.peekNextChar();
  37222. if (c == '+' || c == '-')
  37223. source.skip();
  37224. int numExpDigits = 0;
  37225. while (isDecimalDigit (source.peekNextChar()))
  37226. {
  37227. source.skip();
  37228. ++numExpDigits;
  37229. }
  37230. if (numExpDigits == 0)
  37231. return false;
  37232. }
  37233. c = source.peekNextChar();
  37234. if (c == 'f' || c == 'F')
  37235. source.skip();
  37236. else if (! (hasExponent || hasPoint))
  37237. return false;
  37238. return true;
  37239. }
  37240. static int parseNumber (CodeDocument::Iterator& source)
  37241. {
  37242. const CodeDocument::Iterator original (source);
  37243. if (parseFloatLiteral (source))
  37244. return CPlusPlusCodeTokeniser::tokenType_floatLiteral;
  37245. source = original;
  37246. if (parseHexLiteral (source))
  37247. return CPlusPlusCodeTokeniser::tokenType_integerLiteral;
  37248. source = original;
  37249. if (parseOctalLiteral (source))
  37250. return CPlusPlusCodeTokeniser::tokenType_integerLiteral;
  37251. source = original;
  37252. if (parseDecimalLiteral (source))
  37253. return CPlusPlusCodeTokeniser::tokenType_integerLiteral;
  37254. source = original;
  37255. source.skip();
  37256. return CPlusPlusCodeTokeniser::tokenType_error;
  37257. }
  37258. static void skipQuotedString (CodeDocument::Iterator& source) throw()
  37259. {
  37260. const juce_wchar quote = source.nextChar();
  37261. for (;;)
  37262. {
  37263. const juce_wchar c = source.nextChar();
  37264. if (c == quote || c == 0)
  37265. break;
  37266. if (c == '\\')
  37267. source.skip();
  37268. }
  37269. }
  37270. static void skipComment (CodeDocument::Iterator& source) throw()
  37271. {
  37272. bool lastWasStar = false;
  37273. for (;;)
  37274. {
  37275. const juce_wchar c = source.nextChar();
  37276. if (c == 0 || (c == T('/') && lastWasStar))
  37277. break;
  37278. lastWasStar = (c == '*');
  37279. }
  37280. }
  37281. }
  37282. int CPlusPlusCodeTokeniser::readNextToken (CodeDocument::Iterator& source)
  37283. {
  37284. int result = tokenType_error;
  37285. source.skipWhitespace();
  37286. tchar firstChar = source.peekNextChar();
  37287. switch (firstChar)
  37288. {
  37289. case 0:
  37290. source.skip();
  37291. break;
  37292. case T('0'):
  37293. case T('1'):
  37294. case T('2'):
  37295. case T('3'):
  37296. case T('4'):
  37297. case T('5'):
  37298. case T('6'):
  37299. case T('7'):
  37300. case T('8'):
  37301. case T('9'):
  37302. result = CppTokeniser::parseNumber (source);
  37303. break;
  37304. case T('.'):
  37305. result = CppTokeniser::parseNumber (source);
  37306. if (result == tokenType_error)
  37307. result = tokenType_punctuation;
  37308. break;
  37309. case T(','):
  37310. case T(';'):
  37311. case T(':'):
  37312. source.skip();
  37313. result = tokenType_punctuation;
  37314. break;
  37315. case T('('):
  37316. case T(')'):
  37317. case T('{'):
  37318. case T('}'):
  37319. case T('['):
  37320. case T(']'):
  37321. source.skip();
  37322. result = tokenType_bracket;
  37323. break;
  37324. case T('"'):
  37325. case T('\''):
  37326. CppTokeniser::skipQuotedString (source);
  37327. result = tokenType_stringLiteral;
  37328. break;
  37329. case T('+'):
  37330. result = tokenType_operator;
  37331. source.skip();
  37332. if (source.peekNextChar() == T('+'))
  37333. source.skip();
  37334. else if (source.peekNextChar() == T('='))
  37335. source.skip();
  37336. break;
  37337. case T('-'):
  37338. source.skip();
  37339. result = CppTokeniser::parseNumber (source);
  37340. if (result == tokenType_error)
  37341. {
  37342. result = tokenType_operator;
  37343. if (source.peekNextChar() == T('-'))
  37344. source.skip();
  37345. else if (source.peekNextChar() == T('='))
  37346. source.skip();
  37347. }
  37348. break;
  37349. case T('*'):
  37350. case T('%'):
  37351. case T('='):
  37352. case T('!'):
  37353. result = tokenType_operator;
  37354. source.skip();
  37355. if (source.peekNextChar() == T('='))
  37356. source.skip();
  37357. break;
  37358. case T('/'):
  37359. result = tokenType_operator;
  37360. source.skip();
  37361. if (source.peekNextChar() == T('='))
  37362. {
  37363. source.skip();
  37364. }
  37365. else if (source.peekNextChar() == T('/'))
  37366. {
  37367. result = tokenType_comment;
  37368. source.skipToEndOfLine();
  37369. }
  37370. else if (source.peekNextChar() == T('*'))
  37371. {
  37372. source.skip();
  37373. result = tokenType_comment;
  37374. CppTokeniser::skipComment (source);
  37375. }
  37376. break;
  37377. case T('?'):
  37378. case T('~'):
  37379. source.skip();
  37380. result = tokenType_operator;
  37381. break;
  37382. case T('<'):
  37383. source.skip();
  37384. result = tokenType_operator;
  37385. if (source.peekNextChar() == T('='))
  37386. {
  37387. source.skip();
  37388. }
  37389. else if (source.peekNextChar() == T('<'))
  37390. {
  37391. source.skip();
  37392. if (source.peekNextChar() == T('='))
  37393. source.skip();
  37394. }
  37395. break;
  37396. case T('>'):
  37397. source.skip();
  37398. result = tokenType_operator;
  37399. if (source.peekNextChar() == T('='))
  37400. {
  37401. source.skip();
  37402. }
  37403. else if (source.peekNextChar() == T('<'))
  37404. {
  37405. source.skip();
  37406. if (source.peekNextChar() == T('='))
  37407. source.skip();
  37408. }
  37409. break;
  37410. case T('|'):
  37411. source.skip();
  37412. result = tokenType_operator;
  37413. if (source.peekNextChar() == T('='))
  37414. {
  37415. source.skip();
  37416. }
  37417. else if (source.peekNextChar() == T('|'))
  37418. {
  37419. source.skip();
  37420. if (source.peekNextChar() == T('='))
  37421. source.skip();
  37422. }
  37423. break;
  37424. case T('&'):
  37425. source.skip();
  37426. result = tokenType_operator;
  37427. if (source.peekNextChar() == T('='))
  37428. {
  37429. source.skip();
  37430. }
  37431. else if (source.peekNextChar() == T('&'))
  37432. {
  37433. source.skip();
  37434. if (source.peekNextChar() == T('='))
  37435. source.skip();
  37436. }
  37437. break;
  37438. case T('^'):
  37439. source.skip();
  37440. result = tokenType_operator;
  37441. if (source.peekNextChar() == T('='))
  37442. {
  37443. source.skip();
  37444. }
  37445. else if (source.peekNextChar() == T('^'))
  37446. {
  37447. source.skip();
  37448. if (source.peekNextChar() == T('='))
  37449. source.skip();
  37450. }
  37451. break;
  37452. case T('#'):
  37453. result = tokenType_preprocessor;
  37454. source.skipToEndOfLine();
  37455. break;
  37456. default:
  37457. if (CppTokeniser::isIdentifierStart (firstChar))
  37458. result = CppTokeniser::parseIdentifier (source);
  37459. else
  37460. source.skip();
  37461. break;
  37462. }
  37463. //jassert (result != tokenType_unknown);
  37464. return result;
  37465. }
  37466. const StringArray CPlusPlusCodeTokeniser::getTokenTypes()
  37467. {
  37468. StringArray s;
  37469. s.add ("Error");
  37470. s.add ("Comment");
  37471. s.add ("C++ keyword");
  37472. s.add ("Identifier");
  37473. s.add ("Integer literal");
  37474. s.add ("Float literal");
  37475. s.add ("String literal");
  37476. s.add ("Operator");
  37477. s.add ("Bracket");
  37478. s.add ("Punctuation");
  37479. s.add ("Preprocessor line");
  37480. return s;
  37481. }
  37482. const Colour CPlusPlusCodeTokeniser::getDefaultColour (const int tokenType)
  37483. {
  37484. const uint32 colours[] =
  37485. {
  37486. 0xffcc0000, // error
  37487. 0xff00aa00, // comment
  37488. 0xff0000cc, // keyword
  37489. 0xff000000, // identifier
  37490. 0xff880000, // int literal
  37491. 0xff885500, // float literal
  37492. 0xff990099, // string literal
  37493. 0xff225500, // operator
  37494. 0xff000055, // bracket
  37495. 0xff004400, // punctuation
  37496. 0xff660000 // preprocessor
  37497. };
  37498. if (tokenType >= 0 && tokenType < numElementsInArray (colours))
  37499. return Colour (colours [tokenType]);
  37500. return Colours::black;
  37501. }
  37502. END_JUCE_NAMESPACE
  37503. /*** End of inlined file: juce_CPlusPlusCodeTokeniser.cpp ***/
  37504. /*** Start of inlined file: juce_ComboBox.cpp ***/
  37505. BEGIN_JUCE_NAMESPACE
  37506. ComboBox::ComboBox (const String& name)
  37507. : Component (name),
  37508. lastCurrentId (0),
  37509. isButtonDown (false),
  37510. separatorPending (false),
  37511. menuActive (false),
  37512. label (0)
  37513. {
  37514. noChoicesMessage = TRANS("(no choices)");
  37515. setRepaintsOnMouseActivity (true);
  37516. lookAndFeelChanged();
  37517. currentId.addListener (this);
  37518. }
  37519. ComboBox::~ComboBox()
  37520. {
  37521. currentId.removeListener (this);
  37522. if (menuActive)
  37523. PopupMenu::dismissAllActiveMenus();
  37524. deleteAllChildren();
  37525. }
  37526. void ComboBox::setEditableText (const bool isEditable)
  37527. {
  37528. label->setEditable (isEditable, isEditable, false);
  37529. setWantsKeyboardFocus (! isEditable);
  37530. resized();
  37531. }
  37532. bool ComboBox::isTextEditable() const throw()
  37533. {
  37534. return label->isEditable();
  37535. }
  37536. void ComboBox::setJustificationType (const Justification& justification) throw()
  37537. {
  37538. label->setJustificationType (justification);
  37539. }
  37540. const Justification ComboBox::getJustificationType() const throw()
  37541. {
  37542. return label->getJustificationType();
  37543. }
  37544. void ComboBox::setTooltip (const String& newTooltip)
  37545. {
  37546. SettableTooltipClient::setTooltip (newTooltip);
  37547. label->setTooltip (newTooltip);
  37548. }
  37549. void ComboBox::addItem (const String& newItemText,
  37550. const int newItemId) throw()
  37551. {
  37552. // you can't add empty strings to the list..
  37553. jassert (newItemText.isNotEmpty());
  37554. // IDs must be non-zero, as zero is used to indicate a lack of selecion.
  37555. jassert (newItemId != 0);
  37556. // you shouldn't use duplicate item IDs!
  37557. jassert (getItemForId (newItemId) == 0);
  37558. if (newItemText.isNotEmpty() && newItemId != 0)
  37559. {
  37560. if (separatorPending)
  37561. {
  37562. separatorPending = false;
  37563. ItemInfo* const item = new ItemInfo();
  37564. item->itemId = 0;
  37565. item->isEnabled = false;
  37566. item->isHeading = false;
  37567. items.add (item);
  37568. }
  37569. ItemInfo* const item = new ItemInfo();
  37570. item->name = newItemText;
  37571. item->itemId = newItemId;
  37572. item->isEnabled = true;
  37573. item->isHeading = false;
  37574. items.add (item);
  37575. }
  37576. }
  37577. void ComboBox::addSeparator() throw()
  37578. {
  37579. separatorPending = (items.size() > 0);
  37580. }
  37581. void ComboBox::addSectionHeading (const String& headingName) throw()
  37582. {
  37583. // you can't add empty strings to the list..
  37584. jassert (headingName.isNotEmpty());
  37585. if (headingName.isNotEmpty())
  37586. {
  37587. if (separatorPending)
  37588. {
  37589. separatorPending = false;
  37590. ItemInfo* const item = new ItemInfo();
  37591. item->itemId = 0;
  37592. item->isEnabled = false;
  37593. item->isHeading = false;
  37594. items.add (item);
  37595. }
  37596. ItemInfo* const item = new ItemInfo();
  37597. item->name = headingName;
  37598. item->itemId = 0;
  37599. item->isEnabled = true;
  37600. item->isHeading = true;
  37601. items.add (item);
  37602. }
  37603. }
  37604. void ComboBox::setItemEnabled (const int itemId,
  37605. const bool shouldBeEnabled) throw()
  37606. {
  37607. ItemInfo* const item = getItemForId (itemId);
  37608. if (item != 0)
  37609. item->isEnabled = shouldBeEnabled;
  37610. }
  37611. void ComboBox::changeItemText (const int itemId,
  37612. const String& newText) throw()
  37613. {
  37614. ItemInfo* const item = getItemForId (itemId);
  37615. jassert (item != 0);
  37616. if (item != 0)
  37617. item->name = newText;
  37618. }
  37619. void ComboBox::clear (const bool dontSendChangeMessage)
  37620. {
  37621. items.clear();
  37622. separatorPending = false;
  37623. if (! label->isEditable())
  37624. setSelectedItemIndex (-1, dontSendChangeMessage);
  37625. }
  37626. bool ComboBox::ItemInfo::isSeparator() const throw()
  37627. {
  37628. return name.isEmpty();
  37629. }
  37630. bool ComboBox::ItemInfo::isRealItem() const throw()
  37631. {
  37632. return ! (isHeading || name.isEmpty());
  37633. }
  37634. ComboBox::ItemInfo* ComboBox::getItemForId (const int itemId) const throw()
  37635. {
  37636. if (itemId != 0)
  37637. {
  37638. for (int i = items.size(); --i >= 0;)
  37639. if (items.getUnchecked(i)->itemId == itemId)
  37640. return items.getUnchecked(i);
  37641. }
  37642. return 0;
  37643. }
  37644. ComboBox::ItemInfo* ComboBox::getItemForIndex (const int index) const throw()
  37645. {
  37646. int n = 0;
  37647. for (int i = 0; i < items.size(); ++i)
  37648. {
  37649. ItemInfo* const item = items.getUnchecked(i);
  37650. if (item->isRealItem())
  37651. if (n++ == index)
  37652. return item;
  37653. }
  37654. return 0;
  37655. }
  37656. int ComboBox::getNumItems() const throw()
  37657. {
  37658. int n = 0;
  37659. for (int i = items.size(); --i >= 0;)
  37660. if (items.getUnchecked(i)->isRealItem())
  37661. ++n;
  37662. return n;
  37663. }
  37664. const String ComboBox::getItemText (const int index) const throw()
  37665. {
  37666. const ItemInfo* const item = getItemForIndex (index);
  37667. if (item != 0)
  37668. return item->name;
  37669. return String::empty;
  37670. }
  37671. int ComboBox::getItemId (const int index) const throw()
  37672. {
  37673. const ItemInfo* const item = getItemForIndex (index);
  37674. return (item != 0) ? item->itemId : 0;
  37675. }
  37676. int ComboBox::indexOfItemId (const int itemId) const throw()
  37677. {
  37678. int n = 0;
  37679. for (int i = 0; i < items.size(); ++i)
  37680. {
  37681. const ItemInfo* const item = items.getUnchecked(i);
  37682. if (item->isRealItem())
  37683. {
  37684. if (item->itemId == itemId)
  37685. return n;
  37686. ++n;
  37687. }
  37688. }
  37689. return -1;
  37690. }
  37691. int ComboBox::getSelectedItemIndex() const throw()
  37692. {
  37693. int index = indexOfItemId (currentId.getValue());
  37694. if (getText() != getItemText (index))
  37695. index = -1;
  37696. return index;
  37697. }
  37698. void ComboBox::setSelectedItemIndex (const int index,
  37699. const bool dontSendChangeMessage) throw()
  37700. {
  37701. setSelectedId (getItemId (index), dontSendChangeMessage);
  37702. }
  37703. int ComboBox::getSelectedId() const throw()
  37704. {
  37705. const ItemInfo* const item = getItemForId (currentId.getValue());
  37706. return (item != 0 && getText() == item->name)
  37707. ? item->itemId
  37708. : 0;
  37709. }
  37710. void ComboBox::setSelectedId (const int newItemId,
  37711. const bool dontSendChangeMessage) throw()
  37712. {
  37713. const ItemInfo* const item = getItemForId (newItemId);
  37714. const String newItemText (item != 0 ? item->name : String::empty);
  37715. if (lastCurrentId != newItemId || label->getText() != newItemText)
  37716. {
  37717. if (! dontSendChangeMessage)
  37718. triggerAsyncUpdate();
  37719. label->setText (newItemText, false);
  37720. lastCurrentId = newItemId;
  37721. currentId = newItemId;
  37722. repaint(); // for the benefit of the 'none selected' text
  37723. }
  37724. }
  37725. void ComboBox::valueChanged (Value&)
  37726. {
  37727. if (lastCurrentId != (int) currentId.getValue())
  37728. setSelectedId (currentId.getValue(), false);
  37729. }
  37730. const String ComboBox::getText() const throw()
  37731. {
  37732. return label->getText();
  37733. }
  37734. void ComboBox::setText (const String& newText,
  37735. const bool dontSendChangeMessage) throw()
  37736. {
  37737. for (int i = items.size(); --i >= 0;)
  37738. {
  37739. const ItemInfo* const item = items.getUnchecked(i);
  37740. if (item->isRealItem()
  37741. && item->name == newText)
  37742. {
  37743. setSelectedId (item->itemId, dontSendChangeMessage);
  37744. return;
  37745. }
  37746. }
  37747. lastCurrentId = 0;
  37748. currentId = 0;
  37749. if (label->getText() != newText)
  37750. {
  37751. label->setText (newText, false);
  37752. if (! dontSendChangeMessage)
  37753. triggerAsyncUpdate();
  37754. }
  37755. repaint();
  37756. }
  37757. void ComboBox::showEditor()
  37758. {
  37759. jassert (isTextEditable()); // you probably shouldn't do this to a non-editable combo box?
  37760. label->showEditor();
  37761. }
  37762. void ComboBox::setTextWhenNothingSelected (const String& newMessage) throw()
  37763. {
  37764. textWhenNothingSelected = newMessage;
  37765. repaint();
  37766. }
  37767. const String ComboBox::getTextWhenNothingSelected() const throw()
  37768. {
  37769. return textWhenNothingSelected;
  37770. }
  37771. void ComboBox::setTextWhenNoChoicesAvailable (const String& newMessage) throw()
  37772. {
  37773. noChoicesMessage = newMessage;
  37774. }
  37775. const String ComboBox::getTextWhenNoChoicesAvailable() const throw()
  37776. {
  37777. return noChoicesMessage;
  37778. }
  37779. void ComboBox::paint (Graphics& g)
  37780. {
  37781. getLookAndFeel().drawComboBox (g,
  37782. getWidth(),
  37783. getHeight(),
  37784. isButtonDown,
  37785. label->getRight(),
  37786. 0,
  37787. getWidth() - label->getRight(),
  37788. getHeight(),
  37789. *this);
  37790. if (textWhenNothingSelected.isNotEmpty()
  37791. && label->getText().isEmpty()
  37792. && ! label->isBeingEdited())
  37793. {
  37794. g.setColour (findColour (textColourId).withMultipliedAlpha (0.5f));
  37795. g.setFont (label->getFont());
  37796. g.drawFittedText (textWhenNothingSelected,
  37797. label->getX() + 2, label->getY() + 1,
  37798. label->getWidth() - 4, label->getHeight() - 2,
  37799. label->getJustificationType(),
  37800. jmax (1, (int) (label->getHeight() / label->getFont().getHeight())));
  37801. }
  37802. }
  37803. void ComboBox::resized()
  37804. {
  37805. if (getHeight() > 0 && getWidth() > 0)
  37806. getLookAndFeel().positionComboBoxText (*this, *label);
  37807. }
  37808. void ComboBox::enablementChanged()
  37809. {
  37810. repaint();
  37811. }
  37812. void ComboBox::lookAndFeelChanged()
  37813. {
  37814. repaint();
  37815. Label* const newLabel = getLookAndFeel().createComboBoxTextBox (*this);
  37816. if (label != 0)
  37817. {
  37818. newLabel->setEditable (label->isEditable());
  37819. newLabel->setJustificationType (label->getJustificationType());
  37820. newLabel->setTooltip (label->getTooltip());
  37821. newLabel->setText (label->getText(), false);
  37822. }
  37823. delete label;
  37824. label = newLabel;
  37825. addAndMakeVisible (newLabel);
  37826. newLabel->addListener (this);
  37827. newLabel->addMouseListener (this, false);
  37828. newLabel->setColour (Label::backgroundColourId, Colours::transparentBlack);
  37829. newLabel->setColour (Label::textColourId, findColour (ComboBox::textColourId));
  37830. newLabel->setColour (TextEditor::textColourId, findColour (ComboBox::textColourId));
  37831. newLabel->setColour (TextEditor::backgroundColourId, Colours::transparentBlack);
  37832. newLabel->setColour (TextEditor::highlightColourId, findColour (TextEditor::highlightColourId));
  37833. newLabel->setColour (TextEditor::outlineColourId, Colours::transparentBlack);
  37834. resized();
  37835. }
  37836. void ComboBox::colourChanged()
  37837. {
  37838. lookAndFeelChanged();
  37839. }
  37840. bool ComboBox::keyPressed (const KeyPress& key)
  37841. {
  37842. bool used = false;
  37843. if (key.isKeyCode (KeyPress::upKey)
  37844. || key.isKeyCode (KeyPress::leftKey))
  37845. {
  37846. setSelectedItemIndex (jmax (0, getSelectedItemIndex() - 1));
  37847. used = true;
  37848. }
  37849. else if (key.isKeyCode (KeyPress::downKey)
  37850. || key.isKeyCode (KeyPress::rightKey))
  37851. {
  37852. setSelectedItemIndex (jmin (getSelectedItemIndex() + 1, getNumItems() - 1));
  37853. used = true;
  37854. }
  37855. else if (key.isKeyCode (KeyPress::returnKey))
  37856. {
  37857. showPopup();
  37858. used = true;
  37859. }
  37860. return used;
  37861. }
  37862. bool ComboBox::keyStateChanged (const bool isKeyDown)
  37863. {
  37864. // only forward key events that aren't used by this component
  37865. return isKeyDown
  37866. && (KeyPress::isKeyCurrentlyDown (KeyPress::upKey)
  37867. || KeyPress::isKeyCurrentlyDown (KeyPress::leftKey)
  37868. || KeyPress::isKeyCurrentlyDown (KeyPress::downKey)
  37869. || KeyPress::isKeyCurrentlyDown (KeyPress::rightKey));
  37870. }
  37871. void ComboBox::focusGained (FocusChangeType)
  37872. {
  37873. repaint();
  37874. }
  37875. void ComboBox::focusLost (FocusChangeType)
  37876. {
  37877. repaint();
  37878. }
  37879. void ComboBox::labelTextChanged (Label*)
  37880. {
  37881. triggerAsyncUpdate();
  37882. }
  37883. void ComboBox::showPopup()
  37884. {
  37885. if (! menuActive)
  37886. {
  37887. const int selectedId = getSelectedId();
  37888. ComponentDeletionWatcher deletionWatcher (this);
  37889. PopupMenu menu;
  37890. menu.setLookAndFeel (&getLookAndFeel());
  37891. for (int i = 0; i < items.size(); ++i)
  37892. {
  37893. const ItemInfo* const item = items.getUnchecked(i);
  37894. if (item->isSeparator())
  37895. menu.addSeparator();
  37896. else if (item->isHeading)
  37897. menu.addSectionHeader (item->name);
  37898. else
  37899. menu.addItem (item->itemId, item->name,
  37900. item->isEnabled, item->itemId == selectedId);
  37901. }
  37902. if (items.size() == 0)
  37903. menu.addItem (1, noChoicesMessage, false);
  37904. const int itemHeight = jlimit (12, 24, getHeight());
  37905. menuActive = true;
  37906. const int resultId = menu.showAt (this, selectedId,
  37907. getWidth(), 1, itemHeight);
  37908. if (deletionWatcher.hasBeenDeleted())
  37909. return;
  37910. menuActive = false;
  37911. if (resultId != 0)
  37912. setSelectedId (resultId);
  37913. }
  37914. }
  37915. void ComboBox::mouseDown (const MouseEvent& e)
  37916. {
  37917. beginDragAutoRepeat (300);
  37918. isButtonDown = isEnabled();
  37919. if (isButtonDown
  37920. && (e.eventComponent == this || ! label->isEditable()))
  37921. {
  37922. showPopup();
  37923. }
  37924. }
  37925. void ComboBox::mouseDrag (const MouseEvent& e)
  37926. {
  37927. beginDragAutoRepeat (50);
  37928. if (isButtonDown && ! e.mouseWasClicked())
  37929. showPopup();
  37930. }
  37931. void ComboBox::mouseUp (const MouseEvent& e2)
  37932. {
  37933. if (isButtonDown)
  37934. {
  37935. isButtonDown = false;
  37936. repaint();
  37937. const MouseEvent e (e2.getEventRelativeTo (this));
  37938. if (reallyContains (e.x, e.y, true)
  37939. && (e2.eventComponent == this || ! label->isEditable()))
  37940. {
  37941. showPopup();
  37942. }
  37943. }
  37944. }
  37945. void ComboBox::addListener (ComboBoxListener* const listener) throw()
  37946. {
  37947. jassert (listener != 0);
  37948. if (listener != 0)
  37949. listeners.add (listener);
  37950. }
  37951. void ComboBox::removeListener (ComboBoxListener* const listener) throw()
  37952. {
  37953. listeners.removeValue (listener);
  37954. }
  37955. void ComboBox::handleAsyncUpdate()
  37956. {
  37957. for (int i = listeners.size(); --i >= 0;)
  37958. {
  37959. ((ComboBoxListener*) listeners.getUnchecked (i))->comboBoxChanged (this);
  37960. i = jmin (i, listeners.size());
  37961. }
  37962. }
  37963. END_JUCE_NAMESPACE
  37964. /*** End of inlined file: juce_ComboBox.cpp ***/
  37965. /*** Start of inlined file: juce_Label.cpp ***/
  37966. BEGIN_JUCE_NAMESPACE
  37967. Label::Label (const String& componentName,
  37968. const String& labelText)
  37969. : Component (componentName),
  37970. textValue (labelText),
  37971. lastTextValue (labelText),
  37972. font (15.0f),
  37973. justification (Justification::centredLeft),
  37974. ownerComponent (0),
  37975. horizontalBorderSize (5),
  37976. verticalBorderSize (1),
  37977. minimumHorizontalScale (0.7f),
  37978. editSingleClick (false),
  37979. editDoubleClick (false),
  37980. lossOfFocusDiscardsChanges (false)
  37981. {
  37982. setColour (TextEditor::textColourId, Colours::black);
  37983. setColour (TextEditor::backgroundColourId, Colours::transparentBlack);
  37984. setColour (TextEditor::outlineColourId, Colours::transparentBlack);
  37985. textValue.addListener (this);
  37986. }
  37987. Label::~Label()
  37988. {
  37989. textValue.removeListener (this);
  37990. if (ownerComponent != 0 && ! deletionWatcher->hasBeenDeleted())
  37991. ownerComponent->removeComponentListener (this);
  37992. editor = 0;
  37993. }
  37994. void Label::setText (const String& newText,
  37995. const bool broadcastChangeMessage)
  37996. {
  37997. hideEditor (true);
  37998. if (lastTextValue != newText)
  37999. {
  38000. lastTextValue = newText;
  38001. textValue = newText;
  38002. repaint();
  38003. textWasChanged();
  38004. if (ownerComponent != 0 && ! deletionWatcher->hasBeenDeleted())
  38005. componentMovedOrResized (*ownerComponent, true, true);
  38006. if (broadcastChangeMessage)
  38007. callChangeListeners();
  38008. }
  38009. }
  38010. const String Label::getText (const bool returnActiveEditorContents) const throw()
  38011. {
  38012. return (returnActiveEditorContents && isBeingEdited())
  38013. ? editor->getText()
  38014. : textValue.toString();
  38015. }
  38016. void Label::valueChanged (Value&)
  38017. {
  38018. if (lastTextValue != textValue.toString())
  38019. setText (textValue.toString(), true);
  38020. }
  38021. void Label::setFont (const Font& newFont) throw()
  38022. {
  38023. font = newFont;
  38024. repaint();
  38025. }
  38026. const Font& Label::getFont() const throw()
  38027. {
  38028. return font;
  38029. }
  38030. void Label::setEditable (const bool editOnSingleClick,
  38031. const bool editOnDoubleClick,
  38032. const bool lossOfFocusDiscardsChanges_) throw()
  38033. {
  38034. editSingleClick = editOnSingleClick;
  38035. editDoubleClick = editOnDoubleClick;
  38036. lossOfFocusDiscardsChanges = lossOfFocusDiscardsChanges_;
  38037. setWantsKeyboardFocus (editOnSingleClick || editOnDoubleClick);
  38038. setFocusContainer (editOnSingleClick || editOnDoubleClick);
  38039. }
  38040. void Label::setJustificationType (const Justification& justification_) throw()
  38041. {
  38042. justification = justification_;
  38043. repaint();
  38044. }
  38045. void Label::setBorderSize (int h, int v)
  38046. {
  38047. horizontalBorderSize = h;
  38048. verticalBorderSize = v;
  38049. repaint();
  38050. }
  38051. void Label::attachToComponent (Component* owner,
  38052. const bool onLeft)
  38053. {
  38054. if (ownerComponent != 0 && ! deletionWatcher->hasBeenDeleted())
  38055. ownerComponent->removeComponentListener (this);
  38056. deletionWatcher = 0;
  38057. ownerComponent = owner;
  38058. leftOfOwnerComp = onLeft;
  38059. if (ownerComponent != 0)
  38060. {
  38061. deletionWatcher = new ComponentDeletionWatcher (owner);
  38062. setVisible (owner->isVisible());
  38063. ownerComponent->addComponentListener (this);
  38064. componentParentHierarchyChanged (*ownerComponent);
  38065. componentMovedOrResized (*ownerComponent, true, true);
  38066. }
  38067. }
  38068. void Label::componentMovedOrResized (Component& component,
  38069. bool /*wasMoved*/,
  38070. bool /*wasResized*/)
  38071. {
  38072. if (leftOfOwnerComp)
  38073. {
  38074. setSize (jmin (getFont().getStringWidth (textValue.toString()) + 8, component.getX()),
  38075. component.getHeight());
  38076. setTopRightPosition (component.getX(), component.getY());
  38077. }
  38078. else
  38079. {
  38080. setSize (component.getWidth(),
  38081. 8 + roundToInt (getFont().getHeight()));
  38082. setTopLeftPosition (component.getX(), component.getY() - getHeight());
  38083. }
  38084. }
  38085. void Label::componentParentHierarchyChanged (Component& component)
  38086. {
  38087. if (component.getParentComponent() != 0)
  38088. component.getParentComponent()->addChildComponent (this);
  38089. }
  38090. void Label::componentVisibilityChanged (Component& component)
  38091. {
  38092. setVisible (component.isVisible());
  38093. }
  38094. void Label::textWasEdited()
  38095. {
  38096. }
  38097. void Label::textWasChanged()
  38098. {
  38099. }
  38100. void Label::showEditor()
  38101. {
  38102. if (editor == 0)
  38103. {
  38104. addAndMakeVisible (editor = createEditorComponent());
  38105. editor->setText (getText(), false);
  38106. editor->addListener (this);
  38107. editor->grabKeyboardFocus();
  38108. editor->setHighlightedRegion (Range<int> (0, textValue.toString().length()));
  38109. editor->addListener (this);
  38110. resized();
  38111. repaint();
  38112. editorShown (editor);
  38113. enterModalState();
  38114. editor->grabKeyboardFocus();
  38115. }
  38116. }
  38117. void Label::editorShown (TextEditor* /*editorComponent*/)
  38118. {
  38119. }
  38120. void Label::editorAboutToBeHidden (TextEditor* /*editorComponent*/)
  38121. {
  38122. }
  38123. bool Label::updateFromTextEditorContents()
  38124. {
  38125. jassert (editor != 0);
  38126. const String newText (editor->getText());
  38127. if (textValue.toString() != newText)
  38128. {
  38129. lastTextValue = newText;
  38130. textValue = newText;
  38131. repaint();
  38132. textWasChanged();
  38133. if (ownerComponent != 0 && ! deletionWatcher->hasBeenDeleted())
  38134. componentMovedOrResized (*ownerComponent, true, true);
  38135. return true;
  38136. }
  38137. return false;
  38138. }
  38139. void Label::hideEditor (const bool discardCurrentEditorContents)
  38140. {
  38141. if (editor != 0)
  38142. {
  38143. editorAboutToBeHidden (editor);
  38144. const bool changed = (! discardCurrentEditorContents)
  38145. && updateFromTextEditorContents();
  38146. editor = 0;
  38147. repaint();
  38148. if (changed)
  38149. textWasEdited();
  38150. exitModalState (0);
  38151. if (changed && isValidComponent())
  38152. callChangeListeners();
  38153. }
  38154. }
  38155. void Label::inputAttemptWhenModal()
  38156. {
  38157. if (editor != 0)
  38158. {
  38159. if (lossOfFocusDiscardsChanges)
  38160. textEditorEscapeKeyPressed (*editor);
  38161. else
  38162. textEditorReturnKeyPressed (*editor);
  38163. }
  38164. }
  38165. bool Label::isBeingEdited() const throw()
  38166. {
  38167. return editor != 0;
  38168. }
  38169. TextEditor* Label::createEditorComponent()
  38170. {
  38171. TextEditor* const ed = new TextEditor (getName());
  38172. ed->setFont (font);
  38173. // copy these colours from our own settings..
  38174. const int cols[] = { TextEditor::backgroundColourId,
  38175. TextEditor::textColourId,
  38176. TextEditor::highlightColourId,
  38177. TextEditor::highlightedTextColourId,
  38178. TextEditor::caretColourId,
  38179. TextEditor::outlineColourId,
  38180. TextEditor::focusedOutlineColourId,
  38181. TextEditor::shadowColourId };
  38182. for (int i = 0; i < numElementsInArray (cols); ++i)
  38183. ed->setColour (cols[i], findColour (cols[i]));
  38184. return ed;
  38185. }
  38186. void Label::paint (Graphics& g)
  38187. {
  38188. getLookAndFeel().drawLabel (g, *this);
  38189. }
  38190. void Label::mouseUp (const MouseEvent& e)
  38191. {
  38192. if (editSingleClick
  38193. && e.mouseWasClicked()
  38194. && contains (e.x, e.y)
  38195. && ! e.mods.isPopupMenu())
  38196. {
  38197. showEditor();
  38198. }
  38199. }
  38200. void Label::mouseDoubleClick (const MouseEvent& e)
  38201. {
  38202. if (editDoubleClick && ! e.mods.isPopupMenu())
  38203. showEditor();
  38204. }
  38205. void Label::resized()
  38206. {
  38207. if (editor != 0)
  38208. editor->setBoundsInset (BorderSize (0));
  38209. }
  38210. void Label::focusGained (FocusChangeType cause)
  38211. {
  38212. if (editSingleClick && cause == focusChangedByTabKey)
  38213. showEditor();
  38214. }
  38215. void Label::enablementChanged()
  38216. {
  38217. repaint();
  38218. }
  38219. void Label::colourChanged()
  38220. {
  38221. repaint();
  38222. }
  38223. void Label::setMinimumHorizontalScale (const float newScale)
  38224. {
  38225. if (minimumHorizontalScale != newScale)
  38226. {
  38227. minimumHorizontalScale = newScale;
  38228. repaint();
  38229. }
  38230. }
  38231. // We'll use a custom focus traverser here to make sure focus goes from the
  38232. // text editor to another component rather than back to the label itself.
  38233. class LabelKeyboardFocusTraverser : public KeyboardFocusTraverser
  38234. {
  38235. public:
  38236. LabelKeyboardFocusTraverser() {}
  38237. Component* getNextComponent (Component* current)
  38238. {
  38239. return KeyboardFocusTraverser::getNextComponent (dynamic_cast <TextEditor*> (current) != 0
  38240. ? current->getParentComponent() : current);
  38241. }
  38242. Component* getPreviousComponent (Component* current)
  38243. {
  38244. return KeyboardFocusTraverser::getPreviousComponent (dynamic_cast <TextEditor*> (current) != 0
  38245. ? current->getParentComponent() : current);
  38246. }
  38247. };
  38248. KeyboardFocusTraverser* Label::createFocusTraverser()
  38249. {
  38250. return new LabelKeyboardFocusTraverser();
  38251. }
  38252. void Label::addListener (LabelListener* const listener) throw()
  38253. {
  38254. jassert (listener != 0);
  38255. if (listener != 0)
  38256. listeners.add (listener);
  38257. }
  38258. void Label::removeListener (LabelListener* const listener) throw()
  38259. {
  38260. listeners.removeValue (listener);
  38261. }
  38262. void Label::callChangeListeners()
  38263. {
  38264. for (int i = listeners.size(); --i >= 0;)
  38265. {
  38266. ((LabelListener*) listeners.getUnchecked (i))->labelTextChanged (this);
  38267. i = jmin (i, listeners.size());
  38268. }
  38269. }
  38270. void Label::textEditorTextChanged (TextEditor& ed)
  38271. {
  38272. if (editor != 0)
  38273. {
  38274. jassert (&ed == editor);
  38275. if (! (hasKeyboardFocus (true) || isCurrentlyBlockedByAnotherModalComponent()))
  38276. {
  38277. if (lossOfFocusDiscardsChanges)
  38278. textEditorEscapeKeyPressed (ed);
  38279. else
  38280. textEditorReturnKeyPressed (ed);
  38281. }
  38282. }
  38283. }
  38284. void Label::textEditorReturnKeyPressed (TextEditor& ed)
  38285. {
  38286. if (editor != 0)
  38287. {
  38288. jassert (&ed == editor);
  38289. (void) ed;
  38290. const bool changed = updateFromTextEditorContents();
  38291. hideEditor (true);
  38292. if (changed)
  38293. {
  38294. textWasEdited();
  38295. if (isValidComponent())
  38296. callChangeListeners();
  38297. }
  38298. }
  38299. }
  38300. void Label::textEditorEscapeKeyPressed (TextEditor& ed)
  38301. {
  38302. if (editor != 0)
  38303. {
  38304. jassert (&ed == editor);
  38305. (void) ed;
  38306. editor->setText (textValue.toString(), false);
  38307. hideEditor (true);
  38308. }
  38309. }
  38310. void Label::textEditorFocusLost (TextEditor& ed)
  38311. {
  38312. textEditorTextChanged (ed);
  38313. }
  38314. END_JUCE_NAMESPACE
  38315. /*** End of inlined file: juce_Label.cpp ***/
  38316. /*** Start of inlined file: juce_ListBox.cpp ***/
  38317. BEGIN_JUCE_NAMESPACE
  38318. class ListBoxRowComponent : public Component,
  38319. public TooltipClient
  38320. {
  38321. public:
  38322. ListBoxRowComponent (ListBox& owner_)
  38323. : owner (owner_),
  38324. row (-1),
  38325. selected (false),
  38326. isDragging (false)
  38327. {
  38328. }
  38329. ~ListBoxRowComponent()
  38330. {
  38331. deleteAllChildren();
  38332. }
  38333. void paint (Graphics& g)
  38334. {
  38335. if (owner.getModel() != 0)
  38336. owner.getModel()->paintListBoxItem (row, g, getWidth(), getHeight(), selected);
  38337. }
  38338. void update (const int row_, const bool selected_)
  38339. {
  38340. if (row != row_ || selected != selected_)
  38341. {
  38342. repaint();
  38343. row = row_;
  38344. selected = selected_;
  38345. }
  38346. if (owner.getModel() != 0)
  38347. {
  38348. Component* const customComp = owner.getModel()->refreshComponentForRow (row_, selected_, getChildComponent (0));
  38349. if (customComp != 0)
  38350. {
  38351. addAndMakeVisible (customComp);
  38352. customComp->setBounds (0, 0, getWidth(), getHeight());
  38353. for (int i = getNumChildComponents(); --i >= 0;)
  38354. if (getChildComponent (i) != customComp)
  38355. delete getChildComponent (i);
  38356. }
  38357. else
  38358. {
  38359. deleteAllChildren();
  38360. }
  38361. }
  38362. }
  38363. void mouseDown (const MouseEvent& e)
  38364. {
  38365. isDragging = false;
  38366. selectRowOnMouseUp = false;
  38367. if (isEnabled())
  38368. {
  38369. if (! selected)
  38370. {
  38371. owner.selectRowsBasedOnModifierKeys (row, e.mods);
  38372. if (owner.getModel() != 0)
  38373. owner.getModel()->listBoxItemClicked (row, e);
  38374. }
  38375. else
  38376. {
  38377. selectRowOnMouseUp = true;
  38378. }
  38379. }
  38380. }
  38381. void mouseUp (const MouseEvent& e)
  38382. {
  38383. if (isEnabled() && selectRowOnMouseUp && ! isDragging)
  38384. {
  38385. owner.selectRowsBasedOnModifierKeys (row, e.mods);
  38386. if (owner.getModel() != 0)
  38387. owner.getModel()->listBoxItemClicked (row, e);
  38388. }
  38389. }
  38390. void mouseDoubleClick (const MouseEvent& e)
  38391. {
  38392. if (owner.getModel() != 0 && isEnabled())
  38393. owner.getModel()->listBoxItemDoubleClicked (row, e);
  38394. }
  38395. void mouseDrag (const MouseEvent& e)
  38396. {
  38397. if (isEnabled() && owner.getModel() != 0 && ! (e.mouseWasClicked() || isDragging))
  38398. {
  38399. const SparseSet <int> selectedRows (owner.getSelectedRows());
  38400. if (selectedRows.size() > 0)
  38401. {
  38402. const String dragDescription (owner.getModel()->getDragSourceDescription (selectedRows));
  38403. if (dragDescription.isNotEmpty())
  38404. {
  38405. isDragging = true;
  38406. owner.startDragAndDrop (e, dragDescription);
  38407. }
  38408. }
  38409. }
  38410. }
  38411. void resized()
  38412. {
  38413. if (getNumChildComponents() > 0)
  38414. getChildComponent(0)->setBounds (0, 0, getWidth(), getHeight());
  38415. }
  38416. const String getTooltip()
  38417. {
  38418. if (owner.getModel() != 0)
  38419. return owner.getModel()->getTooltipForRow (row);
  38420. return String::empty;
  38421. }
  38422. juce_UseDebuggingNewOperator
  38423. bool neededFlag;
  38424. private:
  38425. ListBox& owner;
  38426. int row;
  38427. bool selected, isDragging, selectRowOnMouseUp;
  38428. ListBoxRowComponent (const ListBoxRowComponent&);
  38429. const ListBoxRowComponent& operator= (const ListBoxRowComponent&);
  38430. };
  38431. class ListViewport : public Viewport
  38432. {
  38433. public:
  38434. int firstIndex, firstWholeIndex, lastWholeIndex;
  38435. bool hasUpdated;
  38436. ListViewport (ListBox& owner_)
  38437. : owner (owner_)
  38438. {
  38439. setWantsKeyboardFocus (false);
  38440. setViewedComponent (new Component());
  38441. getViewedComponent()->addMouseListener (this, false);
  38442. getViewedComponent()->setWantsKeyboardFocus (false);
  38443. }
  38444. ~ListViewport()
  38445. {
  38446. getViewedComponent()->removeMouseListener (this);
  38447. getViewedComponent()->deleteAllChildren();
  38448. }
  38449. ListBoxRowComponent* getComponentForRow (const int row) const throw()
  38450. {
  38451. return (ListBoxRowComponent*) getViewedComponent()
  38452. ->getChildComponent (row % jmax (1, getViewedComponent()->getNumChildComponents()));
  38453. }
  38454. int getRowNumberOfComponent (Component* const rowComponent) const throw()
  38455. {
  38456. const int index = getIndexOfChildComponent (rowComponent);
  38457. const int num = getViewedComponent()->getNumChildComponents();
  38458. for (int i = num; --i >= 0;)
  38459. if (((firstIndex + i) % jmax (1, num)) == index)
  38460. return firstIndex + i;
  38461. return -1;
  38462. }
  38463. Component* getComponentForRowIfOnscreen (const int row) const throw()
  38464. {
  38465. return (row >= firstIndex && row < firstIndex + getViewedComponent()->getNumChildComponents())
  38466. ? getComponentForRow (row) : 0;
  38467. }
  38468. void visibleAreaChanged (int, int, int, int)
  38469. {
  38470. updateVisibleArea (true);
  38471. if (owner.getModel() != 0)
  38472. owner.getModel()->listWasScrolled();
  38473. }
  38474. void updateVisibleArea (const bool makeSureItUpdatesContent)
  38475. {
  38476. hasUpdated = false;
  38477. const int newX = getViewedComponent()->getX();
  38478. int newY = getViewedComponent()->getY();
  38479. const int newW = jmax (owner.minimumRowWidth, getMaximumVisibleWidth());
  38480. const int newH = owner.totalItems * owner.getRowHeight();
  38481. if (newY + newH < getMaximumVisibleHeight() && newH > getMaximumVisibleHeight())
  38482. newY = getMaximumVisibleHeight() - newH;
  38483. getViewedComponent()->setBounds (newX, newY, newW, newH);
  38484. if (makeSureItUpdatesContent && ! hasUpdated)
  38485. updateContents();
  38486. }
  38487. void updateContents()
  38488. {
  38489. hasUpdated = true;
  38490. const int rowHeight = owner.getRowHeight();
  38491. if (rowHeight > 0)
  38492. {
  38493. const int y = getViewPositionY();
  38494. const int w = getViewedComponent()->getWidth();
  38495. const int numNeeded = 2 + getMaximumVisibleHeight() / rowHeight;
  38496. while (numNeeded > getViewedComponent()->getNumChildComponents())
  38497. getViewedComponent()->addAndMakeVisible (new ListBoxRowComponent (owner));
  38498. jassert (numNeeded >= 0);
  38499. while (numNeeded < getViewedComponent()->getNumChildComponents())
  38500. {
  38501. Component* const rowToRemove
  38502. = getViewedComponent()->getChildComponent (getViewedComponent()->getNumChildComponents() - 1);
  38503. delete rowToRemove;
  38504. }
  38505. firstIndex = y / rowHeight;
  38506. firstWholeIndex = (y + rowHeight - 1) / rowHeight;
  38507. lastWholeIndex = (y + getMaximumVisibleHeight() - 1) / rowHeight;
  38508. for (int i = 0; i < numNeeded; ++i)
  38509. {
  38510. const int row = i + firstIndex;
  38511. ListBoxRowComponent* const rowComp = getComponentForRow (row);
  38512. if (rowComp != 0)
  38513. {
  38514. rowComp->setBounds (0, row * rowHeight, w, rowHeight);
  38515. rowComp->update (row, owner.isRowSelected (row));
  38516. }
  38517. }
  38518. }
  38519. if (owner.headerComponent != 0)
  38520. owner.headerComponent->setBounds (owner.outlineThickness + getViewedComponent()->getX(),
  38521. owner.outlineThickness,
  38522. jmax (owner.getWidth() - owner.outlineThickness * 2,
  38523. getViewedComponent()->getWidth()),
  38524. owner.headerComponent->getHeight());
  38525. }
  38526. void paint (Graphics& g)
  38527. {
  38528. if (isOpaque())
  38529. g.fillAll (owner.findColour (ListBox::backgroundColourId));
  38530. }
  38531. bool keyPressed (const KeyPress& key)
  38532. {
  38533. if (key.isKeyCode (KeyPress::upKey)
  38534. || key.isKeyCode (KeyPress::downKey)
  38535. || key.isKeyCode (KeyPress::pageUpKey)
  38536. || key.isKeyCode (KeyPress::pageDownKey)
  38537. || key.isKeyCode (KeyPress::homeKey)
  38538. || key.isKeyCode (KeyPress::endKey))
  38539. {
  38540. // we want to avoid these keypresses going to the viewport, and instead allow
  38541. // them to pass up to our listbox..
  38542. return false;
  38543. }
  38544. return Viewport::keyPressed (key);
  38545. }
  38546. juce_UseDebuggingNewOperator
  38547. private:
  38548. ListBox& owner;
  38549. ListViewport (const ListViewport&);
  38550. const ListViewport& operator= (const ListViewport&);
  38551. };
  38552. ListBox::ListBox (const String& name, ListBoxModel* const model_)
  38553. : Component (name),
  38554. model (model_),
  38555. headerComponent (0),
  38556. totalItems (0),
  38557. rowHeight (22),
  38558. minimumRowWidth (0),
  38559. outlineThickness (0),
  38560. lastRowSelected (-1),
  38561. mouseMoveSelects (false),
  38562. multipleSelection (false),
  38563. hasDoneInitialUpdate (false)
  38564. {
  38565. addAndMakeVisible (viewport = new ListViewport (*this));
  38566. setWantsKeyboardFocus (true);
  38567. colourChanged();
  38568. }
  38569. ListBox::~ListBox()
  38570. {
  38571. deleteAllChildren();
  38572. }
  38573. void ListBox::setModel (ListBoxModel* const newModel)
  38574. {
  38575. if (model != newModel)
  38576. {
  38577. model = newModel;
  38578. updateContent();
  38579. }
  38580. }
  38581. void ListBox::setMultipleSelectionEnabled (bool b)
  38582. {
  38583. multipleSelection = b;
  38584. }
  38585. void ListBox::setMouseMoveSelectsRows (bool b)
  38586. {
  38587. mouseMoveSelects = b;
  38588. if (b)
  38589. addMouseListener (this, true);
  38590. }
  38591. void ListBox::paint (Graphics& g)
  38592. {
  38593. if (! hasDoneInitialUpdate)
  38594. updateContent();
  38595. g.fillAll (findColour (backgroundColourId));
  38596. }
  38597. void ListBox::paintOverChildren (Graphics& g)
  38598. {
  38599. if (outlineThickness > 0)
  38600. {
  38601. g.setColour (findColour (outlineColourId));
  38602. g.drawRect (0, 0, getWidth(), getHeight(), outlineThickness);
  38603. }
  38604. }
  38605. void ListBox::resized()
  38606. {
  38607. viewport->setBoundsInset (BorderSize (outlineThickness + ((headerComponent != 0) ? headerComponent->getHeight() : 0),
  38608. outlineThickness,
  38609. outlineThickness,
  38610. outlineThickness));
  38611. viewport->setSingleStepSizes (20, getRowHeight());
  38612. viewport->updateVisibleArea (false);
  38613. }
  38614. void ListBox::visibilityChanged()
  38615. {
  38616. viewport->updateVisibleArea (true);
  38617. }
  38618. Viewport* ListBox::getViewport() const throw()
  38619. {
  38620. return viewport;
  38621. }
  38622. void ListBox::updateContent()
  38623. {
  38624. hasDoneInitialUpdate = true;
  38625. totalItems = (model != 0) ? model->getNumRows() : 0;
  38626. bool selectionChanged = false;
  38627. if (selected [selected.size() - 1] >= totalItems)
  38628. {
  38629. selected.removeRange (totalItems, std::numeric_limits<int>::max() - totalItems);
  38630. lastRowSelected = getSelectedRow (0);
  38631. selectionChanged = true;
  38632. }
  38633. viewport->updateVisibleArea (isVisible());
  38634. viewport->resized();
  38635. if (selectionChanged && model != 0)
  38636. model->selectedRowsChanged (lastRowSelected);
  38637. }
  38638. void ListBox::selectRow (const int row,
  38639. bool dontScroll,
  38640. bool deselectOthersFirst)
  38641. {
  38642. selectRowInternal (row, dontScroll, deselectOthersFirst, false);
  38643. }
  38644. void ListBox::selectRowInternal (const int row,
  38645. bool dontScroll,
  38646. bool deselectOthersFirst,
  38647. bool isMouseClick)
  38648. {
  38649. if (! multipleSelection)
  38650. deselectOthersFirst = true;
  38651. if ((! isRowSelected (row))
  38652. || (deselectOthersFirst && getNumSelectedRows() > 1))
  38653. {
  38654. if (((unsigned int) row) < (unsigned int) totalItems)
  38655. {
  38656. if (deselectOthersFirst)
  38657. selected.clear();
  38658. selected.addRange (row, 1);
  38659. if (getHeight() == 0 || getWidth() == 0)
  38660. dontScroll = true;
  38661. viewport->hasUpdated = false;
  38662. if (row < viewport->firstWholeIndex && ! dontScroll)
  38663. {
  38664. viewport->setViewPosition (viewport->getViewPositionX(),
  38665. row * getRowHeight());
  38666. }
  38667. else if (row >= viewport->lastWholeIndex && ! dontScroll)
  38668. {
  38669. const int rowsOnScreen = viewport->lastWholeIndex - viewport->firstWholeIndex;
  38670. if (row >= lastRowSelected + rowsOnScreen
  38671. && rowsOnScreen < totalItems - 1
  38672. && ! isMouseClick)
  38673. {
  38674. viewport->setViewPosition (viewport->getViewPositionX(),
  38675. jlimit (0, jmax (0, totalItems - rowsOnScreen), row)
  38676. * getRowHeight());
  38677. }
  38678. else
  38679. {
  38680. viewport->setViewPosition (viewport->getViewPositionX(),
  38681. jmax (0, (row + 1) * getRowHeight() - viewport->getMaximumVisibleHeight()));
  38682. }
  38683. }
  38684. if (! viewport->hasUpdated)
  38685. viewport->updateContents();
  38686. lastRowSelected = row;
  38687. model->selectedRowsChanged (row);
  38688. }
  38689. else
  38690. {
  38691. if (deselectOthersFirst)
  38692. deselectAllRows();
  38693. }
  38694. }
  38695. }
  38696. void ListBox::deselectRow (const int row)
  38697. {
  38698. if (selected.contains (row))
  38699. {
  38700. selected.removeRange (row, 1);
  38701. if (row == lastRowSelected)
  38702. lastRowSelected = getSelectedRow (0);
  38703. viewport->updateContents();
  38704. model->selectedRowsChanged (lastRowSelected);
  38705. }
  38706. }
  38707. void ListBox::setSelectedRows (const SparseSet<int>& setOfRowsToBeSelected,
  38708. const bool sendNotificationEventToModel)
  38709. {
  38710. selected = setOfRowsToBeSelected;
  38711. selected.removeRange (totalItems, std::numeric_limits<int>::max() - totalItems);
  38712. if (! isRowSelected (lastRowSelected))
  38713. lastRowSelected = getSelectedRow (0);
  38714. viewport->updateContents();
  38715. if ((model != 0) && sendNotificationEventToModel)
  38716. model->selectedRowsChanged (lastRowSelected);
  38717. }
  38718. const SparseSet<int> ListBox::getSelectedRows() const
  38719. {
  38720. return selected;
  38721. }
  38722. void ListBox::selectRangeOfRows (int firstRow, int lastRow)
  38723. {
  38724. if (multipleSelection && (firstRow != lastRow))
  38725. {
  38726. const int numRows = totalItems - 1;
  38727. firstRow = jlimit (0, jmax (0, numRows), firstRow);
  38728. lastRow = jlimit (0, jmax (0, numRows), lastRow);
  38729. selected.addRange (jmin (firstRow, lastRow),
  38730. abs (firstRow - lastRow) + 1);
  38731. selected.removeRange (lastRow, 1);
  38732. }
  38733. selectRowInternal (lastRow, false, false, true);
  38734. }
  38735. void ListBox::flipRowSelection (const int row)
  38736. {
  38737. if (isRowSelected (row))
  38738. deselectRow (row);
  38739. else
  38740. selectRowInternal (row, false, false, true);
  38741. }
  38742. void ListBox::deselectAllRows()
  38743. {
  38744. if (! selected.isEmpty())
  38745. {
  38746. selected.clear();
  38747. lastRowSelected = -1;
  38748. viewport->updateContents();
  38749. if (model != 0)
  38750. model->selectedRowsChanged (lastRowSelected);
  38751. }
  38752. }
  38753. void ListBox::selectRowsBasedOnModifierKeys (const int row,
  38754. const ModifierKeys& mods)
  38755. {
  38756. if (multipleSelection && mods.isCommandDown())
  38757. {
  38758. flipRowSelection (row);
  38759. }
  38760. else if (multipleSelection && mods.isShiftDown() && lastRowSelected >= 0)
  38761. {
  38762. selectRangeOfRows (lastRowSelected, row);
  38763. }
  38764. else if ((! mods.isPopupMenu()) || ! isRowSelected (row))
  38765. {
  38766. selectRowInternal (row, false, true, true);
  38767. }
  38768. }
  38769. int ListBox::getNumSelectedRows() const
  38770. {
  38771. return selected.size();
  38772. }
  38773. int ListBox::getSelectedRow (const int index) const
  38774. {
  38775. return (((unsigned int) index) < (unsigned int) selected.size())
  38776. ? selected [index] : -1;
  38777. }
  38778. bool ListBox::isRowSelected (const int row) const
  38779. {
  38780. return selected.contains (row);
  38781. }
  38782. int ListBox::getLastRowSelected() const
  38783. {
  38784. return (isRowSelected (lastRowSelected)) ? lastRowSelected : -1;
  38785. }
  38786. int ListBox::getRowContainingPosition (const int x, const int y) const throw()
  38787. {
  38788. if (((unsigned int) x) < (unsigned int) getWidth())
  38789. {
  38790. const int row = (viewport->getViewPositionY() + y - viewport->getY()) / rowHeight;
  38791. if (((unsigned int) row) < (unsigned int) totalItems)
  38792. return row;
  38793. }
  38794. return -1;
  38795. }
  38796. int ListBox::getInsertionIndexForPosition (const int x, const int y) const throw()
  38797. {
  38798. if (((unsigned int) x) < (unsigned int) getWidth())
  38799. {
  38800. const int row = (viewport->getViewPositionY() + y + rowHeight / 2 - viewport->getY()) / rowHeight;
  38801. return jlimit (0, totalItems, row);
  38802. }
  38803. return -1;
  38804. }
  38805. Component* ListBox::getComponentForRowNumber (const int row) const throw()
  38806. {
  38807. Component* const listRowComp = viewport->getComponentForRowIfOnscreen (row);
  38808. return listRowComp != 0 ? listRowComp->getChildComponent (0) : 0;
  38809. }
  38810. int ListBox::getRowNumberOfComponent (Component* const rowComponent) const throw()
  38811. {
  38812. return viewport->getRowNumberOfComponent (rowComponent);
  38813. }
  38814. const Rectangle<int> ListBox::getRowPosition (const int rowNumber,
  38815. const bool relativeToComponentTopLeft) const throw()
  38816. {
  38817. const int rowHeight = getRowHeight();
  38818. int y = viewport->getY() + rowHeight * rowNumber;
  38819. if (relativeToComponentTopLeft)
  38820. y -= viewport->getViewPositionY();
  38821. return Rectangle<int> (viewport->getX(), y,
  38822. viewport->getViewedComponent()->getWidth(), rowHeight);
  38823. }
  38824. void ListBox::setVerticalPosition (const double proportion)
  38825. {
  38826. const int offscreen = viewport->getViewedComponent()->getHeight() - viewport->getHeight();
  38827. viewport->setViewPosition (viewport->getViewPositionX(),
  38828. jmax (0, roundToInt (proportion * offscreen)));
  38829. }
  38830. double ListBox::getVerticalPosition() const
  38831. {
  38832. const int offscreen = viewport->getViewedComponent()->getHeight() - viewport->getHeight();
  38833. return (offscreen > 0) ? viewport->getViewPositionY() / (double) offscreen
  38834. : 0;
  38835. }
  38836. int ListBox::getVisibleRowWidth() const throw()
  38837. {
  38838. return viewport->getViewWidth();
  38839. }
  38840. void ListBox::scrollToEnsureRowIsOnscreen (const int row)
  38841. {
  38842. if (row < viewport->firstWholeIndex)
  38843. {
  38844. viewport->setViewPosition (viewport->getViewPositionX(),
  38845. row * getRowHeight());
  38846. }
  38847. else if (row >= viewport->lastWholeIndex)
  38848. {
  38849. viewport->setViewPosition (viewport->getViewPositionX(),
  38850. jmax (0, (row + 1) * getRowHeight() - viewport->getMaximumVisibleHeight()));
  38851. }
  38852. }
  38853. bool ListBox::keyPressed (const KeyPress& key)
  38854. {
  38855. const int numVisibleRows = viewport->getHeight() / getRowHeight();
  38856. const bool multiple = multipleSelection
  38857. && (lastRowSelected >= 0)
  38858. && (key.getModifiers().isShiftDown()
  38859. || key.getModifiers().isCtrlDown()
  38860. || key.getModifiers().isCommandDown());
  38861. if (key.isKeyCode (KeyPress::upKey))
  38862. {
  38863. if (multiple)
  38864. selectRangeOfRows (lastRowSelected, lastRowSelected - 1);
  38865. else
  38866. selectRow (jmax (0, lastRowSelected - 1));
  38867. }
  38868. else if (key.isKeyCode (KeyPress::returnKey)
  38869. && isRowSelected (lastRowSelected))
  38870. {
  38871. if (model != 0)
  38872. model->returnKeyPressed (lastRowSelected);
  38873. }
  38874. else if (key.isKeyCode (KeyPress::pageUpKey))
  38875. {
  38876. if (multiple)
  38877. selectRangeOfRows (lastRowSelected, lastRowSelected - numVisibleRows);
  38878. else
  38879. selectRow (jmax (0, jmax (0, lastRowSelected) - numVisibleRows));
  38880. }
  38881. else if (key.isKeyCode (KeyPress::pageDownKey))
  38882. {
  38883. if (multiple)
  38884. selectRangeOfRows (lastRowSelected, lastRowSelected + numVisibleRows);
  38885. else
  38886. selectRow (jmin (totalItems - 1, jmax (0, lastRowSelected) + numVisibleRows));
  38887. }
  38888. else if (key.isKeyCode (KeyPress::homeKey))
  38889. {
  38890. if (multiple && key.getModifiers().isShiftDown())
  38891. selectRangeOfRows (lastRowSelected, 0);
  38892. else
  38893. selectRow (0);
  38894. }
  38895. else if (key.isKeyCode (KeyPress::endKey))
  38896. {
  38897. if (multiple && key.getModifiers().isShiftDown())
  38898. selectRangeOfRows (lastRowSelected, totalItems - 1);
  38899. else
  38900. selectRow (totalItems - 1);
  38901. }
  38902. else if (key.isKeyCode (KeyPress::downKey))
  38903. {
  38904. if (multiple)
  38905. selectRangeOfRows (lastRowSelected, lastRowSelected + 1);
  38906. else
  38907. selectRow (jmin (totalItems - 1, jmax (0, lastRowSelected) + 1));
  38908. }
  38909. else if ((key.isKeyCode (KeyPress::deleteKey) || key.isKeyCode (KeyPress::backspaceKey))
  38910. && isRowSelected (lastRowSelected))
  38911. {
  38912. if (model != 0)
  38913. model->deleteKeyPressed (lastRowSelected);
  38914. }
  38915. else if (multiple && key == KeyPress (T('a'), ModifierKeys::commandModifier, 0))
  38916. {
  38917. selectRangeOfRows (0, std::numeric_limits<int>::max());
  38918. }
  38919. else
  38920. {
  38921. return false;
  38922. }
  38923. return true;
  38924. }
  38925. bool ListBox::keyStateChanged (const bool isKeyDown)
  38926. {
  38927. return isKeyDown
  38928. && (KeyPress::isKeyCurrentlyDown (KeyPress::upKey)
  38929. || KeyPress::isKeyCurrentlyDown (KeyPress::pageUpKey)
  38930. || KeyPress::isKeyCurrentlyDown (KeyPress::downKey)
  38931. || KeyPress::isKeyCurrentlyDown (KeyPress::pageDownKey)
  38932. || KeyPress::isKeyCurrentlyDown (KeyPress::homeKey)
  38933. || KeyPress::isKeyCurrentlyDown (KeyPress::endKey)
  38934. || KeyPress::isKeyCurrentlyDown (KeyPress::returnKey));
  38935. }
  38936. void ListBox::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  38937. {
  38938. getHorizontalScrollBar()->mouseWheelMove (e, wheelIncrementX, 0);
  38939. getVerticalScrollBar()->mouseWheelMove (e, 0, wheelIncrementY);
  38940. }
  38941. void ListBox::mouseMove (const MouseEvent& e)
  38942. {
  38943. if (mouseMoveSelects)
  38944. {
  38945. const MouseEvent e2 (e.getEventRelativeTo (this));
  38946. selectRow (getRowContainingPosition (e2.x, e2.y), true);
  38947. lastMouseX = e2.x;
  38948. lastMouseY = e2.y;
  38949. }
  38950. }
  38951. void ListBox::mouseExit (const MouseEvent& e)
  38952. {
  38953. mouseMove (e);
  38954. }
  38955. void ListBox::mouseUp (const MouseEvent& e)
  38956. {
  38957. if (e.mouseWasClicked() && model != 0)
  38958. model->backgroundClicked();
  38959. }
  38960. void ListBox::setRowHeight (const int newHeight)
  38961. {
  38962. rowHeight = jmax (1, newHeight);
  38963. viewport->setSingleStepSizes (20, rowHeight);
  38964. updateContent();
  38965. }
  38966. int ListBox::getNumRowsOnScreen() const throw()
  38967. {
  38968. return viewport->getMaximumVisibleHeight() / rowHeight;
  38969. }
  38970. void ListBox::setMinimumContentWidth (const int newMinimumWidth)
  38971. {
  38972. minimumRowWidth = newMinimumWidth;
  38973. updateContent();
  38974. }
  38975. int ListBox::getVisibleContentWidth() const throw()
  38976. {
  38977. return viewport->getMaximumVisibleWidth();
  38978. }
  38979. ScrollBar* ListBox::getVerticalScrollBar() const throw()
  38980. {
  38981. return viewport->getVerticalScrollBar();
  38982. }
  38983. ScrollBar* ListBox::getHorizontalScrollBar() const throw()
  38984. {
  38985. return viewport->getHorizontalScrollBar();
  38986. }
  38987. void ListBox::colourChanged()
  38988. {
  38989. setOpaque (findColour (backgroundColourId).isOpaque());
  38990. viewport->setOpaque (isOpaque());
  38991. repaint();
  38992. }
  38993. void ListBox::setOutlineThickness (const int outlineThickness_)
  38994. {
  38995. outlineThickness = outlineThickness_;
  38996. resized();
  38997. }
  38998. void ListBox::setHeaderComponent (Component* const newHeaderComponent)
  38999. {
  39000. if (headerComponent != newHeaderComponent)
  39001. {
  39002. delete headerComponent;
  39003. headerComponent = newHeaderComponent;
  39004. addAndMakeVisible (newHeaderComponent);
  39005. ListBox::resized();
  39006. }
  39007. }
  39008. void ListBox::repaintRow (const int rowNumber) throw()
  39009. {
  39010. const Rectangle<int> r (getRowPosition (rowNumber, true));
  39011. repaint (r.getX(), r.getY(), r.getWidth(), r.getHeight());
  39012. }
  39013. Image* ListBox::createSnapshotOfSelectedRows (int& imageX, int& imageY)
  39014. {
  39015. Rectangle<int> imageArea;
  39016. const int firstRow = getRowContainingPosition (0, 0);
  39017. int i;
  39018. for (i = getNumRowsOnScreen() + 2; --i >= 0;)
  39019. {
  39020. Component* rowComp = viewport->getComponentForRowIfOnscreen (firstRow + i);
  39021. if (rowComp != 0 && isRowSelected (firstRow + i))
  39022. {
  39023. int x = 0, y = 0;
  39024. rowComp->relativePositionToOtherComponent (this, x, y);
  39025. const Rectangle<int> rowRect (x, y, rowComp->getWidth(), rowComp->getHeight());
  39026. if (imageArea.isEmpty())
  39027. imageArea = rowRect;
  39028. else
  39029. imageArea = imageArea.getUnion (rowRect);
  39030. }
  39031. }
  39032. imageArea = imageArea.getIntersection (Rectangle<int> (0, 0, getWidth(), getHeight()));
  39033. imageX = imageArea.getX();
  39034. imageY = imageArea.getY();
  39035. Image* snapshot = Image::createNativeImage (Image::ARGB, imageArea.getWidth(), imageArea.getHeight(), true);
  39036. for (i = getNumRowsOnScreen() + 2; --i >= 0;)
  39037. {
  39038. Component* rowComp = viewport->getComponentForRowIfOnscreen (firstRow + i);
  39039. if (rowComp != 0 && isRowSelected (firstRow + i))
  39040. {
  39041. int x = 0, y = 0;
  39042. rowComp->relativePositionToOtherComponent (this, x, y);
  39043. Graphics g (*snapshot);
  39044. g.setOrigin (x - imageX, y - imageY);
  39045. if (g.reduceClipRegion (0, 0, rowComp->getWidth(), rowComp->getHeight()))
  39046. rowComp->paintEntireComponent (g);
  39047. }
  39048. }
  39049. return snapshot;
  39050. }
  39051. void ListBox::startDragAndDrop (const MouseEvent& e, const String& dragDescription)
  39052. {
  39053. DragAndDropContainer* const dragContainer
  39054. = DragAndDropContainer::findParentDragContainerFor (this);
  39055. if (dragContainer != 0)
  39056. {
  39057. int x, y;
  39058. Image* dragImage = createSnapshotOfSelectedRows (x, y);
  39059. dragImage->multiplyAllAlphas (0.6f);
  39060. MouseEvent e2 (e.getEventRelativeTo (this));
  39061. const Point<int> p (x - e2.x, y - e2.y);
  39062. dragContainer->startDragging (dragDescription, this, dragImage, true, &p);
  39063. }
  39064. else
  39065. {
  39066. // to be able to do a drag-and-drop operation, the listbox needs to
  39067. // be inside a component which is also a DragAndDropContainer.
  39068. jassertfalse
  39069. }
  39070. }
  39071. Component* ListBoxModel::refreshComponentForRow (int, bool, Component* existingComponentToUpdate)
  39072. {
  39073. (void) existingComponentToUpdate;
  39074. jassert (existingComponentToUpdate == 0); // indicates a failure in the code the recycles the components
  39075. return 0;
  39076. }
  39077. void ListBoxModel::listBoxItemClicked (int, const MouseEvent&)
  39078. {
  39079. }
  39080. void ListBoxModel::listBoxItemDoubleClicked (int, const MouseEvent&)
  39081. {
  39082. }
  39083. void ListBoxModel::backgroundClicked()
  39084. {
  39085. }
  39086. void ListBoxModel::selectedRowsChanged (int)
  39087. {
  39088. }
  39089. void ListBoxModel::deleteKeyPressed (int)
  39090. {
  39091. }
  39092. void ListBoxModel::returnKeyPressed (int)
  39093. {
  39094. }
  39095. void ListBoxModel::listWasScrolled()
  39096. {
  39097. }
  39098. const String ListBoxModel::getDragSourceDescription (const SparseSet<int>&)
  39099. {
  39100. return String::empty;
  39101. }
  39102. const String ListBoxModel::getTooltipForRow (int)
  39103. {
  39104. return String::empty;
  39105. }
  39106. END_JUCE_NAMESPACE
  39107. /*** End of inlined file: juce_ListBox.cpp ***/
  39108. /*** Start of inlined file: juce_ProgressBar.cpp ***/
  39109. BEGIN_JUCE_NAMESPACE
  39110. ProgressBar::ProgressBar (double& progress_)
  39111. : progress (progress_),
  39112. displayPercentage (true),
  39113. lastCallbackTime (0)
  39114. {
  39115. currentValue = jlimit (0.0, 1.0, progress);
  39116. }
  39117. ProgressBar::~ProgressBar()
  39118. {
  39119. }
  39120. void ProgressBar::setPercentageDisplay (const bool shouldDisplayPercentage)
  39121. {
  39122. displayPercentage = shouldDisplayPercentage;
  39123. repaint();
  39124. }
  39125. void ProgressBar::setTextToDisplay (const String& text)
  39126. {
  39127. displayPercentage = false;
  39128. displayedMessage = text;
  39129. }
  39130. void ProgressBar::lookAndFeelChanged()
  39131. {
  39132. setOpaque (findColour (backgroundColourId).isOpaque());
  39133. }
  39134. void ProgressBar::colourChanged()
  39135. {
  39136. lookAndFeelChanged();
  39137. }
  39138. void ProgressBar::paint (Graphics& g)
  39139. {
  39140. String text;
  39141. if (displayPercentage)
  39142. {
  39143. if (currentValue >= 0 && currentValue <= 1.0)
  39144. text << roundToInt (currentValue * 100.0) << T("%");
  39145. }
  39146. else
  39147. {
  39148. text = displayedMessage;
  39149. }
  39150. getLookAndFeel().drawProgressBar (g, *this,
  39151. getWidth(), getHeight(),
  39152. currentValue, text);
  39153. }
  39154. void ProgressBar::visibilityChanged()
  39155. {
  39156. if (isVisible())
  39157. startTimer (30);
  39158. else
  39159. stopTimer();
  39160. }
  39161. void ProgressBar::timerCallback()
  39162. {
  39163. double newProgress = progress;
  39164. const uint32 now = Time::getMillisecondCounter();
  39165. const int timeSinceLastCallback = (int) (now - lastCallbackTime);
  39166. lastCallbackTime = now;
  39167. if (currentValue != newProgress
  39168. || newProgress < 0 || newProgress >= 1.0
  39169. || currentMessage != displayedMessage)
  39170. {
  39171. if (currentValue < newProgress
  39172. && newProgress >= 0 && newProgress < 1.0
  39173. && currentValue >= 0 && currentValue < 1.0)
  39174. {
  39175. newProgress = jmin (currentValue + 0.0008 * timeSinceLastCallback,
  39176. newProgress);
  39177. }
  39178. currentValue = newProgress;
  39179. currentMessage = displayedMessage;
  39180. repaint();
  39181. }
  39182. }
  39183. END_JUCE_NAMESPACE
  39184. /*** End of inlined file: juce_ProgressBar.cpp ***/
  39185. /*** Start of inlined file: juce_Slider.cpp ***/
  39186. BEGIN_JUCE_NAMESPACE
  39187. class SliderPopupDisplayComponent : public BubbleComponent
  39188. {
  39189. public:
  39190. SliderPopupDisplayComponent (Slider* const owner_)
  39191. : owner (owner_),
  39192. font (15.0f, Font::bold)
  39193. {
  39194. setAlwaysOnTop (true);
  39195. }
  39196. ~SliderPopupDisplayComponent()
  39197. {
  39198. }
  39199. void paintContent (Graphics& g, int w, int h)
  39200. {
  39201. g.setFont (font);
  39202. g.setColour (Colours::black);
  39203. g.drawFittedText (text, 0, 0, w, h, Justification::centred, 1);
  39204. }
  39205. void getContentSize (int& w, int& h)
  39206. {
  39207. w = font.getStringWidth (text) + 18;
  39208. h = (int) (font.getHeight() * 1.6f);
  39209. }
  39210. void updatePosition (const String& newText)
  39211. {
  39212. if (text != newText)
  39213. {
  39214. text = newText;
  39215. repaint();
  39216. }
  39217. BubbleComponent::setPosition (owner);
  39218. }
  39219. juce_UseDebuggingNewOperator
  39220. private:
  39221. Slider* owner;
  39222. Font font;
  39223. String text;
  39224. SliderPopupDisplayComponent (const SliderPopupDisplayComponent&);
  39225. const SliderPopupDisplayComponent& operator= (const SliderPopupDisplayComponent&);
  39226. };
  39227. Slider::Slider (const String& name)
  39228. : Component (name),
  39229. lastCurrentValue (0),
  39230. lastValueMin (0),
  39231. lastValueMax (0),
  39232. minimum (0),
  39233. maximum (10),
  39234. interval (0),
  39235. skewFactor (1.0),
  39236. velocityModeSensitivity (1.0),
  39237. velocityModeOffset (0.0),
  39238. velocityModeThreshold (1),
  39239. rotaryStart (float_Pi * 1.2f),
  39240. rotaryEnd (float_Pi * 2.8f),
  39241. numDecimalPlaces (7),
  39242. sliderRegionStart (0),
  39243. sliderRegionSize (1),
  39244. sliderBeingDragged (-1),
  39245. pixelsForFullDragExtent (250),
  39246. style (LinearHorizontal),
  39247. textBoxPos (TextBoxLeft),
  39248. textBoxWidth (80),
  39249. textBoxHeight (20),
  39250. incDecButtonMode (incDecButtonsNotDraggable),
  39251. editableText (true),
  39252. doubleClickToValue (false),
  39253. isVelocityBased (false),
  39254. userKeyOverridesVelocity (true),
  39255. rotaryStop (true),
  39256. incDecButtonsSideBySide (false),
  39257. sendChangeOnlyOnRelease (false),
  39258. popupDisplayEnabled (false),
  39259. menuEnabled (false),
  39260. menuShown (false),
  39261. scrollWheelEnabled (true),
  39262. snapsToMousePos (true),
  39263. valueBox (0),
  39264. incButton (0),
  39265. decButton (0),
  39266. popupDisplay (0),
  39267. parentForPopupDisplay (0)
  39268. {
  39269. setWantsKeyboardFocus (false);
  39270. setRepaintsOnMouseActivity (true);
  39271. lookAndFeelChanged();
  39272. updateText();
  39273. currentValue.addListener (this);
  39274. valueMin.addListener (this);
  39275. valueMax.addListener (this);
  39276. }
  39277. Slider::~Slider()
  39278. {
  39279. currentValue.removeListener (this);
  39280. valueMin.removeListener (this);
  39281. valueMax.removeListener (this);
  39282. popupDisplay = 0;
  39283. deleteAllChildren();
  39284. }
  39285. void Slider::handleAsyncUpdate()
  39286. {
  39287. cancelPendingUpdate();
  39288. for (int i = listeners.size(); --i >= 0;)
  39289. {
  39290. ((SliderListener*) listeners.getUnchecked (i))->sliderValueChanged (this);
  39291. i = jmin (i, listeners.size());
  39292. }
  39293. }
  39294. void Slider::sendDragStart()
  39295. {
  39296. startedDragging();
  39297. for (int i = listeners.size(); --i >= 0;)
  39298. {
  39299. ((SliderListener*) listeners.getUnchecked (i))->sliderDragStarted (this);
  39300. i = jmin (i, listeners.size());
  39301. }
  39302. }
  39303. void Slider::sendDragEnd()
  39304. {
  39305. stoppedDragging();
  39306. sliderBeingDragged = -1;
  39307. for (int i = listeners.size(); --i >= 0;)
  39308. {
  39309. ((SliderListener*) listeners.getUnchecked (i))->sliderDragEnded (this);
  39310. i = jmin (i, listeners.size());
  39311. }
  39312. }
  39313. void Slider::addListener (SliderListener* const listener)
  39314. {
  39315. jassert (listener != 0);
  39316. if (listener != 0)
  39317. listeners.add (listener);
  39318. }
  39319. void Slider::removeListener (SliderListener* const listener)
  39320. {
  39321. listeners.removeValue (listener);
  39322. }
  39323. void Slider::setSliderStyle (const SliderStyle newStyle)
  39324. {
  39325. if (style != newStyle)
  39326. {
  39327. style = newStyle;
  39328. repaint();
  39329. lookAndFeelChanged();
  39330. }
  39331. }
  39332. void Slider::setRotaryParameters (const float startAngleRadians,
  39333. const float endAngleRadians,
  39334. const bool stopAtEnd)
  39335. {
  39336. // make sure the values are sensible..
  39337. jassert (rotaryStart >= 0 && rotaryEnd >= 0);
  39338. jassert (rotaryStart < float_Pi * 4.0f && rotaryEnd < float_Pi * 4.0f);
  39339. jassert (rotaryStart < rotaryEnd);
  39340. rotaryStart = startAngleRadians;
  39341. rotaryEnd = endAngleRadians;
  39342. rotaryStop = stopAtEnd;
  39343. }
  39344. void Slider::setVelocityBasedMode (const bool velBased)
  39345. {
  39346. isVelocityBased = velBased;
  39347. }
  39348. void Slider::setVelocityModeParameters (const double sensitivity,
  39349. const int threshold,
  39350. const double offset,
  39351. const bool userCanPressKeyToSwapMode)
  39352. {
  39353. jassert (threshold >= 0);
  39354. jassert (sensitivity > 0);
  39355. jassert (offset >= 0);
  39356. velocityModeSensitivity = sensitivity;
  39357. velocityModeOffset = offset;
  39358. velocityModeThreshold = threshold;
  39359. userKeyOverridesVelocity = userCanPressKeyToSwapMode;
  39360. }
  39361. void Slider::setSkewFactor (const double factor)
  39362. {
  39363. skewFactor = factor;
  39364. }
  39365. void Slider::setSkewFactorFromMidPoint (const double sliderValueToShowAtMidPoint)
  39366. {
  39367. if (maximum > minimum)
  39368. skewFactor = log (0.5) / log ((sliderValueToShowAtMidPoint - minimum)
  39369. / (maximum - minimum));
  39370. }
  39371. void Slider::setMouseDragSensitivity (const int distanceForFullScaleDrag)
  39372. {
  39373. jassert (distanceForFullScaleDrag > 0);
  39374. pixelsForFullDragExtent = distanceForFullScaleDrag;
  39375. }
  39376. void Slider::setIncDecButtonsMode (const IncDecButtonMode mode)
  39377. {
  39378. if (incDecButtonMode != mode)
  39379. {
  39380. incDecButtonMode = mode;
  39381. lookAndFeelChanged();
  39382. }
  39383. }
  39384. void Slider::setTextBoxStyle (const TextEntryBoxPosition newPosition,
  39385. const bool isReadOnly,
  39386. const int textEntryBoxWidth,
  39387. const int textEntryBoxHeight)
  39388. {
  39389. textBoxPos = newPosition;
  39390. editableText = ! isReadOnly;
  39391. textBoxWidth = textEntryBoxWidth;
  39392. textBoxHeight = textEntryBoxHeight;
  39393. repaint();
  39394. lookAndFeelChanged();
  39395. }
  39396. void Slider::setTextBoxIsEditable (const bool shouldBeEditable)
  39397. {
  39398. editableText = shouldBeEditable;
  39399. if (valueBox != 0)
  39400. valueBox->setEditable (shouldBeEditable && isEnabled());
  39401. }
  39402. void Slider::showTextBox()
  39403. {
  39404. jassert (editableText); // this should probably be avoided in read-only sliders.
  39405. if (valueBox != 0)
  39406. valueBox->showEditor();
  39407. }
  39408. void Slider::hideTextBox (const bool discardCurrentEditorContents)
  39409. {
  39410. if (valueBox != 0)
  39411. {
  39412. valueBox->hideEditor (discardCurrentEditorContents);
  39413. if (discardCurrentEditorContents)
  39414. updateText();
  39415. }
  39416. }
  39417. void Slider::setChangeNotificationOnlyOnRelease (const bool onlyNotifyOnRelease)
  39418. {
  39419. sendChangeOnlyOnRelease = onlyNotifyOnRelease;
  39420. }
  39421. void Slider::setSliderSnapsToMousePosition (const bool shouldSnapToMouse)
  39422. {
  39423. snapsToMousePos = shouldSnapToMouse;
  39424. }
  39425. void Slider::setPopupDisplayEnabled (const bool enabled,
  39426. Component* const parentComponentToUse)
  39427. {
  39428. popupDisplayEnabled = enabled;
  39429. parentForPopupDisplay = parentComponentToUse;
  39430. }
  39431. void Slider::colourChanged()
  39432. {
  39433. lookAndFeelChanged();
  39434. }
  39435. void Slider::lookAndFeelChanged()
  39436. {
  39437. const String previousTextBoxContent (valueBox != 0 ? valueBox->getText()
  39438. : getTextFromValue (currentValue.getValue()));
  39439. deleteAllChildren();
  39440. valueBox = 0;
  39441. LookAndFeel& lf = getLookAndFeel();
  39442. if (textBoxPos != NoTextBox)
  39443. {
  39444. addAndMakeVisible (valueBox = getLookAndFeel().createSliderTextBox (*this));
  39445. valueBox->setWantsKeyboardFocus (false);
  39446. valueBox->setText (previousTextBoxContent, false);
  39447. valueBox->setEditable (editableText && isEnabled());
  39448. valueBox->addListener (this);
  39449. if (style == LinearBar)
  39450. valueBox->addMouseListener (this, false);
  39451. valueBox->setTooltip (getTooltip());
  39452. }
  39453. if (style == IncDecButtons)
  39454. {
  39455. addAndMakeVisible (incButton = lf.createSliderButton (true));
  39456. incButton->addButtonListener (this);
  39457. addAndMakeVisible (decButton = lf.createSliderButton (false));
  39458. decButton->addButtonListener (this);
  39459. if (incDecButtonMode != incDecButtonsNotDraggable)
  39460. {
  39461. incButton->addMouseListener (this, false);
  39462. decButton->addMouseListener (this, false);
  39463. }
  39464. else
  39465. {
  39466. incButton->setRepeatSpeed (300, 100, 20);
  39467. incButton->addMouseListener (decButton, false);
  39468. decButton->setRepeatSpeed (300, 100, 20);
  39469. decButton->addMouseListener (incButton, false);
  39470. }
  39471. incButton->setTooltip (getTooltip());
  39472. decButton->setTooltip (getTooltip());
  39473. }
  39474. setComponentEffect (lf.getSliderEffect());
  39475. resized();
  39476. repaint();
  39477. }
  39478. void Slider::setRange (const double newMin,
  39479. const double newMax,
  39480. const double newInt)
  39481. {
  39482. if (minimum != newMin
  39483. || maximum != newMax
  39484. || interval != newInt)
  39485. {
  39486. minimum = newMin;
  39487. maximum = newMax;
  39488. interval = newInt;
  39489. // figure out the number of DPs needed to display all values at this
  39490. // interval setting.
  39491. numDecimalPlaces = 7;
  39492. if (newInt != 0)
  39493. {
  39494. int v = abs ((int) (newInt * 10000000));
  39495. while ((v % 10) == 0)
  39496. {
  39497. --numDecimalPlaces;
  39498. v /= 10;
  39499. }
  39500. }
  39501. // keep the current values inside the new range..
  39502. if (style != TwoValueHorizontal && style != TwoValueVertical)
  39503. {
  39504. setValue (getValue(), false, false);
  39505. }
  39506. else
  39507. {
  39508. setMinValue (getMinValue(), false, false);
  39509. setMaxValue (getMaxValue(), false, false);
  39510. }
  39511. updateText();
  39512. }
  39513. }
  39514. void Slider::triggerChangeMessage (const bool synchronous)
  39515. {
  39516. if (synchronous)
  39517. handleAsyncUpdate();
  39518. else
  39519. triggerAsyncUpdate();
  39520. valueChanged();
  39521. }
  39522. void Slider::valueChanged (Value& value)
  39523. {
  39524. if (value.refersToSameSourceAs (currentValue))
  39525. {
  39526. if (style != TwoValueHorizontal && style != TwoValueVertical)
  39527. setValue (currentValue.getValue(), false, false);
  39528. }
  39529. else if (value.refersToSameSourceAs (valueMin))
  39530. setMinValue (valueMin.getValue(), false, false, true);
  39531. else if (value.refersToSameSourceAs (valueMax))
  39532. setMaxValue (valueMax.getValue(), false, false, true);
  39533. }
  39534. double Slider::getValue() const
  39535. {
  39536. // for a two-value style slider, you should use the getMinValue() and getMaxValue()
  39537. // methods to get the two values.
  39538. jassert (style != TwoValueHorizontal && style != TwoValueVertical);
  39539. return currentValue.getValue();
  39540. }
  39541. void Slider::setValue (double newValue,
  39542. const bool sendUpdateMessage,
  39543. const bool sendMessageSynchronously)
  39544. {
  39545. // for a two-value style slider, you should use the setMinValue() and setMaxValue()
  39546. // methods to set the two values.
  39547. jassert (style != TwoValueHorizontal && style != TwoValueVertical);
  39548. newValue = constrainedValue (newValue);
  39549. if (style == ThreeValueHorizontal || style == ThreeValueVertical)
  39550. {
  39551. jassert ((double) valueMin.getValue() <= (double) valueMax.getValue());
  39552. newValue = jlimit ((double) valueMin.getValue(),
  39553. (double) valueMax.getValue(),
  39554. newValue);
  39555. }
  39556. if (newValue != lastCurrentValue)
  39557. {
  39558. if (valueBox != 0)
  39559. valueBox->hideEditor (true);
  39560. lastCurrentValue = newValue;
  39561. currentValue = newValue;
  39562. updateText();
  39563. repaint();
  39564. if (popupDisplay != 0)
  39565. {
  39566. ((SliderPopupDisplayComponent*) popupDisplay)->updatePosition (getTextFromValue (newValue));
  39567. popupDisplay->repaint();
  39568. }
  39569. if (sendUpdateMessage)
  39570. triggerChangeMessage (sendMessageSynchronously);
  39571. }
  39572. }
  39573. double Slider::getMinValue() const
  39574. {
  39575. // The minimum value only applies to sliders that are in two- or three-value mode.
  39576. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  39577. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  39578. return valueMin.getValue();
  39579. }
  39580. double Slider::getMaxValue() const
  39581. {
  39582. // The maximum value only applies to sliders that are in two- or three-value mode.
  39583. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  39584. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  39585. return valueMax.getValue();
  39586. }
  39587. void Slider::setMinValue (double newValue, const bool sendUpdateMessage, const bool sendMessageSynchronously, const bool allowNudgingOfOtherValues)
  39588. {
  39589. // The minimum value only applies to sliders that are in two- or three-value mode.
  39590. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  39591. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  39592. newValue = constrainedValue (newValue);
  39593. if (style == TwoValueHorizontal || style == TwoValueVertical)
  39594. {
  39595. if (allowNudgingOfOtherValues && newValue > (double) valueMax.getValue())
  39596. setMaxValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  39597. newValue = jmin ((double) valueMax.getValue(), newValue);
  39598. }
  39599. else
  39600. {
  39601. if (allowNudgingOfOtherValues && newValue > lastCurrentValue)
  39602. setValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  39603. newValue = jmin (lastCurrentValue, newValue);
  39604. }
  39605. if (lastValueMin != newValue)
  39606. {
  39607. lastValueMin = newValue;
  39608. valueMin = newValue;
  39609. repaint();
  39610. if (popupDisplay != 0)
  39611. {
  39612. ((SliderPopupDisplayComponent*) popupDisplay)->updatePosition (getTextFromValue (newValue));
  39613. popupDisplay->repaint();
  39614. }
  39615. if (sendUpdateMessage)
  39616. triggerChangeMessage (sendMessageSynchronously);
  39617. }
  39618. }
  39619. void Slider::setMaxValue (double newValue, const bool sendUpdateMessage, const bool sendMessageSynchronously, const bool allowNudgingOfOtherValues)
  39620. {
  39621. // The maximum value only applies to sliders that are in two- or three-value mode.
  39622. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  39623. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  39624. newValue = constrainedValue (newValue);
  39625. if (style == TwoValueHorizontal || style == TwoValueVertical)
  39626. {
  39627. if (allowNudgingOfOtherValues && newValue < (double) valueMin.getValue())
  39628. setMinValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  39629. newValue = jmax ((double) valueMin.getValue(), newValue);
  39630. }
  39631. else
  39632. {
  39633. if (allowNudgingOfOtherValues && newValue < lastCurrentValue)
  39634. setValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  39635. newValue = jmax (lastCurrentValue, newValue);
  39636. }
  39637. if (lastValueMax != newValue)
  39638. {
  39639. lastValueMax = newValue;
  39640. valueMax = newValue;
  39641. repaint();
  39642. if (popupDisplay != 0)
  39643. {
  39644. ((SliderPopupDisplayComponent*) popupDisplay)->updatePosition (getTextFromValue (valueMax.getValue()));
  39645. popupDisplay->repaint();
  39646. }
  39647. if (sendUpdateMessage)
  39648. triggerChangeMessage (sendMessageSynchronously);
  39649. }
  39650. }
  39651. void Slider::setDoubleClickReturnValue (const bool isDoubleClickEnabled,
  39652. const double valueToSetOnDoubleClick)
  39653. {
  39654. doubleClickToValue = isDoubleClickEnabled;
  39655. doubleClickReturnValue = valueToSetOnDoubleClick;
  39656. }
  39657. double Slider::getDoubleClickReturnValue (bool& isEnabled_) const
  39658. {
  39659. isEnabled_ = doubleClickToValue;
  39660. return doubleClickReturnValue;
  39661. }
  39662. void Slider::updateText()
  39663. {
  39664. if (valueBox != 0)
  39665. valueBox->setText (getTextFromValue (currentValue.getValue()), false);
  39666. }
  39667. void Slider::setTextValueSuffix (const String& suffix)
  39668. {
  39669. if (textSuffix != suffix)
  39670. {
  39671. textSuffix = suffix;
  39672. updateText();
  39673. }
  39674. }
  39675. const String Slider::getTextFromValue (double v)
  39676. {
  39677. if (numDecimalPlaces > 0)
  39678. return String (v, numDecimalPlaces) + textSuffix;
  39679. else
  39680. return String (roundToInt (v)) + textSuffix;
  39681. }
  39682. double Slider::getValueFromText (const String& text)
  39683. {
  39684. String t (text.trimStart());
  39685. if (t.endsWith (textSuffix))
  39686. t = t.substring (0, t.length() - textSuffix.length());
  39687. while (t.startsWithChar (T('+')))
  39688. t = t.substring (1).trimStart();
  39689. return t.initialSectionContainingOnly (T("0123456789.,-"))
  39690. .getDoubleValue();
  39691. }
  39692. double Slider::proportionOfLengthToValue (double proportion)
  39693. {
  39694. if (skewFactor != 1.0 && proportion > 0.0)
  39695. proportion = exp (log (proportion) / skewFactor);
  39696. return minimum + (maximum - minimum) * proportion;
  39697. }
  39698. double Slider::valueToProportionOfLength (double value)
  39699. {
  39700. const double n = (value - minimum) / (maximum - minimum);
  39701. return skewFactor == 1.0 ? n : pow (n, skewFactor);
  39702. }
  39703. double Slider::snapValue (double attemptedValue, const bool)
  39704. {
  39705. return attemptedValue;
  39706. }
  39707. void Slider::startedDragging()
  39708. {
  39709. }
  39710. void Slider::stoppedDragging()
  39711. {
  39712. }
  39713. void Slider::valueChanged()
  39714. {
  39715. }
  39716. void Slider::enablementChanged()
  39717. {
  39718. repaint();
  39719. }
  39720. void Slider::setPopupMenuEnabled (const bool menuEnabled_)
  39721. {
  39722. menuEnabled = menuEnabled_;
  39723. }
  39724. void Slider::setScrollWheelEnabled (const bool enabled)
  39725. {
  39726. scrollWheelEnabled = enabled;
  39727. }
  39728. void Slider::labelTextChanged (Label* label)
  39729. {
  39730. const double newValue = snapValue (getValueFromText (label->getText()), false);
  39731. if (newValue != (double) currentValue.getValue())
  39732. {
  39733. sendDragStart();
  39734. setValue (newValue, true, true);
  39735. sendDragEnd();
  39736. }
  39737. updateText(); // force a clean-up of the text, needed in case setValue() hasn't done this.
  39738. }
  39739. void Slider::buttonClicked (Button* button)
  39740. {
  39741. if (style == IncDecButtons)
  39742. {
  39743. sendDragStart();
  39744. if (button == incButton)
  39745. setValue (snapValue (getValue() + interval, false), true, true);
  39746. else if (button == decButton)
  39747. setValue (snapValue (getValue() - interval, false), true, true);
  39748. sendDragEnd();
  39749. }
  39750. }
  39751. double Slider::constrainedValue (double value) const
  39752. {
  39753. if (interval > 0)
  39754. value = minimum + interval * floor ((value - minimum) / interval + 0.5);
  39755. if (value <= minimum || maximum <= minimum)
  39756. value = minimum;
  39757. else if (value >= maximum)
  39758. value = maximum;
  39759. return value;
  39760. }
  39761. float Slider::getLinearSliderPos (const double value)
  39762. {
  39763. double sliderPosProportional;
  39764. if (maximum > minimum)
  39765. {
  39766. if (value < minimum)
  39767. {
  39768. sliderPosProportional = 0.0;
  39769. }
  39770. else if (value > maximum)
  39771. {
  39772. sliderPosProportional = 1.0;
  39773. }
  39774. else
  39775. {
  39776. sliderPosProportional = valueToProportionOfLength (value);
  39777. jassert (sliderPosProportional >= 0 && sliderPosProportional <= 1.0);
  39778. }
  39779. }
  39780. else
  39781. {
  39782. sliderPosProportional = 0.5;
  39783. }
  39784. if (isVertical() || style == IncDecButtons)
  39785. sliderPosProportional = 1.0 - sliderPosProportional;
  39786. return (float) (sliderRegionStart + sliderPosProportional * sliderRegionSize);
  39787. }
  39788. bool Slider::isHorizontal() const
  39789. {
  39790. return style == LinearHorizontal
  39791. || style == LinearBar
  39792. || style == TwoValueHorizontal
  39793. || style == ThreeValueHorizontal;
  39794. }
  39795. bool Slider::isVertical() const
  39796. {
  39797. return style == LinearVertical
  39798. || style == TwoValueVertical
  39799. || style == ThreeValueVertical;
  39800. }
  39801. bool Slider::incDecDragDirectionIsHorizontal() const
  39802. {
  39803. return incDecButtonMode == incDecButtonsDraggable_Horizontal
  39804. || (incDecButtonMode == incDecButtonsDraggable_AutoDirection && incDecButtonsSideBySide);
  39805. }
  39806. float Slider::getPositionOfValue (const double value)
  39807. {
  39808. if (isHorizontal() || isVertical())
  39809. {
  39810. return getLinearSliderPos (value);
  39811. }
  39812. else
  39813. {
  39814. jassertfalse // not a valid call on a slider that doesn't work linearly!
  39815. return 0.0f;
  39816. }
  39817. }
  39818. void Slider::paint (Graphics& g)
  39819. {
  39820. if (style != IncDecButtons)
  39821. {
  39822. if (style == Rotary || style == RotaryHorizontalDrag || style == RotaryVerticalDrag)
  39823. {
  39824. const float sliderPos = (float) valueToProportionOfLength (lastCurrentValue);
  39825. jassert (sliderPos >= 0 && sliderPos <= 1.0f);
  39826. getLookAndFeel().drawRotarySlider (g,
  39827. sliderRect.getX(),
  39828. sliderRect.getY(),
  39829. sliderRect.getWidth(),
  39830. sliderRect.getHeight(),
  39831. sliderPos,
  39832. rotaryStart, rotaryEnd,
  39833. *this);
  39834. }
  39835. else
  39836. {
  39837. getLookAndFeel().drawLinearSlider (g,
  39838. sliderRect.getX(),
  39839. sliderRect.getY(),
  39840. sliderRect.getWidth(),
  39841. sliderRect.getHeight(),
  39842. getLinearSliderPos (lastCurrentValue),
  39843. getLinearSliderPos (lastValueMin),
  39844. getLinearSliderPos (lastValueMax),
  39845. style,
  39846. *this);
  39847. }
  39848. if (style == LinearBar && valueBox == 0)
  39849. {
  39850. g.setColour (findColour (Slider::textBoxOutlineColourId));
  39851. g.drawRect (0, 0, getWidth(), getHeight(), 1);
  39852. }
  39853. }
  39854. }
  39855. void Slider::resized()
  39856. {
  39857. int minXSpace = 0;
  39858. int minYSpace = 0;
  39859. if (textBoxPos == TextBoxLeft || textBoxPos == TextBoxRight)
  39860. minXSpace = 30;
  39861. else
  39862. minYSpace = 15;
  39863. const int tbw = jmax (0, jmin (textBoxWidth, getWidth() - minXSpace));
  39864. const int tbh = jmax (0, jmin (textBoxHeight, getHeight() - minYSpace));
  39865. if (style == LinearBar)
  39866. {
  39867. if (valueBox != 0)
  39868. valueBox->setBounds (0, 0, getWidth(), getHeight());
  39869. }
  39870. else
  39871. {
  39872. if (textBoxPos == NoTextBox)
  39873. {
  39874. sliderRect.setBounds (0, 0, getWidth(), getHeight());
  39875. }
  39876. else if (textBoxPos == TextBoxLeft)
  39877. {
  39878. valueBox->setBounds (0, (getHeight() - tbh) / 2, tbw, tbh);
  39879. sliderRect.setBounds (tbw, 0, getWidth() - tbw, getHeight());
  39880. }
  39881. else if (textBoxPos == TextBoxRight)
  39882. {
  39883. valueBox->setBounds (getWidth() - tbw, (getHeight() - tbh) / 2, tbw, tbh);
  39884. sliderRect.setBounds (0, 0, getWidth() - tbw, getHeight());
  39885. }
  39886. else if (textBoxPos == TextBoxAbove)
  39887. {
  39888. valueBox->setBounds ((getWidth() - tbw) / 2, 0, tbw, tbh);
  39889. sliderRect.setBounds (0, tbh, getWidth(), getHeight() - tbh);
  39890. }
  39891. else if (textBoxPos == TextBoxBelow)
  39892. {
  39893. valueBox->setBounds ((getWidth() - tbw) / 2, getHeight() - tbh, tbw, tbh);
  39894. sliderRect.setBounds (0, 0, getWidth(), getHeight() - tbh);
  39895. }
  39896. }
  39897. const int indent = getLookAndFeel().getSliderThumbRadius (*this);
  39898. if (style == LinearBar)
  39899. {
  39900. const int barIndent = 1;
  39901. sliderRegionStart = barIndent;
  39902. sliderRegionSize = getWidth() - barIndent * 2;
  39903. sliderRect.setBounds (sliderRegionStart, barIndent,
  39904. sliderRegionSize, getHeight() - barIndent * 2);
  39905. }
  39906. else if (isHorizontal())
  39907. {
  39908. sliderRegionStart = sliderRect.getX() + indent;
  39909. sliderRegionSize = jmax (1, sliderRect.getWidth() - indent * 2);
  39910. sliderRect.setBounds (sliderRegionStart, sliderRect.getY(),
  39911. sliderRegionSize, sliderRect.getHeight());
  39912. }
  39913. else if (isVertical())
  39914. {
  39915. sliderRegionStart = sliderRect.getY() + indent;
  39916. sliderRegionSize = jmax (1, sliderRect.getHeight() - indent * 2);
  39917. sliderRect.setBounds (sliderRect.getX(), sliderRegionStart,
  39918. sliderRect.getWidth(), sliderRegionSize);
  39919. }
  39920. else
  39921. {
  39922. sliderRegionStart = 0;
  39923. sliderRegionSize = 100;
  39924. }
  39925. if (style == IncDecButtons)
  39926. {
  39927. Rectangle<int> buttonRect (sliderRect);
  39928. if (textBoxPos == TextBoxLeft || textBoxPos == TextBoxRight)
  39929. buttonRect.expand (-2, 0);
  39930. else
  39931. buttonRect.expand (0, -2);
  39932. incDecButtonsSideBySide = buttonRect.getWidth() > buttonRect.getHeight();
  39933. if (incDecButtonsSideBySide)
  39934. {
  39935. decButton->setBounds (buttonRect.getX(),
  39936. buttonRect.getY(),
  39937. buttonRect.getWidth() / 2,
  39938. buttonRect.getHeight());
  39939. decButton->setConnectedEdges (Button::ConnectedOnRight);
  39940. incButton->setBounds (buttonRect.getCentreX(),
  39941. buttonRect.getY(),
  39942. buttonRect.getWidth() / 2,
  39943. buttonRect.getHeight());
  39944. incButton->setConnectedEdges (Button::ConnectedOnLeft);
  39945. }
  39946. else
  39947. {
  39948. incButton->setBounds (buttonRect.getX(),
  39949. buttonRect.getY(),
  39950. buttonRect.getWidth(),
  39951. buttonRect.getHeight() / 2);
  39952. incButton->setConnectedEdges (Button::ConnectedOnBottom);
  39953. decButton->setBounds (buttonRect.getX(),
  39954. buttonRect.getCentreY(),
  39955. buttonRect.getWidth(),
  39956. buttonRect.getHeight() / 2);
  39957. decButton->setConnectedEdges (Button::ConnectedOnTop);
  39958. }
  39959. }
  39960. }
  39961. void Slider::focusOfChildComponentChanged (FocusChangeType)
  39962. {
  39963. repaint();
  39964. }
  39965. void Slider::mouseDown (const MouseEvent& e)
  39966. {
  39967. mouseWasHidden = false;
  39968. incDecDragged = false;
  39969. mouseXWhenLastDragged = e.x;
  39970. mouseYWhenLastDragged = e.y;
  39971. mouseDragStartX = e.getMouseDownX();
  39972. mouseDragStartY = e.getMouseDownY();
  39973. if (isEnabled())
  39974. {
  39975. if (e.mods.isPopupMenu() && menuEnabled)
  39976. {
  39977. menuShown = true;
  39978. PopupMenu m;
  39979. m.setLookAndFeel (&getLookAndFeel());
  39980. m.addItem (1, TRANS ("velocity-sensitive mode"), true, isVelocityBased);
  39981. m.addSeparator();
  39982. if (style == Rotary || style == RotaryHorizontalDrag || style == RotaryVerticalDrag)
  39983. {
  39984. PopupMenu rotaryMenu;
  39985. rotaryMenu.addItem (2, TRANS ("use circular dragging"), true, style == Rotary);
  39986. rotaryMenu.addItem (3, TRANS ("use left-right dragging"), true, style == RotaryHorizontalDrag);
  39987. rotaryMenu.addItem (4, TRANS ("use up-down dragging"), true, style == RotaryVerticalDrag);
  39988. m.addSubMenu (TRANS ("rotary mode"), rotaryMenu);
  39989. }
  39990. const int r = m.show();
  39991. if (r == 1)
  39992. {
  39993. setVelocityBasedMode (! isVelocityBased);
  39994. }
  39995. else if (r == 2)
  39996. {
  39997. setSliderStyle (Rotary);
  39998. }
  39999. else if (r == 3)
  40000. {
  40001. setSliderStyle (RotaryHorizontalDrag);
  40002. }
  40003. else if (r == 4)
  40004. {
  40005. setSliderStyle (RotaryVerticalDrag);
  40006. }
  40007. }
  40008. else if (maximum > minimum)
  40009. {
  40010. menuShown = false;
  40011. if (valueBox != 0)
  40012. valueBox->hideEditor (true);
  40013. sliderBeingDragged = 0;
  40014. if (style == TwoValueHorizontal
  40015. || style == TwoValueVertical
  40016. || style == ThreeValueHorizontal
  40017. || style == ThreeValueVertical)
  40018. {
  40019. const float mousePos = (float) (isVertical() ? e.y : e.x);
  40020. const float normalPosDistance = fabsf (getLinearSliderPos (currentValue.getValue()) - mousePos);
  40021. const float minPosDistance = fabsf (getLinearSliderPos (valueMin.getValue()) - 0.1f - mousePos);
  40022. const float maxPosDistance = fabsf (getLinearSliderPos (valueMax.getValue()) + 0.1f - mousePos);
  40023. if (style == TwoValueHorizontal || style == TwoValueVertical)
  40024. {
  40025. if (maxPosDistance <= minPosDistance)
  40026. sliderBeingDragged = 2;
  40027. else
  40028. sliderBeingDragged = 1;
  40029. }
  40030. else if (style == ThreeValueHorizontal || style == ThreeValueVertical)
  40031. {
  40032. if (normalPosDistance >= minPosDistance && maxPosDistance >= minPosDistance)
  40033. sliderBeingDragged = 1;
  40034. else if (normalPosDistance >= maxPosDistance)
  40035. sliderBeingDragged = 2;
  40036. }
  40037. }
  40038. minMaxDiff = (double) valueMax.getValue() - (double) valueMin.getValue();
  40039. lastAngle = rotaryStart + (rotaryEnd - rotaryStart)
  40040. * valueToProportionOfLength (currentValue.getValue());
  40041. valueWhenLastDragged = ((sliderBeingDragged == 2) ? valueMax
  40042. : ((sliderBeingDragged == 1) ? valueMin
  40043. : currentValue)).getValue();
  40044. valueOnMouseDown = valueWhenLastDragged;
  40045. if (popupDisplayEnabled)
  40046. {
  40047. SliderPopupDisplayComponent* const popup = new SliderPopupDisplayComponent (this);
  40048. popupDisplay = popup;
  40049. if (parentForPopupDisplay != 0)
  40050. {
  40051. parentForPopupDisplay->addChildComponent (popup);
  40052. }
  40053. else
  40054. {
  40055. popup->addToDesktop (0);
  40056. }
  40057. popup->setVisible (true);
  40058. }
  40059. sendDragStart();
  40060. mouseDrag (e);
  40061. }
  40062. }
  40063. }
  40064. void Slider::mouseUp (const MouseEvent&)
  40065. {
  40066. if (isEnabled()
  40067. && (! menuShown)
  40068. && (maximum > minimum)
  40069. && (style != IncDecButtons || incDecDragged))
  40070. {
  40071. restoreMouseIfHidden();
  40072. if (sendChangeOnlyOnRelease && valueOnMouseDown != (double) currentValue.getValue())
  40073. triggerChangeMessage (false);
  40074. sendDragEnd();
  40075. popupDisplay = 0;
  40076. if (style == IncDecButtons)
  40077. {
  40078. incButton->setState (Button::buttonNormal);
  40079. decButton->setState (Button::buttonNormal);
  40080. }
  40081. }
  40082. }
  40083. void Slider::restoreMouseIfHidden()
  40084. {
  40085. if (mouseWasHidden)
  40086. {
  40087. mouseWasHidden = false;
  40088. Component* c = Component::getComponentUnderMouse();
  40089. if (c == 0)
  40090. c = this;
  40091. c->enableUnboundedMouseMovement (false);
  40092. const double pos = (sliderBeingDragged == 2) ? getMaxValue()
  40093. : ((sliderBeingDragged == 1) ? getMinValue()
  40094. : (double) currentValue.getValue());
  40095. if (style == RotaryHorizontalDrag || style == RotaryVerticalDrag)
  40096. {
  40097. int x, y, downX, downY;
  40098. Desktop::getMousePosition (x, y);
  40099. Desktop::getLastMouseDownPosition (downX, downY);
  40100. if (style == RotaryHorizontalDrag)
  40101. {
  40102. const double posDiff = valueToProportionOfLength (pos) - valueToProportionOfLength (valueOnMouseDown);
  40103. x = roundToInt (pixelsForFullDragExtent * posDiff + downX);
  40104. y = downY;
  40105. }
  40106. else
  40107. {
  40108. const double posDiff = valueToProportionOfLength (valueOnMouseDown) - valueToProportionOfLength (pos);
  40109. x = downX;
  40110. y = roundToInt (pixelsForFullDragExtent * posDiff + downY);
  40111. }
  40112. Desktop::setMousePosition (x, y);
  40113. }
  40114. else
  40115. {
  40116. const int pixelPos = (int) getLinearSliderPos (pos);
  40117. int x = isHorizontal() ? pixelPos : (getWidth() / 2);
  40118. int y = isVertical() ? pixelPos : (getHeight() / 2);
  40119. relativePositionToGlobal (x, y);
  40120. Desktop::setMousePosition (x, y);
  40121. }
  40122. }
  40123. }
  40124. void Slider::modifierKeysChanged (const ModifierKeys& modifiers)
  40125. {
  40126. if (isEnabled()
  40127. && style != IncDecButtons
  40128. && style != Rotary
  40129. && isVelocityBased == modifiers.isAnyModifierKeyDown())
  40130. {
  40131. restoreMouseIfHidden();
  40132. }
  40133. }
  40134. static double smallestAngleBetween (double a1, double a2)
  40135. {
  40136. return jmin (fabs (a1 - a2),
  40137. fabs (a1 + double_Pi * 2.0 - a2),
  40138. fabs (a2 + double_Pi * 2.0 - a1));
  40139. }
  40140. void Slider::mouseDrag (const MouseEvent& e)
  40141. {
  40142. if (isEnabled()
  40143. && (! menuShown)
  40144. && (maximum > minimum))
  40145. {
  40146. if (style == Rotary)
  40147. {
  40148. int dx = e.x - sliderRect.getCentreX();
  40149. int dy = e.y - sliderRect.getCentreY();
  40150. if (dx * dx + dy * dy > 25)
  40151. {
  40152. double angle = atan2 ((double) dx, (double) -dy);
  40153. while (angle < 0.0)
  40154. angle += double_Pi * 2.0;
  40155. if (rotaryStop && ! e.mouseWasClicked())
  40156. {
  40157. if (fabs (angle - lastAngle) > double_Pi)
  40158. {
  40159. if (angle >= lastAngle)
  40160. angle -= double_Pi * 2.0;
  40161. else
  40162. angle += double_Pi * 2.0;
  40163. }
  40164. if (angle >= lastAngle)
  40165. angle = jmin (angle, (double) jmax (rotaryStart, rotaryEnd));
  40166. else
  40167. angle = jmax (angle, (double) jmin (rotaryStart, rotaryEnd));
  40168. }
  40169. else
  40170. {
  40171. while (angle < rotaryStart)
  40172. angle += double_Pi * 2.0;
  40173. if (angle > rotaryEnd)
  40174. {
  40175. if (smallestAngleBetween (angle, rotaryStart) <= smallestAngleBetween (angle, rotaryEnd))
  40176. angle = rotaryStart;
  40177. else
  40178. angle = rotaryEnd;
  40179. }
  40180. }
  40181. const double proportion = (angle - rotaryStart) / (rotaryEnd - rotaryStart);
  40182. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, proportion));
  40183. lastAngle = angle;
  40184. }
  40185. }
  40186. else
  40187. {
  40188. if (style == LinearBar && e.mouseWasClicked()
  40189. && valueBox != 0 && valueBox->isEditable())
  40190. return;
  40191. if (style == IncDecButtons && ! incDecDragged)
  40192. {
  40193. if (e.getDistanceFromDragStart() < 10 || e.mouseWasClicked())
  40194. return;
  40195. incDecDragged = true;
  40196. mouseDragStartX = e.x;
  40197. mouseDragStartY = e.y;
  40198. }
  40199. if ((isVelocityBased == (userKeyOverridesVelocity ? e.mods.testFlags (ModifierKeys::ctrlModifier | ModifierKeys::commandModifier | ModifierKeys::altModifier)
  40200. : false))
  40201. || ((maximum - minimum) / sliderRegionSize < interval))
  40202. {
  40203. const int mousePos = (isHorizontal() || style == RotaryHorizontalDrag) ? e.x : e.y;
  40204. double scaledMousePos = (mousePos - sliderRegionStart) / (double) sliderRegionSize;
  40205. if (style == RotaryHorizontalDrag
  40206. || style == RotaryVerticalDrag
  40207. || style == IncDecButtons
  40208. || ((style == LinearHorizontal || style == LinearVertical || style == LinearBar)
  40209. && ! snapsToMousePos))
  40210. {
  40211. const int mouseDiff = (style == RotaryHorizontalDrag
  40212. || style == LinearHorizontal
  40213. || style == LinearBar
  40214. || (style == IncDecButtons && incDecDragDirectionIsHorizontal()))
  40215. ? e.x - mouseDragStartX
  40216. : mouseDragStartY - e.y;
  40217. double newPos = valueToProportionOfLength (valueOnMouseDown)
  40218. + mouseDiff * (1.0 / pixelsForFullDragExtent);
  40219. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, newPos));
  40220. if (style == IncDecButtons)
  40221. {
  40222. incButton->setState (mouseDiff < 0 ? Button::buttonNormal : Button::buttonDown);
  40223. decButton->setState (mouseDiff > 0 ? Button::buttonNormal : Button::buttonDown);
  40224. }
  40225. }
  40226. else
  40227. {
  40228. if (isVertical())
  40229. scaledMousePos = 1.0 - scaledMousePos;
  40230. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, scaledMousePos));
  40231. }
  40232. }
  40233. else
  40234. {
  40235. const int mouseDiff = (isHorizontal() || style == RotaryHorizontalDrag
  40236. || (style == IncDecButtons && incDecDragDirectionIsHorizontal()))
  40237. ? e.x - mouseXWhenLastDragged
  40238. : e.y - mouseYWhenLastDragged;
  40239. const double maxSpeed = jmax (200, sliderRegionSize);
  40240. double speed = jlimit (0.0, maxSpeed, (double) abs (mouseDiff));
  40241. if (speed != 0)
  40242. {
  40243. speed = 0.2 * velocityModeSensitivity
  40244. * (1.0 + sin (double_Pi * (1.5 + jmin (0.5, velocityModeOffset
  40245. + jmax (0.0, (double) (speed - velocityModeThreshold))
  40246. / maxSpeed))));
  40247. if (mouseDiff < 0)
  40248. speed = -speed;
  40249. if (isVertical() || style == RotaryVerticalDrag
  40250. || (style == IncDecButtons && ! incDecDragDirectionIsHorizontal()))
  40251. speed = -speed;
  40252. const double currentPos = valueToProportionOfLength (valueWhenLastDragged);
  40253. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, currentPos + speed));
  40254. e.originalComponent->enableUnboundedMouseMovement (true, false);
  40255. mouseWasHidden = true;
  40256. }
  40257. }
  40258. }
  40259. valueWhenLastDragged = jlimit (minimum, maximum, valueWhenLastDragged);
  40260. if (sliderBeingDragged == 0)
  40261. {
  40262. setValue (snapValue (valueWhenLastDragged, true),
  40263. ! sendChangeOnlyOnRelease, true);
  40264. }
  40265. else if (sliderBeingDragged == 1)
  40266. {
  40267. setMinValue (snapValue (valueWhenLastDragged, true),
  40268. ! sendChangeOnlyOnRelease, false, true);
  40269. if (e.mods.isShiftDown())
  40270. setMaxValue (getMinValue() + minMaxDiff, false, false, true);
  40271. else
  40272. minMaxDiff = (double) valueMax.getValue() - (double) valueMin.getValue();
  40273. }
  40274. else
  40275. {
  40276. jassert (sliderBeingDragged == 2);
  40277. setMaxValue (snapValue (valueWhenLastDragged, true),
  40278. ! sendChangeOnlyOnRelease, false, true);
  40279. if (e.mods.isShiftDown())
  40280. setMinValue (getMaxValue() - minMaxDiff, false, false, true);
  40281. else
  40282. minMaxDiff = (double) valueMax.getValue() - (double) valueMin.getValue();
  40283. }
  40284. mouseXWhenLastDragged = e.x;
  40285. mouseYWhenLastDragged = e.y;
  40286. }
  40287. }
  40288. void Slider::mouseDoubleClick (const MouseEvent&)
  40289. {
  40290. if (doubleClickToValue
  40291. && isEnabled()
  40292. && style != IncDecButtons
  40293. && minimum <= doubleClickReturnValue
  40294. && maximum >= doubleClickReturnValue)
  40295. {
  40296. sendDragStart();
  40297. setValue (doubleClickReturnValue, true, true);
  40298. sendDragEnd();
  40299. }
  40300. }
  40301. void Slider::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  40302. {
  40303. if (scrollWheelEnabled && isEnabled()
  40304. && style != TwoValueHorizontal
  40305. && style != TwoValueVertical)
  40306. {
  40307. if (maximum > minimum && ! isMouseButtonDownAnywhere())
  40308. {
  40309. if (valueBox != 0)
  40310. valueBox->hideEditor (false);
  40311. const double value = (double) currentValue.getValue();
  40312. const double proportionDelta = (wheelIncrementX != 0 ? -wheelIncrementX : wheelIncrementY) * 0.15f;
  40313. const double currentPos = valueToProportionOfLength (value);
  40314. const double newValue = proportionOfLengthToValue (jlimit (0.0, 1.0, currentPos + proportionDelta));
  40315. double delta = (newValue != value)
  40316. ? jmax (fabs (newValue - value), interval) : 0;
  40317. if (value > newValue)
  40318. delta = -delta;
  40319. sendDragStart();
  40320. setValue (snapValue (value + delta, false), true, true);
  40321. sendDragEnd();
  40322. }
  40323. }
  40324. else
  40325. {
  40326. Component::mouseWheelMove (e, wheelIncrementX, wheelIncrementY);
  40327. }
  40328. }
  40329. void SliderListener::sliderDragStarted (Slider*)
  40330. {
  40331. }
  40332. void SliderListener::sliderDragEnded (Slider*)
  40333. {
  40334. }
  40335. END_JUCE_NAMESPACE
  40336. /*** End of inlined file: juce_Slider.cpp ***/
  40337. /*** Start of inlined file: juce_TableHeaderComponent.cpp ***/
  40338. BEGIN_JUCE_NAMESPACE
  40339. class DragOverlayComp : public Component
  40340. {
  40341. public:
  40342. DragOverlayComp (Image* const image_)
  40343. : image (image_)
  40344. {
  40345. image->multiplyAllAlphas (0.8f);
  40346. setAlwaysOnTop (true);
  40347. }
  40348. ~DragOverlayComp()
  40349. {
  40350. }
  40351. void paint (Graphics& g)
  40352. {
  40353. g.drawImageAt (image, 0, 0);
  40354. }
  40355. private:
  40356. ScopedPointer <Image> image;
  40357. DragOverlayComp (const DragOverlayComp&);
  40358. const DragOverlayComp& operator= (const DragOverlayComp&);
  40359. };
  40360. TableHeaderComponent::TableHeaderComponent()
  40361. : columnsChanged (false),
  40362. columnsResized (false),
  40363. sortChanged (false),
  40364. menuActive (true),
  40365. stretchToFit (false),
  40366. columnIdBeingResized (0),
  40367. columnIdBeingDragged (0),
  40368. columnIdUnderMouse (0),
  40369. lastDeliberateWidth (0)
  40370. {
  40371. }
  40372. TableHeaderComponent::~TableHeaderComponent()
  40373. {
  40374. dragOverlayComp = 0;
  40375. }
  40376. void TableHeaderComponent::setPopupMenuActive (const bool hasMenu)
  40377. {
  40378. menuActive = hasMenu;
  40379. }
  40380. bool TableHeaderComponent::isPopupMenuActive() const { return menuActive; }
  40381. int TableHeaderComponent::getNumColumns (const bool onlyCountVisibleColumns) const
  40382. {
  40383. if (onlyCountVisibleColumns)
  40384. {
  40385. int num = 0;
  40386. for (int i = columns.size(); --i >= 0;)
  40387. if (columns.getUnchecked(i)->isVisible())
  40388. ++num;
  40389. return num;
  40390. }
  40391. else
  40392. {
  40393. return columns.size();
  40394. }
  40395. }
  40396. const String TableHeaderComponent::getColumnName (const int columnId) const
  40397. {
  40398. const ColumnInfo* const ci = getInfoForId (columnId);
  40399. return ci != 0 ? ci->name : String::empty;
  40400. }
  40401. void TableHeaderComponent::setColumnName (const int columnId, const String& newName)
  40402. {
  40403. ColumnInfo* const ci = getInfoForId (columnId);
  40404. if (ci != 0 && ci->name != newName)
  40405. {
  40406. ci->name = newName;
  40407. sendColumnsChanged();
  40408. }
  40409. }
  40410. void TableHeaderComponent::addColumn (const String& columnName,
  40411. const int columnId,
  40412. const int width,
  40413. const int minimumWidth,
  40414. const int maximumWidth,
  40415. const int propertyFlags,
  40416. const int insertIndex)
  40417. {
  40418. // can't have a duplicate or null ID!
  40419. jassert (columnId != 0 && getIndexOfColumnId (columnId, false) < 0);
  40420. jassert (width > 0);
  40421. ColumnInfo* const ci = new ColumnInfo();
  40422. ci->name = columnName;
  40423. ci->id = columnId;
  40424. ci->width = width;
  40425. ci->lastDeliberateWidth = width;
  40426. ci->minimumWidth = minimumWidth;
  40427. ci->maximumWidth = maximumWidth;
  40428. if (ci->maximumWidth < 0)
  40429. ci->maximumWidth = std::numeric_limits<int>::max();
  40430. jassert (ci->maximumWidth >= ci->minimumWidth);
  40431. ci->propertyFlags = propertyFlags;
  40432. columns.insert (insertIndex, ci);
  40433. sendColumnsChanged();
  40434. }
  40435. void TableHeaderComponent::removeColumn (const int columnIdToRemove)
  40436. {
  40437. const int index = getIndexOfColumnId (columnIdToRemove, false);
  40438. if (index >= 0)
  40439. {
  40440. columns.remove (index);
  40441. sortChanged = true;
  40442. sendColumnsChanged();
  40443. }
  40444. }
  40445. void TableHeaderComponent::removeAllColumns()
  40446. {
  40447. if (columns.size() > 0)
  40448. {
  40449. columns.clear();
  40450. sendColumnsChanged();
  40451. }
  40452. }
  40453. void TableHeaderComponent::moveColumn (const int columnId, int newIndex)
  40454. {
  40455. const int currentIndex = getIndexOfColumnId (columnId, false);
  40456. newIndex = visibleIndexToTotalIndex (newIndex);
  40457. if (columns [currentIndex] != 0 && currentIndex != newIndex)
  40458. {
  40459. columns.move (currentIndex, newIndex);
  40460. sendColumnsChanged();
  40461. }
  40462. }
  40463. int TableHeaderComponent::getColumnWidth (const int columnId) const
  40464. {
  40465. const ColumnInfo* const ci = getInfoForId (columnId);
  40466. return ci != 0 ? ci->width : 0;
  40467. }
  40468. void TableHeaderComponent::setColumnWidth (const int columnId, const int newWidth)
  40469. {
  40470. ColumnInfo* const ci = getInfoForId (columnId);
  40471. if (ci != 0 && ci->width != newWidth)
  40472. {
  40473. const int numColumns = getNumColumns (true);
  40474. ci->lastDeliberateWidth = ci->width
  40475. = jlimit (ci->minimumWidth, ci->maximumWidth, newWidth);
  40476. if (stretchToFit)
  40477. {
  40478. const int index = getIndexOfColumnId (columnId, true) + 1;
  40479. if (((unsigned int) index) < (unsigned int) numColumns)
  40480. {
  40481. const int x = getColumnPosition (index).getX();
  40482. if (lastDeliberateWidth == 0)
  40483. lastDeliberateWidth = getTotalWidth();
  40484. resizeColumnsToFit (visibleIndexToTotalIndex (index), lastDeliberateWidth - x);
  40485. }
  40486. }
  40487. repaint();
  40488. columnsResized = true;
  40489. triggerAsyncUpdate();
  40490. }
  40491. }
  40492. int TableHeaderComponent::getIndexOfColumnId (const int columnId, const bool onlyCountVisibleColumns) const
  40493. {
  40494. int n = 0;
  40495. for (int i = 0; i < columns.size(); ++i)
  40496. {
  40497. if ((! onlyCountVisibleColumns) || columns.getUnchecked(i)->isVisible())
  40498. {
  40499. if (columns.getUnchecked(i)->id == columnId)
  40500. return n;
  40501. ++n;
  40502. }
  40503. }
  40504. return -1;
  40505. }
  40506. int TableHeaderComponent::getColumnIdOfIndex (int index, const bool onlyCountVisibleColumns) const
  40507. {
  40508. if (onlyCountVisibleColumns)
  40509. index = visibleIndexToTotalIndex (index);
  40510. const ColumnInfo* const ci = columns [index];
  40511. return (ci != 0) ? ci->id : 0;
  40512. }
  40513. const Rectangle<int> TableHeaderComponent::getColumnPosition (const int index) const
  40514. {
  40515. int x = 0, width = 0, n = 0;
  40516. for (int i = 0; i < columns.size(); ++i)
  40517. {
  40518. x += width;
  40519. if (columns.getUnchecked(i)->isVisible())
  40520. {
  40521. width = columns.getUnchecked(i)->width;
  40522. if (n++ == index)
  40523. break;
  40524. }
  40525. else
  40526. {
  40527. width = 0;
  40528. }
  40529. }
  40530. return Rectangle<int> (x, 0, width, getHeight());
  40531. }
  40532. int TableHeaderComponent::getColumnIdAtX (const int xToFind) const
  40533. {
  40534. if (xToFind >= 0)
  40535. {
  40536. int x = 0;
  40537. for (int i = 0; i < columns.size(); ++i)
  40538. {
  40539. const ColumnInfo* const ci = columns.getUnchecked(i);
  40540. if (ci->isVisible())
  40541. {
  40542. x += ci->width;
  40543. if (xToFind < x)
  40544. return ci->id;
  40545. }
  40546. }
  40547. }
  40548. return 0;
  40549. }
  40550. int TableHeaderComponent::getTotalWidth() const
  40551. {
  40552. int w = 0;
  40553. for (int i = columns.size(); --i >= 0;)
  40554. if (columns.getUnchecked(i)->isVisible())
  40555. w += columns.getUnchecked(i)->width;
  40556. return w;
  40557. }
  40558. void TableHeaderComponent::setStretchToFitActive (const bool shouldStretchToFit)
  40559. {
  40560. stretchToFit = shouldStretchToFit;
  40561. lastDeliberateWidth = getTotalWidth();
  40562. resized();
  40563. }
  40564. bool TableHeaderComponent::isStretchToFitActive() const
  40565. {
  40566. return stretchToFit;
  40567. }
  40568. void TableHeaderComponent::resizeAllColumnsToFit (int targetTotalWidth)
  40569. {
  40570. if (stretchToFit && getWidth() > 0
  40571. && columnIdBeingResized == 0 && columnIdBeingDragged == 0)
  40572. {
  40573. lastDeliberateWidth = targetTotalWidth;
  40574. resizeColumnsToFit (0, targetTotalWidth);
  40575. }
  40576. }
  40577. void TableHeaderComponent::resizeColumnsToFit (int firstColumnIndex, int targetTotalWidth)
  40578. {
  40579. targetTotalWidth = jmax (targetTotalWidth, 0);
  40580. StretchableObjectResizer sor;
  40581. int i;
  40582. for (i = firstColumnIndex; i < columns.size(); ++i)
  40583. {
  40584. ColumnInfo* const ci = columns.getUnchecked(i);
  40585. if (ci->isVisible())
  40586. sor.addItem (ci->lastDeliberateWidth, ci->minimumWidth, ci->maximumWidth);
  40587. }
  40588. sor.resizeToFit (targetTotalWidth);
  40589. int visIndex = 0;
  40590. for (i = firstColumnIndex; i < columns.size(); ++i)
  40591. {
  40592. ColumnInfo* const ci = columns.getUnchecked(i);
  40593. if (ci->isVisible())
  40594. {
  40595. const int newWidth = jlimit (ci->minimumWidth, ci->maximumWidth,
  40596. (int) floor (sor.getItemSize (visIndex++)));
  40597. if (newWidth != ci->width)
  40598. {
  40599. ci->width = newWidth;
  40600. repaint();
  40601. columnsResized = true;
  40602. triggerAsyncUpdate();
  40603. }
  40604. }
  40605. }
  40606. }
  40607. void TableHeaderComponent::setColumnVisible (const int columnId, const bool shouldBeVisible)
  40608. {
  40609. ColumnInfo* const ci = getInfoForId (columnId);
  40610. if (ci != 0 && shouldBeVisible != ci->isVisible())
  40611. {
  40612. if (shouldBeVisible)
  40613. ci->propertyFlags |= visible;
  40614. else
  40615. ci->propertyFlags &= ~visible;
  40616. sendColumnsChanged();
  40617. resized();
  40618. }
  40619. }
  40620. bool TableHeaderComponent::isColumnVisible (const int columnId) const
  40621. {
  40622. const ColumnInfo* const ci = getInfoForId (columnId);
  40623. return ci != 0 && ci->isVisible();
  40624. }
  40625. void TableHeaderComponent::setSortColumnId (const int columnId, const bool sortForwards)
  40626. {
  40627. if (getSortColumnId() != columnId || isSortedForwards() != sortForwards)
  40628. {
  40629. for (int i = columns.size(); --i >= 0;)
  40630. columns.getUnchecked(i)->propertyFlags &= ~(sortedForwards | sortedBackwards);
  40631. ColumnInfo* const ci = getInfoForId (columnId);
  40632. if (ci != 0)
  40633. ci->propertyFlags |= (sortForwards ? sortedForwards : sortedBackwards);
  40634. reSortTable();
  40635. }
  40636. }
  40637. int TableHeaderComponent::getSortColumnId() const
  40638. {
  40639. for (int i = columns.size(); --i >= 0;)
  40640. if ((columns.getUnchecked(i)->propertyFlags & (sortedForwards | sortedBackwards)) != 0)
  40641. return columns.getUnchecked(i)->id;
  40642. return 0;
  40643. }
  40644. bool TableHeaderComponent::isSortedForwards() const
  40645. {
  40646. for (int i = columns.size(); --i >= 0;)
  40647. if ((columns.getUnchecked(i)->propertyFlags & (sortedForwards | sortedBackwards)) != 0)
  40648. return (columns.getUnchecked(i)->propertyFlags & sortedForwards) != 0;
  40649. return true;
  40650. }
  40651. void TableHeaderComponent::reSortTable()
  40652. {
  40653. sortChanged = true;
  40654. repaint();
  40655. triggerAsyncUpdate();
  40656. }
  40657. const String TableHeaderComponent::toString() const
  40658. {
  40659. String s;
  40660. XmlElement doc ("TABLELAYOUT");
  40661. doc.setAttribute ("sortedCol", getSortColumnId());
  40662. doc.setAttribute ("sortForwards", isSortedForwards());
  40663. for (int i = 0; i < columns.size(); ++i)
  40664. {
  40665. const ColumnInfo* const ci = columns.getUnchecked (i);
  40666. XmlElement* const e = doc.createNewChildElement ("COLUMN");
  40667. e->setAttribute ("id", ci->id);
  40668. e->setAttribute ("visible", ci->isVisible());
  40669. e->setAttribute ("width", ci->width);
  40670. }
  40671. return doc.createDocument (String::empty, true, false);
  40672. }
  40673. void TableHeaderComponent::restoreFromString (const String& storedVersion)
  40674. {
  40675. XmlDocument doc (storedVersion);
  40676. ScopedPointer <XmlElement> storedXml (doc.getDocumentElement());
  40677. int index = 0;
  40678. if (storedXml != 0 && storedXml->hasTagName ("TABLELAYOUT"))
  40679. {
  40680. forEachXmlChildElement (*storedXml, col)
  40681. {
  40682. const int tabId = col->getIntAttribute ("id");
  40683. ColumnInfo* const ci = getInfoForId (tabId);
  40684. if (ci != 0)
  40685. {
  40686. columns.move (columns.indexOf (ci), index);
  40687. ci->width = col->getIntAttribute ("width");
  40688. setColumnVisible (tabId, col->getBoolAttribute ("visible"));
  40689. }
  40690. ++index;
  40691. }
  40692. columnsResized = true;
  40693. sendColumnsChanged();
  40694. setSortColumnId (storedXml->getIntAttribute ("sortedCol"),
  40695. storedXml->getBoolAttribute ("sortForwards", true));
  40696. }
  40697. }
  40698. void TableHeaderComponent::addListener (TableHeaderListener* const newListener)
  40699. {
  40700. listeners.addIfNotAlreadyThere (newListener);
  40701. }
  40702. void TableHeaderComponent::removeListener (TableHeaderListener* const listenerToRemove)
  40703. {
  40704. listeners.removeValue (listenerToRemove);
  40705. }
  40706. void TableHeaderComponent::columnClicked (int columnId, const ModifierKeys& mods)
  40707. {
  40708. const ColumnInfo* const ci = getInfoForId (columnId);
  40709. if (ci != 0 && (ci->propertyFlags & sortable) != 0 && ! mods.isPopupMenu())
  40710. setSortColumnId (columnId, (ci->propertyFlags & sortedForwards) == 0);
  40711. }
  40712. void TableHeaderComponent::addMenuItems (PopupMenu& menu, const int /*columnIdClicked*/)
  40713. {
  40714. for (int i = 0; i < columns.size(); ++i)
  40715. {
  40716. const ColumnInfo* const ci = columns.getUnchecked(i);
  40717. if ((ci->propertyFlags & appearsOnColumnMenu) != 0)
  40718. menu.addItem (ci->id, ci->name,
  40719. (ci->propertyFlags & (sortedForwards | sortedBackwards)) == 0,
  40720. isColumnVisible (ci->id));
  40721. }
  40722. }
  40723. void TableHeaderComponent::reactToMenuItem (const int menuReturnId, const int /*columnIdClicked*/)
  40724. {
  40725. if (getIndexOfColumnId (menuReturnId, false) >= 0)
  40726. setColumnVisible (menuReturnId, ! isColumnVisible (menuReturnId));
  40727. }
  40728. void TableHeaderComponent::paint (Graphics& g)
  40729. {
  40730. LookAndFeel& lf = getLookAndFeel();
  40731. lf.drawTableHeaderBackground (g, *this);
  40732. const Rectangle<int> clip (g.getClipBounds());
  40733. int x = 0;
  40734. for (int i = 0; i < columns.size(); ++i)
  40735. {
  40736. const ColumnInfo* const ci = columns.getUnchecked(i);
  40737. if (ci->isVisible())
  40738. {
  40739. if (x + ci->width > clip.getX()
  40740. && (ci->id != columnIdBeingDragged
  40741. || dragOverlayComp == 0
  40742. || ! dragOverlayComp->isVisible()))
  40743. {
  40744. g.saveState();
  40745. g.setOrigin (x, 0);
  40746. g.reduceClipRegion (0, 0, ci->width, getHeight());
  40747. lf.drawTableHeaderColumn (g, ci->name, ci->id, ci->width, getHeight(),
  40748. ci->id == columnIdUnderMouse,
  40749. ci->id == columnIdUnderMouse && isMouseButtonDown(),
  40750. ci->propertyFlags);
  40751. g.restoreState();
  40752. }
  40753. x += ci->width;
  40754. if (x >= clip.getRight())
  40755. break;
  40756. }
  40757. }
  40758. }
  40759. void TableHeaderComponent::resized()
  40760. {
  40761. }
  40762. void TableHeaderComponent::mouseMove (const MouseEvent& e)
  40763. {
  40764. updateColumnUnderMouse (e.x, e.y);
  40765. }
  40766. void TableHeaderComponent::mouseEnter (const MouseEvent& e)
  40767. {
  40768. updateColumnUnderMouse (e.x, e.y);
  40769. }
  40770. void TableHeaderComponent::mouseExit (const MouseEvent& e)
  40771. {
  40772. updateColumnUnderMouse (e.x, e.y);
  40773. }
  40774. void TableHeaderComponent::mouseDown (const MouseEvent& e)
  40775. {
  40776. repaint();
  40777. columnIdBeingResized = 0;
  40778. columnIdBeingDragged = 0;
  40779. if (columnIdUnderMouse != 0)
  40780. {
  40781. draggingColumnOffset = e.x - getColumnPosition (getIndexOfColumnId (columnIdUnderMouse, true)).getX();
  40782. if (e.mods.isPopupMenu())
  40783. columnClicked (columnIdUnderMouse, e.mods);
  40784. }
  40785. if (menuActive && e.mods.isPopupMenu())
  40786. showColumnChooserMenu (columnIdUnderMouse);
  40787. }
  40788. void TableHeaderComponent::mouseDrag (const MouseEvent& e)
  40789. {
  40790. if (columnIdBeingResized == 0
  40791. && columnIdBeingDragged == 0
  40792. && ! (e.mouseWasClicked() || e.mods.isPopupMenu()))
  40793. {
  40794. dragOverlayComp = 0;
  40795. columnIdBeingResized = getResizeDraggerAt (e.getMouseDownX());
  40796. if (columnIdBeingResized != 0)
  40797. {
  40798. const ColumnInfo* const ci = getInfoForId (columnIdBeingResized);
  40799. initialColumnWidth = ci->width;
  40800. }
  40801. else
  40802. {
  40803. beginDrag (e);
  40804. }
  40805. }
  40806. if (columnIdBeingResized != 0)
  40807. {
  40808. const ColumnInfo* const ci = getInfoForId (columnIdBeingResized);
  40809. if (ci != 0)
  40810. {
  40811. int w = jlimit (ci->minimumWidth, ci->maximumWidth,
  40812. initialColumnWidth + e.getDistanceFromDragStartX());
  40813. if (stretchToFit)
  40814. {
  40815. // prevent us dragging a column too far right if we're in stretch-to-fit mode
  40816. int minWidthOnRight = 0;
  40817. for (int i = getIndexOfColumnId (columnIdBeingResized, false) + 1; i < columns.size(); ++i)
  40818. if (columns.getUnchecked (i)->isVisible())
  40819. minWidthOnRight += columns.getUnchecked (i)->minimumWidth;
  40820. const Rectangle<int> currentPos (getColumnPosition (getIndexOfColumnId (columnIdBeingResized, true)));
  40821. w = jmax (ci->minimumWidth, jmin (w, getWidth() - minWidthOnRight - currentPos.getX()));
  40822. }
  40823. setColumnWidth (columnIdBeingResized, w);
  40824. }
  40825. }
  40826. else if (columnIdBeingDragged != 0)
  40827. {
  40828. if (e.y >= -50 && e.y < getHeight() + 50)
  40829. {
  40830. if (dragOverlayComp != 0)
  40831. {
  40832. dragOverlayComp->setVisible (true);
  40833. dragOverlayComp->setBounds (jlimit (0,
  40834. jmax (0, getTotalWidth() - dragOverlayComp->getWidth()),
  40835. e.x - draggingColumnOffset),
  40836. 0,
  40837. dragOverlayComp->getWidth(),
  40838. getHeight());
  40839. for (int i = columns.size(); --i >= 0;)
  40840. {
  40841. const int currentIndex = getIndexOfColumnId (columnIdBeingDragged, true);
  40842. int newIndex = currentIndex;
  40843. if (newIndex > 0)
  40844. {
  40845. // if the previous column isn't draggable, we can't move our column
  40846. // past it, because that'd change the undraggable column's position..
  40847. const ColumnInfo* const previous = columns.getUnchecked (newIndex - 1);
  40848. if ((previous->propertyFlags & draggable) != 0)
  40849. {
  40850. const int leftOfPrevious = getColumnPosition (newIndex - 1).getX();
  40851. const int rightOfCurrent = getColumnPosition (newIndex).getRight();
  40852. if (abs (dragOverlayComp->getX() - leftOfPrevious)
  40853. < abs (dragOverlayComp->getRight() - rightOfCurrent))
  40854. {
  40855. --newIndex;
  40856. }
  40857. }
  40858. }
  40859. if (newIndex < columns.size() - 1)
  40860. {
  40861. // if the next column isn't draggable, we can't move our column
  40862. // past it, because that'd change the undraggable column's position..
  40863. const ColumnInfo* const nextCol = columns.getUnchecked (newIndex + 1);
  40864. if ((nextCol->propertyFlags & draggable) != 0)
  40865. {
  40866. const int leftOfCurrent = getColumnPosition (newIndex).getX();
  40867. const int rightOfNext = getColumnPosition (newIndex + 1).getRight();
  40868. if (abs (dragOverlayComp->getX() - leftOfCurrent)
  40869. > abs (dragOverlayComp->getRight() - rightOfNext))
  40870. {
  40871. ++newIndex;
  40872. }
  40873. }
  40874. }
  40875. if (newIndex != currentIndex)
  40876. moveColumn (columnIdBeingDragged, newIndex);
  40877. else
  40878. break;
  40879. }
  40880. }
  40881. }
  40882. else
  40883. {
  40884. endDrag (draggingColumnOriginalIndex);
  40885. }
  40886. }
  40887. }
  40888. void TableHeaderComponent::beginDrag (const MouseEvent& e)
  40889. {
  40890. if (columnIdBeingDragged == 0)
  40891. {
  40892. columnIdBeingDragged = getColumnIdAtX (e.getMouseDownX());
  40893. const ColumnInfo* const ci = getInfoForId (columnIdBeingDragged);
  40894. if (ci == 0 || (ci->propertyFlags & draggable) == 0)
  40895. {
  40896. columnIdBeingDragged = 0;
  40897. }
  40898. else
  40899. {
  40900. draggingColumnOriginalIndex = getIndexOfColumnId (columnIdBeingDragged, true);
  40901. const Rectangle<int> columnRect (getColumnPosition (draggingColumnOriginalIndex));
  40902. const int temp = columnIdBeingDragged;
  40903. columnIdBeingDragged = 0;
  40904. addAndMakeVisible (dragOverlayComp = new DragOverlayComp (createComponentSnapshot (columnRect, false)));
  40905. columnIdBeingDragged = temp;
  40906. dragOverlayComp->setBounds (columnRect);
  40907. for (int i = listeners.size(); --i >= 0;)
  40908. {
  40909. listeners.getUnchecked(i)->tableColumnDraggingChanged (this, columnIdBeingDragged);
  40910. i = jmin (i, listeners.size() - 1);
  40911. }
  40912. }
  40913. }
  40914. }
  40915. void TableHeaderComponent::endDrag (const int finalIndex)
  40916. {
  40917. if (columnIdBeingDragged != 0)
  40918. {
  40919. moveColumn (columnIdBeingDragged, finalIndex);
  40920. columnIdBeingDragged = 0;
  40921. repaint();
  40922. for (int i = listeners.size(); --i >= 0;)
  40923. {
  40924. listeners.getUnchecked(i)->tableColumnDraggingChanged (this, 0);
  40925. i = jmin (i, listeners.size() - 1);
  40926. }
  40927. }
  40928. }
  40929. void TableHeaderComponent::mouseUp (const MouseEvent& e)
  40930. {
  40931. mouseDrag (e);
  40932. for (int i = columns.size(); --i >= 0;)
  40933. if (columns.getUnchecked (i)->isVisible())
  40934. columns.getUnchecked (i)->lastDeliberateWidth = columns.getUnchecked (i)->width;
  40935. columnIdBeingResized = 0;
  40936. repaint();
  40937. endDrag (getIndexOfColumnId (columnIdBeingDragged, true));
  40938. updateColumnUnderMouse (e.x, e.y);
  40939. if (columnIdUnderMouse != 0 && e.mouseWasClicked() && ! e.mods.isPopupMenu())
  40940. columnClicked (columnIdUnderMouse, e.mods);
  40941. dragOverlayComp = 0;
  40942. }
  40943. const MouseCursor TableHeaderComponent::getMouseCursor()
  40944. {
  40945. int x, y;
  40946. getMouseXYRelative (x, y);
  40947. if (columnIdBeingResized != 0 || (getResizeDraggerAt (x) != 0 && ! isMouseButtonDown()))
  40948. return MouseCursor (MouseCursor::LeftRightResizeCursor);
  40949. return Component::getMouseCursor();
  40950. }
  40951. bool TableHeaderComponent::ColumnInfo::isVisible() const
  40952. {
  40953. return (propertyFlags & TableHeaderComponent::visible) != 0;
  40954. }
  40955. TableHeaderComponent::ColumnInfo* TableHeaderComponent::getInfoForId (const int id) const
  40956. {
  40957. for (int i = columns.size(); --i >= 0;)
  40958. if (columns.getUnchecked(i)->id == id)
  40959. return columns.getUnchecked(i);
  40960. return 0;
  40961. }
  40962. int TableHeaderComponent::visibleIndexToTotalIndex (const int visibleIndex) const
  40963. {
  40964. int n = 0;
  40965. for (int i = 0; i < columns.size(); ++i)
  40966. {
  40967. if (columns.getUnchecked(i)->isVisible())
  40968. {
  40969. if (n == visibleIndex)
  40970. return i;
  40971. ++n;
  40972. }
  40973. }
  40974. return -1;
  40975. }
  40976. void TableHeaderComponent::sendColumnsChanged()
  40977. {
  40978. if (stretchToFit && lastDeliberateWidth > 0)
  40979. resizeAllColumnsToFit (lastDeliberateWidth);
  40980. repaint();
  40981. columnsChanged = true;
  40982. triggerAsyncUpdate();
  40983. }
  40984. void TableHeaderComponent::handleAsyncUpdate()
  40985. {
  40986. const bool changed = columnsChanged || sortChanged;
  40987. const bool sized = columnsResized || changed;
  40988. const bool sorted = sortChanged;
  40989. columnsChanged = false;
  40990. columnsResized = false;
  40991. sortChanged = false;
  40992. if (sorted)
  40993. {
  40994. for (int i = listeners.size(); --i >= 0;)
  40995. {
  40996. listeners.getUnchecked(i)->tableSortOrderChanged (this);
  40997. i = jmin (i, listeners.size() - 1);
  40998. }
  40999. }
  41000. if (changed)
  41001. {
  41002. for (int i = listeners.size(); --i >= 0;)
  41003. {
  41004. listeners.getUnchecked(i)->tableColumnsChanged (this);
  41005. i = jmin (i, listeners.size() - 1);
  41006. }
  41007. }
  41008. if (sized)
  41009. {
  41010. for (int i = listeners.size(); --i >= 0;)
  41011. {
  41012. listeners.getUnchecked(i)->tableColumnsResized (this);
  41013. i = jmin (i, listeners.size() - 1);
  41014. }
  41015. }
  41016. }
  41017. int TableHeaderComponent::getResizeDraggerAt (const int mouseX) const
  41018. {
  41019. if (((unsigned int) mouseX) < (unsigned int) getWidth())
  41020. {
  41021. const int draggableDistance = 3;
  41022. int x = 0;
  41023. for (int i = 0; i < columns.size(); ++i)
  41024. {
  41025. const ColumnInfo* const ci = columns.getUnchecked(i);
  41026. if (ci->isVisible())
  41027. {
  41028. if (abs (mouseX - (x + ci->width)) <= draggableDistance
  41029. && (ci->propertyFlags & resizable) != 0)
  41030. return ci->id;
  41031. x += ci->width;
  41032. }
  41033. }
  41034. }
  41035. return 0;
  41036. }
  41037. void TableHeaderComponent::updateColumnUnderMouse (int x, int y)
  41038. {
  41039. const int newCol = (reallyContains (x, y, true) && getResizeDraggerAt (x) == 0)
  41040. ? getColumnIdAtX (x) : 0;
  41041. if (newCol != columnIdUnderMouse)
  41042. {
  41043. columnIdUnderMouse = newCol;
  41044. repaint();
  41045. }
  41046. }
  41047. void TableHeaderComponent::showColumnChooserMenu (const int columnIdClicked)
  41048. {
  41049. PopupMenu m;
  41050. addMenuItems (m, columnIdClicked);
  41051. if (m.getNumItems() > 0)
  41052. {
  41053. m.setLookAndFeel (&getLookAndFeel());
  41054. const int result = m.show();
  41055. if (result != 0)
  41056. reactToMenuItem (result, columnIdClicked);
  41057. }
  41058. }
  41059. void TableHeaderListener::tableColumnDraggingChanged (TableHeaderComponent*, int)
  41060. {
  41061. }
  41062. END_JUCE_NAMESPACE
  41063. /*** End of inlined file: juce_TableHeaderComponent.cpp ***/
  41064. /*** Start of inlined file: juce_TableListBox.cpp ***/
  41065. BEGIN_JUCE_NAMESPACE
  41066. static const char* const tableColumnPropertyTag = "_tableColumnID";
  41067. class TableListRowComp : public Component,
  41068. public TooltipClient
  41069. {
  41070. public:
  41071. TableListRowComp (TableListBox& owner_)
  41072. : owner (owner_),
  41073. row (-1),
  41074. isSelected (false)
  41075. {
  41076. }
  41077. ~TableListRowComp()
  41078. {
  41079. deleteAllChildren();
  41080. }
  41081. void paint (Graphics& g)
  41082. {
  41083. TableListBoxModel* const model = owner.getModel();
  41084. if (model != 0)
  41085. {
  41086. const TableHeaderComponent* const header = owner.getHeader();
  41087. model->paintRowBackground (g, row, getWidth(), getHeight(), isSelected);
  41088. const int numColumns = header->getNumColumns (true);
  41089. for (int i = 0; i < numColumns; ++i)
  41090. {
  41091. if (! columnsWithComponents [i])
  41092. {
  41093. const int columnId = header->getColumnIdOfIndex (i, true);
  41094. Rectangle<int> columnRect (header->getColumnPosition (i));
  41095. columnRect.setSize (columnRect.getWidth(), getHeight());
  41096. g.saveState();
  41097. g.reduceClipRegion (columnRect);
  41098. g.setOrigin (columnRect.getX(), 0);
  41099. model->paintCell (g, row, columnId, columnRect.getWidth(), columnRect.getHeight(), isSelected);
  41100. g.restoreState();
  41101. }
  41102. }
  41103. }
  41104. }
  41105. void update (const int newRow, const bool isNowSelected)
  41106. {
  41107. if (newRow != row || isNowSelected != isSelected)
  41108. {
  41109. row = newRow;
  41110. isSelected = isNowSelected;
  41111. repaint();
  41112. }
  41113. if (row < owner.getNumRows())
  41114. {
  41115. jassert (row >= 0);
  41116. const var::identifier tagPropertyName ("_tableLastUseNum");
  41117. const int newTag = Random::getSystemRandom().nextInt();
  41118. const TableHeaderComponent* const header = owner.getHeader();
  41119. const int numColumns = header->getNumColumns (true);
  41120. int i;
  41121. columnsWithComponents.clear();
  41122. if (owner.getModel() != 0)
  41123. {
  41124. for (i = 0; i < numColumns; ++i)
  41125. {
  41126. const int columnId = header->getColumnIdOfIndex (i, true);
  41127. Component* const newComp
  41128. = owner.getModel()->refreshComponentForCell (row, columnId, isSelected,
  41129. findChildComponentForColumn (columnId));
  41130. if (newComp != 0)
  41131. {
  41132. addAndMakeVisible (newComp);
  41133. newComp->getProperties().set (tagPropertyName, newTag);
  41134. newComp->getProperties().set (tableColumnPropertyTag, columnId);
  41135. const Rectangle<int> columnRect (header->getColumnPosition (i));
  41136. newComp->setBounds (columnRect.getX(), 0, columnRect.getWidth(), getHeight());
  41137. columnsWithComponents.setBit (i);
  41138. }
  41139. }
  41140. }
  41141. for (i = getNumChildComponents(); --i >= 0;)
  41142. {
  41143. Component* const c = getChildComponent (i);
  41144. if ((int) c->getProperties() [tagPropertyName] != newTag)
  41145. delete c;
  41146. }
  41147. }
  41148. else
  41149. {
  41150. columnsWithComponents.clear();
  41151. deleteAllChildren();
  41152. }
  41153. }
  41154. void resized()
  41155. {
  41156. for (int i = getNumChildComponents(); --i >= 0;)
  41157. {
  41158. Component* const c = getChildComponent (i);
  41159. const int columnId = c->getProperties() [tableColumnPropertyTag];
  41160. if (columnId != 0)
  41161. {
  41162. const Rectangle<int> columnRect (owner.getHeader()->getColumnPosition (owner.getHeader()->getIndexOfColumnId (columnId, true)));
  41163. c->setBounds (columnRect.getX(), 0, columnRect.getWidth(), getHeight());
  41164. }
  41165. }
  41166. }
  41167. void mouseDown (const MouseEvent& e)
  41168. {
  41169. isDragging = false;
  41170. selectRowOnMouseUp = false;
  41171. if (isEnabled())
  41172. {
  41173. if (! isSelected)
  41174. {
  41175. owner.selectRowsBasedOnModifierKeys (row, e.mods);
  41176. const int columnId = owner.getHeader()->getColumnIdAtX (e.x);
  41177. if (columnId != 0 && owner.getModel() != 0)
  41178. owner.getModel()->cellClicked (row, columnId, e);
  41179. }
  41180. else
  41181. {
  41182. selectRowOnMouseUp = true;
  41183. }
  41184. }
  41185. }
  41186. void mouseDrag (const MouseEvent& e)
  41187. {
  41188. if (isEnabled() && owner.getModel() != 0 && ! (e.mouseWasClicked() || isDragging))
  41189. {
  41190. const SparseSet <int> selectedRows (owner.getSelectedRows());
  41191. if (selectedRows.size() > 0)
  41192. {
  41193. const String dragDescription (owner.getModel()->getDragSourceDescription (selectedRows));
  41194. if (dragDescription.isNotEmpty())
  41195. {
  41196. isDragging = true;
  41197. owner.startDragAndDrop (e, dragDescription);
  41198. }
  41199. }
  41200. }
  41201. }
  41202. void mouseUp (const MouseEvent& e)
  41203. {
  41204. if (selectRowOnMouseUp && e.mouseWasClicked() && isEnabled())
  41205. {
  41206. owner.selectRowsBasedOnModifierKeys (row, e.mods);
  41207. const int columnId = owner.getHeader()->getColumnIdAtX (e.x);
  41208. if (columnId != 0 && owner.getModel() != 0)
  41209. owner.getModel()->cellClicked (row, columnId, e);
  41210. }
  41211. }
  41212. void mouseDoubleClick (const MouseEvent& e)
  41213. {
  41214. const int columnId = owner.getHeader()->getColumnIdAtX (e.x);
  41215. if (columnId != 0 && owner.getModel() != 0)
  41216. owner.getModel()->cellDoubleClicked (row, columnId, e);
  41217. }
  41218. const String getTooltip()
  41219. {
  41220. int x, y;
  41221. getMouseXYRelative (x, y);
  41222. const int columnId = owner.getHeader()->getColumnIdAtX (x);
  41223. if (columnId != 0 && owner.getModel() != 0)
  41224. return owner.getModel()->getCellTooltip (row, columnId);
  41225. return String::empty;
  41226. }
  41227. juce_UseDebuggingNewOperator
  41228. private:
  41229. TableListBox& owner;
  41230. int row;
  41231. bool isSelected, isDragging, selectRowOnMouseUp;
  41232. BitArray columnsWithComponents;
  41233. Component* findChildComponentForColumn (const int columnId) const
  41234. {
  41235. for (int i = getNumChildComponents(); --i >= 0;)
  41236. {
  41237. Component* const c = getChildComponent (i);
  41238. if ((int) c->getProperties() [tableColumnPropertyTag] == columnId)
  41239. return c;
  41240. }
  41241. return 0;
  41242. }
  41243. TableListRowComp (const TableListRowComp&);
  41244. const TableListRowComp& operator= (const TableListRowComp&);
  41245. };
  41246. class TableListBoxHeader : public TableHeaderComponent
  41247. {
  41248. public:
  41249. TableListBoxHeader (TableListBox& owner_)
  41250. : owner (owner_)
  41251. {
  41252. }
  41253. ~TableListBoxHeader()
  41254. {
  41255. }
  41256. void addMenuItems (PopupMenu& menu, const int columnIdClicked)
  41257. {
  41258. if (owner.isAutoSizeMenuOptionShown())
  41259. {
  41260. menu.addItem (0xf836743, TRANS("Auto-size this column"), columnIdClicked != 0);
  41261. menu.addItem (0xf836744, TRANS("Auto-size all columns"), owner.getHeader()->getNumColumns (true) > 0);
  41262. menu.addSeparator();
  41263. }
  41264. TableHeaderComponent::addMenuItems (menu, columnIdClicked);
  41265. }
  41266. void reactToMenuItem (const int menuReturnId, const int columnIdClicked)
  41267. {
  41268. if (menuReturnId == 0xf836743)
  41269. {
  41270. owner.autoSizeColumn (columnIdClicked);
  41271. }
  41272. else if (menuReturnId == 0xf836744)
  41273. {
  41274. owner.autoSizeAllColumns();
  41275. }
  41276. else
  41277. {
  41278. TableHeaderComponent::reactToMenuItem (menuReturnId, columnIdClicked);
  41279. }
  41280. }
  41281. juce_UseDebuggingNewOperator
  41282. private:
  41283. TableListBox& owner;
  41284. TableListBoxHeader (const TableListBoxHeader&);
  41285. const TableListBoxHeader& operator= (const TableListBoxHeader&);
  41286. };
  41287. TableListBox::TableListBox (const String& name, TableListBoxModel* const model_)
  41288. : ListBox (name, 0),
  41289. model (model_),
  41290. autoSizeOptionsShown (true)
  41291. {
  41292. ListBox::model = this;
  41293. header = new TableListBoxHeader (*this);
  41294. header->setSize (100, 28);
  41295. header->addListener (this);
  41296. setHeaderComponent (header);
  41297. }
  41298. TableListBox::~TableListBox()
  41299. {
  41300. deleteAllChildren();
  41301. }
  41302. void TableListBox::setModel (TableListBoxModel* const newModel)
  41303. {
  41304. if (model != newModel)
  41305. {
  41306. model = newModel;
  41307. updateContent();
  41308. }
  41309. }
  41310. int TableListBox::getHeaderHeight() const
  41311. {
  41312. return header->getHeight();
  41313. }
  41314. void TableListBox::setHeaderHeight (const int newHeight)
  41315. {
  41316. header->setSize (header->getWidth(), newHeight);
  41317. resized();
  41318. }
  41319. void TableListBox::autoSizeColumn (const int columnId)
  41320. {
  41321. const int width = model != 0 ? model->getColumnAutoSizeWidth (columnId) : 0;
  41322. if (width > 0)
  41323. header->setColumnWidth (columnId, width);
  41324. }
  41325. void TableListBox::autoSizeAllColumns()
  41326. {
  41327. for (int i = 0; i < header->getNumColumns (true); ++i)
  41328. autoSizeColumn (header->getColumnIdOfIndex (i, true));
  41329. }
  41330. void TableListBox::setAutoSizeMenuOptionShown (const bool shouldBeShown)
  41331. {
  41332. autoSizeOptionsShown = shouldBeShown;
  41333. }
  41334. bool TableListBox::isAutoSizeMenuOptionShown() const
  41335. {
  41336. return autoSizeOptionsShown;
  41337. }
  41338. const Rectangle<int> TableListBox::getCellPosition (const int columnId,
  41339. const int rowNumber,
  41340. const bool relativeToComponentTopLeft) const
  41341. {
  41342. Rectangle<int> headerCell (header->getColumnPosition (header->getIndexOfColumnId (columnId, true)));
  41343. if (relativeToComponentTopLeft)
  41344. headerCell.translate (header->getX(), 0);
  41345. const Rectangle<int> row (getRowPosition (rowNumber, relativeToComponentTopLeft));
  41346. return Rectangle<int> (headerCell.getX(), row.getY(),
  41347. headerCell.getWidth(), row.getHeight());
  41348. }
  41349. void TableListBox::scrollToEnsureColumnIsOnscreen (const int columnId)
  41350. {
  41351. ScrollBar* const scrollbar = getHorizontalScrollBar();
  41352. if (scrollbar != 0)
  41353. {
  41354. const Rectangle<int> pos (header->getColumnPosition (header->getIndexOfColumnId (columnId, true)));
  41355. double x = scrollbar->getCurrentRangeStart();
  41356. const double w = scrollbar->getCurrentRangeSize();
  41357. if (pos.getX() < x)
  41358. x = pos.getX();
  41359. else if (pos.getRight() > x + w)
  41360. x += jmax (0.0, pos.getRight() - (x + w));
  41361. scrollbar->setCurrentRangeStart (x);
  41362. }
  41363. }
  41364. int TableListBox::getNumRows()
  41365. {
  41366. return model != 0 ? model->getNumRows() : 0;
  41367. }
  41368. void TableListBox::paintListBoxItem (int, Graphics&, int, int, bool)
  41369. {
  41370. }
  41371. Component* TableListBox::refreshComponentForRow (int rowNumber, bool isRowSelected_, Component* existingComponentToUpdate)
  41372. {
  41373. if (existingComponentToUpdate == 0)
  41374. existingComponentToUpdate = new TableListRowComp (*this);
  41375. ((TableListRowComp*) existingComponentToUpdate)->update (rowNumber, isRowSelected_);
  41376. return existingComponentToUpdate;
  41377. }
  41378. void TableListBox::selectedRowsChanged (int row)
  41379. {
  41380. if (model != 0)
  41381. model->selectedRowsChanged (row);
  41382. }
  41383. void TableListBox::deleteKeyPressed (int row)
  41384. {
  41385. if (model != 0)
  41386. model->deleteKeyPressed (row);
  41387. }
  41388. void TableListBox::returnKeyPressed (int row)
  41389. {
  41390. if (model != 0)
  41391. model->returnKeyPressed (row);
  41392. }
  41393. void TableListBox::backgroundClicked()
  41394. {
  41395. if (model != 0)
  41396. model->backgroundClicked();
  41397. }
  41398. void TableListBox::listWasScrolled()
  41399. {
  41400. if (model != 0)
  41401. model->listWasScrolled();
  41402. }
  41403. void TableListBox::tableColumnsChanged (TableHeaderComponent*)
  41404. {
  41405. setMinimumContentWidth (header->getTotalWidth());
  41406. repaint();
  41407. updateColumnComponents();
  41408. }
  41409. void TableListBox::tableColumnsResized (TableHeaderComponent*)
  41410. {
  41411. setMinimumContentWidth (header->getTotalWidth());
  41412. repaint();
  41413. updateColumnComponents();
  41414. }
  41415. void TableListBox::tableSortOrderChanged (TableHeaderComponent*)
  41416. {
  41417. if (model != 0)
  41418. model->sortOrderChanged (header->getSortColumnId(),
  41419. header->isSortedForwards());
  41420. }
  41421. void TableListBox::tableColumnDraggingChanged (TableHeaderComponent*, int columnIdNowBeingDragged_)
  41422. {
  41423. columnIdNowBeingDragged = columnIdNowBeingDragged_;
  41424. repaint();
  41425. }
  41426. void TableListBox::resized()
  41427. {
  41428. ListBox::resized();
  41429. header->resizeAllColumnsToFit (getVisibleContentWidth());
  41430. setMinimumContentWidth (header->getTotalWidth());
  41431. }
  41432. void TableListBox::updateColumnComponents() const
  41433. {
  41434. const int firstRow = getRowContainingPosition (0, 0);
  41435. for (int i = firstRow + getNumRowsOnScreen() + 2; --i >= firstRow;)
  41436. {
  41437. TableListRowComp* const rowComp = dynamic_cast <TableListRowComp*> (getComponentForRowNumber (i));
  41438. if (rowComp != 0)
  41439. rowComp->resized();
  41440. }
  41441. }
  41442. void TableListBoxModel::cellClicked (int, int, const MouseEvent&)
  41443. {
  41444. }
  41445. void TableListBoxModel::cellDoubleClicked (int, int, const MouseEvent&)
  41446. {
  41447. }
  41448. void TableListBoxModel::backgroundClicked()
  41449. {
  41450. }
  41451. void TableListBoxModel::sortOrderChanged (int, const bool)
  41452. {
  41453. }
  41454. int TableListBoxModel::getColumnAutoSizeWidth (int)
  41455. {
  41456. return 0;
  41457. }
  41458. void TableListBoxModel::selectedRowsChanged (int)
  41459. {
  41460. }
  41461. void TableListBoxModel::deleteKeyPressed (int)
  41462. {
  41463. }
  41464. void TableListBoxModel::returnKeyPressed (int)
  41465. {
  41466. }
  41467. void TableListBoxModel::listWasScrolled()
  41468. {
  41469. }
  41470. const String TableListBoxModel::getCellTooltip (int /*rowNumber*/, int /*columnId*/)
  41471. {
  41472. return String::empty;
  41473. }
  41474. const String TableListBoxModel::getDragSourceDescription (const SparseSet<int>&)
  41475. {
  41476. return String::empty;
  41477. }
  41478. Component* TableListBoxModel::refreshComponentForCell (int, int, bool, Component* existingComponentToUpdate)
  41479. {
  41480. (void) existingComponentToUpdate;
  41481. jassert (existingComponentToUpdate == 0); // indicates a failure in the code the recycles the components
  41482. return 0;
  41483. }
  41484. END_JUCE_NAMESPACE
  41485. /*** End of inlined file: juce_TableListBox.cpp ***/
  41486. /*** Start of inlined file: juce_TextEditor.cpp ***/
  41487. BEGIN_JUCE_NAMESPACE
  41488. // a word or space that can't be broken down any further
  41489. struct TextAtom
  41490. {
  41491. String atomText;
  41492. float width;
  41493. uint16 numChars;
  41494. bool isWhitespace() const { return CharacterFunctions::isWhitespace (atomText[0]); }
  41495. bool isNewLine() const { return atomText[0] == T('\r') || atomText[0] == T('\n'); }
  41496. const String getText (const tchar passwordCharacter) const
  41497. {
  41498. if (passwordCharacter == 0)
  41499. return atomText;
  41500. else
  41501. return String::repeatedString (String::charToString (passwordCharacter),
  41502. atomText.length());
  41503. }
  41504. const String getTrimmedText (const tchar passwordCharacter) const
  41505. {
  41506. if (passwordCharacter == 0)
  41507. return atomText.substring (0, numChars);
  41508. else if (isNewLine())
  41509. return String::empty;
  41510. else
  41511. return String::repeatedString (String::charToString (passwordCharacter), numChars);
  41512. }
  41513. };
  41514. // a run of text with a single font and colour
  41515. class UniformTextSection
  41516. {
  41517. public:
  41518. UniformTextSection (const String& text,
  41519. const Font& font_,
  41520. const Colour& colour_,
  41521. const tchar passwordCharacter)
  41522. : font (font_),
  41523. colour (colour_)
  41524. {
  41525. initialiseAtoms (text, passwordCharacter);
  41526. }
  41527. UniformTextSection (const UniformTextSection& other)
  41528. : font (other.font),
  41529. colour (other.colour)
  41530. {
  41531. atoms.ensureStorageAllocated (other.atoms.size());
  41532. for (int i = 0; i < other.atoms.size(); ++i)
  41533. atoms.add (new TextAtom (*(const TextAtom*) other.atoms.getUnchecked(i)));
  41534. }
  41535. ~UniformTextSection()
  41536. {
  41537. // (no need to delete the atoms, as they're explicitly deleted by the caller)
  41538. }
  41539. void clear()
  41540. {
  41541. for (int i = atoms.size(); --i >= 0;)
  41542. delete getAtom(i);
  41543. atoms.clear();
  41544. }
  41545. int getNumAtoms() const
  41546. {
  41547. return atoms.size();
  41548. }
  41549. TextAtom* getAtom (const int index) const
  41550. {
  41551. return (TextAtom*) atoms.getUnchecked (index);
  41552. }
  41553. void append (const UniformTextSection& other, const tchar passwordCharacter)
  41554. {
  41555. if (other.atoms.size() > 0)
  41556. {
  41557. TextAtom* const lastAtom = (TextAtom*) atoms.getLast();
  41558. int i = 0;
  41559. if (lastAtom != 0)
  41560. {
  41561. if (! CharacterFunctions::isWhitespace (lastAtom->atomText.getLastCharacter()))
  41562. {
  41563. TextAtom* const first = other.getAtom(0);
  41564. if (! CharacterFunctions::isWhitespace (first->atomText[0]))
  41565. {
  41566. lastAtom->atomText += first->atomText;
  41567. lastAtom->numChars = (uint16) (lastAtom->numChars + first->numChars);
  41568. lastAtom->width = font.getStringWidthFloat (lastAtom->getText (passwordCharacter));
  41569. delete first;
  41570. ++i;
  41571. }
  41572. }
  41573. }
  41574. atoms.ensureStorageAllocated (atoms.size() + other.atoms.size() - i);
  41575. while (i < other.atoms.size())
  41576. {
  41577. atoms.add (other.getAtom(i));
  41578. ++i;
  41579. }
  41580. }
  41581. }
  41582. UniformTextSection* split (const int indexToBreakAt,
  41583. const tchar passwordCharacter)
  41584. {
  41585. UniformTextSection* const section2 = new UniformTextSection (String::empty,
  41586. font, colour,
  41587. passwordCharacter);
  41588. int index = 0;
  41589. for (int i = 0; i < atoms.size(); ++i)
  41590. {
  41591. TextAtom* const atom = getAtom(i);
  41592. const int nextIndex = index + atom->numChars;
  41593. if (index == indexToBreakAt)
  41594. {
  41595. int j;
  41596. for (j = i; j < atoms.size(); ++j)
  41597. section2->atoms.add (getAtom (j));
  41598. for (j = atoms.size(); --j >= i;)
  41599. atoms.remove (j);
  41600. break;
  41601. }
  41602. else if (indexToBreakAt >= index && indexToBreakAt < nextIndex)
  41603. {
  41604. TextAtom* const secondAtom = new TextAtom();
  41605. secondAtom->atomText = atom->atomText.substring (indexToBreakAt - index);
  41606. secondAtom->width = font.getStringWidthFloat (secondAtom->getText (passwordCharacter));
  41607. secondAtom->numChars = (uint16) secondAtom->atomText.length();
  41608. section2->atoms.add (secondAtom);
  41609. atom->atomText = atom->atomText.substring (0, indexToBreakAt - index);
  41610. atom->width = font.getStringWidthFloat (atom->getText (passwordCharacter));
  41611. atom->numChars = (uint16) (indexToBreakAt - index);
  41612. int j;
  41613. for (j = i + 1; j < atoms.size(); ++j)
  41614. section2->atoms.add (getAtom (j));
  41615. for (j = atoms.size(); --j > i;)
  41616. atoms.remove (j);
  41617. break;
  41618. }
  41619. index = nextIndex;
  41620. }
  41621. return section2;
  41622. }
  41623. void appendAllText (String::Concatenator& concatenator) const
  41624. {
  41625. for (int i = 0; i < atoms.size(); ++i)
  41626. concatenator.append (getAtom(i)->atomText);
  41627. }
  41628. void appendSubstring (String::Concatenator& concatenator,
  41629. const Range<int>& range) const
  41630. {
  41631. int index = 0;
  41632. for (int i = 0; i < atoms.size(); ++i)
  41633. {
  41634. const TextAtom* const atom = getAtom (i);
  41635. const int nextIndex = index + atom->numChars;
  41636. if (range.getStart() < nextIndex)
  41637. {
  41638. if (range.getEnd() <= index)
  41639. break;
  41640. const Range<int> r ((range - index).getIntersectionWith (Range<int> (0, (int) atom->numChars)));
  41641. if (! r.isEmpty())
  41642. concatenator.append (atom->atomText.substring (r.getStart(), r.getEnd()));
  41643. }
  41644. index = nextIndex;
  41645. }
  41646. }
  41647. int getTotalLength() const
  41648. {
  41649. int total = 0;
  41650. for (int i = atoms.size(); --i >= 0;)
  41651. total += getAtom(i)->numChars;
  41652. return total;
  41653. }
  41654. void setFont (const Font& newFont,
  41655. const tchar passwordCharacter)
  41656. {
  41657. if (font != newFont)
  41658. {
  41659. font = newFont;
  41660. for (int i = atoms.size(); --i >= 0;)
  41661. {
  41662. TextAtom* const atom = (TextAtom*) atoms.getUnchecked(i);
  41663. atom->width = newFont.getStringWidthFloat (atom->getText (passwordCharacter));
  41664. }
  41665. }
  41666. }
  41667. juce_UseDebuggingNewOperator
  41668. Font font;
  41669. Colour colour;
  41670. private:
  41671. VoidArray atoms;
  41672. void initialiseAtoms (const String& textToParse,
  41673. const tchar passwordCharacter)
  41674. {
  41675. int i = 0;
  41676. const int len = textToParse.length();
  41677. const tchar* const text = (const tchar*) textToParse;
  41678. while (i < len)
  41679. {
  41680. int start = i;
  41681. // create a whitespace atom unless it starts with non-ws
  41682. if (CharacterFunctions::isWhitespace (text[i])
  41683. && text[i] != T('\r')
  41684. && text[i] != T('\n'))
  41685. {
  41686. while (i < len
  41687. && CharacterFunctions::isWhitespace (text[i])
  41688. && text[i] != T('\r')
  41689. && text[i] != T('\n'))
  41690. {
  41691. ++i;
  41692. }
  41693. }
  41694. else
  41695. {
  41696. if (text[i] == T('\r'))
  41697. {
  41698. ++i;
  41699. if ((i < len) && (text[i] == T('\n')))
  41700. {
  41701. ++start;
  41702. ++i;
  41703. }
  41704. }
  41705. else if (text[i] == T('\n'))
  41706. {
  41707. ++i;
  41708. }
  41709. else
  41710. {
  41711. while ((i < len) && ! CharacterFunctions::isWhitespace (text[i]))
  41712. ++i;
  41713. }
  41714. }
  41715. TextAtom* const atom = new TextAtom();
  41716. atom->atomText = String (text + start, i - start);
  41717. atom->width = font.getStringWidthFloat (atom->getText (passwordCharacter));
  41718. atom->numChars = (uint16) (i - start);
  41719. atoms.add (atom);
  41720. }
  41721. }
  41722. const UniformTextSection& operator= (const UniformTextSection& other);
  41723. };
  41724. class TextEditorIterator
  41725. {
  41726. public:
  41727. TextEditorIterator (const VoidArray& sections_,
  41728. const float wordWrapWidth_,
  41729. const tchar passwordCharacter_)
  41730. : indexInText (0),
  41731. lineY (0),
  41732. lineHeight (0),
  41733. maxDescent (0),
  41734. atomX (0),
  41735. atomRight (0),
  41736. atom (0),
  41737. currentSection (0),
  41738. sections (sections_),
  41739. sectionIndex (0),
  41740. atomIndex (0),
  41741. wordWrapWidth (wordWrapWidth_),
  41742. passwordCharacter (passwordCharacter_)
  41743. {
  41744. jassert (wordWrapWidth_ > 0);
  41745. if (sections.size() > 0)
  41746. {
  41747. currentSection = (const UniformTextSection*) sections.getUnchecked (sectionIndex);
  41748. if (currentSection != 0)
  41749. beginNewLine();
  41750. }
  41751. }
  41752. TextEditorIterator (const TextEditorIterator& other)
  41753. : indexInText (other.indexInText),
  41754. lineY (other.lineY),
  41755. lineHeight (other.lineHeight),
  41756. maxDescent (other.maxDescent),
  41757. atomX (other.atomX),
  41758. atomRight (other.atomRight),
  41759. atom (other.atom),
  41760. currentSection (other.currentSection),
  41761. sections (other.sections),
  41762. sectionIndex (other.sectionIndex),
  41763. atomIndex (other.atomIndex),
  41764. wordWrapWidth (other.wordWrapWidth),
  41765. passwordCharacter (other.passwordCharacter),
  41766. tempAtom (other.tempAtom)
  41767. {
  41768. }
  41769. ~TextEditorIterator()
  41770. {
  41771. }
  41772. bool next()
  41773. {
  41774. if (atom == &tempAtom)
  41775. {
  41776. const int numRemaining = tempAtom.atomText.length() - tempAtom.numChars;
  41777. if (numRemaining > 0)
  41778. {
  41779. tempAtom.atomText = tempAtom.atomText.substring (tempAtom.numChars);
  41780. atomX = 0;
  41781. if (tempAtom.numChars > 0)
  41782. lineY += lineHeight;
  41783. indexInText += tempAtom.numChars;
  41784. GlyphArrangement g;
  41785. g.addLineOfText (currentSection->font, atom->getText (passwordCharacter), 0.0f, 0.0f);
  41786. int split;
  41787. for (split = 0; split < g.getNumGlyphs(); ++split)
  41788. if (shouldWrap (g.getGlyph (split).getRight()))
  41789. break;
  41790. if (split > 0 && split <= numRemaining)
  41791. {
  41792. tempAtom.numChars = (uint16) split;
  41793. tempAtom.width = g.getGlyph (split - 1).getRight();
  41794. atomRight = atomX + tempAtom.width;
  41795. return true;
  41796. }
  41797. }
  41798. }
  41799. bool forceNewLine = false;
  41800. if (sectionIndex >= sections.size())
  41801. {
  41802. moveToEndOfLastAtom();
  41803. return false;
  41804. }
  41805. else if (atomIndex >= currentSection->getNumAtoms() - 1)
  41806. {
  41807. if (atomIndex >= currentSection->getNumAtoms())
  41808. {
  41809. if (++sectionIndex >= sections.size())
  41810. {
  41811. moveToEndOfLastAtom();
  41812. return false;
  41813. }
  41814. atomIndex = 0;
  41815. currentSection = (const UniformTextSection*) sections.getUnchecked (sectionIndex);
  41816. }
  41817. else
  41818. {
  41819. const TextAtom* const lastAtom = currentSection->getAtom (atomIndex);
  41820. if (! lastAtom->isWhitespace())
  41821. {
  41822. // handle the case where the last atom in a section is actually part of the same
  41823. // word as the first atom of the next section...
  41824. float right = atomRight + lastAtom->width;
  41825. float lineHeight2 = lineHeight;
  41826. float maxDescent2 = maxDescent;
  41827. for (int section = sectionIndex + 1; section < sections.size(); ++section)
  41828. {
  41829. const UniformTextSection* const s = (const UniformTextSection*) sections.getUnchecked (section);
  41830. if (s->getNumAtoms() == 0)
  41831. break;
  41832. const TextAtom* const nextAtom = s->getAtom (0);
  41833. if (nextAtom->isWhitespace())
  41834. break;
  41835. right += nextAtom->width;
  41836. lineHeight2 = jmax (lineHeight2, s->font.getHeight());
  41837. maxDescent2 = jmax (maxDescent2, s->font.getDescent());
  41838. if (shouldWrap (right))
  41839. {
  41840. lineHeight = lineHeight2;
  41841. maxDescent = maxDescent2;
  41842. forceNewLine = true;
  41843. break;
  41844. }
  41845. if (s->getNumAtoms() > 1)
  41846. break;
  41847. }
  41848. }
  41849. }
  41850. }
  41851. if (atom != 0)
  41852. {
  41853. atomX = atomRight;
  41854. indexInText += atom->numChars;
  41855. if (atom->isNewLine())
  41856. beginNewLine();
  41857. }
  41858. atom = currentSection->getAtom (atomIndex);
  41859. atomRight = atomX + atom->width;
  41860. ++atomIndex;
  41861. if (shouldWrap (atomRight) || forceNewLine)
  41862. {
  41863. if (atom->isWhitespace())
  41864. {
  41865. // leave whitespace at the end of a line, but truncate it to avoid scrolling
  41866. atomRight = jmin (atomRight, wordWrapWidth);
  41867. }
  41868. else
  41869. {
  41870. atomRight = atom->width;
  41871. if (shouldWrap (atomRight)) // atom too big to fit on a line, so break it up..
  41872. {
  41873. tempAtom = *atom;
  41874. tempAtom.width = 0;
  41875. tempAtom.numChars = 0;
  41876. atom = &tempAtom;
  41877. if (atomX > 0)
  41878. beginNewLine();
  41879. return next();
  41880. }
  41881. beginNewLine();
  41882. return true;
  41883. }
  41884. }
  41885. return true;
  41886. }
  41887. void beginNewLine()
  41888. {
  41889. atomX = 0;
  41890. lineY += lineHeight;
  41891. int tempSectionIndex = sectionIndex;
  41892. int tempAtomIndex = atomIndex;
  41893. const UniformTextSection* section = (const UniformTextSection*) sections.getUnchecked (tempSectionIndex);
  41894. lineHeight = section->font.getHeight();
  41895. maxDescent = section->font.getDescent();
  41896. float x = (atom != 0) ? atom->width : 0;
  41897. while (! shouldWrap (x))
  41898. {
  41899. if (tempSectionIndex >= sections.size())
  41900. break;
  41901. bool checkSize = false;
  41902. if (tempAtomIndex >= section->getNumAtoms())
  41903. {
  41904. if (++tempSectionIndex >= sections.size())
  41905. break;
  41906. tempAtomIndex = 0;
  41907. section = (const UniformTextSection*) sections.getUnchecked (tempSectionIndex);
  41908. checkSize = true;
  41909. }
  41910. const TextAtom* const nextAtom = section->getAtom (tempAtomIndex);
  41911. if (nextAtom == 0)
  41912. break;
  41913. x += nextAtom->width;
  41914. if (shouldWrap (x) || nextAtom->isNewLine())
  41915. break;
  41916. if (checkSize)
  41917. {
  41918. lineHeight = jmax (lineHeight, section->font.getHeight());
  41919. maxDescent = jmax (maxDescent, section->font.getDescent());
  41920. }
  41921. ++tempAtomIndex;
  41922. }
  41923. }
  41924. void draw (Graphics& g, const UniformTextSection*& lastSection) const
  41925. {
  41926. if (passwordCharacter != 0 || ! atom->isWhitespace())
  41927. {
  41928. if (lastSection != currentSection)
  41929. {
  41930. lastSection = currentSection;
  41931. g.setColour (currentSection->colour);
  41932. g.setFont (currentSection->font);
  41933. }
  41934. jassert (atom->getTrimmedText (passwordCharacter).isNotEmpty());
  41935. GlyphArrangement ga;
  41936. ga.addLineOfText (currentSection->font,
  41937. atom->getTrimmedText (passwordCharacter),
  41938. atomX,
  41939. (float) roundToInt (lineY + lineHeight - maxDescent));
  41940. ga.draw (g);
  41941. }
  41942. }
  41943. void drawSelection (Graphics& g,
  41944. const Range<int>& selection) const
  41945. {
  41946. const int startX = roundToInt (indexToX (selection.getStart()));
  41947. const int endX = roundToInt (indexToX (selection.getEnd()));
  41948. const int y = roundToInt (lineY);
  41949. const int nextY = roundToInt (lineY + lineHeight);
  41950. g.fillRect (startX, y, endX - startX, nextY - y);
  41951. }
  41952. void drawSelectedText (Graphics& g,
  41953. const Range<int>& selection,
  41954. const Colour& selectedTextColour) const
  41955. {
  41956. if (passwordCharacter != 0 || ! atom->isWhitespace())
  41957. {
  41958. GlyphArrangement ga;
  41959. ga.addLineOfText (currentSection->font,
  41960. atom->getTrimmedText (passwordCharacter),
  41961. atomX,
  41962. (float) roundToInt (lineY + lineHeight - maxDescent));
  41963. if (selection.getEnd() < indexInText + atom->numChars)
  41964. {
  41965. GlyphArrangement ga2 (ga);
  41966. ga2.removeRangeOfGlyphs (0, selection.getEnd() - indexInText);
  41967. ga.removeRangeOfGlyphs (selection.getEnd() - indexInText, -1);
  41968. g.setColour (currentSection->colour);
  41969. ga2.draw (g);
  41970. }
  41971. if (selection.getStart() > indexInText)
  41972. {
  41973. GlyphArrangement ga2 (ga);
  41974. ga2.removeRangeOfGlyphs (selection.getStart() - indexInText, -1);
  41975. ga.removeRangeOfGlyphs (0, selection.getStart() - indexInText);
  41976. g.setColour (currentSection->colour);
  41977. ga2.draw (g);
  41978. }
  41979. g.setColour (selectedTextColour);
  41980. ga.draw (g);
  41981. }
  41982. }
  41983. float indexToX (const int indexToFind) const
  41984. {
  41985. if (indexToFind <= indexInText)
  41986. return atomX;
  41987. if (indexToFind >= indexInText + atom->numChars)
  41988. return atomRight;
  41989. GlyphArrangement g;
  41990. g.addLineOfText (currentSection->font,
  41991. atom->getText (passwordCharacter),
  41992. atomX, 0.0f);
  41993. if (indexToFind - indexInText >= g.getNumGlyphs())
  41994. return atomRight;
  41995. return jmin (atomRight, g.getGlyph (indexToFind - indexInText).getLeft());
  41996. }
  41997. int xToIndex (const float xToFind) const
  41998. {
  41999. if (xToFind <= atomX || atom->isNewLine())
  42000. return indexInText;
  42001. if (xToFind >= atomRight)
  42002. return indexInText + atom->numChars;
  42003. GlyphArrangement g;
  42004. g.addLineOfText (currentSection->font,
  42005. atom->getText (passwordCharacter),
  42006. atomX, 0.0f);
  42007. int j;
  42008. for (j = 0; j < g.getNumGlyphs(); ++j)
  42009. if ((g.getGlyph(j).getLeft() + g.getGlyph(j).getRight()) / 2 > xToFind)
  42010. break;
  42011. return indexInText + j;
  42012. }
  42013. bool getCharPosition (const int index, float& cx, float& cy, float& lineHeight_)
  42014. {
  42015. while (next())
  42016. {
  42017. if (indexInText + atom->numChars > index)
  42018. {
  42019. cx = indexToX (index);
  42020. cy = lineY;
  42021. lineHeight_ = lineHeight;
  42022. return true;
  42023. }
  42024. }
  42025. cx = atomX;
  42026. cy = lineY;
  42027. lineHeight_ = lineHeight;
  42028. return false;
  42029. }
  42030. juce_UseDebuggingNewOperator
  42031. int indexInText;
  42032. float lineY, lineHeight, maxDescent;
  42033. float atomX, atomRight;
  42034. const TextAtom* atom;
  42035. const UniformTextSection* currentSection;
  42036. private:
  42037. const VoidArray& sections;
  42038. int sectionIndex, atomIndex;
  42039. const float wordWrapWidth;
  42040. const tchar passwordCharacter;
  42041. TextAtom tempAtom;
  42042. const TextEditorIterator& operator= (const TextEditorIterator&);
  42043. void moveToEndOfLastAtom()
  42044. {
  42045. if (atom != 0)
  42046. {
  42047. atomX = atomRight;
  42048. if (atom->isNewLine())
  42049. {
  42050. atomX = 0.0f;
  42051. lineY += lineHeight;
  42052. }
  42053. }
  42054. }
  42055. bool shouldWrap (const float x) const
  42056. {
  42057. return (x - 0.0001f) >= wordWrapWidth;
  42058. }
  42059. };
  42060. class TextEditorInsertAction : public UndoableAction
  42061. {
  42062. TextEditor& owner;
  42063. const String text;
  42064. const int insertIndex, oldCaretPos, newCaretPos;
  42065. const Font font;
  42066. const Colour colour;
  42067. TextEditorInsertAction (const TextEditorInsertAction&);
  42068. const TextEditorInsertAction& operator= (const TextEditorInsertAction&);
  42069. public:
  42070. TextEditorInsertAction (TextEditor& owner_,
  42071. const String& text_,
  42072. const int insertIndex_,
  42073. const Font& font_,
  42074. const Colour& colour_,
  42075. const int oldCaretPos_,
  42076. const int newCaretPos_)
  42077. : owner (owner_),
  42078. text (text_),
  42079. insertIndex (insertIndex_),
  42080. oldCaretPos (oldCaretPos_),
  42081. newCaretPos (newCaretPos_),
  42082. font (font_),
  42083. colour (colour_)
  42084. {
  42085. }
  42086. ~TextEditorInsertAction()
  42087. {
  42088. }
  42089. bool perform()
  42090. {
  42091. owner.insert (text, insertIndex, font, colour, 0, newCaretPos);
  42092. return true;
  42093. }
  42094. bool undo()
  42095. {
  42096. owner.remove (Range<int> (insertIndex, insertIndex + text.length()), 0, oldCaretPos);
  42097. return true;
  42098. }
  42099. int getSizeInUnits()
  42100. {
  42101. return text.length() + 16;
  42102. }
  42103. };
  42104. class TextEditorRemoveAction : public UndoableAction
  42105. {
  42106. TextEditor& owner;
  42107. const Range<int> range;
  42108. const int oldCaretPos, newCaretPos;
  42109. VoidArray removedSections;
  42110. TextEditorRemoveAction (const TextEditorRemoveAction&);
  42111. const TextEditorRemoveAction& operator= (const TextEditorRemoveAction&);
  42112. public:
  42113. TextEditorRemoveAction (TextEditor& owner_,
  42114. const Range<int> range_,
  42115. const int oldCaretPos_,
  42116. const int newCaretPos_,
  42117. const VoidArray& removedSections_)
  42118. : owner (owner_),
  42119. range (range_),
  42120. oldCaretPos (oldCaretPos_),
  42121. newCaretPos (newCaretPos_),
  42122. removedSections (removedSections_)
  42123. {
  42124. }
  42125. ~TextEditorRemoveAction()
  42126. {
  42127. for (int i = removedSections.size(); --i >= 0;)
  42128. {
  42129. UniformTextSection* const section = (UniformTextSection*) removedSections.getUnchecked (i);
  42130. section->clear();
  42131. delete section;
  42132. }
  42133. }
  42134. bool perform()
  42135. {
  42136. owner.remove (range, 0, newCaretPos);
  42137. return true;
  42138. }
  42139. bool undo()
  42140. {
  42141. owner.reinsert (range.getStart(), removedSections);
  42142. owner.moveCursorTo (oldCaretPos, false);
  42143. return true;
  42144. }
  42145. int getSizeInUnits()
  42146. {
  42147. int n = 0;
  42148. for (int i = removedSections.size(); --i >= 0;)
  42149. {
  42150. UniformTextSection* const section = (UniformTextSection*) removedSections.getUnchecked (i);
  42151. n += section->getTotalLength();
  42152. }
  42153. return n + 16;
  42154. }
  42155. };
  42156. class TextHolderComponent : public Component,
  42157. public Timer,
  42158. public Value::Listener
  42159. {
  42160. TextEditor& owner;
  42161. TextHolderComponent (const TextHolderComponent&);
  42162. const TextHolderComponent& operator= (const TextHolderComponent&);
  42163. public:
  42164. TextHolderComponent (TextEditor& owner_)
  42165. : owner (owner_)
  42166. {
  42167. setWantsKeyboardFocus (false);
  42168. setInterceptsMouseClicks (false, true);
  42169. owner.getTextValue().addListener (this);
  42170. }
  42171. ~TextHolderComponent()
  42172. {
  42173. owner.getTextValue().removeListener (this);
  42174. }
  42175. void paint (Graphics& g)
  42176. {
  42177. owner.drawContent (g);
  42178. }
  42179. void timerCallback()
  42180. {
  42181. owner.timerCallbackInt();
  42182. }
  42183. const MouseCursor getMouseCursor()
  42184. {
  42185. return owner.getMouseCursor();
  42186. }
  42187. void valueChanged (Value&)
  42188. {
  42189. owner.textWasChangedByValue();
  42190. }
  42191. };
  42192. class TextEditorViewport : public Viewport
  42193. {
  42194. TextEditor* const owner;
  42195. float lastWordWrapWidth;
  42196. TextEditorViewport (const TextEditorViewport&);
  42197. const TextEditorViewport& operator= (const TextEditorViewport&);
  42198. public:
  42199. TextEditorViewport (TextEditor* const owner_)
  42200. : owner (owner_),
  42201. lastWordWrapWidth (0)
  42202. {
  42203. }
  42204. ~TextEditorViewport()
  42205. {
  42206. }
  42207. void visibleAreaChanged (int, int, int, int)
  42208. {
  42209. const float wordWrapWidth = owner->getWordWrapWidth();
  42210. if (wordWrapWidth != lastWordWrapWidth)
  42211. {
  42212. lastWordWrapWidth = wordWrapWidth;
  42213. owner->updateTextHolderSize();
  42214. }
  42215. }
  42216. };
  42217. namespace TextEditorDefs
  42218. {
  42219. const int flashSpeedIntervalMs = 380;
  42220. const int textChangeMessageId = 0x10003001;
  42221. const int returnKeyMessageId = 0x10003002;
  42222. const int escapeKeyMessageId = 0x10003003;
  42223. const int focusLossMessageId = 0x10003004;
  42224. const int maxActionsPerTransaction = 100;
  42225. }
  42226. TextEditor::TextEditor (const String& name,
  42227. const tchar passwordCharacter_)
  42228. : Component (name),
  42229. borderSize (1, 1, 1, 3),
  42230. readOnly (false),
  42231. multiline (false),
  42232. wordWrap (false),
  42233. returnKeyStartsNewLine (false),
  42234. caretVisible (true),
  42235. popupMenuEnabled (true),
  42236. selectAllTextWhenFocused (false),
  42237. scrollbarVisible (true),
  42238. wasFocused (false),
  42239. caretFlashState (true),
  42240. keepCursorOnScreen (true),
  42241. tabKeyUsed (false),
  42242. menuActive (false),
  42243. valueTextNeedsUpdating (false),
  42244. cursorX (0),
  42245. cursorY (0),
  42246. cursorHeight (0),
  42247. maxTextLength (0),
  42248. leftIndent (4),
  42249. topIndent (4),
  42250. lastTransactionTime (0),
  42251. currentFont (14.0f),
  42252. totalNumChars (0),
  42253. caretPosition (0),
  42254. passwordCharacter (passwordCharacter_),
  42255. dragType (notDragging)
  42256. {
  42257. setOpaque (true);
  42258. addAndMakeVisible (viewport = new TextEditorViewport (this));
  42259. viewport->setViewedComponent (textHolder = new TextHolderComponent (*this));
  42260. viewport->setWantsKeyboardFocus (false);
  42261. viewport->setScrollBarsShown (false, false);
  42262. setMouseCursor (MouseCursor::IBeamCursor);
  42263. setWantsKeyboardFocus (true);
  42264. }
  42265. TextEditor::~TextEditor()
  42266. {
  42267. textValue.referTo (Value());
  42268. clearInternal (0);
  42269. viewport = 0;
  42270. textHolder = 0;
  42271. }
  42272. void TextEditor::newTransaction()
  42273. {
  42274. lastTransactionTime = Time::getApproximateMillisecondCounter();
  42275. undoManager.beginNewTransaction();
  42276. }
  42277. void TextEditor::doUndoRedo (const bool isRedo)
  42278. {
  42279. if (! isReadOnly())
  42280. {
  42281. if ((isRedo) ? undoManager.redo()
  42282. : undoManager.undo())
  42283. {
  42284. scrollToMakeSureCursorIsVisible();
  42285. repaint();
  42286. textChanged();
  42287. }
  42288. }
  42289. }
  42290. void TextEditor::setMultiLine (const bool shouldBeMultiLine,
  42291. const bool shouldWordWrap)
  42292. {
  42293. multiline = shouldBeMultiLine;
  42294. wordWrap = shouldWordWrap && shouldBeMultiLine;
  42295. setScrollbarsShown (scrollbarVisible);
  42296. viewport->setViewPosition (0, 0);
  42297. resized();
  42298. scrollToMakeSureCursorIsVisible();
  42299. }
  42300. bool TextEditor::isMultiLine() const
  42301. {
  42302. return multiline;
  42303. }
  42304. void TextEditor::setScrollbarsShown (bool enabled)
  42305. {
  42306. scrollbarVisible = enabled;
  42307. enabled = enabled && isMultiLine();
  42308. viewport->setScrollBarsShown (enabled, enabled);
  42309. }
  42310. void TextEditor::setReadOnly (const bool shouldBeReadOnly)
  42311. {
  42312. readOnly = shouldBeReadOnly;
  42313. enablementChanged();
  42314. }
  42315. bool TextEditor::isReadOnly() const
  42316. {
  42317. return readOnly || ! isEnabled();
  42318. }
  42319. void TextEditor::setReturnKeyStartsNewLine (const bool shouldStartNewLine)
  42320. {
  42321. returnKeyStartsNewLine = shouldStartNewLine;
  42322. }
  42323. void TextEditor::setTabKeyUsedAsCharacter (const bool shouldTabKeyBeUsed)
  42324. {
  42325. tabKeyUsed = shouldTabKeyBeUsed;
  42326. }
  42327. void TextEditor::setPopupMenuEnabled (const bool b)
  42328. {
  42329. popupMenuEnabled = b;
  42330. }
  42331. void TextEditor::setSelectAllWhenFocused (const bool b)
  42332. {
  42333. selectAllTextWhenFocused = b;
  42334. }
  42335. const Font TextEditor::getFont() const
  42336. {
  42337. return currentFont;
  42338. }
  42339. void TextEditor::setFont (const Font& newFont)
  42340. {
  42341. currentFont = newFont;
  42342. scrollToMakeSureCursorIsVisible();
  42343. }
  42344. void TextEditor::applyFontToAllText (const Font& newFont)
  42345. {
  42346. currentFont = newFont;
  42347. const Colour overallColour (findColour (textColourId));
  42348. for (int i = sections.size(); --i >= 0;)
  42349. {
  42350. UniformTextSection* const uts = (UniformTextSection*) sections.getUnchecked(i);
  42351. uts->setFont (newFont, passwordCharacter);
  42352. uts->colour = overallColour;
  42353. }
  42354. coalesceSimilarSections();
  42355. updateTextHolderSize();
  42356. scrollToMakeSureCursorIsVisible();
  42357. repaint();
  42358. }
  42359. void TextEditor::colourChanged()
  42360. {
  42361. setOpaque (findColour (backgroundColourId).isOpaque());
  42362. repaint();
  42363. }
  42364. void TextEditor::setCaretVisible (const bool shouldCaretBeVisible)
  42365. {
  42366. caretVisible = shouldCaretBeVisible;
  42367. if (shouldCaretBeVisible)
  42368. textHolder->startTimer (TextEditorDefs::flashSpeedIntervalMs);
  42369. setMouseCursor (shouldCaretBeVisible ? MouseCursor::IBeamCursor
  42370. : MouseCursor::NormalCursor);
  42371. }
  42372. void TextEditor::setInputRestrictions (const int maxLen,
  42373. const String& chars)
  42374. {
  42375. maxTextLength = jmax (0, maxLen);
  42376. allowedCharacters = chars;
  42377. }
  42378. void TextEditor::setTextToShowWhenEmpty (const String& text, const Colour& colourToUse)
  42379. {
  42380. textToShowWhenEmpty = text;
  42381. colourForTextWhenEmpty = colourToUse;
  42382. }
  42383. void TextEditor::setPasswordCharacter (const tchar newPasswordCharacter)
  42384. {
  42385. if (passwordCharacter != newPasswordCharacter)
  42386. {
  42387. passwordCharacter = newPasswordCharacter;
  42388. resized();
  42389. repaint();
  42390. }
  42391. }
  42392. void TextEditor::setScrollBarThickness (const int newThicknessPixels)
  42393. {
  42394. viewport->setScrollBarThickness (newThicknessPixels);
  42395. }
  42396. void TextEditor::setScrollBarButtonVisibility (const bool buttonsVisible)
  42397. {
  42398. viewport->setScrollBarButtonVisibility (buttonsVisible);
  42399. }
  42400. void TextEditor::clear()
  42401. {
  42402. clearInternal (0);
  42403. updateTextHolderSize();
  42404. undoManager.clearUndoHistory();
  42405. }
  42406. void TextEditor::setText (const String& newText,
  42407. const bool sendTextChangeMessage)
  42408. {
  42409. const int newLength = newText.length();
  42410. if (newLength != getTotalNumChars() || getText() != newText)
  42411. {
  42412. const int oldCursorPos = caretPosition;
  42413. const bool cursorWasAtEnd = oldCursorPos >= getTotalNumChars();
  42414. clearInternal (0);
  42415. insert (newText, 0, currentFont, findColour (textColourId), 0, caretPosition);
  42416. // if you're adding text with line-feeds to a single-line text editor, it
  42417. // ain't gonna look right!
  42418. jassert (multiline || ! newText.containsAnyOf (T("\r\n")));
  42419. if (cursorWasAtEnd && ! isMultiLine())
  42420. moveCursorTo (getTotalNumChars(), false);
  42421. else
  42422. moveCursorTo (oldCursorPos, false);
  42423. if (sendTextChangeMessage)
  42424. textChanged();
  42425. repaint();
  42426. }
  42427. updateTextHolderSize();
  42428. scrollToMakeSureCursorIsVisible();
  42429. undoManager.clearUndoHistory();
  42430. }
  42431. Value& TextEditor::getTextValue()
  42432. {
  42433. if (valueTextNeedsUpdating)
  42434. {
  42435. valueTextNeedsUpdating = false;
  42436. textValue = getText();
  42437. }
  42438. return textValue;
  42439. }
  42440. void TextEditor::textWasChangedByValue()
  42441. {
  42442. if (textValue.getValueSource().getReferenceCount() > 1)
  42443. setText (textValue.getValue());
  42444. }
  42445. void TextEditor::textChanged()
  42446. {
  42447. updateTextHolderSize();
  42448. postCommandMessage (TextEditorDefs::textChangeMessageId);
  42449. if (textValue.getValueSource().getReferenceCount() > 1)
  42450. {
  42451. valueTextNeedsUpdating = false;
  42452. textValue = getText();
  42453. }
  42454. }
  42455. void TextEditor::returnPressed()
  42456. {
  42457. postCommandMessage (TextEditorDefs::returnKeyMessageId);
  42458. }
  42459. void TextEditor::escapePressed()
  42460. {
  42461. postCommandMessage (TextEditorDefs::escapeKeyMessageId);
  42462. }
  42463. void TextEditor::addListener (TextEditorListener* const newListener)
  42464. {
  42465. jassert (newListener != 0)
  42466. if (newListener != 0)
  42467. listeners.add (newListener);
  42468. }
  42469. void TextEditor::removeListener (TextEditorListener* const listenerToRemove)
  42470. {
  42471. listeners.removeValue (listenerToRemove);
  42472. }
  42473. void TextEditor::timerCallbackInt()
  42474. {
  42475. const bool newState = (! caretFlashState) && ! isCurrentlyBlockedByAnotherModalComponent();
  42476. if (caretFlashState != newState)
  42477. {
  42478. caretFlashState = newState;
  42479. if (caretFlashState)
  42480. wasFocused = true;
  42481. if (caretVisible
  42482. && hasKeyboardFocus (false)
  42483. && ! isReadOnly())
  42484. {
  42485. repaintCaret();
  42486. }
  42487. }
  42488. const unsigned int now = Time::getApproximateMillisecondCounter();
  42489. if (now > lastTransactionTime + 200)
  42490. newTransaction();
  42491. }
  42492. void TextEditor::repaintCaret()
  42493. {
  42494. if (! findColour (caretColourId).isTransparent())
  42495. repaint (borderSize.getLeft() + textHolder->getX() + leftIndent + roundToInt (cursorX) - 1,
  42496. borderSize.getTop() + textHolder->getY() + topIndent + roundToInt (cursorY) - 1,
  42497. 4,
  42498. roundToInt (cursorHeight) + 2);
  42499. }
  42500. void TextEditor::repaintText (const Range<int>& range)
  42501. {
  42502. if (! range.isEmpty())
  42503. {
  42504. float x = 0, y = 0, lh = currentFont.getHeight();
  42505. const float wordWrapWidth = getWordWrapWidth();
  42506. if (wordWrapWidth > 0)
  42507. {
  42508. TextEditorIterator i (sections, wordWrapWidth, passwordCharacter);
  42509. i.getCharPosition (range.getStart(), x, y, lh);
  42510. const int y1 = (int) y;
  42511. int y2;
  42512. if (range.getEnd() >= getTotalNumChars())
  42513. {
  42514. y2 = getHeight();
  42515. }
  42516. else
  42517. {
  42518. i.getCharPosition (range.getEnd(), x, y, lh);
  42519. y2 = (int) (y + lh * 2.0f);
  42520. }
  42521. textHolder->repaint (0, y1, textHolder->getWidth(), y2 - y1);
  42522. }
  42523. }
  42524. }
  42525. void TextEditor::moveCaret (int newCaretPos)
  42526. {
  42527. if (newCaretPos < 0)
  42528. newCaretPos = 0;
  42529. else if (newCaretPos > getTotalNumChars())
  42530. newCaretPos = getTotalNumChars();
  42531. if (newCaretPos != getCaretPosition())
  42532. {
  42533. repaintCaret();
  42534. caretFlashState = true;
  42535. caretPosition = newCaretPos;
  42536. textHolder->startTimer (TextEditorDefs::flashSpeedIntervalMs);
  42537. scrollToMakeSureCursorIsVisible();
  42538. repaintCaret();
  42539. }
  42540. }
  42541. void TextEditor::setCaretPosition (const int newIndex)
  42542. {
  42543. moveCursorTo (newIndex, false);
  42544. }
  42545. int TextEditor::getCaretPosition() const
  42546. {
  42547. return caretPosition;
  42548. }
  42549. void TextEditor::scrollEditorToPositionCaret (const int desiredCaretX,
  42550. const int desiredCaretY)
  42551. {
  42552. updateCaretPosition();
  42553. int vx = roundToInt (cursorX) - desiredCaretX;
  42554. int vy = roundToInt (cursorY) - desiredCaretY;
  42555. if (desiredCaretX < jmax (1, proportionOfWidth (0.05f)))
  42556. {
  42557. vx += desiredCaretX - proportionOfWidth (0.2f);
  42558. }
  42559. else if (desiredCaretX > jmax (0, viewport->getMaximumVisibleWidth() - (wordWrap ? 2 : 10)))
  42560. {
  42561. vx += desiredCaretX + (isMultiLine() ? proportionOfWidth (0.2f) : 10) - viewport->getMaximumVisibleWidth();
  42562. }
  42563. vx = jlimit (0, jmax (0, textHolder->getWidth() + 8 - viewport->getMaximumVisibleWidth()), vx);
  42564. if (! isMultiLine())
  42565. {
  42566. vy = viewport->getViewPositionY();
  42567. }
  42568. else
  42569. {
  42570. vy = jlimit (0, jmax (0, textHolder->getHeight() - viewport->getMaximumVisibleHeight()), vy);
  42571. const int curH = roundToInt (cursorHeight);
  42572. if (desiredCaretY < 0)
  42573. {
  42574. vy = jmax (0, desiredCaretY + vy);
  42575. }
  42576. else if (desiredCaretY > jmax (0, viewport->getMaximumVisibleHeight() - topIndent - curH))
  42577. {
  42578. vy += desiredCaretY + 2 + curH + topIndent - viewport->getMaximumVisibleHeight();
  42579. }
  42580. }
  42581. viewport->setViewPosition (vx, vy);
  42582. }
  42583. const Rectangle<int> TextEditor::getCaretRectangle()
  42584. {
  42585. updateCaretPosition();
  42586. return Rectangle<int> (roundToInt (cursorX) - viewport->getX(),
  42587. roundToInt (cursorY) - viewport->getY(),
  42588. 1, roundToInt (cursorHeight));
  42589. }
  42590. float TextEditor::getWordWrapWidth() const
  42591. {
  42592. return (wordWrap) ? (float) (viewport->getMaximumVisibleWidth() - leftIndent - leftIndent / 2)
  42593. : 1.0e10f;
  42594. }
  42595. void TextEditor::updateTextHolderSize()
  42596. {
  42597. const float wordWrapWidth = getWordWrapWidth();
  42598. if (wordWrapWidth > 0)
  42599. {
  42600. float maxWidth = 0.0f;
  42601. TextEditorIterator i (sections, wordWrapWidth, passwordCharacter);
  42602. while (i.next())
  42603. maxWidth = jmax (maxWidth, i.atomRight);
  42604. const int w = leftIndent + roundToInt (maxWidth);
  42605. const int h = topIndent + roundToInt (jmax (i.lineY + i.lineHeight,
  42606. currentFont.getHeight()));
  42607. textHolder->setSize (w + 1, h + 1);
  42608. }
  42609. }
  42610. int TextEditor::getTextWidth() const
  42611. {
  42612. return textHolder->getWidth();
  42613. }
  42614. int TextEditor::getTextHeight() const
  42615. {
  42616. return textHolder->getHeight();
  42617. }
  42618. void TextEditor::setIndents (const int newLeftIndent,
  42619. const int newTopIndent)
  42620. {
  42621. leftIndent = newLeftIndent;
  42622. topIndent = newTopIndent;
  42623. }
  42624. void TextEditor::setBorder (const BorderSize& border)
  42625. {
  42626. borderSize = border;
  42627. resized();
  42628. }
  42629. const BorderSize TextEditor::getBorder() const
  42630. {
  42631. return borderSize;
  42632. }
  42633. void TextEditor::setScrollToShowCursor (const bool shouldScrollToShowCursor)
  42634. {
  42635. keepCursorOnScreen = shouldScrollToShowCursor;
  42636. }
  42637. void TextEditor::updateCaretPosition()
  42638. {
  42639. cursorHeight = currentFont.getHeight(); // (in case the text is empty and the call below doesn't set this value)
  42640. getCharPosition (caretPosition, cursorX, cursorY, cursorHeight);
  42641. }
  42642. void TextEditor::scrollToMakeSureCursorIsVisible()
  42643. {
  42644. updateCaretPosition();
  42645. if (keepCursorOnScreen)
  42646. {
  42647. int x = viewport->getViewPositionX();
  42648. int y = viewport->getViewPositionY();
  42649. const int relativeCursorX = roundToInt (cursorX) - x;
  42650. const int relativeCursorY = roundToInt (cursorY) - y;
  42651. if (relativeCursorX < jmax (1, proportionOfWidth (0.05f)))
  42652. {
  42653. x += relativeCursorX - proportionOfWidth (0.2f);
  42654. }
  42655. else if (relativeCursorX > jmax (0, viewport->getMaximumVisibleWidth() - (wordWrap ? 2 : 10)))
  42656. {
  42657. x += relativeCursorX + (isMultiLine() ? proportionOfWidth (0.2f) : 10) - viewport->getMaximumVisibleWidth();
  42658. }
  42659. x = jlimit (0, jmax (0, textHolder->getWidth() + 8 - viewport->getMaximumVisibleWidth()), x);
  42660. if (! isMultiLine())
  42661. {
  42662. y = (getHeight() - textHolder->getHeight() - topIndent) / -2;
  42663. }
  42664. else
  42665. {
  42666. const int curH = roundToInt (cursorHeight);
  42667. if (relativeCursorY < 0)
  42668. {
  42669. y = jmax (0, relativeCursorY + y);
  42670. }
  42671. else if (relativeCursorY > jmax (0, viewport->getMaximumVisibleHeight() - topIndent - curH))
  42672. {
  42673. y += relativeCursorY + 2 + curH + topIndent - viewport->getMaximumVisibleHeight();
  42674. }
  42675. }
  42676. viewport->setViewPosition (x, y);
  42677. }
  42678. }
  42679. void TextEditor::moveCursorTo (const int newPosition,
  42680. const bool isSelecting)
  42681. {
  42682. if (isSelecting)
  42683. {
  42684. moveCaret (newPosition);
  42685. const Range<int> oldSelection (selection);
  42686. if (dragType == notDragging)
  42687. {
  42688. if (abs (getCaretPosition() - selection.getStart()) < abs (getCaretPosition() - selection.getEnd()))
  42689. dragType = draggingSelectionStart;
  42690. else
  42691. dragType = draggingSelectionEnd;
  42692. }
  42693. if (dragType == draggingSelectionStart)
  42694. {
  42695. if (getCaretPosition() >= selection.getEnd())
  42696. dragType = draggingSelectionEnd;
  42697. selection = Range<int>::between (getCaretPosition(), selection.getEnd());
  42698. }
  42699. else
  42700. {
  42701. if (getCaretPosition() < selection.getStart())
  42702. dragType = draggingSelectionStart;
  42703. selection = Range<int>::between (getCaretPosition(), selection.getStart());
  42704. }
  42705. repaintText (selection.getUnionWith (oldSelection));
  42706. }
  42707. else
  42708. {
  42709. dragType = notDragging;
  42710. repaintText (selection);
  42711. moveCaret (newPosition);
  42712. selection = Range<int>::emptyRange (getCaretPosition());
  42713. }
  42714. }
  42715. int TextEditor::getTextIndexAt (const int x,
  42716. const int y)
  42717. {
  42718. return indexAtPosition ((float) (x + viewport->getViewPositionX() - leftIndent),
  42719. (float) (y + viewport->getViewPositionY() - topIndent));
  42720. }
  42721. void TextEditor::insertTextAtCaret (const String& newText_)
  42722. {
  42723. String newText (newText_);
  42724. if (allowedCharacters.isNotEmpty())
  42725. newText = newText.retainCharacters (allowedCharacters);
  42726. if (! isMultiLine())
  42727. newText = newText.replaceCharacters (T("\r\n"), T(" "));
  42728. else
  42729. newText = newText.replace (T("\r\n"), T("\n"));
  42730. const int newCaretPos = selection.getStart() + newText.length();
  42731. const int insertIndex = selection.getStart();
  42732. remove (selection, &undoManager,
  42733. newText.isNotEmpty() ? newCaretPos - 1 : newCaretPos);
  42734. if (maxTextLength > 0)
  42735. newText = newText.substring (0, maxTextLength - getTotalNumChars());
  42736. if (newText.isNotEmpty())
  42737. insert (newText,
  42738. insertIndex,
  42739. currentFont,
  42740. findColour (textColourId),
  42741. &undoManager,
  42742. newCaretPos);
  42743. textChanged();
  42744. }
  42745. void TextEditor::setHighlightedRegion (const Range<int>& newSelection)
  42746. {
  42747. moveCursorTo (newSelection.getStart(), false);
  42748. moveCursorTo (newSelection.getEnd(), true);
  42749. }
  42750. void TextEditor::copy()
  42751. {
  42752. if (passwordCharacter == 0)
  42753. {
  42754. const String selection (getHighlightedText());
  42755. if (selection.isNotEmpty())
  42756. SystemClipboard::copyTextToClipboard (selection);
  42757. }
  42758. }
  42759. void TextEditor::paste()
  42760. {
  42761. if (! isReadOnly())
  42762. {
  42763. const String clip (SystemClipboard::getTextFromClipboard());
  42764. if (clip.isNotEmpty())
  42765. insertTextAtCaret (clip);
  42766. }
  42767. }
  42768. void TextEditor::cut()
  42769. {
  42770. if (! isReadOnly())
  42771. {
  42772. moveCaret (selection.getEnd());
  42773. insertTextAtCaret (String::empty);
  42774. }
  42775. }
  42776. void TextEditor::drawContent (Graphics& g)
  42777. {
  42778. const float wordWrapWidth = getWordWrapWidth();
  42779. if (wordWrapWidth > 0)
  42780. {
  42781. g.setOrigin (leftIndent, topIndent);
  42782. const Rectangle<int> clip (g.getClipBounds());
  42783. Colour selectedTextColour;
  42784. TextEditorIterator i (sections, wordWrapWidth, passwordCharacter);
  42785. while (i.lineY + 200.0 < clip.getY() && i.next())
  42786. {}
  42787. if (! selection.isEmpty())
  42788. {
  42789. g.setColour (findColour (highlightColourId)
  42790. .withMultipliedAlpha (hasKeyboardFocus (true) ? 1.0f : 0.5f));
  42791. selectedTextColour = findColour (highlightedTextColourId);
  42792. TextEditorIterator i2 (i);
  42793. while (i2.next() && i2.lineY < clip.getBottom())
  42794. {
  42795. if (i2.lineY + i2.lineHeight >= clip.getY()
  42796. && selection.intersects (Range<int> (i2.indexInText, i2.indexInText + i2.atom->numChars)))
  42797. {
  42798. i2.drawSelection (g, selection);
  42799. }
  42800. }
  42801. }
  42802. const UniformTextSection* lastSection = 0;
  42803. while (i.next() && i.lineY < clip.getBottom())
  42804. {
  42805. if (i.lineY + i.lineHeight >= clip.getY())
  42806. {
  42807. if (selection.intersects (Range<int> (i.indexInText, i.indexInText + i.atom->numChars)))
  42808. {
  42809. i.drawSelectedText (g, selection, selectedTextColour);
  42810. lastSection = 0;
  42811. }
  42812. else
  42813. {
  42814. i.draw (g, lastSection);
  42815. }
  42816. }
  42817. }
  42818. }
  42819. }
  42820. void TextEditor::paint (Graphics& g)
  42821. {
  42822. getLookAndFeel().fillTextEditorBackground (g, getWidth(), getHeight(), *this);
  42823. }
  42824. void TextEditor::paintOverChildren (Graphics& g)
  42825. {
  42826. if (caretFlashState
  42827. && hasKeyboardFocus (false)
  42828. && caretVisible
  42829. && ! isReadOnly())
  42830. {
  42831. g.setColour (findColour (caretColourId));
  42832. g.fillRect (borderSize.getLeft() + textHolder->getX() + leftIndent + cursorX,
  42833. borderSize.getTop() + textHolder->getY() + topIndent + cursorY,
  42834. 2.0f, cursorHeight);
  42835. }
  42836. if (textToShowWhenEmpty.isNotEmpty()
  42837. && (! hasKeyboardFocus (false))
  42838. && getTotalNumChars() == 0)
  42839. {
  42840. g.setColour (colourForTextWhenEmpty);
  42841. g.setFont (getFont());
  42842. if (isMultiLine())
  42843. {
  42844. g.drawText (textToShowWhenEmpty,
  42845. 0, 0, getWidth(), getHeight(),
  42846. Justification::centred, true);
  42847. }
  42848. else
  42849. {
  42850. g.drawText (textToShowWhenEmpty,
  42851. leftIndent, topIndent,
  42852. viewport->getWidth() - leftIndent,
  42853. viewport->getHeight() - topIndent,
  42854. Justification::centredLeft, true);
  42855. }
  42856. }
  42857. getLookAndFeel().drawTextEditorOutline (g, getWidth(), getHeight(), *this);
  42858. }
  42859. void TextEditor::mouseDown (const MouseEvent& e)
  42860. {
  42861. beginDragAutoRepeat (100);
  42862. newTransaction();
  42863. if (wasFocused || ! selectAllTextWhenFocused)
  42864. {
  42865. if (! (popupMenuEnabled && e.mods.isPopupMenu()))
  42866. {
  42867. moveCursorTo (getTextIndexAt (e.x, e.y),
  42868. e.mods.isShiftDown());
  42869. }
  42870. else
  42871. {
  42872. PopupMenu m;
  42873. m.setLookAndFeel (&getLookAndFeel());
  42874. addPopupMenuItems (m, &e);
  42875. menuActive = true;
  42876. const int result = m.show();
  42877. menuActive = false;
  42878. if (result != 0)
  42879. performPopupMenuAction (result);
  42880. }
  42881. }
  42882. }
  42883. void TextEditor::mouseDrag (const MouseEvent& e)
  42884. {
  42885. if (wasFocused || ! selectAllTextWhenFocused)
  42886. {
  42887. if (! (popupMenuEnabled && e.mods.isPopupMenu()))
  42888. {
  42889. moveCursorTo (getTextIndexAt (e.x, e.y), true);
  42890. }
  42891. }
  42892. }
  42893. void TextEditor::mouseUp (const MouseEvent& e)
  42894. {
  42895. newTransaction();
  42896. textHolder->startTimer (TextEditorDefs::flashSpeedIntervalMs);
  42897. if (wasFocused || ! selectAllTextWhenFocused)
  42898. {
  42899. if (e.mouseWasClicked() && ! (popupMenuEnabled && e.mods.isPopupMenu()))
  42900. {
  42901. moveCaret (getTextIndexAt (e.x, e.y));
  42902. }
  42903. }
  42904. wasFocused = true;
  42905. }
  42906. void TextEditor::mouseDoubleClick (const MouseEvent& e)
  42907. {
  42908. int tokenEnd = getTextIndexAt (e.x, e.y);
  42909. int tokenStart = tokenEnd;
  42910. if (e.getNumberOfClicks() > 3)
  42911. {
  42912. tokenStart = 0;
  42913. tokenEnd = getTotalNumChars();
  42914. }
  42915. else
  42916. {
  42917. const String t (getText());
  42918. const int totalLength = getTotalNumChars();
  42919. while (tokenEnd < totalLength)
  42920. {
  42921. if (CharacterFunctions::isLetterOrDigit (t [tokenEnd]))
  42922. ++tokenEnd;
  42923. else
  42924. break;
  42925. }
  42926. tokenStart = tokenEnd;
  42927. while (tokenStart > 0)
  42928. {
  42929. if (CharacterFunctions::isLetterOrDigit (t [tokenStart - 1]))
  42930. --tokenStart;
  42931. else
  42932. break;
  42933. }
  42934. if (e.getNumberOfClicks() > 2)
  42935. {
  42936. while (tokenEnd < totalLength)
  42937. {
  42938. if (t [tokenEnd] != T('\r') && t [tokenEnd] != T('\n'))
  42939. ++tokenEnd;
  42940. else
  42941. break;
  42942. }
  42943. while (tokenStart > 0)
  42944. {
  42945. if (t [tokenStart - 1] != T('\r') && t [tokenStart - 1] != T('\n'))
  42946. --tokenStart;
  42947. else
  42948. break;
  42949. }
  42950. }
  42951. }
  42952. moveCursorTo (tokenEnd, false);
  42953. moveCursorTo (tokenStart, true);
  42954. }
  42955. void TextEditor::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  42956. {
  42957. if (! viewport->useMouseWheelMoveIfNeeded (e, wheelIncrementX, wheelIncrementY))
  42958. Component::mouseWheelMove (e, wheelIncrementX, wheelIncrementY);
  42959. }
  42960. bool TextEditor::keyPressed (const KeyPress& key)
  42961. {
  42962. if (isReadOnly() && key != KeyPress (T('c'), ModifierKeys::commandModifier, 0))
  42963. return false;
  42964. const bool moveInWholeWordSteps = key.getModifiers().isCtrlDown() || key.getModifiers().isAltDown();
  42965. if (key.isKeyCode (KeyPress::leftKey)
  42966. || key.isKeyCode (KeyPress::upKey))
  42967. {
  42968. newTransaction();
  42969. int newPos;
  42970. if (isMultiLine() && key.isKeyCode (KeyPress::upKey))
  42971. newPos = indexAtPosition (cursorX, cursorY - 1);
  42972. else if (moveInWholeWordSteps)
  42973. newPos = findWordBreakBefore (getCaretPosition());
  42974. else
  42975. newPos = getCaretPosition() - 1;
  42976. moveCursorTo (newPos, key.getModifiers().isShiftDown());
  42977. }
  42978. else if (key.isKeyCode (KeyPress::rightKey)
  42979. || key.isKeyCode (KeyPress::downKey))
  42980. {
  42981. newTransaction();
  42982. int newPos;
  42983. if (isMultiLine() && key.isKeyCode (KeyPress::downKey))
  42984. newPos = indexAtPosition (cursorX, cursorY + cursorHeight + 1);
  42985. else if (moveInWholeWordSteps)
  42986. newPos = findWordBreakAfter (getCaretPosition());
  42987. else
  42988. newPos = getCaretPosition() + 1;
  42989. moveCursorTo (newPos, key.getModifiers().isShiftDown());
  42990. }
  42991. else if (key.isKeyCode (KeyPress::pageDownKey) && isMultiLine())
  42992. {
  42993. newTransaction();
  42994. moveCursorTo (indexAtPosition (cursorX, cursorY + cursorHeight + viewport->getViewHeight()),
  42995. key.getModifiers().isShiftDown());
  42996. }
  42997. else if (key.isKeyCode (KeyPress::pageUpKey) && isMultiLine())
  42998. {
  42999. newTransaction();
  43000. moveCursorTo (indexAtPosition (cursorX, cursorY - viewport->getViewHeight()),
  43001. key.getModifiers().isShiftDown());
  43002. }
  43003. else if (key.isKeyCode (KeyPress::homeKey))
  43004. {
  43005. newTransaction();
  43006. if (isMultiLine() && ! moveInWholeWordSteps)
  43007. moveCursorTo (indexAtPosition (0.0f, cursorY),
  43008. key.getModifiers().isShiftDown());
  43009. else
  43010. moveCursorTo (0, key.getModifiers().isShiftDown());
  43011. }
  43012. else if (key.isKeyCode (KeyPress::endKey))
  43013. {
  43014. newTransaction();
  43015. if (isMultiLine() && ! moveInWholeWordSteps)
  43016. moveCursorTo (indexAtPosition ((float) textHolder->getWidth(), cursorY),
  43017. key.getModifiers().isShiftDown());
  43018. else
  43019. moveCursorTo (getTotalNumChars(), key.getModifiers().isShiftDown());
  43020. }
  43021. else if (key.isKeyCode (KeyPress::backspaceKey))
  43022. {
  43023. if (moveInWholeWordSteps)
  43024. {
  43025. moveCursorTo (findWordBreakBefore (getCaretPosition()), true);
  43026. }
  43027. else
  43028. {
  43029. if (selection.isEmpty() && selection.getStart() > 0)
  43030. selection.setStart (selection.getEnd() - 1);
  43031. }
  43032. cut();
  43033. }
  43034. else if (key.isKeyCode (KeyPress::deleteKey))
  43035. {
  43036. if (key.getModifiers().isShiftDown())
  43037. copy();
  43038. if (selection.isEmpty() && selection.getStart() < getTotalNumChars())
  43039. selection.setEnd (selection.getStart() + 1);
  43040. cut();
  43041. }
  43042. else if (key == KeyPress (T('c'), ModifierKeys::commandModifier, 0)
  43043. || key == KeyPress (KeyPress::insertKey, ModifierKeys::ctrlModifier, 0))
  43044. {
  43045. newTransaction();
  43046. copy();
  43047. }
  43048. else if (key == KeyPress (T('x'), ModifierKeys::commandModifier, 0))
  43049. {
  43050. newTransaction();
  43051. copy();
  43052. cut();
  43053. }
  43054. else if (key == KeyPress (T('v'), ModifierKeys::commandModifier, 0)
  43055. || key == KeyPress (KeyPress::insertKey, ModifierKeys::shiftModifier, 0))
  43056. {
  43057. newTransaction();
  43058. paste();
  43059. }
  43060. else if (key == KeyPress (T('z'), ModifierKeys::commandModifier, 0))
  43061. {
  43062. newTransaction();
  43063. doUndoRedo (false);
  43064. }
  43065. else if (key == KeyPress (T('y'), ModifierKeys::commandModifier, 0))
  43066. {
  43067. newTransaction();
  43068. doUndoRedo (true);
  43069. }
  43070. else if (key == KeyPress (T('a'), ModifierKeys::commandModifier, 0))
  43071. {
  43072. newTransaction();
  43073. moveCursorTo (getTotalNumChars(), false);
  43074. moveCursorTo (0, true);
  43075. }
  43076. else if (key == KeyPress::returnKey)
  43077. {
  43078. newTransaction();
  43079. if (returnKeyStartsNewLine)
  43080. insertTextAtCaret (T("\n"));
  43081. else
  43082. returnPressed();
  43083. }
  43084. else if (key.isKeyCode (KeyPress::escapeKey))
  43085. {
  43086. newTransaction();
  43087. moveCursorTo (getCaretPosition(), false);
  43088. escapePressed();
  43089. }
  43090. else if (key.getTextCharacter() >= ' '
  43091. || (tabKeyUsed && (key.getTextCharacter() == '\t')))
  43092. {
  43093. insertTextAtCaret (String::charToString (key.getTextCharacter()));
  43094. lastTransactionTime = Time::getApproximateMillisecondCounter();
  43095. }
  43096. else
  43097. {
  43098. return false;
  43099. }
  43100. return true;
  43101. }
  43102. bool TextEditor::keyStateChanged (const bool isKeyDown)
  43103. {
  43104. if (! isKeyDown)
  43105. return false;
  43106. #if JUCE_WIN32
  43107. if (KeyPress (KeyPress::F4Key, ModifierKeys::altModifier, 0).isCurrentlyDown())
  43108. return false; // We need to explicitly allow alt-F4 to pass through on Windows
  43109. #endif
  43110. // (overridden to avoid forwarding key events to the parent)
  43111. return ! ModifierKeys::getCurrentModifiers().isCommandDown();
  43112. }
  43113. const int baseMenuItemID = 0x7fff0000;
  43114. void TextEditor::addPopupMenuItems (PopupMenu& m, const MouseEvent*)
  43115. {
  43116. const bool writable = ! isReadOnly();
  43117. if (passwordCharacter == 0)
  43118. {
  43119. m.addItem (baseMenuItemID + 1, TRANS("cut"), writable);
  43120. m.addItem (baseMenuItemID + 2, TRANS("copy"), ! selection.isEmpty());
  43121. m.addItem (baseMenuItemID + 3, TRANS("paste"), writable);
  43122. }
  43123. m.addItem (baseMenuItemID + 4, TRANS("delete"), writable);
  43124. m.addSeparator();
  43125. m.addItem (baseMenuItemID + 5, TRANS("select all"));
  43126. m.addSeparator();
  43127. m.addItem (baseMenuItemID + 6, TRANS("undo"), undoManager.canUndo());
  43128. m.addItem (baseMenuItemID + 7, TRANS("redo"), undoManager.canRedo());
  43129. }
  43130. void TextEditor::performPopupMenuAction (const int menuItemID)
  43131. {
  43132. switch (menuItemID)
  43133. {
  43134. case baseMenuItemID + 1:
  43135. copy();
  43136. cut();
  43137. break;
  43138. case baseMenuItemID + 2:
  43139. copy();
  43140. break;
  43141. case baseMenuItemID + 3:
  43142. paste();
  43143. break;
  43144. case baseMenuItemID + 4:
  43145. cut();
  43146. break;
  43147. case baseMenuItemID + 5:
  43148. moveCursorTo (getTotalNumChars(), false);
  43149. moveCursorTo (0, true);
  43150. break;
  43151. case baseMenuItemID + 6:
  43152. doUndoRedo (false);
  43153. break;
  43154. case baseMenuItemID + 7:
  43155. doUndoRedo (true);
  43156. break;
  43157. default:
  43158. break;
  43159. }
  43160. }
  43161. void TextEditor::focusGained (FocusChangeType)
  43162. {
  43163. newTransaction();
  43164. caretFlashState = true;
  43165. if (selectAllTextWhenFocused)
  43166. {
  43167. moveCursorTo (0, false);
  43168. moveCursorTo (getTotalNumChars(), true);
  43169. }
  43170. repaint();
  43171. if (caretVisible)
  43172. textHolder->startTimer (TextEditorDefs::flashSpeedIntervalMs);
  43173. ComponentPeer* const peer = getPeer();
  43174. if (peer != 0 && ! isReadOnly())
  43175. peer->textInputRequired (getScreenX() - peer->getScreenX(),
  43176. getScreenY() - peer->getScreenY());
  43177. }
  43178. void TextEditor::focusLost (FocusChangeType)
  43179. {
  43180. newTransaction();
  43181. wasFocused = false;
  43182. textHolder->stopTimer();
  43183. caretFlashState = false;
  43184. postCommandMessage (TextEditorDefs::focusLossMessageId);
  43185. repaint();
  43186. }
  43187. void TextEditor::resized()
  43188. {
  43189. viewport->setBoundsInset (borderSize);
  43190. viewport->setSingleStepSizes (16, roundToInt (currentFont.getHeight()));
  43191. updateTextHolderSize();
  43192. if (! isMultiLine())
  43193. {
  43194. scrollToMakeSureCursorIsVisible();
  43195. }
  43196. else
  43197. {
  43198. updateCaretPosition();
  43199. }
  43200. }
  43201. void TextEditor::handleCommandMessage (const int commandId)
  43202. {
  43203. const ComponentDeletionWatcher deletionChecker (this);
  43204. for (int i = listeners.size(); --i >= 0;)
  43205. {
  43206. TextEditorListener* const tl = (TextEditorListener*) listeners [i];
  43207. if (tl != 0)
  43208. {
  43209. switch (commandId)
  43210. {
  43211. case TextEditorDefs::textChangeMessageId:
  43212. tl->textEditorTextChanged (*this);
  43213. break;
  43214. case TextEditorDefs::returnKeyMessageId:
  43215. tl->textEditorReturnKeyPressed (*this);
  43216. break;
  43217. case TextEditorDefs::escapeKeyMessageId:
  43218. tl->textEditorEscapeKeyPressed (*this);
  43219. break;
  43220. case TextEditorDefs::focusLossMessageId:
  43221. tl->textEditorFocusLost (*this);
  43222. break;
  43223. default:
  43224. jassertfalse
  43225. break;
  43226. }
  43227. if (i > 0 && deletionChecker.hasBeenDeleted())
  43228. return;
  43229. }
  43230. }
  43231. }
  43232. void TextEditor::enablementChanged()
  43233. {
  43234. setMouseCursor (MouseCursor (isReadOnly() ? MouseCursor::NormalCursor
  43235. : MouseCursor::IBeamCursor));
  43236. repaint();
  43237. }
  43238. void TextEditor::clearInternal (UndoManager* const um)
  43239. {
  43240. remove (Range<int> (0, getTotalNumChars()), um, caretPosition);
  43241. }
  43242. void TextEditor::insert (const String& text,
  43243. const int insertIndex,
  43244. const Font& font,
  43245. const Colour& colour,
  43246. UndoManager* const um,
  43247. const int caretPositionToMoveTo)
  43248. {
  43249. if (text.isNotEmpty())
  43250. {
  43251. if (um != 0)
  43252. {
  43253. if (um->getNumActionsInCurrentTransaction() > TextEditorDefs::maxActionsPerTransaction)
  43254. newTransaction();
  43255. um->perform (new TextEditorInsertAction (*this,
  43256. text,
  43257. insertIndex,
  43258. font,
  43259. colour,
  43260. caretPosition,
  43261. caretPositionToMoveTo));
  43262. }
  43263. else
  43264. {
  43265. repaintText (Range<int> (insertIndex, getTotalNumChars())); // must do this before and after changing the data, in case
  43266. // a line gets moved due to word wrap
  43267. int index = 0;
  43268. int nextIndex = 0;
  43269. for (int i = 0; i < sections.size(); ++i)
  43270. {
  43271. nextIndex = index + ((UniformTextSection*) sections.getUnchecked(i))->getTotalLength();
  43272. if (insertIndex == index)
  43273. {
  43274. sections.insert (i, new UniformTextSection (text,
  43275. font, colour,
  43276. passwordCharacter));
  43277. break;
  43278. }
  43279. else if (insertIndex > index && insertIndex < nextIndex)
  43280. {
  43281. splitSection (i, insertIndex - index);
  43282. sections.insert (i + 1, new UniformTextSection (text,
  43283. font, colour,
  43284. passwordCharacter));
  43285. break;
  43286. }
  43287. index = nextIndex;
  43288. }
  43289. if (nextIndex == insertIndex)
  43290. sections.add (new UniformTextSection (text,
  43291. font, colour,
  43292. passwordCharacter));
  43293. coalesceSimilarSections();
  43294. totalNumChars = -1;
  43295. valueTextNeedsUpdating = true;
  43296. moveCursorTo (caretPositionToMoveTo, false);
  43297. repaintText (Range<int> (insertIndex, getTotalNumChars()));
  43298. }
  43299. }
  43300. }
  43301. void TextEditor::reinsert (const int insertIndex,
  43302. const VoidArray& sectionsToInsert)
  43303. {
  43304. int index = 0;
  43305. int nextIndex = 0;
  43306. for (int i = 0; i < sections.size(); ++i)
  43307. {
  43308. nextIndex = index + ((UniformTextSection*) sections.getUnchecked(i))->getTotalLength();
  43309. if (insertIndex == index)
  43310. {
  43311. for (int j = sectionsToInsert.size(); --j >= 0;)
  43312. sections.insert (i, new UniformTextSection (*(UniformTextSection*) sectionsToInsert.getUnchecked(j)));
  43313. break;
  43314. }
  43315. else if (insertIndex > index && insertIndex < nextIndex)
  43316. {
  43317. splitSection (i, insertIndex - index);
  43318. for (int j = sectionsToInsert.size(); --j >= 0;)
  43319. sections.insert (i + 1, new UniformTextSection (*(UniformTextSection*) sectionsToInsert.getUnchecked(j)));
  43320. break;
  43321. }
  43322. index = nextIndex;
  43323. }
  43324. if (nextIndex == insertIndex)
  43325. {
  43326. for (int j = 0; j < sectionsToInsert.size(); ++j)
  43327. sections.add (new UniformTextSection (*(UniformTextSection*) sectionsToInsert.getUnchecked(j)));
  43328. }
  43329. coalesceSimilarSections();
  43330. totalNumChars = -1;
  43331. valueTextNeedsUpdating = true;
  43332. }
  43333. void TextEditor::remove (const Range<int>& range,
  43334. UndoManager* const um,
  43335. const int caretPositionToMoveTo)
  43336. {
  43337. if (! range.isEmpty())
  43338. {
  43339. int index = 0;
  43340. for (int i = 0; i < sections.size(); ++i)
  43341. {
  43342. const int nextIndex = index + ((UniformTextSection*) sections[i])->getTotalLength();
  43343. if (range.getStart() > index && range.getStart() < nextIndex)
  43344. {
  43345. splitSection (i, range.getStart() - index);
  43346. --i;
  43347. }
  43348. else if (range.getEnd() > index && range.getEnd() < nextIndex)
  43349. {
  43350. splitSection (i, range.getEnd() - index);
  43351. --i;
  43352. }
  43353. else
  43354. {
  43355. index = nextIndex;
  43356. if (index > range.getEnd())
  43357. break;
  43358. }
  43359. }
  43360. index = 0;
  43361. if (um != 0)
  43362. {
  43363. VoidArray removedSections;
  43364. for (int i = 0; i < sections.size(); ++i)
  43365. {
  43366. if (range.getEnd() <= range.getStart())
  43367. break;
  43368. UniformTextSection* const section = (UniformTextSection*) sections.getUnchecked (i);
  43369. const int nextIndex = index + section->getTotalLength();
  43370. if (range.getStart() <= index && range.getEnd() >= nextIndex)
  43371. removedSections.add (new UniformTextSection (*section));
  43372. index = nextIndex;
  43373. }
  43374. if (um->getNumActionsInCurrentTransaction() > TextEditorDefs::maxActionsPerTransaction)
  43375. newTransaction();
  43376. um->perform (new TextEditorRemoveAction (*this,
  43377. range,
  43378. caretPosition,
  43379. caretPositionToMoveTo,
  43380. removedSections));
  43381. }
  43382. else
  43383. {
  43384. Range<int> remainingRange (range);
  43385. for (int i = 0; i < sections.size(); ++i)
  43386. {
  43387. UniformTextSection* const section = (UniformTextSection*) sections.getUnchecked (i);
  43388. const int nextIndex = index + section->getTotalLength();
  43389. if (remainingRange.getStart() <= index && remainingRange.getEnd() >= nextIndex)
  43390. {
  43391. sections.remove(i);
  43392. section->clear();
  43393. delete section;
  43394. remainingRange.setEnd (remainingRange.getEnd() - (nextIndex - index));
  43395. if (remainingRange.isEmpty())
  43396. break;
  43397. --i;
  43398. }
  43399. else
  43400. {
  43401. index = nextIndex;
  43402. }
  43403. }
  43404. coalesceSimilarSections();
  43405. totalNumChars = -1;
  43406. valueTextNeedsUpdating = true;
  43407. moveCursorTo (caretPositionToMoveTo, false);
  43408. repaintText (Range<int> (range.getStart(), getTotalNumChars()));
  43409. }
  43410. }
  43411. }
  43412. const String TextEditor::getText() const
  43413. {
  43414. String t;
  43415. t.preallocateStorage (getTotalNumChars());
  43416. String::Concatenator concatenator (t);
  43417. for (int i = 0; i < sections.size(); ++i)
  43418. ((const UniformTextSection*) sections.getUnchecked(i))->appendAllText (concatenator);
  43419. return t;
  43420. }
  43421. const String TextEditor::getTextInRange (const Range<int>& range) const
  43422. {
  43423. String t;
  43424. if (! range.isEmpty())
  43425. {
  43426. t.preallocateStorage (jmin (getTotalNumChars(), range.getLength()));
  43427. String::Concatenator concatenator (t);
  43428. int index = 0;
  43429. for (int i = 0; i < sections.size(); ++i)
  43430. {
  43431. const UniformTextSection* const s = (const UniformTextSection*) sections.getUnchecked(i);
  43432. const int nextIndex = index + s->getTotalLength();
  43433. if (range.getStart() < nextIndex)
  43434. {
  43435. if (range.getEnd() <= index)
  43436. break;
  43437. s->appendSubstring (concatenator, range - index);
  43438. }
  43439. index = nextIndex;
  43440. }
  43441. }
  43442. return t;
  43443. }
  43444. const String TextEditor::getHighlightedText() const
  43445. {
  43446. return getTextInRange (selection);
  43447. }
  43448. int TextEditor::getTotalNumChars() const
  43449. {
  43450. if (totalNumChars < 0)
  43451. {
  43452. totalNumChars = 0;
  43453. for (int i = sections.size(); --i >= 0;)
  43454. totalNumChars += ((const UniformTextSection*) sections.getUnchecked(i))->getTotalLength();
  43455. }
  43456. return totalNumChars;
  43457. }
  43458. bool TextEditor::isEmpty() const
  43459. {
  43460. return getTotalNumChars() == 0;
  43461. }
  43462. void TextEditor::getCharPosition (const int index, float& cx, float& cy, float& lineHeight) const
  43463. {
  43464. const float wordWrapWidth = getWordWrapWidth();
  43465. if (wordWrapWidth > 0 && sections.size() > 0)
  43466. {
  43467. TextEditorIterator i (sections, wordWrapWidth, passwordCharacter);
  43468. i.getCharPosition (index, cx, cy, lineHeight);
  43469. }
  43470. else
  43471. {
  43472. cx = cy = 0;
  43473. lineHeight = currentFont.getHeight();
  43474. }
  43475. }
  43476. int TextEditor::indexAtPosition (const float x, const float y)
  43477. {
  43478. const float wordWrapWidth = getWordWrapWidth();
  43479. if (wordWrapWidth > 0)
  43480. {
  43481. TextEditorIterator i (sections, wordWrapWidth, passwordCharacter);
  43482. while (i.next())
  43483. {
  43484. if (i.lineY + i.lineHeight > y)
  43485. {
  43486. if (i.lineY > y)
  43487. return jmax (0, i.indexInText - 1);
  43488. if (i.atomX >= x)
  43489. return i.indexInText;
  43490. if (x < i.atomRight)
  43491. return i.xToIndex (x);
  43492. }
  43493. }
  43494. }
  43495. return getTotalNumChars();
  43496. }
  43497. static int getCharacterCategory (const tchar character)
  43498. {
  43499. return CharacterFunctions::isLetterOrDigit (character)
  43500. ? 2 : (CharacterFunctions::isWhitespace (character) ? 0 : 1);
  43501. }
  43502. int TextEditor::findWordBreakAfter (const int position) const
  43503. {
  43504. const String t (getTextInRange (Range<int> (position, position + 512)));
  43505. const int totalLength = t.length();
  43506. int i = 0;
  43507. while (i < totalLength && CharacterFunctions::isWhitespace (t[i]))
  43508. ++i;
  43509. const int type = getCharacterCategory (t[i]);
  43510. while (i < totalLength && type == getCharacterCategory (t[i]))
  43511. ++i;
  43512. while (i < totalLength && CharacterFunctions::isWhitespace (t[i]))
  43513. ++i;
  43514. return position + i;
  43515. }
  43516. int TextEditor::findWordBreakBefore (const int position) const
  43517. {
  43518. if (position <= 0)
  43519. return 0;
  43520. const int startOfBuffer = jmax (0, position - 512);
  43521. const String t (getTextInRange (Range<int> (startOfBuffer, position)));
  43522. int i = position - startOfBuffer;
  43523. while (i > 0 && CharacterFunctions::isWhitespace (t [i - 1]))
  43524. --i;
  43525. if (i > 0)
  43526. {
  43527. const int type = getCharacterCategory (t [i - 1]);
  43528. while (i > 0 && type == getCharacterCategory (t [i - 1]))
  43529. --i;
  43530. }
  43531. jassert (startOfBuffer + i >= 0);
  43532. return startOfBuffer + i;
  43533. }
  43534. void TextEditor::splitSection (const int sectionIndex,
  43535. const int charToSplitAt)
  43536. {
  43537. jassert (sections[sectionIndex] != 0);
  43538. sections.insert (sectionIndex + 1,
  43539. ((UniformTextSection*) sections.getUnchecked (sectionIndex))
  43540. ->split (charToSplitAt, passwordCharacter));
  43541. }
  43542. void TextEditor::coalesceSimilarSections()
  43543. {
  43544. for (int i = 0; i < sections.size() - 1; ++i)
  43545. {
  43546. UniformTextSection* const s1 = (UniformTextSection*) sections.getUnchecked (i);
  43547. UniformTextSection* const s2 = (UniformTextSection*) sections.getUnchecked (i + 1);
  43548. if (s1->font == s2->font
  43549. && s1->colour == s2->colour)
  43550. {
  43551. s1->append (*s2, passwordCharacter);
  43552. sections.remove (i + 1);
  43553. delete s2;
  43554. --i;
  43555. }
  43556. }
  43557. }
  43558. END_JUCE_NAMESPACE
  43559. /*** End of inlined file: juce_TextEditor.cpp ***/
  43560. /*** Start of inlined file: juce_Toolbar.cpp ***/
  43561. BEGIN_JUCE_NAMESPACE
  43562. const tchar* const Toolbar::toolbarDragDescriptor = T("_toolbarItem_");
  43563. class ToolbarSpacerComp : public ToolbarItemComponent
  43564. {
  43565. public:
  43566. ToolbarSpacerComp (const int itemId_, const float fixedSize_, const bool drawBar_)
  43567. : ToolbarItemComponent (itemId_, String::empty, false),
  43568. fixedSize (fixedSize_),
  43569. drawBar (drawBar_)
  43570. {
  43571. }
  43572. ~ToolbarSpacerComp()
  43573. {
  43574. }
  43575. bool getToolbarItemSizes (int toolbarThickness, bool /*isToolbarVertical*/,
  43576. int& preferredSize, int& minSize, int& maxSize)
  43577. {
  43578. if (fixedSize <= 0)
  43579. {
  43580. preferredSize = toolbarThickness * 2;
  43581. minSize = 4;
  43582. maxSize = 32768;
  43583. }
  43584. else
  43585. {
  43586. maxSize = roundToInt (toolbarThickness * fixedSize);
  43587. minSize = drawBar ? maxSize : jmin (4, maxSize);
  43588. preferredSize = maxSize;
  43589. if (getEditingMode() == editableOnPalette)
  43590. preferredSize = maxSize = toolbarThickness / (drawBar ? 3 : 2);
  43591. }
  43592. return true;
  43593. }
  43594. void paintButtonArea (Graphics&, int, int, bool, bool)
  43595. {
  43596. }
  43597. void contentAreaChanged (const Rectangle<int>&)
  43598. {
  43599. }
  43600. int getResizeOrder() const throw()
  43601. {
  43602. return fixedSize <= 0 ? 0 : 1;
  43603. }
  43604. void paint (Graphics& g)
  43605. {
  43606. const int w = getWidth();
  43607. const int h = getHeight();
  43608. if (drawBar)
  43609. {
  43610. g.setColour (findColour (Toolbar::separatorColourId, true));
  43611. const float thickness = 0.2f;
  43612. if (isToolbarVertical())
  43613. g.fillRect (w * 0.1f, h * (0.5f - thickness * 0.5f), w * 0.8f, h * thickness);
  43614. else
  43615. g.fillRect (w * (0.5f - thickness * 0.5f), h * 0.1f, w * thickness, h * 0.8f);
  43616. }
  43617. if (getEditingMode() != normalMode && ! drawBar)
  43618. {
  43619. g.setColour (findColour (Toolbar::separatorColourId, true));
  43620. const int indentX = jmin (2, (w - 3) / 2);
  43621. const int indentY = jmin (2, (h - 3) / 2);
  43622. g.drawRect (indentX, indentY, w - indentX * 2, h - indentY * 2, 1);
  43623. if (fixedSize <= 0)
  43624. {
  43625. float x1, y1, x2, y2, x3, y3, x4, y4, hw, hl;
  43626. if (isToolbarVertical())
  43627. {
  43628. x1 = w * 0.5f;
  43629. y1 = h * 0.4f;
  43630. x2 = x1;
  43631. y2 = indentX * 2.0f;
  43632. x3 = x1;
  43633. y3 = h * 0.6f;
  43634. x4 = x1;
  43635. y4 = h - y2;
  43636. hw = w * 0.15f;
  43637. hl = w * 0.2f;
  43638. }
  43639. else
  43640. {
  43641. x1 = w * 0.4f;
  43642. y1 = h * 0.5f;
  43643. x2 = indentX * 2.0f;
  43644. y2 = y1;
  43645. x3 = w * 0.6f;
  43646. y3 = y1;
  43647. x4 = w - x2;
  43648. y4 = y1;
  43649. hw = h * 0.15f;
  43650. hl = h * 0.2f;
  43651. }
  43652. Path p;
  43653. p.addArrow (x1, y1, x2, y2, 1.5f, hw, hl);
  43654. p.addArrow (x3, y3, x4, y4, 1.5f, hw, hl);
  43655. g.fillPath (p);
  43656. }
  43657. }
  43658. }
  43659. juce_UseDebuggingNewOperator
  43660. private:
  43661. const float fixedSize;
  43662. const bool drawBar;
  43663. ToolbarSpacerComp (const ToolbarSpacerComp&);
  43664. const ToolbarSpacerComp& operator= (const ToolbarSpacerComp&);
  43665. };
  43666. class MissingItemsComponent : public PopupMenuCustomComponent
  43667. {
  43668. public:
  43669. MissingItemsComponent (Toolbar& owner_, const int height_)
  43670. : PopupMenuCustomComponent (true),
  43671. owner (owner_),
  43672. height (height_)
  43673. {
  43674. for (int i = owner_.items.size(); --i >= 0;)
  43675. {
  43676. ToolbarItemComponent* const tc = owner_.items.getUnchecked(i);
  43677. if (dynamic_cast <ToolbarSpacerComp*> (tc) == 0 && ! tc->isVisible())
  43678. {
  43679. oldIndexes.insert (0, i);
  43680. addAndMakeVisible (tc, 0);
  43681. }
  43682. }
  43683. layout (400);
  43684. }
  43685. ~MissingItemsComponent()
  43686. {
  43687. // deleting the toolbar while its menu it open??
  43688. jassert (owner.isValidComponent());
  43689. for (int i = 0; i < getNumChildComponents(); ++i)
  43690. {
  43691. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getChildComponent (i));
  43692. if (tc != 0)
  43693. {
  43694. tc->setVisible (false);
  43695. const int index = oldIndexes.remove (i);
  43696. owner.addChildComponent (tc, index);
  43697. --i;
  43698. }
  43699. }
  43700. owner.resized();
  43701. }
  43702. void layout (const int preferredWidth)
  43703. {
  43704. const int indent = 8;
  43705. int x = indent;
  43706. int y = indent;
  43707. int maxX = 0;
  43708. for (int i = 0; i < getNumChildComponents(); ++i)
  43709. {
  43710. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getChildComponent (i));
  43711. if (tc != 0)
  43712. {
  43713. int preferredSize = 1, minSize = 1, maxSize = 1;
  43714. if (tc->getToolbarItemSizes (height, false, preferredSize, minSize, maxSize))
  43715. {
  43716. if (x + preferredSize > preferredWidth && x > indent)
  43717. {
  43718. x = indent;
  43719. y += height;
  43720. }
  43721. tc->setBounds (x, y, preferredSize, height);
  43722. x += preferredSize;
  43723. maxX = jmax (maxX, x);
  43724. }
  43725. }
  43726. }
  43727. setSize (maxX + 8, y + height + 8);
  43728. }
  43729. void getIdealSize (int& idealWidth, int& idealHeight)
  43730. {
  43731. idealWidth = getWidth();
  43732. idealHeight = getHeight();
  43733. }
  43734. juce_UseDebuggingNewOperator
  43735. private:
  43736. Toolbar& owner;
  43737. const int height;
  43738. Array <int> oldIndexes;
  43739. MissingItemsComponent (const MissingItemsComponent&);
  43740. const MissingItemsComponent& operator= (const MissingItemsComponent&);
  43741. };
  43742. Toolbar::Toolbar()
  43743. : vertical (false),
  43744. isEditingActive (false),
  43745. toolbarStyle (Toolbar::iconsOnly)
  43746. {
  43747. addChildComponent (missingItemsButton = getLookAndFeel().createToolbarMissingItemsButton (*this));
  43748. missingItemsButton->setAlwaysOnTop (true);
  43749. missingItemsButton->addButtonListener (this);
  43750. }
  43751. Toolbar::~Toolbar()
  43752. {
  43753. animator.cancelAllAnimations (true);
  43754. deleteAllChildren();
  43755. }
  43756. void Toolbar::setVertical (const bool shouldBeVertical)
  43757. {
  43758. if (vertical != shouldBeVertical)
  43759. {
  43760. vertical = shouldBeVertical;
  43761. resized();
  43762. }
  43763. }
  43764. void Toolbar::clear()
  43765. {
  43766. for (int i = items.size(); --i >= 0;)
  43767. {
  43768. ToolbarItemComponent* const tc = items.getUnchecked(i);
  43769. items.remove (i);
  43770. delete tc;
  43771. }
  43772. resized();
  43773. }
  43774. ToolbarItemComponent* Toolbar::createItem (ToolbarItemFactory& factory, const int itemId)
  43775. {
  43776. if (itemId == ToolbarItemFactory::separatorBarId)
  43777. return new ToolbarSpacerComp (itemId, 0.1f, true);
  43778. else if (itemId == ToolbarItemFactory::spacerId)
  43779. return new ToolbarSpacerComp (itemId, 0.5f, false);
  43780. else if (itemId == ToolbarItemFactory::flexibleSpacerId)
  43781. return new ToolbarSpacerComp (itemId, 0, false);
  43782. return factory.createItem (itemId);
  43783. }
  43784. void Toolbar::addItemInternal (ToolbarItemFactory& factory,
  43785. const int itemId,
  43786. const int insertIndex)
  43787. {
  43788. // An ID can't be zero - this might indicate a mistake somewhere?
  43789. jassert (itemId != 0);
  43790. ToolbarItemComponent* const tc = createItem (factory, itemId);
  43791. if (tc != 0)
  43792. {
  43793. #ifdef JUCE_DEBUG
  43794. Array <int> allowedIds;
  43795. factory.getAllToolbarItemIds (allowedIds);
  43796. // If your factory can create an item for a given ID, it must also return
  43797. // that ID from its getAllToolbarItemIds() method!
  43798. jassert (allowedIds.contains (itemId));
  43799. #endif
  43800. items.insert (insertIndex, tc);
  43801. addAndMakeVisible (tc, insertIndex);
  43802. }
  43803. }
  43804. void Toolbar::addItem (ToolbarItemFactory& factory,
  43805. const int itemId,
  43806. const int insertIndex)
  43807. {
  43808. addItemInternal (factory, itemId, insertIndex);
  43809. resized();
  43810. }
  43811. void Toolbar::addDefaultItems (ToolbarItemFactory& factoryToUse)
  43812. {
  43813. Array <int> ids;
  43814. factoryToUse.getDefaultItemSet (ids);
  43815. clear();
  43816. for (int i = 0; i < ids.size(); ++i)
  43817. addItemInternal (factoryToUse, ids.getUnchecked (i), -1);
  43818. resized();
  43819. }
  43820. void Toolbar::removeToolbarItem (const int itemIndex)
  43821. {
  43822. ToolbarItemComponent* const tc = getItemComponent (itemIndex);
  43823. if (tc != 0)
  43824. {
  43825. items.removeValue (tc);
  43826. delete tc;
  43827. resized();
  43828. }
  43829. }
  43830. int Toolbar::getNumItems() const throw()
  43831. {
  43832. return items.size();
  43833. }
  43834. int Toolbar::getItemId (const int itemIndex) const throw()
  43835. {
  43836. ToolbarItemComponent* const tc = getItemComponent (itemIndex);
  43837. return tc != 0 ? tc->getItemId() : 0;
  43838. }
  43839. ToolbarItemComponent* Toolbar::getItemComponent (const int itemIndex) const throw()
  43840. {
  43841. return items [itemIndex];
  43842. }
  43843. ToolbarItemComponent* Toolbar::getNextActiveComponent (int index, const int delta) const
  43844. {
  43845. for (;;)
  43846. {
  43847. index += delta;
  43848. ToolbarItemComponent* const tc = getItemComponent (index);
  43849. if (tc == 0)
  43850. break;
  43851. if (tc->isActive)
  43852. return tc;
  43853. }
  43854. return 0;
  43855. }
  43856. void Toolbar::setStyle (const ToolbarItemStyle& newStyle)
  43857. {
  43858. if (toolbarStyle != newStyle)
  43859. {
  43860. toolbarStyle = newStyle;
  43861. updateAllItemPositions (false);
  43862. }
  43863. }
  43864. const String Toolbar::toString() const
  43865. {
  43866. String s (T("TB:"));
  43867. for (int i = 0; i < getNumItems(); ++i)
  43868. s << getItemId(i) << T(' ');
  43869. return s.trimEnd();
  43870. }
  43871. bool Toolbar::restoreFromString (ToolbarItemFactory& factoryToUse,
  43872. const String& savedVersion)
  43873. {
  43874. if (! savedVersion.startsWith (T("TB:")))
  43875. return false;
  43876. StringArray tokens;
  43877. tokens.addTokens (savedVersion.substring (3), false);
  43878. clear();
  43879. for (int i = 0; i < tokens.size(); ++i)
  43880. addItemInternal (factoryToUse, tokens[i].getIntValue(), -1);
  43881. resized();
  43882. return true;
  43883. }
  43884. void Toolbar::paint (Graphics& g)
  43885. {
  43886. getLookAndFeel().paintToolbarBackground (g, getWidth(), getHeight(), *this);
  43887. }
  43888. int Toolbar::getThickness() const throw()
  43889. {
  43890. return vertical ? getWidth() : getHeight();
  43891. }
  43892. int Toolbar::getLength() const throw()
  43893. {
  43894. return vertical ? getHeight() : getWidth();
  43895. }
  43896. void Toolbar::setEditingActive (const bool active)
  43897. {
  43898. if (isEditingActive != active)
  43899. {
  43900. isEditingActive = active;
  43901. updateAllItemPositions (false);
  43902. }
  43903. }
  43904. void Toolbar::resized()
  43905. {
  43906. updateAllItemPositions (false);
  43907. }
  43908. void Toolbar::updateAllItemPositions (const bool animate)
  43909. {
  43910. if (getWidth() > 0 && getHeight() > 0)
  43911. {
  43912. StretchableObjectResizer resizer;
  43913. int i;
  43914. for (i = 0; i < items.size(); ++i)
  43915. {
  43916. ToolbarItemComponent* const tc = items.getUnchecked(i);
  43917. tc->setEditingMode (isEditingActive ? ToolbarItemComponent::editableOnToolbar
  43918. : ToolbarItemComponent::normalMode);
  43919. tc->setStyle (toolbarStyle);
  43920. ToolbarSpacerComp* const spacer = dynamic_cast <ToolbarSpacerComp*> (tc);
  43921. int preferredSize = 1, minSize = 1, maxSize = 1;
  43922. if (tc->getToolbarItemSizes (getThickness(), isVertical(),
  43923. preferredSize, minSize, maxSize))
  43924. {
  43925. tc->isActive = true;
  43926. resizer.addItem (preferredSize, minSize, maxSize,
  43927. spacer != 0 ? spacer->getResizeOrder() : 2);
  43928. }
  43929. else
  43930. {
  43931. tc->isActive = false;
  43932. tc->setVisible (false);
  43933. }
  43934. }
  43935. resizer.resizeToFit (getLength());
  43936. int totalLength = 0;
  43937. for (i = 0; i < resizer.getNumItems(); ++i)
  43938. totalLength += (int) resizer.getItemSize (i);
  43939. const bool itemsOffTheEnd = totalLength > getLength();
  43940. const int extrasButtonSize = getThickness() / 2;
  43941. missingItemsButton->setSize (extrasButtonSize, extrasButtonSize);
  43942. missingItemsButton->setVisible (itemsOffTheEnd);
  43943. missingItemsButton->setEnabled (! isEditingActive);
  43944. if (vertical)
  43945. missingItemsButton->setCentrePosition (getWidth() / 2,
  43946. getHeight() - 4 - extrasButtonSize / 2);
  43947. else
  43948. missingItemsButton->setCentrePosition (getWidth() - 4 - extrasButtonSize / 2,
  43949. getHeight() / 2);
  43950. const int maxLength = itemsOffTheEnd ? (vertical ? missingItemsButton->getY()
  43951. : missingItemsButton->getX()) - 4
  43952. : getLength();
  43953. int pos = 0, activeIndex = 0;
  43954. for (i = 0; i < items.size(); ++i)
  43955. {
  43956. ToolbarItemComponent* const tc = items.getUnchecked(i);
  43957. if (tc->isActive)
  43958. {
  43959. const int size = (int) resizer.getItemSize (activeIndex++);
  43960. Rectangle<int> newBounds;
  43961. if (vertical)
  43962. newBounds.setBounds (0, pos, getWidth(), size);
  43963. else
  43964. newBounds.setBounds (pos, 0, size, getHeight());
  43965. if (animate)
  43966. {
  43967. animator.animateComponent (tc, newBounds, 200, 3.0, 0.0);
  43968. }
  43969. else
  43970. {
  43971. animator.cancelAnimation (tc, false);
  43972. tc->setBounds (newBounds);
  43973. }
  43974. pos += size;
  43975. tc->setVisible (pos <= maxLength
  43976. && ((! tc->isBeingDragged)
  43977. || tc->getEditingMode() == ToolbarItemComponent::editableOnPalette));
  43978. }
  43979. }
  43980. }
  43981. }
  43982. void Toolbar::buttonClicked (Button*)
  43983. {
  43984. jassert (missingItemsButton->isShowing());
  43985. if (missingItemsButton->isShowing())
  43986. {
  43987. PopupMenu m;
  43988. m.addCustomItem (1, new MissingItemsComponent (*this, getThickness()));
  43989. m.showAt (missingItemsButton);
  43990. }
  43991. }
  43992. bool Toolbar::isInterestedInDragSource (const String& sourceDescription,
  43993. Component* /*sourceComponent*/)
  43994. {
  43995. return sourceDescription == toolbarDragDescriptor && isEditingActive;
  43996. }
  43997. void Toolbar::itemDragMove (const String&, Component* sourceComponent, int x, int y)
  43998. {
  43999. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (sourceComponent);
  44000. if (tc != 0)
  44001. {
  44002. if (getNumItems() == 0)
  44003. {
  44004. if (tc->getEditingMode() == ToolbarItemComponent::editableOnPalette)
  44005. {
  44006. ToolbarItemPalette* const palette = tc->findParentComponentOfClass ((ToolbarItemPalette*) 0);
  44007. if (palette != 0)
  44008. palette->replaceComponent (tc);
  44009. }
  44010. else
  44011. {
  44012. jassert (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar);
  44013. }
  44014. items.add (tc);
  44015. addChildComponent (tc);
  44016. updateAllItemPositions (false);
  44017. }
  44018. else
  44019. {
  44020. for (int i = getNumItems(); --i >= 0;)
  44021. {
  44022. int currentIndex = getIndexOfChildComponent (tc);
  44023. if (currentIndex < 0)
  44024. {
  44025. if (tc->getEditingMode() == ToolbarItemComponent::editableOnPalette)
  44026. {
  44027. ToolbarItemPalette* const palette = tc->findParentComponentOfClass ((ToolbarItemPalette*) 0);
  44028. if (palette != 0)
  44029. palette->replaceComponent (tc);
  44030. }
  44031. else
  44032. {
  44033. jassert (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar);
  44034. }
  44035. items.add (tc);
  44036. addChildComponent (tc);
  44037. currentIndex = getIndexOfChildComponent (tc);
  44038. updateAllItemPositions (true);
  44039. }
  44040. int newIndex = currentIndex;
  44041. const int dragObjectLeft = vertical ? (y - tc->dragOffsetY) : (x - tc->dragOffsetX);
  44042. const int dragObjectRight = dragObjectLeft + (vertical ? tc->getHeight() : tc->getWidth());
  44043. const Rectangle<int> current (animator.getComponentDestination (getChildComponent (newIndex)));
  44044. ToolbarItemComponent* const prev = getNextActiveComponent (newIndex, -1);
  44045. if (prev != 0)
  44046. {
  44047. const Rectangle<int> previousPos (animator.getComponentDestination (prev));
  44048. if (abs (dragObjectLeft - (vertical ? previousPos.getY() : previousPos.getX())
  44049. < abs (dragObjectRight - (vertical ? current.getBottom() : current.getRight()))))
  44050. {
  44051. newIndex = getIndexOfChildComponent (prev);
  44052. }
  44053. }
  44054. ToolbarItemComponent* const next = getNextActiveComponent (newIndex, 1);
  44055. if (next != 0)
  44056. {
  44057. const Rectangle<int> nextPos (animator.getComponentDestination (next));
  44058. if (abs (dragObjectLeft - (vertical ? current.getY() : current.getX())
  44059. > abs (dragObjectRight - (vertical ? nextPos.getBottom() : nextPos.getRight()))))
  44060. {
  44061. newIndex = getIndexOfChildComponent (next) + 1;
  44062. }
  44063. }
  44064. if (newIndex != currentIndex)
  44065. {
  44066. items.removeValue (tc);
  44067. removeChildComponent (tc);
  44068. addChildComponent (tc, newIndex);
  44069. items.insert (newIndex, tc);
  44070. updateAllItemPositions (true);
  44071. }
  44072. else
  44073. {
  44074. break;
  44075. }
  44076. }
  44077. }
  44078. }
  44079. }
  44080. void Toolbar::itemDragExit (const String&, Component* sourceComponent)
  44081. {
  44082. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (sourceComponent);
  44083. if (tc != 0)
  44084. {
  44085. if (isParentOf (tc))
  44086. {
  44087. items.removeValue (tc);
  44088. removeChildComponent (tc);
  44089. updateAllItemPositions (true);
  44090. }
  44091. }
  44092. }
  44093. void Toolbar::itemDropped (const String&, Component*, int, int)
  44094. {
  44095. }
  44096. void Toolbar::mouseDown (const MouseEvent& e)
  44097. {
  44098. if (e.mods.isPopupMenu())
  44099. {
  44100. }
  44101. }
  44102. class ToolbarCustomisationDialog : public DialogWindow
  44103. {
  44104. public:
  44105. ToolbarCustomisationDialog (ToolbarItemFactory& factory,
  44106. Toolbar* const toolbar_,
  44107. const int optionFlags)
  44108. : DialogWindow (TRANS("Add/remove items from toolbar"), Colours::white, true, true),
  44109. toolbar (toolbar_)
  44110. {
  44111. setContentComponent (new CustomiserPanel (factory, toolbar, optionFlags), true, true);
  44112. setResizable (true, true);
  44113. setResizeLimits (400, 300, 1500, 1000);
  44114. positionNearBar();
  44115. }
  44116. ~ToolbarCustomisationDialog()
  44117. {
  44118. setContentComponent (0, true);
  44119. }
  44120. void closeButtonPressed()
  44121. {
  44122. setVisible (false);
  44123. }
  44124. bool canModalEventBeSentToComponent (const Component* comp)
  44125. {
  44126. return toolbar->isParentOf (comp);
  44127. }
  44128. void positionNearBar()
  44129. {
  44130. const Rectangle<int> screenSize (toolbar->getParentMonitorArea());
  44131. const int tbx = toolbar->getScreenX();
  44132. const int tby = toolbar->getScreenY();
  44133. const int gap = 8;
  44134. int x, y;
  44135. if (toolbar->isVertical())
  44136. {
  44137. y = tby;
  44138. if (tbx > screenSize.getCentreX())
  44139. x = tbx - getWidth() - gap;
  44140. else
  44141. x = tbx + toolbar->getWidth() + gap;
  44142. }
  44143. else
  44144. {
  44145. x = tbx + (toolbar->getWidth() - getWidth()) / 2;
  44146. if (tby > screenSize.getCentreY())
  44147. y = tby - getHeight() - gap;
  44148. else
  44149. y = tby + toolbar->getHeight() + gap;
  44150. }
  44151. setTopLeftPosition (x, y);
  44152. }
  44153. private:
  44154. Toolbar* const toolbar;
  44155. class CustomiserPanel : public Component,
  44156. private ComboBoxListener,
  44157. private ButtonListener
  44158. {
  44159. public:
  44160. CustomiserPanel (ToolbarItemFactory& factory_,
  44161. Toolbar* const toolbar_,
  44162. const int optionFlags)
  44163. : factory (factory_),
  44164. toolbar (toolbar_),
  44165. styleBox (0),
  44166. defaultButton (0)
  44167. {
  44168. addAndMakeVisible (palette = new ToolbarItemPalette (factory, toolbar));
  44169. if ((optionFlags & (Toolbar::allowIconsOnlyChoice
  44170. | Toolbar::allowIconsWithTextChoice
  44171. | Toolbar::allowTextOnlyChoice)) != 0)
  44172. {
  44173. addAndMakeVisible (styleBox = new ComboBox (String::empty));
  44174. styleBox->setEditableText (false);
  44175. if ((optionFlags & Toolbar::allowIconsOnlyChoice) != 0)
  44176. styleBox->addItem (TRANS("Show icons only"), 1);
  44177. if ((optionFlags & Toolbar::allowIconsWithTextChoice) != 0)
  44178. styleBox->addItem (TRANS("Show icons and descriptions"), 2);
  44179. if ((optionFlags & Toolbar::allowTextOnlyChoice) != 0)
  44180. styleBox->addItem (TRANS("Show descriptions only"), 3);
  44181. if (toolbar_->getStyle() == Toolbar::iconsOnly)
  44182. styleBox->setSelectedId (1);
  44183. else if (toolbar_->getStyle() == Toolbar::iconsWithText)
  44184. styleBox->setSelectedId (2);
  44185. else if (toolbar_->getStyle() == Toolbar::textOnly)
  44186. styleBox->setSelectedId (3);
  44187. styleBox->addListener (this);
  44188. }
  44189. if ((optionFlags & Toolbar::showResetToDefaultsButton) != 0)
  44190. {
  44191. addAndMakeVisible (defaultButton = new TextButton (TRANS ("Restore to default set of items")));
  44192. defaultButton->addButtonListener (this);
  44193. }
  44194. addAndMakeVisible (instructions = new Label (String::empty,
  44195. 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.")));
  44196. instructions->setFont (Font (13.0f));
  44197. setSize (500, 300);
  44198. }
  44199. ~CustomiserPanel()
  44200. {
  44201. deleteAllChildren();
  44202. }
  44203. void comboBoxChanged (ComboBox*)
  44204. {
  44205. if (styleBox->getSelectedId() == 1)
  44206. toolbar->setStyle (Toolbar::iconsOnly);
  44207. else if (styleBox->getSelectedId() == 2)
  44208. toolbar->setStyle (Toolbar::iconsWithText);
  44209. else if (styleBox->getSelectedId() == 3)
  44210. toolbar->setStyle (Toolbar::textOnly);
  44211. palette->resized(); // to make it update the styles
  44212. }
  44213. void buttonClicked (Button*)
  44214. {
  44215. toolbar->addDefaultItems (factory);
  44216. }
  44217. void paint (Graphics& g)
  44218. {
  44219. Colour background;
  44220. DialogWindow* const dw = findParentComponentOfClass ((DialogWindow*) 0);
  44221. if (dw != 0)
  44222. background = dw->getBackgroundColour();
  44223. g.setColour (background.contrasting().withAlpha (0.3f));
  44224. g.fillRect (palette->getX(), palette->getBottom() - 1, palette->getWidth(), 1);
  44225. }
  44226. void resized()
  44227. {
  44228. palette->setBounds (0, 0, getWidth(), getHeight() - 120);
  44229. if (styleBox != 0)
  44230. styleBox->setBounds (10, getHeight() - 110, 200, 22);
  44231. if (defaultButton != 0)
  44232. {
  44233. defaultButton->changeWidthToFitText (22);
  44234. defaultButton->setTopLeftPosition (240, getHeight() - 110);
  44235. }
  44236. instructions->setBounds (10, getHeight() - 80, getWidth() - 20, 80);
  44237. }
  44238. private:
  44239. ToolbarItemFactory& factory;
  44240. Toolbar* const toolbar;
  44241. Label* instructions;
  44242. ToolbarItemPalette* palette;
  44243. ComboBox* styleBox;
  44244. TextButton* defaultButton;
  44245. };
  44246. };
  44247. void Toolbar::showCustomisationDialog (ToolbarItemFactory& factory, const int optionFlags)
  44248. {
  44249. setEditingActive (true);
  44250. ToolbarCustomisationDialog dw (factory, this, optionFlags);
  44251. dw.runModalLoop();
  44252. jassert (isValidComponent()); // ? deleting the toolbar while it's being edited?
  44253. setEditingActive (false);
  44254. }
  44255. END_JUCE_NAMESPACE
  44256. /*** End of inlined file: juce_Toolbar.cpp ***/
  44257. /*** Start of inlined file: juce_ToolbarItemComponent.cpp ***/
  44258. BEGIN_JUCE_NAMESPACE
  44259. ToolbarItemFactory::ToolbarItemFactory()
  44260. {
  44261. }
  44262. ToolbarItemFactory::~ToolbarItemFactory()
  44263. {
  44264. }
  44265. class ItemDragAndDropOverlayComponent : public Component
  44266. {
  44267. public:
  44268. ItemDragAndDropOverlayComponent()
  44269. : isDragging (false)
  44270. {
  44271. setAlwaysOnTop (true);
  44272. setRepaintsOnMouseActivity (true);
  44273. setMouseCursor (MouseCursor::DraggingHandCursor);
  44274. }
  44275. ~ItemDragAndDropOverlayComponent()
  44276. {
  44277. }
  44278. void paint (Graphics& g)
  44279. {
  44280. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getParentComponent());
  44281. if (isMouseOverOrDragging()
  44282. && tc != 0
  44283. && tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar)
  44284. {
  44285. g.setColour (findColour (Toolbar::editingModeOutlineColourId, true));
  44286. g.drawRect (0, 0, getWidth(), getHeight(),
  44287. jmin (2, (getWidth() - 1) / 2, (getHeight() - 1) / 2));
  44288. }
  44289. }
  44290. void mouseDown (const MouseEvent& e)
  44291. {
  44292. isDragging = false;
  44293. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getParentComponent());
  44294. if (tc != 0)
  44295. {
  44296. tc->dragOffsetX = e.x;
  44297. tc->dragOffsetY = e.y;
  44298. }
  44299. }
  44300. void mouseDrag (const MouseEvent& e)
  44301. {
  44302. if (! (isDragging || e.mouseWasClicked()))
  44303. {
  44304. isDragging = true;
  44305. DragAndDropContainer* const dnd = DragAndDropContainer::findParentDragContainerFor (this);
  44306. if (dnd != 0)
  44307. {
  44308. dnd->startDragging (Toolbar::toolbarDragDescriptor, getParentComponent(), 0, true);
  44309. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getParentComponent());
  44310. if (tc != 0)
  44311. {
  44312. tc->isBeingDragged = true;
  44313. if (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar)
  44314. tc->setVisible (false);
  44315. }
  44316. }
  44317. }
  44318. }
  44319. void mouseUp (const MouseEvent&)
  44320. {
  44321. isDragging = false;
  44322. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getParentComponent());
  44323. if (tc != 0)
  44324. {
  44325. tc->isBeingDragged = false;
  44326. Toolbar* const tb = tc->getToolbar();
  44327. if (tb != 0)
  44328. tb->updateAllItemPositions (true);
  44329. else if (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar)
  44330. delete tc;
  44331. }
  44332. }
  44333. void parentSizeChanged()
  44334. {
  44335. setBounds (0, 0, getParentWidth(), getParentHeight());
  44336. }
  44337. juce_UseDebuggingNewOperator
  44338. private:
  44339. bool isDragging;
  44340. ItemDragAndDropOverlayComponent (const ItemDragAndDropOverlayComponent&);
  44341. const ItemDragAndDropOverlayComponent& operator= (const ItemDragAndDropOverlayComponent&);
  44342. };
  44343. ToolbarItemComponent::ToolbarItemComponent (const int itemId_,
  44344. const String& labelText,
  44345. const bool isBeingUsedAsAButton_)
  44346. : Button (labelText),
  44347. itemId (itemId_),
  44348. mode (normalMode),
  44349. toolbarStyle (Toolbar::iconsOnly),
  44350. dragOffsetX (0),
  44351. dragOffsetY (0),
  44352. isActive (true),
  44353. isBeingDragged (false),
  44354. isBeingUsedAsAButton (isBeingUsedAsAButton_)
  44355. {
  44356. // Your item ID can't be 0!
  44357. jassert (itemId_ != 0);
  44358. }
  44359. ToolbarItemComponent::~ToolbarItemComponent()
  44360. {
  44361. jassert (overlayComp == 0 || overlayComp->isValidComponent());
  44362. overlayComp = 0;
  44363. }
  44364. Toolbar* ToolbarItemComponent::getToolbar() const
  44365. {
  44366. return dynamic_cast <Toolbar*> (getParentComponent());
  44367. }
  44368. bool ToolbarItemComponent::isToolbarVertical() const
  44369. {
  44370. const Toolbar* const t = getToolbar();
  44371. return t != 0 && t->isVertical();
  44372. }
  44373. void ToolbarItemComponent::setStyle (const Toolbar::ToolbarItemStyle& newStyle)
  44374. {
  44375. if (toolbarStyle != newStyle)
  44376. {
  44377. toolbarStyle = newStyle;
  44378. repaint();
  44379. resized();
  44380. }
  44381. }
  44382. void ToolbarItemComponent::paintButton (Graphics& g, bool isMouseOver, bool isMouseDown)
  44383. {
  44384. if (isBeingUsedAsAButton)
  44385. getLookAndFeel().paintToolbarButtonBackground (g, getWidth(), getHeight(),
  44386. isMouseOver, isMouseDown, *this);
  44387. if (toolbarStyle != Toolbar::iconsOnly)
  44388. {
  44389. const int indent = contentArea.getX();
  44390. int y = indent;
  44391. int h = getHeight() - indent * 2;
  44392. if (toolbarStyle == Toolbar::iconsWithText)
  44393. {
  44394. y = contentArea.getBottom() + indent / 2;
  44395. h -= contentArea.getHeight();
  44396. }
  44397. getLookAndFeel().paintToolbarButtonLabel (g, indent, y, getWidth() - indent * 2, h,
  44398. getButtonText(), *this);
  44399. }
  44400. if (! contentArea.isEmpty())
  44401. {
  44402. g.saveState();
  44403. g.setOrigin (contentArea.getX(), contentArea.getY());
  44404. g.reduceClipRegion (0, 0, contentArea.getWidth(), contentArea.getHeight());
  44405. paintButtonArea (g, contentArea.getWidth(), contentArea.getHeight(), isMouseOver, isMouseDown);
  44406. g.restoreState();
  44407. }
  44408. }
  44409. void ToolbarItemComponent::resized()
  44410. {
  44411. if (toolbarStyle != Toolbar::textOnly)
  44412. {
  44413. const int indent = jmin (proportionOfWidth (0.08f),
  44414. proportionOfHeight (0.08f));
  44415. contentArea = Rectangle<int> (indent, indent,
  44416. getWidth() - indent * 2,
  44417. toolbarStyle == Toolbar::iconsWithText ? proportionOfHeight (0.55f)
  44418. : (getHeight() - indent * 2));
  44419. }
  44420. else
  44421. {
  44422. contentArea = Rectangle<int>();
  44423. }
  44424. contentAreaChanged (contentArea);
  44425. }
  44426. void ToolbarItemComponent::setEditingMode (const ToolbarEditingMode newMode)
  44427. {
  44428. if (mode != newMode)
  44429. {
  44430. mode = newMode;
  44431. repaint();
  44432. if (mode == normalMode)
  44433. {
  44434. jassert (overlayComp == 0 || overlayComp->isValidComponent());
  44435. overlayComp = 0;
  44436. }
  44437. else if (overlayComp == 0)
  44438. {
  44439. addAndMakeVisible (overlayComp = new ItemDragAndDropOverlayComponent());
  44440. overlayComp->parentSizeChanged();
  44441. }
  44442. resized();
  44443. }
  44444. }
  44445. END_JUCE_NAMESPACE
  44446. /*** End of inlined file: juce_ToolbarItemComponent.cpp ***/
  44447. /*** Start of inlined file: juce_ToolbarItemPalette.cpp ***/
  44448. BEGIN_JUCE_NAMESPACE
  44449. ToolbarItemPalette::ToolbarItemPalette (ToolbarItemFactory& factory_,
  44450. Toolbar* const toolbar_)
  44451. : factory (factory_),
  44452. toolbar (toolbar_)
  44453. {
  44454. Component* const itemHolder = new Component();
  44455. Array <int> allIds;
  44456. factory_.getAllToolbarItemIds (allIds);
  44457. for (int i = 0; i < allIds.size(); ++i)
  44458. {
  44459. ToolbarItemComponent* const tc = Toolbar::createItem (factory_, allIds.getUnchecked (i));
  44460. jassert (tc != 0);
  44461. if (tc != 0)
  44462. {
  44463. itemHolder->addAndMakeVisible (tc);
  44464. tc->setEditingMode (ToolbarItemComponent::editableOnPalette);
  44465. }
  44466. }
  44467. viewport = new Viewport();
  44468. viewport->setViewedComponent (itemHolder);
  44469. addAndMakeVisible (viewport);
  44470. }
  44471. ToolbarItemPalette::~ToolbarItemPalette()
  44472. {
  44473. viewport->getViewedComponent()->deleteAllChildren();
  44474. deleteAllChildren();
  44475. }
  44476. void ToolbarItemPalette::resized()
  44477. {
  44478. viewport->setBoundsInset (BorderSize (1));
  44479. Component* const itemHolder = viewport->getViewedComponent();
  44480. const int indent = 8;
  44481. const int preferredWidth = viewport->getWidth() - viewport->getScrollBarThickness() - indent;
  44482. const int height = toolbar->getThickness();
  44483. int x = indent;
  44484. int y = indent;
  44485. int maxX = 0;
  44486. for (int i = 0; i < itemHolder->getNumChildComponents(); ++i)
  44487. {
  44488. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (itemHolder->getChildComponent (i));
  44489. if (tc != 0)
  44490. {
  44491. tc->setStyle (toolbar->getStyle());
  44492. int preferredSize = 1, minSize = 1, maxSize = 1;
  44493. if (tc->getToolbarItemSizes (height, false, preferredSize, minSize, maxSize))
  44494. {
  44495. if (x + preferredSize > preferredWidth && x > indent)
  44496. {
  44497. x = indent;
  44498. y += height;
  44499. }
  44500. tc->setBounds (x, y, preferredSize, height);
  44501. x += preferredSize + 8;
  44502. maxX = jmax (maxX, x);
  44503. }
  44504. }
  44505. }
  44506. itemHolder->setSize (maxX, y + height + 8);
  44507. }
  44508. void ToolbarItemPalette::replaceComponent (ToolbarItemComponent* const comp)
  44509. {
  44510. ToolbarItemComponent* const tc = Toolbar::createItem (factory, comp->getItemId());
  44511. jassert (tc != 0);
  44512. if (tc != 0)
  44513. {
  44514. tc->setBounds (comp->getBounds());
  44515. tc->setStyle (toolbar->getStyle());
  44516. tc->setEditingMode (comp->getEditingMode());
  44517. viewport->getViewedComponent()->addAndMakeVisible (tc, getIndexOfChildComponent (comp));
  44518. }
  44519. }
  44520. END_JUCE_NAMESPACE
  44521. /*** End of inlined file: juce_ToolbarItemPalette.cpp ***/
  44522. /*** Start of inlined file: juce_TreeView.cpp ***/
  44523. BEGIN_JUCE_NAMESPACE
  44524. class TreeViewContentComponent : public Component,
  44525. public TooltipClient
  44526. {
  44527. public:
  44528. TreeViewContentComponent (TreeView* const owner_)
  44529. : owner (owner_),
  44530. buttonUnderMouse (0),
  44531. isDragging (false)
  44532. {
  44533. }
  44534. ~TreeViewContentComponent()
  44535. {
  44536. deleteAllChildren();
  44537. }
  44538. void mouseDown (const MouseEvent& e)
  44539. {
  44540. updateButtonUnderMouse (e);
  44541. isDragging = false;
  44542. needSelectionOnMouseUp = false;
  44543. Rectangle<int> pos;
  44544. TreeViewItem* const item = findItemAt (e.y, pos);
  44545. if (item == 0)
  44546. return;
  44547. // (if the open/close buttons are hidden, we'll treat clicks to the left of the item
  44548. // as selection clicks)
  44549. if (e.x < pos.getX() && owner->openCloseButtonsVisible)
  44550. {
  44551. if (e.x >= pos.getX() - owner->getIndentSize())
  44552. item->setOpen (! item->isOpen());
  44553. // (clicks to the left of an open/close button are ignored)
  44554. }
  44555. else
  44556. {
  44557. // mouse-down inside the body of the item..
  44558. if (! owner->isMultiSelectEnabled())
  44559. item->setSelected (true, true);
  44560. else if (item->isSelected())
  44561. needSelectionOnMouseUp = ! e.mods.isPopupMenu();
  44562. else
  44563. selectBasedOnModifiers (item, e.mods);
  44564. MouseEvent e2 (e);
  44565. e2.x -= pos.getX();
  44566. e2.y -= pos.getY();
  44567. if (e2.x >= 0)
  44568. item->itemClicked (e2);
  44569. }
  44570. }
  44571. void mouseUp (const MouseEvent& e)
  44572. {
  44573. updateButtonUnderMouse (e);
  44574. if (needSelectionOnMouseUp && e.mouseWasClicked())
  44575. {
  44576. Rectangle<int> pos;
  44577. TreeViewItem* const item = findItemAt (e.y, pos);
  44578. if (item != 0)
  44579. selectBasedOnModifiers (item, e.mods);
  44580. }
  44581. }
  44582. void mouseDoubleClick (const MouseEvent& e)
  44583. {
  44584. if (e.getNumberOfClicks() != 3) // ignore triple clicks
  44585. {
  44586. Rectangle<int> pos;
  44587. TreeViewItem* const item = findItemAt (e.y, pos);
  44588. if (item != 0 && (e.x >= pos.getX() || ! owner->openCloseButtonsVisible))
  44589. {
  44590. MouseEvent e2 (e);
  44591. e2.x -= pos.getX();
  44592. e2.y -= pos.getY();
  44593. item->itemDoubleClicked (e2);
  44594. }
  44595. }
  44596. }
  44597. void mouseDrag (const MouseEvent& e)
  44598. {
  44599. if (isEnabled()
  44600. && ! (isDragging || e.mouseWasClicked()
  44601. || e.getDistanceFromDragStart() < 5
  44602. || e.mods.isPopupMenu()))
  44603. {
  44604. isDragging = true;
  44605. Rectangle<int> pos;
  44606. TreeViewItem* const item = findItemAt (e.getMouseDownY(), pos);
  44607. if (item != 0 && e.getMouseDownX() >= pos.getX())
  44608. {
  44609. const String dragDescription (item->getDragSourceDescription());
  44610. if (dragDescription.isNotEmpty())
  44611. {
  44612. DragAndDropContainer* const dragContainer
  44613. = DragAndDropContainer::findParentDragContainerFor (this);
  44614. if (dragContainer != 0)
  44615. {
  44616. pos.setSize (pos.getWidth(), item->itemHeight);
  44617. Image* dragImage = Component::createComponentSnapshot (pos, true);
  44618. dragImage->multiplyAllAlphas (0.6f);
  44619. Point<int> imageOffset (pos.getX() - e.x, pos.getY() - e.y);
  44620. dragContainer->startDragging (dragDescription, owner, dragImage, true, &imageOffset);
  44621. }
  44622. else
  44623. {
  44624. // to be able to do a drag-and-drop operation, the treeview needs to
  44625. // be inside a component which is also a DragAndDropContainer.
  44626. jassertfalse
  44627. }
  44628. }
  44629. }
  44630. }
  44631. }
  44632. void mouseMove (const MouseEvent& e)
  44633. {
  44634. updateButtonUnderMouse (e);
  44635. }
  44636. void mouseExit (const MouseEvent& e)
  44637. {
  44638. updateButtonUnderMouse (e);
  44639. }
  44640. void paint (Graphics& g);
  44641. TreeViewItem* findItemAt (int y, Rectangle<int>& itemPosition) const;
  44642. void updateComponents()
  44643. {
  44644. const int visibleTop = -getY();
  44645. const int visibleBottom = visibleTop + getParentHeight();
  44646. BitArray itemsToKeep;
  44647. TreeViewItem* item = owner->rootItem;
  44648. int y = (item != 0 && !owner->rootItemVisible) ? -item->itemHeight : 0;
  44649. while (item != 0 && y < visibleBottom)
  44650. {
  44651. y += item->itemHeight;
  44652. if (y >= visibleTop)
  44653. {
  44654. const int index = rowComponentIds.indexOf (item->uid);
  44655. if (index < 0)
  44656. {
  44657. Component* const comp = item->createItemComponent();
  44658. if (comp != 0)
  44659. {
  44660. addAndMakeVisible (comp);
  44661. itemsToKeep.setBit (rowComponentItems.size());
  44662. rowComponentItems.add (item);
  44663. rowComponentIds.add (item->uid);
  44664. rowComponents.add (comp);
  44665. }
  44666. }
  44667. else
  44668. {
  44669. itemsToKeep.setBit (index);
  44670. }
  44671. }
  44672. item = item->getNextVisibleItem (true);
  44673. }
  44674. for (int i = rowComponentItems.size(); --i >= 0;)
  44675. {
  44676. Component* const comp = (Component*) rowComponents.getUnchecked(i);
  44677. bool keep = false;
  44678. if (isParentOf (comp))
  44679. {
  44680. if (itemsToKeep[i])
  44681. {
  44682. const TreeViewItem* const item = (TreeViewItem*) rowComponentItems.getUnchecked(i);
  44683. Rectangle<int> pos (item->getItemPosition (false));
  44684. pos.setSize (pos.getWidth(), item->itemHeight);
  44685. if (pos.getBottom() >= visibleTop && pos.getY() < visibleBottom)
  44686. {
  44687. keep = true;
  44688. comp->setBounds (pos);
  44689. }
  44690. }
  44691. if ((! keep)
  44692. && Component::isMouseButtonDownAnywhere()
  44693. && (comp == Component::getComponentUnderMouse()
  44694. || comp->isParentOf (Component::getComponentUnderMouse())))
  44695. {
  44696. keep = true;
  44697. comp->setSize (0, 0);
  44698. }
  44699. }
  44700. if (! keep)
  44701. {
  44702. delete comp;
  44703. rowComponents.remove (i);
  44704. rowComponentIds.remove (i);
  44705. rowComponentItems.remove (i);
  44706. }
  44707. }
  44708. }
  44709. void updateButtonUnderMouse (const MouseEvent& e)
  44710. {
  44711. TreeViewItem* newItem = 0;
  44712. if (owner->openCloseButtonsVisible)
  44713. {
  44714. Rectangle<int> pos;
  44715. TreeViewItem* item = findItemAt (e.y, pos);
  44716. if (item != 0 && e.x < pos.getX() && e.x >= pos.getX() - owner->getIndentSize())
  44717. {
  44718. newItem = item;
  44719. if (! newItem->mightContainSubItems())
  44720. newItem = 0;
  44721. }
  44722. }
  44723. if (buttonUnderMouse != newItem)
  44724. {
  44725. if (buttonUnderMouse != 0 && containsItem (buttonUnderMouse))
  44726. {
  44727. const Rectangle<int> r (buttonUnderMouse->getItemPosition (false));
  44728. repaint (0, r.getY(), r.getX(), buttonUnderMouse->getItemHeight());
  44729. }
  44730. buttonUnderMouse = newItem;
  44731. if (buttonUnderMouse != 0)
  44732. {
  44733. const Rectangle<int> r (buttonUnderMouse->getItemPosition (false));
  44734. repaint (0, r.getY(), r.getX(), buttonUnderMouse->getItemHeight());
  44735. }
  44736. }
  44737. }
  44738. bool isMouseOverButton (TreeViewItem* item) const throw()
  44739. {
  44740. return item == buttonUnderMouse;
  44741. }
  44742. void resized()
  44743. {
  44744. owner->itemsChanged();
  44745. }
  44746. const String getTooltip()
  44747. {
  44748. int x, y;
  44749. getMouseXYRelative (x, y);
  44750. Rectangle<int> pos;
  44751. TreeViewItem* const item = findItemAt (y, pos);
  44752. if (item != 0)
  44753. return item->getTooltip();
  44754. return owner->getTooltip();
  44755. }
  44756. juce_UseDebuggingNewOperator
  44757. private:
  44758. TreeView* const owner;
  44759. VoidArray rowComponentItems;
  44760. Array <int> rowComponentIds;
  44761. VoidArray rowComponents;
  44762. TreeViewItem* buttonUnderMouse;
  44763. bool isDragging, needSelectionOnMouseUp;
  44764. TreeViewContentComponent (const TreeViewContentComponent&);
  44765. const TreeViewContentComponent& operator= (const TreeViewContentComponent&);
  44766. void selectBasedOnModifiers (TreeViewItem* const item, const ModifierKeys& modifiers)
  44767. {
  44768. TreeViewItem* firstSelected = 0;
  44769. if (modifiers.isShiftDown() && ((firstSelected = owner->getSelectedItem (0)) != 0))
  44770. {
  44771. TreeViewItem* const lastSelected = owner->getSelectedItem (owner->getNumSelectedItems() - 1);
  44772. jassert (lastSelected != 0);
  44773. int rowStart = firstSelected->getRowNumberInTree();
  44774. int rowEnd = lastSelected->getRowNumberInTree();
  44775. if (rowStart > rowEnd)
  44776. swapVariables (rowStart, rowEnd);
  44777. int ourRow = item->getRowNumberInTree();
  44778. int otherEnd = ourRow < rowEnd ? rowStart : rowEnd;
  44779. if (ourRow > otherEnd)
  44780. swapVariables (ourRow, otherEnd);
  44781. for (int i = ourRow; i <= otherEnd; ++i)
  44782. owner->getItemOnRow (i)->setSelected (true, false);
  44783. }
  44784. else
  44785. {
  44786. const bool cmd = modifiers.isCommandDown();
  44787. item->setSelected ((! cmd) || (! item->isSelected()), ! cmd);
  44788. }
  44789. }
  44790. bool containsItem (TreeViewItem* const item) const
  44791. {
  44792. for (int i = rowComponentItems.size(); --i >= 0;)
  44793. if ((TreeViewItem*) rowComponentItems.getUnchecked (i) == item)
  44794. return true;
  44795. return false;
  44796. }
  44797. };
  44798. class TreeViewport : public Viewport
  44799. {
  44800. public:
  44801. TreeViewport() throw() {}
  44802. ~TreeViewport() throw() {}
  44803. void updateComponents()
  44804. {
  44805. if (getViewedComponent() != 0)
  44806. ((TreeViewContentComponent*) getViewedComponent())->updateComponents();
  44807. repaint();
  44808. }
  44809. void visibleAreaChanged (int, int, int, int)
  44810. {
  44811. updateComponents();
  44812. }
  44813. juce_UseDebuggingNewOperator
  44814. private:
  44815. TreeViewport (const TreeViewport&);
  44816. const TreeViewport& operator= (const TreeViewport&);
  44817. };
  44818. TreeView::TreeView (const String& componentName)
  44819. : Component (componentName),
  44820. rootItem (0),
  44821. dragInsertPointHighlight (0),
  44822. dragTargetGroupHighlight (0),
  44823. indentSize (24),
  44824. defaultOpenness (false),
  44825. needsRecalculating (true),
  44826. rootItemVisible (true),
  44827. multiSelectEnabled (false),
  44828. openCloseButtonsVisible (true)
  44829. {
  44830. addAndMakeVisible (viewport = new TreeViewport());
  44831. viewport->setViewedComponent (new TreeViewContentComponent (this));
  44832. viewport->setWantsKeyboardFocus (false);
  44833. setWantsKeyboardFocus (true);
  44834. }
  44835. TreeView::~TreeView()
  44836. {
  44837. if (rootItem != 0)
  44838. rootItem->setOwnerView (0);
  44839. deleteAllChildren();
  44840. }
  44841. void TreeView::setRootItem (TreeViewItem* const newRootItem)
  44842. {
  44843. if (rootItem != newRootItem)
  44844. {
  44845. if (newRootItem != 0)
  44846. {
  44847. jassert (newRootItem->ownerView == 0); // can't use a tree item in more than one tree at once..
  44848. if (newRootItem->ownerView != 0)
  44849. newRootItem->ownerView->setRootItem (0);
  44850. }
  44851. if (rootItem != 0)
  44852. rootItem->setOwnerView (0);
  44853. rootItem = newRootItem;
  44854. if (newRootItem != 0)
  44855. newRootItem->setOwnerView (this);
  44856. needsRecalculating = true;
  44857. handleAsyncUpdate();
  44858. if (rootItem != 0 && (defaultOpenness || ! rootItemVisible))
  44859. {
  44860. rootItem->setOpen (false); // force a re-open
  44861. rootItem->setOpen (true);
  44862. }
  44863. }
  44864. }
  44865. void TreeView::deleteRootItem()
  44866. {
  44867. const ScopedPointer <TreeViewItem> deleter (rootItem);
  44868. setRootItem (0);
  44869. }
  44870. void TreeView::setRootItemVisible (const bool shouldBeVisible)
  44871. {
  44872. rootItemVisible = shouldBeVisible;
  44873. if (rootItem != 0 && (defaultOpenness || ! rootItemVisible))
  44874. {
  44875. rootItem->setOpen (false); // force a re-open
  44876. rootItem->setOpen (true);
  44877. }
  44878. itemsChanged();
  44879. }
  44880. void TreeView::colourChanged()
  44881. {
  44882. setOpaque (findColour (backgroundColourId).isOpaque());
  44883. repaint();
  44884. }
  44885. void TreeView::setIndentSize (const int newIndentSize)
  44886. {
  44887. if (indentSize != newIndentSize)
  44888. {
  44889. indentSize = newIndentSize;
  44890. resized();
  44891. }
  44892. }
  44893. void TreeView::setDefaultOpenness (const bool isOpenByDefault)
  44894. {
  44895. if (defaultOpenness != isOpenByDefault)
  44896. {
  44897. defaultOpenness = isOpenByDefault;
  44898. itemsChanged();
  44899. }
  44900. }
  44901. void TreeView::setMultiSelectEnabled (const bool canMultiSelect)
  44902. {
  44903. multiSelectEnabled = canMultiSelect;
  44904. }
  44905. void TreeView::setOpenCloseButtonsVisible (const bool shouldBeVisible)
  44906. {
  44907. if (openCloseButtonsVisible != shouldBeVisible)
  44908. {
  44909. openCloseButtonsVisible = shouldBeVisible;
  44910. itemsChanged();
  44911. }
  44912. }
  44913. void TreeView::clearSelectedItems()
  44914. {
  44915. if (rootItem != 0)
  44916. rootItem->deselectAllRecursively();
  44917. }
  44918. int TreeView::getNumSelectedItems() const throw()
  44919. {
  44920. return (rootItem != 0) ? rootItem->countSelectedItemsRecursively() : 0;
  44921. }
  44922. TreeViewItem* TreeView::getSelectedItem (const int index) const throw()
  44923. {
  44924. return (rootItem != 0) ? rootItem->getSelectedItemWithIndex (index) : 0;
  44925. }
  44926. int TreeView::getNumRowsInTree() const
  44927. {
  44928. if (rootItem != 0)
  44929. return rootItem->getNumRows() - (rootItemVisible ? 0 : 1);
  44930. return 0;
  44931. }
  44932. TreeViewItem* TreeView::getItemOnRow (int index) const
  44933. {
  44934. if (! rootItemVisible)
  44935. ++index;
  44936. if (rootItem != 0 && index >= 0)
  44937. return rootItem->getItemOnRow (index);
  44938. return 0;
  44939. }
  44940. TreeViewItem* TreeView::getItemAt (int y) const throw()
  44941. {
  44942. TreeViewContentComponent* const tc = (TreeViewContentComponent*) viewport->getViewedComponent();
  44943. int x;
  44944. relativePositionToOtherComponent (tc, x, y);
  44945. Rectangle<int> pos;
  44946. return tc->findItemAt (y, pos);
  44947. }
  44948. TreeViewItem* TreeView::findItemFromIdentifierString (const String& identifierString) const
  44949. {
  44950. if (rootItem == 0)
  44951. return 0;
  44952. return rootItem->findItemFromIdentifierString (identifierString);
  44953. }
  44954. XmlElement* TreeView::getOpennessState (const bool alsoIncludeScrollPosition) const
  44955. {
  44956. XmlElement* e = 0;
  44957. if (rootItem != 0)
  44958. {
  44959. e = rootItem->getOpennessState();
  44960. if (e != 0 && alsoIncludeScrollPosition)
  44961. e->setAttribute (T("scrollPos"), viewport->getViewPositionY());
  44962. }
  44963. return e;
  44964. }
  44965. void TreeView::restoreOpennessState (const XmlElement& newState)
  44966. {
  44967. if (rootItem != 0)
  44968. {
  44969. rootItem->restoreOpennessState (newState);
  44970. if (newState.hasAttribute (T("scrollPos")))
  44971. viewport->setViewPosition (viewport->getViewPositionX(),
  44972. newState.getIntAttribute (T("scrollPos")));
  44973. }
  44974. }
  44975. void TreeView::paint (Graphics& g)
  44976. {
  44977. g.fillAll (findColour (backgroundColourId));
  44978. }
  44979. void TreeView::resized()
  44980. {
  44981. viewport->setBounds (0, 0, getWidth(), getHeight());
  44982. itemsChanged();
  44983. handleAsyncUpdate();
  44984. }
  44985. void TreeView::enablementChanged()
  44986. {
  44987. repaint();
  44988. }
  44989. void TreeView::moveSelectedRow (int delta)
  44990. {
  44991. if (delta == 0)
  44992. return;
  44993. int rowSelected = 0;
  44994. TreeViewItem* const firstSelected = getSelectedItem (0);
  44995. if (firstSelected != 0)
  44996. rowSelected = firstSelected->getRowNumberInTree();
  44997. rowSelected = jlimit (0, getNumRowsInTree() - 1, rowSelected + delta);
  44998. for (;;)
  44999. {
  45000. TreeViewItem* item = getItemOnRow (rowSelected);
  45001. if (item != 0)
  45002. {
  45003. if (! item->canBeSelected())
  45004. {
  45005. // if the row we want to highlight doesn't allow it, try skipping
  45006. // to the next item..
  45007. const int nextRowToTry = jlimit (0, getNumRowsInTree() - 1,
  45008. rowSelected + (delta < 0 ? -1 : 1));
  45009. if (rowSelected != nextRowToTry)
  45010. {
  45011. rowSelected = nextRowToTry;
  45012. continue;
  45013. }
  45014. else
  45015. {
  45016. break;
  45017. }
  45018. }
  45019. item->setSelected (true, true);
  45020. scrollToKeepItemVisible (item);
  45021. }
  45022. break;
  45023. }
  45024. }
  45025. void TreeView::scrollToKeepItemVisible (TreeViewItem* item)
  45026. {
  45027. if (item != 0 && item->ownerView == this)
  45028. {
  45029. handleAsyncUpdate();
  45030. item = item->getDeepestOpenParentItem();
  45031. int y = item->y;
  45032. int viewTop = viewport->getViewPositionY();
  45033. if (y < viewTop)
  45034. {
  45035. viewport->setViewPosition (viewport->getViewPositionX(), y);
  45036. }
  45037. else if (y + item->itemHeight > viewTop + viewport->getViewHeight())
  45038. {
  45039. viewport->setViewPosition (viewport->getViewPositionX(),
  45040. (y + item->itemHeight) - viewport->getViewHeight());
  45041. }
  45042. }
  45043. }
  45044. bool TreeView::keyPressed (const KeyPress& key)
  45045. {
  45046. if (key.isKeyCode (KeyPress::upKey))
  45047. {
  45048. moveSelectedRow (-1);
  45049. }
  45050. else if (key.isKeyCode (KeyPress::downKey))
  45051. {
  45052. moveSelectedRow (1);
  45053. }
  45054. else if (key.isKeyCode (KeyPress::pageDownKey) || key.isKeyCode (KeyPress::pageUpKey))
  45055. {
  45056. if (rootItem != 0)
  45057. {
  45058. int rowsOnScreen = getHeight() / jmax (1, rootItem->itemHeight);
  45059. if (key.isKeyCode (KeyPress::pageUpKey))
  45060. rowsOnScreen = -rowsOnScreen;
  45061. moveSelectedRow (rowsOnScreen);
  45062. }
  45063. }
  45064. else if (key.isKeyCode (KeyPress::homeKey))
  45065. {
  45066. moveSelectedRow (-0x3fffffff);
  45067. }
  45068. else if (key.isKeyCode (KeyPress::endKey))
  45069. {
  45070. moveSelectedRow (0x3fffffff);
  45071. }
  45072. else if (key.isKeyCode (KeyPress::returnKey))
  45073. {
  45074. TreeViewItem* const firstSelected = getSelectedItem (0);
  45075. if (firstSelected != 0)
  45076. firstSelected->setOpen (! firstSelected->isOpen());
  45077. }
  45078. else if (key.isKeyCode (KeyPress::leftKey))
  45079. {
  45080. TreeViewItem* const firstSelected = getSelectedItem (0);
  45081. if (firstSelected != 0)
  45082. {
  45083. if (firstSelected->isOpen())
  45084. {
  45085. firstSelected->setOpen (false);
  45086. }
  45087. else
  45088. {
  45089. TreeViewItem* parent = firstSelected->parentItem;
  45090. if ((! rootItemVisible) && parent == rootItem)
  45091. parent = 0;
  45092. if (parent != 0)
  45093. {
  45094. parent->setSelected (true, true);
  45095. scrollToKeepItemVisible (parent);
  45096. }
  45097. }
  45098. }
  45099. }
  45100. else if (key.isKeyCode (KeyPress::rightKey))
  45101. {
  45102. TreeViewItem* const firstSelected = getSelectedItem (0);
  45103. if (firstSelected != 0)
  45104. {
  45105. if (firstSelected->isOpen() || ! firstSelected->mightContainSubItems())
  45106. moveSelectedRow (1);
  45107. else
  45108. firstSelected->setOpen (true);
  45109. }
  45110. }
  45111. else
  45112. {
  45113. return false;
  45114. }
  45115. return true;
  45116. }
  45117. void TreeView::itemsChanged() throw()
  45118. {
  45119. needsRecalculating = true;
  45120. repaint();
  45121. triggerAsyncUpdate();
  45122. }
  45123. void TreeView::handleAsyncUpdate()
  45124. {
  45125. if (needsRecalculating)
  45126. {
  45127. needsRecalculating = false;
  45128. const ScopedLock sl (nodeAlterationLock);
  45129. if (rootItem != 0)
  45130. rootItem->updatePositions (rootItemVisible ? 0 : -rootItem->itemHeight);
  45131. ((TreeViewport*) viewport)->updateComponents();
  45132. if (rootItem != 0)
  45133. {
  45134. viewport->getViewedComponent()
  45135. ->setSize (jmax (viewport->getMaximumVisibleWidth(), rootItem->totalWidth),
  45136. rootItem->totalHeight - (rootItemVisible ? 0 : rootItem->itemHeight));
  45137. }
  45138. else
  45139. {
  45140. viewport->getViewedComponent()->setSize (0, 0);
  45141. }
  45142. }
  45143. }
  45144. class TreeViewDragInsertPointHighlight : public Component
  45145. {
  45146. public:
  45147. TreeViewDragInsertPointHighlight()
  45148. : lastItem (0)
  45149. {
  45150. setSize (100, 12);
  45151. setAlwaysOnTop (true);
  45152. setInterceptsMouseClicks (false, false);
  45153. }
  45154. ~TreeViewDragInsertPointHighlight() {}
  45155. void setTargetPosition (TreeViewItem* const item, int insertIndex, const int x, const int y, const int width) throw()
  45156. {
  45157. lastItem = item;
  45158. lastIndex = insertIndex;
  45159. const int offset = getHeight() / 2;
  45160. setBounds (x - offset, y - offset, width - (x - offset), getHeight());
  45161. }
  45162. void paint (Graphics& g)
  45163. {
  45164. Path p;
  45165. const float h = (float) getHeight();
  45166. p.addEllipse (2.0f, 2.0f, h - 4.0f, h - 4.0f);
  45167. p.startNewSubPath (h - 2.0f, h / 2.0f);
  45168. p.lineTo ((float) getWidth(), h / 2.0f);
  45169. g.setColour (findColour (TreeView::dragAndDropIndicatorColourId, true));
  45170. g.strokePath (p, PathStrokeType (2.0f));
  45171. }
  45172. TreeViewItem* lastItem;
  45173. int lastIndex;
  45174. };
  45175. class TreeViewDragTargetGroupHighlight : public Component
  45176. {
  45177. public:
  45178. TreeViewDragTargetGroupHighlight()
  45179. {
  45180. setAlwaysOnTop (true);
  45181. setInterceptsMouseClicks (false, false);
  45182. }
  45183. ~TreeViewDragTargetGroupHighlight() {}
  45184. void setTargetPosition (TreeViewItem* const item) throw()
  45185. {
  45186. Rectangle<int> r (item->getItemPosition (true));
  45187. r.setHeight (item->getItemHeight());
  45188. setBounds (r);
  45189. }
  45190. void paint (Graphics& g)
  45191. {
  45192. g.setColour (findColour (TreeView::dragAndDropIndicatorColourId, true));
  45193. g.drawRoundedRectangle (1.0f, 1.0f, getWidth() - 2.0f, getHeight() - 2.0f, 3.0f, 2.0f);
  45194. }
  45195. };
  45196. void TreeView::showDragHighlight (TreeViewItem* item, int insertIndex, int x, int y) throw()
  45197. {
  45198. beginDragAutoRepeat (1000 / 30);
  45199. if (dragInsertPointHighlight == 0)
  45200. {
  45201. addAndMakeVisible (dragInsertPointHighlight = new TreeViewDragInsertPointHighlight());
  45202. addAndMakeVisible (dragTargetGroupHighlight = new TreeViewDragTargetGroupHighlight());
  45203. }
  45204. ((TreeViewDragInsertPointHighlight*) dragInsertPointHighlight)
  45205. ->setTargetPosition (item, insertIndex, x, y, viewport->getViewWidth());
  45206. ((TreeViewDragTargetGroupHighlight*) dragTargetGroupHighlight)
  45207. ->setTargetPosition (item);
  45208. }
  45209. void TreeView::hideDragHighlight() throw()
  45210. {
  45211. deleteAndZero (dragInsertPointHighlight);
  45212. deleteAndZero (dragTargetGroupHighlight);
  45213. }
  45214. TreeViewItem* TreeView::getInsertPosition (int& x, int& y, int& insertIndex,
  45215. const StringArray& files, const String& sourceDescription,
  45216. Component* sourceComponent) const throw()
  45217. {
  45218. insertIndex = 0;
  45219. TreeViewItem* item = getItemAt (y);
  45220. if (item == 0)
  45221. return 0;
  45222. Rectangle<int> itemPos (item->getItemPosition (true));
  45223. insertIndex = item->getIndexInParent();
  45224. const int oldY = y;
  45225. y = itemPos.getY();
  45226. if (item->getNumSubItems() == 0 || ! item->isOpen())
  45227. {
  45228. if (files.size() > 0 ? item->isInterestedInFileDrag (files)
  45229. : item->isInterestedInDragSource (sourceDescription, sourceComponent))
  45230. {
  45231. // Check if we're trying to drag into an empty group item..
  45232. if (oldY > itemPos.getY() + itemPos.getHeight() / 4
  45233. && oldY < itemPos.getBottom() - itemPos.getHeight() / 4)
  45234. {
  45235. insertIndex = 0;
  45236. x = itemPos.getX() + getIndentSize();
  45237. y = itemPos.getBottom();
  45238. return item;
  45239. }
  45240. }
  45241. }
  45242. if (oldY > itemPos.getCentreY())
  45243. {
  45244. y += item->getItemHeight();
  45245. while (item->isLastOfSiblings() && item->parentItem != 0
  45246. && item->parentItem->parentItem != 0)
  45247. {
  45248. if (x > itemPos.getX())
  45249. break;
  45250. item = item->parentItem;
  45251. itemPos = item->getItemPosition (true);
  45252. insertIndex = item->getIndexInParent();
  45253. }
  45254. ++insertIndex;
  45255. }
  45256. x = itemPos.getX();
  45257. return item->parentItem;
  45258. }
  45259. void TreeView::handleDrag (const StringArray& files, const String& sourceDescription, Component* sourceComponent, int x, int y)
  45260. {
  45261. const bool scrolled = viewport->autoScroll (x, y, 20, 10);
  45262. int insertIndex;
  45263. TreeViewItem* const item = getInsertPosition (x, y, insertIndex, files, sourceDescription, sourceComponent);
  45264. if (item != 0)
  45265. {
  45266. if (scrolled || dragInsertPointHighlight == 0
  45267. || ((TreeViewDragInsertPointHighlight*) dragInsertPointHighlight)->lastItem != item
  45268. || ((TreeViewDragInsertPointHighlight*) dragInsertPointHighlight)->lastIndex != insertIndex)
  45269. {
  45270. if (files.size() > 0 ? item->isInterestedInFileDrag (files)
  45271. : item->isInterestedInDragSource (sourceDescription, sourceComponent))
  45272. showDragHighlight (item, insertIndex, x, y);
  45273. else
  45274. hideDragHighlight();
  45275. }
  45276. }
  45277. else
  45278. {
  45279. hideDragHighlight();
  45280. }
  45281. }
  45282. void TreeView::handleDrop (const StringArray& files, const String& sourceDescription, Component* sourceComponent, int x, int y)
  45283. {
  45284. hideDragHighlight();
  45285. int insertIndex;
  45286. TreeViewItem* const item = getInsertPosition (x, y, insertIndex, files, sourceDescription, sourceComponent);
  45287. if (item != 0)
  45288. {
  45289. if (files.size() > 0)
  45290. {
  45291. if (item->isInterestedInFileDrag (files))
  45292. item->filesDropped (files, insertIndex);
  45293. }
  45294. else
  45295. {
  45296. if (item->isInterestedInDragSource (sourceDescription, sourceComponent))
  45297. item->itemDropped (sourceDescription, sourceComponent, insertIndex);
  45298. }
  45299. }
  45300. }
  45301. bool TreeView::isInterestedInFileDrag (const StringArray&)
  45302. {
  45303. return true;
  45304. }
  45305. void TreeView::fileDragEnter (const StringArray& files, int x, int y)
  45306. {
  45307. fileDragMove (files, x, y);
  45308. }
  45309. void TreeView::fileDragMove (const StringArray& files, int x, int y)
  45310. {
  45311. handleDrag (files, String::empty, 0, x, y);
  45312. }
  45313. void TreeView::fileDragExit (const StringArray&)
  45314. {
  45315. hideDragHighlight();
  45316. }
  45317. void TreeView::filesDropped (const StringArray& files, int x, int y)
  45318. {
  45319. handleDrop (files, String::empty, 0, x, y);
  45320. }
  45321. bool TreeView::isInterestedInDragSource (const String& /*sourceDescription*/, Component* /*sourceComponent*/)
  45322. {
  45323. return true;
  45324. }
  45325. void TreeView::itemDragEnter (const String& sourceDescription, Component* sourceComponent, int x, int y)
  45326. {
  45327. itemDragMove (sourceDescription, sourceComponent, x, y);
  45328. }
  45329. void TreeView::itemDragMove (const String& sourceDescription, Component* sourceComponent, int x, int y)
  45330. {
  45331. handleDrag (StringArray(), sourceDescription, sourceComponent, x, y);
  45332. }
  45333. void TreeView::itemDragExit (const String& /*sourceDescription*/, Component* /*sourceComponent*/)
  45334. {
  45335. hideDragHighlight();
  45336. }
  45337. void TreeView::itemDropped (const String& sourceDescription, Component* sourceComponent, int x, int y)
  45338. {
  45339. handleDrop (StringArray(), sourceDescription, sourceComponent, x, y);
  45340. }
  45341. void TreeViewContentComponent::paint (Graphics& g)
  45342. {
  45343. if (owner->rootItem != 0)
  45344. {
  45345. owner->handleAsyncUpdate();
  45346. if (! owner->rootItemVisible)
  45347. g.setOrigin (0, -owner->rootItem->itemHeight);
  45348. owner->rootItem->paintRecursively (g, getWidth());
  45349. }
  45350. }
  45351. TreeViewItem* TreeViewContentComponent::findItemAt (int y, Rectangle<int>& itemPosition) const
  45352. {
  45353. if (owner->rootItem != 0)
  45354. {
  45355. owner->handleAsyncUpdate();
  45356. if (! owner->rootItemVisible)
  45357. y += owner->rootItem->itemHeight;
  45358. TreeViewItem* const ti = owner->rootItem->findItemRecursively (y);
  45359. if (ti != 0)
  45360. itemPosition = ti->getItemPosition (false);
  45361. return ti;
  45362. }
  45363. return 0;
  45364. }
  45365. enum TreeViewOpenness
  45366. {
  45367. opennessDefault = 0,
  45368. opennessClosed = 1,
  45369. opennessOpen = 2
  45370. };
  45371. TreeViewItem::TreeViewItem()
  45372. : ownerView (0),
  45373. parentItem (0),
  45374. y (0),
  45375. itemHeight (0),
  45376. totalHeight (0),
  45377. selected (false),
  45378. redrawNeeded (true),
  45379. drawLinesInside (true),
  45380. drawsInLeftMargin (false),
  45381. openness (opennessDefault)
  45382. {
  45383. static int nextUID = 0;
  45384. uid = nextUID++;
  45385. }
  45386. TreeViewItem::~TreeViewItem()
  45387. {
  45388. }
  45389. const String TreeViewItem::getUniqueName() const
  45390. {
  45391. return String::empty;
  45392. }
  45393. void TreeViewItem::itemOpennessChanged (bool)
  45394. {
  45395. }
  45396. int TreeViewItem::getNumSubItems() const throw()
  45397. {
  45398. return subItems.size();
  45399. }
  45400. TreeViewItem* TreeViewItem::getSubItem (const int index) const throw()
  45401. {
  45402. return subItems [index];
  45403. }
  45404. void TreeViewItem::clearSubItems()
  45405. {
  45406. if (subItems.size() > 0)
  45407. {
  45408. if (ownerView != 0)
  45409. {
  45410. const ScopedLock sl (ownerView->nodeAlterationLock);
  45411. subItems.clear();
  45412. treeHasChanged();
  45413. }
  45414. else
  45415. {
  45416. subItems.clear();
  45417. }
  45418. }
  45419. }
  45420. void TreeViewItem::addSubItem (TreeViewItem* const newItem, const int insertPosition)
  45421. {
  45422. if (newItem != 0)
  45423. {
  45424. newItem->parentItem = this;
  45425. newItem->setOwnerView (ownerView);
  45426. newItem->y = 0;
  45427. newItem->itemHeight = newItem->getItemHeight();
  45428. newItem->totalHeight = 0;
  45429. newItem->itemWidth = newItem->getItemWidth();
  45430. newItem->totalWidth = 0;
  45431. if (ownerView != 0)
  45432. {
  45433. const ScopedLock sl (ownerView->nodeAlterationLock);
  45434. subItems.insert (insertPosition, newItem);
  45435. treeHasChanged();
  45436. if (newItem->isOpen())
  45437. newItem->itemOpennessChanged (true);
  45438. }
  45439. else
  45440. {
  45441. subItems.insert (insertPosition, newItem);
  45442. if (newItem->isOpen())
  45443. newItem->itemOpennessChanged (true);
  45444. }
  45445. }
  45446. }
  45447. void TreeViewItem::removeSubItem (const int index, const bool deleteItem)
  45448. {
  45449. if (ownerView != 0)
  45450. ownerView->nodeAlterationLock.enter();
  45451. if (((unsigned int) index) < (unsigned int) subItems.size())
  45452. {
  45453. subItems.remove (index, deleteItem);
  45454. treeHasChanged();
  45455. }
  45456. if (ownerView != 0)
  45457. ownerView->nodeAlterationLock.exit();
  45458. }
  45459. bool TreeViewItem::isOpen() const throw()
  45460. {
  45461. if (openness == opennessDefault)
  45462. return ownerView != 0 && ownerView->defaultOpenness;
  45463. else
  45464. return openness == opennessOpen;
  45465. }
  45466. void TreeViewItem::setOpen (const bool shouldBeOpen)
  45467. {
  45468. if (isOpen() != shouldBeOpen)
  45469. {
  45470. openness = shouldBeOpen ? opennessOpen
  45471. : opennessClosed;
  45472. treeHasChanged();
  45473. itemOpennessChanged (isOpen());
  45474. }
  45475. }
  45476. bool TreeViewItem::isSelected() const throw()
  45477. {
  45478. return selected;
  45479. }
  45480. void TreeViewItem::deselectAllRecursively()
  45481. {
  45482. setSelected (false, false);
  45483. for (int i = 0; i < subItems.size(); ++i)
  45484. subItems.getUnchecked(i)->deselectAllRecursively();
  45485. }
  45486. void TreeViewItem::setSelected (const bool shouldBeSelected,
  45487. const bool deselectOtherItemsFirst)
  45488. {
  45489. if (shouldBeSelected && ! canBeSelected())
  45490. return;
  45491. if (deselectOtherItemsFirst)
  45492. getTopLevelItem()->deselectAllRecursively();
  45493. if (shouldBeSelected != selected)
  45494. {
  45495. selected = shouldBeSelected;
  45496. if (ownerView != 0)
  45497. ownerView->repaint();
  45498. itemSelectionChanged (shouldBeSelected);
  45499. }
  45500. }
  45501. void TreeViewItem::paintItem (Graphics&, int, int)
  45502. {
  45503. }
  45504. void TreeViewItem::paintOpenCloseButton (Graphics& g, int width, int height, bool isMouseOver)
  45505. {
  45506. ownerView->getLookAndFeel()
  45507. .drawTreeviewPlusMinusBox (g, 0, 0, width, height, ! isOpen(), isMouseOver);
  45508. }
  45509. void TreeViewItem::itemClicked (const MouseEvent&)
  45510. {
  45511. }
  45512. void TreeViewItem::itemDoubleClicked (const MouseEvent&)
  45513. {
  45514. if (mightContainSubItems())
  45515. setOpen (! isOpen());
  45516. }
  45517. void TreeViewItem::itemSelectionChanged (bool)
  45518. {
  45519. }
  45520. const String TreeViewItem::getTooltip()
  45521. {
  45522. return String::empty;
  45523. }
  45524. const String TreeViewItem::getDragSourceDescription()
  45525. {
  45526. return String::empty;
  45527. }
  45528. bool TreeViewItem::isInterestedInFileDrag (const StringArray&)
  45529. {
  45530. return false;
  45531. }
  45532. void TreeViewItem::filesDropped (const StringArray& /*files*/, int /*insertIndex*/)
  45533. {
  45534. }
  45535. bool TreeViewItem::isInterestedInDragSource (const String& /*sourceDescription*/, Component* /*sourceComponent*/)
  45536. {
  45537. return false;
  45538. }
  45539. void TreeViewItem::itemDropped (const String& /*sourceDescription*/, Component* /*sourceComponent*/, int /*insertIndex*/)
  45540. {
  45541. }
  45542. const Rectangle<int> TreeViewItem::getItemPosition (const bool relativeToTreeViewTopLeft) const throw()
  45543. {
  45544. const int indentX = getIndentX();
  45545. int width = itemWidth;
  45546. if (ownerView != 0 && width < 0)
  45547. width = ownerView->viewport->getViewWidth() - indentX;
  45548. Rectangle<int> r (indentX, y, jmax (0, width), totalHeight);
  45549. if (relativeToTreeViewTopLeft)
  45550. r.setPosition (r.getX() - ownerView->viewport->getViewPositionX(),
  45551. r.getY() - ownerView->viewport->getViewPositionY());
  45552. return r;
  45553. }
  45554. void TreeViewItem::treeHasChanged() const throw()
  45555. {
  45556. if (ownerView != 0)
  45557. ownerView->itemsChanged();
  45558. }
  45559. void TreeViewItem::repaintItem() const
  45560. {
  45561. if (ownerView != 0 && areAllParentsOpen())
  45562. {
  45563. const Rectangle<int> r (getItemPosition (true));
  45564. ownerView->viewport->repaint (0, r.getY(), r.getRight(), r.getHeight());
  45565. }
  45566. }
  45567. bool TreeViewItem::areAllParentsOpen() const throw()
  45568. {
  45569. return parentItem == 0
  45570. || (parentItem->isOpen() && parentItem->areAllParentsOpen());
  45571. }
  45572. void TreeViewItem::updatePositions (int newY)
  45573. {
  45574. y = newY;
  45575. itemHeight = getItemHeight();
  45576. totalHeight = itemHeight;
  45577. itemWidth = getItemWidth();
  45578. totalWidth = jmax (itemWidth, 0) + getIndentX();
  45579. if (isOpen())
  45580. {
  45581. newY += totalHeight;
  45582. for (int i = 0; i < subItems.size(); ++i)
  45583. {
  45584. TreeViewItem* const ti = subItems.getUnchecked(i);
  45585. ti->updatePositions (newY);
  45586. newY += ti->totalHeight;
  45587. totalHeight += ti->totalHeight;
  45588. totalWidth = jmax (totalWidth, ti->totalWidth);
  45589. }
  45590. }
  45591. }
  45592. TreeViewItem* TreeViewItem::getDeepestOpenParentItem() throw()
  45593. {
  45594. TreeViewItem* result = this;
  45595. TreeViewItem* item = this;
  45596. while (item->parentItem != 0)
  45597. {
  45598. item = item->parentItem;
  45599. if (! item->isOpen())
  45600. result = item;
  45601. }
  45602. return result;
  45603. }
  45604. void TreeViewItem::setOwnerView (TreeView* const newOwner) throw()
  45605. {
  45606. ownerView = newOwner;
  45607. for (int i = subItems.size(); --i >= 0;)
  45608. subItems.getUnchecked(i)->setOwnerView (newOwner);
  45609. }
  45610. int TreeViewItem::getIndentX() const throw()
  45611. {
  45612. const int indentWidth = ownerView->getIndentSize();
  45613. int x = ownerView->rootItemVisible ? indentWidth : 0;
  45614. if (! ownerView->openCloseButtonsVisible)
  45615. x -= indentWidth;
  45616. TreeViewItem* p = parentItem;
  45617. while (p != 0)
  45618. {
  45619. x += indentWidth;
  45620. p = p->parentItem;
  45621. }
  45622. return x;
  45623. }
  45624. void TreeViewItem::setDrawsInLeftMargin (bool canDrawInLeftMargin) throw()
  45625. {
  45626. drawsInLeftMargin = canDrawInLeftMargin;
  45627. }
  45628. void TreeViewItem::paintRecursively (Graphics& g, int width)
  45629. {
  45630. jassert (ownerView != 0);
  45631. if (ownerView == 0)
  45632. return;
  45633. const int indent = getIndentX();
  45634. const int itemW = itemWidth < 0 ? width - indent : itemWidth;
  45635. g.setColour (ownerView->findColour (TreeView::linesColourId));
  45636. const float halfH = itemHeight * 0.5f;
  45637. int depth = 0;
  45638. TreeViewItem* p = parentItem;
  45639. while (p != 0)
  45640. {
  45641. ++depth;
  45642. p = p->parentItem;
  45643. }
  45644. if (! ownerView->rootItemVisible)
  45645. --depth;
  45646. const int indentWidth = ownerView->getIndentSize();
  45647. if (depth >= 0 && ownerView->openCloseButtonsVisible)
  45648. {
  45649. float x = (depth + 0.5f) * indentWidth;
  45650. if (depth >= 0)
  45651. {
  45652. if (parentItem != 0 && parentItem->drawLinesInside)
  45653. g.drawLine (x, 0, x, isLastOfSiblings() ? halfH : (float) itemHeight);
  45654. if ((parentItem != 0 && parentItem->drawLinesInside)
  45655. || (parentItem == 0 && drawLinesInside))
  45656. g.drawLine (x, halfH, x + indentWidth / 2, halfH);
  45657. }
  45658. p = parentItem;
  45659. int d = depth;
  45660. while (p != 0 && --d >= 0)
  45661. {
  45662. x -= (float) indentWidth;
  45663. if ((p->parentItem == 0 || p->parentItem->drawLinesInside)
  45664. && ! p->isLastOfSiblings())
  45665. {
  45666. g.drawLine (x, 0, x, (float) itemHeight);
  45667. }
  45668. p = p->parentItem;
  45669. }
  45670. if (mightContainSubItems())
  45671. {
  45672. g.saveState();
  45673. g.setOrigin (depth * indentWidth, 0);
  45674. g.reduceClipRegion (0, 0, indentWidth, itemHeight);
  45675. paintOpenCloseButton (g, indentWidth, itemHeight,
  45676. ((TreeViewContentComponent*) ownerView->viewport->getViewedComponent())
  45677. ->isMouseOverButton (this));
  45678. g.restoreState();
  45679. }
  45680. }
  45681. {
  45682. g.saveState();
  45683. g.setOrigin (indent, 0);
  45684. if (g.reduceClipRegion (drawsInLeftMargin ? -indent : 0, 0,
  45685. drawsInLeftMargin ? itemW + indent : itemW, itemHeight))
  45686. paintItem (g, itemW, itemHeight);
  45687. g.restoreState();
  45688. }
  45689. if (isOpen())
  45690. {
  45691. const Rectangle<int> clip (g.getClipBounds());
  45692. for (int i = 0; i < subItems.size(); ++i)
  45693. {
  45694. TreeViewItem* const ti = subItems.getUnchecked(i);
  45695. const int relY = ti->y - y;
  45696. if (relY >= clip.getBottom())
  45697. break;
  45698. if (relY + ti->totalHeight >= clip.getY())
  45699. {
  45700. g.saveState();
  45701. g.setOrigin (0, relY);
  45702. if (g.reduceClipRegion (0, 0, width, ti->totalHeight))
  45703. ti->paintRecursively (g, width);
  45704. g.restoreState();
  45705. }
  45706. }
  45707. }
  45708. }
  45709. bool TreeViewItem::isLastOfSiblings() const throw()
  45710. {
  45711. return parentItem == 0
  45712. || parentItem->subItems.getLast() == this;
  45713. }
  45714. int TreeViewItem::getIndexInParent() const throw()
  45715. {
  45716. if (parentItem == 0)
  45717. return 0;
  45718. return parentItem->subItems.indexOf (this);
  45719. }
  45720. TreeViewItem* TreeViewItem::getTopLevelItem() throw()
  45721. {
  45722. return (parentItem == 0) ? this
  45723. : parentItem->getTopLevelItem();
  45724. }
  45725. int TreeViewItem::getNumRows() const throw()
  45726. {
  45727. int num = 1;
  45728. if (isOpen())
  45729. {
  45730. for (int i = subItems.size(); --i >= 0;)
  45731. num += subItems.getUnchecked(i)->getNumRows();
  45732. }
  45733. return num;
  45734. }
  45735. TreeViewItem* TreeViewItem::getItemOnRow (int index) throw()
  45736. {
  45737. if (index == 0)
  45738. return this;
  45739. if (index > 0 && isOpen())
  45740. {
  45741. --index;
  45742. for (int i = 0; i < subItems.size(); ++i)
  45743. {
  45744. TreeViewItem* const item = subItems.getUnchecked(i);
  45745. if (index == 0)
  45746. return item;
  45747. const int numRows = item->getNumRows();
  45748. if (numRows > index)
  45749. return item->getItemOnRow (index);
  45750. index -= numRows;
  45751. }
  45752. }
  45753. return 0;
  45754. }
  45755. TreeViewItem* TreeViewItem::findItemRecursively (int targetY) throw()
  45756. {
  45757. if (((unsigned int) targetY) < (unsigned int) totalHeight)
  45758. {
  45759. const int h = itemHeight;
  45760. if (targetY < h)
  45761. return this;
  45762. if (isOpen())
  45763. {
  45764. targetY -= h;
  45765. for (int i = 0; i < subItems.size(); ++i)
  45766. {
  45767. TreeViewItem* const ti = subItems.getUnchecked(i);
  45768. if (targetY < ti->totalHeight)
  45769. return ti->findItemRecursively (targetY);
  45770. targetY -= ti->totalHeight;
  45771. }
  45772. }
  45773. }
  45774. return 0;
  45775. }
  45776. int TreeViewItem::countSelectedItemsRecursively() const throw()
  45777. {
  45778. int total = 0;
  45779. if (isSelected())
  45780. ++total;
  45781. for (int i = subItems.size(); --i >= 0;)
  45782. total += subItems.getUnchecked(i)->countSelectedItemsRecursively();
  45783. return total;
  45784. }
  45785. TreeViewItem* TreeViewItem::getSelectedItemWithIndex (int index) throw()
  45786. {
  45787. if (isSelected())
  45788. {
  45789. if (index == 0)
  45790. return this;
  45791. --index;
  45792. }
  45793. if (index >= 0)
  45794. {
  45795. for (int i = 0; i < subItems.size(); ++i)
  45796. {
  45797. TreeViewItem* const item = subItems.getUnchecked(i);
  45798. TreeViewItem* const found = item->getSelectedItemWithIndex (index);
  45799. if (found != 0)
  45800. return found;
  45801. index -= item->countSelectedItemsRecursively();
  45802. }
  45803. }
  45804. return 0;
  45805. }
  45806. int TreeViewItem::getRowNumberInTree() const throw()
  45807. {
  45808. if (parentItem != 0 && ownerView != 0)
  45809. {
  45810. int n = 1 + parentItem->getRowNumberInTree();
  45811. int ourIndex = parentItem->subItems.indexOf (this);
  45812. jassert (ourIndex >= 0);
  45813. while (--ourIndex >= 0)
  45814. n += parentItem->subItems [ourIndex]->getNumRows();
  45815. if (parentItem->parentItem == 0
  45816. && ! ownerView->rootItemVisible)
  45817. --n;
  45818. return n;
  45819. }
  45820. else
  45821. {
  45822. return 0;
  45823. }
  45824. }
  45825. void TreeViewItem::setLinesDrawnForSubItems (const bool drawLines) throw()
  45826. {
  45827. drawLinesInside = drawLines;
  45828. }
  45829. TreeViewItem* TreeViewItem::getNextVisibleItem (const bool recurse) const throw()
  45830. {
  45831. if (recurse && isOpen() && subItems.size() > 0)
  45832. return subItems [0];
  45833. if (parentItem != 0)
  45834. {
  45835. const int nextIndex = parentItem->subItems.indexOf (this) + 1;
  45836. if (nextIndex >= parentItem->subItems.size())
  45837. return parentItem->getNextVisibleItem (false);
  45838. return parentItem->subItems [nextIndex];
  45839. }
  45840. return 0;
  45841. }
  45842. const String TreeViewItem::getItemIdentifierString() const
  45843. {
  45844. String s;
  45845. if (parentItem != 0)
  45846. s = parentItem->getItemIdentifierString();
  45847. return s + T("/") + getUniqueName().replaceCharacter (T('/'), T('\\'));
  45848. }
  45849. TreeViewItem* TreeViewItem::findItemFromIdentifierString (const String& identifierString)
  45850. {
  45851. const String uid (getUniqueName());
  45852. if (uid == identifierString)
  45853. return this;
  45854. if (identifierString.startsWith (uid + T("/")))
  45855. {
  45856. const String remainingPath (identifierString.substring (uid.length() + 1));
  45857. bool wasOpen = isOpen();
  45858. setOpen (true);
  45859. for (int i = subItems.size(); --i >= 0;)
  45860. {
  45861. TreeViewItem* item = subItems.getUnchecked(i)->findItemFromIdentifierString (remainingPath);
  45862. if (item != 0)
  45863. return item;
  45864. }
  45865. setOpen (wasOpen);
  45866. }
  45867. return 0;
  45868. }
  45869. void TreeViewItem::restoreOpennessState (const XmlElement& e) throw()
  45870. {
  45871. if (e.hasTagName (T("CLOSED")))
  45872. {
  45873. setOpen (false);
  45874. }
  45875. else if (e.hasTagName (T("OPEN")))
  45876. {
  45877. setOpen (true);
  45878. forEachXmlChildElement (e, n)
  45879. {
  45880. const String id (n->getStringAttribute (T("id")));
  45881. for (int i = 0; i < subItems.size(); ++i)
  45882. {
  45883. TreeViewItem* const ti = subItems.getUnchecked(i);
  45884. if (ti->getUniqueName() == id)
  45885. {
  45886. ti->restoreOpennessState (*n);
  45887. break;
  45888. }
  45889. }
  45890. }
  45891. }
  45892. }
  45893. XmlElement* TreeViewItem::getOpennessState() const throw()
  45894. {
  45895. const String name (getUniqueName());
  45896. if (name.isNotEmpty())
  45897. {
  45898. XmlElement* e;
  45899. if (isOpen())
  45900. {
  45901. e = new XmlElement (T("OPEN"));
  45902. for (int i = 0; i < subItems.size(); ++i)
  45903. e->addChildElement (subItems.getUnchecked(i)->getOpennessState());
  45904. }
  45905. else
  45906. {
  45907. e = new XmlElement (T("CLOSED"));
  45908. }
  45909. e->setAttribute (T("id"), name);
  45910. return e;
  45911. }
  45912. else
  45913. {
  45914. // trying to save the openness for an element that has no name - this won't
  45915. // work because it needs the names to identify what to open.
  45916. jassertfalse
  45917. }
  45918. return 0;
  45919. }
  45920. END_JUCE_NAMESPACE
  45921. /*** End of inlined file: juce_TreeView.cpp ***/
  45922. /*** Start of inlined file: juce_DirectoryContentsDisplayComponent.cpp ***/
  45923. BEGIN_JUCE_NAMESPACE
  45924. DirectoryContentsDisplayComponent::DirectoryContentsDisplayComponent (DirectoryContentsList& listToShow)
  45925. : fileList (listToShow)
  45926. {
  45927. }
  45928. DirectoryContentsDisplayComponent::~DirectoryContentsDisplayComponent()
  45929. {
  45930. }
  45931. FileBrowserListener::~FileBrowserListener()
  45932. {
  45933. }
  45934. void DirectoryContentsDisplayComponent::addListener (FileBrowserListener* const listener) throw()
  45935. {
  45936. jassert (listener != 0);
  45937. if (listener != 0)
  45938. listeners.add (listener);
  45939. }
  45940. void DirectoryContentsDisplayComponent::removeListener (FileBrowserListener* const listener) throw()
  45941. {
  45942. listeners.removeValue (listener);
  45943. }
  45944. void DirectoryContentsDisplayComponent::sendSelectionChangeMessage()
  45945. {
  45946. const ComponentDeletionWatcher deletionWatcher (dynamic_cast <Component*> (this));
  45947. for (int i = listeners.size(); --i >= 0;)
  45948. {
  45949. ((FileBrowserListener*) listeners.getUnchecked (i))->selectionChanged();
  45950. if (deletionWatcher.hasBeenDeleted())
  45951. return;
  45952. i = jmin (i, listeners.size() - 1);
  45953. }
  45954. }
  45955. void DirectoryContentsDisplayComponent::sendMouseClickMessage (const File& file, const MouseEvent& e)
  45956. {
  45957. if (fileList.getDirectory().exists())
  45958. {
  45959. const ComponentDeletionWatcher deletionWatcher (dynamic_cast <Component*> (this));
  45960. for (int i = listeners.size(); --i >= 0;)
  45961. {
  45962. ((FileBrowserListener*) listeners.getUnchecked (i))->fileClicked (file, e);
  45963. if (deletionWatcher.hasBeenDeleted())
  45964. return;
  45965. i = jmin (i, listeners.size() - 1);
  45966. }
  45967. }
  45968. }
  45969. void DirectoryContentsDisplayComponent::sendDoubleClickMessage (const File& file)
  45970. {
  45971. if (fileList.getDirectory().exists())
  45972. {
  45973. const ComponentDeletionWatcher deletionWatcher (dynamic_cast <Component*> (this));
  45974. for (int i = listeners.size(); --i >= 0;)
  45975. {
  45976. ((FileBrowserListener*) listeners.getUnchecked (i))->fileDoubleClicked (file);
  45977. if (deletionWatcher.hasBeenDeleted())
  45978. return;
  45979. i = jmin (i, listeners.size() - 1);
  45980. }
  45981. }
  45982. }
  45983. END_JUCE_NAMESPACE
  45984. /*** End of inlined file: juce_DirectoryContentsDisplayComponent.cpp ***/
  45985. /*** Start of inlined file: juce_DirectoryContentsList.cpp ***/
  45986. BEGIN_JUCE_NAMESPACE
  45987. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  45988. bool* isDirectory, bool* isHidden, int64* fileSize, Time* modTime,
  45989. Time* creationTime, bool* isReadOnly);
  45990. bool juce_findFileNext (void* handle, String& resultFile,
  45991. bool* isDirectory, bool* isHidden, int64* fileSize,
  45992. Time* modTime, Time* creationTime, bool* isReadOnly);
  45993. void juce_findFileClose (void* handle);
  45994. DirectoryContentsList::DirectoryContentsList (const FileFilter* const fileFilter_,
  45995. TimeSliceThread& thread_)
  45996. : fileFilter (fileFilter_),
  45997. thread (thread_),
  45998. includeDirectories (false),
  45999. includeFiles (false),
  46000. ignoreHiddenFiles (true),
  46001. fileFindHandle (0),
  46002. shouldStop (true)
  46003. {
  46004. }
  46005. DirectoryContentsList::~DirectoryContentsList()
  46006. {
  46007. clear();
  46008. }
  46009. void DirectoryContentsList::setIgnoresHiddenFiles (const bool shouldIgnoreHiddenFiles)
  46010. {
  46011. ignoreHiddenFiles = shouldIgnoreHiddenFiles;
  46012. }
  46013. const File& DirectoryContentsList::getDirectory() const
  46014. {
  46015. return root;
  46016. }
  46017. void DirectoryContentsList::setDirectory (const File& directory,
  46018. const bool includeDirectories_,
  46019. const bool includeFiles_)
  46020. {
  46021. if (directory != root
  46022. || includeDirectories != includeDirectories_
  46023. || includeFiles != includeFiles_)
  46024. {
  46025. clear();
  46026. root = directory;
  46027. includeDirectories = includeDirectories_;
  46028. includeFiles = includeFiles_;
  46029. refresh();
  46030. }
  46031. }
  46032. void DirectoryContentsList::clear()
  46033. {
  46034. shouldStop = true;
  46035. thread.removeTimeSliceClient (this);
  46036. if (fileFindHandle != 0)
  46037. {
  46038. juce_findFileClose (fileFindHandle);
  46039. fileFindHandle = 0;
  46040. }
  46041. if (files.size() > 0)
  46042. {
  46043. files.clear();
  46044. changed();
  46045. }
  46046. }
  46047. void DirectoryContentsList::refresh()
  46048. {
  46049. clear();
  46050. if (root.isDirectory())
  46051. {
  46052. String fileFound;
  46053. bool fileFoundIsDir, isHidden, isReadOnly;
  46054. int64 fileSize;
  46055. Time modTime, creationTime;
  46056. String path (root.getFullPathName());
  46057. if (! path.endsWithChar (File::separator))
  46058. path += File::separator;
  46059. jassert (fileFindHandle == 0);
  46060. fileFindHandle = juce_findFileStart (path, T("*"), fileFound,
  46061. &fileFoundIsDir,
  46062. &isHidden,
  46063. &fileSize,
  46064. &modTime,
  46065. &creationTime,
  46066. &isReadOnly);
  46067. if (fileFindHandle != 0 && fileFound.isNotEmpty())
  46068. {
  46069. if (addFile (fileFound, fileFoundIsDir, isHidden,
  46070. fileSize, modTime, creationTime, isReadOnly))
  46071. {
  46072. changed();
  46073. }
  46074. }
  46075. shouldStop = false;
  46076. thread.addTimeSliceClient (this);
  46077. }
  46078. }
  46079. int DirectoryContentsList::getNumFiles() const
  46080. {
  46081. return files.size();
  46082. }
  46083. bool DirectoryContentsList::getFileInfo (const int index,
  46084. FileInfo& result) const
  46085. {
  46086. const ScopedLock sl (fileListLock);
  46087. const FileInfo* const info = files [index];
  46088. if (info != 0)
  46089. {
  46090. result = *info;
  46091. return true;
  46092. }
  46093. return false;
  46094. }
  46095. const File DirectoryContentsList::getFile (const int index) const
  46096. {
  46097. const ScopedLock sl (fileListLock);
  46098. const FileInfo* const info = files [index];
  46099. if (info != 0)
  46100. return root.getChildFile (info->filename);
  46101. return File::nonexistent;
  46102. }
  46103. bool DirectoryContentsList::isStillLoading() const
  46104. {
  46105. return fileFindHandle != 0;
  46106. }
  46107. void DirectoryContentsList::changed()
  46108. {
  46109. sendChangeMessage (this);
  46110. }
  46111. bool DirectoryContentsList::useTimeSlice()
  46112. {
  46113. const uint32 startTime = Time::getApproximateMillisecondCounter();
  46114. bool hasChanged = false;
  46115. for (int i = 100; --i >= 0;)
  46116. {
  46117. if (! checkNextFile (hasChanged))
  46118. {
  46119. if (hasChanged)
  46120. changed();
  46121. return false;
  46122. }
  46123. if (shouldStop || (Time::getApproximateMillisecondCounter() > startTime + 150))
  46124. break;
  46125. }
  46126. if (hasChanged)
  46127. changed();
  46128. return true;
  46129. }
  46130. bool DirectoryContentsList::checkNextFile (bool& hasChanged)
  46131. {
  46132. if (fileFindHandle != 0)
  46133. {
  46134. String fileFound;
  46135. bool fileFoundIsDir, isHidden, isReadOnly;
  46136. int64 fileSize;
  46137. Time modTime, creationTime;
  46138. if (juce_findFileNext (fileFindHandle, fileFound,
  46139. &fileFoundIsDir, &isHidden,
  46140. &fileSize,
  46141. &modTime,
  46142. &creationTime,
  46143. &isReadOnly))
  46144. {
  46145. if (addFile (fileFound, fileFoundIsDir, isHidden, fileSize,
  46146. modTime, creationTime, isReadOnly))
  46147. {
  46148. hasChanged = true;
  46149. }
  46150. return true;
  46151. }
  46152. else
  46153. {
  46154. juce_findFileClose (fileFindHandle);
  46155. fileFindHandle = 0;
  46156. }
  46157. }
  46158. return false;
  46159. }
  46160. int DirectoryContentsList::compareElements (const DirectoryContentsList::FileInfo* const first,
  46161. const DirectoryContentsList::FileInfo* const second)
  46162. {
  46163. #if JUCE_WINDOWS
  46164. if (first->isDirectory != second->isDirectory)
  46165. return first->isDirectory ? -1 : 1;
  46166. #endif
  46167. return first->filename.compareIgnoreCase (second->filename);
  46168. }
  46169. bool DirectoryContentsList::addFile (const String& filename,
  46170. const bool isDir,
  46171. const bool isHidden,
  46172. const int64 fileSize,
  46173. const Time& modTime,
  46174. const Time& creationTime,
  46175. const bool isReadOnly)
  46176. {
  46177. if (filename == T("..")
  46178. || filename == T(".")
  46179. || (ignoreHiddenFiles && isHidden))
  46180. return false;
  46181. const File file (root.getChildFile (filename));
  46182. if (((isDir && includeDirectories) || ((! isDir) && includeFiles))
  46183. && (fileFilter == 0
  46184. || ((! isDir) && fileFilter->isFileSuitable (file))
  46185. || (isDir && fileFilter->isDirectorySuitable (file))))
  46186. {
  46187. ScopedPointer <FileInfo> info (new FileInfo());
  46188. info->filename = filename;
  46189. info->fileSize = fileSize;
  46190. info->modificationTime = modTime;
  46191. info->creationTime = creationTime;
  46192. info->isDirectory = isDir;
  46193. info->isReadOnly = isReadOnly;
  46194. const ScopedLock sl (fileListLock);
  46195. for (int i = files.size(); --i >= 0;)
  46196. if (files.getUnchecked(i)->filename == info->filename)
  46197. return false;
  46198. files.addSorted (*this, info.release());
  46199. return true;
  46200. }
  46201. return false;
  46202. }
  46203. END_JUCE_NAMESPACE
  46204. /*** End of inlined file: juce_DirectoryContentsList.cpp ***/
  46205. /*** Start of inlined file: juce_FileBrowserComponent.cpp ***/
  46206. BEGIN_JUCE_NAMESPACE
  46207. FileBrowserComponent::FileBrowserComponent (int flags_,
  46208. const File& initialFileOrDirectory,
  46209. const FileFilter* fileFilter_,
  46210. FilePreviewComponent* previewComp_)
  46211. : FileFilter (String::empty),
  46212. fileFilter (fileFilter_),
  46213. flags (flags_),
  46214. previewComp (previewComp_),
  46215. thread ("Juce FileBrowser")
  46216. {
  46217. // You need to specify one or other of the open/save flags..
  46218. jassert ((flags & (saveMode | openMode)) != 0);
  46219. jassert ((flags & (saveMode | openMode)) != (saveMode | openMode));
  46220. // You need to specify at least one of these flags..
  46221. jassert ((flags & (canSelectFiles | canSelectDirectories)) != 0);
  46222. String filename;
  46223. if (initialFileOrDirectory == File::nonexistent)
  46224. {
  46225. currentRoot = File::getCurrentWorkingDirectory();
  46226. }
  46227. else if (initialFileOrDirectory.isDirectory())
  46228. {
  46229. currentRoot = initialFileOrDirectory;
  46230. }
  46231. else
  46232. {
  46233. chosenFiles.add (initialFileOrDirectory);
  46234. currentRoot = initialFileOrDirectory.getParentDirectory();
  46235. filename = initialFileOrDirectory.getFileName();
  46236. }
  46237. fileList = new DirectoryContentsList (this, thread);
  46238. if ((flags & useTreeView) != 0)
  46239. {
  46240. FileTreeComponent* const tree = new FileTreeComponent (*fileList);
  46241. if ((flags & canSelectMultipleItems) != 0)
  46242. tree->setMultiSelectEnabled (true);
  46243. addAndMakeVisible (tree);
  46244. fileListComponent = tree;
  46245. }
  46246. else
  46247. {
  46248. FileListComponent* const list = new FileListComponent (*fileList);
  46249. list->setOutlineThickness (1);
  46250. if ((flags & canSelectMultipleItems) != 0)
  46251. list->setMultipleSelectionEnabled (true);
  46252. addAndMakeVisible (list);
  46253. fileListComponent = list;
  46254. }
  46255. fileListComponent->addListener (this);
  46256. addAndMakeVisible (currentPathBox = new ComboBox ("path"));
  46257. currentPathBox->setEditableText (true);
  46258. StringArray rootNames, rootPaths;
  46259. const BitArray separators (getRoots (rootNames, rootPaths));
  46260. for (int i = 0; i < rootNames.size(); ++i)
  46261. {
  46262. if (separators [i])
  46263. currentPathBox->addSeparator();
  46264. currentPathBox->addItem (rootNames[i], i + 1);
  46265. }
  46266. currentPathBox->addSeparator();
  46267. currentPathBox->addListener (this);
  46268. addAndMakeVisible (filenameBox = new TextEditor());
  46269. filenameBox->setMultiLine (false);
  46270. filenameBox->setSelectAllWhenFocused (true);
  46271. filenameBox->setText (filename, false);
  46272. filenameBox->addListener (this);
  46273. filenameBox->setReadOnly ((flags & (filenameBoxIsReadOnly | canSelectMultipleItems)) != 0);
  46274. Label* label = new Label ("f", TRANS("file:"));
  46275. addAndMakeVisible (label);
  46276. label->attachToComponent (filenameBox, true);
  46277. addAndMakeVisible (goUpButton = getLookAndFeel().createFileBrowserGoUpButton());
  46278. goUpButton->addButtonListener (this);
  46279. goUpButton->setTooltip (TRANS ("go up to parent directory"));
  46280. if (previewComp != 0)
  46281. addAndMakeVisible (previewComp);
  46282. setRoot (currentRoot);
  46283. thread.startThread (4);
  46284. }
  46285. FileBrowserComponent::~FileBrowserComponent()
  46286. {
  46287. if (previewComp != 0)
  46288. removeChildComponent (previewComp);
  46289. deleteAllChildren();
  46290. fileList = 0;
  46291. thread.stopThread (10000);
  46292. }
  46293. void FileBrowserComponent::addListener (FileBrowserListener* const newListener) throw()
  46294. {
  46295. jassert (newListener != 0)
  46296. if (newListener != 0)
  46297. listeners.add (newListener);
  46298. }
  46299. void FileBrowserComponent::removeListener (FileBrowserListener* const listener) throw()
  46300. {
  46301. listeners.removeValue (listener);
  46302. }
  46303. bool FileBrowserComponent::isSaveMode() const throw()
  46304. {
  46305. return (flags & saveMode) != 0;
  46306. }
  46307. int FileBrowserComponent::getNumSelectedFiles() const throw()
  46308. {
  46309. if (chosenFiles.size() == 0 && currentFileIsValid())
  46310. return 1;
  46311. return chosenFiles.size();
  46312. }
  46313. const File FileBrowserComponent::getSelectedFile (int index) const throw()
  46314. {
  46315. if (! filenameBox->isReadOnly())
  46316. return currentRoot.getChildFile (filenameBox->getText());
  46317. else
  46318. return chosenFiles[index];
  46319. }
  46320. bool FileBrowserComponent::currentFileIsValid() const
  46321. {
  46322. if (isSaveMode())
  46323. return ! getSelectedFile (0).isDirectory();
  46324. else
  46325. return getSelectedFile (0).exists();
  46326. }
  46327. const File FileBrowserComponent::getHighlightedFile() const throw()
  46328. {
  46329. return fileListComponent->getSelectedFile (0);
  46330. }
  46331. bool FileBrowserComponent::isFileSuitable (const File& file) const
  46332. {
  46333. return (flags & canSelectFiles) != 0 ? (fileFilter == 0 || fileFilter->isFileSuitable (file))
  46334. : false;
  46335. }
  46336. bool FileBrowserComponent::isDirectorySuitable (const File&) const
  46337. {
  46338. return true;
  46339. }
  46340. bool FileBrowserComponent::isFileOrDirSuitable (const File& f) const
  46341. {
  46342. if (f.isDirectory())
  46343. return (flags & canSelectDirectories) != 0 && (fileFilter == 0 || fileFilter->isDirectorySuitable (f));
  46344. return (flags & canSelectFiles) != 0 && f.exists()
  46345. && (fileFilter == 0 || fileFilter->isFileSuitable (f));
  46346. }
  46347. const File FileBrowserComponent::getRoot() const
  46348. {
  46349. return currentRoot;
  46350. }
  46351. void FileBrowserComponent::setRoot (const File& newRootDirectory)
  46352. {
  46353. if (currentRoot != newRootDirectory)
  46354. {
  46355. fileListComponent->scrollToTop();
  46356. String path (newRootDirectory.getFullPathName());
  46357. if (path.isEmpty())
  46358. path += File::separator;
  46359. StringArray rootNames, rootPaths;
  46360. getRoots (rootNames, rootPaths);
  46361. if (! rootPaths.contains (path, true))
  46362. {
  46363. bool alreadyListed = false;
  46364. for (int i = currentPathBox->getNumItems(); --i >= 0;)
  46365. {
  46366. if (currentPathBox->getItemText (i).equalsIgnoreCase (path))
  46367. {
  46368. alreadyListed = true;
  46369. break;
  46370. }
  46371. }
  46372. if (! alreadyListed)
  46373. currentPathBox->addItem (path, currentPathBox->getNumItems() + 2);
  46374. }
  46375. }
  46376. currentRoot = newRootDirectory;
  46377. fileList->setDirectory (currentRoot, true, true);
  46378. String currentRootName (currentRoot.getFullPathName());
  46379. if (currentRootName.isEmpty())
  46380. currentRootName += File::separator;
  46381. currentPathBox->setText (currentRootName, true);
  46382. goUpButton->setEnabled (currentRoot.getParentDirectory().isDirectory()
  46383. && currentRoot.getParentDirectory() != currentRoot);
  46384. }
  46385. void FileBrowserComponent::goUp()
  46386. {
  46387. setRoot (getRoot().getParentDirectory());
  46388. }
  46389. void FileBrowserComponent::refresh()
  46390. {
  46391. fileList->refresh();
  46392. }
  46393. const String FileBrowserComponent::getActionVerb() const
  46394. {
  46395. return isSaveMode() ? TRANS("Save") : TRANS("Open");
  46396. }
  46397. FilePreviewComponent* FileBrowserComponent::getPreviewComponent() const throw()
  46398. {
  46399. return previewComp;
  46400. }
  46401. void FileBrowserComponent::resized()
  46402. {
  46403. getLookAndFeel()
  46404. .layoutFileBrowserComponent (*this, fileListComponent,
  46405. previewComp, currentPathBox,
  46406. filenameBox, goUpButton);
  46407. }
  46408. void FileBrowserComponent::sendListenerChangeMessage()
  46409. {
  46410. ComponentDeletionWatcher deletionWatcher (this);
  46411. if (previewComp != 0)
  46412. previewComp->selectedFileChanged (getSelectedFile (0));
  46413. jassert (! deletionWatcher.hasBeenDeleted());
  46414. for (int i = listeners.size(); --i >= 0;)
  46415. {
  46416. ((FileBrowserListener*) listeners.getUnchecked (i))->selectionChanged();
  46417. if (deletionWatcher.hasBeenDeleted())
  46418. return;
  46419. i = jmin (i, listeners.size() - 1);
  46420. }
  46421. }
  46422. void FileBrowserComponent::selectionChanged()
  46423. {
  46424. StringArray newFilenames;
  46425. bool resetChosenFiles = true;
  46426. for (int i = 0; i < fileListComponent->getNumSelectedFiles(); ++i)
  46427. {
  46428. const File f (fileListComponent->getSelectedFile (i));
  46429. if (isFileOrDirSuitable (f))
  46430. {
  46431. if (resetChosenFiles)
  46432. {
  46433. chosenFiles.clear();
  46434. resetChosenFiles = false;
  46435. }
  46436. chosenFiles.add (f);
  46437. newFilenames.add (f.getRelativePathFrom (getRoot()));
  46438. }
  46439. }
  46440. if (newFilenames.size() > 0)
  46441. filenameBox->setText (newFilenames.joinIntoString (T(", ")), false);
  46442. sendListenerChangeMessage();
  46443. }
  46444. void FileBrowserComponent::fileClicked (const File& f, const MouseEvent& e)
  46445. {
  46446. ComponentDeletionWatcher deletionWatcher (this);
  46447. for (int i = listeners.size(); --i >= 0;)
  46448. {
  46449. ((FileBrowserListener*) listeners.getUnchecked (i))->fileClicked (f, e);
  46450. if (deletionWatcher.hasBeenDeleted())
  46451. return;
  46452. i = jmin (i, listeners.size() - 1);
  46453. }
  46454. }
  46455. void FileBrowserComponent::fileDoubleClicked (const File& f)
  46456. {
  46457. if (f.isDirectory())
  46458. {
  46459. setRoot (f);
  46460. }
  46461. else
  46462. {
  46463. ComponentDeletionWatcher deletionWatcher (this);
  46464. for (int i = listeners.size(); --i >= 0;)
  46465. {
  46466. ((FileBrowserListener*) listeners.getUnchecked (i))->fileDoubleClicked (f);
  46467. if (deletionWatcher.hasBeenDeleted())
  46468. return;
  46469. i = jmin (i, listeners.size() - 1);
  46470. }
  46471. }
  46472. }
  46473. bool FileBrowserComponent::keyPressed (const KeyPress& key)
  46474. {
  46475. #if JUCE_LINUX || JUCE_WINDOWS
  46476. if (key.getModifiers().isCommandDown()
  46477. && (key.getKeyCode() == 'H' || key.getKeyCode() == 'h'))
  46478. {
  46479. fileList->setIgnoresHiddenFiles (! fileList->ignoresHiddenFiles());
  46480. fileList->refresh();
  46481. return true;
  46482. }
  46483. #endif
  46484. return false;
  46485. }
  46486. void FileBrowserComponent::textEditorTextChanged (TextEditor&)
  46487. {
  46488. sendListenerChangeMessage();
  46489. }
  46490. void FileBrowserComponent::textEditorReturnKeyPressed (TextEditor&)
  46491. {
  46492. if (filenameBox->getText().containsChar (File::separator))
  46493. {
  46494. const File f (currentRoot.getChildFile (filenameBox->getText()));
  46495. if (f.isDirectory())
  46496. {
  46497. setRoot (f);
  46498. chosenFiles.clear();
  46499. filenameBox->setText (String::empty);
  46500. }
  46501. else
  46502. {
  46503. setRoot (f.getParentDirectory());
  46504. chosenFiles.clear();
  46505. chosenFiles.add (f);
  46506. filenameBox->setText (f.getFileName());
  46507. }
  46508. }
  46509. else
  46510. {
  46511. fileDoubleClicked (getSelectedFile (0));
  46512. }
  46513. }
  46514. void FileBrowserComponent::textEditorEscapeKeyPressed (TextEditor&)
  46515. {
  46516. }
  46517. void FileBrowserComponent::textEditorFocusLost (TextEditor&)
  46518. {
  46519. if (! isSaveMode())
  46520. selectionChanged();
  46521. }
  46522. void FileBrowserComponent::buttonClicked (Button*)
  46523. {
  46524. goUp();
  46525. }
  46526. void FileBrowserComponent::comboBoxChanged (ComboBox*)
  46527. {
  46528. const String newText (currentPathBox->getText().trim().unquoted());
  46529. if (newText.isNotEmpty())
  46530. {
  46531. const int index = currentPathBox->getSelectedId() - 1;
  46532. StringArray rootNames, rootPaths;
  46533. getRoots (rootNames, rootPaths);
  46534. if (rootPaths [index].isNotEmpty())
  46535. {
  46536. setRoot (File (rootPaths [index]));
  46537. }
  46538. else
  46539. {
  46540. File f (newText);
  46541. for (;;)
  46542. {
  46543. if (f.isDirectory())
  46544. {
  46545. setRoot (f);
  46546. break;
  46547. }
  46548. if (f.getParentDirectory() == f)
  46549. break;
  46550. f = f.getParentDirectory();
  46551. }
  46552. }
  46553. }
  46554. }
  46555. const BitArray FileBrowserComponent::getRoots (StringArray& rootNames, StringArray& rootPaths)
  46556. {
  46557. BitArray separators;
  46558. #if JUCE_WINDOWS
  46559. Array<File> roots;
  46560. File::findFileSystemRoots (roots);
  46561. rootPaths.clear();
  46562. for (int i = 0; i < roots.size(); ++i)
  46563. {
  46564. const File& drive = roots.getReference(i);
  46565. String name (drive.getFullPathName());
  46566. rootPaths.add (name);
  46567. if (drive.isOnHardDisk())
  46568. {
  46569. String volume (drive.getVolumeLabel());
  46570. if (volume.isEmpty())
  46571. volume = TRANS("Hard Drive");
  46572. name << " [" << drive.getVolumeLabel() << ']';
  46573. }
  46574. else if (drive.isOnCDRomDrive())
  46575. {
  46576. name << TRANS(" [CD/DVD drive]");
  46577. }
  46578. rootNames.add (name);
  46579. }
  46580. separators.setBit (rootPaths.size());
  46581. rootPaths.add (File::getSpecialLocation (File::userDocumentsDirectory).getFullPathName());
  46582. rootNames.add ("Documents");
  46583. rootPaths.add (File::getSpecialLocation (File::userDesktopDirectory).getFullPathName());
  46584. rootNames.add ("Desktop");
  46585. #endif
  46586. #if JUCE_MAC
  46587. rootPaths.add (File::getSpecialLocation (File::userHomeDirectory).getFullPathName());
  46588. rootNames.add ("Home folder");
  46589. rootPaths.add (File::getSpecialLocation (File::userDocumentsDirectory).getFullPathName());
  46590. rootNames.add ("Documents");
  46591. rootPaths.add (File::getSpecialLocation (File::userDesktopDirectory).getFullPathName());
  46592. rootNames.add ("Desktop");
  46593. separators.setBit (rootPaths.size());
  46594. Array <File> volumes;
  46595. File vol ("/Volumes");
  46596. vol.findChildFiles (volumes, File::findDirectories, false);
  46597. for (int i = 0; i < volumes.size(); ++i)
  46598. {
  46599. const File& volume = volumes.getReference(i);
  46600. if (volume.isDirectory() && ! volume.getFileName().startsWithChar (T('.')))
  46601. {
  46602. rootPaths.add (volume.getFullPathName());
  46603. rootNames.add (volume.getFileName());
  46604. }
  46605. }
  46606. #endif
  46607. #if JUCE_LINUX
  46608. rootPaths.add ("/");
  46609. rootNames.add ("/");
  46610. rootPaths.add (File::getSpecialLocation (File::userHomeDirectory).getFullPathName());
  46611. rootNames.add ("Home folder");
  46612. rootPaths.add (File::getSpecialLocation (File::userDesktopDirectory).getFullPathName());
  46613. rootNames.add ("Desktop");
  46614. #endif
  46615. return separators;
  46616. }
  46617. END_JUCE_NAMESPACE
  46618. /*** End of inlined file: juce_FileBrowserComponent.cpp ***/
  46619. /*** Start of inlined file: juce_FileChooser.cpp ***/
  46620. BEGIN_JUCE_NAMESPACE
  46621. FileChooser::FileChooser (const String& chooserBoxTitle,
  46622. const File& currentFileOrDirectory,
  46623. const String& fileFilters,
  46624. const bool useNativeDialogBox_)
  46625. : title (chooserBoxTitle),
  46626. filters (fileFilters),
  46627. startingFile (currentFileOrDirectory),
  46628. useNativeDialogBox (useNativeDialogBox_)
  46629. {
  46630. #if JUCE_LINUX
  46631. useNativeDialogBox = false;
  46632. #endif
  46633. if (! fileFilters.containsNonWhitespaceChars())
  46634. filters = T("*");
  46635. }
  46636. FileChooser::~FileChooser()
  46637. {
  46638. }
  46639. bool FileChooser::browseForFileToOpen (FilePreviewComponent* previewComponent)
  46640. {
  46641. return showDialog (false, true, false, false, false, previewComponent);
  46642. }
  46643. bool FileChooser::browseForMultipleFilesToOpen (FilePreviewComponent* previewComponent)
  46644. {
  46645. return showDialog (false, true, false, false, true, previewComponent);
  46646. }
  46647. bool FileChooser::browseForMultipleFilesOrDirectories (FilePreviewComponent* previewComponent)
  46648. {
  46649. return showDialog (true, true, false, false, true, previewComponent);
  46650. }
  46651. bool FileChooser::browseForFileToSave (const bool warnAboutOverwritingExistingFiles)
  46652. {
  46653. return showDialog (false, true, true, warnAboutOverwritingExistingFiles, false, 0);
  46654. }
  46655. bool FileChooser::browseForDirectory()
  46656. {
  46657. return showDialog (true, false, false, false, false, 0);
  46658. }
  46659. const File FileChooser::getResult() const
  46660. {
  46661. // if you've used a multiple-file select, you should use the getResults() method
  46662. // to retrieve all the files that were chosen.
  46663. jassert (results.size() <= 1);
  46664. return results.getFirst();
  46665. }
  46666. const Array<File>& FileChooser::getResults() const
  46667. {
  46668. return results;
  46669. }
  46670. bool FileChooser::showDialog (const bool selectsDirectories,
  46671. const bool selectsFiles,
  46672. const bool isSave,
  46673. const bool warnAboutOverwritingExistingFiles,
  46674. const bool selectMultipleFiles,
  46675. FilePreviewComponent* const previewComponent)
  46676. {
  46677. ScopedPointer <ComponentDeletionWatcher> currentlyFocusedChecker;
  46678. Component* const currentlyFocused = Component::getCurrentlyFocusedComponent();
  46679. if (currentlyFocused != 0)
  46680. currentlyFocusedChecker = new ComponentDeletionWatcher (currentlyFocused);
  46681. results.clear();
  46682. // the preview component needs to be the right size before you pass it in here..
  46683. jassert (previewComponent == 0 || (previewComponent->getWidth() > 10
  46684. && previewComponent->getHeight() > 10));
  46685. #if JUCE_WINDOWS
  46686. if (useNativeDialogBox && ! (selectsFiles && selectsDirectories))
  46687. #elif JUCE_MAC
  46688. if (useNativeDialogBox && (previewComponent == 0))
  46689. #else
  46690. if (false)
  46691. #endif
  46692. {
  46693. showPlatformDialog (results, title, startingFile, filters,
  46694. selectsDirectories, selectsFiles, isSave,
  46695. warnAboutOverwritingExistingFiles,
  46696. selectMultipleFiles,
  46697. previewComponent);
  46698. }
  46699. else
  46700. {
  46701. WildcardFileFilter wildcard (selectsFiles ? filters : String::empty,
  46702. selectsDirectories ? "*" : String::empty,
  46703. String::empty);
  46704. int flags = isSave ? FileBrowserComponent::saveMode
  46705. : FileBrowserComponent::openMode;
  46706. if (selectsFiles)
  46707. flags |= FileBrowserComponent::canSelectFiles;
  46708. if (selectsDirectories)
  46709. flags |= FileBrowserComponent::canSelectDirectories;
  46710. if (selectMultipleFiles)
  46711. flags |= FileBrowserComponent::canSelectMultipleItems;
  46712. FileBrowserComponent browserComponent (flags, startingFile, &wildcard, previewComponent);
  46713. FileChooserDialogBox box (title, String::empty,
  46714. browserComponent,
  46715. warnAboutOverwritingExistingFiles,
  46716. browserComponent.findColour (AlertWindow::backgroundColourId));
  46717. if (box.show())
  46718. {
  46719. for (int i = 0; i < browserComponent.getNumSelectedFiles(); ++i)
  46720. results.add (browserComponent.getSelectedFile (i));
  46721. }
  46722. }
  46723. if (currentlyFocused != 0 && ! currentlyFocusedChecker->hasBeenDeleted())
  46724. currentlyFocused->grabKeyboardFocus();
  46725. return results.size() > 0;
  46726. }
  46727. FilePreviewComponent::FilePreviewComponent()
  46728. {
  46729. }
  46730. FilePreviewComponent::~FilePreviewComponent()
  46731. {
  46732. }
  46733. END_JUCE_NAMESPACE
  46734. /*** End of inlined file: juce_FileChooser.cpp ***/
  46735. /*** Start of inlined file: juce_FileChooserDialogBox.cpp ***/
  46736. BEGIN_JUCE_NAMESPACE
  46737. FileChooserDialogBox::FileChooserDialogBox (const String& name,
  46738. const String& instructions,
  46739. FileBrowserComponent& chooserComponent,
  46740. const bool warnAboutOverwritingExistingFiles_,
  46741. const Colour& backgroundColour)
  46742. : ResizableWindow (name, backgroundColour, true),
  46743. warnAboutOverwritingExistingFiles (warnAboutOverwritingExistingFiles_)
  46744. {
  46745. content = new ContentComponent();
  46746. content->setName (name);
  46747. content->instructions = instructions;
  46748. content->chooserComponent = &chooserComponent;
  46749. content->addAndMakeVisible (&chooserComponent);
  46750. content->okButton = new TextButton (chooserComponent.getActionVerb());
  46751. content->addAndMakeVisible (content->okButton);
  46752. content->okButton->addButtonListener (this);
  46753. content->okButton->setEnabled (chooserComponent.currentFileIsValid());
  46754. content->okButton->addShortcut (KeyPress (KeyPress::returnKey, 0, 0));
  46755. content->cancelButton = new TextButton (TRANS("Cancel"));
  46756. content->addAndMakeVisible (content->cancelButton);
  46757. content->cancelButton->addButtonListener (this);
  46758. content->cancelButton->addShortcut (KeyPress (KeyPress::escapeKey, 0, 0));
  46759. setContentComponent (content);
  46760. setResizable (true, true);
  46761. setResizeLimits (300, 300, 1200, 1000);
  46762. content->chooserComponent->addListener (this);
  46763. }
  46764. FileChooserDialogBox::~FileChooserDialogBox()
  46765. {
  46766. content->chooserComponent->removeListener (this);
  46767. }
  46768. bool FileChooserDialogBox::show (int w, int h)
  46769. {
  46770. if (w <= 0)
  46771. {
  46772. Component* const previewComp = content->chooserComponent->getPreviewComponent();
  46773. if (previewComp != 0)
  46774. w = 400 + previewComp->getWidth();
  46775. else
  46776. w = 600;
  46777. }
  46778. if (h <= 0)
  46779. h = 500;
  46780. centreWithSize (w, h);
  46781. const bool ok = (runModalLoop() != 0);
  46782. setVisible (false);
  46783. return ok;
  46784. }
  46785. void FileChooserDialogBox::buttonClicked (Button* button)
  46786. {
  46787. if (button == content->okButton)
  46788. {
  46789. if (warnAboutOverwritingExistingFiles
  46790. && content->chooserComponent->isSaveMode()
  46791. && content->chooserComponent->getSelectedFile(0).exists())
  46792. {
  46793. if (! AlertWindow::showOkCancelBox (AlertWindow::WarningIcon,
  46794. TRANS("File already exists"),
  46795. TRANS("There's already a file called:\n\n")
  46796. + content->chooserComponent->getSelectedFile(0).getFullPathName()
  46797. + T("\n\nAre you sure you want to overwrite it?"),
  46798. TRANS("overwrite"),
  46799. TRANS("cancel")))
  46800. {
  46801. return;
  46802. }
  46803. }
  46804. exitModalState (1);
  46805. }
  46806. else if (button == content->cancelButton)
  46807. closeButtonPressed();
  46808. }
  46809. void FileChooserDialogBox::closeButtonPressed()
  46810. {
  46811. setVisible (false);
  46812. }
  46813. void FileChooserDialogBox::selectionChanged()
  46814. {
  46815. content->okButton->setEnabled (content->chooserComponent->currentFileIsValid());
  46816. }
  46817. void FileChooserDialogBox::fileClicked (const File&, const MouseEvent&)
  46818. {
  46819. }
  46820. void FileChooserDialogBox::fileDoubleClicked (const File&)
  46821. {
  46822. selectionChanged();
  46823. content->okButton->triggerClick();
  46824. }
  46825. FileChooserDialogBox::ContentComponent::ContentComponent()
  46826. {
  46827. setInterceptsMouseClicks (false, true);
  46828. }
  46829. FileChooserDialogBox::ContentComponent::~ContentComponent()
  46830. {
  46831. delete okButton;
  46832. delete cancelButton;
  46833. }
  46834. void FileChooserDialogBox::ContentComponent::paint (Graphics& g)
  46835. {
  46836. g.setColour (getLookAndFeel().findColour (FileChooserDialogBox::titleTextColourId));
  46837. text.draw (g);
  46838. }
  46839. void FileChooserDialogBox::ContentComponent::resized()
  46840. {
  46841. getLookAndFeel().createFileChooserHeaderText (getName(), instructions, text, getWidth());
  46842. float left, top, right, bottom;
  46843. text.getBoundingBox (0, text.getNumGlyphs(), left, top, right, bottom, false);
  46844. const int y = roundToInt (bottom) + 10;
  46845. const int buttonHeight = 26;
  46846. const int buttonY = getHeight() - buttonHeight - 8;
  46847. chooserComponent->setBounds (0, y, getWidth(), buttonY - y - 20);
  46848. okButton->setBounds (proportionOfWidth (0.25f), buttonY,
  46849. proportionOfWidth (0.2f), buttonHeight);
  46850. cancelButton->setBounds (proportionOfWidth (0.55f), buttonY,
  46851. proportionOfWidth (0.2f), buttonHeight);
  46852. }
  46853. END_JUCE_NAMESPACE
  46854. /*** End of inlined file: juce_FileChooserDialogBox.cpp ***/
  46855. /*** Start of inlined file: juce_FileFilter.cpp ***/
  46856. BEGIN_JUCE_NAMESPACE
  46857. FileFilter::FileFilter (const String& filterDescription)
  46858. : description (filterDescription)
  46859. {
  46860. }
  46861. FileFilter::~FileFilter()
  46862. {
  46863. }
  46864. const String& FileFilter::getDescription() const throw()
  46865. {
  46866. return description;
  46867. }
  46868. END_JUCE_NAMESPACE
  46869. /*** End of inlined file: juce_FileFilter.cpp ***/
  46870. /*** Start of inlined file: juce_FileListComponent.cpp ***/
  46871. BEGIN_JUCE_NAMESPACE
  46872. Image* juce_createIconForFile (const File& file);
  46873. FileListComponent::FileListComponent (DirectoryContentsList& listToShow)
  46874. : ListBox (String::empty, 0),
  46875. DirectoryContentsDisplayComponent (listToShow)
  46876. {
  46877. setModel (this);
  46878. fileList.addChangeListener (this);
  46879. }
  46880. FileListComponent::~FileListComponent()
  46881. {
  46882. fileList.removeChangeListener (this);
  46883. deleteAllChildren();
  46884. }
  46885. int FileListComponent::getNumSelectedFiles() const
  46886. {
  46887. return getNumSelectedRows();
  46888. }
  46889. const File FileListComponent::getSelectedFile (int index) const
  46890. {
  46891. return fileList.getFile (getSelectedRow (index));
  46892. }
  46893. void FileListComponent::scrollToTop()
  46894. {
  46895. getVerticalScrollBar()->setCurrentRangeStart (0);
  46896. }
  46897. void FileListComponent::changeListenerCallback (void*)
  46898. {
  46899. updateContent();
  46900. if (lastDirectory != fileList.getDirectory())
  46901. {
  46902. lastDirectory = fileList.getDirectory();
  46903. deselectAllRows();
  46904. }
  46905. }
  46906. class FileListItemComponent : public Component,
  46907. public TimeSliceClient,
  46908. public AsyncUpdater
  46909. {
  46910. public:
  46911. FileListItemComponent (FileListComponent& owner_,
  46912. TimeSliceThread& thread_) throw()
  46913. : owner (owner_),
  46914. thread (thread_),
  46915. icon (0)
  46916. {
  46917. }
  46918. ~FileListItemComponent() throw()
  46919. {
  46920. thread.removeTimeSliceClient (this);
  46921. clearIcon();
  46922. }
  46923. void paint (Graphics& g)
  46924. {
  46925. getLookAndFeel().drawFileBrowserRow (g, getWidth(), getHeight(),
  46926. file.getFileName(),
  46927. icon,
  46928. fileSize, modTime,
  46929. isDirectory, highlighted,
  46930. index);
  46931. }
  46932. void mouseDown (const MouseEvent& e)
  46933. {
  46934. owner.selectRowsBasedOnModifierKeys (index, e.mods);
  46935. owner.sendMouseClickMessage (file, e);
  46936. }
  46937. void mouseDoubleClick (const MouseEvent&)
  46938. {
  46939. owner.sendDoubleClickMessage (file);
  46940. }
  46941. void update (const File& root,
  46942. const DirectoryContentsList::FileInfo* const fileInfo,
  46943. const int index_,
  46944. const bool highlighted_) throw()
  46945. {
  46946. thread.removeTimeSliceClient (this);
  46947. if (highlighted_ != highlighted
  46948. || index_ != index)
  46949. {
  46950. index = index_;
  46951. highlighted = highlighted_;
  46952. repaint();
  46953. }
  46954. File newFile;
  46955. String newFileSize;
  46956. String newModTime;
  46957. if (fileInfo != 0)
  46958. {
  46959. newFile = root.getChildFile (fileInfo->filename);
  46960. newFileSize = File::descriptionOfSizeInBytes (fileInfo->fileSize);
  46961. newModTime = fileInfo->modificationTime.formatted (T("%d %b '%y %H:%M"));
  46962. }
  46963. if (newFile != file
  46964. || fileSize != newFileSize
  46965. || modTime != newModTime)
  46966. {
  46967. file = newFile;
  46968. fileSize = newFileSize;
  46969. modTime = newModTime;
  46970. isDirectory = fileInfo != 0 && fileInfo->isDirectory;
  46971. repaint();
  46972. clearIcon();
  46973. }
  46974. if (file != File::nonexistent
  46975. && icon == 0 && ! isDirectory)
  46976. {
  46977. updateIcon (true);
  46978. if (icon == 0)
  46979. thread.addTimeSliceClient (this);
  46980. }
  46981. }
  46982. bool useTimeSlice()
  46983. {
  46984. updateIcon (false);
  46985. return false;
  46986. }
  46987. void handleAsyncUpdate()
  46988. {
  46989. repaint();
  46990. }
  46991. juce_UseDebuggingNewOperator
  46992. private:
  46993. FileListComponent& owner;
  46994. TimeSliceThread& thread;
  46995. bool highlighted;
  46996. int index;
  46997. File file;
  46998. String fileSize;
  46999. String modTime;
  47000. Image* icon;
  47001. bool isDirectory;
  47002. void clearIcon() throw()
  47003. {
  47004. ImageCache::release (icon);
  47005. icon = 0;
  47006. }
  47007. void updateIcon (const bool onlyUpdateIfCached) throw()
  47008. {
  47009. if (icon == 0)
  47010. {
  47011. const int hashCode = (file.getFullPathName() + T("_iconCacheSalt")).hashCode();
  47012. Image* im = ImageCache::getFromHashCode (hashCode);
  47013. if (im == 0 && ! onlyUpdateIfCached)
  47014. {
  47015. im = juce_createIconForFile (file);
  47016. if (im != 0)
  47017. ImageCache::addImageToCache (im, hashCode);
  47018. }
  47019. if (im != 0)
  47020. {
  47021. icon = im;
  47022. triggerAsyncUpdate();
  47023. }
  47024. }
  47025. }
  47026. };
  47027. int FileListComponent::getNumRows()
  47028. {
  47029. return fileList.getNumFiles();
  47030. }
  47031. void FileListComponent::paintListBoxItem (int, Graphics&, int, int, bool)
  47032. {
  47033. }
  47034. Component* FileListComponent::refreshComponentForRow (int row, bool isSelected, Component* existingComponentToUpdate)
  47035. {
  47036. FileListItemComponent* comp = dynamic_cast <FileListItemComponent*> (existingComponentToUpdate);
  47037. if (comp == 0)
  47038. {
  47039. delete existingComponentToUpdate;
  47040. comp = new FileListItemComponent (*this, fileList.getTimeSliceThread());
  47041. }
  47042. DirectoryContentsList::FileInfo fileInfo;
  47043. if (fileList.getFileInfo (row, fileInfo))
  47044. comp->update (fileList.getDirectory(), &fileInfo, row, isSelected);
  47045. else
  47046. comp->update (fileList.getDirectory(), 0, row, isSelected);
  47047. return comp;
  47048. }
  47049. void FileListComponent::selectedRowsChanged (int /*lastRowSelected*/)
  47050. {
  47051. sendSelectionChangeMessage();
  47052. }
  47053. void FileListComponent::deleteKeyPressed (int /*currentSelectedRow*/)
  47054. {
  47055. }
  47056. void FileListComponent::returnKeyPressed (int currentSelectedRow)
  47057. {
  47058. sendDoubleClickMessage (fileList.getFile (currentSelectedRow));
  47059. }
  47060. END_JUCE_NAMESPACE
  47061. /*** End of inlined file: juce_FileListComponent.cpp ***/
  47062. /*** Start of inlined file: juce_FilenameComponent.cpp ***/
  47063. BEGIN_JUCE_NAMESPACE
  47064. FilenameComponent::FilenameComponent (const String& name,
  47065. const File& currentFile,
  47066. const bool canEditFilename,
  47067. const bool isDirectory,
  47068. const bool isForSaving,
  47069. const String& fileBrowserWildcard,
  47070. const String& enforcedSuffix_,
  47071. const String& textWhenNothingSelected)
  47072. : Component (name),
  47073. maxRecentFiles (30),
  47074. isDir (isDirectory),
  47075. isSaving (isForSaving),
  47076. isFileDragOver (false),
  47077. wildcard (fileBrowserWildcard),
  47078. enforcedSuffix (enforcedSuffix_)
  47079. {
  47080. addAndMakeVisible (filenameBox = new ComboBox (T("fn")));
  47081. filenameBox->setEditableText (canEditFilename);
  47082. filenameBox->addListener (this);
  47083. filenameBox->setTextWhenNothingSelected (textWhenNothingSelected);
  47084. filenameBox->setTextWhenNoChoicesAvailable (TRANS("(no recently seleced files)"));
  47085. browseButton = 0;
  47086. setBrowseButtonText (T("..."));
  47087. setCurrentFile (currentFile, true);
  47088. }
  47089. FilenameComponent::~FilenameComponent()
  47090. {
  47091. deleteAllChildren();
  47092. }
  47093. void FilenameComponent::paintOverChildren (Graphics& g)
  47094. {
  47095. if (isFileDragOver)
  47096. {
  47097. g.setColour (Colours::red.withAlpha (0.2f));
  47098. g.drawRect (0, 0, getWidth(), getHeight(), 3);
  47099. }
  47100. }
  47101. void FilenameComponent::resized()
  47102. {
  47103. getLookAndFeel().layoutFilenameComponent (*this, filenameBox, browseButton);
  47104. }
  47105. void FilenameComponent::setBrowseButtonText (const String& newBrowseButtonText)
  47106. {
  47107. browseButtonText = newBrowseButtonText;
  47108. lookAndFeelChanged();
  47109. }
  47110. void FilenameComponent::lookAndFeelChanged()
  47111. {
  47112. deleteAndZero (browseButton);
  47113. addAndMakeVisible (browseButton = getLookAndFeel().createFilenameComponentBrowseButton (browseButtonText));
  47114. browseButton->setConnectedEdges (Button::ConnectedOnLeft);
  47115. resized();
  47116. browseButton->addButtonListener (this);
  47117. }
  47118. void FilenameComponent::setTooltip (const String& newTooltip)
  47119. {
  47120. SettableTooltipClient::setTooltip (newTooltip);
  47121. filenameBox->setTooltip (newTooltip);
  47122. }
  47123. void FilenameComponent::setDefaultBrowseTarget (const File& newDefaultDirectory) throw()
  47124. {
  47125. defaultBrowseFile = newDefaultDirectory;
  47126. }
  47127. void FilenameComponent::buttonClicked (Button*)
  47128. {
  47129. FileChooser fc (TRANS("Choose a new file"),
  47130. getCurrentFile() == File::nonexistent ? defaultBrowseFile
  47131. : getCurrentFile(),
  47132. wildcard);
  47133. if (isDir ? fc.browseForDirectory()
  47134. : (isSaving ? fc.browseForFileToSave (false)
  47135. : fc.browseForFileToOpen()))
  47136. {
  47137. setCurrentFile (fc.getResult(), true);
  47138. }
  47139. }
  47140. void FilenameComponent::comboBoxChanged (ComboBox*)
  47141. {
  47142. setCurrentFile (getCurrentFile(), true);
  47143. }
  47144. bool FilenameComponent::isInterestedInFileDrag (const StringArray&)
  47145. {
  47146. return true;
  47147. }
  47148. void FilenameComponent::filesDropped (const StringArray& filenames, int, int)
  47149. {
  47150. isFileDragOver = false;
  47151. repaint();
  47152. const File f (filenames[0]);
  47153. if (f.exists() && (f.isDirectory() == isDir))
  47154. setCurrentFile (f, true);
  47155. }
  47156. void FilenameComponent::fileDragEnter (const StringArray&, int, int)
  47157. {
  47158. isFileDragOver = true;
  47159. repaint();
  47160. }
  47161. void FilenameComponent::fileDragExit (const StringArray&)
  47162. {
  47163. isFileDragOver = false;
  47164. repaint();
  47165. }
  47166. const File FilenameComponent::getCurrentFile() const
  47167. {
  47168. File f (filenameBox->getText());
  47169. if (enforcedSuffix.isNotEmpty())
  47170. f = f.withFileExtension (enforcedSuffix);
  47171. return f;
  47172. }
  47173. void FilenameComponent::setCurrentFile (File newFile,
  47174. const bool addToRecentlyUsedList,
  47175. const bool sendChangeNotification)
  47176. {
  47177. if (enforcedSuffix.isNotEmpty())
  47178. newFile = newFile.withFileExtension (enforcedSuffix);
  47179. if (newFile.getFullPathName() != lastFilename)
  47180. {
  47181. lastFilename = newFile.getFullPathName();
  47182. if (addToRecentlyUsedList)
  47183. addRecentlyUsedFile (newFile);
  47184. filenameBox->setText (lastFilename, true);
  47185. if (sendChangeNotification)
  47186. triggerAsyncUpdate();
  47187. }
  47188. }
  47189. void FilenameComponent::setFilenameIsEditable (const bool shouldBeEditable)
  47190. {
  47191. filenameBox->setEditableText (shouldBeEditable);
  47192. }
  47193. const StringArray FilenameComponent::getRecentlyUsedFilenames() const
  47194. {
  47195. StringArray names;
  47196. for (int i = 0; i < filenameBox->getNumItems(); ++i)
  47197. names.add (filenameBox->getItemText (i));
  47198. return names;
  47199. }
  47200. void FilenameComponent::setRecentlyUsedFilenames (const StringArray& filenames)
  47201. {
  47202. if (filenames != getRecentlyUsedFilenames())
  47203. {
  47204. filenameBox->clear();
  47205. for (int i = 0; i < jmin (filenames.size(), maxRecentFiles); ++i)
  47206. filenameBox->addItem (filenames[i], i + 1);
  47207. }
  47208. }
  47209. void FilenameComponent::setMaxNumberOfRecentFiles (const int newMaximum)
  47210. {
  47211. maxRecentFiles = jmax (1, newMaximum);
  47212. setRecentlyUsedFilenames (getRecentlyUsedFilenames());
  47213. }
  47214. void FilenameComponent::addRecentlyUsedFile (const File& file)
  47215. {
  47216. StringArray files (getRecentlyUsedFilenames());
  47217. if (file.getFullPathName().isNotEmpty())
  47218. {
  47219. files.removeString (file.getFullPathName(), true);
  47220. files.insert (0, file.getFullPathName());
  47221. setRecentlyUsedFilenames (files);
  47222. }
  47223. }
  47224. void FilenameComponent::addListener (FilenameComponentListener* const listener) throw()
  47225. {
  47226. jassert (listener != 0);
  47227. if (listener != 0)
  47228. listeners.add (listener);
  47229. }
  47230. void FilenameComponent::removeListener (FilenameComponentListener* const listener) throw()
  47231. {
  47232. listeners.removeValue (listener);
  47233. }
  47234. void FilenameComponent::handleAsyncUpdate()
  47235. {
  47236. for (int i = listeners.size(); --i >= 0;)
  47237. {
  47238. ((FilenameComponentListener*) listeners.getUnchecked (i))->filenameComponentChanged (this);
  47239. i = jmin (i, listeners.size());
  47240. }
  47241. }
  47242. END_JUCE_NAMESPACE
  47243. /*** End of inlined file: juce_FilenameComponent.cpp ***/
  47244. /*** Start of inlined file: juce_FileSearchPathListComponent.cpp ***/
  47245. BEGIN_JUCE_NAMESPACE
  47246. FileSearchPathListComponent::FileSearchPathListComponent()
  47247. {
  47248. addAndMakeVisible (listBox = new ListBox (String::empty, this));
  47249. listBox->setColour (ListBox::backgroundColourId, Colours::black.withAlpha (0.02f));
  47250. listBox->setColour (ListBox::outlineColourId, Colours::black.withAlpha (0.1f));
  47251. listBox->setOutlineThickness (1);
  47252. addAndMakeVisible (addButton = new TextButton ("+"));
  47253. addButton->addButtonListener (this);
  47254. addButton->setConnectedEdges (Button::ConnectedOnLeft | Button::ConnectedOnRight | Button::ConnectedOnBottom | Button::ConnectedOnTop);
  47255. addAndMakeVisible (removeButton = new TextButton ("-"));
  47256. removeButton->addButtonListener (this);
  47257. removeButton->setConnectedEdges (Button::ConnectedOnLeft | Button::ConnectedOnRight | Button::ConnectedOnBottom | Button::ConnectedOnTop);
  47258. addAndMakeVisible (changeButton = new TextButton (TRANS("change...")));
  47259. changeButton->addButtonListener (this);
  47260. addAndMakeVisible (upButton = new DrawableButton (String::empty, DrawableButton::ImageOnButtonBackground));
  47261. upButton->addButtonListener (this);
  47262. {
  47263. Path arrowPath;
  47264. arrowPath.addArrow (50.0f, 100.0f, 50.0f, 0.0f, 40.0f, 100.0f, 50.0f);
  47265. DrawablePath arrowImage;
  47266. arrowImage.setFill (Colours::black.withAlpha (0.4f));
  47267. arrowImage.setPath (arrowPath);
  47268. ((DrawableButton*) upButton)->setImages (&arrowImage);
  47269. }
  47270. addAndMakeVisible (downButton = new DrawableButton (String::empty, DrawableButton::ImageOnButtonBackground));
  47271. downButton->addButtonListener (this);
  47272. {
  47273. Path arrowPath;
  47274. arrowPath.addArrow (50.0f, 0.0f, 50.0f, 100.0f, 40.0f, 100.0f, 50.0f);
  47275. DrawablePath arrowImage;
  47276. arrowImage.setFill (Colours::black.withAlpha (0.4f));
  47277. arrowImage.setPath (arrowPath);
  47278. ((DrawableButton*) downButton)->setImages (&arrowImage);
  47279. }
  47280. updateButtons();
  47281. }
  47282. FileSearchPathListComponent::~FileSearchPathListComponent()
  47283. {
  47284. deleteAllChildren();
  47285. }
  47286. void FileSearchPathListComponent::updateButtons() throw()
  47287. {
  47288. const bool anythingSelected = listBox->getNumSelectedRows() > 0;
  47289. removeButton->setEnabled (anythingSelected);
  47290. changeButton->setEnabled (anythingSelected);
  47291. upButton->setEnabled (anythingSelected);
  47292. downButton->setEnabled (anythingSelected);
  47293. }
  47294. void FileSearchPathListComponent::changed() throw()
  47295. {
  47296. listBox->updateContent();
  47297. listBox->repaint();
  47298. updateButtons();
  47299. }
  47300. void FileSearchPathListComponent::setPath (const FileSearchPath& newPath)
  47301. {
  47302. if (newPath.toString() != path.toString())
  47303. {
  47304. path = newPath;
  47305. changed();
  47306. }
  47307. }
  47308. void FileSearchPathListComponent::setDefaultBrowseTarget (const File& newDefaultDirectory) throw()
  47309. {
  47310. defaultBrowseTarget = newDefaultDirectory;
  47311. }
  47312. int FileSearchPathListComponent::getNumRows()
  47313. {
  47314. return path.getNumPaths();
  47315. }
  47316. void FileSearchPathListComponent::paintListBoxItem (int rowNumber, Graphics& g, int width, int height, bool rowIsSelected)
  47317. {
  47318. if (rowIsSelected)
  47319. g.fillAll (findColour (TextEditor::highlightColourId));
  47320. g.setColour (findColour (ListBox::textColourId));
  47321. Font f (height * 0.7f);
  47322. f.setHorizontalScale (0.9f);
  47323. g.setFont (f);
  47324. g.drawText (path [rowNumber].getFullPathName(),
  47325. 4, 0, width - 6, height,
  47326. Justification::centredLeft, true);
  47327. }
  47328. void FileSearchPathListComponent::deleteKeyPressed (int row)
  47329. {
  47330. if (((unsigned int) row) < (unsigned int) path.getNumPaths())
  47331. {
  47332. path.remove (row);
  47333. changed();
  47334. }
  47335. }
  47336. void FileSearchPathListComponent::returnKeyPressed (int row)
  47337. {
  47338. FileChooser chooser (TRANS("Change folder..."), path [row], T("*"));
  47339. if (chooser.browseForDirectory())
  47340. {
  47341. path.remove (row);
  47342. path.add (chooser.getResult(), row);
  47343. changed();
  47344. }
  47345. }
  47346. void FileSearchPathListComponent::listBoxItemDoubleClicked (int row, const MouseEvent&)
  47347. {
  47348. returnKeyPressed (row);
  47349. }
  47350. void FileSearchPathListComponent::selectedRowsChanged (int)
  47351. {
  47352. updateButtons();
  47353. }
  47354. void FileSearchPathListComponent::paint (Graphics& g)
  47355. {
  47356. g.fillAll (findColour (backgroundColourId));
  47357. }
  47358. void FileSearchPathListComponent::resized()
  47359. {
  47360. const int buttonH = 22;
  47361. const int buttonY = getHeight() - buttonH - 4;
  47362. listBox->setBounds (2, 2, getWidth() - 4, buttonY - 5);
  47363. addButton->setBounds (2, buttonY, buttonH, buttonH);
  47364. removeButton->setBounds (addButton->getRight(), buttonY, buttonH, buttonH);
  47365. ((TextButton*) changeButton)->changeWidthToFitText (buttonH);
  47366. downButton->setSize (buttonH * 2, buttonH);
  47367. upButton->setSize (buttonH * 2, buttonH);
  47368. downButton->setTopRightPosition (getWidth() - 2, buttonY);
  47369. upButton->setTopRightPosition (downButton->getX() - 4, buttonY);
  47370. changeButton->setTopRightPosition (upButton->getX() - 8, buttonY);
  47371. }
  47372. bool FileSearchPathListComponent::isInterestedInFileDrag (const StringArray&)
  47373. {
  47374. return true;
  47375. }
  47376. void FileSearchPathListComponent::filesDropped (const StringArray& filenames, int, int mouseY)
  47377. {
  47378. for (int i = filenames.size(); --i >= 0;)
  47379. {
  47380. const File f (filenames[i]);
  47381. if (f.isDirectory())
  47382. {
  47383. const int row = listBox->getRowContainingPosition (0, mouseY - listBox->getY());
  47384. path.add (f, row);
  47385. changed();
  47386. }
  47387. }
  47388. }
  47389. void FileSearchPathListComponent::buttonClicked (Button* button)
  47390. {
  47391. const int currentRow = listBox->getSelectedRow();
  47392. if (button == removeButton)
  47393. {
  47394. deleteKeyPressed (currentRow);
  47395. }
  47396. else if (button == addButton)
  47397. {
  47398. File start (defaultBrowseTarget);
  47399. if (start == File::nonexistent)
  47400. start = path [0];
  47401. if (start == File::nonexistent)
  47402. start = File::getCurrentWorkingDirectory();
  47403. FileChooser chooser (TRANS("Add a folder..."), start, T("*"));
  47404. if (chooser.browseForDirectory())
  47405. {
  47406. path.add (chooser.getResult(), currentRow);
  47407. }
  47408. }
  47409. else if (button == changeButton)
  47410. {
  47411. returnKeyPressed (currentRow);
  47412. }
  47413. else if (button == upButton)
  47414. {
  47415. if (currentRow > 0 && currentRow < path.getNumPaths())
  47416. {
  47417. const File f (path[currentRow]);
  47418. path.remove (currentRow);
  47419. path.add (f, currentRow - 1);
  47420. listBox->selectRow (currentRow - 1);
  47421. }
  47422. }
  47423. else if (button == downButton)
  47424. {
  47425. if (currentRow >= 0 && currentRow < path.getNumPaths() - 1)
  47426. {
  47427. const File f (path[currentRow]);
  47428. path.remove (currentRow);
  47429. path.add (f, currentRow + 1);
  47430. listBox->selectRow (currentRow + 1);
  47431. }
  47432. }
  47433. changed();
  47434. }
  47435. END_JUCE_NAMESPACE
  47436. /*** End of inlined file: juce_FileSearchPathListComponent.cpp ***/
  47437. /*** Start of inlined file: juce_FileTreeComponent.cpp ***/
  47438. BEGIN_JUCE_NAMESPACE
  47439. Image* juce_createIconForFile (const File& file);
  47440. class FileListTreeItem : public TreeViewItem,
  47441. public TimeSliceClient,
  47442. public AsyncUpdater,
  47443. public ChangeListener
  47444. {
  47445. public:
  47446. FileListTreeItem (FileTreeComponent& owner_,
  47447. DirectoryContentsList* const parentContentsList_,
  47448. const int indexInContentsList_,
  47449. const File& file_,
  47450. TimeSliceThread& thread_) throw()
  47451. : file (file_),
  47452. owner (owner_),
  47453. parentContentsList (parentContentsList_),
  47454. indexInContentsList (indexInContentsList_),
  47455. subContentsList (0),
  47456. canDeleteSubContentsList (false),
  47457. thread (thread_),
  47458. icon (0)
  47459. {
  47460. DirectoryContentsList::FileInfo fileInfo;
  47461. if (parentContentsList_ != 0
  47462. && parentContentsList_->getFileInfo (indexInContentsList_, fileInfo))
  47463. {
  47464. fileSize = File::descriptionOfSizeInBytes (fileInfo.fileSize);
  47465. modTime = fileInfo.modificationTime.formatted (T("%d %b '%y %H:%M"));
  47466. isDirectory = fileInfo.isDirectory;
  47467. }
  47468. else
  47469. {
  47470. isDirectory = true;
  47471. }
  47472. }
  47473. ~FileListTreeItem() throw()
  47474. {
  47475. thread.removeTimeSliceClient (this);
  47476. clearSubItems();
  47477. ImageCache::release (icon);
  47478. if (canDeleteSubContentsList)
  47479. delete subContentsList;
  47480. }
  47481. bool mightContainSubItems() { return isDirectory; }
  47482. const String getUniqueName() const { return file.getFullPathName(); }
  47483. int getItemHeight() const { return 22; }
  47484. const String getDragSourceDescription() { return owner.getDragAndDropDescription(); }
  47485. void itemOpennessChanged (bool isNowOpen)
  47486. {
  47487. if (isNowOpen)
  47488. {
  47489. clearSubItems();
  47490. isDirectory = file.isDirectory();
  47491. if (isDirectory)
  47492. {
  47493. if (subContentsList == 0)
  47494. {
  47495. jassert (parentContentsList != 0);
  47496. DirectoryContentsList* const l = new DirectoryContentsList (parentContentsList->getFilter(), thread);
  47497. l->setDirectory (file, true, true);
  47498. setSubContentsList (l);
  47499. canDeleteSubContentsList = true;
  47500. }
  47501. changeListenerCallback (0);
  47502. }
  47503. }
  47504. }
  47505. void setSubContentsList (DirectoryContentsList* newList) throw()
  47506. {
  47507. jassert (subContentsList == 0);
  47508. subContentsList = newList;
  47509. newList->addChangeListener (this);
  47510. }
  47511. void changeListenerCallback (void*)
  47512. {
  47513. clearSubItems();
  47514. if (isOpen() && subContentsList != 0)
  47515. {
  47516. for (int i = 0; i < subContentsList->getNumFiles(); ++i)
  47517. {
  47518. FileListTreeItem* const item
  47519. = new FileListTreeItem (owner, subContentsList, i, subContentsList->getFile(i), thread);
  47520. addSubItem (item);
  47521. }
  47522. }
  47523. }
  47524. void paintItem (Graphics& g, int width, int height)
  47525. {
  47526. if (file != File::nonexistent)
  47527. {
  47528. updateIcon (true);
  47529. if (icon == 0)
  47530. thread.addTimeSliceClient (this);
  47531. }
  47532. owner.getLookAndFeel()
  47533. .drawFileBrowserRow (g, width, height,
  47534. file.getFileName(),
  47535. icon,
  47536. fileSize, modTime,
  47537. isDirectory, isSelected(),
  47538. indexInContentsList);
  47539. }
  47540. void itemClicked (const MouseEvent& e)
  47541. {
  47542. owner.sendMouseClickMessage (file, e);
  47543. }
  47544. void itemDoubleClicked (const MouseEvent& e)
  47545. {
  47546. TreeViewItem::itemDoubleClicked (e);
  47547. owner.sendDoubleClickMessage (file);
  47548. }
  47549. void itemSelectionChanged (bool)
  47550. {
  47551. owner.sendSelectionChangeMessage();
  47552. }
  47553. bool useTimeSlice()
  47554. {
  47555. updateIcon (false);
  47556. thread.removeTimeSliceClient (this);
  47557. return false;
  47558. }
  47559. void handleAsyncUpdate()
  47560. {
  47561. owner.repaint();
  47562. }
  47563. const File file;
  47564. juce_UseDebuggingNewOperator
  47565. private:
  47566. FileTreeComponent& owner;
  47567. DirectoryContentsList* parentContentsList;
  47568. int indexInContentsList;
  47569. DirectoryContentsList* subContentsList;
  47570. bool isDirectory, canDeleteSubContentsList;
  47571. TimeSliceThread& thread;
  47572. Image* icon;
  47573. String fileSize;
  47574. String modTime;
  47575. void updateIcon (const bool onlyUpdateIfCached) throw()
  47576. {
  47577. if (icon == 0)
  47578. {
  47579. const int hashCode = (file.getFullPathName() + T("_iconCacheSalt")).hashCode();
  47580. Image* im = ImageCache::getFromHashCode (hashCode);
  47581. if (im == 0 && ! onlyUpdateIfCached)
  47582. {
  47583. im = juce_createIconForFile (file);
  47584. if (im != 0)
  47585. ImageCache::addImageToCache (im, hashCode);
  47586. }
  47587. if (im != 0)
  47588. {
  47589. icon = im;
  47590. triggerAsyncUpdate();
  47591. }
  47592. }
  47593. }
  47594. };
  47595. FileTreeComponent::FileTreeComponent (DirectoryContentsList& listToShow)
  47596. : DirectoryContentsDisplayComponent (listToShow)
  47597. {
  47598. FileListTreeItem* const root
  47599. = new FileListTreeItem (*this, 0, 0, listToShow.getDirectory(),
  47600. listToShow.getTimeSliceThread());
  47601. root->setSubContentsList (&listToShow);
  47602. setRootItemVisible (false);
  47603. setRootItem (root);
  47604. }
  47605. FileTreeComponent::~FileTreeComponent()
  47606. {
  47607. deleteRootItem();
  47608. }
  47609. const File FileTreeComponent::getSelectedFile (const int index) const
  47610. {
  47611. const FileListTreeItem* const item = dynamic_cast <const FileListTreeItem*> (getSelectedItem (index));
  47612. if (item != 0)
  47613. return item->file;
  47614. return File::nonexistent;
  47615. }
  47616. void FileTreeComponent::scrollToTop()
  47617. {
  47618. getViewport()->getVerticalScrollBar()->setCurrentRangeStart (0);
  47619. }
  47620. void FileTreeComponent::setDragAndDropDescription (const String& description) throw()
  47621. {
  47622. dragAndDropDescription = description;
  47623. }
  47624. END_JUCE_NAMESPACE
  47625. /*** End of inlined file: juce_FileTreeComponent.cpp ***/
  47626. /*** Start of inlined file: juce_ImagePreviewComponent.cpp ***/
  47627. BEGIN_JUCE_NAMESPACE
  47628. ImagePreviewComponent::ImagePreviewComponent()
  47629. {
  47630. }
  47631. ImagePreviewComponent::~ImagePreviewComponent()
  47632. {
  47633. }
  47634. void ImagePreviewComponent::getThumbSize (int& w, int& h) const
  47635. {
  47636. const int availableW = proportionOfWidth (0.97f);
  47637. const int availableH = getHeight() - 13 * 4;
  47638. const double scale = jmin (1.0,
  47639. availableW / (double) w,
  47640. availableH / (double) h);
  47641. w = roundToInt (scale * w);
  47642. h = roundToInt (scale * h);
  47643. }
  47644. void ImagePreviewComponent::selectedFileChanged (const File& file)
  47645. {
  47646. if (fileToLoad != file)
  47647. {
  47648. fileToLoad = file;
  47649. startTimer (100);
  47650. }
  47651. }
  47652. void ImagePreviewComponent::timerCallback()
  47653. {
  47654. stopTimer();
  47655. currentThumbnail = 0;
  47656. currentDetails = String::empty;
  47657. repaint();
  47658. ScopedPointer <FileInputStream> in (fileToLoad.createInputStream());
  47659. if (in != 0)
  47660. {
  47661. ImageFileFormat* const format = ImageFileFormat::findImageFormatForStream (*in);
  47662. if (format != 0)
  47663. {
  47664. currentThumbnail = format->decodeImage (*in);
  47665. if (currentThumbnail != 0)
  47666. {
  47667. int w = currentThumbnail->getWidth();
  47668. int h = currentThumbnail->getHeight();
  47669. currentDetails
  47670. << fileToLoad.getFileName() << "\n"
  47671. << format->getFormatName() << "\n"
  47672. << w << " x " << h << " pixels\n"
  47673. << File::descriptionOfSizeInBytes (fileToLoad.getSize());
  47674. getThumbSize (w, h);
  47675. currentThumbnail = currentThumbnail->createCopy (w, h);
  47676. }
  47677. }
  47678. }
  47679. }
  47680. void ImagePreviewComponent::paint (Graphics& g)
  47681. {
  47682. if (currentThumbnail != 0)
  47683. {
  47684. g.setFont (13.0f);
  47685. int w = currentThumbnail->getWidth();
  47686. int h = currentThumbnail->getHeight();
  47687. getThumbSize (w, h);
  47688. const int numLines = 4;
  47689. const int totalH = 13 * numLines + h + 4;
  47690. const int y = (getHeight() - totalH) / 2;
  47691. g.drawImageWithin (currentThumbnail,
  47692. (getWidth() - w) / 2, y, w, h,
  47693. RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize,
  47694. false);
  47695. g.drawFittedText (currentDetails,
  47696. 0, y + h + 4, getWidth(), 100,
  47697. Justification::centredTop, numLines);
  47698. }
  47699. }
  47700. END_JUCE_NAMESPACE
  47701. /*** End of inlined file: juce_ImagePreviewComponent.cpp ***/
  47702. /*** Start of inlined file: juce_WildcardFileFilter.cpp ***/
  47703. BEGIN_JUCE_NAMESPACE
  47704. WildcardFileFilter::WildcardFileFilter (const String& fileWildcardPatterns,
  47705. const String& directoryWildcardPatterns,
  47706. const String& description_)
  47707. : FileFilter (description_.isEmpty() ? fileWildcardPatterns
  47708. : (description_ + T(" (") + fileWildcardPatterns + T(")")))
  47709. {
  47710. parse (fileWildcardPatterns, fileWildcards);
  47711. parse (directoryWildcardPatterns, directoryWildcards);
  47712. }
  47713. WildcardFileFilter::~WildcardFileFilter()
  47714. {
  47715. }
  47716. bool WildcardFileFilter::isFileSuitable (const File& file) const
  47717. {
  47718. return match (file, fileWildcards);
  47719. }
  47720. bool WildcardFileFilter::isDirectorySuitable (const File& file) const
  47721. {
  47722. return match (file, directoryWildcards);
  47723. }
  47724. void WildcardFileFilter::parse (const String& pattern, StringArray& result) throw()
  47725. {
  47726. result.addTokens (pattern.toLowerCase(), T(";,"), T("\"'"));
  47727. result.trim();
  47728. result.removeEmptyStrings();
  47729. // special case for *.*, because people use it to mean "any file", but it
  47730. // would actually ignore files with no extension.
  47731. for (int i = result.size(); --i >= 0;)
  47732. if (result[i] == T("*.*"))
  47733. result.set (i, T("*"));
  47734. }
  47735. bool WildcardFileFilter::match (const File& file, const StringArray& wildcards) throw()
  47736. {
  47737. const String filename (file.getFileName());
  47738. for (int i = wildcards.size(); --i >= 0;)
  47739. if (filename.matchesWildcard (wildcards[i], true))
  47740. return true;
  47741. return false;
  47742. }
  47743. END_JUCE_NAMESPACE
  47744. /*** End of inlined file: juce_WildcardFileFilter.cpp ***/
  47745. /*** Start of inlined file: juce_KeyboardFocusTraverser.cpp ***/
  47746. BEGIN_JUCE_NAMESPACE
  47747. KeyboardFocusTraverser::KeyboardFocusTraverser()
  47748. {
  47749. }
  47750. KeyboardFocusTraverser::~KeyboardFocusTraverser()
  47751. {
  47752. }
  47753. // This will sort a set of components, so that they are ordered in terms of
  47754. // left-to-right and then top-to-bottom.
  47755. class ScreenPositionComparator
  47756. {
  47757. public:
  47758. ScreenPositionComparator() {}
  47759. static int compareElements (const Component* const first, const Component* const second) throw()
  47760. {
  47761. int explicitOrder1 = first->getExplicitFocusOrder();
  47762. if (explicitOrder1 <= 0)
  47763. explicitOrder1 = std::numeric_limits<int>::max() / 2;
  47764. int explicitOrder2 = second->getExplicitFocusOrder();
  47765. if (explicitOrder2 <= 0)
  47766. explicitOrder2 = std::numeric_limits<int>::max() / 2;
  47767. if (explicitOrder1 != explicitOrder2)
  47768. return explicitOrder1 - explicitOrder2;
  47769. const int diff = first->getY() - second->getY();
  47770. return (diff == 0) ? first->getX() - second->getX()
  47771. : diff;
  47772. }
  47773. };
  47774. static void findAllFocusableComponents (Component* const parent, Array <Component*>& comps)
  47775. {
  47776. if (parent->getNumChildComponents() > 0)
  47777. {
  47778. Array <Component*> localComps;
  47779. ScreenPositionComparator comparator;
  47780. int i;
  47781. for (i = parent->getNumChildComponents(); --i >= 0;)
  47782. {
  47783. Component* const c = parent->getChildComponent (i);
  47784. if (c->isVisible() && c->isEnabled())
  47785. localComps.addSorted (comparator, c);
  47786. }
  47787. for (i = 0; i < localComps.size(); ++i)
  47788. {
  47789. Component* const c = localComps.getUnchecked (i);
  47790. if (c->getWantsKeyboardFocus())
  47791. comps.add (c);
  47792. if (! c->isFocusContainer())
  47793. findAllFocusableComponents (c, comps);
  47794. }
  47795. }
  47796. }
  47797. static Component* getIncrementedComponent (Component* const current, const int delta) throw()
  47798. {
  47799. Component* focusContainer = current->getParentComponent();
  47800. if (focusContainer != 0)
  47801. {
  47802. while (focusContainer->getParentComponent() != 0 && ! focusContainer->isFocusContainer())
  47803. focusContainer = focusContainer->getParentComponent();
  47804. if (focusContainer != 0)
  47805. {
  47806. Array <Component*> comps;
  47807. findAllFocusableComponents (focusContainer, comps);
  47808. if (comps.size() > 0)
  47809. {
  47810. const int index = comps.indexOf (current);
  47811. return comps [(index + comps.size() + delta) % comps.size()];
  47812. }
  47813. }
  47814. }
  47815. return 0;
  47816. }
  47817. Component* KeyboardFocusTraverser::getNextComponent (Component* current)
  47818. {
  47819. return getIncrementedComponent (current, 1);
  47820. }
  47821. Component* KeyboardFocusTraverser::getPreviousComponent (Component* current)
  47822. {
  47823. return getIncrementedComponent (current, -1);
  47824. }
  47825. Component* KeyboardFocusTraverser::getDefaultComponent (Component* parentComponent)
  47826. {
  47827. Array <Component*> comps;
  47828. if (parentComponent != 0)
  47829. findAllFocusableComponents (parentComponent, comps);
  47830. return comps.getFirst();
  47831. }
  47832. END_JUCE_NAMESPACE
  47833. /*** End of inlined file: juce_KeyboardFocusTraverser.cpp ***/
  47834. /*** Start of inlined file: juce_KeyListener.cpp ***/
  47835. BEGIN_JUCE_NAMESPACE
  47836. bool KeyListener::keyStateChanged (const bool, Component*)
  47837. {
  47838. return false;
  47839. }
  47840. END_JUCE_NAMESPACE
  47841. /*** End of inlined file: juce_KeyListener.cpp ***/
  47842. /*** Start of inlined file: juce_KeyMappingEditorComponent.cpp ***/
  47843. BEGIN_JUCE_NAMESPACE
  47844. // N.B. these two includes are put here deliberately to avoid problems with
  47845. // old GCCs failing on long include paths
  47846. const int maxKeys = 3;
  47847. class KeyMappingChangeButton : public Button
  47848. {
  47849. public:
  47850. KeyMappingChangeButton (KeyMappingEditorComponent* const owner_,
  47851. const CommandID commandID_,
  47852. const String& keyName,
  47853. const int keyNum_)
  47854. : Button (keyName),
  47855. owner (owner_),
  47856. commandID (commandID_),
  47857. keyNum (keyNum_)
  47858. {
  47859. setWantsKeyboardFocus (false);
  47860. setTriggeredOnMouseDown (keyNum >= 0);
  47861. if (keyNum_ < 0)
  47862. setTooltip (TRANS("adds a new key-mapping"));
  47863. else
  47864. setTooltip (TRANS("click to change this key-mapping"));
  47865. }
  47866. ~KeyMappingChangeButton()
  47867. {
  47868. }
  47869. void paintButton (Graphics& g, bool /*isOver*/, bool /*isDown*/)
  47870. {
  47871. getLookAndFeel().drawKeymapChangeButton (g, getWidth(), getHeight(), *this,
  47872. keyNum >= 0 ? getName() : String::empty);
  47873. }
  47874. void clicked()
  47875. {
  47876. if (keyNum >= 0)
  47877. {
  47878. // existing key clicked..
  47879. PopupMenu m;
  47880. m.addItem (1, TRANS("change this key-mapping"));
  47881. m.addSeparator();
  47882. m.addItem (2, TRANS("remove this key-mapping"));
  47883. const int res = m.show();
  47884. if (res == 1)
  47885. {
  47886. owner->assignNewKey (commandID, keyNum);
  47887. }
  47888. else if (res == 2)
  47889. {
  47890. owner->getMappings()->removeKeyPress (commandID, keyNum);
  47891. }
  47892. }
  47893. else
  47894. {
  47895. // + button pressed..
  47896. owner->assignNewKey (commandID, -1);
  47897. }
  47898. }
  47899. void fitToContent (const int h) throw()
  47900. {
  47901. if (keyNum < 0)
  47902. {
  47903. setSize (h, h);
  47904. }
  47905. else
  47906. {
  47907. Font f (h * 0.6f);
  47908. setSize (jlimit (h * 4, h * 8, 6 + f.getStringWidth (getName())), h);
  47909. }
  47910. }
  47911. juce_UseDebuggingNewOperator
  47912. private:
  47913. KeyMappingEditorComponent* const owner;
  47914. const CommandID commandID;
  47915. const int keyNum;
  47916. KeyMappingChangeButton (const KeyMappingChangeButton&);
  47917. const KeyMappingChangeButton& operator= (const KeyMappingChangeButton&);
  47918. };
  47919. class KeyMappingItemComponent : public Component
  47920. {
  47921. public:
  47922. KeyMappingItemComponent (KeyMappingEditorComponent* const owner_,
  47923. const CommandID commandID_)
  47924. : owner (owner_),
  47925. commandID (commandID_)
  47926. {
  47927. setInterceptsMouseClicks (false, true);
  47928. const bool isReadOnly = owner_->isCommandReadOnly (commandID);
  47929. const Array <KeyPress> keyPresses (owner_->getMappings()->getKeyPressesAssignedToCommand (commandID));
  47930. for (int i = 0; i < jmin (maxKeys, keyPresses.size()); ++i)
  47931. {
  47932. KeyMappingChangeButton* const kb
  47933. = new KeyMappingChangeButton (owner_, commandID,
  47934. owner_->getDescriptionForKeyPress (keyPresses.getReference (i)), i);
  47935. kb->setEnabled (! isReadOnly);
  47936. addAndMakeVisible (kb);
  47937. }
  47938. KeyMappingChangeButton* const kb
  47939. = new KeyMappingChangeButton (owner_, commandID, String::empty, -1);
  47940. addChildComponent (kb);
  47941. kb->setVisible (keyPresses.size() < maxKeys && ! isReadOnly);
  47942. }
  47943. ~KeyMappingItemComponent()
  47944. {
  47945. deleteAllChildren();
  47946. }
  47947. void paint (Graphics& g)
  47948. {
  47949. g.setFont (getHeight() * 0.7f);
  47950. g.setColour (findColour (KeyMappingEditorComponent::textColourId));
  47951. g.drawFittedText (owner->getMappings()->getCommandManager()->getNameOfCommand (commandID),
  47952. 4, 0, jmax (40, getChildComponent (0)->getX() - 5), getHeight(),
  47953. Justification::centredLeft, true);
  47954. }
  47955. void resized()
  47956. {
  47957. int x = getWidth() - 4;
  47958. for (int i = getNumChildComponents(); --i >= 0;)
  47959. {
  47960. KeyMappingChangeButton* const kb = dynamic_cast <KeyMappingChangeButton*> (getChildComponent (i));
  47961. kb->fitToContent (getHeight() - 2);
  47962. kb->setTopRightPosition (x, 1);
  47963. x -= kb->getWidth() + 5;
  47964. }
  47965. }
  47966. juce_UseDebuggingNewOperator
  47967. private:
  47968. KeyMappingEditorComponent* const owner;
  47969. const CommandID commandID;
  47970. KeyMappingItemComponent (const KeyMappingItemComponent&);
  47971. const KeyMappingItemComponent& operator= (const KeyMappingItemComponent&);
  47972. };
  47973. class KeyMappingTreeViewItem : public TreeViewItem
  47974. {
  47975. public:
  47976. KeyMappingTreeViewItem (KeyMappingEditorComponent* const owner_,
  47977. const CommandID commandID_)
  47978. : owner (owner_),
  47979. commandID (commandID_)
  47980. {
  47981. }
  47982. ~KeyMappingTreeViewItem()
  47983. {
  47984. }
  47985. const String getUniqueName() const { return String ((int) commandID) + "_id"; }
  47986. bool mightContainSubItems() { return false; }
  47987. int getItemHeight() const { return 20; }
  47988. Component* createItemComponent()
  47989. {
  47990. return new KeyMappingItemComponent (owner, commandID);
  47991. }
  47992. juce_UseDebuggingNewOperator
  47993. private:
  47994. KeyMappingEditorComponent* const owner;
  47995. const CommandID commandID;
  47996. KeyMappingTreeViewItem (const KeyMappingTreeViewItem&);
  47997. const KeyMappingTreeViewItem& operator= (const KeyMappingTreeViewItem&);
  47998. };
  47999. class KeyCategoryTreeViewItem : public TreeViewItem
  48000. {
  48001. public:
  48002. KeyCategoryTreeViewItem (KeyMappingEditorComponent* const owner_,
  48003. const String& name)
  48004. : owner (owner_),
  48005. categoryName (name)
  48006. {
  48007. }
  48008. ~KeyCategoryTreeViewItem()
  48009. {
  48010. }
  48011. const String getUniqueName() const { return categoryName + "_cat"; }
  48012. bool mightContainSubItems() { return true; }
  48013. int getItemHeight() const { return 28; }
  48014. void paintItem (Graphics& g, int width, int height)
  48015. {
  48016. g.setFont (height * 0.6f, Font::bold);
  48017. g.setColour (owner->findColour (KeyMappingEditorComponent::textColourId));
  48018. g.drawText (categoryName,
  48019. 2, 0, width - 2, height,
  48020. Justification::centredLeft, true);
  48021. }
  48022. void itemOpennessChanged (bool isNowOpen)
  48023. {
  48024. if (isNowOpen)
  48025. {
  48026. if (getNumSubItems() == 0)
  48027. {
  48028. Array <CommandID> commands (owner->getMappings()->getCommandManager()->getCommandsInCategory (categoryName));
  48029. for (int i = 0; i < commands.size(); ++i)
  48030. {
  48031. if (owner->shouldCommandBeIncluded (commands[i]))
  48032. addSubItem (new KeyMappingTreeViewItem (owner, commands[i]));
  48033. }
  48034. }
  48035. }
  48036. else
  48037. {
  48038. clearSubItems();
  48039. }
  48040. }
  48041. juce_UseDebuggingNewOperator
  48042. private:
  48043. KeyMappingEditorComponent* owner;
  48044. String categoryName;
  48045. KeyCategoryTreeViewItem (const KeyCategoryTreeViewItem&);
  48046. const KeyCategoryTreeViewItem& operator= (const KeyCategoryTreeViewItem&);
  48047. };
  48048. KeyMappingEditorComponent::KeyMappingEditorComponent (KeyPressMappingSet* const mappingManager,
  48049. const bool showResetToDefaultButton)
  48050. : mappings (mappingManager)
  48051. {
  48052. jassert (mappingManager != 0); // can't be null!
  48053. mappingManager->addChangeListener (this);
  48054. setLinesDrawnForSubItems (false);
  48055. resetButton = 0;
  48056. if (showResetToDefaultButton)
  48057. {
  48058. addAndMakeVisible (resetButton = new TextButton (TRANS("reset to defaults")));
  48059. resetButton->addButtonListener (this);
  48060. }
  48061. addAndMakeVisible (tree = new TreeView());
  48062. tree->setColour (TreeView::backgroundColourId, findColour (backgroundColourId));
  48063. tree->setRootItemVisible (false);
  48064. tree->setDefaultOpenness (true);
  48065. tree->setRootItem (this);
  48066. }
  48067. KeyMappingEditorComponent::~KeyMappingEditorComponent()
  48068. {
  48069. mappings->removeChangeListener (this);
  48070. deleteAllChildren();
  48071. }
  48072. bool KeyMappingEditorComponent::mightContainSubItems()
  48073. {
  48074. return true;
  48075. }
  48076. const String KeyMappingEditorComponent::getUniqueName() const
  48077. {
  48078. return T("keys");
  48079. }
  48080. void KeyMappingEditorComponent::setColours (const Colour& mainBackground,
  48081. const Colour& textColour)
  48082. {
  48083. setColour (backgroundColourId, mainBackground);
  48084. setColour (textColourId, textColour);
  48085. tree->setColour (TreeView::backgroundColourId, mainBackground);
  48086. }
  48087. void KeyMappingEditorComponent::parentHierarchyChanged()
  48088. {
  48089. changeListenerCallback (0);
  48090. }
  48091. void KeyMappingEditorComponent::resized()
  48092. {
  48093. int h = getHeight();
  48094. if (resetButton != 0)
  48095. {
  48096. const int buttonHeight = 20;
  48097. h -= buttonHeight + 8;
  48098. int x = getWidth() - 8;
  48099. const int y = h + 6;
  48100. resetButton->changeWidthToFitText (buttonHeight);
  48101. resetButton->setTopRightPosition (x, y);
  48102. }
  48103. tree->setBounds (0, 0, getWidth(), h);
  48104. }
  48105. void KeyMappingEditorComponent::buttonClicked (Button* button)
  48106. {
  48107. if (button == resetButton)
  48108. {
  48109. if (AlertWindow::showOkCancelBox (AlertWindow::QuestionIcon,
  48110. TRANS("Reset to defaults"),
  48111. TRANS("Are you sure you want to reset all the key-mappings to their default state?"),
  48112. TRANS("Reset")))
  48113. {
  48114. mappings->resetToDefaultMappings();
  48115. }
  48116. }
  48117. }
  48118. void KeyMappingEditorComponent::changeListenerCallback (void*)
  48119. {
  48120. ScopedPointer <XmlElement> openness (tree->getOpennessState (true));
  48121. clearSubItems();
  48122. const StringArray categories (mappings->getCommandManager()->getCommandCategories());
  48123. for (int i = 0; i < categories.size(); ++i)
  48124. {
  48125. const Array <CommandID> commands (mappings->getCommandManager()->getCommandsInCategory (categories[i]));
  48126. int count = 0;
  48127. for (int j = 0; j < commands.size(); ++j)
  48128. if (shouldCommandBeIncluded (commands[j]))
  48129. ++count;
  48130. if (count > 0)
  48131. addSubItem (new KeyCategoryTreeViewItem (this, categories[i]));
  48132. }
  48133. if (openness != 0)
  48134. tree->restoreOpennessState (*openness);
  48135. }
  48136. class KeyEntryWindow : public AlertWindow
  48137. {
  48138. public:
  48139. KeyEntryWindow (KeyMappingEditorComponent* const owner_)
  48140. : AlertWindow (TRANS("New key-mapping"),
  48141. TRANS("Please press a key combination now..."),
  48142. AlertWindow::NoIcon),
  48143. owner (owner_)
  48144. {
  48145. addButton (TRANS("ok"), 1);
  48146. addButton (TRANS("cancel"), 0);
  48147. // (avoid return + escape keys getting processed by the buttons..)
  48148. for (int i = getNumChildComponents(); --i >= 0;)
  48149. getChildComponent (i)->setWantsKeyboardFocus (false);
  48150. setWantsKeyboardFocus (true);
  48151. grabKeyboardFocus();
  48152. }
  48153. ~KeyEntryWindow()
  48154. {
  48155. }
  48156. bool keyPressed (const KeyPress& key)
  48157. {
  48158. lastPress = key;
  48159. String message (TRANS("Key: ") + owner->getDescriptionForKeyPress (key));
  48160. const CommandID previousCommand = owner->getMappings()->findCommandForKeyPress (key);
  48161. if (previousCommand != 0)
  48162. {
  48163. message << "\n\n"
  48164. << TRANS("(Currently assigned to \"")
  48165. << owner->getMappings()->getCommandManager()->getNameOfCommand (previousCommand)
  48166. << "\")";
  48167. }
  48168. setMessage (message);
  48169. return true;
  48170. }
  48171. bool keyStateChanged (const bool)
  48172. {
  48173. return true;
  48174. }
  48175. KeyPress lastPress;
  48176. juce_UseDebuggingNewOperator
  48177. private:
  48178. KeyMappingEditorComponent* owner;
  48179. KeyEntryWindow (const KeyEntryWindow&);
  48180. const KeyEntryWindow& operator= (const KeyEntryWindow&);
  48181. };
  48182. void KeyMappingEditorComponent::assignNewKey (const CommandID commandID, const int index)
  48183. {
  48184. KeyEntryWindow entryWindow (this);
  48185. if (entryWindow.runModalLoop() != 0)
  48186. {
  48187. entryWindow.setVisible (false);
  48188. if (entryWindow.lastPress.isValid())
  48189. {
  48190. const CommandID previousCommand = mappings->findCommandForKeyPress (entryWindow.lastPress);
  48191. if (previousCommand != 0)
  48192. {
  48193. if (! AlertWindow::showOkCancelBox (AlertWindow::WarningIcon,
  48194. TRANS("Change key-mapping"),
  48195. TRANS("This key is already assigned to the command \"")
  48196. + mappings->getCommandManager()->getNameOfCommand (previousCommand)
  48197. + TRANS("\"\n\nDo you want to re-assign it to this new command instead?"),
  48198. TRANS("re-assign"),
  48199. TRANS("cancel")))
  48200. {
  48201. return;
  48202. }
  48203. }
  48204. mappings->removeKeyPress (entryWindow.lastPress);
  48205. if (index >= 0)
  48206. mappings->removeKeyPress (commandID, index);
  48207. mappings->addKeyPress (commandID, entryWindow.lastPress, index);
  48208. }
  48209. }
  48210. }
  48211. bool KeyMappingEditorComponent::shouldCommandBeIncluded (const CommandID commandID)
  48212. {
  48213. const ApplicationCommandInfo* const ci = mappings->getCommandManager()->getCommandForID (commandID);
  48214. return (ci != 0) && ((ci->flags & ApplicationCommandInfo::hiddenFromKeyEditor) == 0);
  48215. }
  48216. bool KeyMappingEditorComponent::isCommandReadOnly (const CommandID commandID)
  48217. {
  48218. const ApplicationCommandInfo* const ci = mappings->getCommandManager()->getCommandForID (commandID);
  48219. return (ci != 0) && ((ci->flags & ApplicationCommandInfo::readOnlyInKeyEditor) != 0);
  48220. }
  48221. const String KeyMappingEditorComponent::getDescriptionForKeyPress (const KeyPress& key)
  48222. {
  48223. return key.getTextDescription();
  48224. }
  48225. END_JUCE_NAMESPACE
  48226. /*** End of inlined file: juce_KeyMappingEditorComponent.cpp ***/
  48227. /*** Start of inlined file: juce_KeyPress.cpp ***/
  48228. BEGIN_JUCE_NAMESPACE
  48229. KeyPress::KeyPress() throw()
  48230. : keyCode (0),
  48231. mods (0),
  48232. textCharacter (0)
  48233. {
  48234. }
  48235. KeyPress::KeyPress (const int keyCode_,
  48236. const ModifierKeys& mods_,
  48237. const juce_wchar textCharacter_) throw()
  48238. : keyCode (keyCode_),
  48239. mods (mods_),
  48240. textCharacter (textCharacter_)
  48241. {
  48242. }
  48243. KeyPress::KeyPress (const int keyCode_) throw()
  48244. : keyCode (keyCode_),
  48245. textCharacter (0)
  48246. {
  48247. }
  48248. KeyPress::KeyPress (const KeyPress& other) throw()
  48249. : keyCode (other.keyCode),
  48250. mods (other.mods),
  48251. textCharacter (other.textCharacter)
  48252. {
  48253. }
  48254. const KeyPress& KeyPress::operator= (const KeyPress& other) throw()
  48255. {
  48256. keyCode = other.keyCode;
  48257. mods = other.mods;
  48258. textCharacter = other.textCharacter;
  48259. return *this;
  48260. }
  48261. bool KeyPress::operator== (const KeyPress& other) const throw()
  48262. {
  48263. return mods.getRawFlags() == other.mods.getRawFlags()
  48264. && (textCharacter == other.textCharacter
  48265. || textCharacter == 0
  48266. || other.textCharacter == 0)
  48267. && (keyCode == other.keyCode
  48268. || (keyCode < 256
  48269. && other.keyCode < 256
  48270. && CharacterFunctions::toLowerCase ((tchar) keyCode)
  48271. == CharacterFunctions::toLowerCase ((tchar) other.keyCode)));
  48272. }
  48273. bool KeyPress::operator!= (const KeyPress& other) const throw()
  48274. {
  48275. return ! operator== (other);
  48276. }
  48277. bool KeyPress::isCurrentlyDown() const throw()
  48278. {
  48279. return isKeyCurrentlyDown (keyCode)
  48280. && (ModifierKeys::getCurrentModifiers().getRawFlags() & ModifierKeys::allKeyboardModifiers)
  48281. == (mods.getRawFlags() & ModifierKeys::allKeyboardModifiers);
  48282. }
  48283. struct KeyNameAndCode
  48284. {
  48285. const char* name;
  48286. int code;
  48287. };
  48288. static const KeyNameAndCode keyNameTranslations[] =
  48289. {
  48290. { "spacebar", KeyPress::spaceKey },
  48291. { "return", KeyPress::returnKey },
  48292. { "escape", KeyPress::escapeKey },
  48293. { "backspace", KeyPress::backspaceKey },
  48294. { "cursor left", KeyPress::leftKey },
  48295. { "cursor right", KeyPress::rightKey },
  48296. { "cursor up", KeyPress::upKey },
  48297. { "cursor down", KeyPress::downKey },
  48298. { "page up", KeyPress::pageUpKey },
  48299. { "page down", KeyPress::pageDownKey },
  48300. { "home", KeyPress::homeKey },
  48301. { "end", KeyPress::endKey },
  48302. { "delete", KeyPress::deleteKey },
  48303. { "insert", KeyPress::insertKey },
  48304. { "tab", KeyPress::tabKey },
  48305. { "play", KeyPress::playKey },
  48306. { "stop", KeyPress::stopKey },
  48307. { "fast forward", KeyPress::fastForwardKey },
  48308. { "rewind", KeyPress::rewindKey }
  48309. };
  48310. static const tchar* const numberPadPrefix = T("numpad ");
  48311. const KeyPress KeyPress::createFromDescription (const String& desc) throw()
  48312. {
  48313. int modifiers = 0;
  48314. if (desc.containsWholeWordIgnoreCase (T("ctrl"))
  48315. || desc.containsWholeWordIgnoreCase (T("control"))
  48316. || desc.containsWholeWordIgnoreCase (T("ctl")))
  48317. modifiers |= ModifierKeys::ctrlModifier;
  48318. if (desc.containsWholeWordIgnoreCase (T("shift"))
  48319. || desc.containsWholeWordIgnoreCase (T("shft")))
  48320. modifiers |= ModifierKeys::shiftModifier;
  48321. if (desc.containsWholeWordIgnoreCase (T("alt"))
  48322. || desc.containsWholeWordIgnoreCase (T("option")))
  48323. modifiers |= ModifierKeys::altModifier;
  48324. if (desc.containsWholeWordIgnoreCase (T("command"))
  48325. || desc.containsWholeWordIgnoreCase (T("cmd")))
  48326. modifiers |= ModifierKeys::commandModifier;
  48327. int key = 0;
  48328. for (int i = 0; i < numElementsInArray (keyNameTranslations); ++i)
  48329. {
  48330. if (desc.containsWholeWordIgnoreCase (String (keyNameTranslations[i].name)))
  48331. {
  48332. key = keyNameTranslations[i].code;
  48333. break;
  48334. }
  48335. }
  48336. if (key == 0)
  48337. {
  48338. // see if it's a numpad key..
  48339. if (desc.containsIgnoreCase (numberPadPrefix))
  48340. {
  48341. const tchar lastChar = desc.trimEnd().getLastCharacter();
  48342. if (lastChar >= T('0') && lastChar <= T('9'))
  48343. key = numberPad0 + lastChar - T('0');
  48344. else if (lastChar == T('+'))
  48345. key = numberPadAdd;
  48346. else if (lastChar == T('-'))
  48347. key = numberPadSubtract;
  48348. else if (lastChar == T('*'))
  48349. key = numberPadMultiply;
  48350. else if (lastChar == T('/'))
  48351. key = numberPadDivide;
  48352. else if (lastChar == T('.'))
  48353. key = numberPadDecimalPoint;
  48354. else if (lastChar == T('='))
  48355. key = numberPadEquals;
  48356. else if (desc.endsWith (T("separator")))
  48357. key = numberPadSeparator;
  48358. else if (desc.endsWith (T("delete")))
  48359. key = numberPadDelete;
  48360. }
  48361. if (key == 0)
  48362. {
  48363. // see if it's a function key..
  48364. for (int i = 1; i <= 12; ++i)
  48365. if (desc.containsWholeWordIgnoreCase (T("f") + String (i)))
  48366. key = F1Key + i - 1;
  48367. if (key == 0)
  48368. {
  48369. // give up and use the hex code..
  48370. const int hexCode = desc.fromFirstOccurrenceOf (T("#"), false, false)
  48371. .toLowerCase()
  48372. .retainCharacters (T("0123456789abcdef"))
  48373. .getHexValue32();
  48374. if (hexCode > 0)
  48375. key = hexCode;
  48376. else
  48377. key = CharacterFunctions::toUpperCase (desc.getLastCharacter());
  48378. }
  48379. }
  48380. }
  48381. return KeyPress (key, ModifierKeys (modifiers), 0);
  48382. }
  48383. const String KeyPress::getTextDescription() const throw()
  48384. {
  48385. String desc;
  48386. if (keyCode > 0)
  48387. {
  48388. // some keyboard layouts use a shift-key to get the slash, but in those cases, we
  48389. // want to store it as being a slash, not shift+whatever.
  48390. if (textCharacter == T('/'))
  48391. return "/";
  48392. if (mods.isCtrlDown())
  48393. desc << "ctrl + ";
  48394. if (mods.isShiftDown())
  48395. desc << "shift + ";
  48396. #if JUCE_MAC
  48397. // only do this on the mac, because on Windows ctrl and command are the same,
  48398. // and this would get confusing
  48399. if (mods.isCommandDown())
  48400. desc << "command + ";
  48401. if (mods.isAltDown())
  48402. desc << "option + ";
  48403. #else
  48404. if (mods.isAltDown())
  48405. desc << "alt + ";
  48406. #endif
  48407. for (int i = 0; i < numElementsInArray (keyNameTranslations); ++i)
  48408. if (keyCode == keyNameTranslations[i].code)
  48409. return desc + keyNameTranslations[i].name;
  48410. if (keyCode >= F1Key && keyCode <= F16Key)
  48411. desc << 'F' << (1 + keyCode - F1Key);
  48412. else if (keyCode >= numberPad0 && keyCode <= numberPad9)
  48413. desc << numberPadPrefix << (keyCode - numberPad0);
  48414. else if (keyCode >= 33 && keyCode < 176)
  48415. desc += CharacterFunctions::toUpperCase ((tchar) keyCode);
  48416. else if (keyCode == numberPadAdd)
  48417. desc << numberPadPrefix << '+';
  48418. else if (keyCode == numberPadSubtract)
  48419. desc << numberPadPrefix << '-';
  48420. else if (keyCode == numberPadMultiply)
  48421. desc << numberPadPrefix << '*';
  48422. else if (keyCode == numberPadDivide)
  48423. desc << numberPadPrefix << '/';
  48424. else if (keyCode == numberPadSeparator)
  48425. desc << numberPadPrefix << "separator";
  48426. else if (keyCode == numberPadDecimalPoint)
  48427. desc << numberPadPrefix << '.';
  48428. else if (keyCode == numberPadDelete)
  48429. desc << numberPadPrefix << "delete";
  48430. else
  48431. desc << '#' << String::toHexString (keyCode);
  48432. }
  48433. return desc;
  48434. }
  48435. END_JUCE_NAMESPACE
  48436. /*** End of inlined file: juce_KeyPress.cpp ***/
  48437. /*** Start of inlined file: juce_KeyPressMappingSet.cpp ***/
  48438. BEGIN_JUCE_NAMESPACE
  48439. KeyPressMappingSet::KeyPressMappingSet (ApplicationCommandManager* const commandManager_) throw()
  48440. : commandManager (commandManager_)
  48441. {
  48442. // A manager is needed to get the descriptions of commands, and will be called when
  48443. // a command is invoked. So you can't leave this null..
  48444. jassert (commandManager_ != 0);
  48445. Desktop::getInstance().addFocusChangeListener (this);
  48446. }
  48447. KeyPressMappingSet::KeyPressMappingSet (const KeyPressMappingSet& other) throw()
  48448. : commandManager (other.commandManager)
  48449. {
  48450. Desktop::getInstance().addFocusChangeListener (this);
  48451. }
  48452. KeyPressMappingSet::~KeyPressMappingSet()
  48453. {
  48454. Desktop::getInstance().removeFocusChangeListener (this);
  48455. }
  48456. const Array <KeyPress> KeyPressMappingSet::getKeyPressesAssignedToCommand (const CommandID commandID) const throw()
  48457. {
  48458. for (int i = 0; i < mappings.size(); ++i)
  48459. if (mappings.getUnchecked(i)->commandID == commandID)
  48460. return mappings.getUnchecked (i)->keypresses;
  48461. return Array <KeyPress> ();
  48462. }
  48463. void KeyPressMappingSet::addKeyPress (const CommandID commandID,
  48464. const KeyPress& newKeyPress,
  48465. int insertIndex) throw()
  48466. {
  48467. // If you specify an upper-case letter but no shift key, how is the user supposed to press it!?
  48468. // Stick to lower-case letters when defining a keypress, to avoid ambiguity.
  48469. jassert (! (CharacterFunctions::isUpperCase (newKeyPress.getTextCharacter())
  48470. && ! newKeyPress.getModifiers().isShiftDown()));
  48471. if (findCommandForKeyPress (newKeyPress) != commandID)
  48472. {
  48473. removeKeyPress (newKeyPress);
  48474. if (newKeyPress.isValid())
  48475. {
  48476. for (int i = mappings.size(); --i >= 0;)
  48477. {
  48478. if (mappings.getUnchecked(i)->commandID == commandID)
  48479. {
  48480. mappings.getUnchecked(i)->keypresses.insert (insertIndex, newKeyPress);
  48481. sendChangeMessage (this);
  48482. return;
  48483. }
  48484. }
  48485. const ApplicationCommandInfo* const ci = commandManager->getCommandForID (commandID);
  48486. if (ci != 0)
  48487. {
  48488. CommandMapping* const cm = new CommandMapping();
  48489. cm->commandID = commandID;
  48490. cm->keypresses.add (newKeyPress);
  48491. cm->wantsKeyUpDownCallbacks = (ci->flags & ApplicationCommandInfo::wantsKeyUpDownCallbacks) != 0;
  48492. mappings.add (cm);
  48493. sendChangeMessage (this);
  48494. }
  48495. }
  48496. }
  48497. }
  48498. void KeyPressMappingSet::resetToDefaultMappings() throw()
  48499. {
  48500. mappings.clear();
  48501. for (int i = 0; i < commandManager->getNumCommands(); ++i)
  48502. {
  48503. const ApplicationCommandInfo* const ci = commandManager->getCommandForIndex (i);
  48504. for (int j = 0; j < ci->defaultKeypresses.size(); ++j)
  48505. {
  48506. addKeyPress (ci->commandID,
  48507. ci->defaultKeypresses.getReference (j));
  48508. }
  48509. }
  48510. sendChangeMessage (this);
  48511. }
  48512. void KeyPressMappingSet::resetToDefaultMapping (const CommandID commandID) throw()
  48513. {
  48514. clearAllKeyPresses (commandID);
  48515. const ApplicationCommandInfo* const ci = commandManager->getCommandForID (commandID);
  48516. for (int j = 0; j < ci->defaultKeypresses.size(); ++j)
  48517. {
  48518. addKeyPress (ci->commandID,
  48519. ci->defaultKeypresses.getReference (j));
  48520. }
  48521. }
  48522. void KeyPressMappingSet::clearAllKeyPresses() throw()
  48523. {
  48524. if (mappings.size() > 0)
  48525. {
  48526. sendChangeMessage (this);
  48527. mappings.clear();
  48528. }
  48529. }
  48530. void KeyPressMappingSet::clearAllKeyPresses (const CommandID commandID) throw()
  48531. {
  48532. for (int i = mappings.size(); --i >= 0;)
  48533. {
  48534. if (mappings.getUnchecked(i)->commandID == commandID)
  48535. {
  48536. mappings.remove (i);
  48537. sendChangeMessage (this);
  48538. }
  48539. }
  48540. }
  48541. void KeyPressMappingSet::removeKeyPress (const KeyPress& keypress) throw()
  48542. {
  48543. if (keypress.isValid())
  48544. {
  48545. for (int i = mappings.size(); --i >= 0;)
  48546. {
  48547. CommandMapping* const cm = mappings.getUnchecked(i);
  48548. for (int j = cm->keypresses.size(); --j >= 0;)
  48549. {
  48550. if (keypress == cm->keypresses [j])
  48551. {
  48552. cm->keypresses.remove (j);
  48553. sendChangeMessage (this);
  48554. }
  48555. }
  48556. }
  48557. }
  48558. }
  48559. void KeyPressMappingSet::removeKeyPress (const CommandID commandID,
  48560. const int keyPressIndex) throw()
  48561. {
  48562. for (int i = mappings.size(); --i >= 0;)
  48563. {
  48564. if (mappings.getUnchecked(i)->commandID == commandID)
  48565. {
  48566. mappings.getUnchecked(i)->keypresses.remove (keyPressIndex);
  48567. sendChangeMessage (this);
  48568. break;
  48569. }
  48570. }
  48571. }
  48572. CommandID KeyPressMappingSet::findCommandForKeyPress (const KeyPress& keyPress) const throw()
  48573. {
  48574. for (int i = 0; i < mappings.size(); ++i)
  48575. if (mappings.getUnchecked(i)->keypresses.contains (keyPress))
  48576. return mappings.getUnchecked(i)->commandID;
  48577. return 0;
  48578. }
  48579. bool KeyPressMappingSet::containsMapping (const CommandID commandID,
  48580. const KeyPress& keyPress) const throw()
  48581. {
  48582. for (int i = mappings.size(); --i >= 0;)
  48583. if (mappings.getUnchecked(i)->commandID == commandID)
  48584. return mappings.getUnchecked(i)->keypresses.contains (keyPress);
  48585. return false;
  48586. }
  48587. void KeyPressMappingSet::invokeCommand (const CommandID commandID,
  48588. const KeyPress& key,
  48589. const bool isKeyDown,
  48590. const int millisecsSinceKeyPressed,
  48591. Component* const originatingComponent) const
  48592. {
  48593. ApplicationCommandTarget::InvocationInfo info (commandID);
  48594. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromKeyPress;
  48595. info.isKeyDown = isKeyDown;
  48596. info.keyPress = key;
  48597. info.millisecsSinceKeyPressed = millisecsSinceKeyPressed;
  48598. info.originatingComponent = originatingComponent;
  48599. commandManager->invoke (info, false);
  48600. }
  48601. bool KeyPressMappingSet::restoreFromXml (const XmlElement& xmlVersion)
  48602. {
  48603. if (xmlVersion.hasTagName (T("KEYMAPPINGS")))
  48604. {
  48605. if (xmlVersion.getBoolAttribute (T("basedOnDefaults"), true))
  48606. {
  48607. // if the XML was created as a set of differences from the default mappings,
  48608. // (i.e. by calling createXml (true)), then we need to first restore the defaults.
  48609. resetToDefaultMappings();
  48610. }
  48611. else
  48612. {
  48613. // if the XML was created calling createXml (false), then we need to clear all
  48614. // the keys and treat the xml as describing the entire set of mappings.
  48615. clearAllKeyPresses();
  48616. }
  48617. forEachXmlChildElement (xmlVersion, map)
  48618. {
  48619. const CommandID commandId = map->getStringAttribute (T("commandId")).getHexValue32();
  48620. if (commandId != 0)
  48621. {
  48622. const KeyPress key (KeyPress::createFromDescription (map->getStringAttribute (T("key"))));
  48623. if (map->hasTagName (T("MAPPING")))
  48624. {
  48625. addKeyPress (commandId, key);
  48626. }
  48627. else if (map->hasTagName (T("UNMAPPING")))
  48628. {
  48629. if (containsMapping (commandId, key))
  48630. removeKeyPress (key);
  48631. }
  48632. }
  48633. }
  48634. return true;
  48635. }
  48636. return false;
  48637. }
  48638. XmlElement* KeyPressMappingSet::createXml (const bool saveDifferencesFromDefaultSet) const
  48639. {
  48640. ScopedPointer <KeyPressMappingSet> defaultSet;
  48641. if (saveDifferencesFromDefaultSet)
  48642. {
  48643. defaultSet = new KeyPressMappingSet (commandManager);
  48644. defaultSet->resetToDefaultMappings();
  48645. }
  48646. XmlElement* const doc = new XmlElement (T("KEYMAPPINGS"));
  48647. doc->setAttribute (T("basedOnDefaults"), saveDifferencesFromDefaultSet);
  48648. int i;
  48649. for (i = 0; i < mappings.size(); ++i)
  48650. {
  48651. const CommandMapping* const cm = mappings.getUnchecked(i);
  48652. for (int j = 0; j < cm->keypresses.size(); ++j)
  48653. {
  48654. if (defaultSet == 0
  48655. || ! defaultSet->containsMapping (cm->commandID, cm->keypresses.getReference (j)))
  48656. {
  48657. XmlElement* const map = doc->createNewChildElement ("MAPPING");
  48658. map->setAttribute (T("commandId"), String::toHexString ((int) cm->commandID));
  48659. map->setAttribute (T("description"), commandManager->getDescriptionOfCommand (cm->commandID));
  48660. map->setAttribute (T("key"), cm->keypresses.getReference (j).getTextDescription());
  48661. }
  48662. }
  48663. }
  48664. if (defaultSet != 0)
  48665. {
  48666. for (i = 0; i < defaultSet->mappings.size(); ++i)
  48667. {
  48668. const CommandMapping* const cm = defaultSet->mappings.getUnchecked(i);
  48669. for (int j = 0; j < cm->keypresses.size(); ++j)
  48670. {
  48671. if (! containsMapping (cm->commandID, cm->keypresses.getReference (j)))
  48672. {
  48673. XmlElement* const map = doc->createNewChildElement ("UNMAPPING");
  48674. map->setAttribute (T("commandId"), String::toHexString ((int) cm->commandID));
  48675. map->setAttribute (T("description"), commandManager->getDescriptionOfCommand (cm->commandID));
  48676. map->setAttribute (T("key"), cm->keypresses.getReference (j).getTextDescription());
  48677. }
  48678. }
  48679. }
  48680. }
  48681. return doc;
  48682. }
  48683. bool KeyPressMappingSet::keyPressed (const KeyPress& key,
  48684. Component* originatingComponent)
  48685. {
  48686. bool used = false;
  48687. const CommandID commandID = findCommandForKeyPress (key);
  48688. const ApplicationCommandInfo* const ci = commandManager->getCommandForID (commandID);
  48689. if (ci != 0
  48690. && (ci->flags & ApplicationCommandInfo::wantsKeyUpDownCallbacks) == 0)
  48691. {
  48692. ApplicationCommandInfo info (0);
  48693. if (commandManager->getTargetForCommand (commandID, info) != 0
  48694. && (info.flags & ApplicationCommandInfo::isDisabled) == 0)
  48695. {
  48696. invokeCommand (commandID, key, true, 0, originatingComponent);
  48697. used = true;
  48698. }
  48699. else
  48700. {
  48701. if (originatingComponent != 0)
  48702. originatingComponent->getLookAndFeel().playAlertSound();
  48703. }
  48704. }
  48705. return used;
  48706. }
  48707. bool KeyPressMappingSet::keyStateChanged (const bool /*isKeyDown*/, Component* originatingComponent)
  48708. {
  48709. bool used = false;
  48710. const uint32 now = Time::getMillisecondCounter();
  48711. for (int i = mappings.size(); --i >= 0;)
  48712. {
  48713. CommandMapping* const cm = mappings.getUnchecked(i);
  48714. if (cm->wantsKeyUpDownCallbacks)
  48715. {
  48716. for (int j = cm->keypresses.size(); --j >= 0;)
  48717. {
  48718. const KeyPress key (cm->keypresses.getReference (j));
  48719. const bool isDown = key.isCurrentlyDown();
  48720. int keyPressEntryIndex = 0;
  48721. bool wasDown = false;
  48722. for (int k = keysDown.size(); --k >= 0;)
  48723. {
  48724. if (key == keysDown.getUnchecked(k)->key)
  48725. {
  48726. keyPressEntryIndex = k;
  48727. wasDown = true;
  48728. used = true;
  48729. break;
  48730. }
  48731. }
  48732. if (isDown != wasDown)
  48733. {
  48734. int millisecs = 0;
  48735. if (isDown)
  48736. {
  48737. KeyPressTime* const k = new KeyPressTime();
  48738. k->key = key;
  48739. k->timeWhenPressed = now;
  48740. keysDown.add (k);
  48741. }
  48742. else
  48743. {
  48744. const uint32 pressTime = keysDown.getUnchecked (keyPressEntryIndex)->timeWhenPressed;
  48745. if (now > pressTime)
  48746. millisecs = now - pressTime;
  48747. keysDown.remove (keyPressEntryIndex);
  48748. }
  48749. invokeCommand (cm->commandID, key, isDown, millisecs, originatingComponent);
  48750. used = true;
  48751. }
  48752. }
  48753. }
  48754. }
  48755. return used;
  48756. }
  48757. void KeyPressMappingSet::globalFocusChanged (Component* focusedComponent)
  48758. {
  48759. if (focusedComponent != 0)
  48760. focusedComponent->keyStateChanged (false);
  48761. }
  48762. END_JUCE_NAMESPACE
  48763. /*** End of inlined file: juce_KeyPressMappingSet.cpp ***/
  48764. /*** Start of inlined file: juce_ModifierKeys.cpp ***/
  48765. BEGIN_JUCE_NAMESPACE
  48766. ModifierKeys::ModifierKeys (const int flags_) throw()
  48767. : flags (flags_)
  48768. {
  48769. }
  48770. ModifierKeys::ModifierKeys (const ModifierKeys& other) throw()
  48771. : flags (other.flags)
  48772. {
  48773. }
  48774. const ModifierKeys& ModifierKeys::operator= (const ModifierKeys& other) throw()
  48775. {
  48776. flags = other.flags;
  48777. return *this;
  48778. }
  48779. int ModifierKeys::currentModifierFlags = 0;
  48780. const ModifierKeys ModifierKeys::getCurrentModifiers() throw()
  48781. {
  48782. return ModifierKeys (currentModifierFlags);
  48783. }
  48784. int ModifierKeys::getNumMouseButtonsDown() const throw()
  48785. {
  48786. int num = 0;
  48787. if (isLeftButtonDown()) ++num;
  48788. if (isRightButtonDown()) ++num;
  48789. if (isMiddleButtonDown()) ++num;
  48790. return num;
  48791. }
  48792. END_JUCE_NAMESPACE
  48793. /*** End of inlined file: juce_ModifierKeys.cpp ***/
  48794. /*** Start of inlined file: juce_ComponentAnimator.cpp ***/
  48795. BEGIN_JUCE_NAMESPACE
  48796. struct AnimationTask
  48797. {
  48798. AnimationTask (Component* const comp)
  48799. : component (comp),
  48800. watcher (comp)
  48801. {
  48802. }
  48803. Component* component;
  48804. ComponentDeletionWatcher watcher;
  48805. Rectangle<int> destination;
  48806. int msElapsed, msTotal;
  48807. double startSpeed, midSpeed, endSpeed, lastProgress;
  48808. double left, top, right, bottom;
  48809. bool useTimeslice (const int elapsed)
  48810. {
  48811. if (watcher.hasBeenDeleted())
  48812. return false;
  48813. msElapsed += elapsed;
  48814. double newProgress = msElapsed / (double) msTotal;
  48815. if (newProgress >= 0 && newProgress < 1.0)
  48816. {
  48817. newProgress = timeToDistance (newProgress);
  48818. const double delta = (newProgress - lastProgress) / (1.0 - lastProgress);
  48819. jassert (newProgress >= lastProgress);
  48820. lastProgress = newProgress;
  48821. left += (destination.getX() - left) * delta;
  48822. top += (destination.getY() - top) * delta;
  48823. right += (destination.getRight() - right) * delta;
  48824. bottom += (destination.getBottom() - bottom) * delta;
  48825. if (delta < 1.0)
  48826. {
  48827. const Rectangle<int> newBounds (roundToInt (left),
  48828. roundToInt (top),
  48829. roundToInt (right - left),
  48830. roundToInt (bottom - top));
  48831. if (newBounds != destination)
  48832. {
  48833. component->setBounds (newBounds);
  48834. return true;
  48835. }
  48836. }
  48837. }
  48838. component->setBounds (destination);
  48839. return false;
  48840. }
  48841. void moveToFinalDestination()
  48842. {
  48843. if (! watcher.hasBeenDeleted())
  48844. component->setBounds (destination);
  48845. }
  48846. private:
  48847. inline double timeToDistance (const double time) const
  48848. {
  48849. return (time < 0.5) ? time * (startSpeed + time * (midSpeed - startSpeed))
  48850. : 0.5 * (startSpeed + 0.5 * (midSpeed - startSpeed))
  48851. + (time - 0.5) * (midSpeed + (time - 0.5) * (endSpeed - midSpeed));
  48852. }
  48853. };
  48854. ComponentAnimator::ComponentAnimator()
  48855. : lastTime (0)
  48856. {
  48857. }
  48858. ComponentAnimator::~ComponentAnimator()
  48859. {
  48860. cancelAllAnimations (false);
  48861. jassert (tasks.size() == 0);
  48862. }
  48863. void* ComponentAnimator::findTaskFor (Component* const component) const
  48864. {
  48865. for (int i = tasks.size(); --i >= 0;)
  48866. if (component == ((AnimationTask*) tasks.getUnchecked(i))->component)
  48867. return tasks.getUnchecked(i);
  48868. return 0;
  48869. }
  48870. void ComponentAnimator::animateComponent (Component* const component,
  48871. const Rectangle<int>& finalPosition,
  48872. const int millisecondsToSpendMoving,
  48873. const double startSpeed,
  48874. const double endSpeed)
  48875. {
  48876. if (component != 0)
  48877. {
  48878. AnimationTask* at = (AnimationTask*) findTaskFor (component);
  48879. if (at == 0)
  48880. {
  48881. at = new AnimationTask (component);
  48882. tasks.add (at);
  48883. sendChangeMessage (this);
  48884. }
  48885. at->msElapsed = 0;
  48886. at->lastProgress = 0;
  48887. at->msTotal = jmax (1, millisecondsToSpendMoving);
  48888. at->destination = finalPosition;
  48889. // the speeds must be 0 or greater!
  48890. jassert (startSpeed >= 0 && endSpeed >= 0)
  48891. const double invTotalDistance = 4.0 / (startSpeed + endSpeed + 2.0);
  48892. at->startSpeed = jmax (0.0, startSpeed * invTotalDistance);
  48893. at->midSpeed = invTotalDistance;
  48894. at->endSpeed = jmax (0.0, endSpeed * invTotalDistance);
  48895. at->left = component->getX();
  48896. at->top = component->getY();
  48897. at->right = component->getRight();
  48898. at->bottom = component->getBottom();
  48899. if (! isTimerRunning())
  48900. {
  48901. lastTime = Time::getMillisecondCounter();
  48902. startTimer (1000 / 50);
  48903. }
  48904. }
  48905. }
  48906. void ComponentAnimator::cancelAllAnimations (const bool moveComponentsToTheirFinalPositions)
  48907. {
  48908. for (int i = tasks.size(); --i >= 0;)
  48909. {
  48910. AnimationTask* const at = (AnimationTask*) tasks.getUnchecked(i);
  48911. if (moveComponentsToTheirFinalPositions)
  48912. at->moveToFinalDestination();
  48913. delete at;
  48914. tasks.remove (i);
  48915. sendChangeMessage (this);
  48916. }
  48917. }
  48918. void ComponentAnimator::cancelAnimation (Component* const component,
  48919. const bool moveComponentToItsFinalPosition)
  48920. {
  48921. AnimationTask* const at = (AnimationTask*) findTaskFor (component);
  48922. if (at != 0)
  48923. {
  48924. if (moveComponentToItsFinalPosition)
  48925. at->moveToFinalDestination();
  48926. tasks.removeValue (at);
  48927. delete at;
  48928. sendChangeMessage (this);
  48929. }
  48930. }
  48931. const Rectangle<int> ComponentAnimator::getComponentDestination (Component* const component)
  48932. {
  48933. AnimationTask* const at = (AnimationTask*) findTaskFor (component);
  48934. if (at != 0)
  48935. return at->destination;
  48936. else if (component != 0)
  48937. return component->getBounds();
  48938. return Rectangle<int>();
  48939. }
  48940. bool ComponentAnimator::isAnimating (Component* component) const
  48941. {
  48942. return findTaskFor (component) != 0;
  48943. }
  48944. void ComponentAnimator::timerCallback()
  48945. {
  48946. const uint32 timeNow = Time::getMillisecondCounter();
  48947. if (lastTime == 0 || lastTime == timeNow)
  48948. lastTime = timeNow;
  48949. const int elapsed = timeNow - lastTime;
  48950. for (int i = tasks.size(); --i >= 0;)
  48951. {
  48952. AnimationTask* const at = (AnimationTask*) tasks.getUnchecked(i);
  48953. if (! at->useTimeslice (elapsed))
  48954. {
  48955. tasks.remove (i);
  48956. delete at;
  48957. sendChangeMessage (this);
  48958. }
  48959. }
  48960. lastTime = timeNow;
  48961. if (tasks.size() == 0)
  48962. stopTimer();
  48963. }
  48964. END_JUCE_NAMESPACE
  48965. /*** End of inlined file: juce_ComponentAnimator.cpp ***/
  48966. /*** Start of inlined file: juce_ComponentBoundsConstrainer.cpp ***/
  48967. BEGIN_JUCE_NAMESPACE
  48968. ComponentBoundsConstrainer::ComponentBoundsConstrainer() throw()
  48969. : minW (0),
  48970. maxW (0x3fffffff),
  48971. minH (0),
  48972. maxH (0x3fffffff),
  48973. minOffTop (0),
  48974. minOffLeft (0),
  48975. minOffBottom (0),
  48976. minOffRight (0),
  48977. aspectRatio (0.0)
  48978. {
  48979. }
  48980. ComponentBoundsConstrainer::~ComponentBoundsConstrainer()
  48981. {
  48982. }
  48983. void ComponentBoundsConstrainer::setMinimumWidth (const int minimumWidth) throw()
  48984. {
  48985. minW = minimumWidth;
  48986. }
  48987. void ComponentBoundsConstrainer::setMaximumWidth (const int maximumWidth) throw()
  48988. {
  48989. maxW = maximumWidth;
  48990. }
  48991. void ComponentBoundsConstrainer::setMinimumHeight (const int minimumHeight) throw()
  48992. {
  48993. minH = minimumHeight;
  48994. }
  48995. void ComponentBoundsConstrainer::setMaximumHeight (const int maximumHeight) throw()
  48996. {
  48997. maxH = maximumHeight;
  48998. }
  48999. void ComponentBoundsConstrainer::setMinimumSize (const int minimumWidth, const int minimumHeight) throw()
  49000. {
  49001. jassert (maxW >= minimumWidth);
  49002. jassert (maxH >= minimumHeight);
  49003. jassert (minimumWidth > 0 && minimumHeight > 0);
  49004. minW = minimumWidth;
  49005. minH = minimumHeight;
  49006. if (minW > maxW)
  49007. maxW = minW;
  49008. if (minH > maxH)
  49009. maxH = minH;
  49010. }
  49011. void ComponentBoundsConstrainer::setMaximumSize (const int maximumWidth, const int maximumHeight) throw()
  49012. {
  49013. jassert (maximumWidth >= minW);
  49014. jassert (maximumHeight >= minH);
  49015. jassert (maximumWidth > 0 && maximumHeight > 0);
  49016. maxW = jmax (minW, maximumWidth);
  49017. maxH = jmax (minH, maximumHeight);
  49018. }
  49019. void ComponentBoundsConstrainer::setSizeLimits (const int minimumWidth,
  49020. const int minimumHeight,
  49021. const int maximumWidth,
  49022. const int maximumHeight) throw()
  49023. {
  49024. jassert (maximumWidth >= minimumWidth);
  49025. jassert (maximumHeight >= minimumHeight);
  49026. jassert (maximumWidth > 0 && maximumHeight > 0);
  49027. jassert (minimumWidth > 0 && minimumHeight > 0);
  49028. minW = jmax (0, minimumWidth);
  49029. minH = jmax (0, minimumHeight);
  49030. maxW = jmax (minW, maximumWidth);
  49031. maxH = jmax (minH, maximumHeight);
  49032. }
  49033. void ComponentBoundsConstrainer::setMinimumOnscreenAmounts (const int minimumWhenOffTheTop,
  49034. const int minimumWhenOffTheLeft,
  49035. const int minimumWhenOffTheBottom,
  49036. const int minimumWhenOffTheRight) throw()
  49037. {
  49038. minOffTop = minimumWhenOffTheTop;
  49039. minOffLeft = minimumWhenOffTheLeft;
  49040. minOffBottom = minimumWhenOffTheBottom;
  49041. minOffRight = minimumWhenOffTheRight;
  49042. }
  49043. void ComponentBoundsConstrainer::setFixedAspectRatio (const double widthOverHeight) throw()
  49044. {
  49045. aspectRatio = jmax (0.0, widthOverHeight);
  49046. }
  49047. double ComponentBoundsConstrainer::getFixedAspectRatio() const throw()
  49048. {
  49049. return aspectRatio;
  49050. }
  49051. void ComponentBoundsConstrainer::setBoundsForComponent (Component* const component,
  49052. const Rectangle<int>& targetBounds,
  49053. const bool isStretchingTop,
  49054. const bool isStretchingLeft,
  49055. const bool isStretchingBottom,
  49056. const bool isStretchingRight)
  49057. {
  49058. jassert (component != 0);
  49059. Rectangle<int> limits, bounds (targetBounds);
  49060. BorderSize border;
  49061. Component* const parent = component->getParentComponent();
  49062. if (parent == 0)
  49063. {
  49064. ComponentPeer* peer = component->getPeer();
  49065. if (peer != 0)
  49066. border = peer->getFrameSize();
  49067. limits = Desktop::getInstance().getMonitorAreaContaining (bounds.getCentreX(),
  49068. bounds.getCentreY());
  49069. }
  49070. else
  49071. {
  49072. limits.setSize (parent->getWidth(), parent->getHeight());
  49073. }
  49074. border.addTo (bounds);
  49075. checkBounds (bounds,
  49076. border.addedTo (component->getBounds()), limits,
  49077. isStretchingTop, isStretchingLeft,
  49078. isStretchingBottom, isStretchingRight);
  49079. border.subtractFrom (bounds);
  49080. applyBoundsToComponent (component, bounds);
  49081. }
  49082. void ComponentBoundsConstrainer::checkComponentBounds (Component* component)
  49083. {
  49084. setBoundsForComponent (component, component->getBounds(),
  49085. false, false, false, false);
  49086. }
  49087. void ComponentBoundsConstrainer::applyBoundsToComponent (Component* component,
  49088. const Rectangle<int>& bounds)
  49089. {
  49090. component->setBounds (bounds);
  49091. }
  49092. void ComponentBoundsConstrainer::resizeStart()
  49093. {
  49094. }
  49095. void ComponentBoundsConstrainer::resizeEnd()
  49096. {
  49097. }
  49098. void ComponentBoundsConstrainer::checkBounds (Rectangle<int>& bounds,
  49099. const Rectangle<int>& old,
  49100. const Rectangle<int>& limits,
  49101. const bool isStretchingTop,
  49102. const bool isStretchingLeft,
  49103. const bool isStretchingBottom,
  49104. const bool isStretchingRight)
  49105. {
  49106. int x = bounds.getX();
  49107. int y = bounds.getY();
  49108. int w = bounds.getWidth();
  49109. int h = bounds.getHeight();
  49110. // constrain the size if it's being stretched..
  49111. if (isStretchingLeft)
  49112. {
  49113. x = jlimit (old.getRight() - maxW, old.getRight() - minW, x);
  49114. w = old.getRight() - x;
  49115. }
  49116. if (isStretchingRight)
  49117. {
  49118. w = jlimit (minW, maxW, w);
  49119. }
  49120. if (isStretchingTop)
  49121. {
  49122. y = jlimit (old.getBottom() - maxH, old.getBottom() - minH, y);
  49123. h = old.getBottom() - y;
  49124. }
  49125. if (isStretchingBottom)
  49126. {
  49127. h = jlimit (minH, maxH, h);
  49128. }
  49129. // constrain the aspect ratio if one has been specified..
  49130. if (aspectRatio > 0.0 && w > 0 && h > 0)
  49131. {
  49132. bool adjustWidth;
  49133. if ((isStretchingTop || isStretchingBottom) && ! (isStretchingLeft || isStretchingRight))
  49134. {
  49135. adjustWidth = true;
  49136. }
  49137. else if ((isStretchingLeft || isStretchingRight) && ! (isStretchingTop || isStretchingBottom))
  49138. {
  49139. adjustWidth = false;
  49140. }
  49141. else
  49142. {
  49143. const double oldRatio = (old.getHeight() > 0) ? fabs (old.getWidth() / (double) old.getHeight()) : 0.0;
  49144. const double newRatio = fabs (w / (double) h);
  49145. adjustWidth = (oldRatio > newRatio);
  49146. }
  49147. if (adjustWidth)
  49148. {
  49149. w = roundToInt (h * aspectRatio);
  49150. if (w > maxW || w < minW)
  49151. {
  49152. w = jlimit (minW, maxW, w);
  49153. h = roundToInt (w / aspectRatio);
  49154. }
  49155. }
  49156. else
  49157. {
  49158. h = roundToInt (w / aspectRatio);
  49159. if (h > maxH || h < minH)
  49160. {
  49161. h = jlimit (minH, maxH, h);
  49162. w = roundToInt (h * aspectRatio);
  49163. }
  49164. }
  49165. if ((isStretchingTop || isStretchingBottom) && ! (isStretchingLeft || isStretchingRight))
  49166. {
  49167. x = old.getX() + (old.getWidth() - w) / 2;
  49168. }
  49169. else if ((isStretchingLeft || isStretchingRight) && ! (isStretchingTop || isStretchingBottom))
  49170. {
  49171. y = old.getY() + (old.getHeight() - h) / 2;
  49172. }
  49173. else
  49174. {
  49175. if (isStretchingLeft)
  49176. x = old.getRight() - w;
  49177. if (isStretchingTop)
  49178. y = old.getBottom() - h;
  49179. }
  49180. }
  49181. // ...and constrain the position if limits have been set for that.
  49182. if (minOffTop > 0 || minOffLeft > 0 || minOffBottom > 0 || minOffRight > 0)
  49183. {
  49184. if (minOffTop > 0)
  49185. {
  49186. const int limit = limits.getY() + jmin (minOffTop - h, 0);
  49187. if (y < limit)
  49188. {
  49189. if (isStretchingTop)
  49190. h -= (limit - y);
  49191. y = limit;
  49192. }
  49193. }
  49194. if (minOffLeft > 0)
  49195. {
  49196. const int limit = limits.getX() + jmin (minOffLeft - w, 0);
  49197. if (x < limit)
  49198. {
  49199. if (isStretchingLeft)
  49200. w -= (limit - x);
  49201. x = limit;
  49202. }
  49203. }
  49204. if (minOffBottom > 0)
  49205. {
  49206. const int limit = limits.getBottom() - jmin (minOffBottom, h);
  49207. if (y > limit)
  49208. {
  49209. if (isStretchingBottom)
  49210. h += (limit - y);
  49211. else
  49212. y = limit;
  49213. }
  49214. }
  49215. if (minOffRight > 0)
  49216. {
  49217. const int limit = limits.getRight() - jmin (minOffRight, w);
  49218. if (x > limit)
  49219. {
  49220. if (isStretchingRight)
  49221. w += (limit - x);
  49222. else
  49223. x = limit;
  49224. }
  49225. }
  49226. }
  49227. jassert (w >= 0 && h >= 0);
  49228. bounds = Rectangle<int> (x, y, w, h);
  49229. }
  49230. END_JUCE_NAMESPACE
  49231. /*** End of inlined file: juce_ComponentBoundsConstrainer.cpp ***/
  49232. /*** Start of inlined file: juce_ComponentMovementWatcher.cpp ***/
  49233. BEGIN_JUCE_NAMESPACE
  49234. ComponentMovementWatcher::ComponentMovementWatcher (Component* const component_)
  49235. : component (component_),
  49236. lastPeer (0),
  49237. reentrant (false)
  49238. {
  49239. jassert (component != 0); // can't use this with a null pointer..
  49240. #ifdef JUCE_DEBUG
  49241. deletionWatcher = new ComponentDeletionWatcher (component_);
  49242. #endif
  49243. component->addComponentListener (this);
  49244. registerWithParentComps();
  49245. }
  49246. ComponentMovementWatcher::~ComponentMovementWatcher()
  49247. {
  49248. component->removeComponentListener (this);
  49249. unregister();
  49250. }
  49251. void ComponentMovementWatcher::componentParentHierarchyChanged (Component&)
  49252. {
  49253. #ifdef JUCE_DEBUG
  49254. // agh! don't delete the target component without deleting this object first!
  49255. jassert (! deletionWatcher->hasBeenDeleted());
  49256. #endif
  49257. if (! reentrant)
  49258. {
  49259. reentrant = true;
  49260. ComponentPeer* const peer = component->getPeer();
  49261. if (peer != lastPeer)
  49262. {
  49263. ComponentDeletionWatcher watcher (component);
  49264. componentPeerChanged();
  49265. if (watcher.hasBeenDeleted())
  49266. return;
  49267. lastPeer = peer;
  49268. }
  49269. unregister();
  49270. registerWithParentComps();
  49271. reentrant = false;
  49272. componentMovedOrResized (*component, true, true);
  49273. }
  49274. }
  49275. void ComponentMovementWatcher::componentMovedOrResized (Component&, bool wasMoved, bool wasResized)
  49276. {
  49277. #ifdef JUCE_DEBUG
  49278. // agh! don't delete the target component without deleting this object first!
  49279. jassert (! deletionWatcher->hasBeenDeleted());
  49280. #endif
  49281. if (wasMoved)
  49282. {
  49283. int x = 0, y = 0;
  49284. component->relativePositionToOtherComponent (component->getTopLevelComponent(), x, y);
  49285. wasMoved = (lastX != x || lastY != y);
  49286. lastX = x;
  49287. lastY = y;
  49288. }
  49289. wasResized = (lastWidth != component->getWidth() || lastHeight != component->getHeight());
  49290. lastWidth = component->getWidth();
  49291. lastHeight = component->getHeight();
  49292. if (wasMoved || wasResized)
  49293. componentMovedOrResized (wasMoved, wasResized);
  49294. }
  49295. void ComponentMovementWatcher::registerWithParentComps() throw()
  49296. {
  49297. Component* p = component->getParentComponent();
  49298. while (p != 0)
  49299. {
  49300. p->addComponentListener (this);
  49301. registeredParentComps.add (p);
  49302. p = p->getParentComponent();
  49303. }
  49304. }
  49305. void ComponentMovementWatcher::unregister() throw()
  49306. {
  49307. for (int i = registeredParentComps.size(); --i >= 0;)
  49308. ((Component*) registeredParentComps.getUnchecked(i))->removeComponentListener (this);
  49309. registeredParentComps.clear();
  49310. }
  49311. END_JUCE_NAMESPACE
  49312. /*** End of inlined file: juce_ComponentMovementWatcher.cpp ***/
  49313. /*** Start of inlined file: juce_GroupComponent.cpp ***/
  49314. BEGIN_JUCE_NAMESPACE
  49315. GroupComponent::GroupComponent (const String& componentName,
  49316. const String& labelText)
  49317. : Component (componentName),
  49318. text (labelText),
  49319. justification (Justification::left)
  49320. {
  49321. setInterceptsMouseClicks (false, true);
  49322. }
  49323. GroupComponent::~GroupComponent()
  49324. {
  49325. }
  49326. void GroupComponent::setText (const String& newText) throw()
  49327. {
  49328. if (text != newText)
  49329. {
  49330. text = newText;
  49331. repaint();
  49332. }
  49333. }
  49334. const String GroupComponent::getText() const throw()
  49335. {
  49336. return text;
  49337. }
  49338. void GroupComponent::setTextLabelPosition (const Justification& newJustification)
  49339. {
  49340. if (justification.getFlags() != newJustification.getFlags())
  49341. {
  49342. justification = newJustification;
  49343. repaint();
  49344. }
  49345. }
  49346. void GroupComponent::paint (Graphics& g)
  49347. {
  49348. getLookAndFeel()
  49349. .drawGroupComponentOutline (g, getWidth(), getHeight(),
  49350. text, justification,
  49351. *this);
  49352. }
  49353. void GroupComponent::enablementChanged()
  49354. {
  49355. repaint();
  49356. }
  49357. void GroupComponent::colourChanged()
  49358. {
  49359. repaint();
  49360. }
  49361. END_JUCE_NAMESPACE
  49362. /*** End of inlined file: juce_GroupComponent.cpp ***/
  49363. /*** Start of inlined file: juce_MultiDocumentPanel.cpp ***/
  49364. BEGIN_JUCE_NAMESPACE
  49365. MultiDocumentPanelWindow::MultiDocumentPanelWindow (const Colour& backgroundColour)
  49366. : DocumentWindow (String::empty, backgroundColour,
  49367. DocumentWindow::maximiseButton | DocumentWindow::closeButton, false)
  49368. {
  49369. }
  49370. MultiDocumentPanelWindow::~MultiDocumentPanelWindow()
  49371. {
  49372. }
  49373. void MultiDocumentPanelWindow::maximiseButtonPressed()
  49374. {
  49375. MultiDocumentPanel* const owner = getOwner();
  49376. jassert (owner != 0); // these windows are only designed to be used inside a MultiDocumentPanel!
  49377. if (owner != 0)
  49378. owner->setLayoutMode (MultiDocumentPanel::MaximisedWindowsWithTabs);
  49379. }
  49380. void MultiDocumentPanelWindow::closeButtonPressed()
  49381. {
  49382. MultiDocumentPanel* const owner = getOwner();
  49383. jassert (owner != 0); // these windows are only designed to be used inside a MultiDocumentPanel!
  49384. if (owner != 0)
  49385. owner->closeDocument (getContentComponent(), true);
  49386. }
  49387. void MultiDocumentPanelWindow::activeWindowStatusChanged()
  49388. {
  49389. DocumentWindow::activeWindowStatusChanged();
  49390. updateOrder();
  49391. }
  49392. void MultiDocumentPanelWindow::broughtToFront()
  49393. {
  49394. DocumentWindow::broughtToFront();
  49395. updateOrder();
  49396. }
  49397. void MultiDocumentPanelWindow::updateOrder()
  49398. {
  49399. MultiDocumentPanel* const owner = getOwner();
  49400. if (owner != 0)
  49401. owner->updateOrder();
  49402. }
  49403. MultiDocumentPanel* MultiDocumentPanelWindow::getOwner() const throw()
  49404. {
  49405. // (unable to use the syntax findParentComponentOfClass <MultiDocumentPanel> () because of a VC6 compiler bug)
  49406. return findParentComponentOfClass ((MultiDocumentPanel*) 0);
  49407. }
  49408. class MDITabbedComponentInternal : public TabbedComponent
  49409. {
  49410. public:
  49411. MDITabbedComponentInternal()
  49412. : TabbedComponent (TabbedButtonBar::TabsAtTop)
  49413. {
  49414. }
  49415. ~MDITabbedComponentInternal()
  49416. {
  49417. }
  49418. void currentTabChanged (const int, const String&)
  49419. {
  49420. // (unable to use the syntax findParentComponentOfClass <MultiDocumentPanel> () because of a VC6 compiler bug)
  49421. MultiDocumentPanel* const owner = findParentComponentOfClass ((MultiDocumentPanel*) 0);
  49422. if (owner != 0)
  49423. owner->updateOrder();
  49424. }
  49425. };
  49426. MultiDocumentPanel::MultiDocumentPanel()
  49427. : mode (MaximisedWindowsWithTabs),
  49428. tabComponent (0),
  49429. backgroundColour (Colours::lightblue),
  49430. maximumNumDocuments (0),
  49431. numDocsBeforeTabsUsed (0)
  49432. {
  49433. setOpaque (true);
  49434. }
  49435. MultiDocumentPanel::~MultiDocumentPanel()
  49436. {
  49437. closeAllDocuments (false);
  49438. }
  49439. static bool shouldDeleteComp (Component* const c)
  49440. {
  49441. return c->getProperties() ["mdiDocumentDelete_"];
  49442. }
  49443. bool MultiDocumentPanel::closeAllDocuments (const bool checkItsOkToCloseFirst)
  49444. {
  49445. while (components.size() > 0)
  49446. if (! closeDocument (components.getLast(), checkItsOkToCloseFirst))
  49447. return false;
  49448. return true;
  49449. }
  49450. MultiDocumentPanelWindow* MultiDocumentPanel::createNewDocumentWindow()
  49451. {
  49452. return new MultiDocumentPanelWindow (backgroundColour);
  49453. }
  49454. void MultiDocumentPanel::addWindow (Component* component)
  49455. {
  49456. MultiDocumentPanelWindow* const dw = createNewDocumentWindow();
  49457. dw->setResizable (true, false);
  49458. dw->setContentComponent (component, false, true);
  49459. dw->setName (component->getName());
  49460. const var bkg (component->getProperties() ["mdiDocumentBkg_"]);
  49461. dw->setBackgroundColour (bkg.isVoid() ? backgroundColour : Colour ((int) bkg));
  49462. int x = 4;
  49463. Component* const topComp = getChildComponent (getNumChildComponents() - 1);
  49464. if (topComp != 0 && topComp->getX() == x && topComp->getY() == x)
  49465. x += 16;
  49466. dw->setTopLeftPosition (x, x);
  49467. const var pos (component->getProperties() ["mdiDocumentPos_"]);
  49468. if (pos.toString().isNotEmpty())
  49469. dw->restoreWindowStateFromString (pos.toString());
  49470. addAndMakeVisible (dw);
  49471. dw->toFront (true);
  49472. }
  49473. bool MultiDocumentPanel::addDocument (Component* const component,
  49474. const Colour& docColour,
  49475. const bool deleteWhenRemoved)
  49476. {
  49477. // If you try passing a full DocumentWindow or ResizableWindow in here, you'll end up
  49478. // with a frame-within-a-frame! Just pass in the bare content component.
  49479. jassert (dynamic_cast <ResizableWindow*> (component) == 0);
  49480. if (component == 0 || (maximumNumDocuments > 0 && components.size() >= maximumNumDocuments))
  49481. return false;
  49482. components.add (component);
  49483. component->getProperties().set ("mdiDocumentDelete_", deleteWhenRemoved);
  49484. component->getProperties().set ("mdiDocumentBkg_", (int) docColour.getARGB());
  49485. component->addComponentListener (this);
  49486. if (mode == FloatingWindows)
  49487. {
  49488. if (isFullscreenWhenOneDocument())
  49489. {
  49490. if (components.size() == 1)
  49491. {
  49492. addAndMakeVisible (component);
  49493. }
  49494. else
  49495. {
  49496. if (components.size() == 2)
  49497. addWindow (components.getFirst());
  49498. addWindow (component);
  49499. }
  49500. }
  49501. else
  49502. {
  49503. addWindow (component);
  49504. }
  49505. }
  49506. else
  49507. {
  49508. if (tabComponent == 0 && components.size() > numDocsBeforeTabsUsed)
  49509. {
  49510. addAndMakeVisible (tabComponent = new MDITabbedComponentInternal());
  49511. Array <Component*> temp (components);
  49512. for (int i = 0; i < temp.size(); ++i)
  49513. tabComponent->addTab (temp[i]->getName(), docColour, temp[i], false);
  49514. resized();
  49515. }
  49516. else
  49517. {
  49518. if (tabComponent != 0)
  49519. tabComponent->addTab (component->getName(), docColour, component, false);
  49520. else
  49521. addAndMakeVisible (component);
  49522. }
  49523. setActiveDocument (component);
  49524. }
  49525. resized();
  49526. activeDocumentChanged();
  49527. return true;
  49528. }
  49529. bool MultiDocumentPanel::closeDocument (Component* component,
  49530. const bool checkItsOkToCloseFirst)
  49531. {
  49532. if (components.contains (component))
  49533. {
  49534. if (checkItsOkToCloseFirst && ! tryToCloseDocument (component))
  49535. return false;
  49536. component->removeComponentListener (this);
  49537. const bool shouldDelete = shouldDeleteComp (component);
  49538. component->getProperties().remove ("mdiDocumentDelete_");
  49539. component->getProperties().remove ("mdiDocumentBkg_");
  49540. if (mode == FloatingWindows)
  49541. {
  49542. for (int i = getNumChildComponents(); --i >= 0;)
  49543. {
  49544. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49545. if (dw != 0 && dw->getContentComponent() == component)
  49546. {
  49547. dw->setContentComponent (0, false);
  49548. delete dw;
  49549. break;
  49550. }
  49551. }
  49552. if (shouldDelete)
  49553. delete component;
  49554. components.removeValue (component);
  49555. if (isFullscreenWhenOneDocument() && components.size() == 1)
  49556. {
  49557. for (int i = getNumChildComponents(); --i >= 0;)
  49558. {
  49559. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49560. if (dw != 0)
  49561. {
  49562. dw->setContentComponent (0, false);
  49563. delete dw;
  49564. }
  49565. }
  49566. addAndMakeVisible (components.getFirst());
  49567. }
  49568. }
  49569. else
  49570. {
  49571. jassert (components.indexOf (component) >= 0);
  49572. if (tabComponent != 0)
  49573. {
  49574. for (int i = tabComponent->getNumTabs(); --i >= 0;)
  49575. if (tabComponent->getTabContentComponent (i) == component)
  49576. tabComponent->removeTab (i);
  49577. }
  49578. else
  49579. {
  49580. removeChildComponent (component);
  49581. }
  49582. if (shouldDelete)
  49583. delete component;
  49584. if (tabComponent != 0 && tabComponent->getNumTabs() <= numDocsBeforeTabsUsed)
  49585. deleteAndZero (tabComponent);
  49586. components.removeValue (component);
  49587. if (components.size() > 0 && tabComponent == 0)
  49588. addAndMakeVisible (components.getFirst());
  49589. }
  49590. resized();
  49591. activeDocumentChanged();
  49592. }
  49593. else
  49594. {
  49595. jassertfalse
  49596. }
  49597. return true;
  49598. }
  49599. int MultiDocumentPanel::getNumDocuments() const throw()
  49600. {
  49601. return components.size();
  49602. }
  49603. Component* MultiDocumentPanel::getDocument (const int index) const throw()
  49604. {
  49605. return components [index];
  49606. }
  49607. Component* MultiDocumentPanel::getActiveDocument() const throw()
  49608. {
  49609. if (mode == FloatingWindows)
  49610. {
  49611. for (int i = getNumChildComponents(); --i >= 0;)
  49612. {
  49613. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49614. if (dw != 0 && dw->isActiveWindow())
  49615. return dw->getContentComponent();
  49616. }
  49617. }
  49618. return components.getLast();
  49619. }
  49620. void MultiDocumentPanel::setActiveDocument (Component* component)
  49621. {
  49622. if (mode == FloatingWindows)
  49623. {
  49624. component = getContainerComp (component);
  49625. if (component != 0)
  49626. component->toFront (true);
  49627. }
  49628. else if (tabComponent != 0)
  49629. {
  49630. jassert (components.indexOf (component) >= 0);
  49631. for (int i = tabComponent->getNumTabs(); --i >= 0;)
  49632. {
  49633. if (tabComponent->getTabContentComponent (i) == component)
  49634. {
  49635. tabComponent->setCurrentTabIndex (i);
  49636. break;
  49637. }
  49638. }
  49639. }
  49640. else
  49641. {
  49642. component->grabKeyboardFocus();
  49643. }
  49644. }
  49645. void MultiDocumentPanel::activeDocumentChanged()
  49646. {
  49647. }
  49648. void MultiDocumentPanel::setMaximumNumDocuments (const int newNumber)
  49649. {
  49650. maximumNumDocuments = newNumber;
  49651. }
  49652. void MultiDocumentPanel::useFullscreenWhenOneDocument (const bool shouldUseTabs)
  49653. {
  49654. numDocsBeforeTabsUsed = shouldUseTabs ? 1 : 0;
  49655. }
  49656. bool MultiDocumentPanel::isFullscreenWhenOneDocument() const throw()
  49657. {
  49658. return numDocsBeforeTabsUsed != 0;
  49659. }
  49660. void MultiDocumentPanel::setLayoutMode (const LayoutMode newLayoutMode)
  49661. {
  49662. if (mode != newLayoutMode)
  49663. {
  49664. mode = newLayoutMode;
  49665. if (mode == FloatingWindows)
  49666. {
  49667. deleteAndZero (tabComponent);
  49668. }
  49669. else
  49670. {
  49671. for (int i = getNumChildComponents(); --i >= 0;)
  49672. {
  49673. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49674. if (dw != 0)
  49675. {
  49676. dw->getContentComponent()->getProperties().set ("mdiDocumentPos_", dw->getWindowStateAsString());
  49677. dw->setContentComponent (0, false);
  49678. delete dw;
  49679. }
  49680. }
  49681. }
  49682. resized();
  49683. const Array <Component*> tempComps (components);
  49684. components.clear();
  49685. for (int i = 0; i < tempComps.size(); ++i)
  49686. {
  49687. Component* const c = tempComps.getUnchecked(i);
  49688. addDocument (c,
  49689. Colour ((int) c->getProperties().getWithDefault ("mdiDocumentBkg_", (int) Colours::white.getARGB())),
  49690. shouldDeleteComp (c));
  49691. }
  49692. }
  49693. }
  49694. void MultiDocumentPanel::setBackgroundColour (const Colour& newBackgroundColour)
  49695. {
  49696. if (backgroundColour != newBackgroundColour)
  49697. {
  49698. backgroundColour = newBackgroundColour;
  49699. setOpaque (newBackgroundColour.isOpaque());
  49700. repaint();
  49701. }
  49702. }
  49703. void MultiDocumentPanel::paint (Graphics& g)
  49704. {
  49705. g.fillAll (backgroundColour);
  49706. }
  49707. void MultiDocumentPanel::resized()
  49708. {
  49709. if (mode == MaximisedWindowsWithTabs || components.size() == numDocsBeforeTabsUsed)
  49710. {
  49711. for (int i = getNumChildComponents(); --i >= 0;)
  49712. getChildComponent (i)->setBounds (0, 0, getWidth(), getHeight());
  49713. }
  49714. setWantsKeyboardFocus (components.size() == 0);
  49715. }
  49716. Component* MultiDocumentPanel::getContainerComp (Component* c) const
  49717. {
  49718. if (mode == FloatingWindows)
  49719. {
  49720. for (int i = 0; i < getNumChildComponents(); ++i)
  49721. {
  49722. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49723. if (dw != 0 && dw->getContentComponent() == c)
  49724. {
  49725. c = dw;
  49726. break;
  49727. }
  49728. }
  49729. }
  49730. return c;
  49731. }
  49732. void MultiDocumentPanel::componentNameChanged (Component&)
  49733. {
  49734. if (mode == FloatingWindows)
  49735. {
  49736. for (int i = 0; i < getNumChildComponents(); ++i)
  49737. {
  49738. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49739. if (dw != 0)
  49740. dw->setName (dw->getContentComponent()->getName());
  49741. }
  49742. }
  49743. else if (tabComponent != 0)
  49744. {
  49745. for (int i = tabComponent->getNumTabs(); --i >= 0;)
  49746. tabComponent->setTabName (i, tabComponent->getTabContentComponent (i)->getName());
  49747. }
  49748. }
  49749. void MultiDocumentPanel::updateOrder()
  49750. {
  49751. const Array <Component*> oldList (components);
  49752. if (mode == FloatingWindows)
  49753. {
  49754. components.clear();
  49755. for (int i = 0; i < getNumChildComponents(); ++i)
  49756. {
  49757. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49758. if (dw != 0)
  49759. components.add (dw->getContentComponent());
  49760. }
  49761. }
  49762. else
  49763. {
  49764. if (tabComponent != 0)
  49765. {
  49766. Component* const current = tabComponent->getCurrentContentComponent();
  49767. if (current != 0)
  49768. {
  49769. components.removeValue (current);
  49770. components.add (current);
  49771. }
  49772. }
  49773. }
  49774. if (components != oldList)
  49775. activeDocumentChanged();
  49776. }
  49777. END_JUCE_NAMESPACE
  49778. /*** End of inlined file: juce_MultiDocumentPanel.cpp ***/
  49779. /*** Start of inlined file: juce_ResizableBorderComponent.cpp ***/
  49780. BEGIN_JUCE_NAMESPACE
  49781. const int zoneL = 1;
  49782. const int zoneR = 2;
  49783. const int zoneT = 4;
  49784. const int zoneB = 8;
  49785. ResizableBorderComponent::ResizableBorderComponent (Component* const componentToResize,
  49786. ComponentBoundsConstrainer* const constrainer_)
  49787. : component (componentToResize),
  49788. constrainer (constrainer_),
  49789. borderSize (5),
  49790. mouseZone (0)
  49791. {
  49792. }
  49793. ResizableBorderComponent::~ResizableBorderComponent()
  49794. {
  49795. }
  49796. void ResizableBorderComponent::paint (Graphics& g)
  49797. {
  49798. getLookAndFeel().drawResizableFrame (g, getWidth(), getHeight(), borderSize);
  49799. }
  49800. void ResizableBorderComponent::mouseEnter (const MouseEvent& e)
  49801. {
  49802. updateMouseZone (e);
  49803. }
  49804. void ResizableBorderComponent::mouseMove (const MouseEvent& e)
  49805. {
  49806. updateMouseZone (e);
  49807. }
  49808. void ResizableBorderComponent::mouseDown (const MouseEvent& e)
  49809. {
  49810. if (component->isValidComponent())
  49811. {
  49812. updateMouseZone (e);
  49813. originalX = component->getX();
  49814. originalY = component->getY();
  49815. originalW = component->getWidth();
  49816. originalH = component->getHeight();
  49817. if (constrainer != 0)
  49818. constrainer->resizeStart();
  49819. }
  49820. else
  49821. {
  49822. jassertfalse
  49823. }
  49824. }
  49825. void ResizableBorderComponent::mouseDrag (const MouseEvent& e)
  49826. {
  49827. if (! component->isValidComponent())
  49828. {
  49829. jassertfalse
  49830. return;
  49831. }
  49832. int x = originalX;
  49833. int y = originalY;
  49834. int w = originalW;
  49835. int h = originalH;
  49836. const int dx = e.getDistanceFromDragStartX();
  49837. const int dy = e.getDistanceFromDragStartY();
  49838. if ((mouseZone & zoneL) != 0)
  49839. {
  49840. x += dx;
  49841. w -= dx;
  49842. }
  49843. if ((mouseZone & zoneT) != 0)
  49844. {
  49845. y += dy;
  49846. h -= dy;
  49847. }
  49848. if ((mouseZone & zoneR) != 0)
  49849. w += dx;
  49850. if ((mouseZone & zoneB) != 0)
  49851. h += dy;
  49852. if (constrainer != 0)
  49853. constrainer->setBoundsForComponent (component,
  49854. Rectangle<int> (x, y, w, h),
  49855. (mouseZone & zoneT) != 0,
  49856. (mouseZone & zoneL) != 0,
  49857. (mouseZone & zoneB) != 0,
  49858. (mouseZone & zoneR) != 0);
  49859. else
  49860. component->setBounds (x, y, w, h);
  49861. }
  49862. void ResizableBorderComponent::mouseUp (const MouseEvent&)
  49863. {
  49864. if (constrainer != 0)
  49865. constrainer->resizeEnd();
  49866. }
  49867. bool ResizableBorderComponent::hitTest (int x, int y)
  49868. {
  49869. return x < borderSize.getLeft()
  49870. || x >= getWidth() - borderSize.getRight()
  49871. || y < borderSize.getTop()
  49872. || y >= getHeight() - borderSize.getBottom();
  49873. }
  49874. void ResizableBorderComponent::setBorderThickness (const BorderSize& newBorderSize) throw()
  49875. {
  49876. if (borderSize != newBorderSize)
  49877. {
  49878. borderSize = newBorderSize;
  49879. repaint();
  49880. }
  49881. }
  49882. const BorderSize ResizableBorderComponent::getBorderThickness() const throw()
  49883. {
  49884. return borderSize;
  49885. }
  49886. void ResizableBorderComponent::updateMouseZone (const MouseEvent& e) throw()
  49887. {
  49888. int newZone = 0;
  49889. if (ResizableBorderComponent::hitTest (e.x, e.y))
  49890. {
  49891. if (e.x < jmax (borderSize.getLeft(),
  49892. proportionOfWidth (0.1f),
  49893. jmin (10, proportionOfWidth (0.33f))))
  49894. newZone |= zoneL;
  49895. else if (e.x >= jmin (getWidth() - borderSize.getRight(),
  49896. proportionOfWidth (0.9f),
  49897. getWidth() - jmin (10, proportionOfWidth (0.33f))))
  49898. newZone |= zoneR;
  49899. if (e.y < jmax (borderSize.getTop(),
  49900. proportionOfHeight (0.1f),
  49901. jmin (10, proportionOfHeight (0.33f))))
  49902. newZone |= zoneT;
  49903. else if (e.y >= jmin (getHeight() - borderSize.getBottom(),
  49904. proportionOfHeight (0.9f),
  49905. getHeight() - jmin (10, proportionOfHeight (0.33f))))
  49906. newZone |= zoneB;
  49907. }
  49908. if (mouseZone != newZone)
  49909. {
  49910. mouseZone = newZone;
  49911. MouseCursor::StandardCursorType mc = MouseCursor::NormalCursor;
  49912. switch (newZone)
  49913. {
  49914. case (zoneL | zoneT):
  49915. mc = MouseCursor::TopLeftCornerResizeCursor;
  49916. break;
  49917. case zoneT:
  49918. mc = MouseCursor::TopEdgeResizeCursor;
  49919. break;
  49920. case (zoneR | zoneT):
  49921. mc = MouseCursor::TopRightCornerResizeCursor;
  49922. break;
  49923. case zoneL:
  49924. mc = MouseCursor::LeftEdgeResizeCursor;
  49925. break;
  49926. case zoneR:
  49927. mc = MouseCursor::RightEdgeResizeCursor;
  49928. break;
  49929. case (zoneL | zoneB):
  49930. mc = MouseCursor::BottomLeftCornerResizeCursor;
  49931. break;
  49932. case zoneB:
  49933. mc = MouseCursor::BottomEdgeResizeCursor;
  49934. break;
  49935. case (zoneR | zoneB):
  49936. mc = MouseCursor::BottomRightCornerResizeCursor;
  49937. break;
  49938. default:
  49939. break;
  49940. }
  49941. setMouseCursor (mc);
  49942. }
  49943. }
  49944. END_JUCE_NAMESPACE
  49945. /*** End of inlined file: juce_ResizableBorderComponent.cpp ***/
  49946. /*** Start of inlined file: juce_ResizableCornerComponent.cpp ***/
  49947. BEGIN_JUCE_NAMESPACE
  49948. ResizableCornerComponent::ResizableCornerComponent (Component* const componentToResize,
  49949. ComponentBoundsConstrainer* const constrainer_)
  49950. : component (componentToResize),
  49951. constrainer (constrainer_)
  49952. {
  49953. setRepaintsOnMouseActivity (true);
  49954. setMouseCursor (MouseCursor::BottomRightCornerResizeCursor);
  49955. }
  49956. ResizableCornerComponent::~ResizableCornerComponent()
  49957. {
  49958. }
  49959. void ResizableCornerComponent::paint (Graphics& g)
  49960. {
  49961. getLookAndFeel()
  49962. .drawCornerResizer (g, getWidth(), getHeight(),
  49963. isMouseOverOrDragging(),
  49964. isMouseButtonDown());
  49965. }
  49966. void ResizableCornerComponent::mouseDown (const MouseEvent&)
  49967. {
  49968. if (component->isValidComponent())
  49969. {
  49970. originalX = component->getX();
  49971. originalY = component->getY();
  49972. originalW = component->getWidth();
  49973. originalH = component->getHeight();
  49974. if (constrainer != 0)
  49975. constrainer->resizeStart();
  49976. }
  49977. else
  49978. {
  49979. jassertfalse
  49980. }
  49981. }
  49982. void ResizableCornerComponent::mouseDrag (const MouseEvent& e)
  49983. {
  49984. if (! component->isValidComponent())
  49985. {
  49986. jassertfalse
  49987. return;
  49988. }
  49989. int x = originalX;
  49990. int y = originalY;
  49991. int w = originalW + e.getDistanceFromDragStartX();
  49992. int h = originalH + e.getDistanceFromDragStartY();
  49993. if (constrainer != 0)
  49994. constrainer->setBoundsForComponent (component, Rectangle<int> (x, y, w, h),
  49995. false, false, true, true);
  49996. else
  49997. component->setBounds (x, y, w, h);
  49998. }
  49999. void ResizableCornerComponent::mouseUp (const MouseEvent&)
  50000. {
  50001. if (constrainer != 0)
  50002. constrainer->resizeStart();
  50003. }
  50004. bool ResizableCornerComponent::hitTest (int x, int y)
  50005. {
  50006. if (getWidth() <= 0)
  50007. return false;
  50008. const int yAtX = getHeight() - (getHeight() * x / getWidth());
  50009. return y >= yAtX - getHeight() / 4;
  50010. }
  50011. END_JUCE_NAMESPACE
  50012. /*** End of inlined file: juce_ResizableCornerComponent.cpp ***/
  50013. /*** Start of inlined file: juce_ScrollBar.cpp ***/
  50014. BEGIN_JUCE_NAMESPACE
  50015. class ScrollbarButton : public Button
  50016. {
  50017. public:
  50018. int direction;
  50019. ScrollbarButton (const int direction_,
  50020. ScrollBar& owner_) throw()
  50021. : Button (String::empty),
  50022. direction (direction_),
  50023. owner (owner_)
  50024. {
  50025. setWantsKeyboardFocus (false);
  50026. }
  50027. ~ScrollbarButton()
  50028. {
  50029. }
  50030. void paintButton (Graphics& g,
  50031. bool isMouseOver,
  50032. bool isMouseDown)
  50033. {
  50034. getLookAndFeel()
  50035. .drawScrollbarButton (g, owner,
  50036. getWidth(), getHeight(),
  50037. direction,
  50038. owner.isVertical(),
  50039. isMouseOver, isMouseDown);
  50040. }
  50041. void clicked()
  50042. {
  50043. owner.moveScrollbarInSteps ((direction == 1 || direction == 2) ? 1 : -1);
  50044. }
  50045. juce_UseDebuggingNewOperator
  50046. private:
  50047. ScrollBar& owner;
  50048. ScrollbarButton (const ScrollbarButton&);
  50049. const ScrollbarButton& operator= (const ScrollbarButton&);
  50050. };
  50051. ScrollBar::ScrollBar (const bool vertical_,
  50052. const bool buttonsAreVisible)
  50053. : minimum (0.0),
  50054. maximum (1.0),
  50055. rangeStart (0.0),
  50056. rangeSize (0.1),
  50057. singleStepSize (0.1),
  50058. thumbAreaStart (0),
  50059. thumbAreaSize (0),
  50060. thumbStart (0),
  50061. thumbSize (0),
  50062. initialDelayInMillisecs (100),
  50063. repeatDelayInMillisecs (50),
  50064. minimumDelayInMillisecs (10),
  50065. vertical (vertical_),
  50066. isDraggingThumb (false),
  50067. alwaysVisible (false),
  50068. upButton (0),
  50069. downButton (0)
  50070. {
  50071. setButtonVisibility (buttonsAreVisible);
  50072. setRepaintsOnMouseActivity (true);
  50073. setFocusContainer (true);
  50074. }
  50075. ScrollBar::~ScrollBar()
  50076. {
  50077. deleteAllChildren();
  50078. }
  50079. void ScrollBar::setRangeLimits (const double newMinimum,
  50080. const double newMaximum) throw()
  50081. {
  50082. minimum = newMinimum;
  50083. maximum = newMaximum;
  50084. jassert (maximum >= minimum); // these can't be the wrong way round!
  50085. setCurrentRangeStart (rangeStart);
  50086. updateThumbPosition();
  50087. }
  50088. void ScrollBar::setCurrentRange (double newStart,
  50089. double newSize) throw()
  50090. {
  50091. newSize = jlimit (0.0, maximum - minimum, newSize);
  50092. newStart = jlimit (minimum, maximum - newSize, newStart);
  50093. if (rangeStart != newStart
  50094. || rangeSize != newSize)
  50095. {
  50096. rangeStart = newStart;
  50097. rangeSize = newSize;
  50098. updateThumbPosition();
  50099. triggerAsyncUpdate();
  50100. }
  50101. }
  50102. void ScrollBar::setCurrentRangeStart (double newStart) throw()
  50103. {
  50104. setCurrentRange (newStart, rangeSize);
  50105. }
  50106. void ScrollBar::setSingleStepSize (const double newSingleStepSize) throw()
  50107. {
  50108. singleStepSize = newSingleStepSize;
  50109. }
  50110. void ScrollBar::moveScrollbarInSteps (const int howManySteps) throw()
  50111. {
  50112. setCurrentRangeStart (rangeStart + howManySteps * singleStepSize);
  50113. }
  50114. void ScrollBar::moveScrollbarInPages (const int howManyPages) throw()
  50115. {
  50116. setCurrentRangeStart (rangeStart + howManyPages * rangeSize);
  50117. }
  50118. void ScrollBar::scrollToTop() throw()
  50119. {
  50120. setCurrentRangeStart (minimum);
  50121. }
  50122. void ScrollBar::scrollToBottom() throw()
  50123. {
  50124. setCurrentRangeStart (maximum - rangeSize);
  50125. }
  50126. void ScrollBar::setButtonRepeatSpeed (const int initialDelayInMillisecs_,
  50127. const int repeatDelayInMillisecs_,
  50128. const int minimumDelayInMillisecs_) throw()
  50129. {
  50130. initialDelayInMillisecs = initialDelayInMillisecs_;
  50131. repeatDelayInMillisecs = repeatDelayInMillisecs_;
  50132. minimumDelayInMillisecs = minimumDelayInMillisecs_;
  50133. if (upButton != 0)
  50134. {
  50135. upButton->setRepeatSpeed (initialDelayInMillisecs, repeatDelayInMillisecs, minimumDelayInMillisecs);
  50136. downButton->setRepeatSpeed (initialDelayInMillisecs, repeatDelayInMillisecs, minimumDelayInMillisecs);
  50137. }
  50138. }
  50139. void ScrollBar::addListener (ScrollBarListener* const listener) throw()
  50140. {
  50141. jassert (listener != 0);
  50142. if (listener != 0)
  50143. listeners.add (listener);
  50144. }
  50145. void ScrollBar::removeListener (ScrollBarListener* const listener) throw()
  50146. {
  50147. listeners.removeValue (listener);
  50148. }
  50149. void ScrollBar::handleAsyncUpdate()
  50150. {
  50151. const double value = getCurrentRangeStart();
  50152. for (int i = listeners.size(); --i >= 0;)
  50153. {
  50154. ((ScrollBarListener*) listeners.getUnchecked (i))->scrollBarMoved (this, value);
  50155. i = jmin (i, listeners.size());
  50156. }
  50157. }
  50158. void ScrollBar::updateThumbPosition() throw()
  50159. {
  50160. int newThumbSize = roundToInt ((maximum > minimum) ? (rangeSize * thumbAreaSize) / (maximum - minimum)
  50161. : thumbAreaSize);
  50162. if (newThumbSize < getLookAndFeel().getMinimumScrollbarThumbSize (*this))
  50163. newThumbSize = jmin (getLookAndFeel().getMinimumScrollbarThumbSize (*this), thumbAreaSize - 1);
  50164. if (newThumbSize > thumbAreaSize)
  50165. newThumbSize = thumbAreaSize;
  50166. int newThumbStart = thumbAreaStart;
  50167. if (maximum - minimum > rangeSize)
  50168. newThumbStart += roundToInt (((rangeStart - minimum) * (thumbAreaSize - newThumbSize))
  50169. / ((maximum - minimum) - rangeSize));
  50170. setVisible (alwaysVisible || (maximum - minimum > rangeSize && rangeSize > 0.0));
  50171. if (thumbStart != newThumbStart || thumbSize != newThumbSize)
  50172. {
  50173. const int repaintStart = jmin (thumbStart, newThumbStart) - 4;
  50174. const int repaintSize = jmax (thumbStart + thumbSize, newThumbStart + newThumbSize) + 8 - repaintStart;
  50175. if (vertical)
  50176. repaint (0, repaintStart, getWidth(), repaintSize);
  50177. else
  50178. repaint (repaintStart, 0, repaintSize, getHeight());
  50179. thumbStart = newThumbStart;
  50180. thumbSize = newThumbSize;
  50181. }
  50182. }
  50183. void ScrollBar::setOrientation (const bool shouldBeVertical) throw()
  50184. {
  50185. if (vertical != shouldBeVertical)
  50186. {
  50187. vertical = shouldBeVertical;
  50188. if (upButton != 0)
  50189. {
  50190. ((ScrollbarButton*) upButton)->direction = (vertical) ? 0 : 3;
  50191. ((ScrollbarButton*) downButton)->direction = (vertical) ? 2 : 1;
  50192. }
  50193. updateThumbPosition();
  50194. }
  50195. }
  50196. void ScrollBar::setButtonVisibility (const bool buttonsAreVisible)
  50197. {
  50198. deleteAndZero (upButton);
  50199. deleteAndZero (downButton);
  50200. if (buttonsAreVisible)
  50201. {
  50202. addAndMakeVisible (upButton = new ScrollbarButton ((vertical) ? 0 : 3, *this));
  50203. addAndMakeVisible (downButton = new ScrollbarButton ((vertical) ? 2 : 1, *this));
  50204. setButtonRepeatSpeed (initialDelayInMillisecs, repeatDelayInMillisecs, minimumDelayInMillisecs);
  50205. }
  50206. updateThumbPosition();
  50207. }
  50208. void ScrollBar::setAutoHide (const bool shouldHideWhenFullRange)
  50209. {
  50210. alwaysVisible = ! shouldHideWhenFullRange;
  50211. updateThumbPosition();
  50212. }
  50213. void ScrollBar::paint (Graphics& g)
  50214. {
  50215. if (thumbAreaSize > 0)
  50216. {
  50217. LookAndFeel& lf = getLookAndFeel();
  50218. const int thumb = (thumbAreaSize > lf.getMinimumScrollbarThumbSize (*this))
  50219. ? thumbSize : 0;
  50220. if (vertical)
  50221. {
  50222. lf.drawScrollbar (g, *this,
  50223. 0, thumbAreaStart,
  50224. getWidth(), thumbAreaSize,
  50225. vertical,
  50226. thumbStart, thumb,
  50227. isMouseOver(), isMouseButtonDown());
  50228. }
  50229. else
  50230. {
  50231. lf.drawScrollbar (g, *this,
  50232. thumbAreaStart, 0,
  50233. thumbAreaSize, getHeight(),
  50234. vertical,
  50235. thumbStart, thumb,
  50236. isMouseOver(), isMouseButtonDown());
  50237. }
  50238. }
  50239. }
  50240. void ScrollBar::lookAndFeelChanged()
  50241. {
  50242. setComponentEffect (getLookAndFeel().getScrollbarEffect());
  50243. }
  50244. void ScrollBar::resized()
  50245. {
  50246. const int length = ((vertical) ? getHeight() : getWidth());
  50247. const int buttonSize = (upButton != 0) ? jmin (getLookAndFeel().getScrollbarButtonSize (*this), (length >> 1))
  50248. : 0;
  50249. if (length < 32 + getLookAndFeel().getMinimumScrollbarThumbSize (*this))
  50250. {
  50251. thumbAreaStart = length >> 1;
  50252. thumbAreaSize = 0;
  50253. }
  50254. else
  50255. {
  50256. thumbAreaStart = buttonSize;
  50257. thumbAreaSize = length - (buttonSize << 1);
  50258. }
  50259. if (upButton != 0)
  50260. {
  50261. if (vertical)
  50262. {
  50263. upButton->setBounds (0, 0, getWidth(), buttonSize);
  50264. downButton->setBounds (0, thumbAreaStart + thumbAreaSize, getWidth(), buttonSize);
  50265. }
  50266. else
  50267. {
  50268. upButton->setBounds (0, 0, buttonSize, getHeight());
  50269. downButton->setBounds (thumbAreaStart + thumbAreaSize, 0, buttonSize, getHeight());
  50270. }
  50271. }
  50272. updateThumbPosition();
  50273. }
  50274. void ScrollBar::mouseDown (const MouseEvent& e)
  50275. {
  50276. isDraggingThumb = false;
  50277. lastMousePos = vertical ? e.y : e.x;
  50278. dragStartMousePos = lastMousePos;
  50279. dragStartRange = rangeStart;
  50280. if (dragStartMousePos < thumbStart)
  50281. {
  50282. moveScrollbarInPages (-1);
  50283. startTimer (400);
  50284. }
  50285. else if (dragStartMousePos >= thumbStart + thumbSize)
  50286. {
  50287. moveScrollbarInPages (1);
  50288. startTimer (400);
  50289. }
  50290. else
  50291. {
  50292. isDraggingThumb = (thumbAreaSize > getLookAndFeel().getMinimumScrollbarThumbSize (*this))
  50293. && (thumbAreaSize > thumbSize);
  50294. }
  50295. }
  50296. void ScrollBar::mouseDrag (const MouseEvent& e)
  50297. {
  50298. if (isDraggingThumb)
  50299. {
  50300. const int deltaPixels = ((vertical) ? e.y : e.x) - dragStartMousePos;
  50301. setCurrentRangeStart (dragStartRange
  50302. + deltaPixels * ((maximum - minimum) - rangeSize)
  50303. / (thumbAreaSize - thumbSize));
  50304. }
  50305. else
  50306. {
  50307. lastMousePos = (vertical) ? e.y : e.x;
  50308. }
  50309. }
  50310. void ScrollBar::mouseUp (const MouseEvent&)
  50311. {
  50312. isDraggingThumb = false;
  50313. stopTimer();
  50314. repaint();
  50315. }
  50316. void ScrollBar::mouseWheelMove (const MouseEvent&,
  50317. float wheelIncrementX,
  50318. float wheelIncrementY)
  50319. {
  50320. float increment = vertical ? wheelIncrementY : wheelIncrementX;
  50321. if (increment < 0)
  50322. increment = jmin (increment * 10.0f, -1.0f);
  50323. else if (increment > 0)
  50324. increment = jmax (increment * 10.0f, 1.0f);
  50325. setCurrentRangeStart (rangeStart - singleStepSize * increment);
  50326. }
  50327. void ScrollBar::timerCallback()
  50328. {
  50329. if (isMouseButtonDown())
  50330. {
  50331. startTimer (40);
  50332. if (lastMousePos < thumbStart)
  50333. setCurrentRangeStart (rangeStart - rangeSize);
  50334. else if (lastMousePos > thumbStart + thumbSize)
  50335. setCurrentRangeStart (rangeStart + rangeSize);
  50336. }
  50337. else
  50338. {
  50339. stopTimer();
  50340. }
  50341. }
  50342. bool ScrollBar::keyPressed (const KeyPress& key)
  50343. {
  50344. if (! isVisible())
  50345. return false;
  50346. if (key.isKeyCode (KeyPress::upKey) || key.isKeyCode (KeyPress::leftKey))
  50347. moveScrollbarInSteps (-1);
  50348. else if (key.isKeyCode (KeyPress::downKey) || key.isKeyCode (KeyPress::rightKey))
  50349. moveScrollbarInSteps (1);
  50350. else if (key.isKeyCode (KeyPress::pageUpKey))
  50351. moveScrollbarInPages (-1);
  50352. else if (key.isKeyCode (KeyPress::pageDownKey))
  50353. moveScrollbarInPages (1);
  50354. else if (key.isKeyCode (KeyPress::homeKey))
  50355. scrollToTop();
  50356. else if (key.isKeyCode (KeyPress::endKey))
  50357. scrollToBottom();
  50358. else
  50359. return false;
  50360. return true;
  50361. }
  50362. END_JUCE_NAMESPACE
  50363. /*** End of inlined file: juce_ScrollBar.cpp ***/
  50364. /*** Start of inlined file: juce_StretchableLayoutManager.cpp ***/
  50365. BEGIN_JUCE_NAMESPACE
  50366. StretchableLayoutManager::StretchableLayoutManager()
  50367. : totalSize (0)
  50368. {
  50369. }
  50370. StretchableLayoutManager::~StretchableLayoutManager()
  50371. {
  50372. }
  50373. void StretchableLayoutManager::clearAllItems()
  50374. {
  50375. items.clear();
  50376. totalSize = 0;
  50377. }
  50378. void StretchableLayoutManager::setItemLayout (const int itemIndex,
  50379. const double minimumSize,
  50380. const double maximumSize,
  50381. const double preferredSize)
  50382. {
  50383. ItemLayoutProperties* layout = getInfoFor (itemIndex);
  50384. if (layout == 0)
  50385. {
  50386. layout = new ItemLayoutProperties();
  50387. layout->itemIndex = itemIndex;
  50388. int i;
  50389. for (i = 0; i < items.size(); ++i)
  50390. if (items.getUnchecked (i)->itemIndex > itemIndex)
  50391. break;
  50392. items.insert (i, layout);
  50393. }
  50394. layout->minSize = minimumSize;
  50395. layout->maxSize = maximumSize;
  50396. layout->preferredSize = preferredSize;
  50397. layout->currentSize = 0;
  50398. }
  50399. bool StretchableLayoutManager::getItemLayout (const int itemIndex,
  50400. double& minimumSize,
  50401. double& maximumSize,
  50402. double& preferredSize) const
  50403. {
  50404. const ItemLayoutProperties* const layout = getInfoFor (itemIndex);
  50405. if (layout != 0)
  50406. {
  50407. minimumSize = layout->minSize;
  50408. maximumSize = layout->maxSize;
  50409. preferredSize = layout->preferredSize;
  50410. return true;
  50411. }
  50412. return false;
  50413. }
  50414. void StretchableLayoutManager::setTotalSize (const int newTotalSize)
  50415. {
  50416. totalSize = newTotalSize;
  50417. fitComponentsIntoSpace (0, items.size(), totalSize, 0);
  50418. }
  50419. int StretchableLayoutManager::getItemCurrentPosition (const int itemIndex) const
  50420. {
  50421. int pos = 0;
  50422. for (int i = 0; i < itemIndex; ++i)
  50423. {
  50424. const ItemLayoutProperties* const layout = getInfoFor (i);
  50425. if (layout != 0)
  50426. pos += layout->currentSize;
  50427. }
  50428. return pos;
  50429. }
  50430. int StretchableLayoutManager::getItemCurrentAbsoluteSize (const int itemIndex) const
  50431. {
  50432. const ItemLayoutProperties* const layout = getInfoFor (itemIndex);
  50433. if (layout != 0)
  50434. return layout->currentSize;
  50435. return 0;
  50436. }
  50437. double StretchableLayoutManager::getItemCurrentRelativeSize (const int itemIndex) const
  50438. {
  50439. const ItemLayoutProperties* const layout = getInfoFor (itemIndex);
  50440. if (layout != 0)
  50441. return -layout->currentSize / (double) totalSize;
  50442. return 0;
  50443. }
  50444. void StretchableLayoutManager::setItemPosition (const int itemIndex,
  50445. int newPosition)
  50446. {
  50447. for (int i = items.size(); --i >= 0;)
  50448. {
  50449. const ItemLayoutProperties* const layout = items.getUnchecked(i);
  50450. if (layout->itemIndex == itemIndex)
  50451. {
  50452. int realTotalSize = jmax (totalSize, getMinimumSizeOfItems (0, items.size()));
  50453. const int minSizeAfterThisComp = getMinimumSizeOfItems (i, items.size());
  50454. const int maxSizeAfterThisComp = getMaximumSizeOfItems (i + 1, items.size());
  50455. newPosition = jmax (newPosition, totalSize - maxSizeAfterThisComp - layout->currentSize);
  50456. newPosition = jmin (newPosition, realTotalSize - minSizeAfterThisComp);
  50457. int endPos = fitComponentsIntoSpace (0, i, newPosition, 0);
  50458. endPos += layout->currentSize;
  50459. fitComponentsIntoSpace (i + 1, items.size(), totalSize - endPos, endPos);
  50460. updatePrefSizesToMatchCurrentPositions();
  50461. break;
  50462. }
  50463. }
  50464. }
  50465. void StretchableLayoutManager::layOutComponents (Component** const components,
  50466. int numComponents,
  50467. int x, int y, int w, int h,
  50468. const bool vertically,
  50469. const bool resizeOtherDimension)
  50470. {
  50471. setTotalSize (vertically ? h : w);
  50472. int pos = vertically ? y : x;
  50473. for (int i = 0; i < numComponents; ++i)
  50474. {
  50475. const ItemLayoutProperties* const layout = getInfoFor (i);
  50476. if (layout != 0)
  50477. {
  50478. Component* const c = components[i];
  50479. if (c != 0)
  50480. {
  50481. if (i == numComponents - 1)
  50482. {
  50483. // if it's the last item, crop it to exactly fit the available space..
  50484. if (resizeOtherDimension)
  50485. {
  50486. if (vertically)
  50487. c->setBounds (x, pos, w, jmax (layout->currentSize, h - pos));
  50488. else
  50489. c->setBounds (pos, y, jmax (layout->currentSize, w - pos), h);
  50490. }
  50491. else
  50492. {
  50493. if (vertically)
  50494. c->setBounds (c->getX(), pos, c->getWidth(), jmax (layout->currentSize, h - pos));
  50495. else
  50496. c->setBounds (pos, c->getY(), jmax (layout->currentSize, w - pos), c->getHeight());
  50497. }
  50498. }
  50499. else
  50500. {
  50501. if (resizeOtherDimension)
  50502. {
  50503. if (vertically)
  50504. c->setBounds (x, pos, w, layout->currentSize);
  50505. else
  50506. c->setBounds (pos, y, layout->currentSize, h);
  50507. }
  50508. else
  50509. {
  50510. if (vertically)
  50511. c->setBounds (c->getX(), pos, c->getWidth(), layout->currentSize);
  50512. else
  50513. c->setBounds (pos, c->getY(), layout->currentSize, c->getHeight());
  50514. }
  50515. }
  50516. }
  50517. pos += layout->currentSize;
  50518. }
  50519. }
  50520. }
  50521. StretchableLayoutManager::ItemLayoutProperties* StretchableLayoutManager::getInfoFor (const int itemIndex) const
  50522. {
  50523. for (int i = items.size(); --i >= 0;)
  50524. if (items.getUnchecked(i)->itemIndex == itemIndex)
  50525. return items.getUnchecked(i);
  50526. return 0;
  50527. }
  50528. int StretchableLayoutManager::fitComponentsIntoSpace (const int startIndex,
  50529. const int endIndex,
  50530. const int availableSpace,
  50531. int startPos)
  50532. {
  50533. // calculate the total sizes
  50534. int i;
  50535. double totalIdealSize = 0.0;
  50536. int totalMinimums = 0;
  50537. for (i = startIndex; i < endIndex; ++i)
  50538. {
  50539. ItemLayoutProperties* const layout = items.getUnchecked (i);
  50540. layout->currentSize = sizeToRealSize (layout->minSize, totalSize);
  50541. totalMinimums += layout->currentSize;
  50542. totalIdealSize += sizeToRealSize (layout->preferredSize, availableSpace);
  50543. }
  50544. if (totalIdealSize <= 0)
  50545. totalIdealSize = 1.0;
  50546. // now calc the best sizes..
  50547. int extraSpace = availableSpace - totalMinimums;
  50548. while (extraSpace > 0)
  50549. {
  50550. int numWantingMoreSpace = 0;
  50551. int numHavingTakenExtraSpace = 0;
  50552. // first figure out how many comps want a slice of the extra space..
  50553. for (i = startIndex; i < endIndex; ++i)
  50554. {
  50555. ItemLayoutProperties* const layout = items.getUnchecked (i);
  50556. double sizeWanted = sizeToRealSize (layout->preferredSize, availableSpace);
  50557. const int bestSize = jlimit (layout->currentSize,
  50558. jmax (layout->currentSize,
  50559. sizeToRealSize (layout->maxSize, totalSize)),
  50560. roundToInt (sizeWanted * availableSpace / totalIdealSize));
  50561. if (bestSize > layout->currentSize)
  50562. ++numWantingMoreSpace;
  50563. }
  50564. // ..share out the extra space..
  50565. for (i = startIndex; i < endIndex; ++i)
  50566. {
  50567. ItemLayoutProperties* const layout = items.getUnchecked (i);
  50568. double sizeWanted = sizeToRealSize (layout->preferredSize, availableSpace);
  50569. int bestSize = jlimit (layout->currentSize,
  50570. jmax (layout->currentSize, sizeToRealSize (layout->maxSize, totalSize)),
  50571. roundToInt (sizeWanted * availableSpace / totalIdealSize));
  50572. const int extraWanted = bestSize - layout->currentSize;
  50573. if (extraWanted > 0)
  50574. {
  50575. const int extraAllowed = jmin (extraWanted,
  50576. extraSpace / jmax (1, numWantingMoreSpace));
  50577. if (extraAllowed > 0)
  50578. {
  50579. ++numHavingTakenExtraSpace;
  50580. --numWantingMoreSpace;
  50581. layout->currentSize += extraAllowed;
  50582. extraSpace -= extraAllowed;
  50583. }
  50584. }
  50585. }
  50586. if (numHavingTakenExtraSpace <= 0)
  50587. break;
  50588. }
  50589. // ..and calculate the end position
  50590. for (i = startIndex; i < endIndex; ++i)
  50591. {
  50592. ItemLayoutProperties* const layout = items.getUnchecked(i);
  50593. startPos += layout->currentSize;
  50594. }
  50595. return startPos;
  50596. }
  50597. int StretchableLayoutManager::getMinimumSizeOfItems (const int startIndex,
  50598. const int endIndex) const
  50599. {
  50600. int totalMinimums = 0;
  50601. for (int i = startIndex; i < endIndex; ++i)
  50602. totalMinimums += sizeToRealSize (items.getUnchecked (i)->minSize, totalSize);
  50603. return totalMinimums;
  50604. }
  50605. int StretchableLayoutManager::getMaximumSizeOfItems (const int startIndex, const int endIndex) const
  50606. {
  50607. int totalMaximums = 0;
  50608. for (int i = startIndex; i < endIndex; ++i)
  50609. totalMaximums += sizeToRealSize (items.getUnchecked (i)->maxSize, totalSize);
  50610. return totalMaximums;
  50611. }
  50612. void StretchableLayoutManager::updatePrefSizesToMatchCurrentPositions()
  50613. {
  50614. for (int i = 0; i < items.size(); ++i)
  50615. {
  50616. ItemLayoutProperties* const layout = items.getUnchecked (i);
  50617. layout->preferredSize
  50618. = (layout->preferredSize < 0) ? getItemCurrentRelativeSize (i)
  50619. : getItemCurrentAbsoluteSize (i);
  50620. }
  50621. }
  50622. int StretchableLayoutManager::sizeToRealSize (double size, int totalSpace)
  50623. {
  50624. if (size < 0)
  50625. size *= -totalSpace;
  50626. return roundToInt (size);
  50627. }
  50628. END_JUCE_NAMESPACE
  50629. /*** End of inlined file: juce_StretchableLayoutManager.cpp ***/
  50630. /*** Start of inlined file: juce_StretchableLayoutResizerBar.cpp ***/
  50631. BEGIN_JUCE_NAMESPACE
  50632. StretchableLayoutResizerBar::StretchableLayoutResizerBar (StretchableLayoutManager* layout_,
  50633. const int itemIndex_,
  50634. const bool isVertical_)
  50635. : layout (layout_),
  50636. itemIndex (itemIndex_),
  50637. isVertical (isVertical_)
  50638. {
  50639. setRepaintsOnMouseActivity (true);
  50640. setMouseCursor (MouseCursor (isVertical_ ? MouseCursor::LeftRightResizeCursor
  50641. : MouseCursor::UpDownResizeCursor));
  50642. }
  50643. StretchableLayoutResizerBar::~StretchableLayoutResizerBar()
  50644. {
  50645. }
  50646. void StretchableLayoutResizerBar::paint (Graphics& g)
  50647. {
  50648. getLookAndFeel().drawStretchableLayoutResizerBar (g,
  50649. getWidth(), getHeight(),
  50650. isVertical,
  50651. isMouseOver(),
  50652. isMouseButtonDown());
  50653. }
  50654. void StretchableLayoutResizerBar::mouseDown (const MouseEvent&)
  50655. {
  50656. mouseDownPos = layout->getItemCurrentPosition (itemIndex);
  50657. }
  50658. void StretchableLayoutResizerBar::mouseDrag (const MouseEvent& e)
  50659. {
  50660. const int desiredPos = mouseDownPos + (isVertical ? e.getDistanceFromDragStartX()
  50661. : e.getDistanceFromDragStartY());
  50662. layout->setItemPosition (itemIndex, desiredPos);
  50663. hasBeenMoved();
  50664. }
  50665. void StretchableLayoutResizerBar::hasBeenMoved()
  50666. {
  50667. if (getParentComponent() != 0)
  50668. getParentComponent()->resized();
  50669. }
  50670. END_JUCE_NAMESPACE
  50671. /*** End of inlined file: juce_StretchableLayoutResizerBar.cpp ***/
  50672. /*** Start of inlined file: juce_StretchableObjectResizer.cpp ***/
  50673. BEGIN_JUCE_NAMESPACE
  50674. StretchableObjectResizer::StretchableObjectResizer()
  50675. {
  50676. }
  50677. StretchableObjectResizer::~StretchableObjectResizer()
  50678. {
  50679. }
  50680. void StretchableObjectResizer::addItem (const double size,
  50681. const double minSize, const double maxSize,
  50682. const int order)
  50683. {
  50684. // the order must be >= 0 but less than the maximum integer value.
  50685. jassert (order >= 0 && order < std::numeric_limits<int>::max());
  50686. Item* const item = new Item();
  50687. item->size = size;
  50688. item->minSize = minSize;
  50689. item->maxSize = maxSize;
  50690. item->order = order;
  50691. items.add (item);
  50692. }
  50693. double StretchableObjectResizer::getItemSize (const int index) const throw()
  50694. {
  50695. const Item* const it = items [index];
  50696. return it != 0 ? it->size : 0;
  50697. }
  50698. void StretchableObjectResizer::resizeToFit (const double targetSize)
  50699. {
  50700. int order = 0;
  50701. for (;;)
  50702. {
  50703. double currentSize = 0;
  50704. double minSize = 0;
  50705. double maxSize = 0;
  50706. int nextHighestOrder = std::numeric_limits<int>::max();
  50707. for (int i = 0; i < items.size(); ++i)
  50708. {
  50709. const Item* const it = items.getUnchecked(i);
  50710. currentSize += it->size;
  50711. if (it->order <= order)
  50712. {
  50713. minSize += it->minSize;
  50714. maxSize += it->maxSize;
  50715. }
  50716. else
  50717. {
  50718. minSize += it->size;
  50719. maxSize += it->size;
  50720. nextHighestOrder = jmin (nextHighestOrder, it->order);
  50721. }
  50722. }
  50723. const double thisIterationTarget = jlimit (minSize, maxSize, targetSize);
  50724. if (thisIterationTarget >= currentSize)
  50725. {
  50726. const double availableExtraSpace = maxSize - currentSize;
  50727. const double targetAmountOfExtraSpace = thisIterationTarget - currentSize;
  50728. const double scale = targetAmountOfExtraSpace / availableExtraSpace;
  50729. for (int i = 0; i < items.size(); ++i)
  50730. {
  50731. Item* const it = items.getUnchecked(i);
  50732. if (it->order <= order)
  50733. it->size = jmin (it->maxSize, it->size + (it->maxSize - it->size) * scale);
  50734. }
  50735. }
  50736. else
  50737. {
  50738. const double amountOfSlack = currentSize - minSize;
  50739. const double targetAmountOfSlack = thisIterationTarget - minSize;
  50740. const double scale = targetAmountOfSlack / amountOfSlack;
  50741. for (int i = 0; i < items.size(); ++i)
  50742. {
  50743. Item* const it = items.getUnchecked(i);
  50744. if (it->order <= order)
  50745. it->size = jmax (it->minSize, it->minSize + (it->size - it->minSize) * scale);
  50746. }
  50747. }
  50748. if (nextHighestOrder < std::numeric_limits<int>::max())
  50749. order = nextHighestOrder;
  50750. else
  50751. break;
  50752. }
  50753. }
  50754. END_JUCE_NAMESPACE
  50755. /*** End of inlined file: juce_StretchableObjectResizer.cpp ***/
  50756. /*** Start of inlined file: juce_TabbedButtonBar.cpp ***/
  50757. BEGIN_JUCE_NAMESPACE
  50758. TabBarButton::TabBarButton (const String& name,
  50759. TabbedButtonBar* const owner_,
  50760. const int index)
  50761. : Button (name),
  50762. owner (owner_),
  50763. tabIndex (index),
  50764. overlapPixels (0)
  50765. {
  50766. shadow.setShadowProperties (2.2f, 0.7f, 0, 0);
  50767. setComponentEffect (&shadow);
  50768. setWantsKeyboardFocus (false);
  50769. }
  50770. TabBarButton::~TabBarButton()
  50771. {
  50772. }
  50773. void TabBarButton::paintButton (Graphics& g,
  50774. bool isMouseOverButton,
  50775. bool isButtonDown)
  50776. {
  50777. int x, y, w, h;
  50778. getActiveArea (x, y, w, h);
  50779. g.setOrigin (x, y);
  50780. getLookAndFeel()
  50781. .drawTabButton (g, w, h,
  50782. owner->getTabBackgroundColour (tabIndex),
  50783. tabIndex, getButtonText(), *this,
  50784. owner->getOrientation(),
  50785. isMouseOverButton, isButtonDown,
  50786. getToggleState());
  50787. }
  50788. void TabBarButton::clicked (const ModifierKeys& mods)
  50789. {
  50790. if (mods.isPopupMenu())
  50791. owner->popupMenuClickOnTab (tabIndex, getButtonText());
  50792. else
  50793. owner->setCurrentTabIndex (tabIndex);
  50794. }
  50795. bool TabBarButton::hitTest (int mx, int my)
  50796. {
  50797. int x, y, w, h;
  50798. getActiveArea (x, y, w, h);
  50799. if (owner->getOrientation() == TabbedButtonBar::TabsAtLeft
  50800. || owner->getOrientation() == TabbedButtonBar::TabsAtRight)
  50801. {
  50802. if (((unsigned int) mx) < (unsigned int) getWidth()
  50803. && my >= y + overlapPixels
  50804. && my < y + h - overlapPixels)
  50805. return true;
  50806. }
  50807. else
  50808. {
  50809. if (mx >= x + overlapPixels && mx < x + w - overlapPixels
  50810. && ((unsigned int) my) < (unsigned int) getHeight())
  50811. return true;
  50812. }
  50813. Path p;
  50814. getLookAndFeel()
  50815. .createTabButtonShape (p, w, h, tabIndex, getButtonText(), *this,
  50816. owner->getOrientation(),
  50817. false, false, getToggleState());
  50818. return p.contains ((float) (mx - x),
  50819. (float) (my - y));
  50820. }
  50821. int TabBarButton::getBestTabLength (const int depth)
  50822. {
  50823. return jlimit (depth * 2,
  50824. depth * 7,
  50825. getLookAndFeel().getTabButtonBestWidth (tabIndex, getButtonText(), depth, *this));
  50826. }
  50827. void TabBarButton::getActiveArea (int& x, int& y, int& w, int& h)
  50828. {
  50829. x = 0;
  50830. y = 0;
  50831. int r = getWidth();
  50832. int b = getHeight();
  50833. const int spaceAroundImage = getLookAndFeel().getTabButtonSpaceAroundImage();
  50834. if (owner->getOrientation() != TabbedButtonBar::TabsAtLeft)
  50835. r -= spaceAroundImage;
  50836. if (owner->getOrientation() != TabbedButtonBar::TabsAtRight)
  50837. x += spaceAroundImage;
  50838. if (owner->getOrientation() != TabbedButtonBar::TabsAtBottom)
  50839. y += spaceAroundImage;
  50840. if (owner->getOrientation() != TabbedButtonBar::TabsAtTop)
  50841. b -= spaceAroundImage;
  50842. w = r - x;
  50843. h = b - y;
  50844. }
  50845. class TabAreaBehindFrontButtonComponent : public Component
  50846. {
  50847. public:
  50848. TabAreaBehindFrontButtonComponent (TabbedButtonBar* const owner_)
  50849. : owner (owner_)
  50850. {
  50851. setInterceptsMouseClicks (false, false);
  50852. }
  50853. ~TabAreaBehindFrontButtonComponent()
  50854. {
  50855. }
  50856. void paint (Graphics& g)
  50857. {
  50858. getLookAndFeel()
  50859. .drawTabAreaBehindFrontButton (g, getWidth(), getHeight(),
  50860. *owner, owner->getOrientation());
  50861. }
  50862. void enablementChanged()
  50863. {
  50864. repaint();
  50865. }
  50866. private:
  50867. TabbedButtonBar* const owner;
  50868. TabAreaBehindFrontButtonComponent (const TabAreaBehindFrontButtonComponent&);
  50869. const TabAreaBehindFrontButtonComponent& operator= (const TabAreaBehindFrontButtonComponent&);
  50870. };
  50871. TabbedButtonBar::TabbedButtonBar (const Orientation orientation_)
  50872. : orientation (orientation_),
  50873. currentTabIndex (-1),
  50874. extraTabsButton (0)
  50875. {
  50876. setInterceptsMouseClicks (false, true);
  50877. addAndMakeVisible (behindFrontTab = new TabAreaBehindFrontButtonComponent (this));
  50878. setFocusContainer (true);
  50879. }
  50880. TabbedButtonBar::~TabbedButtonBar()
  50881. {
  50882. deleteAllChildren();
  50883. }
  50884. void TabbedButtonBar::setOrientation (const Orientation newOrientation)
  50885. {
  50886. orientation = newOrientation;
  50887. for (int i = getNumChildComponents(); --i >= 0;)
  50888. getChildComponent (i)->resized();
  50889. resized();
  50890. }
  50891. TabBarButton* TabbedButtonBar::createTabButton (const String& name, const int index)
  50892. {
  50893. return new TabBarButton (name, this, index);
  50894. }
  50895. void TabbedButtonBar::clearTabs()
  50896. {
  50897. tabs.clear();
  50898. tabColours.clear();
  50899. currentTabIndex = -1;
  50900. deleteAndZero (extraTabsButton);
  50901. removeChildComponent (behindFrontTab);
  50902. deleteAllChildren();
  50903. addChildComponent (behindFrontTab);
  50904. setCurrentTabIndex (-1);
  50905. }
  50906. void TabbedButtonBar::addTab (const String& tabName,
  50907. const Colour& tabBackgroundColour,
  50908. int insertIndex)
  50909. {
  50910. jassert (tabName.isNotEmpty()); // you have to give them all a name..
  50911. if (tabName.isNotEmpty())
  50912. {
  50913. if (((unsigned int) insertIndex) > (unsigned int) tabs.size())
  50914. insertIndex = tabs.size();
  50915. for (int i = tabs.size(); --i >= insertIndex;)
  50916. {
  50917. TabBarButton* const tb = getTabButton (i);
  50918. if (tb != 0)
  50919. tb->tabIndex++;
  50920. }
  50921. tabs.insert (insertIndex, tabName);
  50922. tabColours.insert (insertIndex, tabBackgroundColour);
  50923. TabBarButton* const tb = createTabButton (tabName, insertIndex);
  50924. jassert (tb != 0); // your createTabButton() mustn't return zero!
  50925. addAndMakeVisible (tb, insertIndex);
  50926. resized();
  50927. if (currentTabIndex < 0)
  50928. setCurrentTabIndex (0);
  50929. }
  50930. }
  50931. void TabbedButtonBar::setTabName (const int tabIndex,
  50932. const String& newName)
  50933. {
  50934. if (((unsigned int) tabIndex) < (unsigned int) tabs.size()
  50935. && tabs[tabIndex] != newName)
  50936. {
  50937. tabs.set (tabIndex, newName);
  50938. TabBarButton* const tb = getTabButton (tabIndex);
  50939. if (tb != 0)
  50940. tb->setButtonText (newName);
  50941. resized();
  50942. }
  50943. }
  50944. void TabbedButtonBar::removeTab (const int tabIndex)
  50945. {
  50946. if (((unsigned int) tabIndex) < (unsigned int) tabs.size())
  50947. {
  50948. const int oldTabIndex = currentTabIndex;
  50949. if (currentTabIndex == tabIndex)
  50950. currentTabIndex = -1;
  50951. tabs.remove (tabIndex);
  50952. tabColours.remove (tabIndex);
  50953. delete getTabButton (tabIndex);
  50954. for (int i = tabIndex + 1; i <= tabs.size(); ++i)
  50955. {
  50956. TabBarButton* const tb = getTabButton (i);
  50957. if (tb != 0)
  50958. tb->tabIndex--;
  50959. }
  50960. resized();
  50961. setCurrentTabIndex (jlimit (0, jmax (0, tabs.size() - 1), oldTabIndex));
  50962. }
  50963. }
  50964. void TabbedButtonBar::moveTab (const int currentIndex,
  50965. const int newIndex)
  50966. {
  50967. tabs.move (currentIndex, newIndex);
  50968. tabColours.move (currentIndex, newIndex);
  50969. resized();
  50970. }
  50971. int TabbedButtonBar::getNumTabs() const
  50972. {
  50973. return tabs.size();
  50974. }
  50975. const StringArray TabbedButtonBar::getTabNames() const
  50976. {
  50977. return tabs;
  50978. }
  50979. void TabbedButtonBar::setCurrentTabIndex (int newIndex, const bool sendChangeMessage_)
  50980. {
  50981. if (currentTabIndex != newIndex)
  50982. {
  50983. if (((unsigned int) newIndex) >= (unsigned int) tabs.size())
  50984. newIndex = -1;
  50985. currentTabIndex = newIndex;
  50986. for (int i = 0; i < getNumChildComponents(); ++i)
  50987. {
  50988. TabBarButton* const tb = dynamic_cast <TabBarButton*> (getChildComponent (i));
  50989. if (tb != 0)
  50990. tb->setToggleState (tb->tabIndex == newIndex, false);
  50991. }
  50992. resized();
  50993. if (sendChangeMessage_)
  50994. sendChangeMessage (this);
  50995. currentTabChanged (newIndex, newIndex >= 0 ? tabs [newIndex] : String::empty);
  50996. }
  50997. }
  50998. TabBarButton* TabbedButtonBar::getTabButton (const int index) const
  50999. {
  51000. for (int i = getNumChildComponents(); --i >= 0;)
  51001. {
  51002. TabBarButton* const tb = dynamic_cast <TabBarButton*> (getChildComponent (i));
  51003. if (tb != 0 && tb->tabIndex == index)
  51004. return tb;
  51005. }
  51006. return 0;
  51007. }
  51008. void TabbedButtonBar::lookAndFeelChanged()
  51009. {
  51010. deleteAndZero (extraTabsButton);
  51011. resized();
  51012. }
  51013. void TabbedButtonBar::resized()
  51014. {
  51015. const double minimumScale = 0.7;
  51016. int depth = getWidth();
  51017. int length = getHeight();
  51018. if (orientation == TabsAtTop || orientation == TabsAtBottom)
  51019. swapVariables (depth, length);
  51020. const int overlap = getLookAndFeel().getTabButtonOverlap (depth)
  51021. + getLookAndFeel().getTabButtonSpaceAroundImage() * 2;
  51022. int i, totalLength = overlap;
  51023. int numVisibleButtons = tabs.size();
  51024. for (i = 0; i < getNumChildComponents(); ++i)
  51025. {
  51026. TabBarButton* const tb = dynamic_cast <TabBarButton*> (getChildComponent (i));
  51027. if (tb != 0)
  51028. {
  51029. totalLength += tb->getBestTabLength (depth) - overlap;
  51030. tb->overlapPixels = overlap / 2;
  51031. }
  51032. }
  51033. double scale = 1.0;
  51034. if (totalLength > length)
  51035. scale = jmax (minimumScale, length / (double) totalLength);
  51036. const bool isTooBig = totalLength * scale > length;
  51037. int tabsButtonPos = 0;
  51038. if (isTooBig)
  51039. {
  51040. if (extraTabsButton == 0)
  51041. {
  51042. addAndMakeVisible (extraTabsButton = getLookAndFeel().createTabBarExtrasButton());
  51043. extraTabsButton->addButtonListener (this);
  51044. extraTabsButton->setAlwaysOnTop (true);
  51045. extraTabsButton->setTriggeredOnMouseDown (true);
  51046. }
  51047. const int buttonSize = jmin (proportionOfWidth (0.7f), proportionOfHeight (0.7f));
  51048. extraTabsButton->setSize (buttonSize, buttonSize);
  51049. if (orientation == TabsAtTop || orientation == TabsAtBottom)
  51050. {
  51051. tabsButtonPos = getWidth() - buttonSize / 2 - 1;
  51052. extraTabsButton->setCentrePosition (tabsButtonPos, getHeight() / 2);
  51053. }
  51054. else
  51055. {
  51056. tabsButtonPos = getHeight() - buttonSize / 2 - 1;
  51057. extraTabsButton->setCentrePosition (getWidth() / 2, tabsButtonPos);
  51058. }
  51059. totalLength = 0;
  51060. for (i = 0; i < tabs.size(); ++i)
  51061. {
  51062. TabBarButton* const tb = getTabButton (i);
  51063. if (tb != 0)
  51064. {
  51065. const int newLength = totalLength + tb->getBestTabLength (depth);
  51066. if (i > 0 && newLength * minimumScale > tabsButtonPos)
  51067. {
  51068. totalLength += overlap;
  51069. break;
  51070. }
  51071. numVisibleButtons = i + 1;
  51072. totalLength = newLength - overlap;
  51073. }
  51074. }
  51075. scale = jmax (minimumScale, tabsButtonPos / (double) totalLength);
  51076. }
  51077. else
  51078. {
  51079. deleteAndZero (extraTabsButton);
  51080. }
  51081. int pos = 0;
  51082. TabBarButton* frontTab = 0;
  51083. for (i = 0; i < tabs.size(); ++i)
  51084. {
  51085. TabBarButton* const tb = getTabButton (i);
  51086. if (tb != 0)
  51087. {
  51088. const int bestLength = roundToInt (scale * tb->getBestTabLength (depth));
  51089. if (i < numVisibleButtons)
  51090. {
  51091. if (orientation == TabsAtTop || orientation == TabsAtBottom)
  51092. tb->setBounds (pos, 0, bestLength, getHeight());
  51093. else
  51094. tb->setBounds (0, pos, getWidth(), bestLength);
  51095. tb->toBack();
  51096. if (tb->tabIndex == currentTabIndex)
  51097. frontTab = tb;
  51098. tb->setVisible (true);
  51099. }
  51100. else
  51101. {
  51102. tb->setVisible (false);
  51103. }
  51104. pos += bestLength - overlap;
  51105. }
  51106. }
  51107. behindFrontTab->setBounds (0, 0, getWidth(), getHeight());
  51108. if (frontTab != 0)
  51109. {
  51110. frontTab->toFront (false);
  51111. behindFrontTab->toBehind (frontTab);
  51112. }
  51113. }
  51114. const Colour TabbedButtonBar::getTabBackgroundColour (const int tabIndex)
  51115. {
  51116. return tabColours [tabIndex];
  51117. }
  51118. void TabbedButtonBar::setTabBackgroundColour (const int tabIndex, const Colour& newColour)
  51119. {
  51120. if (((unsigned int) tabIndex) < (unsigned int) tabColours.size()
  51121. && tabColours [tabIndex] != newColour)
  51122. {
  51123. tabColours.set (tabIndex, newColour);
  51124. repaint();
  51125. }
  51126. }
  51127. void TabbedButtonBar::buttonClicked (Button* button)
  51128. {
  51129. if (extraTabsButton == button)
  51130. {
  51131. PopupMenu m;
  51132. for (int i = 0; i < tabs.size(); ++i)
  51133. {
  51134. TabBarButton* const tb = getTabButton (i);
  51135. if (tb != 0 && ! tb->isVisible())
  51136. m.addItem (tb->tabIndex + 1, tabs[i], true, i == currentTabIndex);
  51137. }
  51138. const int res = m.showAt (extraTabsButton);
  51139. if (res != 0)
  51140. setCurrentTabIndex (res - 1);
  51141. }
  51142. }
  51143. void TabbedButtonBar::currentTabChanged (const int, const String&)
  51144. {
  51145. }
  51146. void TabbedButtonBar::popupMenuClickOnTab (const int, const String&)
  51147. {
  51148. }
  51149. END_JUCE_NAMESPACE
  51150. /*** End of inlined file: juce_TabbedButtonBar.cpp ***/
  51151. /*** Start of inlined file: juce_TabbedComponent.cpp ***/
  51152. BEGIN_JUCE_NAMESPACE
  51153. class TabCompButtonBar : public TabbedButtonBar
  51154. {
  51155. public:
  51156. TabCompButtonBar (TabbedComponent* const owner_,
  51157. const TabbedButtonBar::Orientation orientation)
  51158. : TabbedButtonBar (orientation),
  51159. owner (owner_)
  51160. {
  51161. }
  51162. ~TabCompButtonBar()
  51163. {
  51164. }
  51165. void currentTabChanged (const int newCurrentTabIndex,
  51166. const String& newTabName)
  51167. {
  51168. owner->changeCallback (newCurrentTabIndex, newTabName);
  51169. }
  51170. void popupMenuClickOnTab (const int tabIndex,
  51171. const String& tabName)
  51172. {
  51173. owner->popupMenuClickOnTab (tabIndex, tabName);
  51174. }
  51175. const Colour getTabBackgroundColour (const int tabIndex)
  51176. {
  51177. return owner->tabs->getTabBackgroundColour (tabIndex);
  51178. }
  51179. TabBarButton* createTabButton (const String& tabName, const int tabIndex)
  51180. {
  51181. return owner->createTabButton (tabName, tabIndex);
  51182. }
  51183. juce_UseDebuggingNewOperator
  51184. private:
  51185. TabbedComponent* const owner;
  51186. TabCompButtonBar (const TabCompButtonBar&);
  51187. const TabCompButtonBar& operator= (const TabCompButtonBar&);
  51188. };
  51189. TabbedComponent::TabbedComponent (const TabbedButtonBar::Orientation orientation)
  51190. : panelComponent (0),
  51191. tabDepth (30),
  51192. outlineThickness (1),
  51193. edgeIndent (0)
  51194. {
  51195. addAndMakeVisible (tabs = new TabCompButtonBar (this, orientation));
  51196. }
  51197. TabbedComponent::~TabbedComponent()
  51198. {
  51199. clearTabs();
  51200. delete tabs;
  51201. }
  51202. void TabbedComponent::setOrientation (const TabbedButtonBar::Orientation orientation)
  51203. {
  51204. tabs->setOrientation (orientation);
  51205. resized();
  51206. }
  51207. TabbedButtonBar::Orientation TabbedComponent::getOrientation() const throw()
  51208. {
  51209. return tabs->getOrientation();
  51210. }
  51211. void TabbedComponent::setTabBarDepth (const int newDepth)
  51212. {
  51213. if (tabDepth != newDepth)
  51214. {
  51215. tabDepth = newDepth;
  51216. resized();
  51217. }
  51218. }
  51219. TabBarButton* TabbedComponent::createTabButton (const String& tabName, const int tabIndex)
  51220. {
  51221. return new TabBarButton (tabName, tabs, tabIndex);
  51222. }
  51223. void TabbedComponent::clearTabs()
  51224. {
  51225. if (panelComponent != 0)
  51226. {
  51227. panelComponent->setVisible (false);
  51228. removeChildComponent (panelComponent);
  51229. panelComponent = 0;
  51230. }
  51231. tabs->clearTabs();
  51232. for (int i = contentComponents.size(); --i >= 0;)
  51233. {
  51234. Component* const c = contentComponents.getUnchecked(i);
  51235. // be careful not to delete these components until they've been removed from the tab component
  51236. jassert (c == 0 || c->isValidComponent());
  51237. if (c != 0 && c->getProperties() ["deleteByTabComp_"])
  51238. delete c;
  51239. }
  51240. contentComponents.clear();
  51241. }
  51242. void TabbedComponent::addTab (const String& tabName,
  51243. const Colour& tabBackgroundColour,
  51244. Component* const contentComponent,
  51245. const bool deleteComponentWhenNotNeeded,
  51246. const int insertIndex)
  51247. {
  51248. contentComponents.insert (insertIndex, contentComponent);
  51249. if (contentComponent != 0)
  51250. contentComponent->getProperties().set ("deleteByTabComp_", deleteComponentWhenNotNeeded);
  51251. tabs->addTab (tabName, tabBackgroundColour, insertIndex);
  51252. }
  51253. void TabbedComponent::setTabName (const int tabIndex,
  51254. const String& newName)
  51255. {
  51256. tabs->setTabName (tabIndex, newName);
  51257. }
  51258. void TabbedComponent::removeTab (const int tabIndex)
  51259. {
  51260. Component* const c = contentComponents [tabIndex];
  51261. if (c != 0 && c->getProperties() ["deleteByTabComp_"])
  51262. {
  51263. if (c == panelComponent)
  51264. panelComponent = 0;
  51265. delete c;
  51266. }
  51267. contentComponents.remove (tabIndex);
  51268. tabs->removeTab (tabIndex);
  51269. }
  51270. int TabbedComponent::getNumTabs() const
  51271. {
  51272. return tabs->getNumTabs();
  51273. }
  51274. const StringArray TabbedComponent::getTabNames() const
  51275. {
  51276. return tabs->getTabNames();
  51277. }
  51278. Component* TabbedComponent::getTabContentComponent (const int tabIndex) const throw()
  51279. {
  51280. return contentComponents [tabIndex];
  51281. }
  51282. const Colour TabbedComponent::getTabBackgroundColour (const int tabIndex) const throw()
  51283. {
  51284. return tabs->getTabBackgroundColour (tabIndex);
  51285. }
  51286. void TabbedComponent::setTabBackgroundColour (const int tabIndex, const Colour& newColour)
  51287. {
  51288. tabs->setTabBackgroundColour (tabIndex, newColour);
  51289. if (getCurrentTabIndex() == tabIndex)
  51290. repaint();
  51291. }
  51292. void TabbedComponent::setCurrentTabIndex (const int newTabIndex, const bool sendChangeMessage)
  51293. {
  51294. tabs->setCurrentTabIndex (newTabIndex, sendChangeMessage);
  51295. }
  51296. int TabbedComponent::getCurrentTabIndex() const
  51297. {
  51298. return tabs->getCurrentTabIndex();
  51299. }
  51300. const String& TabbedComponent::getCurrentTabName() const
  51301. {
  51302. return tabs->getCurrentTabName();
  51303. }
  51304. void TabbedComponent::setOutline (int thickness)
  51305. {
  51306. outlineThickness = thickness;
  51307. repaint();
  51308. }
  51309. void TabbedComponent::setIndent (const int indentThickness)
  51310. {
  51311. edgeIndent = indentThickness;
  51312. }
  51313. void TabbedComponent::paint (Graphics& g)
  51314. {
  51315. g.fillAll (findColour (backgroundColourId));
  51316. const TabbedButtonBar::Orientation o = getOrientation();
  51317. int x = 0;
  51318. int y = 0;
  51319. int r = getWidth();
  51320. int b = getHeight();
  51321. if (o == TabbedButtonBar::TabsAtTop)
  51322. y += tabDepth;
  51323. else if (o == TabbedButtonBar::TabsAtBottom)
  51324. b -= tabDepth;
  51325. else if (o == TabbedButtonBar::TabsAtLeft)
  51326. x += tabDepth;
  51327. else if (o == TabbedButtonBar::TabsAtRight)
  51328. r -= tabDepth;
  51329. g.reduceClipRegion (x, y, r - x, b - y);
  51330. g.fillAll (tabs->getTabBackgroundColour (getCurrentTabIndex()));
  51331. if (outlineThickness > 0)
  51332. {
  51333. if (o == TabbedButtonBar::TabsAtTop)
  51334. --y;
  51335. else if (o == TabbedButtonBar::TabsAtBottom)
  51336. ++b;
  51337. else if (o == TabbedButtonBar::TabsAtLeft)
  51338. --x;
  51339. else if (o == TabbedButtonBar::TabsAtRight)
  51340. ++r;
  51341. g.setColour (findColour (outlineColourId));
  51342. g.drawRect (x, y, r - x, b - y, outlineThickness);
  51343. }
  51344. }
  51345. void TabbedComponent::resized()
  51346. {
  51347. const TabbedButtonBar::Orientation o = getOrientation();
  51348. const int indent = edgeIndent + outlineThickness;
  51349. BorderSize indents (indent);
  51350. if (o == TabbedButtonBar::TabsAtTop)
  51351. {
  51352. tabs->setBounds (0, 0, getWidth(), tabDepth);
  51353. indents.setTop (tabDepth + edgeIndent);
  51354. }
  51355. else if (o == TabbedButtonBar::TabsAtBottom)
  51356. {
  51357. tabs->setBounds (0, getHeight() - tabDepth, getWidth(), tabDepth);
  51358. indents.setBottom (tabDepth + edgeIndent);
  51359. }
  51360. else if (o == TabbedButtonBar::TabsAtLeft)
  51361. {
  51362. tabs->setBounds (0, 0, tabDepth, getHeight());
  51363. indents.setLeft (tabDepth + edgeIndent);
  51364. }
  51365. else if (o == TabbedButtonBar::TabsAtRight)
  51366. {
  51367. tabs->setBounds (getWidth() - tabDepth, 0, tabDepth, getHeight());
  51368. indents.setRight (tabDepth + edgeIndent);
  51369. }
  51370. const Rectangle<int> bounds (indents.subtractedFrom (Rectangle<int> (0, 0, getWidth(), getHeight())));
  51371. for (int i = contentComponents.size(); --i >= 0;)
  51372. if (contentComponents.getUnchecked (i) != 0)
  51373. contentComponents.getUnchecked (i)->setBounds (bounds);
  51374. }
  51375. void TabbedComponent::lookAndFeelChanged()
  51376. {
  51377. for (int i = contentComponents.size(); --i >= 0;)
  51378. if (contentComponents.getUnchecked (i) != 0)
  51379. contentComponents.getUnchecked (i)->lookAndFeelChanged();
  51380. }
  51381. void TabbedComponent::changeCallback (const int newCurrentTabIndex,
  51382. const String& newTabName)
  51383. {
  51384. if (panelComponent != 0)
  51385. {
  51386. panelComponent->setVisible (false);
  51387. removeChildComponent (panelComponent);
  51388. panelComponent = 0;
  51389. }
  51390. if (getCurrentTabIndex() >= 0)
  51391. {
  51392. panelComponent = contentComponents [getCurrentTabIndex()];
  51393. if (panelComponent != 0)
  51394. {
  51395. // do these ops as two stages instead of addAndMakeVisible() so that the
  51396. // component has always got a parent when it gets the visibilityChanged() callback
  51397. addChildComponent (panelComponent);
  51398. panelComponent->setVisible (true);
  51399. panelComponent->toFront (true);
  51400. }
  51401. repaint();
  51402. }
  51403. resized();
  51404. currentTabChanged (newCurrentTabIndex, newTabName);
  51405. }
  51406. void TabbedComponent::currentTabChanged (const int, const String&)
  51407. {
  51408. }
  51409. void TabbedComponent::popupMenuClickOnTab (const int, const String&)
  51410. {
  51411. }
  51412. END_JUCE_NAMESPACE
  51413. /*** End of inlined file: juce_TabbedComponent.cpp ***/
  51414. /*** Start of inlined file: juce_Viewport.cpp ***/
  51415. BEGIN_JUCE_NAMESPACE
  51416. Viewport::Viewport (const String& componentName)
  51417. : Component (componentName),
  51418. contentComp (0),
  51419. lastVX (0),
  51420. lastVY (0),
  51421. lastVW (0),
  51422. lastVH (0),
  51423. scrollBarThickness (0),
  51424. singleStepX (16),
  51425. singleStepY (16),
  51426. showHScrollbar (true),
  51427. showVScrollbar (true)
  51428. {
  51429. // content holder is used to clip the contents so they don't overlap the scrollbars
  51430. addAndMakeVisible (contentHolder = new Component());
  51431. contentHolder->setInterceptsMouseClicks (false, true);
  51432. verticalScrollBar = new ScrollBar (true);
  51433. horizontalScrollBar = new ScrollBar (false);
  51434. addChildComponent (verticalScrollBar);
  51435. addChildComponent (horizontalScrollBar);
  51436. verticalScrollBar->addListener (this);
  51437. horizontalScrollBar->addListener (this);
  51438. setInterceptsMouseClicks (false, true);
  51439. setWantsKeyboardFocus (true);
  51440. }
  51441. Viewport::~Viewport()
  51442. {
  51443. contentHolder->deleteAllChildren();
  51444. deleteAllChildren();
  51445. }
  51446. void Viewport::visibleAreaChanged (int, int, int, int)
  51447. {
  51448. }
  51449. void Viewport::setViewedComponent (Component* const newViewedComponent)
  51450. {
  51451. if (contentComp != newViewedComponent)
  51452. {
  51453. if (contentComp->isValidComponent())
  51454. {
  51455. Component* const oldComp = contentComp;
  51456. contentComp = 0;
  51457. delete oldComp;
  51458. }
  51459. contentComp = newViewedComponent;
  51460. if (contentComp != 0)
  51461. {
  51462. contentComp->setTopLeftPosition (0, 0);
  51463. contentHolder->addAndMakeVisible (contentComp);
  51464. contentComp->addComponentListener (this);
  51465. }
  51466. updateVisibleRegion();
  51467. }
  51468. }
  51469. int Viewport::getMaximumVisibleWidth() const throw()
  51470. {
  51471. return jmax (0, getWidth() - (verticalScrollBar->isVisible() ? getScrollBarThickness() : 0));
  51472. }
  51473. int Viewport::getMaximumVisibleHeight() const throw()
  51474. {
  51475. return jmax (0, getHeight() - (horizontalScrollBar->isVisible() ? getScrollBarThickness() : 0));
  51476. }
  51477. void Viewport::setViewPosition (const int xPixelsOffset,
  51478. const int yPixelsOffset)
  51479. {
  51480. if (contentComp != 0)
  51481. contentComp->setTopLeftPosition (-xPixelsOffset,
  51482. -yPixelsOffset);
  51483. }
  51484. void Viewport::setViewPositionProportionately (const double x,
  51485. const double y)
  51486. {
  51487. if (contentComp != 0)
  51488. setViewPosition (jmax (0, roundToInt (x * (contentComp->getWidth() - getWidth()))),
  51489. jmax (0, roundToInt (y * (contentComp->getHeight() - getHeight()))));
  51490. }
  51491. bool Viewport::autoScroll (int mouseX, int mouseY, int activeBorderThickness, int maximumSpeed)
  51492. {
  51493. if (contentComp != 0)
  51494. {
  51495. int dx = 0, dy = 0;
  51496. if (mouseX < activeBorderThickness)
  51497. dx = activeBorderThickness - mouseX;
  51498. else if (mouseX >= contentHolder->getWidth() - activeBorderThickness)
  51499. dx = (contentHolder->getWidth() - activeBorderThickness) - mouseX;
  51500. if (dx < 0)
  51501. dx = jmax (dx, -maximumSpeed, contentHolder->getWidth() - contentComp->getRight());
  51502. else
  51503. dx = jmin (dx, maximumSpeed, -contentComp->getX());
  51504. if (mouseY < activeBorderThickness)
  51505. dy = activeBorderThickness - mouseY;
  51506. else if (mouseY >= contentHolder->getHeight() - activeBorderThickness)
  51507. dy = (contentHolder->getHeight() - activeBorderThickness) - mouseY;
  51508. if (dy < 0)
  51509. dy = jmax (dy, -maximumSpeed, contentHolder->getHeight() - contentComp->getBottom());
  51510. else
  51511. dy = jmin (dy, maximumSpeed, -contentComp->getY());
  51512. if (dx != 0 || dy != 0)
  51513. {
  51514. contentComp->setTopLeftPosition (contentComp->getX() + dx,
  51515. contentComp->getY() + dy);
  51516. return true;
  51517. }
  51518. }
  51519. return false;
  51520. }
  51521. void Viewport::componentMovedOrResized (Component&, bool, bool)
  51522. {
  51523. updateVisibleRegion();
  51524. }
  51525. void Viewport::resized()
  51526. {
  51527. updateVisibleRegion();
  51528. }
  51529. void Viewport::updateVisibleRegion()
  51530. {
  51531. if (contentComp != 0)
  51532. {
  51533. const int newVX = -contentComp->getX();
  51534. const int newVY = -contentComp->getY();
  51535. if (newVX == 0 && newVY == 0
  51536. && contentComp->getWidth() <= getWidth()
  51537. && contentComp->getHeight() <= getHeight())
  51538. {
  51539. horizontalScrollBar->setVisible (false);
  51540. verticalScrollBar->setVisible (false);
  51541. }
  51542. horizontalScrollBar->setRangeLimits (0.0, contentComp->getWidth());
  51543. horizontalScrollBar->setCurrentRange (newVX, getMaximumVisibleWidth());
  51544. horizontalScrollBar->setSingleStepSize (singleStepX);
  51545. if (! (contentComp->getWidth() > 0 && showHScrollbar && getHeight() > getScrollBarThickness()))
  51546. horizontalScrollBar->setVisible (false);
  51547. verticalScrollBar->setRangeLimits (0.0, contentComp->getHeight());
  51548. verticalScrollBar->setCurrentRange (newVY, getMaximumVisibleHeight());
  51549. verticalScrollBar->setSingleStepSize (singleStepY);
  51550. if (! (contentComp->getHeight() > 0 && showVScrollbar && getWidth() > getScrollBarThickness()))
  51551. verticalScrollBar->setVisible (false);
  51552. if (verticalScrollBar->isVisible())
  51553. {
  51554. horizontalScrollBar->setCurrentRange (newVX, getMaximumVisibleWidth());
  51555. verticalScrollBar->setCurrentRange (newVY, getMaximumVisibleHeight());
  51556. verticalScrollBar
  51557. ->setBounds (getMaximumVisibleWidth(), 0,
  51558. getScrollBarThickness(), getMaximumVisibleHeight());
  51559. }
  51560. if (horizontalScrollBar->isVisible())
  51561. {
  51562. horizontalScrollBar->setCurrentRange (newVX, getMaximumVisibleWidth());
  51563. horizontalScrollBar
  51564. ->setBounds (0, getMaximumVisibleHeight(),
  51565. getMaximumVisibleWidth(), getScrollBarThickness());
  51566. }
  51567. contentHolder->setSize (getMaximumVisibleWidth(),
  51568. getMaximumVisibleHeight());
  51569. const int newVW = jmin (contentComp->getRight(), getMaximumVisibleWidth());
  51570. const int newVH = jmin (contentComp->getBottom(), getMaximumVisibleHeight());
  51571. if (newVX != lastVX
  51572. || newVY != lastVY
  51573. || newVW != lastVW
  51574. || newVH != lastVH)
  51575. {
  51576. lastVX = newVX;
  51577. lastVY = newVY;
  51578. lastVW = newVW;
  51579. lastVH = newVH;
  51580. visibleAreaChanged (newVX, newVY, newVW, newVH);
  51581. }
  51582. horizontalScrollBar->handleUpdateNowIfNeeded();
  51583. verticalScrollBar->handleUpdateNowIfNeeded();
  51584. }
  51585. else
  51586. {
  51587. horizontalScrollBar->setVisible (false);
  51588. verticalScrollBar->setVisible (false);
  51589. }
  51590. }
  51591. void Viewport::setSingleStepSizes (const int stepX,
  51592. const int stepY)
  51593. {
  51594. singleStepX = stepX;
  51595. singleStepY = stepY;
  51596. updateVisibleRegion();
  51597. }
  51598. void Viewport::setScrollBarsShown (const bool showVerticalScrollbarIfNeeded,
  51599. const bool showHorizontalScrollbarIfNeeded)
  51600. {
  51601. showVScrollbar = showVerticalScrollbarIfNeeded;
  51602. showHScrollbar = showHorizontalScrollbarIfNeeded;
  51603. updateVisibleRegion();
  51604. }
  51605. void Viewport::setScrollBarThickness (const int thickness)
  51606. {
  51607. scrollBarThickness = thickness;
  51608. updateVisibleRegion();
  51609. }
  51610. int Viewport::getScrollBarThickness() const throw()
  51611. {
  51612. return (scrollBarThickness > 0) ? scrollBarThickness
  51613. : getLookAndFeel().getDefaultScrollbarWidth();
  51614. }
  51615. void Viewport::setScrollBarButtonVisibility (const bool buttonsVisible)
  51616. {
  51617. verticalScrollBar->setButtonVisibility (buttonsVisible);
  51618. horizontalScrollBar->setButtonVisibility (buttonsVisible);
  51619. }
  51620. void Viewport::scrollBarMoved (ScrollBar* scrollBarThatHasMoved, const double newRangeStart)
  51621. {
  51622. if (scrollBarThatHasMoved == horizontalScrollBar)
  51623. {
  51624. setViewPosition (roundToInt (newRangeStart), getViewPositionY());
  51625. }
  51626. else if (scrollBarThatHasMoved == verticalScrollBar)
  51627. {
  51628. setViewPosition (getViewPositionX(), roundToInt (newRangeStart));
  51629. }
  51630. }
  51631. void Viewport::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  51632. {
  51633. if (! useMouseWheelMoveIfNeeded (e, wheelIncrementX, wheelIncrementY))
  51634. Component::mouseWheelMove (e, wheelIncrementX, wheelIncrementY);
  51635. }
  51636. bool Viewport::useMouseWheelMoveIfNeeded (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  51637. {
  51638. if (! (e.mods.isAltDown() || e.mods.isCtrlDown()))
  51639. {
  51640. const bool hasVertBar = verticalScrollBar->isVisible();
  51641. const bool hasHorzBar = horizontalScrollBar->isVisible();
  51642. if (hasHorzBar && (wheelIncrementX != 0 || e.mods.isShiftDown() || ! hasVertBar))
  51643. {
  51644. if (wheelIncrementX == 0 && ! hasVertBar)
  51645. wheelIncrementX = wheelIncrementY;
  51646. horizontalScrollBar->mouseWheelMove (e.getEventRelativeTo (horizontalScrollBar),
  51647. wheelIncrementX, wheelIncrementY);
  51648. return true;
  51649. }
  51650. else if (hasVertBar && wheelIncrementY != 0)
  51651. {
  51652. verticalScrollBar->mouseWheelMove (e.getEventRelativeTo (verticalScrollBar),
  51653. wheelIncrementX, wheelIncrementY);
  51654. return true;
  51655. }
  51656. }
  51657. return false;
  51658. }
  51659. bool Viewport::keyPressed (const KeyPress& key)
  51660. {
  51661. const bool isUpDownKey = key.isKeyCode (KeyPress::upKey)
  51662. || key.isKeyCode (KeyPress::downKey)
  51663. || key.isKeyCode (KeyPress::pageUpKey)
  51664. || key.isKeyCode (KeyPress::pageDownKey)
  51665. || key.isKeyCode (KeyPress::homeKey)
  51666. || key.isKeyCode (KeyPress::endKey);
  51667. if (verticalScrollBar->isVisible() && isUpDownKey)
  51668. return verticalScrollBar->keyPressed (key);
  51669. const bool isLeftRightKey = key.isKeyCode (KeyPress::leftKey)
  51670. || key.isKeyCode (KeyPress::rightKey);
  51671. if (horizontalScrollBar->isVisible() && (isUpDownKey || isLeftRightKey))
  51672. return horizontalScrollBar->keyPressed (key);
  51673. return false;
  51674. }
  51675. END_JUCE_NAMESPACE
  51676. /*** End of inlined file: juce_Viewport.cpp ***/
  51677. /*** Start of inlined file: juce_LookAndFeel.cpp ***/
  51678. BEGIN_JUCE_NAMESPACE
  51679. static const Colour createBaseColour (const Colour& buttonColour,
  51680. const bool hasKeyboardFocus,
  51681. const bool isMouseOverButton,
  51682. const bool isButtonDown) throw()
  51683. {
  51684. const float sat = hasKeyboardFocus ? 1.3f : 0.9f;
  51685. const Colour baseColour (buttonColour.withMultipliedSaturation (sat));
  51686. if (isButtonDown)
  51687. return baseColour.contrasting (0.2f);
  51688. else if (isMouseOverButton)
  51689. return baseColour.contrasting (0.1f);
  51690. return baseColour;
  51691. }
  51692. static String defaultSansName, defaultSerifName, defaultFixedName;
  51693. void clearUpDefaultFontNames() throw()
  51694. {
  51695. defaultSansName = String::empty;
  51696. defaultSerifName = String::empty;
  51697. defaultFixedName = String::empty;
  51698. }
  51699. LookAndFeel::LookAndFeel()
  51700. {
  51701. /* if this fails it means you're trying to create a LookAndFeel object before
  51702. the static Colours have been initialised. That ain't gonna work. It probably
  51703. means that you're using a static LookAndFeel object and that your compiler has
  51704. decided to intialise it before the Colours class.
  51705. */
  51706. jassert (Colours::white == Colour (0xffffffff));
  51707. // set up the standard set of colours..
  51708. const int textButtonColour = 0xffbbbbff;
  51709. const int textHighlightColour = 0x401111ee;
  51710. const int standardOutlineColour = 0xb2808080;
  51711. static const int standardColours[] =
  51712. {
  51713. TextButton::buttonColourId, textButtonColour,
  51714. TextButton::buttonOnColourId, 0xff4444ff,
  51715. TextButton::textColourOnId, 0xff000000,
  51716. TextButton::textColourOffId, 0xff000000,
  51717. ComboBox::buttonColourId, 0xffbbbbff,
  51718. ComboBox::outlineColourId, standardOutlineColour,
  51719. ToggleButton::textColourId, 0xff000000,
  51720. TextEditor::backgroundColourId, 0xffffffff,
  51721. TextEditor::textColourId, 0xff000000,
  51722. TextEditor::highlightColourId, textHighlightColour,
  51723. TextEditor::highlightedTextColourId, 0xff000000,
  51724. TextEditor::caretColourId, 0xff000000,
  51725. TextEditor::outlineColourId, 0x00000000,
  51726. TextEditor::focusedOutlineColourId, textButtonColour,
  51727. TextEditor::shadowColourId, 0x38000000,
  51728. Label::backgroundColourId, 0x00000000,
  51729. Label::textColourId, 0xff000000,
  51730. Label::outlineColourId, 0x00000000,
  51731. ScrollBar::backgroundColourId, 0x00000000,
  51732. ScrollBar::thumbColourId, 0xffffffff,
  51733. ScrollBar::trackColourId, 0xffffffff,
  51734. TreeView::linesColourId, 0x4c000000,
  51735. TreeView::backgroundColourId, 0x00000000,
  51736. TreeView::dragAndDropIndicatorColourId, 0x80ff0000,
  51737. PopupMenu::backgroundColourId, 0xffffffff,
  51738. PopupMenu::textColourId, 0xff000000,
  51739. PopupMenu::headerTextColourId, 0xff000000,
  51740. PopupMenu::highlightedTextColourId, 0xffffffff,
  51741. PopupMenu::highlightedBackgroundColourId, 0x991111aa,
  51742. ComboBox::textColourId, 0xff000000,
  51743. ComboBox::backgroundColourId, 0xffffffff,
  51744. ComboBox::arrowColourId, 0x99000000,
  51745. ListBox::backgroundColourId, 0xffffffff,
  51746. ListBox::outlineColourId, standardOutlineColour,
  51747. ListBox::textColourId, 0xff000000,
  51748. Slider::backgroundColourId, 0x00000000,
  51749. Slider::thumbColourId, textButtonColour,
  51750. Slider::trackColourId, 0x7fffffff,
  51751. Slider::rotarySliderFillColourId, 0x7f0000ff,
  51752. Slider::rotarySliderOutlineColourId, 0x66000000,
  51753. Slider::textBoxTextColourId, 0xff000000,
  51754. Slider::textBoxBackgroundColourId, 0xffffffff,
  51755. Slider::textBoxHighlightColourId, textHighlightColour,
  51756. Slider::textBoxOutlineColourId, standardOutlineColour,
  51757. ResizableWindow::backgroundColourId, 0xff777777,
  51758. //DocumentWindow::textColourId, 0xff000000, // (this is deliberately not set)
  51759. AlertWindow::backgroundColourId, 0xffededed,
  51760. AlertWindow::textColourId, 0xff000000,
  51761. AlertWindow::outlineColourId, 0xff666666,
  51762. ProgressBar::backgroundColourId, 0xffeeeeee,
  51763. ProgressBar::foregroundColourId, 0xffaaaaee,
  51764. TooltipWindow::backgroundColourId, 0xffeeeebb,
  51765. TooltipWindow::textColourId, 0xff000000,
  51766. TooltipWindow::outlineColourId, 0x4c000000,
  51767. TabbedComponent::backgroundColourId, 0x00000000,
  51768. TabbedComponent::outlineColourId, 0xff777777,
  51769. TabbedButtonBar::tabOutlineColourId, 0x80000000,
  51770. TabbedButtonBar::frontOutlineColourId, 0x90000000,
  51771. Toolbar::backgroundColourId, 0xfff6f8f9,
  51772. Toolbar::separatorColourId, 0x4c000000,
  51773. Toolbar::buttonMouseOverBackgroundColourId, 0x4c0000ff,
  51774. Toolbar::buttonMouseDownBackgroundColourId, 0x800000ff,
  51775. Toolbar::labelTextColourId, 0xff000000,
  51776. Toolbar::editingModeOutlineColourId, 0xffff0000,
  51777. HyperlinkButton::textColourId, 0xcc1111ee,
  51778. GroupComponent::outlineColourId, 0x66000000,
  51779. GroupComponent::textColourId, 0xff000000,
  51780. DirectoryContentsDisplayComponent::highlightColourId, textHighlightColour,
  51781. DirectoryContentsDisplayComponent::textColourId, 0xff000000,
  51782. 0x1000440, /*LassoComponent::lassoFillColourId*/ 0x66dddddd,
  51783. 0x1000441, /*LassoComponent::lassoOutlineColourId*/ 0x99111111,
  51784. MidiKeyboardComponent::whiteNoteColourId, 0xffffffff,
  51785. MidiKeyboardComponent::blackNoteColourId, 0xff000000,
  51786. MidiKeyboardComponent::keySeparatorLineColourId, 0x66000000,
  51787. MidiKeyboardComponent::mouseOverKeyOverlayColourId, 0x80ffff00,
  51788. MidiKeyboardComponent::keyDownOverlayColourId, 0xffb6b600,
  51789. MidiKeyboardComponent::textLabelColourId, 0xff000000,
  51790. MidiKeyboardComponent::upDownButtonBackgroundColourId, 0xffd3d3d3,
  51791. MidiKeyboardComponent::upDownButtonArrowColourId, 0xff000000,
  51792. CodeEditorComponent::backgroundColourId, 0xffffffff,
  51793. CodeEditorComponent::caretColourId, 0xff000000,
  51794. CodeEditorComponent::highlightColourId, textHighlightColour,
  51795. CodeEditorComponent::defaultTextColourId, 0xff000000,
  51796. ColourSelector::backgroundColourId, 0xffe5e5e5,
  51797. ColourSelector::labelTextColourId, 0xff000000,
  51798. KeyMappingEditorComponent::backgroundColourId, 0x00000000,
  51799. KeyMappingEditorComponent::textColourId, 0xff000000,
  51800. FileSearchPathListComponent::backgroundColourId, 0xffffffff,
  51801. FileChooserDialogBox::titleTextColourId, 0xff000000,
  51802. };
  51803. for (int i = 0; i < numElementsInArray (standardColours); i += 2)
  51804. setColour (standardColours [i], Colour (standardColours [i + 1]));
  51805. if (defaultSansName.isEmpty())
  51806. Font::getPlatformDefaultFontNames (defaultSansName, defaultSerifName, defaultFixedName);
  51807. defaultSans = defaultSansName;
  51808. defaultSerif = defaultSerifName;
  51809. defaultFixed = defaultFixedName;
  51810. }
  51811. LookAndFeel::~LookAndFeel()
  51812. {
  51813. }
  51814. const Colour LookAndFeel::findColour (const int colourId) const throw()
  51815. {
  51816. const int index = colourIds.indexOf (colourId);
  51817. if (index >= 0)
  51818. return colours [index];
  51819. jassertfalse
  51820. return Colours::black;
  51821. }
  51822. void LookAndFeel::setColour (const int colourId, const Colour& colour) throw()
  51823. {
  51824. const int index = colourIds.indexOf (colourId);
  51825. if (index >= 0)
  51826. colours.set (index, colour);
  51827. colourIds.add (colourId);
  51828. colours.add (colour);
  51829. }
  51830. bool LookAndFeel::isColourSpecified (const int colourId) const throw()
  51831. {
  51832. return colourIds.contains (colourId);
  51833. }
  51834. static LookAndFeel* defaultLF = 0;
  51835. static LookAndFeel* currentDefaultLF = 0;
  51836. LookAndFeel& LookAndFeel::getDefaultLookAndFeel() throw()
  51837. {
  51838. // if this happens, your app hasn't initialised itself properly.. if you're
  51839. // trying to hack your own main() function, have a look at
  51840. // JUCEApplication::initialiseForGUI()
  51841. jassert (currentDefaultLF != 0);
  51842. return *currentDefaultLF;
  51843. }
  51844. void LookAndFeel::setDefaultLookAndFeel (LookAndFeel* newDefaultLookAndFeel) throw()
  51845. {
  51846. if (newDefaultLookAndFeel == 0)
  51847. {
  51848. if (defaultLF == 0)
  51849. defaultLF = new LookAndFeel();
  51850. newDefaultLookAndFeel = defaultLF;
  51851. }
  51852. currentDefaultLF = newDefaultLookAndFeel;
  51853. for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
  51854. {
  51855. Component* const c = Desktop::getInstance().getComponent (i);
  51856. if (c != 0)
  51857. c->sendLookAndFeelChange();
  51858. }
  51859. }
  51860. void LookAndFeel::clearDefaultLookAndFeel() throw()
  51861. {
  51862. if (currentDefaultLF == defaultLF)
  51863. currentDefaultLF = 0;
  51864. deleteAndZero (defaultLF);
  51865. }
  51866. const Typeface::Ptr LookAndFeel::getTypefaceForFont (const Font& font)
  51867. {
  51868. String faceName (font.getTypefaceName());
  51869. if (faceName == Font::getDefaultSansSerifFontName())
  51870. faceName = defaultSans;
  51871. else if (faceName == Font::getDefaultSerifFontName())
  51872. faceName = defaultSerif;
  51873. else if (faceName == Font::getDefaultMonospacedFontName())
  51874. faceName = defaultFixed;
  51875. Font f (font);
  51876. f.setTypefaceName (faceName);
  51877. return Typeface::createSystemTypefaceFor (f);
  51878. }
  51879. void LookAndFeel::setDefaultSansSerifTypefaceName (const String& newName)
  51880. {
  51881. defaultSans = newName;
  51882. }
  51883. const MouseCursor LookAndFeel::getMouseCursorFor (Component& component)
  51884. {
  51885. return component.getMouseCursor();
  51886. }
  51887. void LookAndFeel::drawButtonBackground (Graphics& g,
  51888. Button& button,
  51889. const Colour& backgroundColour,
  51890. bool isMouseOverButton,
  51891. bool isButtonDown)
  51892. {
  51893. const int width = button.getWidth();
  51894. const int height = button.getHeight();
  51895. const float outlineThickness = button.isEnabled() ? ((isButtonDown || isMouseOverButton) ? 1.2f : 0.7f) : 0.4f;
  51896. const float halfThickness = outlineThickness * 0.5f;
  51897. const float indentL = button.isConnectedOnLeft() ? 0.1f : halfThickness;
  51898. const float indentR = button.isConnectedOnRight() ? 0.1f : halfThickness;
  51899. const float indentT = button.isConnectedOnTop() ? 0.1f : halfThickness;
  51900. const float indentB = button.isConnectedOnBottom() ? 0.1f : halfThickness;
  51901. const Colour baseColour (createBaseColour (backgroundColour,
  51902. button.hasKeyboardFocus (true),
  51903. isMouseOverButton, isButtonDown)
  51904. .withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.5f));
  51905. drawGlassLozenge (g,
  51906. indentL,
  51907. indentT,
  51908. width - indentL - indentR,
  51909. height - indentT - indentB,
  51910. baseColour, outlineThickness, -1.0f,
  51911. button.isConnectedOnLeft(),
  51912. button.isConnectedOnRight(),
  51913. button.isConnectedOnTop(),
  51914. button.isConnectedOnBottom());
  51915. }
  51916. const Font LookAndFeel::getFontForTextButton (TextButton& button)
  51917. {
  51918. return button.getFont();
  51919. }
  51920. void LookAndFeel::drawButtonText (Graphics& g, TextButton& button,
  51921. bool /*isMouseOverButton*/, bool /*isButtonDown*/)
  51922. {
  51923. Font font (getFontForTextButton (button));
  51924. g.setFont (font);
  51925. g.setColour (button.findColour (button.getToggleState() ? TextButton::textColourOnId
  51926. : TextButton::textColourOffId)
  51927. .withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.5f));
  51928. const int yIndent = jmin (4, button.proportionOfHeight (0.3f));
  51929. const int cornerSize = jmin (button.getHeight(), button.getWidth()) / 2;
  51930. const int fontHeight = roundToInt (font.getHeight() * 0.6f);
  51931. const int leftIndent = jmin (fontHeight, 2 + cornerSize / (button.isConnectedOnLeft() ? 4 : 2));
  51932. const int rightIndent = jmin (fontHeight, 2 + cornerSize / (button.isConnectedOnRight() ? 4 : 2));
  51933. g.drawFittedText (button.getButtonText(),
  51934. leftIndent,
  51935. yIndent,
  51936. button.getWidth() - leftIndent - rightIndent,
  51937. button.getHeight() - yIndent * 2,
  51938. Justification::centred, 2);
  51939. }
  51940. void LookAndFeel::drawTickBox (Graphics& g,
  51941. Component& component,
  51942. float x, float y, float w, float h,
  51943. const bool ticked,
  51944. const bool isEnabled,
  51945. const bool isMouseOverButton,
  51946. const bool isButtonDown)
  51947. {
  51948. const float boxSize = w * 0.7f;
  51949. drawGlassSphere (g, x, y + (h - boxSize) * 0.5f, boxSize,
  51950. createBaseColour (component.findColour (TextButton::buttonColourId)
  51951. .withMultipliedAlpha (isEnabled ? 1.0f : 0.5f),
  51952. true,
  51953. isMouseOverButton,
  51954. isButtonDown),
  51955. isEnabled ? ((isButtonDown || isMouseOverButton) ? 1.1f : 0.5f) : 0.3f);
  51956. if (ticked)
  51957. {
  51958. Path tick;
  51959. tick.startNewSubPath (1.5f, 3.0f);
  51960. tick.lineTo (3.0f, 6.0f);
  51961. tick.lineTo (6.0f, 0.0f);
  51962. g.setColour (isEnabled ? Colours::black : Colours::grey);
  51963. const AffineTransform trans (AffineTransform::scale (w / 9.0f, h / 9.0f)
  51964. .translated (x, y));
  51965. g.strokePath (tick, PathStrokeType (2.5f), trans);
  51966. }
  51967. }
  51968. void LookAndFeel::drawToggleButton (Graphics& g,
  51969. ToggleButton& button,
  51970. bool isMouseOverButton,
  51971. bool isButtonDown)
  51972. {
  51973. if (button.hasKeyboardFocus (true))
  51974. {
  51975. g.setColour (button.findColour (TextEditor::focusedOutlineColourId));
  51976. g.drawRect (0, 0, button.getWidth(), button.getHeight());
  51977. }
  51978. float fontSize = jmin (15.0f, button.getHeight() * 0.75f);
  51979. const float tickWidth = fontSize * 1.1f;
  51980. drawTickBox (g, button, 4.0f, (button.getHeight() - tickWidth) * 0.5f,
  51981. tickWidth, tickWidth,
  51982. button.getToggleState(),
  51983. button.isEnabled(),
  51984. isMouseOverButton,
  51985. isButtonDown);
  51986. g.setColour (button.findColour (ToggleButton::textColourId));
  51987. g.setFont (fontSize);
  51988. if (! button.isEnabled())
  51989. g.setOpacity (0.5f);
  51990. const int textX = (int) tickWidth + 5;
  51991. g.drawFittedText (button.getButtonText(),
  51992. textX, 0,
  51993. button.getWidth() - textX - 2, button.getHeight(),
  51994. Justification::centredLeft, 10);
  51995. }
  51996. void LookAndFeel::changeToggleButtonWidthToFitText (ToggleButton& button)
  51997. {
  51998. Font font (jmin (15.0f, button.getHeight() * 0.6f));
  51999. const int tickWidth = jmin (24, button.getHeight());
  52000. button.setSize (font.getStringWidth (button.getButtonText()) + tickWidth + 8,
  52001. button.getHeight());
  52002. }
  52003. AlertWindow* LookAndFeel::createAlertWindow (const String& title,
  52004. const String& message,
  52005. const String& button1,
  52006. const String& button2,
  52007. const String& button3,
  52008. AlertWindow::AlertIconType iconType,
  52009. int numButtons,
  52010. Component* associatedComponent)
  52011. {
  52012. AlertWindow* aw = new AlertWindow (title, message, iconType, associatedComponent);
  52013. if (numButtons == 1)
  52014. {
  52015. aw->addButton (button1, 0,
  52016. KeyPress (KeyPress::escapeKey, 0, 0),
  52017. KeyPress (KeyPress::returnKey, 0, 0));
  52018. }
  52019. else
  52020. {
  52021. const KeyPress button1ShortCut (CharacterFunctions::toLowerCase (button1[0]), 0, 0);
  52022. KeyPress button2ShortCut (CharacterFunctions::toLowerCase (button2[0]), 0, 0);
  52023. if (button1ShortCut == button2ShortCut)
  52024. button2ShortCut = KeyPress();
  52025. if (numButtons == 2)
  52026. {
  52027. aw->addButton (button1, 1, KeyPress (KeyPress::returnKey, 0, 0), button1ShortCut);
  52028. aw->addButton (button2, 0, KeyPress (KeyPress::escapeKey, 0, 0), button2ShortCut);
  52029. }
  52030. else if (numButtons == 3)
  52031. {
  52032. aw->addButton (button1, 1, button1ShortCut);
  52033. aw->addButton (button2, 2, button2ShortCut);
  52034. aw->addButton (button3, 0, KeyPress (KeyPress::escapeKey, 0, 0));
  52035. }
  52036. }
  52037. return aw;
  52038. }
  52039. void LookAndFeel::drawAlertBox (Graphics& g,
  52040. AlertWindow& alert,
  52041. const Rectangle<int>& textArea,
  52042. TextLayout& textLayout)
  52043. {
  52044. g.fillAll (alert.findColour (AlertWindow::backgroundColourId));
  52045. int iconSpaceUsed = 0;
  52046. Justification alignment (Justification::horizontallyCentred);
  52047. const int iconWidth = 80;
  52048. int iconSize = jmin (iconWidth + 50, alert.getHeight() + 20);
  52049. if (alert.containsAnyExtraComponents() || alert.getNumButtons() > 2)
  52050. iconSize = jmin (iconSize, textArea.getHeight() + 50);
  52051. const Rectangle<int> iconRect (iconSize / -10, iconSize / -10,
  52052. iconSize, iconSize);
  52053. if (alert.getAlertType() != AlertWindow::NoIcon)
  52054. {
  52055. Path icon;
  52056. uint32 colour;
  52057. char character;
  52058. if (alert.getAlertType() == AlertWindow::WarningIcon)
  52059. {
  52060. colour = 0x55ff5555;
  52061. character = '!';
  52062. icon.addTriangle (iconRect.getX() + iconRect.getWidth() * 0.5f, (float) iconRect.getY(),
  52063. (float) iconRect.getRight(), (float) iconRect.getBottom(),
  52064. (float) iconRect.getX(), (float) iconRect.getBottom());
  52065. icon = icon.createPathWithRoundedCorners (5.0f);
  52066. }
  52067. else
  52068. {
  52069. colour = alert.getAlertType() == AlertWindow::InfoIcon ? 0x605555ff : 0x40b69900;
  52070. character = alert.getAlertType() == AlertWindow::InfoIcon ? 'i' : '?';
  52071. icon.addEllipse ((float) iconRect.getX(), (float) iconRect.getY(),
  52072. (float) iconRect.getWidth(), (float) iconRect.getHeight());
  52073. }
  52074. GlyphArrangement ga;
  52075. ga.addFittedText (Font (iconRect.getHeight() * 0.9f, Font::bold),
  52076. String::charToString (character),
  52077. (float) iconRect.getX(), (float) iconRect.getY(),
  52078. (float) iconRect.getWidth(), (float) iconRect.getHeight(),
  52079. Justification::centred, false);
  52080. ga.createPath (icon);
  52081. icon.setUsingNonZeroWinding (false);
  52082. g.setColour (Colour (colour));
  52083. g.fillPath (icon);
  52084. iconSpaceUsed = iconWidth;
  52085. alignment = Justification::left;
  52086. }
  52087. g.setColour (alert.findColour (AlertWindow::textColourId));
  52088. textLayout.drawWithin (g,
  52089. textArea.getX() + iconSpaceUsed, textArea.getY(),
  52090. textArea.getWidth() - iconSpaceUsed, textArea.getHeight(),
  52091. alignment.getFlags() | Justification::top);
  52092. g.setColour (alert.findColour (AlertWindow::outlineColourId));
  52093. g.drawRect (0, 0, alert.getWidth(), alert.getHeight());
  52094. }
  52095. int LookAndFeel::getAlertBoxWindowFlags()
  52096. {
  52097. return ComponentPeer::windowAppearsOnTaskbar
  52098. | ComponentPeer::windowHasDropShadow;
  52099. }
  52100. int LookAndFeel::getAlertWindowButtonHeight()
  52101. {
  52102. return 28;
  52103. }
  52104. const Font LookAndFeel::getAlertWindowFont()
  52105. {
  52106. return Font (12.0f);
  52107. }
  52108. void LookAndFeel::drawProgressBar (Graphics& g, ProgressBar& progressBar,
  52109. int width, int height,
  52110. double progress, const String& textToShow)
  52111. {
  52112. const Colour background (progressBar.findColour (ProgressBar::backgroundColourId));
  52113. const Colour foreground (progressBar.findColour (ProgressBar::foregroundColourId));
  52114. g.fillAll (background);
  52115. if (progress >= 0.0f && progress < 1.0f)
  52116. {
  52117. drawGlassLozenge (g, 1.0f, 1.0f,
  52118. (float) jlimit (0.0, width - 2.0, progress * (width - 2.0)),
  52119. (float) (height - 2),
  52120. foreground,
  52121. 0.5f, 0.0f,
  52122. true, true, true, true);
  52123. }
  52124. else
  52125. {
  52126. // spinning bar..
  52127. g.setColour (foreground);
  52128. const int stripeWidth = height * 2;
  52129. const int position = (Time::getMillisecondCounter() / 15) % stripeWidth;
  52130. Path p;
  52131. for (float x = (float) (- position); x < width + stripeWidth; x += stripeWidth)
  52132. p.addQuadrilateral (x, 0.0f,
  52133. x + stripeWidth * 0.5f, 0.0f,
  52134. x, (float) height,
  52135. x - stripeWidth * 0.5f, (float) height);
  52136. Image im (Image::ARGB, width, height, true);
  52137. {
  52138. Graphics g2 (im);
  52139. drawGlassLozenge (g2, 1.0f, 1.0f,
  52140. (float) (width - 2),
  52141. (float) (height - 2),
  52142. foreground,
  52143. 0.5f, 0.0f,
  52144. true, true, true, true);
  52145. }
  52146. g.setTiledImageFill (im, 0, 0, 0.85f);
  52147. g.fillPath (p);
  52148. }
  52149. if (textToShow.isNotEmpty())
  52150. {
  52151. g.setColour (Colour::contrasting (background, foreground));
  52152. g.setFont (height * 0.6f);
  52153. g.drawText (textToShow, 0, 0, width, height, Justification::centred, false);
  52154. }
  52155. }
  52156. void LookAndFeel::drawSpinningWaitAnimation (Graphics& g, const Colour& colour, int x, int y, int w, int h)
  52157. {
  52158. const float radius = jmin (w, h) * 0.4f;
  52159. const float thickness = radius * 0.15f;
  52160. Path p;
  52161. p.addRoundedRectangle (radius * 0.4f, thickness * -0.5f,
  52162. radius * 0.6f, thickness,
  52163. thickness * 0.5f);
  52164. const float cx = x + w * 0.5f;
  52165. const float cy = y + h * 0.5f;
  52166. const uint32 animationIndex = (Time::getMillisecondCounter() / (1000 / 10)) % 12;
  52167. for (int i = 0; i < 12; ++i)
  52168. {
  52169. const int n = (i + 12 - animationIndex) % 12;
  52170. g.setColour (colour.withMultipliedAlpha ((n + 1) / 12.0f));
  52171. g.fillPath (p, AffineTransform::rotation (i * (float_Pi / 6.0f))
  52172. .translated (cx, cy));
  52173. }
  52174. }
  52175. void LookAndFeel::drawScrollbarButton (Graphics& g,
  52176. ScrollBar& scrollbar,
  52177. int width, int height,
  52178. int buttonDirection,
  52179. bool /*isScrollbarVertical*/,
  52180. bool /*isMouseOverButton*/,
  52181. bool isButtonDown)
  52182. {
  52183. Path p;
  52184. if (buttonDirection == 0)
  52185. p.addTriangle (width * 0.5f, height * 0.2f,
  52186. width * 0.1f, height * 0.7f,
  52187. width * 0.9f, height * 0.7f);
  52188. else if (buttonDirection == 1)
  52189. p.addTriangle (width * 0.8f, height * 0.5f,
  52190. width * 0.3f, height * 0.1f,
  52191. width * 0.3f, height * 0.9f);
  52192. else if (buttonDirection == 2)
  52193. p.addTriangle (width * 0.5f, height * 0.8f,
  52194. width * 0.1f, height * 0.3f,
  52195. width * 0.9f, height * 0.3f);
  52196. else if (buttonDirection == 3)
  52197. p.addTriangle (width * 0.2f, height * 0.5f,
  52198. width * 0.7f, height * 0.1f,
  52199. width * 0.7f, height * 0.9f);
  52200. if (isButtonDown)
  52201. g.setColour (scrollbar.findColour (ScrollBar::thumbColourId).contrasting (0.2f));
  52202. else
  52203. g.setColour (scrollbar.findColour (ScrollBar::thumbColourId));
  52204. g.fillPath (p);
  52205. g.setColour (Colour (0x80000000));
  52206. g.strokePath (p, PathStrokeType (0.5f));
  52207. }
  52208. void LookAndFeel::drawScrollbar (Graphics& g,
  52209. ScrollBar& scrollbar,
  52210. int x, int y,
  52211. int width, int height,
  52212. bool isScrollbarVertical,
  52213. int thumbStartPosition,
  52214. int thumbSize,
  52215. bool /*isMouseOver*/,
  52216. bool /*isMouseDown*/)
  52217. {
  52218. g.fillAll (scrollbar.findColour (ScrollBar::backgroundColourId));
  52219. Path slotPath, thumbPath;
  52220. const float slotIndent = jmin (width, height) > 15 ? 1.0f : 0.0f;
  52221. const float slotIndentx2 = slotIndent * 2.0f;
  52222. const float thumbIndent = slotIndent + 1.0f;
  52223. const float thumbIndentx2 = thumbIndent * 2.0f;
  52224. float gx1 = 0.0f, gy1 = 0.0f, gx2 = 0.0f, gy2 = 0.0f;
  52225. if (isScrollbarVertical)
  52226. {
  52227. slotPath.addRoundedRectangle (x + slotIndent,
  52228. y + slotIndent,
  52229. width - slotIndentx2,
  52230. height - slotIndentx2,
  52231. (width - slotIndentx2) * 0.5f);
  52232. if (thumbSize > 0)
  52233. thumbPath.addRoundedRectangle (x + thumbIndent,
  52234. thumbStartPosition + thumbIndent,
  52235. width - thumbIndentx2,
  52236. thumbSize - thumbIndentx2,
  52237. (width - thumbIndentx2) * 0.5f);
  52238. gx1 = (float) x;
  52239. gx2 = x + width * 0.7f;
  52240. }
  52241. else
  52242. {
  52243. slotPath.addRoundedRectangle (x + slotIndent,
  52244. y + slotIndent,
  52245. width - slotIndentx2,
  52246. height - slotIndentx2,
  52247. (height - slotIndentx2) * 0.5f);
  52248. if (thumbSize > 0)
  52249. thumbPath.addRoundedRectangle (thumbStartPosition + thumbIndent,
  52250. y + thumbIndent,
  52251. thumbSize - thumbIndentx2,
  52252. height - thumbIndentx2,
  52253. (height - thumbIndentx2) * 0.5f);
  52254. gy1 = (float) y;
  52255. gy2 = y + height * 0.7f;
  52256. }
  52257. const Colour thumbColour (scrollbar.findColour (ScrollBar::thumbColourId));
  52258. g.setGradientFill (ColourGradient (thumbColour.overlaidWith (Colour (0x44000000)), gx1, gy1,
  52259. thumbColour.overlaidWith (Colour (0x19000000)), gx2, gy2, false));
  52260. g.fillPath (slotPath);
  52261. if (isScrollbarVertical)
  52262. {
  52263. gx1 = x + width * 0.6f;
  52264. gx2 = (float) x + width;
  52265. }
  52266. else
  52267. {
  52268. gy1 = y + height * 0.6f;
  52269. gy2 = (float) y + height;
  52270. }
  52271. g.setGradientFill (ColourGradient (Colours::transparentBlack,gx1, gy1,
  52272. Colour (0x19000000), gx2, gy2, false));
  52273. g.fillPath (slotPath);
  52274. g.setColour (thumbColour);
  52275. g.fillPath (thumbPath);
  52276. g.setGradientFill (ColourGradient (Colour (0x10000000), gx1, gy1,
  52277. Colours::transparentBlack, gx2, gy2, false));
  52278. g.saveState();
  52279. if (isScrollbarVertical)
  52280. g.reduceClipRegion (x + width / 2, y, width, height);
  52281. else
  52282. g.reduceClipRegion (x, y + height / 2, width, height);
  52283. g.fillPath (thumbPath);
  52284. g.restoreState();
  52285. g.setColour (Colour (0x4c000000));
  52286. g.strokePath (thumbPath, PathStrokeType (0.4f));
  52287. }
  52288. ImageEffectFilter* LookAndFeel::getScrollbarEffect()
  52289. {
  52290. return 0;
  52291. }
  52292. int LookAndFeel::getMinimumScrollbarThumbSize (ScrollBar& scrollbar)
  52293. {
  52294. return jmin (scrollbar.getWidth(), scrollbar.getHeight()) * 2;
  52295. }
  52296. int LookAndFeel::getDefaultScrollbarWidth()
  52297. {
  52298. return 18;
  52299. }
  52300. int LookAndFeel::getScrollbarButtonSize (ScrollBar& scrollbar)
  52301. {
  52302. return 2 + (scrollbar.isVertical() ? scrollbar.getWidth()
  52303. : scrollbar.getHeight());
  52304. }
  52305. const Path LookAndFeel::getTickShape (const float height)
  52306. {
  52307. static const unsigned char tickShapeData[] =
  52308. {
  52309. 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,
  52310. 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,
  52311. 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,
  52312. 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,
  52313. 96,140,68,0,128,188,67,0,224,168,68,0,0,119,67,99,101
  52314. };
  52315. Path p;
  52316. p.loadPathFromData (tickShapeData, sizeof (tickShapeData));
  52317. p.scaleToFit (0, 0, height * 2.0f, height, true);
  52318. return p;
  52319. }
  52320. const Path LookAndFeel::getCrossShape (const float height)
  52321. {
  52322. static const unsigned char crossShapeData[] =
  52323. {
  52324. 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,
  52325. 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,
  52326. 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,
  52327. 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,
  52328. 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,
  52329. 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,
  52330. 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
  52331. };
  52332. Path p;
  52333. p.loadPathFromData (crossShapeData, sizeof (crossShapeData));
  52334. p.scaleToFit (0, 0, height * 2.0f, height, true);
  52335. return p;
  52336. }
  52337. void LookAndFeel::drawTreeviewPlusMinusBox (Graphics& g, int x, int y, int w, int h, bool isPlus, bool /*isMouseOver*/)
  52338. {
  52339. const int boxSize = ((jmin (16, w, h) << 1) / 3) | 1;
  52340. x += (w - boxSize) >> 1;
  52341. y += (h - boxSize) >> 1;
  52342. w = boxSize;
  52343. h = boxSize;
  52344. g.setColour (Colour (0xe5ffffff));
  52345. g.fillRect (x, y, w, h);
  52346. g.setColour (Colour (0x80000000));
  52347. g.drawRect (x, y, w, h);
  52348. const float size = boxSize / 2 + 1.0f;
  52349. const float centre = (float) (boxSize / 2);
  52350. g.fillRect (x + (w - size) * 0.5f, y + centre, size, 1.0f);
  52351. if (isPlus)
  52352. g.fillRect (x + centre, y + (h - size) * 0.5f, 1.0f, size);
  52353. }
  52354. void LookAndFeel::drawBubble (Graphics& g,
  52355. float tipX, float tipY,
  52356. float boxX, float boxY,
  52357. float boxW, float boxH)
  52358. {
  52359. int side = 0;
  52360. if (tipX < boxX)
  52361. side = 1;
  52362. else if (tipX > boxX + boxW)
  52363. side = 3;
  52364. else if (tipY > boxY + boxH)
  52365. side = 2;
  52366. const float indent = 2.0f;
  52367. Path p;
  52368. p.addBubble (boxX + indent,
  52369. boxY + indent,
  52370. boxW - indent * 2.0f,
  52371. boxH - indent * 2.0f,
  52372. 5.0f,
  52373. tipX, tipY,
  52374. side,
  52375. 0.5f,
  52376. jmin (15.0f, boxW * 0.3f, boxH * 0.3f));
  52377. //xxx need to take comp as param for colour
  52378. g.setColour (findColour (TooltipWindow::backgroundColourId).withAlpha (0.9f));
  52379. g.fillPath (p);
  52380. //xxx as above
  52381. g.setColour (findColour (TooltipWindow::textColourId).withAlpha (0.4f));
  52382. g.strokePath (p, PathStrokeType (1.33f));
  52383. }
  52384. const Font LookAndFeel::getPopupMenuFont()
  52385. {
  52386. return Font (17.0f);
  52387. }
  52388. void LookAndFeel::getIdealPopupMenuItemSize (const String& text,
  52389. const bool isSeparator,
  52390. int standardMenuItemHeight,
  52391. int& idealWidth,
  52392. int& idealHeight)
  52393. {
  52394. if (isSeparator)
  52395. {
  52396. idealWidth = 50;
  52397. idealHeight = standardMenuItemHeight > 0 ? standardMenuItemHeight / 2 : 10;
  52398. }
  52399. else
  52400. {
  52401. Font font (getPopupMenuFont());
  52402. if (standardMenuItemHeight > 0 && font.getHeight() > standardMenuItemHeight / 1.3f)
  52403. font.setHeight (standardMenuItemHeight / 1.3f);
  52404. idealHeight = standardMenuItemHeight > 0 ? standardMenuItemHeight : roundToInt (font.getHeight() * 1.3f);
  52405. idealWidth = font.getStringWidth (text) + idealHeight * 2;
  52406. }
  52407. }
  52408. void LookAndFeel::drawPopupMenuBackground (Graphics& g, int width, int height)
  52409. {
  52410. const Colour background (findColour (PopupMenu::backgroundColourId));
  52411. g.fillAll (background);
  52412. g.setColour (background.overlaidWith (Colour (0x2badd8e6)));
  52413. for (int i = 0; i < height; i += 3)
  52414. g.fillRect (0, i, width, 1);
  52415. #if ! JUCE_MAC
  52416. g.setColour (findColour (PopupMenu::textColourId).withAlpha (0.6f));
  52417. g.drawRect (0, 0, width, height);
  52418. #endif
  52419. }
  52420. void LookAndFeel::drawPopupMenuUpDownArrow (Graphics& g,
  52421. int width, int height,
  52422. bool isScrollUpArrow)
  52423. {
  52424. const Colour background (findColour (PopupMenu::backgroundColourId));
  52425. g.setGradientFill (ColourGradient (background, 0.0f, height * 0.5f,
  52426. background.withAlpha (0.0f),
  52427. 0.0f, isScrollUpArrow ? ((float) height) : 0.0f,
  52428. false));
  52429. g.fillRect (1, 1, width - 2, height - 2);
  52430. const float hw = width * 0.5f;
  52431. const float arrowW = height * 0.3f;
  52432. const float y1 = height * (isScrollUpArrow ? 0.6f : 0.3f);
  52433. const float y2 = height * (isScrollUpArrow ? 0.3f : 0.6f);
  52434. Path p;
  52435. p.addTriangle (hw - arrowW, y1,
  52436. hw + arrowW, y1,
  52437. hw, y2);
  52438. g.setColour (findColour (PopupMenu::textColourId).withAlpha (0.5f));
  52439. g.fillPath (p);
  52440. }
  52441. void LookAndFeel::drawPopupMenuItem (Graphics& g,
  52442. int width, int height,
  52443. const bool isSeparator,
  52444. const bool isActive,
  52445. const bool isHighlighted,
  52446. const bool isTicked,
  52447. const bool hasSubMenu,
  52448. const String& text,
  52449. const String& shortcutKeyText,
  52450. Image* image,
  52451. const Colour* const textColourToUse)
  52452. {
  52453. const float halfH = height * 0.5f;
  52454. if (isSeparator)
  52455. {
  52456. const float separatorIndent = 5.5f;
  52457. g.setColour (Colour (0x33000000));
  52458. g.drawLine (separatorIndent, halfH, width - separatorIndent, halfH);
  52459. g.setColour (Colour (0x66ffffff));
  52460. g.drawLine (separatorIndent, halfH + 1.0f, width - separatorIndent, halfH + 1.0f);
  52461. }
  52462. else
  52463. {
  52464. Colour textColour (findColour (PopupMenu::textColourId));
  52465. if (textColourToUse != 0)
  52466. textColour = *textColourToUse;
  52467. if (isHighlighted)
  52468. {
  52469. g.setColour (findColour (PopupMenu::highlightedBackgroundColourId));
  52470. g.fillRect (1, 1, width - 2, height - 2);
  52471. g.setColour (findColour (PopupMenu::highlightedTextColourId));
  52472. }
  52473. else
  52474. {
  52475. g.setColour (textColour);
  52476. }
  52477. if (! isActive)
  52478. g.setOpacity (0.3f);
  52479. Font font (getPopupMenuFont());
  52480. if (font.getHeight() > height / 1.3f)
  52481. font.setHeight (height / 1.3f);
  52482. g.setFont (font);
  52483. const int leftBorder = (height * 5) / 4;
  52484. const int rightBorder = 4;
  52485. if (image != 0)
  52486. {
  52487. g.drawImageWithin (image,
  52488. 2, 1, leftBorder - 4, height - 2,
  52489. RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize, false);
  52490. }
  52491. else if (isTicked)
  52492. {
  52493. const Path tick (getTickShape (1.0f));
  52494. const float th = font.getAscent();
  52495. const float ty = halfH - th * 0.5f;
  52496. g.fillPath (tick, tick.getTransformToScaleToFit (2.0f, ty, (float) (leftBorder - 4),
  52497. th, true));
  52498. }
  52499. g.drawFittedText (text,
  52500. leftBorder, 0,
  52501. width - (leftBorder + rightBorder), height,
  52502. Justification::centredLeft, 1);
  52503. if (shortcutKeyText.isNotEmpty())
  52504. {
  52505. Font f2 (font);
  52506. f2.setHeight (f2.getHeight() * 0.75f);
  52507. f2.setHorizontalScale (0.95f);
  52508. g.setFont (f2);
  52509. g.drawText (shortcutKeyText,
  52510. leftBorder,
  52511. 0,
  52512. width - (leftBorder + rightBorder + 4),
  52513. height,
  52514. Justification::centredRight,
  52515. true);
  52516. }
  52517. if (hasSubMenu)
  52518. {
  52519. const float arrowH = 0.6f * getPopupMenuFont().getAscent();
  52520. const float x = width - height * 0.6f;
  52521. Path p;
  52522. p.addTriangle (x, halfH - arrowH * 0.5f,
  52523. x, halfH + arrowH * 0.5f,
  52524. x + arrowH * 0.6f, halfH);
  52525. g.fillPath (p);
  52526. }
  52527. }
  52528. }
  52529. int LookAndFeel::getMenuWindowFlags()
  52530. {
  52531. return ComponentPeer::windowHasDropShadow;
  52532. }
  52533. void LookAndFeel::drawMenuBarBackground (Graphics& g, int width, int height,
  52534. bool, MenuBarComponent& menuBar)
  52535. {
  52536. const Colour baseColour (createBaseColour (menuBar.findColour (PopupMenu::backgroundColourId), false, false, false));
  52537. if (menuBar.isEnabled())
  52538. {
  52539. drawShinyButtonShape (g,
  52540. -4.0f, 0.0f,
  52541. width + 8.0f, (float) height,
  52542. 0.0f,
  52543. baseColour,
  52544. 0.4f,
  52545. true, true, true, true);
  52546. }
  52547. else
  52548. {
  52549. g.fillAll (baseColour);
  52550. }
  52551. }
  52552. const Font LookAndFeel::getMenuBarFont (MenuBarComponent& menuBar, int /*itemIndex*/, const String& /*itemText*/)
  52553. {
  52554. return Font (menuBar.getHeight() * 0.7f);
  52555. }
  52556. int LookAndFeel::getMenuBarItemWidth (MenuBarComponent& menuBar, int itemIndex, const String& itemText)
  52557. {
  52558. return getMenuBarFont (menuBar, itemIndex, itemText)
  52559. .getStringWidth (itemText) + menuBar.getHeight();
  52560. }
  52561. void LookAndFeel::drawMenuBarItem (Graphics& g,
  52562. int width, int height,
  52563. int itemIndex,
  52564. const String& itemText,
  52565. bool isMouseOverItem,
  52566. bool isMenuOpen,
  52567. bool /*isMouseOverBar*/,
  52568. MenuBarComponent& menuBar)
  52569. {
  52570. if (! menuBar.isEnabled())
  52571. {
  52572. g.setColour (menuBar.findColour (PopupMenu::textColourId)
  52573. .withMultipliedAlpha (0.5f));
  52574. }
  52575. else if (isMenuOpen || isMouseOverItem)
  52576. {
  52577. g.fillAll (menuBar.findColour (PopupMenu::highlightedBackgroundColourId));
  52578. g.setColour (menuBar.findColour (PopupMenu::highlightedTextColourId));
  52579. }
  52580. else
  52581. {
  52582. g.setColour (menuBar.findColour (PopupMenu::textColourId));
  52583. }
  52584. g.setFont (getMenuBarFont (menuBar, itemIndex, itemText));
  52585. g.drawFittedText (itemText, 0, 0, width, height, Justification::centred, 1);
  52586. }
  52587. void LookAndFeel::fillTextEditorBackground (Graphics& g, int /*width*/, int /*height*/,
  52588. TextEditor& textEditor)
  52589. {
  52590. g.fillAll (textEditor.findColour (TextEditor::backgroundColourId));
  52591. }
  52592. void LookAndFeel::drawTextEditorOutline (Graphics& g, int width, int height, TextEditor& textEditor)
  52593. {
  52594. if (textEditor.isEnabled())
  52595. {
  52596. if (textEditor.hasKeyboardFocus (true) && ! textEditor.isReadOnly())
  52597. {
  52598. const int border = 2;
  52599. g.setColour (textEditor.findColour (TextEditor::focusedOutlineColourId));
  52600. g.drawRect (0, 0, width, height, border);
  52601. g.setOpacity (1.0f);
  52602. const Colour shadowColour (textEditor.findColour (TextEditor::shadowColourId).withMultipliedAlpha (0.75f));
  52603. g.drawBevel (0, 0, width, height + 2, border + 2, shadowColour, shadowColour);
  52604. }
  52605. else
  52606. {
  52607. g.setColour (textEditor.findColour (TextEditor::outlineColourId));
  52608. g.drawRect (0, 0, width, height);
  52609. g.setOpacity (1.0f);
  52610. const Colour shadowColour (textEditor.findColour (TextEditor::shadowColourId));
  52611. g.drawBevel (0, 0, width, height + 2, 3, shadowColour, shadowColour);
  52612. }
  52613. }
  52614. }
  52615. void LookAndFeel::drawComboBox (Graphics& g, int width, int height,
  52616. const bool isButtonDown,
  52617. int buttonX, int buttonY,
  52618. int buttonW, int buttonH,
  52619. ComboBox& box)
  52620. {
  52621. g.fillAll (box.findColour (ComboBox::backgroundColourId));
  52622. if (box.isEnabled() && box.hasKeyboardFocus (false))
  52623. {
  52624. g.setColour (box.findColour (TextButton::buttonColourId));
  52625. g.drawRect (0, 0, width, height, 2);
  52626. }
  52627. else
  52628. {
  52629. g.setColour (box.findColour (ComboBox::outlineColourId));
  52630. g.drawRect (0, 0, width, height);
  52631. }
  52632. const float outlineThickness = box.isEnabled() ? (isButtonDown ? 1.2f : 0.5f) : 0.3f;
  52633. const Colour baseColour (createBaseColour (box.findColour (ComboBox::buttonColourId),
  52634. box.hasKeyboardFocus (true),
  52635. false, isButtonDown)
  52636. .withMultipliedAlpha (box.isEnabled() ? 1.0f : 0.5f));
  52637. drawGlassLozenge (g,
  52638. buttonX + outlineThickness, buttonY + outlineThickness,
  52639. buttonW - outlineThickness * 2.0f, buttonH - outlineThickness * 2.0f,
  52640. baseColour, outlineThickness, -1.0f,
  52641. true, true, true, true);
  52642. if (box.isEnabled())
  52643. {
  52644. const float arrowX = 0.3f;
  52645. const float arrowH = 0.2f;
  52646. Path p;
  52647. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.45f - arrowH),
  52648. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.45f,
  52649. buttonX + buttonW * arrowX, buttonY + buttonH * 0.45f);
  52650. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.55f + arrowH),
  52651. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.55f,
  52652. buttonX + buttonW * arrowX, buttonY + buttonH * 0.55f);
  52653. g.setColour (box.findColour (ComboBox::arrowColourId));
  52654. g.fillPath (p);
  52655. }
  52656. }
  52657. const Font LookAndFeel::getComboBoxFont (ComboBox& box)
  52658. {
  52659. return Font (jmin (15.0f, box.getHeight() * 0.85f));
  52660. }
  52661. Label* LookAndFeel::createComboBoxTextBox (ComboBox&)
  52662. {
  52663. return new Label (String::empty, String::empty);
  52664. }
  52665. void LookAndFeel::positionComboBoxText (ComboBox& box, Label& label)
  52666. {
  52667. label.setBounds (1, 1,
  52668. box.getWidth() + 3 - box.getHeight(),
  52669. box.getHeight() - 2);
  52670. label.setFont (getComboBoxFont (box));
  52671. }
  52672. void LookAndFeel::drawLabel (Graphics& g, Label& label)
  52673. {
  52674. g.fillAll (label.findColour (Label::backgroundColourId));
  52675. if (! label.isBeingEdited())
  52676. {
  52677. const float alpha = label.isEnabled() ? 1.0f : 0.5f;
  52678. g.setColour (label.findColour (Label::textColourId).withMultipliedAlpha (alpha));
  52679. g.setFont (label.getFont());
  52680. g.drawFittedText (label.getText(),
  52681. label.getHorizontalBorderSize(),
  52682. label.getVerticalBorderSize(),
  52683. label.getWidth() - 2 * label.getHorizontalBorderSize(),
  52684. label.getHeight() - 2 * label.getVerticalBorderSize(),
  52685. label.getJustificationType(),
  52686. jmax (1, (int) (label.getHeight() / label.getFont().getHeight())),
  52687. label.getMinimumHorizontalScale());
  52688. g.setColour (label.findColour (Label::outlineColourId).withMultipliedAlpha (alpha));
  52689. g.drawRect (0, 0, label.getWidth(), label.getHeight());
  52690. }
  52691. else if (label.isEnabled())
  52692. {
  52693. g.setColour (label.findColour (Label::outlineColourId));
  52694. g.drawRect (0, 0, label.getWidth(), label.getHeight());
  52695. }
  52696. }
  52697. void LookAndFeel::drawLinearSliderBackground (Graphics& g,
  52698. int x, int y,
  52699. int width, int height,
  52700. float /*sliderPos*/,
  52701. float /*minSliderPos*/,
  52702. float /*maxSliderPos*/,
  52703. const Slider::SliderStyle /*style*/,
  52704. Slider& slider)
  52705. {
  52706. const float sliderRadius = (float) (getSliderThumbRadius (slider) - 2);
  52707. const Colour trackColour (slider.findColour (Slider::trackColourId));
  52708. const Colour gradCol1 (trackColour.overlaidWith (Colours::black.withAlpha (slider.isEnabled() ? 0.25f : 0.13f)));
  52709. const Colour gradCol2 (trackColour.overlaidWith (Colour (0x14000000)));
  52710. Path indent;
  52711. if (slider.isHorizontal())
  52712. {
  52713. const float iy = y + height * 0.5f - sliderRadius * 0.5f;
  52714. const float ih = sliderRadius;
  52715. g.setGradientFill (ColourGradient (gradCol1, 0.0f, iy,
  52716. gradCol2, 0.0f, iy + ih, false));
  52717. indent.addRoundedRectangle (x - sliderRadius * 0.5f, iy,
  52718. width + sliderRadius, ih,
  52719. 5.0f);
  52720. g.fillPath (indent);
  52721. }
  52722. else
  52723. {
  52724. const float ix = x + width * 0.5f - sliderRadius * 0.5f;
  52725. const float iw = sliderRadius;
  52726. g.setGradientFill (ColourGradient (gradCol1, ix, 0.0f,
  52727. gradCol2, ix + iw, 0.0f, false));
  52728. indent.addRoundedRectangle (ix, y - sliderRadius * 0.5f,
  52729. iw, height + sliderRadius,
  52730. 5.0f);
  52731. g.fillPath (indent);
  52732. }
  52733. g.setColour (Colour (0x4c000000));
  52734. g.strokePath (indent, PathStrokeType (0.5f));
  52735. }
  52736. void LookAndFeel::drawLinearSliderThumb (Graphics& g,
  52737. int x, int y,
  52738. int width, int height,
  52739. float sliderPos,
  52740. float minSliderPos,
  52741. float maxSliderPos,
  52742. const Slider::SliderStyle style,
  52743. Slider& slider)
  52744. {
  52745. const float sliderRadius = (float) (getSliderThumbRadius (slider) - 2);
  52746. Colour knobColour (createBaseColour (slider.findColour (Slider::thumbColourId),
  52747. slider.hasKeyboardFocus (false) && slider.isEnabled(),
  52748. slider.isMouseOverOrDragging() && slider.isEnabled(),
  52749. slider.isMouseButtonDown() && slider.isEnabled()));
  52750. const float outlineThickness = slider.isEnabled() ? 0.8f : 0.3f;
  52751. if (style == Slider::LinearHorizontal || style == Slider::LinearVertical)
  52752. {
  52753. float kx, ky;
  52754. if (style == Slider::LinearVertical)
  52755. {
  52756. kx = x + width * 0.5f;
  52757. ky = sliderPos;
  52758. }
  52759. else
  52760. {
  52761. kx = sliderPos;
  52762. ky = y + height * 0.5f;
  52763. }
  52764. drawGlassSphere (g,
  52765. kx - sliderRadius,
  52766. ky - sliderRadius,
  52767. sliderRadius * 2.0f,
  52768. knobColour, outlineThickness);
  52769. }
  52770. else
  52771. {
  52772. if (style == Slider::ThreeValueVertical)
  52773. {
  52774. drawGlassSphere (g, x + width * 0.5f - sliderRadius,
  52775. sliderPos - sliderRadius,
  52776. sliderRadius * 2.0f,
  52777. knobColour, outlineThickness);
  52778. }
  52779. else if (style == Slider::ThreeValueHorizontal)
  52780. {
  52781. drawGlassSphere (g,sliderPos - sliderRadius,
  52782. y + height * 0.5f - sliderRadius,
  52783. sliderRadius * 2.0f,
  52784. knobColour, outlineThickness);
  52785. }
  52786. if (style == Slider::TwoValueVertical || style == Slider::ThreeValueVertical)
  52787. {
  52788. const float sr = jmin (sliderRadius, width * 0.4f);
  52789. drawGlassPointer (g, jmax (0.0f, x + width * 0.5f - sliderRadius * 2.0f),
  52790. minSliderPos - sliderRadius,
  52791. sliderRadius * 2.0f, knobColour, outlineThickness, 1);
  52792. drawGlassPointer (g, jmin (x + width - sliderRadius * 2.0f, x + width * 0.5f), maxSliderPos - sr,
  52793. sliderRadius * 2.0f, knobColour, outlineThickness, 3);
  52794. }
  52795. else if (style == Slider::TwoValueHorizontal || style == Slider::ThreeValueHorizontal)
  52796. {
  52797. const float sr = jmin (sliderRadius, height * 0.4f);
  52798. drawGlassPointer (g, minSliderPos - sr,
  52799. jmax (0.0f, y + height * 0.5f - sliderRadius * 2.0f),
  52800. sliderRadius * 2.0f, knobColour, outlineThickness, 2);
  52801. drawGlassPointer (g, maxSliderPos - sliderRadius,
  52802. jmin (y + height - sliderRadius * 2.0f, y + height * 0.5f),
  52803. sliderRadius * 2.0f, knobColour, outlineThickness, 4);
  52804. }
  52805. }
  52806. }
  52807. void LookAndFeel::drawLinearSlider (Graphics& g,
  52808. int x, int y,
  52809. int width, int height,
  52810. float sliderPos,
  52811. float minSliderPos,
  52812. float maxSliderPos,
  52813. const Slider::SliderStyle style,
  52814. Slider& slider)
  52815. {
  52816. g.fillAll (slider.findColour (Slider::backgroundColourId));
  52817. if (style == Slider::LinearBar)
  52818. {
  52819. const bool isMouseOver = slider.isMouseOverOrDragging() && slider.isEnabled();
  52820. Colour baseColour (createBaseColour (slider.findColour (Slider::thumbColourId)
  52821. .withMultipliedSaturation (slider.isEnabled() ? 1.0f : 0.5f),
  52822. false,
  52823. isMouseOver,
  52824. isMouseOver || slider.isMouseButtonDown()));
  52825. drawShinyButtonShape (g,
  52826. (float) x, (float) y, sliderPos - (float) x, (float) height, 0.0f,
  52827. baseColour,
  52828. slider.isEnabled() ? 0.9f : 0.3f,
  52829. true, true, true, true);
  52830. }
  52831. else
  52832. {
  52833. drawLinearSliderBackground (g, x, y, width, height, sliderPos, minSliderPos, maxSliderPos, style, slider);
  52834. drawLinearSliderThumb (g, x, y, width, height, sliderPos, minSliderPos, maxSliderPos, style, slider);
  52835. }
  52836. }
  52837. int LookAndFeel::getSliderThumbRadius (Slider& slider)
  52838. {
  52839. return jmin (7,
  52840. slider.getHeight() / 2,
  52841. slider.getWidth() / 2) + 2;
  52842. }
  52843. void LookAndFeel::drawRotarySlider (Graphics& g,
  52844. int x, int y,
  52845. int width, int height,
  52846. float sliderPos,
  52847. const float rotaryStartAngle,
  52848. const float rotaryEndAngle,
  52849. Slider& slider)
  52850. {
  52851. const float radius = jmin (width / 2, height / 2) - 2.0f;
  52852. const float centreX = x + width * 0.5f;
  52853. const float centreY = y + height * 0.5f;
  52854. const float rx = centreX - radius;
  52855. const float ry = centreY - radius;
  52856. const float rw = radius * 2.0f;
  52857. const float angle = rotaryStartAngle + sliderPos * (rotaryEndAngle - rotaryStartAngle);
  52858. const bool isMouseOver = slider.isMouseOverOrDragging() && slider.isEnabled();
  52859. if (radius > 12.0f)
  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. const float thickness = 0.7f;
  52866. {
  52867. Path filledArc;
  52868. filledArc.addPieSegment (rx, ry, rw, rw,
  52869. rotaryStartAngle,
  52870. angle,
  52871. thickness);
  52872. g.fillPath (filledArc);
  52873. }
  52874. if (thickness > 0)
  52875. {
  52876. const float innerRadius = radius * 0.2f;
  52877. Path p;
  52878. p.addTriangle (-innerRadius, 0.0f,
  52879. 0.0f, -radius * thickness * 1.1f,
  52880. innerRadius, 0.0f);
  52881. p.addEllipse (-innerRadius, -innerRadius, innerRadius * 2.0f, innerRadius * 2.0f);
  52882. g.fillPath (p, AffineTransform::rotation (angle).translated (centreX, centreY));
  52883. }
  52884. if (slider.isEnabled())
  52885. g.setColour (slider.findColour (Slider::rotarySliderOutlineColourId));
  52886. else
  52887. g.setColour (Colour (0x80808080));
  52888. Path outlineArc;
  52889. outlineArc.addPieSegment (rx, ry, rw, rw, rotaryStartAngle, rotaryEndAngle, thickness);
  52890. outlineArc.closeSubPath();
  52891. g.strokePath (outlineArc, PathStrokeType (slider.isEnabled() ? (isMouseOver ? 2.0f : 1.2f) : 0.3f));
  52892. }
  52893. else
  52894. {
  52895. if (slider.isEnabled())
  52896. g.setColour (slider.findColour (Slider::rotarySliderFillColourId).withAlpha (isMouseOver ? 1.0f : 0.7f));
  52897. else
  52898. g.setColour (Colour (0x80808080));
  52899. Path p;
  52900. p.addEllipse (-0.4f * rw, -0.4f * rw, rw * 0.8f, rw * 0.8f);
  52901. PathStrokeType (rw * 0.1f).createStrokedPath (p, p);
  52902. p.addLineSegment (0.0f, 0.0f, 0.0f, -radius, rw * 0.2f);
  52903. g.fillPath (p, AffineTransform::rotation (angle).translated (centreX, centreY));
  52904. }
  52905. }
  52906. Button* LookAndFeel::createSliderButton (const bool isIncrement)
  52907. {
  52908. return new TextButton (isIncrement ? "+" : "-", String::empty);
  52909. }
  52910. class SliderLabelComp : public Label
  52911. {
  52912. public:
  52913. SliderLabelComp() : Label (String::empty, String::empty) {}
  52914. ~SliderLabelComp() {}
  52915. void mouseWheelMove (const MouseEvent&, float, float) {}
  52916. };
  52917. Label* LookAndFeel::createSliderTextBox (Slider& slider)
  52918. {
  52919. Label* const l = new SliderLabelComp();
  52920. l->setJustificationType (Justification::centred);
  52921. l->setColour (Label::textColourId, slider.findColour (Slider::textBoxTextColourId));
  52922. l->setColour (Label::backgroundColourId,
  52923. (slider.getSliderStyle() == Slider::LinearBar) ? Colours::transparentBlack
  52924. : slider.findColour (Slider::textBoxBackgroundColourId));
  52925. l->setColour (Label::outlineColourId, slider.findColour (Slider::textBoxOutlineColourId));
  52926. l->setColour (TextEditor::textColourId, slider.findColour (Slider::textBoxTextColourId));
  52927. l->setColour (TextEditor::backgroundColourId,
  52928. slider.findColour (Slider::textBoxBackgroundColourId)
  52929. .withAlpha (slider.getSliderStyle() == Slider::LinearBar ? 0.7f : 1.0f));
  52930. l->setColour (TextEditor::outlineColourId, slider.findColour (Slider::textBoxOutlineColourId));
  52931. return l;
  52932. }
  52933. ImageEffectFilter* LookAndFeel::getSliderEffect()
  52934. {
  52935. return 0;
  52936. }
  52937. static const TextLayout layoutTooltipText (const String& text) throw()
  52938. {
  52939. const float tooltipFontSize = 12.0f;
  52940. const int maxToolTipWidth = 400;
  52941. const Font f (tooltipFontSize, Font::bold);
  52942. TextLayout tl (text, f);
  52943. tl.layout (maxToolTipWidth, Justification::left, true);
  52944. return tl;
  52945. }
  52946. void LookAndFeel::getTooltipSize (const String& tipText, int& width, int& height)
  52947. {
  52948. const TextLayout tl (layoutTooltipText (tipText));
  52949. width = tl.getWidth() + 14;
  52950. height = tl.getHeight() + 6;
  52951. }
  52952. void LookAndFeel::drawTooltip (Graphics& g, const String& text, int width, int height)
  52953. {
  52954. g.fillAll (findColour (TooltipWindow::backgroundColourId));
  52955. const Colour textCol (findColour (TooltipWindow::textColourId));
  52956. #if ! JUCE_MAC // The mac windows already have a non-optional 1 pix outline, so don't double it here..
  52957. g.setColour (findColour (TooltipWindow::outlineColourId));
  52958. g.drawRect (0, 0, width, height, 1);
  52959. #endif
  52960. const TextLayout tl (layoutTooltipText (text));
  52961. g.setColour (findColour (TooltipWindow::textColourId));
  52962. tl.drawWithin (g, 0, 0, width, height, Justification::centred);
  52963. }
  52964. Button* LookAndFeel::createFilenameComponentBrowseButton (const String& text)
  52965. {
  52966. return new TextButton (text, TRANS("click to browse for a different file"));
  52967. }
  52968. void LookAndFeel::layoutFilenameComponent (FilenameComponent& filenameComp,
  52969. ComboBox* filenameBox,
  52970. Button* browseButton)
  52971. {
  52972. browseButton->setSize (80, filenameComp.getHeight());
  52973. TextButton* const tb = dynamic_cast <TextButton*> (browseButton);
  52974. if (tb != 0)
  52975. tb->changeWidthToFitText();
  52976. browseButton->setTopRightPosition (filenameComp.getWidth(), 0);
  52977. filenameBox->setBounds (0, 0, browseButton->getX(), filenameComp.getHeight());
  52978. }
  52979. void LookAndFeel::drawImageButton (Graphics& g, Image* image,
  52980. int imageX, int imageY, int imageW, int imageH,
  52981. const Colour& overlayColour,
  52982. float imageOpacity,
  52983. ImageButton& button)
  52984. {
  52985. if (! button.isEnabled())
  52986. imageOpacity *= 0.3f;
  52987. if (! overlayColour.isOpaque())
  52988. {
  52989. g.setOpacity (imageOpacity);
  52990. g.drawImage (image, imageX, imageY, imageW, imageH,
  52991. 0, 0, image->getWidth(), image->getHeight(), false);
  52992. }
  52993. if (! overlayColour.isTransparent())
  52994. {
  52995. g.setColour (overlayColour);
  52996. g.drawImage (image, imageX, imageY, imageW, imageH,
  52997. 0, 0, image->getWidth(), image->getHeight(), true);
  52998. }
  52999. }
  53000. void LookAndFeel::drawCornerResizer (Graphics& g,
  53001. int w, int h,
  53002. bool /*isMouseOver*/,
  53003. bool /*isMouseDragging*/)
  53004. {
  53005. const float lineThickness = jmin (w, h) * 0.075f;
  53006. for (float i = 0.0f; i < 1.0f; i += 0.3f)
  53007. {
  53008. g.setColour (Colours::lightgrey);
  53009. g.drawLine (w * i,
  53010. h + 1.0f,
  53011. w + 1.0f,
  53012. h * i,
  53013. lineThickness);
  53014. g.setColour (Colours::darkgrey);
  53015. g.drawLine (w * i + lineThickness,
  53016. h + 1.0f,
  53017. w + 1.0f,
  53018. h * i + lineThickness,
  53019. lineThickness);
  53020. }
  53021. }
  53022. void LookAndFeel::drawResizableFrame (Graphics&, int /*w*/, int /*h*/,
  53023. const BorderSize& /*borders*/)
  53024. {
  53025. }
  53026. void LookAndFeel::fillResizableWindowBackground (Graphics& g, int /*w*/, int /*h*/,
  53027. const BorderSize& /*border*/, ResizableWindow& window)
  53028. {
  53029. g.fillAll (window.getBackgroundColour());
  53030. }
  53031. void LookAndFeel::drawResizableWindowBorder (Graphics& g, int w, int h,
  53032. const BorderSize& border, ResizableWindow&)
  53033. {
  53034. g.setColour (Colour (0x80000000));
  53035. g.drawRect (0, 0, w, h);
  53036. g.setColour (Colour (0x19000000));
  53037. g.drawRect (border.getLeft() - 1,
  53038. border.getTop() - 1,
  53039. w + 2 - border.getLeftAndRight(),
  53040. h + 2 - border.getTopAndBottom());
  53041. }
  53042. void LookAndFeel::drawDocumentWindowTitleBar (DocumentWindow& window,
  53043. Graphics& g, int w, int h,
  53044. int titleSpaceX, int titleSpaceW,
  53045. const Image* icon,
  53046. bool drawTitleTextOnLeft)
  53047. {
  53048. const bool isActive = window.isActiveWindow();
  53049. g.setGradientFill (ColourGradient (window.getBackgroundColour(),
  53050. 0.0f, 0.0f,
  53051. window.getBackgroundColour().contrasting (isActive ? 0.15f : 0.05f),
  53052. 0.0f, (float) h, false));
  53053. g.fillAll();
  53054. Font font (h * 0.65f, Font::bold);
  53055. g.setFont (font);
  53056. int textW = font.getStringWidth (window.getName());
  53057. int iconW = 0;
  53058. int iconH = 0;
  53059. if (icon != 0)
  53060. {
  53061. iconH = (int) font.getHeight();
  53062. iconW = icon->getWidth() * iconH / icon->getHeight() + 4;
  53063. }
  53064. textW = jmin (titleSpaceW, textW + iconW);
  53065. int textX = drawTitleTextOnLeft ? titleSpaceX
  53066. : jmax (titleSpaceX, (w - textW) / 2);
  53067. if (textX + textW > titleSpaceX + titleSpaceW)
  53068. textX = titleSpaceX + titleSpaceW - textW;
  53069. if (icon != 0)
  53070. {
  53071. g.setOpacity (isActive ? 1.0f : 0.6f);
  53072. g.drawImageWithin (icon, textX, (h - iconH) / 2, iconW, iconH,
  53073. RectanglePlacement::centred, false);
  53074. textX += iconW;
  53075. textW -= iconW;
  53076. }
  53077. if (window.isColourSpecified (DocumentWindow::textColourId) || isColourSpecified (DocumentWindow::textColourId))
  53078. g.setColour (findColour (DocumentWindow::textColourId));
  53079. else
  53080. g.setColour (window.getBackgroundColour().contrasting (isActive ? 0.7f : 0.4f));
  53081. g.drawText (window.getName(), textX, 0, textW, h, Justification::centredLeft, true);
  53082. }
  53083. class GlassWindowButton : public Button
  53084. {
  53085. public:
  53086. GlassWindowButton (const String& name, const Colour& col,
  53087. const Path& normalShape_,
  53088. const Path& toggledShape_) throw()
  53089. : Button (name),
  53090. colour (col),
  53091. normalShape (normalShape_),
  53092. toggledShape (toggledShape_)
  53093. {
  53094. }
  53095. ~GlassWindowButton()
  53096. {
  53097. }
  53098. void paintButton (Graphics& g, bool isMouseOverButton, bool isButtonDown)
  53099. {
  53100. float alpha = isMouseOverButton ? (isButtonDown ? 1.0f : 0.8f) : 0.55f;
  53101. if (! isEnabled())
  53102. alpha *= 0.5f;
  53103. float x = 0, y = 0, diam;
  53104. if (getWidth() < getHeight())
  53105. {
  53106. diam = (float) getWidth();
  53107. y = (getHeight() - getWidth()) * 0.5f;
  53108. }
  53109. else
  53110. {
  53111. diam = (float) getHeight();
  53112. y = (getWidth() - getHeight()) * 0.5f;
  53113. }
  53114. x += diam * 0.05f;
  53115. y += diam * 0.05f;
  53116. diam *= 0.9f;
  53117. g.setGradientFill (ColourGradient (Colour::greyLevel (0.9f).withAlpha (alpha), 0, y + diam,
  53118. Colour::greyLevel (0.6f).withAlpha (alpha), 0, y, false));
  53119. g.fillEllipse (x, y, diam, diam);
  53120. x += 2.0f;
  53121. y += 2.0f;
  53122. diam -= 4.0f;
  53123. LookAndFeel::drawGlassSphere (g, x, y, diam, colour.withAlpha (alpha), 1.0f);
  53124. Path& p = getToggleState() ? toggledShape : normalShape;
  53125. const AffineTransform t (p.getTransformToScaleToFit (x + diam * 0.3f, y + diam * 0.3f,
  53126. diam * 0.4f, diam * 0.4f, true));
  53127. g.setColour (Colours::black.withAlpha (alpha * 0.6f));
  53128. g.fillPath (p, t);
  53129. }
  53130. juce_UseDebuggingNewOperator
  53131. private:
  53132. Colour colour;
  53133. Path normalShape, toggledShape;
  53134. GlassWindowButton (const GlassWindowButton&);
  53135. const GlassWindowButton& operator= (const GlassWindowButton&);
  53136. };
  53137. Button* LookAndFeel::createDocumentWindowButton (int buttonType)
  53138. {
  53139. Path shape;
  53140. const float crossThickness = 0.25f;
  53141. if (buttonType == DocumentWindow::closeButton)
  53142. {
  53143. shape.addLineSegment (0.0f, 0.0f, 1.0f, 1.0f, crossThickness * 1.4f);
  53144. shape.addLineSegment (1.0f, 0.0f, 0.0f, 1.0f, crossThickness * 1.4f);
  53145. return new GlassWindowButton ("close", Colour (0xffdd1100), shape, shape);
  53146. }
  53147. else if (buttonType == DocumentWindow::minimiseButton)
  53148. {
  53149. shape.addLineSegment (0.0f, 0.5f, 1.0f, 0.5f, crossThickness);
  53150. return new GlassWindowButton ("minimise", Colour (0xffaa8811), shape, shape);
  53151. }
  53152. else if (buttonType == DocumentWindow::maximiseButton)
  53153. {
  53154. shape.addLineSegment (0.5f, 0.0f, 0.5f, 1.0f, crossThickness);
  53155. shape.addLineSegment (0.0f, 0.5f, 1.0f, 0.5f, crossThickness);
  53156. Path fullscreenShape;
  53157. fullscreenShape.startNewSubPath (45.0f, 100.0f);
  53158. fullscreenShape.lineTo (0.0f, 100.0f);
  53159. fullscreenShape.lineTo (0.0f, 0.0f);
  53160. fullscreenShape.lineTo (100.0f, 0.0f);
  53161. fullscreenShape.lineTo (100.0f, 45.0f);
  53162. fullscreenShape.addRectangle (45.0f, 45.0f, 100.0f, 100.0f);
  53163. PathStrokeType (30.0f).createStrokedPath (fullscreenShape, fullscreenShape);
  53164. return new GlassWindowButton ("maximise", Colour (0xff119911), shape, fullscreenShape);
  53165. }
  53166. jassertfalse
  53167. return 0;
  53168. }
  53169. void LookAndFeel::positionDocumentWindowButtons (DocumentWindow&,
  53170. int titleBarX,
  53171. int titleBarY,
  53172. int titleBarW,
  53173. int titleBarH,
  53174. Button* minimiseButton,
  53175. Button* maximiseButton,
  53176. Button* closeButton,
  53177. bool positionTitleBarButtonsOnLeft)
  53178. {
  53179. const int buttonW = titleBarH - titleBarH / 8;
  53180. int x = positionTitleBarButtonsOnLeft ? titleBarX + 4
  53181. : titleBarX + titleBarW - buttonW - buttonW / 4;
  53182. if (closeButton != 0)
  53183. {
  53184. closeButton->setBounds (x, titleBarY, buttonW, titleBarH);
  53185. x += positionTitleBarButtonsOnLeft ? buttonW : -(buttonW + buttonW / 4);
  53186. }
  53187. if (positionTitleBarButtonsOnLeft)
  53188. swapVariables (minimiseButton, maximiseButton);
  53189. if (maximiseButton != 0)
  53190. {
  53191. maximiseButton->setBounds (x, titleBarY, buttonW, titleBarH);
  53192. x += positionTitleBarButtonsOnLeft ? buttonW : -buttonW;
  53193. }
  53194. if (minimiseButton != 0)
  53195. minimiseButton->setBounds (x, titleBarY, buttonW, titleBarH);
  53196. }
  53197. int LookAndFeel::getDefaultMenuBarHeight()
  53198. {
  53199. return 24;
  53200. }
  53201. DropShadower* LookAndFeel::createDropShadowerForComponent (Component*)
  53202. {
  53203. return new DropShadower (0.4f, 1, 5, 10);
  53204. }
  53205. void LookAndFeel::drawStretchableLayoutResizerBar (Graphics& g,
  53206. int w, int h,
  53207. bool /*isVerticalBar*/,
  53208. bool isMouseOver,
  53209. bool isMouseDragging)
  53210. {
  53211. float alpha = 0.5f;
  53212. if (isMouseOver || isMouseDragging)
  53213. {
  53214. g.fillAll (Colour (0x190000ff));
  53215. alpha = 1.0f;
  53216. }
  53217. const float cx = w * 0.5f;
  53218. const float cy = h * 0.5f;
  53219. const float cr = jmin (w, h) * 0.4f;
  53220. g.setGradientFill (ColourGradient (Colours::white.withAlpha (alpha), cx + cr * 0.1f, cy + cr,
  53221. Colours::black.withAlpha (alpha), cx, cy - cr * 4.0f,
  53222. true));
  53223. g.fillEllipse (cx - cr, cy - cr, cr * 2.0f, cr * 2.0f);
  53224. }
  53225. void LookAndFeel::drawGroupComponentOutline (Graphics& g, int width, int height,
  53226. const String& text,
  53227. const Justification& position,
  53228. GroupComponent& group)
  53229. {
  53230. const float textH = 15.0f;
  53231. const float indent = 3.0f;
  53232. const float textEdgeGap = 4.0f;
  53233. float cs = 5.0f;
  53234. Font f (textH);
  53235. Path p;
  53236. float x = indent;
  53237. float y = f.getAscent() - 3.0f;
  53238. float w = jmax (0.0f, width - x * 2.0f);
  53239. float h = jmax (0.0f, height - y - indent);
  53240. cs = jmin (cs, w * 0.5f, h * 0.5f);
  53241. const float cs2 = 2.0f * cs;
  53242. float textW = text.isEmpty() ? 0 : jlimit (0.0f, jmax (0.0f, w - cs2 - textEdgeGap * 2), f.getStringWidth (text) + textEdgeGap * 2.0f);
  53243. float textX = cs + textEdgeGap;
  53244. if (position.testFlags (Justification::horizontallyCentred))
  53245. textX = cs + (w - cs2 - textW) * 0.5f;
  53246. else if (position.testFlags (Justification::right))
  53247. textX = w - cs - textW - textEdgeGap;
  53248. p.startNewSubPath (x + textX + textW, y);
  53249. p.lineTo (x + w - cs, y);
  53250. p.addArc (x + w - cs2, y, cs2, cs2, 0, float_Pi * 0.5f);
  53251. p.lineTo (x + w, y + h - cs);
  53252. p.addArc (x + w - cs2, y + h - cs2, cs2, cs2, float_Pi * 0.5f, float_Pi);
  53253. p.lineTo (x + cs, y + h);
  53254. p.addArc (x, y + h - cs2, cs2, cs2, float_Pi, float_Pi * 1.5f);
  53255. p.lineTo (x, y + cs);
  53256. p.addArc (x, y, cs2, cs2, float_Pi * 1.5f, float_Pi * 2.0f);
  53257. p.lineTo (x + textX, y);
  53258. const float alpha = group.isEnabled() ? 1.0f : 0.5f;
  53259. g.setColour (group.findColour (GroupComponent::outlineColourId)
  53260. .withMultipliedAlpha (alpha));
  53261. g.strokePath (p, PathStrokeType (2.0f));
  53262. g.setColour (group.findColour (GroupComponent::textColourId)
  53263. .withMultipliedAlpha (alpha));
  53264. g.setFont (f);
  53265. g.drawText (text,
  53266. roundToInt (x + textX), 0,
  53267. roundToInt (textW),
  53268. roundToInt (textH),
  53269. Justification::centred, true);
  53270. }
  53271. int LookAndFeel::getTabButtonOverlap (int tabDepth)
  53272. {
  53273. return 1 + tabDepth / 3;
  53274. }
  53275. int LookAndFeel::getTabButtonSpaceAroundImage()
  53276. {
  53277. return 4;
  53278. }
  53279. void LookAndFeel::createTabButtonShape (Path& p,
  53280. int width, int height,
  53281. int /*tabIndex*/,
  53282. const String& /*text*/,
  53283. Button& /*button*/,
  53284. TabbedButtonBar::Orientation orientation,
  53285. const bool /*isMouseOver*/,
  53286. const bool /*isMouseDown*/,
  53287. const bool /*isFrontTab*/)
  53288. {
  53289. const float w = (float) width;
  53290. const float h = (float) height;
  53291. float length = w;
  53292. float depth = h;
  53293. if (orientation == TabbedButtonBar::TabsAtLeft
  53294. || orientation == TabbedButtonBar::TabsAtRight)
  53295. {
  53296. swapVariables (length, depth);
  53297. }
  53298. const float indent = (float) getTabButtonOverlap ((int) depth);
  53299. const float overhang = 4.0f;
  53300. if (orientation == TabbedButtonBar::TabsAtLeft)
  53301. {
  53302. p.startNewSubPath (w, 0.0f);
  53303. p.lineTo (0.0f, indent);
  53304. p.lineTo (0.0f, h - indent);
  53305. p.lineTo (w, h);
  53306. p.lineTo (w + overhang, h + overhang);
  53307. p.lineTo (w + overhang, -overhang);
  53308. }
  53309. else if (orientation == TabbedButtonBar::TabsAtRight)
  53310. {
  53311. p.startNewSubPath (0.0f, 0.0f);
  53312. p.lineTo (w, indent);
  53313. p.lineTo (w, h - indent);
  53314. p.lineTo (0.0f, h);
  53315. p.lineTo (-overhang, h + overhang);
  53316. p.lineTo (-overhang, -overhang);
  53317. }
  53318. else if (orientation == TabbedButtonBar::TabsAtBottom)
  53319. {
  53320. p.startNewSubPath (0.0f, 0.0f);
  53321. p.lineTo (indent, h);
  53322. p.lineTo (w - indent, h);
  53323. p.lineTo (w, 0.0f);
  53324. p.lineTo (w + overhang, -overhang);
  53325. p.lineTo (-overhang, -overhang);
  53326. }
  53327. else
  53328. {
  53329. p.startNewSubPath (0.0f, h);
  53330. p.lineTo (indent, 0.0f);
  53331. p.lineTo (w - indent, 0.0f);
  53332. p.lineTo (w, h);
  53333. p.lineTo (w + overhang, h + overhang);
  53334. p.lineTo (-overhang, h + overhang);
  53335. }
  53336. p.closeSubPath();
  53337. p = p.createPathWithRoundedCorners (3.0f);
  53338. }
  53339. void LookAndFeel::fillTabButtonShape (Graphics& g,
  53340. const Path& path,
  53341. const Colour& preferredColour,
  53342. int /*tabIndex*/,
  53343. const String& /*text*/,
  53344. Button& button,
  53345. TabbedButtonBar::Orientation /*orientation*/,
  53346. const bool /*isMouseOver*/,
  53347. const bool /*isMouseDown*/,
  53348. const bool isFrontTab)
  53349. {
  53350. g.setColour (isFrontTab ? preferredColour
  53351. : preferredColour.withMultipliedAlpha (0.9f));
  53352. g.fillPath (path);
  53353. g.setColour (button.findColour (isFrontTab ? TabbedButtonBar::frontOutlineColourId
  53354. : TabbedButtonBar::tabOutlineColourId, false)
  53355. .withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.5f));
  53356. g.strokePath (path, PathStrokeType (isFrontTab ? 1.0f : 0.5f));
  53357. }
  53358. void LookAndFeel::drawTabButtonText (Graphics& g,
  53359. int x, int y, int w, int h,
  53360. const Colour& preferredBackgroundColour,
  53361. int /*tabIndex*/,
  53362. const String& text,
  53363. Button& button,
  53364. TabbedButtonBar::Orientation orientation,
  53365. const bool isMouseOver,
  53366. const bool isMouseDown,
  53367. const bool isFrontTab)
  53368. {
  53369. int length = w;
  53370. int depth = h;
  53371. if (orientation == TabbedButtonBar::TabsAtLeft
  53372. || orientation == TabbedButtonBar::TabsAtRight)
  53373. {
  53374. swapVariables (length, depth);
  53375. }
  53376. Font font (depth * 0.6f);
  53377. font.setUnderline (button.hasKeyboardFocus (false));
  53378. GlyphArrangement textLayout;
  53379. textLayout.addFittedText (font, text.trim(),
  53380. 0.0f, 0.0f, (float) length, (float) depth,
  53381. Justification::centred,
  53382. jmax (1, depth / 12));
  53383. AffineTransform transform;
  53384. if (orientation == TabbedButtonBar::TabsAtLeft)
  53385. {
  53386. transform = transform.rotated (float_Pi * -0.5f)
  53387. .translated ((float) x, (float) (y + h));
  53388. }
  53389. else if (orientation == TabbedButtonBar::TabsAtRight)
  53390. {
  53391. transform = transform.rotated (float_Pi * 0.5f)
  53392. .translated ((float) (x + w), (float) y);
  53393. }
  53394. else
  53395. {
  53396. transform = transform.translated ((float) x, (float) y);
  53397. }
  53398. if (isFrontTab && (button.isColourSpecified (TabbedButtonBar::frontTextColourId) || isColourSpecified (TabbedButtonBar::frontTextColourId)))
  53399. g.setColour (findColour (TabbedButtonBar::frontTextColourId));
  53400. else if (button.isColourSpecified (TabbedButtonBar::tabTextColourId) || isColourSpecified (TabbedButtonBar::tabTextColourId))
  53401. g.setColour (findColour (TabbedButtonBar::tabTextColourId));
  53402. else
  53403. g.setColour (preferredBackgroundColour.contrasting());
  53404. if (! (isMouseOver || isMouseDown))
  53405. g.setOpacity (0.8f);
  53406. if (! button.isEnabled())
  53407. g.setOpacity (0.3f);
  53408. textLayout.draw (g, transform);
  53409. }
  53410. int LookAndFeel::getTabButtonBestWidth (int /*tabIndex*/,
  53411. const String& text,
  53412. int tabDepth,
  53413. Button&)
  53414. {
  53415. Font f (tabDepth * 0.6f);
  53416. return f.getStringWidth (text.trim()) + getTabButtonOverlap (tabDepth) * 2;
  53417. }
  53418. void LookAndFeel::drawTabButton (Graphics& g,
  53419. int w, int h,
  53420. const Colour& preferredColour,
  53421. int tabIndex,
  53422. const String& text,
  53423. Button& button,
  53424. TabbedButtonBar::Orientation orientation,
  53425. const bool isMouseOver,
  53426. const bool isMouseDown,
  53427. const bool isFrontTab)
  53428. {
  53429. int length = w;
  53430. int depth = h;
  53431. if (orientation == TabbedButtonBar::TabsAtLeft
  53432. || orientation == TabbedButtonBar::TabsAtRight)
  53433. {
  53434. swapVariables (length, depth);
  53435. }
  53436. Path tabShape;
  53437. createTabButtonShape (tabShape, w, h,
  53438. tabIndex, text, button, orientation,
  53439. isMouseOver, isMouseDown, isFrontTab);
  53440. fillTabButtonShape (g, tabShape, preferredColour,
  53441. tabIndex, text, button, orientation,
  53442. isMouseOver, isMouseDown, isFrontTab);
  53443. const int indent = getTabButtonOverlap (depth);
  53444. int x = 0, y = 0;
  53445. if (orientation == TabbedButtonBar::TabsAtLeft
  53446. || orientation == TabbedButtonBar::TabsAtRight)
  53447. {
  53448. y += indent;
  53449. h -= indent * 2;
  53450. }
  53451. else
  53452. {
  53453. x += indent;
  53454. w -= indent * 2;
  53455. }
  53456. drawTabButtonText (g, x, y, w, h, preferredColour,
  53457. tabIndex, text, button, orientation,
  53458. isMouseOver, isMouseDown, isFrontTab);
  53459. }
  53460. void LookAndFeel::drawTabAreaBehindFrontButton (Graphics& g,
  53461. int w, int h,
  53462. TabbedButtonBar& tabBar,
  53463. TabbedButtonBar::Orientation orientation)
  53464. {
  53465. const float shadowSize = 0.2f;
  53466. float x1 = 0.0f, y1 = 0.0f, x2 = 0.0f, y2 = 0.0f;
  53467. Rectangle<int> shadowRect;
  53468. if (orientation == TabbedButtonBar::TabsAtLeft)
  53469. {
  53470. x1 = (float) w;
  53471. x2 = w * (1.0f - shadowSize);
  53472. shadowRect.setBounds ((int) x2, 0, w - (int) x2, h);
  53473. }
  53474. else if (orientation == TabbedButtonBar::TabsAtRight)
  53475. {
  53476. x2 = w * shadowSize;
  53477. shadowRect.setBounds (0, 0, (int) x2, h);
  53478. }
  53479. else if (orientation == TabbedButtonBar::TabsAtBottom)
  53480. {
  53481. y2 = h * shadowSize;
  53482. shadowRect.setBounds (0, 0, w, (int) y2);
  53483. }
  53484. else
  53485. {
  53486. y1 = (float) h;
  53487. y2 = h * (1.0f - shadowSize);
  53488. shadowRect.setBounds (0, (int) y2, w, h - (int) y2);
  53489. }
  53490. g.setGradientFill (ColourGradient (Colours::black.withAlpha (tabBar.isEnabled() ? 0.3f : 0.15f), x1, y1,
  53491. Colours::transparentBlack, x2, y2, false));
  53492. shadowRect.expand (2, 2);
  53493. g.fillRect (shadowRect);
  53494. g.setColour (Colour (0x80000000));
  53495. if (orientation == TabbedButtonBar::TabsAtLeft)
  53496. {
  53497. g.fillRect (w - 1, 0, 1, h);
  53498. }
  53499. else if (orientation == TabbedButtonBar::TabsAtRight)
  53500. {
  53501. g.fillRect (0, 0, 1, h);
  53502. }
  53503. else if (orientation == TabbedButtonBar::TabsAtBottom)
  53504. {
  53505. g.fillRect (0, 0, w, 1);
  53506. }
  53507. else
  53508. {
  53509. g.fillRect (0, h - 1, w, 1);
  53510. }
  53511. }
  53512. Button* LookAndFeel::createTabBarExtrasButton()
  53513. {
  53514. const float thickness = 7.0f;
  53515. const float indent = 22.0f;
  53516. Path p;
  53517. p.addEllipse (-10.0f, -10.0f, 120.0f, 120.0f);
  53518. DrawablePath ellipse;
  53519. ellipse.setPath (p);
  53520. ellipse.setFill (Colour (0x99ffffff));
  53521. p.clear();
  53522. p.addEllipse (0.0f, 0.0f, 100.0f, 100.0f);
  53523. p.addRectangle (indent, 50.0f - thickness, 100.0f - indent * 2.0f, thickness * 2.0f);
  53524. p.addRectangle (50.0f - thickness, indent, thickness * 2.0f, 50.0f - indent - thickness);
  53525. p.addRectangle (50.0f - thickness, 50.0f + thickness, thickness * 2.0f, 50.0f - indent - thickness);
  53526. p.setUsingNonZeroWinding (false);
  53527. DrawablePath dp;
  53528. dp.setPath (p);
  53529. dp.setFill (Colour (0x59000000));
  53530. DrawableComposite normalImage;
  53531. normalImage.insertDrawable (ellipse);
  53532. normalImage.insertDrawable (dp);
  53533. dp.setFill (Colour (0xcc000000));
  53534. DrawableComposite overImage;
  53535. overImage.insertDrawable (ellipse);
  53536. overImage.insertDrawable (dp);
  53537. DrawableButton* db = new DrawableButton (T("tabs"), DrawableButton::ImageFitted);
  53538. db->setImages (&normalImage, &overImage, 0);
  53539. return db;
  53540. }
  53541. void LookAndFeel::drawTableHeaderBackground (Graphics& g, TableHeaderComponent& header)
  53542. {
  53543. g.fillAll (Colours::white);
  53544. const int w = header.getWidth();
  53545. const int h = header.getHeight();
  53546. g.setGradientFill (ColourGradient (Colour (0xffe8ebf9), 0.0f, h * 0.5f,
  53547. Colour (0xfff6f8f9), 0.0f, h - 1.0f,
  53548. false));
  53549. g.fillRect (0, h / 2, w, h);
  53550. g.setColour (Colour (0x33000000));
  53551. g.fillRect (0, h - 1, w, 1);
  53552. for (int i = header.getNumColumns (true); --i >= 0;)
  53553. g.fillRect (header.getColumnPosition (i).getRight() - 1, 0, 1, h - 1);
  53554. }
  53555. void LookAndFeel::drawTableHeaderColumn (Graphics& g, const String& columnName, int /*columnId*/,
  53556. int width, int height,
  53557. bool isMouseOver, bool isMouseDown,
  53558. int columnFlags)
  53559. {
  53560. if (isMouseDown)
  53561. g.fillAll (Colour (0x8899aadd));
  53562. else if (isMouseOver)
  53563. g.fillAll (Colour (0x5599aadd));
  53564. int rightOfText = width - 4;
  53565. if ((columnFlags & (TableHeaderComponent::sortedForwards | TableHeaderComponent::sortedBackwards)) != 0)
  53566. {
  53567. const float top = height * ((columnFlags & TableHeaderComponent::sortedForwards) != 0 ? 0.35f : (1.0f - 0.35f));
  53568. const float bottom = height - top;
  53569. const float w = height * 0.5f;
  53570. const float x = rightOfText - (w * 1.25f);
  53571. rightOfText = (int) x;
  53572. Path sortArrow;
  53573. sortArrow.addTriangle (x, bottom, x + w * 0.5f, top, x + w, bottom);
  53574. g.setColour (Colour (0x99000000));
  53575. g.fillPath (sortArrow);
  53576. }
  53577. g.setColour (Colours::black);
  53578. g.setFont (height * 0.5f, Font::bold);
  53579. const int textX = 4;
  53580. g.drawFittedText (columnName, textX, 0, rightOfText - textX, height, Justification::centredLeft, 1);
  53581. }
  53582. void LookAndFeel::paintToolbarBackground (Graphics& g, int w, int h, Toolbar& toolbar)
  53583. {
  53584. const Colour background (toolbar.findColour (Toolbar::backgroundColourId));
  53585. g.setGradientFill (ColourGradient (background, 0.0f, 0.0f,
  53586. background.darker (0.1f),
  53587. toolbar.isVertical() ? w - 1.0f : 0.0f,
  53588. toolbar.isVertical() ? 0.0f : h - 1.0f,
  53589. false));
  53590. g.fillAll();
  53591. }
  53592. Button* LookAndFeel::createToolbarMissingItemsButton (Toolbar& /*toolbar*/)
  53593. {
  53594. return createTabBarExtrasButton();
  53595. }
  53596. void LookAndFeel::paintToolbarButtonBackground (Graphics& g, int /*width*/, int /*height*/,
  53597. bool isMouseOver, bool isMouseDown,
  53598. ToolbarItemComponent& component)
  53599. {
  53600. if (isMouseDown)
  53601. g.fillAll (component.findColour (Toolbar::buttonMouseDownBackgroundColourId, true));
  53602. else if (isMouseOver)
  53603. g.fillAll (component.findColour (Toolbar::buttonMouseOverBackgroundColourId, true));
  53604. }
  53605. void LookAndFeel::paintToolbarButtonLabel (Graphics& g, int x, int y, int width, int height,
  53606. const String& text, ToolbarItemComponent& component)
  53607. {
  53608. g.setColour (component.findColour (Toolbar::labelTextColourId, true)
  53609. .withAlpha (component.isEnabled() ? 1.0f : 0.25f));
  53610. const float fontHeight = jmin (14.0f, height * 0.85f);
  53611. g.setFont (fontHeight);
  53612. g.drawFittedText (text,
  53613. x, y, width, height,
  53614. Justification::centred,
  53615. jmax (1, height / (int) fontHeight));
  53616. }
  53617. void LookAndFeel::drawPropertyPanelSectionHeader (Graphics& g, const String& name,
  53618. bool isOpen, int width, int height)
  53619. {
  53620. const int buttonSize = (height * 3) / 4;
  53621. const int buttonIndent = (height - buttonSize) / 2;
  53622. drawTreeviewPlusMinusBox (g, buttonIndent, buttonIndent, buttonSize, buttonSize, ! isOpen, false);
  53623. const int textX = buttonIndent * 2 + buttonSize + 2;
  53624. g.setColour (Colours::black);
  53625. g.setFont (height * 0.7f, Font::bold);
  53626. g.drawText (name, textX, 0, width - textX - 4, height, Justification::centredLeft, true);
  53627. }
  53628. void LookAndFeel::drawPropertyComponentBackground (Graphics& g, int width, int height,
  53629. PropertyComponent&)
  53630. {
  53631. g.setColour (Colour (0x66ffffff));
  53632. g.fillRect (0, 0, width, height - 1);
  53633. }
  53634. void LookAndFeel::drawPropertyComponentLabel (Graphics& g, int, int height,
  53635. PropertyComponent& component)
  53636. {
  53637. g.setColour (Colours::black);
  53638. if (! component.isEnabled())
  53639. g.setOpacity (0.6f);
  53640. g.setFont (jmin (height, 24) * 0.65f);
  53641. const Rectangle<int> r (getPropertyComponentContentPosition (component));
  53642. g.drawFittedText (component.getName(),
  53643. 3, r.getY(), r.getX() - 5, r.getHeight(),
  53644. Justification::centredLeft, 2);
  53645. }
  53646. const Rectangle<int> LookAndFeel::getPropertyComponentContentPosition (PropertyComponent& component)
  53647. {
  53648. return Rectangle<int> (component.getWidth() / 3, 1,
  53649. component.getWidth() - component.getWidth() / 3 - 1, component.getHeight() - 3);
  53650. }
  53651. void LookAndFeel::createFileChooserHeaderText (const String& title,
  53652. const String& instructions,
  53653. GlyphArrangement& text,
  53654. int width)
  53655. {
  53656. text.clear();
  53657. text.addJustifiedText (Font (17.0f, Font::bold), title,
  53658. 8.0f, 22.0f, width - 16.0f,
  53659. Justification::centred);
  53660. text.addJustifiedText (Font (14.0f), instructions,
  53661. 8.0f, 24.0f + 16.0f, width - 16.0f,
  53662. Justification::centred);
  53663. }
  53664. void LookAndFeel::drawFileBrowserRow (Graphics& g, int width, int height,
  53665. const String& filename, Image* icon,
  53666. const String& fileSizeDescription,
  53667. const String& fileTimeDescription,
  53668. const bool isDirectory,
  53669. const bool isItemSelected,
  53670. const int /*itemIndex*/)
  53671. {
  53672. if (isItemSelected)
  53673. g.fillAll (findColour (DirectoryContentsDisplayComponent::highlightColourId));
  53674. g.setColour (findColour (DirectoryContentsDisplayComponent::textColourId));
  53675. g.setFont (height * 0.7f);
  53676. Image* im = icon;
  53677. Image* toRelease = 0;
  53678. if (im == 0)
  53679. {
  53680. toRelease = im = (isDirectory ? getDefaultFolderImage()
  53681. : getDefaultDocumentFileImage());
  53682. }
  53683. const int x = 32;
  53684. if (im != 0)
  53685. {
  53686. g.drawImageWithin (im, 2, 2, x - 4, height - 4,
  53687. RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize,
  53688. false);
  53689. ImageCache::release (toRelease);
  53690. }
  53691. if (width > 450 && ! isDirectory)
  53692. {
  53693. const int sizeX = roundToInt (width * 0.7f);
  53694. const int dateX = roundToInt (width * 0.8f);
  53695. g.drawFittedText (filename,
  53696. x, 0, sizeX - x, height,
  53697. Justification::centredLeft, 1);
  53698. g.setFont (height * 0.5f);
  53699. g.setColour (Colours::darkgrey);
  53700. if (! isDirectory)
  53701. {
  53702. g.drawFittedText (fileSizeDescription,
  53703. sizeX, 0, dateX - sizeX - 8, height,
  53704. Justification::centredRight, 1);
  53705. g.drawFittedText (fileTimeDescription,
  53706. dateX, 0, width - 8 - dateX, height,
  53707. Justification::centredRight, 1);
  53708. }
  53709. }
  53710. else
  53711. {
  53712. g.drawFittedText (filename,
  53713. x, 0, width - x, height,
  53714. Justification::centredLeft, 1);
  53715. }
  53716. }
  53717. Button* LookAndFeel::createFileBrowserGoUpButton()
  53718. {
  53719. DrawableButton* goUpButton = new DrawableButton ("up", DrawableButton::ImageOnButtonBackground);
  53720. Path arrowPath;
  53721. arrowPath.addArrow (50.0f, 100.0f, 50.0f, 0.0f, 40.0f, 100.0f, 50.0f);
  53722. DrawablePath arrowImage;
  53723. arrowImage.setFill (Colours::black.withAlpha (0.4f));
  53724. arrowImage.setPath (arrowPath);
  53725. goUpButton->setImages (&arrowImage);
  53726. return goUpButton;
  53727. }
  53728. void LookAndFeel::layoutFileBrowserComponent (FileBrowserComponent& browserComp,
  53729. DirectoryContentsDisplayComponent* fileListComponent,
  53730. FilePreviewComponent* previewComp,
  53731. ComboBox* currentPathBox,
  53732. TextEditor* filenameBox,
  53733. Button* goUpButton)
  53734. {
  53735. const int x = 8;
  53736. int w = browserComp.getWidth() - x - x;
  53737. if (previewComp != 0)
  53738. {
  53739. const int previewWidth = w / 3;
  53740. previewComp->setBounds (x + w - previewWidth, 0, previewWidth, browserComp.getHeight());
  53741. w -= previewWidth + 4;
  53742. }
  53743. int y = 4;
  53744. const int controlsHeight = 22;
  53745. const int bottomSectionHeight = controlsHeight + 8;
  53746. const int upButtonWidth = 50;
  53747. currentPathBox->setBounds (x, y, w - upButtonWidth - 6, controlsHeight);
  53748. goUpButton->setBounds (x + w - upButtonWidth, y, upButtonWidth, controlsHeight);
  53749. y += controlsHeight + 4;
  53750. Component* const listAsComp = dynamic_cast <Component*> (fileListComponent);
  53751. listAsComp->setBounds (x, y, w, browserComp.getHeight() - y - bottomSectionHeight);
  53752. y = listAsComp->getBottom() + 4;
  53753. filenameBox->setBounds (x + 50, y, w - 50, controlsHeight);
  53754. }
  53755. Image* LookAndFeel::getDefaultFolderImage()
  53756. {
  53757. 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,
  53758. 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,
  53759. 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,
  53760. 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,
  53761. 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,
  53762. 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,
  53763. 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,
  53764. 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,
  53765. 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,
  53766. 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,
  53767. 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,
  53768. 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,
  53769. 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,
  53770. 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,
  53771. 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,
  53772. 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,
  53773. 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,
  53774. 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,
  53775. 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,
  53776. 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,
  53777. 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,
  53778. 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,
  53779. 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,
  53780. 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,
  53781. 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,
  53782. 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,
  53783. 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,
  53784. 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,
  53785. 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,
  53786. 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,
  53787. 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,
  53788. 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,
  53789. 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,
  53790. 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,
  53791. 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,
  53792. 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,
  53793. 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,
  53794. 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,
  53795. 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,
  53796. 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,
  53797. 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,
  53798. 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,
  53799. 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,
  53800. 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};
  53801. return ImageCache::getFromMemory (foldericon_png, sizeof (foldericon_png));
  53802. }
  53803. Image* LookAndFeel::getDefaultDocumentFileImage()
  53804. {
  53805. 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,
  53806. 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,
  53807. 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,
  53808. 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,
  53809. 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,
  53810. 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,
  53811. 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,
  53812. 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,
  53813. 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,
  53814. 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,
  53815. 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,
  53816. 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,
  53817. 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,
  53818. 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,
  53819. 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,
  53820. 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,
  53821. 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,
  53822. 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,
  53823. 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,
  53824. 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,
  53825. 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,
  53826. 174,66,96,130,0,0};
  53827. return ImageCache::getFromMemory (fileicon_png, sizeof (fileicon_png));
  53828. }
  53829. void LookAndFeel::playAlertSound()
  53830. {
  53831. PlatformUtilities::beep();
  53832. }
  53833. void LookAndFeel::drawLevelMeter (Graphics& g, int width, int height, float level)
  53834. {
  53835. g.setColour (Colours::white.withAlpha (0.7f));
  53836. g.fillRoundedRectangle (0.0f, 0.0f, (float) width, (float) height, 3.0f);
  53837. g.setColour (Colours::black.withAlpha (0.2f));
  53838. g.drawRoundedRectangle (1.0f, 1.0f, width - 2.0f, height - 2.0f, 3.0f, 1.0f);
  53839. const int totalBlocks = 7;
  53840. const int numBlocks = roundToInt (totalBlocks * level);
  53841. const float w = (width - 6.0f) / (float) totalBlocks;
  53842. for (int i = 0; i < totalBlocks; ++i)
  53843. {
  53844. if (i >= numBlocks)
  53845. g.setColour (Colours::lightblue.withAlpha (0.6f));
  53846. else
  53847. g.setColour (i < totalBlocks - 1 ? Colours::blue.withAlpha (0.5f)
  53848. : Colours::red);
  53849. g.fillRoundedRectangle (3.0f + i * w + w * 0.1f, 3.0f, w * 0.8f, height - 6.0f, w * 0.4f);
  53850. }
  53851. }
  53852. void LookAndFeel::drawKeymapChangeButton (Graphics& g, int width, int height, Button& button, const String& keyDescription)
  53853. {
  53854. const Colour textColour (button.findColour (KeyMappingEditorComponent::textColourId, true));
  53855. if (keyDescription.isNotEmpty())
  53856. {
  53857. if (button.isEnabled())
  53858. {
  53859. const float alpha = button.isDown() ? 0.3f : (button.isOver() ? 0.15f : 0.08f);
  53860. g.fillAll (textColour.withAlpha (alpha));
  53861. g.setOpacity (0.3f);
  53862. g.drawBevel (0, 0, width, height, 2);
  53863. }
  53864. g.setColour (textColour);
  53865. g.setFont (height * 0.6f);
  53866. g.drawFittedText (keyDescription,
  53867. 3, 0, width - 6, height,
  53868. Justification::centred, 1);
  53869. }
  53870. else
  53871. {
  53872. const float thickness = 7.0f;
  53873. const float indent = 22.0f;
  53874. Path p;
  53875. p.addEllipse (0.0f, 0.0f, 100.0f, 100.0f);
  53876. p.addRectangle (indent, 50.0f - thickness, 100.0f - indent * 2.0f, thickness * 2.0f);
  53877. p.addRectangle (50.0f - thickness, indent, thickness * 2.0f, 50.0f - indent - thickness);
  53878. p.addRectangle (50.0f - thickness, 50.0f + thickness, thickness * 2.0f, 50.0f - indent - thickness);
  53879. p.setUsingNonZeroWinding (false);
  53880. g.setColour (textColour.withAlpha (button.isDown() ? 0.7f : (button.isOver() ? 0.5f : 0.3f)));
  53881. g.fillPath (p, p.getTransformToScaleToFit (2.0f, 2.0f, width - 4.0f, height - 4.0f, true));
  53882. }
  53883. if (button.hasKeyboardFocus (false))
  53884. {
  53885. g.setColour (textColour.withAlpha (0.4f));
  53886. g.drawRect (0, 0, width, height);
  53887. }
  53888. }
  53889. static void createRoundedPath (Path& p,
  53890. const float x, const float y,
  53891. const float w, const float h,
  53892. const float cs,
  53893. const bool curveTopLeft, const bool curveTopRight,
  53894. const bool curveBottomLeft, const bool curveBottomRight) throw()
  53895. {
  53896. const float cs2 = 2.0f * cs;
  53897. if (curveTopLeft)
  53898. {
  53899. p.startNewSubPath (x, y + cs);
  53900. p.addArc (x, y, cs2, cs2, float_Pi * 1.5f, float_Pi * 2.0f);
  53901. }
  53902. else
  53903. {
  53904. p.startNewSubPath (x, y);
  53905. }
  53906. if (curveTopRight)
  53907. {
  53908. p.lineTo (x + w - cs, y);
  53909. p.addArc (x + w - cs2, y, cs2, cs2, 0.0f, float_Pi * 0.5f);
  53910. }
  53911. else
  53912. {
  53913. p.lineTo (x + w, y);
  53914. }
  53915. if (curveBottomRight)
  53916. {
  53917. p.lineTo (x + w, y + h - cs);
  53918. p.addArc (x + w - cs2, y + h - cs2, cs2, cs2, float_Pi * 0.5f, float_Pi);
  53919. }
  53920. else
  53921. {
  53922. p.lineTo (x + w, y + h);
  53923. }
  53924. if (curveBottomLeft)
  53925. {
  53926. p.lineTo (x + cs, y + h);
  53927. p.addArc (x, y + h - cs2, cs2, cs2, float_Pi, float_Pi * 1.5f);
  53928. }
  53929. else
  53930. {
  53931. p.lineTo (x, y + h);
  53932. }
  53933. p.closeSubPath();
  53934. }
  53935. void LookAndFeel::drawShinyButtonShape (Graphics& g,
  53936. float x, float y, float w, float h,
  53937. float maxCornerSize,
  53938. const Colour& baseColour,
  53939. const float strokeWidth,
  53940. const bool flatOnLeft,
  53941. const bool flatOnRight,
  53942. const bool flatOnTop,
  53943. const bool flatOnBottom) throw()
  53944. {
  53945. if (w <= strokeWidth * 1.1f || h <= strokeWidth * 1.1f)
  53946. return;
  53947. const float cs = jmin (maxCornerSize, w * 0.5f, h * 0.5f);
  53948. Path outline;
  53949. createRoundedPath (outline, x, y, w, h, cs,
  53950. ! (flatOnLeft || flatOnTop),
  53951. ! (flatOnRight || flatOnTop),
  53952. ! (flatOnLeft || flatOnBottom),
  53953. ! (flatOnRight || flatOnBottom));
  53954. ColourGradient cg (baseColour, 0.0f, y,
  53955. baseColour.overlaidWith (Colour (0x070000ff)), 0.0f, y + h,
  53956. false);
  53957. cg.addColour (0.5, baseColour.overlaidWith (Colour (0x33ffffff)));
  53958. cg.addColour (0.51, baseColour.overlaidWith (Colour (0x110000ff)));
  53959. g.setGradientFill (cg);
  53960. g.fillPath (outline);
  53961. g.setColour (Colour (0x80000000));
  53962. g.strokePath (outline, PathStrokeType (strokeWidth));
  53963. }
  53964. void LookAndFeel::drawGlassSphere (Graphics& g,
  53965. const float x, const float y,
  53966. const float diameter,
  53967. const Colour& colour,
  53968. const float outlineThickness) throw()
  53969. {
  53970. if (diameter <= outlineThickness)
  53971. return;
  53972. Path p;
  53973. p.addEllipse (x, y, diameter, diameter);
  53974. {
  53975. ColourGradient cg (Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y,
  53976. Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y + diameter, false);
  53977. cg.addColour (0.4, Colours::white.overlaidWith (colour));
  53978. g.setGradientFill (cg);
  53979. g.fillPath (p);
  53980. }
  53981. g.setGradientFill (ColourGradient (Colours::white, 0, y + diameter * 0.06f,
  53982. Colours::transparentWhite, 0, y + diameter * 0.3f, false));
  53983. g.fillEllipse (x + diameter * 0.2f, y + diameter * 0.05f, diameter * 0.6f, diameter * 0.4f);
  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, y + diameter * 0.5f, true);
  53988. cg.addColour (0.7, Colours::transparentBlack);
  53989. cg.addColour (0.8, Colours::black.withAlpha (0.1f * outlineThickness));
  53990. g.setGradientFill (cg);
  53991. g.fillPath (p);
  53992. g.setColour (Colours::black.withAlpha (0.5f * colour.getFloatAlpha()));
  53993. g.drawEllipse (x, y, diameter, diameter, outlineThickness);
  53994. }
  53995. void LookAndFeel::drawGlassPointer (Graphics& g,
  53996. const float x, const float y,
  53997. const float diameter,
  53998. const Colour& colour, const float outlineThickness,
  53999. const int direction) throw()
  54000. {
  54001. if (diameter <= outlineThickness)
  54002. return;
  54003. Path p;
  54004. p.startNewSubPath (x + diameter * 0.5f, y);
  54005. p.lineTo (x + diameter, y + diameter * 0.6f);
  54006. p.lineTo (x + diameter, y + diameter);
  54007. p.lineTo (x, y + diameter);
  54008. p.lineTo (x, y + diameter * 0.6f);
  54009. p.closeSubPath();
  54010. p.applyTransform (AffineTransform::rotation (direction * (float_Pi * 0.5f), x + diameter * 0.5f, y + diameter * 0.5f));
  54011. {
  54012. ColourGradient cg (Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y,
  54013. Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y + diameter, false);
  54014. cg.addColour (0.4, Colours::white.overlaidWith (colour));
  54015. g.setGradientFill (cg);
  54016. g.fillPath (p);
  54017. }
  54018. ColourGradient cg (Colours::transparentBlack,
  54019. x + diameter * 0.5f, y + diameter * 0.5f,
  54020. Colours::black.withAlpha (0.5f * outlineThickness * colour.getFloatAlpha()),
  54021. x - diameter * 0.2f, y + diameter * 0.5f, true);
  54022. cg.addColour (0.5, Colours::transparentBlack);
  54023. cg.addColour (0.7, Colours::black.withAlpha (0.07f * outlineThickness));
  54024. g.setGradientFill (cg);
  54025. g.fillPath (p);
  54026. g.setColour (Colours::black.withAlpha (0.5f * colour.getFloatAlpha()));
  54027. g.strokePath (p, PathStrokeType (outlineThickness));
  54028. }
  54029. void LookAndFeel::drawGlassLozenge (Graphics& g,
  54030. const float x, const float y,
  54031. const float width, const float height,
  54032. const Colour& colour,
  54033. const float outlineThickness,
  54034. const float cornerSize,
  54035. const bool flatOnLeft,
  54036. const bool flatOnRight,
  54037. const bool flatOnTop,
  54038. const bool flatOnBottom) throw()
  54039. {
  54040. if (width <= outlineThickness || height <= outlineThickness)
  54041. return;
  54042. const int intX = (int) x;
  54043. const int intY = (int) y;
  54044. const int intW = (int) width;
  54045. const int intH = (int) height;
  54046. const float cs = cornerSize < 0 ? jmin (width * 0.5f, height * 0.5f) : cornerSize;
  54047. const float edgeBlurRadius = height * 0.75f + (height - cs * 2.0f);
  54048. const int intEdge = (int) edgeBlurRadius;
  54049. Path outline;
  54050. createRoundedPath (outline, x, y, width, height, cs,
  54051. ! (flatOnLeft || flatOnTop),
  54052. ! (flatOnRight || flatOnTop),
  54053. ! (flatOnLeft || flatOnBottom),
  54054. ! (flatOnRight || flatOnBottom));
  54055. {
  54056. ColourGradient cg (colour.darker (0.2f), 0, y,
  54057. colour.darker (0.2f), 0, y + height, false);
  54058. cg.addColour (0.03, colour.withMultipliedAlpha (0.3f));
  54059. cg.addColour (0.4, colour);
  54060. cg.addColour (0.97, colour.withMultipliedAlpha (0.3f));
  54061. g.setGradientFill (cg);
  54062. g.fillPath (outline);
  54063. }
  54064. ColourGradient cg (Colours::transparentBlack, x + edgeBlurRadius, y + height * 0.5f,
  54065. colour.darker (0.2f), x, y + height * 0.5f, true);
  54066. cg.addColour (jlimit (0.0, 1.0, 1.0 - (cs * 0.5f) / edgeBlurRadius), Colours::transparentBlack);
  54067. cg.addColour (jlimit (0.0, 1.0, 1.0 - (cs * 0.25f) / edgeBlurRadius), colour.darker (0.2f).withMultipliedAlpha (0.3f));
  54068. if (! (flatOnLeft || flatOnTop || flatOnBottom))
  54069. {
  54070. g.saveState();
  54071. g.setGradientFill (cg);
  54072. g.reduceClipRegion (intX, intY, intEdge, intH);
  54073. g.fillPath (outline);
  54074. g.restoreState();
  54075. }
  54076. if (! (flatOnRight || flatOnTop || flatOnBottom))
  54077. {
  54078. cg.x1 = x + width - edgeBlurRadius;
  54079. cg.x2 = x + width;
  54080. g.saveState();
  54081. g.setGradientFill (cg);
  54082. g.reduceClipRegion (intX + intW - intEdge, intY, 2 + intEdge, intH);
  54083. g.fillPath (outline);
  54084. g.restoreState();
  54085. }
  54086. {
  54087. const float leftIndent = flatOnLeft ? 0.0f : cs * 0.4f;
  54088. const float rightIndent = flatOnRight ? 0.0f : cs * 0.4f;
  54089. Path highlight;
  54090. createRoundedPath (highlight,
  54091. x + leftIndent,
  54092. y + cs * 0.1f,
  54093. width - (leftIndent + rightIndent),
  54094. height * 0.4f, cs * 0.4f,
  54095. ! (flatOnLeft || flatOnTop),
  54096. ! (flatOnRight || flatOnTop),
  54097. ! (flatOnLeft || flatOnBottom),
  54098. ! (flatOnRight || flatOnBottom));
  54099. g.setGradientFill (ColourGradient (colour.brighter (10.0f), 0, y + height * 0.06f,
  54100. Colours::transparentWhite, 0, y + height * 0.4f, false));
  54101. g.fillPath (highlight);
  54102. }
  54103. g.setColour (colour.darker().withMultipliedAlpha (1.5f));
  54104. g.strokePath (outline, PathStrokeType (outlineThickness));
  54105. }
  54106. END_JUCE_NAMESPACE
  54107. /*** End of inlined file: juce_LookAndFeel.cpp ***/
  54108. /*** Start of inlined file: juce_OldSchoolLookAndFeel.cpp ***/
  54109. BEGIN_JUCE_NAMESPACE
  54110. OldSchoolLookAndFeel::OldSchoolLookAndFeel()
  54111. {
  54112. setColour (TextButton::buttonColourId, Colour (0xffbbbbff));
  54113. setColour (ListBox::outlineColourId, findColour (ComboBox::outlineColourId));
  54114. setColour (ScrollBar::thumbColourId, Colour (0xffbbbbdd));
  54115. setColour (ScrollBar::backgroundColourId, Colours::transparentBlack);
  54116. setColour (Slider::thumbColourId, Colours::white);
  54117. setColour (Slider::trackColourId, Colour (0x7f000000));
  54118. setColour (Slider::textBoxOutlineColourId, Colours::grey);
  54119. setColour (ProgressBar::backgroundColourId, Colours::white.withAlpha (0.6f));
  54120. setColour (ProgressBar::foregroundColourId, Colours::green.withAlpha (0.7f));
  54121. setColour (PopupMenu::backgroundColourId, Colour (0xffeef5f8));
  54122. setColour (PopupMenu::highlightedBackgroundColourId, Colour (0xbfa4c2ce));
  54123. setColour (PopupMenu::highlightedTextColourId, Colours::black);
  54124. setColour (TextEditor::focusedOutlineColourId, findColour (TextButton::buttonColourId));
  54125. scrollbarShadow.setShadowProperties (2.2f, 0.5f, 0, 0);
  54126. }
  54127. OldSchoolLookAndFeel::~OldSchoolLookAndFeel()
  54128. {
  54129. }
  54130. void OldSchoolLookAndFeel::drawButtonBackground (Graphics& g,
  54131. Button& button,
  54132. const Colour& backgroundColour,
  54133. bool isMouseOverButton,
  54134. bool isButtonDown)
  54135. {
  54136. const int width = button.getWidth();
  54137. const int height = button.getHeight();
  54138. const float indent = 2.0f;
  54139. const int cornerSize = jmin (roundToInt (width * 0.4f),
  54140. roundToInt (height * 0.4f));
  54141. Path p;
  54142. p.addRoundedRectangle (indent, indent,
  54143. width - indent * 2.0f,
  54144. height - indent * 2.0f,
  54145. (float) cornerSize);
  54146. Colour bc (backgroundColour.withMultipliedSaturation (0.3f));
  54147. if (isMouseOverButton)
  54148. {
  54149. if (isButtonDown)
  54150. bc = bc.brighter();
  54151. else if (bc.getBrightness() > 0.5f)
  54152. bc = bc.darker (0.1f);
  54153. else
  54154. bc = bc.brighter (0.1f);
  54155. }
  54156. g.setColour (bc);
  54157. g.fillPath (p);
  54158. g.setColour (bc.contrasting().withAlpha ((isMouseOverButton) ? 0.6f : 0.4f));
  54159. g.strokePath (p, PathStrokeType ((isMouseOverButton) ? 2.0f : 1.4f));
  54160. }
  54161. void OldSchoolLookAndFeel::drawTickBox (Graphics& g,
  54162. Component& /*component*/,
  54163. int x, int y, int w, int h,
  54164. const bool ticked,
  54165. const bool isEnabled,
  54166. const bool /*isMouseOverButton*/,
  54167. const bool isButtonDown)
  54168. {
  54169. Path box;
  54170. box.addRoundedRectangle (0.0f, 2.0f, 6.0f, 6.0f, 1.0f);
  54171. g.setColour (isEnabled ? Colours::blue.withAlpha (isButtonDown ? 0.3f : 0.1f)
  54172. : Colours::lightgrey.withAlpha (0.1f));
  54173. AffineTransform trans (AffineTransform::scale (w / 9.0f, h / 9.0f)
  54174. .translated ((float) x, (float) y));
  54175. g.fillPath (box, trans);
  54176. g.setColour (Colours::black.withAlpha (0.6f));
  54177. g.strokePath (box, PathStrokeType (0.9f), trans);
  54178. if (ticked)
  54179. {
  54180. Path tick;
  54181. tick.startNewSubPath (1.5f, 3.0f);
  54182. tick.lineTo (3.0f, 6.0f);
  54183. tick.lineTo (6.0f, 0.0f);
  54184. g.setColour (isEnabled ? Colours::black : Colours::grey);
  54185. g.strokePath (tick, PathStrokeType (2.5f), trans);
  54186. }
  54187. }
  54188. void OldSchoolLookAndFeel::drawToggleButton (Graphics& g,
  54189. ToggleButton& button,
  54190. bool isMouseOverButton,
  54191. bool isButtonDown)
  54192. {
  54193. if (button.hasKeyboardFocus (true))
  54194. {
  54195. g.setColour (button.findColour (TextEditor::focusedOutlineColourId));
  54196. g.drawRect (0, 0, button.getWidth(), button.getHeight());
  54197. }
  54198. const int tickWidth = jmin (20, button.getHeight() - 4);
  54199. drawTickBox (g, button, 4, (button.getHeight() - tickWidth) / 2,
  54200. tickWidth, tickWidth,
  54201. button.getToggleState(),
  54202. button.isEnabled(),
  54203. isMouseOverButton,
  54204. isButtonDown);
  54205. g.setColour (button.findColour (ToggleButton::textColourId));
  54206. g.setFont (jmin (15.0f, button.getHeight() * 0.6f));
  54207. if (! button.isEnabled())
  54208. g.setOpacity (0.5f);
  54209. const int textX = tickWidth + 5;
  54210. g.drawFittedText (button.getButtonText(),
  54211. textX, 4,
  54212. button.getWidth() - textX - 2, button.getHeight() - 8,
  54213. Justification::centredLeft, 10);
  54214. }
  54215. void OldSchoolLookAndFeel::drawProgressBar (Graphics& g, ProgressBar& progressBar,
  54216. int width, int height,
  54217. double progress, const String& textToShow)
  54218. {
  54219. if (progress < 0 || progress >= 1.0)
  54220. {
  54221. LookAndFeel::drawProgressBar (g, progressBar, width, height, progress, textToShow);
  54222. }
  54223. else
  54224. {
  54225. const Colour background (progressBar.findColour (ProgressBar::backgroundColourId));
  54226. const Colour foreground (progressBar.findColour (ProgressBar::foregroundColourId));
  54227. g.fillAll (background);
  54228. g.setColour (foreground);
  54229. g.fillRect (1, 1,
  54230. jlimit (0, width - 2, roundToInt (progress * (width - 2))),
  54231. height - 2);
  54232. if (textToShow.isNotEmpty())
  54233. {
  54234. g.setColour (Colour::contrasting (background, foreground));
  54235. g.setFont (height * 0.6f);
  54236. g.drawText (textToShow, 0, 0, width, height, Justification::centred, false);
  54237. }
  54238. }
  54239. }
  54240. void OldSchoolLookAndFeel::drawScrollbarButton (Graphics& g,
  54241. ScrollBar& bar,
  54242. int width, int height,
  54243. int buttonDirection,
  54244. bool isScrollbarVertical,
  54245. bool isMouseOverButton,
  54246. bool isButtonDown)
  54247. {
  54248. if (isScrollbarVertical)
  54249. width -= 2;
  54250. else
  54251. height -= 2;
  54252. Path p;
  54253. if (buttonDirection == 0)
  54254. p.addTriangle (width * 0.5f, height * 0.2f,
  54255. width * 0.1f, height * 0.7f,
  54256. width * 0.9f, height * 0.7f);
  54257. else if (buttonDirection == 1)
  54258. p.addTriangle (width * 0.8f, height * 0.5f,
  54259. width * 0.3f, height * 0.1f,
  54260. width * 0.3f, height * 0.9f);
  54261. else if (buttonDirection == 2)
  54262. p.addTriangle (width * 0.5f, height * 0.8f,
  54263. width * 0.1f, height * 0.3f,
  54264. width * 0.9f, height * 0.3f);
  54265. else if (buttonDirection == 3)
  54266. p.addTriangle (width * 0.2f, height * 0.5f,
  54267. width * 0.7f, height * 0.1f,
  54268. width * 0.7f, height * 0.9f);
  54269. if (isButtonDown)
  54270. g.setColour (Colours::white);
  54271. else if (isMouseOverButton)
  54272. g.setColour (Colours::white.withAlpha (0.7f));
  54273. else
  54274. g.setColour (bar.findColour (ScrollBar::thumbColourId).withAlpha (0.5f));
  54275. g.fillPath (p);
  54276. g.setColour (Colours::black.withAlpha (0.5f));
  54277. g.strokePath (p, PathStrokeType (0.5f));
  54278. }
  54279. void OldSchoolLookAndFeel::drawScrollbar (Graphics& g,
  54280. ScrollBar& bar,
  54281. int x, int y,
  54282. int width, int height,
  54283. bool isScrollbarVertical,
  54284. int thumbStartPosition,
  54285. int thumbSize,
  54286. bool isMouseOver,
  54287. bool isMouseDown)
  54288. {
  54289. g.fillAll (bar.findColour (ScrollBar::backgroundColourId));
  54290. g.setColour (bar.findColour (ScrollBar::thumbColourId)
  54291. .withAlpha ((isMouseOver || isMouseDown) ? 0.4f : 0.15f));
  54292. if (thumbSize > 0.0f)
  54293. {
  54294. Rectangle<int> thumb;
  54295. if (isScrollbarVertical)
  54296. {
  54297. width -= 2;
  54298. g.fillRect (x + roundToInt (width * 0.35f), y,
  54299. roundToInt (width * 0.3f), height);
  54300. thumb.setBounds (x + 1, thumbStartPosition,
  54301. width - 2, thumbSize);
  54302. }
  54303. else
  54304. {
  54305. height -= 2;
  54306. g.fillRect (x, y + roundToInt (height * 0.35f),
  54307. width, roundToInt (height * 0.3f));
  54308. thumb.setBounds (thumbStartPosition, y + 1,
  54309. thumbSize, height - 2);
  54310. }
  54311. g.setColour (bar.findColour (ScrollBar::thumbColourId)
  54312. .withAlpha ((isMouseOver || isMouseDown) ? 0.95f : 0.7f));
  54313. g.fillRect (thumb);
  54314. g.setColour (Colours::black.withAlpha ((isMouseOver || isMouseDown) ? 0.4f : 0.25f));
  54315. g.drawRect (thumb.getX(), thumb.getY(), thumb.getWidth(), thumb.getHeight());
  54316. if (thumbSize > 16)
  54317. {
  54318. for (int i = 3; --i >= 0;)
  54319. {
  54320. const float linePos = thumbStartPosition + thumbSize / 2 + (i - 1) * 4.0f;
  54321. g.setColour (Colours::black.withAlpha (0.15f));
  54322. if (isScrollbarVertical)
  54323. {
  54324. g.drawLine (x + width * 0.2f, linePos, width * 0.8f, linePos);
  54325. g.setColour (Colours::white.withAlpha (0.15f));
  54326. g.drawLine (width * 0.2f, linePos - 1, width * 0.8f, linePos - 1);
  54327. }
  54328. else
  54329. {
  54330. g.drawLine (linePos, height * 0.2f, linePos, height * 0.8f);
  54331. g.setColour (Colours::white.withAlpha (0.15f));
  54332. g.drawLine (linePos - 1, height * 0.2f, linePos - 1, height * 0.8f);
  54333. }
  54334. }
  54335. }
  54336. }
  54337. }
  54338. ImageEffectFilter* OldSchoolLookAndFeel::getScrollbarEffect()
  54339. {
  54340. return &scrollbarShadow;
  54341. }
  54342. void OldSchoolLookAndFeel::drawPopupMenuBackground (Graphics& g, int width, int height)
  54343. {
  54344. g.fillAll (findColour (PopupMenu::backgroundColourId));
  54345. g.setColour (Colours::black.withAlpha (0.6f));
  54346. g.drawRect (0, 0, width, height);
  54347. }
  54348. void OldSchoolLookAndFeel::drawMenuBarBackground (Graphics& g, int /*width*/, int /*height*/,
  54349. bool, MenuBarComponent& menuBar)
  54350. {
  54351. g.fillAll (menuBar.findColour (PopupMenu::backgroundColourId));
  54352. }
  54353. void OldSchoolLookAndFeel::drawTextEditorOutline (Graphics& g, int width, int height, TextEditor& textEditor)
  54354. {
  54355. if (textEditor.isEnabled())
  54356. {
  54357. g.setColour (textEditor.findColour (TextEditor::outlineColourId));
  54358. g.drawRect (0, 0, width, height);
  54359. }
  54360. }
  54361. void OldSchoolLookAndFeel::drawComboBox (Graphics& g, int width, int height,
  54362. const bool isButtonDown,
  54363. int buttonX, int buttonY,
  54364. int buttonW, int buttonH,
  54365. ComboBox& box)
  54366. {
  54367. g.fillAll (box.findColour (ComboBox::backgroundColourId));
  54368. g.setColour (box.findColour ((isButtonDown) ? ComboBox::buttonColourId
  54369. : ComboBox::backgroundColourId));
  54370. g.fillRect (buttonX, buttonY, buttonW, buttonH);
  54371. g.setColour (box.findColour (ComboBox::outlineColourId));
  54372. g.drawRect (0, 0, width, height);
  54373. const float arrowX = 0.2f;
  54374. const float arrowH = 0.3f;
  54375. if (box.isEnabled())
  54376. {
  54377. Path p;
  54378. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.45f - arrowH),
  54379. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.45f,
  54380. buttonX + buttonW * arrowX, buttonY + buttonH * 0.45f);
  54381. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.55f + arrowH),
  54382. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.55f,
  54383. buttonX + buttonW * arrowX, buttonY + buttonH * 0.55f);
  54384. g.setColour (box.findColour ((isButtonDown) ? ComboBox::backgroundColourId
  54385. : ComboBox::buttonColourId));
  54386. g.fillPath (p);
  54387. }
  54388. }
  54389. const Font OldSchoolLookAndFeel::getComboBoxFont (ComboBox& box)
  54390. {
  54391. Font f (jmin (15.0f, box.getHeight() * 0.85f));
  54392. f.setHorizontalScale (0.9f);
  54393. return f;
  54394. }
  54395. static void drawTriangle (Graphics& g, float x1, float y1, float x2, float y2, float x3, float y3, const Colour& fill, const Colour& outline) throw()
  54396. {
  54397. Path p;
  54398. p.addTriangle (x1, y1, x2, y2, x3, y3);
  54399. g.setColour (fill);
  54400. g.fillPath (p);
  54401. g.setColour (outline);
  54402. g.strokePath (p, PathStrokeType (0.3f));
  54403. }
  54404. void OldSchoolLookAndFeel::drawLinearSlider (Graphics& g,
  54405. int x, int y,
  54406. int w, int h,
  54407. float sliderPos,
  54408. float minSliderPos,
  54409. float maxSliderPos,
  54410. const Slider::SliderStyle style,
  54411. Slider& slider)
  54412. {
  54413. g.fillAll (slider.findColour (Slider::backgroundColourId));
  54414. if (style == Slider::LinearBar)
  54415. {
  54416. g.setColour (slider.findColour (Slider::thumbColourId));
  54417. g.fillRect (x, y, (int) sliderPos - x, h);
  54418. g.setColour (slider.findColour (Slider::textBoxTextColourId).withMultipliedAlpha (0.5f));
  54419. g.drawRect (x, y, (int) sliderPos - x, h);
  54420. }
  54421. else
  54422. {
  54423. g.setColour (slider.findColour (Slider::trackColourId)
  54424. .withMultipliedAlpha (slider.isEnabled() ? 1.0f : 0.3f));
  54425. if (slider.isHorizontal())
  54426. {
  54427. g.fillRect (x, y + roundToInt (h * 0.6f),
  54428. w, roundToInt (h * 0.2f));
  54429. }
  54430. else
  54431. {
  54432. g.fillRect (x + roundToInt (w * 0.5f - jmin (3.0f, w * 0.1f)), y,
  54433. jmin (4, roundToInt (w * 0.2f)), h);
  54434. }
  54435. float alpha = 0.35f;
  54436. if (slider.isEnabled())
  54437. alpha = slider.isMouseOverOrDragging() ? 1.0f : 0.7f;
  54438. const Colour fill (slider.findColour (Slider::thumbColourId).withAlpha (alpha));
  54439. const Colour outline (Colours::black.withAlpha (slider.isEnabled() ? 0.7f : 0.35f));
  54440. if (style == Slider::TwoValueVertical || style == Slider::ThreeValueVertical)
  54441. {
  54442. drawTriangle (g, x + w * 0.5f + jmin (4.0f, w * 0.3f), minSliderPos,
  54443. x + w * 0.5f - jmin (8.0f, w * 0.4f), minSliderPos - 7.0f,
  54444. x + w * 0.5f - jmin (8.0f, w * 0.4f), minSliderPos,
  54445. fill, outline);
  54446. drawTriangle (g, x + w * 0.5f + jmin (4.0f, w * 0.3f), maxSliderPos,
  54447. x + w * 0.5f - jmin (8.0f, w * 0.4f), maxSliderPos,
  54448. x + w * 0.5f - jmin (8.0f, w * 0.4f), maxSliderPos + 7.0f,
  54449. fill, outline);
  54450. }
  54451. else if (style == Slider::TwoValueHorizontal || style == Slider::ThreeValueHorizontal)
  54452. {
  54453. drawTriangle (g, minSliderPos, y + h * 0.6f - jmin (4.0f, h * 0.3f),
  54454. minSliderPos - 7.0f, y + h * 0.9f ,
  54455. minSliderPos, y + h * 0.9f,
  54456. fill, outline);
  54457. drawTriangle (g, maxSliderPos, y + h * 0.6f - jmin (4.0f, h * 0.3f),
  54458. maxSliderPos, y + h * 0.9f,
  54459. maxSliderPos + 7.0f, y + h * 0.9f,
  54460. fill, outline);
  54461. }
  54462. if (style == Slider::LinearHorizontal || style == Slider::ThreeValueHorizontal)
  54463. {
  54464. drawTriangle (g, sliderPos, y + h * 0.9f,
  54465. sliderPos - 7.0f, y + h * 0.2f,
  54466. sliderPos + 7.0f, y + h * 0.2f,
  54467. fill, outline);
  54468. }
  54469. else if (style == Slider::LinearVertical || style == Slider::ThreeValueVertical)
  54470. {
  54471. drawTriangle (g, x + w * 0.5f - jmin (4.0f, w * 0.3f), sliderPos,
  54472. x + w * 0.5f + jmin (8.0f, w * 0.4f), sliderPos - 7.0f,
  54473. x + w * 0.5f + jmin (8.0f, w * 0.4f), sliderPos + 7.0f,
  54474. fill, outline);
  54475. }
  54476. }
  54477. }
  54478. Button* OldSchoolLookAndFeel::createSliderButton (const bool isIncrement)
  54479. {
  54480. if (isIncrement)
  54481. return new ArrowButton ("u", 0.75f, Colours::white.withAlpha (0.8f));
  54482. else
  54483. return new ArrowButton ("d", 0.25f, Colours::white.withAlpha (0.8f));
  54484. }
  54485. ImageEffectFilter* OldSchoolLookAndFeel::getSliderEffect()
  54486. {
  54487. return &scrollbarShadow;
  54488. }
  54489. int OldSchoolLookAndFeel::getSliderThumbRadius (Slider&)
  54490. {
  54491. return 8;
  54492. }
  54493. void OldSchoolLookAndFeel::drawCornerResizer (Graphics& g,
  54494. int w, int h,
  54495. bool isMouseOver,
  54496. bool isMouseDragging)
  54497. {
  54498. g.setColour ((isMouseOver || isMouseDragging) ? Colours::lightgrey
  54499. : Colours::darkgrey);
  54500. const float lineThickness = jmin (w, h) * 0.1f;
  54501. for (float i = 0.0f; i < 1.0f; i += 0.3f)
  54502. {
  54503. g.drawLine (w * i,
  54504. h + 1.0f,
  54505. w + 1.0f,
  54506. h * i,
  54507. lineThickness);
  54508. }
  54509. }
  54510. Button* OldSchoolLookAndFeel::createDocumentWindowButton (int buttonType)
  54511. {
  54512. Path shape;
  54513. if (buttonType == DocumentWindow::closeButton)
  54514. {
  54515. shape.addLineSegment (0.0f, 0.0f, 1.0f, 1.0f, 0.35f);
  54516. shape.addLineSegment (1.0f, 0.0f, 0.0f, 1.0f, 0.35f);
  54517. ShapeButton* const b = new ShapeButton ("close",
  54518. Colour (0x7fff3333),
  54519. Colour (0xd7ff3333),
  54520. Colour (0xf7ff3333));
  54521. b->setShape (shape, true, true, true);
  54522. return b;
  54523. }
  54524. else if (buttonType == DocumentWindow::minimiseButton)
  54525. {
  54526. shape.addLineSegment (0.0f, 0.5f, 1.0f, 0.5f, 0.25f);
  54527. DrawableButton* b = new DrawableButton ("minimise", DrawableButton::ImageFitted);
  54528. DrawablePath dp;
  54529. dp.setPath (shape);
  54530. dp.setFill (Colours::black.withAlpha (0.3f));
  54531. b->setImages (&dp);
  54532. return b;
  54533. }
  54534. else if (buttonType == DocumentWindow::maximiseButton)
  54535. {
  54536. shape.addLineSegment (0.5f, 0.0f, 0.5f, 1.0f, 0.25f);
  54537. shape.addLineSegment (0.0f, 0.5f, 1.0f, 0.5f, 0.25f);
  54538. DrawableButton* b = new DrawableButton ("maximise", DrawableButton::ImageFitted);
  54539. DrawablePath dp;
  54540. dp.setPath (shape);
  54541. dp.setFill (Colours::black.withAlpha (0.3f));
  54542. b->setImages (&dp);
  54543. return b;
  54544. }
  54545. jassertfalse
  54546. return 0;
  54547. }
  54548. void OldSchoolLookAndFeel::positionDocumentWindowButtons (DocumentWindow&,
  54549. int titleBarX,
  54550. int titleBarY,
  54551. int titleBarW,
  54552. int titleBarH,
  54553. Button* minimiseButton,
  54554. Button* maximiseButton,
  54555. Button* closeButton,
  54556. bool positionTitleBarButtonsOnLeft)
  54557. {
  54558. titleBarY += titleBarH / 8;
  54559. titleBarH -= titleBarH / 4;
  54560. const int buttonW = titleBarH;
  54561. int x = positionTitleBarButtonsOnLeft ? titleBarX + 4
  54562. : titleBarX + titleBarW - buttonW - 4;
  54563. if (closeButton != 0)
  54564. {
  54565. closeButton->setBounds (x, titleBarY, buttonW, titleBarH);
  54566. x += positionTitleBarButtonsOnLeft ? buttonW + buttonW / 5
  54567. : -(buttonW + buttonW / 5);
  54568. }
  54569. if (positionTitleBarButtonsOnLeft)
  54570. swapVariables (minimiseButton, maximiseButton);
  54571. if (maximiseButton != 0)
  54572. {
  54573. maximiseButton->setBounds (x, titleBarY - 2, buttonW, titleBarH);
  54574. x += positionTitleBarButtonsOnLeft ? buttonW : -buttonW;
  54575. }
  54576. if (minimiseButton != 0)
  54577. minimiseButton->setBounds (x, titleBarY - 2, buttonW, titleBarH);
  54578. }
  54579. END_JUCE_NAMESPACE
  54580. /*** End of inlined file: juce_OldSchoolLookAndFeel.cpp ***/
  54581. /*** Start of inlined file: juce_MenuBarComponent.cpp ***/
  54582. BEGIN_JUCE_NAMESPACE
  54583. class DummyMenuComponent : public Component
  54584. {
  54585. DummyMenuComponent (const DummyMenuComponent&);
  54586. const DummyMenuComponent& operator= (const DummyMenuComponent&);
  54587. public:
  54588. DummyMenuComponent() {}
  54589. ~DummyMenuComponent() {}
  54590. void inputAttemptWhenModal()
  54591. {
  54592. exitModalState (0);
  54593. }
  54594. };
  54595. MenuBarComponent::MenuBarComponent (MenuBarModel* model_)
  54596. : model (0),
  54597. itemUnderMouse (-1),
  54598. currentPopupIndex (-1),
  54599. indexToShowAgain (-1),
  54600. lastMouseX (0),
  54601. lastMouseY (0),
  54602. inModalState (false)
  54603. {
  54604. setRepaintsOnMouseActivity (true);
  54605. setWantsKeyboardFocus (false);
  54606. setMouseClickGrabsKeyboardFocus (false);
  54607. setModel (model_);
  54608. }
  54609. MenuBarComponent::~MenuBarComponent()
  54610. {
  54611. setModel (0);
  54612. Desktop::getInstance().removeGlobalMouseListener (this);
  54613. currentPopup = 0;
  54614. }
  54615. void MenuBarComponent::setModel (MenuBarModel* const newModel)
  54616. {
  54617. if (model != newModel)
  54618. {
  54619. if (model != 0)
  54620. model->removeListener (this);
  54621. model = newModel;
  54622. if (model != 0)
  54623. model->addListener (this);
  54624. repaint();
  54625. menuBarItemsChanged (0);
  54626. }
  54627. }
  54628. void MenuBarComponent::paint (Graphics& g)
  54629. {
  54630. const bool isMouseOverBar = currentPopupIndex >= 0 || itemUnderMouse >= 0 || isMouseOver();
  54631. getLookAndFeel().drawMenuBarBackground (g,
  54632. getWidth(),
  54633. getHeight(),
  54634. isMouseOverBar,
  54635. *this);
  54636. if (model != 0)
  54637. {
  54638. for (int i = 0; i < menuNames.size(); ++i)
  54639. {
  54640. g.saveState();
  54641. g.setOrigin (xPositions [i], 0);
  54642. g.reduceClipRegion (0, 0, xPositions[i + 1] - xPositions[i], getHeight());
  54643. getLookAndFeel().drawMenuBarItem (g,
  54644. xPositions[i + 1] - xPositions[i],
  54645. getHeight(),
  54646. i,
  54647. menuNames[i],
  54648. i == itemUnderMouse,
  54649. i == currentPopupIndex,
  54650. isMouseOverBar,
  54651. *this);
  54652. g.restoreState();
  54653. }
  54654. }
  54655. }
  54656. void MenuBarComponent::resized()
  54657. {
  54658. xPositions.clear();
  54659. int x = 2;
  54660. xPositions.add (x);
  54661. for (int i = 0; i < menuNames.size(); ++i)
  54662. {
  54663. x += getLookAndFeel().getMenuBarItemWidth (*this, i, menuNames[i]);
  54664. xPositions.add (x);
  54665. }
  54666. }
  54667. int MenuBarComponent::getItemAt (const int x, const int y)
  54668. {
  54669. for (int i = 0; i < xPositions.size(); ++i)
  54670. if (x >= xPositions[i] && x < xPositions[i + 1])
  54671. return reallyContains (x, y, true) ? i : -1;
  54672. return -1;
  54673. }
  54674. void MenuBarComponent::repaintMenuItem (int index)
  54675. {
  54676. if (((unsigned int) index) < (unsigned int) xPositions.size())
  54677. {
  54678. const int x1 = xPositions [index];
  54679. const int x2 = xPositions [index + 1];
  54680. repaint (x1 - 2, 0, x2 - x1 + 4, getHeight());
  54681. }
  54682. }
  54683. void MenuBarComponent::updateItemUnderMouse (int x, int y)
  54684. {
  54685. const int newItem = getItemAt (x, y);
  54686. if (itemUnderMouse != newItem)
  54687. {
  54688. repaintMenuItem (itemUnderMouse);
  54689. itemUnderMouse = newItem;
  54690. repaintMenuItem (itemUnderMouse);
  54691. }
  54692. }
  54693. void MenuBarComponent::hideCurrentMenu()
  54694. {
  54695. currentPopup = 0;
  54696. repaint();
  54697. }
  54698. void MenuBarComponent::showMenu (int index)
  54699. {
  54700. if (index != currentPopupIndex)
  54701. {
  54702. if (inModalState)
  54703. {
  54704. hideCurrentMenu();
  54705. indexToShowAgain = index;
  54706. return;
  54707. }
  54708. indexToShowAgain = -1;
  54709. currentPopupIndex = -1;
  54710. itemUnderMouse = index;
  54711. currentPopup = 0;
  54712. menuBarItemsChanged (0);
  54713. Component* const prevFocused = getCurrentlyFocusedComponent();
  54714. ScopedPointer <ComponentDeletionWatcher> prevCompDeletionChecker;
  54715. if (prevFocused != 0)
  54716. prevCompDeletionChecker = new ComponentDeletionWatcher (prevFocused);
  54717. ComponentDeletionWatcher deletionChecker (this);
  54718. enterModalState (false);
  54719. inModalState = true;
  54720. int result = 0;
  54721. ApplicationCommandManager* managerOfChosenCommand = 0;
  54722. Desktop::getInstance().addGlobalMouseListener (this);
  54723. for (;;)
  54724. {
  54725. const int x = getScreenX() + xPositions [itemUnderMouse];
  54726. const int w = xPositions [itemUnderMouse + 1] - xPositions [itemUnderMouse];
  54727. currentPopupIndex = itemUnderMouse;
  54728. indexToShowAgain = -1;
  54729. repaint();
  54730. if (((unsigned int) itemUnderMouse) < (unsigned int) menuNames.size())
  54731. {
  54732. PopupMenu m (model->getMenuForIndex (itemUnderMouse,
  54733. menuNames [itemUnderMouse]));
  54734. if (m.lookAndFeel == 0)
  54735. m.setLookAndFeel (&getLookAndFeel());
  54736. currentPopup = m.createMenuComponent (x, getScreenY(),
  54737. w, getHeight(),
  54738. 0, w, 0, 0,
  54739. true, this,
  54740. &managerOfChosenCommand,
  54741. this);
  54742. }
  54743. if (currentPopup == 0)
  54744. {
  54745. currentPopup = new DummyMenuComponent();
  54746. addAndMakeVisible (currentPopup);
  54747. }
  54748. currentPopup->enterModalState (false);
  54749. currentPopup->toFront (false); // need to do this after making it modal, or it could
  54750. // be stuck behind other comps that are already modal..
  54751. result = currentPopup->runModalLoop();
  54752. if (deletionChecker.hasBeenDeleted())
  54753. return;
  54754. const int lastPopupIndex = currentPopupIndex;
  54755. currentPopup = 0;
  54756. currentPopupIndex = -1;
  54757. if (result != 0)
  54758. {
  54759. topLevelIndexClicked = lastPopupIndex;
  54760. break;
  54761. }
  54762. else if (indexToShowAgain >= 0)
  54763. {
  54764. menuBarItemsChanged (0);
  54765. repaint();
  54766. itemUnderMouse = indexToShowAgain;
  54767. if (((unsigned int) itemUnderMouse) >= (unsigned int) menuNames.size())
  54768. break;
  54769. }
  54770. else
  54771. {
  54772. break;
  54773. }
  54774. }
  54775. Desktop::getInstance().removeGlobalMouseListener (this);
  54776. inModalState = false;
  54777. exitModalState (0);
  54778. if (prevCompDeletionChecker != 0 && ! prevCompDeletionChecker->hasBeenDeleted())
  54779. prevFocused->grabKeyboardFocus();
  54780. int mx, my;
  54781. getMouseXYRelative (mx, my);
  54782. updateItemUnderMouse (mx, my);
  54783. repaint();
  54784. if (result != 0)
  54785. {
  54786. if (managerOfChosenCommand != 0)
  54787. {
  54788. ApplicationCommandTarget::InvocationInfo info (result);
  54789. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromMenu;
  54790. managerOfChosenCommand->invoke (info, true);
  54791. }
  54792. postCommandMessage (result);
  54793. }
  54794. }
  54795. }
  54796. void MenuBarComponent::handleCommandMessage (int commandId)
  54797. {
  54798. if (model != 0)
  54799. model->menuItemSelected (commandId, topLevelIndexClicked);
  54800. }
  54801. void MenuBarComponent::mouseEnter (const MouseEvent& e)
  54802. {
  54803. if (e.eventComponent == this)
  54804. updateItemUnderMouse (e.x, e.y);
  54805. }
  54806. void MenuBarComponent::mouseExit (const MouseEvent& e)
  54807. {
  54808. if (e.eventComponent == this)
  54809. updateItemUnderMouse (e.x, e.y);
  54810. }
  54811. void MenuBarComponent::mouseDown (const MouseEvent& e)
  54812. {
  54813. const MouseEvent e2 (e.getEventRelativeTo (this));
  54814. if (currentPopupIndex < 0)
  54815. {
  54816. updateItemUnderMouse (e2.x, e2.y);
  54817. currentPopupIndex = -2;
  54818. showMenu (itemUnderMouse);
  54819. }
  54820. }
  54821. void MenuBarComponent::mouseDrag (const MouseEvent& e)
  54822. {
  54823. const MouseEvent e2 (e.getEventRelativeTo (this));
  54824. const int item = getItemAt (e2.x, e2.y);
  54825. if (item >= 0)
  54826. showMenu (item);
  54827. }
  54828. void MenuBarComponent::mouseUp (const MouseEvent& e)
  54829. {
  54830. const MouseEvent e2 (e.getEventRelativeTo (this));
  54831. updateItemUnderMouse (e2.x, e2.y);
  54832. if (itemUnderMouse < 0 && dynamic_cast <DummyMenuComponent*> ((Component*) currentPopup) != 0)
  54833. hideCurrentMenu();
  54834. }
  54835. void MenuBarComponent::mouseMove (const MouseEvent& e)
  54836. {
  54837. const MouseEvent e2 (e.getEventRelativeTo (this));
  54838. if (lastMouseX != e2.x || lastMouseY != e2.y)
  54839. {
  54840. if (currentPopupIndex >= 0)
  54841. {
  54842. const int item = getItemAt (e2.x, e2.y);
  54843. if (item >= 0)
  54844. showMenu (item);
  54845. }
  54846. else
  54847. {
  54848. updateItemUnderMouse (e2.x, e2.y);
  54849. }
  54850. lastMouseX = e2.x;
  54851. lastMouseY = e2.y;
  54852. }
  54853. }
  54854. bool MenuBarComponent::keyPressed (const KeyPress& key)
  54855. {
  54856. bool used = false;
  54857. const int numMenus = menuNames.size();
  54858. const int currentIndex = jlimit (0, menuNames.size() - 1, currentPopupIndex);
  54859. if (key.isKeyCode (KeyPress::leftKey))
  54860. {
  54861. showMenu ((currentIndex + numMenus - 1) % numMenus);
  54862. used = true;
  54863. }
  54864. else if (key.isKeyCode (KeyPress::rightKey))
  54865. {
  54866. showMenu ((currentIndex + 1) % numMenus);
  54867. used = true;
  54868. }
  54869. return used;
  54870. }
  54871. void MenuBarComponent::inputAttemptWhenModal()
  54872. {
  54873. hideCurrentMenu();
  54874. }
  54875. void MenuBarComponent::menuBarItemsChanged (MenuBarModel* /*menuBarModel*/)
  54876. {
  54877. StringArray newNames;
  54878. if (model != 0)
  54879. newNames = model->getMenuBarNames();
  54880. if (newNames != menuNames)
  54881. {
  54882. menuNames = newNames;
  54883. repaint();
  54884. resized();
  54885. }
  54886. }
  54887. void MenuBarComponent::menuCommandInvoked (MenuBarModel* /*menuBarModel*/,
  54888. const ApplicationCommandTarget::InvocationInfo& info)
  54889. {
  54890. if (model == 0
  54891. || (info.commandFlags & ApplicationCommandInfo::dontTriggerVisualFeedback) != 0)
  54892. return;
  54893. for (int i = 0; i < menuNames.size(); ++i)
  54894. {
  54895. const PopupMenu menu (model->getMenuForIndex (i, menuNames [i]));
  54896. if (menu.containsCommandItem (info.commandID))
  54897. {
  54898. itemUnderMouse = i;
  54899. repaintMenuItem (i);
  54900. startTimer (200);
  54901. break;
  54902. }
  54903. }
  54904. }
  54905. void MenuBarComponent::timerCallback()
  54906. {
  54907. stopTimer();
  54908. int mx, my;
  54909. getMouseXYRelative (mx, my);
  54910. updateItemUnderMouse (mx, my);
  54911. }
  54912. END_JUCE_NAMESPACE
  54913. /*** End of inlined file: juce_MenuBarComponent.cpp ***/
  54914. /*** Start of inlined file: juce_MenuBarModel.cpp ***/
  54915. BEGIN_JUCE_NAMESPACE
  54916. MenuBarModel::MenuBarModel() throw()
  54917. : manager (0)
  54918. {
  54919. }
  54920. MenuBarModel::~MenuBarModel()
  54921. {
  54922. setApplicationCommandManagerToWatch (0);
  54923. }
  54924. void MenuBarModel::menuItemsChanged()
  54925. {
  54926. triggerAsyncUpdate();
  54927. }
  54928. void MenuBarModel::setApplicationCommandManagerToWatch (ApplicationCommandManager* const newManager) throw()
  54929. {
  54930. if (manager != newManager)
  54931. {
  54932. if (manager != 0)
  54933. manager->removeListener (this);
  54934. manager = newManager;
  54935. if (manager != 0)
  54936. manager->addListener (this);
  54937. }
  54938. }
  54939. void MenuBarModel::addListener (MenuBarModelListener* const newListener) throw()
  54940. {
  54941. jassert (newListener != 0);
  54942. jassert (! listeners.contains (newListener)); // trying to add a listener to the list twice!
  54943. if (newListener != 0)
  54944. listeners.add (newListener);
  54945. }
  54946. void MenuBarModel::removeListener (MenuBarModelListener* const listenerToRemove) throw()
  54947. {
  54948. // Trying to remove a listener that isn't on the list!
  54949. // If this assertion happens because this object is a dangling pointer, make sure you've not
  54950. // deleted this menu model while it's still being used by something (e.g. by a MenuBarComponent)
  54951. jassert (listeners.contains (listenerToRemove));
  54952. listeners.removeValue (listenerToRemove);
  54953. }
  54954. void MenuBarModel::handleAsyncUpdate()
  54955. {
  54956. for (int i = listeners.size(); --i >= 0;)
  54957. {
  54958. ((MenuBarModelListener*) listeners.getUnchecked (i))->menuBarItemsChanged (this);
  54959. i = jmin (i, listeners.size());
  54960. }
  54961. }
  54962. void MenuBarModel::applicationCommandInvoked (const ApplicationCommandTarget::InvocationInfo& info)
  54963. {
  54964. for (int i = listeners.size(); --i >= 0;)
  54965. {
  54966. ((MenuBarModelListener*) listeners.getUnchecked (i))->menuCommandInvoked (this, info);
  54967. i = jmin (i, listeners.size());
  54968. }
  54969. }
  54970. void MenuBarModel::applicationCommandListChanged()
  54971. {
  54972. menuItemsChanged();
  54973. }
  54974. END_JUCE_NAMESPACE
  54975. /*** End of inlined file: juce_MenuBarModel.cpp ***/
  54976. /*** Start of inlined file: juce_PopupMenu.cpp ***/
  54977. BEGIN_JUCE_NAMESPACE
  54978. class PopupMenu::Item
  54979. {
  54980. public:
  54981. Item()
  54982. : itemId (0), active (true), isSeparator (true), isTicked (false),
  54983. usesColour (false), customComp (0), commandManager (0)
  54984. {
  54985. }
  54986. Item (const int itemId_,
  54987. const String& text_,
  54988. const bool active_,
  54989. const bool isTicked_,
  54990. const Image* im,
  54991. const Colour& textColour_,
  54992. const bool usesColour_,
  54993. PopupMenuCustomComponent* const customComp_,
  54994. const PopupMenu* const subMenu_,
  54995. ApplicationCommandManager* const commandManager_)
  54996. : itemId (itemId_), text (text_), textColour (textColour_),
  54997. active (active_), isSeparator (false), isTicked (isTicked_),
  54998. usesColour (usesColour_), customComp (customComp_),
  54999. commandManager (commandManager_)
  55000. {
  55001. if (subMenu_ != 0)
  55002. subMenu = new PopupMenu (*subMenu_);
  55003. if (im != 0)
  55004. image = im->createCopy();
  55005. if (commandManager_ != 0 && itemId_ != 0)
  55006. {
  55007. String shortcutKey;
  55008. Array <KeyPress> keyPresses (commandManager_->getKeyMappings()
  55009. ->getKeyPressesAssignedToCommand (itemId_));
  55010. for (int i = 0; i < keyPresses.size(); ++i)
  55011. {
  55012. const String key (keyPresses.getReference(i).getTextDescription());
  55013. if (shortcutKey.isNotEmpty())
  55014. shortcutKey << ", ";
  55015. if (key.length() == 1)
  55016. shortcutKey << "shortcut: '" << key << '\'';
  55017. else
  55018. shortcutKey << key;
  55019. }
  55020. shortcutKey = shortcutKey.trim();
  55021. if (shortcutKey.isNotEmpty())
  55022. text << "<end>" << shortcutKey;
  55023. }
  55024. }
  55025. Item (const Item& other)
  55026. : itemId (other.itemId),
  55027. text (other.text),
  55028. textColour (other.textColour),
  55029. active (other.active),
  55030. isSeparator (other.isSeparator),
  55031. isTicked (other.isTicked),
  55032. usesColour (other.usesColour),
  55033. customComp (other.customComp),
  55034. commandManager (other.commandManager)
  55035. {
  55036. if (other.subMenu != 0)
  55037. subMenu = new PopupMenu (*(other.subMenu));
  55038. if (other.image != 0)
  55039. image = other.image->createCopy();
  55040. }
  55041. ~Item()
  55042. {
  55043. customComp = 0;
  55044. }
  55045. bool canBeTriggered() const throw()
  55046. {
  55047. return active && ! (isSeparator || (subMenu != 0));
  55048. }
  55049. bool hasActiveSubMenu() const throw()
  55050. {
  55051. return active && (subMenu != 0);
  55052. }
  55053. const int itemId;
  55054. String text;
  55055. const Colour textColour;
  55056. const bool active, isSeparator, isTicked, usesColour;
  55057. ScopedPointer <Image> image;
  55058. ReferenceCountedObjectPtr <PopupMenuCustomComponent> customComp;
  55059. ScopedPointer <PopupMenu> subMenu;
  55060. ApplicationCommandManager* const commandManager;
  55061. juce_UseDebuggingNewOperator
  55062. private:
  55063. Item& operator= (const Item&);
  55064. };
  55065. class PopupMenu::ItemComponent : public Component
  55066. {
  55067. public:
  55068. ItemComponent (const PopupMenu::Item& itemInfo_)
  55069. : itemInfo (itemInfo_),
  55070. isHighlighted (false)
  55071. {
  55072. if (itemInfo.customComp != 0)
  55073. addAndMakeVisible (itemInfo.customComp);
  55074. }
  55075. ~ItemComponent()
  55076. {
  55077. if (itemInfo.customComp != 0)
  55078. removeChildComponent (itemInfo.customComp);
  55079. }
  55080. void getIdealSize (int& idealWidth,
  55081. int& idealHeight,
  55082. const int standardItemHeight)
  55083. {
  55084. if (itemInfo.customComp != 0)
  55085. {
  55086. itemInfo.customComp->getIdealSize (idealWidth, idealHeight);
  55087. }
  55088. else
  55089. {
  55090. getLookAndFeel().getIdealPopupMenuItemSize (itemInfo.text,
  55091. itemInfo.isSeparator,
  55092. standardItemHeight,
  55093. idealWidth,
  55094. idealHeight);
  55095. }
  55096. }
  55097. void paint (Graphics& g)
  55098. {
  55099. if (itemInfo.customComp == 0)
  55100. {
  55101. String mainText (itemInfo.text);
  55102. String endText;
  55103. const int endIndex = mainText.indexOf (T("<end>"));
  55104. if (endIndex >= 0)
  55105. {
  55106. endText = mainText.substring (endIndex + 5).trim();
  55107. mainText = mainText.substring (0, endIndex);
  55108. }
  55109. getLookAndFeel()
  55110. .drawPopupMenuItem (g, getWidth(), getHeight(),
  55111. itemInfo.isSeparator,
  55112. itemInfo.active,
  55113. isHighlighted,
  55114. itemInfo.isTicked,
  55115. itemInfo.subMenu != 0,
  55116. mainText, endText,
  55117. itemInfo.image,
  55118. itemInfo.usesColour ? &(itemInfo.textColour) : 0);
  55119. }
  55120. }
  55121. void resized()
  55122. {
  55123. if (getNumChildComponents() > 0)
  55124. getChildComponent(0)->setBounds (2, 0, getWidth() - 4, getHeight());
  55125. }
  55126. void setHighlighted (bool shouldBeHighlighted)
  55127. {
  55128. shouldBeHighlighted = shouldBeHighlighted && itemInfo.active;
  55129. if (isHighlighted != shouldBeHighlighted)
  55130. {
  55131. isHighlighted = shouldBeHighlighted;
  55132. if (itemInfo.customComp != 0)
  55133. {
  55134. itemInfo.customComp->isHighlighted = shouldBeHighlighted;
  55135. itemInfo.customComp->repaint();
  55136. }
  55137. repaint();
  55138. }
  55139. }
  55140. PopupMenu::Item itemInfo;
  55141. juce_UseDebuggingNewOperator
  55142. private:
  55143. bool isHighlighted;
  55144. ItemComponent (const ItemComponent&);
  55145. ItemComponent& operator= (const ItemComponent&);
  55146. };
  55147. namespace PopupMenuSettings
  55148. {
  55149. static const int scrollZone = 24;
  55150. static const int borderSize = 2;
  55151. static const int timerInterval = 50;
  55152. static const int dismissCommandId = 0x6287345f;
  55153. }
  55154. class PopupMenu::Window : public Component,
  55155. private Timer
  55156. {
  55157. public:
  55158. Window()
  55159. : Component (T("menu")),
  55160. owner (0),
  55161. currentChild (0),
  55162. activeSubMenu (0),
  55163. menuBarComponent (0),
  55164. managerOfChosenCommand (0),
  55165. componentAttachedTo (0),
  55166. lastMouseX (0),
  55167. lastMouseY (0),
  55168. minimumWidth (0),
  55169. maximumNumColumns (7),
  55170. standardItemHeight (0),
  55171. isOver (false),
  55172. hasBeenOver (false),
  55173. isDown (false),
  55174. needsToScroll (false),
  55175. hideOnExit (false),
  55176. disableMouseMoves (false),
  55177. hasAnyJuceCompHadFocus (false),
  55178. numColumns (0),
  55179. contentHeight (0),
  55180. childYOffset (0),
  55181. timeEnteredCurrentChildComp (0),
  55182. scrollAcceleration (1.0)
  55183. {
  55184. menuCreationTime = lastFocused = lastScroll = Time::getMillisecondCounter();
  55185. setWantsKeyboardFocus (true);
  55186. setMouseClickGrabsKeyboardFocus (false);
  55187. setOpaque (true);
  55188. setAlwaysOnTop (true);
  55189. Desktop::getInstance().addGlobalMouseListener (this);
  55190. getActiveWindows().add (this);
  55191. }
  55192. ~Window()
  55193. {
  55194. getActiveWindows().removeValue (this);
  55195. Desktop::getInstance().removeGlobalMouseListener (this);
  55196. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  55197. activeSubMenu = 0;
  55198. deleteAllChildren();
  55199. attachedCompWatcher = 0;
  55200. }
  55201. static Window* create (const PopupMenu& menu,
  55202. const bool dismissOnMouseUp,
  55203. Window* const owner_,
  55204. const int minX, const int maxX,
  55205. const int minY, const int maxY,
  55206. const int minimumWidth,
  55207. const int maximumNumColumns,
  55208. const int standardItemHeight,
  55209. const bool alignToRectangle,
  55210. const int itemIdThatMustBeVisible,
  55211. Component* const menuBarComponent,
  55212. ApplicationCommandManager** managerOfChosenCommand,
  55213. Component* const componentAttachedTo)
  55214. {
  55215. if (menu.items.size() > 0)
  55216. {
  55217. int totalItems = 0;
  55218. ScopedPointer <Window> mw (new Window());
  55219. mw->setLookAndFeel (menu.lookAndFeel);
  55220. mw->setWantsKeyboardFocus (false);
  55221. mw->minimumWidth = minimumWidth;
  55222. mw->maximumNumColumns = maximumNumColumns;
  55223. mw->standardItemHeight = standardItemHeight;
  55224. mw->dismissOnMouseUp = dismissOnMouseUp;
  55225. for (int i = 0; i < menu.items.size(); ++i)
  55226. {
  55227. PopupMenu::Item* const item = menu.items.getUnchecked(i);
  55228. mw->addItem (*item);
  55229. ++totalItems;
  55230. }
  55231. if (totalItems > 0)
  55232. {
  55233. mw->owner = owner_;
  55234. mw->menuBarComponent = menuBarComponent;
  55235. mw->managerOfChosenCommand = managerOfChosenCommand;
  55236. mw->componentAttachedTo = componentAttachedTo;
  55237. mw->attachedCompWatcher = componentAttachedTo != 0 ? new ComponentDeletionWatcher (componentAttachedTo) : 0;
  55238. mw->calculateWindowPos (minX, maxX, minY, maxY, alignToRectangle);
  55239. mw->setTopLeftPosition (mw->windowPos.getX(),
  55240. mw->windowPos.getY());
  55241. mw->updateYPositions();
  55242. if (itemIdThatMustBeVisible != 0)
  55243. {
  55244. const int y = minY - mw->windowPos.getY();
  55245. mw->ensureItemIsVisible (itemIdThatMustBeVisible,
  55246. (((unsigned int) y) < (unsigned int) mw->windowPos.getHeight()) ? y : -1);
  55247. }
  55248. mw->resizeToBestWindowPos();
  55249. mw->addToDesktop (ComponentPeer::windowIsTemporary
  55250. | mw->getLookAndFeel().getMenuWindowFlags());
  55251. return mw.release();
  55252. }
  55253. }
  55254. return 0;
  55255. }
  55256. void paint (Graphics& g)
  55257. {
  55258. getLookAndFeel().drawPopupMenuBackground (g, getWidth(), getHeight());
  55259. }
  55260. void paintOverChildren (Graphics& g)
  55261. {
  55262. if (isScrolling())
  55263. {
  55264. LookAndFeel& lf = getLookAndFeel();
  55265. if (isScrollZoneActive (false))
  55266. lf.drawPopupMenuUpDownArrow (g, getWidth(), PopupMenuSettings::scrollZone, true);
  55267. if (isScrollZoneActive (true))
  55268. {
  55269. g.setOrigin (0, getHeight() - PopupMenuSettings::scrollZone);
  55270. lf.drawPopupMenuUpDownArrow (g, getWidth(), PopupMenuSettings::scrollZone, false);
  55271. }
  55272. }
  55273. }
  55274. bool isScrollZoneActive (bool bottomOne) const
  55275. {
  55276. return isScrolling()
  55277. && (bottomOne
  55278. ? childYOffset < contentHeight - windowPos.getHeight()
  55279. : childYOffset > 0);
  55280. }
  55281. void addItem (const PopupMenu::Item& item)
  55282. {
  55283. PopupMenu::ItemComponent* const mic = new PopupMenu::ItemComponent (item);
  55284. addAndMakeVisible (mic);
  55285. int itemW = 80;
  55286. int itemH = 16;
  55287. mic->getIdealSize (itemW, itemH, standardItemHeight);
  55288. mic->setSize (itemW, jlimit (2, 600, itemH));
  55289. mic->addMouseListener (this, false);
  55290. }
  55291. // hide this and all sub-comps
  55292. void hide (const PopupMenu::Item* const item)
  55293. {
  55294. if (isVisible())
  55295. {
  55296. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  55297. activeSubMenu = 0;
  55298. currentChild = 0;
  55299. exitModalState (item != 0 ? item->itemId : 0);
  55300. setVisible (false);
  55301. if (item != 0
  55302. && item->commandManager != 0
  55303. && item->itemId != 0)
  55304. {
  55305. *managerOfChosenCommand = item->commandManager;
  55306. }
  55307. }
  55308. }
  55309. void dismissMenu (const PopupMenu::Item* const item)
  55310. {
  55311. if (owner != 0)
  55312. {
  55313. owner->dismissMenu (item);
  55314. }
  55315. else
  55316. {
  55317. if (item != 0)
  55318. {
  55319. // need a copy of this on the stack as the one passed in will get deleted during this call
  55320. const PopupMenu::Item mi (*item);
  55321. hide (&mi);
  55322. }
  55323. else
  55324. {
  55325. hide (0);
  55326. }
  55327. }
  55328. }
  55329. void mouseMove (const MouseEvent&)
  55330. {
  55331. timerCallback();
  55332. }
  55333. void mouseDown (const MouseEvent&)
  55334. {
  55335. timerCallback();
  55336. }
  55337. void mouseDrag (const MouseEvent&)
  55338. {
  55339. timerCallback();
  55340. }
  55341. void mouseUp (const MouseEvent&)
  55342. {
  55343. timerCallback();
  55344. }
  55345. void mouseWheelMove (const MouseEvent&, float /*amountX*/, float amountY)
  55346. {
  55347. alterChildYPos (roundToInt (-10.0f * amountY * PopupMenuSettings::scrollZone));
  55348. lastMouseX = -1;
  55349. }
  55350. bool keyPressed (const KeyPress& key)
  55351. {
  55352. if (key.isKeyCode (KeyPress::downKey))
  55353. {
  55354. selectNextItem (1);
  55355. }
  55356. else if (key.isKeyCode (KeyPress::upKey))
  55357. {
  55358. selectNextItem (-1);
  55359. }
  55360. else if (key.isKeyCode (KeyPress::leftKey))
  55361. {
  55362. Window* parentWindow = owner;
  55363. if (parentWindow != 0)
  55364. {
  55365. PopupMenu::ItemComponent* currentChildOfParent
  55366. = (parentWindow != 0) ? parentWindow->currentChild : 0;
  55367. hide (0);
  55368. if (parentWindow->isValidComponent())
  55369. parentWindow->setCurrentlyHighlightedChild (currentChildOfParent);
  55370. disableTimerUntilMouseMoves();
  55371. }
  55372. else if (menuBarComponent != 0)
  55373. {
  55374. menuBarComponent->keyPressed (key);
  55375. }
  55376. }
  55377. else if (key.isKeyCode (KeyPress::rightKey))
  55378. {
  55379. disableTimerUntilMouseMoves();
  55380. if (showSubMenuFor (currentChild))
  55381. {
  55382. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  55383. if (activeSubMenu != 0 && activeSubMenu->isVisible())
  55384. activeSubMenu->selectNextItem (1);
  55385. }
  55386. else if (menuBarComponent != 0)
  55387. {
  55388. menuBarComponent->keyPressed (key);
  55389. }
  55390. }
  55391. else if (key.isKeyCode (KeyPress::returnKey))
  55392. {
  55393. triggerCurrentlyHighlightedItem();
  55394. }
  55395. else if (key.isKeyCode (KeyPress::escapeKey))
  55396. {
  55397. dismissMenu (0);
  55398. }
  55399. else
  55400. {
  55401. return false;
  55402. }
  55403. return true;
  55404. }
  55405. void inputAttemptWhenModal()
  55406. {
  55407. timerCallback();
  55408. if (! isOverAnyMenu())
  55409. {
  55410. if (componentAttachedTo != 0 && ! attachedCompWatcher->hasBeenDeleted())
  55411. {
  55412. // we want to dismiss the menu, but if we do it synchronously, then
  55413. // the mouse-click will be allowed to pass through. That's good, except
  55414. // when the user clicks on the button that orginally popped the menu up,
  55415. // as they'll expect the menu to go away, and in fact it'll just
  55416. // come back. So only dismiss synchronously if they're not on the original
  55417. // comp that we're attached to.
  55418. int mx, my;
  55419. componentAttachedTo->getMouseXYRelative (mx, my);
  55420. if (componentAttachedTo->reallyContains (mx, my, true))
  55421. {
  55422. postCommandMessage (PopupMenuSettings::dismissCommandId); // dismiss asynchrounously
  55423. return;
  55424. }
  55425. }
  55426. dismissMenu (0);
  55427. }
  55428. }
  55429. void handleCommandMessage (int commandId)
  55430. {
  55431. Component::handleCommandMessage (commandId);
  55432. if (commandId == PopupMenuSettings::dismissCommandId)
  55433. dismissMenu (0);
  55434. }
  55435. void timerCallback()
  55436. {
  55437. if (! isVisible())
  55438. return;
  55439. if (attachedCompWatcher != 0 && attachedCompWatcher->hasBeenDeleted())
  55440. {
  55441. dismissMenu (0);
  55442. return;
  55443. }
  55444. Window* currentlyModalWindow = dynamic_cast <Window*> (Component::getCurrentlyModalComponent());
  55445. if (currentlyModalWindow != 0 && ! treeContains (currentlyModalWindow))
  55446. return;
  55447. startTimer (PopupMenuSettings::timerInterval); // do this in case it was called from a mouse
  55448. // move rather than a real timer callback
  55449. int mx, my;
  55450. Desktop::getMousePosition (mx, my);
  55451. int x = mx, y = my;
  55452. globalPositionToRelative (x, y);
  55453. const uint32 now = Time::getMillisecondCounter();
  55454. if (now > timeEnteredCurrentChildComp + 100
  55455. && reallyContains (x, y, true)
  55456. && currentChild->isValidComponent()
  55457. && (! disableMouseMoves)
  55458. && ! (activeSubMenu != 0 && activeSubMenu->isVisible()))
  55459. {
  55460. showSubMenuFor (currentChild);
  55461. }
  55462. if (mx != lastMouseX || my != lastMouseY || now > lastMouseMoveTime + 350)
  55463. {
  55464. highlightItemUnderMouse (mx, my, x, y);
  55465. }
  55466. bool overScrollArea = false;
  55467. if (isScrolling()
  55468. && (isOver || (isDown && ((unsigned int) x) < (unsigned int) getWidth()))
  55469. && ((isScrollZoneActive (false) && y < PopupMenuSettings::scrollZone)
  55470. || (isScrollZoneActive (true) && y > getHeight() - PopupMenuSettings::scrollZone)))
  55471. {
  55472. if (now > lastScroll + 20)
  55473. {
  55474. scrollAcceleration = jmin (4.0, scrollAcceleration * 1.04);
  55475. int amount = 0;
  55476. for (int i = 0; i < getNumChildComponents() && amount == 0; ++i)
  55477. amount = ((int) scrollAcceleration) * getChildComponent (i)->getHeight();
  55478. alterChildYPos (y < PopupMenuSettings::scrollZone ? -amount : amount);
  55479. lastScroll = now;
  55480. }
  55481. overScrollArea = true;
  55482. lastMouseX = -1; // trigger a mouse-move
  55483. }
  55484. else
  55485. {
  55486. scrollAcceleration = 1.0;
  55487. }
  55488. const bool wasDown = isDown;
  55489. bool isOverAny = isOverAnyMenu();
  55490. if (hideOnExit && hasBeenOver && (! isOverAny) && activeSubMenu != 0)
  55491. {
  55492. activeSubMenu->updateMouseOverStatus (mx, my);
  55493. isOverAny = isOverAnyMenu();
  55494. }
  55495. if (hideOnExit && hasBeenOver && ! isOverAny)
  55496. {
  55497. hide (0);
  55498. }
  55499. else
  55500. {
  55501. isDown = hasBeenOver
  55502. && (ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown()
  55503. || ModifierKeys::getCurrentModifiersRealtime().isAnyMouseButtonDown());
  55504. bool anyFocused = Process::isForegroundProcess();
  55505. if (anyFocused && Component::getCurrentlyFocusedComponent() == 0)
  55506. {
  55507. // because no component at all may have focus, our test here will
  55508. // only be triggered when something has focus and then loses it.
  55509. anyFocused = ! hasAnyJuceCompHadFocus;
  55510. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  55511. {
  55512. if (ComponentPeer::getPeer (i)->isFocused())
  55513. {
  55514. anyFocused = true;
  55515. hasAnyJuceCompHadFocus = true;
  55516. break;
  55517. }
  55518. }
  55519. }
  55520. if (! anyFocused)
  55521. {
  55522. if (now > lastFocused + 10)
  55523. {
  55524. wasHiddenBecauseOfAppChange() = true;
  55525. dismissMenu (0);
  55526. return; // may have been deleted by the previous call..
  55527. }
  55528. }
  55529. else if (wasDown && now > menuCreationTime + 250
  55530. && ! (isDown || overScrollArea))
  55531. {
  55532. isOver = reallyContains (x, y, true);
  55533. if (isOver)
  55534. {
  55535. triggerCurrentlyHighlightedItem();
  55536. }
  55537. else if ((hasBeenOver || ! dismissOnMouseUp) && ! isOverAny)
  55538. {
  55539. dismissMenu (0);
  55540. }
  55541. return; // may have been deleted by the previous calls..
  55542. }
  55543. else
  55544. {
  55545. lastFocused = now;
  55546. }
  55547. }
  55548. }
  55549. static Array<Window*>& getActiveWindows()
  55550. {
  55551. static Array<Window*> activeMenuWindows;
  55552. return activeMenuWindows;
  55553. }
  55554. static bool& wasHiddenBecauseOfAppChange() throw()
  55555. {
  55556. static bool b = false;
  55557. return b;
  55558. }
  55559. juce_UseDebuggingNewOperator
  55560. private:
  55561. Window* owner;
  55562. PopupMenu::ItemComponent* currentChild;
  55563. ScopedPointer <Window> activeSubMenu;
  55564. Component* menuBarComponent;
  55565. ApplicationCommandManager** managerOfChosenCommand;
  55566. Component* componentAttachedTo;
  55567. ScopedPointer <ComponentDeletionWatcher> attachedCompWatcher;
  55568. Rectangle<int> windowPos;
  55569. int lastMouseX, lastMouseY;
  55570. int minimumWidth, maximumNumColumns, standardItemHeight;
  55571. bool isOver, hasBeenOver, isDown, needsToScroll;
  55572. bool dismissOnMouseUp, hideOnExit, disableMouseMoves, hasAnyJuceCompHadFocus;
  55573. int numColumns, contentHeight, childYOffset;
  55574. Array <int> columnWidths;
  55575. uint32 menuCreationTime, lastFocused, lastScroll, lastMouseMoveTime, timeEnteredCurrentChildComp;
  55576. double scrollAcceleration;
  55577. bool overlaps (const Rectangle<int>& r) const
  55578. {
  55579. return r.intersects (getBounds())
  55580. || (owner != 0 && owner->overlaps (r));
  55581. }
  55582. bool isOverAnyMenu() const
  55583. {
  55584. return (owner != 0) ? owner->isOverAnyMenu()
  55585. : isOverChildren();
  55586. }
  55587. bool isOverChildren() const
  55588. {
  55589. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  55590. return isVisible()
  55591. && (isOver || (activeSubMenu != 0 && activeSubMenu->isOverChildren()));
  55592. }
  55593. void updateMouseOverStatus (const int mx, const int my)
  55594. {
  55595. int rx = mx, ry = my;
  55596. globalPositionToRelative (rx, ry);
  55597. isOver = reallyContains (rx, ry, true);
  55598. if (activeSubMenu != 0)
  55599. activeSubMenu->updateMouseOverStatus (mx, my);
  55600. }
  55601. bool treeContains (const Window* const window) const throw()
  55602. {
  55603. const Window* mw = this;
  55604. while (mw->owner != 0)
  55605. mw = mw->owner;
  55606. while (mw != 0)
  55607. {
  55608. if (mw == window)
  55609. return true;
  55610. mw = mw->activeSubMenu;
  55611. }
  55612. return false;
  55613. }
  55614. void calculateWindowPos (const int minX, const int maxX,
  55615. const int minY, const int maxY,
  55616. const bool alignToRectangle)
  55617. {
  55618. const Rectangle<int> mon (Desktop::getInstance()
  55619. .getMonitorAreaContaining ((minX + maxX) / 2,
  55620. (minY + maxY) / 2,
  55621. #if JUCE_MAC
  55622. true));
  55623. #else
  55624. false)); // on windows, don't stop the menu overlapping the taskbar
  55625. #endif
  55626. int x, y, widthToUse, heightToUse;
  55627. layoutMenuItems (mon.getWidth() - 24, widthToUse, heightToUse);
  55628. if (alignToRectangle)
  55629. {
  55630. x = minX;
  55631. const int spaceUnder = mon.getHeight() - (maxY - mon.getY());
  55632. const int spaceOver = minY - mon.getY();
  55633. if (heightToUse < spaceUnder - 30 || spaceUnder >= spaceOver)
  55634. y = maxY;
  55635. else
  55636. y = minY - heightToUse;
  55637. }
  55638. else
  55639. {
  55640. bool tendTowardsRight = (minX + maxX) / 2 < mon.getCentreX();
  55641. if (owner != 0)
  55642. {
  55643. if (owner->owner != 0)
  55644. {
  55645. const bool ownerGoingRight = (owner->getX() + owner->getWidth() / 2
  55646. > owner->owner->getX() + owner->owner->getWidth() / 2);
  55647. if (ownerGoingRight && maxX + widthToUse < mon.getRight() - 4)
  55648. tendTowardsRight = true;
  55649. else if ((! ownerGoingRight) && minX > widthToUse + 4)
  55650. tendTowardsRight = false;
  55651. }
  55652. else if (maxX + widthToUse < mon.getRight() - 32)
  55653. {
  55654. tendTowardsRight = true;
  55655. }
  55656. }
  55657. const int biggestSpace = jmax (mon.getRight() - maxX,
  55658. minX - mon.getX()) - 32;
  55659. if (biggestSpace < widthToUse)
  55660. {
  55661. layoutMenuItems (biggestSpace + (maxX - minX) / 3, widthToUse, heightToUse);
  55662. if (numColumns > 1)
  55663. layoutMenuItems (biggestSpace - 4, widthToUse, heightToUse);
  55664. tendTowardsRight = (mon.getRight() - maxX) >= (minX - mon.getX());
  55665. }
  55666. if (tendTowardsRight)
  55667. x = jmin (mon.getRight() - widthToUse - 4, maxX);
  55668. else
  55669. x = jmax (mon.getX() + 4, minX - widthToUse);
  55670. y = minY;
  55671. if ((minY + maxY) / 2 > mon.getCentreY())
  55672. y = jmax (mon.getY(), maxY - heightToUse);
  55673. }
  55674. x = jmax (mon.getX() + 1, jmin (mon.getRight() - (widthToUse + 6), x));
  55675. y = jmax (mon.getY() + 1, jmin (mon.getBottom() - (heightToUse + 6), y));
  55676. windowPos.setBounds (x, y, widthToUse, heightToUse);
  55677. // sets this flag if it's big enough to obscure any of its parent menus
  55678. hideOnExit = (owner != 0)
  55679. && owner->windowPos.intersects (windowPos.expanded (-4, -4));
  55680. }
  55681. void layoutMenuItems (const int maxMenuW, int& width, int& height)
  55682. {
  55683. numColumns = 0;
  55684. contentHeight = 0;
  55685. const int maxMenuH = getParentHeight() - 24;
  55686. int totalW;
  55687. do
  55688. {
  55689. ++numColumns;
  55690. totalW = workOutBestSize (maxMenuW);
  55691. if (totalW > maxMenuW)
  55692. {
  55693. numColumns = jmax (1, numColumns - 1);
  55694. totalW = workOutBestSize (maxMenuW); // to update col widths
  55695. break;
  55696. }
  55697. else if (totalW > maxMenuW / 2 || contentHeight < maxMenuH)
  55698. {
  55699. break;
  55700. }
  55701. } while (numColumns < maximumNumColumns);
  55702. const int actualH = jmin (contentHeight, maxMenuH);
  55703. needsToScroll = contentHeight > actualH;
  55704. width = updateYPositions();
  55705. height = actualH + PopupMenuSettings::borderSize * 2;
  55706. }
  55707. int workOutBestSize (const int maxMenuW)
  55708. {
  55709. int totalW = 0;
  55710. contentHeight = 0;
  55711. int childNum = 0;
  55712. for (int col = 0; col < numColumns; ++col)
  55713. {
  55714. int i, colW = 50, colH = 0;
  55715. const int numChildren = jmin (getNumChildComponents() - childNum,
  55716. (getNumChildComponents() + numColumns - 1) / numColumns);
  55717. for (i = numChildren; --i >= 0;)
  55718. {
  55719. colW = jmax (colW, getChildComponent (childNum + i)->getWidth());
  55720. colH += getChildComponent (childNum + i)->getHeight();
  55721. }
  55722. colW = jmin (maxMenuW / jmax (1, numColumns - 2), colW + PopupMenuSettings::borderSize * 2);
  55723. columnWidths.set (col, colW);
  55724. totalW += colW;
  55725. contentHeight = jmax (contentHeight, colH);
  55726. childNum += numChildren;
  55727. }
  55728. if (totalW < minimumWidth)
  55729. {
  55730. totalW = minimumWidth;
  55731. for (int col = 0; col < numColumns; ++col)
  55732. columnWidths.set (0, totalW / numColumns);
  55733. }
  55734. return totalW;
  55735. }
  55736. void ensureItemIsVisible (const int itemId, int wantedY)
  55737. {
  55738. jassert (itemId != 0)
  55739. for (int i = getNumChildComponents(); --i >= 0;)
  55740. {
  55741. PopupMenu::ItemComponent* const m = (PopupMenu::ItemComponent*) getChildComponent (i);
  55742. if (m != 0
  55743. && m->itemInfo.itemId == itemId
  55744. && windowPos.getHeight() > PopupMenuSettings::scrollZone * 4)
  55745. {
  55746. const int currentY = m->getY();
  55747. if (wantedY > 0 || currentY < 0 || m->getBottom() > windowPos.getHeight())
  55748. {
  55749. if (wantedY < 0)
  55750. wantedY = jlimit (PopupMenuSettings::scrollZone,
  55751. jmax (PopupMenuSettings::scrollZone,
  55752. windowPos.getHeight() - (PopupMenuSettings::scrollZone + m->getHeight())),
  55753. currentY);
  55754. const Rectangle<int> mon (Desktop::getInstance()
  55755. .getMonitorAreaContaining (windowPos.getX(),
  55756. windowPos.getY(),
  55757. true));
  55758. int deltaY = wantedY - currentY;
  55759. windowPos.setSize (jmin (windowPos.getWidth(), mon.getWidth()),
  55760. jmin (windowPos.getHeight(), mon.getHeight()));
  55761. const int newY = jlimit (mon.getY(),
  55762. mon.getBottom() - windowPos.getHeight(),
  55763. windowPos.getY() + deltaY);
  55764. deltaY -= newY - windowPos.getY();
  55765. childYOffset -= deltaY;
  55766. windowPos.setPosition (windowPos.getX(), newY);
  55767. updateYPositions();
  55768. }
  55769. break;
  55770. }
  55771. }
  55772. }
  55773. void resizeToBestWindowPos()
  55774. {
  55775. Rectangle<int> r (windowPos);
  55776. if (childYOffset < 0)
  55777. {
  55778. r.setBounds (r.getX(), r.getY() - childYOffset,
  55779. r.getWidth(), r.getHeight() + childYOffset);
  55780. }
  55781. else if (childYOffset > 0)
  55782. {
  55783. const int spaceAtBottom = r.getHeight() - (contentHeight - childYOffset);
  55784. if (spaceAtBottom > 0)
  55785. r.setSize (r.getWidth(), r.getHeight() - spaceAtBottom);
  55786. }
  55787. setBounds (r);
  55788. updateYPositions();
  55789. }
  55790. void alterChildYPos (const int delta)
  55791. {
  55792. if (isScrolling())
  55793. {
  55794. childYOffset += delta;
  55795. if (delta < 0)
  55796. {
  55797. childYOffset = jmax (childYOffset, 0);
  55798. }
  55799. else if (delta > 0)
  55800. {
  55801. childYOffset = jmin (childYOffset,
  55802. contentHeight - windowPos.getHeight() + PopupMenuSettings::borderSize);
  55803. }
  55804. updateYPositions();
  55805. }
  55806. else
  55807. {
  55808. childYOffset = 0;
  55809. }
  55810. resizeToBestWindowPos();
  55811. repaint();
  55812. }
  55813. int updateYPositions()
  55814. {
  55815. int x = 0;
  55816. int childNum = 0;
  55817. for (int col = 0; col < numColumns; ++col)
  55818. {
  55819. const int numChildren = jmin (getNumChildComponents() - childNum,
  55820. (getNumChildComponents() + numColumns - 1) / numColumns);
  55821. const int colW = columnWidths [col];
  55822. int y = PopupMenuSettings::borderSize - (childYOffset + (getY() - windowPos.getY()));
  55823. for (int i = 0; i < numChildren; ++i)
  55824. {
  55825. Component* const c = getChildComponent (childNum + i);
  55826. c->setBounds (x, y, colW, c->getHeight());
  55827. y += c->getHeight();
  55828. }
  55829. x += colW;
  55830. childNum += numChildren;
  55831. }
  55832. return x;
  55833. }
  55834. bool isScrolling() const throw()
  55835. {
  55836. return childYOffset != 0 || needsToScroll;
  55837. }
  55838. void setCurrentlyHighlightedChild (PopupMenu::ItemComponent* const child)
  55839. {
  55840. if (currentChild->isValidComponent())
  55841. currentChild->setHighlighted (false);
  55842. currentChild = child;
  55843. if (currentChild != 0)
  55844. {
  55845. currentChild->setHighlighted (true);
  55846. timeEnteredCurrentChildComp = Time::getApproximateMillisecondCounter();
  55847. }
  55848. }
  55849. bool showSubMenuFor (PopupMenu::ItemComponent* const childComp)
  55850. {
  55851. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  55852. activeSubMenu = 0;
  55853. if (childComp->isValidComponent() && childComp->itemInfo.hasActiveSubMenu())
  55854. {
  55855. int left = 0, top = 0;
  55856. childComp->relativePositionToGlobal (left, top);
  55857. int right = childComp->getWidth(), bottom = childComp->getHeight();
  55858. childComp->relativePositionToGlobal (right, bottom);
  55859. activeSubMenu = Window::create (*(childComp->itemInfo.subMenu),
  55860. dismissOnMouseUp,
  55861. this,
  55862. left, right, top, bottom,
  55863. 0, maximumNumColumns,
  55864. standardItemHeight,
  55865. false, 0, menuBarComponent,
  55866. managerOfChosenCommand,
  55867. componentAttachedTo);
  55868. if (activeSubMenu != 0)
  55869. {
  55870. activeSubMenu->setVisible (true);
  55871. activeSubMenu->enterModalState (false);
  55872. activeSubMenu->toFront (false);
  55873. return true;
  55874. }
  55875. }
  55876. return false;
  55877. }
  55878. void highlightItemUnderMouse (const int mx, const int my, const int x, const int y)
  55879. {
  55880. isOver = reallyContains (x, y, true);
  55881. if (isOver)
  55882. hasBeenOver = true;
  55883. if (abs (lastMouseX - mx) > 2 || abs (lastMouseY - my) > 2)
  55884. {
  55885. lastMouseMoveTime = Time::getApproximateMillisecondCounter();
  55886. if (disableMouseMoves && isOver)
  55887. disableMouseMoves = false;
  55888. }
  55889. if (disableMouseMoves)
  55890. return;
  55891. bool isMovingTowardsMenu = false;
  55892. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent())
  55893. if (isOver && (activeSubMenu != 0) && (mx != lastMouseX || my != lastMouseY))
  55894. {
  55895. // try to intelligently guess whether the user is moving the mouse towards a currently-open
  55896. // submenu. To do this, look at whether the mouse stays inside a triangular region that
  55897. // extends from the last mouse pos to the submenu's rectangle..
  55898. float subX = (float) activeSubMenu->getScreenX();
  55899. if (activeSubMenu->getX() > getX())
  55900. {
  55901. lastMouseX -= 2; // to enlarge the triangle a bit, in case the mouse only moves a couple of pixels
  55902. }
  55903. else
  55904. {
  55905. lastMouseX += 2;
  55906. subX += activeSubMenu->getWidth();
  55907. }
  55908. Path areaTowardsSubMenu;
  55909. areaTowardsSubMenu.addTriangle ((float) lastMouseX,
  55910. (float) lastMouseY,
  55911. subX,
  55912. (float) activeSubMenu->getScreenY(),
  55913. subX,
  55914. (float) (activeSubMenu->getScreenY() + activeSubMenu->getHeight()));
  55915. isMovingTowardsMenu = areaTowardsSubMenu.contains ((float) mx, (float) my);
  55916. }
  55917. lastMouseX = mx;
  55918. lastMouseY = my;
  55919. if (! isMovingTowardsMenu)
  55920. {
  55921. Component* c = getComponentAt (x, y);
  55922. if (c == this)
  55923. c = 0;
  55924. PopupMenu::ItemComponent* mic = dynamic_cast <PopupMenu::ItemComponent*> (c);
  55925. if (mic == 0 && c != 0)
  55926. mic = c->findParentComponentOfClass ((PopupMenu::ItemComponent*) 0);
  55927. if (mic != currentChild
  55928. && (isOver || (activeSubMenu == 0) || ! activeSubMenu->isVisible()))
  55929. {
  55930. if (isOver && (c != 0) && (activeSubMenu != 0))
  55931. {
  55932. activeSubMenu->hide (0);
  55933. }
  55934. if (! isOver)
  55935. mic = 0;
  55936. setCurrentlyHighlightedChild (mic);
  55937. }
  55938. }
  55939. }
  55940. void triggerCurrentlyHighlightedItem()
  55941. {
  55942. if (currentChild->isValidComponent()
  55943. && currentChild->itemInfo.canBeTriggered()
  55944. && (currentChild->itemInfo.customComp == 0
  55945. || currentChild->itemInfo.customComp->isTriggeredAutomatically))
  55946. {
  55947. dismissMenu (&currentChild->itemInfo);
  55948. }
  55949. }
  55950. void selectNextItem (const int delta)
  55951. {
  55952. disableTimerUntilMouseMoves();
  55953. PopupMenu::ItemComponent* mic = 0;
  55954. bool wasLastOne = (currentChild == 0);
  55955. const int numItems = getNumChildComponents();
  55956. for (int i = 0; i < numItems + 1; ++i)
  55957. {
  55958. int index = (delta > 0) ? i : (numItems - 1 - i);
  55959. index = (index + numItems) % numItems;
  55960. mic = dynamic_cast <PopupMenu::ItemComponent*> (getChildComponent (index));
  55961. if (mic != 0 && (mic->itemInfo.canBeTriggered() || mic->itemInfo.hasActiveSubMenu())
  55962. && wasLastOne)
  55963. break;
  55964. if (mic == currentChild)
  55965. wasLastOne = true;
  55966. }
  55967. setCurrentlyHighlightedChild (mic);
  55968. }
  55969. void disableTimerUntilMouseMoves()
  55970. {
  55971. disableMouseMoves = true;
  55972. if (owner != 0)
  55973. owner->disableTimerUntilMouseMoves();
  55974. }
  55975. Window (const Window&);
  55976. Window& operator= (const Window&);
  55977. };
  55978. PopupMenu::PopupMenu()
  55979. : lookAndFeel (0),
  55980. separatorPending (false)
  55981. {
  55982. }
  55983. PopupMenu::PopupMenu (const PopupMenu& other)
  55984. : lookAndFeel (other.lookAndFeel),
  55985. separatorPending (false)
  55986. {
  55987. items.ensureStorageAllocated (other.items.size());
  55988. for (int i = 0; i < other.items.size(); ++i)
  55989. items.add (new Item (*other.items.getUnchecked(i)));
  55990. }
  55991. const PopupMenu& PopupMenu::operator= (const PopupMenu& other)
  55992. {
  55993. if (this != &other)
  55994. {
  55995. lookAndFeel = other.lookAndFeel;
  55996. clear();
  55997. items.ensureStorageAllocated (other.items.size());
  55998. for (int i = 0; i < other.items.size(); ++i)
  55999. items.add (new Item (*other.items.getUnchecked(i)));
  56000. }
  56001. return *this;
  56002. }
  56003. PopupMenu::~PopupMenu()
  56004. {
  56005. clear();
  56006. }
  56007. void PopupMenu::clear()
  56008. {
  56009. items.clear();
  56010. separatorPending = false;
  56011. }
  56012. void PopupMenu::addSeparatorIfPending()
  56013. {
  56014. if (separatorPending)
  56015. {
  56016. separatorPending = false;
  56017. if (items.size() > 0)
  56018. items.add (new Item());
  56019. }
  56020. }
  56021. void PopupMenu::addItem (const int itemResultId,
  56022. const String& itemText,
  56023. const bool isActive,
  56024. const bool isTicked,
  56025. const Image* const iconToUse)
  56026. {
  56027. jassert (itemResultId != 0); // 0 is used as a return value to indicate that the user
  56028. // didn't pick anything, so you shouldn't use it as the id
  56029. // for an item..
  56030. addSeparatorIfPending();
  56031. items.add (new Item (itemResultId, itemText, isActive, isTicked,
  56032. iconToUse, Colours::black, false, 0, 0, 0));
  56033. }
  56034. void PopupMenu::addCommandItem (ApplicationCommandManager* commandManager,
  56035. const int commandID,
  56036. const String& displayName)
  56037. {
  56038. jassert (commandManager != 0 && commandID != 0);
  56039. const ApplicationCommandInfo* const registeredInfo = commandManager->getCommandForID (commandID);
  56040. if (registeredInfo != 0)
  56041. {
  56042. ApplicationCommandInfo info (*registeredInfo);
  56043. ApplicationCommandTarget* const target = commandManager->getTargetForCommand (commandID, info);
  56044. addSeparatorIfPending();
  56045. items.add (new Item (commandID,
  56046. displayName.isNotEmpty() ? displayName
  56047. : info.shortName,
  56048. target != 0 && (info.flags & ApplicationCommandInfo::isDisabled) == 0,
  56049. (info.flags & ApplicationCommandInfo::isTicked) != 0,
  56050. 0,
  56051. Colours::black,
  56052. false,
  56053. 0, 0,
  56054. commandManager));
  56055. }
  56056. }
  56057. void PopupMenu::addColouredItem (const int itemResultId,
  56058. const String& itemText,
  56059. const Colour& itemTextColour,
  56060. const bool isActive,
  56061. const bool isTicked,
  56062. const Image* const iconToUse)
  56063. {
  56064. jassert (itemResultId != 0); // 0 is used as a return value to indicate that the user
  56065. // didn't pick anything, so you shouldn't use it as the id
  56066. // for an item..
  56067. addSeparatorIfPending();
  56068. items.add (new Item (itemResultId, itemText, isActive, isTicked,
  56069. iconToUse, itemTextColour, true, 0, 0, 0));
  56070. }
  56071. void PopupMenu::addCustomItem (const int itemResultId,
  56072. PopupMenuCustomComponent* const customComponent)
  56073. {
  56074. jassert (itemResultId != 0); // 0 is used as a return value to indicate that the user
  56075. // didn't pick anything, so you shouldn't use it as the id
  56076. // for an item..
  56077. addSeparatorIfPending();
  56078. items.add (new Item (itemResultId, String::empty, true, false, 0,
  56079. Colours::black, false, customComponent, 0, 0));
  56080. }
  56081. class NormalComponentWrapper : public PopupMenuCustomComponent
  56082. {
  56083. public:
  56084. NormalComponentWrapper (Component* const comp,
  56085. const int w, const int h,
  56086. const bool triggerMenuItemAutomaticallyWhenClicked)
  56087. : PopupMenuCustomComponent (triggerMenuItemAutomaticallyWhenClicked),
  56088. width (w),
  56089. height (h)
  56090. {
  56091. addAndMakeVisible (comp);
  56092. }
  56093. ~NormalComponentWrapper() {}
  56094. void getIdealSize (int& idealWidth, int& idealHeight)
  56095. {
  56096. idealWidth = width;
  56097. idealHeight = height;
  56098. }
  56099. void resized()
  56100. {
  56101. if (getChildComponent(0) != 0)
  56102. getChildComponent(0)->setBounds (0, 0, getWidth(), getHeight());
  56103. }
  56104. juce_UseDebuggingNewOperator
  56105. private:
  56106. const int width, height;
  56107. NormalComponentWrapper (const NormalComponentWrapper&);
  56108. const NormalComponentWrapper& operator= (const NormalComponentWrapper&);
  56109. };
  56110. void PopupMenu::addCustomItem (const int itemResultId,
  56111. Component* customComponent,
  56112. int idealWidth, int idealHeight,
  56113. const bool triggerMenuItemAutomaticallyWhenClicked)
  56114. {
  56115. addCustomItem (itemResultId,
  56116. new NormalComponentWrapper (customComponent,
  56117. idealWidth, idealHeight,
  56118. triggerMenuItemAutomaticallyWhenClicked));
  56119. }
  56120. void PopupMenu::addSubMenu (const String& subMenuName,
  56121. const PopupMenu& subMenu,
  56122. const bool isActive,
  56123. Image* const iconToUse,
  56124. const bool isTicked)
  56125. {
  56126. addSeparatorIfPending();
  56127. items.add (new Item (0, subMenuName, isActive && (subMenu.getNumItems() > 0), isTicked,
  56128. iconToUse, Colours::black, false, 0, &subMenu, 0));
  56129. }
  56130. void PopupMenu::addSeparator()
  56131. {
  56132. separatorPending = true;
  56133. }
  56134. class HeaderItemComponent : public PopupMenuCustomComponent
  56135. {
  56136. public:
  56137. HeaderItemComponent (const String& name)
  56138. : PopupMenuCustomComponent (false)
  56139. {
  56140. setName (name);
  56141. }
  56142. ~HeaderItemComponent()
  56143. {
  56144. }
  56145. void paint (Graphics& g)
  56146. {
  56147. Font f (getLookAndFeel().getPopupMenuFont());
  56148. f.setBold (true);
  56149. g.setFont (f);
  56150. g.setColour (findColour (PopupMenu::headerTextColourId));
  56151. g.drawFittedText (getName(),
  56152. 12, 0, getWidth() - 16, proportionOfHeight (0.8f),
  56153. Justification::bottomLeft, 1);
  56154. }
  56155. void getIdealSize (int& idealWidth,
  56156. int& idealHeight)
  56157. {
  56158. getLookAndFeel().getIdealPopupMenuItemSize (getName(), false, -1, idealWidth, idealHeight);
  56159. idealHeight += idealHeight / 2;
  56160. idealWidth += idealWidth / 4;
  56161. }
  56162. juce_UseDebuggingNewOperator
  56163. };
  56164. void PopupMenu::addSectionHeader (const String& title)
  56165. {
  56166. addCustomItem (0X4734a34f, new HeaderItemComponent (title));
  56167. }
  56168. Component* PopupMenu::createMenuComponent (const int x, const int y, const int w, const int h,
  56169. const int itemIdThatMustBeVisible,
  56170. const int minimumWidth,
  56171. const int maximumNumColumns,
  56172. const int standardItemHeight,
  56173. const bool alignToRectangle,
  56174. Component* menuBarComponent,
  56175. ApplicationCommandManager** managerOfChosenCommand,
  56176. Component* const componentAttachedTo)
  56177. {
  56178. Window* const pw
  56179. = Window::create (*this,
  56180. ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown(),
  56181. 0,
  56182. x, x + w,
  56183. y, y + h,
  56184. minimumWidth,
  56185. maximumNumColumns,
  56186. standardItemHeight,
  56187. alignToRectangle,
  56188. itemIdThatMustBeVisible,
  56189. menuBarComponent,
  56190. managerOfChosenCommand,
  56191. componentAttachedTo);
  56192. if (pw != 0)
  56193. pw->setVisible (true);
  56194. return pw;
  56195. }
  56196. int PopupMenu::showMenu (const int x, const int y, const int w, const int h,
  56197. const int itemIdThatMustBeVisible,
  56198. const int minimumWidth,
  56199. const int maximumNumColumns,
  56200. const int standardItemHeight,
  56201. const bool alignToRectangle,
  56202. Component* const componentAttachedTo)
  56203. {
  56204. Component* const prevFocused = Component::getCurrentlyFocusedComponent();
  56205. ScopedPointer <ComponentDeletionWatcher> deletionChecker[2];
  56206. if (prevFocused != 0)
  56207. deletionChecker[0] = new ComponentDeletionWatcher (prevFocused);
  56208. Component* const prevTopLevel = (prevFocused != 0) ? prevFocused->getTopLevelComponent() : 0;
  56209. if (prevTopLevel != 0)
  56210. deletionChecker[1] = new ComponentDeletionWatcher (prevTopLevel);
  56211. Window::wasHiddenBecauseOfAppChange() = false;
  56212. int result = 0;
  56213. ApplicationCommandManager* managerOfChosenCommand = 0;
  56214. ScopedPointer <Component> popupComp (createMenuComponent (x, y, w, h,
  56215. itemIdThatMustBeVisible,
  56216. minimumWidth,
  56217. maximumNumColumns > 0 ? maximumNumColumns : 7,
  56218. standardItemHeight,
  56219. alignToRectangle, 0,
  56220. &managerOfChosenCommand,
  56221. componentAttachedTo));
  56222. if (popupComp != 0)
  56223. {
  56224. popupComp->enterModalState (false);
  56225. popupComp->toFront (false); // need to do this after making it modal, or it could
  56226. // be stuck behind other comps that are already modal..
  56227. result = popupComp->runModalLoop();
  56228. popupComp = 0;
  56229. if (! Window::wasHiddenBecauseOfAppChange())
  56230. {
  56231. if (deletionChecker[1] != 0 && ! deletionChecker[1]->hasBeenDeleted())
  56232. prevTopLevel->toFront (true);
  56233. if (deletionChecker[0] != 0 && ! deletionChecker[0]->hasBeenDeleted())
  56234. prevFocused->grabKeyboardFocus();
  56235. }
  56236. }
  56237. if (managerOfChosenCommand != 0 && result != 0)
  56238. {
  56239. ApplicationCommandTarget::InvocationInfo info (result);
  56240. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromMenu;
  56241. managerOfChosenCommand->invoke (info, true);
  56242. }
  56243. return result;
  56244. }
  56245. int PopupMenu::show (const int itemIdThatMustBeVisible,
  56246. const int minimumWidth,
  56247. const int maximumNumColumns,
  56248. const int standardItemHeight)
  56249. {
  56250. int x, y;
  56251. Desktop::getMousePosition (x, y);
  56252. return showAt (x, y,
  56253. itemIdThatMustBeVisible,
  56254. minimumWidth,
  56255. maximumNumColumns,
  56256. standardItemHeight);
  56257. }
  56258. int PopupMenu::showAt (const int screenX,
  56259. const int screenY,
  56260. const int itemIdThatMustBeVisible,
  56261. const int minimumWidth,
  56262. const int maximumNumColumns,
  56263. const int standardItemHeight)
  56264. {
  56265. return showMenu (screenX, screenY, 1, 1,
  56266. itemIdThatMustBeVisible,
  56267. minimumWidth, maximumNumColumns,
  56268. standardItemHeight,
  56269. false, 0);
  56270. }
  56271. int PopupMenu::showAt (Component* componentToAttachTo,
  56272. const int itemIdThatMustBeVisible,
  56273. const int minimumWidth,
  56274. const int maximumNumColumns,
  56275. const int standardItemHeight)
  56276. {
  56277. if (componentToAttachTo != 0)
  56278. {
  56279. return showMenu (componentToAttachTo->getScreenX(),
  56280. componentToAttachTo->getScreenY(),
  56281. componentToAttachTo->getWidth(),
  56282. componentToAttachTo->getHeight(),
  56283. itemIdThatMustBeVisible,
  56284. minimumWidth,
  56285. maximumNumColumns,
  56286. standardItemHeight,
  56287. true, componentToAttachTo);
  56288. }
  56289. else
  56290. {
  56291. return show (itemIdThatMustBeVisible,
  56292. minimumWidth,
  56293. maximumNumColumns,
  56294. standardItemHeight);
  56295. }
  56296. }
  56297. void JUCE_CALLTYPE PopupMenu::dismissAllActiveMenus()
  56298. {
  56299. for (int i = Window::getActiveWindows().size(); --i >= 0;)
  56300. {
  56301. Window* const pmw = Window::getActiveWindows()[i];
  56302. if (pmw != 0)
  56303. pmw->dismissMenu (0);
  56304. }
  56305. }
  56306. int PopupMenu::getNumItems() const throw()
  56307. {
  56308. int num = 0;
  56309. for (int i = items.size(); --i >= 0;)
  56310. if (! (items.getUnchecked(i))->isSeparator)
  56311. ++num;
  56312. return num;
  56313. }
  56314. bool PopupMenu::containsCommandItem (const int commandID) const
  56315. {
  56316. for (int i = items.size(); --i >= 0;)
  56317. {
  56318. const Item* mi = items.getUnchecked (i);
  56319. if ((mi->itemId == commandID && mi->commandManager != 0)
  56320. || (mi->subMenu != 0 && mi->subMenu->containsCommandItem (commandID)))
  56321. {
  56322. return true;
  56323. }
  56324. }
  56325. return false;
  56326. }
  56327. bool PopupMenu::containsAnyActiveItems() const throw()
  56328. {
  56329. for (int i = items.size(); --i >= 0;)
  56330. {
  56331. const Item* const mi = items.getUnchecked (i);
  56332. if (mi->subMenu != 0)
  56333. {
  56334. if (mi->subMenu->containsAnyActiveItems())
  56335. return true;
  56336. }
  56337. else if (mi->active)
  56338. {
  56339. return true;
  56340. }
  56341. }
  56342. return false;
  56343. }
  56344. void PopupMenu::setLookAndFeel (LookAndFeel* const newLookAndFeel)
  56345. {
  56346. lookAndFeel = newLookAndFeel;
  56347. }
  56348. PopupMenuCustomComponent::PopupMenuCustomComponent (const bool isTriggeredAutomatically_)
  56349. : isHighlighted (false),
  56350. isTriggeredAutomatically (isTriggeredAutomatically_)
  56351. {
  56352. }
  56353. PopupMenuCustomComponent::~PopupMenuCustomComponent()
  56354. {
  56355. }
  56356. void PopupMenuCustomComponent::triggerMenuItem()
  56357. {
  56358. PopupMenu::ItemComponent* const mic = dynamic_cast <PopupMenu::ItemComponent*> (getParentComponent());
  56359. if (mic != 0)
  56360. {
  56361. PopupMenu::Window* const pmw = dynamic_cast <PopupMenu::Window*> (mic->getParentComponent());
  56362. if (pmw != 0)
  56363. {
  56364. pmw->dismissMenu (&mic->itemInfo);
  56365. }
  56366. else
  56367. {
  56368. // something must have gone wrong with the component hierarchy if this happens..
  56369. jassertfalse
  56370. }
  56371. }
  56372. else
  56373. {
  56374. // why isn't this component inside a menu? Not much point triggering the item if
  56375. // there's no menu.
  56376. jassertfalse
  56377. }
  56378. }
  56379. PopupMenu::MenuItemIterator::MenuItemIterator (const PopupMenu& menu_)
  56380. : subMenu (0),
  56381. itemId (0),
  56382. isSeparator (false),
  56383. isTicked (false),
  56384. isEnabled (false),
  56385. isCustomComponent (false),
  56386. isSectionHeader (false),
  56387. customColour (0),
  56388. customImage (0),
  56389. menu (menu_),
  56390. index (0)
  56391. {
  56392. }
  56393. PopupMenu::MenuItemIterator::~MenuItemIterator()
  56394. {
  56395. }
  56396. bool PopupMenu::MenuItemIterator::next()
  56397. {
  56398. if (index >= menu.items.size())
  56399. return false;
  56400. const Item* const item = menu.items.getUnchecked (index);
  56401. ++index;
  56402. itemName = item->customComp != 0 ? item->customComp->getName() : item->text;
  56403. subMenu = item->subMenu;
  56404. itemId = item->itemId;
  56405. isSeparator = item->isSeparator;
  56406. isTicked = item->isTicked;
  56407. isEnabled = item->active;
  56408. isSectionHeader = dynamic_cast <HeaderItemComponent*> ((PopupMenuCustomComponent*) item->customComp) != 0;
  56409. isCustomComponent = (! isSectionHeader) && item->customComp != 0;
  56410. customColour = item->usesColour ? &(item->textColour) : 0;
  56411. customImage = item->image;
  56412. commandManager = item->commandManager;
  56413. return true;
  56414. }
  56415. END_JUCE_NAMESPACE
  56416. /*** End of inlined file: juce_PopupMenu.cpp ***/
  56417. /*** Start of inlined file: juce_ComponentDragger.cpp ***/
  56418. BEGIN_JUCE_NAMESPACE
  56419. ComponentDragger::ComponentDragger()
  56420. : constrainer (0),
  56421. originalX (0),
  56422. originalY (0)
  56423. {
  56424. }
  56425. ComponentDragger::~ComponentDragger()
  56426. {
  56427. }
  56428. void ComponentDragger::startDraggingComponent (Component* const componentToDrag,
  56429. ComponentBoundsConstrainer* const constrainer_)
  56430. {
  56431. jassert (componentToDrag->isValidComponent());
  56432. if (componentToDrag->isValidComponent())
  56433. {
  56434. constrainer = constrainer_;
  56435. originalX = 0;
  56436. originalY = 0;
  56437. componentToDrag->relativePositionToGlobal (originalX, originalY);
  56438. }
  56439. }
  56440. void ComponentDragger::dragComponent (Component* const componentToDrag, const MouseEvent& e)
  56441. {
  56442. jassert (componentToDrag->isValidComponent());
  56443. jassert (e.mods.isAnyMouseButtonDown()); // (the event has to be a drag event..)
  56444. if (componentToDrag->isValidComponent())
  56445. {
  56446. int x = originalX;
  56447. int y = originalY;
  56448. int w = componentToDrag->getWidth();
  56449. int h = componentToDrag->getHeight();
  56450. const Component* const parentComp = componentToDrag->getParentComponent();
  56451. if (parentComp != 0)
  56452. parentComp->globalPositionToRelative (x, y);
  56453. x += e.getDistanceFromDragStartX();
  56454. y += e.getDistanceFromDragStartY();
  56455. if (constrainer != 0)
  56456. constrainer->setBoundsForComponent (componentToDrag, Rectangle<int> (x, y, w, h),
  56457. false, false, false, false);
  56458. else
  56459. componentToDrag->setBounds (x, y, w, h);
  56460. }
  56461. }
  56462. END_JUCE_NAMESPACE
  56463. /*** End of inlined file: juce_ComponentDragger.cpp ***/
  56464. /*** Start of inlined file: juce_DragAndDropContainer.cpp ***/
  56465. BEGIN_JUCE_NAMESPACE
  56466. bool juce_performDragDropFiles (const StringArray& files, const bool copyFiles, bool& shouldStop);
  56467. bool juce_performDragDropText (const String& text, bool& shouldStop);
  56468. class DragImageComponent : public Component,
  56469. public Timer
  56470. {
  56471. private:
  56472. ScopedPointer <Image> image;
  56473. Component* const source;
  56474. DragAndDropContainer* const owner;
  56475. ScopedPointer <ComponentDeletionWatcher> sourceWatcher, mouseDragSourceWatcher, currentlyOverWatcher;
  56476. Component* mouseDragSource;
  56477. DragAndDropTarget* currentlyOver;
  56478. String dragDesc;
  56479. const int imageX, imageY;
  56480. bool hasCheckedForExternalDrag, drawImage;
  56481. DragImageComponent (const DragImageComponent&);
  56482. const DragImageComponent& operator= (const DragImageComponent&);
  56483. public:
  56484. DragImageComponent (Image* const im,
  56485. const String& desc,
  56486. Component* const s,
  56487. DragAndDropContainer* const o,
  56488. const int imageX_, const int imageY_)
  56489. : image (im),
  56490. source (s),
  56491. owner (o),
  56492. currentlyOver (0),
  56493. dragDesc (desc),
  56494. imageX (imageX_),
  56495. imageY (imageY_),
  56496. hasCheckedForExternalDrag (false),
  56497. drawImage (true)
  56498. {
  56499. setSize (im->getWidth(), im->getHeight());
  56500. sourceWatcher = new ComponentDeletionWatcher (source);
  56501. mouseDragSource = Component::getComponentUnderMouse();
  56502. if (mouseDragSource == 0)
  56503. mouseDragSource = source;
  56504. mouseDragSourceWatcher = new ComponentDeletionWatcher (mouseDragSource);
  56505. mouseDragSource->addMouseListener (this, false);
  56506. startTimer (200);
  56507. setInterceptsMouseClicks (false, false);
  56508. setAlwaysOnTop (true);
  56509. }
  56510. ~DragImageComponent()
  56511. {
  56512. if ((DragImageComponent*) owner->dragImageComponent == this)
  56513. owner->dragImageComponent.release();
  56514. if (! mouseDragSourceWatcher->hasBeenDeleted())
  56515. {
  56516. mouseDragSource->removeMouseListener (this);
  56517. if (currentlyOverWatcher != 0 && ! currentlyOverWatcher->hasBeenDeleted())
  56518. if (currentlyOver->isInterestedInDragSource (dragDesc, source))
  56519. currentlyOver->itemDragExit (dragDesc, source);
  56520. }
  56521. }
  56522. void paint (Graphics& g)
  56523. {
  56524. if (isOpaque())
  56525. g.fillAll (Colours::white);
  56526. if (drawImage)
  56527. {
  56528. g.setOpacity (1.0f);
  56529. g.drawImageAt (image, 0, 0);
  56530. }
  56531. }
  56532. DragAndDropTarget* findTarget (const int screenX, const int screenY,
  56533. int& relX, int& relY) const
  56534. {
  56535. Component* hit = getParentComponent();
  56536. if (hit == 0)
  56537. {
  56538. hit = Desktop::getInstance().findComponentAt (screenX, screenY);
  56539. }
  56540. else
  56541. {
  56542. int rx = screenX, ry = screenY;
  56543. hit->globalPositionToRelative (rx, ry);
  56544. hit = hit->getComponentAt (rx, ry);
  56545. }
  56546. // (note: use a local copy of the dragDesc member in case the callback runs
  56547. // a modal loop and deletes this object before the method completes)
  56548. const String dragDescLocal (dragDesc);
  56549. while (hit != 0)
  56550. {
  56551. DragAndDropTarget* const ddt = dynamic_cast <DragAndDropTarget*> (hit);
  56552. if (ddt != 0 && ddt->isInterestedInDragSource (dragDescLocal, source))
  56553. {
  56554. relX = screenX;
  56555. relY = screenY;
  56556. hit->globalPositionToRelative (relX, relY);
  56557. return ddt;
  56558. }
  56559. hit = hit->getParentComponent();
  56560. }
  56561. return 0;
  56562. }
  56563. void mouseUp (const MouseEvent& e)
  56564. {
  56565. if (e.originalComponent != this)
  56566. {
  56567. if (! mouseDragSourceWatcher->hasBeenDeleted())
  56568. mouseDragSource->removeMouseListener (this);
  56569. bool dropAccepted = false;
  56570. DragAndDropTarget* ddt = 0;
  56571. int relX = 0, relY = 0;
  56572. if (isVisible())
  56573. {
  56574. setVisible (false);
  56575. ddt = findTarget (e.getScreenX(),
  56576. e.getScreenY(),
  56577. relX, relY);
  56578. // fade this component and remove it - it'll be deleted later by the timer callback
  56579. dropAccepted = ddt != 0;
  56580. setVisible (true);
  56581. if (dropAccepted || sourceWatcher->hasBeenDeleted())
  56582. {
  56583. fadeOutComponent (120);
  56584. }
  56585. else
  56586. {
  56587. int targetX = source->getWidth() / 2;
  56588. int targetY = source->getHeight() / 2;
  56589. source->relativePositionToGlobal (targetX, targetY);
  56590. int ourCentreX = getWidth() / 2;
  56591. int ourCentreY = getHeight() / 2;
  56592. relativePositionToGlobal (ourCentreX, ourCentreY);
  56593. fadeOutComponent (120,
  56594. targetX - ourCentreX,
  56595. targetY - ourCentreY);
  56596. }
  56597. }
  56598. if (getParentComponent() != 0)
  56599. getParentComponent()->removeChildComponent (this);
  56600. if (dropAccepted && ddt != 0)
  56601. {
  56602. // (note: use a local copy of the dragDesc member in case the callback runs
  56603. // a modal loop and deletes this object before the method completes)
  56604. const String dragDescLocal (dragDesc);
  56605. currentlyOverWatcher = 0;
  56606. currentlyOver = 0;
  56607. ddt->itemDropped (dragDescLocal, source, relX, relY);
  56608. }
  56609. // careful - this object could now be deleted..
  56610. }
  56611. }
  56612. void updateLocation (const bool canDoExternalDrag, int x, int y)
  56613. {
  56614. // (note: use a local copy of the dragDesc member in case the callback runs
  56615. // a modal loop and deletes this object before it returns)
  56616. const String dragDescLocal (dragDesc);
  56617. int newX = x + imageX;
  56618. int newY = y + imageY;
  56619. if (getParentComponent() != 0)
  56620. getParentComponent()->globalPositionToRelative (newX, newY);
  56621. //if (newX != getX() || newY != getY())
  56622. {
  56623. setTopLeftPosition (newX, newY);
  56624. int relX = 0, relY = 0;
  56625. DragAndDropTarget* const ddt = findTarget (x, y, relX, relY);
  56626. drawImage = (ddt == 0) || ddt->shouldDrawDragImageWhenOver();
  56627. if (ddt != currentlyOver)
  56628. {
  56629. if (currentlyOverWatcher != 0 && ! currentlyOverWatcher->hasBeenDeleted())
  56630. {
  56631. Component* const over = dynamic_cast <Component*> (currentlyOver);
  56632. if (over != 0
  56633. && over->isValidComponent()
  56634. && ! (sourceWatcher->hasBeenDeleted())
  56635. && currentlyOver->isInterestedInDragSource (dragDescLocal, source))
  56636. {
  56637. currentlyOver->itemDragExit (dragDescLocal, source);
  56638. }
  56639. }
  56640. currentlyOver = ddt;
  56641. currentlyOverWatcher = 0;
  56642. if (ddt != 0)
  56643. {
  56644. currentlyOverWatcher = new ComponentDeletionWatcher (dynamic_cast <Component*> (ddt));
  56645. if (currentlyOver->isInterestedInDragSource (dragDescLocal, source))
  56646. currentlyOver->itemDragEnter (dragDescLocal, source, relX, relY);
  56647. }
  56648. }
  56649. else if (currentlyOverWatcher != 0 && currentlyOverWatcher->hasBeenDeleted())
  56650. {
  56651. currentlyOver = 0;
  56652. currentlyOverWatcher = 0;
  56653. }
  56654. if (currentlyOver != 0
  56655. && currentlyOver->isInterestedInDragSource (dragDescLocal, source))
  56656. currentlyOver->itemDragMove (dragDescLocal, source, relX, relY);
  56657. if (currentlyOver == 0
  56658. && canDoExternalDrag
  56659. && ! hasCheckedForExternalDrag)
  56660. {
  56661. if (Desktop::getInstance().findComponentAt (x, y) == 0)
  56662. {
  56663. hasCheckedForExternalDrag = true;
  56664. StringArray files;
  56665. bool canMoveFiles = false;
  56666. if (owner->shouldDropFilesWhenDraggedExternally (dragDescLocal, source, files, canMoveFiles)
  56667. && files.size() > 0)
  56668. {
  56669. ComponentDeletionWatcher cdw (this);
  56670. setVisible (false);
  56671. if (ModifierKeys::getCurrentModifiersRealtime().isAnyMouseButtonDown())
  56672. DragAndDropContainer::performExternalDragDropOfFiles (files, canMoveFiles);
  56673. if (! cdw.hasBeenDeleted())
  56674. delete this;
  56675. return;
  56676. }
  56677. }
  56678. }
  56679. }
  56680. }
  56681. void mouseDrag (const MouseEvent& e)
  56682. {
  56683. if (e.originalComponent != this)
  56684. updateLocation (true, e.getScreenX(), e.getScreenY());
  56685. }
  56686. void timerCallback()
  56687. {
  56688. if (sourceWatcher->hasBeenDeleted())
  56689. {
  56690. delete this;
  56691. }
  56692. else if (! isMouseButtonDownAnywhere())
  56693. {
  56694. if (! mouseDragSourceWatcher->hasBeenDeleted())
  56695. mouseDragSource->removeMouseListener (this);
  56696. delete this;
  56697. }
  56698. }
  56699. };
  56700. DragAndDropContainer::DragAndDropContainer()
  56701. {
  56702. }
  56703. DragAndDropContainer::~DragAndDropContainer()
  56704. {
  56705. dragImageComponent = 0;
  56706. }
  56707. void DragAndDropContainer::startDragging (const String& sourceDescription,
  56708. Component* sourceComponent,
  56709. Image* dragImage_,
  56710. const bool allowDraggingToExternalWindows,
  56711. const Point<int>* imageOffsetFromMouse)
  56712. {
  56713. ScopedPointer <Image> dragImage (dragImage_);
  56714. if (dragImageComponent == 0)
  56715. {
  56716. Component* const thisComp = dynamic_cast <Component*> (this);
  56717. if (thisComp != 0)
  56718. {
  56719. int mx, my;
  56720. Desktop::getLastMouseDownPosition (mx, my);
  56721. int imageX = 0, imageY = 0;
  56722. if (dragImage == 0)
  56723. {
  56724. dragImage = sourceComponent->createComponentSnapshot (Rectangle<int> (0, 0, sourceComponent->getWidth(), sourceComponent->getHeight()));
  56725. if (dragImage->getFormat() != Image::ARGB)
  56726. {
  56727. Image* newIm = Image::createNativeImage (Image::ARGB, dragImage->getWidth(), dragImage->getHeight(), true);
  56728. Graphics g2 (*newIm);
  56729. g2.drawImageAt (dragImage, 0, 0);
  56730. dragImage = newIm;
  56731. }
  56732. dragImage->multiplyAllAlphas (0.6f);
  56733. const int lo = 150;
  56734. const int hi = 400;
  56735. int rx = mx, ry = my;
  56736. sourceComponent->globalPositionToRelative (rx, ry);
  56737. const int cx = jlimit (0, dragImage->getWidth(), rx);
  56738. const int cy = jlimit (0, dragImage->getHeight(), ry);
  56739. for (int y = dragImage->getHeight(); --y >= 0;)
  56740. {
  56741. const double dy = (y - cy) * (y - cy);
  56742. for (int x = dragImage->getWidth(); --x >= 0;)
  56743. {
  56744. const int dx = x - cx;
  56745. const int distance = roundToInt (sqrt (dx * dx + dy));
  56746. if (distance > lo)
  56747. {
  56748. const float alpha = (distance > hi) ? 0
  56749. : (hi - distance) / (float) (hi - lo)
  56750. + Random::getSystemRandom().nextFloat() * 0.008f;
  56751. dragImage->multiplyAlphaAt (x, y, alpha);
  56752. }
  56753. }
  56754. }
  56755. imageX = -cx;
  56756. imageY = -cy;
  56757. }
  56758. else
  56759. {
  56760. if (imageOffsetFromMouse == 0)
  56761. {
  56762. imageX = dragImage->getWidth() / -2;
  56763. imageY = dragImage->getHeight() / -2;
  56764. }
  56765. else
  56766. {
  56767. imageX = imageOffsetFromMouse->getX();
  56768. imageY = imageOffsetFromMouse->getY();
  56769. }
  56770. }
  56771. dragImageComponent = new DragImageComponent (dragImage.release(), sourceDescription, sourceComponent,
  56772. this, imageX, imageY);
  56773. currentDragDesc = sourceDescription;
  56774. if (allowDraggingToExternalWindows)
  56775. {
  56776. if (! Desktop::canUseSemiTransparentWindows())
  56777. dragImageComponent->setOpaque (true);
  56778. dragImageComponent->addToDesktop (ComponentPeer::windowIgnoresMouseClicks
  56779. | ComponentPeer::windowIsTemporary
  56780. | ComponentPeer::windowIgnoresKeyPresses);
  56781. }
  56782. else
  56783. thisComp->addChildComponent (dragImageComponent);
  56784. ((DragImageComponent*) dragImageComponent)->updateLocation (false, mx, my);
  56785. dragImageComponent->setVisible (true);
  56786. }
  56787. else
  56788. {
  56789. // this class must only be implemented by an object that
  56790. // is also a Component.
  56791. jassertfalse
  56792. }
  56793. }
  56794. }
  56795. bool DragAndDropContainer::isDragAndDropActive() const
  56796. {
  56797. return dragImageComponent != 0;
  56798. }
  56799. const String DragAndDropContainer::getCurrentDragDescription() const
  56800. {
  56801. return (dragImageComponent != 0) ? currentDragDesc
  56802. : String::empty;
  56803. }
  56804. DragAndDropContainer* DragAndDropContainer::findParentDragContainerFor (Component* c)
  56805. {
  56806. if (c == 0)
  56807. return 0;
  56808. // (unable to use the syntax findParentComponentOfClass <DragAndDropContainer> () because of a VC6 compiler bug)
  56809. return c->findParentComponentOfClass ((DragAndDropContainer*) 0);
  56810. }
  56811. bool DragAndDropContainer::shouldDropFilesWhenDraggedExternally (const String&, Component*, StringArray&, bool&)
  56812. {
  56813. return false;
  56814. }
  56815. void DragAndDropTarget::itemDragEnter (const String&, Component*, int, int)
  56816. {
  56817. }
  56818. void DragAndDropTarget::itemDragMove (const String&, Component*, int, int)
  56819. {
  56820. }
  56821. void DragAndDropTarget::itemDragExit (const String&, Component*)
  56822. {
  56823. }
  56824. bool DragAndDropTarget::shouldDrawDragImageWhenOver()
  56825. {
  56826. return true;
  56827. }
  56828. void FileDragAndDropTarget::fileDragEnter (const StringArray&, int, int)
  56829. {
  56830. }
  56831. void FileDragAndDropTarget::fileDragMove (const StringArray&, int, int)
  56832. {
  56833. }
  56834. void FileDragAndDropTarget::fileDragExit (const StringArray&)
  56835. {
  56836. }
  56837. END_JUCE_NAMESPACE
  56838. /*** End of inlined file: juce_DragAndDropContainer.cpp ***/
  56839. /*** Start of inlined file: juce_MouseCursor.cpp ***/
  56840. BEGIN_JUCE_NAMESPACE
  56841. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw();
  56842. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw();
  56843. // isStandard set depending on which interface was used to create the cursor
  56844. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw();
  56845. static CriticalSection activeCursorListLock;
  56846. static VoidArray activeCursors;
  56847. class SharedMouseCursorInternal : public ReferenceCountedObject
  56848. {
  56849. public:
  56850. SharedMouseCursorInternal (const MouseCursor::StandardCursorType type) throw()
  56851. : standardType (type),
  56852. isStandard (true)
  56853. {
  56854. handle = juce_createStandardMouseCursor (standardType);
  56855. activeCursors.add (this);
  56856. }
  56857. SharedMouseCursorInternal (const Image& image, const int hotSpotX, const int hotSpotY) throw()
  56858. : standardType (MouseCursor::NormalCursor),
  56859. isStandard (false)
  56860. {
  56861. handle = juce_createMouseCursorFromImage (image, hotSpotX, hotSpotY);
  56862. }
  56863. ~SharedMouseCursorInternal() throw()
  56864. {
  56865. juce_deleteMouseCursor (handle, isStandard);
  56866. activeCursors.removeValue (this);
  56867. }
  56868. void* getHandle() const throw()
  56869. {
  56870. return handle;
  56871. }
  56872. static SharedMouseCursorInternal* findInstance (MouseCursor::StandardCursorType type) throw()
  56873. {
  56874. for (int i = activeCursors.size(); --i >= 0;)
  56875. {
  56876. SharedMouseCursorInternal* const r = (SharedMouseCursorInternal*) activeCursors.getUnchecked(i);
  56877. if (r->standardType == type)
  56878. return r;
  56879. }
  56880. return new SharedMouseCursorInternal (type);
  56881. }
  56882. juce_UseDebuggingNewOperator
  56883. private:
  56884. void* handle;
  56885. const MouseCursor::StandardCursorType standardType;
  56886. const bool isStandard;
  56887. const SharedMouseCursorInternal& operator= (const SharedMouseCursorInternal&);
  56888. };
  56889. MouseCursor::MouseCursor() throw()
  56890. {
  56891. const ScopedLock sl (activeCursorListLock);
  56892. cursorHandle = SharedMouseCursorInternal::findInstance (NormalCursor);
  56893. }
  56894. MouseCursor::MouseCursor (const StandardCursorType type) throw()
  56895. {
  56896. const ScopedLock sl (activeCursorListLock);
  56897. cursorHandle = SharedMouseCursorInternal::findInstance (type);
  56898. }
  56899. MouseCursor::MouseCursor (const Image& image, const int hotSpotX, const int hotSpotY) throw()
  56900. {
  56901. const ScopedLock sl (activeCursorListLock);
  56902. cursorHandle = new SharedMouseCursorInternal (image, hotSpotX, hotSpotY);
  56903. }
  56904. MouseCursor::MouseCursor (const MouseCursor& other) throw()
  56905. : cursorHandle (other.cursorHandle)
  56906. {
  56907. }
  56908. MouseCursor::~MouseCursor() throw()
  56909. {
  56910. }
  56911. const MouseCursor& MouseCursor::operator= (const MouseCursor& other) throw()
  56912. {
  56913. cursorHandle = other.cursorHandle;
  56914. return *this;
  56915. }
  56916. bool MouseCursor::operator== (const MouseCursor& other) const throw()
  56917. {
  56918. return cursorHandle == other.cursorHandle;
  56919. }
  56920. bool MouseCursor::operator!= (const MouseCursor& other) const throw()
  56921. {
  56922. return cursorHandle != other.cursorHandle;
  56923. }
  56924. void* MouseCursor::getHandle() const throw()
  56925. {
  56926. return cursorHandle->getHandle();
  56927. }
  56928. void MouseCursor::showWaitCursor() throw()
  56929. {
  56930. const MouseCursor mc (MouseCursor::WaitCursor);
  56931. mc.showInAllWindows();
  56932. }
  56933. void MouseCursor::hideWaitCursor() throw()
  56934. {
  56935. Component* const c = Component::getComponentUnderMouse();
  56936. MouseCursor mc (c->isValidComponent() ? c->getLookAndFeel().getMouseCursorFor (*c)
  56937. : MouseCursor::NormalCursor);
  56938. mc.showInAllWindows();
  56939. }
  56940. END_JUCE_NAMESPACE
  56941. /*** End of inlined file: juce_MouseCursor.cpp ***/
  56942. /*** Start of inlined file: juce_MouseEvent.cpp ***/
  56943. BEGIN_JUCE_NAMESPACE
  56944. MouseEvent::MouseEvent (const int x_,
  56945. const int y_,
  56946. const ModifierKeys& mods_,
  56947. Component* const originator,
  56948. const Time& eventTime_,
  56949. const int mouseDownX_,
  56950. const int mouseDownY_,
  56951. const Time& mouseDownTime_,
  56952. const int numberOfClicks_,
  56953. const bool mouseWasDragged) throw()
  56954. : x (x_),
  56955. y (y_),
  56956. mods (mods_),
  56957. eventComponent (originator),
  56958. originalComponent (originator),
  56959. eventTime (eventTime_),
  56960. mouseDownX (mouseDownX_),
  56961. mouseDownY (mouseDownY_),
  56962. mouseDownTime (mouseDownTime_),
  56963. numberOfClicks (numberOfClicks_),
  56964. wasMovedSinceMouseDown (mouseWasDragged)
  56965. {
  56966. }
  56967. MouseEvent::~MouseEvent() throw()
  56968. {
  56969. }
  56970. bool MouseEvent::mouseWasClicked() const throw()
  56971. {
  56972. return ! wasMovedSinceMouseDown;
  56973. }
  56974. int MouseEvent::getMouseDownX() const throw()
  56975. {
  56976. return mouseDownX;
  56977. }
  56978. int MouseEvent::getMouseDownY() const throw()
  56979. {
  56980. return mouseDownY;
  56981. }
  56982. int MouseEvent::getDistanceFromDragStartX() const throw()
  56983. {
  56984. return x - mouseDownX;
  56985. }
  56986. int MouseEvent::getDistanceFromDragStartY() const throw()
  56987. {
  56988. return y - mouseDownY;
  56989. }
  56990. int MouseEvent::getDistanceFromDragStart() const throw()
  56991. {
  56992. return roundToInt (juce_hypot (getDistanceFromDragStartX(),
  56993. getDistanceFromDragStartY()));
  56994. }
  56995. int MouseEvent::getLengthOfMousePress() const throw()
  56996. {
  56997. if (mouseDownTime.toMilliseconds() > 0)
  56998. return jmax (0, (int) (eventTime - mouseDownTime).inMilliseconds());
  56999. return 0;
  57000. }
  57001. int MouseEvent::getScreenX() const throw()
  57002. {
  57003. int sx = x, sy = y;
  57004. eventComponent->relativePositionToGlobal (sx, sy);
  57005. return sx;
  57006. }
  57007. int MouseEvent::getScreenY() const throw()
  57008. {
  57009. int sx = x, sy = y;
  57010. eventComponent->relativePositionToGlobal (sx, sy);
  57011. return sy;
  57012. }
  57013. int MouseEvent::getMouseDownScreenX() const throw()
  57014. {
  57015. int sx = mouseDownX, sy = mouseDownY;
  57016. eventComponent->relativePositionToGlobal (sx, sy);
  57017. return sx;
  57018. }
  57019. int MouseEvent::getMouseDownScreenY() const throw()
  57020. {
  57021. int sx = mouseDownX, sy = mouseDownY;
  57022. eventComponent->relativePositionToGlobal (sx, sy);
  57023. return sy;
  57024. }
  57025. const MouseEvent MouseEvent::getEventRelativeTo (Component* const otherComponent) const throw()
  57026. {
  57027. if (otherComponent == 0)
  57028. {
  57029. jassertfalse
  57030. return *this;
  57031. }
  57032. MouseEvent me (*this);
  57033. eventComponent->relativePositionToOtherComponent (otherComponent, me.x, me.y);
  57034. eventComponent->relativePositionToOtherComponent (otherComponent, me.mouseDownX, me.mouseDownY);
  57035. me.eventComponent = otherComponent;
  57036. return me;
  57037. }
  57038. static int doubleClickTimeOutMs = 400;
  57039. void MouseEvent::setDoubleClickTimeout (const int newTime) throw()
  57040. {
  57041. doubleClickTimeOutMs = newTime;
  57042. }
  57043. int MouseEvent::getDoubleClickTimeout() throw()
  57044. {
  57045. return doubleClickTimeOutMs;
  57046. }
  57047. END_JUCE_NAMESPACE
  57048. /*** End of inlined file: juce_MouseEvent.cpp ***/
  57049. /*** Start of inlined file: juce_MouseHoverDetector.cpp ***/
  57050. BEGIN_JUCE_NAMESPACE
  57051. MouseHoverDetector::MouseHoverDetector (const int hoverTimeMillisecs_)
  57052. : source (0),
  57053. hoverTimeMillisecs (hoverTimeMillisecs_),
  57054. hasJustHovered (false)
  57055. {
  57056. internalTimer.owner = this;
  57057. }
  57058. MouseHoverDetector::~MouseHoverDetector()
  57059. {
  57060. setHoverComponent (0);
  57061. }
  57062. void MouseHoverDetector::setHoverTimeMillisecs (const int newTimeInMillisecs)
  57063. {
  57064. hoverTimeMillisecs = newTimeInMillisecs;
  57065. }
  57066. void MouseHoverDetector::setHoverComponent (Component* const newSourceComponent)
  57067. {
  57068. if (source != newSourceComponent)
  57069. {
  57070. internalTimer.stopTimer();
  57071. hasJustHovered = false;
  57072. if (source != 0)
  57073. {
  57074. // ! you need to delete the hover detector before deleting its component
  57075. jassert (source->isValidComponent());
  57076. source->removeMouseListener (&internalTimer);
  57077. }
  57078. source = newSourceComponent;
  57079. if (newSourceComponent != 0)
  57080. newSourceComponent->addMouseListener (&internalTimer, false);
  57081. }
  57082. }
  57083. void MouseHoverDetector::hoverTimerCallback()
  57084. {
  57085. internalTimer.stopTimer();
  57086. if (source != 0)
  57087. {
  57088. int mx, my;
  57089. source->getMouseXYRelative (mx, my);
  57090. if (source->reallyContains (mx, my, false))
  57091. {
  57092. hasJustHovered = true;
  57093. mouseHovered (mx, my);
  57094. }
  57095. }
  57096. }
  57097. void MouseHoverDetector::checkJustHoveredCallback()
  57098. {
  57099. if (hasJustHovered)
  57100. {
  57101. hasJustHovered = false;
  57102. mouseMovedAfterHover();
  57103. }
  57104. }
  57105. void MouseHoverDetector::HoverDetectorInternal::timerCallback()
  57106. {
  57107. owner->hoverTimerCallback();
  57108. }
  57109. void MouseHoverDetector::HoverDetectorInternal::mouseEnter (const MouseEvent&)
  57110. {
  57111. stopTimer();
  57112. owner->checkJustHoveredCallback();
  57113. }
  57114. void MouseHoverDetector::HoverDetectorInternal::mouseExit (const MouseEvent&)
  57115. {
  57116. stopTimer();
  57117. owner->checkJustHoveredCallback();
  57118. }
  57119. void MouseHoverDetector::HoverDetectorInternal::mouseDown (const MouseEvent&)
  57120. {
  57121. stopTimer();
  57122. owner->checkJustHoveredCallback();
  57123. }
  57124. void MouseHoverDetector::HoverDetectorInternal::mouseUp (const MouseEvent&)
  57125. {
  57126. stopTimer();
  57127. owner->checkJustHoveredCallback();
  57128. }
  57129. void MouseHoverDetector::HoverDetectorInternal::mouseMove (const MouseEvent& e)
  57130. {
  57131. if (lastX != e.x || lastY != e.y) // to avoid fake mouse-moves setting it off
  57132. {
  57133. lastX = e.x;
  57134. lastY = e.y;
  57135. if (owner->source != 0)
  57136. startTimer (owner->hoverTimeMillisecs);
  57137. owner->checkJustHoveredCallback();
  57138. }
  57139. }
  57140. void MouseHoverDetector::HoverDetectorInternal::mouseWheelMove (const MouseEvent&, float, float)
  57141. {
  57142. stopTimer();
  57143. owner->checkJustHoveredCallback();
  57144. }
  57145. END_JUCE_NAMESPACE
  57146. /*** End of inlined file: juce_MouseHoverDetector.cpp ***/
  57147. /*** Start of inlined file: juce_MouseListener.cpp ***/
  57148. BEGIN_JUCE_NAMESPACE
  57149. void MouseListener::mouseEnter (const MouseEvent&)
  57150. {
  57151. }
  57152. void MouseListener::mouseExit (const MouseEvent&)
  57153. {
  57154. }
  57155. void MouseListener::mouseDown (const MouseEvent&)
  57156. {
  57157. }
  57158. void MouseListener::mouseUp (const MouseEvent&)
  57159. {
  57160. }
  57161. void MouseListener::mouseDrag (const MouseEvent&)
  57162. {
  57163. }
  57164. void MouseListener::mouseMove (const MouseEvent&)
  57165. {
  57166. }
  57167. void MouseListener::mouseDoubleClick (const MouseEvent&)
  57168. {
  57169. }
  57170. void MouseListener::mouseWheelMove (const MouseEvent&, float, float)
  57171. {
  57172. }
  57173. END_JUCE_NAMESPACE
  57174. /*** End of inlined file: juce_MouseListener.cpp ***/
  57175. /*** Start of inlined file: juce_BooleanPropertyComponent.cpp ***/
  57176. BEGIN_JUCE_NAMESPACE
  57177. BooleanPropertyComponent::BooleanPropertyComponent (const String& name,
  57178. const String& buttonTextWhenTrue,
  57179. const String& buttonTextWhenFalse)
  57180. : PropertyComponent (name),
  57181. onText (buttonTextWhenTrue),
  57182. offText (buttonTextWhenFalse)
  57183. {
  57184. createButton();
  57185. button->addButtonListener (this);
  57186. }
  57187. BooleanPropertyComponent::BooleanPropertyComponent (const Value& valueToControl,
  57188. const String& name,
  57189. const String& buttonText)
  57190. : PropertyComponent (name),
  57191. onText (buttonText),
  57192. offText (buttonText)
  57193. {
  57194. createButton();
  57195. button->setButtonText (buttonText);
  57196. button->getToggleStateValue().referTo (valueToControl);
  57197. button->setClickingTogglesState (true);
  57198. }
  57199. BooleanPropertyComponent::~BooleanPropertyComponent()
  57200. {
  57201. deleteAllChildren();
  57202. }
  57203. void BooleanPropertyComponent::createButton()
  57204. {
  57205. addAndMakeVisible (button = new ToggleButton (String::empty));
  57206. button->setClickingTogglesState (false);
  57207. }
  57208. void BooleanPropertyComponent::setState (const bool newState)
  57209. {
  57210. button->setToggleState (newState, true);
  57211. }
  57212. bool BooleanPropertyComponent::getState() const
  57213. {
  57214. return button->getToggleState();
  57215. }
  57216. void BooleanPropertyComponent::paint (Graphics& g)
  57217. {
  57218. PropertyComponent::paint (g);
  57219. const Rectangle<int> r (button->getBounds());
  57220. g.setColour (Colours::white);
  57221. g.fillRect (r);
  57222. g.setColour (findColour (ComboBox::outlineColourId));
  57223. g.drawRect (r.getX(), r.getY(), r.getWidth(), r.getHeight());
  57224. }
  57225. void BooleanPropertyComponent::refresh()
  57226. {
  57227. button->setToggleState (getState(), false);
  57228. button->setButtonText (button->getToggleState() ? onText : offText);
  57229. }
  57230. void BooleanPropertyComponent::buttonClicked (Button*)
  57231. {
  57232. setState (! getState());
  57233. }
  57234. END_JUCE_NAMESPACE
  57235. /*** End of inlined file: juce_BooleanPropertyComponent.cpp ***/
  57236. /*** Start of inlined file: juce_ButtonPropertyComponent.cpp ***/
  57237. BEGIN_JUCE_NAMESPACE
  57238. ButtonPropertyComponent::ButtonPropertyComponent (const String& name,
  57239. const bool triggerOnMouseDown)
  57240. : PropertyComponent (name)
  57241. {
  57242. addAndMakeVisible (button = new TextButton (String::empty));
  57243. button->setTriggeredOnMouseDown (triggerOnMouseDown);
  57244. button->addButtonListener (this);
  57245. }
  57246. ButtonPropertyComponent::~ButtonPropertyComponent()
  57247. {
  57248. deleteAllChildren();
  57249. }
  57250. void ButtonPropertyComponent::refresh()
  57251. {
  57252. button->setButtonText (getButtonText());
  57253. }
  57254. void ButtonPropertyComponent::buttonClicked (Button*)
  57255. {
  57256. buttonClicked();
  57257. }
  57258. END_JUCE_NAMESPACE
  57259. /*** End of inlined file: juce_ButtonPropertyComponent.cpp ***/
  57260. /*** Start of inlined file: juce_ChoicePropertyComponent.cpp ***/
  57261. BEGIN_JUCE_NAMESPACE
  57262. ChoicePropertyComponent::ChoicePropertyComponent (const String& name)
  57263. : PropertyComponent (name),
  57264. comboBox (0)
  57265. {
  57266. }
  57267. ChoicePropertyComponent::ChoicePropertyComponent (const Value& valueToControl,
  57268. const String& name,
  57269. const StringArray& choices_,
  57270. const Array <int>* choiceIDs)
  57271. : PropertyComponent (name),
  57272. choices (choices_),
  57273. comboBox (0)
  57274. {
  57275. createComboBox (choiceIDs);
  57276. comboBox->getSelectedIdAsValue().referTo (valueToControl);
  57277. }
  57278. ChoicePropertyComponent::~ChoicePropertyComponent()
  57279. {
  57280. deleteAllChildren();
  57281. }
  57282. void ChoicePropertyComponent::createComboBox (const Array <int>* choiceIDs)
  57283. {
  57284. // The array of IDs must contain the same number of values as the choices list!
  57285. jassert (choiceIDs == 0 || choiceIDs->size() == choices.size());
  57286. addAndMakeVisible (comboBox = new ComboBox (String::empty));
  57287. for (int i = 0; i < choices.size(); ++i)
  57288. {
  57289. if (choices[i].isNotEmpty())
  57290. comboBox->addItem (choices[i], choiceIDs == 0 ? (i + 1)
  57291. : ((*choiceIDs)[i]));
  57292. else
  57293. comboBox->addSeparator();
  57294. }
  57295. comboBox->setEditableText (false);
  57296. }
  57297. void ChoicePropertyComponent::setIndex (const int newIndex)
  57298. {
  57299. comboBox->setSelectedId (comboBox->getItemId (newIndex));
  57300. }
  57301. int ChoicePropertyComponent::getIndex() const
  57302. {
  57303. return comboBox->getSelectedItemIndex();
  57304. }
  57305. const StringArray& ChoicePropertyComponent::getChoices() const
  57306. {
  57307. return choices;
  57308. }
  57309. void ChoicePropertyComponent::refresh()
  57310. {
  57311. if (comboBox == 0)
  57312. {
  57313. createComboBox (0);
  57314. comboBox->addListener (this);
  57315. }
  57316. comboBox->setSelectedId (getIndex() + 1, true);
  57317. }
  57318. void ChoicePropertyComponent::comboBoxChanged (ComboBox*)
  57319. {
  57320. const int newIndex = comboBox->getSelectedId() - 1;
  57321. if (newIndex != getIndex())
  57322. setIndex (newIndex);
  57323. }
  57324. END_JUCE_NAMESPACE
  57325. /*** End of inlined file: juce_ChoicePropertyComponent.cpp ***/
  57326. /*** Start of inlined file: juce_PropertyComponent.cpp ***/
  57327. BEGIN_JUCE_NAMESPACE
  57328. PropertyComponent::PropertyComponent (const String& name,
  57329. const int preferredHeight_)
  57330. : Component (name),
  57331. preferredHeight (preferredHeight_)
  57332. {
  57333. jassert (name.isNotEmpty());
  57334. }
  57335. PropertyComponent::~PropertyComponent()
  57336. {
  57337. }
  57338. void PropertyComponent::paint (Graphics& g)
  57339. {
  57340. getLookAndFeel().drawPropertyComponentBackground (g, getWidth(), getHeight(), *this);
  57341. getLookAndFeel().drawPropertyComponentLabel (g, getWidth(), getHeight(), *this);
  57342. }
  57343. void PropertyComponent::resized()
  57344. {
  57345. if (getNumChildComponents() > 0)
  57346. getChildComponent (0)->setBounds (getLookAndFeel().getPropertyComponentContentPosition (*this));
  57347. }
  57348. void PropertyComponent::enablementChanged()
  57349. {
  57350. repaint();
  57351. }
  57352. END_JUCE_NAMESPACE
  57353. /*** End of inlined file: juce_PropertyComponent.cpp ***/
  57354. /*** Start of inlined file: juce_PropertyPanel.cpp ***/
  57355. BEGIN_JUCE_NAMESPACE
  57356. class PropertyHolderComponent : public Component
  57357. {
  57358. public:
  57359. PropertyHolderComponent()
  57360. {
  57361. }
  57362. ~PropertyHolderComponent()
  57363. {
  57364. deleteAllChildren();
  57365. }
  57366. void paint (Graphics&)
  57367. {
  57368. }
  57369. void updateLayout (const int width);
  57370. void refreshAll() const;
  57371. };
  57372. class PropertySectionComponent : public Component
  57373. {
  57374. public:
  57375. PropertySectionComponent (const String& sectionTitle,
  57376. const Array <PropertyComponent*>& newProperties,
  57377. const bool open)
  57378. : Component (sectionTitle),
  57379. titleHeight (sectionTitle.isNotEmpty() ? 22 : 0),
  57380. isOpen_ (open)
  57381. {
  57382. for (int i = newProperties.size(); --i >= 0;)
  57383. {
  57384. addAndMakeVisible (newProperties.getUnchecked(i));
  57385. newProperties.getUnchecked(i)->refresh();
  57386. }
  57387. }
  57388. ~PropertySectionComponent()
  57389. {
  57390. deleteAllChildren();
  57391. }
  57392. void paint (Graphics& g)
  57393. {
  57394. if (titleHeight > 0)
  57395. getLookAndFeel().drawPropertyPanelSectionHeader (g, getName(), isOpen(), getWidth(), titleHeight);
  57396. }
  57397. void resized()
  57398. {
  57399. int y = titleHeight;
  57400. for (int i = getNumChildComponents(); --i >= 0;)
  57401. {
  57402. PropertyComponent* const pec = dynamic_cast <PropertyComponent*> (getChildComponent (i));
  57403. if (pec != 0)
  57404. {
  57405. const int prefH = pec->getPreferredHeight();
  57406. pec->setBounds (1, y, getWidth() - 2, prefH);
  57407. y += prefH;
  57408. }
  57409. }
  57410. }
  57411. int getPreferredHeight() const
  57412. {
  57413. int y = titleHeight;
  57414. if (isOpen())
  57415. {
  57416. for (int i = 0; i < getNumChildComponents(); ++i)
  57417. {
  57418. PropertyComponent* pec = dynamic_cast <PropertyComponent*> (getChildComponent (i));
  57419. if (pec != 0)
  57420. y += pec->getPreferredHeight();
  57421. }
  57422. }
  57423. return y;
  57424. }
  57425. void setOpen (const bool open)
  57426. {
  57427. if (isOpen_ != open)
  57428. {
  57429. isOpen_ = open;
  57430. for (int i = 0; i < getNumChildComponents(); ++i)
  57431. {
  57432. PropertyComponent* pec = dynamic_cast <PropertyComponent*> (getChildComponent (i));
  57433. if (pec != 0)
  57434. pec->setVisible (open);
  57435. }
  57436. // (unable to use the syntax findParentComponentOfClass <DragAndDropContainer> () because of a VC6 compiler bug)
  57437. PropertyPanel* const pp = findParentComponentOfClass ((PropertyPanel*) 0);
  57438. if (pp != 0)
  57439. pp->resized();
  57440. }
  57441. }
  57442. bool isOpen() const
  57443. {
  57444. return isOpen_;
  57445. }
  57446. void refreshAll() const
  57447. {
  57448. for (int i = 0; i < getNumChildComponents(); ++i)
  57449. {
  57450. PropertyComponent* pec = dynamic_cast <PropertyComponent*> (getChildComponent (i));
  57451. if (pec != 0)
  57452. pec->refresh();
  57453. }
  57454. }
  57455. void mouseDown (const MouseEvent&)
  57456. {
  57457. }
  57458. void mouseUp (const MouseEvent& e)
  57459. {
  57460. if (e.getMouseDownX() < titleHeight
  57461. && e.x < titleHeight
  57462. && e.y < titleHeight
  57463. && e.getNumberOfClicks() != 2)
  57464. {
  57465. setOpen (! isOpen());
  57466. }
  57467. }
  57468. void mouseDoubleClick (const MouseEvent& e)
  57469. {
  57470. if (e.y < titleHeight)
  57471. setOpen (! isOpen());
  57472. }
  57473. private:
  57474. int titleHeight;
  57475. bool isOpen_;
  57476. };
  57477. void PropertyHolderComponent::updateLayout (const int width)
  57478. {
  57479. int y = 0;
  57480. for (int i = getNumChildComponents(); --i >= 0;)
  57481. {
  57482. PropertySectionComponent* const section
  57483. = dynamic_cast <PropertySectionComponent*> (getChildComponent (i));
  57484. if (section != 0)
  57485. {
  57486. const int prefH = section->getPreferredHeight();
  57487. section->setBounds (0, y, width, prefH);
  57488. y += prefH;
  57489. }
  57490. }
  57491. setSize (width, y);
  57492. repaint();
  57493. }
  57494. void PropertyHolderComponent::refreshAll() const
  57495. {
  57496. for (int i = getNumChildComponents(); --i >= 0;)
  57497. {
  57498. PropertySectionComponent* const section
  57499. = dynamic_cast <PropertySectionComponent*> (getChildComponent (i));
  57500. if (section != 0)
  57501. section->refreshAll();
  57502. }
  57503. }
  57504. PropertyPanel::PropertyPanel()
  57505. {
  57506. messageWhenEmpty = TRANS("(nothing selected)");
  57507. addAndMakeVisible (viewport = new Viewport());
  57508. viewport->setViewedComponent (propertyHolderComponent = new PropertyHolderComponent());
  57509. viewport->setFocusContainer (true);
  57510. }
  57511. PropertyPanel::~PropertyPanel()
  57512. {
  57513. clear();
  57514. deleteAllChildren();
  57515. }
  57516. void PropertyPanel::paint (Graphics& g)
  57517. {
  57518. if (propertyHolderComponent->getNumChildComponents() == 0)
  57519. {
  57520. g.setColour (Colours::black.withAlpha (0.5f));
  57521. g.setFont (14.0f);
  57522. g.drawText (messageWhenEmpty, 0, 0, getWidth(), 30,
  57523. Justification::centred, true);
  57524. }
  57525. }
  57526. void PropertyPanel::resized()
  57527. {
  57528. viewport->setBounds (0, 0, getWidth(), getHeight());
  57529. updatePropHolderLayout();
  57530. }
  57531. void PropertyPanel::clear()
  57532. {
  57533. if (propertyHolderComponent->getNumChildComponents() > 0)
  57534. {
  57535. propertyHolderComponent->deleteAllChildren();
  57536. repaint();
  57537. }
  57538. }
  57539. void PropertyPanel::addProperties (const Array <PropertyComponent*>& newProperties)
  57540. {
  57541. if (propertyHolderComponent->getNumChildComponents() == 0)
  57542. repaint();
  57543. propertyHolderComponent->addAndMakeVisible (new PropertySectionComponent (String::empty,
  57544. newProperties,
  57545. true), 0);
  57546. updatePropHolderLayout();
  57547. }
  57548. void PropertyPanel::addSection (const String& sectionTitle,
  57549. const Array <PropertyComponent*>& newProperties,
  57550. const bool shouldBeOpen)
  57551. {
  57552. jassert (sectionTitle.isNotEmpty());
  57553. if (propertyHolderComponent->getNumChildComponents() == 0)
  57554. repaint();
  57555. propertyHolderComponent->addAndMakeVisible (new PropertySectionComponent (sectionTitle,
  57556. newProperties,
  57557. shouldBeOpen), 0);
  57558. updatePropHolderLayout();
  57559. }
  57560. void PropertyPanel::updatePropHolderLayout() const
  57561. {
  57562. const int maxWidth = viewport->getMaximumVisibleWidth();
  57563. ((PropertyHolderComponent*) propertyHolderComponent)->updateLayout (maxWidth);
  57564. const int newMaxWidth = viewport->getMaximumVisibleWidth();
  57565. if (maxWidth != newMaxWidth)
  57566. {
  57567. // need to do this twice because of scrollbars changing the size, etc.
  57568. ((PropertyHolderComponent*) propertyHolderComponent)->updateLayout (newMaxWidth);
  57569. }
  57570. }
  57571. void PropertyPanel::refreshAll() const
  57572. {
  57573. ((PropertyHolderComponent*) propertyHolderComponent)->refreshAll();
  57574. }
  57575. const StringArray PropertyPanel::getSectionNames() const
  57576. {
  57577. StringArray s;
  57578. for (int i = 0; i < propertyHolderComponent->getNumChildComponents(); ++i)
  57579. {
  57580. PropertySectionComponent* const section = dynamic_cast <PropertySectionComponent*> (propertyHolderComponent->getChildComponent (i));
  57581. if (section != 0 && section->getName().isNotEmpty())
  57582. s.add (section->getName());
  57583. }
  57584. return s;
  57585. }
  57586. bool PropertyPanel::isSectionOpen (const int sectionIndex) const
  57587. {
  57588. int index = 0;
  57589. for (int i = 0; i < propertyHolderComponent->getNumChildComponents(); ++i)
  57590. {
  57591. PropertySectionComponent* const section = dynamic_cast <PropertySectionComponent*> (propertyHolderComponent->getChildComponent (i));
  57592. if (section != 0 && section->getName().isNotEmpty())
  57593. {
  57594. if (index == sectionIndex)
  57595. return section->isOpen();
  57596. ++index;
  57597. }
  57598. }
  57599. return false;
  57600. }
  57601. void PropertyPanel::setSectionOpen (const int sectionIndex, const bool shouldBeOpen)
  57602. {
  57603. int index = 0;
  57604. for (int i = 0; i < propertyHolderComponent->getNumChildComponents(); ++i)
  57605. {
  57606. PropertySectionComponent* const section = dynamic_cast <PropertySectionComponent*> (propertyHolderComponent->getChildComponent (i));
  57607. if (section != 0 && section->getName().isNotEmpty())
  57608. {
  57609. if (index == sectionIndex)
  57610. {
  57611. section->setOpen (shouldBeOpen);
  57612. break;
  57613. }
  57614. ++index;
  57615. }
  57616. }
  57617. }
  57618. void PropertyPanel::setSectionEnabled (const int sectionIndex, const bool shouldBeEnabled)
  57619. {
  57620. int index = 0;
  57621. for (int i = 0; i < propertyHolderComponent->getNumChildComponents(); ++i)
  57622. {
  57623. PropertySectionComponent* const section = dynamic_cast <PropertySectionComponent*> (propertyHolderComponent->getChildComponent (i));
  57624. if (section != 0 && section->getName().isNotEmpty())
  57625. {
  57626. if (index == sectionIndex)
  57627. {
  57628. section->setEnabled (shouldBeEnabled);
  57629. break;
  57630. }
  57631. ++index;
  57632. }
  57633. }
  57634. }
  57635. XmlElement* PropertyPanel::getOpennessState() const
  57636. {
  57637. XmlElement* const xml = new XmlElement (T("PROPERTYPANELSTATE"));
  57638. xml->setAttribute ("scrollPos", viewport->getViewPositionY());
  57639. const StringArray sections (getSectionNames());
  57640. for (int i = 0; i < sections.size(); ++i)
  57641. {
  57642. if (sections[i].isNotEmpty())
  57643. {
  57644. XmlElement* const e = xml->createNewChildElement ("SECTION");
  57645. e->setAttribute ("name", sections[i]);
  57646. e->setAttribute ("open", isSectionOpen (i) ? 1 : 0);
  57647. }
  57648. }
  57649. return xml;
  57650. }
  57651. void PropertyPanel::restoreOpennessState (const XmlElement& xml)
  57652. {
  57653. if (xml.hasTagName (T("PROPERTYPANELSTATE")))
  57654. {
  57655. const StringArray sections (getSectionNames());
  57656. forEachXmlChildElementWithTagName (xml, e, T("SECTION"))
  57657. {
  57658. setSectionOpen (sections.indexOf (e->getStringAttribute (T("name"))),
  57659. e->getBoolAttribute (T("open")));
  57660. }
  57661. viewport->setViewPosition (viewport->getViewPositionX(),
  57662. xml.getIntAttribute ("scrollPos", viewport->getViewPositionY()));
  57663. }
  57664. }
  57665. void PropertyPanel::setMessageWhenEmpty (const String& newMessage)
  57666. {
  57667. if (messageWhenEmpty != newMessage)
  57668. {
  57669. messageWhenEmpty = newMessage;
  57670. repaint();
  57671. }
  57672. }
  57673. const String& PropertyPanel::getMessageWhenEmpty() const
  57674. {
  57675. return messageWhenEmpty;
  57676. }
  57677. END_JUCE_NAMESPACE
  57678. /*** End of inlined file: juce_PropertyPanel.cpp ***/
  57679. /*** Start of inlined file: juce_SliderPropertyComponent.cpp ***/
  57680. BEGIN_JUCE_NAMESPACE
  57681. SliderPropertyComponent::SliderPropertyComponent (const String& name,
  57682. const double rangeMin,
  57683. const double rangeMax,
  57684. const double interval,
  57685. const double skewFactor)
  57686. : PropertyComponent (name)
  57687. {
  57688. addAndMakeVisible (slider = new Slider (name));
  57689. slider->setRange (rangeMin, rangeMax, interval);
  57690. slider->setSkewFactor (skewFactor);
  57691. slider->setSliderStyle (Slider::LinearBar);
  57692. slider->addListener (this);
  57693. }
  57694. SliderPropertyComponent::SliderPropertyComponent (Value& valueToControl,
  57695. const String& name,
  57696. const double rangeMin,
  57697. const double rangeMax,
  57698. const double interval,
  57699. const double skewFactor)
  57700. : PropertyComponent (name)
  57701. {
  57702. addAndMakeVisible (slider = new Slider (name));
  57703. slider->setRange (rangeMin, rangeMax, interval);
  57704. slider->setSkewFactor (skewFactor);
  57705. slider->setSliderStyle (Slider::LinearBar);
  57706. slider->getValueObject().referTo (valueToControl);
  57707. }
  57708. SliderPropertyComponent::~SliderPropertyComponent()
  57709. {
  57710. deleteAllChildren();
  57711. }
  57712. void SliderPropertyComponent::setValue (const double /*newValue*/)
  57713. {
  57714. }
  57715. const double SliderPropertyComponent::getValue() const
  57716. {
  57717. return slider->getValue();
  57718. }
  57719. void SliderPropertyComponent::refresh()
  57720. {
  57721. slider->setValue (getValue(), false);
  57722. }
  57723. void SliderPropertyComponent::sliderValueChanged (Slider*)
  57724. {
  57725. if (getValue() != slider->getValue())
  57726. setValue (slider->getValue());
  57727. }
  57728. END_JUCE_NAMESPACE
  57729. /*** End of inlined file: juce_SliderPropertyComponent.cpp ***/
  57730. /*** Start of inlined file: juce_TextPropertyComponent.cpp ***/
  57731. BEGIN_JUCE_NAMESPACE
  57732. class TextPropLabel : public Label
  57733. {
  57734. TextPropertyComponent& owner;
  57735. int maxChars;
  57736. bool isMultiline;
  57737. public:
  57738. TextPropLabel (TextPropertyComponent& owner_,
  57739. const int maxChars_, const bool isMultiline_)
  57740. : Label (String::empty, String::empty),
  57741. owner (owner_),
  57742. maxChars (maxChars_),
  57743. isMultiline (isMultiline_)
  57744. {
  57745. setEditable (true, true, false);
  57746. setColour (backgroundColourId, Colours::white);
  57747. setColour (outlineColourId, findColour (ComboBox::outlineColourId));
  57748. }
  57749. ~TextPropLabel()
  57750. {
  57751. }
  57752. TextEditor* createEditorComponent()
  57753. {
  57754. TextEditor* const textEditor = Label::createEditorComponent();
  57755. textEditor->setInputRestrictions (maxChars);
  57756. if (isMultiline)
  57757. {
  57758. textEditor->setMultiLine (true, true);
  57759. textEditor->setReturnKeyStartsNewLine (true);
  57760. }
  57761. return textEditor;
  57762. }
  57763. void textWasEdited()
  57764. {
  57765. owner.textWasEdited();
  57766. }
  57767. };
  57768. TextPropertyComponent::TextPropertyComponent (const String& name,
  57769. const int maxNumChars,
  57770. const bool isMultiLine)
  57771. : PropertyComponent (name)
  57772. {
  57773. createEditor (maxNumChars, isMultiLine);
  57774. }
  57775. TextPropertyComponent::TextPropertyComponent (const Value& valueToControl,
  57776. const String& name,
  57777. const int maxNumChars,
  57778. const bool isMultiLine)
  57779. : PropertyComponent (name)
  57780. {
  57781. createEditor (maxNumChars, isMultiLine);
  57782. textEditor->getTextValue().referTo (valueToControl);
  57783. }
  57784. TextPropertyComponent::~TextPropertyComponent()
  57785. {
  57786. deleteAllChildren();
  57787. }
  57788. void TextPropertyComponent::setText (const String& newText)
  57789. {
  57790. textEditor->setText (newText, true);
  57791. }
  57792. const String TextPropertyComponent::getText() const
  57793. {
  57794. return textEditor->getText();
  57795. }
  57796. void TextPropertyComponent::createEditor (const int maxNumChars, const bool isMultiLine)
  57797. {
  57798. addAndMakeVisible (textEditor = new TextPropLabel (*this, maxNumChars, isMultiLine));
  57799. if (isMultiLine)
  57800. {
  57801. textEditor->setJustificationType (Justification::topLeft);
  57802. preferredHeight = 120;
  57803. }
  57804. }
  57805. void TextPropertyComponent::refresh()
  57806. {
  57807. textEditor->setText (getText(), false);
  57808. }
  57809. void TextPropertyComponent::textWasEdited()
  57810. {
  57811. const String newText (textEditor->getText());
  57812. if (getText() != newText)
  57813. setText (newText);
  57814. }
  57815. END_JUCE_NAMESPACE
  57816. /*** End of inlined file: juce_TextPropertyComponent.cpp ***/
  57817. /*** Start of inlined file: juce_AudioDeviceSelectorComponent.cpp ***/
  57818. BEGIN_JUCE_NAMESPACE
  57819. class SimpleDeviceManagerInputLevelMeter : public Component,
  57820. public Timer
  57821. {
  57822. public:
  57823. SimpleDeviceManagerInputLevelMeter (AudioDeviceManager* const manager_)
  57824. : manager (manager_),
  57825. level (0)
  57826. {
  57827. startTimer (50);
  57828. manager->enableInputLevelMeasurement (true);
  57829. }
  57830. ~SimpleDeviceManagerInputLevelMeter()
  57831. {
  57832. manager->enableInputLevelMeasurement (false);
  57833. }
  57834. void timerCallback()
  57835. {
  57836. const float newLevel = (float) manager->getCurrentInputLevel();
  57837. if (fabsf (level - newLevel) > 0.005f)
  57838. {
  57839. level = newLevel;
  57840. repaint();
  57841. }
  57842. }
  57843. void paint (Graphics& g)
  57844. {
  57845. getLookAndFeel().drawLevelMeter (g, getWidth(), getHeight(),
  57846. (float) exp (log (level) / 3.0)); // (add a bit of a skew to make the level more obvious)
  57847. }
  57848. private:
  57849. AudioDeviceManager* const manager;
  57850. float level;
  57851. };
  57852. class MidiInputSelectorComponentListBox : public ListBox,
  57853. public ListBoxModel
  57854. {
  57855. public:
  57856. MidiInputSelectorComponentListBox (AudioDeviceManager& deviceManager_,
  57857. const String& noItemsMessage_,
  57858. const int minNumber_,
  57859. const int maxNumber_)
  57860. : ListBox (String::empty, 0),
  57861. deviceManager (deviceManager_),
  57862. noItemsMessage (noItemsMessage_),
  57863. minNumber (minNumber_),
  57864. maxNumber (maxNumber_)
  57865. {
  57866. items = MidiInput::getDevices();
  57867. setModel (this);
  57868. setOutlineThickness (1);
  57869. }
  57870. ~MidiInputSelectorComponentListBox()
  57871. {
  57872. }
  57873. int getNumRows()
  57874. {
  57875. return items.size();
  57876. }
  57877. void paintListBoxItem (int row,
  57878. Graphics& g,
  57879. int width, int height,
  57880. bool rowIsSelected)
  57881. {
  57882. if (((unsigned int) row) < (unsigned int) items.size())
  57883. {
  57884. if (rowIsSelected)
  57885. g.fillAll (findColour (TextEditor::highlightColourId)
  57886. .withMultipliedAlpha (0.3f));
  57887. const String item (items [row]);
  57888. bool enabled = deviceManager.isMidiInputEnabled (item);
  57889. const int x = getTickX();
  57890. const float tickW = height * 0.75f;
  57891. getLookAndFeel().drawTickBox (g, *this, x - tickW, (height - tickW) / 2, tickW, tickW,
  57892. enabled, true, true, false);
  57893. g.setFont (height * 0.6f);
  57894. g.setColour (findColour (ListBox::textColourId, true).withMultipliedAlpha (enabled ? 1.0f : 0.6f));
  57895. g.drawText (item, x, 0, width - x - 2, height, Justification::centredLeft, true);
  57896. }
  57897. }
  57898. void listBoxItemClicked (int row, const MouseEvent& e)
  57899. {
  57900. selectRow (row);
  57901. if (e.x < getTickX())
  57902. flipEnablement (row);
  57903. }
  57904. void listBoxItemDoubleClicked (int row, const MouseEvent&)
  57905. {
  57906. flipEnablement (row);
  57907. }
  57908. void returnKeyPressed (int row)
  57909. {
  57910. flipEnablement (row);
  57911. }
  57912. void paint (Graphics& g)
  57913. {
  57914. ListBox::paint (g);
  57915. if (items.size() == 0)
  57916. {
  57917. g.setColour (Colours::grey);
  57918. g.setFont (13.0f);
  57919. g.drawText (noItemsMessage,
  57920. 0, 0, getWidth(), getHeight() / 2,
  57921. Justification::centred, true);
  57922. }
  57923. }
  57924. int getBestHeight (const int preferredHeight)
  57925. {
  57926. const int extra = getOutlineThickness() * 2;
  57927. return jmax (getRowHeight() * 2 + extra,
  57928. jmin (getRowHeight() * getNumRows() + extra,
  57929. preferredHeight));
  57930. }
  57931. juce_UseDebuggingNewOperator
  57932. private:
  57933. AudioDeviceManager& deviceManager;
  57934. const String noItemsMessage;
  57935. StringArray items;
  57936. int minNumber, maxNumber;
  57937. void flipEnablement (const int row)
  57938. {
  57939. if (((unsigned int) row) < (unsigned int) items.size())
  57940. {
  57941. const String item (items [row]);
  57942. deviceManager.setMidiInputEnabled (item, ! deviceManager.isMidiInputEnabled (item));
  57943. }
  57944. }
  57945. int getTickX() const
  57946. {
  57947. return getRowHeight() + 5;
  57948. }
  57949. MidiInputSelectorComponentListBox (const MidiInputSelectorComponentListBox&);
  57950. const MidiInputSelectorComponentListBox& operator= (const MidiInputSelectorComponentListBox&);
  57951. };
  57952. class AudioDeviceSettingsPanel : public Component,
  57953. public ComboBoxListener,
  57954. public ChangeListener,
  57955. public ButtonListener
  57956. {
  57957. public:
  57958. AudioDeviceSettingsPanel (AudioIODeviceType* type_,
  57959. AudioIODeviceType::DeviceSetupDetails& setup_,
  57960. const bool hideAdvancedOptionsWithButton)
  57961. : type (type_),
  57962. setup (setup_)
  57963. {
  57964. sampleRateDropDown = 0;
  57965. sampleRateLabel = 0;
  57966. bufferSizeDropDown = 0;
  57967. bufferSizeLabel = 0;
  57968. outputDeviceDropDown = 0;
  57969. outputDeviceLabel = 0;
  57970. inputDeviceDropDown = 0;
  57971. inputDeviceLabel = 0;
  57972. testButton = 0;
  57973. inputLevelMeter = 0;
  57974. showUIButton = 0;
  57975. inputChanList = 0;
  57976. outputChanList = 0;
  57977. inputChanLabel = 0;
  57978. outputChanLabel = 0;
  57979. showAdvancedSettingsButton = 0;
  57980. if (hideAdvancedOptionsWithButton)
  57981. {
  57982. addAndMakeVisible (showAdvancedSettingsButton = new TextButton (TRANS("Show advanced settings...")));
  57983. showAdvancedSettingsButton->addButtonListener (this);
  57984. }
  57985. type->scanForDevices();
  57986. setup.manager->addChangeListener (this);
  57987. changeListenerCallback (0);
  57988. }
  57989. ~AudioDeviceSettingsPanel()
  57990. {
  57991. setup.manager->removeChangeListener (this);
  57992. deleteAndZero (outputDeviceLabel);
  57993. deleteAndZero (inputDeviceLabel);
  57994. deleteAndZero (sampleRateLabel);
  57995. deleteAndZero (bufferSizeLabel);
  57996. deleteAndZero (showUIButton);
  57997. deleteAndZero (inputChanLabel);
  57998. deleteAndZero (outputChanLabel);
  57999. deleteAndZero (showAdvancedSettingsButton);
  58000. deleteAllChildren();
  58001. }
  58002. void resized()
  58003. {
  58004. const int lx = proportionOfWidth (0.35f);
  58005. const int w = proportionOfWidth (0.4f);
  58006. const int h = 24;
  58007. const int space = 6;
  58008. const int dh = h + space;
  58009. int y = 0;
  58010. if (outputDeviceDropDown != 0)
  58011. {
  58012. outputDeviceDropDown->setBounds (lx, y, w, h);
  58013. if (testButton != 0)
  58014. testButton->setBounds (proportionOfWidth (0.77f),
  58015. outputDeviceDropDown->getY(),
  58016. proportionOfWidth (0.18f),
  58017. h);
  58018. y += dh;
  58019. }
  58020. if (inputDeviceDropDown != 0)
  58021. {
  58022. inputDeviceDropDown->setBounds (lx, y, w, h);
  58023. inputLevelMeter->setBounds (proportionOfWidth (0.77f),
  58024. inputDeviceDropDown->getY(),
  58025. proportionOfWidth (0.18f),
  58026. h);
  58027. y += dh;
  58028. }
  58029. const int maxBoxHeight = 100;//(getHeight() - y - dh * 2) / numBoxes;
  58030. if (outputChanList != 0)
  58031. {
  58032. const int bh = outputChanList->getBestHeight (maxBoxHeight);
  58033. outputChanList->setBounds (lx, y, proportionOfWidth (0.55f), bh);
  58034. y += bh + space;
  58035. }
  58036. if (inputChanList != 0)
  58037. {
  58038. const int bh = inputChanList->getBestHeight (maxBoxHeight);
  58039. inputChanList->setBounds (lx, y, proportionOfWidth (0.55f), bh);
  58040. y += bh + space;
  58041. }
  58042. y += space * 2;
  58043. if (showAdvancedSettingsButton != 0)
  58044. {
  58045. showAdvancedSettingsButton->changeWidthToFitText (h);
  58046. showAdvancedSettingsButton->setTopLeftPosition (lx, y);
  58047. }
  58048. if (sampleRateDropDown != 0)
  58049. {
  58050. sampleRateDropDown->setVisible (showAdvancedSettingsButton == 0
  58051. || ! showAdvancedSettingsButton->isVisible());
  58052. sampleRateDropDown->setBounds (lx, y, w, h);
  58053. y += dh;
  58054. }
  58055. if (bufferSizeDropDown != 0)
  58056. {
  58057. bufferSizeDropDown->setVisible (showAdvancedSettingsButton == 0
  58058. || ! showAdvancedSettingsButton->isVisible());
  58059. bufferSizeDropDown->setBounds (lx, y, w, h);
  58060. y += dh;
  58061. }
  58062. if (showUIButton != 0)
  58063. {
  58064. showUIButton->setVisible (showAdvancedSettingsButton == 0
  58065. || ! showAdvancedSettingsButton->isVisible());
  58066. showUIButton->changeWidthToFitText (h);
  58067. showUIButton->setTopLeftPosition (lx, y);
  58068. }
  58069. }
  58070. void comboBoxChanged (ComboBox* comboBoxThatHasChanged)
  58071. {
  58072. if (comboBoxThatHasChanged == 0)
  58073. return;
  58074. AudioDeviceManager::AudioDeviceSetup config;
  58075. setup.manager->getAudioDeviceSetup (config);
  58076. String error;
  58077. if (comboBoxThatHasChanged == outputDeviceDropDown
  58078. || comboBoxThatHasChanged == inputDeviceDropDown)
  58079. {
  58080. if (outputDeviceDropDown != 0)
  58081. config.outputDeviceName = outputDeviceDropDown->getSelectedId() < 0 ? String::empty
  58082. : outputDeviceDropDown->getText();
  58083. if (inputDeviceDropDown != 0)
  58084. config.inputDeviceName = inputDeviceDropDown->getSelectedId() < 0 ? String::empty
  58085. : inputDeviceDropDown->getText();
  58086. if (! type->hasSeparateInputsAndOutputs())
  58087. config.inputDeviceName = config.outputDeviceName;
  58088. if (comboBoxThatHasChanged == inputDeviceDropDown)
  58089. config.useDefaultInputChannels = true;
  58090. else
  58091. config.useDefaultOutputChannels = true;
  58092. error = setup.manager->setAudioDeviceSetup (config, true);
  58093. showCorrectDeviceName (inputDeviceDropDown, true);
  58094. showCorrectDeviceName (outputDeviceDropDown, false);
  58095. updateControlPanelButton();
  58096. resized();
  58097. }
  58098. else if (comboBoxThatHasChanged == sampleRateDropDown)
  58099. {
  58100. if (sampleRateDropDown->getSelectedId() > 0)
  58101. {
  58102. config.sampleRate = sampleRateDropDown->getSelectedId();
  58103. error = setup.manager->setAudioDeviceSetup (config, true);
  58104. }
  58105. }
  58106. else if (comboBoxThatHasChanged == bufferSizeDropDown)
  58107. {
  58108. if (bufferSizeDropDown->getSelectedId() > 0)
  58109. {
  58110. config.bufferSize = bufferSizeDropDown->getSelectedId();
  58111. error = setup.manager->setAudioDeviceSetup (config, true);
  58112. }
  58113. }
  58114. if (error.isNotEmpty())
  58115. {
  58116. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  58117. T("Error when trying to open audio device!"),
  58118. error);
  58119. }
  58120. }
  58121. void buttonClicked (Button* button)
  58122. {
  58123. if (button == showAdvancedSettingsButton)
  58124. {
  58125. showAdvancedSettingsButton->setVisible (false);
  58126. resized();
  58127. }
  58128. else if (button == showUIButton)
  58129. {
  58130. AudioIODevice* const device = setup.manager->getCurrentAudioDevice();
  58131. if (device != 0 && device->showControlPanel())
  58132. {
  58133. setup.manager->closeAudioDevice();
  58134. setup.manager->restartLastAudioDevice();
  58135. getTopLevelComponent()->toFront (true);
  58136. }
  58137. }
  58138. else if (button == testButton && testButton != 0)
  58139. {
  58140. setup.manager->playTestSound();
  58141. }
  58142. }
  58143. void updateControlPanelButton()
  58144. {
  58145. AudioIODevice* const currentDevice = setup.manager->getCurrentAudioDevice();
  58146. deleteAndZero (showUIButton);
  58147. if (currentDevice != 0 && currentDevice->hasControlPanel())
  58148. {
  58149. addAndMakeVisible (showUIButton = new TextButton (TRANS ("show this device's control panel"),
  58150. TRANS ("opens the device's own control panel")));
  58151. showUIButton->addButtonListener (this);
  58152. }
  58153. resized();
  58154. }
  58155. void changeListenerCallback (void*)
  58156. {
  58157. AudioIODevice* const currentDevice = setup.manager->getCurrentAudioDevice();
  58158. if (setup.maxNumOutputChannels > 0 || ! type->hasSeparateInputsAndOutputs())
  58159. {
  58160. if (outputDeviceDropDown == 0)
  58161. {
  58162. outputDeviceDropDown = new ComboBox (String::empty);
  58163. outputDeviceDropDown->addListener (this);
  58164. addAndMakeVisible (outputDeviceDropDown);
  58165. outputDeviceLabel = new Label (String::empty,
  58166. type->hasSeparateInputsAndOutputs() ? TRANS ("output:")
  58167. : TRANS ("device:"));
  58168. outputDeviceLabel->attachToComponent (outputDeviceDropDown, true);
  58169. if (setup.maxNumOutputChannels > 0)
  58170. {
  58171. addAndMakeVisible (testButton = new TextButton (TRANS ("Test")));
  58172. testButton->addButtonListener (this);
  58173. }
  58174. }
  58175. addNamesToDeviceBox (*outputDeviceDropDown, false);
  58176. }
  58177. if (setup.maxNumInputChannels > 0 && type->hasSeparateInputsAndOutputs())
  58178. {
  58179. if (inputDeviceDropDown == 0)
  58180. {
  58181. inputDeviceDropDown = new ComboBox (String::empty);
  58182. inputDeviceDropDown->addListener (this);
  58183. addAndMakeVisible (inputDeviceDropDown);
  58184. inputDeviceLabel = new Label (String::empty, TRANS ("input:"));
  58185. inputDeviceLabel->attachToComponent (inputDeviceDropDown, true);
  58186. addAndMakeVisible (inputLevelMeter
  58187. = new SimpleDeviceManagerInputLevelMeter (setup.manager));
  58188. }
  58189. addNamesToDeviceBox (*inputDeviceDropDown, true);
  58190. }
  58191. updateControlPanelButton();
  58192. showCorrectDeviceName (inputDeviceDropDown, true);
  58193. showCorrectDeviceName (outputDeviceDropDown, false);
  58194. if (currentDevice != 0)
  58195. {
  58196. if (setup.maxNumOutputChannels > 0
  58197. && setup.minNumOutputChannels < setup.manager->getCurrentAudioDevice()->getOutputChannelNames().size())
  58198. {
  58199. if (outputChanList == 0)
  58200. {
  58201. addAndMakeVisible (outputChanList
  58202. = new ChannelSelectorListBox (setup, ChannelSelectorListBox::audioOutputType,
  58203. TRANS ("(no audio output channels found)")));
  58204. outputChanLabel = new Label (String::empty, TRANS ("active output channels:"));
  58205. outputChanLabel->attachToComponent (outputChanList, true);
  58206. }
  58207. outputChanList->refresh();
  58208. }
  58209. else
  58210. {
  58211. deleteAndZero (outputChanLabel);
  58212. deleteAndZero (outputChanList);
  58213. }
  58214. if (setup.maxNumInputChannels > 0
  58215. && setup.minNumInputChannels < setup.manager->getCurrentAudioDevice()->getInputChannelNames().size())
  58216. {
  58217. if (inputChanList == 0)
  58218. {
  58219. addAndMakeVisible (inputChanList
  58220. = new ChannelSelectorListBox (setup, ChannelSelectorListBox::audioInputType,
  58221. TRANS ("(no audio input channels found)")));
  58222. inputChanLabel = new Label (String::empty, TRANS ("active input channels:"));
  58223. inputChanLabel->attachToComponent (inputChanList, true);
  58224. }
  58225. inputChanList->refresh();
  58226. }
  58227. else
  58228. {
  58229. deleteAndZero (inputChanLabel);
  58230. deleteAndZero (inputChanList);
  58231. }
  58232. // sample rate..
  58233. {
  58234. if (sampleRateDropDown == 0)
  58235. {
  58236. addAndMakeVisible (sampleRateDropDown = new ComboBox (String::empty));
  58237. sampleRateDropDown->addListener (this);
  58238. delete sampleRateLabel;
  58239. sampleRateLabel = new Label (String::empty, TRANS ("sample rate:"));
  58240. sampleRateLabel->attachToComponent (sampleRateDropDown, true);
  58241. }
  58242. else
  58243. {
  58244. sampleRateDropDown->clear();
  58245. sampleRateDropDown->removeListener (this);
  58246. }
  58247. const int numRates = currentDevice->getNumSampleRates();
  58248. for (int i = 0; i < numRates; ++i)
  58249. {
  58250. const int rate = roundToInt (currentDevice->getSampleRate (i));
  58251. sampleRateDropDown->addItem (String (rate) + T(" Hz"), rate);
  58252. }
  58253. sampleRateDropDown->setSelectedId (roundToInt (currentDevice->getCurrentSampleRate()), true);
  58254. sampleRateDropDown->addListener (this);
  58255. }
  58256. // buffer size
  58257. {
  58258. if (bufferSizeDropDown == 0)
  58259. {
  58260. addAndMakeVisible (bufferSizeDropDown = new ComboBox (String::empty));
  58261. bufferSizeDropDown->addListener (this);
  58262. delete bufferSizeLabel;
  58263. bufferSizeLabel = new Label (String::empty, TRANS ("audio buffer size:"));
  58264. bufferSizeLabel->attachToComponent (bufferSizeDropDown, true);
  58265. }
  58266. else
  58267. {
  58268. bufferSizeDropDown->clear();
  58269. }
  58270. const int numBufferSizes = currentDevice->getNumBufferSizesAvailable();
  58271. double currentRate = currentDevice->getCurrentSampleRate();
  58272. if (currentRate == 0)
  58273. currentRate = 48000.0;
  58274. for (int i = 0; i < numBufferSizes; ++i)
  58275. {
  58276. const int bs = currentDevice->getBufferSizeSamples (i);
  58277. bufferSizeDropDown->addItem (String (bs)
  58278. + T(" samples (")
  58279. + String (bs * 1000.0 / currentRate, 1)
  58280. + T(" ms)"),
  58281. bs);
  58282. }
  58283. bufferSizeDropDown->setSelectedId (currentDevice->getCurrentBufferSizeSamples(), true);
  58284. }
  58285. }
  58286. else
  58287. {
  58288. jassert (setup.manager->getCurrentAudioDevice() == 0); // not the correct device type!
  58289. deleteAndZero (sampleRateLabel);
  58290. deleteAndZero (bufferSizeLabel);
  58291. deleteAndZero (sampleRateDropDown);
  58292. deleteAndZero (bufferSizeDropDown);
  58293. if (outputDeviceDropDown != 0)
  58294. outputDeviceDropDown->setSelectedId (-1, true);
  58295. if (inputDeviceDropDown != 0)
  58296. inputDeviceDropDown->setSelectedId (-1, true);
  58297. }
  58298. resized();
  58299. setSize (getWidth(), getLowestY() + 4);
  58300. }
  58301. private:
  58302. AudioIODeviceType* const type;
  58303. const AudioIODeviceType::DeviceSetupDetails setup;
  58304. ComboBox* outputDeviceDropDown;
  58305. ComboBox* inputDeviceDropDown;
  58306. ComboBox* sampleRateDropDown;
  58307. ComboBox* bufferSizeDropDown;
  58308. Label* outputDeviceLabel;
  58309. Label* inputDeviceLabel;
  58310. Label* sampleRateLabel;
  58311. Label* bufferSizeLabel;
  58312. Label* inputChanLabel;
  58313. Label* outputChanLabel;
  58314. TextButton* testButton;
  58315. Component* inputLevelMeter;
  58316. TextButton* showUIButton;
  58317. TextButton* showAdvancedSettingsButton;
  58318. void showCorrectDeviceName (ComboBox* const box, const bool isInput)
  58319. {
  58320. if (box != 0)
  58321. {
  58322. AudioIODevice* const currentDevice = dynamic_cast <AudioIODevice*> (setup.manager->getCurrentAudioDevice());
  58323. const int index = type->getIndexOfDevice (currentDevice, isInput);
  58324. box->setSelectedId (index + 1, true);
  58325. if (testButton != 0 && ! isInput)
  58326. testButton->setEnabled (index >= 0);
  58327. }
  58328. }
  58329. void addNamesToDeviceBox (ComboBox& combo, bool isInputs)
  58330. {
  58331. const StringArray devs (type->getDeviceNames (isInputs));
  58332. combo.clear (true);
  58333. for (int i = 0; i < devs.size(); ++i)
  58334. combo.addItem (devs[i], i + 1);
  58335. combo.addItem (TRANS("<< none >>"), -1);
  58336. combo.setSelectedId (-1, true);
  58337. }
  58338. int getLowestY() const
  58339. {
  58340. int y = 0;
  58341. for (int i = getNumChildComponents(); --i >= 0;)
  58342. y = jmax (y, getChildComponent (i)->getBottom());
  58343. return y;
  58344. }
  58345. public:
  58346. class ChannelSelectorListBox : public ListBox,
  58347. public ListBoxModel
  58348. {
  58349. public:
  58350. enum BoxType
  58351. {
  58352. audioInputType,
  58353. audioOutputType
  58354. };
  58355. ChannelSelectorListBox (const AudioIODeviceType::DeviceSetupDetails& setup_,
  58356. const BoxType type_,
  58357. const String& noItemsMessage_)
  58358. : ListBox (String::empty, 0),
  58359. setup (setup_),
  58360. type (type_),
  58361. noItemsMessage (noItemsMessage_)
  58362. {
  58363. refresh();
  58364. setModel (this);
  58365. setOutlineThickness (1);
  58366. }
  58367. ~ChannelSelectorListBox()
  58368. {
  58369. }
  58370. void refresh()
  58371. {
  58372. items.clear();
  58373. AudioIODevice* const currentDevice = setup.manager->getCurrentAudioDevice();
  58374. if (currentDevice != 0)
  58375. {
  58376. if (type == audioInputType)
  58377. items = currentDevice->getInputChannelNames();
  58378. else if (type == audioOutputType)
  58379. items = currentDevice->getOutputChannelNames();
  58380. if (setup.useStereoPairs)
  58381. {
  58382. StringArray pairs;
  58383. for (int i = 0; i < items.size(); i += 2)
  58384. {
  58385. String name (items[i]);
  58386. String name2 (items[i + 1]);
  58387. String commonBit;
  58388. for (int j = 0; j < name.length(); ++j)
  58389. if (name.substring (0, j).equalsIgnoreCase (name2.substring (0, j)))
  58390. commonBit = name.substring (0, j);
  58391. pairs.add (name.trim()
  58392. + " + "
  58393. + name2.substring (commonBit.length()).trim());
  58394. }
  58395. items = pairs;
  58396. }
  58397. }
  58398. updateContent();
  58399. repaint();
  58400. }
  58401. int getNumRows()
  58402. {
  58403. return items.size();
  58404. }
  58405. void paintListBoxItem (int row,
  58406. Graphics& g,
  58407. int width, int height,
  58408. bool rowIsSelected)
  58409. {
  58410. if (((unsigned int) row) < (unsigned int) items.size())
  58411. {
  58412. if (rowIsSelected)
  58413. g.fillAll (findColour (TextEditor::highlightColourId)
  58414. .withMultipliedAlpha (0.3f));
  58415. const String item (items [row]);
  58416. bool enabled = false;
  58417. AudioDeviceManager::AudioDeviceSetup config;
  58418. setup.manager->getAudioDeviceSetup (config);
  58419. if (setup.useStereoPairs)
  58420. {
  58421. if (type == audioInputType)
  58422. enabled = config.inputChannels [row * 2] || config.inputChannels [row * 2 + 1];
  58423. else if (type == audioOutputType)
  58424. enabled = config.outputChannels [row * 2] || config.outputChannels [row * 2 + 1];
  58425. }
  58426. else
  58427. {
  58428. if (type == audioInputType)
  58429. enabled = config.inputChannels [row];
  58430. else if (type == audioOutputType)
  58431. enabled = config.outputChannels [row];
  58432. }
  58433. const int x = getTickX();
  58434. const float tickW = height * 0.75f;
  58435. getLookAndFeel().drawTickBox (g, *this, x - tickW, (height - tickW) / 2, tickW, tickW,
  58436. enabled, true, true, false);
  58437. g.setFont (height * 0.6f);
  58438. g.setColour (findColour (ListBox::textColourId, true).withMultipliedAlpha (enabled ? 1.0f : 0.6f));
  58439. g.drawText (item, x, 0, width - x - 2, height, Justification::centredLeft, true);
  58440. }
  58441. }
  58442. void listBoxItemClicked (int row, const MouseEvent& e)
  58443. {
  58444. selectRow (row);
  58445. if (e.x < getTickX())
  58446. flipEnablement (row);
  58447. }
  58448. void listBoxItemDoubleClicked (int row, const MouseEvent&)
  58449. {
  58450. flipEnablement (row);
  58451. }
  58452. void returnKeyPressed (int row)
  58453. {
  58454. flipEnablement (row);
  58455. }
  58456. void paint (Graphics& g)
  58457. {
  58458. ListBox::paint (g);
  58459. if (items.size() == 0)
  58460. {
  58461. g.setColour (Colours::grey);
  58462. g.setFont (13.0f);
  58463. g.drawText (noItemsMessage,
  58464. 0, 0, getWidth(), getHeight() / 2,
  58465. Justification::centred, true);
  58466. }
  58467. }
  58468. int getBestHeight (int maxHeight)
  58469. {
  58470. return getRowHeight() * jlimit (2, jmax (2, maxHeight / getRowHeight()),
  58471. getNumRows())
  58472. + getOutlineThickness() * 2;
  58473. }
  58474. juce_UseDebuggingNewOperator
  58475. private:
  58476. const AudioIODeviceType::DeviceSetupDetails setup;
  58477. const BoxType type;
  58478. const String noItemsMessage;
  58479. StringArray items;
  58480. void flipEnablement (const int row)
  58481. {
  58482. jassert (type == audioInputType || type == audioOutputType);
  58483. if (((unsigned int) row) < (unsigned int) items.size())
  58484. {
  58485. AudioDeviceManager::AudioDeviceSetup config;
  58486. setup.manager->getAudioDeviceSetup (config);
  58487. if (setup.useStereoPairs)
  58488. {
  58489. BitArray bits;
  58490. BitArray& original = (type == audioInputType ? config.inputChannels
  58491. : config.outputChannels);
  58492. int i;
  58493. for (i = 0; i < 256; i += 2)
  58494. bits.setBit (i / 2, original [i] || original [i + 1]);
  58495. if (type == audioInputType)
  58496. {
  58497. config.useDefaultInputChannels = false;
  58498. flipBit (bits, row, setup.minNumInputChannels / 2, setup.maxNumInputChannels / 2);
  58499. }
  58500. else
  58501. {
  58502. config.useDefaultOutputChannels = false;
  58503. flipBit (bits, row, setup.minNumOutputChannels / 2, setup.maxNumOutputChannels / 2);
  58504. }
  58505. for (i = 0; i < 256; ++i)
  58506. original.setBit (i, bits [i / 2]);
  58507. }
  58508. else
  58509. {
  58510. if (type == audioInputType)
  58511. {
  58512. config.useDefaultInputChannels = false;
  58513. flipBit (config.inputChannels, row, setup.minNumInputChannels, setup.maxNumInputChannels);
  58514. }
  58515. else
  58516. {
  58517. config.useDefaultOutputChannels = false;
  58518. flipBit (config.outputChannels, row, setup.minNumOutputChannels, setup.maxNumOutputChannels);
  58519. }
  58520. }
  58521. String error (setup.manager->setAudioDeviceSetup (config, true));
  58522. if (! error.isEmpty())
  58523. {
  58524. //xxx
  58525. }
  58526. }
  58527. }
  58528. static void flipBit (BitArray& chans, int index, int minNumber, int maxNumber)
  58529. {
  58530. const int numActive = chans.countNumberOfSetBits();
  58531. if (chans [index])
  58532. {
  58533. if (numActive > minNumber)
  58534. chans.setBit (index, false);
  58535. }
  58536. else
  58537. {
  58538. if (numActive >= maxNumber)
  58539. {
  58540. const int firstActiveChan = chans.findNextSetBit();
  58541. chans.setBit (index > firstActiveChan
  58542. ? firstActiveChan : chans.getHighestBit(),
  58543. false);
  58544. }
  58545. chans.setBit (index, true);
  58546. }
  58547. }
  58548. int getTickX() const
  58549. {
  58550. return getRowHeight() + 5;
  58551. }
  58552. ChannelSelectorListBox (const ChannelSelectorListBox&);
  58553. const ChannelSelectorListBox& operator= (const ChannelSelectorListBox&);
  58554. };
  58555. private:
  58556. ChannelSelectorListBox* inputChanList;
  58557. ChannelSelectorListBox* outputChanList;
  58558. AudioDeviceSettingsPanel (const AudioDeviceSettingsPanel&);
  58559. const AudioDeviceSettingsPanel& operator= (const AudioDeviceSettingsPanel&);
  58560. };
  58561. AudioDeviceSelectorComponent::AudioDeviceSelectorComponent (AudioDeviceManager& deviceManager_,
  58562. const int minInputChannels_,
  58563. const int maxInputChannels_,
  58564. const int minOutputChannels_,
  58565. const int maxOutputChannels_,
  58566. const bool showMidiInputOptions,
  58567. const bool showMidiOutputSelector,
  58568. const bool showChannelsAsStereoPairs_,
  58569. const bool hideAdvancedOptionsWithButton_)
  58570. : deviceManager (deviceManager_),
  58571. deviceTypeDropDown (0),
  58572. deviceTypeDropDownLabel (0),
  58573. audioDeviceSettingsComp (0),
  58574. minOutputChannels (minOutputChannels_),
  58575. maxOutputChannels (maxOutputChannels_),
  58576. minInputChannels (minInputChannels_),
  58577. maxInputChannels (maxInputChannels_),
  58578. showChannelsAsStereoPairs (showChannelsAsStereoPairs_),
  58579. hideAdvancedOptionsWithButton (hideAdvancedOptionsWithButton_)
  58580. {
  58581. jassert (minOutputChannels >= 0 && minOutputChannels <= maxOutputChannels);
  58582. jassert (minInputChannels >= 0 && minInputChannels <= maxInputChannels);
  58583. if (deviceManager_.getAvailableDeviceTypes().size() > 1)
  58584. {
  58585. deviceTypeDropDown = new ComboBox (String::empty);
  58586. for (int i = 0; i < deviceManager_.getAvailableDeviceTypes().size(); ++i)
  58587. {
  58588. deviceTypeDropDown
  58589. ->addItem (deviceManager_.getAvailableDeviceTypes().getUnchecked(i)->getTypeName(),
  58590. i + 1);
  58591. }
  58592. addAndMakeVisible (deviceTypeDropDown);
  58593. deviceTypeDropDown->addListener (this);
  58594. deviceTypeDropDownLabel = new Label (String::empty, TRANS ("audio device type:"));
  58595. deviceTypeDropDownLabel->setJustificationType (Justification::centredRight);
  58596. deviceTypeDropDownLabel->attachToComponent (deviceTypeDropDown, true);
  58597. }
  58598. if (showMidiInputOptions)
  58599. {
  58600. addAndMakeVisible (midiInputsList
  58601. = new MidiInputSelectorComponentListBox (deviceManager,
  58602. TRANS("(no midi inputs available)"),
  58603. 0, 0));
  58604. midiInputsLabel = new Label (String::empty, TRANS ("active midi inputs:"));
  58605. midiInputsLabel->setJustificationType (Justification::topRight);
  58606. midiInputsLabel->attachToComponent (midiInputsList, true);
  58607. }
  58608. else
  58609. {
  58610. midiInputsList = 0;
  58611. midiInputsLabel = 0;
  58612. }
  58613. if (showMidiOutputSelector)
  58614. {
  58615. addAndMakeVisible (midiOutputSelector = new ComboBox (String::empty));
  58616. midiOutputSelector->addListener (this);
  58617. midiOutputLabel = new Label ("lm", TRANS("Midi Output:"));
  58618. midiOutputLabel->attachToComponent (midiOutputSelector, true);
  58619. }
  58620. else
  58621. {
  58622. midiOutputSelector = 0;
  58623. midiOutputLabel = 0;
  58624. }
  58625. deviceManager_.addChangeListener (this);
  58626. changeListenerCallback (0);
  58627. }
  58628. AudioDeviceSelectorComponent::~AudioDeviceSelectorComponent()
  58629. {
  58630. deviceManager.removeChangeListener (this);
  58631. deleteAllChildren();
  58632. }
  58633. void AudioDeviceSelectorComponent::resized()
  58634. {
  58635. const int lx = proportionOfWidth (0.35f);
  58636. const int w = proportionOfWidth (0.4f);
  58637. const int h = 24;
  58638. const int space = 6;
  58639. const int dh = h + space;
  58640. int y = 15;
  58641. if (deviceTypeDropDown != 0)
  58642. {
  58643. deviceTypeDropDown->setBounds (lx, y, proportionOfWidth (0.3f), h);
  58644. y += dh + space * 2;
  58645. }
  58646. if (audioDeviceSettingsComp != 0)
  58647. {
  58648. audioDeviceSettingsComp->setBounds (0, y, getWidth(), audioDeviceSettingsComp->getHeight());
  58649. y += audioDeviceSettingsComp->getHeight() + space;
  58650. }
  58651. if (midiInputsList != 0)
  58652. {
  58653. const int bh = midiInputsList->getBestHeight (jmin (h * 8, getHeight() - y - space - h));
  58654. midiInputsList->setBounds (lx, y, w, bh);
  58655. y += bh + space;
  58656. }
  58657. if (midiOutputSelector != 0)
  58658. midiOutputSelector->setBounds (lx, y, w, h);
  58659. }
  58660. void AudioDeviceSelectorComponent::childBoundsChanged (Component* child)
  58661. {
  58662. if (child == audioDeviceSettingsComp)
  58663. resized();
  58664. }
  58665. void AudioDeviceSelectorComponent::buttonClicked (Button*)
  58666. {
  58667. AudioIODevice* const device = deviceManager.getCurrentAudioDevice();
  58668. if (device != 0 && device->hasControlPanel())
  58669. {
  58670. if (device->showControlPanel())
  58671. deviceManager.restartLastAudioDevice();
  58672. getTopLevelComponent()->toFront (true);
  58673. }
  58674. }
  58675. void AudioDeviceSelectorComponent::comboBoxChanged (ComboBox* comboBoxThatHasChanged)
  58676. {
  58677. if (comboBoxThatHasChanged == deviceTypeDropDown)
  58678. {
  58679. AudioIODeviceType* const type = deviceManager.getAvailableDeviceTypes() [deviceTypeDropDown->getSelectedId() - 1];
  58680. if (type != 0)
  58681. {
  58682. deleteAndZero (audioDeviceSettingsComp);
  58683. deviceManager.setCurrentAudioDeviceType (type->getTypeName(), true);
  58684. changeListenerCallback (0); // needed in case the type hasn't actally changed
  58685. }
  58686. }
  58687. else if (comboBoxThatHasChanged == midiOutputSelector)
  58688. {
  58689. deviceManager.setDefaultMidiOutput (midiOutputSelector->getText());
  58690. }
  58691. }
  58692. void AudioDeviceSelectorComponent::changeListenerCallback (void*)
  58693. {
  58694. if (deviceTypeDropDown != 0)
  58695. {
  58696. deviceTypeDropDown->setText (deviceManager.getCurrentAudioDeviceType(), false);
  58697. }
  58698. if (audioDeviceSettingsComp == 0
  58699. || audioDeviceSettingsCompType != deviceManager.getCurrentAudioDeviceType())
  58700. {
  58701. audioDeviceSettingsCompType = deviceManager.getCurrentAudioDeviceType();
  58702. deleteAndZero (audioDeviceSettingsComp);
  58703. AudioIODeviceType* const type
  58704. = deviceManager.getAvailableDeviceTypes() [deviceTypeDropDown == 0
  58705. ? 0 : deviceTypeDropDown->getSelectedId() - 1];
  58706. if (type != 0)
  58707. {
  58708. AudioIODeviceType::DeviceSetupDetails details;
  58709. details.manager = &deviceManager;
  58710. details.minNumInputChannels = minInputChannels;
  58711. details.maxNumInputChannels = maxInputChannels;
  58712. details.minNumOutputChannels = minOutputChannels;
  58713. details.maxNumOutputChannels = maxOutputChannels;
  58714. details.useStereoPairs = showChannelsAsStereoPairs;
  58715. audioDeviceSettingsComp = new AudioDeviceSettingsPanel (type, details, hideAdvancedOptionsWithButton);
  58716. if (audioDeviceSettingsComp != 0)
  58717. {
  58718. addAndMakeVisible (audioDeviceSettingsComp);
  58719. audioDeviceSettingsComp->resized();
  58720. }
  58721. }
  58722. }
  58723. if (midiInputsList != 0)
  58724. {
  58725. midiInputsList->updateContent();
  58726. midiInputsList->repaint();
  58727. }
  58728. if (midiOutputSelector != 0)
  58729. {
  58730. midiOutputSelector->clear();
  58731. const StringArray midiOuts (MidiOutput::getDevices());
  58732. midiOutputSelector->addItem (TRANS("<< none >>"), -1);
  58733. midiOutputSelector->addSeparator();
  58734. for (int i = 0; i < midiOuts.size(); ++i)
  58735. midiOutputSelector->addItem (midiOuts[i], i + 1);
  58736. int current = -1;
  58737. if (deviceManager.getDefaultMidiOutput() != 0)
  58738. current = 1 + midiOuts.indexOf (deviceManager.getDefaultMidiOutputName());
  58739. midiOutputSelector->setSelectedId (current, true);
  58740. }
  58741. resized();
  58742. }
  58743. END_JUCE_NAMESPACE
  58744. /*** End of inlined file: juce_AudioDeviceSelectorComponent.cpp ***/
  58745. /*** Start of inlined file: juce_BubbleComponent.cpp ***/
  58746. BEGIN_JUCE_NAMESPACE
  58747. BubbleComponent::BubbleComponent()
  58748. : side (0),
  58749. allowablePlacements (above | below | left | right),
  58750. arrowTipX (0.0f),
  58751. arrowTipY (0.0f)
  58752. {
  58753. setInterceptsMouseClicks (false, false);
  58754. shadow.setShadowProperties (5.0f, 0.35f, 0, 0);
  58755. setComponentEffect (&shadow);
  58756. }
  58757. BubbleComponent::~BubbleComponent()
  58758. {
  58759. }
  58760. void BubbleComponent::paint (Graphics& g)
  58761. {
  58762. int x = content.getX();
  58763. int y = content.getY();
  58764. int w = content.getWidth();
  58765. int h = content.getHeight();
  58766. int cw, ch;
  58767. getContentSize (cw, ch);
  58768. if (side == 3)
  58769. x += w - cw;
  58770. else if (side != 1)
  58771. x += (w - cw) / 2;
  58772. w = cw;
  58773. if (side == 2)
  58774. y += h - ch;
  58775. else if (side != 0)
  58776. y += (h - ch) / 2;
  58777. h = ch;
  58778. getLookAndFeel().drawBubble (g, arrowTipX, arrowTipY,
  58779. (float) x, (float) y,
  58780. (float) w, (float) h);
  58781. const int cx = x + (w - cw) / 2;
  58782. const int cy = y + (h - ch) / 2;
  58783. const int indent = 3;
  58784. g.setOrigin (cx + indent, cy + indent);
  58785. g.reduceClipRegion (0, 0, cw - indent * 2, ch - indent * 2);
  58786. paintContent (g, cw - indent * 2, ch - indent * 2);
  58787. }
  58788. void BubbleComponent::setAllowedPlacement (const int newPlacement)
  58789. {
  58790. allowablePlacements = newPlacement;
  58791. }
  58792. void BubbleComponent::setPosition (Component* componentToPointTo)
  58793. {
  58794. jassert (componentToPointTo->isValidComponent());
  58795. int tx = 0;
  58796. int ty = 0;
  58797. if (getParentComponent() != 0)
  58798. componentToPointTo->relativePositionToOtherComponent (getParentComponent(), tx, ty);
  58799. else
  58800. componentToPointTo->relativePositionToGlobal (tx, ty);
  58801. setPosition (Rectangle<int> (tx, ty, componentToPointTo->getWidth(), componentToPointTo->getHeight()));
  58802. }
  58803. void BubbleComponent::setPosition (const int arrowTipX_,
  58804. const int arrowTipY_)
  58805. {
  58806. setPosition (Rectangle<int> (arrowTipX_, arrowTipY_, 1, 1));
  58807. }
  58808. void BubbleComponent::setPosition (const Rectangle<int>& rectangleToPointTo)
  58809. {
  58810. Rectangle<int> availableSpace;
  58811. if (getParentComponent() != 0)
  58812. {
  58813. availableSpace.setSize (getParentComponent()->getWidth(),
  58814. getParentComponent()->getHeight());
  58815. }
  58816. else
  58817. {
  58818. availableSpace = getParentMonitorArea();
  58819. }
  58820. int x = 0;
  58821. int y = 0;
  58822. int w = 150;
  58823. int h = 30;
  58824. getContentSize (w, h);
  58825. w += 30;
  58826. h += 30;
  58827. const float edgeIndent = 2.0f;
  58828. const int arrowLength = jmin (10, h / 3, w / 3);
  58829. int spaceAbove = ((allowablePlacements & above) != 0) ? jmax (0, rectangleToPointTo.getY() - availableSpace.getY()) : -1;
  58830. int spaceBelow = ((allowablePlacements & below) != 0) ? jmax (0, availableSpace.getBottom() - rectangleToPointTo.getBottom()) : -1;
  58831. int spaceLeft = ((allowablePlacements & left) != 0) ? jmax (0, rectangleToPointTo.getX() - availableSpace.getX()) : -1;
  58832. int spaceRight = ((allowablePlacements & right) != 0) ? jmax (0, availableSpace.getRight() - rectangleToPointTo.getRight()) : -1;
  58833. // look at whether the component is elongated, and if so, try to position next to its longer dimension.
  58834. if (rectangleToPointTo.getWidth() > rectangleToPointTo.getHeight() * 2
  58835. && (spaceAbove > h + 20 || spaceBelow > h + 20))
  58836. {
  58837. spaceLeft = spaceRight = 0;
  58838. }
  58839. else if (rectangleToPointTo.getWidth() < rectangleToPointTo.getHeight() / 2
  58840. && (spaceLeft > w + 20 || spaceRight > w + 20))
  58841. {
  58842. spaceAbove = spaceBelow = 0;
  58843. }
  58844. if (jmax (spaceAbove, spaceBelow) >= jmax (spaceLeft, spaceRight))
  58845. {
  58846. x = rectangleToPointTo.getX() + (rectangleToPointTo.getWidth() - w) / 2;
  58847. arrowTipX = w * 0.5f;
  58848. content.setSize (w, h - arrowLength);
  58849. if (spaceAbove >= spaceBelow)
  58850. {
  58851. // above
  58852. y = rectangleToPointTo.getY() - h;
  58853. content.setPosition (0, 0);
  58854. arrowTipY = h - edgeIndent;
  58855. side = 2;
  58856. }
  58857. else
  58858. {
  58859. // below
  58860. y = rectangleToPointTo.getBottom();
  58861. content.setPosition (0, arrowLength);
  58862. arrowTipY = edgeIndent;
  58863. side = 0;
  58864. }
  58865. }
  58866. else
  58867. {
  58868. y = rectangleToPointTo.getY() + (rectangleToPointTo.getHeight() - h) / 2;
  58869. arrowTipY = h * 0.5f;
  58870. content.setSize (w - arrowLength, h);
  58871. if (spaceLeft > spaceRight)
  58872. {
  58873. // on the left
  58874. x = rectangleToPointTo.getX() - w;
  58875. content.setPosition (0, 0);
  58876. arrowTipX = w - edgeIndent;
  58877. side = 3;
  58878. }
  58879. else
  58880. {
  58881. // on the right
  58882. x = rectangleToPointTo.getRight();
  58883. content.setPosition (arrowLength, 0);
  58884. arrowTipX = edgeIndent;
  58885. side = 1;
  58886. }
  58887. }
  58888. setBounds (x, y, w, h);
  58889. }
  58890. END_JUCE_NAMESPACE
  58891. /*** End of inlined file: juce_BubbleComponent.cpp ***/
  58892. /*** Start of inlined file: juce_BubbleMessageComponent.cpp ***/
  58893. BEGIN_JUCE_NAMESPACE
  58894. BubbleMessageComponent::BubbleMessageComponent (int fadeOutLengthMs)
  58895. : fadeOutLength (fadeOutLengthMs),
  58896. deleteAfterUse (false)
  58897. {
  58898. }
  58899. BubbleMessageComponent::~BubbleMessageComponent()
  58900. {
  58901. fadeOutComponent (fadeOutLength);
  58902. }
  58903. void BubbleMessageComponent::showAt (int x, int y,
  58904. const String& text,
  58905. const int numMillisecondsBeforeRemoving,
  58906. const bool removeWhenMouseClicked,
  58907. const bool deleteSelfAfterUse)
  58908. {
  58909. textLayout.clear();
  58910. textLayout.setText (text, Font (14.0f));
  58911. textLayout.layout (256, Justification::centredLeft, true);
  58912. setPosition (x, y);
  58913. init (numMillisecondsBeforeRemoving, removeWhenMouseClicked, deleteSelfAfterUse);
  58914. }
  58915. void BubbleMessageComponent::showAt (Component* const component,
  58916. const String& text,
  58917. const int numMillisecondsBeforeRemoving,
  58918. const bool removeWhenMouseClicked,
  58919. const bool deleteSelfAfterUse)
  58920. {
  58921. textLayout.clear();
  58922. textLayout.setText (text, Font (14.0f));
  58923. textLayout.layout (256, Justification::centredLeft, true);
  58924. setPosition (component);
  58925. init (numMillisecondsBeforeRemoving, removeWhenMouseClicked, deleteSelfAfterUse);
  58926. }
  58927. void BubbleMessageComponent::init (const int numMillisecondsBeforeRemoving,
  58928. const bool removeWhenMouseClicked,
  58929. const bool deleteSelfAfterUse)
  58930. {
  58931. setVisible (true);
  58932. deleteAfterUse = deleteSelfAfterUse;
  58933. if (numMillisecondsBeforeRemoving > 0)
  58934. expiryTime = Time::getMillisecondCounter() + numMillisecondsBeforeRemoving;
  58935. else
  58936. expiryTime = 0;
  58937. startTimer (77);
  58938. mouseClickCounter = Desktop::getInstance().getMouseButtonClickCounter();
  58939. if (! (removeWhenMouseClicked && isShowing()))
  58940. mouseClickCounter += 0xfffff;
  58941. repaint();
  58942. }
  58943. void BubbleMessageComponent::getContentSize (int& w, int& h)
  58944. {
  58945. w = textLayout.getWidth() + 16;
  58946. h = textLayout.getHeight() + 16;
  58947. }
  58948. void BubbleMessageComponent::paintContent (Graphics& g, int w, int h)
  58949. {
  58950. g.setColour (findColour (TooltipWindow::textColourId));
  58951. textLayout.drawWithin (g, 0, 0, w, h, Justification::centred);
  58952. }
  58953. void BubbleMessageComponent::timerCallback()
  58954. {
  58955. if (Desktop::getInstance().getMouseButtonClickCounter() > mouseClickCounter)
  58956. {
  58957. stopTimer();
  58958. setVisible (false);
  58959. if (deleteAfterUse)
  58960. delete this;
  58961. }
  58962. else if (expiryTime != 0 && Time::getMillisecondCounter() > expiryTime)
  58963. {
  58964. stopTimer();
  58965. fadeOutComponent (fadeOutLength);
  58966. if (deleteAfterUse)
  58967. delete this;
  58968. }
  58969. }
  58970. END_JUCE_NAMESPACE
  58971. /*** End of inlined file: juce_BubbleMessageComponent.cpp ***/
  58972. /*** Start of inlined file: juce_ColourSelector.cpp ***/
  58973. BEGIN_JUCE_NAMESPACE
  58974. static const int swatchesPerRow = 8;
  58975. static const int swatchHeight = 22;
  58976. class ColourComponentSlider : public Slider
  58977. {
  58978. public:
  58979. ColourComponentSlider (const String& name)
  58980. : Slider (name)
  58981. {
  58982. setRange (0.0, 255.0, 1.0);
  58983. }
  58984. ~ColourComponentSlider()
  58985. {
  58986. }
  58987. const String getTextFromValue (double value)
  58988. {
  58989. return String::formatted (T("%02X"), (int) value);
  58990. }
  58991. double getValueFromText (const String& text)
  58992. {
  58993. return (double) text.getHexValue32();
  58994. }
  58995. private:
  58996. ColourComponentSlider (const ColourComponentSlider&);
  58997. const ColourComponentSlider& operator= (const ColourComponentSlider&);
  58998. };
  58999. class ColourSpaceMarker : public Component
  59000. {
  59001. public:
  59002. ColourSpaceMarker()
  59003. {
  59004. setInterceptsMouseClicks (false, false);
  59005. }
  59006. ~ColourSpaceMarker()
  59007. {
  59008. }
  59009. void paint (Graphics& g)
  59010. {
  59011. g.setColour (Colour::greyLevel (0.1f));
  59012. g.drawEllipse (1.0f, 1.0f, getWidth() - 2.0f, getHeight() - 2.0f, 1.0f);
  59013. g.setColour (Colour::greyLevel (0.9f));
  59014. g.drawEllipse (2.0f, 2.0f, getWidth() - 4.0f, getHeight() - 4.0f, 1.0f);
  59015. }
  59016. private:
  59017. ColourSpaceMarker (const ColourSpaceMarker&);
  59018. const ColourSpaceMarker& operator= (const ColourSpaceMarker&);
  59019. };
  59020. class ColourSpaceView : public Component
  59021. {
  59022. ColourSelector* const owner;
  59023. float& h;
  59024. float& s;
  59025. float& v;
  59026. float lastHue;
  59027. ColourSpaceMarker* marker;
  59028. const int edge;
  59029. public:
  59030. ColourSpaceView (ColourSelector* owner_,
  59031. float& h_, float& s_, float& v_,
  59032. const int edgeSize)
  59033. : owner (owner_),
  59034. h (h_), s (s_), v (v_),
  59035. lastHue (0.0f),
  59036. edge (edgeSize)
  59037. {
  59038. addAndMakeVisible (marker = new ColourSpaceMarker());
  59039. setMouseCursor (MouseCursor::CrosshairCursor);
  59040. }
  59041. ~ColourSpaceView()
  59042. {
  59043. deleteAllChildren();
  59044. }
  59045. void paint (Graphics& g)
  59046. {
  59047. if (colours == 0)
  59048. {
  59049. const int width = getWidth() / 2;
  59050. const int height = getHeight() / 2;
  59051. colours = new Image (Image::RGB, width, height, false);
  59052. Image::BitmapData pixels (*colours, 0, 0, width, height, true);
  59053. for (int y = 0; y < height; ++y)
  59054. {
  59055. const float v = 1.0f - y / (float) height;
  59056. for (int x = 0; x < width; ++x)
  59057. {
  59058. const float s = x / (float) width;
  59059. const Colour col (h, s, v, 1.0f);
  59060. PixelRGB* const pix = (PixelRGB*) pixels.getPixelPointer (x, y);
  59061. pix->set (col.getPixelARGB());
  59062. }
  59063. }
  59064. }
  59065. g.setOpacity (1.0f);
  59066. g.drawImage (colours, edge, edge, getWidth() - edge * 2, getHeight() - edge * 2,
  59067. 0, 0, colours->getWidth(), colours->getHeight());
  59068. }
  59069. void mouseDown (const MouseEvent& e)
  59070. {
  59071. mouseDrag (e);
  59072. }
  59073. void mouseDrag (const MouseEvent& e)
  59074. {
  59075. const float s = (e.x - edge) / (float) (getWidth() - edge * 2);
  59076. const float v = 1.0f - (e.y - edge) / (float) (getHeight() - edge * 2);
  59077. owner->setSV (s, v);
  59078. }
  59079. void updateIfNeeded()
  59080. {
  59081. if (lastHue != h)
  59082. {
  59083. lastHue = h;
  59084. colours = 0;
  59085. repaint();
  59086. }
  59087. updateMarker();
  59088. }
  59089. void resized()
  59090. {
  59091. colours = 0;
  59092. updateMarker();
  59093. }
  59094. private:
  59095. ScopedPointer <Image> colours;
  59096. void updateMarker() const throw()
  59097. {
  59098. marker->setBounds (roundToInt ((getWidth() - edge * 2) * s),
  59099. roundToInt ((getHeight() - edge * 2) * (1.0f - v)),
  59100. edge * 2, edge * 2);
  59101. }
  59102. ColourSpaceView (const ColourSpaceView&);
  59103. const ColourSpaceView& operator= (const ColourSpaceView&);
  59104. };
  59105. class HueSelectorMarker : public Component
  59106. {
  59107. public:
  59108. HueSelectorMarker()
  59109. {
  59110. setInterceptsMouseClicks (false, false);
  59111. }
  59112. ~HueSelectorMarker()
  59113. {
  59114. }
  59115. void paint (Graphics& g)
  59116. {
  59117. Path p;
  59118. p.addTriangle (1.0f, 1.0f,
  59119. getWidth() * 0.3f, getHeight() * 0.5f,
  59120. 1.0f, getHeight() - 1.0f);
  59121. p.addTriangle (getWidth() - 1.0f, 1.0f,
  59122. getWidth() * 0.7f, getHeight() * 0.5f,
  59123. getWidth() - 1.0f, getHeight() - 1.0f);
  59124. g.setColour (Colours::white.withAlpha (0.75f));
  59125. g.fillPath (p);
  59126. g.setColour (Colours::black.withAlpha (0.75f));
  59127. g.strokePath (p, PathStrokeType (1.2f));
  59128. }
  59129. private:
  59130. HueSelectorMarker (const HueSelectorMarker&);
  59131. const HueSelectorMarker& operator= (const HueSelectorMarker&);
  59132. };
  59133. class HueSelectorComp : public Component
  59134. {
  59135. public:
  59136. HueSelectorComp (ColourSelector* owner_,
  59137. float& h_, float& s_, float& v_,
  59138. const int edgeSize)
  59139. : owner (owner_),
  59140. h (h_), s (s_), v (v_),
  59141. lastHue (0.0f),
  59142. edge (edgeSize)
  59143. {
  59144. addAndMakeVisible (marker = new HueSelectorMarker());
  59145. }
  59146. ~HueSelectorComp()
  59147. {
  59148. deleteAllChildren();
  59149. }
  59150. void paint (Graphics& g)
  59151. {
  59152. const float yScale = 1.0f / (getHeight() - edge * 2);
  59153. const Rectangle<int> clip (g.getClipBounds());
  59154. for (int y = jmin (clip.getBottom(), getHeight() - edge); --y >= jmax (edge, clip.getY());)
  59155. {
  59156. g.setColour (Colour ((y - edge) * yScale, 1.0f, 1.0f, 1.0f));
  59157. g.fillRect (edge, y, getWidth() - edge * 2, 1);
  59158. }
  59159. }
  59160. void resized()
  59161. {
  59162. marker->setBounds (0, roundToInt ((getHeight() - edge * 2) * h),
  59163. getWidth(), edge * 2);
  59164. }
  59165. void mouseDown (const MouseEvent& e)
  59166. {
  59167. mouseDrag (e);
  59168. }
  59169. void mouseDrag (const MouseEvent& e)
  59170. {
  59171. const float hue = (e.y - edge) / (float) (getHeight() - edge * 2);
  59172. owner->setHue (hue);
  59173. }
  59174. void updateIfNeeded()
  59175. {
  59176. resized();
  59177. }
  59178. private:
  59179. ColourSelector* const owner;
  59180. float& h;
  59181. float& s;
  59182. float& v;
  59183. float lastHue;
  59184. HueSelectorMarker* marker;
  59185. const int edge;
  59186. HueSelectorComp (const HueSelectorComp&);
  59187. const HueSelectorComp& operator= (const HueSelectorComp&);
  59188. };
  59189. class ColourSelector::SwatchComponent : public Component
  59190. {
  59191. public:
  59192. SwatchComponent (ColourSelector* owner_, int index_)
  59193. : owner (owner_),
  59194. index (index_)
  59195. {
  59196. }
  59197. ~SwatchComponent()
  59198. {
  59199. }
  59200. void paint (Graphics& g)
  59201. {
  59202. const Colour colour (owner->getSwatchColour (index));
  59203. g.fillCheckerBoard (0, 0, getWidth(), getHeight(),
  59204. 6, 6,
  59205. Colour (0xffdddddd).overlaidWith (colour),
  59206. Colour (0xffffffff).overlaidWith (colour));
  59207. }
  59208. void mouseDown (const MouseEvent&)
  59209. {
  59210. PopupMenu m;
  59211. m.addItem (1, TRANS("Use this swatch as the current colour"));
  59212. m.addSeparator();
  59213. m.addItem (2, TRANS("Set this swatch to the current colour"));
  59214. const int r = m.showAt (this);
  59215. if (r == 1)
  59216. {
  59217. owner->setCurrentColour (owner->getSwatchColour (index));
  59218. }
  59219. else if (r == 2)
  59220. {
  59221. if (owner->getSwatchColour (index) != owner->getCurrentColour())
  59222. {
  59223. owner->setSwatchColour (index, owner->getCurrentColour());
  59224. repaint();
  59225. }
  59226. }
  59227. }
  59228. private:
  59229. ColourSelector* const owner;
  59230. const int index;
  59231. SwatchComponent (const SwatchComponent&);
  59232. const SwatchComponent& operator= (const SwatchComponent&);
  59233. };
  59234. ColourSelector::ColourSelector (const int flags_,
  59235. const int edgeGap_,
  59236. const int gapAroundColourSpaceComponent)
  59237. : colour (Colours::white),
  59238. flags (flags_),
  59239. topSpace (0),
  59240. edgeGap (edgeGap_)
  59241. {
  59242. // not much point having a selector with no components in it!
  59243. jassert ((flags_ & (showColourAtTop | showSliders | showColourspace)) != 0);
  59244. updateHSV();
  59245. if ((flags & showSliders) != 0)
  59246. {
  59247. addAndMakeVisible (sliders[0] = new ColourComponentSlider (TRANS ("red")));
  59248. addAndMakeVisible (sliders[1] = new ColourComponentSlider (TRANS ("green")));
  59249. addAndMakeVisible (sliders[2] = new ColourComponentSlider (TRANS ("blue")));
  59250. addChildComponent (sliders[3] = new ColourComponentSlider (TRANS ("alpha")));
  59251. sliders[3]->setVisible ((flags & showAlphaChannel) != 0);
  59252. for (int i = 4; --i >= 0;)
  59253. sliders[i]->addListener (this);
  59254. }
  59255. else
  59256. {
  59257. zeromem (sliders, sizeof (sliders));
  59258. }
  59259. if ((flags & showColourspace) != 0)
  59260. {
  59261. addAndMakeVisible (colourSpace = new ColourSpaceView (this, h, s, v, gapAroundColourSpaceComponent));
  59262. addAndMakeVisible (hueSelector = new HueSelectorComp (this, h, s, v, gapAroundColourSpaceComponent));
  59263. }
  59264. else
  59265. {
  59266. colourSpace = 0;
  59267. hueSelector = 0;
  59268. }
  59269. update();
  59270. }
  59271. ColourSelector::~ColourSelector()
  59272. {
  59273. dispatchPendingMessages();
  59274. swatchComponents.clear();
  59275. deleteAllChildren();
  59276. }
  59277. const Colour ColourSelector::getCurrentColour() const
  59278. {
  59279. return ((flags & showAlphaChannel) != 0) ? colour
  59280. : colour.withAlpha ((uint8) 0xff);
  59281. }
  59282. void ColourSelector::setCurrentColour (const Colour& c)
  59283. {
  59284. if (c != colour)
  59285. {
  59286. colour = ((flags & showAlphaChannel) != 0) ? c : c.withAlpha ((uint8) 0xff);
  59287. updateHSV();
  59288. update();
  59289. }
  59290. }
  59291. void ColourSelector::setHue (float newH)
  59292. {
  59293. newH = jlimit (0.0f, 1.0f, newH);
  59294. if (h != newH)
  59295. {
  59296. h = newH;
  59297. colour = Colour (h, s, v, colour.getFloatAlpha());
  59298. update();
  59299. }
  59300. }
  59301. void ColourSelector::setSV (float newS, float newV)
  59302. {
  59303. newS = jlimit (0.0f, 1.0f, newS);
  59304. newV = jlimit (0.0f, 1.0f, newV);
  59305. if (s != newS || v != newV)
  59306. {
  59307. s = newS;
  59308. v = newV;
  59309. colour = Colour (h, s, v, colour.getFloatAlpha());
  59310. update();
  59311. }
  59312. }
  59313. void ColourSelector::updateHSV()
  59314. {
  59315. colour.getHSB (h, s, v);
  59316. }
  59317. void ColourSelector::update()
  59318. {
  59319. if (sliders[0] != 0)
  59320. {
  59321. sliders[0]->setValue ((int) colour.getRed());
  59322. sliders[1]->setValue ((int) colour.getGreen());
  59323. sliders[2]->setValue ((int) colour.getBlue());
  59324. sliders[3]->setValue ((int) colour.getAlpha());
  59325. }
  59326. if (colourSpace != 0)
  59327. {
  59328. ((ColourSpaceView*) colourSpace)->updateIfNeeded();
  59329. ((HueSelectorComp*) hueSelector)->updateIfNeeded();
  59330. }
  59331. if ((flags & showColourAtTop) != 0)
  59332. repaint (0, edgeGap, getWidth(), topSpace - edgeGap);
  59333. sendChangeMessage (this);
  59334. }
  59335. void ColourSelector::paint (Graphics& g)
  59336. {
  59337. g.fillAll (findColour (backgroundColourId));
  59338. if ((flags & showColourAtTop) != 0)
  59339. {
  59340. const Colour colour (getCurrentColour());
  59341. g.fillCheckerBoard (edgeGap, edgeGap, getWidth() - edgeGap - edgeGap, topSpace - edgeGap - edgeGap,
  59342. 10, 10,
  59343. Colour (0xffdddddd).overlaidWith (colour),
  59344. Colour (0xffffffff).overlaidWith (colour));
  59345. g.setColour (Colours::white.overlaidWith (colour).contrasting());
  59346. g.setFont (14.0f, true);
  59347. g.drawText (((flags & showAlphaChannel) != 0)
  59348. ? String::formatted (T("#%02X%02X%02X%02X"),
  59349. (int) colour.getAlpha(),
  59350. (int) colour.getRed(),
  59351. (int) colour.getGreen(),
  59352. (int) colour.getBlue())
  59353. : String::formatted (T("#%02X%02X%02X"),
  59354. (int) colour.getRed(),
  59355. (int) colour.getGreen(),
  59356. (int) colour.getBlue()),
  59357. 0, edgeGap, getWidth(), topSpace - edgeGap * 2,
  59358. Justification::centred, false);
  59359. }
  59360. if ((flags & showSliders) != 0)
  59361. {
  59362. g.setColour (findColour (labelTextColourId));
  59363. g.setFont (11.0f);
  59364. for (int i = 4; --i >= 0;)
  59365. {
  59366. if (sliders[i]->isVisible())
  59367. g.drawText (sliders[i]->getName() + T(":"),
  59368. 0, sliders[i]->getY(),
  59369. sliders[i]->getX() - 8, sliders[i]->getHeight(),
  59370. Justification::centredRight, false);
  59371. }
  59372. }
  59373. }
  59374. void ColourSelector::resized()
  59375. {
  59376. const int numSliders = ((flags & showAlphaChannel) != 0) ? 4 : 3;
  59377. const int numSwatches = getNumSwatches();
  59378. const int swatchSpace = numSwatches > 0 ? edgeGap + swatchHeight * ((numSwatches + 7) / swatchesPerRow) : 0;
  59379. const int sliderSpace = ((flags & showSliders) != 0) ? jmin (22 * numSliders + edgeGap, proportionOfHeight (0.3f)) : 0;
  59380. topSpace = ((flags & showColourAtTop) != 0) ? jmin (30 + edgeGap * 2, proportionOfHeight (0.2f)) : edgeGap;
  59381. int y = topSpace;
  59382. if ((flags & showColourspace) != 0)
  59383. {
  59384. const int hueWidth = jmin (50, proportionOfWidth (0.15f));
  59385. colourSpace->setBounds (edgeGap, y,
  59386. getWidth() - hueWidth - edgeGap - 4,
  59387. getHeight() - topSpace - sliderSpace - swatchSpace - edgeGap);
  59388. hueSelector->setBounds (colourSpace->getRight() + 4, y,
  59389. getWidth() - edgeGap - (colourSpace->getRight() + 4),
  59390. colourSpace->getHeight());
  59391. y = getHeight() - sliderSpace - swatchSpace - edgeGap;
  59392. }
  59393. if ((flags & showSliders) != 0)
  59394. {
  59395. const int sliderHeight = jmax (4, sliderSpace / numSliders);
  59396. for (int i = 0; i < numSliders; ++i)
  59397. {
  59398. sliders[i]->setBounds (proportionOfWidth (0.2f), y,
  59399. proportionOfWidth (0.72f), sliderHeight - 2);
  59400. y += sliderHeight;
  59401. }
  59402. }
  59403. if (numSwatches > 0)
  59404. {
  59405. const int startX = 8;
  59406. const int xGap = 4;
  59407. const int yGap = 4;
  59408. const int swatchWidth = (getWidth() - startX * 2) / swatchesPerRow;
  59409. y += edgeGap;
  59410. if (swatchComponents.size() != numSwatches)
  59411. {
  59412. swatchComponents.clear();
  59413. for (int i = 0; i < numSwatches; ++i)
  59414. {
  59415. SwatchComponent* const sc = new SwatchComponent (this, i);
  59416. swatchComponents.add (sc);
  59417. addAndMakeVisible (sc);
  59418. }
  59419. }
  59420. int x = startX;
  59421. for (int i = 0; i < swatchComponents.size(); ++i)
  59422. {
  59423. SwatchComponent* const sc = swatchComponents.getUnchecked(i);
  59424. sc->setBounds (x + xGap / 2,
  59425. y + yGap / 2,
  59426. swatchWidth - xGap,
  59427. swatchHeight - yGap);
  59428. if (((i + 1) % swatchesPerRow) == 0)
  59429. {
  59430. x = startX;
  59431. y += swatchHeight;
  59432. }
  59433. else
  59434. {
  59435. x += swatchWidth;
  59436. }
  59437. }
  59438. }
  59439. }
  59440. void ColourSelector::sliderValueChanged (Slider*)
  59441. {
  59442. if (sliders[0] != 0)
  59443. setCurrentColour (Colour ((uint8) sliders[0]->getValue(),
  59444. (uint8) sliders[1]->getValue(),
  59445. (uint8) sliders[2]->getValue(),
  59446. (uint8) sliders[3]->getValue()));
  59447. }
  59448. int ColourSelector::getNumSwatches() const
  59449. {
  59450. return 0;
  59451. }
  59452. const Colour ColourSelector::getSwatchColour (const int) const
  59453. {
  59454. jassertfalse // if you've overridden getNumSwatches(), you also need to implement this method
  59455. return Colours::black;
  59456. }
  59457. void ColourSelector::setSwatchColour (const int, const Colour&) const
  59458. {
  59459. jassertfalse // if you've overridden getNumSwatches(), you also need to implement this method
  59460. }
  59461. END_JUCE_NAMESPACE
  59462. /*** End of inlined file: juce_ColourSelector.cpp ***/
  59463. /*** Start of inlined file: juce_DropShadower.cpp ***/
  59464. BEGIN_JUCE_NAMESPACE
  59465. class ShadowWindow : public Component
  59466. {
  59467. Component* owner;
  59468. Image** shadowImageSections;
  59469. const int type; // 0 = left, 1 = right, 2 = top, 3 = bottom. left + right are full-height
  59470. public:
  59471. ShadowWindow (Component* const owner_,
  59472. const int type_,
  59473. Image** const shadowImageSections_)
  59474. : owner (owner_),
  59475. shadowImageSections (shadowImageSections_),
  59476. type (type_)
  59477. {
  59478. setInterceptsMouseClicks (false, false);
  59479. if (owner_->isOnDesktop())
  59480. {
  59481. setSize (1, 1); // to keep the OS happy by not having zero-size windows
  59482. addToDesktop (ComponentPeer::windowIgnoresMouseClicks
  59483. | ComponentPeer::windowIsTemporary
  59484. | ComponentPeer::windowIgnoresKeyPresses);
  59485. }
  59486. else if (owner_->getParentComponent() != 0)
  59487. {
  59488. owner_->getParentComponent()->addChildComponent (this);
  59489. }
  59490. }
  59491. ~ShadowWindow()
  59492. {
  59493. }
  59494. void paint (Graphics& g)
  59495. {
  59496. Image* const topLeft = shadowImageSections [type * 3];
  59497. Image* const bottomRight = shadowImageSections [type * 3 + 1];
  59498. Image* const filler = shadowImageSections [type * 3 + 2];
  59499. g.setOpacity (1.0f);
  59500. if (type < 2)
  59501. {
  59502. int imH = jmin (topLeft->getHeight(), getHeight() / 2);
  59503. g.drawImage (topLeft,
  59504. 0, 0, topLeft->getWidth(), imH,
  59505. 0, 0, topLeft->getWidth(), imH);
  59506. imH = jmin (bottomRight->getHeight(), getHeight() - getHeight() / 2);
  59507. g.drawImage (bottomRight,
  59508. 0, getHeight() - imH, bottomRight->getWidth(), imH,
  59509. 0, bottomRight->getHeight() - imH, bottomRight->getWidth(), imH);
  59510. g.setTiledImageFill (*filler, 0, 0, 1.0f);
  59511. g.fillRect (0, topLeft->getHeight(), getWidth(), getHeight() - (topLeft->getHeight() + bottomRight->getHeight()));
  59512. }
  59513. else
  59514. {
  59515. int imW = jmin (topLeft->getWidth(), getWidth() / 2);
  59516. g.drawImage (topLeft,
  59517. 0, 0, imW, topLeft->getHeight(),
  59518. 0, 0, imW, topLeft->getHeight());
  59519. imW = jmin (bottomRight->getWidth(), getWidth() - getWidth() / 2);
  59520. g.drawImage (bottomRight,
  59521. getWidth() - imW, 0, imW, bottomRight->getHeight(),
  59522. bottomRight->getWidth() - imW, 0, imW, bottomRight->getHeight());
  59523. g.setTiledImageFill (*filler, 0, 0, 1.0f);
  59524. g.fillRect (topLeft->getWidth(), 0, getWidth() - (topLeft->getWidth() + bottomRight->getWidth()), getHeight());
  59525. }
  59526. }
  59527. void resized()
  59528. {
  59529. repaint(); // (needed for correct repainting)
  59530. }
  59531. private:
  59532. ShadowWindow (const ShadowWindow&);
  59533. const ShadowWindow& operator= (const ShadowWindow&);
  59534. };
  59535. DropShadower::DropShadower (const float alpha_,
  59536. const int xOffset_,
  59537. const int yOffset_,
  59538. const float blurRadius_)
  59539. : owner (0),
  59540. numShadows (0),
  59541. shadowEdge (jmax (xOffset_, yOffset_) + (int) blurRadius_),
  59542. xOffset (xOffset_),
  59543. yOffset (yOffset_),
  59544. alpha (alpha_),
  59545. blurRadius (blurRadius_),
  59546. inDestructor (false),
  59547. reentrant (false)
  59548. {
  59549. }
  59550. DropShadower::~DropShadower()
  59551. {
  59552. if (owner != 0)
  59553. owner->removeComponentListener (this);
  59554. inDestructor = true;
  59555. deleteShadowWindows();
  59556. }
  59557. void DropShadower::deleteShadowWindows()
  59558. {
  59559. if (numShadows > 0)
  59560. {
  59561. int i;
  59562. for (i = numShadows; --i >= 0;)
  59563. delete shadowWindows[i];
  59564. for (i = 12; --i >= 0;)
  59565. delete shadowImageSections[i];
  59566. numShadows = 0;
  59567. }
  59568. }
  59569. void DropShadower::setOwner (Component* componentToFollow)
  59570. {
  59571. if (componentToFollow != owner)
  59572. {
  59573. if (owner != 0)
  59574. owner->removeComponentListener (this);
  59575. // (the component can't be null)
  59576. jassert (componentToFollow != 0);
  59577. owner = componentToFollow;
  59578. jassert (owner != 0);
  59579. jassert (owner->isOpaque()); // doesn't work properly for semi-transparent comps!
  59580. owner->addComponentListener (this);
  59581. updateShadows();
  59582. }
  59583. }
  59584. void DropShadower::componentMovedOrResized (Component&, bool /*wasMoved*/, bool /*wasResized*/)
  59585. {
  59586. updateShadows();
  59587. }
  59588. void DropShadower::componentBroughtToFront (Component&)
  59589. {
  59590. bringShadowWindowsToFront();
  59591. }
  59592. void DropShadower::componentChildrenChanged (Component&)
  59593. {
  59594. }
  59595. void DropShadower::componentParentHierarchyChanged (Component&)
  59596. {
  59597. deleteShadowWindows();
  59598. updateShadows();
  59599. }
  59600. void DropShadower::componentVisibilityChanged (Component&)
  59601. {
  59602. updateShadows();
  59603. }
  59604. void DropShadower::updateShadows()
  59605. {
  59606. if (reentrant || inDestructor || (owner == 0))
  59607. return;
  59608. reentrant = true;
  59609. ComponentPeer* const nw = owner->getPeer();
  59610. const bool isOwnerVisible = owner->isVisible()
  59611. && (nw == 0 || ! nw->isMinimised());
  59612. const bool createShadowWindows = numShadows == 0
  59613. && owner->getWidth() > 0
  59614. && owner->getHeight() > 0
  59615. && isOwnerVisible
  59616. && (Desktop::canUseSemiTransparentWindows()
  59617. || owner->getParentComponent() != 0);
  59618. if (createShadowWindows)
  59619. {
  59620. // keep a cached version of the image to save doing the gaussian too often
  59621. String imageId;
  59622. imageId << shadowEdge << T(',')
  59623. << xOffset << T(',')
  59624. << yOffset << T(',')
  59625. << alpha;
  59626. const int hash = imageId.hashCode();
  59627. Image* bigIm = ImageCache::getFromHashCode (hash);
  59628. if (bigIm == 0)
  59629. {
  59630. bigIm = Image::createNativeImage (Image::ARGB, shadowEdge * 5, shadowEdge * 5, true);
  59631. Graphics bigG (*bigIm);
  59632. bigG.setColour (Colours::black.withAlpha (alpha));
  59633. bigG.fillRect (shadowEdge + xOffset,
  59634. shadowEdge + yOffset,
  59635. bigIm->getWidth() - (shadowEdge * 2),
  59636. bigIm->getHeight() - (shadowEdge * 2));
  59637. ImageConvolutionKernel blurKernel (roundToInt (blurRadius * 2.0f));
  59638. blurKernel.createGaussianBlur (blurRadius);
  59639. blurKernel.applyToImage (*bigIm, 0,
  59640. xOffset,
  59641. yOffset,
  59642. bigIm->getWidth(),
  59643. bigIm->getHeight());
  59644. ImageCache::addImageToCache (bigIm, hash);
  59645. }
  59646. const int iw = bigIm->getWidth();
  59647. const int ih = bigIm->getHeight();
  59648. const int shadowEdge2 = shadowEdge * 2;
  59649. setShadowImage (bigIm, 0, shadowEdge, shadowEdge2, 0, 0);
  59650. setShadowImage (bigIm, 1, shadowEdge, shadowEdge2, 0, ih - shadowEdge2);
  59651. setShadowImage (bigIm, 2, shadowEdge, shadowEdge, 0, shadowEdge2);
  59652. setShadowImage (bigIm, 3, shadowEdge, shadowEdge2, iw - shadowEdge, 0);
  59653. setShadowImage (bigIm, 4, shadowEdge, shadowEdge2, iw - shadowEdge, ih - shadowEdge2);
  59654. setShadowImage (bigIm, 5, shadowEdge, shadowEdge, iw - shadowEdge, shadowEdge2);
  59655. setShadowImage (bigIm, 6, shadowEdge, shadowEdge, shadowEdge, 0);
  59656. setShadowImage (bigIm, 7, shadowEdge, shadowEdge, iw - shadowEdge2, 0);
  59657. setShadowImage (bigIm, 8, shadowEdge, shadowEdge, shadowEdge2, 0);
  59658. setShadowImage (bigIm, 9, shadowEdge, shadowEdge, shadowEdge, ih - shadowEdge);
  59659. setShadowImage (bigIm, 10, shadowEdge, shadowEdge, iw - shadowEdge2, ih - shadowEdge);
  59660. setShadowImage (bigIm, 11, shadowEdge, shadowEdge, shadowEdge2, ih - shadowEdge);
  59661. ImageCache::release (bigIm);
  59662. for (int i = 0; i < 4; ++i)
  59663. {
  59664. shadowWindows[numShadows] = new ShadowWindow (owner, i, shadowImageSections);
  59665. ++numShadows;
  59666. }
  59667. }
  59668. if (numShadows > 0)
  59669. {
  59670. for (int i = numShadows; --i >= 0;)
  59671. {
  59672. shadowWindows[i]->setAlwaysOnTop (owner->isAlwaysOnTop());
  59673. shadowWindows[i]->setVisible (isOwnerVisible);
  59674. }
  59675. const int x = owner->getX();
  59676. const int y = owner->getY() - shadowEdge;
  59677. const int w = owner->getWidth();
  59678. const int h = owner->getHeight() + shadowEdge + shadowEdge;
  59679. shadowWindows[0]->setBounds (x - shadowEdge,
  59680. y,
  59681. shadowEdge,
  59682. h);
  59683. shadowWindows[1]->setBounds (x + w,
  59684. y,
  59685. shadowEdge,
  59686. h);
  59687. shadowWindows[2]->setBounds (x,
  59688. y,
  59689. w,
  59690. shadowEdge);
  59691. shadowWindows[3]->setBounds (x,
  59692. owner->getBottom(),
  59693. w,
  59694. shadowEdge);
  59695. }
  59696. reentrant = false;
  59697. if (createShadowWindows)
  59698. bringShadowWindowsToFront();
  59699. }
  59700. void DropShadower::setShadowImage (Image* const src,
  59701. const int num,
  59702. const int w,
  59703. const int h,
  59704. const int sx,
  59705. const int sy)
  59706. {
  59707. shadowImageSections[num] = new Image (Image::ARGB, w, h, true);
  59708. Graphics g (*shadowImageSections[num]);
  59709. g.drawImage (src, 0, 0, w, h, sx, sy, w, h);
  59710. }
  59711. void DropShadower::bringShadowWindowsToFront()
  59712. {
  59713. if (! (inDestructor || reentrant))
  59714. {
  59715. updateShadows();
  59716. reentrant = true;
  59717. for (int i = numShadows; --i >= 0;)
  59718. shadowWindows[i]->toBehind (owner);
  59719. reentrant = false;
  59720. }
  59721. }
  59722. END_JUCE_NAMESPACE
  59723. /*** End of inlined file: juce_DropShadower.cpp ***/
  59724. /*** Start of inlined file: juce_MagnifierComponent.cpp ***/
  59725. BEGIN_JUCE_NAMESPACE
  59726. class MagnifyingPeer : public ComponentPeer
  59727. {
  59728. public:
  59729. MagnifyingPeer (Component* const component_,
  59730. MagnifierComponent* const magnifierComp_)
  59731. : ComponentPeer (component_, 0),
  59732. magnifierComp (magnifierComp_)
  59733. {
  59734. }
  59735. ~MagnifyingPeer()
  59736. {
  59737. }
  59738. void* getNativeHandle() const { return 0; }
  59739. void setVisible (bool) {}
  59740. void setTitle (const String&) {}
  59741. void setPosition (int, int) {}
  59742. void setSize (int, int) {}
  59743. void setBounds (int, int, int, int, const bool) {}
  59744. void setMinimised (bool) {}
  59745. bool isMinimised() const { return false; }
  59746. void setFullScreen (bool) {}
  59747. bool isFullScreen() const { return false; }
  59748. const BorderSize getFrameSize() const { return BorderSize (0); }
  59749. bool setAlwaysOnTop (bool) { return true; }
  59750. void toFront (bool) {}
  59751. void toBehind (ComponentPeer*) {}
  59752. void setIcon (const Image&) {}
  59753. bool isFocused() const
  59754. {
  59755. return magnifierComp->hasKeyboardFocus (true);
  59756. }
  59757. void grabFocus()
  59758. {
  59759. ComponentPeer* peer = magnifierComp->getPeer();
  59760. if (peer != 0)
  59761. peer->grabFocus();
  59762. }
  59763. void textInputRequired (int x, int y)
  59764. {
  59765. ComponentPeer* peer = magnifierComp->getPeer();
  59766. if (peer != 0)
  59767. peer->textInputRequired (x, y);
  59768. }
  59769. void getBounds (int& x, int& y, int& w, int& h) const
  59770. {
  59771. x = magnifierComp->getScreenX();
  59772. y = magnifierComp->getScreenY();
  59773. w = component->getWidth();
  59774. h = component->getHeight();
  59775. }
  59776. int getScreenX() const { return magnifierComp->getScreenX(); }
  59777. int getScreenY() const { return magnifierComp->getScreenY(); }
  59778. void relativePositionToGlobal (int& x, int& y)
  59779. {
  59780. const double zoom = magnifierComp->getScaleFactor();
  59781. x = roundToInt (x * zoom);
  59782. y = roundToInt (y * zoom);
  59783. magnifierComp->relativePositionToGlobal (x, y);
  59784. }
  59785. void globalPositionToRelative (int& x, int& y)
  59786. {
  59787. magnifierComp->globalPositionToRelative (x, y);
  59788. const double zoom = magnifierComp->getScaleFactor();
  59789. x = roundToInt (x / zoom);
  59790. y = roundToInt (y / zoom);
  59791. }
  59792. bool contains (int x, int y, bool) const
  59793. {
  59794. return ((unsigned int) x) < (unsigned int) magnifierComp->getWidth()
  59795. && ((unsigned int) y) < (unsigned int) magnifierComp->getHeight();
  59796. }
  59797. void repaint (int x, int y, int w, int h)
  59798. {
  59799. const double zoom = magnifierComp->getScaleFactor();
  59800. magnifierComp->repaint ((int) (x * zoom),
  59801. (int) (y * zoom),
  59802. roundToInt (w * zoom) + 1,
  59803. roundToInt (h * zoom) + 1);
  59804. }
  59805. void performAnyPendingRepaintsNow()
  59806. {
  59807. }
  59808. juce_UseDebuggingNewOperator
  59809. private:
  59810. MagnifierComponent* const magnifierComp;
  59811. MagnifyingPeer (const MagnifyingPeer&);
  59812. const MagnifyingPeer& operator= (const MagnifyingPeer&);
  59813. };
  59814. class PeerHolderComp : public Component
  59815. {
  59816. public:
  59817. PeerHolderComp (MagnifierComponent* const magnifierComp_)
  59818. : magnifierComp (magnifierComp_)
  59819. {
  59820. setVisible (true);
  59821. }
  59822. ~PeerHolderComp()
  59823. {
  59824. }
  59825. ComponentPeer* createNewPeer (int, void*)
  59826. {
  59827. return new MagnifyingPeer (this, magnifierComp);
  59828. }
  59829. void childBoundsChanged (Component* c)
  59830. {
  59831. if (c != 0)
  59832. {
  59833. setSize (c->getWidth(), c->getHeight());
  59834. magnifierComp->childBoundsChanged (this);
  59835. }
  59836. }
  59837. void mouseWheelMove (const MouseEvent& e, float ix, float iy)
  59838. {
  59839. // unhandled mouse wheel moves can be referred upwards to the parent comp..
  59840. Component* const p = magnifierComp->getParentComponent();
  59841. if (p != 0)
  59842. p->mouseWheelMove (e.getEventRelativeTo (p), ix, iy);
  59843. }
  59844. private:
  59845. MagnifierComponent* const magnifierComp;
  59846. PeerHolderComp (const PeerHolderComp&);
  59847. const PeerHolderComp& operator= (const PeerHolderComp&);
  59848. };
  59849. MagnifierComponent::MagnifierComponent (Component* const content_,
  59850. const bool deleteContentCompWhenNoLongerNeeded)
  59851. : content (content_),
  59852. scaleFactor (0.0),
  59853. peer (0),
  59854. deleteContent (deleteContentCompWhenNoLongerNeeded),
  59855. quality (Graphics::lowResamplingQuality)
  59856. {
  59857. holderComp = new PeerHolderComp (this);
  59858. setScaleFactor (1.0);
  59859. }
  59860. MagnifierComponent::~MagnifierComponent()
  59861. {
  59862. delete holderComp;
  59863. if (deleteContent)
  59864. delete content;
  59865. }
  59866. void MagnifierComponent::setScaleFactor (double newScaleFactor)
  59867. {
  59868. jassert (newScaleFactor > 0.0); // hmm - unlikely to work well with a negative scale factor
  59869. newScaleFactor = jlimit (1.0 / 8.0, 1000.0, newScaleFactor);
  59870. if (scaleFactor != newScaleFactor)
  59871. {
  59872. scaleFactor = newScaleFactor;
  59873. if (scaleFactor == 1.0)
  59874. {
  59875. holderComp->removeFromDesktop();
  59876. peer = 0;
  59877. addChildComponent (content);
  59878. childBoundsChanged (content);
  59879. }
  59880. else
  59881. {
  59882. holderComp->addAndMakeVisible (content);
  59883. holderComp->childBoundsChanged (content);
  59884. childBoundsChanged (holderComp);
  59885. holderComp->addToDesktop (0);
  59886. peer = holderComp->getPeer();
  59887. }
  59888. repaint();
  59889. }
  59890. }
  59891. void MagnifierComponent::setResamplingQuality (Graphics::ResamplingQuality newQuality)
  59892. {
  59893. quality = newQuality;
  59894. }
  59895. void MagnifierComponent::paint (Graphics& g)
  59896. {
  59897. const int w = holderComp->getWidth();
  59898. const int h = holderComp->getHeight();
  59899. if (w == 0 || h == 0)
  59900. return;
  59901. const Rectangle<int> r (g.getClipBounds());
  59902. const int srcX = (int) (r.getX() / scaleFactor);
  59903. const int srcY = (int) (r.getY() / scaleFactor);
  59904. int srcW = roundToInt (r.getRight() / scaleFactor) - srcX;
  59905. int srcH = roundToInt (r.getBottom() / scaleFactor) - srcY;
  59906. if (scaleFactor >= 1.0)
  59907. {
  59908. ++srcW;
  59909. ++srcH;
  59910. }
  59911. Image temp (Image::ARGB, jmax (w, srcX + srcW), jmax (h, srcY + srcH), false);
  59912. temp.clear (srcX, srcY, srcW, srcH);
  59913. {
  59914. Graphics g2 (temp);
  59915. g2.reduceClipRegion (srcX, srcY, srcW, srcH);
  59916. holderComp->paintEntireComponent (g2);
  59917. }
  59918. g.setImageResamplingQuality (quality);
  59919. g.drawImageTransformed (&temp, temp.getBounds(),
  59920. AffineTransform::scale ((float) scaleFactor, (float) scaleFactor),
  59921. false);
  59922. }
  59923. void MagnifierComponent::childBoundsChanged (Component* c)
  59924. {
  59925. if (c != 0)
  59926. setSize (roundToInt (c->getWidth() * scaleFactor),
  59927. roundToInt (c->getHeight() * scaleFactor));
  59928. }
  59929. void MagnifierComponent::mouseDown (const MouseEvent& e)
  59930. {
  59931. if (peer != 0)
  59932. peer->handleMouseDown (scaleInt (e.x), scaleInt (e.y), e.eventTime.toMilliseconds());
  59933. }
  59934. void MagnifierComponent::mouseUp (const MouseEvent& e)
  59935. {
  59936. if (peer != 0)
  59937. peer->handleMouseUp (e.mods.getRawFlags(), scaleInt (e.x), scaleInt (e.y), e.eventTime.toMilliseconds());
  59938. }
  59939. void MagnifierComponent::mouseDrag (const MouseEvent& e)
  59940. {
  59941. if (peer != 0)
  59942. peer->handleMouseDrag (scaleInt (e.x), scaleInt (e.y), e.eventTime.toMilliseconds());
  59943. }
  59944. void MagnifierComponent::mouseMove (const MouseEvent& e)
  59945. {
  59946. if (peer != 0)
  59947. peer->handleMouseMove (scaleInt (e.x), scaleInt (e.y), e.eventTime.toMilliseconds());
  59948. }
  59949. void MagnifierComponent::mouseEnter (const MouseEvent& e)
  59950. {
  59951. if (peer != 0)
  59952. peer->handleMouseEnter (scaleInt (e.x), scaleInt (e.y), e.eventTime.toMilliseconds());
  59953. }
  59954. void MagnifierComponent::mouseExit (const MouseEvent& e)
  59955. {
  59956. if (peer != 0)
  59957. peer->handleMouseExit (scaleInt (e.x), scaleInt (e.y), e.eventTime.toMilliseconds());
  59958. }
  59959. void MagnifierComponent::mouseWheelMove (const MouseEvent& e, float ix, float iy)
  59960. {
  59961. if (peer != 0)
  59962. peer->handleMouseWheel (roundToInt (ix * 256.0f),
  59963. roundToInt (iy * 256.0f),
  59964. e.eventTime.toMilliseconds());
  59965. else
  59966. Component::mouseWheelMove (e, ix, iy);
  59967. }
  59968. int MagnifierComponent::scaleInt (const int n) const
  59969. {
  59970. return roundToInt (n / scaleFactor);
  59971. }
  59972. END_JUCE_NAMESPACE
  59973. /*** End of inlined file: juce_MagnifierComponent.cpp ***/
  59974. /*** Start of inlined file: juce_MidiKeyboardComponent.cpp ***/
  59975. BEGIN_JUCE_NAMESPACE
  59976. class MidiKeyboardUpDownButton : public Button
  59977. {
  59978. public:
  59979. MidiKeyboardUpDownButton (MidiKeyboardComponent* const owner_,
  59980. const int delta_)
  59981. : Button (String::empty),
  59982. owner (owner_),
  59983. delta (delta_)
  59984. {
  59985. setOpaque (true);
  59986. }
  59987. ~MidiKeyboardUpDownButton()
  59988. {
  59989. }
  59990. void clicked()
  59991. {
  59992. int note = owner->getLowestVisibleKey();
  59993. if (delta < 0)
  59994. note = (note - 1) / 12;
  59995. else
  59996. note = note / 12 + 1;
  59997. owner->setLowestVisibleKey (note * 12);
  59998. }
  59999. void paintButton (Graphics& g,
  60000. bool isMouseOverButton,
  60001. bool isButtonDown)
  60002. {
  60003. owner->drawUpDownButton (g, getWidth(), getHeight(),
  60004. isMouseOverButton, isButtonDown,
  60005. delta > 0);
  60006. }
  60007. private:
  60008. MidiKeyboardComponent* const owner;
  60009. const int delta;
  60010. MidiKeyboardUpDownButton (const MidiKeyboardUpDownButton&);
  60011. const MidiKeyboardUpDownButton& operator= (const MidiKeyboardUpDownButton&);
  60012. };
  60013. MidiKeyboardComponent::MidiKeyboardComponent (MidiKeyboardState& state_,
  60014. const Orientation orientation_)
  60015. : state (state_),
  60016. xOffset (0),
  60017. blackNoteLength (1),
  60018. keyWidth (16.0f),
  60019. orientation (orientation_),
  60020. midiChannel (1),
  60021. midiInChannelMask (0xffff),
  60022. velocity (1.0f),
  60023. noteUnderMouse (-1),
  60024. mouseDownNote (-1),
  60025. rangeStart (0),
  60026. rangeEnd (127),
  60027. firstKey (12 * 4),
  60028. canScroll (true),
  60029. mouseDragging (false),
  60030. useMousePositionForVelocity (true),
  60031. keyMappingOctave (6),
  60032. octaveNumForMiddleC (3)
  60033. {
  60034. addChildComponent (scrollDown = new MidiKeyboardUpDownButton (this, -1));
  60035. addChildComponent (scrollUp = new MidiKeyboardUpDownButton (this, 1));
  60036. // initialise with a default set of querty key-mappings..
  60037. const char* const keymap = "awsedftgyhujkolp;";
  60038. for (int i = String (keymap).length(); --i >= 0;)
  60039. setKeyPressForNote (KeyPress (keymap[i], 0, 0), i);
  60040. setOpaque (true);
  60041. setWantsKeyboardFocus (true);
  60042. state.addListener (this);
  60043. }
  60044. MidiKeyboardComponent::~MidiKeyboardComponent()
  60045. {
  60046. state.removeListener (this);
  60047. jassert (mouseDownNote < 0 && keysPressed.countNumberOfSetBits() == 0); // leaving stuck notes!
  60048. deleteAllChildren();
  60049. }
  60050. void MidiKeyboardComponent::setKeyWidth (const float widthInPixels)
  60051. {
  60052. keyWidth = widthInPixels;
  60053. resized();
  60054. }
  60055. void MidiKeyboardComponent::setOrientation (const Orientation newOrientation)
  60056. {
  60057. if (orientation != newOrientation)
  60058. {
  60059. orientation = newOrientation;
  60060. resized();
  60061. }
  60062. }
  60063. void MidiKeyboardComponent::setAvailableRange (const int lowestNote,
  60064. const int highestNote)
  60065. {
  60066. jassert (lowestNote >= 0 && lowestNote <= 127);
  60067. jassert (highestNote >= 0 && highestNote <= 127);
  60068. jassert (lowestNote <= highestNote);
  60069. if (rangeStart != lowestNote || rangeEnd != highestNote)
  60070. {
  60071. rangeStart = jlimit (0, 127, lowestNote);
  60072. rangeEnd = jlimit (0, 127, highestNote);
  60073. firstKey = jlimit (rangeStart, rangeEnd, firstKey);
  60074. resized();
  60075. }
  60076. }
  60077. void MidiKeyboardComponent::setLowestVisibleKey (int noteNumber)
  60078. {
  60079. noteNumber = jlimit (rangeStart, rangeEnd, noteNumber);
  60080. if (noteNumber != firstKey)
  60081. {
  60082. firstKey = noteNumber;
  60083. sendChangeMessage (this);
  60084. resized();
  60085. }
  60086. }
  60087. void MidiKeyboardComponent::setScrollButtonsVisible (const bool canScroll_)
  60088. {
  60089. if (canScroll != canScroll_)
  60090. {
  60091. canScroll = canScroll_;
  60092. resized();
  60093. }
  60094. }
  60095. void MidiKeyboardComponent::colourChanged()
  60096. {
  60097. repaint();
  60098. }
  60099. void MidiKeyboardComponent::setMidiChannel (const int midiChannelNumber)
  60100. {
  60101. jassert (midiChannelNumber > 0 && midiChannelNumber <= 16);
  60102. if (midiChannel != midiChannelNumber)
  60103. {
  60104. resetAnyKeysInUse();
  60105. midiChannel = jlimit (1, 16, midiChannelNumber);
  60106. }
  60107. }
  60108. void MidiKeyboardComponent::setMidiChannelsToDisplay (const int midiChannelMask)
  60109. {
  60110. midiInChannelMask = midiChannelMask;
  60111. triggerAsyncUpdate();
  60112. }
  60113. void MidiKeyboardComponent::setVelocity (const float velocity_, const bool useMousePositionForVelocity_)
  60114. {
  60115. velocity = jlimit (0.0f, 1.0f, velocity_);
  60116. useMousePositionForVelocity = useMousePositionForVelocity_;
  60117. }
  60118. void MidiKeyboardComponent::getKeyPosition (int midiNoteNumber, const float keyWidth, int& x, int& w) const
  60119. {
  60120. jassert (midiNoteNumber >= 0 && midiNoteNumber < 128);
  60121. static const float blackNoteWidth = 0.7f;
  60122. static const float notePos[] = { 0.0f, 1 - blackNoteWidth * 0.6f,
  60123. 1.0f, 2 - blackNoteWidth * 0.4f,
  60124. 2.0f, 3.0f, 4 - blackNoteWidth * 0.7f,
  60125. 4.0f, 5 - blackNoteWidth * 0.5f,
  60126. 5.0f, 6 - blackNoteWidth * 0.3f,
  60127. 6.0f };
  60128. static const float widths[] = { 1.0f, blackNoteWidth,
  60129. 1.0f, blackNoteWidth,
  60130. 1.0f, 1.0f, blackNoteWidth,
  60131. 1.0f, blackNoteWidth,
  60132. 1.0f, blackNoteWidth,
  60133. 1.0f };
  60134. const int octave = midiNoteNumber / 12;
  60135. const int note = midiNoteNumber % 12;
  60136. x = roundToInt (octave * 7.0f * keyWidth + notePos [note] * keyWidth);
  60137. w = roundToInt (widths [note] * keyWidth);
  60138. }
  60139. void MidiKeyboardComponent::getKeyPos (int midiNoteNumber, int& x, int& w) const
  60140. {
  60141. getKeyPosition (midiNoteNumber, keyWidth, x, w);
  60142. int rx, rw;
  60143. getKeyPosition (rangeStart, keyWidth, rx, rw);
  60144. x -= xOffset + rx;
  60145. }
  60146. int MidiKeyboardComponent::getKeyStartPosition (const int midiNoteNumber) const
  60147. {
  60148. int x, y;
  60149. getKeyPos (midiNoteNumber, x, y);
  60150. return x;
  60151. }
  60152. static const uint8 whiteNotes[] = { 0, 2, 4, 5, 7, 9, 11 };
  60153. static const uint8 blackNotes[] = { 1, 3, 6, 8, 10 };
  60154. int MidiKeyboardComponent::xyToNote (int x, int y, float& mousePositionVelocity)
  60155. {
  60156. if (! reallyContains (x, y, false))
  60157. return -1;
  60158. if (orientation != horizontalKeyboard)
  60159. {
  60160. swapVariables (x, y);
  60161. if (orientation == verticalKeyboardFacingLeft)
  60162. y = getWidth() - y;
  60163. else
  60164. x = getHeight() - x;
  60165. }
  60166. return remappedXYToNote (x + xOffset, y, mousePositionVelocity);
  60167. }
  60168. int MidiKeyboardComponent::remappedXYToNote (int x, int y, float& mousePositionVelocity) const
  60169. {
  60170. if (y < blackNoteLength)
  60171. {
  60172. for (int octaveStart = 12 * (rangeStart / 12); octaveStart <= rangeEnd; octaveStart += 12)
  60173. {
  60174. for (int i = 0; i < 5; ++i)
  60175. {
  60176. const int note = octaveStart + blackNotes [i];
  60177. if (note >= rangeStart && note <= rangeEnd)
  60178. {
  60179. int kx, kw;
  60180. getKeyPos (note, kx, kw);
  60181. kx += xOffset;
  60182. if (x >= kx && x < kx + kw)
  60183. {
  60184. mousePositionVelocity = y / (float) blackNoteLength;
  60185. return note;
  60186. }
  60187. }
  60188. }
  60189. }
  60190. }
  60191. for (int octaveStart = 12 * (rangeStart / 12); octaveStart <= rangeEnd; octaveStart += 12)
  60192. {
  60193. for (int i = 0; i < 7; ++i)
  60194. {
  60195. const int note = octaveStart + whiteNotes [i];
  60196. if (note >= rangeStart && note <= rangeEnd)
  60197. {
  60198. int kx, kw;
  60199. getKeyPos (note, kx, kw);
  60200. kx += xOffset;
  60201. if (x >= kx && x < kx + kw)
  60202. {
  60203. const int whiteNoteLength = (orientation == horizontalKeyboard) ? getHeight() : getWidth();
  60204. mousePositionVelocity = y / (float) whiteNoteLength;
  60205. return note;
  60206. }
  60207. }
  60208. }
  60209. }
  60210. mousePositionVelocity = 0;
  60211. return -1;
  60212. }
  60213. void MidiKeyboardComponent::repaintNote (const int noteNum)
  60214. {
  60215. if (noteNum >= rangeStart && noteNum <= rangeEnd)
  60216. {
  60217. int x, w;
  60218. getKeyPos (noteNum, x, w);
  60219. if (orientation == horizontalKeyboard)
  60220. repaint (x, 0, w, getHeight());
  60221. else if (orientation == verticalKeyboardFacingLeft)
  60222. repaint (0, x, getWidth(), w);
  60223. else if (orientation == verticalKeyboardFacingRight)
  60224. repaint (0, getHeight() - x - w, getWidth(), w);
  60225. }
  60226. }
  60227. void MidiKeyboardComponent::paint (Graphics& g)
  60228. {
  60229. g.fillAll (Colours::white.overlaidWith (findColour (whiteNoteColourId)));
  60230. const Colour lineColour (findColour (keySeparatorLineColourId));
  60231. const Colour textColour (findColour (textLabelColourId));
  60232. int x, w, octave;
  60233. for (octave = 0; octave < 128; octave += 12)
  60234. {
  60235. for (int white = 0; white < 7; ++white)
  60236. {
  60237. const int noteNum = octave + whiteNotes [white];
  60238. if (noteNum >= rangeStart && noteNum <= rangeEnd)
  60239. {
  60240. getKeyPos (noteNum, x, w);
  60241. if (orientation == horizontalKeyboard)
  60242. drawWhiteNote (noteNum, g, x, 0, w, getHeight(),
  60243. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  60244. noteUnderMouse == noteNum,
  60245. lineColour, textColour);
  60246. else if (orientation == verticalKeyboardFacingLeft)
  60247. drawWhiteNote (noteNum, g, 0, x, getWidth(), w,
  60248. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  60249. noteUnderMouse == noteNum,
  60250. lineColour, textColour);
  60251. else if (orientation == verticalKeyboardFacingRight)
  60252. drawWhiteNote (noteNum, g, 0, getHeight() - x - w, getWidth(), w,
  60253. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  60254. noteUnderMouse == noteNum,
  60255. lineColour, textColour);
  60256. }
  60257. }
  60258. }
  60259. float x1 = 0.0f, y1 = 0.0f, x2 = 0.0f, y2 = 0.0f;
  60260. if (orientation == verticalKeyboardFacingLeft)
  60261. {
  60262. x1 = getWidth() - 1.0f;
  60263. x2 = getWidth() - 5.0f;
  60264. }
  60265. else if (orientation == verticalKeyboardFacingRight)
  60266. x2 = 5.0f;
  60267. else
  60268. y2 = 5.0f;
  60269. g.setGradientFill (ColourGradient (Colours::black.withAlpha (0.3f), x1, y1,
  60270. Colours::transparentBlack, x2, y2, false));
  60271. getKeyPos (rangeEnd, x, w);
  60272. x += w;
  60273. if (orientation == verticalKeyboardFacingLeft)
  60274. g.fillRect (getWidth() - 5, 0, 5, x);
  60275. else if (orientation == verticalKeyboardFacingRight)
  60276. g.fillRect (0, 0, 5, x);
  60277. else
  60278. g.fillRect (0, 0, x, 5);
  60279. g.setColour (lineColour);
  60280. if (orientation == verticalKeyboardFacingLeft)
  60281. g.fillRect (0, 0, 1, x);
  60282. else if (orientation == verticalKeyboardFacingRight)
  60283. g.fillRect (getWidth() - 1, 0, 1, x);
  60284. else
  60285. g.fillRect (0, getHeight() - 1, x, 1);
  60286. const Colour blackNoteColour (findColour (blackNoteColourId));
  60287. for (octave = 0; octave < 128; octave += 12)
  60288. {
  60289. for (int black = 0; black < 5; ++black)
  60290. {
  60291. const int noteNum = octave + blackNotes [black];
  60292. if (noteNum >= rangeStart && noteNum <= rangeEnd)
  60293. {
  60294. getKeyPos (noteNum, x, w);
  60295. if (orientation == horizontalKeyboard)
  60296. drawBlackNote (noteNum, g, x, 0, w, blackNoteLength,
  60297. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  60298. noteUnderMouse == noteNum,
  60299. blackNoteColour);
  60300. else if (orientation == verticalKeyboardFacingLeft)
  60301. drawBlackNote (noteNum, g, getWidth() - blackNoteLength, x, blackNoteLength, w,
  60302. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  60303. noteUnderMouse == noteNum,
  60304. blackNoteColour);
  60305. else if (orientation == verticalKeyboardFacingRight)
  60306. drawBlackNote (noteNum, g, 0, getHeight() - x - w, blackNoteLength, w,
  60307. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  60308. noteUnderMouse == noteNum,
  60309. blackNoteColour);
  60310. }
  60311. }
  60312. }
  60313. }
  60314. void MidiKeyboardComponent::drawWhiteNote (int midiNoteNumber,
  60315. Graphics& g, int x, int y, int w, int h,
  60316. bool isDown, bool isOver,
  60317. const Colour& lineColour,
  60318. const Colour& textColour)
  60319. {
  60320. Colour c (Colours::transparentWhite);
  60321. if (isDown)
  60322. c = findColour (keyDownOverlayColourId);
  60323. if (isOver)
  60324. c = c.overlaidWith (findColour (mouseOverKeyOverlayColourId));
  60325. g.setColour (c);
  60326. g.fillRect (x, y, w, h);
  60327. const String text (getWhiteNoteText (midiNoteNumber));
  60328. if (! text.isEmpty())
  60329. {
  60330. g.setColour (textColour);
  60331. Font f (jmin (12.0f, keyWidth * 0.9f));
  60332. f.setHorizontalScale (0.8f);
  60333. g.setFont (f);
  60334. Justification justification (Justification::centredBottom);
  60335. if (orientation == verticalKeyboardFacingLeft)
  60336. justification = Justification::centredLeft;
  60337. else if (orientation == verticalKeyboardFacingRight)
  60338. justification = Justification::centredRight;
  60339. g.drawFittedText (text, x + 2, y + 2, w - 4, h - 4, justification, 1);
  60340. }
  60341. g.setColour (lineColour);
  60342. if (orientation == horizontalKeyboard)
  60343. g.fillRect (x, y, 1, h);
  60344. else if (orientation == verticalKeyboardFacingLeft)
  60345. g.fillRect (x, y, w, 1);
  60346. else if (orientation == verticalKeyboardFacingRight)
  60347. g.fillRect (x, y + h - 1, w, 1);
  60348. if (midiNoteNumber == rangeEnd)
  60349. {
  60350. if (orientation == horizontalKeyboard)
  60351. g.fillRect (x + w, y, 1, h);
  60352. else if (orientation == verticalKeyboardFacingLeft)
  60353. g.fillRect (x, y + h, w, 1);
  60354. else if (orientation == verticalKeyboardFacingRight)
  60355. g.fillRect (x, y - 1, w, 1);
  60356. }
  60357. }
  60358. void MidiKeyboardComponent::drawBlackNote (int /*midiNoteNumber*/,
  60359. Graphics& g, int x, int y, int w, int h,
  60360. bool isDown, bool isOver,
  60361. const Colour& noteFillColour)
  60362. {
  60363. Colour c (noteFillColour);
  60364. if (isDown)
  60365. c = c.overlaidWith (findColour (keyDownOverlayColourId));
  60366. if (isOver)
  60367. c = c.overlaidWith (findColour (mouseOverKeyOverlayColourId));
  60368. g.setColour (c);
  60369. g.fillRect (x, y, w, h);
  60370. if (isDown)
  60371. {
  60372. g.setColour (noteFillColour);
  60373. g.drawRect (x, y, w, h);
  60374. }
  60375. else
  60376. {
  60377. const int xIndent = jmax (1, jmin (w, h) / 8);
  60378. g.setColour (c.brighter());
  60379. if (orientation == horizontalKeyboard)
  60380. g.fillRect (x + xIndent, y, w - xIndent * 2, 7 * h / 8);
  60381. else if (orientation == verticalKeyboardFacingLeft)
  60382. g.fillRect (x + w / 8, y + xIndent, w - w / 8, h - xIndent * 2);
  60383. else if (orientation == verticalKeyboardFacingRight)
  60384. g.fillRect (x, y + xIndent, 7 * w / 8, h - xIndent * 2);
  60385. }
  60386. }
  60387. void MidiKeyboardComponent::setOctaveForMiddleC (const int octaveNumForMiddleC_) throw()
  60388. {
  60389. octaveNumForMiddleC = octaveNumForMiddleC_;
  60390. repaint();
  60391. }
  60392. const String MidiKeyboardComponent::getWhiteNoteText (const int midiNoteNumber)
  60393. {
  60394. if (keyWidth > 14.0f && midiNoteNumber % 12 == 0)
  60395. return MidiMessage::getMidiNoteName (midiNoteNumber, true, true, octaveNumForMiddleC);
  60396. return String::empty;
  60397. }
  60398. void MidiKeyboardComponent::drawUpDownButton (Graphics& g, int w, int h,
  60399. const bool isMouseOver,
  60400. const bool isButtonDown,
  60401. const bool movesOctavesUp)
  60402. {
  60403. g.fillAll (findColour (upDownButtonBackgroundColourId));
  60404. float angle;
  60405. if (orientation == MidiKeyboardComponent::horizontalKeyboard)
  60406. angle = movesOctavesUp ? 0.0f : 0.5f;
  60407. else if (orientation == MidiKeyboardComponent::verticalKeyboardFacingLeft)
  60408. angle = movesOctavesUp ? 0.25f : 0.75f;
  60409. else
  60410. angle = movesOctavesUp ? 0.75f : 0.25f;
  60411. Path path;
  60412. path.lineTo (0.0f, 1.0f);
  60413. path.lineTo (1.0f, 0.5f);
  60414. path.closeSubPath();
  60415. path.applyTransform (AffineTransform::rotation (float_Pi * 2.0f * angle, 0.5f, 0.5f));
  60416. g.setColour (findColour (upDownButtonArrowColourId)
  60417. .withAlpha (isButtonDown ? 1.0f : (isMouseOver ? 0.6f : 0.4f)));
  60418. g.fillPath (path, path.getTransformToScaleToFit (1.0f, 1.0f,
  60419. w - 2.0f,
  60420. h - 2.0f,
  60421. true));
  60422. }
  60423. void MidiKeyboardComponent::resized()
  60424. {
  60425. int w = getWidth();
  60426. int h = getHeight();
  60427. if (w > 0 && h > 0)
  60428. {
  60429. if (orientation != horizontalKeyboard)
  60430. swapVariables (w, h);
  60431. blackNoteLength = roundToInt (h * 0.7f);
  60432. int kx2, kw2;
  60433. getKeyPos (rangeEnd, kx2, kw2);
  60434. kx2 += kw2;
  60435. if (firstKey != rangeStart)
  60436. {
  60437. int kx1, kw1;
  60438. getKeyPos (rangeStart, kx1, kw1);
  60439. if (kx2 - kx1 <= w)
  60440. {
  60441. firstKey = rangeStart;
  60442. sendChangeMessage (this);
  60443. repaint();
  60444. }
  60445. }
  60446. const bool showScrollButtons = canScroll && (firstKey > rangeStart || kx2 > w + xOffset * 2);
  60447. scrollDown->setVisible (showScrollButtons);
  60448. scrollUp->setVisible (showScrollButtons);
  60449. xOffset = 0;
  60450. if (showScrollButtons)
  60451. {
  60452. const int scrollButtonW = jmin (12, w / 2);
  60453. if (orientation == horizontalKeyboard)
  60454. {
  60455. scrollDown->setBounds (0, 0, scrollButtonW, getHeight());
  60456. scrollUp->setBounds (getWidth() - scrollButtonW, 0, scrollButtonW, getHeight());
  60457. }
  60458. else if (orientation == verticalKeyboardFacingLeft)
  60459. {
  60460. scrollDown->setBounds (0, 0, getWidth(), scrollButtonW);
  60461. scrollUp->setBounds (0, getHeight() - scrollButtonW, getWidth(), scrollButtonW);
  60462. }
  60463. else if (orientation == verticalKeyboardFacingRight)
  60464. {
  60465. scrollDown->setBounds (0, getHeight() - scrollButtonW, getWidth(), scrollButtonW);
  60466. scrollUp->setBounds (0, 0, getWidth(), scrollButtonW);
  60467. }
  60468. int endOfLastKey, kw;
  60469. getKeyPos (rangeEnd, endOfLastKey, kw);
  60470. endOfLastKey += kw;
  60471. float mousePositionVelocity;
  60472. const int spaceAvailable = w - scrollButtonW * 2;
  60473. const int lastStartKey = remappedXYToNote (endOfLastKey - spaceAvailable, 0, mousePositionVelocity) + 1;
  60474. if (lastStartKey >= 0 && firstKey > lastStartKey)
  60475. {
  60476. firstKey = jlimit (rangeStart, rangeEnd, lastStartKey);
  60477. sendChangeMessage (this);
  60478. }
  60479. int newOffset = 0;
  60480. getKeyPos (firstKey, newOffset, kw);
  60481. xOffset = newOffset - scrollButtonW;
  60482. }
  60483. else
  60484. {
  60485. firstKey = rangeStart;
  60486. }
  60487. timerCallback();
  60488. repaint();
  60489. }
  60490. }
  60491. void MidiKeyboardComponent::handleNoteOn (MidiKeyboardState*, int /*midiChannel*/, int /*midiNoteNumber*/, float /*velocity*/)
  60492. {
  60493. triggerAsyncUpdate();
  60494. }
  60495. void MidiKeyboardComponent::handleNoteOff (MidiKeyboardState*, int /*midiChannel*/, int /*midiNoteNumber*/)
  60496. {
  60497. triggerAsyncUpdate();
  60498. }
  60499. void MidiKeyboardComponent::handleAsyncUpdate()
  60500. {
  60501. for (int i = rangeStart; i <= rangeEnd; ++i)
  60502. {
  60503. if (keysCurrentlyDrawnDown[i] != state.isNoteOnForChannels (midiInChannelMask, i))
  60504. {
  60505. keysCurrentlyDrawnDown.setBit (i, state.isNoteOnForChannels (midiInChannelMask, i));
  60506. repaintNote (i);
  60507. }
  60508. }
  60509. }
  60510. void MidiKeyboardComponent::resetAnyKeysInUse()
  60511. {
  60512. if (keysPressed.countNumberOfSetBits() > 0 || mouseDownNote > 0)
  60513. {
  60514. state.allNotesOff (midiChannel);
  60515. keysPressed.clear();
  60516. mouseDownNote = -1;
  60517. }
  60518. }
  60519. void MidiKeyboardComponent::updateNoteUnderMouse (int x, int y)
  60520. {
  60521. float mousePositionVelocity = 0.0f;
  60522. const int newNote = (mouseDragging || isMouseOver())
  60523. ? xyToNote (x, y, mousePositionVelocity) : -1;
  60524. if (noteUnderMouse != newNote)
  60525. {
  60526. if (mouseDownNote >= 0)
  60527. {
  60528. state.noteOff (midiChannel, mouseDownNote);
  60529. mouseDownNote = -1;
  60530. }
  60531. if (mouseDragging && newNote >= 0)
  60532. {
  60533. if (! useMousePositionForVelocity)
  60534. mousePositionVelocity = 1.0f;
  60535. state.noteOn (midiChannel, newNote, mousePositionVelocity * velocity);
  60536. mouseDownNote = newNote;
  60537. }
  60538. repaintNote (noteUnderMouse);
  60539. noteUnderMouse = newNote;
  60540. repaintNote (noteUnderMouse);
  60541. }
  60542. else if (mouseDownNote >= 0 && ! mouseDragging)
  60543. {
  60544. state.noteOff (midiChannel, mouseDownNote);
  60545. mouseDownNote = -1;
  60546. }
  60547. }
  60548. void MidiKeyboardComponent::mouseMove (const MouseEvent& e)
  60549. {
  60550. updateNoteUnderMouse (e.x, e.y);
  60551. stopTimer();
  60552. }
  60553. void MidiKeyboardComponent::mouseDrag (const MouseEvent& e)
  60554. {
  60555. float mousePositionVelocity;
  60556. const int newNote = xyToNote (e.x, e.y, mousePositionVelocity);
  60557. if (newNote >= 0)
  60558. mouseDraggedToKey (newNote, e);
  60559. updateNoteUnderMouse (e.x, e.y);
  60560. }
  60561. bool MidiKeyboardComponent::mouseDownOnKey (int /*midiNoteNumber*/, const MouseEvent&)
  60562. {
  60563. return true;
  60564. }
  60565. void MidiKeyboardComponent::mouseDraggedToKey (int /*midiNoteNumber*/, const MouseEvent&)
  60566. {
  60567. }
  60568. void MidiKeyboardComponent::mouseDown (const MouseEvent& e)
  60569. {
  60570. float mousePositionVelocity;
  60571. const int newNote = xyToNote (e.x, e.y, mousePositionVelocity);
  60572. mouseDragging = false;
  60573. if (newNote >= 0 && mouseDownOnKey (newNote, e))
  60574. {
  60575. repaintNote (noteUnderMouse);
  60576. noteUnderMouse = -1;
  60577. mouseDragging = true;
  60578. updateNoteUnderMouse (e.x, e.y);
  60579. startTimer (500);
  60580. }
  60581. }
  60582. void MidiKeyboardComponent::mouseUp (const MouseEvent& e)
  60583. {
  60584. mouseDragging = false;
  60585. updateNoteUnderMouse (e.x, e.y);
  60586. stopTimer();
  60587. }
  60588. void MidiKeyboardComponent::mouseEnter (const MouseEvent& e)
  60589. {
  60590. updateNoteUnderMouse (e.x, e.y);
  60591. }
  60592. void MidiKeyboardComponent::mouseExit (const MouseEvent& e)
  60593. {
  60594. updateNoteUnderMouse (e.x, e.y);
  60595. }
  60596. void MidiKeyboardComponent::mouseWheelMove (const MouseEvent&, float ix, float iy)
  60597. {
  60598. setLowestVisibleKey (getLowestVisibleKey() + roundToInt ((ix != 0 ? ix : iy) * 5.0f));
  60599. }
  60600. void MidiKeyboardComponent::timerCallback()
  60601. {
  60602. int mx, my;
  60603. getMouseXYRelative (mx, my);
  60604. updateNoteUnderMouse (mx, my);
  60605. }
  60606. void MidiKeyboardComponent::clearKeyMappings()
  60607. {
  60608. resetAnyKeysInUse();
  60609. keyPressNotes.clear();
  60610. keyPresses.clear();
  60611. }
  60612. void MidiKeyboardComponent::setKeyPressForNote (const KeyPress& key,
  60613. const int midiNoteOffsetFromC)
  60614. {
  60615. removeKeyPressForNote (midiNoteOffsetFromC);
  60616. keyPressNotes.add (midiNoteOffsetFromC);
  60617. keyPresses.add (key);
  60618. }
  60619. void MidiKeyboardComponent::removeKeyPressForNote (const int midiNoteOffsetFromC)
  60620. {
  60621. for (int i = keyPressNotes.size(); --i >= 0;)
  60622. {
  60623. if (keyPressNotes.getUnchecked (i) == midiNoteOffsetFromC)
  60624. {
  60625. keyPressNotes.remove (i);
  60626. keyPresses.remove (i);
  60627. }
  60628. }
  60629. }
  60630. void MidiKeyboardComponent::setKeyPressBaseOctave (const int newOctaveNumber)
  60631. {
  60632. jassert (newOctaveNumber >= 0 && newOctaveNumber <= 10);
  60633. keyMappingOctave = newOctaveNumber;
  60634. }
  60635. bool MidiKeyboardComponent::keyStateChanged (const bool /*isKeyDown*/)
  60636. {
  60637. bool keyPressUsed = false;
  60638. for (int i = keyPresses.size(); --i >= 0;)
  60639. {
  60640. const int note = 12 * keyMappingOctave + keyPressNotes.getUnchecked (i);
  60641. if (keyPresses.getReference(i).isCurrentlyDown())
  60642. {
  60643. if (! keysPressed [note])
  60644. {
  60645. keysPressed.setBit (note);
  60646. state.noteOn (midiChannel, note, velocity);
  60647. keyPressUsed = true;
  60648. }
  60649. }
  60650. else
  60651. {
  60652. if (keysPressed [note])
  60653. {
  60654. keysPressed.clearBit (note);
  60655. state.noteOff (midiChannel, note);
  60656. keyPressUsed = true;
  60657. }
  60658. }
  60659. }
  60660. return keyPressUsed;
  60661. }
  60662. void MidiKeyboardComponent::focusLost (FocusChangeType)
  60663. {
  60664. resetAnyKeysInUse();
  60665. }
  60666. END_JUCE_NAMESPACE
  60667. /*** End of inlined file: juce_MidiKeyboardComponent.cpp ***/
  60668. /*** Start of inlined file: juce_OpenGLComponent.cpp ***/
  60669. #if JUCE_OPENGL
  60670. BEGIN_JUCE_NAMESPACE
  60671. extern void juce_glViewport (const int w, const int h);
  60672. OpenGLPixelFormat::OpenGLPixelFormat (const int bitsPerRGBComponent,
  60673. const int alphaBits_,
  60674. const int depthBufferBits_,
  60675. const int stencilBufferBits_) throw()
  60676. : redBits (bitsPerRGBComponent),
  60677. greenBits (bitsPerRGBComponent),
  60678. blueBits (bitsPerRGBComponent),
  60679. alphaBits (alphaBits_),
  60680. depthBufferBits (depthBufferBits_),
  60681. stencilBufferBits (stencilBufferBits_),
  60682. accumulationBufferRedBits (0),
  60683. accumulationBufferGreenBits (0),
  60684. accumulationBufferBlueBits (0),
  60685. accumulationBufferAlphaBits (0),
  60686. fullSceneAntiAliasingNumSamples (0)
  60687. {
  60688. }
  60689. bool OpenGLPixelFormat::operator== (const OpenGLPixelFormat& other) const throw()
  60690. {
  60691. return memcmp (this, &other, sizeof (other)) == 0;
  60692. }
  60693. static VoidArray knownContexts;
  60694. OpenGLContext::OpenGLContext() throw()
  60695. {
  60696. knownContexts.add (this);
  60697. }
  60698. OpenGLContext::~OpenGLContext()
  60699. {
  60700. knownContexts.removeValue (this);
  60701. }
  60702. OpenGLContext* OpenGLContext::getCurrentContext()
  60703. {
  60704. for (int i = knownContexts.size(); --i >= 0;)
  60705. {
  60706. OpenGLContext* const oglc = (OpenGLContext*) knownContexts.getUnchecked(i);
  60707. if (oglc->isActive())
  60708. return oglc;
  60709. }
  60710. return 0;
  60711. }
  60712. class OpenGLComponent::OpenGLComponentWatcher : public ComponentMovementWatcher
  60713. {
  60714. public:
  60715. OpenGLComponentWatcher (OpenGLComponent* const owner_)
  60716. : ComponentMovementWatcher (owner_),
  60717. owner (owner_),
  60718. wasShowing (false)
  60719. {
  60720. }
  60721. ~OpenGLComponentWatcher() {}
  60722. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  60723. {
  60724. owner->updateContextPosition();
  60725. }
  60726. void componentPeerChanged()
  60727. {
  60728. const ScopedLock sl (owner->getContextLock());
  60729. owner->deleteContext();
  60730. }
  60731. void componentVisibilityChanged (Component&)
  60732. {
  60733. const bool isShowingNow = owner->isShowing();
  60734. if (wasShowing != isShowingNow)
  60735. {
  60736. wasShowing = isShowingNow;
  60737. owner->updateContextPosition();
  60738. }
  60739. }
  60740. juce_UseDebuggingNewOperator
  60741. private:
  60742. OpenGLComponent* const owner;
  60743. bool wasShowing;
  60744. };
  60745. OpenGLComponent::OpenGLComponent()
  60746. : context (0),
  60747. contextToShareListsWith (0),
  60748. needToUpdateViewport (true)
  60749. {
  60750. setOpaque (true);
  60751. componentWatcher = new OpenGLComponentWatcher (this);
  60752. }
  60753. OpenGLComponent::~OpenGLComponent()
  60754. {
  60755. deleteContext();
  60756. componentWatcher = 0;
  60757. }
  60758. void OpenGLComponent::deleteContext()
  60759. {
  60760. const ScopedLock sl (contextLock);
  60761. deleteAndZero (context);
  60762. }
  60763. void OpenGLComponent::updateContextPosition()
  60764. {
  60765. needToUpdateViewport = true;
  60766. if (getWidth() > 0 && getHeight() > 0)
  60767. {
  60768. Component* const topComp = getTopLevelComponent();
  60769. if (topComp->getPeer() != 0)
  60770. {
  60771. const ScopedLock sl (contextLock);
  60772. if (context != 0)
  60773. context->updateWindowPosition (getScreenX() - topComp->getScreenX(),
  60774. getScreenY() - topComp->getScreenY(),
  60775. getWidth(),
  60776. getHeight(),
  60777. topComp->getHeight());
  60778. }
  60779. }
  60780. }
  60781. const OpenGLPixelFormat OpenGLComponent::getPixelFormat() const
  60782. {
  60783. OpenGLPixelFormat pf;
  60784. const ScopedLock sl (contextLock);
  60785. if (context != 0)
  60786. pf = context->getPixelFormat();
  60787. return pf;
  60788. }
  60789. void OpenGLComponent::setPixelFormat (const OpenGLPixelFormat& formatToUse)
  60790. {
  60791. if (! (preferredPixelFormat == formatToUse))
  60792. {
  60793. const ScopedLock sl (contextLock);
  60794. deleteContext();
  60795. preferredPixelFormat = formatToUse;
  60796. }
  60797. }
  60798. void OpenGLComponent::shareWith (OpenGLContext* c)
  60799. {
  60800. if (contextToShareListsWith != c)
  60801. {
  60802. const ScopedLock sl (contextLock);
  60803. deleteContext();
  60804. contextToShareListsWith = c;
  60805. }
  60806. }
  60807. bool OpenGLComponent::makeCurrentContextActive()
  60808. {
  60809. if (context == 0)
  60810. {
  60811. const ScopedLock sl (contextLock);
  60812. if (isShowing() && getTopLevelComponent()->getPeer() != 0)
  60813. {
  60814. context = OpenGLContext::createContextForWindow (this,
  60815. preferredPixelFormat,
  60816. contextToShareListsWith);
  60817. if (context != 0)
  60818. {
  60819. updateContextPosition();
  60820. if (context->makeActive())
  60821. newOpenGLContextCreated();
  60822. }
  60823. }
  60824. }
  60825. return context != 0 && context->makeActive();
  60826. }
  60827. void OpenGLComponent::makeCurrentContextInactive()
  60828. {
  60829. if (context != 0)
  60830. context->makeInactive();
  60831. }
  60832. bool OpenGLComponent::isActiveContext() const throw()
  60833. {
  60834. return context != 0 && context->isActive();
  60835. }
  60836. void OpenGLComponent::swapBuffers()
  60837. {
  60838. if (context != 0)
  60839. context->swapBuffers();
  60840. }
  60841. void OpenGLComponent::paint (Graphics&)
  60842. {
  60843. if (renderAndSwapBuffers())
  60844. {
  60845. ComponentPeer* const peer = getPeer();
  60846. if (peer != 0)
  60847. {
  60848. peer->addMaskedRegion (getScreenX() - peer->getScreenX(),
  60849. getScreenY() - peer->getScreenY(),
  60850. getWidth(), getHeight());
  60851. }
  60852. }
  60853. }
  60854. bool OpenGLComponent::renderAndSwapBuffers()
  60855. {
  60856. const ScopedLock sl (contextLock);
  60857. if (! makeCurrentContextActive())
  60858. return false;
  60859. if (needToUpdateViewport)
  60860. {
  60861. needToUpdateViewport = false;
  60862. juce_glViewport (getWidth(), getHeight());
  60863. }
  60864. renderOpenGL();
  60865. swapBuffers();
  60866. return true;
  60867. }
  60868. void OpenGLComponent::internalRepaint (int x, int y, int w, int h)
  60869. {
  60870. Component::internalRepaint (x, y, w, h);
  60871. if (context != 0)
  60872. context->repaint();
  60873. }
  60874. END_JUCE_NAMESPACE
  60875. #endif
  60876. /*** End of inlined file: juce_OpenGLComponent.cpp ***/
  60877. /*** Start of inlined file: juce_PreferencesPanel.cpp ***/
  60878. BEGIN_JUCE_NAMESPACE
  60879. PreferencesPanel::PreferencesPanel()
  60880. : buttonSize (70)
  60881. {
  60882. }
  60883. PreferencesPanel::~PreferencesPanel()
  60884. {
  60885. currentPage = 0;
  60886. deleteAllChildren();
  60887. }
  60888. void PreferencesPanel::addSettingsPage (const String& title,
  60889. const Drawable* icon,
  60890. const Drawable* overIcon,
  60891. const Drawable* downIcon)
  60892. {
  60893. DrawableButton* button = new DrawableButton (title, DrawableButton::ImageAboveTextLabel);
  60894. button->setImages (icon, overIcon, downIcon);
  60895. button->setRadioGroupId (1);
  60896. button->addButtonListener (this);
  60897. button->setClickingTogglesState (true);
  60898. button->setWantsKeyboardFocus (false);
  60899. addAndMakeVisible (button);
  60900. resized();
  60901. if (currentPage == 0)
  60902. setCurrentPage (title);
  60903. }
  60904. void PreferencesPanel::addSettingsPage (const String& title,
  60905. const char* imageData,
  60906. const int imageDataSize)
  60907. {
  60908. DrawableImage icon, iconOver, iconDown;
  60909. icon.setImage (ImageCache::getFromMemory (imageData, imageDataSize), true);
  60910. iconOver.setImage (ImageCache::getFromMemory (imageData, imageDataSize), true);
  60911. iconOver.setOverlayColour (Colours::black.withAlpha (0.12f));
  60912. iconDown.setImage (ImageCache::getFromMemory (imageData, imageDataSize), true);
  60913. iconDown.setOverlayColour (Colours::black.withAlpha (0.25f));
  60914. addSettingsPage (title, &icon, &iconOver, &iconDown);
  60915. }
  60916. class PrefsDialogWindow : public DialogWindow
  60917. {
  60918. public:
  60919. PrefsDialogWindow (const String& dialogtitle,
  60920. const Colour& backgroundColour)
  60921. : DialogWindow (dialogtitle, backgroundColour, true)
  60922. {
  60923. }
  60924. ~PrefsDialogWindow()
  60925. {
  60926. }
  60927. void closeButtonPressed()
  60928. {
  60929. exitModalState (0);
  60930. }
  60931. private:
  60932. PrefsDialogWindow (const PrefsDialogWindow&);
  60933. const PrefsDialogWindow& operator= (const PrefsDialogWindow&);
  60934. };
  60935. void PreferencesPanel::showInDialogBox (const String& dialogtitle,
  60936. int dialogWidth,
  60937. int dialogHeight,
  60938. const Colour& backgroundColour)
  60939. {
  60940. setSize (dialogWidth, dialogHeight);
  60941. PrefsDialogWindow dw (dialogtitle, backgroundColour);
  60942. dw.setContentComponent (this, true, true);
  60943. dw.centreAroundComponent (0, dw.getWidth(), dw.getHeight());
  60944. dw.runModalLoop();
  60945. dw.setContentComponent (0, false, false);
  60946. }
  60947. void PreferencesPanel::resized()
  60948. {
  60949. int x = 0;
  60950. for (int i = 0; i < getNumChildComponents(); ++i)
  60951. {
  60952. Component* c = getChildComponent (i);
  60953. if (dynamic_cast <DrawableButton*> (c) == 0)
  60954. {
  60955. c->setBounds (0, buttonSize + 5, getWidth(), getHeight() - buttonSize - 5);
  60956. }
  60957. else
  60958. {
  60959. c->setBounds (x, 0, buttonSize, buttonSize);
  60960. x += buttonSize;
  60961. }
  60962. }
  60963. }
  60964. void PreferencesPanel::paint (Graphics& g)
  60965. {
  60966. g.setColour (Colours::grey);
  60967. g.fillRect (0, buttonSize + 2, getWidth(), 1);
  60968. }
  60969. void PreferencesPanel::setCurrentPage (const String& pageName)
  60970. {
  60971. if (currentPageName != pageName)
  60972. {
  60973. currentPageName = pageName;
  60974. currentPage = 0;
  60975. currentPage = createComponentForPage (pageName);
  60976. if (currentPage != 0)
  60977. {
  60978. addAndMakeVisible (currentPage);
  60979. currentPage->toBack();
  60980. resized();
  60981. }
  60982. for (int i = 0; i < getNumChildComponents(); ++i)
  60983. {
  60984. DrawableButton* db = dynamic_cast <DrawableButton*> (getChildComponent (i));
  60985. if (db != 0 && db->getName() == pageName)
  60986. {
  60987. db->setToggleState (true, false);
  60988. break;
  60989. }
  60990. }
  60991. }
  60992. }
  60993. void PreferencesPanel::buttonClicked (Button*)
  60994. {
  60995. for (int i = 0; i < getNumChildComponents(); ++i)
  60996. {
  60997. DrawableButton* db = dynamic_cast <DrawableButton*> (getChildComponent (i));
  60998. if (db != 0 && db->getToggleState())
  60999. {
  61000. setCurrentPage (db->getName());
  61001. break;
  61002. }
  61003. }
  61004. }
  61005. END_JUCE_NAMESPACE
  61006. /*** End of inlined file: juce_PreferencesPanel.cpp ***/
  61007. /*** Start of inlined file: juce_SystemTrayIconComponent.cpp ***/
  61008. #if JUCE_WINDOWS || JUCE_LINUX
  61009. BEGIN_JUCE_NAMESPACE
  61010. SystemTrayIconComponent::SystemTrayIconComponent()
  61011. {
  61012. addToDesktop (0);
  61013. }
  61014. SystemTrayIconComponent::~SystemTrayIconComponent()
  61015. {
  61016. }
  61017. END_JUCE_NAMESPACE
  61018. #endif
  61019. /*** End of inlined file: juce_SystemTrayIconComponent.cpp ***/
  61020. /*** Start of inlined file: juce_AlertWindow.cpp ***/
  61021. BEGIN_JUCE_NAMESPACE
  61022. static const int titleH = 24;
  61023. static const int iconWidth = 80;
  61024. class AlertWindowTextEditor : public TextEditor
  61025. {
  61026. public:
  61027. static const tchar passwordChar;
  61028. AlertWindowTextEditor (const String& name, const bool isPasswordBox)
  61029. : TextEditor (name, isPasswordBox ? passwordChar : 0)
  61030. {
  61031. setSelectAllWhenFocused (true);
  61032. }
  61033. ~AlertWindowTextEditor()
  61034. {
  61035. }
  61036. void returnPressed()
  61037. {
  61038. // pass these up the component hierarchy to be trigger the buttons
  61039. getParentComponent()->keyPressed (KeyPress (KeyPress::returnKey, 0, T('\n')));
  61040. }
  61041. void escapePressed()
  61042. {
  61043. // pass these up the component hierarchy to be trigger the buttons
  61044. getParentComponent()->keyPressed (KeyPress (KeyPress::escapeKey, 0, 0));
  61045. }
  61046. private:
  61047. AlertWindowTextEditor (const AlertWindowTextEditor&);
  61048. const AlertWindowTextEditor& operator= (const AlertWindowTextEditor&);
  61049. };
  61050. #if JUCE_LINUX
  61051. const tchar AlertWindowTextEditor::passwordChar = 0x2022;
  61052. #else
  61053. const tchar AlertWindowTextEditor::passwordChar = 0x25cf;
  61054. #endif
  61055. AlertWindow::AlertWindow (const String& title,
  61056. const String& message,
  61057. AlertIconType iconType,
  61058. Component* associatedComponent_)
  61059. : TopLevelWindow (title, true),
  61060. alertIconType (iconType),
  61061. associatedComponent (associatedComponent_)
  61062. {
  61063. if (message.isEmpty())
  61064. text = T(" "); // to force an update if the message is empty
  61065. setMessage (message);
  61066. for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
  61067. {
  61068. Component* const c = Desktop::getInstance().getComponent (i);
  61069. if (c != 0 && c->isAlwaysOnTop() && c->isShowing())
  61070. {
  61071. setAlwaysOnTop (true);
  61072. break;
  61073. }
  61074. }
  61075. if (JUCEApplication::getInstance() == 0)
  61076. setAlwaysOnTop (true); // for a plugin, make it always-on-top because the host windows are often top-level
  61077. lookAndFeelChanged();
  61078. constrainer.setMinimumOnscreenAmounts (0x10000, 0x10000, 0x10000, 0x10000);
  61079. }
  61080. AlertWindow::~AlertWindow()
  61081. {
  61082. for (int i = customComps.size(); --i >= 0;)
  61083. removeChildComponent ((Component*) customComps[i]);
  61084. deleteAllChildren();
  61085. }
  61086. void AlertWindow::userTriedToCloseWindow()
  61087. {
  61088. exitModalState (0);
  61089. }
  61090. void AlertWindow::setMessage (const String& message)
  61091. {
  61092. const String newMessage (message.substring (0, 2048));
  61093. if (text != newMessage)
  61094. {
  61095. text = newMessage;
  61096. font.setHeight (15.0f);
  61097. Font titleFont (font.getHeight() * 1.1f, Font::bold);
  61098. textLayout.setText (getName() + T("\n\n"), titleFont);
  61099. textLayout.appendText (text, font);
  61100. updateLayout (true);
  61101. repaint();
  61102. }
  61103. }
  61104. void AlertWindow::buttonClicked (Button* button)
  61105. {
  61106. for (int i = 0; i < buttons.size(); i++)
  61107. {
  61108. TextButton* const c = (TextButton*) buttons[i];
  61109. if (button->getName() == c->getName())
  61110. {
  61111. if (c->getParentComponent() != 0)
  61112. c->getParentComponent()->exitModalState (c->getCommandID());
  61113. break;
  61114. }
  61115. }
  61116. }
  61117. void AlertWindow::addButton (const String& name,
  61118. const int returnValue,
  61119. const KeyPress& shortcutKey1,
  61120. const KeyPress& shortcutKey2)
  61121. {
  61122. TextButton* const b = new TextButton (name, String::empty);
  61123. b->setWantsKeyboardFocus (true);
  61124. b->setMouseClickGrabsKeyboardFocus (false);
  61125. b->setCommandToTrigger (0, returnValue, false);
  61126. b->addShortcut (shortcutKey1);
  61127. b->addShortcut (shortcutKey2);
  61128. b->addButtonListener (this);
  61129. b->changeWidthToFitText (getLookAndFeel().getAlertWindowButtonHeight());
  61130. addAndMakeVisible (b, 0);
  61131. buttons.add (b);
  61132. updateLayout (false);
  61133. }
  61134. int AlertWindow::getNumButtons() const
  61135. {
  61136. return buttons.size();
  61137. }
  61138. void AlertWindow::addTextEditor (const String& name,
  61139. const String& initialContents,
  61140. const String& onScreenLabel,
  61141. const bool isPasswordBox)
  61142. {
  61143. AlertWindowTextEditor* const tc = new AlertWindowTextEditor (name, isPasswordBox);
  61144. tc->setColour (TextEditor::outlineColourId, findColour (ComboBox::outlineColourId));
  61145. tc->setFont (font);
  61146. tc->setText (initialContents);
  61147. tc->setCaretPosition (initialContents.length());
  61148. addAndMakeVisible (tc);
  61149. textBoxes.add (tc);
  61150. allComps.add (tc);
  61151. textboxNames.add (onScreenLabel);
  61152. updateLayout (false);
  61153. }
  61154. const String AlertWindow::getTextEditorContents (const String& nameOfTextEditor) const
  61155. {
  61156. for (int i = textBoxes.size(); --i >= 0;)
  61157. if (((TextEditor*)textBoxes[i])->getName() == nameOfTextEditor)
  61158. return ((TextEditor*)textBoxes[i])->getText();
  61159. return String::empty;
  61160. }
  61161. void AlertWindow::addComboBox (const String& name,
  61162. const StringArray& items,
  61163. const String& onScreenLabel)
  61164. {
  61165. ComboBox* const cb = new ComboBox (name);
  61166. for (int i = 0; i < items.size(); ++i)
  61167. cb->addItem (items[i], i + 1);
  61168. addAndMakeVisible (cb);
  61169. cb->setSelectedItemIndex (0);
  61170. comboBoxes.add (cb);
  61171. allComps.add (cb);
  61172. comboBoxNames.add (onScreenLabel);
  61173. updateLayout (false);
  61174. }
  61175. ComboBox* AlertWindow::getComboBoxComponent (const String& nameOfList) const
  61176. {
  61177. for (int i = comboBoxes.size(); --i >= 0;)
  61178. if (((ComboBox*) comboBoxes[i])->getName() == nameOfList)
  61179. return (ComboBox*) comboBoxes[i];
  61180. return 0;
  61181. }
  61182. class AlertTextComp : public TextEditor
  61183. {
  61184. AlertTextComp (const AlertTextComp&);
  61185. const AlertTextComp& operator= (const AlertTextComp&);
  61186. int bestWidth;
  61187. public:
  61188. AlertTextComp (const String& message,
  61189. const Font& font)
  61190. {
  61191. setReadOnly (true);
  61192. setMultiLine (true, true);
  61193. setCaretVisible (false);
  61194. setScrollbarsShown (true);
  61195. lookAndFeelChanged();
  61196. setWantsKeyboardFocus (false);
  61197. setFont (font);
  61198. setText (message, false);
  61199. bestWidth = 2 * (int) sqrt (font.getHeight() * font.getStringWidth (message));
  61200. setColour (TextEditor::backgroundColourId, Colours::transparentBlack);
  61201. setColour (TextEditor::outlineColourId, Colours::transparentBlack);
  61202. setColour (TextEditor::shadowColourId, Colours::transparentBlack);
  61203. }
  61204. ~AlertTextComp()
  61205. {
  61206. }
  61207. int getPreferredWidth() const throw() { return bestWidth; }
  61208. void updateLayout (const int width)
  61209. {
  61210. TextLayout text;
  61211. text.appendText (getText(), getFont());
  61212. text.layout (width - 8, Justification::topLeft, true);
  61213. setSize (width, jmin (width, text.getHeight() + (int) getFont().getHeight()));
  61214. }
  61215. };
  61216. void AlertWindow::addTextBlock (const String& text)
  61217. {
  61218. AlertTextComp* const c = new AlertTextComp (text, font);
  61219. textBlocks.add (c);
  61220. allComps.add (c);
  61221. addAndMakeVisible (c);
  61222. updateLayout (false);
  61223. }
  61224. void AlertWindow::addProgressBarComponent (double& progressValue)
  61225. {
  61226. ProgressBar* const pb = new ProgressBar (progressValue);
  61227. progressBars.add (pb);
  61228. allComps.add (pb);
  61229. addAndMakeVisible (pb);
  61230. updateLayout (false);
  61231. }
  61232. void AlertWindow::addCustomComponent (Component* const component)
  61233. {
  61234. customComps.add (component);
  61235. allComps.add (component);
  61236. addAndMakeVisible (component);
  61237. updateLayout (false);
  61238. }
  61239. int AlertWindow::getNumCustomComponents() const
  61240. {
  61241. return customComps.size();
  61242. }
  61243. Component* AlertWindow::getCustomComponent (const int index) const
  61244. {
  61245. return (Component*) customComps [index];
  61246. }
  61247. Component* AlertWindow::removeCustomComponent (const int index)
  61248. {
  61249. Component* const c = getCustomComponent (index);
  61250. if (c != 0)
  61251. {
  61252. customComps.removeValue (c);
  61253. allComps.removeValue (c);
  61254. removeChildComponent (c);
  61255. updateLayout (false);
  61256. }
  61257. return c;
  61258. }
  61259. void AlertWindow::paint (Graphics& g)
  61260. {
  61261. getLookAndFeel().drawAlertBox (g, *this, textArea, textLayout);
  61262. g.setColour (findColour (textColourId));
  61263. g.setFont (getLookAndFeel().getAlertWindowFont());
  61264. int i;
  61265. for (i = textBoxes.size(); --i >= 0;)
  61266. {
  61267. const TextEditor* const te = (TextEditor*) textBoxes[i];
  61268. g.drawFittedText (textboxNames[i],
  61269. te->getX(), te->getY() - 14,
  61270. te->getWidth(), 14,
  61271. Justification::centredLeft, 1);
  61272. }
  61273. for (i = comboBoxNames.size(); --i >= 0;)
  61274. {
  61275. const ComboBox* const cb = (ComboBox*) comboBoxes[i];
  61276. g.drawFittedText (comboBoxNames[i],
  61277. cb->getX(), cb->getY() - 14,
  61278. cb->getWidth(), 14,
  61279. Justification::centredLeft, 1);
  61280. }
  61281. for (i = customComps.size(); --i >= 0;)
  61282. {
  61283. const Component* const c = (Component*) customComps[i];
  61284. g.drawFittedText (c->getName(),
  61285. c->getX(), c->getY() - 14,
  61286. c->getWidth(), 14,
  61287. Justification::centredLeft, 1);
  61288. }
  61289. }
  61290. void AlertWindow::updateLayout (const bool onlyIncreaseSize)
  61291. {
  61292. const int wid = jmax (font.getStringWidth (text),
  61293. font.getStringWidth (getName()));
  61294. const int sw = (int) sqrt (font.getHeight() * wid);
  61295. int w = jmin (300 + sw * 2, (int) (getParentWidth() * 0.7f));
  61296. const int edgeGap = 10;
  61297. const int labelHeight = 18;
  61298. int iconSpace;
  61299. if (alertIconType == NoIcon)
  61300. {
  61301. textLayout.layout (w, Justification::horizontallyCentred, true);
  61302. iconSpace = 0;
  61303. }
  61304. else
  61305. {
  61306. textLayout.layout (w, Justification::left, true);
  61307. iconSpace = iconWidth;
  61308. }
  61309. w = jmax (350, textLayout.getWidth() + iconSpace + edgeGap * 4);
  61310. w = jmin (w, (int) (getParentWidth() * 0.7f));
  61311. const int textLayoutH = textLayout.getHeight();
  61312. const int textBottom = 16 + titleH + textLayoutH;
  61313. int h = textBottom;
  61314. int buttonW = 40;
  61315. int i;
  61316. for (i = 0; i < buttons.size(); ++i)
  61317. buttonW += 16 + ((const TextButton*) buttons[i])->getWidth();
  61318. w = jmax (buttonW, w);
  61319. h += (textBoxes.size() + comboBoxes.size() + progressBars.size()) * 50;
  61320. if (buttons.size() > 0)
  61321. h += 20 + ((TextButton*) buttons[0])->getHeight();
  61322. for (i = customComps.size(); --i >= 0;)
  61323. {
  61324. Component* c = (Component*) customComps[i];
  61325. w = jmax (w, (c->getWidth() * 100) / 80);
  61326. h += 10 + c->getHeight();
  61327. if (c->getName().isNotEmpty())
  61328. h += labelHeight;
  61329. }
  61330. for (i = textBlocks.size(); --i >= 0;)
  61331. {
  61332. const AlertTextComp* const ac = (AlertTextComp*) textBlocks[i];
  61333. w = jmax (w, ac->getPreferredWidth());
  61334. }
  61335. w = jmin (w, (int) (getParentWidth() * 0.7f));
  61336. for (i = textBlocks.size(); --i >= 0;)
  61337. {
  61338. AlertTextComp* const ac = (AlertTextComp*) textBlocks[i];
  61339. ac->updateLayout ((int) (w * 0.8f));
  61340. h += ac->getHeight() + 10;
  61341. }
  61342. h = jmin (getParentHeight() - 50, h);
  61343. if (onlyIncreaseSize)
  61344. {
  61345. w = jmax (w, getWidth());
  61346. h = jmax (h, getHeight());
  61347. }
  61348. if (! isVisible())
  61349. {
  61350. centreAroundComponent (associatedComponent, w, h);
  61351. }
  61352. else
  61353. {
  61354. const int cx = getX() + getWidth() / 2;
  61355. const int cy = getY() + getHeight() / 2;
  61356. setBounds (cx - w / 2,
  61357. cy - h / 2,
  61358. w, h);
  61359. }
  61360. textArea.setBounds (edgeGap, edgeGap, w - (edgeGap * 2), h - edgeGap);
  61361. const int spacer = 16;
  61362. int totalWidth = -spacer;
  61363. for (i = buttons.size(); --i >= 0;)
  61364. totalWidth += ((TextButton*) buttons[i])->getWidth() + spacer;
  61365. int x = (w - totalWidth) / 2;
  61366. int y = (int) (getHeight() * 0.95f);
  61367. for (i = 0; i < buttons.size(); ++i)
  61368. {
  61369. TextButton* const c = (TextButton*) buttons[i];
  61370. int ny = proportionOfHeight (0.95f) - c->getHeight();
  61371. c->setTopLeftPosition (x, ny);
  61372. if (ny < y)
  61373. y = ny;
  61374. x += c->getWidth() + spacer;
  61375. c->toFront (false);
  61376. }
  61377. y = textBottom;
  61378. for (i = 0; i < allComps.size(); ++i)
  61379. {
  61380. Component* const c = (Component*) allComps[i];
  61381. int h = 22;
  61382. const int comboIndex = comboBoxes.indexOf (c);
  61383. if (comboIndex >= 0 && comboBoxNames [comboIndex].isNotEmpty())
  61384. y += labelHeight;
  61385. const int tbIndex = textBoxes.indexOf (c);
  61386. if (tbIndex >= 0 && textboxNames[tbIndex].isNotEmpty())
  61387. y += labelHeight;
  61388. if (customComps.contains (c))
  61389. {
  61390. if (c->getName().isNotEmpty())
  61391. y += labelHeight;
  61392. c->setTopLeftPosition (proportionOfWidth (0.1f), y);
  61393. h = c->getHeight();
  61394. }
  61395. else if (textBlocks.contains (c))
  61396. {
  61397. c->setTopLeftPosition ((getWidth() - c->getWidth()) / 2, y);
  61398. h = c->getHeight();
  61399. }
  61400. else
  61401. {
  61402. c->setBounds (proportionOfWidth (0.1f), y, proportionOfWidth (0.8f), h);
  61403. }
  61404. y += h + 10;
  61405. }
  61406. setWantsKeyboardFocus (getNumChildComponents() == 0);
  61407. }
  61408. bool AlertWindow::containsAnyExtraComponents() const
  61409. {
  61410. return textBoxes.size()
  61411. + comboBoxes.size()
  61412. + progressBars.size()
  61413. + customComps.size() > 0;
  61414. }
  61415. void AlertWindow::mouseDown (const MouseEvent&)
  61416. {
  61417. dragger.startDraggingComponent (this, &constrainer);
  61418. }
  61419. void AlertWindow::mouseDrag (const MouseEvent& e)
  61420. {
  61421. dragger.dragComponent (this, e);
  61422. }
  61423. bool AlertWindow::keyPressed (const KeyPress& key)
  61424. {
  61425. for (int i = buttons.size(); --i >= 0;)
  61426. {
  61427. TextButton* const b = (TextButton*) buttons[i];
  61428. if (b->isRegisteredForShortcut (key))
  61429. {
  61430. b->triggerClick();
  61431. return true;
  61432. }
  61433. }
  61434. if (key.isKeyCode (KeyPress::escapeKey) && buttons.size() == 0)
  61435. {
  61436. exitModalState (0);
  61437. return true;
  61438. }
  61439. else if (key.isKeyCode (KeyPress::returnKey) && buttons.size() == 1)
  61440. {
  61441. ((TextButton*) buttons.getFirst())->triggerClick();
  61442. return true;
  61443. }
  61444. return false;
  61445. }
  61446. void AlertWindow::lookAndFeelChanged()
  61447. {
  61448. const int flags = getLookAndFeel().getAlertBoxWindowFlags();
  61449. setUsingNativeTitleBar ((flags & ComponentPeer::windowHasTitleBar) != 0);
  61450. setDropShadowEnabled (isOpaque() && (flags & ComponentPeer::windowHasDropShadow) != 0);
  61451. }
  61452. int AlertWindow::getDesktopWindowStyleFlags() const
  61453. {
  61454. return getLookAndFeel().getAlertBoxWindowFlags();
  61455. }
  61456. struct AlertWindowInfo
  61457. {
  61458. String title, message, button1, button2, button3;
  61459. AlertWindow::AlertIconType iconType;
  61460. int numButtons;
  61461. Component* associatedComponent;
  61462. int run() const
  61463. {
  61464. return (int) (pointer_sized_int)
  61465. MessageManager::getInstance()->callFunctionOnMessageThread (showCallback, (void*) this);
  61466. }
  61467. private:
  61468. int show() const
  61469. {
  61470. jassert (associatedComponent == 0 || associatedComponent->isValidComponent()); // has your comp been deleted?
  61471. LookAndFeel& lf = associatedComponent->isValidComponent() ? associatedComponent->getLookAndFeel()
  61472. : LookAndFeel::getDefaultLookAndFeel();
  61473. ScopedPointer <Component> alertBox (lf.createAlertWindow (title, message, button1, button2, button3,
  61474. iconType, numButtons, associatedComponent));
  61475. jassert (alertBox != 0); // you have to return one of these!
  61476. return alertBox->runModalLoop();
  61477. }
  61478. static void* showCallback (void* userData)
  61479. {
  61480. return (void*) (pointer_sized_int) ((const AlertWindowInfo*) userData)->show();
  61481. }
  61482. };
  61483. void AlertWindow::showMessageBox (AlertIconType iconType,
  61484. const String& title,
  61485. const String& message,
  61486. const String& buttonText,
  61487. Component* associatedComponent)
  61488. {
  61489. AlertWindowInfo info;
  61490. info.title = title;
  61491. info.message = message;
  61492. info.button1 = buttonText.isEmpty() ? TRANS("ok") : buttonText;
  61493. info.iconType = iconType;
  61494. info.numButtons = 1;
  61495. info.associatedComponent = associatedComponent;
  61496. info.run();
  61497. }
  61498. bool AlertWindow::showOkCancelBox (AlertIconType iconType,
  61499. const String& title,
  61500. const String& message,
  61501. const String& button1Text,
  61502. const String& button2Text,
  61503. Component* associatedComponent)
  61504. {
  61505. AlertWindowInfo info;
  61506. info.title = title;
  61507. info.message = message;
  61508. info.button1 = button1Text.isEmpty() ? TRANS("ok") : button1Text;
  61509. info.button2 = button2Text.isEmpty() ? TRANS("cancel") : button2Text;
  61510. info.iconType = iconType;
  61511. info.numButtons = 2;
  61512. info.associatedComponent = associatedComponent;
  61513. return info.run() != 0;
  61514. }
  61515. int AlertWindow::showYesNoCancelBox (AlertIconType iconType,
  61516. const String& title,
  61517. const String& message,
  61518. const String& button1Text,
  61519. const String& button2Text,
  61520. const String& button3Text,
  61521. Component* associatedComponent)
  61522. {
  61523. AlertWindowInfo info;
  61524. info.title = title;
  61525. info.message = message;
  61526. info.button1 = button1Text.isEmpty() ? TRANS("yes") : button1Text;
  61527. info.button2 = button2Text.isEmpty() ? TRANS("no") : button2Text;
  61528. info.button3 = button3Text.isEmpty() ? TRANS("cancel") : button3Text;
  61529. info.iconType = iconType;
  61530. info.numButtons = 3;
  61531. info.associatedComponent = associatedComponent;
  61532. return info.run();
  61533. }
  61534. END_JUCE_NAMESPACE
  61535. /*** End of inlined file: juce_AlertWindow.cpp ***/
  61536. /*** Start of inlined file: juce_ComponentPeer.cpp ***/
  61537. BEGIN_JUCE_NAMESPACE
  61538. //#define JUCE_ENABLE_REPAINT_DEBUGGING 1
  61539. static const int fakeMouseMoveMessage = 0x7fff00ff;
  61540. static VoidArray heavyweightPeers;
  61541. ComponentPeer::ComponentPeer (Component* const component_,
  61542. const int styleFlags_) throw()
  61543. : component (component_),
  61544. styleFlags (styleFlags_),
  61545. lastPaintTime (0),
  61546. constrainer (0),
  61547. lastFocusedComponent (0),
  61548. lastDragAndDropCompUnderMouse (0),
  61549. fakeMouseMessageSent (false),
  61550. isWindowMinimised (false)
  61551. {
  61552. heavyweightPeers.add (this);
  61553. }
  61554. ComponentPeer::~ComponentPeer()
  61555. {
  61556. heavyweightPeers.removeValue (this);
  61557. Desktop::getInstance().triggerFocusCallback();
  61558. }
  61559. int ComponentPeer::getNumPeers() throw()
  61560. {
  61561. return heavyweightPeers.size();
  61562. }
  61563. ComponentPeer* ComponentPeer::getPeer (const int index) throw()
  61564. {
  61565. return (ComponentPeer*) heavyweightPeers [index];
  61566. }
  61567. ComponentPeer* ComponentPeer::getPeerFor (const Component* const component) throw()
  61568. {
  61569. for (int i = heavyweightPeers.size(); --i >= 0;)
  61570. {
  61571. ComponentPeer* const peer = (ComponentPeer*) heavyweightPeers.getUnchecked(i);
  61572. if (peer->getComponent() == component)
  61573. return peer;
  61574. }
  61575. return 0;
  61576. }
  61577. bool ComponentPeer::isValidPeer (const ComponentPeer* const peer) throw()
  61578. {
  61579. return heavyweightPeers.contains (const_cast <ComponentPeer*> (peer));
  61580. }
  61581. void ComponentPeer::updateCurrentModifiers() throw()
  61582. {
  61583. ModifierKeys::updateCurrentModifiers();
  61584. }
  61585. void ComponentPeer::handleMouseEnter (int x, int y, const int64 time)
  61586. {
  61587. jassert (component->isValidComponent());
  61588. updateCurrentModifiers();
  61589. Component* c = component->getComponentAt (x, y);
  61590. const ComponentDeletionWatcher deletionChecker (component);
  61591. if (c != Component::componentUnderMouse && Component::componentUnderMouse != 0)
  61592. {
  61593. jassert (Component::componentUnderMouse->isValidComponent());
  61594. const int oldX = x;
  61595. const int oldY = y;
  61596. component->relativePositionToOtherComponent (Component::componentUnderMouse, x, y);
  61597. Component::componentUnderMouse->internalMouseExit (x, y, time);
  61598. Component::componentUnderMouse = 0;
  61599. if (deletionChecker.hasBeenDeleted())
  61600. return;
  61601. c = component->getComponentAt (oldX, oldY);
  61602. }
  61603. Component::componentUnderMouse = c;
  61604. if (Component::componentUnderMouse != 0)
  61605. {
  61606. component->relativePositionToOtherComponent (Component::componentUnderMouse, x, y);
  61607. Component::componentUnderMouse->internalMouseEnter (x, y, time);
  61608. }
  61609. }
  61610. void ComponentPeer::handleMouseMove (int x, int y, const int64 time)
  61611. {
  61612. jassert (component->isValidComponent());
  61613. updateCurrentModifiers();
  61614. fakeMouseMessageSent = false;
  61615. const ComponentDeletionWatcher deletionChecker (component);
  61616. Component* c = component->getComponentAt (x, y);
  61617. if (c != Component::componentUnderMouse)
  61618. {
  61619. const int oldX = x;
  61620. const int oldY = y;
  61621. if (Component::componentUnderMouse != 0)
  61622. {
  61623. component->relativePositionToOtherComponent (Component::componentUnderMouse, x, y);
  61624. Component::componentUnderMouse->internalMouseExit (x, y, time);
  61625. x = oldX;
  61626. y = oldY;
  61627. Component::componentUnderMouse = 0;
  61628. if (deletionChecker.hasBeenDeleted())
  61629. return; // if this window has just been deleted..
  61630. c = component->getComponentAt (x, y);
  61631. }
  61632. Component::componentUnderMouse = c;
  61633. if (c != 0)
  61634. {
  61635. component->relativePositionToOtherComponent (c, x, y);
  61636. c->internalMouseEnter (x, y, time);
  61637. x = oldX;
  61638. y = oldY;
  61639. if (deletionChecker.hasBeenDeleted())
  61640. return; // if this window has just been deleted..
  61641. }
  61642. }
  61643. if (Component::componentUnderMouse != 0)
  61644. {
  61645. component->relativePositionToOtherComponent (Component::componentUnderMouse, x, y);
  61646. Component::componentUnderMouse->internalMouseMove (x, y, time);
  61647. }
  61648. }
  61649. void ComponentPeer::handleMouseDown (int x, int y, const int64 time)
  61650. {
  61651. Desktop::getInstance().incrementMouseClickCounter();
  61652. updateCurrentModifiers();
  61653. if (ModifierKeys::getCurrentModifiers().getNumMouseButtonsDown() == 1)
  61654. {
  61655. Component::componentUnderMouse = component->getComponentAt (x, y);
  61656. if (Component::componentUnderMouse != 0)
  61657. {
  61658. component->relativePositionToOtherComponent (Component::componentUnderMouse, x, y);
  61659. Component::componentUnderMouse->internalMouseDown (x, y, time);
  61660. }
  61661. }
  61662. }
  61663. void ComponentPeer::handleMouseDrag (int x, int y, const int64 time)
  61664. {
  61665. updateCurrentModifiers();
  61666. if (Component::componentUnderMouse != 0)
  61667. {
  61668. component->relativePositionToOtherComponent (Component::componentUnderMouse, x, y);
  61669. Component::componentUnderMouse->internalMouseDrag (x, y, time);
  61670. }
  61671. }
  61672. void ComponentPeer::handleMouseUp (const int oldModifiers, int x, int y, const int64 time)
  61673. {
  61674. updateCurrentModifiers();
  61675. if (ModifierKeys (oldModifiers).getNumMouseButtonsDown() == 1)
  61676. {
  61677. const ComponentDeletionWatcher deletionChecker (component);
  61678. Component* c = component->getComponentAt (x, y);
  61679. if (c != Component::componentUnderMouse)
  61680. {
  61681. const int oldX = x;
  61682. const int oldY = y;
  61683. if (Component::componentUnderMouse != 0)
  61684. {
  61685. component->relativePositionToOtherComponent (Component::componentUnderMouse, x, y);
  61686. Component::componentUnderMouse->internalMouseUp (oldModifiers, x, y, time);
  61687. x = oldX;
  61688. y = oldY;
  61689. if (Component::componentUnderMouse != 0)
  61690. Component::componentUnderMouse->internalMouseExit (x, y, time);
  61691. if (deletionChecker.hasBeenDeleted())
  61692. return;
  61693. c = component->getComponentAt (oldX, oldY);
  61694. }
  61695. Component::componentUnderMouse = c;
  61696. if (Component::componentUnderMouse != 0)
  61697. {
  61698. component->relativePositionToOtherComponent (Component::componentUnderMouse, x, y);
  61699. Component::componentUnderMouse->internalMouseEnter (x, y, time);
  61700. }
  61701. }
  61702. else
  61703. {
  61704. if (Component::componentUnderMouse != 0)
  61705. {
  61706. component->relativePositionToOtherComponent (Component::componentUnderMouse, x, y);
  61707. Component::componentUnderMouse->internalMouseUp (oldModifiers, x, y, time);
  61708. }
  61709. }
  61710. }
  61711. }
  61712. void ComponentPeer::handleMouseExit (int x, int y, const int64 time)
  61713. {
  61714. jassert (component->isValidComponent());
  61715. updateCurrentModifiers();
  61716. if (Component::componentUnderMouse != 0)
  61717. {
  61718. component->relativePositionToOtherComponent (Component::componentUnderMouse, x, y);
  61719. Component::componentUnderMouse->internalMouseExit (x, y, time);
  61720. Component::componentUnderMouse = 0;
  61721. }
  61722. }
  61723. void ComponentPeer::handleMouseWheel (const int amountX, const int amountY, const int64 time)
  61724. {
  61725. updateCurrentModifiers();
  61726. if (Component::componentUnderMouse != 0)
  61727. Component::componentUnderMouse->internalMouseWheel (amountX, amountY, time);
  61728. }
  61729. void ComponentPeer::sendFakeMouseMove() throw()
  61730. {
  61731. if ((! fakeMouseMessageSent)
  61732. && component->flags.hasHeavyweightPeerFlag
  61733. && ! ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown())
  61734. {
  61735. if (! isMinimised())
  61736. {
  61737. int realX, realY, realW, realH;
  61738. getBounds (realX, realY, realW, realH);
  61739. component->bounds_.setBounds (realX, realY, realW, realH);
  61740. }
  61741. int x, y;
  61742. component->getMouseXYRelative (x, y);
  61743. if (((unsigned int) x) < (unsigned int) component->getWidth()
  61744. && ((unsigned int) y) < (unsigned int) component->getHeight()
  61745. && contains (x, y, false))
  61746. {
  61747. postMessage (new Message (fakeMouseMoveMessage, x, y, 0));
  61748. }
  61749. fakeMouseMessageSent = true;
  61750. }
  61751. }
  61752. void ComponentPeer::handleMessage (const Message& message)
  61753. {
  61754. if (message.intParameter1 == fakeMouseMoveMessage)
  61755. {
  61756. if (! ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown())
  61757. handleMouseMove (message.intParameter2,
  61758. message.intParameter3,
  61759. Time::currentTimeMillis());
  61760. }
  61761. }
  61762. void ComponentPeer::handlePaint (LowLevelGraphicsContext& contextToPaintTo)
  61763. {
  61764. Graphics g (&contextToPaintTo);
  61765. #if JUCE_ENABLE_REPAINT_DEBUGGING
  61766. g.saveState();
  61767. #endif
  61768. JUCE_TRY
  61769. {
  61770. component->paintEntireComponent (g);
  61771. }
  61772. JUCE_CATCH_EXCEPTION
  61773. #if JUCE_ENABLE_REPAINT_DEBUGGING
  61774. // enabling this code will fill all areas that get repainted with a colour overlay, to show
  61775. // clearly when things are being repainted.
  61776. {
  61777. g.restoreState();
  61778. g.fillAll (Colour ((uint8) Random::getSystemRandom().nextInt (255),
  61779. (uint8) Random::getSystemRandom().nextInt (255),
  61780. (uint8) Random::getSystemRandom().nextInt (255),
  61781. (uint8) 0x50));
  61782. }
  61783. #endif
  61784. }
  61785. bool ComponentPeer::handleKeyPress (const int keyCode,
  61786. const juce_wchar textCharacter)
  61787. {
  61788. updateCurrentModifiers();
  61789. Component* target = Component::currentlyFocusedComponent->isValidComponent()
  61790. ? Component::currentlyFocusedComponent
  61791. : component;
  61792. if (target->isCurrentlyBlockedByAnotherModalComponent())
  61793. {
  61794. Component* const currentModalComp = Component::getCurrentlyModalComponent();
  61795. if (currentModalComp != 0)
  61796. target = currentModalComp;
  61797. }
  61798. const KeyPress keyInfo (keyCode,
  61799. ModifierKeys::getCurrentModifiers().getRawFlags()
  61800. & ModifierKeys::allKeyboardModifiers,
  61801. textCharacter);
  61802. bool keyWasUsed = false;
  61803. while (target != 0)
  61804. {
  61805. const ComponentDeletionWatcher deletionChecker (target);
  61806. if (target->keyListeners_ != 0)
  61807. {
  61808. for (int i = target->keyListeners_->size(); --i >= 0;)
  61809. {
  61810. keyWasUsed = ((KeyListener*) target->keyListeners_->getUnchecked(i))->keyPressed (keyInfo, target);
  61811. if (keyWasUsed || deletionChecker.hasBeenDeleted())
  61812. return keyWasUsed;
  61813. i = jmin (i, target->keyListeners_->size());
  61814. }
  61815. }
  61816. keyWasUsed = target->keyPressed (keyInfo);
  61817. if (keyWasUsed || deletionChecker.hasBeenDeleted())
  61818. break;
  61819. if (keyInfo.isKeyCode (KeyPress::tabKey) && Component::getCurrentlyFocusedComponent() != 0)
  61820. {
  61821. Component* const currentlyFocused = Component::getCurrentlyFocusedComponent();
  61822. currentlyFocused->moveKeyboardFocusToSibling (! keyInfo.getModifiers().isShiftDown());
  61823. keyWasUsed = (currentlyFocused != Component::getCurrentlyFocusedComponent());
  61824. break;
  61825. }
  61826. target = target->parentComponent_;
  61827. }
  61828. return keyWasUsed;
  61829. }
  61830. bool ComponentPeer::handleKeyUpOrDown (const bool isKeyDown)
  61831. {
  61832. updateCurrentModifiers();
  61833. Component* target = Component::currentlyFocusedComponent->isValidComponent()
  61834. ? Component::currentlyFocusedComponent
  61835. : component;
  61836. if (target->isCurrentlyBlockedByAnotherModalComponent())
  61837. {
  61838. Component* const currentModalComp = Component::getCurrentlyModalComponent();
  61839. if (currentModalComp != 0)
  61840. target = currentModalComp;
  61841. }
  61842. bool keyWasUsed = false;
  61843. while (target != 0)
  61844. {
  61845. const ComponentDeletionWatcher deletionChecker (target);
  61846. keyWasUsed = target->keyStateChanged (isKeyDown);
  61847. if (keyWasUsed || deletionChecker.hasBeenDeleted())
  61848. break;
  61849. if (target->keyListeners_ != 0)
  61850. {
  61851. for (int i = target->keyListeners_->size(); --i >= 0;)
  61852. {
  61853. keyWasUsed = ((KeyListener*) target->keyListeners_->getUnchecked(i))->keyStateChanged (isKeyDown, target);
  61854. if (keyWasUsed || deletionChecker.hasBeenDeleted())
  61855. return keyWasUsed;
  61856. i = jmin (i, target->keyListeners_->size());
  61857. }
  61858. }
  61859. target = target->parentComponent_;
  61860. }
  61861. return keyWasUsed;
  61862. }
  61863. void ComponentPeer::handleModifierKeysChange()
  61864. {
  61865. updateCurrentModifiers();
  61866. Component* target = Component::getComponentUnderMouse();
  61867. if (target == 0)
  61868. target = Component::getCurrentlyFocusedComponent();
  61869. if (target == 0)
  61870. target = component;
  61871. if (target->isValidComponent())
  61872. target->internalModifierKeysChanged();
  61873. }
  61874. void ComponentPeer::handleBroughtToFront()
  61875. {
  61876. updateCurrentModifiers();
  61877. if (component != 0)
  61878. component->internalBroughtToFront();
  61879. }
  61880. void ComponentPeer::setConstrainer (ComponentBoundsConstrainer* const newConstrainer) throw()
  61881. {
  61882. constrainer = newConstrainer;
  61883. }
  61884. void ComponentPeer::handleMovedOrResized()
  61885. {
  61886. jassert (component->isValidComponent());
  61887. updateCurrentModifiers();
  61888. const bool nowMinimised = isMinimised();
  61889. if (component->flags.hasHeavyweightPeerFlag && ! nowMinimised)
  61890. {
  61891. const ComponentDeletionWatcher deletionChecker (component);
  61892. int realX, realY, realW, realH;
  61893. getBounds (realX, realY, realW, realH);
  61894. const bool wasMoved = (component->getX() != realX || component->getY() != realY);
  61895. const bool wasResized = (component->getWidth() != realW || component->getHeight() != realH);
  61896. if (wasMoved || wasResized)
  61897. {
  61898. component->bounds_.setBounds (realX, realY, realW, realH);
  61899. if (wasResized)
  61900. component->repaint();
  61901. component->sendMovedResizedMessages (wasMoved, wasResized);
  61902. if (deletionChecker.hasBeenDeleted())
  61903. return;
  61904. }
  61905. }
  61906. if (isWindowMinimised != nowMinimised)
  61907. {
  61908. isWindowMinimised = nowMinimised;
  61909. component->minimisationStateChanged (nowMinimised);
  61910. component->sendVisibilityChangeMessage();
  61911. }
  61912. if (! isFullScreen())
  61913. lastNonFullscreenBounds = component->getBounds();
  61914. }
  61915. void ComponentPeer::handleFocusGain()
  61916. {
  61917. updateCurrentModifiers();
  61918. if (component->isParentOf (lastFocusedComponent))
  61919. {
  61920. Component::currentlyFocusedComponent = lastFocusedComponent;
  61921. Desktop::getInstance().triggerFocusCallback();
  61922. lastFocusedComponent->internalFocusGain (Component::focusChangedDirectly);
  61923. }
  61924. else
  61925. {
  61926. if (! component->isCurrentlyBlockedByAnotherModalComponent())
  61927. component->grabKeyboardFocus();
  61928. else
  61929. Component::bringModalComponentToFront();
  61930. }
  61931. }
  61932. void ComponentPeer::handleFocusLoss()
  61933. {
  61934. updateCurrentModifiers();
  61935. if (component->hasKeyboardFocus (true))
  61936. {
  61937. lastFocusedComponent = Component::currentlyFocusedComponent;
  61938. if (lastFocusedComponent != 0)
  61939. {
  61940. Component::currentlyFocusedComponent = 0;
  61941. Desktop::getInstance().triggerFocusCallback();
  61942. lastFocusedComponent->internalFocusLoss (Component::focusChangedByMouseClick);
  61943. }
  61944. }
  61945. }
  61946. Component* ComponentPeer::getLastFocusedSubcomponent() const throw()
  61947. {
  61948. return (component->isParentOf (lastFocusedComponent) && lastFocusedComponent->isShowing())
  61949. ? lastFocusedComponent
  61950. : component;
  61951. }
  61952. void ComponentPeer::handleScreenSizeChange()
  61953. {
  61954. updateCurrentModifiers();
  61955. component->parentSizeChanged();
  61956. handleMovedOrResized();
  61957. }
  61958. void ComponentPeer::setNonFullScreenBounds (const Rectangle<int>& newBounds) throw()
  61959. {
  61960. lastNonFullscreenBounds = newBounds;
  61961. }
  61962. const Rectangle<int>& ComponentPeer::getNonFullScreenBounds() const throw()
  61963. {
  61964. return lastNonFullscreenBounds;
  61965. }
  61966. static FileDragAndDropTarget* findDragAndDropTarget (Component* c,
  61967. const StringArray& files,
  61968. FileDragAndDropTarget* const lastOne)
  61969. {
  61970. while (c != 0)
  61971. {
  61972. FileDragAndDropTarget* const t = dynamic_cast <FileDragAndDropTarget*> (c);
  61973. if (t != 0 && (t == lastOne || t->isInterestedInFileDrag (files)))
  61974. return t;
  61975. c = c->getParentComponent();
  61976. }
  61977. return 0;
  61978. }
  61979. void ComponentPeer::handleFileDragMove (const StringArray& files, int x, int y)
  61980. {
  61981. updateCurrentModifiers();
  61982. FileDragAndDropTarget* lastTarget = 0;
  61983. if (dragAndDropTargetComponent != 0 && ! dragAndDropTargetComponent->hasBeenDeleted())
  61984. lastTarget = const_cast <FileDragAndDropTarget*> (dynamic_cast <const FileDragAndDropTarget*> (dragAndDropTargetComponent->getComponent()));
  61985. FileDragAndDropTarget* newTarget = 0;
  61986. Component* const compUnderMouse = component->getComponentAt (x, y);
  61987. if (compUnderMouse != lastDragAndDropCompUnderMouse)
  61988. {
  61989. lastDragAndDropCompUnderMouse = compUnderMouse;
  61990. newTarget = findDragAndDropTarget (compUnderMouse, files, lastTarget);
  61991. if (newTarget != lastTarget)
  61992. {
  61993. if (lastTarget != 0)
  61994. lastTarget->fileDragExit (files);
  61995. dragAndDropTargetComponent = 0;
  61996. if (newTarget != 0)
  61997. {
  61998. Component* const targetComp = dynamic_cast <Component*> (newTarget);
  61999. int mx = x, my = y;
  62000. component->relativePositionToOtherComponent (targetComp, mx, my);
  62001. dragAndDropTargetComponent = new ComponentDeletionWatcher (dynamic_cast <Component*> (newTarget));
  62002. newTarget->fileDragEnter (files, mx, my);
  62003. }
  62004. }
  62005. }
  62006. else
  62007. {
  62008. newTarget = lastTarget;
  62009. }
  62010. if (newTarget != 0)
  62011. {
  62012. Component* const targetComp = dynamic_cast <Component*> (newTarget);
  62013. component->relativePositionToOtherComponent (targetComp, x, y);
  62014. newTarget->fileDragMove (files, x, y);
  62015. }
  62016. }
  62017. void ComponentPeer::handleFileDragExit (const StringArray& files)
  62018. {
  62019. handleFileDragMove (files, -1, -1);
  62020. jassert (dragAndDropTargetComponent == 0);
  62021. lastDragAndDropCompUnderMouse = 0;
  62022. }
  62023. void ComponentPeer::handleFileDragDrop (const StringArray& files, int x, int y)
  62024. {
  62025. handleFileDragMove (files, x, y);
  62026. if (dragAndDropTargetComponent != 0 && ! dragAndDropTargetComponent->hasBeenDeleted())
  62027. {
  62028. FileDragAndDropTarget* const target = const_cast <FileDragAndDropTarget*> (dynamic_cast <const FileDragAndDropTarget*> (dragAndDropTargetComponent->getComponent()));
  62029. dragAndDropTargetComponent = 0;
  62030. lastDragAndDropCompUnderMouse = 0;
  62031. if (target != 0)
  62032. {
  62033. Component* const targetComp = dynamic_cast <Component*> (target);
  62034. if (targetComp->isCurrentlyBlockedByAnotherModalComponent())
  62035. {
  62036. targetComp->internalModalInputAttempt();
  62037. if (targetComp->isCurrentlyBlockedByAnotherModalComponent())
  62038. return;
  62039. }
  62040. component->relativePositionToOtherComponent (targetComp, x, y);
  62041. target->filesDropped (files, x, y);
  62042. }
  62043. }
  62044. }
  62045. void ComponentPeer::handleUserClosingWindow()
  62046. {
  62047. updateCurrentModifiers();
  62048. component->userTriedToCloseWindow();
  62049. }
  62050. void ComponentPeer::bringModalComponentToFront()
  62051. {
  62052. Component::bringModalComponentToFront();
  62053. }
  62054. void ComponentPeer::clearMaskedRegion() throw()
  62055. {
  62056. maskedRegion.clear();
  62057. }
  62058. void ComponentPeer::addMaskedRegion (int x, int y, int w, int h) throw()
  62059. {
  62060. maskedRegion.add (x, y, w, h);
  62061. }
  62062. const StringArray ComponentPeer::getAvailableRenderingEngines() throw()
  62063. {
  62064. StringArray s;
  62065. s.add ("Software Renderer");
  62066. return s;
  62067. }
  62068. int ComponentPeer::getCurrentRenderingEngine() throw()
  62069. {
  62070. return 0;
  62071. }
  62072. void ComponentPeer::setCurrentRenderingEngine (int /*index*/) throw()
  62073. {
  62074. }
  62075. END_JUCE_NAMESPACE
  62076. /*** End of inlined file: juce_ComponentPeer.cpp ***/
  62077. /*** Start of inlined file: juce_DialogWindow.cpp ***/
  62078. BEGIN_JUCE_NAMESPACE
  62079. DialogWindow::DialogWindow (const String& name,
  62080. const Colour& backgroundColour_,
  62081. const bool escapeKeyTriggersCloseButton_,
  62082. const bool addToDesktop_)
  62083. : DocumentWindow (name, backgroundColour_, DocumentWindow::closeButton, addToDesktop_),
  62084. escapeKeyTriggersCloseButton (escapeKeyTriggersCloseButton_)
  62085. {
  62086. }
  62087. DialogWindow::~DialogWindow()
  62088. {
  62089. }
  62090. void DialogWindow::resized()
  62091. {
  62092. DocumentWindow::resized();
  62093. const KeyPress esc (KeyPress::escapeKey, 0, 0);
  62094. if (escapeKeyTriggersCloseButton
  62095. && getCloseButton() != 0
  62096. && ! getCloseButton()->isRegisteredForShortcut (esc))
  62097. {
  62098. getCloseButton()->addShortcut (esc);
  62099. }
  62100. }
  62101. class TempDialogWindow : public DialogWindow
  62102. {
  62103. public:
  62104. TempDialogWindow (const String& title, const Colour& colour, const bool escapeCloses)
  62105. : DialogWindow (title, colour, escapeCloses, true)
  62106. {
  62107. }
  62108. ~TempDialogWindow()
  62109. {
  62110. }
  62111. void closeButtonPressed()
  62112. {
  62113. setVisible (false);
  62114. }
  62115. private:
  62116. TempDialogWindow (const TempDialogWindow&);
  62117. const TempDialogWindow& operator= (const TempDialogWindow&);
  62118. };
  62119. int DialogWindow::showModalDialog (const String& dialogTitle,
  62120. Component* contentComponent,
  62121. Component* componentToCentreAround,
  62122. const Colour& colour,
  62123. const bool escapeKeyTriggersCloseButton,
  62124. const bool shouldBeResizable,
  62125. const bool useBottomRightCornerResizer)
  62126. {
  62127. TempDialogWindow dw (dialogTitle, colour, escapeKeyTriggersCloseButton);
  62128. dw.setContentComponent (contentComponent, true, true);
  62129. dw.centreAroundComponent (componentToCentreAround, dw.getWidth(), dw.getHeight());
  62130. dw.setResizable (shouldBeResizable, useBottomRightCornerResizer);
  62131. const int result = dw.runModalLoop();
  62132. dw.setContentComponent (0, false);
  62133. return result;
  62134. }
  62135. END_JUCE_NAMESPACE
  62136. /*** End of inlined file: juce_DialogWindow.cpp ***/
  62137. /*** Start of inlined file: juce_DocumentWindow.cpp ***/
  62138. BEGIN_JUCE_NAMESPACE
  62139. class DocumentWindow::ButtonListenerProxy : public ButtonListener
  62140. {
  62141. public:
  62142. ButtonListenerProxy (DocumentWindow& owner_)
  62143. : owner (owner_)
  62144. {
  62145. }
  62146. void buttonClicked (Button* button)
  62147. {
  62148. if (button == owner.getMinimiseButton())
  62149. owner.minimiseButtonPressed();
  62150. else if (button == owner.getMaximiseButton())
  62151. owner.maximiseButtonPressed();
  62152. else if (button == owner.getCloseButton())
  62153. owner.closeButtonPressed();
  62154. }
  62155. juce_UseDebuggingNewOperator
  62156. private:
  62157. DocumentWindow& owner;
  62158. ButtonListenerProxy (const ButtonListenerProxy&);
  62159. ButtonListenerProxy& operator= (const ButtonListenerProxy&);
  62160. };
  62161. DocumentWindow::DocumentWindow (const String& title,
  62162. const Colour& backgroundColour,
  62163. const int requiredButtons_,
  62164. const bool addToDesktop_)
  62165. : ResizableWindow (title, backgroundColour, addToDesktop_),
  62166. titleBarHeight (26),
  62167. menuBarHeight (24),
  62168. requiredButtons (requiredButtons_),
  62169. #if JUCE_MAC
  62170. positionTitleBarButtonsOnLeft (true),
  62171. #else
  62172. positionTitleBarButtonsOnLeft (false),
  62173. #endif
  62174. drawTitleTextCentred (true),
  62175. menuBarModel (0)
  62176. {
  62177. setResizeLimits (128, 128, 32768, 32768);
  62178. lookAndFeelChanged();
  62179. }
  62180. DocumentWindow::~DocumentWindow()
  62181. {
  62182. for (int i = numElementsInArray (titleBarButtons); --i >= 0;)
  62183. titleBarButtons[i] = 0;
  62184. menuBar = 0;
  62185. }
  62186. void DocumentWindow::repaintTitleBar()
  62187. {
  62188. const Rectangle<int> titleBarArea (getTitleBarArea());
  62189. repaint (titleBarArea.getX(), titleBarArea.getY(),
  62190. titleBarArea.getWidth(), titleBarArea.getHeight());
  62191. }
  62192. void DocumentWindow::setName (const String& newName)
  62193. {
  62194. if (newName != getName())
  62195. {
  62196. Component::setName (newName);
  62197. repaintTitleBar();
  62198. }
  62199. }
  62200. void DocumentWindow::setIcon (const Image* imageToUse)
  62201. {
  62202. titleBarIcon = imageToUse != 0 ? imageToUse->createCopy() : 0;
  62203. repaintTitleBar();
  62204. }
  62205. void DocumentWindow::setTitleBarHeight (const int newHeight)
  62206. {
  62207. titleBarHeight = newHeight;
  62208. resized();
  62209. repaintTitleBar();
  62210. }
  62211. void DocumentWindow::setTitleBarButtonsRequired (const int requiredButtons_,
  62212. const bool positionTitleBarButtonsOnLeft_)
  62213. {
  62214. requiredButtons = requiredButtons_;
  62215. positionTitleBarButtonsOnLeft = positionTitleBarButtonsOnLeft_;
  62216. lookAndFeelChanged();
  62217. }
  62218. void DocumentWindow::setTitleBarTextCentred (const bool textShouldBeCentred)
  62219. {
  62220. drawTitleTextCentred = textShouldBeCentred;
  62221. repaintTitleBar();
  62222. }
  62223. void DocumentWindow::setMenuBar (MenuBarModel* menuBarModel_,
  62224. const int menuBarHeight_)
  62225. {
  62226. if (menuBarModel != menuBarModel_)
  62227. {
  62228. menuBar = 0;
  62229. menuBarModel = menuBarModel_;
  62230. menuBarHeight = (menuBarHeight_ > 0) ? menuBarHeight_
  62231. : getLookAndFeel().getDefaultMenuBarHeight();
  62232. if (menuBarModel != 0)
  62233. {
  62234. // (call the Component method directly to avoid the assertion in ResizableWindow)
  62235. Component::addAndMakeVisible (menuBar = new MenuBarComponent (menuBarModel));
  62236. menuBar->setEnabled (isActiveWindow());
  62237. }
  62238. resized();
  62239. }
  62240. }
  62241. void DocumentWindow::closeButtonPressed()
  62242. {
  62243. /* If you've got a close button, you have to override this method to get
  62244. rid of your window!
  62245. If the window is just a pop-up, you should override this method and make
  62246. it delete the window in whatever way is appropriate for your app. E.g. you
  62247. might just want to call "delete this".
  62248. If your app is centred around this window such that the whole app should quit when
  62249. the window is closed, then you will probably want to use this method as an opportunity
  62250. to call JUCEApplication::quit(), and leave the window to be deleted later by your
  62251. JUCEApplication::shutdown() method. (Doing it this way means that your window will
  62252. still get cleaned-up if the app is quit by some other means (e.g. a cmd-Q on the mac
  62253. or closing it via the taskbar icon on Windows).
  62254. */
  62255. jassertfalse
  62256. }
  62257. void DocumentWindow::minimiseButtonPressed()
  62258. {
  62259. setMinimised (true);
  62260. }
  62261. void DocumentWindow::maximiseButtonPressed()
  62262. {
  62263. setFullScreen (! isFullScreen());
  62264. }
  62265. void DocumentWindow::paint (Graphics& g)
  62266. {
  62267. ResizableWindow::paint (g);
  62268. if (resizableBorder == 0)
  62269. {
  62270. g.setColour (getBackgroundColour().overlaidWith (Colour (0x80000000)));
  62271. const BorderSize border (getBorderThickness());
  62272. g.fillRect (0, 0, getWidth(), border.getTop());
  62273. g.fillRect (0, border.getTop(), border.getLeft(), getHeight() - border.getTopAndBottom());
  62274. g.fillRect (getWidth() - border.getRight(), border.getTop(), border.getRight(), getHeight() - border.getTopAndBottom());
  62275. g.fillRect (0, getHeight() - border.getBottom(), getWidth(), border.getBottom());
  62276. }
  62277. const Rectangle<int> titleBarArea (getTitleBarArea());
  62278. g.setOrigin (titleBarArea.getX(), titleBarArea.getY());
  62279. g.reduceClipRegion (0, 0, titleBarArea.getWidth(), titleBarArea.getHeight());
  62280. int titleSpaceX1 = 6;
  62281. int titleSpaceX2 = titleBarArea.getWidth() - 6;
  62282. for (int i = 0; i < 3; ++i)
  62283. {
  62284. if (titleBarButtons[i] != 0)
  62285. {
  62286. if (positionTitleBarButtonsOnLeft)
  62287. titleSpaceX1 = jmax (titleSpaceX1, titleBarButtons[i]->getRight() + (getWidth() - titleBarButtons[i]->getRight()) / 8);
  62288. else
  62289. titleSpaceX2 = jmin (titleSpaceX2, titleBarButtons[i]->getX() - (titleBarButtons[i]->getX() / 8));
  62290. }
  62291. }
  62292. getLookAndFeel().drawDocumentWindowTitleBar (*this, g,
  62293. titleBarArea.getWidth(),
  62294. titleBarArea.getHeight(),
  62295. titleSpaceX1,
  62296. jmax (1, titleSpaceX2 - titleSpaceX1),
  62297. titleBarIcon,
  62298. ! drawTitleTextCentred);
  62299. }
  62300. void DocumentWindow::resized()
  62301. {
  62302. ResizableWindow::resized();
  62303. if (titleBarButtons[1] != 0)
  62304. titleBarButtons[1]->setToggleState (isFullScreen(), false);
  62305. const Rectangle<int> titleBarArea (getTitleBarArea());
  62306. getLookAndFeel()
  62307. .positionDocumentWindowButtons (*this,
  62308. titleBarArea.getX(), titleBarArea.getY(),
  62309. titleBarArea.getWidth(), titleBarArea.getHeight(),
  62310. titleBarButtons[0],
  62311. titleBarButtons[1],
  62312. titleBarButtons[2],
  62313. positionTitleBarButtonsOnLeft);
  62314. if (menuBar != 0)
  62315. menuBar->setBounds (titleBarArea.getX(), titleBarArea.getBottom(),
  62316. titleBarArea.getWidth(), menuBarHeight);
  62317. }
  62318. const BorderSize DocumentWindow::getBorderThickness()
  62319. {
  62320. return BorderSize ((isFullScreen() || isUsingNativeTitleBar())
  62321. ? 0 : (resizableBorder != 0 ? 4 : 1));
  62322. }
  62323. const BorderSize DocumentWindow::getContentComponentBorder()
  62324. {
  62325. BorderSize border (getBorderThickness());
  62326. border.setTop (border.getTop()
  62327. + (isUsingNativeTitleBar() ? 0 : titleBarHeight)
  62328. + (menuBar != 0 ? menuBarHeight : 0));
  62329. return border;
  62330. }
  62331. int DocumentWindow::getTitleBarHeight() const
  62332. {
  62333. return isUsingNativeTitleBar() ? 0 : jmin (titleBarHeight, getHeight() - 4);
  62334. }
  62335. const Rectangle<int> DocumentWindow::getTitleBarArea()
  62336. {
  62337. const BorderSize border (getBorderThickness());
  62338. return Rectangle<int> (border.getLeft(), border.getTop(),
  62339. getWidth() - border.getLeftAndRight(),
  62340. getTitleBarHeight());
  62341. }
  62342. Button* DocumentWindow::getCloseButton() const throw()
  62343. {
  62344. return titleBarButtons[2];
  62345. }
  62346. Button* DocumentWindow::getMinimiseButton() const throw()
  62347. {
  62348. return titleBarButtons[0];
  62349. }
  62350. Button* DocumentWindow::getMaximiseButton() const throw()
  62351. {
  62352. return titleBarButtons[1];
  62353. }
  62354. int DocumentWindow::getDesktopWindowStyleFlags() const
  62355. {
  62356. int flags = ResizableWindow::getDesktopWindowStyleFlags();
  62357. if ((requiredButtons & minimiseButton) != 0)
  62358. flags |= ComponentPeer::windowHasMinimiseButton;
  62359. if ((requiredButtons & maximiseButton) != 0)
  62360. flags |= ComponentPeer::windowHasMaximiseButton;
  62361. if ((requiredButtons & closeButton) != 0)
  62362. flags |= ComponentPeer::windowHasCloseButton;
  62363. return flags;
  62364. }
  62365. void DocumentWindow::lookAndFeelChanged()
  62366. {
  62367. int i;
  62368. for (i = numElementsInArray (titleBarButtons); --i >= 0;)
  62369. titleBarButtons[i] = 0;
  62370. if (! isUsingNativeTitleBar())
  62371. {
  62372. titleBarButtons[0] = ((requiredButtons & minimiseButton) != 0)
  62373. ? getLookAndFeel().createDocumentWindowButton (minimiseButton) : 0;
  62374. titleBarButtons[1] = ((requiredButtons & maximiseButton) != 0)
  62375. ? getLookAndFeel().createDocumentWindowButton (maximiseButton) : 0;
  62376. titleBarButtons[2] = ((requiredButtons & closeButton) != 0)
  62377. ? getLookAndFeel().createDocumentWindowButton (closeButton) : 0;
  62378. for (i = 0; i < 3; ++i)
  62379. {
  62380. if (titleBarButtons[i] != 0)
  62381. {
  62382. if (buttonListener == 0)
  62383. buttonListener = new ButtonListenerProxy (*this);
  62384. titleBarButtons[i]->addButtonListener (buttonListener);
  62385. titleBarButtons[i]->setWantsKeyboardFocus (false);
  62386. // (call the Component method directly to avoid the assertion in ResizableWindow)
  62387. Component::addAndMakeVisible (titleBarButtons[i]);
  62388. }
  62389. }
  62390. if (getCloseButton() != 0)
  62391. {
  62392. #if JUCE_MAC
  62393. getCloseButton()->addShortcut (KeyPress (T('w'), ModifierKeys::commandModifier, 0));
  62394. #else
  62395. getCloseButton()->addShortcut (KeyPress (KeyPress::F4Key, ModifierKeys::altModifier, 0));
  62396. #endif
  62397. }
  62398. }
  62399. activeWindowStatusChanged();
  62400. ResizableWindow::lookAndFeelChanged();
  62401. }
  62402. void DocumentWindow::parentHierarchyChanged()
  62403. {
  62404. lookAndFeelChanged();
  62405. }
  62406. void DocumentWindow::activeWindowStatusChanged()
  62407. {
  62408. ResizableWindow::activeWindowStatusChanged();
  62409. for (int i = numElementsInArray (titleBarButtons); --i >= 0;)
  62410. if (titleBarButtons[i] != 0)
  62411. titleBarButtons[i]->setEnabled (isActiveWindow());
  62412. if (menuBar != 0)
  62413. menuBar->setEnabled (isActiveWindow());
  62414. }
  62415. void DocumentWindow::mouseDoubleClick (const MouseEvent& e)
  62416. {
  62417. if (getTitleBarArea().contains (e.x, e.y)
  62418. && getMaximiseButton() != 0)
  62419. {
  62420. getMaximiseButton()->triggerClick();
  62421. }
  62422. }
  62423. void DocumentWindow::userTriedToCloseWindow()
  62424. {
  62425. closeButtonPressed();
  62426. }
  62427. END_JUCE_NAMESPACE
  62428. /*** End of inlined file: juce_DocumentWindow.cpp ***/
  62429. /*** Start of inlined file: juce_ResizableWindow.cpp ***/
  62430. BEGIN_JUCE_NAMESPACE
  62431. ResizableWindow::ResizableWindow (const String& name,
  62432. const bool addToDesktop_)
  62433. : TopLevelWindow (name, addToDesktop_),
  62434. resizeToFitContent (false),
  62435. fullscreen (false),
  62436. lastNonFullScreenPos (50, 50, 256, 256),
  62437. constrainer (0)
  62438. #ifdef JUCE_DEBUG
  62439. , hasBeenResized (false)
  62440. #endif
  62441. {
  62442. defaultConstrainer.setMinimumOnscreenAmounts (0x10000, 16, 24, 16);
  62443. lastNonFullScreenPos.setBounds (50, 50, 256, 256);
  62444. if (addToDesktop_)
  62445. Component::addToDesktop (getDesktopWindowStyleFlags());
  62446. }
  62447. ResizableWindow::ResizableWindow (const String& name,
  62448. const Colour& backgroundColour_,
  62449. const bool addToDesktop_)
  62450. : TopLevelWindow (name, addToDesktop_),
  62451. resizeToFitContent (false),
  62452. fullscreen (false),
  62453. lastNonFullScreenPos (50, 50, 256, 256),
  62454. constrainer (0)
  62455. #ifdef JUCE_DEBUG
  62456. , hasBeenResized (false)
  62457. #endif
  62458. {
  62459. setBackgroundColour (backgroundColour_);
  62460. defaultConstrainer.setMinimumOnscreenAmounts (0x10000, 16, 24, 16);
  62461. if (addToDesktop_)
  62462. Component::addToDesktop (getDesktopWindowStyleFlags());
  62463. }
  62464. ResizableWindow::~ResizableWindow()
  62465. {
  62466. resizableCorner = 0;
  62467. resizableBorder = 0;
  62468. contentComponent = 0;
  62469. // have you been adding your own components directly to this window..? tut tut tut.
  62470. // Read the instructions for using a ResizableWindow!
  62471. jassert (getNumChildComponents() == 0);
  62472. }
  62473. int ResizableWindow::getDesktopWindowStyleFlags() const
  62474. {
  62475. int flags = TopLevelWindow::getDesktopWindowStyleFlags();
  62476. if (isResizable() && (flags & ComponentPeer::windowHasTitleBar) != 0)
  62477. flags |= ComponentPeer::windowIsResizable;
  62478. return flags;
  62479. }
  62480. void ResizableWindow::setContentComponent (Component* const newContentComponent,
  62481. const bool deleteOldOne,
  62482. const bool resizeToFit)
  62483. {
  62484. resizeToFitContent = resizeToFit;
  62485. if (newContentComponent != (Component*) contentComponent)
  62486. {
  62487. if (! deleteOldOne)
  62488. removeChildComponent (contentComponent.release());
  62489. contentComponent = newContentComponent;
  62490. Component::addAndMakeVisible (contentComponent);
  62491. }
  62492. if (resizeToFit)
  62493. childBoundsChanged (contentComponent);
  62494. resized(); // must always be called to position the new content comp
  62495. }
  62496. void ResizableWindow::setContentComponentSize (int width, int height)
  62497. {
  62498. jassert (width > 0 && height > 0); // not a great idea to give it a zero size..
  62499. const BorderSize border (getContentComponentBorder());
  62500. setSize (width + border.getLeftAndRight(),
  62501. height + border.getTopAndBottom());
  62502. }
  62503. const BorderSize ResizableWindow::getBorderThickness()
  62504. {
  62505. return BorderSize (isUsingNativeTitleBar() ? 0 : ((resizableBorder != 0 && ! isFullScreen()) ? 5 : 3));
  62506. }
  62507. const BorderSize ResizableWindow::getContentComponentBorder()
  62508. {
  62509. return getBorderThickness();
  62510. }
  62511. void ResizableWindow::moved()
  62512. {
  62513. updateLastPos();
  62514. }
  62515. void ResizableWindow::visibilityChanged()
  62516. {
  62517. TopLevelWindow::visibilityChanged();
  62518. updateLastPos();
  62519. }
  62520. void ResizableWindow::resized()
  62521. {
  62522. if (resizableBorder != 0)
  62523. {
  62524. resizableBorder->setVisible (! isFullScreen());
  62525. resizableBorder->setBorderThickness (getBorderThickness());
  62526. resizableBorder->setSize (getWidth(), getHeight());
  62527. resizableBorder->toBack();
  62528. }
  62529. if (resizableCorner != 0)
  62530. {
  62531. resizableCorner->setVisible (! isFullScreen());
  62532. const int resizerSize = 18;
  62533. resizableCorner->setBounds (getWidth() - resizerSize,
  62534. getHeight() - resizerSize,
  62535. resizerSize, resizerSize);
  62536. }
  62537. if (contentComponent != 0)
  62538. contentComponent->setBoundsInset (getContentComponentBorder());
  62539. updateLastPos();
  62540. #ifdef JUCE_DEBUG
  62541. hasBeenResized = true;
  62542. #endif
  62543. }
  62544. void ResizableWindow::childBoundsChanged (Component* child)
  62545. {
  62546. if ((child == contentComponent) && (child != 0) && resizeToFitContent)
  62547. {
  62548. // not going to look very good if this component has a zero size..
  62549. jassert (child->getWidth() > 0);
  62550. jassert (child->getHeight() > 0);
  62551. const BorderSize borders (getContentComponentBorder());
  62552. setSize (child->getWidth() + borders.getLeftAndRight(),
  62553. child->getHeight() + borders.getTopAndBottom());
  62554. }
  62555. }
  62556. void ResizableWindow::activeWindowStatusChanged()
  62557. {
  62558. const BorderSize borders (getContentComponentBorder());
  62559. repaint (0, 0, getWidth(), borders.getTop());
  62560. repaint (0, borders.getTop(), borders.getLeft(), getHeight() - borders.getBottom() - borders.getTop());
  62561. repaint (0, getHeight() - borders.getBottom(), getWidth(), borders.getBottom());
  62562. repaint (getWidth() - borders.getRight(), borders.getTop(), borders.getRight(), getHeight() - borders.getBottom() - borders.getTop());
  62563. }
  62564. void ResizableWindow::setResizable (const bool shouldBeResizable,
  62565. const bool useBottomRightCornerResizer)
  62566. {
  62567. if (shouldBeResizable)
  62568. {
  62569. if (useBottomRightCornerResizer)
  62570. {
  62571. resizableBorder = 0;
  62572. if (resizableCorner == 0)
  62573. {
  62574. Component::addChildComponent (resizableCorner = new ResizableCornerComponent (this, constrainer));
  62575. resizableCorner->setAlwaysOnTop (true);
  62576. }
  62577. }
  62578. else
  62579. {
  62580. resizableCorner = 0;
  62581. if (resizableBorder == 0)
  62582. Component::addChildComponent (resizableBorder = new ResizableBorderComponent (this, constrainer));
  62583. }
  62584. }
  62585. else
  62586. {
  62587. resizableCorner = 0;
  62588. resizableBorder = 0;
  62589. }
  62590. if (isUsingNativeTitleBar())
  62591. recreateDesktopWindow();
  62592. childBoundsChanged (contentComponent);
  62593. resized();
  62594. }
  62595. bool ResizableWindow::isResizable() const throw()
  62596. {
  62597. return resizableCorner != 0
  62598. || resizableBorder != 0;
  62599. }
  62600. void ResizableWindow::setResizeLimits (const int newMinimumWidth,
  62601. const int newMinimumHeight,
  62602. const int newMaximumWidth,
  62603. const int newMaximumHeight) throw()
  62604. {
  62605. // if you've set up a custom constrainer then these settings won't have any effect..
  62606. jassert (constrainer == &defaultConstrainer || constrainer == 0);
  62607. if (constrainer == 0)
  62608. setConstrainer (&defaultConstrainer);
  62609. defaultConstrainer.setSizeLimits (newMinimumWidth, newMinimumHeight,
  62610. newMaximumWidth, newMaximumHeight);
  62611. setBoundsConstrained (getBounds());
  62612. }
  62613. void ResizableWindow::setConstrainer (ComponentBoundsConstrainer* newConstrainer)
  62614. {
  62615. if (constrainer != newConstrainer)
  62616. {
  62617. constrainer = newConstrainer;
  62618. const bool useBottomRightCornerResizer = resizableCorner != 0;
  62619. const bool shouldBeResizable = useBottomRightCornerResizer || resizableBorder != 0;
  62620. resizableCorner = 0;
  62621. resizableBorder = 0;
  62622. setResizable (shouldBeResizable, useBottomRightCornerResizer);
  62623. ComponentPeer* const peer = getPeer();
  62624. if (peer != 0)
  62625. peer->setConstrainer (newConstrainer);
  62626. }
  62627. }
  62628. void ResizableWindow::setBoundsConstrained (const Rectangle<int>& bounds)
  62629. {
  62630. if (constrainer != 0)
  62631. constrainer->setBoundsForComponent (this, bounds, false, false, false, false);
  62632. else
  62633. setBounds (bounds);
  62634. }
  62635. void ResizableWindow::paint (Graphics& g)
  62636. {
  62637. getLookAndFeel().fillResizableWindowBackground (g, getWidth(), getHeight(),
  62638. getBorderThickness(), *this);
  62639. if (! isFullScreen())
  62640. {
  62641. getLookAndFeel().drawResizableWindowBorder (g, getWidth(), getHeight(),
  62642. getBorderThickness(), *this);
  62643. }
  62644. #ifdef JUCE_DEBUG
  62645. /* If this fails, then you've probably written a subclass with a resized()
  62646. callback but forgotten to make it call its parent class's resized() method.
  62647. It's important when you override methods like resized(), moved(),
  62648. etc., that you make sure the base class methods also get called.
  62649. Of course you shouldn't really be overriding ResizableWindow::resized() anyway,
  62650. because your content should all be inside the content component - and it's the
  62651. content component's resized() method that you should be using to do your
  62652. layout.
  62653. */
  62654. jassert (hasBeenResized || (getWidth() == 0 && getHeight() == 0));
  62655. #endif
  62656. }
  62657. void ResizableWindow::lookAndFeelChanged()
  62658. {
  62659. resized();
  62660. if (isOnDesktop())
  62661. {
  62662. Component::addToDesktop (getDesktopWindowStyleFlags());
  62663. ComponentPeer* const peer = getPeer();
  62664. if (peer != 0)
  62665. peer->setConstrainer (constrainer);
  62666. }
  62667. }
  62668. const Colour ResizableWindow::getBackgroundColour() const throw()
  62669. {
  62670. return findColour (backgroundColourId, false);
  62671. }
  62672. void ResizableWindow::setBackgroundColour (const Colour& newColour)
  62673. {
  62674. Colour backgroundColour (newColour);
  62675. if (! Desktop::canUseSemiTransparentWindows())
  62676. backgroundColour = newColour.withAlpha (1.0f);
  62677. setColour (backgroundColourId, backgroundColour);
  62678. setOpaque (backgroundColour.isOpaque());
  62679. repaint();
  62680. }
  62681. bool ResizableWindow::isFullScreen() const
  62682. {
  62683. if (isOnDesktop())
  62684. {
  62685. ComponentPeer* const peer = getPeer();
  62686. return peer != 0 && peer->isFullScreen();
  62687. }
  62688. return fullscreen;
  62689. }
  62690. void ResizableWindow::setFullScreen (const bool shouldBeFullScreen)
  62691. {
  62692. if (shouldBeFullScreen != isFullScreen())
  62693. {
  62694. updateLastPos();
  62695. fullscreen = shouldBeFullScreen;
  62696. if (isOnDesktop())
  62697. {
  62698. ComponentPeer* const peer = getPeer();
  62699. if (peer != 0)
  62700. {
  62701. // keep a copy of this intact in case the real one gets messed-up while we're un-maximising
  62702. const Rectangle<int> lastPos (lastNonFullScreenPos);
  62703. peer->setFullScreen (shouldBeFullScreen);
  62704. if (! shouldBeFullScreen)
  62705. setBounds (lastPos);
  62706. }
  62707. else
  62708. {
  62709. jassertfalse
  62710. }
  62711. }
  62712. else
  62713. {
  62714. if (shouldBeFullScreen)
  62715. setBounds (0, 0, getParentWidth(), getParentHeight());
  62716. else
  62717. setBounds (lastNonFullScreenPos);
  62718. }
  62719. resized();
  62720. }
  62721. }
  62722. bool ResizableWindow::isMinimised() const
  62723. {
  62724. ComponentPeer* const peer = getPeer();
  62725. return (peer != 0) && peer->isMinimised();
  62726. }
  62727. void ResizableWindow::setMinimised (const bool shouldMinimise)
  62728. {
  62729. if (shouldMinimise != isMinimised())
  62730. {
  62731. ComponentPeer* const peer = getPeer();
  62732. if (peer != 0)
  62733. {
  62734. updateLastPos();
  62735. peer->setMinimised (shouldMinimise);
  62736. }
  62737. else
  62738. {
  62739. jassertfalse
  62740. }
  62741. }
  62742. }
  62743. void ResizableWindow::updateLastPos()
  62744. {
  62745. if (isShowing() && ! (isFullScreen() || isMinimised()))
  62746. {
  62747. lastNonFullScreenPos = getBounds();
  62748. }
  62749. }
  62750. void ResizableWindow::parentSizeChanged()
  62751. {
  62752. if (isFullScreen() && getParentComponent() != 0)
  62753. {
  62754. setBounds (0, 0, getParentWidth(), getParentHeight());
  62755. }
  62756. }
  62757. const String ResizableWindow::getWindowStateAsString()
  62758. {
  62759. updateLastPos();
  62760. return (isFullScreen() ? "fs " : "") + lastNonFullScreenPos.toString();
  62761. }
  62762. bool ResizableWindow::restoreWindowStateFromString (const String& s)
  62763. {
  62764. StringArray tokens;
  62765. tokens.addTokens (s, false);
  62766. tokens.removeEmptyStrings();
  62767. tokens.trim();
  62768. const bool fs = tokens[0].startsWithIgnoreCase (T("fs"));
  62769. const int firstCoord = fs ? 1 : 0;
  62770. if (tokens.size() != firstCoord + 4)
  62771. return false;
  62772. Rectangle<int> newPos (tokens[firstCoord].getIntValue(),
  62773. tokens[firstCoord + 1].getIntValue(),
  62774. tokens[firstCoord + 2].getIntValue(),
  62775. tokens[firstCoord + 3].getIntValue());
  62776. if (newPos.isEmpty())
  62777. return false;
  62778. const Rectangle<int> screen (Desktop::getInstance().getMonitorAreaContaining (newPos.getCentreX(),
  62779. newPos.getCentreY()));
  62780. ComponentPeer* const peer = isOnDesktop() ? getPeer() : 0;
  62781. if (peer != 0)
  62782. peer->getFrameSize().addTo (newPos);
  62783. if (! screen.contains (newPos))
  62784. {
  62785. newPos.setSize (jmin (newPos.getWidth(), screen.getWidth()),
  62786. jmin (newPos.getHeight(), screen.getHeight()));
  62787. newPos.setPosition (jlimit (screen.getX(), screen.getRight() - newPos.getWidth(), newPos.getX()),
  62788. jlimit (screen.getY(), screen.getBottom() - newPos.getHeight(), newPos.getY()));
  62789. }
  62790. if (peer != 0)
  62791. {
  62792. peer->getFrameSize().subtractFrom (newPos);
  62793. peer->setNonFullScreenBounds (newPos);
  62794. }
  62795. lastNonFullScreenPos = newPos;
  62796. setFullScreen (fs);
  62797. if (! fs)
  62798. setBoundsConstrained (newPos);
  62799. return true;
  62800. }
  62801. void ResizableWindow::mouseDown (const MouseEvent&)
  62802. {
  62803. if (! isFullScreen())
  62804. dragger.startDraggingComponent (this, constrainer);
  62805. }
  62806. void ResizableWindow::mouseDrag (const MouseEvent& e)
  62807. {
  62808. if (! isFullScreen())
  62809. dragger.dragComponent (this, e);
  62810. }
  62811. #ifdef JUCE_DEBUG
  62812. void ResizableWindow::addChildComponent (Component* const child, int zOrder)
  62813. {
  62814. /* Agh! You shouldn't add components directly to a ResizableWindow - this class
  62815. manages its child components automatically, and if you add your own it'll cause
  62816. trouble. Instead, use setContentComponent() to give it a component which
  62817. will be automatically resized and kept in the right place - then you can add
  62818. subcomponents to the content comp. See the notes for the ResizableWindow class
  62819. for more info.
  62820. If you really know what you're doing and want to avoid this assertion, just call
  62821. Component::addChildComponent directly.
  62822. */
  62823. jassertfalse
  62824. Component::addChildComponent (child, zOrder);
  62825. }
  62826. void ResizableWindow::addAndMakeVisible (Component* const child, int zOrder)
  62827. {
  62828. /* Agh! You shouldn't add components directly to a ResizableWindow - this class
  62829. manages its child components automatically, and if you add your own it'll cause
  62830. trouble. Instead, use setContentComponent() to give it a component which
  62831. will be automatically resized and kept in the right place - then you can add
  62832. subcomponents to the content comp. See the notes for the ResizableWindow class
  62833. for more info.
  62834. If you really know what you're doing and want to avoid this assertion, just call
  62835. Component::addAndMakeVisible directly.
  62836. */
  62837. jassertfalse
  62838. Component::addAndMakeVisible (child, zOrder);
  62839. }
  62840. #endif
  62841. END_JUCE_NAMESPACE
  62842. /*** End of inlined file: juce_ResizableWindow.cpp ***/
  62843. /*** Start of inlined file: juce_SplashScreen.cpp ***/
  62844. BEGIN_JUCE_NAMESPACE
  62845. SplashScreen::SplashScreen()
  62846. : backgroundImage (0)
  62847. {
  62848. setOpaque (true);
  62849. }
  62850. SplashScreen::~SplashScreen()
  62851. {
  62852. ImageCache::releaseOrDelete (backgroundImage);
  62853. }
  62854. void SplashScreen::show (const String& title,
  62855. Image* const backgroundImage_,
  62856. const int minimumTimeToDisplayFor,
  62857. const bool useDropShadow,
  62858. const bool removeOnMouseClick)
  62859. {
  62860. backgroundImage = backgroundImage_;
  62861. jassert (backgroundImage_ != 0);
  62862. if (backgroundImage_ != 0)
  62863. {
  62864. setOpaque (! backgroundImage_->hasAlphaChannel());
  62865. show (title,
  62866. backgroundImage_->getWidth(),
  62867. backgroundImage_->getHeight(),
  62868. minimumTimeToDisplayFor,
  62869. useDropShadow,
  62870. removeOnMouseClick);
  62871. }
  62872. }
  62873. void SplashScreen::show (const String& title,
  62874. const int width,
  62875. const int height,
  62876. const int minimumTimeToDisplayFor,
  62877. const bool useDropShadow,
  62878. const bool removeOnMouseClick)
  62879. {
  62880. setName (title);
  62881. setAlwaysOnTop (true);
  62882. setVisible (true);
  62883. centreWithSize (width, height);
  62884. addToDesktop (useDropShadow ? ComponentPeer::windowHasDropShadow : 0);
  62885. toFront (false);
  62886. MessageManager::getInstance()->runDispatchLoopUntil (300);
  62887. repaint();
  62888. originalClickCounter = removeOnMouseClick
  62889. ? Desktop::getMouseButtonClickCounter()
  62890. : std::numeric_limits<int>::max();
  62891. earliestTimeToDelete = Time::getCurrentTime() + RelativeTime::milliseconds (minimumTimeToDisplayFor);
  62892. startTimer (50);
  62893. }
  62894. void SplashScreen::paint (Graphics& g)
  62895. {
  62896. if (backgroundImage != 0)
  62897. {
  62898. g.setOpacity (1.0f);
  62899. g.drawImage (backgroundImage,
  62900. 0, 0, getWidth(), getHeight(),
  62901. 0, 0, backgroundImage->getWidth(), backgroundImage->getHeight());
  62902. }
  62903. }
  62904. void SplashScreen::timerCallback()
  62905. {
  62906. if (Time::getCurrentTime() > earliestTimeToDelete
  62907. || Desktop::getMouseButtonClickCounter() > originalClickCounter)
  62908. {
  62909. delete this;
  62910. }
  62911. }
  62912. END_JUCE_NAMESPACE
  62913. /*** End of inlined file: juce_SplashScreen.cpp ***/
  62914. /*** Start of inlined file: juce_ThreadWithProgressWindow.cpp ***/
  62915. BEGIN_JUCE_NAMESPACE
  62916. ThreadWithProgressWindow::ThreadWithProgressWindow (const String& title,
  62917. const bool hasProgressBar,
  62918. const bool hasCancelButton,
  62919. const int timeOutMsWhenCancelling_,
  62920. const String& cancelButtonText)
  62921. : Thread ("Juce Progress Window"),
  62922. progress (0.0),
  62923. timeOutMsWhenCancelling (timeOutMsWhenCancelling_)
  62924. {
  62925. alertWindow = LookAndFeel::getDefaultLookAndFeel()
  62926. .createAlertWindow (title, String::empty, cancelButtonText,
  62927. String::empty, String::empty,
  62928. AlertWindow::NoIcon, hasCancelButton ? 1 : 0, 0);
  62929. if (hasProgressBar)
  62930. alertWindow->addProgressBarComponent (progress);
  62931. }
  62932. ThreadWithProgressWindow::~ThreadWithProgressWindow()
  62933. {
  62934. stopThread (timeOutMsWhenCancelling);
  62935. }
  62936. bool ThreadWithProgressWindow::runThread (const int priority)
  62937. {
  62938. startThread (priority);
  62939. startTimer (100);
  62940. {
  62941. const ScopedLock sl (messageLock);
  62942. alertWindow->setMessage (message);
  62943. }
  62944. const bool finishedNaturally = alertWindow->runModalLoop() != 0;
  62945. stopThread (timeOutMsWhenCancelling);
  62946. alertWindow->setVisible (false);
  62947. return finishedNaturally;
  62948. }
  62949. void ThreadWithProgressWindow::setProgress (const double newProgress)
  62950. {
  62951. progress = newProgress;
  62952. }
  62953. void ThreadWithProgressWindow::setStatusMessage (const String& newStatusMessage)
  62954. {
  62955. const ScopedLock sl (messageLock);
  62956. message = newStatusMessage;
  62957. }
  62958. void ThreadWithProgressWindow::timerCallback()
  62959. {
  62960. if (! isThreadRunning())
  62961. {
  62962. // thread has finished normally..
  62963. alertWindow->exitModalState (1);
  62964. alertWindow->setVisible (false);
  62965. }
  62966. else
  62967. {
  62968. const ScopedLock sl (messageLock);
  62969. alertWindow->setMessage (message);
  62970. }
  62971. }
  62972. END_JUCE_NAMESPACE
  62973. /*** End of inlined file: juce_ThreadWithProgressWindow.cpp ***/
  62974. /*** Start of inlined file: juce_TooltipWindow.cpp ***/
  62975. BEGIN_JUCE_NAMESPACE
  62976. TooltipWindow::TooltipWindow (Component* const parentComponent,
  62977. const int millisecondsBeforeTipAppears_)
  62978. : Component ("tooltip"),
  62979. millisecondsBeforeTipAppears (millisecondsBeforeTipAppears_),
  62980. mouseX (0),
  62981. mouseY (0),
  62982. lastHideTime (0),
  62983. lastComponentUnderMouse (0),
  62984. changedCompsSinceShown (true)
  62985. {
  62986. startTimer (123);
  62987. setAlwaysOnTop (true);
  62988. setOpaque (true);
  62989. if (parentComponent != 0)
  62990. parentComponent->addChildComponent (this);
  62991. }
  62992. TooltipWindow::~TooltipWindow()
  62993. {
  62994. hide();
  62995. }
  62996. void TooltipWindow::setMillisecondsBeforeTipAppears (const int newTimeMs) throw()
  62997. {
  62998. millisecondsBeforeTipAppears = newTimeMs;
  62999. }
  63000. void TooltipWindow::paint (Graphics& g)
  63001. {
  63002. getLookAndFeel().drawTooltip (g, tipShowing, getWidth(), getHeight());
  63003. }
  63004. void TooltipWindow::mouseEnter (const MouseEvent&)
  63005. {
  63006. hide();
  63007. }
  63008. void TooltipWindow::showFor (const String& tip)
  63009. {
  63010. jassert (tip.isNotEmpty());
  63011. tipShowing = tip;
  63012. int mx, my;
  63013. Desktop::getMousePosition (mx, my);
  63014. if (getParentComponent() != 0)
  63015. getParentComponent()->globalPositionToRelative (mx, my);
  63016. int x, y, w, h;
  63017. getLookAndFeel().getTooltipSize (tip, w, h);
  63018. if (mx > getParentWidth() / 2)
  63019. x = mx - (w + 12);
  63020. else
  63021. x = mx + 24;
  63022. if (my > getParentHeight() / 2)
  63023. y = my - (h + 6);
  63024. else
  63025. y = my + 6;
  63026. setBounds (x, y, w, h);
  63027. setVisible (true);
  63028. if (getParentComponent() == 0)
  63029. {
  63030. addToDesktop (ComponentPeer::windowHasDropShadow
  63031. | ComponentPeer::windowIsTemporary
  63032. | ComponentPeer::windowIgnoresKeyPresses);
  63033. }
  63034. toFront (false);
  63035. }
  63036. const String TooltipWindow::getTipFor (Component* const c)
  63037. {
  63038. if (c->isValidComponent()
  63039. && Process::isForegroundProcess()
  63040. && ! Component::isMouseButtonDownAnywhere())
  63041. {
  63042. TooltipClient* const ttc = dynamic_cast <TooltipClient*> (c);
  63043. if (ttc != 0 && ! c->isCurrentlyBlockedByAnotherModalComponent())
  63044. return ttc->getTooltip();
  63045. }
  63046. return String::empty;
  63047. }
  63048. void TooltipWindow::hide()
  63049. {
  63050. tipShowing = String::empty;
  63051. removeFromDesktop();
  63052. setVisible (false);
  63053. }
  63054. void TooltipWindow::timerCallback()
  63055. {
  63056. const unsigned int now = Time::getApproximateMillisecondCounter();
  63057. Component* const newComp = Component::getComponentUnderMouse();
  63058. const String newTip (getTipFor (newComp));
  63059. const bool tipChanged = (newTip != lastTipUnderMouse || newComp != lastComponentUnderMouse);
  63060. lastComponentUnderMouse = newComp;
  63061. lastTipUnderMouse = newTip;
  63062. const int clickCount = Desktop::getInstance().getMouseButtonClickCounter();
  63063. const bool mouseWasClicked = clickCount > mouseClicks;
  63064. mouseClicks = clickCount;
  63065. int mx, my;
  63066. Desktop::getMousePosition (mx, my);
  63067. const bool mouseMovedQuickly = (abs (mx - mouseX) + abs (my - mouseY) > 12);
  63068. mouseX = mx;
  63069. mouseY = my;
  63070. if (tipChanged || mouseWasClicked || mouseMovedQuickly)
  63071. lastCompChangeTime = now;
  63072. if (isVisible() || now < lastHideTime + 500)
  63073. {
  63074. // if a tip is currently visible (or has just disappeared), update to a new one
  63075. // immediately if needed..
  63076. if (newComp == 0 || mouseWasClicked || newTip.isEmpty())
  63077. {
  63078. if (isVisible())
  63079. {
  63080. lastHideTime = now;
  63081. hide();
  63082. }
  63083. }
  63084. else if (tipChanged)
  63085. {
  63086. showFor (newTip);
  63087. }
  63088. }
  63089. else
  63090. {
  63091. // if there isn't currently a tip, but one is needed, only let it
  63092. // appear after a timeout..
  63093. if (newTip.isNotEmpty()
  63094. && newTip != tipShowing
  63095. && now > lastCompChangeTime + millisecondsBeforeTipAppears)
  63096. {
  63097. showFor (newTip);
  63098. }
  63099. }
  63100. }
  63101. END_JUCE_NAMESPACE
  63102. /*** End of inlined file: juce_TooltipWindow.cpp ***/
  63103. /*** Start of inlined file: juce_TopLevelWindow.cpp ***/
  63104. BEGIN_JUCE_NAMESPACE
  63105. class TopLevelWindowManager : public Timer,
  63106. public DeletedAtShutdown
  63107. {
  63108. public:
  63109. TopLevelWindowManager()
  63110. : currentActive (0)
  63111. {
  63112. }
  63113. ~TopLevelWindowManager()
  63114. {
  63115. clearSingletonInstance();
  63116. }
  63117. juce_DeclareSingleton_SingleThreaded_Minimal (TopLevelWindowManager)
  63118. void timerCallback()
  63119. {
  63120. startTimer (jmin (1731, getTimerInterval() * 2));
  63121. TopLevelWindow* active = 0;
  63122. if (Process::isForegroundProcess())
  63123. {
  63124. active = currentActive;
  63125. Component* const c = Component::getCurrentlyFocusedComponent();
  63126. TopLevelWindow* tlw = dynamic_cast <TopLevelWindow*> (c);
  63127. if (tlw == 0 && c != 0)
  63128. // (unable to use the syntax findParentComponentOfClass <TopLevelWindow> () because of a VC6 compiler bug)
  63129. tlw = c->findParentComponentOfClass ((TopLevelWindow*) 0);
  63130. if (tlw != 0)
  63131. active = tlw;
  63132. }
  63133. if (active != currentActive)
  63134. {
  63135. currentActive = active;
  63136. for (int i = windows.size(); --i >= 0;)
  63137. {
  63138. TopLevelWindow* const tlw = (TopLevelWindow*) windows.getUnchecked (i);
  63139. tlw->setWindowActive (isWindowActive (tlw));
  63140. i = jmin (i, windows.size() - 1);
  63141. }
  63142. Desktop::getInstance().triggerFocusCallback();
  63143. }
  63144. }
  63145. bool addWindow (TopLevelWindow* const w) throw()
  63146. {
  63147. windows.add (w);
  63148. startTimer (10);
  63149. return isWindowActive (w);
  63150. }
  63151. void removeWindow (TopLevelWindow* const w) throw()
  63152. {
  63153. startTimer (10);
  63154. if (currentActive == w)
  63155. currentActive = 0;
  63156. windows.removeValue (w);
  63157. if (windows.size() == 0)
  63158. deleteInstance();
  63159. }
  63160. VoidArray windows;
  63161. private:
  63162. TopLevelWindow* currentActive;
  63163. bool isWindowActive (TopLevelWindow* const tlw) const throw()
  63164. {
  63165. return (tlw == currentActive
  63166. || tlw->isParentOf (currentActive)
  63167. || tlw->hasKeyboardFocus (true))
  63168. && tlw->isShowing();
  63169. }
  63170. TopLevelWindowManager (const TopLevelWindowManager&);
  63171. const TopLevelWindowManager& operator= (const TopLevelWindowManager&);
  63172. };
  63173. juce_ImplementSingleton_SingleThreaded (TopLevelWindowManager)
  63174. void juce_CheckCurrentlyFocusedTopLevelWindow()
  63175. {
  63176. if (TopLevelWindowManager::getInstanceWithoutCreating() != 0)
  63177. TopLevelWindowManager::getInstanceWithoutCreating()->startTimer (20);
  63178. }
  63179. TopLevelWindow::TopLevelWindow (const String& name,
  63180. const bool addToDesktop_)
  63181. : Component (name),
  63182. useDropShadow (true),
  63183. useNativeTitleBar (false),
  63184. windowIsActive_ (false)
  63185. {
  63186. setOpaque (true);
  63187. if (addToDesktop_)
  63188. Component::addToDesktop (getDesktopWindowStyleFlags());
  63189. else
  63190. setDropShadowEnabled (true);
  63191. setWantsKeyboardFocus (true);
  63192. setBroughtToFrontOnMouseClick (true);
  63193. windowIsActive_ = TopLevelWindowManager::getInstance()->addWindow (this);
  63194. }
  63195. TopLevelWindow::~TopLevelWindow()
  63196. {
  63197. shadower = 0;
  63198. TopLevelWindowManager::getInstance()->removeWindow (this);
  63199. }
  63200. void TopLevelWindow::focusOfChildComponentChanged (FocusChangeType)
  63201. {
  63202. if (hasKeyboardFocus (true))
  63203. TopLevelWindowManager::getInstance()->timerCallback();
  63204. else
  63205. TopLevelWindowManager::getInstance()->startTimer (10);
  63206. }
  63207. void TopLevelWindow::setWindowActive (const bool isNowActive) throw()
  63208. {
  63209. if (windowIsActive_ != isNowActive)
  63210. {
  63211. windowIsActive_ = isNowActive;
  63212. activeWindowStatusChanged();
  63213. }
  63214. }
  63215. void TopLevelWindow::activeWindowStatusChanged()
  63216. {
  63217. }
  63218. void TopLevelWindow::parentHierarchyChanged()
  63219. {
  63220. setDropShadowEnabled (useDropShadow);
  63221. }
  63222. void TopLevelWindow::visibilityChanged()
  63223. {
  63224. if (isShowing())
  63225. toFront (true);
  63226. }
  63227. int TopLevelWindow::getDesktopWindowStyleFlags() const
  63228. {
  63229. int flags = ComponentPeer::windowAppearsOnTaskbar;
  63230. if (useDropShadow)
  63231. flags |= ComponentPeer::windowHasDropShadow;
  63232. if (useNativeTitleBar)
  63233. flags |= ComponentPeer::windowHasTitleBar;
  63234. return flags;
  63235. }
  63236. void TopLevelWindow::setDropShadowEnabled (const bool useShadow)
  63237. {
  63238. useDropShadow = useShadow;
  63239. if (isOnDesktop())
  63240. {
  63241. shadower = 0;
  63242. Component::addToDesktop (getDesktopWindowStyleFlags());
  63243. }
  63244. else
  63245. {
  63246. if (useShadow && isOpaque())
  63247. {
  63248. if (shadower == 0)
  63249. {
  63250. shadower = getLookAndFeel().createDropShadowerForComponent (this);
  63251. if (shadower != 0)
  63252. shadower->setOwner (this);
  63253. }
  63254. }
  63255. else
  63256. {
  63257. shadower = 0;
  63258. }
  63259. }
  63260. }
  63261. void TopLevelWindow::setUsingNativeTitleBar (const bool useNativeTitleBar_)
  63262. {
  63263. if (useNativeTitleBar != useNativeTitleBar_)
  63264. {
  63265. useNativeTitleBar = useNativeTitleBar_;
  63266. recreateDesktopWindow();
  63267. sendLookAndFeelChange();
  63268. }
  63269. }
  63270. void TopLevelWindow::recreateDesktopWindow()
  63271. {
  63272. if (isOnDesktop())
  63273. {
  63274. Component::addToDesktop (getDesktopWindowStyleFlags());
  63275. toFront (true);
  63276. }
  63277. }
  63278. void TopLevelWindow::addToDesktop (int windowStyleFlags, void* nativeWindowToAttachTo)
  63279. {
  63280. /* It's not recommended to change the desktop window flags directly for a TopLevelWindow,
  63281. because this class needs to make sure its layout corresponds with settings like whether
  63282. it's got a native title bar or not.
  63283. If you need custom flags for your window, you can override the getDesktopWindowStyleFlags()
  63284. method. If you do this, it's best to call the base class's getDesktopWindowStyleFlags()
  63285. method, then add or remove whatever flags are necessary from this value before returning it.
  63286. */
  63287. jassert ((windowStyleFlags & ~ComponentPeer::windowIsSemiTransparent)
  63288. == (getDesktopWindowStyleFlags() & ~ComponentPeer::windowIsSemiTransparent));
  63289. Component::addToDesktop (windowStyleFlags, nativeWindowToAttachTo);
  63290. if (windowStyleFlags != getDesktopWindowStyleFlags())
  63291. sendLookAndFeelChange();
  63292. }
  63293. void TopLevelWindow::centreAroundComponent (Component* c, const int width, const int height)
  63294. {
  63295. if (c == 0)
  63296. c = TopLevelWindow::getActiveTopLevelWindow();
  63297. if (c == 0)
  63298. {
  63299. centreWithSize (width, height);
  63300. }
  63301. else
  63302. {
  63303. int x = (c->getWidth() - width) / 2;
  63304. int y = (c->getHeight() - height) / 2;
  63305. c->relativePositionToGlobal (x, y);
  63306. Rectangle<int> parentArea (c->getParentMonitorArea());
  63307. if (getParentComponent() != 0)
  63308. {
  63309. getParentComponent()->globalPositionToRelative (x, y);
  63310. parentArea.setBounds (0, 0, getParentWidth(), getParentHeight());
  63311. }
  63312. parentArea.reduce (12, 12);
  63313. setBounds (jlimit (parentArea.getX(), jmax (parentArea.getX(), parentArea.getRight() - width), x),
  63314. jlimit (parentArea.getY(), jmax (parentArea.getY(), parentArea.getBottom() - height), y),
  63315. width, height);
  63316. }
  63317. }
  63318. int TopLevelWindow::getNumTopLevelWindows() throw()
  63319. {
  63320. return TopLevelWindowManager::getInstance()->windows.size();
  63321. }
  63322. TopLevelWindow* TopLevelWindow::getTopLevelWindow (const int index) throw()
  63323. {
  63324. return (TopLevelWindow*) TopLevelWindowManager::getInstance()->windows [index];
  63325. }
  63326. TopLevelWindow* TopLevelWindow::getActiveTopLevelWindow() throw()
  63327. {
  63328. TopLevelWindow* best = 0;
  63329. int bestNumTWLParents = -1;
  63330. for (int i = TopLevelWindow::getNumTopLevelWindows(); --i >= 0;)
  63331. {
  63332. TopLevelWindow* const tlw = TopLevelWindow::getTopLevelWindow (i);
  63333. if (tlw->isActiveWindow())
  63334. {
  63335. int numTWLParents = 0;
  63336. const Component* c = tlw->getParentComponent();
  63337. while (c != 0)
  63338. {
  63339. if (dynamic_cast <const TopLevelWindow*> (c) != 0)
  63340. ++numTWLParents;
  63341. c = c->getParentComponent();
  63342. }
  63343. if (bestNumTWLParents < numTWLParents)
  63344. {
  63345. best = tlw;
  63346. bestNumTWLParents = numTWLParents;
  63347. }
  63348. }
  63349. }
  63350. return best;
  63351. }
  63352. END_JUCE_NAMESPACE
  63353. /*** End of inlined file: juce_TopLevelWindow.cpp ***/
  63354. /*** Start of inlined file: juce_Colour.cpp ***/
  63355. BEGIN_JUCE_NAMESPACE
  63356. static uint8 floatAlphaToInt (const float alpha)
  63357. {
  63358. return (uint8) jlimit (0, 0xff, roundToInt (alpha * 255.0f));
  63359. }
  63360. static const float oneOver255 = 1.0f / 255.0f;
  63361. Colour::Colour() throw()
  63362. : argb (0)
  63363. {
  63364. }
  63365. Colour::Colour (const Colour& other) throw()
  63366. : argb (other.argb)
  63367. {
  63368. }
  63369. const Colour& Colour::operator= (const Colour& other) throw()
  63370. {
  63371. argb = other.argb;
  63372. return *this;
  63373. }
  63374. bool Colour::operator== (const Colour& other) const throw()
  63375. {
  63376. return argb.getARGB() == other.argb.getARGB();
  63377. }
  63378. bool Colour::operator!= (const Colour& other) const throw()
  63379. {
  63380. return argb.getARGB() != other.argb.getARGB();
  63381. }
  63382. Colour::Colour (const uint32 argb_) throw()
  63383. : argb (argb_)
  63384. {
  63385. }
  63386. Colour::Colour (const uint8 red,
  63387. const uint8 green,
  63388. const uint8 blue) throw()
  63389. {
  63390. argb.setARGB (0xff, red, green, blue);
  63391. }
  63392. const Colour Colour::fromRGB (const uint8 red,
  63393. const uint8 green,
  63394. const uint8 blue) throw()
  63395. {
  63396. return Colour (red, green, blue);
  63397. }
  63398. Colour::Colour (const uint8 red,
  63399. const uint8 green,
  63400. const uint8 blue,
  63401. const uint8 alpha) throw()
  63402. {
  63403. argb.setARGB (alpha, red, green, blue);
  63404. }
  63405. const Colour Colour::fromRGBA (const uint8 red,
  63406. const uint8 green,
  63407. const uint8 blue,
  63408. const uint8 alpha) throw()
  63409. {
  63410. return Colour (red, green, blue, alpha);
  63411. }
  63412. Colour::Colour (const uint8 red,
  63413. const uint8 green,
  63414. const uint8 blue,
  63415. const float alpha) throw()
  63416. {
  63417. argb.setARGB (floatAlphaToInt (alpha), red, green, blue);
  63418. }
  63419. const Colour Colour::fromRGBAFloat (const uint8 red,
  63420. const uint8 green,
  63421. const uint8 blue,
  63422. const float alpha) throw()
  63423. {
  63424. return Colour (red, green, blue, alpha);
  63425. }
  63426. static void convertHSBtoRGB (float h, float s, float v,
  63427. uint8& r, uint8& g, uint8& b) throw()
  63428. {
  63429. v = jlimit (0.0f, 1.0f, v);
  63430. v *= 255.0f;
  63431. const uint8 intV = (uint8) roundToInt (v);
  63432. if (s <= 0)
  63433. {
  63434. r = intV;
  63435. g = intV;
  63436. b = intV;
  63437. }
  63438. else
  63439. {
  63440. s = jmin (1.0f, s);
  63441. h = jlimit (0.0f, 1.0f, h);
  63442. h = (h - floorf (h)) * 6.0f + 0.00001f; // need a small adjustment to compensate for rounding errors
  63443. const float f = h - floorf (h);
  63444. const uint8 x = (uint8) roundToInt (v * (1.0f - s));
  63445. const float y = v * (1.0f - s * f);
  63446. const float z = v * (1.0f - (s * (1.0f - f)));
  63447. if (h < 1.0f)
  63448. {
  63449. r = intV;
  63450. g = (uint8) roundToInt (z);
  63451. b = x;
  63452. }
  63453. else if (h < 2.0f)
  63454. {
  63455. r = (uint8) roundToInt (y);
  63456. g = intV;
  63457. b = x;
  63458. }
  63459. else if (h < 3.0f)
  63460. {
  63461. r = x;
  63462. g = intV;
  63463. b = (uint8) roundToInt (z);
  63464. }
  63465. else if (h < 4.0f)
  63466. {
  63467. r = x;
  63468. g = (uint8) roundToInt (y);
  63469. b = intV;
  63470. }
  63471. else if (h < 5.0f)
  63472. {
  63473. r = (uint8) roundToInt (z);
  63474. g = x;
  63475. b = intV;
  63476. }
  63477. else if (h < 6.0f)
  63478. {
  63479. r = intV;
  63480. g = x;
  63481. b = (uint8) roundToInt (y);
  63482. }
  63483. else
  63484. {
  63485. r = 0;
  63486. g = 0;
  63487. b = 0;
  63488. }
  63489. }
  63490. }
  63491. Colour::Colour (const float hue,
  63492. const float saturation,
  63493. const float brightness,
  63494. const float alpha) throw()
  63495. {
  63496. uint8 r = getRed(), g = getGreen(), b = getBlue();
  63497. convertHSBtoRGB (hue, saturation, brightness, r, g, b);
  63498. argb.setARGB (floatAlphaToInt (alpha), r, g, b);
  63499. }
  63500. const Colour Colour::fromHSV (const float hue,
  63501. const float saturation,
  63502. const float brightness,
  63503. const float alpha) throw()
  63504. {
  63505. return Colour (hue, saturation, brightness, alpha);
  63506. }
  63507. Colour::Colour (const float hue,
  63508. const float saturation,
  63509. const float brightness,
  63510. const uint8 alpha) throw()
  63511. {
  63512. uint8 r = getRed(), g = getGreen(), b = getBlue();
  63513. convertHSBtoRGB (hue, saturation, brightness, r, g, b);
  63514. argb.setARGB (alpha, r, g, b);
  63515. }
  63516. Colour::~Colour() throw()
  63517. {
  63518. }
  63519. const PixelARGB Colour::getPixelARGB() const throw()
  63520. {
  63521. PixelARGB p (argb);
  63522. p.premultiply();
  63523. return p;
  63524. }
  63525. uint32 Colour::getARGB() const throw()
  63526. {
  63527. return argb.getARGB();
  63528. }
  63529. bool Colour::isTransparent() const throw()
  63530. {
  63531. return getAlpha() == 0;
  63532. }
  63533. bool Colour::isOpaque() const throw()
  63534. {
  63535. return getAlpha() == 0xff;
  63536. }
  63537. const Colour Colour::withAlpha (const uint8 newAlpha) const throw()
  63538. {
  63539. PixelARGB newCol (argb);
  63540. newCol.setAlpha (newAlpha);
  63541. return Colour (newCol.getARGB());
  63542. }
  63543. const Colour Colour::withAlpha (const float newAlpha) const throw()
  63544. {
  63545. jassert (newAlpha >= 0 && newAlpha <= 1.0f);
  63546. PixelARGB newCol (argb);
  63547. newCol.setAlpha (floatAlphaToInt (newAlpha));
  63548. return Colour (newCol.getARGB());
  63549. }
  63550. const Colour Colour::withMultipliedAlpha (const float alphaMultiplier) const throw()
  63551. {
  63552. jassert (alphaMultiplier >= 0);
  63553. PixelARGB newCol (argb);
  63554. newCol.setAlpha ((uint8) jmin (0xff, roundToInt (alphaMultiplier * newCol.getAlpha())));
  63555. return Colour (newCol.getARGB());
  63556. }
  63557. const Colour Colour::overlaidWith (const Colour& src) const throw()
  63558. {
  63559. const int destAlpha = getAlpha();
  63560. if (destAlpha > 0)
  63561. {
  63562. const int invA = 0xff - (int) src.getAlpha();
  63563. const int resA = 0xff - (((0xff - destAlpha) * invA) >> 8);
  63564. if (resA > 0)
  63565. {
  63566. const int da = (invA * destAlpha) / resA;
  63567. return Colour ((uint8) (src.getRed() + ((((int) getRed() - src.getRed()) * da) >> 8)),
  63568. (uint8) (src.getGreen() + ((((int) getGreen() - src.getGreen()) * da) >> 8)),
  63569. (uint8) (src.getBlue() + ((((int) getBlue() - src.getBlue()) * da) >> 8)),
  63570. (uint8) resA);
  63571. }
  63572. return *this;
  63573. }
  63574. else
  63575. {
  63576. return src;
  63577. }
  63578. }
  63579. const Colour Colour::interpolatedWith (const Colour& other, float proportionOfOther) const throw()
  63580. {
  63581. if (proportionOfOther <= 0)
  63582. return *this;
  63583. if (proportionOfOther >= 1.0f)
  63584. return other;
  63585. PixelARGB c1 (getPixelARGB());
  63586. const PixelARGB c2 (other.getPixelARGB());
  63587. c1.tween (c2, roundToInt (proportionOfOther * 255.0f));
  63588. c1.unpremultiply();
  63589. return Colour (c1.getARGB());
  63590. }
  63591. float Colour::getFloatRed() const throw()
  63592. {
  63593. return getRed() * oneOver255;
  63594. }
  63595. float Colour::getFloatGreen() const throw()
  63596. {
  63597. return getGreen() * oneOver255;
  63598. }
  63599. float Colour::getFloatBlue() const throw()
  63600. {
  63601. return getBlue() * oneOver255;
  63602. }
  63603. float Colour::getFloatAlpha() const throw()
  63604. {
  63605. return getAlpha() * oneOver255;
  63606. }
  63607. void Colour::getHSB (float& h, float& s, float& v) const throw()
  63608. {
  63609. const int r = getRed();
  63610. const int g = getGreen();
  63611. const int b = getBlue();
  63612. const int hi = jmax (r, g, b);
  63613. const int lo = jmin (r, g, b);
  63614. if (hi != 0)
  63615. {
  63616. s = (hi - lo) / (float) hi;
  63617. if (s != 0)
  63618. {
  63619. const float invDiff = 1.0f / (hi - lo);
  63620. const float red = (hi - r) * invDiff;
  63621. const float green = (hi - g) * invDiff;
  63622. const float blue = (hi - b) * invDiff;
  63623. if (r == hi)
  63624. h = blue - green;
  63625. else if (g == hi)
  63626. h = 2.0f + red - blue;
  63627. else
  63628. h = 4.0f + green - red;
  63629. h *= 1.0f / 6.0f;
  63630. if (h < 0)
  63631. ++h;
  63632. }
  63633. else
  63634. {
  63635. h = 0;
  63636. }
  63637. }
  63638. else
  63639. {
  63640. s = 0;
  63641. h = 0;
  63642. }
  63643. v = hi * oneOver255;
  63644. }
  63645. float Colour::getHue() const throw()
  63646. {
  63647. float h, s, b;
  63648. getHSB (h, s, b);
  63649. return h;
  63650. }
  63651. const Colour Colour::withHue (const float hue) const throw()
  63652. {
  63653. float h, s, b;
  63654. getHSB (h, s, b);
  63655. return Colour (hue, s, b, getAlpha());
  63656. }
  63657. const Colour Colour::withRotatedHue (const float amountToRotate) const throw()
  63658. {
  63659. float h, s, b;
  63660. getHSB (h, s, b);
  63661. h += amountToRotate;
  63662. h -= floorf (h);
  63663. return Colour (h, s, b, getAlpha());
  63664. }
  63665. float Colour::getSaturation() const throw()
  63666. {
  63667. float h, s, b;
  63668. getHSB (h, s, b);
  63669. return s;
  63670. }
  63671. const Colour Colour::withSaturation (const float saturation) const throw()
  63672. {
  63673. float h, s, b;
  63674. getHSB (h, s, b);
  63675. return Colour (h, saturation, b, getAlpha());
  63676. }
  63677. const Colour Colour::withMultipliedSaturation (const float amount) const throw()
  63678. {
  63679. float h, s, b;
  63680. getHSB (h, s, b);
  63681. return Colour (h, jmin (1.0f, s * amount), b, getAlpha());
  63682. }
  63683. float Colour::getBrightness() const throw()
  63684. {
  63685. float h, s, b;
  63686. getHSB (h, s, b);
  63687. return b;
  63688. }
  63689. const Colour Colour::withBrightness (const float brightness) const throw()
  63690. {
  63691. float h, s, b;
  63692. getHSB (h, s, b);
  63693. return Colour (h, s, brightness, getAlpha());
  63694. }
  63695. const Colour Colour::withMultipliedBrightness (const float amount) const throw()
  63696. {
  63697. float h, s, b;
  63698. getHSB (h, s, b);
  63699. b *= amount;
  63700. if (b > 1.0f)
  63701. b = 1.0f;
  63702. return Colour (h, s, b, getAlpha());
  63703. }
  63704. const Colour Colour::brighter (float amount) const throw()
  63705. {
  63706. amount = 1.0f / (1.0f + amount);
  63707. return Colour ((uint8) (255 - (amount * (255 - getRed()))),
  63708. (uint8) (255 - (amount * (255 - getGreen()))),
  63709. (uint8) (255 - (amount * (255 - getBlue()))),
  63710. getAlpha());
  63711. }
  63712. const Colour Colour::darker (float amount) const throw()
  63713. {
  63714. amount = 1.0f / (1.0f + amount);
  63715. return Colour ((uint8) (amount * getRed()),
  63716. (uint8) (amount * getGreen()),
  63717. (uint8) (amount * getBlue()),
  63718. getAlpha());
  63719. }
  63720. const Colour Colour::greyLevel (const float brightness) throw()
  63721. {
  63722. const uint8 level
  63723. = (uint8) jlimit (0x00, 0xff, roundToInt (brightness * 255.0f));
  63724. return Colour (level, level, level);
  63725. }
  63726. const Colour Colour::contrasting (const float amount) const throw()
  63727. {
  63728. return overlaidWith ((((int) getRed() + (int) getGreen() + (int) getBlue() >= 3 * 128)
  63729. ? Colours::black
  63730. : Colours::white).withAlpha (amount));
  63731. }
  63732. const Colour Colour::contrasting (const Colour& colour1,
  63733. const Colour& colour2) throw()
  63734. {
  63735. const float b1 = colour1.getBrightness();
  63736. const float b2 = colour2.getBrightness();
  63737. float best = 0.0f;
  63738. float bestDist = 0.0f;
  63739. for (float i = 0.0f; i < 1.0f; i += 0.02f)
  63740. {
  63741. const float d1 = fabsf (i - b1);
  63742. const float d2 = fabsf (i - b2);
  63743. const float dist = jmin (d1, d2, 1.0f - d1, 1.0f - d2);
  63744. if (dist > bestDist)
  63745. {
  63746. best = i;
  63747. bestDist = dist;
  63748. }
  63749. }
  63750. return colour1.overlaidWith (colour2.withMultipliedAlpha (0.5f))
  63751. .withBrightness (best);
  63752. }
  63753. const String Colour::toString() const throw()
  63754. {
  63755. return String::toHexString ((int) argb.getARGB());
  63756. }
  63757. const Colour Colour::fromString (const String& encodedColourString)
  63758. {
  63759. return Colour ((uint32) encodedColourString.getHexValue32());
  63760. }
  63761. END_JUCE_NAMESPACE
  63762. /*** End of inlined file: juce_Colour.cpp ***/
  63763. /*** Start of inlined file: juce_ColourGradient.cpp ***/
  63764. BEGIN_JUCE_NAMESPACE
  63765. ColourGradient::ColourGradient() throw()
  63766. {
  63767. #ifdef JUCE_DEBUG
  63768. x1 = 987654.0f;
  63769. #endif
  63770. }
  63771. ColourGradient::ColourGradient (const Colour& colour1,
  63772. const float x1_,
  63773. const float y1_,
  63774. const Colour& colour2,
  63775. const float x2_,
  63776. const float y2_,
  63777. const bool isRadial_) throw()
  63778. : x1 (x1_),
  63779. y1 (y1_),
  63780. x2 (x2_),
  63781. y2 (y2_),
  63782. isRadial (isRadial_)
  63783. {
  63784. colours.add (0);
  63785. colours.add (colour1.getARGB());
  63786. colours.add (1 << 16);
  63787. colours.add (colour2.getARGB());
  63788. }
  63789. ColourGradient::~ColourGradient() throw()
  63790. {
  63791. }
  63792. void ColourGradient::clearColours() throw()
  63793. {
  63794. colours.clear();
  63795. }
  63796. void ColourGradient::addColour (const double proportionAlongGradient,
  63797. const Colour& colour) throw()
  63798. {
  63799. // must be within the two end-points
  63800. jassert (proportionAlongGradient >= 0 && proportionAlongGradient <= 1.0);
  63801. const uint32 pos = jlimit (0, 65535, roundToInt (proportionAlongGradient * 65536.0));
  63802. int i;
  63803. for (i = 0; i < colours.size(); i += 2)
  63804. if (colours.getUnchecked(i) > pos)
  63805. break;
  63806. colours.insert (i, pos);
  63807. colours.insert (i + 1, colour.getARGB());
  63808. }
  63809. void ColourGradient::multiplyOpacity (const float multiplier) throw()
  63810. {
  63811. for (int i = 1; i < colours.size(); i += 2)
  63812. {
  63813. const Colour c (colours.getUnchecked(i));
  63814. colours.set (i, c.withMultipliedAlpha (multiplier).getARGB());
  63815. }
  63816. }
  63817. int ColourGradient::getNumColours() const throw()
  63818. {
  63819. return colours.size() >> 1;
  63820. }
  63821. double ColourGradient::getColourPosition (const int index) const throw()
  63822. {
  63823. return jlimit (0.0, 1.0, colours [index << 1] / 65535.0);
  63824. }
  63825. const Colour ColourGradient::getColour (const int index) const throw()
  63826. {
  63827. return Colour (colours [(index << 1) + 1]);
  63828. }
  63829. const Colour ColourGradient::getColourAtPosition (const float position) const throw()
  63830. {
  63831. jassert (colours.getUnchecked (0) == 0); // the first colour specified has to go at position 0
  63832. const int integerPos = jlimit (0, 65535, roundToInt (position * 65536.0f));
  63833. if (integerPos <= 0 || colours.size() <= 2)
  63834. return getColour (0);
  63835. int i = colours.size() - 2;
  63836. while (integerPos < (int) colours.getUnchecked(i))
  63837. i -= 2;
  63838. if (i >= colours.size() - 2)
  63839. return Colour (colours.getUnchecked(i));
  63840. const int pos1 = colours.getUnchecked (i);
  63841. const Colour col1 (colours.getUnchecked (i + 1));
  63842. const int pos2 = colours.getUnchecked (i + 2);
  63843. const Colour col2 (colours.getUnchecked (i + 3));
  63844. return col1.interpolatedWith (col2, (integerPos - pos1) / (float) (pos2 - pos1));
  63845. }
  63846. int ColourGradient::createLookupTable (const AffineTransform& transform, HeapBlock <PixelARGB>& lookupTable) const throw()
  63847. {
  63848. #ifdef JUCE_DEBUG
  63849. // trying to use the object without setting its co-ordinates? Have a careful read of
  63850. // the comments for the constructors.
  63851. jassert (x1 != 987654.0f);
  63852. #endif
  63853. const int numColours = colours.size() >> 1;
  63854. float tx1 = x1, ty1 = y1, tx2 = x2, ty2 = y2;
  63855. transform.transformPoint (tx1, ty1);
  63856. transform.transformPoint (tx2, ty2);
  63857. const double distance = juce_hypot (tx1 - tx2, ty1 - ty2);
  63858. const int numEntries = jlimit (1, (numColours - 1) << 8, 3 * (int) distance);
  63859. lookupTable.malloc (numEntries);
  63860. if (numColours >= 2)
  63861. {
  63862. jassert (colours.getUnchecked (0) == 0); // the first colour specified has to go at position 0
  63863. PixelARGB pix1 (colours.getUnchecked (1));
  63864. pix1.premultiply();
  63865. int index = 0;
  63866. for (int j = 2; j < colours.size(); j += 2)
  63867. {
  63868. const int numToDo = ((colours.getUnchecked (j) * (numEntries - 1)) >> 16) - index;
  63869. PixelARGB pix2 (colours.getUnchecked (j + 1));
  63870. pix2.premultiply();
  63871. for (int i = 0; i < numToDo; ++i)
  63872. {
  63873. jassert (index >= 0 && index < numEntries);
  63874. lookupTable[index] = pix1;
  63875. lookupTable[index].tween (pix2, (i << 8) / numToDo);
  63876. ++index;
  63877. }
  63878. pix1 = pix2;
  63879. }
  63880. while (index < numEntries)
  63881. lookupTable [index++] = pix1;
  63882. }
  63883. else
  63884. {
  63885. jassertfalse // no colours specified!
  63886. }
  63887. return numEntries;
  63888. }
  63889. bool ColourGradient::isOpaque() const throw()
  63890. {
  63891. for (int i = 1; i < colours.size(); i += 2)
  63892. if (PixelARGB (colours.getUnchecked(i)).getAlpha() < 0xff)
  63893. return false;
  63894. return true;
  63895. }
  63896. bool ColourGradient::isInvisible() const throw()
  63897. {
  63898. for (int i = 1; i < colours.size(); i += 2)
  63899. if (PixelARGB (colours.getUnchecked(i)).getAlpha() > 0)
  63900. return false;
  63901. return true;
  63902. }
  63903. END_JUCE_NAMESPACE
  63904. /*** End of inlined file: juce_ColourGradient.cpp ***/
  63905. /*** Start of inlined file: juce_Colours.cpp ***/
  63906. BEGIN_JUCE_NAMESPACE
  63907. const Colour Colours::transparentBlack (0);
  63908. const Colour Colours::transparentWhite (0x00ffffff);
  63909. const Colour Colours::aliceblue (0xfff0f8ff);
  63910. const Colour Colours::antiquewhite (0xfffaebd7);
  63911. const Colour Colours::aqua (0xff00ffff);
  63912. const Colour Colours::aquamarine (0xff7fffd4);
  63913. const Colour Colours::azure (0xfff0ffff);
  63914. const Colour Colours::beige (0xfff5f5dc);
  63915. const Colour Colours::bisque (0xffffe4c4);
  63916. const Colour Colours::black (0xff000000);
  63917. const Colour Colours::blanchedalmond (0xffffebcd);
  63918. const Colour Colours::blue (0xff0000ff);
  63919. const Colour Colours::blueviolet (0xff8a2be2);
  63920. const Colour Colours::brown (0xffa52a2a);
  63921. const Colour Colours::burlywood (0xffdeb887);
  63922. const Colour Colours::cadetblue (0xff5f9ea0);
  63923. const Colour Colours::chartreuse (0xff7fff00);
  63924. const Colour Colours::chocolate (0xffd2691e);
  63925. const Colour Colours::coral (0xffff7f50);
  63926. const Colour Colours::cornflowerblue (0xff6495ed);
  63927. const Colour Colours::cornsilk (0xfffff8dc);
  63928. const Colour Colours::crimson (0xffdc143c);
  63929. const Colour Colours::cyan (0xff00ffff);
  63930. const Colour Colours::darkblue (0xff00008b);
  63931. const Colour Colours::darkcyan (0xff008b8b);
  63932. const Colour Colours::darkgoldenrod (0xffb8860b);
  63933. const Colour Colours::darkgrey (0xff555555);
  63934. const Colour Colours::darkgreen (0xff006400);
  63935. const Colour Colours::darkkhaki (0xffbdb76b);
  63936. const Colour Colours::darkmagenta (0xff8b008b);
  63937. const Colour Colours::darkolivegreen (0xff556b2f);
  63938. const Colour Colours::darkorange (0xffff8c00);
  63939. const Colour Colours::darkorchid (0xff9932cc);
  63940. const Colour Colours::darkred (0xff8b0000);
  63941. const Colour Colours::darksalmon (0xffe9967a);
  63942. const Colour Colours::darkseagreen (0xff8fbc8f);
  63943. const Colour Colours::darkslateblue (0xff483d8b);
  63944. const Colour Colours::darkslategrey (0xff2f4f4f);
  63945. const Colour Colours::darkturquoise (0xff00ced1);
  63946. const Colour Colours::darkviolet (0xff9400d3);
  63947. const Colour Colours::deeppink (0xffff1493);
  63948. const Colour Colours::deepskyblue (0xff00bfff);
  63949. const Colour Colours::dimgrey (0xff696969);
  63950. const Colour Colours::dodgerblue (0xff1e90ff);
  63951. const Colour Colours::firebrick (0xffb22222);
  63952. const Colour Colours::floralwhite (0xfffffaf0);
  63953. const Colour Colours::forestgreen (0xff228b22);
  63954. const Colour Colours::fuchsia (0xffff00ff);
  63955. const Colour Colours::gainsboro (0xffdcdcdc);
  63956. const Colour Colours::gold (0xffffd700);
  63957. const Colour Colours::goldenrod (0xffdaa520);
  63958. const Colour Colours::grey (0xff808080);
  63959. const Colour Colours::green (0xff008000);
  63960. const Colour Colours::greenyellow (0xffadff2f);
  63961. const Colour Colours::honeydew (0xfff0fff0);
  63962. const Colour Colours::hotpink (0xffff69b4);
  63963. const Colour Colours::indianred (0xffcd5c5c);
  63964. const Colour Colours::indigo (0xff4b0082);
  63965. const Colour Colours::ivory (0xfffffff0);
  63966. const Colour Colours::khaki (0xfff0e68c);
  63967. const Colour Colours::lavender (0xffe6e6fa);
  63968. const Colour Colours::lavenderblush (0xfffff0f5);
  63969. const Colour Colours::lemonchiffon (0xfffffacd);
  63970. const Colour Colours::lightblue (0xffadd8e6);
  63971. const Colour Colours::lightcoral (0xfff08080);
  63972. const Colour Colours::lightcyan (0xffe0ffff);
  63973. const Colour Colours::lightgoldenrodyellow (0xfffafad2);
  63974. const Colour Colours::lightgreen (0xff90ee90);
  63975. const Colour Colours::lightgrey (0xffd3d3d3);
  63976. const Colour Colours::lightpink (0xffffb6c1);
  63977. const Colour Colours::lightsalmon (0xffffa07a);
  63978. const Colour Colours::lightseagreen (0xff20b2aa);
  63979. const Colour Colours::lightskyblue (0xff87cefa);
  63980. const Colour Colours::lightslategrey (0xff778899);
  63981. const Colour Colours::lightsteelblue (0xffb0c4de);
  63982. const Colour Colours::lightyellow (0xffffffe0);
  63983. const Colour Colours::lime (0xff00ff00);
  63984. const Colour Colours::limegreen (0xff32cd32);
  63985. const Colour Colours::linen (0xfffaf0e6);
  63986. const Colour Colours::magenta (0xffff00ff);
  63987. const Colour Colours::maroon (0xff800000);
  63988. const Colour Colours::mediumaquamarine (0xff66cdaa);
  63989. const Colour Colours::mediumblue (0xff0000cd);
  63990. const Colour Colours::mediumorchid (0xffba55d3);
  63991. const Colour Colours::mediumpurple (0xff9370db);
  63992. const Colour Colours::mediumseagreen (0xff3cb371);
  63993. const Colour Colours::mediumslateblue (0xff7b68ee);
  63994. const Colour Colours::mediumspringgreen (0xff00fa9a);
  63995. const Colour Colours::mediumturquoise (0xff48d1cc);
  63996. const Colour Colours::mediumvioletred (0xffc71585);
  63997. const Colour Colours::midnightblue (0xff191970);
  63998. const Colour Colours::mintcream (0xfff5fffa);
  63999. const Colour Colours::mistyrose (0xffffe4e1);
  64000. const Colour Colours::navajowhite (0xffffdead);
  64001. const Colour Colours::navy (0xff000080);
  64002. const Colour Colours::oldlace (0xfffdf5e6);
  64003. const Colour Colours::olive (0xff808000);
  64004. const Colour Colours::olivedrab (0xff6b8e23);
  64005. const Colour Colours::orange (0xffffa500);
  64006. const Colour Colours::orangered (0xffff4500);
  64007. const Colour Colours::orchid (0xffda70d6);
  64008. const Colour Colours::palegoldenrod (0xffeee8aa);
  64009. const Colour Colours::palegreen (0xff98fb98);
  64010. const Colour Colours::paleturquoise (0xffafeeee);
  64011. const Colour Colours::palevioletred (0xffdb7093);
  64012. const Colour Colours::papayawhip (0xffffefd5);
  64013. const Colour Colours::peachpuff (0xffffdab9);
  64014. const Colour Colours::peru (0xffcd853f);
  64015. const Colour Colours::pink (0xffffc0cb);
  64016. const Colour Colours::plum (0xffdda0dd);
  64017. const Colour Colours::powderblue (0xffb0e0e6);
  64018. const Colour Colours::purple (0xff800080);
  64019. const Colour Colours::red (0xffff0000);
  64020. const Colour Colours::rosybrown (0xffbc8f8f);
  64021. const Colour Colours::royalblue (0xff4169e1);
  64022. const Colour Colours::saddlebrown (0xff8b4513);
  64023. const Colour Colours::salmon (0xfffa8072);
  64024. const Colour Colours::sandybrown (0xfff4a460);
  64025. const Colour Colours::seagreen (0xff2e8b57);
  64026. const Colour Colours::seashell (0xfffff5ee);
  64027. const Colour Colours::sienna (0xffa0522d);
  64028. const Colour Colours::silver (0xffc0c0c0);
  64029. const Colour Colours::skyblue (0xff87ceeb);
  64030. const Colour Colours::slateblue (0xff6a5acd);
  64031. const Colour Colours::slategrey (0xff708090);
  64032. const Colour Colours::snow (0xfffffafa);
  64033. const Colour Colours::springgreen (0xff00ff7f);
  64034. const Colour Colours::steelblue (0xff4682b4);
  64035. const Colour Colours::tan (0xffd2b48c);
  64036. const Colour Colours::teal (0xff008080);
  64037. const Colour Colours::thistle (0xffd8bfd8);
  64038. const Colour Colours::tomato (0xffff6347);
  64039. const Colour Colours::turquoise (0xff40e0d0);
  64040. const Colour Colours::violet (0xffee82ee);
  64041. const Colour Colours::wheat (0xfff5deb3);
  64042. const Colour Colours::white (0xffffffff);
  64043. const Colour Colours::whitesmoke (0xfff5f5f5);
  64044. const Colour Colours::yellow (0xffffff00);
  64045. const Colour Colours::yellowgreen (0xff9acd32);
  64046. const Colour Colours::findColourForName (const String& colourName,
  64047. const Colour& defaultColour)
  64048. {
  64049. static const int presets[] =
  64050. {
  64051. // (first value is the string's hashcode, second is ARGB)
  64052. 0x05978fff, 0xff000000, /* black */
  64053. 0x06bdcc29, 0xffffffff, /* white */
  64054. 0x002e305a, 0xff0000ff, /* blue */
  64055. 0x00308adf, 0xff808080, /* grey */
  64056. 0x05e0cf03, 0xff008000, /* green */
  64057. 0x0001b891, 0xffff0000, /* red */
  64058. 0xd43c6474, 0xffffff00, /* yellow */
  64059. 0x620886da, 0xfff0f8ff, /* aliceblue */
  64060. 0x20a2676a, 0xfffaebd7, /* antiquewhite */
  64061. 0x002dcebc, 0xff00ffff, /* aqua */
  64062. 0x46bb5f7e, 0xff7fffd4, /* aquamarine */
  64063. 0x0590228f, 0xfff0ffff, /* azure */
  64064. 0x05947fe4, 0xfff5f5dc, /* beige */
  64065. 0xad388e35, 0xffffe4c4, /* bisque */
  64066. 0x00674f7e, 0xffffebcd, /* blanchedalmond */
  64067. 0x39129959, 0xff8a2be2, /* blueviolet */
  64068. 0x059a8136, 0xffa52a2a, /* brown */
  64069. 0x89cea8f9, 0xffdeb887, /* burlywood */
  64070. 0x0fa260cf, 0xff5f9ea0, /* cadetblue */
  64071. 0x6b748956, 0xff7fff00, /* chartreuse */
  64072. 0x2903623c, 0xffd2691e, /* chocolate */
  64073. 0x05a74431, 0xffff7f50, /* coral */
  64074. 0x618d42dd, 0xff6495ed, /* cornflowerblue */
  64075. 0xe4b479fd, 0xfffff8dc, /* cornsilk */
  64076. 0x3d8c4edf, 0xffdc143c, /* crimson */
  64077. 0x002ed323, 0xff00ffff, /* cyan */
  64078. 0x67cc74d0, 0xff00008b, /* darkblue */
  64079. 0x67cd1799, 0xff008b8b, /* darkcyan */
  64080. 0x31bbd168, 0xffb8860b, /* darkgoldenrod */
  64081. 0x67cecf55, 0xff555555, /* darkgrey */
  64082. 0x920b194d, 0xff006400, /* darkgreen */
  64083. 0x923edd4c, 0xffbdb76b, /* darkkhaki */
  64084. 0x5c293873, 0xff8b008b, /* darkmagenta */
  64085. 0x6b6671fe, 0xff556b2f, /* darkolivegreen */
  64086. 0xbcfd2524, 0xffff8c00, /* darkorange */
  64087. 0xbcfdf799, 0xff9932cc, /* darkorchid */
  64088. 0x55ee0d5b, 0xff8b0000, /* darkred */
  64089. 0xc2e5f564, 0xffe9967a, /* darksalmon */
  64090. 0x61be858a, 0xff8fbc8f, /* darkseagreen */
  64091. 0xc2b0f2bd, 0xff483d8b, /* darkslateblue */
  64092. 0xc2b34d42, 0xff2f4f4f, /* darkslategrey */
  64093. 0x7cf2b06b, 0xff00ced1, /* darkturquoise */
  64094. 0xc8769375, 0xff9400d3, /* darkviolet */
  64095. 0x25832862, 0xffff1493, /* deeppink */
  64096. 0xfcad568f, 0xff00bfff, /* deepskyblue */
  64097. 0x634c8b67, 0xff696969, /* dimgrey */
  64098. 0x45c1ce55, 0xff1e90ff, /* dodgerblue */
  64099. 0xef19e3cb, 0xffb22222, /* firebrick */
  64100. 0xb852b195, 0xfffffaf0, /* floralwhite */
  64101. 0xd086fd06, 0xff228b22, /* forestgreen */
  64102. 0xe106b6d7, 0xffff00ff, /* fuchsia */
  64103. 0x7880d61e, 0xffdcdcdc, /* gainsboro */
  64104. 0x00308060, 0xffffd700, /* gold */
  64105. 0xb3b3bc1e, 0xffdaa520, /* goldenrod */
  64106. 0xbab8a537, 0xffadff2f, /* greenyellow */
  64107. 0xe4cacafb, 0xfff0fff0, /* honeydew */
  64108. 0x41892743, 0xffff69b4, /* hotpink */
  64109. 0xd5796f1a, 0xffcd5c5c, /* indianred */
  64110. 0xb969fed2, 0xff4b0082, /* indigo */
  64111. 0x05fef6a9, 0xfffffff0, /* ivory */
  64112. 0x06149302, 0xfff0e68c, /* khaki */
  64113. 0xad5a05c7, 0xffe6e6fa, /* lavender */
  64114. 0x7c4d5b99, 0xfffff0f5, /* lavenderblush */
  64115. 0x195756f0, 0xfffffacd, /* lemonchiffon */
  64116. 0x28e4ea70, 0xffadd8e6, /* lightblue */
  64117. 0xf3c7ccdb, 0xfff08080, /* lightcoral */
  64118. 0x28e58d39, 0xffe0ffff, /* lightcyan */
  64119. 0x21234e3c, 0xfffafad2, /* lightgoldenrodyellow */
  64120. 0xf40157ad, 0xff90ee90, /* lightgreen */
  64121. 0x28e744f5, 0xffd3d3d3, /* lightgrey */
  64122. 0x28eb3b8c, 0xffffb6c1, /* lightpink */
  64123. 0x9fb78304, 0xffffa07a, /* lightsalmon */
  64124. 0x50632b2a, 0xff20b2aa, /* lightseagreen */
  64125. 0x68fb7b25, 0xff87cefa, /* lightskyblue */
  64126. 0xa8a35ba2, 0xff778899, /* lightslategrey */
  64127. 0xa20d484f, 0xffb0c4de, /* lightsteelblue */
  64128. 0xaa2cf10a, 0xffffffe0, /* lightyellow */
  64129. 0x0032afd5, 0xff00ff00, /* lime */
  64130. 0x607bbc4e, 0xff32cd32, /* limegreen */
  64131. 0x06234efa, 0xfffaf0e6, /* linen */
  64132. 0x316858a9, 0xffff00ff, /* magenta */
  64133. 0xbf8ca470, 0xff800000, /* maroon */
  64134. 0xbd58e0b3, 0xff66cdaa, /* mediumaquamarine */
  64135. 0x967dfd4f, 0xff0000cd, /* mediumblue */
  64136. 0x056f5c58, 0xffba55d3, /* mediumorchid */
  64137. 0x07556b71, 0xff9370db, /* mediumpurple */
  64138. 0x5369b689, 0xff3cb371, /* mediumseagreen */
  64139. 0x066be19e, 0xff7b68ee, /* mediumslateblue */
  64140. 0x3256b281, 0xff00fa9a, /* mediumspringgreen */
  64141. 0xc0ad9f4c, 0xff48d1cc, /* mediumturquoise */
  64142. 0x628e63dd, 0xffc71585, /* mediumvioletred */
  64143. 0x168eb32a, 0xff191970, /* midnightblue */
  64144. 0x4306b960, 0xfff5fffa, /* mintcream */
  64145. 0x4cbc0e6b, 0xffffe4e1, /* mistyrose */
  64146. 0xe97218a6, 0xffffdead, /* navajowhite */
  64147. 0x00337bb6, 0xff000080, /* navy */
  64148. 0xadd2d33e, 0xfffdf5e6, /* oldlace */
  64149. 0x064ee1db, 0xff808000, /* olive */
  64150. 0x9e33a98a, 0xff6b8e23, /* olivedrab */
  64151. 0xc3de262e, 0xffffa500, /* orange */
  64152. 0x58bebba3, 0xffff4500, /* orangered */
  64153. 0xc3def8a3, 0xffda70d6, /* orchid */
  64154. 0x28cb4834, 0xffeee8aa, /* palegoldenrod */
  64155. 0x3d9dd619, 0xff98fb98, /* palegreen */
  64156. 0x74022737, 0xffafeeee, /* paleturquoise */
  64157. 0x15e2ebc8, 0xffdb7093, /* palevioletred */
  64158. 0x5fd898e2, 0xffffefd5, /* papayawhip */
  64159. 0x93e1b776, 0xffffdab9, /* peachpuff */
  64160. 0x003472f8, 0xffcd853f, /* peru */
  64161. 0x00348176, 0xffffc0cb, /* pink */
  64162. 0x00348d94, 0xffdda0dd, /* plum */
  64163. 0xd036be93, 0xffb0e0e6, /* powderblue */
  64164. 0xc5c507bc, 0xff800080, /* purple */
  64165. 0xa89d65b3, 0xffbc8f8f, /* rosybrown */
  64166. 0xbd9413e1, 0xff4169e1, /* royalblue */
  64167. 0xf456044f, 0xff8b4513, /* saddlebrown */
  64168. 0xc9c6f66e, 0xfffa8072, /* salmon */
  64169. 0x0bb131e1, 0xfff4a460, /* sandybrown */
  64170. 0x34636c14, 0xff2e8b57, /* seagreen */
  64171. 0x3507fb41, 0xfffff5ee, /* seashell */
  64172. 0xca348772, 0xffa0522d, /* sienna */
  64173. 0xca37d30d, 0xffc0c0c0, /* silver */
  64174. 0x80da74fb, 0xff87ceeb, /* skyblue */
  64175. 0x44a8dd73, 0xff6a5acd, /* slateblue */
  64176. 0x44ab37f8, 0xff708090, /* slategrey */
  64177. 0x0035f183, 0xfffffafa, /* snow */
  64178. 0xd5440d16, 0xff00ff7f, /* springgreen */
  64179. 0x3e1524a5, 0xff4682b4, /* steelblue */
  64180. 0x0001bfa1, 0xffd2b48c, /* tan */
  64181. 0x0036425c, 0xff008080, /* teal */
  64182. 0xafc8858f, 0xffd8bfd8, /* thistle */
  64183. 0xcc41600a, 0xffff6347, /* tomato */
  64184. 0xfeea9b21, 0xff40e0d0, /* turquoise */
  64185. 0xcf57947f, 0xffee82ee, /* violet */
  64186. 0x06bdbae7, 0xfff5deb3, /* wheat */
  64187. 0x10802ee6, 0xfff5f5f5, /* whitesmoke */
  64188. 0xe1b5130f, 0xff9acd32 /* yellowgreen */
  64189. };
  64190. const int hash = colourName.trim().toLowerCase().hashCode();
  64191. for (int i = 0; i < numElementsInArray (presets); i += 2)
  64192. if (presets [i] == hash)
  64193. return Colour (presets [i + 1]);
  64194. return defaultColour;
  64195. }
  64196. END_JUCE_NAMESPACE
  64197. /*** End of inlined file: juce_Colours.cpp ***/
  64198. /*** Start of inlined file: juce_EdgeTable.cpp ***/
  64199. BEGIN_JUCE_NAMESPACE
  64200. const int juce_edgeTableDefaultEdgesPerLine = 32;
  64201. static void copyEdgeTableData (int* dest, const int destLineStride, const int* src, const int srcLineStride, int numLines) throw()
  64202. {
  64203. while (--numLines >= 0)
  64204. {
  64205. memcpy (dest, src, (src[0] * 2 + 1) * sizeof (int));
  64206. src += srcLineStride;
  64207. dest += destLineStride;
  64208. }
  64209. }
  64210. EdgeTable::EdgeTable (const Rectangle<int>& bounds_,
  64211. const Path& path, const AffineTransform& transform) throw()
  64212. : bounds (bounds_),
  64213. maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine),
  64214. lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1),
  64215. needToCheckEmptinesss (true)
  64216. {
  64217. table.malloc ((bounds.getHeight() + 1) * lineStrideElements);
  64218. int* t = table;
  64219. for (int i = bounds.getHeight(); --i >= 0;)
  64220. {
  64221. *t = 0;
  64222. t += lineStrideElements;
  64223. }
  64224. const int topLimit = bounds.getY() << 8;
  64225. const int heightLimit = bounds.getHeight() << 8;
  64226. const int leftLimit = bounds.getX() << 8;
  64227. const int rightLimit = bounds.getRight() << 8;
  64228. PathFlatteningIterator iter (path, transform);
  64229. while (iter.next())
  64230. {
  64231. int y1 = roundToInt (iter.y1 * 256.0f);
  64232. int y2 = roundToInt (iter.y2 * 256.0f);
  64233. if (y1 != y2)
  64234. {
  64235. y1 -= topLimit;
  64236. y2 -= topLimit;
  64237. const int startY = y1;
  64238. int direction = -1;
  64239. if (y1 > y2)
  64240. {
  64241. swapVariables (y1, y2);
  64242. direction = 1;
  64243. }
  64244. if (y1 < 0)
  64245. y1 = 0;
  64246. if (y2 > heightLimit)
  64247. y2 = heightLimit;
  64248. if (y1 < y2)
  64249. {
  64250. const double startX = 256.0f * iter.x1;
  64251. const double multiplier = (iter.x2 - iter.x1) / (iter.y2 - iter.y1);
  64252. const int stepSize = jlimit (1, 256, 256 / (1 + (int) fabs (multiplier)));
  64253. do
  64254. {
  64255. const int step = jmin (stepSize, y2 - y1, 256 - (y1 & 255));
  64256. int x = roundToInt (startX + multiplier * ((y1 + (step >> 1)) - startY));
  64257. if (x < leftLimit)
  64258. x = leftLimit;
  64259. else if (x >= rightLimit)
  64260. x = rightLimit - 1;
  64261. addEdgePoint (x, y1 >> 8, direction * step);
  64262. y1 += step;
  64263. }
  64264. while (y1 < y2);
  64265. }
  64266. }
  64267. }
  64268. sanitiseLevels (path.isUsingNonZeroWinding());
  64269. }
  64270. EdgeTable::EdgeTable (const Rectangle<int>& rectangleToAdd) throw()
  64271. : bounds (rectangleToAdd),
  64272. maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine),
  64273. lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1),
  64274. needToCheckEmptinesss (true)
  64275. {
  64276. table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements);
  64277. table[0] = 0;
  64278. const int x1 = rectangleToAdd.getX() << 8;
  64279. const int x2 = rectangleToAdd.getRight() << 8;
  64280. int* t = table;
  64281. for (int i = rectangleToAdd.getHeight(); --i >= 0;)
  64282. {
  64283. t[0] = 2;
  64284. t[1] = x1;
  64285. t[2] = 255;
  64286. t[3] = x2;
  64287. t[4] = 0;
  64288. t += lineStrideElements;
  64289. }
  64290. }
  64291. EdgeTable::EdgeTable (const RectangleList& rectanglesToAdd) throw()
  64292. : bounds (rectanglesToAdd.getBounds()),
  64293. maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine),
  64294. lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1),
  64295. needToCheckEmptinesss (true)
  64296. {
  64297. table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements);
  64298. int* t = table;
  64299. for (int i = bounds.getHeight(); --i >= 0;)
  64300. {
  64301. *t = 0;
  64302. t += lineStrideElements;
  64303. }
  64304. for (RectangleList::Iterator iter (rectanglesToAdd); iter.next();)
  64305. {
  64306. const Rectangle<int>* const r = iter.getRectangle();
  64307. const int x1 = r->getX() << 8;
  64308. const int x2 = r->getRight() << 8;
  64309. int y = r->getY() - bounds.getY();
  64310. for (int j = r->getHeight(); --j >= 0;)
  64311. {
  64312. addEdgePoint (x1, y, 255);
  64313. addEdgePoint (x2, y, -255);
  64314. ++y;
  64315. }
  64316. }
  64317. sanitiseLevels (true);
  64318. }
  64319. EdgeTable::EdgeTable (const float x, const float y, const float w, const float h) throw()
  64320. : bounds (Rectangle<int> ((int) floorf (x), roundToInt (y * 256.0f) >> 8, 2 + (int) w, 2 + (int) h)),
  64321. maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine),
  64322. lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1),
  64323. needToCheckEmptinesss (true)
  64324. {
  64325. jassert (w > 0 && h > 0);
  64326. table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements);
  64327. table[0] = 0;
  64328. const int x1 = roundToInt (x * 256.0f);
  64329. const int x2 = roundToInt ((x + w) * 256.0f);
  64330. int y1 = roundToInt (y * 256.0f) - (bounds.getY() << 8);
  64331. jassert (y1 < 256);
  64332. int y2 = roundToInt ((y + h) * 256.0f) - (bounds.getY() << 8);
  64333. if (x2 <= x1 || y2 <= y1)
  64334. {
  64335. bounds.setHeight (0);
  64336. return;
  64337. }
  64338. int lineY = 0;
  64339. int* t = table;
  64340. if ((y1 >> 8) == (y2 >> 8))
  64341. {
  64342. t[0] = 2;
  64343. t[1] = x1;
  64344. t[2] = y2 - y1;
  64345. t[3] = x2;
  64346. t[4] = 0;
  64347. ++lineY;
  64348. t += lineStrideElements;
  64349. }
  64350. else
  64351. {
  64352. t[0] = 2;
  64353. t[1] = x1;
  64354. t[2] = 255 - (y1 & 255);
  64355. t[3] = x2;
  64356. t[4] = 0;
  64357. ++lineY;
  64358. t += lineStrideElements;
  64359. while (lineY < (y2 >> 8))
  64360. {
  64361. t[0] = 2;
  64362. t[1] = x1;
  64363. t[2] = 255;
  64364. t[3] = x2;
  64365. t[4] = 0;
  64366. ++lineY;
  64367. t += lineStrideElements;
  64368. }
  64369. jassert (lineY < bounds.getHeight());
  64370. t[0] = 2;
  64371. t[1] = x1;
  64372. t[2] = y2 & 255;
  64373. t[3] = x2;
  64374. t[4] = 0;
  64375. ++lineY;
  64376. t += lineStrideElements;
  64377. }
  64378. while (lineY < bounds.getHeight())
  64379. {
  64380. t[0] = 0;
  64381. t += lineStrideElements;
  64382. ++lineY;
  64383. }
  64384. }
  64385. EdgeTable::EdgeTable (const EdgeTable& other) throw()
  64386. : table (0)
  64387. {
  64388. operator= (other);
  64389. }
  64390. const EdgeTable& EdgeTable::operator= (const EdgeTable& other) throw()
  64391. {
  64392. bounds = other.bounds;
  64393. maxEdgesPerLine = other.maxEdgesPerLine;
  64394. lineStrideElements = other.lineStrideElements;
  64395. needToCheckEmptinesss = other.needToCheckEmptinesss;
  64396. table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements);
  64397. copyEdgeTableData (table, lineStrideElements, other.table, lineStrideElements, bounds.getHeight());
  64398. return *this;
  64399. }
  64400. EdgeTable::~EdgeTable() throw()
  64401. {
  64402. }
  64403. void EdgeTable::sanitiseLevels (const bool useNonZeroWinding) throw()
  64404. {
  64405. // Convert the table from relative windings to absolute levels..
  64406. int* lineStart = table;
  64407. for (int i = bounds.getHeight(); --i >= 0;)
  64408. {
  64409. int* line = lineStart;
  64410. lineStart += lineStrideElements;
  64411. int num = *line;
  64412. if (num == 0)
  64413. continue;
  64414. int level = 0;
  64415. if (useNonZeroWinding)
  64416. {
  64417. while (--num > 0)
  64418. {
  64419. line += 2;
  64420. level += *line;
  64421. int corrected = abs (level);
  64422. if (corrected >> 8)
  64423. corrected = 255;
  64424. *line = corrected;
  64425. }
  64426. }
  64427. else
  64428. {
  64429. while (--num > 0)
  64430. {
  64431. line += 2;
  64432. level += *line;
  64433. int corrected = abs (level);
  64434. if (corrected >> 8)
  64435. {
  64436. corrected &= 511;
  64437. if (corrected >> 8)
  64438. corrected = 511 - corrected;
  64439. }
  64440. *line = corrected;
  64441. }
  64442. }
  64443. line[2] = 0; // force the last level to 0, just in case something went wrong in creating the table
  64444. }
  64445. }
  64446. void EdgeTable::remapTableForNumEdges (const int newNumEdgesPerLine) throw()
  64447. {
  64448. if (newNumEdgesPerLine != maxEdgesPerLine)
  64449. {
  64450. maxEdgesPerLine = newNumEdgesPerLine;
  64451. jassert (bounds.getHeight() > 0);
  64452. const int newLineStrideElements = maxEdgesPerLine * 2 + 1;
  64453. HeapBlock <int> newTable (bounds.getHeight() * newLineStrideElements);
  64454. copyEdgeTableData (newTable, newLineStrideElements, table, lineStrideElements, bounds.getHeight());
  64455. table.swapWith (newTable);
  64456. lineStrideElements = newLineStrideElements;
  64457. }
  64458. }
  64459. void EdgeTable::optimiseTable() throw()
  64460. {
  64461. int maxLineElements = 0;
  64462. for (int i = bounds.getHeight(); --i >= 0;)
  64463. maxLineElements = jmax (maxLineElements, table [i * lineStrideElements]);
  64464. remapTableForNumEdges (maxLineElements);
  64465. }
  64466. void EdgeTable::addEdgePoint (const int x, const int y, const int winding) throw()
  64467. {
  64468. jassert (y >= 0 && y < bounds.getHeight());
  64469. int* line = table + lineStrideElements * y;
  64470. const int numPoints = line[0];
  64471. int n = numPoints << 1;
  64472. if (n > 0)
  64473. {
  64474. while (n > 0)
  64475. {
  64476. const int cx = line [n - 1];
  64477. if (cx <= x)
  64478. {
  64479. if (cx == x)
  64480. {
  64481. line [n] += winding;
  64482. return;
  64483. }
  64484. break;
  64485. }
  64486. n -= 2;
  64487. }
  64488. if (numPoints >= maxEdgesPerLine)
  64489. {
  64490. remapTableForNumEdges (maxEdgesPerLine + juce_edgeTableDefaultEdgesPerLine);
  64491. jassert (numPoints < maxEdgesPerLine);
  64492. line = table + lineStrideElements * y;
  64493. }
  64494. memmove (line + (n + 3), line + (n + 1), sizeof (int) * ((numPoints << 1) - n));
  64495. }
  64496. line [n + 1] = x;
  64497. line [n + 2] = winding;
  64498. line[0]++;
  64499. }
  64500. void EdgeTable::translate (float dx, int dy) throw()
  64501. {
  64502. bounds.setPosition (bounds.getX() + (int) floorf (dx), bounds.getY() + dy);
  64503. int* lineStart = table;
  64504. const int intDx = (int) (dx * 256.0f);
  64505. for (int i = bounds.getHeight(); --i >= 0;)
  64506. {
  64507. int* line = lineStart;
  64508. lineStart += lineStrideElements;
  64509. int num = *line++;
  64510. while (--num >= 0)
  64511. {
  64512. *line += intDx;
  64513. line += 2;
  64514. }
  64515. }
  64516. }
  64517. void EdgeTable::intersectWithEdgeTableLine (const int y, const int* otherLine) throw()
  64518. {
  64519. jassert (y >= 0 && y < bounds.getHeight());
  64520. int* dest = table + lineStrideElements * y;
  64521. if (dest[0] == 0)
  64522. return;
  64523. int otherNumPoints = *otherLine;
  64524. if (otherNumPoints == 0)
  64525. {
  64526. *dest = 0;
  64527. return;
  64528. }
  64529. const int right = bounds.getRight() << 8;
  64530. // optimise for the common case where our line lies entirely within a
  64531. // single pair of points, as happens when clipping to a simple rect.
  64532. if (otherNumPoints == 2 && otherLine[2] >= 255)
  64533. {
  64534. clipEdgeTableLineToRange (dest, otherLine[1], jmin (right, otherLine[3]));
  64535. return;
  64536. }
  64537. ++otherLine;
  64538. const size_t lineSizeBytes = (dest[0] * 2 + 1) * sizeof (int);
  64539. int* temp = (int*) alloca (lineSizeBytes);
  64540. memcpy (temp, dest, lineSizeBytes);
  64541. const int* src1 = temp;
  64542. int srcNum1 = *src1++;
  64543. int x1 = *src1++;
  64544. const int* src2 = otherLine;
  64545. int srcNum2 = otherNumPoints;
  64546. int x2 = *src2++;
  64547. int destIndex = 0, destTotal = 0;
  64548. int level1 = 0, level2 = 0;
  64549. int lastX = std::numeric_limits<int>::min(), lastLevel = 0;
  64550. while (srcNum1 > 0 && srcNum2 > 0)
  64551. {
  64552. int nextX;
  64553. if (x1 < x2)
  64554. {
  64555. nextX = x1;
  64556. level1 = *src1++;
  64557. x1 = *src1++;
  64558. --srcNum1;
  64559. }
  64560. else if (x1 == x2)
  64561. {
  64562. nextX = x1;
  64563. level1 = *src1++;
  64564. level2 = *src2++;
  64565. x1 = *src1++;
  64566. x2 = *src2++;
  64567. --srcNum1;
  64568. --srcNum2;
  64569. }
  64570. else
  64571. {
  64572. nextX = x2;
  64573. level2 = *src2++;
  64574. x2 = *src2++;
  64575. --srcNum2;
  64576. }
  64577. if (nextX > lastX)
  64578. {
  64579. if (nextX >= right)
  64580. break;
  64581. lastX = nextX;
  64582. const int nextLevel = (level1 * (level2 + 1)) >> 8;
  64583. jassert (((unsigned int) nextLevel) < (unsigned int) 256);
  64584. if (nextLevel != lastLevel)
  64585. {
  64586. if (destTotal >= maxEdgesPerLine)
  64587. {
  64588. dest[0] = destTotal;
  64589. remapTableForNumEdges (maxEdgesPerLine + juce_edgeTableDefaultEdgesPerLine);
  64590. dest = table + lineStrideElements * y;
  64591. }
  64592. ++destTotal;
  64593. lastLevel = nextLevel;
  64594. dest[++destIndex] = nextX;
  64595. dest[++destIndex] = nextLevel;
  64596. }
  64597. }
  64598. }
  64599. if (lastLevel > 0)
  64600. {
  64601. if (destTotal >= maxEdgesPerLine)
  64602. {
  64603. dest[0] = destTotal;
  64604. remapTableForNumEdges (maxEdgesPerLine + juce_edgeTableDefaultEdgesPerLine);
  64605. dest = table + lineStrideElements * y;
  64606. }
  64607. ++destTotal;
  64608. dest[++destIndex] = right;
  64609. dest[++destIndex] = 0;
  64610. }
  64611. dest[0] = destTotal;
  64612. #if JUCE_DEBUG
  64613. int last = std::numeric_limits<int>::min();
  64614. for (int i = 0; i < dest[0]; ++i)
  64615. {
  64616. jassert (dest[i * 2 + 1] > last);
  64617. last = dest[i * 2 + 1];
  64618. }
  64619. jassert (dest [dest[0] * 2] == 0);
  64620. #endif
  64621. }
  64622. void EdgeTable::clipEdgeTableLineToRange (int* dest, const int x1, const int x2) throw()
  64623. {
  64624. int* lastItem = dest + (dest[0] * 2 - 1);
  64625. if (x2 < lastItem[0])
  64626. {
  64627. if (x2 <= dest[1])
  64628. {
  64629. dest[0] = 0;
  64630. return;
  64631. }
  64632. while (x2 < lastItem[-2])
  64633. {
  64634. --(dest[0]);
  64635. lastItem -= 2;
  64636. }
  64637. lastItem[0] = x2;
  64638. lastItem[1] = 0;
  64639. }
  64640. if (x1 > dest[1])
  64641. {
  64642. while (lastItem[0] > x1)
  64643. lastItem -= 2;
  64644. const int itemsRemoved = (int) (lastItem - (dest + 1)) / 2;
  64645. if (itemsRemoved > 0)
  64646. {
  64647. dest[0] -= itemsRemoved;
  64648. memmove (dest + 1, lastItem, dest[0] * (sizeof (int) * 2));
  64649. }
  64650. dest[1] = x1;
  64651. }
  64652. }
  64653. void EdgeTable::clipToRectangle (const Rectangle<int>& r) throw()
  64654. {
  64655. const Rectangle<int> clipped (r.getIntersection (bounds));
  64656. if (clipped.isEmpty())
  64657. {
  64658. needToCheckEmptinesss = false;
  64659. bounds.setHeight (0);
  64660. }
  64661. else
  64662. {
  64663. const int top = clipped.getY() - bounds.getY();
  64664. const int bottom = clipped.getBottom() - bounds.getY();
  64665. if (bottom < bounds.getHeight())
  64666. bounds.setHeight (bottom);
  64667. if (clipped.getRight() < bounds.getRight())
  64668. bounds.setRight (clipped.getRight());
  64669. for (int i = top; --i >= 0;)
  64670. table [lineStrideElements * i] = 0;
  64671. if (clipped.getX() > bounds.getX())
  64672. {
  64673. const int x1 = clipped.getX() << 8;
  64674. const int x2 = jmin (bounds.getRight(), clipped.getRight()) << 8;
  64675. int* line = table + lineStrideElements * top;
  64676. for (int i = bottom - top; --i >= 0;)
  64677. {
  64678. if (line[0] != 0)
  64679. clipEdgeTableLineToRange (line, x1, x2);
  64680. line += lineStrideElements;
  64681. }
  64682. }
  64683. needToCheckEmptinesss = true;
  64684. }
  64685. }
  64686. void EdgeTable::excludeRectangle (const Rectangle<int>& r) throw()
  64687. {
  64688. const Rectangle<int> clipped (r.getIntersection (bounds));
  64689. if (! clipped.isEmpty())
  64690. {
  64691. const int top = clipped.getY() - bounds.getY();
  64692. const int bottom = clipped.getBottom() - bounds.getY();
  64693. //XXX optimise here by shortening the table if it fills top or bottom
  64694. const int rectLine[] = { 4, std::numeric_limits<int>::min(), 255,
  64695. clipped.getX() << 8, 0,
  64696. clipped.getRight() << 8, 255,
  64697. std::numeric_limits<int>::max(), 0 };
  64698. for (int i = top; i < bottom; ++i)
  64699. intersectWithEdgeTableLine (i, rectLine);
  64700. needToCheckEmptinesss = true;
  64701. }
  64702. }
  64703. void EdgeTable::clipToEdgeTable (const EdgeTable& other)
  64704. {
  64705. const Rectangle<int> clipped (other.bounds.getIntersection (bounds));
  64706. if (clipped.isEmpty())
  64707. {
  64708. needToCheckEmptinesss = false;
  64709. bounds.setHeight (0);
  64710. }
  64711. else
  64712. {
  64713. const int top = clipped.getY() - bounds.getY();
  64714. const int bottom = clipped.getBottom() - bounds.getY();
  64715. if (bottom < bounds.getHeight())
  64716. bounds.setHeight (bottom);
  64717. if (clipped.getRight() < bounds.getRight())
  64718. bounds.setRight (clipped.getRight());
  64719. int i = 0;
  64720. for (i = top; --i >= 0;)
  64721. table [lineStrideElements * i] = 0;
  64722. const int* otherLine = other.table + other.lineStrideElements * (clipped.getY() - other.bounds.getY());
  64723. for (i = top; i < bottom; ++i)
  64724. {
  64725. intersectWithEdgeTableLine (i, otherLine);
  64726. otherLine += other.lineStrideElements;
  64727. }
  64728. needToCheckEmptinesss = true;
  64729. }
  64730. }
  64731. void EdgeTable::clipLineToMask (int x, int y, uint8* mask, int maskStride, int numPixels) throw()
  64732. {
  64733. y -= bounds.getY();
  64734. if (y < 0 || y >= bounds.getHeight())
  64735. return;
  64736. needToCheckEmptinesss = true;
  64737. if (numPixels <= 0)
  64738. {
  64739. table [lineStrideElements * y] = 0;
  64740. return;
  64741. }
  64742. int* tempLine = (int*) alloca ((numPixels * 2 + 4) * sizeof (int));
  64743. int destIndex = 0, lastLevel = 0;
  64744. while (--numPixels >= 0)
  64745. {
  64746. const int alpha = *mask;
  64747. mask += maskStride;
  64748. if (alpha != lastLevel)
  64749. {
  64750. tempLine[++destIndex] = (x << 8);
  64751. tempLine[++destIndex] = alpha;
  64752. lastLevel = alpha;
  64753. }
  64754. ++x;
  64755. }
  64756. if (lastLevel > 0)
  64757. {
  64758. tempLine[++destIndex] = (x << 8);
  64759. tempLine[++destIndex] = 0;
  64760. }
  64761. tempLine[0] = destIndex >> 1;
  64762. intersectWithEdgeTableLine (y, tempLine);
  64763. }
  64764. bool EdgeTable::isEmpty() throw()
  64765. {
  64766. if (needToCheckEmptinesss)
  64767. {
  64768. needToCheckEmptinesss = false;
  64769. int* t = table;
  64770. for (int i = bounds.getHeight(); --i >= 0;)
  64771. {
  64772. if (t[0] > 1)
  64773. return false;
  64774. t += lineStrideElements;
  64775. }
  64776. bounds.setHeight (0);
  64777. }
  64778. return bounds.getHeight() == 0;
  64779. }
  64780. END_JUCE_NAMESPACE
  64781. /*** End of inlined file: juce_EdgeTable.cpp ***/
  64782. /*** Start of inlined file: juce_FillType.cpp ***/
  64783. BEGIN_JUCE_NAMESPACE
  64784. FillType::FillType() throw()
  64785. : colour (0xff000000), image (0)
  64786. {
  64787. }
  64788. FillType::FillType (const Colour& colour_) throw()
  64789. : colour (colour_), image (0)
  64790. {
  64791. }
  64792. FillType::FillType (const ColourGradient& gradient_) throw()
  64793. : colour (0xff000000), gradient (new ColourGradient (gradient_)), image (0)
  64794. {
  64795. }
  64796. FillType::FillType (const Image& image_, const AffineTransform& transform_) throw()
  64797. : colour (0xff000000), image (&image_), transform (transform_)
  64798. {
  64799. }
  64800. FillType::FillType (const FillType& other) throw()
  64801. : colour (other.colour),
  64802. gradient (other.gradient != 0 ? new ColourGradient (*other.gradient) : 0),
  64803. image (other.image), transform (other.transform)
  64804. {
  64805. }
  64806. const FillType& FillType::operator= (const FillType& other) throw()
  64807. {
  64808. if (this != &other)
  64809. {
  64810. colour = other.colour;
  64811. gradient = (other.gradient != 0 ? new ColourGradient (*other.gradient) : 0);
  64812. image = other.image;
  64813. transform = other.transform;
  64814. }
  64815. return *this;
  64816. }
  64817. FillType::~FillType() throw()
  64818. {
  64819. }
  64820. void FillType::setColour (const Colour& newColour) throw()
  64821. {
  64822. gradient = 0;
  64823. image = 0;
  64824. colour = newColour;
  64825. }
  64826. void FillType::setGradient (const ColourGradient& newGradient) throw()
  64827. {
  64828. if (gradient != 0)
  64829. {
  64830. *gradient = newGradient;
  64831. }
  64832. else
  64833. {
  64834. image = 0;
  64835. gradient = new ColourGradient (newGradient);
  64836. colour = Colours::black;
  64837. }
  64838. }
  64839. void FillType::setTiledImage (const Image& image_, const AffineTransform& transform_) throw()
  64840. {
  64841. gradient = 0;
  64842. image = &image_;
  64843. transform = transform_;
  64844. colour = Colours::black;
  64845. }
  64846. void FillType::setOpacity (const float newOpacity) throw()
  64847. {
  64848. colour = colour.withAlpha (newOpacity);
  64849. }
  64850. END_JUCE_NAMESPACE
  64851. /*** End of inlined file: juce_FillType.cpp ***/
  64852. /*** Start of inlined file: juce_Graphics.cpp ***/
  64853. BEGIN_JUCE_NAMESPACE
  64854. static const Graphics::ResamplingQuality defaultQuality = Graphics::mediumResamplingQuality;
  64855. template <typename Type>
  64856. static bool areCoordsSensibleNumbers (Type x, Type y, Type w, Type h)
  64857. {
  64858. const int maxVal = 0x3fffffff;
  64859. return (int) x >= -maxVal && (int) x <= maxVal
  64860. && (int) y >= -maxVal && (int) y <= maxVal
  64861. && (int) w >= -maxVal && (int) w <= maxVal
  64862. && (int) h >= -maxVal && (int) h <= maxVal;
  64863. }
  64864. LowLevelGraphicsContext::LowLevelGraphicsContext()
  64865. {
  64866. }
  64867. LowLevelGraphicsContext::~LowLevelGraphicsContext()
  64868. {
  64869. }
  64870. Graphics::Graphics (Image& imageToDrawOnto) throw()
  64871. : context (imageToDrawOnto.createLowLevelContext()),
  64872. contextToDelete (context),
  64873. saveStatePending (false)
  64874. {
  64875. resetToDefaultState();
  64876. }
  64877. Graphics::Graphics (LowLevelGraphicsContext* const internalContext) throw()
  64878. : context (internalContext),
  64879. saveStatePending (false)
  64880. {
  64881. resetToDefaultState();
  64882. }
  64883. Graphics::~Graphics() throw()
  64884. {
  64885. }
  64886. void Graphics::resetToDefaultState() throw()
  64887. {
  64888. saveStateIfPending();
  64889. context->setFill (FillType());
  64890. context->setFont (Font());
  64891. context->setInterpolationQuality (defaultQuality);
  64892. }
  64893. bool Graphics::isVectorDevice() const throw()
  64894. {
  64895. return context->isVectorDevice();
  64896. }
  64897. bool Graphics::reduceClipRegion (const int x, const int y,
  64898. const int w, const int h) throw()
  64899. {
  64900. saveStateIfPending();
  64901. return context->clipToRectangle (Rectangle<int> (x, y, w, h));
  64902. }
  64903. bool Graphics::reduceClipRegion (const RectangleList& clipRegion) throw()
  64904. {
  64905. saveStateIfPending();
  64906. return context->clipToRectangleList (clipRegion);
  64907. }
  64908. bool Graphics::reduceClipRegion (const Path& path, const AffineTransform& transform) throw()
  64909. {
  64910. saveStateIfPending();
  64911. context->clipToPath (path, transform);
  64912. return ! context->isClipEmpty();
  64913. }
  64914. bool Graphics::reduceClipRegion (const Image& image, const Rectangle<int>& sourceClipRegion, const AffineTransform& transform) throw()
  64915. {
  64916. saveStateIfPending();
  64917. context->clipToImageAlpha (image, sourceClipRegion, transform);
  64918. return ! context->isClipEmpty();
  64919. }
  64920. void Graphics::excludeClipRegion (const int x, const int y,
  64921. const int w, const int h) throw()
  64922. {
  64923. saveStateIfPending();
  64924. context->excludeClipRectangle (Rectangle<int> (x, y, w, h));
  64925. }
  64926. bool Graphics::isClipEmpty() const throw()
  64927. {
  64928. return context->isClipEmpty();
  64929. }
  64930. const Rectangle<int> Graphics::getClipBounds() const throw()
  64931. {
  64932. return context->getClipBounds();
  64933. }
  64934. void Graphics::saveState() throw()
  64935. {
  64936. saveStateIfPending();
  64937. saveStatePending = true;
  64938. }
  64939. void Graphics::restoreState() throw()
  64940. {
  64941. if (saveStatePending)
  64942. saveStatePending = false;
  64943. else
  64944. context->restoreState();
  64945. }
  64946. void Graphics::saveStateIfPending() throw()
  64947. {
  64948. if (saveStatePending)
  64949. {
  64950. saveStatePending = false;
  64951. context->saveState();
  64952. }
  64953. }
  64954. void Graphics::setOrigin (const int newOriginX,
  64955. const int newOriginY) throw()
  64956. {
  64957. saveStateIfPending();
  64958. context->setOrigin (newOriginX, newOriginY);
  64959. }
  64960. bool Graphics::clipRegionIntersects (const int x, const int y,
  64961. const int w, const int h) const throw()
  64962. {
  64963. return context->clipRegionIntersects (Rectangle<int> (x, y, w, h));
  64964. }
  64965. void Graphics::setColour (const Colour& newColour) throw()
  64966. {
  64967. saveStateIfPending();
  64968. context->setFill (FillType (newColour));
  64969. }
  64970. void Graphics::setOpacity (const float newOpacity) throw()
  64971. {
  64972. saveStateIfPending();
  64973. context->setOpacity (newOpacity);
  64974. }
  64975. void Graphics::setGradientFill (const ColourGradient& gradient) throw()
  64976. {
  64977. saveStateIfPending();
  64978. context->setFill (FillType (gradient));
  64979. }
  64980. void Graphics::setTiledImageFill (const Image& imageToUse,
  64981. const int anchorX,
  64982. const int anchorY,
  64983. const float opacity) throw()
  64984. {
  64985. saveStateIfPending();
  64986. context->setFill (FillType (imageToUse, AffineTransform::translation ((float) anchorX, (float) anchorY)));
  64987. context->setOpacity (opacity);
  64988. }
  64989. void Graphics::setFillType (const FillType& newFill) throw()
  64990. {
  64991. saveStateIfPending();
  64992. context->setFill (newFill);
  64993. }
  64994. void Graphics::setFont (const Font& newFont) throw()
  64995. {
  64996. saveStateIfPending();
  64997. context->setFont (newFont);
  64998. }
  64999. void Graphics::setFont (const float newFontHeight,
  65000. const int newFontStyleFlags) throw()
  65001. {
  65002. saveStateIfPending();
  65003. Font f (context->getFont());
  65004. f.setSizeAndStyle (newFontHeight, newFontStyleFlags, 1.0f, 0);
  65005. context->setFont (f);
  65006. }
  65007. void Graphics::drawSingleLineText (const String& text,
  65008. const int startX,
  65009. const int baselineY) const throw()
  65010. {
  65011. if (text.isNotEmpty()
  65012. && startX < context->getClipBounds().getRight())
  65013. {
  65014. GlyphArrangement arr;
  65015. arr.addLineOfText (context->getFont(), text, (float) startX, (float) baselineY);
  65016. arr.draw (*this);
  65017. }
  65018. }
  65019. void Graphics::drawTextAsPath (const String& text,
  65020. const AffineTransform& transform) const throw()
  65021. {
  65022. if (text.isNotEmpty())
  65023. {
  65024. GlyphArrangement arr;
  65025. arr.addLineOfText (context->getFont(), text, 0.0f, 0.0f);
  65026. arr.draw (*this, transform);
  65027. }
  65028. }
  65029. void Graphics::drawMultiLineText (const String& text,
  65030. const int startX,
  65031. const int baselineY,
  65032. const int maximumLineWidth) const throw()
  65033. {
  65034. if (text.isNotEmpty()
  65035. && startX < context->getClipBounds().getRight())
  65036. {
  65037. GlyphArrangement arr;
  65038. arr.addJustifiedText (context->getFont(), text,
  65039. (float) startX, (float) baselineY, (float) maximumLineWidth,
  65040. Justification::left);
  65041. arr.draw (*this);
  65042. }
  65043. }
  65044. void Graphics::drawText (const String& text,
  65045. const int x,
  65046. const int y,
  65047. const int width,
  65048. const int height,
  65049. const Justification& justificationType,
  65050. const bool useEllipsesIfTooBig) const throw()
  65051. {
  65052. if (text.isNotEmpty() && context->clipRegionIntersects (Rectangle<int> (x, y, width, height)))
  65053. {
  65054. GlyphArrangement arr;
  65055. arr.addCurtailedLineOfText (context->getFont(), text,
  65056. 0.0f, 0.0f, (float)width,
  65057. useEllipsesIfTooBig);
  65058. arr.justifyGlyphs (0, arr.getNumGlyphs(),
  65059. (float) x, (float) y,
  65060. (float) width, (float) height,
  65061. justificationType);
  65062. arr.draw (*this);
  65063. }
  65064. }
  65065. void Graphics::drawFittedText (const String& text,
  65066. const int x,
  65067. const int y,
  65068. const int width,
  65069. const int height,
  65070. const Justification& justification,
  65071. const int maximumNumberOfLines,
  65072. const float minimumHorizontalScale) const throw()
  65073. {
  65074. if (text.isNotEmpty()
  65075. && width > 0 && height > 0
  65076. && context->clipRegionIntersects (Rectangle<int> (x, y, width, height)))
  65077. {
  65078. GlyphArrangement arr;
  65079. arr.addFittedText (context->getFont(), text,
  65080. (float) x, (float) y,
  65081. (float) width, (float) height,
  65082. justification,
  65083. maximumNumberOfLines,
  65084. minimumHorizontalScale);
  65085. arr.draw (*this);
  65086. }
  65087. }
  65088. void Graphics::fillRect (int x,
  65089. int y,
  65090. int width,
  65091. int height) const throw()
  65092. {
  65093. // passing in a silly number can cause maths problems in rendering!
  65094. jassert (areCoordsSensibleNumbers (x, y, width, height));
  65095. context->fillRect (Rectangle<int> (x, y, width, height), false);
  65096. }
  65097. void Graphics::fillRect (const Rectangle<int>& r) const throw()
  65098. {
  65099. context->fillRect (r, false);
  65100. }
  65101. void Graphics::fillRect (const float x,
  65102. const float y,
  65103. const float width,
  65104. const float height) const throw()
  65105. {
  65106. // passing in a silly number can cause maths problems in rendering!
  65107. jassert (areCoordsSensibleNumbers (x, y, width, height));
  65108. Path p;
  65109. p.addRectangle (x, y, width, height);
  65110. fillPath (p);
  65111. }
  65112. void Graphics::setPixel (int x, int y) const throw()
  65113. {
  65114. context->fillRect (Rectangle<int> (x, y, 1, 1), false);
  65115. }
  65116. void Graphics::fillAll() const throw()
  65117. {
  65118. fillRect (context->getClipBounds());
  65119. }
  65120. void Graphics::fillAll (const Colour& colourToUse) const throw()
  65121. {
  65122. if (! colourToUse.isTransparent())
  65123. {
  65124. const Rectangle<int> clip (context->getClipBounds());
  65125. context->saveState();
  65126. context->setFill (FillType (colourToUse));
  65127. context->fillRect (clip, false);
  65128. context->restoreState();
  65129. }
  65130. }
  65131. void Graphics::fillPath (const Path& path,
  65132. const AffineTransform& transform) const throw()
  65133. {
  65134. if ((! context->isClipEmpty()) && ! path.isEmpty())
  65135. context->fillPath (path, transform);
  65136. }
  65137. void Graphics::strokePath (const Path& path,
  65138. const PathStrokeType& strokeType,
  65139. const AffineTransform& transform) const throw()
  65140. {
  65141. Path stroke;
  65142. strokeType.createStrokedPath (stroke, path, transform);
  65143. fillPath (stroke);
  65144. }
  65145. void Graphics::drawRect (const int x,
  65146. const int y,
  65147. const int width,
  65148. const int height,
  65149. const int lineThickness) const throw()
  65150. {
  65151. // passing in a silly number can cause maths problems in rendering!
  65152. jassert (areCoordsSensibleNumbers (x, y, width, height));
  65153. context->fillRect (Rectangle<int> (x, y, width, lineThickness), false);
  65154. context->fillRect (Rectangle<int> (x, y + lineThickness, lineThickness, height - lineThickness * 2), false);
  65155. context->fillRect (Rectangle<int> (x + width - lineThickness, y + lineThickness, lineThickness, height - lineThickness * 2), false);
  65156. context->fillRect (Rectangle<int> (x, y + height - lineThickness, width, lineThickness), false);
  65157. }
  65158. void Graphics::drawRect (const float x,
  65159. const float y,
  65160. const float width,
  65161. const float height,
  65162. const float lineThickness) const throw()
  65163. {
  65164. // passing in a silly number can cause maths problems in rendering!
  65165. jassert (areCoordsSensibleNumbers (x, y, width, height));
  65166. Path p;
  65167. p.addRectangle (x, y, width, lineThickness);
  65168. p.addRectangle (x, y + lineThickness, lineThickness, height - lineThickness * 2.0f);
  65169. p.addRectangle (x + width - lineThickness, y + lineThickness, lineThickness, height - lineThickness * 2.0f);
  65170. p.addRectangle (x, y + height - lineThickness, width, lineThickness);
  65171. fillPath (p);
  65172. }
  65173. void Graphics::drawRect (const Rectangle<int>& r,
  65174. const int lineThickness) const throw()
  65175. {
  65176. drawRect (r.getX(), r.getY(),
  65177. r.getWidth(), r.getHeight(),
  65178. lineThickness);
  65179. }
  65180. void Graphics::drawBevel (const int x,
  65181. const int y,
  65182. const int width,
  65183. const int height,
  65184. const int bevelThickness,
  65185. const Colour& topLeftColour,
  65186. const Colour& bottomRightColour,
  65187. const bool useGradient,
  65188. const bool sharpEdgeOnOutside) const throw()
  65189. {
  65190. // passing in a silly number can cause maths problems in rendering!
  65191. jassert (areCoordsSensibleNumbers (x, y, width, height));
  65192. if (clipRegionIntersects (x, y, width, height))
  65193. {
  65194. context->saveState();
  65195. const float oldOpacity = 1.0f;//xxx state->colour.getFloatAlpha();
  65196. const float ramp = oldOpacity / bevelThickness;
  65197. for (int i = bevelThickness; --i >= 0;)
  65198. {
  65199. const float op = useGradient ? ramp * (sharpEdgeOnOutside ? bevelThickness - i : i)
  65200. : oldOpacity;
  65201. context->setFill (FillType (topLeftColour.withMultipliedAlpha (op)));
  65202. context->fillRect (Rectangle<int> (x + i, y + i, width - i * 2, 1), false);
  65203. context->setFill (FillType (topLeftColour.withMultipliedAlpha (op * 0.75f)));
  65204. context->fillRect (Rectangle<int> (x + i, y + i + 1, 1, height - i * 2 - 2), false);
  65205. context->setFill (FillType (bottomRightColour.withMultipliedAlpha (op)));
  65206. context->fillRect (Rectangle<int> (x + i, y + height - i - 1, width - i * 2, 1), false);
  65207. context->setFill (FillType (bottomRightColour.withMultipliedAlpha (op * 0.75f)));
  65208. context->fillRect (Rectangle<int> (x + width - i - 1, y + i + 1, 1, height - i * 2 - 2), false);
  65209. }
  65210. context->restoreState();
  65211. }
  65212. }
  65213. void Graphics::fillEllipse (const float x,
  65214. const float y,
  65215. const float width,
  65216. const float height) const throw()
  65217. {
  65218. // passing in a silly number can cause maths problems in rendering!
  65219. jassert (areCoordsSensibleNumbers (x, y, width, height));
  65220. Path p;
  65221. p.addEllipse (x, y, width, height);
  65222. fillPath (p);
  65223. }
  65224. void Graphics::drawEllipse (const float x,
  65225. const float y,
  65226. const float width,
  65227. const float height,
  65228. const float lineThickness) const throw()
  65229. {
  65230. // passing in a silly number can cause maths problems in rendering!
  65231. jassert (areCoordsSensibleNumbers (x, y, width, height));
  65232. Path p;
  65233. p.addEllipse (x, y, width, height);
  65234. strokePath (p, PathStrokeType (lineThickness));
  65235. }
  65236. void Graphics::fillRoundedRectangle (const float x,
  65237. const float y,
  65238. const float width,
  65239. const float height,
  65240. const float cornerSize) const throw()
  65241. {
  65242. // passing in a silly number can cause maths problems in rendering!
  65243. jassert (areCoordsSensibleNumbers (x, y, width, height));
  65244. Path p;
  65245. p.addRoundedRectangle (x, y, width, height, cornerSize);
  65246. fillPath (p);
  65247. }
  65248. void Graphics::fillRoundedRectangle (const Rectangle<int>& r,
  65249. const float cornerSize) const throw()
  65250. {
  65251. fillRoundedRectangle ((float) r.getX(),
  65252. (float) r.getY(),
  65253. (float) r.getWidth(),
  65254. (float) r.getHeight(),
  65255. cornerSize);
  65256. }
  65257. void Graphics::drawRoundedRectangle (const float x,
  65258. const float y,
  65259. const float width,
  65260. const float height,
  65261. const float cornerSize,
  65262. const float lineThickness) const throw()
  65263. {
  65264. // passing in a silly number can cause maths problems in rendering!
  65265. jassert (areCoordsSensibleNumbers (x, y, width, height));
  65266. Path p;
  65267. p.addRoundedRectangle (x, y, width, height, cornerSize);
  65268. strokePath (p, PathStrokeType (lineThickness));
  65269. }
  65270. void Graphics::drawRoundedRectangle (const Rectangle<int>& r,
  65271. const float cornerSize,
  65272. const float lineThickness) const throw()
  65273. {
  65274. drawRoundedRectangle ((float) r.getX(),
  65275. (float) r.getY(),
  65276. (float) r.getWidth(),
  65277. (float) r.getHeight(),
  65278. cornerSize, lineThickness);
  65279. }
  65280. void Graphics::drawArrow (const float startX,
  65281. const float startY,
  65282. const float endX,
  65283. const float endY,
  65284. const float lineThickness,
  65285. const float arrowheadWidth,
  65286. const float arrowheadLength) const throw()
  65287. {
  65288. Path p;
  65289. p.addArrow (startX, startY, endX, endY,
  65290. lineThickness, arrowheadWidth, arrowheadLength);
  65291. fillPath (p);
  65292. }
  65293. void Graphics::fillCheckerBoard (int x, int y,
  65294. int width, int height,
  65295. const int checkWidth,
  65296. const int checkHeight,
  65297. const Colour& colour1,
  65298. const Colour& colour2) const throw()
  65299. {
  65300. jassert (checkWidth > 0 && checkHeight > 0); // can't be zero or less!
  65301. if (checkWidth > 0 && checkHeight > 0)
  65302. {
  65303. context->saveState();
  65304. if (colour1 == colour2)
  65305. {
  65306. context->setFill (FillType (colour1));
  65307. context->fillRect (Rectangle<int> (x, y, width, height), false);
  65308. }
  65309. else
  65310. {
  65311. const Rectangle<int> clip (context->getClipBounds());
  65312. const int right = jmin (x + width, clip.getRight());
  65313. const int bottom = jmin (y + height, clip.getBottom());
  65314. int cy = 0;
  65315. while (y < bottom)
  65316. {
  65317. int cx = cy;
  65318. for (int xx = x; xx < right; xx += checkWidth)
  65319. {
  65320. context->setFill (FillType (((cx++ & 1) == 0) ? colour1 : colour2));
  65321. context->fillRect (Rectangle<int> (xx, y, jmin (checkWidth, right - xx), jmin (checkHeight, bottom - y)),
  65322. false);
  65323. }
  65324. ++cy;
  65325. y += checkHeight;
  65326. }
  65327. }
  65328. context->restoreState();
  65329. }
  65330. }
  65331. void Graphics::drawVerticalLine (const int x, float top, float bottom) const throw()
  65332. {
  65333. context->drawVerticalLine (x, top, bottom);
  65334. }
  65335. void Graphics::drawHorizontalLine (const int y, float left, float right) const throw()
  65336. {
  65337. context->drawHorizontalLine (y, left, right);
  65338. }
  65339. void Graphics::drawLine (float x1, float y1, float x2, float y2) const throw()
  65340. {
  65341. context->drawLine (x1, y1, x2, y2);
  65342. }
  65343. void Graphics::drawLine (const float startX,
  65344. const float startY,
  65345. const float endX,
  65346. const float endY,
  65347. const float lineThickness) const throw()
  65348. {
  65349. Path p;
  65350. p.addLineSegment (startX, startY, endX, endY, lineThickness);
  65351. fillPath (p);
  65352. }
  65353. void Graphics::drawLine (const Line& line) const throw()
  65354. {
  65355. drawLine (line.getStartX(), line.getStartY(), line.getEndX(), line.getEndY());
  65356. }
  65357. void Graphics::drawLine (const Line& line,
  65358. const float lineThickness) const throw()
  65359. {
  65360. drawLine (line.getStartX(), line.getStartY(), line.getEndX(), line.getEndY(), lineThickness);
  65361. }
  65362. void Graphics::drawDashedLine (const float startX,
  65363. const float startY,
  65364. const float endX,
  65365. const float endY,
  65366. const float* const dashLengths,
  65367. const int numDashLengths,
  65368. const float lineThickness) const throw()
  65369. {
  65370. const double dx = endX - startX;
  65371. const double dy = endY - startY;
  65372. const double totalLen = juce_hypot (dx, dy);
  65373. if (totalLen >= 0.5)
  65374. {
  65375. const double onePixAlpha = 1.0 / totalLen;
  65376. double alpha = 0.0;
  65377. float x = startX;
  65378. float y = startY;
  65379. int n = 0;
  65380. while (alpha < 1.0f)
  65381. {
  65382. alpha = jmin (1.0, alpha + dashLengths[n++] * onePixAlpha);
  65383. n = n % numDashLengths;
  65384. const float oldX = x;
  65385. const float oldY = y;
  65386. x = (float) (startX + dx * alpha);
  65387. y = (float) (startY + dy * alpha);
  65388. if ((n & 1) != 0)
  65389. {
  65390. if (lineThickness != 1.0f)
  65391. drawLine (oldX, oldY, x, y, lineThickness);
  65392. else
  65393. drawLine (oldX, oldY, x, y);
  65394. }
  65395. }
  65396. }
  65397. }
  65398. void Graphics::setImageResamplingQuality (const Graphics::ResamplingQuality newQuality) throw()
  65399. {
  65400. saveStateIfPending();
  65401. context->setInterpolationQuality (newQuality);
  65402. }
  65403. void Graphics::drawImageAt (const Image* const imageToDraw,
  65404. const int topLeftX,
  65405. const int topLeftY,
  65406. const bool fillAlphaChannelWithCurrentBrush) const throw()
  65407. {
  65408. if (imageToDraw != 0)
  65409. {
  65410. const int imageW = imageToDraw->getWidth();
  65411. const int imageH = imageToDraw->getHeight();
  65412. drawImage (imageToDraw,
  65413. topLeftX, topLeftY, imageW, imageH,
  65414. 0, 0, imageW, imageH,
  65415. fillAlphaChannelWithCurrentBrush);
  65416. }
  65417. }
  65418. void Graphics::drawImageWithin (const Image* const imageToDraw,
  65419. const int destX,
  65420. const int destY,
  65421. const int destW,
  65422. const int destH,
  65423. const RectanglePlacement& placementWithinTarget,
  65424. const bool fillAlphaChannelWithCurrentBrush) const throw()
  65425. {
  65426. // passing in a silly number can cause maths problems in rendering!
  65427. jassert (areCoordsSensibleNumbers (destX, destY, destW, destH));
  65428. if (imageToDraw != 0)
  65429. {
  65430. const int imageW = imageToDraw->getWidth();
  65431. const int imageH = imageToDraw->getHeight();
  65432. if (imageW > 0 && imageH > 0)
  65433. {
  65434. double newX = 0.0, newY = 0.0;
  65435. double newW = imageW;
  65436. double newH = imageH;
  65437. placementWithinTarget.applyTo (newX, newY, newW, newH,
  65438. destX, destY, destW, destH);
  65439. if (newW > 0 && newH > 0)
  65440. {
  65441. drawImage (imageToDraw,
  65442. roundToInt (newX), roundToInt (newY),
  65443. roundToInt (newW), roundToInt (newH),
  65444. 0, 0, imageW, imageH,
  65445. fillAlphaChannelWithCurrentBrush);
  65446. }
  65447. }
  65448. }
  65449. }
  65450. void Graphics::drawImage (const Image* const imageToDraw,
  65451. int dx, int dy, int dw, int dh,
  65452. int sx, int sy, int sw, int sh,
  65453. const bool fillAlphaChannelWithCurrentBrush) const throw()
  65454. {
  65455. // passing in a silly number can cause maths problems in rendering!
  65456. jassert (areCoordsSensibleNumbers (dx, dy, dw, dh));
  65457. jassert (areCoordsSensibleNumbers (sx, sy, sw, sh));
  65458. if (context->clipRegionIntersects (Rectangle<int> (dx, dy, dw, dh)))
  65459. {
  65460. drawImageTransformed (imageToDraw, Rectangle<int> (sx, sy, sw, sh),
  65461. AffineTransform::scale (dw / (float) sw, dh / (float) sh)
  65462. .translated ((float) dx, (float) dy),
  65463. fillAlphaChannelWithCurrentBrush);
  65464. }
  65465. }
  65466. void Graphics::drawImageTransformed (const Image* const imageToDraw,
  65467. const Rectangle<int>& imageSubRegion,
  65468. const AffineTransform& transform,
  65469. const bool fillAlphaChannelWithCurrentBrush) const throw()
  65470. {
  65471. if (imageToDraw != 0 && ! context->isClipEmpty())
  65472. {
  65473. const Rectangle<int> srcClip (imageSubRegion.getIntersection (imageToDraw->getBounds()));
  65474. if (fillAlphaChannelWithCurrentBrush)
  65475. {
  65476. context->saveState();
  65477. context->clipToImageAlpha (*imageToDraw, srcClip, transform);
  65478. fillAll();
  65479. context->restoreState();
  65480. }
  65481. else
  65482. {
  65483. context->drawImage (*imageToDraw, srcClip, transform, false);
  65484. }
  65485. }
  65486. }
  65487. END_JUCE_NAMESPACE
  65488. /*** End of inlined file: juce_Graphics.cpp ***/
  65489. /*** Start of inlined file: juce_Justification.cpp ***/
  65490. BEGIN_JUCE_NAMESPACE
  65491. Justification::Justification (const Justification& other) throw()
  65492. : flags (other.flags)
  65493. {
  65494. }
  65495. const Justification& Justification::operator= (const Justification& other) throw()
  65496. {
  65497. flags = other.flags;
  65498. return *this;
  65499. }
  65500. int Justification::getOnlyVerticalFlags() const throw()
  65501. {
  65502. return flags & (top | bottom | verticallyCentred);
  65503. }
  65504. int Justification::getOnlyHorizontalFlags() const throw()
  65505. {
  65506. return flags & (left | right | horizontallyCentred | horizontallyJustified);
  65507. }
  65508. void Justification::applyToRectangle (int& x, int& y,
  65509. const int w, const int h,
  65510. const int spaceX, const int spaceY,
  65511. const int spaceW, const int spaceH) const throw()
  65512. {
  65513. if ((flags & horizontallyCentred) != 0)
  65514. {
  65515. x = spaceX + ((spaceW - w) >> 1);
  65516. }
  65517. else if ((flags & right) != 0)
  65518. {
  65519. x = spaceX + spaceW - w;
  65520. }
  65521. else
  65522. {
  65523. x = spaceX;
  65524. }
  65525. if ((flags & verticallyCentred) != 0)
  65526. {
  65527. y = spaceY + ((spaceH - h) >> 1);
  65528. }
  65529. else if ((flags & bottom) != 0)
  65530. {
  65531. y = spaceY + spaceH - h;
  65532. }
  65533. else
  65534. {
  65535. y = spaceY;
  65536. }
  65537. }
  65538. END_JUCE_NAMESPACE
  65539. /*** End of inlined file: juce_Justification.cpp ***/
  65540. /*** Start of inlined file: juce_LowLevelGraphicsPostScriptRenderer.cpp ***/
  65541. BEGIN_JUCE_NAMESPACE
  65542. // this will throw an assertion if you try to draw something that's not
  65543. // possible in postscript
  65544. #define WARN_ABOUT_NON_POSTSCRIPT_OPERATIONS 0
  65545. #if defined (JUCE_DEBUG) && WARN_ABOUT_NON_POSTSCRIPT_OPERATIONS
  65546. #define notPossibleInPostscriptAssert jassertfalse
  65547. #else
  65548. #define notPossibleInPostscriptAssert
  65549. #endif
  65550. LowLevelGraphicsPostScriptRenderer::LowLevelGraphicsPostScriptRenderer (OutputStream& resultingPostScript,
  65551. const String& documentTitle,
  65552. const int totalWidth_,
  65553. const int totalHeight_)
  65554. : out (resultingPostScript),
  65555. totalWidth (totalWidth_),
  65556. totalHeight (totalHeight_),
  65557. needToClip (true)
  65558. {
  65559. stateStack.add (new SavedState());
  65560. stateStack.getLast()->clip = Rectangle<int> (0, 0, totalWidth_, totalHeight_);
  65561. const float scale = jmin ((520.0f / totalWidth_), (750.0f / totalHeight));
  65562. out << "%!PS-Adobe-3.0 EPSF-3.0"
  65563. "\n%%BoundingBox: 0 0 600 824"
  65564. "\n%%Pages: 0"
  65565. "\n%%Creator: Raw Material Software JUCE"
  65566. "\n%%Title: " << documentTitle <<
  65567. "\n%%CreationDate: none"
  65568. "\n%%LanguageLevel: 2"
  65569. "\n%%EndComments"
  65570. "\n%%BeginProlog"
  65571. "\n%%BeginResource: JRes"
  65572. "\n/bd {bind def} bind def"
  65573. "\n/c {setrgbcolor} bd"
  65574. "\n/m {moveto} bd"
  65575. "\n/l {lineto} bd"
  65576. "\n/rl {rlineto} bd"
  65577. "\n/ct {curveto} bd"
  65578. "\n/cp {closepath} bd"
  65579. "\n/pr {3 index 3 index moveto 1 index 0 rlineto 0 1 index rlineto pop neg 0 rlineto pop pop closepath} bd"
  65580. "\n/doclip {initclip newpath} bd"
  65581. "\n/endclip {clip newpath} bd"
  65582. "\n%%EndResource"
  65583. "\n%%EndProlog"
  65584. "\n%%BeginSetup"
  65585. "\n%%EndSetup"
  65586. "\n%%Page: 1 1"
  65587. "\n%%BeginPageSetup"
  65588. "\n%%EndPageSetup\n\n"
  65589. << "40 800 translate\n"
  65590. << scale << ' ' << scale << " scale\n\n";
  65591. }
  65592. LowLevelGraphicsPostScriptRenderer::~LowLevelGraphicsPostScriptRenderer()
  65593. {
  65594. }
  65595. bool LowLevelGraphicsPostScriptRenderer::isVectorDevice() const
  65596. {
  65597. return true;
  65598. }
  65599. void LowLevelGraphicsPostScriptRenderer::setOrigin (int x, int y)
  65600. {
  65601. if (x != 0 || y != 0)
  65602. {
  65603. stateStack.getLast()->xOffset += x;
  65604. stateStack.getLast()->yOffset += y;
  65605. needToClip = true;
  65606. }
  65607. }
  65608. bool LowLevelGraphicsPostScriptRenderer::clipToRectangle (const Rectangle<int>& r)
  65609. {
  65610. needToClip = true;
  65611. return stateStack.getLast()->clip.clipTo (r.translated (stateStack.getLast()->xOffset, stateStack.getLast()->yOffset));
  65612. }
  65613. bool LowLevelGraphicsPostScriptRenderer::clipToRectangleList (const RectangleList& clipRegion)
  65614. {
  65615. needToClip = true;
  65616. return stateStack.getLast()->clip.clipTo (clipRegion);
  65617. }
  65618. void LowLevelGraphicsPostScriptRenderer::excludeClipRectangle (const Rectangle<int>& r)
  65619. {
  65620. needToClip = true;
  65621. stateStack.getLast()->clip.subtract (r.translated (stateStack.getLast()->xOffset, stateStack.getLast()->yOffset));
  65622. }
  65623. void LowLevelGraphicsPostScriptRenderer::clipToPath (const Path& path, const AffineTransform& transform)
  65624. {
  65625. writeClip();
  65626. Path p (path);
  65627. p.applyTransform (transform.translated ((float) stateStack.getLast()->xOffset, (float) stateStack.getLast()->yOffset));
  65628. writePath (p);
  65629. out << "clip\n";
  65630. }
  65631. void LowLevelGraphicsPostScriptRenderer::clipToImageAlpha (const Image& /*sourceImage*/, const Rectangle<int>& /*srcClip*/, const AffineTransform& /*transform*/)
  65632. {
  65633. needToClip = true;
  65634. jassertfalse // xxx
  65635. }
  65636. bool LowLevelGraphicsPostScriptRenderer::clipRegionIntersects (const Rectangle<int>& r)
  65637. {
  65638. return stateStack.getLast()->clip.intersectsRectangle (r.translated (stateStack.getLast()->xOffset, stateStack.getLast()->yOffset));
  65639. }
  65640. const Rectangle<int> LowLevelGraphicsPostScriptRenderer::getClipBounds() const
  65641. {
  65642. return stateStack.getLast()->clip.getBounds().translated (-stateStack.getLast()->xOffset,
  65643. -stateStack.getLast()->yOffset);
  65644. }
  65645. bool LowLevelGraphicsPostScriptRenderer::isClipEmpty() const
  65646. {
  65647. return stateStack.getLast()->clip.isEmpty();
  65648. }
  65649. LowLevelGraphicsPostScriptRenderer::SavedState::SavedState()
  65650. : xOffset (0),
  65651. yOffset (0)
  65652. {
  65653. }
  65654. LowLevelGraphicsPostScriptRenderer::SavedState::~SavedState()
  65655. {
  65656. }
  65657. void LowLevelGraphicsPostScriptRenderer::saveState()
  65658. {
  65659. stateStack.add (new SavedState (*stateStack.getLast()));
  65660. }
  65661. void LowLevelGraphicsPostScriptRenderer::restoreState()
  65662. {
  65663. jassert (stateStack.size() > 0);
  65664. if (stateStack.size() > 0)
  65665. stateStack.removeLast();
  65666. }
  65667. void LowLevelGraphicsPostScriptRenderer::writeClip()
  65668. {
  65669. if (needToClip)
  65670. {
  65671. needToClip = false;
  65672. out << "doclip ";
  65673. int itemsOnLine = 0;
  65674. for (RectangleList::Iterator i (stateStack.getLast()->clip); i.next();)
  65675. {
  65676. if (++itemsOnLine == 6)
  65677. {
  65678. itemsOnLine = 0;
  65679. out << '\n';
  65680. }
  65681. const Rectangle<int>& r = *i.getRectangle();
  65682. out << r.getX() << ' ' << -r.getY() << ' '
  65683. << r.getWidth() << ' ' << -r.getHeight() << " pr ";
  65684. }
  65685. out << "endclip\n";
  65686. }
  65687. }
  65688. void LowLevelGraphicsPostScriptRenderer::writeColour (const Colour& colour)
  65689. {
  65690. Colour c (Colours::white.overlaidWith (colour));
  65691. if (lastColour != c)
  65692. {
  65693. lastColour = c;
  65694. out << String (c.getFloatRed(), 3) << ' '
  65695. << String (c.getFloatGreen(), 3) << ' '
  65696. << String (c.getFloatBlue(), 3) << " c\n";
  65697. }
  65698. }
  65699. void LowLevelGraphicsPostScriptRenderer::writeXY (const float x, const float y) const
  65700. {
  65701. out << String (x, 2) << ' '
  65702. << String (-y, 2) << ' ';
  65703. }
  65704. void LowLevelGraphicsPostScriptRenderer::writePath (const Path& path) const
  65705. {
  65706. out << "newpath ";
  65707. float lastX = 0.0f;
  65708. float lastY = 0.0f;
  65709. int itemsOnLine = 0;
  65710. Path::Iterator i (path);
  65711. while (i.next())
  65712. {
  65713. if (++itemsOnLine == 4)
  65714. {
  65715. itemsOnLine = 0;
  65716. out << '\n';
  65717. }
  65718. switch (i.elementType)
  65719. {
  65720. case Path::Iterator::startNewSubPath:
  65721. writeXY (i.x1, i.y1);
  65722. lastX = i.x1;
  65723. lastY = i.y1;
  65724. out << "m ";
  65725. break;
  65726. case Path::Iterator::lineTo:
  65727. writeXY (i.x1, i.y1);
  65728. lastX = i.x1;
  65729. lastY = i.y1;
  65730. out << "l ";
  65731. break;
  65732. case Path::Iterator::quadraticTo:
  65733. {
  65734. const float cp1x = lastX + (i.x1 - lastX) * 2.0f / 3.0f;
  65735. const float cp1y = lastY + (i.y1 - lastY) * 2.0f / 3.0f;
  65736. const float cp2x = cp1x + (i.x2 - lastX) / 3.0f;
  65737. const float cp2y = cp1y + (i.y2 - lastY) / 3.0f;
  65738. writeXY (cp1x, cp1y);
  65739. writeXY (cp2x, cp2y);
  65740. writeXY (i.x2, i.y2);
  65741. out << "ct ";
  65742. lastX = i.x2;
  65743. lastY = i.y2;
  65744. }
  65745. break;
  65746. case Path::Iterator::cubicTo:
  65747. writeXY (i.x1, i.y1);
  65748. writeXY (i.x2, i.y2);
  65749. writeXY (i.x3, i.y3);
  65750. out << "ct ";
  65751. lastX = i.x3;
  65752. lastY = i.y3;
  65753. break;
  65754. case Path::Iterator::closePath:
  65755. out << "cp ";
  65756. break;
  65757. default:
  65758. jassertfalse
  65759. break;
  65760. }
  65761. }
  65762. out << '\n';
  65763. }
  65764. void LowLevelGraphicsPostScriptRenderer::writeTransform (const AffineTransform& trans) const
  65765. {
  65766. out << "[ "
  65767. << trans.mat00 << ' '
  65768. << trans.mat10 << ' '
  65769. << trans.mat01 << ' '
  65770. << trans.mat11 << ' '
  65771. << trans.mat02 << ' '
  65772. << trans.mat12 << " ] concat ";
  65773. }
  65774. void LowLevelGraphicsPostScriptRenderer::setFill (const FillType& fillType)
  65775. {
  65776. stateStack.getLast()->fillType = fillType;
  65777. }
  65778. void LowLevelGraphicsPostScriptRenderer::setOpacity (float /*opacity*/)
  65779. {
  65780. }
  65781. void LowLevelGraphicsPostScriptRenderer::setInterpolationQuality (Graphics::ResamplingQuality /*quality*/)
  65782. {
  65783. }
  65784. void LowLevelGraphicsPostScriptRenderer::fillRect (const Rectangle<int>& r, const bool /*replaceExistingContents*/)
  65785. {
  65786. if (stateStack.getLast()->fillType.isColour())
  65787. {
  65788. writeClip();
  65789. writeColour (stateStack.getLast()->fillType.colour);
  65790. Rectangle<int> r2 (r.translated (stateStack.getLast()->xOffset, stateStack.getLast()->yOffset));
  65791. out << r2.getX() << ' ' << -r2.getBottom() << ' ' << r2.getWidth() << ' ' << r2.getHeight() << " rectfill\n";
  65792. }
  65793. else
  65794. {
  65795. Path p;
  65796. p.addRectangle (r);
  65797. fillPath (p, AffineTransform::identity);
  65798. }
  65799. }
  65800. void LowLevelGraphicsPostScriptRenderer::fillPath (const Path& path, const AffineTransform& t)
  65801. {
  65802. if (stateStack.getLast()->fillType.isColour())
  65803. {
  65804. writeClip();
  65805. Path p (path);
  65806. p.applyTransform (t.translated ((float) stateStack.getLast()->xOffset,
  65807. (float) stateStack.getLast()->yOffset));
  65808. writePath (p);
  65809. writeColour (stateStack.getLast()->fillType.colour);
  65810. out << "fill\n";
  65811. }
  65812. else if (stateStack.getLast()->fillType.isGradient())
  65813. {
  65814. // this doesn't work correctly yet - it could be improved to handle solid gradients, but
  65815. // postscript can't do semi-transparent ones.
  65816. notPossibleInPostscriptAssert // you can disable this warning by setting the WARN_ABOUT_NON_POSTSCRIPT_OPERATIONS flag at the top of this file
  65817. writeClip();
  65818. out << "gsave ";
  65819. {
  65820. Path p (path);
  65821. p.applyTransform (t.translated ((float) stateStack.getLast()->xOffset, (float) stateStack.getLast()->yOffset));
  65822. writePath (p);
  65823. out << "clip\n";
  65824. }
  65825. const Rectangle<int> bounds (stateStack.getLast()->clip.getBounds());
  65826. // ideally this would draw lots of lines or ellipses to approximate the gradient, but for the
  65827. // time-being, this just fills it with the average colour..
  65828. writeColour (stateStack.getLast()->fillType.gradient->getColourAtPosition (0.5f));
  65829. out << bounds.getX() << ' ' << -bounds.getBottom() << ' ' << bounds.getWidth() << ' ' << bounds.getHeight() << " rectfill\n";
  65830. out << "grestore\n";
  65831. }
  65832. }
  65833. void LowLevelGraphicsPostScriptRenderer::writeImage (const Image& im,
  65834. const int sx, const int sy,
  65835. const int maxW, const int maxH) const
  65836. {
  65837. out << "{<\n";
  65838. const int w = jmin (maxW, im.getWidth());
  65839. const int h = jmin (maxH, im.getHeight());
  65840. int charsOnLine = 0;
  65841. const Image::BitmapData srcData (im, 0, 0, w, h);
  65842. Colour pixel;
  65843. for (int y = h; --y >= 0;)
  65844. {
  65845. for (int x = 0; x < w; ++x)
  65846. {
  65847. const uint8* pixelData = srcData.getPixelPointer (x, y);
  65848. if (x >= sx && y >= sy)
  65849. {
  65850. if (im.isARGB())
  65851. {
  65852. PixelARGB p (*(const PixelARGB*) pixelData);
  65853. p.unpremultiply();
  65854. pixel = Colours::white.overlaidWith (Colour (p.getARGB()));
  65855. }
  65856. else if (im.isRGB())
  65857. {
  65858. pixel = Colour (((const PixelRGB*) pixelData)->getARGB());
  65859. }
  65860. else
  65861. {
  65862. pixel = Colour ((uint8) 0, (uint8) 0, (uint8) 0, *pixelData);
  65863. }
  65864. }
  65865. else
  65866. {
  65867. pixel = Colours::transparentWhite;
  65868. }
  65869. const uint8 pixelValues[3] = { pixel.getRed(), pixel.getGreen(), pixel.getBlue() };
  65870. out << String::toHexString (pixelValues, 3, 0);
  65871. charsOnLine += 3;
  65872. if (charsOnLine > 100)
  65873. {
  65874. out << '\n';
  65875. charsOnLine = 0;
  65876. }
  65877. }
  65878. }
  65879. out << "\n>}\n";
  65880. }
  65881. void LowLevelGraphicsPostScriptRenderer::drawImage (const Image& sourceImage, const Rectangle<int>& srcClip,
  65882. const AffineTransform& transform, const bool /*fillEntireClipAsTiles*/)
  65883. {
  65884. const int w = jmin (sourceImage.getWidth(), srcClip.getRight());
  65885. const int h = jmin (sourceImage.getHeight(), srcClip.getBottom());
  65886. writeClip();
  65887. out << "gsave ";
  65888. writeTransform (transform.translated ((float) stateStack.getLast()->xOffset, (float) stateStack.getLast()->yOffset)
  65889. .scaled (1.0f, -1.0f));
  65890. RectangleList imageClip;
  65891. sourceImage.createSolidAreaMask (imageClip, 0.5f);
  65892. imageClip.clipTo (srcClip);
  65893. out << "newpath ";
  65894. int itemsOnLine = 0;
  65895. for (RectangleList::Iterator i (imageClip); i.next();)
  65896. {
  65897. if (++itemsOnLine == 6)
  65898. {
  65899. out << '\n';
  65900. itemsOnLine = 0;
  65901. }
  65902. const Rectangle<int>& r = *i.getRectangle();
  65903. out << r.getX() << ' ' << r.getY() << ' ' << r.getWidth() << ' ' << r.getHeight() << " pr ";
  65904. }
  65905. out << " clip newpath\n";
  65906. out << w << ' ' << h << " scale\n";
  65907. out << w << ' ' << h << " 8 [" << w << " 0 0 -" << h << ' ' << (int) 0 << ' ' << h << " ]\n";
  65908. writeImage (sourceImage, srcClip.getX(), srcClip.getY(), srcClip.getWidth(), srcClip.getHeight());
  65909. out << "false 3 colorimage grestore\n";
  65910. needToClip = true;
  65911. }
  65912. void LowLevelGraphicsPostScriptRenderer::drawLine (double x1, double y1, double x2, double y2)
  65913. {
  65914. Path p;
  65915. p.addLineSegment ((float) x1, (float) y1, (float) x2, (float) y2, 1.0f);
  65916. fillPath (p, AffineTransform::identity);
  65917. }
  65918. void LowLevelGraphicsPostScriptRenderer::drawVerticalLine (const int x, double top, double bottom)
  65919. {
  65920. drawLine (x, top, x, bottom);
  65921. }
  65922. void LowLevelGraphicsPostScriptRenderer::drawHorizontalLine (const int y, double left, double right)
  65923. {
  65924. drawLine (left, y, right, y);
  65925. }
  65926. void LowLevelGraphicsPostScriptRenderer::setFont (const Font& newFont)
  65927. {
  65928. stateStack.getLast()->font = newFont;
  65929. }
  65930. const Font LowLevelGraphicsPostScriptRenderer::getFont()
  65931. {
  65932. return stateStack.getLast()->font;
  65933. }
  65934. void LowLevelGraphicsPostScriptRenderer::drawGlyph (int glyphNumber, const AffineTransform& transform)
  65935. {
  65936. Path p;
  65937. Font& font = stateStack.getLast()->font;
  65938. font.getTypeface()->getOutlineForGlyph (glyphNumber, p);
  65939. fillPath (p, AffineTransform::scale (font.getHeight() * font.getHorizontalScale(), font.getHeight()).followedBy (transform));
  65940. }
  65941. END_JUCE_NAMESPACE
  65942. /*** End of inlined file: juce_LowLevelGraphicsPostScriptRenderer.cpp ***/
  65943. /*** Start of inlined file: juce_LowLevelGraphicsSoftwareRenderer.cpp ***/
  65944. BEGIN_JUCE_NAMESPACE
  65945. #if (JUCE_WINDOWS || JUCE_LINUX) && ! JUCE_64BIT
  65946. #define JUCE_USE_SSE_INSTRUCTIONS 1
  65947. #endif
  65948. #if JUCE_MSVC && JUCE_DEBUG
  65949. #pragma warning (disable: 4714) // warning about forcedinline methods not being inlined
  65950. #endif
  65951. #if JUCE_MSVC
  65952. #pragma warning (push)
  65953. #pragma warning (disable: 4127) // "expression is constant" warning
  65954. #endif
  65955. template <class PixelType, bool replaceExisting = false>
  65956. class SolidColourEdgeTableRenderer
  65957. {
  65958. public:
  65959. SolidColourEdgeTableRenderer (const Image::BitmapData& data_, const PixelARGB& colour) throw()
  65960. : data (data_),
  65961. sourceColour (colour)
  65962. {
  65963. if (sizeof (PixelType) == 3)
  65964. {
  65965. areRGBComponentsEqual = sourceColour.getRed() == sourceColour.getGreen()
  65966. && sourceColour.getGreen() == sourceColour.getBlue();
  65967. filler[0].set (sourceColour);
  65968. filler[1].set (sourceColour);
  65969. filler[2].set (sourceColour);
  65970. filler[3].set (sourceColour);
  65971. }
  65972. }
  65973. forcedinline void setEdgeTableYPos (const int y) throw()
  65974. {
  65975. linePixels = (PixelType*) data.getLinePointer (y);
  65976. }
  65977. forcedinline void handleEdgeTablePixel (const int x, const int alphaLevel) const throw()
  65978. {
  65979. if (replaceExisting)
  65980. linePixels[x].set (sourceColour);
  65981. else
  65982. linePixels[x].blend (sourceColour, alphaLevel);
  65983. }
  65984. forcedinline void handleEdgeTableLine (const int x, int width, const int alphaLevel) const throw()
  65985. {
  65986. PixelARGB p (sourceColour);
  65987. p.multiplyAlpha (alphaLevel);
  65988. PixelType* dest = linePixels + x;
  65989. if (replaceExisting || p.getAlpha() >= 0xff)
  65990. replaceLine (dest, p, width);
  65991. else
  65992. blendLine (dest, p, width);
  65993. }
  65994. private:
  65995. const Image::BitmapData& data;
  65996. PixelType* linePixels;
  65997. PixelARGB sourceColour;
  65998. PixelRGB filler [4];
  65999. bool areRGBComponentsEqual;
  66000. inline void blendLine (PixelType* dest, const PixelARGB& colour, int width) const
  66001. {
  66002. do
  66003. {
  66004. dest->blend (colour);
  66005. ++dest;
  66006. } while (--width > 0);
  66007. }
  66008. forcedinline void replaceLine (PixelRGB* dest, const PixelARGB& colour, int width) const throw()
  66009. {
  66010. if (areRGBComponentsEqual) // if all the component values are the same, we can cheat..
  66011. {
  66012. memset (dest, colour.getRed(), width * 3);
  66013. }
  66014. else
  66015. {
  66016. if (width >> 5)
  66017. {
  66018. const int* const intFiller = (const int*) filler;
  66019. while (width > 8 && (((pointer_sized_int) dest) & 7) != 0)
  66020. {
  66021. dest->set (colour);
  66022. ++dest;
  66023. --width;
  66024. }
  66025. while (width > 4)
  66026. {
  66027. ((int*) dest) [0] = intFiller[0];
  66028. ((int*) dest) [1] = intFiller[1];
  66029. ((int*) dest) [2] = intFiller[2];
  66030. dest = (PixelRGB*) (((uint8*) dest) + 12);
  66031. width -= 4;
  66032. }
  66033. }
  66034. while (--width >= 0)
  66035. {
  66036. dest->set (colour);
  66037. ++dest;
  66038. }
  66039. }
  66040. }
  66041. forcedinline void replaceLine (PixelAlpha* dest, const PixelARGB& colour, int width) const throw()
  66042. {
  66043. memset (dest, colour.getAlpha(), width);
  66044. }
  66045. forcedinline void replaceLine (PixelARGB* dest, const PixelARGB& colour, int width) const throw()
  66046. {
  66047. do
  66048. {
  66049. dest->set (colour);
  66050. ++dest;
  66051. } while (--width > 0);
  66052. }
  66053. SolidColourEdgeTableRenderer (const SolidColourEdgeTableRenderer&);
  66054. const SolidColourEdgeTableRenderer& operator= (const SolidColourEdgeTableRenderer&);
  66055. };
  66056. class LinearGradientPixelGenerator
  66057. {
  66058. public:
  66059. LinearGradientPixelGenerator (const ColourGradient& gradient, const AffineTransform& transform, const PixelARGB* const lookupTable_, const int numEntries_)
  66060. : lookupTable (lookupTable_), numEntries (numEntries_)
  66061. {
  66062. jassert (numEntries_ >= 0);
  66063. float x1 = gradient.x1;
  66064. float y1 = gradient.y1;
  66065. float x2 = gradient.x2;
  66066. float y2 = gradient.y2;
  66067. if (! transform.isIdentity())
  66068. {
  66069. const Line l (x2, y2, x1, y1);
  66070. const Point<float> p3 = l.getPointAlongLine (0.0f, 100.0f);
  66071. float x3 = p3.getX();
  66072. float y3 = p3.getY();
  66073. transform.transformPoint (x1, y1);
  66074. transform.transformPoint (x2, y2);
  66075. transform.transformPoint (x3, y3);
  66076. const Line l2 (x2, y2, x3, y3);
  66077. const float prop = l2.findNearestPointTo (x1, y1);
  66078. const Point<float> newP2 (l2.getPointAlongLineProportionally (prop));
  66079. x2 = newP2.getX();
  66080. y2 = newP2.getY();
  66081. }
  66082. vertical = fabs (x1 - x2) < 0.001f;
  66083. horizontal = fabs (y1 - y2) < 0.001f;
  66084. if (vertical)
  66085. {
  66086. scale = roundToInt ((numEntries << (int) numScaleBits) / (double) (y2 - y1));
  66087. start = roundToInt (y1 * scale);
  66088. }
  66089. else if (horizontal)
  66090. {
  66091. scale = roundToInt ((numEntries << (int) numScaleBits) / (double) (x2 - x1));
  66092. start = roundToInt (x1 * scale);
  66093. }
  66094. else
  66095. {
  66096. grad = (y2 - y1) / (double) (x1 - x2);
  66097. yTerm = y1 - x1 / grad;
  66098. scale = roundToInt ((numEntries << (int) numScaleBits) / (yTerm * grad - (y2 * grad - x2)));
  66099. grad *= scale;
  66100. }
  66101. }
  66102. forcedinline void setY (const int y) throw()
  66103. {
  66104. if (vertical)
  66105. linePix = lookupTable [jlimit (0, numEntries, (y * scale - start) >> (int) numScaleBits)];
  66106. else if (! horizontal)
  66107. start = roundToInt ((y - yTerm) * grad);
  66108. }
  66109. forcedinline const PixelARGB getPixel (const int x) const throw()
  66110. {
  66111. return vertical ? linePix
  66112. : lookupTable [jlimit (0, numEntries, (x * scale - start) >> (int) numScaleBits)];
  66113. }
  66114. private:
  66115. const PixelARGB* const lookupTable;
  66116. const int numEntries;
  66117. PixelARGB linePix;
  66118. int start, scale;
  66119. double grad, yTerm;
  66120. bool vertical, horizontal;
  66121. enum { numScaleBits = 12 };
  66122. LinearGradientPixelGenerator (const LinearGradientPixelGenerator&);
  66123. const LinearGradientPixelGenerator& operator= (const LinearGradientPixelGenerator&);
  66124. };
  66125. class RadialGradientPixelGenerator
  66126. {
  66127. public:
  66128. RadialGradientPixelGenerator (const ColourGradient& gradient, const AffineTransform&,
  66129. const PixelARGB* const lookupTable_, const int numEntries_) throw()
  66130. : lookupTable (lookupTable_),
  66131. numEntries (numEntries_),
  66132. gx1 (gradient.x1),
  66133. gy1 (gradient.y1)
  66134. {
  66135. jassert (numEntries_ >= 0);
  66136. const float gdx = gradient.x1 - gradient.x2;
  66137. const float gdy = gradient.y1 - gradient.y2;
  66138. maxDist = gdx * gdx + gdy * gdy;
  66139. invScale = numEntries / sqrt (maxDist);
  66140. jassert (roundToInt (sqrt (maxDist) * invScale) <= numEntries);
  66141. }
  66142. forcedinline void setY (const int y) throw()
  66143. {
  66144. dy = y - gy1;
  66145. dy *= dy;
  66146. }
  66147. forcedinline const PixelARGB getPixel (const int px) const throw()
  66148. {
  66149. double x = px - gx1;
  66150. x *= x;
  66151. x += dy;
  66152. return lookupTable [x >= maxDist ? numEntries : roundToInt (sqrt (x) * invScale)];
  66153. }
  66154. protected:
  66155. const PixelARGB* const lookupTable;
  66156. const int numEntries;
  66157. const double gx1, gy1;
  66158. double maxDist, invScale, dy;
  66159. RadialGradientPixelGenerator (const RadialGradientPixelGenerator&);
  66160. const RadialGradientPixelGenerator& operator= (const RadialGradientPixelGenerator&);
  66161. };
  66162. class TransformedRadialGradientPixelGenerator : public RadialGradientPixelGenerator
  66163. {
  66164. public:
  66165. TransformedRadialGradientPixelGenerator (const ColourGradient& gradient, const AffineTransform& transform,
  66166. const PixelARGB* const lookupTable_, const int numEntries_) throw()
  66167. : RadialGradientPixelGenerator (gradient, transform, lookupTable_, numEntries_),
  66168. inverseTransform (transform.inverted())
  66169. {
  66170. tM10 = inverseTransform.mat10;
  66171. tM00 = inverseTransform.mat00;
  66172. }
  66173. forcedinline void setY (const int y) throw()
  66174. {
  66175. lineYM01 = inverseTransform.mat01 * y + inverseTransform.mat02 - gx1;
  66176. lineYM11 = inverseTransform.mat11 * y + inverseTransform.mat12 - gy1;
  66177. }
  66178. forcedinline const PixelARGB getPixel (const int px) const throw()
  66179. {
  66180. double x = px;
  66181. const double y = tM10 * x + lineYM11;
  66182. x = tM00 * x + lineYM01;
  66183. x *= x;
  66184. x += y * y;
  66185. if (x >= maxDist)
  66186. return lookupTable [numEntries];
  66187. else
  66188. return lookupTable [jmin (numEntries, roundToInt (sqrt (x) * invScale))];
  66189. }
  66190. private:
  66191. double tM10, tM00, lineYM01, lineYM11;
  66192. const AffineTransform inverseTransform;
  66193. TransformedRadialGradientPixelGenerator (const TransformedRadialGradientPixelGenerator&);
  66194. const TransformedRadialGradientPixelGenerator& operator= (const TransformedRadialGradientPixelGenerator&);
  66195. };
  66196. template <class PixelType, class GradientType>
  66197. class GradientEdgeTableRenderer : public GradientType
  66198. {
  66199. public:
  66200. GradientEdgeTableRenderer (const Image::BitmapData& destData_, const ColourGradient& gradient, const AffineTransform& transform,
  66201. const PixelARGB* const lookupTable_, const int numEntries_) throw()
  66202. : GradientType (gradient, transform, lookupTable_, numEntries_ - 1),
  66203. destData (destData_)
  66204. {
  66205. }
  66206. forcedinline void setEdgeTableYPos (const int y) throw()
  66207. {
  66208. linePixels = (PixelType*) destData.getLinePointer (y);
  66209. GradientType::setY (y);
  66210. }
  66211. forcedinline void handleEdgeTablePixel (const int x, const int alphaLevel) const throw()
  66212. {
  66213. linePixels[x].blend (GradientType::getPixel (x), alphaLevel);
  66214. }
  66215. forcedinline void handleEdgeTableLine (int x, int width, const int alphaLevel) const throw()
  66216. {
  66217. PixelType* dest = linePixels + x;
  66218. if (alphaLevel < 0xff)
  66219. {
  66220. do
  66221. {
  66222. (dest++)->blend (GradientType::getPixel (x++), alphaLevel);
  66223. } while (--width > 0);
  66224. }
  66225. else
  66226. {
  66227. do
  66228. {
  66229. (dest++)->blend (GradientType::getPixel (x++));
  66230. } while (--width > 0);
  66231. }
  66232. }
  66233. private:
  66234. const Image::BitmapData& destData;
  66235. PixelType* linePixels;
  66236. GradientEdgeTableRenderer (const GradientEdgeTableRenderer&);
  66237. const GradientEdgeTableRenderer& operator= (const GradientEdgeTableRenderer&);
  66238. };
  66239. static forcedinline int safeModulo (int n, const int divisor) throw()
  66240. {
  66241. jassert (divisor > 0);
  66242. n %= divisor;
  66243. return (n < 0) ? (n + divisor) : n;
  66244. }
  66245. template <class DestPixelType, class SrcPixelType, bool repeatPattern>
  66246. class ImageFillEdgeTableRenderer
  66247. {
  66248. public:
  66249. ImageFillEdgeTableRenderer (const Image::BitmapData& destData_,
  66250. const Image::BitmapData& srcData_,
  66251. const int extraAlpha_,
  66252. const int x, const int y) throw()
  66253. : destData (destData_),
  66254. srcData (srcData_),
  66255. extraAlpha (extraAlpha_ + 1),
  66256. xOffset (repeatPattern ? safeModulo (x, srcData_.width) - srcData_.width : x),
  66257. yOffset (repeatPattern ? safeModulo (y, srcData_.height) - srcData_.height : y)
  66258. {
  66259. }
  66260. forcedinline void setEdgeTableYPos (int y) throw()
  66261. {
  66262. linePixels = (DestPixelType*) destData.getLinePointer (y);
  66263. y -= yOffset;
  66264. if (repeatPattern)
  66265. {
  66266. jassert (y >= 0);
  66267. y %= srcData.height;
  66268. }
  66269. sourceLineStart = (SrcPixelType*) srcData.getLinePointer (y);
  66270. }
  66271. forcedinline void handleEdgeTablePixel (int x, int alphaLevel) const throw()
  66272. {
  66273. alphaLevel = (alphaLevel * extraAlpha) >> 8;
  66274. linePixels[x].blend (sourceLineStart [repeatPattern ? ((x - xOffset) % srcData.width) : (x - xOffset)], alphaLevel);
  66275. }
  66276. forcedinline void handleEdgeTableLine (int x, int width, int alphaLevel) const throw()
  66277. {
  66278. DestPixelType* dest = linePixels + x;
  66279. alphaLevel = (alphaLevel * extraAlpha) >> 8;
  66280. x -= xOffset;
  66281. jassert (repeatPattern || (x >= 0 && x + width <= srcData.width));
  66282. if (alphaLevel < 0xfe)
  66283. {
  66284. do
  66285. {
  66286. dest++ ->blend (sourceLineStart [repeatPattern ? (x++ % srcData.width) : x++], alphaLevel);
  66287. } while (--width > 0);
  66288. }
  66289. else
  66290. {
  66291. if (repeatPattern)
  66292. {
  66293. do
  66294. {
  66295. dest++ ->blend (sourceLineStart [x++ % srcData.width]);
  66296. } while (--width > 0);
  66297. }
  66298. else
  66299. {
  66300. copyRow (dest, sourceLineStart + x, width);
  66301. }
  66302. }
  66303. }
  66304. void clipEdgeTableLine (EdgeTable& et, int x, int y, int width) throw()
  66305. {
  66306. jassert (x - xOffset >= 0 && x + width - xOffset <= srcData.width);
  66307. SrcPixelType* s = (SrcPixelType*) srcData.getLinePointer (y - yOffset);
  66308. uint8* mask = (uint8*) (s + x - xOffset);
  66309. if (sizeof (SrcPixelType) == sizeof (PixelARGB))
  66310. mask += PixelARGB::indexA;
  66311. et.clipLineToMask (x, y, mask, sizeof (SrcPixelType), width);
  66312. }
  66313. private:
  66314. const Image::BitmapData& destData;
  66315. const Image::BitmapData& srcData;
  66316. const int extraAlpha, xOffset, yOffset;
  66317. DestPixelType* linePixels;
  66318. SrcPixelType* sourceLineStart;
  66319. template <class PixelType1, class PixelType2>
  66320. forcedinline static void copyRow (PixelType1* dest, PixelType2* src, int width) throw()
  66321. {
  66322. do
  66323. {
  66324. dest++ ->blend (*src++);
  66325. } while (--width > 0);
  66326. }
  66327. forcedinline static void copyRow (PixelRGB* dest, PixelRGB* src, int width) throw()
  66328. {
  66329. memcpy (dest, src, width * sizeof (PixelRGB));
  66330. }
  66331. ImageFillEdgeTableRenderer (const ImageFillEdgeTableRenderer&);
  66332. const ImageFillEdgeTableRenderer& operator= (const ImageFillEdgeTableRenderer&);
  66333. };
  66334. template <class DestPixelType, class SrcPixelType, bool repeatPattern>
  66335. class TransformedImageFillEdgeTableRenderer
  66336. {
  66337. public:
  66338. TransformedImageFillEdgeTableRenderer (const Image::BitmapData& destData_,
  66339. const Image::BitmapData& srcData_,
  66340. const AffineTransform& transform,
  66341. const int extraAlpha_,
  66342. const bool betterQuality_) throw()
  66343. : interpolator (transform),
  66344. destData (destData_),
  66345. srcData (srcData_),
  66346. extraAlpha (extraAlpha_ + 1),
  66347. betterQuality (betterQuality_),
  66348. pixelOffset (betterQuality_ ? 0.5f : 0.0f),
  66349. pixelOffsetInt (betterQuality_ ? -128 : 0),
  66350. maxX (srcData_.width - 1),
  66351. maxY (srcData_.height - 1),
  66352. scratchSize (2048)
  66353. {
  66354. scratchBuffer.malloc (scratchSize);
  66355. }
  66356. ~TransformedImageFillEdgeTableRenderer() throw()
  66357. {
  66358. }
  66359. forcedinline void setEdgeTableYPos (const int newY) throw()
  66360. {
  66361. y = newY;
  66362. linePixels = (DestPixelType*) destData.getLinePointer (newY);
  66363. }
  66364. forcedinline void handleEdgeTablePixel (const int x, int alphaLevel) throw()
  66365. {
  66366. alphaLevel *= extraAlpha;
  66367. alphaLevel >>= 8;
  66368. SrcPixelType p;
  66369. generate (&p, x, 1);
  66370. linePixels[x].blend (p, alphaLevel);
  66371. }
  66372. forcedinline void handleEdgeTableLine (const int x, int width, int alphaLevel) throw()
  66373. {
  66374. if (width > scratchSize)
  66375. {
  66376. scratchSize = width;
  66377. scratchBuffer.malloc (scratchSize);
  66378. }
  66379. SrcPixelType* span = scratchBuffer;
  66380. generate (span, x, width);
  66381. DestPixelType* dest = linePixels + x;
  66382. alphaLevel *= extraAlpha;
  66383. alphaLevel >>= 8;
  66384. if (alphaLevel < 0xfe)
  66385. {
  66386. do
  66387. {
  66388. dest++ ->blend (*span++, alphaLevel);
  66389. } while (--width > 0);
  66390. }
  66391. else
  66392. {
  66393. do
  66394. {
  66395. dest++ ->blend (*span++);
  66396. } while (--width > 0);
  66397. }
  66398. }
  66399. void clipEdgeTableLine (EdgeTable& et, int x, int y_, int width) throw()
  66400. {
  66401. if (width > scratchSize)
  66402. {
  66403. scratchSize = width;
  66404. scratchBuffer.malloc (scratchSize);
  66405. }
  66406. uint8* mask = (uint8*) scratchBuffer;
  66407. y = y_;
  66408. generate ((SrcPixelType*) mask, x, width);
  66409. if (sizeof (SrcPixelType) == sizeof (PixelARGB))
  66410. mask += PixelARGB::indexA;
  66411. et.clipLineToMask (x, y_, mask, sizeof (SrcPixelType), width);
  66412. }
  66413. private:
  66414. void generate (PixelARGB* dest, const int x, int numPixels) throw()
  66415. {
  66416. this->interpolator.setStartOfLine (x + pixelOffset, y + pixelOffset, numPixels);
  66417. do
  66418. {
  66419. int hiResX, hiResY;
  66420. this->interpolator.next (hiResX, hiResY);
  66421. hiResX += pixelOffsetInt;
  66422. hiResY += pixelOffsetInt;
  66423. int loResX = hiResX >> 8;
  66424. int loResY = hiResY >> 8;
  66425. if (repeatPattern)
  66426. {
  66427. loResX = safeModulo (loResX, srcData.width);
  66428. loResY = safeModulo (loResY, srcData.height);
  66429. }
  66430. if (betterQuality
  66431. && ((unsigned int) loResX) < (unsigned int) maxX
  66432. && ((unsigned int) loResY) < (unsigned int) maxY)
  66433. {
  66434. uint32 c[4] = { 256 * 128, 256 * 128, 256 * 128, 256 * 128 };
  66435. hiResX &= 255;
  66436. hiResY &= 255;
  66437. const uint8* src = this->srcData.getPixelPointer (loResX, loResY);
  66438. uint32 weight = (256 - hiResX) * (256 - hiResY);
  66439. c[0] += weight * src[0];
  66440. c[1] += weight * src[1];
  66441. c[2] += weight * src[2];
  66442. c[3] += weight * src[3];
  66443. weight = hiResX * (256 - hiResY);
  66444. c[0] += weight * src[4];
  66445. c[1] += weight * src[5];
  66446. c[2] += weight * src[6];
  66447. c[3] += weight * src[7];
  66448. src += this->srcData.lineStride;
  66449. weight = (256 - hiResX) * hiResY;
  66450. c[0] += weight * src[0];
  66451. c[1] += weight * src[1];
  66452. c[2] += weight * src[2];
  66453. c[3] += weight * src[3];
  66454. weight = hiResX * hiResY;
  66455. c[0] += weight * src[4];
  66456. c[1] += weight * src[5];
  66457. c[2] += weight * src[6];
  66458. c[3] += weight * src[7];
  66459. dest->setARGB ((uint8) (c[PixelARGB::indexA] >> 16),
  66460. (uint8) (c[PixelARGB::indexR] >> 16),
  66461. (uint8) (c[PixelARGB::indexG] >> 16),
  66462. (uint8) (c[PixelARGB::indexB] >> 16));
  66463. }
  66464. else
  66465. {
  66466. if (! repeatPattern)
  66467. {
  66468. // Beyond the edges, just repeat the edge pixels and leave the anti-aliasing to be handled by the edgetable
  66469. if (loResX < 0) loResX = 0;
  66470. if (loResY < 0) loResY = 0;
  66471. if (loResX > maxX) loResX = maxX;
  66472. if (loResY > maxY) loResY = maxY;
  66473. }
  66474. dest->set (*(const PixelARGB*) this->srcData.getPixelPointer (loResX, loResY));
  66475. }
  66476. ++dest;
  66477. } while (--numPixels > 0);
  66478. }
  66479. void generate (PixelRGB* dest, const int x, int numPixels) throw()
  66480. {
  66481. this->interpolator.setStartOfLine (x + pixelOffset, y + pixelOffset, numPixels);
  66482. do
  66483. {
  66484. int hiResX, hiResY;
  66485. this->interpolator.next (hiResX, hiResY);
  66486. hiResX += pixelOffsetInt;
  66487. hiResY += pixelOffsetInt;
  66488. int loResX = hiResX >> 8;
  66489. int loResY = hiResY >> 8;
  66490. if (repeatPattern)
  66491. {
  66492. loResX = safeModulo (loResX, srcData.width);
  66493. loResY = safeModulo (loResY, srcData.height);
  66494. }
  66495. if (betterQuality
  66496. && ((unsigned int) loResX) < (unsigned int) maxX
  66497. && ((unsigned int) loResY) < (unsigned int) maxY)
  66498. {
  66499. uint32 c[3] = { 256 * 128, 256 * 128, 256 * 128 };
  66500. hiResX &= 255;
  66501. hiResY &= 255;
  66502. const uint8* src = this->srcData.getPixelPointer (loResX, loResY);
  66503. unsigned int weight = (256 - hiResX) * (256 - hiResY);
  66504. c[0] += weight * src[0];
  66505. c[1] += weight * src[1];
  66506. c[2] += weight * src[2];
  66507. weight = hiResX * (256 - hiResY);
  66508. c[0] += weight * src[3];
  66509. c[1] += weight * src[4];
  66510. c[2] += weight * src[5];
  66511. src += this->srcData.lineStride;
  66512. weight = (256 - hiResX) * hiResY;
  66513. c[0] += weight * src[0];
  66514. c[1] += weight * src[1];
  66515. c[2] += weight * src[2];
  66516. weight = hiResX * hiResY;
  66517. c[0] += weight * src[3];
  66518. c[1] += weight * src[4];
  66519. c[2] += weight * src[5];
  66520. dest->setARGB ((uint8) 255,
  66521. (uint8) (c[PixelRGB::indexR] >> 16),
  66522. (uint8) (c[PixelRGB::indexG] >> 16),
  66523. (uint8) (c[PixelRGB::indexB] >> 16));
  66524. }
  66525. else
  66526. {
  66527. if (! repeatPattern)
  66528. {
  66529. // Beyond the edges, just repeat the edge pixels and leave the anti-aliasing to be handled by the edgetable
  66530. if (loResX < 0) loResX = 0;
  66531. if (loResY < 0) loResY = 0;
  66532. if (loResX > maxX) loResX = maxX;
  66533. if (loResY > maxY) loResY = maxY;
  66534. }
  66535. dest->set (*(const PixelRGB*) this->srcData.getPixelPointer (loResX, loResY));
  66536. }
  66537. ++dest;
  66538. } while (--numPixels > 0);
  66539. }
  66540. void generate (PixelAlpha* dest, const int x, int numPixels) throw()
  66541. {
  66542. this->interpolator.setStartOfLine (x + pixelOffset, y + pixelOffset, numPixels);
  66543. do
  66544. {
  66545. int hiResX, hiResY;
  66546. this->interpolator.next (hiResX, hiResY);
  66547. hiResX += pixelOffsetInt;
  66548. hiResY += pixelOffsetInt;
  66549. int loResX = hiResX >> 8;
  66550. int loResY = hiResY >> 8;
  66551. if (repeatPattern)
  66552. {
  66553. loResX = safeModulo (loResX, srcData.width);
  66554. loResY = safeModulo (loResY, srcData.height);
  66555. }
  66556. if (betterQuality
  66557. && ((unsigned int) loResX) < (unsigned int) maxX
  66558. && ((unsigned int) loResY) < (unsigned int) maxY)
  66559. {
  66560. hiResX &= 255;
  66561. hiResY &= 255;
  66562. const uint8* src = this->srcData.getPixelPointer (loResX, loResY);
  66563. uint32 c = 256 * 128;
  66564. c += src[0] * ((256 - hiResX) * (256 - hiResY));
  66565. c += src[1] * (hiResX * (256 - hiResY));
  66566. src += this->srcData.lineStride;
  66567. c += src[0] * ((256 - hiResX) * hiResY);
  66568. c += src[1] * (hiResX * hiResY);
  66569. *((uint8*) dest) = (uint8) c;
  66570. }
  66571. else
  66572. {
  66573. if (! repeatPattern)
  66574. {
  66575. // Beyond the edges, just repeat the edge pixels and leave the anti-aliasing to be handled by the edgetable
  66576. if (loResX < 0) loResX = 0;
  66577. if (loResY < 0) loResY = 0;
  66578. if (loResX > maxX) loResX = maxX;
  66579. if (loResY > maxY) loResY = maxY;
  66580. }
  66581. *((uint8*) dest) = *(this->srcData.getPixelPointer (loResX, loResY));
  66582. }
  66583. ++dest;
  66584. } while (--numPixels > 0);
  66585. }
  66586. class TransformedImageSpanInterpolator
  66587. {
  66588. public:
  66589. TransformedImageSpanInterpolator (const AffineTransform& transform) throw()
  66590. : inverseTransform (transform.inverted())
  66591. {}
  66592. void setStartOfLine (float x, float y, const int numPixels) throw()
  66593. {
  66594. float x1 = x, y1 = y;
  66595. inverseTransform.transformPoint (x1, y1);
  66596. x += numPixels;
  66597. inverseTransform.transformPoint (x, y);
  66598. xBresenham.set ((int) (x1 * 256.0f), (int) (x * 256.0f), numPixels);
  66599. yBresenham.set ((int) (y1 * 256.0f), (int) (y * 256.0f), numPixels);
  66600. }
  66601. void next (int& x, int& y) throw()
  66602. {
  66603. x = xBresenham.n;
  66604. xBresenham.stepToNext();
  66605. y = yBresenham.n;
  66606. yBresenham.stepToNext();
  66607. }
  66608. private:
  66609. class BresenhamInterpolator
  66610. {
  66611. public:
  66612. BresenhamInterpolator() throw() {}
  66613. void set (const int n1, const int n2, const int numSteps_) throw()
  66614. {
  66615. numSteps = jmax (1, numSteps_);
  66616. step = (n2 - n1) / numSteps;
  66617. remainder = modulo = (n2 - n1) % numSteps;
  66618. n = n1;
  66619. if (modulo <= 0)
  66620. {
  66621. modulo += numSteps;
  66622. remainder += numSteps;
  66623. --step;
  66624. }
  66625. modulo -= numSteps;
  66626. }
  66627. forcedinline void stepToNext() throw()
  66628. {
  66629. modulo += remainder;
  66630. n += step;
  66631. if (modulo > 0)
  66632. {
  66633. modulo -= numSteps;
  66634. ++n;
  66635. }
  66636. }
  66637. int n;
  66638. private:
  66639. int numSteps, step, modulo, remainder;
  66640. };
  66641. const AffineTransform inverseTransform;
  66642. BresenhamInterpolator xBresenham, yBresenham;
  66643. TransformedImageSpanInterpolator (const TransformedImageSpanInterpolator&);
  66644. const TransformedImageSpanInterpolator& operator= (const TransformedImageSpanInterpolator&);
  66645. };
  66646. TransformedImageSpanInterpolator interpolator;
  66647. const Image::BitmapData& destData;
  66648. const Image::BitmapData& srcData;
  66649. const int extraAlpha;
  66650. const bool betterQuality;
  66651. const float pixelOffset;
  66652. const int pixelOffsetInt, maxX, maxY;
  66653. int y;
  66654. DestPixelType* linePixels;
  66655. HeapBlock <SrcPixelType> scratchBuffer;
  66656. int scratchSize;
  66657. TransformedImageFillEdgeTableRenderer (const TransformedImageFillEdgeTableRenderer&);
  66658. const TransformedImageFillEdgeTableRenderer& operator= (const TransformedImageFillEdgeTableRenderer&);
  66659. };
  66660. class LLGCSavedState
  66661. {
  66662. public:
  66663. LLGCSavedState (const Rectangle<int>& clip_, const int xOffset_, const int yOffset_,
  66664. const Font& font_, const FillType& fillType_,
  66665. const Graphics::ResamplingQuality interpolationQuality_) throw()
  66666. : edgeTable (new EdgeTableHolder (EdgeTable (clip_))),
  66667. xOffset (xOffset_), yOffset (yOffset_),
  66668. font (font_), fillType (fillType_),
  66669. interpolationQuality (interpolationQuality_)
  66670. {
  66671. }
  66672. LLGCSavedState (const LLGCSavedState& other) throw()
  66673. : edgeTable (other.edgeTable), xOffset (other.xOffset),
  66674. yOffset (other.yOffset), font (other.font),
  66675. fillType (other.fillType), interpolationQuality (other.interpolationQuality)
  66676. {
  66677. }
  66678. ~LLGCSavedState() throw()
  66679. {
  66680. }
  66681. bool clipToRectangle (const Rectangle<int>& r) throw()
  66682. {
  66683. dupeEdgeTableIfMultiplyReferenced();
  66684. edgeTable->edgeTable.clipToRectangle (r.translated (xOffset, yOffset));
  66685. return ! edgeTable->edgeTable.isEmpty();
  66686. }
  66687. bool clipToRectangleList (const RectangleList& r) throw()
  66688. {
  66689. dupeEdgeTableIfMultiplyReferenced();
  66690. RectangleList offsetList (r);
  66691. offsetList.offsetAll (xOffset, yOffset);
  66692. EdgeTable e2 (offsetList);
  66693. edgeTable->edgeTable.clipToEdgeTable (e2);
  66694. return ! edgeTable->edgeTable.isEmpty();
  66695. }
  66696. bool excludeClipRectangle (const Rectangle<int>& r) throw()
  66697. {
  66698. dupeEdgeTableIfMultiplyReferenced();
  66699. edgeTable->edgeTable.excludeRectangle (r.translated (xOffset, yOffset));
  66700. return ! edgeTable->edgeTable.isEmpty();
  66701. }
  66702. void clipToPath (const Path& p, const AffineTransform& transform) throw()
  66703. {
  66704. dupeEdgeTableIfMultiplyReferenced();
  66705. EdgeTable et (edgeTable->edgeTable.getMaximumBounds(), p, transform.translated ((float) xOffset, (float) yOffset));
  66706. edgeTable->edgeTable.clipToEdgeTable (et);
  66707. }
  66708. void fillEdgeTable (Image& image, EdgeTable& et, const bool replaceContents = false) throw()
  66709. {
  66710. et.clipToEdgeTable (edgeTable->edgeTable);
  66711. Image::BitmapData destData (image, 0, 0, image.getWidth(), image.getHeight(), true);
  66712. if (fillType.isGradient())
  66713. {
  66714. jassert (! replaceContents); // that option is just for solid colours
  66715. ColourGradient g2 (*(fillType.gradient));
  66716. g2.multiplyOpacity (fillType.getOpacity());
  66717. g2.x1 -= 0.5f; g2.y1 -= 0.5f;
  66718. g2.x2 -= 0.5f; g2.y2 -= 0.5f;
  66719. AffineTransform transform (fillType.transform.translated ((float) xOffset, (float) yOffset));
  66720. const bool isIdentity = transform.isOnlyTranslation();
  66721. if (isIdentity)
  66722. {
  66723. // If our translation doesn't involve any distortion, we can speed it up..
  66724. transform.transformPoint (g2.x1, g2.y1);
  66725. transform.transformPoint (g2.x2, g2.y2);
  66726. transform = AffineTransform::identity;
  66727. }
  66728. HeapBlock <PixelARGB> lookupTable;
  66729. const int numLookupEntries = g2.createLookupTable (transform, lookupTable);
  66730. jassert (numLookupEntries > 0);
  66731. switch (image.getFormat())
  66732. {
  66733. case Image::ARGB: renderGradient (et, destData, g2, transform, lookupTable, numLookupEntries, isIdentity, (PixelARGB*) 0); break;
  66734. case Image::RGB: renderGradient (et, destData, g2, transform, lookupTable, numLookupEntries, isIdentity, (PixelRGB*) 0); break;
  66735. default: renderGradient (et, destData, g2, transform, lookupTable, numLookupEntries, isIdentity, (PixelAlpha*) 0); break;
  66736. }
  66737. }
  66738. else if (fillType.isTiledImage())
  66739. {
  66740. renderImage (image, *(fillType.image), fillType.image->getBounds(), fillType.transform, &et);
  66741. }
  66742. else
  66743. {
  66744. const PixelARGB fillColour (fillType.colour.getPixelARGB());
  66745. switch (image.getFormat())
  66746. {
  66747. case Image::ARGB: renderSolidFill (et, destData, fillColour, replaceContents, (PixelARGB*) 0); break;
  66748. case Image::RGB: renderSolidFill (et, destData, fillColour, replaceContents, (PixelRGB*) 0); break;
  66749. default: renderSolidFill (et, destData, fillColour, replaceContents, (PixelAlpha*) 0); break;
  66750. }
  66751. }
  66752. }
  66753. void renderImage (Image& destImage, const Image& sourceImage, const Rectangle<int>& srcClip,
  66754. const AffineTransform& t, const EdgeTable* const tiledFillClipRegion) throw()
  66755. {
  66756. const AffineTransform transform (t.translated ((float) xOffset, (float) yOffset));
  66757. const Image::BitmapData destData (destImage, 0, 0, destImage.getWidth(), destImage.getHeight(), true);
  66758. const Image::BitmapData srcData (sourceImage, srcClip.getX(), srcClip.getY(), srcClip.getWidth(), srcClip.getHeight());
  66759. const int alpha = fillType.colour.getAlpha();
  66760. const bool betterQuality = (interpolationQuality != Graphics::lowResamplingQuality);
  66761. if (transform.isOnlyTranslation())
  66762. {
  66763. // If our translation doesn't involve any distortion, just use a simple blit..
  66764. int tx = (int) (transform.getTranslationX() * 256.0f);
  66765. int ty = (int) (transform.getTranslationY() * 256.0f);
  66766. if ((! betterQuality) || ((tx | ty) & 224) == 0)
  66767. {
  66768. tx = ((tx + 128) >> 8);
  66769. ty = ((ty + 128) >> 8);
  66770. if (tiledFillClipRegion != 0)
  66771. {
  66772. blittedRenderImage (sourceImage, destImage, *tiledFillClipRegion, destData, srcData, alpha, tx, ty, true);
  66773. }
  66774. else
  66775. {
  66776. EdgeTable et (Rectangle<int> (tx, ty, srcClip.getWidth(), srcClip.getHeight()).getIntersection (destImage.getBounds()));
  66777. et.clipToEdgeTable (edgeTable->edgeTable);
  66778. if (! et.isEmpty())
  66779. blittedRenderImage (sourceImage, destImage, et, destData, srcData, alpha, tx, ty, false);
  66780. }
  66781. return;
  66782. }
  66783. }
  66784. if (transform.isSingularity())
  66785. return;
  66786. if (tiledFillClipRegion != 0)
  66787. {
  66788. transformedRenderImage (sourceImage, destImage, *tiledFillClipRegion, destData, srcData, alpha, transform, betterQuality, true);
  66789. }
  66790. else
  66791. {
  66792. Path p;
  66793. p.addRectangle (0.0f, 0.0f, (float) srcClip.getWidth(), (float) srcClip.getHeight());
  66794. EdgeTable et (edgeTable->edgeTable.getMaximumBounds(), p, transform);
  66795. et.clipToEdgeTable (edgeTable->edgeTable);
  66796. if (! et.isEmpty())
  66797. transformedRenderImage (sourceImage, destImage, et, destData, srcData, alpha, transform, betterQuality, false);
  66798. }
  66799. }
  66800. void clipToImageAlpha (const Image& image, const Rectangle<int>& srcClip, const AffineTransform& t) throw()
  66801. {
  66802. if (! image.hasAlphaChannel())
  66803. {
  66804. Path p;
  66805. p.addRectangle (srcClip);
  66806. clipToPath (p, t);
  66807. return;
  66808. }
  66809. dupeEdgeTableIfMultiplyReferenced();
  66810. const AffineTransform transform (t.translated ((float) xOffset, (float) yOffset));
  66811. const Image::BitmapData srcData (image, srcClip.getX(), srcClip.getY(), srcClip.getWidth(), srcClip.getHeight());
  66812. const bool betterQuality = (interpolationQuality != Graphics::lowResamplingQuality);
  66813. EdgeTable& et = edgeTable->edgeTable;
  66814. if (transform.isOnlyTranslation())
  66815. {
  66816. // If our translation doesn't involve any distortion, just use a simple blit..
  66817. const int tx = (int) (transform.getTranslationX() * 256.0f);
  66818. const int ty = (int) (transform.getTranslationY() * 256.0f);
  66819. if ((! betterQuality) || ((tx | ty) & 224) == 0)
  66820. {
  66821. const int imageX = ((tx + 128) >> 8);
  66822. const int imageY = ((ty + 128) >> 8);
  66823. if (image.getFormat() == Image::ARGB)
  66824. straightClipImage (et, srcData, imageX, imageY, (PixelARGB*)0);
  66825. else
  66826. straightClipImage (et, srcData, imageX, imageY, (PixelAlpha*)0);
  66827. return;
  66828. }
  66829. }
  66830. if (transform.isSingularity())
  66831. {
  66832. et.clipToRectangle (Rectangle<int>());
  66833. return;
  66834. }
  66835. {
  66836. Path p;
  66837. p.addRectangle (0, 0, (float) srcData.width, (float) srcData.height);
  66838. EdgeTable et2 (et.getMaximumBounds(), p, transform);
  66839. et.clipToEdgeTable (et2);
  66840. }
  66841. if (! et.isEmpty())
  66842. {
  66843. if (image.getFormat() == Image::ARGB)
  66844. transformedClipImage (et, srcData, transform, betterQuality, (PixelARGB*)0);
  66845. else
  66846. transformedClipImage (et, srcData, transform, betterQuality, (PixelAlpha*)0);
  66847. }
  66848. }
  66849. template <class SrcPixelType>
  66850. void transformedClipImage (EdgeTable& et, const Image::BitmapData& srcData, const AffineTransform& transform, const bool betterQuality, const SrcPixelType *) throw()
  66851. {
  66852. TransformedImageFillEdgeTableRenderer <SrcPixelType, SrcPixelType, false> renderer (srcData, srcData, transform, 255, betterQuality);
  66853. for (int y = 0; y < et.getMaximumBounds().getHeight(); ++y)
  66854. renderer.clipEdgeTableLine (et, et.getMaximumBounds().getX(), y + et.getMaximumBounds().getY(),
  66855. et.getMaximumBounds().getWidth());
  66856. }
  66857. template <class SrcPixelType>
  66858. void straightClipImage (EdgeTable& et, const Image::BitmapData& srcData, int imageX, int imageY, const SrcPixelType *) throw()
  66859. {
  66860. Rectangle<int> r (imageX, imageY, srcData.width, srcData.height);
  66861. et.clipToRectangle (r);
  66862. ImageFillEdgeTableRenderer <SrcPixelType, SrcPixelType, false> renderer (srcData, srcData, 255, imageX, imageY);
  66863. for (int y = 0; y < r.getHeight(); ++y)
  66864. renderer.clipEdgeTableLine (et, r.getX(), y + r.getY(), r.getWidth());
  66865. }
  66866. class EdgeTableHolder : public ReferenceCountedObject
  66867. {
  66868. public:
  66869. EdgeTableHolder (const EdgeTable& e) throw() : edgeTable (e) {}
  66870. EdgeTable edgeTable;
  66871. };
  66872. ReferenceCountedObjectPtr<EdgeTableHolder> edgeTable;
  66873. int xOffset, yOffset;
  66874. Font font;
  66875. FillType fillType;
  66876. Graphics::ResamplingQuality interpolationQuality;
  66877. private:
  66878. const LLGCSavedState& operator= (const LLGCSavedState&);
  66879. void dupeEdgeTableIfMultiplyReferenced() throw()
  66880. {
  66881. if (edgeTable->getReferenceCount() > 1)
  66882. edgeTable = new EdgeTableHolder (edgeTable->edgeTable);
  66883. }
  66884. template <class DestPixelType>
  66885. void renderGradient (EdgeTable& et, const Image::BitmapData& destData, const ColourGradient& g, const AffineTransform& transform,
  66886. const PixelARGB* const lookupTable, const int numLookupEntries, const bool isIdentity, DestPixelType*) throw()
  66887. {
  66888. jassert (destData.pixelStride == sizeof (DestPixelType));
  66889. if (g.isRadial)
  66890. {
  66891. if (isIdentity)
  66892. {
  66893. GradientEdgeTableRenderer <DestPixelType, RadialGradientPixelGenerator> renderer (destData, g, transform, lookupTable, numLookupEntries);
  66894. et.iterate (renderer);
  66895. }
  66896. else
  66897. {
  66898. GradientEdgeTableRenderer <DestPixelType, TransformedRadialGradientPixelGenerator> renderer (destData, g, transform, lookupTable, numLookupEntries);
  66899. et.iterate (renderer);
  66900. }
  66901. }
  66902. else
  66903. {
  66904. GradientEdgeTableRenderer <DestPixelType, LinearGradientPixelGenerator> renderer (destData, g, transform, lookupTable, numLookupEntries);
  66905. et.iterate (renderer);
  66906. }
  66907. }
  66908. template <class DestPixelType>
  66909. void renderSolidFill (EdgeTable& et, const Image::BitmapData& destData, const PixelARGB& fillColour, const bool replaceContents, DestPixelType*) throw()
  66910. {
  66911. jassert (destData.pixelStride == sizeof (DestPixelType));
  66912. if (replaceContents)
  66913. {
  66914. SolidColourEdgeTableRenderer <DestPixelType, true> r (destData, fillColour);
  66915. et.iterate (r);
  66916. }
  66917. else
  66918. {
  66919. SolidColourEdgeTableRenderer <DestPixelType, false> r (destData, fillColour);
  66920. et.iterate (r);
  66921. }
  66922. }
  66923. void transformedRenderImage (const Image& srcImage, Image& destImage, const EdgeTable& et, const Image::BitmapData& destData, const Image::BitmapData& srcData,
  66924. const int alpha, const AffineTransform& transform, const bool betterQuality, const bool repeatPattern) throw()
  66925. {
  66926. switch (destImage.getFormat())
  66927. {
  66928. case Image::ARGB:
  66929. switch (srcImage.getFormat())
  66930. {
  66931. case Image::ARGB:
  66932. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelARGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66933. else { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelARGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66934. break;
  66935. case Image::RGB:
  66936. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelRGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66937. else { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelRGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66938. break;
  66939. default:
  66940. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelAlpha, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66941. else { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelAlpha, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66942. break;
  66943. }
  66944. break;
  66945. case Image::RGB:
  66946. switch (srcImage.getFormat())
  66947. {
  66948. case Image::ARGB:
  66949. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelARGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66950. else { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelARGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66951. break;
  66952. case Image::RGB:
  66953. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelRGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66954. else { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelRGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66955. break;
  66956. default:
  66957. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelAlpha, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66958. else { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelAlpha, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66959. break;
  66960. }
  66961. break;
  66962. default:
  66963. switch (srcImage.getFormat())
  66964. {
  66965. case Image::ARGB:
  66966. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelARGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66967. else { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelARGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66968. break;
  66969. case Image::RGB:
  66970. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelRGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66971. else { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelRGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66972. break;
  66973. default:
  66974. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelAlpha, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66975. else { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelAlpha, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66976. break;
  66977. }
  66978. break;
  66979. }
  66980. }
  66981. void blittedRenderImage (const Image& srcImage, Image& destImage, const EdgeTable& et, const Image::BitmapData& destData,
  66982. const Image::BitmapData& srcData, const int alpha, int x, int y, const bool repeatPattern) throw()
  66983. {
  66984. switch (destImage.getFormat())
  66985. {
  66986. case Image::ARGB:
  66987. switch (srcImage.getFormat())
  66988. {
  66989. case Image::ARGB:
  66990. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelARGB, PixelARGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66991. else { ImageFillEdgeTableRenderer <PixelARGB, PixelARGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66992. break;
  66993. case Image::RGB:
  66994. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelARGB, PixelRGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66995. else { ImageFillEdgeTableRenderer <PixelARGB, PixelRGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66996. break;
  66997. default:
  66998. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelARGB, PixelAlpha, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66999. else { ImageFillEdgeTableRenderer <PixelARGB, PixelAlpha, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  67000. break;
  67001. }
  67002. break;
  67003. case Image::RGB:
  67004. switch (srcImage.getFormat())
  67005. {
  67006. case Image::ARGB:
  67007. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelRGB, PixelARGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  67008. else { ImageFillEdgeTableRenderer <PixelRGB, PixelARGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  67009. break;
  67010. case Image::RGB:
  67011. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelRGB, PixelRGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  67012. else { ImageFillEdgeTableRenderer <PixelRGB, PixelRGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  67013. break;
  67014. default:
  67015. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelRGB, PixelAlpha, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  67016. else { ImageFillEdgeTableRenderer <PixelRGB, PixelAlpha, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  67017. break;
  67018. }
  67019. break;
  67020. default:
  67021. switch (srcImage.getFormat())
  67022. {
  67023. case Image::ARGB:
  67024. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelAlpha, PixelARGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  67025. else { ImageFillEdgeTableRenderer <PixelAlpha, PixelARGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  67026. break;
  67027. case Image::RGB:
  67028. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelAlpha, PixelRGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  67029. else { ImageFillEdgeTableRenderer <PixelAlpha, PixelRGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  67030. break;
  67031. default:
  67032. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelAlpha, PixelAlpha, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  67033. else { ImageFillEdgeTableRenderer <PixelAlpha, PixelAlpha, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  67034. break;
  67035. }
  67036. break;
  67037. }
  67038. }
  67039. };
  67040. LowLevelGraphicsSoftwareRenderer::LowLevelGraphicsSoftwareRenderer (Image& image_)
  67041. : image (image_)
  67042. {
  67043. currentState = new LLGCSavedState (image_.getBounds(), 0, 0, Font(),
  67044. FillType(), Graphics::mediumResamplingQuality);
  67045. }
  67046. LowLevelGraphicsSoftwareRenderer::~LowLevelGraphicsSoftwareRenderer()
  67047. {
  67048. }
  67049. bool LowLevelGraphicsSoftwareRenderer::isVectorDevice() const
  67050. {
  67051. return false;
  67052. }
  67053. void LowLevelGraphicsSoftwareRenderer::setOrigin (int x, int y)
  67054. {
  67055. currentState->xOffset += x;
  67056. currentState->yOffset += y;
  67057. }
  67058. bool LowLevelGraphicsSoftwareRenderer::clipToRectangle (const Rectangle<int>& r)
  67059. {
  67060. return currentState->clipToRectangle (r);
  67061. }
  67062. bool LowLevelGraphicsSoftwareRenderer::clipToRectangleList (const RectangleList& clipRegion)
  67063. {
  67064. return currentState->clipToRectangleList (clipRegion);
  67065. }
  67066. void LowLevelGraphicsSoftwareRenderer::excludeClipRectangle (const Rectangle<int>& r)
  67067. {
  67068. currentState->excludeClipRectangle (r);
  67069. }
  67070. void LowLevelGraphicsSoftwareRenderer::clipToPath (const Path& path, const AffineTransform& transform)
  67071. {
  67072. currentState->clipToPath (path, transform);
  67073. }
  67074. void LowLevelGraphicsSoftwareRenderer::clipToImageAlpha (const Image& sourceImage, const Rectangle<int>& srcClip, const AffineTransform& transform)
  67075. {
  67076. currentState->clipToImageAlpha (sourceImage, srcClip, transform);
  67077. }
  67078. bool LowLevelGraphicsSoftwareRenderer::clipRegionIntersects (const Rectangle<int>& r)
  67079. {
  67080. return currentState->edgeTable->edgeTable.getMaximumBounds()
  67081. .intersects (r.translated (currentState->xOffset, currentState->yOffset));
  67082. }
  67083. const Rectangle<int> LowLevelGraphicsSoftwareRenderer::getClipBounds() const
  67084. {
  67085. return currentState->edgeTable->edgeTable.getMaximumBounds().translated (-currentState->xOffset, -currentState->yOffset);
  67086. }
  67087. bool LowLevelGraphicsSoftwareRenderer::isClipEmpty() const
  67088. {
  67089. return currentState->edgeTable->edgeTable.isEmpty();
  67090. }
  67091. void LowLevelGraphicsSoftwareRenderer::saveState()
  67092. {
  67093. stateStack.add (new LLGCSavedState (*currentState));
  67094. }
  67095. void LowLevelGraphicsSoftwareRenderer::restoreState()
  67096. {
  67097. LLGCSavedState* const top = stateStack.getLast();
  67098. if (top != 0)
  67099. {
  67100. currentState = top;
  67101. stateStack.removeLast (1, false);
  67102. }
  67103. else
  67104. {
  67105. jassertfalse // trying to pop with an empty stack!
  67106. }
  67107. }
  67108. void LowLevelGraphicsSoftwareRenderer::setFill (const FillType& fillType)
  67109. {
  67110. currentState->fillType = fillType;
  67111. }
  67112. void LowLevelGraphicsSoftwareRenderer::setOpacity (float newOpacity)
  67113. {
  67114. currentState->fillType.setOpacity (newOpacity);
  67115. }
  67116. void LowLevelGraphicsSoftwareRenderer::setInterpolationQuality (Graphics::ResamplingQuality quality)
  67117. {
  67118. currentState->interpolationQuality = quality;
  67119. }
  67120. void LowLevelGraphicsSoftwareRenderer::fillRect (const Rectangle<int>& r, const bool replaceExistingContents)
  67121. {
  67122. const Rectangle<int>& totalClip = currentState->edgeTable->edgeTable.getMaximumBounds();
  67123. const Rectangle<int> clipped (totalClip.getIntersection (r.translated (currentState->xOffset, currentState->yOffset)));
  67124. if (! clipped.isEmpty())
  67125. {
  67126. EdgeTable et (clipped);
  67127. currentState->fillEdgeTable (image, et, replaceExistingContents);
  67128. }
  67129. }
  67130. void LowLevelGraphicsSoftwareRenderer::fillPath (const Path& path, const AffineTransform& transform)
  67131. {
  67132. EdgeTable et (currentState->edgeTable->edgeTable.getMaximumBounds(),
  67133. path, transform.translated ((float) currentState->xOffset,
  67134. (float) currentState->yOffset));
  67135. currentState->fillEdgeTable (image, et);
  67136. }
  67137. void LowLevelGraphicsSoftwareRenderer::drawImage (const Image& sourceImage, const Rectangle<int>& srcClip,
  67138. const AffineTransform& transform, const bool fillEntireClipAsTiles)
  67139. {
  67140. jassert (sourceImage.getBounds().contains (srcClip));
  67141. currentState->renderImage (image, sourceImage, srcClip, transform,
  67142. fillEntireClipAsTiles ? &(currentState->edgeTable->edgeTable) : 0);
  67143. }
  67144. void LowLevelGraphicsSoftwareRenderer::drawLine (double x1, double y1, double x2, double y2)
  67145. {
  67146. Path p;
  67147. p.addLineSegment ((float) x1, (float) y1, (float) x2, (float) y2, 1.0f);
  67148. fillPath (p, AffineTransform::identity);
  67149. }
  67150. void LowLevelGraphicsSoftwareRenderer::drawVerticalLine (const int x, double top, double bottom)
  67151. {
  67152. if (bottom > top)
  67153. {
  67154. EdgeTable et ((float) (x + currentState->xOffset), (float) (top + currentState->yOffset), 1.0f, (float) (bottom - top));
  67155. currentState->fillEdgeTable (image, et);
  67156. }
  67157. }
  67158. void LowLevelGraphicsSoftwareRenderer::drawHorizontalLine (const int y, double left, double right)
  67159. {
  67160. if (right > left)
  67161. {
  67162. EdgeTable et ((float) (left + currentState->xOffset), (float) (y + currentState->yOffset),
  67163. (float) (right - left), 1.0f);
  67164. currentState->fillEdgeTable (image, et);
  67165. }
  67166. }
  67167. class GlyphCache : private DeletedAtShutdown
  67168. {
  67169. public:
  67170. GlyphCache() throw()
  67171. : accessCounter (0), hits (0), misses (0)
  67172. {
  67173. for (int i = 120; --i >= 0;)
  67174. glyphs.add (new CachedGlyph());
  67175. }
  67176. ~GlyphCache() throw()
  67177. {
  67178. clearSingletonInstance();
  67179. }
  67180. juce_DeclareSingleton_SingleThreaded_Minimal (GlyphCache);
  67181. void drawGlyph (LLGCSavedState& state, Image& image, const Font& font, const int glyphNumber, float x, float y) throw()
  67182. {
  67183. ++accessCounter;
  67184. int oldestCounter = std::numeric_limits<int>::max();
  67185. CachedGlyph* oldest = 0;
  67186. for (int i = glyphs.size(); --i >= 0;)
  67187. {
  67188. CachedGlyph* const glyph = glyphs.getUnchecked (i);
  67189. if (glyph->glyph == glyphNumber && glyph->font == font)
  67190. {
  67191. ++hits;
  67192. glyph->lastAccessCount = accessCounter;
  67193. glyph->draw (state, image, x, y);
  67194. return;
  67195. }
  67196. if (glyph->lastAccessCount <= oldestCounter)
  67197. {
  67198. oldestCounter = glyph->lastAccessCount;
  67199. oldest = glyph;
  67200. }
  67201. }
  67202. if (hits + ++misses > (glyphs.size() << 4))
  67203. {
  67204. if (misses * 2 > hits)
  67205. {
  67206. for (int i = 32; --i >= 0;)
  67207. glyphs.add (new CachedGlyph());
  67208. }
  67209. hits = misses = 0;
  67210. oldest = glyphs.getLast();
  67211. }
  67212. jassert (oldest != 0);
  67213. oldest->lastAccessCount = accessCounter;
  67214. oldest->generate (font, glyphNumber);
  67215. oldest->draw (state, image, x, y);
  67216. }
  67217. class CachedGlyph
  67218. {
  67219. public:
  67220. CachedGlyph() : glyph (0), lastAccessCount (0) {}
  67221. ~CachedGlyph() {}
  67222. void draw (LLGCSavedState& state, Image& image, const float x, const float y) const throw()
  67223. {
  67224. if (edgeTable != 0)
  67225. {
  67226. EdgeTable et (*edgeTable);
  67227. et.translate (x, roundToInt (y));
  67228. state.fillEdgeTable (image, et, false);
  67229. }
  67230. }
  67231. void generate (const Font& newFont, const int glyphNumber) throw()
  67232. {
  67233. font = newFont;
  67234. glyph = glyphNumber;
  67235. edgeTable = 0;
  67236. Path glyphPath;
  67237. font.getTypeface()->getOutlineForGlyph (glyphNumber, glyphPath);
  67238. if (! glyphPath.isEmpty())
  67239. {
  67240. const float fontHeight = font.getHeight();
  67241. const AffineTransform transform (AffineTransform::scale (fontHeight * font.getHorizontalScale(), fontHeight)
  67242. .translated (0.0f, -0.5f));
  67243. edgeTable = new EdgeTable (glyphPath.getBoundsTransformed (transform).getSmallestIntegerContainer().expanded (1, 0),
  67244. glyphPath, transform);
  67245. }
  67246. }
  67247. int glyph, lastAccessCount;
  67248. Font font;
  67249. juce_UseDebuggingNewOperator
  67250. private:
  67251. ScopedPointer <EdgeTable> edgeTable;
  67252. CachedGlyph (const CachedGlyph&);
  67253. const CachedGlyph& operator= (const CachedGlyph&);
  67254. };
  67255. juce_UseDebuggingNewOperator
  67256. private:
  67257. OwnedArray <CachedGlyph> glyphs;
  67258. int accessCounter, hits, misses;
  67259. GlyphCache (const GlyphCache&);
  67260. const GlyphCache& operator= (const GlyphCache&);
  67261. };
  67262. juce_ImplementSingleton_SingleThreaded (GlyphCache);
  67263. void LowLevelGraphicsSoftwareRenderer::setFont (const Font& newFont)
  67264. {
  67265. currentState->font = newFont;
  67266. }
  67267. const Font LowLevelGraphicsSoftwareRenderer::getFont()
  67268. {
  67269. return currentState->font;
  67270. }
  67271. void LowLevelGraphicsSoftwareRenderer::drawGlyph (int glyphNumber, const AffineTransform& transform)
  67272. {
  67273. Font& f = currentState->font;
  67274. if (transform.isOnlyTranslation())
  67275. {
  67276. GlyphCache::getInstance()->drawGlyph (*currentState, image, f, glyphNumber,
  67277. transform.getTranslationX() + (float) currentState->xOffset,
  67278. transform.getTranslationY() + (float) currentState->yOffset);
  67279. }
  67280. else
  67281. {
  67282. Path p;
  67283. f.getTypeface()->getOutlineForGlyph (glyphNumber, p);
  67284. fillPath (p, AffineTransform::scale (f.getHeight() * f.getHorizontalScale(), f.getHeight()).followedBy (transform));
  67285. }
  67286. }
  67287. #if JUCE_MSVC
  67288. #pragma warning (pop)
  67289. #endif
  67290. END_JUCE_NAMESPACE
  67291. /*** End of inlined file: juce_LowLevelGraphicsSoftwareRenderer.cpp ***/
  67292. /*** Start of inlined file: juce_RectanglePlacement.cpp ***/
  67293. BEGIN_JUCE_NAMESPACE
  67294. RectanglePlacement::RectanglePlacement (const RectanglePlacement& other) throw()
  67295. : flags (other.flags)
  67296. {
  67297. }
  67298. const RectanglePlacement& RectanglePlacement::operator= (const RectanglePlacement& other) throw()
  67299. {
  67300. flags = other.flags;
  67301. return *this;
  67302. }
  67303. void RectanglePlacement::applyTo (double& x, double& y,
  67304. double& w, double& h,
  67305. const double dx, const double dy,
  67306. const double dw, const double dh) const throw()
  67307. {
  67308. if (w == 0 || h == 0)
  67309. return;
  67310. if ((flags & stretchToFit) != 0)
  67311. {
  67312. x = dx;
  67313. y = dy;
  67314. w = dw;
  67315. h = dh;
  67316. }
  67317. else
  67318. {
  67319. double scale = (flags & fillDestination) != 0 ? jmax (dw / w, dh / h)
  67320. : jmin (dw / w, dh / h);
  67321. if ((flags & onlyReduceInSize) != 0)
  67322. scale = jmin (scale, 1.0);
  67323. if ((flags & onlyIncreaseInSize) != 0)
  67324. scale = jmax (scale, 1.0);
  67325. w *= scale;
  67326. h *= scale;
  67327. if ((flags & xLeft) != 0)
  67328. x = dx;
  67329. else if ((flags & xRight) != 0)
  67330. x = dx + dw - w;
  67331. else
  67332. x = dx + (dw - w) * 0.5;
  67333. if ((flags & yTop) != 0)
  67334. y = dy;
  67335. else if ((flags & yBottom) != 0)
  67336. y = dy + dh - h;
  67337. else
  67338. y = dy + (dh - h) * 0.5;
  67339. }
  67340. }
  67341. const AffineTransform RectanglePlacement::getTransformToFit (float x, float y,
  67342. float w, float h,
  67343. const float dx, const float dy,
  67344. const float dw, const float dh) const throw()
  67345. {
  67346. if (w == 0 || h == 0)
  67347. return AffineTransform::identity;
  67348. const float scaleX = dw / w;
  67349. const float scaleY = dh / h;
  67350. if ((flags & stretchToFit) != 0)
  67351. return AffineTransform::translation (-x, -y)
  67352. .scaled (scaleX, scaleY)
  67353. .translated (dx, dy);
  67354. float scale = (flags & fillDestination) != 0 ? jmax (scaleX, scaleY)
  67355. : jmin (scaleX, scaleY);
  67356. if ((flags & onlyReduceInSize) != 0)
  67357. scale = jmin (scale, 1.0f);
  67358. if ((flags & onlyIncreaseInSize) != 0)
  67359. scale = jmax (scale, 1.0f);
  67360. w *= scale;
  67361. h *= scale;
  67362. float newX = dx;
  67363. if ((flags & xRight) != 0)
  67364. newX += dw - w; // right
  67365. else if ((flags & xLeft) == 0)
  67366. newX += (dw - w) / 2.0f; // centre
  67367. float newY = dy;
  67368. if ((flags & yBottom) != 0)
  67369. newY += dh - h; // bottom
  67370. else if ((flags & yTop) == 0)
  67371. newY += (dh - h) / 2.0f; // centre
  67372. return AffineTransform::translation (-x, -y)
  67373. .scaled (scale, scale)
  67374. .translated (newX, newY);
  67375. }
  67376. END_JUCE_NAMESPACE
  67377. /*** End of inlined file: juce_RectanglePlacement.cpp ***/
  67378. /*** Start of inlined file: juce_Drawable.cpp ***/
  67379. BEGIN_JUCE_NAMESPACE
  67380. Drawable::RenderingContext::RenderingContext (Graphics& g_,
  67381. const AffineTransform& transform_,
  67382. const float opacity_) throw()
  67383. : g (g_),
  67384. transform (transform_),
  67385. opacity (opacity_)
  67386. {
  67387. }
  67388. Drawable::Drawable()
  67389. {
  67390. }
  67391. Drawable::~Drawable()
  67392. {
  67393. }
  67394. void Drawable::draw (Graphics& g, const float opacity,
  67395. const AffineTransform& transform) const
  67396. {
  67397. render (RenderingContext (g, transform, opacity));
  67398. }
  67399. void Drawable::drawAt (Graphics& g, const float x, const float y, const float opacity) const
  67400. {
  67401. draw (g, opacity, AffineTransform::translation (x, y));
  67402. }
  67403. void Drawable::drawWithin (Graphics& g,
  67404. const int destX,
  67405. const int destY,
  67406. const int destW,
  67407. const int destH,
  67408. const RectanglePlacement& placement,
  67409. const float opacity) const
  67410. {
  67411. if (destW > 0 && destH > 0)
  67412. {
  67413. Rectangle<float> bounds (getBounds());
  67414. draw (g, opacity,
  67415. placement.getTransformToFit (bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight(),
  67416. (float) destX, (float) destY,
  67417. (float) destW, (float) destH));
  67418. }
  67419. }
  67420. Drawable* Drawable::createFromImageData (const void* data, const size_t numBytes)
  67421. {
  67422. Drawable* result = 0;
  67423. Image* const image = ImageFileFormat::loadFrom (data, (int) numBytes);
  67424. if (image != 0)
  67425. {
  67426. DrawableImage* const di = new DrawableImage();
  67427. di->setImage (image, true);
  67428. result = di;
  67429. }
  67430. else
  67431. {
  67432. const String asString (String::createStringFromData (data, (int) numBytes));
  67433. XmlDocument doc (asString);
  67434. ScopedPointer <XmlElement> outer (doc.getDocumentElement (true));
  67435. if (outer != 0 && outer->hasTagName (T("svg")))
  67436. {
  67437. ScopedPointer <XmlElement> svg (doc.getDocumentElement());
  67438. if (svg != 0)
  67439. result = Drawable::createFromSVG (*svg);
  67440. }
  67441. }
  67442. return result;
  67443. }
  67444. Drawable* Drawable::createFromImageDataStream (InputStream& dataSource)
  67445. {
  67446. MemoryBlock mb;
  67447. dataSource.readIntoMemoryBlock (mb);
  67448. return createFromImageData (mb.getData(), mb.getSize());
  67449. }
  67450. Drawable* Drawable::createFromImageFile (const File& file)
  67451. {
  67452. const ScopedPointer <FileInputStream> fin (file.createInputStream());
  67453. return fin != 0 ? createFromImageDataStream (*fin) : 0;
  67454. }
  67455. Drawable* Drawable::createFromValueTree (const ValueTree& tree) throw()
  67456. {
  67457. Drawable* d = DrawablePath::createFromValueTree (tree);
  67458. if (d == 0)
  67459. {
  67460. d = DrawableComposite::createFromValueTree (tree);
  67461. if (d == 0)
  67462. {
  67463. d = DrawableImage::createFromValueTree (tree);
  67464. if (d == 0)
  67465. d = DrawableText::createFromValueTree (tree);
  67466. }
  67467. }
  67468. return d;
  67469. }
  67470. END_JUCE_NAMESPACE
  67471. /*** End of inlined file: juce_Drawable.cpp ***/
  67472. /*** Start of inlined file: juce_DrawableComposite.cpp ***/
  67473. BEGIN_JUCE_NAMESPACE
  67474. DrawableComposite::DrawableComposite()
  67475. {
  67476. }
  67477. DrawableComposite::~DrawableComposite()
  67478. {
  67479. }
  67480. void DrawableComposite::insertDrawable (Drawable* drawable,
  67481. const AffineTransform& transform,
  67482. const int index)
  67483. {
  67484. if (drawable != 0)
  67485. {
  67486. if (! drawables.contains (drawable))
  67487. {
  67488. drawables.insert (index, drawable);
  67489. if (transform.isIdentity())
  67490. transforms.insert (index, 0);
  67491. else
  67492. transforms.insert (index, new AffineTransform (transform));
  67493. }
  67494. else
  67495. {
  67496. jassertfalse // trying to add a drawable that's already in here!
  67497. }
  67498. }
  67499. }
  67500. void DrawableComposite::insertDrawable (const Drawable& drawable,
  67501. const AffineTransform& transform,
  67502. const int index)
  67503. {
  67504. insertDrawable (drawable.createCopy(), transform, index);
  67505. }
  67506. void DrawableComposite::removeDrawable (const int index, const bool deleteDrawable)
  67507. {
  67508. drawables.remove (index, deleteDrawable);
  67509. transforms.remove (index);
  67510. }
  67511. void DrawableComposite::bringToFront (const int index)
  67512. {
  67513. if (index >= 0 && index < drawables.size() - 1)
  67514. {
  67515. drawables.move (index, -1);
  67516. transforms.move (index, -1);
  67517. }
  67518. }
  67519. void DrawableComposite::render (const Drawable::RenderingContext& context) const
  67520. {
  67521. if (drawables.size() > 0 && context.opacity > 0)
  67522. {
  67523. if (context.opacity >= 1.0f || drawables.size() == 1)
  67524. {
  67525. Drawable::RenderingContext contextCopy (context);
  67526. for (int i = 0; i < drawables.size(); ++i)
  67527. {
  67528. const AffineTransform* const t = transforms.getUnchecked(i);
  67529. contextCopy.transform = (t == 0) ? context.transform
  67530. : t->followedBy (context.transform);
  67531. drawables.getUnchecked(i)->render (contextCopy);
  67532. }
  67533. }
  67534. else
  67535. {
  67536. // To correctly render a whole composite layer with an overall transparency,
  67537. // we need to render everything opaquely into a temp buffer, then blend that
  67538. // with the target opacity...
  67539. const Rectangle<int> clipBounds (context.g.getClipBounds());
  67540. Image tempImage (Image::ARGB, clipBounds.getWidth(), clipBounds.getHeight(), true);
  67541. {
  67542. Graphics tempG (tempImage);
  67543. tempG.setOrigin (-clipBounds.getX(), -clipBounds.getY());
  67544. Drawable::RenderingContext tempContext (tempG, context.transform, 1.0f);
  67545. render (tempContext);
  67546. }
  67547. context.g.setOpacity (context.opacity);
  67548. context.g.drawImageAt (&tempImage, clipBounds.getX(), clipBounds.getY());
  67549. }
  67550. }
  67551. }
  67552. const Rectangle<float> DrawableComposite::getBounds() const
  67553. {
  67554. Rectangle<float> bounds;
  67555. for (int i = 0; i < drawables.size(); ++i)
  67556. {
  67557. const Drawable* const d = drawables.getUnchecked(i);
  67558. const AffineTransform* const t = transforms.getUnchecked(i);
  67559. bounds = bounds.getUnion (t == 0 ? d->getBounds()
  67560. : d->getBounds().transformed (*t));
  67561. }
  67562. return bounds;
  67563. }
  67564. bool DrawableComposite::hitTest (float x, float y) const
  67565. {
  67566. for (int i = 0; i < drawables.size(); ++i)
  67567. {
  67568. float tx = x;
  67569. float ty = y;
  67570. const AffineTransform* const t = transforms.getUnchecked(i);
  67571. if (t != 0)
  67572. t->inverted().transformPoint (tx, ty);
  67573. if (drawables.getUnchecked(i)->hitTest (tx, ty))
  67574. return true;
  67575. }
  67576. return false;
  67577. }
  67578. Drawable* DrawableComposite::createCopy() const
  67579. {
  67580. DrawableComposite* const dc = new DrawableComposite();
  67581. for (int i = 0; i < drawables.size(); ++i)
  67582. {
  67583. dc->drawables.add (drawables.getUnchecked(i)->createCopy());
  67584. const AffineTransform* const t = transforms.getUnchecked(i);
  67585. dc->transforms.add (t != 0 ? new AffineTransform (*t) : 0);
  67586. }
  67587. return dc;
  67588. }
  67589. ValueTree DrawableComposite::createValueTree() const throw()
  67590. {
  67591. ValueTree v (T("Group"));
  67592. if (getName().isNotEmpty())
  67593. v.setProperty ("id", getName(), 0);
  67594. for (int i = 0; i < drawables.size(); ++i)
  67595. {
  67596. Drawable* const d = drawables.getUnchecked(i);
  67597. ValueTree child (d->createValueTree());
  67598. AffineTransform* transform = transforms.getUnchecked(i);
  67599. if (transform != 0)
  67600. {
  67601. String t;
  67602. t << transform->mat00 << " " << transform->mat01 << " " << transform->mat02 << " "
  67603. << transform->mat10 << " " << transform->mat11 << " " << transform->mat12;
  67604. child.setProperty ("transform", t, 0);
  67605. }
  67606. v.addChild (child, -1, 0);
  67607. }
  67608. return v;
  67609. }
  67610. DrawableComposite* DrawableComposite::createFromValueTree (const ValueTree& tree) throw()
  67611. {
  67612. if (! tree.hasType ("Group"))
  67613. return 0;
  67614. DrawableComposite* dc = new DrawableComposite();
  67615. dc->setName (tree ["id"]);
  67616. for (int i = 0; i < tree.getNumChildren(); ++i)
  67617. {
  67618. ValueTree childTree (tree.getChild (i));
  67619. Drawable* d = Drawable::createFromValueTree (childTree);
  67620. if (d != 0)
  67621. {
  67622. AffineTransform transform;
  67623. const String transformAtt (childTree ["transform"].toString());
  67624. if (transformAtt.isNotEmpty())
  67625. {
  67626. StringArray tokens;
  67627. tokens.addTokens (transformAtt.trim(), false);
  67628. tokens.removeEmptyStrings (true);
  67629. if (tokens.size() == 6)
  67630. {
  67631. float f[6];
  67632. for (int j = 0; j < 6; ++j)
  67633. f[j] = (float) tokens[j].getDoubleValue();
  67634. transform = AffineTransform (f[0], f[1], f[2], f[3], f[4], f[5]);
  67635. }
  67636. }
  67637. dc->insertDrawable (d, transform);
  67638. }
  67639. }
  67640. return dc;
  67641. }
  67642. END_JUCE_NAMESPACE
  67643. /*** End of inlined file: juce_DrawableComposite.cpp ***/
  67644. /*** Start of inlined file: juce_DrawableImage.cpp ***/
  67645. BEGIN_JUCE_NAMESPACE
  67646. DrawableImage::DrawableImage()
  67647. : image (0),
  67648. canDeleteImage (false),
  67649. opacity (1.0f),
  67650. overlayColour (0x00000000)
  67651. {
  67652. }
  67653. DrawableImage::~DrawableImage()
  67654. {
  67655. clearImage();
  67656. }
  67657. void DrawableImage::clearImage()
  67658. {
  67659. if (canDeleteImage && image != 0)
  67660. ImageCache::releaseOrDelete (image);
  67661. image = 0;
  67662. }
  67663. void DrawableImage::setImage (const Image& imageToCopy)
  67664. {
  67665. clearImage();
  67666. image = new Image (imageToCopy);
  67667. canDeleteImage = true;
  67668. }
  67669. void DrawableImage::setImage (Image* imageToUse,
  67670. const bool releaseWhenNotNeeded)
  67671. {
  67672. clearImage();
  67673. image = imageToUse;
  67674. canDeleteImage = releaseWhenNotNeeded;
  67675. }
  67676. void DrawableImage::setOpacity (const float newOpacity)
  67677. {
  67678. opacity = newOpacity;
  67679. }
  67680. void DrawableImage::setOverlayColour (const Colour& newOverlayColour)
  67681. {
  67682. overlayColour = newOverlayColour;
  67683. }
  67684. void DrawableImage::render (const Drawable::RenderingContext& context) const
  67685. {
  67686. if (image != 0)
  67687. {
  67688. if (opacity > 0.0f && ! overlayColour.isOpaque())
  67689. {
  67690. context.g.setOpacity (context.opacity * opacity);
  67691. context.g.drawImageTransformed (image, image->getBounds(),
  67692. context.transform, false);
  67693. }
  67694. if (! overlayColour.isTransparent())
  67695. {
  67696. context.g.setColour (overlayColour.withMultipliedAlpha (context.opacity));
  67697. context.g.drawImageTransformed (image, image->getBounds(),
  67698. context.transform, true);
  67699. }
  67700. }
  67701. }
  67702. const Rectangle<float> DrawableImage::getBounds() const
  67703. {
  67704. if (image == 0)
  67705. return Rectangle<float>();
  67706. return Rectangle<float> (0, 0, (float) image->getWidth(), (float) image->getHeight());
  67707. }
  67708. bool DrawableImage::hitTest (float x, float y) const
  67709. {
  67710. return image != 0
  67711. && x >= 0.0f
  67712. && y >= 0.0f
  67713. && x < image->getWidth()
  67714. && y < image->getHeight()
  67715. && image->getPixelAt (roundToInt (x), roundToInt (y)).getAlpha() >= 127;
  67716. }
  67717. Drawable* DrawableImage::createCopy() const
  67718. {
  67719. DrawableImage* const di = new DrawableImage();
  67720. di->opacity = opacity;
  67721. di->overlayColour = overlayColour;
  67722. if (image != 0)
  67723. {
  67724. if ((! canDeleteImage) || ! ImageCache::isImageInCache (image))
  67725. {
  67726. di->setImage (*image);
  67727. }
  67728. else
  67729. {
  67730. ImageCache::incReferenceCount (image);
  67731. di->setImage (image, true);
  67732. }
  67733. }
  67734. return di;
  67735. }
  67736. ValueTree DrawableImage::createValueTree() const throw()
  67737. {
  67738. ValueTree v (T("Image"));
  67739. if (getName().isNotEmpty())
  67740. v.setProperty ("id", getName(), 0);
  67741. if (opacity < 1.0f)
  67742. v.setProperty ("opacity", (double) opacity, 0);
  67743. if (! overlayColour.isTransparent())
  67744. v.setProperty ("overlay", String::toHexString ((int) overlayColour.getARGB()), 0);
  67745. if (image != 0)
  67746. {
  67747. MemoryOutputStream imageData;
  67748. PNGImageFormat pngFormat;
  67749. if (pngFormat.writeImageToStream (*image, imageData))
  67750. {
  67751. String base64 (MemoryBlock (imageData.getData(), imageData.getDataSize()).toBase64Encoding());
  67752. for (int i = (base64.length() & ~127); i >= 0; i -= 128)
  67753. base64 = base64.substring (0, i) + "\n" + base64.substring (i);
  67754. v.setProperty ("data", base64, 0);
  67755. }
  67756. }
  67757. return v;
  67758. }
  67759. DrawableImage* DrawableImage::createFromValueTree (const ValueTree& tree) throw()
  67760. {
  67761. if (! tree.hasType ("Image"))
  67762. return 0;
  67763. DrawableImage* di = new DrawableImage();
  67764. di->setName (tree ["id"]);
  67765. di->opacity = tree.hasProperty ("opacity") ? (float) tree ["opacity"] : 1.0f;
  67766. di->overlayColour = Colour (tree ["overlay"].toString().getHexValue32());
  67767. MemoryBlock imageData;
  67768. if (imageData.fromBase64Encoding (tree ["data"]))
  67769. {
  67770. Image* const im = ImageFileFormat::loadFrom (imageData.getData(), (int) imageData.getSize());
  67771. if (im == 0)
  67772. return false;
  67773. di->setImage (im, true);
  67774. }
  67775. return di;
  67776. }
  67777. END_JUCE_NAMESPACE
  67778. /*** End of inlined file: juce_DrawableImage.cpp ***/
  67779. /*** Start of inlined file: juce_DrawablePath.cpp ***/
  67780. BEGIN_JUCE_NAMESPACE
  67781. DrawablePath::DrawablePath()
  67782. : mainFill (FillType (Colours::black)),
  67783. strokeFill (FillType (Colours::transparentBlack)),
  67784. strokeType (0.0f)
  67785. {
  67786. }
  67787. DrawablePath::~DrawablePath()
  67788. {
  67789. }
  67790. void DrawablePath::setPath (const Path& newPath) throw()
  67791. {
  67792. path = newPath;
  67793. updateOutline();
  67794. }
  67795. void DrawablePath::setFill (const FillType& newFill) throw()
  67796. {
  67797. mainFill = newFill;
  67798. }
  67799. void DrawablePath::setStrokeFill (const FillType& newFill) throw()
  67800. {
  67801. strokeFill = newFill;
  67802. }
  67803. void DrawablePath::setStrokeType (const PathStrokeType& newStrokeType) throw()
  67804. {
  67805. strokeType = newStrokeType;
  67806. updateOutline();
  67807. }
  67808. void DrawablePath::setStrokeThickness (const float newThickness) throw()
  67809. {
  67810. setStrokeType (PathStrokeType (newThickness, strokeType.getJointStyle(), strokeType.getEndStyle()));
  67811. }
  67812. void DrawablePath::render (const Drawable::RenderingContext& context) const
  67813. {
  67814. {
  67815. FillType f (mainFill);
  67816. if (f.isGradient())
  67817. f.gradient->multiplyOpacity (context.opacity);
  67818. f.transform = f.transform.followedBy (context.transform);
  67819. context.g.setFillType (f);
  67820. context.g.fillPath (path, context.transform);
  67821. }
  67822. if (strokeType.getStrokeThickness() > 0.0f)
  67823. {
  67824. FillType f (strokeFill);
  67825. if (f.isGradient())
  67826. f.gradient->multiplyOpacity (context.opacity);
  67827. f.transform = f.transform.followedBy (context.transform);
  67828. context.g.setFillType (f);
  67829. context.g.fillPath (stroke, context.transform);
  67830. }
  67831. }
  67832. void DrawablePath::updateOutline()
  67833. {
  67834. stroke.clear();
  67835. strokeType.createStrokedPath (stroke, path, AffineTransform::identity, 4.0f);
  67836. }
  67837. const Rectangle<float> DrawablePath::getBounds() const
  67838. {
  67839. if (strokeType.getStrokeThickness() > 0.0f)
  67840. return stroke.getBounds();
  67841. else
  67842. return path.getBounds();
  67843. }
  67844. bool DrawablePath::hitTest (float x, float y) const
  67845. {
  67846. return path.contains (x, y)
  67847. || stroke.contains (x, y);
  67848. }
  67849. Drawable* DrawablePath::createCopy() const
  67850. {
  67851. DrawablePath* const dp = new DrawablePath();
  67852. dp->path = path;
  67853. dp->stroke = stroke;
  67854. dp->mainFill = mainFill;
  67855. dp->strokeFill = strokeFill;
  67856. dp->strokeType = strokeType;
  67857. return dp;
  67858. }
  67859. static const FillType readFillTypeFromTree (const ValueTree& v)
  67860. {
  67861. const String type (v["type"].toString());
  67862. if (type.equalsIgnoreCase (T("solid")))
  67863. {
  67864. const String colour (v ["colour"].toString());
  67865. return FillType (Colour (colour.isEmpty() ? (uint32) 0xff000000
  67866. : (uint32) colour.getHexValue32()));
  67867. }
  67868. else if (type.equalsIgnoreCase ("gradient"))
  67869. {
  67870. ColourGradient g;
  67871. g.x1 = v["x1"];
  67872. g.y1 = v["y1"];
  67873. g.x2 = v["x2"];
  67874. g.y2 = v["y2"];
  67875. g.isRadial = v["radial"];
  67876. StringArray colours;
  67877. colours.addTokens (v["colours"].toString(), false);
  67878. for (int i = 0; i < colours.size() / 2; ++i)
  67879. g.addColour (colours[i * 2].getDoubleValue(),
  67880. Colour ((uint32) colours[i * 2 + 1].getHexValue32()));
  67881. return FillType (g);
  67882. }
  67883. jassertfalse
  67884. return FillType();
  67885. }
  67886. static ValueTree createTreeForFillType (const String& tagName, const FillType& fillType)
  67887. {
  67888. ValueTree v (tagName);
  67889. if (fillType.isColour())
  67890. {
  67891. v.setProperty ("type", T("solid"), 0);
  67892. v.setProperty ("colour", String::toHexString ((int) fillType.colour.getARGB()), 0);
  67893. }
  67894. else if (fillType.isGradient())
  67895. {
  67896. v.setProperty ("type", T("gradient"), 0);
  67897. v.setProperty ("x1", fillType.gradient->x1, 0);
  67898. v.setProperty ("y1", fillType.gradient->y1, 0);
  67899. v.setProperty ("x2", fillType.gradient->x2, 0);
  67900. v.setProperty ("y2", fillType.gradient->y2, 0);
  67901. v.setProperty ("radial", fillType.gradient->isRadial, 0);
  67902. String s;
  67903. for (int i = 0; i < fillType.gradient->getNumColours(); ++i)
  67904. s << " " << fillType.gradient->getColourPosition (i)
  67905. << " " << String::toHexString ((int) fillType.gradient->getColour(i).getARGB());
  67906. v.setProperty ("colours", s.trimStart(), 0);
  67907. }
  67908. else
  67909. {
  67910. jassertfalse //xxx
  67911. }
  67912. return v;
  67913. }
  67914. ValueTree DrawablePath::createValueTree() const throw()
  67915. {
  67916. ValueTree v (T("Path"));
  67917. v.addChild (createTreeForFillType (T("fill"), mainFill), -1, 0);
  67918. v.addChild (createTreeForFillType (T("stroke"), strokeFill), -1, 0);
  67919. if (getName().isNotEmpty())
  67920. v.setProperty ("id", getName(), 0);
  67921. v.setProperty ("strokeWidth", (double) strokeType.getStrokeThickness(), 0);
  67922. v.setProperty ("jointStyle", strokeType.getJointStyle() == PathStrokeType::mitered
  67923. ? T("miter") : (strokeType.getJointStyle() == PathStrokeType::curved ? T("curved") : T("bevel")), 0);
  67924. v.setProperty ("capStyle", strokeType.getEndStyle() == PathStrokeType::butt
  67925. ? T("butt") : (strokeType.getEndStyle() == PathStrokeType::square ? T("square") : T("round")), 0);
  67926. v.setProperty ("path", path.toString(), 0);
  67927. return v;
  67928. }
  67929. DrawablePath* DrawablePath::createFromValueTree (const ValueTree& tree) throw()
  67930. {
  67931. if (! tree.hasType ("Path"))
  67932. return 0;
  67933. DrawablePath* p = new DrawablePath();
  67934. p->setName (tree ["id"]);
  67935. p->mainFill = readFillTypeFromTree (tree.getChildWithName (T("fill")));
  67936. p->strokeFill = readFillTypeFromTree (tree.getChildWithName (T("stroke")));
  67937. const String jointStyle (tree ["jointStyle"].toString());
  67938. const String endStyle (tree ["capStyle"].toString());
  67939. p->strokeType
  67940. = PathStrokeType (tree ["strokeWidth"],
  67941. jointStyle.equalsIgnoreCase (T("curved")) ? PathStrokeType::curved
  67942. : (jointStyle.equalsIgnoreCase (T("bevel")) ? PathStrokeType::beveled
  67943. : PathStrokeType::mitered),
  67944. endStyle.equalsIgnoreCase (T("square")) ? PathStrokeType::square
  67945. : (endStyle.equalsIgnoreCase (T("round")) ? PathStrokeType::rounded
  67946. : PathStrokeType::butt));
  67947. p->path.clear();
  67948. p->path.restoreFromString (tree ["path"]);
  67949. p->updateOutline();
  67950. return p;
  67951. }
  67952. END_JUCE_NAMESPACE
  67953. /*** End of inlined file: juce_DrawablePath.cpp ***/
  67954. /*** Start of inlined file: juce_DrawableText.cpp ***/
  67955. BEGIN_JUCE_NAMESPACE
  67956. DrawableText::DrawableText()
  67957. : colour (Colours::white)
  67958. {
  67959. }
  67960. DrawableText::~DrawableText()
  67961. {
  67962. }
  67963. void DrawableText::setText (const GlyphArrangement& newText)
  67964. {
  67965. text = newText;
  67966. }
  67967. void DrawableText::setText (const String& newText, const Font& fontToUse)
  67968. {
  67969. text.clear();
  67970. text.addLineOfText (fontToUse, newText, 0.0f, 0.0f);
  67971. }
  67972. void DrawableText::setColour (const Colour& newColour)
  67973. {
  67974. colour = newColour;
  67975. }
  67976. void DrawableText::render (const Drawable::RenderingContext& context) const
  67977. {
  67978. context.g.setColour (colour.withMultipliedAlpha (context.opacity));
  67979. text.draw (context.g, context.transform);
  67980. }
  67981. const Rectangle<float> DrawableText::getBounds() const
  67982. {
  67983. float x, y, w, h;
  67984. text.getBoundingBox (0, -1, x, y, w, h, false); // (really returns top, left, bottom, right)
  67985. w -= x;
  67986. h -= y;
  67987. return Rectangle<float> (x, y, w, h);
  67988. }
  67989. bool DrawableText::hitTest (float x, float y) const
  67990. {
  67991. return text.findGlyphIndexAt (x, y) >= 0;
  67992. }
  67993. Drawable* DrawableText::createCopy() const
  67994. {
  67995. DrawableText* const dt = new DrawableText();
  67996. dt->text = text;
  67997. dt->colour = colour;
  67998. return dt;
  67999. }
  68000. ValueTree DrawableText::createValueTree() const throw()
  68001. {
  68002. ValueTree v (T("Text"));
  68003. if (getName().isNotEmpty())
  68004. v.setProperty ("id", getName(), 0);
  68005. jassertfalse // xxx not finished!
  68006. return v;
  68007. }
  68008. DrawableText* DrawableText::createFromValueTree (const ValueTree& tree) throw()
  68009. {
  68010. if (! tree.hasType ("Text"))
  68011. return 0;
  68012. DrawableText* dt = new DrawableText();
  68013. dt->setName (tree ["id"]);
  68014. jassertfalse // xxx not finished!
  68015. return dt;
  68016. }
  68017. END_JUCE_NAMESPACE
  68018. /*** End of inlined file: juce_DrawableText.cpp ***/
  68019. /*** Start of inlined file: juce_SVGParser.cpp ***/
  68020. BEGIN_JUCE_NAMESPACE
  68021. class SVGState
  68022. {
  68023. public:
  68024. SVGState (const XmlElement* const topLevel)
  68025. : topLevelXml (topLevel),
  68026. elementX (0), elementY (0),
  68027. width (512), height (512),
  68028. viewBoxW (0), viewBoxH (0)
  68029. {
  68030. }
  68031. ~SVGState()
  68032. {
  68033. }
  68034. Drawable* parseSVGElement (const XmlElement& xml)
  68035. {
  68036. if (! xml.hasTagName (T("svg")))
  68037. return 0;
  68038. DrawableComposite* const drawable = new DrawableComposite();
  68039. drawable->setName (xml.getStringAttribute (T("id")));
  68040. SVGState newState (*this);
  68041. if (xml.hasAttribute (T("transform")))
  68042. newState.addTransform (xml);
  68043. newState.elementX = getCoordLength (xml.getStringAttribute (T("x"), String (newState.elementX)), viewBoxW);
  68044. newState.elementY = getCoordLength (xml.getStringAttribute (T("y"), String (newState.elementY)), viewBoxH);
  68045. newState.width = getCoordLength (xml.getStringAttribute (T("width"), String (newState.width)), viewBoxW);
  68046. newState.height = getCoordLength (xml.getStringAttribute (T("height"), String (newState.height)), viewBoxH);
  68047. if (xml.hasAttribute (T("viewBox")))
  68048. {
  68049. const String viewParams (xml.getStringAttribute (T("viewBox")));
  68050. int i = 0;
  68051. float vx, vy, vw, vh;
  68052. if (parseCoords (viewParams, vx, vy, i, true)
  68053. && parseCoords (viewParams, vw, vh, i, true)
  68054. && vw > 0
  68055. && vh > 0)
  68056. {
  68057. newState.viewBoxW = vw;
  68058. newState.viewBoxH = vh;
  68059. int placementFlags = 0;
  68060. const String aspect (xml.getStringAttribute (T("preserveAspectRatio")));
  68061. if (aspect.containsIgnoreCase (T("none")))
  68062. {
  68063. placementFlags = RectanglePlacement::stretchToFit;
  68064. }
  68065. else
  68066. {
  68067. if (aspect.containsIgnoreCase (T("slice")))
  68068. placementFlags |= RectanglePlacement::fillDestination;
  68069. if (aspect.containsIgnoreCase (T("xMin")))
  68070. placementFlags |= RectanglePlacement::xLeft;
  68071. else if (aspect.containsIgnoreCase (T("xMax")))
  68072. placementFlags |= RectanglePlacement::xRight;
  68073. else
  68074. placementFlags |= RectanglePlacement::xMid;
  68075. if (aspect.containsIgnoreCase (T("yMin")))
  68076. placementFlags |= RectanglePlacement::yTop;
  68077. else if (aspect.containsIgnoreCase (T("yMax")))
  68078. placementFlags |= RectanglePlacement::yBottom;
  68079. else
  68080. placementFlags |= RectanglePlacement::yMid;
  68081. }
  68082. const RectanglePlacement placement (placementFlags);
  68083. newState.transform
  68084. = placement.getTransformToFit (vx, vy, vw, vh,
  68085. 0.0f, 0.0f, newState.width, newState.height)
  68086. .followedBy (newState.transform);
  68087. }
  68088. }
  68089. else
  68090. {
  68091. if (viewBoxW == 0)
  68092. newState.viewBoxW = newState.width;
  68093. if (viewBoxH == 0)
  68094. newState.viewBoxH = newState.height;
  68095. }
  68096. newState.parseSubElements (xml, drawable);
  68097. return drawable;
  68098. }
  68099. private:
  68100. const XmlElement* const topLevelXml;
  68101. float elementX, elementY, width, height, viewBoxW, viewBoxH;
  68102. AffineTransform transform;
  68103. String cssStyleText;
  68104. void parseSubElements (const XmlElement& xml, DrawableComposite* const parentDrawable)
  68105. {
  68106. forEachXmlChildElement (xml, e)
  68107. {
  68108. Drawable* d = 0;
  68109. if (e->hasTagName (T("g")))
  68110. d = parseGroupElement (*e);
  68111. else if (e->hasTagName (T("svg")))
  68112. d = parseSVGElement (*e);
  68113. else if (e->hasTagName (T("path")))
  68114. d = parsePath (*e);
  68115. else if (e->hasTagName (T("rect")))
  68116. d = parseRect (*e);
  68117. else if (e->hasTagName (T("circle")))
  68118. d = parseCircle (*e);
  68119. else if (e->hasTagName (T("ellipse")))
  68120. d = parseEllipse (*e);
  68121. else if (e->hasTagName (T("line")))
  68122. d = parseLine (*e);
  68123. else if (e->hasTagName (T("polyline")))
  68124. d = parsePolygon (*e, true);
  68125. else if (e->hasTagName (T("polygon")))
  68126. d = parsePolygon (*e, false);
  68127. else if (e->hasTagName (T("text")))
  68128. d = parseText (*e);
  68129. else if (e->hasTagName (T("switch")))
  68130. d = parseSwitch (*e);
  68131. else if (e->hasTagName (T("style")))
  68132. parseCSSStyle (*e);
  68133. parentDrawable->insertDrawable (d);
  68134. }
  68135. }
  68136. DrawableComposite* parseSwitch (const XmlElement& xml)
  68137. {
  68138. const XmlElement* const group = xml.getChildByName (T("g"));
  68139. if (group != 0)
  68140. return parseGroupElement (*group);
  68141. return 0;
  68142. }
  68143. DrawableComposite* parseGroupElement (const XmlElement& xml)
  68144. {
  68145. DrawableComposite* const drawable = new DrawableComposite();
  68146. drawable->setName (xml.getStringAttribute (T("id")));
  68147. if (xml.hasAttribute (T("transform")))
  68148. {
  68149. SVGState newState (*this);
  68150. newState.addTransform (xml);
  68151. newState.parseSubElements (xml, drawable);
  68152. }
  68153. else
  68154. {
  68155. parseSubElements (xml, drawable);
  68156. }
  68157. return drawable;
  68158. }
  68159. Drawable* parsePath (const XmlElement& xml) const
  68160. {
  68161. const String d (xml.getStringAttribute (T("d")).trimStart());
  68162. Path path;
  68163. if (getStyleAttribute (&xml, T("fill-rule")).trim().equalsIgnoreCase (T("evenodd")))
  68164. path.setUsingNonZeroWinding (false);
  68165. int index = 0;
  68166. float lastX = 0, lastY = 0;
  68167. float lastX2 = 0, lastY2 = 0;
  68168. tchar lastCommandChar = 0;
  68169. bool carryOn = true;
  68170. const String validCommandChars (T("MmLlHhVvCcSsQqTtAaZz"));
  68171. for (;;)
  68172. {
  68173. float x, y, x2, y2, x3, y3;
  68174. const bool isRelative = (d[index] >= 'a' && d[index] <= 'z');
  68175. if (validCommandChars.containsChar (d[index]))
  68176. lastCommandChar = d [index++];
  68177. switch (lastCommandChar)
  68178. {
  68179. case T('M'):
  68180. case T('m'):
  68181. case T('L'):
  68182. case T('l'):
  68183. if (parseCoords (d, x, y, index, false))
  68184. {
  68185. if (isRelative)
  68186. {
  68187. x += lastX;
  68188. y += lastY;
  68189. }
  68190. if (lastCommandChar == T('M') || lastCommandChar == T('m'))
  68191. path.startNewSubPath (x, y);
  68192. else
  68193. path.lineTo (x, y);
  68194. lastX2 = lastX;
  68195. lastY2 = lastY;
  68196. lastX = x;
  68197. lastY = y;
  68198. }
  68199. else
  68200. {
  68201. ++index;
  68202. }
  68203. break;
  68204. case T('H'):
  68205. case T('h'):
  68206. if (parseCoord (d, x, index, false, true))
  68207. {
  68208. if (isRelative)
  68209. x += lastX;
  68210. path.lineTo (x, lastY);
  68211. lastX2 = lastX;
  68212. lastX = x;
  68213. }
  68214. else
  68215. {
  68216. ++index;
  68217. }
  68218. break;
  68219. case T('V'):
  68220. case T('v'):
  68221. if (parseCoord (d, y, index, false, false))
  68222. {
  68223. if (isRelative)
  68224. y += lastY;
  68225. path.lineTo (lastX, y);
  68226. lastY2 = lastY;
  68227. lastY = y;
  68228. }
  68229. else
  68230. {
  68231. ++index;
  68232. }
  68233. break;
  68234. case T('C'):
  68235. case T('c'):
  68236. if (parseCoords (d, x, y, index, false)
  68237. && parseCoords (d, x2, y2, index, false)
  68238. && parseCoords (d, x3, y3, index, false))
  68239. {
  68240. if (isRelative)
  68241. {
  68242. x += lastX;
  68243. y += lastY;
  68244. x2 += lastX;
  68245. y2 += lastY;
  68246. x3 += lastX;
  68247. y3 += lastY;
  68248. }
  68249. path.cubicTo (x, y, x2, y2, x3, y3);
  68250. lastX2 = x2;
  68251. lastY2 = y2;
  68252. lastX = x3;
  68253. lastY = y3;
  68254. }
  68255. else
  68256. {
  68257. ++index;
  68258. }
  68259. break;
  68260. case T('S'):
  68261. case T('s'):
  68262. if (parseCoords (d, x, y, index, false)
  68263. && parseCoords (d, x3, y3, index, false))
  68264. {
  68265. if (isRelative)
  68266. {
  68267. x += lastX;
  68268. y += lastY;
  68269. x3 += lastX;
  68270. y3 += lastY;
  68271. }
  68272. x2 = lastX + (lastX - lastX2);
  68273. y2 = lastY + (lastY - lastY2);
  68274. path.cubicTo (x2, y2, x, y, x3, y3);
  68275. lastX2 = x;
  68276. lastY2 = y;
  68277. lastX = x3;
  68278. lastY = y3;
  68279. }
  68280. else
  68281. {
  68282. ++index;
  68283. }
  68284. break;
  68285. case T('Q'):
  68286. case T('q'):
  68287. if (parseCoords (d, x, y, index, false)
  68288. && parseCoords (d, x2, y2, index, false))
  68289. {
  68290. if (isRelative)
  68291. {
  68292. x += lastX;
  68293. y += lastY;
  68294. x2 += lastX;
  68295. y2 += lastY;
  68296. }
  68297. path.quadraticTo (x, y, x2, y2);
  68298. lastX2 = x;
  68299. lastY2 = y;
  68300. lastX = x2;
  68301. lastY = y2;
  68302. }
  68303. else
  68304. {
  68305. ++index;
  68306. }
  68307. break;
  68308. case T('T'):
  68309. case T('t'):
  68310. if (parseCoords (d, x, y, index, false))
  68311. {
  68312. if (isRelative)
  68313. {
  68314. x += lastX;
  68315. y += lastY;
  68316. }
  68317. x2 = lastX + (lastX - lastX2);
  68318. y2 = lastY + (lastY - lastY2);
  68319. path.quadraticTo (x2, y2, x, y);
  68320. lastX2 = x2;
  68321. lastY2 = y2;
  68322. lastX = x;
  68323. lastY = y;
  68324. }
  68325. else
  68326. {
  68327. ++index;
  68328. }
  68329. break;
  68330. case T('A'):
  68331. case T('a'):
  68332. if (parseCoords (d, x, y, index, false))
  68333. {
  68334. String num;
  68335. if (parseNextNumber (d, num, index, false))
  68336. {
  68337. const float angle = num.getFloatValue() * (180.0f / float_Pi);
  68338. if (parseNextNumber (d, num, index, false))
  68339. {
  68340. const bool largeArc = num.getIntValue() != 0;
  68341. if (parseNextNumber (d, num, index, false))
  68342. {
  68343. const bool sweep = num.getIntValue() != 0;
  68344. if (parseCoords (d, x2, y2, index, false))
  68345. {
  68346. if (isRelative)
  68347. {
  68348. x2 += lastX;
  68349. y2 += lastY;
  68350. }
  68351. if (lastX != x2 || lastY != y2)
  68352. {
  68353. double centreX, centreY, startAngle, deltaAngle;
  68354. double rx = x, ry = y;
  68355. endpointToCentreParameters (lastX, lastY, x2, y2,
  68356. angle, largeArc, sweep,
  68357. rx, ry, centreX, centreY,
  68358. startAngle, deltaAngle);
  68359. path.addCentredArc ((float) centreX, (float) centreY,
  68360. (float) rx, (float) ry,
  68361. angle, (float) startAngle, (float) (startAngle + deltaAngle),
  68362. false);
  68363. path.lineTo (x2, y2);
  68364. }
  68365. lastX2 = lastX;
  68366. lastY2 = lastY;
  68367. lastX = x2;
  68368. lastY = y2;
  68369. }
  68370. }
  68371. }
  68372. }
  68373. }
  68374. else
  68375. {
  68376. ++index;
  68377. }
  68378. break;
  68379. case T('Z'):
  68380. case T('z'):
  68381. path.closeSubPath();
  68382. while (CharacterFunctions::isWhitespace (d [index]))
  68383. ++index;
  68384. break;
  68385. default:
  68386. carryOn = false;
  68387. break;
  68388. }
  68389. if (! carryOn)
  68390. break;
  68391. }
  68392. return parseShape (xml, path);
  68393. }
  68394. Drawable* parseRect (const XmlElement& xml) const
  68395. {
  68396. Path rect;
  68397. const bool hasRX = xml.hasAttribute (T("rx"));
  68398. const bool hasRY = xml.hasAttribute (T("ry"));
  68399. if (hasRX || hasRY)
  68400. {
  68401. float rx = getCoordLength (xml.getStringAttribute (T("rx")), viewBoxW);
  68402. float ry = getCoordLength (xml.getStringAttribute (T("ry")), viewBoxH);
  68403. if (! hasRX)
  68404. rx = ry;
  68405. else if (! hasRY)
  68406. ry = rx;
  68407. rect.addRoundedRectangle (getCoordLength (xml.getStringAttribute (T("x")), viewBoxW),
  68408. getCoordLength (xml.getStringAttribute (T("y")), viewBoxH),
  68409. getCoordLength (xml.getStringAttribute (T("width")), viewBoxW),
  68410. getCoordLength (xml.getStringAttribute (T("height")), viewBoxH),
  68411. rx, ry);
  68412. }
  68413. else
  68414. {
  68415. rect.addRectangle (getCoordLength (xml.getStringAttribute (T("x")), viewBoxW),
  68416. getCoordLength (xml.getStringAttribute (T("y")), viewBoxH),
  68417. getCoordLength (xml.getStringAttribute (T("width")), viewBoxW),
  68418. getCoordLength (xml.getStringAttribute (T("height")), viewBoxH));
  68419. }
  68420. return parseShape (xml, rect);
  68421. }
  68422. Drawable* parseCircle (const XmlElement& xml) const
  68423. {
  68424. Path circle;
  68425. const float cx = getCoordLength (xml.getStringAttribute (T("cx")), viewBoxW);
  68426. const float cy = getCoordLength (xml.getStringAttribute (T("cy")), viewBoxH);
  68427. const float radius = getCoordLength (xml.getStringAttribute (T("r")), viewBoxW);
  68428. circle.addEllipse (cx - radius, cy - radius, radius * 2.0f, radius * 2.0f);
  68429. return parseShape (xml, circle);
  68430. }
  68431. Drawable* parseEllipse (const XmlElement& xml) const
  68432. {
  68433. Path ellipse;
  68434. const float cx = getCoordLength (xml.getStringAttribute (T("cx")), viewBoxW);
  68435. const float cy = getCoordLength (xml.getStringAttribute (T("cy")), viewBoxH);
  68436. const float radiusX = getCoordLength (xml.getStringAttribute (T("rx")), viewBoxW);
  68437. const float radiusY = getCoordLength (xml.getStringAttribute (T("ry")), viewBoxH);
  68438. ellipse.addEllipse (cx - radiusX, cy - radiusY, radiusX * 2.0f, radiusY * 2.0f);
  68439. return parseShape (xml, ellipse);
  68440. }
  68441. Drawable* parseLine (const XmlElement& xml) const
  68442. {
  68443. Path line;
  68444. const float x1 = getCoordLength (xml.getStringAttribute (T("x1")), viewBoxW);
  68445. const float y1 = getCoordLength (xml.getStringAttribute (T("y1")), viewBoxH);
  68446. const float x2 = getCoordLength (xml.getStringAttribute (T("x2")), viewBoxW);
  68447. const float y2 = getCoordLength (xml.getStringAttribute (T("y2")), viewBoxH);
  68448. line.startNewSubPath (x1, y1);
  68449. line.lineTo (x2, y2);
  68450. return parseShape (xml, line);
  68451. }
  68452. Drawable* parsePolygon (const XmlElement& xml, const bool isPolyline) const
  68453. {
  68454. const String points (xml.getStringAttribute (T("points")));
  68455. Path path;
  68456. int index = 0;
  68457. float x, y;
  68458. if (parseCoords (points, x, y, index, true))
  68459. {
  68460. float firstX = x;
  68461. float firstY = y;
  68462. float lastX = 0, lastY = 0;
  68463. path.startNewSubPath (x, y);
  68464. while (parseCoords (points, x, y, index, true))
  68465. {
  68466. lastX = x;
  68467. lastY = y;
  68468. path.lineTo (x, y);
  68469. }
  68470. if ((! isPolyline) || (firstX == lastX && firstY == lastY))
  68471. path.closeSubPath();
  68472. }
  68473. return parseShape (xml, path);
  68474. }
  68475. Drawable* parseShape (const XmlElement& xml, Path& path,
  68476. const bool shouldParseTransform = true) const
  68477. {
  68478. if (shouldParseTransform && xml.hasAttribute (T("transform")))
  68479. {
  68480. SVGState newState (*this);
  68481. newState.addTransform (xml);
  68482. return newState.parseShape (xml, path, false);
  68483. }
  68484. DrawablePath* dp = new DrawablePath();
  68485. dp->setName (xml.getStringAttribute (T("id")));
  68486. dp->setFill (FillType (Colours::transparentBlack));
  68487. path.applyTransform (transform);
  68488. dp->setPath (path);
  68489. Path::Iterator iter (path);
  68490. bool containsClosedSubPath = false;
  68491. while (iter.next())
  68492. {
  68493. if (iter.elementType == Path::Iterator::closePath)
  68494. {
  68495. containsClosedSubPath = true;
  68496. break;
  68497. }
  68498. }
  68499. dp->setFill (getPathFillType (path,
  68500. getStyleAttribute (&xml, T("fill")),
  68501. getStyleAttribute (&xml, T("fill-opacity")),
  68502. getStyleAttribute (&xml, T("opacity")),
  68503. containsClosedSubPath ? Colours::black
  68504. : Colours::transparentBlack));
  68505. const String strokeType (getStyleAttribute (&xml, T("stroke")));
  68506. if (strokeType.isNotEmpty() && ! strokeType.equalsIgnoreCase (T("none")))
  68507. {
  68508. dp->setStrokeFill (getPathFillType (path, strokeType,
  68509. getStyleAttribute (&xml, T("stroke-opacity")),
  68510. getStyleAttribute (&xml, T("opacity")),
  68511. Colours::transparentBlack));
  68512. dp->setStrokeType (getStrokeFor (&xml));
  68513. }
  68514. return dp;
  68515. }
  68516. const XmlElement* findLinkedElement (const XmlElement* e) const
  68517. {
  68518. const String id (e->getStringAttribute (T("xlink:href")));
  68519. if (! id.startsWithChar (T('#')))
  68520. return 0;
  68521. return findElementForId (topLevelXml, id.substring (1));
  68522. }
  68523. void addGradientStopsIn (ColourGradient& cg, const XmlElement* const fillXml) const
  68524. {
  68525. if (fillXml == 0)
  68526. return;
  68527. forEachXmlChildElementWithTagName (*fillXml, e, T("stop"))
  68528. {
  68529. int index = 0;
  68530. Colour col (parseColour (getStyleAttribute (e, T("stop-color")), index, Colours::black));
  68531. const String opacity (getStyleAttribute (e, T("stop-opacity"), T("1")));
  68532. col = col.withMultipliedAlpha (jlimit (0.0f, 1.0f, opacity.getFloatValue()));
  68533. double offset = e->getDoubleAttribute (T("offset"));
  68534. if (e->getStringAttribute (T("offset")).containsChar (T('%')))
  68535. offset *= 0.01;
  68536. cg.addColour (jlimit (0.0, 1.0, offset), col);
  68537. }
  68538. }
  68539. const FillType getPathFillType (const Path& path,
  68540. const String& fill,
  68541. const String& fillOpacity,
  68542. const String& overallOpacity,
  68543. const Colour& defaultColour) const
  68544. {
  68545. float opacity = 1.0f;
  68546. if (overallOpacity.isNotEmpty())
  68547. opacity = jlimit (0.0f, 1.0f, overallOpacity.getFloatValue());
  68548. if (fillOpacity.isNotEmpty())
  68549. opacity *= (jlimit (0.0f, 1.0f, fillOpacity.getFloatValue()));
  68550. if (fill.startsWithIgnoreCase (T("url")))
  68551. {
  68552. const String id (fill.fromFirstOccurrenceOf (T("#"), false, false)
  68553. .upToLastOccurrenceOf (T(")"), false, false).trim());
  68554. const XmlElement* const fillXml = findElementForId (topLevelXml, id);
  68555. if (fillXml != 0
  68556. && (fillXml->hasTagName (T("linearGradient"))
  68557. || fillXml->hasTagName (T("radialGradient"))))
  68558. {
  68559. const XmlElement* inheritedFrom = findLinkedElement (fillXml);
  68560. ColourGradient gradient;
  68561. addGradientStopsIn (gradient, inheritedFrom);
  68562. addGradientStopsIn (gradient, fillXml);
  68563. if (gradient.getNumColours() > 0)
  68564. {
  68565. gradient.addColour (0.0, gradient.getColour (0));
  68566. gradient.addColour (1.0, gradient.getColour (gradient.getNumColours() - 1));
  68567. }
  68568. else
  68569. {
  68570. gradient.addColour (0.0, Colours::black);
  68571. gradient.addColour (1.0, Colours::black);
  68572. }
  68573. if (overallOpacity.isNotEmpty())
  68574. gradient.multiplyOpacity (overallOpacity.getFloatValue());
  68575. jassert (gradient.getNumColours() > 0);
  68576. gradient.isRadial = fillXml->hasTagName (T("radialGradient"));
  68577. float width = viewBoxW;
  68578. float height = viewBoxH;
  68579. float dx = 0.0f;
  68580. float dy = 0.0f;
  68581. const bool userSpace = fillXml->getStringAttribute (T("gradientUnits")).equalsIgnoreCase (T("userSpaceOnUse"));
  68582. if (! userSpace)
  68583. {
  68584. const Rectangle<float> bounds (path.getBounds());
  68585. dx = bounds.getX();
  68586. dy = bounds.getY();
  68587. width = bounds.getWidth();
  68588. height = bounds.getHeight();
  68589. }
  68590. if (gradient.isRadial)
  68591. {
  68592. gradient.x1 = dx + getCoordLength (fillXml->getStringAttribute (T("cx"), T("50%")), width);
  68593. gradient.y1 = dy + getCoordLength (fillXml->getStringAttribute (T("cy"), T("50%")), height);
  68594. const float radius = getCoordLength (fillXml->getStringAttribute (T("r"), T("50%")), width);
  68595. gradient.x2 = gradient.x1 + radius;
  68596. gradient.y2 = gradient.y1;
  68597. //xxx (the fx, fy focal point isn't handled properly here..)
  68598. }
  68599. else
  68600. {
  68601. gradient.x1 = dx + getCoordLength (fillXml->getStringAttribute (T("x1"), T("0%")), width);
  68602. gradient.y1 = dy + getCoordLength (fillXml->getStringAttribute (T("y1"), T("0%")), height);
  68603. gradient.x2 = dx + getCoordLength (fillXml->getStringAttribute (T("x2"), T("100%")), width);
  68604. gradient.y2 = dy + getCoordLength (fillXml->getStringAttribute (T("y2"), T("0%")), height);
  68605. if (gradient.x1 == gradient.x2 && gradient.y1 == gradient.y2)
  68606. return Colour (gradient.getColour (gradient.getNumColours() - 1));
  68607. }
  68608. FillType type (gradient);
  68609. type.transform = parseTransform (fillXml->getStringAttribute (T("gradientTransform")))
  68610. .followedBy (transform);
  68611. return type;
  68612. }
  68613. }
  68614. if (fill.equalsIgnoreCase (T("none")))
  68615. return Colours::transparentBlack;
  68616. int i = 0;
  68617. const Colour colour (parseColour (fill, i, defaultColour));
  68618. return colour.withMultipliedAlpha (opacity);
  68619. }
  68620. const PathStrokeType getStrokeFor (const XmlElement* const xml) const
  68621. {
  68622. const String width (getStyleAttribute (xml, T("stroke-width")));
  68623. const String cap (getStyleAttribute (xml, T("stroke-linecap")));
  68624. const String join (getStyleAttribute (xml, T("stroke-linejoin")));
  68625. //const String mitreLimit (getStyleAttribute (xml, T("stroke-miterlimit")));
  68626. //const String dashArray (getStyleAttribute (xml, T("stroke-dasharray")));
  68627. //const String dashOffset (getStyleAttribute (xml, T("stroke-dashoffset")));
  68628. PathStrokeType::JointStyle joinStyle = PathStrokeType::mitered;
  68629. PathStrokeType::EndCapStyle capStyle = PathStrokeType::butt;
  68630. if (join.equalsIgnoreCase (T("round")))
  68631. joinStyle = PathStrokeType::curved;
  68632. else if (join.equalsIgnoreCase (T("bevel")))
  68633. joinStyle = PathStrokeType::beveled;
  68634. if (cap.equalsIgnoreCase (T("round")))
  68635. capStyle = PathStrokeType::rounded;
  68636. else if (cap.equalsIgnoreCase (T("square")))
  68637. capStyle = PathStrokeType::square;
  68638. float ox = 0.0f, oy = 0.0f;
  68639. transform.transformPoint (ox, oy);
  68640. float x = getCoordLength (width, viewBoxW), y = 0.0f;
  68641. transform.transformPoint (x, y);
  68642. return PathStrokeType (width.isNotEmpty() ? juce_hypotf (x - ox, y - oy) : 1.0f,
  68643. joinStyle, capStyle);
  68644. }
  68645. Drawable* parseText (const XmlElement& xml)
  68646. {
  68647. Array <float> xCoords, yCoords, dxCoords, dyCoords;
  68648. getCoordList (xCoords, getInheritedAttribute (&xml, T("x")), true, true);
  68649. getCoordList (yCoords, getInheritedAttribute (&xml, T("y")), true, false);
  68650. getCoordList (dxCoords, getInheritedAttribute (&xml, T("dx")), true, true);
  68651. getCoordList (dyCoords, getInheritedAttribute (&xml, T("dy")), true, false);
  68652. //xxx not done text yet!
  68653. forEachXmlChildElement (xml, e)
  68654. {
  68655. if (e->isTextElement())
  68656. {
  68657. const String text (e->getText());
  68658. Path path;
  68659. Drawable* s = parseShape (*e, path);
  68660. delete s;
  68661. }
  68662. else if (e->hasTagName (T("tspan")))
  68663. {
  68664. Drawable* s = parseText (*e);
  68665. delete s;
  68666. }
  68667. }
  68668. return 0;
  68669. }
  68670. void addTransform (const XmlElement& xml)
  68671. {
  68672. transform = parseTransform (xml.getStringAttribute (T("transform")))
  68673. .followedBy (transform);
  68674. }
  68675. bool parseCoord (const String& s, float& value, int& index,
  68676. const bool allowUnits, const bool isX) const
  68677. {
  68678. String number;
  68679. if (! parseNextNumber (s, number, index, allowUnits))
  68680. {
  68681. value = 0;
  68682. return false;
  68683. }
  68684. value = getCoordLength (number, isX ? viewBoxW : viewBoxH);
  68685. return true;
  68686. }
  68687. bool parseCoords (const String& s, float& x, float& y,
  68688. int& index, const bool allowUnits) const
  68689. {
  68690. return parseCoord (s, x, index, allowUnits, true)
  68691. && parseCoord (s, y, index, allowUnits, false);
  68692. }
  68693. float getCoordLength (const String& s, const float sizeForProportions) const
  68694. {
  68695. float n = s.getFloatValue();
  68696. const int len = s.length();
  68697. if (len > 2)
  68698. {
  68699. const float dpi = 96.0f;
  68700. const tchar n1 = s [len - 2];
  68701. const tchar n2 = s [len - 1];
  68702. if (n1 == T('i') && n2 == T('n'))
  68703. n *= dpi;
  68704. else if (n1 == T('m') && n2 == T('m'))
  68705. n *= dpi / 25.4f;
  68706. else if (n1 == T('c') && n2 == T('m'))
  68707. n *= dpi / 2.54f;
  68708. else if (n1 == T('p') && n2 == T('c'))
  68709. n *= 15.0f;
  68710. else if (n2 == T('%'))
  68711. n *= 0.01f * sizeForProportions;
  68712. }
  68713. return n;
  68714. }
  68715. void getCoordList (Array <float>& coords, const String& list,
  68716. const bool allowUnits, const bool isX) const
  68717. {
  68718. int index = 0;
  68719. float value;
  68720. while (parseCoord (list, value, index, allowUnits, isX))
  68721. coords.add (value);
  68722. }
  68723. void parseCSSStyle (const XmlElement& xml)
  68724. {
  68725. cssStyleText = xml.getAllSubText() + T("\n") + cssStyleText;
  68726. }
  68727. const String getStyleAttribute (const XmlElement* xml, const String& attributeName,
  68728. const String& defaultValue = String::empty) const
  68729. {
  68730. if (xml->hasAttribute (attributeName))
  68731. return xml->getStringAttribute (attributeName, defaultValue);
  68732. const String styleAtt (xml->getStringAttribute (T("style")));
  68733. if (styleAtt.isNotEmpty())
  68734. {
  68735. const String value (getAttributeFromStyleList (styleAtt, attributeName, String::empty));
  68736. if (value.isNotEmpty())
  68737. return value;
  68738. }
  68739. else if (xml->hasAttribute (T("class")))
  68740. {
  68741. const String className (T(".") + xml->getStringAttribute (T("class")));
  68742. int index = cssStyleText.indexOfIgnoreCase (className + T(" "));
  68743. if (index < 0)
  68744. index = cssStyleText.indexOfIgnoreCase (className + T("{"));
  68745. if (index >= 0)
  68746. {
  68747. const int openBracket = cssStyleText.indexOfChar (index, T('{'));
  68748. if (openBracket > index)
  68749. {
  68750. const int closeBracket = cssStyleText.indexOfChar (openBracket, T('}'));
  68751. if (closeBracket > openBracket)
  68752. {
  68753. const String value (getAttributeFromStyleList (cssStyleText.substring (openBracket + 1, closeBracket), attributeName, defaultValue));
  68754. if (value.isNotEmpty())
  68755. return value;
  68756. }
  68757. }
  68758. }
  68759. }
  68760. xml = const_cast <XmlElement*> (topLevelXml)->findParentElementOf (xml);
  68761. if (xml != 0)
  68762. return getStyleAttribute (xml, attributeName, defaultValue);
  68763. return defaultValue;
  68764. }
  68765. const String getInheritedAttribute (const XmlElement* xml, const String& attributeName) const
  68766. {
  68767. if (xml->hasAttribute (attributeName))
  68768. return xml->getStringAttribute (attributeName);
  68769. xml = const_cast <XmlElement*> (topLevelXml)->findParentElementOf (xml);
  68770. if (xml != 0)
  68771. return getInheritedAttribute (xml, attributeName);
  68772. return String::empty;
  68773. }
  68774. static bool isIdentifierChar (const tchar c)
  68775. {
  68776. return CharacterFunctions::isLetter (c) || c == T('-');
  68777. }
  68778. static const String getAttributeFromStyleList (const String& list, const String& attributeName, const String& defaultValue)
  68779. {
  68780. int i = 0;
  68781. for (;;)
  68782. {
  68783. i = list.indexOf (i, attributeName);
  68784. if (i < 0)
  68785. break;
  68786. if ((i == 0 || (i > 0 && ! isIdentifierChar (list [i - 1])))
  68787. && ! isIdentifierChar (list [i + attributeName.length()]))
  68788. {
  68789. i = list.indexOfChar (i, T(':'));
  68790. if (i < 0)
  68791. break;
  68792. int end = list.indexOfChar (i, T(';'));
  68793. if (end < 0)
  68794. end = 0x7ffff;
  68795. return list.substring (i + 1, end).trim();
  68796. }
  68797. ++i;
  68798. }
  68799. return defaultValue;
  68800. }
  68801. static bool parseNextNumber (const String& source, String& value, int& index, const bool allowUnits)
  68802. {
  68803. const tchar* const s = (const tchar*) source;
  68804. while (CharacterFunctions::isWhitespace (s[index]) || s[index] == T(','))
  68805. ++index;
  68806. int start = index;
  68807. if (CharacterFunctions::isDigit (s[index]) || s[index] == T('.') || s[index] == T('-'))
  68808. ++index;
  68809. while (CharacterFunctions::isDigit (s[index]) || s[index] == T('.'))
  68810. ++index;
  68811. if ((s[index] == T('e') || s[index] == T('E'))
  68812. && (CharacterFunctions::isDigit (s[index + 1])
  68813. || s[index + 1] == T('-')
  68814. || s[index + 1] == T('+')))
  68815. {
  68816. index += 2;
  68817. while (CharacterFunctions::isDigit (s[index]))
  68818. ++index;
  68819. }
  68820. if (allowUnits)
  68821. {
  68822. while (CharacterFunctions::isLetter (s[index]))
  68823. ++index;
  68824. }
  68825. if (index == start)
  68826. return false;
  68827. value = String (s + start, index - start);
  68828. while (CharacterFunctions::isWhitespace (s[index]) || s[index] == T(','))
  68829. ++index;
  68830. return true;
  68831. }
  68832. static const Colour parseColour (const String& s, int& index, const Colour& defaultColour)
  68833. {
  68834. if (s [index] == T('#'))
  68835. {
  68836. uint32 hex [6];
  68837. zeromem (hex, sizeof (hex));
  68838. int numChars = 0;
  68839. for (int i = 6; --i >= 0;)
  68840. {
  68841. const int hexValue = CharacterFunctions::getHexDigitValue (s [++index]);
  68842. if (hexValue >= 0)
  68843. hex [numChars++] = hexValue;
  68844. else
  68845. break;
  68846. }
  68847. if (numChars <= 3)
  68848. return Colour ((uint8) (hex [0] * 0x11),
  68849. (uint8) (hex [1] * 0x11),
  68850. (uint8) (hex [2] * 0x11));
  68851. else
  68852. return Colour ((uint8) ((hex [0] << 4) + hex [1]),
  68853. (uint8) ((hex [2] << 4) + hex [3]),
  68854. (uint8) ((hex [4] << 4) + hex [5]));
  68855. }
  68856. else if (s [index] == T('r')
  68857. && s [index + 1] == T('g')
  68858. && s [index + 2] == T('b'))
  68859. {
  68860. const int openBracket = s.indexOfChar (index, T('('));
  68861. const int closeBracket = s.indexOfChar (openBracket, T(')'));
  68862. if (openBracket >= 3 && closeBracket > openBracket)
  68863. {
  68864. index = closeBracket;
  68865. StringArray tokens;
  68866. tokens.addTokens (s.substring (openBracket + 1, closeBracket), T(","), T(""));
  68867. tokens.trim();
  68868. tokens.removeEmptyStrings();
  68869. if (tokens[0].containsChar (T('%')))
  68870. return Colour ((uint8) roundToInt (2.55 * tokens[0].getDoubleValue()),
  68871. (uint8) roundToInt (2.55 * tokens[1].getDoubleValue()),
  68872. (uint8) roundToInt (2.55 * tokens[2].getDoubleValue()));
  68873. else
  68874. return Colour ((uint8) tokens[0].getIntValue(),
  68875. (uint8) tokens[1].getIntValue(),
  68876. (uint8) tokens[2].getIntValue());
  68877. }
  68878. }
  68879. return Colours::findColourForName (s, defaultColour);
  68880. }
  68881. static const AffineTransform parseTransform (String t)
  68882. {
  68883. AffineTransform result;
  68884. while (t.isNotEmpty())
  68885. {
  68886. StringArray tokens;
  68887. tokens.addTokens (t.fromFirstOccurrenceOf (T("("), false, false)
  68888. .upToFirstOccurrenceOf (T(")"), false, false),
  68889. T(", "), 0);
  68890. tokens.removeEmptyStrings (true);
  68891. float numbers [6];
  68892. for (int i = 0; i < 6; ++i)
  68893. numbers[i] = tokens[i].getFloatValue();
  68894. AffineTransform trans;
  68895. if (t.startsWithIgnoreCase (T("matrix")))
  68896. {
  68897. trans = AffineTransform (numbers[0], numbers[2], numbers[4],
  68898. numbers[1], numbers[3], numbers[5]);
  68899. }
  68900. else if (t.startsWithIgnoreCase (T("translate")))
  68901. {
  68902. trans = trans.translated (numbers[0], numbers[1]);
  68903. }
  68904. else if (t.startsWithIgnoreCase (T("scale")))
  68905. {
  68906. if (tokens.size() == 1)
  68907. trans = trans.scaled (numbers[0], numbers[0]);
  68908. else
  68909. trans = trans.scaled (numbers[0], numbers[1]);
  68910. }
  68911. else if (t.startsWithIgnoreCase (T("rotate")))
  68912. {
  68913. if (tokens.size() != 3)
  68914. trans = trans.rotated (numbers[0] / (180.0f / float_Pi));
  68915. else
  68916. trans = trans.rotated (numbers[0] / (180.0f / float_Pi),
  68917. numbers[1], numbers[2]);
  68918. }
  68919. else if (t.startsWithIgnoreCase (T("skewX")))
  68920. {
  68921. trans = AffineTransform (1.0f, tanf (numbers[0] * (float_Pi / 180.0f)), 0.0f,
  68922. 0.0f, 1.0f, 0.0f);
  68923. }
  68924. else if (t.startsWithIgnoreCase (T("skewY")))
  68925. {
  68926. trans = AffineTransform (1.0f, 0.0f, 0.0f,
  68927. tanf (numbers[0] * (float_Pi / 180.0f)), 1.0f, 0.0f);
  68928. }
  68929. result = trans.followedBy (result);
  68930. t = t.fromFirstOccurrenceOf (T(")"), false, false).trimStart();
  68931. }
  68932. return result;
  68933. }
  68934. static void endpointToCentreParameters (const double x1, const double y1,
  68935. const double x2, const double y2,
  68936. const double angle,
  68937. const bool largeArc, const bool sweep,
  68938. double& rx, double& ry,
  68939. double& centreX, double& centreY,
  68940. double& startAngle, double& deltaAngle)
  68941. {
  68942. const double midX = (x1 - x2) * 0.5;
  68943. const double midY = (y1 - y2) * 0.5;
  68944. const double cosAngle = cos (angle);
  68945. const double sinAngle = sin (angle);
  68946. const double xp = cosAngle * midX + sinAngle * midY;
  68947. const double yp = cosAngle * midY - sinAngle * midX;
  68948. const double xp2 = xp * xp;
  68949. const double yp2 = yp * yp;
  68950. double rx2 = rx * rx;
  68951. double ry2 = ry * ry;
  68952. const double s = (xp2 / rx2) + (yp2 / ry2);
  68953. double c;
  68954. if (s <= 1.0)
  68955. {
  68956. c = sqrt (jmax (0.0, ((rx2 * ry2) - (rx2 * yp2) - (ry2 * xp2))
  68957. / (( rx2 * yp2) + (ry2 * xp2))));
  68958. if (largeArc == sweep)
  68959. c = -c;
  68960. }
  68961. else
  68962. {
  68963. const double s2 = sqrt (s);
  68964. rx *= s2;
  68965. ry *= s2;
  68966. rx2 = rx * rx;
  68967. ry2 = ry * ry;
  68968. c = 0;
  68969. }
  68970. const double cpx = ((rx * yp) / ry) * c;
  68971. const double cpy = ((-ry * xp) / rx) * c;
  68972. centreX = ((x1 + x2) * 0.5) + (cosAngle * cpx) - (sinAngle * cpy);
  68973. centreY = ((y1 + y2) * 0.5) + (sinAngle * cpx) + (cosAngle * cpy);
  68974. const double ux = (xp - cpx) / rx;
  68975. const double uy = (yp - cpy) / ry;
  68976. const double vx = (-xp - cpx) / rx;
  68977. const double vy = (-yp - cpy) / ry;
  68978. const double length = juce_hypot (ux, uy);
  68979. startAngle = acos (jlimit (-1.0, 1.0, ux / length));
  68980. if (uy < 0)
  68981. startAngle = -startAngle;
  68982. startAngle += double_Pi * 0.5;
  68983. deltaAngle = acos (jlimit (-1.0, 1.0, ((ux * vx) + (uy * vy))
  68984. / (length * juce_hypot (vx, vy))));
  68985. if ((ux * vy) - (uy * vx) < 0)
  68986. deltaAngle = -deltaAngle;
  68987. if (sweep)
  68988. {
  68989. if (deltaAngle < 0)
  68990. deltaAngle += double_Pi * 2.0;
  68991. }
  68992. else
  68993. {
  68994. if (deltaAngle > 0)
  68995. deltaAngle -= double_Pi * 2.0;
  68996. }
  68997. deltaAngle = fmod (deltaAngle, double_Pi * 2.0);
  68998. }
  68999. static const XmlElement* findElementForId (const XmlElement* const parent, const String& id)
  69000. {
  69001. forEachXmlChildElement (*parent, e)
  69002. {
  69003. if (e->compareAttribute (T("id"), id))
  69004. return e;
  69005. const XmlElement* const found = findElementForId (e, id);
  69006. if (found != 0)
  69007. return found;
  69008. }
  69009. return 0;
  69010. }
  69011. const SVGState& operator= (const SVGState&);
  69012. };
  69013. Drawable* Drawable::createFromSVG (const XmlElement& svgDocument)
  69014. {
  69015. SVGState state (&svgDocument);
  69016. return state.parseSVGElement (svgDocument);
  69017. }
  69018. END_JUCE_NAMESPACE
  69019. /*** End of inlined file: juce_SVGParser.cpp ***/
  69020. /*** Start of inlined file: juce_DropShadowEffect.cpp ***/
  69021. BEGIN_JUCE_NAMESPACE
  69022. #if JUCE_MSVC
  69023. #pragma optimize ("t", on) // try to avoid slowing everything down in debug builds
  69024. #endif
  69025. DropShadowEffect::DropShadowEffect()
  69026. : offsetX (0),
  69027. offsetY (0),
  69028. radius (4),
  69029. opacity (0.6f)
  69030. {
  69031. }
  69032. DropShadowEffect::~DropShadowEffect()
  69033. {
  69034. }
  69035. void DropShadowEffect::setShadowProperties (const float newRadius,
  69036. const float newOpacity,
  69037. const int newShadowOffsetX,
  69038. const int newShadowOffsetY)
  69039. {
  69040. radius = jmax (1.1f, newRadius);
  69041. offsetX = newShadowOffsetX;
  69042. offsetY = newShadowOffsetY;
  69043. opacity = newOpacity;
  69044. }
  69045. void DropShadowEffect::applyEffect (Image& image, Graphics& g)
  69046. {
  69047. const int w = image.getWidth();
  69048. const int h = image.getHeight();
  69049. Image shadowImage (Image::SingleChannel, w, h, false);
  69050. const Image::BitmapData srcData (image, 0, 0, w, h);
  69051. const Image::BitmapData destData (shadowImage, 0, 0, w, h, true);
  69052. const int filter = roundToInt (63.0f / radius);
  69053. const int radiusMinus1 = roundToInt ((radius - 1.0f) * 63.0f);
  69054. for (int x = w; --x >= 0;)
  69055. {
  69056. int shadowAlpha = 0;
  69057. const PixelARGB* src = ((const PixelARGB*) srcData.data) + x;
  69058. uint8* shadowPix = destData.data + x;
  69059. for (int y = h; --y >= 0;)
  69060. {
  69061. shadowAlpha = ((shadowAlpha * radiusMinus1 + (src->getAlpha() << 6)) * filter) >> 12;
  69062. *shadowPix = (uint8) shadowAlpha;
  69063. src = (const PixelARGB*) (((const uint8*) src) + srcData.lineStride);
  69064. shadowPix += destData.lineStride;
  69065. }
  69066. }
  69067. for (int y = h; --y >= 0;)
  69068. {
  69069. int shadowAlpha = 0;
  69070. uint8* shadowPix = destData.getLinePointer (y);
  69071. for (int x = w; --x >= 0;)
  69072. {
  69073. shadowAlpha = ((shadowAlpha * radiusMinus1 + (*shadowPix << 6)) * filter) >> 12;
  69074. *shadowPix++ = (uint8) shadowAlpha;
  69075. }
  69076. }
  69077. g.setColour (Colours::black.withAlpha (opacity));
  69078. g.drawImageAt (&shadowImage, offsetX, offsetY, true);
  69079. g.setOpacity (1.0f);
  69080. g.drawImageAt (&image, 0, 0);
  69081. }
  69082. END_JUCE_NAMESPACE
  69083. /*** End of inlined file: juce_DropShadowEffect.cpp ***/
  69084. /*** Start of inlined file: juce_GlowEffect.cpp ***/
  69085. BEGIN_JUCE_NAMESPACE
  69086. GlowEffect::GlowEffect()
  69087. : radius (2.0f),
  69088. colour (Colours::white)
  69089. {
  69090. }
  69091. GlowEffect::~GlowEffect()
  69092. {
  69093. }
  69094. void GlowEffect::setGlowProperties (const float newRadius,
  69095. const Colour& newColour)
  69096. {
  69097. radius = newRadius;
  69098. colour = newColour;
  69099. }
  69100. void GlowEffect::applyEffect (Image& image, Graphics& g)
  69101. {
  69102. const int w = image.getWidth();
  69103. const int h = image.getHeight();
  69104. Image temp (image.getFormat(), w, h, true);
  69105. ImageConvolutionKernel blurKernel (roundToInt (radius * 2.0f));
  69106. blurKernel.createGaussianBlur (radius);
  69107. blurKernel.rescaleAllValues (radius);
  69108. blurKernel.applyToImage (temp, &image, 0, 0, w, h);
  69109. g.setColour (colour);
  69110. g.drawImageAt (&temp, 0, 0, true);
  69111. g.setOpacity (1.0f);
  69112. g.drawImageAt (&image, 0, 0, false);
  69113. }
  69114. END_JUCE_NAMESPACE
  69115. /*** End of inlined file: juce_GlowEffect.cpp ***/
  69116. /*** Start of inlined file: juce_ReduceOpacityEffect.cpp ***/
  69117. BEGIN_JUCE_NAMESPACE
  69118. ReduceOpacityEffect::ReduceOpacityEffect (const float opacity_)
  69119. : opacity (opacity_)
  69120. {
  69121. }
  69122. ReduceOpacityEffect::~ReduceOpacityEffect()
  69123. {
  69124. }
  69125. void ReduceOpacityEffect::setOpacity (const float newOpacity)
  69126. {
  69127. opacity = jlimit (0.0f, 1.0f, newOpacity);
  69128. }
  69129. void ReduceOpacityEffect::applyEffect (Image& image, Graphics& g)
  69130. {
  69131. g.setOpacity (opacity);
  69132. g.drawImageAt (&image, 0, 0);
  69133. }
  69134. END_JUCE_NAMESPACE
  69135. /*** End of inlined file: juce_ReduceOpacityEffect.cpp ***/
  69136. /*** Start of inlined file: juce_Font.cpp ***/
  69137. BEGIN_JUCE_NAMESPACE
  69138. static const float minFontHeight = 0.1f;
  69139. static const float maxFontHeight = 10000.0f;
  69140. static const float defaultFontHeight = 14.0f;
  69141. static const tchar* const juce_defaultFontNameSans = T("<Sans-Serif>");
  69142. static const tchar* const juce_defaultFontNameSerif = T("<Serif>");
  69143. static const tchar* const juce_defaultFontNameMono = T("<Monospaced>");
  69144. void clearUpDefaultFontNames() throw(); // in juce_LookAndFeel.cpp
  69145. Font::SharedFontInternal::SharedFontInternal (const String& typefaceName_, const float height_, const float horizontalScale_,
  69146. const float kerning_, const float ascent_, const int styleFlags_,
  69147. Typeface* const typeface_) throw()
  69148. : typefaceName (typefaceName_),
  69149. height (height_),
  69150. horizontalScale (horizontalScale_),
  69151. kerning (kerning_),
  69152. ascent (ascent_),
  69153. styleFlags (styleFlags_),
  69154. typeface (typeface_)
  69155. {
  69156. }
  69157. Font::SharedFontInternal::SharedFontInternal (const SharedFontInternal& other) throw()
  69158. : typefaceName (other.typefaceName),
  69159. height (other.height),
  69160. horizontalScale (other.horizontalScale),
  69161. kerning (other.kerning),
  69162. ascent (other.ascent),
  69163. styleFlags (other.styleFlags),
  69164. typeface (other.typeface)
  69165. {
  69166. }
  69167. Font::Font() throw()
  69168. : font (new SharedFontInternal (juce_defaultFontNameSans, defaultFontHeight,
  69169. 1.0f, 0, 0, Font::plain, 0))
  69170. {
  69171. }
  69172. Font::Font (const float fontHeight, const int styleFlags_) throw()
  69173. : font (new SharedFontInternal (juce_defaultFontNameSans, jlimit (minFontHeight, maxFontHeight, fontHeight),
  69174. 1.0f, 0, 0, styleFlags_, 0))
  69175. {
  69176. }
  69177. Font::Font (const String& typefaceName_,
  69178. const float fontHeight,
  69179. const int styleFlags_) throw()
  69180. : font (new SharedFontInternal (typefaceName_, jlimit (minFontHeight, maxFontHeight, fontHeight),
  69181. 1.0f, 0, 0, styleFlags_, 0))
  69182. {
  69183. }
  69184. Font::Font (const Font& other) throw()
  69185. : font (other.font)
  69186. {
  69187. }
  69188. const Font& Font::operator= (const Font& other) throw()
  69189. {
  69190. font = other.font;
  69191. return *this;
  69192. }
  69193. Font::~Font() throw()
  69194. {
  69195. }
  69196. Font::Font (const Typeface::Ptr& typeface) throw()
  69197. : font (new SharedFontInternal (typeface->getName(), defaultFontHeight,
  69198. 1.0f, 0, 0, Font::plain, typeface))
  69199. {
  69200. }
  69201. bool Font::operator== (const Font& other) const throw()
  69202. {
  69203. return font == other.font
  69204. || (font->height == other.font->height
  69205. && font->styleFlags == other.font->styleFlags
  69206. && font->horizontalScale == other.font->horizontalScale
  69207. && font->kerning == other.font->kerning
  69208. && font->typefaceName == other.font->typefaceName);
  69209. }
  69210. bool Font::operator!= (const Font& other) const throw()
  69211. {
  69212. return ! operator== (other);
  69213. }
  69214. void Font::dupeInternalIfShared() throw()
  69215. {
  69216. if (font->getReferenceCount() > 1)
  69217. font = new SharedFontInternal (*font);
  69218. }
  69219. const String Font::getDefaultSansSerifFontName() throw()
  69220. {
  69221. return juce_defaultFontNameSans;
  69222. }
  69223. const String Font::getDefaultSerifFontName() throw()
  69224. {
  69225. return juce_defaultFontNameSerif;
  69226. }
  69227. const String Font::getDefaultMonospacedFontName() throw()
  69228. {
  69229. return juce_defaultFontNameMono;
  69230. }
  69231. void Font::setTypefaceName (const String& faceName) throw()
  69232. {
  69233. if (faceName != font->typefaceName)
  69234. {
  69235. dupeInternalIfShared();
  69236. font->typefaceName = faceName;
  69237. font->typeface = 0;
  69238. font->ascent = 0;
  69239. }
  69240. }
  69241. static String fallbackFont;
  69242. const String Font::getFallbackFontName() throw()
  69243. {
  69244. return fallbackFont;
  69245. }
  69246. void Font::setFallbackFontName (const String& name) throw()
  69247. {
  69248. fallbackFont = name;
  69249. }
  69250. void Font::setHeight (float newHeight) throw()
  69251. {
  69252. newHeight = jlimit (minFontHeight, maxFontHeight, newHeight);
  69253. if (font->height != newHeight)
  69254. {
  69255. dupeInternalIfShared();
  69256. font->height = newHeight;
  69257. }
  69258. }
  69259. void Font::setHeightWithoutChangingWidth (float newHeight) throw()
  69260. {
  69261. newHeight = jlimit (minFontHeight, maxFontHeight, newHeight);
  69262. if (font->height != newHeight)
  69263. {
  69264. dupeInternalIfShared();
  69265. font->horizontalScale *= (font->height / newHeight);
  69266. font->height = newHeight;
  69267. }
  69268. }
  69269. void Font::setStyleFlags (const int newFlags) throw()
  69270. {
  69271. if (font->styleFlags != newFlags)
  69272. {
  69273. dupeInternalIfShared();
  69274. font->styleFlags = newFlags;
  69275. font->typeface = 0;
  69276. font->ascent = 0;
  69277. }
  69278. }
  69279. void Font::setSizeAndStyle (float newHeight,
  69280. const int newStyleFlags,
  69281. const float newHorizontalScale,
  69282. const float newKerningAmount) throw()
  69283. {
  69284. newHeight = jlimit (minFontHeight, maxFontHeight, newHeight);
  69285. if (font->height != newHeight
  69286. || font->horizontalScale != newHorizontalScale
  69287. || font->kerning != newKerningAmount)
  69288. {
  69289. dupeInternalIfShared();
  69290. font->height = newHeight;
  69291. font->horizontalScale = newHorizontalScale;
  69292. font->kerning = newKerningAmount;
  69293. }
  69294. setStyleFlags (newStyleFlags);
  69295. }
  69296. void Font::setHorizontalScale (const float scaleFactor) throw()
  69297. {
  69298. dupeInternalIfShared();
  69299. font->horizontalScale = scaleFactor;
  69300. }
  69301. void Font::setExtraKerningFactor (const float extraKerning) throw()
  69302. {
  69303. dupeInternalIfShared();
  69304. font->kerning = extraKerning;
  69305. }
  69306. void Font::setBold (const bool shouldBeBold) throw()
  69307. {
  69308. setStyleFlags (shouldBeBold ? (font->styleFlags | bold)
  69309. : (font->styleFlags & ~bold));
  69310. }
  69311. bool Font::isBold() const throw()
  69312. {
  69313. return (font->styleFlags & bold) != 0;
  69314. }
  69315. void Font::setItalic (const bool shouldBeItalic) throw()
  69316. {
  69317. setStyleFlags (shouldBeItalic ? (font->styleFlags | italic)
  69318. : (font->styleFlags & ~italic));
  69319. }
  69320. bool Font::isItalic() const throw()
  69321. {
  69322. return (font->styleFlags & italic) != 0;
  69323. }
  69324. void Font::setUnderline (const bool shouldBeUnderlined) throw()
  69325. {
  69326. setStyleFlags (shouldBeUnderlined ? (font->styleFlags | underlined)
  69327. : (font->styleFlags & ~underlined));
  69328. }
  69329. bool Font::isUnderlined() const throw()
  69330. {
  69331. return (font->styleFlags & underlined) != 0;
  69332. }
  69333. float Font::getAscent() const throw()
  69334. {
  69335. if (font->ascent == 0)
  69336. font->ascent = getTypeface()->getAscent();
  69337. return font->height * font->ascent;
  69338. }
  69339. float Font::getDescent() const throw()
  69340. {
  69341. return font->height - getAscent();
  69342. }
  69343. int Font::getStringWidth (const String& text) const throw()
  69344. {
  69345. return roundToInt (getStringWidthFloat (text));
  69346. }
  69347. float Font::getStringWidthFloat (const String& text) const throw()
  69348. {
  69349. float w = getTypeface()->getStringWidth (text);
  69350. if (font->kerning != 0)
  69351. w += font->kerning * text.length();
  69352. return w * font->height * font->horizontalScale;
  69353. }
  69354. void Font::getGlyphPositions (const String& text, Array <int>& glyphs, Array <float>& xOffsets) const throw()
  69355. {
  69356. getTypeface()->getGlyphPositions (text, glyphs, xOffsets);
  69357. const float scale = font->height * font->horizontalScale;
  69358. const int num = xOffsets.size();
  69359. if (num > 0)
  69360. {
  69361. float* const x = &(xOffsets.getReference(0));
  69362. if (font->kerning != 0)
  69363. {
  69364. for (int i = 0; i < num; ++i)
  69365. x[i] = (x[i] + i * font->kerning) * scale;
  69366. }
  69367. else
  69368. {
  69369. for (int i = 0; i < num; ++i)
  69370. x[i] *= scale;
  69371. }
  69372. }
  69373. }
  69374. void Font::findFonts (Array<Font>& destArray) throw()
  69375. {
  69376. const StringArray names (findAllTypefaceNames());
  69377. for (int i = 0; i < names.size(); ++i)
  69378. destArray.add (Font (names[i], defaultFontHeight, Font::plain));
  69379. }
  69380. class TypefaceCache : public DeletedAtShutdown
  69381. {
  69382. public:
  69383. TypefaceCache (int numToCache = 10) throw()
  69384. : counter (1)
  69385. {
  69386. while (--numToCache >= 0)
  69387. faces.add (new CachedFace());
  69388. }
  69389. ~TypefaceCache()
  69390. {
  69391. clearUpDefaultFontNames();
  69392. clearSingletonInstance();
  69393. }
  69394. juce_DeclareSingleton_SingleThreaded_Minimal (TypefaceCache)
  69395. const Typeface::Ptr findTypefaceFor (const Font& font) throw()
  69396. {
  69397. const int flags = font.getStyleFlags() & (Font::bold | Font::italic);
  69398. const String faceName (font.getTypefaceName());
  69399. int i;
  69400. for (i = faces.size(); --i >= 0;)
  69401. {
  69402. CachedFace* const face = faces.getUnchecked(i);
  69403. if (face->flags == flags
  69404. && face->typefaceName == faceName)
  69405. {
  69406. face->lastUsageCount = ++counter;
  69407. return face->typeFace;
  69408. }
  69409. }
  69410. int replaceIndex = 0;
  69411. int bestLastUsageCount = std::numeric_limits<int>::max();
  69412. for (i = faces.size(); --i >= 0;)
  69413. {
  69414. const int lu = faces.getUnchecked(i)->lastUsageCount;
  69415. if (bestLastUsageCount > lu)
  69416. {
  69417. bestLastUsageCount = lu;
  69418. replaceIndex = i;
  69419. }
  69420. }
  69421. CachedFace* const face = faces.getUnchecked (replaceIndex);
  69422. face->typefaceName = faceName;
  69423. face->flags = flags;
  69424. face->lastUsageCount = ++counter;
  69425. face->typeFace = LookAndFeel::getDefaultLookAndFeel().getTypefaceForFont (font);
  69426. jassert (face->typeFace != 0); // the look and feel must return a typeface!
  69427. return face->typeFace;
  69428. }
  69429. juce_UseDebuggingNewOperator
  69430. private:
  69431. struct CachedFace
  69432. {
  69433. CachedFace() throw()
  69434. : lastUsageCount (0), flags (-1)
  69435. {
  69436. }
  69437. String typefaceName;
  69438. int lastUsageCount;
  69439. int flags;
  69440. Typeface::Ptr typeFace;
  69441. };
  69442. int counter;
  69443. OwnedArray <CachedFace> faces;
  69444. TypefaceCache (const TypefaceCache&);
  69445. const TypefaceCache& operator= (const TypefaceCache&);
  69446. };
  69447. juce_ImplementSingleton_SingleThreaded (TypefaceCache)
  69448. Typeface* Font::getTypeface() const throw()
  69449. {
  69450. if (font->typeface == 0)
  69451. font->typeface = TypefaceCache::getInstance()->findTypefaceFor (*this);
  69452. return font->typeface;
  69453. }
  69454. END_JUCE_NAMESPACE
  69455. /*** End of inlined file: juce_Font.cpp ***/
  69456. /*** Start of inlined file: juce_GlyphArrangement.cpp ***/
  69457. BEGIN_JUCE_NAMESPACE
  69458. PositionedGlyph::PositionedGlyph()
  69459. {
  69460. }
  69461. void PositionedGlyph::draw (const Graphics& g) const
  69462. {
  69463. if (! isWhitespace())
  69464. {
  69465. g.getInternalContext()->setFont (font);
  69466. g.getInternalContext()->drawGlyph (glyph, AffineTransform::translation (x, y));
  69467. }
  69468. }
  69469. void PositionedGlyph::draw (const Graphics& g,
  69470. const AffineTransform& transform) const
  69471. {
  69472. if (! isWhitespace())
  69473. {
  69474. g.getInternalContext()->setFont (font);
  69475. g.getInternalContext()->drawGlyph (glyph, AffineTransform::translation (x, y)
  69476. .followedBy (transform));
  69477. }
  69478. }
  69479. void PositionedGlyph::createPath (Path& path) const
  69480. {
  69481. if (! isWhitespace())
  69482. {
  69483. Typeface* const t = font.getTypeface();
  69484. if (t != 0)
  69485. {
  69486. Path p;
  69487. t->getOutlineForGlyph (glyph, p);
  69488. path.addPath (p, AffineTransform::scale (font.getHeight() * font.getHorizontalScale(), font.getHeight())
  69489. .translated (x, y));
  69490. }
  69491. }
  69492. }
  69493. bool PositionedGlyph::hitTest (float px, float py) const
  69494. {
  69495. if (px >= getLeft() && px < getRight()
  69496. && py >= getTop() && py < getBottom()
  69497. && ! isWhitespace())
  69498. {
  69499. Typeface* const t = font.getTypeface();
  69500. if (t != 0)
  69501. {
  69502. Path p;
  69503. t->getOutlineForGlyph (glyph, p);
  69504. AffineTransform::translation (-x, -y)
  69505. .scaled (1.0f / (font.getHeight() * font.getHorizontalScale()), 1.0f / font.getHeight())
  69506. .transformPoint (px, py);
  69507. return p.contains (px, py);
  69508. }
  69509. }
  69510. return false;
  69511. }
  69512. void PositionedGlyph::moveBy (const float deltaX,
  69513. const float deltaY)
  69514. {
  69515. x += deltaX;
  69516. y += deltaY;
  69517. }
  69518. GlyphArrangement::GlyphArrangement()
  69519. {
  69520. glyphs.ensureStorageAllocated (128);
  69521. }
  69522. GlyphArrangement::GlyphArrangement (const GlyphArrangement& other)
  69523. {
  69524. addGlyphArrangement (other);
  69525. }
  69526. const GlyphArrangement& GlyphArrangement::operator= (const GlyphArrangement& other)
  69527. {
  69528. if (this != &other)
  69529. {
  69530. clear();
  69531. addGlyphArrangement (other);
  69532. }
  69533. return *this;
  69534. }
  69535. GlyphArrangement::~GlyphArrangement()
  69536. {
  69537. }
  69538. void GlyphArrangement::clear()
  69539. {
  69540. glyphs.clear();
  69541. }
  69542. PositionedGlyph& GlyphArrangement::getGlyph (const int index) const
  69543. {
  69544. jassert (((unsigned int) index) < (unsigned int) glyphs.size());
  69545. return *glyphs [index];
  69546. }
  69547. void GlyphArrangement::addGlyphArrangement (const GlyphArrangement& other)
  69548. {
  69549. glyphs.ensureStorageAllocated (glyphs.size() + other.glyphs.size());
  69550. for (int i = 0; i < other.glyphs.size(); ++i)
  69551. glyphs.add (new PositionedGlyph (*other.glyphs.getUnchecked (i)));
  69552. }
  69553. void GlyphArrangement::removeRangeOfGlyphs (int startIndex, const int num)
  69554. {
  69555. glyphs.removeRange (startIndex, num < 0 ? glyphs.size() : num);
  69556. }
  69557. void GlyphArrangement::addLineOfText (const Font& font,
  69558. const String& text,
  69559. const float xOffset,
  69560. const float yOffset)
  69561. {
  69562. addCurtailedLineOfText (font, text,
  69563. xOffset, yOffset,
  69564. 1.0e10f, false);
  69565. }
  69566. void GlyphArrangement::addCurtailedLineOfText (const Font& font,
  69567. const String& text,
  69568. float xOffset,
  69569. const float yOffset,
  69570. const float maxWidthPixels,
  69571. const bool useEllipsis)
  69572. {
  69573. int textLen = text.length();
  69574. if (textLen > 0)
  69575. {
  69576. Array <int> newGlyphs;
  69577. Array <float> xOffsets;
  69578. font.getGlyphPositions (text, newGlyphs, xOffsets);
  69579. const juce_wchar* const unicodeText = (const juce_wchar*) text;
  69580. textLen = jmin (textLen, newGlyphs.size());
  69581. for (int i = 0; i < textLen; ++i)
  69582. {
  69583. const float thisX = xOffsets.getUnchecked (i);
  69584. const float nextX = xOffsets.getUnchecked (i + 1);
  69585. if (nextX > maxWidthPixels + 1.0f)
  69586. {
  69587. // curtail the string if it's too wide..
  69588. if (useEllipsis && textLen > 3 && glyphs.size() >= 3)
  69589. insertEllipsis (font, xOffset + maxWidthPixels, 0, glyphs.size());
  69590. break;
  69591. }
  69592. else
  69593. {
  69594. PositionedGlyph* const pg = new PositionedGlyph();
  69595. pg->x = xOffset + thisX;
  69596. pg->y = yOffset;
  69597. pg->w = nextX - thisX;
  69598. pg->font = font;
  69599. pg->glyph = newGlyphs.getUnchecked(i);
  69600. pg->character = unicodeText[i];
  69601. glyphs.add (pg);
  69602. }
  69603. }
  69604. }
  69605. }
  69606. int GlyphArrangement::insertEllipsis (const Font& font, const float maxXPos,
  69607. const int startIndex, int endIndex)
  69608. {
  69609. int numDeleted = 0;
  69610. if (glyphs.size() > 0)
  69611. {
  69612. Array<int> dotGlyphs;
  69613. Array<float> dotXs;
  69614. font.getGlyphPositions (T(".."), dotGlyphs, dotXs);
  69615. const float dx = dotXs[1];
  69616. float xOffset = 0.0f, yOffset = 0.0f;
  69617. while (endIndex > startIndex)
  69618. {
  69619. const PositionedGlyph* pg = glyphs.getUnchecked (--endIndex);
  69620. xOffset = pg->x;
  69621. yOffset = pg->y;
  69622. glyphs.remove (endIndex);
  69623. ++numDeleted;
  69624. if (xOffset + dx * 3 <= maxXPos)
  69625. break;
  69626. }
  69627. for (int i = 3; --i >= 0;)
  69628. {
  69629. PositionedGlyph* const pg = new PositionedGlyph();
  69630. pg->x = xOffset;
  69631. pg->y = yOffset;
  69632. pg->w = dx;
  69633. pg->font = font;
  69634. pg->character = '.';
  69635. pg->glyph = dotGlyphs.getFirst();
  69636. glyphs.insert (endIndex++, pg);
  69637. --numDeleted;
  69638. xOffset += dx;
  69639. if (xOffset > maxXPos)
  69640. break;
  69641. }
  69642. }
  69643. return numDeleted;
  69644. }
  69645. void GlyphArrangement::addJustifiedText (const Font& font,
  69646. const String& text,
  69647. float x, float y,
  69648. const float maxLineWidth,
  69649. const Justification& horizontalLayout)
  69650. {
  69651. int lineStartIndex = glyphs.size();
  69652. addLineOfText (font, text, x, y);
  69653. const float originalY = y;
  69654. while (lineStartIndex < glyphs.size())
  69655. {
  69656. int i = lineStartIndex;
  69657. if (glyphs.getUnchecked(i)->getCharacter() != T('\n')
  69658. && glyphs.getUnchecked(i)->getCharacter() != T('\r'))
  69659. ++i;
  69660. const float lineMaxX = glyphs.getUnchecked (lineStartIndex)->getLeft() + maxLineWidth;
  69661. int lastWordBreakIndex = -1;
  69662. while (i < glyphs.size())
  69663. {
  69664. const PositionedGlyph* pg = glyphs.getUnchecked (i);
  69665. const juce_wchar c = pg->getCharacter();
  69666. if (c == T('\r') || c == T('\n'))
  69667. {
  69668. ++i;
  69669. if (c == T('\r') && i < glyphs.size()
  69670. && glyphs.getUnchecked(i)->getCharacter() == T('\n'))
  69671. ++i;
  69672. break;
  69673. }
  69674. else if (pg->isWhitespace())
  69675. {
  69676. lastWordBreakIndex = i + 1;
  69677. }
  69678. else if (pg->getRight() - 0.0001f >= lineMaxX)
  69679. {
  69680. if (lastWordBreakIndex >= 0)
  69681. i = lastWordBreakIndex;
  69682. break;
  69683. }
  69684. ++i;
  69685. }
  69686. const float currentLineStartX = glyphs.getUnchecked (lineStartIndex)->getLeft();
  69687. float currentLineEndX = currentLineStartX;
  69688. for (int j = i; --j >= lineStartIndex;)
  69689. {
  69690. if (! glyphs.getUnchecked (j)->isWhitespace())
  69691. {
  69692. currentLineEndX = glyphs.getUnchecked (j)->getRight();
  69693. break;
  69694. }
  69695. }
  69696. float deltaX = 0.0f;
  69697. if (horizontalLayout.testFlags (Justification::horizontallyJustified))
  69698. spreadOutLine (lineStartIndex, i - lineStartIndex, maxLineWidth);
  69699. else if (horizontalLayout.testFlags (Justification::horizontallyCentred))
  69700. deltaX = (maxLineWidth - (currentLineEndX - currentLineStartX)) * 0.5f;
  69701. else if (horizontalLayout.testFlags (Justification::right))
  69702. deltaX = maxLineWidth - (currentLineEndX - currentLineStartX);
  69703. moveRangeOfGlyphs (lineStartIndex, i - lineStartIndex,
  69704. x + deltaX - currentLineStartX, y - originalY);
  69705. lineStartIndex = i;
  69706. y += font.getHeight();
  69707. }
  69708. }
  69709. void GlyphArrangement::addFittedText (const Font& f,
  69710. const String& text,
  69711. const float x, const float y,
  69712. const float width, const float height,
  69713. const Justification& layout,
  69714. int maximumLines,
  69715. const float minimumHorizontalScale)
  69716. {
  69717. // doesn't make much sense if this is outside a sensible range of 0.5 to 1.0
  69718. jassert (minimumHorizontalScale > 0 && minimumHorizontalScale <= 1.0f);
  69719. if (text.containsAnyOf (T("\r\n")))
  69720. {
  69721. GlyphArrangement ga;
  69722. ga.addJustifiedText (f, text, x, y, width, layout);
  69723. float l, t, r, b;
  69724. ga.getBoundingBox (0, -1, l, t, r, b, false);
  69725. float dy = y - t;
  69726. if (layout.testFlags (Justification::verticallyCentred))
  69727. dy += (height - (b - t)) * 0.5f;
  69728. else if (layout.testFlags (Justification::bottom))
  69729. dy += height - (b - t);
  69730. ga.moveRangeOfGlyphs (0, -1, 0.0f, dy);
  69731. glyphs.ensureStorageAllocated (glyphs.size() + ga.glyphs.size());
  69732. for (int i = 0; i < ga.glyphs.size(); ++i)
  69733. glyphs.add (ga.glyphs.getUnchecked (i));
  69734. ga.glyphs.clear (false);
  69735. return;
  69736. }
  69737. int startIndex = glyphs.size();
  69738. addLineOfText (f, text.trim(), x, y);
  69739. if (glyphs.size() > startIndex)
  69740. {
  69741. float lineWidth = glyphs.getUnchecked (glyphs.size() - 1)->getRight()
  69742. - glyphs.getUnchecked (startIndex)->getLeft();
  69743. if (lineWidth <= 0)
  69744. return;
  69745. if (lineWidth * minimumHorizontalScale < width)
  69746. {
  69747. if (lineWidth > width)
  69748. stretchRangeOfGlyphs (startIndex, glyphs.size() - startIndex,
  69749. width / lineWidth);
  69750. justifyGlyphs (startIndex, glyphs.size() - startIndex,
  69751. x, y, width, height, layout);
  69752. }
  69753. else if (maximumLines <= 1)
  69754. {
  69755. fitLineIntoSpace (startIndex, glyphs.size() - startIndex,
  69756. x, y, width, height, f, layout, minimumHorizontalScale);
  69757. }
  69758. else
  69759. {
  69760. Font font (f);
  69761. String txt (text.trim());
  69762. const int length = txt.length();
  69763. const int originalStartIndex = startIndex;
  69764. int numLines = 1;
  69765. if (length <= 12 && ! txt.containsAnyOf (T(" -\t\r\n")))
  69766. maximumLines = 1;
  69767. maximumLines = jmin (maximumLines, length);
  69768. while (numLines < maximumLines)
  69769. {
  69770. ++numLines;
  69771. const float newFontHeight = height / (float) numLines;
  69772. if (newFontHeight < font.getHeight())
  69773. {
  69774. font.setHeight (jmax (8.0f, newFontHeight));
  69775. removeRangeOfGlyphs (startIndex, -1);
  69776. addLineOfText (font, txt, x, y);
  69777. lineWidth = glyphs.getUnchecked (glyphs.size() - 1)->getRight()
  69778. - glyphs.getUnchecked (startIndex)->getLeft();
  69779. }
  69780. if (numLines > lineWidth / width || newFontHeight < 8.0f)
  69781. break;
  69782. }
  69783. if (numLines < 1)
  69784. numLines = 1;
  69785. float lineY = y;
  69786. float widthPerLine = lineWidth / numLines;
  69787. int lastLineStartIndex = 0;
  69788. for (int line = 0; line < numLines; ++line)
  69789. {
  69790. int i = startIndex;
  69791. lastLineStartIndex = i;
  69792. float lineStartX = glyphs.getUnchecked (startIndex)->getLeft();
  69793. if (line == numLines - 1)
  69794. {
  69795. widthPerLine = width;
  69796. i = glyphs.size();
  69797. }
  69798. else
  69799. {
  69800. while (i < glyphs.size())
  69801. {
  69802. lineWidth = (glyphs.getUnchecked (i)->getRight() - lineStartX);
  69803. if (lineWidth > widthPerLine)
  69804. {
  69805. // got to a point where the line's too long, so skip forward to find a
  69806. // good place to break it..
  69807. const int searchStartIndex = i;
  69808. while (i < glyphs.size())
  69809. {
  69810. if ((glyphs.getUnchecked (i)->getRight() - lineStartX) * minimumHorizontalScale < width)
  69811. {
  69812. if (glyphs.getUnchecked (i)->isWhitespace()
  69813. || glyphs.getUnchecked (i)->getCharacter() == T('-'))
  69814. {
  69815. ++i;
  69816. break;
  69817. }
  69818. }
  69819. else
  69820. {
  69821. // can't find a suitable break, so try looking backwards..
  69822. i = searchStartIndex;
  69823. for (int back = 1; back < jmin (5, i - startIndex - 1); ++back)
  69824. {
  69825. if (glyphs.getUnchecked (i - back)->isWhitespace()
  69826. || glyphs.getUnchecked (i - back)->getCharacter() == T('-'))
  69827. {
  69828. i -= back - 1;
  69829. break;
  69830. }
  69831. }
  69832. break;
  69833. }
  69834. ++i;
  69835. }
  69836. break;
  69837. }
  69838. ++i;
  69839. }
  69840. int wsStart = i;
  69841. while (wsStart > 0 && glyphs.getUnchecked (wsStart - 1)->isWhitespace())
  69842. --wsStart;
  69843. int wsEnd = i;
  69844. while (wsEnd < glyphs.size() && glyphs.getUnchecked (wsEnd)->isWhitespace())
  69845. ++wsEnd;
  69846. removeRangeOfGlyphs (wsStart, wsEnd - wsStart);
  69847. i = jmax (wsStart, startIndex + 1);
  69848. }
  69849. i -= fitLineIntoSpace (startIndex, i - startIndex,
  69850. x, lineY, width, font.getHeight(), font,
  69851. layout.getOnlyHorizontalFlags() | Justification::verticallyCentred,
  69852. minimumHorizontalScale);
  69853. startIndex = i;
  69854. lineY += font.getHeight();
  69855. if (startIndex >= glyphs.size())
  69856. break;
  69857. }
  69858. justifyGlyphs (originalStartIndex, glyphs.size() - originalStartIndex,
  69859. x, y, width, height, layout.getFlags() & ~Justification::horizontallyJustified);
  69860. }
  69861. }
  69862. }
  69863. void GlyphArrangement::moveRangeOfGlyphs (int startIndex, int num,
  69864. const float dx, const float dy)
  69865. {
  69866. jassert (startIndex >= 0);
  69867. if (dx != 0.0f || dy != 0.0f)
  69868. {
  69869. if (num < 0 || startIndex + num > glyphs.size())
  69870. num = glyphs.size() - startIndex;
  69871. while (--num >= 0)
  69872. glyphs.getUnchecked (startIndex++)->moveBy (dx, dy);
  69873. }
  69874. }
  69875. int GlyphArrangement::fitLineIntoSpace (int start, int numGlyphs, float x, float y, float w, float h, const Font& font,
  69876. const Justification& justification, float minimumHorizontalScale)
  69877. {
  69878. int numDeleted = 0;
  69879. const float lineStartX = glyphs.getUnchecked (start)->getLeft();
  69880. float lineWidth = glyphs.getUnchecked (start + numGlyphs - 1)->getRight() - lineStartX;
  69881. if (lineWidth > w)
  69882. {
  69883. if (minimumHorizontalScale < 1.0f)
  69884. {
  69885. stretchRangeOfGlyphs (start, numGlyphs, jmax (minimumHorizontalScale, w / lineWidth));
  69886. lineWidth = glyphs.getUnchecked (start + numGlyphs - 1)->getRight() - lineStartX - 0.5f;
  69887. }
  69888. if (lineWidth > w)
  69889. {
  69890. numDeleted = insertEllipsis (font, lineStartX + w, start, start + numGlyphs);
  69891. numGlyphs -= numDeleted;
  69892. }
  69893. }
  69894. justifyGlyphs (start, numGlyphs, x, y, w, h, justification);
  69895. return numDeleted;
  69896. }
  69897. void GlyphArrangement::stretchRangeOfGlyphs (int startIndex, int num,
  69898. const float horizontalScaleFactor)
  69899. {
  69900. jassert (startIndex >= 0);
  69901. if (num < 0 || startIndex + num > glyphs.size())
  69902. num = glyphs.size() - startIndex;
  69903. if (num > 0)
  69904. {
  69905. const float xAnchor = glyphs.getUnchecked (startIndex)->getLeft();
  69906. while (--num >= 0)
  69907. {
  69908. PositionedGlyph* const pg = glyphs.getUnchecked (startIndex++);
  69909. pg->x = xAnchor + (pg->x - xAnchor) * horizontalScaleFactor;
  69910. pg->font.setHorizontalScale (pg->font.getHorizontalScale() * horizontalScaleFactor);
  69911. pg->w *= horizontalScaleFactor;
  69912. }
  69913. }
  69914. }
  69915. void GlyphArrangement::getBoundingBox (int startIndex, int num,
  69916. float& left,
  69917. float& top,
  69918. float& right,
  69919. float& bottom,
  69920. const bool includeWhitespace) const
  69921. {
  69922. jassert (startIndex >= 0);
  69923. if (num < 0 || startIndex + num > glyphs.size())
  69924. num = glyphs.size() - startIndex;
  69925. left = 0.0f;
  69926. top = 0.0f;
  69927. right = 0.0f;
  69928. bottom = 0.0f;
  69929. bool isFirst = true;
  69930. while (--num >= 0)
  69931. {
  69932. const PositionedGlyph* const pg = glyphs.getUnchecked (startIndex++);
  69933. if (includeWhitespace || ! pg->isWhitespace())
  69934. {
  69935. if (isFirst)
  69936. {
  69937. isFirst = false;
  69938. left = pg->getLeft();
  69939. top = pg->getTop();
  69940. right = pg->getRight();
  69941. bottom = pg->getBottom();
  69942. }
  69943. else
  69944. {
  69945. left = jmin (left, pg->getLeft());
  69946. top = jmin (top, pg->getTop());
  69947. right = jmax (right, pg->getRight());
  69948. bottom = jmax (bottom, pg->getBottom());
  69949. }
  69950. }
  69951. }
  69952. }
  69953. void GlyphArrangement::justifyGlyphs (const int startIndex,
  69954. const int num,
  69955. const float x, const float y,
  69956. const float width, const float height,
  69957. const Justification& justification)
  69958. {
  69959. jassert (num >= 0 && startIndex >= 0);
  69960. if (glyphs.size() > 0 && num > 0)
  69961. {
  69962. float left, top, right, bottom;
  69963. getBoundingBox (startIndex, num, left, top, right, bottom,
  69964. ! justification.testFlags (Justification::horizontallyJustified
  69965. | Justification::horizontallyCentred));
  69966. float deltaX = 0.0f;
  69967. if (justification.testFlags (Justification::horizontallyJustified))
  69968. deltaX = x - left;
  69969. else if (justification.testFlags (Justification::horizontallyCentred))
  69970. deltaX = x + (width - (right - left)) * 0.5f - left;
  69971. else if (justification.testFlags (Justification::right))
  69972. deltaX = (x + width) - right;
  69973. else
  69974. deltaX = x - left;
  69975. float deltaY = 0.0f;
  69976. if (justification.testFlags (Justification::top))
  69977. deltaY = y - top;
  69978. else if (justification.testFlags (Justification::bottom))
  69979. deltaY = (y + height) - bottom;
  69980. else
  69981. deltaY = y + (height - (bottom - top)) * 0.5f - top;
  69982. moveRangeOfGlyphs (startIndex, num, deltaX, deltaY);
  69983. if (justification.testFlags (Justification::horizontallyJustified))
  69984. {
  69985. int lineStart = 0;
  69986. float baseY = glyphs.getUnchecked (startIndex)->getBaselineY();
  69987. int i;
  69988. for (i = 0; i < num; ++i)
  69989. {
  69990. const float glyphY = glyphs.getUnchecked (startIndex + i)->getBaselineY();
  69991. if (glyphY != baseY)
  69992. {
  69993. spreadOutLine (startIndex + lineStart, i - lineStart, width);
  69994. lineStart = i;
  69995. baseY = glyphY;
  69996. }
  69997. }
  69998. if (i > lineStart)
  69999. spreadOutLine (startIndex + lineStart, i - lineStart, width);
  70000. }
  70001. }
  70002. }
  70003. void GlyphArrangement::spreadOutLine (const int start, const int num, const float targetWidth)
  70004. {
  70005. if (start + num < glyphs.size()
  70006. && glyphs.getUnchecked (start + num - 1)->getCharacter() != T('\r')
  70007. && glyphs.getUnchecked (start + num - 1)->getCharacter() != T('\n'))
  70008. {
  70009. int numSpaces = 0;
  70010. int spacesAtEnd = 0;
  70011. for (int i = 0; i < num; ++i)
  70012. {
  70013. if (glyphs.getUnchecked (start + i)->isWhitespace())
  70014. {
  70015. ++spacesAtEnd;
  70016. ++numSpaces;
  70017. }
  70018. else
  70019. {
  70020. spacesAtEnd = 0;
  70021. }
  70022. }
  70023. numSpaces -= spacesAtEnd;
  70024. if (numSpaces > 0)
  70025. {
  70026. const float startX = glyphs.getUnchecked (start)->getLeft();
  70027. const float endX = glyphs.getUnchecked (start + num - 1 - spacesAtEnd)->getRight();
  70028. const float extraPaddingBetweenWords
  70029. = (targetWidth - (endX - startX)) / (float) numSpaces;
  70030. float deltaX = 0.0f;
  70031. for (int i = 0; i < num; ++i)
  70032. {
  70033. glyphs.getUnchecked (start + i)->moveBy (deltaX, 0.0f);
  70034. if (glyphs.getUnchecked (start + i)->isWhitespace())
  70035. deltaX += extraPaddingBetweenWords;
  70036. }
  70037. }
  70038. }
  70039. }
  70040. void GlyphArrangement::draw (const Graphics& g) const
  70041. {
  70042. for (int i = 0; i < glyphs.size(); ++i)
  70043. {
  70044. const PositionedGlyph* const pg = glyphs.getUnchecked(i);
  70045. if (pg->font.isUnderlined())
  70046. {
  70047. const float lineThickness = (pg->font.getDescent()) * 0.3f;
  70048. float nextX = pg->x + pg->w;
  70049. if (i < glyphs.size() - 1 && glyphs.getUnchecked (i + 1)->y == pg->y)
  70050. nextX = glyphs.getUnchecked (i + 1)->x;
  70051. g.fillRect (pg->x, pg->y + lineThickness * 2.0f,
  70052. nextX - pg->x, lineThickness);
  70053. }
  70054. pg->draw (g);
  70055. }
  70056. }
  70057. void GlyphArrangement::draw (const Graphics& g, const AffineTransform& transform) const
  70058. {
  70059. for (int i = 0; i < glyphs.size(); ++i)
  70060. {
  70061. const PositionedGlyph* const pg = glyphs.getUnchecked(i);
  70062. if (pg->font.isUnderlined())
  70063. {
  70064. const float lineThickness = (pg->font.getDescent()) * 0.3f;
  70065. float nextX = pg->x + pg->w;
  70066. if (i < glyphs.size() - 1 && glyphs.getUnchecked (i + 1)->y == pg->y)
  70067. nextX = glyphs.getUnchecked (i + 1)->x;
  70068. Path p;
  70069. p.addLineSegment (pg->x, pg->y + lineThickness * 2.0f,
  70070. nextX, pg->y + lineThickness * 2.0f,
  70071. lineThickness);
  70072. g.fillPath (p, transform);
  70073. }
  70074. pg->draw (g, transform);
  70075. }
  70076. }
  70077. void GlyphArrangement::createPath (Path& path) const
  70078. {
  70079. for (int i = 0; i < glyphs.size(); ++i)
  70080. glyphs.getUnchecked (i)->createPath (path);
  70081. }
  70082. int GlyphArrangement::findGlyphIndexAt (float x, float y) const
  70083. {
  70084. for (int i = 0; i < glyphs.size(); ++i)
  70085. if (glyphs.getUnchecked (i)->hitTest (x, y))
  70086. return i;
  70087. return -1;
  70088. }
  70089. END_JUCE_NAMESPACE
  70090. /*** End of inlined file: juce_GlyphArrangement.cpp ***/
  70091. /*** Start of inlined file: juce_TextLayout.cpp ***/
  70092. BEGIN_JUCE_NAMESPACE
  70093. class TextLayout::Token
  70094. {
  70095. public:
  70096. String text;
  70097. Font font;
  70098. int x, y, w, h;
  70099. int line, lineHeight;
  70100. bool isWhitespace, isNewLine;
  70101. Token (const String& t,
  70102. const Font& f,
  70103. const bool isWhitespace_) throw()
  70104. : text (t),
  70105. font (f),
  70106. x(0),
  70107. y(0),
  70108. isWhitespace (isWhitespace_)
  70109. {
  70110. w = font.getStringWidth (t);
  70111. h = roundToInt (f.getHeight());
  70112. isNewLine = t.containsAnyOf (T("\r\n"));
  70113. }
  70114. Token (const Token& other) throw()
  70115. : text (other.text),
  70116. font (other.font),
  70117. x (other.x),
  70118. y (other.y),
  70119. w (other.w),
  70120. h (other.h),
  70121. line (other.line),
  70122. lineHeight (other.lineHeight),
  70123. isWhitespace (other.isWhitespace),
  70124. isNewLine (other.isNewLine)
  70125. {
  70126. }
  70127. ~Token() throw()
  70128. {
  70129. }
  70130. void draw (Graphics& g,
  70131. const int xOffset,
  70132. const int yOffset) throw()
  70133. {
  70134. if (! isWhitespace)
  70135. {
  70136. g.setFont (font);
  70137. g.drawSingleLineText (text.trimEnd(),
  70138. xOffset + x,
  70139. yOffset + y + (lineHeight - h)
  70140. + roundToInt (font.getAscent()));
  70141. }
  70142. }
  70143. juce_UseDebuggingNewOperator
  70144. };
  70145. TextLayout::TextLayout() throw()
  70146. : totalLines (0)
  70147. {
  70148. tokens.ensureStorageAllocated (64);
  70149. }
  70150. TextLayout::TextLayout (const String& text,
  70151. const Font& font) throw()
  70152. : totalLines (0)
  70153. {
  70154. tokens.ensureStorageAllocated (64);
  70155. appendText (text, font);
  70156. }
  70157. TextLayout::TextLayout (const TextLayout& other) throw()
  70158. : totalLines (0)
  70159. {
  70160. *this = other;
  70161. }
  70162. const TextLayout& TextLayout::operator= (const TextLayout& other) throw()
  70163. {
  70164. if (this != &other)
  70165. {
  70166. clear();
  70167. totalLines = other.totalLines;
  70168. for (int i = 0; i < other.tokens.size(); ++i)
  70169. tokens.add (new Token (*other.tokens.getUnchecked(i)));
  70170. }
  70171. return *this;
  70172. }
  70173. TextLayout::~TextLayout() throw()
  70174. {
  70175. clear();
  70176. }
  70177. void TextLayout::clear() throw()
  70178. {
  70179. tokens.clear();
  70180. totalLines = 0;
  70181. }
  70182. void TextLayout::appendText (const String& text,
  70183. const Font& font) throw()
  70184. {
  70185. const tchar* t = text;
  70186. String currentString;
  70187. int lastCharType = 0;
  70188. for (;;)
  70189. {
  70190. const tchar c = *t++;
  70191. if (c == 0)
  70192. break;
  70193. int charType;
  70194. if (c == T('\r') || c == T('\n'))
  70195. {
  70196. charType = 0;
  70197. }
  70198. else if (CharacterFunctions::isWhitespace (c))
  70199. {
  70200. charType = 2;
  70201. }
  70202. else
  70203. {
  70204. charType = 1;
  70205. }
  70206. if (charType == 0 || charType != lastCharType)
  70207. {
  70208. if (currentString.isNotEmpty())
  70209. {
  70210. tokens.add (new Token (currentString, font,
  70211. lastCharType == 2 || lastCharType == 0));
  70212. }
  70213. currentString = String::charToString (c);
  70214. if (c == T('\r') && *t == T('\n'))
  70215. currentString += *t++;
  70216. }
  70217. else
  70218. {
  70219. currentString += c;
  70220. }
  70221. lastCharType = charType;
  70222. }
  70223. if (currentString.isNotEmpty())
  70224. tokens.add (new Token (currentString, font, lastCharType == 2));
  70225. }
  70226. void TextLayout::setText (const String& text, const Font& font) throw()
  70227. {
  70228. clear();
  70229. appendText (text, font);
  70230. }
  70231. void TextLayout::layout (int maxWidth,
  70232. const Justification& justification,
  70233. const bool attemptToBalanceLineLengths) throw()
  70234. {
  70235. if (attemptToBalanceLineLengths)
  70236. {
  70237. const int originalW = maxWidth;
  70238. int bestWidth = maxWidth;
  70239. float bestLineProportion = 0.0f;
  70240. while (maxWidth > originalW / 2)
  70241. {
  70242. layout (maxWidth, justification, false);
  70243. if (getNumLines() <= 1)
  70244. return;
  70245. const int lastLineW = getLineWidth (getNumLines() - 1);
  70246. const int lastButOneLineW = getLineWidth (getNumLines() - 2);
  70247. const float prop = lastLineW / (float) lastButOneLineW;
  70248. if (prop > 0.9f)
  70249. return;
  70250. if (prop > bestLineProportion)
  70251. {
  70252. bestLineProportion = prop;
  70253. bestWidth = maxWidth;
  70254. }
  70255. maxWidth -= 10;
  70256. }
  70257. layout (bestWidth, justification, false);
  70258. }
  70259. else
  70260. {
  70261. int x = 0;
  70262. int y = 0;
  70263. int h = 0;
  70264. totalLines = 0;
  70265. int i;
  70266. for (i = 0; i < tokens.size(); ++i)
  70267. {
  70268. Token* const t = tokens.getUnchecked(i);
  70269. t->x = x;
  70270. t->y = y;
  70271. t->line = totalLines;
  70272. x += t->w;
  70273. h = jmax (h, t->h);
  70274. const Token* nextTok = tokens [i + 1];
  70275. if (nextTok == 0)
  70276. break;
  70277. if (t->isNewLine || ((! nextTok->isWhitespace) && x + nextTok->w > maxWidth))
  70278. {
  70279. // finished a line, so go back and update the heights of the things on it
  70280. for (int j = i; j >= 0; --j)
  70281. {
  70282. Token* const tok = tokens.getUnchecked(j);
  70283. if (tok->line == totalLines)
  70284. tok->lineHeight = h;
  70285. else
  70286. break;
  70287. }
  70288. x = 0;
  70289. y += h;
  70290. h = 0;
  70291. ++totalLines;
  70292. }
  70293. }
  70294. // finished a line, so go back and update the heights of the things on it
  70295. for (int j = jmin (i, tokens.size() - 1); j >= 0; --j)
  70296. {
  70297. Token* const t = tokens.getUnchecked(j);
  70298. if (t->line == totalLines)
  70299. t->lineHeight = h;
  70300. else
  70301. break;
  70302. }
  70303. ++totalLines;
  70304. if (! justification.testFlags (Justification::left))
  70305. {
  70306. int totalW = getWidth();
  70307. for (i = totalLines; --i >= 0;)
  70308. {
  70309. const int lineW = getLineWidth (i);
  70310. int dx = 0;
  70311. if (justification.testFlags (Justification::horizontallyCentred))
  70312. dx = (totalW - lineW) / 2;
  70313. else if (justification.testFlags (Justification::right))
  70314. dx = totalW - lineW;
  70315. for (int j = tokens.size(); --j >= 0;)
  70316. {
  70317. Token* const t = tokens.getUnchecked(j);
  70318. if (t->line == i)
  70319. t->x += dx;
  70320. }
  70321. }
  70322. }
  70323. }
  70324. }
  70325. int TextLayout::getLineWidth (const int lineNumber) const throw()
  70326. {
  70327. int maxW = 0;
  70328. for (int i = tokens.size(); --i >= 0;)
  70329. {
  70330. const Token* const t = tokens.getUnchecked(i);
  70331. if (t->line == lineNumber && ! t->isWhitespace)
  70332. maxW = jmax (maxW, t->x + t->w);
  70333. }
  70334. return maxW;
  70335. }
  70336. int TextLayout::getWidth() const throw()
  70337. {
  70338. int maxW = 0;
  70339. for (int i = tokens.size(); --i >= 0;)
  70340. {
  70341. const Token* const t = tokens.getUnchecked(i);
  70342. if (! t->isWhitespace)
  70343. maxW = jmax (maxW, t->x + t->w);
  70344. }
  70345. return maxW;
  70346. }
  70347. int TextLayout::getHeight() const throw()
  70348. {
  70349. int maxH = 0;
  70350. for (int i = tokens.size(); --i >= 0;)
  70351. {
  70352. const Token* const t = tokens.getUnchecked(i);
  70353. if (! t->isWhitespace)
  70354. maxH = jmax (maxH, t->y + t->h);
  70355. }
  70356. return maxH;
  70357. }
  70358. void TextLayout::draw (Graphics& g,
  70359. const int xOffset,
  70360. const int yOffset) const throw()
  70361. {
  70362. for (int i = tokens.size(); --i >= 0;)
  70363. tokens.getUnchecked(i)->draw (g, xOffset, yOffset);
  70364. }
  70365. void TextLayout::drawWithin (Graphics& g,
  70366. int x, int y, int w, int h,
  70367. const Justification& justification) const throw()
  70368. {
  70369. justification.applyToRectangle (x, y, getWidth(), getHeight(),
  70370. x, y, w, h);
  70371. draw (g, x, y);
  70372. }
  70373. END_JUCE_NAMESPACE
  70374. /*** End of inlined file: juce_TextLayout.cpp ***/
  70375. /*** Start of inlined file: juce_Typeface.cpp ***/
  70376. BEGIN_JUCE_NAMESPACE
  70377. Typeface::Typeface (const String& name_) throw()
  70378. : name (name_)
  70379. {
  70380. }
  70381. Typeface::~Typeface()
  70382. {
  70383. }
  70384. class CustomTypeface::GlyphInfo
  70385. {
  70386. public:
  70387. GlyphInfo (const juce_wchar character_, const Path& path_, const float width_) throw()
  70388. : character (character_), path (path_), width (width_)
  70389. {
  70390. }
  70391. ~GlyphInfo() throw()
  70392. {
  70393. }
  70394. struct KerningPair
  70395. {
  70396. juce_wchar character2;
  70397. float kerningAmount;
  70398. };
  70399. void addKerningPair (const juce_wchar subsequentCharacter,
  70400. const float extraKerningAmount) throw()
  70401. {
  70402. KerningPair kp;
  70403. kp.character2 = subsequentCharacter;
  70404. kp.kerningAmount = extraKerningAmount;
  70405. kerningPairs.add (kp);
  70406. }
  70407. float getHorizontalSpacing (const juce_wchar subsequentCharacter) const throw()
  70408. {
  70409. if (subsequentCharacter != 0)
  70410. {
  70411. for (int i = kerningPairs.size(); --i >= 0;)
  70412. if (kerningPairs.getReference(i).character2 == subsequentCharacter)
  70413. return width + kerningPairs.getReference(i).kerningAmount;
  70414. }
  70415. return width;
  70416. }
  70417. const juce_wchar character;
  70418. const Path path;
  70419. float width;
  70420. Array <KerningPair> kerningPairs;
  70421. juce_UseDebuggingNewOperator
  70422. private:
  70423. GlyphInfo (const GlyphInfo&);
  70424. const GlyphInfo& operator= (const GlyphInfo&);
  70425. };
  70426. CustomTypeface::CustomTypeface()
  70427. : Typeface (String::empty)
  70428. {
  70429. clear();
  70430. }
  70431. CustomTypeface::CustomTypeface (InputStream& serialisedTypefaceStream)
  70432. : Typeface (String::empty)
  70433. {
  70434. clear();
  70435. GZIPDecompressorInputStream gzin (&serialisedTypefaceStream, false);
  70436. BufferedInputStream in (&gzin, 32768, false);
  70437. name = in.readString();
  70438. isBold = in.readBool();
  70439. isItalic = in.readBool();
  70440. ascent = in.readFloat();
  70441. defaultCharacter = (juce_wchar) in.readShort();
  70442. int i, numChars = in.readInt();
  70443. for (i = 0; i < numChars; ++i)
  70444. {
  70445. const juce_wchar c = (juce_wchar) in.readShort();
  70446. const float width = in.readFloat();
  70447. Path p;
  70448. p.loadPathFromStream (in);
  70449. addGlyph (c, p, width);
  70450. }
  70451. const int numKerningPairs = in.readInt();
  70452. for (i = 0; i < numKerningPairs; ++i)
  70453. {
  70454. const juce_wchar char1 = (juce_wchar) in.readShort();
  70455. const juce_wchar char2 = (juce_wchar) in.readShort();
  70456. addKerningPair (char1, char2, in.readFloat());
  70457. }
  70458. }
  70459. CustomTypeface::~CustomTypeface()
  70460. {
  70461. }
  70462. void CustomTypeface::clear()
  70463. {
  70464. defaultCharacter = 0;
  70465. ascent = 1.0f;
  70466. isBold = isItalic = false;
  70467. zeromem (lookupTable, sizeof (lookupTable));
  70468. glyphs.clear();
  70469. }
  70470. void CustomTypeface::setCharacteristics (const String& name_, const float ascent_, const bool isBold_,
  70471. const bool isItalic_, const juce_wchar defaultCharacter_) throw()
  70472. {
  70473. name = name_;
  70474. defaultCharacter = defaultCharacter_;
  70475. ascent = ascent_;
  70476. isBold = isBold_;
  70477. isItalic = isItalic_;
  70478. }
  70479. void CustomTypeface::addGlyph (const juce_wchar character, const Path& path, const float width) throw()
  70480. {
  70481. // Check that you're not trying to add the same character twice..
  70482. jassert (findGlyph (character, false) == 0);
  70483. if (((unsigned int) character) < (unsigned int) numElementsInArray (lookupTable))
  70484. lookupTable [character] = (short) glyphs.size();
  70485. glyphs.add (new GlyphInfo (character, path, width));
  70486. }
  70487. void CustomTypeface::addKerningPair (const juce_wchar char1, const juce_wchar char2, const float extraAmount) throw()
  70488. {
  70489. if (extraAmount != 0)
  70490. {
  70491. GlyphInfo* const g = findGlyph (char1, true);
  70492. jassert (g != 0); // can only add kerning pairs for characters that exist!
  70493. if (g != 0)
  70494. g->addKerningPair (char2, extraAmount);
  70495. }
  70496. }
  70497. CustomTypeface::GlyphInfo* CustomTypeface::findGlyph (const juce_wchar character, const bool loadIfNeeded) throw()
  70498. {
  70499. if (((unsigned int) character) < (unsigned int) numElementsInArray (lookupTable) && lookupTable [character] > 0)
  70500. return glyphs [(int) lookupTable [(int) character]];
  70501. for (int i = 0; i < glyphs.size(); ++i)
  70502. {
  70503. GlyphInfo* const g = glyphs.getUnchecked(i);
  70504. if (g->character == character)
  70505. return g;
  70506. }
  70507. if (loadIfNeeded && loadGlyphIfPossible (character))
  70508. return findGlyph (character, false);
  70509. return 0;
  70510. }
  70511. CustomTypeface::GlyphInfo* CustomTypeface::findGlyphSubstituting (const juce_wchar character) throw()
  70512. {
  70513. GlyphInfo* glyph = findGlyph (character, true);
  70514. if (glyph == 0)
  70515. {
  70516. if (CharacterFunctions::isWhitespace (character) && character != L' ')
  70517. glyph = findGlyph (L' ', true);
  70518. if (glyph == 0)
  70519. {
  70520. const Font fallbackFont (Font::getFallbackFontName(), 10, 0);
  70521. Typeface* const fallbackTypeface = fallbackFont.getTypeface();
  70522. if (fallbackTypeface != 0 && fallbackTypeface != this)
  70523. {
  70524. //xxx
  70525. }
  70526. if (glyph == 0)
  70527. glyph = findGlyph (defaultCharacter, true);
  70528. }
  70529. }
  70530. return glyph;
  70531. }
  70532. bool CustomTypeface::loadGlyphIfPossible (const juce_wchar /*characterNeeded*/)
  70533. {
  70534. return false;
  70535. }
  70536. void CustomTypeface::addGlyphsFromOtherTypeface (Typeface& typefaceToCopy, juce_wchar characterStartIndex, int numCharacters) throw()
  70537. {
  70538. for (int i = 0; i < numCharacters; ++i)
  70539. {
  70540. const juce_wchar c = (juce_wchar) (characterStartIndex + i);
  70541. Array <int> glyphIndexes;
  70542. Array <float> offsets;
  70543. typefaceToCopy.getGlyphPositions (String::charToString (c), glyphIndexes, offsets);
  70544. const int glyphIndex = glyphIndexes.getFirst();
  70545. if (glyphIndex >= 0 && glyphIndexes.size() > 0)
  70546. {
  70547. const float glyphWidth = offsets[1];
  70548. Path p;
  70549. typefaceToCopy.getOutlineForGlyph (glyphIndex, p);
  70550. addGlyph (c, p, glyphWidth);
  70551. for (int j = glyphs.size() - 1; --j >= 0;)
  70552. {
  70553. const juce_wchar char2 = glyphs.getUnchecked (j)->character;
  70554. glyphIndexes.clearQuick();
  70555. offsets.clearQuick();
  70556. typefaceToCopy.getGlyphPositions (String::charToString (c) + String::charToString (char2), glyphIndexes, offsets);
  70557. if (offsets.size() > 1)
  70558. addKerningPair (c, char2, offsets[1] - glyphWidth);
  70559. }
  70560. }
  70561. }
  70562. }
  70563. bool CustomTypeface::writeToStream (OutputStream& outputStream)
  70564. {
  70565. GZIPCompressorOutputStream out (&outputStream);
  70566. out.writeString (name);
  70567. out.writeBool (isBold);
  70568. out.writeBool (isItalic);
  70569. out.writeFloat (ascent);
  70570. out.writeShort ((short) (unsigned short) defaultCharacter);
  70571. out.writeInt (glyphs.size());
  70572. int i, numKerningPairs = 0;
  70573. for (i = 0; i < glyphs.size(); ++i)
  70574. {
  70575. const GlyphInfo* const g = glyphs.getUnchecked (i);
  70576. out.writeShort ((short) (unsigned short) g->character);
  70577. out.writeFloat (g->width);
  70578. g->path.writePathToStream (out);
  70579. numKerningPairs += g->kerningPairs.size();
  70580. }
  70581. out.writeInt (numKerningPairs);
  70582. for (i = 0; i < glyphs.size(); ++i)
  70583. {
  70584. const GlyphInfo* const g = glyphs.getUnchecked (i);
  70585. for (int j = 0; j < g->kerningPairs.size(); ++j)
  70586. {
  70587. const GlyphInfo::KerningPair& p = g->kerningPairs.getReference (j);
  70588. out.writeShort ((short) (unsigned short) g->character);
  70589. out.writeShort ((short) (unsigned short) p.character2);
  70590. out.writeFloat (p.kerningAmount);
  70591. }
  70592. }
  70593. return true;
  70594. }
  70595. float CustomTypeface::getAscent() const
  70596. {
  70597. return ascent;
  70598. }
  70599. float CustomTypeface::getDescent() const
  70600. {
  70601. return 1.0f - ascent;
  70602. }
  70603. float CustomTypeface::getStringWidth (const String& text)
  70604. {
  70605. float x = 0;
  70606. const juce_wchar* t = (const juce_wchar*) text;
  70607. while (*t != 0)
  70608. {
  70609. const GlyphInfo* const glyph = findGlyphSubstituting (*t++);
  70610. if (glyph != 0)
  70611. x += glyph->getHorizontalSpacing (*t);
  70612. }
  70613. return x;
  70614. }
  70615. void CustomTypeface::getGlyphPositions (const String& text, Array <int>& resultGlyphs, Array<float>& xOffsets)
  70616. {
  70617. xOffsets.add (0);
  70618. float x = 0;
  70619. const juce_wchar* t = (const juce_wchar*) text;
  70620. while (*t != 0)
  70621. {
  70622. const juce_wchar c = *t++;
  70623. const GlyphInfo* const glyph = findGlyphSubstituting (c);
  70624. if (glyph != 0)
  70625. {
  70626. x += glyph->getHorizontalSpacing (*t);
  70627. resultGlyphs.add ((int) glyph->character);
  70628. xOffsets.add (x);
  70629. }
  70630. }
  70631. }
  70632. bool CustomTypeface::getOutlineForGlyph (int glyphNumber, Path& path)
  70633. {
  70634. const GlyphInfo* const glyph = findGlyphSubstituting ((juce_wchar) glyphNumber);
  70635. if (glyph != 0)
  70636. {
  70637. path = glyph->path;
  70638. return true;
  70639. }
  70640. return false;
  70641. }
  70642. END_JUCE_NAMESPACE
  70643. /*** End of inlined file: juce_Typeface.cpp ***/
  70644. /*** Start of inlined file: juce_AffineTransform.cpp ***/
  70645. BEGIN_JUCE_NAMESPACE
  70646. AffineTransform::AffineTransform() throw()
  70647. : mat00 (1.0f),
  70648. mat01 (0),
  70649. mat02 (0),
  70650. mat10 (0),
  70651. mat11 (1.0f),
  70652. mat12 (0)
  70653. {
  70654. }
  70655. AffineTransform::AffineTransform (const AffineTransform& other) throw()
  70656. : mat00 (other.mat00),
  70657. mat01 (other.mat01),
  70658. mat02 (other.mat02),
  70659. mat10 (other.mat10),
  70660. mat11 (other.mat11),
  70661. mat12 (other.mat12)
  70662. {
  70663. }
  70664. AffineTransform::AffineTransform (const float mat00_,
  70665. const float mat01_,
  70666. const float mat02_,
  70667. const float mat10_,
  70668. const float mat11_,
  70669. const float mat12_) throw()
  70670. : mat00 (mat00_),
  70671. mat01 (mat01_),
  70672. mat02 (mat02_),
  70673. mat10 (mat10_),
  70674. mat11 (mat11_),
  70675. mat12 (mat12_)
  70676. {
  70677. }
  70678. const AffineTransform& AffineTransform::operator= (const AffineTransform& other) throw()
  70679. {
  70680. mat00 = other.mat00;
  70681. mat01 = other.mat01;
  70682. mat02 = other.mat02;
  70683. mat10 = other.mat10;
  70684. mat11 = other.mat11;
  70685. mat12 = other.mat12;
  70686. return *this;
  70687. }
  70688. bool AffineTransform::operator== (const AffineTransform& other) const throw()
  70689. {
  70690. return mat00 == other.mat00
  70691. && mat01 == other.mat01
  70692. && mat02 == other.mat02
  70693. && mat10 == other.mat10
  70694. && mat11 == other.mat11
  70695. && mat12 == other.mat12;
  70696. }
  70697. bool AffineTransform::operator!= (const AffineTransform& other) const throw()
  70698. {
  70699. return ! operator== (other);
  70700. }
  70701. bool AffineTransform::isIdentity() const throw()
  70702. {
  70703. return (mat01 == 0)
  70704. && (mat02 == 0)
  70705. && (mat10 == 0)
  70706. && (mat12 == 0)
  70707. && (mat00 == 1.0f)
  70708. && (mat11 == 1.0f);
  70709. }
  70710. const AffineTransform AffineTransform::identity;
  70711. const AffineTransform AffineTransform::followedBy (const AffineTransform& other) const throw()
  70712. {
  70713. return AffineTransform (other.mat00 * mat00 + other.mat01 * mat10,
  70714. other.mat00 * mat01 + other.mat01 * mat11,
  70715. other.mat00 * mat02 + other.mat01 * mat12 + other.mat02,
  70716. other.mat10 * mat00 + other.mat11 * mat10,
  70717. other.mat10 * mat01 + other.mat11 * mat11,
  70718. other.mat10 * mat02 + other.mat11 * mat12 + other.mat12);
  70719. }
  70720. const AffineTransform AffineTransform::followedBy (const float omat00,
  70721. const float omat01,
  70722. const float omat02,
  70723. const float omat10,
  70724. const float omat11,
  70725. const float omat12) const throw()
  70726. {
  70727. return AffineTransform (omat00 * mat00 + omat01 * mat10,
  70728. omat00 * mat01 + omat01 * mat11,
  70729. omat00 * mat02 + omat01 * mat12 + omat02,
  70730. omat10 * mat00 + omat11 * mat10,
  70731. omat10 * mat01 + omat11 * mat11,
  70732. omat10 * mat02 + omat11 * mat12 + omat12);
  70733. }
  70734. const AffineTransform AffineTransform::translated (const float dx,
  70735. const float dy) const throw()
  70736. {
  70737. return AffineTransform (mat00, mat01, mat02 + dx,
  70738. mat10, mat11, mat12 + dy);
  70739. }
  70740. const AffineTransform AffineTransform::translation (const float dx,
  70741. const float dy) throw()
  70742. {
  70743. return AffineTransform (1.0f, 0, dx,
  70744. 0, 1.0f, dy);
  70745. }
  70746. const AffineTransform AffineTransform::rotated (const float rad) const throw()
  70747. {
  70748. const float cosRad = cosf (rad);
  70749. const float sinRad = sinf (rad);
  70750. return followedBy (cosRad, -sinRad, 0,
  70751. sinRad, cosRad, 0);
  70752. }
  70753. const AffineTransform AffineTransform::rotation (const float rad) throw()
  70754. {
  70755. const float cosRad = cosf (rad);
  70756. const float sinRad = sinf (rad);
  70757. return AffineTransform (cosRad, -sinRad, 0,
  70758. sinRad, cosRad, 0);
  70759. }
  70760. const AffineTransform AffineTransform::rotated (const float angle,
  70761. const float pivotX,
  70762. const float pivotY) const throw()
  70763. {
  70764. return translated (-pivotX, -pivotY)
  70765. .rotated (angle)
  70766. .translated (pivotX, pivotY);
  70767. }
  70768. const AffineTransform AffineTransform::rotation (const float angle,
  70769. const float pivotX,
  70770. const float pivotY) throw()
  70771. {
  70772. return translation (-pivotX, -pivotY)
  70773. .rotated (angle)
  70774. .translated (pivotX, pivotY);
  70775. }
  70776. const AffineTransform AffineTransform::scaled (const float factorX,
  70777. const float factorY) const throw()
  70778. {
  70779. return AffineTransform (factorX * mat00, factorX * mat01, factorX * mat02,
  70780. factorY * mat10, factorY * mat11, factorY * mat12);
  70781. }
  70782. const AffineTransform AffineTransform::scale (const float factorX,
  70783. const float factorY) throw()
  70784. {
  70785. return AffineTransform (factorX, 0, 0,
  70786. 0, factorY, 0);
  70787. }
  70788. const AffineTransform AffineTransform::sheared (const float shearX,
  70789. const float shearY) const throw()
  70790. {
  70791. return followedBy (1.0f, shearX, 0,
  70792. shearY, 1.0f, 0);
  70793. }
  70794. const AffineTransform AffineTransform::inverted() const throw()
  70795. {
  70796. double determinant = (mat00 * mat11 - mat10 * mat01);
  70797. if (determinant != 0.0)
  70798. {
  70799. determinant = 1.0 / determinant;
  70800. const float dst00 = (float) (mat11 * determinant);
  70801. const float dst10 = (float) (-mat10 * determinant);
  70802. const float dst01 = (float) (-mat01 * determinant);
  70803. const float dst11 = (float) (mat00 * determinant);
  70804. return AffineTransform (dst00, dst01, -mat02 * dst00 - mat12 * dst01,
  70805. dst10, dst11, -mat02 * dst10 - mat12 * dst11);
  70806. }
  70807. else
  70808. {
  70809. // singularity..
  70810. return *this;
  70811. }
  70812. }
  70813. bool AffineTransform::isSingularity() const throw()
  70814. {
  70815. return (mat00 * mat11 - mat10 * mat01) == 0.0;
  70816. }
  70817. bool AffineTransform::isOnlyTranslation() const throw()
  70818. {
  70819. return (mat01 == 0)
  70820. && (mat10 == 0)
  70821. && (mat00 == 1.0f)
  70822. && (mat11 == 1.0f);
  70823. }
  70824. void AffineTransform::transformPoint (float& x,
  70825. float& y) const throw()
  70826. {
  70827. const float oldX = x;
  70828. x = mat00 * oldX + mat01 * y + mat02;
  70829. y = mat10 * oldX + mat11 * y + mat12;
  70830. }
  70831. void AffineTransform::transformPoint (double& x,
  70832. double& y) const throw()
  70833. {
  70834. const double oldX = x;
  70835. x = mat00 * oldX + mat01 * y + mat02;
  70836. y = mat10 * oldX + mat11 * y + mat12;
  70837. }
  70838. END_JUCE_NAMESPACE
  70839. /*** End of inlined file: juce_AffineTransform.cpp ***/
  70840. /*** Start of inlined file: juce_BorderSize.cpp ***/
  70841. BEGIN_JUCE_NAMESPACE
  70842. BorderSize::BorderSize() throw()
  70843. : top (0),
  70844. left (0),
  70845. bottom (0),
  70846. right (0)
  70847. {
  70848. }
  70849. BorderSize::BorderSize (const BorderSize& other) throw()
  70850. : top (other.top),
  70851. left (other.left),
  70852. bottom (other.bottom),
  70853. right (other.right)
  70854. {
  70855. }
  70856. BorderSize::BorderSize (const int topGap,
  70857. const int leftGap,
  70858. const int bottomGap,
  70859. const int rightGap) throw()
  70860. : top (topGap),
  70861. left (leftGap),
  70862. bottom (bottomGap),
  70863. right (rightGap)
  70864. {
  70865. }
  70866. BorderSize::BorderSize (const int allGaps) throw()
  70867. : top (allGaps),
  70868. left (allGaps),
  70869. bottom (allGaps),
  70870. right (allGaps)
  70871. {
  70872. }
  70873. BorderSize::~BorderSize() throw()
  70874. {
  70875. }
  70876. void BorderSize::setTop (const int newTopGap) throw()
  70877. {
  70878. top = newTopGap;
  70879. }
  70880. void BorderSize::setLeft (const int newLeftGap) throw()
  70881. {
  70882. left = newLeftGap;
  70883. }
  70884. void BorderSize::setBottom (const int newBottomGap) throw()
  70885. {
  70886. bottom = newBottomGap;
  70887. }
  70888. void BorderSize::setRight (const int newRightGap) throw()
  70889. {
  70890. right = newRightGap;
  70891. }
  70892. const Rectangle<int> BorderSize::subtractedFrom (const Rectangle<int>& r) const throw()
  70893. {
  70894. return Rectangle<int> (r.getX() + left,
  70895. r.getY() + top,
  70896. r.getWidth() - (left + right),
  70897. r.getHeight() - (top + bottom));
  70898. }
  70899. void BorderSize::subtractFrom (Rectangle<int>& r) const throw()
  70900. {
  70901. r.setBounds (r.getX() + left,
  70902. r.getY() + top,
  70903. r.getWidth() - (left + right),
  70904. r.getHeight() - (top + bottom));
  70905. }
  70906. const Rectangle<int> BorderSize::addedTo (const Rectangle<int>& r) const throw()
  70907. {
  70908. return Rectangle<int> (r.getX() - left,
  70909. r.getY() - top,
  70910. r.getWidth() + (left + right),
  70911. r.getHeight() + (top + bottom));
  70912. }
  70913. void BorderSize::addTo (Rectangle<int>& r) const throw()
  70914. {
  70915. r.setBounds (r.getX() - left,
  70916. r.getY() - top,
  70917. r.getWidth() + (left + right),
  70918. r.getHeight() + (top + bottom));
  70919. }
  70920. bool BorderSize::operator== (const BorderSize& other) const throw()
  70921. {
  70922. return top == other.top
  70923. && left == other.left
  70924. && bottom == other.bottom
  70925. && right == other.right;
  70926. }
  70927. bool BorderSize::operator!= (const BorderSize& other) const throw()
  70928. {
  70929. return ! operator== (other);
  70930. }
  70931. END_JUCE_NAMESPACE
  70932. /*** End of inlined file: juce_BorderSize.cpp ***/
  70933. /*** Start of inlined file: juce_Line.cpp ***/
  70934. BEGIN_JUCE_NAMESPACE
  70935. static bool juce_lineIntersection (const float x1, const float y1,
  70936. const float x2, const float y2,
  70937. const float x3, const float y3,
  70938. const float x4, const float y4,
  70939. float& intersectionX,
  70940. float& intersectionY) throw()
  70941. {
  70942. if (x2 != x3 || y2 != y3)
  70943. {
  70944. const float dx1 = x2 - x1;
  70945. const float dy1 = y2 - y1;
  70946. const float dx2 = x4 - x3;
  70947. const float dy2 = y4 - y3;
  70948. const float divisor = dx1 * dy2 - dx2 * dy1;
  70949. if (divisor == 0)
  70950. {
  70951. if (! ((dx1 == 0 && dy1 == 0) || (dx2 == 0 && dy2 == 0)))
  70952. {
  70953. if (dy1 == 0 && dy2 != 0)
  70954. {
  70955. const float along = (y1 - y3) / dy2;
  70956. intersectionX = x3 + along * dx2;
  70957. intersectionY = y1;
  70958. return along >= 0 && along <= 1.0f;
  70959. }
  70960. else if (dy2 == 0 && dy1 != 0)
  70961. {
  70962. const float along = (y3 - y1) / dy1;
  70963. intersectionX = x1 + along * dx1;
  70964. intersectionY = y3;
  70965. return along >= 0 && along <= 1.0f;
  70966. }
  70967. else if (dx1 == 0 && dx2 != 0)
  70968. {
  70969. const float along = (x1 - x3) / dx2;
  70970. intersectionX = x1;
  70971. intersectionY = y3 + along * dy2;
  70972. return along >= 0 && along <= 1.0f;
  70973. }
  70974. else if (dx2 == 0 && dx1 != 0)
  70975. {
  70976. const float along = (x3 - x1) / dx1;
  70977. intersectionX = x3;
  70978. intersectionY = y1 + along * dy1;
  70979. return along >= 0 && along <= 1.0f;
  70980. }
  70981. }
  70982. intersectionX = 0.5f * (x2 + x3);
  70983. intersectionY = 0.5f * (y2 + y3);
  70984. return false;
  70985. }
  70986. const float along1 = ((y1 - y3) * dx2 - (x1 - x3) * dy2) / divisor;
  70987. intersectionX = x1 + along1 * dx1;
  70988. intersectionY = y1 + along1 * dy1;
  70989. if (along1 < 0 || along1 > 1.0f)
  70990. return false;
  70991. const float along2 = ((y1 - y3) * dx1 - (x1 - x3) * dy1) / divisor;
  70992. return along2 >= 0 && along2 <= 1.0f;
  70993. }
  70994. intersectionX = x2;
  70995. intersectionY = y2;
  70996. return true;
  70997. }
  70998. Line::Line() throw()
  70999. : startX (0.0f),
  71000. startY (0.0f),
  71001. endX (0.0f),
  71002. endY (0.0f)
  71003. {
  71004. }
  71005. Line::Line (const Line& other) throw()
  71006. : startX (other.startX),
  71007. startY (other.startY),
  71008. endX (other.endX),
  71009. endY (other.endY)
  71010. {
  71011. }
  71012. Line::Line (const float startX_, const float startY_,
  71013. const float endX_, const float endY_) throw()
  71014. : startX (startX_),
  71015. startY (startY_),
  71016. endX (endX_),
  71017. endY (endY_)
  71018. {
  71019. }
  71020. Line::Line (const Point<float>& start,
  71021. const Point<float>& end) throw()
  71022. : startX (start.getX()),
  71023. startY (start.getY()),
  71024. endX (end.getX()),
  71025. endY (end.getY())
  71026. {
  71027. }
  71028. const Line& Line::operator= (const Line& other) throw()
  71029. {
  71030. startX = other.startX;
  71031. startY = other.startY;
  71032. endX = other.endX;
  71033. endY = other.endY;
  71034. return *this;
  71035. }
  71036. Line::~Line() throw()
  71037. {
  71038. }
  71039. const Point<float> Line::getStart() const throw()
  71040. {
  71041. return Point<float> (startX, startY);
  71042. }
  71043. const Point<float> Line::getEnd() const throw()
  71044. {
  71045. return Point<float> (endX, endY);
  71046. }
  71047. void Line::setStart (const float newStartX,
  71048. const float newStartY) throw()
  71049. {
  71050. startX = newStartX;
  71051. startY = newStartY;
  71052. }
  71053. void Line::setStart (const Point<float>& newStart) throw()
  71054. {
  71055. startX = newStart.getX();
  71056. startY = newStart.getY();
  71057. }
  71058. void Line::setEnd (const float newEndX,
  71059. const float newEndY) throw()
  71060. {
  71061. endX = newEndX;
  71062. endY = newEndY;
  71063. }
  71064. void Line::setEnd (const Point<float>& newEnd) throw()
  71065. {
  71066. endX = newEnd.getX();
  71067. endY = newEnd.getY();
  71068. }
  71069. bool Line::operator== (const Line& other) const throw()
  71070. {
  71071. return startX == other.startX
  71072. && startY == other.startY
  71073. && endX == other.endX
  71074. && endY == other.endY;
  71075. }
  71076. bool Line::operator!= (const Line& other) const throw()
  71077. {
  71078. return startX != other.startX
  71079. || startY != other.startY
  71080. || endX != other.endX
  71081. || endY != other.endY;
  71082. }
  71083. void Line::applyTransform (const AffineTransform& transform) throw()
  71084. {
  71085. transform.transformPoint (startX, startY);
  71086. transform.transformPoint (endX, endY);
  71087. }
  71088. float Line::getLength() const throw()
  71089. {
  71090. return (float) juce_hypot (startX - endX,
  71091. startY - endY);
  71092. }
  71093. float Line::getAngle() const throw()
  71094. {
  71095. return atan2f (endX - startX,
  71096. endY - startY);
  71097. }
  71098. const Point<float> Line::getPointAlongLine (const float distanceFromStart) const throw()
  71099. {
  71100. const float alpha = distanceFromStart / getLength();
  71101. return Point<float> (startX + (endX - startX) * alpha,
  71102. startY + (endY - startY) * alpha);
  71103. }
  71104. const Point<float> Line::getPointAlongLine (const float offsetX,
  71105. const float offsetY) const throw()
  71106. {
  71107. const float dx = endX - startX;
  71108. const float dy = endY - startY;
  71109. const double length = juce_hypot (dx, dy);
  71110. if (length == 0)
  71111. return Point<float> (startX, startY);
  71112. else
  71113. return Point<float> (startX + (float) (((dx * offsetX) - (dy * offsetY)) / length),
  71114. startY + (float) (((dy * offsetX) + (dx * offsetY)) / length));
  71115. }
  71116. const Point<float> Line::getPointAlongLineProportionally (const float alpha) const throw()
  71117. {
  71118. return Point<float> (startX + (endX - startX) * alpha,
  71119. startY + (endY - startY) * alpha);
  71120. }
  71121. float Line::getDistanceFromLine (const float x,
  71122. const float y) const throw()
  71123. {
  71124. const double dx = endX - startX;
  71125. const double dy = endY - startY;
  71126. const double length = dx * dx + dy * dy;
  71127. if (length > 0)
  71128. {
  71129. const double prop = ((x - startX) * dx + (y - startY) * dy) / length;
  71130. if (prop >= 0.0f && prop < 1.0f)
  71131. {
  71132. return (float) juce_hypot (x - (startX + prop * dx),
  71133. y - (startY + prop * dy));
  71134. }
  71135. }
  71136. return (float) jmin (juce_hypot (x - startX, y - startY),
  71137. juce_hypot (x - endX, y - endY));
  71138. }
  71139. float Line::findNearestPointTo (const float x,
  71140. const float y) const throw()
  71141. {
  71142. const double dx = endX - startX;
  71143. const double dy = endY - startY;
  71144. const double length = dx * dx + dy * dy;
  71145. if (length <= 0.0)
  71146. return 0.0f;
  71147. return jlimit (0.0f, 1.0f,
  71148. (float) (((x - startX) * dx + (y - startY) * dy) / length));
  71149. }
  71150. const Line Line::withShortenedStart (const float distanceToShortenBy) const throw()
  71151. {
  71152. const float length = getLength();
  71153. return Line (getPointAlongLine (jmin (distanceToShortenBy, length)),
  71154. getEnd());
  71155. }
  71156. const Line Line::withShortenedEnd (const float distanceToShortenBy) const throw()
  71157. {
  71158. const float length = getLength();
  71159. return Line (getStart(),
  71160. getPointAlongLine (length - jmin (distanceToShortenBy, length)));
  71161. }
  71162. bool Line::clipToPath (const Path& path,
  71163. const bool keepSectionOutsidePath) throw()
  71164. {
  71165. const bool startInside = path.contains (startX, startY);
  71166. const bool endInside = path.contains (endX, endY);
  71167. if (startInside == endInside)
  71168. {
  71169. if (keepSectionOutsidePath != startInside)
  71170. {
  71171. // entirely outside the path
  71172. return false;
  71173. }
  71174. else
  71175. {
  71176. // entirely inside the path
  71177. startX = 0.0f;
  71178. startY = 0.0f;
  71179. endX = 0.0f;
  71180. endY = 0.0f;
  71181. return true;
  71182. }
  71183. }
  71184. else
  71185. {
  71186. bool changed = false;
  71187. PathFlatteningIterator iter (path, AffineTransform::identity);
  71188. while (iter.next())
  71189. {
  71190. float ix, iy;
  71191. if (intersects (Line (iter.x1, iter.y1,
  71192. iter.x2, iter.y2),
  71193. ix, iy))
  71194. {
  71195. if ((startInside && keepSectionOutsidePath)
  71196. || (endInside && ! keepSectionOutsidePath))
  71197. {
  71198. setStart (ix, iy);
  71199. }
  71200. else
  71201. {
  71202. setEnd (ix, iy);
  71203. }
  71204. changed = true;
  71205. }
  71206. }
  71207. return changed;
  71208. }
  71209. }
  71210. bool Line::intersects (const Line& line,
  71211. float& intersectionX,
  71212. float& intersectionY) const throw()
  71213. {
  71214. return juce_lineIntersection (startX, startY,
  71215. endX, endY,
  71216. line.startX, line.startY,
  71217. line.endX, line.endY,
  71218. intersectionX,
  71219. intersectionY);
  71220. }
  71221. bool Line::isVertical() const throw()
  71222. {
  71223. return startX == endX;
  71224. }
  71225. bool Line::isHorizontal() const throw()
  71226. {
  71227. return startY == endY;
  71228. }
  71229. bool Line::isPointAbove (const float x, const float y) const throw()
  71230. {
  71231. return startX != endX
  71232. && y < ((endY - startY) * (x - startX)) / (endX - startX) + startY;
  71233. }
  71234. END_JUCE_NAMESPACE
  71235. /*** End of inlined file: juce_Line.cpp ***/
  71236. /*** Start of inlined file: juce_Path.cpp ***/
  71237. BEGIN_JUCE_NAMESPACE
  71238. // tests that some co-ords aren't NaNs
  71239. #define CHECK_COORDS_ARE_VALID(x, y) \
  71240. jassert (x == x && y == y);
  71241. const float Path::lineMarker = 100001.0f;
  71242. const float Path::moveMarker = 100002.0f;
  71243. const float Path::quadMarker = 100003.0f;
  71244. const float Path::cubicMarker = 100004.0f;
  71245. const float Path::closeSubPathMarker = 100005.0f;
  71246. static const int defaultGranularity = 32;
  71247. Path::Path() throw()
  71248. : numElements (0),
  71249. pathXMin (0),
  71250. pathXMax (0),
  71251. pathYMin (0),
  71252. pathYMax (0),
  71253. useNonZeroWinding (true)
  71254. {
  71255. }
  71256. Path::~Path() throw()
  71257. {
  71258. }
  71259. Path::Path (const Path& other) throw()
  71260. : numElements (other.numElements),
  71261. pathXMin (other.pathXMin),
  71262. pathXMax (other.pathXMax),
  71263. pathYMin (other.pathYMin),
  71264. pathYMax (other.pathYMax),
  71265. useNonZeroWinding (other.useNonZeroWinding)
  71266. {
  71267. if (numElements > 0)
  71268. {
  71269. data.setAllocatedSize (numElements);
  71270. memcpy (data.elements, other.data.elements, numElements * sizeof (float));
  71271. }
  71272. }
  71273. const Path& Path::operator= (const Path& other) throw()
  71274. {
  71275. if (this != &other)
  71276. {
  71277. data.ensureAllocatedSize (other.numElements);
  71278. numElements = other.numElements;
  71279. pathXMin = other.pathXMin;
  71280. pathXMax = other.pathXMax;
  71281. pathYMin = other.pathYMin;
  71282. pathYMax = other.pathYMax;
  71283. useNonZeroWinding = other.useNonZeroWinding;
  71284. if (numElements > 0)
  71285. memcpy (data.elements, other.data.elements, numElements * sizeof (float));
  71286. }
  71287. return *this;
  71288. }
  71289. void Path::clear() throw()
  71290. {
  71291. numElements = 0;
  71292. pathXMin = 0;
  71293. pathYMin = 0;
  71294. pathYMax = 0;
  71295. pathXMax = 0;
  71296. }
  71297. void Path::swapWithPath (Path& other)
  71298. {
  71299. data.swapWith (other.data);
  71300. swapVariables <int> (numElements, other.numElements);
  71301. swapVariables <float> (pathXMin, other.pathXMin);
  71302. swapVariables <float> (pathXMax, other.pathXMax);
  71303. swapVariables <float> (pathYMin, other.pathYMin);
  71304. swapVariables <float> (pathYMax, other.pathYMax);
  71305. swapVariables <bool> (useNonZeroWinding, other.useNonZeroWinding);
  71306. }
  71307. void Path::setUsingNonZeroWinding (const bool isNonZero) throw()
  71308. {
  71309. useNonZeroWinding = isNonZero;
  71310. }
  71311. void Path::scaleToFit (const float x, const float y, const float w, const float h,
  71312. const bool preserveProportions) throw()
  71313. {
  71314. applyTransform (getTransformToScaleToFit (x, y, w, h, preserveProportions));
  71315. }
  71316. bool Path::isEmpty() const throw()
  71317. {
  71318. int i = 0;
  71319. while (i < numElements)
  71320. {
  71321. const float type = data.elements [i++];
  71322. if (type == moveMarker)
  71323. {
  71324. i += 2;
  71325. }
  71326. else if (type == lineMarker
  71327. || type == quadMarker
  71328. || type == cubicMarker)
  71329. {
  71330. return false;
  71331. }
  71332. }
  71333. return true;
  71334. }
  71335. const Rectangle<float> Path::getBounds () const throw()
  71336. {
  71337. return Rectangle<float> (pathXMin, pathYMin,
  71338. pathXMax - pathXMin,
  71339. pathYMax - pathYMin);
  71340. }
  71341. const Rectangle<float> Path::getBoundsTransformed (const AffineTransform& transform) const throw()
  71342. {
  71343. return getBounds().transformed (transform);
  71344. }
  71345. void Path::startNewSubPath (const float x,
  71346. const float y) throw()
  71347. {
  71348. CHECK_COORDS_ARE_VALID (x, y);
  71349. if (numElements == 0)
  71350. {
  71351. pathXMin = pathXMax = x;
  71352. pathYMin = pathYMax = y;
  71353. }
  71354. else
  71355. {
  71356. pathXMin = jmin (pathXMin, x);
  71357. pathXMax = jmax (pathXMax, x);
  71358. pathYMin = jmin (pathYMin, y);
  71359. pathYMax = jmax (pathYMax, y);
  71360. }
  71361. data.ensureAllocatedSize (numElements + 3);
  71362. data.elements [numElements++] = moveMarker;
  71363. data.elements [numElements++] = x;
  71364. data.elements [numElements++] = y;
  71365. }
  71366. void Path::lineTo (const float x, const float y) throw()
  71367. {
  71368. CHECK_COORDS_ARE_VALID (x, y);
  71369. if (numElements == 0)
  71370. startNewSubPath (0, 0);
  71371. data.ensureAllocatedSize (numElements + 3);
  71372. data.elements [numElements++] = lineMarker;
  71373. data.elements [numElements++] = x;
  71374. data.elements [numElements++] = y;
  71375. pathXMin = jmin (pathXMin, x);
  71376. pathXMax = jmax (pathXMax, x);
  71377. pathYMin = jmin (pathYMin, y);
  71378. pathYMax = jmax (pathYMax, y);
  71379. }
  71380. void Path::quadraticTo (const float x1, const float y1,
  71381. const float x2, const float y2) throw()
  71382. {
  71383. CHECK_COORDS_ARE_VALID (x1, y1);
  71384. CHECK_COORDS_ARE_VALID (x2, y2);
  71385. if (numElements == 0)
  71386. startNewSubPath (0, 0);
  71387. data.ensureAllocatedSize (numElements + 5);
  71388. data.elements [numElements++] = quadMarker;
  71389. data.elements [numElements++] = x1;
  71390. data.elements [numElements++] = y1;
  71391. data.elements [numElements++] = x2;
  71392. data.elements [numElements++] = y2;
  71393. pathXMin = jmin (pathXMin, x1, x2);
  71394. pathXMax = jmax (pathXMax, x1, x2);
  71395. pathYMin = jmin (pathYMin, y1, y2);
  71396. pathYMax = jmax (pathYMax, y1, y2);
  71397. }
  71398. void Path::cubicTo (const float x1, const float y1,
  71399. const float x2, const float y2,
  71400. const float x3, const float y3) throw()
  71401. {
  71402. CHECK_COORDS_ARE_VALID (x1, y1);
  71403. CHECK_COORDS_ARE_VALID (x2, y2);
  71404. CHECK_COORDS_ARE_VALID (x3, y3);
  71405. if (numElements == 0)
  71406. startNewSubPath (0, 0);
  71407. data.ensureAllocatedSize (numElements + 7);
  71408. data.elements [numElements++] = cubicMarker;
  71409. data.elements [numElements++] = x1;
  71410. data.elements [numElements++] = y1;
  71411. data.elements [numElements++] = x2;
  71412. data.elements [numElements++] = y2;
  71413. data.elements [numElements++] = x3;
  71414. data.elements [numElements++] = y3;
  71415. pathXMin = jmin (pathXMin, x1, x2, x3);
  71416. pathXMax = jmax (pathXMax, x1, x2, x3);
  71417. pathYMin = jmin (pathYMin, y1, y2, y3);
  71418. pathYMax = jmax (pathYMax, y1, y2, y3);
  71419. }
  71420. void Path::closeSubPath() throw()
  71421. {
  71422. if (numElements > 0
  71423. && data.elements [numElements - 1] != closeSubPathMarker)
  71424. {
  71425. data.ensureAllocatedSize (numElements + 1);
  71426. data.elements [numElements++] = closeSubPathMarker;
  71427. }
  71428. }
  71429. const Point<float> Path::getCurrentPosition() const
  71430. {
  71431. int i = numElements - 1;
  71432. if (i > 0 && data.elements[i] == closeSubPathMarker)
  71433. {
  71434. while (i >= 0)
  71435. {
  71436. if (data.elements[i] == moveMarker)
  71437. {
  71438. i += 2;
  71439. break;
  71440. }
  71441. --i;
  71442. }
  71443. }
  71444. if (i > 0)
  71445. return Point<float> (data.elements [i - 1], data.elements [i]);
  71446. return Point<float>();
  71447. }
  71448. void Path::addRectangle (const float x, const float y,
  71449. const float w, const float h) throw()
  71450. {
  71451. float x1 = x, y1 = y, x2 = x + w, y2 = y + h;
  71452. if (w < 0)
  71453. swapVariables (x1, x2);
  71454. if (h < 0)
  71455. swapVariables (y1, y2);
  71456. data.ensureAllocatedSize (numElements + 13);
  71457. if (numElements == 0)
  71458. {
  71459. pathXMin = x1;
  71460. pathXMax = x2;
  71461. pathYMin = y1;
  71462. pathYMax = y2;
  71463. }
  71464. else
  71465. {
  71466. pathXMin = jmin (pathXMin, x1);
  71467. pathXMax = jmax (pathXMax, x2);
  71468. pathYMin = jmin (pathYMin, y1);
  71469. pathYMax = jmax (pathYMax, y2);
  71470. }
  71471. data.elements [numElements++] = moveMarker;
  71472. data.elements [numElements++] = x1;
  71473. data.elements [numElements++] = y2;
  71474. data.elements [numElements++] = lineMarker;
  71475. data.elements [numElements++] = x1;
  71476. data.elements [numElements++] = y1;
  71477. data.elements [numElements++] = lineMarker;
  71478. data.elements [numElements++] = x2;
  71479. data.elements [numElements++] = y1;
  71480. data.elements [numElements++] = lineMarker;
  71481. data.elements [numElements++] = x2;
  71482. data.elements [numElements++] = y2;
  71483. data.elements [numElements++] = closeSubPathMarker;
  71484. }
  71485. void Path::addRectangle (const Rectangle<int>& rectangle) throw()
  71486. {
  71487. addRectangle ((float) rectangle.getX(), (float) rectangle.getY(),
  71488. (float) rectangle.getWidth(), (float) rectangle.getHeight());
  71489. }
  71490. void Path::addRoundedRectangle (const float x, const float y,
  71491. const float w, const float h,
  71492. float csx,
  71493. float csy) throw()
  71494. {
  71495. csx = jmin (csx, w * 0.5f);
  71496. csy = jmin (csy, h * 0.5f);
  71497. const float cs45x = csx * 0.45f;
  71498. const float cs45y = csy * 0.45f;
  71499. const float x2 = x + w;
  71500. const float y2 = y + h;
  71501. startNewSubPath (x + csx, y);
  71502. lineTo (x2 - csx, y);
  71503. cubicTo (x2 - cs45x, y, x2, y + cs45y, x2, y + csy);
  71504. lineTo (x2, y2 - csy);
  71505. cubicTo (x2, y2 - cs45y, x2 - cs45x, y2, x2 - csx, y2);
  71506. lineTo (x + csx, y2);
  71507. cubicTo (x + cs45x, y2, x, y2 - cs45y, x, y2 - csy);
  71508. lineTo (x, y + csy);
  71509. cubicTo (x, y + cs45y, x + cs45x, y, x + csx, y);
  71510. closeSubPath();
  71511. }
  71512. void Path::addRoundedRectangle (const float x, const float y,
  71513. const float w, const float h,
  71514. float cs) throw()
  71515. {
  71516. addRoundedRectangle (x, y, w, h, cs, cs);
  71517. }
  71518. void Path::addTriangle (const float x1, const float y1,
  71519. const float x2, const float y2,
  71520. const float x3, const float y3) throw()
  71521. {
  71522. startNewSubPath (x1, y1);
  71523. lineTo (x2, y2);
  71524. lineTo (x3, y3);
  71525. closeSubPath();
  71526. }
  71527. void Path::addQuadrilateral (const float x1, const float y1,
  71528. const float x2, const float y2,
  71529. const float x3, const float y3,
  71530. const float x4, const float y4) throw()
  71531. {
  71532. startNewSubPath (x1, y1);
  71533. lineTo (x2, y2);
  71534. lineTo (x3, y3);
  71535. lineTo (x4, y4);
  71536. closeSubPath();
  71537. }
  71538. void Path::addEllipse (const float x, const float y,
  71539. const float w, const float h) throw()
  71540. {
  71541. const float hw = w * 0.5f;
  71542. const float hw55 = hw * 0.55f;
  71543. const float hh = h * 0.5f;
  71544. const float hh45 = hh * 0.55f;
  71545. const float cx = x + hw;
  71546. const float cy = y + hh;
  71547. startNewSubPath (cx, cy - hh);
  71548. cubicTo (cx + hw55, cy - hh, cx + hw, cy - hh45, cx + hw, cy);
  71549. cubicTo (cx + hw, cy + hh45, cx + hw55, cy + hh, cx, cy + hh);
  71550. cubicTo (cx - hw55, cy + hh, cx - hw, cy + hh45, cx - hw, cy);
  71551. cubicTo (cx - hw, cy - hh45, cx - hw55, cy - hh, cx, cy - hh);
  71552. closeSubPath();
  71553. }
  71554. void Path::addArc (const float x, const float y,
  71555. const float w, const float h,
  71556. const float fromRadians,
  71557. const float toRadians,
  71558. const bool startAsNewSubPath) throw()
  71559. {
  71560. const float radiusX = w / 2.0f;
  71561. const float radiusY = h / 2.0f;
  71562. addCentredArc (x + radiusX,
  71563. y + radiusY,
  71564. radiusX, radiusY,
  71565. 0.0f,
  71566. fromRadians, toRadians,
  71567. startAsNewSubPath);
  71568. }
  71569. static const float ellipseAngularIncrement = 0.05f;
  71570. void Path::addCentredArc (const float centreX, const float centreY,
  71571. const float radiusX, const float radiusY,
  71572. const float rotationOfEllipse,
  71573. const float fromRadians,
  71574. const float toRadians,
  71575. const bool startAsNewSubPath) throw()
  71576. {
  71577. if (radiusX > 0.0f && radiusY > 0.0f)
  71578. {
  71579. const AffineTransform rotation (AffineTransform::rotation (rotationOfEllipse, centreX, centreY));
  71580. float angle = fromRadians;
  71581. if (startAsNewSubPath)
  71582. {
  71583. float x = centreX + radiusX * sinf (angle);
  71584. float y = centreY - radiusY * cosf (angle);
  71585. if (rotationOfEllipse != 0)
  71586. rotation.transformPoint (x, y);
  71587. startNewSubPath (x, y);
  71588. }
  71589. if (fromRadians < toRadians)
  71590. {
  71591. if (startAsNewSubPath)
  71592. angle += ellipseAngularIncrement;
  71593. while (angle < toRadians)
  71594. {
  71595. float x = centreX + radiusX * sinf (angle);
  71596. float y = centreY - radiusY * cosf (angle);
  71597. if (rotationOfEllipse != 0)
  71598. rotation.transformPoint (x, y);
  71599. lineTo (x, y);
  71600. angle += ellipseAngularIncrement;
  71601. }
  71602. }
  71603. else
  71604. {
  71605. if (startAsNewSubPath)
  71606. angle -= ellipseAngularIncrement;
  71607. while (angle > toRadians)
  71608. {
  71609. float x = centreX + radiusX * sinf (angle);
  71610. float y = centreY - radiusY * cosf (angle);
  71611. if (rotationOfEllipse != 0)
  71612. rotation.transformPoint (x, y);
  71613. lineTo (x, y);
  71614. angle -= ellipseAngularIncrement;
  71615. }
  71616. }
  71617. float x = centreX + radiusX * sinf (toRadians);
  71618. float y = centreY - radiusY * cosf (toRadians);
  71619. if (rotationOfEllipse != 0)
  71620. rotation.transformPoint (x, y);
  71621. lineTo (x, y);
  71622. }
  71623. }
  71624. void Path::addPieSegment (const float x, const float y,
  71625. const float width, const float height,
  71626. const float fromRadians,
  71627. const float toRadians,
  71628. const float innerCircleProportionalSize)
  71629. {
  71630. float hw = width * 0.5f;
  71631. float hh = height * 0.5f;
  71632. const float centreX = x + hw;
  71633. const float centreY = y + hh;
  71634. startNewSubPath (centreX + hw * sinf (fromRadians),
  71635. centreY - hh * cosf (fromRadians));
  71636. addArc (x, y, width, height, fromRadians, toRadians);
  71637. if (fabs (fromRadians - toRadians) > float_Pi * 1.999f)
  71638. {
  71639. closeSubPath();
  71640. if (innerCircleProportionalSize > 0)
  71641. {
  71642. hw *= innerCircleProportionalSize;
  71643. hh *= innerCircleProportionalSize;
  71644. startNewSubPath (centreX + hw * sinf (toRadians),
  71645. centreY - hh * cosf (toRadians));
  71646. addArc (centreX - hw, centreY - hh, hw * 2.0f, hh * 2.0f,
  71647. toRadians, fromRadians);
  71648. }
  71649. }
  71650. else
  71651. {
  71652. if (innerCircleProportionalSize > 0)
  71653. {
  71654. hw *= innerCircleProportionalSize;
  71655. hh *= innerCircleProportionalSize;
  71656. addArc (centreX - hw, centreY - hh, hw * 2.0f, hh * 2.0f,
  71657. toRadians, fromRadians);
  71658. }
  71659. else
  71660. {
  71661. lineTo (centreX, centreY);
  71662. }
  71663. }
  71664. closeSubPath();
  71665. }
  71666. static void perpendicularOffset (const float x1, const float y1,
  71667. const float x2, const float y2,
  71668. const float offsetX, const float offsetY,
  71669. float& resultX, float& resultY) throw()
  71670. {
  71671. const float dx = x2 - x1;
  71672. const float dy = y2 - y1;
  71673. const float len = juce_hypotf (dx, dy);
  71674. if (len == 0)
  71675. {
  71676. resultX = x1;
  71677. resultY = y1;
  71678. }
  71679. else
  71680. {
  71681. resultX = x1 + ((dx * offsetX) - (dy * offsetY)) / len;
  71682. resultY = y1 + ((dy * offsetX) + (dx * offsetY)) / len;
  71683. }
  71684. }
  71685. void Path::addLineSegment (const float startX, const float startY,
  71686. const float endX, const float endY,
  71687. float lineThickness) throw()
  71688. {
  71689. lineThickness *= 0.5f;
  71690. float x, y;
  71691. perpendicularOffset (startX, startY, endX, endY,
  71692. 0, lineThickness, x, y);
  71693. startNewSubPath (x, y);
  71694. perpendicularOffset (startX, startY, endX, endY,
  71695. 0, -lineThickness, x, y);
  71696. lineTo (x, y);
  71697. perpendicularOffset (endX, endY, startX, startY,
  71698. 0, lineThickness, x, y);
  71699. lineTo (x, y);
  71700. perpendicularOffset (endX, endY, startX, startY,
  71701. 0, -lineThickness, x, y);
  71702. lineTo (x, y);
  71703. closeSubPath();
  71704. }
  71705. void Path::addArrow (const float startX, const float startY,
  71706. const float endX, const float endY,
  71707. float lineThickness,
  71708. float arrowheadWidth,
  71709. float arrowheadLength) throw()
  71710. {
  71711. lineThickness *= 0.5f;
  71712. arrowheadWidth *= 0.5f;
  71713. arrowheadLength = jmin (arrowheadLength, 0.8f * juce_hypotf (startX - endX,
  71714. startY - endY));
  71715. float x, y;
  71716. perpendicularOffset (startX, startY, endX, endY,
  71717. 0, lineThickness, x, y);
  71718. startNewSubPath (x, y);
  71719. perpendicularOffset (startX, startY, endX, endY,
  71720. 0, -lineThickness, x, y);
  71721. lineTo (x, y);
  71722. perpendicularOffset (endX, endY, startX, startY,
  71723. arrowheadLength, lineThickness, x, y);
  71724. lineTo (x, y);
  71725. perpendicularOffset (endX, endY, startX, startY,
  71726. arrowheadLength, arrowheadWidth, x, y);
  71727. lineTo (x, y);
  71728. perpendicularOffset (endX, endY, startX, startY,
  71729. 0, 0, x, y);
  71730. lineTo (x, y);
  71731. perpendicularOffset (endX, endY, startX, startY,
  71732. arrowheadLength, -arrowheadWidth, x, y);
  71733. lineTo (x, y);
  71734. perpendicularOffset (endX, endY, startX, startY,
  71735. arrowheadLength, -lineThickness, x, y);
  71736. lineTo (x, y);
  71737. closeSubPath();
  71738. }
  71739. void Path::addStar (const float centreX,
  71740. const float centreY,
  71741. const int numberOfPoints,
  71742. const float innerRadius,
  71743. const float outerRadius,
  71744. const float startAngle)
  71745. {
  71746. jassert (numberOfPoints > 1); // this would be silly.
  71747. if (numberOfPoints > 1)
  71748. {
  71749. const float angleBetweenPoints = float_Pi * 2.0f / numberOfPoints;
  71750. for (int i = 0; i < numberOfPoints; ++i)
  71751. {
  71752. float angle = startAngle + i * angleBetweenPoints;
  71753. const float x = centreX + outerRadius * sinf (angle);
  71754. const float y = centreY - outerRadius * cosf (angle);
  71755. if (i == 0)
  71756. startNewSubPath (x, y);
  71757. else
  71758. lineTo (x, y);
  71759. angle += angleBetweenPoints * 0.5f;
  71760. lineTo (centreX + innerRadius * sinf (angle),
  71761. centreY - innerRadius * cosf (angle));
  71762. }
  71763. closeSubPath();
  71764. }
  71765. }
  71766. void Path::addBubble (float x, float y,
  71767. float w, float h,
  71768. float cs,
  71769. float tipX,
  71770. float tipY,
  71771. int whichSide,
  71772. float arrowPos,
  71773. float arrowWidth)
  71774. {
  71775. if (w > 1.0f && h > 1.0f)
  71776. {
  71777. cs = jmin (cs, w * 0.5f, h * 0.5f);
  71778. const float cs2 = 2.0f * cs;
  71779. startNewSubPath (x + cs, y);
  71780. if (whichSide == 0)
  71781. {
  71782. const float halfArrowW = jmin (arrowWidth, w - cs2) * 0.5f;
  71783. const float arrowX1 = x + cs + jmax (0.0f, (w - cs2) * arrowPos - halfArrowW);
  71784. lineTo (arrowX1, y);
  71785. lineTo (tipX, tipY);
  71786. lineTo (arrowX1 + halfArrowW * 2.0f, y);
  71787. }
  71788. lineTo (x + w - cs, y);
  71789. if (cs > 0.0f)
  71790. addArc (x + w - cs2, y, cs2, cs2, 0, float_Pi * 0.5f);
  71791. if (whichSide == 3)
  71792. {
  71793. const float halfArrowH = jmin (arrowWidth, h - cs2) * 0.5f;
  71794. const float arrowY1 = y + cs + jmax (0.0f, (h - cs2) * arrowPos - halfArrowH);
  71795. lineTo (x + w, arrowY1);
  71796. lineTo (tipX, tipY);
  71797. lineTo (x + w, arrowY1 + halfArrowH * 2.0f);
  71798. }
  71799. lineTo (x + w, y + h - cs);
  71800. if (cs > 0.0f)
  71801. addArc (x + w - cs2, y + h - cs2, cs2, cs2, float_Pi * 0.5f, float_Pi);
  71802. if (whichSide == 2)
  71803. {
  71804. const float halfArrowW = jmin (arrowWidth, w - cs2) * 0.5f;
  71805. const float arrowX1 = x + cs + jmax (0.0f, (w - cs2) * arrowPos - halfArrowW);
  71806. lineTo (arrowX1 + halfArrowW * 2.0f, y + h);
  71807. lineTo (tipX, tipY);
  71808. lineTo (arrowX1, y + h);
  71809. }
  71810. lineTo (x + cs, y + h);
  71811. if (cs > 0.0f)
  71812. addArc (x, y + h - cs2, cs2, cs2, float_Pi, float_Pi * 1.5f);
  71813. if (whichSide == 1)
  71814. {
  71815. const float halfArrowH = jmin (arrowWidth, h - cs2) * 0.5f;
  71816. const float arrowY1 = y + cs + jmax (0.0f, (h - cs2) * arrowPos - halfArrowH);
  71817. lineTo (x, arrowY1 + halfArrowH * 2.0f);
  71818. lineTo (tipX, tipY);
  71819. lineTo (x, arrowY1);
  71820. }
  71821. lineTo (x, y + cs);
  71822. if (cs > 0.0f)
  71823. addArc (x, y, cs2, cs2, float_Pi * 1.5f, float_Pi * 2.0f - ellipseAngularIncrement);
  71824. closeSubPath();
  71825. }
  71826. }
  71827. void Path::addPath (const Path& other) throw()
  71828. {
  71829. int i = 0;
  71830. while (i < other.numElements)
  71831. {
  71832. const float type = other.data.elements [i++];
  71833. if (type == moveMarker)
  71834. {
  71835. startNewSubPath (other.data.elements [i],
  71836. other.data.elements [i + 1]);
  71837. i += 2;
  71838. }
  71839. else if (type == lineMarker)
  71840. {
  71841. lineTo (other.data.elements [i],
  71842. other.data.elements [i + 1]);
  71843. i += 2;
  71844. }
  71845. else if (type == quadMarker)
  71846. {
  71847. quadraticTo (other.data.elements [i],
  71848. other.data.elements [i + 1],
  71849. other.data.elements [i + 2],
  71850. other.data.elements [i + 3]);
  71851. i += 4;
  71852. }
  71853. else if (type == cubicMarker)
  71854. {
  71855. cubicTo (other.data.elements [i],
  71856. other.data.elements [i + 1],
  71857. other.data.elements [i + 2],
  71858. other.data.elements [i + 3],
  71859. other.data.elements [i + 4],
  71860. other.data.elements [i + 5]);
  71861. i += 6;
  71862. }
  71863. else if (type == closeSubPathMarker)
  71864. {
  71865. closeSubPath();
  71866. }
  71867. else
  71868. {
  71869. // something's gone wrong with the element list!
  71870. jassertfalse
  71871. }
  71872. }
  71873. }
  71874. void Path::addPath (const Path& other,
  71875. const AffineTransform& transformToApply) throw()
  71876. {
  71877. int i = 0;
  71878. while (i < other.numElements)
  71879. {
  71880. const float type = other.data.elements [i++];
  71881. if (type == closeSubPathMarker)
  71882. {
  71883. closeSubPath();
  71884. }
  71885. else
  71886. {
  71887. float x = other.data.elements [i++];
  71888. float y = other.data.elements [i++];
  71889. transformToApply.transformPoint (x, y);
  71890. if (type == moveMarker)
  71891. {
  71892. startNewSubPath (x, y);
  71893. }
  71894. else if (type == lineMarker)
  71895. {
  71896. lineTo (x, y);
  71897. }
  71898. else if (type == quadMarker)
  71899. {
  71900. float x2 = other.data.elements [i++];
  71901. float y2 = other.data.elements [i++];
  71902. transformToApply.transformPoint (x2, y2);
  71903. quadraticTo (x, y, x2, y2);
  71904. }
  71905. else if (type == cubicMarker)
  71906. {
  71907. float x2 = other.data.elements [i++];
  71908. float y2 = other.data.elements [i++];
  71909. float x3 = other.data.elements [i++];
  71910. float y3 = other.data.elements [i++];
  71911. transformToApply.transformPoint (x2, y2);
  71912. transformToApply.transformPoint (x3, y3);
  71913. cubicTo (x, y, x2, y2, x3, y3);
  71914. }
  71915. else
  71916. {
  71917. // something's gone wrong with the element list!
  71918. jassertfalse
  71919. }
  71920. }
  71921. }
  71922. }
  71923. void Path::applyTransform (const AffineTransform& transform) throw()
  71924. {
  71925. int i = 0;
  71926. pathYMin = pathXMin = 0;
  71927. pathYMax = pathXMax = 0;
  71928. bool setMaxMin = false;
  71929. while (i < numElements)
  71930. {
  71931. const float type = data.elements [i++];
  71932. if (type == moveMarker)
  71933. {
  71934. transform.transformPoint (data.elements [i],
  71935. data.elements [i + 1]);
  71936. if (setMaxMin)
  71937. {
  71938. pathXMin = jmin (pathXMin, data.elements [i]);
  71939. pathXMax = jmax (pathXMax, data.elements [i]);
  71940. pathYMin = jmin (pathYMin, data.elements [i + 1]);
  71941. pathYMax = jmax (pathYMax, data.elements [i + 1]);
  71942. }
  71943. else
  71944. {
  71945. pathXMin = pathXMax = data.elements [i];
  71946. pathYMin = pathYMax = data.elements [i + 1];
  71947. setMaxMin = true;
  71948. }
  71949. i += 2;
  71950. }
  71951. else if (type == lineMarker)
  71952. {
  71953. transform.transformPoint (data.elements [i],
  71954. data.elements [i + 1]);
  71955. pathXMin = jmin (pathXMin, data.elements [i]);
  71956. pathXMax = jmax (pathXMax, data.elements [i]);
  71957. pathYMin = jmin (pathYMin, data.elements [i + 1]);
  71958. pathYMax = jmax (pathYMax, data.elements [i + 1]);
  71959. i += 2;
  71960. }
  71961. else if (type == quadMarker)
  71962. {
  71963. transform.transformPoint (data.elements [i],
  71964. data.elements [i + 1]);
  71965. transform.transformPoint (data.elements [i + 2],
  71966. data.elements [i + 3]);
  71967. pathXMin = jmin (pathXMin, data.elements [i], data.elements [i + 2]);
  71968. pathXMax = jmax (pathXMax, data.elements [i], data.elements [i + 2]);
  71969. pathYMin = jmin (pathYMin, data.elements [i + 1], data.elements [i + 3]);
  71970. pathYMax = jmax (pathYMax, data.elements [i + 1], data.elements [i + 3]);
  71971. i += 4;
  71972. }
  71973. else if (type == cubicMarker)
  71974. {
  71975. transform.transformPoint (data.elements [i],
  71976. data.elements [i + 1]);
  71977. transform.transformPoint (data.elements [i + 2],
  71978. data.elements [i + 3]);
  71979. transform.transformPoint (data.elements [i + 4],
  71980. data.elements [i + 5]);
  71981. pathXMin = jmin (pathXMin, data.elements [i], data.elements [i + 2], data.elements [i + 4]);
  71982. pathXMax = jmax (pathXMax, data.elements [i], data.elements [i + 2], data.elements [i + 4]);
  71983. pathYMin = jmin (pathYMin, data.elements [i + 1], data.elements [i + 3], data.elements [i + 5]);
  71984. pathYMax = jmax (pathYMax, data.elements [i + 1], data.elements [i + 3], data.elements [i + 5]);
  71985. i += 6;
  71986. }
  71987. }
  71988. }
  71989. const AffineTransform Path::getTransformToScaleToFit (const float x, const float y,
  71990. const float w, const float h,
  71991. const bool preserveProportions,
  71992. const Justification& justification) const throw()
  71993. {
  71994. Rectangle<float> bounds (getBounds());
  71995. if (preserveProportions)
  71996. {
  71997. if (w <= 0 || h <= 0 || bounds.isEmpty())
  71998. return AffineTransform::identity;
  71999. float newW, newH;
  72000. const float srcRatio = bounds.getHeight() / bounds.getWidth();
  72001. if (srcRatio > h / w)
  72002. {
  72003. newW = h / srcRatio;
  72004. newH = h;
  72005. }
  72006. else
  72007. {
  72008. newW = w;
  72009. newH = w * srcRatio;
  72010. }
  72011. float newXCentre = x;
  72012. float newYCentre = y;
  72013. if (justification.testFlags (Justification::left))
  72014. newXCentre += newW * 0.5f;
  72015. else if (justification.testFlags (Justification::right))
  72016. newXCentre += w - newW * 0.5f;
  72017. else
  72018. newXCentre += w * 0.5f;
  72019. if (justification.testFlags (Justification::top))
  72020. newYCentre += newH * 0.5f;
  72021. else if (justification.testFlags (Justification::bottom))
  72022. newYCentre += h - newH * 0.5f;
  72023. else
  72024. newYCentre += h * 0.5f;
  72025. return AffineTransform::translation (bounds.getWidth() * -0.5f - bounds.getX(),
  72026. bounds.getHeight() * -0.5f - bounds.getY())
  72027. .scaled (newW / bounds.getWidth(), newH / bounds.getHeight())
  72028. .translated (newXCentre, newYCentre);
  72029. }
  72030. else
  72031. {
  72032. return AffineTransform::translation (-bounds.getX(), -bounds.getY())
  72033. .scaled (w / bounds.getWidth(), h / bounds.getHeight())
  72034. .translated (x, y);
  72035. }
  72036. }
  72037. bool Path::contains (const float x, const float y, const float tolerence) const throw()
  72038. {
  72039. if (x <= pathXMin || x >= pathXMax
  72040. || y <= pathYMin || y >= pathYMax)
  72041. return false;
  72042. PathFlatteningIterator i (*this, AffineTransform::identity, tolerence);
  72043. int positiveCrossings = 0;
  72044. int negativeCrossings = 0;
  72045. while (i.next())
  72046. {
  72047. if ((i.y1 <= y && i.y2 > y)
  72048. || (i.y2 <= y && i.y1 > y))
  72049. {
  72050. const float intersectX = i.x1 + (i.x2 - i.x1) * (y - i.y1) / (i.y2 - i.y1);
  72051. if (intersectX <= x)
  72052. {
  72053. if (i.y1 < i.y2)
  72054. ++positiveCrossings;
  72055. else
  72056. ++negativeCrossings;
  72057. }
  72058. }
  72059. }
  72060. return (useNonZeroWinding) ? (negativeCrossings != positiveCrossings)
  72061. : ((negativeCrossings + positiveCrossings) & 1) != 0;
  72062. }
  72063. bool Path::intersectsLine (const float x1, const float y1,
  72064. const float x2, const float y2,
  72065. const float tolerence) throw()
  72066. {
  72067. PathFlatteningIterator i (*this, AffineTransform::identity, tolerence);
  72068. const Line line1 (x1, y1, x2, y2);
  72069. while (i.next())
  72070. {
  72071. const Line line2 (i.x1, i.y1, i.x2, i.y2);
  72072. float ix, iy;
  72073. if (line1.intersects (line2, ix, iy))
  72074. return true;
  72075. }
  72076. return false;
  72077. }
  72078. const Path Path::createPathWithRoundedCorners (const float cornerRadius) const throw()
  72079. {
  72080. if (cornerRadius <= 0.01f)
  72081. return *this;
  72082. int indexOfPathStart = 0, indexOfPathStartThis = 0;
  72083. int n = 0;
  72084. bool lastWasLine = false, firstWasLine = false;
  72085. Path p;
  72086. while (n < numElements)
  72087. {
  72088. const float type = data.elements [n++];
  72089. if (type == moveMarker)
  72090. {
  72091. indexOfPathStart = p.numElements;
  72092. indexOfPathStartThis = n - 1;
  72093. const float x = data.elements [n++];
  72094. const float y = data.elements [n++];
  72095. p.startNewSubPath (x, y);
  72096. lastWasLine = false;
  72097. firstWasLine = (data.elements [n] == lineMarker);
  72098. }
  72099. else if (type == lineMarker || type == closeSubPathMarker)
  72100. {
  72101. float startX = 0, startY = 0, joinX = 0, joinY = 0, endX, endY;
  72102. if (type == lineMarker)
  72103. {
  72104. endX = data.elements [n++];
  72105. endY = data.elements [n++];
  72106. if (n > 8)
  72107. {
  72108. startX = data.elements [n - 8];
  72109. startY = data.elements [n - 7];
  72110. joinX = data.elements [n - 5];
  72111. joinY = data.elements [n - 4];
  72112. }
  72113. }
  72114. else
  72115. {
  72116. endX = data.elements [indexOfPathStartThis + 1];
  72117. endY = data.elements [indexOfPathStartThis + 2];
  72118. if (n > 6)
  72119. {
  72120. startX = data.elements [n - 6];
  72121. startY = data.elements [n - 5];
  72122. joinX = data.elements [n - 3];
  72123. joinY = data.elements [n - 2];
  72124. }
  72125. }
  72126. if (lastWasLine)
  72127. {
  72128. const double len1 = juce_hypot (startX - joinX,
  72129. startY - joinY);
  72130. if (len1 > 0)
  72131. {
  72132. const double propNeeded = jmin (0.5, cornerRadius / len1);
  72133. p.data.elements [p.numElements - 2] = (float) (joinX - (joinX - startX) * propNeeded);
  72134. p.data.elements [p.numElements - 1] = (float) (joinY - (joinY - startY) * propNeeded);
  72135. }
  72136. const double len2 = juce_hypot (endX - joinX,
  72137. endY - joinY);
  72138. if (len2 > 0)
  72139. {
  72140. const double propNeeded = jmin (0.5, cornerRadius / len2);
  72141. p.quadraticTo (joinX, joinY,
  72142. (float) (joinX + (endX - joinX) * propNeeded),
  72143. (float) (joinY + (endY - joinY) * propNeeded));
  72144. }
  72145. p.lineTo (endX, endY);
  72146. }
  72147. else if (type == lineMarker)
  72148. {
  72149. p.lineTo (endX, endY);
  72150. lastWasLine = true;
  72151. }
  72152. if (type == closeSubPathMarker)
  72153. {
  72154. if (firstWasLine)
  72155. {
  72156. startX = data.elements [n - 3];
  72157. startY = data.elements [n - 2];
  72158. joinX = endX;
  72159. joinY = endY;
  72160. endX = data.elements [indexOfPathStartThis + 4];
  72161. endY = data.elements [indexOfPathStartThis + 5];
  72162. const double len1 = juce_hypot (startX - joinX,
  72163. startY - joinY);
  72164. if (len1 > 0)
  72165. {
  72166. const double propNeeded = jmin (0.5, cornerRadius / len1);
  72167. p.data.elements [p.numElements - 2] = (float) (joinX - (joinX - startX) * propNeeded);
  72168. p.data.elements [p.numElements - 1] = (float) (joinY - (joinY - startY) * propNeeded);
  72169. }
  72170. const double len2 = juce_hypot (endX - joinX,
  72171. endY - joinY);
  72172. if (len2 > 0)
  72173. {
  72174. const double propNeeded = jmin (0.5, cornerRadius / len2);
  72175. endX = (float) (joinX + (endX - joinX) * propNeeded);
  72176. endY = (float) (joinY + (endY - joinY) * propNeeded);
  72177. p.quadraticTo (joinX, joinY, endX, endY);
  72178. p.data.elements [indexOfPathStart + 1] = endX;
  72179. p.data.elements [indexOfPathStart + 2] = endY;
  72180. }
  72181. }
  72182. p.closeSubPath();
  72183. }
  72184. }
  72185. else if (type == quadMarker)
  72186. {
  72187. lastWasLine = false;
  72188. const float x1 = data.elements [n++];
  72189. const float y1 = data.elements [n++];
  72190. const float x2 = data.elements [n++];
  72191. const float y2 = data.elements [n++];
  72192. p.quadraticTo (x1, y1, x2, y2);
  72193. }
  72194. else if (type == cubicMarker)
  72195. {
  72196. lastWasLine = false;
  72197. const float x1 = data.elements [n++];
  72198. const float y1 = data.elements [n++];
  72199. const float x2 = data.elements [n++];
  72200. const float y2 = data.elements [n++];
  72201. const float x3 = data.elements [n++];
  72202. const float y3 = data.elements [n++];
  72203. p.cubicTo (x1, y1, x2, y2, x3, y3);
  72204. }
  72205. }
  72206. return p;
  72207. }
  72208. void Path::loadPathFromStream (InputStream& source)
  72209. {
  72210. while (! source.isExhausted())
  72211. {
  72212. switch (source.readByte())
  72213. {
  72214. case 'm':
  72215. {
  72216. const float x = source.readFloat();
  72217. const float y = source.readFloat();
  72218. startNewSubPath (x, y);
  72219. break;
  72220. }
  72221. case 'l':
  72222. {
  72223. const float x = source.readFloat();
  72224. const float y = source.readFloat();
  72225. lineTo (x, y);
  72226. break;
  72227. }
  72228. case 'q':
  72229. {
  72230. const float x1 = source.readFloat();
  72231. const float y1 = source.readFloat();
  72232. const float x2 = source.readFloat();
  72233. const float y2 = source.readFloat();
  72234. quadraticTo (x1, y1, x2, y2);
  72235. break;
  72236. }
  72237. case 'b':
  72238. {
  72239. const float x1 = source.readFloat();
  72240. const float y1 = source.readFloat();
  72241. const float x2 = source.readFloat();
  72242. const float y2 = source.readFloat();
  72243. const float x3 = source.readFloat();
  72244. const float y3 = source.readFloat();
  72245. cubicTo (x1, y1, x2, y2, x3, y3);
  72246. break;
  72247. }
  72248. case 'c':
  72249. closeSubPath();
  72250. break;
  72251. case 'n':
  72252. useNonZeroWinding = true;
  72253. break;
  72254. case 'z':
  72255. useNonZeroWinding = false;
  72256. break;
  72257. case 'e':
  72258. return; // end of path marker
  72259. default:
  72260. jassertfalse // illegal char in the stream
  72261. break;
  72262. }
  72263. }
  72264. }
  72265. void Path::loadPathFromData (const unsigned char* const data,
  72266. const int numberOfBytes) throw()
  72267. {
  72268. MemoryInputStream in ((const char*) data, numberOfBytes, false);
  72269. loadPathFromStream (in);
  72270. }
  72271. void Path::writePathToStream (OutputStream& dest) const
  72272. {
  72273. dest.writeByte ((useNonZeroWinding) ? 'n' : 'z');
  72274. int i = 0;
  72275. while (i < numElements)
  72276. {
  72277. const float type = data.elements [i++];
  72278. if (type == moveMarker)
  72279. {
  72280. dest.writeByte ('m');
  72281. dest.writeFloat (data.elements [i++]);
  72282. dest.writeFloat (data.elements [i++]);
  72283. }
  72284. else if (type == lineMarker)
  72285. {
  72286. dest.writeByte ('l');
  72287. dest.writeFloat (data.elements [i++]);
  72288. dest.writeFloat (data.elements [i++]);
  72289. }
  72290. else if (type == quadMarker)
  72291. {
  72292. dest.writeByte ('q');
  72293. dest.writeFloat (data.elements [i++]);
  72294. dest.writeFloat (data.elements [i++]);
  72295. dest.writeFloat (data.elements [i++]);
  72296. dest.writeFloat (data.elements [i++]);
  72297. }
  72298. else if (type == cubicMarker)
  72299. {
  72300. dest.writeByte ('b');
  72301. dest.writeFloat (data.elements [i++]);
  72302. dest.writeFloat (data.elements [i++]);
  72303. dest.writeFloat (data.elements [i++]);
  72304. dest.writeFloat (data.elements [i++]);
  72305. dest.writeFloat (data.elements [i++]);
  72306. dest.writeFloat (data.elements [i++]);
  72307. }
  72308. else if (type == closeSubPathMarker)
  72309. {
  72310. dest.writeByte ('c');
  72311. }
  72312. }
  72313. dest.writeByte ('e'); // marks the end-of-path
  72314. }
  72315. const String Path::toString() const
  72316. {
  72317. MemoryOutputStream s (2048, 2048);
  72318. if (! useNonZeroWinding)
  72319. s << "a ";
  72320. int i = 0;
  72321. float lastMarker = 0.0f;
  72322. while (i < numElements)
  72323. {
  72324. const float marker = data.elements [i++];
  72325. char markerChar = 0;
  72326. int numCoords = 0;
  72327. if (marker == moveMarker)
  72328. {
  72329. markerChar = 'm';
  72330. numCoords = 2;
  72331. }
  72332. else if (marker == lineMarker)
  72333. {
  72334. markerChar = 'l';
  72335. numCoords = 2;
  72336. }
  72337. else if (marker == quadMarker)
  72338. {
  72339. markerChar = 'q';
  72340. numCoords = 4;
  72341. }
  72342. else if (marker == cubicMarker)
  72343. {
  72344. markerChar = 'c';
  72345. numCoords = 6;
  72346. }
  72347. else
  72348. {
  72349. jassert (marker == closeSubPathMarker);
  72350. markerChar = 'z';
  72351. }
  72352. if (marker != lastMarker)
  72353. {
  72354. s << markerChar << ' ';
  72355. lastMarker = marker;
  72356. }
  72357. while (--numCoords >= 0 && i < numElements)
  72358. {
  72359. String n (data.elements [i++], 3);
  72360. if (n.endsWithChar (T('0')))
  72361. {
  72362. do
  72363. {
  72364. n = n.dropLastCharacters (1);
  72365. } while (n.endsWithChar (T('0')));
  72366. if (n.endsWithChar (T('.')))
  72367. n = n.dropLastCharacters (1);
  72368. }
  72369. s << n << ' ';
  72370. }
  72371. }
  72372. const char* const result = (const char*) s.getData();
  72373. size_t len = s.getDataSize();
  72374. while (len > 0 && CharacterFunctions::isWhitespace (result [len - 1]))
  72375. --len;
  72376. return String (result, len);
  72377. }
  72378. static const String nextToken (const tchar*& t)
  72379. {
  72380. while (CharacterFunctions::isWhitespace (*t))
  72381. ++t;
  72382. const tchar* const start = t;
  72383. while (*t != 0 && ! CharacterFunctions::isWhitespace (*t))
  72384. ++t;
  72385. const int length = (int) (t - start);
  72386. while (CharacterFunctions::isWhitespace (*t))
  72387. ++t;
  72388. return String (start, length);
  72389. }
  72390. void Path::restoreFromString (const String& stringVersion)
  72391. {
  72392. clear();
  72393. setUsingNonZeroWinding (true);
  72394. const tchar* t = stringVersion;
  72395. tchar marker = T('m');
  72396. int numValues = 2;
  72397. float values [6];
  72398. while (*t != 0)
  72399. {
  72400. const String token (nextToken (t));
  72401. const tchar firstChar = token[0];
  72402. int startNum = 0;
  72403. if (firstChar == T('m') || firstChar == T('l'))
  72404. {
  72405. marker = firstChar;
  72406. numValues = 2;
  72407. }
  72408. else if (firstChar == T('q'))
  72409. {
  72410. marker = firstChar;
  72411. numValues = 4;
  72412. }
  72413. else if (firstChar == T('c'))
  72414. {
  72415. marker = firstChar;
  72416. numValues = 6;
  72417. }
  72418. else if (firstChar == T('z'))
  72419. {
  72420. marker = firstChar;
  72421. numValues = 0;
  72422. }
  72423. else if (firstChar == T('a'))
  72424. {
  72425. setUsingNonZeroWinding (false);
  72426. continue;
  72427. }
  72428. else
  72429. {
  72430. ++startNum;
  72431. values [0] = token.getFloatValue();
  72432. }
  72433. for (int i = startNum; i < numValues; ++i)
  72434. values [i] = nextToken (t).getFloatValue();
  72435. switch (marker)
  72436. {
  72437. case T('m'):
  72438. startNewSubPath (values[0], values[1]);
  72439. break;
  72440. case T('l'):
  72441. lineTo (values[0], values[1]);
  72442. break;
  72443. case T('q'):
  72444. quadraticTo (values[0], values[1],
  72445. values[2], values[3]);
  72446. break;
  72447. case T('c'):
  72448. cubicTo (values[0], values[1],
  72449. values[2], values[3],
  72450. values[4], values[5]);
  72451. break;
  72452. case T('z'):
  72453. closeSubPath();
  72454. break;
  72455. default:
  72456. jassertfalse // illegal string format?
  72457. break;
  72458. }
  72459. }
  72460. }
  72461. Path::Iterator::Iterator (const Path& path_)
  72462. : path (path_),
  72463. index (0)
  72464. {
  72465. }
  72466. Path::Iterator::~Iterator()
  72467. {
  72468. }
  72469. bool Path::Iterator::next()
  72470. {
  72471. const float* const elements = path.data.elements;
  72472. if (index < path.numElements)
  72473. {
  72474. const float type = elements [index++];
  72475. if (type == moveMarker)
  72476. {
  72477. elementType = startNewSubPath;
  72478. x1 = elements [index++];
  72479. y1 = elements [index++];
  72480. }
  72481. else if (type == lineMarker)
  72482. {
  72483. elementType = lineTo;
  72484. x1 = elements [index++];
  72485. y1 = elements [index++];
  72486. }
  72487. else if (type == quadMarker)
  72488. {
  72489. elementType = quadraticTo;
  72490. x1 = elements [index++];
  72491. y1 = elements [index++];
  72492. x2 = elements [index++];
  72493. y2 = elements [index++];
  72494. }
  72495. else if (type == cubicMarker)
  72496. {
  72497. elementType = cubicTo;
  72498. x1 = elements [index++];
  72499. y1 = elements [index++];
  72500. x2 = elements [index++];
  72501. y2 = elements [index++];
  72502. x3 = elements [index++];
  72503. y3 = elements [index++];
  72504. }
  72505. else if (type == closeSubPathMarker)
  72506. {
  72507. elementType = closePath;
  72508. }
  72509. return true;
  72510. }
  72511. return false;
  72512. }
  72513. END_JUCE_NAMESPACE
  72514. /*** End of inlined file: juce_Path.cpp ***/
  72515. /*** Start of inlined file: juce_PathIterator.cpp ***/
  72516. BEGIN_JUCE_NAMESPACE
  72517. #if JUCE_MSVC
  72518. #pragma optimize ("t", on)
  72519. #endif
  72520. PathFlatteningIterator::PathFlatteningIterator (const Path& path_,
  72521. const AffineTransform& transform_,
  72522. float tolerence_) throw()
  72523. : x2 (0),
  72524. y2 (0),
  72525. closesSubPath (false),
  72526. subPathIndex (-1),
  72527. path (path_),
  72528. transform (transform_),
  72529. points (path_.data.elements),
  72530. tolerence (tolerence_ * tolerence_),
  72531. subPathCloseX (0),
  72532. subPathCloseY (0),
  72533. stackBase (32),
  72534. index (0),
  72535. stackSize (32)
  72536. {
  72537. isIdentityTransform = transform.isIdentity();
  72538. stackPos = stackBase;
  72539. }
  72540. PathFlatteningIterator::~PathFlatteningIterator() throw()
  72541. {
  72542. }
  72543. bool PathFlatteningIterator::next() throw()
  72544. {
  72545. x1 = x2;
  72546. y1 = y2;
  72547. float x3 = 0;
  72548. float y3 = 0;
  72549. float x4 = 0;
  72550. float y4 = 0;
  72551. float type;
  72552. for (;;)
  72553. {
  72554. if (stackPos == stackBase)
  72555. {
  72556. if (index >= path.numElements)
  72557. {
  72558. return false;
  72559. }
  72560. else
  72561. {
  72562. type = points [index++];
  72563. if (type != Path::closeSubPathMarker)
  72564. {
  72565. x2 = points [index++];
  72566. y2 = points [index++];
  72567. if (! isIdentityTransform)
  72568. transform.transformPoint (x2, y2);
  72569. if (type == Path::quadMarker)
  72570. {
  72571. x3 = points [index++];
  72572. y3 = points [index++];
  72573. if (! isIdentityTransform)
  72574. transform.transformPoint (x3, y3);
  72575. }
  72576. else if (type == Path::cubicMarker)
  72577. {
  72578. x3 = points [index++];
  72579. y3 = points [index++];
  72580. x4 = points [index++];
  72581. y4 = points [index++];
  72582. if (! isIdentityTransform)
  72583. {
  72584. transform.transformPoint (x3, y3);
  72585. transform.transformPoint (x4, y4);
  72586. }
  72587. }
  72588. }
  72589. }
  72590. }
  72591. else
  72592. {
  72593. type = *--stackPos;
  72594. if (type != Path::closeSubPathMarker)
  72595. {
  72596. x2 = *--stackPos;
  72597. y2 = *--stackPos;
  72598. if (type == Path::quadMarker)
  72599. {
  72600. x3 = *--stackPos;
  72601. y3 = *--stackPos;
  72602. }
  72603. else if (type == Path::cubicMarker)
  72604. {
  72605. x3 = *--stackPos;
  72606. y3 = *--stackPos;
  72607. x4 = *--stackPos;
  72608. y4 = *--stackPos;
  72609. }
  72610. }
  72611. }
  72612. if (type == Path::lineMarker)
  72613. {
  72614. ++subPathIndex;
  72615. closesSubPath = (stackPos == stackBase)
  72616. && (index < path.numElements)
  72617. && (points [index] == Path::closeSubPathMarker)
  72618. && x2 == subPathCloseX
  72619. && y2 == subPathCloseY;
  72620. return true;
  72621. }
  72622. else if (type == Path::quadMarker)
  72623. {
  72624. const int offset = (int) (stackPos - stackBase);
  72625. if (offset >= stackSize - 10)
  72626. {
  72627. stackSize <<= 1;
  72628. stackBase.realloc (stackSize);
  72629. stackPos = stackBase + offset;
  72630. }
  72631. const float dx1 = x1 - x2;
  72632. const float dy1 = y1 - y2;
  72633. const float dx2 = x2 - x3;
  72634. const float dy2 = y2 - y3;
  72635. const float m1x = (x1 + x2) * 0.5f;
  72636. const float m1y = (y1 + y2) * 0.5f;
  72637. const float m2x = (x2 + x3) * 0.5f;
  72638. const float m2y = (y2 + y3) * 0.5f;
  72639. const float m3x = (m1x + m2x) * 0.5f;
  72640. const float m3y = (m1y + m2y) * 0.5f;
  72641. if (dx1*dx1 + dy1*dy1 + dx2*dx2 + dy2*dy2 > tolerence)
  72642. {
  72643. *stackPos++ = y3;
  72644. *stackPos++ = x3;
  72645. *stackPos++ = m2y;
  72646. *stackPos++ = m2x;
  72647. *stackPos++ = Path::quadMarker;
  72648. *stackPos++ = m3y;
  72649. *stackPos++ = m3x;
  72650. *stackPos++ = m1y;
  72651. *stackPos++ = m1x;
  72652. *stackPos++ = Path::quadMarker;
  72653. }
  72654. else
  72655. {
  72656. *stackPos++ = y3;
  72657. *stackPos++ = x3;
  72658. *stackPos++ = Path::lineMarker;
  72659. *stackPos++ = m3y;
  72660. *stackPos++ = m3x;
  72661. *stackPos++ = Path::lineMarker;
  72662. }
  72663. jassert (stackPos < stackBase + stackSize);
  72664. }
  72665. else if (type == Path::cubicMarker)
  72666. {
  72667. const int offset = (int) (stackPos - stackBase);
  72668. if (offset >= stackSize - 16)
  72669. {
  72670. stackSize <<= 1;
  72671. stackBase.realloc (stackSize);
  72672. stackPos = stackBase + offset;
  72673. }
  72674. const float dx1 = x1 - x2;
  72675. const float dy1 = y1 - y2;
  72676. const float dx2 = x2 - x3;
  72677. const float dy2 = y2 - y3;
  72678. const float dx3 = x3 - x4;
  72679. const float dy3 = y3 - y4;
  72680. const float m1x = (x1 + x2) * 0.5f;
  72681. const float m1y = (y1 + y2) * 0.5f;
  72682. const float m2x = (x3 + x2) * 0.5f;
  72683. const float m2y = (y3 + y2) * 0.5f;
  72684. const float m3x = (x3 + x4) * 0.5f;
  72685. const float m3y = (y3 + y4) * 0.5f;
  72686. const float m4x = (m1x + m2x) * 0.5f;
  72687. const float m4y = (m1y + m2y) * 0.5f;
  72688. const float m5x = (m3x + m2x) * 0.5f;
  72689. const float m5y = (m3y + m2y) * 0.5f;
  72690. if (dx1*dx1 + dy1*dy1 + dx2*dx2
  72691. + dy2*dy2 + dx3*dx3 + dy3*dy3 > tolerence)
  72692. {
  72693. *stackPos++ = y4;
  72694. *stackPos++ = x4;
  72695. *stackPos++ = m3y;
  72696. *stackPos++ = m3x;
  72697. *stackPos++ = m5y;
  72698. *stackPos++ = m5x;
  72699. *stackPos++ = Path::cubicMarker;
  72700. *stackPos++ = (m4y + m5y) * 0.5f;
  72701. *stackPos++ = (m4x + m5x) * 0.5f;
  72702. *stackPos++ = m4y;
  72703. *stackPos++ = m4x;
  72704. *stackPos++ = m1y;
  72705. *stackPos++ = m1x;
  72706. *stackPos++ = Path::cubicMarker;
  72707. }
  72708. else
  72709. {
  72710. *stackPos++ = y4;
  72711. *stackPos++ = x4;
  72712. *stackPos++ = Path::lineMarker;
  72713. *stackPos++ = m5y;
  72714. *stackPos++ = m5x;
  72715. *stackPos++ = Path::lineMarker;
  72716. *stackPos++ = m4y;
  72717. *stackPos++ = m4x;
  72718. *stackPos++ = Path::lineMarker;
  72719. }
  72720. }
  72721. else if (type == Path::closeSubPathMarker)
  72722. {
  72723. if (x2 != subPathCloseX || y2 != subPathCloseY)
  72724. {
  72725. x1 = x2;
  72726. y1 = y2;
  72727. x2 = subPathCloseX;
  72728. y2 = subPathCloseY;
  72729. closesSubPath = true;
  72730. return true;
  72731. }
  72732. }
  72733. else
  72734. {
  72735. jassert (type == Path::moveMarker);
  72736. subPathIndex = -1;
  72737. subPathCloseX = x1 = x2;
  72738. subPathCloseY = y1 = y2;
  72739. }
  72740. }
  72741. }
  72742. END_JUCE_NAMESPACE
  72743. /*** End of inlined file: juce_PathIterator.cpp ***/
  72744. /*** Start of inlined file: juce_PathStrokeType.cpp ***/
  72745. BEGIN_JUCE_NAMESPACE
  72746. PathStrokeType::PathStrokeType (const float strokeThickness,
  72747. const JointStyle jointStyle_,
  72748. const EndCapStyle endStyle_) throw()
  72749. : thickness (strokeThickness),
  72750. jointStyle (jointStyle_),
  72751. endStyle (endStyle_)
  72752. {
  72753. }
  72754. PathStrokeType::PathStrokeType (const PathStrokeType& other) throw()
  72755. : thickness (other.thickness),
  72756. jointStyle (other.jointStyle),
  72757. endStyle (other.endStyle)
  72758. {
  72759. }
  72760. const PathStrokeType& PathStrokeType::operator= (const PathStrokeType& other) throw()
  72761. {
  72762. thickness = other.thickness;
  72763. jointStyle = other.jointStyle;
  72764. endStyle = other.endStyle;
  72765. return *this;
  72766. }
  72767. PathStrokeType::~PathStrokeType() throw()
  72768. {
  72769. }
  72770. bool PathStrokeType::operator== (const PathStrokeType& other) const throw()
  72771. {
  72772. return thickness == other.thickness
  72773. && jointStyle == other.jointStyle
  72774. && endStyle == other.endStyle;
  72775. }
  72776. bool PathStrokeType::operator!= (const PathStrokeType& other) const throw()
  72777. {
  72778. return ! operator== (other);
  72779. }
  72780. static bool lineIntersection (const float x1, const float y1,
  72781. const float x2, const float y2,
  72782. const float x3, const float y3,
  72783. const float x4, const float y4,
  72784. float& intersectionX,
  72785. float& intersectionY,
  72786. float& distanceBeyondLine1EndSquared) throw()
  72787. {
  72788. if (x2 != x3 || y2 != y3)
  72789. {
  72790. const float dx1 = x2 - x1;
  72791. const float dy1 = y2 - y1;
  72792. const float dx2 = x4 - x3;
  72793. const float dy2 = y4 - y3;
  72794. const float divisor = dx1 * dy2 - dx2 * dy1;
  72795. if (divisor == 0)
  72796. {
  72797. if (! ((dx1 == 0 && dy1 == 0) || (dx2 == 0 && dy2 == 0)))
  72798. {
  72799. if (dy1 == 0 && dy2 != 0)
  72800. {
  72801. const float along = (y1 - y3) / dy2;
  72802. intersectionX = x3 + along * dx2;
  72803. intersectionY = y1;
  72804. distanceBeyondLine1EndSquared = intersectionX - x2;
  72805. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72806. if ((x2 > x1) == (intersectionX < x2))
  72807. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72808. return along >= 0 && along <= 1.0f;
  72809. }
  72810. else if (dy2 == 0 && dy1 != 0)
  72811. {
  72812. const float along = (y3 - y1) / dy1;
  72813. intersectionX = x1 + along * dx1;
  72814. intersectionY = y3;
  72815. distanceBeyondLine1EndSquared = (along - 1.0f) * dx1;
  72816. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72817. if (along < 1.0f)
  72818. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72819. return along >= 0 && along <= 1.0f;
  72820. }
  72821. else if (dx1 == 0 && dx2 != 0)
  72822. {
  72823. const float along = (x1 - x3) / dx2;
  72824. intersectionX = x1;
  72825. intersectionY = y3 + along * dy2;
  72826. distanceBeyondLine1EndSquared = intersectionY - y2;
  72827. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72828. if ((y2 > y1) == (intersectionY < y2))
  72829. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72830. return along >= 0 && along <= 1.0f;
  72831. }
  72832. else if (dx2 == 0 && dx1 != 0)
  72833. {
  72834. const float along = (x3 - x1) / dx1;
  72835. intersectionX = x3;
  72836. intersectionY = y1 + along * dy1;
  72837. distanceBeyondLine1EndSquared = (along - 1.0f) * dy1;
  72838. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72839. if (along < 1.0f)
  72840. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72841. return along >= 0 && along <= 1.0f;
  72842. }
  72843. }
  72844. intersectionX = 0.5f * (x2 + x3);
  72845. intersectionY = 0.5f * (y2 + y3);
  72846. distanceBeyondLine1EndSquared = 0.0f;
  72847. return false;
  72848. }
  72849. else
  72850. {
  72851. const float along1 = ((y1 - y3) * dx2 - (x1 - x3) * dy2) / divisor;
  72852. intersectionX = x1 + along1 * dx1;
  72853. intersectionY = y1 + along1 * dy1;
  72854. if (along1 >= 0 && along1 <= 1.0f)
  72855. {
  72856. const float along2 = ((y1 - y3) * dx1 - (x1 - x3) * dy1);
  72857. if (along2 >= 0 && along2 <= divisor)
  72858. {
  72859. distanceBeyondLine1EndSquared = 0.0f;
  72860. return true;
  72861. }
  72862. }
  72863. distanceBeyondLine1EndSquared = along1 - 1.0f;
  72864. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72865. distanceBeyondLine1EndSquared *= (dx1 * dx1 + dy1 * dy1);
  72866. if (along1 < 1.0f)
  72867. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72868. return false;
  72869. }
  72870. }
  72871. intersectionX = x2;
  72872. intersectionY = y2;
  72873. distanceBeyondLine1EndSquared = 0.0f;
  72874. return true;
  72875. }
  72876. // part of stroke drawing stuff
  72877. static void addEdgeAndJoint (Path& destPath,
  72878. const PathStrokeType::JointStyle style,
  72879. const float maxMiterExtensionSquared, const float width,
  72880. const float x1, const float y1,
  72881. const float x2, const float y2,
  72882. const float x3, const float y3,
  72883. const float x4, const float y4,
  72884. const float midX, const float midY) throw()
  72885. {
  72886. if (style == PathStrokeType::beveled
  72887. || (x3 == x4 && y3 == y4)
  72888. || (x1 == x2 && y1 == y2))
  72889. {
  72890. destPath.lineTo (x2, y2);
  72891. destPath.lineTo (x3, y3);
  72892. }
  72893. else
  72894. {
  72895. float jx, jy, distanceBeyondLine1EndSquared;
  72896. // if they intersect, use this point..
  72897. if (lineIntersection (x1, y1, x2, y2,
  72898. x3, y3, x4, y4,
  72899. jx, jy, distanceBeyondLine1EndSquared))
  72900. {
  72901. destPath.lineTo (jx, jy);
  72902. }
  72903. else
  72904. {
  72905. if (style == PathStrokeType::mitered)
  72906. {
  72907. if (distanceBeyondLine1EndSquared < maxMiterExtensionSquared
  72908. && distanceBeyondLine1EndSquared > 0.0f)
  72909. {
  72910. destPath.lineTo (jx, jy);
  72911. }
  72912. else
  72913. {
  72914. // the end sticks out too far, so just use a blunt joint
  72915. destPath.lineTo (x2, y2);
  72916. destPath.lineTo (x3, y3);
  72917. }
  72918. }
  72919. else
  72920. {
  72921. // curved joints
  72922. float angle1 = atan2f (x2 - midX, y2 - midY);
  72923. float angle2 = atan2f (x3 - midX, y3 - midY);
  72924. const float angleIncrement = 0.1f;
  72925. destPath.lineTo (x2, y2);
  72926. if (fabs (angle1 - angle2) > angleIncrement)
  72927. {
  72928. if (angle2 > angle1 + float_Pi
  72929. || (angle2 < angle1 && angle2 >= angle1 - float_Pi))
  72930. {
  72931. if (angle2 > angle1)
  72932. angle2 -= float_Pi * 2.0f;
  72933. jassert (angle1 <= angle2 + float_Pi);
  72934. angle1 -= angleIncrement;
  72935. while (angle1 > angle2)
  72936. {
  72937. destPath.lineTo (midX + width * sinf (angle1),
  72938. midY + width * cosf (angle1));
  72939. angle1 -= angleIncrement;
  72940. }
  72941. }
  72942. else
  72943. {
  72944. if (angle1 > angle2)
  72945. angle1 -= float_Pi * 2.0f;
  72946. jassert (angle1 >= angle2 - float_Pi);
  72947. angle1 += angleIncrement;
  72948. while (angle1 < angle2)
  72949. {
  72950. destPath.lineTo (midX + width * sinf (angle1),
  72951. midY + width * cosf (angle1));
  72952. angle1 += angleIncrement;
  72953. }
  72954. }
  72955. }
  72956. destPath.lineTo (x3, y3);
  72957. }
  72958. }
  72959. }
  72960. }
  72961. static inline void addLineEnd (Path& destPath,
  72962. const PathStrokeType::EndCapStyle style,
  72963. const float x1, const float y1,
  72964. const float x2, const float y2,
  72965. const float width) throw()
  72966. {
  72967. if (style == PathStrokeType::butt)
  72968. {
  72969. destPath.lineTo (x2, y2);
  72970. }
  72971. else
  72972. {
  72973. float offx1, offy1, offx2, offy2;
  72974. float dx = x2 - x1;
  72975. float dy = y2 - y1;
  72976. const float len = juce_hypotf (dx, dy);
  72977. if (len == 0)
  72978. {
  72979. offx1 = offx2 = x1;
  72980. offy1 = offy2 = y1;
  72981. }
  72982. else
  72983. {
  72984. const float offset = width / len;
  72985. dx *= offset;
  72986. dy *= offset;
  72987. offx1 = x1 + dy;
  72988. offy1 = y1 - dx;
  72989. offx2 = x2 + dy;
  72990. offy2 = y2 - dx;
  72991. }
  72992. if (style == PathStrokeType::square)
  72993. {
  72994. // sqaure ends
  72995. destPath.lineTo (offx1, offy1);
  72996. destPath.lineTo (offx2, offy2);
  72997. destPath.lineTo (x2, y2);
  72998. }
  72999. else
  73000. {
  73001. // rounded ends
  73002. const float midx = (offx1 + offx2) * 0.5f;
  73003. const float midy = (offy1 + offy2) * 0.5f;
  73004. destPath.cubicTo (x1 + (offx1 - x1) * 0.55f, y1 + (offy1 - y1) * 0.55f,
  73005. offx1 + (midx - offx1) * 0.45f, offy1 + (midy - offy1) * 0.45f,
  73006. midx, midy);
  73007. destPath.cubicTo (midx + (offx2 - midx) * 0.55f, midy + (offy2 - midy) * 0.55f,
  73008. offx2 + (x2 - offx2) * 0.45f, offy2 + (y2 - offy2) * 0.45f,
  73009. x2, y2);
  73010. }
  73011. }
  73012. }
  73013. struct LineSection
  73014. {
  73015. LineSection() {}
  73016. LineSection (int) {}
  73017. float x1, y1, x2, y2; // original line
  73018. float lx1, ly1, lx2, ly2; // the left-hand stroke
  73019. float rx1, ry1, rx2, ry2; // the right-hand stroke
  73020. };
  73021. static void addSubPath (Path& destPath, const Array <LineSection>& subPath,
  73022. const bool isClosed,
  73023. const float width, const float maxMiterExtensionSquared,
  73024. const PathStrokeType::JointStyle jointStyle, const PathStrokeType::EndCapStyle endStyle) throw()
  73025. {
  73026. jassert (subPath.size() > 0);
  73027. const LineSection& firstLine = subPath.getReference (0);
  73028. float lastX1 = firstLine.lx1;
  73029. float lastY1 = firstLine.ly1;
  73030. float lastX2 = firstLine.lx2;
  73031. float lastY2 = firstLine.ly2;
  73032. if (isClosed)
  73033. {
  73034. destPath.startNewSubPath (lastX1, lastY1);
  73035. }
  73036. else
  73037. {
  73038. destPath.startNewSubPath (firstLine.rx2, firstLine.ry2);
  73039. addLineEnd (destPath, endStyle,
  73040. firstLine.rx2, firstLine.ry2,
  73041. lastX1, lastY1,
  73042. width);
  73043. }
  73044. int i;
  73045. for (i = 1; i < subPath.size(); ++i)
  73046. {
  73047. const LineSection& l = subPath.getReference (i);
  73048. addEdgeAndJoint (destPath, jointStyle,
  73049. maxMiterExtensionSquared, width,
  73050. lastX1, lastY1, lastX2, lastY2,
  73051. l.lx1, l.ly1, l.lx2, l.ly2,
  73052. l.x1, l.y1);
  73053. lastX1 = l.lx1;
  73054. lastY1 = l.ly1;
  73055. lastX2 = l.lx2;
  73056. lastY2 = l.ly2;
  73057. }
  73058. const LineSection& lastLine = subPath.getReference (subPath.size() - 1);
  73059. if (isClosed)
  73060. {
  73061. const LineSection& l = subPath.getReference (0);
  73062. addEdgeAndJoint (destPath, jointStyle,
  73063. maxMiterExtensionSquared, width,
  73064. lastX1, lastY1, lastX2, lastY2,
  73065. l.lx1, l.ly1, l.lx2, l.ly2,
  73066. l.x1, l.y1);
  73067. destPath.closeSubPath();
  73068. destPath.startNewSubPath (lastLine.rx1, lastLine.ry1);
  73069. }
  73070. else
  73071. {
  73072. destPath.lineTo (lastX2, lastY2);
  73073. addLineEnd (destPath, endStyle,
  73074. lastX2, lastY2,
  73075. lastLine.rx1, lastLine.ry1,
  73076. width);
  73077. }
  73078. lastX1 = lastLine.rx1;
  73079. lastY1 = lastLine.ry1;
  73080. lastX2 = lastLine.rx2;
  73081. lastY2 = lastLine.ry2;
  73082. for (i = subPath.size() - 1; --i >= 0;)
  73083. {
  73084. const LineSection& l = subPath.getReference (i);
  73085. addEdgeAndJoint (destPath, jointStyle,
  73086. maxMiterExtensionSquared, width,
  73087. lastX1, lastY1, lastX2, lastY2,
  73088. l.rx1, l.ry1, l.rx2, l.ry2,
  73089. l.x2, l.y2);
  73090. lastX1 = l.rx1;
  73091. lastY1 = l.ry1;
  73092. lastX2 = l.rx2;
  73093. lastY2 = l.ry2;
  73094. }
  73095. if (isClosed)
  73096. {
  73097. addEdgeAndJoint (destPath, jointStyle,
  73098. maxMiterExtensionSquared, width,
  73099. lastX1, lastY1, lastX2, lastY2,
  73100. lastLine.rx1, lastLine.ry1, lastLine.rx2, lastLine.ry2,
  73101. lastLine.x2, lastLine.y2);
  73102. }
  73103. else
  73104. {
  73105. // do the last line
  73106. destPath.lineTo (lastX2, lastY2);
  73107. }
  73108. destPath.closeSubPath();
  73109. }
  73110. void PathStrokeType::createStrokedPath (Path& destPath,
  73111. const Path& source,
  73112. const AffineTransform& transform,
  73113. const float extraAccuracy) const throw()
  73114. {
  73115. if (thickness <= 0)
  73116. {
  73117. destPath.clear();
  73118. return;
  73119. }
  73120. const Path* sourcePath = &source;
  73121. Path temp;
  73122. if (sourcePath == &destPath)
  73123. {
  73124. destPath.swapWithPath (temp);
  73125. sourcePath = &temp;
  73126. }
  73127. else
  73128. {
  73129. destPath.clear();
  73130. }
  73131. destPath.setUsingNonZeroWinding (true);
  73132. const float maxMiterExtensionSquared = 9.0f * thickness * thickness;
  73133. const float width = 0.5f * thickness;
  73134. // Iterate the path, creating a list of the
  73135. // left/right-hand lines along either side of it...
  73136. PathFlatteningIterator it (*sourcePath, transform, 9.0f / extraAccuracy);
  73137. Array <LineSection> subPath;
  73138. LineSection l;
  73139. l.x1 = 0;
  73140. l.y1 = 0;
  73141. const float minSegmentLength = 2.0f / (extraAccuracy * extraAccuracy);
  73142. while (it.next())
  73143. {
  73144. if (it.subPathIndex == 0)
  73145. {
  73146. if (subPath.size() > 0)
  73147. {
  73148. addSubPath (destPath, subPath, false, width, maxMiterExtensionSquared, jointStyle, endStyle);
  73149. subPath.clearQuick();
  73150. }
  73151. l.x1 = it.x1;
  73152. l.y1 = it.y1;
  73153. }
  73154. l.x2 = it.x2;
  73155. l.y2 = it.y2;
  73156. float dx = l.x2 - l.x1;
  73157. float dy = l.y2 - l.y1;
  73158. const float hypotSquared = dx*dx + dy*dy;
  73159. if (it.closesSubPath || hypotSquared > minSegmentLength || it.isLastInSubpath())
  73160. {
  73161. const float len = sqrtf (hypotSquared);
  73162. if (len == 0)
  73163. {
  73164. l.rx1 = l.rx2 = l.lx1 = l.lx2 = l.x1;
  73165. l.ry1 = l.ry2 = l.ly1 = l.ly2 = l.y1;
  73166. }
  73167. else
  73168. {
  73169. const float offset = width / len;
  73170. dx *= offset;
  73171. dy *= offset;
  73172. l.rx2 = l.x1 - dy;
  73173. l.ry2 = l.y1 + dx;
  73174. l.lx1 = l.x1 + dy;
  73175. l.ly1 = l.y1 - dx;
  73176. l.lx2 = l.x2 + dy;
  73177. l.ly2 = l.y2 - dx;
  73178. l.rx1 = l.x2 - dy;
  73179. l.ry1 = l.y2 + dx;
  73180. }
  73181. subPath.add (l);
  73182. if (it.closesSubPath)
  73183. {
  73184. addSubPath (destPath, subPath, true, width, maxMiterExtensionSquared, jointStyle, endStyle);
  73185. subPath.clearQuick();
  73186. }
  73187. else
  73188. {
  73189. l.x1 = it.x2;
  73190. l.y1 = it.y2;
  73191. }
  73192. }
  73193. }
  73194. if (subPath.size() > 0)
  73195. addSubPath (destPath, subPath, false, width, maxMiterExtensionSquared, jointStyle, endStyle);
  73196. }
  73197. void PathStrokeType::createDashedStroke (Path& destPath,
  73198. const Path& sourcePath,
  73199. const float* dashLengths,
  73200. int numDashLengths,
  73201. const AffineTransform& transform,
  73202. const float extraAccuracy) const throw()
  73203. {
  73204. if (thickness <= 0)
  73205. return;
  73206. // this should really be an even number..
  73207. jassert ((numDashLengths & 1) == 0);
  73208. Path newDestPath;
  73209. PathFlatteningIterator it (sourcePath, transform, 9.0f / extraAccuracy);
  73210. bool first = true;
  73211. int dashNum = 0;
  73212. float pos = 0.0f, lineLen = 0.0f, lineEndPos = 0.0f;
  73213. float dx = 0.0f, dy = 0.0f;
  73214. for (;;)
  73215. {
  73216. const bool isSolid = ((dashNum & 1) == 0);
  73217. const float dashLen = dashLengths [dashNum++ % numDashLengths];
  73218. jassert (dashLen > 0); // must be a positive increment!
  73219. if (dashLen <= 0)
  73220. break;
  73221. pos += dashLen;
  73222. while (pos > lineEndPos)
  73223. {
  73224. if (! it.next())
  73225. {
  73226. if (isSolid && ! first)
  73227. newDestPath.lineTo (it.x2, it.y2);
  73228. createStrokedPath (destPath, newDestPath, AffineTransform::identity, extraAccuracy);
  73229. return;
  73230. }
  73231. if (isSolid && ! first)
  73232. newDestPath.lineTo (it.x1, it.y1);
  73233. else
  73234. newDestPath.startNewSubPath (it.x1, it.y1);
  73235. dx = it.x2 - it.x1;
  73236. dy = it.y2 - it.y1;
  73237. lineLen = juce_hypotf (dx, dy);
  73238. lineEndPos += lineLen;
  73239. first = it.closesSubPath;
  73240. }
  73241. const float alpha = (pos - (lineEndPos - lineLen)) / lineLen;
  73242. if (isSolid)
  73243. newDestPath.lineTo (it.x1 + dx * alpha,
  73244. it.y1 + dy * alpha);
  73245. else
  73246. newDestPath.startNewSubPath (it.x1 + dx * alpha,
  73247. it.y1 + dy * alpha);
  73248. }
  73249. }
  73250. END_JUCE_NAMESPACE
  73251. /*** End of inlined file: juce_PathStrokeType.cpp ***/
  73252. /*** Start of inlined file: juce_PositionedRectangle.cpp ***/
  73253. BEGIN_JUCE_NAMESPACE
  73254. PositionedRectangle::PositionedRectangle() throw()
  73255. : x (0.0),
  73256. y (0.0),
  73257. w (0.0),
  73258. h (0.0),
  73259. xMode (anchorAtLeftOrTop | absoluteFromParentTopLeft),
  73260. yMode (anchorAtLeftOrTop | absoluteFromParentTopLeft),
  73261. wMode (absoluteSize),
  73262. hMode (absoluteSize)
  73263. {
  73264. }
  73265. PositionedRectangle::PositionedRectangle (const PositionedRectangle& other) throw()
  73266. : x (other.x),
  73267. y (other.y),
  73268. w (other.w),
  73269. h (other.h),
  73270. xMode (other.xMode),
  73271. yMode (other.yMode),
  73272. wMode (other.wMode),
  73273. hMode (other.hMode)
  73274. {
  73275. }
  73276. const PositionedRectangle& PositionedRectangle::operator= (const PositionedRectangle& other) throw()
  73277. {
  73278. x = other.x;
  73279. y = other.y;
  73280. w = other.w;
  73281. h = other.h;
  73282. xMode = other.xMode;
  73283. yMode = other.yMode;
  73284. wMode = other.wMode;
  73285. hMode = other.hMode;
  73286. return *this;
  73287. }
  73288. PositionedRectangle::~PositionedRectangle() throw()
  73289. {
  73290. }
  73291. const bool PositionedRectangle::operator== (const PositionedRectangle& other) const throw()
  73292. {
  73293. return x == other.x
  73294. && y == other.y
  73295. && w == other.w
  73296. && h == other.h
  73297. && xMode == other.xMode
  73298. && yMode == other.yMode
  73299. && wMode == other.wMode
  73300. && hMode == other.hMode;
  73301. }
  73302. const bool PositionedRectangle::operator!= (const PositionedRectangle& other) const throw()
  73303. {
  73304. return ! operator== (other);
  73305. }
  73306. PositionedRectangle::PositionedRectangle (const String& stringVersion) throw()
  73307. {
  73308. StringArray tokens;
  73309. tokens.addTokens (stringVersion, false);
  73310. decodePosString (tokens [0], xMode, x);
  73311. decodePosString (tokens [1], yMode, y);
  73312. decodeSizeString (tokens [2], wMode, w);
  73313. decodeSizeString (tokens [3], hMode, h);
  73314. }
  73315. const String PositionedRectangle::toString() const throw()
  73316. {
  73317. String s;
  73318. s.preallocateStorage (12);
  73319. addPosDescription (s, xMode, x);
  73320. s << T(' ');
  73321. addPosDescription (s, yMode, y);
  73322. s << T(' ');
  73323. addSizeDescription (s, wMode, w);
  73324. s << T(' ');
  73325. addSizeDescription (s, hMode, h);
  73326. return s;
  73327. }
  73328. const Rectangle<int> PositionedRectangle::getRectangle (const Rectangle<int>& target) const throw()
  73329. {
  73330. jassert (! target.isEmpty());
  73331. double x_, y_, w_, h_;
  73332. applyPosAndSize (x_, w_, x, w, xMode, wMode, target.getX(), target.getWidth());
  73333. applyPosAndSize (y_, h_, y, h, yMode, hMode, target.getY(), target.getHeight());
  73334. return Rectangle<int> (roundToInt (x_), roundToInt (y_),
  73335. roundToInt (w_), roundToInt (h_));
  73336. }
  73337. void PositionedRectangle::getRectangleDouble (const Rectangle<int>& target,
  73338. double& x_, double& y_,
  73339. double& w_, double& h_) const throw()
  73340. {
  73341. jassert (! target.isEmpty());
  73342. applyPosAndSize (x_, w_, x, w, xMode, wMode, target.getX(), target.getWidth());
  73343. applyPosAndSize (y_, h_, y, h, yMode, hMode, target.getY(), target.getHeight());
  73344. }
  73345. void PositionedRectangle::applyToComponent (Component& comp) const throw()
  73346. {
  73347. comp.setBounds (getRectangle (Rectangle<int> (0, 0, comp.getParentWidth(), comp.getParentHeight())));
  73348. }
  73349. void PositionedRectangle::updateFrom (const Rectangle<int>& rectangle,
  73350. const Rectangle<int>& target) throw()
  73351. {
  73352. updatePosAndSize (x, w, rectangle.getX(), rectangle.getWidth(), xMode, wMode, target.getX(), target.getWidth());
  73353. updatePosAndSize (y, h, rectangle.getY(), rectangle.getHeight(), yMode, hMode, target.getY(), target.getHeight());
  73354. }
  73355. void PositionedRectangle::updateFromDouble (const double newX, const double newY,
  73356. const double newW, const double newH,
  73357. const Rectangle<int>& target) throw()
  73358. {
  73359. updatePosAndSize (x, w, newX, newW, xMode, wMode, target.getX(), target.getWidth());
  73360. updatePosAndSize (y, h, newY, newH, yMode, hMode, target.getY(), target.getHeight());
  73361. }
  73362. void PositionedRectangle::updateFromComponent (const Component& comp) throw()
  73363. {
  73364. if (comp.getParentComponent() == 0 && ! comp.isOnDesktop())
  73365. updateFrom (comp.getBounds(), Rectangle<int>());
  73366. else
  73367. updateFrom (comp.getBounds(), Rectangle<int> (0, 0, comp.getParentWidth(), comp.getParentHeight()));
  73368. }
  73369. PositionedRectangle::AnchorPoint PositionedRectangle::getAnchorPointX() const throw()
  73370. {
  73371. return (AnchorPoint) (xMode & (anchorAtLeftOrTop | anchorAtRightOrBottom | anchorAtCentre));
  73372. }
  73373. PositionedRectangle::PositionMode PositionedRectangle::getPositionModeX() const throw()
  73374. {
  73375. return (PositionMode) (xMode & (absoluteFromParentTopLeft
  73376. | absoluteFromParentBottomRight
  73377. | absoluteFromParentCentre
  73378. | proportionOfParentSize));
  73379. }
  73380. PositionedRectangle::AnchorPoint PositionedRectangle::getAnchorPointY() const throw()
  73381. {
  73382. return (AnchorPoint) (yMode & (anchorAtLeftOrTop | anchorAtRightOrBottom | anchorAtCentre));
  73383. }
  73384. PositionedRectangle::PositionMode PositionedRectangle::getPositionModeY() const throw()
  73385. {
  73386. return (PositionMode) (yMode & (absoluteFromParentTopLeft
  73387. | absoluteFromParentBottomRight
  73388. | absoluteFromParentCentre
  73389. | proportionOfParentSize));
  73390. }
  73391. PositionedRectangle::SizeMode PositionedRectangle::getWidthMode() const throw()
  73392. {
  73393. return (SizeMode) wMode;
  73394. }
  73395. PositionedRectangle::SizeMode PositionedRectangle::getHeightMode() const throw()
  73396. {
  73397. return (SizeMode) hMode;
  73398. }
  73399. void PositionedRectangle::setModes (const AnchorPoint xAnchor,
  73400. const PositionMode xMode_,
  73401. const AnchorPoint yAnchor,
  73402. const PositionMode yMode_,
  73403. const SizeMode widthMode,
  73404. const SizeMode heightMode,
  73405. const Rectangle<int>& target) throw()
  73406. {
  73407. if (xMode != (xAnchor | xMode_) || wMode != widthMode)
  73408. {
  73409. double tx, tw;
  73410. applyPosAndSize (tx, tw, x, w, xMode, wMode, target.getX(), target.getWidth());
  73411. xMode = (uint8) (xAnchor | xMode_);
  73412. wMode = (uint8) widthMode;
  73413. updatePosAndSize (x, w, tx, tw, xMode, wMode, target.getX(), target.getWidth());
  73414. }
  73415. if (yMode != (yAnchor | yMode_) || hMode != heightMode)
  73416. {
  73417. double ty, th;
  73418. applyPosAndSize (ty, th, y, h, yMode, hMode, target.getY(), target.getHeight());
  73419. yMode = (uint8) (yAnchor | yMode_);
  73420. hMode = (uint8) heightMode;
  73421. updatePosAndSize (y, h, ty, th, yMode, hMode, target.getY(), target.getHeight());
  73422. }
  73423. }
  73424. bool PositionedRectangle::isPositionAbsolute() const throw()
  73425. {
  73426. return xMode == absoluteFromParentTopLeft
  73427. && yMode == absoluteFromParentTopLeft
  73428. && wMode == absoluteSize
  73429. && hMode == absoluteSize;
  73430. }
  73431. void PositionedRectangle::addPosDescription (String& s, const uint8 mode, const double value) const throw()
  73432. {
  73433. if ((mode & proportionOfParentSize) != 0)
  73434. {
  73435. s << (roundToInt (value * 100000.0) / 1000.0) << T('%');
  73436. }
  73437. else
  73438. {
  73439. s << (roundToInt (value * 100.0) / 100.0);
  73440. if ((mode & absoluteFromParentBottomRight) != 0)
  73441. s << T('R');
  73442. else if ((mode & absoluteFromParentCentre) != 0)
  73443. s << T('C');
  73444. }
  73445. if ((mode & anchorAtRightOrBottom) != 0)
  73446. s << T('r');
  73447. else if ((mode & anchorAtCentre) != 0)
  73448. s << T('c');
  73449. }
  73450. void PositionedRectangle::addSizeDescription (String& s, const uint8 mode, const double value) const throw()
  73451. {
  73452. if (mode == proportionalSize)
  73453. s << (roundToInt (value * 100000.0) / 1000.0) << T('%');
  73454. else if (mode == parentSizeMinusAbsolute)
  73455. s << (roundToInt (value * 100.0) / 100.0) << T('M');
  73456. else
  73457. s << (roundToInt (value * 100.0) / 100.0);
  73458. }
  73459. void PositionedRectangle::decodePosString (const String& s, uint8& mode, double& value) throw()
  73460. {
  73461. if (s.containsChar (T('r')))
  73462. mode = anchorAtRightOrBottom;
  73463. else if (s.containsChar (T('c')))
  73464. mode = anchorAtCentre;
  73465. else
  73466. mode = anchorAtLeftOrTop;
  73467. if (s.containsChar (T('%')))
  73468. {
  73469. mode |= proportionOfParentSize;
  73470. value = s.removeCharacters (T("%rcRC")).getDoubleValue() / 100.0;
  73471. }
  73472. else
  73473. {
  73474. if (s.containsChar (T('R')))
  73475. mode |= absoluteFromParentBottomRight;
  73476. else if (s.containsChar (T('C')))
  73477. mode |= absoluteFromParentCentre;
  73478. else
  73479. mode |= absoluteFromParentTopLeft;
  73480. value = s.removeCharacters (T("rcRC")).getDoubleValue();
  73481. }
  73482. }
  73483. void PositionedRectangle::decodeSizeString (const String& s, uint8& mode, double& value) throw()
  73484. {
  73485. if (s.containsChar (T('%')))
  73486. {
  73487. mode = proportionalSize;
  73488. value = s.upToFirstOccurrenceOf (T("%"), false, false).getDoubleValue() / 100.0;
  73489. }
  73490. else if (s.containsChar (T('M')))
  73491. {
  73492. mode = parentSizeMinusAbsolute;
  73493. value = s.getDoubleValue();
  73494. }
  73495. else
  73496. {
  73497. mode = absoluteSize;
  73498. value = s.getDoubleValue();
  73499. }
  73500. }
  73501. void PositionedRectangle::applyPosAndSize (double& xOut, double& wOut,
  73502. const double x_, const double w_,
  73503. const uint8 xMode_, const uint8 wMode_,
  73504. const int parentPos,
  73505. const int parentSize) const throw()
  73506. {
  73507. if (wMode_ == proportionalSize)
  73508. wOut = roundToInt (w_ * parentSize);
  73509. else if (wMode_ == parentSizeMinusAbsolute)
  73510. wOut = jmax (0, parentSize - roundToInt (w_));
  73511. else
  73512. wOut = roundToInt (w_);
  73513. if ((xMode_ & proportionOfParentSize) != 0)
  73514. xOut = parentPos + x_ * parentSize;
  73515. else if ((xMode_ & absoluteFromParentBottomRight) != 0)
  73516. xOut = (parentPos + parentSize) - x_;
  73517. else if ((xMode_ & absoluteFromParentCentre) != 0)
  73518. xOut = x_ + (parentPos + parentSize / 2);
  73519. else
  73520. xOut = x_ + parentPos;
  73521. if ((xMode_ & anchorAtRightOrBottom) != 0)
  73522. xOut -= wOut;
  73523. else if ((xMode_ & anchorAtCentre) != 0)
  73524. xOut -= wOut / 2;
  73525. }
  73526. void PositionedRectangle::updatePosAndSize (double& xOut, double& wOut,
  73527. double x_, const double w_,
  73528. const uint8 xMode_, const uint8 wMode_,
  73529. const int parentPos,
  73530. const int parentSize) const throw()
  73531. {
  73532. if (wMode_ == proportionalSize)
  73533. {
  73534. if (parentSize > 0)
  73535. wOut = w_ / parentSize;
  73536. }
  73537. else if (wMode_ == parentSizeMinusAbsolute)
  73538. wOut = parentSize - w_;
  73539. else
  73540. wOut = w_;
  73541. if ((xMode_ & anchorAtRightOrBottom) != 0)
  73542. x_ += w_;
  73543. else if ((xMode_ & anchorAtCentre) != 0)
  73544. x_ += w_ / 2;
  73545. if ((xMode_ & proportionOfParentSize) != 0)
  73546. {
  73547. if (parentSize > 0)
  73548. xOut = (x_ - parentPos) / parentSize;
  73549. }
  73550. else if ((xMode_ & absoluteFromParentBottomRight) != 0)
  73551. xOut = (parentPos + parentSize) - x_;
  73552. else if ((xMode_ & absoluteFromParentCentre) != 0)
  73553. xOut = x_ - (parentPos + parentSize / 2);
  73554. else
  73555. xOut = x_ - parentPos;
  73556. }
  73557. END_JUCE_NAMESPACE
  73558. /*** End of inlined file: juce_PositionedRectangle.cpp ***/
  73559. /*** Start of inlined file: juce_RectangleList.cpp ***/
  73560. BEGIN_JUCE_NAMESPACE
  73561. RectangleList::RectangleList() throw()
  73562. {
  73563. }
  73564. RectangleList::RectangleList (const Rectangle<int>& rect) throw()
  73565. {
  73566. if (! rect.isEmpty())
  73567. rects.add (rect);
  73568. }
  73569. RectangleList::RectangleList (const RectangleList& other) throw()
  73570. : rects (other.rects)
  73571. {
  73572. }
  73573. const RectangleList& RectangleList::operator= (const RectangleList& other) throw()
  73574. {
  73575. rects = other.rects;
  73576. return *this;
  73577. }
  73578. RectangleList::~RectangleList() throw()
  73579. {
  73580. }
  73581. void RectangleList::clear() throw()
  73582. {
  73583. rects.clearQuick();
  73584. }
  73585. const Rectangle<int> RectangleList::getRectangle (const int index) const throw()
  73586. {
  73587. if (((unsigned int) index) < (unsigned int) rects.size())
  73588. return rects.getReference (index);
  73589. return Rectangle<int>();
  73590. }
  73591. bool RectangleList::isEmpty() const throw()
  73592. {
  73593. return rects.size() == 0;
  73594. }
  73595. RectangleList::Iterator::Iterator (const RectangleList& list) throw()
  73596. : current (0),
  73597. owner (list),
  73598. index (list.rects.size())
  73599. {
  73600. }
  73601. RectangleList::Iterator::~Iterator() throw()
  73602. {
  73603. }
  73604. bool RectangleList::Iterator::next() throw()
  73605. {
  73606. if (--index >= 0)
  73607. {
  73608. current = & (owner.rects.getReference (index));
  73609. return true;
  73610. }
  73611. return false;
  73612. }
  73613. void RectangleList::add (const Rectangle<int>& rect) throw()
  73614. {
  73615. if (! rect.isEmpty())
  73616. {
  73617. if (rects.size() == 0)
  73618. {
  73619. rects.add (rect);
  73620. }
  73621. else
  73622. {
  73623. bool anyOverlaps = false;
  73624. int i;
  73625. for (i = rects.size(); --i >= 0;)
  73626. {
  73627. Rectangle<int>& ourRect = rects.getReference (i);
  73628. if (rect.intersects (ourRect))
  73629. {
  73630. if (rect.contains (ourRect))
  73631. rects.remove (i);
  73632. else if (! ourRect.reduceIfPartlyContainedIn (rect))
  73633. anyOverlaps = true;
  73634. }
  73635. }
  73636. if (anyOverlaps && rects.size() > 0)
  73637. {
  73638. RectangleList r (rect);
  73639. for (i = rects.size(); --i >= 0;)
  73640. {
  73641. const Rectangle<int>& ourRect = rects.getReference (i);
  73642. if (rect.intersects (ourRect))
  73643. {
  73644. r.subtract (ourRect);
  73645. if (r.rects.size() == 0)
  73646. return;
  73647. }
  73648. }
  73649. for (i = r.getNumRectangles(); --i >= 0;)
  73650. rects.add (r.rects.getReference (i));
  73651. }
  73652. else
  73653. {
  73654. rects.add (rect);
  73655. }
  73656. }
  73657. }
  73658. }
  73659. void RectangleList::addWithoutMerging (const Rectangle<int>& rect) throw()
  73660. {
  73661. rects.add (rect);
  73662. }
  73663. void RectangleList::add (const int x, const int y, const int w, const int h) throw()
  73664. {
  73665. if (rects.size() == 0)
  73666. {
  73667. if (w > 0 && h > 0)
  73668. rects.add (Rectangle<int> (x, y, w, h));
  73669. }
  73670. else
  73671. {
  73672. add (Rectangle<int> (x, y, w, h));
  73673. }
  73674. }
  73675. void RectangleList::add (const RectangleList& other) throw()
  73676. {
  73677. for (int i = 0; i < other.rects.size(); ++i)
  73678. add (other.rects.getReference (i));
  73679. }
  73680. void RectangleList::subtract (const Rectangle<int>& rect) throw()
  73681. {
  73682. const int originalNumRects = rects.size();
  73683. if (originalNumRects > 0)
  73684. {
  73685. const int x1 = rect.x;
  73686. const int y1 = rect.y;
  73687. const int x2 = x1 + rect.w;
  73688. const int y2 = y1 + rect.h;
  73689. for (int i = getNumRectangles(); --i >= 0;)
  73690. {
  73691. Rectangle<int>& r = rects.getReference (i);
  73692. const int rx1 = r.x;
  73693. const int ry1 = r.y;
  73694. const int rx2 = rx1 + r.w;
  73695. const int ry2 = ry1 + r.h;
  73696. if (! (x2 <= rx1 || x1 >= rx2 || y2 <= ry1 || y1 >= ry2))
  73697. {
  73698. if (x1 > rx1 && x1 < rx2)
  73699. {
  73700. if (y1 <= ry1 && y2 >= ry2 && x2 >= rx2)
  73701. {
  73702. r.w = x1 - rx1;
  73703. }
  73704. else
  73705. {
  73706. r.x = x1;
  73707. r.w = rx2 - x1;
  73708. rects.insert (i + 1, Rectangle<int> (rx1, ry1, x1 - rx1, ry2 - ry1));
  73709. i += 2;
  73710. }
  73711. }
  73712. else if (x2 > rx1 && x2 < rx2)
  73713. {
  73714. r.x = x2;
  73715. r.w = rx2 - x2;
  73716. if (y1 > ry1 || y2 < ry2 || x1 > rx1)
  73717. {
  73718. rects.insert (i + 1, Rectangle<int> (rx1, ry1, x2 - rx1, ry2 - ry1));
  73719. i += 2;
  73720. }
  73721. }
  73722. else if (y1 > ry1 && y1 < ry2)
  73723. {
  73724. if (x1 <= rx1 && x2 >= rx2 && y2 >= ry2)
  73725. {
  73726. r.h = y1 - ry1;
  73727. }
  73728. else
  73729. {
  73730. r.y = y1;
  73731. r.h = ry2 - y1;
  73732. rects.insert (i + 1, Rectangle<int> (rx1, ry1, rx2 - rx1, y1 - ry1));
  73733. i += 2;
  73734. }
  73735. }
  73736. else if (y2 > ry1 && y2 < ry2)
  73737. {
  73738. r.y = y2;
  73739. r.h = ry2 - y2;
  73740. if (x1 > rx1 || x2 < rx2 || y1 > ry1)
  73741. {
  73742. rects.insert (i + 1, Rectangle<int> (rx1, ry1, rx2 - rx1, y2 - ry1));
  73743. i += 2;
  73744. }
  73745. }
  73746. else
  73747. {
  73748. rects.remove (i);
  73749. }
  73750. }
  73751. }
  73752. if (rects.size() > originalNumRects + 10)
  73753. consolidate();
  73754. }
  73755. }
  73756. void RectangleList::subtract (const RectangleList& otherList) throw()
  73757. {
  73758. for (int i = otherList.rects.size(); --i >= 0;)
  73759. subtract (otherList.rects.getReference (i));
  73760. }
  73761. bool RectangleList::clipTo (const Rectangle<int>& rect) throw()
  73762. {
  73763. bool notEmpty = false;
  73764. if (rect.isEmpty())
  73765. {
  73766. clear();
  73767. }
  73768. else
  73769. {
  73770. for (int i = rects.size(); --i >= 0;)
  73771. {
  73772. Rectangle<int>& r = rects.getReference (i);
  73773. if (! rect.intersectRectangle (r.x, r.y, r.w, r.h))
  73774. rects.remove (i);
  73775. else
  73776. notEmpty = true;
  73777. }
  73778. }
  73779. return notEmpty;
  73780. }
  73781. bool RectangleList::clipTo (const RectangleList& other) throw()
  73782. {
  73783. if (rects.size() == 0)
  73784. return false;
  73785. RectangleList result;
  73786. for (int j = 0; j < rects.size(); ++j)
  73787. {
  73788. const Rectangle<int>& rect = rects.getReference (j);
  73789. for (int i = other.rects.size(); --i >= 0;)
  73790. {
  73791. Rectangle<int> r (other.rects.getReference (i));
  73792. if (rect.intersectRectangle (r.x, r.y, r.w, r.h))
  73793. result.rects.add (r);
  73794. }
  73795. }
  73796. swapWith (result);
  73797. return ! isEmpty();
  73798. }
  73799. bool RectangleList::getIntersectionWith (const Rectangle<int>& rect, RectangleList& destRegion) const throw()
  73800. {
  73801. destRegion.clear();
  73802. if (! rect.isEmpty())
  73803. {
  73804. for (int i = rects.size(); --i >= 0;)
  73805. {
  73806. Rectangle<int> r (rects.getReference (i));
  73807. if (rect.intersectRectangle (r.x, r.y, r.w, r.h))
  73808. destRegion.rects.add (r);
  73809. }
  73810. }
  73811. return destRegion.rects.size() > 0;
  73812. }
  73813. void RectangleList::swapWith (RectangleList& otherList) throw()
  73814. {
  73815. rects.swapWithArray (otherList.rects);
  73816. }
  73817. void RectangleList::consolidate() throw()
  73818. {
  73819. int i;
  73820. for (i = 0; i < getNumRectangles() - 1; ++i)
  73821. {
  73822. Rectangle<int>& r = rects.getReference (i);
  73823. const int rx1 = r.x;
  73824. const int ry1 = r.y;
  73825. const int rx2 = rx1 + r.w;
  73826. const int ry2 = ry1 + r.h;
  73827. for (int j = rects.size(); --j > i;)
  73828. {
  73829. Rectangle<int>& r2 = rects.getReference (j);
  73830. const int jrx1 = r2.x;
  73831. const int jry1 = r2.y;
  73832. const int jrx2 = jrx1 + r2.w;
  73833. const int jry2 = jry1 + r2.h;
  73834. // if the vertical edges of any blocks are touching and their horizontals don't
  73835. // line up, split them horizontally..
  73836. if (jrx1 == rx2 || jrx2 == rx1)
  73837. {
  73838. if (jry1 > ry1 && jry1 < ry2)
  73839. {
  73840. r.h = jry1 - ry1;
  73841. rects.add (Rectangle<int> (rx1, jry1, rx2 - rx1, ry2 - jry1));
  73842. i = -1;
  73843. break;
  73844. }
  73845. if (jry2 > ry1 && jry2 < ry2)
  73846. {
  73847. r.h = jry2 - ry1;
  73848. rects.add (Rectangle<int> (rx1, jry2, rx2 - rx1, ry2 - jry2));
  73849. i = -1;
  73850. break;
  73851. }
  73852. else if (ry1 > jry1 && ry1 < jry2)
  73853. {
  73854. r2.h = ry1 - jry1;
  73855. rects.add (Rectangle<int> (jrx1, ry1, jrx2 - jrx1, jry2 - ry1));
  73856. i = -1;
  73857. break;
  73858. }
  73859. else if (ry2 > jry1 && ry2 < jry2)
  73860. {
  73861. r2.h = ry2 - jry1;
  73862. rects.add (Rectangle<int> (jrx1, ry2, jrx2 - jrx1, jry2 - ry2));
  73863. i = -1;
  73864. break;
  73865. }
  73866. }
  73867. }
  73868. }
  73869. for (i = 0; i < rects.size() - 1; ++i)
  73870. {
  73871. Rectangle<int>& r = rects.getReference (i);
  73872. for (int j = rects.size(); --j > i;)
  73873. {
  73874. if (r.enlargeIfAdjacent (rects.getReference (j)))
  73875. {
  73876. rects.remove (j);
  73877. i = -1;
  73878. break;
  73879. }
  73880. }
  73881. }
  73882. }
  73883. bool RectangleList::containsPoint (const int x, const int y) const throw()
  73884. {
  73885. for (int i = getNumRectangles(); --i >= 0;)
  73886. if (rects.getReference (i).contains (x, y))
  73887. return true;
  73888. return false;
  73889. }
  73890. bool RectangleList::containsRectangle (const Rectangle<int>& rectangleToCheck) const throw()
  73891. {
  73892. if (rects.size() > 1)
  73893. {
  73894. RectangleList r (rectangleToCheck);
  73895. for (int i = rects.size(); --i >= 0;)
  73896. {
  73897. r.subtract (rects.getReference (i));
  73898. if (r.rects.size() == 0)
  73899. return true;
  73900. }
  73901. }
  73902. else if (rects.size() > 0)
  73903. {
  73904. return rects.getReference (0).contains (rectangleToCheck);
  73905. }
  73906. return false;
  73907. }
  73908. bool RectangleList::intersectsRectangle (const Rectangle<int>& rectangleToCheck) const throw()
  73909. {
  73910. for (int i = rects.size(); --i >= 0;)
  73911. if (rects.getReference (i).intersects (rectangleToCheck))
  73912. return true;
  73913. return false;
  73914. }
  73915. bool RectangleList::intersects (const RectangleList& other) const throw()
  73916. {
  73917. for (int i = rects.size(); --i >= 0;)
  73918. if (other.intersectsRectangle (rects.getReference (i)))
  73919. return true;
  73920. return false;
  73921. }
  73922. const Rectangle<int> RectangleList::getBounds() const throw()
  73923. {
  73924. if (rects.size() <= 1)
  73925. {
  73926. if (rects.size() == 0)
  73927. return Rectangle<int>();
  73928. else
  73929. return rects.getReference (0);
  73930. }
  73931. else
  73932. {
  73933. const Rectangle<int>& r = rects.getReference (0);
  73934. int minX = r.x;
  73935. int minY = r.y;
  73936. int maxX = minX + r.w;
  73937. int maxY = minY + r.h;
  73938. for (int i = rects.size(); --i > 0;)
  73939. {
  73940. const Rectangle<int>& r2 = rects.getReference (i);
  73941. minX = jmin (minX, r2.x);
  73942. minY = jmin (minY, r2.y);
  73943. maxX = jmax (maxX, r2.getRight());
  73944. maxY = jmax (maxY, r2.getBottom());
  73945. }
  73946. return Rectangle<int> (minX, minY, maxX - minX, maxY - minY);
  73947. }
  73948. }
  73949. void RectangleList::offsetAll (const int dx, const int dy) throw()
  73950. {
  73951. for (int i = rects.size(); --i >= 0;)
  73952. {
  73953. Rectangle<int>& r = rects.getReference (i);
  73954. r.x += dx;
  73955. r.y += dy;
  73956. }
  73957. }
  73958. const Path RectangleList::toPath() const throw()
  73959. {
  73960. Path p;
  73961. for (int i = rects.size(); --i >= 0;)
  73962. {
  73963. const Rectangle<int>& r = rects.getReference (i);
  73964. p.addRectangle ((float) r.x,
  73965. (float) r.y,
  73966. (float) r.w,
  73967. (float) r.h);
  73968. }
  73969. return p;
  73970. }
  73971. END_JUCE_NAMESPACE
  73972. /*** End of inlined file: juce_RectangleList.cpp ***/
  73973. /*** Start of inlined file: juce_Image.cpp ***/
  73974. BEGIN_JUCE_NAMESPACE
  73975. static const int fullAlphaThreshold = 253;
  73976. Image::Image (const PixelFormat format_,
  73977. const int imageWidth_,
  73978. const int imageHeight_)
  73979. : format (format_),
  73980. imageWidth (imageWidth_),
  73981. imageHeight (imageHeight_),
  73982. imageData (0)
  73983. {
  73984. jassert (format_ == RGB || format_ == ARGB || format_ == SingleChannel);
  73985. jassert (imageWidth_ > 0 && imageHeight_ > 0); // it's illegal to create a zero-sized image - the
  73986. // actual image will be at least 1x1.
  73987. }
  73988. Image::Image (const PixelFormat format_,
  73989. const int imageWidth_,
  73990. const int imageHeight_,
  73991. const bool clearImage)
  73992. : format (format_),
  73993. imageWidth (imageWidth_),
  73994. imageHeight (imageHeight_)
  73995. {
  73996. jassert (format_ == RGB || format_ == ARGB || format_ == SingleChannel);
  73997. jassert (imageWidth_ > 0 && imageHeight_ > 0); // it's illegal to create a zero-sized image - the
  73998. // actual image will be at least 1x1.
  73999. pixelStride = (format == RGB) ? 3 : ((format == ARGB) ? 4 : 1);
  74000. lineStride = (pixelStride * jmax (1, imageWidth_) + 3) & ~3;
  74001. imageDataAllocated.allocate (lineStride * jmax (1, imageHeight_), clearImage);
  74002. imageData = imageDataAllocated;
  74003. }
  74004. Image::Image (const Image& other)
  74005. : format (other.format),
  74006. imageWidth (other.imageWidth),
  74007. imageHeight (other.imageHeight)
  74008. {
  74009. pixelStride = (format == RGB) ? 3 : ((format == ARGB) ? 4 : 1);
  74010. lineStride = (pixelStride * jmax (1, imageWidth) + 3) & ~3;
  74011. imageDataAllocated.malloc (lineStride * jmax (1, imageHeight));
  74012. imageData = imageDataAllocated;
  74013. BitmapData srcData (other, 0, 0, imageWidth, imageHeight);
  74014. setPixelData (0, 0, imageWidth, imageHeight, srcData.data, srcData.lineStride);
  74015. }
  74016. Image::~Image()
  74017. {
  74018. }
  74019. LowLevelGraphicsContext* Image::createLowLevelContext()
  74020. {
  74021. return new LowLevelGraphicsSoftwareRenderer (*this);
  74022. }
  74023. Image::BitmapData::BitmapData (Image& image, int x, int y, int w, int h, const bool /*makeWritable*/)
  74024. : data (image.imageData + image.lineStride * y + image.pixelStride * x),
  74025. lineStride (image.lineStride),
  74026. pixelStride (image.pixelStride),
  74027. width (w),
  74028. height (h)
  74029. {
  74030. jassert (x >= 0 && y >= 0 && w > 0 && h > 0 && x + w <= image.getWidth() && y + h <= image.getHeight());
  74031. }
  74032. Image::BitmapData::BitmapData (const Image& image, int x, int y, int w, int h)
  74033. : data (image.imageData + image.lineStride * y + image.pixelStride * x),
  74034. lineStride (image.lineStride),
  74035. pixelStride (image.pixelStride),
  74036. width (w),
  74037. height (h)
  74038. {
  74039. jassert (x >= 0 && y >= 0 && w > 0 && h > 0 && x + w <= image.getWidth() && y + h <= image.getHeight());
  74040. }
  74041. Image::BitmapData::~BitmapData()
  74042. {
  74043. }
  74044. void Image::setPixelData (int x, int y, int w, int h,
  74045. const uint8* sourcePixelData, int sourceLineStride)
  74046. {
  74047. jassert (x >= 0 && y >= 0 && w > 0 && h > 0 && x + w <= imageWidth && y + h <= imageHeight);
  74048. if (Rectangle<int>::intersectRectangles (x, y, w, h, 0, 0, imageWidth, imageHeight))
  74049. {
  74050. const BitmapData dest (*this, x, y, w, h, true);
  74051. for (int i = 0; i < h; ++i)
  74052. {
  74053. memcpy (dest.getLinePointer(i),
  74054. sourcePixelData + sourceLineStride * i,
  74055. w * dest.pixelStride);
  74056. }
  74057. }
  74058. }
  74059. void Image::clear (int dx, int dy, int dw, int dh,
  74060. const Colour& colourToClearTo)
  74061. {
  74062. const PixelARGB col (colourToClearTo.getPixelARGB());
  74063. const BitmapData destData (*this, dx, dy, dw, dh, true);
  74064. uint8* dest = destData.data;
  74065. while (--dh >= 0)
  74066. {
  74067. uint8* line = dest;
  74068. dest += destData.lineStride;
  74069. if (isARGB())
  74070. {
  74071. for (int x = dw; --x >= 0;)
  74072. {
  74073. ((PixelARGB*) line)->set (col);
  74074. line += destData.pixelStride;
  74075. }
  74076. }
  74077. else if (isRGB())
  74078. {
  74079. for (int x = dw; --x >= 0;)
  74080. {
  74081. ((PixelRGB*) line)->set (col);
  74082. line += destData.pixelStride;
  74083. }
  74084. }
  74085. else
  74086. {
  74087. for (int x = dw; --x >= 0;)
  74088. {
  74089. *line = col.getAlpha();
  74090. line += destData.pixelStride;
  74091. }
  74092. }
  74093. }
  74094. }
  74095. Image* Image::createCopy (int newWidth, int newHeight,
  74096. const Graphics::ResamplingQuality quality) const
  74097. {
  74098. if (newWidth < 0)
  74099. newWidth = imageWidth;
  74100. if (newHeight < 0)
  74101. newHeight = imageHeight;
  74102. Image* const newImage = Image::createNativeImage (format, newWidth, newHeight, true);
  74103. Graphics g (*newImage);
  74104. g.setImageResamplingQuality (quality);
  74105. g.drawImage (this,
  74106. 0, 0, newWidth, newHeight,
  74107. 0, 0, imageWidth, imageHeight,
  74108. false);
  74109. return newImage;
  74110. }
  74111. Image* Image::createCopyOfAlphaChannel() const
  74112. {
  74113. jassert (format != SingleChannel);
  74114. Image* const newImage = Image::createNativeImage (SingleChannel, imageWidth, imageHeight, false);
  74115. if (! hasAlphaChannel())
  74116. {
  74117. newImage->clear (0, 0, imageWidth, imageHeight, Colours::black);
  74118. }
  74119. else
  74120. {
  74121. const BitmapData destData (*newImage, 0, 0, imageWidth, imageHeight, true);
  74122. const BitmapData srcData (*this, 0, 0, imageWidth, imageHeight);
  74123. for (int y = 0; y < imageHeight; ++y)
  74124. {
  74125. const PixelARGB* src = (const PixelARGB*) srcData.getLinePointer(y);
  74126. uint8* dst = destData.getLinePointer (y);
  74127. for (int x = imageWidth; --x >= 0;)
  74128. {
  74129. *dst++ = src->getAlpha();
  74130. ++src;
  74131. }
  74132. }
  74133. }
  74134. return newImage;
  74135. }
  74136. const Colour Image::getPixelAt (const int x, const int y) const
  74137. {
  74138. Colour c;
  74139. if (((unsigned int) x) < (unsigned int) imageWidth
  74140. && ((unsigned int) y) < (unsigned int) imageHeight)
  74141. {
  74142. const BitmapData srcData (*this, x, y, 1, 1);
  74143. if (isARGB())
  74144. {
  74145. PixelARGB p (*(const PixelARGB*) srcData.data);
  74146. p.unpremultiply();
  74147. c = Colour (p.getARGB());
  74148. }
  74149. else if (isRGB())
  74150. c = Colour (((const PixelRGB*) srcData.data)->getARGB());
  74151. else
  74152. c = Colour ((uint8) 0, (uint8) 0, (uint8) 0, *(srcData.data));
  74153. }
  74154. return c;
  74155. }
  74156. void Image::setPixelAt (const int x, const int y,
  74157. const Colour& colour)
  74158. {
  74159. if (((unsigned int) x) < (unsigned int) imageWidth
  74160. && ((unsigned int) y) < (unsigned int) imageHeight)
  74161. {
  74162. const BitmapData destData (*this, x, y, 1, 1, true);
  74163. const PixelARGB col (colour.getPixelARGB());
  74164. if (isARGB())
  74165. ((PixelARGB*) destData.data)->set (col);
  74166. else if (isRGB())
  74167. ((PixelRGB*) destData.data)->set (col);
  74168. else
  74169. *(destData.data) = col.getAlpha();
  74170. }
  74171. }
  74172. void Image::multiplyAlphaAt (const int x, const int y,
  74173. const float multiplier)
  74174. {
  74175. if (((unsigned int) x) < (unsigned int) imageWidth
  74176. && ((unsigned int) y) < (unsigned int) imageHeight
  74177. && hasAlphaChannel())
  74178. {
  74179. const BitmapData destData (*this, x, y, 1, 1, true);
  74180. if (isARGB())
  74181. ((PixelARGB*) destData.data)->multiplyAlpha (multiplier);
  74182. else
  74183. *(destData.data) = (uint8) (*(destData.data) * multiplier);
  74184. }
  74185. }
  74186. void Image::multiplyAllAlphas (const float amountToMultiplyBy)
  74187. {
  74188. if (hasAlphaChannel())
  74189. {
  74190. const BitmapData destData (*this, 0, 0, getWidth(), getHeight(), true);
  74191. if (isARGB())
  74192. {
  74193. for (int y = 0; y < imageHeight; ++y)
  74194. {
  74195. uint8* p = destData.getLinePointer (y);
  74196. for (int x = 0; x < imageWidth; ++x)
  74197. {
  74198. ((PixelARGB*) p)->multiplyAlpha (amountToMultiplyBy);
  74199. p += destData.pixelStride;
  74200. }
  74201. }
  74202. }
  74203. else
  74204. {
  74205. for (int y = 0; y < imageHeight; ++y)
  74206. {
  74207. uint8* p = destData.getLinePointer (y);
  74208. for (int x = 0; x < imageWidth; ++x)
  74209. {
  74210. *p = (uint8) (*p * amountToMultiplyBy);
  74211. p += destData.pixelStride;
  74212. }
  74213. }
  74214. }
  74215. }
  74216. else
  74217. {
  74218. jassertfalse // can't do this without an alpha-channel!
  74219. }
  74220. }
  74221. void Image::desaturate()
  74222. {
  74223. if (isARGB() || isRGB())
  74224. {
  74225. const BitmapData destData (*this, 0, 0, getWidth(), getHeight(), true);
  74226. if (isARGB())
  74227. {
  74228. for (int y = 0; y < imageHeight; ++y)
  74229. {
  74230. uint8* p = destData.getLinePointer (y);
  74231. for (int x = 0; x < imageWidth; ++x)
  74232. {
  74233. ((PixelARGB*) p)->desaturate();
  74234. p += destData.pixelStride;
  74235. }
  74236. }
  74237. }
  74238. else
  74239. {
  74240. for (int y = 0; y < imageHeight; ++y)
  74241. {
  74242. uint8* p = destData.getLinePointer (y);
  74243. for (int x = 0; x < imageWidth; ++x)
  74244. {
  74245. ((PixelRGB*) p)->desaturate();
  74246. p += destData.pixelStride;
  74247. }
  74248. }
  74249. }
  74250. }
  74251. }
  74252. void Image::createSolidAreaMask (RectangleList& result, const float alphaThreshold) const
  74253. {
  74254. if (hasAlphaChannel())
  74255. {
  74256. const uint8 threshold = (uint8) jlimit (0, 255, roundToInt (alphaThreshold * 255.0f));
  74257. SparseSet <int> pixelsOnRow;
  74258. const BitmapData srcData (*this, 0, 0, getWidth(), getHeight());
  74259. for (int y = 0; y < imageHeight; ++y)
  74260. {
  74261. pixelsOnRow.clear();
  74262. const uint8* lineData = srcData.getLinePointer (y);
  74263. if (isARGB())
  74264. {
  74265. for (int x = 0; x < imageWidth; ++x)
  74266. {
  74267. if (((const PixelARGB*) lineData)->getAlpha() >= threshold)
  74268. pixelsOnRow.addRange (x, 1);
  74269. lineData += srcData.pixelStride;
  74270. }
  74271. }
  74272. else
  74273. {
  74274. for (int x = 0; x < imageWidth; ++x)
  74275. {
  74276. if (*lineData >= threshold)
  74277. pixelsOnRow.addRange (x, 1);
  74278. lineData += srcData.pixelStride;
  74279. }
  74280. }
  74281. for (int i = 0; i < pixelsOnRow.getNumRanges(); ++i)
  74282. {
  74283. int x, w;
  74284. if (pixelsOnRow.getRange (i, x, w))
  74285. result.add (Rectangle<int> (x, y, w, 1));
  74286. }
  74287. result.consolidate();
  74288. }
  74289. }
  74290. else
  74291. {
  74292. result.add (0, 0, imageWidth, imageHeight);
  74293. }
  74294. }
  74295. void Image::moveImageSection (int dx, int dy,
  74296. int sx, int sy,
  74297. int w, int h)
  74298. {
  74299. if (dx < 0)
  74300. {
  74301. w += dx;
  74302. sx -= dx;
  74303. dx = 0;
  74304. }
  74305. if (dy < 0)
  74306. {
  74307. h += dy;
  74308. sy -= dy;
  74309. dy = 0;
  74310. }
  74311. if (sx < 0)
  74312. {
  74313. w += sx;
  74314. dx -= sx;
  74315. sx = 0;
  74316. }
  74317. if (sy < 0)
  74318. {
  74319. h += sy;
  74320. dy -= sy;
  74321. sy = 0;
  74322. }
  74323. const int minX = jmin (dx, sx);
  74324. const int minY = jmin (dy, sy);
  74325. w = jmin (w, getWidth() - jmax (sx, dx));
  74326. h = jmin (h, getHeight() - jmax (sy, dy));
  74327. if (w > 0 && h > 0)
  74328. {
  74329. const int maxX = jmax (dx, sx) + w;
  74330. const int maxY = jmax (dy, sy) + h;
  74331. const BitmapData destData (*this, minX, minY, maxX - minX, maxY - minY, true);
  74332. uint8* dst = destData.getPixelPointer (dx - minX, dy - minY);
  74333. const uint8* src = destData.getPixelPointer (sx - minX, sy - minY);
  74334. const int lineSize = destData.pixelStride * w;
  74335. if (dy > sy)
  74336. {
  74337. while (--h >= 0)
  74338. {
  74339. const int offset = h * destData.lineStride;
  74340. memmove (dst + offset, src + offset, lineSize);
  74341. }
  74342. }
  74343. else if (dst != src)
  74344. {
  74345. while (--h >= 0)
  74346. {
  74347. memmove (dst, src, lineSize);
  74348. dst += destData.lineStride;
  74349. src += destData.lineStride;
  74350. }
  74351. }
  74352. }
  74353. }
  74354. END_JUCE_NAMESPACE
  74355. /*** End of inlined file: juce_Image.cpp ***/
  74356. /*** Start of inlined file: juce_ImageCache.cpp ***/
  74357. BEGIN_JUCE_NAMESPACE
  74358. struct ImageCacheItem
  74359. {
  74360. ScopedPointer <Image> image;
  74361. int64 hashCode;
  74362. int refCount;
  74363. uint32 releaseTime;
  74364. juce_UseDebuggingNewOperator
  74365. };
  74366. static ImageCache* instance = 0;
  74367. static int cacheTimeout = 5000;
  74368. ImageCache::ImageCache()
  74369. {
  74370. }
  74371. ImageCache::~ImageCache()
  74372. {
  74373. jassert (instance == this);
  74374. instance = 0;
  74375. }
  74376. Image* ImageCache::getFromHashCode (const int64 hashCode)
  74377. {
  74378. if (instance != 0)
  74379. {
  74380. const ScopedLock sl (instance->lock);
  74381. for (int i = instance->images.size(); --i >= 0;)
  74382. {
  74383. ImageCacheItem* const ci = instance->images.getUnchecked(i);
  74384. if (ci->hashCode == hashCode)
  74385. {
  74386. ci->refCount++;
  74387. return ci->image;
  74388. }
  74389. }
  74390. }
  74391. return 0;
  74392. }
  74393. void ImageCache::addImageToCache (Image* const image,
  74394. const int64 hashCode)
  74395. {
  74396. if (image != 0)
  74397. {
  74398. if (instance == 0)
  74399. instance = new ImageCache();
  74400. ImageCacheItem* const newC = new ImageCacheItem();
  74401. newC->hashCode = hashCode;
  74402. newC->image = image;
  74403. newC->refCount = 1;
  74404. newC->releaseTime = 0;
  74405. const ScopedLock sl (instance->lock);
  74406. instance->images.add (newC);
  74407. }
  74408. }
  74409. void ImageCache::release (Image* const imageToRelease)
  74410. {
  74411. if (imageToRelease != 0 && instance != 0)
  74412. {
  74413. const ScopedLock sl (instance->lock);
  74414. for (int i = instance->images.size(); --i >= 0;)
  74415. {
  74416. ImageCacheItem* const ci = instance->images.getUnchecked(i);
  74417. if ((Image*) ci->image == imageToRelease)
  74418. {
  74419. if (--(ci->refCount) == 0)
  74420. ci->releaseTime = Time::getApproximateMillisecondCounter();
  74421. if (! instance->isTimerRunning())
  74422. instance->startTimer (999);
  74423. break;
  74424. }
  74425. }
  74426. }
  74427. }
  74428. void ImageCache::releaseOrDelete (Image* const imageToRelease)
  74429. {
  74430. if (isImageInCache (imageToRelease))
  74431. release (imageToRelease);
  74432. else
  74433. delete imageToRelease;
  74434. }
  74435. bool ImageCache::isImageInCache (Image* const imageToLookFor)
  74436. {
  74437. if (instance != 0)
  74438. {
  74439. const ScopedLock sl (instance->lock);
  74440. for (int i = instance->images.size(); --i >= 0;)
  74441. if ((Image*) instance->images.getUnchecked(i)->image == imageToLookFor)
  74442. return true;
  74443. }
  74444. return false;
  74445. }
  74446. void ImageCache::incReferenceCount (Image* const image)
  74447. {
  74448. if (instance != 0)
  74449. {
  74450. const ScopedLock sl (instance->lock);
  74451. for (int i = instance->images.size(); --i >= 0;)
  74452. {
  74453. ImageCacheItem* const ci = (ImageCacheItem*) instance->images.getUnchecked(i);
  74454. if ((Image*) ci->image == image)
  74455. {
  74456. ci->refCount++;
  74457. return;
  74458. }
  74459. }
  74460. }
  74461. jassertfalse // (trying to inc the ref count of an image that's not in the cache)
  74462. }
  74463. void ImageCache::timerCallback()
  74464. {
  74465. int numberStillNeedingReleasing = 0;
  74466. const unsigned int now = Time::getApproximateMillisecondCounter();
  74467. const ScopedLock sl (lock);
  74468. for (int i = images.size(); --i >= 0;)
  74469. {
  74470. ImageCacheItem* const ci = images.getUnchecked(i);
  74471. if (ci->refCount <= 0)
  74472. {
  74473. if (now > ci->releaseTime + cacheTimeout
  74474. || now < ci->releaseTime - 1000)
  74475. {
  74476. images.remove (i);
  74477. }
  74478. else
  74479. {
  74480. ++numberStillNeedingReleasing;
  74481. }
  74482. }
  74483. }
  74484. if (numberStillNeedingReleasing == 0)
  74485. stopTimer();
  74486. }
  74487. Image* ImageCache::getFromFile (const File& file)
  74488. {
  74489. const int64 hashCode = file.hashCode64();
  74490. Image* image = getFromHashCode (hashCode);
  74491. if (image == 0)
  74492. {
  74493. image = ImageFileFormat::loadFrom (file);
  74494. addImageToCache (image, hashCode);
  74495. }
  74496. return image;
  74497. }
  74498. Image* ImageCache::getFromMemory (const void* imageData,
  74499. const int dataSize)
  74500. {
  74501. const int64 hashCode = (int64) (pointer_sized_int) imageData;
  74502. Image* image = getFromHashCode (hashCode);
  74503. if (image == 0)
  74504. {
  74505. image = ImageFileFormat::loadFrom (imageData, dataSize);
  74506. addImageToCache (image, hashCode);
  74507. }
  74508. return image;
  74509. }
  74510. void ImageCache::setCacheTimeout (const int millisecs)
  74511. {
  74512. cacheTimeout = millisecs;
  74513. }
  74514. END_JUCE_NAMESPACE
  74515. /*** End of inlined file: juce_ImageCache.cpp ***/
  74516. /*** Start of inlined file: juce_ImageConvolutionKernel.cpp ***/
  74517. BEGIN_JUCE_NAMESPACE
  74518. ImageConvolutionKernel::ImageConvolutionKernel (const int size_)
  74519. : values (size_ * size_),
  74520. size (size_)
  74521. {
  74522. clear();
  74523. }
  74524. ImageConvolutionKernel::~ImageConvolutionKernel()
  74525. {
  74526. }
  74527. void ImageConvolutionKernel::setKernelValue (const int x,
  74528. const int y,
  74529. const float value)
  74530. {
  74531. if (((unsigned int) x) < (unsigned int) size
  74532. && ((unsigned int) y) < (unsigned int) size)
  74533. {
  74534. values [x + y * size] = value;
  74535. }
  74536. else
  74537. {
  74538. jassertfalse
  74539. }
  74540. }
  74541. void ImageConvolutionKernel::clear()
  74542. {
  74543. for (int i = size * size; --i >= 0;)
  74544. values[i] = 0;
  74545. }
  74546. void ImageConvolutionKernel::setOverallSum (const float desiredTotalSum)
  74547. {
  74548. double currentTotal = 0.0;
  74549. for (int i = size * size; --i >= 0;)
  74550. currentTotal += values[i];
  74551. rescaleAllValues ((float) (desiredTotalSum / currentTotal));
  74552. }
  74553. void ImageConvolutionKernel::rescaleAllValues (const float multiplier)
  74554. {
  74555. for (int i = size * size; --i >= 0;)
  74556. values[i] *= multiplier;
  74557. }
  74558. void ImageConvolutionKernel::createGaussianBlur (const float radius)
  74559. {
  74560. const double radiusFactor = -1.0 / (radius * radius * 2);
  74561. const int centre = size >> 1;
  74562. for (int y = size; --y >= 0;)
  74563. {
  74564. for (int x = size; --x >= 0;)
  74565. {
  74566. const int cx = x - centre;
  74567. const int cy = y - centre;
  74568. values [x + y * size] = (float) exp (radiusFactor * (cx * cx + cy * cy));
  74569. }
  74570. }
  74571. setOverallSum (1.0f);
  74572. }
  74573. void ImageConvolutionKernel::applyToImage (Image& destImage,
  74574. const Image* sourceImage,
  74575. int dx,
  74576. int dy,
  74577. int dw,
  74578. int dh) const
  74579. {
  74580. ScopedPointer <Image> imageCreated;
  74581. if (sourceImage == 0)
  74582. {
  74583. sourceImage = imageCreated = destImage.createCopy();
  74584. }
  74585. else
  74586. {
  74587. jassert (sourceImage->getWidth() == destImage.getWidth()
  74588. && sourceImage->getHeight() == destImage.getHeight()
  74589. && sourceImage->getFormat() == destImage.getFormat());
  74590. if (sourceImage->getWidth() != destImage.getWidth()
  74591. || sourceImage->getHeight() != destImage.getHeight()
  74592. || sourceImage->getFormat() != destImage.getFormat())
  74593. return;
  74594. }
  74595. const int imageWidth = destImage.getWidth();
  74596. const int imageHeight = destImage.getHeight();
  74597. if (dx >= imageWidth || dy >= imageHeight)
  74598. return;
  74599. if (dx + dw > imageWidth)
  74600. dw = imageWidth - dx;
  74601. if (dy + dh > imageHeight)
  74602. dh = imageHeight - dy;
  74603. const int dx2 = dx + dw;
  74604. const int dy2 = dy + dh;
  74605. const Image::BitmapData destData (destImage, dx, dy, dw, dh, true);
  74606. uint8* line = destData.data;
  74607. const Image::BitmapData srcData (*sourceImage, 0, 0, sourceImage->getWidth(), sourceImage->getHeight());
  74608. if (destData.pixelStride == 4)
  74609. {
  74610. for (int y = dy; y < dy2; ++y)
  74611. {
  74612. uint8* dest = line;
  74613. line += destData.lineStride;
  74614. for (int x = dx; x < dx2; ++x)
  74615. {
  74616. float c1 = 0;
  74617. float c2 = 0;
  74618. float c3 = 0;
  74619. float c4 = 0;
  74620. for (int yy = 0; yy < size; ++yy)
  74621. {
  74622. const int sy = y + yy - (size >> 1);
  74623. if (sy >= imageHeight)
  74624. break;
  74625. if (sy >= 0)
  74626. {
  74627. int sx = x - (size >> 1);
  74628. const uint8* src = srcData.getPixelPointer (sx, sy);
  74629. for (int xx = 0; xx < size; ++xx)
  74630. {
  74631. if (sx >= imageWidth)
  74632. break;
  74633. if (sx >= 0)
  74634. {
  74635. const float kernelMult = values [xx + yy * size];
  74636. c1 += kernelMult * *src++;
  74637. c2 += kernelMult * *src++;
  74638. c3 += kernelMult * *src++;
  74639. c4 += kernelMult * *src++;
  74640. }
  74641. else
  74642. {
  74643. src += 4;
  74644. }
  74645. ++sx;
  74646. }
  74647. }
  74648. }
  74649. *dest++ = (uint8) jmin (0xff, roundToInt (c1));
  74650. *dest++ = (uint8) jmin (0xff, roundToInt (c2));
  74651. *dest++ = (uint8) jmin (0xff, roundToInt (c3));
  74652. *dest++ = (uint8) jmin (0xff, roundToInt (c4));
  74653. }
  74654. }
  74655. }
  74656. else if (destData.pixelStride == 3)
  74657. {
  74658. for (int y = dy; y < dy2; ++y)
  74659. {
  74660. uint8* dest = line;
  74661. line += destData.lineStride;
  74662. for (int x = dx; x < dx2; ++x)
  74663. {
  74664. float c1 = 0;
  74665. float c2 = 0;
  74666. float c3 = 0;
  74667. for (int yy = 0; yy < size; ++yy)
  74668. {
  74669. const int sy = y + yy - (size >> 1);
  74670. if (sy >= imageHeight)
  74671. break;
  74672. if (sy >= 0)
  74673. {
  74674. int sx = x - (size >> 1);
  74675. const uint8* src = srcData.getPixelPointer (sx, sy);
  74676. for (int xx = 0; xx < size; ++xx)
  74677. {
  74678. if (sx >= imageWidth)
  74679. break;
  74680. if (sx >= 0)
  74681. {
  74682. const float kernelMult = values [xx + yy * size];
  74683. c1 += kernelMult * *src++;
  74684. c2 += kernelMult * *src++;
  74685. c3 += kernelMult * *src++;
  74686. }
  74687. else
  74688. {
  74689. src += 3;
  74690. }
  74691. ++sx;
  74692. }
  74693. }
  74694. }
  74695. *dest++ = (uint8) roundToInt (c1);
  74696. *dest++ = (uint8) roundToInt (c2);
  74697. *dest++ = (uint8) roundToInt (c3);
  74698. }
  74699. }
  74700. }
  74701. }
  74702. END_JUCE_NAMESPACE
  74703. /*** End of inlined file: juce_ImageConvolutionKernel.cpp ***/
  74704. /*** Start of inlined file: juce_ImageFileFormat.cpp ***/
  74705. BEGIN_JUCE_NAMESPACE
  74706. /*** Start of inlined file: juce_GIFLoader.h ***/
  74707. #ifndef __JUCE_GIFLOADER_JUCEHEADER__
  74708. #define __JUCE_GIFLOADER_JUCEHEADER__
  74709. #ifndef DOXYGEN
  74710. class GIFLoader
  74711. {
  74712. public:
  74713. GIFLoader (InputStream& in);
  74714. ~GIFLoader();
  74715. Image* getImage() const { return image; }
  74716. private:
  74717. Image* image;
  74718. InputStream& input;
  74719. uint8 buffer [300];
  74720. uint8 palette [256][4];
  74721. bool dataBlockIsZero, fresh, finished;
  74722. int currentBit, lastBit, lastByteIndex;
  74723. int codeSize, setCodeSize;
  74724. int maxCode, maxCodeSize;
  74725. int firstcode, oldcode;
  74726. int clearCode, end_code;
  74727. enum { maxGifCode = 1 << 12 };
  74728. int table [2] [maxGifCode];
  74729. int stack [2 * maxGifCode];
  74730. int *sp;
  74731. bool getSizeFromHeader (int& width, int& height);
  74732. bool readPalette (const int numCols);
  74733. int readDataBlock (unsigned char* dest);
  74734. int processExtension (int type, int& transparent);
  74735. int readLZWByte (bool initialise, int input_code_size);
  74736. int getCode (int code_size, bool initialise);
  74737. bool readImage (int width, int height, int interlace, int transparent);
  74738. static inline int makeWord (const uint8 a, const uint8 b) { return (b << 8) | a; }
  74739. GIFLoader (const GIFLoader&);
  74740. const GIFLoader& operator= (const GIFLoader&);
  74741. };
  74742. #endif // DOXYGEN
  74743. #endif // __JUCE_GIFLOADER_JUCEHEADER__
  74744. /*** End of inlined file: juce_GIFLoader.h ***/
  74745. Image* juce_loadPNGImageFromStream (InputStream& inputStream);
  74746. bool juce_writePNGImageToStream (const Image& image, OutputStream& out);
  74747. PNGImageFormat::PNGImageFormat() {}
  74748. PNGImageFormat::~PNGImageFormat() {}
  74749. const String PNGImageFormat::getFormatName()
  74750. {
  74751. return T("PNG");
  74752. }
  74753. bool PNGImageFormat::canUnderstand (InputStream& in)
  74754. {
  74755. const int bytesNeeded = 4;
  74756. char header [bytesNeeded];
  74757. return in.read (header, bytesNeeded) == bytesNeeded
  74758. && header[1] == 'P'
  74759. && header[2] == 'N'
  74760. && header[3] == 'G';
  74761. }
  74762. Image* PNGImageFormat::decodeImage (InputStream& in)
  74763. {
  74764. return juce_loadPNGImageFromStream (in);
  74765. }
  74766. bool PNGImageFormat::writeImageToStream (const Image& sourceImage,
  74767. OutputStream& destStream)
  74768. {
  74769. return juce_writePNGImageToStream (sourceImage, destStream);
  74770. }
  74771. Image* juce_loadJPEGImageFromStream (InputStream& inputStream);
  74772. bool juce_writeJPEGImageToStream (const Image& image, OutputStream& out, float quality);
  74773. JPEGImageFormat::JPEGImageFormat()
  74774. : quality (-1.0f)
  74775. {
  74776. }
  74777. JPEGImageFormat::~JPEGImageFormat() {}
  74778. void JPEGImageFormat::setQuality (const float newQuality)
  74779. {
  74780. quality = newQuality;
  74781. }
  74782. const String JPEGImageFormat::getFormatName()
  74783. {
  74784. return T("JPEG");
  74785. }
  74786. bool JPEGImageFormat::canUnderstand (InputStream& in)
  74787. {
  74788. const int bytesNeeded = 10;
  74789. uint8 header [bytesNeeded];
  74790. if (in.read (header, bytesNeeded) == bytesNeeded)
  74791. {
  74792. return header[0] == 0xff
  74793. && header[1] == 0xd8
  74794. && header[2] == 0xff
  74795. && (header[3] == 0xe0 || header[3] == 0xe1);
  74796. }
  74797. return false;
  74798. }
  74799. Image* JPEGImageFormat::decodeImage (InputStream& in)
  74800. {
  74801. return juce_loadJPEGImageFromStream (in);
  74802. }
  74803. bool JPEGImageFormat::writeImageToStream (const Image& sourceImage,
  74804. OutputStream& destStream)
  74805. {
  74806. return juce_writeJPEGImageToStream (sourceImage, destStream, quality);
  74807. }
  74808. class GIFImageFormat : public ImageFileFormat
  74809. {
  74810. public:
  74811. GIFImageFormat() {}
  74812. ~GIFImageFormat() {}
  74813. const String getFormatName()
  74814. {
  74815. return T("GIF");
  74816. }
  74817. bool canUnderstand (InputStream& in)
  74818. {
  74819. const int bytesNeeded = 4;
  74820. char header [bytesNeeded];
  74821. return (in.read (header, bytesNeeded) == bytesNeeded)
  74822. && header[0] == 'G'
  74823. && header[1] == 'I'
  74824. && header[2] == 'F';
  74825. }
  74826. Image* decodeImage (InputStream& in)
  74827. {
  74828. const ScopedPointer <GIFLoader> loader (new GIFLoader (in));
  74829. return loader->getImage();
  74830. }
  74831. bool writeImageToStream (const Image& /*sourceImage*/, OutputStream& /*destStream*/)
  74832. {
  74833. return false;
  74834. }
  74835. };
  74836. ImageFileFormat* ImageFileFormat::findImageFormatForStream (InputStream& input)
  74837. {
  74838. static PNGImageFormat png;
  74839. static JPEGImageFormat jpg;
  74840. static GIFImageFormat gif;
  74841. ImageFileFormat* formats[4];
  74842. int numFormats = 0;
  74843. formats [numFormats++] = &png;
  74844. formats [numFormats++] = &jpg;
  74845. formats [numFormats++] = &gif;
  74846. const int64 streamPos = input.getPosition();
  74847. for (int i = 0; i < numFormats; ++i)
  74848. {
  74849. const bool found = formats[i]->canUnderstand (input);
  74850. input.setPosition (streamPos);
  74851. if (found)
  74852. return formats[i];
  74853. }
  74854. return 0;
  74855. }
  74856. Image* ImageFileFormat::loadFrom (InputStream& input)
  74857. {
  74858. ImageFileFormat* const format = findImageFormatForStream (input);
  74859. if (format != 0)
  74860. return format->decodeImage (input);
  74861. return 0;
  74862. }
  74863. Image* ImageFileFormat::loadFrom (const File& file)
  74864. {
  74865. InputStream* const in = file.createInputStream();
  74866. if (in != 0)
  74867. {
  74868. BufferedInputStream b (in, 8192, true);
  74869. return loadFrom (b);
  74870. }
  74871. return 0;
  74872. }
  74873. Image* ImageFileFormat::loadFrom (const void* rawData, const int numBytes)
  74874. {
  74875. if (rawData != 0 && numBytes > 4)
  74876. {
  74877. MemoryInputStream stream (rawData, numBytes, false);
  74878. return loadFrom (stream);
  74879. }
  74880. return 0;
  74881. }
  74882. END_JUCE_NAMESPACE
  74883. /*** End of inlined file: juce_ImageFileFormat.cpp ***/
  74884. /*** Start of inlined file: juce_GIFLoader.cpp ***/
  74885. BEGIN_JUCE_NAMESPACE
  74886. GIFLoader::GIFLoader (InputStream& in)
  74887. : image (0),
  74888. input (in),
  74889. dataBlockIsZero (false),
  74890. fresh (false),
  74891. finished (false)
  74892. {
  74893. currentBit = lastBit = lastByteIndex = 0;
  74894. maxCode = maxCodeSize = codeSize = setCodeSize = 0;
  74895. firstcode = oldcode = 0;
  74896. clearCode = end_code = 0;
  74897. int imageWidth, imageHeight;
  74898. int transparent = -1;
  74899. if (! getSizeFromHeader (imageWidth, imageHeight))
  74900. return;
  74901. if ((imageWidth <= 0) || (imageHeight <= 0))
  74902. return;
  74903. unsigned char buf [16];
  74904. if (in.read (buf, 3) != 3)
  74905. return;
  74906. int numColours = 2 << (buf[0] & 7);
  74907. if ((buf[0] & 0x80) != 0)
  74908. readPalette (numColours);
  74909. for (;;)
  74910. {
  74911. if (input.read (buf, 1) != 1)
  74912. break;
  74913. if (buf[0] == ';')
  74914. break;
  74915. if (buf[0] == '!')
  74916. {
  74917. if (input.read (buf, 1) != 1)
  74918. break;
  74919. if (processExtension (buf[0], transparent) < 0)
  74920. break;
  74921. continue;
  74922. }
  74923. if (buf[0] != ',')
  74924. continue;
  74925. if (input.read (buf, 9) != 9)
  74926. break;
  74927. imageWidth = makeWord (buf[4], buf[5]);
  74928. imageHeight = makeWord (buf[6], buf[7]);
  74929. numColours = 2 << (buf[8] & 7);
  74930. if ((buf[8] & 0x80) != 0)
  74931. if (! readPalette (numColours))
  74932. break;
  74933. image = Image::createNativeImage ((transparent >= 0) ? Image::ARGB : Image::RGB,
  74934. imageWidth, imageHeight, (transparent >= 0));
  74935. readImage (imageWidth, imageHeight,
  74936. (buf[8] & 0x40) != 0,
  74937. transparent);
  74938. break;
  74939. }
  74940. }
  74941. GIFLoader::~GIFLoader()
  74942. {
  74943. }
  74944. bool GIFLoader::getSizeFromHeader (int& w, int& h)
  74945. {
  74946. unsigned char b [8];
  74947. if (input.read (b, 6) == 6)
  74948. {
  74949. if ((strncmp ("GIF87a", (char*) b, 6) == 0)
  74950. || (strncmp ("GIF89a", (char*) b, 6) == 0))
  74951. {
  74952. if (input.read (b, 4) == 4)
  74953. {
  74954. w = makeWord (b[0], b[1]);
  74955. h = makeWord (b[2], b[3]);
  74956. return true;
  74957. }
  74958. }
  74959. }
  74960. return false;
  74961. }
  74962. bool GIFLoader::readPalette (const int numCols)
  74963. {
  74964. unsigned char rgb[4];
  74965. for (int i = 0; i < numCols; ++i)
  74966. {
  74967. input.read (rgb, 3);
  74968. palette [i][0] = rgb[0];
  74969. palette [i][1] = rgb[1];
  74970. palette [i][2] = rgb[2];
  74971. palette [i][3] = 0xff;
  74972. }
  74973. return true;
  74974. }
  74975. int GIFLoader::readDataBlock (unsigned char* const dest)
  74976. {
  74977. unsigned char n;
  74978. if (input.read (&n, 1) == 1)
  74979. {
  74980. dataBlockIsZero = (n == 0);
  74981. if (dataBlockIsZero || (input.read (dest, n) == n))
  74982. return n;
  74983. }
  74984. return -1;
  74985. }
  74986. int GIFLoader::processExtension (const int type, int& transparent)
  74987. {
  74988. unsigned char b [300];
  74989. int n = 0;
  74990. if (type == 0xf9)
  74991. {
  74992. n = readDataBlock (b);
  74993. if (n < 0)
  74994. return 1;
  74995. if ((b[0] & 0x1) != 0)
  74996. transparent = b[3];
  74997. }
  74998. do
  74999. {
  75000. n = readDataBlock (b);
  75001. }
  75002. while (n > 0);
  75003. return n;
  75004. }
  75005. int GIFLoader::getCode (const int codeSize_, const bool initialise)
  75006. {
  75007. if (initialise)
  75008. {
  75009. currentBit = 0;
  75010. lastBit = 0;
  75011. finished = false;
  75012. return 0;
  75013. }
  75014. if ((currentBit + codeSize_) >= lastBit)
  75015. {
  75016. if (finished)
  75017. return -1;
  75018. buffer[0] = buffer [lastByteIndex - 2];
  75019. buffer[1] = buffer [lastByteIndex - 1];
  75020. const int n = readDataBlock (&buffer[2]);
  75021. if (n == 0)
  75022. finished = true;
  75023. lastByteIndex = 2 + n;
  75024. currentBit = (currentBit - lastBit) + 16;
  75025. lastBit = (2 + n) * 8 ;
  75026. }
  75027. int result = 0;
  75028. int i = currentBit;
  75029. for (int j = 0; j < codeSize_; ++j)
  75030. {
  75031. result |= ((buffer[i >> 3] & (1 << (i & 7))) != 0) << j;
  75032. ++i;
  75033. }
  75034. currentBit += codeSize_;
  75035. return result;
  75036. }
  75037. int GIFLoader::readLZWByte (const bool initialise, const int inputCodeSize)
  75038. {
  75039. int code, incode, i;
  75040. if (initialise)
  75041. {
  75042. setCodeSize = inputCodeSize;
  75043. codeSize = setCodeSize + 1;
  75044. clearCode = 1 << setCodeSize;
  75045. end_code = clearCode + 1;
  75046. maxCodeSize = 2 * clearCode;
  75047. maxCode = clearCode + 2;
  75048. getCode (0, true);
  75049. fresh = true;
  75050. for (i = 0; i < clearCode; ++i)
  75051. {
  75052. table[0][i] = 0;
  75053. table[1][i] = i;
  75054. }
  75055. for (; i < maxGifCode; ++i)
  75056. {
  75057. table[0][i] = 0;
  75058. table[1][i] = 0;
  75059. }
  75060. sp = stack;
  75061. return 0;
  75062. }
  75063. else if (fresh)
  75064. {
  75065. fresh = false;
  75066. do
  75067. {
  75068. firstcode = oldcode
  75069. = getCode (codeSize, false);
  75070. }
  75071. while (firstcode == clearCode);
  75072. return firstcode;
  75073. }
  75074. if (sp > stack)
  75075. return *--sp;
  75076. while ((code = getCode (codeSize, false)) >= 0)
  75077. {
  75078. if (code == clearCode)
  75079. {
  75080. for (i = 0; i < clearCode; ++i)
  75081. {
  75082. table[0][i] = 0;
  75083. table[1][i] = i;
  75084. }
  75085. for (; i < maxGifCode; ++i)
  75086. {
  75087. table[0][i] = 0;
  75088. table[1][i] = 0;
  75089. }
  75090. codeSize = setCodeSize + 1;
  75091. maxCodeSize = 2 * clearCode;
  75092. maxCode = clearCode + 2;
  75093. sp = stack;
  75094. firstcode = oldcode = getCode (codeSize, false);
  75095. return firstcode;
  75096. }
  75097. else if (code == end_code)
  75098. {
  75099. if (dataBlockIsZero)
  75100. return -2;
  75101. unsigned char buf [260];
  75102. int n;
  75103. while ((n = readDataBlock (buf)) > 0)
  75104. {}
  75105. if (n != 0)
  75106. return -2;
  75107. }
  75108. incode = code;
  75109. if (code >= maxCode)
  75110. {
  75111. *sp++ = firstcode;
  75112. code = oldcode;
  75113. }
  75114. while (code >= clearCode)
  75115. {
  75116. *sp++ = table[1][code];
  75117. if (code == table[0][code])
  75118. return -2;
  75119. code = table[0][code];
  75120. }
  75121. *sp++ = firstcode = table[1][code];
  75122. if ((code = maxCode) < maxGifCode)
  75123. {
  75124. table[0][code] = oldcode;
  75125. table[1][code] = firstcode;
  75126. ++maxCode;
  75127. if ((maxCode >= maxCodeSize)
  75128. && (maxCodeSize < maxGifCode))
  75129. {
  75130. maxCodeSize <<= 1;
  75131. ++codeSize;
  75132. }
  75133. }
  75134. oldcode = incode;
  75135. if (sp > stack)
  75136. return *--sp;
  75137. }
  75138. return code;
  75139. }
  75140. bool GIFLoader::readImage (const int width, const int height,
  75141. const int interlace, const int transparent)
  75142. {
  75143. unsigned char c;
  75144. if (input.read (&c, 1) != 1
  75145. || readLZWByte (true, c) < 0)
  75146. return false;
  75147. if (transparent >= 0)
  75148. {
  75149. palette [transparent][0] = 0;
  75150. palette [transparent][1] = 0;
  75151. palette [transparent][2] = 0;
  75152. palette [transparent][3] = 0;
  75153. }
  75154. int index;
  75155. int xpos = 0, ypos = 0, pass = 0;
  75156. const Image::BitmapData destData (*image, 0, 0, width, height, true);
  75157. uint8* p = destData.data;
  75158. const bool hasAlpha = image->hasAlphaChannel();
  75159. while ((index = readLZWByte (false, c)) >= 0)
  75160. {
  75161. const uint8* const paletteEntry = palette [index];
  75162. if (hasAlpha)
  75163. {
  75164. ((PixelARGB*) p)->setARGB (paletteEntry[3],
  75165. paletteEntry[0],
  75166. paletteEntry[1],
  75167. paletteEntry[2]);
  75168. ((PixelARGB*) p)->premultiply();
  75169. }
  75170. else
  75171. {
  75172. ((PixelRGB*) p)->setARGB (0,
  75173. paletteEntry[0],
  75174. paletteEntry[1],
  75175. paletteEntry[2]);
  75176. }
  75177. p += destData.pixelStride;
  75178. ++xpos;
  75179. if (xpos == width)
  75180. {
  75181. xpos = 0;
  75182. if (interlace)
  75183. {
  75184. switch (pass)
  75185. {
  75186. case 0:
  75187. case 1:
  75188. ypos += 8;
  75189. break;
  75190. case 2:
  75191. ypos += 4;
  75192. break;
  75193. case 3:
  75194. ypos += 2;
  75195. break;
  75196. }
  75197. while (ypos >= height)
  75198. {
  75199. ++pass;
  75200. switch (pass)
  75201. {
  75202. case 1:
  75203. ypos = 4;
  75204. break;
  75205. case 2:
  75206. ypos = 2;
  75207. break;
  75208. case 3:
  75209. ypos = 1;
  75210. break;
  75211. default:
  75212. return true;
  75213. }
  75214. }
  75215. }
  75216. else
  75217. {
  75218. ++ypos;
  75219. }
  75220. p = destData.getPixelPointer (xpos, ypos);
  75221. }
  75222. if (ypos >= height)
  75223. break;
  75224. }
  75225. return true;
  75226. }
  75227. END_JUCE_NAMESPACE
  75228. /*** End of inlined file: juce_GIFLoader.cpp ***/
  75229. #endif
  75230. //==============================================================================
  75231. // some files include lots of library code, so leave them to the end to avoid cluttering
  75232. // up the build for the clean files.
  75233. #if JUCE_BUILD_CORE
  75234. /*** Start of inlined file: juce_GZIPCompressorOutputStream.cpp ***/
  75235. namespace zlibNamespace
  75236. {
  75237. #if JUCE_INCLUDE_ZLIB_CODE
  75238. #undef OS_CODE
  75239. #undef fdopen
  75240. /*** Start of inlined file: zlib.h ***/
  75241. #ifndef ZLIB_H
  75242. #define ZLIB_H
  75243. /*** Start of inlined file: zconf.h ***/
  75244. #ifndef ZCONF_H
  75245. #define ZCONF_H
  75246. // *** Just a few hacks here to make it compile nicely with Juce..
  75247. #define Z_PREFIX 1
  75248. #undef __MACTYPES__
  75249. #ifdef _MSC_VER
  75250. #pragma warning (disable : 4131 4127 4244 4267)
  75251. #endif
  75252. #ifdef Z_PREFIX
  75253. # define deflateInit_ z_deflateInit_
  75254. # define deflate z_deflate
  75255. # define deflateEnd z_deflateEnd
  75256. # define inflateInit_ z_inflateInit_
  75257. # define inflate z_inflate
  75258. # define inflateEnd z_inflateEnd
  75259. # define deflateInit2_ z_deflateInit2_
  75260. # define deflateSetDictionary z_deflateSetDictionary
  75261. # define deflateCopy z_deflateCopy
  75262. # define deflateReset z_deflateReset
  75263. # define deflateParams z_deflateParams
  75264. # define deflateBound z_deflateBound
  75265. # define deflatePrime z_deflatePrime
  75266. # define inflateInit2_ z_inflateInit2_
  75267. # define inflateSetDictionary z_inflateSetDictionary
  75268. # define inflateSync z_inflateSync
  75269. # define inflateSyncPoint z_inflateSyncPoint
  75270. # define inflateCopy z_inflateCopy
  75271. # define inflateReset z_inflateReset
  75272. # define inflateBack z_inflateBack
  75273. # define inflateBackEnd z_inflateBackEnd
  75274. # define compress z_compress
  75275. # define compress2 z_compress2
  75276. # define compressBound z_compressBound
  75277. # define uncompress z_uncompress
  75278. # define adler32 z_adler32
  75279. # define crc32 z_crc32
  75280. # define get_crc_table z_get_crc_table
  75281. # define zError z_zError
  75282. # define alloc_func z_alloc_func
  75283. # define free_func z_free_func
  75284. # define in_func z_in_func
  75285. # define out_func z_out_func
  75286. # define Byte z_Byte
  75287. # define uInt z_uInt
  75288. # define uLong z_uLong
  75289. # define Bytef z_Bytef
  75290. # define charf z_charf
  75291. # define intf z_intf
  75292. # define uIntf z_uIntf
  75293. # define uLongf z_uLongf
  75294. # define voidpf z_voidpf
  75295. # define voidp z_voidp
  75296. #endif
  75297. #if defined(__MSDOS__) && !defined(MSDOS)
  75298. # define MSDOS
  75299. #endif
  75300. #if (defined(OS_2) || defined(__OS2__)) && !defined(OS2)
  75301. # define OS2
  75302. #endif
  75303. #if defined(_WINDOWS) && !defined(WINDOWS)
  75304. # define WINDOWS
  75305. #endif
  75306. #if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__)
  75307. # ifndef WIN32
  75308. # define WIN32
  75309. # endif
  75310. #endif
  75311. #if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32)
  75312. # if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__)
  75313. # ifndef SYS16BIT
  75314. # define SYS16BIT
  75315. # endif
  75316. # endif
  75317. #endif
  75318. #ifdef SYS16BIT
  75319. # define MAXSEG_64K
  75320. #endif
  75321. #ifdef MSDOS
  75322. # define UNALIGNED_OK
  75323. #endif
  75324. #ifdef __STDC_VERSION__
  75325. # ifndef STDC
  75326. # define STDC
  75327. # endif
  75328. # if __STDC_VERSION__ >= 199901L
  75329. # ifndef STDC99
  75330. # define STDC99
  75331. # endif
  75332. # endif
  75333. #endif
  75334. #if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus))
  75335. # define STDC
  75336. #endif
  75337. #if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__))
  75338. # define STDC
  75339. #endif
  75340. #if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32))
  75341. # define STDC
  75342. #endif
  75343. #if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__))
  75344. # define STDC
  75345. #endif
  75346. #if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */
  75347. # define STDC
  75348. #endif
  75349. #ifndef STDC
  75350. # ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
  75351. # define const /* note: need a more gentle solution here */
  75352. # endif
  75353. #endif
  75354. #if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__)
  75355. # define NO_DUMMY_DECL
  75356. #endif
  75357. #ifndef MAX_MEM_LEVEL
  75358. # ifdef MAXSEG_64K
  75359. # define MAX_MEM_LEVEL 8
  75360. # else
  75361. # define MAX_MEM_LEVEL 9
  75362. # endif
  75363. #endif
  75364. #ifndef MAX_WBITS
  75365. # define MAX_WBITS 15 /* 32K LZ77 window */
  75366. #endif
  75367. #ifndef OF /* function prototypes */
  75368. # ifdef STDC
  75369. # define OF(args) args
  75370. # else
  75371. # define OF(args) ()
  75372. # endif
  75373. #endif
  75374. #ifdef SYS16BIT
  75375. # if defined(M_I86SM) || defined(M_I86MM)
  75376. # define SMALL_MEDIUM
  75377. # ifdef _MSC_VER
  75378. # define FAR _far
  75379. # else
  75380. # define FAR far
  75381. # endif
  75382. # endif
  75383. # if (defined(__SMALL__) || defined(__MEDIUM__))
  75384. # define SMALL_MEDIUM
  75385. # ifdef __BORLANDC__
  75386. # define FAR _far
  75387. # else
  75388. # define FAR far
  75389. # endif
  75390. # endif
  75391. #endif
  75392. #if defined(WINDOWS) || defined(WIN32)
  75393. # ifdef ZLIB_DLL
  75394. # if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500))
  75395. # ifdef ZLIB_INTERNAL
  75396. # define ZEXTERN extern __declspec(dllexport)
  75397. # else
  75398. # define ZEXTERN extern __declspec(dllimport)
  75399. # endif
  75400. # endif
  75401. # endif /* ZLIB_DLL */
  75402. # ifdef ZLIB_WINAPI
  75403. # ifdef FAR
  75404. # undef FAR
  75405. # endif
  75406. # include <windows.h>
  75407. # define ZEXPORT WINAPI
  75408. # ifdef WIN32
  75409. # define ZEXPORTVA WINAPIV
  75410. # else
  75411. # define ZEXPORTVA FAR CDECL
  75412. # endif
  75413. # endif
  75414. #endif
  75415. #if defined (__BEOS__)
  75416. # ifdef ZLIB_DLL
  75417. # ifdef ZLIB_INTERNAL
  75418. # define ZEXPORT __declspec(dllexport)
  75419. # define ZEXPORTVA __declspec(dllexport)
  75420. # else
  75421. # define ZEXPORT __declspec(dllimport)
  75422. # define ZEXPORTVA __declspec(dllimport)
  75423. # endif
  75424. # endif
  75425. #endif
  75426. #ifndef ZEXTERN
  75427. # define ZEXTERN extern
  75428. #endif
  75429. #ifndef ZEXPORT
  75430. # define ZEXPORT
  75431. #endif
  75432. #ifndef ZEXPORTVA
  75433. # define ZEXPORTVA
  75434. #endif
  75435. #ifndef FAR
  75436. # define FAR
  75437. #endif
  75438. #if !defined(__MACTYPES__)
  75439. typedef unsigned char Byte; /* 8 bits */
  75440. #endif
  75441. typedef unsigned int uInt; /* 16 bits or more */
  75442. typedef unsigned long uLong; /* 32 bits or more */
  75443. #ifdef SMALL_MEDIUM
  75444. # define Bytef Byte FAR
  75445. #else
  75446. typedef Byte FAR Bytef;
  75447. #endif
  75448. typedef char FAR charf;
  75449. typedef int FAR intf;
  75450. typedef uInt FAR uIntf;
  75451. typedef uLong FAR uLongf;
  75452. #ifdef STDC
  75453. typedef void const *voidpc;
  75454. typedef void FAR *voidpf;
  75455. typedef void *voidp;
  75456. #else
  75457. typedef Byte const *voidpc;
  75458. typedef Byte FAR *voidpf;
  75459. typedef Byte *voidp;
  75460. #endif
  75461. #if 0 /* HAVE_UNISTD_H -- this line is updated by ./configure */
  75462. # include <sys/types.h> /* for off_t */
  75463. # include <unistd.h> /* for SEEK_* and off_t */
  75464. # ifdef VMS
  75465. # include <unixio.h> /* for off_t */
  75466. # endif
  75467. # define z_off_t off_t
  75468. #endif
  75469. #ifndef SEEK_SET
  75470. # define SEEK_SET 0 /* Seek from beginning of file. */
  75471. # define SEEK_CUR 1 /* Seek from current position. */
  75472. # define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
  75473. #endif
  75474. #ifndef z_off_t
  75475. # define z_off_t long
  75476. #endif
  75477. #if defined(__OS400__)
  75478. # define NO_vsnprintf
  75479. #endif
  75480. #if defined(__MVS__)
  75481. # define NO_vsnprintf
  75482. # ifdef FAR
  75483. # undef FAR
  75484. # endif
  75485. #endif
  75486. #if defined(__MVS__)
  75487. # pragma map(deflateInit_,"DEIN")
  75488. # pragma map(deflateInit2_,"DEIN2")
  75489. # pragma map(deflateEnd,"DEEND")
  75490. # pragma map(deflateBound,"DEBND")
  75491. # pragma map(inflateInit_,"ININ")
  75492. # pragma map(inflateInit2_,"ININ2")
  75493. # pragma map(inflateEnd,"INEND")
  75494. # pragma map(inflateSync,"INSY")
  75495. # pragma map(inflateSetDictionary,"INSEDI")
  75496. # pragma map(compressBound,"CMBND")
  75497. # pragma map(inflate_table,"INTABL")
  75498. # pragma map(inflate_fast,"INFA")
  75499. # pragma map(inflate_copyright,"INCOPY")
  75500. #endif
  75501. #endif /* ZCONF_H */
  75502. /*** End of inlined file: zconf.h ***/
  75503. #ifdef __cplusplus
  75504. extern "C" {
  75505. #endif
  75506. #define ZLIB_VERSION "1.2.3"
  75507. #define ZLIB_VERNUM 0x1230
  75508. typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
  75509. typedef void (*free_func) OF((voidpf opaque, voidpf address));
  75510. struct internal_state;
  75511. typedef struct z_stream_s {
  75512. Bytef *next_in; /* next input byte */
  75513. uInt avail_in; /* number of bytes available at next_in */
  75514. uLong total_in; /* total nb of input bytes read so far */
  75515. Bytef *next_out; /* next output byte should be put there */
  75516. uInt avail_out; /* remaining free space at next_out */
  75517. uLong total_out; /* total nb of bytes output so far */
  75518. char *msg; /* last error message, NULL if no error */
  75519. struct internal_state FAR *state; /* not visible by applications */
  75520. alloc_func zalloc; /* used to allocate the internal state */
  75521. free_func zfree; /* used to free the internal state */
  75522. voidpf opaque; /* private data object passed to zalloc and zfree */
  75523. int data_type; /* best guess about the data type: binary or text */
  75524. uLong adler; /* adler32 value of the uncompressed data */
  75525. uLong reserved; /* reserved for future use */
  75526. } z_stream;
  75527. typedef z_stream FAR *z_streamp;
  75528. typedef struct gz_header_s {
  75529. int text; /* true if compressed data believed to be text */
  75530. uLong time; /* modification time */
  75531. int xflags; /* extra flags (not used when writing a gzip file) */
  75532. int os; /* operating system */
  75533. Bytef *extra; /* pointer to extra field or Z_NULL if none */
  75534. uInt extra_len; /* extra field length (valid if extra != Z_NULL) */
  75535. uInt extra_max; /* space at extra (only when reading header) */
  75536. Bytef *name; /* pointer to zero-terminated file name or Z_NULL */
  75537. uInt name_max; /* space at name (only when reading header) */
  75538. Bytef *comment; /* pointer to zero-terminated comment or Z_NULL */
  75539. uInt comm_max; /* space at comment (only when reading header) */
  75540. int hcrc; /* true if there was or will be a header crc */
  75541. int done; /* true when done reading gzip header (not used
  75542. when writing a gzip file) */
  75543. } gz_header;
  75544. typedef gz_header FAR *gz_headerp;
  75545. #define Z_NO_FLUSH 0
  75546. #define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */
  75547. #define Z_SYNC_FLUSH 2
  75548. #define Z_FULL_FLUSH 3
  75549. #define Z_FINISH 4
  75550. #define Z_BLOCK 5
  75551. #define Z_OK 0
  75552. #define Z_STREAM_END 1
  75553. #define Z_NEED_DICT 2
  75554. #define Z_ERRNO (-1)
  75555. #define Z_STREAM_ERROR (-2)
  75556. #define Z_DATA_ERROR (-3)
  75557. #define Z_MEM_ERROR (-4)
  75558. #define Z_BUF_ERROR (-5)
  75559. #define Z_VERSION_ERROR (-6)
  75560. #define Z_NO_COMPRESSION 0
  75561. #define Z_BEST_SPEED 1
  75562. #define Z_BEST_COMPRESSION 9
  75563. #define Z_DEFAULT_COMPRESSION (-1)
  75564. #define Z_FILTERED 1
  75565. #define Z_HUFFMAN_ONLY 2
  75566. #define Z_RLE 3
  75567. #define Z_FIXED 4
  75568. #define Z_DEFAULT_STRATEGY 0
  75569. #define Z_BINARY 0
  75570. #define Z_TEXT 1
  75571. #define Z_ASCII Z_TEXT /* for compatibility with 1.2.2 and earlier */
  75572. #define Z_UNKNOWN 2
  75573. #define Z_DEFLATED 8
  75574. #define Z_NULL 0 /* for initializing zalloc, zfree, opaque */
  75575. #define zlib_version zlibVersion()
  75576. //ZEXTERN const char * ZEXPORT zlibVersion OF((void));
  75577. ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
  75578. ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm));
  75579. ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
  75580. ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm));
  75581. ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
  75582. const Bytef *dictionary,
  75583. uInt dictLength));
  75584. ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest,
  75585. z_streamp source));
  75586. ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm));
  75587. ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm,
  75588. int level,
  75589. int strategy));
  75590. ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm,
  75591. int good_length,
  75592. int max_lazy,
  75593. int nice_length,
  75594. int max_chain));
  75595. ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm,
  75596. uLong sourceLen));
  75597. ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm,
  75598. int bits,
  75599. int value));
  75600. ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm,
  75601. gz_headerp head));
  75602. ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
  75603. const Bytef *dictionary,
  75604. uInt dictLength));
  75605. ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm));
  75606. ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest,
  75607. z_streamp source));
  75608. ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm));
  75609. ZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm,
  75610. int bits,
  75611. int value));
  75612. ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm,
  75613. gz_headerp head));
  75614. typedef unsigned (*in_func) OF((void FAR *, unsigned char FAR * FAR *));
  75615. typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned));
  75616. ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm,
  75617. in_func in, void FAR *in_desc,
  75618. out_func out, void FAR *out_desc));
  75619. ZEXTERN int ZEXPORT inflateBackEnd OF((z_streamp strm));
  75620. //ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void));
  75621. ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen,
  75622. const Bytef *source, uLong sourceLen));
  75623. ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen,
  75624. const Bytef *source, uLong sourceLen,
  75625. int level));
  75626. ZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen));
  75627. ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen,
  75628. const Bytef *source, uLong sourceLen));
  75629. typedef voidp gzFile;
  75630. ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode));
  75631. ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode));
  75632. ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy));
  75633. ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len));
  75634. ZEXTERN int ZEXPORT gzwrite OF((gzFile file,
  75635. voidpc buf, unsigned len));
  75636. ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...));
  75637. ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s));
  75638. ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len));
  75639. ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c));
  75640. ZEXTERN int ZEXPORT gzgetc OF((gzFile file));
  75641. ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file));
  75642. ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush));
  75643. ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file,
  75644. z_off_t offset, int whence));
  75645. ZEXTERN int ZEXPORT gzrewind OF((gzFile file));
  75646. ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file));
  75647. ZEXTERN int ZEXPORT gzeof OF((gzFile file));
  75648. ZEXTERN int ZEXPORT gzdirect OF((gzFile file));
  75649. ZEXTERN int ZEXPORT gzclose OF((gzFile file));
  75650. ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum));
  75651. ZEXTERN void ZEXPORT gzclearerr OF((gzFile file));
  75652. ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
  75653. ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2,
  75654. z_off_t len2));
  75655. ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len));
  75656. ZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, z_off_t len2));
  75657. ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level,
  75658. const char *version, int stream_size));
  75659. ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm,
  75660. const char *version, int stream_size));
  75661. ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method,
  75662. int windowBits, int memLevel,
  75663. int strategy, const char *version,
  75664. int stream_size));
  75665. ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits,
  75666. const char *version, int stream_size));
  75667. ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits,
  75668. unsigned char FAR *window,
  75669. const char *version,
  75670. int stream_size));
  75671. #define deflateInit(strm, level) \
  75672. deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream))
  75673. #define inflateInit(strm) \
  75674. inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream))
  75675. #define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \
  75676. deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\
  75677. (strategy), ZLIB_VERSION, sizeof(z_stream))
  75678. #define inflateInit2(strm, windowBits) \
  75679. inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream))
  75680. #define inflateBackInit(strm, windowBits, window) \
  75681. inflateBackInit_((strm), (windowBits), (window), \
  75682. ZLIB_VERSION, sizeof(z_stream))
  75683. #if !defined(ZUTIL_H) && !defined(NO_DUMMY_DECL)
  75684. struct internal_state {int dummy;}; /* hack for buggy compilers */
  75685. #endif
  75686. ZEXTERN const char * ZEXPORT zError OF((int));
  75687. ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp z));
  75688. ZEXTERN const uLongf * ZEXPORT get_crc_table OF((void));
  75689. #ifdef __cplusplus
  75690. }
  75691. #endif
  75692. #endif /* ZLIB_H */
  75693. /*** End of inlined file: zlib.h ***/
  75694. #undef OS_CODE
  75695. #else
  75696. #include <zlib.h>
  75697. #endif
  75698. }
  75699. BEGIN_JUCE_NAMESPACE
  75700. using namespace zlibNamespace;
  75701. // internal helper object that holds the zlib structures so they don't have to be
  75702. // included publicly.
  75703. class GZIPCompressorHelper
  75704. {
  75705. public:
  75706. GZIPCompressorHelper (const int compressionLevel, const bool nowrap)
  75707. : data (0),
  75708. dataSize (0),
  75709. compLevel (compressionLevel),
  75710. strategy (0),
  75711. setParams (true),
  75712. streamIsValid (false),
  75713. finished (false),
  75714. shouldFinish (false)
  75715. {
  75716. zerostruct (stream);
  75717. streamIsValid = (deflateInit2 (&stream, compLevel, Z_DEFLATED,
  75718. nowrap ? -MAX_WBITS : MAX_WBITS,
  75719. 8, strategy) == Z_OK);
  75720. }
  75721. ~GZIPCompressorHelper()
  75722. {
  75723. if (streamIsValid)
  75724. deflateEnd (&stream);
  75725. }
  75726. bool needsInput() const throw()
  75727. {
  75728. return dataSize <= 0;
  75729. }
  75730. void setInput (uint8* const newData, const int size) throw()
  75731. {
  75732. data = newData;
  75733. dataSize = size;
  75734. }
  75735. int doNextBlock (uint8* const dest, const int destSize) throw()
  75736. {
  75737. if (streamIsValid)
  75738. {
  75739. stream.next_in = data;
  75740. stream.next_out = dest;
  75741. stream.avail_in = dataSize;
  75742. stream.avail_out = destSize;
  75743. const int result = setParams ? deflateParams (&stream, compLevel, strategy)
  75744. : deflate (&stream, shouldFinish ? Z_FINISH : Z_NO_FLUSH);
  75745. setParams = false;
  75746. switch (result)
  75747. {
  75748. case Z_STREAM_END:
  75749. finished = true;
  75750. // Deliberate fall-through..
  75751. case Z_OK:
  75752. data += dataSize - stream.avail_in;
  75753. dataSize = stream.avail_in;
  75754. return destSize - stream.avail_out;
  75755. default:
  75756. break;
  75757. }
  75758. }
  75759. return 0;
  75760. }
  75761. private:
  75762. z_stream stream;
  75763. uint8* data;
  75764. int dataSize, compLevel, strategy;
  75765. bool setParams, streamIsValid;
  75766. public:
  75767. bool finished, shouldFinish;
  75768. };
  75769. const int gzipCompBufferSize = 32768;
  75770. GZIPCompressorOutputStream::GZIPCompressorOutputStream (OutputStream* const destStream_,
  75771. int compressionLevel,
  75772. const bool deleteDestStream,
  75773. const bool noWrap)
  75774. : destStream (destStream_),
  75775. streamToDelete (deleteDestStream ? destStream_ : 0),
  75776. buffer (gzipCompBufferSize)
  75777. {
  75778. if (compressionLevel < 1 || compressionLevel > 9)
  75779. compressionLevel = -1;
  75780. helper = new GZIPCompressorHelper (compressionLevel, noWrap);
  75781. }
  75782. GZIPCompressorOutputStream::~GZIPCompressorOutputStream()
  75783. {
  75784. flush();
  75785. }
  75786. void GZIPCompressorOutputStream::flush()
  75787. {
  75788. if (! helper->finished)
  75789. {
  75790. helper->shouldFinish = true;
  75791. while (! helper->finished)
  75792. doNextBlock();
  75793. }
  75794. destStream->flush();
  75795. }
  75796. bool GZIPCompressorOutputStream::write (const void* destBuffer, int howMany)
  75797. {
  75798. if (! helper->finished)
  75799. {
  75800. helper->setInput ((uint8*) destBuffer, howMany);
  75801. while (! helper->needsInput())
  75802. {
  75803. if (! doNextBlock())
  75804. return false;
  75805. }
  75806. }
  75807. return true;
  75808. }
  75809. bool GZIPCompressorOutputStream::doNextBlock()
  75810. {
  75811. const int len = helper->doNextBlock (buffer, gzipCompBufferSize);
  75812. if (len > 0)
  75813. return destStream->write (buffer, len);
  75814. else
  75815. return true;
  75816. }
  75817. int64 GZIPCompressorOutputStream::getPosition()
  75818. {
  75819. return destStream->getPosition();
  75820. }
  75821. bool GZIPCompressorOutputStream::setPosition (int64 /*newPosition*/)
  75822. {
  75823. jassertfalse // can't do it!
  75824. return false;
  75825. }
  75826. END_JUCE_NAMESPACE
  75827. /*** End of inlined file: juce_GZIPCompressorOutputStream.cpp ***/
  75828. /*** Start of inlined file: juce_GZIPDecompressorInputStream.cpp ***/
  75829. #if JUCE_MSVC
  75830. #pragma warning (push)
  75831. #pragma warning (disable: 4309 4305)
  75832. #endif
  75833. namespace zlibNamespace
  75834. {
  75835. #if JUCE_INCLUDE_ZLIB_CODE
  75836. extern "C"
  75837. {
  75838. #undef OS_CODE
  75839. #undef fdopen
  75840. #define ZLIB_INTERNAL
  75841. #define NO_DUMMY_DECL
  75842. /*** Start of inlined file: adler32.c ***/
  75843. #define ZLIB_INTERNAL
  75844. #define BASE 65521UL /* largest prime smaller than 65536 */
  75845. #define NMAX 5552
  75846. #define DO1(buf,i) {adler += (buf)[i]; sum2 += adler;}
  75847. #define DO2(buf,i) DO1(buf,i); DO1(buf,i+1);
  75848. #define DO4(buf,i) DO2(buf,i); DO2(buf,i+2);
  75849. #define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);
  75850. #define DO16(buf) DO8(buf,0); DO8(buf,8);
  75851. #ifdef NO_DIVIDE
  75852. # define MOD(a) \
  75853. do { \
  75854. if (a >= (BASE << 16)) a -= (BASE << 16); \
  75855. if (a >= (BASE << 15)) a -= (BASE << 15); \
  75856. if (a >= (BASE << 14)) a -= (BASE << 14); \
  75857. if (a >= (BASE << 13)) a -= (BASE << 13); \
  75858. if (a >= (BASE << 12)) a -= (BASE << 12); \
  75859. if (a >= (BASE << 11)) a -= (BASE << 11); \
  75860. if (a >= (BASE << 10)) a -= (BASE << 10); \
  75861. if (a >= (BASE << 9)) a -= (BASE << 9); \
  75862. if (a >= (BASE << 8)) a -= (BASE << 8); \
  75863. if (a >= (BASE << 7)) a -= (BASE << 7); \
  75864. if (a >= (BASE << 6)) a -= (BASE << 6); \
  75865. if (a >= (BASE << 5)) a -= (BASE << 5); \
  75866. if (a >= (BASE << 4)) a -= (BASE << 4); \
  75867. if (a >= (BASE << 3)) a -= (BASE << 3); \
  75868. if (a >= (BASE << 2)) a -= (BASE << 2); \
  75869. if (a >= (BASE << 1)) a -= (BASE << 1); \
  75870. if (a >= BASE) a -= BASE; \
  75871. } while (0)
  75872. # define MOD4(a) \
  75873. do { \
  75874. if (a >= (BASE << 4)) a -= (BASE << 4); \
  75875. if (a >= (BASE << 3)) a -= (BASE << 3); \
  75876. if (a >= (BASE << 2)) a -= (BASE << 2); \
  75877. if (a >= (BASE << 1)) a -= (BASE << 1); \
  75878. if (a >= BASE) a -= BASE; \
  75879. } while (0)
  75880. #else
  75881. # define MOD(a) a %= BASE
  75882. # define MOD4(a) a %= BASE
  75883. #endif
  75884. uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len)
  75885. {
  75886. unsigned long sum2;
  75887. unsigned n;
  75888. sum2 = (adler >> 16) & 0xffff;
  75889. adler &= 0xffff;
  75890. if (len == 1) {
  75891. adler += buf[0];
  75892. if (adler >= BASE)
  75893. adler -= BASE;
  75894. sum2 += adler;
  75895. if (sum2 >= BASE)
  75896. sum2 -= BASE;
  75897. return adler | (sum2 << 16);
  75898. }
  75899. if (buf == Z_NULL)
  75900. return 1L;
  75901. if (len < 16) {
  75902. while (len--) {
  75903. adler += *buf++;
  75904. sum2 += adler;
  75905. }
  75906. if (adler >= BASE)
  75907. adler -= BASE;
  75908. MOD4(sum2); /* only added so many BASE's */
  75909. return adler | (sum2 << 16);
  75910. }
  75911. while (len >= NMAX) {
  75912. len -= NMAX;
  75913. n = NMAX / 16; /* NMAX is divisible by 16 */
  75914. do {
  75915. DO16(buf); /* 16 sums unrolled */
  75916. buf += 16;
  75917. } while (--n);
  75918. MOD(adler);
  75919. MOD(sum2);
  75920. }
  75921. if (len) { /* avoid modulos if none remaining */
  75922. while (len >= 16) {
  75923. len -= 16;
  75924. DO16(buf);
  75925. buf += 16;
  75926. }
  75927. while (len--) {
  75928. adler += *buf++;
  75929. sum2 += adler;
  75930. }
  75931. MOD(adler);
  75932. MOD(sum2);
  75933. }
  75934. return adler | (sum2 << 16);
  75935. }
  75936. uLong ZEXPORT adler32_combine(uLong adler1, uLong adler2, z_off_t len2)
  75937. {
  75938. unsigned long sum1;
  75939. unsigned long sum2;
  75940. unsigned rem;
  75941. rem = (unsigned)(len2 % BASE);
  75942. sum1 = adler1 & 0xffff;
  75943. sum2 = rem * sum1;
  75944. MOD(sum2);
  75945. sum1 += (adler2 & 0xffff) + BASE - 1;
  75946. sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem;
  75947. if (sum1 > BASE) sum1 -= BASE;
  75948. if (sum1 > BASE) sum1 -= BASE;
  75949. if (sum2 > (BASE << 1)) sum2 -= (BASE << 1);
  75950. if (sum2 > BASE) sum2 -= BASE;
  75951. return sum1 | (sum2 << 16);
  75952. }
  75953. /*** End of inlined file: adler32.c ***/
  75954. /*** Start of inlined file: compress.c ***/
  75955. #define ZLIB_INTERNAL
  75956. int ZEXPORT compress2 (Bytef *dest, uLongf *destLen, const Bytef *source,
  75957. uLong sourceLen, int level)
  75958. {
  75959. z_stream stream;
  75960. int err;
  75961. stream.next_in = (Bytef*)source;
  75962. stream.avail_in = (uInt)sourceLen;
  75963. #ifdef MAXSEG_64K
  75964. if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
  75965. #endif
  75966. stream.next_out = dest;
  75967. stream.avail_out = (uInt)*destLen;
  75968. if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
  75969. stream.zalloc = (alloc_func)0;
  75970. stream.zfree = (free_func)0;
  75971. stream.opaque = (voidpf)0;
  75972. err = deflateInit(&stream, level);
  75973. if (err != Z_OK) return err;
  75974. err = deflate(&stream, Z_FINISH);
  75975. if (err != Z_STREAM_END) {
  75976. deflateEnd(&stream);
  75977. return err == Z_OK ? Z_BUF_ERROR : err;
  75978. }
  75979. *destLen = stream.total_out;
  75980. err = deflateEnd(&stream);
  75981. return err;
  75982. }
  75983. int ZEXPORT compress (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen)
  75984. {
  75985. return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION);
  75986. }
  75987. uLong ZEXPORT compressBound (uLong sourceLen)
  75988. {
  75989. return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + 11;
  75990. }
  75991. /*** End of inlined file: compress.c ***/
  75992. #undef DO1
  75993. #undef DO8
  75994. /*** Start of inlined file: crc32.c ***/
  75995. #ifdef MAKECRCH
  75996. # include <stdio.h>
  75997. # ifndef DYNAMIC_CRC_TABLE
  75998. # define DYNAMIC_CRC_TABLE
  75999. # endif /* !DYNAMIC_CRC_TABLE */
  76000. #endif /* MAKECRCH */
  76001. /*** Start of inlined file: zutil.h ***/
  76002. #ifndef ZUTIL_H
  76003. #define ZUTIL_H
  76004. #define ZLIB_INTERNAL
  76005. #ifdef STDC
  76006. # ifndef _WIN32_WCE
  76007. # include <stddef.h>
  76008. # endif
  76009. # include <string.h>
  76010. # include <stdlib.h>
  76011. #endif
  76012. #ifdef NO_ERRNO_H
  76013. # ifdef _WIN32_WCE
  76014. # define errno z_errno
  76015. # endif
  76016. extern int errno;
  76017. #else
  76018. # ifndef _WIN32_WCE
  76019. # include <errno.h>
  76020. # endif
  76021. #endif
  76022. #ifndef local
  76023. # define local static
  76024. #endif
  76025. typedef unsigned char uch;
  76026. typedef uch FAR uchf;
  76027. typedef unsigned short ush;
  76028. typedef ush FAR ushf;
  76029. typedef unsigned long ulg;
  76030. extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
  76031. #define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)]
  76032. #define ERR_RETURN(strm,err) \
  76033. return (strm->msg = (char*)ERR_MSG(err), (err))
  76034. #ifndef DEF_WBITS
  76035. # define DEF_WBITS MAX_WBITS
  76036. #endif
  76037. #if MAX_MEM_LEVEL >= 8
  76038. # define DEF_MEM_LEVEL 8
  76039. #else
  76040. # define DEF_MEM_LEVEL MAX_MEM_LEVEL
  76041. #endif
  76042. #define STORED_BLOCK 0
  76043. #define STATIC_TREES 1
  76044. #define DYN_TREES 2
  76045. #define MIN_MATCH 3
  76046. #define MAX_MATCH 258
  76047. #define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */
  76048. #if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32))
  76049. # define OS_CODE 0x00
  76050. # if defined(__TURBOC__) || defined(__BORLANDC__)
  76051. # if(__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))
  76052. void _Cdecl farfree( void *block );
  76053. void *_Cdecl farmalloc( unsigned long nbytes );
  76054. # else
  76055. # include <alloc.h>
  76056. # endif
  76057. # else /* MSC or DJGPP */
  76058. # include <malloc.h>
  76059. # endif
  76060. #endif
  76061. #ifdef AMIGA
  76062. # define OS_CODE 0x01
  76063. #endif
  76064. #if defined(VAXC) || defined(VMS)
  76065. # define OS_CODE 0x02
  76066. # define F_OPEN(name, mode) \
  76067. fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")
  76068. #endif
  76069. #if defined(ATARI) || defined(atarist)
  76070. # define OS_CODE 0x05
  76071. #endif
  76072. #ifdef OS2
  76073. # define OS_CODE 0x06
  76074. # ifdef M_I86
  76075. #include <malloc.h>
  76076. # endif
  76077. #endif
  76078. #if defined(MACOS) || TARGET_OS_MAC
  76079. # define OS_CODE 0x07
  76080. # if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
  76081. # include <unix.h> /* for fdopen */
  76082. # else
  76083. # ifndef fdopen
  76084. # define fdopen(fd,mode) NULL /* No fdopen() */
  76085. # endif
  76086. # endif
  76087. #endif
  76088. #ifdef TOPS20
  76089. # define OS_CODE 0x0a
  76090. #endif
  76091. #ifdef WIN32
  76092. # ifndef __CYGWIN__ /* Cygwin is Unix, not Win32 */
  76093. # define OS_CODE 0x0b
  76094. # endif
  76095. #endif
  76096. #ifdef __50SERIES /* Prime/PRIMOS */
  76097. # define OS_CODE 0x0f
  76098. #endif
  76099. #if defined(_BEOS_) || defined(RISCOS)
  76100. # define fdopen(fd,mode) NULL /* No fdopen() */
  76101. #endif
  76102. #if (defined(_MSC_VER) && (_MSC_VER > 600))
  76103. # if defined(_WIN32_WCE)
  76104. # define fdopen(fd,mode) NULL /* No fdopen() */
  76105. # ifndef _PTRDIFF_T_DEFINED
  76106. typedef int ptrdiff_t;
  76107. # define _PTRDIFF_T_DEFINED
  76108. # endif
  76109. # else
  76110. # define fdopen(fd,type) _fdopen(fd,type)
  76111. # endif
  76112. #endif
  76113. #ifndef OS_CODE
  76114. # define OS_CODE 0x03 /* assume Unix */
  76115. #endif
  76116. #ifndef F_OPEN
  76117. # define F_OPEN(name, mode) fopen((name), (mode))
  76118. #endif
  76119. #if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550)
  76120. # ifndef HAVE_VSNPRINTF
  76121. # define HAVE_VSNPRINTF
  76122. # endif
  76123. #endif
  76124. #if defined(__CYGWIN__)
  76125. # ifndef HAVE_VSNPRINTF
  76126. # define HAVE_VSNPRINTF
  76127. # endif
  76128. #endif
  76129. #ifndef HAVE_VSNPRINTF
  76130. # ifdef MSDOS
  76131. # define NO_vsnprintf
  76132. # endif
  76133. # ifdef __TURBOC__
  76134. # define NO_vsnprintf
  76135. # endif
  76136. # ifdef WIN32
  76137. # if !defined(vsnprintf) && !defined(NO_vsnprintf)
  76138. # define vsnprintf _vsnprintf
  76139. # endif
  76140. # endif
  76141. # ifdef __SASC
  76142. # define NO_vsnprintf
  76143. # endif
  76144. #endif
  76145. #ifdef VMS
  76146. # define NO_vsnprintf
  76147. #endif
  76148. #if defined(pyr)
  76149. # define NO_MEMCPY
  76150. #endif
  76151. #if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__)
  76152. # define NO_MEMCPY
  76153. #endif
  76154. #if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY)
  76155. # define HAVE_MEMCPY
  76156. #endif
  76157. #ifdef HAVE_MEMCPY
  76158. # ifdef SMALL_MEDIUM /* MSDOS small or medium model */
  76159. # define zmemcpy _fmemcpy
  76160. # define zmemcmp _fmemcmp
  76161. # define zmemzero(dest, len) _fmemset(dest, 0, len)
  76162. # else
  76163. # define zmemcpy memcpy
  76164. # define zmemcmp memcmp
  76165. # define zmemzero(dest, len) memset(dest, 0, len)
  76166. # endif
  76167. #else
  76168. extern void zmemcpy OF((Bytef* dest, const Bytef* source, uInt len));
  76169. extern int zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len));
  76170. extern void zmemzero OF((Bytef* dest, uInt len));
  76171. #endif
  76172. #ifdef DEBUG
  76173. # include <stdio.h>
  76174. extern int z_verbose;
  76175. extern void z_error OF((const char *m));
  76176. # define Assert(cond,msg) {if(!(cond)) z_error(msg);}
  76177. # define Trace(x) {if (z_verbose>=0) fprintf x ;}
  76178. # define Tracev(x) {if (z_verbose>0) fprintf x ;}
  76179. # define Tracevv(x) {if (z_verbose>1) fprintf x ;}
  76180. # define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;}
  76181. # define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;}
  76182. #else
  76183. # define Assert(cond,msg)
  76184. # define Trace(x)
  76185. # define Tracev(x)
  76186. # define Tracevv(x)
  76187. # define Tracec(c,x)
  76188. # define Tracecv(c,x)
  76189. #endif
  76190. voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size));
  76191. void zcfree OF((voidpf opaque, voidpf ptr));
  76192. #define ZALLOC(strm, items, size) \
  76193. (*((strm)->zalloc))((strm)->opaque, (items), (size))
  76194. #define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
  76195. #define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
  76196. #endif /* ZUTIL_H */
  76197. /*** End of inlined file: zutil.h ***/
  76198. /* for STDC and FAR definitions */
  76199. #define local static
  76200. #ifndef NOBYFOUR
  76201. # ifdef STDC /* need ANSI C limits.h to determine sizes */
  76202. # include <limits.h>
  76203. # define BYFOUR
  76204. # if (UINT_MAX == 0xffffffffUL)
  76205. typedef unsigned int u4;
  76206. # else
  76207. # if (ULONG_MAX == 0xffffffffUL)
  76208. typedef unsigned long u4;
  76209. # else
  76210. # if (USHRT_MAX == 0xffffffffUL)
  76211. typedef unsigned short u4;
  76212. # else
  76213. # undef BYFOUR /* can't find a four-byte integer type! */
  76214. # endif
  76215. # endif
  76216. # endif
  76217. # endif /* STDC */
  76218. #endif /* !NOBYFOUR */
  76219. #ifdef BYFOUR
  76220. # define REV(w) (((w)>>24)+(((w)>>8)&0xff00)+ \
  76221. (((w)&0xff00)<<8)+(((w)&0xff)<<24))
  76222. local unsigned long crc32_little OF((unsigned long,
  76223. const unsigned char FAR *, unsigned));
  76224. local unsigned long crc32_big OF((unsigned long,
  76225. const unsigned char FAR *, unsigned));
  76226. # define TBLS 8
  76227. #else
  76228. # define TBLS 1
  76229. #endif /* BYFOUR */
  76230. local unsigned long gf2_matrix_times OF((unsigned long *mat,
  76231. unsigned long vec));
  76232. local void gf2_matrix_square OF((unsigned long *square, unsigned long *mat));
  76233. #ifdef DYNAMIC_CRC_TABLE
  76234. local volatile int crc_table_empty = 1;
  76235. local unsigned long FAR crc_table[TBLS][256];
  76236. local void make_crc_table OF((void));
  76237. #ifdef MAKECRCH
  76238. local void write_table OF((FILE *, const unsigned long FAR *));
  76239. #endif /* MAKECRCH */
  76240. local void make_crc_table()
  76241. {
  76242. unsigned long c;
  76243. int n, k;
  76244. unsigned long poly; /* polynomial exclusive-or pattern */
  76245. static volatile int first = 1; /* flag to limit concurrent making */
  76246. static const unsigned char p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
  76247. if (first) {
  76248. first = 0;
  76249. poly = 0UL;
  76250. for (n = 0; n < sizeof(p)/sizeof(unsigned char); n++)
  76251. poly |= 1UL << (31 - p[n]);
  76252. for (n = 0; n < 256; n++) {
  76253. c = (unsigned long)n;
  76254. for (k = 0; k < 8; k++)
  76255. c = c & 1 ? poly ^ (c >> 1) : c >> 1;
  76256. crc_table[0][n] = c;
  76257. }
  76258. #ifdef BYFOUR
  76259. for (n = 0; n < 256; n++) {
  76260. c = crc_table[0][n];
  76261. crc_table[4][n] = REV(c);
  76262. for (k = 1; k < 4; k++) {
  76263. c = crc_table[0][c & 0xff] ^ (c >> 8);
  76264. crc_table[k][n] = c;
  76265. crc_table[k + 4][n] = REV(c);
  76266. }
  76267. }
  76268. #endif /* BYFOUR */
  76269. crc_table_empty = 0;
  76270. }
  76271. else { /* not first */
  76272. while (crc_table_empty)
  76273. ;
  76274. }
  76275. #ifdef MAKECRCH
  76276. {
  76277. FILE *out;
  76278. out = fopen("crc32.h", "w");
  76279. if (out == NULL) return;
  76280. fprintf(out, "/* crc32.h -- tables for rapid CRC calculation\n");
  76281. fprintf(out, " * Generated automatically by crc32.c\n */\n\n");
  76282. fprintf(out, "local const unsigned long FAR ");
  76283. fprintf(out, "crc_table[TBLS][256] =\n{\n {\n");
  76284. write_table(out, crc_table[0]);
  76285. # ifdef BYFOUR
  76286. fprintf(out, "#ifdef BYFOUR\n");
  76287. for (k = 1; k < 8; k++) {
  76288. fprintf(out, " },\n {\n");
  76289. write_table(out, crc_table[k]);
  76290. }
  76291. fprintf(out, "#endif\n");
  76292. # endif /* BYFOUR */
  76293. fprintf(out, " }\n};\n");
  76294. fclose(out);
  76295. }
  76296. #endif /* MAKECRCH */
  76297. }
  76298. #ifdef MAKECRCH
  76299. local void write_table(out, table)
  76300. FILE *out;
  76301. const unsigned long FAR *table;
  76302. {
  76303. int n;
  76304. for (n = 0; n < 256; n++)
  76305. fprintf(out, "%s0x%08lxUL%s", n % 5 ? "" : " ", table[n],
  76306. n == 255 ? "\n" : (n % 5 == 4 ? ",\n" : ", "));
  76307. }
  76308. #endif /* MAKECRCH */
  76309. #else /* !DYNAMIC_CRC_TABLE */
  76310. /*** Start of inlined file: crc32.h ***/
  76311. local const unsigned long FAR crc_table[TBLS][256] =
  76312. {
  76313. {
  76314. 0x00000000UL, 0x77073096UL, 0xee0e612cUL, 0x990951baUL, 0x076dc419UL,
  76315. 0x706af48fUL, 0xe963a535UL, 0x9e6495a3UL, 0x0edb8832UL, 0x79dcb8a4UL,
  76316. 0xe0d5e91eUL, 0x97d2d988UL, 0x09b64c2bUL, 0x7eb17cbdUL, 0xe7b82d07UL,
  76317. 0x90bf1d91UL, 0x1db71064UL, 0x6ab020f2UL, 0xf3b97148UL, 0x84be41deUL,
  76318. 0x1adad47dUL, 0x6ddde4ebUL, 0xf4d4b551UL, 0x83d385c7UL, 0x136c9856UL,
  76319. 0x646ba8c0UL, 0xfd62f97aUL, 0x8a65c9ecUL, 0x14015c4fUL, 0x63066cd9UL,
  76320. 0xfa0f3d63UL, 0x8d080df5UL, 0x3b6e20c8UL, 0x4c69105eUL, 0xd56041e4UL,
  76321. 0xa2677172UL, 0x3c03e4d1UL, 0x4b04d447UL, 0xd20d85fdUL, 0xa50ab56bUL,
  76322. 0x35b5a8faUL, 0x42b2986cUL, 0xdbbbc9d6UL, 0xacbcf940UL, 0x32d86ce3UL,
  76323. 0x45df5c75UL, 0xdcd60dcfUL, 0xabd13d59UL, 0x26d930acUL, 0x51de003aUL,
  76324. 0xc8d75180UL, 0xbfd06116UL, 0x21b4f4b5UL, 0x56b3c423UL, 0xcfba9599UL,
  76325. 0xb8bda50fUL, 0x2802b89eUL, 0x5f058808UL, 0xc60cd9b2UL, 0xb10be924UL,
  76326. 0x2f6f7c87UL, 0x58684c11UL, 0xc1611dabUL, 0xb6662d3dUL, 0x76dc4190UL,
  76327. 0x01db7106UL, 0x98d220bcUL, 0xefd5102aUL, 0x71b18589UL, 0x06b6b51fUL,
  76328. 0x9fbfe4a5UL, 0xe8b8d433UL, 0x7807c9a2UL, 0x0f00f934UL, 0x9609a88eUL,
  76329. 0xe10e9818UL, 0x7f6a0dbbUL, 0x086d3d2dUL, 0x91646c97UL, 0xe6635c01UL,
  76330. 0x6b6b51f4UL, 0x1c6c6162UL, 0x856530d8UL, 0xf262004eUL, 0x6c0695edUL,
  76331. 0x1b01a57bUL, 0x8208f4c1UL, 0xf50fc457UL, 0x65b0d9c6UL, 0x12b7e950UL,
  76332. 0x8bbeb8eaUL, 0xfcb9887cUL, 0x62dd1ddfUL, 0x15da2d49UL, 0x8cd37cf3UL,
  76333. 0xfbd44c65UL, 0x4db26158UL, 0x3ab551ceUL, 0xa3bc0074UL, 0xd4bb30e2UL,
  76334. 0x4adfa541UL, 0x3dd895d7UL, 0xa4d1c46dUL, 0xd3d6f4fbUL, 0x4369e96aUL,
  76335. 0x346ed9fcUL, 0xad678846UL, 0xda60b8d0UL, 0x44042d73UL, 0x33031de5UL,
  76336. 0xaa0a4c5fUL, 0xdd0d7cc9UL, 0x5005713cUL, 0x270241aaUL, 0xbe0b1010UL,
  76337. 0xc90c2086UL, 0x5768b525UL, 0x206f85b3UL, 0xb966d409UL, 0xce61e49fUL,
  76338. 0x5edef90eUL, 0x29d9c998UL, 0xb0d09822UL, 0xc7d7a8b4UL, 0x59b33d17UL,
  76339. 0x2eb40d81UL, 0xb7bd5c3bUL, 0xc0ba6cadUL, 0xedb88320UL, 0x9abfb3b6UL,
  76340. 0x03b6e20cUL, 0x74b1d29aUL, 0xead54739UL, 0x9dd277afUL, 0x04db2615UL,
  76341. 0x73dc1683UL, 0xe3630b12UL, 0x94643b84UL, 0x0d6d6a3eUL, 0x7a6a5aa8UL,
  76342. 0xe40ecf0bUL, 0x9309ff9dUL, 0x0a00ae27UL, 0x7d079eb1UL, 0xf00f9344UL,
  76343. 0x8708a3d2UL, 0x1e01f268UL, 0x6906c2feUL, 0xf762575dUL, 0x806567cbUL,
  76344. 0x196c3671UL, 0x6e6b06e7UL, 0xfed41b76UL, 0x89d32be0UL, 0x10da7a5aUL,
  76345. 0x67dd4accUL, 0xf9b9df6fUL, 0x8ebeeff9UL, 0x17b7be43UL, 0x60b08ed5UL,
  76346. 0xd6d6a3e8UL, 0xa1d1937eUL, 0x38d8c2c4UL, 0x4fdff252UL, 0xd1bb67f1UL,
  76347. 0xa6bc5767UL, 0x3fb506ddUL, 0x48b2364bUL, 0xd80d2bdaUL, 0xaf0a1b4cUL,
  76348. 0x36034af6UL, 0x41047a60UL, 0xdf60efc3UL, 0xa867df55UL, 0x316e8eefUL,
  76349. 0x4669be79UL, 0xcb61b38cUL, 0xbc66831aUL, 0x256fd2a0UL, 0x5268e236UL,
  76350. 0xcc0c7795UL, 0xbb0b4703UL, 0x220216b9UL, 0x5505262fUL, 0xc5ba3bbeUL,
  76351. 0xb2bd0b28UL, 0x2bb45a92UL, 0x5cb36a04UL, 0xc2d7ffa7UL, 0xb5d0cf31UL,
  76352. 0x2cd99e8bUL, 0x5bdeae1dUL, 0x9b64c2b0UL, 0xec63f226UL, 0x756aa39cUL,
  76353. 0x026d930aUL, 0x9c0906a9UL, 0xeb0e363fUL, 0x72076785UL, 0x05005713UL,
  76354. 0x95bf4a82UL, 0xe2b87a14UL, 0x7bb12baeUL, 0x0cb61b38UL, 0x92d28e9bUL,
  76355. 0xe5d5be0dUL, 0x7cdcefb7UL, 0x0bdbdf21UL, 0x86d3d2d4UL, 0xf1d4e242UL,
  76356. 0x68ddb3f8UL, 0x1fda836eUL, 0x81be16cdUL, 0xf6b9265bUL, 0x6fb077e1UL,
  76357. 0x18b74777UL, 0x88085ae6UL, 0xff0f6a70UL, 0x66063bcaUL, 0x11010b5cUL,
  76358. 0x8f659effUL, 0xf862ae69UL, 0x616bffd3UL, 0x166ccf45UL, 0xa00ae278UL,
  76359. 0xd70dd2eeUL, 0x4e048354UL, 0x3903b3c2UL, 0xa7672661UL, 0xd06016f7UL,
  76360. 0x4969474dUL, 0x3e6e77dbUL, 0xaed16a4aUL, 0xd9d65adcUL, 0x40df0b66UL,
  76361. 0x37d83bf0UL, 0xa9bcae53UL, 0xdebb9ec5UL, 0x47b2cf7fUL, 0x30b5ffe9UL,
  76362. 0xbdbdf21cUL, 0xcabac28aUL, 0x53b39330UL, 0x24b4a3a6UL, 0xbad03605UL,
  76363. 0xcdd70693UL, 0x54de5729UL, 0x23d967bfUL, 0xb3667a2eUL, 0xc4614ab8UL,
  76364. 0x5d681b02UL, 0x2a6f2b94UL, 0xb40bbe37UL, 0xc30c8ea1UL, 0x5a05df1bUL,
  76365. 0x2d02ef8dUL
  76366. #ifdef BYFOUR
  76367. },
  76368. {
  76369. 0x00000000UL, 0x191b3141UL, 0x32366282UL, 0x2b2d53c3UL, 0x646cc504UL,
  76370. 0x7d77f445UL, 0x565aa786UL, 0x4f4196c7UL, 0xc8d98a08UL, 0xd1c2bb49UL,
  76371. 0xfaefe88aUL, 0xe3f4d9cbUL, 0xacb54f0cUL, 0xb5ae7e4dUL, 0x9e832d8eUL,
  76372. 0x87981ccfUL, 0x4ac21251UL, 0x53d92310UL, 0x78f470d3UL, 0x61ef4192UL,
  76373. 0x2eaed755UL, 0x37b5e614UL, 0x1c98b5d7UL, 0x05838496UL, 0x821b9859UL,
  76374. 0x9b00a918UL, 0xb02dfadbUL, 0xa936cb9aUL, 0xe6775d5dUL, 0xff6c6c1cUL,
  76375. 0xd4413fdfUL, 0xcd5a0e9eUL, 0x958424a2UL, 0x8c9f15e3UL, 0xa7b24620UL,
  76376. 0xbea97761UL, 0xf1e8e1a6UL, 0xe8f3d0e7UL, 0xc3de8324UL, 0xdac5b265UL,
  76377. 0x5d5daeaaUL, 0x44469febUL, 0x6f6bcc28UL, 0x7670fd69UL, 0x39316baeUL,
  76378. 0x202a5aefUL, 0x0b07092cUL, 0x121c386dUL, 0xdf4636f3UL, 0xc65d07b2UL,
  76379. 0xed705471UL, 0xf46b6530UL, 0xbb2af3f7UL, 0xa231c2b6UL, 0x891c9175UL,
  76380. 0x9007a034UL, 0x179fbcfbUL, 0x0e848dbaUL, 0x25a9de79UL, 0x3cb2ef38UL,
  76381. 0x73f379ffUL, 0x6ae848beUL, 0x41c51b7dUL, 0x58de2a3cUL, 0xf0794f05UL,
  76382. 0xe9627e44UL, 0xc24f2d87UL, 0xdb541cc6UL, 0x94158a01UL, 0x8d0ebb40UL,
  76383. 0xa623e883UL, 0xbf38d9c2UL, 0x38a0c50dUL, 0x21bbf44cUL, 0x0a96a78fUL,
  76384. 0x138d96ceUL, 0x5ccc0009UL, 0x45d73148UL, 0x6efa628bUL, 0x77e153caUL,
  76385. 0xbabb5d54UL, 0xa3a06c15UL, 0x888d3fd6UL, 0x91960e97UL, 0xded79850UL,
  76386. 0xc7cca911UL, 0xece1fad2UL, 0xf5facb93UL, 0x7262d75cUL, 0x6b79e61dUL,
  76387. 0x4054b5deUL, 0x594f849fUL, 0x160e1258UL, 0x0f152319UL, 0x243870daUL,
  76388. 0x3d23419bUL, 0x65fd6ba7UL, 0x7ce65ae6UL, 0x57cb0925UL, 0x4ed03864UL,
  76389. 0x0191aea3UL, 0x188a9fe2UL, 0x33a7cc21UL, 0x2abcfd60UL, 0xad24e1afUL,
  76390. 0xb43fd0eeUL, 0x9f12832dUL, 0x8609b26cUL, 0xc94824abUL, 0xd05315eaUL,
  76391. 0xfb7e4629UL, 0xe2657768UL, 0x2f3f79f6UL, 0x362448b7UL, 0x1d091b74UL,
  76392. 0x04122a35UL, 0x4b53bcf2UL, 0x52488db3UL, 0x7965de70UL, 0x607eef31UL,
  76393. 0xe7e6f3feUL, 0xfefdc2bfUL, 0xd5d0917cUL, 0xcccba03dUL, 0x838a36faUL,
  76394. 0x9a9107bbUL, 0xb1bc5478UL, 0xa8a76539UL, 0x3b83984bUL, 0x2298a90aUL,
  76395. 0x09b5fac9UL, 0x10aecb88UL, 0x5fef5d4fUL, 0x46f46c0eUL, 0x6dd93fcdUL,
  76396. 0x74c20e8cUL, 0xf35a1243UL, 0xea412302UL, 0xc16c70c1UL, 0xd8774180UL,
  76397. 0x9736d747UL, 0x8e2de606UL, 0xa500b5c5UL, 0xbc1b8484UL, 0x71418a1aUL,
  76398. 0x685abb5bUL, 0x4377e898UL, 0x5a6cd9d9UL, 0x152d4f1eUL, 0x0c367e5fUL,
  76399. 0x271b2d9cUL, 0x3e001cddUL, 0xb9980012UL, 0xa0833153UL, 0x8bae6290UL,
  76400. 0x92b553d1UL, 0xddf4c516UL, 0xc4eff457UL, 0xefc2a794UL, 0xf6d996d5UL,
  76401. 0xae07bce9UL, 0xb71c8da8UL, 0x9c31de6bUL, 0x852aef2aUL, 0xca6b79edUL,
  76402. 0xd37048acUL, 0xf85d1b6fUL, 0xe1462a2eUL, 0x66de36e1UL, 0x7fc507a0UL,
  76403. 0x54e85463UL, 0x4df36522UL, 0x02b2f3e5UL, 0x1ba9c2a4UL, 0x30849167UL,
  76404. 0x299fa026UL, 0xe4c5aeb8UL, 0xfdde9ff9UL, 0xd6f3cc3aUL, 0xcfe8fd7bUL,
  76405. 0x80a96bbcUL, 0x99b25afdUL, 0xb29f093eUL, 0xab84387fUL, 0x2c1c24b0UL,
  76406. 0x350715f1UL, 0x1e2a4632UL, 0x07317773UL, 0x4870e1b4UL, 0x516bd0f5UL,
  76407. 0x7a468336UL, 0x635db277UL, 0xcbfad74eUL, 0xd2e1e60fUL, 0xf9ccb5ccUL,
  76408. 0xe0d7848dUL, 0xaf96124aUL, 0xb68d230bUL, 0x9da070c8UL, 0x84bb4189UL,
  76409. 0x03235d46UL, 0x1a386c07UL, 0x31153fc4UL, 0x280e0e85UL, 0x674f9842UL,
  76410. 0x7e54a903UL, 0x5579fac0UL, 0x4c62cb81UL, 0x8138c51fUL, 0x9823f45eUL,
  76411. 0xb30ea79dUL, 0xaa1596dcUL, 0xe554001bUL, 0xfc4f315aUL, 0xd7626299UL,
  76412. 0xce7953d8UL, 0x49e14f17UL, 0x50fa7e56UL, 0x7bd72d95UL, 0x62cc1cd4UL,
  76413. 0x2d8d8a13UL, 0x3496bb52UL, 0x1fbbe891UL, 0x06a0d9d0UL, 0x5e7ef3ecUL,
  76414. 0x4765c2adUL, 0x6c48916eUL, 0x7553a02fUL, 0x3a1236e8UL, 0x230907a9UL,
  76415. 0x0824546aUL, 0x113f652bUL, 0x96a779e4UL, 0x8fbc48a5UL, 0xa4911b66UL,
  76416. 0xbd8a2a27UL, 0xf2cbbce0UL, 0xebd08da1UL, 0xc0fdde62UL, 0xd9e6ef23UL,
  76417. 0x14bce1bdUL, 0x0da7d0fcUL, 0x268a833fUL, 0x3f91b27eUL, 0x70d024b9UL,
  76418. 0x69cb15f8UL, 0x42e6463bUL, 0x5bfd777aUL, 0xdc656bb5UL, 0xc57e5af4UL,
  76419. 0xee530937UL, 0xf7483876UL, 0xb809aeb1UL, 0xa1129ff0UL, 0x8a3fcc33UL,
  76420. 0x9324fd72UL
  76421. },
  76422. {
  76423. 0x00000000UL, 0x01c26a37UL, 0x0384d46eUL, 0x0246be59UL, 0x0709a8dcUL,
  76424. 0x06cbc2ebUL, 0x048d7cb2UL, 0x054f1685UL, 0x0e1351b8UL, 0x0fd13b8fUL,
  76425. 0x0d9785d6UL, 0x0c55efe1UL, 0x091af964UL, 0x08d89353UL, 0x0a9e2d0aUL,
  76426. 0x0b5c473dUL, 0x1c26a370UL, 0x1de4c947UL, 0x1fa2771eUL, 0x1e601d29UL,
  76427. 0x1b2f0bacUL, 0x1aed619bUL, 0x18abdfc2UL, 0x1969b5f5UL, 0x1235f2c8UL,
  76428. 0x13f798ffUL, 0x11b126a6UL, 0x10734c91UL, 0x153c5a14UL, 0x14fe3023UL,
  76429. 0x16b88e7aUL, 0x177ae44dUL, 0x384d46e0UL, 0x398f2cd7UL, 0x3bc9928eUL,
  76430. 0x3a0bf8b9UL, 0x3f44ee3cUL, 0x3e86840bUL, 0x3cc03a52UL, 0x3d025065UL,
  76431. 0x365e1758UL, 0x379c7d6fUL, 0x35dac336UL, 0x3418a901UL, 0x3157bf84UL,
  76432. 0x3095d5b3UL, 0x32d36beaUL, 0x331101ddUL, 0x246be590UL, 0x25a98fa7UL,
  76433. 0x27ef31feUL, 0x262d5bc9UL, 0x23624d4cUL, 0x22a0277bUL, 0x20e69922UL,
  76434. 0x2124f315UL, 0x2a78b428UL, 0x2bbade1fUL, 0x29fc6046UL, 0x283e0a71UL,
  76435. 0x2d711cf4UL, 0x2cb376c3UL, 0x2ef5c89aUL, 0x2f37a2adUL, 0x709a8dc0UL,
  76436. 0x7158e7f7UL, 0x731e59aeUL, 0x72dc3399UL, 0x7793251cUL, 0x76514f2bUL,
  76437. 0x7417f172UL, 0x75d59b45UL, 0x7e89dc78UL, 0x7f4bb64fUL, 0x7d0d0816UL,
  76438. 0x7ccf6221UL, 0x798074a4UL, 0x78421e93UL, 0x7a04a0caUL, 0x7bc6cafdUL,
  76439. 0x6cbc2eb0UL, 0x6d7e4487UL, 0x6f38fadeUL, 0x6efa90e9UL, 0x6bb5866cUL,
  76440. 0x6a77ec5bUL, 0x68315202UL, 0x69f33835UL, 0x62af7f08UL, 0x636d153fUL,
  76441. 0x612bab66UL, 0x60e9c151UL, 0x65a6d7d4UL, 0x6464bde3UL, 0x662203baUL,
  76442. 0x67e0698dUL, 0x48d7cb20UL, 0x4915a117UL, 0x4b531f4eUL, 0x4a917579UL,
  76443. 0x4fde63fcUL, 0x4e1c09cbUL, 0x4c5ab792UL, 0x4d98dda5UL, 0x46c49a98UL,
  76444. 0x4706f0afUL, 0x45404ef6UL, 0x448224c1UL, 0x41cd3244UL, 0x400f5873UL,
  76445. 0x4249e62aUL, 0x438b8c1dUL, 0x54f16850UL, 0x55330267UL, 0x5775bc3eUL,
  76446. 0x56b7d609UL, 0x53f8c08cUL, 0x523aaabbUL, 0x507c14e2UL, 0x51be7ed5UL,
  76447. 0x5ae239e8UL, 0x5b2053dfUL, 0x5966ed86UL, 0x58a487b1UL, 0x5deb9134UL,
  76448. 0x5c29fb03UL, 0x5e6f455aUL, 0x5fad2f6dUL, 0xe1351b80UL, 0xe0f771b7UL,
  76449. 0xe2b1cfeeUL, 0xe373a5d9UL, 0xe63cb35cUL, 0xe7fed96bUL, 0xe5b86732UL,
  76450. 0xe47a0d05UL, 0xef264a38UL, 0xeee4200fUL, 0xeca29e56UL, 0xed60f461UL,
  76451. 0xe82fe2e4UL, 0xe9ed88d3UL, 0xebab368aUL, 0xea695cbdUL, 0xfd13b8f0UL,
  76452. 0xfcd1d2c7UL, 0xfe976c9eUL, 0xff5506a9UL, 0xfa1a102cUL, 0xfbd87a1bUL,
  76453. 0xf99ec442UL, 0xf85cae75UL, 0xf300e948UL, 0xf2c2837fUL, 0xf0843d26UL,
  76454. 0xf1465711UL, 0xf4094194UL, 0xf5cb2ba3UL, 0xf78d95faUL, 0xf64fffcdUL,
  76455. 0xd9785d60UL, 0xd8ba3757UL, 0xdafc890eUL, 0xdb3ee339UL, 0xde71f5bcUL,
  76456. 0xdfb39f8bUL, 0xddf521d2UL, 0xdc374be5UL, 0xd76b0cd8UL, 0xd6a966efUL,
  76457. 0xd4efd8b6UL, 0xd52db281UL, 0xd062a404UL, 0xd1a0ce33UL, 0xd3e6706aUL,
  76458. 0xd2241a5dUL, 0xc55efe10UL, 0xc49c9427UL, 0xc6da2a7eUL, 0xc7184049UL,
  76459. 0xc25756ccUL, 0xc3953cfbUL, 0xc1d382a2UL, 0xc011e895UL, 0xcb4dafa8UL,
  76460. 0xca8fc59fUL, 0xc8c97bc6UL, 0xc90b11f1UL, 0xcc440774UL, 0xcd866d43UL,
  76461. 0xcfc0d31aUL, 0xce02b92dUL, 0x91af9640UL, 0x906dfc77UL, 0x922b422eUL,
  76462. 0x93e92819UL, 0x96a63e9cUL, 0x976454abUL, 0x9522eaf2UL, 0x94e080c5UL,
  76463. 0x9fbcc7f8UL, 0x9e7eadcfUL, 0x9c381396UL, 0x9dfa79a1UL, 0x98b56f24UL,
  76464. 0x99770513UL, 0x9b31bb4aUL, 0x9af3d17dUL, 0x8d893530UL, 0x8c4b5f07UL,
  76465. 0x8e0de15eUL, 0x8fcf8b69UL, 0x8a809decUL, 0x8b42f7dbUL, 0x89044982UL,
  76466. 0x88c623b5UL, 0x839a6488UL, 0x82580ebfUL, 0x801eb0e6UL, 0x81dcdad1UL,
  76467. 0x8493cc54UL, 0x8551a663UL, 0x8717183aUL, 0x86d5720dUL, 0xa9e2d0a0UL,
  76468. 0xa820ba97UL, 0xaa6604ceUL, 0xaba46ef9UL, 0xaeeb787cUL, 0xaf29124bUL,
  76469. 0xad6fac12UL, 0xacadc625UL, 0xa7f18118UL, 0xa633eb2fUL, 0xa4755576UL,
  76470. 0xa5b73f41UL, 0xa0f829c4UL, 0xa13a43f3UL, 0xa37cfdaaUL, 0xa2be979dUL,
  76471. 0xb5c473d0UL, 0xb40619e7UL, 0xb640a7beUL, 0xb782cd89UL, 0xb2cddb0cUL,
  76472. 0xb30fb13bUL, 0xb1490f62UL, 0xb08b6555UL, 0xbbd72268UL, 0xba15485fUL,
  76473. 0xb853f606UL, 0xb9919c31UL, 0xbcde8ab4UL, 0xbd1ce083UL, 0xbf5a5edaUL,
  76474. 0xbe9834edUL
  76475. },
  76476. {
  76477. 0x00000000UL, 0xb8bc6765UL, 0xaa09c88bUL, 0x12b5afeeUL, 0x8f629757UL,
  76478. 0x37def032UL, 0x256b5fdcUL, 0x9dd738b9UL, 0xc5b428efUL, 0x7d084f8aUL,
  76479. 0x6fbde064UL, 0xd7018701UL, 0x4ad6bfb8UL, 0xf26ad8ddUL, 0xe0df7733UL,
  76480. 0x58631056UL, 0x5019579fUL, 0xe8a530faUL, 0xfa109f14UL, 0x42acf871UL,
  76481. 0xdf7bc0c8UL, 0x67c7a7adUL, 0x75720843UL, 0xcdce6f26UL, 0x95ad7f70UL,
  76482. 0x2d111815UL, 0x3fa4b7fbUL, 0x8718d09eUL, 0x1acfe827UL, 0xa2738f42UL,
  76483. 0xb0c620acUL, 0x087a47c9UL, 0xa032af3eUL, 0x188ec85bUL, 0x0a3b67b5UL,
  76484. 0xb28700d0UL, 0x2f503869UL, 0x97ec5f0cUL, 0x8559f0e2UL, 0x3de59787UL,
  76485. 0x658687d1UL, 0xdd3ae0b4UL, 0xcf8f4f5aUL, 0x7733283fUL, 0xeae41086UL,
  76486. 0x525877e3UL, 0x40edd80dUL, 0xf851bf68UL, 0xf02bf8a1UL, 0x48979fc4UL,
  76487. 0x5a22302aUL, 0xe29e574fUL, 0x7f496ff6UL, 0xc7f50893UL, 0xd540a77dUL,
  76488. 0x6dfcc018UL, 0x359fd04eUL, 0x8d23b72bUL, 0x9f9618c5UL, 0x272a7fa0UL,
  76489. 0xbafd4719UL, 0x0241207cUL, 0x10f48f92UL, 0xa848e8f7UL, 0x9b14583dUL,
  76490. 0x23a83f58UL, 0x311d90b6UL, 0x89a1f7d3UL, 0x1476cf6aUL, 0xaccaa80fUL,
  76491. 0xbe7f07e1UL, 0x06c36084UL, 0x5ea070d2UL, 0xe61c17b7UL, 0xf4a9b859UL,
  76492. 0x4c15df3cUL, 0xd1c2e785UL, 0x697e80e0UL, 0x7bcb2f0eUL, 0xc377486bUL,
  76493. 0xcb0d0fa2UL, 0x73b168c7UL, 0x6104c729UL, 0xd9b8a04cUL, 0x446f98f5UL,
  76494. 0xfcd3ff90UL, 0xee66507eUL, 0x56da371bUL, 0x0eb9274dUL, 0xb6054028UL,
  76495. 0xa4b0efc6UL, 0x1c0c88a3UL, 0x81dbb01aUL, 0x3967d77fUL, 0x2bd27891UL,
  76496. 0x936e1ff4UL, 0x3b26f703UL, 0x839a9066UL, 0x912f3f88UL, 0x299358edUL,
  76497. 0xb4446054UL, 0x0cf80731UL, 0x1e4da8dfUL, 0xa6f1cfbaUL, 0xfe92dfecUL,
  76498. 0x462eb889UL, 0x549b1767UL, 0xec277002UL, 0x71f048bbUL, 0xc94c2fdeUL,
  76499. 0xdbf98030UL, 0x6345e755UL, 0x6b3fa09cUL, 0xd383c7f9UL, 0xc1366817UL,
  76500. 0x798a0f72UL, 0xe45d37cbUL, 0x5ce150aeUL, 0x4e54ff40UL, 0xf6e89825UL,
  76501. 0xae8b8873UL, 0x1637ef16UL, 0x048240f8UL, 0xbc3e279dUL, 0x21e91f24UL,
  76502. 0x99557841UL, 0x8be0d7afUL, 0x335cb0caUL, 0xed59b63bUL, 0x55e5d15eUL,
  76503. 0x47507eb0UL, 0xffec19d5UL, 0x623b216cUL, 0xda874609UL, 0xc832e9e7UL,
  76504. 0x708e8e82UL, 0x28ed9ed4UL, 0x9051f9b1UL, 0x82e4565fUL, 0x3a58313aUL,
  76505. 0xa78f0983UL, 0x1f336ee6UL, 0x0d86c108UL, 0xb53aa66dUL, 0xbd40e1a4UL,
  76506. 0x05fc86c1UL, 0x1749292fUL, 0xaff54e4aUL, 0x322276f3UL, 0x8a9e1196UL,
  76507. 0x982bbe78UL, 0x2097d91dUL, 0x78f4c94bUL, 0xc048ae2eUL, 0xd2fd01c0UL,
  76508. 0x6a4166a5UL, 0xf7965e1cUL, 0x4f2a3979UL, 0x5d9f9697UL, 0xe523f1f2UL,
  76509. 0x4d6b1905UL, 0xf5d77e60UL, 0xe762d18eUL, 0x5fdeb6ebUL, 0xc2098e52UL,
  76510. 0x7ab5e937UL, 0x680046d9UL, 0xd0bc21bcUL, 0x88df31eaUL, 0x3063568fUL,
  76511. 0x22d6f961UL, 0x9a6a9e04UL, 0x07bda6bdUL, 0xbf01c1d8UL, 0xadb46e36UL,
  76512. 0x15080953UL, 0x1d724e9aUL, 0xa5ce29ffUL, 0xb77b8611UL, 0x0fc7e174UL,
  76513. 0x9210d9cdUL, 0x2aacbea8UL, 0x38191146UL, 0x80a57623UL, 0xd8c66675UL,
  76514. 0x607a0110UL, 0x72cfaefeUL, 0xca73c99bUL, 0x57a4f122UL, 0xef189647UL,
  76515. 0xfdad39a9UL, 0x45115eccUL, 0x764dee06UL, 0xcef18963UL, 0xdc44268dUL,
  76516. 0x64f841e8UL, 0xf92f7951UL, 0x41931e34UL, 0x5326b1daUL, 0xeb9ad6bfUL,
  76517. 0xb3f9c6e9UL, 0x0b45a18cUL, 0x19f00e62UL, 0xa14c6907UL, 0x3c9b51beUL,
  76518. 0x842736dbUL, 0x96929935UL, 0x2e2efe50UL, 0x2654b999UL, 0x9ee8defcUL,
  76519. 0x8c5d7112UL, 0x34e11677UL, 0xa9362eceUL, 0x118a49abUL, 0x033fe645UL,
  76520. 0xbb838120UL, 0xe3e09176UL, 0x5b5cf613UL, 0x49e959fdUL, 0xf1553e98UL,
  76521. 0x6c820621UL, 0xd43e6144UL, 0xc68bceaaUL, 0x7e37a9cfUL, 0xd67f4138UL,
  76522. 0x6ec3265dUL, 0x7c7689b3UL, 0xc4caeed6UL, 0x591dd66fUL, 0xe1a1b10aUL,
  76523. 0xf3141ee4UL, 0x4ba87981UL, 0x13cb69d7UL, 0xab770eb2UL, 0xb9c2a15cUL,
  76524. 0x017ec639UL, 0x9ca9fe80UL, 0x241599e5UL, 0x36a0360bUL, 0x8e1c516eUL,
  76525. 0x866616a7UL, 0x3eda71c2UL, 0x2c6fde2cUL, 0x94d3b949UL, 0x090481f0UL,
  76526. 0xb1b8e695UL, 0xa30d497bUL, 0x1bb12e1eUL, 0x43d23e48UL, 0xfb6e592dUL,
  76527. 0xe9dbf6c3UL, 0x516791a6UL, 0xccb0a91fUL, 0x740cce7aUL, 0x66b96194UL,
  76528. 0xde0506f1UL
  76529. },
  76530. {
  76531. 0x00000000UL, 0x96300777UL, 0x2c610eeeUL, 0xba510999UL, 0x19c46d07UL,
  76532. 0x8ff46a70UL, 0x35a563e9UL, 0xa395649eUL, 0x3288db0eUL, 0xa4b8dc79UL,
  76533. 0x1ee9d5e0UL, 0x88d9d297UL, 0x2b4cb609UL, 0xbd7cb17eUL, 0x072db8e7UL,
  76534. 0x911dbf90UL, 0x6410b71dUL, 0xf220b06aUL, 0x4871b9f3UL, 0xde41be84UL,
  76535. 0x7dd4da1aUL, 0xebe4dd6dUL, 0x51b5d4f4UL, 0xc785d383UL, 0x56986c13UL,
  76536. 0xc0a86b64UL, 0x7af962fdUL, 0xecc9658aUL, 0x4f5c0114UL, 0xd96c0663UL,
  76537. 0x633d0ffaUL, 0xf50d088dUL, 0xc8206e3bUL, 0x5e10694cUL, 0xe44160d5UL,
  76538. 0x727167a2UL, 0xd1e4033cUL, 0x47d4044bUL, 0xfd850dd2UL, 0x6bb50aa5UL,
  76539. 0xfaa8b535UL, 0x6c98b242UL, 0xd6c9bbdbUL, 0x40f9bcacUL, 0xe36cd832UL,
  76540. 0x755cdf45UL, 0xcf0dd6dcUL, 0x593dd1abUL, 0xac30d926UL, 0x3a00de51UL,
  76541. 0x8051d7c8UL, 0x1661d0bfUL, 0xb5f4b421UL, 0x23c4b356UL, 0x9995bacfUL,
  76542. 0x0fa5bdb8UL, 0x9eb80228UL, 0x0888055fUL, 0xb2d90cc6UL, 0x24e90bb1UL,
  76543. 0x877c6f2fUL, 0x114c6858UL, 0xab1d61c1UL, 0x3d2d66b6UL, 0x9041dc76UL,
  76544. 0x0671db01UL, 0xbc20d298UL, 0x2a10d5efUL, 0x8985b171UL, 0x1fb5b606UL,
  76545. 0xa5e4bf9fUL, 0x33d4b8e8UL, 0xa2c90778UL, 0x34f9000fUL, 0x8ea80996UL,
  76546. 0x18980ee1UL, 0xbb0d6a7fUL, 0x2d3d6d08UL, 0x976c6491UL, 0x015c63e6UL,
  76547. 0xf4516b6bUL, 0x62616c1cUL, 0xd8306585UL, 0x4e0062f2UL, 0xed95066cUL,
  76548. 0x7ba5011bUL, 0xc1f40882UL, 0x57c40ff5UL, 0xc6d9b065UL, 0x50e9b712UL,
  76549. 0xeab8be8bUL, 0x7c88b9fcUL, 0xdf1ddd62UL, 0x492dda15UL, 0xf37cd38cUL,
  76550. 0x654cd4fbUL, 0x5861b24dUL, 0xce51b53aUL, 0x7400bca3UL, 0xe230bbd4UL,
  76551. 0x41a5df4aUL, 0xd795d83dUL, 0x6dc4d1a4UL, 0xfbf4d6d3UL, 0x6ae96943UL,
  76552. 0xfcd96e34UL, 0x468867adUL, 0xd0b860daUL, 0x732d0444UL, 0xe51d0333UL,
  76553. 0x5f4c0aaaUL, 0xc97c0dddUL, 0x3c710550UL, 0xaa410227UL, 0x10100bbeUL,
  76554. 0x86200cc9UL, 0x25b56857UL, 0xb3856f20UL, 0x09d466b9UL, 0x9fe461ceUL,
  76555. 0x0ef9de5eUL, 0x98c9d929UL, 0x2298d0b0UL, 0xb4a8d7c7UL, 0x173db359UL,
  76556. 0x810db42eUL, 0x3b5cbdb7UL, 0xad6cbac0UL, 0x2083b8edUL, 0xb6b3bf9aUL,
  76557. 0x0ce2b603UL, 0x9ad2b174UL, 0x3947d5eaUL, 0xaf77d29dUL, 0x1526db04UL,
  76558. 0x8316dc73UL, 0x120b63e3UL, 0x843b6494UL, 0x3e6a6d0dUL, 0xa85a6a7aUL,
  76559. 0x0bcf0ee4UL, 0x9dff0993UL, 0x27ae000aUL, 0xb19e077dUL, 0x44930ff0UL,
  76560. 0xd2a30887UL, 0x68f2011eUL, 0xfec20669UL, 0x5d5762f7UL, 0xcb676580UL,
  76561. 0x71366c19UL, 0xe7066b6eUL, 0x761bd4feUL, 0xe02bd389UL, 0x5a7ada10UL,
  76562. 0xcc4add67UL, 0x6fdfb9f9UL, 0xf9efbe8eUL, 0x43beb717UL, 0xd58eb060UL,
  76563. 0xe8a3d6d6UL, 0x7e93d1a1UL, 0xc4c2d838UL, 0x52f2df4fUL, 0xf167bbd1UL,
  76564. 0x6757bca6UL, 0xdd06b53fUL, 0x4b36b248UL, 0xda2b0dd8UL, 0x4c1b0aafUL,
  76565. 0xf64a0336UL, 0x607a0441UL, 0xc3ef60dfUL, 0x55df67a8UL, 0xef8e6e31UL,
  76566. 0x79be6946UL, 0x8cb361cbUL, 0x1a8366bcUL, 0xa0d26f25UL, 0x36e26852UL,
  76567. 0x95770cccUL, 0x03470bbbUL, 0xb9160222UL, 0x2f260555UL, 0xbe3bbac5UL,
  76568. 0x280bbdb2UL, 0x925ab42bUL, 0x046ab35cUL, 0xa7ffd7c2UL, 0x31cfd0b5UL,
  76569. 0x8b9ed92cUL, 0x1daede5bUL, 0xb0c2649bUL, 0x26f263ecUL, 0x9ca36a75UL,
  76570. 0x0a936d02UL, 0xa906099cUL, 0x3f360eebUL, 0x85670772UL, 0x13570005UL,
  76571. 0x824abf95UL, 0x147ab8e2UL, 0xae2bb17bUL, 0x381bb60cUL, 0x9b8ed292UL,
  76572. 0x0dbed5e5UL, 0xb7efdc7cUL, 0x21dfdb0bUL, 0xd4d2d386UL, 0x42e2d4f1UL,
  76573. 0xf8b3dd68UL, 0x6e83da1fUL, 0xcd16be81UL, 0x5b26b9f6UL, 0xe177b06fUL,
  76574. 0x7747b718UL, 0xe65a0888UL, 0x706a0fffUL, 0xca3b0666UL, 0x5c0b0111UL,
  76575. 0xff9e658fUL, 0x69ae62f8UL, 0xd3ff6b61UL, 0x45cf6c16UL, 0x78e20aa0UL,
  76576. 0xeed20dd7UL, 0x5483044eUL, 0xc2b30339UL, 0x612667a7UL, 0xf71660d0UL,
  76577. 0x4d476949UL, 0xdb776e3eUL, 0x4a6ad1aeUL, 0xdc5ad6d9UL, 0x660bdf40UL,
  76578. 0xf03bd837UL, 0x53aebca9UL, 0xc59ebbdeUL, 0x7fcfb247UL, 0xe9ffb530UL,
  76579. 0x1cf2bdbdUL, 0x8ac2bacaUL, 0x3093b353UL, 0xa6a3b424UL, 0x0536d0baUL,
  76580. 0x9306d7cdUL, 0x2957de54UL, 0xbf67d923UL, 0x2e7a66b3UL, 0xb84a61c4UL,
  76581. 0x021b685dUL, 0x942b6f2aUL, 0x37be0bb4UL, 0xa18e0cc3UL, 0x1bdf055aUL,
  76582. 0x8def022dUL
  76583. },
  76584. {
  76585. 0x00000000UL, 0x41311b19UL, 0x82623632UL, 0xc3532d2bUL, 0x04c56c64UL,
  76586. 0x45f4777dUL, 0x86a75a56UL, 0xc796414fUL, 0x088ad9c8UL, 0x49bbc2d1UL,
  76587. 0x8ae8effaUL, 0xcbd9f4e3UL, 0x0c4fb5acUL, 0x4d7eaeb5UL, 0x8e2d839eUL,
  76588. 0xcf1c9887UL, 0x5112c24aUL, 0x1023d953UL, 0xd370f478UL, 0x9241ef61UL,
  76589. 0x55d7ae2eUL, 0x14e6b537UL, 0xd7b5981cUL, 0x96848305UL, 0x59981b82UL,
  76590. 0x18a9009bUL, 0xdbfa2db0UL, 0x9acb36a9UL, 0x5d5d77e6UL, 0x1c6c6cffUL,
  76591. 0xdf3f41d4UL, 0x9e0e5acdUL, 0xa2248495UL, 0xe3159f8cUL, 0x2046b2a7UL,
  76592. 0x6177a9beUL, 0xa6e1e8f1UL, 0xe7d0f3e8UL, 0x2483dec3UL, 0x65b2c5daUL,
  76593. 0xaaae5d5dUL, 0xeb9f4644UL, 0x28cc6b6fUL, 0x69fd7076UL, 0xae6b3139UL,
  76594. 0xef5a2a20UL, 0x2c09070bUL, 0x6d381c12UL, 0xf33646dfUL, 0xb2075dc6UL,
  76595. 0x715470edUL, 0x30656bf4UL, 0xf7f32abbUL, 0xb6c231a2UL, 0x75911c89UL,
  76596. 0x34a00790UL, 0xfbbc9f17UL, 0xba8d840eUL, 0x79dea925UL, 0x38efb23cUL,
  76597. 0xff79f373UL, 0xbe48e86aUL, 0x7d1bc541UL, 0x3c2ade58UL, 0x054f79f0UL,
  76598. 0x447e62e9UL, 0x872d4fc2UL, 0xc61c54dbUL, 0x018a1594UL, 0x40bb0e8dUL,
  76599. 0x83e823a6UL, 0xc2d938bfUL, 0x0dc5a038UL, 0x4cf4bb21UL, 0x8fa7960aUL,
  76600. 0xce968d13UL, 0x0900cc5cUL, 0x4831d745UL, 0x8b62fa6eUL, 0xca53e177UL,
  76601. 0x545dbbbaUL, 0x156ca0a3UL, 0xd63f8d88UL, 0x970e9691UL, 0x5098d7deUL,
  76602. 0x11a9ccc7UL, 0xd2fae1ecUL, 0x93cbfaf5UL, 0x5cd76272UL, 0x1de6796bUL,
  76603. 0xdeb55440UL, 0x9f844f59UL, 0x58120e16UL, 0x1923150fUL, 0xda703824UL,
  76604. 0x9b41233dUL, 0xa76bfd65UL, 0xe65ae67cUL, 0x2509cb57UL, 0x6438d04eUL,
  76605. 0xa3ae9101UL, 0xe29f8a18UL, 0x21cca733UL, 0x60fdbc2aUL, 0xafe124adUL,
  76606. 0xeed03fb4UL, 0x2d83129fUL, 0x6cb20986UL, 0xab2448c9UL, 0xea1553d0UL,
  76607. 0x29467efbUL, 0x687765e2UL, 0xf6793f2fUL, 0xb7482436UL, 0x741b091dUL,
  76608. 0x352a1204UL, 0xf2bc534bUL, 0xb38d4852UL, 0x70de6579UL, 0x31ef7e60UL,
  76609. 0xfef3e6e7UL, 0xbfc2fdfeUL, 0x7c91d0d5UL, 0x3da0cbccUL, 0xfa368a83UL,
  76610. 0xbb07919aUL, 0x7854bcb1UL, 0x3965a7a8UL, 0x4b98833bUL, 0x0aa99822UL,
  76611. 0xc9fab509UL, 0x88cbae10UL, 0x4f5def5fUL, 0x0e6cf446UL, 0xcd3fd96dUL,
  76612. 0x8c0ec274UL, 0x43125af3UL, 0x022341eaUL, 0xc1706cc1UL, 0x804177d8UL,
  76613. 0x47d73697UL, 0x06e62d8eUL, 0xc5b500a5UL, 0x84841bbcUL, 0x1a8a4171UL,
  76614. 0x5bbb5a68UL, 0x98e87743UL, 0xd9d96c5aUL, 0x1e4f2d15UL, 0x5f7e360cUL,
  76615. 0x9c2d1b27UL, 0xdd1c003eUL, 0x120098b9UL, 0x533183a0UL, 0x9062ae8bUL,
  76616. 0xd153b592UL, 0x16c5f4ddUL, 0x57f4efc4UL, 0x94a7c2efUL, 0xd596d9f6UL,
  76617. 0xe9bc07aeUL, 0xa88d1cb7UL, 0x6bde319cUL, 0x2aef2a85UL, 0xed796bcaUL,
  76618. 0xac4870d3UL, 0x6f1b5df8UL, 0x2e2a46e1UL, 0xe136de66UL, 0xa007c57fUL,
  76619. 0x6354e854UL, 0x2265f34dUL, 0xe5f3b202UL, 0xa4c2a91bUL, 0x67918430UL,
  76620. 0x26a09f29UL, 0xb8aec5e4UL, 0xf99fdefdUL, 0x3accf3d6UL, 0x7bfde8cfUL,
  76621. 0xbc6ba980UL, 0xfd5ab299UL, 0x3e099fb2UL, 0x7f3884abUL, 0xb0241c2cUL,
  76622. 0xf1150735UL, 0x32462a1eUL, 0x73773107UL, 0xb4e17048UL, 0xf5d06b51UL,
  76623. 0x3683467aUL, 0x77b25d63UL, 0x4ed7facbUL, 0x0fe6e1d2UL, 0xccb5ccf9UL,
  76624. 0x8d84d7e0UL, 0x4a1296afUL, 0x0b238db6UL, 0xc870a09dUL, 0x8941bb84UL,
  76625. 0x465d2303UL, 0x076c381aUL, 0xc43f1531UL, 0x850e0e28UL, 0x42984f67UL,
  76626. 0x03a9547eUL, 0xc0fa7955UL, 0x81cb624cUL, 0x1fc53881UL, 0x5ef42398UL,
  76627. 0x9da70eb3UL, 0xdc9615aaUL, 0x1b0054e5UL, 0x5a314ffcUL, 0x996262d7UL,
  76628. 0xd85379ceUL, 0x174fe149UL, 0x567efa50UL, 0x952dd77bUL, 0xd41ccc62UL,
  76629. 0x138a8d2dUL, 0x52bb9634UL, 0x91e8bb1fUL, 0xd0d9a006UL, 0xecf37e5eUL,
  76630. 0xadc26547UL, 0x6e91486cUL, 0x2fa05375UL, 0xe836123aUL, 0xa9070923UL,
  76631. 0x6a542408UL, 0x2b653f11UL, 0xe479a796UL, 0xa548bc8fUL, 0x661b91a4UL,
  76632. 0x272a8abdUL, 0xe0bccbf2UL, 0xa18dd0ebUL, 0x62defdc0UL, 0x23efe6d9UL,
  76633. 0xbde1bc14UL, 0xfcd0a70dUL, 0x3f838a26UL, 0x7eb2913fUL, 0xb924d070UL,
  76634. 0xf815cb69UL, 0x3b46e642UL, 0x7a77fd5bUL, 0xb56b65dcUL, 0xf45a7ec5UL,
  76635. 0x370953eeUL, 0x763848f7UL, 0xb1ae09b8UL, 0xf09f12a1UL, 0x33cc3f8aUL,
  76636. 0x72fd2493UL
  76637. },
  76638. {
  76639. 0x00000000UL, 0x376ac201UL, 0x6ed48403UL, 0x59be4602UL, 0xdca80907UL,
  76640. 0xebc2cb06UL, 0xb27c8d04UL, 0x85164f05UL, 0xb851130eUL, 0x8f3bd10fUL,
  76641. 0xd685970dUL, 0xe1ef550cUL, 0x64f91a09UL, 0x5393d808UL, 0x0a2d9e0aUL,
  76642. 0x3d475c0bUL, 0x70a3261cUL, 0x47c9e41dUL, 0x1e77a21fUL, 0x291d601eUL,
  76643. 0xac0b2f1bUL, 0x9b61ed1aUL, 0xc2dfab18UL, 0xf5b56919UL, 0xc8f23512UL,
  76644. 0xff98f713UL, 0xa626b111UL, 0x914c7310UL, 0x145a3c15UL, 0x2330fe14UL,
  76645. 0x7a8eb816UL, 0x4de47a17UL, 0xe0464d38UL, 0xd72c8f39UL, 0x8e92c93bUL,
  76646. 0xb9f80b3aUL, 0x3cee443fUL, 0x0b84863eUL, 0x523ac03cUL, 0x6550023dUL,
  76647. 0x58175e36UL, 0x6f7d9c37UL, 0x36c3da35UL, 0x01a91834UL, 0x84bf5731UL,
  76648. 0xb3d59530UL, 0xea6bd332UL, 0xdd011133UL, 0x90e56b24UL, 0xa78fa925UL,
  76649. 0xfe31ef27UL, 0xc95b2d26UL, 0x4c4d6223UL, 0x7b27a022UL, 0x2299e620UL,
  76650. 0x15f32421UL, 0x28b4782aUL, 0x1fdeba2bUL, 0x4660fc29UL, 0x710a3e28UL,
  76651. 0xf41c712dUL, 0xc376b32cUL, 0x9ac8f52eUL, 0xada2372fUL, 0xc08d9a70UL,
  76652. 0xf7e75871UL, 0xae591e73UL, 0x9933dc72UL, 0x1c259377UL, 0x2b4f5176UL,
  76653. 0x72f11774UL, 0x459bd575UL, 0x78dc897eUL, 0x4fb64b7fUL, 0x16080d7dUL,
  76654. 0x2162cf7cUL, 0xa4748079UL, 0x931e4278UL, 0xcaa0047aUL, 0xfdcac67bUL,
  76655. 0xb02ebc6cUL, 0x87447e6dUL, 0xdefa386fUL, 0xe990fa6eUL, 0x6c86b56bUL,
  76656. 0x5bec776aUL, 0x02523168UL, 0x3538f369UL, 0x087faf62UL, 0x3f156d63UL,
  76657. 0x66ab2b61UL, 0x51c1e960UL, 0xd4d7a665UL, 0xe3bd6464UL, 0xba032266UL,
  76658. 0x8d69e067UL, 0x20cbd748UL, 0x17a11549UL, 0x4e1f534bUL, 0x7975914aUL,
  76659. 0xfc63de4fUL, 0xcb091c4eUL, 0x92b75a4cUL, 0xa5dd984dUL, 0x989ac446UL,
  76660. 0xaff00647UL, 0xf64e4045UL, 0xc1248244UL, 0x4432cd41UL, 0x73580f40UL,
  76661. 0x2ae64942UL, 0x1d8c8b43UL, 0x5068f154UL, 0x67023355UL, 0x3ebc7557UL,
  76662. 0x09d6b756UL, 0x8cc0f853UL, 0xbbaa3a52UL, 0xe2147c50UL, 0xd57ebe51UL,
  76663. 0xe839e25aUL, 0xdf53205bUL, 0x86ed6659UL, 0xb187a458UL, 0x3491eb5dUL,
  76664. 0x03fb295cUL, 0x5a456f5eUL, 0x6d2fad5fUL, 0x801b35e1UL, 0xb771f7e0UL,
  76665. 0xeecfb1e2UL, 0xd9a573e3UL, 0x5cb33ce6UL, 0x6bd9fee7UL, 0x3267b8e5UL,
  76666. 0x050d7ae4UL, 0x384a26efUL, 0x0f20e4eeUL, 0x569ea2ecUL, 0x61f460edUL,
  76667. 0xe4e22fe8UL, 0xd388ede9UL, 0x8a36abebUL, 0xbd5c69eaUL, 0xf0b813fdUL,
  76668. 0xc7d2d1fcUL, 0x9e6c97feUL, 0xa90655ffUL, 0x2c101afaUL, 0x1b7ad8fbUL,
  76669. 0x42c49ef9UL, 0x75ae5cf8UL, 0x48e900f3UL, 0x7f83c2f2UL, 0x263d84f0UL,
  76670. 0x115746f1UL, 0x944109f4UL, 0xa32bcbf5UL, 0xfa958df7UL, 0xcdff4ff6UL,
  76671. 0x605d78d9UL, 0x5737bad8UL, 0x0e89fcdaUL, 0x39e33edbUL, 0xbcf571deUL,
  76672. 0x8b9fb3dfUL, 0xd221f5ddUL, 0xe54b37dcUL, 0xd80c6bd7UL, 0xef66a9d6UL,
  76673. 0xb6d8efd4UL, 0x81b22dd5UL, 0x04a462d0UL, 0x33cea0d1UL, 0x6a70e6d3UL,
  76674. 0x5d1a24d2UL, 0x10fe5ec5UL, 0x27949cc4UL, 0x7e2adac6UL, 0x494018c7UL,
  76675. 0xcc5657c2UL, 0xfb3c95c3UL, 0xa282d3c1UL, 0x95e811c0UL, 0xa8af4dcbUL,
  76676. 0x9fc58fcaUL, 0xc67bc9c8UL, 0xf1110bc9UL, 0x740744ccUL, 0x436d86cdUL,
  76677. 0x1ad3c0cfUL, 0x2db902ceUL, 0x4096af91UL, 0x77fc6d90UL, 0x2e422b92UL,
  76678. 0x1928e993UL, 0x9c3ea696UL, 0xab546497UL, 0xf2ea2295UL, 0xc580e094UL,
  76679. 0xf8c7bc9fUL, 0xcfad7e9eUL, 0x9613389cUL, 0xa179fa9dUL, 0x246fb598UL,
  76680. 0x13057799UL, 0x4abb319bUL, 0x7dd1f39aUL, 0x3035898dUL, 0x075f4b8cUL,
  76681. 0x5ee10d8eUL, 0x698bcf8fUL, 0xec9d808aUL, 0xdbf7428bUL, 0x82490489UL,
  76682. 0xb523c688UL, 0x88649a83UL, 0xbf0e5882UL, 0xe6b01e80UL, 0xd1dadc81UL,
  76683. 0x54cc9384UL, 0x63a65185UL, 0x3a181787UL, 0x0d72d586UL, 0xa0d0e2a9UL,
  76684. 0x97ba20a8UL, 0xce0466aaUL, 0xf96ea4abUL, 0x7c78ebaeUL, 0x4b1229afUL,
  76685. 0x12ac6fadUL, 0x25c6adacUL, 0x1881f1a7UL, 0x2feb33a6UL, 0x765575a4UL,
  76686. 0x413fb7a5UL, 0xc429f8a0UL, 0xf3433aa1UL, 0xaafd7ca3UL, 0x9d97bea2UL,
  76687. 0xd073c4b5UL, 0xe71906b4UL, 0xbea740b6UL, 0x89cd82b7UL, 0x0cdbcdb2UL,
  76688. 0x3bb10fb3UL, 0x620f49b1UL, 0x55658bb0UL, 0x6822d7bbUL, 0x5f4815baUL,
  76689. 0x06f653b8UL, 0x319c91b9UL, 0xb48adebcUL, 0x83e01cbdUL, 0xda5e5abfUL,
  76690. 0xed3498beUL
  76691. },
  76692. {
  76693. 0x00000000UL, 0x6567bcb8UL, 0x8bc809aaUL, 0xeeafb512UL, 0x5797628fUL,
  76694. 0x32f0de37UL, 0xdc5f6b25UL, 0xb938d79dUL, 0xef28b4c5UL, 0x8a4f087dUL,
  76695. 0x64e0bd6fUL, 0x018701d7UL, 0xb8bfd64aUL, 0xddd86af2UL, 0x3377dfe0UL,
  76696. 0x56106358UL, 0x9f571950UL, 0xfa30a5e8UL, 0x149f10faUL, 0x71f8ac42UL,
  76697. 0xc8c07bdfUL, 0xada7c767UL, 0x43087275UL, 0x266fcecdUL, 0x707fad95UL,
  76698. 0x1518112dUL, 0xfbb7a43fUL, 0x9ed01887UL, 0x27e8cf1aUL, 0x428f73a2UL,
  76699. 0xac20c6b0UL, 0xc9477a08UL, 0x3eaf32a0UL, 0x5bc88e18UL, 0xb5673b0aUL,
  76700. 0xd00087b2UL, 0x6938502fUL, 0x0c5fec97UL, 0xe2f05985UL, 0x8797e53dUL,
  76701. 0xd1878665UL, 0xb4e03addUL, 0x5a4f8fcfUL, 0x3f283377UL, 0x8610e4eaUL,
  76702. 0xe3775852UL, 0x0dd8ed40UL, 0x68bf51f8UL, 0xa1f82bf0UL, 0xc49f9748UL,
  76703. 0x2a30225aUL, 0x4f579ee2UL, 0xf66f497fUL, 0x9308f5c7UL, 0x7da740d5UL,
  76704. 0x18c0fc6dUL, 0x4ed09f35UL, 0x2bb7238dUL, 0xc518969fUL, 0xa07f2a27UL,
  76705. 0x1947fdbaUL, 0x7c204102UL, 0x928ff410UL, 0xf7e848a8UL, 0x3d58149bUL,
  76706. 0x583fa823UL, 0xb6901d31UL, 0xd3f7a189UL, 0x6acf7614UL, 0x0fa8caacUL,
  76707. 0xe1077fbeUL, 0x8460c306UL, 0xd270a05eUL, 0xb7171ce6UL, 0x59b8a9f4UL,
  76708. 0x3cdf154cUL, 0x85e7c2d1UL, 0xe0807e69UL, 0x0e2fcb7bUL, 0x6b4877c3UL,
  76709. 0xa20f0dcbUL, 0xc768b173UL, 0x29c70461UL, 0x4ca0b8d9UL, 0xf5986f44UL,
  76710. 0x90ffd3fcUL, 0x7e5066eeUL, 0x1b37da56UL, 0x4d27b90eUL, 0x284005b6UL,
  76711. 0xc6efb0a4UL, 0xa3880c1cUL, 0x1ab0db81UL, 0x7fd76739UL, 0x9178d22bUL,
  76712. 0xf41f6e93UL, 0x03f7263bUL, 0x66909a83UL, 0x883f2f91UL, 0xed589329UL,
  76713. 0x546044b4UL, 0x3107f80cUL, 0xdfa84d1eUL, 0xbacff1a6UL, 0xecdf92feUL,
  76714. 0x89b82e46UL, 0x67179b54UL, 0x027027ecUL, 0xbb48f071UL, 0xde2f4cc9UL,
  76715. 0x3080f9dbUL, 0x55e74563UL, 0x9ca03f6bUL, 0xf9c783d3UL, 0x176836c1UL,
  76716. 0x720f8a79UL, 0xcb375de4UL, 0xae50e15cUL, 0x40ff544eUL, 0x2598e8f6UL,
  76717. 0x73888baeUL, 0x16ef3716UL, 0xf8408204UL, 0x9d273ebcUL, 0x241fe921UL,
  76718. 0x41785599UL, 0xafd7e08bUL, 0xcab05c33UL, 0x3bb659edUL, 0x5ed1e555UL,
  76719. 0xb07e5047UL, 0xd519ecffUL, 0x6c213b62UL, 0x094687daUL, 0xe7e932c8UL,
  76720. 0x828e8e70UL, 0xd49eed28UL, 0xb1f95190UL, 0x5f56e482UL, 0x3a31583aUL,
  76721. 0x83098fa7UL, 0xe66e331fUL, 0x08c1860dUL, 0x6da63ab5UL, 0xa4e140bdUL,
  76722. 0xc186fc05UL, 0x2f294917UL, 0x4a4ef5afUL, 0xf3762232UL, 0x96119e8aUL,
  76723. 0x78be2b98UL, 0x1dd99720UL, 0x4bc9f478UL, 0x2eae48c0UL, 0xc001fdd2UL,
  76724. 0xa566416aUL, 0x1c5e96f7UL, 0x79392a4fUL, 0x97969f5dUL, 0xf2f123e5UL,
  76725. 0x05196b4dUL, 0x607ed7f5UL, 0x8ed162e7UL, 0xebb6de5fUL, 0x528e09c2UL,
  76726. 0x37e9b57aUL, 0xd9460068UL, 0xbc21bcd0UL, 0xea31df88UL, 0x8f566330UL,
  76727. 0x61f9d622UL, 0x049e6a9aUL, 0xbda6bd07UL, 0xd8c101bfUL, 0x366eb4adUL,
  76728. 0x53090815UL, 0x9a4e721dUL, 0xff29cea5UL, 0x11867bb7UL, 0x74e1c70fUL,
  76729. 0xcdd91092UL, 0xa8beac2aUL, 0x46111938UL, 0x2376a580UL, 0x7566c6d8UL,
  76730. 0x10017a60UL, 0xfeaecf72UL, 0x9bc973caUL, 0x22f1a457UL, 0x479618efUL,
  76731. 0xa939adfdUL, 0xcc5e1145UL, 0x06ee4d76UL, 0x6389f1ceUL, 0x8d2644dcUL,
  76732. 0xe841f864UL, 0x51792ff9UL, 0x341e9341UL, 0xdab12653UL, 0xbfd69aebUL,
  76733. 0xe9c6f9b3UL, 0x8ca1450bUL, 0x620ef019UL, 0x07694ca1UL, 0xbe519b3cUL,
  76734. 0xdb362784UL, 0x35999296UL, 0x50fe2e2eUL, 0x99b95426UL, 0xfcdee89eUL,
  76735. 0x12715d8cUL, 0x7716e134UL, 0xce2e36a9UL, 0xab498a11UL, 0x45e63f03UL,
  76736. 0x208183bbUL, 0x7691e0e3UL, 0x13f65c5bUL, 0xfd59e949UL, 0x983e55f1UL,
  76737. 0x2106826cUL, 0x44613ed4UL, 0xaace8bc6UL, 0xcfa9377eUL, 0x38417fd6UL,
  76738. 0x5d26c36eUL, 0xb389767cUL, 0xd6eecac4UL, 0x6fd61d59UL, 0x0ab1a1e1UL,
  76739. 0xe41e14f3UL, 0x8179a84bUL, 0xd769cb13UL, 0xb20e77abUL, 0x5ca1c2b9UL,
  76740. 0x39c67e01UL, 0x80fea99cUL, 0xe5991524UL, 0x0b36a036UL, 0x6e511c8eUL,
  76741. 0xa7166686UL, 0xc271da3eUL, 0x2cde6f2cUL, 0x49b9d394UL, 0xf0810409UL,
  76742. 0x95e6b8b1UL, 0x7b490da3UL, 0x1e2eb11bUL, 0x483ed243UL, 0x2d596efbUL,
  76743. 0xc3f6dbe9UL, 0xa6916751UL, 0x1fa9b0ccUL, 0x7ace0c74UL, 0x9461b966UL,
  76744. 0xf10605deUL
  76745. #endif
  76746. }
  76747. };
  76748. /*** End of inlined file: crc32.h ***/
  76749. #endif /* DYNAMIC_CRC_TABLE */
  76750. const unsigned long FAR * ZEXPORT get_crc_table()
  76751. {
  76752. #ifdef DYNAMIC_CRC_TABLE
  76753. if (crc_table_empty)
  76754. make_crc_table();
  76755. #endif /* DYNAMIC_CRC_TABLE */
  76756. return (const unsigned long FAR *)crc_table;
  76757. }
  76758. #define DO1 crc = crc_table[0][((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8)
  76759. #define DO8 DO1; DO1; DO1; DO1; DO1; DO1; DO1; DO1
  76760. unsigned long ZEXPORT crc32 (unsigned long crc, const unsigned char FAR *buf, unsigned len)
  76761. {
  76762. if (buf == Z_NULL) return 0UL;
  76763. #ifdef DYNAMIC_CRC_TABLE
  76764. if (crc_table_empty)
  76765. make_crc_table();
  76766. #endif /* DYNAMIC_CRC_TABLE */
  76767. #ifdef BYFOUR
  76768. if (sizeof(void *) == sizeof(ptrdiff_t)) {
  76769. u4 endian;
  76770. endian = 1;
  76771. if (*((unsigned char *)(&endian)))
  76772. return crc32_little(crc, buf, len);
  76773. else
  76774. return crc32_big(crc, buf, len);
  76775. }
  76776. #endif /* BYFOUR */
  76777. crc = crc ^ 0xffffffffUL;
  76778. while (len >= 8) {
  76779. DO8;
  76780. len -= 8;
  76781. }
  76782. if (len) do {
  76783. DO1;
  76784. } while (--len);
  76785. return crc ^ 0xffffffffUL;
  76786. }
  76787. #ifdef BYFOUR
  76788. #define DOLIT4 c ^= *buf4++; \
  76789. c = crc_table[3][c & 0xff] ^ crc_table[2][(c >> 8) & 0xff] ^ \
  76790. crc_table[1][(c >> 16) & 0xff] ^ crc_table[0][c >> 24]
  76791. #define DOLIT32 DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4
  76792. local unsigned long crc32_little(unsigned long crc, const unsigned char FAR *buf, unsigned len)
  76793. {
  76794. register u4 c;
  76795. register const u4 FAR *buf4;
  76796. c = (u4)crc;
  76797. c = ~c;
  76798. while (len && ((ptrdiff_t)buf & 3)) {
  76799. c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
  76800. len--;
  76801. }
  76802. buf4 = (const u4 FAR *)(const void FAR *)buf;
  76803. while (len >= 32) {
  76804. DOLIT32;
  76805. len -= 32;
  76806. }
  76807. while (len >= 4) {
  76808. DOLIT4;
  76809. len -= 4;
  76810. }
  76811. buf = (const unsigned char FAR *)buf4;
  76812. if (len) do {
  76813. c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
  76814. } while (--len);
  76815. c = ~c;
  76816. return (unsigned long)c;
  76817. }
  76818. #define DOBIG4 c ^= *++buf4; \
  76819. c = crc_table[4][c & 0xff] ^ crc_table[5][(c >> 8) & 0xff] ^ \
  76820. crc_table[6][(c >> 16) & 0xff] ^ crc_table[7][c >> 24]
  76821. #define DOBIG32 DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4
  76822. local unsigned long crc32_big (unsigned long crc, const unsigned char FAR *buf, unsigned len)
  76823. {
  76824. register u4 c;
  76825. register const u4 FAR *buf4;
  76826. c = REV((u4)crc);
  76827. c = ~c;
  76828. while (len && ((ptrdiff_t)buf & 3)) {
  76829. c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
  76830. len--;
  76831. }
  76832. buf4 = (const u4 FAR *)(const void FAR *)buf;
  76833. buf4--;
  76834. while (len >= 32) {
  76835. DOBIG32;
  76836. len -= 32;
  76837. }
  76838. while (len >= 4) {
  76839. DOBIG4;
  76840. len -= 4;
  76841. }
  76842. buf4++;
  76843. buf = (const unsigned char FAR *)buf4;
  76844. if (len) do {
  76845. c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
  76846. } while (--len);
  76847. c = ~c;
  76848. return (unsigned long)(REV(c));
  76849. }
  76850. #endif /* BYFOUR */
  76851. #define GF2_DIM 32 /* dimension of GF(2) vectors (length of CRC) */
  76852. local unsigned long gf2_matrix_times (unsigned long *mat, unsigned long vec)
  76853. {
  76854. unsigned long sum;
  76855. sum = 0;
  76856. while (vec) {
  76857. if (vec & 1)
  76858. sum ^= *mat;
  76859. vec >>= 1;
  76860. mat++;
  76861. }
  76862. return sum;
  76863. }
  76864. local void gf2_matrix_square (unsigned long *square, unsigned long *mat)
  76865. {
  76866. int n;
  76867. for (n = 0; n < GF2_DIM; n++)
  76868. square[n] = gf2_matrix_times(mat, mat[n]);
  76869. }
  76870. uLong ZEXPORT crc32_combine (uLong crc1, uLong crc2, z_off_t len2)
  76871. {
  76872. int n;
  76873. unsigned long row;
  76874. unsigned long even[GF2_DIM]; /* even-power-of-two zeros operator */
  76875. unsigned long odd[GF2_DIM]; /* odd-power-of-two zeros operator */
  76876. if (len2 == 0)
  76877. return crc1;
  76878. odd[0] = 0xedb88320L; /* CRC-32 polynomial */
  76879. row = 1;
  76880. for (n = 1; n < GF2_DIM; n++) {
  76881. odd[n] = row;
  76882. row <<= 1;
  76883. }
  76884. gf2_matrix_square(even, odd);
  76885. gf2_matrix_square(odd, even);
  76886. do {
  76887. gf2_matrix_square(even, odd);
  76888. if (len2 & 1)
  76889. crc1 = gf2_matrix_times(even, crc1);
  76890. len2 >>= 1;
  76891. if (len2 == 0)
  76892. break;
  76893. gf2_matrix_square(odd, even);
  76894. if (len2 & 1)
  76895. crc1 = gf2_matrix_times(odd, crc1);
  76896. len2 >>= 1;
  76897. } while (len2 != 0);
  76898. crc1 ^= crc2;
  76899. return crc1;
  76900. }
  76901. /*** End of inlined file: crc32.c ***/
  76902. /*** Start of inlined file: deflate.c ***/
  76903. /*** Start of inlined file: deflate.h ***/
  76904. #ifndef DEFLATE_H
  76905. #define DEFLATE_H
  76906. #ifndef NO_GZIP
  76907. # define GZIP
  76908. #endif
  76909. #define NO_DUMMY_DECL
  76910. #define LENGTH_CODES 29
  76911. #define LITERALS 256
  76912. #define L_CODES (LITERALS+1+LENGTH_CODES)
  76913. #define D_CODES 30
  76914. #define BL_CODES 19
  76915. #define HEAP_SIZE (2*L_CODES+1)
  76916. #define MAX_BITS 15
  76917. #define INIT_STATE 42
  76918. #define EXTRA_STATE 69
  76919. #define NAME_STATE 73
  76920. #define COMMENT_STATE 91
  76921. #define HCRC_STATE 103
  76922. #define BUSY_STATE 113
  76923. #define FINISH_STATE 666
  76924. typedef struct ct_data_s {
  76925. union {
  76926. ush freq; /* frequency count */
  76927. ush code; /* bit string */
  76928. } fc;
  76929. union {
  76930. ush dad; /* father node in Huffman tree */
  76931. ush len; /* length of bit string */
  76932. } dl;
  76933. } FAR ct_data;
  76934. #define Freq fc.freq
  76935. #define Code fc.code
  76936. #define Dad dl.dad
  76937. #define Len dl.len
  76938. typedef struct static_tree_desc_s static_tree_desc;
  76939. typedef struct tree_desc_s {
  76940. ct_data *dyn_tree; /* the dynamic tree */
  76941. int max_code; /* largest code with non zero frequency */
  76942. static_tree_desc *stat_desc; /* the corresponding static tree */
  76943. } FAR tree_desc;
  76944. typedef ush Pos;
  76945. typedef Pos FAR Posf;
  76946. typedef unsigned IPos;
  76947. typedef struct internal_state {
  76948. z_streamp strm; /* pointer back to this zlib stream */
  76949. int status; /* as the name implies */
  76950. Bytef *pending_buf; /* output still pending */
  76951. ulg pending_buf_size; /* size of pending_buf */
  76952. Bytef *pending_out; /* next pending byte to output to the stream */
  76953. uInt pending; /* nb of bytes in the pending buffer */
  76954. int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
  76955. gz_headerp gzhead; /* gzip header information to write */
  76956. uInt gzindex; /* where in extra, name, or comment */
  76957. Byte method; /* STORED (for zip only) or DEFLATED */
  76958. int last_flush; /* value of flush param for previous deflate call */
  76959. uInt w_size; /* LZ77 window size (32K by default) */
  76960. uInt w_bits; /* log2(w_size) (8..16) */
  76961. uInt w_mask; /* w_size - 1 */
  76962. Bytef *window;
  76963. ulg window_size;
  76964. Posf *prev;
  76965. Posf *head; /* Heads of the hash chains or NIL. */
  76966. uInt ins_h; /* hash index of string to be inserted */
  76967. uInt hash_size; /* number of elements in hash table */
  76968. uInt hash_bits; /* log2(hash_size) */
  76969. uInt hash_mask; /* hash_size-1 */
  76970. uInt hash_shift;
  76971. long block_start;
  76972. uInt match_length; /* length of best match */
  76973. IPos prev_match; /* previous match */
  76974. int match_available; /* set if previous match exists */
  76975. uInt strstart; /* start of string to insert */
  76976. uInt match_start; /* start of matching string */
  76977. uInt lookahead; /* number of valid bytes ahead in window */
  76978. uInt prev_length;
  76979. uInt max_chain_length;
  76980. uInt max_lazy_match;
  76981. # define max_insert_length max_lazy_match
  76982. int level; /* compression level (1..9) */
  76983. int strategy; /* favor or force Huffman coding*/
  76984. uInt good_match;
  76985. int nice_match; /* Stop searching when current match exceeds this */
  76986. struct ct_data_s dyn_ltree[HEAP_SIZE]; /* literal and length tree */
  76987. struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */
  76988. struct ct_data_s bl_tree[2*BL_CODES+1]; /* Huffman tree for bit lengths */
  76989. struct tree_desc_s l_desc; /* desc. for literal tree */
  76990. struct tree_desc_s d_desc; /* desc. for distance tree */
  76991. struct tree_desc_s bl_desc; /* desc. for bit length tree */
  76992. ush bl_count[MAX_BITS+1];
  76993. int heap[2*L_CODES+1]; /* heap used to build the Huffman trees */
  76994. int heap_len; /* number of elements in the heap */
  76995. int heap_max; /* element of largest frequency */
  76996. uch depth[2*L_CODES+1];
  76997. uchf *l_buf; /* buffer for literals or lengths */
  76998. uInt lit_bufsize;
  76999. uInt last_lit; /* running index in l_buf */
  77000. ushf *d_buf;
  77001. ulg opt_len; /* bit length of current block with optimal trees */
  77002. ulg static_len; /* bit length of current block with static trees */
  77003. uInt matches; /* number of string matches in current block */
  77004. int last_eob_len; /* bit length of EOB code for last block */
  77005. #ifdef DEBUG
  77006. ulg compressed_len; /* total bit length of compressed file mod 2^32 */
  77007. ulg bits_sent; /* bit length of compressed data sent mod 2^32 */
  77008. #endif
  77009. ush bi_buf;
  77010. int bi_valid;
  77011. } FAR deflate_state;
  77012. #define put_byte(s, c) {s->pending_buf[s->pending++] = (c);}
  77013. #define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
  77014. #define MAX_DIST(s) ((s)->w_size-MIN_LOOKAHEAD)
  77015. void _tr_init OF((deflate_state *s));
  77016. int _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc));
  77017. void _tr_flush_block OF((deflate_state *s, charf *buf, ulg stored_len,
  77018. int eof));
  77019. void _tr_align OF((deflate_state *s));
  77020. void _tr_stored_block OF((deflate_state *s, charf *buf, ulg stored_len,
  77021. int eof));
  77022. #define d_code(dist) \
  77023. ((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)])
  77024. #ifndef DEBUG
  77025. #if defined(GEN_TREES_H) || !defined(STDC)
  77026. extern uch _length_code[];
  77027. extern uch _dist_code[];
  77028. #else
  77029. extern const uch _length_code[];
  77030. extern const uch _dist_code[];
  77031. #endif
  77032. # define _tr_tally_lit(s, c, flush) \
  77033. { uch cc = (c); \
  77034. s->d_buf[s->last_lit] = 0; \
  77035. s->l_buf[s->last_lit++] = cc; \
  77036. s->dyn_ltree[cc].Freq++; \
  77037. flush = (s->last_lit == s->lit_bufsize-1); \
  77038. }
  77039. # define _tr_tally_dist(s, distance, length, flush) \
  77040. { uch len = (length); \
  77041. ush dist = (distance); \
  77042. s->d_buf[s->last_lit] = dist; \
  77043. s->l_buf[s->last_lit++] = len; \
  77044. dist--; \
  77045. s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \
  77046. s->dyn_dtree[d_code(dist)].Freq++; \
  77047. flush = (s->last_lit == s->lit_bufsize-1); \
  77048. }
  77049. #else
  77050. # define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c)
  77051. # define _tr_tally_dist(s, distance, length, flush) \
  77052. flush = _tr_tally(s, distance, length)
  77053. #endif
  77054. #endif /* DEFLATE_H */
  77055. /*** End of inlined file: deflate.h ***/
  77056. const char deflate_copyright[] =
  77057. " deflate 1.2.3 Copyright 1995-2005 Jean-loup Gailly ";
  77058. typedef enum {
  77059. need_more, /* block not completed, need more input or more output */
  77060. block_done, /* block flush performed */
  77061. finish_started, /* finish started, need only more output at next deflate */
  77062. finish_done /* finish done, accept no more input or output */
  77063. } block_state;
  77064. typedef block_state (*compress_func) OF((deflate_state *s, int flush));
  77065. local void fill_window OF((deflate_state *s));
  77066. local block_state deflate_stored OF((deflate_state *s, int flush));
  77067. local block_state deflate_fast OF((deflate_state *s, int flush));
  77068. #ifndef FASTEST
  77069. local block_state deflate_slow OF((deflate_state *s, int flush));
  77070. #endif
  77071. local void lm_init OF((deflate_state *s));
  77072. local void putShortMSB OF((deflate_state *s, uInt b));
  77073. local void flush_pending OF((z_streamp strm));
  77074. local int read_buf OF((z_streamp strm, Bytef *buf, unsigned size));
  77075. #ifndef FASTEST
  77076. #ifdef ASMV
  77077. void match_init OF((void)); /* asm code initialization */
  77078. uInt longest_match OF((deflate_state *s, IPos cur_match));
  77079. #else
  77080. local uInt longest_match OF((deflate_state *s, IPos cur_match));
  77081. #endif
  77082. #endif
  77083. local uInt longest_match_fast OF((deflate_state *s, IPos cur_match));
  77084. #ifdef DEBUG
  77085. local void check_match OF((deflate_state *s, IPos start, IPos match,
  77086. int length));
  77087. #endif
  77088. #define NIL 0
  77089. #ifndef TOO_FAR
  77090. # define TOO_FAR 4096
  77091. #endif
  77092. #define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
  77093. typedef struct config_s {
  77094. ush good_length; /* reduce lazy search above this match length */
  77095. ush max_lazy; /* do not perform lazy search above this match length */
  77096. ush nice_length; /* quit search above this match length */
  77097. ush max_chain;
  77098. compress_func func;
  77099. } config;
  77100. #ifdef FASTEST
  77101. local const config configuration_table[2] = {
  77102. {0, 0, 0, 0, deflate_stored}, /* store only */
  77103. {4, 4, 8, 4, deflate_fast}}; /* max speed, no lazy matches */
  77104. #else
  77105. local const config configuration_table[10] = {
  77106. {0, 0, 0, 0, deflate_stored}, /* store only */
  77107. {4, 4, 8, 4, deflate_fast}, /* max speed, no lazy matches */
  77108. {4, 5, 16, 8, deflate_fast},
  77109. {4, 6, 32, 32, deflate_fast},
  77110. {4, 4, 16, 16, deflate_slow}, /* lazy matches */
  77111. {8, 16, 32, 32, deflate_slow},
  77112. {8, 16, 128, 128, deflate_slow},
  77113. {8, 32, 128, 256, deflate_slow},
  77114. {32, 128, 258, 1024, deflate_slow},
  77115. {32, 258, 258, 4096, deflate_slow}}; /* max compression */
  77116. #endif
  77117. #define EQUAL 0
  77118. #ifndef NO_DUMMY_DECL
  77119. struct static_tree_desc_s {int dummy;}; /* for buggy compilers */
  77120. #endif
  77121. #define UPDATE_HASH(s,h,c) (h = (((h)<<s->hash_shift) ^ (c)) & s->hash_mask)
  77122. #ifdef FASTEST
  77123. #define INSERT_STRING(s, str, match_head) \
  77124. (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
  77125. match_head = s->head[s->ins_h], \
  77126. s->head[s->ins_h] = (Pos)(str))
  77127. #else
  77128. #define INSERT_STRING(s, str, match_head) \
  77129. (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
  77130. match_head = s->prev[(str) & s->w_mask] = s->head[s->ins_h], \
  77131. s->head[s->ins_h] = (Pos)(str))
  77132. #endif
  77133. #define CLEAR_HASH(s) \
  77134. s->head[s->hash_size-1] = NIL; \
  77135. zmemzero((Bytef *)s->head, (unsigned)(s->hash_size-1)*sizeof(*s->head));
  77136. int ZEXPORT deflateInit_(z_streamp strm, int level, const char *version, int stream_size)
  77137. {
  77138. return deflateInit2_(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL,
  77139. Z_DEFAULT_STRATEGY, version, stream_size);
  77140. }
  77141. int ZEXPORT deflateInit2_ (z_streamp strm, int level, int method, int windowBits, int memLevel, int strategy, const char *version, int stream_size)
  77142. {
  77143. deflate_state *s;
  77144. int wrap = 1;
  77145. static const char my_version[] = ZLIB_VERSION;
  77146. ushf *overlay;
  77147. if (version == Z_NULL || version[0] != my_version[0] ||
  77148. stream_size != sizeof(z_stream)) {
  77149. return Z_VERSION_ERROR;
  77150. }
  77151. if (strm == Z_NULL) return Z_STREAM_ERROR;
  77152. strm->msg = Z_NULL;
  77153. if (strm->zalloc == (alloc_func)0) {
  77154. strm->zalloc = zcalloc;
  77155. strm->opaque = (voidpf)0;
  77156. }
  77157. if (strm->zfree == (free_func)0) strm->zfree = zcfree;
  77158. #ifdef FASTEST
  77159. if (level != 0) level = 1;
  77160. #else
  77161. if (level == Z_DEFAULT_COMPRESSION) level = 6;
  77162. #endif
  77163. if (windowBits < 0) { /* suppress zlib wrapper */
  77164. wrap = 0;
  77165. windowBits = -windowBits;
  77166. }
  77167. #ifdef GZIP
  77168. else if (windowBits > 15) {
  77169. wrap = 2; /* write gzip wrapper instead */
  77170. windowBits -= 16;
  77171. }
  77172. #endif
  77173. if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED ||
  77174. windowBits < 8 || windowBits > 15 || level < 0 || level > 9 ||
  77175. strategy < 0 || strategy > Z_FIXED) {
  77176. return Z_STREAM_ERROR;
  77177. }
  77178. if (windowBits == 8) windowBits = 9; /* until 256-byte window bug fixed */
  77179. s = (deflate_state *) ZALLOC(strm, 1, sizeof(deflate_state));
  77180. if (s == Z_NULL) return Z_MEM_ERROR;
  77181. strm->state = (struct internal_state FAR *)s;
  77182. s->strm = strm;
  77183. s->wrap = wrap;
  77184. s->gzhead = Z_NULL;
  77185. s->w_bits = windowBits;
  77186. s->w_size = 1 << s->w_bits;
  77187. s->w_mask = s->w_size - 1;
  77188. s->hash_bits = memLevel + 7;
  77189. s->hash_size = 1 << s->hash_bits;
  77190. s->hash_mask = s->hash_size - 1;
  77191. s->hash_shift = ((s->hash_bits+MIN_MATCH-1)/MIN_MATCH);
  77192. s->window = (Bytef *) ZALLOC(strm, s->w_size, 2*sizeof(Byte));
  77193. s->prev = (Posf *) ZALLOC(strm, s->w_size, sizeof(Pos));
  77194. s->head = (Posf *) ZALLOC(strm, s->hash_size, sizeof(Pos));
  77195. s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */
  77196. overlay = (ushf *) ZALLOC(strm, s->lit_bufsize, sizeof(ush)+2);
  77197. s->pending_buf = (uchf *) overlay;
  77198. s->pending_buf_size = (ulg)s->lit_bufsize * (sizeof(ush)+2L);
  77199. if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL ||
  77200. s->pending_buf == Z_NULL) {
  77201. s->status = FINISH_STATE;
  77202. strm->msg = (char*)ERR_MSG(Z_MEM_ERROR);
  77203. deflateEnd (strm);
  77204. return Z_MEM_ERROR;
  77205. }
  77206. s->d_buf = overlay + s->lit_bufsize/sizeof(ush);
  77207. s->l_buf = s->pending_buf + (1+sizeof(ush))*s->lit_bufsize;
  77208. s->level = level;
  77209. s->strategy = strategy;
  77210. s->method = (Byte)method;
  77211. return deflateReset(strm);
  77212. }
  77213. int ZEXPORT deflateSetDictionary (z_streamp strm, const Bytef *dictionary, uInt dictLength)
  77214. {
  77215. deflate_state *s;
  77216. uInt length = dictLength;
  77217. uInt n;
  77218. IPos hash_head = 0;
  77219. if (strm == Z_NULL || strm->state == Z_NULL || dictionary == Z_NULL ||
  77220. strm->state->wrap == 2 ||
  77221. (strm->state->wrap == 1 && strm->state->status != INIT_STATE))
  77222. return Z_STREAM_ERROR;
  77223. s = strm->state;
  77224. if (s->wrap)
  77225. strm->adler = adler32(strm->adler, dictionary, dictLength);
  77226. if (length < MIN_MATCH) return Z_OK;
  77227. if (length > MAX_DIST(s)) {
  77228. length = MAX_DIST(s);
  77229. dictionary += dictLength - length; /* use the tail of the dictionary */
  77230. }
  77231. zmemcpy(s->window, dictionary, length);
  77232. s->strstart = length;
  77233. s->block_start = (long)length;
  77234. s->ins_h = s->window[0];
  77235. UPDATE_HASH(s, s->ins_h, s->window[1]);
  77236. for (n = 0; n <= length - MIN_MATCH; n++) {
  77237. INSERT_STRING(s, n, hash_head);
  77238. }
  77239. if (hash_head) hash_head = 0; /* to make compiler happy */
  77240. return Z_OK;
  77241. }
  77242. int ZEXPORT deflateReset (z_streamp strm)
  77243. {
  77244. deflate_state *s;
  77245. if (strm == Z_NULL || strm->state == Z_NULL ||
  77246. strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0) {
  77247. return Z_STREAM_ERROR;
  77248. }
  77249. strm->total_in = strm->total_out = 0;
  77250. strm->msg = Z_NULL; /* use zfree if we ever allocate msg dynamically */
  77251. strm->data_type = Z_UNKNOWN;
  77252. s = (deflate_state *)strm->state;
  77253. s->pending = 0;
  77254. s->pending_out = s->pending_buf;
  77255. if (s->wrap < 0) {
  77256. s->wrap = -s->wrap; /* was made negative by deflate(..., Z_FINISH); */
  77257. }
  77258. s->status = s->wrap ? INIT_STATE : BUSY_STATE;
  77259. strm->adler =
  77260. #ifdef GZIP
  77261. s->wrap == 2 ? crc32(0L, Z_NULL, 0) :
  77262. #endif
  77263. adler32(0L, Z_NULL, 0);
  77264. s->last_flush = Z_NO_FLUSH;
  77265. _tr_init(s);
  77266. lm_init(s);
  77267. return Z_OK;
  77268. }
  77269. int ZEXPORT deflateSetHeader (z_streamp strm, gz_headerp head)
  77270. {
  77271. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  77272. if (strm->state->wrap != 2) return Z_STREAM_ERROR;
  77273. strm->state->gzhead = head;
  77274. return Z_OK;
  77275. }
  77276. int ZEXPORT deflatePrime (z_streamp strm, int bits, int value)
  77277. {
  77278. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  77279. strm->state->bi_valid = bits;
  77280. strm->state->bi_buf = (ush)(value & ((1 << bits) - 1));
  77281. return Z_OK;
  77282. }
  77283. int ZEXPORT deflateParams (z_streamp strm, int level, int strategy)
  77284. {
  77285. deflate_state *s;
  77286. compress_func func;
  77287. int err = Z_OK;
  77288. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  77289. s = strm->state;
  77290. #ifdef FASTEST
  77291. if (level != 0) level = 1;
  77292. #else
  77293. if (level == Z_DEFAULT_COMPRESSION) level = 6;
  77294. #endif
  77295. if (level < 0 || level > 9 || strategy < 0 || strategy > Z_FIXED) {
  77296. return Z_STREAM_ERROR;
  77297. }
  77298. func = configuration_table[s->level].func;
  77299. if (func != configuration_table[level].func && strm->total_in != 0) {
  77300. err = deflate(strm, Z_PARTIAL_FLUSH);
  77301. }
  77302. if (s->level != level) {
  77303. s->level = level;
  77304. s->max_lazy_match = configuration_table[level].max_lazy;
  77305. s->good_match = configuration_table[level].good_length;
  77306. s->nice_match = configuration_table[level].nice_length;
  77307. s->max_chain_length = configuration_table[level].max_chain;
  77308. }
  77309. s->strategy = strategy;
  77310. return err;
  77311. }
  77312. int ZEXPORT deflateTune (z_streamp strm, int good_length, int max_lazy, int nice_length, int max_chain)
  77313. {
  77314. deflate_state *s;
  77315. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  77316. s = strm->state;
  77317. s->good_match = good_length;
  77318. s->max_lazy_match = max_lazy;
  77319. s->nice_match = nice_length;
  77320. s->max_chain_length = max_chain;
  77321. return Z_OK;
  77322. }
  77323. uLong ZEXPORT deflateBound (z_streamp strm, uLong sourceLen)
  77324. {
  77325. deflate_state *s;
  77326. uLong destLen;
  77327. destLen = sourceLen +
  77328. ((sourceLen + 7) >> 3) + ((sourceLen + 63) >> 6) + 11;
  77329. if (strm == Z_NULL || strm->state == Z_NULL)
  77330. return destLen;
  77331. s = strm->state;
  77332. if (s->w_bits != 15 || s->hash_bits != 8 + 7)
  77333. return destLen;
  77334. return compressBound(sourceLen);
  77335. }
  77336. local void putShortMSB (deflate_state *s, uInt b)
  77337. {
  77338. put_byte(s, (Byte)(b >> 8));
  77339. put_byte(s, (Byte)(b & 0xff));
  77340. }
  77341. local void flush_pending (z_streamp strm)
  77342. {
  77343. unsigned len = strm->state->pending;
  77344. if (len > strm->avail_out) len = strm->avail_out;
  77345. if (len == 0) return;
  77346. zmemcpy(strm->next_out, strm->state->pending_out, len);
  77347. strm->next_out += len;
  77348. strm->state->pending_out += len;
  77349. strm->total_out += len;
  77350. strm->avail_out -= len;
  77351. strm->state->pending -= len;
  77352. if (strm->state->pending == 0) {
  77353. strm->state->pending_out = strm->state->pending_buf;
  77354. }
  77355. }
  77356. int ZEXPORT deflate (z_streamp strm, int flush)
  77357. {
  77358. int old_flush; /* value of flush param for previous deflate call */
  77359. deflate_state *s;
  77360. if (strm == Z_NULL || strm->state == Z_NULL ||
  77361. flush > Z_FINISH || flush < 0) {
  77362. return Z_STREAM_ERROR;
  77363. }
  77364. s = strm->state;
  77365. if (strm->next_out == Z_NULL ||
  77366. (strm->next_in == Z_NULL && strm->avail_in != 0) ||
  77367. (s->status == FINISH_STATE && flush != Z_FINISH)) {
  77368. ERR_RETURN(strm, Z_STREAM_ERROR);
  77369. }
  77370. if (strm->avail_out == 0) ERR_RETURN(strm, Z_BUF_ERROR);
  77371. s->strm = strm; /* just in case */
  77372. old_flush = s->last_flush;
  77373. s->last_flush = flush;
  77374. if (s->status == INIT_STATE) {
  77375. #ifdef GZIP
  77376. if (s->wrap == 2) {
  77377. strm->adler = crc32(0L, Z_NULL, 0);
  77378. put_byte(s, 31);
  77379. put_byte(s, 139);
  77380. put_byte(s, 8);
  77381. if (s->gzhead == NULL) {
  77382. put_byte(s, 0);
  77383. put_byte(s, 0);
  77384. put_byte(s, 0);
  77385. put_byte(s, 0);
  77386. put_byte(s, 0);
  77387. put_byte(s, s->level == 9 ? 2 :
  77388. (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?
  77389. 4 : 0));
  77390. put_byte(s, OS_CODE);
  77391. s->status = BUSY_STATE;
  77392. }
  77393. else {
  77394. put_byte(s, (s->gzhead->text ? 1 : 0) +
  77395. (s->gzhead->hcrc ? 2 : 0) +
  77396. (s->gzhead->extra == Z_NULL ? 0 : 4) +
  77397. (s->gzhead->name == Z_NULL ? 0 : 8) +
  77398. (s->gzhead->comment == Z_NULL ? 0 : 16)
  77399. );
  77400. put_byte(s, (Byte)(s->gzhead->time & 0xff));
  77401. put_byte(s, (Byte)((s->gzhead->time >> 8) & 0xff));
  77402. put_byte(s, (Byte)((s->gzhead->time >> 16) & 0xff));
  77403. put_byte(s, (Byte)((s->gzhead->time >> 24) & 0xff));
  77404. put_byte(s, s->level == 9 ? 2 :
  77405. (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?
  77406. 4 : 0));
  77407. put_byte(s, s->gzhead->os & 0xff);
  77408. if (s->gzhead->extra != NULL) {
  77409. put_byte(s, s->gzhead->extra_len & 0xff);
  77410. put_byte(s, (s->gzhead->extra_len >> 8) & 0xff);
  77411. }
  77412. if (s->gzhead->hcrc)
  77413. strm->adler = crc32(strm->adler, s->pending_buf,
  77414. s->pending);
  77415. s->gzindex = 0;
  77416. s->status = EXTRA_STATE;
  77417. }
  77418. }
  77419. else
  77420. #endif
  77421. {
  77422. uInt header = (Z_DEFLATED + ((s->w_bits-8)<<4)) << 8;
  77423. uInt level_flags;
  77424. if (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2)
  77425. level_flags = 0;
  77426. else if (s->level < 6)
  77427. level_flags = 1;
  77428. else if (s->level == 6)
  77429. level_flags = 2;
  77430. else
  77431. level_flags = 3;
  77432. header |= (level_flags << 6);
  77433. if (s->strstart != 0) header |= PRESET_DICT;
  77434. header += 31 - (header % 31);
  77435. s->status = BUSY_STATE;
  77436. putShortMSB(s, header);
  77437. if (s->strstart != 0) {
  77438. putShortMSB(s, (uInt)(strm->adler >> 16));
  77439. putShortMSB(s, (uInt)(strm->adler & 0xffff));
  77440. }
  77441. strm->adler = adler32(0L, Z_NULL, 0);
  77442. }
  77443. }
  77444. #ifdef GZIP
  77445. if (s->status == EXTRA_STATE) {
  77446. if (s->gzhead->extra != NULL) {
  77447. uInt beg = s->pending; /* start of bytes to update crc */
  77448. while (s->gzindex < (s->gzhead->extra_len & 0xffff)) {
  77449. if (s->pending == s->pending_buf_size) {
  77450. if (s->gzhead->hcrc && s->pending > beg)
  77451. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  77452. s->pending - beg);
  77453. flush_pending(strm);
  77454. beg = s->pending;
  77455. if (s->pending == s->pending_buf_size)
  77456. break;
  77457. }
  77458. put_byte(s, s->gzhead->extra[s->gzindex]);
  77459. s->gzindex++;
  77460. }
  77461. if (s->gzhead->hcrc && s->pending > beg)
  77462. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  77463. s->pending - beg);
  77464. if (s->gzindex == s->gzhead->extra_len) {
  77465. s->gzindex = 0;
  77466. s->status = NAME_STATE;
  77467. }
  77468. }
  77469. else
  77470. s->status = NAME_STATE;
  77471. }
  77472. if (s->status == NAME_STATE) {
  77473. if (s->gzhead->name != NULL) {
  77474. uInt beg = s->pending; /* start of bytes to update crc */
  77475. int val;
  77476. do {
  77477. if (s->pending == s->pending_buf_size) {
  77478. if (s->gzhead->hcrc && s->pending > beg)
  77479. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  77480. s->pending - beg);
  77481. flush_pending(strm);
  77482. beg = s->pending;
  77483. if (s->pending == s->pending_buf_size) {
  77484. val = 1;
  77485. break;
  77486. }
  77487. }
  77488. val = s->gzhead->name[s->gzindex++];
  77489. put_byte(s, val);
  77490. } while (val != 0);
  77491. if (s->gzhead->hcrc && s->pending > beg)
  77492. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  77493. s->pending - beg);
  77494. if (val == 0) {
  77495. s->gzindex = 0;
  77496. s->status = COMMENT_STATE;
  77497. }
  77498. }
  77499. else
  77500. s->status = COMMENT_STATE;
  77501. }
  77502. if (s->status == COMMENT_STATE) {
  77503. if (s->gzhead->comment != NULL) {
  77504. uInt beg = s->pending; /* start of bytes to update crc */
  77505. int val;
  77506. do {
  77507. if (s->pending == s->pending_buf_size) {
  77508. if (s->gzhead->hcrc && s->pending > beg)
  77509. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  77510. s->pending - beg);
  77511. flush_pending(strm);
  77512. beg = s->pending;
  77513. if (s->pending == s->pending_buf_size) {
  77514. val = 1;
  77515. break;
  77516. }
  77517. }
  77518. val = s->gzhead->comment[s->gzindex++];
  77519. put_byte(s, val);
  77520. } while (val != 0);
  77521. if (s->gzhead->hcrc && s->pending > beg)
  77522. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  77523. s->pending - beg);
  77524. if (val == 0)
  77525. s->status = HCRC_STATE;
  77526. }
  77527. else
  77528. s->status = HCRC_STATE;
  77529. }
  77530. if (s->status == HCRC_STATE) {
  77531. if (s->gzhead->hcrc) {
  77532. if (s->pending + 2 > s->pending_buf_size)
  77533. flush_pending(strm);
  77534. if (s->pending + 2 <= s->pending_buf_size) {
  77535. put_byte(s, (Byte)(strm->adler & 0xff));
  77536. put_byte(s, (Byte)((strm->adler >> 8) & 0xff));
  77537. strm->adler = crc32(0L, Z_NULL, 0);
  77538. s->status = BUSY_STATE;
  77539. }
  77540. }
  77541. else
  77542. s->status = BUSY_STATE;
  77543. }
  77544. #endif
  77545. if (s->pending != 0) {
  77546. flush_pending(strm);
  77547. if (strm->avail_out == 0) {
  77548. s->last_flush = -1;
  77549. return Z_OK;
  77550. }
  77551. } else if (strm->avail_in == 0 && flush <= old_flush &&
  77552. flush != Z_FINISH) {
  77553. ERR_RETURN(strm, Z_BUF_ERROR);
  77554. }
  77555. if (s->status == FINISH_STATE && strm->avail_in != 0) {
  77556. ERR_RETURN(strm, Z_BUF_ERROR);
  77557. }
  77558. if (strm->avail_in != 0 || s->lookahead != 0 ||
  77559. (flush != Z_NO_FLUSH && s->status != FINISH_STATE)) {
  77560. block_state bstate;
  77561. bstate = (*(configuration_table[s->level].func))(s, flush);
  77562. if (bstate == finish_started || bstate == finish_done) {
  77563. s->status = FINISH_STATE;
  77564. }
  77565. if (bstate == need_more || bstate == finish_started) {
  77566. if (strm->avail_out == 0) {
  77567. s->last_flush = -1; /* avoid BUF_ERROR next call, see above */
  77568. }
  77569. return Z_OK;
  77570. }
  77571. if (bstate == block_done) {
  77572. if (flush == Z_PARTIAL_FLUSH) {
  77573. _tr_align(s);
  77574. } else { /* FULL_FLUSH or SYNC_FLUSH */
  77575. _tr_stored_block(s, (char*)0, 0L, 0);
  77576. if (flush == Z_FULL_FLUSH) {
  77577. CLEAR_HASH(s); /* forget history */
  77578. }
  77579. }
  77580. flush_pending(strm);
  77581. if (strm->avail_out == 0) {
  77582. s->last_flush = -1; /* avoid BUF_ERROR at next call, see above */
  77583. return Z_OK;
  77584. }
  77585. }
  77586. }
  77587. Assert(strm->avail_out > 0, "bug2");
  77588. if (flush != Z_FINISH) return Z_OK;
  77589. if (s->wrap <= 0) return Z_STREAM_END;
  77590. #ifdef GZIP
  77591. if (s->wrap == 2) {
  77592. put_byte(s, (Byte)(strm->adler & 0xff));
  77593. put_byte(s, (Byte)((strm->adler >> 8) & 0xff));
  77594. put_byte(s, (Byte)((strm->adler >> 16) & 0xff));
  77595. put_byte(s, (Byte)((strm->adler >> 24) & 0xff));
  77596. put_byte(s, (Byte)(strm->total_in & 0xff));
  77597. put_byte(s, (Byte)((strm->total_in >> 8) & 0xff));
  77598. put_byte(s, (Byte)((strm->total_in >> 16) & 0xff));
  77599. put_byte(s, (Byte)((strm->total_in >> 24) & 0xff));
  77600. }
  77601. else
  77602. #endif
  77603. {
  77604. putShortMSB(s, (uInt)(strm->adler >> 16));
  77605. putShortMSB(s, (uInt)(strm->adler & 0xffff));
  77606. }
  77607. flush_pending(strm);
  77608. if (s->wrap > 0) s->wrap = -s->wrap; /* write the trailer only once! */
  77609. return s->pending != 0 ? Z_OK : Z_STREAM_END;
  77610. }
  77611. int ZEXPORT deflateEnd (z_streamp strm)
  77612. {
  77613. int status;
  77614. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  77615. status = strm->state->status;
  77616. if (status != INIT_STATE &&
  77617. status != EXTRA_STATE &&
  77618. status != NAME_STATE &&
  77619. status != COMMENT_STATE &&
  77620. status != HCRC_STATE &&
  77621. status != BUSY_STATE &&
  77622. status != FINISH_STATE) {
  77623. return Z_STREAM_ERROR;
  77624. }
  77625. TRY_FREE(strm, strm->state->pending_buf);
  77626. TRY_FREE(strm, strm->state->head);
  77627. TRY_FREE(strm, strm->state->prev);
  77628. TRY_FREE(strm, strm->state->window);
  77629. ZFREE(strm, strm->state);
  77630. strm->state = Z_NULL;
  77631. return status == BUSY_STATE ? Z_DATA_ERROR : Z_OK;
  77632. }
  77633. int ZEXPORT deflateCopy (z_streamp dest, z_streamp source)
  77634. {
  77635. #ifdef MAXSEG_64K
  77636. return Z_STREAM_ERROR;
  77637. #else
  77638. deflate_state *ds;
  77639. deflate_state *ss;
  77640. ushf *overlay;
  77641. if (source == Z_NULL || dest == Z_NULL || source->state == Z_NULL) {
  77642. return Z_STREAM_ERROR;
  77643. }
  77644. ss = source->state;
  77645. zmemcpy(dest, source, sizeof(z_stream));
  77646. ds = (deflate_state *) ZALLOC(dest, 1, sizeof(deflate_state));
  77647. if (ds == Z_NULL) return Z_MEM_ERROR;
  77648. dest->state = (struct internal_state FAR *) ds;
  77649. zmemcpy(ds, ss, sizeof(deflate_state));
  77650. ds->strm = dest;
  77651. ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte));
  77652. ds->prev = (Posf *) ZALLOC(dest, ds->w_size, sizeof(Pos));
  77653. ds->head = (Posf *) ZALLOC(dest, ds->hash_size, sizeof(Pos));
  77654. overlay = (ushf *) ZALLOC(dest, ds->lit_bufsize, sizeof(ush)+2);
  77655. ds->pending_buf = (uchf *) overlay;
  77656. if (ds->window == Z_NULL || ds->prev == Z_NULL || ds->head == Z_NULL ||
  77657. ds->pending_buf == Z_NULL) {
  77658. deflateEnd (dest);
  77659. return Z_MEM_ERROR;
  77660. }
  77661. zmemcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(Byte));
  77662. zmemcpy(ds->prev, ss->prev, ds->w_size * sizeof(Pos));
  77663. zmemcpy(ds->head, ss->head, ds->hash_size * sizeof(Pos));
  77664. zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size);
  77665. ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf);
  77666. ds->d_buf = overlay + ds->lit_bufsize/sizeof(ush);
  77667. ds->l_buf = ds->pending_buf + (1+sizeof(ush))*ds->lit_bufsize;
  77668. ds->l_desc.dyn_tree = ds->dyn_ltree;
  77669. ds->d_desc.dyn_tree = ds->dyn_dtree;
  77670. ds->bl_desc.dyn_tree = ds->bl_tree;
  77671. return Z_OK;
  77672. #endif /* MAXSEG_64K */
  77673. }
  77674. local int read_buf (z_streamp strm, Bytef *buf, unsigned size)
  77675. {
  77676. unsigned len = strm->avail_in;
  77677. if (len > size) len = size;
  77678. if (len == 0) return 0;
  77679. strm->avail_in -= len;
  77680. if (strm->state->wrap == 1) {
  77681. strm->adler = adler32(strm->adler, strm->next_in, len);
  77682. }
  77683. #ifdef GZIP
  77684. else if (strm->state->wrap == 2) {
  77685. strm->adler = crc32(strm->adler, strm->next_in, len);
  77686. }
  77687. #endif
  77688. zmemcpy(buf, strm->next_in, len);
  77689. strm->next_in += len;
  77690. strm->total_in += len;
  77691. return (int)len;
  77692. }
  77693. local void lm_init (deflate_state *s)
  77694. {
  77695. s->window_size = (ulg)2L*s->w_size;
  77696. CLEAR_HASH(s);
  77697. s->max_lazy_match = configuration_table[s->level].max_lazy;
  77698. s->good_match = configuration_table[s->level].good_length;
  77699. s->nice_match = configuration_table[s->level].nice_length;
  77700. s->max_chain_length = configuration_table[s->level].max_chain;
  77701. s->strstart = 0;
  77702. s->block_start = 0L;
  77703. s->lookahead = 0;
  77704. s->match_length = s->prev_length = MIN_MATCH-1;
  77705. s->match_available = 0;
  77706. s->ins_h = 0;
  77707. #ifndef FASTEST
  77708. #ifdef ASMV
  77709. match_init(); /* initialize the asm code */
  77710. #endif
  77711. #endif
  77712. }
  77713. #ifndef FASTEST
  77714. #ifndef ASMV
  77715. local uInt longest_match(deflate_state *s, IPos cur_match)
  77716. {
  77717. unsigned chain_length = s->max_chain_length;/* max hash chain length */
  77718. register Bytef *scan = s->window + s->strstart; /* current string */
  77719. register Bytef *match; /* matched string */
  77720. register int len; /* length of current match */
  77721. int best_len = s->prev_length; /* best match length so far */
  77722. int nice_match = s->nice_match; /* stop if match long enough */
  77723. IPos limit = s->strstart > (IPos)MAX_DIST(s) ?
  77724. s->strstart - (IPos)MAX_DIST(s) : NIL;
  77725. Posf *prev = s->prev;
  77726. uInt wmask = s->w_mask;
  77727. #ifdef UNALIGNED_OK
  77728. register Bytef *strend = s->window + s->strstart + MAX_MATCH - 1;
  77729. register ush scan_start = *(ushf*)scan;
  77730. register ush scan_end = *(ushf*)(scan+best_len-1);
  77731. #else
  77732. register Bytef *strend = s->window + s->strstart + MAX_MATCH;
  77733. register Byte scan_end1 = scan[best_len-1];
  77734. register Byte scan_end = scan[best_len];
  77735. #endif
  77736. Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
  77737. if (s->prev_length >= s->good_match) {
  77738. chain_length >>= 2;
  77739. }
  77740. if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead;
  77741. Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
  77742. do {
  77743. Assert(cur_match < s->strstart, "no future");
  77744. match = s->window + cur_match;
  77745. #if (defined(UNALIGNED_OK) && MAX_MATCH == 258)
  77746. if (*(ushf*)(match+best_len-1) != scan_end ||
  77747. *(ushf*)match != scan_start) continue;
  77748. Assert(scan[2] == match[2], "scan[2]?");
  77749. scan++, match++;
  77750. do {
  77751. } while (*(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  77752. *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  77753. *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  77754. *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  77755. scan < strend);
  77756. Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
  77757. if (*scan == *match) scan++;
  77758. len = (MAX_MATCH - 1) - (int)(strend-scan);
  77759. scan = strend - (MAX_MATCH-1);
  77760. #else /* UNALIGNED_OK */
  77761. if (match[best_len] != scan_end ||
  77762. match[best_len-1] != scan_end1 ||
  77763. *match != *scan ||
  77764. *++match != scan[1]) continue;
  77765. scan += 2, match++;
  77766. Assert(*scan == *match, "match[2]?");
  77767. do {
  77768. } while (*++scan == *++match && *++scan == *++match &&
  77769. *++scan == *++match && *++scan == *++match &&
  77770. *++scan == *++match && *++scan == *++match &&
  77771. *++scan == *++match && *++scan == *++match &&
  77772. scan < strend);
  77773. Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
  77774. len = MAX_MATCH - (int)(strend - scan);
  77775. scan = strend - MAX_MATCH;
  77776. #endif /* UNALIGNED_OK */
  77777. if (len > best_len) {
  77778. s->match_start = cur_match;
  77779. best_len = len;
  77780. if (len >= nice_match) break;
  77781. #ifdef UNALIGNED_OK
  77782. scan_end = *(ushf*)(scan+best_len-1);
  77783. #else
  77784. scan_end1 = scan[best_len-1];
  77785. scan_end = scan[best_len];
  77786. #endif
  77787. }
  77788. } while ((cur_match = prev[cur_match & wmask]) > limit
  77789. && --chain_length != 0);
  77790. if ((uInt)best_len <= s->lookahead) return (uInt)best_len;
  77791. return s->lookahead;
  77792. }
  77793. #endif /* ASMV */
  77794. #endif /* FASTEST */
  77795. local uInt longest_match_fast (deflate_state *s, IPos cur_match)
  77796. {
  77797. register Bytef *scan = s->window + s->strstart; /* current string */
  77798. register Bytef *match; /* matched string */
  77799. register int len; /* length of current match */
  77800. register Bytef *strend = s->window + s->strstart + MAX_MATCH;
  77801. Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
  77802. Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
  77803. Assert(cur_match < s->strstart, "no future");
  77804. match = s->window + cur_match;
  77805. if (match[0] != scan[0] || match[1] != scan[1]) return MIN_MATCH-1;
  77806. scan += 2, match += 2;
  77807. Assert(*scan == *match, "match[2]?");
  77808. do {
  77809. } while (*++scan == *++match && *++scan == *++match &&
  77810. *++scan == *++match && *++scan == *++match &&
  77811. *++scan == *++match && *++scan == *++match &&
  77812. *++scan == *++match && *++scan == *++match &&
  77813. scan < strend);
  77814. Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
  77815. len = MAX_MATCH - (int)(strend - scan);
  77816. if (len < MIN_MATCH) return MIN_MATCH - 1;
  77817. s->match_start = cur_match;
  77818. return (uInt)len <= s->lookahead ? (uInt)len : s->lookahead;
  77819. }
  77820. #ifdef DEBUG
  77821. local void check_match(deflate_state *s, IPos start, IPos match, int length)
  77822. {
  77823. if (zmemcmp(s->window + match,
  77824. s->window + start, length) != EQUAL) {
  77825. fprintf(stderr, " start %u, match %u, length %d\n",
  77826. start, match, length);
  77827. do {
  77828. fprintf(stderr, "%c%c", s->window[match++], s->window[start++]);
  77829. } while (--length != 0);
  77830. z_error("invalid match");
  77831. }
  77832. if (z_verbose > 1) {
  77833. fprintf(stderr,"\\[%d,%d]", start-match, length);
  77834. do { putc(s->window[start++], stderr); } while (--length != 0);
  77835. }
  77836. }
  77837. #else
  77838. # define check_match(s, start, match, length)
  77839. #endif /* DEBUG */
  77840. local void fill_window (deflate_state *s)
  77841. {
  77842. register unsigned n, m;
  77843. register Posf *p;
  77844. unsigned more; /* Amount of free space at the end of the window. */
  77845. uInt wsize = s->w_size;
  77846. do {
  77847. more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart);
  77848. if (sizeof(int) <= 2) {
  77849. if (more == 0 && s->strstart == 0 && s->lookahead == 0) {
  77850. more = wsize;
  77851. } else if (more == (unsigned)(-1)) {
  77852. more--;
  77853. }
  77854. }
  77855. if (s->strstart >= wsize+MAX_DIST(s)) {
  77856. zmemcpy(s->window, s->window+wsize, (unsigned)wsize);
  77857. s->match_start -= wsize;
  77858. s->strstart -= wsize; /* we now have strstart >= MAX_DIST */
  77859. s->block_start -= (long) wsize;
  77860. n = s->hash_size;
  77861. p = &s->head[n];
  77862. do {
  77863. m = *--p;
  77864. *p = (Pos)(m >= wsize ? m-wsize : NIL);
  77865. } while (--n);
  77866. n = wsize;
  77867. #ifndef FASTEST
  77868. p = &s->prev[n];
  77869. do {
  77870. m = *--p;
  77871. *p = (Pos)(m >= wsize ? m-wsize : NIL);
  77872. } while (--n);
  77873. #endif
  77874. more += wsize;
  77875. }
  77876. if (s->strm->avail_in == 0) return;
  77877. Assert(more >= 2, "more < 2");
  77878. n = read_buf(s->strm, s->window + s->strstart + s->lookahead, more);
  77879. s->lookahead += n;
  77880. if (s->lookahead >= MIN_MATCH) {
  77881. s->ins_h = s->window[s->strstart];
  77882. UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]);
  77883. #if MIN_MATCH != 3
  77884. Call UPDATE_HASH() MIN_MATCH-3 more times
  77885. #endif
  77886. }
  77887. } while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0);
  77888. }
  77889. #define FLUSH_BLOCK_ONLY(s, eof) { \
  77890. _tr_flush_block(s, (s->block_start >= 0L ? \
  77891. (charf *)&s->window[(unsigned)s->block_start] : \
  77892. (charf *)Z_NULL), \
  77893. (ulg)((long)s->strstart - s->block_start), \
  77894. (eof)); \
  77895. s->block_start = s->strstart; \
  77896. flush_pending(s->strm); \
  77897. Tracev((stderr,"[FLUSH]")); \
  77898. }
  77899. #define FLUSH_BLOCK(s, eof) { \
  77900. FLUSH_BLOCK_ONLY(s, eof); \
  77901. if (s->strm->avail_out == 0) return (eof) ? finish_started : need_more; \
  77902. }
  77903. local block_state deflate_stored(deflate_state *s, int flush)
  77904. {
  77905. ulg max_block_size = 0xffff;
  77906. ulg max_start;
  77907. if (max_block_size > s->pending_buf_size - 5) {
  77908. max_block_size = s->pending_buf_size - 5;
  77909. }
  77910. for (;;) {
  77911. if (s->lookahead <= 1) {
  77912. Assert(s->strstart < s->w_size+MAX_DIST(s) ||
  77913. s->block_start >= (long)s->w_size, "slide too late");
  77914. fill_window(s);
  77915. if (s->lookahead == 0 && flush == Z_NO_FLUSH) return need_more;
  77916. if (s->lookahead == 0) break; /* flush the current block */
  77917. }
  77918. Assert(s->block_start >= 0L, "block gone");
  77919. s->strstart += s->lookahead;
  77920. s->lookahead = 0;
  77921. max_start = s->block_start + max_block_size;
  77922. if (s->strstart == 0 || (ulg)s->strstart >= max_start) {
  77923. s->lookahead = (uInt)(s->strstart - max_start);
  77924. s->strstart = (uInt)max_start;
  77925. FLUSH_BLOCK(s, 0);
  77926. }
  77927. if (s->strstart - (uInt)s->block_start >= MAX_DIST(s)) {
  77928. FLUSH_BLOCK(s, 0);
  77929. }
  77930. }
  77931. FLUSH_BLOCK(s, flush == Z_FINISH);
  77932. return flush == Z_FINISH ? finish_done : block_done;
  77933. }
  77934. local block_state deflate_fast(deflate_state *s, int flush)
  77935. {
  77936. IPos hash_head = NIL; /* head of the hash chain */
  77937. int bflush; /* set if current block must be flushed */
  77938. for (;;) {
  77939. if (s->lookahead < MIN_LOOKAHEAD) {
  77940. fill_window(s);
  77941. if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {
  77942. return need_more;
  77943. }
  77944. if (s->lookahead == 0) break; /* flush the current block */
  77945. }
  77946. if (s->lookahead >= MIN_MATCH) {
  77947. INSERT_STRING(s, s->strstart, hash_head);
  77948. }
  77949. if (hash_head != NIL && s->strstart - hash_head <= MAX_DIST(s)) {
  77950. #ifdef FASTEST
  77951. if ((s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) ||
  77952. (s->strategy == Z_RLE && s->strstart - hash_head == 1)) {
  77953. s->match_length = longest_match_fast (s, hash_head);
  77954. }
  77955. #else
  77956. if (s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) {
  77957. s->match_length = longest_match (s, hash_head);
  77958. } else if (s->strategy == Z_RLE && s->strstart - hash_head == 1) {
  77959. s->match_length = longest_match_fast (s, hash_head);
  77960. }
  77961. #endif
  77962. }
  77963. if (s->match_length >= MIN_MATCH) {
  77964. check_match(s, s->strstart, s->match_start, s->match_length);
  77965. _tr_tally_dist(s, s->strstart - s->match_start,
  77966. s->match_length - MIN_MATCH, bflush);
  77967. s->lookahead -= s->match_length;
  77968. #ifndef FASTEST
  77969. if (s->match_length <= s->max_insert_length &&
  77970. s->lookahead >= MIN_MATCH) {
  77971. s->match_length--; /* string at strstart already in table */
  77972. do {
  77973. s->strstart++;
  77974. INSERT_STRING(s, s->strstart, hash_head);
  77975. } while (--s->match_length != 0);
  77976. s->strstart++;
  77977. } else
  77978. #endif
  77979. {
  77980. s->strstart += s->match_length;
  77981. s->match_length = 0;
  77982. s->ins_h = s->window[s->strstart];
  77983. UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]);
  77984. #if MIN_MATCH != 3
  77985. Call UPDATE_HASH() MIN_MATCH-3 more times
  77986. #endif
  77987. }
  77988. } else {
  77989. Tracevv((stderr,"%c", s->window[s->strstart]));
  77990. _tr_tally_lit (s, s->window[s->strstart], bflush);
  77991. s->lookahead--;
  77992. s->strstart++;
  77993. }
  77994. if (bflush) FLUSH_BLOCK(s, 0);
  77995. }
  77996. FLUSH_BLOCK(s, flush == Z_FINISH);
  77997. return flush == Z_FINISH ? finish_done : block_done;
  77998. }
  77999. #ifndef FASTEST
  78000. local block_state deflate_slow(deflate_state *s, int flush)
  78001. {
  78002. IPos hash_head = NIL; /* head of hash chain */
  78003. int bflush; /* set if current block must be flushed */
  78004. for (;;) {
  78005. if (s->lookahead < MIN_LOOKAHEAD) {
  78006. fill_window(s);
  78007. if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {
  78008. return need_more;
  78009. }
  78010. if (s->lookahead == 0) break; /* flush the current block */
  78011. }
  78012. if (s->lookahead >= MIN_MATCH) {
  78013. INSERT_STRING(s, s->strstart, hash_head);
  78014. }
  78015. s->prev_length = s->match_length, s->prev_match = s->match_start;
  78016. s->match_length = MIN_MATCH-1;
  78017. if (hash_head != NIL && s->prev_length < s->max_lazy_match &&
  78018. s->strstart - hash_head <= MAX_DIST(s)) {
  78019. if (s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) {
  78020. s->match_length = longest_match (s, hash_head);
  78021. } else if (s->strategy == Z_RLE && s->strstart - hash_head == 1) {
  78022. s->match_length = longest_match_fast (s, hash_head);
  78023. }
  78024. if (s->match_length <= 5 && (s->strategy == Z_FILTERED
  78025. #if TOO_FAR <= 32767
  78026. || (s->match_length == MIN_MATCH &&
  78027. s->strstart - s->match_start > TOO_FAR)
  78028. #endif
  78029. )) {
  78030. s->match_length = MIN_MATCH-1;
  78031. }
  78032. }
  78033. if (s->prev_length >= MIN_MATCH && s->match_length <= s->prev_length) {
  78034. uInt max_insert = s->strstart + s->lookahead - MIN_MATCH;
  78035. check_match(s, s->strstart-1, s->prev_match, s->prev_length);
  78036. _tr_tally_dist(s, s->strstart -1 - s->prev_match,
  78037. s->prev_length - MIN_MATCH, bflush);
  78038. s->lookahead -= s->prev_length-1;
  78039. s->prev_length -= 2;
  78040. do {
  78041. if (++s->strstart <= max_insert) {
  78042. INSERT_STRING(s, s->strstart, hash_head);
  78043. }
  78044. } while (--s->prev_length != 0);
  78045. s->match_available = 0;
  78046. s->match_length = MIN_MATCH-1;
  78047. s->strstart++;
  78048. if (bflush) FLUSH_BLOCK(s, 0);
  78049. } else if (s->match_available) {
  78050. Tracevv((stderr,"%c", s->window[s->strstart-1]));
  78051. _tr_tally_lit(s, s->window[s->strstart-1], bflush);
  78052. if (bflush) {
  78053. FLUSH_BLOCK_ONLY(s, 0);
  78054. }
  78055. s->strstart++;
  78056. s->lookahead--;
  78057. if (s->strm->avail_out == 0) return need_more;
  78058. } else {
  78059. s->match_available = 1;
  78060. s->strstart++;
  78061. s->lookahead--;
  78062. }
  78063. }
  78064. Assert (flush != Z_NO_FLUSH, "no flush?");
  78065. if (s->match_available) {
  78066. Tracevv((stderr,"%c", s->window[s->strstart-1]));
  78067. _tr_tally_lit(s, s->window[s->strstart-1], bflush);
  78068. s->match_available = 0;
  78069. }
  78070. FLUSH_BLOCK(s, flush == Z_FINISH);
  78071. return flush == Z_FINISH ? finish_done : block_done;
  78072. }
  78073. #endif /* FASTEST */
  78074. #if 0
  78075. local block_state deflate_rle(s, flush)
  78076. deflate_state *s;
  78077. int flush;
  78078. {
  78079. int bflush; /* set if current block must be flushed */
  78080. uInt run; /* length of run */
  78081. uInt max; /* maximum length of run */
  78082. uInt prev; /* byte at distance one to match */
  78083. Bytef *scan; /* scan for end of run */
  78084. for (;;) {
  78085. if (s->lookahead < MAX_MATCH) {
  78086. fill_window(s);
  78087. if (s->lookahead < MAX_MATCH && flush == Z_NO_FLUSH) {
  78088. return need_more;
  78089. }
  78090. if (s->lookahead == 0) break; /* flush the current block */
  78091. }
  78092. run = 0;
  78093. if (s->strstart > 0) { /* if there is a previous byte, that is */
  78094. max = s->lookahead < MAX_MATCH ? s->lookahead : MAX_MATCH;
  78095. scan = s->window + s->strstart - 1;
  78096. prev = *scan++;
  78097. do {
  78098. if (*scan++ != prev)
  78099. break;
  78100. } while (++run < max);
  78101. }
  78102. if (run >= MIN_MATCH) {
  78103. check_match(s, s->strstart, s->strstart - 1, run);
  78104. _tr_tally_dist(s, 1, run - MIN_MATCH, bflush);
  78105. s->lookahead -= run;
  78106. s->strstart += run;
  78107. } else {
  78108. Tracevv((stderr,"%c", s->window[s->strstart]));
  78109. _tr_tally_lit (s, s->window[s->strstart], bflush);
  78110. s->lookahead--;
  78111. s->strstart++;
  78112. }
  78113. if (bflush) FLUSH_BLOCK(s, 0);
  78114. }
  78115. FLUSH_BLOCK(s, flush == Z_FINISH);
  78116. return flush == Z_FINISH ? finish_done : block_done;
  78117. }
  78118. #endif
  78119. /*** End of inlined file: deflate.c ***/
  78120. /*** Start of inlined file: inffast.c ***/
  78121. /*** Start of inlined file: inftrees.h ***/
  78122. #ifndef _INFTREES_H_
  78123. #define _INFTREES_H_
  78124. typedef struct {
  78125. unsigned char op; /* operation, extra bits, table bits */
  78126. unsigned char bits; /* bits in this part of the code */
  78127. unsigned short val; /* offset in table or code value */
  78128. } code;
  78129. #define ENOUGH 2048
  78130. #define MAXD 592
  78131. typedef enum {
  78132. CODES,
  78133. LENS,
  78134. DISTS
  78135. } codetype;
  78136. extern int inflate_table OF((codetype type, unsigned short FAR *lens,
  78137. unsigned codes, code FAR * FAR *table,
  78138. unsigned FAR *bits, unsigned short FAR *work));
  78139. #endif
  78140. /*** End of inlined file: inftrees.h ***/
  78141. /*** Start of inlined file: inflate.h ***/
  78142. #ifndef _INFLATE_H_
  78143. #define _INFLATE_H_
  78144. #ifndef NO_GZIP
  78145. # define GUNZIP
  78146. #endif
  78147. typedef enum {
  78148. HEAD, /* i: waiting for magic header */
  78149. FLAGS, /* i: waiting for method and flags (gzip) */
  78150. TIME, /* i: waiting for modification time (gzip) */
  78151. OS, /* i: waiting for extra flags and operating system (gzip) */
  78152. EXLEN, /* i: waiting for extra length (gzip) */
  78153. EXTRA, /* i: waiting for extra bytes (gzip) */
  78154. NAME, /* i: waiting for end of file name (gzip) */
  78155. COMMENT, /* i: waiting for end of comment (gzip) */
  78156. HCRC, /* i: waiting for header crc (gzip) */
  78157. DICTID, /* i: waiting for dictionary check value */
  78158. DICT, /* waiting for inflateSetDictionary() call */
  78159. TYPE, /* i: waiting for type bits, including last-flag bit */
  78160. TYPEDO, /* i: same, but skip check to exit inflate on new block */
  78161. STORED, /* i: waiting for stored size (length and complement) */
  78162. COPY, /* i/o: waiting for input or output to copy stored block */
  78163. TABLE, /* i: waiting for dynamic block table lengths */
  78164. LENLENS, /* i: waiting for code length code lengths */
  78165. CODELENS, /* i: waiting for length/lit and distance code lengths */
  78166. LEN, /* i: waiting for length/lit code */
  78167. LENEXT, /* i: waiting for length extra bits */
  78168. DIST, /* i: waiting for distance code */
  78169. DISTEXT, /* i: waiting for distance extra bits */
  78170. MATCH, /* o: waiting for output space to copy string */
  78171. LIT, /* o: waiting for output space to write literal */
  78172. CHECK, /* i: waiting for 32-bit check value */
  78173. LENGTH, /* i: waiting for 32-bit length (gzip) */
  78174. DONE, /* finished check, done -- remain here until reset */
  78175. BAD, /* got a data error -- remain here until reset */
  78176. MEM, /* got an inflate() memory error -- remain here until reset */
  78177. SYNC /* looking for synchronization bytes to restart inflate() */
  78178. } inflate_mode;
  78179. struct inflate_state {
  78180. inflate_mode mode; /* current inflate mode */
  78181. int last; /* true if processing last block */
  78182. int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
  78183. int havedict; /* true if dictionary provided */
  78184. int flags; /* gzip header method and flags (0 if zlib) */
  78185. unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */
  78186. unsigned long check; /* protected copy of check value */
  78187. unsigned long total; /* protected copy of output count */
  78188. gz_headerp head; /* where to save gzip header information */
  78189. unsigned wbits; /* log base 2 of requested window size */
  78190. unsigned wsize; /* window size or zero if not using window */
  78191. unsigned whave; /* valid bytes in the window */
  78192. unsigned write; /* window write index */
  78193. unsigned char FAR *window; /* allocated sliding window, if needed */
  78194. unsigned long hold; /* input bit accumulator */
  78195. unsigned bits; /* number of bits in "in" */
  78196. unsigned length; /* literal or length of data to copy */
  78197. unsigned offset; /* distance back to copy string from */
  78198. unsigned extra; /* extra bits needed */
  78199. code const FAR *lencode; /* starting table for length/literal codes */
  78200. code const FAR *distcode; /* starting table for distance codes */
  78201. unsigned lenbits; /* index bits for lencode */
  78202. unsigned distbits; /* index bits for distcode */
  78203. unsigned ncode; /* number of code length code lengths */
  78204. unsigned nlen; /* number of length code lengths */
  78205. unsigned ndist; /* number of distance code lengths */
  78206. unsigned have; /* number of code lengths in lens[] */
  78207. code FAR *next; /* next available space in codes[] */
  78208. unsigned short lens[320]; /* temporary storage for code lengths */
  78209. unsigned short work[288]; /* work area for code table building */
  78210. code codes[ENOUGH]; /* space for code tables */
  78211. };
  78212. #endif
  78213. /*** End of inlined file: inflate.h ***/
  78214. /*** Start of inlined file: inffast.h ***/
  78215. void inflate_fast OF((z_streamp strm, unsigned start));
  78216. /*** End of inlined file: inffast.h ***/
  78217. #ifndef ASMINF
  78218. #ifdef POSTINC
  78219. # define OFF 0
  78220. # define PUP(a) *(a)++
  78221. #else
  78222. # define OFF 1
  78223. # define PUP(a) *++(a)
  78224. #endif
  78225. void inflate_fast (z_streamp strm, unsigned start)
  78226. {
  78227. struct inflate_state FAR *state;
  78228. unsigned char FAR *in; /* local strm->next_in */
  78229. unsigned char FAR *last; /* while in < last, enough input available */
  78230. unsigned char FAR *out; /* local strm->next_out */
  78231. unsigned char FAR *beg; /* inflate()'s initial strm->next_out */
  78232. unsigned char FAR *end; /* while out < end, enough space available */
  78233. #ifdef INFLATE_STRICT
  78234. unsigned dmax; /* maximum distance from zlib header */
  78235. #endif
  78236. unsigned wsize; /* window size or zero if not using window */
  78237. unsigned whave; /* valid bytes in the window */
  78238. unsigned write; /* window write index */
  78239. unsigned char FAR *window; /* allocated sliding window, if wsize != 0 */
  78240. unsigned long hold; /* local strm->hold */
  78241. unsigned bits; /* local strm->bits */
  78242. code const FAR *lcode; /* local strm->lencode */
  78243. code const FAR *dcode; /* local strm->distcode */
  78244. unsigned lmask; /* mask for first level of length codes */
  78245. unsigned dmask; /* mask for first level of distance codes */
  78246. code thisx; /* retrieved table entry */
  78247. unsigned op; /* code bits, operation, extra bits, or */
  78248. unsigned len; /* match length, unused bytes */
  78249. unsigned dist; /* match distance */
  78250. unsigned char FAR *from; /* where to copy match from */
  78251. state = (struct inflate_state FAR *)strm->state;
  78252. in = strm->next_in - OFF;
  78253. last = in + (strm->avail_in - 5);
  78254. out = strm->next_out - OFF;
  78255. beg = out - (start - strm->avail_out);
  78256. end = out + (strm->avail_out - 257);
  78257. #ifdef INFLATE_STRICT
  78258. dmax = state->dmax;
  78259. #endif
  78260. wsize = state->wsize;
  78261. whave = state->whave;
  78262. write = state->write;
  78263. window = state->window;
  78264. hold = state->hold;
  78265. bits = state->bits;
  78266. lcode = state->lencode;
  78267. dcode = state->distcode;
  78268. lmask = (1U << state->lenbits) - 1;
  78269. dmask = (1U << state->distbits) - 1;
  78270. do {
  78271. if (bits < 15) {
  78272. hold += (unsigned long)(PUP(in)) << bits;
  78273. bits += 8;
  78274. hold += (unsigned long)(PUP(in)) << bits;
  78275. bits += 8;
  78276. }
  78277. thisx = lcode[hold & lmask];
  78278. dolen:
  78279. op = (unsigned)(thisx.bits);
  78280. hold >>= op;
  78281. bits -= op;
  78282. op = (unsigned)(thisx.op);
  78283. if (op == 0) { /* literal */
  78284. Tracevv((stderr, thisx.val >= 0x20 && thisx.val < 0x7f ?
  78285. "inflate: literal '%c'\n" :
  78286. "inflate: literal 0x%02x\n", thisx.val));
  78287. PUP(out) = (unsigned char)(thisx.val);
  78288. }
  78289. else if (op & 16) { /* length base */
  78290. len = (unsigned)(thisx.val);
  78291. op &= 15; /* number of extra bits */
  78292. if (op) {
  78293. if (bits < op) {
  78294. hold += (unsigned long)(PUP(in)) << bits;
  78295. bits += 8;
  78296. }
  78297. len += (unsigned)hold & ((1U << op) - 1);
  78298. hold >>= op;
  78299. bits -= op;
  78300. }
  78301. Tracevv((stderr, "inflate: length %u\n", len));
  78302. if (bits < 15) {
  78303. hold += (unsigned long)(PUP(in)) << bits;
  78304. bits += 8;
  78305. hold += (unsigned long)(PUP(in)) << bits;
  78306. bits += 8;
  78307. }
  78308. thisx = dcode[hold & dmask];
  78309. dodist:
  78310. op = (unsigned)(thisx.bits);
  78311. hold >>= op;
  78312. bits -= op;
  78313. op = (unsigned)(thisx.op);
  78314. if (op & 16) { /* distance base */
  78315. dist = (unsigned)(thisx.val);
  78316. op &= 15; /* number of extra bits */
  78317. if (bits < op) {
  78318. hold += (unsigned long)(PUP(in)) << bits;
  78319. bits += 8;
  78320. if (bits < op) {
  78321. hold += (unsigned long)(PUP(in)) << bits;
  78322. bits += 8;
  78323. }
  78324. }
  78325. dist += (unsigned)hold & ((1U << op) - 1);
  78326. #ifdef INFLATE_STRICT
  78327. if (dist > dmax) {
  78328. strm->msg = (char *)"invalid distance too far back";
  78329. state->mode = BAD;
  78330. break;
  78331. }
  78332. #endif
  78333. hold >>= op;
  78334. bits -= op;
  78335. Tracevv((stderr, "inflate: distance %u\n", dist));
  78336. op = (unsigned)(out - beg); /* max distance in output */
  78337. if (dist > op) { /* see if copy from window */
  78338. op = dist - op; /* distance back in window */
  78339. if (op > whave) {
  78340. strm->msg = (char *)"invalid distance too far back";
  78341. state->mode = BAD;
  78342. break;
  78343. }
  78344. from = window - OFF;
  78345. if (write == 0) { /* very common case */
  78346. from += wsize - 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. else if (write < op) { /* wrap around window */
  78356. from += wsize + write - op;
  78357. op -= write;
  78358. if (op < len) { /* some from end of window */
  78359. len -= op;
  78360. do {
  78361. PUP(out) = PUP(from);
  78362. } while (--op);
  78363. from = window - OFF;
  78364. if (write < len) { /* some from start of window */
  78365. op = write;
  78366. len -= op;
  78367. do {
  78368. PUP(out) = PUP(from);
  78369. } while (--op);
  78370. from = out - dist; /* rest from output */
  78371. }
  78372. }
  78373. }
  78374. else { /* contiguous in window */
  78375. from += write - op;
  78376. if (op < len) { /* some from window */
  78377. len -= op;
  78378. do {
  78379. PUP(out) = PUP(from);
  78380. } while (--op);
  78381. from = out - dist; /* rest from output */
  78382. }
  78383. }
  78384. while (len > 2) {
  78385. PUP(out) = PUP(from);
  78386. PUP(out) = PUP(from);
  78387. PUP(out) = PUP(from);
  78388. len -= 3;
  78389. }
  78390. if (len) {
  78391. PUP(out) = PUP(from);
  78392. if (len > 1)
  78393. PUP(out) = PUP(from);
  78394. }
  78395. }
  78396. else {
  78397. from = out - dist; /* copy direct from output */
  78398. do { /* minimum length is three */
  78399. PUP(out) = PUP(from);
  78400. PUP(out) = PUP(from);
  78401. PUP(out) = PUP(from);
  78402. len -= 3;
  78403. } while (len > 2);
  78404. if (len) {
  78405. PUP(out) = PUP(from);
  78406. if (len > 1)
  78407. PUP(out) = PUP(from);
  78408. }
  78409. }
  78410. }
  78411. else if ((op & 64) == 0) { /* 2nd level distance code */
  78412. thisx = dcode[thisx.val + (hold & ((1U << op) - 1))];
  78413. goto dodist;
  78414. }
  78415. else {
  78416. strm->msg = (char *)"invalid distance code";
  78417. state->mode = BAD;
  78418. break;
  78419. }
  78420. }
  78421. else if ((op & 64) == 0) { /* 2nd level length code */
  78422. thisx = lcode[thisx.val + (hold & ((1U << op) - 1))];
  78423. goto dolen;
  78424. }
  78425. else if (op & 32) { /* end-of-block */
  78426. Tracevv((stderr, "inflate: end of block\n"));
  78427. state->mode = TYPE;
  78428. break;
  78429. }
  78430. else {
  78431. strm->msg = (char *)"invalid literal/length code";
  78432. state->mode = BAD;
  78433. break;
  78434. }
  78435. } while (in < last && out < end);
  78436. len = bits >> 3;
  78437. in -= len;
  78438. bits -= len << 3;
  78439. hold &= (1U << bits) - 1;
  78440. strm->next_in = in + OFF;
  78441. strm->next_out = out + OFF;
  78442. strm->avail_in = (unsigned)(in < last ? 5 + (last - in) : 5 - (in - last));
  78443. strm->avail_out = (unsigned)(out < end ?
  78444. 257 + (end - out) : 257 - (out - end));
  78445. state->hold = hold;
  78446. state->bits = bits;
  78447. return;
  78448. }
  78449. #endif /* !ASMINF */
  78450. /*** End of inlined file: inffast.c ***/
  78451. #undef PULLBYTE
  78452. #undef LOAD
  78453. #undef RESTORE
  78454. #undef INITBITS
  78455. #undef NEEDBITS
  78456. #undef DROPBITS
  78457. #undef BYTEBITS
  78458. /*** Start of inlined file: inflate.c ***/
  78459. /*** Start of inlined file: inffast.h ***/
  78460. void inflate_fast OF((z_streamp strm, unsigned start));
  78461. /*** End of inlined file: inffast.h ***/
  78462. #ifdef MAKEFIXED
  78463. # ifndef BUILDFIXED
  78464. # define BUILDFIXED
  78465. # endif
  78466. #endif
  78467. local void fixedtables OF((struct inflate_state FAR *state));
  78468. local int updatewindow OF((z_streamp strm, unsigned out));
  78469. #ifdef BUILDFIXED
  78470. void makefixed OF((void));
  78471. #endif
  78472. local unsigned syncsearch OF((unsigned FAR *have, unsigned char FAR *buf,
  78473. unsigned len));
  78474. int ZEXPORT inflateReset (z_streamp strm)
  78475. {
  78476. struct inflate_state FAR *state;
  78477. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  78478. state = (struct inflate_state FAR *)strm->state;
  78479. strm->total_in = strm->total_out = state->total = 0;
  78480. strm->msg = Z_NULL;
  78481. strm->adler = 1; /* to support ill-conceived Java test suite */
  78482. state->mode = HEAD;
  78483. state->last = 0;
  78484. state->havedict = 0;
  78485. state->dmax = 32768U;
  78486. state->head = Z_NULL;
  78487. state->wsize = 0;
  78488. state->whave = 0;
  78489. state->write = 0;
  78490. state->hold = 0;
  78491. state->bits = 0;
  78492. state->lencode = state->distcode = state->next = state->codes;
  78493. Tracev((stderr, "inflate: reset\n"));
  78494. return Z_OK;
  78495. }
  78496. int ZEXPORT inflatePrime (z_streamp strm, int bits, int value)
  78497. {
  78498. struct inflate_state FAR *state;
  78499. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  78500. state = (struct inflate_state FAR *)strm->state;
  78501. if (bits > 16 || state->bits + bits > 32) return Z_STREAM_ERROR;
  78502. value &= (1L << bits) - 1;
  78503. state->hold += value << state->bits;
  78504. state->bits += bits;
  78505. return Z_OK;
  78506. }
  78507. int ZEXPORT inflateInit2_(z_streamp strm, int windowBits, const char *version, int stream_size)
  78508. {
  78509. struct inflate_state FAR *state;
  78510. if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
  78511. stream_size != (int)(sizeof(z_stream)))
  78512. return Z_VERSION_ERROR;
  78513. if (strm == Z_NULL) return Z_STREAM_ERROR;
  78514. strm->msg = Z_NULL; /* in case we return an error */
  78515. if (strm->zalloc == (alloc_func)0) {
  78516. strm->zalloc = zcalloc;
  78517. strm->opaque = (voidpf)0;
  78518. }
  78519. if (strm->zfree == (free_func)0) strm->zfree = zcfree;
  78520. state = (struct inflate_state FAR *)
  78521. ZALLOC(strm, 1, sizeof(struct inflate_state));
  78522. if (state == Z_NULL) return Z_MEM_ERROR;
  78523. Tracev((stderr, "inflate: allocated\n"));
  78524. strm->state = (struct internal_state FAR *)state;
  78525. if (windowBits < 0) {
  78526. state->wrap = 0;
  78527. windowBits = -windowBits;
  78528. }
  78529. else {
  78530. state->wrap = (windowBits >> 4) + 1;
  78531. #ifdef GUNZIP
  78532. if (windowBits < 48) windowBits &= 15;
  78533. #endif
  78534. }
  78535. if (windowBits < 8 || windowBits > 15) {
  78536. ZFREE(strm, state);
  78537. strm->state = Z_NULL;
  78538. return Z_STREAM_ERROR;
  78539. }
  78540. state->wbits = (unsigned)windowBits;
  78541. state->window = Z_NULL;
  78542. return inflateReset(strm);
  78543. }
  78544. int ZEXPORT inflateInit_ (z_streamp strm, const char *version, int stream_size)
  78545. {
  78546. return inflateInit2_(strm, DEF_WBITS, version, stream_size);
  78547. }
  78548. local void fixedtables (struct inflate_state FAR *state)
  78549. {
  78550. #ifdef BUILDFIXED
  78551. static int virgin = 1;
  78552. static code *lenfix, *distfix;
  78553. static code fixed[544];
  78554. if (virgin) {
  78555. unsigned sym, bits;
  78556. static code *next;
  78557. sym = 0;
  78558. while (sym < 144) state->lens[sym++] = 8;
  78559. while (sym < 256) state->lens[sym++] = 9;
  78560. while (sym < 280) state->lens[sym++] = 7;
  78561. while (sym < 288) state->lens[sym++] = 8;
  78562. next = fixed;
  78563. lenfix = next;
  78564. bits = 9;
  78565. inflate_table(LENS, state->lens, 288, &(next), &(bits), state->work);
  78566. sym = 0;
  78567. while (sym < 32) state->lens[sym++] = 5;
  78568. distfix = next;
  78569. bits = 5;
  78570. inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work);
  78571. virgin = 0;
  78572. }
  78573. #else /* !BUILDFIXED */
  78574. /*** Start of inlined file: inffixed.h ***/
  78575. static const code lenfix[512] = {
  78576. {96,7,0},{0,8,80},{0,8,16},{20,8,115},{18,7,31},{0,8,112},{0,8,48},
  78577. {0,9,192},{16,7,10},{0,8,96},{0,8,32},{0,9,160},{0,8,0},{0,8,128},
  78578. {0,8,64},{0,9,224},{16,7,6},{0,8,88},{0,8,24},{0,9,144},{19,7,59},
  78579. {0,8,120},{0,8,56},{0,9,208},{17,7,17},{0,8,104},{0,8,40},{0,9,176},
  78580. {0,8,8},{0,8,136},{0,8,72},{0,9,240},{16,7,4},{0,8,84},{0,8,20},
  78581. {21,8,227},{19,7,43},{0,8,116},{0,8,52},{0,9,200},{17,7,13},{0,8,100},
  78582. {0,8,36},{0,9,168},{0,8,4},{0,8,132},{0,8,68},{0,9,232},{16,7,8},
  78583. {0,8,92},{0,8,28},{0,9,152},{20,7,83},{0,8,124},{0,8,60},{0,9,216},
  78584. {18,7,23},{0,8,108},{0,8,44},{0,9,184},{0,8,12},{0,8,140},{0,8,76},
  78585. {0,9,248},{16,7,3},{0,8,82},{0,8,18},{21,8,163},{19,7,35},{0,8,114},
  78586. {0,8,50},{0,9,196},{17,7,11},{0,8,98},{0,8,34},{0,9,164},{0,8,2},
  78587. {0,8,130},{0,8,66},{0,9,228},{16,7,7},{0,8,90},{0,8,26},{0,9,148},
  78588. {20,7,67},{0,8,122},{0,8,58},{0,9,212},{18,7,19},{0,8,106},{0,8,42},
  78589. {0,9,180},{0,8,10},{0,8,138},{0,8,74},{0,9,244},{16,7,5},{0,8,86},
  78590. {0,8,22},{64,8,0},{19,7,51},{0,8,118},{0,8,54},{0,9,204},{17,7,15},
  78591. {0,8,102},{0,8,38},{0,9,172},{0,8,6},{0,8,134},{0,8,70},{0,9,236},
  78592. {16,7,9},{0,8,94},{0,8,30},{0,9,156},{20,7,99},{0,8,126},{0,8,62},
  78593. {0,9,220},{18,7,27},{0,8,110},{0,8,46},{0,9,188},{0,8,14},{0,8,142},
  78594. {0,8,78},{0,9,252},{96,7,0},{0,8,81},{0,8,17},{21,8,131},{18,7,31},
  78595. {0,8,113},{0,8,49},{0,9,194},{16,7,10},{0,8,97},{0,8,33},{0,9,162},
  78596. {0,8,1},{0,8,129},{0,8,65},{0,9,226},{16,7,6},{0,8,89},{0,8,25},
  78597. {0,9,146},{19,7,59},{0,8,121},{0,8,57},{0,9,210},{17,7,17},{0,8,105},
  78598. {0,8,41},{0,9,178},{0,8,9},{0,8,137},{0,8,73},{0,9,242},{16,7,4},
  78599. {0,8,85},{0,8,21},{16,8,258},{19,7,43},{0,8,117},{0,8,53},{0,9,202},
  78600. {17,7,13},{0,8,101},{0,8,37},{0,9,170},{0,8,5},{0,8,133},{0,8,69},
  78601. {0,9,234},{16,7,8},{0,8,93},{0,8,29},{0,9,154},{20,7,83},{0,8,125},
  78602. {0,8,61},{0,9,218},{18,7,23},{0,8,109},{0,8,45},{0,9,186},{0,8,13},
  78603. {0,8,141},{0,8,77},{0,9,250},{16,7,3},{0,8,83},{0,8,19},{21,8,195},
  78604. {19,7,35},{0,8,115},{0,8,51},{0,9,198},{17,7,11},{0,8,99},{0,8,35},
  78605. {0,9,166},{0,8,3},{0,8,131},{0,8,67},{0,9,230},{16,7,7},{0,8,91},
  78606. {0,8,27},{0,9,150},{20,7,67},{0,8,123},{0,8,59},{0,9,214},{18,7,19},
  78607. {0,8,107},{0,8,43},{0,9,182},{0,8,11},{0,8,139},{0,8,75},{0,9,246},
  78608. {16,7,5},{0,8,87},{0,8,23},{64,8,0},{19,7,51},{0,8,119},{0,8,55},
  78609. {0,9,206},{17,7,15},{0,8,103},{0,8,39},{0,9,174},{0,8,7},{0,8,135},
  78610. {0,8,71},{0,9,238},{16,7,9},{0,8,95},{0,8,31},{0,9,158},{20,7,99},
  78611. {0,8,127},{0,8,63},{0,9,222},{18,7,27},{0,8,111},{0,8,47},{0,9,190},
  78612. {0,8,15},{0,8,143},{0,8,79},{0,9,254},{96,7,0},{0,8,80},{0,8,16},
  78613. {20,8,115},{18,7,31},{0,8,112},{0,8,48},{0,9,193},{16,7,10},{0,8,96},
  78614. {0,8,32},{0,9,161},{0,8,0},{0,8,128},{0,8,64},{0,9,225},{16,7,6},
  78615. {0,8,88},{0,8,24},{0,9,145},{19,7,59},{0,8,120},{0,8,56},{0,9,209},
  78616. {17,7,17},{0,8,104},{0,8,40},{0,9,177},{0,8,8},{0,8,136},{0,8,72},
  78617. {0,9,241},{16,7,4},{0,8,84},{0,8,20},{21,8,227},{19,7,43},{0,8,116},
  78618. {0,8,52},{0,9,201},{17,7,13},{0,8,100},{0,8,36},{0,9,169},{0,8,4},
  78619. {0,8,132},{0,8,68},{0,9,233},{16,7,8},{0,8,92},{0,8,28},{0,9,153},
  78620. {20,7,83},{0,8,124},{0,8,60},{0,9,217},{18,7,23},{0,8,108},{0,8,44},
  78621. {0,9,185},{0,8,12},{0,8,140},{0,8,76},{0,9,249},{16,7,3},{0,8,82},
  78622. {0,8,18},{21,8,163},{19,7,35},{0,8,114},{0,8,50},{0,9,197},{17,7,11},
  78623. {0,8,98},{0,8,34},{0,9,165},{0,8,2},{0,8,130},{0,8,66},{0,9,229},
  78624. {16,7,7},{0,8,90},{0,8,26},{0,9,149},{20,7,67},{0,8,122},{0,8,58},
  78625. {0,9,213},{18,7,19},{0,8,106},{0,8,42},{0,9,181},{0,8,10},{0,8,138},
  78626. {0,8,74},{0,9,245},{16,7,5},{0,8,86},{0,8,22},{64,8,0},{19,7,51},
  78627. {0,8,118},{0,8,54},{0,9,205},{17,7,15},{0,8,102},{0,8,38},{0,9,173},
  78628. {0,8,6},{0,8,134},{0,8,70},{0,9,237},{16,7,9},{0,8,94},{0,8,30},
  78629. {0,9,157},{20,7,99},{0,8,126},{0,8,62},{0,9,221},{18,7,27},{0,8,110},
  78630. {0,8,46},{0,9,189},{0,8,14},{0,8,142},{0,8,78},{0,9,253},{96,7,0},
  78631. {0,8,81},{0,8,17},{21,8,131},{18,7,31},{0,8,113},{0,8,49},{0,9,195},
  78632. {16,7,10},{0,8,97},{0,8,33},{0,9,163},{0,8,1},{0,8,129},{0,8,65},
  78633. {0,9,227},{16,7,6},{0,8,89},{0,8,25},{0,9,147},{19,7,59},{0,8,121},
  78634. {0,8,57},{0,9,211},{17,7,17},{0,8,105},{0,8,41},{0,9,179},{0,8,9},
  78635. {0,8,137},{0,8,73},{0,9,243},{16,7,4},{0,8,85},{0,8,21},{16,8,258},
  78636. {19,7,43},{0,8,117},{0,8,53},{0,9,203},{17,7,13},{0,8,101},{0,8,37},
  78637. {0,9,171},{0,8,5},{0,8,133},{0,8,69},{0,9,235},{16,7,8},{0,8,93},
  78638. {0,8,29},{0,9,155},{20,7,83},{0,8,125},{0,8,61},{0,9,219},{18,7,23},
  78639. {0,8,109},{0,8,45},{0,9,187},{0,8,13},{0,8,141},{0,8,77},{0,9,251},
  78640. {16,7,3},{0,8,83},{0,8,19},{21,8,195},{19,7,35},{0,8,115},{0,8,51},
  78641. {0,9,199},{17,7,11},{0,8,99},{0,8,35},{0,9,167},{0,8,3},{0,8,131},
  78642. {0,8,67},{0,9,231},{16,7,7},{0,8,91},{0,8,27},{0,9,151},{20,7,67},
  78643. {0,8,123},{0,8,59},{0,9,215},{18,7,19},{0,8,107},{0,8,43},{0,9,183},
  78644. {0,8,11},{0,8,139},{0,8,75},{0,9,247},{16,7,5},{0,8,87},{0,8,23},
  78645. {64,8,0},{19,7,51},{0,8,119},{0,8,55},{0,9,207},{17,7,15},{0,8,103},
  78646. {0,8,39},{0,9,175},{0,8,7},{0,8,135},{0,8,71},{0,9,239},{16,7,9},
  78647. {0,8,95},{0,8,31},{0,9,159},{20,7,99},{0,8,127},{0,8,63},{0,9,223},
  78648. {18,7,27},{0,8,111},{0,8,47},{0,9,191},{0,8,15},{0,8,143},{0,8,79},
  78649. {0,9,255}
  78650. };
  78651. static const code distfix[32] = {
  78652. {16,5,1},{23,5,257},{19,5,17},{27,5,4097},{17,5,5},{25,5,1025},
  78653. {21,5,65},{29,5,16385},{16,5,3},{24,5,513},{20,5,33},{28,5,8193},
  78654. {18,5,9},{26,5,2049},{22,5,129},{64,5,0},{16,5,2},{23,5,385},
  78655. {19,5,25},{27,5,6145},{17,5,7},{25,5,1537},{21,5,97},{29,5,24577},
  78656. {16,5,4},{24,5,769},{20,5,49},{28,5,12289},{18,5,13},{26,5,3073},
  78657. {22,5,193},{64,5,0}
  78658. };
  78659. /*** End of inlined file: inffixed.h ***/
  78660. #endif /* BUILDFIXED */
  78661. state->lencode = lenfix;
  78662. state->lenbits = 9;
  78663. state->distcode = distfix;
  78664. state->distbits = 5;
  78665. }
  78666. #ifdef MAKEFIXED
  78667. #include <stdio.h>
  78668. void makefixed()
  78669. {
  78670. unsigned low, size;
  78671. struct inflate_state state;
  78672. fixedtables(&state);
  78673. puts(" /* inffixed.h -- table for decoding fixed codes");
  78674. puts(" * Generated automatically by makefixed().");
  78675. puts(" */");
  78676. puts("");
  78677. puts(" /* WARNING: this file should *not* be used by applications.");
  78678. puts(" It is part of the implementation of this library and is");
  78679. puts(" subject to change. Applications should only use zlib.h.");
  78680. puts(" */");
  78681. puts("");
  78682. size = 1U << 9;
  78683. printf(" static const code lenfix[%u] = {", size);
  78684. low = 0;
  78685. for (;;) {
  78686. if ((low % 7) == 0) printf("\n ");
  78687. printf("{%u,%u,%d}", state.lencode[low].op, state.lencode[low].bits,
  78688. state.lencode[low].val);
  78689. if (++low == size) break;
  78690. putchar(',');
  78691. }
  78692. puts("\n };");
  78693. size = 1U << 5;
  78694. printf("\n static const code distfix[%u] = {", size);
  78695. low = 0;
  78696. for (;;) {
  78697. if ((low % 6) == 0) printf("\n ");
  78698. printf("{%u,%u,%d}", state.distcode[low].op, state.distcode[low].bits,
  78699. state.distcode[low].val);
  78700. if (++low == size) break;
  78701. putchar(',');
  78702. }
  78703. puts("\n };");
  78704. }
  78705. #endif /* MAKEFIXED */
  78706. local int updatewindow (z_streamp strm, unsigned out)
  78707. {
  78708. struct inflate_state FAR *state;
  78709. unsigned copy, dist;
  78710. state = (struct inflate_state FAR *)strm->state;
  78711. if (state->window == Z_NULL) {
  78712. state->window = (unsigned char FAR *)
  78713. ZALLOC(strm, 1U << state->wbits,
  78714. sizeof(unsigned char));
  78715. if (state->window == Z_NULL) return 1;
  78716. }
  78717. if (state->wsize == 0) {
  78718. state->wsize = 1U << state->wbits;
  78719. state->write = 0;
  78720. state->whave = 0;
  78721. }
  78722. copy = out - strm->avail_out;
  78723. if (copy >= state->wsize) {
  78724. zmemcpy(state->window, strm->next_out - state->wsize, state->wsize);
  78725. state->write = 0;
  78726. state->whave = state->wsize;
  78727. }
  78728. else {
  78729. dist = state->wsize - state->write;
  78730. if (dist > copy) dist = copy;
  78731. zmemcpy(state->window + state->write, strm->next_out - copy, dist);
  78732. copy -= dist;
  78733. if (copy) {
  78734. zmemcpy(state->window, strm->next_out - copy, copy);
  78735. state->write = copy;
  78736. state->whave = state->wsize;
  78737. }
  78738. else {
  78739. state->write += dist;
  78740. if (state->write == state->wsize) state->write = 0;
  78741. if (state->whave < state->wsize) state->whave += dist;
  78742. }
  78743. }
  78744. return 0;
  78745. }
  78746. #ifdef GUNZIP
  78747. # define UPDATE(check, buf, len) \
  78748. (state->flags ? crc32(check, buf, len) : adler32(check, buf, len))
  78749. #else
  78750. # define UPDATE(check, buf, len) adler32(check, buf, len)
  78751. #endif
  78752. #ifdef GUNZIP
  78753. # define CRC2(check, word) \
  78754. do { \
  78755. hbuf[0] = (unsigned char)(word); \
  78756. hbuf[1] = (unsigned char)((word) >> 8); \
  78757. check = crc32(check, hbuf, 2); \
  78758. } while (0)
  78759. # define CRC4(check, word) \
  78760. do { \
  78761. hbuf[0] = (unsigned char)(word); \
  78762. hbuf[1] = (unsigned char)((word) >> 8); \
  78763. hbuf[2] = (unsigned char)((word) >> 16); \
  78764. hbuf[3] = (unsigned char)((word) >> 24); \
  78765. check = crc32(check, hbuf, 4); \
  78766. } while (0)
  78767. #endif
  78768. #define LOAD() \
  78769. do { \
  78770. put = strm->next_out; \
  78771. left = strm->avail_out; \
  78772. next = strm->next_in; \
  78773. have = strm->avail_in; \
  78774. hold = state->hold; \
  78775. bits = state->bits; \
  78776. } while (0)
  78777. #define RESTORE() \
  78778. do { \
  78779. strm->next_out = put; \
  78780. strm->avail_out = left; \
  78781. strm->next_in = next; \
  78782. strm->avail_in = have; \
  78783. state->hold = hold; \
  78784. state->bits = bits; \
  78785. } while (0)
  78786. #define INITBITS() \
  78787. do { \
  78788. hold = 0; \
  78789. bits = 0; \
  78790. } while (0)
  78791. #define PULLBYTE() \
  78792. do { \
  78793. if (have == 0) goto inf_leave; \
  78794. have--; \
  78795. hold += (unsigned long)(*next++) << bits; \
  78796. bits += 8; \
  78797. } while (0)
  78798. #define NEEDBITS(n) \
  78799. do { \
  78800. while (bits < (unsigned)(n)) \
  78801. PULLBYTE(); \
  78802. } while (0)
  78803. #define BITS(n) \
  78804. ((unsigned)hold & ((1U << (n)) - 1))
  78805. #define DROPBITS(n) \
  78806. do { \
  78807. hold >>= (n); \
  78808. bits -= (unsigned)(n); \
  78809. } while (0)
  78810. #define BYTEBITS() \
  78811. do { \
  78812. hold >>= bits & 7; \
  78813. bits -= bits & 7; \
  78814. } while (0)
  78815. #define REVERSE(q) \
  78816. ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \
  78817. (((q) & 0xff00) << 8) + (((q) & 0xff) << 24))
  78818. int ZEXPORT inflate (z_streamp strm, int flush)
  78819. {
  78820. struct inflate_state FAR *state;
  78821. unsigned char FAR *next; /* next input */
  78822. unsigned char FAR *put; /* next output */
  78823. unsigned have, left; /* available input and output */
  78824. unsigned long hold; /* bit buffer */
  78825. unsigned bits; /* bits in bit buffer */
  78826. unsigned in, out; /* save starting available input and output */
  78827. unsigned copy; /* number of stored or match bytes to copy */
  78828. unsigned char FAR *from; /* where to copy match bytes from */
  78829. code thisx; /* current decoding table entry */
  78830. code last; /* parent table entry */
  78831. unsigned len; /* length to copy for repeats, bits to drop */
  78832. int ret; /* return code */
  78833. #ifdef GUNZIP
  78834. unsigned char hbuf[4]; /* buffer for gzip header crc calculation */
  78835. #endif
  78836. static const unsigned short order[19] = /* permutation of code lengths */
  78837. {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
  78838. if (strm == Z_NULL || strm->state == Z_NULL || strm->next_out == Z_NULL ||
  78839. (strm->next_in == Z_NULL && strm->avail_in != 0))
  78840. return Z_STREAM_ERROR;
  78841. state = (struct inflate_state FAR *)strm->state;
  78842. if (state->mode == TYPE) state->mode = TYPEDO; /* skip check */
  78843. LOAD();
  78844. in = have;
  78845. out = left;
  78846. ret = Z_OK;
  78847. for (;;)
  78848. switch (state->mode) {
  78849. case HEAD:
  78850. if (state->wrap == 0) {
  78851. state->mode = TYPEDO;
  78852. break;
  78853. }
  78854. NEEDBITS(16);
  78855. #ifdef GUNZIP
  78856. if ((state->wrap & 2) && hold == 0x8b1f) { /* gzip header */
  78857. state->check = crc32(0L, Z_NULL, 0);
  78858. CRC2(state->check, hold);
  78859. INITBITS();
  78860. state->mode = FLAGS;
  78861. break;
  78862. }
  78863. state->flags = 0; /* expect zlib header */
  78864. if (state->head != Z_NULL)
  78865. state->head->done = -1;
  78866. if (!(state->wrap & 1) || /* check if zlib header allowed */
  78867. #else
  78868. if (
  78869. #endif
  78870. ((BITS(8) << 8) + (hold >> 8)) % 31) {
  78871. strm->msg = (char *)"incorrect header check";
  78872. state->mode = BAD;
  78873. break;
  78874. }
  78875. if (BITS(4) != Z_DEFLATED) {
  78876. strm->msg = (char *)"unknown compression method";
  78877. state->mode = BAD;
  78878. break;
  78879. }
  78880. DROPBITS(4);
  78881. len = BITS(4) + 8;
  78882. if (len > state->wbits) {
  78883. strm->msg = (char *)"invalid window size";
  78884. state->mode = BAD;
  78885. break;
  78886. }
  78887. state->dmax = 1U << len;
  78888. Tracev((stderr, "inflate: zlib header ok\n"));
  78889. strm->adler = state->check = adler32(0L, Z_NULL, 0);
  78890. state->mode = hold & 0x200 ? DICTID : TYPE;
  78891. INITBITS();
  78892. break;
  78893. #ifdef GUNZIP
  78894. case FLAGS:
  78895. NEEDBITS(16);
  78896. state->flags = (int)(hold);
  78897. if ((state->flags & 0xff) != Z_DEFLATED) {
  78898. strm->msg = (char *)"unknown compression method";
  78899. state->mode = BAD;
  78900. break;
  78901. }
  78902. if (state->flags & 0xe000) {
  78903. strm->msg = (char *)"unknown header flags set";
  78904. state->mode = BAD;
  78905. break;
  78906. }
  78907. if (state->head != Z_NULL)
  78908. state->head->text = (int)((hold >> 8) & 1);
  78909. if (state->flags & 0x0200) CRC2(state->check, hold);
  78910. INITBITS();
  78911. state->mode = TIME;
  78912. case TIME:
  78913. NEEDBITS(32);
  78914. if (state->head != Z_NULL)
  78915. state->head->time = hold;
  78916. if (state->flags & 0x0200) CRC4(state->check, hold);
  78917. INITBITS();
  78918. state->mode = OS;
  78919. case OS:
  78920. NEEDBITS(16);
  78921. if (state->head != Z_NULL) {
  78922. state->head->xflags = (int)(hold & 0xff);
  78923. state->head->os = (int)(hold >> 8);
  78924. }
  78925. if (state->flags & 0x0200) CRC2(state->check, hold);
  78926. INITBITS();
  78927. state->mode = EXLEN;
  78928. case EXLEN:
  78929. if (state->flags & 0x0400) {
  78930. NEEDBITS(16);
  78931. state->length = (unsigned)(hold);
  78932. if (state->head != Z_NULL)
  78933. state->head->extra_len = (unsigned)hold;
  78934. if (state->flags & 0x0200) CRC2(state->check, hold);
  78935. INITBITS();
  78936. }
  78937. else if (state->head != Z_NULL)
  78938. state->head->extra = Z_NULL;
  78939. state->mode = EXTRA;
  78940. case EXTRA:
  78941. if (state->flags & 0x0400) {
  78942. copy = state->length;
  78943. if (copy > have) copy = have;
  78944. if (copy) {
  78945. if (state->head != Z_NULL &&
  78946. state->head->extra != Z_NULL) {
  78947. len = state->head->extra_len - state->length;
  78948. zmemcpy(state->head->extra + len, next,
  78949. len + copy > state->head->extra_max ?
  78950. state->head->extra_max - len : copy);
  78951. }
  78952. if (state->flags & 0x0200)
  78953. state->check = crc32(state->check, next, copy);
  78954. have -= copy;
  78955. next += copy;
  78956. state->length -= copy;
  78957. }
  78958. if (state->length) goto inf_leave;
  78959. }
  78960. state->length = 0;
  78961. state->mode = NAME;
  78962. case NAME:
  78963. if (state->flags & 0x0800) {
  78964. if (have == 0) goto inf_leave;
  78965. copy = 0;
  78966. do {
  78967. len = (unsigned)(next[copy++]);
  78968. if (state->head != Z_NULL &&
  78969. state->head->name != Z_NULL &&
  78970. state->length < state->head->name_max)
  78971. state->head->name[state->length++] = len;
  78972. } while (len && copy < have);
  78973. if (state->flags & 0x0200)
  78974. state->check = crc32(state->check, next, copy);
  78975. have -= copy;
  78976. next += copy;
  78977. if (len) goto inf_leave;
  78978. }
  78979. else if (state->head != Z_NULL)
  78980. state->head->name = Z_NULL;
  78981. state->length = 0;
  78982. state->mode = COMMENT;
  78983. case COMMENT:
  78984. if (state->flags & 0x1000) {
  78985. if (have == 0) goto inf_leave;
  78986. copy = 0;
  78987. do {
  78988. len = (unsigned)(next[copy++]);
  78989. if (state->head != Z_NULL &&
  78990. state->head->comment != Z_NULL &&
  78991. state->length < state->head->comm_max)
  78992. state->head->comment[state->length++] = len;
  78993. } while (len && copy < have);
  78994. if (state->flags & 0x0200)
  78995. state->check = crc32(state->check, next, copy);
  78996. have -= copy;
  78997. next += copy;
  78998. if (len) goto inf_leave;
  78999. }
  79000. else if (state->head != Z_NULL)
  79001. state->head->comment = Z_NULL;
  79002. state->mode = HCRC;
  79003. case HCRC:
  79004. if (state->flags & 0x0200) {
  79005. NEEDBITS(16);
  79006. if (hold != (state->check & 0xffff)) {
  79007. strm->msg = (char *)"header crc mismatch";
  79008. state->mode = BAD;
  79009. break;
  79010. }
  79011. INITBITS();
  79012. }
  79013. if (state->head != Z_NULL) {
  79014. state->head->hcrc = (int)((state->flags >> 9) & 1);
  79015. state->head->done = 1;
  79016. }
  79017. strm->adler = state->check = crc32(0L, Z_NULL, 0);
  79018. state->mode = TYPE;
  79019. break;
  79020. #endif
  79021. case DICTID:
  79022. NEEDBITS(32);
  79023. strm->adler = state->check = REVERSE(hold);
  79024. INITBITS();
  79025. state->mode = DICT;
  79026. case DICT:
  79027. if (state->havedict == 0) {
  79028. RESTORE();
  79029. return Z_NEED_DICT;
  79030. }
  79031. strm->adler = state->check = adler32(0L, Z_NULL, 0);
  79032. state->mode = TYPE;
  79033. case TYPE:
  79034. if (flush == Z_BLOCK) goto inf_leave;
  79035. case TYPEDO:
  79036. if (state->last) {
  79037. BYTEBITS();
  79038. state->mode = CHECK;
  79039. break;
  79040. }
  79041. NEEDBITS(3);
  79042. state->last = BITS(1);
  79043. DROPBITS(1);
  79044. switch (BITS(2)) {
  79045. case 0: /* stored block */
  79046. Tracev((stderr, "inflate: stored block%s\n",
  79047. state->last ? " (last)" : ""));
  79048. state->mode = STORED;
  79049. break;
  79050. case 1: /* fixed block */
  79051. fixedtables(state);
  79052. Tracev((stderr, "inflate: fixed codes block%s\n",
  79053. state->last ? " (last)" : ""));
  79054. state->mode = LEN; /* decode codes */
  79055. break;
  79056. case 2: /* dynamic block */
  79057. Tracev((stderr, "inflate: dynamic codes block%s\n",
  79058. state->last ? " (last)" : ""));
  79059. state->mode = TABLE;
  79060. break;
  79061. case 3:
  79062. strm->msg = (char *)"invalid block type";
  79063. state->mode = BAD;
  79064. }
  79065. DROPBITS(2);
  79066. break;
  79067. case STORED:
  79068. BYTEBITS(); /* go to byte boundary */
  79069. NEEDBITS(32);
  79070. if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) {
  79071. strm->msg = (char *)"invalid stored block lengths";
  79072. state->mode = BAD;
  79073. break;
  79074. }
  79075. state->length = (unsigned)hold & 0xffff;
  79076. Tracev((stderr, "inflate: stored length %u\n",
  79077. state->length));
  79078. INITBITS();
  79079. state->mode = COPY;
  79080. case COPY:
  79081. copy = state->length;
  79082. if (copy) {
  79083. if (copy > have) copy = have;
  79084. if (copy > left) copy = left;
  79085. if (copy == 0) goto inf_leave;
  79086. zmemcpy(put, next, copy);
  79087. have -= copy;
  79088. next += copy;
  79089. left -= copy;
  79090. put += copy;
  79091. state->length -= copy;
  79092. break;
  79093. }
  79094. Tracev((stderr, "inflate: stored end\n"));
  79095. state->mode = TYPE;
  79096. break;
  79097. case TABLE:
  79098. NEEDBITS(14);
  79099. state->nlen = BITS(5) + 257;
  79100. DROPBITS(5);
  79101. state->ndist = BITS(5) + 1;
  79102. DROPBITS(5);
  79103. state->ncode = BITS(4) + 4;
  79104. DROPBITS(4);
  79105. #ifndef PKZIP_BUG_WORKAROUND
  79106. if (state->nlen > 286 || state->ndist > 30) {
  79107. strm->msg = (char *)"too many length or distance symbols";
  79108. state->mode = BAD;
  79109. break;
  79110. }
  79111. #endif
  79112. Tracev((stderr, "inflate: table sizes ok\n"));
  79113. state->have = 0;
  79114. state->mode = LENLENS;
  79115. case LENLENS:
  79116. while (state->have < state->ncode) {
  79117. NEEDBITS(3);
  79118. state->lens[order[state->have++]] = (unsigned short)BITS(3);
  79119. DROPBITS(3);
  79120. }
  79121. while (state->have < 19)
  79122. state->lens[order[state->have++]] = 0;
  79123. state->next = state->codes;
  79124. state->lencode = (code const FAR *)(state->next);
  79125. state->lenbits = 7;
  79126. ret = inflate_table(CODES, state->lens, 19, &(state->next),
  79127. &(state->lenbits), state->work);
  79128. if (ret) {
  79129. strm->msg = (char *)"invalid code lengths set";
  79130. state->mode = BAD;
  79131. break;
  79132. }
  79133. Tracev((stderr, "inflate: code lengths ok\n"));
  79134. state->have = 0;
  79135. state->mode = CODELENS;
  79136. case CODELENS:
  79137. while (state->have < state->nlen + state->ndist) {
  79138. for (;;) {
  79139. thisx = state->lencode[BITS(state->lenbits)];
  79140. if ((unsigned)(thisx.bits) <= bits) break;
  79141. PULLBYTE();
  79142. }
  79143. if (thisx.val < 16) {
  79144. NEEDBITS(thisx.bits);
  79145. DROPBITS(thisx.bits);
  79146. state->lens[state->have++] = thisx.val;
  79147. }
  79148. else {
  79149. if (thisx.val == 16) {
  79150. NEEDBITS(thisx.bits + 2);
  79151. DROPBITS(thisx.bits);
  79152. if (state->have == 0) {
  79153. strm->msg = (char *)"invalid bit length repeat";
  79154. state->mode = BAD;
  79155. break;
  79156. }
  79157. len = state->lens[state->have - 1];
  79158. copy = 3 + BITS(2);
  79159. DROPBITS(2);
  79160. }
  79161. else if (thisx.val == 17) {
  79162. NEEDBITS(thisx.bits + 3);
  79163. DROPBITS(thisx.bits);
  79164. len = 0;
  79165. copy = 3 + BITS(3);
  79166. DROPBITS(3);
  79167. }
  79168. else {
  79169. NEEDBITS(thisx.bits + 7);
  79170. DROPBITS(thisx.bits);
  79171. len = 0;
  79172. copy = 11 + BITS(7);
  79173. DROPBITS(7);
  79174. }
  79175. if (state->have + copy > state->nlen + state->ndist) {
  79176. strm->msg = (char *)"invalid bit length repeat";
  79177. state->mode = BAD;
  79178. break;
  79179. }
  79180. while (copy--)
  79181. state->lens[state->have++] = (unsigned short)len;
  79182. }
  79183. }
  79184. if (state->mode == BAD) break;
  79185. state->next = state->codes;
  79186. state->lencode = (code const FAR *)(state->next);
  79187. state->lenbits = 9;
  79188. ret = inflate_table(LENS, state->lens, state->nlen, &(state->next),
  79189. &(state->lenbits), state->work);
  79190. if (ret) {
  79191. strm->msg = (char *)"invalid literal/lengths set";
  79192. state->mode = BAD;
  79193. break;
  79194. }
  79195. state->distcode = (code const FAR *)(state->next);
  79196. state->distbits = 6;
  79197. ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist,
  79198. &(state->next), &(state->distbits), state->work);
  79199. if (ret) {
  79200. strm->msg = (char *)"invalid distances set";
  79201. state->mode = BAD;
  79202. break;
  79203. }
  79204. Tracev((stderr, "inflate: codes ok\n"));
  79205. state->mode = LEN;
  79206. case LEN:
  79207. if (have >= 6 && left >= 258) {
  79208. RESTORE();
  79209. inflate_fast(strm, out);
  79210. LOAD();
  79211. break;
  79212. }
  79213. for (;;) {
  79214. thisx = state->lencode[BITS(state->lenbits)];
  79215. if ((unsigned)(thisx.bits) <= bits) break;
  79216. PULLBYTE();
  79217. }
  79218. if (thisx.op && (thisx.op & 0xf0) == 0) {
  79219. last = thisx;
  79220. for (;;) {
  79221. thisx = state->lencode[last.val +
  79222. (BITS(last.bits + last.op) >> last.bits)];
  79223. if ((unsigned)(last.bits + thisx.bits) <= bits) break;
  79224. PULLBYTE();
  79225. }
  79226. DROPBITS(last.bits);
  79227. }
  79228. DROPBITS(thisx.bits);
  79229. state->length = (unsigned)thisx.val;
  79230. if ((int)(thisx.op) == 0) {
  79231. Tracevv((stderr, thisx.val >= 0x20 && thisx.val < 0x7f ?
  79232. "inflate: literal '%c'\n" :
  79233. "inflate: literal 0x%02x\n", thisx.val));
  79234. state->mode = LIT;
  79235. break;
  79236. }
  79237. if (thisx.op & 32) {
  79238. Tracevv((stderr, "inflate: end of block\n"));
  79239. state->mode = TYPE;
  79240. break;
  79241. }
  79242. if (thisx.op & 64) {
  79243. strm->msg = (char *)"invalid literal/length code";
  79244. state->mode = BAD;
  79245. break;
  79246. }
  79247. state->extra = (unsigned)(thisx.op) & 15;
  79248. state->mode = LENEXT;
  79249. case LENEXT:
  79250. if (state->extra) {
  79251. NEEDBITS(state->extra);
  79252. state->length += BITS(state->extra);
  79253. DROPBITS(state->extra);
  79254. }
  79255. Tracevv((stderr, "inflate: length %u\n", state->length));
  79256. state->mode = DIST;
  79257. case DIST:
  79258. for (;;) {
  79259. thisx = state->distcode[BITS(state->distbits)];
  79260. if ((unsigned)(thisx.bits) <= bits) break;
  79261. PULLBYTE();
  79262. }
  79263. if ((thisx.op & 0xf0) == 0) {
  79264. last = thisx;
  79265. for (;;) {
  79266. thisx = state->distcode[last.val +
  79267. (BITS(last.bits + last.op) >> last.bits)];
  79268. if ((unsigned)(last.bits + thisx.bits) <= bits) break;
  79269. PULLBYTE();
  79270. }
  79271. DROPBITS(last.bits);
  79272. }
  79273. DROPBITS(thisx.bits);
  79274. if (thisx.op & 64) {
  79275. strm->msg = (char *)"invalid distance code";
  79276. state->mode = BAD;
  79277. break;
  79278. }
  79279. state->offset = (unsigned)thisx.val;
  79280. state->extra = (unsigned)(thisx.op) & 15;
  79281. state->mode = DISTEXT;
  79282. case DISTEXT:
  79283. if (state->extra) {
  79284. NEEDBITS(state->extra);
  79285. state->offset += BITS(state->extra);
  79286. DROPBITS(state->extra);
  79287. }
  79288. #ifdef INFLATE_STRICT
  79289. if (state->offset > state->dmax) {
  79290. strm->msg = (char *)"invalid distance too far back";
  79291. state->mode = BAD;
  79292. break;
  79293. }
  79294. #endif
  79295. if (state->offset > state->whave + out - left) {
  79296. strm->msg = (char *)"invalid distance too far back";
  79297. state->mode = BAD;
  79298. break;
  79299. }
  79300. Tracevv((stderr, "inflate: distance %u\n", state->offset));
  79301. state->mode = MATCH;
  79302. case MATCH:
  79303. if (left == 0) goto inf_leave;
  79304. copy = out - left;
  79305. if (state->offset > copy) { /* copy from window */
  79306. copy = state->offset - copy;
  79307. if (copy > state->write) {
  79308. copy -= state->write;
  79309. from = state->window + (state->wsize - copy);
  79310. }
  79311. else
  79312. from = state->window + (state->write - copy);
  79313. if (copy > state->length) copy = state->length;
  79314. }
  79315. else { /* copy from output */
  79316. from = put - state->offset;
  79317. copy = state->length;
  79318. }
  79319. if (copy > left) copy = left;
  79320. left -= copy;
  79321. state->length -= copy;
  79322. do {
  79323. *put++ = *from++;
  79324. } while (--copy);
  79325. if (state->length == 0) state->mode = LEN;
  79326. break;
  79327. case LIT:
  79328. if (left == 0) goto inf_leave;
  79329. *put++ = (unsigned char)(state->length);
  79330. left--;
  79331. state->mode = LEN;
  79332. break;
  79333. case CHECK:
  79334. if (state->wrap) {
  79335. NEEDBITS(32);
  79336. out -= left;
  79337. strm->total_out += out;
  79338. state->total += out;
  79339. if (out)
  79340. strm->adler = state->check =
  79341. UPDATE(state->check, put - out, out);
  79342. out = left;
  79343. if ((
  79344. #ifdef GUNZIP
  79345. state->flags ? hold :
  79346. #endif
  79347. REVERSE(hold)) != state->check) {
  79348. strm->msg = (char *)"incorrect data check";
  79349. state->mode = BAD;
  79350. break;
  79351. }
  79352. INITBITS();
  79353. Tracev((stderr, "inflate: check matches trailer\n"));
  79354. }
  79355. #ifdef GUNZIP
  79356. state->mode = LENGTH;
  79357. case LENGTH:
  79358. if (state->wrap && state->flags) {
  79359. NEEDBITS(32);
  79360. if (hold != (state->total & 0xffffffffUL)) {
  79361. strm->msg = (char *)"incorrect length check";
  79362. state->mode = BAD;
  79363. break;
  79364. }
  79365. INITBITS();
  79366. Tracev((stderr, "inflate: length matches trailer\n"));
  79367. }
  79368. #endif
  79369. state->mode = DONE;
  79370. case DONE:
  79371. ret = Z_STREAM_END;
  79372. goto inf_leave;
  79373. case BAD:
  79374. ret = Z_DATA_ERROR;
  79375. goto inf_leave;
  79376. case MEM:
  79377. return Z_MEM_ERROR;
  79378. case SYNC:
  79379. default:
  79380. return Z_STREAM_ERROR;
  79381. }
  79382. inf_leave:
  79383. RESTORE();
  79384. if (state->wsize || (state->mode < CHECK && out != strm->avail_out))
  79385. if (updatewindow(strm, out)) {
  79386. state->mode = MEM;
  79387. return Z_MEM_ERROR;
  79388. }
  79389. in -= strm->avail_in;
  79390. out -= strm->avail_out;
  79391. strm->total_in += in;
  79392. strm->total_out += out;
  79393. state->total += out;
  79394. if (state->wrap && out)
  79395. strm->adler = state->check =
  79396. UPDATE(state->check, strm->next_out - out, out);
  79397. strm->data_type = state->bits + (state->last ? 64 : 0) +
  79398. (state->mode == TYPE ? 128 : 0);
  79399. if (((in == 0 && out == 0) || flush == Z_FINISH) && ret == Z_OK)
  79400. ret = Z_BUF_ERROR;
  79401. return ret;
  79402. }
  79403. int ZEXPORT inflateEnd (z_streamp strm)
  79404. {
  79405. struct inflate_state FAR *state;
  79406. if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0)
  79407. return Z_STREAM_ERROR;
  79408. state = (struct inflate_state FAR *)strm->state;
  79409. if (state->window != Z_NULL) ZFREE(strm, state->window);
  79410. ZFREE(strm, strm->state);
  79411. strm->state = Z_NULL;
  79412. Tracev((stderr, "inflate: end\n"));
  79413. return Z_OK;
  79414. }
  79415. int ZEXPORT inflateSetDictionary (z_streamp strm, const Bytef *dictionary, uInt dictLength)
  79416. {
  79417. struct inflate_state FAR *state;
  79418. unsigned long id_;
  79419. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  79420. state = (struct inflate_state FAR *)strm->state;
  79421. if (state->wrap != 0 && state->mode != DICT)
  79422. return Z_STREAM_ERROR;
  79423. if (state->mode == DICT) {
  79424. id_ = adler32(0L, Z_NULL, 0);
  79425. id_ = adler32(id_, dictionary, dictLength);
  79426. if (id_ != state->check)
  79427. return Z_DATA_ERROR;
  79428. }
  79429. if (updatewindow(strm, strm->avail_out)) {
  79430. state->mode = MEM;
  79431. return Z_MEM_ERROR;
  79432. }
  79433. if (dictLength > state->wsize) {
  79434. zmemcpy(state->window, dictionary + dictLength - state->wsize,
  79435. state->wsize);
  79436. state->whave = state->wsize;
  79437. }
  79438. else {
  79439. zmemcpy(state->window + state->wsize - dictLength, dictionary,
  79440. dictLength);
  79441. state->whave = dictLength;
  79442. }
  79443. state->havedict = 1;
  79444. Tracev((stderr, "inflate: dictionary set\n"));
  79445. return Z_OK;
  79446. }
  79447. int ZEXPORT inflateGetHeader (z_streamp strm, gz_headerp head)
  79448. {
  79449. struct inflate_state FAR *state;
  79450. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  79451. state = (struct inflate_state FAR *)strm->state;
  79452. if ((state->wrap & 2) == 0) return Z_STREAM_ERROR;
  79453. state->head = head;
  79454. head->done = 0;
  79455. return Z_OK;
  79456. }
  79457. local unsigned syncsearch (unsigned FAR *have, unsigned char FAR *buf, unsigned len)
  79458. {
  79459. unsigned got;
  79460. unsigned next;
  79461. got = *have;
  79462. next = 0;
  79463. while (next < len && got < 4) {
  79464. if ((int)(buf[next]) == (got < 2 ? 0 : 0xff))
  79465. got++;
  79466. else if (buf[next])
  79467. got = 0;
  79468. else
  79469. got = 4 - got;
  79470. next++;
  79471. }
  79472. *have = got;
  79473. return next;
  79474. }
  79475. int ZEXPORT inflateSync (z_streamp strm)
  79476. {
  79477. unsigned len; /* number of bytes to look at or looked at */
  79478. unsigned long in, out; /* temporary to save total_in and total_out */
  79479. unsigned char buf[4]; /* to restore bit buffer to byte string */
  79480. struct inflate_state FAR *state;
  79481. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  79482. state = (struct inflate_state FAR *)strm->state;
  79483. if (strm->avail_in == 0 && state->bits < 8) return Z_BUF_ERROR;
  79484. if (state->mode != SYNC) {
  79485. state->mode = SYNC;
  79486. state->hold <<= state->bits & 7;
  79487. state->bits -= state->bits & 7;
  79488. len = 0;
  79489. while (state->bits >= 8) {
  79490. buf[len++] = (unsigned char)(state->hold);
  79491. state->hold >>= 8;
  79492. state->bits -= 8;
  79493. }
  79494. state->have = 0;
  79495. syncsearch(&(state->have), buf, len);
  79496. }
  79497. len = syncsearch(&(state->have), strm->next_in, strm->avail_in);
  79498. strm->avail_in -= len;
  79499. strm->next_in += len;
  79500. strm->total_in += len;
  79501. if (state->have != 4) return Z_DATA_ERROR;
  79502. in = strm->total_in; out = strm->total_out;
  79503. inflateReset(strm);
  79504. strm->total_in = in; strm->total_out = out;
  79505. state->mode = TYPE;
  79506. return Z_OK;
  79507. }
  79508. int ZEXPORT inflateSyncPoint (z_streamp strm)
  79509. {
  79510. struct inflate_state FAR *state;
  79511. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  79512. state = (struct inflate_state FAR *)strm->state;
  79513. return state->mode == STORED && state->bits == 0;
  79514. }
  79515. int ZEXPORT inflateCopy(z_streamp dest, z_streamp source)
  79516. {
  79517. struct inflate_state FAR *state;
  79518. struct inflate_state FAR *copy;
  79519. unsigned char FAR *window;
  79520. unsigned wsize;
  79521. if (dest == Z_NULL || source == Z_NULL || source->state == Z_NULL ||
  79522. source->zalloc == (alloc_func)0 || source->zfree == (free_func)0)
  79523. return Z_STREAM_ERROR;
  79524. state = (struct inflate_state FAR *)source->state;
  79525. copy = (struct inflate_state FAR *)
  79526. ZALLOC(source, 1, sizeof(struct inflate_state));
  79527. if (copy == Z_NULL) return Z_MEM_ERROR;
  79528. window = Z_NULL;
  79529. if (state->window != Z_NULL) {
  79530. window = (unsigned char FAR *)
  79531. ZALLOC(source, 1U << state->wbits, sizeof(unsigned char));
  79532. if (window == Z_NULL) {
  79533. ZFREE(source, copy);
  79534. return Z_MEM_ERROR;
  79535. }
  79536. }
  79537. zmemcpy(dest, source, sizeof(z_stream));
  79538. zmemcpy(copy, state, sizeof(struct inflate_state));
  79539. if (state->lencode >= state->codes &&
  79540. state->lencode <= state->codes + ENOUGH - 1) {
  79541. copy->lencode = copy->codes + (state->lencode - state->codes);
  79542. copy->distcode = copy->codes + (state->distcode - state->codes);
  79543. }
  79544. copy->next = copy->codes + (state->next - state->codes);
  79545. if (window != Z_NULL) {
  79546. wsize = 1U << state->wbits;
  79547. zmemcpy(window, state->window, wsize);
  79548. }
  79549. copy->window = window;
  79550. dest->state = (struct internal_state FAR *)copy;
  79551. return Z_OK;
  79552. }
  79553. /*** End of inlined file: inflate.c ***/
  79554. /*** Start of inlined file: inftrees.c ***/
  79555. #define MAXBITS 15
  79556. const char inflate_copyright[] =
  79557. " inflate 1.2.3 Copyright 1995-2005 Mark Adler ";
  79558. int inflate_table (codetype type,
  79559. unsigned short FAR *lens,
  79560. unsigned codes,
  79561. code FAR * FAR *table,
  79562. unsigned FAR *bits,
  79563. unsigned short FAR *work)
  79564. {
  79565. unsigned len; /* a code's length in bits */
  79566. unsigned sym; /* index of code symbols */
  79567. unsigned min, max; /* minimum and maximum code lengths */
  79568. unsigned root; /* number of index bits for root table */
  79569. unsigned curr; /* number of index bits for current table */
  79570. unsigned drop; /* code bits to drop for sub-table */
  79571. int left; /* number of prefix codes available */
  79572. unsigned used; /* code entries in table used */
  79573. unsigned huff; /* Huffman code */
  79574. unsigned incr; /* for incrementing code, index */
  79575. unsigned fill; /* index for replicating entries */
  79576. unsigned low; /* low bits for current root entry */
  79577. unsigned mask; /* mask for low root bits */
  79578. code thisx; /* table entry for duplication */
  79579. code FAR *next; /* next available space in table */
  79580. const unsigned short FAR *base; /* base value table to use */
  79581. const unsigned short FAR *extra; /* extra bits table to use */
  79582. int end; /* use base and extra for symbol > end */
  79583. unsigned short count[MAXBITS+1]; /* number of codes of each length */
  79584. unsigned short offs[MAXBITS+1]; /* offsets in table for each length */
  79585. static const unsigned short lbase[31] = { /* Length codes 257..285 base */
  79586. 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
  79587. 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
  79588. static const unsigned short lext[31] = { /* Length codes 257..285 extra */
  79589. 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18,
  79590. 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 201, 196};
  79591. static const unsigned short dbase[32] = { /* Distance codes 0..29 base */
  79592. 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
  79593. 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
  79594. 8193, 12289, 16385, 24577, 0, 0};
  79595. static const unsigned short dext[32] = { /* Distance codes 0..29 extra */
  79596. 16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22,
  79597. 23, 23, 24, 24, 25, 25, 26, 26, 27, 27,
  79598. 28, 28, 29, 29, 64, 64};
  79599. for (len = 0; len <= MAXBITS; len++)
  79600. count[len] = 0;
  79601. for (sym = 0; sym < codes; sym++)
  79602. count[lens[sym]]++;
  79603. root = *bits;
  79604. for (max = MAXBITS; max >= 1; max--)
  79605. if (count[max] != 0) break;
  79606. if (root > max) root = max;
  79607. if (max == 0) { /* no symbols to code at all */
  79608. thisx.op = (unsigned char)64; /* invalid code marker */
  79609. thisx.bits = (unsigned char)1;
  79610. thisx.val = (unsigned short)0;
  79611. *(*table)++ = thisx; /* make a table to force an error */
  79612. *(*table)++ = thisx;
  79613. *bits = 1;
  79614. return 0; /* no symbols, but wait for decoding to report error */
  79615. }
  79616. for (min = 1; min <= MAXBITS; min++)
  79617. if (count[min] != 0) break;
  79618. if (root < min) root = min;
  79619. left = 1;
  79620. for (len = 1; len <= MAXBITS; len++) {
  79621. left <<= 1;
  79622. left -= count[len];
  79623. if (left < 0) return -1; /* over-subscribed */
  79624. }
  79625. if (left > 0 && (type == CODES || max != 1))
  79626. return -1; /* incomplete set */
  79627. offs[1] = 0;
  79628. for (len = 1; len < MAXBITS; len++)
  79629. offs[len + 1] = offs[len] + count[len];
  79630. for (sym = 0; sym < codes; sym++)
  79631. if (lens[sym] != 0) work[offs[lens[sym]]++] = (unsigned short)sym;
  79632. switch (type) {
  79633. case CODES:
  79634. base = extra = work; /* dummy value--not used */
  79635. end = 19;
  79636. break;
  79637. case LENS:
  79638. base = lbase;
  79639. base -= 257;
  79640. extra = lext;
  79641. extra -= 257;
  79642. end = 256;
  79643. break;
  79644. default: /* DISTS */
  79645. base = dbase;
  79646. extra = dext;
  79647. end = -1;
  79648. }
  79649. huff = 0; /* starting code */
  79650. sym = 0; /* starting code symbol */
  79651. len = min; /* starting code length */
  79652. next = *table; /* current table to fill in */
  79653. curr = root; /* current table index bits */
  79654. drop = 0; /* current bits to drop from code for index */
  79655. low = (unsigned)(-1); /* trigger new sub-table when len > root */
  79656. used = 1U << root; /* use root table entries */
  79657. mask = used - 1; /* mask for comparing low */
  79658. if (type == LENS && used >= ENOUGH - MAXD)
  79659. return 1;
  79660. for (;;) {
  79661. thisx.bits = (unsigned char)(len - drop);
  79662. if ((int)(work[sym]) < end) {
  79663. thisx.op = (unsigned char)0;
  79664. thisx.val = work[sym];
  79665. }
  79666. else if ((int)(work[sym]) > end) {
  79667. thisx.op = (unsigned char)(extra[work[sym]]);
  79668. thisx.val = base[work[sym]];
  79669. }
  79670. else {
  79671. thisx.op = (unsigned char)(32 + 64); /* end of block */
  79672. thisx.val = 0;
  79673. }
  79674. incr = 1U << (len - drop);
  79675. fill = 1U << curr;
  79676. min = fill; /* save offset to next table */
  79677. do {
  79678. fill -= incr;
  79679. next[(huff >> drop) + fill] = thisx;
  79680. } while (fill != 0);
  79681. incr = 1U << (len - 1);
  79682. while (huff & incr)
  79683. incr >>= 1;
  79684. if (incr != 0) {
  79685. huff &= incr - 1;
  79686. huff += incr;
  79687. }
  79688. else
  79689. huff = 0;
  79690. sym++;
  79691. if (--(count[len]) == 0) {
  79692. if (len == max) break;
  79693. len = lens[work[sym]];
  79694. }
  79695. if (len > root && (huff & mask) != low) {
  79696. if (drop == 0)
  79697. drop = root;
  79698. next += min; /* here min is 1 << curr */
  79699. curr = len - drop;
  79700. left = (int)(1 << curr);
  79701. while (curr + drop < max) {
  79702. left -= count[curr + drop];
  79703. if (left <= 0) break;
  79704. curr++;
  79705. left <<= 1;
  79706. }
  79707. used += 1U << curr;
  79708. if (type == LENS && used >= ENOUGH - MAXD)
  79709. return 1;
  79710. low = huff & mask;
  79711. (*table)[low].op = (unsigned char)curr;
  79712. (*table)[low].bits = (unsigned char)root;
  79713. (*table)[low].val = (unsigned short)(next - *table);
  79714. }
  79715. }
  79716. thisx.op = (unsigned char)64; /* invalid code marker */
  79717. thisx.bits = (unsigned char)(len - drop);
  79718. thisx.val = (unsigned short)0;
  79719. while (huff != 0) {
  79720. if (drop != 0 && (huff & mask) != low) {
  79721. drop = 0;
  79722. len = root;
  79723. next = *table;
  79724. thisx.bits = (unsigned char)len;
  79725. }
  79726. next[huff >> drop] = thisx;
  79727. incr = 1U << (len - 1);
  79728. while (huff & incr)
  79729. incr >>= 1;
  79730. if (incr != 0) {
  79731. huff &= incr - 1;
  79732. huff += incr;
  79733. }
  79734. else
  79735. huff = 0;
  79736. }
  79737. *table += used;
  79738. *bits = root;
  79739. return 0;
  79740. }
  79741. /*** End of inlined file: inftrees.c ***/
  79742. /*** Start of inlined file: trees.c ***/
  79743. #ifdef DEBUG
  79744. # include <ctype.h>
  79745. #endif
  79746. #define MAX_BL_BITS 7
  79747. #define END_BLOCK 256
  79748. #define REP_3_6 16
  79749. #define REPZ_3_10 17
  79750. #define REPZ_11_138 18
  79751. local const int extra_lbits[LENGTH_CODES] /* extra bits for each length code */
  79752. = {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};
  79753. local const int extra_dbits[D_CODES] /* extra bits for each distance code */
  79754. = {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};
  79755. local const int extra_blbits[BL_CODES]/* extra bits for each bit length code */
  79756. = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7};
  79757. local const uch bl_order[BL_CODES]
  79758. = {16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15};
  79759. #define Buf_size (8 * 2*sizeof(char))
  79760. #define DIST_CODE_LEN 512 /* see definition of array dist_code below */
  79761. #if defined(GEN_TREES_H) || !defined(STDC)
  79762. local ct_data static_ltree[L_CODES+2];
  79763. local ct_data static_dtree[D_CODES];
  79764. uch _dist_code[DIST_CODE_LEN];
  79765. uch _length_code[MAX_MATCH-MIN_MATCH+1];
  79766. local int base_length[LENGTH_CODES];
  79767. local int base_dist[D_CODES];
  79768. #else
  79769. /*** Start of inlined file: trees.h ***/
  79770. local const ct_data static_ltree[L_CODES+2] = {
  79771. {{ 12},{ 8}}, {{140},{ 8}}, {{ 76},{ 8}}, {{204},{ 8}}, {{ 44},{ 8}},
  79772. {{172},{ 8}}, {{108},{ 8}}, {{236},{ 8}}, {{ 28},{ 8}}, {{156},{ 8}},
  79773. {{ 92},{ 8}}, {{220},{ 8}}, {{ 60},{ 8}}, {{188},{ 8}}, {{124},{ 8}},
  79774. {{252},{ 8}}, {{ 2},{ 8}}, {{130},{ 8}}, {{ 66},{ 8}}, {{194},{ 8}},
  79775. {{ 34},{ 8}}, {{162},{ 8}}, {{ 98},{ 8}}, {{226},{ 8}}, {{ 18},{ 8}},
  79776. {{146},{ 8}}, {{ 82},{ 8}}, {{210},{ 8}}, {{ 50},{ 8}}, {{178},{ 8}},
  79777. {{114},{ 8}}, {{242},{ 8}}, {{ 10},{ 8}}, {{138},{ 8}}, {{ 74},{ 8}},
  79778. {{202},{ 8}}, {{ 42},{ 8}}, {{170},{ 8}}, {{106},{ 8}}, {{234},{ 8}},
  79779. {{ 26},{ 8}}, {{154},{ 8}}, {{ 90},{ 8}}, {{218},{ 8}}, {{ 58},{ 8}},
  79780. {{186},{ 8}}, {{122},{ 8}}, {{250},{ 8}}, {{ 6},{ 8}}, {{134},{ 8}},
  79781. {{ 70},{ 8}}, {{198},{ 8}}, {{ 38},{ 8}}, {{166},{ 8}}, {{102},{ 8}},
  79782. {{230},{ 8}}, {{ 22},{ 8}}, {{150},{ 8}}, {{ 86},{ 8}}, {{214},{ 8}},
  79783. {{ 54},{ 8}}, {{182},{ 8}}, {{118},{ 8}}, {{246},{ 8}}, {{ 14},{ 8}},
  79784. {{142},{ 8}}, {{ 78},{ 8}}, {{206},{ 8}}, {{ 46},{ 8}}, {{174},{ 8}},
  79785. {{110},{ 8}}, {{238},{ 8}}, {{ 30},{ 8}}, {{158},{ 8}}, {{ 94},{ 8}},
  79786. {{222},{ 8}}, {{ 62},{ 8}}, {{190},{ 8}}, {{126},{ 8}}, {{254},{ 8}},
  79787. {{ 1},{ 8}}, {{129},{ 8}}, {{ 65},{ 8}}, {{193},{ 8}}, {{ 33},{ 8}},
  79788. {{161},{ 8}}, {{ 97},{ 8}}, {{225},{ 8}}, {{ 17},{ 8}}, {{145},{ 8}},
  79789. {{ 81},{ 8}}, {{209},{ 8}}, {{ 49},{ 8}}, {{177},{ 8}}, {{113},{ 8}},
  79790. {{241},{ 8}}, {{ 9},{ 8}}, {{137},{ 8}}, {{ 73},{ 8}}, {{201},{ 8}},
  79791. {{ 41},{ 8}}, {{169},{ 8}}, {{105},{ 8}}, {{233},{ 8}}, {{ 25},{ 8}},
  79792. {{153},{ 8}}, {{ 89},{ 8}}, {{217},{ 8}}, {{ 57},{ 8}}, {{185},{ 8}},
  79793. {{121},{ 8}}, {{249},{ 8}}, {{ 5},{ 8}}, {{133},{ 8}}, {{ 69},{ 8}},
  79794. {{197},{ 8}}, {{ 37},{ 8}}, {{165},{ 8}}, {{101},{ 8}}, {{229},{ 8}},
  79795. {{ 21},{ 8}}, {{149},{ 8}}, {{ 85},{ 8}}, {{213},{ 8}}, {{ 53},{ 8}},
  79796. {{181},{ 8}}, {{117},{ 8}}, {{245},{ 8}}, {{ 13},{ 8}}, {{141},{ 8}},
  79797. {{ 77},{ 8}}, {{205},{ 8}}, {{ 45},{ 8}}, {{173},{ 8}}, {{109},{ 8}},
  79798. {{237},{ 8}}, {{ 29},{ 8}}, {{157},{ 8}}, {{ 93},{ 8}}, {{221},{ 8}},
  79799. {{ 61},{ 8}}, {{189},{ 8}}, {{125},{ 8}}, {{253},{ 8}}, {{ 19},{ 9}},
  79800. {{275},{ 9}}, {{147},{ 9}}, {{403},{ 9}}, {{ 83},{ 9}}, {{339},{ 9}},
  79801. {{211},{ 9}}, {{467},{ 9}}, {{ 51},{ 9}}, {{307},{ 9}}, {{179},{ 9}},
  79802. {{435},{ 9}}, {{115},{ 9}}, {{371},{ 9}}, {{243},{ 9}}, {{499},{ 9}},
  79803. {{ 11},{ 9}}, {{267},{ 9}}, {{139},{ 9}}, {{395},{ 9}}, {{ 75},{ 9}},
  79804. {{331},{ 9}}, {{203},{ 9}}, {{459},{ 9}}, {{ 43},{ 9}}, {{299},{ 9}},
  79805. {{171},{ 9}}, {{427},{ 9}}, {{107},{ 9}}, {{363},{ 9}}, {{235},{ 9}},
  79806. {{491},{ 9}}, {{ 27},{ 9}}, {{283},{ 9}}, {{155},{ 9}}, {{411},{ 9}},
  79807. {{ 91},{ 9}}, {{347},{ 9}}, {{219},{ 9}}, {{475},{ 9}}, {{ 59},{ 9}},
  79808. {{315},{ 9}}, {{187},{ 9}}, {{443},{ 9}}, {{123},{ 9}}, {{379},{ 9}},
  79809. {{251},{ 9}}, {{507},{ 9}}, {{ 7},{ 9}}, {{263},{ 9}}, {{135},{ 9}},
  79810. {{391},{ 9}}, {{ 71},{ 9}}, {{327},{ 9}}, {{199},{ 9}}, {{455},{ 9}},
  79811. {{ 39},{ 9}}, {{295},{ 9}}, {{167},{ 9}}, {{423},{ 9}}, {{103},{ 9}},
  79812. {{359},{ 9}}, {{231},{ 9}}, {{487},{ 9}}, {{ 23},{ 9}}, {{279},{ 9}},
  79813. {{151},{ 9}}, {{407},{ 9}}, {{ 87},{ 9}}, {{343},{ 9}}, {{215},{ 9}},
  79814. {{471},{ 9}}, {{ 55},{ 9}}, {{311},{ 9}}, {{183},{ 9}}, {{439},{ 9}},
  79815. {{119},{ 9}}, {{375},{ 9}}, {{247},{ 9}}, {{503},{ 9}}, {{ 15},{ 9}},
  79816. {{271},{ 9}}, {{143},{ 9}}, {{399},{ 9}}, {{ 79},{ 9}}, {{335},{ 9}},
  79817. {{207},{ 9}}, {{463},{ 9}}, {{ 47},{ 9}}, {{303},{ 9}}, {{175},{ 9}},
  79818. {{431},{ 9}}, {{111},{ 9}}, {{367},{ 9}}, {{239},{ 9}}, {{495},{ 9}},
  79819. {{ 31},{ 9}}, {{287},{ 9}}, {{159},{ 9}}, {{415},{ 9}}, {{ 95},{ 9}},
  79820. {{351},{ 9}}, {{223},{ 9}}, {{479},{ 9}}, {{ 63},{ 9}}, {{319},{ 9}},
  79821. {{191},{ 9}}, {{447},{ 9}}, {{127},{ 9}}, {{383},{ 9}}, {{255},{ 9}},
  79822. {{511},{ 9}}, {{ 0},{ 7}}, {{ 64},{ 7}}, {{ 32},{ 7}}, {{ 96},{ 7}},
  79823. {{ 16},{ 7}}, {{ 80},{ 7}}, {{ 48},{ 7}}, {{112},{ 7}}, {{ 8},{ 7}},
  79824. {{ 72},{ 7}}, {{ 40},{ 7}}, {{104},{ 7}}, {{ 24},{ 7}}, {{ 88},{ 7}},
  79825. {{ 56},{ 7}}, {{120},{ 7}}, {{ 4},{ 7}}, {{ 68},{ 7}}, {{ 36},{ 7}},
  79826. {{100},{ 7}}, {{ 20},{ 7}}, {{ 84},{ 7}}, {{ 52},{ 7}}, {{116},{ 7}},
  79827. {{ 3},{ 8}}, {{131},{ 8}}, {{ 67},{ 8}}, {{195},{ 8}}, {{ 35},{ 8}},
  79828. {{163},{ 8}}, {{ 99},{ 8}}, {{227},{ 8}}
  79829. };
  79830. local const ct_data static_dtree[D_CODES] = {
  79831. {{ 0},{ 5}}, {{16},{ 5}}, {{ 8},{ 5}}, {{24},{ 5}}, {{ 4},{ 5}},
  79832. {{20},{ 5}}, {{12},{ 5}}, {{28},{ 5}}, {{ 2},{ 5}}, {{18},{ 5}},
  79833. {{10},{ 5}}, {{26},{ 5}}, {{ 6},{ 5}}, {{22},{ 5}}, {{14},{ 5}},
  79834. {{30},{ 5}}, {{ 1},{ 5}}, {{17},{ 5}}, {{ 9},{ 5}}, {{25},{ 5}},
  79835. {{ 5},{ 5}}, {{21},{ 5}}, {{13},{ 5}}, {{29},{ 5}}, {{ 3},{ 5}},
  79836. {{19},{ 5}}, {{11},{ 5}}, {{27},{ 5}}, {{ 7},{ 5}}, {{23},{ 5}}
  79837. };
  79838. const uch _dist_code[DIST_CODE_LEN] = {
  79839. 0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8,
  79840. 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10,
  79841. 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
  79842. 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
  79843. 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13,
  79844. 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
  79845. 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  79846. 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  79847. 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  79848. 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15,
  79849. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
  79850. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
  79851. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 0, 16, 17,
  79852. 18, 18, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22,
  79853. 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
  79854. 24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
  79855. 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
  79856. 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27,
  79857. 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
  79858. 27, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
  79859. 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
  79860. 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
  79861. 28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
  79862. 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
  79863. 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
  79864. 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29
  79865. };
  79866. const uch _length_code[MAX_MATCH-MIN_MATCH+1]= {
  79867. 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, 12,
  79868. 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16,
  79869. 17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19,
  79870. 19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
  79871. 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22,
  79872. 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23,
  79873. 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
  79874. 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
  79875. 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
  79876. 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, 26, 26,
  79877. 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
  79878. 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
  79879. 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28
  79880. };
  79881. local const int base_length[LENGTH_CODES] = {
  79882. 0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 32, 40, 48, 56,
  79883. 64, 80, 96, 112, 128, 160, 192, 224, 0
  79884. };
  79885. local const int base_dist[D_CODES] = {
  79886. 0, 1, 2, 3, 4, 6, 8, 12, 16, 24,
  79887. 32, 48, 64, 96, 128, 192, 256, 384, 512, 768,
  79888. 1024, 1536, 2048, 3072, 4096, 6144, 8192, 12288, 16384, 24576
  79889. };
  79890. /*** End of inlined file: trees.h ***/
  79891. #endif /* GEN_TREES_H */
  79892. struct static_tree_desc_s {
  79893. const ct_data *static_tree; /* static tree or NULL */
  79894. const intf *extra_bits; /* extra bits for each code or NULL */
  79895. int extra_base; /* base index for extra_bits */
  79896. int elems; /* max number of elements in the tree */
  79897. int max_length; /* max bit length for the codes */
  79898. };
  79899. local static_tree_desc static_l_desc =
  79900. {static_ltree, extra_lbits, LITERALS+1, L_CODES, MAX_BITS};
  79901. local static_tree_desc static_d_desc =
  79902. {static_dtree, extra_dbits, 0, D_CODES, MAX_BITS};
  79903. local static_tree_desc static_bl_desc =
  79904. {(const ct_data *)0, extra_blbits, 0, BL_CODES, MAX_BL_BITS};
  79905. local void tr_static_init OF((void));
  79906. local void init_block OF((deflate_state *s));
  79907. local void pqdownheap OF((deflate_state *s, ct_data *tree, int k));
  79908. local void gen_bitlen OF((deflate_state *s, tree_desc *desc));
  79909. local void gen_codes OF((ct_data *tree, int max_code, ushf *bl_count));
  79910. local void build_tree OF((deflate_state *s, tree_desc *desc));
  79911. local void scan_tree OF((deflate_state *s, ct_data *tree, int max_code));
  79912. local void send_tree OF((deflate_state *s, ct_data *tree, int max_code));
  79913. local int build_bl_tree OF((deflate_state *s));
  79914. local void send_all_trees OF((deflate_state *s, int lcodes, int dcodes,
  79915. int blcodes));
  79916. local void compress_block OF((deflate_state *s, ct_data *ltree,
  79917. ct_data *dtree));
  79918. local void set_data_type OF((deflate_state *s));
  79919. local unsigned bi_reverse OF((unsigned value, int length));
  79920. local void bi_windup OF((deflate_state *s));
  79921. local void bi_flush OF((deflate_state *s));
  79922. local void copy_block OF((deflate_state *s, charf *buf, unsigned len,
  79923. int header));
  79924. #ifdef GEN_TREES_H
  79925. local void gen_trees_header OF((void));
  79926. #endif
  79927. #ifndef DEBUG
  79928. # define send_code(s, c, tree) send_bits(s, tree[c].Code, tree[c].Len)
  79929. #else /* DEBUG */
  79930. # define send_code(s, c, tree) \
  79931. { if (z_verbose>2) fprintf(stderr,"\ncd %3d ",(c)); \
  79932. send_bits(s, tree[c].Code, tree[c].Len); }
  79933. #endif
  79934. #define put_short(s, w) { \
  79935. put_byte(s, (uch)((w) & 0xff)); \
  79936. put_byte(s, (uch)((ush)(w) >> 8)); \
  79937. }
  79938. #ifdef DEBUG
  79939. local void send_bits OF((deflate_state *s, int value, int length));
  79940. local void send_bits (deflate_state *s, int value, int length)
  79941. {
  79942. Tracevv((stderr," l %2d v %4x ", length, value));
  79943. Assert(length > 0 && length <= 15, "invalid length");
  79944. s->bits_sent += (ulg)length;
  79945. if (s->bi_valid > (int)Buf_size - length) {
  79946. s->bi_buf |= (value << s->bi_valid);
  79947. put_short(s, s->bi_buf);
  79948. s->bi_buf = (ush)value >> (Buf_size - s->bi_valid);
  79949. s->bi_valid += length - Buf_size;
  79950. } else {
  79951. s->bi_buf |= value << s->bi_valid;
  79952. s->bi_valid += length;
  79953. }
  79954. }
  79955. #else /* !DEBUG */
  79956. #define send_bits(s, value, length) \
  79957. { int len = length;\
  79958. if (s->bi_valid > (int)Buf_size - len) {\
  79959. int val = value;\
  79960. s->bi_buf |= (val << s->bi_valid);\
  79961. put_short(s, s->bi_buf);\
  79962. s->bi_buf = (ush)val >> (Buf_size - s->bi_valid);\
  79963. s->bi_valid += len - Buf_size;\
  79964. } else {\
  79965. s->bi_buf |= (value) << s->bi_valid;\
  79966. s->bi_valid += len;\
  79967. }\
  79968. }
  79969. #endif /* DEBUG */
  79970. local void tr_static_init()
  79971. {
  79972. #if defined(GEN_TREES_H) || !defined(STDC)
  79973. static int static_init_done = 0;
  79974. int n; /* iterates over tree elements */
  79975. int bits; /* bit counter */
  79976. int length; /* length value */
  79977. int code; /* code value */
  79978. int dist; /* distance index */
  79979. ush bl_count[MAX_BITS+1];
  79980. if (static_init_done) return;
  79981. static_l_desc.static_tree = static_ltree;
  79982. static_l_desc.extra_bits = extra_lbits;
  79983. static_d_desc.static_tree = static_dtree;
  79984. static_d_desc.extra_bits = extra_dbits;
  79985. static_bl_desc.extra_bits = extra_blbits;
  79986. length = 0;
  79987. for (code = 0; code < LENGTH_CODES-1; code++) {
  79988. base_length[code] = length;
  79989. for (n = 0; n < (1<<extra_lbits[code]); n++) {
  79990. _length_code[length++] = (uch)code;
  79991. }
  79992. }
  79993. Assert (length == 256, "tr_static_init: length != 256");
  79994. _length_code[length-1] = (uch)code;
  79995. dist = 0;
  79996. for (code = 0 ; code < 16; code++) {
  79997. base_dist[code] = dist;
  79998. for (n = 0; n < (1<<extra_dbits[code]); n++) {
  79999. _dist_code[dist++] = (uch)code;
  80000. }
  80001. }
  80002. Assert (dist == 256, "tr_static_init: dist != 256");
  80003. dist >>= 7; /* from now on, all distances are divided by 128 */
  80004. for ( ; code < D_CODES; code++) {
  80005. base_dist[code] = dist << 7;
  80006. for (n = 0; n < (1<<(extra_dbits[code]-7)); n++) {
  80007. _dist_code[256 + dist++] = (uch)code;
  80008. }
  80009. }
  80010. Assert (dist == 256, "tr_static_init: 256+dist != 512");
  80011. for (bits = 0; bits <= MAX_BITS; bits++) bl_count[bits] = 0;
  80012. n = 0;
  80013. while (n <= 143) static_ltree[n++].Len = 8, bl_count[8]++;
  80014. while (n <= 255) static_ltree[n++].Len = 9, bl_count[9]++;
  80015. while (n <= 279) static_ltree[n++].Len = 7, bl_count[7]++;
  80016. while (n <= 287) static_ltree[n++].Len = 8, bl_count[8]++;
  80017. gen_codes((ct_data *)static_ltree, L_CODES+1, bl_count);
  80018. for (n = 0; n < D_CODES; n++) {
  80019. static_dtree[n].Len = 5;
  80020. static_dtree[n].Code = bi_reverse((unsigned)n, 5);
  80021. }
  80022. static_init_done = 1;
  80023. # ifdef GEN_TREES_H
  80024. gen_trees_header();
  80025. # endif
  80026. #endif /* defined(GEN_TREES_H) || !defined(STDC) */
  80027. }
  80028. #ifdef GEN_TREES_H
  80029. # ifndef DEBUG
  80030. # include <stdio.h>
  80031. # endif
  80032. # define SEPARATOR(i, last, width) \
  80033. ((i) == (last)? "\n};\n\n" : \
  80034. ((i) % (width) == (width)-1 ? ",\n" : ", "))
  80035. void gen_trees_header()
  80036. {
  80037. FILE *header = fopen("trees.h", "w");
  80038. int i;
  80039. Assert (header != NULL, "Can't open trees.h");
  80040. fprintf(header,
  80041. "/* header created automatically with -DGEN_TREES_H */\n\n");
  80042. fprintf(header, "local const ct_data static_ltree[L_CODES+2] = {\n");
  80043. for (i = 0; i < L_CODES+2; i++) {
  80044. fprintf(header, "{{%3u},{%3u}}%s", static_ltree[i].Code,
  80045. static_ltree[i].Len, SEPARATOR(i, L_CODES+1, 5));
  80046. }
  80047. fprintf(header, "local const ct_data static_dtree[D_CODES] = {\n");
  80048. for (i = 0; i < D_CODES; i++) {
  80049. fprintf(header, "{{%2u},{%2u}}%s", static_dtree[i].Code,
  80050. static_dtree[i].Len, SEPARATOR(i, D_CODES-1, 5));
  80051. }
  80052. fprintf(header, "const uch _dist_code[DIST_CODE_LEN] = {\n");
  80053. for (i = 0; i < DIST_CODE_LEN; i++) {
  80054. fprintf(header, "%2u%s", _dist_code[i],
  80055. SEPARATOR(i, DIST_CODE_LEN-1, 20));
  80056. }
  80057. fprintf(header, "const uch _length_code[MAX_MATCH-MIN_MATCH+1]= {\n");
  80058. for (i = 0; i < MAX_MATCH-MIN_MATCH+1; i++) {
  80059. fprintf(header, "%2u%s", _length_code[i],
  80060. SEPARATOR(i, MAX_MATCH-MIN_MATCH, 20));
  80061. }
  80062. fprintf(header, "local const int base_length[LENGTH_CODES] = {\n");
  80063. for (i = 0; i < LENGTH_CODES; i++) {
  80064. fprintf(header, "%1u%s", base_length[i],
  80065. SEPARATOR(i, LENGTH_CODES-1, 20));
  80066. }
  80067. fprintf(header, "local const int base_dist[D_CODES] = {\n");
  80068. for (i = 0; i < D_CODES; i++) {
  80069. fprintf(header, "%5u%s", base_dist[i],
  80070. SEPARATOR(i, D_CODES-1, 10));
  80071. }
  80072. fclose(header);
  80073. }
  80074. #endif /* GEN_TREES_H */
  80075. void _tr_init(deflate_state *s)
  80076. {
  80077. tr_static_init();
  80078. s->l_desc.dyn_tree = s->dyn_ltree;
  80079. s->l_desc.stat_desc = &static_l_desc;
  80080. s->d_desc.dyn_tree = s->dyn_dtree;
  80081. s->d_desc.stat_desc = &static_d_desc;
  80082. s->bl_desc.dyn_tree = s->bl_tree;
  80083. s->bl_desc.stat_desc = &static_bl_desc;
  80084. s->bi_buf = 0;
  80085. s->bi_valid = 0;
  80086. s->last_eob_len = 8; /* enough lookahead for inflate */
  80087. #ifdef DEBUG
  80088. s->compressed_len = 0L;
  80089. s->bits_sent = 0L;
  80090. #endif
  80091. init_block(s);
  80092. }
  80093. local void init_block (deflate_state *s)
  80094. {
  80095. int n; /* iterates over tree elements */
  80096. for (n = 0; n < L_CODES; n++) s->dyn_ltree[n].Freq = 0;
  80097. for (n = 0; n < D_CODES; n++) s->dyn_dtree[n].Freq = 0;
  80098. for (n = 0; n < BL_CODES; n++) s->bl_tree[n].Freq = 0;
  80099. s->dyn_ltree[END_BLOCK].Freq = 1;
  80100. s->opt_len = s->static_len = 0L;
  80101. s->last_lit = s->matches = 0;
  80102. }
  80103. #define SMALLEST 1
  80104. #define pqremove(s, tree, top) \
  80105. {\
  80106. top = s->heap[SMALLEST]; \
  80107. s->heap[SMALLEST] = s->heap[s->heap_len--]; \
  80108. pqdownheap(s, tree, SMALLEST); \
  80109. }
  80110. #define smaller(tree, n, m, depth) \
  80111. (tree[n].Freq < tree[m].Freq || \
  80112. (tree[n].Freq == tree[m].Freq && depth[n] <= depth[m]))
  80113. local void pqdownheap (deflate_state *s,
  80114. ct_data *tree, /* the tree to restore */
  80115. int k) /* node to move down */
  80116. {
  80117. int v = s->heap[k];
  80118. int j = k << 1; /* left son of k */
  80119. while (j <= s->heap_len) {
  80120. if (j < s->heap_len &&
  80121. smaller(tree, s->heap[j+1], s->heap[j], s->depth)) {
  80122. j++;
  80123. }
  80124. if (smaller(tree, v, s->heap[j], s->depth)) break;
  80125. s->heap[k] = s->heap[j]; k = j;
  80126. j <<= 1;
  80127. }
  80128. s->heap[k] = v;
  80129. }
  80130. local void gen_bitlen (deflate_state *s, tree_desc *desc)
  80131. {
  80132. ct_data *tree = desc->dyn_tree;
  80133. int max_code = desc->max_code;
  80134. const ct_data *stree = desc->stat_desc->static_tree;
  80135. const intf *extra = desc->stat_desc->extra_bits;
  80136. int base = desc->stat_desc->extra_base;
  80137. int max_length = desc->stat_desc->max_length;
  80138. int h; /* heap index */
  80139. int n, m; /* iterate over the tree elements */
  80140. int bits; /* bit length */
  80141. int xbits; /* extra bits */
  80142. ush f; /* frequency */
  80143. int overflow = 0; /* number of elements with bit length too large */
  80144. for (bits = 0; bits <= MAX_BITS; bits++) s->bl_count[bits] = 0;
  80145. tree[s->heap[s->heap_max]].Len = 0; /* root of the heap */
  80146. for (h = s->heap_max+1; h < HEAP_SIZE; h++) {
  80147. n = s->heap[h];
  80148. bits = tree[tree[n].Dad].Len + 1;
  80149. if (bits > max_length) bits = max_length, overflow++;
  80150. tree[n].Len = (ush)bits;
  80151. if (n > max_code) continue; /* not a leaf node */
  80152. s->bl_count[bits]++;
  80153. xbits = 0;
  80154. if (n >= base) xbits = extra[n-base];
  80155. f = tree[n].Freq;
  80156. s->opt_len += (ulg)f * (bits + xbits);
  80157. if (stree) s->static_len += (ulg)f * (stree[n].Len + xbits);
  80158. }
  80159. if (overflow == 0) return;
  80160. Trace((stderr,"\nbit length overflow\n"));
  80161. do {
  80162. bits = max_length-1;
  80163. while (s->bl_count[bits] == 0) bits--;
  80164. s->bl_count[bits]--; /* move one leaf down the tree */
  80165. s->bl_count[bits+1] += 2; /* move one overflow item as its brother */
  80166. s->bl_count[max_length]--;
  80167. overflow -= 2;
  80168. } while (overflow > 0);
  80169. for (bits = max_length; bits != 0; bits--) {
  80170. n = s->bl_count[bits];
  80171. while (n != 0) {
  80172. m = s->heap[--h];
  80173. if (m > max_code) continue;
  80174. if ((unsigned) tree[m].Len != (unsigned) bits) {
  80175. Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits));
  80176. s->opt_len += ((long)bits - (long)tree[m].Len)
  80177. *(long)tree[m].Freq;
  80178. tree[m].Len = (ush)bits;
  80179. }
  80180. n--;
  80181. }
  80182. }
  80183. }
  80184. local void gen_codes (ct_data *tree, /* the tree to decorate */
  80185. int max_code, /* largest code with non zero frequency */
  80186. ushf *bl_count) /* number of codes at each bit length */
  80187. {
  80188. ush next_code[MAX_BITS+1]; /* next code value for each bit length */
  80189. ush code = 0; /* running code value */
  80190. int bits; /* bit index */
  80191. int n; /* code index */
  80192. for (bits = 1; bits <= MAX_BITS; bits++) {
  80193. next_code[bits] = code = (code + bl_count[bits-1]) << 1;
  80194. }
  80195. Assert (code + bl_count[MAX_BITS]-1 == (1<<MAX_BITS)-1,
  80196. "inconsistent bit counts");
  80197. Tracev((stderr,"\ngen_codes: max_code %d ", max_code));
  80198. for (n = 0; n <= max_code; n++) {
  80199. int len = tree[n].Len;
  80200. if (len == 0) continue;
  80201. tree[n].Code = bi_reverse(next_code[len]++, len);
  80202. Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ",
  80203. n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len]-1));
  80204. }
  80205. }
  80206. local void build_tree (deflate_state *s,
  80207. tree_desc *desc) /* the tree descriptor */
  80208. {
  80209. ct_data *tree = desc->dyn_tree;
  80210. const ct_data *stree = desc->stat_desc->static_tree;
  80211. int elems = desc->stat_desc->elems;
  80212. int n, m; /* iterate over heap elements */
  80213. int max_code = -1; /* largest code with non zero frequency */
  80214. int node; /* new node being created */
  80215. s->heap_len = 0, s->heap_max = HEAP_SIZE;
  80216. for (n = 0; n < elems; n++) {
  80217. if (tree[n].Freq != 0) {
  80218. s->heap[++(s->heap_len)] = max_code = n;
  80219. s->depth[n] = 0;
  80220. } else {
  80221. tree[n].Len = 0;
  80222. }
  80223. }
  80224. while (s->heap_len < 2) {
  80225. node = s->heap[++(s->heap_len)] = (max_code < 2 ? ++max_code : 0);
  80226. tree[node].Freq = 1;
  80227. s->depth[node] = 0;
  80228. s->opt_len--; if (stree) s->static_len -= stree[node].Len;
  80229. }
  80230. desc->max_code = max_code;
  80231. for (n = s->heap_len/2; n >= 1; n--) pqdownheap(s, tree, n);
  80232. node = elems; /* next internal node of the tree */
  80233. do {
  80234. pqremove(s, tree, n); /* n = node of least frequency */
  80235. m = s->heap[SMALLEST]; /* m = node of next least frequency */
  80236. s->heap[--(s->heap_max)] = n; /* keep the nodes sorted by frequency */
  80237. s->heap[--(s->heap_max)] = m;
  80238. tree[node].Freq = tree[n].Freq + tree[m].Freq;
  80239. s->depth[node] = (uch)((s->depth[n] >= s->depth[m] ?
  80240. s->depth[n] : s->depth[m]) + 1);
  80241. tree[n].Dad = tree[m].Dad = (ush)node;
  80242. #ifdef DUMP_BL_TREE
  80243. if (tree == s->bl_tree) {
  80244. fprintf(stderr,"\nnode %d(%d), sons %d(%d) %d(%d)",
  80245. node, tree[node].Freq, n, tree[n].Freq, m, tree[m].Freq);
  80246. }
  80247. #endif
  80248. s->heap[SMALLEST] = node++;
  80249. pqdownheap(s, tree, SMALLEST);
  80250. } while (s->heap_len >= 2);
  80251. s->heap[--(s->heap_max)] = s->heap[SMALLEST];
  80252. gen_bitlen(s, (tree_desc *)desc);
  80253. gen_codes ((ct_data *)tree, max_code, s->bl_count);
  80254. }
  80255. local void scan_tree (deflate_state *s,
  80256. ct_data *tree, /* the tree to be scanned */
  80257. int max_code) /* and its largest code of non zero frequency */
  80258. {
  80259. int n; /* iterates over all tree elements */
  80260. int prevlen = -1; /* last emitted length */
  80261. int curlen; /* length of current code */
  80262. int nextlen = tree[0].Len; /* length of next code */
  80263. int count = 0; /* repeat count of the current code */
  80264. int max_count = 7; /* max repeat count */
  80265. int min_count = 4; /* min repeat count */
  80266. if (nextlen == 0) max_count = 138, min_count = 3;
  80267. tree[max_code+1].Len = (ush)0xffff; /* guard */
  80268. for (n = 0; n <= max_code; n++) {
  80269. curlen = nextlen; nextlen = tree[n+1].Len;
  80270. if (++count < max_count && curlen == nextlen) {
  80271. continue;
  80272. } else if (count < min_count) {
  80273. s->bl_tree[curlen].Freq += count;
  80274. } else if (curlen != 0) {
  80275. if (curlen != prevlen) s->bl_tree[curlen].Freq++;
  80276. s->bl_tree[REP_3_6].Freq++;
  80277. } else if (count <= 10) {
  80278. s->bl_tree[REPZ_3_10].Freq++;
  80279. } else {
  80280. s->bl_tree[REPZ_11_138].Freq++;
  80281. }
  80282. count = 0; prevlen = curlen;
  80283. if (nextlen == 0) {
  80284. max_count = 138, min_count = 3;
  80285. } else if (curlen == nextlen) {
  80286. max_count = 6, min_count = 3;
  80287. } else {
  80288. max_count = 7, min_count = 4;
  80289. }
  80290. }
  80291. }
  80292. local void send_tree (deflate_state *s,
  80293. ct_data *tree, /* the tree to be scanned */
  80294. int max_code) /* and its largest code of non zero frequency */
  80295. {
  80296. int n; /* iterates over all tree elements */
  80297. int prevlen = -1; /* last emitted length */
  80298. int curlen; /* length of current code */
  80299. int nextlen = tree[0].Len; /* length of next code */
  80300. int count = 0; /* repeat count of the current code */
  80301. int max_count = 7; /* max repeat count */
  80302. int min_count = 4; /* min repeat count */
  80303. /* guard already set */
  80304. if (nextlen == 0) max_count = 138, min_count = 3;
  80305. for (n = 0; n <= max_code; n++) {
  80306. curlen = nextlen; nextlen = tree[n+1].Len;
  80307. if (++count < max_count && curlen == nextlen) {
  80308. continue;
  80309. } else if (count < min_count) {
  80310. do { send_code(s, curlen, s->bl_tree); } while (--count != 0);
  80311. } else if (curlen != 0) {
  80312. if (curlen != prevlen) {
  80313. send_code(s, curlen, s->bl_tree); count--;
  80314. }
  80315. Assert(count >= 3 && count <= 6, " 3_6?");
  80316. send_code(s, REP_3_6, s->bl_tree); send_bits(s, count-3, 2);
  80317. } else if (count <= 10) {
  80318. send_code(s, REPZ_3_10, s->bl_tree); send_bits(s, count-3, 3);
  80319. } else {
  80320. send_code(s, REPZ_11_138, s->bl_tree); send_bits(s, count-11, 7);
  80321. }
  80322. count = 0; prevlen = curlen;
  80323. if (nextlen == 0) {
  80324. max_count = 138, min_count = 3;
  80325. } else if (curlen == nextlen) {
  80326. max_count = 6, min_count = 3;
  80327. } else {
  80328. max_count = 7, min_count = 4;
  80329. }
  80330. }
  80331. }
  80332. local int build_bl_tree (deflate_state *s)
  80333. {
  80334. int max_blindex; /* index of last bit length code of non zero freq */
  80335. scan_tree(s, (ct_data *)s->dyn_ltree, s->l_desc.max_code);
  80336. scan_tree(s, (ct_data *)s->dyn_dtree, s->d_desc.max_code);
  80337. build_tree(s, (tree_desc *)(&(s->bl_desc)));
  80338. for (max_blindex = BL_CODES-1; max_blindex >= 3; max_blindex--) {
  80339. if (s->bl_tree[bl_order[max_blindex]].Len != 0) break;
  80340. }
  80341. s->opt_len += 3*(max_blindex+1) + 5+5+4;
  80342. Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld",
  80343. s->opt_len, s->static_len));
  80344. return max_blindex;
  80345. }
  80346. local void send_all_trees (deflate_state *s,
  80347. int lcodes, int dcodes, int blcodes) /* number of codes for each tree */
  80348. {
  80349. int rank; /* index in bl_order */
  80350. Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes");
  80351. Assert (lcodes <= L_CODES && dcodes <= D_CODES && blcodes <= BL_CODES,
  80352. "too many codes");
  80353. Tracev((stderr, "\nbl counts: "));
  80354. send_bits(s, lcodes-257, 5); /* not +255 as stated in appnote.txt */
  80355. send_bits(s, dcodes-1, 5);
  80356. send_bits(s, blcodes-4, 4); /* not -3 as stated in appnote.txt */
  80357. for (rank = 0; rank < blcodes; rank++) {
  80358. Tracev((stderr, "\nbl code %2d ", bl_order[rank]));
  80359. send_bits(s, s->bl_tree[bl_order[rank]].Len, 3);
  80360. }
  80361. Tracev((stderr, "\nbl tree: sent %ld", s->bits_sent));
  80362. send_tree(s, (ct_data *)s->dyn_ltree, lcodes-1); /* literal tree */
  80363. Tracev((stderr, "\nlit tree: sent %ld", s->bits_sent));
  80364. send_tree(s, (ct_data *)s->dyn_dtree, dcodes-1); /* distance tree */
  80365. Tracev((stderr, "\ndist tree: sent %ld", s->bits_sent));
  80366. }
  80367. void _tr_stored_block (deflate_state *s, charf *buf, ulg stored_len, int eof)
  80368. {
  80369. send_bits(s, (STORED_BLOCK<<1)+eof, 3); /* send block type */
  80370. #ifdef DEBUG
  80371. s->compressed_len = (s->compressed_len + 3 + 7) & (ulg)~7L;
  80372. s->compressed_len += (stored_len + 4) << 3;
  80373. #endif
  80374. copy_block(s, buf, (unsigned)stored_len, 1); /* with header */
  80375. }
  80376. void _tr_align (deflate_state *s)
  80377. {
  80378. send_bits(s, STATIC_TREES<<1, 3);
  80379. send_code(s, END_BLOCK, static_ltree);
  80380. #ifdef DEBUG
  80381. s->compressed_len += 10L; /* 3 for block type, 7 for EOB */
  80382. #endif
  80383. bi_flush(s);
  80384. if (1 + s->last_eob_len + 10 - s->bi_valid < 9) {
  80385. send_bits(s, STATIC_TREES<<1, 3);
  80386. send_code(s, END_BLOCK, static_ltree);
  80387. #ifdef DEBUG
  80388. s->compressed_len += 10L;
  80389. #endif
  80390. bi_flush(s);
  80391. }
  80392. s->last_eob_len = 7;
  80393. }
  80394. void _tr_flush_block (deflate_state *s,
  80395. charf *buf, /* input block, or NULL if too old */
  80396. ulg stored_len, /* length of input block */
  80397. int eof) /* true if this is the last block for a file */
  80398. {
  80399. ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */
  80400. int max_blindex = 0; /* index of last bit length code of non zero freq */
  80401. if (s->level > 0) {
  80402. if (stored_len > 0 && s->strm->data_type == Z_UNKNOWN)
  80403. set_data_type(s);
  80404. build_tree(s, (tree_desc *)(&(s->l_desc)));
  80405. Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len,
  80406. s->static_len));
  80407. build_tree(s, (tree_desc *)(&(s->d_desc)));
  80408. Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len,
  80409. s->static_len));
  80410. max_blindex = build_bl_tree(s);
  80411. opt_lenb = (s->opt_len+3+7)>>3;
  80412. static_lenb = (s->static_len+3+7)>>3;
  80413. Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ",
  80414. opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len,
  80415. s->last_lit));
  80416. if (static_lenb <= opt_lenb) opt_lenb = static_lenb;
  80417. } else {
  80418. Assert(buf != (char*)0, "lost buf");
  80419. opt_lenb = static_lenb = stored_len + 5; /* force a stored block */
  80420. }
  80421. #ifdef FORCE_STORED
  80422. if (buf != (char*)0) { /* force stored block */
  80423. #else
  80424. if (stored_len+4 <= opt_lenb && buf != (char*)0) {
  80425. #endif
  80426. _tr_stored_block(s, buf, stored_len, eof);
  80427. #ifdef FORCE_STATIC
  80428. } else if (static_lenb >= 0) { /* force static trees */
  80429. #else
  80430. } else if (s->strategy == Z_FIXED || static_lenb == opt_lenb) {
  80431. #endif
  80432. send_bits(s, (STATIC_TREES<<1)+eof, 3);
  80433. compress_block(s, (ct_data *)static_ltree, (ct_data *)static_dtree);
  80434. #ifdef DEBUG
  80435. s->compressed_len += 3 + s->static_len;
  80436. #endif
  80437. } else {
  80438. send_bits(s, (DYN_TREES<<1)+eof, 3);
  80439. send_all_trees(s, s->l_desc.max_code+1, s->d_desc.max_code+1,
  80440. max_blindex+1);
  80441. compress_block(s, (ct_data *)s->dyn_ltree, (ct_data *)s->dyn_dtree);
  80442. #ifdef DEBUG
  80443. s->compressed_len += 3 + s->opt_len;
  80444. #endif
  80445. }
  80446. Assert (s->compressed_len == s->bits_sent, "bad compressed size");
  80447. init_block(s);
  80448. if (eof) {
  80449. bi_windup(s);
  80450. #ifdef DEBUG
  80451. s->compressed_len += 7; /* align on byte boundary */
  80452. #endif
  80453. }
  80454. Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3,
  80455. s->compressed_len-7*eof));
  80456. }
  80457. int _tr_tally (deflate_state *s,
  80458. unsigned dist, /* distance of matched string */
  80459. unsigned lc) /* match length-MIN_MATCH or unmatched char (if dist==0) */
  80460. {
  80461. s->d_buf[s->last_lit] = (ush)dist;
  80462. s->l_buf[s->last_lit++] = (uch)lc;
  80463. if (dist == 0) {
  80464. s->dyn_ltree[lc].Freq++;
  80465. } else {
  80466. s->matches++;
  80467. dist--; /* dist = match distance - 1 */
  80468. Assert((ush)dist < (ush)MAX_DIST(s) &&
  80469. (ush)lc <= (ush)(MAX_MATCH-MIN_MATCH) &&
  80470. (ush)d_code(dist) < (ush)D_CODES, "_tr_tally: bad match");
  80471. s->dyn_ltree[_length_code[lc]+LITERALS+1].Freq++;
  80472. s->dyn_dtree[d_code(dist)].Freq++;
  80473. }
  80474. #ifdef TRUNCATE_BLOCK
  80475. if ((s->last_lit & 0x1fff) == 0 && s->level > 2) {
  80476. ulg out_length = (ulg)s->last_lit*8L;
  80477. ulg in_length = (ulg)((long)s->strstart - s->block_start);
  80478. int dcode;
  80479. for (dcode = 0; dcode < D_CODES; dcode++) {
  80480. out_length += (ulg)s->dyn_dtree[dcode].Freq *
  80481. (5L+extra_dbits[dcode]);
  80482. }
  80483. out_length >>= 3;
  80484. Tracev((stderr,"\nlast_lit %u, in %ld, out ~%ld(%ld%%) ",
  80485. s->last_lit, in_length, out_length,
  80486. 100L - out_length*100L/in_length));
  80487. if (s->matches < s->last_lit/2 && out_length < in_length/2) return 1;
  80488. }
  80489. #endif
  80490. return (s->last_lit == s->lit_bufsize-1);
  80491. }
  80492. local void compress_block (deflate_state *s,
  80493. ct_data *ltree, /* literal tree */
  80494. ct_data *dtree) /* distance tree */
  80495. {
  80496. unsigned dist; /* distance of matched string */
  80497. int lc; /* match length or unmatched char (if dist == 0) */
  80498. unsigned lx = 0; /* running index in l_buf */
  80499. unsigned code; /* the code to send */
  80500. int extra; /* number of extra bits to send */
  80501. if (s->last_lit != 0) do {
  80502. dist = s->d_buf[lx];
  80503. lc = s->l_buf[lx++];
  80504. if (dist == 0) {
  80505. send_code(s, lc, ltree); /* send a literal byte */
  80506. Tracecv(isgraph(lc), (stderr," '%c' ", lc));
  80507. } else {
  80508. code = _length_code[lc];
  80509. send_code(s, code+LITERALS+1, ltree); /* send the length code */
  80510. extra = extra_lbits[code];
  80511. if (extra != 0) {
  80512. lc -= base_length[code];
  80513. send_bits(s, lc, extra); /* send the extra length bits */
  80514. }
  80515. dist--; /* dist is now the match distance - 1 */
  80516. code = d_code(dist);
  80517. Assert (code < D_CODES, "bad d_code");
  80518. send_code(s, code, dtree); /* send the distance code */
  80519. extra = extra_dbits[code];
  80520. if (extra != 0) {
  80521. dist -= base_dist[code];
  80522. send_bits(s, dist, extra); /* send the extra distance bits */
  80523. }
  80524. } /* literal or match pair ? */
  80525. Assert((uInt)(s->pending) < s->lit_bufsize + 2*lx,
  80526. "pendingBuf overflow");
  80527. } while (lx < s->last_lit);
  80528. send_code(s, END_BLOCK, ltree);
  80529. s->last_eob_len = ltree[END_BLOCK].Len;
  80530. }
  80531. local void set_data_type (deflate_state *s)
  80532. {
  80533. int n;
  80534. for (n = 0; n < 9; n++)
  80535. if (s->dyn_ltree[n].Freq != 0)
  80536. break;
  80537. if (n == 9)
  80538. for (n = 14; n < 32; n++)
  80539. if (s->dyn_ltree[n].Freq != 0)
  80540. break;
  80541. s->strm->data_type = (n == 32) ? Z_TEXT : Z_BINARY;
  80542. }
  80543. local unsigned bi_reverse (unsigned code, int len)
  80544. {
  80545. register unsigned res = 0;
  80546. do {
  80547. res |= code & 1;
  80548. code >>= 1, res <<= 1;
  80549. } while (--len > 0);
  80550. return res >> 1;
  80551. }
  80552. local void bi_flush (deflate_state *s)
  80553. {
  80554. if (s->bi_valid == 16) {
  80555. put_short(s, s->bi_buf);
  80556. s->bi_buf = 0;
  80557. s->bi_valid = 0;
  80558. } else if (s->bi_valid >= 8) {
  80559. put_byte(s, (Byte)s->bi_buf);
  80560. s->bi_buf >>= 8;
  80561. s->bi_valid -= 8;
  80562. }
  80563. }
  80564. local void bi_windup (deflate_state *s)
  80565. {
  80566. if (s->bi_valid > 8) {
  80567. put_short(s, s->bi_buf);
  80568. } else if (s->bi_valid > 0) {
  80569. put_byte(s, (Byte)s->bi_buf);
  80570. }
  80571. s->bi_buf = 0;
  80572. s->bi_valid = 0;
  80573. #ifdef DEBUG
  80574. s->bits_sent = (s->bits_sent+7) & ~7;
  80575. #endif
  80576. }
  80577. local void copy_block(deflate_state *s,
  80578. charf *buf, /* the input data */
  80579. unsigned len, /* its length */
  80580. int header) /* true if block header must be written */
  80581. {
  80582. bi_windup(s); /* align on byte boundary */
  80583. s->last_eob_len = 8; /* enough lookahead for inflate */
  80584. if (header) {
  80585. put_short(s, (ush)len);
  80586. put_short(s, (ush)~len);
  80587. #ifdef DEBUG
  80588. s->bits_sent += 2*16;
  80589. #endif
  80590. }
  80591. #ifdef DEBUG
  80592. s->bits_sent += (ulg)len<<3;
  80593. #endif
  80594. while (len--) {
  80595. put_byte(s, *buf++);
  80596. }
  80597. }
  80598. /*** End of inlined file: trees.c ***/
  80599. /*** Start of inlined file: zutil.c ***/
  80600. #ifndef NO_DUMMY_DECL
  80601. struct internal_state {int dummy;}; /* for buggy compilers */
  80602. #endif
  80603. const char * const z_errmsg[10] = {
  80604. "need dictionary", /* Z_NEED_DICT 2 */
  80605. "stream end", /* Z_STREAM_END 1 */
  80606. "", /* Z_OK 0 */
  80607. "file error", /* Z_ERRNO (-1) */
  80608. "stream error", /* Z_STREAM_ERROR (-2) */
  80609. "data error", /* Z_DATA_ERROR (-3) */
  80610. "insufficient memory", /* Z_MEM_ERROR (-4) */
  80611. "buffer error", /* Z_BUF_ERROR (-5) */
  80612. "incompatible version",/* Z_VERSION_ERROR (-6) */
  80613. ""};
  80614. #ifdef DEBUG
  80615. # ifndef verbose
  80616. # define verbose 0
  80617. # endif
  80618. int z_verbose = verbose;
  80619. void z_error (const char *m)
  80620. {
  80621. fprintf(stderr, "%s\n", m);
  80622. exit(1);
  80623. }
  80624. #endif
  80625. const char * ZEXPORT zError(int err)
  80626. {
  80627. return ERR_MSG(err);
  80628. }
  80629. #if defined(_WIN32_WCE)
  80630. int errno = 0;
  80631. #endif
  80632. #ifndef HAVE_MEMCPY
  80633. void zmemcpy(dest, source, len)
  80634. Bytef* dest;
  80635. const Bytef* source;
  80636. uInt len;
  80637. {
  80638. if (len == 0) return;
  80639. do {
  80640. *dest++ = *source++; /* ??? to be unrolled */
  80641. } while (--len != 0);
  80642. }
  80643. int zmemcmp(s1, s2, len)
  80644. const Bytef* s1;
  80645. const Bytef* s2;
  80646. uInt len;
  80647. {
  80648. uInt j;
  80649. for (j = 0; j < len; j++) {
  80650. if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1;
  80651. }
  80652. return 0;
  80653. }
  80654. void zmemzero(dest, len)
  80655. Bytef* dest;
  80656. uInt len;
  80657. {
  80658. if (len == 0) return;
  80659. do {
  80660. *dest++ = 0; /* ??? to be unrolled */
  80661. } while (--len != 0);
  80662. }
  80663. #endif
  80664. #ifdef SYS16BIT
  80665. #ifdef __TURBOC__
  80666. # define MY_ZCALLOC
  80667. #define MAX_PTR 10
  80668. local int next_ptr = 0;
  80669. typedef struct ptr_table_s {
  80670. voidpf org_ptr;
  80671. voidpf new_ptr;
  80672. } ptr_table;
  80673. local ptr_table table[MAX_PTR];
  80674. voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
  80675. {
  80676. voidpf buf = opaque; /* just to make some compilers happy */
  80677. ulg bsize = (ulg)items*size;
  80678. if (bsize < 65520L) {
  80679. buf = farmalloc(bsize);
  80680. if (*(ush*)&buf != 0) return buf;
  80681. } else {
  80682. buf = farmalloc(bsize + 16L);
  80683. }
  80684. if (buf == NULL || next_ptr >= MAX_PTR) return NULL;
  80685. table[next_ptr].org_ptr = buf;
  80686. *((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4;
  80687. *(ush*)&buf = 0;
  80688. table[next_ptr++].new_ptr = buf;
  80689. return buf;
  80690. }
  80691. void zcfree (voidpf opaque, voidpf ptr)
  80692. {
  80693. int n;
  80694. if (*(ush*)&ptr != 0) { /* object < 64K */
  80695. farfree(ptr);
  80696. return;
  80697. }
  80698. for (n = 0; n < next_ptr; n++) {
  80699. if (ptr != table[n].new_ptr) continue;
  80700. farfree(table[n].org_ptr);
  80701. while (++n < next_ptr) {
  80702. table[n-1] = table[n];
  80703. }
  80704. next_ptr--;
  80705. return;
  80706. }
  80707. ptr = opaque; /* just to make some compilers happy */
  80708. Assert(0, "zcfree: ptr not found");
  80709. }
  80710. #endif /* __TURBOC__ */
  80711. #ifdef M_I86
  80712. # define MY_ZCALLOC
  80713. #if (!defined(_MSC_VER) || (_MSC_VER <= 600))
  80714. # define _halloc halloc
  80715. # define _hfree hfree
  80716. #endif
  80717. voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
  80718. {
  80719. if (opaque) opaque = 0; /* to make compiler happy */
  80720. return _halloc((long)items, size);
  80721. }
  80722. void zcfree (voidpf opaque, voidpf ptr)
  80723. {
  80724. if (opaque) opaque = 0; /* to make compiler happy */
  80725. _hfree(ptr);
  80726. }
  80727. #endif /* M_I86 */
  80728. #endif /* SYS16BIT */
  80729. #ifndef MY_ZCALLOC /* Any system without a special alloc function */
  80730. #ifndef STDC
  80731. extern voidp malloc OF((uInt size));
  80732. extern voidp calloc OF((uInt items, uInt size));
  80733. extern void free OF((voidpf ptr));
  80734. #endif
  80735. voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
  80736. {
  80737. if (opaque) items += size - size; /* make compiler happy */
  80738. return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) :
  80739. (voidpf)calloc(items, size);
  80740. }
  80741. void zcfree (voidpf opaque, voidpf ptr)
  80742. {
  80743. free(ptr);
  80744. if (opaque) return; /* make compiler happy */
  80745. }
  80746. #endif /* MY_ZCALLOC */
  80747. /*** End of inlined file: zutil.c ***/
  80748. #undef Byte
  80749. }
  80750. #else
  80751. #include <zlib.h>
  80752. #endif
  80753. }
  80754. #if JUCE_MSVC
  80755. #pragma warning (pop)
  80756. #endif
  80757. BEGIN_JUCE_NAMESPACE
  80758. using namespace zlibNamespace;
  80759. // internal helper object that holds the zlib structures so they don't have to be
  80760. // included publicly.
  80761. class GZIPDecompressHelper
  80762. {
  80763. public:
  80764. GZIPDecompressHelper (const bool noWrap) throw()
  80765. : data (0),
  80766. dataSize (0),
  80767. finished (true),
  80768. needsDictionary (false),
  80769. error (true),
  80770. streamIsValid (false)
  80771. {
  80772. zerostruct (stream);
  80773. streamIsValid = (inflateInit2 (&stream, noWrap ? -MAX_WBITS : MAX_WBITS) == Z_OK);
  80774. finished = error = ! streamIsValid;
  80775. }
  80776. ~GZIPDecompressHelper() throw()
  80777. {
  80778. if (streamIsValid)
  80779. inflateEnd (&stream);
  80780. }
  80781. bool needsInput() const throw() { return dataSize <= 0; }
  80782. void setInput (uint8* const data_, const int size) throw()
  80783. {
  80784. data = data_;
  80785. dataSize = size;
  80786. }
  80787. int doNextBlock (uint8* const dest, const int destSize) throw()
  80788. {
  80789. if (streamIsValid && data != 0 && ! finished)
  80790. {
  80791. stream.next_in = data;
  80792. stream.next_out = dest;
  80793. stream.avail_in = dataSize;
  80794. stream.avail_out = destSize;
  80795. switch (inflate (&stream, Z_PARTIAL_FLUSH))
  80796. {
  80797. case Z_STREAM_END:
  80798. finished = true;
  80799. // deliberate fall-through
  80800. case Z_OK:
  80801. data += dataSize - stream.avail_in;
  80802. dataSize = stream.avail_in;
  80803. return destSize - stream.avail_out;
  80804. case Z_NEED_DICT:
  80805. needsDictionary = true;
  80806. data += dataSize - stream.avail_in;
  80807. dataSize = stream.avail_in;
  80808. break;
  80809. case Z_DATA_ERROR:
  80810. case Z_MEM_ERROR:
  80811. error = true;
  80812. default:
  80813. break;
  80814. }
  80815. }
  80816. return 0;
  80817. }
  80818. private:
  80819. z_stream stream;
  80820. uint8* data;
  80821. int dataSize;
  80822. public:
  80823. bool finished, needsDictionary, error, streamIsValid;
  80824. };
  80825. const int gzipDecompBufferSize = 32768;
  80826. GZIPDecompressorInputStream::GZIPDecompressorInputStream (InputStream* const sourceStream_,
  80827. const bool deleteSourceWhenDestroyed,
  80828. const bool noWrap_,
  80829. const int64 uncompressedStreamLength_)
  80830. : sourceStream (sourceStream_),
  80831. streamToDelete (deleteSourceWhenDestroyed ? sourceStream_ : 0),
  80832. uncompressedStreamLength (uncompressedStreamLength_),
  80833. noWrap (noWrap_),
  80834. isEof (false),
  80835. activeBufferSize (0),
  80836. originalSourcePos (sourceStream_->getPosition()),
  80837. currentPos (0),
  80838. buffer (gzipDecompBufferSize),
  80839. helper (new GZIPDecompressHelper (noWrap_))
  80840. {
  80841. }
  80842. GZIPDecompressorInputStream::~GZIPDecompressorInputStream()
  80843. {
  80844. }
  80845. int64 GZIPDecompressorInputStream::getTotalLength()
  80846. {
  80847. return uncompressedStreamLength;
  80848. }
  80849. int GZIPDecompressorInputStream::read (void* destBuffer, int howMany)
  80850. {
  80851. if ((howMany > 0) && ! isEof)
  80852. {
  80853. jassert (destBuffer != 0);
  80854. if (destBuffer != 0)
  80855. {
  80856. int numRead = 0;
  80857. uint8* d = (uint8*) destBuffer;
  80858. while (! helper->error)
  80859. {
  80860. const int n = helper->doNextBlock (d, howMany);
  80861. currentPos += n;
  80862. if (n == 0)
  80863. {
  80864. if (helper->finished || helper->needsDictionary)
  80865. {
  80866. isEof = true;
  80867. return numRead;
  80868. }
  80869. if (helper->needsInput())
  80870. {
  80871. activeBufferSize = sourceStream->read (buffer, gzipDecompBufferSize);
  80872. if (activeBufferSize > 0)
  80873. {
  80874. helper->setInput ((uint8*) buffer, activeBufferSize);
  80875. }
  80876. else
  80877. {
  80878. isEof = true;
  80879. return numRead;
  80880. }
  80881. }
  80882. }
  80883. else
  80884. {
  80885. numRead += n;
  80886. howMany -= n;
  80887. d += n;
  80888. if (howMany <= 0)
  80889. return numRead;
  80890. }
  80891. }
  80892. }
  80893. }
  80894. return 0;
  80895. }
  80896. bool GZIPDecompressorInputStream::isExhausted()
  80897. {
  80898. return helper->error || isEof;
  80899. }
  80900. int64 GZIPDecompressorInputStream::getPosition()
  80901. {
  80902. return currentPos;
  80903. }
  80904. bool GZIPDecompressorInputStream::setPosition (int64 newPos)
  80905. {
  80906. if (newPos < currentPos)
  80907. {
  80908. // to go backwards, reset the stream and start again..
  80909. isEof = false;
  80910. activeBufferSize = 0;
  80911. currentPos = 0;
  80912. helper = new GZIPDecompressHelper (noWrap);
  80913. sourceStream->setPosition (originalSourcePos);
  80914. }
  80915. skipNextBytes (newPos - currentPos);
  80916. return true;
  80917. }
  80918. END_JUCE_NAMESPACE
  80919. /*** End of inlined file: juce_GZIPDecompressorInputStream.cpp ***/
  80920. #endif
  80921. #if JUCE_BUILD_NATIVE && ! JUCE_ONLY_BUILD_CORE_LIBRARY
  80922. /*** Start of inlined file: juce_FlacAudioFormat.cpp ***/
  80923. #if JUCE_USE_FLAC
  80924. #if JUCE_WINDOWS
  80925. #include <windows.h>
  80926. #endif
  80927. #ifdef _MSC_VER
  80928. #pragma warning (disable : 4505)
  80929. #pragma warning (push)
  80930. #endif
  80931. namespace FlacNamespace
  80932. {
  80933. #if JUCE_INCLUDE_FLAC_CODE
  80934. #define FLAC__NO_DLL 1
  80935. #if ! defined (SIZE_MAX)
  80936. #define SIZE_MAX 0xffffffff
  80937. #endif
  80938. #define __STDC_LIMIT_MACROS 1
  80939. /*** Start of inlined file: all.h ***/
  80940. #ifndef FLAC__ALL_H
  80941. #define FLAC__ALL_H
  80942. /*** Start of inlined file: export.h ***/
  80943. #ifndef FLAC__EXPORT_H
  80944. #define FLAC__EXPORT_H
  80945. #if defined(FLAC__NO_DLL) || !defined(_MSC_VER)
  80946. #define FLAC_API
  80947. #else
  80948. #ifdef FLAC_API_EXPORTS
  80949. #define FLAC_API _declspec(dllexport)
  80950. #else
  80951. #define FLAC_API _declspec(dllimport)
  80952. #endif
  80953. #endif
  80954. #define FLAC_API_VERSION_CURRENT 10
  80955. #define FLAC_API_VERSION_REVISION 0 /**< see above */
  80956. #define FLAC_API_VERSION_AGE 2 /**< see above */
  80957. #ifdef __cplusplus
  80958. extern "C" {
  80959. #endif
  80960. extern FLAC_API int FLAC_API_SUPPORTS_OGG_FLAC;
  80961. #ifdef __cplusplus
  80962. }
  80963. #endif
  80964. #endif
  80965. /*** End of inlined file: export.h ***/
  80966. /*** Start of inlined file: assert.h ***/
  80967. #ifndef FLAC__ASSERT_H
  80968. #define FLAC__ASSERT_H
  80969. /* we need this since some compilers (like MSVC) leave assert()s on release code (and we don't want to use their ASSERT) */
  80970. #ifdef DEBUG
  80971. #include <assert.h>
  80972. #define FLAC__ASSERT(x) assert(x)
  80973. #define FLAC__ASSERT_DECLARATION(x) x
  80974. #else
  80975. #define FLAC__ASSERT(x)
  80976. #define FLAC__ASSERT_DECLARATION(x)
  80977. #endif
  80978. #endif
  80979. /*** End of inlined file: assert.h ***/
  80980. /*** Start of inlined file: callback.h ***/
  80981. #ifndef FLAC__CALLBACK_H
  80982. #define FLAC__CALLBACK_H
  80983. /*** Start of inlined file: ordinals.h ***/
  80984. #ifndef FLAC__ORDINALS_H
  80985. #define FLAC__ORDINALS_H
  80986. #if !(defined(_MSC_VER) || defined(__BORLANDC__) || defined(__EMX__))
  80987. #include <inttypes.h>
  80988. #endif
  80989. typedef signed char FLAC__int8;
  80990. typedef unsigned char FLAC__uint8;
  80991. #if defined(_MSC_VER) || defined(__BORLANDC__)
  80992. typedef __int16 FLAC__int16;
  80993. typedef __int32 FLAC__int32;
  80994. typedef __int64 FLAC__int64;
  80995. typedef unsigned __int16 FLAC__uint16;
  80996. typedef unsigned __int32 FLAC__uint32;
  80997. typedef unsigned __int64 FLAC__uint64;
  80998. #elif defined(__EMX__)
  80999. typedef short FLAC__int16;
  81000. typedef long FLAC__int32;
  81001. typedef long long FLAC__int64;
  81002. typedef unsigned short FLAC__uint16;
  81003. typedef unsigned long FLAC__uint32;
  81004. typedef unsigned long long FLAC__uint64;
  81005. #else
  81006. typedef int16_t FLAC__int16;
  81007. typedef int32_t FLAC__int32;
  81008. typedef int64_t FLAC__int64;
  81009. typedef uint16_t FLAC__uint16;
  81010. typedef uint32_t FLAC__uint32;
  81011. typedef uint64_t FLAC__uint64;
  81012. #endif
  81013. typedef int FLAC__bool;
  81014. typedef FLAC__uint8 FLAC__byte;
  81015. #ifdef true
  81016. #undef true
  81017. #endif
  81018. #ifdef false
  81019. #undef false
  81020. #endif
  81021. #ifndef __cplusplus
  81022. #define true 1
  81023. #define false 0
  81024. #endif
  81025. #endif
  81026. /*** End of inlined file: ordinals.h ***/
  81027. #include <stdlib.h> /* for size_t */
  81028. #ifdef __cplusplus
  81029. extern "C" {
  81030. #endif
  81031. typedef void* FLAC__IOHandle;
  81032. typedef size_t (*FLAC__IOCallback_Read) (void *ptr, size_t size, size_t nmemb, FLAC__IOHandle handle);
  81033. typedef size_t (*FLAC__IOCallback_Write) (const void *ptr, size_t size, size_t nmemb, FLAC__IOHandle handle);
  81034. typedef int (*FLAC__IOCallback_Seek) (FLAC__IOHandle handle, FLAC__int64 offset, int whence);
  81035. typedef FLAC__int64 (*FLAC__IOCallback_Tell) (FLAC__IOHandle handle);
  81036. typedef int (*FLAC__IOCallback_Eof) (FLAC__IOHandle handle);
  81037. typedef int (*FLAC__IOCallback_Close) (FLAC__IOHandle handle);
  81038. typedef struct {
  81039. FLAC__IOCallback_Read read;
  81040. FLAC__IOCallback_Write write;
  81041. FLAC__IOCallback_Seek seek;
  81042. FLAC__IOCallback_Tell tell;
  81043. FLAC__IOCallback_Eof eof;
  81044. FLAC__IOCallback_Close close;
  81045. } FLAC__IOCallbacks;
  81046. #ifdef __cplusplus
  81047. }
  81048. #endif
  81049. #endif
  81050. /*** End of inlined file: callback.h ***/
  81051. /*** Start of inlined file: format.h ***/
  81052. #ifndef FLAC__FORMAT_H
  81053. #define FLAC__FORMAT_H
  81054. #ifdef __cplusplus
  81055. extern "C" {
  81056. #endif
  81057. #define FLAC__MAX_METADATA_TYPE_CODE (126u)
  81058. #define FLAC__MIN_BLOCK_SIZE (16u)
  81059. #define FLAC__MAX_BLOCK_SIZE (65535u)
  81060. #define FLAC__SUBSET_MAX_BLOCK_SIZE_48000HZ (4608u)
  81061. #define FLAC__MAX_CHANNELS (8u)
  81062. #define FLAC__MIN_BITS_PER_SAMPLE (4u)
  81063. #define FLAC__MAX_BITS_PER_SAMPLE (32u)
  81064. #define FLAC__REFERENCE_CODEC_MAX_BITS_PER_SAMPLE (24u)
  81065. #define FLAC__MAX_SAMPLE_RATE (655350u)
  81066. #define FLAC__MAX_LPC_ORDER (32u)
  81067. #define FLAC__SUBSET_MAX_LPC_ORDER_48000HZ (12u)
  81068. #define FLAC__MIN_QLP_COEFF_PRECISION (5u)
  81069. #define FLAC__MAX_QLP_COEFF_PRECISION (15u)
  81070. #define FLAC__MAX_FIXED_ORDER (4u)
  81071. #define FLAC__MAX_RICE_PARTITION_ORDER (15u)
  81072. #define FLAC__SUBSET_MAX_RICE_PARTITION_ORDER (8u)
  81073. extern FLAC_API const char *FLAC__VERSION_STRING;
  81074. extern FLAC_API const char *FLAC__VENDOR_STRING;
  81075. extern FLAC_API const FLAC__byte FLAC__STREAM_SYNC_STRING[4]; /* = "fLaC" */
  81076. extern FLAC_API const unsigned FLAC__STREAM_SYNC; /* = 0x664C6143 */
  81077. extern FLAC_API const unsigned FLAC__STREAM_SYNC_LEN; /* = 32 bits */
  81078. #define FLAC__STREAM_SYNC_LENGTH (4u)
  81079. typedef enum {
  81080. FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE = 0,
  81081. FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2 = 1
  81082. } FLAC__EntropyCodingMethodType;
  81083. extern FLAC_API const char * const FLAC__EntropyCodingMethodTypeString[];
  81084. typedef struct {
  81085. unsigned *parameters;
  81086. unsigned *raw_bits;
  81087. unsigned capacity_by_order;
  81088. } FLAC__EntropyCodingMethod_PartitionedRiceContents;
  81089. typedef struct {
  81090. unsigned order;
  81091. const FLAC__EntropyCodingMethod_PartitionedRiceContents *contents;
  81092. } FLAC__EntropyCodingMethod_PartitionedRice;
  81093. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN; /**< == 4 (bits) */
  81094. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN; /**< == 4 (bits) */
  81095. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN; /**< == 5 (bits) */
  81096. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN; /**< == 5 (bits) */
  81097. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER;
  81098. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER;
  81099. typedef struct {
  81100. FLAC__EntropyCodingMethodType type;
  81101. union {
  81102. FLAC__EntropyCodingMethod_PartitionedRice partitioned_rice;
  81103. } data;
  81104. } FLAC__EntropyCodingMethod;
  81105. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_TYPE_LEN; /**< == 2 (bits) */
  81106. typedef enum {
  81107. FLAC__SUBFRAME_TYPE_CONSTANT = 0, /**< constant signal */
  81108. FLAC__SUBFRAME_TYPE_VERBATIM = 1, /**< uncompressed signal */
  81109. FLAC__SUBFRAME_TYPE_FIXED = 2, /**< fixed polynomial prediction */
  81110. FLAC__SUBFRAME_TYPE_LPC = 3 /**< linear prediction */
  81111. } FLAC__SubframeType;
  81112. extern FLAC_API const char * const FLAC__SubframeTypeString[];
  81113. typedef struct {
  81114. FLAC__int32 value; /**< The constant signal value. */
  81115. } FLAC__Subframe_Constant;
  81116. typedef struct {
  81117. const FLAC__int32 *data; /**< A pointer to verbatim signal. */
  81118. } FLAC__Subframe_Verbatim;
  81119. typedef struct {
  81120. FLAC__EntropyCodingMethod entropy_coding_method;
  81121. unsigned order;
  81122. FLAC__int32 warmup[FLAC__MAX_FIXED_ORDER];
  81123. const FLAC__int32 *residual;
  81124. } FLAC__Subframe_Fixed;
  81125. typedef struct {
  81126. FLAC__EntropyCodingMethod entropy_coding_method;
  81127. unsigned order;
  81128. unsigned qlp_coeff_precision;
  81129. int quantization_level;
  81130. FLAC__int32 qlp_coeff[FLAC__MAX_LPC_ORDER];
  81131. FLAC__int32 warmup[FLAC__MAX_LPC_ORDER];
  81132. const FLAC__int32 *residual;
  81133. } FLAC__Subframe_LPC;
  81134. extern FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN; /**< == 4 (bits) */
  81135. extern FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN; /**< == 5 (bits) */
  81136. typedef struct {
  81137. FLAC__SubframeType type;
  81138. union {
  81139. FLAC__Subframe_Constant constant;
  81140. FLAC__Subframe_Fixed fixed;
  81141. FLAC__Subframe_LPC lpc;
  81142. FLAC__Subframe_Verbatim verbatim;
  81143. } data;
  81144. unsigned wasted_bits;
  81145. } FLAC__Subframe;
  81146. extern FLAC_API const unsigned FLAC__SUBFRAME_ZERO_PAD_LEN;
  81147. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LEN; /**< == 6 (bits) */
  81148. extern FLAC_API const unsigned FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN; /**< == 1 (bit) */
  81149. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_CONSTANT_BYTE_ALIGNED_MASK; /**< = 0x00 */
  81150. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_VERBATIM_BYTE_ALIGNED_MASK; /**< = 0x02 */
  81151. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_FIXED_BYTE_ALIGNED_MASK; /**< = 0x10 */
  81152. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LPC_BYTE_ALIGNED_MASK; /**< = 0x40 */
  81153. typedef enum {
  81154. FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT = 0, /**< independent channels */
  81155. FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE = 1, /**< left+side stereo */
  81156. FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE = 2, /**< right+side stereo */
  81157. FLAC__CHANNEL_ASSIGNMENT_MID_SIDE = 3 /**< mid+side stereo */
  81158. } FLAC__ChannelAssignment;
  81159. extern FLAC_API const char * const FLAC__ChannelAssignmentString[];
  81160. typedef enum {
  81161. FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER, /**< number contains the frame number */
  81162. FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER /**< number contains the sample number of first sample in frame */
  81163. } FLAC__FrameNumberType;
  81164. extern FLAC_API const char * const FLAC__FrameNumberTypeString[];
  81165. typedef struct {
  81166. unsigned blocksize;
  81167. unsigned sample_rate;
  81168. unsigned channels;
  81169. FLAC__ChannelAssignment channel_assignment;
  81170. unsigned bits_per_sample;
  81171. FLAC__FrameNumberType number_type;
  81172. union {
  81173. FLAC__uint32 frame_number;
  81174. FLAC__uint64 sample_number;
  81175. } number;
  81176. FLAC__uint8 crc;
  81177. } FLAC__FrameHeader;
  81178. extern FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC; /**< == 0x3ffe; the frame header sync code */
  81179. extern FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC_LEN; /**< == 14 (bits) */
  81180. extern FLAC_API const unsigned FLAC__FRAME_HEADER_RESERVED_LEN; /**< == 1 (bits) */
  81181. extern FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCKING_STRATEGY_LEN; /**< == 1 (bits) */
  81182. extern FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCK_SIZE_LEN; /**< == 4 (bits) */
  81183. extern FLAC_API const unsigned FLAC__FRAME_HEADER_SAMPLE_RATE_LEN; /**< == 4 (bits) */
  81184. extern FLAC_API const unsigned FLAC__FRAME_HEADER_CHANNEL_ASSIGNMENT_LEN; /**< == 4 (bits) */
  81185. extern FLAC_API const unsigned FLAC__FRAME_HEADER_BITS_PER_SAMPLE_LEN; /**< == 3 (bits) */
  81186. extern FLAC_API const unsigned FLAC__FRAME_HEADER_ZERO_PAD_LEN; /**< == 1 (bit) */
  81187. extern FLAC_API const unsigned FLAC__FRAME_HEADER_CRC_LEN; /**< == 8 (bits) */
  81188. typedef struct {
  81189. FLAC__uint16 crc;
  81190. } FLAC__FrameFooter;
  81191. extern FLAC_API const unsigned FLAC__FRAME_FOOTER_CRC_LEN; /**< == 16 (bits) */
  81192. typedef struct {
  81193. FLAC__FrameHeader header;
  81194. FLAC__Subframe subframes[FLAC__MAX_CHANNELS];
  81195. FLAC__FrameFooter footer;
  81196. } FLAC__Frame;
  81197. typedef enum {
  81198. FLAC__METADATA_TYPE_STREAMINFO = 0,
  81199. FLAC__METADATA_TYPE_PADDING = 1,
  81200. FLAC__METADATA_TYPE_APPLICATION = 2,
  81201. FLAC__METADATA_TYPE_SEEKTABLE = 3,
  81202. FLAC__METADATA_TYPE_VORBIS_COMMENT = 4,
  81203. FLAC__METADATA_TYPE_CUESHEET = 5,
  81204. FLAC__METADATA_TYPE_PICTURE = 6,
  81205. FLAC__METADATA_TYPE_UNDEFINED = 7
  81206. } FLAC__MetadataType;
  81207. extern FLAC_API const char * const FLAC__MetadataTypeString[];
  81208. typedef struct {
  81209. unsigned min_blocksize, max_blocksize;
  81210. unsigned min_framesize, max_framesize;
  81211. unsigned sample_rate;
  81212. unsigned channels;
  81213. unsigned bits_per_sample;
  81214. FLAC__uint64 total_samples;
  81215. FLAC__byte md5sum[16];
  81216. } FLAC__StreamMetadata_StreamInfo;
  81217. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN; /**< == 16 (bits) */
  81218. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN; /**< == 16 (bits) */
  81219. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN; /**< == 24 (bits) */
  81220. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN; /**< == 24 (bits) */
  81221. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN; /**< == 20 (bits) */
  81222. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN; /**< == 3 (bits) */
  81223. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN; /**< == 5 (bits) */
  81224. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN; /**< == 36 (bits) */
  81225. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MD5SUM_LEN; /**< == 128 (bits) */
  81226. #define FLAC__STREAM_METADATA_STREAMINFO_LENGTH (34u)
  81227. typedef struct {
  81228. int dummy;
  81229. } FLAC__StreamMetadata_Padding;
  81230. typedef struct {
  81231. FLAC__byte id[4];
  81232. FLAC__byte *data;
  81233. } FLAC__StreamMetadata_Application;
  81234. extern FLAC_API const unsigned FLAC__STREAM_METADATA_APPLICATION_ID_LEN; /**< == 32 (bits) */
  81235. typedef struct {
  81236. FLAC__uint64 sample_number;
  81237. FLAC__uint64 stream_offset;
  81238. unsigned frame_samples;
  81239. } FLAC__StreamMetadata_SeekPoint;
  81240. extern FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN; /**< == 64 (bits) */
  81241. extern FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN; /**< == 64 (bits) */
  81242. extern FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN; /**< == 16 (bits) */
  81243. #define FLAC__STREAM_METADATA_SEEKPOINT_LENGTH (18u)
  81244. extern FLAC_API const FLAC__uint64 FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
  81245. typedef struct {
  81246. unsigned num_points;
  81247. FLAC__StreamMetadata_SeekPoint *points;
  81248. } FLAC__StreamMetadata_SeekTable;
  81249. typedef struct {
  81250. FLAC__uint32 length;
  81251. FLAC__byte *entry;
  81252. } FLAC__StreamMetadata_VorbisComment_Entry;
  81253. extern FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN; /**< == 32 (bits) */
  81254. typedef struct {
  81255. FLAC__StreamMetadata_VorbisComment_Entry vendor_string;
  81256. FLAC__uint32 num_comments;
  81257. FLAC__StreamMetadata_VorbisComment_Entry *comments;
  81258. } FLAC__StreamMetadata_VorbisComment;
  81259. extern FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN; /**< == 32 (bits) */
  81260. typedef struct {
  81261. FLAC__uint64 offset;
  81262. FLAC__byte number;
  81263. } FLAC__StreamMetadata_CueSheet_Index;
  81264. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN; /**< == 64 (bits) */
  81265. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN; /**< == 8 (bits) */
  81266. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN; /**< == 3*8 (bits) */
  81267. typedef struct {
  81268. FLAC__uint64 offset;
  81269. FLAC__byte number;
  81270. char isrc[13];
  81271. unsigned type:1;
  81272. unsigned pre_emphasis:1;
  81273. FLAC__byte num_indices;
  81274. FLAC__StreamMetadata_CueSheet_Index *indices;
  81275. } FLAC__StreamMetadata_CueSheet_Track;
  81276. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN; /**< == 64 (bits) */
  81277. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN; /**< == 8 (bits) */
  81278. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN; /**< == 12*8 (bits) */
  81279. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN; /**< == 1 (bit) */
  81280. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN; /**< == 1 (bit) */
  81281. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN; /**< == 6+13*8 (bits) */
  81282. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN; /**< == 8 (bits) */
  81283. typedef struct {
  81284. char media_catalog_number[129];
  81285. FLAC__uint64 lead_in;
  81286. FLAC__bool is_cd;
  81287. unsigned num_tracks;
  81288. FLAC__StreamMetadata_CueSheet_Track *tracks;
  81289. } FLAC__StreamMetadata_CueSheet;
  81290. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN; /**< == 128*8 (bits) */
  81291. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN; /**< == 64 (bits) */
  81292. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN; /**< == 1 (bit) */
  81293. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN; /**< == 7+258*8 (bits) */
  81294. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN; /**< == 8 (bits) */
  81295. typedef enum {
  81296. FLAC__STREAM_METADATA_PICTURE_TYPE_OTHER = 0, /**< Other */
  81297. FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON_STANDARD = 1, /**< 32x32 pixels 'file icon' (PNG only) */
  81298. FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON = 2, /**< Other file icon */
  81299. FLAC__STREAM_METADATA_PICTURE_TYPE_FRONT_COVER = 3, /**< Cover (front) */
  81300. FLAC__STREAM_METADATA_PICTURE_TYPE_BACK_COVER = 4, /**< Cover (back) */
  81301. FLAC__STREAM_METADATA_PICTURE_TYPE_LEAFLET_PAGE = 5, /**< Leaflet page */
  81302. FLAC__STREAM_METADATA_PICTURE_TYPE_MEDIA = 6, /**< Media (e.g. label side of CD) */
  81303. FLAC__STREAM_METADATA_PICTURE_TYPE_LEAD_ARTIST = 7, /**< Lead artist/lead performer/soloist */
  81304. FLAC__STREAM_METADATA_PICTURE_TYPE_ARTIST = 8, /**< Artist/performer */
  81305. FLAC__STREAM_METADATA_PICTURE_TYPE_CONDUCTOR = 9, /**< Conductor */
  81306. FLAC__STREAM_METADATA_PICTURE_TYPE_BAND = 10, /**< Band/Orchestra */
  81307. FLAC__STREAM_METADATA_PICTURE_TYPE_COMPOSER = 11, /**< Composer */
  81308. FLAC__STREAM_METADATA_PICTURE_TYPE_LYRICIST = 12, /**< Lyricist/text writer */
  81309. FLAC__STREAM_METADATA_PICTURE_TYPE_RECORDING_LOCATION = 13, /**< Recording Location */
  81310. FLAC__STREAM_METADATA_PICTURE_TYPE_DURING_RECORDING = 14, /**< During recording */
  81311. FLAC__STREAM_METADATA_PICTURE_TYPE_DURING_PERFORMANCE = 15, /**< During performance */
  81312. FLAC__STREAM_METADATA_PICTURE_TYPE_VIDEO_SCREEN_CAPTURE = 16, /**< Movie/video screen capture */
  81313. FLAC__STREAM_METADATA_PICTURE_TYPE_FISH = 17, /**< A bright coloured fish */
  81314. FLAC__STREAM_METADATA_PICTURE_TYPE_ILLUSTRATION = 18, /**< Illustration */
  81315. FLAC__STREAM_METADATA_PICTURE_TYPE_BAND_LOGOTYPE = 19, /**< Band/artist logotype */
  81316. FLAC__STREAM_METADATA_PICTURE_TYPE_PUBLISHER_LOGOTYPE = 20, /**< Publisher/Studio logotype */
  81317. FLAC__STREAM_METADATA_PICTURE_TYPE_UNDEFINED
  81318. } FLAC__StreamMetadata_Picture_Type;
  81319. extern FLAC_API const char * const FLAC__StreamMetadata_Picture_TypeString[];
  81320. typedef struct {
  81321. FLAC__StreamMetadata_Picture_Type type;
  81322. char *mime_type;
  81323. FLAC__byte *description;
  81324. FLAC__uint32 width;
  81325. FLAC__uint32 height;
  81326. FLAC__uint32 depth;
  81327. FLAC__uint32 colors;
  81328. FLAC__uint32 data_length;
  81329. FLAC__byte *data;
  81330. } FLAC__StreamMetadata_Picture;
  81331. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_TYPE_LEN; /**< == 32 (bits) */
  81332. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN; /**< == 32 (bits) */
  81333. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN; /**< == 32 (bits) */
  81334. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN; /**< == 32 (bits) */
  81335. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN; /**< == 32 (bits) */
  81336. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN; /**< == 32 (bits) */
  81337. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_COLORS_LEN; /**< == 32 (bits) */
  81338. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN; /**< == 32 (bits) */
  81339. typedef struct {
  81340. FLAC__byte *data;
  81341. } FLAC__StreamMetadata_Unknown;
  81342. typedef struct {
  81343. FLAC__MetadataType type;
  81344. FLAC__bool is_last;
  81345. unsigned length;
  81346. union {
  81347. FLAC__StreamMetadata_StreamInfo stream_info;
  81348. FLAC__StreamMetadata_Padding padding;
  81349. FLAC__StreamMetadata_Application application;
  81350. FLAC__StreamMetadata_SeekTable seek_table;
  81351. FLAC__StreamMetadata_VorbisComment vorbis_comment;
  81352. FLAC__StreamMetadata_CueSheet cue_sheet;
  81353. FLAC__StreamMetadata_Picture picture;
  81354. FLAC__StreamMetadata_Unknown unknown;
  81355. } data;
  81356. } FLAC__StreamMetadata;
  81357. extern FLAC_API const unsigned FLAC__STREAM_METADATA_IS_LAST_LEN; /**< == 1 (bit) */
  81358. extern FLAC_API const unsigned FLAC__STREAM_METADATA_TYPE_LEN; /**< == 7 (bits) */
  81359. extern FLAC_API const unsigned FLAC__STREAM_METADATA_LENGTH_LEN; /**< == 24 (bits) */
  81360. #define FLAC__STREAM_METADATA_HEADER_LENGTH (4u)
  81361. FLAC_API FLAC__bool FLAC__format_sample_rate_is_valid(unsigned sample_rate);
  81362. FLAC_API FLAC__bool FLAC__format_sample_rate_is_subset(unsigned sample_rate);
  81363. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_name_is_legal(const char *name);
  81364. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_value_is_legal(const FLAC__byte *value, unsigned length);
  81365. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_is_legal(const FLAC__byte *entry, unsigned length);
  81366. FLAC_API FLAC__bool FLAC__format_seektable_is_legal(const FLAC__StreamMetadata_SeekTable *seek_table);
  81367. FLAC_API unsigned FLAC__format_seektable_sort(FLAC__StreamMetadata_SeekTable *seek_table);
  81368. FLAC_API FLAC__bool FLAC__format_cuesheet_is_legal(const FLAC__StreamMetadata_CueSheet *cue_sheet, FLAC__bool check_cd_da_subset, const char **violation);
  81369. FLAC_API FLAC__bool FLAC__format_picture_is_legal(const FLAC__StreamMetadata_Picture *picture, const char **violation);
  81370. #ifdef __cplusplus
  81371. }
  81372. #endif
  81373. #endif
  81374. /*** End of inlined file: format.h ***/
  81375. /*** Start of inlined file: metadata.h ***/
  81376. #ifndef FLAC__METADATA_H
  81377. #define FLAC__METADATA_H
  81378. #include <sys/types.h> /* for off_t */
  81379. #ifdef __cplusplus
  81380. extern "C" {
  81381. #endif
  81382. FLAC_API FLAC__bool FLAC__metadata_get_streaminfo(const char *filename, FLAC__StreamMetadata *streaminfo);
  81383. FLAC_API FLAC__bool FLAC__metadata_get_tags(const char *filename, FLAC__StreamMetadata **tags);
  81384. FLAC_API FLAC__bool FLAC__metadata_get_cuesheet(const char *filename, FLAC__StreamMetadata **cuesheet);
  81385. 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);
  81386. struct FLAC__Metadata_SimpleIterator;
  81387. typedef struct FLAC__Metadata_SimpleIterator FLAC__Metadata_SimpleIterator;
  81388. typedef enum {
  81389. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK = 0,
  81390. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ILLEGAL_INPUT,
  81391. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ERROR_OPENING_FILE,
  81392. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_NOT_A_FLAC_FILE,
  81393. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_NOT_WRITABLE,
  81394. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_BAD_METADATA,
  81395. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR,
  81396. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR,
  81397. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_WRITE_ERROR,
  81398. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_RENAME_ERROR,
  81399. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_UNLINK_ERROR,
  81400. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_MEMORY_ALLOCATION_ERROR,
  81401. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_INTERNAL_ERROR
  81402. } FLAC__Metadata_SimpleIteratorStatus;
  81403. extern FLAC_API const char * const FLAC__Metadata_SimpleIteratorStatusString[];
  81404. FLAC_API FLAC__Metadata_SimpleIterator *FLAC__metadata_simple_iterator_new(void);
  81405. FLAC_API void FLAC__metadata_simple_iterator_delete(FLAC__Metadata_SimpleIterator *iterator);
  81406. FLAC_API FLAC__Metadata_SimpleIteratorStatus FLAC__metadata_simple_iterator_status(FLAC__Metadata_SimpleIterator *iterator);
  81407. 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);
  81408. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_is_writable(const FLAC__Metadata_SimpleIterator *iterator);
  81409. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_next(FLAC__Metadata_SimpleIterator *iterator);
  81410. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_prev(FLAC__Metadata_SimpleIterator *iterator);
  81411. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_is_last(const FLAC__Metadata_SimpleIterator *iterator);
  81412. FLAC_API off_t FLAC__metadata_simple_iterator_get_block_offset(const FLAC__Metadata_SimpleIterator *iterator);
  81413. FLAC_API FLAC__MetadataType FLAC__metadata_simple_iterator_get_block_type(const FLAC__Metadata_SimpleIterator *iterator);
  81414. FLAC_API unsigned FLAC__metadata_simple_iterator_get_block_length(const FLAC__Metadata_SimpleIterator *iterator);
  81415. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_get_application_id(FLAC__Metadata_SimpleIterator *iterator, FLAC__byte *id);
  81416. FLAC_API FLAC__StreamMetadata *FLAC__metadata_simple_iterator_get_block(FLAC__Metadata_SimpleIterator *iterator);
  81417. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_set_block(FLAC__Metadata_SimpleIterator *iterator, FLAC__StreamMetadata *block, FLAC__bool use_padding);
  81418. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_insert_block_after(FLAC__Metadata_SimpleIterator *iterator, FLAC__StreamMetadata *block, FLAC__bool use_padding);
  81419. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_delete_block(FLAC__Metadata_SimpleIterator *iterator, FLAC__bool use_padding);
  81420. struct FLAC__Metadata_Chain;
  81421. typedef struct FLAC__Metadata_Chain FLAC__Metadata_Chain;
  81422. struct FLAC__Metadata_Iterator;
  81423. typedef struct FLAC__Metadata_Iterator FLAC__Metadata_Iterator;
  81424. typedef enum {
  81425. FLAC__METADATA_CHAIN_STATUS_OK = 0,
  81426. FLAC__METADATA_CHAIN_STATUS_ILLEGAL_INPUT,
  81427. FLAC__METADATA_CHAIN_STATUS_ERROR_OPENING_FILE,
  81428. FLAC__METADATA_CHAIN_STATUS_NOT_A_FLAC_FILE,
  81429. FLAC__METADATA_CHAIN_STATUS_NOT_WRITABLE,
  81430. FLAC__METADATA_CHAIN_STATUS_BAD_METADATA,
  81431. FLAC__METADATA_CHAIN_STATUS_READ_ERROR,
  81432. FLAC__METADATA_CHAIN_STATUS_SEEK_ERROR,
  81433. FLAC__METADATA_CHAIN_STATUS_WRITE_ERROR,
  81434. FLAC__METADATA_CHAIN_STATUS_RENAME_ERROR,
  81435. FLAC__METADATA_CHAIN_STATUS_UNLINK_ERROR,
  81436. FLAC__METADATA_CHAIN_STATUS_MEMORY_ALLOCATION_ERROR,
  81437. FLAC__METADATA_CHAIN_STATUS_INTERNAL_ERROR,
  81438. FLAC__METADATA_CHAIN_STATUS_INVALID_CALLBACKS,
  81439. FLAC__METADATA_CHAIN_STATUS_READ_WRITE_MISMATCH,
  81440. FLAC__METADATA_CHAIN_STATUS_WRONG_WRITE_CALL
  81441. } FLAC__Metadata_ChainStatus;
  81442. extern FLAC_API const char * const FLAC__Metadata_ChainStatusString[];
  81443. FLAC_API FLAC__Metadata_Chain *FLAC__metadata_chain_new(void);
  81444. FLAC_API void FLAC__metadata_chain_delete(FLAC__Metadata_Chain *chain);
  81445. FLAC_API FLAC__Metadata_ChainStatus FLAC__metadata_chain_status(FLAC__Metadata_Chain *chain);
  81446. FLAC_API FLAC__bool FLAC__metadata_chain_read(FLAC__Metadata_Chain *chain, const char *filename);
  81447. FLAC_API FLAC__bool FLAC__metadata_chain_read_ogg(FLAC__Metadata_Chain *chain, const char *filename);
  81448. FLAC_API FLAC__bool FLAC__metadata_chain_read_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks);
  81449. FLAC_API FLAC__bool FLAC__metadata_chain_read_ogg_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks);
  81450. FLAC_API FLAC__bool FLAC__metadata_chain_check_if_tempfile_needed(FLAC__Metadata_Chain *chain, FLAC__bool use_padding);
  81451. FLAC_API FLAC__bool FLAC__metadata_chain_write(FLAC__Metadata_Chain *chain, FLAC__bool use_padding, FLAC__bool preserve_file_stats);
  81452. FLAC_API FLAC__bool FLAC__metadata_chain_write_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__bool use_padding, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks);
  81453. 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);
  81454. FLAC_API void FLAC__metadata_chain_merge_padding(FLAC__Metadata_Chain *chain);
  81455. FLAC_API void FLAC__metadata_chain_sort_padding(FLAC__Metadata_Chain *chain);
  81456. FLAC_API FLAC__Metadata_Iterator *FLAC__metadata_iterator_new(void);
  81457. FLAC_API void FLAC__metadata_iterator_delete(FLAC__Metadata_Iterator *iterator);
  81458. FLAC_API void FLAC__metadata_iterator_init(FLAC__Metadata_Iterator *iterator, FLAC__Metadata_Chain *chain);
  81459. FLAC_API FLAC__bool FLAC__metadata_iterator_next(FLAC__Metadata_Iterator *iterator);
  81460. FLAC_API FLAC__bool FLAC__metadata_iterator_prev(FLAC__Metadata_Iterator *iterator);
  81461. FLAC_API FLAC__MetadataType FLAC__metadata_iterator_get_block_type(const FLAC__Metadata_Iterator *iterator);
  81462. FLAC_API FLAC__StreamMetadata *FLAC__metadata_iterator_get_block(FLAC__Metadata_Iterator *iterator);
  81463. FLAC_API FLAC__bool FLAC__metadata_iterator_set_block(FLAC__Metadata_Iterator *iterator, FLAC__StreamMetadata *block);
  81464. FLAC_API FLAC__bool FLAC__metadata_iterator_delete_block(FLAC__Metadata_Iterator *iterator, FLAC__bool replace_with_padding);
  81465. FLAC_API FLAC__bool FLAC__metadata_iterator_insert_block_before(FLAC__Metadata_Iterator *iterator, FLAC__StreamMetadata *block);
  81466. FLAC_API FLAC__bool FLAC__metadata_iterator_insert_block_after(FLAC__Metadata_Iterator *iterator, FLAC__StreamMetadata *block);
  81467. FLAC_API FLAC__StreamMetadata *FLAC__metadata_object_new(FLAC__MetadataType type);
  81468. FLAC_API FLAC__StreamMetadata *FLAC__metadata_object_clone(const FLAC__StreamMetadata *object);
  81469. FLAC_API void FLAC__metadata_object_delete(FLAC__StreamMetadata *object);
  81470. FLAC_API FLAC__bool FLAC__metadata_object_is_equal(const FLAC__StreamMetadata *block1, const FLAC__StreamMetadata *block2);
  81471. FLAC_API FLAC__bool FLAC__metadata_object_application_set_data(FLAC__StreamMetadata *object, FLAC__byte *data, unsigned length, FLAC__bool copy);
  81472. FLAC_API FLAC__bool FLAC__metadata_object_seektable_resize_points(FLAC__StreamMetadata *object, unsigned new_num_points);
  81473. FLAC_API void FLAC__metadata_object_seektable_set_point(FLAC__StreamMetadata *object, unsigned point_num, FLAC__StreamMetadata_SeekPoint point);
  81474. FLAC_API FLAC__bool FLAC__metadata_object_seektable_insert_point(FLAC__StreamMetadata *object, unsigned point_num, FLAC__StreamMetadata_SeekPoint point);
  81475. FLAC_API FLAC__bool FLAC__metadata_object_seektable_delete_point(FLAC__StreamMetadata *object, unsigned point_num);
  81476. FLAC_API FLAC__bool FLAC__metadata_object_seektable_is_legal(const FLAC__StreamMetadata *object);
  81477. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_placeholders(FLAC__StreamMetadata *object, unsigned num);
  81478. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_point(FLAC__StreamMetadata *object, FLAC__uint64 sample_number);
  81479. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_points(FLAC__StreamMetadata *object, FLAC__uint64 sample_numbers[], unsigned num);
  81480. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_spaced_points(FLAC__StreamMetadata *object, unsigned num, FLAC__uint64 total_samples);
  81481. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_spaced_points_by_samples(FLAC__StreamMetadata *object, unsigned samples, FLAC__uint64 total_samples);
  81482. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_sort(FLAC__StreamMetadata *object, FLAC__bool compact);
  81483. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_set_vendor_string(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
  81484. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_resize_comments(FLAC__StreamMetadata *object, unsigned new_num_comments);
  81485. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_set_comment(FLAC__StreamMetadata *object, unsigned comment_num, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
  81486. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_insert_comment(FLAC__StreamMetadata *object, unsigned comment_num, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
  81487. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_append_comment(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
  81488. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_replace_comment(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool all, FLAC__bool copy);
  81489. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_delete_comment(FLAC__StreamMetadata *object, unsigned comment_num);
  81490. 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);
  81491. 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);
  81492. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_entry_matches(const FLAC__StreamMetadata_VorbisComment_Entry entry, const char *field_name, unsigned field_name_length);
  81493. FLAC_API int FLAC__metadata_object_vorbiscomment_find_entry_from(const FLAC__StreamMetadata *object, unsigned offset, const char *field_name);
  81494. FLAC_API int FLAC__metadata_object_vorbiscomment_remove_entry_matching(FLAC__StreamMetadata *object, const char *field_name);
  81495. FLAC_API int FLAC__metadata_object_vorbiscomment_remove_entries_matching(FLAC__StreamMetadata *object, const char *field_name);
  81496. FLAC_API FLAC__StreamMetadata_CueSheet_Track *FLAC__metadata_object_cuesheet_track_new(void);
  81497. FLAC_API FLAC__StreamMetadata_CueSheet_Track *FLAC__metadata_object_cuesheet_track_clone(const FLAC__StreamMetadata_CueSheet_Track *object);
  81498. FLAC_API void FLAC__metadata_object_cuesheet_track_delete(FLAC__StreamMetadata_CueSheet_Track *object);
  81499. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_resize_indices(FLAC__StreamMetadata *object, unsigned track_num, unsigned new_num_indices);
  81500. 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);
  81501. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_insert_blank_index(FLAC__StreamMetadata *object, unsigned track_num, unsigned index_num);
  81502. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_delete_index(FLAC__StreamMetadata *object, unsigned track_num, unsigned index_num);
  81503. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_resize_tracks(FLAC__StreamMetadata *object, unsigned new_num_tracks);
  81504. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_set_track(FLAC__StreamMetadata *object, unsigned track_num, FLAC__StreamMetadata_CueSheet_Track *track, FLAC__bool copy);
  81505. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_insert_track(FLAC__StreamMetadata *object, unsigned track_num, FLAC__StreamMetadata_CueSheet_Track *track, FLAC__bool copy);
  81506. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_insert_blank_track(FLAC__StreamMetadata *object, unsigned track_num);
  81507. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_delete_track(FLAC__StreamMetadata *object, unsigned track_num);
  81508. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_is_legal(const FLAC__StreamMetadata *object, FLAC__bool check_cd_da_subset, const char **violation);
  81509. FLAC_API FLAC__uint32 FLAC__metadata_object_cuesheet_calculate_cddb_id(const FLAC__StreamMetadata *object);
  81510. FLAC_API FLAC__bool FLAC__metadata_object_picture_set_mime_type(FLAC__StreamMetadata *object, char *mime_type, FLAC__bool copy);
  81511. FLAC_API FLAC__bool FLAC__metadata_object_picture_set_description(FLAC__StreamMetadata *object, FLAC__byte *description, FLAC__bool copy);
  81512. FLAC_API FLAC__bool FLAC__metadata_object_picture_set_data(FLAC__StreamMetadata *object, FLAC__byte *data, FLAC__uint32 length, FLAC__bool copy);
  81513. FLAC_API FLAC__bool FLAC__metadata_object_picture_is_legal(const FLAC__StreamMetadata *object, const char **violation);
  81514. #ifdef __cplusplus
  81515. }
  81516. #endif
  81517. #endif
  81518. /*** End of inlined file: metadata.h ***/
  81519. /*** Start of inlined file: stream_decoder.h ***/
  81520. #ifndef FLAC__STREAM_DECODER_H
  81521. #define FLAC__STREAM_DECODER_H
  81522. #include <stdio.h> /* for FILE */
  81523. #ifdef __cplusplus
  81524. extern "C" {
  81525. #endif
  81526. typedef enum {
  81527. FLAC__STREAM_DECODER_SEARCH_FOR_METADATA = 0,
  81528. FLAC__STREAM_DECODER_READ_METADATA,
  81529. FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC,
  81530. FLAC__STREAM_DECODER_READ_FRAME,
  81531. FLAC__STREAM_DECODER_END_OF_STREAM,
  81532. FLAC__STREAM_DECODER_OGG_ERROR,
  81533. FLAC__STREAM_DECODER_SEEK_ERROR,
  81534. FLAC__STREAM_DECODER_ABORTED,
  81535. FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR,
  81536. FLAC__STREAM_DECODER_UNINITIALIZED
  81537. } FLAC__StreamDecoderState;
  81538. extern FLAC_API const char * const FLAC__StreamDecoderStateString[];
  81539. typedef enum {
  81540. FLAC__STREAM_DECODER_INIT_STATUS_OK = 0,
  81541. FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER,
  81542. FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS,
  81543. FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR,
  81544. FLAC__STREAM_DECODER_INIT_STATUS_ERROR_OPENING_FILE,
  81545. FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED
  81546. } FLAC__StreamDecoderInitStatus;
  81547. extern FLAC_API const char * const FLAC__StreamDecoderInitStatusString[];
  81548. typedef enum {
  81549. FLAC__STREAM_DECODER_READ_STATUS_CONTINUE,
  81550. FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM,
  81551. FLAC__STREAM_DECODER_READ_STATUS_ABORT
  81552. } FLAC__StreamDecoderReadStatus;
  81553. extern FLAC_API const char * const FLAC__StreamDecoderReadStatusString[];
  81554. typedef enum {
  81555. FLAC__STREAM_DECODER_SEEK_STATUS_OK,
  81556. FLAC__STREAM_DECODER_SEEK_STATUS_ERROR,
  81557. FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED
  81558. } FLAC__StreamDecoderSeekStatus;
  81559. extern FLAC_API const char * const FLAC__StreamDecoderSeekStatusString[];
  81560. typedef enum {
  81561. FLAC__STREAM_DECODER_TELL_STATUS_OK,
  81562. FLAC__STREAM_DECODER_TELL_STATUS_ERROR,
  81563. FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED
  81564. } FLAC__StreamDecoderTellStatus;
  81565. extern FLAC_API const char * const FLAC__StreamDecoderTellStatusString[];
  81566. typedef enum {
  81567. FLAC__STREAM_DECODER_LENGTH_STATUS_OK,
  81568. FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR,
  81569. FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED
  81570. } FLAC__StreamDecoderLengthStatus;
  81571. extern FLAC_API const char * const FLAC__StreamDecoderLengthStatusString[];
  81572. typedef enum {
  81573. FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE,
  81574. FLAC__STREAM_DECODER_WRITE_STATUS_ABORT
  81575. } FLAC__StreamDecoderWriteStatus;
  81576. extern FLAC_API const char * const FLAC__StreamDecoderWriteStatusString[];
  81577. typedef enum {
  81578. FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC,
  81579. FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER,
  81580. FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH,
  81581. FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM
  81582. } FLAC__StreamDecoderErrorStatus;
  81583. extern FLAC_API const char * const FLAC__StreamDecoderErrorStatusString[];
  81584. struct FLAC__StreamDecoderProtected;
  81585. struct FLAC__StreamDecoderPrivate;
  81586. typedef struct {
  81587. struct FLAC__StreamDecoderProtected *protected_; /* avoid the C++ keyword 'protected' */
  81588. struct FLAC__StreamDecoderPrivate *private_; /* avoid the C++ keyword 'private' */
  81589. } FLAC__StreamDecoder;
  81590. typedef FLAC__StreamDecoderReadStatus (*FLAC__StreamDecoderReadCallback)(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  81591. typedef FLAC__StreamDecoderSeekStatus (*FLAC__StreamDecoderSeekCallback)(const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  81592. typedef FLAC__StreamDecoderTellStatus (*FLAC__StreamDecoderTellCallback)(const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  81593. typedef FLAC__StreamDecoderLengthStatus (*FLAC__StreamDecoderLengthCallback)(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data);
  81594. typedef FLAC__bool (*FLAC__StreamDecoderEofCallback)(const FLAC__StreamDecoder *decoder, void *client_data);
  81595. typedef FLAC__StreamDecoderWriteStatus (*FLAC__StreamDecoderWriteCallback)(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
  81596. typedef void (*FLAC__StreamDecoderMetadataCallback)(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data);
  81597. typedef void (*FLAC__StreamDecoderErrorCallback)(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data);
  81598. FLAC_API FLAC__StreamDecoder *FLAC__stream_decoder_new(void);
  81599. FLAC_API void FLAC__stream_decoder_delete(FLAC__StreamDecoder *decoder);
  81600. FLAC_API FLAC__bool FLAC__stream_decoder_set_ogg_serial_number(FLAC__StreamDecoder *decoder, long serial_number);
  81601. FLAC_API FLAC__bool FLAC__stream_decoder_set_md5_checking(FLAC__StreamDecoder *decoder, FLAC__bool value);
  81602. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond(FLAC__StreamDecoder *decoder, FLAC__MetadataType type);
  81603. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4]);
  81604. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_all(FLAC__StreamDecoder *decoder);
  81605. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore(FLAC__StreamDecoder *decoder, FLAC__MetadataType type);
  81606. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4]);
  81607. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_all(FLAC__StreamDecoder *decoder);
  81608. FLAC_API FLAC__StreamDecoderState FLAC__stream_decoder_get_state(const FLAC__StreamDecoder *decoder);
  81609. FLAC_API const char *FLAC__stream_decoder_get_resolved_state_string(const FLAC__StreamDecoder *decoder);
  81610. FLAC_API FLAC__bool FLAC__stream_decoder_get_md5_checking(const FLAC__StreamDecoder *decoder);
  81611. FLAC_API FLAC__uint64 FLAC__stream_decoder_get_total_samples(const FLAC__StreamDecoder *decoder);
  81612. FLAC_API unsigned FLAC__stream_decoder_get_channels(const FLAC__StreamDecoder *decoder);
  81613. FLAC_API FLAC__ChannelAssignment FLAC__stream_decoder_get_channel_assignment(const FLAC__StreamDecoder *decoder);
  81614. FLAC_API unsigned FLAC__stream_decoder_get_bits_per_sample(const FLAC__StreamDecoder *decoder);
  81615. FLAC_API unsigned FLAC__stream_decoder_get_sample_rate(const FLAC__StreamDecoder *decoder);
  81616. FLAC_API unsigned FLAC__stream_decoder_get_blocksize(const FLAC__StreamDecoder *decoder);
  81617. FLAC_API FLAC__bool FLAC__stream_decoder_get_decode_position(const FLAC__StreamDecoder *decoder, FLAC__uint64 *position);
  81618. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_stream(
  81619. FLAC__StreamDecoder *decoder,
  81620. FLAC__StreamDecoderReadCallback read_callback,
  81621. FLAC__StreamDecoderSeekCallback seek_callback,
  81622. FLAC__StreamDecoderTellCallback tell_callback,
  81623. FLAC__StreamDecoderLengthCallback length_callback,
  81624. FLAC__StreamDecoderEofCallback eof_callback,
  81625. FLAC__StreamDecoderWriteCallback write_callback,
  81626. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81627. FLAC__StreamDecoderErrorCallback error_callback,
  81628. void *client_data
  81629. );
  81630. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_stream(
  81631. FLAC__StreamDecoder *decoder,
  81632. FLAC__StreamDecoderReadCallback read_callback,
  81633. FLAC__StreamDecoderSeekCallback seek_callback,
  81634. FLAC__StreamDecoderTellCallback tell_callback,
  81635. FLAC__StreamDecoderLengthCallback length_callback,
  81636. FLAC__StreamDecoderEofCallback eof_callback,
  81637. FLAC__StreamDecoderWriteCallback write_callback,
  81638. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81639. FLAC__StreamDecoderErrorCallback error_callback,
  81640. void *client_data
  81641. );
  81642. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_FILE(
  81643. FLAC__StreamDecoder *decoder,
  81644. FILE *file,
  81645. FLAC__StreamDecoderWriteCallback write_callback,
  81646. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81647. FLAC__StreamDecoderErrorCallback error_callback,
  81648. void *client_data
  81649. );
  81650. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_FILE(
  81651. FLAC__StreamDecoder *decoder,
  81652. FILE *file,
  81653. FLAC__StreamDecoderWriteCallback write_callback,
  81654. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81655. FLAC__StreamDecoderErrorCallback error_callback,
  81656. void *client_data
  81657. );
  81658. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_file(
  81659. FLAC__StreamDecoder *decoder,
  81660. const char *filename,
  81661. FLAC__StreamDecoderWriteCallback write_callback,
  81662. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81663. FLAC__StreamDecoderErrorCallback error_callback,
  81664. void *client_data
  81665. );
  81666. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_file(
  81667. FLAC__StreamDecoder *decoder,
  81668. const char *filename,
  81669. FLAC__StreamDecoderWriteCallback write_callback,
  81670. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81671. FLAC__StreamDecoderErrorCallback error_callback,
  81672. void *client_data
  81673. );
  81674. FLAC_API FLAC__bool FLAC__stream_decoder_finish(FLAC__StreamDecoder *decoder);
  81675. FLAC_API FLAC__bool FLAC__stream_decoder_flush(FLAC__StreamDecoder *decoder);
  81676. FLAC_API FLAC__bool FLAC__stream_decoder_reset(FLAC__StreamDecoder *decoder);
  81677. FLAC_API FLAC__bool FLAC__stream_decoder_process_single(FLAC__StreamDecoder *decoder);
  81678. FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_metadata(FLAC__StreamDecoder *decoder);
  81679. FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_stream(FLAC__StreamDecoder *decoder);
  81680. FLAC_API FLAC__bool FLAC__stream_decoder_skip_single_frame(FLAC__StreamDecoder *decoder);
  81681. FLAC_API FLAC__bool FLAC__stream_decoder_seek_absolute(FLAC__StreamDecoder *decoder, FLAC__uint64 sample);
  81682. #ifdef __cplusplus
  81683. }
  81684. #endif
  81685. #endif
  81686. /*** End of inlined file: stream_decoder.h ***/
  81687. /*** Start of inlined file: stream_encoder.h ***/
  81688. #ifndef FLAC__STREAM_ENCODER_H
  81689. #define FLAC__STREAM_ENCODER_H
  81690. #include <stdio.h> /* for FILE */
  81691. #ifdef __cplusplus
  81692. extern "C" {
  81693. #endif
  81694. typedef enum {
  81695. FLAC__STREAM_ENCODER_OK = 0,
  81696. FLAC__STREAM_ENCODER_UNINITIALIZED,
  81697. FLAC__STREAM_ENCODER_OGG_ERROR,
  81698. FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR,
  81699. FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA,
  81700. FLAC__STREAM_ENCODER_CLIENT_ERROR,
  81701. FLAC__STREAM_ENCODER_IO_ERROR,
  81702. FLAC__STREAM_ENCODER_FRAMING_ERROR,
  81703. FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR
  81704. } FLAC__StreamEncoderState;
  81705. extern FLAC_API const char * const FLAC__StreamEncoderStateString[];
  81706. typedef enum {
  81707. FLAC__STREAM_ENCODER_INIT_STATUS_OK = 0,
  81708. FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR,
  81709. FLAC__STREAM_ENCODER_INIT_STATUS_UNSUPPORTED_CONTAINER,
  81710. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_CALLBACKS,
  81711. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_NUMBER_OF_CHANNELS,
  81712. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BITS_PER_SAMPLE,
  81713. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_SAMPLE_RATE,
  81714. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BLOCK_SIZE,
  81715. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_MAX_LPC_ORDER,
  81716. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_QLP_COEFF_PRECISION,
  81717. FLAC__STREAM_ENCODER_INIT_STATUS_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER,
  81718. FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE,
  81719. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA,
  81720. FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED
  81721. } FLAC__StreamEncoderInitStatus;
  81722. extern FLAC_API const char * const FLAC__StreamEncoderInitStatusString[];
  81723. typedef enum {
  81724. FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE,
  81725. FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM,
  81726. FLAC__STREAM_ENCODER_READ_STATUS_ABORT,
  81727. FLAC__STREAM_ENCODER_READ_STATUS_UNSUPPORTED
  81728. } FLAC__StreamEncoderReadStatus;
  81729. extern FLAC_API const char * const FLAC__StreamEncoderReadStatusString[];
  81730. typedef enum {
  81731. FLAC__STREAM_ENCODER_WRITE_STATUS_OK = 0,
  81732. FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR
  81733. } FLAC__StreamEncoderWriteStatus;
  81734. extern FLAC_API const char * const FLAC__StreamEncoderWriteStatusString[];
  81735. typedef enum {
  81736. FLAC__STREAM_ENCODER_SEEK_STATUS_OK,
  81737. FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR,
  81738. FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED
  81739. } FLAC__StreamEncoderSeekStatus;
  81740. extern FLAC_API const char * const FLAC__StreamEncoderSeekStatusString[];
  81741. typedef enum {
  81742. FLAC__STREAM_ENCODER_TELL_STATUS_OK,
  81743. FLAC__STREAM_ENCODER_TELL_STATUS_ERROR,
  81744. FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED
  81745. } FLAC__StreamEncoderTellStatus;
  81746. extern FLAC_API const char * const FLAC__StreamEncoderTellStatusString[];
  81747. struct FLAC__StreamEncoderProtected;
  81748. struct FLAC__StreamEncoderPrivate;
  81749. typedef struct {
  81750. struct FLAC__StreamEncoderProtected *protected_; /* avoid the C++ keyword 'protected' */
  81751. struct FLAC__StreamEncoderPrivate *private_; /* avoid the C++ keyword 'private' */
  81752. } FLAC__StreamEncoder;
  81753. typedef FLAC__StreamEncoderReadStatus (*FLAC__StreamEncoderReadCallback)(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  81754. typedef FLAC__StreamEncoderWriteStatus (*FLAC__StreamEncoderWriteCallback)(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, unsigned current_frame, void *client_data);
  81755. typedef FLAC__StreamEncoderSeekStatus (*FLAC__StreamEncoderSeekCallback)(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  81756. typedef FLAC__StreamEncoderTellStatus (*FLAC__StreamEncoderTellCallback)(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  81757. typedef void (*FLAC__StreamEncoderMetadataCallback)(const FLAC__StreamEncoder *encoder, const FLAC__StreamMetadata *metadata, void *client_data);
  81758. 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);
  81759. FLAC_API FLAC__StreamEncoder *FLAC__stream_encoder_new(void);
  81760. FLAC_API void FLAC__stream_encoder_delete(FLAC__StreamEncoder *encoder);
  81761. FLAC_API FLAC__bool FLAC__stream_encoder_set_ogg_serial_number(FLAC__StreamEncoder *encoder, long serial_number);
  81762. FLAC_API FLAC__bool FLAC__stream_encoder_set_verify(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81763. FLAC_API FLAC__bool FLAC__stream_encoder_set_streamable_subset(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81764. FLAC_API FLAC__bool FLAC__stream_encoder_set_channels(FLAC__StreamEncoder *encoder, unsigned value);
  81765. FLAC_API FLAC__bool FLAC__stream_encoder_set_bits_per_sample(FLAC__StreamEncoder *encoder, unsigned value);
  81766. FLAC_API FLAC__bool FLAC__stream_encoder_set_sample_rate(FLAC__StreamEncoder *encoder, unsigned value);
  81767. FLAC_API FLAC__bool FLAC__stream_encoder_set_compression_level(FLAC__StreamEncoder *encoder, unsigned value);
  81768. FLAC_API FLAC__bool FLAC__stream_encoder_set_blocksize(FLAC__StreamEncoder *encoder, unsigned value);
  81769. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81770. FLAC_API FLAC__bool FLAC__stream_encoder_set_loose_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81771. FLAC_API FLAC__bool FLAC__stream_encoder_set_apodization(FLAC__StreamEncoder *encoder, const char *specification);
  81772. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_lpc_order(FLAC__StreamEncoder *encoder, unsigned value);
  81773. FLAC_API FLAC__bool FLAC__stream_encoder_set_qlp_coeff_precision(FLAC__StreamEncoder *encoder, unsigned value);
  81774. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_qlp_coeff_prec_search(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81775. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_escape_coding(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81776. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_exhaustive_model_search(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81777. FLAC_API FLAC__bool FLAC__stream_encoder_set_min_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value);
  81778. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value);
  81779. FLAC_API FLAC__bool FLAC__stream_encoder_set_rice_parameter_search_dist(FLAC__StreamEncoder *encoder, unsigned value);
  81780. FLAC_API FLAC__bool FLAC__stream_encoder_set_total_samples_estimate(FLAC__StreamEncoder *encoder, FLAC__uint64 value);
  81781. FLAC_API FLAC__bool FLAC__stream_encoder_set_metadata(FLAC__StreamEncoder *encoder, FLAC__StreamMetadata **metadata, unsigned num_blocks);
  81782. FLAC_API FLAC__StreamEncoderState FLAC__stream_encoder_get_state(const FLAC__StreamEncoder *encoder);
  81783. FLAC_API FLAC__StreamDecoderState FLAC__stream_encoder_get_verify_decoder_state(const FLAC__StreamEncoder *encoder);
  81784. FLAC_API const char *FLAC__stream_encoder_get_resolved_state_string(const FLAC__StreamEncoder *encoder);
  81785. 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);
  81786. FLAC_API FLAC__bool FLAC__stream_encoder_get_verify(const FLAC__StreamEncoder *encoder);
  81787. FLAC_API FLAC__bool FLAC__stream_encoder_get_streamable_subset(const FLAC__StreamEncoder *encoder);
  81788. FLAC_API unsigned FLAC__stream_encoder_get_channels(const FLAC__StreamEncoder *encoder);
  81789. FLAC_API unsigned FLAC__stream_encoder_get_bits_per_sample(const FLAC__StreamEncoder *encoder);
  81790. FLAC_API unsigned FLAC__stream_encoder_get_sample_rate(const FLAC__StreamEncoder *encoder);
  81791. FLAC_API unsigned FLAC__stream_encoder_get_blocksize(const FLAC__StreamEncoder *encoder);
  81792. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_mid_side_stereo(const FLAC__StreamEncoder *encoder);
  81793. FLAC_API FLAC__bool FLAC__stream_encoder_get_loose_mid_side_stereo(const FLAC__StreamEncoder *encoder);
  81794. FLAC_API unsigned FLAC__stream_encoder_get_max_lpc_order(const FLAC__StreamEncoder *encoder);
  81795. FLAC_API unsigned FLAC__stream_encoder_get_qlp_coeff_precision(const FLAC__StreamEncoder *encoder);
  81796. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_qlp_coeff_prec_search(const FLAC__StreamEncoder *encoder);
  81797. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_escape_coding(const FLAC__StreamEncoder *encoder);
  81798. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_exhaustive_model_search(const FLAC__StreamEncoder *encoder);
  81799. FLAC_API unsigned FLAC__stream_encoder_get_min_residual_partition_order(const FLAC__StreamEncoder *encoder);
  81800. FLAC_API unsigned FLAC__stream_encoder_get_max_residual_partition_order(const FLAC__StreamEncoder *encoder);
  81801. FLAC_API unsigned FLAC__stream_encoder_get_rice_parameter_search_dist(const FLAC__StreamEncoder *encoder);
  81802. FLAC_API FLAC__uint64 FLAC__stream_encoder_get_total_samples_estimate(const FLAC__StreamEncoder *encoder);
  81803. 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);
  81804. 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);
  81805. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_FILE(FLAC__StreamEncoder *encoder, FILE *file, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  81806. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_FILE(FLAC__StreamEncoder *encoder, FILE *file, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  81807. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_file(FLAC__StreamEncoder *encoder, const char *filename, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  81808. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_file(FLAC__StreamEncoder *encoder, const char *filename, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  81809. FLAC_API FLAC__bool FLAC__stream_encoder_finish(FLAC__StreamEncoder *encoder);
  81810. FLAC_API FLAC__bool FLAC__stream_encoder_process(FLAC__StreamEncoder *encoder, const FLAC__int32 * const buffer[], unsigned samples);
  81811. FLAC_API FLAC__bool FLAC__stream_encoder_process_interleaved(FLAC__StreamEncoder *encoder, const FLAC__int32 buffer[], unsigned samples);
  81812. #ifdef __cplusplus
  81813. }
  81814. #endif
  81815. #endif
  81816. /*** End of inlined file: stream_encoder.h ***/
  81817. #ifdef _MSC_VER
  81818. static _inline FLAC__uint32 local_swap32_(FLAC__uint32 x)
  81819. {
  81820. x = ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF);
  81821. return (x>>16) | (x<<16);
  81822. }
  81823. #endif
  81824. #if defined(_MSC_VER) && defined(_X86_)
  81825. static void local_swap32_block_(FLAC__uint32 *start, FLAC__uint32 len)
  81826. {
  81827. __asm {
  81828. mov edx, start
  81829. mov ecx, len
  81830. test ecx, ecx
  81831. loop1:
  81832. jz done1
  81833. mov eax, [edx]
  81834. bswap eax
  81835. mov [edx], eax
  81836. add edx, 4
  81837. dec ecx
  81838. jmp short loop1
  81839. done1:
  81840. }
  81841. }
  81842. #endif
  81843. #endif
  81844. /*** End of inlined file: all.h ***/
  81845. /*** Start of inlined file: bitmath.c ***/
  81846. /*** Start of inlined file: juce_FlacHeader.h ***/
  81847. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  81848. // tasks..
  81849. #define VERSION "1.2.1"
  81850. #define FLAC__NO_DLL 1
  81851. #if JUCE_MSVC
  81852. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  81853. #endif
  81854. #if JUCE_MAC
  81855. #define FLAC__SYS_DARWIN 1
  81856. #endif
  81857. /*** End of inlined file: juce_FlacHeader.h ***/
  81858. #if JUCE_USE_FLAC
  81859. #if HAVE_CONFIG_H
  81860. # include <config.h>
  81861. #endif
  81862. /*** Start of inlined file: bitmath.h ***/
  81863. #ifndef FLAC__PRIVATE__BITMATH_H
  81864. #define FLAC__PRIVATE__BITMATH_H
  81865. unsigned FLAC__bitmath_ilog2(FLAC__uint32 v);
  81866. unsigned FLAC__bitmath_ilog2_wide(FLAC__uint64 v);
  81867. unsigned FLAC__bitmath_silog2(int v);
  81868. unsigned FLAC__bitmath_silog2_wide(FLAC__int64 v);
  81869. #endif
  81870. /*** End of inlined file: bitmath.h ***/
  81871. unsigned FLAC__bitmath_ilog2(FLAC__uint32 v)
  81872. {
  81873. unsigned l = 0;
  81874. FLAC__ASSERT(v > 0);
  81875. while(v >>= 1)
  81876. l++;
  81877. return l;
  81878. }
  81879. unsigned FLAC__bitmath_ilog2_wide(FLAC__uint64 v)
  81880. {
  81881. unsigned l = 0;
  81882. FLAC__ASSERT(v > 0);
  81883. while(v >>= 1)
  81884. l++;
  81885. return l;
  81886. }
  81887. unsigned FLAC__bitmath_silog2(int v)
  81888. {
  81889. while(1) {
  81890. if(v == 0) {
  81891. return 0;
  81892. }
  81893. else if(v > 0) {
  81894. unsigned l = 0;
  81895. while(v) {
  81896. l++;
  81897. v >>= 1;
  81898. }
  81899. return l+1;
  81900. }
  81901. else if(v == -1) {
  81902. return 2;
  81903. }
  81904. else {
  81905. v++;
  81906. v = -v;
  81907. }
  81908. }
  81909. }
  81910. unsigned FLAC__bitmath_silog2_wide(FLAC__int64 v)
  81911. {
  81912. while(1) {
  81913. if(v == 0) {
  81914. return 0;
  81915. }
  81916. else if(v > 0) {
  81917. unsigned l = 0;
  81918. while(v) {
  81919. l++;
  81920. v >>= 1;
  81921. }
  81922. return l+1;
  81923. }
  81924. else if(v == -1) {
  81925. return 2;
  81926. }
  81927. else {
  81928. v++;
  81929. v = -v;
  81930. }
  81931. }
  81932. }
  81933. #endif
  81934. /*** End of inlined file: bitmath.c ***/
  81935. /*** Start of inlined file: bitreader.c ***/
  81936. /*** Start of inlined file: juce_FlacHeader.h ***/
  81937. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  81938. // tasks..
  81939. #define VERSION "1.2.1"
  81940. #define FLAC__NO_DLL 1
  81941. #if JUCE_MSVC
  81942. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  81943. #endif
  81944. #if JUCE_MAC
  81945. #define FLAC__SYS_DARWIN 1
  81946. #endif
  81947. /*** End of inlined file: juce_FlacHeader.h ***/
  81948. #if JUCE_USE_FLAC
  81949. #if HAVE_CONFIG_H
  81950. # include <config.h>
  81951. #endif
  81952. #include <stdlib.h> /* for malloc() */
  81953. #include <string.h> /* for memcpy(), memset() */
  81954. #ifdef _MSC_VER
  81955. #include <winsock.h> /* for ntohl() */
  81956. #elif defined FLAC__SYS_DARWIN
  81957. #include <machine/endian.h> /* for ntohl() */
  81958. #elif defined __MINGW32__
  81959. #include <winsock.h> /* for ntohl() */
  81960. #else
  81961. #include <netinet/in.h> /* for ntohl() */
  81962. #endif
  81963. /*** Start of inlined file: bitreader.h ***/
  81964. #ifndef FLAC__PRIVATE__BITREADER_H
  81965. #define FLAC__PRIVATE__BITREADER_H
  81966. #include <stdio.h> /* for FILE */
  81967. /*** Start of inlined file: cpu.h ***/
  81968. #ifndef FLAC__PRIVATE__CPU_H
  81969. #define FLAC__PRIVATE__CPU_H
  81970. #ifdef HAVE_CONFIG_H
  81971. #include <config.h>
  81972. #endif
  81973. typedef enum {
  81974. FLAC__CPUINFO_TYPE_IA32,
  81975. FLAC__CPUINFO_TYPE_PPC,
  81976. FLAC__CPUINFO_TYPE_UNKNOWN
  81977. } FLAC__CPUInfo_Type;
  81978. typedef struct {
  81979. FLAC__bool cpuid;
  81980. FLAC__bool bswap;
  81981. FLAC__bool cmov;
  81982. FLAC__bool mmx;
  81983. FLAC__bool fxsr;
  81984. FLAC__bool sse;
  81985. FLAC__bool sse2;
  81986. FLAC__bool sse3;
  81987. FLAC__bool ssse3;
  81988. FLAC__bool _3dnow;
  81989. FLAC__bool ext3dnow;
  81990. FLAC__bool extmmx;
  81991. } FLAC__CPUInfo_IA32;
  81992. typedef struct {
  81993. FLAC__bool altivec;
  81994. FLAC__bool ppc64;
  81995. } FLAC__CPUInfo_PPC;
  81996. typedef struct {
  81997. FLAC__bool use_asm;
  81998. FLAC__CPUInfo_Type type;
  81999. union {
  82000. FLAC__CPUInfo_IA32 ia32;
  82001. FLAC__CPUInfo_PPC ppc;
  82002. } data;
  82003. } FLAC__CPUInfo;
  82004. void FLAC__cpu_info(FLAC__CPUInfo *info);
  82005. #ifndef FLAC__NO_ASM
  82006. #ifdef FLAC__CPU_IA32
  82007. #ifdef FLAC__HAS_NASM
  82008. FLAC__uint32 FLAC__cpu_have_cpuid_asm_ia32(void);
  82009. void FLAC__cpu_info_asm_ia32(FLAC__uint32 *flags_edx, FLAC__uint32 *flags_ecx);
  82010. FLAC__uint32 FLAC__cpu_info_extended_amd_asm_ia32(void);
  82011. #endif
  82012. #endif
  82013. #endif
  82014. #endif
  82015. /*** End of inlined file: cpu.h ***/
  82016. struct FLAC__BitReader;
  82017. typedef struct FLAC__BitReader FLAC__BitReader;
  82018. typedef FLAC__bool (*FLAC__BitReaderReadCallback)(FLAC__byte buffer[], size_t *bytes, void *client_data);
  82019. FLAC__BitReader *FLAC__bitreader_new(void);
  82020. void FLAC__bitreader_delete(FLAC__BitReader *br);
  82021. FLAC__bool FLAC__bitreader_init(FLAC__BitReader *br, FLAC__CPUInfo cpu, FLAC__BitReaderReadCallback rcb, void *cd);
  82022. void FLAC__bitreader_free(FLAC__BitReader *br); /* does not 'free(br)' */
  82023. FLAC__bool FLAC__bitreader_clear(FLAC__BitReader *br);
  82024. void FLAC__bitreader_dump(const FLAC__BitReader *br, FILE *out);
  82025. void FLAC__bitreader_reset_read_crc16(FLAC__BitReader *br, FLAC__uint16 seed);
  82026. FLAC__uint16 FLAC__bitreader_get_read_crc16(FLAC__BitReader *br);
  82027. FLAC__bool FLAC__bitreader_is_consumed_byte_aligned(const FLAC__BitReader *br);
  82028. unsigned FLAC__bitreader_bits_left_for_byte_alignment(const FLAC__BitReader *br);
  82029. unsigned FLAC__bitreader_get_input_bits_unconsumed(const FLAC__BitReader *br);
  82030. FLAC__bool FLAC__bitreader_read_raw_uint32(FLAC__BitReader *br, FLAC__uint32 *val, unsigned bits);
  82031. FLAC__bool FLAC__bitreader_read_raw_int32(FLAC__BitReader *br, FLAC__int32 *val, unsigned bits);
  82032. FLAC__bool FLAC__bitreader_read_raw_uint64(FLAC__BitReader *br, FLAC__uint64 *val, unsigned bits);
  82033. FLAC__bool FLAC__bitreader_read_uint32_little_endian(FLAC__BitReader *br, FLAC__uint32 *val); /*only for bits=32*/
  82034. FLAC__bool FLAC__bitreader_skip_bits_no_crc(FLAC__BitReader *br, unsigned bits); /* WATCHOUT: does not CRC the skipped data! */ /*@@@@ add to unit tests */
  82035. FLAC__bool FLAC__bitreader_skip_byte_block_aligned_no_crc(FLAC__BitReader *br, unsigned nvals); /* WATCHOUT: does not CRC the read data! */
  82036. 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! */
  82037. FLAC__bool FLAC__bitreader_read_unary_unsigned(FLAC__BitReader *br, unsigned *val);
  82038. FLAC__bool FLAC__bitreader_read_rice_signed(FLAC__BitReader *br, int *val, unsigned parameter);
  82039. FLAC__bool FLAC__bitreader_read_rice_signed_block(FLAC__BitReader *br, int vals[], unsigned nvals, unsigned parameter);
  82040. #ifndef FLAC__NO_ASM
  82041. # ifdef FLAC__CPU_IA32
  82042. # ifdef FLAC__HAS_NASM
  82043. FLAC__bool FLAC__bitreader_read_rice_signed_block_asm_ia32_bswap(FLAC__BitReader *br, int vals[], unsigned nvals, unsigned parameter);
  82044. # endif
  82045. # endif
  82046. #endif
  82047. #if 0 /* UNUSED */
  82048. FLAC__bool FLAC__bitreader_read_golomb_signed(FLAC__BitReader *br, int *val, unsigned parameter);
  82049. FLAC__bool FLAC__bitreader_read_golomb_unsigned(FLAC__BitReader *br, unsigned *val, unsigned parameter);
  82050. #endif
  82051. FLAC__bool FLAC__bitreader_read_utf8_uint32(FLAC__BitReader *br, FLAC__uint32 *val, FLAC__byte *raw, unsigned *rawlen);
  82052. FLAC__bool FLAC__bitreader_read_utf8_uint64(FLAC__BitReader *br, FLAC__uint64 *val, FLAC__byte *raw, unsigned *rawlen);
  82053. FLAC__bool bitreader_read_from_client_(FLAC__BitReader *br);
  82054. #endif
  82055. /*** End of inlined file: bitreader.h ***/
  82056. /*** Start of inlined file: crc.h ***/
  82057. #ifndef FLAC__PRIVATE__CRC_H
  82058. #define FLAC__PRIVATE__CRC_H
  82059. extern FLAC__byte const FLAC__crc8_table[256];
  82060. #define FLAC__CRC8_UPDATE(data, crc) (crc) = FLAC__crc8_table[(crc) ^ (data)];
  82061. void FLAC__crc8_update(const FLAC__byte data, FLAC__uint8 *crc);
  82062. void FLAC__crc8_update_block(const FLAC__byte *data, unsigned len, FLAC__uint8 *crc);
  82063. FLAC__uint8 FLAC__crc8(const FLAC__byte *data, unsigned len);
  82064. extern unsigned FLAC__crc16_table[256];
  82065. #define FLAC__CRC16_UPDATE(data, crc) (((((crc)<<8) & 0xffff) ^ FLAC__crc16_table[((crc)>>8) ^ (data)]))
  82066. #if 0
  82067. #define FLAC__CRC16_UPDATE(data, crc) ((((crc)<<8) ^ FLAC__crc16_table[((crc)>>8) ^ (data)]) & 0xffff)
  82068. #endif
  82069. unsigned FLAC__crc16(const FLAC__byte *data, unsigned len);
  82070. #endif
  82071. /*** End of inlined file: crc.h ***/
  82072. typedef FLAC__uint32 brword;
  82073. #define FLAC__BYTES_PER_WORD 4
  82074. #define FLAC__BITS_PER_WORD 32
  82075. #define FLAC__WORD_ALL_ONES ((FLAC__uint32)0xffffffff)
  82076. #if WORDS_BIGENDIAN
  82077. #define SWAP_BE_WORD_TO_HOST(x) (x)
  82078. #else
  82079. #if defined (_MSC_VER) && defined (_X86_)
  82080. #define SWAP_BE_WORD_TO_HOST(x) local_swap32_(x)
  82081. #else
  82082. #define SWAP_BE_WORD_TO_HOST(x) ntohl(x)
  82083. #endif
  82084. #endif
  82085. #define COUNT_ZERO_MSBS(word) ( \
  82086. (word) <= 0xffff ? \
  82087. ( (word) <= 0xff? byte_to_unary_table[word] + 24 : byte_to_unary_table[(word) >> 8] + 16 ) : \
  82088. ( (word) <= 0xffffff? byte_to_unary_table[word >> 16] + 8 : byte_to_unary_table[(word) >> 24] ) \
  82089. )
  82090. #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])) )
  82091. static const unsigned FLAC__BITREADER_DEFAULT_CAPACITY = 65536u / FLAC__BITS_PER_WORD; /* in words */
  82092. static const unsigned char byte_to_unary_table[] = {
  82093. 8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4,
  82094. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  82095. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  82096. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  82097. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  82098. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  82099. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  82100. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  82101. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  82102. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  82103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  82104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  82105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  82106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  82107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  82108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  82109. };
  82110. #ifdef min
  82111. #undef min
  82112. #endif
  82113. #define min(x,y) ((x)<(y)?(x):(y))
  82114. #ifdef max
  82115. #undef max
  82116. #endif
  82117. #define max(x,y) ((x)>(y)?(x):(y))
  82118. #ifdef _MSC_VER
  82119. #define FLAC__U64L(x) x
  82120. #else
  82121. #define FLAC__U64L(x) x##LLU
  82122. #endif
  82123. #ifndef FLaC__INLINE
  82124. #define FLaC__INLINE
  82125. #endif
  82126. struct FLAC__BitReader {
  82127. brword *buffer;
  82128. unsigned capacity; /* in words */
  82129. unsigned words; /* # of completed words in buffer */
  82130. unsigned bytes; /* # of bytes in incomplete word at buffer[words] */
  82131. unsigned consumed_words; /* #words ... */
  82132. unsigned consumed_bits; /* ... + (#bits of head word) already consumed from the front of buffer */
  82133. unsigned read_crc16; /* the running frame CRC */
  82134. unsigned crc16_align; /* the number of bits in the current consumed word that should not be CRC'd */
  82135. FLAC__BitReaderReadCallback read_callback;
  82136. void *client_data;
  82137. FLAC__CPUInfo cpu_info;
  82138. };
  82139. static FLaC__INLINE void crc16_update_word_(FLAC__BitReader *br, brword word)
  82140. {
  82141. register unsigned crc = br->read_crc16;
  82142. #if FLAC__BYTES_PER_WORD == 4
  82143. switch(br->crc16_align) {
  82144. case 0: crc = FLAC__CRC16_UPDATE((unsigned)(word >> 24), crc);
  82145. case 8: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 16) & 0xff), crc);
  82146. case 16: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 8) & 0xff), crc);
  82147. case 24: br->read_crc16 = FLAC__CRC16_UPDATE((unsigned)(word & 0xff), crc);
  82148. }
  82149. #elif FLAC__BYTES_PER_WORD == 8
  82150. switch(br->crc16_align) {
  82151. case 0: crc = FLAC__CRC16_UPDATE((unsigned)(word >> 56), crc);
  82152. case 8: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 48) & 0xff), crc);
  82153. case 16: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 40) & 0xff), crc);
  82154. case 24: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 32) & 0xff), crc);
  82155. case 32: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 24) & 0xff), crc);
  82156. case 40: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 16) & 0xff), crc);
  82157. case 48: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 8) & 0xff), crc);
  82158. case 56: br->read_crc16 = FLAC__CRC16_UPDATE((unsigned)(word & 0xff), crc);
  82159. }
  82160. #else
  82161. for( ; br->crc16_align < FLAC__BITS_PER_WORD; br->crc16_align += 8)
  82162. crc = FLAC__CRC16_UPDATE((unsigned)((word >> (FLAC__BITS_PER_WORD-8-br->crc16_align)) & 0xff), crc);
  82163. br->read_crc16 = crc;
  82164. #endif
  82165. br->crc16_align = 0;
  82166. }
  82167. FLAC__bool bitreader_read_from_client_(FLAC__BitReader *br)
  82168. {
  82169. unsigned start, end;
  82170. size_t bytes;
  82171. FLAC__byte *target;
  82172. if(br->consumed_words > 0) {
  82173. start = br->consumed_words;
  82174. end = br->words + (br->bytes? 1:0);
  82175. memmove(br->buffer, br->buffer+start, FLAC__BYTES_PER_WORD * (end - start));
  82176. br->words -= start;
  82177. br->consumed_words = 0;
  82178. }
  82179. bytes = (br->capacity - br->words) * FLAC__BYTES_PER_WORD - br->bytes;
  82180. if(bytes == 0)
  82181. return false; /* no space left, buffer is too small; see note for FLAC__BITREADER_DEFAULT_CAPACITY */
  82182. target = ((FLAC__byte*)(br->buffer+br->words)) + br->bytes;
  82183. #if WORDS_BIGENDIAN
  82184. #else
  82185. if(br->bytes)
  82186. br->buffer[br->words] = SWAP_BE_WORD_TO_HOST(br->buffer[br->words]);
  82187. #endif
  82188. if(!br->read_callback(target, &bytes, br->client_data))
  82189. return false;
  82190. #if WORDS_BIGENDIAN
  82191. #else
  82192. end = (br->words*FLAC__BYTES_PER_WORD + br->bytes + bytes + (FLAC__BYTES_PER_WORD-1)) / FLAC__BYTES_PER_WORD;
  82193. # if defined(_MSC_VER) && defined (_X86_) && (FLAC__BYTES_PER_WORD == 4)
  82194. if(br->cpu_info.type == FLAC__CPUINFO_TYPE_IA32 && br->cpu_info.data.ia32.bswap) {
  82195. start = br->words;
  82196. local_swap32_block_(br->buffer + start, end - start);
  82197. }
  82198. else
  82199. # endif
  82200. for(start = br->words; start < end; start++)
  82201. br->buffer[start] = SWAP_BE_WORD_TO_HOST(br->buffer[start]);
  82202. #endif
  82203. end = br->words*FLAC__BYTES_PER_WORD + br->bytes + bytes;
  82204. br->words = end / FLAC__BYTES_PER_WORD;
  82205. br->bytes = end % FLAC__BYTES_PER_WORD;
  82206. return true;
  82207. }
  82208. FLAC__BitReader *FLAC__bitreader_new(void)
  82209. {
  82210. FLAC__BitReader *br = (FLAC__BitReader*)calloc(1, sizeof(FLAC__BitReader));
  82211. return br;
  82212. }
  82213. void FLAC__bitreader_delete(FLAC__BitReader *br)
  82214. {
  82215. FLAC__ASSERT(0 != br);
  82216. FLAC__bitreader_free(br);
  82217. free(br);
  82218. }
  82219. FLAC__bool FLAC__bitreader_init(FLAC__BitReader *br, FLAC__CPUInfo cpu, FLAC__BitReaderReadCallback rcb, void *cd)
  82220. {
  82221. FLAC__ASSERT(0 != br);
  82222. br->words = br->bytes = 0;
  82223. br->consumed_words = br->consumed_bits = 0;
  82224. br->capacity = FLAC__BITREADER_DEFAULT_CAPACITY;
  82225. br->buffer = (brword*)malloc(sizeof(brword) * br->capacity);
  82226. if(br->buffer == 0)
  82227. return false;
  82228. br->read_callback = rcb;
  82229. br->client_data = cd;
  82230. br->cpu_info = cpu;
  82231. return true;
  82232. }
  82233. void FLAC__bitreader_free(FLAC__BitReader *br)
  82234. {
  82235. FLAC__ASSERT(0 != br);
  82236. if(0 != br->buffer)
  82237. free(br->buffer);
  82238. br->buffer = 0;
  82239. br->capacity = 0;
  82240. br->words = br->bytes = 0;
  82241. br->consumed_words = br->consumed_bits = 0;
  82242. br->read_callback = 0;
  82243. br->client_data = 0;
  82244. }
  82245. FLAC__bool FLAC__bitreader_clear(FLAC__BitReader *br)
  82246. {
  82247. br->words = br->bytes = 0;
  82248. br->consumed_words = br->consumed_bits = 0;
  82249. return true;
  82250. }
  82251. void FLAC__bitreader_dump(const FLAC__BitReader *br, FILE *out)
  82252. {
  82253. unsigned i, j;
  82254. if(br == 0) {
  82255. fprintf(out, "bitreader is NULL\n");
  82256. }
  82257. else {
  82258. 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);
  82259. for(i = 0; i < br->words; i++) {
  82260. fprintf(out, "%08X: ", i);
  82261. for(j = 0; j < FLAC__BITS_PER_WORD; j++)
  82262. if(i < br->consumed_words || (i == br->consumed_words && j < br->consumed_bits))
  82263. fprintf(out, ".");
  82264. else
  82265. fprintf(out, "%01u", br->buffer[i] & (1 << (FLAC__BITS_PER_WORD-j-1)) ? 1:0);
  82266. fprintf(out, "\n");
  82267. }
  82268. if(br->bytes > 0) {
  82269. fprintf(out, "%08X: ", i);
  82270. for(j = 0; j < br->bytes*8; j++)
  82271. if(i < br->consumed_words || (i == br->consumed_words && j < br->consumed_bits))
  82272. fprintf(out, ".");
  82273. else
  82274. fprintf(out, "%01u", br->buffer[i] & (1 << (br->bytes*8-j-1)) ? 1:0);
  82275. fprintf(out, "\n");
  82276. }
  82277. }
  82278. }
  82279. void FLAC__bitreader_reset_read_crc16(FLAC__BitReader *br, FLAC__uint16 seed)
  82280. {
  82281. FLAC__ASSERT(0 != br);
  82282. FLAC__ASSERT(0 != br->buffer);
  82283. FLAC__ASSERT((br->consumed_bits & 7) == 0);
  82284. br->read_crc16 = (unsigned)seed;
  82285. br->crc16_align = br->consumed_bits;
  82286. }
  82287. FLAC__uint16 FLAC__bitreader_get_read_crc16(FLAC__BitReader *br)
  82288. {
  82289. FLAC__ASSERT(0 != br);
  82290. FLAC__ASSERT(0 != br->buffer);
  82291. FLAC__ASSERT((br->consumed_bits & 7) == 0);
  82292. FLAC__ASSERT(br->crc16_align <= br->consumed_bits);
  82293. if(br->consumed_bits) {
  82294. const brword tail = br->buffer[br->consumed_words];
  82295. for( ; br->crc16_align < br->consumed_bits; br->crc16_align += 8)
  82296. br->read_crc16 = FLAC__CRC16_UPDATE((unsigned)((tail >> (FLAC__BITS_PER_WORD-8-br->crc16_align)) & 0xff), br->read_crc16);
  82297. }
  82298. return br->read_crc16;
  82299. }
  82300. FLaC__INLINE FLAC__bool FLAC__bitreader_is_consumed_byte_aligned(const FLAC__BitReader *br)
  82301. {
  82302. return ((br->consumed_bits & 7) == 0);
  82303. }
  82304. FLaC__INLINE unsigned FLAC__bitreader_bits_left_for_byte_alignment(const FLAC__BitReader *br)
  82305. {
  82306. return 8 - (br->consumed_bits & 7);
  82307. }
  82308. FLaC__INLINE unsigned FLAC__bitreader_get_input_bits_unconsumed(const FLAC__BitReader *br)
  82309. {
  82310. return (br->words-br->consumed_words)*FLAC__BITS_PER_WORD + br->bytes*8 - br->consumed_bits;
  82311. }
  82312. FLaC__INLINE FLAC__bool FLAC__bitreader_read_raw_uint32(FLAC__BitReader *br, FLAC__uint32 *val, unsigned bits)
  82313. {
  82314. FLAC__ASSERT(0 != br);
  82315. FLAC__ASSERT(0 != br->buffer);
  82316. FLAC__ASSERT(bits <= 32);
  82317. FLAC__ASSERT((br->capacity*FLAC__BITS_PER_WORD) * 2 >= bits);
  82318. FLAC__ASSERT(br->consumed_words <= br->words);
  82319. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  82320. if(bits == 0) { /* OPT: investigate if this can ever happen, maybe change to assertion */
  82321. *val = 0;
  82322. return true;
  82323. }
  82324. while((br->words-br->consumed_words)*FLAC__BITS_PER_WORD + br->bytes*8 - br->consumed_bits < bits) {
  82325. if(!bitreader_read_from_client_(br))
  82326. return false;
  82327. }
  82328. if(br->consumed_words < br->words) { /* if we've not consumed up to a partial tail word... */
  82329. if(br->consumed_bits) {
  82330. const unsigned n = FLAC__BITS_PER_WORD - br->consumed_bits;
  82331. const brword word = br->buffer[br->consumed_words];
  82332. if(bits < n) {
  82333. *val = (word & (FLAC__WORD_ALL_ONES >> br->consumed_bits)) >> (n-bits);
  82334. br->consumed_bits += bits;
  82335. return true;
  82336. }
  82337. *val = word & (FLAC__WORD_ALL_ONES >> br->consumed_bits);
  82338. bits -= n;
  82339. crc16_update_word_(br, word);
  82340. br->consumed_words++;
  82341. br->consumed_bits = 0;
  82342. 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 */
  82343. *val <<= bits;
  82344. *val |= (br->buffer[br->consumed_words] >> (FLAC__BITS_PER_WORD-bits));
  82345. br->consumed_bits = bits;
  82346. }
  82347. return true;
  82348. }
  82349. else {
  82350. const brword word = br->buffer[br->consumed_words];
  82351. if(bits < FLAC__BITS_PER_WORD) {
  82352. *val = word >> (FLAC__BITS_PER_WORD-bits);
  82353. br->consumed_bits = bits;
  82354. return true;
  82355. }
  82356. *val = word;
  82357. crc16_update_word_(br, word);
  82358. br->consumed_words++;
  82359. return true;
  82360. }
  82361. }
  82362. else {
  82363. if(br->consumed_bits) {
  82364. FLAC__ASSERT(br->consumed_bits + bits <= br->bytes*8);
  82365. *val = (br->buffer[br->consumed_words] & (FLAC__WORD_ALL_ONES >> br->consumed_bits)) >> (FLAC__BITS_PER_WORD-br->consumed_bits-bits);
  82366. br->consumed_bits += bits;
  82367. return true;
  82368. }
  82369. else {
  82370. *val = br->buffer[br->consumed_words] >> (FLAC__BITS_PER_WORD-bits);
  82371. br->consumed_bits += bits;
  82372. return true;
  82373. }
  82374. }
  82375. }
  82376. FLAC__bool FLAC__bitreader_read_raw_int32(FLAC__BitReader *br, FLAC__int32 *val, unsigned bits)
  82377. {
  82378. if(!FLAC__bitreader_read_raw_uint32(br, (FLAC__uint32*)val, bits))
  82379. return false;
  82380. *val <<= (32-bits);
  82381. *val >>= (32-bits);
  82382. return true;
  82383. }
  82384. FLAC__bool FLAC__bitreader_read_raw_uint64(FLAC__BitReader *br, FLAC__uint64 *val, unsigned bits)
  82385. {
  82386. FLAC__uint32 hi, lo;
  82387. if(bits > 32) {
  82388. if(!FLAC__bitreader_read_raw_uint32(br, &hi, bits-32))
  82389. return false;
  82390. if(!FLAC__bitreader_read_raw_uint32(br, &lo, 32))
  82391. return false;
  82392. *val = hi;
  82393. *val <<= 32;
  82394. *val |= lo;
  82395. }
  82396. else {
  82397. if(!FLAC__bitreader_read_raw_uint32(br, &lo, bits))
  82398. return false;
  82399. *val = lo;
  82400. }
  82401. return true;
  82402. }
  82403. FLaC__INLINE FLAC__bool FLAC__bitreader_read_uint32_little_endian(FLAC__BitReader *br, FLAC__uint32 *val)
  82404. {
  82405. FLAC__uint32 x8, x32 = 0;
  82406. if(!FLAC__bitreader_read_raw_uint32(br, &x32, 8))
  82407. return false;
  82408. if(!FLAC__bitreader_read_raw_uint32(br, &x8, 8))
  82409. return false;
  82410. x32 |= (x8 << 8);
  82411. if(!FLAC__bitreader_read_raw_uint32(br, &x8, 8))
  82412. return false;
  82413. x32 |= (x8 << 16);
  82414. if(!FLAC__bitreader_read_raw_uint32(br, &x8, 8))
  82415. return false;
  82416. x32 |= (x8 << 24);
  82417. *val = x32;
  82418. return true;
  82419. }
  82420. FLAC__bool FLAC__bitreader_skip_bits_no_crc(FLAC__BitReader *br, unsigned bits)
  82421. {
  82422. FLAC__ASSERT(0 != br);
  82423. FLAC__ASSERT(0 != br->buffer);
  82424. if(bits > 0) {
  82425. const unsigned n = br->consumed_bits & 7;
  82426. unsigned m;
  82427. FLAC__uint32 x;
  82428. if(n != 0) {
  82429. m = min(8-n, bits);
  82430. if(!FLAC__bitreader_read_raw_uint32(br, &x, m))
  82431. return false;
  82432. bits -= m;
  82433. }
  82434. m = bits / 8;
  82435. if(m > 0) {
  82436. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(br, m))
  82437. return false;
  82438. bits %= 8;
  82439. }
  82440. if(bits > 0) {
  82441. if(!FLAC__bitreader_read_raw_uint32(br, &x, bits))
  82442. return false;
  82443. }
  82444. }
  82445. return true;
  82446. }
  82447. FLAC__bool FLAC__bitreader_skip_byte_block_aligned_no_crc(FLAC__BitReader *br, unsigned nvals)
  82448. {
  82449. FLAC__uint32 x;
  82450. FLAC__ASSERT(0 != br);
  82451. FLAC__ASSERT(0 != br->buffer);
  82452. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(br));
  82453. while(nvals && br->consumed_bits) { /* i.e. run until we read 'nvals' bytes or we hit the end of the head word */
  82454. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82455. return false;
  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. br->consumed_words++;
  82463. nvals -= FLAC__BYTES_PER_WORD;
  82464. }
  82465. else if(!bitreader_read_from_client_(br))
  82466. return false;
  82467. }
  82468. while(nvals) {
  82469. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82470. return false;
  82471. nvals--;
  82472. }
  82473. return true;
  82474. }
  82475. FLAC__bool FLAC__bitreader_read_byte_block_aligned_no_crc(FLAC__BitReader *br, FLAC__byte *val, unsigned nvals)
  82476. {
  82477. FLAC__uint32 x;
  82478. FLAC__ASSERT(0 != br);
  82479. FLAC__ASSERT(0 != br->buffer);
  82480. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(br));
  82481. while(nvals && br->consumed_bits) { /* i.e. run until we read 'nvals' bytes or we hit the end of the head word */
  82482. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82483. return false;
  82484. *val++ = (FLAC__byte)x;
  82485. nvals--;
  82486. }
  82487. if(0 == nvals)
  82488. return true;
  82489. while(nvals >= FLAC__BYTES_PER_WORD) {
  82490. if(br->consumed_words < br->words) {
  82491. const brword word = br->buffer[br->consumed_words++];
  82492. #if FLAC__BYTES_PER_WORD == 4
  82493. val[0] = (FLAC__byte)(word >> 24);
  82494. val[1] = (FLAC__byte)(word >> 16);
  82495. val[2] = (FLAC__byte)(word >> 8);
  82496. val[3] = (FLAC__byte)word;
  82497. #elif FLAC__BYTES_PER_WORD == 8
  82498. val[0] = (FLAC__byte)(word >> 56);
  82499. val[1] = (FLAC__byte)(word >> 48);
  82500. val[2] = (FLAC__byte)(word >> 40);
  82501. val[3] = (FLAC__byte)(word >> 32);
  82502. val[4] = (FLAC__byte)(word >> 24);
  82503. val[5] = (FLAC__byte)(word >> 16);
  82504. val[6] = (FLAC__byte)(word >> 8);
  82505. val[7] = (FLAC__byte)word;
  82506. #else
  82507. for(x = 0; x < FLAC__BYTES_PER_WORD; x++)
  82508. val[x] = (FLAC__byte)(word >> (8*(FLAC__BYTES_PER_WORD-x-1)));
  82509. #endif
  82510. val += FLAC__BYTES_PER_WORD;
  82511. nvals -= FLAC__BYTES_PER_WORD;
  82512. }
  82513. else if(!bitreader_read_from_client_(br))
  82514. return false;
  82515. }
  82516. while(nvals) {
  82517. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82518. return false;
  82519. *val++ = (FLAC__byte)x;
  82520. nvals--;
  82521. }
  82522. return true;
  82523. }
  82524. FLaC__INLINE FLAC__bool FLAC__bitreader_read_unary_unsigned(FLAC__BitReader *br, unsigned *val)
  82525. #if 0 /* slow but readable version */
  82526. {
  82527. unsigned bit;
  82528. FLAC__ASSERT(0 != br);
  82529. FLAC__ASSERT(0 != br->buffer);
  82530. *val = 0;
  82531. while(1) {
  82532. if(!FLAC__bitreader_read_bit(br, &bit))
  82533. return false;
  82534. if(bit)
  82535. break;
  82536. else
  82537. *val++;
  82538. }
  82539. return true;
  82540. }
  82541. #else
  82542. {
  82543. unsigned i;
  82544. FLAC__ASSERT(0 != br);
  82545. FLAC__ASSERT(0 != br->buffer);
  82546. *val = 0;
  82547. while(1) {
  82548. while(br->consumed_words < br->words) { /* if we've not consumed up to a partial tail word... */
  82549. brword b = br->buffer[br->consumed_words] << br->consumed_bits;
  82550. if(b) {
  82551. i = COUNT_ZERO_MSBS(b);
  82552. *val += i;
  82553. i++;
  82554. br->consumed_bits += i;
  82555. if(br->consumed_bits >= FLAC__BITS_PER_WORD) { /* faster way of testing if(br->consumed_bits == FLAC__BITS_PER_WORD) */
  82556. crc16_update_word_(br, br->buffer[br->consumed_words]);
  82557. br->consumed_words++;
  82558. br->consumed_bits = 0;
  82559. }
  82560. return true;
  82561. }
  82562. else {
  82563. *val += FLAC__BITS_PER_WORD - br->consumed_bits;
  82564. crc16_update_word_(br, br->buffer[br->consumed_words]);
  82565. br->consumed_words++;
  82566. br->consumed_bits = 0;
  82567. }
  82568. }
  82569. if(br->bytes) {
  82570. const unsigned end = br->bytes * 8;
  82571. brword b = (br->buffer[br->consumed_words] & (FLAC__WORD_ALL_ONES << (FLAC__BITS_PER_WORD-end))) << br->consumed_bits;
  82572. if(b) {
  82573. i = COUNT_ZERO_MSBS(b);
  82574. *val += i;
  82575. i++;
  82576. br->consumed_bits += i;
  82577. FLAC__ASSERT(br->consumed_bits < FLAC__BITS_PER_WORD);
  82578. return true;
  82579. }
  82580. else {
  82581. *val += end - br->consumed_bits;
  82582. br->consumed_bits += end;
  82583. FLAC__ASSERT(br->consumed_bits < FLAC__BITS_PER_WORD);
  82584. }
  82585. }
  82586. if(!bitreader_read_from_client_(br))
  82587. return false;
  82588. }
  82589. }
  82590. #endif
  82591. FLAC__bool FLAC__bitreader_read_rice_signed(FLAC__BitReader *br, int *val, unsigned parameter)
  82592. {
  82593. FLAC__uint32 lsbs = 0, msbs = 0;
  82594. unsigned uval;
  82595. FLAC__ASSERT(0 != br);
  82596. FLAC__ASSERT(0 != br->buffer);
  82597. FLAC__ASSERT(parameter <= 31);
  82598. if(!FLAC__bitreader_read_unary_unsigned(br, (unsigned int*) &msbs))
  82599. return false;
  82600. if(!FLAC__bitreader_read_raw_uint32(br, &lsbs, parameter))
  82601. return false;
  82602. uval = (msbs << parameter) | lsbs;
  82603. if(uval & 1)
  82604. *val = -((int)(uval >> 1)) - 1;
  82605. else
  82606. *val = (int)(uval >> 1);
  82607. return true;
  82608. }
  82609. FLAC__bool FLAC__bitreader_read_rice_signed_block(FLAC__BitReader *br, int vals[], unsigned nvals, unsigned parameter)
  82610. #ifdef _MSC_VER
  82611. {
  82612. unsigned i;
  82613. unsigned uval = 0;
  82614. unsigned bits; /* the # of binary LSBs left to read to finish a rice codeword */
  82615. register unsigned cwords;
  82616. register unsigned cbits;
  82617. FLAC__ASSERT(0 != br);
  82618. FLAC__ASSERT(0 != br->buffer);
  82619. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  82620. FLAC__ASSERT(parameter < 32);
  82621. if(nvals == 0)
  82622. return true;
  82623. cbits = br->consumed_bits;
  82624. cwords = br->consumed_words;
  82625. while(1) {
  82626. while(1) {
  82627. while(cwords < br->words) { /* if we've not consumed up to a partial tail word... */
  82628. brword b = br->buffer[cwords] << cbits;
  82629. if(b) {
  82630. #if 0 /* slower, probably due to bad register allocation... */ && defined FLAC__CPU_IA32 && !defined FLAC__NO_ASM && FLAC__BITS_PER_WORD == 32
  82631. __asm {
  82632. bsr eax, b
  82633. not eax
  82634. and eax, 31
  82635. mov i, eax
  82636. }
  82637. #else
  82638. i = COUNT_ZERO_MSBS(b);
  82639. #endif
  82640. uval += i;
  82641. bits = parameter;
  82642. i++;
  82643. cbits += i;
  82644. if(cbits == FLAC__BITS_PER_WORD) {
  82645. crc16_update_word_(br, br->buffer[cwords]);
  82646. cwords++;
  82647. cbits = 0;
  82648. }
  82649. goto break1;
  82650. }
  82651. else {
  82652. uval += FLAC__BITS_PER_WORD - cbits;
  82653. crc16_update_word_(br, br->buffer[cwords]);
  82654. cwords++;
  82655. cbits = 0;
  82656. }
  82657. }
  82658. if(br->bytes) {
  82659. const unsigned end = br->bytes * 8;
  82660. brword b = (br->buffer[cwords] & (FLAC__WORD_ALL_ONES << (FLAC__BITS_PER_WORD-end))) << cbits;
  82661. if(b) {
  82662. i = COUNT_ZERO_MSBS(b);
  82663. uval += i;
  82664. bits = parameter;
  82665. i++;
  82666. cbits += i;
  82667. FLAC__ASSERT(cbits < FLAC__BITS_PER_WORD);
  82668. goto break1;
  82669. }
  82670. else {
  82671. uval += end - cbits;
  82672. cbits += end;
  82673. FLAC__ASSERT(cbits < FLAC__BITS_PER_WORD);
  82674. }
  82675. }
  82676. br->consumed_bits = cbits;
  82677. br->consumed_words = cwords;
  82678. if(!bitreader_read_from_client_(br))
  82679. return false;
  82680. cwords = br->consumed_words;
  82681. }
  82682. break1:
  82683. FLAC__ASSERT(cwords <= br->words);
  82684. if(bits) {
  82685. while((br->words-cwords)*FLAC__BITS_PER_WORD + br->bytes*8 - cbits < bits) {
  82686. br->consumed_bits = cbits;
  82687. br->consumed_words = cwords;
  82688. if(!bitreader_read_from_client_(br))
  82689. return false;
  82690. cwords = br->consumed_words;
  82691. }
  82692. if(cwords < br->words) { /* if we've not consumed up to a partial tail word... */
  82693. if(cbits) {
  82694. const unsigned n = FLAC__BITS_PER_WORD - cbits;
  82695. const brword word = br->buffer[cwords];
  82696. if(bits < n) {
  82697. uval <<= bits;
  82698. uval |= (word & (FLAC__WORD_ALL_ONES >> cbits)) >> (n-bits);
  82699. cbits += bits;
  82700. goto break2;
  82701. }
  82702. uval <<= n;
  82703. uval |= word & (FLAC__WORD_ALL_ONES >> cbits);
  82704. bits -= n;
  82705. crc16_update_word_(br, word);
  82706. cwords++;
  82707. cbits = 0;
  82708. 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 */
  82709. uval <<= bits;
  82710. uval |= (br->buffer[cwords] >> (FLAC__BITS_PER_WORD-bits));
  82711. cbits = bits;
  82712. }
  82713. goto break2;
  82714. }
  82715. else {
  82716. FLAC__ASSERT(bits < FLAC__BITS_PER_WORD);
  82717. uval <<= bits;
  82718. uval |= br->buffer[cwords] >> (FLAC__BITS_PER_WORD-bits);
  82719. cbits = bits;
  82720. goto break2;
  82721. }
  82722. }
  82723. else {
  82724. uval <<= bits;
  82725. if(cbits) {
  82726. FLAC__ASSERT(cbits + bits <= br->bytes*8);
  82727. uval |= (br->buffer[cwords] & (FLAC__WORD_ALL_ONES >> cbits)) >> (FLAC__BITS_PER_WORD-cbits-bits);
  82728. cbits += bits;
  82729. goto break2;
  82730. }
  82731. else {
  82732. uval |= br->buffer[cwords] >> (FLAC__BITS_PER_WORD-bits);
  82733. cbits += bits;
  82734. goto break2;
  82735. }
  82736. }
  82737. }
  82738. break2:
  82739. *vals = (int)(uval >> 1 ^ -(int)(uval & 1));
  82740. --nvals;
  82741. if(nvals == 0) {
  82742. br->consumed_bits = cbits;
  82743. br->consumed_words = cwords;
  82744. return true;
  82745. }
  82746. uval = 0;
  82747. ++vals;
  82748. }
  82749. }
  82750. #else
  82751. {
  82752. unsigned i;
  82753. unsigned uval = 0;
  82754. register unsigned cwords;
  82755. register unsigned cbits;
  82756. unsigned ucbits; /* keep track of the number of unconsumed bits in the buffer */
  82757. FLAC__ASSERT(0 != br);
  82758. FLAC__ASSERT(0 != br->buffer);
  82759. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  82760. FLAC__ASSERT(parameter < 32);
  82761. if(nvals == 0)
  82762. return true;
  82763. cbits = br->consumed_bits;
  82764. cwords = br->consumed_words;
  82765. ucbits = (br->words-cwords)*FLAC__BITS_PER_WORD + br->bytes*8 - cbits;
  82766. while(1) {
  82767. while(1) {
  82768. while(cwords < br->words) { /* if we've not consumed up to a partial tail word... */
  82769. brword b = br->buffer[cwords] << cbits;
  82770. if(b) {
  82771. #if 0 /* is not discernably faster... */ && defined FLAC__CPU_IA32 && !defined FLAC__NO_ASM && FLAC__BITS_PER_WORD == 32 && defined __GNUC__
  82772. asm volatile (
  82773. "bsrl %1, %0;"
  82774. "notl %0;"
  82775. "andl $31, %0;"
  82776. : "=r"(i)
  82777. : "r"(b)
  82778. );
  82779. #else
  82780. i = COUNT_ZERO_MSBS(b);
  82781. #endif
  82782. uval += i;
  82783. cbits += i;
  82784. cbits++; /* skip over stop bit */
  82785. if(cbits >= FLAC__BITS_PER_WORD) { /* faster way of testing if(cbits == FLAC__BITS_PER_WORD) */
  82786. crc16_update_word_(br, br->buffer[cwords]);
  82787. cwords++;
  82788. cbits = 0;
  82789. }
  82790. goto break1;
  82791. }
  82792. else {
  82793. uval += FLAC__BITS_PER_WORD - cbits;
  82794. crc16_update_word_(br, br->buffer[cwords]);
  82795. cwords++;
  82796. cbits = 0;
  82797. }
  82798. }
  82799. if(br->bytes) {
  82800. const unsigned end = br->bytes * 8;
  82801. brword b = (br->buffer[cwords] & ~(FLAC__WORD_ALL_ONES >> end)) << cbits;
  82802. if(b) {
  82803. i = COUNT_ZERO_MSBS(b);
  82804. uval += i;
  82805. cbits += i;
  82806. cbits++; /* skip over stop bit */
  82807. FLAC__ASSERT(cbits < FLAC__BITS_PER_WORD);
  82808. goto break1;
  82809. }
  82810. else {
  82811. uval += end - cbits;
  82812. cbits += end;
  82813. FLAC__ASSERT(cbits < FLAC__BITS_PER_WORD);
  82814. }
  82815. }
  82816. br->consumed_bits = cbits;
  82817. br->consumed_words = cwords;
  82818. if(!bitreader_read_from_client_(br))
  82819. return false;
  82820. cwords = br->consumed_words;
  82821. ucbits = (br->words-cwords)*FLAC__BITS_PER_WORD + br->bytes*8 - cbits + uval;
  82822. }
  82823. break1:
  82824. ucbits -= uval;
  82825. ucbits--; /* account for stop bit */
  82826. FLAC__ASSERT(cwords <= br->words);
  82827. if(parameter) {
  82828. while(ucbits < parameter) {
  82829. br->consumed_bits = cbits;
  82830. br->consumed_words = cwords;
  82831. if(!bitreader_read_from_client_(br))
  82832. return false;
  82833. cwords = br->consumed_words;
  82834. ucbits = (br->words-cwords)*FLAC__BITS_PER_WORD + br->bytes*8 - cbits;
  82835. }
  82836. if(cwords < br->words) { /* if we've not consumed up to a partial tail word... */
  82837. if(cbits) {
  82838. const unsigned n = FLAC__BITS_PER_WORD - cbits;
  82839. const brword word = br->buffer[cwords];
  82840. if(parameter < n) {
  82841. uval <<= parameter;
  82842. uval |= (word & (FLAC__WORD_ALL_ONES >> cbits)) >> (n-parameter);
  82843. cbits += parameter;
  82844. }
  82845. else {
  82846. uval <<= n;
  82847. uval |= word & (FLAC__WORD_ALL_ONES >> cbits);
  82848. crc16_update_word_(br, word);
  82849. cwords++;
  82850. cbits = parameter - n;
  82851. 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 */
  82852. uval <<= cbits;
  82853. uval |= (br->buffer[cwords] >> (FLAC__BITS_PER_WORD-cbits));
  82854. }
  82855. }
  82856. }
  82857. else {
  82858. cbits = parameter;
  82859. uval <<= parameter;
  82860. uval |= br->buffer[cwords] >> (FLAC__BITS_PER_WORD-cbits);
  82861. }
  82862. }
  82863. else {
  82864. uval <<= parameter;
  82865. if(cbits) {
  82866. FLAC__ASSERT(cbits + parameter <= br->bytes*8);
  82867. uval |= (br->buffer[cwords] & (FLAC__WORD_ALL_ONES >> cbits)) >> (FLAC__BITS_PER_WORD-cbits-parameter);
  82868. cbits += parameter;
  82869. }
  82870. else {
  82871. cbits = parameter;
  82872. uval |= br->buffer[cwords] >> (FLAC__BITS_PER_WORD-cbits);
  82873. }
  82874. }
  82875. }
  82876. ucbits -= parameter;
  82877. *vals = (int)(uval >> 1 ^ -(int)(uval & 1));
  82878. --nvals;
  82879. if(nvals == 0) {
  82880. br->consumed_bits = cbits;
  82881. br->consumed_words = cwords;
  82882. return true;
  82883. }
  82884. uval = 0;
  82885. ++vals;
  82886. }
  82887. }
  82888. #endif
  82889. #if 0 /* UNUSED */
  82890. FLAC__bool FLAC__bitreader_read_golomb_signed(FLAC__BitReader *br, int *val, unsigned parameter)
  82891. {
  82892. FLAC__uint32 lsbs = 0, msbs = 0;
  82893. unsigned bit, uval, k;
  82894. FLAC__ASSERT(0 != br);
  82895. FLAC__ASSERT(0 != br->buffer);
  82896. k = FLAC__bitmath_ilog2(parameter);
  82897. if(!FLAC__bitreader_read_unary_unsigned(br, &msbs))
  82898. return false;
  82899. if(!FLAC__bitreader_read_raw_uint32(br, &lsbs, k))
  82900. return false;
  82901. if(parameter == 1u<<k) {
  82902. uval = (msbs << k) | lsbs;
  82903. }
  82904. else {
  82905. unsigned d = (1 << (k+1)) - parameter;
  82906. if(lsbs >= d) {
  82907. if(!FLAC__bitreader_read_bit(br, &bit))
  82908. return false;
  82909. lsbs <<= 1;
  82910. lsbs |= bit;
  82911. lsbs -= d;
  82912. }
  82913. uval = msbs * parameter + lsbs;
  82914. }
  82915. if(uval & 1)
  82916. *val = -((int)(uval >> 1)) - 1;
  82917. else
  82918. *val = (int)(uval >> 1);
  82919. return true;
  82920. }
  82921. FLAC__bool FLAC__bitreader_read_golomb_unsigned(FLAC__BitReader *br, unsigned *val, unsigned parameter)
  82922. {
  82923. FLAC__uint32 lsbs, msbs = 0;
  82924. unsigned bit, k;
  82925. FLAC__ASSERT(0 != br);
  82926. FLAC__ASSERT(0 != br->buffer);
  82927. k = FLAC__bitmath_ilog2(parameter);
  82928. if(!FLAC__bitreader_read_unary_unsigned(br, &msbs))
  82929. return false;
  82930. if(!FLAC__bitreader_read_raw_uint32(br, &lsbs, k))
  82931. return false;
  82932. if(parameter == 1u<<k) {
  82933. *val = (msbs << k) | lsbs;
  82934. }
  82935. else {
  82936. unsigned d = (1 << (k+1)) - parameter;
  82937. if(lsbs >= d) {
  82938. if(!FLAC__bitreader_read_bit(br, &bit))
  82939. return false;
  82940. lsbs <<= 1;
  82941. lsbs |= bit;
  82942. lsbs -= d;
  82943. }
  82944. *val = msbs * parameter + lsbs;
  82945. }
  82946. return true;
  82947. }
  82948. #endif /* UNUSED */
  82949. FLAC__bool FLAC__bitreader_read_utf8_uint32(FLAC__BitReader *br, FLAC__uint32 *val, FLAC__byte *raw, unsigned *rawlen)
  82950. {
  82951. FLAC__uint32 v = 0;
  82952. FLAC__uint32 x;
  82953. unsigned i;
  82954. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82955. return false;
  82956. if(raw)
  82957. raw[(*rawlen)++] = (FLAC__byte)x;
  82958. if(!(x & 0x80)) { /* 0xxxxxxx */
  82959. v = x;
  82960. i = 0;
  82961. }
  82962. else if(x & 0xC0 && !(x & 0x20)) { /* 110xxxxx */
  82963. v = x & 0x1F;
  82964. i = 1;
  82965. }
  82966. else if(x & 0xE0 && !(x & 0x10)) { /* 1110xxxx */
  82967. v = x & 0x0F;
  82968. i = 2;
  82969. }
  82970. else if(x & 0xF0 && !(x & 0x08)) { /* 11110xxx */
  82971. v = x & 0x07;
  82972. i = 3;
  82973. }
  82974. else if(x & 0xF8 && !(x & 0x04)) { /* 111110xx */
  82975. v = x & 0x03;
  82976. i = 4;
  82977. }
  82978. else if(x & 0xFC && !(x & 0x02)) { /* 1111110x */
  82979. v = x & 0x01;
  82980. i = 5;
  82981. }
  82982. else {
  82983. *val = 0xffffffff;
  82984. return true;
  82985. }
  82986. for( ; i; i--) {
  82987. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82988. return false;
  82989. if(raw)
  82990. raw[(*rawlen)++] = (FLAC__byte)x;
  82991. if(!(x & 0x80) || (x & 0x40)) { /* 10xxxxxx */
  82992. *val = 0xffffffff;
  82993. return true;
  82994. }
  82995. v <<= 6;
  82996. v |= (x & 0x3F);
  82997. }
  82998. *val = v;
  82999. return true;
  83000. }
  83001. FLAC__bool FLAC__bitreader_read_utf8_uint64(FLAC__BitReader *br, FLAC__uint64 *val, FLAC__byte *raw, unsigned *rawlen)
  83002. {
  83003. FLAC__uint64 v = 0;
  83004. FLAC__uint32 x;
  83005. unsigned i;
  83006. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  83007. return false;
  83008. if(raw)
  83009. raw[(*rawlen)++] = (FLAC__byte)x;
  83010. if(!(x & 0x80)) { /* 0xxxxxxx */
  83011. v = x;
  83012. i = 0;
  83013. }
  83014. else if(x & 0xC0 && !(x & 0x20)) { /* 110xxxxx */
  83015. v = x & 0x1F;
  83016. i = 1;
  83017. }
  83018. else if(x & 0xE0 && !(x & 0x10)) { /* 1110xxxx */
  83019. v = x & 0x0F;
  83020. i = 2;
  83021. }
  83022. else if(x & 0xF0 && !(x & 0x08)) { /* 11110xxx */
  83023. v = x & 0x07;
  83024. i = 3;
  83025. }
  83026. else if(x & 0xF8 && !(x & 0x04)) { /* 111110xx */
  83027. v = x & 0x03;
  83028. i = 4;
  83029. }
  83030. else if(x & 0xFC && !(x & 0x02)) { /* 1111110x */
  83031. v = x & 0x01;
  83032. i = 5;
  83033. }
  83034. else if(x & 0xFE && !(x & 0x01)) { /* 11111110 */
  83035. v = 0;
  83036. i = 6;
  83037. }
  83038. else {
  83039. *val = FLAC__U64L(0xffffffffffffffff);
  83040. return true;
  83041. }
  83042. for( ; i; i--) {
  83043. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  83044. return false;
  83045. if(raw)
  83046. raw[(*rawlen)++] = (FLAC__byte)x;
  83047. if(!(x & 0x80) || (x & 0x40)) { /* 10xxxxxx */
  83048. *val = FLAC__U64L(0xffffffffffffffff);
  83049. return true;
  83050. }
  83051. v <<= 6;
  83052. v |= (x & 0x3F);
  83053. }
  83054. *val = v;
  83055. return true;
  83056. }
  83057. #endif
  83058. /*** End of inlined file: bitreader.c ***/
  83059. /*** Start of inlined file: bitwriter.c ***/
  83060. /*** Start of inlined file: juce_FlacHeader.h ***/
  83061. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  83062. // tasks..
  83063. #define VERSION "1.2.1"
  83064. #define FLAC__NO_DLL 1
  83065. #if JUCE_MSVC
  83066. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  83067. #endif
  83068. #if JUCE_MAC
  83069. #define FLAC__SYS_DARWIN 1
  83070. #endif
  83071. /*** End of inlined file: juce_FlacHeader.h ***/
  83072. #if JUCE_USE_FLAC
  83073. #if HAVE_CONFIG_H
  83074. # include <config.h>
  83075. #endif
  83076. #include <stdlib.h> /* for malloc() */
  83077. #include <string.h> /* for memcpy(), memset() */
  83078. #ifdef _MSC_VER
  83079. #include <winsock.h> /* for ntohl() */
  83080. #elif defined FLAC__SYS_DARWIN
  83081. #include <machine/endian.h> /* for ntohl() */
  83082. #elif defined __MINGW32__
  83083. #include <winsock.h> /* for ntohl() */
  83084. #else
  83085. #include <netinet/in.h> /* for ntohl() */
  83086. #endif
  83087. #if 0 /* UNUSED */
  83088. #endif
  83089. /*** Start of inlined file: bitwriter.h ***/
  83090. #ifndef FLAC__PRIVATE__BITWRITER_H
  83091. #define FLAC__PRIVATE__BITWRITER_H
  83092. #include <stdio.h> /* for FILE */
  83093. struct FLAC__BitWriter;
  83094. typedef struct FLAC__BitWriter FLAC__BitWriter;
  83095. FLAC__BitWriter *FLAC__bitwriter_new(void);
  83096. void FLAC__bitwriter_delete(FLAC__BitWriter *bw);
  83097. FLAC__bool FLAC__bitwriter_init(FLAC__BitWriter *bw);
  83098. void FLAC__bitwriter_free(FLAC__BitWriter *bw); /* does not 'free(buffer)' */
  83099. void FLAC__bitwriter_clear(FLAC__BitWriter *bw);
  83100. void FLAC__bitwriter_dump(const FLAC__BitWriter *bw, FILE *out);
  83101. FLAC__bool FLAC__bitwriter_get_write_crc16(FLAC__BitWriter *bw, FLAC__uint16 *crc);
  83102. FLAC__bool FLAC__bitwriter_get_write_crc8(FLAC__BitWriter *bw, FLAC__byte *crc);
  83103. FLAC__bool FLAC__bitwriter_is_byte_aligned(const FLAC__BitWriter *bw);
  83104. unsigned FLAC__bitwriter_get_input_bits_unconsumed(const FLAC__BitWriter *bw); /* can be called anytime, returns total # of bits unconsumed */
  83105. FLAC__bool FLAC__bitwriter_get_buffer(FLAC__BitWriter *bw, const FLAC__byte **buffer, size_t *bytes);
  83106. void FLAC__bitwriter_release_buffer(FLAC__BitWriter *bw);
  83107. FLAC__bool FLAC__bitwriter_write_zeroes(FLAC__BitWriter *bw, unsigned bits);
  83108. FLAC__bool FLAC__bitwriter_write_raw_uint32(FLAC__BitWriter *bw, FLAC__uint32 val, unsigned bits);
  83109. FLAC__bool FLAC__bitwriter_write_raw_int32(FLAC__BitWriter *bw, FLAC__int32 val, unsigned bits);
  83110. FLAC__bool FLAC__bitwriter_write_raw_uint64(FLAC__BitWriter *bw, FLAC__uint64 val, unsigned bits);
  83111. FLAC__bool FLAC__bitwriter_write_raw_uint32_little_endian(FLAC__BitWriter *bw, FLAC__uint32 val); /*only for bits=32*/
  83112. FLAC__bool FLAC__bitwriter_write_byte_block(FLAC__BitWriter *bw, const FLAC__byte vals[], unsigned nvals);
  83113. FLAC__bool FLAC__bitwriter_write_unary_unsigned(FLAC__BitWriter *bw, unsigned val);
  83114. unsigned FLAC__bitwriter_rice_bits(FLAC__int32 val, unsigned parameter);
  83115. #if 0 /* UNUSED */
  83116. unsigned FLAC__bitwriter_golomb_bits_signed(int val, unsigned parameter);
  83117. unsigned FLAC__bitwriter_golomb_bits_unsigned(unsigned val, unsigned parameter);
  83118. #endif
  83119. FLAC__bool FLAC__bitwriter_write_rice_signed(FLAC__BitWriter *bw, FLAC__int32 val, unsigned parameter);
  83120. FLAC__bool FLAC__bitwriter_write_rice_signed_block(FLAC__BitWriter *bw, const FLAC__int32 *vals, unsigned nvals, unsigned parameter);
  83121. #if 0 /* UNUSED */
  83122. FLAC__bool FLAC__bitwriter_write_golomb_signed(FLAC__BitWriter *bw, int val, unsigned parameter);
  83123. FLAC__bool FLAC__bitwriter_write_golomb_unsigned(FLAC__BitWriter *bw, unsigned val, unsigned parameter);
  83124. #endif
  83125. FLAC__bool FLAC__bitwriter_write_utf8_uint32(FLAC__BitWriter *bw, FLAC__uint32 val);
  83126. FLAC__bool FLAC__bitwriter_write_utf8_uint64(FLAC__BitWriter *bw, FLAC__uint64 val);
  83127. FLAC__bool FLAC__bitwriter_zero_pad_to_byte_boundary(FLAC__BitWriter *bw);
  83128. #endif
  83129. /*** End of inlined file: bitwriter.h ***/
  83130. /*** Start of inlined file: alloc.h ***/
  83131. #ifndef FLAC__SHARE__ALLOC_H
  83132. #define FLAC__SHARE__ALLOC_H
  83133. #if HAVE_CONFIG_H
  83134. # include <config.h>
  83135. #endif
  83136. #include <limits.h> /* for SIZE_MAX */
  83137. #if !defined _MSC_VER && !defined __MINGW32__ && !defined __EMX__
  83138. #include <stdint.h> /* for SIZE_MAX in case limits.h didn't get it */
  83139. #endif
  83140. #include <stdlib.h> /* for size_t, malloc(), etc */
  83141. #ifndef SIZE_MAX
  83142. # ifndef SIZE_T_MAX
  83143. # ifdef _MSC_VER
  83144. # define SIZE_T_MAX UINT_MAX
  83145. # else
  83146. # error
  83147. # endif
  83148. # endif
  83149. # define SIZE_MAX SIZE_T_MAX
  83150. #endif
  83151. #ifndef FLaC__INLINE
  83152. #define FLaC__INLINE
  83153. #endif
  83154. static FLaC__INLINE void *safe_malloc_(size_t size)
  83155. {
  83156. if(!size)
  83157. size++;
  83158. return malloc(size);
  83159. }
  83160. static FLaC__INLINE void *safe_calloc_(size_t nmemb, size_t size)
  83161. {
  83162. if(!nmemb || !size)
  83163. return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
  83164. return calloc(nmemb, size);
  83165. }
  83166. static FLaC__INLINE void *safe_malloc_add_2op_(size_t size1, size_t size2)
  83167. {
  83168. size2 += size1;
  83169. if(size2 < size1)
  83170. return 0;
  83171. return safe_malloc_(size2);
  83172. }
  83173. static FLaC__INLINE void *safe_malloc_add_3op_(size_t size1, size_t size2, size_t size3)
  83174. {
  83175. size2 += size1;
  83176. if(size2 < size1)
  83177. return 0;
  83178. size3 += size2;
  83179. if(size3 < size2)
  83180. return 0;
  83181. return safe_malloc_(size3);
  83182. }
  83183. static FLaC__INLINE void *safe_malloc_add_4op_(size_t size1, size_t size2, size_t size3, size_t size4)
  83184. {
  83185. size2 += size1;
  83186. if(size2 < size1)
  83187. return 0;
  83188. size3 += size2;
  83189. if(size3 < size2)
  83190. return 0;
  83191. size4 += size3;
  83192. if(size4 < size3)
  83193. return 0;
  83194. return safe_malloc_(size4);
  83195. }
  83196. static FLaC__INLINE void *safe_malloc_mul_2op_(size_t size1, size_t size2)
  83197. #if 0
  83198. needs support for cases where sizeof(size_t) != 4
  83199. {
  83200. if(sizeof(size_t) == 4) {
  83201. if ((double)size1 * (double)size2 < 4294967296.0)
  83202. return malloc(size1*size2);
  83203. }
  83204. return 0;
  83205. }
  83206. #else
  83207. {
  83208. if(!size1 || !size2)
  83209. return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
  83210. if(size1 > SIZE_MAX / size2)
  83211. return 0;
  83212. return malloc(size1*size2);
  83213. }
  83214. #endif
  83215. static FLaC__INLINE void *safe_malloc_mul_3op_(size_t size1, size_t size2, size_t size3)
  83216. {
  83217. if(!size1 || !size2 || !size3)
  83218. return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
  83219. if(size1 > SIZE_MAX / size2)
  83220. return 0;
  83221. size1 *= size2;
  83222. if(size1 > SIZE_MAX / size3)
  83223. return 0;
  83224. return malloc(size1*size3);
  83225. }
  83226. static FLaC__INLINE void *safe_malloc_mul2add_(size_t size1, size_t size2, size_t size3)
  83227. {
  83228. if(!size1 || !size2)
  83229. return safe_malloc_(size3);
  83230. if(size1 > SIZE_MAX / size2)
  83231. return 0;
  83232. return safe_malloc_add_2op_(size1*size2, size3);
  83233. }
  83234. static FLaC__INLINE void *safe_malloc_muladd2_(size_t size1, size_t size2, size_t size3)
  83235. {
  83236. if(!size1 || (!size2 && !size3))
  83237. return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
  83238. size2 += size3;
  83239. if(size2 < size3)
  83240. return 0;
  83241. return safe_malloc_mul_2op_(size1, size2);
  83242. }
  83243. static FLaC__INLINE void *safe_realloc_add_2op_(void *ptr, size_t size1, size_t size2)
  83244. {
  83245. size2 += size1;
  83246. if(size2 < size1)
  83247. return 0;
  83248. return realloc(ptr, size2);
  83249. }
  83250. static FLaC__INLINE void *safe_realloc_add_3op_(void *ptr, size_t size1, size_t size2, size_t size3)
  83251. {
  83252. size2 += size1;
  83253. if(size2 < size1)
  83254. return 0;
  83255. size3 += size2;
  83256. if(size3 < size2)
  83257. return 0;
  83258. return realloc(ptr, size3);
  83259. }
  83260. static FLaC__INLINE void *safe_realloc_add_4op_(void *ptr, size_t size1, size_t size2, size_t size3, size_t size4)
  83261. {
  83262. size2 += size1;
  83263. if(size2 < size1)
  83264. return 0;
  83265. size3 += size2;
  83266. if(size3 < size2)
  83267. return 0;
  83268. size4 += size3;
  83269. if(size4 < size3)
  83270. return 0;
  83271. return realloc(ptr, size4);
  83272. }
  83273. static FLaC__INLINE void *safe_realloc_mul_2op_(void *ptr, size_t size1, size_t size2)
  83274. {
  83275. if(!size1 || !size2)
  83276. return realloc(ptr, 0); /* preserve POSIX realloc(ptr, 0) semantics */
  83277. if(size1 > SIZE_MAX / size2)
  83278. return 0;
  83279. return realloc(ptr, size1*size2);
  83280. }
  83281. static FLaC__INLINE void *safe_realloc_muladd2_(void *ptr, size_t size1, size_t size2, size_t size3)
  83282. {
  83283. if(!size1 || (!size2 && !size3))
  83284. return realloc(ptr, 0); /* preserve POSIX realloc(ptr, 0) semantics */
  83285. size2 += size3;
  83286. if(size2 < size3)
  83287. return 0;
  83288. return safe_realloc_mul_2op_(ptr, size1, size2);
  83289. }
  83290. #endif
  83291. /*** End of inlined file: alloc.h ***/
  83292. typedef FLAC__uint32 bwword;
  83293. #define FLAC__BYTES_PER_WORD 4
  83294. #define FLAC__BITS_PER_WORD 32
  83295. #define FLAC__WORD_ALL_ONES ((FLAC__uint32)0xffffffff)
  83296. #if WORDS_BIGENDIAN
  83297. #define SWAP_BE_WORD_TO_HOST(x) (x)
  83298. #else
  83299. #ifdef _MSC_VER
  83300. #define SWAP_BE_WORD_TO_HOST(x) local_swap32_(x)
  83301. #else
  83302. #define SWAP_BE_WORD_TO_HOST(x) ntohl(x)
  83303. #endif
  83304. #endif
  83305. static const unsigned FLAC__BITWRITER_DEFAULT_CAPACITY = 32768u / sizeof(bwword); /* size in words */
  83306. static const unsigned FLAC__BITWRITER_DEFAULT_INCREMENT = 4096u / sizeof(bwword); /* size in words */
  83307. #define FLAC__WORDS_TO_BITS(words) ((words) * FLAC__BITS_PER_WORD)
  83308. #define FLAC__TOTAL_BITS(bw) (FLAC__WORDS_TO_BITS((bw)->words) + (bw)->bits)
  83309. #ifdef min
  83310. #undef min
  83311. #endif
  83312. #define min(x,y) ((x)<(y)?(x):(y))
  83313. #ifdef _MSC_VER
  83314. #define FLAC__U64L(x) x
  83315. #else
  83316. #define FLAC__U64L(x) x##LLU
  83317. #endif
  83318. #ifndef FLaC__INLINE
  83319. #define FLaC__INLINE
  83320. #endif
  83321. struct FLAC__BitWriter {
  83322. bwword *buffer;
  83323. bwword accum; /* accumulator; bits are right-justified; when full, accum is appended to buffer */
  83324. unsigned capacity; /* capacity of buffer in words */
  83325. unsigned words; /* # of complete words in buffer */
  83326. unsigned bits; /* # of used bits in accum */
  83327. };
  83328. static FLAC__bool bitwriter_grow_(FLAC__BitWriter *bw, unsigned bits_to_add)
  83329. {
  83330. unsigned new_capacity;
  83331. bwword *new_buffer;
  83332. FLAC__ASSERT(0 != bw);
  83333. FLAC__ASSERT(0 != bw->buffer);
  83334. new_capacity = bw->words + ((bw->bits + bits_to_add + FLAC__BITS_PER_WORD - 1) / FLAC__BITS_PER_WORD);
  83335. if(bw->capacity >= new_capacity)
  83336. return true;
  83337. if((new_capacity - bw->capacity) % FLAC__BITWRITER_DEFAULT_INCREMENT)
  83338. new_capacity += FLAC__BITWRITER_DEFAULT_INCREMENT - ((new_capacity - bw->capacity) % FLAC__BITWRITER_DEFAULT_INCREMENT);
  83339. FLAC__ASSERT(0 == (new_capacity - bw->capacity) % FLAC__BITWRITER_DEFAULT_INCREMENT);
  83340. FLAC__ASSERT(new_capacity > bw->capacity);
  83341. FLAC__ASSERT(new_capacity >= bw->words + ((bw->bits + bits_to_add + FLAC__BITS_PER_WORD - 1) / FLAC__BITS_PER_WORD));
  83342. new_buffer = (bwword*)safe_realloc_mul_2op_(bw->buffer, sizeof(bwword), /*times*/new_capacity);
  83343. if(new_buffer == 0)
  83344. return false;
  83345. bw->buffer = new_buffer;
  83346. bw->capacity = new_capacity;
  83347. return true;
  83348. }
  83349. FLAC__BitWriter *FLAC__bitwriter_new(void)
  83350. {
  83351. FLAC__BitWriter *bw = (FLAC__BitWriter*)calloc(1, sizeof(FLAC__BitWriter));
  83352. return bw;
  83353. }
  83354. void FLAC__bitwriter_delete(FLAC__BitWriter *bw)
  83355. {
  83356. FLAC__ASSERT(0 != bw);
  83357. FLAC__bitwriter_free(bw);
  83358. free(bw);
  83359. }
  83360. FLAC__bool FLAC__bitwriter_init(FLAC__BitWriter *bw)
  83361. {
  83362. FLAC__ASSERT(0 != bw);
  83363. bw->words = bw->bits = 0;
  83364. bw->capacity = FLAC__BITWRITER_DEFAULT_CAPACITY;
  83365. bw->buffer = (bwword*)malloc(sizeof(bwword) * bw->capacity);
  83366. if(bw->buffer == 0)
  83367. return false;
  83368. return true;
  83369. }
  83370. void FLAC__bitwriter_free(FLAC__BitWriter *bw)
  83371. {
  83372. FLAC__ASSERT(0 != bw);
  83373. if(0 != bw->buffer)
  83374. free(bw->buffer);
  83375. bw->buffer = 0;
  83376. bw->capacity = 0;
  83377. bw->words = bw->bits = 0;
  83378. }
  83379. void FLAC__bitwriter_clear(FLAC__BitWriter *bw)
  83380. {
  83381. bw->words = bw->bits = 0;
  83382. }
  83383. void FLAC__bitwriter_dump(const FLAC__BitWriter *bw, FILE *out)
  83384. {
  83385. unsigned i, j;
  83386. if(bw == 0) {
  83387. fprintf(out, "bitwriter is NULL\n");
  83388. }
  83389. else {
  83390. fprintf(out, "bitwriter: capacity=%u words=%u bits=%u total_bits=%u\n", bw->capacity, bw->words, bw->bits, FLAC__TOTAL_BITS(bw));
  83391. for(i = 0; i < bw->words; i++) {
  83392. fprintf(out, "%08X: ", i);
  83393. for(j = 0; j < FLAC__BITS_PER_WORD; j++)
  83394. fprintf(out, "%01u", bw->buffer[i] & (1 << (FLAC__BITS_PER_WORD-j-1)) ? 1:0);
  83395. fprintf(out, "\n");
  83396. }
  83397. if(bw->bits > 0) {
  83398. fprintf(out, "%08X: ", i);
  83399. for(j = 0; j < bw->bits; j++)
  83400. fprintf(out, "%01u", bw->accum & (1 << (bw->bits-j-1)) ? 1:0);
  83401. fprintf(out, "\n");
  83402. }
  83403. }
  83404. }
  83405. FLAC__bool FLAC__bitwriter_get_write_crc16(FLAC__BitWriter *bw, FLAC__uint16 *crc)
  83406. {
  83407. const FLAC__byte *buffer;
  83408. size_t bytes;
  83409. FLAC__ASSERT((bw->bits & 7) == 0); /* assert that we're byte-aligned */
  83410. if(!FLAC__bitwriter_get_buffer(bw, &buffer, &bytes))
  83411. return false;
  83412. *crc = (FLAC__uint16)FLAC__crc16(buffer, bytes);
  83413. FLAC__bitwriter_release_buffer(bw);
  83414. return true;
  83415. }
  83416. FLAC__bool FLAC__bitwriter_get_write_crc8(FLAC__BitWriter *bw, FLAC__byte *crc)
  83417. {
  83418. const FLAC__byte *buffer;
  83419. size_t bytes;
  83420. FLAC__ASSERT((bw->bits & 7) == 0); /* assert that we're byte-aligned */
  83421. if(!FLAC__bitwriter_get_buffer(bw, &buffer, &bytes))
  83422. return false;
  83423. *crc = FLAC__crc8(buffer, bytes);
  83424. FLAC__bitwriter_release_buffer(bw);
  83425. return true;
  83426. }
  83427. FLAC__bool FLAC__bitwriter_is_byte_aligned(const FLAC__BitWriter *bw)
  83428. {
  83429. return ((bw->bits & 7) == 0);
  83430. }
  83431. unsigned FLAC__bitwriter_get_input_bits_unconsumed(const FLAC__BitWriter *bw)
  83432. {
  83433. return FLAC__TOTAL_BITS(bw);
  83434. }
  83435. FLAC__bool FLAC__bitwriter_get_buffer(FLAC__BitWriter *bw, const FLAC__byte **buffer, size_t *bytes)
  83436. {
  83437. FLAC__ASSERT((bw->bits & 7) == 0);
  83438. if(bw->bits & 7)
  83439. return false;
  83440. if(bw->bits) {
  83441. FLAC__ASSERT(bw->words <= bw->capacity);
  83442. if(bw->words == bw->capacity && !bitwriter_grow_(bw, FLAC__BITS_PER_WORD))
  83443. return false;
  83444. bw->buffer[bw->words] = SWAP_BE_WORD_TO_HOST(bw->accum << (FLAC__BITS_PER_WORD-bw->bits));
  83445. }
  83446. *buffer = (FLAC__byte*)bw->buffer;
  83447. *bytes = (FLAC__BYTES_PER_WORD * bw->words) + (bw->bits >> 3);
  83448. return true;
  83449. }
  83450. void FLAC__bitwriter_release_buffer(FLAC__BitWriter *bw)
  83451. {
  83452. (void)bw;
  83453. }
  83454. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_zeroes(FLAC__BitWriter *bw, unsigned bits)
  83455. {
  83456. unsigned n;
  83457. FLAC__ASSERT(0 != bw);
  83458. FLAC__ASSERT(0 != bw->buffer);
  83459. if(bits == 0)
  83460. return true;
  83461. if(bw->capacity <= bw->words + bits && !bitwriter_grow_(bw, bits))
  83462. return false;
  83463. if(bw->bits) {
  83464. n = min(FLAC__BITS_PER_WORD - bw->bits, bits);
  83465. bw->accum <<= n;
  83466. bits -= n;
  83467. bw->bits += n;
  83468. if(bw->bits == FLAC__BITS_PER_WORD) {
  83469. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  83470. bw->bits = 0;
  83471. }
  83472. else
  83473. return true;
  83474. }
  83475. while(bits >= FLAC__BITS_PER_WORD) {
  83476. bw->buffer[bw->words++] = 0;
  83477. bits -= FLAC__BITS_PER_WORD;
  83478. }
  83479. if(bits > 0) {
  83480. bw->accum = 0;
  83481. bw->bits = bits;
  83482. }
  83483. return true;
  83484. }
  83485. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_raw_uint32(FLAC__BitWriter *bw, FLAC__uint32 val, unsigned bits)
  83486. {
  83487. register unsigned left;
  83488. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  83489. FLAC__ASSERT(0 != bw);
  83490. FLAC__ASSERT(0 != bw->buffer);
  83491. FLAC__ASSERT(bits <= 32);
  83492. if(bits == 0)
  83493. return true;
  83494. if(bw->capacity <= bw->words + bits && !bitwriter_grow_(bw, bits))
  83495. return false;
  83496. left = FLAC__BITS_PER_WORD - bw->bits;
  83497. if(bits < left) {
  83498. bw->accum <<= bits;
  83499. bw->accum |= val;
  83500. bw->bits += bits;
  83501. }
  83502. 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 */
  83503. bw->accum <<= left;
  83504. bw->accum |= val >> (bw->bits = bits - left);
  83505. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  83506. bw->accum = val;
  83507. }
  83508. else {
  83509. bw->accum = val;
  83510. bw->bits = 0;
  83511. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(val);
  83512. }
  83513. return true;
  83514. }
  83515. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_raw_int32(FLAC__BitWriter *bw, FLAC__int32 val, unsigned bits)
  83516. {
  83517. if(bits < 32)
  83518. val &= (~(0xffffffff << bits));
  83519. return FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, bits);
  83520. }
  83521. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_raw_uint64(FLAC__BitWriter *bw, FLAC__uint64 val, unsigned bits)
  83522. {
  83523. if(bits > 32) {
  83524. return
  83525. FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)(val>>32), bits-32) &&
  83526. FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, 32);
  83527. }
  83528. else
  83529. return FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, bits);
  83530. }
  83531. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_raw_uint32_little_endian(FLAC__BitWriter *bw, FLAC__uint32 val)
  83532. {
  83533. if(!FLAC__bitwriter_write_raw_uint32(bw, val & 0xff, 8))
  83534. return false;
  83535. if(!FLAC__bitwriter_write_raw_uint32(bw, (val>>8) & 0xff, 8))
  83536. return false;
  83537. if(!FLAC__bitwriter_write_raw_uint32(bw, (val>>16) & 0xff, 8))
  83538. return false;
  83539. if(!FLAC__bitwriter_write_raw_uint32(bw, val>>24, 8))
  83540. return false;
  83541. return true;
  83542. }
  83543. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_byte_block(FLAC__BitWriter *bw, const FLAC__byte vals[], unsigned nvals)
  83544. {
  83545. unsigned i;
  83546. for(i = 0; i < nvals; i++) {
  83547. if(!FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)(vals[i]), 8))
  83548. return false;
  83549. }
  83550. return true;
  83551. }
  83552. FLAC__bool FLAC__bitwriter_write_unary_unsigned(FLAC__BitWriter *bw, unsigned val)
  83553. {
  83554. if(val < 32)
  83555. return FLAC__bitwriter_write_raw_uint32(bw, 1, ++val);
  83556. else
  83557. return
  83558. FLAC__bitwriter_write_zeroes(bw, val) &&
  83559. FLAC__bitwriter_write_raw_uint32(bw, 1, 1);
  83560. }
  83561. unsigned FLAC__bitwriter_rice_bits(FLAC__int32 val, unsigned parameter)
  83562. {
  83563. FLAC__uint32 uval;
  83564. FLAC__ASSERT(parameter < sizeof(unsigned)*8);
  83565. uval = (val<<1) ^ (val>>31);
  83566. return 1 + parameter + (uval >> parameter);
  83567. }
  83568. #if 0 /* UNUSED */
  83569. unsigned FLAC__bitwriter_golomb_bits_signed(int val, unsigned parameter)
  83570. {
  83571. unsigned bits, msbs, uval;
  83572. unsigned k;
  83573. FLAC__ASSERT(parameter > 0);
  83574. if(val < 0)
  83575. uval = (unsigned)(((-(++val)) << 1) + 1);
  83576. else
  83577. uval = (unsigned)(val << 1);
  83578. k = FLAC__bitmath_ilog2(parameter);
  83579. if(parameter == 1u<<k) {
  83580. FLAC__ASSERT(k <= 30);
  83581. msbs = uval >> k;
  83582. bits = 1 + k + msbs;
  83583. }
  83584. else {
  83585. unsigned q, r, d;
  83586. d = (1 << (k+1)) - parameter;
  83587. q = uval / parameter;
  83588. r = uval - (q * parameter);
  83589. bits = 1 + q + k;
  83590. if(r >= d)
  83591. bits++;
  83592. }
  83593. return bits;
  83594. }
  83595. unsigned FLAC__bitwriter_golomb_bits_unsigned(unsigned uval, unsigned parameter)
  83596. {
  83597. unsigned bits, msbs;
  83598. unsigned k;
  83599. FLAC__ASSERT(parameter > 0);
  83600. k = FLAC__bitmath_ilog2(parameter);
  83601. if(parameter == 1u<<k) {
  83602. FLAC__ASSERT(k <= 30);
  83603. msbs = uval >> k;
  83604. bits = 1 + k + msbs;
  83605. }
  83606. else {
  83607. unsigned q, r, d;
  83608. d = (1 << (k+1)) - parameter;
  83609. q = uval / parameter;
  83610. r = uval - (q * parameter);
  83611. bits = 1 + q + k;
  83612. if(r >= d)
  83613. bits++;
  83614. }
  83615. return bits;
  83616. }
  83617. #endif /* UNUSED */
  83618. FLAC__bool FLAC__bitwriter_write_rice_signed(FLAC__BitWriter *bw, FLAC__int32 val, unsigned parameter)
  83619. {
  83620. unsigned total_bits, interesting_bits, msbs;
  83621. FLAC__uint32 uval, pattern;
  83622. FLAC__ASSERT(0 != bw);
  83623. FLAC__ASSERT(0 != bw->buffer);
  83624. FLAC__ASSERT(parameter < 8*sizeof(uval));
  83625. uval = (val<<1) ^ (val>>31);
  83626. msbs = uval >> parameter;
  83627. interesting_bits = 1 + parameter;
  83628. total_bits = interesting_bits + msbs;
  83629. pattern = 1 << parameter; /* the unary end bit */
  83630. pattern |= (uval & ((1<<parameter)-1)); /* the binary LSBs */
  83631. if(total_bits <= 32)
  83632. return FLAC__bitwriter_write_raw_uint32(bw, pattern, total_bits);
  83633. else
  83634. return
  83635. FLAC__bitwriter_write_zeroes(bw, msbs) && /* write the unary MSBs */
  83636. FLAC__bitwriter_write_raw_uint32(bw, pattern, interesting_bits); /* write the unary end bit and binary LSBs */
  83637. }
  83638. FLAC__bool FLAC__bitwriter_write_rice_signed_block(FLAC__BitWriter *bw, const FLAC__int32 *vals, unsigned nvals, unsigned parameter)
  83639. {
  83640. const FLAC__uint32 mask1 = FLAC__WORD_ALL_ONES << parameter; /* we val|=mask1 to set the stop bit above it... */
  83641. const FLAC__uint32 mask2 = FLAC__WORD_ALL_ONES >> (31-parameter); /* ...then mask off the bits above the stop bit with val&=mask2*/
  83642. FLAC__uint32 uval;
  83643. unsigned left;
  83644. const unsigned lsbits = 1 + parameter;
  83645. unsigned msbits;
  83646. FLAC__ASSERT(0 != bw);
  83647. FLAC__ASSERT(0 != bw->buffer);
  83648. FLAC__ASSERT(parameter < 8*sizeof(bwword)-1);
  83649. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  83650. while(nvals) {
  83651. uval = (*vals<<1) ^ (*vals>>31);
  83652. msbits = uval >> parameter;
  83653. #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) */
  83654. if(bw->bits && bw->bits + msbits + lsbits <= FLAC__BITS_PER_WORD) { /* i.e. if the whole thing fits in the current bwword */
  83655. bw->bits = bw->bits + msbits + lsbits;
  83656. uval |= mask1; /* set stop bit */
  83657. uval &= mask2; /* mask off unused top bits */
  83658. bw->accum <<= msbits;
  83659. bw->accum <<= lsbits;
  83660. bw->accum |= uval;
  83661. if(bw->bits == FLAC__BITS_PER_WORD) {
  83662. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  83663. bw->bits = 0;
  83664. if(bw->capacity <= bw->words && nvals > 1 && !bitwriter_grow_(bw, 1)) {
  83665. FLAC__ASSERT(bw->capacity == bw->words);
  83666. return false;
  83667. }
  83668. }
  83669. }
  83670. else {
  83671. #elif 1 /*@@@@@@ OPT: try this version with MSVC6 to see if better, not much difference for gcc-4 */
  83672. if(bw->bits && bw->bits + msbits + lsbits < FLAC__BITS_PER_WORD) { /* i.e. if the whole thing fits in the current bwword */
  83673. bw->bits = bw->bits + msbits + lsbits;
  83674. uval |= mask1; /* set stop bit */
  83675. uval &= mask2; /* mask off unused top bits */
  83676. bw->accum <<= msbits + lsbits;
  83677. bw->accum |= uval;
  83678. }
  83679. else {
  83680. #endif
  83681. if(bw->capacity <= bw->words + bw->bits + msbits + 1/*lsbits always fit in 1 bwword*/ && !bitwriter_grow_(bw, msbits+lsbits))
  83682. return false;
  83683. if(msbits) {
  83684. if(bw->bits) {
  83685. left = FLAC__BITS_PER_WORD - bw->bits;
  83686. if(msbits < left) {
  83687. bw->accum <<= msbits;
  83688. bw->bits += msbits;
  83689. goto break1;
  83690. }
  83691. else {
  83692. bw->accum <<= left;
  83693. msbits -= left;
  83694. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  83695. bw->bits = 0;
  83696. }
  83697. }
  83698. while(msbits >= FLAC__BITS_PER_WORD) {
  83699. bw->buffer[bw->words++] = 0;
  83700. msbits -= FLAC__BITS_PER_WORD;
  83701. }
  83702. if(msbits > 0) {
  83703. bw->accum = 0;
  83704. bw->bits = msbits;
  83705. }
  83706. }
  83707. break1:
  83708. uval |= mask1; /* set stop bit */
  83709. uval &= mask2; /* mask off unused top bits */
  83710. left = FLAC__BITS_PER_WORD - bw->bits;
  83711. if(lsbits < left) {
  83712. bw->accum <<= lsbits;
  83713. bw->accum |= uval;
  83714. bw->bits += lsbits;
  83715. }
  83716. else {
  83717. FLAC__ASSERT(bw->bits);
  83718. FLAC__ASSERT(left < FLAC__BITS_PER_WORD);
  83719. bw->accum <<= left;
  83720. bw->accum |= uval >> (bw->bits = lsbits - left);
  83721. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  83722. bw->accum = uval;
  83723. }
  83724. #if 1
  83725. }
  83726. #endif
  83727. vals++;
  83728. nvals--;
  83729. }
  83730. return true;
  83731. }
  83732. #if 0 /* UNUSED */
  83733. FLAC__bool FLAC__bitwriter_write_golomb_signed(FLAC__BitWriter *bw, int val, unsigned parameter)
  83734. {
  83735. unsigned total_bits, msbs, uval;
  83736. unsigned k;
  83737. FLAC__ASSERT(0 != bw);
  83738. FLAC__ASSERT(0 != bw->buffer);
  83739. FLAC__ASSERT(parameter > 0);
  83740. if(val < 0)
  83741. uval = (unsigned)(((-(++val)) << 1) + 1);
  83742. else
  83743. uval = (unsigned)(val << 1);
  83744. k = FLAC__bitmath_ilog2(parameter);
  83745. if(parameter == 1u<<k) {
  83746. unsigned pattern;
  83747. FLAC__ASSERT(k <= 30);
  83748. msbs = uval >> k;
  83749. total_bits = 1 + k + msbs;
  83750. pattern = 1 << k; /* the unary end bit */
  83751. pattern |= (uval & ((1u<<k)-1)); /* the binary LSBs */
  83752. if(total_bits <= 32) {
  83753. if(!FLAC__bitwriter_write_raw_uint32(bw, pattern, total_bits))
  83754. return false;
  83755. }
  83756. else {
  83757. if(!FLAC__bitwriter_write_zeroes(bw, msbs))
  83758. return false;
  83759. if(!FLAC__bitwriter_write_raw_uint32(bw, pattern, k+1))
  83760. return false;
  83761. }
  83762. }
  83763. else {
  83764. unsigned q, r, d;
  83765. d = (1 << (k+1)) - parameter;
  83766. q = uval / parameter;
  83767. r = uval - (q * parameter);
  83768. if(!FLAC__bitwriter_write_zeroes(bw, q))
  83769. return false;
  83770. if(!FLAC__bitwriter_write_raw_uint32(bw, 1, 1))
  83771. return false;
  83772. if(r >= d) {
  83773. if(!FLAC__bitwriter_write_raw_uint32(bw, r+d, k+1))
  83774. return false;
  83775. }
  83776. else {
  83777. if(!FLAC__bitwriter_write_raw_uint32(bw, r, k))
  83778. return false;
  83779. }
  83780. }
  83781. return true;
  83782. }
  83783. FLAC__bool FLAC__bitwriter_write_golomb_unsigned(FLAC__BitWriter *bw, unsigned uval, unsigned parameter)
  83784. {
  83785. unsigned total_bits, msbs;
  83786. unsigned k;
  83787. FLAC__ASSERT(0 != bw);
  83788. FLAC__ASSERT(0 != bw->buffer);
  83789. FLAC__ASSERT(parameter > 0);
  83790. k = FLAC__bitmath_ilog2(parameter);
  83791. if(parameter == 1u<<k) {
  83792. unsigned pattern;
  83793. FLAC__ASSERT(k <= 30);
  83794. msbs = uval >> k;
  83795. total_bits = 1 + k + msbs;
  83796. pattern = 1 << k; /* the unary end bit */
  83797. pattern |= (uval & ((1u<<k)-1)); /* the binary LSBs */
  83798. if(total_bits <= 32) {
  83799. if(!FLAC__bitwriter_write_raw_uint32(bw, pattern, total_bits))
  83800. return false;
  83801. }
  83802. else {
  83803. if(!FLAC__bitwriter_write_zeroes(bw, msbs))
  83804. return false;
  83805. if(!FLAC__bitwriter_write_raw_uint32(bw, pattern, k+1))
  83806. return false;
  83807. }
  83808. }
  83809. else {
  83810. unsigned q, r, d;
  83811. d = (1 << (k+1)) - parameter;
  83812. q = uval / parameter;
  83813. r = uval - (q * parameter);
  83814. if(!FLAC__bitwriter_write_zeroes(bw, q))
  83815. return false;
  83816. if(!FLAC__bitwriter_write_raw_uint32(bw, 1, 1))
  83817. return false;
  83818. if(r >= d) {
  83819. if(!FLAC__bitwriter_write_raw_uint32(bw, r+d, k+1))
  83820. return false;
  83821. }
  83822. else {
  83823. if(!FLAC__bitwriter_write_raw_uint32(bw, r, k))
  83824. return false;
  83825. }
  83826. }
  83827. return true;
  83828. }
  83829. #endif /* UNUSED */
  83830. FLAC__bool FLAC__bitwriter_write_utf8_uint32(FLAC__BitWriter *bw, FLAC__uint32 val)
  83831. {
  83832. FLAC__bool ok = 1;
  83833. FLAC__ASSERT(0 != bw);
  83834. FLAC__ASSERT(0 != bw->buffer);
  83835. FLAC__ASSERT(!(val & 0x80000000)); /* this version only handles 31 bits */
  83836. if(val < 0x80) {
  83837. return FLAC__bitwriter_write_raw_uint32(bw, val, 8);
  83838. }
  83839. else if(val < 0x800) {
  83840. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xC0 | (val>>6), 8);
  83841. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83842. }
  83843. else if(val < 0x10000) {
  83844. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xE0 | (val>>12), 8);
  83845. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
  83846. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83847. }
  83848. else if(val < 0x200000) {
  83849. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF0 | (val>>18), 8);
  83850. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>12)&0x3F), 8);
  83851. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
  83852. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83853. }
  83854. else if(val < 0x4000000) {
  83855. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF8 | (val>>24), 8);
  83856. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>18)&0x3F), 8);
  83857. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>12)&0x3F), 8);
  83858. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
  83859. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83860. }
  83861. else {
  83862. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xFC | (val>>30), 8);
  83863. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>24)&0x3F), 8);
  83864. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>18)&0x3F), 8);
  83865. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>12)&0x3F), 8);
  83866. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
  83867. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83868. }
  83869. return ok;
  83870. }
  83871. FLAC__bool FLAC__bitwriter_write_utf8_uint64(FLAC__BitWriter *bw, FLAC__uint64 val)
  83872. {
  83873. FLAC__bool ok = 1;
  83874. FLAC__ASSERT(0 != bw);
  83875. FLAC__ASSERT(0 != bw->buffer);
  83876. FLAC__ASSERT(!(val & FLAC__U64L(0xFFFFFFF000000000))); /* this version only handles 36 bits */
  83877. if(val < 0x80) {
  83878. return FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, 8);
  83879. }
  83880. else if(val < 0x800) {
  83881. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xC0 | (FLAC__uint32)(val>>6), 8);
  83882. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83883. }
  83884. else if(val < 0x10000) {
  83885. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xE0 | (FLAC__uint32)(val>>12), 8);
  83886. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83887. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83888. }
  83889. else if(val < 0x200000) {
  83890. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF0 | (FLAC__uint32)(val>>18), 8);
  83891. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
  83892. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83893. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83894. }
  83895. else if(val < 0x4000000) {
  83896. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF8 | (FLAC__uint32)(val>>24), 8);
  83897. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>18)&0x3F), 8);
  83898. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
  83899. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83900. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83901. }
  83902. else if(val < 0x80000000) {
  83903. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xFC | (FLAC__uint32)(val>>30), 8);
  83904. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>24)&0x3F), 8);
  83905. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>18)&0x3F), 8);
  83906. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
  83907. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83908. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83909. }
  83910. else {
  83911. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xFE, 8);
  83912. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>30)&0x3F), 8);
  83913. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>24)&0x3F), 8);
  83914. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>18)&0x3F), 8);
  83915. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
  83916. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83917. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83918. }
  83919. return ok;
  83920. }
  83921. FLAC__bool FLAC__bitwriter_zero_pad_to_byte_boundary(FLAC__BitWriter *bw)
  83922. {
  83923. if(bw->bits & 7u)
  83924. return FLAC__bitwriter_write_zeroes(bw, 8 - (bw->bits & 7u));
  83925. else
  83926. return true;
  83927. }
  83928. #endif
  83929. /*** End of inlined file: bitwriter.c ***/
  83930. /*** Start of inlined file: cpu.c ***/
  83931. /*** Start of inlined file: juce_FlacHeader.h ***/
  83932. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  83933. // tasks..
  83934. #define VERSION "1.2.1"
  83935. #define FLAC__NO_DLL 1
  83936. #if JUCE_MSVC
  83937. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  83938. #endif
  83939. #if JUCE_MAC
  83940. #define FLAC__SYS_DARWIN 1
  83941. #endif
  83942. /*** End of inlined file: juce_FlacHeader.h ***/
  83943. #if JUCE_USE_FLAC
  83944. #if HAVE_CONFIG_H
  83945. # include <config.h>
  83946. #endif
  83947. #include <stdlib.h>
  83948. #include <stdio.h>
  83949. #if defined FLAC__CPU_IA32
  83950. # include <signal.h>
  83951. #elif defined FLAC__CPU_PPC
  83952. # if !defined FLAC__NO_ASM
  83953. # if defined FLAC__SYS_DARWIN
  83954. # include <sys/sysctl.h>
  83955. # include <mach/mach.h>
  83956. # include <mach/mach_host.h>
  83957. # include <mach/host_info.h>
  83958. # include <mach/machine.h>
  83959. # ifndef CPU_SUBTYPE_POWERPC_970
  83960. # define CPU_SUBTYPE_POWERPC_970 ((cpu_subtype_t) 100)
  83961. # endif
  83962. # else /* FLAC__SYS_DARWIN */
  83963. # include <signal.h>
  83964. # include <setjmp.h>
  83965. static sigjmp_buf jmpbuf;
  83966. static volatile sig_atomic_t canjump = 0;
  83967. static void sigill_handler (int sig)
  83968. {
  83969. if (!canjump) {
  83970. signal (sig, SIG_DFL);
  83971. raise (sig);
  83972. }
  83973. canjump = 0;
  83974. siglongjmp (jmpbuf, 1);
  83975. }
  83976. # endif /* FLAC__SYS_DARWIN */
  83977. # endif /* FLAC__NO_ASM */
  83978. #endif /* FLAC__CPU_PPC */
  83979. #if defined (__NetBSD__) || defined(__OpenBSD__)
  83980. #include <sys/param.h>
  83981. #include <sys/sysctl.h>
  83982. #include <machine/cpu.h>
  83983. #endif
  83984. #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
  83985. #include <sys/types.h>
  83986. #include <sys/sysctl.h>
  83987. #endif
  83988. #if defined(__APPLE__)
  83989. #endif
  83990. static const unsigned FLAC__CPUINFO_IA32_CPUID_CMOV = 0x00008000;
  83991. static const unsigned FLAC__CPUINFO_IA32_CPUID_MMX = 0x00800000;
  83992. static const unsigned FLAC__CPUINFO_IA32_CPUID_FXSR = 0x01000000;
  83993. static const unsigned FLAC__CPUINFO_IA32_CPUID_SSE = 0x02000000;
  83994. static const unsigned FLAC__CPUINFO_IA32_CPUID_SSE2 = 0x04000000;
  83995. static const unsigned FLAC__CPUINFO_IA32_CPUID_SSE3 = 0x00000001;
  83996. static const unsigned FLAC__CPUINFO_IA32_CPUID_SSSE3 = 0x00000200;
  83997. static const unsigned FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_3DNOW = 0x80000000;
  83998. static const unsigned FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_EXT3DNOW = 0x40000000;
  83999. static const unsigned FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_EXTMMX = 0x00400000;
  84000. #if defined(FLAC__CPU_IA32) && !defined FLAC__NO_ASM && defined FLAC__HAS_NASM && !defined FLAC__NO_SSE_OS && !defined FLAC__SSE_OS
  84001. # if defined(__linux__)
  84002. # undef USE_OBSOLETE_SIGCONTEXT_FLAVOR /* #define this to use the older signal handler method */
  84003. # ifdef USE_OBSOLETE_SIGCONTEXT_FLAVOR
  84004. static void sigill_handler_sse_os(int signal, struct sigcontext sc)
  84005. {
  84006. (void)signal;
  84007. sc.eip += 3 + 3 + 6;
  84008. }
  84009. # else
  84010. # include <sys/ucontext.h>
  84011. static void sigill_handler_sse_os(int signal, siginfo_t *si, void *uc)
  84012. {
  84013. (void)signal, (void)si;
  84014. ((ucontext_t*)uc)->uc_mcontext.gregs[14/*REG_EIP*/] += 3 + 3 + 6;
  84015. }
  84016. # endif
  84017. # elif defined(_MSC_VER)
  84018. # include <windows.h>
  84019. # undef USE_TRY_CATCH_FLAVOR /* #define this to use the try/catch method for catching illegal opcode exception */
  84020. # ifdef USE_TRY_CATCH_FLAVOR
  84021. # else
  84022. LONG CALLBACK sigill_handler_sse_os(EXCEPTION_POINTERS *ep)
  84023. {
  84024. if(ep->ExceptionRecord->ExceptionCode == EXCEPTION_ILLEGAL_INSTRUCTION) {
  84025. ep->ContextRecord->Eip += 3 + 3 + 6;
  84026. return EXCEPTION_CONTINUE_EXECUTION;
  84027. }
  84028. return EXCEPTION_CONTINUE_SEARCH;
  84029. }
  84030. # endif
  84031. # endif
  84032. #endif
  84033. void FLAC__cpu_info(FLAC__CPUInfo *info)
  84034. {
  84035. #ifdef FLAC__CPU_IA32
  84036. info->type = FLAC__CPUINFO_TYPE_IA32;
  84037. #if !defined FLAC__NO_ASM && defined FLAC__HAS_NASM
  84038. info->use_asm = true; /* we assume a minimum of 80386 with FLAC__CPU_IA32 */
  84039. info->data.ia32.cpuid = FLAC__cpu_have_cpuid_asm_ia32()? true : false;
  84040. info->data.ia32.bswap = info->data.ia32.cpuid; /* CPUID => BSWAP since it came after */
  84041. info->data.ia32.cmov = false;
  84042. info->data.ia32.mmx = false;
  84043. info->data.ia32.fxsr = false;
  84044. info->data.ia32.sse = false;
  84045. info->data.ia32.sse2 = false;
  84046. info->data.ia32.sse3 = false;
  84047. info->data.ia32.ssse3 = false;
  84048. info->data.ia32._3dnow = false;
  84049. info->data.ia32.ext3dnow = false;
  84050. info->data.ia32.extmmx = false;
  84051. if(info->data.ia32.cpuid) {
  84052. FLAC__uint32 flags_edx, flags_ecx;
  84053. FLAC__cpu_info_asm_ia32(&flags_edx, &flags_ecx);
  84054. info->data.ia32.cmov = (flags_edx & FLAC__CPUINFO_IA32_CPUID_CMOV )? true : false;
  84055. info->data.ia32.mmx = (flags_edx & FLAC__CPUINFO_IA32_CPUID_MMX )? true : false;
  84056. info->data.ia32.fxsr = (flags_edx & FLAC__CPUINFO_IA32_CPUID_FXSR )? true : false;
  84057. info->data.ia32.sse = (flags_edx & FLAC__CPUINFO_IA32_CPUID_SSE )? true : false;
  84058. info->data.ia32.sse2 = (flags_edx & FLAC__CPUINFO_IA32_CPUID_SSE2 )? true : false;
  84059. info->data.ia32.sse3 = (flags_ecx & FLAC__CPUINFO_IA32_CPUID_SSE3 )? true : false;
  84060. info->data.ia32.ssse3 = (flags_ecx & FLAC__CPUINFO_IA32_CPUID_SSSE3)? true : false;
  84061. #ifdef FLAC__USE_3DNOW
  84062. flags_edx = FLAC__cpu_info_extended_amd_asm_ia32();
  84063. info->data.ia32._3dnow = (flags_edx & FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_3DNOW )? true : false;
  84064. info->data.ia32.ext3dnow = (flags_edx & FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_EXT3DNOW)? true : false;
  84065. info->data.ia32.extmmx = (flags_edx & FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_EXTMMX )? true : false;
  84066. #else
  84067. info->data.ia32._3dnow = info->data.ia32.ext3dnow = info->data.ia32.extmmx = false;
  84068. #endif
  84069. #ifdef DEBUG
  84070. fprintf(stderr, "CPU info (IA-32):\n");
  84071. fprintf(stderr, " CPUID ...... %c\n", info->data.ia32.cpuid ? 'Y' : 'n');
  84072. fprintf(stderr, " BSWAP ...... %c\n", info->data.ia32.bswap ? 'Y' : 'n');
  84073. fprintf(stderr, " CMOV ....... %c\n", info->data.ia32.cmov ? 'Y' : 'n');
  84074. fprintf(stderr, " MMX ........ %c\n", info->data.ia32.mmx ? 'Y' : 'n');
  84075. fprintf(stderr, " FXSR ....... %c\n", info->data.ia32.fxsr ? 'Y' : 'n');
  84076. fprintf(stderr, " SSE ........ %c\n", info->data.ia32.sse ? 'Y' : 'n');
  84077. fprintf(stderr, " SSE2 ....... %c\n", info->data.ia32.sse2 ? 'Y' : 'n');
  84078. fprintf(stderr, " SSE3 ....... %c\n", info->data.ia32.sse3 ? 'Y' : 'n');
  84079. fprintf(stderr, " SSSE3 ...... %c\n", info->data.ia32.ssse3 ? 'Y' : 'n');
  84080. fprintf(stderr, " 3DNow! ..... %c\n", info->data.ia32._3dnow ? 'Y' : 'n');
  84081. fprintf(stderr, " 3DNow!-ext . %c\n", info->data.ia32.ext3dnow? 'Y' : 'n');
  84082. fprintf(stderr, " 3DNow!-MMX . %c\n", info->data.ia32.extmmx ? 'Y' : 'n');
  84083. #endif
  84084. if(info->data.ia32.fxsr || info->data.ia32.sse || info->data.ia32.sse2) {
  84085. #if defined FLAC__NO_SSE_OS
  84086. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  84087. #elif defined FLAC__SSE_OS
  84088. #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) || defined(__APPLE__)
  84089. int sse = 0;
  84090. size_t len;
  84091. len = sizeof(sse); sse = sse || (sysctlbyname("hw.instruction_sse", &sse, &len, NULL, 0) == 0 && sse);
  84092. len = sizeof(sse); sse = sse || (sysctlbyname("hw.optional.sse" , &sse, &len, NULL, 0) == 0 && sse); /* __APPLE__ ? */
  84093. if(!sse)
  84094. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  84095. #elif defined(__NetBSD__) || defined (__OpenBSD__)
  84096. # if __NetBSD_Version__ >= 105250000 || (defined __OpenBSD__)
  84097. int val = 0, mib[2] = { CTL_MACHDEP, CPU_SSE };
  84098. size_t len = sizeof(val);
  84099. if(sysctl(mib, 2, &val, &len, NULL, 0) < 0 || !val)
  84100. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  84101. else { /* double-check SSE2 */
  84102. mib[1] = CPU_SSE2;
  84103. len = sizeof(val);
  84104. if(sysctl(mib, 2, &val, &len, NULL, 0) < 0 || !val)
  84105. info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  84106. }
  84107. # else
  84108. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  84109. # endif
  84110. #elif defined(__linux__)
  84111. int sse = 0;
  84112. struct sigaction sigill_save;
  84113. #ifdef USE_OBSOLETE_SIGCONTEXT_FLAVOR
  84114. if(0 == sigaction(SIGILL, NULL, &sigill_save) && signal(SIGILL, (void (*)(int))sigill_handler_sse_os) != SIG_ERR)
  84115. #else
  84116. struct sigaction sigill_sse;
  84117. sigill_sse.sa_sigaction = sigill_handler_sse_os;
  84118. __sigemptyset(&sigill_sse.sa_mask);
  84119. 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 */
  84120. if(0 == sigaction(SIGILL, &sigill_sse, &sigill_save))
  84121. #endif
  84122. {
  84123. asm volatile (
  84124. "xorl %0,%0\n\t" /* for some reason, still need to do this to clear 'sse' var */
  84125. "xorps %%xmm0,%%xmm0\n\t" /* will cause SIGILL if unsupported by OS */
  84126. "incl %0\n\t" /* SIGILL handler will jump over this */
  84127. "nop\n\t" /* SIGILL jump lands here if "inc" is 9 bytes */
  84128. "nop\n\t"
  84129. "nop\n\t"
  84130. "nop\n\t"
  84131. "nop\n\t"
  84132. "nop\n\t"
  84133. "nop\n\t" /* SIGILL jump lands here if "inc" is 3 bytes (expected) */
  84134. "nop\n\t"
  84135. "nop" /* SIGILL jump lands here if "inc" is 1 byte */
  84136. : "=r"(sse)
  84137. : "r"(sse)
  84138. );
  84139. sigaction(SIGILL, &sigill_save, NULL);
  84140. }
  84141. if(!sse)
  84142. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  84143. #elif defined(_MSC_VER)
  84144. # ifdef USE_TRY_CATCH_FLAVOR
  84145. _try {
  84146. __asm {
  84147. # if _MSC_VER <= 1200
  84148. _emit 0x0F
  84149. _emit 0x57
  84150. _emit 0xC0
  84151. # else
  84152. xorps xmm0,xmm0
  84153. # endif
  84154. }
  84155. }
  84156. _except(EXCEPTION_EXECUTE_HANDLER) {
  84157. if (_exception_code() == STATUS_ILLEGAL_INSTRUCTION)
  84158. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  84159. }
  84160. # else
  84161. int sse = 0;
  84162. LPTOP_LEVEL_EXCEPTION_FILTER save = SetUnhandledExceptionFilter(sigill_handler_sse_os);
  84163. __asm {
  84164. # if _MSC_VER <= 1200
  84165. _emit 0x0F
  84166. _emit 0x57
  84167. _emit 0xC0
  84168. # else
  84169. xorps xmm0,xmm0
  84170. # endif
  84171. inc sse
  84172. nop
  84173. nop
  84174. nop
  84175. nop
  84176. nop
  84177. nop
  84178. nop
  84179. nop
  84180. nop
  84181. }
  84182. SetUnhandledExceptionFilter(save);
  84183. if(!sse)
  84184. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  84185. # endif
  84186. #else
  84187. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  84188. #endif
  84189. #ifdef DEBUG
  84190. fprintf(stderr, " SSE OS sup . %c\n", info->data.ia32.sse ? 'Y' : 'n');
  84191. #endif
  84192. }
  84193. }
  84194. #else
  84195. info->use_asm = false;
  84196. #endif
  84197. #elif defined FLAC__CPU_PPC
  84198. info->type = FLAC__CPUINFO_TYPE_PPC;
  84199. # if !defined FLAC__NO_ASM
  84200. info->use_asm = true;
  84201. # ifdef FLAC__USE_ALTIVEC
  84202. # if defined FLAC__SYS_DARWIN
  84203. {
  84204. int val = 0, mib[2] = { CTL_HW, HW_VECTORUNIT };
  84205. size_t len = sizeof(val);
  84206. info->data.ppc.altivec = !(sysctl(mib, 2, &val, &len, NULL, 0) || !val);
  84207. }
  84208. {
  84209. host_basic_info_data_t hostInfo;
  84210. mach_msg_type_number_t infoCount;
  84211. infoCount = HOST_BASIC_INFO_COUNT;
  84212. host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)&hostInfo, &infoCount);
  84213. info->data.ppc.ppc64 = (hostInfo.cpu_type == CPU_TYPE_POWERPC) && (hostInfo.cpu_subtype == CPU_SUBTYPE_POWERPC_970);
  84214. }
  84215. # else /* FLAC__USE_ALTIVEC && !FLAC__SYS_DARWIN */
  84216. {
  84217. info->data.ppc.altivec = 0;
  84218. info->data.ppc.ppc64 = 0;
  84219. signal (SIGILL, sigill_handler);
  84220. canjump = 0;
  84221. if (!sigsetjmp (jmpbuf, 1)) {
  84222. canjump = 1;
  84223. asm volatile (
  84224. "mtspr 256, %0\n\t"
  84225. "vand %%v0, %%v0, %%v0"
  84226. :
  84227. : "r" (-1)
  84228. );
  84229. info->data.ppc.altivec = 1;
  84230. }
  84231. canjump = 0;
  84232. if (!sigsetjmp (jmpbuf, 1)) {
  84233. int x = 0;
  84234. canjump = 1;
  84235. asm volatile ("cntlzd %0, %1" : "=r" (x) : "r" (x) );
  84236. info->data.ppc.ppc64 = 1;
  84237. }
  84238. signal (SIGILL, SIG_DFL); /*@@@@@@ should save and restore old signal */
  84239. }
  84240. # endif
  84241. # else /* !FLAC__USE_ALTIVEC */
  84242. info->data.ppc.altivec = 0;
  84243. info->data.ppc.ppc64 = 0;
  84244. # endif
  84245. # else
  84246. info->use_asm = false;
  84247. # endif
  84248. #else
  84249. info->type = FLAC__CPUINFO_TYPE_UNKNOWN;
  84250. info->use_asm = false;
  84251. #endif
  84252. }
  84253. #endif
  84254. /*** End of inlined file: cpu.c ***/
  84255. /*** Start of inlined file: crc.c ***/
  84256. /*** Start of inlined file: juce_FlacHeader.h ***/
  84257. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  84258. // tasks..
  84259. #define VERSION "1.2.1"
  84260. #define FLAC__NO_DLL 1
  84261. #if JUCE_MSVC
  84262. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  84263. #endif
  84264. #if JUCE_MAC
  84265. #define FLAC__SYS_DARWIN 1
  84266. #endif
  84267. /*** End of inlined file: juce_FlacHeader.h ***/
  84268. #if JUCE_USE_FLAC
  84269. #if HAVE_CONFIG_H
  84270. # include <config.h>
  84271. #endif
  84272. FLAC__byte const FLAC__crc8_table[256] = {
  84273. 0x00, 0x07, 0x0E, 0x09, 0x1C, 0x1B, 0x12, 0x15,
  84274. 0x38, 0x3F, 0x36, 0x31, 0x24, 0x23, 0x2A, 0x2D,
  84275. 0x70, 0x77, 0x7E, 0x79, 0x6C, 0x6B, 0x62, 0x65,
  84276. 0x48, 0x4F, 0x46, 0x41, 0x54, 0x53, 0x5A, 0x5D,
  84277. 0xE0, 0xE7, 0xEE, 0xE9, 0xFC, 0xFB, 0xF2, 0xF5,
  84278. 0xD8, 0xDF, 0xD6, 0xD1, 0xC4, 0xC3, 0xCA, 0xCD,
  84279. 0x90, 0x97, 0x9E, 0x99, 0x8C, 0x8B, 0x82, 0x85,
  84280. 0xA8, 0xAF, 0xA6, 0xA1, 0xB4, 0xB3, 0xBA, 0xBD,
  84281. 0xC7, 0xC0, 0xC9, 0xCE, 0xDB, 0xDC, 0xD5, 0xD2,
  84282. 0xFF, 0xF8, 0xF1, 0xF6, 0xE3, 0xE4, 0xED, 0xEA,
  84283. 0xB7, 0xB0, 0xB9, 0xBE, 0xAB, 0xAC, 0xA5, 0xA2,
  84284. 0x8F, 0x88, 0x81, 0x86, 0x93, 0x94, 0x9D, 0x9A,
  84285. 0x27, 0x20, 0x29, 0x2E, 0x3B, 0x3C, 0x35, 0x32,
  84286. 0x1F, 0x18, 0x11, 0x16, 0x03, 0x04, 0x0D, 0x0A,
  84287. 0x57, 0x50, 0x59, 0x5E, 0x4B, 0x4C, 0x45, 0x42,
  84288. 0x6F, 0x68, 0x61, 0x66, 0x73, 0x74, 0x7D, 0x7A,
  84289. 0x89, 0x8E, 0x87, 0x80, 0x95, 0x92, 0x9B, 0x9C,
  84290. 0xB1, 0xB6, 0xBF, 0xB8, 0xAD, 0xAA, 0xA3, 0xA4,
  84291. 0xF9, 0xFE, 0xF7, 0xF0, 0xE5, 0xE2, 0xEB, 0xEC,
  84292. 0xC1, 0xC6, 0xCF, 0xC8, 0xDD, 0xDA, 0xD3, 0xD4,
  84293. 0x69, 0x6E, 0x67, 0x60, 0x75, 0x72, 0x7B, 0x7C,
  84294. 0x51, 0x56, 0x5F, 0x58, 0x4D, 0x4A, 0x43, 0x44,
  84295. 0x19, 0x1E, 0x17, 0x10, 0x05, 0x02, 0x0B, 0x0C,
  84296. 0x21, 0x26, 0x2F, 0x28, 0x3D, 0x3A, 0x33, 0x34,
  84297. 0x4E, 0x49, 0x40, 0x47, 0x52, 0x55, 0x5C, 0x5B,
  84298. 0x76, 0x71, 0x78, 0x7F, 0x6A, 0x6D, 0x64, 0x63,
  84299. 0x3E, 0x39, 0x30, 0x37, 0x22, 0x25, 0x2C, 0x2B,
  84300. 0x06, 0x01, 0x08, 0x0F, 0x1A, 0x1D, 0x14, 0x13,
  84301. 0xAE, 0xA9, 0xA0, 0xA7, 0xB2, 0xB5, 0xBC, 0xBB,
  84302. 0x96, 0x91, 0x98, 0x9F, 0x8A, 0x8D, 0x84, 0x83,
  84303. 0xDE, 0xD9, 0xD0, 0xD7, 0xC2, 0xC5, 0xCC, 0xCB,
  84304. 0xE6, 0xE1, 0xE8, 0xEF, 0xFA, 0xFD, 0xF4, 0xF3
  84305. };
  84306. unsigned FLAC__crc16_table[256] = {
  84307. 0x0000, 0x8005, 0x800f, 0x000a, 0x801b, 0x001e, 0x0014, 0x8011,
  84308. 0x8033, 0x0036, 0x003c, 0x8039, 0x0028, 0x802d, 0x8027, 0x0022,
  84309. 0x8063, 0x0066, 0x006c, 0x8069, 0x0078, 0x807d, 0x8077, 0x0072,
  84310. 0x0050, 0x8055, 0x805f, 0x005a, 0x804b, 0x004e, 0x0044, 0x8041,
  84311. 0x80c3, 0x00c6, 0x00cc, 0x80c9, 0x00d8, 0x80dd, 0x80d7, 0x00d2,
  84312. 0x00f0, 0x80f5, 0x80ff, 0x00fa, 0x80eb, 0x00ee, 0x00e4, 0x80e1,
  84313. 0x00a0, 0x80a5, 0x80af, 0x00aa, 0x80bb, 0x00be, 0x00b4, 0x80b1,
  84314. 0x8093, 0x0096, 0x009c, 0x8099, 0x0088, 0x808d, 0x8087, 0x0082,
  84315. 0x8183, 0x0186, 0x018c, 0x8189, 0x0198, 0x819d, 0x8197, 0x0192,
  84316. 0x01b0, 0x81b5, 0x81bf, 0x01ba, 0x81ab, 0x01ae, 0x01a4, 0x81a1,
  84317. 0x01e0, 0x81e5, 0x81ef, 0x01ea, 0x81fb, 0x01fe, 0x01f4, 0x81f1,
  84318. 0x81d3, 0x01d6, 0x01dc, 0x81d9, 0x01c8, 0x81cd, 0x81c7, 0x01c2,
  84319. 0x0140, 0x8145, 0x814f, 0x014a, 0x815b, 0x015e, 0x0154, 0x8151,
  84320. 0x8173, 0x0176, 0x017c, 0x8179, 0x0168, 0x816d, 0x8167, 0x0162,
  84321. 0x8123, 0x0126, 0x012c, 0x8129, 0x0138, 0x813d, 0x8137, 0x0132,
  84322. 0x0110, 0x8115, 0x811f, 0x011a, 0x810b, 0x010e, 0x0104, 0x8101,
  84323. 0x8303, 0x0306, 0x030c, 0x8309, 0x0318, 0x831d, 0x8317, 0x0312,
  84324. 0x0330, 0x8335, 0x833f, 0x033a, 0x832b, 0x032e, 0x0324, 0x8321,
  84325. 0x0360, 0x8365, 0x836f, 0x036a, 0x837b, 0x037e, 0x0374, 0x8371,
  84326. 0x8353, 0x0356, 0x035c, 0x8359, 0x0348, 0x834d, 0x8347, 0x0342,
  84327. 0x03c0, 0x83c5, 0x83cf, 0x03ca, 0x83db, 0x03de, 0x03d4, 0x83d1,
  84328. 0x83f3, 0x03f6, 0x03fc, 0x83f9, 0x03e8, 0x83ed, 0x83e7, 0x03e2,
  84329. 0x83a3, 0x03a6, 0x03ac, 0x83a9, 0x03b8, 0x83bd, 0x83b7, 0x03b2,
  84330. 0x0390, 0x8395, 0x839f, 0x039a, 0x838b, 0x038e, 0x0384, 0x8381,
  84331. 0x0280, 0x8285, 0x828f, 0x028a, 0x829b, 0x029e, 0x0294, 0x8291,
  84332. 0x82b3, 0x02b6, 0x02bc, 0x82b9, 0x02a8, 0x82ad, 0x82a7, 0x02a2,
  84333. 0x82e3, 0x02e6, 0x02ec, 0x82e9, 0x02f8, 0x82fd, 0x82f7, 0x02f2,
  84334. 0x02d0, 0x82d5, 0x82df, 0x02da, 0x82cb, 0x02ce, 0x02c4, 0x82c1,
  84335. 0x8243, 0x0246, 0x024c, 0x8249, 0x0258, 0x825d, 0x8257, 0x0252,
  84336. 0x0270, 0x8275, 0x827f, 0x027a, 0x826b, 0x026e, 0x0264, 0x8261,
  84337. 0x0220, 0x8225, 0x822f, 0x022a, 0x823b, 0x023e, 0x0234, 0x8231,
  84338. 0x8213, 0x0216, 0x021c, 0x8219, 0x0208, 0x820d, 0x8207, 0x0202
  84339. };
  84340. void FLAC__crc8_update(const FLAC__byte data, FLAC__uint8 *crc)
  84341. {
  84342. *crc = FLAC__crc8_table[*crc ^ data];
  84343. }
  84344. void FLAC__crc8_update_block(const FLAC__byte *data, unsigned len, FLAC__uint8 *crc)
  84345. {
  84346. while(len--)
  84347. *crc = FLAC__crc8_table[*crc ^ *data++];
  84348. }
  84349. FLAC__uint8 FLAC__crc8(const FLAC__byte *data, unsigned len)
  84350. {
  84351. FLAC__uint8 crc = 0;
  84352. while(len--)
  84353. crc = FLAC__crc8_table[crc ^ *data++];
  84354. return crc;
  84355. }
  84356. unsigned FLAC__crc16(const FLAC__byte *data, unsigned len)
  84357. {
  84358. unsigned crc = 0;
  84359. while(len--)
  84360. crc = ((crc<<8) ^ FLAC__crc16_table[(crc>>8) ^ *data++]) & 0xffff;
  84361. return crc;
  84362. }
  84363. #endif
  84364. /*** End of inlined file: crc.c ***/
  84365. /*** Start of inlined file: fixed.c ***/
  84366. /*** Start of inlined file: juce_FlacHeader.h ***/
  84367. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  84368. // tasks..
  84369. #define VERSION "1.2.1"
  84370. #define FLAC__NO_DLL 1
  84371. #if JUCE_MSVC
  84372. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  84373. #endif
  84374. #if JUCE_MAC
  84375. #define FLAC__SYS_DARWIN 1
  84376. #endif
  84377. /*** End of inlined file: juce_FlacHeader.h ***/
  84378. #if JUCE_USE_FLAC
  84379. #if HAVE_CONFIG_H
  84380. # include <config.h>
  84381. #endif
  84382. #include <math.h>
  84383. #include <string.h>
  84384. /*** Start of inlined file: fixed.h ***/
  84385. #ifndef FLAC__PRIVATE__FIXED_H
  84386. #define FLAC__PRIVATE__FIXED_H
  84387. #ifdef HAVE_CONFIG_H
  84388. #include <config.h>
  84389. #endif
  84390. /*** Start of inlined file: float.h ***/
  84391. #ifndef FLAC__PRIVATE__FLOAT_H
  84392. #define FLAC__PRIVATE__FLOAT_H
  84393. #ifdef HAVE_CONFIG_H
  84394. #include <config.h>
  84395. #endif
  84396. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84397. typedef double FLAC__double;
  84398. typedef float FLAC__float;
  84399. typedef float FLAC__real;
  84400. #else
  84401. typedef FLAC__int32 FLAC__fixedpoint;
  84402. extern const FLAC__fixedpoint FLAC__FP_ZERO;
  84403. extern const FLAC__fixedpoint FLAC__FP_ONE_HALF;
  84404. extern const FLAC__fixedpoint FLAC__FP_ONE;
  84405. extern const FLAC__fixedpoint FLAC__FP_LN2;
  84406. extern const FLAC__fixedpoint FLAC__FP_E;
  84407. #define FLAC__fixedpoint_trunc(x) ((x)>>16)
  84408. #define FLAC__fixedpoint_mul(x, y) ( (FLAC__fixedpoint) ( ((FLAC__int64)(x)*(FLAC__int64)(y)) >> 16 ) )
  84409. #define FLAC__fixedpoint_div(x, y) ( (FLAC__fixedpoint) ( ( ((FLAC__int64)(x)<<32) / (FLAC__int64)(y) ) >> 16 ) )
  84410. FLAC__uint32 FLAC__fixedpoint_log2(FLAC__uint32 x, unsigned fracbits, unsigned precision);
  84411. #endif
  84412. #endif
  84413. /*** End of inlined file: float.h ***/
  84414. /*** Start of inlined file: format.h ***/
  84415. #ifndef FLAC__PRIVATE__FORMAT_H
  84416. #define FLAC__PRIVATE__FORMAT_H
  84417. unsigned FLAC__format_get_max_rice_partition_order(unsigned blocksize, unsigned predictor_order);
  84418. unsigned FLAC__format_get_max_rice_partition_order_from_blocksize(unsigned blocksize);
  84419. unsigned FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(unsigned limit, unsigned blocksize, unsigned predictor_order);
  84420. void FLAC__format_entropy_coding_method_partitioned_rice_contents_init(FLAC__EntropyCodingMethod_PartitionedRiceContents *object);
  84421. void FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(FLAC__EntropyCodingMethod_PartitionedRiceContents *object);
  84422. FLAC__bool FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(FLAC__EntropyCodingMethod_PartitionedRiceContents *object, unsigned max_partition_order);
  84423. #endif
  84424. /*** End of inlined file: format.h ***/
  84425. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84426. unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  84427. # ifndef FLAC__NO_ASM
  84428. # ifdef FLAC__CPU_IA32
  84429. # ifdef FLAC__HAS_NASM
  84430. 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]);
  84431. # endif
  84432. # endif
  84433. # endif
  84434. 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]);
  84435. #else
  84436. unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  84437. 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]);
  84438. #endif
  84439. void FLAC__fixed_compute_residual(const FLAC__int32 data[], unsigned data_len, unsigned order, FLAC__int32 residual[]);
  84440. void FLAC__fixed_restore_signal(const FLAC__int32 residual[], unsigned data_len, unsigned order, FLAC__int32 data[]);
  84441. #endif
  84442. /*** End of inlined file: fixed.h ***/
  84443. #ifndef M_LN2
  84444. #define M_LN2 0.69314718055994530942
  84445. #endif
  84446. #ifdef min
  84447. #undef min
  84448. #endif
  84449. #define min(x,y) ((x) < (y)? (x) : (y))
  84450. #ifdef local_abs
  84451. #undef local_abs
  84452. #endif
  84453. #define local_abs(x) ((unsigned)((x)<0? -(x) : (x)))
  84454. #ifdef FLAC__INTEGER_ONLY_LIBRARY
  84455. static FLAC__fixedpoint local__compute_rbps_integerized(FLAC__uint32 err, FLAC__uint32 n)
  84456. {
  84457. FLAC__uint32 rbps;
  84458. unsigned bits; /* the number of bits required to represent a number */
  84459. int fracbits; /* the number of bits of rbps that comprise the fractional part */
  84460. FLAC__ASSERT(sizeof(rbps) == sizeof(FLAC__fixedpoint));
  84461. FLAC__ASSERT(err > 0);
  84462. FLAC__ASSERT(n > 0);
  84463. FLAC__ASSERT(n <= FLAC__MAX_BLOCK_SIZE);
  84464. if(err <= n)
  84465. return 0;
  84466. fracbits = (8*sizeof(err)) - (FLAC__bitmath_ilog2(err)+1);
  84467. err <<= fracbits;
  84468. err /= n;
  84469. FLAC__ASSERT(err > 0);
  84470. bits = FLAC__bitmath_ilog2(err)+1;
  84471. if(bits > 16) {
  84472. err >>= (bits-16);
  84473. fracbits -= (bits-16);
  84474. }
  84475. rbps = (FLAC__uint32)err;
  84476. rbps *= FLAC__FP_LN2;
  84477. fracbits += 16;
  84478. FLAC__ASSERT(fracbits >= 0);
  84479. {
  84480. const int f = fracbits & 3;
  84481. if(f) {
  84482. rbps >>= f;
  84483. fracbits -= f;
  84484. }
  84485. }
  84486. rbps = FLAC__fixedpoint_log2(rbps, fracbits, (unsigned)(-1));
  84487. if(rbps == 0)
  84488. return 0;
  84489. FLAC__ASSERT((int)FLAC__bitmath_ilog2(rbps)+1 <= fracbits + 6);
  84490. FLAC__ASSERT(fracbits >= -3);
  84491. if(fracbits < 16)
  84492. return rbps << (16-fracbits);
  84493. else if(fracbits > 16)
  84494. return rbps >> (fracbits-16);
  84495. else
  84496. return rbps;
  84497. }
  84498. static FLAC__fixedpoint local__compute_rbps_wide_integerized(FLAC__uint64 err, FLAC__uint32 n)
  84499. {
  84500. FLAC__uint32 rbps;
  84501. unsigned bits; /* the number of bits required to represent a number */
  84502. int fracbits; /* the number of bits of rbps that comprise the fractional part */
  84503. FLAC__ASSERT(sizeof(rbps) == sizeof(FLAC__fixedpoint));
  84504. FLAC__ASSERT(err > 0);
  84505. FLAC__ASSERT(n > 0);
  84506. FLAC__ASSERT(n <= FLAC__MAX_BLOCK_SIZE);
  84507. if(err <= n)
  84508. return 0;
  84509. fracbits = (8*sizeof(err)) - (FLAC__bitmath_ilog2_wide(err)+1);
  84510. err <<= fracbits;
  84511. err /= n;
  84512. FLAC__ASSERT(err > 0);
  84513. bits = FLAC__bitmath_ilog2_wide(err)+1;
  84514. if(bits > 16) {
  84515. err >>= (bits-16);
  84516. fracbits -= (bits-16);
  84517. }
  84518. rbps = (FLAC__uint32)err;
  84519. rbps *= FLAC__FP_LN2;
  84520. fracbits += 16;
  84521. FLAC__ASSERT(fracbits >= 0);
  84522. {
  84523. const int f = fracbits & 3;
  84524. if(f) {
  84525. rbps >>= f;
  84526. fracbits -= f;
  84527. }
  84528. }
  84529. rbps = FLAC__fixedpoint_log2(rbps, fracbits, (unsigned)(-1));
  84530. if(rbps == 0)
  84531. return 0;
  84532. FLAC__ASSERT((int)FLAC__bitmath_ilog2(rbps)+1 <= fracbits + 6);
  84533. FLAC__ASSERT(fracbits >= -3);
  84534. if(fracbits < 16)
  84535. return rbps << (16-fracbits);
  84536. else if(fracbits > 16)
  84537. return rbps >> (fracbits-16);
  84538. else
  84539. return rbps;
  84540. }
  84541. #endif
  84542. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84543. unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1])
  84544. #else
  84545. unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1])
  84546. #endif
  84547. {
  84548. FLAC__int32 last_error_0 = data[-1];
  84549. FLAC__int32 last_error_1 = data[-1] - data[-2];
  84550. FLAC__int32 last_error_2 = last_error_1 - (data[-2] - data[-3]);
  84551. FLAC__int32 last_error_3 = last_error_2 - (data[-2] - 2*data[-3] + data[-4]);
  84552. FLAC__int32 error, save;
  84553. FLAC__uint32 total_error_0 = 0, total_error_1 = 0, total_error_2 = 0, total_error_3 = 0, total_error_4 = 0;
  84554. unsigned i, order;
  84555. for(i = 0; i < data_len; i++) {
  84556. error = data[i] ; total_error_0 += local_abs(error); save = error;
  84557. error -= last_error_0; total_error_1 += local_abs(error); last_error_0 = save; save = error;
  84558. error -= last_error_1; total_error_2 += local_abs(error); last_error_1 = save; save = error;
  84559. error -= last_error_2; total_error_3 += local_abs(error); last_error_2 = save; save = error;
  84560. error -= last_error_3; total_error_4 += local_abs(error); last_error_3 = save;
  84561. }
  84562. if(total_error_0 < min(min(min(total_error_1, total_error_2), total_error_3), total_error_4))
  84563. order = 0;
  84564. else if(total_error_1 < min(min(total_error_2, total_error_3), total_error_4))
  84565. order = 1;
  84566. else if(total_error_2 < min(total_error_3, total_error_4))
  84567. order = 2;
  84568. else if(total_error_3 < total_error_4)
  84569. order = 3;
  84570. else
  84571. order = 4;
  84572. FLAC__ASSERT(data_len > 0 || total_error_0 == 0);
  84573. FLAC__ASSERT(data_len > 0 || total_error_1 == 0);
  84574. FLAC__ASSERT(data_len > 0 || total_error_2 == 0);
  84575. FLAC__ASSERT(data_len > 0 || total_error_3 == 0);
  84576. FLAC__ASSERT(data_len > 0 || total_error_4 == 0);
  84577. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84578. 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);
  84579. 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);
  84580. 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);
  84581. 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);
  84582. 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);
  84583. #else
  84584. residual_bits_per_sample[0] = (total_error_0 > 0) ? local__compute_rbps_integerized(total_error_0, data_len) : 0;
  84585. residual_bits_per_sample[1] = (total_error_1 > 0) ? local__compute_rbps_integerized(total_error_1, data_len) : 0;
  84586. residual_bits_per_sample[2] = (total_error_2 > 0) ? local__compute_rbps_integerized(total_error_2, data_len) : 0;
  84587. residual_bits_per_sample[3] = (total_error_3 > 0) ? local__compute_rbps_integerized(total_error_3, data_len) : 0;
  84588. residual_bits_per_sample[4] = (total_error_4 > 0) ? local__compute_rbps_integerized(total_error_4, data_len) : 0;
  84589. #endif
  84590. return order;
  84591. }
  84592. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84593. 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])
  84594. #else
  84595. 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])
  84596. #endif
  84597. {
  84598. FLAC__int32 last_error_0 = data[-1];
  84599. FLAC__int32 last_error_1 = data[-1] - data[-2];
  84600. FLAC__int32 last_error_2 = last_error_1 - (data[-2] - data[-3]);
  84601. FLAC__int32 last_error_3 = last_error_2 - (data[-2] - 2*data[-3] + data[-4]);
  84602. FLAC__int32 error, save;
  84603. FLAC__uint64 total_error_0 = 0, total_error_1 = 0, total_error_2 = 0, total_error_3 = 0, total_error_4 = 0;
  84604. unsigned i, order;
  84605. for(i = 0; i < data_len; i++) {
  84606. error = data[i] ; total_error_0 += local_abs(error); save = error;
  84607. error -= last_error_0; total_error_1 += local_abs(error); last_error_0 = save; save = error;
  84608. error -= last_error_1; total_error_2 += local_abs(error); last_error_1 = save; save = error;
  84609. error -= last_error_2; total_error_3 += local_abs(error); last_error_2 = save; save = error;
  84610. error -= last_error_3; total_error_4 += local_abs(error); last_error_3 = save;
  84611. }
  84612. if(total_error_0 < min(min(min(total_error_1, total_error_2), total_error_3), total_error_4))
  84613. order = 0;
  84614. else if(total_error_1 < min(min(total_error_2, total_error_3), total_error_4))
  84615. order = 1;
  84616. else if(total_error_2 < min(total_error_3, total_error_4))
  84617. order = 2;
  84618. else if(total_error_3 < total_error_4)
  84619. order = 3;
  84620. else
  84621. order = 4;
  84622. FLAC__ASSERT(data_len > 0 || total_error_0 == 0);
  84623. FLAC__ASSERT(data_len > 0 || total_error_1 == 0);
  84624. FLAC__ASSERT(data_len > 0 || total_error_2 == 0);
  84625. FLAC__ASSERT(data_len > 0 || total_error_3 == 0);
  84626. FLAC__ASSERT(data_len > 0 || total_error_4 == 0);
  84627. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84628. #if defined _MSC_VER || defined __MINGW32__
  84629. 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);
  84630. 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);
  84631. 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);
  84632. 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);
  84633. 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);
  84634. #else
  84635. 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);
  84636. 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);
  84637. 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);
  84638. 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);
  84639. 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);
  84640. #endif
  84641. #else
  84642. residual_bits_per_sample[0] = (total_error_0 > 0) ? local__compute_rbps_wide_integerized(total_error_0, data_len) : 0;
  84643. residual_bits_per_sample[1] = (total_error_1 > 0) ? local__compute_rbps_wide_integerized(total_error_1, data_len) : 0;
  84644. residual_bits_per_sample[2] = (total_error_2 > 0) ? local__compute_rbps_wide_integerized(total_error_2, data_len) : 0;
  84645. residual_bits_per_sample[3] = (total_error_3 > 0) ? local__compute_rbps_wide_integerized(total_error_3, data_len) : 0;
  84646. residual_bits_per_sample[4] = (total_error_4 > 0) ? local__compute_rbps_wide_integerized(total_error_4, data_len) : 0;
  84647. #endif
  84648. return order;
  84649. }
  84650. void FLAC__fixed_compute_residual(const FLAC__int32 data[], unsigned data_len, unsigned order, FLAC__int32 residual[])
  84651. {
  84652. const int idata_len = (int)data_len;
  84653. int i;
  84654. switch(order) {
  84655. case 0:
  84656. FLAC__ASSERT(sizeof(residual[0]) == sizeof(data[0]));
  84657. memcpy(residual, data, sizeof(residual[0])*data_len);
  84658. break;
  84659. case 1:
  84660. for(i = 0; i < idata_len; i++)
  84661. residual[i] = data[i] - data[i-1];
  84662. break;
  84663. case 2:
  84664. for(i = 0; i < idata_len; i++)
  84665. #if 1 /* OPT: may be faster with some compilers on some systems */
  84666. residual[i] = data[i] - (data[i-1] << 1) + data[i-2];
  84667. #else
  84668. residual[i] = data[i] - 2*data[i-1] + data[i-2];
  84669. #endif
  84670. break;
  84671. case 3:
  84672. for(i = 0; i < idata_len; i++)
  84673. #if 1 /* OPT: may be faster with some compilers on some systems */
  84674. residual[i] = data[i] - (((data[i-1]-data[i-2])<<1) + (data[i-1]-data[i-2])) - data[i-3];
  84675. #else
  84676. residual[i] = data[i] - 3*data[i-1] + 3*data[i-2] - data[i-3];
  84677. #endif
  84678. break;
  84679. case 4:
  84680. for(i = 0; i < idata_len; i++)
  84681. #if 1 /* OPT: may be faster with some compilers on some systems */
  84682. residual[i] = data[i] - ((data[i-1]+data[i-3])<<2) + ((data[i-2]<<2) + (data[i-2]<<1)) + data[i-4];
  84683. #else
  84684. residual[i] = data[i] - 4*data[i-1] + 6*data[i-2] - 4*data[i-3] + data[i-4];
  84685. #endif
  84686. break;
  84687. default:
  84688. FLAC__ASSERT(0);
  84689. }
  84690. }
  84691. void FLAC__fixed_restore_signal(const FLAC__int32 residual[], unsigned data_len, unsigned order, FLAC__int32 data[])
  84692. {
  84693. int i, idata_len = (int)data_len;
  84694. switch(order) {
  84695. case 0:
  84696. FLAC__ASSERT(sizeof(residual[0]) == sizeof(data[0]));
  84697. memcpy(data, residual, sizeof(residual[0])*data_len);
  84698. break;
  84699. case 1:
  84700. for(i = 0; i < idata_len; i++)
  84701. data[i] = residual[i] + data[i-1];
  84702. break;
  84703. case 2:
  84704. for(i = 0; i < idata_len; i++)
  84705. #if 1 /* OPT: may be faster with some compilers on some systems */
  84706. data[i] = residual[i] + (data[i-1]<<1) - data[i-2];
  84707. #else
  84708. data[i] = residual[i] + 2*data[i-1] - data[i-2];
  84709. #endif
  84710. break;
  84711. case 3:
  84712. for(i = 0; i < idata_len; i++)
  84713. #if 1 /* OPT: may be faster with some compilers on some systems */
  84714. data[i] = residual[i] + (((data[i-1]-data[i-2])<<1) + (data[i-1]-data[i-2])) + data[i-3];
  84715. #else
  84716. data[i] = residual[i] + 3*data[i-1] - 3*data[i-2] + data[i-3];
  84717. #endif
  84718. break;
  84719. case 4:
  84720. for(i = 0; i < idata_len; i++)
  84721. #if 1 /* OPT: may be faster with some compilers on some systems */
  84722. data[i] = residual[i] + ((data[i-1]+data[i-3])<<2) - ((data[i-2]<<2) + (data[i-2]<<1)) - data[i-4];
  84723. #else
  84724. data[i] = residual[i] + 4*data[i-1] - 6*data[i-2] + 4*data[i-3] - data[i-4];
  84725. #endif
  84726. break;
  84727. default:
  84728. FLAC__ASSERT(0);
  84729. }
  84730. }
  84731. #endif
  84732. /*** End of inlined file: fixed.c ***/
  84733. /*** Start of inlined file: float.c ***/
  84734. /*** Start of inlined file: juce_FlacHeader.h ***/
  84735. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  84736. // tasks..
  84737. #define VERSION "1.2.1"
  84738. #define FLAC__NO_DLL 1
  84739. #if JUCE_MSVC
  84740. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  84741. #endif
  84742. #if JUCE_MAC
  84743. #define FLAC__SYS_DARWIN 1
  84744. #endif
  84745. /*** End of inlined file: juce_FlacHeader.h ***/
  84746. #if JUCE_USE_FLAC
  84747. #if HAVE_CONFIG_H
  84748. # include <config.h>
  84749. #endif
  84750. #ifdef FLAC__INTEGER_ONLY_LIBRARY
  84751. #ifdef _MSC_VER
  84752. #define FLAC__U64L(x) x
  84753. #else
  84754. #define FLAC__U64L(x) x##LLU
  84755. #endif
  84756. const FLAC__fixedpoint FLAC__FP_ZERO = 0;
  84757. const FLAC__fixedpoint FLAC__FP_ONE_HALF = 0x00008000;
  84758. const FLAC__fixedpoint FLAC__FP_ONE = 0x00010000;
  84759. const FLAC__fixedpoint FLAC__FP_LN2 = 45426;
  84760. const FLAC__fixedpoint FLAC__FP_E = 178145;
  84761. #define LOG2_LOOKUP_PRECISION 16
  84762. static const FLAC__uint32 log2_lookup[][LOG2_LOOKUP_PRECISION] = {
  84763. {
  84764. 0x00000000,
  84765. 0x00000001,
  84766. 0x00000000,
  84767. 0x00000000,
  84768. 0x00000000,
  84769. 0x00000000,
  84770. 0x00000000,
  84771. 0x00000000,
  84772. 0x00000000,
  84773. 0x00000000,
  84774. 0x00000000,
  84775. 0x00000000,
  84776. 0x00000000,
  84777. 0x00000000,
  84778. 0x00000000,
  84779. 0x00000000
  84780. },
  84781. {
  84782. 0x00000000,
  84783. 0x00000010,
  84784. 0x00000007,
  84785. 0x00000003,
  84786. 0x00000001,
  84787. 0x00000001,
  84788. 0x00000000,
  84789. 0x00000000,
  84790. 0x00000000,
  84791. 0x00000000,
  84792. 0x00000000,
  84793. 0x00000000,
  84794. 0x00000000,
  84795. 0x00000000,
  84796. 0x00000000,
  84797. 0x00000000
  84798. },
  84799. {
  84800. 0x00000000,
  84801. 0x00000100,
  84802. 0x0000006a,
  84803. 0x00000031,
  84804. 0x00000018,
  84805. 0x0000000c,
  84806. 0x00000006,
  84807. 0x00000003,
  84808. 0x00000001,
  84809. 0x00000001,
  84810. 0x00000000,
  84811. 0x00000000,
  84812. 0x00000000,
  84813. 0x00000000,
  84814. 0x00000000,
  84815. 0x00000000
  84816. },
  84817. {
  84818. 0x00000000,
  84819. 0x00001000,
  84820. 0x000006a4,
  84821. 0x00000315,
  84822. 0x0000017d,
  84823. 0x000000bc,
  84824. 0x0000005d,
  84825. 0x0000002e,
  84826. 0x00000017,
  84827. 0x0000000c,
  84828. 0x00000006,
  84829. 0x00000003,
  84830. 0x00000001,
  84831. 0x00000001,
  84832. 0x00000000,
  84833. 0x00000000
  84834. },
  84835. {
  84836. 0x00000000,
  84837. 0x00010000,
  84838. 0x00006a40,
  84839. 0x00003151,
  84840. 0x000017d6,
  84841. 0x00000bba,
  84842. 0x000005d1,
  84843. 0x000002e6,
  84844. 0x00000172,
  84845. 0x000000b9,
  84846. 0x0000005c,
  84847. 0x0000002e,
  84848. 0x00000017,
  84849. 0x0000000c,
  84850. 0x00000006,
  84851. 0x00000003
  84852. },
  84853. {
  84854. 0x00000000,
  84855. 0x00100000,
  84856. 0x0006a3fe,
  84857. 0x00031513,
  84858. 0x00017d60,
  84859. 0x0000bb9d,
  84860. 0x00005d10,
  84861. 0x00002e59,
  84862. 0x00001721,
  84863. 0x00000b8e,
  84864. 0x000005c6,
  84865. 0x000002e3,
  84866. 0x00000171,
  84867. 0x000000b9,
  84868. 0x0000005c,
  84869. 0x0000002e
  84870. },
  84871. {
  84872. 0x00000000,
  84873. 0x01000000,
  84874. 0x006a3fe6,
  84875. 0x00315130,
  84876. 0x0017d605,
  84877. 0x000bb9ca,
  84878. 0x0005d0fc,
  84879. 0x0002e58f,
  84880. 0x0001720e,
  84881. 0x0000b8d8,
  84882. 0x00005c61,
  84883. 0x00002e2d,
  84884. 0x00001716,
  84885. 0x00000b8b,
  84886. 0x000005c5,
  84887. 0x000002e3
  84888. },
  84889. {
  84890. 0x00000000,
  84891. 0x10000000,
  84892. 0x06a3fe5c,
  84893. 0x03151301,
  84894. 0x017d6049,
  84895. 0x00bb9ca6,
  84896. 0x005d0fba,
  84897. 0x002e58f7,
  84898. 0x001720da,
  84899. 0x000b8d87,
  84900. 0x0005c60b,
  84901. 0x0002e2d7,
  84902. 0x00017160,
  84903. 0x0000b8ad,
  84904. 0x00005c56,
  84905. 0x00002e2b
  84906. }
  84907. };
  84908. #if 0
  84909. static const FLAC__uint64 log2_lookup_wide[] = {
  84910. {
  84911. 0x00000000,
  84912. FLAC__U64L(0x100000000),
  84913. FLAC__U64L(0x6a3fe5c6),
  84914. FLAC__U64L(0x31513015),
  84915. FLAC__U64L(0x17d60497),
  84916. FLAC__U64L(0x0bb9ca65),
  84917. FLAC__U64L(0x05d0fba2),
  84918. FLAC__U64L(0x02e58f74),
  84919. FLAC__U64L(0x01720d9c),
  84920. FLAC__U64L(0x00b8d875),
  84921. FLAC__U64L(0x005c60aa),
  84922. FLAC__U64L(0x002e2d72),
  84923. FLAC__U64L(0x00171600),
  84924. FLAC__U64L(0x000b8ad2),
  84925. FLAC__U64L(0x0005c55d),
  84926. FLAC__U64L(0x0002e2ac)
  84927. },
  84928. {
  84929. 0x00000000,
  84930. FLAC__U64L(0x1000000000000),
  84931. FLAC__U64L(0x6a3fe5c60429),
  84932. FLAC__U64L(0x315130157f7a),
  84933. FLAC__U64L(0x17d60496cfbb),
  84934. FLAC__U64L(0xbb9ca64ecac),
  84935. FLAC__U64L(0x5d0fba187cd),
  84936. FLAC__U64L(0x2e58f7441ee),
  84937. FLAC__U64L(0x1720d9c06a8),
  84938. FLAC__U64L(0xb8d8752173),
  84939. FLAC__U64L(0x5c60aa252e),
  84940. FLAC__U64L(0x2e2d71b0d8),
  84941. FLAC__U64L(0x1716001719),
  84942. FLAC__U64L(0xb8ad1de1b),
  84943. FLAC__U64L(0x5c55d640d),
  84944. FLAC__U64L(0x2e2abcf52)
  84945. }
  84946. };
  84947. #endif
  84948. FLAC__uint32 FLAC__fixedpoint_log2(FLAC__uint32 x, unsigned fracbits, unsigned precision)
  84949. {
  84950. const FLAC__uint32 ONE = (1u << fracbits);
  84951. const FLAC__uint32 *table = log2_lookup[fracbits >> 2];
  84952. FLAC__ASSERT(fracbits < 32);
  84953. FLAC__ASSERT((fracbits & 0x3) == 0);
  84954. if(x < ONE)
  84955. return 0;
  84956. if(precision > LOG2_LOOKUP_PRECISION)
  84957. precision = LOG2_LOOKUP_PRECISION;
  84958. {
  84959. FLAC__uint32 y = 0;
  84960. FLAC__uint32 z = x >> 1, k = 1;
  84961. while (x > ONE && k < precision) {
  84962. if (x - z >= ONE) {
  84963. x -= z;
  84964. z = x >> k;
  84965. y += table[k];
  84966. }
  84967. else {
  84968. z >>= 1;
  84969. k++;
  84970. }
  84971. }
  84972. return y;
  84973. }
  84974. }
  84975. #endif /* defined FLAC__INTEGER_ONLY_LIBRARY */
  84976. #endif
  84977. /*** End of inlined file: float.c ***/
  84978. /*** Start of inlined file: format.c ***/
  84979. /*** Start of inlined file: juce_FlacHeader.h ***/
  84980. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  84981. // tasks..
  84982. #define VERSION "1.2.1"
  84983. #define FLAC__NO_DLL 1
  84984. #if JUCE_MSVC
  84985. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  84986. #endif
  84987. #if JUCE_MAC
  84988. #define FLAC__SYS_DARWIN 1
  84989. #endif
  84990. /*** End of inlined file: juce_FlacHeader.h ***/
  84991. #if JUCE_USE_FLAC
  84992. #if HAVE_CONFIG_H
  84993. # include <config.h>
  84994. #endif
  84995. #include <stdio.h>
  84996. #include <stdlib.h> /* for qsort() */
  84997. #include <string.h> /* for memset() */
  84998. #ifndef FLaC__INLINE
  84999. #define FLaC__INLINE
  85000. #endif
  85001. #ifdef min
  85002. #undef min
  85003. #endif
  85004. #define min(a,b) ((a)<(b)?(a):(b))
  85005. #ifdef _MSC_VER
  85006. #define FLAC__U64L(x) x
  85007. #else
  85008. #define FLAC__U64L(x) x##LLU
  85009. #endif
  85010. FLAC_API const char *FLAC__VERSION_STRING = VERSION
  85011. ;
  85012. #if defined _MSC_VER || defined __BORLANDC__ || defined __MINW32__
  85013. FLAC_API const char *FLAC__VENDOR_STRING = "reference libFLAC 1.2.1 20070917";
  85014. #else
  85015. FLAC_API const char *FLAC__VENDOR_STRING = "reference libFLAC " VERSION " 20070917";
  85016. #endif
  85017. FLAC_API const FLAC__byte FLAC__STREAM_SYNC_STRING[4] = { 'f','L','a','C' };
  85018. FLAC_API const unsigned FLAC__STREAM_SYNC = 0x664C6143;
  85019. FLAC_API const unsigned FLAC__STREAM_SYNC_LEN = 32; /* bits */
  85020. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN = 16; /* bits */
  85021. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN = 16; /* bits */
  85022. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN = 24; /* bits */
  85023. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN = 24; /* bits */
  85024. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN = 20; /* bits */
  85025. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN = 3; /* bits */
  85026. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN = 5; /* bits */
  85027. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN = 36; /* bits */
  85028. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MD5SUM_LEN = 128; /* bits */
  85029. FLAC_API const unsigned FLAC__STREAM_METADATA_APPLICATION_ID_LEN = 32; /* bits */
  85030. FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN = 64; /* bits */
  85031. FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN = 64; /* bits */
  85032. FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN = 16; /* bits */
  85033. FLAC_API const FLAC__uint64 FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER = FLAC__U64L(0xffffffffffffffff);
  85034. FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN = 32; /* bits */
  85035. FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN = 32; /* bits */
  85036. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN = 64; /* bits */
  85037. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN = 8; /* bits */
  85038. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN = 3*8; /* bits */
  85039. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN = 64; /* bits */
  85040. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN = 8; /* bits */
  85041. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN = 12*8; /* bits */
  85042. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN = 1; /* bit */
  85043. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN = 1; /* bit */
  85044. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN = 6+13*8; /* bits */
  85045. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN = 8; /* bits */
  85046. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN = 128*8; /* bits */
  85047. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN = 64; /* bits */
  85048. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN = 1; /* bit */
  85049. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN = 7+258*8; /* bits */
  85050. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN = 8; /* bits */
  85051. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_TYPE_LEN = 32; /* bits */
  85052. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN = 32; /* bits */
  85053. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN = 32; /* bits */
  85054. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN = 32; /* bits */
  85055. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN = 32; /* bits */
  85056. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN = 32; /* bits */
  85057. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_COLORS_LEN = 32; /* bits */
  85058. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN = 32; /* bits */
  85059. FLAC_API const unsigned FLAC__STREAM_METADATA_IS_LAST_LEN = 1; /* bits */
  85060. FLAC_API const unsigned FLAC__STREAM_METADATA_TYPE_LEN = 7; /* bits */
  85061. FLAC_API const unsigned FLAC__STREAM_METADATA_LENGTH_LEN = 24; /* bits */
  85062. FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC = 0x3ffe;
  85063. FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC_LEN = 14; /* bits */
  85064. FLAC_API const unsigned FLAC__FRAME_HEADER_RESERVED_LEN = 1; /* bits */
  85065. FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCKING_STRATEGY_LEN = 1; /* bits */
  85066. FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCK_SIZE_LEN = 4; /* bits */
  85067. FLAC_API const unsigned FLAC__FRAME_HEADER_SAMPLE_RATE_LEN = 4; /* bits */
  85068. FLAC_API const unsigned FLAC__FRAME_HEADER_CHANNEL_ASSIGNMENT_LEN = 4; /* bits */
  85069. FLAC_API const unsigned FLAC__FRAME_HEADER_BITS_PER_SAMPLE_LEN = 3; /* bits */
  85070. FLAC_API const unsigned FLAC__FRAME_HEADER_ZERO_PAD_LEN = 1; /* bits */
  85071. FLAC_API const unsigned FLAC__FRAME_HEADER_CRC_LEN = 8; /* bits */
  85072. FLAC_API const unsigned FLAC__FRAME_FOOTER_CRC_LEN = 16; /* bits */
  85073. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_TYPE_LEN = 2; /* bits */
  85074. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN = 4; /* bits */
  85075. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN = 4; /* bits */
  85076. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN = 5; /* bits */
  85077. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN = 5; /* bits */
  85078. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER = 15; /* == (1<<FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN)-1 */
  85079. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER = 31; /* == (1<<FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN)-1 */
  85080. FLAC_API const char * const FLAC__EntropyCodingMethodTypeString[] = {
  85081. "PARTITIONED_RICE",
  85082. "PARTITIONED_RICE2"
  85083. };
  85084. FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN = 4; /* bits */
  85085. FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN = 5; /* bits */
  85086. FLAC_API const unsigned FLAC__SUBFRAME_ZERO_PAD_LEN = 1; /* bits */
  85087. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LEN = 6; /* bits */
  85088. FLAC_API const unsigned FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN = 1; /* bits */
  85089. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_CONSTANT_BYTE_ALIGNED_MASK = 0x00;
  85090. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_VERBATIM_BYTE_ALIGNED_MASK = 0x02;
  85091. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_FIXED_BYTE_ALIGNED_MASK = 0x10;
  85092. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LPC_BYTE_ALIGNED_MASK = 0x40;
  85093. FLAC_API const char * const FLAC__SubframeTypeString[] = {
  85094. "CONSTANT",
  85095. "VERBATIM",
  85096. "FIXED",
  85097. "LPC"
  85098. };
  85099. FLAC_API const char * const FLAC__ChannelAssignmentString[] = {
  85100. "INDEPENDENT",
  85101. "LEFT_SIDE",
  85102. "RIGHT_SIDE",
  85103. "MID_SIDE"
  85104. };
  85105. FLAC_API const char * const FLAC__FrameNumberTypeString[] = {
  85106. "FRAME_NUMBER_TYPE_FRAME_NUMBER",
  85107. "FRAME_NUMBER_TYPE_SAMPLE_NUMBER"
  85108. };
  85109. FLAC_API const char * const FLAC__MetadataTypeString[] = {
  85110. "STREAMINFO",
  85111. "PADDING",
  85112. "APPLICATION",
  85113. "SEEKTABLE",
  85114. "VORBIS_COMMENT",
  85115. "CUESHEET",
  85116. "PICTURE"
  85117. };
  85118. FLAC_API const char * const FLAC__StreamMetadata_Picture_TypeString[] = {
  85119. "Other",
  85120. "32x32 pixels 'file icon' (PNG only)",
  85121. "Other file icon",
  85122. "Cover (front)",
  85123. "Cover (back)",
  85124. "Leaflet page",
  85125. "Media (e.g. label side of CD)",
  85126. "Lead artist/lead performer/soloist",
  85127. "Artist/performer",
  85128. "Conductor",
  85129. "Band/Orchestra",
  85130. "Composer",
  85131. "Lyricist/text writer",
  85132. "Recording Location",
  85133. "During recording",
  85134. "During performance",
  85135. "Movie/video screen capture",
  85136. "A bright coloured fish",
  85137. "Illustration",
  85138. "Band/artist logotype",
  85139. "Publisher/Studio logotype"
  85140. };
  85141. FLAC_API FLAC__bool FLAC__format_sample_rate_is_valid(unsigned sample_rate)
  85142. {
  85143. if(sample_rate == 0 || sample_rate > FLAC__MAX_SAMPLE_RATE) {
  85144. return false;
  85145. }
  85146. else
  85147. return true;
  85148. }
  85149. FLAC_API FLAC__bool FLAC__format_sample_rate_is_subset(unsigned sample_rate)
  85150. {
  85151. if(
  85152. !FLAC__format_sample_rate_is_valid(sample_rate) ||
  85153. (
  85154. sample_rate >= (1u << 16) &&
  85155. !(sample_rate % 1000 == 0 || sample_rate % 10 == 0)
  85156. )
  85157. ) {
  85158. return false;
  85159. }
  85160. else
  85161. return true;
  85162. }
  85163. FLAC_API FLAC__bool FLAC__format_seektable_is_legal(const FLAC__StreamMetadata_SeekTable *seek_table)
  85164. {
  85165. unsigned i;
  85166. FLAC__uint64 prev_sample_number = 0;
  85167. FLAC__bool got_prev = false;
  85168. FLAC__ASSERT(0 != seek_table);
  85169. for(i = 0; i < seek_table->num_points; i++) {
  85170. if(got_prev) {
  85171. if(
  85172. seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER &&
  85173. seek_table->points[i].sample_number <= prev_sample_number
  85174. )
  85175. return false;
  85176. }
  85177. prev_sample_number = seek_table->points[i].sample_number;
  85178. got_prev = true;
  85179. }
  85180. return true;
  85181. }
  85182. static int seekpoint_compare_(const FLAC__StreamMetadata_SeekPoint *l, const FLAC__StreamMetadata_SeekPoint *r)
  85183. {
  85184. if(l->sample_number == r->sample_number)
  85185. return 0;
  85186. else if(l->sample_number < r->sample_number)
  85187. return -1;
  85188. else
  85189. return 1;
  85190. }
  85191. FLAC_API unsigned FLAC__format_seektable_sort(FLAC__StreamMetadata_SeekTable *seek_table)
  85192. {
  85193. unsigned i, j;
  85194. FLAC__bool first;
  85195. FLAC__ASSERT(0 != seek_table);
  85196. qsort(seek_table->points, seek_table->num_points, sizeof(FLAC__StreamMetadata_SeekPoint), (int (*)(const void *, const void *))seekpoint_compare_);
  85197. first = true;
  85198. for(i = j = 0; i < seek_table->num_points; i++) {
  85199. if(seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER) {
  85200. if(!first) {
  85201. if(seek_table->points[i].sample_number == seek_table->points[j-1].sample_number)
  85202. continue;
  85203. }
  85204. }
  85205. first = false;
  85206. seek_table->points[j++] = seek_table->points[i];
  85207. }
  85208. for(i = j; i < seek_table->num_points; i++) {
  85209. seek_table->points[i].sample_number = FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
  85210. seek_table->points[i].stream_offset = 0;
  85211. seek_table->points[i].frame_samples = 0;
  85212. }
  85213. return j;
  85214. }
  85215. static FLaC__INLINE unsigned utf8len_(const FLAC__byte *utf8)
  85216. {
  85217. FLAC__ASSERT(0 != utf8);
  85218. if ((utf8[0] & 0x80) == 0) {
  85219. return 1;
  85220. }
  85221. else if ((utf8[0] & 0xE0) == 0xC0 && (utf8[1] & 0xC0) == 0x80) {
  85222. if ((utf8[0] & 0xFE) == 0xC0) /* overlong sequence check */
  85223. return 0;
  85224. return 2;
  85225. }
  85226. else if ((utf8[0] & 0xF0) == 0xE0 && (utf8[1] & 0xC0) == 0x80 && (utf8[2] & 0xC0) == 0x80) {
  85227. if (utf8[0] == 0xE0 && (utf8[1] & 0xE0) == 0x80) /* overlong sequence check */
  85228. return 0;
  85229. if (utf8[0] == 0xED && (utf8[1] & 0xE0) == 0xA0) /* D800-DFFF */
  85230. return 0;
  85231. if (utf8[0] == 0xEF && utf8[1] == 0xBF && (utf8[2] & 0xFE) == 0xBE) /* FFFE-FFFF */
  85232. return 0;
  85233. return 3;
  85234. }
  85235. else if ((utf8[0] & 0xF8) == 0xF0 && (utf8[1] & 0xC0) == 0x80 && (utf8[2] & 0xC0) == 0x80 && (utf8[3] & 0xC0) == 0x80) {
  85236. if (utf8[0] == 0xF0 && (utf8[1] & 0xF0) == 0x80) /* overlong sequence check */
  85237. return 0;
  85238. return 4;
  85239. }
  85240. else if ((utf8[0] & 0xFC) == 0xF8 && (utf8[1] & 0xC0) == 0x80 && (utf8[2] & 0xC0) == 0x80 && (utf8[3] & 0xC0) == 0x80 && (utf8[4] & 0xC0) == 0x80) {
  85241. if (utf8[0] == 0xF8 && (utf8[1] & 0xF8) == 0x80) /* overlong sequence check */
  85242. return 0;
  85243. return 5;
  85244. }
  85245. 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) {
  85246. if (utf8[0] == 0xFC && (utf8[1] & 0xFC) == 0x80) /* overlong sequence check */
  85247. return 0;
  85248. return 6;
  85249. }
  85250. else {
  85251. return 0;
  85252. }
  85253. }
  85254. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_name_is_legal(const char *name)
  85255. {
  85256. char c;
  85257. for(c = *name; c; c = *(++name))
  85258. if(c < 0x20 || c == 0x3d || c > 0x7d)
  85259. return false;
  85260. return true;
  85261. }
  85262. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_value_is_legal(const FLAC__byte *value, unsigned length)
  85263. {
  85264. if(length == (unsigned)(-1)) {
  85265. while(*value) {
  85266. unsigned n = utf8len_(value);
  85267. if(n == 0)
  85268. return false;
  85269. value += n;
  85270. }
  85271. }
  85272. else {
  85273. const FLAC__byte *end = value + length;
  85274. while(value < end) {
  85275. unsigned n = utf8len_(value);
  85276. if(n == 0)
  85277. return false;
  85278. value += n;
  85279. }
  85280. if(value != end)
  85281. return false;
  85282. }
  85283. return true;
  85284. }
  85285. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_is_legal(const FLAC__byte *entry, unsigned length)
  85286. {
  85287. const FLAC__byte *s, *end;
  85288. for(s = entry, end = s + length; s < end && *s != '='; s++) {
  85289. if(*s < 0x20 || *s > 0x7D)
  85290. return false;
  85291. }
  85292. if(s == end)
  85293. return false;
  85294. s++; /* skip '=' */
  85295. while(s < end) {
  85296. unsigned n = utf8len_(s);
  85297. if(n == 0)
  85298. return false;
  85299. s += n;
  85300. }
  85301. if(s != end)
  85302. return false;
  85303. return true;
  85304. }
  85305. FLAC_API FLAC__bool FLAC__format_cuesheet_is_legal(const FLAC__StreamMetadata_CueSheet *cue_sheet, FLAC__bool check_cd_da_subset, const char **violation)
  85306. {
  85307. unsigned i, j;
  85308. if(check_cd_da_subset) {
  85309. if(cue_sheet->lead_in < 2 * 44100) {
  85310. if(violation) *violation = "CD-DA cue sheet must have a lead-in length of at least 2 seconds";
  85311. return false;
  85312. }
  85313. if(cue_sheet->lead_in % 588 != 0) {
  85314. if(violation) *violation = "CD-DA cue sheet lead-in length must be evenly divisible by 588 samples";
  85315. return false;
  85316. }
  85317. }
  85318. if(cue_sheet->num_tracks == 0) {
  85319. if(violation) *violation = "cue sheet must have at least one track (the lead-out)";
  85320. return false;
  85321. }
  85322. if(check_cd_da_subset && cue_sheet->tracks[cue_sheet->num_tracks-1].number != 170) {
  85323. if(violation) *violation = "CD-DA cue sheet must have a lead-out track number 170 (0xAA)";
  85324. return false;
  85325. }
  85326. for(i = 0; i < cue_sheet->num_tracks; i++) {
  85327. if(cue_sheet->tracks[i].number == 0) {
  85328. if(violation) *violation = "cue sheet may not have a track number 0";
  85329. return false;
  85330. }
  85331. if(check_cd_da_subset) {
  85332. if(!((cue_sheet->tracks[i].number >= 1 && cue_sheet->tracks[i].number <= 99) || cue_sheet->tracks[i].number == 170)) {
  85333. if(violation) *violation = "CD-DA cue sheet track number must be 1-99 or 170";
  85334. return false;
  85335. }
  85336. }
  85337. if(check_cd_da_subset && cue_sheet->tracks[i].offset % 588 != 0) {
  85338. if(violation) {
  85339. if(i == cue_sheet->num_tracks-1) /* the lead-out track... */
  85340. *violation = "CD-DA cue sheet lead-out offset must be evenly divisible by 588 samples";
  85341. else
  85342. *violation = "CD-DA cue sheet track offset must be evenly divisible by 588 samples";
  85343. }
  85344. return false;
  85345. }
  85346. if(i < cue_sheet->num_tracks - 1) {
  85347. if(cue_sheet->tracks[i].num_indices == 0) {
  85348. if(violation) *violation = "cue sheet track must have at least one index point";
  85349. return false;
  85350. }
  85351. if(cue_sheet->tracks[i].indices[0].number > 1) {
  85352. if(violation) *violation = "cue sheet track's first index number must be 0 or 1";
  85353. return false;
  85354. }
  85355. }
  85356. for(j = 0; j < cue_sheet->tracks[i].num_indices; j++) {
  85357. if(check_cd_da_subset && cue_sheet->tracks[i].indices[j].offset % 588 != 0) {
  85358. if(violation) *violation = "CD-DA cue sheet track index offset must be evenly divisible by 588 samples";
  85359. return false;
  85360. }
  85361. if(j > 0) {
  85362. if(cue_sheet->tracks[i].indices[j].number != cue_sheet->tracks[i].indices[j-1].number + 1) {
  85363. if(violation) *violation = "cue sheet track index numbers must increase by 1";
  85364. return false;
  85365. }
  85366. }
  85367. }
  85368. }
  85369. return true;
  85370. }
  85371. FLAC_API FLAC__bool FLAC__format_picture_is_legal(const FLAC__StreamMetadata_Picture *picture, const char **violation)
  85372. {
  85373. char *p;
  85374. FLAC__byte *b;
  85375. for(p = picture->mime_type; *p; p++) {
  85376. if(*p < 0x20 || *p > 0x7e) {
  85377. if(violation) *violation = "MIME type string must contain only printable ASCII characters (0x20-0x7e)";
  85378. return false;
  85379. }
  85380. }
  85381. for(b = picture->description; *b; ) {
  85382. unsigned n = utf8len_(b);
  85383. if(n == 0) {
  85384. if(violation) *violation = "description string must be valid UTF-8";
  85385. return false;
  85386. }
  85387. b += n;
  85388. }
  85389. return true;
  85390. }
  85391. unsigned FLAC__format_get_max_rice_partition_order(unsigned blocksize, unsigned predictor_order)
  85392. {
  85393. return
  85394. FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(
  85395. FLAC__format_get_max_rice_partition_order_from_blocksize(blocksize),
  85396. blocksize,
  85397. predictor_order
  85398. );
  85399. }
  85400. unsigned FLAC__format_get_max_rice_partition_order_from_blocksize(unsigned blocksize)
  85401. {
  85402. unsigned max_rice_partition_order = 0;
  85403. while(!(blocksize & 1)) {
  85404. max_rice_partition_order++;
  85405. blocksize >>= 1;
  85406. }
  85407. return min(FLAC__MAX_RICE_PARTITION_ORDER, max_rice_partition_order);
  85408. }
  85409. unsigned FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(unsigned limit, unsigned blocksize, unsigned predictor_order)
  85410. {
  85411. unsigned max_rice_partition_order = limit;
  85412. while(max_rice_partition_order > 0 && (blocksize >> max_rice_partition_order) <= predictor_order)
  85413. max_rice_partition_order--;
  85414. FLAC__ASSERT(
  85415. (max_rice_partition_order == 0 && blocksize >= predictor_order) ||
  85416. (max_rice_partition_order > 0 && blocksize >> max_rice_partition_order > predictor_order)
  85417. );
  85418. return max_rice_partition_order;
  85419. }
  85420. void FLAC__format_entropy_coding_method_partitioned_rice_contents_init(FLAC__EntropyCodingMethod_PartitionedRiceContents *object)
  85421. {
  85422. FLAC__ASSERT(0 != object);
  85423. object->parameters = 0;
  85424. object->raw_bits = 0;
  85425. object->capacity_by_order = 0;
  85426. }
  85427. void FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(FLAC__EntropyCodingMethod_PartitionedRiceContents *object)
  85428. {
  85429. FLAC__ASSERT(0 != object);
  85430. if(0 != object->parameters)
  85431. free(object->parameters);
  85432. if(0 != object->raw_bits)
  85433. free(object->raw_bits);
  85434. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(object);
  85435. }
  85436. FLAC__bool FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(FLAC__EntropyCodingMethod_PartitionedRiceContents *object, unsigned max_partition_order)
  85437. {
  85438. FLAC__ASSERT(0 != object);
  85439. FLAC__ASSERT(object->capacity_by_order > 0 || (0 == object->parameters && 0 == object->raw_bits));
  85440. if(object->capacity_by_order < max_partition_order) {
  85441. if(0 == (object->parameters = (unsigned*)realloc(object->parameters, sizeof(unsigned)*(1 << max_partition_order))))
  85442. return false;
  85443. if(0 == (object->raw_bits = (unsigned*)realloc(object->raw_bits, sizeof(unsigned)*(1 << max_partition_order))))
  85444. return false;
  85445. memset(object->raw_bits, 0, sizeof(unsigned)*(1 << max_partition_order));
  85446. object->capacity_by_order = max_partition_order;
  85447. }
  85448. return true;
  85449. }
  85450. #endif
  85451. /*** End of inlined file: format.c ***/
  85452. /*** Start of inlined file: lpc_flac.c ***/
  85453. /*** Start of inlined file: juce_FlacHeader.h ***/
  85454. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  85455. // tasks..
  85456. #define VERSION "1.2.1"
  85457. #define FLAC__NO_DLL 1
  85458. #if JUCE_MSVC
  85459. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  85460. #endif
  85461. #if JUCE_MAC
  85462. #define FLAC__SYS_DARWIN 1
  85463. #endif
  85464. /*** End of inlined file: juce_FlacHeader.h ***/
  85465. #if JUCE_USE_FLAC
  85466. #if HAVE_CONFIG_H
  85467. # include <config.h>
  85468. #endif
  85469. #include <math.h>
  85470. /*** Start of inlined file: lpc.h ***/
  85471. #ifndef FLAC__PRIVATE__LPC_H
  85472. #define FLAC__PRIVATE__LPC_H
  85473. #ifdef HAVE_CONFIG_H
  85474. #include <config.h>
  85475. #endif
  85476. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  85477. void FLAC__lpc_window_data(const FLAC__int32 in[], const FLAC__real window[], FLAC__real out[], unsigned data_len);
  85478. void FLAC__lpc_compute_autocorrelation(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  85479. #ifndef FLAC__NO_ASM
  85480. # ifdef FLAC__CPU_IA32
  85481. # ifdef FLAC__HAS_NASM
  85482. void FLAC__lpc_compute_autocorrelation_asm_ia32(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  85483. void FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_4(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  85484. void FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_8(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  85485. void FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_12(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  85486. void FLAC__lpc_compute_autocorrelation_asm_ia32_3dnow(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  85487. # endif
  85488. # endif
  85489. #endif
  85490. void FLAC__lpc_compute_lp_coefficients(const FLAC__real autoc[], unsigned *max_order, FLAC__real lp_coeff[][FLAC__MAX_LPC_ORDER], FLAC__double error[]);
  85491. int FLAC__lpc_quantize_coefficients(const FLAC__real lp_coeff[], unsigned order, unsigned precision, FLAC__int32 qlp_coeff[], int *shift);
  85492. 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[]);
  85493. 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[]);
  85494. #ifndef FLAC__NO_ASM
  85495. # ifdef FLAC__CPU_IA32
  85496. # ifdef FLAC__HAS_NASM
  85497. 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[]);
  85498. 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[]);
  85499. # endif
  85500. # endif
  85501. #endif
  85502. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  85503. 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[]);
  85504. 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[]);
  85505. #ifndef FLAC__NO_ASM
  85506. # ifdef FLAC__CPU_IA32
  85507. # ifdef FLAC__HAS_NASM
  85508. 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[]);
  85509. 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[]);
  85510. # endif /* FLAC__HAS_NASM */
  85511. # elif defined FLAC__CPU_PPC
  85512. 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[]);
  85513. 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[]);
  85514. # endif/* FLAC__CPU_IA32 || FLAC__CPU_PPC */
  85515. #endif /* FLAC__NO_ASM */
  85516. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  85517. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample(FLAC__double lpc_error, unsigned total_samples);
  85518. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale(FLAC__double lpc_error, FLAC__double error_scale);
  85519. unsigned FLAC__lpc_compute_best_order(const FLAC__double lpc_error[], unsigned max_order, unsigned total_samples, unsigned overhead_bits_per_order);
  85520. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  85521. #endif
  85522. /*** End of inlined file: lpc.h ***/
  85523. #if defined DEBUG || defined FLAC__OVERFLOW_DETECT || defined FLAC__OVERFLOW_DETECT_VERBOSE
  85524. #include <stdio.h>
  85525. #endif
  85526. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  85527. #ifndef M_LN2
  85528. #define M_LN2 0.69314718055994530942
  85529. #endif
  85530. #define FLAC__LPC_UNROLLED_FILTER_LOOPS
  85531. void FLAC__lpc_window_data(const FLAC__int32 in[], const FLAC__real window[], FLAC__real out[], unsigned data_len)
  85532. {
  85533. unsigned i;
  85534. for(i = 0; i < data_len; i++)
  85535. out[i] = in[i] * window[i];
  85536. }
  85537. void FLAC__lpc_compute_autocorrelation(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[])
  85538. {
  85539. #if 0
  85540. FLAC__real d;
  85541. unsigned i;
  85542. FLAC__ASSERT(lag > 0);
  85543. FLAC__ASSERT(lag <= data_len);
  85544. while(lag--) {
  85545. for(i = lag, d = 0.0; i < data_len; i++)
  85546. d += data[i] * data[i - lag];
  85547. autoc[lag] = d;
  85548. }
  85549. #endif
  85550. FLAC__real d;
  85551. unsigned sample, coeff;
  85552. const unsigned limit = data_len - lag;
  85553. FLAC__ASSERT(lag > 0);
  85554. FLAC__ASSERT(lag <= data_len);
  85555. for(coeff = 0; coeff < lag; coeff++)
  85556. autoc[coeff] = 0.0;
  85557. for(sample = 0; sample <= limit; sample++) {
  85558. d = data[sample];
  85559. for(coeff = 0; coeff < lag; coeff++)
  85560. autoc[coeff] += d * data[sample+coeff];
  85561. }
  85562. for(; sample < data_len; sample++) {
  85563. d = data[sample];
  85564. for(coeff = 0; coeff < data_len - sample; coeff++)
  85565. autoc[coeff] += d * data[sample+coeff];
  85566. }
  85567. }
  85568. void FLAC__lpc_compute_lp_coefficients(const FLAC__real autoc[], unsigned *max_order, FLAC__real lp_coeff[][FLAC__MAX_LPC_ORDER], FLAC__double error[])
  85569. {
  85570. unsigned i, j;
  85571. FLAC__double r, err, ref[FLAC__MAX_LPC_ORDER], lpc[FLAC__MAX_LPC_ORDER];
  85572. FLAC__ASSERT(0 != max_order);
  85573. FLAC__ASSERT(0 < *max_order);
  85574. FLAC__ASSERT(*max_order <= FLAC__MAX_LPC_ORDER);
  85575. FLAC__ASSERT(autoc[0] != 0.0);
  85576. err = autoc[0];
  85577. for(i = 0; i < *max_order; i++) {
  85578. r = -autoc[i+1];
  85579. for(j = 0; j < i; j++)
  85580. r -= lpc[j] * autoc[i-j];
  85581. ref[i] = (r/=err);
  85582. lpc[i]=r;
  85583. for(j = 0; j < (i>>1); j++) {
  85584. FLAC__double tmp = lpc[j];
  85585. lpc[j] += r * lpc[i-1-j];
  85586. lpc[i-1-j] += r * tmp;
  85587. }
  85588. if(i & 1)
  85589. lpc[j] += lpc[j] * r;
  85590. err *= (1.0 - r * r);
  85591. for(j = 0; j <= i; j++)
  85592. lp_coeff[i][j] = (FLAC__real)(-lpc[j]); /* negate FIR filter coeff to get predictor coeff */
  85593. error[i] = err;
  85594. if(err == 0.0) {
  85595. *max_order = i+1;
  85596. return;
  85597. }
  85598. }
  85599. }
  85600. int FLAC__lpc_quantize_coefficients(const FLAC__real lp_coeff[], unsigned order, unsigned precision, FLAC__int32 qlp_coeff[], int *shift)
  85601. {
  85602. unsigned i;
  85603. FLAC__double cmax;
  85604. FLAC__int32 qmax, qmin;
  85605. FLAC__ASSERT(precision > 0);
  85606. FLAC__ASSERT(precision >= FLAC__MIN_QLP_COEFF_PRECISION);
  85607. precision--;
  85608. qmax = 1 << precision;
  85609. qmin = -qmax;
  85610. qmax--;
  85611. cmax = 0.0;
  85612. for(i = 0; i < order; i++) {
  85613. const FLAC__double d = fabs(lp_coeff[i]);
  85614. if(d > cmax)
  85615. cmax = d;
  85616. }
  85617. if(cmax <= 0.0) {
  85618. return 2;
  85619. }
  85620. else {
  85621. const int max_shiftlimit = (1 << (FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN-1)) - 1;
  85622. const int min_shiftlimit = -max_shiftlimit - 1;
  85623. int log2cmax;
  85624. (void)frexp(cmax, &log2cmax);
  85625. log2cmax--;
  85626. *shift = (int)precision - log2cmax - 1;
  85627. if(*shift > max_shiftlimit)
  85628. *shift = max_shiftlimit;
  85629. else if(*shift < min_shiftlimit)
  85630. return 1;
  85631. }
  85632. if(*shift >= 0) {
  85633. FLAC__double error = 0.0;
  85634. FLAC__int32 q;
  85635. for(i = 0; i < order; i++) {
  85636. error += lp_coeff[i] * (1 << *shift);
  85637. #if 1 /* unfortunately lround() is C99 */
  85638. if(error >= 0.0)
  85639. q = (FLAC__int32)(error + 0.5);
  85640. else
  85641. q = (FLAC__int32)(error - 0.5);
  85642. #else
  85643. q = lround(error);
  85644. #endif
  85645. #ifdef FLAC__OVERFLOW_DETECT
  85646. if(q > qmax+1) /* we expect q==qmax+1 occasionally due to rounding */
  85647. 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]);
  85648. else if(q < qmin)
  85649. 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]);
  85650. #endif
  85651. if(q > qmax)
  85652. q = qmax;
  85653. else if(q < qmin)
  85654. q = qmin;
  85655. error -= q;
  85656. qlp_coeff[i] = q;
  85657. }
  85658. }
  85659. else {
  85660. const int nshift = -(*shift);
  85661. FLAC__double error = 0.0;
  85662. FLAC__int32 q;
  85663. #ifdef DEBUG
  85664. fprintf(stderr,"FLAC__lpc_quantize_coefficients: negative shift=%d order=%u cmax=%f\n", *shift, order, cmax);
  85665. #endif
  85666. for(i = 0; i < order; i++) {
  85667. error += lp_coeff[i] / (1 << nshift);
  85668. #if 1 /* unfortunately lround() is C99 */
  85669. if(error >= 0.0)
  85670. q = (FLAC__int32)(error + 0.5);
  85671. else
  85672. q = (FLAC__int32)(error - 0.5);
  85673. #else
  85674. q = lround(error);
  85675. #endif
  85676. #ifdef FLAC__OVERFLOW_DETECT
  85677. if(q > qmax+1) /* we expect q==qmax+1 occasionally due to rounding */
  85678. 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]);
  85679. else if(q < qmin)
  85680. 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]);
  85681. #endif
  85682. if(q > qmax)
  85683. q = qmax;
  85684. else if(q < qmin)
  85685. q = qmin;
  85686. error -= q;
  85687. qlp_coeff[i] = q;
  85688. }
  85689. *shift = 0;
  85690. }
  85691. return 0;
  85692. }
  85693. 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[])
  85694. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  85695. {
  85696. FLAC__int64 sumo;
  85697. unsigned i, j;
  85698. FLAC__int32 sum;
  85699. const FLAC__int32 *history;
  85700. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  85701. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  85702. for(i=0;i<order;i++)
  85703. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  85704. fprintf(stderr,"\n");
  85705. #endif
  85706. FLAC__ASSERT(order > 0);
  85707. for(i = 0; i < data_len; i++) {
  85708. sumo = 0;
  85709. sum = 0;
  85710. history = data;
  85711. for(j = 0; j < order; j++) {
  85712. sum += qlp_coeff[j] * (*(--history));
  85713. sumo += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*history);
  85714. #if defined _MSC_VER
  85715. if(sumo > 2147483647I64 || sumo < -2147483648I64)
  85716. 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);
  85717. #else
  85718. if(sumo > 2147483647ll || sumo < -2147483648ll)
  85719. 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);
  85720. #endif
  85721. }
  85722. *(residual++) = *(data++) - (sum >> lp_quantization);
  85723. }
  85724. }
  85725. #else /* fully unrolled version for normal use */
  85726. {
  85727. int i;
  85728. FLAC__int32 sum;
  85729. FLAC__ASSERT(order > 0);
  85730. FLAC__ASSERT(order <= 32);
  85731. if(order <= 12) {
  85732. if(order > 8) {
  85733. if(order > 10) {
  85734. if(order == 12) {
  85735. for(i = 0; i < (int)data_len; i++) {
  85736. sum = 0;
  85737. sum += qlp_coeff[11] * data[i-12];
  85738. sum += qlp_coeff[10] * data[i-11];
  85739. sum += qlp_coeff[9] * data[i-10];
  85740. sum += qlp_coeff[8] * data[i-9];
  85741. sum += qlp_coeff[7] * data[i-8];
  85742. sum += qlp_coeff[6] * data[i-7];
  85743. sum += qlp_coeff[5] * data[i-6];
  85744. sum += qlp_coeff[4] * data[i-5];
  85745. sum += qlp_coeff[3] * data[i-4];
  85746. sum += qlp_coeff[2] * data[i-3];
  85747. sum += qlp_coeff[1] * data[i-2];
  85748. sum += qlp_coeff[0] * data[i-1];
  85749. residual[i] = data[i] - (sum >> lp_quantization);
  85750. }
  85751. }
  85752. else { /* order == 11 */
  85753. for(i = 0; i < (int)data_len; i++) {
  85754. sum = 0;
  85755. sum += qlp_coeff[10] * data[i-11];
  85756. sum += qlp_coeff[9] * data[i-10];
  85757. sum += qlp_coeff[8] * data[i-9];
  85758. sum += qlp_coeff[7] * data[i-8];
  85759. sum += qlp_coeff[6] * data[i-7];
  85760. sum += qlp_coeff[5] * data[i-6];
  85761. sum += qlp_coeff[4] * data[i-5];
  85762. sum += qlp_coeff[3] * data[i-4];
  85763. sum += qlp_coeff[2] * data[i-3];
  85764. sum += qlp_coeff[1] * data[i-2];
  85765. sum += qlp_coeff[0] * data[i-1];
  85766. residual[i] = data[i] - (sum >> lp_quantization);
  85767. }
  85768. }
  85769. }
  85770. else {
  85771. if(order == 10) {
  85772. for(i = 0; i < (int)data_len; i++) {
  85773. sum = 0;
  85774. sum += qlp_coeff[9] * data[i-10];
  85775. sum += qlp_coeff[8] * data[i-9];
  85776. sum += qlp_coeff[7] * data[i-8];
  85777. sum += qlp_coeff[6] * data[i-7];
  85778. sum += qlp_coeff[5] * data[i-6];
  85779. sum += qlp_coeff[4] * data[i-5];
  85780. sum += qlp_coeff[3] * data[i-4];
  85781. sum += qlp_coeff[2] * data[i-3];
  85782. sum += qlp_coeff[1] * data[i-2];
  85783. sum += qlp_coeff[0] * data[i-1];
  85784. residual[i] = data[i] - (sum >> lp_quantization);
  85785. }
  85786. }
  85787. else { /* order == 9 */
  85788. for(i = 0; i < (int)data_len; i++) {
  85789. sum = 0;
  85790. sum += qlp_coeff[8] * data[i-9];
  85791. sum += qlp_coeff[7] * data[i-8];
  85792. sum += qlp_coeff[6] * data[i-7];
  85793. sum += qlp_coeff[5] * data[i-6];
  85794. sum += qlp_coeff[4] * data[i-5];
  85795. sum += qlp_coeff[3] * data[i-4];
  85796. sum += qlp_coeff[2] * data[i-3];
  85797. sum += qlp_coeff[1] * data[i-2];
  85798. sum += qlp_coeff[0] * data[i-1];
  85799. residual[i] = data[i] - (sum >> lp_quantization);
  85800. }
  85801. }
  85802. }
  85803. }
  85804. else if(order > 4) {
  85805. if(order > 6) {
  85806. if(order == 8) {
  85807. for(i = 0; i < (int)data_len; i++) {
  85808. sum = 0;
  85809. sum += qlp_coeff[7] * data[i-8];
  85810. sum += qlp_coeff[6] * data[i-7];
  85811. sum += qlp_coeff[5] * data[i-6];
  85812. sum += qlp_coeff[4] * data[i-5];
  85813. sum += qlp_coeff[3] * data[i-4];
  85814. sum += qlp_coeff[2] * data[i-3];
  85815. sum += qlp_coeff[1] * data[i-2];
  85816. sum += qlp_coeff[0] * data[i-1];
  85817. residual[i] = data[i] - (sum >> lp_quantization);
  85818. }
  85819. }
  85820. else { /* order == 7 */
  85821. for(i = 0; i < (int)data_len; i++) {
  85822. sum = 0;
  85823. sum += qlp_coeff[6] * data[i-7];
  85824. sum += qlp_coeff[5] * data[i-6];
  85825. sum += qlp_coeff[4] * data[i-5];
  85826. sum += qlp_coeff[3] * data[i-4];
  85827. sum += qlp_coeff[2] * data[i-3];
  85828. sum += qlp_coeff[1] * data[i-2];
  85829. sum += qlp_coeff[0] * data[i-1];
  85830. residual[i] = data[i] - (sum >> lp_quantization);
  85831. }
  85832. }
  85833. }
  85834. else {
  85835. if(order == 6) {
  85836. for(i = 0; i < (int)data_len; i++) {
  85837. sum = 0;
  85838. sum += qlp_coeff[5] * data[i-6];
  85839. sum += qlp_coeff[4] * data[i-5];
  85840. sum += qlp_coeff[3] * data[i-4];
  85841. sum += qlp_coeff[2] * data[i-3];
  85842. sum += qlp_coeff[1] * data[i-2];
  85843. sum += qlp_coeff[0] * data[i-1];
  85844. residual[i] = data[i] - (sum >> lp_quantization);
  85845. }
  85846. }
  85847. else { /* order == 5 */
  85848. for(i = 0; i < (int)data_len; i++) {
  85849. sum = 0;
  85850. sum += qlp_coeff[4] * data[i-5];
  85851. sum += qlp_coeff[3] * data[i-4];
  85852. sum += qlp_coeff[2] * data[i-3];
  85853. sum += qlp_coeff[1] * data[i-2];
  85854. sum += qlp_coeff[0] * data[i-1];
  85855. residual[i] = data[i] - (sum >> lp_quantization);
  85856. }
  85857. }
  85858. }
  85859. }
  85860. else {
  85861. if(order > 2) {
  85862. if(order == 4) {
  85863. for(i = 0; i < (int)data_len; i++) {
  85864. sum = 0;
  85865. sum += qlp_coeff[3] * data[i-4];
  85866. sum += qlp_coeff[2] * data[i-3];
  85867. sum += qlp_coeff[1] * data[i-2];
  85868. sum += qlp_coeff[0] * data[i-1];
  85869. residual[i] = data[i] - (sum >> lp_quantization);
  85870. }
  85871. }
  85872. else { /* order == 3 */
  85873. for(i = 0; i < (int)data_len; i++) {
  85874. sum = 0;
  85875. sum += qlp_coeff[2] * data[i-3];
  85876. sum += qlp_coeff[1] * data[i-2];
  85877. sum += qlp_coeff[0] * data[i-1];
  85878. residual[i] = data[i] - (sum >> lp_quantization);
  85879. }
  85880. }
  85881. }
  85882. else {
  85883. if(order == 2) {
  85884. for(i = 0; i < (int)data_len; i++) {
  85885. sum = 0;
  85886. sum += qlp_coeff[1] * data[i-2];
  85887. sum += qlp_coeff[0] * data[i-1];
  85888. residual[i] = data[i] - (sum >> lp_quantization);
  85889. }
  85890. }
  85891. else { /* order == 1 */
  85892. for(i = 0; i < (int)data_len; i++)
  85893. residual[i] = data[i] - ((qlp_coeff[0] * data[i-1]) >> lp_quantization);
  85894. }
  85895. }
  85896. }
  85897. }
  85898. else { /* order > 12 */
  85899. for(i = 0; i < (int)data_len; i++) {
  85900. sum = 0;
  85901. switch(order) {
  85902. case 32: sum += qlp_coeff[31] * data[i-32];
  85903. case 31: sum += qlp_coeff[30] * data[i-31];
  85904. case 30: sum += qlp_coeff[29] * data[i-30];
  85905. case 29: sum += qlp_coeff[28] * data[i-29];
  85906. case 28: sum += qlp_coeff[27] * data[i-28];
  85907. case 27: sum += qlp_coeff[26] * data[i-27];
  85908. case 26: sum += qlp_coeff[25] * data[i-26];
  85909. case 25: sum += qlp_coeff[24] * data[i-25];
  85910. case 24: sum += qlp_coeff[23] * data[i-24];
  85911. case 23: sum += qlp_coeff[22] * data[i-23];
  85912. case 22: sum += qlp_coeff[21] * data[i-22];
  85913. case 21: sum += qlp_coeff[20] * data[i-21];
  85914. case 20: sum += qlp_coeff[19] * data[i-20];
  85915. case 19: sum += qlp_coeff[18] * data[i-19];
  85916. case 18: sum += qlp_coeff[17] * data[i-18];
  85917. case 17: sum += qlp_coeff[16] * data[i-17];
  85918. case 16: sum += qlp_coeff[15] * data[i-16];
  85919. case 15: sum += qlp_coeff[14] * data[i-15];
  85920. case 14: sum += qlp_coeff[13] * data[i-14];
  85921. case 13: sum += qlp_coeff[12] * data[i-13];
  85922. sum += qlp_coeff[11] * data[i-12];
  85923. sum += qlp_coeff[10] * data[i-11];
  85924. sum += qlp_coeff[ 9] * data[i-10];
  85925. sum += qlp_coeff[ 8] * data[i- 9];
  85926. sum += qlp_coeff[ 7] * data[i- 8];
  85927. sum += qlp_coeff[ 6] * data[i- 7];
  85928. sum += qlp_coeff[ 5] * data[i- 6];
  85929. sum += qlp_coeff[ 4] * data[i- 5];
  85930. sum += qlp_coeff[ 3] * data[i- 4];
  85931. sum += qlp_coeff[ 2] * data[i- 3];
  85932. sum += qlp_coeff[ 1] * data[i- 2];
  85933. sum += qlp_coeff[ 0] * data[i- 1];
  85934. }
  85935. residual[i] = data[i] - (sum >> lp_quantization);
  85936. }
  85937. }
  85938. }
  85939. #endif
  85940. 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[])
  85941. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  85942. {
  85943. unsigned i, j;
  85944. FLAC__int64 sum;
  85945. const FLAC__int32 *history;
  85946. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  85947. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients_wide: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  85948. for(i=0;i<order;i++)
  85949. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  85950. fprintf(stderr,"\n");
  85951. #endif
  85952. FLAC__ASSERT(order > 0);
  85953. for(i = 0; i < data_len; i++) {
  85954. sum = 0;
  85955. history = data;
  85956. for(j = 0; j < order; j++)
  85957. sum += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*(--history));
  85958. if(FLAC__bitmath_silog2_wide(sum >> lp_quantization) > 32) {
  85959. #if defined _MSC_VER
  85960. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients_wide: OVERFLOW, i=%u, sum=%I64d\n", i, sum >> lp_quantization);
  85961. #else
  85962. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients_wide: OVERFLOW, i=%u, sum=%lld\n", i, (long long)(sum >> lp_quantization));
  85963. #endif
  85964. break;
  85965. }
  85966. if(FLAC__bitmath_silog2_wide((FLAC__int64)(*data) - (sum >> lp_quantization)) > 32) {
  85967. #if defined _MSC_VER
  85968. 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));
  85969. #else
  85970. 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)));
  85971. #endif
  85972. break;
  85973. }
  85974. *(residual++) = *(data++) - (FLAC__int32)(sum >> lp_quantization);
  85975. }
  85976. }
  85977. #else /* fully unrolled version for normal use */
  85978. {
  85979. int i;
  85980. FLAC__int64 sum;
  85981. FLAC__ASSERT(order > 0);
  85982. FLAC__ASSERT(order <= 32);
  85983. if(order <= 12) {
  85984. if(order > 8) {
  85985. if(order > 10) {
  85986. if(order == 12) {
  85987. for(i = 0; i < (int)data_len; i++) {
  85988. sum = 0;
  85989. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  85990. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  85991. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  85992. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85993. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85994. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85995. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85996. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85997. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85998. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85999. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86000. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86001. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  86002. }
  86003. }
  86004. else { /* order == 11 */
  86005. for(i = 0; i < (int)data_len; i++) {
  86006. sum = 0;
  86007. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  86008. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  86009. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  86010. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86011. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86012. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86013. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86014. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86015. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86016. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86017. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86018. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  86019. }
  86020. }
  86021. }
  86022. else {
  86023. if(order == 10) {
  86024. for(i = 0; i < (int)data_len; i++) {
  86025. sum = 0;
  86026. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  86027. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  86028. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86029. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86030. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86031. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86032. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86033. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86034. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86035. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86036. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  86037. }
  86038. }
  86039. else { /* order == 9 */
  86040. for(i = 0; i < (int)data_len; i++) {
  86041. sum = 0;
  86042. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  86043. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86044. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86045. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86046. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86047. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86048. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86049. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86050. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86051. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  86052. }
  86053. }
  86054. }
  86055. }
  86056. else if(order > 4) {
  86057. if(order > 6) {
  86058. if(order == 8) {
  86059. for(i = 0; i < (int)data_len; i++) {
  86060. sum = 0;
  86061. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86062. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86063. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86064. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86065. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86066. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86067. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86068. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86069. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  86070. }
  86071. }
  86072. else { /* order == 7 */
  86073. for(i = 0; i < (int)data_len; i++) {
  86074. sum = 0;
  86075. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86076. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86077. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86078. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86079. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86080. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86081. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86082. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  86083. }
  86084. }
  86085. }
  86086. else {
  86087. if(order == 6) {
  86088. for(i = 0; i < (int)data_len; i++) {
  86089. sum = 0;
  86090. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86091. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86092. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86093. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86094. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86095. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86096. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  86097. }
  86098. }
  86099. else { /* order == 5 */
  86100. for(i = 0; i < (int)data_len; i++) {
  86101. sum = 0;
  86102. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86103. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86104. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86105. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86106. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86107. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  86108. }
  86109. }
  86110. }
  86111. }
  86112. else {
  86113. if(order > 2) {
  86114. if(order == 4) {
  86115. for(i = 0; i < (int)data_len; i++) {
  86116. sum = 0;
  86117. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86118. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86119. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86120. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86121. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  86122. }
  86123. }
  86124. else { /* order == 3 */
  86125. for(i = 0; i < (int)data_len; i++) {
  86126. sum = 0;
  86127. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86128. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86129. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86130. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  86131. }
  86132. }
  86133. }
  86134. else {
  86135. if(order == 2) {
  86136. for(i = 0; i < (int)data_len; i++) {
  86137. sum = 0;
  86138. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86139. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86140. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  86141. }
  86142. }
  86143. else { /* order == 1 */
  86144. for(i = 0; i < (int)data_len; i++)
  86145. residual[i] = data[i] - (FLAC__int32)((qlp_coeff[0] * (FLAC__int64)data[i-1]) >> lp_quantization);
  86146. }
  86147. }
  86148. }
  86149. }
  86150. else { /* order > 12 */
  86151. for(i = 0; i < (int)data_len; i++) {
  86152. sum = 0;
  86153. switch(order) {
  86154. case 32: sum += qlp_coeff[31] * (FLAC__int64)data[i-32];
  86155. case 31: sum += qlp_coeff[30] * (FLAC__int64)data[i-31];
  86156. case 30: sum += qlp_coeff[29] * (FLAC__int64)data[i-30];
  86157. case 29: sum += qlp_coeff[28] * (FLAC__int64)data[i-29];
  86158. case 28: sum += qlp_coeff[27] * (FLAC__int64)data[i-28];
  86159. case 27: sum += qlp_coeff[26] * (FLAC__int64)data[i-27];
  86160. case 26: sum += qlp_coeff[25] * (FLAC__int64)data[i-26];
  86161. case 25: sum += qlp_coeff[24] * (FLAC__int64)data[i-25];
  86162. case 24: sum += qlp_coeff[23] * (FLAC__int64)data[i-24];
  86163. case 23: sum += qlp_coeff[22] * (FLAC__int64)data[i-23];
  86164. case 22: sum += qlp_coeff[21] * (FLAC__int64)data[i-22];
  86165. case 21: sum += qlp_coeff[20] * (FLAC__int64)data[i-21];
  86166. case 20: sum += qlp_coeff[19] * (FLAC__int64)data[i-20];
  86167. case 19: sum += qlp_coeff[18] * (FLAC__int64)data[i-19];
  86168. case 18: sum += qlp_coeff[17] * (FLAC__int64)data[i-18];
  86169. case 17: sum += qlp_coeff[16] * (FLAC__int64)data[i-17];
  86170. case 16: sum += qlp_coeff[15] * (FLAC__int64)data[i-16];
  86171. case 15: sum += qlp_coeff[14] * (FLAC__int64)data[i-15];
  86172. case 14: sum += qlp_coeff[13] * (FLAC__int64)data[i-14];
  86173. case 13: sum += qlp_coeff[12] * (FLAC__int64)data[i-13];
  86174. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  86175. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  86176. sum += qlp_coeff[ 9] * (FLAC__int64)data[i-10];
  86177. sum += qlp_coeff[ 8] * (FLAC__int64)data[i- 9];
  86178. sum += qlp_coeff[ 7] * (FLAC__int64)data[i- 8];
  86179. sum += qlp_coeff[ 6] * (FLAC__int64)data[i- 7];
  86180. sum += qlp_coeff[ 5] * (FLAC__int64)data[i- 6];
  86181. sum += qlp_coeff[ 4] * (FLAC__int64)data[i- 5];
  86182. sum += qlp_coeff[ 3] * (FLAC__int64)data[i- 4];
  86183. sum += qlp_coeff[ 2] * (FLAC__int64)data[i- 3];
  86184. sum += qlp_coeff[ 1] * (FLAC__int64)data[i- 2];
  86185. sum += qlp_coeff[ 0] * (FLAC__int64)data[i- 1];
  86186. }
  86187. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  86188. }
  86189. }
  86190. }
  86191. #endif
  86192. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  86193. 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[])
  86194. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  86195. {
  86196. FLAC__int64 sumo;
  86197. unsigned i, j;
  86198. FLAC__int32 sum;
  86199. const FLAC__int32 *r = residual, *history;
  86200. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  86201. fprintf(stderr,"FLAC__lpc_restore_signal: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  86202. for(i=0;i<order;i++)
  86203. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  86204. fprintf(stderr,"\n");
  86205. #endif
  86206. FLAC__ASSERT(order > 0);
  86207. for(i = 0; i < data_len; i++) {
  86208. sumo = 0;
  86209. sum = 0;
  86210. history = data;
  86211. for(j = 0; j < order; j++) {
  86212. sum += qlp_coeff[j] * (*(--history));
  86213. sumo += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*history);
  86214. #if defined _MSC_VER
  86215. if(sumo > 2147483647I64 || sumo < -2147483648I64)
  86216. 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);
  86217. #else
  86218. if(sumo > 2147483647ll || sumo < -2147483648ll)
  86219. 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);
  86220. #endif
  86221. }
  86222. *(data++) = *(r++) + (sum >> lp_quantization);
  86223. }
  86224. }
  86225. #else /* fully unrolled version for normal use */
  86226. {
  86227. int i;
  86228. FLAC__int32 sum;
  86229. FLAC__ASSERT(order > 0);
  86230. FLAC__ASSERT(order <= 32);
  86231. if(order <= 12) {
  86232. if(order > 8) {
  86233. if(order > 10) {
  86234. if(order == 12) {
  86235. for(i = 0; i < (int)data_len; i++) {
  86236. sum = 0;
  86237. sum += qlp_coeff[11] * data[i-12];
  86238. sum += qlp_coeff[10] * data[i-11];
  86239. sum += qlp_coeff[9] * data[i-10];
  86240. sum += qlp_coeff[8] * data[i-9];
  86241. sum += qlp_coeff[7] * data[i-8];
  86242. sum += qlp_coeff[6] * data[i-7];
  86243. sum += qlp_coeff[5] * data[i-6];
  86244. sum += qlp_coeff[4] * data[i-5];
  86245. sum += qlp_coeff[3] * data[i-4];
  86246. sum += qlp_coeff[2] * data[i-3];
  86247. sum += qlp_coeff[1] * data[i-2];
  86248. sum += qlp_coeff[0] * data[i-1];
  86249. data[i] = residual[i] + (sum >> lp_quantization);
  86250. }
  86251. }
  86252. else { /* order == 11 */
  86253. for(i = 0; i < (int)data_len; i++) {
  86254. sum = 0;
  86255. sum += qlp_coeff[10] * data[i-11];
  86256. sum += qlp_coeff[9] * data[i-10];
  86257. sum += qlp_coeff[8] * data[i-9];
  86258. sum += qlp_coeff[7] * data[i-8];
  86259. sum += qlp_coeff[6] * data[i-7];
  86260. sum += qlp_coeff[5] * data[i-6];
  86261. sum += qlp_coeff[4] * data[i-5];
  86262. sum += qlp_coeff[3] * data[i-4];
  86263. sum += qlp_coeff[2] * data[i-3];
  86264. sum += qlp_coeff[1] * data[i-2];
  86265. sum += qlp_coeff[0] * data[i-1];
  86266. data[i] = residual[i] + (sum >> lp_quantization);
  86267. }
  86268. }
  86269. }
  86270. else {
  86271. if(order == 10) {
  86272. for(i = 0; i < (int)data_len; i++) {
  86273. sum = 0;
  86274. sum += qlp_coeff[9] * data[i-10];
  86275. sum += qlp_coeff[8] * data[i-9];
  86276. sum += qlp_coeff[7] * data[i-8];
  86277. sum += qlp_coeff[6] * data[i-7];
  86278. sum += qlp_coeff[5] * data[i-6];
  86279. sum += qlp_coeff[4] * data[i-5];
  86280. sum += qlp_coeff[3] * data[i-4];
  86281. sum += qlp_coeff[2] * data[i-3];
  86282. sum += qlp_coeff[1] * data[i-2];
  86283. sum += qlp_coeff[0] * data[i-1];
  86284. data[i] = residual[i] + (sum >> lp_quantization);
  86285. }
  86286. }
  86287. else { /* order == 9 */
  86288. for(i = 0; i < (int)data_len; i++) {
  86289. sum = 0;
  86290. sum += qlp_coeff[8] * data[i-9];
  86291. sum += qlp_coeff[7] * data[i-8];
  86292. sum += qlp_coeff[6] * data[i-7];
  86293. sum += qlp_coeff[5] * data[i-6];
  86294. sum += qlp_coeff[4] * data[i-5];
  86295. sum += qlp_coeff[3] * data[i-4];
  86296. sum += qlp_coeff[2] * data[i-3];
  86297. sum += qlp_coeff[1] * data[i-2];
  86298. sum += qlp_coeff[0] * data[i-1];
  86299. data[i] = residual[i] + (sum >> lp_quantization);
  86300. }
  86301. }
  86302. }
  86303. }
  86304. else if(order > 4) {
  86305. if(order > 6) {
  86306. if(order == 8) {
  86307. for(i = 0; i < (int)data_len; i++) {
  86308. sum = 0;
  86309. sum += qlp_coeff[7] * data[i-8];
  86310. sum += qlp_coeff[6] * data[i-7];
  86311. sum += qlp_coeff[5] * data[i-6];
  86312. sum += qlp_coeff[4] * data[i-5];
  86313. sum += qlp_coeff[3] * data[i-4];
  86314. sum += qlp_coeff[2] * data[i-3];
  86315. sum += qlp_coeff[1] * data[i-2];
  86316. sum += qlp_coeff[0] * data[i-1];
  86317. data[i] = residual[i] + (sum >> lp_quantization);
  86318. }
  86319. }
  86320. else { /* order == 7 */
  86321. for(i = 0; i < (int)data_len; i++) {
  86322. sum = 0;
  86323. sum += qlp_coeff[6] * data[i-7];
  86324. sum += qlp_coeff[5] * data[i-6];
  86325. sum += qlp_coeff[4] * data[i-5];
  86326. sum += qlp_coeff[3] * data[i-4];
  86327. sum += qlp_coeff[2] * data[i-3];
  86328. sum += qlp_coeff[1] * data[i-2];
  86329. sum += qlp_coeff[0] * data[i-1];
  86330. data[i] = residual[i] + (sum >> lp_quantization);
  86331. }
  86332. }
  86333. }
  86334. else {
  86335. if(order == 6) {
  86336. for(i = 0; i < (int)data_len; i++) {
  86337. sum = 0;
  86338. sum += qlp_coeff[5] * data[i-6];
  86339. sum += qlp_coeff[4] * data[i-5];
  86340. sum += qlp_coeff[3] * data[i-4];
  86341. sum += qlp_coeff[2] * data[i-3];
  86342. sum += qlp_coeff[1] * data[i-2];
  86343. sum += qlp_coeff[0] * data[i-1];
  86344. data[i] = residual[i] + (sum >> lp_quantization);
  86345. }
  86346. }
  86347. else { /* order == 5 */
  86348. for(i = 0; i < (int)data_len; i++) {
  86349. sum = 0;
  86350. sum += qlp_coeff[4] * data[i-5];
  86351. sum += qlp_coeff[3] * data[i-4];
  86352. sum += qlp_coeff[2] * data[i-3];
  86353. sum += qlp_coeff[1] * data[i-2];
  86354. sum += qlp_coeff[0] * data[i-1];
  86355. data[i] = residual[i] + (sum >> lp_quantization);
  86356. }
  86357. }
  86358. }
  86359. }
  86360. else {
  86361. if(order > 2) {
  86362. if(order == 4) {
  86363. for(i = 0; i < (int)data_len; i++) {
  86364. sum = 0;
  86365. sum += qlp_coeff[3] * data[i-4];
  86366. sum += qlp_coeff[2] * data[i-3];
  86367. sum += qlp_coeff[1] * data[i-2];
  86368. sum += qlp_coeff[0] * data[i-1];
  86369. data[i] = residual[i] + (sum >> lp_quantization);
  86370. }
  86371. }
  86372. else { /* order == 3 */
  86373. for(i = 0; i < (int)data_len; i++) {
  86374. sum = 0;
  86375. sum += qlp_coeff[2] * data[i-3];
  86376. sum += qlp_coeff[1] * data[i-2];
  86377. sum += qlp_coeff[0] * data[i-1];
  86378. data[i] = residual[i] + (sum >> lp_quantization);
  86379. }
  86380. }
  86381. }
  86382. else {
  86383. if(order == 2) {
  86384. for(i = 0; i < (int)data_len; i++) {
  86385. sum = 0;
  86386. sum += qlp_coeff[1] * data[i-2];
  86387. sum += qlp_coeff[0] * data[i-1];
  86388. data[i] = residual[i] + (sum >> lp_quantization);
  86389. }
  86390. }
  86391. else { /* order == 1 */
  86392. for(i = 0; i < (int)data_len; i++)
  86393. data[i] = residual[i] + ((qlp_coeff[0] * data[i-1]) >> lp_quantization);
  86394. }
  86395. }
  86396. }
  86397. }
  86398. else { /* order > 12 */
  86399. for(i = 0; i < (int)data_len; i++) {
  86400. sum = 0;
  86401. switch(order) {
  86402. case 32: sum += qlp_coeff[31] * data[i-32];
  86403. case 31: sum += qlp_coeff[30] * data[i-31];
  86404. case 30: sum += qlp_coeff[29] * data[i-30];
  86405. case 29: sum += qlp_coeff[28] * data[i-29];
  86406. case 28: sum += qlp_coeff[27] * data[i-28];
  86407. case 27: sum += qlp_coeff[26] * data[i-27];
  86408. case 26: sum += qlp_coeff[25] * data[i-26];
  86409. case 25: sum += qlp_coeff[24] * data[i-25];
  86410. case 24: sum += qlp_coeff[23] * data[i-24];
  86411. case 23: sum += qlp_coeff[22] * data[i-23];
  86412. case 22: sum += qlp_coeff[21] * data[i-22];
  86413. case 21: sum += qlp_coeff[20] * data[i-21];
  86414. case 20: sum += qlp_coeff[19] * data[i-20];
  86415. case 19: sum += qlp_coeff[18] * data[i-19];
  86416. case 18: sum += qlp_coeff[17] * data[i-18];
  86417. case 17: sum += qlp_coeff[16] * data[i-17];
  86418. case 16: sum += qlp_coeff[15] * data[i-16];
  86419. case 15: sum += qlp_coeff[14] * data[i-15];
  86420. case 14: sum += qlp_coeff[13] * data[i-14];
  86421. case 13: sum += qlp_coeff[12] * data[i-13];
  86422. sum += qlp_coeff[11] * data[i-12];
  86423. sum += qlp_coeff[10] * data[i-11];
  86424. sum += qlp_coeff[ 9] * data[i-10];
  86425. sum += qlp_coeff[ 8] * data[i- 9];
  86426. sum += qlp_coeff[ 7] * data[i- 8];
  86427. sum += qlp_coeff[ 6] * data[i- 7];
  86428. sum += qlp_coeff[ 5] * data[i- 6];
  86429. sum += qlp_coeff[ 4] * data[i- 5];
  86430. sum += qlp_coeff[ 3] * data[i- 4];
  86431. sum += qlp_coeff[ 2] * data[i- 3];
  86432. sum += qlp_coeff[ 1] * data[i- 2];
  86433. sum += qlp_coeff[ 0] * data[i- 1];
  86434. }
  86435. data[i] = residual[i] + (sum >> lp_quantization);
  86436. }
  86437. }
  86438. }
  86439. #endif
  86440. 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[])
  86441. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  86442. {
  86443. unsigned i, j;
  86444. FLAC__int64 sum;
  86445. const FLAC__int32 *r = residual, *history;
  86446. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  86447. fprintf(stderr,"FLAC__lpc_restore_signal_wide: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  86448. for(i=0;i<order;i++)
  86449. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  86450. fprintf(stderr,"\n");
  86451. #endif
  86452. FLAC__ASSERT(order > 0);
  86453. for(i = 0; i < data_len; i++) {
  86454. sum = 0;
  86455. history = data;
  86456. for(j = 0; j < order; j++)
  86457. sum += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*(--history));
  86458. if(FLAC__bitmath_silog2_wide(sum >> lp_quantization) > 32) {
  86459. #ifdef _MSC_VER
  86460. fprintf(stderr,"FLAC__lpc_restore_signal_wide: OVERFLOW, i=%u, sum=%I64d\n", i, sum >> lp_quantization);
  86461. #else
  86462. fprintf(stderr,"FLAC__lpc_restore_signal_wide: OVERFLOW, i=%u, sum=%lld\n", i, (long long)(sum >> lp_quantization));
  86463. #endif
  86464. break;
  86465. }
  86466. if(FLAC__bitmath_silog2_wide((FLAC__int64)(*r) + (sum >> lp_quantization)) > 32) {
  86467. #ifdef _MSC_VER
  86468. 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));
  86469. #else
  86470. 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)));
  86471. #endif
  86472. break;
  86473. }
  86474. *(data++) = *(r++) + (FLAC__int32)(sum >> lp_quantization);
  86475. }
  86476. }
  86477. #else /* fully unrolled version for normal use */
  86478. {
  86479. int i;
  86480. FLAC__int64 sum;
  86481. FLAC__ASSERT(order > 0);
  86482. FLAC__ASSERT(order <= 32);
  86483. if(order <= 12) {
  86484. if(order > 8) {
  86485. if(order > 10) {
  86486. if(order == 12) {
  86487. for(i = 0; i < (int)data_len; i++) {
  86488. sum = 0;
  86489. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  86490. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  86491. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  86492. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  86493. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86494. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86495. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86496. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86497. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86498. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86499. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86500. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86501. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86502. }
  86503. }
  86504. else { /* order == 11 */
  86505. for(i = 0; i < (int)data_len; i++) {
  86506. sum = 0;
  86507. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  86508. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  86509. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  86510. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86511. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86512. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86513. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86514. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86515. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86516. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86517. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86518. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86519. }
  86520. }
  86521. }
  86522. else {
  86523. if(order == 10) {
  86524. for(i = 0; i < (int)data_len; i++) {
  86525. sum = 0;
  86526. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  86527. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  86528. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86529. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86530. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86531. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86532. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86533. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86534. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86535. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86536. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86537. }
  86538. }
  86539. else { /* order == 9 */
  86540. for(i = 0; i < (int)data_len; i++) {
  86541. sum = 0;
  86542. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  86543. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86544. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86545. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86546. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86547. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86548. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86549. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86550. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86551. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86552. }
  86553. }
  86554. }
  86555. }
  86556. else if(order > 4) {
  86557. if(order > 6) {
  86558. if(order == 8) {
  86559. for(i = 0; i < (int)data_len; i++) {
  86560. sum = 0;
  86561. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86562. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86563. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86564. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86565. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86566. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86567. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86568. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86569. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86570. }
  86571. }
  86572. else { /* order == 7 */
  86573. for(i = 0; i < (int)data_len; i++) {
  86574. sum = 0;
  86575. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86576. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86577. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86578. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86579. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86580. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86581. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86582. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86583. }
  86584. }
  86585. }
  86586. else {
  86587. if(order == 6) {
  86588. for(i = 0; i < (int)data_len; i++) {
  86589. sum = 0;
  86590. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86591. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86592. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86593. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86594. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86595. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86596. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86597. }
  86598. }
  86599. else { /* order == 5 */
  86600. for(i = 0; i < (int)data_len; i++) {
  86601. sum = 0;
  86602. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86603. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86604. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86605. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86606. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86607. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86608. }
  86609. }
  86610. }
  86611. }
  86612. else {
  86613. if(order > 2) {
  86614. if(order == 4) {
  86615. for(i = 0; i < (int)data_len; i++) {
  86616. sum = 0;
  86617. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86618. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86619. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86620. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86621. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86622. }
  86623. }
  86624. else { /* order == 3 */
  86625. for(i = 0; i < (int)data_len; i++) {
  86626. sum = 0;
  86627. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86628. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86629. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86630. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86631. }
  86632. }
  86633. }
  86634. else {
  86635. if(order == 2) {
  86636. for(i = 0; i < (int)data_len; i++) {
  86637. sum = 0;
  86638. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86639. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86640. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86641. }
  86642. }
  86643. else { /* order == 1 */
  86644. for(i = 0; i < (int)data_len; i++)
  86645. data[i] = residual[i] + (FLAC__int32)((qlp_coeff[0] * (FLAC__int64)data[i-1]) >> lp_quantization);
  86646. }
  86647. }
  86648. }
  86649. }
  86650. else { /* order > 12 */
  86651. for(i = 0; i < (int)data_len; i++) {
  86652. sum = 0;
  86653. switch(order) {
  86654. case 32: sum += qlp_coeff[31] * (FLAC__int64)data[i-32];
  86655. case 31: sum += qlp_coeff[30] * (FLAC__int64)data[i-31];
  86656. case 30: sum += qlp_coeff[29] * (FLAC__int64)data[i-30];
  86657. case 29: sum += qlp_coeff[28] * (FLAC__int64)data[i-29];
  86658. case 28: sum += qlp_coeff[27] * (FLAC__int64)data[i-28];
  86659. case 27: sum += qlp_coeff[26] * (FLAC__int64)data[i-27];
  86660. case 26: sum += qlp_coeff[25] * (FLAC__int64)data[i-26];
  86661. case 25: sum += qlp_coeff[24] * (FLAC__int64)data[i-25];
  86662. case 24: sum += qlp_coeff[23] * (FLAC__int64)data[i-24];
  86663. case 23: sum += qlp_coeff[22] * (FLAC__int64)data[i-23];
  86664. case 22: sum += qlp_coeff[21] * (FLAC__int64)data[i-22];
  86665. case 21: sum += qlp_coeff[20] * (FLAC__int64)data[i-21];
  86666. case 20: sum += qlp_coeff[19] * (FLAC__int64)data[i-20];
  86667. case 19: sum += qlp_coeff[18] * (FLAC__int64)data[i-19];
  86668. case 18: sum += qlp_coeff[17] * (FLAC__int64)data[i-18];
  86669. case 17: sum += qlp_coeff[16] * (FLAC__int64)data[i-17];
  86670. case 16: sum += qlp_coeff[15] * (FLAC__int64)data[i-16];
  86671. case 15: sum += qlp_coeff[14] * (FLAC__int64)data[i-15];
  86672. case 14: sum += qlp_coeff[13] * (FLAC__int64)data[i-14];
  86673. case 13: sum += qlp_coeff[12] * (FLAC__int64)data[i-13];
  86674. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  86675. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  86676. sum += qlp_coeff[ 9] * (FLAC__int64)data[i-10];
  86677. sum += qlp_coeff[ 8] * (FLAC__int64)data[i- 9];
  86678. sum += qlp_coeff[ 7] * (FLAC__int64)data[i- 8];
  86679. sum += qlp_coeff[ 6] * (FLAC__int64)data[i- 7];
  86680. sum += qlp_coeff[ 5] * (FLAC__int64)data[i- 6];
  86681. sum += qlp_coeff[ 4] * (FLAC__int64)data[i- 5];
  86682. sum += qlp_coeff[ 3] * (FLAC__int64)data[i- 4];
  86683. sum += qlp_coeff[ 2] * (FLAC__int64)data[i- 3];
  86684. sum += qlp_coeff[ 1] * (FLAC__int64)data[i- 2];
  86685. sum += qlp_coeff[ 0] * (FLAC__int64)data[i- 1];
  86686. }
  86687. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86688. }
  86689. }
  86690. }
  86691. #endif
  86692. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  86693. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample(FLAC__double lpc_error, unsigned total_samples)
  86694. {
  86695. FLAC__double error_scale;
  86696. FLAC__ASSERT(total_samples > 0);
  86697. error_scale = 0.5 * M_LN2 * M_LN2 / (FLAC__double)total_samples;
  86698. return FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale(lpc_error, error_scale);
  86699. }
  86700. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale(FLAC__double lpc_error, FLAC__double error_scale)
  86701. {
  86702. if(lpc_error > 0.0) {
  86703. FLAC__double bps = (FLAC__double)0.5 * log(error_scale * lpc_error) / M_LN2;
  86704. if(bps >= 0.0)
  86705. return bps;
  86706. else
  86707. return 0.0;
  86708. }
  86709. else if(lpc_error < 0.0) { /* error should not be negative but can happen due to inadequate floating-point resolution */
  86710. return 1e32;
  86711. }
  86712. else {
  86713. return 0.0;
  86714. }
  86715. }
  86716. unsigned FLAC__lpc_compute_best_order(const FLAC__double lpc_error[], unsigned max_order, unsigned total_samples, unsigned overhead_bits_per_order)
  86717. {
  86718. 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 */
  86719. FLAC__double bits, best_bits, error_scale;
  86720. FLAC__ASSERT(max_order > 0);
  86721. FLAC__ASSERT(total_samples > 0);
  86722. error_scale = 0.5 * M_LN2 * M_LN2 / (FLAC__double)total_samples;
  86723. best_index = 0;
  86724. best_bits = (unsigned)(-1);
  86725. for(index = 0, order = 1; index < max_order; index++, order++) {
  86726. 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);
  86727. if(bits < best_bits) {
  86728. best_index = index;
  86729. best_bits = bits;
  86730. }
  86731. }
  86732. return best_index+1; /* +1 since index of lpc_error[] is order-1 */
  86733. }
  86734. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  86735. #endif
  86736. /*** End of inlined file: lpc_flac.c ***/
  86737. /*** Start of inlined file: md5.c ***/
  86738. /*** Start of inlined file: juce_FlacHeader.h ***/
  86739. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  86740. // tasks..
  86741. #define VERSION "1.2.1"
  86742. #define FLAC__NO_DLL 1
  86743. #if JUCE_MSVC
  86744. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  86745. #endif
  86746. #if JUCE_MAC
  86747. #define FLAC__SYS_DARWIN 1
  86748. #endif
  86749. /*** End of inlined file: juce_FlacHeader.h ***/
  86750. #if JUCE_USE_FLAC
  86751. #if HAVE_CONFIG_H
  86752. # include <config.h>
  86753. #endif
  86754. #include <stdlib.h> /* for malloc() */
  86755. #include <string.h> /* for memcpy() */
  86756. /*** Start of inlined file: md5.h ***/
  86757. #ifndef FLAC__PRIVATE__MD5_H
  86758. #define FLAC__PRIVATE__MD5_H
  86759. typedef struct {
  86760. FLAC__uint32 in[16];
  86761. FLAC__uint32 buf[4];
  86762. FLAC__uint32 bytes[2];
  86763. FLAC__byte *internal_buf;
  86764. size_t capacity;
  86765. } FLAC__MD5Context;
  86766. void FLAC__MD5Init(FLAC__MD5Context *context);
  86767. void FLAC__MD5Final(FLAC__byte digest[16], FLAC__MD5Context *context);
  86768. FLAC__bool FLAC__MD5Accumulate(FLAC__MD5Context *ctx, const FLAC__int32 * const signal[], unsigned channels, unsigned samples, unsigned bytes_per_sample);
  86769. #endif
  86770. /*** End of inlined file: md5.h ***/
  86771. #ifndef FLaC__INLINE
  86772. #define FLaC__INLINE
  86773. #endif
  86774. #define F1(x, y, z) (z ^ (x & (y ^ z)))
  86775. #define F2(x, y, z) F1(z, x, y)
  86776. #define F3(x, y, z) (x ^ y ^ z)
  86777. #define F4(x, y, z) (y ^ (x | ~z))
  86778. #define MD5STEP(f,w,x,y,z,in,s) \
  86779. (w += f(x,y,z) + in, w = (w<<s | w>>(32-s)) + x)
  86780. static void FLAC__MD5Transform(FLAC__uint32 buf[4], FLAC__uint32 const in[16])
  86781. {
  86782. register FLAC__uint32 a, b, c, d;
  86783. a = buf[0];
  86784. b = buf[1];
  86785. c = buf[2];
  86786. d = buf[3];
  86787. MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7);
  86788. MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12);
  86789. MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17);
  86790. MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22);
  86791. MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7);
  86792. MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12);
  86793. MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17);
  86794. MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22);
  86795. MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7);
  86796. MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12);
  86797. MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17);
  86798. MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22);
  86799. MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7);
  86800. MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12);
  86801. MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17);
  86802. MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22);
  86803. MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5);
  86804. MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9);
  86805. MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14);
  86806. MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20);
  86807. MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5);
  86808. MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9);
  86809. MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14);
  86810. MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20);
  86811. MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5);
  86812. MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9);
  86813. MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14);
  86814. MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20);
  86815. MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5);
  86816. MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9);
  86817. MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14);
  86818. MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20);
  86819. MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4);
  86820. MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11);
  86821. MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16);
  86822. MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23);
  86823. MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4);
  86824. MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11);
  86825. MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16);
  86826. MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23);
  86827. MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4);
  86828. MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11);
  86829. MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16);
  86830. MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23);
  86831. MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4);
  86832. MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11);
  86833. MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16);
  86834. MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23);
  86835. MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6);
  86836. MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10);
  86837. MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15);
  86838. MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21);
  86839. MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6);
  86840. MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10);
  86841. MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15);
  86842. MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21);
  86843. MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6);
  86844. MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10);
  86845. MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15);
  86846. MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21);
  86847. MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6);
  86848. MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10);
  86849. MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15);
  86850. MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21);
  86851. buf[0] += a;
  86852. buf[1] += b;
  86853. buf[2] += c;
  86854. buf[3] += d;
  86855. }
  86856. #if WORDS_BIGENDIAN
  86857. //@@@@@@ OPT: use bswap/intrinsics
  86858. static void byteSwap(FLAC__uint32 *buf, unsigned words)
  86859. {
  86860. register FLAC__uint32 x;
  86861. do {
  86862. x = *buf;
  86863. x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff);
  86864. *buf++ = (x >> 16) | (x << 16);
  86865. } while (--words);
  86866. }
  86867. static void byteSwapX16(FLAC__uint32 *buf)
  86868. {
  86869. register FLAC__uint32 x;
  86870. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86871. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86872. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86873. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86874. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86875. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86876. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86877. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86878. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86879. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86880. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86881. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86882. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86883. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86884. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86885. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf = (x >> 16) | (x << 16);
  86886. }
  86887. #else
  86888. #define byteSwap(buf, words)
  86889. #define byteSwapX16(buf)
  86890. #endif
  86891. static void FLAC__MD5Update(FLAC__MD5Context *ctx, FLAC__byte const *buf, unsigned len)
  86892. {
  86893. FLAC__uint32 t;
  86894. t = ctx->bytes[0];
  86895. if ((ctx->bytes[0] = t + len) < t)
  86896. ctx->bytes[1]++; /* Carry from low to high */
  86897. t = 64 - (t & 0x3f); /* Space available in ctx->in (at least 1) */
  86898. if (t > len) {
  86899. memcpy((FLAC__byte *)ctx->in + 64 - t, buf, len);
  86900. return;
  86901. }
  86902. memcpy((FLAC__byte *)ctx->in + 64 - t, buf, t);
  86903. byteSwapX16(ctx->in);
  86904. FLAC__MD5Transform(ctx->buf, ctx->in);
  86905. buf += t;
  86906. len -= t;
  86907. while (len >= 64) {
  86908. memcpy(ctx->in, buf, 64);
  86909. byteSwapX16(ctx->in);
  86910. FLAC__MD5Transform(ctx->buf, ctx->in);
  86911. buf += 64;
  86912. len -= 64;
  86913. }
  86914. memcpy(ctx->in, buf, len);
  86915. }
  86916. void FLAC__MD5Init(FLAC__MD5Context *ctx)
  86917. {
  86918. ctx->buf[0] = 0x67452301;
  86919. ctx->buf[1] = 0xefcdab89;
  86920. ctx->buf[2] = 0x98badcfe;
  86921. ctx->buf[3] = 0x10325476;
  86922. ctx->bytes[0] = 0;
  86923. ctx->bytes[1] = 0;
  86924. ctx->internal_buf = 0;
  86925. ctx->capacity = 0;
  86926. }
  86927. void FLAC__MD5Final(FLAC__byte digest[16], FLAC__MD5Context *ctx)
  86928. {
  86929. int count = ctx->bytes[0] & 0x3f; /* Number of bytes in ctx->in */
  86930. FLAC__byte *p = (FLAC__byte *)ctx->in + count;
  86931. *p++ = 0x80;
  86932. count = 56 - 1 - count;
  86933. if (count < 0) { /* Padding forces an extra block */
  86934. memset(p, 0, count + 8);
  86935. byteSwapX16(ctx->in);
  86936. FLAC__MD5Transform(ctx->buf, ctx->in);
  86937. p = (FLAC__byte *)ctx->in;
  86938. count = 56;
  86939. }
  86940. memset(p, 0, count);
  86941. byteSwap(ctx->in, 14);
  86942. ctx->in[14] = ctx->bytes[0] << 3;
  86943. ctx->in[15] = ctx->bytes[1] << 3 | ctx->bytes[0] >> 29;
  86944. FLAC__MD5Transform(ctx->buf, ctx->in);
  86945. byteSwap(ctx->buf, 4);
  86946. memcpy(digest, ctx->buf, 16);
  86947. memset(ctx, 0, sizeof(ctx)); /* In case it's sensitive */
  86948. if(0 != ctx->internal_buf) {
  86949. free(ctx->internal_buf);
  86950. ctx->internal_buf = 0;
  86951. ctx->capacity = 0;
  86952. }
  86953. }
  86954. static void format_input_(FLAC__byte *buf, const FLAC__int32 * const signal[], unsigned channels, unsigned samples, unsigned bytes_per_sample)
  86955. {
  86956. unsigned channel, sample;
  86957. register FLAC__int32 a_word;
  86958. register FLAC__byte *buf_ = buf;
  86959. #if WORDS_BIGENDIAN
  86960. #else
  86961. if(channels == 2 && bytes_per_sample == 2) {
  86962. FLAC__int16 *buf1_ = ((FLAC__int16*)buf_) + 1;
  86963. memcpy(buf_, signal[0], sizeof(FLAC__int32) * samples);
  86964. for(sample = 0; sample < samples; sample++, buf1_+=2)
  86965. *buf1_ = (FLAC__int16)signal[1][sample];
  86966. }
  86967. else if(channels == 1 && bytes_per_sample == 2) {
  86968. FLAC__int16 *buf1_ = (FLAC__int16*)buf_;
  86969. for(sample = 0; sample < samples; sample++)
  86970. *buf1_++ = (FLAC__int16)signal[0][sample];
  86971. }
  86972. else
  86973. #endif
  86974. if(bytes_per_sample == 2) {
  86975. if(channels == 2) {
  86976. for(sample = 0; sample < samples; sample++) {
  86977. a_word = signal[0][sample];
  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;
  86983. }
  86984. }
  86985. else if(channels == 1) {
  86986. for(sample = 0; sample < samples; sample++) {
  86987. a_word = signal[0][sample];
  86988. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86989. *buf_++ = (FLAC__byte)a_word;
  86990. }
  86991. }
  86992. else {
  86993. for(sample = 0; sample < samples; sample++) {
  86994. for(channel = 0; channel < channels; channel++) {
  86995. a_word = signal[channel][sample];
  86996. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86997. *buf_++ = (FLAC__byte)a_word;
  86998. }
  86999. }
  87000. }
  87001. }
  87002. else if(bytes_per_sample == 3) {
  87003. if(channels == 2) {
  87004. for(sample = 0; sample < samples; sample++) {
  87005. a_word = signal[0][sample];
  87006. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  87007. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  87008. *buf_++ = (FLAC__byte)a_word;
  87009. a_word = signal[1][sample];
  87010. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  87011. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  87012. *buf_++ = (FLAC__byte)a_word;
  87013. }
  87014. }
  87015. else if(channels == 1) {
  87016. for(sample = 0; sample < samples; sample++) {
  87017. a_word = signal[0][sample];
  87018. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  87019. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  87020. *buf_++ = (FLAC__byte)a_word;
  87021. }
  87022. }
  87023. else {
  87024. for(sample = 0; sample < samples; sample++) {
  87025. for(channel = 0; channel < channels; channel++) {
  87026. a_word = signal[channel][sample];
  87027. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  87028. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  87029. *buf_++ = (FLAC__byte)a_word;
  87030. }
  87031. }
  87032. }
  87033. }
  87034. else if(bytes_per_sample == 1) {
  87035. if(channels == 2) {
  87036. for(sample = 0; sample < samples; sample++) {
  87037. a_word = signal[0][sample];
  87038. *buf_++ = (FLAC__byte)a_word;
  87039. a_word = signal[1][sample];
  87040. *buf_++ = (FLAC__byte)a_word;
  87041. }
  87042. }
  87043. else if(channels == 1) {
  87044. for(sample = 0; sample < samples; sample++) {
  87045. a_word = signal[0][sample];
  87046. *buf_++ = (FLAC__byte)a_word;
  87047. }
  87048. }
  87049. else {
  87050. for(sample = 0; sample < samples; sample++) {
  87051. for(channel = 0; channel < channels; channel++) {
  87052. a_word = signal[channel][sample];
  87053. *buf_++ = (FLAC__byte)a_word;
  87054. }
  87055. }
  87056. }
  87057. }
  87058. else { /* bytes_per_sample == 4, maybe optimize more later */
  87059. for(sample = 0; sample < samples; sample++) {
  87060. for(channel = 0; channel < channels; channel++) {
  87061. a_word = signal[channel][sample];
  87062. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  87063. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  87064. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  87065. *buf_++ = (FLAC__byte)a_word;
  87066. }
  87067. }
  87068. }
  87069. }
  87070. FLAC__bool FLAC__MD5Accumulate(FLAC__MD5Context *ctx, const FLAC__int32 * const signal[], unsigned channels, unsigned samples, unsigned bytes_per_sample)
  87071. {
  87072. const size_t bytes_needed = (size_t)channels * (size_t)samples * (size_t)bytes_per_sample;
  87073. if((size_t)channels > SIZE_MAX / (size_t)bytes_per_sample)
  87074. return false;
  87075. if((size_t)channels * (size_t)bytes_per_sample > SIZE_MAX / (size_t)samples)
  87076. return false;
  87077. if(ctx->capacity < bytes_needed) {
  87078. FLAC__byte *tmp = (FLAC__byte*)realloc(ctx->internal_buf, bytes_needed);
  87079. if(0 == tmp) {
  87080. free(ctx->internal_buf);
  87081. if(0 == (ctx->internal_buf = (FLAC__byte*)safe_malloc_(bytes_needed)))
  87082. return false;
  87083. }
  87084. ctx->internal_buf = tmp;
  87085. ctx->capacity = bytes_needed;
  87086. }
  87087. format_input_(ctx->internal_buf, signal, channels, samples, bytes_per_sample);
  87088. FLAC__MD5Update(ctx, ctx->internal_buf, bytes_needed);
  87089. return true;
  87090. }
  87091. #endif
  87092. /*** End of inlined file: md5.c ***/
  87093. /*** Start of inlined file: memory.c ***/
  87094. /*** Start of inlined file: juce_FlacHeader.h ***/
  87095. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  87096. // tasks..
  87097. #define VERSION "1.2.1"
  87098. #define FLAC__NO_DLL 1
  87099. #if JUCE_MSVC
  87100. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  87101. #endif
  87102. #if JUCE_MAC
  87103. #define FLAC__SYS_DARWIN 1
  87104. #endif
  87105. /*** End of inlined file: juce_FlacHeader.h ***/
  87106. #if JUCE_USE_FLAC
  87107. #if HAVE_CONFIG_H
  87108. # include <config.h>
  87109. #endif
  87110. /*** Start of inlined file: memory.h ***/
  87111. #ifndef FLAC__PRIVATE__MEMORY_H
  87112. #define FLAC__PRIVATE__MEMORY_H
  87113. #ifdef HAVE_CONFIG_H
  87114. #include <config.h>
  87115. #endif
  87116. #include <stdlib.h> /* for size_t */
  87117. void *FLAC__memory_alloc_aligned(size_t bytes, void **aligned_address);
  87118. FLAC__bool FLAC__memory_alloc_aligned_int32_array(unsigned elements, FLAC__int32 **unaligned_pointer, FLAC__int32 **aligned_pointer);
  87119. FLAC__bool FLAC__memory_alloc_aligned_uint32_array(unsigned elements, FLAC__uint32 **unaligned_pointer, FLAC__uint32 **aligned_pointer);
  87120. FLAC__bool FLAC__memory_alloc_aligned_uint64_array(unsigned elements, FLAC__uint64 **unaligned_pointer, FLAC__uint64 **aligned_pointer);
  87121. FLAC__bool FLAC__memory_alloc_aligned_unsigned_array(unsigned elements, unsigned **unaligned_pointer, unsigned **aligned_pointer);
  87122. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  87123. FLAC__bool FLAC__memory_alloc_aligned_real_array(unsigned elements, FLAC__real **unaligned_pointer, FLAC__real **aligned_pointer);
  87124. #endif
  87125. #endif
  87126. /*** End of inlined file: memory.h ***/
  87127. void *FLAC__memory_alloc_aligned(size_t bytes, void **aligned_address)
  87128. {
  87129. void *x;
  87130. FLAC__ASSERT(0 != aligned_address);
  87131. #ifdef FLAC__ALIGN_MALLOC_DATA
  87132. x = safe_malloc_add_2op_(bytes, /*+*/31);
  87133. #ifdef SIZEOF_VOIDP
  87134. #if SIZEOF_VOIDP == 4
  87135. *aligned_address = (void*)(((unsigned)x + 31) & -32);
  87136. #elif SIZEOF_VOIDP == 8
  87137. *aligned_address = (void*)(((FLAC__uint64)x + 31) & (FLAC__uint64)(-((FLAC__int64)32)));
  87138. #else
  87139. # error Unsupported sizeof(void*)
  87140. #endif
  87141. #else
  87142. if(sizeof(void*) == sizeof(unsigned))
  87143. *aligned_address = (void*)(((unsigned)x + 31) & -32);
  87144. else if(sizeof(void*) == sizeof(FLAC__uint64))
  87145. *aligned_address = (void*)(((FLAC__uint64)x + 31) & (FLAC__uint64)(-((FLAC__int64)32)));
  87146. else
  87147. return 0;
  87148. #endif
  87149. #else
  87150. x = safe_malloc_(bytes);
  87151. *aligned_address = x;
  87152. #endif
  87153. return x;
  87154. }
  87155. FLAC__bool FLAC__memory_alloc_aligned_int32_array(unsigned elements, FLAC__int32 **unaligned_pointer, FLAC__int32 **aligned_pointer)
  87156. {
  87157. FLAC__int32 *pu; /* unaligned pointer */
  87158. union { /* union needed to comply with C99 pointer aliasing rules */
  87159. FLAC__int32 *pa; /* aligned pointer */
  87160. void *pv; /* aligned pointer alias */
  87161. } u;
  87162. FLAC__ASSERT(elements > 0);
  87163. FLAC__ASSERT(0 != unaligned_pointer);
  87164. FLAC__ASSERT(0 != aligned_pointer);
  87165. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  87166. pu = (FLAC__int32*)FLAC__memory_alloc_aligned(sizeof(*pu) * (size_t)elements, &u.pv);
  87167. if(0 == pu) {
  87168. return false;
  87169. }
  87170. else {
  87171. if(*unaligned_pointer != 0)
  87172. free(*unaligned_pointer);
  87173. *unaligned_pointer = pu;
  87174. *aligned_pointer = u.pa;
  87175. return true;
  87176. }
  87177. }
  87178. FLAC__bool FLAC__memory_alloc_aligned_uint32_array(unsigned elements, FLAC__uint32 **unaligned_pointer, FLAC__uint32 **aligned_pointer)
  87179. {
  87180. FLAC__uint32 *pu; /* unaligned pointer */
  87181. union { /* union needed to comply with C99 pointer aliasing rules */
  87182. FLAC__uint32 *pa; /* aligned pointer */
  87183. void *pv; /* aligned pointer alias */
  87184. } u;
  87185. FLAC__ASSERT(elements > 0);
  87186. FLAC__ASSERT(0 != unaligned_pointer);
  87187. FLAC__ASSERT(0 != aligned_pointer);
  87188. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  87189. pu = (FLAC__uint32*)FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv);
  87190. if(0 == pu) {
  87191. return false;
  87192. }
  87193. else {
  87194. if(*unaligned_pointer != 0)
  87195. free(*unaligned_pointer);
  87196. *unaligned_pointer = pu;
  87197. *aligned_pointer = u.pa;
  87198. return true;
  87199. }
  87200. }
  87201. FLAC__bool FLAC__memory_alloc_aligned_uint64_array(unsigned elements, FLAC__uint64 **unaligned_pointer, FLAC__uint64 **aligned_pointer)
  87202. {
  87203. FLAC__uint64 *pu; /* unaligned pointer */
  87204. union { /* union needed to comply with C99 pointer aliasing rules */
  87205. FLAC__uint64 *pa; /* aligned pointer */
  87206. void *pv; /* aligned pointer alias */
  87207. } u;
  87208. FLAC__ASSERT(elements > 0);
  87209. FLAC__ASSERT(0 != unaligned_pointer);
  87210. FLAC__ASSERT(0 != aligned_pointer);
  87211. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  87212. pu = (FLAC__uint64*)FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv);
  87213. if(0 == pu) {
  87214. return false;
  87215. }
  87216. else {
  87217. if(*unaligned_pointer != 0)
  87218. free(*unaligned_pointer);
  87219. *unaligned_pointer = pu;
  87220. *aligned_pointer = u.pa;
  87221. return true;
  87222. }
  87223. }
  87224. FLAC__bool FLAC__memory_alloc_aligned_unsigned_array(unsigned elements, unsigned **unaligned_pointer, unsigned **aligned_pointer)
  87225. {
  87226. unsigned *pu; /* unaligned pointer */
  87227. union { /* union needed to comply with C99 pointer aliasing rules */
  87228. unsigned *pa; /* aligned pointer */
  87229. void *pv; /* aligned pointer alias */
  87230. } u;
  87231. FLAC__ASSERT(elements > 0);
  87232. FLAC__ASSERT(0 != unaligned_pointer);
  87233. FLAC__ASSERT(0 != aligned_pointer);
  87234. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  87235. pu = (unsigned*)FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv);
  87236. if(0 == pu) {
  87237. return false;
  87238. }
  87239. else {
  87240. if(*unaligned_pointer != 0)
  87241. free(*unaligned_pointer);
  87242. *unaligned_pointer = pu;
  87243. *aligned_pointer = u.pa;
  87244. return true;
  87245. }
  87246. }
  87247. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  87248. FLAC__bool FLAC__memory_alloc_aligned_real_array(unsigned elements, FLAC__real **unaligned_pointer, FLAC__real **aligned_pointer)
  87249. {
  87250. FLAC__real *pu; /* unaligned pointer */
  87251. union { /* union needed to comply with C99 pointer aliasing rules */
  87252. FLAC__real *pa; /* aligned pointer */
  87253. void *pv; /* aligned pointer alias */
  87254. } u;
  87255. FLAC__ASSERT(elements > 0);
  87256. FLAC__ASSERT(0 != unaligned_pointer);
  87257. FLAC__ASSERT(0 != aligned_pointer);
  87258. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  87259. pu = (FLAC__real*)FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv);
  87260. if(0 == pu) {
  87261. return false;
  87262. }
  87263. else {
  87264. if(*unaligned_pointer != 0)
  87265. free(*unaligned_pointer);
  87266. *unaligned_pointer = pu;
  87267. *aligned_pointer = u.pa;
  87268. return true;
  87269. }
  87270. }
  87271. #endif
  87272. #endif
  87273. /*** End of inlined file: memory.c ***/
  87274. /*** Start of inlined file: stream_decoder.c ***/
  87275. /*** Start of inlined file: juce_FlacHeader.h ***/
  87276. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  87277. // tasks..
  87278. #define VERSION "1.2.1"
  87279. #define FLAC__NO_DLL 1
  87280. #if JUCE_MSVC
  87281. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  87282. #endif
  87283. #if JUCE_MAC
  87284. #define FLAC__SYS_DARWIN 1
  87285. #endif
  87286. /*** End of inlined file: juce_FlacHeader.h ***/
  87287. #if JUCE_USE_FLAC
  87288. #if HAVE_CONFIG_H
  87289. # include <config.h>
  87290. #endif
  87291. #if defined _MSC_VER || defined __MINGW32__
  87292. #include <io.h> /* for _setmode() */
  87293. #include <fcntl.h> /* for _O_BINARY */
  87294. #endif
  87295. #if defined __CYGWIN__ || defined __EMX__
  87296. #include <io.h> /* for setmode(), O_BINARY */
  87297. #include <fcntl.h> /* for _O_BINARY */
  87298. #endif
  87299. #include <stdio.h>
  87300. #include <stdlib.h> /* for malloc() */
  87301. #include <string.h> /* for memset/memcpy() */
  87302. #include <sys/stat.h> /* for stat() */
  87303. #include <sys/types.h> /* for off_t */
  87304. #if defined _MSC_VER || defined __BORLANDC__ || defined __MINGW32__
  87305. #if _MSC_VER <= 1600 || defined __BORLANDC__ /* @@@ [2G limit] */
  87306. #define fseeko fseek
  87307. #define ftello ftell
  87308. #endif
  87309. #endif
  87310. /*** Start of inlined file: stream_decoder.h ***/
  87311. #ifndef FLAC__PROTECTED__STREAM_DECODER_H
  87312. #define FLAC__PROTECTED__STREAM_DECODER_H
  87313. #if FLAC__HAS_OGG
  87314. #include "include/private/ogg_decoder_aspect.h"
  87315. #endif
  87316. typedef struct FLAC__StreamDecoderProtected {
  87317. FLAC__StreamDecoderState state;
  87318. unsigned channels;
  87319. FLAC__ChannelAssignment channel_assignment;
  87320. unsigned bits_per_sample;
  87321. unsigned sample_rate; /* in Hz */
  87322. unsigned blocksize; /* in samples (per channel) */
  87323. FLAC__bool md5_checking; /* if true, generate MD5 signature of decoded data and compare against signature in the STREAMINFO metadata block */
  87324. #if FLAC__HAS_OGG
  87325. FLAC__OggDecoderAspect ogg_decoder_aspect;
  87326. #endif
  87327. } FLAC__StreamDecoderProtected;
  87328. unsigned FLAC__stream_decoder_get_input_bytes_unconsumed(const FLAC__StreamDecoder *decoder);
  87329. #endif
  87330. /*** End of inlined file: stream_decoder.h ***/
  87331. #ifdef max
  87332. #undef max
  87333. #endif
  87334. #define max(a,b) ((a)>(b)?(a):(b))
  87335. #ifdef _MSC_VER
  87336. #define FLAC__U64L(x) x
  87337. #else
  87338. #define FLAC__U64L(x) x##LLU
  87339. #endif
  87340. FLAC_API int FLAC_API_SUPPORTS_OGG_FLAC =
  87341. #if FLAC__HAS_OGG
  87342. 1
  87343. #else
  87344. 0
  87345. #endif
  87346. ;
  87347. static FLAC__byte ID3V2_TAG_[3] = { 'I', 'D', '3' };
  87348. static void set_defaults_dec(FLAC__StreamDecoder *decoder);
  87349. static FILE *get_binary_stdin_(void);
  87350. static FLAC__bool allocate_output_(FLAC__StreamDecoder *decoder, unsigned size, unsigned channels);
  87351. static FLAC__bool has_id_filtered_(FLAC__StreamDecoder *decoder, FLAC__byte *id);
  87352. static FLAC__bool find_metadata_(FLAC__StreamDecoder *decoder);
  87353. static FLAC__bool read_metadata_(FLAC__StreamDecoder *decoder);
  87354. static FLAC__bool read_metadata_streaminfo_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length);
  87355. static FLAC__bool read_metadata_seektable_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length);
  87356. static FLAC__bool read_metadata_vorbiscomment_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_VorbisComment *obj);
  87357. static FLAC__bool read_metadata_cuesheet_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_CueSheet *obj);
  87358. static FLAC__bool read_metadata_picture_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_Picture *obj);
  87359. static FLAC__bool skip_id3v2_tag_(FLAC__StreamDecoder *decoder);
  87360. static FLAC__bool frame_sync_(FLAC__StreamDecoder *decoder);
  87361. static FLAC__bool read_frame_(FLAC__StreamDecoder *decoder, FLAC__bool *got_a_frame, FLAC__bool do_full_decode);
  87362. static FLAC__bool read_frame_header_(FLAC__StreamDecoder *decoder);
  87363. static FLAC__bool read_subframe_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode);
  87364. static FLAC__bool read_subframe_constant_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode);
  87365. static FLAC__bool read_subframe_fixed_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode);
  87366. static FLAC__bool read_subframe_lpc_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode);
  87367. static FLAC__bool read_subframe_verbatim_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode);
  87368. 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);
  87369. static FLAC__bool read_zero_padding_(FLAC__StreamDecoder *decoder);
  87370. static FLAC__bool read_callback_(FLAC__byte buffer[], size_t *bytes, void *client_data);
  87371. #if FLAC__HAS_OGG
  87372. static FLAC__StreamDecoderReadStatus read_callback_ogg_aspect_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes);
  87373. static FLAC__OggDecoderAspectReadStatus read_callback_proxy_(const void *void_decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  87374. #endif
  87375. static FLAC__StreamDecoderWriteStatus write_audio_frame_to_client_(FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[]);
  87376. static void send_error_to_client_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status);
  87377. static FLAC__bool seek_to_absolute_sample_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample);
  87378. #if FLAC__HAS_OGG
  87379. static FLAC__bool seek_to_absolute_sample_ogg_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample);
  87380. #endif
  87381. static FLAC__StreamDecoderReadStatus file_read_callback_dec (const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  87382. static FLAC__StreamDecoderSeekStatus file_seek_callback_dec (const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  87383. static FLAC__StreamDecoderTellStatus file_tell_callback_dec (const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  87384. static FLAC__StreamDecoderLengthStatus file_length_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data);
  87385. static FLAC__bool file_eof_callback_(const FLAC__StreamDecoder *decoder, void *client_data);
  87386. typedef struct FLAC__StreamDecoderPrivate {
  87387. #if FLAC__HAS_OGG
  87388. FLAC__bool is_ogg;
  87389. #endif
  87390. FLAC__StreamDecoderReadCallback read_callback;
  87391. FLAC__StreamDecoderSeekCallback seek_callback;
  87392. FLAC__StreamDecoderTellCallback tell_callback;
  87393. FLAC__StreamDecoderLengthCallback length_callback;
  87394. FLAC__StreamDecoderEofCallback eof_callback;
  87395. FLAC__StreamDecoderWriteCallback write_callback;
  87396. FLAC__StreamDecoderMetadataCallback metadata_callback;
  87397. FLAC__StreamDecoderErrorCallback error_callback;
  87398. 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[]);
  87399. 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[]);
  87400. 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[]);
  87401. 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[]);
  87402. FLAC__bool (*local_bitreader_read_rice_signed_block)(FLAC__BitReader *br, int* vals, unsigned nvals, unsigned parameter);
  87403. void *client_data;
  87404. FILE *file; /* only used if FLAC__stream_decoder_init_file()/FLAC__stream_decoder_init_file() called, else NULL */
  87405. FLAC__BitReader *input;
  87406. FLAC__int32 *output[FLAC__MAX_CHANNELS];
  87407. FLAC__int32 *residual[FLAC__MAX_CHANNELS]; /* WATCHOUT: these are the aligned pointers; the real pointers that should be free()'d are residual_unaligned[] below */
  87408. FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents[FLAC__MAX_CHANNELS];
  87409. unsigned output_capacity, output_channels;
  87410. FLAC__uint32 fixed_block_size, next_fixed_block_size;
  87411. FLAC__uint64 samples_decoded;
  87412. FLAC__bool has_stream_info, has_seek_table;
  87413. FLAC__StreamMetadata stream_info;
  87414. FLAC__StreamMetadata seek_table;
  87415. FLAC__bool metadata_filter[128]; /* MAGIC number 128 == total number of metadata block types == 1 << 7 */
  87416. FLAC__byte *metadata_filter_ids;
  87417. size_t metadata_filter_ids_count, metadata_filter_ids_capacity; /* units for both are IDs, not bytes */
  87418. FLAC__Frame frame;
  87419. FLAC__bool cached; /* true if there is a byte in lookahead */
  87420. FLAC__CPUInfo cpuinfo;
  87421. FLAC__byte header_warmup[2]; /* contains the sync code and reserved bits */
  87422. FLAC__byte lookahead; /* temp storage when we need to look ahead one byte in the stream */
  87423. FLAC__int32 *residual_unaligned[FLAC__MAX_CHANNELS];
  87424. 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 */
  87425. FLAC__bool internal_reset_hack; /* used only during init() so we can call reset to set up the decoder without rewinding the input */
  87426. FLAC__bool is_seeking;
  87427. FLAC__MD5Context md5context;
  87428. FLAC__byte computed_md5sum[16]; /* this is the sum we computed from the decoded data */
  87429. FLAC__Frame last_frame; /* holds the info of the last frame we seeked to */
  87430. FLAC__uint64 first_frame_offset; /* hint to the seek routine of where in the stream the first audio frame starts */
  87431. FLAC__uint64 target_sample;
  87432. unsigned unparseable_frame_count; /* used to tell whether we're decoding a future version of FLAC or just got a bad sync */
  87433. #if FLAC__HAS_OGG
  87434. FLAC__bool got_a_frame; /* hack needed in Ogg FLAC seek routine to check when process_single() actually writes a frame */
  87435. #endif
  87436. } FLAC__StreamDecoderPrivate;
  87437. FLAC_API const char * const FLAC__StreamDecoderStateString[] = {
  87438. "FLAC__STREAM_DECODER_SEARCH_FOR_METADATA",
  87439. "FLAC__STREAM_DECODER_READ_METADATA",
  87440. "FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC",
  87441. "FLAC__STREAM_DECODER_READ_FRAME",
  87442. "FLAC__STREAM_DECODER_END_OF_STREAM",
  87443. "FLAC__STREAM_DECODER_OGG_ERROR",
  87444. "FLAC__STREAM_DECODER_SEEK_ERROR",
  87445. "FLAC__STREAM_DECODER_ABORTED",
  87446. "FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR",
  87447. "FLAC__STREAM_DECODER_UNINITIALIZED"
  87448. };
  87449. FLAC_API const char * const FLAC__StreamDecoderInitStatusString[] = {
  87450. "FLAC__STREAM_DECODER_INIT_STATUS_OK",
  87451. "FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER",
  87452. "FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS",
  87453. "FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR",
  87454. "FLAC__STREAM_DECODER_INIT_STATUS_ERROR_OPENING_FILE",
  87455. "FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED"
  87456. };
  87457. FLAC_API const char * const FLAC__StreamDecoderReadStatusString[] = {
  87458. "FLAC__STREAM_DECODER_READ_STATUS_CONTINUE",
  87459. "FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM",
  87460. "FLAC__STREAM_DECODER_READ_STATUS_ABORT"
  87461. };
  87462. FLAC_API const char * const FLAC__StreamDecoderSeekStatusString[] = {
  87463. "FLAC__STREAM_DECODER_SEEK_STATUS_OK",
  87464. "FLAC__STREAM_DECODER_SEEK_STATUS_ERROR",
  87465. "FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED"
  87466. };
  87467. FLAC_API const char * const FLAC__StreamDecoderTellStatusString[] = {
  87468. "FLAC__STREAM_DECODER_TELL_STATUS_OK",
  87469. "FLAC__STREAM_DECODER_TELL_STATUS_ERROR",
  87470. "FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED"
  87471. };
  87472. FLAC_API const char * const FLAC__StreamDecoderLengthStatusString[] = {
  87473. "FLAC__STREAM_DECODER_LENGTH_STATUS_OK",
  87474. "FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR",
  87475. "FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED"
  87476. };
  87477. FLAC_API const char * const FLAC__StreamDecoderWriteStatusString[] = {
  87478. "FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE",
  87479. "FLAC__STREAM_DECODER_WRITE_STATUS_ABORT"
  87480. };
  87481. FLAC_API const char * const FLAC__StreamDecoderErrorStatusString[] = {
  87482. "FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC",
  87483. "FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER",
  87484. "FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH",
  87485. "FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM"
  87486. };
  87487. FLAC_API FLAC__StreamDecoder *FLAC__stream_decoder_new(void)
  87488. {
  87489. FLAC__StreamDecoder *decoder;
  87490. unsigned i;
  87491. FLAC__ASSERT(sizeof(int) >= 4); /* we want to die right away if this is not true */
  87492. decoder = (FLAC__StreamDecoder*)calloc(1, sizeof(FLAC__StreamDecoder));
  87493. if(decoder == 0) {
  87494. return 0;
  87495. }
  87496. decoder->protected_ = (FLAC__StreamDecoderProtected*)calloc(1, sizeof(FLAC__StreamDecoderProtected));
  87497. if(decoder->protected_ == 0) {
  87498. free(decoder);
  87499. return 0;
  87500. }
  87501. decoder->private_ = (FLAC__StreamDecoderPrivate*)calloc(1, sizeof(FLAC__StreamDecoderPrivate));
  87502. if(decoder->private_ == 0) {
  87503. free(decoder->protected_);
  87504. free(decoder);
  87505. return 0;
  87506. }
  87507. decoder->private_->input = FLAC__bitreader_new();
  87508. if(decoder->private_->input == 0) {
  87509. free(decoder->private_);
  87510. free(decoder->protected_);
  87511. free(decoder);
  87512. return 0;
  87513. }
  87514. decoder->private_->metadata_filter_ids_capacity = 16;
  87515. if(0 == (decoder->private_->metadata_filter_ids = (FLAC__byte*)malloc((FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8) * decoder->private_->metadata_filter_ids_capacity))) {
  87516. FLAC__bitreader_delete(decoder->private_->input);
  87517. free(decoder->private_);
  87518. free(decoder->protected_);
  87519. free(decoder);
  87520. return 0;
  87521. }
  87522. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  87523. decoder->private_->output[i] = 0;
  87524. decoder->private_->residual_unaligned[i] = decoder->private_->residual[i] = 0;
  87525. }
  87526. decoder->private_->output_capacity = 0;
  87527. decoder->private_->output_channels = 0;
  87528. decoder->private_->has_seek_table = false;
  87529. for(i = 0; i < FLAC__MAX_CHANNELS; i++)
  87530. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&decoder->private_->partitioned_rice_contents[i]);
  87531. decoder->private_->file = 0;
  87532. set_defaults_dec(decoder);
  87533. decoder->protected_->state = FLAC__STREAM_DECODER_UNINITIALIZED;
  87534. return decoder;
  87535. }
  87536. FLAC_API void FLAC__stream_decoder_delete(FLAC__StreamDecoder *decoder)
  87537. {
  87538. unsigned i;
  87539. FLAC__ASSERT(0 != decoder);
  87540. FLAC__ASSERT(0 != decoder->protected_);
  87541. FLAC__ASSERT(0 != decoder->private_);
  87542. FLAC__ASSERT(0 != decoder->private_->input);
  87543. (void)FLAC__stream_decoder_finish(decoder);
  87544. if(0 != decoder->private_->metadata_filter_ids)
  87545. free(decoder->private_->metadata_filter_ids);
  87546. FLAC__bitreader_delete(decoder->private_->input);
  87547. for(i = 0; i < FLAC__MAX_CHANNELS; i++)
  87548. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&decoder->private_->partitioned_rice_contents[i]);
  87549. free(decoder->private_);
  87550. free(decoder->protected_);
  87551. free(decoder);
  87552. }
  87553. static FLAC__StreamDecoderInitStatus init_stream_internal_dec(
  87554. FLAC__StreamDecoder *decoder,
  87555. FLAC__StreamDecoderReadCallback read_callback,
  87556. FLAC__StreamDecoderSeekCallback seek_callback,
  87557. FLAC__StreamDecoderTellCallback tell_callback,
  87558. FLAC__StreamDecoderLengthCallback length_callback,
  87559. FLAC__StreamDecoderEofCallback eof_callback,
  87560. FLAC__StreamDecoderWriteCallback write_callback,
  87561. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87562. FLAC__StreamDecoderErrorCallback error_callback,
  87563. void *client_data,
  87564. FLAC__bool is_ogg
  87565. )
  87566. {
  87567. FLAC__ASSERT(0 != decoder);
  87568. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87569. return FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED;
  87570. #if !FLAC__HAS_OGG
  87571. if(is_ogg)
  87572. return FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER;
  87573. #endif
  87574. if(
  87575. 0 == read_callback ||
  87576. 0 == write_callback ||
  87577. 0 == error_callback ||
  87578. (seek_callback && (0 == tell_callback || 0 == length_callback || 0 == eof_callback))
  87579. )
  87580. return FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS;
  87581. #if FLAC__HAS_OGG
  87582. decoder->private_->is_ogg = is_ogg;
  87583. if(is_ogg && !FLAC__ogg_decoder_aspect_init(&decoder->protected_->ogg_decoder_aspect))
  87584. return decoder->protected_->state = FLAC__STREAM_DECODER_OGG_ERROR;
  87585. #endif
  87586. FLAC__cpu_info(&decoder->private_->cpuinfo);
  87587. decoder->private_->local_lpc_restore_signal = FLAC__lpc_restore_signal;
  87588. decoder->private_->local_lpc_restore_signal_64bit = FLAC__lpc_restore_signal_wide;
  87589. decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal;
  87590. decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal;
  87591. decoder->private_->local_bitreader_read_rice_signed_block = FLAC__bitreader_read_rice_signed_block;
  87592. #ifndef FLAC__NO_ASM
  87593. if(decoder->private_->cpuinfo.use_asm) {
  87594. #ifdef FLAC__CPU_IA32
  87595. FLAC__ASSERT(decoder->private_->cpuinfo.type == FLAC__CPUINFO_TYPE_IA32);
  87596. #ifdef FLAC__HAS_NASM
  87597. #if 1 /*@@@@@@ OPT: not clearly faster, needs more testing */
  87598. if(decoder->private_->cpuinfo.data.ia32.bswap)
  87599. decoder->private_->local_bitreader_read_rice_signed_block = FLAC__bitreader_read_rice_signed_block_asm_ia32_bswap;
  87600. #endif
  87601. if(decoder->private_->cpuinfo.data.ia32.mmx) {
  87602. decoder->private_->local_lpc_restore_signal = FLAC__lpc_restore_signal_asm_ia32;
  87603. decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal_asm_ia32_mmx;
  87604. decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal_asm_ia32_mmx;
  87605. }
  87606. else {
  87607. decoder->private_->local_lpc_restore_signal = FLAC__lpc_restore_signal_asm_ia32;
  87608. decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal_asm_ia32;
  87609. decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal_asm_ia32;
  87610. }
  87611. #endif
  87612. #elif defined FLAC__CPU_PPC
  87613. FLAC__ASSERT(decoder->private_->cpuinfo.type == FLAC__CPUINFO_TYPE_PPC);
  87614. if(decoder->private_->cpuinfo.data.ppc.altivec) {
  87615. decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal_asm_ppc_altivec_16;
  87616. decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal_asm_ppc_altivec_16_order8;
  87617. }
  87618. #endif
  87619. }
  87620. #endif
  87621. if(!FLAC__bitreader_init(decoder->private_->input, decoder->private_->cpuinfo, read_callback_, decoder)) {
  87622. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87623. return FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR;
  87624. }
  87625. decoder->private_->read_callback = read_callback;
  87626. decoder->private_->seek_callback = seek_callback;
  87627. decoder->private_->tell_callback = tell_callback;
  87628. decoder->private_->length_callback = length_callback;
  87629. decoder->private_->eof_callback = eof_callback;
  87630. decoder->private_->write_callback = write_callback;
  87631. decoder->private_->metadata_callback = metadata_callback;
  87632. decoder->private_->error_callback = error_callback;
  87633. decoder->private_->client_data = client_data;
  87634. decoder->private_->fixed_block_size = decoder->private_->next_fixed_block_size = 0;
  87635. decoder->private_->samples_decoded = 0;
  87636. decoder->private_->has_stream_info = false;
  87637. decoder->private_->cached = false;
  87638. decoder->private_->do_md5_checking = decoder->protected_->md5_checking;
  87639. decoder->private_->is_seeking = false;
  87640. decoder->private_->internal_reset_hack = true; /* so the following reset does not try to rewind the input */
  87641. if(!FLAC__stream_decoder_reset(decoder)) {
  87642. return FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR;
  87643. }
  87644. return FLAC__STREAM_DECODER_INIT_STATUS_OK;
  87645. }
  87646. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_stream(
  87647. FLAC__StreamDecoder *decoder,
  87648. FLAC__StreamDecoderReadCallback read_callback,
  87649. FLAC__StreamDecoderSeekCallback seek_callback,
  87650. FLAC__StreamDecoderTellCallback tell_callback,
  87651. FLAC__StreamDecoderLengthCallback length_callback,
  87652. FLAC__StreamDecoderEofCallback eof_callback,
  87653. FLAC__StreamDecoderWriteCallback write_callback,
  87654. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87655. FLAC__StreamDecoderErrorCallback error_callback,
  87656. void *client_data
  87657. )
  87658. {
  87659. return init_stream_internal_dec(
  87660. decoder,
  87661. read_callback,
  87662. seek_callback,
  87663. tell_callback,
  87664. length_callback,
  87665. eof_callback,
  87666. write_callback,
  87667. metadata_callback,
  87668. error_callback,
  87669. client_data,
  87670. false
  87671. );
  87672. }
  87673. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_stream(
  87674. FLAC__StreamDecoder *decoder,
  87675. FLAC__StreamDecoderReadCallback read_callback,
  87676. FLAC__StreamDecoderSeekCallback seek_callback,
  87677. FLAC__StreamDecoderTellCallback tell_callback,
  87678. FLAC__StreamDecoderLengthCallback length_callback,
  87679. FLAC__StreamDecoderEofCallback eof_callback,
  87680. FLAC__StreamDecoderWriteCallback write_callback,
  87681. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87682. FLAC__StreamDecoderErrorCallback error_callback,
  87683. void *client_data
  87684. )
  87685. {
  87686. return init_stream_internal_dec(
  87687. decoder,
  87688. read_callback,
  87689. seek_callback,
  87690. tell_callback,
  87691. length_callback,
  87692. eof_callback,
  87693. write_callback,
  87694. metadata_callback,
  87695. error_callback,
  87696. client_data,
  87697. true
  87698. );
  87699. }
  87700. static FLAC__StreamDecoderInitStatus init_FILE_internal_(
  87701. FLAC__StreamDecoder *decoder,
  87702. FILE *file,
  87703. FLAC__StreamDecoderWriteCallback write_callback,
  87704. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87705. FLAC__StreamDecoderErrorCallback error_callback,
  87706. void *client_data,
  87707. FLAC__bool is_ogg
  87708. )
  87709. {
  87710. FLAC__ASSERT(0 != decoder);
  87711. FLAC__ASSERT(0 != file);
  87712. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87713. return (FLAC__StreamDecoderInitStatus) (decoder->protected_->state = (FLAC__StreamDecoderState) FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED);
  87714. if(0 == write_callback || 0 == error_callback)
  87715. return (FLAC__StreamDecoderInitStatus) (decoder->protected_->state = (FLAC__StreamDecoderState) FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS);
  87716. if(file == stdin)
  87717. file = get_binary_stdin_(); /* just to be safe */
  87718. decoder->private_->file = file;
  87719. return init_stream_internal_dec(
  87720. decoder,
  87721. file_read_callback_dec,
  87722. decoder->private_->file == stdin? 0: file_seek_callback_dec,
  87723. decoder->private_->file == stdin? 0: file_tell_callback_dec,
  87724. decoder->private_->file == stdin? 0: file_length_callback_,
  87725. file_eof_callback_,
  87726. write_callback,
  87727. metadata_callback,
  87728. error_callback,
  87729. client_data,
  87730. is_ogg
  87731. );
  87732. }
  87733. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_FILE(
  87734. FLAC__StreamDecoder *decoder,
  87735. FILE *file,
  87736. FLAC__StreamDecoderWriteCallback write_callback,
  87737. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87738. FLAC__StreamDecoderErrorCallback error_callback,
  87739. void *client_data
  87740. )
  87741. {
  87742. return init_FILE_internal_(decoder, file, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/false);
  87743. }
  87744. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_FILE(
  87745. FLAC__StreamDecoder *decoder,
  87746. FILE *file,
  87747. FLAC__StreamDecoderWriteCallback write_callback,
  87748. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87749. FLAC__StreamDecoderErrorCallback error_callback,
  87750. void *client_data
  87751. )
  87752. {
  87753. return init_FILE_internal_(decoder, file, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/true);
  87754. }
  87755. static FLAC__StreamDecoderInitStatus init_file_internal_(
  87756. FLAC__StreamDecoder *decoder,
  87757. const char *filename,
  87758. FLAC__StreamDecoderWriteCallback write_callback,
  87759. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87760. FLAC__StreamDecoderErrorCallback error_callback,
  87761. void *client_data,
  87762. FLAC__bool is_ogg
  87763. )
  87764. {
  87765. FILE *file;
  87766. FLAC__ASSERT(0 != decoder);
  87767. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87768. return (FLAC__StreamDecoderInitStatus) (decoder->protected_->state = (FLAC__StreamDecoderState) FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED);
  87769. if(0 == write_callback || 0 == error_callback)
  87770. return (FLAC__StreamDecoderInitStatus) (decoder->protected_->state = (FLAC__StreamDecoderState) FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS);
  87771. file = filename? fopen(filename, "rb") : stdin;
  87772. if(0 == file)
  87773. return FLAC__STREAM_DECODER_INIT_STATUS_ERROR_OPENING_FILE;
  87774. return init_FILE_internal_(decoder, file, write_callback, metadata_callback, error_callback, client_data, is_ogg);
  87775. }
  87776. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_file(
  87777. FLAC__StreamDecoder *decoder,
  87778. const char *filename,
  87779. FLAC__StreamDecoderWriteCallback write_callback,
  87780. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87781. FLAC__StreamDecoderErrorCallback error_callback,
  87782. void *client_data
  87783. )
  87784. {
  87785. return init_file_internal_(decoder, filename, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/false);
  87786. }
  87787. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_file(
  87788. FLAC__StreamDecoder *decoder,
  87789. const char *filename,
  87790. FLAC__StreamDecoderWriteCallback write_callback,
  87791. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87792. FLAC__StreamDecoderErrorCallback error_callback,
  87793. void *client_data
  87794. )
  87795. {
  87796. return init_file_internal_(decoder, filename, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/true);
  87797. }
  87798. FLAC_API FLAC__bool FLAC__stream_decoder_finish(FLAC__StreamDecoder *decoder)
  87799. {
  87800. FLAC__bool md5_failed = false;
  87801. unsigned i;
  87802. FLAC__ASSERT(0 != decoder);
  87803. FLAC__ASSERT(0 != decoder->private_);
  87804. FLAC__ASSERT(0 != decoder->protected_);
  87805. if(decoder->protected_->state == FLAC__STREAM_DECODER_UNINITIALIZED)
  87806. return true;
  87807. FLAC__MD5Final(decoder->private_->computed_md5sum, &decoder->private_->md5context);
  87808. if(decoder->private_->has_seek_table && 0 != decoder->private_->seek_table.data.seek_table.points) {
  87809. free(decoder->private_->seek_table.data.seek_table.points);
  87810. decoder->private_->seek_table.data.seek_table.points = 0;
  87811. decoder->private_->has_seek_table = false;
  87812. }
  87813. FLAC__bitreader_free(decoder->private_->input);
  87814. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  87815. if(0 != decoder->private_->output[i]) {
  87816. free(decoder->private_->output[i]-4);
  87817. decoder->private_->output[i] = 0;
  87818. }
  87819. if(0 != decoder->private_->residual_unaligned[i]) {
  87820. free(decoder->private_->residual_unaligned[i]);
  87821. decoder->private_->residual_unaligned[i] = decoder->private_->residual[i] = 0;
  87822. }
  87823. }
  87824. decoder->private_->output_capacity = 0;
  87825. decoder->private_->output_channels = 0;
  87826. #if FLAC__HAS_OGG
  87827. if(decoder->private_->is_ogg)
  87828. FLAC__ogg_decoder_aspect_finish(&decoder->protected_->ogg_decoder_aspect);
  87829. #endif
  87830. if(0 != decoder->private_->file) {
  87831. if(decoder->private_->file != stdin)
  87832. fclose(decoder->private_->file);
  87833. decoder->private_->file = 0;
  87834. }
  87835. if(decoder->private_->do_md5_checking) {
  87836. if(memcmp(decoder->private_->stream_info.data.stream_info.md5sum, decoder->private_->computed_md5sum, 16))
  87837. md5_failed = true;
  87838. }
  87839. decoder->private_->is_seeking = false;
  87840. set_defaults_dec(decoder);
  87841. decoder->protected_->state = FLAC__STREAM_DECODER_UNINITIALIZED;
  87842. return !md5_failed;
  87843. }
  87844. FLAC_API FLAC__bool FLAC__stream_decoder_set_ogg_serial_number(FLAC__StreamDecoder *decoder, long value)
  87845. {
  87846. FLAC__ASSERT(0 != decoder);
  87847. FLAC__ASSERT(0 != decoder->private_);
  87848. FLAC__ASSERT(0 != decoder->protected_);
  87849. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87850. return false;
  87851. #if FLAC__HAS_OGG
  87852. FLAC__ogg_decoder_aspect_set_serial_number(&decoder->protected_->ogg_decoder_aspect, value);
  87853. return true;
  87854. #else
  87855. (void)value;
  87856. return false;
  87857. #endif
  87858. }
  87859. FLAC_API FLAC__bool FLAC__stream_decoder_set_md5_checking(FLAC__StreamDecoder *decoder, FLAC__bool value)
  87860. {
  87861. FLAC__ASSERT(0 != decoder);
  87862. FLAC__ASSERT(0 != decoder->protected_);
  87863. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87864. return false;
  87865. decoder->protected_->md5_checking = value;
  87866. return true;
  87867. }
  87868. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond(FLAC__StreamDecoder *decoder, FLAC__MetadataType type)
  87869. {
  87870. FLAC__ASSERT(0 != decoder);
  87871. FLAC__ASSERT(0 != decoder->private_);
  87872. FLAC__ASSERT(0 != decoder->protected_);
  87873. FLAC__ASSERT((unsigned)type <= FLAC__MAX_METADATA_TYPE_CODE);
  87874. if((unsigned)type > FLAC__MAX_METADATA_TYPE_CODE)
  87875. return false;
  87876. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87877. return false;
  87878. decoder->private_->metadata_filter[type] = true;
  87879. if(type == FLAC__METADATA_TYPE_APPLICATION)
  87880. decoder->private_->metadata_filter_ids_count = 0;
  87881. return true;
  87882. }
  87883. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4])
  87884. {
  87885. FLAC__ASSERT(0 != decoder);
  87886. FLAC__ASSERT(0 != decoder->private_);
  87887. FLAC__ASSERT(0 != decoder->protected_);
  87888. FLAC__ASSERT(0 != id);
  87889. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87890. return false;
  87891. if(decoder->private_->metadata_filter[FLAC__METADATA_TYPE_APPLICATION])
  87892. return true;
  87893. FLAC__ASSERT(0 != decoder->private_->metadata_filter_ids);
  87894. if(decoder->private_->metadata_filter_ids_count == decoder->private_->metadata_filter_ids_capacity) {
  87895. 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))) {
  87896. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87897. return false;
  87898. }
  87899. decoder->private_->metadata_filter_ids_capacity *= 2;
  87900. }
  87901. 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));
  87902. decoder->private_->metadata_filter_ids_count++;
  87903. return true;
  87904. }
  87905. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_all(FLAC__StreamDecoder *decoder)
  87906. {
  87907. unsigned i;
  87908. FLAC__ASSERT(0 != decoder);
  87909. FLAC__ASSERT(0 != decoder->private_);
  87910. FLAC__ASSERT(0 != decoder->protected_);
  87911. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87912. return false;
  87913. for(i = 0; i < sizeof(decoder->private_->metadata_filter) / sizeof(decoder->private_->metadata_filter[0]); i++)
  87914. decoder->private_->metadata_filter[i] = true;
  87915. decoder->private_->metadata_filter_ids_count = 0;
  87916. return true;
  87917. }
  87918. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore(FLAC__StreamDecoder *decoder, FLAC__MetadataType type)
  87919. {
  87920. FLAC__ASSERT(0 != decoder);
  87921. FLAC__ASSERT(0 != decoder->private_);
  87922. FLAC__ASSERT(0 != decoder->protected_);
  87923. FLAC__ASSERT((unsigned)type <= FLAC__MAX_METADATA_TYPE_CODE);
  87924. if((unsigned)type > FLAC__MAX_METADATA_TYPE_CODE)
  87925. return false;
  87926. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87927. return false;
  87928. decoder->private_->metadata_filter[type] = false;
  87929. if(type == FLAC__METADATA_TYPE_APPLICATION)
  87930. decoder->private_->metadata_filter_ids_count = 0;
  87931. return true;
  87932. }
  87933. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4])
  87934. {
  87935. FLAC__ASSERT(0 != decoder);
  87936. FLAC__ASSERT(0 != decoder->private_);
  87937. FLAC__ASSERT(0 != decoder->protected_);
  87938. FLAC__ASSERT(0 != id);
  87939. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87940. return false;
  87941. if(!decoder->private_->metadata_filter[FLAC__METADATA_TYPE_APPLICATION])
  87942. return true;
  87943. FLAC__ASSERT(0 != decoder->private_->metadata_filter_ids);
  87944. if(decoder->private_->metadata_filter_ids_count == decoder->private_->metadata_filter_ids_capacity) {
  87945. 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))) {
  87946. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87947. return false;
  87948. }
  87949. decoder->private_->metadata_filter_ids_capacity *= 2;
  87950. }
  87951. 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));
  87952. decoder->private_->metadata_filter_ids_count++;
  87953. return true;
  87954. }
  87955. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_all(FLAC__StreamDecoder *decoder)
  87956. {
  87957. FLAC__ASSERT(0 != decoder);
  87958. FLAC__ASSERT(0 != decoder->private_);
  87959. FLAC__ASSERT(0 != decoder->protected_);
  87960. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87961. return false;
  87962. memset(decoder->private_->metadata_filter, 0, sizeof(decoder->private_->metadata_filter));
  87963. decoder->private_->metadata_filter_ids_count = 0;
  87964. return true;
  87965. }
  87966. FLAC_API FLAC__StreamDecoderState FLAC__stream_decoder_get_state(const FLAC__StreamDecoder *decoder)
  87967. {
  87968. FLAC__ASSERT(0 != decoder);
  87969. FLAC__ASSERT(0 != decoder->protected_);
  87970. return decoder->protected_->state;
  87971. }
  87972. FLAC_API const char *FLAC__stream_decoder_get_resolved_state_string(const FLAC__StreamDecoder *decoder)
  87973. {
  87974. return FLAC__StreamDecoderStateString[decoder->protected_->state];
  87975. }
  87976. FLAC_API FLAC__bool FLAC__stream_decoder_get_md5_checking(const FLAC__StreamDecoder *decoder)
  87977. {
  87978. FLAC__ASSERT(0 != decoder);
  87979. FLAC__ASSERT(0 != decoder->protected_);
  87980. return decoder->protected_->md5_checking;
  87981. }
  87982. FLAC_API FLAC__uint64 FLAC__stream_decoder_get_total_samples(const FLAC__StreamDecoder *decoder)
  87983. {
  87984. FLAC__ASSERT(0 != decoder);
  87985. FLAC__ASSERT(0 != decoder->protected_);
  87986. return decoder->private_->has_stream_info? decoder->private_->stream_info.data.stream_info.total_samples : 0;
  87987. }
  87988. FLAC_API unsigned FLAC__stream_decoder_get_channels(const FLAC__StreamDecoder *decoder)
  87989. {
  87990. FLAC__ASSERT(0 != decoder);
  87991. FLAC__ASSERT(0 != decoder->protected_);
  87992. return decoder->protected_->channels;
  87993. }
  87994. FLAC_API FLAC__ChannelAssignment FLAC__stream_decoder_get_channel_assignment(const FLAC__StreamDecoder *decoder)
  87995. {
  87996. FLAC__ASSERT(0 != decoder);
  87997. FLAC__ASSERT(0 != decoder->protected_);
  87998. return decoder->protected_->channel_assignment;
  87999. }
  88000. FLAC_API unsigned FLAC__stream_decoder_get_bits_per_sample(const FLAC__StreamDecoder *decoder)
  88001. {
  88002. FLAC__ASSERT(0 != decoder);
  88003. FLAC__ASSERT(0 != decoder->protected_);
  88004. return decoder->protected_->bits_per_sample;
  88005. }
  88006. FLAC_API unsigned FLAC__stream_decoder_get_sample_rate(const FLAC__StreamDecoder *decoder)
  88007. {
  88008. FLAC__ASSERT(0 != decoder);
  88009. FLAC__ASSERT(0 != decoder->protected_);
  88010. return decoder->protected_->sample_rate;
  88011. }
  88012. FLAC_API unsigned FLAC__stream_decoder_get_blocksize(const FLAC__StreamDecoder *decoder)
  88013. {
  88014. FLAC__ASSERT(0 != decoder);
  88015. FLAC__ASSERT(0 != decoder->protected_);
  88016. return decoder->protected_->blocksize;
  88017. }
  88018. FLAC_API FLAC__bool FLAC__stream_decoder_get_decode_position(const FLAC__StreamDecoder *decoder, FLAC__uint64 *position)
  88019. {
  88020. FLAC__ASSERT(0 != decoder);
  88021. FLAC__ASSERT(0 != decoder->private_);
  88022. FLAC__ASSERT(0 != position);
  88023. #if FLAC__HAS_OGG
  88024. if(decoder->private_->is_ogg)
  88025. return false;
  88026. #endif
  88027. if(0 == decoder->private_->tell_callback)
  88028. return false;
  88029. if(decoder->private_->tell_callback(decoder, position, decoder->private_->client_data) != FLAC__STREAM_DECODER_TELL_STATUS_OK)
  88030. return false;
  88031. if(!FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input))
  88032. return false;
  88033. FLAC__ASSERT(*position >= FLAC__stream_decoder_get_input_bytes_unconsumed(decoder));
  88034. *position -= FLAC__stream_decoder_get_input_bytes_unconsumed(decoder);
  88035. return true;
  88036. }
  88037. FLAC_API FLAC__bool FLAC__stream_decoder_flush(FLAC__StreamDecoder *decoder)
  88038. {
  88039. FLAC__ASSERT(0 != decoder);
  88040. FLAC__ASSERT(0 != decoder->private_);
  88041. FLAC__ASSERT(0 != decoder->protected_);
  88042. decoder->private_->samples_decoded = 0;
  88043. decoder->private_->do_md5_checking = false;
  88044. #if FLAC__HAS_OGG
  88045. if(decoder->private_->is_ogg)
  88046. FLAC__ogg_decoder_aspect_flush(&decoder->protected_->ogg_decoder_aspect);
  88047. #endif
  88048. if(!FLAC__bitreader_clear(decoder->private_->input)) {
  88049. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88050. return false;
  88051. }
  88052. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88053. return true;
  88054. }
  88055. FLAC_API FLAC__bool FLAC__stream_decoder_reset(FLAC__StreamDecoder *decoder)
  88056. {
  88057. FLAC__ASSERT(0 != decoder);
  88058. FLAC__ASSERT(0 != decoder->private_);
  88059. FLAC__ASSERT(0 != decoder->protected_);
  88060. if(!FLAC__stream_decoder_flush(decoder)) {
  88061. return false;
  88062. }
  88063. #if FLAC__HAS_OGG
  88064. if(decoder->private_->is_ogg)
  88065. FLAC__ogg_decoder_aspect_reset(&decoder->protected_->ogg_decoder_aspect);
  88066. #endif
  88067. if(!decoder->private_->internal_reset_hack) {
  88068. if(decoder->private_->file == stdin)
  88069. return false; /* can't rewind stdin, reset fails */
  88070. if(decoder->private_->seek_callback && decoder->private_->seek_callback(decoder, 0, decoder->private_->client_data) == FLAC__STREAM_DECODER_SEEK_STATUS_ERROR)
  88071. return false; /* seekable and seek fails, reset fails */
  88072. }
  88073. else
  88074. decoder->private_->internal_reset_hack = false;
  88075. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_METADATA;
  88076. decoder->private_->has_stream_info = false;
  88077. if(decoder->private_->has_seek_table && 0 != decoder->private_->seek_table.data.seek_table.points) {
  88078. free(decoder->private_->seek_table.data.seek_table.points);
  88079. decoder->private_->seek_table.data.seek_table.points = 0;
  88080. decoder->private_->has_seek_table = false;
  88081. }
  88082. decoder->private_->do_md5_checking = decoder->protected_->md5_checking;
  88083. decoder->private_->fixed_block_size = decoder->private_->next_fixed_block_size = 0;
  88084. FLAC__MD5Init(&decoder->private_->md5context);
  88085. decoder->private_->first_frame_offset = 0;
  88086. decoder->private_->unparseable_frame_count = 0;
  88087. return true;
  88088. }
  88089. FLAC_API FLAC__bool FLAC__stream_decoder_process_single(FLAC__StreamDecoder *decoder)
  88090. {
  88091. FLAC__bool got_a_frame;
  88092. FLAC__ASSERT(0 != decoder);
  88093. FLAC__ASSERT(0 != decoder->protected_);
  88094. while(1) {
  88095. switch(decoder->protected_->state) {
  88096. case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
  88097. if(!find_metadata_(decoder))
  88098. return false; /* above function sets the status for us */
  88099. break;
  88100. case FLAC__STREAM_DECODER_READ_METADATA:
  88101. if(!read_metadata_(decoder))
  88102. return false; /* above function sets the status for us */
  88103. else
  88104. return true;
  88105. case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
  88106. if(!frame_sync_(decoder))
  88107. return true; /* above function sets the status for us */
  88108. break;
  88109. case FLAC__STREAM_DECODER_READ_FRAME:
  88110. if(!read_frame_(decoder, &got_a_frame, /*do_full_decode=*/true))
  88111. return false; /* above function sets the status for us */
  88112. if(got_a_frame)
  88113. return true; /* above function sets the status for us */
  88114. break;
  88115. case FLAC__STREAM_DECODER_END_OF_STREAM:
  88116. case FLAC__STREAM_DECODER_ABORTED:
  88117. return true;
  88118. default:
  88119. FLAC__ASSERT(0);
  88120. return false;
  88121. }
  88122. }
  88123. }
  88124. FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_metadata(FLAC__StreamDecoder *decoder)
  88125. {
  88126. FLAC__ASSERT(0 != decoder);
  88127. FLAC__ASSERT(0 != decoder->protected_);
  88128. while(1) {
  88129. switch(decoder->protected_->state) {
  88130. case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
  88131. if(!find_metadata_(decoder))
  88132. return false; /* above function sets the status for us */
  88133. break;
  88134. case FLAC__STREAM_DECODER_READ_METADATA:
  88135. if(!read_metadata_(decoder))
  88136. return false; /* above function sets the status for us */
  88137. break;
  88138. case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
  88139. case FLAC__STREAM_DECODER_READ_FRAME:
  88140. case FLAC__STREAM_DECODER_END_OF_STREAM:
  88141. case FLAC__STREAM_DECODER_ABORTED:
  88142. return true;
  88143. default:
  88144. FLAC__ASSERT(0);
  88145. return false;
  88146. }
  88147. }
  88148. }
  88149. FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_stream(FLAC__StreamDecoder *decoder)
  88150. {
  88151. FLAC__bool dummy;
  88152. FLAC__ASSERT(0 != decoder);
  88153. FLAC__ASSERT(0 != decoder->protected_);
  88154. while(1) {
  88155. switch(decoder->protected_->state) {
  88156. case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
  88157. if(!find_metadata_(decoder))
  88158. return false; /* above function sets the status for us */
  88159. break;
  88160. case FLAC__STREAM_DECODER_READ_METADATA:
  88161. if(!read_metadata_(decoder))
  88162. return false; /* above function sets the status for us */
  88163. break;
  88164. case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
  88165. if(!frame_sync_(decoder))
  88166. return true; /* above function sets the status for us */
  88167. break;
  88168. case FLAC__STREAM_DECODER_READ_FRAME:
  88169. if(!read_frame_(decoder, &dummy, /*do_full_decode=*/true))
  88170. return false; /* 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_skip_single_frame(FLAC__StreamDecoder *decoder)
  88182. {
  88183. FLAC__bool got_a_frame;
  88184. FLAC__ASSERT(0 != decoder);
  88185. FLAC__ASSERT(0 != decoder->protected_);
  88186. while(1) {
  88187. switch(decoder->protected_->state) {
  88188. case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
  88189. case FLAC__STREAM_DECODER_READ_METADATA:
  88190. return false; /* above function sets the status for us */
  88191. case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
  88192. if(!frame_sync_(decoder))
  88193. return true; /* above function sets the status for us */
  88194. break;
  88195. case FLAC__STREAM_DECODER_READ_FRAME:
  88196. if(!read_frame_(decoder, &got_a_frame, /*do_full_decode=*/false))
  88197. return false; /* above function sets the status for us */
  88198. if(got_a_frame)
  88199. return true; /* above function sets the status for us */
  88200. break;
  88201. case FLAC__STREAM_DECODER_END_OF_STREAM:
  88202. case FLAC__STREAM_DECODER_ABORTED:
  88203. return true;
  88204. default:
  88205. FLAC__ASSERT(0);
  88206. return false;
  88207. }
  88208. }
  88209. }
  88210. FLAC_API FLAC__bool FLAC__stream_decoder_seek_absolute(FLAC__StreamDecoder *decoder, FLAC__uint64 sample)
  88211. {
  88212. FLAC__uint64 length;
  88213. FLAC__ASSERT(0 != decoder);
  88214. if(
  88215. decoder->protected_->state != FLAC__STREAM_DECODER_SEARCH_FOR_METADATA &&
  88216. decoder->protected_->state != FLAC__STREAM_DECODER_READ_METADATA &&
  88217. decoder->protected_->state != FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC &&
  88218. decoder->protected_->state != FLAC__STREAM_DECODER_READ_FRAME &&
  88219. decoder->protected_->state != FLAC__STREAM_DECODER_END_OF_STREAM
  88220. )
  88221. return false;
  88222. if(0 == decoder->private_->seek_callback)
  88223. return false;
  88224. FLAC__ASSERT(decoder->private_->seek_callback);
  88225. FLAC__ASSERT(decoder->private_->tell_callback);
  88226. FLAC__ASSERT(decoder->private_->length_callback);
  88227. FLAC__ASSERT(decoder->private_->eof_callback);
  88228. if(FLAC__stream_decoder_get_total_samples(decoder) > 0 && sample >= FLAC__stream_decoder_get_total_samples(decoder))
  88229. return false;
  88230. decoder->private_->is_seeking = true;
  88231. decoder->private_->do_md5_checking = false;
  88232. if(decoder->private_->length_callback(decoder, &length, decoder->private_->client_data) != FLAC__STREAM_DECODER_LENGTH_STATUS_OK) {
  88233. decoder->private_->is_seeking = false;
  88234. return false;
  88235. }
  88236. if(
  88237. decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_METADATA ||
  88238. decoder->protected_->state == FLAC__STREAM_DECODER_READ_METADATA
  88239. ) {
  88240. if(!FLAC__stream_decoder_process_until_end_of_metadata(decoder)) {
  88241. decoder->private_->is_seeking = false;
  88242. return false;
  88243. }
  88244. if(FLAC__stream_decoder_get_total_samples(decoder) > 0 && sample >= FLAC__stream_decoder_get_total_samples(decoder)) {
  88245. decoder->private_->is_seeking = false;
  88246. return false;
  88247. }
  88248. }
  88249. {
  88250. const FLAC__bool ok =
  88251. #if FLAC__HAS_OGG
  88252. decoder->private_->is_ogg?
  88253. seek_to_absolute_sample_ogg_(decoder, length, sample) :
  88254. #endif
  88255. seek_to_absolute_sample_(decoder, length, sample)
  88256. ;
  88257. decoder->private_->is_seeking = false;
  88258. return ok;
  88259. }
  88260. }
  88261. unsigned FLAC__stream_decoder_get_input_bytes_unconsumed(const FLAC__StreamDecoder *decoder)
  88262. {
  88263. FLAC__ASSERT(0 != decoder);
  88264. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88265. FLAC__ASSERT(!(FLAC__bitreader_get_input_bits_unconsumed(decoder->private_->input) & 7));
  88266. return FLAC__bitreader_get_input_bits_unconsumed(decoder->private_->input) / 8;
  88267. }
  88268. void set_defaults_dec(FLAC__StreamDecoder *decoder)
  88269. {
  88270. #if FLAC__HAS_OGG
  88271. decoder->private_->is_ogg = false;
  88272. #endif
  88273. decoder->private_->read_callback = 0;
  88274. decoder->private_->seek_callback = 0;
  88275. decoder->private_->tell_callback = 0;
  88276. decoder->private_->length_callback = 0;
  88277. decoder->private_->eof_callback = 0;
  88278. decoder->private_->write_callback = 0;
  88279. decoder->private_->metadata_callback = 0;
  88280. decoder->private_->error_callback = 0;
  88281. decoder->private_->client_data = 0;
  88282. memset(decoder->private_->metadata_filter, 0, sizeof(decoder->private_->metadata_filter));
  88283. decoder->private_->metadata_filter[FLAC__METADATA_TYPE_STREAMINFO] = true;
  88284. decoder->private_->metadata_filter_ids_count = 0;
  88285. decoder->protected_->md5_checking = false;
  88286. #if FLAC__HAS_OGG
  88287. FLAC__ogg_decoder_aspect_set_defaults(&decoder->protected_->ogg_decoder_aspect);
  88288. #endif
  88289. }
  88290. FILE *get_binary_stdin_(void)
  88291. {
  88292. #if defined _MSC_VER || defined __MINGW32__
  88293. _setmode(_fileno(stdin), _O_BINARY);
  88294. #elif defined __CYGWIN__
  88295. setmode(_fileno(stdin), _O_BINARY);
  88296. #elif defined __EMX__
  88297. setmode(fileno(stdin), O_BINARY);
  88298. #endif
  88299. return stdin;
  88300. }
  88301. FLAC__bool allocate_output_(FLAC__StreamDecoder *decoder, unsigned size, unsigned channels)
  88302. {
  88303. unsigned i;
  88304. FLAC__int32 *tmp;
  88305. if(size <= decoder->private_->output_capacity && channels <= decoder->private_->output_channels)
  88306. return true;
  88307. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  88308. if(0 != decoder->private_->output[i]) {
  88309. free(decoder->private_->output[i]-4);
  88310. decoder->private_->output[i] = 0;
  88311. }
  88312. if(0 != decoder->private_->residual_unaligned[i]) {
  88313. free(decoder->private_->residual_unaligned[i]);
  88314. decoder->private_->residual_unaligned[i] = decoder->private_->residual[i] = 0;
  88315. }
  88316. }
  88317. for(i = 0; i < channels; i++) {
  88318. tmp = (FLAC__int32*)safe_malloc_muladd2_(sizeof(FLAC__int32), /*times (*/size, /*+*/4/*)*/);
  88319. if(tmp == 0) {
  88320. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88321. return false;
  88322. }
  88323. memset(tmp, 0, sizeof(FLAC__int32)*4);
  88324. decoder->private_->output[i] = tmp + 4;
  88325. if(!FLAC__memory_alloc_aligned_int32_array(size, &decoder->private_->residual_unaligned[i], &decoder->private_->residual[i])) {
  88326. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88327. return false;
  88328. }
  88329. }
  88330. decoder->private_->output_capacity = size;
  88331. decoder->private_->output_channels = channels;
  88332. return true;
  88333. }
  88334. FLAC__bool has_id_filtered_(FLAC__StreamDecoder *decoder, FLAC__byte *id)
  88335. {
  88336. size_t i;
  88337. FLAC__ASSERT(0 != decoder);
  88338. FLAC__ASSERT(0 != decoder->private_);
  88339. for(i = 0; i < decoder->private_->metadata_filter_ids_count; i++)
  88340. if(0 == memcmp(decoder->private_->metadata_filter_ids + i * (FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8), id, (FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8)))
  88341. return true;
  88342. return false;
  88343. }
  88344. FLAC__bool find_metadata_(FLAC__StreamDecoder *decoder)
  88345. {
  88346. FLAC__uint32 x;
  88347. unsigned i, id_;
  88348. FLAC__bool first = true;
  88349. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88350. for(i = id_ = 0; i < 4; ) {
  88351. if(decoder->private_->cached) {
  88352. x = (FLAC__uint32)decoder->private_->lookahead;
  88353. decoder->private_->cached = false;
  88354. }
  88355. else {
  88356. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88357. return false; /* read_callback_ sets the state for us */
  88358. }
  88359. if(x == FLAC__STREAM_SYNC_STRING[i]) {
  88360. first = true;
  88361. i++;
  88362. id_ = 0;
  88363. continue;
  88364. }
  88365. if(x == ID3V2_TAG_[id_]) {
  88366. id_++;
  88367. i = 0;
  88368. if(id_ == 3) {
  88369. if(!skip_id3v2_tag_(decoder))
  88370. return false; /* skip_id3v2_tag_ sets the state for us */
  88371. }
  88372. continue;
  88373. }
  88374. id_ = 0;
  88375. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  88376. decoder->private_->header_warmup[0] = (FLAC__byte)x;
  88377. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88378. return false; /* read_callback_ sets the state for us */
  88379. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  88380. decoder->private_->lookahead = (FLAC__byte)x;
  88381. decoder->private_->cached = true;
  88382. }
  88383. else if(x >> 2 == 0x3e) { /* MAGIC NUMBER for the last 6 sync bits */
  88384. decoder->private_->header_warmup[1] = (FLAC__byte)x;
  88385. decoder->protected_->state = FLAC__STREAM_DECODER_READ_FRAME;
  88386. return true;
  88387. }
  88388. }
  88389. i = 0;
  88390. if(first) {
  88391. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  88392. first = false;
  88393. }
  88394. }
  88395. decoder->protected_->state = FLAC__STREAM_DECODER_READ_METADATA;
  88396. return true;
  88397. }
  88398. FLAC__bool read_metadata_(FLAC__StreamDecoder *decoder)
  88399. {
  88400. FLAC__bool is_last;
  88401. FLAC__uint32 i, x, type, length;
  88402. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88403. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_IS_LAST_LEN))
  88404. return false; /* read_callback_ sets the state for us */
  88405. is_last = x? true : false;
  88406. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &type, FLAC__STREAM_METADATA_TYPE_LEN))
  88407. return false; /* read_callback_ sets the state for us */
  88408. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &length, FLAC__STREAM_METADATA_LENGTH_LEN))
  88409. return false; /* read_callback_ sets the state for us */
  88410. if(type == FLAC__METADATA_TYPE_STREAMINFO) {
  88411. if(!read_metadata_streaminfo_(decoder, is_last, length))
  88412. return false;
  88413. decoder->private_->has_stream_info = true;
  88414. 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))
  88415. decoder->private_->do_md5_checking = false;
  88416. if(!decoder->private_->is_seeking && decoder->private_->metadata_filter[FLAC__METADATA_TYPE_STREAMINFO] && decoder->private_->metadata_callback)
  88417. decoder->private_->metadata_callback(decoder, &decoder->private_->stream_info, decoder->private_->client_data);
  88418. }
  88419. else if(type == FLAC__METADATA_TYPE_SEEKTABLE) {
  88420. if(!read_metadata_seektable_(decoder, is_last, length))
  88421. return false;
  88422. decoder->private_->has_seek_table = true;
  88423. if(!decoder->private_->is_seeking && decoder->private_->metadata_filter[FLAC__METADATA_TYPE_SEEKTABLE] && decoder->private_->metadata_callback)
  88424. decoder->private_->metadata_callback(decoder, &decoder->private_->seek_table, decoder->private_->client_data);
  88425. }
  88426. else {
  88427. FLAC__bool skip_it = !decoder->private_->metadata_filter[type];
  88428. unsigned real_length = length;
  88429. FLAC__StreamMetadata block;
  88430. block.is_last = is_last;
  88431. block.type = (FLAC__MetadataType)type;
  88432. block.length = length;
  88433. if(type == FLAC__METADATA_TYPE_APPLICATION) {
  88434. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, block.data.application.id, FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8))
  88435. return false; /* read_callback_ sets the state for us */
  88436. if(real_length < FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8) { /* underflow check */
  88437. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;/*@@@@@@ maybe wrong error? need to resync?*/
  88438. return false;
  88439. }
  88440. real_length -= FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8;
  88441. if(decoder->private_->metadata_filter_ids_count > 0 && has_id_filtered_(decoder, block.data.application.id))
  88442. skip_it = !skip_it;
  88443. }
  88444. if(skip_it) {
  88445. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, real_length))
  88446. return false; /* read_callback_ sets the state for us */
  88447. }
  88448. else {
  88449. switch(type) {
  88450. case FLAC__METADATA_TYPE_PADDING:
  88451. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, real_length))
  88452. return false; /* read_callback_ sets the state for us */
  88453. break;
  88454. case FLAC__METADATA_TYPE_APPLICATION:
  88455. if(real_length > 0) {
  88456. if(0 == (block.data.application.data = (FLAC__byte*)malloc(real_length))) {
  88457. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88458. return false;
  88459. }
  88460. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, block.data.application.data, real_length))
  88461. return false; /* read_callback_ sets the state for us */
  88462. }
  88463. else
  88464. block.data.application.data = 0;
  88465. break;
  88466. case FLAC__METADATA_TYPE_VORBIS_COMMENT:
  88467. if(!read_metadata_vorbiscomment_(decoder, &block.data.vorbis_comment))
  88468. return false;
  88469. break;
  88470. case FLAC__METADATA_TYPE_CUESHEET:
  88471. if(!read_metadata_cuesheet_(decoder, &block.data.cue_sheet))
  88472. return false;
  88473. break;
  88474. case FLAC__METADATA_TYPE_PICTURE:
  88475. if(!read_metadata_picture_(decoder, &block.data.picture))
  88476. return false;
  88477. break;
  88478. case FLAC__METADATA_TYPE_STREAMINFO:
  88479. case FLAC__METADATA_TYPE_SEEKTABLE:
  88480. FLAC__ASSERT(0);
  88481. break;
  88482. default:
  88483. if(real_length > 0) {
  88484. if(0 == (block.data.unknown.data = (FLAC__byte*)malloc(real_length))) {
  88485. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88486. return false;
  88487. }
  88488. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, block.data.unknown.data, real_length))
  88489. return false; /* read_callback_ sets the state for us */
  88490. }
  88491. else
  88492. block.data.unknown.data = 0;
  88493. break;
  88494. }
  88495. if(!decoder->private_->is_seeking && decoder->private_->metadata_callback)
  88496. decoder->private_->metadata_callback(decoder, &block, decoder->private_->client_data);
  88497. switch(type) {
  88498. case FLAC__METADATA_TYPE_PADDING:
  88499. break;
  88500. case FLAC__METADATA_TYPE_APPLICATION:
  88501. if(0 != block.data.application.data)
  88502. free(block.data.application.data);
  88503. break;
  88504. case FLAC__METADATA_TYPE_VORBIS_COMMENT:
  88505. if(0 != block.data.vorbis_comment.vendor_string.entry)
  88506. free(block.data.vorbis_comment.vendor_string.entry);
  88507. if(block.data.vorbis_comment.num_comments > 0)
  88508. for(i = 0; i < block.data.vorbis_comment.num_comments; i++)
  88509. if(0 != block.data.vorbis_comment.comments[i].entry)
  88510. free(block.data.vorbis_comment.comments[i].entry);
  88511. if(0 != block.data.vorbis_comment.comments)
  88512. free(block.data.vorbis_comment.comments);
  88513. break;
  88514. case FLAC__METADATA_TYPE_CUESHEET:
  88515. if(block.data.cue_sheet.num_tracks > 0)
  88516. for(i = 0; i < block.data.cue_sheet.num_tracks; i++)
  88517. if(0 != block.data.cue_sheet.tracks[i].indices)
  88518. free(block.data.cue_sheet.tracks[i].indices);
  88519. if(0 != block.data.cue_sheet.tracks)
  88520. free(block.data.cue_sheet.tracks);
  88521. break;
  88522. case FLAC__METADATA_TYPE_PICTURE:
  88523. if(0 != block.data.picture.mime_type)
  88524. free(block.data.picture.mime_type);
  88525. if(0 != block.data.picture.description)
  88526. free(block.data.picture.description);
  88527. if(0 != block.data.picture.data)
  88528. free(block.data.picture.data);
  88529. break;
  88530. case FLAC__METADATA_TYPE_STREAMINFO:
  88531. case FLAC__METADATA_TYPE_SEEKTABLE:
  88532. FLAC__ASSERT(0);
  88533. default:
  88534. if(0 != block.data.unknown.data)
  88535. free(block.data.unknown.data);
  88536. break;
  88537. }
  88538. }
  88539. }
  88540. if(is_last) {
  88541. if(!FLAC__stream_decoder_get_decode_position(decoder, &decoder->private_->first_frame_offset))
  88542. decoder->private_->first_frame_offset = 0;
  88543. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88544. }
  88545. return true;
  88546. }
  88547. FLAC__bool read_metadata_streaminfo_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length)
  88548. {
  88549. FLAC__uint32 x;
  88550. unsigned bits, used_bits = 0;
  88551. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88552. decoder->private_->stream_info.type = FLAC__METADATA_TYPE_STREAMINFO;
  88553. decoder->private_->stream_info.is_last = is_last;
  88554. decoder->private_->stream_info.length = length;
  88555. bits = FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN;
  88556. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, bits))
  88557. return false; /* read_callback_ sets the state for us */
  88558. decoder->private_->stream_info.data.stream_info.min_blocksize = x;
  88559. used_bits += bits;
  88560. bits = FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN;
  88561. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN))
  88562. return false; /* read_callback_ sets the state for us */
  88563. decoder->private_->stream_info.data.stream_info.max_blocksize = x;
  88564. used_bits += bits;
  88565. bits = FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN;
  88566. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN))
  88567. return false; /* read_callback_ sets the state for us */
  88568. decoder->private_->stream_info.data.stream_info.min_framesize = x;
  88569. used_bits += bits;
  88570. bits = FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN;
  88571. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN))
  88572. return false; /* read_callback_ sets the state for us */
  88573. decoder->private_->stream_info.data.stream_info.max_framesize = x;
  88574. used_bits += bits;
  88575. bits = FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN;
  88576. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN))
  88577. return false; /* read_callback_ sets the state for us */
  88578. decoder->private_->stream_info.data.stream_info.sample_rate = x;
  88579. used_bits += bits;
  88580. bits = FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN;
  88581. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN))
  88582. return false; /* read_callback_ sets the state for us */
  88583. decoder->private_->stream_info.data.stream_info.channels = x+1;
  88584. used_bits += bits;
  88585. bits = FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN;
  88586. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN))
  88587. return false; /* read_callback_ sets the state for us */
  88588. decoder->private_->stream_info.data.stream_info.bits_per_sample = x+1;
  88589. used_bits += bits;
  88590. bits = FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN;
  88591. 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))
  88592. return false; /* read_callback_ sets the state for us */
  88593. used_bits += bits;
  88594. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, decoder->private_->stream_info.data.stream_info.md5sum, 16))
  88595. return false; /* read_callback_ sets the state for us */
  88596. used_bits += 16*8;
  88597. FLAC__ASSERT(used_bits % 8 == 0);
  88598. length -= (used_bits / 8);
  88599. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, length))
  88600. return false; /* read_callback_ sets the state for us */
  88601. return true;
  88602. }
  88603. FLAC__bool read_metadata_seektable_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length)
  88604. {
  88605. FLAC__uint32 i, x;
  88606. FLAC__uint64 xx;
  88607. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88608. decoder->private_->seek_table.type = FLAC__METADATA_TYPE_SEEKTABLE;
  88609. decoder->private_->seek_table.is_last = is_last;
  88610. decoder->private_->seek_table.length = length;
  88611. decoder->private_->seek_table.data.seek_table.num_points = length / FLAC__STREAM_METADATA_SEEKPOINT_LENGTH;
  88612. 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)))) {
  88613. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88614. return false;
  88615. }
  88616. for(i = 0; i < decoder->private_->seek_table.data.seek_table.num_points; i++) {
  88617. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &xx, FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN))
  88618. return false; /* read_callback_ sets the state for us */
  88619. decoder->private_->seek_table.data.seek_table.points[i].sample_number = xx;
  88620. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &xx, FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN))
  88621. return false; /* read_callback_ sets the state for us */
  88622. decoder->private_->seek_table.data.seek_table.points[i].stream_offset = xx;
  88623. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN))
  88624. return false; /* read_callback_ sets the state for us */
  88625. decoder->private_->seek_table.data.seek_table.points[i].frame_samples = x;
  88626. }
  88627. length -= (decoder->private_->seek_table.data.seek_table.num_points * FLAC__STREAM_METADATA_SEEKPOINT_LENGTH);
  88628. if(length > 0) {
  88629. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, length))
  88630. return false; /* read_callback_ sets the state for us */
  88631. }
  88632. return true;
  88633. }
  88634. FLAC__bool read_metadata_vorbiscomment_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_VorbisComment *obj)
  88635. {
  88636. FLAC__uint32 i;
  88637. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88638. FLAC__ASSERT(FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN == 32);
  88639. if(!FLAC__bitreader_read_uint32_little_endian(decoder->private_->input, &obj->vendor_string.length))
  88640. return false; /* read_callback_ sets the state for us */
  88641. if(obj->vendor_string.length > 0) {
  88642. if(0 == (obj->vendor_string.entry = (FLAC__byte*)safe_malloc_add_2op_(obj->vendor_string.length, /*+*/1))) {
  88643. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88644. return false;
  88645. }
  88646. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->vendor_string.entry, obj->vendor_string.length))
  88647. return false; /* read_callback_ sets the state for us */
  88648. obj->vendor_string.entry[obj->vendor_string.length] = '\0';
  88649. }
  88650. else
  88651. obj->vendor_string.entry = 0;
  88652. FLAC__ASSERT(FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN == 32);
  88653. if(!FLAC__bitreader_read_uint32_little_endian(decoder->private_->input, &obj->num_comments))
  88654. return false; /* read_callback_ sets the state for us */
  88655. if(obj->num_comments > 0) {
  88656. if(0 == (obj->comments = (FLAC__StreamMetadata_VorbisComment_Entry*)safe_malloc_mul_2op_(obj->num_comments, /*times*/sizeof(FLAC__StreamMetadata_VorbisComment_Entry)))) {
  88657. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88658. return false;
  88659. }
  88660. for(i = 0; i < obj->num_comments; i++) {
  88661. FLAC__ASSERT(FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN == 32);
  88662. if(!FLAC__bitreader_read_uint32_little_endian(decoder->private_->input, &obj->comments[i].length))
  88663. return false; /* read_callback_ sets the state for us */
  88664. if(obj->comments[i].length > 0) {
  88665. if(0 == (obj->comments[i].entry = (FLAC__byte*)safe_malloc_add_2op_(obj->comments[i].length, /*+*/1))) {
  88666. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88667. return false;
  88668. }
  88669. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->comments[i].entry, obj->comments[i].length))
  88670. return false; /* read_callback_ sets the state for us */
  88671. obj->comments[i].entry[obj->comments[i].length] = '\0';
  88672. }
  88673. else
  88674. obj->comments[i].entry = 0;
  88675. }
  88676. }
  88677. else {
  88678. obj->comments = 0;
  88679. }
  88680. return true;
  88681. }
  88682. FLAC__bool read_metadata_cuesheet_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_CueSheet *obj)
  88683. {
  88684. FLAC__uint32 i, j, x;
  88685. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88686. memset(obj, 0, sizeof(FLAC__StreamMetadata_CueSheet));
  88687. FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN % 8 == 0);
  88688. 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))
  88689. return false; /* read_callback_ sets the state for us */
  88690. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &obj->lead_in, FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN))
  88691. return false; /* read_callback_ sets the state for us */
  88692. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN))
  88693. return false; /* read_callback_ sets the state for us */
  88694. obj->is_cd = x? true : false;
  88695. if(!FLAC__bitreader_skip_bits_no_crc(decoder->private_->input, FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN))
  88696. return false; /* read_callback_ sets the state for us */
  88697. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN))
  88698. return false; /* read_callback_ sets the state for us */
  88699. obj->num_tracks = x;
  88700. if(obj->num_tracks > 0) {
  88701. if(0 == (obj->tracks = (FLAC__StreamMetadata_CueSheet_Track*)safe_calloc_(obj->num_tracks, sizeof(FLAC__StreamMetadata_CueSheet_Track)))) {
  88702. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88703. return false;
  88704. }
  88705. for(i = 0; i < obj->num_tracks; i++) {
  88706. FLAC__StreamMetadata_CueSheet_Track *track = &obj->tracks[i];
  88707. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &track->offset, FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN))
  88708. return false; /* read_callback_ sets the state for us */
  88709. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN))
  88710. return false; /* read_callback_ sets the state for us */
  88711. track->number = (FLAC__byte)x;
  88712. FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN % 8 == 0);
  88713. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, (FLAC__byte*)track->isrc, FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN/8))
  88714. return false; /* read_callback_ sets the state for us */
  88715. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN))
  88716. return false; /* read_callback_ sets the state for us */
  88717. track->type = x;
  88718. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN))
  88719. return false; /* read_callback_ sets the state for us */
  88720. track->pre_emphasis = x;
  88721. if(!FLAC__bitreader_skip_bits_no_crc(decoder->private_->input, FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN))
  88722. return false; /* read_callback_ sets the state for us */
  88723. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN))
  88724. return false; /* read_callback_ sets the state for us */
  88725. track->num_indices = (FLAC__byte)x;
  88726. if(track->num_indices > 0) {
  88727. if(0 == (track->indices = (FLAC__StreamMetadata_CueSheet_Index*)safe_calloc_(track->num_indices, sizeof(FLAC__StreamMetadata_CueSheet_Index)))) {
  88728. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88729. return false;
  88730. }
  88731. for(j = 0; j < track->num_indices; j++) {
  88732. FLAC__StreamMetadata_CueSheet_Index *index = &track->indices[j];
  88733. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &index->offset, FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN))
  88734. return false; /* read_callback_ sets the state for us */
  88735. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN))
  88736. return false; /* read_callback_ sets the state for us */
  88737. index->number = (FLAC__byte)x;
  88738. if(!FLAC__bitreader_skip_bits_no_crc(decoder->private_->input, FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN))
  88739. return false; /* read_callback_ sets the state for us */
  88740. }
  88741. }
  88742. }
  88743. }
  88744. return true;
  88745. }
  88746. FLAC__bool read_metadata_picture_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_Picture *obj)
  88747. {
  88748. FLAC__uint32 x;
  88749. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88750. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_PICTURE_TYPE_LEN))
  88751. return false; /* read_callback_ sets the state for us */
  88752. obj->type = (FLAC__StreamMetadata_Picture_Type) x;
  88753. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN))
  88754. return false; /* read_callback_ sets the state for us */
  88755. if(0 == (obj->mime_type = (char*)safe_malloc_add_2op_(x, /*+*/1))) {
  88756. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88757. return false;
  88758. }
  88759. if(x > 0) {
  88760. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, (FLAC__byte*)obj->mime_type, x))
  88761. return false; /* read_callback_ sets the state for us */
  88762. }
  88763. obj->mime_type[x] = '\0';
  88764. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN))
  88765. return false; /* read_callback_ sets the state for us */
  88766. if(0 == (obj->description = (FLAC__byte*)safe_malloc_add_2op_(x, /*+*/1))) {
  88767. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88768. return false;
  88769. }
  88770. if(x > 0) {
  88771. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->description, x))
  88772. return false; /* read_callback_ sets the state for us */
  88773. }
  88774. obj->description[x] = '\0';
  88775. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->width, FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN))
  88776. return false; /* read_callback_ sets the state for us */
  88777. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->height, FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN))
  88778. return false; /* read_callback_ sets the state for us */
  88779. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->depth, FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN))
  88780. return false; /* read_callback_ sets the state for us */
  88781. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->colors, FLAC__STREAM_METADATA_PICTURE_COLORS_LEN))
  88782. return false; /* read_callback_ sets the state for us */
  88783. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &(obj->data_length), FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN))
  88784. return false; /* read_callback_ sets the state for us */
  88785. if(0 == (obj->data = (FLAC__byte*)safe_malloc_(obj->data_length))) {
  88786. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88787. return false;
  88788. }
  88789. if(obj->data_length > 0) {
  88790. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->data, obj->data_length))
  88791. return false; /* read_callback_ sets the state for us */
  88792. }
  88793. return true;
  88794. }
  88795. FLAC__bool skip_id3v2_tag_(FLAC__StreamDecoder *decoder)
  88796. {
  88797. FLAC__uint32 x;
  88798. unsigned i, skip;
  88799. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 24))
  88800. return false; /* read_callback_ sets the state for us */
  88801. skip = 0;
  88802. for(i = 0; i < 4; i++) {
  88803. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88804. return false; /* read_callback_ sets the state for us */
  88805. skip <<= 7;
  88806. skip |= (x & 0x7f);
  88807. }
  88808. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, skip))
  88809. return false; /* read_callback_ sets the state for us */
  88810. return true;
  88811. }
  88812. FLAC__bool frame_sync_(FLAC__StreamDecoder *decoder)
  88813. {
  88814. FLAC__uint32 x;
  88815. FLAC__bool first = true;
  88816. if(FLAC__stream_decoder_get_total_samples(decoder) > 0) {
  88817. if(decoder->private_->samples_decoded >= FLAC__stream_decoder_get_total_samples(decoder)) {
  88818. decoder->protected_->state = FLAC__STREAM_DECODER_END_OF_STREAM;
  88819. return true;
  88820. }
  88821. }
  88822. if(!FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input)) {
  88823. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__bitreader_bits_left_for_byte_alignment(decoder->private_->input)))
  88824. return false; /* read_callback_ sets the state for us */
  88825. }
  88826. while(1) {
  88827. if(decoder->private_->cached) {
  88828. x = (FLAC__uint32)decoder->private_->lookahead;
  88829. decoder->private_->cached = false;
  88830. }
  88831. else {
  88832. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88833. return false; /* read_callback_ sets the state for us */
  88834. }
  88835. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  88836. decoder->private_->header_warmup[0] = (FLAC__byte)x;
  88837. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88838. return false; /* read_callback_ sets the state for us */
  88839. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  88840. decoder->private_->lookahead = (FLAC__byte)x;
  88841. decoder->private_->cached = true;
  88842. }
  88843. else if(x >> 2 == 0x3e) { /* MAGIC NUMBER for the last 6 sync bits */
  88844. decoder->private_->header_warmup[1] = (FLAC__byte)x;
  88845. decoder->protected_->state = FLAC__STREAM_DECODER_READ_FRAME;
  88846. return true;
  88847. }
  88848. }
  88849. if(first) {
  88850. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  88851. first = false;
  88852. }
  88853. }
  88854. return true;
  88855. }
  88856. FLAC__bool read_frame_(FLAC__StreamDecoder *decoder, FLAC__bool *got_a_frame, FLAC__bool do_full_decode)
  88857. {
  88858. unsigned channel;
  88859. unsigned i;
  88860. FLAC__int32 mid, side;
  88861. unsigned frame_crc; /* the one we calculate from the input stream */
  88862. FLAC__uint32 x;
  88863. *got_a_frame = false;
  88864. frame_crc = 0;
  88865. frame_crc = FLAC__CRC16_UPDATE(decoder->private_->header_warmup[0], frame_crc);
  88866. frame_crc = FLAC__CRC16_UPDATE(decoder->private_->header_warmup[1], frame_crc);
  88867. FLAC__bitreader_reset_read_crc16(decoder->private_->input, (FLAC__uint16)frame_crc);
  88868. if(!read_frame_header_(decoder))
  88869. return false;
  88870. if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means we didn't sync on a valid header */
  88871. return true;
  88872. if(!allocate_output_(decoder, decoder->private_->frame.header.blocksize, decoder->private_->frame.header.channels))
  88873. return false;
  88874. for(channel = 0; channel < decoder->private_->frame.header.channels; channel++) {
  88875. unsigned bps = decoder->private_->frame.header.bits_per_sample;
  88876. switch(decoder->private_->frame.header.channel_assignment) {
  88877. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  88878. break;
  88879. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  88880. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88881. if(channel == 1)
  88882. bps++;
  88883. break;
  88884. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  88885. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88886. if(channel == 0)
  88887. bps++;
  88888. break;
  88889. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  88890. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88891. if(channel == 1)
  88892. bps++;
  88893. break;
  88894. default:
  88895. FLAC__ASSERT(0);
  88896. }
  88897. if(!read_subframe_(decoder, channel, bps, do_full_decode))
  88898. return false;
  88899. if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means bad sync or got corruption */
  88900. return true;
  88901. }
  88902. if(!read_zero_padding_(decoder))
  88903. return false;
  88904. 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) */
  88905. return true;
  88906. frame_crc = FLAC__bitreader_get_read_crc16(decoder->private_->input);
  88907. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__FRAME_FOOTER_CRC_LEN))
  88908. return false; /* read_callback_ sets the state for us */
  88909. if(frame_crc == x) {
  88910. if(do_full_decode) {
  88911. switch(decoder->private_->frame.header.channel_assignment) {
  88912. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  88913. break;
  88914. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  88915. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88916. for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
  88917. decoder->private_->output[1][i] = decoder->private_->output[0][i] - decoder->private_->output[1][i];
  88918. break;
  88919. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  88920. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88921. for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
  88922. decoder->private_->output[0][i] += decoder->private_->output[1][i];
  88923. break;
  88924. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  88925. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88926. for(i = 0; i < decoder->private_->frame.header.blocksize; i++) {
  88927. #if 1
  88928. mid = decoder->private_->output[0][i];
  88929. side = decoder->private_->output[1][i];
  88930. mid <<= 1;
  88931. mid |= (side & 1); /* i.e. if 'side' is odd... */
  88932. decoder->private_->output[0][i] = (mid + side) >> 1;
  88933. decoder->private_->output[1][i] = (mid - side) >> 1;
  88934. #else
  88935. mid = (decoder->private_->output[0][i] << 1) | (decoder->private_->output[1][i] & 1); /* i.e. if 'side' is odd... */
  88936. decoder->private_->output[0][i] = (mid + decoder->private_->output[1][i]) >> 1;
  88937. decoder->private_->output[1][i] = (mid - decoder->private_->output[1][i]) >> 1;
  88938. #endif
  88939. }
  88940. break;
  88941. default:
  88942. FLAC__ASSERT(0);
  88943. break;
  88944. }
  88945. }
  88946. }
  88947. else {
  88948. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH);
  88949. if(do_full_decode) {
  88950. for(channel = 0; channel < decoder->private_->frame.header.channels; channel++) {
  88951. memset(decoder->private_->output[channel], 0, sizeof(FLAC__int32) * decoder->private_->frame.header.blocksize);
  88952. }
  88953. }
  88954. }
  88955. *got_a_frame = true;
  88956. if(decoder->private_->next_fixed_block_size)
  88957. decoder->private_->fixed_block_size = decoder->private_->next_fixed_block_size;
  88958. decoder->protected_->channels = decoder->private_->frame.header.channels;
  88959. decoder->protected_->channel_assignment = decoder->private_->frame.header.channel_assignment;
  88960. decoder->protected_->bits_per_sample = decoder->private_->frame.header.bits_per_sample;
  88961. decoder->protected_->sample_rate = decoder->private_->frame.header.sample_rate;
  88962. decoder->protected_->blocksize = decoder->private_->frame.header.blocksize;
  88963. FLAC__ASSERT(decoder->private_->frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  88964. decoder->private_->samples_decoded = decoder->private_->frame.header.number.sample_number + decoder->private_->frame.header.blocksize;
  88965. if(do_full_decode) {
  88966. if(write_audio_frame_to_client_(decoder, &decoder->private_->frame, (const FLAC__int32 * const *)decoder->private_->output) != FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE)
  88967. return false;
  88968. }
  88969. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88970. return true;
  88971. }
  88972. FLAC__bool read_frame_header_(FLAC__StreamDecoder *decoder)
  88973. {
  88974. FLAC__uint32 x;
  88975. FLAC__uint64 xx;
  88976. unsigned i, blocksize_hint = 0, sample_rate_hint = 0;
  88977. FLAC__byte crc8, raw_header[16]; /* MAGIC NUMBER based on the maximum frame header size, including CRC */
  88978. unsigned raw_header_len;
  88979. FLAC__bool is_unparseable = false;
  88980. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88981. raw_header[0] = decoder->private_->header_warmup[0];
  88982. raw_header[1] = decoder->private_->header_warmup[1];
  88983. raw_header_len = 2;
  88984. if(raw_header[1] & 0x02) /* MAGIC NUMBER */
  88985. is_unparseable = true;
  88986. for(i = 0; i < 2; i++) {
  88987. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88988. return false; /* read_callback_ sets the state for us */
  88989. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  88990. decoder->private_->lookahead = (FLAC__byte)x;
  88991. decoder->private_->cached = true;
  88992. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  88993. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88994. return true;
  88995. }
  88996. raw_header[raw_header_len++] = (FLAC__byte)x;
  88997. }
  88998. switch(x = raw_header[2] >> 4) {
  88999. case 0:
  89000. is_unparseable = true;
  89001. break;
  89002. case 1:
  89003. decoder->private_->frame.header.blocksize = 192;
  89004. break;
  89005. case 2:
  89006. case 3:
  89007. case 4:
  89008. case 5:
  89009. decoder->private_->frame.header.blocksize = 576 << (x-2);
  89010. break;
  89011. case 6:
  89012. case 7:
  89013. blocksize_hint = x;
  89014. break;
  89015. case 8:
  89016. case 9:
  89017. case 10:
  89018. case 11:
  89019. case 12:
  89020. case 13:
  89021. case 14:
  89022. case 15:
  89023. decoder->private_->frame.header.blocksize = 256 << (x-8);
  89024. break;
  89025. default:
  89026. FLAC__ASSERT(0);
  89027. break;
  89028. }
  89029. switch(x = raw_header[2] & 0x0f) {
  89030. case 0:
  89031. if(decoder->private_->has_stream_info)
  89032. decoder->private_->frame.header.sample_rate = decoder->private_->stream_info.data.stream_info.sample_rate;
  89033. else
  89034. is_unparseable = true;
  89035. break;
  89036. case 1:
  89037. decoder->private_->frame.header.sample_rate = 88200;
  89038. break;
  89039. case 2:
  89040. decoder->private_->frame.header.sample_rate = 176400;
  89041. break;
  89042. case 3:
  89043. decoder->private_->frame.header.sample_rate = 192000;
  89044. break;
  89045. case 4:
  89046. decoder->private_->frame.header.sample_rate = 8000;
  89047. break;
  89048. case 5:
  89049. decoder->private_->frame.header.sample_rate = 16000;
  89050. break;
  89051. case 6:
  89052. decoder->private_->frame.header.sample_rate = 22050;
  89053. break;
  89054. case 7:
  89055. decoder->private_->frame.header.sample_rate = 24000;
  89056. break;
  89057. case 8:
  89058. decoder->private_->frame.header.sample_rate = 32000;
  89059. break;
  89060. case 9:
  89061. decoder->private_->frame.header.sample_rate = 44100;
  89062. break;
  89063. case 10:
  89064. decoder->private_->frame.header.sample_rate = 48000;
  89065. break;
  89066. case 11:
  89067. decoder->private_->frame.header.sample_rate = 96000;
  89068. break;
  89069. case 12:
  89070. case 13:
  89071. case 14:
  89072. sample_rate_hint = x;
  89073. break;
  89074. case 15:
  89075. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  89076. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89077. return true;
  89078. default:
  89079. FLAC__ASSERT(0);
  89080. }
  89081. x = (unsigned)(raw_header[3] >> 4);
  89082. if(x & 8) {
  89083. decoder->private_->frame.header.channels = 2;
  89084. switch(x & 7) {
  89085. case 0:
  89086. decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE;
  89087. break;
  89088. case 1:
  89089. decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE;
  89090. break;
  89091. case 2:
  89092. decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_MID_SIDE;
  89093. break;
  89094. default:
  89095. is_unparseable = true;
  89096. break;
  89097. }
  89098. }
  89099. else {
  89100. decoder->private_->frame.header.channels = (unsigned)x + 1;
  89101. decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT;
  89102. }
  89103. switch(x = (unsigned)(raw_header[3] & 0x0e) >> 1) {
  89104. case 0:
  89105. if(decoder->private_->has_stream_info)
  89106. decoder->private_->frame.header.bits_per_sample = decoder->private_->stream_info.data.stream_info.bits_per_sample;
  89107. else
  89108. is_unparseable = true;
  89109. break;
  89110. case 1:
  89111. decoder->private_->frame.header.bits_per_sample = 8;
  89112. break;
  89113. case 2:
  89114. decoder->private_->frame.header.bits_per_sample = 12;
  89115. break;
  89116. case 4:
  89117. decoder->private_->frame.header.bits_per_sample = 16;
  89118. break;
  89119. case 5:
  89120. decoder->private_->frame.header.bits_per_sample = 20;
  89121. break;
  89122. case 6:
  89123. decoder->private_->frame.header.bits_per_sample = 24;
  89124. break;
  89125. case 3:
  89126. case 7:
  89127. is_unparseable = true;
  89128. break;
  89129. default:
  89130. FLAC__ASSERT(0);
  89131. break;
  89132. }
  89133. if(raw_header[3] & 0x01) /* MAGIC NUMBER */
  89134. is_unparseable = true;
  89135. if(
  89136. raw_header[1] & 0x01 ||
  89137. (decoder->private_->has_stream_info && decoder->private_->stream_info.data.stream_info.min_blocksize != decoder->private_->stream_info.data.stream_info.max_blocksize)
  89138. ) { /* variable blocksize */
  89139. if(!FLAC__bitreader_read_utf8_uint64(decoder->private_->input, &xx, raw_header, &raw_header_len))
  89140. return false; /* read_callback_ sets the state for us */
  89141. if(xx == FLAC__U64L(0xffffffffffffffff)) { /* i.e. non-UTF8 code... */
  89142. decoder->private_->lookahead = raw_header[raw_header_len-1]; /* back up as much as we can */
  89143. decoder->private_->cached = true;
  89144. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  89145. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89146. return true;
  89147. }
  89148. decoder->private_->frame.header.number_type = FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER;
  89149. decoder->private_->frame.header.number.sample_number = xx;
  89150. }
  89151. else { /* fixed blocksize */
  89152. if(!FLAC__bitreader_read_utf8_uint32(decoder->private_->input, &x, raw_header, &raw_header_len))
  89153. return false; /* read_callback_ sets the state for us */
  89154. if(x == 0xffffffff) { /* i.e. non-UTF8 code... */
  89155. decoder->private_->lookahead = raw_header[raw_header_len-1]; /* back up as much as we can */
  89156. decoder->private_->cached = true;
  89157. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  89158. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89159. return true;
  89160. }
  89161. decoder->private_->frame.header.number_type = FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER;
  89162. decoder->private_->frame.header.number.frame_number = x;
  89163. }
  89164. if(blocksize_hint) {
  89165. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  89166. return false; /* read_callback_ sets the state for us */
  89167. raw_header[raw_header_len++] = (FLAC__byte)x;
  89168. if(blocksize_hint == 7) {
  89169. FLAC__uint32 _x;
  89170. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &_x, 8))
  89171. return false; /* read_callback_ sets the state for us */
  89172. raw_header[raw_header_len++] = (FLAC__byte)_x;
  89173. x = (x << 8) | _x;
  89174. }
  89175. decoder->private_->frame.header.blocksize = x+1;
  89176. }
  89177. if(sample_rate_hint) {
  89178. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  89179. return false; /* read_callback_ sets the state for us */
  89180. raw_header[raw_header_len++] = (FLAC__byte)x;
  89181. if(sample_rate_hint != 12) {
  89182. FLAC__uint32 _x;
  89183. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &_x, 8))
  89184. return false; /* read_callback_ sets the state for us */
  89185. raw_header[raw_header_len++] = (FLAC__byte)_x;
  89186. x = (x << 8) | _x;
  89187. }
  89188. if(sample_rate_hint == 12)
  89189. decoder->private_->frame.header.sample_rate = x*1000;
  89190. else if(sample_rate_hint == 13)
  89191. decoder->private_->frame.header.sample_rate = x;
  89192. else
  89193. decoder->private_->frame.header.sample_rate = x*10;
  89194. }
  89195. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  89196. return false; /* read_callback_ sets the state for us */
  89197. crc8 = (FLAC__byte)x;
  89198. if(FLAC__crc8(raw_header, raw_header_len) != crc8) {
  89199. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  89200. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89201. return true;
  89202. }
  89203. decoder->private_->next_fixed_block_size = 0;
  89204. if(decoder->private_->frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER) {
  89205. x = decoder->private_->frame.header.number.frame_number;
  89206. decoder->private_->frame.header.number_type = FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER;
  89207. if(decoder->private_->fixed_block_size)
  89208. decoder->private_->frame.header.number.sample_number = (FLAC__uint64)decoder->private_->fixed_block_size * (FLAC__uint64)x;
  89209. else if(decoder->private_->has_stream_info) {
  89210. if(decoder->private_->stream_info.data.stream_info.min_blocksize == decoder->private_->stream_info.data.stream_info.max_blocksize) {
  89211. decoder->private_->frame.header.number.sample_number = (FLAC__uint64)decoder->private_->stream_info.data.stream_info.min_blocksize * (FLAC__uint64)x;
  89212. decoder->private_->next_fixed_block_size = decoder->private_->stream_info.data.stream_info.max_blocksize;
  89213. }
  89214. else
  89215. is_unparseable = true;
  89216. }
  89217. else if(x == 0) {
  89218. decoder->private_->frame.header.number.sample_number = 0;
  89219. decoder->private_->next_fixed_block_size = decoder->private_->frame.header.blocksize;
  89220. }
  89221. else {
  89222. decoder->private_->frame.header.number.sample_number = (FLAC__uint64)decoder->private_->frame.header.blocksize * (FLAC__uint64)x;
  89223. }
  89224. }
  89225. if(is_unparseable) {
  89226. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  89227. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89228. return true;
  89229. }
  89230. return true;
  89231. }
  89232. FLAC__bool read_subframe_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode)
  89233. {
  89234. FLAC__uint32 x;
  89235. FLAC__bool wasted_bits;
  89236. unsigned i;
  89237. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8)) /* MAGIC NUMBER */
  89238. return false; /* read_callback_ sets the state for us */
  89239. wasted_bits = (x & 1);
  89240. x &= 0xfe;
  89241. if(wasted_bits) {
  89242. unsigned u;
  89243. if(!FLAC__bitreader_read_unary_unsigned(decoder->private_->input, &u))
  89244. return false; /* read_callback_ sets the state for us */
  89245. decoder->private_->frame.subframes[channel].wasted_bits = u+1;
  89246. bps -= decoder->private_->frame.subframes[channel].wasted_bits;
  89247. }
  89248. else
  89249. decoder->private_->frame.subframes[channel].wasted_bits = 0;
  89250. if(x & 0x80) {
  89251. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  89252. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89253. return true;
  89254. }
  89255. else if(x == 0) {
  89256. if(!read_subframe_constant_(decoder, channel, bps, do_full_decode))
  89257. return false;
  89258. }
  89259. else if(x == 2) {
  89260. if(!read_subframe_verbatim_(decoder, channel, bps, do_full_decode))
  89261. return false;
  89262. }
  89263. else if(x < 16) {
  89264. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  89265. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89266. return true;
  89267. }
  89268. else if(x <= 24) {
  89269. if(!read_subframe_fixed_(decoder, channel, bps, (x>>1)&7, do_full_decode))
  89270. return false;
  89271. if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means bad sync or got corruption */
  89272. return true;
  89273. }
  89274. else if(x < 64) {
  89275. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  89276. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89277. return true;
  89278. }
  89279. else {
  89280. if(!read_subframe_lpc_(decoder, channel, bps, ((x>>1)&31)+1, do_full_decode))
  89281. return false;
  89282. if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means bad sync or got corruption */
  89283. return true;
  89284. }
  89285. if(wasted_bits && do_full_decode) {
  89286. x = decoder->private_->frame.subframes[channel].wasted_bits;
  89287. for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
  89288. decoder->private_->output[channel][i] <<= x;
  89289. }
  89290. return true;
  89291. }
  89292. FLAC__bool read_subframe_constant_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode)
  89293. {
  89294. FLAC__Subframe_Constant *subframe = &decoder->private_->frame.subframes[channel].data.constant;
  89295. FLAC__int32 x;
  89296. unsigned i;
  89297. FLAC__int32 *output = decoder->private_->output[channel];
  89298. decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_CONSTANT;
  89299. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &x, bps))
  89300. return false; /* read_callback_ sets the state for us */
  89301. subframe->value = x;
  89302. if(do_full_decode) {
  89303. for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
  89304. output[i] = x;
  89305. }
  89306. return true;
  89307. }
  89308. FLAC__bool read_subframe_fixed_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode)
  89309. {
  89310. FLAC__Subframe_Fixed *subframe = &decoder->private_->frame.subframes[channel].data.fixed;
  89311. FLAC__int32 i32;
  89312. FLAC__uint32 u32;
  89313. unsigned u;
  89314. decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_FIXED;
  89315. subframe->residual = decoder->private_->residual[channel];
  89316. subframe->order = order;
  89317. for(u = 0; u < order; u++) {
  89318. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, bps))
  89319. return false; /* read_callback_ sets the state for us */
  89320. subframe->warmup[u] = i32;
  89321. }
  89322. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_TYPE_LEN))
  89323. return false; /* read_callback_ sets the state for us */
  89324. subframe->entropy_coding_method.type = (FLAC__EntropyCodingMethodType)u32;
  89325. switch(subframe->entropy_coding_method.type) {
  89326. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  89327. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  89328. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
  89329. return false; /* read_callback_ sets the state for us */
  89330. subframe->entropy_coding_method.data.partitioned_rice.order = u32;
  89331. subframe->entropy_coding_method.data.partitioned_rice.contents = &decoder->private_->partitioned_rice_contents[channel];
  89332. break;
  89333. default:
  89334. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  89335. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89336. return true;
  89337. }
  89338. switch(subframe->entropy_coding_method.type) {
  89339. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  89340. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  89341. 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))
  89342. return false;
  89343. break;
  89344. default:
  89345. FLAC__ASSERT(0);
  89346. }
  89347. if(do_full_decode) {
  89348. memcpy(decoder->private_->output[channel], subframe->warmup, sizeof(FLAC__int32) * order);
  89349. FLAC__fixed_restore_signal(decoder->private_->residual[channel], decoder->private_->frame.header.blocksize-order, order, decoder->private_->output[channel]+order);
  89350. }
  89351. return true;
  89352. }
  89353. FLAC__bool read_subframe_lpc_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode)
  89354. {
  89355. FLAC__Subframe_LPC *subframe = &decoder->private_->frame.subframes[channel].data.lpc;
  89356. FLAC__int32 i32;
  89357. FLAC__uint32 u32;
  89358. unsigned u;
  89359. decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_LPC;
  89360. subframe->residual = decoder->private_->residual[channel];
  89361. subframe->order = order;
  89362. for(u = 0; u < order; u++) {
  89363. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, bps))
  89364. return false; /* read_callback_ sets the state for us */
  89365. subframe->warmup[u] = i32;
  89366. }
  89367. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN))
  89368. return false; /* read_callback_ sets the state for us */
  89369. if(u32 == (1u << FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN) - 1) {
  89370. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  89371. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89372. return true;
  89373. }
  89374. subframe->qlp_coeff_precision = u32+1;
  89375. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN))
  89376. return false; /* read_callback_ sets the state for us */
  89377. subframe->quantization_level = i32;
  89378. for(u = 0; u < order; u++) {
  89379. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, subframe->qlp_coeff_precision))
  89380. return false; /* read_callback_ sets the state for us */
  89381. subframe->qlp_coeff[u] = i32;
  89382. }
  89383. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_TYPE_LEN))
  89384. return false; /* read_callback_ sets the state for us */
  89385. subframe->entropy_coding_method.type = (FLAC__EntropyCodingMethodType)u32;
  89386. switch(subframe->entropy_coding_method.type) {
  89387. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  89388. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  89389. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
  89390. return false; /* read_callback_ sets the state for us */
  89391. subframe->entropy_coding_method.data.partitioned_rice.order = u32;
  89392. subframe->entropy_coding_method.data.partitioned_rice.contents = &decoder->private_->partitioned_rice_contents[channel];
  89393. break;
  89394. default:
  89395. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  89396. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89397. return true;
  89398. }
  89399. switch(subframe->entropy_coding_method.type) {
  89400. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  89401. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  89402. 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))
  89403. return false;
  89404. break;
  89405. default:
  89406. FLAC__ASSERT(0);
  89407. }
  89408. if(do_full_decode) {
  89409. memcpy(decoder->private_->output[channel], subframe->warmup, sizeof(FLAC__int32) * order);
  89410. if(bps + subframe->qlp_coeff_precision + FLAC__bitmath_ilog2(order) <= 32)
  89411. if(bps <= 16 && subframe->qlp_coeff_precision <= 16) {
  89412. if(order <= 8)
  89413. 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);
  89414. else
  89415. 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);
  89416. }
  89417. else
  89418. 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);
  89419. else
  89420. 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);
  89421. }
  89422. return true;
  89423. }
  89424. FLAC__bool read_subframe_verbatim_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode)
  89425. {
  89426. FLAC__Subframe_Verbatim *subframe = &decoder->private_->frame.subframes[channel].data.verbatim;
  89427. FLAC__int32 x, *residual = decoder->private_->residual[channel];
  89428. unsigned i;
  89429. decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_VERBATIM;
  89430. subframe->data = residual;
  89431. for(i = 0; i < decoder->private_->frame.header.blocksize; i++) {
  89432. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &x, bps))
  89433. return false; /* read_callback_ sets the state for us */
  89434. residual[i] = x;
  89435. }
  89436. if(do_full_decode)
  89437. memcpy(decoder->private_->output[channel], subframe->data, sizeof(FLAC__int32) * decoder->private_->frame.header.blocksize);
  89438. return true;
  89439. }
  89440. 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)
  89441. {
  89442. FLAC__uint32 rice_parameter;
  89443. int i;
  89444. unsigned partition, sample, u;
  89445. const unsigned partitions = 1u << partition_order;
  89446. const unsigned partition_samples = partition_order > 0? decoder->private_->frame.header.blocksize >> partition_order : decoder->private_->frame.header.blocksize - predictor_order;
  89447. const unsigned plen = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN;
  89448. const unsigned pesc = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER;
  89449. if(partition_order == 0) {
  89450. if(decoder->private_->frame.header.blocksize < predictor_order) {
  89451. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  89452. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89453. return true;
  89454. }
  89455. }
  89456. else {
  89457. if(partition_samples < predictor_order) {
  89458. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  89459. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89460. return true;
  89461. }
  89462. }
  89463. if(!FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(partitioned_rice_contents, max(6, partition_order))) {
  89464. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  89465. return false;
  89466. }
  89467. sample = 0;
  89468. for(partition = 0; partition < partitions; partition++) {
  89469. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &rice_parameter, plen))
  89470. return false; /* read_callback_ sets the state for us */
  89471. partitioned_rice_contents->parameters[partition] = rice_parameter;
  89472. if(rice_parameter < pesc) {
  89473. partitioned_rice_contents->raw_bits[partition] = 0;
  89474. u = (partition_order == 0 || partition > 0)? partition_samples : partition_samples - predictor_order;
  89475. if(!decoder->private_->local_bitreader_read_rice_signed_block(decoder->private_->input, (int*) residual + sample, u, rice_parameter))
  89476. return false; /* read_callback_ sets the state for us */
  89477. sample += u;
  89478. }
  89479. else {
  89480. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &rice_parameter, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN))
  89481. return false; /* read_callback_ sets the state for us */
  89482. partitioned_rice_contents->raw_bits[partition] = rice_parameter;
  89483. for(u = (partition_order == 0 || partition > 0)? 0 : predictor_order; u < partition_samples; u++, sample++) {
  89484. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, (FLAC__int32*) &i, rice_parameter))
  89485. return false; /* read_callback_ sets the state for us */
  89486. residual[sample] = i;
  89487. }
  89488. }
  89489. }
  89490. return true;
  89491. }
  89492. FLAC__bool read_zero_padding_(FLAC__StreamDecoder *decoder)
  89493. {
  89494. if(!FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input)) {
  89495. FLAC__uint32 zero = 0;
  89496. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &zero, FLAC__bitreader_bits_left_for_byte_alignment(decoder->private_->input)))
  89497. return false; /* read_callback_ sets the state for us */
  89498. if(zero != 0) {
  89499. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  89500. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89501. }
  89502. }
  89503. return true;
  89504. }
  89505. FLAC__bool read_callback_(FLAC__byte buffer[], size_t *bytes, void *client_data)
  89506. {
  89507. FLAC__StreamDecoder *decoder = (FLAC__StreamDecoder *)client_data;
  89508. if(
  89509. #if FLAC__HAS_OGG
  89510. !decoder->private_->is_ogg &&
  89511. #endif
  89512. decoder->private_->eof_callback && decoder->private_->eof_callback(decoder, decoder->private_->client_data)
  89513. ) {
  89514. *bytes = 0;
  89515. decoder->protected_->state = FLAC__STREAM_DECODER_END_OF_STREAM;
  89516. return false;
  89517. }
  89518. else if(*bytes > 0) {
  89519. if(decoder->private_->is_seeking && decoder->private_->unparseable_frame_count > 20) {
  89520. decoder->protected_->state = FLAC__STREAM_DECODER_ABORTED;
  89521. return false;
  89522. }
  89523. else {
  89524. const FLAC__StreamDecoderReadStatus status =
  89525. #if FLAC__HAS_OGG
  89526. decoder->private_->is_ogg?
  89527. read_callback_ogg_aspect_(decoder, buffer, bytes) :
  89528. #endif
  89529. decoder->private_->read_callback(decoder, buffer, bytes, decoder->private_->client_data)
  89530. ;
  89531. if(status == FLAC__STREAM_DECODER_READ_STATUS_ABORT) {
  89532. decoder->protected_->state = FLAC__STREAM_DECODER_ABORTED;
  89533. return false;
  89534. }
  89535. else if(*bytes == 0) {
  89536. if(
  89537. status == FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM ||
  89538. (
  89539. #if FLAC__HAS_OGG
  89540. !decoder->private_->is_ogg &&
  89541. #endif
  89542. decoder->private_->eof_callback && decoder->private_->eof_callback(decoder, decoder->private_->client_data)
  89543. )
  89544. ) {
  89545. decoder->protected_->state = FLAC__STREAM_DECODER_END_OF_STREAM;
  89546. return false;
  89547. }
  89548. else
  89549. return true;
  89550. }
  89551. else
  89552. return true;
  89553. }
  89554. }
  89555. else {
  89556. decoder->protected_->state = FLAC__STREAM_DECODER_ABORTED;
  89557. return false;
  89558. }
  89559. }
  89560. #if FLAC__HAS_OGG
  89561. FLAC__StreamDecoderReadStatus read_callback_ogg_aspect_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes)
  89562. {
  89563. switch(FLAC__ogg_decoder_aspect_read_callback_wrapper(&decoder->protected_->ogg_decoder_aspect, buffer, bytes, read_callback_proxy_, decoder, decoder->private_->client_data)) {
  89564. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_OK:
  89565. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  89566. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_LOST_SYNC:
  89567. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  89568. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_END_OF_STREAM:
  89569. return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
  89570. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_NOT_FLAC:
  89571. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_UNSUPPORTED_MAPPING_VERSION:
  89572. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT:
  89573. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_ERROR:
  89574. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_MEMORY_ALLOCATION_ERROR:
  89575. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  89576. default:
  89577. FLAC__ASSERT(0);
  89578. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  89579. }
  89580. }
  89581. FLAC__OggDecoderAspectReadStatus read_callback_proxy_(const void *void_decoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  89582. {
  89583. FLAC__StreamDecoder *decoder = (FLAC__StreamDecoder*)void_decoder;
  89584. switch(decoder->private_->read_callback(decoder, buffer, bytes, client_data)) {
  89585. case FLAC__STREAM_DECODER_READ_STATUS_CONTINUE:
  89586. return FLAC__OGG_DECODER_ASPECT_READ_STATUS_OK;
  89587. case FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM:
  89588. return FLAC__OGG_DECODER_ASPECT_READ_STATUS_END_OF_STREAM;
  89589. case FLAC__STREAM_DECODER_READ_STATUS_ABORT:
  89590. return FLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT;
  89591. default:
  89592. FLAC__ASSERT(0);
  89593. return FLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT;
  89594. }
  89595. }
  89596. #endif
  89597. FLAC__StreamDecoderWriteStatus write_audio_frame_to_client_(FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[])
  89598. {
  89599. if(decoder->private_->is_seeking) {
  89600. FLAC__uint64 this_frame_sample = frame->header.number.sample_number;
  89601. FLAC__uint64 next_frame_sample = this_frame_sample + (FLAC__uint64)frame->header.blocksize;
  89602. FLAC__uint64 target_sample = decoder->private_->target_sample;
  89603. FLAC__ASSERT(frame->header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  89604. #if FLAC__HAS_OGG
  89605. decoder->private_->got_a_frame = true;
  89606. #endif
  89607. decoder->private_->last_frame = *frame; /* save the frame */
  89608. if(this_frame_sample <= target_sample && target_sample < next_frame_sample) { /* we hit our target frame */
  89609. unsigned delta = (unsigned)(target_sample - this_frame_sample);
  89610. decoder->private_->is_seeking = false;
  89611. if(delta > 0) {
  89612. unsigned channel;
  89613. const FLAC__int32 *newbuffer[FLAC__MAX_CHANNELS];
  89614. for(channel = 0; channel < frame->header.channels; channel++)
  89615. newbuffer[channel] = buffer[channel] + delta;
  89616. decoder->private_->last_frame.header.blocksize -= delta;
  89617. decoder->private_->last_frame.header.number.sample_number += (FLAC__uint64)delta;
  89618. return decoder->private_->write_callback(decoder, &decoder->private_->last_frame, newbuffer, decoder->private_->client_data);
  89619. }
  89620. else {
  89621. return decoder->private_->write_callback(decoder, frame, buffer, decoder->private_->client_data);
  89622. }
  89623. }
  89624. return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
  89625. }
  89626. if(!decoder->private_->has_stream_info)
  89627. decoder->private_->do_md5_checking = false;
  89628. if(decoder->private_->do_md5_checking) {
  89629. if(!FLAC__MD5Accumulate(&decoder->private_->md5context, buffer, frame->header.channels, frame->header.blocksize, (frame->header.bits_per_sample+7) / 8))
  89630. return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
  89631. }
  89632. return decoder->private_->write_callback(decoder, frame, buffer, decoder->private_->client_data);
  89633. }
  89634. void send_error_to_client_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status)
  89635. {
  89636. if(!decoder->private_->is_seeking)
  89637. decoder->private_->error_callback(decoder, status, decoder->private_->client_data);
  89638. else if(status == FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM)
  89639. decoder->private_->unparseable_frame_count++;
  89640. }
  89641. FLAC__bool seek_to_absolute_sample_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample)
  89642. {
  89643. FLAC__uint64 first_frame_offset = decoder->private_->first_frame_offset, lower_bound, upper_bound, lower_bound_sample, upper_bound_sample, this_frame_sample;
  89644. FLAC__int64 pos = -1;
  89645. int i;
  89646. unsigned approx_bytes_per_frame;
  89647. FLAC__bool first_seek = true;
  89648. const FLAC__uint64 total_samples = FLAC__stream_decoder_get_total_samples(decoder);
  89649. const unsigned min_blocksize = decoder->private_->stream_info.data.stream_info.min_blocksize;
  89650. const unsigned max_blocksize = decoder->private_->stream_info.data.stream_info.max_blocksize;
  89651. const unsigned max_framesize = decoder->private_->stream_info.data.stream_info.max_framesize;
  89652. const unsigned min_framesize = decoder->private_->stream_info.data.stream_info.min_framesize;
  89653. unsigned channels = FLAC__stream_decoder_get_channels(decoder);
  89654. unsigned bps = FLAC__stream_decoder_get_bits_per_sample(decoder);
  89655. const FLAC__StreamMetadata_SeekTable *seek_table = decoder->private_->has_seek_table? &decoder->private_->seek_table.data.seek_table : 0;
  89656. if(channels == 0)
  89657. channels = decoder->private_->stream_info.data.stream_info.channels;
  89658. if(bps == 0)
  89659. bps = decoder->private_->stream_info.data.stream_info.bits_per_sample;
  89660. if(max_framesize > 0)
  89661. approx_bytes_per_frame = (max_framesize + min_framesize) / 2 + 1;
  89662. else if(min_blocksize == max_blocksize && min_blocksize > 0) {
  89663. approx_bytes_per_frame = min_blocksize * channels * bps/8 + 64;
  89664. }
  89665. else
  89666. approx_bytes_per_frame = 4096 * channels * bps/8 + 64;
  89667. lower_bound = first_frame_offset;
  89668. lower_bound_sample = 0;
  89669. upper_bound = stream_length;
  89670. upper_bound_sample = total_samples > 0 ? total_samples : target_sample /*estimate it*/;
  89671. if(seek_table) {
  89672. FLAC__uint64 new_lower_bound = lower_bound;
  89673. FLAC__uint64 new_upper_bound = upper_bound;
  89674. FLAC__uint64 new_lower_bound_sample = lower_bound_sample;
  89675. FLAC__uint64 new_upper_bound_sample = upper_bound_sample;
  89676. for(i = (int)seek_table->num_points - 1; i >= 0; i--) {
  89677. if(
  89678. seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER &&
  89679. seek_table->points[i].frame_samples > 0 && /* defense against bad seekpoints */
  89680. (total_samples <= 0 || seek_table->points[i].sample_number < total_samples) && /* defense against bad seekpoints */
  89681. seek_table->points[i].sample_number <= target_sample
  89682. )
  89683. break;
  89684. }
  89685. if(i >= 0) { /* i.e. we found a suitable seek point... */
  89686. new_lower_bound = first_frame_offset + seek_table->points[i].stream_offset;
  89687. new_lower_bound_sample = seek_table->points[i].sample_number;
  89688. }
  89689. for(i = 0; i < (int)seek_table->num_points; i++) {
  89690. if(
  89691. seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER &&
  89692. seek_table->points[i].frame_samples > 0 && /* defense against bad seekpoints */
  89693. (total_samples <= 0 || seek_table->points[i].sample_number < total_samples) && /* defense against bad seekpoints */
  89694. seek_table->points[i].sample_number > target_sample
  89695. )
  89696. break;
  89697. }
  89698. if(i < (int)seek_table->num_points) { /* i.e. we found a suitable seek point... */
  89699. new_upper_bound = first_frame_offset + seek_table->points[i].stream_offset;
  89700. new_upper_bound_sample = seek_table->points[i].sample_number;
  89701. }
  89702. if(new_upper_bound >= new_lower_bound) {
  89703. lower_bound = new_lower_bound;
  89704. upper_bound = new_upper_bound;
  89705. lower_bound_sample = new_lower_bound_sample;
  89706. upper_bound_sample = new_upper_bound_sample;
  89707. }
  89708. }
  89709. FLAC__ASSERT(upper_bound_sample >= lower_bound_sample);
  89710. if(upper_bound_sample == lower_bound_sample)
  89711. upper_bound_sample++;
  89712. decoder->private_->target_sample = target_sample;
  89713. while(1) {
  89714. if (lower_bound_sample >= upper_bound_sample || lower_bound > upper_bound) {
  89715. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89716. return false;
  89717. }
  89718. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89719. #if defined _MSC_VER || defined __MINGW32__
  89720. 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;
  89721. #else
  89722. 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;
  89723. #endif
  89724. #else
  89725. if(upper_bound - lower_bound < 0xffffffff)
  89726. 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;
  89727. else /* @@@ WATCHOUT, ~2TB limit */
  89728. 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;
  89729. #endif
  89730. if(pos >= (FLAC__int64)upper_bound)
  89731. pos = (FLAC__int64)upper_bound - 1;
  89732. if(pos < (FLAC__int64)lower_bound)
  89733. pos = (FLAC__int64)lower_bound;
  89734. if(decoder->private_->seek_callback(decoder, (FLAC__uint64)pos, decoder->private_->client_data) != FLAC__STREAM_DECODER_SEEK_STATUS_OK) {
  89735. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89736. return false;
  89737. }
  89738. if(!FLAC__stream_decoder_flush(decoder)) {
  89739. return false;
  89740. }
  89741. decoder->private_->unparseable_frame_count = 0;
  89742. if(!FLAC__stream_decoder_process_single(decoder)) {
  89743. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89744. return false;
  89745. }
  89746. #if 0
  89747. if(decoder->protected_->state != FLAC__SEEKABLE_STREAM_DECODER_SEEKING && decoder->protected_->state != FLAC__STREAM_DECODER_END_OF_STREAM)
  89748. break;
  89749. #endif
  89750. if(!decoder->private_->is_seeking)
  89751. break;
  89752. FLAC__ASSERT(decoder->private_->last_frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  89753. this_frame_sample = decoder->private_->last_frame.header.number.sample_number;
  89754. if (0 == decoder->private_->samples_decoded || (this_frame_sample + decoder->private_->last_frame.header.blocksize >= upper_bound_sample && !first_seek)) {
  89755. if (pos == (FLAC__int64)lower_bound) {
  89756. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89757. return false;
  89758. }
  89759. approx_bytes_per_frame = approx_bytes_per_frame? approx_bytes_per_frame * 2 : 16;
  89760. continue;
  89761. }
  89762. first_seek = false;
  89763. if (this_frame_sample < lower_bound_sample) {
  89764. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89765. return false;
  89766. }
  89767. if(target_sample < this_frame_sample) {
  89768. upper_bound_sample = this_frame_sample + decoder->private_->last_frame.header.blocksize;
  89769. if(!FLAC__stream_decoder_get_decode_position(decoder, &upper_bound)) {
  89770. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89771. return false;
  89772. }
  89773. approx_bytes_per_frame = (unsigned)(2 * (upper_bound - pos) / 3 + 16);
  89774. }
  89775. else { /* target_sample >= this_frame_sample + this frame's blocksize */
  89776. lower_bound_sample = this_frame_sample + decoder->private_->last_frame.header.blocksize;
  89777. if(!FLAC__stream_decoder_get_decode_position(decoder, &lower_bound)) {
  89778. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89779. return false;
  89780. }
  89781. approx_bytes_per_frame = (unsigned)(2 * (lower_bound - pos) / 3 + 16);
  89782. }
  89783. }
  89784. return true;
  89785. }
  89786. #if FLAC__HAS_OGG
  89787. FLAC__bool seek_to_absolute_sample_ogg_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample)
  89788. {
  89789. FLAC__uint64 left_pos = 0, right_pos = stream_length;
  89790. FLAC__uint64 left_sample = 0, right_sample = FLAC__stream_decoder_get_total_samples(decoder);
  89791. FLAC__uint64 this_frame_sample = (FLAC__uint64)0 - 1;
  89792. FLAC__uint64 pos = 0; /* only initialized to avoid compiler warning */
  89793. FLAC__bool did_a_seek;
  89794. unsigned iteration = 0;
  89795. unsigned BINARY_SEARCH_AFTER_ITERATION = 2;
  89796. static const FLAC__uint64 LINEAR_SEARCH_WITHIN_SAMPLES = FLAC__MAX_BLOCK_SIZE * 2;
  89797. if(right_sample == 0) {
  89798. right_sample = (FLAC__uint64)(-1);
  89799. BINARY_SEARCH_AFTER_ITERATION = 0;
  89800. }
  89801. decoder->private_->target_sample = target_sample;
  89802. for( ; ; iteration++) {
  89803. if (iteration == 0 || this_frame_sample > target_sample || target_sample - this_frame_sample > LINEAR_SEARCH_WITHIN_SAMPLES) {
  89804. if (iteration >= BINARY_SEARCH_AFTER_ITERATION) {
  89805. pos = (right_pos + left_pos) / 2;
  89806. }
  89807. else {
  89808. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89809. #if defined _MSC_VER || defined __MINGW32__
  89810. 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));
  89811. #else
  89812. pos = (FLAC__uint64)((FLAC__double)(target_sample - left_sample) / (FLAC__double)(right_sample - left_sample) * (FLAC__double)(right_pos - left_pos));
  89813. #endif
  89814. #else
  89815. if ((target_sample-left_sample <= 0xffffffff) && (right_pos-left_pos <= 0xffffffff))
  89816. pos = (FLAC__int64)(((target_sample-left_sample) * (right_pos-left_pos)) / (right_sample-left_sample));
  89817. else /* @@@ WATCHOUT, ~2TB limit */
  89818. pos = (FLAC__int64)((((target_sample-left_sample)>>8) * ((right_pos-left_pos)>>8)) / ((right_sample-left_sample)>>16));
  89819. #endif
  89820. }
  89821. if(decoder->private_->seek_callback((FLAC__StreamDecoder*)decoder, (FLAC__uint64)pos, decoder->private_->client_data) != FLAC__STREAM_DECODER_SEEK_STATUS_OK) {
  89822. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89823. return false;
  89824. }
  89825. if(!FLAC__stream_decoder_flush(decoder)) {
  89826. return false;
  89827. }
  89828. did_a_seek = true;
  89829. }
  89830. else
  89831. did_a_seek = false;
  89832. decoder->private_->got_a_frame = false;
  89833. if(!FLAC__stream_decoder_process_single(decoder)) {
  89834. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89835. return false;
  89836. }
  89837. if(!decoder->private_->got_a_frame) {
  89838. if(did_a_seek) {
  89839. right_pos = pos;
  89840. BINARY_SEARCH_AFTER_ITERATION = 0;
  89841. }
  89842. else {
  89843. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89844. return false;
  89845. }
  89846. }
  89847. else if(!decoder->private_->is_seeking) {
  89848. break;
  89849. }
  89850. else {
  89851. this_frame_sample = decoder->private_->last_frame.header.number.sample_number;
  89852. FLAC__ASSERT(decoder->private_->last_frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  89853. if (did_a_seek) {
  89854. if (this_frame_sample <= target_sample) {
  89855. FLAC__ASSERT(this_frame_sample != target_sample);
  89856. left_sample = this_frame_sample;
  89857. if (left_pos == pos) {
  89858. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89859. return false;
  89860. }
  89861. left_pos = pos;
  89862. }
  89863. else if(this_frame_sample > target_sample) {
  89864. right_sample = this_frame_sample;
  89865. if (right_pos == pos) {
  89866. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89867. return false;
  89868. }
  89869. right_pos = pos;
  89870. }
  89871. }
  89872. }
  89873. }
  89874. return true;
  89875. }
  89876. #endif
  89877. FLAC__StreamDecoderReadStatus file_read_callback_dec(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  89878. {
  89879. (void)client_data;
  89880. if(*bytes > 0) {
  89881. *bytes = fread(buffer, sizeof(FLAC__byte), *bytes, decoder->private_->file);
  89882. if(ferror(decoder->private_->file))
  89883. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  89884. else if(*bytes == 0)
  89885. return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
  89886. else
  89887. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  89888. }
  89889. else
  89890. return FLAC__STREAM_DECODER_READ_STATUS_ABORT; /* abort to avoid a deadlock */
  89891. }
  89892. FLAC__StreamDecoderSeekStatus file_seek_callback_dec(const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data)
  89893. {
  89894. (void)client_data;
  89895. if(decoder->private_->file == stdin)
  89896. return FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED;
  89897. else if(fseeko(decoder->private_->file, (off_t)absolute_byte_offset, SEEK_SET) < 0)
  89898. return FLAC__STREAM_DECODER_SEEK_STATUS_ERROR;
  89899. else
  89900. return FLAC__STREAM_DECODER_SEEK_STATUS_OK;
  89901. }
  89902. FLAC__StreamDecoderTellStatus file_tell_callback_dec(const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data)
  89903. {
  89904. off_t pos;
  89905. (void)client_data;
  89906. if(decoder->private_->file == stdin)
  89907. return FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED;
  89908. else if((pos = ftello(decoder->private_->file)) < 0)
  89909. return FLAC__STREAM_DECODER_TELL_STATUS_ERROR;
  89910. else {
  89911. *absolute_byte_offset = (FLAC__uint64)pos;
  89912. return FLAC__STREAM_DECODER_TELL_STATUS_OK;
  89913. }
  89914. }
  89915. FLAC__StreamDecoderLengthStatus file_length_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data)
  89916. {
  89917. struct stat filestats;
  89918. (void)client_data;
  89919. if(decoder->private_->file == stdin)
  89920. return FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED;
  89921. else if(fstat(fileno(decoder->private_->file), &filestats) != 0)
  89922. return FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR;
  89923. else {
  89924. *stream_length = (FLAC__uint64)filestats.st_size;
  89925. return FLAC__STREAM_DECODER_LENGTH_STATUS_OK;
  89926. }
  89927. }
  89928. FLAC__bool file_eof_callback_(const FLAC__StreamDecoder *decoder, void *client_data)
  89929. {
  89930. (void)client_data;
  89931. return feof(decoder->private_->file)? true : false;
  89932. }
  89933. #endif
  89934. /*** End of inlined file: stream_decoder.c ***/
  89935. /*** Start of inlined file: stream_encoder.c ***/
  89936. /*** Start of inlined file: juce_FlacHeader.h ***/
  89937. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  89938. // tasks..
  89939. #define VERSION "1.2.1"
  89940. #define FLAC__NO_DLL 1
  89941. #if JUCE_MSVC
  89942. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  89943. #endif
  89944. #if JUCE_MAC
  89945. #define FLAC__SYS_DARWIN 1
  89946. #endif
  89947. /*** End of inlined file: juce_FlacHeader.h ***/
  89948. #if JUCE_USE_FLAC
  89949. #if HAVE_CONFIG_H
  89950. # include <config.h>
  89951. #endif
  89952. #if defined _MSC_VER || defined __MINGW32__
  89953. #include <io.h> /* for _setmode() */
  89954. #include <fcntl.h> /* for _O_BINARY */
  89955. #endif
  89956. #if defined __CYGWIN__ || defined __EMX__
  89957. #include <io.h> /* for setmode(), O_BINARY */
  89958. #include <fcntl.h> /* for _O_BINARY */
  89959. #endif
  89960. #include <limits.h>
  89961. #include <stdio.h>
  89962. #include <stdlib.h> /* for malloc() */
  89963. #include <string.h> /* for memcpy() */
  89964. #include <sys/types.h> /* for off_t */
  89965. #if defined _MSC_VER || defined __BORLANDC__ || defined __MINGW32__
  89966. #if _MSC_VER <= 1600 || defined __BORLANDC__ /* @@@ [2G limit] */
  89967. #define fseeko fseek
  89968. #define ftello ftell
  89969. #endif
  89970. #endif
  89971. /*** Start of inlined file: stream_encoder.h ***/
  89972. #ifndef FLAC__PROTECTED__STREAM_ENCODER_H
  89973. #define FLAC__PROTECTED__STREAM_ENCODER_H
  89974. #if FLAC__HAS_OGG
  89975. #include "private/ogg_encoder_aspect.h"
  89976. #endif
  89977. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89978. #define FLAC__MAX_APODIZATION_FUNCTIONS 32
  89979. typedef enum {
  89980. FLAC__APODIZATION_BARTLETT,
  89981. FLAC__APODIZATION_BARTLETT_HANN,
  89982. FLAC__APODIZATION_BLACKMAN,
  89983. FLAC__APODIZATION_BLACKMAN_HARRIS_4TERM_92DB_SIDELOBE,
  89984. FLAC__APODIZATION_CONNES,
  89985. FLAC__APODIZATION_FLATTOP,
  89986. FLAC__APODIZATION_GAUSS,
  89987. FLAC__APODIZATION_HAMMING,
  89988. FLAC__APODIZATION_HANN,
  89989. FLAC__APODIZATION_KAISER_BESSEL,
  89990. FLAC__APODIZATION_NUTTALL,
  89991. FLAC__APODIZATION_RECTANGLE,
  89992. FLAC__APODIZATION_TRIANGLE,
  89993. FLAC__APODIZATION_TUKEY,
  89994. FLAC__APODIZATION_WELCH
  89995. } FLAC__ApodizationFunction;
  89996. typedef struct {
  89997. FLAC__ApodizationFunction type;
  89998. union {
  89999. struct {
  90000. FLAC__real stddev;
  90001. } gauss;
  90002. struct {
  90003. FLAC__real p;
  90004. } tukey;
  90005. } parameters;
  90006. } FLAC__ApodizationSpecification;
  90007. #endif // #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90008. typedef struct FLAC__StreamEncoderProtected {
  90009. FLAC__StreamEncoderState state;
  90010. FLAC__bool verify;
  90011. FLAC__bool streamable_subset;
  90012. FLAC__bool do_md5;
  90013. FLAC__bool do_mid_side_stereo;
  90014. FLAC__bool loose_mid_side_stereo;
  90015. unsigned channels;
  90016. unsigned bits_per_sample;
  90017. unsigned sample_rate;
  90018. unsigned blocksize;
  90019. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90020. unsigned num_apodizations;
  90021. FLAC__ApodizationSpecification apodizations[FLAC__MAX_APODIZATION_FUNCTIONS];
  90022. #endif
  90023. unsigned max_lpc_order;
  90024. unsigned qlp_coeff_precision;
  90025. FLAC__bool do_qlp_coeff_prec_search;
  90026. FLAC__bool do_exhaustive_model_search;
  90027. FLAC__bool do_escape_coding;
  90028. unsigned min_residual_partition_order;
  90029. unsigned max_residual_partition_order;
  90030. unsigned rice_parameter_search_dist;
  90031. FLAC__uint64 total_samples_estimate;
  90032. FLAC__StreamMetadata **metadata;
  90033. unsigned num_metadata_blocks;
  90034. FLAC__uint64 streaminfo_offset, seektable_offset, audio_offset;
  90035. #if FLAC__HAS_OGG
  90036. FLAC__OggEncoderAspect ogg_encoder_aspect;
  90037. #endif
  90038. } FLAC__StreamEncoderProtected;
  90039. #endif
  90040. /*** End of inlined file: stream_encoder.h ***/
  90041. #if FLAC__HAS_OGG
  90042. #include "include/private/ogg_helper.h"
  90043. #include "include/private/ogg_mapping.h"
  90044. #endif
  90045. /*** Start of inlined file: stream_encoder_framing.h ***/
  90046. #ifndef FLAC__PRIVATE__STREAM_ENCODER_FRAMING_H
  90047. #define FLAC__PRIVATE__STREAM_ENCODER_FRAMING_H
  90048. FLAC__bool FLAC__add_metadata_block(const FLAC__StreamMetadata *metadata, FLAC__BitWriter *bw);
  90049. FLAC__bool FLAC__frame_add_header(const FLAC__FrameHeader *header, FLAC__BitWriter *bw);
  90050. FLAC__bool FLAC__subframe_add_constant(const FLAC__Subframe_Constant *subframe, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
  90051. FLAC__bool FLAC__subframe_add_fixed(const FLAC__Subframe_Fixed *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
  90052. FLAC__bool FLAC__subframe_add_lpc(const FLAC__Subframe_LPC *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
  90053. FLAC__bool FLAC__subframe_add_verbatim(const FLAC__Subframe_Verbatim *subframe, unsigned samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
  90054. #endif
  90055. /*** End of inlined file: stream_encoder_framing.h ***/
  90056. /*** Start of inlined file: window.h ***/
  90057. #ifndef FLAC__PRIVATE__WINDOW_H
  90058. #define FLAC__PRIVATE__WINDOW_H
  90059. #ifdef HAVE_CONFIG_H
  90060. #include <config.h>
  90061. #endif
  90062. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90063. void FLAC__window_bartlett(FLAC__real *window, const FLAC__int32 L);
  90064. void FLAC__window_bartlett_hann(FLAC__real *window, const FLAC__int32 L);
  90065. void FLAC__window_blackman(FLAC__real *window, const FLAC__int32 L);
  90066. void FLAC__window_blackman_harris_4term_92db_sidelobe(FLAC__real *window, const FLAC__int32 L);
  90067. void FLAC__window_connes(FLAC__real *window, const FLAC__int32 L);
  90068. void FLAC__window_flattop(FLAC__real *window, const FLAC__int32 L);
  90069. void FLAC__window_gauss(FLAC__real *window, const FLAC__int32 L, const FLAC__real stddev); /* 0.0 < stddev <= 0.5 */
  90070. void FLAC__window_hamming(FLAC__real *window, const FLAC__int32 L);
  90071. void FLAC__window_hann(FLAC__real *window, const FLAC__int32 L);
  90072. void FLAC__window_kaiser_bessel(FLAC__real *window, const FLAC__int32 L);
  90073. void FLAC__window_nuttall(FLAC__real *window, const FLAC__int32 L);
  90074. void FLAC__window_rectangle(FLAC__real *window, const FLAC__int32 L);
  90075. void FLAC__window_triangle(FLAC__real *window, const FLAC__int32 L);
  90076. void FLAC__window_tukey(FLAC__real *window, const FLAC__int32 L, const FLAC__real p);
  90077. void FLAC__window_welch(FLAC__real *window, const FLAC__int32 L);
  90078. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  90079. #endif
  90080. /*** End of inlined file: window.h ***/
  90081. #ifndef FLaC__INLINE
  90082. #define FLaC__INLINE
  90083. #endif
  90084. #ifdef min
  90085. #undef min
  90086. #endif
  90087. #define min(x,y) ((x)<(y)?(x):(y))
  90088. #ifdef max
  90089. #undef max
  90090. #endif
  90091. #define max(x,y) ((x)>(y)?(x):(y))
  90092. #undef EXACT_RICE_BITS_CALCULATION
  90093. #undef ENABLE_RICE_PARAMETER_SEARCH
  90094. typedef struct {
  90095. FLAC__int32 *data[FLAC__MAX_CHANNELS];
  90096. unsigned size; /* of each data[] in samples */
  90097. unsigned tail;
  90098. } verify_input_fifo;
  90099. typedef struct {
  90100. const FLAC__byte *data;
  90101. unsigned capacity;
  90102. unsigned bytes;
  90103. } verify_output;
  90104. typedef enum {
  90105. ENCODER_IN_MAGIC = 0,
  90106. ENCODER_IN_METADATA = 1,
  90107. ENCODER_IN_AUDIO = 2
  90108. } EncoderStateHint;
  90109. static struct CompressionLevels {
  90110. FLAC__bool do_mid_side_stereo;
  90111. FLAC__bool loose_mid_side_stereo;
  90112. unsigned max_lpc_order;
  90113. unsigned qlp_coeff_precision;
  90114. FLAC__bool do_qlp_coeff_prec_search;
  90115. FLAC__bool do_escape_coding;
  90116. FLAC__bool do_exhaustive_model_search;
  90117. unsigned min_residual_partition_order;
  90118. unsigned max_residual_partition_order;
  90119. unsigned rice_parameter_search_dist;
  90120. } compression_levels_[] = {
  90121. { false, false, 0, 0, false, false, false, 0, 3, 0 },
  90122. { true , true , 0, 0, false, false, false, 0, 3, 0 },
  90123. { true , false, 0, 0, false, false, false, 0, 3, 0 },
  90124. { false, false, 6, 0, false, false, false, 0, 4, 0 },
  90125. { true , true , 8, 0, false, false, false, 0, 4, 0 },
  90126. { true , false, 8, 0, false, false, false, 0, 5, 0 },
  90127. { true , false, 8, 0, false, false, false, 0, 6, 0 },
  90128. { true , false, 8, 0, false, false, true , 0, 6, 0 },
  90129. { true , false, 12, 0, false, false, true , 0, 6, 0 }
  90130. };
  90131. static void set_defaults_enc(FLAC__StreamEncoder *encoder);
  90132. static void free_(FLAC__StreamEncoder *encoder);
  90133. static FLAC__bool resize_buffers_(FLAC__StreamEncoder *encoder, unsigned new_blocksize);
  90134. static FLAC__bool write_bitbuffer_(FLAC__StreamEncoder *encoder, unsigned samples, FLAC__bool is_last_block);
  90135. static FLAC__StreamEncoderWriteStatus write_frame_(FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, FLAC__bool is_last_block);
  90136. static void update_metadata_(const FLAC__StreamEncoder *encoder);
  90137. #if FLAC__HAS_OGG
  90138. static void update_ogg_metadata_(FLAC__StreamEncoder *encoder);
  90139. #endif
  90140. static FLAC__bool process_frame_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block, FLAC__bool is_last_block);
  90141. static FLAC__bool process_subframes_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block);
  90142. static FLAC__bool process_subframe_(
  90143. FLAC__StreamEncoder *encoder,
  90144. unsigned min_partition_order,
  90145. unsigned max_partition_order,
  90146. const FLAC__FrameHeader *frame_header,
  90147. unsigned subframe_bps,
  90148. const FLAC__int32 integer_signal[],
  90149. FLAC__Subframe *subframe[2],
  90150. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents[2],
  90151. FLAC__int32 *residual[2],
  90152. unsigned *best_subframe,
  90153. unsigned *best_bits
  90154. );
  90155. static FLAC__bool add_subframe_(
  90156. FLAC__StreamEncoder *encoder,
  90157. unsigned blocksize,
  90158. unsigned subframe_bps,
  90159. const FLAC__Subframe *subframe,
  90160. FLAC__BitWriter *frame
  90161. );
  90162. static unsigned evaluate_constant_subframe_(
  90163. FLAC__StreamEncoder *encoder,
  90164. const FLAC__int32 signal,
  90165. unsigned blocksize,
  90166. unsigned subframe_bps,
  90167. FLAC__Subframe *subframe
  90168. );
  90169. static unsigned evaluate_fixed_subframe_(
  90170. FLAC__StreamEncoder *encoder,
  90171. const FLAC__int32 signal[],
  90172. FLAC__int32 residual[],
  90173. FLAC__uint64 abs_residual_partition_sums[],
  90174. unsigned raw_bits_per_partition[],
  90175. unsigned blocksize,
  90176. unsigned subframe_bps,
  90177. unsigned order,
  90178. unsigned rice_parameter,
  90179. unsigned rice_parameter_limit,
  90180. unsigned min_partition_order,
  90181. unsigned max_partition_order,
  90182. FLAC__bool do_escape_coding,
  90183. unsigned rice_parameter_search_dist,
  90184. FLAC__Subframe *subframe,
  90185. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
  90186. );
  90187. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90188. static unsigned evaluate_lpc_subframe_(
  90189. FLAC__StreamEncoder *encoder,
  90190. const FLAC__int32 signal[],
  90191. FLAC__int32 residual[],
  90192. FLAC__uint64 abs_residual_partition_sums[],
  90193. unsigned raw_bits_per_partition[],
  90194. const FLAC__real lp_coeff[],
  90195. unsigned blocksize,
  90196. unsigned subframe_bps,
  90197. unsigned order,
  90198. unsigned qlp_coeff_precision,
  90199. unsigned rice_parameter,
  90200. unsigned rice_parameter_limit,
  90201. unsigned min_partition_order,
  90202. unsigned max_partition_order,
  90203. FLAC__bool do_escape_coding,
  90204. unsigned rice_parameter_search_dist,
  90205. FLAC__Subframe *subframe,
  90206. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
  90207. );
  90208. #endif
  90209. static unsigned evaluate_verbatim_subframe_(
  90210. FLAC__StreamEncoder *encoder,
  90211. const FLAC__int32 signal[],
  90212. unsigned blocksize,
  90213. unsigned subframe_bps,
  90214. FLAC__Subframe *subframe
  90215. );
  90216. static unsigned find_best_partition_order_(
  90217. struct FLAC__StreamEncoderPrivate *private_,
  90218. const FLAC__int32 residual[],
  90219. FLAC__uint64 abs_residual_partition_sums[],
  90220. unsigned raw_bits_per_partition[],
  90221. unsigned residual_samples,
  90222. unsigned predictor_order,
  90223. unsigned rice_parameter,
  90224. unsigned rice_parameter_limit,
  90225. unsigned min_partition_order,
  90226. unsigned max_partition_order,
  90227. unsigned bps,
  90228. FLAC__bool do_escape_coding,
  90229. unsigned rice_parameter_search_dist,
  90230. FLAC__EntropyCodingMethod *best_ecm
  90231. );
  90232. static void precompute_partition_info_sums_(
  90233. const FLAC__int32 residual[],
  90234. FLAC__uint64 abs_residual_partition_sums[],
  90235. unsigned residual_samples,
  90236. unsigned predictor_order,
  90237. unsigned min_partition_order,
  90238. unsigned max_partition_order,
  90239. unsigned bps
  90240. );
  90241. static void precompute_partition_info_escapes_(
  90242. const FLAC__int32 residual[],
  90243. unsigned raw_bits_per_partition[],
  90244. unsigned residual_samples,
  90245. unsigned predictor_order,
  90246. unsigned min_partition_order,
  90247. unsigned max_partition_order
  90248. );
  90249. static FLAC__bool set_partitioned_rice_(
  90250. #ifdef EXACT_RICE_BITS_CALCULATION
  90251. const FLAC__int32 residual[],
  90252. #endif
  90253. const FLAC__uint64 abs_residual_partition_sums[],
  90254. const unsigned raw_bits_per_partition[],
  90255. const unsigned residual_samples,
  90256. const unsigned predictor_order,
  90257. const unsigned suggested_rice_parameter,
  90258. const unsigned rice_parameter_limit,
  90259. const unsigned rice_parameter_search_dist,
  90260. const unsigned partition_order,
  90261. const FLAC__bool search_for_escapes,
  90262. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents,
  90263. unsigned *bits
  90264. );
  90265. static unsigned get_wasted_bits_(FLAC__int32 signal[], unsigned samples);
  90266. static void append_to_verify_fifo_(
  90267. verify_input_fifo *fifo,
  90268. const FLAC__int32 * const input[],
  90269. unsigned input_offset,
  90270. unsigned channels,
  90271. unsigned wide_samples
  90272. );
  90273. static void append_to_verify_fifo_interleaved_(
  90274. verify_input_fifo *fifo,
  90275. const FLAC__int32 input[],
  90276. unsigned input_offset,
  90277. unsigned channels,
  90278. unsigned wide_samples
  90279. );
  90280. static FLAC__StreamDecoderReadStatus verify_read_callback_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  90281. static FLAC__StreamDecoderWriteStatus verify_write_callback_(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
  90282. static void verify_metadata_callback_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data);
  90283. static void verify_error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data);
  90284. static FLAC__StreamEncoderReadStatus file_read_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  90285. static FLAC__StreamEncoderSeekStatus file_seek_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  90286. static FLAC__StreamEncoderTellStatus file_tell_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  90287. 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);
  90288. static FILE *get_binary_stdout_(void);
  90289. typedef struct FLAC__StreamEncoderPrivate {
  90290. unsigned input_capacity; /* current size (in samples) of the signal and residual buffers */
  90291. FLAC__int32 *integer_signal[FLAC__MAX_CHANNELS]; /* the integer version of the input signal */
  90292. FLAC__int32 *integer_signal_mid_side[2]; /* the integer version of the mid-side input signal (stereo only) */
  90293. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90294. FLAC__real *real_signal[FLAC__MAX_CHANNELS]; /* (@@@ currently unused) the floating-point version of the input signal */
  90295. FLAC__real *real_signal_mid_side[2]; /* (@@@ currently unused) the floating-point version of the mid-side input signal (stereo only) */
  90296. FLAC__real *window[FLAC__MAX_APODIZATION_FUNCTIONS]; /* the pre-computed floating-point window for each apodization function */
  90297. FLAC__real *windowed_signal; /* the integer_signal[] * current window[] */
  90298. #endif
  90299. unsigned subframe_bps[FLAC__MAX_CHANNELS]; /* the effective bits per sample of the input signal (stream bps - wasted bits) */
  90300. unsigned subframe_bps_mid_side[2]; /* the effective bits per sample of the mid-side input signal (stream bps - wasted bits + 0/1) */
  90301. FLAC__int32 *residual_workspace[FLAC__MAX_CHANNELS][2]; /* each channel has a candidate and best workspace where the subframe residual signals will be stored */
  90302. FLAC__int32 *residual_workspace_mid_side[2][2];
  90303. FLAC__Subframe subframe_workspace[FLAC__MAX_CHANNELS][2];
  90304. FLAC__Subframe subframe_workspace_mid_side[2][2];
  90305. FLAC__Subframe *subframe_workspace_ptr[FLAC__MAX_CHANNELS][2];
  90306. FLAC__Subframe *subframe_workspace_ptr_mid_side[2][2];
  90307. FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents_workspace[FLAC__MAX_CHANNELS][2];
  90308. FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents_workspace_mid_side[FLAC__MAX_CHANNELS][2];
  90309. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents_workspace_ptr[FLAC__MAX_CHANNELS][2];
  90310. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents_workspace_ptr_mid_side[FLAC__MAX_CHANNELS][2];
  90311. unsigned best_subframe[FLAC__MAX_CHANNELS]; /* index (0 or 1) into 2nd dimension of the above workspaces */
  90312. unsigned best_subframe_mid_side[2];
  90313. unsigned best_subframe_bits[FLAC__MAX_CHANNELS]; /* size in bits of the best subframe for each channel */
  90314. unsigned best_subframe_bits_mid_side[2];
  90315. FLAC__uint64 *abs_residual_partition_sums; /* workspace where the sum of abs(candidate residual) for each partition is stored */
  90316. unsigned *raw_bits_per_partition; /* workspace where the sum of silog2(candidate residual) for each partition is stored */
  90317. FLAC__BitWriter *frame; /* the current frame being worked on */
  90318. unsigned loose_mid_side_stereo_frames; /* rounded number of frames the encoder will use before trying both independent and mid/side frames again */
  90319. unsigned loose_mid_side_stereo_frame_count; /* number of frames using the current channel assignment */
  90320. FLAC__ChannelAssignment last_channel_assignment;
  90321. FLAC__StreamMetadata streaminfo; /* scratchpad for STREAMINFO as it is built */
  90322. FLAC__StreamMetadata_SeekTable *seek_table; /* pointer into encoder->protected_->metadata_ where the seek table is */
  90323. unsigned current_sample_number;
  90324. unsigned current_frame_number;
  90325. FLAC__MD5Context md5context;
  90326. FLAC__CPUInfo cpuinfo;
  90327. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90328. unsigned (*local_fixed_compute_best_predictor)(const FLAC__int32 data[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  90329. #else
  90330. unsigned (*local_fixed_compute_best_predictor)(const FLAC__int32 data[], unsigned data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  90331. #endif
  90332. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90333. void (*local_lpc_compute_autocorrelation)(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  90334. 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[]);
  90335. 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[]);
  90336. 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[]);
  90337. #endif
  90338. FLAC__bool use_wide_by_block; /* use slow 64-bit versions of some functions because of the block size */
  90339. FLAC__bool use_wide_by_partition; /* use slow 64-bit versions of some functions because of the min partition order and blocksize */
  90340. FLAC__bool use_wide_by_order; /* use slow 64-bit versions of some functions because of the lpc order */
  90341. FLAC__bool disable_constant_subframes;
  90342. FLAC__bool disable_fixed_subframes;
  90343. FLAC__bool disable_verbatim_subframes;
  90344. #if FLAC__HAS_OGG
  90345. FLAC__bool is_ogg;
  90346. #endif
  90347. FLAC__StreamEncoderReadCallback read_callback; /* currently only needed for Ogg FLAC */
  90348. FLAC__StreamEncoderSeekCallback seek_callback;
  90349. FLAC__StreamEncoderTellCallback tell_callback;
  90350. FLAC__StreamEncoderWriteCallback write_callback;
  90351. FLAC__StreamEncoderMetadataCallback metadata_callback;
  90352. FLAC__StreamEncoderProgressCallback progress_callback;
  90353. void *client_data;
  90354. unsigned first_seekpoint_to_check;
  90355. FILE *file; /* only used when encoding to a file */
  90356. FLAC__uint64 bytes_written;
  90357. FLAC__uint64 samples_written;
  90358. unsigned frames_written;
  90359. unsigned total_frames_estimate;
  90360. FLAC__int32 *integer_signal_unaligned[FLAC__MAX_CHANNELS];
  90361. FLAC__int32 *integer_signal_mid_side_unaligned[2];
  90362. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90363. FLAC__real *real_signal_unaligned[FLAC__MAX_CHANNELS]; /* (@@@ currently unused) */
  90364. FLAC__real *real_signal_mid_side_unaligned[2]; /* (@@@ currently unused) */
  90365. FLAC__real *window_unaligned[FLAC__MAX_APODIZATION_FUNCTIONS];
  90366. FLAC__real *windowed_signal_unaligned;
  90367. #endif
  90368. FLAC__int32 *residual_workspace_unaligned[FLAC__MAX_CHANNELS][2];
  90369. FLAC__int32 *residual_workspace_mid_side_unaligned[2][2];
  90370. FLAC__uint64 *abs_residual_partition_sums_unaligned;
  90371. unsigned *raw_bits_per_partition_unaligned;
  90372. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90373. FLAC__real lp_coeff[FLAC__MAX_LPC_ORDER][FLAC__MAX_LPC_ORDER]; /* from process_subframe_() */
  90374. #endif
  90375. FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents_extra[2]; /* from find_best_partition_order_() */
  90376. struct {
  90377. FLAC__StreamDecoder *decoder;
  90378. EncoderStateHint state_hint;
  90379. FLAC__bool needs_magic_hack;
  90380. verify_input_fifo input_fifo;
  90381. verify_output output;
  90382. struct {
  90383. FLAC__uint64 absolute_sample;
  90384. unsigned frame_number;
  90385. unsigned channel;
  90386. unsigned sample;
  90387. FLAC__int32 expected;
  90388. FLAC__int32 got;
  90389. } error_stats;
  90390. } verify;
  90391. FLAC__bool is_being_deleted; /* if true, call to ..._finish() from ..._delete() will not call the callbacks */
  90392. } FLAC__StreamEncoderPrivate;
  90393. FLAC_API const char * const FLAC__StreamEncoderStateString[] = {
  90394. "FLAC__STREAM_ENCODER_OK",
  90395. "FLAC__STREAM_ENCODER_UNINITIALIZED",
  90396. "FLAC__STREAM_ENCODER_OGG_ERROR",
  90397. "FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR",
  90398. "FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA",
  90399. "FLAC__STREAM_ENCODER_CLIENT_ERROR",
  90400. "FLAC__STREAM_ENCODER_IO_ERROR",
  90401. "FLAC__STREAM_ENCODER_FRAMING_ERROR",
  90402. "FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR"
  90403. };
  90404. FLAC_API const char * const FLAC__StreamEncoderInitStatusString[] = {
  90405. "FLAC__STREAM_ENCODER_INIT_STATUS_OK",
  90406. "FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR",
  90407. "FLAC__STREAM_ENCODER_INIT_STATUS_UNSUPPORTED_CONTAINER",
  90408. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_CALLBACKS",
  90409. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_NUMBER_OF_CHANNELS",
  90410. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BITS_PER_SAMPLE",
  90411. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_SAMPLE_RATE",
  90412. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BLOCK_SIZE",
  90413. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_MAX_LPC_ORDER",
  90414. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_QLP_COEFF_PRECISION",
  90415. "FLAC__STREAM_ENCODER_INIT_STATUS_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER",
  90416. "FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE",
  90417. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA",
  90418. "FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED"
  90419. };
  90420. FLAC_API const char * const FLAC__treamEncoderReadStatusString[] = {
  90421. "FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE",
  90422. "FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM",
  90423. "FLAC__STREAM_ENCODER_READ_STATUS_ABORT",
  90424. "FLAC__STREAM_ENCODER_READ_STATUS_UNSUPPORTED"
  90425. };
  90426. FLAC_API const char * const FLAC__StreamEncoderWriteStatusString[] = {
  90427. "FLAC__STREAM_ENCODER_WRITE_STATUS_OK",
  90428. "FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR"
  90429. };
  90430. FLAC_API const char * const FLAC__StreamEncoderSeekStatusString[] = {
  90431. "FLAC__STREAM_ENCODER_SEEK_STATUS_OK",
  90432. "FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR",
  90433. "FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED"
  90434. };
  90435. FLAC_API const char * const FLAC__StreamEncoderTellStatusString[] = {
  90436. "FLAC__STREAM_ENCODER_TELL_STATUS_OK",
  90437. "FLAC__STREAM_ENCODER_TELL_STATUS_ERROR",
  90438. "FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED"
  90439. };
  90440. static const unsigned OVERREAD_ = 1;
  90441. FLAC_API FLAC__StreamEncoder *FLAC__stream_encoder_new(void)
  90442. {
  90443. FLAC__StreamEncoder *encoder;
  90444. unsigned i;
  90445. FLAC__ASSERT(sizeof(int) >= 4); /* we want to die right away if this is not true */
  90446. encoder = (FLAC__StreamEncoder*)calloc(1, sizeof(FLAC__StreamEncoder));
  90447. if(encoder == 0) {
  90448. return 0;
  90449. }
  90450. encoder->protected_ = (FLAC__StreamEncoderProtected*)calloc(1, sizeof(FLAC__StreamEncoderProtected));
  90451. if(encoder->protected_ == 0) {
  90452. free(encoder);
  90453. return 0;
  90454. }
  90455. encoder->private_ = (FLAC__StreamEncoderPrivate*)calloc(1, sizeof(FLAC__StreamEncoderPrivate));
  90456. if(encoder->private_ == 0) {
  90457. free(encoder->protected_);
  90458. free(encoder);
  90459. return 0;
  90460. }
  90461. encoder->private_->frame = FLAC__bitwriter_new();
  90462. if(encoder->private_->frame == 0) {
  90463. free(encoder->private_);
  90464. free(encoder->protected_);
  90465. free(encoder);
  90466. return 0;
  90467. }
  90468. encoder->private_->file = 0;
  90469. set_defaults_enc(encoder);
  90470. encoder->private_->is_being_deleted = false;
  90471. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  90472. encoder->private_->subframe_workspace_ptr[i][0] = &encoder->private_->subframe_workspace[i][0];
  90473. encoder->private_->subframe_workspace_ptr[i][1] = &encoder->private_->subframe_workspace[i][1];
  90474. }
  90475. for(i = 0; i < 2; i++) {
  90476. encoder->private_->subframe_workspace_ptr_mid_side[i][0] = &encoder->private_->subframe_workspace_mid_side[i][0];
  90477. encoder->private_->subframe_workspace_ptr_mid_side[i][1] = &encoder->private_->subframe_workspace_mid_side[i][1];
  90478. }
  90479. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  90480. encoder->private_->partitioned_rice_contents_workspace_ptr[i][0] = &encoder->private_->partitioned_rice_contents_workspace[i][0];
  90481. encoder->private_->partitioned_rice_contents_workspace_ptr[i][1] = &encoder->private_->partitioned_rice_contents_workspace[i][1];
  90482. }
  90483. for(i = 0; i < 2; i++) {
  90484. encoder->private_->partitioned_rice_contents_workspace_ptr_mid_side[i][0] = &encoder->private_->partitioned_rice_contents_workspace_mid_side[i][0];
  90485. encoder->private_->partitioned_rice_contents_workspace_ptr_mid_side[i][1] = &encoder->private_->partitioned_rice_contents_workspace_mid_side[i][1];
  90486. }
  90487. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  90488. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace[i][0]);
  90489. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace[i][1]);
  90490. }
  90491. for(i = 0; i < 2; i++) {
  90492. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][0]);
  90493. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][1]);
  90494. }
  90495. for(i = 0; i < 2; i++)
  90496. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_extra[i]);
  90497. encoder->protected_->state = FLAC__STREAM_ENCODER_UNINITIALIZED;
  90498. return encoder;
  90499. }
  90500. FLAC_API void FLAC__stream_encoder_delete(FLAC__StreamEncoder *encoder)
  90501. {
  90502. unsigned i;
  90503. FLAC__ASSERT(0 != encoder);
  90504. FLAC__ASSERT(0 != encoder->protected_);
  90505. FLAC__ASSERT(0 != encoder->private_);
  90506. FLAC__ASSERT(0 != encoder->private_->frame);
  90507. encoder->private_->is_being_deleted = true;
  90508. (void)FLAC__stream_encoder_finish(encoder);
  90509. if(0 != encoder->private_->verify.decoder)
  90510. FLAC__stream_decoder_delete(encoder->private_->verify.decoder);
  90511. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  90512. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace[i][0]);
  90513. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace[i][1]);
  90514. }
  90515. for(i = 0; i < 2; i++) {
  90516. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][0]);
  90517. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][1]);
  90518. }
  90519. for(i = 0; i < 2; i++)
  90520. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_extra[i]);
  90521. FLAC__bitwriter_delete(encoder->private_->frame);
  90522. free(encoder->private_);
  90523. free(encoder->protected_);
  90524. free(encoder);
  90525. }
  90526. static FLAC__StreamEncoderInitStatus init_stream_internal_enc(
  90527. FLAC__StreamEncoder *encoder,
  90528. FLAC__StreamEncoderReadCallback read_callback,
  90529. FLAC__StreamEncoderWriteCallback write_callback,
  90530. FLAC__StreamEncoderSeekCallback seek_callback,
  90531. FLAC__StreamEncoderTellCallback tell_callback,
  90532. FLAC__StreamEncoderMetadataCallback metadata_callback,
  90533. void *client_data,
  90534. FLAC__bool is_ogg
  90535. )
  90536. {
  90537. unsigned i;
  90538. FLAC__bool metadata_has_seektable, metadata_has_vorbis_comment, metadata_picture_has_type1, metadata_picture_has_type2;
  90539. FLAC__ASSERT(0 != encoder);
  90540. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90541. return FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED;
  90542. #if !FLAC__HAS_OGG
  90543. if(is_ogg)
  90544. return FLAC__STREAM_ENCODER_INIT_STATUS_UNSUPPORTED_CONTAINER;
  90545. #endif
  90546. if(0 == write_callback || (seek_callback && 0 == tell_callback))
  90547. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_CALLBACKS;
  90548. if(encoder->protected_->channels == 0 || encoder->protected_->channels > FLAC__MAX_CHANNELS)
  90549. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_NUMBER_OF_CHANNELS;
  90550. if(encoder->protected_->channels != 2) {
  90551. encoder->protected_->do_mid_side_stereo = false;
  90552. encoder->protected_->loose_mid_side_stereo = false;
  90553. }
  90554. else if(!encoder->protected_->do_mid_side_stereo)
  90555. encoder->protected_->loose_mid_side_stereo = false;
  90556. if(encoder->protected_->bits_per_sample >= 32)
  90557. encoder->protected_->do_mid_side_stereo = false; /* since we currenty do 32-bit math, the side channel would have 33 bps and overflow */
  90558. if(encoder->protected_->bits_per_sample < FLAC__MIN_BITS_PER_SAMPLE || encoder->protected_->bits_per_sample > FLAC__REFERENCE_CODEC_MAX_BITS_PER_SAMPLE)
  90559. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BITS_PER_SAMPLE;
  90560. if(!FLAC__format_sample_rate_is_valid(encoder->protected_->sample_rate))
  90561. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_SAMPLE_RATE;
  90562. if(encoder->protected_->blocksize == 0) {
  90563. if(encoder->protected_->max_lpc_order == 0)
  90564. encoder->protected_->blocksize = 1152;
  90565. else
  90566. encoder->protected_->blocksize = 4096;
  90567. }
  90568. if(encoder->protected_->blocksize < FLAC__MIN_BLOCK_SIZE || encoder->protected_->blocksize > FLAC__MAX_BLOCK_SIZE)
  90569. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BLOCK_SIZE;
  90570. if(encoder->protected_->max_lpc_order > FLAC__MAX_LPC_ORDER)
  90571. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_MAX_LPC_ORDER;
  90572. if(encoder->protected_->blocksize < encoder->protected_->max_lpc_order)
  90573. return FLAC__STREAM_ENCODER_INIT_STATUS_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER;
  90574. if(encoder->protected_->qlp_coeff_precision == 0) {
  90575. if(encoder->protected_->bits_per_sample < 16) {
  90576. encoder->protected_->qlp_coeff_precision = max(FLAC__MIN_QLP_COEFF_PRECISION, 2 + encoder->protected_->bits_per_sample / 2);
  90577. }
  90578. else if(encoder->protected_->bits_per_sample == 16) {
  90579. if(encoder->protected_->blocksize <= 192)
  90580. encoder->protected_->qlp_coeff_precision = 7;
  90581. else if(encoder->protected_->blocksize <= 384)
  90582. encoder->protected_->qlp_coeff_precision = 8;
  90583. else if(encoder->protected_->blocksize <= 576)
  90584. encoder->protected_->qlp_coeff_precision = 9;
  90585. else if(encoder->protected_->blocksize <= 1152)
  90586. encoder->protected_->qlp_coeff_precision = 10;
  90587. else if(encoder->protected_->blocksize <= 2304)
  90588. encoder->protected_->qlp_coeff_precision = 11;
  90589. else if(encoder->protected_->blocksize <= 4608)
  90590. encoder->protected_->qlp_coeff_precision = 12;
  90591. else
  90592. encoder->protected_->qlp_coeff_precision = 13;
  90593. }
  90594. else {
  90595. if(encoder->protected_->blocksize <= 384)
  90596. encoder->protected_->qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION-2;
  90597. else if(encoder->protected_->blocksize <= 1152)
  90598. encoder->protected_->qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION-1;
  90599. else
  90600. encoder->protected_->qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION;
  90601. }
  90602. FLAC__ASSERT(encoder->protected_->qlp_coeff_precision <= FLAC__MAX_QLP_COEFF_PRECISION);
  90603. }
  90604. else if(encoder->protected_->qlp_coeff_precision < FLAC__MIN_QLP_COEFF_PRECISION || encoder->protected_->qlp_coeff_precision > FLAC__MAX_QLP_COEFF_PRECISION)
  90605. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_QLP_COEFF_PRECISION;
  90606. if(encoder->protected_->streamable_subset) {
  90607. if(
  90608. encoder->protected_->blocksize != 192 &&
  90609. encoder->protected_->blocksize != 576 &&
  90610. encoder->protected_->blocksize != 1152 &&
  90611. encoder->protected_->blocksize != 2304 &&
  90612. encoder->protected_->blocksize != 4608 &&
  90613. encoder->protected_->blocksize != 256 &&
  90614. encoder->protected_->blocksize != 512 &&
  90615. encoder->protected_->blocksize != 1024 &&
  90616. encoder->protected_->blocksize != 2048 &&
  90617. encoder->protected_->blocksize != 4096 &&
  90618. encoder->protected_->blocksize != 8192 &&
  90619. encoder->protected_->blocksize != 16384
  90620. )
  90621. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90622. if(!FLAC__format_sample_rate_is_subset(encoder->protected_->sample_rate))
  90623. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90624. if(
  90625. encoder->protected_->bits_per_sample != 8 &&
  90626. encoder->protected_->bits_per_sample != 12 &&
  90627. encoder->protected_->bits_per_sample != 16 &&
  90628. encoder->protected_->bits_per_sample != 20 &&
  90629. encoder->protected_->bits_per_sample != 24
  90630. )
  90631. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90632. if(encoder->protected_->max_residual_partition_order > FLAC__SUBSET_MAX_RICE_PARTITION_ORDER)
  90633. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90634. if(
  90635. encoder->protected_->sample_rate <= 48000 &&
  90636. (
  90637. encoder->protected_->blocksize > FLAC__SUBSET_MAX_BLOCK_SIZE_48000HZ ||
  90638. encoder->protected_->max_lpc_order > FLAC__SUBSET_MAX_LPC_ORDER_48000HZ
  90639. )
  90640. ) {
  90641. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90642. }
  90643. }
  90644. if(encoder->protected_->max_residual_partition_order >= (1u << FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
  90645. encoder->protected_->max_residual_partition_order = (1u << FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN) - 1;
  90646. if(encoder->protected_->min_residual_partition_order >= encoder->protected_->max_residual_partition_order)
  90647. encoder->protected_->min_residual_partition_order = encoder->protected_->max_residual_partition_order;
  90648. #if FLAC__HAS_OGG
  90649. if(is_ogg && 0 != encoder->protected_->metadata && encoder->protected_->num_metadata_blocks > 1) {
  90650. unsigned i;
  90651. for(i = 1; i < encoder->protected_->num_metadata_blocks; i++) {
  90652. if(0 != encoder->protected_->metadata[i] && encoder->protected_->metadata[i]->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
  90653. FLAC__StreamMetadata *vc = encoder->protected_->metadata[i];
  90654. for( ; i > 0; i--)
  90655. encoder->protected_->metadata[i] = encoder->protected_->metadata[i-1];
  90656. encoder->protected_->metadata[0] = vc;
  90657. break;
  90658. }
  90659. }
  90660. }
  90661. #endif
  90662. if(0 != encoder->protected_->metadata && encoder->protected_->num_metadata_blocks > 0) {
  90663. unsigned i;
  90664. for(i = 0; i < encoder->protected_->num_metadata_blocks; i++) {
  90665. if(0 != encoder->protected_->metadata[i] && encoder->protected_->metadata[i]->type == FLAC__METADATA_TYPE_SEEKTABLE) {
  90666. encoder->private_->seek_table = &encoder->protected_->metadata[i]->data.seek_table;
  90667. break; /* take only the first one */
  90668. }
  90669. }
  90670. }
  90671. if(0 == encoder->protected_->metadata && encoder->protected_->num_metadata_blocks > 0)
  90672. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90673. metadata_has_seektable = false;
  90674. metadata_has_vorbis_comment = false;
  90675. metadata_picture_has_type1 = false;
  90676. metadata_picture_has_type2 = false;
  90677. for(i = 0; i < encoder->protected_->num_metadata_blocks; i++) {
  90678. const FLAC__StreamMetadata *m = encoder->protected_->metadata[i];
  90679. if(m->type == FLAC__METADATA_TYPE_STREAMINFO)
  90680. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90681. else if(m->type == FLAC__METADATA_TYPE_SEEKTABLE) {
  90682. if(metadata_has_seektable) /* only one is allowed */
  90683. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90684. metadata_has_seektable = true;
  90685. if(!FLAC__format_seektable_is_legal(&m->data.seek_table))
  90686. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90687. }
  90688. else if(m->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
  90689. if(metadata_has_vorbis_comment) /* only one is allowed */
  90690. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90691. metadata_has_vorbis_comment = true;
  90692. }
  90693. else if(m->type == FLAC__METADATA_TYPE_CUESHEET) {
  90694. if(!FLAC__format_cuesheet_is_legal(&m->data.cue_sheet, m->data.cue_sheet.is_cd, /*violation=*/0))
  90695. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90696. }
  90697. else if(m->type == FLAC__METADATA_TYPE_PICTURE) {
  90698. if(!FLAC__format_picture_is_legal(&m->data.picture, /*violation=*/0))
  90699. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90700. if(m->data.picture.type == FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON_STANDARD) {
  90701. if(metadata_picture_has_type1) /* there should only be 1 per stream */
  90702. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90703. metadata_picture_has_type1 = true;
  90704. if(
  90705. m->data.picture.type == FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON_STANDARD &&
  90706. (
  90707. (strcmp(m->data.picture.mime_type, "image/png") && strcmp(m->data.picture.mime_type, "-->")) ||
  90708. m->data.picture.width != 32 ||
  90709. m->data.picture.height != 32
  90710. )
  90711. )
  90712. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90713. }
  90714. else if(m->data.picture.type == FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON) {
  90715. if(metadata_picture_has_type2) /* there should only be 1 per stream */
  90716. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90717. metadata_picture_has_type2 = true;
  90718. }
  90719. }
  90720. }
  90721. encoder->private_->input_capacity = 0;
  90722. for(i = 0; i < encoder->protected_->channels; i++) {
  90723. encoder->private_->integer_signal_unaligned[i] = encoder->private_->integer_signal[i] = 0;
  90724. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90725. encoder->private_->real_signal_unaligned[i] = encoder->private_->real_signal[i] = 0;
  90726. #endif
  90727. }
  90728. for(i = 0; i < 2; i++) {
  90729. encoder->private_->integer_signal_mid_side_unaligned[i] = encoder->private_->integer_signal_mid_side[i] = 0;
  90730. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90731. encoder->private_->real_signal_mid_side_unaligned[i] = encoder->private_->real_signal_mid_side[i] = 0;
  90732. #endif
  90733. }
  90734. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90735. for(i = 0; i < encoder->protected_->num_apodizations; i++)
  90736. encoder->private_->window_unaligned[i] = encoder->private_->window[i] = 0;
  90737. encoder->private_->windowed_signal_unaligned = encoder->private_->windowed_signal = 0;
  90738. #endif
  90739. for(i = 0; i < encoder->protected_->channels; i++) {
  90740. encoder->private_->residual_workspace_unaligned[i][0] = encoder->private_->residual_workspace[i][0] = 0;
  90741. encoder->private_->residual_workspace_unaligned[i][1] = encoder->private_->residual_workspace[i][1] = 0;
  90742. encoder->private_->best_subframe[i] = 0;
  90743. }
  90744. for(i = 0; i < 2; i++) {
  90745. encoder->private_->residual_workspace_mid_side_unaligned[i][0] = encoder->private_->residual_workspace_mid_side[i][0] = 0;
  90746. encoder->private_->residual_workspace_mid_side_unaligned[i][1] = encoder->private_->residual_workspace_mid_side[i][1] = 0;
  90747. encoder->private_->best_subframe_mid_side[i] = 0;
  90748. }
  90749. encoder->private_->abs_residual_partition_sums_unaligned = encoder->private_->abs_residual_partition_sums = 0;
  90750. encoder->private_->raw_bits_per_partition_unaligned = encoder->private_->raw_bits_per_partition = 0;
  90751. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90752. encoder->private_->loose_mid_side_stereo_frames = (unsigned)((FLAC__double)encoder->protected_->sample_rate * 0.4 / (FLAC__double)encoder->protected_->blocksize + 0.5);
  90753. #else
  90754. FLAC__ASSERT(FLAC__MAX_SAMPLE_RATE <= 655350);
  90755. FLAC__ASSERT(FLAC__MAX_BLOCK_SIZE <= 65535);
  90756. FLAC__ASSERT(encoder->protected_->sample_rate <= 655350);
  90757. FLAC__ASSERT(encoder->protected_->blocksize <= 65535);
  90758. 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);
  90759. #endif
  90760. if(encoder->private_->loose_mid_side_stereo_frames == 0)
  90761. encoder->private_->loose_mid_side_stereo_frames = 1;
  90762. encoder->private_->loose_mid_side_stereo_frame_count = 0;
  90763. encoder->private_->current_sample_number = 0;
  90764. encoder->private_->current_frame_number = 0;
  90765. encoder->private_->use_wide_by_block = (encoder->protected_->bits_per_sample + FLAC__bitmath_ilog2(encoder->protected_->blocksize)+1 > 30);
  90766. 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? */
  90767. encoder->private_->use_wide_by_partition = (false); /*@@@ need to set this */
  90768. FLAC__cpu_info(&encoder->private_->cpuinfo);
  90769. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90770. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation;
  90771. #endif
  90772. encoder->private_->local_fixed_compute_best_predictor = FLAC__fixed_compute_best_predictor;
  90773. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90774. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients;
  90775. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_64bit = FLAC__lpc_compute_residual_from_qlp_coefficients_wide;
  90776. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients;
  90777. #endif
  90778. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90779. # ifndef FLAC__NO_ASM
  90780. if(encoder->private_->cpuinfo.use_asm) {
  90781. # ifdef FLAC__CPU_IA32
  90782. FLAC__ASSERT(encoder->private_->cpuinfo.type == FLAC__CPUINFO_TYPE_IA32);
  90783. # ifdef FLAC__HAS_NASM
  90784. if(encoder->private_->cpuinfo.data.ia32.sse) {
  90785. if(encoder->protected_->max_lpc_order < 4)
  90786. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_4;
  90787. else if(encoder->protected_->max_lpc_order < 8)
  90788. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_8;
  90789. else if(encoder->protected_->max_lpc_order < 12)
  90790. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_12;
  90791. else
  90792. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32;
  90793. }
  90794. else if(encoder->private_->cpuinfo.data.ia32._3dnow)
  90795. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_3dnow;
  90796. else
  90797. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32;
  90798. if(encoder->private_->cpuinfo.data.ia32.mmx) {
  90799. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32;
  90800. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32_mmx;
  90801. }
  90802. else {
  90803. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32;
  90804. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32;
  90805. }
  90806. if(encoder->private_->cpuinfo.data.ia32.mmx && encoder->private_->cpuinfo.data.ia32.cmov)
  90807. encoder->private_->local_fixed_compute_best_predictor = FLAC__fixed_compute_best_predictor_asm_ia32_mmx_cmov;
  90808. # endif /* FLAC__HAS_NASM */
  90809. # endif /* FLAC__CPU_IA32 */
  90810. }
  90811. # endif /* !FLAC__NO_ASM */
  90812. #endif /* !FLAC__INTEGER_ONLY_LIBRARY */
  90813. if(encoder->private_->use_wide_by_block) {
  90814. encoder->private_->local_fixed_compute_best_predictor = FLAC__fixed_compute_best_predictor_wide;
  90815. }
  90816. encoder->protected_->state = FLAC__STREAM_ENCODER_OK;
  90817. #if FLAC__HAS_OGG
  90818. encoder->private_->is_ogg = is_ogg;
  90819. if(is_ogg && !FLAC__ogg_encoder_aspect_init(&encoder->protected_->ogg_encoder_aspect)) {
  90820. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  90821. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90822. }
  90823. #endif
  90824. encoder->private_->read_callback = read_callback;
  90825. encoder->private_->write_callback = write_callback;
  90826. encoder->private_->seek_callback = seek_callback;
  90827. encoder->private_->tell_callback = tell_callback;
  90828. encoder->private_->metadata_callback = metadata_callback;
  90829. encoder->private_->client_data = client_data;
  90830. if(!resize_buffers_(encoder, encoder->protected_->blocksize)) {
  90831. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90832. }
  90833. if(!FLAC__bitwriter_init(encoder->private_->frame)) {
  90834. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  90835. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90836. }
  90837. if(encoder->protected_->verify) {
  90838. encoder->private_->verify.input_fifo.size = encoder->protected_->blocksize+OVERREAD_;
  90839. for(i = 0; i < encoder->protected_->channels; i++) {
  90840. 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))) {
  90841. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  90842. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90843. }
  90844. }
  90845. encoder->private_->verify.input_fifo.tail = 0;
  90846. encoder->private_->verify.decoder = FLAC__stream_decoder_new();
  90847. if(0 == encoder->private_->verify.decoder) {
  90848. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
  90849. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90850. }
  90851. 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) {
  90852. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
  90853. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90854. }
  90855. }
  90856. encoder->private_->verify.error_stats.absolute_sample = 0;
  90857. encoder->private_->verify.error_stats.frame_number = 0;
  90858. encoder->private_->verify.error_stats.channel = 0;
  90859. encoder->private_->verify.error_stats.sample = 0;
  90860. encoder->private_->verify.error_stats.expected = 0;
  90861. encoder->private_->verify.error_stats.got = 0;
  90862. encoder->private_->first_seekpoint_to_check = 0;
  90863. encoder->private_->samples_written = 0;
  90864. encoder->protected_->streaminfo_offset = 0;
  90865. encoder->protected_->seektable_offset = 0;
  90866. encoder->protected_->audio_offset = 0;
  90867. if(encoder->protected_->verify)
  90868. encoder->private_->verify.state_hint = ENCODER_IN_MAGIC;
  90869. if(!FLAC__bitwriter_write_raw_uint32(encoder->private_->frame, FLAC__STREAM_SYNC, FLAC__STREAM_SYNC_LEN)) {
  90870. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  90871. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90872. }
  90873. if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
  90874. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90875. }
  90876. if(encoder->protected_->verify)
  90877. encoder->private_->verify.state_hint = ENCODER_IN_METADATA;
  90878. encoder->private_->streaminfo.type = FLAC__METADATA_TYPE_STREAMINFO;
  90879. encoder->private_->streaminfo.is_last = false; /* we will have at a minimum a VORBIS_COMMENT afterwards */
  90880. encoder->private_->streaminfo.length = FLAC__STREAM_METADATA_STREAMINFO_LENGTH;
  90881. encoder->private_->streaminfo.data.stream_info.min_blocksize = encoder->protected_->blocksize; /* this encoder uses the same blocksize for the whole stream */
  90882. encoder->private_->streaminfo.data.stream_info.max_blocksize = encoder->protected_->blocksize;
  90883. encoder->private_->streaminfo.data.stream_info.min_framesize = 0; /* we don't know this yet; have to fill it in later */
  90884. encoder->private_->streaminfo.data.stream_info.max_framesize = 0; /* we don't know this yet; have to fill it in later */
  90885. encoder->private_->streaminfo.data.stream_info.sample_rate = encoder->protected_->sample_rate;
  90886. encoder->private_->streaminfo.data.stream_info.channels = encoder->protected_->channels;
  90887. encoder->private_->streaminfo.data.stream_info.bits_per_sample = encoder->protected_->bits_per_sample;
  90888. encoder->private_->streaminfo.data.stream_info.total_samples = encoder->protected_->total_samples_estimate; /* we will replace this later with the real total */
  90889. memset(encoder->private_->streaminfo.data.stream_info.md5sum, 0, 16); /* we don't know this yet; have to fill it in later */
  90890. if(encoder->protected_->do_md5)
  90891. FLAC__MD5Init(&encoder->private_->md5context);
  90892. if(!FLAC__add_metadata_block(&encoder->private_->streaminfo, encoder->private_->frame)) {
  90893. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  90894. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90895. }
  90896. if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
  90897. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90898. }
  90899. encoder->private_->streaminfo.data.stream_info.min_framesize = (1u << FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN) - 1;
  90900. encoder->private_->streaminfo.data.stream_info.total_samples = 0;
  90901. if(!metadata_has_vorbis_comment) {
  90902. FLAC__StreamMetadata vorbis_comment;
  90903. vorbis_comment.type = FLAC__METADATA_TYPE_VORBIS_COMMENT;
  90904. vorbis_comment.is_last = (encoder->protected_->num_metadata_blocks == 0);
  90905. vorbis_comment.length = 4 + 4; /* MAGIC NUMBER */
  90906. vorbis_comment.data.vorbis_comment.vendor_string.length = 0;
  90907. vorbis_comment.data.vorbis_comment.vendor_string.entry = 0;
  90908. vorbis_comment.data.vorbis_comment.num_comments = 0;
  90909. vorbis_comment.data.vorbis_comment.comments = 0;
  90910. if(!FLAC__add_metadata_block(&vorbis_comment, encoder->private_->frame)) {
  90911. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  90912. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90913. }
  90914. if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
  90915. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90916. }
  90917. }
  90918. for(i = 0; i < encoder->protected_->num_metadata_blocks; i++) {
  90919. encoder->protected_->metadata[i]->is_last = (i == encoder->protected_->num_metadata_blocks - 1);
  90920. if(!FLAC__add_metadata_block(encoder->protected_->metadata[i], encoder->private_->frame)) {
  90921. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  90922. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90923. }
  90924. if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
  90925. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90926. }
  90927. }
  90928. 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 */
  90929. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  90930. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90931. }
  90932. if(encoder->protected_->verify)
  90933. encoder->private_->verify.state_hint = ENCODER_IN_AUDIO;
  90934. return FLAC__STREAM_ENCODER_INIT_STATUS_OK;
  90935. }
  90936. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_stream(
  90937. FLAC__StreamEncoder *encoder,
  90938. FLAC__StreamEncoderWriteCallback write_callback,
  90939. FLAC__StreamEncoderSeekCallback seek_callback,
  90940. FLAC__StreamEncoderTellCallback tell_callback,
  90941. FLAC__StreamEncoderMetadataCallback metadata_callback,
  90942. void *client_data
  90943. )
  90944. {
  90945. return init_stream_internal_enc(
  90946. encoder,
  90947. 0,
  90948. write_callback,
  90949. seek_callback,
  90950. tell_callback,
  90951. metadata_callback,
  90952. client_data,
  90953. false
  90954. );
  90955. }
  90956. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_stream(
  90957. FLAC__StreamEncoder *encoder,
  90958. FLAC__StreamEncoderReadCallback read_callback,
  90959. FLAC__StreamEncoderWriteCallback write_callback,
  90960. FLAC__StreamEncoderSeekCallback seek_callback,
  90961. FLAC__StreamEncoderTellCallback tell_callback,
  90962. FLAC__StreamEncoderMetadataCallback metadata_callback,
  90963. void *client_data
  90964. )
  90965. {
  90966. return init_stream_internal_enc(
  90967. encoder,
  90968. read_callback,
  90969. write_callback,
  90970. seek_callback,
  90971. tell_callback,
  90972. metadata_callback,
  90973. client_data,
  90974. true
  90975. );
  90976. }
  90977. static FLAC__StreamEncoderInitStatus init_FILE_internal_enc(
  90978. FLAC__StreamEncoder *encoder,
  90979. FILE *file,
  90980. FLAC__StreamEncoderProgressCallback progress_callback,
  90981. void *client_data,
  90982. FLAC__bool is_ogg
  90983. )
  90984. {
  90985. FLAC__StreamEncoderInitStatus init_status;
  90986. FLAC__ASSERT(0 != encoder);
  90987. FLAC__ASSERT(0 != file);
  90988. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90989. return FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED;
  90990. if(file == 0) {
  90991. encoder->protected_->state = FLAC__STREAM_ENCODER_IO_ERROR;
  90992. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90993. }
  90994. if(file == stdout)
  90995. file = get_binary_stdout_(); /* just to be safe */
  90996. encoder->private_->file = file;
  90997. encoder->private_->progress_callback = progress_callback;
  90998. encoder->private_->bytes_written = 0;
  90999. encoder->private_->samples_written = 0;
  91000. encoder->private_->frames_written = 0;
  91001. init_status = init_stream_internal_enc(
  91002. encoder,
  91003. encoder->private_->file == stdout? 0 : is_ogg? file_read_callback_enc : 0,
  91004. file_write_callback_,
  91005. encoder->private_->file == stdout? 0 : file_seek_callback_enc,
  91006. encoder->private_->file == stdout? 0 : file_tell_callback_enc,
  91007. 0,
  91008. client_data,
  91009. is_ogg
  91010. );
  91011. if(init_status != FLAC__STREAM_ENCODER_INIT_STATUS_OK) {
  91012. return init_status;
  91013. }
  91014. {
  91015. unsigned blocksize = FLAC__stream_encoder_get_blocksize(encoder);
  91016. FLAC__ASSERT(blocksize != 0);
  91017. encoder->private_->total_frames_estimate = (unsigned)((FLAC__stream_encoder_get_total_samples_estimate(encoder) + blocksize - 1) / blocksize);
  91018. }
  91019. return init_status;
  91020. }
  91021. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_FILE(
  91022. FLAC__StreamEncoder *encoder,
  91023. FILE *file,
  91024. FLAC__StreamEncoderProgressCallback progress_callback,
  91025. void *client_data
  91026. )
  91027. {
  91028. return init_FILE_internal_enc(encoder, file, progress_callback, client_data, /*is_ogg=*/false);
  91029. }
  91030. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_FILE(
  91031. FLAC__StreamEncoder *encoder,
  91032. FILE *file,
  91033. FLAC__StreamEncoderProgressCallback progress_callback,
  91034. void *client_data
  91035. )
  91036. {
  91037. return init_FILE_internal_enc(encoder, file, progress_callback, client_data, /*is_ogg=*/true);
  91038. }
  91039. static FLAC__StreamEncoderInitStatus init_file_internal_enc(
  91040. FLAC__StreamEncoder *encoder,
  91041. const char *filename,
  91042. FLAC__StreamEncoderProgressCallback progress_callback,
  91043. void *client_data,
  91044. FLAC__bool is_ogg
  91045. )
  91046. {
  91047. FILE *file;
  91048. FLAC__ASSERT(0 != encoder);
  91049. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91050. return FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED;
  91051. file = filename? fopen(filename, "w+b") : stdout;
  91052. if(file == 0) {
  91053. encoder->protected_->state = FLAC__STREAM_ENCODER_IO_ERROR;
  91054. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  91055. }
  91056. return init_FILE_internal_enc(encoder, file, progress_callback, client_data, is_ogg);
  91057. }
  91058. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_file(
  91059. FLAC__StreamEncoder *encoder,
  91060. const char *filename,
  91061. FLAC__StreamEncoderProgressCallback progress_callback,
  91062. void *client_data
  91063. )
  91064. {
  91065. return init_file_internal_enc(encoder, filename, progress_callback, client_data, /*is_ogg=*/false);
  91066. }
  91067. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_file(
  91068. FLAC__StreamEncoder *encoder,
  91069. const char *filename,
  91070. FLAC__StreamEncoderProgressCallback progress_callback,
  91071. void *client_data
  91072. )
  91073. {
  91074. return init_file_internal_enc(encoder, filename, progress_callback, client_data, /*is_ogg=*/true);
  91075. }
  91076. FLAC_API FLAC__bool FLAC__stream_encoder_finish(FLAC__StreamEncoder *encoder)
  91077. {
  91078. FLAC__bool error = false;
  91079. FLAC__ASSERT(0 != encoder);
  91080. FLAC__ASSERT(0 != encoder->private_);
  91081. FLAC__ASSERT(0 != encoder->protected_);
  91082. if(encoder->protected_->state == FLAC__STREAM_ENCODER_UNINITIALIZED)
  91083. return true;
  91084. if(encoder->protected_->state == FLAC__STREAM_ENCODER_OK && !encoder->private_->is_being_deleted) {
  91085. if(encoder->private_->current_sample_number != 0) {
  91086. const FLAC__bool is_fractional_block = encoder->protected_->blocksize != encoder->private_->current_sample_number;
  91087. encoder->protected_->blocksize = encoder->private_->current_sample_number;
  91088. if(!process_frame_(encoder, is_fractional_block, /*is_last_block=*/true))
  91089. error = true;
  91090. }
  91091. }
  91092. if(encoder->protected_->do_md5)
  91093. FLAC__MD5Final(encoder->private_->streaminfo.data.stream_info.md5sum, &encoder->private_->md5context);
  91094. if(!encoder->private_->is_being_deleted) {
  91095. if(encoder->protected_->state == FLAC__STREAM_ENCODER_OK) {
  91096. if(encoder->private_->seek_callback) {
  91097. #if FLAC__HAS_OGG
  91098. if(encoder->private_->is_ogg)
  91099. update_ogg_metadata_(encoder);
  91100. else
  91101. #endif
  91102. update_metadata_(encoder);
  91103. if(encoder->protected_->state != FLAC__STREAM_ENCODER_OK)
  91104. error = true;
  91105. }
  91106. if(encoder->private_->metadata_callback)
  91107. encoder->private_->metadata_callback(encoder, &encoder->private_->streaminfo, encoder->private_->client_data);
  91108. }
  91109. if(encoder->protected_->verify && 0 != encoder->private_->verify.decoder && !FLAC__stream_decoder_finish(encoder->private_->verify.decoder)) {
  91110. if(!error)
  91111. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA;
  91112. error = true;
  91113. }
  91114. }
  91115. if(0 != encoder->private_->file) {
  91116. if(encoder->private_->file != stdout)
  91117. fclose(encoder->private_->file);
  91118. encoder->private_->file = 0;
  91119. }
  91120. #if FLAC__HAS_OGG
  91121. if(encoder->private_->is_ogg)
  91122. FLAC__ogg_encoder_aspect_finish(&encoder->protected_->ogg_encoder_aspect);
  91123. #endif
  91124. free_(encoder);
  91125. set_defaults_enc(encoder);
  91126. if(!error)
  91127. encoder->protected_->state = FLAC__STREAM_ENCODER_UNINITIALIZED;
  91128. return !error;
  91129. }
  91130. FLAC_API FLAC__bool FLAC__stream_encoder_set_ogg_serial_number(FLAC__StreamEncoder *encoder, long value)
  91131. {
  91132. FLAC__ASSERT(0 != encoder);
  91133. FLAC__ASSERT(0 != encoder->private_);
  91134. FLAC__ASSERT(0 != encoder->protected_);
  91135. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91136. return false;
  91137. #if FLAC__HAS_OGG
  91138. FLAC__ogg_encoder_aspect_set_serial_number(&encoder->protected_->ogg_encoder_aspect, value);
  91139. return true;
  91140. #else
  91141. (void)value;
  91142. return false;
  91143. #endif
  91144. }
  91145. FLAC_API FLAC__bool FLAC__stream_encoder_set_verify(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91146. {
  91147. FLAC__ASSERT(0 != encoder);
  91148. FLAC__ASSERT(0 != encoder->private_);
  91149. FLAC__ASSERT(0 != encoder->protected_);
  91150. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91151. return false;
  91152. #ifndef FLAC__MANDATORY_VERIFY_WHILE_ENCODING
  91153. encoder->protected_->verify = value;
  91154. #endif
  91155. return true;
  91156. }
  91157. FLAC_API FLAC__bool FLAC__stream_encoder_set_streamable_subset(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91158. {
  91159. FLAC__ASSERT(0 != encoder);
  91160. FLAC__ASSERT(0 != encoder->private_);
  91161. FLAC__ASSERT(0 != encoder->protected_);
  91162. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91163. return false;
  91164. encoder->protected_->streamable_subset = value;
  91165. return true;
  91166. }
  91167. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_md5(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91168. {
  91169. FLAC__ASSERT(0 != encoder);
  91170. FLAC__ASSERT(0 != encoder->private_);
  91171. FLAC__ASSERT(0 != encoder->protected_);
  91172. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91173. return false;
  91174. encoder->protected_->do_md5 = value;
  91175. return true;
  91176. }
  91177. FLAC_API FLAC__bool FLAC__stream_encoder_set_channels(FLAC__StreamEncoder *encoder, unsigned value)
  91178. {
  91179. FLAC__ASSERT(0 != encoder);
  91180. FLAC__ASSERT(0 != encoder->private_);
  91181. FLAC__ASSERT(0 != encoder->protected_);
  91182. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91183. return false;
  91184. encoder->protected_->channels = value;
  91185. return true;
  91186. }
  91187. FLAC_API FLAC__bool FLAC__stream_encoder_set_bits_per_sample(FLAC__StreamEncoder *encoder, unsigned value)
  91188. {
  91189. FLAC__ASSERT(0 != encoder);
  91190. FLAC__ASSERT(0 != encoder->private_);
  91191. FLAC__ASSERT(0 != encoder->protected_);
  91192. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91193. return false;
  91194. encoder->protected_->bits_per_sample = value;
  91195. return true;
  91196. }
  91197. FLAC_API FLAC__bool FLAC__stream_encoder_set_sample_rate(FLAC__StreamEncoder *encoder, unsigned value)
  91198. {
  91199. FLAC__ASSERT(0 != encoder);
  91200. FLAC__ASSERT(0 != encoder->private_);
  91201. FLAC__ASSERT(0 != encoder->protected_);
  91202. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91203. return false;
  91204. encoder->protected_->sample_rate = value;
  91205. return true;
  91206. }
  91207. FLAC_API FLAC__bool FLAC__stream_encoder_set_compression_level(FLAC__StreamEncoder *encoder, unsigned value)
  91208. {
  91209. FLAC__bool ok = true;
  91210. FLAC__ASSERT(0 != encoder);
  91211. FLAC__ASSERT(0 != encoder->private_);
  91212. FLAC__ASSERT(0 != encoder->protected_);
  91213. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91214. return false;
  91215. if(value >= sizeof(compression_levels_)/sizeof(compression_levels_[0]))
  91216. value = sizeof(compression_levels_)/sizeof(compression_levels_[0]) - 1;
  91217. ok &= FLAC__stream_encoder_set_do_mid_side_stereo (encoder, compression_levels_[value].do_mid_side_stereo);
  91218. ok &= FLAC__stream_encoder_set_loose_mid_side_stereo (encoder, compression_levels_[value].loose_mid_side_stereo);
  91219. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91220. #if 0
  91221. ok &= FLAC__stream_encoder_set_apodization (encoder, compression_levels_[value].apodization);
  91222. #else
  91223. encoder->protected_->num_apodizations = 1;
  91224. encoder->protected_->apodizations[0].type = FLAC__APODIZATION_TUKEY;
  91225. encoder->protected_->apodizations[0].parameters.tukey.p = 0.5;
  91226. #endif
  91227. #endif
  91228. ok &= FLAC__stream_encoder_set_max_lpc_order (encoder, compression_levels_[value].max_lpc_order);
  91229. ok &= FLAC__stream_encoder_set_qlp_coeff_precision (encoder, compression_levels_[value].qlp_coeff_precision);
  91230. ok &= FLAC__stream_encoder_set_do_qlp_coeff_prec_search (encoder, compression_levels_[value].do_qlp_coeff_prec_search);
  91231. ok &= FLAC__stream_encoder_set_do_escape_coding (encoder, compression_levels_[value].do_escape_coding);
  91232. ok &= FLAC__stream_encoder_set_do_exhaustive_model_search (encoder, compression_levels_[value].do_exhaustive_model_search);
  91233. ok &= FLAC__stream_encoder_set_min_residual_partition_order(encoder, compression_levels_[value].min_residual_partition_order);
  91234. ok &= FLAC__stream_encoder_set_max_residual_partition_order(encoder, compression_levels_[value].max_residual_partition_order);
  91235. ok &= FLAC__stream_encoder_set_rice_parameter_search_dist (encoder, compression_levels_[value].rice_parameter_search_dist);
  91236. return ok;
  91237. }
  91238. FLAC_API FLAC__bool FLAC__stream_encoder_set_blocksize(FLAC__StreamEncoder *encoder, unsigned value)
  91239. {
  91240. FLAC__ASSERT(0 != encoder);
  91241. FLAC__ASSERT(0 != encoder->private_);
  91242. FLAC__ASSERT(0 != encoder->protected_);
  91243. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91244. return false;
  91245. encoder->protected_->blocksize = value;
  91246. return true;
  91247. }
  91248. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91249. {
  91250. FLAC__ASSERT(0 != encoder);
  91251. FLAC__ASSERT(0 != encoder->private_);
  91252. FLAC__ASSERT(0 != encoder->protected_);
  91253. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91254. return false;
  91255. encoder->protected_->do_mid_side_stereo = value;
  91256. return true;
  91257. }
  91258. FLAC_API FLAC__bool FLAC__stream_encoder_set_loose_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91259. {
  91260. FLAC__ASSERT(0 != encoder);
  91261. FLAC__ASSERT(0 != encoder->private_);
  91262. FLAC__ASSERT(0 != encoder->protected_);
  91263. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91264. return false;
  91265. encoder->protected_->loose_mid_side_stereo = value;
  91266. return true;
  91267. }
  91268. FLAC_API FLAC__bool FLAC__stream_encoder_set_apodization(FLAC__StreamEncoder *encoder, const char *specification)
  91269. {
  91270. FLAC__ASSERT(0 != encoder);
  91271. FLAC__ASSERT(0 != encoder->private_);
  91272. FLAC__ASSERT(0 != encoder->protected_);
  91273. FLAC__ASSERT(0 != specification);
  91274. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91275. return false;
  91276. #ifdef FLAC__INTEGER_ONLY_LIBRARY
  91277. (void)specification; /* silently ignore since we haven't integerized; will always use a rectangular window */
  91278. #else
  91279. encoder->protected_->num_apodizations = 0;
  91280. while(1) {
  91281. const char *s = strchr(specification, ';');
  91282. const size_t n = s? (size_t)(s - specification) : strlen(specification);
  91283. if (n==8 && 0 == strncmp("bartlett" , specification, n))
  91284. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BARTLETT;
  91285. else if(n==13 && 0 == strncmp("bartlett_hann", specification, n))
  91286. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BARTLETT_HANN;
  91287. else if(n==8 && 0 == strncmp("blackman" , specification, n))
  91288. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BLACKMAN;
  91289. else if(n==26 && 0 == strncmp("blackman_harris_4term_92db", specification, n))
  91290. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BLACKMAN_HARRIS_4TERM_92DB_SIDELOBE;
  91291. else if(n==6 && 0 == strncmp("connes" , specification, n))
  91292. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_CONNES;
  91293. else if(n==7 && 0 == strncmp("flattop" , specification, n))
  91294. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_FLATTOP;
  91295. else if(n>7 && 0 == strncmp("gauss(" , specification, 6)) {
  91296. FLAC__real stddev = (FLAC__real)strtod(specification+6, 0);
  91297. if (stddev > 0.0 && stddev <= 0.5) {
  91298. encoder->protected_->apodizations[encoder->protected_->num_apodizations].parameters.gauss.stddev = stddev;
  91299. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_GAUSS;
  91300. }
  91301. }
  91302. else if(n==7 && 0 == strncmp("hamming" , specification, n))
  91303. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_HAMMING;
  91304. else if(n==4 && 0 == strncmp("hann" , specification, n))
  91305. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_HANN;
  91306. else if(n==13 && 0 == strncmp("kaiser_bessel", specification, n))
  91307. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_KAISER_BESSEL;
  91308. else if(n==7 && 0 == strncmp("nuttall" , specification, n))
  91309. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_NUTTALL;
  91310. else if(n==9 && 0 == strncmp("rectangle" , specification, n))
  91311. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_RECTANGLE;
  91312. else if(n==8 && 0 == strncmp("triangle" , specification, n))
  91313. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_TRIANGLE;
  91314. else if(n>7 && 0 == strncmp("tukey(" , specification, 6)) {
  91315. FLAC__real p = (FLAC__real)strtod(specification+6, 0);
  91316. if (p >= 0.0 && p <= 1.0) {
  91317. encoder->protected_->apodizations[encoder->protected_->num_apodizations].parameters.tukey.p = p;
  91318. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_TUKEY;
  91319. }
  91320. }
  91321. else if(n==5 && 0 == strncmp("welch" , specification, n))
  91322. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_WELCH;
  91323. if (encoder->protected_->num_apodizations == 32)
  91324. break;
  91325. if (s)
  91326. specification = s+1;
  91327. else
  91328. break;
  91329. }
  91330. if(encoder->protected_->num_apodizations == 0) {
  91331. encoder->protected_->num_apodizations = 1;
  91332. encoder->protected_->apodizations[0].type = FLAC__APODIZATION_TUKEY;
  91333. encoder->protected_->apodizations[0].parameters.tukey.p = 0.5;
  91334. }
  91335. #endif
  91336. return true;
  91337. }
  91338. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_lpc_order(FLAC__StreamEncoder *encoder, unsigned value)
  91339. {
  91340. FLAC__ASSERT(0 != encoder);
  91341. FLAC__ASSERT(0 != encoder->private_);
  91342. FLAC__ASSERT(0 != encoder->protected_);
  91343. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91344. return false;
  91345. encoder->protected_->max_lpc_order = value;
  91346. return true;
  91347. }
  91348. FLAC_API FLAC__bool FLAC__stream_encoder_set_qlp_coeff_precision(FLAC__StreamEncoder *encoder, unsigned value)
  91349. {
  91350. FLAC__ASSERT(0 != encoder);
  91351. FLAC__ASSERT(0 != encoder->private_);
  91352. FLAC__ASSERT(0 != encoder->protected_);
  91353. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91354. return false;
  91355. encoder->protected_->qlp_coeff_precision = value;
  91356. return true;
  91357. }
  91358. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_qlp_coeff_prec_search(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91359. {
  91360. FLAC__ASSERT(0 != encoder);
  91361. FLAC__ASSERT(0 != encoder->private_);
  91362. FLAC__ASSERT(0 != encoder->protected_);
  91363. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91364. return false;
  91365. encoder->protected_->do_qlp_coeff_prec_search = value;
  91366. return true;
  91367. }
  91368. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_escape_coding(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91369. {
  91370. FLAC__ASSERT(0 != encoder);
  91371. FLAC__ASSERT(0 != encoder->private_);
  91372. FLAC__ASSERT(0 != encoder->protected_);
  91373. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91374. return false;
  91375. #if 0
  91376. encoder->protected_->do_escape_coding = value;
  91377. #else
  91378. (void)value;
  91379. #endif
  91380. return true;
  91381. }
  91382. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_exhaustive_model_search(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91383. {
  91384. FLAC__ASSERT(0 != encoder);
  91385. FLAC__ASSERT(0 != encoder->private_);
  91386. FLAC__ASSERT(0 != encoder->protected_);
  91387. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91388. return false;
  91389. encoder->protected_->do_exhaustive_model_search = value;
  91390. return true;
  91391. }
  91392. FLAC_API FLAC__bool FLAC__stream_encoder_set_min_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value)
  91393. {
  91394. FLAC__ASSERT(0 != encoder);
  91395. FLAC__ASSERT(0 != encoder->private_);
  91396. FLAC__ASSERT(0 != encoder->protected_);
  91397. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91398. return false;
  91399. encoder->protected_->min_residual_partition_order = value;
  91400. return true;
  91401. }
  91402. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value)
  91403. {
  91404. FLAC__ASSERT(0 != encoder);
  91405. FLAC__ASSERT(0 != encoder->private_);
  91406. FLAC__ASSERT(0 != encoder->protected_);
  91407. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91408. return false;
  91409. encoder->protected_->max_residual_partition_order = value;
  91410. return true;
  91411. }
  91412. FLAC_API FLAC__bool FLAC__stream_encoder_set_rice_parameter_search_dist(FLAC__StreamEncoder *encoder, unsigned value)
  91413. {
  91414. FLAC__ASSERT(0 != encoder);
  91415. FLAC__ASSERT(0 != encoder->private_);
  91416. FLAC__ASSERT(0 != encoder->protected_);
  91417. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91418. return false;
  91419. #if 0
  91420. encoder->protected_->rice_parameter_search_dist = value;
  91421. #else
  91422. (void)value;
  91423. #endif
  91424. return true;
  91425. }
  91426. FLAC_API FLAC__bool FLAC__stream_encoder_set_total_samples_estimate(FLAC__StreamEncoder *encoder, FLAC__uint64 value)
  91427. {
  91428. FLAC__ASSERT(0 != encoder);
  91429. FLAC__ASSERT(0 != encoder->private_);
  91430. FLAC__ASSERT(0 != encoder->protected_);
  91431. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91432. return false;
  91433. encoder->protected_->total_samples_estimate = value;
  91434. return true;
  91435. }
  91436. FLAC_API FLAC__bool FLAC__stream_encoder_set_metadata(FLAC__StreamEncoder *encoder, FLAC__StreamMetadata **metadata, unsigned num_blocks)
  91437. {
  91438. FLAC__ASSERT(0 != encoder);
  91439. FLAC__ASSERT(0 != encoder->private_);
  91440. FLAC__ASSERT(0 != encoder->protected_);
  91441. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91442. return false;
  91443. if(0 == metadata)
  91444. num_blocks = 0;
  91445. if(0 == num_blocks)
  91446. metadata = 0;
  91447. if(encoder->protected_->metadata) {
  91448. free(encoder->protected_->metadata);
  91449. encoder->protected_->metadata = 0;
  91450. encoder->protected_->num_metadata_blocks = 0;
  91451. }
  91452. if(num_blocks) {
  91453. FLAC__StreamMetadata **m;
  91454. if(0 == (m = (FLAC__StreamMetadata**)safe_malloc_mul_2op_(sizeof(m[0]), /*times*/num_blocks)))
  91455. return false;
  91456. memcpy(m, metadata, sizeof(m[0]) * num_blocks);
  91457. encoder->protected_->metadata = m;
  91458. encoder->protected_->num_metadata_blocks = num_blocks;
  91459. }
  91460. #if FLAC__HAS_OGG
  91461. if(!FLAC__ogg_encoder_aspect_set_num_metadata(&encoder->protected_->ogg_encoder_aspect, num_blocks))
  91462. return false;
  91463. #endif
  91464. return true;
  91465. }
  91466. FLAC_API FLAC__bool FLAC__stream_encoder_disable_constant_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91467. {
  91468. FLAC__ASSERT(0 != encoder);
  91469. FLAC__ASSERT(0 != encoder->private_);
  91470. FLAC__ASSERT(0 != encoder->protected_);
  91471. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91472. return false;
  91473. encoder->private_->disable_constant_subframes = value;
  91474. return true;
  91475. }
  91476. FLAC_API FLAC__bool FLAC__stream_encoder_disable_fixed_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91477. {
  91478. FLAC__ASSERT(0 != encoder);
  91479. FLAC__ASSERT(0 != encoder->private_);
  91480. FLAC__ASSERT(0 != encoder->protected_);
  91481. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91482. return false;
  91483. encoder->private_->disable_fixed_subframes = value;
  91484. return true;
  91485. }
  91486. FLAC_API FLAC__bool FLAC__stream_encoder_disable_verbatim_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91487. {
  91488. FLAC__ASSERT(0 != encoder);
  91489. FLAC__ASSERT(0 != encoder->private_);
  91490. FLAC__ASSERT(0 != encoder->protected_);
  91491. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91492. return false;
  91493. encoder->private_->disable_verbatim_subframes = value;
  91494. return true;
  91495. }
  91496. FLAC_API FLAC__StreamEncoderState FLAC__stream_encoder_get_state(const FLAC__StreamEncoder *encoder)
  91497. {
  91498. FLAC__ASSERT(0 != encoder);
  91499. FLAC__ASSERT(0 != encoder->private_);
  91500. FLAC__ASSERT(0 != encoder->protected_);
  91501. return encoder->protected_->state;
  91502. }
  91503. FLAC_API FLAC__StreamDecoderState FLAC__stream_encoder_get_verify_decoder_state(const FLAC__StreamEncoder *encoder)
  91504. {
  91505. FLAC__ASSERT(0 != encoder);
  91506. FLAC__ASSERT(0 != encoder->private_);
  91507. FLAC__ASSERT(0 != encoder->protected_);
  91508. if(encoder->protected_->verify)
  91509. return FLAC__stream_decoder_get_state(encoder->private_->verify.decoder);
  91510. else
  91511. return FLAC__STREAM_DECODER_UNINITIALIZED;
  91512. }
  91513. FLAC_API const char *FLAC__stream_encoder_get_resolved_state_string(const FLAC__StreamEncoder *encoder)
  91514. {
  91515. FLAC__ASSERT(0 != encoder);
  91516. FLAC__ASSERT(0 != encoder->private_);
  91517. FLAC__ASSERT(0 != encoder->protected_);
  91518. if(encoder->protected_->state != FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR)
  91519. return FLAC__StreamEncoderStateString[encoder->protected_->state];
  91520. else
  91521. return FLAC__stream_decoder_get_resolved_state_string(encoder->private_->verify.decoder);
  91522. }
  91523. 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)
  91524. {
  91525. FLAC__ASSERT(0 != encoder);
  91526. FLAC__ASSERT(0 != encoder->private_);
  91527. FLAC__ASSERT(0 != encoder->protected_);
  91528. if(0 != absolute_sample)
  91529. *absolute_sample = encoder->private_->verify.error_stats.absolute_sample;
  91530. if(0 != frame_number)
  91531. *frame_number = encoder->private_->verify.error_stats.frame_number;
  91532. if(0 != channel)
  91533. *channel = encoder->private_->verify.error_stats.channel;
  91534. if(0 != sample)
  91535. *sample = encoder->private_->verify.error_stats.sample;
  91536. if(0 != expected)
  91537. *expected = encoder->private_->verify.error_stats.expected;
  91538. if(0 != got)
  91539. *got = encoder->private_->verify.error_stats.got;
  91540. }
  91541. FLAC_API FLAC__bool FLAC__stream_encoder_get_verify(const FLAC__StreamEncoder *encoder)
  91542. {
  91543. FLAC__ASSERT(0 != encoder);
  91544. FLAC__ASSERT(0 != encoder->private_);
  91545. FLAC__ASSERT(0 != encoder->protected_);
  91546. return encoder->protected_->verify;
  91547. }
  91548. FLAC_API FLAC__bool FLAC__stream_encoder_get_streamable_subset(const FLAC__StreamEncoder *encoder)
  91549. {
  91550. FLAC__ASSERT(0 != encoder);
  91551. FLAC__ASSERT(0 != encoder->private_);
  91552. FLAC__ASSERT(0 != encoder->protected_);
  91553. return encoder->protected_->streamable_subset;
  91554. }
  91555. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_md5(const FLAC__StreamEncoder *encoder)
  91556. {
  91557. FLAC__ASSERT(0 != encoder);
  91558. FLAC__ASSERT(0 != encoder->private_);
  91559. FLAC__ASSERT(0 != encoder->protected_);
  91560. return encoder->protected_->do_md5;
  91561. }
  91562. FLAC_API unsigned FLAC__stream_encoder_get_channels(const FLAC__StreamEncoder *encoder)
  91563. {
  91564. FLAC__ASSERT(0 != encoder);
  91565. FLAC__ASSERT(0 != encoder->private_);
  91566. FLAC__ASSERT(0 != encoder->protected_);
  91567. return encoder->protected_->channels;
  91568. }
  91569. FLAC_API unsigned FLAC__stream_encoder_get_bits_per_sample(const FLAC__StreamEncoder *encoder)
  91570. {
  91571. FLAC__ASSERT(0 != encoder);
  91572. FLAC__ASSERT(0 != encoder->private_);
  91573. FLAC__ASSERT(0 != encoder->protected_);
  91574. return encoder->protected_->bits_per_sample;
  91575. }
  91576. FLAC_API unsigned FLAC__stream_encoder_get_sample_rate(const FLAC__StreamEncoder *encoder)
  91577. {
  91578. FLAC__ASSERT(0 != encoder);
  91579. FLAC__ASSERT(0 != encoder->private_);
  91580. FLAC__ASSERT(0 != encoder->protected_);
  91581. return encoder->protected_->sample_rate;
  91582. }
  91583. FLAC_API unsigned FLAC__stream_encoder_get_blocksize(const FLAC__StreamEncoder *encoder)
  91584. {
  91585. FLAC__ASSERT(0 != encoder);
  91586. FLAC__ASSERT(0 != encoder->private_);
  91587. FLAC__ASSERT(0 != encoder->protected_);
  91588. return encoder->protected_->blocksize;
  91589. }
  91590. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_mid_side_stereo(const FLAC__StreamEncoder *encoder)
  91591. {
  91592. FLAC__ASSERT(0 != encoder);
  91593. FLAC__ASSERT(0 != encoder->private_);
  91594. FLAC__ASSERT(0 != encoder->protected_);
  91595. return encoder->protected_->do_mid_side_stereo;
  91596. }
  91597. FLAC_API FLAC__bool FLAC__stream_encoder_get_loose_mid_side_stereo(const FLAC__StreamEncoder *encoder)
  91598. {
  91599. FLAC__ASSERT(0 != encoder);
  91600. FLAC__ASSERT(0 != encoder->private_);
  91601. FLAC__ASSERT(0 != encoder->protected_);
  91602. return encoder->protected_->loose_mid_side_stereo;
  91603. }
  91604. FLAC_API unsigned FLAC__stream_encoder_get_max_lpc_order(const FLAC__StreamEncoder *encoder)
  91605. {
  91606. FLAC__ASSERT(0 != encoder);
  91607. FLAC__ASSERT(0 != encoder->private_);
  91608. FLAC__ASSERT(0 != encoder->protected_);
  91609. return encoder->protected_->max_lpc_order;
  91610. }
  91611. FLAC_API unsigned FLAC__stream_encoder_get_qlp_coeff_precision(const FLAC__StreamEncoder *encoder)
  91612. {
  91613. FLAC__ASSERT(0 != encoder);
  91614. FLAC__ASSERT(0 != encoder->private_);
  91615. FLAC__ASSERT(0 != encoder->protected_);
  91616. return encoder->protected_->qlp_coeff_precision;
  91617. }
  91618. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_qlp_coeff_prec_search(const FLAC__StreamEncoder *encoder)
  91619. {
  91620. FLAC__ASSERT(0 != encoder);
  91621. FLAC__ASSERT(0 != encoder->private_);
  91622. FLAC__ASSERT(0 != encoder->protected_);
  91623. return encoder->protected_->do_qlp_coeff_prec_search;
  91624. }
  91625. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_escape_coding(const FLAC__StreamEncoder *encoder)
  91626. {
  91627. FLAC__ASSERT(0 != encoder);
  91628. FLAC__ASSERT(0 != encoder->private_);
  91629. FLAC__ASSERT(0 != encoder->protected_);
  91630. return encoder->protected_->do_escape_coding;
  91631. }
  91632. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_exhaustive_model_search(const FLAC__StreamEncoder *encoder)
  91633. {
  91634. FLAC__ASSERT(0 != encoder);
  91635. FLAC__ASSERT(0 != encoder->private_);
  91636. FLAC__ASSERT(0 != encoder->protected_);
  91637. return encoder->protected_->do_exhaustive_model_search;
  91638. }
  91639. FLAC_API unsigned FLAC__stream_encoder_get_min_residual_partition_order(const FLAC__StreamEncoder *encoder)
  91640. {
  91641. FLAC__ASSERT(0 != encoder);
  91642. FLAC__ASSERT(0 != encoder->private_);
  91643. FLAC__ASSERT(0 != encoder->protected_);
  91644. return encoder->protected_->min_residual_partition_order;
  91645. }
  91646. FLAC_API unsigned FLAC__stream_encoder_get_max_residual_partition_order(const FLAC__StreamEncoder *encoder)
  91647. {
  91648. FLAC__ASSERT(0 != encoder);
  91649. FLAC__ASSERT(0 != encoder->private_);
  91650. FLAC__ASSERT(0 != encoder->protected_);
  91651. return encoder->protected_->max_residual_partition_order;
  91652. }
  91653. FLAC_API unsigned FLAC__stream_encoder_get_rice_parameter_search_dist(const FLAC__StreamEncoder *encoder)
  91654. {
  91655. FLAC__ASSERT(0 != encoder);
  91656. FLAC__ASSERT(0 != encoder->private_);
  91657. FLAC__ASSERT(0 != encoder->protected_);
  91658. return encoder->protected_->rice_parameter_search_dist;
  91659. }
  91660. FLAC_API FLAC__uint64 FLAC__stream_encoder_get_total_samples_estimate(const FLAC__StreamEncoder *encoder)
  91661. {
  91662. FLAC__ASSERT(0 != encoder);
  91663. FLAC__ASSERT(0 != encoder->private_);
  91664. FLAC__ASSERT(0 != encoder->protected_);
  91665. return encoder->protected_->total_samples_estimate;
  91666. }
  91667. FLAC_API FLAC__bool FLAC__stream_encoder_process(FLAC__StreamEncoder *encoder, const FLAC__int32 * const buffer[], unsigned samples)
  91668. {
  91669. unsigned i, j = 0, channel;
  91670. const unsigned channels = encoder->protected_->channels, blocksize = encoder->protected_->blocksize;
  91671. FLAC__ASSERT(0 != encoder);
  91672. FLAC__ASSERT(0 != encoder->private_);
  91673. FLAC__ASSERT(0 != encoder->protected_);
  91674. FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
  91675. do {
  91676. const unsigned n = min(blocksize+OVERREAD_-encoder->private_->current_sample_number, samples-j);
  91677. if(encoder->protected_->verify)
  91678. append_to_verify_fifo_(&encoder->private_->verify.input_fifo, buffer, j, channels, n);
  91679. for(channel = 0; channel < channels; channel++)
  91680. memcpy(&encoder->private_->integer_signal[channel][encoder->private_->current_sample_number], &buffer[channel][j], sizeof(buffer[channel][0]) * n);
  91681. if(encoder->protected_->do_mid_side_stereo) {
  91682. FLAC__ASSERT(channels == 2);
  91683. for(i = encoder->private_->current_sample_number; i <= blocksize && j < samples; i++, j++) {
  91684. encoder->private_->integer_signal_mid_side[1][i] = buffer[0][j] - buffer[1][j];
  91685. 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' ! */
  91686. }
  91687. }
  91688. else
  91689. j += n;
  91690. encoder->private_->current_sample_number += n;
  91691. if(encoder->private_->current_sample_number > blocksize) {
  91692. FLAC__ASSERT(encoder->private_->current_sample_number == blocksize+OVERREAD_);
  91693. FLAC__ASSERT(OVERREAD_ == 1); /* assert we only overread 1 sample which simplifies the rest of the code below */
  91694. if(!process_frame_(encoder, /*is_fractional_block=*/false, /*is_last_block=*/false))
  91695. return false;
  91696. for(channel = 0; channel < channels; channel++)
  91697. encoder->private_->integer_signal[channel][0] = encoder->private_->integer_signal[channel][blocksize];
  91698. if(encoder->protected_->do_mid_side_stereo) {
  91699. encoder->private_->integer_signal_mid_side[0][0] = encoder->private_->integer_signal_mid_side[0][blocksize];
  91700. encoder->private_->integer_signal_mid_side[1][0] = encoder->private_->integer_signal_mid_side[1][blocksize];
  91701. }
  91702. encoder->private_->current_sample_number = 1;
  91703. }
  91704. } while(j < samples);
  91705. return true;
  91706. }
  91707. FLAC_API FLAC__bool FLAC__stream_encoder_process_interleaved(FLAC__StreamEncoder *encoder, const FLAC__int32 buffer[], unsigned samples)
  91708. {
  91709. unsigned i, j, k, channel;
  91710. FLAC__int32 x, mid, side;
  91711. const unsigned channels = encoder->protected_->channels, blocksize = encoder->protected_->blocksize;
  91712. FLAC__ASSERT(0 != encoder);
  91713. FLAC__ASSERT(0 != encoder->private_);
  91714. FLAC__ASSERT(0 != encoder->protected_);
  91715. FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
  91716. j = k = 0;
  91717. if(encoder->protected_->do_mid_side_stereo && channels == 2) {
  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. encoder->private_->integer_signal[0][i] = mid = side = buffer[k++];
  91723. x = buffer[k++];
  91724. encoder->private_->integer_signal[1][i] = x;
  91725. mid += x;
  91726. side -= x;
  91727. mid >>= 1; /* NOTE: not the same as 'mid = (left + right) / 2' ! */
  91728. encoder->private_->integer_signal_mid_side[1][i] = side;
  91729. encoder->private_->integer_signal_mid_side[0][i] = mid;
  91730. }
  91731. encoder->private_->current_sample_number = i;
  91732. if(i > blocksize) {
  91733. if(!process_frame_(encoder, /*is_fractional_block=*/false, /*is_last_block=*/false))
  91734. return false;
  91735. /* move unprocessed overread samples to beginnings of arrays */
  91736. FLAC__ASSERT(i == blocksize+OVERREAD_);
  91737. FLAC__ASSERT(OVERREAD_ == 1); /* assert we only overread 1 sample which simplifies the rest of the code below */
  91738. encoder->private_->integer_signal[0][0] = encoder->private_->integer_signal[0][blocksize];
  91739. encoder->private_->integer_signal[1][0] = encoder->private_->integer_signal[1][blocksize];
  91740. encoder->private_->integer_signal_mid_side[0][0] = encoder->private_->integer_signal_mid_side[0][blocksize];
  91741. encoder->private_->integer_signal_mid_side[1][0] = encoder->private_->integer_signal_mid_side[1][blocksize];
  91742. encoder->private_->current_sample_number = 1;
  91743. }
  91744. } while(j < samples);
  91745. }
  91746. else {
  91747. do {
  91748. if(encoder->protected_->verify)
  91749. append_to_verify_fifo_interleaved_(&encoder->private_->verify.input_fifo, buffer, j, channels, min(blocksize+OVERREAD_-encoder->private_->current_sample_number, samples-j));
  91750. for(i = encoder->private_->current_sample_number; i <= blocksize && j < samples; i++, j++) {
  91751. for(channel = 0; channel < channels; channel++)
  91752. encoder->private_->integer_signal[channel][i] = buffer[k++];
  91753. }
  91754. encoder->private_->current_sample_number = i;
  91755. if(i > blocksize) {
  91756. if(!process_frame_(encoder, /*is_fractional_block=*/false, /*is_last_block=*/false))
  91757. return false;
  91758. /* move unprocessed overread samples to beginnings of arrays */
  91759. FLAC__ASSERT(i == blocksize+OVERREAD_);
  91760. FLAC__ASSERT(OVERREAD_ == 1); /* assert we only overread 1 sample which simplifies the rest of the code below */
  91761. for(channel = 0; channel < channels; channel++)
  91762. encoder->private_->integer_signal[channel][0] = encoder->private_->integer_signal[channel][blocksize];
  91763. encoder->private_->current_sample_number = 1;
  91764. }
  91765. } while(j < samples);
  91766. }
  91767. return true;
  91768. }
  91769. void set_defaults_enc(FLAC__StreamEncoder *encoder)
  91770. {
  91771. FLAC__ASSERT(0 != encoder);
  91772. #ifdef FLAC__MANDATORY_VERIFY_WHILE_ENCODING
  91773. encoder->protected_->verify = true;
  91774. #else
  91775. encoder->protected_->verify = false;
  91776. #endif
  91777. encoder->protected_->streamable_subset = true;
  91778. encoder->protected_->do_md5 = true;
  91779. encoder->protected_->do_mid_side_stereo = false;
  91780. encoder->protected_->loose_mid_side_stereo = false;
  91781. encoder->protected_->channels = 2;
  91782. encoder->protected_->bits_per_sample = 16;
  91783. encoder->protected_->sample_rate = 44100;
  91784. encoder->protected_->blocksize = 0;
  91785. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91786. encoder->protected_->num_apodizations = 1;
  91787. encoder->protected_->apodizations[0].type = FLAC__APODIZATION_TUKEY;
  91788. encoder->protected_->apodizations[0].parameters.tukey.p = 0.5;
  91789. #endif
  91790. encoder->protected_->max_lpc_order = 0;
  91791. encoder->protected_->qlp_coeff_precision = 0;
  91792. encoder->protected_->do_qlp_coeff_prec_search = false;
  91793. encoder->protected_->do_exhaustive_model_search = false;
  91794. encoder->protected_->do_escape_coding = false;
  91795. encoder->protected_->min_residual_partition_order = 0;
  91796. encoder->protected_->max_residual_partition_order = 0;
  91797. encoder->protected_->rice_parameter_search_dist = 0;
  91798. encoder->protected_->total_samples_estimate = 0;
  91799. encoder->protected_->metadata = 0;
  91800. encoder->protected_->num_metadata_blocks = 0;
  91801. encoder->private_->seek_table = 0;
  91802. encoder->private_->disable_constant_subframes = false;
  91803. encoder->private_->disable_fixed_subframes = false;
  91804. encoder->private_->disable_verbatim_subframes = false;
  91805. #if FLAC__HAS_OGG
  91806. encoder->private_->is_ogg = false;
  91807. #endif
  91808. encoder->private_->read_callback = 0;
  91809. encoder->private_->write_callback = 0;
  91810. encoder->private_->seek_callback = 0;
  91811. encoder->private_->tell_callback = 0;
  91812. encoder->private_->metadata_callback = 0;
  91813. encoder->private_->progress_callback = 0;
  91814. encoder->private_->client_data = 0;
  91815. #if FLAC__HAS_OGG
  91816. FLAC__ogg_encoder_aspect_set_defaults(&encoder->protected_->ogg_encoder_aspect);
  91817. #endif
  91818. }
  91819. void free_(FLAC__StreamEncoder *encoder)
  91820. {
  91821. unsigned i, channel;
  91822. FLAC__ASSERT(0 != encoder);
  91823. if(encoder->protected_->metadata) {
  91824. free(encoder->protected_->metadata);
  91825. encoder->protected_->metadata = 0;
  91826. encoder->protected_->num_metadata_blocks = 0;
  91827. }
  91828. for(i = 0; i < encoder->protected_->channels; i++) {
  91829. if(0 != encoder->private_->integer_signal_unaligned[i]) {
  91830. free(encoder->private_->integer_signal_unaligned[i]);
  91831. encoder->private_->integer_signal_unaligned[i] = 0;
  91832. }
  91833. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91834. if(0 != encoder->private_->real_signal_unaligned[i]) {
  91835. free(encoder->private_->real_signal_unaligned[i]);
  91836. encoder->private_->real_signal_unaligned[i] = 0;
  91837. }
  91838. #endif
  91839. }
  91840. for(i = 0; i < 2; i++) {
  91841. if(0 != encoder->private_->integer_signal_mid_side_unaligned[i]) {
  91842. free(encoder->private_->integer_signal_mid_side_unaligned[i]);
  91843. encoder->private_->integer_signal_mid_side_unaligned[i] = 0;
  91844. }
  91845. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91846. if(0 != encoder->private_->real_signal_mid_side_unaligned[i]) {
  91847. free(encoder->private_->real_signal_mid_side_unaligned[i]);
  91848. encoder->private_->real_signal_mid_side_unaligned[i] = 0;
  91849. }
  91850. #endif
  91851. }
  91852. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91853. for(i = 0; i < encoder->protected_->num_apodizations; i++) {
  91854. if(0 != encoder->private_->window_unaligned[i]) {
  91855. free(encoder->private_->window_unaligned[i]);
  91856. encoder->private_->window_unaligned[i] = 0;
  91857. }
  91858. }
  91859. if(0 != encoder->private_->windowed_signal_unaligned) {
  91860. free(encoder->private_->windowed_signal_unaligned);
  91861. encoder->private_->windowed_signal_unaligned = 0;
  91862. }
  91863. #endif
  91864. for(channel = 0; channel < encoder->protected_->channels; channel++) {
  91865. for(i = 0; i < 2; i++) {
  91866. if(0 != encoder->private_->residual_workspace_unaligned[channel][i]) {
  91867. free(encoder->private_->residual_workspace_unaligned[channel][i]);
  91868. encoder->private_->residual_workspace_unaligned[channel][i] = 0;
  91869. }
  91870. }
  91871. }
  91872. for(channel = 0; channel < 2; channel++) {
  91873. for(i = 0; i < 2; i++) {
  91874. if(0 != encoder->private_->residual_workspace_mid_side_unaligned[channel][i]) {
  91875. free(encoder->private_->residual_workspace_mid_side_unaligned[channel][i]);
  91876. encoder->private_->residual_workspace_mid_side_unaligned[channel][i] = 0;
  91877. }
  91878. }
  91879. }
  91880. if(0 != encoder->private_->abs_residual_partition_sums_unaligned) {
  91881. free(encoder->private_->abs_residual_partition_sums_unaligned);
  91882. encoder->private_->abs_residual_partition_sums_unaligned = 0;
  91883. }
  91884. if(0 != encoder->private_->raw_bits_per_partition_unaligned) {
  91885. free(encoder->private_->raw_bits_per_partition_unaligned);
  91886. encoder->private_->raw_bits_per_partition_unaligned = 0;
  91887. }
  91888. if(encoder->protected_->verify) {
  91889. for(i = 0; i < encoder->protected_->channels; i++) {
  91890. if(0 != encoder->private_->verify.input_fifo.data[i]) {
  91891. free(encoder->private_->verify.input_fifo.data[i]);
  91892. encoder->private_->verify.input_fifo.data[i] = 0;
  91893. }
  91894. }
  91895. }
  91896. FLAC__bitwriter_free(encoder->private_->frame);
  91897. }
  91898. FLAC__bool resize_buffers_(FLAC__StreamEncoder *encoder, unsigned new_blocksize)
  91899. {
  91900. FLAC__bool ok;
  91901. unsigned i, channel;
  91902. FLAC__ASSERT(new_blocksize > 0);
  91903. FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
  91904. FLAC__ASSERT(encoder->private_->current_sample_number == 0);
  91905. if(new_blocksize <= encoder->private_->input_capacity)
  91906. return true;
  91907. ok = true;
  91908. for(i = 0; ok && i < encoder->protected_->channels; i++) {
  91909. ok = ok && FLAC__memory_alloc_aligned_int32_array(new_blocksize+4+OVERREAD_, &encoder->private_->integer_signal_unaligned[i], &encoder->private_->integer_signal[i]);
  91910. memset(encoder->private_->integer_signal[i], 0, sizeof(FLAC__int32)*4);
  91911. encoder->private_->integer_signal[i] += 4;
  91912. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91913. #if 0 /* @@@ currently unused */
  91914. if(encoder->protected_->max_lpc_order > 0)
  91915. ok = ok && FLAC__memory_alloc_aligned_real_array(new_blocksize+OVERREAD_, &encoder->private_->real_signal_unaligned[i], &encoder->private_->real_signal[i]);
  91916. #endif
  91917. #endif
  91918. }
  91919. for(i = 0; ok && i < 2; i++) {
  91920. 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]);
  91921. memset(encoder->private_->integer_signal_mid_side[i], 0, sizeof(FLAC__int32)*4);
  91922. encoder->private_->integer_signal_mid_side[i] += 4;
  91923. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91924. #if 0 /* @@@ currently unused */
  91925. if(encoder->protected_->max_lpc_order > 0)
  91926. 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]);
  91927. #endif
  91928. #endif
  91929. }
  91930. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91931. if(ok && encoder->protected_->max_lpc_order > 0) {
  91932. for(i = 0; ok && i < encoder->protected_->num_apodizations; i++)
  91933. ok = ok && FLAC__memory_alloc_aligned_real_array(new_blocksize, &encoder->private_->window_unaligned[i], &encoder->private_->window[i]);
  91934. ok = ok && FLAC__memory_alloc_aligned_real_array(new_blocksize, &encoder->private_->windowed_signal_unaligned, &encoder->private_->windowed_signal);
  91935. }
  91936. #endif
  91937. for(channel = 0; ok && channel < encoder->protected_->channels; channel++) {
  91938. for(i = 0; ok && i < 2; i++) {
  91939. ok = ok && FLAC__memory_alloc_aligned_int32_array(new_blocksize, &encoder->private_->residual_workspace_unaligned[channel][i], &encoder->private_->residual_workspace[channel][i]);
  91940. }
  91941. }
  91942. for(channel = 0; ok && channel < 2; channel++) {
  91943. for(i = 0; ok && i < 2; i++) {
  91944. 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]);
  91945. }
  91946. }
  91947. ok = ok && FLAC__memory_alloc_aligned_uint64_array(new_blocksize * 2, &encoder->private_->abs_residual_partition_sums_unaligned, &encoder->private_->abs_residual_partition_sums);
  91948. if(encoder->protected_->do_escape_coding)
  91949. ok = ok && FLAC__memory_alloc_aligned_unsigned_array(new_blocksize * 2, &encoder->private_->raw_bits_per_partition_unaligned, &encoder->private_->raw_bits_per_partition);
  91950. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91951. if(ok && new_blocksize != encoder->private_->input_capacity && encoder->protected_->max_lpc_order > 0) {
  91952. for(i = 0; ok && i < encoder->protected_->num_apodizations; i++) {
  91953. switch(encoder->protected_->apodizations[i].type) {
  91954. case FLAC__APODIZATION_BARTLETT:
  91955. FLAC__window_bartlett(encoder->private_->window[i], new_blocksize);
  91956. break;
  91957. case FLAC__APODIZATION_BARTLETT_HANN:
  91958. FLAC__window_bartlett_hann(encoder->private_->window[i], new_blocksize);
  91959. break;
  91960. case FLAC__APODIZATION_BLACKMAN:
  91961. FLAC__window_blackman(encoder->private_->window[i], new_blocksize);
  91962. break;
  91963. case FLAC__APODIZATION_BLACKMAN_HARRIS_4TERM_92DB_SIDELOBE:
  91964. FLAC__window_blackman_harris_4term_92db_sidelobe(encoder->private_->window[i], new_blocksize);
  91965. break;
  91966. case FLAC__APODIZATION_CONNES:
  91967. FLAC__window_connes(encoder->private_->window[i], new_blocksize);
  91968. break;
  91969. case FLAC__APODIZATION_FLATTOP:
  91970. FLAC__window_flattop(encoder->private_->window[i], new_blocksize);
  91971. break;
  91972. case FLAC__APODIZATION_GAUSS:
  91973. FLAC__window_gauss(encoder->private_->window[i], new_blocksize, encoder->protected_->apodizations[i].parameters.gauss.stddev);
  91974. break;
  91975. case FLAC__APODIZATION_HAMMING:
  91976. FLAC__window_hamming(encoder->private_->window[i], new_blocksize);
  91977. break;
  91978. case FLAC__APODIZATION_HANN:
  91979. FLAC__window_hann(encoder->private_->window[i], new_blocksize);
  91980. break;
  91981. case FLAC__APODIZATION_KAISER_BESSEL:
  91982. FLAC__window_kaiser_bessel(encoder->private_->window[i], new_blocksize);
  91983. break;
  91984. case FLAC__APODIZATION_NUTTALL:
  91985. FLAC__window_nuttall(encoder->private_->window[i], new_blocksize);
  91986. break;
  91987. case FLAC__APODIZATION_RECTANGLE:
  91988. FLAC__window_rectangle(encoder->private_->window[i], new_blocksize);
  91989. break;
  91990. case FLAC__APODIZATION_TRIANGLE:
  91991. FLAC__window_triangle(encoder->private_->window[i], new_blocksize);
  91992. break;
  91993. case FLAC__APODIZATION_TUKEY:
  91994. FLAC__window_tukey(encoder->private_->window[i], new_blocksize, encoder->protected_->apodizations[i].parameters.tukey.p);
  91995. break;
  91996. case FLAC__APODIZATION_WELCH:
  91997. FLAC__window_welch(encoder->private_->window[i], new_blocksize);
  91998. break;
  91999. default:
  92000. FLAC__ASSERT(0);
  92001. FLAC__window_hann(encoder->private_->window[i], new_blocksize);
  92002. break;
  92003. }
  92004. }
  92005. }
  92006. #endif
  92007. if(ok)
  92008. encoder->private_->input_capacity = new_blocksize;
  92009. else
  92010. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  92011. return ok;
  92012. }
  92013. FLAC__bool write_bitbuffer_(FLAC__StreamEncoder *encoder, unsigned samples, FLAC__bool is_last_block)
  92014. {
  92015. const FLAC__byte *buffer;
  92016. size_t bytes;
  92017. FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(encoder->private_->frame));
  92018. if(!FLAC__bitwriter_get_buffer(encoder->private_->frame, &buffer, &bytes)) {
  92019. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  92020. return false;
  92021. }
  92022. if(encoder->protected_->verify) {
  92023. encoder->private_->verify.output.data = buffer;
  92024. encoder->private_->verify.output.bytes = bytes;
  92025. if(encoder->private_->verify.state_hint == ENCODER_IN_MAGIC) {
  92026. encoder->private_->verify.needs_magic_hack = true;
  92027. }
  92028. else {
  92029. if(!FLAC__stream_decoder_process_single(encoder->private_->verify.decoder)) {
  92030. FLAC__bitwriter_release_buffer(encoder->private_->frame);
  92031. FLAC__bitwriter_clear(encoder->private_->frame);
  92032. if(encoder->protected_->state != FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA)
  92033. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
  92034. return false;
  92035. }
  92036. }
  92037. }
  92038. if(write_frame_(encoder, buffer, bytes, samples, is_last_block) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  92039. FLAC__bitwriter_release_buffer(encoder->private_->frame);
  92040. FLAC__bitwriter_clear(encoder->private_->frame);
  92041. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92042. return false;
  92043. }
  92044. FLAC__bitwriter_release_buffer(encoder->private_->frame);
  92045. FLAC__bitwriter_clear(encoder->private_->frame);
  92046. if(samples > 0) {
  92047. encoder->private_->streaminfo.data.stream_info.min_framesize = min(bytes, encoder->private_->streaminfo.data.stream_info.min_framesize);
  92048. encoder->private_->streaminfo.data.stream_info.max_framesize = max(bytes, encoder->private_->streaminfo.data.stream_info.max_framesize);
  92049. }
  92050. return true;
  92051. }
  92052. FLAC__StreamEncoderWriteStatus write_frame_(FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, FLAC__bool is_last_block)
  92053. {
  92054. FLAC__StreamEncoderWriteStatus status;
  92055. FLAC__uint64 output_position = 0;
  92056. if(encoder->private_->tell_callback && encoder->private_->tell_callback(encoder, &output_position, encoder->private_->client_data) == FLAC__STREAM_ENCODER_TELL_STATUS_ERROR) {
  92057. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92058. return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
  92059. }
  92060. if(samples == 0) {
  92061. FLAC__MetadataType type = (FLAC__MetadataType) (buffer[0] & 0x7f);
  92062. if(type == FLAC__METADATA_TYPE_STREAMINFO)
  92063. encoder->protected_->streaminfo_offset = output_position;
  92064. else if(type == FLAC__METADATA_TYPE_SEEKTABLE && encoder->protected_->seektable_offset == 0)
  92065. encoder->protected_->seektable_offset = output_position;
  92066. }
  92067. if(0 != encoder->private_->seek_table && encoder->protected_->audio_offset > 0 && encoder->private_->seek_table->num_points > 0) {
  92068. const unsigned blocksize = FLAC__stream_encoder_get_blocksize(encoder);
  92069. const FLAC__uint64 frame_first_sample = encoder->private_->samples_written;
  92070. const FLAC__uint64 frame_last_sample = frame_first_sample + (FLAC__uint64)blocksize - 1;
  92071. FLAC__uint64 test_sample;
  92072. unsigned i;
  92073. for(i = encoder->private_->first_seekpoint_to_check; i < encoder->private_->seek_table->num_points; i++) {
  92074. test_sample = encoder->private_->seek_table->points[i].sample_number;
  92075. if(test_sample > frame_last_sample) {
  92076. break;
  92077. }
  92078. else if(test_sample >= frame_first_sample) {
  92079. encoder->private_->seek_table->points[i].sample_number = frame_first_sample;
  92080. encoder->private_->seek_table->points[i].stream_offset = output_position - encoder->protected_->audio_offset;
  92081. encoder->private_->seek_table->points[i].frame_samples = blocksize;
  92082. encoder->private_->first_seekpoint_to_check++;
  92083. }
  92084. else {
  92085. encoder->private_->first_seekpoint_to_check++;
  92086. }
  92087. }
  92088. }
  92089. #if FLAC__HAS_OGG
  92090. if(encoder->private_->is_ogg) {
  92091. status = FLAC__ogg_encoder_aspect_write_callback_wrapper(
  92092. &encoder->protected_->ogg_encoder_aspect,
  92093. buffer,
  92094. bytes,
  92095. samples,
  92096. encoder->private_->current_frame_number,
  92097. is_last_block,
  92098. (FLAC__OggEncoderAspectWriteCallbackProxy)encoder->private_->write_callback,
  92099. encoder,
  92100. encoder->private_->client_data
  92101. );
  92102. }
  92103. else
  92104. #endif
  92105. status = encoder->private_->write_callback(encoder, buffer, bytes, samples, encoder->private_->current_frame_number, encoder->private_->client_data);
  92106. if(status == FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  92107. encoder->private_->bytes_written += bytes;
  92108. encoder->private_->samples_written += samples;
  92109. encoder->private_->frames_written = max(encoder->private_->frames_written, encoder->private_->current_frame_number+1);
  92110. }
  92111. else
  92112. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92113. return status;
  92114. }
  92115. void update_metadata_(const FLAC__StreamEncoder *encoder)
  92116. {
  92117. FLAC__byte b[max(6, FLAC__STREAM_METADATA_SEEKPOINT_LENGTH)];
  92118. const FLAC__StreamMetadata *metadata = &encoder->private_->streaminfo;
  92119. const FLAC__uint64 samples = metadata->data.stream_info.total_samples;
  92120. const unsigned min_framesize = metadata->data.stream_info.min_framesize;
  92121. const unsigned max_framesize = metadata->data.stream_info.max_framesize;
  92122. const unsigned bps = metadata->data.stream_info.bits_per_sample;
  92123. FLAC__StreamEncoderSeekStatus seek_status;
  92124. FLAC__ASSERT(metadata->type == FLAC__METADATA_TYPE_STREAMINFO);
  92125. {
  92126. const unsigned md5_offset =
  92127. FLAC__STREAM_METADATA_HEADER_LENGTH +
  92128. (
  92129. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  92130. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
  92131. FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
  92132. FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
  92133. FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
  92134. FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
  92135. FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN +
  92136. FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN
  92137. ) / 8;
  92138. if((seek_status = encoder->private_->seek_callback(encoder, encoder->protected_->streaminfo_offset + md5_offset, encoder->private_->client_data)) != FLAC__STREAM_ENCODER_SEEK_STATUS_OK) {
  92139. if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
  92140. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92141. return;
  92142. }
  92143. if(encoder->private_->write_callback(encoder, metadata->data.stream_info.md5sum, 16, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  92144. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92145. return;
  92146. }
  92147. }
  92148. {
  92149. const unsigned total_samples_byte_offset =
  92150. FLAC__STREAM_METADATA_HEADER_LENGTH +
  92151. (
  92152. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  92153. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
  92154. FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
  92155. FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
  92156. FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
  92157. FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
  92158. FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN
  92159. - 4
  92160. ) / 8;
  92161. b[0] = ((FLAC__byte)(bps-1) << 4) | (FLAC__byte)((samples >> 32) & 0x0F);
  92162. b[1] = (FLAC__byte)((samples >> 24) & 0xFF);
  92163. b[2] = (FLAC__byte)((samples >> 16) & 0xFF);
  92164. b[3] = (FLAC__byte)((samples >> 8) & 0xFF);
  92165. b[4] = (FLAC__byte)(samples & 0xFF);
  92166. 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) {
  92167. if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
  92168. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92169. return;
  92170. }
  92171. if(encoder->private_->write_callback(encoder, b, 5, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  92172. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92173. return;
  92174. }
  92175. }
  92176. {
  92177. const unsigned min_framesize_offset =
  92178. FLAC__STREAM_METADATA_HEADER_LENGTH +
  92179. (
  92180. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  92181. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN
  92182. ) / 8;
  92183. b[0] = (FLAC__byte)((min_framesize >> 16) & 0xFF);
  92184. b[1] = (FLAC__byte)((min_framesize >> 8) & 0xFF);
  92185. b[2] = (FLAC__byte)(min_framesize & 0xFF);
  92186. b[3] = (FLAC__byte)((max_framesize >> 16) & 0xFF);
  92187. b[4] = (FLAC__byte)((max_framesize >> 8) & 0xFF);
  92188. b[5] = (FLAC__byte)(max_framesize & 0xFF);
  92189. 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) {
  92190. if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
  92191. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92192. return;
  92193. }
  92194. if(encoder->private_->write_callback(encoder, b, 6, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  92195. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92196. return;
  92197. }
  92198. }
  92199. if(0 != encoder->private_->seek_table && encoder->private_->seek_table->num_points > 0 && encoder->protected_->seektable_offset > 0) {
  92200. unsigned i;
  92201. FLAC__format_seektable_sort(encoder->private_->seek_table);
  92202. FLAC__ASSERT(FLAC__format_seektable_is_legal(encoder->private_->seek_table));
  92203. 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) {
  92204. if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
  92205. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92206. return;
  92207. }
  92208. for(i = 0; i < encoder->private_->seek_table->num_points; i++) {
  92209. FLAC__uint64 xx;
  92210. unsigned x;
  92211. xx = encoder->private_->seek_table->points[i].sample_number;
  92212. b[7] = (FLAC__byte)xx; xx >>= 8;
  92213. b[6] = (FLAC__byte)xx; xx >>= 8;
  92214. b[5] = (FLAC__byte)xx; xx >>= 8;
  92215. b[4] = (FLAC__byte)xx; xx >>= 8;
  92216. b[3] = (FLAC__byte)xx; xx >>= 8;
  92217. b[2] = (FLAC__byte)xx; xx >>= 8;
  92218. b[1] = (FLAC__byte)xx; xx >>= 8;
  92219. b[0] = (FLAC__byte)xx; xx >>= 8;
  92220. xx = encoder->private_->seek_table->points[i].stream_offset;
  92221. b[15] = (FLAC__byte)xx; xx >>= 8;
  92222. b[14] = (FLAC__byte)xx; xx >>= 8;
  92223. b[13] = (FLAC__byte)xx; xx >>= 8;
  92224. b[12] = (FLAC__byte)xx; xx >>= 8;
  92225. b[11] = (FLAC__byte)xx; xx >>= 8;
  92226. b[10] = (FLAC__byte)xx; xx >>= 8;
  92227. b[9] = (FLAC__byte)xx; xx >>= 8;
  92228. b[8] = (FLAC__byte)xx; xx >>= 8;
  92229. x = encoder->private_->seek_table->points[i].frame_samples;
  92230. b[17] = (FLAC__byte)x; x >>= 8;
  92231. b[16] = (FLAC__byte)x; x >>= 8;
  92232. if(encoder->private_->write_callback(encoder, b, 18, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  92233. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92234. return;
  92235. }
  92236. }
  92237. }
  92238. }
  92239. #if FLAC__HAS_OGG
  92240. void update_ogg_metadata_(FLAC__StreamEncoder *encoder)
  92241. {
  92242. static const unsigned FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH =
  92243. FLAC__OGG_MAPPING_PACKET_TYPE_LENGTH +
  92244. FLAC__OGG_MAPPING_MAGIC_LENGTH +
  92245. FLAC__OGG_MAPPING_VERSION_MAJOR_LENGTH +
  92246. FLAC__OGG_MAPPING_VERSION_MINOR_LENGTH +
  92247. FLAC__OGG_MAPPING_NUM_HEADERS_LENGTH +
  92248. FLAC__STREAM_SYNC_LENGTH
  92249. ;
  92250. FLAC__byte b[max(6, FLAC__STREAM_METADATA_SEEKPOINT_LENGTH)];
  92251. const FLAC__StreamMetadata *metadata = &encoder->private_->streaminfo;
  92252. const FLAC__uint64 samples = metadata->data.stream_info.total_samples;
  92253. const unsigned min_framesize = metadata->data.stream_info.min_framesize;
  92254. const unsigned max_framesize = metadata->data.stream_info.max_framesize;
  92255. ogg_page page;
  92256. FLAC__ASSERT(metadata->type == FLAC__METADATA_TYPE_STREAMINFO);
  92257. FLAC__ASSERT(0 != encoder->private_->seek_callback);
  92258. if(encoder->private_->seek_callback(encoder, 0, encoder->private_->client_data) == FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED)
  92259. return;
  92260. simple_ogg_page__init(&page);
  92261. if(!simple_ogg_page__get_at(encoder, encoder->protected_->streaminfo_offset, &page, encoder->private_->seek_callback, encoder->private_->read_callback, encoder->private_->client_data)) {
  92262. simple_ogg_page__clear(&page);
  92263. return; /* state already set */
  92264. }
  92265. {
  92266. const unsigned md5_offset =
  92267. FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH +
  92268. FLAC__STREAM_METADATA_HEADER_LENGTH +
  92269. (
  92270. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  92271. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
  92272. FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
  92273. FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
  92274. FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
  92275. FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
  92276. FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN +
  92277. FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN
  92278. ) / 8;
  92279. if(md5_offset + 16 > (unsigned)page.body_len) {
  92280. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  92281. simple_ogg_page__clear(&page);
  92282. return;
  92283. }
  92284. memcpy(page.body + md5_offset, metadata->data.stream_info.md5sum, 16);
  92285. }
  92286. {
  92287. const unsigned total_samples_byte_offset =
  92288. FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH +
  92289. FLAC__STREAM_METADATA_HEADER_LENGTH +
  92290. (
  92291. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  92292. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
  92293. FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
  92294. FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
  92295. FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
  92296. FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
  92297. FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN
  92298. - 4
  92299. ) / 8;
  92300. if(total_samples_byte_offset + 5 > (unsigned)page.body_len) {
  92301. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  92302. simple_ogg_page__clear(&page);
  92303. return;
  92304. }
  92305. b[0] = (FLAC__byte)page.body[total_samples_byte_offset] & 0xF0;
  92306. b[0] |= (FLAC__byte)((samples >> 32) & 0x0F);
  92307. b[1] = (FLAC__byte)((samples >> 24) & 0xFF);
  92308. b[2] = (FLAC__byte)((samples >> 16) & 0xFF);
  92309. b[3] = (FLAC__byte)((samples >> 8) & 0xFF);
  92310. b[4] = (FLAC__byte)(samples & 0xFF);
  92311. memcpy(page.body + total_samples_byte_offset, b, 5);
  92312. }
  92313. {
  92314. const unsigned min_framesize_offset =
  92315. FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH +
  92316. FLAC__STREAM_METADATA_HEADER_LENGTH +
  92317. (
  92318. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  92319. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN
  92320. ) / 8;
  92321. if(min_framesize_offset + 6 > (unsigned)page.body_len) {
  92322. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  92323. simple_ogg_page__clear(&page);
  92324. return;
  92325. }
  92326. b[0] = (FLAC__byte)((min_framesize >> 16) & 0xFF);
  92327. b[1] = (FLAC__byte)((min_framesize >> 8) & 0xFF);
  92328. b[2] = (FLAC__byte)(min_framesize & 0xFF);
  92329. b[3] = (FLAC__byte)((max_framesize >> 16) & 0xFF);
  92330. b[4] = (FLAC__byte)((max_framesize >> 8) & 0xFF);
  92331. b[5] = (FLAC__byte)(max_framesize & 0xFF);
  92332. memcpy(page.body + min_framesize_offset, b, 6);
  92333. }
  92334. if(!simple_ogg_page__set_at(encoder, encoder->protected_->streaminfo_offset, &page, encoder->private_->seek_callback, encoder->private_->write_callback, encoder->private_->client_data)) {
  92335. simple_ogg_page__clear(&page);
  92336. return; /* state already set */
  92337. }
  92338. simple_ogg_page__clear(&page);
  92339. if(0 != encoder->private_->seek_table && encoder->private_->seek_table->num_points > 0 && encoder->protected_->seektable_offset > 0) {
  92340. unsigned i;
  92341. FLAC__byte *p;
  92342. FLAC__format_seektable_sort(encoder->private_->seek_table);
  92343. FLAC__ASSERT(FLAC__format_seektable_is_legal(encoder->private_->seek_table));
  92344. simple_ogg_page__init(&page);
  92345. if(!simple_ogg_page__get_at(encoder, encoder->protected_->seektable_offset, &page, encoder->private_->seek_callback, encoder->private_->read_callback, encoder->private_->client_data)) {
  92346. simple_ogg_page__clear(&page);
  92347. return; /* state already set */
  92348. }
  92349. if((FLAC__STREAM_METADATA_HEADER_LENGTH + 18*encoder->private_->seek_table->num_points) != (unsigned)page.body_len) {
  92350. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  92351. simple_ogg_page__clear(&page);
  92352. return;
  92353. }
  92354. for(i = 0, p = page.body + FLAC__STREAM_METADATA_HEADER_LENGTH; i < encoder->private_->seek_table->num_points; i++, p += 18) {
  92355. FLAC__uint64 xx;
  92356. unsigned x;
  92357. xx = encoder->private_->seek_table->points[i].sample_number;
  92358. b[7] = (FLAC__byte)xx; xx >>= 8;
  92359. b[6] = (FLAC__byte)xx; xx >>= 8;
  92360. b[5] = (FLAC__byte)xx; xx >>= 8;
  92361. b[4] = (FLAC__byte)xx; xx >>= 8;
  92362. b[3] = (FLAC__byte)xx; xx >>= 8;
  92363. b[2] = (FLAC__byte)xx; xx >>= 8;
  92364. b[1] = (FLAC__byte)xx; xx >>= 8;
  92365. b[0] = (FLAC__byte)xx; xx >>= 8;
  92366. xx = encoder->private_->seek_table->points[i].stream_offset;
  92367. b[15] = (FLAC__byte)xx; xx >>= 8;
  92368. b[14] = (FLAC__byte)xx; xx >>= 8;
  92369. b[13] = (FLAC__byte)xx; xx >>= 8;
  92370. b[12] = (FLAC__byte)xx; xx >>= 8;
  92371. b[11] = (FLAC__byte)xx; xx >>= 8;
  92372. b[10] = (FLAC__byte)xx; xx >>= 8;
  92373. b[9] = (FLAC__byte)xx; xx >>= 8;
  92374. b[8] = (FLAC__byte)xx; xx >>= 8;
  92375. x = encoder->private_->seek_table->points[i].frame_samples;
  92376. b[17] = (FLAC__byte)x; x >>= 8;
  92377. b[16] = (FLAC__byte)x; x >>= 8;
  92378. memcpy(p, b, 18);
  92379. }
  92380. if(!simple_ogg_page__set_at(encoder, encoder->protected_->seektable_offset, &page, encoder->private_->seek_callback, encoder->private_->write_callback, encoder->private_->client_data)) {
  92381. simple_ogg_page__clear(&page);
  92382. return; /* state already set */
  92383. }
  92384. simple_ogg_page__clear(&page);
  92385. }
  92386. }
  92387. #endif
  92388. FLAC__bool process_frame_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block, FLAC__bool is_last_block)
  92389. {
  92390. FLAC__uint16 crc;
  92391. FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
  92392. 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)) {
  92393. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  92394. return false;
  92395. }
  92396. if(!process_subframes_(encoder, is_fractional_block)) {
  92397. return false;
  92398. }
  92399. if(!FLAC__bitwriter_zero_pad_to_byte_boundary(encoder->private_->frame)) {
  92400. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  92401. return false;
  92402. }
  92403. FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(encoder->private_->frame));
  92404. if(
  92405. !FLAC__bitwriter_get_write_crc16(encoder->private_->frame, &crc) ||
  92406. !FLAC__bitwriter_write_raw_uint32(encoder->private_->frame, crc, FLAC__FRAME_FOOTER_CRC_LEN)
  92407. ) {
  92408. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  92409. return false;
  92410. }
  92411. if(!write_bitbuffer_(encoder, encoder->protected_->blocksize, is_last_block)) {
  92412. return false;
  92413. }
  92414. encoder->private_->current_sample_number = 0;
  92415. encoder->private_->current_frame_number++;
  92416. encoder->private_->streaminfo.data.stream_info.total_samples += (FLAC__uint64)encoder->protected_->blocksize;
  92417. return true;
  92418. }
  92419. FLAC__bool process_subframes_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block)
  92420. {
  92421. FLAC__FrameHeader frame_header;
  92422. unsigned channel, min_partition_order = encoder->protected_->min_residual_partition_order, max_partition_order;
  92423. FLAC__bool do_independent, do_mid_side;
  92424. if(is_fractional_block) {
  92425. max_partition_order = 0;
  92426. }
  92427. else {
  92428. max_partition_order = FLAC__format_get_max_rice_partition_order_from_blocksize(encoder->protected_->blocksize);
  92429. max_partition_order = min(max_partition_order, encoder->protected_->max_residual_partition_order);
  92430. }
  92431. min_partition_order = min(min_partition_order, max_partition_order);
  92432. frame_header.blocksize = encoder->protected_->blocksize;
  92433. frame_header.sample_rate = encoder->protected_->sample_rate;
  92434. frame_header.channels = encoder->protected_->channels;
  92435. frame_header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT; /* the default unless the encoder determines otherwise */
  92436. frame_header.bits_per_sample = encoder->protected_->bits_per_sample;
  92437. frame_header.number_type = FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER;
  92438. frame_header.number.frame_number = encoder->private_->current_frame_number;
  92439. if(encoder->protected_->do_mid_side_stereo) {
  92440. if(encoder->protected_->loose_mid_side_stereo) {
  92441. if(encoder->private_->loose_mid_side_stereo_frame_count == 0) {
  92442. do_independent = true;
  92443. do_mid_side = true;
  92444. }
  92445. else {
  92446. do_independent = (encoder->private_->last_channel_assignment == FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT);
  92447. do_mid_side = !do_independent;
  92448. }
  92449. }
  92450. else {
  92451. do_independent = true;
  92452. do_mid_side = true;
  92453. }
  92454. }
  92455. else {
  92456. do_independent = true;
  92457. do_mid_side = false;
  92458. }
  92459. FLAC__ASSERT(do_independent || do_mid_side);
  92460. if(do_independent) {
  92461. for(channel = 0; channel < encoder->protected_->channels; channel++) {
  92462. const unsigned w = get_wasted_bits_(encoder->private_->integer_signal[channel], encoder->protected_->blocksize);
  92463. encoder->private_->subframe_workspace[channel][0].wasted_bits = encoder->private_->subframe_workspace[channel][1].wasted_bits = w;
  92464. encoder->private_->subframe_bps[channel] = encoder->protected_->bits_per_sample - w;
  92465. }
  92466. }
  92467. if(do_mid_side) {
  92468. FLAC__ASSERT(encoder->protected_->channels == 2);
  92469. for(channel = 0; channel < 2; channel++) {
  92470. const unsigned w = get_wasted_bits_(encoder->private_->integer_signal_mid_side[channel], encoder->protected_->blocksize);
  92471. encoder->private_->subframe_workspace_mid_side[channel][0].wasted_bits = encoder->private_->subframe_workspace_mid_side[channel][1].wasted_bits = w;
  92472. encoder->private_->subframe_bps_mid_side[channel] = encoder->protected_->bits_per_sample - w + (channel==0? 0:1);
  92473. }
  92474. }
  92475. if(do_independent) {
  92476. for(channel = 0; channel < encoder->protected_->channels; channel++) {
  92477. if(!
  92478. process_subframe_(
  92479. encoder,
  92480. min_partition_order,
  92481. max_partition_order,
  92482. &frame_header,
  92483. encoder->private_->subframe_bps[channel],
  92484. encoder->private_->integer_signal[channel],
  92485. encoder->private_->subframe_workspace_ptr[channel],
  92486. encoder->private_->partitioned_rice_contents_workspace_ptr[channel],
  92487. encoder->private_->residual_workspace[channel],
  92488. encoder->private_->best_subframe+channel,
  92489. encoder->private_->best_subframe_bits+channel
  92490. )
  92491. )
  92492. return false;
  92493. }
  92494. }
  92495. if(do_mid_side) {
  92496. FLAC__ASSERT(encoder->protected_->channels == 2);
  92497. for(channel = 0; channel < 2; channel++) {
  92498. if(!
  92499. process_subframe_(
  92500. encoder,
  92501. min_partition_order,
  92502. max_partition_order,
  92503. &frame_header,
  92504. encoder->private_->subframe_bps_mid_side[channel],
  92505. encoder->private_->integer_signal_mid_side[channel],
  92506. encoder->private_->subframe_workspace_ptr_mid_side[channel],
  92507. encoder->private_->partitioned_rice_contents_workspace_ptr_mid_side[channel],
  92508. encoder->private_->residual_workspace_mid_side[channel],
  92509. encoder->private_->best_subframe_mid_side+channel,
  92510. encoder->private_->best_subframe_bits_mid_side+channel
  92511. )
  92512. )
  92513. return false;
  92514. }
  92515. }
  92516. if(do_mid_side) {
  92517. unsigned left_bps = 0, right_bps = 0; /* initialized only to prevent superfluous compiler warning */
  92518. FLAC__Subframe *left_subframe = 0, *right_subframe = 0; /* initialized only to prevent superfluous compiler warning */
  92519. FLAC__ChannelAssignment channel_assignment;
  92520. FLAC__ASSERT(encoder->protected_->channels == 2);
  92521. if(encoder->protected_->loose_mid_side_stereo && encoder->private_->loose_mid_side_stereo_frame_count > 0) {
  92522. channel_assignment = (encoder->private_->last_channel_assignment == FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT? FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT : FLAC__CHANNEL_ASSIGNMENT_MID_SIDE);
  92523. }
  92524. else {
  92525. unsigned bits[4]; /* WATCHOUT - indexed by FLAC__ChannelAssignment */
  92526. unsigned min_bits;
  92527. int ca;
  92528. FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT == 0);
  92529. FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE == 1);
  92530. FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE == 2);
  92531. FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_MID_SIDE == 3);
  92532. FLAC__ASSERT(do_independent && do_mid_side);
  92533. bits[FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT] = encoder->private_->best_subframe_bits [0] + encoder->private_->best_subframe_bits [1];
  92534. bits[FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE ] = encoder->private_->best_subframe_bits [0] + encoder->private_->best_subframe_bits_mid_side[1];
  92535. bits[FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE ] = encoder->private_->best_subframe_bits [1] + encoder->private_->best_subframe_bits_mid_side[1];
  92536. bits[FLAC__CHANNEL_ASSIGNMENT_MID_SIDE ] = encoder->private_->best_subframe_bits_mid_side[0] + encoder->private_->best_subframe_bits_mid_side[1];
  92537. channel_assignment = FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT;
  92538. min_bits = bits[channel_assignment];
  92539. for(ca = 1; ca <= 3; ca++) {
  92540. if(bits[ca] < min_bits) {
  92541. min_bits = bits[ca];
  92542. channel_assignment = (FLAC__ChannelAssignment)ca;
  92543. }
  92544. }
  92545. }
  92546. frame_header.channel_assignment = channel_assignment;
  92547. if(!FLAC__frame_add_header(&frame_header, encoder->private_->frame)) {
  92548. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92549. return false;
  92550. }
  92551. switch(channel_assignment) {
  92552. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  92553. left_subframe = &encoder->private_->subframe_workspace [0][encoder->private_->best_subframe [0]];
  92554. right_subframe = &encoder->private_->subframe_workspace [1][encoder->private_->best_subframe [1]];
  92555. break;
  92556. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  92557. left_subframe = &encoder->private_->subframe_workspace [0][encoder->private_->best_subframe [0]];
  92558. right_subframe = &encoder->private_->subframe_workspace_mid_side[1][encoder->private_->best_subframe_mid_side[1]];
  92559. break;
  92560. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  92561. left_subframe = &encoder->private_->subframe_workspace_mid_side[1][encoder->private_->best_subframe_mid_side[1]];
  92562. right_subframe = &encoder->private_->subframe_workspace [1][encoder->private_->best_subframe [1]];
  92563. break;
  92564. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  92565. left_subframe = &encoder->private_->subframe_workspace_mid_side[0][encoder->private_->best_subframe_mid_side[0]];
  92566. right_subframe = &encoder->private_->subframe_workspace_mid_side[1][encoder->private_->best_subframe_mid_side[1]];
  92567. break;
  92568. default:
  92569. FLAC__ASSERT(0);
  92570. }
  92571. switch(channel_assignment) {
  92572. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  92573. left_bps = encoder->private_->subframe_bps [0];
  92574. right_bps = encoder->private_->subframe_bps [1];
  92575. break;
  92576. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  92577. left_bps = encoder->private_->subframe_bps [0];
  92578. right_bps = encoder->private_->subframe_bps_mid_side[1];
  92579. break;
  92580. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  92581. left_bps = encoder->private_->subframe_bps_mid_side[1];
  92582. right_bps = encoder->private_->subframe_bps [1];
  92583. break;
  92584. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  92585. left_bps = encoder->private_->subframe_bps_mid_side[0];
  92586. right_bps = encoder->private_->subframe_bps_mid_side[1];
  92587. break;
  92588. default:
  92589. FLAC__ASSERT(0);
  92590. }
  92591. if(!add_subframe_(encoder, frame_header.blocksize, left_bps , left_subframe , encoder->private_->frame))
  92592. return false;
  92593. if(!add_subframe_(encoder, frame_header.blocksize, right_bps, right_subframe, encoder->private_->frame))
  92594. return false;
  92595. }
  92596. else {
  92597. if(!FLAC__frame_add_header(&frame_header, encoder->private_->frame)) {
  92598. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92599. return false;
  92600. }
  92601. for(channel = 0; channel < encoder->protected_->channels; channel++) {
  92602. 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)) {
  92603. return false;
  92604. }
  92605. }
  92606. }
  92607. if(encoder->protected_->loose_mid_side_stereo) {
  92608. encoder->private_->loose_mid_side_stereo_frame_count++;
  92609. if(encoder->private_->loose_mid_side_stereo_frame_count >= encoder->private_->loose_mid_side_stereo_frames)
  92610. encoder->private_->loose_mid_side_stereo_frame_count = 0;
  92611. }
  92612. encoder->private_->last_channel_assignment = frame_header.channel_assignment;
  92613. return true;
  92614. }
  92615. FLAC__bool process_subframe_(
  92616. FLAC__StreamEncoder *encoder,
  92617. unsigned min_partition_order,
  92618. unsigned max_partition_order,
  92619. const FLAC__FrameHeader *frame_header,
  92620. unsigned subframe_bps,
  92621. const FLAC__int32 integer_signal[],
  92622. FLAC__Subframe *subframe[2],
  92623. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents[2],
  92624. FLAC__int32 *residual[2],
  92625. unsigned *best_subframe,
  92626. unsigned *best_bits
  92627. )
  92628. {
  92629. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92630. FLAC__float fixed_residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1];
  92631. #else
  92632. FLAC__fixedpoint fixed_residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1];
  92633. #endif
  92634. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92635. FLAC__double lpc_residual_bits_per_sample;
  92636. 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 */
  92637. FLAC__double lpc_error[FLAC__MAX_LPC_ORDER];
  92638. unsigned min_lpc_order, max_lpc_order, lpc_order;
  92639. unsigned min_qlp_coeff_precision, max_qlp_coeff_precision, qlp_coeff_precision;
  92640. #endif
  92641. unsigned min_fixed_order, max_fixed_order, guess_fixed_order, fixed_order;
  92642. unsigned rice_parameter;
  92643. unsigned _candidate_bits, _best_bits;
  92644. unsigned _best_subframe;
  92645. 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;
  92646. FLAC__ASSERT(frame_header->blocksize > 0);
  92647. _best_subframe = 0;
  92648. if(encoder->private_->disable_verbatim_subframes && frame_header->blocksize >= FLAC__MAX_FIXED_ORDER)
  92649. _best_bits = UINT_MAX;
  92650. else
  92651. _best_bits = evaluate_verbatim_subframe_(encoder, integer_signal, frame_header->blocksize, subframe_bps, subframe[_best_subframe]);
  92652. if(frame_header->blocksize >= FLAC__MAX_FIXED_ORDER) {
  92653. unsigned signal_is_constant = false;
  92654. 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);
  92655. if(
  92656. !encoder->private_->disable_constant_subframes &&
  92657. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92658. fixed_residual_bits_per_sample[1] == 0.0
  92659. #else
  92660. fixed_residual_bits_per_sample[1] == FLAC__FP_ZERO
  92661. #endif
  92662. ) {
  92663. unsigned i;
  92664. signal_is_constant = true;
  92665. for(i = 1; i < frame_header->blocksize; i++) {
  92666. if(integer_signal[0] != integer_signal[i]) {
  92667. signal_is_constant = false;
  92668. break;
  92669. }
  92670. }
  92671. }
  92672. if(signal_is_constant) {
  92673. _candidate_bits = evaluate_constant_subframe_(encoder, integer_signal[0], frame_header->blocksize, subframe_bps, subframe[!_best_subframe]);
  92674. if(_candidate_bits < _best_bits) {
  92675. _best_subframe = !_best_subframe;
  92676. _best_bits = _candidate_bits;
  92677. }
  92678. }
  92679. else {
  92680. if(!encoder->private_->disable_fixed_subframes || (encoder->protected_->max_lpc_order == 0 && _best_bits == UINT_MAX)) {
  92681. if(encoder->protected_->do_exhaustive_model_search) {
  92682. min_fixed_order = 0;
  92683. max_fixed_order = FLAC__MAX_FIXED_ORDER;
  92684. }
  92685. else {
  92686. min_fixed_order = max_fixed_order = guess_fixed_order;
  92687. }
  92688. if(max_fixed_order >= frame_header->blocksize)
  92689. max_fixed_order = frame_header->blocksize - 1;
  92690. for(fixed_order = min_fixed_order; fixed_order <= max_fixed_order; fixed_order++) {
  92691. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92692. if(fixed_residual_bits_per_sample[fixed_order] >= (FLAC__float)subframe_bps)
  92693. continue; /* don't even try */
  92694. 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 */
  92695. #else
  92696. if(FLAC__fixedpoint_trunc(fixed_residual_bits_per_sample[fixed_order]) >= (int)subframe_bps)
  92697. continue; /* don't even try */
  92698. 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 */
  92699. #endif
  92700. rice_parameter++; /* to account for the signed->unsigned conversion during rice coding */
  92701. if(rice_parameter >= rice_parameter_limit) {
  92702. #ifdef DEBUG_VERBOSE
  92703. fprintf(stderr, "clipping rice_parameter (%u -> %u) @0\n", rice_parameter, rice_parameter_limit - 1);
  92704. #endif
  92705. rice_parameter = rice_parameter_limit - 1;
  92706. }
  92707. _candidate_bits =
  92708. evaluate_fixed_subframe_(
  92709. encoder,
  92710. integer_signal,
  92711. residual[!_best_subframe],
  92712. encoder->private_->abs_residual_partition_sums,
  92713. encoder->private_->raw_bits_per_partition,
  92714. frame_header->blocksize,
  92715. subframe_bps,
  92716. fixed_order,
  92717. rice_parameter,
  92718. rice_parameter_limit,
  92719. min_partition_order,
  92720. max_partition_order,
  92721. encoder->protected_->do_escape_coding,
  92722. encoder->protected_->rice_parameter_search_dist,
  92723. subframe[!_best_subframe],
  92724. partitioned_rice_contents[!_best_subframe]
  92725. );
  92726. if(_candidate_bits < _best_bits) {
  92727. _best_subframe = !_best_subframe;
  92728. _best_bits = _candidate_bits;
  92729. }
  92730. }
  92731. }
  92732. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92733. if(encoder->protected_->max_lpc_order > 0) {
  92734. if(encoder->protected_->max_lpc_order >= frame_header->blocksize)
  92735. max_lpc_order = frame_header->blocksize-1;
  92736. else
  92737. max_lpc_order = encoder->protected_->max_lpc_order;
  92738. if(max_lpc_order > 0) {
  92739. unsigned a;
  92740. for (a = 0; a < encoder->protected_->num_apodizations; a++) {
  92741. FLAC__lpc_window_data(integer_signal, encoder->private_->window[a], encoder->private_->windowed_signal, frame_header->blocksize);
  92742. encoder->private_->local_lpc_compute_autocorrelation(encoder->private_->windowed_signal, frame_header->blocksize, max_lpc_order+1, autoc);
  92743. if(autoc[0] != 0.0) {
  92744. FLAC__lpc_compute_lp_coefficients(autoc, &max_lpc_order, encoder->private_->lp_coeff, lpc_error);
  92745. if(encoder->protected_->do_exhaustive_model_search) {
  92746. min_lpc_order = 1;
  92747. }
  92748. else {
  92749. const unsigned guess_lpc_order =
  92750. FLAC__lpc_compute_best_order(
  92751. lpc_error,
  92752. max_lpc_order,
  92753. frame_header->blocksize,
  92754. subframe_bps + (
  92755. encoder->protected_->do_qlp_coeff_prec_search?
  92756. FLAC__MIN_QLP_COEFF_PRECISION : /* have to guess; use the min possible size to avoid accidentally favoring lower orders */
  92757. encoder->protected_->qlp_coeff_precision
  92758. )
  92759. );
  92760. min_lpc_order = max_lpc_order = guess_lpc_order;
  92761. }
  92762. if(max_lpc_order >= frame_header->blocksize)
  92763. max_lpc_order = frame_header->blocksize - 1;
  92764. for(lpc_order = min_lpc_order; lpc_order <= max_lpc_order; lpc_order++) {
  92765. lpc_residual_bits_per_sample = FLAC__lpc_compute_expected_bits_per_residual_sample(lpc_error[lpc_order-1], frame_header->blocksize-lpc_order);
  92766. if(lpc_residual_bits_per_sample >= (FLAC__double)subframe_bps)
  92767. continue; /* don't even try */
  92768. rice_parameter = (lpc_residual_bits_per_sample > 0.0)? (unsigned)(lpc_residual_bits_per_sample+0.5) : 0; /* 0.5 is for rounding */
  92769. rice_parameter++; /* to account for the signed->unsigned conversion during rice coding */
  92770. if(rice_parameter >= rice_parameter_limit) {
  92771. #ifdef DEBUG_VERBOSE
  92772. fprintf(stderr, "clipping rice_parameter (%u -> %u) @1\n", rice_parameter, rice_parameter_limit - 1);
  92773. #endif
  92774. rice_parameter = rice_parameter_limit - 1;
  92775. }
  92776. if(encoder->protected_->do_qlp_coeff_prec_search) {
  92777. min_qlp_coeff_precision = FLAC__MIN_QLP_COEFF_PRECISION;
  92778. if(subframe_bps <= 17) {
  92779. max_qlp_coeff_precision = min(32 - subframe_bps - lpc_order, FLAC__MAX_QLP_COEFF_PRECISION);
  92780. max_qlp_coeff_precision = max(max_qlp_coeff_precision, min_qlp_coeff_precision);
  92781. }
  92782. else
  92783. max_qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION;
  92784. }
  92785. else {
  92786. min_qlp_coeff_precision = max_qlp_coeff_precision = encoder->protected_->qlp_coeff_precision;
  92787. }
  92788. for(qlp_coeff_precision = min_qlp_coeff_precision; qlp_coeff_precision <= max_qlp_coeff_precision; qlp_coeff_precision++) {
  92789. _candidate_bits =
  92790. evaluate_lpc_subframe_(
  92791. encoder,
  92792. integer_signal,
  92793. residual[!_best_subframe],
  92794. encoder->private_->abs_residual_partition_sums,
  92795. encoder->private_->raw_bits_per_partition,
  92796. encoder->private_->lp_coeff[lpc_order-1],
  92797. frame_header->blocksize,
  92798. subframe_bps,
  92799. lpc_order,
  92800. qlp_coeff_precision,
  92801. rice_parameter,
  92802. rice_parameter_limit,
  92803. min_partition_order,
  92804. max_partition_order,
  92805. encoder->protected_->do_escape_coding,
  92806. encoder->protected_->rice_parameter_search_dist,
  92807. subframe[!_best_subframe],
  92808. partitioned_rice_contents[!_best_subframe]
  92809. );
  92810. if(_candidate_bits > 0) { /* if == 0, there was a problem quantizing the lpcoeffs */
  92811. if(_candidate_bits < _best_bits) {
  92812. _best_subframe = !_best_subframe;
  92813. _best_bits = _candidate_bits;
  92814. }
  92815. }
  92816. }
  92817. }
  92818. }
  92819. }
  92820. }
  92821. }
  92822. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  92823. }
  92824. }
  92825. if(_best_bits == UINT_MAX) {
  92826. FLAC__ASSERT(_best_subframe == 0);
  92827. _best_bits = evaluate_verbatim_subframe_(encoder, integer_signal, frame_header->blocksize, subframe_bps, subframe[_best_subframe]);
  92828. }
  92829. *best_subframe = _best_subframe;
  92830. *best_bits = _best_bits;
  92831. return true;
  92832. }
  92833. FLAC__bool add_subframe_(
  92834. FLAC__StreamEncoder *encoder,
  92835. unsigned blocksize,
  92836. unsigned subframe_bps,
  92837. const FLAC__Subframe *subframe,
  92838. FLAC__BitWriter *frame
  92839. )
  92840. {
  92841. switch(subframe->type) {
  92842. case FLAC__SUBFRAME_TYPE_CONSTANT:
  92843. if(!FLAC__subframe_add_constant(&(subframe->data.constant), subframe_bps, subframe->wasted_bits, frame)) {
  92844. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92845. return false;
  92846. }
  92847. break;
  92848. case FLAC__SUBFRAME_TYPE_FIXED:
  92849. if(!FLAC__subframe_add_fixed(&(subframe->data.fixed), blocksize - subframe->data.fixed.order, subframe_bps, subframe->wasted_bits, frame)) {
  92850. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92851. return false;
  92852. }
  92853. break;
  92854. case FLAC__SUBFRAME_TYPE_LPC:
  92855. if(!FLAC__subframe_add_lpc(&(subframe->data.lpc), blocksize - subframe->data.lpc.order, subframe_bps, subframe->wasted_bits, frame)) {
  92856. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92857. return false;
  92858. }
  92859. break;
  92860. case FLAC__SUBFRAME_TYPE_VERBATIM:
  92861. if(!FLAC__subframe_add_verbatim(&(subframe->data.verbatim), blocksize, subframe_bps, subframe->wasted_bits, frame)) {
  92862. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92863. return false;
  92864. }
  92865. break;
  92866. default:
  92867. FLAC__ASSERT(0);
  92868. }
  92869. return true;
  92870. }
  92871. #define SPOTCHECK_ESTIMATE 0
  92872. #if SPOTCHECK_ESTIMATE
  92873. static void spotcheck_subframe_estimate_(
  92874. FLAC__StreamEncoder *encoder,
  92875. unsigned blocksize,
  92876. unsigned subframe_bps,
  92877. const FLAC__Subframe *subframe,
  92878. unsigned estimate
  92879. )
  92880. {
  92881. FLAC__bool ret;
  92882. FLAC__BitWriter *frame = FLAC__bitwriter_new();
  92883. if(frame == 0) {
  92884. fprintf(stderr, "EST: can't allocate frame\n");
  92885. return;
  92886. }
  92887. if(!FLAC__bitwriter_init(frame)) {
  92888. fprintf(stderr, "EST: can't init frame\n");
  92889. return;
  92890. }
  92891. ret = add_subframe_(encoder, blocksize, subframe_bps, subframe, frame);
  92892. FLAC__ASSERT(ret);
  92893. {
  92894. const unsigned actual = FLAC__bitwriter_get_input_bits_unconsumed(frame);
  92895. if(estimate != actual)
  92896. 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);
  92897. }
  92898. FLAC__bitwriter_delete(frame);
  92899. }
  92900. #endif
  92901. unsigned evaluate_constant_subframe_(
  92902. FLAC__StreamEncoder *encoder,
  92903. const FLAC__int32 signal,
  92904. unsigned blocksize,
  92905. unsigned subframe_bps,
  92906. FLAC__Subframe *subframe
  92907. )
  92908. {
  92909. unsigned estimate;
  92910. subframe->type = FLAC__SUBFRAME_TYPE_CONSTANT;
  92911. subframe->data.constant.value = signal;
  92912. estimate = FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN + subframe->wasted_bits + subframe_bps;
  92913. #if SPOTCHECK_ESTIMATE
  92914. spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
  92915. #else
  92916. (void)encoder, (void)blocksize;
  92917. #endif
  92918. return estimate;
  92919. }
  92920. unsigned evaluate_fixed_subframe_(
  92921. FLAC__StreamEncoder *encoder,
  92922. const FLAC__int32 signal[],
  92923. FLAC__int32 residual[],
  92924. FLAC__uint64 abs_residual_partition_sums[],
  92925. unsigned raw_bits_per_partition[],
  92926. unsigned blocksize,
  92927. unsigned subframe_bps,
  92928. unsigned order,
  92929. unsigned rice_parameter,
  92930. unsigned rice_parameter_limit,
  92931. unsigned min_partition_order,
  92932. unsigned max_partition_order,
  92933. FLAC__bool do_escape_coding,
  92934. unsigned rice_parameter_search_dist,
  92935. FLAC__Subframe *subframe,
  92936. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
  92937. )
  92938. {
  92939. unsigned i, residual_bits, estimate;
  92940. const unsigned residual_samples = blocksize - order;
  92941. FLAC__fixed_compute_residual(signal+order, residual_samples, order, residual);
  92942. subframe->type = FLAC__SUBFRAME_TYPE_FIXED;
  92943. subframe->data.fixed.entropy_coding_method.type = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE;
  92944. subframe->data.fixed.entropy_coding_method.data.partitioned_rice.contents = partitioned_rice_contents;
  92945. subframe->data.fixed.residual = residual;
  92946. residual_bits =
  92947. find_best_partition_order_(
  92948. encoder->private_,
  92949. residual,
  92950. abs_residual_partition_sums,
  92951. raw_bits_per_partition,
  92952. residual_samples,
  92953. order,
  92954. rice_parameter,
  92955. rice_parameter_limit,
  92956. min_partition_order,
  92957. max_partition_order,
  92958. subframe_bps,
  92959. do_escape_coding,
  92960. rice_parameter_search_dist,
  92961. &subframe->data.fixed.entropy_coding_method
  92962. );
  92963. subframe->data.fixed.order = order;
  92964. for(i = 0; i < order; i++)
  92965. subframe->data.fixed.warmup[i] = signal[i];
  92966. estimate = FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN + subframe->wasted_bits + (order * subframe_bps) + residual_bits;
  92967. #if SPOTCHECK_ESTIMATE
  92968. spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
  92969. #endif
  92970. return estimate;
  92971. }
  92972. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92973. unsigned evaluate_lpc_subframe_(
  92974. FLAC__StreamEncoder *encoder,
  92975. const FLAC__int32 signal[],
  92976. FLAC__int32 residual[],
  92977. FLAC__uint64 abs_residual_partition_sums[],
  92978. unsigned raw_bits_per_partition[],
  92979. const FLAC__real lp_coeff[],
  92980. unsigned blocksize,
  92981. unsigned subframe_bps,
  92982. unsigned order,
  92983. unsigned qlp_coeff_precision,
  92984. unsigned rice_parameter,
  92985. unsigned rice_parameter_limit,
  92986. unsigned min_partition_order,
  92987. unsigned max_partition_order,
  92988. FLAC__bool do_escape_coding,
  92989. unsigned rice_parameter_search_dist,
  92990. FLAC__Subframe *subframe,
  92991. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
  92992. )
  92993. {
  92994. FLAC__int32 qlp_coeff[FLAC__MAX_LPC_ORDER];
  92995. unsigned i, residual_bits, estimate;
  92996. int quantization, ret;
  92997. const unsigned residual_samples = blocksize - order;
  92998. if(subframe_bps <= 16) {
  92999. FLAC__ASSERT(order > 0);
  93000. FLAC__ASSERT(order <= FLAC__MAX_LPC_ORDER);
  93001. qlp_coeff_precision = min(qlp_coeff_precision, 32 - subframe_bps - FLAC__bitmath_ilog2(order));
  93002. }
  93003. ret = FLAC__lpc_quantize_coefficients(lp_coeff, order, qlp_coeff_precision, qlp_coeff, &quantization);
  93004. if(ret != 0)
  93005. return 0; /* this is a hack to indicate to the caller that we can't do lp at this order on this subframe */
  93006. if(subframe_bps + qlp_coeff_precision + FLAC__bitmath_ilog2(order) <= 32)
  93007. if(subframe_bps <= 16 && qlp_coeff_precision <= 16)
  93008. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit(signal+order, residual_samples, qlp_coeff, order, quantization, residual);
  93009. else
  93010. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients(signal+order, residual_samples, qlp_coeff, order, quantization, residual);
  93011. else
  93012. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_64bit(signal+order, residual_samples, qlp_coeff, order, quantization, residual);
  93013. subframe->type = FLAC__SUBFRAME_TYPE_LPC;
  93014. subframe->data.lpc.entropy_coding_method.type = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE;
  93015. subframe->data.lpc.entropy_coding_method.data.partitioned_rice.contents = partitioned_rice_contents;
  93016. subframe->data.lpc.residual = residual;
  93017. residual_bits =
  93018. find_best_partition_order_(
  93019. encoder->private_,
  93020. residual,
  93021. abs_residual_partition_sums,
  93022. raw_bits_per_partition,
  93023. residual_samples,
  93024. order,
  93025. rice_parameter,
  93026. rice_parameter_limit,
  93027. min_partition_order,
  93028. max_partition_order,
  93029. subframe_bps,
  93030. do_escape_coding,
  93031. rice_parameter_search_dist,
  93032. &subframe->data.lpc.entropy_coding_method
  93033. );
  93034. subframe->data.lpc.order = order;
  93035. subframe->data.lpc.qlp_coeff_precision = qlp_coeff_precision;
  93036. subframe->data.lpc.quantization_level = quantization;
  93037. memcpy(subframe->data.lpc.qlp_coeff, qlp_coeff, sizeof(FLAC__int32)*FLAC__MAX_LPC_ORDER);
  93038. for(i = 0; i < order; i++)
  93039. subframe->data.lpc.warmup[i] = signal[i];
  93040. 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;
  93041. #if SPOTCHECK_ESTIMATE
  93042. spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
  93043. #endif
  93044. return estimate;
  93045. }
  93046. #endif
  93047. unsigned evaluate_verbatim_subframe_(
  93048. FLAC__StreamEncoder *encoder,
  93049. const FLAC__int32 signal[],
  93050. unsigned blocksize,
  93051. unsigned subframe_bps,
  93052. FLAC__Subframe *subframe
  93053. )
  93054. {
  93055. unsigned estimate;
  93056. subframe->type = FLAC__SUBFRAME_TYPE_VERBATIM;
  93057. subframe->data.verbatim.data = signal;
  93058. estimate = FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN + subframe->wasted_bits + (blocksize * subframe_bps);
  93059. #if SPOTCHECK_ESTIMATE
  93060. spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
  93061. #else
  93062. (void)encoder;
  93063. #endif
  93064. return estimate;
  93065. }
  93066. unsigned find_best_partition_order_(
  93067. FLAC__StreamEncoderPrivate *private_,
  93068. const FLAC__int32 residual[],
  93069. FLAC__uint64 abs_residual_partition_sums[],
  93070. unsigned raw_bits_per_partition[],
  93071. unsigned residual_samples,
  93072. unsigned predictor_order,
  93073. unsigned rice_parameter,
  93074. unsigned rice_parameter_limit,
  93075. unsigned min_partition_order,
  93076. unsigned max_partition_order,
  93077. unsigned bps,
  93078. FLAC__bool do_escape_coding,
  93079. unsigned rice_parameter_search_dist,
  93080. FLAC__EntropyCodingMethod *best_ecm
  93081. )
  93082. {
  93083. unsigned residual_bits, best_residual_bits = 0;
  93084. unsigned best_parameters_index = 0;
  93085. unsigned best_partition_order = 0;
  93086. const unsigned blocksize = residual_samples + predictor_order;
  93087. max_partition_order = FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(max_partition_order, blocksize, predictor_order);
  93088. min_partition_order = min(min_partition_order, max_partition_order);
  93089. precompute_partition_info_sums_(residual, abs_residual_partition_sums, residual_samples, predictor_order, min_partition_order, max_partition_order, bps);
  93090. if(do_escape_coding)
  93091. precompute_partition_info_escapes_(residual, raw_bits_per_partition, residual_samples, predictor_order, min_partition_order, max_partition_order);
  93092. {
  93093. int partition_order;
  93094. unsigned sum;
  93095. for(partition_order = (int)max_partition_order, sum = 0; partition_order >= (int)min_partition_order; partition_order--) {
  93096. if(!
  93097. set_partitioned_rice_(
  93098. #ifdef EXACT_RICE_BITS_CALCULATION
  93099. residual,
  93100. #endif
  93101. abs_residual_partition_sums+sum,
  93102. raw_bits_per_partition+sum,
  93103. residual_samples,
  93104. predictor_order,
  93105. rice_parameter,
  93106. rice_parameter_limit,
  93107. rice_parameter_search_dist,
  93108. (unsigned)partition_order,
  93109. do_escape_coding,
  93110. &private_->partitioned_rice_contents_extra[!best_parameters_index],
  93111. &residual_bits
  93112. )
  93113. )
  93114. {
  93115. FLAC__ASSERT(best_residual_bits != 0);
  93116. break;
  93117. }
  93118. sum += 1u << partition_order;
  93119. if(best_residual_bits == 0 || residual_bits < best_residual_bits) {
  93120. best_residual_bits = residual_bits;
  93121. best_parameters_index = !best_parameters_index;
  93122. best_partition_order = partition_order;
  93123. }
  93124. }
  93125. }
  93126. best_ecm->data.partitioned_rice.order = best_partition_order;
  93127. {
  93128. FLAC__EntropyCodingMethod_PartitionedRiceContents* prc = (FLAC__EntropyCodingMethod_PartitionedRiceContents*)best_ecm->data.partitioned_rice.contents;
  93129. unsigned partition;
  93130. FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(prc, max(6, best_partition_order));
  93131. memcpy(prc->parameters, private_->partitioned_rice_contents_extra[best_parameters_index].parameters, sizeof(unsigned)*(1<<(best_partition_order)));
  93132. if(do_escape_coding)
  93133. memcpy(prc->raw_bits, private_->partitioned_rice_contents_extra[best_parameters_index].raw_bits, sizeof(unsigned)*(1<<(best_partition_order)));
  93134. for(partition = 0; partition < (1u<<best_partition_order); partition++) {
  93135. if(prc->parameters[partition] >= FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER) {
  93136. best_ecm->type = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2;
  93137. break;
  93138. }
  93139. }
  93140. }
  93141. return best_residual_bits;
  93142. }
  93143. #if defined(FLAC__CPU_IA32) && !defined FLAC__NO_ASM && defined FLAC__HAS_NASM
  93144. extern void precompute_partition_info_sums_32bit_asm_ia32_(
  93145. const FLAC__int32 residual[],
  93146. FLAC__uint64 abs_residual_partition_sums[],
  93147. unsigned blocksize,
  93148. unsigned predictor_order,
  93149. unsigned min_partition_order,
  93150. unsigned max_partition_order
  93151. );
  93152. #endif
  93153. void precompute_partition_info_sums_(
  93154. const FLAC__int32 residual[],
  93155. FLAC__uint64 abs_residual_partition_sums[],
  93156. unsigned residual_samples,
  93157. unsigned predictor_order,
  93158. unsigned min_partition_order,
  93159. unsigned max_partition_order,
  93160. unsigned bps
  93161. )
  93162. {
  93163. const unsigned default_partition_samples = (residual_samples + predictor_order) >> max_partition_order;
  93164. unsigned partitions = 1u << max_partition_order;
  93165. FLAC__ASSERT(default_partition_samples > predictor_order);
  93166. #if defined(FLAC__CPU_IA32) && !defined FLAC__NO_ASM && defined FLAC__HAS_NASM
  93167. if(FLAC__bitmath_ilog2(default_partition_samples) + bps < 32) {
  93168. precompute_partition_info_sums_32bit_asm_ia32_(residual, abs_residual_partition_sums, residual_samples + predictor_order, predictor_order, min_partition_order, max_partition_order);
  93169. return;
  93170. }
  93171. #endif
  93172. {
  93173. unsigned partition, residual_sample, end = (unsigned)(-(int)predictor_order);
  93174. if(FLAC__bitmath_ilog2(default_partition_samples) + bps < 32) {
  93175. FLAC__uint32 abs_residual_partition_sum;
  93176. for(partition = residual_sample = 0; partition < partitions; partition++) {
  93177. end += default_partition_samples;
  93178. abs_residual_partition_sum = 0;
  93179. for( ; residual_sample < end; residual_sample++)
  93180. abs_residual_partition_sum += abs(residual[residual_sample]); /* abs(INT_MIN) is undefined, but if the residual is INT_MIN we have bigger problems */
  93181. abs_residual_partition_sums[partition] = abs_residual_partition_sum;
  93182. }
  93183. }
  93184. else { /* have to pessimistically use 64 bits for accumulator */
  93185. FLAC__uint64 abs_residual_partition_sum;
  93186. for(partition = residual_sample = 0; partition < partitions; partition++) {
  93187. end += default_partition_samples;
  93188. abs_residual_partition_sum = 0;
  93189. for( ; residual_sample < end; residual_sample++)
  93190. abs_residual_partition_sum += abs(residual[residual_sample]); /* abs(INT_MIN) is undefined, but if the residual is INT_MIN we have bigger problems */
  93191. abs_residual_partition_sums[partition] = abs_residual_partition_sum;
  93192. }
  93193. }
  93194. }
  93195. {
  93196. unsigned from_partition = 0, to_partition = partitions;
  93197. int partition_order;
  93198. for(partition_order = (int)max_partition_order - 1; partition_order >= (int)min_partition_order; partition_order--) {
  93199. unsigned i;
  93200. partitions >>= 1;
  93201. for(i = 0; i < partitions; i++) {
  93202. abs_residual_partition_sums[to_partition++] =
  93203. abs_residual_partition_sums[from_partition ] +
  93204. abs_residual_partition_sums[from_partition+1];
  93205. from_partition += 2;
  93206. }
  93207. }
  93208. }
  93209. }
  93210. void precompute_partition_info_escapes_(
  93211. const FLAC__int32 residual[],
  93212. unsigned raw_bits_per_partition[],
  93213. unsigned residual_samples,
  93214. unsigned predictor_order,
  93215. unsigned min_partition_order,
  93216. unsigned max_partition_order
  93217. )
  93218. {
  93219. int partition_order;
  93220. unsigned from_partition, to_partition = 0;
  93221. const unsigned blocksize = residual_samples + predictor_order;
  93222. for(partition_order = (int)max_partition_order; partition_order >= 0; partition_order--) {
  93223. FLAC__int32 r;
  93224. FLAC__uint32 rmax;
  93225. unsigned partition, partition_sample, partition_samples, residual_sample;
  93226. const unsigned partitions = 1u << partition_order;
  93227. const unsigned default_partition_samples = blocksize >> partition_order;
  93228. FLAC__ASSERT(default_partition_samples > predictor_order);
  93229. for(partition = residual_sample = 0; partition < partitions; partition++) {
  93230. partition_samples = default_partition_samples;
  93231. if(partition == 0)
  93232. partition_samples -= predictor_order;
  93233. rmax = 0;
  93234. for(partition_sample = 0; partition_sample < partition_samples; partition_sample++) {
  93235. r = residual[residual_sample++];
  93236. if(r < 0)
  93237. rmax |= ~r;
  93238. else
  93239. rmax |= r;
  93240. }
  93241. raw_bits_per_partition[partition] = rmax? FLAC__bitmath_ilog2(rmax) + 2 : 1;
  93242. }
  93243. to_partition = partitions;
  93244. break; /*@@@ yuck, should remove the 'for' loop instead */
  93245. }
  93246. for(from_partition = 0, --partition_order; partition_order >= (int)min_partition_order; partition_order--) {
  93247. unsigned m;
  93248. unsigned i;
  93249. const unsigned partitions = 1u << partition_order;
  93250. for(i = 0; i < partitions; i++) {
  93251. m = raw_bits_per_partition[from_partition];
  93252. from_partition++;
  93253. raw_bits_per_partition[to_partition] = max(m, raw_bits_per_partition[from_partition]);
  93254. from_partition++;
  93255. to_partition++;
  93256. }
  93257. }
  93258. }
  93259. #ifdef EXACT_RICE_BITS_CALCULATION
  93260. static FLaC__INLINE unsigned count_rice_bits_in_partition_(
  93261. const unsigned rice_parameter,
  93262. const unsigned partition_samples,
  93263. const FLAC__int32 *residual
  93264. )
  93265. {
  93266. unsigned i, partition_bits =
  93267. 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 */
  93268. (1+rice_parameter) * partition_samples /* 1 for unary stop bit + rice_parameter for the binary portion */
  93269. ;
  93270. for(i = 0; i < partition_samples; i++)
  93271. partition_bits += ( (FLAC__uint32)((residual[i]<<1)^(residual[i]>>31)) >> rice_parameter );
  93272. return partition_bits;
  93273. }
  93274. #else
  93275. static FLaC__INLINE unsigned count_rice_bits_in_partition_(
  93276. const unsigned rice_parameter,
  93277. const unsigned partition_samples,
  93278. const FLAC__uint64 abs_residual_partition_sum
  93279. )
  93280. {
  93281. return
  93282. 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 */
  93283. (1+rice_parameter) * partition_samples + /* 1 for unary stop bit + rice_parameter for the binary portion */
  93284. (
  93285. rice_parameter?
  93286. (unsigned)(abs_residual_partition_sum >> (rice_parameter-1)) /* rice_parameter-1 because the real coder sign-folds instead of using a sign bit */
  93287. : (unsigned)(abs_residual_partition_sum << 1) /* can't shift by negative number, so reverse */
  93288. )
  93289. - (partition_samples >> 1)
  93290. ;
  93291. }
  93292. #endif
  93293. FLAC__bool set_partitioned_rice_(
  93294. #ifdef EXACT_RICE_BITS_CALCULATION
  93295. const FLAC__int32 residual[],
  93296. #endif
  93297. const FLAC__uint64 abs_residual_partition_sums[],
  93298. const unsigned raw_bits_per_partition[],
  93299. const unsigned residual_samples,
  93300. const unsigned predictor_order,
  93301. const unsigned suggested_rice_parameter,
  93302. const unsigned rice_parameter_limit,
  93303. const unsigned rice_parameter_search_dist,
  93304. const unsigned partition_order,
  93305. const FLAC__bool search_for_escapes,
  93306. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents,
  93307. unsigned *bits
  93308. )
  93309. {
  93310. unsigned rice_parameter, partition_bits;
  93311. unsigned best_partition_bits, best_rice_parameter = 0;
  93312. unsigned bits_ = FLAC__ENTROPY_CODING_METHOD_TYPE_LEN + FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN;
  93313. unsigned *parameters, *raw_bits;
  93314. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  93315. unsigned min_rice_parameter, max_rice_parameter;
  93316. #else
  93317. (void)rice_parameter_search_dist;
  93318. #endif
  93319. FLAC__ASSERT(suggested_rice_parameter < FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER);
  93320. FLAC__ASSERT(rice_parameter_limit <= FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER);
  93321. FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(partitioned_rice_contents, max(6, partition_order));
  93322. parameters = partitioned_rice_contents->parameters;
  93323. raw_bits = partitioned_rice_contents->raw_bits;
  93324. if(partition_order == 0) {
  93325. best_partition_bits = (unsigned)(-1);
  93326. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  93327. if(rice_parameter_search_dist) {
  93328. if(suggested_rice_parameter < rice_parameter_search_dist)
  93329. min_rice_parameter = 0;
  93330. else
  93331. min_rice_parameter = suggested_rice_parameter - rice_parameter_search_dist;
  93332. max_rice_parameter = suggested_rice_parameter + rice_parameter_search_dist;
  93333. if(max_rice_parameter >= rice_parameter_limit) {
  93334. #ifdef DEBUG_VERBOSE
  93335. fprintf(stderr, "clipping rice_parameter (%u -> %u) @5\n", max_rice_parameter, rice_parameter_limit - 1);
  93336. #endif
  93337. max_rice_parameter = rice_parameter_limit - 1;
  93338. }
  93339. }
  93340. else
  93341. min_rice_parameter = max_rice_parameter = suggested_rice_parameter;
  93342. for(rice_parameter = min_rice_parameter; rice_parameter <= max_rice_parameter; rice_parameter++) {
  93343. #else
  93344. rice_parameter = suggested_rice_parameter;
  93345. #endif
  93346. #ifdef EXACT_RICE_BITS_CALCULATION
  93347. partition_bits = count_rice_bits_in_partition_(rice_parameter, residual_samples, residual);
  93348. #else
  93349. partition_bits = count_rice_bits_in_partition_(rice_parameter, residual_samples, abs_residual_partition_sums[0]);
  93350. #endif
  93351. if(partition_bits < best_partition_bits) {
  93352. best_rice_parameter = rice_parameter;
  93353. best_partition_bits = partition_bits;
  93354. }
  93355. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  93356. }
  93357. #endif
  93358. if(search_for_escapes) {
  93359. 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;
  93360. if(partition_bits <= best_partition_bits) {
  93361. raw_bits[0] = raw_bits_per_partition[0];
  93362. best_rice_parameter = 0; /* will be converted to appropriate escape parameter later */
  93363. best_partition_bits = partition_bits;
  93364. }
  93365. else
  93366. raw_bits[0] = 0;
  93367. }
  93368. parameters[0] = best_rice_parameter;
  93369. bits_ += best_partition_bits;
  93370. }
  93371. else {
  93372. unsigned partition, residual_sample;
  93373. unsigned partition_samples;
  93374. FLAC__uint64 mean, k;
  93375. const unsigned partitions = 1u << partition_order;
  93376. for(partition = residual_sample = 0; partition < partitions; partition++) {
  93377. partition_samples = (residual_samples+predictor_order) >> partition_order;
  93378. if(partition == 0) {
  93379. if(partition_samples <= predictor_order)
  93380. return false;
  93381. else
  93382. partition_samples -= predictor_order;
  93383. }
  93384. mean = abs_residual_partition_sums[partition];
  93385. for(rice_parameter = 0, k = partition_samples; k < mean; rice_parameter++, k <<= 1)
  93386. ;
  93387. if(rice_parameter >= rice_parameter_limit) {
  93388. #ifdef DEBUG_VERBOSE
  93389. fprintf(stderr, "clipping rice_parameter (%u -> %u) @6\n", rice_parameter, rice_parameter_limit - 1);
  93390. #endif
  93391. rice_parameter = rice_parameter_limit - 1;
  93392. }
  93393. best_partition_bits = (unsigned)(-1);
  93394. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  93395. if(rice_parameter_search_dist) {
  93396. if(rice_parameter < rice_parameter_search_dist)
  93397. min_rice_parameter = 0;
  93398. else
  93399. min_rice_parameter = rice_parameter - rice_parameter_search_dist;
  93400. max_rice_parameter = rice_parameter + rice_parameter_search_dist;
  93401. if(max_rice_parameter >= rice_parameter_limit) {
  93402. #ifdef DEBUG_VERBOSE
  93403. fprintf(stderr, "clipping rice_parameter (%u -> %u) @7\n", max_rice_parameter, rice_parameter_limit - 1);
  93404. #endif
  93405. max_rice_parameter = rice_parameter_limit - 1;
  93406. }
  93407. }
  93408. else
  93409. min_rice_parameter = max_rice_parameter = rice_parameter;
  93410. for(rice_parameter = min_rice_parameter; rice_parameter <= max_rice_parameter; rice_parameter++) {
  93411. #endif
  93412. #ifdef EXACT_RICE_BITS_CALCULATION
  93413. partition_bits = count_rice_bits_in_partition_(rice_parameter, partition_samples, residual+residual_sample);
  93414. #else
  93415. partition_bits = count_rice_bits_in_partition_(rice_parameter, partition_samples, abs_residual_partition_sums[partition]);
  93416. #endif
  93417. if(partition_bits < best_partition_bits) {
  93418. best_rice_parameter = rice_parameter;
  93419. best_partition_bits = partition_bits;
  93420. }
  93421. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  93422. }
  93423. #endif
  93424. if(search_for_escapes) {
  93425. 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;
  93426. if(partition_bits <= best_partition_bits) {
  93427. raw_bits[partition] = raw_bits_per_partition[partition];
  93428. best_rice_parameter = 0; /* will be converted to appropriate escape parameter later */
  93429. best_partition_bits = partition_bits;
  93430. }
  93431. else
  93432. raw_bits[partition] = 0;
  93433. }
  93434. parameters[partition] = best_rice_parameter;
  93435. bits_ += best_partition_bits;
  93436. residual_sample += partition_samples;
  93437. }
  93438. }
  93439. *bits = bits_;
  93440. return true;
  93441. }
  93442. unsigned get_wasted_bits_(FLAC__int32 signal[], unsigned samples)
  93443. {
  93444. unsigned i, shift;
  93445. FLAC__int32 x = 0;
  93446. for(i = 0; i < samples && !(x&1); i++)
  93447. x |= signal[i];
  93448. if(x == 0) {
  93449. shift = 0;
  93450. }
  93451. else {
  93452. for(shift = 0; !(x&1); shift++)
  93453. x >>= 1;
  93454. }
  93455. if(shift > 0) {
  93456. for(i = 0; i < samples; i++)
  93457. signal[i] >>= shift;
  93458. }
  93459. return shift;
  93460. }
  93461. void append_to_verify_fifo_(verify_input_fifo *fifo, const FLAC__int32 * const input[], unsigned input_offset, unsigned channels, unsigned wide_samples)
  93462. {
  93463. unsigned channel;
  93464. for(channel = 0; channel < channels; channel++)
  93465. memcpy(&fifo->data[channel][fifo->tail], &input[channel][input_offset], sizeof(FLAC__int32) * wide_samples);
  93466. fifo->tail += wide_samples;
  93467. FLAC__ASSERT(fifo->tail <= fifo->size);
  93468. }
  93469. void append_to_verify_fifo_interleaved_(verify_input_fifo *fifo, const FLAC__int32 input[], unsigned input_offset, unsigned channels, unsigned wide_samples)
  93470. {
  93471. unsigned channel;
  93472. unsigned sample, wide_sample;
  93473. unsigned tail = fifo->tail;
  93474. sample = input_offset * channels;
  93475. for(wide_sample = 0; wide_sample < wide_samples; wide_sample++) {
  93476. for(channel = 0; channel < channels; channel++)
  93477. fifo->data[channel][tail] = input[sample++];
  93478. tail++;
  93479. }
  93480. fifo->tail = tail;
  93481. FLAC__ASSERT(fifo->tail <= fifo->size);
  93482. }
  93483. FLAC__StreamDecoderReadStatus verify_read_callback_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  93484. {
  93485. FLAC__StreamEncoder *encoder = (FLAC__StreamEncoder*)client_data;
  93486. const size_t encoded_bytes = encoder->private_->verify.output.bytes;
  93487. (void)decoder;
  93488. if(encoder->private_->verify.needs_magic_hack) {
  93489. FLAC__ASSERT(*bytes >= FLAC__STREAM_SYNC_LENGTH);
  93490. *bytes = FLAC__STREAM_SYNC_LENGTH;
  93491. memcpy(buffer, FLAC__STREAM_SYNC_STRING, *bytes);
  93492. encoder->private_->verify.needs_magic_hack = false;
  93493. }
  93494. else {
  93495. if(encoded_bytes == 0) {
  93496. FLAC__ASSERT(0);
  93497. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  93498. }
  93499. else if(encoded_bytes < *bytes)
  93500. *bytes = encoded_bytes;
  93501. memcpy(buffer, encoder->private_->verify.output.data, *bytes);
  93502. encoder->private_->verify.output.data += *bytes;
  93503. encoder->private_->verify.output.bytes -= *bytes;
  93504. }
  93505. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  93506. }
  93507. FLAC__StreamDecoderWriteStatus verify_write_callback_(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data)
  93508. {
  93509. FLAC__StreamEncoder *encoder = (FLAC__StreamEncoder *)client_data;
  93510. unsigned channel;
  93511. const unsigned channels = frame->header.channels;
  93512. const unsigned blocksize = frame->header.blocksize;
  93513. const unsigned bytes_per_block = sizeof(FLAC__int32) * blocksize;
  93514. (void)decoder;
  93515. for(channel = 0; channel < channels; channel++) {
  93516. if(0 != memcmp(buffer[channel], encoder->private_->verify.input_fifo.data[channel], bytes_per_block)) {
  93517. unsigned i, sample = 0;
  93518. FLAC__int32 expect = 0, got = 0;
  93519. for(i = 0; i < blocksize; i++) {
  93520. if(buffer[channel][i] != encoder->private_->verify.input_fifo.data[channel][i]) {
  93521. sample = i;
  93522. expect = (FLAC__int32)encoder->private_->verify.input_fifo.data[channel][i];
  93523. got = (FLAC__int32)buffer[channel][i];
  93524. break;
  93525. }
  93526. }
  93527. FLAC__ASSERT(i < blocksize);
  93528. FLAC__ASSERT(frame->header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  93529. encoder->private_->verify.error_stats.absolute_sample = frame->header.number.sample_number + sample;
  93530. encoder->private_->verify.error_stats.frame_number = (unsigned)(frame->header.number.sample_number / blocksize);
  93531. encoder->private_->verify.error_stats.channel = channel;
  93532. encoder->private_->verify.error_stats.sample = sample;
  93533. encoder->private_->verify.error_stats.expected = expect;
  93534. encoder->private_->verify.error_stats.got = got;
  93535. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA;
  93536. return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
  93537. }
  93538. }
  93539. encoder->private_->verify.input_fifo.tail -= blocksize;
  93540. FLAC__ASSERT(encoder->private_->verify.input_fifo.tail <= OVERREAD_);
  93541. for(channel = 0; channel < channels; channel++)
  93542. 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]));
  93543. return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
  93544. }
  93545. void verify_metadata_callback_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data)
  93546. {
  93547. (void)decoder, (void)metadata, (void)client_data;
  93548. }
  93549. void verify_error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data)
  93550. {
  93551. FLAC__StreamEncoder *encoder = (FLAC__StreamEncoder*)client_data;
  93552. (void)decoder, (void)status;
  93553. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
  93554. }
  93555. FLAC__StreamEncoderReadStatus file_read_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  93556. {
  93557. (void)client_data;
  93558. *bytes = fread(buffer, 1, *bytes, encoder->private_->file);
  93559. if (*bytes == 0) {
  93560. if (feof(encoder->private_->file))
  93561. return FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM;
  93562. else if (ferror(encoder->private_->file))
  93563. return FLAC__STREAM_ENCODER_READ_STATUS_ABORT;
  93564. }
  93565. return FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE;
  93566. }
  93567. FLAC__StreamEncoderSeekStatus file_seek_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data)
  93568. {
  93569. (void)client_data;
  93570. if(fseeko(encoder->private_->file, (off_t)absolute_byte_offset, SEEK_SET) < 0)
  93571. return FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR;
  93572. else
  93573. return FLAC__STREAM_ENCODER_SEEK_STATUS_OK;
  93574. }
  93575. FLAC__StreamEncoderTellStatus file_tell_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data)
  93576. {
  93577. off_t offset;
  93578. (void)client_data;
  93579. offset = ftello(encoder->private_->file);
  93580. if(offset < 0) {
  93581. return FLAC__STREAM_ENCODER_TELL_STATUS_ERROR;
  93582. }
  93583. else {
  93584. *absolute_byte_offset = (FLAC__uint64)offset;
  93585. return FLAC__STREAM_ENCODER_TELL_STATUS_OK;
  93586. }
  93587. }
  93588. #ifdef FLAC__VALGRIND_TESTING
  93589. static size_t local__fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream)
  93590. {
  93591. size_t ret = fwrite(ptr, size, nmemb, stream);
  93592. if(!ferror(stream))
  93593. fflush(stream);
  93594. return ret;
  93595. }
  93596. #else
  93597. #define local__fwrite fwrite
  93598. #endif
  93599. FLAC__StreamEncoderWriteStatus file_write_callback_(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, unsigned current_frame, void *client_data)
  93600. {
  93601. (void)client_data, (void)current_frame;
  93602. if(local__fwrite(buffer, sizeof(FLAC__byte), bytes, encoder->private_->file) == bytes) {
  93603. FLAC__bool call_it = 0 != encoder->private_->progress_callback && (
  93604. #if FLAC__HAS_OGG
  93605. encoder->private_->is_ogg? true :
  93606. #endif
  93607. samples > 0
  93608. );
  93609. if(call_it) {
  93610. 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);
  93611. }
  93612. return FLAC__STREAM_ENCODER_WRITE_STATUS_OK;
  93613. }
  93614. else
  93615. return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
  93616. }
  93617. FILE *get_binary_stdout_(void)
  93618. {
  93619. #if defined _MSC_VER || defined __MINGW32__
  93620. _setmode(_fileno(stdout), _O_BINARY);
  93621. #elif defined __CYGWIN__
  93622. setmode(_fileno(stdout), _O_BINARY);
  93623. #elif defined __EMX__
  93624. setmode(fileno(stdout), O_BINARY);
  93625. #endif
  93626. return stdout;
  93627. }
  93628. #endif
  93629. /*** End of inlined file: stream_encoder.c ***/
  93630. /*** Start of inlined file: stream_encoder_framing.c ***/
  93631. /*** Start of inlined file: juce_FlacHeader.h ***/
  93632. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  93633. // tasks..
  93634. #define VERSION "1.2.1"
  93635. #define FLAC__NO_DLL 1
  93636. #if JUCE_MSVC
  93637. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  93638. #endif
  93639. #if JUCE_MAC
  93640. #define FLAC__SYS_DARWIN 1
  93641. #endif
  93642. /*** End of inlined file: juce_FlacHeader.h ***/
  93643. #if JUCE_USE_FLAC
  93644. #if HAVE_CONFIG_H
  93645. # include <config.h>
  93646. #endif
  93647. #include <stdio.h>
  93648. #include <string.h> /* for strlen() */
  93649. #ifdef max
  93650. #undef max
  93651. #endif
  93652. #define max(x,y) ((x)>(y)?(x):(y))
  93653. static FLAC__bool add_entropy_coding_method_(FLAC__BitWriter *bw, const FLAC__EntropyCodingMethod *method);
  93654. 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);
  93655. FLAC__bool FLAC__add_metadata_block(const FLAC__StreamMetadata *metadata, FLAC__BitWriter *bw)
  93656. {
  93657. unsigned i, j;
  93658. const unsigned vendor_string_length = (unsigned)strlen(FLAC__VENDOR_STRING);
  93659. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->is_last, FLAC__STREAM_METADATA_IS_LAST_LEN))
  93660. return false;
  93661. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->type, FLAC__STREAM_METADATA_TYPE_LEN))
  93662. return false;
  93663. i = metadata->length;
  93664. if(metadata->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
  93665. FLAC__ASSERT(metadata->data.vorbis_comment.vendor_string.length == 0 || 0 != metadata->data.vorbis_comment.vendor_string.entry);
  93666. i -= metadata->data.vorbis_comment.vendor_string.length;
  93667. i += vendor_string_length;
  93668. }
  93669. FLAC__ASSERT(i < (1u << FLAC__STREAM_METADATA_LENGTH_LEN));
  93670. if(!FLAC__bitwriter_write_raw_uint32(bw, i, FLAC__STREAM_METADATA_LENGTH_LEN))
  93671. return false;
  93672. switch(metadata->type) {
  93673. case FLAC__METADATA_TYPE_STREAMINFO:
  93674. FLAC__ASSERT(metadata->data.stream_info.min_blocksize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN));
  93675. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.min_blocksize, FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN))
  93676. return false;
  93677. FLAC__ASSERT(metadata->data.stream_info.max_blocksize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN));
  93678. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.max_blocksize, FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN))
  93679. return false;
  93680. FLAC__ASSERT(metadata->data.stream_info.min_framesize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN));
  93681. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.min_framesize, FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN))
  93682. return false;
  93683. FLAC__ASSERT(metadata->data.stream_info.max_framesize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN));
  93684. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.max_framesize, FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN))
  93685. return false;
  93686. FLAC__ASSERT(FLAC__format_sample_rate_is_valid(metadata->data.stream_info.sample_rate));
  93687. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.sample_rate, FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN))
  93688. return false;
  93689. FLAC__ASSERT(metadata->data.stream_info.channels > 0);
  93690. FLAC__ASSERT(metadata->data.stream_info.channels <= (1u << FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN));
  93691. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.channels-1, FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN))
  93692. return false;
  93693. FLAC__ASSERT(metadata->data.stream_info.bits_per_sample > 0);
  93694. FLAC__ASSERT(metadata->data.stream_info.bits_per_sample <= (1u << FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN));
  93695. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.bits_per_sample-1, FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN))
  93696. return false;
  93697. if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.stream_info.total_samples, FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN))
  93698. return false;
  93699. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.stream_info.md5sum, 16))
  93700. return false;
  93701. break;
  93702. case FLAC__METADATA_TYPE_PADDING:
  93703. if(!FLAC__bitwriter_write_zeroes(bw, metadata->length * 8))
  93704. return false;
  93705. break;
  93706. case FLAC__METADATA_TYPE_APPLICATION:
  93707. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.application.id, FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8))
  93708. return false;
  93709. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.application.data, metadata->length - (FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8)))
  93710. return false;
  93711. break;
  93712. case FLAC__METADATA_TYPE_SEEKTABLE:
  93713. for(i = 0; i < metadata->data.seek_table.num_points; i++) {
  93714. if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.seek_table.points[i].sample_number, FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN))
  93715. return false;
  93716. if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.seek_table.points[i].stream_offset, FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN))
  93717. return false;
  93718. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.seek_table.points[i].frame_samples, FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN))
  93719. return false;
  93720. }
  93721. break;
  93722. case FLAC__METADATA_TYPE_VORBIS_COMMENT:
  93723. if(!FLAC__bitwriter_write_raw_uint32_little_endian(bw, vendor_string_length))
  93724. return false;
  93725. if(!FLAC__bitwriter_write_byte_block(bw, (const FLAC__byte*)FLAC__VENDOR_STRING, vendor_string_length))
  93726. return false;
  93727. if(!FLAC__bitwriter_write_raw_uint32_little_endian(bw, metadata->data.vorbis_comment.num_comments))
  93728. return false;
  93729. for(i = 0; i < metadata->data.vorbis_comment.num_comments; i++) {
  93730. if(!FLAC__bitwriter_write_raw_uint32_little_endian(bw, metadata->data.vorbis_comment.comments[i].length))
  93731. return false;
  93732. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.vorbis_comment.comments[i].entry, metadata->data.vorbis_comment.comments[i].length))
  93733. return false;
  93734. }
  93735. break;
  93736. case FLAC__METADATA_TYPE_CUESHEET:
  93737. FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN % 8 == 0);
  93738. 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))
  93739. return false;
  93740. if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.cue_sheet.lead_in, FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN))
  93741. return false;
  93742. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.cue_sheet.is_cd? 1 : 0, FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN))
  93743. return false;
  93744. if(!FLAC__bitwriter_write_zeroes(bw, FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN))
  93745. return false;
  93746. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.cue_sheet.num_tracks, FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN))
  93747. return false;
  93748. for(i = 0; i < metadata->data.cue_sheet.num_tracks; i++) {
  93749. const FLAC__StreamMetadata_CueSheet_Track *track = metadata->data.cue_sheet.tracks + i;
  93750. if(!FLAC__bitwriter_write_raw_uint64(bw, track->offset, FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN))
  93751. return false;
  93752. if(!FLAC__bitwriter_write_raw_uint32(bw, track->number, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN))
  93753. return false;
  93754. FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN % 8 == 0);
  93755. if(!FLAC__bitwriter_write_byte_block(bw, (const FLAC__byte*)track->isrc, FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN/8))
  93756. return false;
  93757. if(!FLAC__bitwriter_write_raw_uint32(bw, track->type, FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN))
  93758. return false;
  93759. if(!FLAC__bitwriter_write_raw_uint32(bw, track->pre_emphasis, FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN))
  93760. return false;
  93761. if(!FLAC__bitwriter_write_zeroes(bw, FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN))
  93762. return false;
  93763. if(!FLAC__bitwriter_write_raw_uint32(bw, track->num_indices, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN))
  93764. return false;
  93765. for(j = 0; j < track->num_indices; j++) {
  93766. const FLAC__StreamMetadata_CueSheet_Index *index = track->indices + j;
  93767. if(!FLAC__bitwriter_write_raw_uint64(bw, index->offset, FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN))
  93768. return false;
  93769. if(!FLAC__bitwriter_write_raw_uint32(bw, index->number, FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN))
  93770. return false;
  93771. if(!FLAC__bitwriter_write_zeroes(bw, FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN))
  93772. return false;
  93773. }
  93774. }
  93775. break;
  93776. case FLAC__METADATA_TYPE_PICTURE:
  93777. {
  93778. size_t len;
  93779. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.type, FLAC__STREAM_METADATA_PICTURE_TYPE_LEN))
  93780. return false;
  93781. len = strlen(metadata->data.picture.mime_type);
  93782. if(!FLAC__bitwriter_write_raw_uint32(bw, len, FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN))
  93783. return false;
  93784. if(!FLAC__bitwriter_write_byte_block(bw, (const FLAC__byte*)metadata->data.picture.mime_type, len))
  93785. return false;
  93786. len = strlen((const char *)metadata->data.picture.description);
  93787. if(!FLAC__bitwriter_write_raw_uint32(bw, len, FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN))
  93788. return false;
  93789. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.picture.description, len))
  93790. return false;
  93791. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.width, FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN))
  93792. return false;
  93793. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.height, FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN))
  93794. return false;
  93795. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.depth, FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN))
  93796. return false;
  93797. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.colors, FLAC__STREAM_METADATA_PICTURE_COLORS_LEN))
  93798. return false;
  93799. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.data_length, FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN))
  93800. return false;
  93801. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.picture.data, metadata->data.picture.data_length))
  93802. return false;
  93803. }
  93804. break;
  93805. default:
  93806. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.unknown.data, metadata->length))
  93807. return false;
  93808. break;
  93809. }
  93810. FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(bw));
  93811. return true;
  93812. }
  93813. FLAC__bool FLAC__frame_add_header(const FLAC__FrameHeader *header, FLAC__BitWriter *bw)
  93814. {
  93815. unsigned u, blocksize_hint, sample_rate_hint;
  93816. FLAC__byte crc;
  93817. FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(bw));
  93818. if(!FLAC__bitwriter_write_raw_uint32(bw, FLAC__FRAME_HEADER_SYNC, FLAC__FRAME_HEADER_SYNC_LEN))
  93819. return false;
  93820. if(!FLAC__bitwriter_write_raw_uint32(bw, 0, FLAC__FRAME_HEADER_RESERVED_LEN))
  93821. return false;
  93822. if(!FLAC__bitwriter_write_raw_uint32(bw, (header->number_type == FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER)? 0 : 1, FLAC__FRAME_HEADER_BLOCKING_STRATEGY_LEN))
  93823. return false;
  93824. FLAC__ASSERT(header->blocksize > 0 && header->blocksize <= FLAC__MAX_BLOCK_SIZE);
  93825. FLAC__ASSERT(FLAC__MAX_BLOCK_SIZE <= 65535u);
  93826. blocksize_hint = 0;
  93827. switch(header->blocksize) {
  93828. case 192: u = 1; break;
  93829. case 576: u = 2; break;
  93830. case 1152: u = 3; break;
  93831. case 2304: u = 4; break;
  93832. case 4608: u = 5; break;
  93833. case 256: u = 8; break;
  93834. case 512: u = 9; break;
  93835. case 1024: u = 10; break;
  93836. case 2048: u = 11; break;
  93837. case 4096: u = 12; break;
  93838. case 8192: u = 13; break;
  93839. case 16384: u = 14; break;
  93840. case 32768: u = 15; break;
  93841. default:
  93842. if(header->blocksize <= 0x100)
  93843. blocksize_hint = u = 6;
  93844. else
  93845. blocksize_hint = u = 7;
  93846. break;
  93847. }
  93848. if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_BLOCK_SIZE_LEN))
  93849. return false;
  93850. FLAC__ASSERT(FLAC__format_sample_rate_is_valid(header->sample_rate));
  93851. sample_rate_hint = 0;
  93852. switch(header->sample_rate) {
  93853. case 88200: u = 1; break;
  93854. case 176400: u = 2; break;
  93855. case 192000: u = 3; break;
  93856. case 8000: u = 4; break;
  93857. case 16000: u = 5; break;
  93858. case 22050: u = 6; break;
  93859. case 24000: u = 7; break;
  93860. case 32000: u = 8; break;
  93861. case 44100: u = 9; break;
  93862. case 48000: u = 10; break;
  93863. case 96000: u = 11; break;
  93864. default:
  93865. if(header->sample_rate <= 255000 && header->sample_rate % 1000 == 0)
  93866. sample_rate_hint = u = 12;
  93867. else if(header->sample_rate % 10 == 0)
  93868. sample_rate_hint = u = 14;
  93869. else if(header->sample_rate <= 0xffff)
  93870. sample_rate_hint = u = 13;
  93871. else
  93872. u = 0;
  93873. break;
  93874. }
  93875. if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_SAMPLE_RATE_LEN))
  93876. return false;
  93877. FLAC__ASSERT(header->channels > 0 && header->channels <= (1u << FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN) && header->channels <= FLAC__MAX_CHANNELS);
  93878. switch(header->channel_assignment) {
  93879. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  93880. u = header->channels - 1;
  93881. break;
  93882. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  93883. FLAC__ASSERT(header->channels == 2);
  93884. u = 8;
  93885. break;
  93886. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  93887. FLAC__ASSERT(header->channels == 2);
  93888. u = 9;
  93889. break;
  93890. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  93891. FLAC__ASSERT(header->channels == 2);
  93892. u = 10;
  93893. break;
  93894. default:
  93895. FLAC__ASSERT(0);
  93896. }
  93897. if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_CHANNEL_ASSIGNMENT_LEN))
  93898. return false;
  93899. FLAC__ASSERT(header->bits_per_sample > 0 && header->bits_per_sample <= (1u << FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN));
  93900. switch(header->bits_per_sample) {
  93901. case 8 : u = 1; break;
  93902. case 12: u = 2; break;
  93903. case 16: u = 4; break;
  93904. case 20: u = 5; break;
  93905. case 24: u = 6; break;
  93906. default: u = 0; break;
  93907. }
  93908. if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_BITS_PER_SAMPLE_LEN))
  93909. return false;
  93910. if(!FLAC__bitwriter_write_raw_uint32(bw, 0, FLAC__FRAME_HEADER_ZERO_PAD_LEN))
  93911. return false;
  93912. if(header->number_type == FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER) {
  93913. if(!FLAC__bitwriter_write_utf8_uint32(bw, header->number.frame_number))
  93914. return false;
  93915. }
  93916. else {
  93917. if(!FLAC__bitwriter_write_utf8_uint64(bw, header->number.sample_number))
  93918. return false;
  93919. }
  93920. if(blocksize_hint)
  93921. if(!FLAC__bitwriter_write_raw_uint32(bw, header->blocksize-1, (blocksize_hint==6)? 8:16))
  93922. return false;
  93923. switch(sample_rate_hint) {
  93924. case 12:
  93925. if(!FLAC__bitwriter_write_raw_uint32(bw, header->sample_rate / 1000, 8))
  93926. return false;
  93927. break;
  93928. case 13:
  93929. if(!FLAC__bitwriter_write_raw_uint32(bw, header->sample_rate, 16))
  93930. return false;
  93931. break;
  93932. case 14:
  93933. if(!FLAC__bitwriter_write_raw_uint32(bw, header->sample_rate / 10, 16))
  93934. return false;
  93935. break;
  93936. }
  93937. if(!FLAC__bitwriter_get_write_crc8(bw, &crc))
  93938. return false;
  93939. if(!FLAC__bitwriter_write_raw_uint32(bw, crc, FLAC__FRAME_HEADER_CRC_LEN))
  93940. return false;
  93941. return true;
  93942. }
  93943. FLAC__bool FLAC__subframe_add_constant(const FLAC__Subframe_Constant *subframe, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
  93944. {
  93945. FLAC__bool ok;
  93946. ok =
  93947. 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) &&
  93948. (wasted_bits? FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1) : true) &&
  93949. FLAC__bitwriter_write_raw_int32(bw, subframe->value, subframe_bps)
  93950. ;
  93951. return ok;
  93952. }
  93953. FLAC__bool FLAC__subframe_add_fixed(const FLAC__Subframe_Fixed *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
  93954. {
  93955. unsigned i;
  93956. 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))
  93957. return false;
  93958. if(wasted_bits)
  93959. if(!FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1))
  93960. return false;
  93961. for(i = 0; i < subframe->order; i++)
  93962. if(!FLAC__bitwriter_write_raw_int32(bw, subframe->warmup[i], subframe_bps))
  93963. return false;
  93964. if(!add_entropy_coding_method_(bw, &subframe->entropy_coding_method))
  93965. return false;
  93966. switch(subframe->entropy_coding_method.type) {
  93967. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  93968. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  93969. if(!add_residual_partitioned_rice_(
  93970. bw,
  93971. subframe->residual,
  93972. residual_samples,
  93973. subframe->order,
  93974. subframe->entropy_coding_method.data.partitioned_rice.contents->parameters,
  93975. subframe->entropy_coding_method.data.partitioned_rice.contents->raw_bits,
  93976. subframe->entropy_coding_method.data.partitioned_rice.order,
  93977. subframe->entropy_coding_method.type == FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2
  93978. ))
  93979. return false;
  93980. break;
  93981. default:
  93982. FLAC__ASSERT(0);
  93983. }
  93984. return true;
  93985. }
  93986. FLAC__bool FLAC__subframe_add_lpc(const FLAC__Subframe_LPC *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
  93987. {
  93988. unsigned i;
  93989. 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))
  93990. return false;
  93991. if(wasted_bits)
  93992. if(!FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1))
  93993. return false;
  93994. for(i = 0; i < subframe->order; i++)
  93995. if(!FLAC__bitwriter_write_raw_int32(bw, subframe->warmup[i], subframe_bps))
  93996. return false;
  93997. if(!FLAC__bitwriter_write_raw_uint32(bw, subframe->qlp_coeff_precision-1, FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN))
  93998. return false;
  93999. if(!FLAC__bitwriter_write_raw_int32(bw, subframe->quantization_level, FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN))
  94000. return false;
  94001. for(i = 0; i < subframe->order; i++)
  94002. if(!FLAC__bitwriter_write_raw_int32(bw, subframe->qlp_coeff[i], subframe->qlp_coeff_precision))
  94003. return false;
  94004. if(!add_entropy_coding_method_(bw, &subframe->entropy_coding_method))
  94005. return false;
  94006. switch(subframe->entropy_coding_method.type) {
  94007. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  94008. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  94009. if(!add_residual_partitioned_rice_(
  94010. bw,
  94011. subframe->residual,
  94012. residual_samples,
  94013. subframe->order,
  94014. subframe->entropy_coding_method.data.partitioned_rice.contents->parameters,
  94015. subframe->entropy_coding_method.data.partitioned_rice.contents->raw_bits,
  94016. subframe->entropy_coding_method.data.partitioned_rice.order,
  94017. subframe->entropy_coding_method.type == FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2
  94018. ))
  94019. return false;
  94020. break;
  94021. default:
  94022. FLAC__ASSERT(0);
  94023. }
  94024. return true;
  94025. }
  94026. FLAC__bool FLAC__subframe_add_verbatim(const FLAC__Subframe_Verbatim *subframe, unsigned samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
  94027. {
  94028. unsigned i;
  94029. const FLAC__int32 *signal = subframe->data;
  94030. 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))
  94031. return false;
  94032. if(wasted_bits)
  94033. if(!FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1))
  94034. return false;
  94035. for(i = 0; i < samples; i++)
  94036. if(!FLAC__bitwriter_write_raw_int32(bw, signal[i], subframe_bps))
  94037. return false;
  94038. return true;
  94039. }
  94040. FLAC__bool add_entropy_coding_method_(FLAC__BitWriter *bw, const FLAC__EntropyCodingMethod *method)
  94041. {
  94042. if(!FLAC__bitwriter_write_raw_uint32(bw, method->type, FLAC__ENTROPY_CODING_METHOD_TYPE_LEN))
  94043. return false;
  94044. switch(method->type) {
  94045. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  94046. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  94047. if(!FLAC__bitwriter_write_raw_uint32(bw, method->data.partitioned_rice.order, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
  94048. return false;
  94049. break;
  94050. default:
  94051. FLAC__ASSERT(0);
  94052. }
  94053. return true;
  94054. }
  94055. 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)
  94056. {
  94057. const unsigned plen = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN;
  94058. const unsigned pesc = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER;
  94059. if(partition_order == 0) {
  94060. unsigned i;
  94061. if(raw_bits[0] == 0) {
  94062. if(!FLAC__bitwriter_write_raw_uint32(bw, rice_parameters[0], plen))
  94063. return false;
  94064. if(!FLAC__bitwriter_write_rice_signed_block(bw, residual, residual_samples, rice_parameters[0]))
  94065. return false;
  94066. }
  94067. else {
  94068. FLAC__ASSERT(rice_parameters[0] == 0);
  94069. if(!FLAC__bitwriter_write_raw_uint32(bw, pesc, plen))
  94070. return false;
  94071. if(!FLAC__bitwriter_write_raw_uint32(bw, raw_bits[0], FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN))
  94072. return false;
  94073. for(i = 0; i < residual_samples; i++) {
  94074. if(!FLAC__bitwriter_write_raw_int32(bw, residual[i], raw_bits[0]))
  94075. return false;
  94076. }
  94077. }
  94078. return true;
  94079. }
  94080. else {
  94081. unsigned i, j, k = 0, k_last = 0;
  94082. unsigned partition_samples;
  94083. const unsigned default_partition_samples = (residual_samples+predictor_order) >> partition_order;
  94084. for(i = 0; i < (1u<<partition_order); i++) {
  94085. partition_samples = default_partition_samples;
  94086. if(i == 0)
  94087. partition_samples -= predictor_order;
  94088. k += partition_samples;
  94089. if(raw_bits[i] == 0) {
  94090. if(!FLAC__bitwriter_write_raw_uint32(bw, rice_parameters[i], plen))
  94091. return false;
  94092. if(!FLAC__bitwriter_write_rice_signed_block(bw, residual+k_last, k-k_last, rice_parameters[i]))
  94093. return false;
  94094. }
  94095. else {
  94096. if(!FLAC__bitwriter_write_raw_uint32(bw, pesc, plen))
  94097. return false;
  94098. if(!FLAC__bitwriter_write_raw_uint32(bw, raw_bits[i], FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN))
  94099. return false;
  94100. for(j = k_last; j < k; j++) {
  94101. if(!FLAC__bitwriter_write_raw_int32(bw, residual[j], raw_bits[i]))
  94102. return false;
  94103. }
  94104. }
  94105. k_last = k;
  94106. }
  94107. return true;
  94108. }
  94109. }
  94110. #endif
  94111. /*** End of inlined file: stream_encoder_framing.c ***/
  94112. /*** Start of inlined file: window_flac.c ***/
  94113. /*** Start of inlined file: juce_FlacHeader.h ***/
  94114. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  94115. // tasks..
  94116. #define VERSION "1.2.1"
  94117. #define FLAC__NO_DLL 1
  94118. #if JUCE_MSVC
  94119. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  94120. #endif
  94121. #if JUCE_MAC
  94122. #define FLAC__SYS_DARWIN 1
  94123. #endif
  94124. /*** End of inlined file: juce_FlacHeader.h ***/
  94125. #if JUCE_USE_FLAC
  94126. #if HAVE_CONFIG_H
  94127. # include <config.h>
  94128. #endif
  94129. #include <math.h>
  94130. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  94131. #ifndef M_PI
  94132. #define M_PI 3.14159265358979323846
  94133. #endif
  94134. void FLAC__window_bartlett(FLAC__real *window, const FLAC__int32 L)
  94135. {
  94136. const FLAC__int32 N = L - 1;
  94137. FLAC__int32 n;
  94138. if (L & 1) {
  94139. for (n = 0; n <= N/2; n++)
  94140. window[n] = 2.0f * n / (float)N;
  94141. for (; n <= N; n++)
  94142. window[n] = 2.0f - 2.0f * n / (float)N;
  94143. }
  94144. else {
  94145. for (n = 0; n <= L/2-1; n++)
  94146. window[n] = 2.0f * n / (float)N;
  94147. for (; n <= N; n++)
  94148. window[n] = 2.0f - 2.0f * (N-n) / (float)N;
  94149. }
  94150. }
  94151. void FLAC__window_bartlett_hann(FLAC__real *window, const FLAC__int32 L)
  94152. {
  94153. const FLAC__int32 N = L - 1;
  94154. FLAC__int32 n;
  94155. for (n = 0; n < L; n++)
  94156. 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)));
  94157. }
  94158. void FLAC__window_blackman(FLAC__real *window, const FLAC__int32 L)
  94159. {
  94160. const FLAC__int32 N = L - 1;
  94161. FLAC__int32 n;
  94162. for (n = 0; n < L; n++)
  94163. window[n] = (FLAC__real)(0.42f - 0.5f * cos(2.0f * M_PI * n / N) + 0.08f * cos(4.0f * M_PI * n / N));
  94164. }
  94165. void FLAC__window_blackman_harris_4term_92db_sidelobe(FLAC__real *window, const FLAC__int32 L)
  94166. {
  94167. const FLAC__int32 N = L - 1;
  94168. FLAC__int32 n;
  94169. for (n = 0; n <= N; n++)
  94170. 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));
  94171. }
  94172. void FLAC__window_connes(FLAC__real *window, const FLAC__int32 L)
  94173. {
  94174. const FLAC__int32 N = L - 1;
  94175. const double N2 = (double)N / 2.;
  94176. FLAC__int32 n;
  94177. for (n = 0; n <= N; n++) {
  94178. double k = ((double)n - N2) / N2;
  94179. k = 1.0f - k * k;
  94180. window[n] = (FLAC__real)(k * k);
  94181. }
  94182. }
  94183. void FLAC__window_flattop(FLAC__real *window, const FLAC__int32 L)
  94184. {
  94185. const FLAC__int32 N = L - 1;
  94186. FLAC__int32 n;
  94187. for (n = 0; n < L; n++)
  94188. 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));
  94189. }
  94190. void FLAC__window_gauss(FLAC__real *window, const FLAC__int32 L, const FLAC__real stddev)
  94191. {
  94192. const FLAC__int32 N = L - 1;
  94193. const double N2 = (double)N / 2.;
  94194. FLAC__int32 n;
  94195. for (n = 0; n <= N; n++) {
  94196. const double k = ((double)n - N2) / (stddev * N2);
  94197. window[n] = (FLAC__real)exp(-0.5f * k * k);
  94198. }
  94199. }
  94200. void FLAC__window_hamming(FLAC__real *window, const FLAC__int32 L)
  94201. {
  94202. const FLAC__int32 N = L - 1;
  94203. FLAC__int32 n;
  94204. for (n = 0; n < L; n++)
  94205. window[n] = (FLAC__real)(0.54f - 0.46f * cos(2.0f * M_PI * n / N));
  94206. }
  94207. void FLAC__window_hann(FLAC__real *window, const FLAC__int32 L)
  94208. {
  94209. const FLAC__int32 N = L - 1;
  94210. FLAC__int32 n;
  94211. for (n = 0; n < L; n++)
  94212. window[n] = (FLAC__real)(0.5f - 0.5f * cos(2.0f * M_PI * n / N));
  94213. }
  94214. void FLAC__window_kaiser_bessel(FLAC__real *window, const FLAC__int32 L)
  94215. {
  94216. const FLAC__int32 N = L - 1;
  94217. FLAC__int32 n;
  94218. for (n = 0; n < L; n++)
  94219. 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));
  94220. }
  94221. void FLAC__window_nuttall(FLAC__real *window, const FLAC__int32 L)
  94222. {
  94223. const FLAC__int32 N = L - 1;
  94224. FLAC__int32 n;
  94225. for (n = 0; n < L; n++)
  94226. 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));
  94227. }
  94228. void FLAC__window_rectangle(FLAC__real *window, const FLAC__int32 L)
  94229. {
  94230. FLAC__int32 n;
  94231. for (n = 0; n < L; n++)
  94232. window[n] = 1.0f;
  94233. }
  94234. void FLAC__window_triangle(FLAC__real *window, const FLAC__int32 L)
  94235. {
  94236. FLAC__int32 n;
  94237. if (L & 1) {
  94238. for (n = 1; n <= L+1/2; n++)
  94239. window[n-1] = 2.0f * n / ((float)L + 1.0f);
  94240. for (; n <= L; n++)
  94241. window[n-1] = - (float)(2 * (L - n + 1)) / ((float)L + 1.0f);
  94242. }
  94243. else {
  94244. for (n = 1; n <= L/2; n++)
  94245. window[n-1] = 2.0f * n / (float)L;
  94246. for (; n <= L; n++)
  94247. window[n-1] = ((float)(2 * (L - n)) + 1.0f) / (float)L;
  94248. }
  94249. }
  94250. void FLAC__window_tukey(FLAC__real *window, const FLAC__int32 L, const FLAC__real p)
  94251. {
  94252. if (p <= 0.0)
  94253. FLAC__window_rectangle(window, L);
  94254. else if (p >= 1.0)
  94255. FLAC__window_hann(window, L);
  94256. else {
  94257. const FLAC__int32 Np = (FLAC__int32)(p / 2.0f * L) - 1;
  94258. FLAC__int32 n;
  94259. FLAC__window_rectangle(window, L);
  94260. if (Np > 0) {
  94261. for (n = 0; n <= Np; n++) {
  94262. window[n] = (FLAC__real)(0.5f - 0.5f * cos(M_PI * n / Np));
  94263. window[L-Np-1+n] = (FLAC__real)(0.5f - 0.5f * cos(M_PI * (n+Np) / Np));
  94264. }
  94265. }
  94266. }
  94267. }
  94268. void FLAC__window_welch(FLAC__real *window, const FLAC__int32 L)
  94269. {
  94270. const FLAC__int32 N = L - 1;
  94271. const double N2 = (double)N / 2.;
  94272. FLAC__int32 n;
  94273. for (n = 0; n <= N; n++) {
  94274. const double k = ((double)n - N2) / N2;
  94275. window[n] = (FLAC__real)(1.0f - k * k);
  94276. }
  94277. }
  94278. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  94279. #endif
  94280. /*** End of inlined file: window_flac.c ***/
  94281. #else
  94282. #include <FLAC/all.h>
  94283. #endif
  94284. }
  94285. #ifdef _MSC_VER
  94286. #pragma warning (pop)
  94287. #endif
  94288. BEGIN_JUCE_NAMESPACE
  94289. using namespace FlacNamespace;
  94290. static const char* const flacFormatName = "FLAC file";
  94291. static const tchar* const flacExtensions[] = { T(".flac"), 0 };
  94292. class FlacReader : public AudioFormatReader
  94293. {
  94294. FLAC__StreamDecoder* decoder;
  94295. AudioSampleBuffer reservoir;
  94296. int reservoirStart, samplesInReservoir;
  94297. bool ok, scanningForLength;
  94298. public:
  94299. FlacReader (InputStream* const in)
  94300. : AudioFormatReader (in, TRANS (flacFormatName)),
  94301. reservoir (2, 0),
  94302. reservoirStart (0),
  94303. samplesInReservoir (0),
  94304. scanningForLength (false)
  94305. {
  94306. using namespace FlacNamespace;
  94307. lengthInSamples = 0;
  94308. decoder = FLAC__stream_decoder_new();
  94309. ok = FLAC__stream_decoder_init_stream (decoder,
  94310. readCallback_, seekCallback_, tellCallback_, lengthCallback_,
  94311. eofCallback_, writeCallback_, metadataCallback_, errorCallback_,
  94312. (void*) this) == FLAC__STREAM_DECODER_INIT_STATUS_OK;
  94313. if (ok)
  94314. {
  94315. FLAC__stream_decoder_process_until_end_of_metadata (decoder);
  94316. if (lengthInSamples == 0 && sampleRate > 0)
  94317. {
  94318. // the length hasn't been stored in the metadata, so we'll need to
  94319. // work it out the length the hard way, by scanning the whole file..
  94320. scanningForLength = true;
  94321. FLAC__stream_decoder_process_until_end_of_stream (decoder);
  94322. scanningForLength = false;
  94323. const int64 tempLength = lengthInSamples;
  94324. FLAC__stream_decoder_reset (decoder);
  94325. FLAC__stream_decoder_process_until_end_of_metadata (decoder);
  94326. lengthInSamples = tempLength;
  94327. }
  94328. }
  94329. }
  94330. ~FlacReader()
  94331. {
  94332. FLAC__stream_decoder_delete (decoder);
  94333. }
  94334. void useMetadata (const FLAC__StreamMetadata_StreamInfo& info)
  94335. {
  94336. sampleRate = info.sample_rate;
  94337. bitsPerSample = info.bits_per_sample;
  94338. lengthInSamples = (unsigned int) info.total_samples;
  94339. numChannels = info.channels;
  94340. reservoir.setSize (numChannels, 2 * info.max_blocksize, false, false, true);
  94341. }
  94342. // returns the number of samples read
  94343. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  94344. int64 startSampleInFile, int numSamples)
  94345. {
  94346. using namespace FlacNamespace;
  94347. if (! ok)
  94348. return false;
  94349. while (numSamples > 0)
  94350. {
  94351. if (startSampleInFile >= reservoirStart
  94352. && startSampleInFile < reservoirStart + samplesInReservoir)
  94353. {
  94354. const int num = (int) jmin ((int64) numSamples,
  94355. reservoirStart + samplesInReservoir - startSampleInFile);
  94356. jassert (num > 0);
  94357. for (int i = jmin (numDestChannels, reservoir.getNumChannels()); --i >= 0;)
  94358. if (destSamples[i] != 0)
  94359. memcpy (destSamples[i] + startOffsetInDestBuffer,
  94360. reservoir.getSampleData (i, (int) (startSampleInFile - reservoirStart)),
  94361. sizeof (int) * num);
  94362. startOffsetInDestBuffer += num;
  94363. startSampleInFile += num;
  94364. numSamples -= num;
  94365. }
  94366. else
  94367. {
  94368. if (startSampleInFile >= (int) lengthInSamples)
  94369. {
  94370. samplesInReservoir = 0;
  94371. }
  94372. else if (startSampleInFile < reservoirStart
  94373. || startSampleInFile > reservoirStart + jmax (samplesInReservoir, 511))
  94374. {
  94375. // had some problems with flac crashing if the read pos is aligned more
  94376. // accurately than this. Probably fixed in newer versions of the library, though.
  94377. reservoirStart = (int) (startSampleInFile & ~511);
  94378. samplesInReservoir = 0;
  94379. FLAC__stream_decoder_seek_absolute (decoder, (FLAC__uint64) reservoirStart);
  94380. }
  94381. else
  94382. {
  94383. reservoirStart += samplesInReservoir;
  94384. samplesInReservoir = 0;
  94385. FLAC__stream_decoder_process_single (decoder);
  94386. }
  94387. if (samplesInReservoir == 0)
  94388. break;
  94389. }
  94390. }
  94391. if (numSamples > 0)
  94392. {
  94393. for (int i = numDestChannels; --i >= 0;)
  94394. if (destSamples[i] != 0)
  94395. zeromem (destSamples[i] + startOffsetInDestBuffer,
  94396. sizeof (int) * numSamples);
  94397. }
  94398. return true;
  94399. }
  94400. void useSamples (const FLAC__int32* const buffer[], int numSamples)
  94401. {
  94402. if (scanningForLength)
  94403. {
  94404. lengthInSamples += numSamples;
  94405. }
  94406. else
  94407. {
  94408. if (numSamples > reservoir.getNumSamples())
  94409. reservoir.setSize (numChannels, numSamples, false, false, true);
  94410. const int bitsToShift = 32 - bitsPerSample;
  94411. for (int i = 0; i < (int) numChannels; ++i)
  94412. {
  94413. const FLAC__int32* src = buffer[i];
  94414. int n = i;
  94415. while (src == 0 && n > 0)
  94416. src = buffer [--n];
  94417. if (src != 0)
  94418. {
  94419. int* dest = (int*) reservoir.getSampleData(i);
  94420. for (int j = 0; j < numSamples; ++j)
  94421. dest[j] = src[j] << bitsToShift;
  94422. }
  94423. }
  94424. samplesInReservoir = numSamples;
  94425. }
  94426. }
  94427. static FLAC__StreamDecoderReadStatus readCallback_ (const FLAC__StreamDecoder*, FLAC__byte buffer[], size_t* bytes, void* client_data)
  94428. {
  94429. *bytes = (unsigned int) ((const FlacReader*) client_data)->input->read (buffer, (int) *bytes);
  94430. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  94431. }
  94432. static FLAC__StreamDecoderSeekStatus seekCallback_ (const FLAC__StreamDecoder*, FLAC__uint64 absolute_byte_offset, void* client_data)
  94433. {
  94434. ((const FlacReader*) client_data)->input->setPosition ((int) absolute_byte_offset);
  94435. return FLAC__STREAM_DECODER_SEEK_STATUS_OK;
  94436. }
  94437. static FLAC__StreamDecoderTellStatus tellCallback_ (const FLAC__StreamDecoder*, FLAC__uint64* absolute_byte_offset, void* client_data)
  94438. {
  94439. *absolute_byte_offset = ((const FlacReader*) client_data)->input->getPosition();
  94440. return FLAC__STREAM_DECODER_TELL_STATUS_OK;
  94441. }
  94442. static FLAC__StreamDecoderLengthStatus lengthCallback_ (const FLAC__StreamDecoder*, FLAC__uint64* stream_length, void* client_data)
  94443. {
  94444. *stream_length = ((const FlacReader*) client_data)->input->getTotalLength();
  94445. return FLAC__STREAM_DECODER_LENGTH_STATUS_OK;
  94446. }
  94447. static FLAC__bool eofCallback_ (const FLAC__StreamDecoder*, void* client_data)
  94448. {
  94449. return ((const FlacReader*) client_data)->input->isExhausted();
  94450. }
  94451. static FLAC__StreamDecoderWriteStatus writeCallback_ (const FLAC__StreamDecoder*,
  94452. const FLAC__Frame* frame,
  94453. const FLAC__int32* const buffer[],
  94454. void* client_data)
  94455. {
  94456. ((FlacReader*) client_data)->useSamples (buffer, frame->header.blocksize);
  94457. return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
  94458. }
  94459. static void metadataCallback_ (const FLAC__StreamDecoder*,
  94460. const FLAC__StreamMetadata* metadata,
  94461. void* client_data)
  94462. {
  94463. ((FlacReader*) client_data)->useMetadata (metadata->data.stream_info);
  94464. }
  94465. static void errorCallback_ (const FLAC__StreamDecoder*, FLAC__StreamDecoderErrorStatus, void*)
  94466. {
  94467. }
  94468. juce_UseDebuggingNewOperator
  94469. };
  94470. class FlacWriter : public AudioFormatWriter
  94471. {
  94472. FLAC__StreamEncoder* encoder;
  94473. MemoryBlock temp;
  94474. public:
  94475. bool ok;
  94476. FlacWriter (OutputStream* const out,
  94477. const double sampleRate_,
  94478. const int numChannels_,
  94479. const int bitsPerSample_)
  94480. : AudioFormatWriter (out, TRANS (flacFormatName),
  94481. sampleRate_,
  94482. numChannels_,
  94483. bitsPerSample_)
  94484. {
  94485. using namespace FlacNamespace;
  94486. encoder = FLAC__stream_encoder_new();
  94487. FLAC__stream_encoder_set_do_mid_side_stereo (encoder, numChannels == 2);
  94488. FLAC__stream_encoder_set_loose_mid_side_stereo (encoder, numChannels == 2);
  94489. FLAC__stream_encoder_set_channels (encoder, numChannels);
  94490. FLAC__stream_encoder_set_bits_per_sample (encoder, jmin ((unsigned int) 24, bitsPerSample));
  94491. FLAC__stream_encoder_set_sample_rate (encoder, (unsigned int) sampleRate);
  94492. FLAC__stream_encoder_set_blocksize (encoder, 2048);
  94493. FLAC__stream_encoder_set_do_escape_coding (encoder, true);
  94494. ok = FLAC__stream_encoder_init_stream (encoder,
  94495. encodeWriteCallback, encodeSeekCallback,
  94496. encodeTellCallback, encodeMetadataCallback,
  94497. (void*) this) == FLAC__STREAM_ENCODER_INIT_STATUS_OK;
  94498. }
  94499. ~FlacWriter()
  94500. {
  94501. if (ok)
  94502. {
  94503. FLAC__stream_encoder_finish (encoder);
  94504. output->flush();
  94505. }
  94506. else
  94507. {
  94508. output = 0; // to stop the base class deleting this, as it needs to be returned
  94509. // to the caller of createWriter()
  94510. }
  94511. FLAC__stream_encoder_delete (encoder);
  94512. }
  94513. bool write (const int** samplesToWrite, int numSamples)
  94514. {
  94515. if (! ok)
  94516. return false;
  94517. int* buf[3];
  94518. const int bitsToShift = 32 - bitsPerSample;
  94519. if (bitsToShift > 0)
  94520. {
  94521. const int numChannelsToWrite = (samplesToWrite[1] == 0) ? 1 : 2;
  94522. temp.setSize (sizeof (int) * numSamples * numChannelsToWrite);
  94523. buf[0] = (int*) temp.getData();
  94524. buf[1] = buf[0] + numSamples;
  94525. buf[2] = 0;
  94526. for (int i = numChannelsToWrite; --i >= 0;)
  94527. {
  94528. if (samplesToWrite[i] != 0)
  94529. {
  94530. for (int j = 0; j < numSamples; ++j)
  94531. buf [i][j] = (samplesToWrite [i][j] >> bitsToShift);
  94532. }
  94533. }
  94534. samplesToWrite = (const int**) buf;
  94535. }
  94536. return FLAC__stream_encoder_process (encoder,
  94537. (const FLAC__int32**) samplesToWrite,
  94538. numSamples) != 0;
  94539. }
  94540. bool writeData (const void* const data, const int size) const
  94541. {
  94542. return output->write (data, size);
  94543. }
  94544. static void packUint32 (FLAC__uint32 val, FLAC__byte* b, const int bytes)
  94545. {
  94546. b += bytes;
  94547. for (int i = 0; i < bytes; ++i)
  94548. {
  94549. *(--b) = (FLAC__byte) (val & 0xff);
  94550. val >>= 8;
  94551. }
  94552. }
  94553. void writeMetaData (const FLAC__StreamMetadata* metadata)
  94554. {
  94555. using namespace FlacNamespace;
  94556. const FLAC__StreamMetadata_StreamInfo& info = metadata->data.stream_info;
  94557. unsigned char buffer [FLAC__STREAM_METADATA_STREAMINFO_LENGTH];
  94558. const unsigned int channelsMinus1 = info.channels - 1;
  94559. const unsigned int bitsMinus1 = info.bits_per_sample - 1;
  94560. packUint32 (info.min_blocksize, buffer, 2);
  94561. packUint32 (info.max_blocksize, buffer + 2, 2);
  94562. packUint32 (info.min_framesize, buffer + 4, 3);
  94563. packUint32 (info.max_framesize, buffer + 7, 3);
  94564. buffer[10] = (uint8) ((info.sample_rate >> 12) & 0xff);
  94565. buffer[11] = (uint8) ((info.sample_rate >> 4) & 0xff);
  94566. buffer[12] = (uint8) (((info.sample_rate & 0x0f) << 4) | (channelsMinus1 << 1) | (bitsMinus1 >> 4));
  94567. buffer[13] = (FLAC__byte) (((bitsMinus1 & 0x0f) << 4) | (unsigned int) ((info.total_samples >> 32) & 0x0f));
  94568. packUint32 ((FLAC__uint32) info.total_samples, buffer + 14, 4);
  94569. memcpy (buffer + 18, info.md5sum, 16);
  94570. const bool seekOk = output->setPosition (4);
  94571. (void) seekOk;
  94572. // if this fails, you've given it an output stream that can't seek! It needs
  94573. // to be able to seek back to write the header
  94574. jassert (seekOk);
  94575. output->writeIntBigEndian (FLAC__STREAM_METADATA_STREAMINFO_LENGTH);
  94576. output->write (buffer, FLAC__STREAM_METADATA_STREAMINFO_LENGTH);
  94577. }
  94578. static FLAC__StreamEncoderWriteStatus encodeWriteCallback (const FLAC__StreamEncoder*,
  94579. const FLAC__byte buffer[],
  94580. size_t bytes,
  94581. unsigned int /*samples*/,
  94582. unsigned int /*current_frame*/,
  94583. void* client_data)
  94584. {
  94585. using namespace FlacNamespace;
  94586. return ((FlacWriter*) client_data)->writeData (buffer, (int) bytes)
  94587. ? FLAC__STREAM_ENCODER_WRITE_STATUS_OK
  94588. : FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
  94589. }
  94590. static FLAC__StreamEncoderSeekStatus encodeSeekCallback (const FLAC__StreamEncoder*, FLAC__uint64, void*)
  94591. {
  94592. return FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED;
  94593. }
  94594. static FLAC__StreamEncoderTellStatus encodeTellCallback (const FLAC__StreamEncoder*, FLAC__uint64* absolute_byte_offset, void* client_data)
  94595. {
  94596. if (client_data == 0)
  94597. return FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED;
  94598. *absolute_byte_offset = (FLAC__uint64) ((FlacWriter*) client_data)->output->getPosition();
  94599. return FLAC__STREAM_ENCODER_TELL_STATUS_OK;
  94600. }
  94601. static void encodeMetadataCallback (const FLAC__StreamEncoder*,
  94602. const FLAC__StreamMetadata* metadata,
  94603. void* client_data)
  94604. {
  94605. ((FlacWriter*) client_data)->writeMetaData (metadata);
  94606. }
  94607. juce_UseDebuggingNewOperator
  94608. };
  94609. FlacAudioFormat::FlacAudioFormat()
  94610. : AudioFormat (TRANS (flacFormatName), (const tchar**) flacExtensions)
  94611. {
  94612. }
  94613. FlacAudioFormat::~FlacAudioFormat()
  94614. {
  94615. }
  94616. const Array <int> FlacAudioFormat::getPossibleSampleRates()
  94617. {
  94618. const int rates[] = { 22050, 32000, 44100, 48000, 88200, 96000, 0 };
  94619. return Array <int> (rates);
  94620. }
  94621. const Array <int> FlacAudioFormat::getPossibleBitDepths()
  94622. {
  94623. const int depths[] = { 16, 24, 0 };
  94624. return Array <int> (depths);
  94625. }
  94626. bool FlacAudioFormat::canDoStereo()
  94627. {
  94628. return true;
  94629. }
  94630. bool FlacAudioFormat::canDoMono()
  94631. {
  94632. return true;
  94633. }
  94634. bool FlacAudioFormat::isCompressed()
  94635. {
  94636. return true;
  94637. }
  94638. AudioFormatReader* FlacAudioFormat::createReaderFor (InputStream* in,
  94639. const bool deleteStreamIfOpeningFails)
  94640. {
  94641. ScopedPointer <FlacReader> r (new FlacReader (in));
  94642. if (r->sampleRate != 0)
  94643. return r.release();
  94644. if (! deleteStreamIfOpeningFails)
  94645. r->input = 0;
  94646. return 0;
  94647. }
  94648. AudioFormatWriter* FlacAudioFormat::createWriterFor (OutputStream* out,
  94649. double sampleRate,
  94650. unsigned int numberOfChannels,
  94651. int bitsPerSample,
  94652. const StringPairArray& /*metadataValues*/,
  94653. int /*qualityOptionIndex*/)
  94654. {
  94655. if (getPossibleBitDepths().contains (bitsPerSample))
  94656. {
  94657. ScopedPointer <FlacWriter> w (new FlacWriter (out,
  94658. sampleRate,
  94659. numberOfChannels,
  94660. bitsPerSample));
  94661. if (w->ok)
  94662. return w.release();
  94663. }
  94664. return 0;
  94665. }
  94666. END_JUCE_NAMESPACE
  94667. #endif
  94668. /*** End of inlined file: juce_FlacAudioFormat.cpp ***/
  94669. /*** Start of inlined file: juce_OggVorbisAudioFormat.cpp ***/
  94670. #if JUCE_USE_OGGVORBIS
  94671. #if JUCE_MAC
  94672. #define __MACOSX__ 1
  94673. #endif
  94674. namespace OggVorbisNamespace
  94675. {
  94676. #if JUCE_INCLUDE_OGGVORBIS_CODE
  94677. /*** Start of inlined file: vorbisenc.h ***/
  94678. #ifndef _OV_ENC_H_
  94679. #define _OV_ENC_H_
  94680. #ifdef __cplusplus
  94681. extern "C"
  94682. {
  94683. #endif /* __cplusplus */
  94684. /*** Start of inlined file: codec.h ***/
  94685. #ifndef _vorbis_codec_h_
  94686. #define _vorbis_codec_h_
  94687. #ifdef __cplusplus
  94688. extern "C"
  94689. {
  94690. #endif /* __cplusplus */
  94691. /*** Start of inlined file: ogg.h ***/
  94692. #ifndef _OGG_H
  94693. #define _OGG_H
  94694. #ifdef __cplusplus
  94695. extern "C" {
  94696. #endif
  94697. /*** Start of inlined file: os_types.h ***/
  94698. #ifndef _OS_TYPES_H
  94699. #define _OS_TYPES_H
  94700. #define _ogg_malloc malloc
  94701. #define _ogg_calloc calloc
  94702. #define _ogg_realloc realloc
  94703. #define _ogg_free free
  94704. #if defined(_WIN32)
  94705. # if defined(__CYGWIN__)
  94706. # include <_G_config.h>
  94707. typedef _G_int64_t ogg_int64_t;
  94708. typedef _G_int32_t ogg_int32_t;
  94709. typedef _G_uint32_t ogg_uint32_t;
  94710. typedef _G_int16_t ogg_int16_t;
  94711. typedef _G_uint16_t ogg_uint16_t;
  94712. # elif defined(__MINGW32__)
  94713. typedef short ogg_int16_t;
  94714. typedef unsigned short ogg_uint16_t;
  94715. typedef int ogg_int32_t;
  94716. typedef unsigned int ogg_uint32_t;
  94717. typedef long long ogg_int64_t;
  94718. typedef unsigned long long ogg_uint64_t;
  94719. # elif defined(__MWERKS__)
  94720. typedef long long ogg_int64_t;
  94721. typedef int ogg_int32_t;
  94722. typedef unsigned int ogg_uint32_t;
  94723. typedef short ogg_int16_t;
  94724. typedef unsigned short ogg_uint16_t;
  94725. # else
  94726. typedef __int64 ogg_int64_t;
  94727. typedef __int32 ogg_int32_t;
  94728. typedef unsigned __int32 ogg_uint32_t;
  94729. typedef __int16 ogg_int16_t;
  94730. typedef unsigned __int16 ogg_uint16_t;
  94731. # endif
  94732. #elif defined(__MACOS__)
  94733. # include <sys/types.h>
  94734. typedef SInt16 ogg_int16_t;
  94735. typedef UInt16 ogg_uint16_t;
  94736. typedef SInt32 ogg_int32_t;
  94737. typedef UInt32 ogg_uint32_t;
  94738. typedef SInt64 ogg_int64_t;
  94739. #elif defined(__MACOSX__) /* MacOS X Framework build */
  94740. # include <sys/types.h>
  94741. typedef int16_t ogg_int16_t;
  94742. typedef u_int16_t ogg_uint16_t;
  94743. typedef int32_t ogg_int32_t;
  94744. typedef u_int32_t ogg_uint32_t;
  94745. typedef int64_t ogg_int64_t;
  94746. #elif defined(__BEOS__)
  94747. # include <inttypes.h>
  94748. typedef int16_t ogg_int16_t;
  94749. typedef u_int16_t ogg_uint16_t;
  94750. typedef int32_t ogg_int32_t;
  94751. typedef u_int32_t ogg_uint32_t;
  94752. typedef int64_t ogg_int64_t;
  94753. #elif defined (__EMX__)
  94754. typedef short ogg_int16_t;
  94755. typedef unsigned short ogg_uint16_t;
  94756. typedef int ogg_int32_t;
  94757. typedef unsigned int ogg_uint32_t;
  94758. typedef long long ogg_int64_t;
  94759. #elif defined (DJGPP)
  94760. typedef short ogg_int16_t;
  94761. typedef int ogg_int32_t;
  94762. typedef unsigned int ogg_uint32_t;
  94763. typedef long long ogg_int64_t;
  94764. #elif defined(R5900)
  94765. typedef long ogg_int64_t;
  94766. typedef int ogg_int32_t;
  94767. typedef unsigned ogg_uint32_t;
  94768. typedef short ogg_int16_t;
  94769. #elif defined(__SYMBIAN32__)
  94770. typedef signed short ogg_int16_t;
  94771. typedef unsigned short ogg_uint16_t;
  94772. typedef signed int ogg_int32_t;
  94773. typedef unsigned int ogg_uint32_t;
  94774. typedef long long int ogg_int64_t;
  94775. #else
  94776. # include <sys/types.h>
  94777. /*** Start of inlined file: config_types.h ***/
  94778. #ifndef __CONFIG_TYPES_H__
  94779. #define __CONFIG_TYPES_H__
  94780. typedef int16_t ogg_int16_t;
  94781. typedef unsigned short ogg_uint16_t;
  94782. typedef int32_t ogg_int32_t;
  94783. typedef unsigned int ogg_uint32_t;
  94784. typedef int64_t ogg_int64_t;
  94785. #endif
  94786. /*** End of inlined file: config_types.h ***/
  94787. #endif
  94788. #endif /* _OS_TYPES_H */
  94789. /*** End of inlined file: os_types.h ***/
  94790. typedef struct {
  94791. long endbyte;
  94792. int endbit;
  94793. unsigned char *buffer;
  94794. unsigned char *ptr;
  94795. long storage;
  94796. } oggpack_buffer;
  94797. typedef struct {
  94798. unsigned char *header;
  94799. long header_len;
  94800. unsigned char *body;
  94801. long body_len;
  94802. } ogg_page;
  94803. ogg_uint32_t ogg_bitreverse(ogg_uint32_t x){
  94804. x= ((x>>16)&0x0000ffffUL) | ((x<<16)&0xffff0000UL);
  94805. x= ((x>> 8)&0x00ff00ffUL) | ((x<< 8)&0xff00ff00UL);
  94806. x= ((x>> 4)&0x0f0f0f0fUL) | ((x<< 4)&0xf0f0f0f0UL);
  94807. x= ((x>> 2)&0x33333333UL) | ((x<< 2)&0xccccccccUL);
  94808. return((x>> 1)&0x55555555UL) | ((x<< 1)&0xaaaaaaaaUL);
  94809. }
  94810. typedef struct {
  94811. unsigned char *body_data; /* bytes from packet bodies */
  94812. long body_storage; /* storage elements allocated */
  94813. long body_fill; /* elements stored; fill mark */
  94814. long body_returned; /* elements of fill returned */
  94815. int *lacing_vals; /* The values that will go to the segment table */
  94816. ogg_int64_t *granule_vals; /* granulepos values for headers. Not compact
  94817. this way, but it is simple coupled to the
  94818. lacing fifo */
  94819. long lacing_storage;
  94820. long lacing_fill;
  94821. long lacing_packet;
  94822. long lacing_returned;
  94823. unsigned char header[282]; /* working space for header encode */
  94824. int header_fill;
  94825. int e_o_s; /* set when we have buffered the last packet in the
  94826. logical bitstream */
  94827. int b_o_s; /* set after we've written the initial page
  94828. of a logical bitstream */
  94829. long serialno;
  94830. long pageno;
  94831. ogg_int64_t packetno; /* sequence number for decode; the framing
  94832. knows where there's a hole in the data,
  94833. but we need coupling so that the codec
  94834. (which is in a seperate abstraction
  94835. layer) also knows about the gap */
  94836. ogg_int64_t granulepos;
  94837. } ogg_stream_state;
  94838. typedef struct {
  94839. unsigned char *packet;
  94840. long bytes;
  94841. long b_o_s;
  94842. long e_o_s;
  94843. ogg_int64_t granulepos;
  94844. ogg_int64_t packetno; /* sequence number for decode; the framing
  94845. knows where there's a hole in the data,
  94846. but we need coupling so that the codec
  94847. (which is in a seperate abstraction
  94848. layer) also knows about the gap */
  94849. } ogg_packet;
  94850. typedef struct {
  94851. unsigned char *data;
  94852. int storage;
  94853. int fill;
  94854. int returned;
  94855. int unsynced;
  94856. int headerbytes;
  94857. int bodybytes;
  94858. } ogg_sync_state;
  94859. extern void oggpack_writeinit(oggpack_buffer *b);
  94860. extern void oggpack_writetrunc(oggpack_buffer *b,long bits);
  94861. extern void oggpack_writealign(oggpack_buffer *b);
  94862. extern void oggpack_writecopy(oggpack_buffer *b,void *source,long bits);
  94863. extern void oggpack_reset(oggpack_buffer *b);
  94864. extern void oggpack_writeclear(oggpack_buffer *b);
  94865. extern void oggpack_readinit(oggpack_buffer *b,unsigned char *buf,int bytes);
  94866. extern void oggpack_write(oggpack_buffer *b,unsigned long value,int bits);
  94867. extern long oggpack_look(oggpack_buffer *b,int bits);
  94868. extern long oggpack_look1(oggpack_buffer *b);
  94869. extern void oggpack_adv(oggpack_buffer *b,int bits);
  94870. extern void oggpack_adv1(oggpack_buffer *b);
  94871. extern long oggpack_read(oggpack_buffer *b,int bits);
  94872. extern long oggpack_read1(oggpack_buffer *b);
  94873. extern long oggpack_bytes(oggpack_buffer *b);
  94874. extern long oggpack_bits(oggpack_buffer *b);
  94875. extern unsigned char *oggpack_get_buffer(oggpack_buffer *b);
  94876. extern void oggpackB_writeinit(oggpack_buffer *b);
  94877. extern void oggpackB_writetrunc(oggpack_buffer *b,long bits);
  94878. extern void oggpackB_writealign(oggpack_buffer *b);
  94879. extern void oggpackB_writecopy(oggpack_buffer *b,void *source,long bits);
  94880. extern void oggpackB_reset(oggpack_buffer *b);
  94881. extern void oggpackB_writeclear(oggpack_buffer *b);
  94882. extern void oggpackB_readinit(oggpack_buffer *b,unsigned char *buf,int bytes);
  94883. extern void oggpackB_write(oggpack_buffer *b,unsigned long value,int bits);
  94884. extern long oggpackB_look(oggpack_buffer *b,int bits);
  94885. extern long oggpackB_look1(oggpack_buffer *b);
  94886. extern void oggpackB_adv(oggpack_buffer *b,int bits);
  94887. extern void oggpackB_adv1(oggpack_buffer *b);
  94888. extern long oggpackB_read(oggpack_buffer *b,int bits);
  94889. extern long oggpackB_read1(oggpack_buffer *b);
  94890. extern long oggpackB_bytes(oggpack_buffer *b);
  94891. extern long oggpackB_bits(oggpack_buffer *b);
  94892. extern unsigned char *oggpackB_get_buffer(oggpack_buffer *b);
  94893. extern int ogg_stream_packetin(ogg_stream_state *os, ogg_packet *op);
  94894. extern int ogg_stream_pageout(ogg_stream_state *os, ogg_page *og);
  94895. extern int ogg_stream_flush(ogg_stream_state *os, ogg_page *og);
  94896. extern int ogg_sync_init(ogg_sync_state *oy);
  94897. extern int ogg_sync_clear(ogg_sync_state *oy);
  94898. extern int ogg_sync_reset(ogg_sync_state *oy);
  94899. extern int ogg_sync_destroy(ogg_sync_state *oy);
  94900. extern char *ogg_sync_buffer(ogg_sync_state *oy, long size);
  94901. extern int ogg_sync_wrote(ogg_sync_state *oy, long bytes);
  94902. extern long ogg_sync_pageseek(ogg_sync_state *oy,ogg_page *og);
  94903. extern int ogg_sync_pageout(ogg_sync_state *oy, ogg_page *og);
  94904. extern int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og);
  94905. extern int ogg_stream_packetout(ogg_stream_state *os,ogg_packet *op);
  94906. extern int ogg_stream_packetpeek(ogg_stream_state *os,ogg_packet *op);
  94907. extern int ogg_stream_init(ogg_stream_state *os,int serialno);
  94908. extern int ogg_stream_clear(ogg_stream_state *os);
  94909. extern int ogg_stream_reset(ogg_stream_state *os);
  94910. extern int ogg_stream_reset_serialno(ogg_stream_state *os,int serialno);
  94911. extern int ogg_stream_destroy(ogg_stream_state *os);
  94912. extern int ogg_stream_eos(ogg_stream_state *os);
  94913. extern void ogg_page_checksum_set(ogg_page *og);
  94914. extern int ogg_page_version(ogg_page *og);
  94915. extern int ogg_page_continued(ogg_page *og);
  94916. extern int ogg_page_bos(ogg_page *og);
  94917. extern int ogg_page_eos(ogg_page *og);
  94918. extern ogg_int64_t ogg_page_granulepos(ogg_page *og);
  94919. extern int ogg_page_serialno(ogg_page *og);
  94920. extern long ogg_page_pageno(ogg_page *og);
  94921. extern int ogg_page_packets(ogg_page *og);
  94922. extern void ogg_packet_clear(ogg_packet *op);
  94923. #ifdef __cplusplus
  94924. }
  94925. #endif
  94926. #endif /* _OGG_H */
  94927. /*** End of inlined file: ogg.h ***/
  94928. typedef struct vorbis_info{
  94929. int version;
  94930. int channels;
  94931. long rate;
  94932. long bitrate_upper;
  94933. long bitrate_nominal;
  94934. long bitrate_lower;
  94935. long bitrate_window;
  94936. void *codec_setup;
  94937. } vorbis_info;
  94938. typedef struct vorbis_dsp_state{
  94939. int analysisp;
  94940. vorbis_info *vi;
  94941. float **pcm;
  94942. float **pcmret;
  94943. int pcm_storage;
  94944. int pcm_current;
  94945. int pcm_returned;
  94946. int preextrapolate;
  94947. int eofflag;
  94948. long lW;
  94949. long W;
  94950. long nW;
  94951. long centerW;
  94952. ogg_int64_t granulepos;
  94953. ogg_int64_t sequence;
  94954. ogg_int64_t glue_bits;
  94955. ogg_int64_t time_bits;
  94956. ogg_int64_t floor_bits;
  94957. ogg_int64_t res_bits;
  94958. void *backend_state;
  94959. } vorbis_dsp_state;
  94960. typedef struct vorbis_block{
  94961. float **pcm; /* this is a pointer into local storage */
  94962. oggpack_buffer opb;
  94963. long lW;
  94964. long W;
  94965. long nW;
  94966. int pcmend;
  94967. int mode;
  94968. int eofflag;
  94969. ogg_int64_t granulepos;
  94970. ogg_int64_t sequence;
  94971. vorbis_dsp_state *vd; /* For read-only access of configuration */
  94972. void *localstore;
  94973. long localtop;
  94974. long localalloc;
  94975. long totaluse;
  94976. struct alloc_chain *reap;
  94977. long glue_bits;
  94978. long time_bits;
  94979. long floor_bits;
  94980. long res_bits;
  94981. void *internal;
  94982. } vorbis_block;
  94983. struct alloc_chain{
  94984. void *ptr;
  94985. struct alloc_chain *next;
  94986. };
  94987. typedef struct vorbis_comment{
  94988. char **user_comments;
  94989. int *comment_lengths;
  94990. int comments;
  94991. char *vendor;
  94992. } vorbis_comment;
  94993. extern void vorbis_info_init(vorbis_info *vi);
  94994. extern void vorbis_info_clear(vorbis_info *vi);
  94995. extern int vorbis_info_blocksize(vorbis_info *vi,int zo);
  94996. extern void vorbis_comment_init(vorbis_comment *vc);
  94997. extern void vorbis_comment_add(vorbis_comment *vc, char *comment);
  94998. extern void vorbis_comment_add_tag(vorbis_comment *vc,
  94999. const char *tag, char *contents);
  95000. extern char *vorbis_comment_query(vorbis_comment *vc, char *tag, int count);
  95001. extern int vorbis_comment_query_count(vorbis_comment *vc, char *tag);
  95002. extern void vorbis_comment_clear(vorbis_comment *vc);
  95003. extern int vorbis_block_init(vorbis_dsp_state *v, vorbis_block *vb);
  95004. extern int vorbis_block_clear(vorbis_block *vb);
  95005. extern void vorbis_dsp_clear(vorbis_dsp_state *v);
  95006. extern double vorbis_granule_time(vorbis_dsp_state *v,
  95007. ogg_int64_t granulepos);
  95008. extern int vorbis_analysis_init(vorbis_dsp_state *v,vorbis_info *vi);
  95009. extern int vorbis_commentheader_out(vorbis_comment *vc, ogg_packet *op);
  95010. extern int vorbis_analysis_headerout(vorbis_dsp_state *v,
  95011. vorbis_comment *vc,
  95012. ogg_packet *op,
  95013. ogg_packet *op_comm,
  95014. ogg_packet *op_code);
  95015. extern float **vorbis_analysis_buffer(vorbis_dsp_state *v,int vals);
  95016. extern int vorbis_analysis_wrote(vorbis_dsp_state *v,int vals);
  95017. extern int vorbis_analysis_blockout(vorbis_dsp_state *v,vorbis_block *vb);
  95018. extern int vorbis_analysis(vorbis_block *vb,ogg_packet *op);
  95019. extern int vorbis_bitrate_addblock(vorbis_block *vb);
  95020. extern int vorbis_bitrate_flushpacket(vorbis_dsp_state *vd,
  95021. ogg_packet *op);
  95022. extern int vorbis_synthesis_headerin(vorbis_info *vi,vorbis_comment *vc,
  95023. ogg_packet *op);
  95024. extern int vorbis_synthesis_init(vorbis_dsp_state *v,vorbis_info *vi);
  95025. extern int vorbis_synthesis_restart(vorbis_dsp_state *v);
  95026. extern int vorbis_synthesis(vorbis_block *vb,ogg_packet *op);
  95027. extern int vorbis_synthesis_trackonly(vorbis_block *vb,ogg_packet *op);
  95028. extern int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb);
  95029. extern int vorbis_synthesis_pcmout(vorbis_dsp_state *v,float ***pcm);
  95030. extern int vorbis_synthesis_lapout(vorbis_dsp_state *v,float ***pcm);
  95031. extern int vorbis_synthesis_read(vorbis_dsp_state *v,int samples);
  95032. extern long vorbis_packet_blocksize(vorbis_info *vi,ogg_packet *op);
  95033. extern int vorbis_synthesis_halfrate(vorbis_info *v,int flag);
  95034. extern int vorbis_synthesis_halfrate_p(vorbis_info *v);
  95035. #define OV_FALSE -1
  95036. #define OV_EOF -2
  95037. #define OV_HOLE -3
  95038. #define OV_EREAD -128
  95039. #define OV_EFAULT -129
  95040. #define OV_EIMPL -130
  95041. #define OV_EINVAL -131
  95042. #define OV_ENOTVORBIS -132
  95043. #define OV_EBADHEADER -133
  95044. #define OV_EVERSION -134
  95045. #define OV_ENOTAUDIO -135
  95046. #define OV_EBADPACKET -136
  95047. #define OV_EBADLINK -137
  95048. #define OV_ENOSEEK -138
  95049. #ifdef __cplusplus
  95050. }
  95051. #endif /* __cplusplus */
  95052. #endif
  95053. /*** End of inlined file: codec.h ***/
  95054. extern int vorbis_encode_init(vorbis_info *vi,
  95055. long channels,
  95056. long rate,
  95057. long max_bitrate,
  95058. long nominal_bitrate,
  95059. long min_bitrate);
  95060. extern int vorbis_encode_setup_managed(vorbis_info *vi,
  95061. long channels,
  95062. long rate,
  95063. long max_bitrate,
  95064. long nominal_bitrate,
  95065. long min_bitrate);
  95066. extern int vorbis_encode_setup_vbr(vorbis_info *vi,
  95067. long channels,
  95068. long rate,
  95069. float quality /* quality level from 0. (lo) to 1. (hi) */
  95070. );
  95071. extern int vorbis_encode_init_vbr(vorbis_info *vi,
  95072. long channels,
  95073. long rate,
  95074. float base_quality /* quality level from 0. (lo) to 1. (hi) */
  95075. );
  95076. extern int vorbis_encode_setup_init(vorbis_info *vi);
  95077. extern int vorbis_encode_ctl(vorbis_info *vi,int number,void *arg);
  95078. #define OV_ECTL_RATEMANAGE_GET 0x10
  95079. #define OV_ECTL_RATEMANAGE_SET 0x11
  95080. #define OV_ECTL_RATEMANAGE_AVG 0x12
  95081. #define OV_ECTL_RATEMANAGE_HARD 0x13
  95082. struct ovectl_ratemanage_arg {
  95083. int management_active;
  95084. long bitrate_hard_min;
  95085. long bitrate_hard_max;
  95086. double bitrate_hard_window;
  95087. long bitrate_av_lo;
  95088. long bitrate_av_hi;
  95089. double bitrate_av_window;
  95090. double bitrate_av_window_center;
  95091. };
  95092. #define OV_ECTL_RATEMANAGE2_GET 0x14
  95093. #define OV_ECTL_RATEMANAGE2_SET 0x15
  95094. struct ovectl_ratemanage2_arg {
  95095. int management_active;
  95096. long bitrate_limit_min_kbps;
  95097. long bitrate_limit_max_kbps;
  95098. long bitrate_limit_reservoir_bits;
  95099. double bitrate_limit_reservoir_bias;
  95100. long bitrate_average_kbps;
  95101. double bitrate_average_damping;
  95102. };
  95103. #define OV_ECTL_LOWPASS_GET 0x20
  95104. #define OV_ECTL_LOWPASS_SET 0x21
  95105. #define OV_ECTL_IBLOCK_GET 0x30
  95106. #define OV_ECTL_IBLOCK_SET 0x31
  95107. #ifdef __cplusplus
  95108. }
  95109. #endif /* __cplusplus */
  95110. #endif
  95111. /*** End of inlined file: vorbisenc.h ***/
  95112. /*** Start of inlined file: vorbisfile.h ***/
  95113. #ifndef _OV_FILE_H_
  95114. #define _OV_FILE_H_
  95115. #ifdef __cplusplus
  95116. extern "C"
  95117. {
  95118. #endif /* __cplusplus */
  95119. #include <stdio.h>
  95120. typedef struct {
  95121. size_t (*read_func) (void *ptr, size_t size, size_t nmemb, void *datasource);
  95122. int (*seek_func) (void *datasource, ogg_int64_t offset, int whence);
  95123. int (*close_func) (void *datasource);
  95124. long (*tell_func) (void *datasource);
  95125. } ov_callbacks;
  95126. #define NOTOPEN 0
  95127. #define PARTOPEN 1
  95128. #define OPENED 2
  95129. #define STREAMSET 3
  95130. #define INITSET 4
  95131. typedef struct OggVorbis_File {
  95132. void *datasource; /* Pointer to a FILE *, etc. */
  95133. int seekable;
  95134. ogg_int64_t offset;
  95135. ogg_int64_t end;
  95136. ogg_sync_state oy;
  95137. int links;
  95138. ogg_int64_t *offsets;
  95139. ogg_int64_t *dataoffsets;
  95140. long *serialnos;
  95141. ogg_int64_t *pcmlengths; /* overloaded to maintain binary
  95142. compatability; x2 size, stores both
  95143. beginning and end values */
  95144. vorbis_info *vi;
  95145. vorbis_comment *vc;
  95146. ogg_int64_t pcm_offset;
  95147. int ready_state;
  95148. long current_serialno;
  95149. int current_link;
  95150. double bittrack;
  95151. double samptrack;
  95152. ogg_stream_state os; /* take physical pages, weld into a logical
  95153. stream of packets */
  95154. vorbis_dsp_state vd; /* central working state for the packet->PCM decoder */
  95155. vorbis_block vb; /* local working space for packet->PCM decode */
  95156. ov_callbacks callbacks;
  95157. } OggVorbis_File;
  95158. extern int ov_clear(OggVorbis_File *vf);
  95159. extern int ov_open(FILE *f,OggVorbis_File *vf,char *initial,long ibytes);
  95160. extern int ov_open_callbacks(void *datasource, OggVorbis_File *vf,
  95161. char *initial, long ibytes, ov_callbacks callbacks);
  95162. extern int ov_test(FILE *f,OggVorbis_File *vf,char *initial,long ibytes);
  95163. extern int ov_test_callbacks(void *datasource, OggVorbis_File *vf,
  95164. char *initial, long ibytes, ov_callbacks callbacks);
  95165. extern int ov_test_open(OggVorbis_File *vf);
  95166. extern long ov_bitrate(OggVorbis_File *vf,int i);
  95167. extern long ov_bitrate_instant(OggVorbis_File *vf);
  95168. extern long ov_streams(OggVorbis_File *vf);
  95169. extern long ov_seekable(OggVorbis_File *vf);
  95170. extern long ov_serialnumber(OggVorbis_File *vf,int i);
  95171. extern ogg_int64_t ov_raw_total(OggVorbis_File *vf,int i);
  95172. extern ogg_int64_t ov_pcm_total(OggVorbis_File *vf,int i);
  95173. extern double ov_time_total(OggVorbis_File *vf,int i);
  95174. extern int ov_raw_seek(OggVorbis_File *vf,ogg_int64_t pos);
  95175. extern int ov_pcm_seek(OggVorbis_File *vf,ogg_int64_t pos);
  95176. extern int ov_pcm_seek_page(OggVorbis_File *vf,ogg_int64_t pos);
  95177. extern int ov_time_seek(OggVorbis_File *vf,double pos);
  95178. extern int ov_time_seek_page(OggVorbis_File *vf,double pos);
  95179. extern int ov_raw_seek_lap(OggVorbis_File *vf,ogg_int64_t pos);
  95180. extern int ov_pcm_seek_lap(OggVorbis_File *vf,ogg_int64_t pos);
  95181. extern int ov_pcm_seek_page_lap(OggVorbis_File *vf,ogg_int64_t pos);
  95182. extern int ov_time_seek_lap(OggVorbis_File *vf,double pos);
  95183. extern int ov_time_seek_page_lap(OggVorbis_File *vf,double pos);
  95184. extern ogg_int64_t ov_raw_tell(OggVorbis_File *vf);
  95185. extern ogg_int64_t ov_pcm_tell(OggVorbis_File *vf);
  95186. extern double ov_time_tell(OggVorbis_File *vf);
  95187. extern vorbis_info *ov_info(OggVorbis_File *vf,int link);
  95188. extern vorbis_comment *ov_comment(OggVorbis_File *vf,int link);
  95189. extern long ov_read_float(OggVorbis_File *vf,float ***pcm_channels,int samples,
  95190. int *bitstream);
  95191. extern long ov_read(OggVorbis_File *vf,char *buffer,int length,
  95192. int bigendianp,int word,int sgned,int *bitstream);
  95193. extern int ov_crosslap(OggVorbis_File *vf1,OggVorbis_File *vf2);
  95194. extern int ov_halfrate(OggVorbis_File *vf,int flag);
  95195. extern int ov_halfrate_p(OggVorbis_File *vf);
  95196. #ifdef __cplusplus
  95197. }
  95198. #endif /* __cplusplus */
  95199. #endif
  95200. /*** End of inlined file: vorbisfile.h ***/
  95201. /*** Start of inlined file: bitwise.c ***/
  95202. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  95203. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  95204. // tasks..
  95205. #if JUCE_MSVC
  95206. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  95207. #endif
  95208. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  95209. #if JUCE_USE_OGGVORBIS
  95210. #include <string.h>
  95211. #include <stdlib.h>
  95212. #define BUFFER_INCREMENT 256
  95213. static const unsigned long mask[]=
  95214. {0x00000000,0x00000001,0x00000003,0x00000007,0x0000000f,
  95215. 0x0000001f,0x0000003f,0x0000007f,0x000000ff,0x000001ff,
  95216. 0x000003ff,0x000007ff,0x00000fff,0x00001fff,0x00003fff,
  95217. 0x00007fff,0x0000ffff,0x0001ffff,0x0003ffff,0x0007ffff,
  95218. 0x000fffff,0x001fffff,0x003fffff,0x007fffff,0x00ffffff,
  95219. 0x01ffffff,0x03ffffff,0x07ffffff,0x0fffffff,0x1fffffff,
  95220. 0x3fffffff,0x7fffffff,0xffffffff };
  95221. static const unsigned int mask8B[]=
  95222. {0x00,0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff};
  95223. void oggpack_writeinit(oggpack_buffer *b){
  95224. memset(b,0,sizeof(*b));
  95225. b->ptr=b->buffer=(unsigned char*) _ogg_malloc(BUFFER_INCREMENT);
  95226. b->buffer[0]='\0';
  95227. b->storage=BUFFER_INCREMENT;
  95228. }
  95229. void oggpackB_writeinit(oggpack_buffer *b){
  95230. oggpack_writeinit(b);
  95231. }
  95232. void oggpack_writetrunc(oggpack_buffer *b,long bits){
  95233. long bytes=bits>>3;
  95234. bits-=bytes*8;
  95235. b->ptr=b->buffer+bytes;
  95236. b->endbit=bits;
  95237. b->endbyte=bytes;
  95238. *b->ptr&=mask[bits];
  95239. }
  95240. void oggpackB_writetrunc(oggpack_buffer *b,long bits){
  95241. long bytes=bits>>3;
  95242. bits-=bytes*8;
  95243. b->ptr=b->buffer+bytes;
  95244. b->endbit=bits;
  95245. b->endbyte=bytes;
  95246. *b->ptr&=mask8B[bits];
  95247. }
  95248. void oggpack_write(oggpack_buffer *b,unsigned long value,int bits){
  95249. if(b->endbyte+4>=b->storage){
  95250. b->buffer=(unsigned char*) _ogg_realloc(b->buffer,b->storage+BUFFER_INCREMENT);
  95251. b->storage+=BUFFER_INCREMENT;
  95252. b->ptr=b->buffer+b->endbyte;
  95253. }
  95254. value&=mask[bits];
  95255. bits+=b->endbit;
  95256. b->ptr[0]|=value<<b->endbit;
  95257. if(bits>=8){
  95258. b->ptr[1]=(unsigned char)(value>>(8-b->endbit));
  95259. if(bits>=16){
  95260. b->ptr[2]=(unsigned char)(value>>(16-b->endbit));
  95261. if(bits>=24){
  95262. b->ptr[3]=(unsigned char)(value>>(24-b->endbit));
  95263. if(bits>=32){
  95264. if(b->endbit)
  95265. b->ptr[4]=(unsigned char)(value>>(32-b->endbit));
  95266. else
  95267. b->ptr[4]=0;
  95268. }
  95269. }
  95270. }
  95271. }
  95272. b->endbyte+=bits/8;
  95273. b->ptr+=bits/8;
  95274. b->endbit=bits&7;
  95275. }
  95276. void oggpackB_write(oggpack_buffer *b,unsigned long value,int bits){
  95277. if(b->endbyte+4>=b->storage){
  95278. b->buffer=(unsigned char*) _ogg_realloc(b->buffer,b->storage+BUFFER_INCREMENT);
  95279. b->storage+=BUFFER_INCREMENT;
  95280. b->ptr=b->buffer+b->endbyte;
  95281. }
  95282. value=(value&mask[bits])<<(32-bits);
  95283. bits+=b->endbit;
  95284. b->ptr[0]|=value>>(24+b->endbit);
  95285. if(bits>=8){
  95286. b->ptr[1]=(unsigned char)(value>>(16+b->endbit));
  95287. if(bits>=16){
  95288. b->ptr[2]=(unsigned char)(value>>(8+b->endbit));
  95289. if(bits>=24){
  95290. b->ptr[3]=(unsigned char)(value>>(b->endbit));
  95291. if(bits>=32){
  95292. if(b->endbit)
  95293. b->ptr[4]=(unsigned char)(value<<(8-b->endbit));
  95294. else
  95295. b->ptr[4]=0;
  95296. }
  95297. }
  95298. }
  95299. }
  95300. b->endbyte+=bits/8;
  95301. b->ptr+=bits/8;
  95302. b->endbit=bits&7;
  95303. }
  95304. void oggpack_writealign(oggpack_buffer *b){
  95305. int bits=8-b->endbit;
  95306. if(bits<8)
  95307. oggpack_write(b,0,bits);
  95308. }
  95309. void oggpackB_writealign(oggpack_buffer *b){
  95310. int bits=8-b->endbit;
  95311. if(bits<8)
  95312. oggpackB_write(b,0,bits);
  95313. }
  95314. static void oggpack_writecopy_helper(oggpack_buffer *b,
  95315. void *source,
  95316. long bits,
  95317. void (*w)(oggpack_buffer *,
  95318. unsigned long,
  95319. int),
  95320. int msb){
  95321. unsigned char *ptr=(unsigned char *)source;
  95322. long bytes=bits/8;
  95323. bits-=bytes*8;
  95324. if(b->endbit){
  95325. int i;
  95326. for(i=0;i<bytes;i++)
  95327. w(b,(unsigned long)(ptr[i]),8);
  95328. }else{
  95329. if(b->endbyte+bytes+1>=b->storage){
  95330. b->storage=b->endbyte+bytes+BUFFER_INCREMENT;
  95331. b->buffer=(unsigned char*) _ogg_realloc(b->buffer,b->storage);
  95332. b->ptr=b->buffer+b->endbyte;
  95333. }
  95334. memmove(b->ptr,source,bytes);
  95335. b->ptr+=bytes;
  95336. b->endbyte+=bytes;
  95337. *b->ptr=0;
  95338. }
  95339. if(bits){
  95340. if(msb)
  95341. w(b,(unsigned long)(ptr[bytes]>>(8-bits)),bits);
  95342. else
  95343. w(b,(unsigned long)(ptr[bytes]),bits);
  95344. }
  95345. }
  95346. void oggpack_writecopy(oggpack_buffer *b,void *source,long bits){
  95347. oggpack_writecopy_helper(b,source,bits,oggpack_write,0);
  95348. }
  95349. void oggpackB_writecopy(oggpack_buffer *b,void *source,long bits){
  95350. oggpack_writecopy_helper(b,source,bits,oggpackB_write,1);
  95351. }
  95352. void oggpack_reset(oggpack_buffer *b){
  95353. b->ptr=b->buffer;
  95354. b->buffer[0]=0;
  95355. b->endbit=b->endbyte=0;
  95356. }
  95357. void oggpackB_reset(oggpack_buffer *b){
  95358. oggpack_reset(b);
  95359. }
  95360. void oggpack_writeclear(oggpack_buffer *b){
  95361. _ogg_free(b->buffer);
  95362. memset(b,0,sizeof(*b));
  95363. }
  95364. void oggpackB_writeclear(oggpack_buffer *b){
  95365. oggpack_writeclear(b);
  95366. }
  95367. void oggpack_readinit(oggpack_buffer *b,unsigned char *buf,int bytes){
  95368. memset(b,0,sizeof(*b));
  95369. b->buffer=b->ptr=buf;
  95370. b->storage=bytes;
  95371. }
  95372. void oggpackB_readinit(oggpack_buffer *b,unsigned char *buf,int bytes){
  95373. oggpack_readinit(b,buf,bytes);
  95374. }
  95375. long oggpack_look(oggpack_buffer *b,int bits){
  95376. unsigned long ret;
  95377. unsigned long m=mask[bits];
  95378. bits+=b->endbit;
  95379. if(b->endbyte+4>=b->storage){
  95380. if(b->endbyte*8+bits>b->storage*8)return(-1);
  95381. }
  95382. ret=b->ptr[0]>>b->endbit;
  95383. if(bits>8){
  95384. ret|=b->ptr[1]<<(8-b->endbit);
  95385. if(bits>16){
  95386. ret|=b->ptr[2]<<(16-b->endbit);
  95387. if(bits>24){
  95388. ret|=b->ptr[3]<<(24-b->endbit);
  95389. if(bits>32 && b->endbit)
  95390. ret|=b->ptr[4]<<(32-b->endbit);
  95391. }
  95392. }
  95393. }
  95394. return(m&ret);
  95395. }
  95396. long oggpackB_look(oggpack_buffer *b,int bits){
  95397. unsigned long ret;
  95398. int m=32-bits;
  95399. bits+=b->endbit;
  95400. if(b->endbyte+4>=b->storage){
  95401. if(b->endbyte*8+bits>b->storage*8)return(-1);
  95402. }
  95403. ret=b->ptr[0]<<(24+b->endbit);
  95404. if(bits>8){
  95405. ret|=b->ptr[1]<<(16+b->endbit);
  95406. if(bits>16){
  95407. ret|=b->ptr[2]<<(8+b->endbit);
  95408. if(bits>24){
  95409. ret|=b->ptr[3]<<(b->endbit);
  95410. if(bits>32 && b->endbit)
  95411. ret|=b->ptr[4]>>(8-b->endbit);
  95412. }
  95413. }
  95414. }
  95415. return ((ret&0xffffffff)>>(m>>1))>>((m+1)>>1);
  95416. }
  95417. long oggpack_look1(oggpack_buffer *b){
  95418. if(b->endbyte>=b->storage)return(-1);
  95419. return((b->ptr[0]>>b->endbit)&1);
  95420. }
  95421. long oggpackB_look1(oggpack_buffer *b){
  95422. if(b->endbyte>=b->storage)return(-1);
  95423. return((b->ptr[0]>>(7-b->endbit))&1);
  95424. }
  95425. void oggpack_adv(oggpack_buffer *b,int bits){
  95426. bits+=b->endbit;
  95427. b->ptr+=bits/8;
  95428. b->endbyte+=bits/8;
  95429. b->endbit=bits&7;
  95430. }
  95431. void oggpackB_adv(oggpack_buffer *b,int bits){
  95432. oggpack_adv(b,bits);
  95433. }
  95434. void oggpack_adv1(oggpack_buffer *b){
  95435. if(++(b->endbit)>7){
  95436. b->endbit=0;
  95437. b->ptr++;
  95438. b->endbyte++;
  95439. }
  95440. }
  95441. void oggpackB_adv1(oggpack_buffer *b){
  95442. oggpack_adv1(b);
  95443. }
  95444. long oggpack_read(oggpack_buffer *b,int bits){
  95445. long ret;
  95446. unsigned long m=mask[bits];
  95447. bits+=b->endbit;
  95448. if(b->endbyte+4>=b->storage){
  95449. ret=-1L;
  95450. if(b->endbyte*8+bits>b->storage*8)goto overflow;
  95451. }
  95452. ret=b->ptr[0]>>b->endbit;
  95453. if(bits>8){
  95454. ret|=b->ptr[1]<<(8-b->endbit);
  95455. if(bits>16){
  95456. ret|=b->ptr[2]<<(16-b->endbit);
  95457. if(bits>24){
  95458. ret|=b->ptr[3]<<(24-b->endbit);
  95459. if(bits>32 && b->endbit){
  95460. ret|=b->ptr[4]<<(32-b->endbit);
  95461. }
  95462. }
  95463. }
  95464. }
  95465. ret&=m;
  95466. overflow:
  95467. b->ptr+=bits/8;
  95468. b->endbyte+=bits/8;
  95469. b->endbit=bits&7;
  95470. return(ret);
  95471. }
  95472. long oggpackB_read(oggpack_buffer *b,int bits){
  95473. long ret;
  95474. long m=32-bits;
  95475. bits+=b->endbit;
  95476. if(b->endbyte+4>=b->storage){
  95477. ret=-1L;
  95478. if(b->endbyte*8+bits>b->storage*8)goto overflow;
  95479. }
  95480. ret=b->ptr[0]<<(24+b->endbit);
  95481. if(bits>8){
  95482. ret|=b->ptr[1]<<(16+b->endbit);
  95483. if(bits>16){
  95484. ret|=b->ptr[2]<<(8+b->endbit);
  95485. if(bits>24){
  95486. ret|=b->ptr[3]<<(b->endbit);
  95487. if(bits>32 && b->endbit)
  95488. ret|=b->ptr[4]>>(8-b->endbit);
  95489. }
  95490. }
  95491. }
  95492. ret=((ret&0xffffffffUL)>>(m>>1))>>((m+1)>>1);
  95493. overflow:
  95494. b->ptr+=bits/8;
  95495. b->endbyte+=bits/8;
  95496. b->endbit=bits&7;
  95497. return(ret);
  95498. }
  95499. long oggpack_read1(oggpack_buffer *b){
  95500. long ret;
  95501. if(b->endbyte>=b->storage){
  95502. ret=-1L;
  95503. goto overflow;
  95504. }
  95505. ret=(b->ptr[0]>>b->endbit)&1;
  95506. overflow:
  95507. b->endbit++;
  95508. if(b->endbit>7){
  95509. b->endbit=0;
  95510. b->ptr++;
  95511. b->endbyte++;
  95512. }
  95513. return(ret);
  95514. }
  95515. long oggpackB_read1(oggpack_buffer *b){
  95516. long ret;
  95517. if(b->endbyte>=b->storage){
  95518. ret=-1L;
  95519. goto overflow;
  95520. }
  95521. ret=(b->ptr[0]>>(7-b->endbit))&1;
  95522. overflow:
  95523. b->endbit++;
  95524. if(b->endbit>7){
  95525. b->endbit=0;
  95526. b->ptr++;
  95527. b->endbyte++;
  95528. }
  95529. return(ret);
  95530. }
  95531. long oggpack_bytes(oggpack_buffer *b){
  95532. return(b->endbyte+(b->endbit+7)/8);
  95533. }
  95534. long oggpack_bits(oggpack_buffer *b){
  95535. return(b->endbyte*8+b->endbit);
  95536. }
  95537. long oggpackB_bytes(oggpack_buffer *b){
  95538. return oggpack_bytes(b);
  95539. }
  95540. long oggpackB_bits(oggpack_buffer *b){
  95541. return oggpack_bits(b);
  95542. }
  95543. unsigned char *oggpack_get_buffer(oggpack_buffer *b){
  95544. return(b->buffer);
  95545. }
  95546. unsigned char *oggpackB_get_buffer(oggpack_buffer *b){
  95547. return oggpack_get_buffer(b);
  95548. }
  95549. #ifdef _V_SELFTEST
  95550. #include <stdio.h>
  95551. static int ilog(unsigned int v){
  95552. int ret=0;
  95553. while(v){
  95554. ret++;
  95555. v>>=1;
  95556. }
  95557. return(ret);
  95558. }
  95559. oggpack_buffer o;
  95560. oggpack_buffer r;
  95561. void report(char *in){
  95562. fprintf(stderr,"%s",in);
  95563. exit(1);
  95564. }
  95565. void cliptest(unsigned long *b,int vals,int bits,int *comp,int compsize){
  95566. long bytes,i;
  95567. unsigned char *buffer;
  95568. oggpack_reset(&o);
  95569. for(i=0;i<vals;i++)
  95570. oggpack_write(&o,b[i],bits?bits:ilog(b[i]));
  95571. buffer=oggpack_get_buffer(&o);
  95572. bytes=oggpack_bytes(&o);
  95573. if(bytes!=compsize)report("wrong number of bytes!\n");
  95574. for(i=0;i<bytes;i++)if(buffer[i]!=comp[i]){
  95575. for(i=0;i<bytes;i++)fprintf(stderr,"%x %x\n",(int)buffer[i],(int)comp[i]);
  95576. report("wrote incorrect value!\n");
  95577. }
  95578. oggpack_readinit(&r,buffer,bytes);
  95579. for(i=0;i<vals;i++){
  95580. int tbit=bits?bits:ilog(b[i]);
  95581. if(oggpack_look(&r,tbit)==-1)
  95582. report("out of data!\n");
  95583. if(oggpack_look(&r,tbit)!=(b[i]&mask[tbit]))
  95584. report("looked at incorrect value!\n");
  95585. if(tbit==1)
  95586. if(oggpack_look1(&r)!=(b[i]&mask[tbit]))
  95587. report("looked at single bit incorrect value!\n");
  95588. if(tbit==1){
  95589. if(oggpack_read1(&r)!=(b[i]&mask[tbit]))
  95590. report("read incorrect single bit value!\n");
  95591. }else{
  95592. if(oggpack_read(&r,tbit)!=(b[i]&mask[tbit]))
  95593. report("read incorrect value!\n");
  95594. }
  95595. }
  95596. if(oggpack_bytes(&r)!=bytes)report("leftover bytes after read!\n");
  95597. }
  95598. void cliptestB(unsigned long *b,int vals,int bits,int *comp,int compsize){
  95599. long bytes,i;
  95600. unsigned char *buffer;
  95601. oggpackB_reset(&o);
  95602. for(i=0;i<vals;i++)
  95603. oggpackB_write(&o,b[i],bits?bits:ilog(b[i]));
  95604. buffer=oggpackB_get_buffer(&o);
  95605. bytes=oggpackB_bytes(&o);
  95606. if(bytes!=compsize)report("wrong number of bytes!\n");
  95607. for(i=0;i<bytes;i++)if(buffer[i]!=comp[i]){
  95608. for(i=0;i<bytes;i++)fprintf(stderr,"%x %x\n",(int)buffer[i],(int)comp[i]);
  95609. report("wrote incorrect value!\n");
  95610. }
  95611. oggpackB_readinit(&r,buffer,bytes);
  95612. for(i=0;i<vals;i++){
  95613. int tbit=bits?bits:ilog(b[i]);
  95614. if(oggpackB_look(&r,tbit)==-1)
  95615. report("out of data!\n");
  95616. if(oggpackB_look(&r,tbit)!=(b[i]&mask[tbit]))
  95617. report("looked at incorrect value!\n");
  95618. if(tbit==1)
  95619. if(oggpackB_look1(&r)!=(b[i]&mask[tbit]))
  95620. report("looked at single bit incorrect value!\n");
  95621. if(tbit==1){
  95622. if(oggpackB_read1(&r)!=(b[i]&mask[tbit]))
  95623. report("read incorrect single bit value!\n");
  95624. }else{
  95625. if(oggpackB_read(&r,tbit)!=(b[i]&mask[tbit]))
  95626. report("read incorrect value!\n");
  95627. }
  95628. }
  95629. if(oggpackB_bytes(&r)!=bytes)report("leftover bytes after read!\n");
  95630. }
  95631. int main(void){
  95632. unsigned char *buffer;
  95633. long bytes,i;
  95634. static unsigned long testbuffer1[]=
  95635. {18,12,103948,4325,543,76,432,52,3,65,4,56,32,42,34,21,1,23,32,546,456,7,
  95636. 567,56,8,8,55,3,52,342,341,4,265,7,67,86,2199,21,7,1,5,1,4};
  95637. int test1size=43;
  95638. static unsigned long testbuffer2[]=
  95639. {216531625L,1237861823,56732452,131,3212421,12325343,34547562,12313212,
  95640. 1233432,534,5,346435231,14436467,7869299,76326614,167548585,
  95641. 85525151,0,12321,1,349528352};
  95642. int test2size=21;
  95643. static unsigned long testbuffer3[]=
  95644. {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,
  95645. 0,1,30,1,1,1,0,0,1,0,0,0,12,0,11,0,1,0,0,1};
  95646. int test3size=56;
  95647. static unsigned long large[]=
  95648. {2136531625L,2137861823,56732452,131,3212421,12325343,34547562,12313212,
  95649. 1233432,534,5,2146435231,14436467,7869299,76326614,167548585,
  95650. 85525151,0,12321,1,2146528352};
  95651. int onesize=33;
  95652. static int one[33]={146,25,44,151,195,15,153,176,233,131,196,65,85,172,47,40,
  95653. 34,242,223,136,35,222,211,86,171,50,225,135,214,75,172,
  95654. 223,4};
  95655. static int oneB[33]={150,101,131,33,203,15,204,216,105,193,156,65,84,85,222,
  95656. 8,139,145,227,126,34,55,244,171,85,100,39,195,173,18,
  95657. 245,251,128};
  95658. int twosize=6;
  95659. static int two[6]={61,255,255,251,231,29};
  95660. static int twoB[6]={247,63,255,253,249,120};
  95661. int threesize=54;
  95662. static int three[54]={169,2,232,252,91,132,156,36,89,13,123,176,144,32,254,
  95663. 142,224,85,59,121,144,79,124,23,67,90,90,216,79,23,83,
  95664. 58,135,196,61,55,129,183,54,101,100,170,37,127,126,10,
  95665. 100,52,4,14,18,86,77,1};
  95666. static int threeB[54]={206,128,42,153,57,8,183,251,13,89,36,30,32,144,183,
  95667. 130,59,240,121,59,85,223,19,228,180,134,33,107,74,98,
  95668. 233,253,196,135,63,2,110,114,50,155,90,127,37,170,104,
  95669. 200,20,254,4,58,106,176,144,0};
  95670. int foursize=38;
  95671. static int four[38]={18,6,163,252,97,194,104,131,32,1,7,82,137,42,129,11,72,
  95672. 132,60,220,112,8,196,109,64,179,86,9,137,195,208,122,169,
  95673. 28,2,133,0,1};
  95674. static int fourB[38]={36,48,102,83,243,24,52,7,4,35,132,10,145,21,2,93,2,41,
  95675. 1,219,184,16,33,184,54,149,170,132,18,30,29,98,229,67,
  95676. 129,10,4,32};
  95677. int fivesize=45;
  95678. static int five[45]={169,2,126,139,144,172,30,4,80,72,240,59,130,218,73,62,
  95679. 241,24,210,44,4,20,0,248,116,49,135,100,110,130,181,169,
  95680. 84,75,159,2,1,0,132,192,8,0,0,18,22};
  95681. static int fiveB[45]={1,84,145,111,245,100,128,8,56,36,40,71,126,78,213,226,
  95682. 124,105,12,0,133,128,0,162,233,242,67,152,77,205,77,
  95683. 172,150,169,129,79,128,0,6,4,32,0,27,9,0};
  95684. int sixsize=7;
  95685. static int six[7]={17,177,170,242,169,19,148};
  95686. static int sixB[7]={136,141,85,79,149,200,41};
  95687. oggpack_writeinit(&o);
  95688. fprintf(stderr,"\nSmall preclipped packing (LSb): ");
  95689. cliptest(testbuffer1,test1size,0,one,onesize);
  95690. fprintf(stderr,"ok.");
  95691. fprintf(stderr,"\nNull bit call (LSb): ");
  95692. cliptest(testbuffer3,test3size,0,two,twosize);
  95693. fprintf(stderr,"ok.");
  95694. fprintf(stderr,"\nLarge preclipped packing (LSb): ");
  95695. cliptest(testbuffer2,test2size,0,three,threesize);
  95696. fprintf(stderr,"ok.");
  95697. fprintf(stderr,"\n32 bit preclipped packing (LSb): ");
  95698. oggpack_reset(&o);
  95699. for(i=0;i<test2size;i++)
  95700. oggpack_write(&o,large[i],32);
  95701. buffer=oggpack_get_buffer(&o);
  95702. bytes=oggpack_bytes(&o);
  95703. oggpack_readinit(&r,buffer,bytes);
  95704. for(i=0;i<test2size;i++){
  95705. if(oggpack_look(&r,32)==-1)report("out of data. failed!");
  95706. if(oggpack_look(&r,32)!=large[i]){
  95707. fprintf(stderr,"%ld != %ld (%lx!=%lx):",oggpack_look(&r,32),large[i],
  95708. oggpack_look(&r,32),large[i]);
  95709. report("read incorrect value!\n");
  95710. }
  95711. oggpack_adv(&r,32);
  95712. }
  95713. if(oggpack_bytes(&r)!=bytes)report("leftover bytes after read!\n");
  95714. fprintf(stderr,"ok.");
  95715. fprintf(stderr,"\nSmall unclipped packing (LSb): ");
  95716. cliptest(testbuffer1,test1size,7,four,foursize);
  95717. fprintf(stderr,"ok.");
  95718. fprintf(stderr,"\nLarge unclipped packing (LSb): ");
  95719. cliptest(testbuffer2,test2size,17,five,fivesize);
  95720. fprintf(stderr,"ok.");
  95721. fprintf(stderr,"\nSingle bit unclipped packing (LSb): ");
  95722. cliptest(testbuffer3,test3size,1,six,sixsize);
  95723. fprintf(stderr,"ok.");
  95724. fprintf(stderr,"\nTesting read past end (LSb): ");
  95725. oggpack_readinit(&r,"\0\0\0\0\0\0\0\0",8);
  95726. for(i=0;i<64;i++){
  95727. if(oggpack_read(&r,1)!=0){
  95728. fprintf(stderr,"failed; got -1 prematurely.\n");
  95729. exit(1);
  95730. }
  95731. }
  95732. if(oggpack_look(&r,1)!=-1 ||
  95733. oggpack_read(&r,1)!=-1){
  95734. fprintf(stderr,"failed; read past end without -1.\n");
  95735. exit(1);
  95736. }
  95737. oggpack_readinit(&r,"\0\0\0\0\0\0\0\0",8);
  95738. if(oggpack_read(&r,30)!=0 || oggpack_read(&r,16)!=0){
  95739. fprintf(stderr,"failed 2; got -1 prematurely.\n");
  95740. exit(1);
  95741. }
  95742. if(oggpack_look(&r,18)!=0 ||
  95743. oggpack_look(&r,18)!=0){
  95744. fprintf(stderr,"failed 3; got -1 prematurely.\n");
  95745. exit(1);
  95746. }
  95747. if(oggpack_look(&r,19)!=-1 ||
  95748. oggpack_look(&r,19)!=-1){
  95749. fprintf(stderr,"failed; read past end without -1.\n");
  95750. exit(1);
  95751. }
  95752. if(oggpack_look(&r,32)!=-1 ||
  95753. oggpack_look(&r,32)!=-1){
  95754. fprintf(stderr,"failed; read past end without -1.\n");
  95755. exit(1);
  95756. }
  95757. oggpack_writeclear(&o);
  95758. fprintf(stderr,"ok.\n");
  95759. oggpackB_writeinit(&o);
  95760. fprintf(stderr,"\nSmall preclipped packing (MSb): ");
  95761. cliptestB(testbuffer1,test1size,0,oneB,onesize);
  95762. fprintf(stderr,"ok.");
  95763. fprintf(stderr,"\nNull bit call (MSb): ");
  95764. cliptestB(testbuffer3,test3size,0,twoB,twosize);
  95765. fprintf(stderr,"ok.");
  95766. fprintf(stderr,"\nLarge preclipped packing (MSb): ");
  95767. cliptestB(testbuffer2,test2size,0,threeB,threesize);
  95768. fprintf(stderr,"ok.");
  95769. fprintf(stderr,"\n32 bit preclipped packing (MSb): ");
  95770. oggpackB_reset(&o);
  95771. for(i=0;i<test2size;i++)
  95772. oggpackB_write(&o,large[i],32);
  95773. buffer=oggpackB_get_buffer(&o);
  95774. bytes=oggpackB_bytes(&o);
  95775. oggpackB_readinit(&r,buffer,bytes);
  95776. for(i=0;i<test2size;i++){
  95777. if(oggpackB_look(&r,32)==-1)report("out of data. failed!");
  95778. if(oggpackB_look(&r,32)!=large[i]){
  95779. fprintf(stderr,"%ld != %ld (%lx!=%lx):",oggpackB_look(&r,32),large[i],
  95780. oggpackB_look(&r,32),large[i]);
  95781. report("read incorrect value!\n");
  95782. }
  95783. oggpackB_adv(&r,32);
  95784. }
  95785. if(oggpackB_bytes(&r)!=bytes)report("leftover bytes after read!\n");
  95786. fprintf(stderr,"ok.");
  95787. fprintf(stderr,"\nSmall unclipped packing (MSb): ");
  95788. cliptestB(testbuffer1,test1size,7,fourB,foursize);
  95789. fprintf(stderr,"ok.");
  95790. fprintf(stderr,"\nLarge unclipped packing (MSb): ");
  95791. cliptestB(testbuffer2,test2size,17,fiveB,fivesize);
  95792. fprintf(stderr,"ok.");
  95793. fprintf(stderr,"\nSingle bit unclipped packing (MSb): ");
  95794. cliptestB(testbuffer3,test3size,1,sixB,sixsize);
  95795. fprintf(stderr,"ok.");
  95796. fprintf(stderr,"\nTesting read past end (MSb): ");
  95797. oggpackB_readinit(&r,"\0\0\0\0\0\0\0\0",8);
  95798. for(i=0;i<64;i++){
  95799. if(oggpackB_read(&r,1)!=0){
  95800. fprintf(stderr,"failed; got -1 prematurely.\n");
  95801. exit(1);
  95802. }
  95803. }
  95804. if(oggpackB_look(&r,1)!=-1 ||
  95805. oggpackB_read(&r,1)!=-1){
  95806. fprintf(stderr,"failed; read past end without -1.\n");
  95807. exit(1);
  95808. }
  95809. oggpackB_readinit(&r,"\0\0\0\0\0\0\0\0",8);
  95810. if(oggpackB_read(&r,30)!=0 || oggpackB_read(&r,16)!=0){
  95811. fprintf(stderr,"failed 2; got -1 prematurely.\n");
  95812. exit(1);
  95813. }
  95814. if(oggpackB_look(&r,18)!=0 ||
  95815. oggpackB_look(&r,18)!=0){
  95816. fprintf(stderr,"failed 3; got -1 prematurely.\n");
  95817. exit(1);
  95818. }
  95819. if(oggpackB_look(&r,19)!=-1 ||
  95820. oggpackB_look(&r,19)!=-1){
  95821. fprintf(stderr,"failed; read past end without -1.\n");
  95822. exit(1);
  95823. }
  95824. if(oggpackB_look(&r,32)!=-1 ||
  95825. oggpackB_look(&r,32)!=-1){
  95826. fprintf(stderr,"failed; read past end without -1.\n");
  95827. exit(1);
  95828. }
  95829. oggpackB_writeclear(&o);
  95830. fprintf(stderr,"ok.\n\n");
  95831. return(0);
  95832. }
  95833. #endif /* _V_SELFTEST */
  95834. #undef BUFFER_INCREMENT
  95835. #endif
  95836. /*** End of inlined file: bitwise.c ***/
  95837. /*** Start of inlined file: framing.c ***/
  95838. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  95839. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  95840. // tasks..
  95841. #if JUCE_MSVC
  95842. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  95843. #endif
  95844. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  95845. #if JUCE_USE_OGGVORBIS
  95846. #include <stdlib.h>
  95847. #include <string.h>
  95848. int ogg_page_version(ogg_page *og){
  95849. return((int)(og->header[4]));
  95850. }
  95851. int ogg_page_continued(ogg_page *og){
  95852. return((int)(og->header[5]&0x01));
  95853. }
  95854. int ogg_page_bos(ogg_page *og){
  95855. return((int)(og->header[5]&0x02));
  95856. }
  95857. int ogg_page_eos(ogg_page *og){
  95858. return((int)(og->header[5]&0x04));
  95859. }
  95860. ogg_int64_t ogg_page_granulepos(ogg_page *og){
  95861. unsigned char *page=og->header;
  95862. ogg_int64_t granulepos=page[13]&(0xff);
  95863. granulepos= (granulepos<<8)|(page[12]&0xff);
  95864. granulepos= (granulepos<<8)|(page[11]&0xff);
  95865. granulepos= (granulepos<<8)|(page[10]&0xff);
  95866. granulepos= (granulepos<<8)|(page[9]&0xff);
  95867. granulepos= (granulepos<<8)|(page[8]&0xff);
  95868. granulepos= (granulepos<<8)|(page[7]&0xff);
  95869. granulepos= (granulepos<<8)|(page[6]&0xff);
  95870. return(granulepos);
  95871. }
  95872. int ogg_page_serialno(ogg_page *og){
  95873. return(og->header[14] |
  95874. (og->header[15]<<8) |
  95875. (og->header[16]<<16) |
  95876. (og->header[17]<<24));
  95877. }
  95878. long ogg_page_pageno(ogg_page *og){
  95879. return(og->header[18] |
  95880. (og->header[19]<<8) |
  95881. (og->header[20]<<16) |
  95882. (og->header[21]<<24));
  95883. }
  95884. int ogg_page_packets(ogg_page *og){
  95885. int i,n=og->header[26],count=0;
  95886. for(i=0;i<n;i++)
  95887. if(og->header[27+i]<255)count++;
  95888. return(count);
  95889. }
  95890. #if 0
  95891. static ogg_uint32_t _ogg_crc_entry(unsigned long index){
  95892. int i;
  95893. unsigned long r;
  95894. r = index << 24;
  95895. for (i=0; i<8; i++)
  95896. if (r & 0x80000000UL)
  95897. r = (r << 1) ^ 0x04c11db7; /* The same as the ethernet generator
  95898. polynomial, although we use an
  95899. unreflected alg and an init/final
  95900. of 0, not 0xffffffff */
  95901. else
  95902. r<<=1;
  95903. return (r & 0xffffffffUL);
  95904. }
  95905. #endif
  95906. static const ogg_uint32_t crc_lookup[256]={
  95907. 0x00000000,0x04c11db7,0x09823b6e,0x0d4326d9,
  95908. 0x130476dc,0x17c56b6b,0x1a864db2,0x1e475005,
  95909. 0x2608edb8,0x22c9f00f,0x2f8ad6d6,0x2b4bcb61,
  95910. 0x350c9b64,0x31cd86d3,0x3c8ea00a,0x384fbdbd,
  95911. 0x4c11db70,0x48d0c6c7,0x4593e01e,0x4152fda9,
  95912. 0x5f15adac,0x5bd4b01b,0x569796c2,0x52568b75,
  95913. 0x6a1936c8,0x6ed82b7f,0x639b0da6,0x675a1011,
  95914. 0x791d4014,0x7ddc5da3,0x709f7b7a,0x745e66cd,
  95915. 0x9823b6e0,0x9ce2ab57,0x91a18d8e,0x95609039,
  95916. 0x8b27c03c,0x8fe6dd8b,0x82a5fb52,0x8664e6e5,
  95917. 0xbe2b5b58,0xbaea46ef,0xb7a96036,0xb3687d81,
  95918. 0xad2f2d84,0xa9ee3033,0xa4ad16ea,0xa06c0b5d,
  95919. 0xd4326d90,0xd0f37027,0xddb056fe,0xd9714b49,
  95920. 0xc7361b4c,0xc3f706fb,0xceb42022,0xca753d95,
  95921. 0xf23a8028,0xf6fb9d9f,0xfbb8bb46,0xff79a6f1,
  95922. 0xe13ef6f4,0xe5ffeb43,0xe8bccd9a,0xec7dd02d,
  95923. 0x34867077,0x30476dc0,0x3d044b19,0x39c556ae,
  95924. 0x278206ab,0x23431b1c,0x2e003dc5,0x2ac12072,
  95925. 0x128e9dcf,0x164f8078,0x1b0ca6a1,0x1fcdbb16,
  95926. 0x018aeb13,0x054bf6a4,0x0808d07d,0x0cc9cdca,
  95927. 0x7897ab07,0x7c56b6b0,0x71159069,0x75d48dde,
  95928. 0x6b93dddb,0x6f52c06c,0x6211e6b5,0x66d0fb02,
  95929. 0x5e9f46bf,0x5a5e5b08,0x571d7dd1,0x53dc6066,
  95930. 0x4d9b3063,0x495a2dd4,0x44190b0d,0x40d816ba,
  95931. 0xaca5c697,0xa864db20,0xa527fdf9,0xa1e6e04e,
  95932. 0xbfa1b04b,0xbb60adfc,0xb6238b25,0xb2e29692,
  95933. 0x8aad2b2f,0x8e6c3698,0x832f1041,0x87ee0df6,
  95934. 0x99a95df3,0x9d684044,0x902b669d,0x94ea7b2a,
  95935. 0xe0b41de7,0xe4750050,0xe9362689,0xedf73b3e,
  95936. 0xf3b06b3b,0xf771768c,0xfa325055,0xfef34de2,
  95937. 0xc6bcf05f,0xc27dede8,0xcf3ecb31,0xcbffd686,
  95938. 0xd5b88683,0xd1799b34,0xdc3abded,0xd8fba05a,
  95939. 0x690ce0ee,0x6dcdfd59,0x608edb80,0x644fc637,
  95940. 0x7a089632,0x7ec98b85,0x738aad5c,0x774bb0eb,
  95941. 0x4f040d56,0x4bc510e1,0x46863638,0x42472b8f,
  95942. 0x5c007b8a,0x58c1663d,0x558240e4,0x51435d53,
  95943. 0x251d3b9e,0x21dc2629,0x2c9f00f0,0x285e1d47,
  95944. 0x36194d42,0x32d850f5,0x3f9b762c,0x3b5a6b9b,
  95945. 0x0315d626,0x07d4cb91,0x0a97ed48,0x0e56f0ff,
  95946. 0x1011a0fa,0x14d0bd4d,0x19939b94,0x1d528623,
  95947. 0xf12f560e,0xf5ee4bb9,0xf8ad6d60,0xfc6c70d7,
  95948. 0xe22b20d2,0xe6ea3d65,0xeba91bbc,0xef68060b,
  95949. 0xd727bbb6,0xd3e6a601,0xdea580d8,0xda649d6f,
  95950. 0xc423cd6a,0xc0e2d0dd,0xcda1f604,0xc960ebb3,
  95951. 0xbd3e8d7e,0xb9ff90c9,0xb4bcb610,0xb07daba7,
  95952. 0xae3afba2,0xaafbe615,0xa7b8c0cc,0xa379dd7b,
  95953. 0x9b3660c6,0x9ff77d71,0x92b45ba8,0x9675461f,
  95954. 0x8832161a,0x8cf30bad,0x81b02d74,0x857130c3,
  95955. 0x5d8a9099,0x594b8d2e,0x5408abf7,0x50c9b640,
  95956. 0x4e8ee645,0x4a4ffbf2,0x470cdd2b,0x43cdc09c,
  95957. 0x7b827d21,0x7f436096,0x7200464f,0x76c15bf8,
  95958. 0x68860bfd,0x6c47164a,0x61043093,0x65c52d24,
  95959. 0x119b4be9,0x155a565e,0x18197087,0x1cd86d30,
  95960. 0x029f3d35,0x065e2082,0x0b1d065b,0x0fdc1bec,
  95961. 0x3793a651,0x3352bbe6,0x3e119d3f,0x3ad08088,
  95962. 0x2497d08d,0x2056cd3a,0x2d15ebe3,0x29d4f654,
  95963. 0xc5a92679,0xc1683bce,0xcc2b1d17,0xc8ea00a0,
  95964. 0xd6ad50a5,0xd26c4d12,0xdf2f6bcb,0xdbee767c,
  95965. 0xe3a1cbc1,0xe760d676,0xea23f0af,0xeee2ed18,
  95966. 0xf0a5bd1d,0xf464a0aa,0xf9278673,0xfde69bc4,
  95967. 0x89b8fd09,0x8d79e0be,0x803ac667,0x84fbdbd0,
  95968. 0x9abc8bd5,0x9e7d9662,0x933eb0bb,0x97ffad0c,
  95969. 0xafb010b1,0xab710d06,0xa6322bdf,0xa2f33668,
  95970. 0xbcb4666d,0xb8757bda,0xb5365d03,0xb1f740b4};
  95971. int ogg_stream_init(ogg_stream_state *os,int serialno){
  95972. if(os){
  95973. memset(os,0,sizeof(*os));
  95974. os->body_storage=16*1024;
  95975. os->body_data=(unsigned char*) _ogg_malloc(os->body_storage*sizeof(*os->body_data));
  95976. os->lacing_storage=1024;
  95977. os->lacing_vals=(int*) _ogg_malloc(os->lacing_storage*sizeof(*os->lacing_vals));
  95978. os->granule_vals=(ogg_int64_t*) _ogg_malloc(os->lacing_storage*sizeof(*os->granule_vals));
  95979. os->serialno=serialno;
  95980. return(0);
  95981. }
  95982. return(-1);
  95983. }
  95984. int ogg_stream_clear(ogg_stream_state *os){
  95985. if(os){
  95986. if(os->body_data)_ogg_free(os->body_data);
  95987. if(os->lacing_vals)_ogg_free(os->lacing_vals);
  95988. if(os->granule_vals)_ogg_free(os->granule_vals);
  95989. memset(os,0,sizeof(*os));
  95990. }
  95991. return(0);
  95992. }
  95993. int ogg_stream_destroy(ogg_stream_state *os){
  95994. if(os){
  95995. ogg_stream_clear(os);
  95996. _ogg_free(os);
  95997. }
  95998. return(0);
  95999. }
  96000. static void _os_body_expand(ogg_stream_state *os,int needed){
  96001. if(os->body_storage<=os->body_fill+needed){
  96002. os->body_storage+=(needed+1024);
  96003. os->body_data=(unsigned char*) _ogg_realloc(os->body_data,os->body_storage*sizeof(*os->body_data));
  96004. }
  96005. }
  96006. static void _os_lacing_expand(ogg_stream_state *os,int needed){
  96007. if(os->lacing_storage<=os->lacing_fill+needed){
  96008. os->lacing_storage+=(needed+32);
  96009. os->lacing_vals=(int*)_ogg_realloc(os->lacing_vals,os->lacing_storage*sizeof(*os->lacing_vals));
  96010. os->granule_vals=(ogg_int64_t*)_ogg_realloc(os->granule_vals,os->lacing_storage*sizeof(*os->granule_vals));
  96011. }
  96012. }
  96013. void ogg_page_checksum_set(ogg_page *og){
  96014. if(og){
  96015. ogg_uint32_t crc_reg=0;
  96016. int i;
  96017. og->header[22]=0;
  96018. og->header[23]=0;
  96019. og->header[24]=0;
  96020. og->header[25]=0;
  96021. for(i=0;i<og->header_len;i++)
  96022. crc_reg=(crc_reg<<8)^crc_lookup[((crc_reg >> 24)&0xff)^og->header[i]];
  96023. for(i=0;i<og->body_len;i++)
  96024. crc_reg=(crc_reg<<8)^crc_lookup[((crc_reg >> 24)&0xff)^og->body[i]];
  96025. og->header[22]=(unsigned char)(crc_reg&0xff);
  96026. og->header[23]=(unsigned char)((crc_reg>>8)&0xff);
  96027. og->header[24]=(unsigned char)((crc_reg>>16)&0xff);
  96028. og->header[25]=(unsigned char)((crc_reg>>24)&0xff);
  96029. }
  96030. }
  96031. int ogg_stream_packetin(ogg_stream_state *os,ogg_packet *op){
  96032. int lacing_vals=op->bytes/255+1,i;
  96033. if(os->body_returned){
  96034. os->body_fill-=os->body_returned;
  96035. if(os->body_fill)
  96036. memmove(os->body_data,os->body_data+os->body_returned,
  96037. os->body_fill);
  96038. os->body_returned=0;
  96039. }
  96040. _os_body_expand(os,op->bytes);
  96041. _os_lacing_expand(os,lacing_vals);
  96042. memcpy(os->body_data+os->body_fill,op->packet,op->bytes);
  96043. os->body_fill+=op->bytes;
  96044. for(i=0;i<lacing_vals-1;i++){
  96045. os->lacing_vals[os->lacing_fill+i]=255;
  96046. os->granule_vals[os->lacing_fill+i]=os->granulepos;
  96047. }
  96048. os->lacing_vals[os->lacing_fill+i]=(op->bytes)%255;
  96049. os->granulepos=os->granule_vals[os->lacing_fill+i]=op->granulepos;
  96050. os->lacing_vals[os->lacing_fill]|= 0x100;
  96051. os->lacing_fill+=lacing_vals;
  96052. os->packetno++;
  96053. if(op->e_o_s)os->e_o_s=1;
  96054. return(0);
  96055. }
  96056. int ogg_stream_flush(ogg_stream_state *os,ogg_page *og){
  96057. int i;
  96058. int vals=0;
  96059. int maxvals=(os->lacing_fill>255?255:os->lacing_fill);
  96060. int bytes=0;
  96061. long acc=0;
  96062. ogg_int64_t granule_pos=-1;
  96063. if(maxvals==0)return(0);
  96064. if(os->b_o_s==0){ /* 'initial header page' case */
  96065. granule_pos=0;
  96066. for(vals=0;vals<maxvals;vals++){
  96067. if((os->lacing_vals[vals]&0x0ff)<255){
  96068. vals++;
  96069. break;
  96070. }
  96071. }
  96072. }else{
  96073. for(vals=0;vals<maxvals;vals++){
  96074. if(acc>4096)break;
  96075. acc+=os->lacing_vals[vals]&0x0ff;
  96076. if((os->lacing_vals[vals]&0xff)<255)
  96077. granule_pos=os->granule_vals[vals];
  96078. }
  96079. }
  96080. memcpy(os->header,"OggS",4);
  96081. os->header[4]=0x00;
  96082. os->header[5]=0x00;
  96083. if((os->lacing_vals[0]&0x100)==0)os->header[5]|=0x01;
  96084. if(os->b_o_s==0)os->header[5]|=0x02;
  96085. if(os->e_o_s && os->lacing_fill==vals)os->header[5]|=0x04;
  96086. os->b_o_s=1;
  96087. for(i=6;i<14;i++){
  96088. os->header[i]=(unsigned char)(granule_pos&0xff);
  96089. granule_pos>>=8;
  96090. }
  96091. {
  96092. long serialno=os->serialno;
  96093. for(i=14;i<18;i++){
  96094. os->header[i]=(unsigned char)(serialno&0xff);
  96095. serialno>>=8;
  96096. }
  96097. }
  96098. if(os->pageno==-1)os->pageno=0; /* because someone called
  96099. stream_reset; this would be a
  96100. strange thing to do in an
  96101. encode stream, but it has
  96102. plausible uses */
  96103. {
  96104. long pageno=os->pageno++;
  96105. for(i=18;i<22;i++){
  96106. os->header[i]=(unsigned char)(pageno&0xff);
  96107. pageno>>=8;
  96108. }
  96109. }
  96110. os->header[22]=0;
  96111. os->header[23]=0;
  96112. os->header[24]=0;
  96113. os->header[25]=0;
  96114. os->header[26]=(unsigned char)(vals&0xff);
  96115. for(i=0;i<vals;i++)
  96116. bytes+=os->header[i+27]=(unsigned char)(os->lacing_vals[i]&0xff);
  96117. og->header=os->header;
  96118. og->header_len=os->header_fill=vals+27;
  96119. og->body=os->body_data+os->body_returned;
  96120. og->body_len=bytes;
  96121. os->lacing_fill-=vals;
  96122. memmove(os->lacing_vals,os->lacing_vals+vals,os->lacing_fill*sizeof(*os->lacing_vals));
  96123. memmove(os->granule_vals,os->granule_vals+vals,os->lacing_fill*sizeof(*os->granule_vals));
  96124. os->body_returned+=bytes;
  96125. ogg_page_checksum_set(og);
  96126. return(1);
  96127. }
  96128. int ogg_stream_pageout(ogg_stream_state *os, ogg_page *og){
  96129. if((os->e_o_s&&os->lacing_fill) || /* 'were done, now flush' case */
  96130. os->body_fill-os->body_returned > 4096 ||/* 'page nominal size' case */
  96131. os->lacing_fill>=255 || /* 'segment table full' case */
  96132. (os->lacing_fill&&!os->b_o_s)){ /* 'initial header page' case */
  96133. return(ogg_stream_flush(os,og));
  96134. }
  96135. return(0);
  96136. }
  96137. int ogg_stream_eos(ogg_stream_state *os){
  96138. return os->e_o_s;
  96139. }
  96140. int ogg_sync_init(ogg_sync_state *oy){
  96141. if(oy){
  96142. memset(oy,0,sizeof(*oy));
  96143. }
  96144. return(0);
  96145. }
  96146. int ogg_sync_clear(ogg_sync_state *oy){
  96147. if(oy){
  96148. if(oy->data)_ogg_free(oy->data);
  96149. ogg_sync_init(oy);
  96150. }
  96151. return(0);
  96152. }
  96153. int ogg_sync_destroy(ogg_sync_state *oy){
  96154. if(oy){
  96155. ogg_sync_clear(oy);
  96156. _ogg_free(oy);
  96157. }
  96158. return(0);
  96159. }
  96160. char *ogg_sync_buffer(ogg_sync_state *oy, long size){
  96161. if(oy->returned){
  96162. oy->fill-=oy->returned;
  96163. if(oy->fill>0)
  96164. memmove(oy->data,oy->data+oy->returned,oy->fill);
  96165. oy->returned=0;
  96166. }
  96167. if(size>oy->storage-oy->fill){
  96168. long newsize=size+oy->fill+4096; /* an extra page to be nice */
  96169. if(oy->data)
  96170. oy->data=(unsigned char*) _ogg_realloc(oy->data,newsize);
  96171. else
  96172. oy->data=(unsigned char*) _ogg_malloc(newsize);
  96173. oy->storage=newsize;
  96174. }
  96175. return((char *)oy->data+oy->fill);
  96176. }
  96177. int ogg_sync_wrote(ogg_sync_state *oy, long bytes){
  96178. if(oy->fill+bytes>oy->storage)return(-1);
  96179. oy->fill+=bytes;
  96180. return(0);
  96181. }
  96182. long ogg_sync_pageseek(ogg_sync_state *oy,ogg_page *og){
  96183. unsigned char *page=oy->data+oy->returned;
  96184. unsigned char *next;
  96185. long bytes=oy->fill-oy->returned;
  96186. if(oy->headerbytes==0){
  96187. int headerbytes,i;
  96188. if(bytes<27)return(0); /* not enough for a header */
  96189. if(memcmp(page,"OggS",4))goto sync_fail;
  96190. headerbytes=page[26]+27;
  96191. if(bytes<headerbytes)return(0); /* not enough for header + seg table */
  96192. for(i=0;i<page[26];i++)
  96193. oy->bodybytes+=page[27+i];
  96194. oy->headerbytes=headerbytes;
  96195. }
  96196. if(oy->bodybytes+oy->headerbytes>bytes)return(0);
  96197. {
  96198. char chksum[4];
  96199. ogg_page log;
  96200. memcpy(chksum,page+22,4);
  96201. memset(page+22,0,4);
  96202. log.header=page;
  96203. log.header_len=oy->headerbytes;
  96204. log.body=page+oy->headerbytes;
  96205. log.body_len=oy->bodybytes;
  96206. ogg_page_checksum_set(&log);
  96207. if(memcmp(chksum,page+22,4)){
  96208. memcpy(page+22,chksum,4);
  96209. goto sync_fail;
  96210. }
  96211. }
  96212. {
  96213. unsigned char *page=oy->data+oy->returned;
  96214. long bytes;
  96215. if(og){
  96216. og->header=page;
  96217. og->header_len=oy->headerbytes;
  96218. og->body=page+oy->headerbytes;
  96219. og->body_len=oy->bodybytes;
  96220. }
  96221. oy->unsynced=0;
  96222. oy->returned+=(bytes=oy->headerbytes+oy->bodybytes);
  96223. oy->headerbytes=0;
  96224. oy->bodybytes=0;
  96225. return(bytes);
  96226. }
  96227. sync_fail:
  96228. oy->headerbytes=0;
  96229. oy->bodybytes=0;
  96230. next=(unsigned char*)memchr(page+1,'O',bytes-1);
  96231. if(!next)
  96232. next=oy->data+oy->fill;
  96233. oy->returned=next-oy->data;
  96234. return(-(next-page));
  96235. }
  96236. int ogg_sync_pageout(ogg_sync_state *oy, ogg_page *og){
  96237. for(;;){
  96238. long ret=ogg_sync_pageseek(oy,og);
  96239. if(ret>0){
  96240. return(1);
  96241. }
  96242. if(ret==0){
  96243. return(0);
  96244. }
  96245. if(!oy->unsynced){
  96246. oy->unsynced=1;
  96247. return(-1);
  96248. }
  96249. }
  96250. }
  96251. int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og){
  96252. unsigned char *header=og->header;
  96253. unsigned char *body=og->body;
  96254. long bodysize=og->body_len;
  96255. int segptr=0;
  96256. int version=ogg_page_version(og);
  96257. int continued=ogg_page_continued(og);
  96258. int bos=ogg_page_bos(og);
  96259. int eos=ogg_page_eos(og);
  96260. ogg_int64_t granulepos=ogg_page_granulepos(og);
  96261. int serialno=ogg_page_serialno(og);
  96262. long pageno=ogg_page_pageno(og);
  96263. int segments=header[26];
  96264. {
  96265. long lr=os->lacing_returned;
  96266. long br=os->body_returned;
  96267. if(br){
  96268. os->body_fill-=br;
  96269. if(os->body_fill)
  96270. memmove(os->body_data,os->body_data+br,os->body_fill);
  96271. os->body_returned=0;
  96272. }
  96273. if(lr){
  96274. if(os->lacing_fill-lr){
  96275. memmove(os->lacing_vals,os->lacing_vals+lr,
  96276. (os->lacing_fill-lr)*sizeof(*os->lacing_vals));
  96277. memmove(os->granule_vals,os->granule_vals+lr,
  96278. (os->lacing_fill-lr)*sizeof(*os->granule_vals));
  96279. }
  96280. os->lacing_fill-=lr;
  96281. os->lacing_packet-=lr;
  96282. os->lacing_returned=0;
  96283. }
  96284. }
  96285. if(serialno!=os->serialno)return(-1);
  96286. if(version>0)return(-1);
  96287. _os_lacing_expand(os,segments+1);
  96288. if(pageno!=os->pageno){
  96289. int i;
  96290. for(i=os->lacing_packet;i<os->lacing_fill;i++)
  96291. os->body_fill-=os->lacing_vals[i]&0xff;
  96292. os->lacing_fill=os->lacing_packet;
  96293. if(os->pageno!=-1){
  96294. os->lacing_vals[os->lacing_fill++]=0x400;
  96295. os->lacing_packet++;
  96296. }
  96297. }
  96298. if(continued){
  96299. if(os->lacing_fill<1 ||
  96300. os->lacing_vals[os->lacing_fill-1]==0x400){
  96301. bos=0;
  96302. for(;segptr<segments;segptr++){
  96303. int val=header[27+segptr];
  96304. body+=val;
  96305. bodysize-=val;
  96306. if(val<255){
  96307. segptr++;
  96308. break;
  96309. }
  96310. }
  96311. }
  96312. }
  96313. if(bodysize){
  96314. _os_body_expand(os,bodysize);
  96315. memcpy(os->body_data+os->body_fill,body,bodysize);
  96316. os->body_fill+=bodysize;
  96317. }
  96318. {
  96319. int saved=-1;
  96320. while(segptr<segments){
  96321. int val=header[27+segptr];
  96322. os->lacing_vals[os->lacing_fill]=val;
  96323. os->granule_vals[os->lacing_fill]=-1;
  96324. if(bos){
  96325. os->lacing_vals[os->lacing_fill]|=0x100;
  96326. bos=0;
  96327. }
  96328. if(val<255)saved=os->lacing_fill;
  96329. os->lacing_fill++;
  96330. segptr++;
  96331. if(val<255)os->lacing_packet=os->lacing_fill;
  96332. }
  96333. if(saved!=-1){
  96334. os->granule_vals[saved]=granulepos;
  96335. }
  96336. }
  96337. if(eos){
  96338. os->e_o_s=1;
  96339. if(os->lacing_fill>0)
  96340. os->lacing_vals[os->lacing_fill-1]|=0x200;
  96341. }
  96342. os->pageno=pageno+1;
  96343. return(0);
  96344. }
  96345. int ogg_sync_reset(ogg_sync_state *oy){
  96346. oy->fill=0;
  96347. oy->returned=0;
  96348. oy->unsynced=0;
  96349. oy->headerbytes=0;
  96350. oy->bodybytes=0;
  96351. return(0);
  96352. }
  96353. int ogg_stream_reset(ogg_stream_state *os){
  96354. os->body_fill=0;
  96355. os->body_returned=0;
  96356. os->lacing_fill=0;
  96357. os->lacing_packet=0;
  96358. os->lacing_returned=0;
  96359. os->header_fill=0;
  96360. os->e_o_s=0;
  96361. os->b_o_s=0;
  96362. os->pageno=-1;
  96363. os->packetno=0;
  96364. os->granulepos=0;
  96365. return(0);
  96366. }
  96367. int ogg_stream_reset_serialno(ogg_stream_state *os,int serialno){
  96368. ogg_stream_reset(os);
  96369. os->serialno=serialno;
  96370. return(0);
  96371. }
  96372. static int _packetout(ogg_stream_state *os,ogg_packet *op,int adv){
  96373. int ptr=os->lacing_returned;
  96374. if(os->lacing_packet<=ptr)return(0);
  96375. if(os->lacing_vals[ptr]&0x400){
  96376. os->lacing_returned++;
  96377. os->packetno++;
  96378. return(-1);
  96379. }
  96380. if(!op && !adv)return(1); /* just using peek as an inexpensive way
  96381. to ask if there's a whole packet
  96382. waiting */
  96383. {
  96384. int size=os->lacing_vals[ptr]&0xff;
  96385. int bytes=size;
  96386. int eos=os->lacing_vals[ptr]&0x200; /* last packet of the stream? */
  96387. int bos=os->lacing_vals[ptr]&0x100; /* first packet of the stream? */
  96388. while(size==255){
  96389. int val=os->lacing_vals[++ptr];
  96390. size=val&0xff;
  96391. if(val&0x200)eos=0x200;
  96392. bytes+=size;
  96393. }
  96394. if(op){
  96395. op->e_o_s=eos;
  96396. op->b_o_s=bos;
  96397. op->packet=os->body_data+os->body_returned;
  96398. op->packetno=os->packetno;
  96399. op->granulepos=os->granule_vals[ptr];
  96400. op->bytes=bytes;
  96401. }
  96402. if(adv){
  96403. os->body_returned+=bytes;
  96404. os->lacing_returned=ptr+1;
  96405. os->packetno++;
  96406. }
  96407. }
  96408. return(1);
  96409. }
  96410. int ogg_stream_packetout(ogg_stream_state *os,ogg_packet *op){
  96411. return _packetout(os,op,1);
  96412. }
  96413. int ogg_stream_packetpeek(ogg_stream_state *os,ogg_packet *op){
  96414. return _packetout(os,op,0);
  96415. }
  96416. void ogg_packet_clear(ogg_packet *op) {
  96417. _ogg_free(op->packet);
  96418. memset(op, 0, sizeof(*op));
  96419. }
  96420. #ifdef _V_SELFTEST
  96421. #include <stdio.h>
  96422. ogg_stream_state os_en, os_de;
  96423. ogg_sync_state oy;
  96424. void checkpacket(ogg_packet *op,int len, int no, int pos){
  96425. long j;
  96426. static int sequence=0;
  96427. static int lastno=0;
  96428. if(op->bytes!=len){
  96429. fprintf(stderr,"incorrect packet length!\n");
  96430. exit(1);
  96431. }
  96432. if(op->granulepos!=pos){
  96433. fprintf(stderr,"incorrect packet position!\n");
  96434. exit(1);
  96435. }
  96436. if(no==0){
  96437. sequence=0;
  96438. }else{
  96439. sequence++;
  96440. if(no>lastno+1)
  96441. sequence++;
  96442. }
  96443. lastno=no;
  96444. if(op->packetno!=sequence){
  96445. fprintf(stderr,"incorrect packet sequence %ld != %d\n",
  96446. (long)(op->packetno),sequence);
  96447. exit(1);
  96448. }
  96449. for(j=0;j<op->bytes;j++)
  96450. if(op->packet[j]!=((j+no)&0xff)){
  96451. fprintf(stderr,"body data mismatch (1) at pos %ld: %x!=%lx!\n\n",
  96452. j,op->packet[j],(j+no)&0xff);
  96453. exit(1);
  96454. }
  96455. }
  96456. void check_page(unsigned char *data,const int *header,ogg_page *og){
  96457. long j;
  96458. for(j=0;j<og->body_len;j++)
  96459. if(og->body[j]!=data[j]){
  96460. fprintf(stderr,"body data mismatch (2) at pos %ld: %x!=%x!\n\n",
  96461. j,data[j],og->body[j]);
  96462. exit(1);
  96463. }
  96464. for(j=0;j<og->header_len;j++){
  96465. if(og->header[j]!=header[j]){
  96466. fprintf(stderr,"header content mismatch at pos %ld:\n",j);
  96467. for(j=0;j<header[26]+27;j++)
  96468. fprintf(stderr," (%ld)%02x:%02x",j,header[j],og->header[j]);
  96469. fprintf(stderr,"\n");
  96470. exit(1);
  96471. }
  96472. }
  96473. if(og->header_len!=header[26]+27){
  96474. fprintf(stderr,"header length incorrect! (%ld!=%d)\n",
  96475. og->header_len,header[26]+27);
  96476. exit(1);
  96477. }
  96478. }
  96479. void print_header(ogg_page *og){
  96480. int j;
  96481. fprintf(stderr,"\nHEADER:\n");
  96482. fprintf(stderr," capture: %c %c %c %c version: %d flags: %x\n",
  96483. og->header[0],og->header[1],og->header[2],og->header[3],
  96484. (int)og->header[4],(int)og->header[5]);
  96485. fprintf(stderr," granulepos: %d serialno: %d pageno: %ld\n",
  96486. (og->header[9]<<24)|(og->header[8]<<16)|
  96487. (og->header[7]<<8)|og->header[6],
  96488. (og->header[17]<<24)|(og->header[16]<<16)|
  96489. (og->header[15]<<8)|og->header[14],
  96490. ((long)(og->header[21])<<24)|(og->header[20]<<16)|
  96491. (og->header[19]<<8)|og->header[18]);
  96492. fprintf(stderr," checksum: %02x:%02x:%02x:%02x\n segments: %d (",
  96493. (int)og->header[22],(int)og->header[23],
  96494. (int)og->header[24],(int)og->header[25],
  96495. (int)og->header[26]);
  96496. for(j=27;j<og->header_len;j++)
  96497. fprintf(stderr,"%d ",(int)og->header[j]);
  96498. fprintf(stderr,")\n\n");
  96499. }
  96500. void copy_page(ogg_page *og){
  96501. unsigned char *temp=_ogg_malloc(og->header_len);
  96502. memcpy(temp,og->header,og->header_len);
  96503. og->header=temp;
  96504. temp=_ogg_malloc(og->body_len);
  96505. memcpy(temp,og->body,og->body_len);
  96506. og->body=temp;
  96507. }
  96508. void free_page(ogg_page *og){
  96509. _ogg_free (og->header);
  96510. _ogg_free (og->body);
  96511. }
  96512. void error(void){
  96513. fprintf(stderr,"error!\n");
  96514. exit(1);
  96515. }
  96516. const int head1_0[] = {0x4f,0x67,0x67,0x53,0,0x06,
  96517. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96518. 0x01,0x02,0x03,0x04,0,0,0,0,
  96519. 0x15,0xed,0xec,0x91,
  96520. 1,
  96521. 17};
  96522. const int head1_1[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96523. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96524. 0x01,0x02,0x03,0x04,0,0,0,0,
  96525. 0x59,0x10,0x6c,0x2c,
  96526. 1,
  96527. 17};
  96528. const int head2_1[] = {0x4f,0x67,0x67,0x53,0,0x04,
  96529. 0x07,0x18,0x00,0x00,0x00,0x00,0x00,0x00,
  96530. 0x01,0x02,0x03,0x04,1,0,0,0,
  96531. 0x89,0x33,0x85,0xce,
  96532. 13,
  96533. 254,255,0,255,1,255,245,255,255,0,
  96534. 255,255,90};
  96535. const int head1_2[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96536. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96537. 0x01,0x02,0x03,0x04,0,0,0,0,
  96538. 0xff,0x7b,0x23,0x17,
  96539. 1,
  96540. 0};
  96541. const int head2_2[] = {0x4f,0x67,0x67,0x53,0,0x04,
  96542. 0x07,0x28,0x00,0x00,0x00,0x00,0x00,0x00,
  96543. 0x01,0x02,0x03,0x04,1,0,0,0,
  96544. 0x5c,0x3f,0x66,0xcb,
  96545. 17,
  96546. 17,254,255,0,0,255,1,0,255,245,255,255,0,
  96547. 255,255,90,0};
  96548. const int head1_3[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96549. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96550. 0x01,0x02,0x03,0x04,0,0,0,0,
  96551. 0x01,0x27,0x31,0xaa,
  96552. 18,
  96553. 255,255,255,255,255,255,255,255,
  96554. 255,255,255,255,255,255,255,255,255,10};
  96555. const int head2_3[] = {0x4f,0x67,0x67,0x53,0,0x04,
  96556. 0x07,0x08,0x00,0x00,0x00,0x00,0x00,0x00,
  96557. 0x01,0x02,0x03,0x04,1,0,0,0,
  96558. 0x7f,0x4e,0x8a,0xd2,
  96559. 4,
  96560. 255,4,255,0};
  96561. const int head1_4[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96562. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96563. 0x01,0x02,0x03,0x04,0,0,0,0,
  96564. 0xff,0x7b,0x23,0x17,
  96565. 1,
  96566. 0};
  96567. const int head2_4[] = {0x4f,0x67,0x67,0x53,0,0x00,
  96568. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  96569. 0x01,0x02,0x03,0x04,1,0,0,0,
  96570. 0x54,0x05,0x51,0xc8,
  96571. 17,
  96572. 255,255,255,255,255,255,255,255,
  96573. 255,255,255,255,255,255,255,255,255};
  96574. const int head3_4[] = {0x4f,0x67,0x67,0x53,0,0x05,
  96575. 0x07,0x0c,0x00,0x00,0x00,0x00,0x00,0x00,
  96576. 0x01,0x02,0x03,0x04,2,0,0,0,
  96577. 0xc8,0xc3,0xcb,0xed,
  96578. 5,
  96579. 10,255,4,255,0};
  96580. const int head1_5[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96581. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96582. 0x01,0x02,0x03,0x04,0,0,0,0,
  96583. 0xff,0x7b,0x23,0x17,
  96584. 1,
  96585. 0};
  96586. const int head2_5[] = {0x4f,0x67,0x67,0x53,0,0x00,
  96587. 0x07,0xfc,0x03,0x00,0x00,0x00,0x00,0x00,
  96588. 0x01,0x02,0x03,0x04,1,0,0,0,
  96589. 0xed,0x2a,0x2e,0xa7,
  96590. 255,
  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,10,
  96594. 10,10,10,10,10,10,10,10,
  96595. 10,10,10,10,10,10,10,10,
  96596. 10,10,10,10,10,10,10,10,
  96597. 10,10,10,10,10,10,10,10,
  96598. 10,10,10,10,10,10,10,10,
  96599. 10,10,10,10,10,10,10,10,
  96600. 10,10,10,10,10,10,10,10,
  96601. 10,10,10,10,10,10,10,10,
  96602. 10,10,10,10,10,10,10,10,
  96603. 10,10,10,10,10,10,10,10,
  96604. 10,10,10,10,10,10,10,10,
  96605. 10,10,10,10,10,10,10,10,
  96606. 10,10,10,10,10,10,10,10,
  96607. 10,10,10,10,10,10,10,10,
  96608. 10,10,10,10,10,10,10,10,
  96609. 10,10,10,10,10,10,10,10,
  96610. 10,10,10,10,10,10,10,10,
  96611. 10,10,10,10,10,10,10,10,
  96612. 10,10,10,10,10,10,10,10,
  96613. 10,10,10,10,10,10,10,10,
  96614. 10,10,10,10,10,10,10,10,
  96615. 10,10,10,10,10,10,10,10,
  96616. 10,10,10,10,10,10,10,10,
  96617. 10,10,10,10,10,10,10,10,
  96618. 10,10,10,10,10,10,10,10,
  96619. 10,10,10,10,10,10,10,10,
  96620. 10,10,10,10,10,10,10,10,
  96621. 10,10,10,10,10,10,10,10,
  96622. 10,10,10,10,10,10,10};
  96623. const int head3_5[] = {0x4f,0x67,0x67,0x53,0,0x04,
  96624. 0x07,0x00,0x04,0x00,0x00,0x00,0x00,0x00,
  96625. 0x01,0x02,0x03,0x04,2,0,0,0,
  96626. 0x6c,0x3b,0x82,0x3d,
  96627. 1,
  96628. 50};
  96629. const int head1_6[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96630. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96631. 0x01,0x02,0x03,0x04,0,0,0,0,
  96632. 0xff,0x7b,0x23,0x17,
  96633. 1,
  96634. 0};
  96635. const int head2_6[] = {0x4f,0x67,0x67,0x53,0,0x00,
  96636. 0x07,0x04,0x00,0x00,0x00,0x00,0x00,0x00,
  96637. 0x01,0x02,0x03,0x04,1,0,0,0,
  96638. 0x3c,0xd9,0x4d,0x3f,
  96639. 17,
  96640. 100,255,255,255,255,255,255,255,255,
  96641. 255,255,255,255,255,255,255,255};
  96642. const int head3_6[] = {0x4f,0x67,0x67,0x53,0,0x01,
  96643. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  96644. 0x01,0x02,0x03,0x04,2,0,0,0,
  96645. 0x01,0xd2,0xe5,0xe5,
  96646. 17,
  96647. 255,255,255,255,255,255,255,255,
  96648. 255,255,255,255,255,255,255,255,255};
  96649. const int head4_6[] = {0x4f,0x67,0x67,0x53,0,0x05,
  96650. 0x07,0x10,0x00,0x00,0x00,0x00,0x00,0x00,
  96651. 0x01,0x02,0x03,0x04,3,0,0,0,
  96652. 0xef,0xdd,0x88,0xde,
  96653. 7,
  96654. 255,255,75,255,4,255,0};
  96655. const int head1_7[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96656. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96657. 0x01,0x02,0x03,0x04,0,0,0,0,
  96658. 0xff,0x7b,0x23,0x17,
  96659. 1,
  96660. 0};
  96661. const int head2_7[] = {0x4f,0x67,0x67,0x53,0,0x00,
  96662. 0x07,0x04,0x00,0x00,0x00,0x00,0x00,0x00,
  96663. 0x01,0x02,0x03,0x04,1,0,0,0,
  96664. 0x3c,0xd9,0x4d,0x3f,
  96665. 17,
  96666. 100,255,255,255,255,255,255,255,255,
  96667. 255,255,255,255,255,255,255,255};
  96668. const int head3_7[] = {0x4f,0x67,0x67,0x53,0,0x05,
  96669. 0x07,0x08,0x00,0x00,0x00,0x00,0x00,0x00,
  96670. 0x01,0x02,0x03,0x04,2,0,0,0,
  96671. 0xd4,0xe0,0x60,0xe5,
  96672. 1,0};
  96673. void test_pack(const int *pl, const int **headers, int byteskip,
  96674. int pageskip, int packetskip){
  96675. unsigned char *data=_ogg_malloc(1024*1024); /* for scripted test cases only */
  96676. long inptr=0;
  96677. long outptr=0;
  96678. long deptr=0;
  96679. long depacket=0;
  96680. long granule_pos=7,pageno=0;
  96681. int i,j,packets,pageout=pageskip;
  96682. int eosflag=0;
  96683. int bosflag=0;
  96684. int byteskipcount=0;
  96685. ogg_stream_reset(&os_en);
  96686. ogg_stream_reset(&os_de);
  96687. ogg_sync_reset(&oy);
  96688. for(packets=0;packets<packetskip;packets++)
  96689. depacket+=pl[packets];
  96690. for(packets=0;;packets++)if(pl[packets]==-1)break;
  96691. for(i=0;i<packets;i++){
  96692. ogg_packet op;
  96693. int len=pl[i];
  96694. op.packet=data+inptr;
  96695. op.bytes=len;
  96696. op.e_o_s=(pl[i+1]<0?1:0);
  96697. op.granulepos=granule_pos;
  96698. granule_pos+=1024;
  96699. for(j=0;j<len;j++)data[inptr++]=i+j;
  96700. ogg_stream_packetin(&os_en,&op);
  96701. {
  96702. ogg_page og;
  96703. while(ogg_stream_pageout(&os_en,&og)){
  96704. fprintf(stderr,"%ld, ",pageno);
  96705. if(headers[pageno]==NULL){
  96706. fprintf(stderr,"coded too many pages!\n");
  96707. exit(1);
  96708. }
  96709. check_page(data+outptr,headers[pageno],&og);
  96710. outptr+=og.body_len;
  96711. pageno++;
  96712. if(pageskip){
  96713. bosflag=1;
  96714. pageskip--;
  96715. deptr+=og.body_len;
  96716. }
  96717. {
  96718. ogg_page og_de;
  96719. ogg_packet op_de,op_de2;
  96720. char *buf=ogg_sync_buffer(&oy,og.header_len+og.body_len);
  96721. char *next=buf;
  96722. byteskipcount+=og.header_len;
  96723. if(byteskipcount>byteskip){
  96724. memcpy(next,og.header,byteskipcount-byteskip);
  96725. next+=byteskipcount-byteskip;
  96726. byteskipcount=byteskip;
  96727. }
  96728. byteskipcount+=og.body_len;
  96729. if(byteskipcount>byteskip){
  96730. memcpy(next,og.body,byteskipcount-byteskip);
  96731. next+=byteskipcount-byteskip;
  96732. byteskipcount=byteskip;
  96733. }
  96734. ogg_sync_wrote(&oy,next-buf);
  96735. while(1){
  96736. int ret=ogg_sync_pageout(&oy,&og_de);
  96737. if(ret==0)break;
  96738. if(ret<0)continue;
  96739. fprintf(stderr,"(%ld), ",pageout);
  96740. check_page(data+deptr,headers[pageout],&og_de);
  96741. deptr+=og_de.body_len;
  96742. pageout++;
  96743. ogg_stream_pagein(&os_de,&og_de);
  96744. while(ogg_stream_packetpeek(&os_de,&op_de2)>0){
  96745. ogg_stream_packetpeek(&os_de,NULL);
  96746. ogg_stream_packetout(&os_de,&op_de); /* just catching them all */
  96747. if(memcmp(&op_de,&op_de2,sizeof(op_de))){
  96748. fprintf(stderr,"packetout != packetpeek! pos=%ld\n",
  96749. depacket);
  96750. exit(1);
  96751. }
  96752. if(memcmp(data+depacket,op_de.packet,op_de.bytes)){
  96753. fprintf(stderr,"packet data mismatch in decode! pos=%ld\n",
  96754. depacket);
  96755. exit(1);
  96756. }
  96757. if(bosflag==0 && op_de.b_o_s==0){
  96758. fprintf(stderr,"b_o_s flag not set on packet!\n");
  96759. exit(1);
  96760. }
  96761. if(bosflag && op_de.b_o_s){
  96762. fprintf(stderr,"b_o_s flag incorrectly set on packet!\n");
  96763. exit(1);
  96764. }
  96765. bosflag=1;
  96766. depacket+=op_de.bytes;
  96767. if(eosflag){
  96768. fprintf(stderr,"Multiple decoded packets with eos flag!\n");
  96769. exit(1);
  96770. }
  96771. if(op_de.e_o_s)eosflag=1;
  96772. if(op_de.granulepos!=-1){
  96773. fprintf(stderr," granule:%ld ",(long)op_de.granulepos);
  96774. }
  96775. }
  96776. }
  96777. }
  96778. }
  96779. }
  96780. }
  96781. _ogg_free(data);
  96782. if(headers[pageno]!=NULL){
  96783. fprintf(stderr,"did not write last page!\n");
  96784. exit(1);
  96785. }
  96786. if(headers[pageout]!=NULL){
  96787. fprintf(stderr,"did not decode last page!\n");
  96788. exit(1);
  96789. }
  96790. if(inptr!=outptr){
  96791. fprintf(stderr,"encoded page data incomplete!\n");
  96792. exit(1);
  96793. }
  96794. if(inptr!=deptr){
  96795. fprintf(stderr,"decoded page data incomplete!\n");
  96796. exit(1);
  96797. }
  96798. if(inptr!=depacket){
  96799. fprintf(stderr,"decoded packet data incomplete!\n");
  96800. exit(1);
  96801. }
  96802. if(!eosflag){
  96803. fprintf(stderr,"Never got a packet with EOS set!\n");
  96804. exit(1);
  96805. }
  96806. fprintf(stderr,"ok.\n");
  96807. }
  96808. int main(void){
  96809. ogg_stream_init(&os_en,0x04030201);
  96810. ogg_stream_init(&os_de,0x04030201);
  96811. ogg_sync_init(&oy);
  96812. {
  96813. const int packets[]={17, -1};
  96814. const int *headret[]={head1_0,NULL};
  96815. fprintf(stderr,"testing single page encoding... ");
  96816. test_pack(packets,headret,0,0,0);
  96817. }
  96818. {
  96819. const int packets[]={17, 254, 255, 256, 500, 510, 600, -1};
  96820. const int *headret[]={head1_1,head2_1,NULL};
  96821. fprintf(stderr,"testing basic page encoding... ");
  96822. test_pack(packets,headret,0,0,0);
  96823. }
  96824. {
  96825. const int packets[]={0,17, 254, 255, 0, 256, 0, 500, 510, 600, 0, -1};
  96826. const int *headret[]={head1_2,head2_2,NULL};
  96827. fprintf(stderr,"testing basic nil packets... ");
  96828. test_pack(packets,headret,0,0,0);
  96829. }
  96830. {
  96831. const int packets[]={4345,259,255,-1};
  96832. const int *headret[]={head1_3,head2_3,NULL};
  96833. fprintf(stderr,"testing initial-packet lacing > 4k... ");
  96834. test_pack(packets,headret,0,0,0);
  96835. }
  96836. {
  96837. const int packets[]={0,4345,259,255,-1};
  96838. const int *headret[]={head1_4,head2_4,head3_4,NULL};
  96839. fprintf(stderr,"testing single packet page span... ");
  96840. test_pack(packets,headret,0,0,0);
  96841. }
  96842. {
  96843. const int packets[]={0,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,10,
  96846. 10,10,10,10,10,10,10,10,
  96847. 10,10,10,10,10,10,10,10,
  96848. 10,10,10,10,10,10,10,10,
  96849. 10,10,10,10,10,10,10,10,
  96850. 10,10,10,10,10,10,10,10,
  96851. 10,10,10,10,10,10,10,10,
  96852. 10,10,10,10,10,10,10,10,
  96853. 10,10,10,10,10,10,10,10,
  96854. 10,10,10,10,10,10,10,10,
  96855. 10,10,10,10,10,10,10,10,
  96856. 10,10,10,10,10,10,10,10,
  96857. 10,10,10,10,10,10,10,10,
  96858. 10,10,10,10,10,10,10,10,
  96859. 10,10,10,10,10,10,10,10,
  96860. 10,10,10,10,10,10,10,10,
  96861. 10,10,10,10,10,10,10,10,
  96862. 10,10,10,10,10,10,10,10,
  96863. 10,10,10,10,10,10,10,10,
  96864. 10,10,10,10,10,10,10,10,
  96865. 10,10,10,10,10,10,10,10,
  96866. 10,10,10,10,10,10,10,10,
  96867. 10,10,10,10,10,10,10,10,
  96868. 10,10,10,10,10,10,10,10,
  96869. 10,10,10,10,10,10,10,10,
  96870. 10,10,10,10,10,10,10,10,
  96871. 10,10,10,10,10,10,10,10,
  96872. 10,10,10,10,10,10,10,10,
  96873. 10,10,10,10,10,10,10,10,
  96874. 10,10,10,10,10,10,10,50,-1};
  96875. const int *headret[]={head1_5,head2_5,head3_5,NULL};
  96876. fprintf(stderr,"testing max packet segments... ");
  96877. test_pack(packets,headret,0,0,0);
  96878. }
  96879. {
  96880. const int packets[]={0,100,9000,259,255,-1};
  96881. const int *headret[]={head1_6,head2_6,head3_6,head4_6,NULL};
  96882. fprintf(stderr,"testing very large packets... ");
  96883. test_pack(packets,headret,0,0,0);
  96884. }
  96885. {
  96886. const int packets[]={0,100,9000,259,255,-1};
  96887. const int *headret[]={head1_6,head2_6,head3_6,head4_6,NULL};
  96888. fprintf(stderr,"testing continuation resync in very large packets... ");
  96889. test_pack(packets,headret,100,2,3);
  96890. }
  96891. {
  96892. const int packets[]={0,100,4080,-1};
  96893. const int *headret[]={head1_7,head2_7,head3_7,NULL};
  96894. fprintf(stderr,"testing zero data page (1 nil packet)... ");
  96895. test_pack(packets,headret,0,0,0);
  96896. }
  96897. {
  96898. unsigned char *data=_ogg_malloc(1024*1024);
  96899. int pl[]={0,100,4079,2956,2057,76,34,912,0,234,1000,1000,1000,300,-1};
  96900. int inptr=0,i,j;
  96901. ogg_page og[5];
  96902. ogg_stream_reset(&os_en);
  96903. for(i=0;pl[i]!=-1;i++){
  96904. ogg_packet op;
  96905. int len=pl[i];
  96906. op.packet=data+inptr;
  96907. op.bytes=len;
  96908. op.e_o_s=(pl[i+1]<0?1:0);
  96909. op.granulepos=(i+1)*1000;
  96910. for(j=0;j<len;j++)data[inptr++]=i+j;
  96911. ogg_stream_packetin(&os_en,&op);
  96912. }
  96913. _ogg_free(data);
  96914. for(i=0;i<5;i++){
  96915. if(ogg_stream_pageout(&os_en,&og[i])==0){
  96916. fprintf(stderr,"Too few pages output building sync tests!\n");
  96917. exit(1);
  96918. }
  96919. copy_page(&og[i]);
  96920. }
  96921. {
  96922. ogg_page temp;
  96923. ogg_packet test;
  96924. fprintf(stderr,"Testing loss of pages... ");
  96925. ogg_sync_reset(&oy);
  96926. ogg_stream_reset(&os_de);
  96927. for(i=0;i<5;i++){
  96928. memcpy(ogg_sync_buffer(&oy,og[i].header_len),og[i].header,
  96929. og[i].header_len);
  96930. ogg_sync_wrote(&oy,og[i].header_len);
  96931. memcpy(ogg_sync_buffer(&oy,og[i].body_len),og[i].body,og[i].body_len);
  96932. ogg_sync_wrote(&oy,og[i].body_len);
  96933. }
  96934. ogg_sync_pageout(&oy,&temp);
  96935. ogg_stream_pagein(&os_de,&temp);
  96936. ogg_sync_pageout(&oy,&temp);
  96937. ogg_stream_pagein(&os_de,&temp);
  96938. ogg_sync_pageout(&oy,&temp);
  96939. ogg_sync_pageout(&oy,&temp);
  96940. ogg_stream_pagein(&os_de,&temp);
  96941. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96942. checkpacket(&test,0,0,0);
  96943. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96944. checkpacket(&test,100,1,-1);
  96945. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96946. checkpacket(&test,4079,2,3000);
  96947. if(ogg_stream_packetout(&os_de,&test)!=-1){
  96948. fprintf(stderr,"Error: loss of page did not return error\n");
  96949. exit(1);
  96950. }
  96951. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96952. checkpacket(&test,76,5,-1);
  96953. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96954. checkpacket(&test,34,6,-1);
  96955. fprintf(stderr,"ok.\n");
  96956. }
  96957. {
  96958. ogg_page temp;
  96959. ogg_packet test;
  96960. fprintf(stderr,"Testing loss of pages (rollback required)... ");
  96961. ogg_sync_reset(&oy);
  96962. ogg_stream_reset(&os_de);
  96963. for(i=0;i<5;i++){
  96964. memcpy(ogg_sync_buffer(&oy,og[i].header_len),og[i].header,
  96965. og[i].header_len);
  96966. ogg_sync_wrote(&oy,og[i].header_len);
  96967. memcpy(ogg_sync_buffer(&oy,og[i].body_len),og[i].body,og[i].body_len);
  96968. ogg_sync_wrote(&oy,og[i].body_len);
  96969. }
  96970. ogg_sync_pageout(&oy,&temp);
  96971. ogg_stream_pagein(&os_de,&temp);
  96972. ogg_sync_pageout(&oy,&temp);
  96973. ogg_stream_pagein(&os_de,&temp);
  96974. ogg_sync_pageout(&oy,&temp);
  96975. ogg_stream_pagein(&os_de,&temp);
  96976. ogg_sync_pageout(&oy,&temp);
  96977. ogg_sync_pageout(&oy,&temp);
  96978. ogg_stream_pagein(&os_de,&temp);
  96979. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96980. checkpacket(&test,0,0,0);
  96981. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96982. checkpacket(&test,100,1,-1);
  96983. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96984. checkpacket(&test,4079,2,3000);
  96985. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96986. checkpacket(&test,2956,3,4000);
  96987. if(ogg_stream_packetout(&os_de,&test)!=-1){
  96988. fprintf(stderr,"Error: loss of page did not return error\n");
  96989. exit(1);
  96990. }
  96991. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96992. checkpacket(&test,300,13,14000);
  96993. fprintf(stderr,"ok.\n");
  96994. }
  96995. {
  96996. ogg_page og_de;
  96997. fprintf(stderr,"Testing sync on partial inputs... ");
  96998. ogg_sync_reset(&oy);
  96999. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  97000. 3);
  97001. ogg_sync_wrote(&oy,3);
  97002. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  97003. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+3,
  97004. 20);
  97005. ogg_sync_wrote(&oy,20);
  97006. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  97007. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+23,
  97008. 5);
  97009. ogg_sync_wrote(&oy,5);
  97010. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  97011. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+28,
  97012. og[1].header_len-28);
  97013. ogg_sync_wrote(&oy,og[1].header_len-28);
  97014. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  97015. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,1000);
  97016. ogg_sync_wrote(&oy,1000);
  97017. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  97018. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body+1000,
  97019. og[1].body_len-1000);
  97020. ogg_sync_wrote(&oy,og[1].body_len-1000);
  97021. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  97022. fprintf(stderr,"ok.\n");
  97023. }
  97024. {
  97025. ogg_page og_de;
  97026. fprintf(stderr,"Testing sync on 1+partial inputs... ");
  97027. ogg_sync_reset(&oy);
  97028. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  97029. og[1].header_len);
  97030. ogg_sync_wrote(&oy,og[1].header_len);
  97031. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  97032. og[1].body_len);
  97033. ogg_sync_wrote(&oy,og[1].body_len);
  97034. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  97035. 20);
  97036. ogg_sync_wrote(&oy,20);
  97037. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  97038. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  97039. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+20,
  97040. og[1].header_len-20);
  97041. ogg_sync_wrote(&oy,og[1].header_len-20);
  97042. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  97043. og[1].body_len);
  97044. ogg_sync_wrote(&oy,og[1].body_len);
  97045. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  97046. fprintf(stderr,"ok.\n");
  97047. }
  97048. {
  97049. ogg_page og_de;
  97050. fprintf(stderr,"Testing search for capture... ");
  97051. ogg_sync_reset(&oy);
  97052. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  97053. og[1].body_len);
  97054. ogg_sync_wrote(&oy,og[1].body_len);
  97055. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  97056. og[1].header_len);
  97057. ogg_sync_wrote(&oy,og[1].header_len);
  97058. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  97059. og[1].body_len);
  97060. ogg_sync_wrote(&oy,og[1].body_len);
  97061. memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header,
  97062. 20);
  97063. ogg_sync_wrote(&oy,20);
  97064. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  97065. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  97066. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  97067. memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header+20,
  97068. og[2].header_len-20);
  97069. ogg_sync_wrote(&oy,og[2].header_len-20);
  97070. memcpy(ogg_sync_buffer(&oy,og[2].body_len),og[2].body,
  97071. og[2].body_len);
  97072. ogg_sync_wrote(&oy,og[2].body_len);
  97073. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  97074. fprintf(stderr,"ok.\n");
  97075. }
  97076. {
  97077. ogg_page og_de;
  97078. fprintf(stderr,"Testing recapture... ");
  97079. ogg_sync_reset(&oy);
  97080. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  97081. og[1].header_len);
  97082. ogg_sync_wrote(&oy,og[1].header_len);
  97083. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  97084. og[1].body_len);
  97085. ogg_sync_wrote(&oy,og[1].body_len);
  97086. memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header,
  97087. og[2].header_len);
  97088. ogg_sync_wrote(&oy,og[2].header_len);
  97089. memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header,
  97090. og[2].header_len);
  97091. ogg_sync_wrote(&oy,og[2].header_len);
  97092. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  97093. memcpy(ogg_sync_buffer(&oy,og[2].body_len),og[2].body,
  97094. og[2].body_len-5);
  97095. ogg_sync_wrote(&oy,og[2].body_len-5);
  97096. memcpy(ogg_sync_buffer(&oy,og[3].header_len),og[3].header,
  97097. og[3].header_len);
  97098. ogg_sync_wrote(&oy,og[3].header_len);
  97099. memcpy(ogg_sync_buffer(&oy,og[3].body_len),og[3].body,
  97100. og[3].body_len);
  97101. ogg_sync_wrote(&oy,og[3].body_len);
  97102. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  97103. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  97104. fprintf(stderr,"ok.\n");
  97105. }
  97106. {
  97107. for(i=0;i<5;i++){
  97108. free_page(&og[i]);
  97109. }
  97110. }
  97111. }
  97112. return(0);
  97113. }
  97114. #endif
  97115. #endif
  97116. /*** End of inlined file: framing.c ***/
  97117. /*** Start of inlined file: analysis.c ***/
  97118. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  97119. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  97120. // tasks..
  97121. #if JUCE_MSVC
  97122. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  97123. #endif
  97124. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  97125. #if JUCE_USE_OGGVORBIS
  97126. #include <stdio.h>
  97127. #include <string.h>
  97128. #include <math.h>
  97129. /*** Start of inlined file: codec_internal.h ***/
  97130. #ifndef _V_CODECI_H_
  97131. #define _V_CODECI_H_
  97132. /*** Start of inlined file: envelope.h ***/
  97133. #ifndef _V_ENVELOPE_
  97134. #define _V_ENVELOPE_
  97135. /*** Start of inlined file: mdct.h ***/
  97136. #ifndef _OGG_mdct_H_
  97137. #define _OGG_mdct_H_
  97138. #ifdef MDCT_INTEGERIZED
  97139. #define DATA_TYPE int
  97140. #define REG_TYPE register int
  97141. #define TRIGBITS 14
  97142. #define cPI3_8 6270
  97143. #define cPI2_8 11585
  97144. #define cPI1_8 15137
  97145. #define FLOAT_CONV(x) ((int)((x)*(1<<TRIGBITS)+.5))
  97146. #define MULT_NORM(x) ((x)>>TRIGBITS)
  97147. #define HALVE(x) ((x)>>1)
  97148. #else
  97149. #define DATA_TYPE float
  97150. #define REG_TYPE float
  97151. #define cPI3_8 .38268343236508977175F
  97152. #define cPI2_8 .70710678118654752441F
  97153. #define cPI1_8 .92387953251128675613F
  97154. #define FLOAT_CONV(x) (x)
  97155. #define MULT_NORM(x) (x)
  97156. #define HALVE(x) ((x)*.5f)
  97157. #endif
  97158. typedef struct {
  97159. int n;
  97160. int log2n;
  97161. DATA_TYPE *trig;
  97162. int *bitrev;
  97163. DATA_TYPE scale;
  97164. } mdct_lookup;
  97165. extern void mdct_init(mdct_lookup *lookup,int n);
  97166. extern void mdct_clear(mdct_lookup *l);
  97167. extern void mdct_forward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out);
  97168. extern void mdct_backward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out);
  97169. #endif
  97170. /*** End of inlined file: mdct.h ***/
  97171. #define VE_PRE 16
  97172. #define VE_WIN 4
  97173. #define VE_POST 2
  97174. #define VE_AMP (VE_PRE+VE_POST-1)
  97175. #define VE_BANDS 7
  97176. #define VE_NEARDC 15
  97177. #define VE_MINSTRETCH 2 /* a bit less than short block */
  97178. #define VE_MAXSTRETCH 12 /* one-third full block */
  97179. typedef struct {
  97180. float ampbuf[VE_AMP];
  97181. int ampptr;
  97182. float nearDC[VE_NEARDC];
  97183. float nearDC_acc;
  97184. float nearDC_partialacc;
  97185. int nearptr;
  97186. } envelope_filter_state;
  97187. typedef struct {
  97188. int begin;
  97189. int end;
  97190. float *window;
  97191. float total;
  97192. } envelope_band;
  97193. typedef struct {
  97194. int ch;
  97195. int winlength;
  97196. int searchstep;
  97197. float minenergy;
  97198. mdct_lookup mdct;
  97199. float *mdct_win;
  97200. envelope_band band[VE_BANDS];
  97201. envelope_filter_state *filter;
  97202. int stretch;
  97203. int *mark;
  97204. long storage;
  97205. long current;
  97206. long curmark;
  97207. long cursor;
  97208. } envelope_lookup;
  97209. extern void _ve_envelope_init(envelope_lookup *e,vorbis_info *vi);
  97210. extern void _ve_envelope_clear(envelope_lookup *e);
  97211. extern long _ve_envelope_search(vorbis_dsp_state *v);
  97212. extern void _ve_envelope_shift(envelope_lookup *e,long shift);
  97213. extern int _ve_envelope_mark(vorbis_dsp_state *v);
  97214. #endif
  97215. /*** End of inlined file: envelope.h ***/
  97216. /*** Start of inlined file: codebook.h ***/
  97217. #ifndef _V_CODEBOOK_H_
  97218. #define _V_CODEBOOK_H_
  97219. typedef struct static_codebook{
  97220. long dim; /* codebook dimensions (elements per vector) */
  97221. long entries; /* codebook entries */
  97222. long *lengthlist; /* codeword lengths in bits */
  97223. int maptype; /* 0=none
  97224. 1=implicitly populated values from map column
  97225. 2=listed arbitrary values */
  97226. long q_min; /* packed 32 bit float; quant value 0 maps to minval */
  97227. long q_delta; /* packed 32 bit float; val 1 - val 0 == delta */
  97228. int q_quant; /* bits: 0 < quant <= 16 */
  97229. int q_sequencep; /* bitflag */
  97230. long *quantlist; /* map == 1: (int)(entries^(1/dim)) element column map
  97231. map == 2: list of dim*entries quantized entry vals
  97232. */
  97233. struct encode_aux_nearestmatch *nearest_tree;
  97234. struct encode_aux_threshmatch *thresh_tree;
  97235. struct encode_aux_pigeonhole *pigeon_tree;
  97236. int allocedp;
  97237. } static_codebook;
  97238. typedef struct encode_aux_nearestmatch{
  97239. long *ptr0;
  97240. long *ptr1;
  97241. long *p; /* decision points (each is an entry) */
  97242. long *q; /* decision points (each is an entry) */
  97243. long aux; /* number of tree entries */
  97244. long alloc;
  97245. } encode_aux_nearestmatch;
  97246. typedef struct encode_aux_threshmatch{
  97247. float *quantthresh;
  97248. long *quantmap;
  97249. int quantvals;
  97250. int threshvals;
  97251. } encode_aux_threshmatch;
  97252. typedef struct encode_aux_pigeonhole{
  97253. float min;
  97254. float del;
  97255. int mapentries;
  97256. int quantvals;
  97257. long *pigeonmap;
  97258. long fittotal;
  97259. long *fitlist;
  97260. long *fitmap;
  97261. long *fitlength;
  97262. } encode_aux_pigeonhole;
  97263. typedef struct codebook{
  97264. long dim; /* codebook dimensions (elements per vector) */
  97265. long entries; /* codebook entries */
  97266. long used_entries; /* populated codebook entries */
  97267. const static_codebook *c;
  97268. float *valuelist; /* list of dim*entries actual entry values */
  97269. ogg_uint32_t *codelist; /* list of bitstream codewords for each entry */
  97270. int *dec_index; /* only used if sparseness collapsed */
  97271. char *dec_codelengths;
  97272. ogg_uint32_t *dec_firsttable;
  97273. int dec_firsttablen;
  97274. int dec_maxlength;
  97275. } codebook;
  97276. extern void vorbis_staticbook_clear(static_codebook *b);
  97277. extern void vorbis_staticbook_destroy(static_codebook *b);
  97278. extern int vorbis_book_init_encode(codebook *dest,const static_codebook *source);
  97279. extern int vorbis_book_init_decode(codebook *dest,const static_codebook *source);
  97280. extern void vorbis_book_clear(codebook *b);
  97281. extern float *_book_unquantize(const static_codebook *b,int n,int *map);
  97282. extern float *_book_logdist(const static_codebook *b,float *vals);
  97283. extern float _float32_unpack(long val);
  97284. extern long _float32_pack(float val);
  97285. extern int _best(codebook *book, float *a, int step);
  97286. extern int _ilog(unsigned int v);
  97287. extern long _book_maptype1_quantvals(const static_codebook *b);
  97288. extern int vorbis_book_besterror(codebook *book,float *a,int step,int addmul);
  97289. extern long vorbis_book_codeword(codebook *book,int entry);
  97290. extern long vorbis_book_codelen(codebook *book,int entry);
  97291. extern int vorbis_staticbook_pack(const static_codebook *c,oggpack_buffer *b);
  97292. extern int vorbis_staticbook_unpack(oggpack_buffer *b,static_codebook *c);
  97293. extern int vorbis_book_encode(codebook *book, int a, oggpack_buffer *b);
  97294. extern int vorbis_book_errorv(codebook *book, float *a);
  97295. extern int vorbis_book_encodev(codebook *book, int best,float *a,
  97296. oggpack_buffer *b);
  97297. extern long vorbis_book_decode(codebook *book, oggpack_buffer *b);
  97298. extern long vorbis_book_decodevs_add(codebook *book, float *a,
  97299. oggpack_buffer *b,int n);
  97300. extern long vorbis_book_decodev_set(codebook *book, float *a,
  97301. oggpack_buffer *b,int n);
  97302. extern long vorbis_book_decodev_add(codebook *book, float *a,
  97303. oggpack_buffer *b,int n);
  97304. extern long vorbis_book_decodevv_add(codebook *book, float **a,
  97305. long off,int ch,
  97306. oggpack_buffer *b,int n);
  97307. #endif
  97308. /*** End of inlined file: codebook.h ***/
  97309. #define BLOCKTYPE_IMPULSE 0
  97310. #define BLOCKTYPE_PADDING 1
  97311. #define BLOCKTYPE_TRANSITION 0
  97312. #define BLOCKTYPE_LONG 1
  97313. #define PACKETBLOBS 15
  97314. typedef struct vorbis_block_internal{
  97315. float **pcmdelay; /* this is a pointer into local storage */
  97316. float ampmax;
  97317. int blocktype;
  97318. oggpack_buffer *packetblob[PACKETBLOBS]; /* initialized, must be freed;
  97319. blob [PACKETBLOBS/2] points to
  97320. the oggpack_buffer in the
  97321. main vorbis_block */
  97322. } vorbis_block_internal;
  97323. typedef void vorbis_look_floor;
  97324. typedef void vorbis_look_residue;
  97325. typedef void vorbis_look_transform;
  97326. typedef struct {
  97327. int blockflag;
  97328. int windowtype;
  97329. int transformtype;
  97330. int mapping;
  97331. } vorbis_info_mode;
  97332. typedef void vorbis_info_floor;
  97333. typedef void vorbis_info_residue;
  97334. typedef void vorbis_info_mapping;
  97335. /*** Start of inlined file: psy.h ***/
  97336. #ifndef _V_PSY_H_
  97337. #define _V_PSY_H_
  97338. /*** Start of inlined file: smallft.h ***/
  97339. #ifndef _V_SMFT_H_
  97340. #define _V_SMFT_H_
  97341. typedef struct {
  97342. int n;
  97343. float *trigcache;
  97344. int *splitcache;
  97345. } drft_lookup;
  97346. extern void drft_forward(drft_lookup *l,float *data);
  97347. extern void drft_backward(drft_lookup *l,float *data);
  97348. extern void drft_init(drft_lookup *l,int n);
  97349. extern void drft_clear(drft_lookup *l);
  97350. #endif
  97351. /*** End of inlined file: smallft.h ***/
  97352. /*** Start of inlined file: backends.h ***/
  97353. #ifndef _vorbis_backend_h_
  97354. #define _vorbis_backend_h_
  97355. typedef struct{
  97356. void (*pack) (vorbis_info_floor *,oggpack_buffer *);
  97357. vorbis_info_floor *(*unpack)(vorbis_info *,oggpack_buffer *);
  97358. vorbis_look_floor *(*look) (vorbis_dsp_state *,vorbis_info_floor *);
  97359. void (*free_info) (vorbis_info_floor *);
  97360. void (*free_look) (vorbis_look_floor *);
  97361. void *(*inverse1) (struct vorbis_block *,vorbis_look_floor *);
  97362. int (*inverse2) (struct vorbis_block *,vorbis_look_floor *,
  97363. void *buffer,float *);
  97364. } vorbis_func_floor;
  97365. typedef struct{
  97366. int order;
  97367. long rate;
  97368. long barkmap;
  97369. int ampbits;
  97370. int ampdB;
  97371. int numbooks; /* <= 16 */
  97372. int books[16];
  97373. float lessthan; /* encode-only config setting hacks for libvorbis */
  97374. float greaterthan; /* encode-only config setting hacks for libvorbis */
  97375. } vorbis_info_floor0;
  97376. #define VIF_POSIT 63
  97377. #define VIF_CLASS 16
  97378. #define VIF_PARTS 31
  97379. typedef struct{
  97380. int partitions; /* 0 to 31 */
  97381. int partitionclass[VIF_PARTS]; /* 0 to 15 */
  97382. int class_dim[VIF_CLASS]; /* 1 to 8 */
  97383. int class_subs[VIF_CLASS]; /* 0,1,2,3 (bits: 1<<n poss) */
  97384. int class_book[VIF_CLASS]; /* subs ^ dim entries */
  97385. int class_subbook[VIF_CLASS][8]; /* [VIF_CLASS][subs] */
  97386. int mult; /* 1 2 3 or 4 */
  97387. int postlist[VIF_POSIT+2]; /* first two implicit */
  97388. float maxover;
  97389. float maxunder;
  97390. float maxerr;
  97391. float twofitweight;
  97392. float twofitatten;
  97393. int n;
  97394. } vorbis_info_floor1;
  97395. typedef struct{
  97396. void (*pack) (vorbis_info_residue *,oggpack_buffer *);
  97397. vorbis_info_residue *(*unpack)(vorbis_info *,oggpack_buffer *);
  97398. vorbis_look_residue *(*look) (vorbis_dsp_state *,
  97399. vorbis_info_residue *);
  97400. void (*free_info) (vorbis_info_residue *);
  97401. void (*free_look) (vorbis_look_residue *);
  97402. long **(*classx) (struct vorbis_block *,vorbis_look_residue *,
  97403. float **,int *,int);
  97404. int (*forward) (oggpack_buffer *,struct vorbis_block *,
  97405. vorbis_look_residue *,
  97406. float **,float **,int *,int,long **);
  97407. int (*inverse) (struct vorbis_block *,vorbis_look_residue *,
  97408. float **,int *,int);
  97409. } vorbis_func_residue;
  97410. typedef struct vorbis_info_residue0{
  97411. long begin;
  97412. long end;
  97413. int grouping; /* group n vectors per partition */
  97414. int partitions; /* possible codebooks for a partition */
  97415. int groupbook; /* huffbook for partitioning */
  97416. int secondstages[64]; /* expanded out to pointers in lookup */
  97417. int booklist[256]; /* list of second stage books */
  97418. float classmetric1[64];
  97419. float classmetric2[64];
  97420. } vorbis_info_residue0;
  97421. typedef struct{
  97422. void (*pack) (vorbis_info *,vorbis_info_mapping *,
  97423. oggpack_buffer *);
  97424. vorbis_info_mapping *(*unpack)(vorbis_info *,oggpack_buffer *);
  97425. void (*free_info) (vorbis_info_mapping *);
  97426. int (*forward) (struct vorbis_block *vb);
  97427. int (*inverse) (struct vorbis_block *vb,vorbis_info_mapping *);
  97428. } vorbis_func_mapping;
  97429. typedef struct vorbis_info_mapping0{
  97430. int submaps; /* <= 16 */
  97431. int chmuxlist[256]; /* up to 256 channels in a Vorbis stream */
  97432. int floorsubmap[16]; /* [mux] submap to floors */
  97433. int residuesubmap[16]; /* [mux] submap to residue */
  97434. int coupling_steps;
  97435. int coupling_mag[256];
  97436. int coupling_ang[256];
  97437. } vorbis_info_mapping0;
  97438. #endif
  97439. /*** End of inlined file: backends.h ***/
  97440. #ifndef EHMER_MAX
  97441. #define EHMER_MAX 56
  97442. #endif
  97443. #define P_BANDS 17 /* 62Hz to 16kHz */
  97444. #define P_LEVELS 8 /* 30dB to 100dB */
  97445. #define P_LEVEL_0 30. /* 30 dB */
  97446. #define P_NOISECURVES 3
  97447. #define NOISE_COMPAND_LEVELS 40
  97448. typedef struct vorbis_info_psy{
  97449. int blockflag;
  97450. float ath_adjatt;
  97451. float ath_maxatt;
  97452. float tone_masteratt[P_NOISECURVES];
  97453. float tone_centerboost;
  97454. float tone_decay;
  97455. float tone_abs_limit;
  97456. float toneatt[P_BANDS];
  97457. int noisemaskp;
  97458. float noisemaxsupp;
  97459. float noisewindowlo;
  97460. float noisewindowhi;
  97461. int noisewindowlomin;
  97462. int noisewindowhimin;
  97463. int noisewindowfixed;
  97464. float noiseoff[P_NOISECURVES][P_BANDS];
  97465. float noisecompand[NOISE_COMPAND_LEVELS];
  97466. float max_curve_dB;
  97467. int normal_channel_p;
  97468. int normal_point_p;
  97469. int normal_start;
  97470. int normal_partition;
  97471. double normal_thresh;
  97472. } vorbis_info_psy;
  97473. typedef struct{
  97474. int eighth_octave_lines;
  97475. float preecho_thresh[VE_BANDS];
  97476. float postecho_thresh[VE_BANDS];
  97477. float stretch_penalty;
  97478. float preecho_minenergy;
  97479. float ampmax_att_per_sec;
  97480. int coupling_pkHz[PACKETBLOBS];
  97481. int coupling_pointlimit[2][PACKETBLOBS];
  97482. int coupling_prepointamp[PACKETBLOBS];
  97483. int coupling_postpointamp[PACKETBLOBS];
  97484. int sliding_lowpass[2][PACKETBLOBS];
  97485. } vorbis_info_psy_global;
  97486. typedef struct {
  97487. float ampmax;
  97488. int channels;
  97489. vorbis_info_psy_global *gi;
  97490. int coupling_pointlimit[2][P_NOISECURVES];
  97491. } vorbis_look_psy_global;
  97492. typedef struct {
  97493. int n;
  97494. struct vorbis_info_psy *vi;
  97495. float ***tonecurves;
  97496. float **noiseoffset;
  97497. float *ath;
  97498. long *octave; /* in n.ocshift format */
  97499. long *bark;
  97500. long firstoc;
  97501. long shiftoc;
  97502. int eighth_octave_lines; /* power of two, please */
  97503. int total_octave_lines;
  97504. long rate; /* cache it */
  97505. float m_val; /* Masking compensation value */
  97506. } vorbis_look_psy;
  97507. extern void _vp_psy_init(vorbis_look_psy *p,vorbis_info_psy *vi,
  97508. vorbis_info_psy_global *gi,int n,long rate);
  97509. extern void _vp_psy_clear(vorbis_look_psy *p);
  97510. extern void *_vi_psy_dup(void *source);
  97511. extern void _vi_psy_free(vorbis_info_psy *i);
  97512. extern vorbis_info_psy *_vi_psy_copy(vorbis_info_psy *i);
  97513. extern void _vp_remove_floor(vorbis_look_psy *p,
  97514. float *mdct,
  97515. int *icodedflr,
  97516. float *residue,
  97517. int sliding_lowpass);
  97518. extern void _vp_noisemask(vorbis_look_psy *p,
  97519. float *logmdct,
  97520. float *logmask);
  97521. extern void _vp_tonemask(vorbis_look_psy *p,
  97522. float *logfft,
  97523. float *logmask,
  97524. float global_specmax,
  97525. float local_specmax);
  97526. extern void _vp_offset_and_mix(vorbis_look_psy *p,
  97527. float *noise,
  97528. float *tone,
  97529. int offset_select,
  97530. float *logmask,
  97531. float *mdct,
  97532. float *logmdct);
  97533. extern float _vp_ampmax_decay(float amp,vorbis_dsp_state *vd);
  97534. extern float **_vp_quantize_couple_memo(vorbis_block *vb,
  97535. vorbis_info_psy_global *g,
  97536. vorbis_look_psy *p,
  97537. vorbis_info_mapping0 *vi,
  97538. float **mdct);
  97539. extern void _vp_couple(int blobno,
  97540. vorbis_info_psy_global *g,
  97541. vorbis_look_psy *p,
  97542. vorbis_info_mapping0 *vi,
  97543. float **res,
  97544. float **mag_memo,
  97545. int **mag_sort,
  97546. int **ifloor,
  97547. int *nonzero,
  97548. int sliding_lowpass);
  97549. extern void _vp_noise_normalize(vorbis_look_psy *p,
  97550. float *in,float *out,int *sortedindex);
  97551. extern void _vp_noise_normalize_sort(vorbis_look_psy *p,
  97552. float *magnitudes,int *sortedindex);
  97553. extern int **_vp_quantize_couple_sort(vorbis_block *vb,
  97554. vorbis_look_psy *p,
  97555. vorbis_info_mapping0 *vi,
  97556. float **mags);
  97557. extern void hf_reduction(vorbis_info_psy_global *g,
  97558. vorbis_look_psy *p,
  97559. vorbis_info_mapping0 *vi,
  97560. float **mdct);
  97561. #endif
  97562. /*** End of inlined file: psy.h ***/
  97563. /*** Start of inlined file: bitrate.h ***/
  97564. #ifndef _V_BITRATE_H_
  97565. #define _V_BITRATE_H_
  97566. /*** Start of inlined file: os.h ***/
  97567. #ifndef _OS_H
  97568. #define _OS_H
  97569. #ifdef HAVE_CONFIG_H
  97570. #include "config.h"
  97571. #endif
  97572. #include <math.h>
  97573. /*** Start of inlined file: misc.h ***/
  97574. #ifndef _V_RANDOM_H_
  97575. #define _V_RANDOM_H_
  97576. extern int analysis_noisy;
  97577. extern void *_vorbis_block_alloc(vorbis_block *vb,long bytes);
  97578. extern void _vorbis_block_ripcord(vorbis_block *vb);
  97579. extern void _analysis_output(char *base,int i,float *v,int n,int bark,int dB,
  97580. ogg_int64_t off);
  97581. #ifdef DEBUG_MALLOC
  97582. #define _VDBG_GRAPHFILE "malloc.m"
  97583. extern void *_VDBG_malloc(void *ptr,long bytes,char *file,long line);
  97584. extern void _VDBG_free(void *ptr,char *file,long line);
  97585. #ifndef MISC_C
  97586. #undef _ogg_malloc
  97587. #undef _ogg_calloc
  97588. #undef _ogg_realloc
  97589. #undef _ogg_free
  97590. #define _ogg_malloc(x) _VDBG_malloc(NULL,(x),__FILE__,__LINE__)
  97591. #define _ogg_calloc(x,y) _VDBG_malloc(NULL,(x)*(y),__FILE__,__LINE__)
  97592. #define _ogg_realloc(x,y) _VDBG_malloc((x),(y),__FILE__,__LINE__)
  97593. #define _ogg_free(x) _VDBG_free((x),__FILE__,__LINE__)
  97594. #endif
  97595. #endif
  97596. #endif
  97597. /*** End of inlined file: misc.h ***/
  97598. #ifndef _V_IFDEFJAIL_H_
  97599. # define _V_IFDEFJAIL_H_
  97600. # ifdef __GNUC__
  97601. # define STIN static __inline__
  97602. # elif _WIN32
  97603. # define STIN static __inline
  97604. # else
  97605. # define STIN static
  97606. # endif
  97607. #ifdef DJGPP
  97608. # define rint(x) (floor((x)+0.5f))
  97609. #endif
  97610. #ifndef M_PI
  97611. # define M_PI (3.1415926536f)
  97612. #endif
  97613. #if defined(_WIN32) && !defined(__SYMBIAN32__)
  97614. # include <malloc.h>
  97615. # define rint(x) (floor((x)+0.5f))
  97616. # define NO_FLOAT_MATH_LIB
  97617. # define FAST_HYPOT(a, b) sqrt((a)*(a) + (b)*(b))
  97618. #endif
  97619. #if defined(__SYMBIAN32__) && defined(__WINS__)
  97620. void *_alloca(size_t size);
  97621. # define alloca _alloca
  97622. #endif
  97623. #ifndef FAST_HYPOT
  97624. # define FAST_HYPOT hypot
  97625. #endif
  97626. #endif
  97627. #ifdef HAVE_ALLOCA_H
  97628. # include <alloca.h>
  97629. #endif
  97630. #ifdef USE_MEMORY_H
  97631. # include <memory.h>
  97632. #endif
  97633. #ifndef min
  97634. # define min(x,y) ((x)>(y)?(y):(x))
  97635. #endif
  97636. #ifndef max
  97637. # define max(x,y) ((x)<(y)?(y):(x))
  97638. #endif
  97639. #if defined(__i386__) && defined(__GNUC__) && !defined(__BEOS__)
  97640. # define VORBIS_FPU_CONTROL
  97641. typedef ogg_int16_t vorbis_fpu_control;
  97642. static inline void vorbis_fpu_setround(vorbis_fpu_control *fpu){
  97643. ogg_int16_t ret;
  97644. ogg_int16_t temp;
  97645. __asm__ __volatile__("fnstcw %0\n\t"
  97646. "movw %0,%%dx\n\t"
  97647. "orw $62463,%%dx\n\t"
  97648. "movw %%dx,%1\n\t"
  97649. "fldcw %1\n\t":"=m"(ret):"m"(temp): "dx");
  97650. *fpu=ret;
  97651. }
  97652. static inline void vorbis_fpu_restore(vorbis_fpu_control fpu){
  97653. __asm__ __volatile__("fldcw %0":: "m"(fpu));
  97654. }
  97655. static inline int vorbis_ftoi(double f){ /* yes, double! Otherwise,
  97656. we get extra fst/fld to
  97657. truncate precision */
  97658. int i;
  97659. __asm__("fistl %0": "=m"(i) : "t"(f));
  97660. return(i);
  97661. }
  97662. #endif
  97663. #if defined(_WIN32) && defined(_X86_) && !defined(__GNUC__) && !defined(__BORLANDC__)
  97664. # define VORBIS_FPU_CONTROL
  97665. typedef ogg_int16_t vorbis_fpu_control;
  97666. static __inline int vorbis_ftoi(double f){
  97667. int i;
  97668. __asm{
  97669. fld f
  97670. fistp i
  97671. }
  97672. return i;
  97673. }
  97674. static __inline void vorbis_fpu_setround(vorbis_fpu_control *fpu){
  97675. }
  97676. static __inline void vorbis_fpu_restore(vorbis_fpu_control fpu){
  97677. }
  97678. #endif
  97679. #ifndef VORBIS_FPU_CONTROL
  97680. typedef int vorbis_fpu_control;
  97681. static int vorbis_ftoi(double f){
  97682. return (int)(f+.5);
  97683. }
  97684. # define vorbis_fpu_setround(vorbis_fpu_control) {}
  97685. # define vorbis_fpu_restore(vorbis_fpu_control) {}
  97686. #endif
  97687. #endif /* _OS_H */
  97688. /*** End of inlined file: os.h ***/
  97689. typedef struct bitrate_manager_state {
  97690. int managed;
  97691. long avg_reservoir;
  97692. long minmax_reservoir;
  97693. long avg_bitsper;
  97694. long min_bitsper;
  97695. long max_bitsper;
  97696. long short_per_long;
  97697. double avgfloat;
  97698. vorbis_block *vb;
  97699. int choice;
  97700. } bitrate_manager_state;
  97701. typedef struct bitrate_manager_info{
  97702. long avg_rate;
  97703. long min_rate;
  97704. long max_rate;
  97705. long reservoir_bits;
  97706. double reservoir_bias;
  97707. double slew_damp;
  97708. } bitrate_manager_info;
  97709. extern void vorbis_bitrate_init(vorbis_info *vi,bitrate_manager_state *bs);
  97710. extern void vorbis_bitrate_clear(bitrate_manager_state *bs);
  97711. extern int vorbis_bitrate_managed(vorbis_block *vb);
  97712. extern int vorbis_bitrate_addblock(vorbis_block *vb);
  97713. extern int vorbis_bitrate_flushpacket(vorbis_dsp_state *vd, ogg_packet *op);
  97714. #endif
  97715. /*** End of inlined file: bitrate.h ***/
  97716. static int ilog(unsigned int v){
  97717. int ret=0;
  97718. while(v){
  97719. ret++;
  97720. v>>=1;
  97721. }
  97722. return(ret);
  97723. }
  97724. static int ilog2(unsigned int v){
  97725. int ret=0;
  97726. if(v)--v;
  97727. while(v){
  97728. ret++;
  97729. v>>=1;
  97730. }
  97731. return(ret);
  97732. }
  97733. typedef struct private_state {
  97734. envelope_lookup *ve; /* envelope lookup */
  97735. int window[2];
  97736. vorbis_look_transform **transform[2]; /* block, type */
  97737. drft_lookup fft_look[2];
  97738. int modebits;
  97739. vorbis_look_floor **flr;
  97740. vorbis_look_residue **residue;
  97741. vorbis_look_psy *psy;
  97742. vorbis_look_psy_global *psy_g_look;
  97743. unsigned char *header;
  97744. unsigned char *header1;
  97745. unsigned char *header2;
  97746. bitrate_manager_state bms;
  97747. ogg_int64_t sample_count;
  97748. } private_state;
  97749. /*** Start of inlined file: highlevel.h ***/
  97750. typedef struct highlevel_byblocktype {
  97751. double tone_mask_setting;
  97752. double tone_peaklimit_setting;
  97753. double noise_bias_setting;
  97754. double noise_compand_setting;
  97755. } highlevel_byblocktype;
  97756. typedef struct highlevel_encode_setup {
  97757. void *setup;
  97758. int set_in_stone;
  97759. double base_setting;
  97760. double long_setting;
  97761. double short_setting;
  97762. double impulse_noisetune;
  97763. int managed;
  97764. long bitrate_min;
  97765. long bitrate_av;
  97766. double bitrate_av_damp;
  97767. long bitrate_max;
  97768. long bitrate_reservoir;
  97769. double bitrate_reservoir_bias;
  97770. int impulse_block_p;
  97771. int noise_normalize_p;
  97772. double stereo_point_setting;
  97773. double lowpass_kHz;
  97774. double ath_floating_dB;
  97775. double ath_absolute_dB;
  97776. double amplitude_track_dBpersec;
  97777. double trigger_setting;
  97778. highlevel_byblocktype block[4]; /* padding, impulse, transition, long */
  97779. } highlevel_encode_setup;
  97780. /*** End of inlined file: highlevel.h ***/
  97781. typedef struct codec_setup_info {
  97782. long blocksizes[2];
  97783. int modes;
  97784. int maps;
  97785. int floors;
  97786. int residues;
  97787. int books;
  97788. int psys; /* encode only */
  97789. vorbis_info_mode *mode_param[64];
  97790. int map_type[64];
  97791. vorbis_info_mapping *map_param[64];
  97792. int floor_type[64];
  97793. vorbis_info_floor *floor_param[64];
  97794. int residue_type[64];
  97795. vorbis_info_residue *residue_param[64];
  97796. static_codebook *book_param[256];
  97797. codebook *fullbooks;
  97798. vorbis_info_psy *psy_param[4]; /* encode only */
  97799. vorbis_info_psy_global psy_g_param;
  97800. bitrate_manager_info bi;
  97801. highlevel_encode_setup hi; /* used only by vorbisenc.c. It's a
  97802. highly redundant structure, but
  97803. improves clarity of program flow. */
  97804. int halfrate_flag; /* painless downsample for decode */
  97805. } codec_setup_info;
  97806. extern vorbis_look_psy_global *_vp_global_look(vorbis_info *vi);
  97807. extern void _vp_global_free(vorbis_look_psy_global *look);
  97808. #endif
  97809. /*** End of inlined file: codec_internal.h ***/
  97810. /*** Start of inlined file: registry.h ***/
  97811. #ifndef _V_REG_H_
  97812. #define _V_REG_H_
  97813. #define VI_TRANSFORMB 1
  97814. #define VI_WINDOWB 1
  97815. #define VI_TIMEB 1
  97816. #define VI_FLOORB 2
  97817. #define VI_RESB 3
  97818. #define VI_MAPB 1
  97819. extern vorbis_func_floor *_floor_P[];
  97820. extern vorbis_func_residue *_residue_P[];
  97821. extern vorbis_func_mapping *_mapping_P[];
  97822. #endif
  97823. /*** End of inlined file: registry.h ***/
  97824. /*** Start of inlined file: scales.h ***/
  97825. #ifndef _V_SCALES_H_
  97826. #define _V_SCALES_H_
  97827. #include <math.h>
  97828. #define VORBIS_IEEE_FLOAT32 1
  97829. #ifdef VORBIS_IEEE_FLOAT32
  97830. static float unitnorm(float x){
  97831. union {
  97832. ogg_uint32_t i;
  97833. float f;
  97834. } ix;
  97835. ix.f = x;
  97836. ix.i = (ix.i & 0x80000000U) | (0x3f800000U);
  97837. return ix.f;
  97838. }
  97839. static float todB(const float *x){
  97840. union {
  97841. ogg_uint32_t i;
  97842. float f;
  97843. } ix;
  97844. ix.f = *x;
  97845. ix.i = ix.i&0x7fffffff;
  97846. return (float)(ix.i * 7.17711438e-7f -764.6161886f);
  97847. }
  97848. #define todB_nn(x) todB(x)
  97849. #else
  97850. static float unitnorm(float x){
  97851. if(x<0)return(-1.f);
  97852. return(1.f);
  97853. }
  97854. #define todB(x) (*(x)==0?-400.f:log(*(x)**(x))*4.34294480f)
  97855. #define todB_nn(x) (*(x)==0.f?-400.f:log(*(x))*8.6858896f)
  97856. #endif
  97857. #define fromdB(x) (exp((x)*.11512925f))
  97858. #define toBARK(n) (13.1f*atan(.00074f*(n))+2.24f*atan((n)*(n)*1.85e-8f)+1e-4f*(n))
  97859. #define fromBARK(z) (102.f*(z)-2.f*pow(z,2.f)+.4f*pow(z,3.f)+pow(1.46f,z)-1.f)
  97860. #define toMEL(n) (log(1.f+(n)*.001f)*1442.695f)
  97861. #define fromMEL(m) (1000.f*exp((m)/1442.695f)-1000.f)
  97862. #define toOC(n) (log(n)*1.442695f-5.965784f)
  97863. #define fromOC(o) (exp(((o)+5.965784f)*.693147f))
  97864. #endif
  97865. /*** End of inlined file: scales.h ***/
  97866. int analysis_noisy=1;
  97867. int vorbis_analysis(vorbis_block *vb, ogg_packet *op){
  97868. int ret,i;
  97869. vorbis_block_internal *vbi=(vorbis_block_internal *)vb->internal;
  97870. vb->glue_bits=0;
  97871. vb->time_bits=0;
  97872. vb->floor_bits=0;
  97873. vb->res_bits=0;
  97874. for(i=0;i<PACKETBLOBS;i++)
  97875. oggpack_reset(vbi->packetblob[i]);
  97876. if((ret=_mapping_P[0]->forward(vb)))
  97877. return(ret);
  97878. if(op){
  97879. if(vorbis_bitrate_managed(vb))
  97880. return(OV_EINVAL);
  97881. op->packet=oggpack_get_buffer(&vb->opb);
  97882. op->bytes=oggpack_bytes(&vb->opb);
  97883. op->b_o_s=0;
  97884. op->e_o_s=vb->eofflag;
  97885. op->granulepos=vb->granulepos;
  97886. op->packetno=vb->sequence; /* for sake of completeness */
  97887. }
  97888. return(0);
  97889. }
  97890. void _analysis_output_always(const char *base,int i,float *v,int n,int bark,int dB,ogg_int64_t off){
  97891. int j;
  97892. FILE *of;
  97893. char buffer[80];
  97894. sprintf(buffer,"%s_%d.m",base,i);
  97895. of=fopen(buffer,"w");
  97896. if(!of)perror("failed to open data dump file");
  97897. for(j=0;j<n;j++){
  97898. if(bark){
  97899. float b=toBARK((4000.f*j/n)+.25);
  97900. fprintf(of,"%f ",b);
  97901. }else
  97902. if(off!=0)
  97903. fprintf(of,"%f ",(double)(j+off)/8000.);
  97904. else
  97905. fprintf(of,"%f ",(double)j);
  97906. if(dB){
  97907. float val;
  97908. if(v[j]==0.)
  97909. val=-140.;
  97910. else
  97911. val=todB(v+j);
  97912. fprintf(of,"%f\n",val);
  97913. }else{
  97914. fprintf(of,"%f\n",v[j]);
  97915. }
  97916. }
  97917. fclose(of);
  97918. }
  97919. void _analysis_output(char *base,int i,float *v,int n,int bark,int dB,
  97920. ogg_int64_t off){
  97921. if(analysis_noisy)_analysis_output_always(base,i,v,n,bark,dB,off);
  97922. }
  97923. #endif
  97924. /*** End of inlined file: analysis.c ***/
  97925. /*** Start of inlined file: bitrate.c ***/
  97926. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  97927. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  97928. // tasks..
  97929. #if JUCE_MSVC
  97930. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  97931. #endif
  97932. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  97933. #if JUCE_USE_OGGVORBIS
  97934. #include <stdlib.h>
  97935. #include <string.h>
  97936. #include <math.h>
  97937. void vorbis_bitrate_init(vorbis_info *vi,bitrate_manager_state *bm){
  97938. codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
  97939. bitrate_manager_info *bi=&ci->bi;
  97940. memset(bm,0,sizeof(*bm));
  97941. if(bi && (bi->reservoir_bits>0)){
  97942. long ratesamples=vi->rate;
  97943. int halfsamples=ci->blocksizes[0]>>1;
  97944. bm->short_per_long=ci->blocksizes[1]/ci->blocksizes[0];
  97945. bm->managed=1;
  97946. bm->avg_bitsper= rint(1.*bi->avg_rate*halfsamples/ratesamples);
  97947. bm->min_bitsper= rint(1.*bi->min_rate*halfsamples/ratesamples);
  97948. bm->max_bitsper= rint(1.*bi->max_rate*halfsamples/ratesamples);
  97949. bm->avgfloat=PACKETBLOBS/2;
  97950. {
  97951. long desired_fill=bi->reservoir_bits*bi->reservoir_bias;
  97952. bm->minmax_reservoir=desired_fill;
  97953. bm->avg_reservoir=desired_fill;
  97954. }
  97955. }
  97956. }
  97957. void vorbis_bitrate_clear(bitrate_manager_state *bm){
  97958. memset(bm,0,sizeof(*bm));
  97959. return;
  97960. }
  97961. int vorbis_bitrate_managed(vorbis_block *vb){
  97962. vorbis_dsp_state *vd=vb->vd;
  97963. private_state *b=(private_state*)vd->backend_state;
  97964. bitrate_manager_state *bm=&b->bms;
  97965. if(bm && bm->managed)return(1);
  97966. return(0);
  97967. }
  97968. int vorbis_bitrate_addblock(vorbis_block *vb){
  97969. vorbis_block_internal *vbi=(vorbis_block_internal*)vb->internal;
  97970. vorbis_dsp_state *vd=vb->vd;
  97971. private_state *b=(private_state*)vd->backend_state;
  97972. bitrate_manager_state *bm=&b->bms;
  97973. vorbis_info *vi=vd->vi;
  97974. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  97975. bitrate_manager_info *bi=&ci->bi;
  97976. int choice=rint(bm->avgfloat);
  97977. long this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97978. long min_target_bits=(vb->W?bm->min_bitsper*bm->short_per_long:bm->min_bitsper);
  97979. long max_target_bits=(vb->W?bm->max_bitsper*bm->short_per_long:bm->max_bitsper);
  97980. int samples=ci->blocksizes[vb->W]>>1;
  97981. long desired_fill=bi->reservoir_bits*bi->reservoir_bias;
  97982. if(!bm->managed){
  97983. if(bm->vb)return(-1); /* one has been submitted without
  97984. being claimed */
  97985. bm->vb=vb;
  97986. return(0);
  97987. }
  97988. bm->vb=vb;
  97989. if(bm->avg_bitsper>0){
  97990. double slew=0.;
  97991. long avg_target_bits=(vb->W?bm->avg_bitsper*bm->short_per_long:bm->avg_bitsper);
  97992. double slewlimit= 15./bi->slew_damp;
  97993. if(bm->avg_reservoir+(this_bits-avg_target_bits)>desired_fill){
  97994. while(choice>0 && this_bits>avg_target_bits &&
  97995. bm->avg_reservoir+(this_bits-avg_target_bits)>desired_fill){
  97996. choice--;
  97997. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97998. }
  97999. }else if(bm->avg_reservoir+(this_bits-avg_target_bits)<desired_fill){
  98000. while(choice+1<PACKETBLOBS && this_bits<avg_target_bits &&
  98001. bm->avg_reservoir+(this_bits-avg_target_bits)<desired_fill){
  98002. choice++;
  98003. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  98004. }
  98005. }
  98006. slew=rint(choice-bm->avgfloat)/samples*vi->rate;
  98007. if(slew<-slewlimit)slew=-slewlimit;
  98008. if(slew>slewlimit)slew=slewlimit;
  98009. choice=rint(bm->avgfloat+= slew/vi->rate*samples);
  98010. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  98011. }
  98012. if(bm->min_bitsper>0){
  98013. if(this_bits<min_target_bits){
  98014. while(bm->minmax_reservoir-(min_target_bits-this_bits)<0){
  98015. choice++;
  98016. if(choice>=PACKETBLOBS)break;
  98017. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  98018. }
  98019. }
  98020. }
  98021. if(bm->max_bitsper>0){
  98022. if(this_bits>max_target_bits){
  98023. while(bm->minmax_reservoir+(this_bits-max_target_bits)>bi->reservoir_bits){
  98024. choice--;
  98025. if(choice<0)break;
  98026. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  98027. }
  98028. }
  98029. }
  98030. if(choice<0){
  98031. long maxsize=(max_target_bits+(bi->reservoir_bits-bm->minmax_reservoir))/8;
  98032. bm->choice=choice=0;
  98033. if(oggpack_bytes(vbi->packetblob[choice])>maxsize){
  98034. oggpack_writetrunc(vbi->packetblob[choice],maxsize*8);
  98035. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  98036. }
  98037. }else{
  98038. long minsize=(min_target_bits-bm->minmax_reservoir+7)/8;
  98039. if(choice>=PACKETBLOBS)
  98040. choice=PACKETBLOBS-1;
  98041. bm->choice=choice;
  98042. minsize-=oggpack_bytes(vbi->packetblob[choice]);
  98043. while(minsize-->0)oggpack_write(vbi->packetblob[choice],0,8);
  98044. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  98045. }
  98046. if(bm->min_bitsper>0 || bm->max_bitsper>0){
  98047. if(max_target_bits>0 && this_bits>max_target_bits){
  98048. bm->minmax_reservoir+=(this_bits-max_target_bits);
  98049. }else if(min_target_bits>0 && this_bits<min_target_bits){
  98050. bm->minmax_reservoir+=(this_bits-min_target_bits);
  98051. }else{
  98052. if(bm->minmax_reservoir>desired_fill){
  98053. if(max_target_bits>0){ /* logical bulletproofing against initialization state */
  98054. bm->minmax_reservoir+=(this_bits-max_target_bits);
  98055. if(bm->minmax_reservoir<desired_fill)bm->minmax_reservoir=desired_fill;
  98056. }else{
  98057. bm->minmax_reservoir=desired_fill;
  98058. }
  98059. }else{
  98060. if(min_target_bits>0){ /* logical bulletproofing against initialization state */
  98061. bm->minmax_reservoir+=(this_bits-min_target_bits);
  98062. if(bm->minmax_reservoir>desired_fill)bm->minmax_reservoir=desired_fill;
  98063. }else{
  98064. bm->minmax_reservoir=desired_fill;
  98065. }
  98066. }
  98067. }
  98068. }
  98069. if(bm->avg_bitsper>0){
  98070. long avg_target_bits=(vb->W?bm->avg_bitsper*bm->short_per_long:bm->avg_bitsper);
  98071. bm->avg_reservoir+=this_bits-avg_target_bits;
  98072. }
  98073. return(0);
  98074. }
  98075. int vorbis_bitrate_flushpacket(vorbis_dsp_state *vd,ogg_packet *op){
  98076. private_state *b=(private_state*)vd->backend_state;
  98077. bitrate_manager_state *bm=&b->bms;
  98078. vorbis_block *vb=bm->vb;
  98079. int choice=PACKETBLOBS/2;
  98080. if(!vb)return 0;
  98081. if(op){
  98082. vorbis_block_internal *vbi=(vorbis_block_internal*)vb->internal;
  98083. if(vorbis_bitrate_managed(vb))
  98084. choice=bm->choice;
  98085. op->packet=oggpack_get_buffer(vbi->packetblob[choice]);
  98086. op->bytes=oggpack_bytes(vbi->packetblob[choice]);
  98087. op->b_o_s=0;
  98088. op->e_o_s=vb->eofflag;
  98089. op->granulepos=vb->granulepos;
  98090. op->packetno=vb->sequence; /* for sake of completeness */
  98091. }
  98092. bm->vb=0;
  98093. return(1);
  98094. }
  98095. #endif
  98096. /*** End of inlined file: bitrate.c ***/
  98097. /*** Start of inlined file: block.c ***/
  98098. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  98099. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  98100. // tasks..
  98101. #if JUCE_MSVC
  98102. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  98103. #endif
  98104. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  98105. #if JUCE_USE_OGGVORBIS
  98106. #include <stdio.h>
  98107. #include <stdlib.h>
  98108. #include <string.h>
  98109. /*** Start of inlined file: window.h ***/
  98110. #ifndef _V_WINDOW_
  98111. #define _V_WINDOW_
  98112. extern float *_vorbis_window_get(int n);
  98113. extern void _vorbis_apply_window(float *d,int *winno,long *blocksizes,
  98114. int lW,int W,int nW);
  98115. #endif
  98116. /*** End of inlined file: window.h ***/
  98117. /*** Start of inlined file: lpc.h ***/
  98118. #ifndef _V_LPC_H_
  98119. #define _V_LPC_H_
  98120. extern float vorbis_lpc_from_data(float *data,float *lpc,int n,int m);
  98121. extern void vorbis_lpc_predict(float *coeff,float *prime,int m,
  98122. float *data,long n);
  98123. #endif
  98124. /*** End of inlined file: lpc.h ***/
  98125. #ifndef WORD_ALIGN
  98126. #define WORD_ALIGN 8
  98127. #endif
  98128. int vorbis_block_init(vorbis_dsp_state *v, vorbis_block *vb){
  98129. int i;
  98130. memset(vb,0,sizeof(*vb));
  98131. vb->vd=v;
  98132. vb->localalloc=0;
  98133. vb->localstore=NULL;
  98134. if(v->analysisp){
  98135. vorbis_block_internal *vbi=(vorbis_block_internal*)
  98136. (vb->internal=(vorbis_block_internal*)_ogg_calloc(1,sizeof(vorbis_block_internal)));
  98137. vbi->ampmax=-9999;
  98138. for(i=0;i<PACKETBLOBS;i++){
  98139. if(i==PACKETBLOBS/2){
  98140. vbi->packetblob[i]=&vb->opb;
  98141. }else{
  98142. vbi->packetblob[i]=
  98143. (oggpack_buffer*) _ogg_calloc(1,sizeof(oggpack_buffer));
  98144. }
  98145. oggpack_writeinit(vbi->packetblob[i]);
  98146. }
  98147. }
  98148. return(0);
  98149. }
  98150. void *_vorbis_block_alloc(vorbis_block *vb,long bytes){
  98151. bytes=(bytes+(WORD_ALIGN-1)) & ~(WORD_ALIGN-1);
  98152. if(bytes+vb->localtop>vb->localalloc){
  98153. if(vb->localstore){
  98154. struct alloc_chain *link=(struct alloc_chain*)_ogg_malloc(sizeof(*link));
  98155. vb->totaluse+=vb->localtop;
  98156. link->next=vb->reap;
  98157. link->ptr=vb->localstore;
  98158. vb->reap=link;
  98159. }
  98160. vb->localalloc=bytes;
  98161. vb->localstore=_ogg_malloc(vb->localalloc);
  98162. vb->localtop=0;
  98163. }
  98164. {
  98165. void *ret=(void *)(((char *)vb->localstore)+vb->localtop);
  98166. vb->localtop+=bytes;
  98167. return ret;
  98168. }
  98169. }
  98170. void _vorbis_block_ripcord(vorbis_block *vb){
  98171. struct alloc_chain *reap=vb->reap;
  98172. while(reap){
  98173. struct alloc_chain *next=reap->next;
  98174. _ogg_free(reap->ptr);
  98175. memset(reap,0,sizeof(*reap));
  98176. _ogg_free(reap);
  98177. reap=next;
  98178. }
  98179. if(vb->totaluse){
  98180. vb->localstore=_ogg_realloc(vb->localstore,vb->totaluse+vb->localalloc);
  98181. vb->localalloc+=vb->totaluse;
  98182. vb->totaluse=0;
  98183. }
  98184. vb->localtop=0;
  98185. vb->reap=NULL;
  98186. }
  98187. int vorbis_block_clear(vorbis_block *vb){
  98188. int i;
  98189. vorbis_block_internal *vbi=(vorbis_block_internal*)vb->internal;
  98190. _vorbis_block_ripcord(vb);
  98191. if(vb->localstore)_ogg_free(vb->localstore);
  98192. if(vbi){
  98193. for(i=0;i<PACKETBLOBS;i++){
  98194. oggpack_writeclear(vbi->packetblob[i]);
  98195. if(i!=PACKETBLOBS/2)_ogg_free(vbi->packetblob[i]);
  98196. }
  98197. _ogg_free(vbi);
  98198. }
  98199. memset(vb,0,sizeof(*vb));
  98200. return(0);
  98201. }
  98202. static int _vds_shared_init(vorbis_dsp_state *v,vorbis_info *vi,int encp){
  98203. int i;
  98204. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98205. private_state *b=NULL;
  98206. int hs;
  98207. if(ci==NULL) return 1;
  98208. hs=ci->halfrate_flag;
  98209. memset(v,0,sizeof(*v));
  98210. b=(private_state*) (v->backend_state=(private_state*)_ogg_calloc(1,sizeof(*b)));
  98211. v->vi=vi;
  98212. b->modebits=ilog2(ci->modes);
  98213. b->transform[0]=(vorbis_look_transform**)_ogg_calloc(VI_TRANSFORMB,sizeof(*b->transform[0]));
  98214. b->transform[1]=(vorbis_look_transform**)_ogg_calloc(VI_TRANSFORMB,sizeof(*b->transform[1]));
  98215. b->transform[0][0]=_ogg_calloc(1,sizeof(mdct_lookup));
  98216. b->transform[1][0]=_ogg_calloc(1,sizeof(mdct_lookup));
  98217. mdct_init((mdct_lookup*)b->transform[0][0],ci->blocksizes[0]>>hs);
  98218. mdct_init((mdct_lookup*)b->transform[1][0],ci->blocksizes[1]>>hs);
  98219. b->window[0]=ilog2(ci->blocksizes[0])-6;
  98220. b->window[1]=ilog2(ci->blocksizes[1])-6;
  98221. if(encp){ /* encode/decode differ here */
  98222. drft_init(&b->fft_look[0],ci->blocksizes[0]);
  98223. drft_init(&b->fft_look[1],ci->blocksizes[1]);
  98224. if(!ci->fullbooks){
  98225. ci->fullbooks=(codebook*) _ogg_calloc(ci->books,sizeof(*ci->fullbooks));
  98226. for(i=0;i<ci->books;i++)
  98227. vorbis_book_init_encode(ci->fullbooks+i,ci->book_param[i]);
  98228. }
  98229. b->psy=(vorbis_look_psy*)_ogg_calloc(ci->psys,sizeof(*b->psy));
  98230. for(i=0;i<ci->psys;i++){
  98231. _vp_psy_init(b->psy+i,
  98232. ci->psy_param[i],
  98233. &ci->psy_g_param,
  98234. ci->blocksizes[ci->psy_param[i]->blockflag]/2,
  98235. vi->rate);
  98236. }
  98237. v->analysisp=1;
  98238. }else{
  98239. if(!ci->fullbooks){
  98240. ci->fullbooks=(codebook*) _ogg_calloc(ci->books,sizeof(*ci->fullbooks));
  98241. for(i=0;i<ci->books;i++){
  98242. vorbis_book_init_decode(ci->fullbooks+i,ci->book_param[i]);
  98243. vorbis_staticbook_destroy(ci->book_param[i]);
  98244. ci->book_param[i]=NULL;
  98245. }
  98246. }
  98247. }
  98248. v->pcm_storage=ci->blocksizes[1];
  98249. v->pcm=(float**)_ogg_malloc(vi->channels*sizeof(*v->pcm));
  98250. v->pcmret=(float**)_ogg_malloc(vi->channels*sizeof(*v->pcmret));
  98251. {
  98252. int i;
  98253. for(i=0;i<vi->channels;i++)
  98254. v->pcm[i]=(float*)_ogg_calloc(v->pcm_storage,sizeof(*v->pcm[i]));
  98255. }
  98256. v->lW=0; /* previous window size */
  98257. v->W=0; /* current window size */
  98258. v->centerW=ci->blocksizes[1]/2;
  98259. v->pcm_current=v->centerW;
  98260. b->flr=(vorbis_look_floor**)_ogg_calloc(ci->floors,sizeof(*b->flr));
  98261. b->residue=(vorbis_look_residue**)_ogg_calloc(ci->residues,sizeof(*b->residue));
  98262. for(i=0;i<ci->floors;i++)
  98263. b->flr[i]=_floor_P[ci->floor_type[i]]->
  98264. look(v,ci->floor_param[i]);
  98265. for(i=0;i<ci->residues;i++)
  98266. b->residue[i]=_residue_P[ci->residue_type[i]]->
  98267. look(v,ci->residue_param[i]);
  98268. return 0;
  98269. }
  98270. int vorbis_analysis_init(vorbis_dsp_state *v,vorbis_info *vi){
  98271. private_state *b=NULL;
  98272. if(_vds_shared_init(v,vi,1))return 1;
  98273. b=(private_state*)v->backend_state;
  98274. b->psy_g_look=_vp_global_look(vi);
  98275. b->ve=(envelope_lookup*)_ogg_calloc(1,sizeof(*b->ve));
  98276. _ve_envelope_init(b->ve,vi);
  98277. vorbis_bitrate_init(vi,&b->bms);
  98278. v->sequence=3;
  98279. return(0);
  98280. }
  98281. void vorbis_dsp_clear(vorbis_dsp_state *v){
  98282. int i;
  98283. if(v){
  98284. vorbis_info *vi=v->vi;
  98285. codec_setup_info *ci=(codec_setup_info*)(vi?vi->codec_setup:NULL);
  98286. private_state *b=(private_state*)v->backend_state;
  98287. if(b){
  98288. if(b->ve){
  98289. _ve_envelope_clear(b->ve);
  98290. _ogg_free(b->ve);
  98291. }
  98292. if(b->transform[0]){
  98293. mdct_clear((mdct_lookup*) b->transform[0][0]);
  98294. _ogg_free(b->transform[0][0]);
  98295. _ogg_free(b->transform[0]);
  98296. }
  98297. if(b->transform[1]){
  98298. mdct_clear((mdct_lookup*) b->transform[1][0]);
  98299. _ogg_free(b->transform[1][0]);
  98300. _ogg_free(b->transform[1]);
  98301. }
  98302. if(b->flr){
  98303. for(i=0;i<ci->floors;i++)
  98304. _floor_P[ci->floor_type[i]]->
  98305. free_look(b->flr[i]);
  98306. _ogg_free(b->flr);
  98307. }
  98308. if(b->residue){
  98309. for(i=0;i<ci->residues;i++)
  98310. _residue_P[ci->residue_type[i]]->
  98311. free_look(b->residue[i]);
  98312. _ogg_free(b->residue);
  98313. }
  98314. if(b->psy){
  98315. for(i=0;i<ci->psys;i++)
  98316. _vp_psy_clear(b->psy+i);
  98317. _ogg_free(b->psy);
  98318. }
  98319. if(b->psy_g_look)_vp_global_free(b->psy_g_look);
  98320. vorbis_bitrate_clear(&b->bms);
  98321. drft_clear(&b->fft_look[0]);
  98322. drft_clear(&b->fft_look[1]);
  98323. }
  98324. if(v->pcm){
  98325. for(i=0;i<vi->channels;i++)
  98326. if(v->pcm[i])_ogg_free(v->pcm[i]);
  98327. _ogg_free(v->pcm);
  98328. if(v->pcmret)_ogg_free(v->pcmret);
  98329. }
  98330. if(b){
  98331. if(b->header)_ogg_free(b->header);
  98332. if(b->header1)_ogg_free(b->header1);
  98333. if(b->header2)_ogg_free(b->header2);
  98334. _ogg_free(b);
  98335. }
  98336. memset(v,0,sizeof(*v));
  98337. }
  98338. }
  98339. float **vorbis_analysis_buffer(vorbis_dsp_state *v, int vals){
  98340. int i;
  98341. vorbis_info *vi=v->vi;
  98342. private_state *b=(private_state*)v->backend_state;
  98343. if(b->header)_ogg_free(b->header);b->header=NULL;
  98344. if(b->header1)_ogg_free(b->header1);b->header1=NULL;
  98345. if(b->header2)_ogg_free(b->header2);b->header2=NULL;
  98346. if(v->pcm_current+vals>=v->pcm_storage){
  98347. v->pcm_storage=v->pcm_current+vals*2;
  98348. for(i=0;i<vi->channels;i++){
  98349. v->pcm[i]=(float*)_ogg_realloc(v->pcm[i],v->pcm_storage*sizeof(*v->pcm[i]));
  98350. }
  98351. }
  98352. for(i=0;i<vi->channels;i++)
  98353. v->pcmret[i]=v->pcm[i]+v->pcm_current;
  98354. return(v->pcmret);
  98355. }
  98356. static void _preextrapolate_helper(vorbis_dsp_state *v){
  98357. int i;
  98358. int order=32;
  98359. float *lpc=(float*)alloca(order*sizeof(*lpc));
  98360. float *work=(float*)alloca(v->pcm_current*sizeof(*work));
  98361. long j;
  98362. v->preextrapolate=1;
  98363. if(v->pcm_current-v->centerW>order*2){ /* safety */
  98364. for(i=0;i<v->vi->channels;i++){
  98365. for(j=0;j<v->pcm_current;j++)
  98366. work[j]=v->pcm[i][v->pcm_current-j-1];
  98367. vorbis_lpc_from_data(work,lpc,v->pcm_current-v->centerW,order);
  98368. vorbis_lpc_predict(lpc,work+v->pcm_current-v->centerW-order,
  98369. order,
  98370. work+v->pcm_current-v->centerW,
  98371. v->centerW);
  98372. for(j=0;j<v->pcm_current;j++)
  98373. v->pcm[i][v->pcm_current-j-1]=work[j];
  98374. }
  98375. }
  98376. }
  98377. int vorbis_analysis_wrote(vorbis_dsp_state *v, int vals){
  98378. vorbis_info *vi=v->vi;
  98379. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98380. if(vals<=0){
  98381. int order=32;
  98382. int i;
  98383. float *lpc=(float*) alloca(order*sizeof(*lpc));
  98384. if(!v->preextrapolate)
  98385. _preextrapolate_helper(v);
  98386. vorbis_analysis_buffer(v,ci->blocksizes[1]*3);
  98387. v->eofflag=v->pcm_current;
  98388. v->pcm_current+=ci->blocksizes[1]*3;
  98389. for(i=0;i<vi->channels;i++){
  98390. if(v->eofflag>order*2){
  98391. long n;
  98392. n=v->eofflag;
  98393. if(n>ci->blocksizes[1])n=ci->blocksizes[1];
  98394. vorbis_lpc_from_data(v->pcm[i]+v->eofflag-n,lpc,n,order);
  98395. vorbis_lpc_predict(lpc,v->pcm[i]+v->eofflag-order,order,
  98396. v->pcm[i]+v->eofflag,v->pcm_current-v->eofflag);
  98397. }else{
  98398. memset(v->pcm[i]+v->eofflag,0,
  98399. (v->pcm_current-v->eofflag)*sizeof(*v->pcm[i]));
  98400. }
  98401. }
  98402. }else{
  98403. if(v->pcm_current+vals>v->pcm_storage)
  98404. return(OV_EINVAL);
  98405. v->pcm_current+=vals;
  98406. if(!v->preextrapolate && v->pcm_current-v->centerW>ci->blocksizes[1])
  98407. _preextrapolate_helper(v);
  98408. }
  98409. return(0);
  98410. }
  98411. int vorbis_analysis_blockout(vorbis_dsp_state *v,vorbis_block *vb){
  98412. int i;
  98413. vorbis_info *vi=v->vi;
  98414. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98415. private_state *b=(private_state*)v->backend_state;
  98416. vorbis_look_psy_global *g=b->psy_g_look;
  98417. long beginW=v->centerW-ci->blocksizes[v->W]/2,centerNext;
  98418. vorbis_block_internal *vbi=(vorbis_block_internal *)vb->internal;
  98419. if(!v->preextrapolate)return(0);
  98420. if(v->eofflag==-1)return(0);
  98421. {
  98422. long bp=_ve_envelope_search(v);
  98423. if(bp==-1){
  98424. if(v->eofflag==0)return(0); /* not enough data currently to search for a
  98425. full long block */
  98426. v->nW=0;
  98427. }else{
  98428. if(ci->blocksizes[0]==ci->blocksizes[1])
  98429. v->nW=0;
  98430. else
  98431. v->nW=bp;
  98432. }
  98433. }
  98434. centerNext=v->centerW+ci->blocksizes[v->W]/4+ci->blocksizes[v->nW]/4;
  98435. {
  98436. long blockbound=centerNext+ci->blocksizes[v->nW]/2;
  98437. if(v->pcm_current<blockbound)return(0); /* not enough data yet;
  98438. although this check is
  98439. less strict that the
  98440. _ve_envelope_search,
  98441. the search is not run
  98442. if we only use one
  98443. block size */
  98444. }
  98445. _vorbis_block_ripcord(vb);
  98446. vb->lW=v->lW;
  98447. vb->W=v->W;
  98448. vb->nW=v->nW;
  98449. if(v->W){
  98450. if(!v->lW || !v->nW){
  98451. vbi->blocktype=BLOCKTYPE_TRANSITION;
  98452. }else{
  98453. vbi->blocktype=BLOCKTYPE_LONG;
  98454. }
  98455. }else{
  98456. if(_ve_envelope_mark(v)){
  98457. vbi->blocktype=BLOCKTYPE_IMPULSE;
  98458. }else{
  98459. vbi->blocktype=BLOCKTYPE_PADDING;
  98460. }
  98461. }
  98462. vb->vd=v;
  98463. vb->sequence=v->sequence++;
  98464. vb->granulepos=v->granulepos;
  98465. vb->pcmend=ci->blocksizes[v->W];
  98466. if(vbi->ampmax>g->ampmax)g->ampmax=vbi->ampmax;
  98467. g->ampmax=_vp_ampmax_decay(g->ampmax,v);
  98468. vbi->ampmax=g->ampmax;
  98469. vb->pcm=(float**)_vorbis_block_alloc(vb,sizeof(*vb->pcm)*vi->channels);
  98470. vbi->pcmdelay=(float**)_vorbis_block_alloc(vb,sizeof(*vbi->pcmdelay)*vi->channels);
  98471. for(i=0;i<vi->channels;i++){
  98472. vbi->pcmdelay[i]=
  98473. (float*) _vorbis_block_alloc(vb,(vb->pcmend+beginW)*sizeof(*vbi->pcmdelay[i]));
  98474. memcpy(vbi->pcmdelay[i],v->pcm[i],(vb->pcmend+beginW)*sizeof(*vbi->pcmdelay[i]));
  98475. vb->pcm[i]=vbi->pcmdelay[i]+beginW;
  98476. }
  98477. if(v->eofflag){
  98478. if(v->centerW>=v->eofflag){
  98479. v->eofflag=-1;
  98480. vb->eofflag=1;
  98481. return(1);
  98482. }
  98483. }
  98484. {
  98485. int new_centerNext=ci->blocksizes[1]/2;
  98486. int movementW=centerNext-new_centerNext;
  98487. if(movementW>0){
  98488. _ve_envelope_shift(b->ve,movementW);
  98489. v->pcm_current-=movementW;
  98490. for(i=0;i<vi->channels;i++)
  98491. memmove(v->pcm[i],v->pcm[i]+movementW,
  98492. v->pcm_current*sizeof(*v->pcm[i]));
  98493. v->lW=v->W;
  98494. v->W=v->nW;
  98495. v->centerW=new_centerNext;
  98496. if(v->eofflag){
  98497. v->eofflag-=movementW;
  98498. if(v->eofflag<=0)v->eofflag=-1;
  98499. if(v->centerW>=v->eofflag){
  98500. v->granulepos+=movementW-(v->centerW-v->eofflag);
  98501. }else{
  98502. v->granulepos+=movementW;
  98503. }
  98504. }else{
  98505. v->granulepos+=movementW;
  98506. }
  98507. }
  98508. }
  98509. return(1);
  98510. }
  98511. int vorbis_synthesis_restart(vorbis_dsp_state *v){
  98512. vorbis_info *vi=v->vi;
  98513. codec_setup_info *ci;
  98514. int hs;
  98515. if(!v->backend_state)return -1;
  98516. if(!vi)return -1;
  98517. ci=(codec_setup_info*) vi->codec_setup;
  98518. if(!ci)return -1;
  98519. hs=ci->halfrate_flag;
  98520. v->centerW=ci->blocksizes[1]>>(hs+1);
  98521. v->pcm_current=v->centerW>>hs;
  98522. v->pcm_returned=-1;
  98523. v->granulepos=-1;
  98524. v->sequence=-1;
  98525. v->eofflag=0;
  98526. ((private_state *)(v->backend_state))->sample_count=-1;
  98527. return(0);
  98528. }
  98529. int vorbis_synthesis_init(vorbis_dsp_state *v,vorbis_info *vi){
  98530. if(_vds_shared_init(v,vi,0)) return 1;
  98531. vorbis_synthesis_restart(v);
  98532. return 0;
  98533. }
  98534. int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb){
  98535. vorbis_info *vi=v->vi;
  98536. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98537. private_state *b=(private_state*)v->backend_state;
  98538. int hs=ci->halfrate_flag;
  98539. int i,j;
  98540. if(!vb)return(OV_EINVAL);
  98541. if(v->pcm_current>v->pcm_returned && v->pcm_returned!=-1)return(OV_EINVAL);
  98542. v->lW=v->W;
  98543. v->W=vb->W;
  98544. v->nW=-1;
  98545. if((v->sequence==-1)||
  98546. (v->sequence+1 != vb->sequence)){
  98547. v->granulepos=-1; /* out of sequence; lose count */
  98548. b->sample_count=-1;
  98549. }
  98550. v->sequence=vb->sequence;
  98551. if(vb->pcm){ /* no pcm to process if vorbis_synthesis_trackonly
  98552. was called on block */
  98553. int n=ci->blocksizes[v->W]>>(hs+1);
  98554. int n0=ci->blocksizes[0]>>(hs+1);
  98555. int n1=ci->blocksizes[1]>>(hs+1);
  98556. int thisCenter;
  98557. int prevCenter;
  98558. v->glue_bits+=vb->glue_bits;
  98559. v->time_bits+=vb->time_bits;
  98560. v->floor_bits+=vb->floor_bits;
  98561. v->res_bits+=vb->res_bits;
  98562. if(v->centerW){
  98563. thisCenter=n1;
  98564. prevCenter=0;
  98565. }else{
  98566. thisCenter=0;
  98567. prevCenter=n1;
  98568. }
  98569. for(j=0;j<vi->channels;j++){
  98570. if(v->lW){
  98571. if(v->W){
  98572. float *w=_vorbis_window_get(b->window[1]-hs);
  98573. float *pcm=v->pcm[j]+prevCenter;
  98574. float *p=vb->pcm[j];
  98575. for(i=0;i<n1;i++)
  98576. pcm[i]=pcm[i]*w[n1-i-1] + p[i]*w[i];
  98577. }else{
  98578. float *w=_vorbis_window_get(b->window[0]-hs);
  98579. float *pcm=v->pcm[j]+prevCenter+n1/2-n0/2;
  98580. float *p=vb->pcm[j];
  98581. for(i=0;i<n0;i++)
  98582. pcm[i]=pcm[i]*w[n0-i-1] +p[i]*w[i];
  98583. }
  98584. }else{
  98585. if(v->W){
  98586. float *w=_vorbis_window_get(b->window[0]-hs);
  98587. float *pcm=v->pcm[j]+prevCenter;
  98588. float *p=vb->pcm[j]+n1/2-n0/2;
  98589. for(i=0;i<n0;i++)
  98590. pcm[i]=pcm[i]*w[n0-i-1] +p[i]*w[i];
  98591. for(;i<n1/2+n0/2;i++)
  98592. pcm[i]=p[i];
  98593. }else{
  98594. float *w=_vorbis_window_get(b->window[0]-hs);
  98595. float *pcm=v->pcm[j]+prevCenter;
  98596. float *p=vb->pcm[j];
  98597. for(i=0;i<n0;i++)
  98598. pcm[i]=pcm[i]*w[n0-i-1] +p[i]*w[i];
  98599. }
  98600. }
  98601. {
  98602. float *pcm=v->pcm[j]+thisCenter;
  98603. float *p=vb->pcm[j]+n;
  98604. for(i=0;i<n;i++)
  98605. pcm[i]=p[i];
  98606. }
  98607. }
  98608. if(v->centerW)
  98609. v->centerW=0;
  98610. else
  98611. v->centerW=n1;
  98612. if(v->pcm_returned==-1){
  98613. v->pcm_returned=thisCenter;
  98614. v->pcm_current=thisCenter;
  98615. }else{
  98616. v->pcm_returned=prevCenter;
  98617. v->pcm_current=prevCenter+
  98618. ((ci->blocksizes[v->lW]/4+
  98619. ci->blocksizes[v->W]/4)>>hs);
  98620. }
  98621. }
  98622. if(b->sample_count==-1){
  98623. b->sample_count=0;
  98624. }else{
  98625. b->sample_count+=ci->blocksizes[v->lW]/4+ci->blocksizes[v->W]/4;
  98626. }
  98627. if(v->granulepos==-1){
  98628. if(vb->granulepos!=-1){ /* only set if we have a position to set to */
  98629. v->granulepos=vb->granulepos;
  98630. if(b->sample_count>v->granulepos){
  98631. if(vb->eofflag){
  98632. v->pcm_current-=(b->sample_count-v->granulepos)>>hs;
  98633. }else{
  98634. v->pcm_returned+=(b->sample_count-v->granulepos)>>hs;
  98635. if(v->pcm_returned>v->pcm_current)
  98636. v->pcm_returned=v->pcm_current;
  98637. }
  98638. }
  98639. }
  98640. }else{
  98641. v->granulepos+=ci->blocksizes[v->lW]/4+ci->blocksizes[v->W]/4;
  98642. if(vb->granulepos!=-1 && v->granulepos!=vb->granulepos){
  98643. if(v->granulepos>vb->granulepos){
  98644. long extra=v->granulepos-vb->granulepos;
  98645. if(extra)
  98646. if(vb->eofflag){
  98647. v->pcm_current-=extra>>hs;
  98648. } /* else {Shouldn't happen *unless* the bitstream is out of
  98649. spec. Either way, believe the bitstream } */
  98650. } /* else {Shouldn't happen *unless* the bitstream is out of
  98651. spec. Either way, believe the bitstream } */
  98652. v->granulepos=vb->granulepos;
  98653. }
  98654. }
  98655. if(vb->eofflag)v->eofflag=1;
  98656. return(0);
  98657. }
  98658. int vorbis_synthesis_pcmout(vorbis_dsp_state *v,float ***pcm){
  98659. vorbis_info *vi=v->vi;
  98660. if(v->pcm_returned>-1 && v->pcm_returned<v->pcm_current){
  98661. if(pcm){
  98662. int i;
  98663. for(i=0;i<vi->channels;i++)
  98664. v->pcmret[i]=v->pcm[i]+v->pcm_returned;
  98665. *pcm=v->pcmret;
  98666. }
  98667. return(v->pcm_current-v->pcm_returned);
  98668. }
  98669. return(0);
  98670. }
  98671. int vorbis_synthesis_read(vorbis_dsp_state *v,int n){
  98672. if(n && v->pcm_returned+n>v->pcm_current)return(OV_EINVAL);
  98673. v->pcm_returned+=n;
  98674. return(0);
  98675. }
  98676. int vorbis_synthesis_lapout(vorbis_dsp_state *v,float ***pcm){
  98677. vorbis_info *vi=v->vi;
  98678. codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
  98679. int hs=ci->halfrate_flag;
  98680. int n=ci->blocksizes[v->W]>>(hs+1);
  98681. int n0=ci->blocksizes[0]>>(hs+1);
  98682. int n1=ci->blocksizes[1]>>(hs+1);
  98683. int i,j;
  98684. if(v->pcm_returned<0)return 0;
  98685. if(v->centerW==n1){
  98686. for(j=0;j<vi->channels;j++){
  98687. float *p=v->pcm[j];
  98688. for(i=0;i<n1;i++){
  98689. float temp=p[i];
  98690. p[i]=p[i+n1];
  98691. p[i+n1]=temp;
  98692. }
  98693. }
  98694. v->pcm_current-=n1;
  98695. v->pcm_returned-=n1;
  98696. v->centerW=0;
  98697. }
  98698. if((v->lW^v->W)==1){
  98699. for(j=0;j<vi->channels;j++){
  98700. float *s=v->pcm[j];
  98701. float *d=v->pcm[j]+(n1-n0)/2;
  98702. for(i=(n1+n0)/2-1;i>=0;--i)
  98703. d[i]=s[i];
  98704. }
  98705. v->pcm_returned+=(n1-n0)/2;
  98706. v->pcm_current+=(n1-n0)/2;
  98707. }else{
  98708. if(v->lW==0){
  98709. for(j=0;j<vi->channels;j++){
  98710. float *s=v->pcm[j];
  98711. float *d=v->pcm[j]+n1-n0;
  98712. for(i=n0-1;i>=0;--i)
  98713. d[i]=s[i];
  98714. }
  98715. v->pcm_returned+=n1-n0;
  98716. v->pcm_current+=n1-n0;
  98717. }
  98718. }
  98719. if(pcm){
  98720. int i;
  98721. for(i=0;i<vi->channels;i++)
  98722. v->pcmret[i]=v->pcm[i]+v->pcm_returned;
  98723. *pcm=v->pcmret;
  98724. }
  98725. return(n1+n-v->pcm_returned);
  98726. }
  98727. float *vorbis_window(vorbis_dsp_state *v,int W){
  98728. vorbis_info *vi=v->vi;
  98729. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  98730. int hs=ci->halfrate_flag;
  98731. private_state *b=(private_state*)v->backend_state;
  98732. if(b->window[W]-1<0)return NULL;
  98733. return _vorbis_window_get(b->window[W]-hs);
  98734. }
  98735. #endif
  98736. /*** End of inlined file: block.c ***/
  98737. /*** Start of inlined file: codebook.c ***/
  98738. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  98739. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  98740. // tasks..
  98741. #if JUCE_MSVC
  98742. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  98743. #endif
  98744. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  98745. #if JUCE_USE_OGGVORBIS
  98746. #include <stdlib.h>
  98747. #include <string.h>
  98748. #include <math.h>
  98749. int vorbis_staticbook_pack(const static_codebook *c,oggpack_buffer *opb){
  98750. long i,j;
  98751. int ordered=0;
  98752. oggpack_write(opb,0x564342,24);
  98753. oggpack_write(opb,c->dim,16);
  98754. oggpack_write(opb,c->entries,24);
  98755. for(i=1;i<c->entries;i++)
  98756. if(c->lengthlist[i-1]==0 || c->lengthlist[i]<c->lengthlist[i-1])break;
  98757. if(i==c->entries)ordered=1;
  98758. if(ordered){
  98759. long count=0;
  98760. oggpack_write(opb,1,1); /* ordered */
  98761. oggpack_write(opb,c->lengthlist[0]-1,5); /* 1 to 32 */
  98762. for(i=1;i<c->entries;i++){
  98763. long thisx=c->lengthlist[i];
  98764. long last=c->lengthlist[i-1];
  98765. if(thisx>last){
  98766. for(j=last;j<thisx;j++){
  98767. oggpack_write(opb,i-count,_ilog(c->entries-count));
  98768. count=i;
  98769. }
  98770. }
  98771. }
  98772. oggpack_write(opb,i-count,_ilog(c->entries-count));
  98773. }else{
  98774. oggpack_write(opb,0,1); /* unordered */
  98775. for(i=0;i<c->entries;i++)
  98776. if(c->lengthlist[i]==0)break;
  98777. if(i==c->entries){
  98778. oggpack_write(opb,0,1); /* no unused entries */
  98779. for(i=0;i<c->entries;i++)
  98780. oggpack_write(opb,c->lengthlist[i]-1,5);
  98781. }else{
  98782. oggpack_write(opb,1,1); /* we have unused entries; thus we tag */
  98783. for(i=0;i<c->entries;i++){
  98784. if(c->lengthlist[i]==0){
  98785. oggpack_write(opb,0,1);
  98786. }else{
  98787. oggpack_write(opb,1,1);
  98788. oggpack_write(opb,c->lengthlist[i]-1,5);
  98789. }
  98790. }
  98791. }
  98792. }
  98793. oggpack_write(opb,c->maptype,4);
  98794. switch(c->maptype){
  98795. case 0:
  98796. break;
  98797. case 1:case 2:
  98798. if(!c->quantlist){
  98799. return(-1);
  98800. }
  98801. oggpack_write(opb,c->q_min,32);
  98802. oggpack_write(opb,c->q_delta,32);
  98803. oggpack_write(opb,c->q_quant-1,4);
  98804. oggpack_write(opb,c->q_sequencep,1);
  98805. {
  98806. int quantvals;
  98807. switch(c->maptype){
  98808. case 1:
  98809. quantvals=_book_maptype1_quantvals(c);
  98810. break;
  98811. case 2:
  98812. quantvals=c->entries*c->dim;
  98813. break;
  98814. default: /* NOT_REACHABLE */
  98815. quantvals=-1;
  98816. }
  98817. for(i=0;i<quantvals;i++)
  98818. oggpack_write(opb,labs(c->quantlist[i]),c->q_quant);
  98819. }
  98820. break;
  98821. default:
  98822. return(-1);
  98823. }
  98824. return(0);
  98825. }
  98826. int vorbis_staticbook_unpack(oggpack_buffer *opb,static_codebook *s){
  98827. long i,j;
  98828. memset(s,0,sizeof(*s));
  98829. s->allocedp=1;
  98830. if(oggpack_read(opb,24)!=0x564342)goto _eofout;
  98831. s->dim=oggpack_read(opb,16);
  98832. s->entries=oggpack_read(opb,24);
  98833. if(s->entries==-1)goto _eofout;
  98834. switch((int)oggpack_read(opb,1)){
  98835. case 0:
  98836. s->lengthlist=(long*)_ogg_malloc(sizeof(*s->lengthlist)*s->entries);
  98837. if(oggpack_read(opb,1)){
  98838. for(i=0;i<s->entries;i++){
  98839. if(oggpack_read(opb,1)){
  98840. long num=oggpack_read(opb,5);
  98841. if(num==-1)goto _eofout;
  98842. s->lengthlist[i]=num+1;
  98843. }else
  98844. s->lengthlist[i]=0;
  98845. }
  98846. }else{
  98847. for(i=0;i<s->entries;i++){
  98848. long num=oggpack_read(opb,5);
  98849. if(num==-1)goto _eofout;
  98850. s->lengthlist[i]=num+1;
  98851. }
  98852. }
  98853. break;
  98854. case 1:
  98855. {
  98856. long length=oggpack_read(opb,5)+1;
  98857. s->lengthlist=(long*)_ogg_malloc(sizeof(*s->lengthlist)*s->entries);
  98858. for(i=0;i<s->entries;){
  98859. long num=oggpack_read(opb,_ilog(s->entries-i));
  98860. if(num==-1)goto _eofout;
  98861. for(j=0;j<num && i<s->entries;j++,i++)
  98862. s->lengthlist[i]=length;
  98863. length++;
  98864. }
  98865. }
  98866. break;
  98867. default:
  98868. return(-1);
  98869. }
  98870. switch((s->maptype=oggpack_read(opb,4))){
  98871. case 0:
  98872. break;
  98873. case 1: case 2:
  98874. s->q_min=oggpack_read(opb,32);
  98875. s->q_delta=oggpack_read(opb,32);
  98876. s->q_quant=oggpack_read(opb,4)+1;
  98877. s->q_sequencep=oggpack_read(opb,1);
  98878. {
  98879. int quantvals=0;
  98880. switch(s->maptype){
  98881. case 1:
  98882. quantvals=_book_maptype1_quantvals(s);
  98883. break;
  98884. case 2:
  98885. quantvals=s->entries*s->dim;
  98886. break;
  98887. }
  98888. s->quantlist=(long*)_ogg_malloc(sizeof(*s->quantlist)*quantvals);
  98889. for(i=0;i<quantvals;i++)
  98890. s->quantlist[i]=oggpack_read(opb,s->q_quant);
  98891. if(quantvals&&s->quantlist[quantvals-1]==-1)goto _eofout;
  98892. }
  98893. break;
  98894. default:
  98895. goto _errout;
  98896. }
  98897. return(0);
  98898. _errout:
  98899. _eofout:
  98900. vorbis_staticbook_clear(s);
  98901. return(-1);
  98902. }
  98903. int vorbis_book_encode(codebook *book, int a, oggpack_buffer *b){
  98904. oggpack_write(b,book->codelist[a],book->c->lengthlist[a]);
  98905. return(book->c->lengthlist[a]);
  98906. }
  98907. int vorbis_book_errorv(codebook *book,float *a){
  98908. int dim=book->dim,k;
  98909. int best=_best(book,a,1);
  98910. for(k=0;k<dim;k++)
  98911. a[k]=(book->valuelist+best*dim)[k];
  98912. return(best);
  98913. }
  98914. int vorbis_book_encodev(codebook *book,int best,float *a,oggpack_buffer *b){
  98915. int k,dim=book->dim;
  98916. for(k=0;k<dim;k++)
  98917. a[k]=(book->valuelist+best*dim)[k];
  98918. return(vorbis_book_encode(book,best,b));
  98919. }
  98920. STIN long decode_packed_entry_number(codebook *book, oggpack_buffer *b){
  98921. int read=book->dec_maxlength;
  98922. long lo,hi;
  98923. long lok = oggpack_look(b,book->dec_firsttablen);
  98924. if (lok >= 0) {
  98925. long entry = book->dec_firsttable[lok];
  98926. if(entry&0x80000000UL){
  98927. lo=(entry>>15)&0x7fff;
  98928. hi=book->used_entries-(entry&0x7fff);
  98929. }else{
  98930. oggpack_adv(b, book->dec_codelengths[entry-1]);
  98931. return(entry-1);
  98932. }
  98933. }else{
  98934. lo=0;
  98935. hi=book->used_entries;
  98936. }
  98937. lok = oggpack_look(b, read);
  98938. while(lok<0 && read>1)
  98939. lok = oggpack_look(b, --read);
  98940. if(lok<0)return -1;
  98941. {
  98942. ogg_uint32_t testword=ogg_bitreverse((ogg_uint32_t)lok);
  98943. while(hi-lo>1){
  98944. long p=(hi-lo)>>1;
  98945. long test=book->codelist[lo+p]>testword;
  98946. lo+=p&(test-1);
  98947. hi-=p&(-test);
  98948. }
  98949. if(book->dec_codelengths[lo]<=read){
  98950. oggpack_adv(b, book->dec_codelengths[lo]);
  98951. return(lo);
  98952. }
  98953. }
  98954. oggpack_adv(b, read);
  98955. return(-1);
  98956. }
  98957. long vorbis_book_decode(codebook *book, oggpack_buffer *b){
  98958. long packed_entry=decode_packed_entry_number(book,b);
  98959. if(packed_entry>=0)
  98960. return(book->dec_index[packed_entry]);
  98961. return(packed_entry);
  98962. }
  98963. long vorbis_book_decodevs_add(codebook *book,float *a,oggpack_buffer *b,int n){
  98964. int step=n/book->dim;
  98965. long *entry = (long*)alloca(sizeof(*entry)*step);
  98966. float **t = (float**)alloca(sizeof(*t)*step);
  98967. int i,j,o;
  98968. for (i = 0; i < step; i++) {
  98969. entry[i]=decode_packed_entry_number(book,b);
  98970. if(entry[i]==-1)return(-1);
  98971. t[i] = book->valuelist+entry[i]*book->dim;
  98972. }
  98973. for(i=0,o=0;i<book->dim;i++,o+=step)
  98974. for (j=0;j<step;j++)
  98975. a[o+j]+=t[j][i];
  98976. return(0);
  98977. }
  98978. long vorbis_book_decodev_add(codebook *book,float *a,oggpack_buffer *b,int n){
  98979. int i,j,entry;
  98980. float *t;
  98981. if(book->dim>8){
  98982. for(i=0;i<n;){
  98983. entry = decode_packed_entry_number(book,b);
  98984. if(entry==-1)return(-1);
  98985. t = book->valuelist+entry*book->dim;
  98986. for (j=0;j<book->dim;)
  98987. a[i++]+=t[j++];
  98988. }
  98989. }else{
  98990. for(i=0;i<n;){
  98991. entry = decode_packed_entry_number(book,b);
  98992. if(entry==-1)return(-1);
  98993. t = book->valuelist+entry*book->dim;
  98994. j=0;
  98995. switch((int)book->dim){
  98996. case 8:
  98997. a[i++]+=t[j++];
  98998. case 7:
  98999. a[i++]+=t[j++];
  99000. case 6:
  99001. a[i++]+=t[j++];
  99002. case 5:
  99003. a[i++]+=t[j++];
  99004. case 4:
  99005. a[i++]+=t[j++];
  99006. case 3:
  99007. a[i++]+=t[j++];
  99008. case 2:
  99009. a[i++]+=t[j++];
  99010. case 1:
  99011. a[i++]+=t[j++];
  99012. case 0:
  99013. break;
  99014. }
  99015. }
  99016. }
  99017. return(0);
  99018. }
  99019. long vorbis_book_decodev_set(codebook *book,float *a,oggpack_buffer *b,int n){
  99020. int i,j,entry;
  99021. float *t;
  99022. for(i=0;i<n;){
  99023. entry = decode_packed_entry_number(book,b);
  99024. if(entry==-1)return(-1);
  99025. t = book->valuelist+entry*book->dim;
  99026. for (j=0;j<book->dim;)
  99027. a[i++]=t[j++];
  99028. }
  99029. return(0);
  99030. }
  99031. long vorbis_book_decodevv_add(codebook *book,float **a,long offset,int ch,
  99032. oggpack_buffer *b,int n){
  99033. long i,j,entry;
  99034. int chptr=0;
  99035. for(i=offset/ch;i<(offset+n)/ch;){
  99036. entry = decode_packed_entry_number(book,b);
  99037. if(entry==-1)return(-1);
  99038. {
  99039. const float *t = book->valuelist+entry*book->dim;
  99040. for (j=0;j<book->dim;j++){
  99041. a[chptr++][i]+=t[j];
  99042. if(chptr==ch){
  99043. chptr=0;
  99044. i++;
  99045. }
  99046. }
  99047. }
  99048. }
  99049. return(0);
  99050. }
  99051. #ifdef _V_SELFTEST
  99052. #include <stdio.h>
  99053. #include "vorbis/book/lsp20_0.vqh"
  99054. #include "vorbis/book/res0a_13.vqh"
  99055. #define TESTSIZE 40
  99056. float test1[TESTSIZE]={
  99057. 0.105939f,
  99058. 0.215373f,
  99059. 0.429117f,
  99060. 0.587974f,
  99061. 0.181173f,
  99062. 0.296583f,
  99063. 0.515707f,
  99064. 0.715261f,
  99065. 0.162327f,
  99066. 0.263834f,
  99067. 0.342876f,
  99068. 0.406025f,
  99069. 0.103571f,
  99070. 0.223561f,
  99071. 0.368513f,
  99072. 0.540313f,
  99073. 0.136672f,
  99074. 0.395882f,
  99075. 0.587183f,
  99076. 0.652476f,
  99077. 0.114338f,
  99078. 0.417300f,
  99079. 0.525486f,
  99080. 0.698679f,
  99081. 0.147492f,
  99082. 0.324481f,
  99083. 0.643089f,
  99084. 0.757582f,
  99085. 0.139556f,
  99086. 0.215795f,
  99087. 0.324559f,
  99088. 0.399387f,
  99089. 0.120236f,
  99090. 0.267420f,
  99091. 0.446940f,
  99092. 0.608760f,
  99093. 0.115587f,
  99094. 0.287234f,
  99095. 0.571081f,
  99096. 0.708603f,
  99097. };
  99098. float test3[TESTSIZE]={
  99099. 0,1,-2,3,4,-5,6,7,8,9,
  99100. 8,-2,7,-1,4,6,8,3,1,-9,
  99101. 10,11,12,13,14,15,26,17,18,19,
  99102. 30,-25,-30,-1,-5,-32,4,3,-2,0};
  99103. static_codebook *testlist[]={&_vq_book_lsp20_0,
  99104. &_vq_book_res0a_13,NULL};
  99105. float *testvec[]={test1,test3};
  99106. int main(){
  99107. oggpack_buffer write;
  99108. oggpack_buffer read;
  99109. long ptr=0,i;
  99110. oggpack_writeinit(&write);
  99111. fprintf(stderr,"Testing codebook abstraction...:\n");
  99112. while(testlist[ptr]){
  99113. codebook c;
  99114. static_codebook s;
  99115. float *qv=alloca(sizeof(*qv)*TESTSIZE);
  99116. float *iv=alloca(sizeof(*iv)*TESTSIZE);
  99117. memcpy(qv,testvec[ptr],sizeof(*qv)*TESTSIZE);
  99118. memset(iv,0,sizeof(*iv)*TESTSIZE);
  99119. fprintf(stderr,"\tpacking/coding %ld... ",ptr);
  99120. oggpack_reset(&write);
  99121. vorbis_book_init_encode(&c,testlist[ptr]); /* get it into memory
  99122. we can write */
  99123. vorbis_staticbook_pack(testlist[ptr],&write);
  99124. fprintf(stderr,"Codebook size %ld bytes... ",oggpack_bytes(&write));
  99125. for(i=0;i<TESTSIZE;i+=c.dim){
  99126. int best=_best(&c,qv+i,1);
  99127. vorbis_book_encodev(&c,best,qv+i,&write);
  99128. }
  99129. vorbis_book_clear(&c);
  99130. fprintf(stderr,"OK.\n");
  99131. fprintf(stderr,"\tunpacking/decoding %ld... ",ptr);
  99132. oggpack_readinit(&read,oggpack_get_buffer(&write),oggpack_bytes(&write));
  99133. if(vorbis_staticbook_unpack(&read,&s)){
  99134. fprintf(stderr,"Error unpacking codebook.\n");
  99135. exit(1);
  99136. }
  99137. if(vorbis_book_init_decode(&c,&s)){
  99138. fprintf(stderr,"Error initializing codebook.\n");
  99139. exit(1);
  99140. }
  99141. for(i=0;i<TESTSIZE;i+=c.dim)
  99142. if(vorbis_book_decodev_set(&c,iv+i,&read,c.dim)==-1){
  99143. fprintf(stderr,"Error reading codebook test data (EOP).\n");
  99144. exit(1);
  99145. }
  99146. for(i=0;i<TESTSIZE;i++)
  99147. if(fabs(qv[i]-iv[i])>.000001){
  99148. fprintf(stderr,"read (%g) != written (%g) at position (%ld)\n",
  99149. iv[i],qv[i],i);
  99150. exit(1);
  99151. }
  99152. fprintf(stderr,"OK\n");
  99153. ptr++;
  99154. }
  99155. exit(0);
  99156. }
  99157. #endif
  99158. #endif
  99159. /*** End of inlined file: codebook.c ***/
  99160. /*** Start of inlined file: envelope.c ***/
  99161. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  99162. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  99163. // tasks..
  99164. #if JUCE_MSVC
  99165. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  99166. #endif
  99167. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  99168. #if JUCE_USE_OGGVORBIS
  99169. #include <stdlib.h>
  99170. #include <string.h>
  99171. #include <stdio.h>
  99172. #include <math.h>
  99173. void _ve_envelope_init(envelope_lookup *e,vorbis_info *vi){
  99174. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  99175. vorbis_info_psy_global *gi=&ci->psy_g_param;
  99176. int ch=vi->channels;
  99177. int i,j;
  99178. int n=e->winlength=128;
  99179. e->searchstep=64; /* not random */
  99180. e->minenergy=gi->preecho_minenergy;
  99181. e->ch=ch;
  99182. e->storage=128;
  99183. e->cursor=ci->blocksizes[1]/2;
  99184. e->mdct_win=(float*)_ogg_calloc(n,sizeof(*e->mdct_win));
  99185. mdct_init(&e->mdct,n);
  99186. for(i=0;i<n;i++){
  99187. e->mdct_win[i]=sin(i/(n-1.)*M_PI);
  99188. e->mdct_win[i]*=e->mdct_win[i];
  99189. }
  99190. e->band[0].begin=2; e->band[0].end=4;
  99191. e->band[1].begin=4; e->band[1].end=5;
  99192. e->band[2].begin=6; e->band[2].end=6;
  99193. e->band[3].begin=9; e->band[3].end=8;
  99194. e->band[4].begin=13; e->band[4].end=8;
  99195. e->band[5].begin=17; e->band[5].end=8;
  99196. e->band[6].begin=22; e->band[6].end=8;
  99197. for(j=0;j<VE_BANDS;j++){
  99198. n=e->band[j].end;
  99199. e->band[j].window=(float*)_ogg_malloc(n*sizeof(*e->band[0].window));
  99200. for(i=0;i<n;i++){
  99201. e->band[j].window[i]=sin((i+.5)/n*M_PI);
  99202. e->band[j].total+=e->band[j].window[i];
  99203. }
  99204. e->band[j].total=1./e->band[j].total;
  99205. }
  99206. e->filter=(envelope_filter_state*)_ogg_calloc(VE_BANDS*ch,sizeof(*e->filter));
  99207. e->mark=(int*)_ogg_calloc(e->storage,sizeof(*e->mark));
  99208. }
  99209. void _ve_envelope_clear(envelope_lookup *e){
  99210. int i;
  99211. mdct_clear(&e->mdct);
  99212. for(i=0;i<VE_BANDS;i++)
  99213. _ogg_free(e->band[i].window);
  99214. _ogg_free(e->mdct_win);
  99215. _ogg_free(e->filter);
  99216. _ogg_free(e->mark);
  99217. memset(e,0,sizeof(*e));
  99218. }
  99219. static int _ve_amp(envelope_lookup *ve,
  99220. vorbis_info_psy_global *gi,
  99221. float *data,
  99222. envelope_band *bands,
  99223. envelope_filter_state *filters,
  99224. long pos){
  99225. long n=ve->winlength;
  99226. int ret=0;
  99227. long i,j;
  99228. float decay;
  99229. float minV=ve->minenergy;
  99230. float *vec=(float*) alloca(n*sizeof(*vec));
  99231. int stretch=max(VE_MINSTRETCH,ve->stretch/2);
  99232. float penalty=gi->stretch_penalty-(ve->stretch/2-VE_MINSTRETCH);
  99233. if(penalty<0.f)penalty=0.f;
  99234. if(penalty>gi->stretch_penalty)penalty=gi->stretch_penalty;
  99235. for(i=0;i<n;i++)
  99236. vec[i]=data[i]*ve->mdct_win[i];
  99237. mdct_forward(&ve->mdct,vec,vec);
  99238. {
  99239. float temp=vec[0]*vec[0]+.7*vec[1]*vec[1]+.2*vec[2]*vec[2];
  99240. int ptr=filters->nearptr;
  99241. if(ptr==0){
  99242. decay=filters->nearDC_acc=filters->nearDC_partialacc+temp;
  99243. filters->nearDC_partialacc=temp;
  99244. }else{
  99245. decay=filters->nearDC_acc+=temp;
  99246. filters->nearDC_partialacc+=temp;
  99247. }
  99248. filters->nearDC_acc-=filters->nearDC[ptr];
  99249. filters->nearDC[ptr]=temp;
  99250. decay*=(1./(VE_NEARDC+1));
  99251. filters->nearptr++;
  99252. if(filters->nearptr>=VE_NEARDC)filters->nearptr=0;
  99253. decay=todB(&decay)*.5-15.f;
  99254. }
  99255. for(i=0;i<n/2;i+=2){
  99256. float val=vec[i]*vec[i]+vec[i+1]*vec[i+1];
  99257. val=todB(&val)*.5f;
  99258. if(val<decay)val=decay;
  99259. if(val<minV)val=minV;
  99260. vec[i>>1]=val;
  99261. decay-=8.;
  99262. }
  99263. for(j=0;j<VE_BANDS;j++){
  99264. float acc=0.;
  99265. float valmax,valmin;
  99266. for(i=0;i<bands[j].end;i++)
  99267. acc+=vec[i+bands[j].begin]*bands[j].window[i];
  99268. acc*=bands[j].total;
  99269. {
  99270. int p,thisx=filters[j].ampptr;
  99271. float postmax,postmin,premax=-99999.f,premin=99999.f;
  99272. p=thisx;
  99273. p--;
  99274. if(p<0)p+=VE_AMP;
  99275. postmax=max(acc,filters[j].ampbuf[p]);
  99276. postmin=min(acc,filters[j].ampbuf[p]);
  99277. for(i=0;i<stretch;i++){
  99278. p--;
  99279. if(p<0)p+=VE_AMP;
  99280. premax=max(premax,filters[j].ampbuf[p]);
  99281. premin=min(premin,filters[j].ampbuf[p]);
  99282. }
  99283. valmin=postmin-premin;
  99284. valmax=postmax-premax;
  99285. filters[j].ampbuf[thisx]=acc;
  99286. filters[j].ampptr++;
  99287. if(filters[j].ampptr>=VE_AMP)filters[j].ampptr=0;
  99288. }
  99289. if(valmax>gi->preecho_thresh[j]+penalty){
  99290. ret|=1;
  99291. ret|=4;
  99292. }
  99293. if(valmin<gi->postecho_thresh[j]-penalty)ret|=2;
  99294. }
  99295. return(ret);
  99296. }
  99297. #if 0
  99298. static int seq=0;
  99299. static ogg_int64_t totalshift=-1024;
  99300. #endif
  99301. long _ve_envelope_search(vorbis_dsp_state *v){
  99302. vorbis_info *vi=v->vi;
  99303. codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
  99304. vorbis_info_psy_global *gi=&ci->psy_g_param;
  99305. envelope_lookup *ve=((private_state *)(v->backend_state))->ve;
  99306. long i,j;
  99307. int first=ve->current/ve->searchstep;
  99308. int last=v->pcm_current/ve->searchstep-VE_WIN;
  99309. if(first<0)first=0;
  99310. if(last+VE_WIN+VE_POST>ve->storage){
  99311. ve->storage=last+VE_WIN+VE_POST; /* be sure */
  99312. ve->mark=(int*)_ogg_realloc(ve->mark,ve->storage*sizeof(*ve->mark));
  99313. }
  99314. for(j=first;j<last;j++){
  99315. int ret=0;
  99316. ve->stretch++;
  99317. if(ve->stretch>VE_MAXSTRETCH*2)
  99318. ve->stretch=VE_MAXSTRETCH*2;
  99319. for(i=0;i<ve->ch;i++){
  99320. float *pcm=v->pcm[i]+ve->searchstep*(j);
  99321. ret|=_ve_amp(ve,gi,pcm,ve->band,ve->filter+i*VE_BANDS,j);
  99322. }
  99323. ve->mark[j+VE_POST]=0;
  99324. if(ret&1){
  99325. ve->mark[j]=1;
  99326. ve->mark[j+1]=1;
  99327. }
  99328. if(ret&2){
  99329. ve->mark[j]=1;
  99330. if(j>0)ve->mark[j-1]=1;
  99331. }
  99332. if(ret&4)ve->stretch=-1;
  99333. }
  99334. ve->current=last*ve->searchstep;
  99335. {
  99336. long centerW=v->centerW;
  99337. long testW=
  99338. centerW+
  99339. ci->blocksizes[v->W]/4+
  99340. ci->blocksizes[1]/2+
  99341. ci->blocksizes[0]/4;
  99342. j=ve->cursor;
  99343. while(j<ve->current-(ve->searchstep)){/* account for postecho
  99344. working back one window */
  99345. if(j>=testW)return(1);
  99346. ve->cursor=j;
  99347. if(ve->mark[j/ve->searchstep]){
  99348. if(j>centerW){
  99349. #if 0
  99350. if(j>ve->curmark){
  99351. float *marker=alloca(v->pcm_current*sizeof(*marker));
  99352. int l,m;
  99353. memset(marker,0,sizeof(*marker)*v->pcm_current);
  99354. fprintf(stderr,"mark! seq=%d, cursor:%fs time:%fs\n",
  99355. seq,
  99356. (totalshift+ve->cursor)/44100.,
  99357. (totalshift+j)/44100.);
  99358. _analysis_output_always("pcmL",seq,v->pcm[0],v->pcm_current,0,0,totalshift);
  99359. _analysis_output_always("pcmR",seq,v->pcm[1],v->pcm_current,0,0,totalshift);
  99360. _analysis_output_always("markL",seq,v->pcm[0],j,0,0,totalshift);
  99361. _analysis_output_always("markR",seq,v->pcm[1],j,0,0,totalshift);
  99362. for(m=0;m<VE_BANDS;m++){
  99363. char buf[80];
  99364. sprintf(buf,"delL%d",m);
  99365. for(l=0;l<last;l++)marker[l*ve->searchstep]=ve->filter[m].markers[l]*.1;
  99366. _analysis_output_always(buf,seq,marker,v->pcm_current,0,0,totalshift);
  99367. }
  99368. for(m=0;m<VE_BANDS;m++){
  99369. char buf[80];
  99370. sprintf(buf,"delR%d",m);
  99371. for(l=0;l<last;l++)marker[l*ve->searchstep]=ve->filter[m+VE_BANDS].markers[l]*.1;
  99372. _analysis_output_always(buf,seq,marker,v->pcm_current,0,0,totalshift);
  99373. }
  99374. for(l=0;l<last;l++)marker[l*ve->searchstep]=ve->mark[l]*.4;
  99375. _analysis_output_always("mark",seq,marker,v->pcm_current,0,0,totalshift);
  99376. seq++;
  99377. }
  99378. #endif
  99379. ve->curmark=j;
  99380. if(j>=testW)return(1);
  99381. return(0);
  99382. }
  99383. }
  99384. j+=ve->searchstep;
  99385. }
  99386. }
  99387. return(-1);
  99388. }
  99389. int _ve_envelope_mark(vorbis_dsp_state *v){
  99390. envelope_lookup *ve=((private_state *)(v->backend_state))->ve;
  99391. vorbis_info *vi=v->vi;
  99392. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  99393. long centerW=v->centerW;
  99394. long beginW=centerW-ci->blocksizes[v->W]/4;
  99395. long endW=centerW+ci->blocksizes[v->W]/4;
  99396. if(v->W){
  99397. beginW-=ci->blocksizes[v->lW]/4;
  99398. endW+=ci->blocksizes[v->nW]/4;
  99399. }else{
  99400. beginW-=ci->blocksizes[0]/4;
  99401. endW+=ci->blocksizes[0]/4;
  99402. }
  99403. if(ve->curmark>=beginW && ve->curmark<endW)return(1);
  99404. {
  99405. long first=beginW/ve->searchstep;
  99406. long last=endW/ve->searchstep;
  99407. long i;
  99408. for(i=first;i<last;i++)
  99409. if(ve->mark[i])return(1);
  99410. }
  99411. return(0);
  99412. }
  99413. void _ve_envelope_shift(envelope_lookup *e,long shift){
  99414. int smallsize=e->current/e->searchstep+VE_POST; /* adjust for placing marks
  99415. ahead of ve->current */
  99416. int smallshift=shift/e->searchstep;
  99417. memmove(e->mark,e->mark+smallshift,(smallsize-smallshift)*sizeof(*e->mark));
  99418. #if 0
  99419. for(i=0;i<VE_BANDS*e->ch;i++)
  99420. memmove(e->filter[i].markers,
  99421. e->filter[i].markers+smallshift,
  99422. (1024-smallshift)*sizeof(*(*e->filter).markers));
  99423. totalshift+=shift;
  99424. #endif
  99425. e->current-=shift;
  99426. if(e->curmark>=0)
  99427. e->curmark-=shift;
  99428. e->cursor-=shift;
  99429. }
  99430. #endif
  99431. /*** End of inlined file: envelope.c ***/
  99432. /*** Start of inlined file: floor0.c ***/
  99433. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  99434. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  99435. // tasks..
  99436. #if JUCE_MSVC
  99437. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  99438. #endif
  99439. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  99440. #if JUCE_USE_OGGVORBIS
  99441. #include <stdlib.h>
  99442. #include <string.h>
  99443. #include <math.h>
  99444. /*** Start of inlined file: lsp.h ***/
  99445. #ifndef _V_LSP_H_
  99446. #define _V_LSP_H_
  99447. extern int vorbis_lpc_to_lsp(float *lpc,float *lsp,int m);
  99448. extern void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,
  99449. float *lsp,int m,
  99450. float amp,float ampoffset);
  99451. #endif
  99452. /*** End of inlined file: lsp.h ***/
  99453. #include <stdio.h>
  99454. typedef struct {
  99455. int ln;
  99456. int m;
  99457. int **linearmap;
  99458. int n[2];
  99459. vorbis_info_floor0 *vi;
  99460. long bits;
  99461. long frames;
  99462. } vorbis_look_floor0;
  99463. static void floor0_free_info(vorbis_info_floor *i){
  99464. vorbis_info_floor0 *info=(vorbis_info_floor0 *)i;
  99465. if(info){
  99466. memset(info,0,sizeof(*info));
  99467. _ogg_free(info);
  99468. }
  99469. }
  99470. static void floor0_free_look(vorbis_look_floor *i){
  99471. vorbis_look_floor0 *look=(vorbis_look_floor0 *)i;
  99472. if(look){
  99473. if(look->linearmap){
  99474. if(look->linearmap[0])_ogg_free(look->linearmap[0]);
  99475. if(look->linearmap[1])_ogg_free(look->linearmap[1]);
  99476. _ogg_free(look->linearmap);
  99477. }
  99478. memset(look,0,sizeof(*look));
  99479. _ogg_free(look);
  99480. }
  99481. }
  99482. static vorbis_info_floor *floor0_unpack (vorbis_info *vi,oggpack_buffer *opb){
  99483. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  99484. int j;
  99485. vorbis_info_floor0 *info=(vorbis_info_floor0*)_ogg_malloc(sizeof(*info));
  99486. info->order=oggpack_read(opb,8);
  99487. info->rate=oggpack_read(opb,16);
  99488. info->barkmap=oggpack_read(opb,16);
  99489. info->ampbits=oggpack_read(opb,6);
  99490. info->ampdB=oggpack_read(opb,8);
  99491. info->numbooks=oggpack_read(opb,4)+1;
  99492. if(info->order<1)goto err_out;
  99493. if(info->rate<1)goto err_out;
  99494. if(info->barkmap<1)goto err_out;
  99495. if(info->numbooks<1)goto err_out;
  99496. for(j=0;j<info->numbooks;j++){
  99497. info->books[j]=oggpack_read(opb,8);
  99498. if(info->books[j]<0 || info->books[j]>=ci->books)goto err_out;
  99499. }
  99500. return(info);
  99501. err_out:
  99502. floor0_free_info(info);
  99503. return(NULL);
  99504. }
  99505. static void floor0_map_lazy_init(vorbis_block *vb,
  99506. vorbis_info_floor *infoX,
  99507. vorbis_look_floor0 *look){
  99508. if(!look->linearmap[vb->W]){
  99509. vorbis_dsp_state *vd=vb->vd;
  99510. vorbis_info *vi=vd->vi;
  99511. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  99512. vorbis_info_floor0 *info=(vorbis_info_floor0 *)infoX;
  99513. int W=vb->W;
  99514. int n=ci->blocksizes[W]/2,j;
  99515. float scale=look->ln/toBARK(info->rate/2.f);
  99516. look->linearmap[W]=(int*)_ogg_malloc((n+1)*sizeof(**look->linearmap));
  99517. for(j=0;j<n;j++){
  99518. int val=floor( toBARK((info->rate/2.f)/n*j)
  99519. *scale); /* bark numbers represent band edges */
  99520. if(val>=look->ln)val=look->ln-1; /* guard against the approximation */
  99521. look->linearmap[W][j]=val;
  99522. }
  99523. look->linearmap[W][j]=-1;
  99524. look->n[W]=n;
  99525. }
  99526. }
  99527. static vorbis_look_floor *floor0_look(vorbis_dsp_state *vd,
  99528. vorbis_info_floor *i){
  99529. vorbis_info_floor0 *info=(vorbis_info_floor0*)i;
  99530. vorbis_look_floor0 *look=(vorbis_look_floor0*)_ogg_calloc(1,sizeof(*look));
  99531. look->m=info->order;
  99532. look->ln=info->barkmap;
  99533. look->vi=info;
  99534. look->linearmap=(int**)_ogg_calloc(2,sizeof(*look->linearmap));
  99535. return look;
  99536. }
  99537. static void *floor0_inverse1(vorbis_block *vb,vorbis_look_floor *i){
  99538. vorbis_look_floor0 *look=(vorbis_look_floor0 *)i;
  99539. vorbis_info_floor0 *info=look->vi;
  99540. int j,k;
  99541. int ampraw=oggpack_read(&vb->opb,info->ampbits);
  99542. if(ampraw>0){ /* also handles the -1 out of data case */
  99543. long maxval=(1<<info->ampbits)-1;
  99544. float amp=(float)ampraw/maxval*info->ampdB;
  99545. int booknum=oggpack_read(&vb->opb,_ilog(info->numbooks));
  99546. if(booknum!=-1 && booknum<info->numbooks){ /* be paranoid */
  99547. codec_setup_info *ci=(codec_setup_info *)vb->vd->vi->codec_setup;
  99548. codebook *b=ci->fullbooks+info->books[booknum];
  99549. float last=0.f;
  99550. float *lsp=(float*)_vorbis_block_alloc(vb,sizeof(*lsp)*(look->m+b->dim+1));
  99551. for(j=0;j<look->m;j+=b->dim)
  99552. if(vorbis_book_decodev_set(b,lsp+j,&vb->opb,b->dim)==-1)goto eop;
  99553. for(j=0;j<look->m;){
  99554. for(k=0;k<b->dim;k++,j++)lsp[j]+=last;
  99555. last=lsp[j-1];
  99556. }
  99557. lsp[look->m]=amp;
  99558. return(lsp);
  99559. }
  99560. }
  99561. eop:
  99562. return(NULL);
  99563. }
  99564. static int floor0_inverse2(vorbis_block *vb,vorbis_look_floor *i,
  99565. void *memo,float *out){
  99566. vorbis_look_floor0 *look=(vorbis_look_floor0 *)i;
  99567. vorbis_info_floor0 *info=look->vi;
  99568. floor0_map_lazy_init(vb,info,look);
  99569. if(memo){
  99570. float *lsp=(float *)memo;
  99571. float amp=lsp[look->m];
  99572. vorbis_lsp_to_curve(out,
  99573. look->linearmap[vb->W],
  99574. look->n[vb->W],
  99575. look->ln,
  99576. lsp,look->m,amp,(float)info->ampdB);
  99577. return(1);
  99578. }
  99579. memset(out,0,sizeof(*out)*look->n[vb->W]);
  99580. return(0);
  99581. }
  99582. vorbis_func_floor floor0_exportbundle={
  99583. NULL,&floor0_unpack,&floor0_look,&floor0_free_info,
  99584. &floor0_free_look,&floor0_inverse1,&floor0_inverse2
  99585. };
  99586. #endif
  99587. /*** End of inlined file: floor0.c ***/
  99588. /*** Start of inlined file: floor1.c ***/
  99589. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  99590. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  99591. // tasks..
  99592. #if JUCE_MSVC
  99593. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  99594. #endif
  99595. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  99596. #if JUCE_USE_OGGVORBIS
  99597. #include <stdlib.h>
  99598. #include <string.h>
  99599. #include <math.h>
  99600. #include <stdio.h>
  99601. #define floor1_rangedB 140 /* floor 1 fixed at -140dB to 0dB range */
  99602. typedef struct {
  99603. int sorted_index[VIF_POSIT+2];
  99604. int forward_index[VIF_POSIT+2];
  99605. int reverse_index[VIF_POSIT+2];
  99606. int hineighbor[VIF_POSIT];
  99607. int loneighbor[VIF_POSIT];
  99608. int posts;
  99609. int n;
  99610. int quant_q;
  99611. vorbis_info_floor1 *vi;
  99612. long phrasebits;
  99613. long postbits;
  99614. long frames;
  99615. } vorbis_look_floor1;
  99616. typedef struct lsfit_acc{
  99617. long x0;
  99618. long x1;
  99619. long xa;
  99620. long ya;
  99621. long x2a;
  99622. long y2a;
  99623. long xya;
  99624. long an;
  99625. } lsfit_acc;
  99626. static void floor1_free_info(vorbis_info_floor *i){
  99627. vorbis_info_floor1 *info=(vorbis_info_floor1 *)i;
  99628. if(info){
  99629. memset(info,0,sizeof(*info));
  99630. _ogg_free(info);
  99631. }
  99632. }
  99633. static void floor1_free_look(vorbis_look_floor *i){
  99634. vorbis_look_floor1 *look=(vorbis_look_floor1 *)i;
  99635. if(look){
  99636. memset(look,0,sizeof(*look));
  99637. _ogg_free(look);
  99638. }
  99639. }
  99640. static void floor1_pack (vorbis_info_floor *i,oggpack_buffer *opb){
  99641. vorbis_info_floor1 *info=(vorbis_info_floor1 *)i;
  99642. int j,k;
  99643. int count=0;
  99644. int rangebits;
  99645. int maxposit=info->postlist[1];
  99646. int maxclass=-1;
  99647. oggpack_write(opb,info->partitions,5); /* only 0 to 31 legal */
  99648. for(j=0;j<info->partitions;j++){
  99649. oggpack_write(opb,info->partitionclass[j],4); /* only 0 to 15 legal */
  99650. if(maxclass<info->partitionclass[j])maxclass=info->partitionclass[j];
  99651. }
  99652. for(j=0;j<maxclass+1;j++){
  99653. oggpack_write(opb,info->class_dim[j]-1,3); /* 1 to 8 */
  99654. oggpack_write(opb,info->class_subs[j],2); /* 0 to 3 */
  99655. if(info->class_subs[j])oggpack_write(opb,info->class_book[j],8);
  99656. for(k=0;k<(1<<info->class_subs[j]);k++)
  99657. oggpack_write(opb,info->class_subbook[j][k]+1,8);
  99658. }
  99659. oggpack_write(opb,info->mult-1,2); /* only 1,2,3,4 legal now */
  99660. oggpack_write(opb,ilog2(maxposit),4);
  99661. rangebits=ilog2(maxposit);
  99662. for(j=0,k=0;j<info->partitions;j++){
  99663. count+=info->class_dim[info->partitionclass[j]];
  99664. for(;k<count;k++)
  99665. oggpack_write(opb,info->postlist[k+2],rangebits);
  99666. }
  99667. }
  99668. static vorbis_info_floor *floor1_unpack (vorbis_info *vi,oggpack_buffer *opb){
  99669. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  99670. int j,k,count=0,maxclass=-1,rangebits;
  99671. vorbis_info_floor1 *info=(vorbis_info_floor1*)_ogg_calloc(1,sizeof(*info));
  99672. info->partitions=oggpack_read(opb,5); /* only 0 to 31 legal */
  99673. for(j=0;j<info->partitions;j++){
  99674. info->partitionclass[j]=oggpack_read(opb,4); /* only 0 to 15 legal */
  99675. if(maxclass<info->partitionclass[j])maxclass=info->partitionclass[j];
  99676. }
  99677. for(j=0;j<maxclass+1;j++){
  99678. info->class_dim[j]=oggpack_read(opb,3)+1; /* 1 to 8 */
  99679. info->class_subs[j]=oggpack_read(opb,2); /* 0,1,2,3 bits */
  99680. if(info->class_subs[j]<0)
  99681. goto err_out;
  99682. if(info->class_subs[j])info->class_book[j]=oggpack_read(opb,8);
  99683. if(info->class_book[j]<0 || info->class_book[j]>=ci->books)
  99684. goto err_out;
  99685. for(k=0;k<(1<<info->class_subs[j]);k++){
  99686. info->class_subbook[j][k]=oggpack_read(opb,8)-1;
  99687. if(info->class_subbook[j][k]<-1 || info->class_subbook[j][k]>=ci->books)
  99688. goto err_out;
  99689. }
  99690. }
  99691. info->mult=oggpack_read(opb,2)+1; /* only 1,2,3,4 legal now */
  99692. rangebits=oggpack_read(opb,4);
  99693. for(j=0,k=0;j<info->partitions;j++){
  99694. count+=info->class_dim[info->partitionclass[j]];
  99695. for(;k<count;k++){
  99696. int t=info->postlist[k+2]=oggpack_read(opb,rangebits);
  99697. if(t<0 || t>=(1<<rangebits))
  99698. goto err_out;
  99699. }
  99700. }
  99701. info->postlist[0]=0;
  99702. info->postlist[1]=1<<rangebits;
  99703. return(info);
  99704. err_out:
  99705. floor1_free_info(info);
  99706. return(NULL);
  99707. }
  99708. static int icomp(const void *a,const void *b){
  99709. return(**(int **)a-**(int **)b);
  99710. }
  99711. static vorbis_look_floor *floor1_look(vorbis_dsp_state *vd,
  99712. vorbis_info_floor *in){
  99713. int *sortpointer[VIF_POSIT+2];
  99714. vorbis_info_floor1 *info=(vorbis_info_floor1*)in;
  99715. vorbis_look_floor1 *look=(vorbis_look_floor1*)_ogg_calloc(1,sizeof(*look));
  99716. int i,j,n=0;
  99717. look->vi=info;
  99718. look->n=info->postlist[1];
  99719. for(i=0;i<info->partitions;i++)n+=info->class_dim[info->partitionclass[i]];
  99720. n+=2;
  99721. look->posts=n;
  99722. for(i=0;i<n;i++)sortpointer[i]=info->postlist+i;
  99723. qsort(sortpointer,n,sizeof(*sortpointer),icomp);
  99724. for(i=0;i<n;i++)look->forward_index[i]=sortpointer[i]-info->postlist;
  99725. for(i=0;i<n;i++)look->reverse_index[look->forward_index[i]]=i;
  99726. for(i=0;i<n;i++)look->sorted_index[i]=info->postlist[look->forward_index[i]];
  99727. switch(info->mult){
  99728. case 1: /* 1024 -> 256 */
  99729. look->quant_q=256;
  99730. break;
  99731. case 2: /* 1024 -> 128 */
  99732. look->quant_q=128;
  99733. break;
  99734. case 3: /* 1024 -> 86 */
  99735. look->quant_q=86;
  99736. break;
  99737. case 4: /* 1024 -> 64 */
  99738. look->quant_q=64;
  99739. break;
  99740. }
  99741. for(i=0;i<n-2;i++){
  99742. int lo=0;
  99743. int hi=1;
  99744. int lx=0;
  99745. int hx=look->n;
  99746. int currentx=info->postlist[i+2];
  99747. for(j=0;j<i+2;j++){
  99748. int x=info->postlist[j];
  99749. if(x>lx && x<currentx){
  99750. lo=j;
  99751. lx=x;
  99752. }
  99753. if(x<hx && x>currentx){
  99754. hi=j;
  99755. hx=x;
  99756. }
  99757. }
  99758. look->loneighbor[i]=lo;
  99759. look->hineighbor[i]=hi;
  99760. }
  99761. return(look);
  99762. }
  99763. static int render_point(int x0,int x1,int y0,int y1,int x){
  99764. y0&=0x7fff; /* mask off flag */
  99765. y1&=0x7fff;
  99766. {
  99767. int dy=y1-y0;
  99768. int adx=x1-x0;
  99769. int ady=abs(dy);
  99770. int err=ady*(x-x0);
  99771. int off=err/adx;
  99772. if(dy<0)return(y0-off);
  99773. return(y0+off);
  99774. }
  99775. }
  99776. static int vorbis_dBquant(const float *x){
  99777. int i= *x*7.3142857f+1023.5f;
  99778. if(i>1023)return(1023);
  99779. if(i<0)return(0);
  99780. return i;
  99781. }
  99782. static float FLOOR1_fromdB_LOOKUP[256]={
  99783. 1.0649863e-07F, 1.1341951e-07F, 1.2079015e-07F, 1.2863978e-07F,
  99784. 1.3699951e-07F, 1.4590251e-07F, 1.5538408e-07F, 1.6548181e-07F,
  99785. 1.7623575e-07F, 1.8768855e-07F, 1.9988561e-07F, 2.128753e-07F,
  99786. 2.2670913e-07F, 2.4144197e-07F, 2.5713223e-07F, 2.7384213e-07F,
  99787. 2.9163793e-07F, 3.1059021e-07F, 3.3077411e-07F, 3.5226968e-07F,
  99788. 3.7516214e-07F, 3.9954229e-07F, 4.2550680e-07F, 4.5315863e-07F,
  99789. 4.8260743e-07F, 5.1396998e-07F, 5.4737065e-07F, 5.8294187e-07F,
  99790. 6.2082472e-07F, 6.6116941e-07F, 7.0413592e-07F, 7.4989464e-07F,
  99791. 7.9862701e-07F, 8.5052630e-07F, 9.0579828e-07F, 9.6466216e-07F,
  99792. 1.0273513e-06F, 1.0941144e-06F, 1.1652161e-06F, 1.2409384e-06F,
  99793. 1.3215816e-06F, 1.4074654e-06F, 1.4989305e-06F, 1.5963394e-06F,
  99794. 1.7000785e-06F, 1.8105592e-06F, 1.9282195e-06F, 2.0535261e-06F,
  99795. 2.1869758e-06F, 2.3290978e-06F, 2.4804557e-06F, 2.6416497e-06F,
  99796. 2.8133190e-06F, 2.9961443e-06F, 3.1908506e-06F, 3.3982101e-06F,
  99797. 3.6190449e-06F, 3.8542308e-06F, 4.1047004e-06F, 4.3714470e-06F,
  99798. 4.6555282e-06F, 4.9580707e-06F, 5.2802740e-06F, 5.6234160e-06F,
  99799. 5.9888572e-06F, 6.3780469e-06F, 6.7925283e-06F, 7.2339451e-06F,
  99800. 7.7040476e-06F, 8.2047000e-06F, 8.7378876e-06F, 9.3057248e-06F,
  99801. 9.9104632e-06F, 1.0554501e-05F, 1.1240392e-05F, 1.1970856e-05F,
  99802. 1.2748789e-05F, 1.3577278e-05F, 1.4459606e-05F, 1.5399272e-05F,
  99803. 1.6400004e-05F, 1.7465768e-05F, 1.8600792e-05F, 1.9809576e-05F,
  99804. 2.1096914e-05F, 2.2467911e-05F, 2.3928002e-05F, 2.5482978e-05F,
  99805. 2.7139006e-05F, 2.8902651e-05F, 3.0780908e-05F, 3.2781225e-05F,
  99806. 3.4911534e-05F, 3.7180282e-05F, 3.9596466e-05F, 4.2169667e-05F,
  99807. 4.4910090e-05F, 4.7828601e-05F, 5.0936773e-05F, 5.4246931e-05F,
  99808. 5.7772202e-05F, 6.1526565e-05F, 6.5524908e-05F, 6.9783085e-05F,
  99809. 7.4317983e-05F, 7.9147585e-05F, 8.4291040e-05F, 8.9768747e-05F,
  99810. 9.5602426e-05F, 0.00010181521F, 0.00010843174F, 0.00011547824F,
  99811. 0.00012298267F, 0.00013097477F, 0.00013948625F, 0.00014855085F,
  99812. 0.00015820453F, 0.00016848555F, 0.00017943469F, 0.00019109536F,
  99813. 0.00020351382F, 0.00021673929F, 0.00023082423F, 0.00024582449F,
  99814. 0.00026179955F, 0.00027881276F, 0.00029693158F, 0.00031622787F,
  99815. 0.00033677814F, 0.00035866388F, 0.00038197188F, 0.00040679456F,
  99816. 0.00043323036F, 0.00046138411F, 0.00049136745F, 0.00052329927F,
  99817. 0.00055730621F, 0.00059352311F, 0.00063209358F, 0.00067317058F,
  99818. 0.00071691700F, 0.00076350630F, 0.00081312324F, 0.00086596457F,
  99819. 0.00092223983F, 0.00098217216F, 0.0010459992F, 0.0011139742F,
  99820. 0.0011863665F, 0.0012634633F, 0.0013455702F, 0.0014330129F,
  99821. 0.0015261382F, 0.0016253153F, 0.0017309374F, 0.0018434235F,
  99822. 0.0019632195F, 0.0020908006F, 0.0022266726F, 0.0023713743F,
  99823. 0.0025254795F, 0.0026895994F, 0.0028643847F, 0.0030505286F,
  99824. 0.0032487691F, 0.0034598925F, 0.0036847358F, 0.0039241906F,
  99825. 0.0041792066F, 0.0044507950F, 0.0047400328F, 0.0050480668F,
  99826. 0.0053761186F, 0.0057254891F, 0.0060975636F, 0.0064938176F,
  99827. 0.0069158225F, 0.0073652516F, 0.0078438871F, 0.0083536271F,
  99828. 0.0088964928F, 0.009474637F, 0.010090352F, 0.010746080F,
  99829. 0.011444421F, 0.012188144F, 0.012980198F, 0.013823725F,
  99830. 0.014722068F, 0.015678791F, 0.016697687F, 0.017782797F,
  99831. 0.018938423F, 0.020169149F, 0.021479854F, 0.022875735F,
  99832. 0.024362330F, 0.025945531F, 0.027631618F, 0.029427276F,
  99833. 0.031339626F, 0.033376252F, 0.035545228F, 0.037855157F,
  99834. 0.040315199F, 0.042935108F, 0.045725273F, 0.048696758F,
  99835. 0.051861348F, 0.055231591F, 0.058820850F, 0.062643361F,
  99836. 0.066714279F, 0.071049749F, 0.075666962F, 0.080584227F,
  99837. 0.085821044F, 0.091398179F, 0.097337747F, 0.10366330F,
  99838. 0.11039993F, 0.11757434F, 0.12521498F, 0.13335215F,
  99839. 0.14201813F, 0.15124727F, 0.16107617F, 0.17154380F,
  99840. 0.18269168F, 0.19456402F, 0.20720788F, 0.22067342F,
  99841. 0.23501402F, 0.25028656F, 0.26655159F, 0.28387361F,
  99842. 0.30232132F, 0.32196786F, 0.34289114F, 0.36517414F,
  99843. 0.38890521F, 0.41417847F, 0.44109412F, 0.46975890F,
  99844. 0.50028648F, 0.53279791F, 0.56742212F, 0.60429640F,
  99845. 0.64356699F, 0.68538959F, 0.72993007F, 0.77736504F,
  99846. 0.82788260F, 0.88168307F, 0.9389798F, 1.F,
  99847. };
  99848. static void render_line(int x0,int x1,int y0,int y1,float *d){
  99849. int dy=y1-y0;
  99850. int adx=x1-x0;
  99851. int ady=abs(dy);
  99852. int base=dy/adx;
  99853. int sy=(dy<0?base-1:base+1);
  99854. int x=x0;
  99855. int y=y0;
  99856. int err=0;
  99857. ady-=abs(base*adx);
  99858. d[x]*=FLOOR1_fromdB_LOOKUP[y];
  99859. while(++x<x1){
  99860. err=err+ady;
  99861. if(err>=adx){
  99862. err-=adx;
  99863. y+=sy;
  99864. }else{
  99865. y+=base;
  99866. }
  99867. d[x]*=FLOOR1_fromdB_LOOKUP[y];
  99868. }
  99869. }
  99870. static void render_line0(int x0,int x1,int y0,int y1,int *d){
  99871. int dy=y1-y0;
  99872. int adx=x1-x0;
  99873. int ady=abs(dy);
  99874. int base=dy/adx;
  99875. int sy=(dy<0?base-1:base+1);
  99876. int x=x0;
  99877. int y=y0;
  99878. int err=0;
  99879. ady-=abs(base*adx);
  99880. d[x]=y;
  99881. while(++x<x1){
  99882. err=err+ady;
  99883. if(err>=adx){
  99884. err-=adx;
  99885. y+=sy;
  99886. }else{
  99887. y+=base;
  99888. }
  99889. d[x]=y;
  99890. }
  99891. }
  99892. static int accumulate_fit(const float *flr,const float *mdct,
  99893. int x0, int x1,lsfit_acc *a,
  99894. int n,vorbis_info_floor1 *info){
  99895. long i;
  99896. 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;
  99897. memset(a,0,sizeof(*a));
  99898. a->x0=x0;
  99899. a->x1=x1;
  99900. if(x1>=n)x1=n-1;
  99901. for(i=x0;i<=x1;i++){
  99902. int quantized=vorbis_dBquant(flr+i);
  99903. if(quantized){
  99904. if(mdct[i]+info->twofitatten>=flr[i]){
  99905. xa += i;
  99906. ya += quantized;
  99907. x2a += i*i;
  99908. y2a += quantized*quantized;
  99909. xya += i*quantized;
  99910. na++;
  99911. }else{
  99912. xb += i;
  99913. yb += quantized;
  99914. x2b += i*i;
  99915. y2b += quantized*quantized;
  99916. xyb += i*quantized;
  99917. nb++;
  99918. }
  99919. }
  99920. }
  99921. xb+=xa;
  99922. yb+=ya;
  99923. x2b+=x2a;
  99924. y2b+=y2a;
  99925. xyb+=xya;
  99926. nb+=na;
  99927. {
  99928. int weight=nb*info->twofitweight/(na+1);
  99929. a->xa=xa*weight+xb;
  99930. a->ya=ya*weight+yb;
  99931. a->x2a=x2a*weight+x2b;
  99932. a->y2a=y2a*weight+y2b;
  99933. a->xya=xya*weight+xyb;
  99934. a->an=na*weight+nb;
  99935. }
  99936. return(na);
  99937. }
  99938. static void fit_line(lsfit_acc *a,int fits,int *y0,int *y1){
  99939. long x=0,y=0,x2=0,y2=0,xy=0,an=0,i;
  99940. long x0=a[0].x0;
  99941. long x1=a[fits-1].x1;
  99942. for(i=0;i<fits;i++){
  99943. x+=a[i].xa;
  99944. y+=a[i].ya;
  99945. x2+=a[i].x2a;
  99946. y2+=a[i].y2a;
  99947. xy+=a[i].xya;
  99948. an+=a[i].an;
  99949. }
  99950. if(*y0>=0){
  99951. x+= x0;
  99952. y+= *y0;
  99953. x2+= x0 * x0;
  99954. y2+= *y0 * *y0;
  99955. xy+= *y0 * x0;
  99956. an++;
  99957. }
  99958. if(*y1>=0){
  99959. x+= x1;
  99960. y+= *y1;
  99961. x2+= x1 * x1;
  99962. y2+= *y1 * *y1;
  99963. xy+= *y1 * x1;
  99964. an++;
  99965. }
  99966. if(an){
  99967. double fx=x;
  99968. double fy=y;
  99969. double fx2=x2;
  99970. double fxy=xy;
  99971. double denom=1./(an*fx2-fx*fx);
  99972. double a=(fy*fx2-fxy*fx)*denom;
  99973. double b=(an*fxy-fx*fy)*denom;
  99974. *y0=rint(a+b*x0);
  99975. *y1=rint(a+b*x1);
  99976. if(*y0>1023)*y0=1023;
  99977. if(*y1>1023)*y1=1023;
  99978. if(*y0<0)*y0=0;
  99979. if(*y1<0)*y1=0;
  99980. }else{
  99981. *y0=0;
  99982. *y1=0;
  99983. }
  99984. }
  99985. static int inspect_error(int x0,int x1,int y0,int y1,const float *mask,
  99986. const float *mdct,
  99987. vorbis_info_floor1 *info){
  99988. int dy=y1-y0;
  99989. int adx=x1-x0;
  99990. int ady=abs(dy);
  99991. int base=dy/adx;
  99992. int sy=(dy<0?base-1:base+1);
  99993. int x=x0;
  99994. int y=y0;
  99995. int err=0;
  99996. int val=vorbis_dBquant(mask+x);
  99997. int mse=0;
  99998. int n=0;
  99999. ady-=abs(base*adx);
  100000. mse=(y-val);
  100001. mse*=mse;
  100002. n++;
  100003. if(mdct[x]+info->twofitatten>=mask[x]){
  100004. if(y+info->maxover<val)return(1);
  100005. if(y-info->maxunder>val)return(1);
  100006. }
  100007. while(++x<x1){
  100008. err=err+ady;
  100009. if(err>=adx){
  100010. err-=adx;
  100011. y+=sy;
  100012. }else{
  100013. y+=base;
  100014. }
  100015. val=vorbis_dBquant(mask+x);
  100016. mse+=((y-val)*(y-val));
  100017. n++;
  100018. if(mdct[x]+info->twofitatten>=mask[x]){
  100019. if(val){
  100020. if(y+info->maxover<val)return(1);
  100021. if(y-info->maxunder>val)return(1);
  100022. }
  100023. }
  100024. }
  100025. if(info->maxover*info->maxover/n>info->maxerr)return(0);
  100026. if(info->maxunder*info->maxunder/n>info->maxerr)return(0);
  100027. if(mse/n>info->maxerr)return(1);
  100028. return(0);
  100029. }
  100030. static int post_Y(int *A,int *B,int pos){
  100031. if(A[pos]<0)
  100032. return B[pos];
  100033. if(B[pos]<0)
  100034. return A[pos];
  100035. return (A[pos]+B[pos])>>1;
  100036. }
  100037. int *floor1_fit(vorbis_block *vb,void *look_,
  100038. const float *logmdct, /* in */
  100039. const float *logmask){
  100040. long i,j;
  100041. vorbis_look_floor1 *look = (vorbis_look_floor1*) look_;
  100042. vorbis_info_floor1 *info=look->vi;
  100043. long n=look->n;
  100044. long posts=look->posts;
  100045. long nonzero=0;
  100046. lsfit_acc fits[VIF_POSIT+1];
  100047. int fit_valueA[VIF_POSIT+2]; /* index by range list position */
  100048. int fit_valueB[VIF_POSIT+2]; /* index by range list position */
  100049. int loneighbor[VIF_POSIT+2]; /* sorted index of range list position (+2) */
  100050. int hineighbor[VIF_POSIT+2];
  100051. int *output=NULL;
  100052. int memo[VIF_POSIT+2];
  100053. for(i=0;i<posts;i++)fit_valueA[i]=-200; /* mark all unused */
  100054. for(i=0;i<posts;i++)fit_valueB[i]=-200; /* mark all unused */
  100055. for(i=0;i<posts;i++)loneighbor[i]=0; /* 0 for the implicit 0 post */
  100056. for(i=0;i<posts;i++)hineighbor[i]=1; /* 1 for the implicit post at n */
  100057. for(i=0;i<posts;i++)memo[i]=-1; /* no neighbor yet */
  100058. if(posts==0){
  100059. nonzero+=accumulate_fit(logmask,logmdct,0,n,fits,n,info);
  100060. }else{
  100061. for(i=0;i<posts-1;i++)
  100062. nonzero+=accumulate_fit(logmask,logmdct,look->sorted_index[i],
  100063. look->sorted_index[i+1],fits+i,
  100064. n,info);
  100065. }
  100066. if(nonzero){
  100067. int y0=-200;
  100068. int y1=-200;
  100069. fit_line(fits,posts-1,&y0,&y1);
  100070. fit_valueA[0]=y0;
  100071. fit_valueB[0]=y0;
  100072. fit_valueB[1]=y1;
  100073. fit_valueA[1]=y1;
  100074. for(i=2;i<posts;i++){
  100075. int sortpos=look->reverse_index[i];
  100076. int ln=loneighbor[sortpos];
  100077. int hn=hineighbor[sortpos];
  100078. if(memo[ln]!=hn){
  100079. int lsortpos=look->reverse_index[ln];
  100080. int hsortpos=look->reverse_index[hn];
  100081. memo[ln]=hn;
  100082. {
  100083. int lx=info->postlist[ln];
  100084. int hx=info->postlist[hn];
  100085. int ly=post_Y(fit_valueA,fit_valueB,ln);
  100086. int hy=post_Y(fit_valueA,fit_valueB,hn);
  100087. if(ly==-1 || hy==-1){
  100088. exit(1);
  100089. }
  100090. if(inspect_error(lx,hx,ly,hy,logmask,logmdct,info)){
  100091. int ly0=-200;
  100092. int ly1=-200;
  100093. int hy0=-200;
  100094. int hy1=-200;
  100095. fit_line(fits+lsortpos,sortpos-lsortpos,&ly0,&ly1);
  100096. fit_line(fits+sortpos,hsortpos-sortpos,&hy0,&hy1);
  100097. fit_valueB[ln]=ly0;
  100098. if(ln==0)fit_valueA[ln]=ly0;
  100099. fit_valueA[i]=ly1;
  100100. fit_valueB[i]=hy0;
  100101. fit_valueA[hn]=hy1;
  100102. if(hn==1)fit_valueB[hn]=hy1;
  100103. if(ly1>=0 || hy0>=0){
  100104. for(j=sortpos-1;j>=0;j--)
  100105. if(hineighbor[j]==hn)
  100106. hineighbor[j]=i;
  100107. else
  100108. break;
  100109. for(j=sortpos+1;j<posts;j++)
  100110. if(loneighbor[j]==ln)
  100111. loneighbor[j]=i;
  100112. else
  100113. break;
  100114. }
  100115. }else{
  100116. fit_valueA[i]=-200;
  100117. fit_valueB[i]=-200;
  100118. }
  100119. }
  100120. }
  100121. }
  100122. output=(int*)_vorbis_block_alloc(vb,sizeof(*output)*posts);
  100123. output[0]=post_Y(fit_valueA,fit_valueB,0);
  100124. output[1]=post_Y(fit_valueA,fit_valueB,1);
  100125. for(i=2;i<posts;i++){
  100126. int ln=look->loneighbor[i-2];
  100127. int hn=look->hineighbor[i-2];
  100128. int x0=info->postlist[ln];
  100129. int x1=info->postlist[hn];
  100130. int y0=output[ln];
  100131. int y1=output[hn];
  100132. int predicted=render_point(x0,x1,y0,y1,info->postlist[i]);
  100133. int vx=post_Y(fit_valueA,fit_valueB,i);
  100134. if(vx>=0 && predicted!=vx){
  100135. output[i]=vx;
  100136. }else{
  100137. output[i]= predicted|0x8000;
  100138. }
  100139. }
  100140. }
  100141. return(output);
  100142. }
  100143. int *floor1_interpolate_fit(vorbis_block *vb,void *look_,
  100144. int *A,int *B,
  100145. int del){
  100146. long i;
  100147. vorbis_look_floor1* look = (vorbis_look_floor1*) look_;
  100148. long posts=look->posts;
  100149. int *output=NULL;
  100150. if(A && B){
  100151. output=(int*)_vorbis_block_alloc(vb,sizeof(*output)*posts);
  100152. for(i=0;i<posts;i++){
  100153. output[i]=((65536-del)*(A[i]&0x7fff)+del*(B[i]&0x7fff)+32768)>>16;
  100154. if(A[i]&0x8000 && B[i]&0x8000)output[i]|=0x8000;
  100155. }
  100156. }
  100157. return(output);
  100158. }
  100159. int floor1_encode(oggpack_buffer *opb,vorbis_block *vb,
  100160. void*look_,
  100161. int *post,int *ilogmask){
  100162. long i,j;
  100163. vorbis_look_floor1 *look = (vorbis_look_floor1 *) look_;
  100164. vorbis_info_floor1 *info=look->vi;
  100165. long posts=look->posts;
  100166. codec_setup_info *ci=(codec_setup_info*)vb->vd->vi->codec_setup;
  100167. int out[VIF_POSIT+2];
  100168. static_codebook **sbooks=ci->book_param;
  100169. codebook *books=ci->fullbooks;
  100170. static long seq=0;
  100171. if(post){
  100172. for(i=0;i<posts;i++){
  100173. int val=post[i]&0x7fff;
  100174. switch(info->mult){
  100175. case 1: /* 1024 -> 256 */
  100176. val>>=2;
  100177. break;
  100178. case 2: /* 1024 -> 128 */
  100179. val>>=3;
  100180. break;
  100181. case 3: /* 1024 -> 86 */
  100182. val/=12;
  100183. break;
  100184. case 4: /* 1024 -> 64 */
  100185. val>>=4;
  100186. break;
  100187. }
  100188. post[i]=val | (post[i]&0x8000);
  100189. }
  100190. out[0]=post[0];
  100191. out[1]=post[1];
  100192. for(i=2;i<posts;i++){
  100193. int ln=look->loneighbor[i-2];
  100194. int hn=look->hineighbor[i-2];
  100195. int x0=info->postlist[ln];
  100196. int x1=info->postlist[hn];
  100197. int y0=post[ln];
  100198. int y1=post[hn];
  100199. int predicted=render_point(x0,x1,y0,y1,info->postlist[i]);
  100200. if((post[i]&0x8000) || (predicted==post[i])){
  100201. post[i]=predicted|0x8000; /* in case there was roundoff jitter
  100202. in interpolation */
  100203. out[i]=0;
  100204. }else{
  100205. int headroom=(look->quant_q-predicted<predicted?
  100206. look->quant_q-predicted:predicted);
  100207. int val=post[i]-predicted;
  100208. if(val<0)
  100209. if(val<-headroom)
  100210. val=headroom-val-1;
  100211. else
  100212. val=-1-(val<<1);
  100213. else
  100214. if(val>=headroom)
  100215. val= val+headroom;
  100216. else
  100217. val<<=1;
  100218. out[i]=val;
  100219. post[ln]&=0x7fff;
  100220. post[hn]&=0x7fff;
  100221. }
  100222. }
  100223. oggpack_write(opb,1,1);
  100224. look->frames++;
  100225. look->postbits+=ilog(look->quant_q-1)*2;
  100226. oggpack_write(opb,out[0],ilog(look->quant_q-1));
  100227. oggpack_write(opb,out[1],ilog(look->quant_q-1));
  100228. for(i=0,j=2;i<info->partitions;i++){
  100229. int classx=info->partitionclass[i];
  100230. int cdim=info->class_dim[classx];
  100231. int csubbits=info->class_subs[classx];
  100232. int csub=1<<csubbits;
  100233. int bookas[8]={0,0,0,0,0,0,0,0};
  100234. int cval=0;
  100235. int cshift=0;
  100236. int k,l;
  100237. if(csubbits){
  100238. int maxval[8];
  100239. for(k=0;k<csub;k++){
  100240. int booknum=info->class_subbook[classx][k];
  100241. if(booknum<0){
  100242. maxval[k]=1;
  100243. }else{
  100244. maxval[k]=sbooks[info->class_subbook[classx][k]]->entries;
  100245. }
  100246. }
  100247. for(k=0;k<cdim;k++){
  100248. for(l=0;l<csub;l++){
  100249. int val=out[j+k];
  100250. if(val<maxval[l]){
  100251. bookas[k]=l;
  100252. break;
  100253. }
  100254. }
  100255. cval|= bookas[k]<<cshift;
  100256. cshift+=csubbits;
  100257. }
  100258. look->phrasebits+=
  100259. vorbis_book_encode(books+info->class_book[classx],cval,opb);
  100260. #ifdef TRAIN_FLOOR1
  100261. {
  100262. FILE *of;
  100263. char buffer[80];
  100264. sprintf(buffer,"line_%dx%ld_class%d.vqd",
  100265. vb->pcmend/2,posts-2,class);
  100266. of=fopen(buffer,"a");
  100267. fprintf(of,"%d\n",cval);
  100268. fclose(of);
  100269. }
  100270. #endif
  100271. }
  100272. for(k=0;k<cdim;k++){
  100273. int book=info->class_subbook[classx][bookas[k]];
  100274. if(book>=0){
  100275. if(out[j+k]<(books+book)->entries)
  100276. look->postbits+=vorbis_book_encode(books+book,
  100277. out[j+k],opb);
  100278. #ifdef TRAIN_FLOOR1
  100279. {
  100280. FILE *of;
  100281. char buffer[80];
  100282. sprintf(buffer,"line_%dx%ld_%dsub%d.vqd",
  100283. vb->pcmend/2,posts-2,class,bookas[k]);
  100284. of=fopen(buffer,"a");
  100285. fprintf(of,"%d\n",out[j+k]);
  100286. fclose(of);
  100287. }
  100288. #endif
  100289. }
  100290. }
  100291. j+=cdim;
  100292. }
  100293. {
  100294. int hx=0;
  100295. int lx=0;
  100296. int ly=post[0]*info->mult;
  100297. for(j=1;j<look->posts;j++){
  100298. int current=look->forward_index[j];
  100299. int hy=post[current]&0x7fff;
  100300. if(hy==post[current]){
  100301. hy*=info->mult;
  100302. hx=info->postlist[current];
  100303. render_line0(lx,hx,ly,hy,ilogmask);
  100304. lx=hx;
  100305. ly=hy;
  100306. }
  100307. }
  100308. for(j=hx;j<vb->pcmend/2;j++)ilogmask[j]=ly; /* be certain */
  100309. seq++;
  100310. return(1);
  100311. }
  100312. }else{
  100313. oggpack_write(opb,0,1);
  100314. memset(ilogmask,0,vb->pcmend/2*sizeof(*ilogmask));
  100315. seq++;
  100316. return(0);
  100317. }
  100318. }
  100319. static void *floor1_inverse1(vorbis_block *vb,vorbis_look_floor *in){
  100320. vorbis_look_floor1 *look=(vorbis_look_floor1 *)in;
  100321. vorbis_info_floor1 *info=look->vi;
  100322. codec_setup_info *ci=(codec_setup_info*)vb->vd->vi->codec_setup;
  100323. int i,j,k;
  100324. codebook *books=ci->fullbooks;
  100325. if(oggpack_read(&vb->opb,1)==1){
  100326. int *fit_value=(int*)_vorbis_block_alloc(vb,(look->posts)*sizeof(*fit_value));
  100327. fit_value[0]=oggpack_read(&vb->opb,ilog(look->quant_q-1));
  100328. fit_value[1]=oggpack_read(&vb->opb,ilog(look->quant_q-1));
  100329. for(i=0,j=2;i<info->partitions;i++){
  100330. int classx=info->partitionclass[i];
  100331. int cdim=info->class_dim[classx];
  100332. int csubbits=info->class_subs[classx];
  100333. int csub=1<<csubbits;
  100334. int cval=0;
  100335. if(csubbits){
  100336. cval=vorbis_book_decode(books+info->class_book[classx],&vb->opb);
  100337. if(cval==-1)goto eop;
  100338. }
  100339. for(k=0;k<cdim;k++){
  100340. int book=info->class_subbook[classx][cval&(csub-1)];
  100341. cval>>=csubbits;
  100342. if(book>=0){
  100343. if((fit_value[j+k]=vorbis_book_decode(books+book,&vb->opb))==-1)
  100344. goto eop;
  100345. }else{
  100346. fit_value[j+k]=0;
  100347. }
  100348. }
  100349. j+=cdim;
  100350. }
  100351. for(i=2;i<look->posts;i++){
  100352. int predicted=render_point(info->postlist[look->loneighbor[i-2]],
  100353. info->postlist[look->hineighbor[i-2]],
  100354. fit_value[look->loneighbor[i-2]],
  100355. fit_value[look->hineighbor[i-2]],
  100356. info->postlist[i]);
  100357. int hiroom=look->quant_q-predicted;
  100358. int loroom=predicted;
  100359. int room=(hiroom<loroom?hiroom:loroom)<<1;
  100360. int val=fit_value[i];
  100361. if(val){
  100362. if(val>=room){
  100363. if(hiroom>loroom){
  100364. val = val-loroom;
  100365. }else{
  100366. val = -1-(val-hiroom);
  100367. }
  100368. }else{
  100369. if(val&1){
  100370. val= -((val+1)>>1);
  100371. }else{
  100372. val>>=1;
  100373. }
  100374. }
  100375. fit_value[i]=val+predicted;
  100376. fit_value[look->loneighbor[i-2]]&=0x7fff;
  100377. fit_value[look->hineighbor[i-2]]&=0x7fff;
  100378. }else{
  100379. fit_value[i]=predicted|0x8000;
  100380. }
  100381. }
  100382. return(fit_value);
  100383. }
  100384. eop:
  100385. return(NULL);
  100386. }
  100387. static int floor1_inverse2(vorbis_block *vb,vorbis_look_floor *in,void *memo,
  100388. float *out){
  100389. vorbis_look_floor1 *look=(vorbis_look_floor1 *)in;
  100390. vorbis_info_floor1 *info=look->vi;
  100391. codec_setup_info *ci=(codec_setup_info*)vb->vd->vi->codec_setup;
  100392. int n=ci->blocksizes[vb->W]/2;
  100393. int j;
  100394. if(memo){
  100395. int *fit_value=(int *)memo;
  100396. int hx=0;
  100397. int lx=0;
  100398. int ly=fit_value[0]*info->mult;
  100399. for(j=1;j<look->posts;j++){
  100400. int current=look->forward_index[j];
  100401. int hy=fit_value[current]&0x7fff;
  100402. if(hy==fit_value[current]){
  100403. hy*=info->mult;
  100404. hx=info->postlist[current];
  100405. render_line(lx,hx,ly,hy,out);
  100406. lx=hx;
  100407. ly=hy;
  100408. }
  100409. }
  100410. for(j=hx;j<n;j++)out[j]*=FLOOR1_fromdB_LOOKUP[ly]; /* be certain */
  100411. return(1);
  100412. }
  100413. memset(out,0,sizeof(*out)*n);
  100414. return(0);
  100415. }
  100416. vorbis_func_floor floor1_exportbundle={
  100417. &floor1_pack,&floor1_unpack,&floor1_look,&floor1_free_info,
  100418. &floor1_free_look,&floor1_inverse1,&floor1_inverse2
  100419. };
  100420. #endif
  100421. /*** End of inlined file: floor1.c ***/
  100422. /*** Start of inlined file: info.c ***/
  100423. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  100424. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  100425. // tasks..
  100426. #if JUCE_MSVC
  100427. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  100428. #endif
  100429. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  100430. #if JUCE_USE_OGGVORBIS
  100431. #include <stdlib.h>
  100432. #include <string.h>
  100433. #include <ctype.h>
  100434. static void _v_writestring(oggpack_buffer *o, const char *s, int bytes){
  100435. while(bytes--){
  100436. oggpack_write(o,*s++,8);
  100437. }
  100438. }
  100439. static void _v_readstring(oggpack_buffer *o,char *buf,int bytes){
  100440. while(bytes--){
  100441. *buf++=oggpack_read(o,8);
  100442. }
  100443. }
  100444. void vorbis_comment_init(vorbis_comment *vc){
  100445. memset(vc,0,sizeof(*vc));
  100446. }
  100447. void vorbis_comment_add(vorbis_comment *vc,char *comment){
  100448. vc->user_comments=(char**)_ogg_realloc(vc->user_comments,
  100449. (vc->comments+2)*sizeof(*vc->user_comments));
  100450. vc->comment_lengths=(int*)_ogg_realloc(vc->comment_lengths,
  100451. (vc->comments+2)*sizeof(*vc->comment_lengths));
  100452. vc->comment_lengths[vc->comments]=strlen(comment);
  100453. vc->user_comments[vc->comments]=(char*)_ogg_malloc(vc->comment_lengths[vc->comments]+1);
  100454. strcpy(vc->user_comments[vc->comments], comment);
  100455. vc->comments++;
  100456. vc->user_comments[vc->comments]=NULL;
  100457. }
  100458. void vorbis_comment_add_tag(vorbis_comment *vc, const char *tag, char *contents){
  100459. char *comment=(char*)alloca(strlen(tag)+strlen(contents)+2); /* +2 for = and \0 */
  100460. strcpy(comment, tag);
  100461. strcat(comment, "=");
  100462. strcat(comment, contents);
  100463. vorbis_comment_add(vc, comment);
  100464. }
  100465. static int tagcompare(const char *s1, const char *s2, int n){
  100466. int c=0;
  100467. while(c < n){
  100468. if(toupper(s1[c]) != toupper(s2[c]))
  100469. return !0;
  100470. c++;
  100471. }
  100472. return 0;
  100473. }
  100474. char *vorbis_comment_query(vorbis_comment *vc, char *tag, int count){
  100475. long i;
  100476. int found = 0;
  100477. int taglen = strlen(tag)+1; /* +1 for the = we append */
  100478. char *fulltag = (char*)alloca(taglen+ 1);
  100479. strcpy(fulltag, tag);
  100480. strcat(fulltag, "=");
  100481. for(i=0;i<vc->comments;i++){
  100482. if(!tagcompare(vc->user_comments[i], fulltag, taglen)){
  100483. if(count == found)
  100484. return vc->user_comments[i] + taglen;
  100485. else
  100486. found++;
  100487. }
  100488. }
  100489. return NULL; /* didn't find anything */
  100490. }
  100491. int vorbis_comment_query_count(vorbis_comment *vc, char *tag){
  100492. int i,count=0;
  100493. int taglen = strlen(tag)+1; /* +1 for the = we append */
  100494. char *fulltag = (char*)alloca(taglen+1);
  100495. strcpy(fulltag,tag);
  100496. strcat(fulltag, "=");
  100497. for(i=0;i<vc->comments;i++){
  100498. if(!tagcompare(vc->user_comments[i], fulltag, taglen))
  100499. count++;
  100500. }
  100501. return count;
  100502. }
  100503. void vorbis_comment_clear(vorbis_comment *vc){
  100504. if(vc){
  100505. long i;
  100506. for(i=0;i<vc->comments;i++)
  100507. if(vc->user_comments[i])_ogg_free(vc->user_comments[i]);
  100508. if(vc->user_comments)_ogg_free(vc->user_comments);
  100509. if(vc->comment_lengths)_ogg_free(vc->comment_lengths);
  100510. if(vc->vendor)_ogg_free(vc->vendor);
  100511. }
  100512. memset(vc,0,sizeof(*vc));
  100513. }
  100514. int vorbis_info_blocksize(vorbis_info *vi,int zo){
  100515. codec_setup_info *ci = (codec_setup_info*)vi->codec_setup;
  100516. return ci ? ci->blocksizes[zo] : -1;
  100517. }
  100518. void vorbis_info_init(vorbis_info *vi){
  100519. memset(vi,0,sizeof(*vi));
  100520. vi->codec_setup=_ogg_calloc(1,sizeof(codec_setup_info));
  100521. }
  100522. void vorbis_info_clear(vorbis_info *vi){
  100523. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100524. int i;
  100525. if(ci){
  100526. for(i=0;i<ci->modes;i++)
  100527. if(ci->mode_param[i])_ogg_free(ci->mode_param[i]);
  100528. for(i=0;i<ci->maps;i++) /* unpack does the range checking */
  100529. _mapping_P[ci->map_type[i]]->free_info(ci->map_param[i]);
  100530. for(i=0;i<ci->floors;i++) /* unpack does the range checking */
  100531. _floor_P[ci->floor_type[i]]->free_info(ci->floor_param[i]);
  100532. for(i=0;i<ci->residues;i++) /* unpack does the range checking */
  100533. _residue_P[ci->residue_type[i]]->free_info(ci->residue_param[i]);
  100534. for(i=0;i<ci->books;i++){
  100535. if(ci->book_param[i]){
  100536. vorbis_staticbook_destroy(ci->book_param[i]);
  100537. }
  100538. if(ci->fullbooks)
  100539. vorbis_book_clear(ci->fullbooks+i);
  100540. }
  100541. if(ci->fullbooks)
  100542. _ogg_free(ci->fullbooks);
  100543. for(i=0;i<ci->psys;i++)
  100544. _vi_psy_free(ci->psy_param[i]);
  100545. _ogg_free(ci);
  100546. }
  100547. memset(vi,0,sizeof(*vi));
  100548. }
  100549. static int _vorbis_unpack_info(vorbis_info *vi,oggpack_buffer *opb){
  100550. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100551. if(!ci)return(OV_EFAULT);
  100552. vi->version=oggpack_read(opb,32);
  100553. if(vi->version!=0)return(OV_EVERSION);
  100554. vi->channels=oggpack_read(opb,8);
  100555. vi->rate=oggpack_read(opb,32);
  100556. vi->bitrate_upper=oggpack_read(opb,32);
  100557. vi->bitrate_nominal=oggpack_read(opb,32);
  100558. vi->bitrate_lower=oggpack_read(opb,32);
  100559. ci->blocksizes[0]=1<<oggpack_read(opb,4);
  100560. ci->blocksizes[1]=1<<oggpack_read(opb,4);
  100561. if(vi->rate<1)goto err_out;
  100562. if(vi->channels<1)goto err_out;
  100563. if(ci->blocksizes[0]<8)goto err_out;
  100564. if(ci->blocksizes[1]<ci->blocksizes[0])goto err_out;
  100565. if(oggpack_read(opb,1)!=1)goto err_out; /* EOP check */
  100566. return(0);
  100567. err_out:
  100568. vorbis_info_clear(vi);
  100569. return(OV_EBADHEADER);
  100570. }
  100571. static int _vorbis_unpack_comment(vorbis_comment *vc,oggpack_buffer *opb){
  100572. int i;
  100573. int vendorlen=oggpack_read(opb,32);
  100574. if(vendorlen<0)goto err_out;
  100575. vc->vendor=(char*)_ogg_calloc(vendorlen+1,1);
  100576. _v_readstring(opb,vc->vendor,vendorlen);
  100577. vc->comments=oggpack_read(opb,32);
  100578. if(vc->comments<0)goto err_out;
  100579. vc->user_comments=(char**)_ogg_calloc(vc->comments+1,sizeof(*vc->user_comments));
  100580. vc->comment_lengths=(int*)_ogg_calloc(vc->comments+1, sizeof(*vc->comment_lengths));
  100581. for(i=0;i<vc->comments;i++){
  100582. int len=oggpack_read(opb,32);
  100583. if(len<0)goto err_out;
  100584. vc->comment_lengths[i]=len;
  100585. vc->user_comments[i]=(char*)_ogg_calloc(len+1,1);
  100586. _v_readstring(opb,vc->user_comments[i],len);
  100587. }
  100588. if(oggpack_read(opb,1)!=1)goto err_out; /* EOP check */
  100589. return(0);
  100590. err_out:
  100591. vorbis_comment_clear(vc);
  100592. return(OV_EBADHEADER);
  100593. }
  100594. static int _vorbis_unpack_books(vorbis_info *vi,oggpack_buffer *opb){
  100595. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100596. int i;
  100597. if(!ci)return(OV_EFAULT);
  100598. ci->books=oggpack_read(opb,8)+1;
  100599. for(i=0;i<ci->books;i++){
  100600. ci->book_param[i]=(static_codebook*)_ogg_calloc(1,sizeof(*ci->book_param[i]));
  100601. if(vorbis_staticbook_unpack(opb,ci->book_param[i]))goto err_out;
  100602. }
  100603. {
  100604. int times=oggpack_read(opb,6)+1;
  100605. for(i=0;i<times;i++){
  100606. int test=oggpack_read(opb,16);
  100607. if(test<0 || test>=VI_TIMEB)goto err_out;
  100608. }
  100609. }
  100610. ci->floors=oggpack_read(opb,6)+1;
  100611. for(i=0;i<ci->floors;i++){
  100612. ci->floor_type[i]=oggpack_read(opb,16);
  100613. if(ci->floor_type[i]<0 || ci->floor_type[i]>=VI_FLOORB)goto err_out;
  100614. ci->floor_param[i]=_floor_P[ci->floor_type[i]]->unpack(vi,opb);
  100615. if(!ci->floor_param[i])goto err_out;
  100616. }
  100617. ci->residues=oggpack_read(opb,6)+1;
  100618. for(i=0;i<ci->residues;i++){
  100619. ci->residue_type[i]=oggpack_read(opb,16);
  100620. if(ci->residue_type[i]<0 || ci->residue_type[i]>=VI_RESB)goto err_out;
  100621. ci->residue_param[i]=_residue_P[ci->residue_type[i]]->unpack(vi,opb);
  100622. if(!ci->residue_param[i])goto err_out;
  100623. }
  100624. ci->maps=oggpack_read(opb,6)+1;
  100625. for(i=0;i<ci->maps;i++){
  100626. ci->map_type[i]=oggpack_read(opb,16);
  100627. if(ci->map_type[i]<0 || ci->map_type[i]>=VI_MAPB)goto err_out;
  100628. ci->map_param[i]=_mapping_P[ci->map_type[i]]->unpack(vi,opb);
  100629. if(!ci->map_param[i])goto err_out;
  100630. }
  100631. ci->modes=oggpack_read(opb,6)+1;
  100632. for(i=0;i<ci->modes;i++){
  100633. ci->mode_param[i]=(vorbis_info_mode*)_ogg_calloc(1,sizeof(*ci->mode_param[i]));
  100634. ci->mode_param[i]->blockflag=oggpack_read(opb,1);
  100635. ci->mode_param[i]->windowtype=oggpack_read(opb,16);
  100636. ci->mode_param[i]->transformtype=oggpack_read(opb,16);
  100637. ci->mode_param[i]->mapping=oggpack_read(opb,8);
  100638. if(ci->mode_param[i]->windowtype>=VI_WINDOWB)goto err_out;
  100639. if(ci->mode_param[i]->transformtype>=VI_WINDOWB)goto err_out;
  100640. if(ci->mode_param[i]->mapping>=ci->maps)goto err_out;
  100641. }
  100642. if(oggpack_read(opb,1)!=1)goto err_out; /* top level EOP check */
  100643. return(0);
  100644. err_out:
  100645. vorbis_info_clear(vi);
  100646. return(OV_EBADHEADER);
  100647. }
  100648. int vorbis_synthesis_headerin(vorbis_info *vi,vorbis_comment *vc,ogg_packet *op){
  100649. oggpack_buffer opb;
  100650. if(op){
  100651. oggpack_readinit(&opb,op->packet,op->bytes);
  100652. {
  100653. char buffer[6];
  100654. int packtype=oggpack_read(&opb,8);
  100655. memset(buffer,0,6);
  100656. _v_readstring(&opb,buffer,6);
  100657. if(memcmp(buffer,"vorbis",6)){
  100658. return(OV_ENOTVORBIS);
  100659. }
  100660. switch(packtype){
  100661. case 0x01: /* least significant *bit* is read first */
  100662. if(!op->b_o_s){
  100663. return(OV_EBADHEADER);
  100664. }
  100665. if(vi->rate!=0){
  100666. return(OV_EBADHEADER);
  100667. }
  100668. return(_vorbis_unpack_info(vi,&opb));
  100669. case 0x03: /* least significant *bit* is read first */
  100670. if(vi->rate==0){
  100671. return(OV_EBADHEADER);
  100672. }
  100673. return(_vorbis_unpack_comment(vc,&opb));
  100674. case 0x05: /* least significant *bit* is read first */
  100675. if(vi->rate==0 || vc->vendor==NULL){
  100676. return(OV_EBADHEADER);
  100677. }
  100678. return(_vorbis_unpack_books(vi,&opb));
  100679. default:
  100680. return(OV_EBADHEADER);
  100681. break;
  100682. }
  100683. }
  100684. }
  100685. return(OV_EBADHEADER);
  100686. }
  100687. static int _vorbis_pack_info(oggpack_buffer *opb,vorbis_info *vi){
  100688. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100689. if(!ci)return(OV_EFAULT);
  100690. oggpack_write(opb,0x01,8);
  100691. _v_writestring(opb,"vorbis", 6);
  100692. oggpack_write(opb,0x00,32);
  100693. oggpack_write(opb,vi->channels,8);
  100694. oggpack_write(opb,vi->rate,32);
  100695. oggpack_write(opb,vi->bitrate_upper,32);
  100696. oggpack_write(opb,vi->bitrate_nominal,32);
  100697. oggpack_write(opb,vi->bitrate_lower,32);
  100698. oggpack_write(opb,ilog2(ci->blocksizes[0]),4);
  100699. oggpack_write(opb,ilog2(ci->blocksizes[1]),4);
  100700. oggpack_write(opb,1,1);
  100701. return(0);
  100702. }
  100703. static int _vorbis_pack_comment(oggpack_buffer *opb,vorbis_comment *vc){
  100704. char temp[]="Xiph.Org libVorbis I 20050304";
  100705. int bytes = strlen(temp);
  100706. oggpack_write(opb,0x03,8);
  100707. _v_writestring(opb,"vorbis", 6);
  100708. oggpack_write(opb,bytes,32);
  100709. _v_writestring(opb,temp, bytes);
  100710. oggpack_write(opb,vc->comments,32);
  100711. if(vc->comments){
  100712. int i;
  100713. for(i=0;i<vc->comments;i++){
  100714. if(vc->user_comments[i]){
  100715. oggpack_write(opb,vc->comment_lengths[i],32);
  100716. _v_writestring(opb,vc->user_comments[i], vc->comment_lengths[i]);
  100717. }else{
  100718. oggpack_write(opb,0,32);
  100719. }
  100720. }
  100721. }
  100722. oggpack_write(opb,1,1);
  100723. return(0);
  100724. }
  100725. static int _vorbis_pack_books(oggpack_buffer *opb,vorbis_info *vi){
  100726. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100727. int i;
  100728. if(!ci)return(OV_EFAULT);
  100729. oggpack_write(opb,0x05,8);
  100730. _v_writestring(opb,"vorbis", 6);
  100731. oggpack_write(opb,ci->books-1,8);
  100732. for(i=0;i<ci->books;i++)
  100733. if(vorbis_staticbook_pack(ci->book_param[i],opb))goto err_out;
  100734. oggpack_write(opb,0,6);
  100735. oggpack_write(opb,0,16);
  100736. oggpack_write(opb,ci->floors-1,6);
  100737. for(i=0;i<ci->floors;i++){
  100738. oggpack_write(opb,ci->floor_type[i],16);
  100739. if(_floor_P[ci->floor_type[i]]->pack)
  100740. _floor_P[ci->floor_type[i]]->pack(ci->floor_param[i],opb);
  100741. else
  100742. goto err_out;
  100743. }
  100744. oggpack_write(opb,ci->residues-1,6);
  100745. for(i=0;i<ci->residues;i++){
  100746. oggpack_write(opb,ci->residue_type[i],16);
  100747. _residue_P[ci->residue_type[i]]->pack(ci->residue_param[i],opb);
  100748. }
  100749. oggpack_write(opb,ci->maps-1,6);
  100750. for(i=0;i<ci->maps;i++){
  100751. oggpack_write(opb,ci->map_type[i],16);
  100752. _mapping_P[ci->map_type[i]]->pack(vi,ci->map_param[i],opb);
  100753. }
  100754. oggpack_write(opb,ci->modes-1,6);
  100755. for(i=0;i<ci->modes;i++){
  100756. oggpack_write(opb,ci->mode_param[i]->blockflag,1);
  100757. oggpack_write(opb,ci->mode_param[i]->windowtype,16);
  100758. oggpack_write(opb,ci->mode_param[i]->transformtype,16);
  100759. oggpack_write(opb,ci->mode_param[i]->mapping,8);
  100760. }
  100761. oggpack_write(opb,1,1);
  100762. return(0);
  100763. err_out:
  100764. return(-1);
  100765. }
  100766. int vorbis_commentheader_out(vorbis_comment *vc,
  100767. ogg_packet *op){
  100768. oggpack_buffer opb;
  100769. oggpack_writeinit(&opb);
  100770. if(_vorbis_pack_comment(&opb,vc)) return OV_EIMPL;
  100771. op->packet = (unsigned char*) _ogg_malloc(oggpack_bytes(&opb));
  100772. memcpy(op->packet, opb.buffer, oggpack_bytes(&opb));
  100773. op->bytes=oggpack_bytes(&opb);
  100774. op->b_o_s=0;
  100775. op->e_o_s=0;
  100776. op->granulepos=0;
  100777. op->packetno=1;
  100778. return 0;
  100779. }
  100780. int vorbis_analysis_headerout(vorbis_dsp_state *v,
  100781. vorbis_comment *vc,
  100782. ogg_packet *op,
  100783. ogg_packet *op_comm,
  100784. ogg_packet *op_code){
  100785. int ret=OV_EIMPL;
  100786. vorbis_info *vi=v->vi;
  100787. oggpack_buffer opb;
  100788. private_state *b=(private_state*)v->backend_state;
  100789. if(!b){
  100790. ret=OV_EFAULT;
  100791. goto err_out;
  100792. }
  100793. oggpack_writeinit(&opb);
  100794. if(_vorbis_pack_info(&opb,vi))goto err_out;
  100795. if(b->header)_ogg_free(b->header);
  100796. b->header=(unsigned char*) _ogg_malloc(oggpack_bytes(&opb));
  100797. memcpy(b->header,opb.buffer,oggpack_bytes(&opb));
  100798. op->packet=b->header;
  100799. op->bytes=oggpack_bytes(&opb);
  100800. op->b_o_s=1;
  100801. op->e_o_s=0;
  100802. op->granulepos=0;
  100803. op->packetno=0;
  100804. oggpack_reset(&opb);
  100805. if(_vorbis_pack_comment(&opb,vc))goto err_out;
  100806. if(b->header1)_ogg_free(b->header1);
  100807. b->header1=(unsigned char*) _ogg_malloc(oggpack_bytes(&opb));
  100808. memcpy(b->header1,opb.buffer,oggpack_bytes(&opb));
  100809. op_comm->packet=b->header1;
  100810. op_comm->bytes=oggpack_bytes(&opb);
  100811. op_comm->b_o_s=0;
  100812. op_comm->e_o_s=0;
  100813. op_comm->granulepos=0;
  100814. op_comm->packetno=1;
  100815. oggpack_reset(&opb);
  100816. if(_vorbis_pack_books(&opb,vi))goto err_out;
  100817. if(b->header2)_ogg_free(b->header2);
  100818. b->header2=(unsigned char*) _ogg_malloc(oggpack_bytes(&opb));
  100819. memcpy(b->header2,opb.buffer,oggpack_bytes(&opb));
  100820. op_code->packet=b->header2;
  100821. op_code->bytes=oggpack_bytes(&opb);
  100822. op_code->b_o_s=0;
  100823. op_code->e_o_s=0;
  100824. op_code->granulepos=0;
  100825. op_code->packetno=2;
  100826. oggpack_writeclear(&opb);
  100827. return(0);
  100828. err_out:
  100829. oggpack_writeclear(&opb);
  100830. memset(op,0,sizeof(*op));
  100831. memset(op_comm,0,sizeof(*op_comm));
  100832. memset(op_code,0,sizeof(*op_code));
  100833. if(b->header)_ogg_free(b->header);
  100834. if(b->header1)_ogg_free(b->header1);
  100835. if(b->header2)_ogg_free(b->header2);
  100836. b->header=NULL;
  100837. b->header1=NULL;
  100838. b->header2=NULL;
  100839. return(ret);
  100840. }
  100841. double vorbis_granule_time(vorbis_dsp_state *v,ogg_int64_t granulepos){
  100842. if(granulepos>=0)
  100843. return((double)granulepos/v->vi->rate);
  100844. return(-1);
  100845. }
  100846. #endif
  100847. /*** End of inlined file: info.c ***/
  100848. /*** Start of inlined file: lpc.c ***/
  100849. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  100850. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  100851. // tasks..
  100852. #if JUCE_MSVC
  100853. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  100854. #endif
  100855. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  100856. #if JUCE_USE_OGGVORBIS
  100857. #include <stdlib.h>
  100858. #include <string.h>
  100859. #include <math.h>
  100860. float vorbis_lpc_from_data(float *data,float *lpci,int n,int m){
  100861. double *aut=(double*)alloca(sizeof(*aut)*(m+1));
  100862. double *lpc=(double*)alloca(sizeof(*lpc)*(m));
  100863. double error;
  100864. int i,j;
  100865. j=m+1;
  100866. while(j--){
  100867. double d=0; /* double needed for accumulator depth */
  100868. for(i=j;i<n;i++)d+=(double)data[i]*data[i-j];
  100869. aut[j]=d;
  100870. }
  100871. error=aut[0];
  100872. for(i=0;i<m;i++){
  100873. double r= -aut[i+1];
  100874. if(error==0){
  100875. memset(lpci,0,m*sizeof(*lpci));
  100876. return 0;
  100877. }
  100878. for(j=0;j<i;j++)r-=lpc[j]*aut[i-j];
  100879. r/=error;
  100880. lpc[i]=r;
  100881. for(j=0;j<i/2;j++){
  100882. double tmp=lpc[j];
  100883. lpc[j]+=r*lpc[i-1-j];
  100884. lpc[i-1-j]+=r*tmp;
  100885. }
  100886. if(i%2)lpc[j]+=lpc[j]*r;
  100887. error*=1.f-r*r;
  100888. }
  100889. for(j=0;j<m;j++)lpci[j]=(float)lpc[j];
  100890. return error;
  100891. }
  100892. void vorbis_lpc_predict(float *coeff,float *prime,int m,
  100893. float *data,long n){
  100894. long i,j,o,p;
  100895. float y;
  100896. float *work=(float*)alloca(sizeof(*work)*(m+n));
  100897. if(!prime)
  100898. for(i=0;i<m;i++)
  100899. work[i]=0.f;
  100900. else
  100901. for(i=0;i<m;i++)
  100902. work[i]=prime[i];
  100903. for(i=0;i<n;i++){
  100904. y=0;
  100905. o=i;
  100906. p=m;
  100907. for(j=0;j<m;j++)
  100908. y-=work[o++]*coeff[--p];
  100909. data[i]=work[o]=y;
  100910. }
  100911. }
  100912. #endif
  100913. /*** End of inlined file: lpc.c ***/
  100914. /*** Start of inlined file: lsp.c ***/
  100915. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  100916. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  100917. // tasks..
  100918. #if JUCE_MSVC
  100919. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  100920. #endif
  100921. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  100922. #if JUCE_USE_OGGVORBIS
  100923. #include <math.h>
  100924. #include <string.h>
  100925. #include <stdlib.h>
  100926. /*** Start of inlined file: lookup.h ***/
  100927. #ifndef _V_LOOKUP_H_
  100928. #ifdef FLOAT_LOOKUP
  100929. extern float vorbis_coslook(float a);
  100930. extern float vorbis_invsqlook(float a);
  100931. extern float vorbis_invsq2explook(int a);
  100932. extern float vorbis_fromdBlook(float a);
  100933. #endif
  100934. #ifdef INT_LOOKUP
  100935. extern long vorbis_invsqlook_i(long a,long e);
  100936. extern long vorbis_coslook_i(long a);
  100937. extern float vorbis_fromdBlook_i(long a);
  100938. #endif
  100939. #endif
  100940. /*** End of inlined file: lookup.h ***/
  100941. #define FLOAT_LOOKUP
  100942. #undef INT_LOOKUP
  100943. #ifdef FLOAT_LOOKUP
  100944. /*** Start of inlined file: lookup.c ***/
  100945. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  100946. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  100947. // tasks..
  100948. #if JUCE_MSVC
  100949. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  100950. #endif
  100951. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  100952. #if JUCE_USE_OGGVORBIS
  100953. #include <math.h>
  100954. /*** Start of inlined file: lookup.h ***/
  100955. #ifndef _V_LOOKUP_H_
  100956. #ifdef FLOAT_LOOKUP
  100957. extern float vorbis_coslook(float a);
  100958. extern float vorbis_invsqlook(float a);
  100959. extern float vorbis_invsq2explook(int a);
  100960. extern float vorbis_fromdBlook(float a);
  100961. #endif
  100962. #ifdef INT_LOOKUP
  100963. extern long vorbis_invsqlook_i(long a,long e);
  100964. extern long vorbis_coslook_i(long a);
  100965. extern float vorbis_fromdBlook_i(long a);
  100966. #endif
  100967. #endif
  100968. /*** End of inlined file: lookup.h ***/
  100969. /*** Start of inlined file: lookup_data.h ***/
  100970. #ifndef _V_LOOKUP_DATA_H_
  100971. #ifdef FLOAT_LOOKUP
  100972. #define COS_LOOKUP_SZ 128
  100973. static float COS_LOOKUP[COS_LOOKUP_SZ+1]={
  100974. +1.0000000000000f,+0.9996988186962f,+0.9987954562052f,+0.9972904566787f,
  100975. +0.9951847266722f,+0.9924795345987f,+0.9891765099648f,+0.9852776423889f,
  100976. +0.9807852804032f,+0.9757021300385f,+0.9700312531945f,+0.9637760657954f,
  100977. +0.9569403357322f,+0.9495281805930f,+0.9415440651830f,+0.9329927988347f,
  100978. +0.9238795325113f,+0.9142097557035f,+0.9039892931234f,+0.8932243011955f,
  100979. +0.8819212643484f,+0.8700869911087f,+0.8577286100003f,+0.8448535652497f,
  100980. +0.8314696123025f,+0.8175848131516f,+0.8032075314806f,+0.7883464276266f,
  100981. +0.7730104533627f,+0.7572088465065f,+0.7409511253550f,+0.7242470829515f,
  100982. +0.7071067811865f,+0.6895405447371f,+0.6715589548470f,+0.6531728429538f,
  100983. +0.6343932841636f,+0.6152315905806f,+0.5956993044924f,+0.5758081914178f,
  100984. +0.5555702330196f,+0.5349976198871f,+0.5141027441932f,+0.4928981922298f,
  100985. +0.4713967368260f,+0.4496113296546f,+0.4275550934303f,+0.4052413140050f,
  100986. +0.3826834323651f,+0.3598950365350f,+0.3368898533922f,+0.3136817403989f,
  100987. +0.2902846772545f,+0.2667127574749f,+0.2429801799033f,+0.2191012401569f,
  100988. +0.1950903220161f,+0.1709618887603f,+0.1467304744554f,+0.1224106751992f,
  100989. +0.0980171403296f,+0.0735645635997f,+0.0490676743274f,+0.0245412285229f,
  100990. +0.0000000000000f,-0.0245412285229f,-0.0490676743274f,-0.0735645635997f,
  100991. -0.0980171403296f,-0.1224106751992f,-0.1467304744554f,-0.1709618887603f,
  100992. -0.1950903220161f,-0.2191012401569f,-0.2429801799033f,-0.2667127574749f,
  100993. -0.2902846772545f,-0.3136817403989f,-0.3368898533922f,-0.3598950365350f,
  100994. -0.3826834323651f,-0.4052413140050f,-0.4275550934303f,-0.4496113296546f,
  100995. -0.4713967368260f,-0.4928981922298f,-0.5141027441932f,-0.5349976198871f,
  100996. -0.5555702330196f,-0.5758081914178f,-0.5956993044924f,-0.6152315905806f,
  100997. -0.6343932841636f,-0.6531728429538f,-0.6715589548470f,-0.6895405447371f,
  100998. -0.7071067811865f,-0.7242470829515f,-0.7409511253550f,-0.7572088465065f,
  100999. -0.7730104533627f,-0.7883464276266f,-0.8032075314806f,-0.8175848131516f,
  101000. -0.8314696123025f,-0.8448535652497f,-0.8577286100003f,-0.8700869911087f,
  101001. -0.8819212643484f,-0.8932243011955f,-0.9039892931234f,-0.9142097557035f,
  101002. -0.9238795325113f,-0.9329927988347f,-0.9415440651830f,-0.9495281805930f,
  101003. -0.9569403357322f,-0.9637760657954f,-0.9700312531945f,-0.9757021300385f,
  101004. -0.9807852804032f,-0.9852776423889f,-0.9891765099648f,-0.9924795345987f,
  101005. -0.9951847266722f,-0.9972904566787f,-0.9987954562052f,-0.9996988186962f,
  101006. -1.0000000000000f,
  101007. };
  101008. #define INVSQ_LOOKUP_SZ 32
  101009. static float INVSQ_LOOKUP[INVSQ_LOOKUP_SZ+1]={
  101010. 1.414213562373f,1.392621247646f,1.371988681140f,1.352246807566f,
  101011. 1.333333333333f,1.315191898443f,1.297771369046f,1.281025230441f,
  101012. 1.264911064067f,1.249390095109f,1.234426799697f,1.219988562661f,
  101013. 1.206045378311f,1.192569588000f,1.179535649239f,1.166919931983f,
  101014. 1.154700538379f,1.142857142857f,1.131370849898f,1.120224067222f,
  101015. 1.109400392450f,1.098884511590f,1.088662107904f,1.078719779941f,
  101016. 1.069044967650f,1.059625885652f,1.050451462878f,1.041511287847f,
  101017. 1.032795558989f,1.024295039463f,1.016001016002f,1.007905261358f,
  101018. 1.000000000000f,
  101019. };
  101020. #define INVSQ2EXP_LOOKUP_MIN (-32)
  101021. #define INVSQ2EXP_LOOKUP_MAX 32
  101022. static float INVSQ2EXP_LOOKUP[INVSQ2EXP_LOOKUP_MAX-\
  101023. INVSQ2EXP_LOOKUP_MIN+1]={
  101024. 65536.f, 46340.95001f, 32768.f, 23170.47501f,
  101025. 16384.f, 11585.2375f, 8192.f, 5792.618751f,
  101026. 4096.f, 2896.309376f, 2048.f, 1448.154688f,
  101027. 1024.f, 724.0773439f, 512.f, 362.038672f,
  101028. 256.f, 181.019336f, 128.f, 90.50966799f,
  101029. 64.f, 45.254834f, 32.f, 22.627417f,
  101030. 16.f, 11.3137085f, 8.f, 5.656854249f,
  101031. 4.f, 2.828427125f, 2.f, 1.414213562f,
  101032. 1.f, 0.7071067812f, 0.5f, 0.3535533906f,
  101033. 0.25f, 0.1767766953f, 0.125f, 0.08838834765f,
  101034. 0.0625f, 0.04419417382f, 0.03125f, 0.02209708691f,
  101035. 0.015625f, 0.01104854346f, 0.0078125f, 0.005524271728f,
  101036. 0.00390625f, 0.002762135864f, 0.001953125f, 0.001381067932f,
  101037. 0.0009765625f, 0.000690533966f, 0.00048828125f, 0.000345266983f,
  101038. 0.000244140625f,0.0001726334915f,0.0001220703125f,8.631674575e-05f,
  101039. 6.103515625e-05f,4.315837288e-05f,3.051757812e-05f,2.157918644e-05f,
  101040. 1.525878906e-05f,
  101041. };
  101042. #endif
  101043. #define FROMdB_LOOKUP_SZ 35
  101044. #define FROMdB2_LOOKUP_SZ 32
  101045. #define FROMdB_SHIFT 5
  101046. #define FROMdB2_SHIFT 3
  101047. #define FROMdB2_MASK 31
  101048. static float FROMdB_LOOKUP[FROMdB_LOOKUP_SZ]={
  101049. 1.f, 0.6309573445f, 0.3981071706f, 0.2511886432f,
  101050. 0.1584893192f, 0.1f, 0.06309573445f, 0.03981071706f,
  101051. 0.02511886432f, 0.01584893192f, 0.01f, 0.006309573445f,
  101052. 0.003981071706f, 0.002511886432f, 0.001584893192f, 0.001f,
  101053. 0.0006309573445f,0.0003981071706f,0.0002511886432f,0.0001584893192f,
  101054. 0.0001f,6.309573445e-05f,3.981071706e-05f,2.511886432e-05f,
  101055. 1.584893192e-05f, 1e-05f,6.309573445e-06f,3.981071706e-06f,
  101056. 2.511886432e-06f,1.584893192e-06f, 1e-06f,6.309573445e-07f,
  101057. 3.981071706e-07f,2.511886432e-07f,1.584893192e-07f,
  101058. };
  101059. static float FROMdB2_LOOKUP[FROMdB2_LOOKUP_SZ]={
  101060. 0.9928302478f, 0.9786445908f, 0.9646616199f, 0.9508784391f,
  101061. 0.9372921937f, 0.92390007f, 0.9106992942f, 0.8976871324f,
  101062. 0.8848608897f, 0.8722179097f, 0.8597555737f, 0.8474713009f,
  101063. 0.835362547f, 0.8234268041f, 0.8116616003f, 0.8000644989f,
  101064. 0.7886330981f, 0.7773650302f, 0.7662579617f, 0.755309592f,
  101065. 0.7445176537f, 0.7338799116f, 0.7233941627f, 0.7130582353f,
  101066. 0.7028699885f, 0.6928273125f, 0.6829281272f, 0.6731703824f,
  101067. 0.6635520573f, 0.6540711597f, 0.6447257262f, 0.6355138211f,
  101068. };
  101069. #ifdef INT_LOOKUP
  101070. #define INVSQ_LOOKUP_I_SHIFT 10
  101071. #define INVSQ_LOOKUP_I_MASK 1023
  101072. static long INVSQ_LOOKUP_I[64+1]={
  101073. 92682l, 91966l, 91267l, 90583l,
  101074. 89915l, 89261l, 88621l, 87995l,
  101075. 87381l, 86781l, 86192l, 85616l,
  101076. 85051l, 84497l, 83953l, 83420l,
  101077. 82897l, 82384l, 81880l, 81385l,
  101078. 80899l, 80422l, 79953l, 79492l,
  101079. 79039l, 78594l, 78156l, 77726l,
  101080. 77302l, 76885l, 76475l, 76072l,
  101081. 75674l, 75283l, 74898l, 74519l,
  101082. 74146l, 73778l, 73415l, 73058l,
  101083. 72706l, 72359l, 72016l, 71679l,
  101084. 71347l, 71019l, 70695l, 70376l,
  101085. 70061l, 69750l, 69444l, 69141l,
  101086. 68842l, 68548l, 68256l, 67969l,
  101087. 67685l, 67405l, 67128l, 66855l,
  101088. 66585l, 66318l, 66054l, 65794l,
  101089. 65536l,
  101090. };
  101091. #define COS_LOOKUP_I_SHIFT 9
  101092. #define COS_LOOKUP_I_MASK 511
  101093. #define COS_LOOKUP_I_SZ 128
  101094. static long COS_LOOKUP_I[COS_LOOKUP_I_SZ+1]={
  101095. 16384l, 16379l, 16364l, 16340l,
  101096. 16305l, 16261l, 16207l, 16143l,
  101097. 16069l, 15986l, 15893l, 15791l,
  101098. 15679l, 15557l, 15426l, 15286l,
  101099. 15137l, 14978l, 14811l, 14635l,
  101100. 14449l, 14256l, 14053l, 13842l,
  101101. 13623l, 13395l, 13160l, 12916l,
  101102. 12665l, 12406l, 12140l, 11866l,
  101103. 11585l, 11297l, 11003l, 10702l,
  101104. 10394l, 10080l, 9760l, 9434l,
  101105. 9102l, 8765l, 8423l, 8076l,
  101106. 7723l, 7366l, 7005l, 6639l,
  101107. 6270l, 5897l, 5520l, 5139l,
  101108. 4756l, 4370l, 3981l, 3590l,
  101109. 3196l, 2801l, 2404l, 2006l,
  101110. 1606l, 1205l, 804l, 402l,
  101111. 0l, -401l, -803l, -1204l,
  101112. -1605l, -2005l, -2403l, -2800l,
  101113. -3195l, -3589l, -3980l, -4369l,
  101114. -4755l, -5138l, -5519l, -5896l,
  101115. -6269l, -6638l, -7004l, -7365l,
  101116. -7722l, -8075l, -8422l, -8764l,
  101117. -9101l, -9433l, -9759l, -10079l,
  101118. -10393l, -10701l, -11002l, -11296l,
  101119. -11584l, -11865l, -12139l, -12405l,
  101120. -12664l, -12915l, -13159l, -13394l,
  101121. -13622l, -13841l, -14052l, -14255l,
  101122. -14448l, -14634l, -14810l, -14977l,
  101123. -15136l, -15285l, -15425l, -15556l,
  101124. -15678l, -15790l, -15892l, -15985l,
  101125. -16068l, -16142l, -16206l, -16260l,
  101126. -16304l, -16339l, -16363l, -16378l,
  101127. -16383l,
  101128. };
  101129. #endif
  101130. #endif
  101131. /*** End of inlined file: lookup_data.h ***/
  101132. #ifdef FLOAT_LOOKUP
  101133. float vorbis_coslook(float a){
  101134. double d=a*(.31830989*(float)COS_LOOKUP_SZ);
  101135. int i=vorbis_ftoi(d-.5);
  101136. return COS_LOOKUP[i]+ (d-i)*(COS_LOOKUP[i+1]-COS_LOOKUP[i]);
  101137. }
  101138. float vorbis_invsqlook(float a){
  101139. double d=a*(2.f*(float)INVSQ_LOOKUP_SZ)-(float)INVSQ_LOOKUP_SZ;
  101140. int i=vorbis_ftoi(d-.5f);
  101141. return INVSQ_LOOKUP[i]+ (d-i)*(INVSQ_LOOKUP[i+1]-INVSQ_LOOKUP[i]);
  101142. }
  101143. float vorbis_invsq2explook(int a){
  101144. return INVSQ2EXP_LOOKUP[a-INVSQ2EXP_LOOKUP_MIN];
  101145. }
  101146. #include <stdio.h>
  101147. float vorbis_fromdBlook(float a){
  101148. int i=vorbis_ftoi(a*((float)(-(1<<FROMdB2_SHIFT)))-.5f);
  101149. return (i<0)?1.f:
  101150. ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
  101151. FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
  101152. }
  101153. #endif
  101154. #ifdef INT_LOOKUP
  101155. long vorbis_invsqlook_i(long a,long e){
  101156. long i=(a&0x7fff)>>(INVSQ_LOOKUP_I_SHIFT-1);
  101157. long d=(a&INVSQ_LOOKUP_I_MASK)<<(16-INVSQ_LOOKUP_I_SHIFT); /* 0.16 */
  101158. long val=INVSQ_LOOKUP_I[i]- /* 1.16 */
  101159. (((INVSQ_LOOKUP_I[i]-INVSQ_LOOKUP_I[i+1])* /* 0.16 */
  101160. d)>>16); /* result 1.16 */
  101161. e+=32;
  101162. if(e&1)val=(val*5792)>>13; /* multiply val by 1/sqrt(2) */
  101163. e=(e>>1)-8;
  101164. return(val>>e);
  101165. }
  101166. float vorbis_fromdBlook_i(long a){
  101167. int i=(-a)>>(12-FROMdB2_SHIFT);
  101168. return (i<0)?1.f:
  101169. ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
  101170. FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
  101171. }
  101172. long vorbis_coslook_i(long a){
  101173. int i=a>>COS_LOOKUP_I_SHIFT;
  101174. int d=a&COS_LOOKUP_I_MASK;
  101175. return COS_LOOKUP_I[i]- ((d*(COS_LOOKUP_I[i]-COS_LOOKUP_I[i+1]))>>
  101176. COS_LOOKUP_I_SHIFT);
  101177. }
  101178. #endif
  101179. #endif
  101180. /*** End of inlined file: lookup.c ***/
  101181. /* catch this in the build system; we #include for
  101182. compilers (like gcc) that can't inline across
  101183. modules */
  101184. void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,float *lsp,int m,
  101185. float amp,float ampoffset){
  101186. int i;
  101187. float wdel=M_PI/ln;
  101188. vorbis_fpu_control fpu;
  101189. (void) fpu; // to avoid an unused variable warning
  101190. vorbis_fpu_setround(&fpu);
  101191. for(i=0;i<m;i++)lsp[i]=vorbis_coslook(lsp[i]);
  101192. i=0;
  101193. while(i<n){
  101194. int k=map[i];
  101195. int qexp;
  101196. float p=.7071067812f;
  101197. float q=.7071067812f;
  101198. float w=vorbis_coslook(wdel*k);
  101199. float *ftmp=lsp;
  101200. int c=m>>1;
  101201. do{
  101202. q*=ftmp[0]-w;
  101203. p*=ftmp[1]-w;
  101204. ftmp+=2;
  101205. }while(--c);
  101206. if(m&1){
  101207. q*=ftmp[0]-w;
  101208. q*=q;
  101209. p*=p*(1.f-w*w);
  101210. }else{
  101211. q*=q*(1.f+w);
  101212. p*=p*(1.f-w);
  101213. }
  101214. q=frexp(p+q,&qexp);
  101215. q=vorbis_fromdBlook(amp*
  101216. vorbis_invsqlook(q)*
  101217. vorbis_invsq2explook(qexp+m)-
  101218. ampoffset);
  101219. do{
  101220. curve[i++]*=q;
  101221. }while(map[i]==k);
  101222. }
  101223. vorbis_fpu_restore(fpu);
  101224. }
  101225. #else
  101226. #ifdef INT_LOOKUP
  101227. /*** Start of inlined file: lookup.c ***/
  101228. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  101229. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  101230. // tasks..
  101231. #if JUCE_MSVC
  101232. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  101233. #endif
  101234. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  101235. #if JUCE_USE_OGGVORBIS
  101236. #include <math.h>
  101237. /*** Start of inlined file: lookup.h ***/
  101238. #ifndef _V_LOOKUP_H_
  101239. #ifdef FLOAT_LOOKUP
  101240. extern float vorbis_coslook(float a);
  101241. extern float vorbis_invsqlook(float a);
  101242. extern float vorbis_invsq2explook(int a);
  101243. extern float vorbis_fromdBlook(float a);
  101244. #endif
  101245. #ifdef INT_LOOKUP
  101246. extern long vorbis_invsqlook_i(long a,long e);
  101247. extern long vorbis_coslook_i(long a);
  101248. extern float vorbis_fromdBlook_i(long a);
  101249. #endif
  101250. #endif
  101251. /*** End of inlined file: lookup.h ***/
  101252. /*** Start of inlined file: lookup_data.h ***/
  101253. #ifndef _V_LOOKUP_DATA_H_
  101254. #ifdef FLOAT_LOOKUP
  101255. #define COS_LOOKUP_SZ 128
  101256. static float COS_LOOKUP[COS_LOOKUP_SZ+1]={
  101257. +1.0000000000000f,+0.9996988186962f,+0.9987954562052f,+0.9972904566787f,
  101258. +0.9951847266722f,+0.9924795345987f,+0.9891765099648f,+0.9852776423889f,
  101259. +0.9807852804032f,+0.9757021300385f,+0.9700312531945f,+0.9637760657954f,
  101260. +0.9569403357322f,+0.9495281805930f,+0.9415440651830f,+0.9329927988347f,
  101261. +0.9238795325113f,+0.9142097557035f,+0.9039892931234f,+0.8932243011955f,
  101262. +0.8819212643484f,+0.8700869911087f,+0.8577286100003f,+0.8448535652497f,
  101263. +0.8314696123025f,+0.8175848131516f,+0.8032075314806f,+0.7883464276266f,
  101264. +0.7730104533627f,+0.7572088465065f,+0.7409511253550f,+0.7242470829515f,
  101265. +0.7071067811865f,+0.6895405447371f,+0.6715589548470f,+0.6531728429538f,
  101266. +0.6343932841636f,+0.6152315905806f,+0.5956993044924f,+0.5758081914178f,
  101267. +0.5555702330196f,+0.5349976198871f,+0.5141027441932f,+0.4928981922298f,
  101268. +0.4713967368260f,+0.4496113296546f,+0.4275550934303f,+0.4052413140050f,
  101269. +0.3826834323651f,+0.3598950365350f,+0.3368898533922f,+0.3136817403989f,
  101270. +0.2902846772545f,+0.2667127574749f,+0.2429801799033f,+0.2191012401569f,
  101271. +0.1950903220161f,+0.1709618887603f,+0.1467304744554f,+0.1224106751992f,
  101272. +0.0980171403296f,+0.0735645635997f,+0.0490676743274f,+0.0245412285229f,
  101273. +0.0000000000000f,-0.0245412285229f,-0.0490676743274f,-0.0735645635997f,
  101274. -0.0980171403296f,-0.1224106751992f,-0.1467304744554f,-0.1709618887603f,
  101275. -0.1950903220161f,-0.2191012401569f,-0.2429801799033f,-0.2667127574749f,
  101276. -0.2902846772545f,-0.3136817403989f,-0.3368898533922f,-0.3598950365350f,
  101277. -0.3826834323651f,-0.4052413140050f,-0.4275550934303f,-0.4496113296546f,
  101278. -0.4713967368260f,-0.4928981922298f,-0.5141027441932f,-0.5349976198871f,
  101279. -0.5555702330196f,-0.5758081914178f,-0.5956993044924f,-0.6152315905806f,
  101280. -0.6343932841636f,-0.6531728429538f,-0.6715589548470f,-0.6895405447371f,
  101281. -0.7071067811865f,-0.7242470829515f,-0.7409511253550f,-0.7572088465065f,
  101282. -0.7730104533627f,-0.7883464276266f,-0.8032075314806f,-0.8175848131516f,
  101283. -0.8314696123025f,-0.8448535652497f,-0.8577286100003f,-0.8700869911087f,
  101284. -0.8819212643484f,-0.8932243011955f,-0.9039892931234f,-0.9142097557035f,
  101285. -0.9238795325113f,-0.9329927988347f,-0.9415440651830f,-0.9495281805930f,
  101286. -0.9569403357322f,-0.9637760657954f,-0.9700312531945f,-0.9757021300385f,
  101287. -0.9807852804032f,-0.9852776423889f,-0.9891765099648f,-0.9924795345987f,
  101288. -0.9951847266722f,-0.9972904566787f,-0.9987954562052f,-0.9996988186962f,
  101289. -1.0000000000000f,
  101290. };
  101291. #define INVSQ_LOOKUP_SZ 32
  101292. static float INVSQ_LOOKUP[INVSQ_LOOKUP_SZ+1]={
  101293. 1.414213562373f,1.392621247646f,1.371988681140f,1.352246807566f,
  101294. 1.333333333333f,1.315191898443f,1.297771369046f,1.281025230441f,
  101295. 1.264911064067f,1.249390095109f,1.234426799697f,1.219988562661f,
  101296. 1.206045378311f,1.192569588000f,1.179535649239f,1.166919931983f,
  101297. 1.154700538379f,1.142857142857f,1.131370849898f,1.120224067222f,
  101298. 1.109400392450f,1.098884511590f,1.088662107904f,1.078719779941f,
  101299. 1.069044967650f,1.059625885652f,1.050451462878f,1.041511287847f,
  101300. 1.032795558989f,1.024295039463f,1.016001016002f,1.007905261358f,
  101301. 1.000000000000f,
  101302. };
  101303. #define INVSQ2EXP_LOOKUP_MIN (-32)
  101304. #define INVSQ2EXP_LOOKUP_MAX 32
  101305. static float INVSQ2EXP_LOOKUP[INVSQ2EXP_LOOKUP_MAX-\
  101306. INVSQ2EXP_LOOKUP_MIN+1]={
  101307. 65536.f, 46340.95001f, 32768.f, 23170.47501f,
  101308. 16384.f, 11585.2375f, 8192.f, 5792.618751f,
  101309. 4096.f, 2896.309376f, 2048.f, 1448.154688f,
  101310. 1024.f, 724.0773439f, 512.f, 362.038672f,
  101311. 256.f, 181.019336f, 128.f, 90.50966799f,
  101312. 64.f, 45.254834f, 32.f, 22.627417f,
  101313. 16.f, 11.3137085f, 8.f, 5.656854249f,
  101314. 4.f, 2.828427125f, 2.f, 1.414213562f,
  101315. 1.f, 0.7071067812f, 0.5f, 0.3535533906f,
  101316. 0.25f, 0.1767766953f, 0.125f, 0.08838834765f,
  101317. 0.0625f, 0.04419417382f, 0.03125f, 0.02209708691f,
  101318. 0.015625f, 0.01104854346f, 0.0078125f, 0.005524271728f,
  101319. 0.00390625f, 0.002762135864f, 0.001953125f, 0.001381067932f,
  101320. 0.0009765625f, 0.000690533966f, 0.00048828125f, 0.000345266983f,
  101321. 0.000244140625f,0.0001726334915f,0.0001220703125f,8.631674575e-05f,
  101322. 6.103515625e-05f,4.315837288e-05f,3.051757812e-05f,2.157918644e-05f,
  101323. 1.525878906e-05f,
  101324. };
  101325. #endif
  101326. #define FROMdB_LOOKUP_SZ 35
  101327. #define FROMdB2_LOOKUP_SZ 32
  101328. #define FROMdB_SHIFT 5
  101329. #define FROMdB2_SHIFT 3
  101330. #define FROMdB2_MASK 31
  101331. static float FROMdB_LOOKUP[FROMdB_LOOKUP_SZ]={
  101332. 1.f, 0.6309573445f, 0.3981071706f, 0.2511886432f,
  101333. 0.1584893192f, 0.1f, 0.06309573445f, 0.03981071706f,
  101334. 0.02511886432f, 0.01584893192f, 0.01f, 0.006309573445f,
  101335. 0.003981071706f, 0.002511886432f, 0.001584893192f, 0.001f,
  101336. 0.0006309573445f,0.0003981071706f,0.0002511886432f,0.0001584893192f,
  101337. 0.0001f,6.309573445e-05f,3.981071706e-05f,2.511886432e-05f,
  101338. 1.584893192e-05f, 1e-05f,6.309573445e-06f,3.981071706e-06f,
  101339. 2.511886432e-06f,1.584893192e-06f, 1e-06f,6.309573445e-07f,
  101340. 3.981071706e-07f,2.511886432e-07f,1.584893192e-07f,
  101341. };
  101342. static float FROMdB2_LOOKUP[FROMdB2_LOOKUP_SZ]={
  101343. 0.9928302478f, 0.9786445908f, 0.9646616199f, 0.9508784391f,
  101344. 0.9372921937f, 0.92390007f, 0.9106992942f, 0.8976871324f,
  101345. 0.8848608897f, 0.8722179097f, 0.8597555737f, 0.8474713009f,
  101346. 0.835362547f, 0.8234268041f, 0.8116616003f, 0.8000644989f,
  101347. 0.7886330981f, 0.7773650302f, 0.7662579617f, 0.755309592f,
  101348. 0.7445176537f, 0.7338799116f, 0.7233941627f, 0.7130582353f,
  101349. 0.7028699885f, 0.6928273125f, 0.6829281272f, 0.6731703824f,
  101350. 0.6635520573f, 0.6540711597f, 0.6447257262f, 0.6355138211f,
  101351. };
  101352. #ifdef INT_LOOKUP
  101353. #define INVSQ_LOOKUP_I_SHIFT 10
  101354. #define INVSQ_LOOKUP_I_MASK 1023
  101355. static long INVSQ_LOOKUP_I[64+1]={
  101356. 92682l, 91966l, 91267l, 90583l,
  101357. 89915l, 89261l, 88621l, 87995l,
  101358. 87381l, 86781l, 86192l, 85616l,
  101359. 85051l, 84497l, 83953l, 83420l,
  101360. 82897l, 82384l, 81880l, 81385l,
  101361. 80899l, 80422l, 79953l, 79492l,
  101362. 79039l, 78594l, 78156l, 77726l,
  101363. 77302l, 76885l, 76475l, 76072l,
  101364. 75674l, 75283l, 74898l, 74519l,
  101365. 74146l, 73778l, 73415l, 73058l,
  101366. 72706l, 72359l, 72016l, 71679l,
  101367. 71347l, 71019l, 70695l, 70376l,
  101368. 70061l, 69750l, 69444l, 69141l,
  101369. 68842l, 68548l, 68256l, 67969l,
  101370. 67685l, 67405l, 67128l, 66855l,
  101371. 66585l, 66318l, 66054l, 65794l,
  101372. 65536l,
  101373. };
  101374. #define COS_LOOKUP_I_SHIFT 9
  101375. #define COS_LOOKUP_I_MASK 511
  101376. #define COS_LOOKUP_I_SZ 128
  101377. static long COS_LOOKUP_I[COS_LOOKUP_I_SZ+1]={
  101378. 16384l, 16379l, 16364l, 16340l,
  101379. 16305l, 16261l, 16207l, 16143l,
  101380. 16069l, 15986l, 15893l, 15791l,
  101381. 15679l, 15557l, 15426l, 15286l,
  101382. 15137l, 14978l, 14811l, 14635l,
  101383. 14449l, 14256l, 14053l, 13842l,
  101384. 13623l, 13395l, 13160l, 12916l,
  101385. 12665l, 12406l, 12140l, 11866l,
  101386. 11585l, 11297l, 11003l, 10702l,
  101387. 10394l, 10080l, 9760l, 9434l,
  101388. 9102l, 8765l, 8423l, 8076l,
  101389. 7723l, 7366l, 7005l, 6639l,
  101390. 6270l, 5897l, 5520l, 5139l,
  101391. 4756l, 4370l, 3981l, 3590l,
  101392. 3196l, 2801l, 2404l, 2006l,
  101393. 1606l, 1205l, 804l, 402l,
  101394. 0l, -401l, -803l, -1204l,
  101395. -1605l, -2005l, -2403l, -2800l,
  101396. -3195l, -3589l, -3980l, -4369l,
  101397. -4755l, -5138l, -5519l, -5896l,
  101398. -6269l, -6638l, -7004l, -7365l,
  101399. -7722l, -8075l, -8422l, -8764l,
  101400. -9101l, -9433l, -9759l, -10079l,
  101401. -10393l, -10701l, -11002l, -11296l,
  101402. -11584l, -11865l, -12139l, -12405l,
  101403. -12664l, -12915l, -13159l, -13394l,
  101404. -13622l, -13841l, -14052l, -14255l,
  101405. -14448l, -14634l, -14810l, -14977l,
  101406. -15136l, -15285l, -15425l, -15556l,
  101407. -15678l, -15790l, -15892l, -15985l,
  101408. -16068l, -16142l, -16206l, -16260l,
  101409. -16304l, -16339l, -16363l, -16378l,
  101410. -16383l,
  101411. };
  101412. #endif
  101413. #endif
  101414. /*** End of inlined file: lookup_data.h ***/
  101415. #ifdef FLOAT_LOOKUP
  101416. float vorbis_coslook(float a){
  101417. double d=a*(.31830989*(float)COS_LOOKUP_SZ);
  101418. int i=vorbis_ftoi(d-.5);
  101419. return COS_LOOKUP[i]+ (d-i)*(COS_LOOKUP[i+1]-COS_LOOKUP[i]);
  101420. }
  101421. float vorbis_invsqlook(float a){
  101422. double d=a*(2.f*(float)INVSQ_LOOKUP_SZ)-(float)INVSQ_LOOKUP_SZ;
  101423. int i=vorbis_ftoi(d-.5f);
  101424. return INVSQ_LOOKUP[i]+ (d-i)*(INVSQ_LOOKUP[i+1]-INVSQ_LOOKUP[i]);
  101425. }
  101426. float vorbis_invsq2explook(int a){
  101427. return INVSQ2EXP_LOOKUP[a-INVSQ2EXP_LOOKUP_MIN];
  101428. }
  101429. #include <stdio.h>
  101430. float vorbis_fromdBlook(float a){
  101431. int i=vorbis_ftoi(a*((float)(-(1<<FROMdB2_SHIFT)))-.5f);
  101432. return (i<0)?1.f:
  101433. ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
  101434. FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
  101435. }
  101436. #endif
  101437. #ifdef INT_LOOKUP
  101438. long vorbis_invsqlook_i(long a,long e){
  101439. long i=(a&0x7fff)>>(INVSQ_LOOKUP_I_SHIFT-1);
  101440. long d=(a&INVSQ_LOOKUP_I_MASK)<<(16-INVSQ_LOOKUP_I_SHIFT); /* 0.16 */
  101441. long val=INVSQ_LOOKUP_I[i]- /* 1.16 */
  101442. (((INVSQ_LOOKUP_I[i]-INVSQ_LOOKUP_I[i+1])* /* 0.16 */
  101443. d)>>16); /* result 1.16 */
  101444. e+=32;
  101445. if(e&1)val=(val*5792)>>13; /* multiply val by 1/sqrt(2) */
  101446. e=(e>>1)-8;
  101447. return(val>>e);
  101448. }
  101449. float vorbis_fromdBlook_i(long a){
  101450. int i=(-a)>>(12-FROMdB2_SHIFT);
  101451. return (i<0)?1.f:
  101452. ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
  101453. FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
  101454. }
  101455. long vorbis_coslook_i(long a){
  101456. int i=a>>COS_LOOKUP_I_SHIFT;
  101457. int d=a&COS_LOOKUP_I_MASK;
  101458. return COS_LOOKUP_I[i]- ((d*(COS_LOOKUP_I[i]-COS_LOOKUP_I[i+1]))>>
  101459. COS_LOOKUP_I_SHIFT);
  101460. }
  101461. #endif
  101462. #endif
  101463. /*** End of inlined file: lookup.c ***/
  101464. /* catch this in the build system; we #include for
  101465. compilers (like gcc) that can't inline across
  101466. modules */
  101467. static int MLOOP_1[64]={
  101468. 0,10,11,11, 12,12,12,12, 13,13,13,13, 13,13,13,13,
  101469. 14,14,14,14, 14,14,14,14, 14,14,14,14, 14,14,14,14,
  101470. 15,15,15,15, 15,15,15,15, 15,15,15,15, 15,15,15,15,
  101471. 15,15,15,15, 15,15,15,15, 15,15,15,15, 15,15,15,15,
  101472. };
  101473. static int MLOOP_2[64]={
  101474. 0,4,5,5, 6,6,6,6, 7,7,7,7, 7,7,7,7,
  101475. 8,8,8,8, 8,8,8,8, 8,8,8,8, 8,8,8,8,
  101476. 9,9,9,9, 9,9,9,9, 9,9,9,9, 9,9,9,9,
  101477. 9,9,9,9, 9,9,9,9, 9,9,9,9, 9,9,9,9,
  101478. };
  101479. static int MLOOP_3[8]={0,1,2,2,3,3,3,3};
  101480. void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,float *lsp,int m,
  101481. float amp,float ampoffset){
  101482. int i;
  101483. int ampoffseti=rint(ampoffset*4096.f);
  101484. int ampi=rint(amp*16.f);
  101485. long *ilsp=alloca(m*sizeof(*ilsp));
  101486. for(i=0;i<m;i++)ilsp[i]=vorbis_coslook_i(lsp[i]/M_PI*65536.f+.5f);
  101487. i=0;
  101488. while(i<n){
  101489. int j,k=map[i];
  101490. unsigned long pi=46341; /* 2**-.5 in 0.16 */
  101491. unsigned long qi=46341;
  101492. int qexp=0,shift;
  101493. long wi=vorbis_coslook_i(k*65536/ln);
  101494. qi*=labs(ilsp[0]-wi);
  101495. pi*=labs(ilsp[1]-wi);
  101496. for(j=3;j<m;j+=2){
  101497. if(!(shift=MLOOP_1[(pi|qi)>>25]))
  101498. if(!(shift=MLOOP_2[(pi|qi)>>19]))
  101499. shift=MLOOP_3[(pi|qi)>>16];
  101500. qi=(qi>>shift)*labs(ilsp[j-1]-wi);
  101501. pi=(pi>>shift)*labs(ilsp[j]-wi);
  101502. qexp+=shift;
  101503. }
  101504. if(!(shift=MLOOP_1[(pi|qi)>>25]))
  101505. if(!(shift=MLOOP_2[(pi|qi)>>19]))
  101506. shift=MLOOP_3[(pi|qi)>>16];
  101507. if(m&1){
  101508. qi=(qi>>shift)*labs(ilsp[j-1]-wi);
  101509. pi=(pi>>shift)<<14;
  101510. qexp+=shift;
  101511. if(!(shift=MLOOP_1[(pi|qi)>>25]))
  101512. if(!(shift=MLOOP_2[(pi|qi)>>19]))
  101513. shift=MLOOP_3[(pi|qi)>>16];
  101514. pi>>=shift;
  101515. qi>>=shift;
  101516. qexp+=shift-14*((m+1)>>1);
  101517. pi=((pi*pi)>>16);
  101518. qi=((qi*qi)>>16);
  101519. qexp=qexp*2+m;
  101520. pi*=(1<<14)-((wi*wi)>>14);
  101521. qi+=pi>>14;
  101522. }else{
  101523. pi>>=shift;
  101524. qi>>=shift;
  101525. qexp+=shift-7*m;
  101526. pi=((pi*pi)>>16);
  101527. qi=((qi*qi)>>16);
  101528. qexp=qexp*2+m;
  101529. pi*=(1<<14)-wi;
  101530. qi*=(1<<14)+wi;
  101531. qi=(qi+pi)>>14;
  101532. }
  101533. if(qi&0xffff0000){ /* checks for 1.xxxxxxxxxxxxxxxx */
  101534. qi>>=1; qexp++;
  101535. }else
  101536. while(qi && !(qi&0x8000)){ /* checks for 0.0xxxxxxxxxxxxxxx or less*/
  101537. qi<<=1; qexp--;
  101538. }
  101539. amp=vorbis_fromdBlook_i(ampi* /* n.4 */
  101540. vorbis_invsqlook_i(qi,qexp)-
  101541. ampoffseti); /* 8.12[0] */
  101542. curve[i]*=amp;
  101543. while(map[++i]==k)curve[i]*=amp;
  101544. }
  101545. }
  101546. #else
  101547. void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,float *lsp,int m,
  101548. float amp,float ampoffset){
  101549. int i;
  101550. float wdel=M_PI/ln;
  101551. for(i=0;i<m;i++)lsp[i]=2.f*cos(lsp[i]);
  101552. i=0;
  101553. while(i<n){
  101554. int j,k=map[i];
  101555. float p=.5f;
  101556. float q=.5f;
  101557. float w=2.f*cos(wdel*k);
  101558. for(j=1;j<m;j+=2){
  101559. q *= w-lsp[j-1];
  101560. p *= w-lsp[j];
  101561. }
  101562. if(j==m){
  101563. q*=w-lsp[j-1];
  101564. p*=p*(4.f-w*w);
  101565. q*=q;
  101566. }else{
  101567. p*=p*(2.f-w);
  101568. q*=q*(2.f+w);
  101569. }
  101570. q=fromdB(amp/sqrt(p+q)-ampoffset);
  101571. curve[i]*=q;
  101572. while(map[++i]==k)curve[i]*=q;
  101573. }
  101574. }
  101575. #endif
  101576. #endif
  101577. static void cheby(float *g, int ord) {
  101578. int i, j;
  101579. g[0] *= .5f;
  101580. for(i=2; i<= ord; i++) {
  101581. for(j=ord; j >= i; j--) {
  101582. g[j-2] -= g[j];
  101583. g[j] += g[j];
  101584. }
  101585. }
  101586. }
  101587. static int comp(const void *a,const void *b){
  101588. return (*(float *)a<*(float *)b)-(*(float *)a>*(float *)b);
  101589. }
  101590. #define EPSILON 10e-7
  101591. static int Laguerre_With_Deflation(float *a,int ord,float *r){
  101592. int i,m;
  101593. double lastdelta=0.f;
  101594. double *defl=(double*)alloca(sizeof(*defl)*(ord+1));
  101595. for(i=0;i<=ord;i++)defl[i]=a[i];
  101596. for(m=ord;m>0;m--){
  101597. double newx=0.f,delta;
  101598. while(1){
  101599. double p=defl[m],pp=0.f,ppp=0.f,denom;
  101600. for(i=m;i>0;i--){
  101601. ppp = newx*ppp + pp;
  101602. pp = newx*pp + p;
  101603. p = newx*p + defl[i-1];
  101604. }
  101605. denom=(m-1) * ((m-1)*pp*pp - m*p*ppp);
  101606. if(denom<0)
  101607. return(-1); /* complex root! The LPC generator handed us a bad filter */
  101608. if(pp>0){
  101609. denom = pp + sqrt(denom);
  101610. if(denom<EPSILON)denom=EPSILON;
  101611. }else{
  101612. denom = pp - sqrt(denom);
  101613. if(denom>-(EPSILON))denom=-(EPSILON);
  101614. }
  101615. delta = m*p/denom;
  101616. newx -= delta;
  101617. if(delta<0.f)delta*=-1;
  101618. if(fabs(delta/newx)<10e-12)break;
  101619. lastdelta=delta;
  101620. }
  101621. r[m-1]=newx;
  101622. for(i=m;i>0;i--)
  101623. defl[i-1]+=newx*defl[i];
  101624. defl++;
  101625. }
  101626. return(0);
  101627. }
  101628. static int Newton_Raphson(float *a,int ord,float *r){
  101629. int i, k, count=0;
  101630. double error=1.f;
  101631. double *root=(double*)alloca(ord*sizeof(*root));
  101632. for(i=0; i<ord;i++) root[i] = r[i];
  101633. while(error>1e-20){
  101634. error=0;
  101635. for(i=0; i<ord; i++) { /* Update each point. */
  101636. double pp=0.,delta;
  101637. double rooti=root[i];
  101638. double p=a[ord];
  101639. for(k=ord-1; k>= 0; k--) {
  101640. pp= pp* rooti + p;
  101641. p = p * rooti + a[k];
  101642. }
  101643. delta = p/pp;
  101644. root[i] -= delta;
  101645. error+= delta*delta;
  101646. }
  101647. if(count>40)return(-1);
  101648. count++;
  101649. }
  101650. for(i=0; i<ord;i++) r[i] = root[i];
  101651. return(0);
  101652. }
  101653. int vorbis_lpc_to_lsp(float *lpc,float *lsp,int m){
  101654. int order2=(m+1)>>1;
  101655. int g1_order,g2_order;
  101656. float *g1=(float*)alloca(sizeof(*g1)*(order2+1));
  101657. float *g2=(float*)alloca(sizeof(*g2)*(order2+1));
  101658. float *g1r=(float*)alloca(sizeof(*g1r)*(order2+1));
  101659. float *g2r=(float*)alloca(sizeof(*g2r)*(order2+1));
  101660. int i;
  101661. g1_order=(m+1)>>1;
  101662. g2_order=(m) >>1;
  101663. g1[g1_order] = 1.f;
  101664. for(i=1;i<=g1_order;i++) g1[g1_order-i] = lpc[i-1]+lpc[m-i];
  101665. g2[g2_order] = 1.f;
  101666. for(i=1;i<=g2_order;i++) g2[g2_order-i] = lpc[i-1]-lpc[m-i];
  101667. if(g1_order>g2_order){
  101668. for(i=2; i<=g2_order;i++) g2[g2_order-i] += g2[g2_order-i+2];
  101669. }else{
  101670. for(i=1; i<=g1_order;i++) g1[g1_order-i] -= g1[g1_order-i+1];
  101671. for(i=1; i<=g2_order;i++) g2[g2_order-i] += g2[g2_order-i+1];
  101672. }
  101673. cheby(g1,g1_order);
  101674. cheby(g2,g2_order);
  101675. if(Laguerre_With_Deflation(g1,g1_order,g1r) ||
  101676. Laguerre_With_Deflation(g2,g2_order,g2r))
  101677. return(-1);
  101678. Newton_Raphson(g1,g1_order,g1r); /* if it fails, it leaves g1r alone */
  101679. Newton_Raphson(g2,g2_order,g2r); /* if it fails, it leaves g2r alone */
  101680. qsort(g1r,g1_order,sizeof(*g1r),comp);
  101681. qsort(g2r,g2_order,sizeof(*g2r),comp);
  101682. for(i=0;i<g1_order;i++)
  101683. lsp[i*2] = acos(g1r[i]);
  101684. for(i=0;i<g2_order;i++)
  101685. lsp[i*2+1] = acos(g2r[i]);
  101686. return(0);
  101687. }
  101688. #endif
  101689. /*** End of inlined file: lsp.c ***/
  101690. /*** Start of inlined file: mapping0.c ***/
  101691. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  101692. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  101693. // tasks..
  101694. #if JUCE_MSVC
  101695. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  101696. #endif
  101697. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  101698. #if JUCE_USE_OGGVORBIS
  101699. #include <stdlib.h>
  101700. #include <stdio.h>
  101701. #include <string.h>
  101702. #include <math.h>
  101703. static void mapping0_free_info(vorbis_info_mapping *i){
  101704. vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)i;
  101705. if(info){
  101706. memset(info,0,sizeof(*info));
  101707. _ogg_free(info);
  101708. }
  101709. }
  101710. static int ilog3(unsigned int v){
  101711. int ret=0;
  101712. if(v)--v;
  101713. while(v){
  101714. ret++;
  101715. v>>=1;
  101716. }
  101717. return(ret);
  101718. }
  101719. static void mapping0_pack(vorbis_info *vi,vorbis_info_mapping *vm,
  101720. oggpack_buffer *opb){
  101721. int i;
  101722. vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)vm;
  101723. if(info->submaps>1){
  101724. oggpack_write(opb,1,1);
  101725. oggpack_write(opb,info->submaps-1,4);
  101726. }else
  101727. oggpack_write(opb,0,1);
  101728. if(info->coupling_steps>0){
  101729. oggpack_write(opb,1,1);
  101730. oggpack_write(opb,info->coupling_steps-1,8);
  101731. for(i=0;i<info->coupling_steps;i++){
  101732. oggpack_write(opb,info->coupling_mag[i],ilog3(vi->channels));
  101733. oggpack_write(opb,info->coupling_ang[i],ilog3(vi->channels));
  101734. }
  101735. }else
  101736. oggpack_write(opb,0,1);
  101737. oggpack_write(opb,0,2); /* 2,3:reserved */
  101738. if(info->submaps>1){
  101739. for(i=0;i<vi->channels;i++)
  101740. oggpack_write(opb,info->chmuxlist[i],4);
  101741. }
  101742. for(i=0;i<info->submaps;i++){
  101743. oggpack_write(opb,0,8); /* time submap unused */
  101744. oggpack_write(opb,info->floorsubmap[i],8);
  101745. oggpack_write(opb,info->residuesubmap[i],8);
  101746. }
  101747. }
  101748. static vorbis_info_mapping *mapping0_unpack(vorbis_info *vi,oggpack_buffer *opb){
  101749. int i;
  101750. vorbis_info_mapping0 *info=(vorbis_info_mapping0*)_ogg_calloc(1,sizeof(*info));
  101751. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  101752. memset(info,0,sizeof(*info));
  101753. if(oggpack_read(opb,1))
  101754. info->submaps=oggpack_read(opb,4)+1;
  101755. else
  101756. info->submaps=1;
  101757. if(oggpack_read(opb,1)){
  101758. info->coupling_steps=oggpack_read(opb,8)+1;
  101759. for(i=0;i<info->coupling_steps;i++){
  101760. int testM=info->coupling_mag[i]=oggpack_read(opb,ilog3(vi->channels));
  101761. int testA=info->coupling_ang[i]=oggpack_read(opb,ilog3(vi->channels));
  101762. if(testM<0 ||
  101763. testA<0 ||
  101764. testM==testA ||
  101765. testM>=vi->channels ||
  101766. testA>=vi->channels) goto err_out;
  101767. }
  101768. }
  101769. if(oggpack_read(opb,2)>0)goto err_out; /* 2,3:reserved */
  101770. if(info->submaps>1){
  101771. for(i=0;i<vi->channels;i++){
  101772. info->chmuxlist[i]=oggpack_read(opb,4);
  101773. if(info->chmuxlist[i]>=info->submaps)goto err_out;
  101774. }
  101775. }
  101776. for(i=0;i<info->submaps;i++){
  101777. oggpack_read(opb,8); /* time submap unused */
  101778. info->floorsubmap[i]=oggpack_read(opb,8);
  101779. if(info->floorsubmap[i]>=ci->floors)goto err_out;
  101780. info->residuesubmap[i]=oggpack_read(opb,8);
  101781. if(info->residuesubmap[i]>=ci->residues)goto err_out;
  101782. }
  101783. return info;
  101784. err_out:
  101785. mapping0_free_info(info);
  101786. return(NULL);
  101787. }
  101788. #if 0
  101789. static long seq=0;
  101790. static ogg_int64_t total=0;
  101791. static float FLOOR1_fromdB_LOOKUP[256]={
  101792. 1.0649863e-07F, 1.1341951e-07F, 1.2079015e-07F, 1.2863978e-07F,
  101793. 1.3699951e-07F, 1.4590251e-07F, 1.5538408e-07F, 1.6548181e-07F,
  101794. 1.7623575e-07F, 1.8768855e-07F, 1.9988561e-07F, 2.128753e-07F,
  101795. 2.2670913e-07F, 2.4144197e-07F, 2.5713223e-07F, 2.7384213e-07F,
  101796. 2.9163793e-07F, 3.1059021e-07F, 3.3077411e-07F, 3.5226968e-07F,
  101797. 3.7516214e-07F, 3.9954229e-07F, 4.2550680e-07F, 4.5315863e-07F,
  101798. 4.8260743e-07F, 5.1396998e-07F, 5.4737065e-07F, 5.8294187e-07F,
  101799. 6.2082472e-07F, 6.6116941e-07F, 7.0413592e-07F, 7.4989464e-07F,
  101800. 7.9862701e-07F, 8.5052630e-07F, 9.0579828e-07F, 9.6466216e-07F,
  101801. 1.0273513e-06F, 1.0941144e-06F, 1.1652161e-06F, 1.2409384e-06F,
  101802. 1.3215816e-06F, 1.4074654e-06F, 1.4989305e-06F, 1.5963394e-06F,
  101803. 1.7000785e-06F, 1.8105592e-06F, 1.9282195e-06F, 2.0535261e-06F,
  101804. 2.1869758e-06F, 2.3290978e-06F, 2.4804557e-06F, 2.6416497e-06F,
  101805. 2.8133190e-06F, 2.9961443e-06F, 3.1908506e-06F, 3.3982101e-06F,
  101806. 3.6190449e-06F, 3.8542308e-06F, 4.1047004e-06F, 4.3714470e-06F,
  101807. 4.6555282e-06F, 4.9580707e-06F, 5.2802740e-06F, 5.6234160e-06F,
  101808. 5.9888572e-06F, 6.3780469e-06F, 6.7925283e-06F, 7.2339451e-06F,
  101809. 7.7040476e-06F, 8.2047000e-06F, 8.7378876e-06F, 9.3057248e-06F,
  101810. 9.9104632e-06F, 1.0554501e-05F, 1.1240392e-05F, 1.1970856e-05F,
  101811. 1.2748789e-05F, 1.3577278e-05F, 1.4459606e-05F, 1.5399272e-05F,
  101812. 1.6400004e-05F, 1.7465768e-05F, 1.8600792e-05F, 1.9809576e-05F,
  101813. 2.1096914e-05F, 2.2467911e-05F, 2.3928002e-05F, 2.5482978e-05F,
  101814. 2.7139006e-05F, 2.8902651e-05F, 3.0780908e-05F, 3.2781225e-05F,
  101815. 3.4911534e-05F, 3.7180282e-05F, 3.9596466e-05F, 4.2169667e-05F,
  101816. 4.4910090e-05F, 4.7828601e-05F, 5.0936773e-05F, 5.4246931e-05F,
  101817. 5.7772202e-05F, 6.1526565e-05F, 6.5524908e-05F, 6.9783085e-05F,
  101818. 7.4317983e-05F, 7.9147585e-05F, 8.4291040e-05F, 8.9768747e-05F,
  101819. 9.5602426e-05F, 0.00010181521F, 0.00010843174F, 0.00011547824F,
  101820. 0.00012298267F, 0.00013097477F, 0.00013948625F, 0.00014855085F,
  101821. 0.00015820453F, 0.00016848555F, 0.00017943469F, 0.00019109536F,
  101822. 0.00020351382F, 0.00021673929F, 0.00023082423F, 0.00024582449F,
  101823. 0.00026179955F, 0.00027881276F, 0.00029693158F, 0.00031622787F,
  101824. 0.00033677814F, 0.00035866388F, 0.00038197188F, 0.00040679456F,
  101825. 0.00043323036F, 0.00046138411F, 0.00049136745F, 0.00052329927F,
  101826. 0.00055730621F, 0.00059352311F, 0.00063209358F, 0.00067317058F,
  101827. 0.00071691700F, 0.00076350630F, 0.00081312324F, 0.00086596457F,
  101828. 0.00092223983F, 0.00098217216F, 0.0010459992F, 0.0011139742F,
  101829. 0.0011863665F, 0.0012634633F, 0.0013455702F, 0.0014330129F,
  101830. 0.0015261382F, 0.0016253153F, 0.0017309374F, 0.0018434235F,
  101831. 0.0019632195F, 0.0020908006F, 0.0022266726F, 0.0023713743F,
  101832. 0.0025254795F, 0.0026895994F, 0.0028643847F, 0.0030505286F,
  101833. 0.0032487691F, 0.0034598925F, 0.0036847358F, 0.0039241906F,
  101834. 0.0041792066F, 0.0044507950F, 0.0047400328F, 0.0050480668F,
  101835. 0.0053761186F, 0.0057254891F, 0.0060975636F, 0.0064938176F,
  101836. 0.0069158225F, 0.0073652516F, 0.0078438871F, 0.0083536271F,
  101837. 0.0088964928F, 0.009474637F, 0.010090352F, 0.010746080F,
  101838. 0.011444421F, 0.012188144F, 0.012980198F, 0.013823725F,
  101839. 0.014722068F, 0.015678791F, 0.016697687F, 0.017782797F,
  101840. 0.018938423F, 0.020169149F, 0.021479854F, 0.022875735F,
  101841. 0.024362330F, 0.025945531F, 0.027631618F, 0.029427276F,
  101842. 0.031339626F, 0.033376252F, 0.035545228F, 0.037855157F,
  101843. 0.040315199F, 0.042935108F, 0.045725273F, 0.048696758F,
  101844. 0.051861348F, 0.055231591F, 0.058820850F, 0.062643361F,
  101845. 0.066714279F, 0.071049749F, 0.075666962F, 0.080584227F,
  101846. 0.085821044F, 0.091398179F, 0.097337747F, 0.10366330F,
  101847. 0.11039993F, 0.11757434F, 0.12521498F, 0.13335215F,
  101848. 0.14201813F, 0.15124727F, 0.16107617F, 0.17154380F,
  101849. 0.18269168F, 0.19456402F, 0.20720788F, 0.22067342F,
  101850. 0.23501402F, 0.25028656F, 0.26655159F, 0.28387361F,
  101851. 0.30232132F, 0.32196786F, 0.34289114F, 0.36517414F,
  101852. 0.38890521F, 0.41417847F, 0.44109412F, 0.46975890F,
  101853. 0.50028648F, 0.53279791F, 0.56742212F, 0.60429640F,
  101854. 0.64356699F, 0.68538959F, 0.72993007F, 0.77736504F,
  101855. 0.82788260F, 0.88168307F, 0.9389798F, 1.F,
  101856. };
  101857. #endif
  101858. extern int *floor1_fit(vorbis_block *vb,void *look,
  101859. const float *logmdct, /* in */
  101860. const float *logmask);
  101861. extern int *floor1_interpolate_fit(vorbis_block *vb,void *look,
  101862. int *A,int *B,
  101863. int del);
  101864. extern int floor1_encode(oggpack_buffer *opb,vorbis_block *vb,
  101865. void*look,
  101866. int *post,int *ilogmask);
  101867. static int mapping0_forward(vorbis_block *vb){
  101868. vorbis_dsp_state *vd=vb->vd;
  101869. vorbis_info *vi=vd->vi;
  101870. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  101871. private_state *b=(private_state*)vb->vd->backend_state;
  101872. vorbis_block_internal *vbi=(vorbis_block_internal *)vb->internal;
  101873. int n=vb->pcmend;
  101874. int i,j,k;
  101875. int *nonzero = (int*) alloca(sizeof(*nonzero)*vi->channels);
  101876. float **gmdct = (float**) _vorbis_block_alloc(vb,vi->channels*sizeof(*gmdct));
  101877. int **ilogmaskch= (int**) _vorbis_block_alloc(vb,vi->channels*sizeof(*ilogmaskch));
  101878. int ***floor_posts = (int***) _vorbis_block_alloc(vb,vi->channels*sizeof(*floor_posts));
  101879. float global_ampmax=vbi->ampmax;
  101880. float *local_ampmax=(float*)alloca(sizeof(*local_ampmax)*vi->channels);
  101881. int blocktype=vbi->blocktype;
  101882. int modenumber=vb->W;
  101883. vorbis_info_mapping0 *info=(vorbis_info_mapping0*)ci->map_param[modenumber];
  101884. vorbis_look_psy *psy_look=
  101885. b->psy+blocktype+(vb->W?2:0);
  101886. vb->mode=modenumber;
  101887. for(i=0;i<vi->channels;i++){
  101888. float scale=4.f/n;
  101889. float scale_dB;
  101890. float *pcm =vb->pcm[i];
  101891. float *logfft =pcm;
  101892. gmdct[i]=(float*)_vorbis_block_alloc(vb,n/2*sizeof(**gmdct));
  101893. scale_dB=todB(&scale) + .345; /* + .345 is a hack; the original
  101894. todB estimation used on IEEE 754
  101895. compliant machines had a bug that
  101896. returned dB values about a third
  101897. of a decibel too high. The bug
  101898. was harmless because tunings
  101899. implicitly took that into
  101900. account. However, fixing the bug
  101901. in the estimator requires
  101902. changing all the tunings as well.
  101903. For now, it's easier to sync
  101904. things back up here, and
  101905. recalibrate the tunings in the
  101906. next major model upgrade. */
  101907. #if 0
  101908. if(vi->channels==2)
  101909. if(i==0)
  101910. _analysis_output("pcmL",seq,pcm,n,0,0,total-n/2);
  101911. else
  101912. _analysis_output("pcmR",seq,pcm,n,0,0,total-n/2);
  101913. #endif
  101914. _vorbis_apply_window(pcm,b->window,ci->blocksizes,vb->lW,vb->W,vb->nW);
  101915. #if 0
  101916. if(vi->channels==2)
  101917. if(i==0)
  101918. _analysis_output("windowedL",seq,pcm,n,0,0,total-n/2);
  101919. else
  101920. _analysis_output("windowedR",seq,pcm,n,0,0,total-n/2);
  101921. #endif
  101922. mdct_forward((mdct_lookup*) b->transform[vb->W][0],pcm,gmdct[i]);
  101923. drft_forward(&b->fft_look[vb->W],pcm);
  101924. logfft[0]=scale_dB+todB(pcm) + .345; /* + .345 is a hack; the
  101925. original todB estimation used on
  101926. IEEE 754 compliant machines had a
  101927. bug that returned dB values about
  101928. a third of a decibel too high.
  101929. The bug was harmless because
  101930. tunings implicitly took that into
  101931. account. However, fixing the bug
  101932. in the estimator requires
  101933. changing all the tunings as well.
  101934. For now, it's easier to sync
  101935. things back up here, and
  101936. recalibrate the tunings in the
  101937. next major model upgrade. */
  101938. local_ampmax[i]=logfft[0];
  101939. for(j=1;j<n-1;j+=2){
  101940. float temp=pcm[j]*pcm[j]+pcm[j+1]*pcm[j+1];
  101941. temp=logfft[(j+1)>>1]=scale_dB+.5f*todB(&temp) + .345; /* +
  101942. .345 is a hack; the original todB
  101943. estimation used on IEEE 754
  101944. compliant machines had a bug that
  101945. returned dB values about a third
  101946. of a decibel too high. The bug
  101947. was harmless because tunings
  101948. implicitly took that into
  101949. account. However, fixing the bug
  101950. in the estimator requires
  101951. changing all the tunings as well.
  101952. For now, it's easier to sync
  101953. things back up here, and
  101954. recalibrate the tunings in the
  101955. next major model upgrade. */
  101956. if(temp>local_ampmax[i])local_ampmax[i]=temp;
  101957. }
  101958. if(local_ampmax[i]>0.f)local_ampmax[i]=0.f;
  101959. if(local_ampmax[i]>global_ampmax)global_ampmax=local_ampmax[i];
  101960. #if 0
  101961. if(vi->channels==2){
  101962. if(i==0){
  101963. _analysis_output("fftL",seq,logfft,n/2,1,0,0);
  101964. }else{
  101965. _analysis_output("fftR",seq,logfft,n/2,1,0,0);
  101966. }
  101967. }
  101968. #endif
  101969. }
  101970. {
  101971. float *noise = (float*) _vorbis_block_alloc(vb,n/2*sizeof(*noise));
  101972. float *tone = (float*) _vorbis_block_alloc(vb,n/2*sizeof(*tone));
  101973. for(i=0;i<vi->channels;i++){
  101974. int submap=info->chmuxlist[i];
  101975. float *mdct =gmdct[i];
  101976. float *logfft =vb->pcm[i];
  101977. float *logmdct =logfft+n/2;
  101978. float *logmask =logfft;
  101979. vb->mode=modenumber;
  101980. floor_posts[i]=(int**) _vorbis_block_alloc(vb,PACKETBLOBS*sizeof(**floor_posts));
  101981. memset(floor_posts[i],0,sizeof(**floor_posts)*PACKETBLOBS);
  101982. for(j=0;j<n/2;j++)
  101983. logmdct[j]=todB(mdct+j) + .345; /* + .345 is a hack; the original
  101984. todB estimation used on IEEE 754
  101985. compliant machines had a bug that
  101986. returned dB values about a third
  101987. of a decibel too high. The bug
  101988. was harmless because tunings
  101989. implicitly took that into
  101990. account. However, fixing the bug
  101991. in the estimator requires
  101992. changing all the tunings as well.
  101993. For now, it's easier to sync
  101994. things back up here, and
  101995. recalibrate the tunings in the
  101996. next major model upgrade. */
  101997. #if 0
  101998. if(vi->channels==2){
  101999. if(i==0)
  102000. _analysis_output("mdctL",seq,logmdct,n/2,1,0,0);
  102001. else
  102002. _analysis_output("mdctR",seq,logmdct,n/2,1,0,0);
  102003. }else{
  102004. _analysis_output("mdct",seq,logmdct,n/2,1,0,0);
  102005. }
  102006. #endif
  102007. _vp_noisemask(psy_look,
  102008. logmdct,
  102009. noise); /* noise does not have by-frequency offset
  102010. bias applied yet */
  102011. #if 0
  102012. if(vi->channels==2){
  102013. if(i==0)
  102014. _analysis_output("noiseL",seq,noise,n/2,1,0,0);
  102015. else
  102016. _analysis_output("noiseR",seq,noise,n/2,1,0,0);
  102017. }
  102018. #endif
  102019. _vp_tonemask(psy_look,
  102020. logfft,
  102021. tone,
  102022. global_ampmax,
  102023. local_ampmax[i]);
  102024. #if 0
  102025. if(vi->channels==2){
  102026. if(i==0)
  102027. _analysis_output("toneL",seq,tone,n/2,1,0,0);
  102028. else
  102029. _analysis_output("toneR",seq,tone,n/2,1,0,0);
  102030. }
  102031. #endif
  102032. #if 0
  102033. {
  102034. float aotuv[psy_look->n];
  102035. #endif
  102036. _vp_offset_and_mix(psy_look,
  102037. noise,
  102038. tone,
  102039. 1,
  102040. logmask,
  102041. mdct,
  102042. logmdct);
  102043. #if 0
  102044. if(vi->channels==2){
  102045. if(i==0)
  102046. _analysis_output("aotuvM1_L",seq,aotuv,psy_look->n,1,1,0);
  102047. else
  102048. _analysis_output("aotuvM1_R",seq,aotuv,psy_look->n,1,1,0);
  102049. }
  102050. }
  102051. #endif
  102052. #if 0
  102053. if(vi->channels==2){
  102054. if(i==0)
  102055. _analysis_output("mask1L",seq,logmask,n/2,1,0,0);
  102056. else
  102057. _analysis_output("mask1R",seq,logmask,n/2,1,0,0);
  102058. }
  102059. #endif
  102060. if(ci->floor_type[info->floorsubmap[submap]]!=1)return(-1);
  102061. floor_posts[i][PACKETBLOBS/2]=
  102062. floor1_fit(vb,b->flr[info->floorsubmap[submap]],
  102063. logmdct,
  102064. logmask);
  102065. if(vorbis_bitrate_managed(vb) && floor_posts[i][PACKETBLOBS/2]){
  102066. _vp_offset_and_mix(psy_look,
  102067. noise,
  102068. tone,
  102069. 2,
  102070. logmask,
  102071. mdct,
  102072. logmdct);
  102073. #if 0
  102074. if(vi->channels==2){
  102075. if(i==0)
  102076. _analysis_output("mask2L",seq,logmask,n/2,1,0,0);
  102077. else
  102078. _analysis_output("mask2R",seq,logmask,n/2,1,0,0);
  102079. }
  102080. #endif
  102081. floor_posts[i][PACKETBLOBS-1]=
  102082. floor1_fit(vb,b->flr[info->floorsubmap[submap]],
  102083. logmdct,
  102084. logmask);
  102085. _vp_offset_and_mix(psy_look,
  102086. noise,
  102087. tone,
  102088. 0,
  102089. logmask,
  102090. mdct,
  102091. logmdct);
  102092. #if 0
  102093. if(vi->channels==2)
  102094. if(i==0)
  102095. _analysis_output("mask0L",seq,logmask,n/2,1,0,0);
  102096. else
  102097. _analysis_output("mask0R",seq,logmask,n/2,1,0,0);
  102098. #endif
  102099. floor_posts[i][0]=
  102100. floor1_fit(vb,b->flr[info->floorsubmap[submap]],
  102101. logmdct,
  102102. logmask);
  102103. for(k=1;k<PACKETBLOBS/2;k++)
  102104. floor_posts[i][k]=
  102105. floor1_interpolate_fit(vb,b->flr[info->floorsubmap[submap]],
  102106. floor_posts[i][0],
  102107. floor_posts[i][PACKETBLOBS/2],
  102108. k*65536/(PACKETBLOBS/2));
  102109. for(k=PACKETBLOBS/2+1;k<PACKETBLOBS-1;k++)
  102110. floor_posts[i][k]=
  102111. floor1_interpolate_fit(vb,b->flr[info->floorsubmap[submap]],
  102112. floor_posts[i][PACKETBLOBS/2],
  102113. floor_posts[i][PACKETBLOBS-1],
  102114. (k-PACKETBLOBS/2)*65536/(PACKETBLOBS/2));
  102115. }
  102116. }
  102117. }
  102118. vbi->ampmax=global_ampmax;
  102119. {
  102120. float **res_bundle=(float**) alloca(sizeof(*res_bundle)*vi->channels);
  102121. float **couple_bundle=(float**) alloca(sizeof(*couple_bundle)*vi->channels);
  102122. int *zerobundle=(int*) alloca(sizeof(*zerobundle)*vi->channels);
  102123. int **sortindex=(int**) alloca(sizeof(*sortindex)*vi->channels);
  102124. float **mag_memo;
  102125. int **mag_sort;
  102126. if(info->coupling_steps){
  102127. mag_memo=_vp_quantize_couple_memo(vb,
  102128. &ci->psy_g_param,
  102129. psy_look,
  102130. info,
  102131. gmdct);
  102132. mag_sort=_vp_quantize_couple_sort(vb,
  102133. psy_look,
  102134. info,
  102135. mag_memo);
  102136. hf_reduction(&ci->psy_g_param,
  102137. psy_look,
  102138. info,
  102139. mag_memo);
  102140. }
  102141. memset(sortindex,0,sizeof(*sortindex)*vi->channels);
  102142. if(psy_look->vi->normal_channel_p){
  102143. for(i=0;i<vi->channels;i++){
  102144. float *mdct =gmdct[i];
  102145. sortindex[i]=(int*) alloca(sizeof(**sortindex)*n/2);
  102146. _vp_noise_normalize_sort(psy_look,mdct,sortindex[i]);
  102147. }
  102148. }
  102149. for(k=(vorbis_bitrate_managed(vb)?0:PACKETBLOBS/2);
  102150. k<=(vorbis_bitrate_managed(vb)?PACKETBLOBS-1:PACKETBLOBS/2);
  102151. k++){
  102152. oggpack_buffer *opb=vbi->packetblob[k];
  102153. oggpack_write(opb,0,1);
  102154. oggpack_write(opb,modenumber,b->modebits);
  102155. if(vb->W){
  102156. oggpack_write(opb,vb->lW,1);
  102157. oggpack_write(opb,vb->nW,1);
  102158. }
  102159. for(i=0;i<vi->channels;i++){
  102160. int submap=info->chmuxlist[i];
  102161. float *mdct =gmdct[i];
  102162. float *res =vb->pcm[i];
  102163. int *ilogmask=ilogmaskch[i]=
  102164. (int*) _vorbis_block_alloc(vb,n/2*sizeof(**gmdct));
  102165. nonzero[i]=floor1_encode(opb,vb,b->flr[info->floorsubmap[submap]],
  102166. floor_posts[i][k],
  102167. ilogmask);
  102168. #if 0
  102169. {
  102170. char buf[80];
  102171. sprintf(buf,"maskI%c%d",i?'R':'L',k);
  102172. float work[n/2];
  102173. for(j=0;j<n/2;j++)
  102174. work[j]=FLOOR1_fromdB_LOOKUP[ilogmask[j]];
  102175. _analysis_output(buf,seq,work,n/2,1,1,0);
  102176. }
  102177. #endif
  102178. _vp_remove_floor(psy_look,
  102179. mdct,
  102180. ilogmask,
  102181. res,
  102182. ci->psy_g_param.sliding_lowpass[vb->W][k]);
  102183. _vp_noise_normalize(psy_look,res,res+n/2,sortindex[i]);
  102184. #if 0
  102185. {
  102186. char buf[80];
  102187. float work[n/2];
  102188. for(j=0;j<n/2;j++)
  102189. work[j]=FLOOR1_fromdB_LOOKUP[ilogmask[j]]*(res+n/2)[j];
  102190. sprintf(buf,"resI%c%d",i?'R':'L',k);
  102191. _analysis_output(buf,seq,work,n/2,1,1,0);
  102192. }
  102193. #endif
  102194. }
  102195. if(info->coupling_steps){
  102196. _vp_couple(k,
  102197. &ci->psy_g_param,
  102198. psy_look,
  102199. info,
  102200. vb->pcm,
  102201. mag_memo,
  102202. mag_sort,
  102203. ilogmaskch,
  102204. nonzero,
  102205. ci->psy_g_param.sliding_lowpass[vb->W][k]);
  102206. }
  102207. for(i=0;i<info->submaps;i++){
  102208. int ch_in_bundle=0;
  102209. long **classifications;
  102210. int resnum=info->residuesubmap[i];
  102211. for(j=0;j<vi->channels;j++){
  102212. if(info->chmuxlist[j]==i){
  102213. zerobundle[ch_in_bundle]=0;
  102214. if(nonzero[j])zerobundle[ch_in_bundle]=1;
  102215. res_bundle[ch_in_bundle]=vb->pcm[j];
  102216. couple_bundle[ch_in_bundle++]=vb->pcm[j]+n/2;
  102217. }
  102218. }
  102219. classifications=_residue_P[ci->residue_type[resnum]]->
  102220. classx(vb,b->residue[resnum],couple_bundle,zerobundle,ch_in_bundle);
  102221. _residue_P[ci->residue_type[resnum]]->
  102222. forward(opb,vb,b->residue[resnum],
  102223. couple_bundle,NULL,zerobundle,ch_in_bundle,classifications);
  102224. }
  102225. }
  102226. }
  102227. #if 0
  102228. seq++;
  102229. total+=ci->blocksizes[vb->W]/4+ci->blocksizes[vb->nW]/4;
  102230. #endif
  102231. return(0);
  102232. }
  102233. static int mapping0_inverse(vorbis_block *vb,vorbis_info_mapping *l){
  102234. vorbis_dsp_state *vd=vb->vd;
  102235. vorbis_info *vi=vd->vi;
  102236. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  102237. private_state *b=(private_state*)vd->backend_state;
  102238. vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)l;
  102239. int i,j;
  102240. long n=vb->pcmend=ci->blocksizes[vb->W];
  102241. float **pcmbundle=(float**) alloca(sizeof(*pcmbundle)*vi->channels);
  102242. int *zerobundle=(int*) alloca(sizeof(*zerobundle)*vi->channels);
  102243. int *nonzero =(int*) alloca(sizeof(*nonzero)*vi->channels);
  102244. void **floormemo=(void**) alloca(sizeof(*floormemo)*vi->channels);
  102245. for(i=0;i<vi->channels;i++){
  102246. int submap=info->chmuxlist[i];
  102247. floormemo[i]=_floor_P[ci->floor_type[info->floorsubmap[submap]]]->
  102248. inverse1(vb,b->flr[info->floorsubmap[submap]]);
  102249. if(floormemo[i])
  102250. nonzero[i]=1;
  102251. else
  102252. nonzero[i]=0;
  102253. memset(vb->pcm[i],0,sizeof(*vb->pcm[i])*n/2);
  102254. }
  102255. for(i=0;i<info->coupling_steps;i++){
  102256. if(nonzero[info->coupling_mag[i]] ||
  102257. nonzero[info->coupling_ang[i]]){
  102258. nonzero[info->coupling_mag[i]]=1;
  102259. nonzero[info->coupling_ang[i]]=1;
  102260. }
  102261. }
  102262. for(i=0;i<info->submaps;i++){
  102263. int ch_in_bundle=0;
  102264. for(j=0;j<vi->channels;j++){
  102265. if(info->chmuxlist[j]==i){
  102266. if(nonzero[j])
  102267. zerobundle[ch_in_bundle]=1;
  102268. else
  102269. zerobundle[ch_in_bundle]=0;
  102270. pcmbundle[ch_in_bundle++]=vb->pcm[j];
  102271. }
  102272. }
  102273. _residue_P[ci->residue_type[info->residuesubmap[i]]]->
  102274. inverse(vb,b->residue[info->residuesubmap[i]],
  102275. pcmbundle,zerobundle,ch_in_bundle);
  102276. }
  102277. for(i=info->coupling_steps-1;i>=0;i--){
  102278. float *pcmM=vb->pcm[info->coupling_mag[i]];
  102279. float *pcmA=vb->pcm[info->coupling_ang[i]];
  102280. for(j=0;j<n/2;j++){
  102281. float mag=pcmM[j];
  102282. float ang=pcmA[j];
  102283. if(mag>0)
  102284. if(ang>0){
  102285. pcmM[j]=mag;
  102286. pcmA[j]=mag-ang;
  102287. }else{
  102288. pcmA[j]=mag;
  102289. pcmM[j]=mag+ang;
  102290. }
  102291. else
  102292. if(ang>0){
  102293. pcmM[j]=mag;
  102294. pcmA[j]=mag+ang;
  102295. }else{
  102296. pcmA[j]=mag;
  102297. pcmM[j]=mag-ang;
  102298. }
  102299. }
  102300. }
  102301. for(i=0;i<vi->channels;i++){
  102302. float *pcm=vb->pcm[i];
  102303. int submap=info->chmuxlist[i];
  102304. _floor_P[ci->floor_type[info->floorsubmap[submap]]]->
  102305. inverse2(vb,b->flr[info->floorsubmap[submap]],
  102306. floormemo[i],pcm);
  102307. }
  102308. for(i=0;i<vi->channels;i++){
  102309. float *pcm=vb->pcm[i];
  102310. mdct_backward((mdct_lookup*) b->transform[vb->W][0],pcm,pcm);
  102311. }
  102312. return(0);
  102313. }
  102314. vorbis_func_mapping mapping0_exportbundle={
  102315. &mapping0_pack,
  102316. &mapping0_unpack,
  102317. &mapping0_free_info,
  102318. &mapping0_forward,
  102319. &mapping0_inverse
  102320. };
  102321. #endif
  102322. /*** End of inlined file: mapping0.c ***/
  102323. /*** Start of inlined file: mdct.c ***/
  102324. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  102325. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  102326. // tasks..
  102327. #if JUCE_MSVC
  102328. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  102329. #endif
  102330. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  102331. #if JUCE_USE_OGGVORBIS
  102332. #include <stdio.h>
  102333. #include <stdlib.h>
  102334. #include <string.h>
  102335. #include <math.h>
  102336. void mdct_init(mdct_lookup *lookup,int n){
  102337. int *bitrev=(int*) _ogg_malloc(sizeof(*bitrev)*(n/4));
  102338. DATA_TYPE *T=(DATA_TYPE*) _ogg_malloc(sizeof(*T)*(n+n/4));
  102339. int i;
  102340. int n2=n>>1;
  102341. int log2n=lookup->log2n=rint(log((float)n)/log(2.f));
  102342. lookup->n=n;
  102343. lookup->trig=T;
  102344. lookup->bitrev=bitrev;
  102345. for(i=0;i<n/4;i++){
  102346. T[i*2]=FLOAT_CONV(cos((M_PI/n)*(4*i)));
  102347. T[i*2+1]=FLOAT_CONV(-sin((M_PI/n)*(4*i)));
  102348. T[n2+i*2]=FLOAT_CONV(cos((M_PI/(2*n))*(2*i+1)));
  102349. T[n2+i*2+1]=FLOAT_CONV(sin((M_PI/(2*n))*(2*i+1)));
  102350. }
  102351. for(i=0;i<n/8;i++){
  102352. T[n+i*2]=FLOAT_CONV(cos((M_PI/n)*(4*i+2))*.5);
  102353. T[n+i*2+1]=FLOAT_CONV(-sin((M_PI/n)*(4*i+2))*.5);
  102354. }
  102355. {
  102356. int mask=(1<<(log2n-1))-1,i,j;
  102357. int msb=1<<(log2n-2);
  102358. for(i=0;i<n/8;i++){
  102359. int acc=0;
  102360. for(j=0;msb>>j;j++)
  102361. if((msb>>j)&i)acc|=1<<j;
  102362. bitrev[i*2]=((~acc)&mask)-1;
  102363. bitrev[i*2+1]=acc;
  102364. }
  102365. }
  102366. lookup->scale=FLOAT_CONV(4.f/n);
  102367. }
  102368. STIN void mdct_butterfly_8(DATA_TYPE *x){
  102369. REG_TYPE r0 = x[6] + x[2];
  102370. REG_TYPE r1 = x[6] - x[2];
  102371. REG_TYPE r2 = x[4] + x[0];
  102372. REG_TYPE r3 = x[4] - x[0];
  102373. x[6] = r0 + r2;
  102374. x[4] = r0 - r2;
  102375. r0 = x[5] - x[1];
  102376. r2 = x[7] - x[3];
  102377. x[0] = r1 + r0;
  102378. x[2] = r1 - r0;
  102379. r0 = x[5] + x[1];
  102380. r1 = x[7] + x[3];
  102381. x[3] = r2 + r3;
  102382. x[1] = r2 - r3;
  102383. x[7] = r1 + r0;
  102384. x[5] = r1 - r0;
  102385. }
  102386. STIN void mdct_butterfly_16(DATA_TYPE *x){
  102387. REG_TYPE r0 = x[1] - x[9];
  102388. REG_TYPE r1 = x[0] - x[8];
  102389. x[8] += x[0];
  102390. x[9] += x[1];
  102391. x[0] = MULT_NORM((r0 + r1) * cPI2_8);
  102392. x[1] = MULT_NORM((r0 - r1) * cPI2_8);
  102393. r0 = x[3] - x[11];
  102394. r1 = x[10] - x[2];
  102395. x[10] += x[2];
  102396. x[11] += x[3];
  102397. x[2] = r0;
  102398. x[3] = r1;
  102399. r0 = x[12] - x[4];
  102400. r1 = x[13] - x[5];
  102401. x[12] += x[4];
  102402. x[13] += x[5];
  102403. x[4] = MULT_NORM((r0 - r1) * cPI2_8);
  102404. x[5] = MULT_NORM((r0 + r1) * cPI2_8);
  102405. r0 = x[14] - x[6];
  102406. r1 = x[15] - x[7];
  102407. x[14] += x[6];
  102408. x[15] += x[7];
  102409. x[6] = r0;
  102410. x[7] = r1;
  102411. mdct_butterfly_8(x);
  102412. mdct_butterfly_8(x+8);
  102413. }
  102414. STIN void mdct_butterfly_32(DATA_TYPE *x){
  102415. REG_TYPE r0 = x[30] - x[14];
  102416. REG_TYPE r1 = x[31] - x[15];
  102417. x[30] += x[14];
  102418. x[31] += x[15];
  102419. x[14] = r0;
  102420. x[15] = r1;
  102421. r0 = x[28] - x[12];
  102422. r1 = x[29] - x[13];
  102423. x[28] += x[12];
  102424. x[29] += x[13];
  102425. x[12] = MULT_NORM( r0 * cPI1_8 - r1 * cPI3_8 );
  102426. x[13] = MULT_NORM( r0 * cPI3_8 + r1 * cPI1_8 );
  102427. r0 = x[26] - x[10];
  102428. r1 = x[27] - x[11];
  102429. x[26] += x[10];
  102430. x[27] += x[11];
  102431. x[10] = MULT_NORM(( r0 - r1 ) * cPI2_8);
  102432. x[11] = MULT_NORM(( r0 + r1 ) * cPI2_8);
  102433. r0 = x[24] - x[8];
  102434. r1 = x[25] - x[9];
  102435. x[24] += x[8];
  102436. x[25] += x[9];
  102437. x[8] = MULT_NORM( r0 * cPI3_8 - r1 * cPI1_8 );
  102438. x[9] = MULT_NORM( r1 * cPI3_8 + r0 * cPI1_8 );
  102439. r0 = x[22] - x[6];
  102440. r1 = x[7] - x[23];
  102441. x[22] += x[6];
  102442. x[23] += x[7];
  102443. x[6] = r1;
  102444. x[7] = r0;
  102445. r0 = x[4] - x[20];
  102446. r1 = x[5] - x[21];
  102447. x[20] += x[4];
  102448. x[21] += x[5];
  102449. x[4] = MULT_NORM( r1 * cPI1_8 + r0 * cPI3_8 );
  102450. x[5] = MULT_NORM( r1 * cPI3_8 - r0 * cPI1_8 );
  102451. r0 = x[2] - x[18];
  102452. r1 = x[3] - x[19];
  102453. x[18] += x[2];
  102454. x[19] += x[3];
  102455. x[2] = MULT_NORM(( r1 + r0 ) * cPI2_8);
  102456. x[3] = MULT_NORM(( r1 - r0 ) * cPI2_8);
  102457. r0 = x[0] - x[16];
  102458. r1 = x[1] - x[17];
  102459. x[16] += x[0];
  102460. x[17] += x[1];
  102461. x[0] = MULT_NORM( r1 * cPI3_8 + r0 * cPI1_8 );
  102462. x[1] = MULT_NORM( r1 * cPI1_8 - r0 * cPI3_8 );
  102463. mdct_butterfly_16(x);
  102464. mdct_butterfly_16(x+16);
  102465. }
  102466. STIN void mdct_butterfly_first(DATA_TYPE *T,
  102467. DATA_TYPE *x,
  102468. int points){
  102469. DATA_TYPE *x1 = x + points - 8;
  102470. DATA_TYPE *x2 = x + (points>>1) - 8;
  102471. REG_TYPE r0;
  102472. REG_TYPE r1;
  102473. do{
  102474. r0 = x1[6] - x2[6];
  102475. r1 = x1[7] - x2[7];
  102476. x1[6] += x2[6];
  102477. x1[7] += x2[7];
  102478. x2[6] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  102479. x2[7] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  102480. r0 = x1[4] - x2[4];
  102481. r1 = x1[5] - x2[5];
  102482. x1[4] += x2[4];
  102483. x1[5] += x2[5];
  102484. x2[4] = MULT_NORM(r1 * T[5] + r0 * T[4]);
  102485. x2[5] = MULT_NORM(r1 * T[4] - r0 * T[5]);
  102486. r0 = x1[2] - x2[2];
  102487. r1 = x1[3] - x2[3];
  102488. x1[2] += x2[2];
  102489. x1[3] += x2[3];
  102490. x2[2] = MULT_NORM(r1 * T[9] + r0 * T[8]);
  102491. x2[3] = MULT_NORM(r1 * T[8] - r0 * T[9]);
  102492. r0 = x1[0] - x2[0];
  102493. r1 = x1[1] - x2[1];
  102494. x1[0] += x2[0];
  102495. x1[1] += x2[1];
  102496. x2[0] = MULT_NORM(r1 * T[13] + r0 * T[12]);
  102497. x2[1] = MULT_NORM(r1 * T[12] - r0 * T[13]);
  102498. x1-=8;
  102499. x2-=8;
  102500. T+=16;
  102501. }while(x2>=x);
  102502. }
  102503. STIN void mdct_butterfly_generic(DATA_TYPE *T,
  102504. DATA_TYPE *x,
  102505. int points,
  102506. int trigint){
  102507. DATA_TYPE *x1 = x + points - 8;
  102508. DATA_TYPE *x2 = x + (points>>1) - 8;
  102509. REG_TYPE r0;
  102510. REG_TYPE r1;
  102511. do{
  102512. r0 = x1[6] - x2[6];
  102513. r1 = x1[7] - x2[7];
  102514. x1[6] += x2[6];
  102515. x1[7] += x2[7];
  102516. x2[6] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  102517. x2[7] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  102518. T+=trigint;
  102519. r0 = x1[4] - x2[4];
  102520. r1 = x1[5] - x2[5];
  102521. x1[4] += x2[4];
  102522. x1[5] += x2[5];
  102523. x2[4] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  102524. x2[5] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  102525. T+=trigint;
  102526. r0 = x1[2] - x2[2];
  102527. r1 = x1[3] - x2[3];
  102528. x1[2] += x2[2];
  102529. x1[3] += x2[3];
  102530. x2[2] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  102531. x2[3] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  102532. T+=trigint;
  102533. r0 = x1[0] - x2[0];
  102534. r1 = x1[1] - x2[1];
  102535. x1[0] += x2[0];
  102536. x1[1] += x2[1];
  102537. x2[0] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  102538. x2[1] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  102539. T+=trigint;
  102540. x1-=8;
  102541. x2-=8;
  102542. }while(x2>=x);
  102543. }
  102544. STIN void mdct_butterflies(mdct_lookup *init,
  102545. DATA_TYPE *x,
  102546. int points){
  102547. DATA_TYPE *T=init->trig;
  102548. int stages=init->log2n-5;
  102549. int i,j;
  102550. if(--stages>0){
  102551. mdct_butterfly_first(T,x,points);
  102552. }
  102553. for(i=1;--stages>0;i++){
  102554. for(j=0;j<(1<<i);j++)
  102555. mdct_butterfly_generic(T,x+(points>>i)*j,points>>i,4<<i);
  102556. }
  102557. for(j=0;j<points;j+=32)
  102558. mdct_butterfly_32(x+j);
  102559. }
  102560. void mdct_clear(mdct_lookup *l){
  102561. if(l){
  102562. if(l->trig)_ogg_free(l->trig);
  102563. if(l->bitrev)_ogg_free(l->bitrev);
  102564. memset(l,0,sizeof(*l));
  102565. }
  102566. }
  102567. STIN void mdct_bitreverse(mdct_lookup *init,
  102568. DATA_TYPE *x){
  102569. int n = init->n;
  102570. int *bit = init->bitrev;
  102571. DATA_TYPE *w0 = x;
  102572. DATA_TYPE *w1 = x = w0+(n>>1);
  102573. DATA_TYPE *T = init->trig+n;
  102574. do{
  102575. DATA_TYPE *x0 = x+bit[0];
  102576. DATA_TYPE *x1 = x+bit[1];
  102577. REG_TYPE r0 = x0[1] - x1[1];
  102578. REG_TYPE r1 = x0[0] + x1[0];
  102579. REG_TYPE r2 = MULT_NORM(r1 * T[0] + r0 * T[1]);
  102580. REG_TYPE r3 = MULT_NORM(r1 * T[1] - r0 * T[0]);
  102581. w1 -= 4;
  102582. r0 = HALVE(x0[1] + x1[1]);
  102583. r1 = HALVE(x0[0] - x1[0]);
  102584. w0[0] = r0 + r2;
  102585. w1[2] = r0 - r2;
  102586. w0[1] = r1 + r3;
  102587. w1[3] = r3 - r1;
  102588. x0 = x+bit[2];
  102589. x1 = x+bit[3];
  102590. r0 = x0[1] - x1[1];
  102591. r1 = x0[0] + x1[0];
  102592. r2 = MULT_NORM(r1 * T[2] + r0 * T[3]);
  102593. r3 = MULT_NORM(r1 * T[3] - r0 * T[2]);
  102594. r0 = HALVE(x0[1] + x1[1]);
  102595. r1 = HALVE(x0[0] - x1[0]);
  102596. w0[2] = r0 + r2;
  102597. w1[0] = r0 - r2;
  102598. w0[3] = r1 + r3;
  102599. w1[1] = r3 - r1;
  102600. T += 4;
  102601. bit += 4;
  102602. w0 += 4;
  102603. }while(w0<w1);
  102604. }
  102605. void mdct_backward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out){
  102606. int n=init->n;
  102607. int n2=n>>1;
  102608. int n4=n>>2;
  102609. DATA_TYPE *iX = in+n2-7;
  102610. DATA_TYPE *oX = out+n2+n4;
  102611. DATA_TYPE *T = init->trig+n4;
  102612. do{
  102613. oX -= 4;
  102614. oX[0] = MULT_NORM(-iX[2] * T[3] - iX[0] * T[2]);
  102615. oX[1] = MULT_NORM (iX[0] * T[3] - iX[2] * T[2]);
  102616. oX[2] = MULT_NORM(-iX[6] * T[1] - iX[4] * T[0]);
  102617. oX[3] = MULT_NORM (iX[4] * T[1] - iX[6] * T[0]);
  102618. iX -= 8;
  102619. T += 4;
  102620. }while(iX>=in);
  102621. iX = in+n2-8;
  102622. oX = out+n2+n4;
  102623. T = init->trig+n4;
  102624. do{
  102625. T -= 4;
  102626. oX[0] = MULT_NORM (iX[4] * T[3] + iX[6] * T[2]);
  102627. oX[1] = MULT_NORM (iX[4] * T[2] - iX[6] * T[3]);
  102628. oX[2] = MULT_NORM (iX[0] * T[1] + iX[2] * T[0]);
  102629. oX[3] = MULT_NORM (iX[0] * T[0] - iX[2] * T[1]);
  102630. iX -= 8;
  102631. oX += 4;
  102632. }while(iX>=in);
  102633. mdct_butterflies(init,out+n2,n2);
  102634. mdct_bitreverse(init,out);
  102635. {
  102636. DATA_TYPE *oX1=out+n2+n4;
  102637. DATA_TYPE *oX2=out+n2+n4;
  102638. DATA_TYPE *iX =out;
  102639. T =init->trig+n2;
  102640. do{
  102641. oX1-=4;
  102642. oX1[3] = MULT_NORM (iX[0] * T[1] - iX[1] * T[0]);
  102643. oX2[0] = -MULT_NORM (iX[0] * T[0] + iX[1] * T[1]);
  102644. oX1[2] = MULT_NORM (iX[2] * T[3] - iX[3] * T[2]);
  102645. oX2[1] = -MULT_NORM (iX[2] * T[2] + iX[3] * T[3]);
  102646. oX1[1] = MULT_NORM (iX[4] * T[5] - iX[5] * T[4]);
  102647. oX2[2] = -MULT_NORM (iX[4] * T[4] + iX[5] * T[5]);
  102648. oX1[0] = MULT_NORM (iX[6] * T[7] - iX[7] * T[6]);
  102649. oX2[3] = -MULT_NORM (iX[6] * T[6] + iX[7] * T[7]);
  102650. oX2+=4;
  102651. iX += 8;
  102652. T += 8;
  102653. }while(iX<oX1);
  102654. iX=out+n2+n4;
  102655. oX1=out+n4;
  102656. oX2=oX1;
  102657. do{
  102658. oX1-=4;
  102659. iX-=4;
  102660. oX2[0] = -(oX1[3] = iX[3]);
  102661. oX2[1] = -(oX1[2] = iX[2]);
  102662. oX2[2] = -(oX1[1] = iX[1]);
  102663. oX2[3] = -(oX1[0] = iX[0]);
  102664. oX2+=4;
  102665. }while(oX2<iX);
  102666. iX=out+n2+n4;
  102667. oX1=out+n2+n4;
  102668. oX2=out+n2;
  102669. do{
  102670. oX1-=4;
  102671. oX1[0]= iX[3];
  102672. oX1[1]= iX[2];
  102673. oX1[2]= iX[1];
  102674. oX1[3]= iX[0];
  102675. iX+=4;
  102676. }while(oX1>oX2);
  102677. }
  102678. }
  102679. void mdct_forward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out){
  102680. int n=init->n;
  102681. int n2=n>>1;
  102682. int n4=n>>2;
  102683. int n8=n>>3;
  102684. DATA_TYPE *w=(DATA_TYPE*) alloca(n*sizeof(*w)); /* forward needs working space */
  102685. DATA_TYPE *w2=w+n2;
  102686. REG_TYPE r0;
  102687. REG_TYPE r1;
  102688. DATA_TYPE *x0=in+n2+n4;
  102689. DATA_TYPE *x1=x0+1;
  102690. DATA_TYPE *T=init->trig+n2;
  102691. int i=0;
  102692. for(i=0;i<n8;i+=2){
  102693. x0 -=4;
  102694. T-=2;
  102695. r0= x0[2] + x1[0];
  102696. r1= x0[0] + x1[2];
  102697. w2[i]= MULT_NORM(r1*T[1] + r0*T[0]);
  102698. w2[i+1]= MULT_NORM(r1*T[0] - r0*T[1]);
  102699. x1 +=4;
  102700. }
  102701. x1=in+1;
  102702. for(;i<n2-n8;i+=2){
  102703. T-=2;
  102704. x0 -=4;
  102705. r0= x0[2] - x1[0];
  102706. r1= x0[0] - x1[2];
  102707. w2[i]= MULT_NORM(r1*T[1] + r0*T[0]);
  102708. w2[i+1]= MULT_NORM(r1*T[0] - r0*T[1]);
  102709. x1 +=4;
  102710. }
  102711. x0=in+n;
  102712. for(;i<n2;i+=2){
  102713. T-=2;
  102714. x0 -=4;
  102715. r0= -x0[2] - x1[0];
  102716. r1= -x0[0] - x1[2];
  102717. w2[i]= MULT_NORM(r1*T[1] + r0*T[0]);
  102718. w2[i+1]= MULT_NORM(r1*T[0] - r0*T[1]);
  102719. x1 +=4;
  102720. }
  102721. mdct_butterflies(init,w+n2,n2);
  102722. mdct_bitreverse(init,w);
  102723. T=init->trig+n2;
  102724. x0=out+n2;
  102725. for(i=0;i<n4;i++){
  102726. x0--;
  102727. out[i] =MULT_NORM((w[0]*T[0]+w[1]*T[1])*init->scale);
  102728. x0[0] =MULT_NORM((w[0]*T[1]-w[1]*T[0])*init->scale);
  102729. w+=2;
  102730. T+=2;
  102731. }
  102732. }
  102733. #endif
  102734. /*** End of inlined file: mdct.c ***/
  102735. /*** Start of inlined file: psy.c ***/
  102736. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  102737. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  102738. // tasks..
  102739. #if JUCE_MSVC
  102740. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  102741. #endif
  102742. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  102743. #if JUCE_USE_OGGVORBIS
  102744. #include <stdlib.h>
  102745. #include <math.h>
  102746. #include <string.h>
  102747. /*** Start of inlined file: masking.h ***/
  102748. #ifndef _V_MASKING_H_
  102749. #define _V_MASKING_H_
  102750. #define MAX_ATH 88
  102751. static float ATH[]={
  102752. -51, -52, -53, -54, -55, -56, -57, -58,
  102753. -59, -60, -61, -62, -63, -64, -65, -66,
  102754. -67, -68, -69, -70, -71, -72, -73, -74,
  102755. -75, -76, -77, -78, -80, -81, -82, -83,
  102756. -84, -85, -86, -87, -88, -88, -89, -89,
  102757. -90, -91, -91, -92, -93, -94, -95, -96,
  102758. -96, -97, -98, -98, -99, -99,-100,-100,
  102759. -101,-102,-103,-104,-106,-107,-107,-107,
  102760. -107,-105,-103,-102,-101, -99, -98, -96,
  102761. -95, -95, -96, -97, -96, -95, -93, -90,
  102762. -80, -70, -50, -40, -30, -30, -30, -30
  102763. };
  102764. #define EHMER_OFFSET 16
  102765. #define EHMER_MAX 56
  102766. static float tonemasks[P_BANDS][6][EHMER_MAX]={
  102767. {{ -60, -60, -60, -60, -60, -60, -60, -60,
  102768. -60, -60, -60, -60, -62, -62, -65, -73,
  102769. -69, -68, -68, -67, -70, -70, -72, -74,
  102770. -75, -79, -79, -80, -83, -88, -93, -100,
  102771. -110, -999, -999, -999, -999, -999, -999, -999,
  102772. -999, -999, -999, -999, -999, -999, -999, -999,
  102773. -999, -999, -999, -999, -999, -999, -999, -999},
  102774. { -48, -48, -48, -48, -48, -48, -48, -48,
  102775. -48, -48, -48, -48, -48, -53, -61, -66,
  102776. -66, -68, -67, -70, -76, -76, -72, -73,
  102777. -75, -76, -78, -79, -83, -88, -93, -100,
  102778. -110, -999, -999, -999, -999, -999, -999, -999,
  102779. -999, -999, -999, -999, -999, -999, -999, -999,
  102780. -999, -999, -999, -999, -999, -999, -999, -999},
  102781. { -37, -37, -37, -37, -37, -37, -37, -37,
  102782. -38, -40, -42, -46, -48, -53, -55, -62,
  102783. -65, -58, -56, -56, -61, -60, -65, -67,
  102784. -69, -71, -77, -77, -78, -80, -82, -84,
  102785. -88, -93, -98, -106, -112, -999, -999, -999,
  102786. -999, -999, -999, -999, -999, -999, -999, -999,
  102787. -999, -999, -999, -999, -999, -999, -999, -999},
  102788. { -25, -25, -25, -25, -25, -25, -25, -25,
  102789. -25, -26, -27, -29, -32, -38, -48, -52,
  102790. -52, -50, -48, -48, -51, -52, -54, -60,
  102791. -67, -67, -66, -68, -69, -73, -73, -76,
  102792. -80, -81, -81, -85, -85, -86, -88, -93,
  102793. -100, -110, -999, -999, -999, -999, -999, -999,
  102794. -999, -999, -999, -999, -999, -999, -999, -999},
  102795. { -16, -16, -16, -16, -16, -16, -16, -16,
  102796. -17, -19, -20, -22, -26, -28, -31, -40,
  102797. -47, -39, -39, -40, -42, -43, -47, -51,
  102798. -57, -52, -55, -55, -60, -58, -62, -63,
  102799. -70, -67, -69, -72, -73, -77, -80, -82,
  102800. -83, -87, -90, -94, -98, -104, -115, -999,
  102801. -999, -999, -999, -999, -999, -999, -999, -999},
  102802. { -8, -8, -8, -8, -8, -8, -8, -8,
  102803. -8, -8, -10, -11, -15, -19, -25, -30,
  102804. -34, -31, -30, -31, -29, -32, -35, -42,
  102805. -48, -42, -44, -46, -50, -50, -51, -52,
  102806. -59, -54, -55, -55, -58, -62, -63, -66,
  102807. -72, -73, -76, -75, -78, -80, -80, -81,
  102808. -84, -88, -90, -94, -98, -101, -106, -110}},
  102809. {{ -66, -66, -66, -66, -66, -66, -66, -66,
  102810. -66, -66, -66, -66, -66, -67, -67, -67,
  102811. -76, -72, -71, -74, -76, -76, -75, -78,
  102812. -79, -79, -81, -83, -86, -89, -93, -97,
  102813. -100, -105, -110, -999, -999, -999, -999, -999,
  102814. -999, -999, -999, -999, -999, -999, -999, -999,
  102815. -999, -999, -999, -999, -999, -999, -999, -999},
  102816. { -47, -47, -47, -47, -47, -47, -47, -47,
  102817. -47, -47, -47, -48, -51, -55, -59, -66,
  102818. -66, -66, -67, -66, -68, -69, -70, -74,
  102819. -79, -77, -77, -78, -80, -81, -82, -84,
  102820. -86, -88, -91, -95, -100, -108, -116, -999,
  102821. -999, -999, -999, -999, -999, -999, -999, -999,
  102822. -999, -999, -999, -999, -999, -999, -999, -999},
  102823. { -36, -36, -36, -36, -36, -36, -36, -36,
  102824. -36, -37, -37, -41, -44, -48, -51, -58,
  102825. -62, -60, -57, -59, -59, -60, -63, -65,
  102826. -72, -71, -70, -72, -74, -77, -76, -78,
  102827. -81, -81, -80, -83, -86, -91, -96, -100,
  102828. -105, -110, -999, -999, -999, -999, -999, -999,
  102829. -999, -999, -999, -999, -999, -999, -999, -999},
  102830. { -28, -28, -28, -28, -28, -28, -28, -28,
  102831. -28, -30, -32, -32, -33, -35, -41, -49,
  102832. -50, -49, -47, -48, -48, -52, -51, -57,
  102833. -65, -61, -59, -61, -64, -69, -70, -74,
  102834. -77, -77, -78, -81, -84, -85, -87, -90,
  102835. -92, -96, -100, -107, -112, -999, -999, -999,
  102836. -999, -999, -999, -999, -999, -999, -999, -999},
  102837. { -19, -19, -19, -19, -19, -19, -19, -19,
  102838. -20, -21, -23, -27, -30, -35, -36, -41,
  102839. -46, -44, -42, -40, -41, -41, -43, -48,
  102840. -55, -53, -52, -53, -56, -59, -58, -60,
  102841. -67, -66, -69, -71, -72, -75, -79, -81,
  102842. -84, -87, -90, -93, -97, -101, -107, -114,
  102843. -999, -999, -999, -999, -999, -999, -999, -999},
  102844. { -9, -9, -9, -9, -9, -9, -9, -9,
  102845. -11, -12, -12, -15, -16, -20, -23, -30,
  102846. -37, -34, -33, -34, -31, -32, -32, -38,
  102847. -47, -44, -41, -40, -47, -49, -46, -46,
  102848. -58, -50, -50, -54, -58, -62, -64, -67,
  102849. -67, -70, -72, -76, -79, -83, -87, -91,
  102850. -96, -100, -104, -110, -999, -999, -999, -999}},
  102851. {{ -62, -62, -62, -62, -62, -62, -62, -62,
  102852. -62, -62, -63, -64, -66, -67, -66, -68,
  102853. -75, -72, -76, -75, -76, -78, -79, -82,
  102854. -84, -85, -90, -94, -101, -110, -999, -999,
  102855. -999, -999, -999, -999, -999, -999, -999, -999,
  102856. -999, -999, -999, -999, -999, -999, -999, -999,
  102857. -999, -999, -999, -999, -999, -999, -999, -999},
  102858. { -59, -59, -59, -59, -59, -59, -59, -59,
  102859. -59, -59, -59, -60, -60, -61, -63, -66,
  102860. -71, -68, -70, -70, -71, -72, -72, -75,
  102861. -81, -78, -79, -82, -83, -86, -90, -97,
  102862. -103, -113, -999, -999, -999, -999, -999, -999,
  102863. -999, -999, -999, -999, -999, -999, -999, -999,
  102864. -999, -999, -999, -999, -999, -999, -999, -999},
  102865. { -53, -53, -53, -53, -53, -53, -53, -53,
  102866. -53, -54, -55, -57, -56, -57, -55, -61,
  102867. -65, -60, -60, -62, -63, -63, -66, -68,
  102868. -74, -73, -75, -75, -78, -80, -80, -82,
  102869. -85, -90, -96, -101, -108, -999, -999, -999,
  102870. -999, -999, -999, -999, -999, -999, -999, -999,
  102871. -999, -999, -999, -999, -999, -999, -999, -999},
  102872. { -46, -46, -46, -46, -46, -46, -46, -46,
  102873. -46, -46, -47, -47, -47, -47, -48, -51,
  102874. -57, -51, -49, -50, -51, -53, -54, -59,
  102875. -66, -60, -62, -67, -67, -70, -72, -75,
  102876. -76, -78, -81, -85, -88, -94, -97, -104,
  102877. -112, -999, -999, -999, -999, -999, -999, -999,
  102878. -999, -999, -999, -999, -999, -999, -999, -999},
  102879. { -36, -36, -36, -36, -36, -36, -36, -36,
  102880. -39, -41, -42, -42, -39, -38, -41, -43,
  102881. -52, -44, -40, -39, -37, -37, -40, -47,
  102882. -54, -50, -48, -50, -55, -61, -59, -62,
  102883. -66, -66, -66, -69, -69, -73, -74, -74,
  102884. -75, -77, -79, -82, -87, -91, -95, -100,
  102885. -108, -115, -999, -999, -999, -999, -999, -999},
  102886. { -28, -26, -24, -22, -20, -20, -23, -29,
  102887. -30, -31, -28, -27, -28, -28, -28, -35,
  102888. -40, -33, -32, -29, -30, -30, -30, -37,
  102889. -45, -41, -37, -38, -45, -47, -47, -48,
  102890. -53, -49, -48, -50, -49, -49, -51, -52,
  102891. -58, -56, -57, -56, -60, -61, -62, -70,
  102892. -72, -74, -78, -83, -88, -93, -100, -106}},
  102893. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102894. -999, -110, -105, -100, -95, -91, -87, -83,
  102895. -80, -78, -76, -78, -78, -81, -83, -85,
  102896. -86, -85, -86, -87, -90, -97, -107, -999,
  102897. -999, -999, -999, -999, -999, -999, -999, -999,
  102898. -999, -999, -999, -999, -999, -999, -999, -999,
  102899. -999, -999, -999, -999, -999, -999, -999, -999},
  102900. {-999, -999, -999, -110, -105, -100, -95, -90,
  102901. -85, -81, -77, -73, -70, -67, -67, -68,
  102902. -75, -73, -70, -69, -70, -72, -75, -79,
  102903. -84, -83, -84, -86, -88, -89, -89, -93,
  102904. -98, -105, -112, -999, -999, -999, -999, -999,
  102905. -999, -999, -999, -999, -999, -999, -999, -999,
  102906. -999, -999, -999, -999, -999, -999, -999, -999},
  102907. {-105, -100, -95, -90, -85, -80, -76, -71,
  102908. -68, -68, -65, -63, -63, -62, -62, -64,
  102909. -65, -64, -61, -62, -63, -64, -66, -68,
  102910. -73, -73, -74, -75, -76, -81, -83, -85,
  102911. -88, -89, -92, -95, -100, -108, -999, -999,
  102912. -999, -999, -999, -999, -999, -999, -999, -999,
  102913. -999, -999, -999, -999, -999, -999, -999, -999},
  102914. { -80, -75, -71, -68, -65, -63, -62, -61,
  102915. -61, -61, -61, -59, -56, -57, -53, -50,
  102916. -58, -52, -50, -50, -52, -53, -54, -58,
  102917. -67, -63, -67, -68, -72, -75, -78, -80,
  102918. -81, -81, -82, -85, -89, -90, -93, -97,
  102919. -101, -107, -114, -999, -999, -999, -999, -999,
  102920. -999, -999, -999, -999, -999, -999, -999, -999},
  102921. { -65, -61, -59, -57, -56, -55, -55, -56,
  102922. -56, -57, -55, -53, -52, -47, -44, -44,
  102923. -50, -44, -41, -39, -39, -42, -40, -46,
  102924. -51, -49, -50, -53, -54, -63, -60, -61,
  102925. -62, -66, -66, -66, -70, -73, -74, -75,
  102926. -76, -75, -79, -85, -89, -91, -96, -102,
  102927. -110, -999, -999, -999, -999, -999, -999, -999},
  102928. { -52, -50, -49, -49, -48, -48, -48, -49,
  102929. -50, -50, -49, -46, -43, -39, -35, -33,
  102930. -38, -36, -32, -29, -32, -32, -32, -35,
  102931. -44, -39, -38, -38, -46, -50, -45, -46,
  102932. -53, -50, -50, -50, -54, -54, -53, -53,
  102933. -56, -57, -59, -66, -70, -72, -74, -79,
  102934. -83, -85, -90, -97, -114, -999, -999, -999}},
  102935. {{-999, -999, -999, -999, -999, -999, -110, -105,
  102936. -100, -95, -90, -86, -80, -75, -75, -79,
  102937. -80, -79, -80, -81, -82, -88, -95, -103,
  102938. -110, -999, -999, -999, -999, -999, -999, -999,
  102939. -999, -999, -999, -999, -999, -999, -999, -999,
  102940. -999, -999, -999, -999, -999, -999, -999, -999,
  102941. -999, -999, -999, -999, -999, -999, -999, -999},
  102942. {-999, -999, -999, -999, -108, -103, -98, -93,
  102943. -88, -83, -79, -78, -75, -71, -67, -68,
  102944. -73, -73, -72, -73, -75, -77, -80, -82,
  102945. -88, -93, -100, -107, -114, -999, -999, -999,
  102946. -999, -999, -999, -999, -999, -999, -999, -999,
  102947. -999, -999, -999, -999, -999, -999, -999, -999,
  102948. -999, -999, -999, -999, -999, -999, -999, -999},
  102949. {-999, -999, -999, -110, -105, -101, -96, -90,
  102950. -86, -81, -77, -73, -69, -66, -61, -62,
  102951. -66, -64, -62, -65, -66, -70, -72, -76,
  102952. -81, -80, -84, -90, -95, -102, -110, -999,
  102953. -999, -999, -999, -999, -999, -999, -999, -999,
  102954. -999, -999, -999, -999, -999, -999, -999, -999,
  102955. -999, -999, -999, -999, -999, -999, -999, -999},
  102956. {-999, -999, -999, -107, -103, -97, -92, -88,
  102957. -83, -79, -74, -70, -66, -59, -53, -58,
  102958. -62, -55, -54, -54, -54, -58, -61, -62,
  102959. -72, -70, -72, -75, -78, -80, -81, -80,
  102960. -83, -83, -88, -93, -100, -107, -115, -999,
  102961. -999, -999, -999, -999, -999, -999, -999, -999,
  102962. -999, -999, -999, -999, -999, -999, -999, -999},
  102963. {-999, -999, -999, -105, -100, -95, -90, -85,
  102964. -80, -75, -70, -66, -62, -56, -48, -44,
  102965. -48, -46, -46, -43, -46, -48, -48, -51,
  102966. -58, -58, -59, -60, -62, -62, -61, -61,
  102967. -65, -64, -65, -68, -70, -74, -75, -78,
  102968. -81, -86, -95, -110, -999, -999, -999, -999,
  102969. -999, -999, -999, -999, -999, -999, -999, -999},
  102970. {-999, -999, -105, -100, -95, -90, -85, -80,
  102971. -75, -70, -65, -61, -55, -49, -39, -33,
  102972. -40, -35, -32, -38, -40, -33, -35, -37,
  102973. -46, -41, -45, -44, -46, -42, -45, -46,
  102974. -52, -50, -50, -50, -54, -54, -55, -57,
  102975. -62, -64, -66, -68, -70, -76, -81, -90,
  102976. -100, -110, -999, -999, -999, -999, -999, -999}},
  102977. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102978. -105, -98, -90, -85, -82, -83, -80, -78,
  102979. -84, -79, -80, -83, -87, -89, -91, -93,
  102980. -99, -106, -117, -999, -999, -999, -999, -999,
  102981. -999, -999, -999, -999, -999, -999, -999, -999,
  102982. -999, -999, -999, -999, -999, -999, -999, -999,
  102983. -999, -999, -999, -999, -999, -999, -999, -999},
  102984. {-999, -999, -999, -999, -999, -999, -999, -999,
  102985. -105, -98, -90, -85, -80, -75, -70, -68,
  102986. -74, -72, -74, -77, -80, -82, -85, -87,
  102987. -92, -89, -91, -95, -100, -106, -112, -999,
  102988. -999, -999, -999, -999, -999, -999, -999, -999,
  102989. -999, -999, -999, -999, -999, -999, -999, -999,
  102990. -999, -999, -999, -999, -999, -999, -999, -999},
  102991. {-999, -999, -999, -999, -999, -999, -999, -999,
  102992. -105, -98, -90, -83, -75, -71, -63, -64,
  102993. -67, -62, -64, -67, -70, -73, -77, -81,
  102994. -84, -83, -85, -89, -90, -93, -98, -104,
  102995. -109, -114, -999, -999, -999, -999, -999, -999,
  102996. -999, -999, -999, -999, -999, -999, -999, -999,
  102997. -999, -999, -999, -999, -999, -999, -999, -999},
  102998. {-999, -999, -999, -999, -999, -999, -999, -999,
  102999. -103, -96, -88, -81, -75, -68, -58, -54,
  103000. -56, -54, -56, -56, -58, -60, -63, -66,
  103001. -74, -69, -72, -72, -75, -74, -77, -81,
  103002. -81, -82, -84, -87, -93, -96, -99, -104,
  103003. -110, -999, -999, -999, -999, -999, -999, -999,
  103004. -999, -999, -999, -999, -999, -999, -999, -999},
  103005. {-999, -999, -999, -999, -999, -108, -102, -96,
  103006. -91, -85, -80, -74, -68, -60, -51, -46,
  103007. -48, -46, -43, -45, -47, -47, -49, -48,
  103008. -56, -53, -55, -58, -57, -63, -58, -60,
  103009. -66, -64, -67, -70, -70, -74, -77, -84,
  103010. -86, -89, -91, -93, -94, -101, -109, -118,
  103011. -999, -999, -999, -999, -999, -999, -999, -999},
  103012. {-999, -999, -999, -108, -103, -98, -93, -88,
  103013. -83, -78, -73, -68, -60, -53, -44, -35,
  103014. -38, -38, -34, -34, -36, -40, -41, -44,
  103015. -51, -45, -46, -47, -46, -54, -50, -49,
  103016. -50, -50, -50, -51, -54, -57, -58, -60,
  103017. -66, -66, -66, -64, -65, -68, -77, -82,
  103018. -87, -95, -110, -999, -999, -999, -999, -999}},
  103019. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103020. -107, -102, -97, -92, -87, -83, -78, -75,
  103021. -82, -79, -83, -85, -89, -92, -95, -98,
  103022. -101, -105, -109, -113, -999, -999, -999, -999,
  103023. -999, -999, -999, -999, -999, -999, -999, -999,
  103024. -999, -999, -999, -999, -999, -999, -999, -999,
  103025. -999, -999, -999, -999, -999, -999, -999, -999},
  103026. {-999, -999, -999, -999, -999, -999, -999, -106,
  103027. -100, -95, -90, -86, -81, -78, -74, -69,
  103028. -74, -74, -76, -79, -83, -84, -86, -89,
  103029. -92, -97, -93, -100, -103, -107, -110, -999,
  103030. -999, -999, -999, -999, -999, -999, -999, -999,
  103031. -999, -999, -999, -999, -999, -999, -999, -999,
  103032. -999, -999, -999, -999, -999, -999, -999, -999},
  103033. {-999, -999, -999, -999, -999, -999, -106, -100,
  103034. -95, -90, -87, -83, -80, -75, -69, -60,
  103035. -66, -66, -68, -70, -74, -78, -79, -81,
  103036. -81, -83, -84, -87, -93, -96, -99, -103,
  103037. -107, -110, -999, -999, -999, -999, -999, -999,
  103038. -999, -999, -999, -999, -999, -999, -999, -999,
  103039. -999, -999, -999, -999, -999, -999, -999, -999},
  103040. {-999, -999, -999, -999, -999, -108, -103, -98,
  103041. -93, -89, -85, -82, -78, -71, -62, -55,
  103042. -58, -58, -54, -54, -55, -59, -61, -62,
  103043. -70, -66, -66, -67, -70, -72, -75, -78,
  103044. -84, -84, -84, -88, -91, -90, -95, -98,
  103045. -102, -103, -106, -110, -999, -999, -999, -999,
  103046. -999, -999, -999, -999, -999, -999, -999, -999},
  103047. {-999, -999, -999, -999, -108, -103, -98, -94,
  103048. -90, -87, -82, -79, -73, -67, -58, -47,
  103049. -50, -45, -41, -45, -48, -44, -44, -49,
  103050. -54, -51, -48, -47, -49, -50, -51, -57,
  103051. -58, -60, -63, -69, -70, -69, -71, -74,
  103052. -78, -82, -90, -95, -101, -105, -110, -999,
  103053. -999, -999, -999, -999, -999, -999, -999, -999},
  103054. {-999, -999, -999, -105, -101, -97, -93, -90,
  103055. -85, -80, -77, -72, -65, -56, -48, -37,
  103056. -40, -36, -34, -40, -50, -47, -38, -41,
  103057. -47, -38, -35, -39, -38, -43, -40, -45,
  103058. -50, -45, -44, -47, -50, -55, -48, -48,
  103059. -52, -66, -70, -76, -82, -90, -97, -105,
  103060. -110, -999, -999, -999, -999, -999, -999, -999}},
  103061. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103062. -999, -108, -103, -98, -93, -86, -79, -76,
  103063. -83, -81, -85, -87, -89, -93, -98, -102,
  103064. -107, -112, -999, -999, -999, -999, -999, -999,
  103065. -999, -999, -999, -999, -999, -999, -999, -999,
  103066. -999, -999, -999, -999, -999, -999, -999, -999,
  103067. -999, -999, -999, -999, -999, -999, -999, -999},
  103068. {-999, -999, -999, -999, -999, -999, -999, -999,
  103069. -999, -108, -103, -98, -93, -86, -79, -71,
  103070. -77, -74, -77, -79, -81, -84, -85, -90,
  103071. -92, -93, -92, -98, -101, -108, -112, -999,
  103072. -999, -999, -999, -999, -999, -999, -999, -999,
  103073. -999, -999, -999, -999, -999, -999, -999, -999,
  103074. -999, -999, -999, -999, -999, -999, -999, -999},
  103075. {-999, -999, -999, -999, -999, -999, -999, -999,
  103076. -108, -103, -98, -93, -87, -78, -68, -65,
  103077. -66, -62, -65, -67, -70, -73, -75, -78,
  103078. -82, -82, -83, -84, -91, -93, -98, -102,
  103079. -106, -110, -999, -999, -999, -999, -999, -999,
  103080. -999, -999, -999, -999, -999, -999, -999, -999,
  103081. -999, -999, -999, -999, -999, -999, -999, -999},
  103082. {-999, -999, -999, -999, -999, -999, -999, -999,
  103083. -105, -100, -95, -90, -82, -74, -62, -57,
  103084. -58, -56, -51, -52, -52, -54, -54, -58,
  103085. -66, -59, -60, -63, -66, -69, -73, -79,
  103086. -83, -84, -80, -81, -81, -82, -88, -92,
  103087. -98, -105, -113, -999, -999, -999, -999, -999,
  103088. -999, -999, -999, -999, -999, -999, -999, -999},
  103089. {-999, -999, -999, -999, -999, -999, -999, -107,
  103090. -102, -97, -92, -84, -79, -69, -57, -47,
  103091. -52, -47, -44, -45, -50, -52, -42, -42,
  103092. -53, -43, -43, -48, -51, -56, -55, -52,
  103093. -57, -59, -61, -62, -67, -71, -78, -83,
  103094. -86, -94, -98, -103, -110, -999, -999, -999,
  103095. -999, -999, -999, -999, -999, -999, -999, -999},
  103096. {-999, -999, -999, -999, -999, -999, -105, -100,
  103097. -95, -90, -84, -78, -70, -61, -51, -41,
  103098. -40, -38, -40, -46, -52, -51, -41, -40,
  103099. -46, -40, -38, -38, -41, -46, -41, -46,
  103100. -47, -43, -43, -45, -41, -45, -56, -67,
  103101. -68, -83, -87, -90, -95, -102, -107, -113,
  103102. -999, -999, -999, -999, -999, -999, -999, -999}},
  103103. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103104. -999, -109, -105, -101, -96, -91, -84, -77,
  103105. -82, -82, -85, -89, -94, -100, -106, -110,
  103106. -999, -999, -999, -999, -999, -999, -999, -999,
  103107. -999, -999, -999, -999, -999, -999, -999, -999,
  103108. -999, -999, -999, -999, -999, -999, -999, -999,
  103109. -999, -999, -999, -999, -999, -999, -999, -999},
  103110. {-999, -999, -999, -999, -999, -999, -999, -999,
  103111. -999, -106, -103, -98, -92, -85, -80, -71,
  103112. -75, -72, -76, -80, -84, -86, -89, -93,
  103113. -100, -107, -113, -999, -999, -999, -999, -999,
  103114. -999, -999, -999, -999, -999, -999, -999, -999,
  103115. -999, -999, -999, -999, -999, -999, -999, -999,
  103116. -999, -999, -999, -999, -999, -999, -999, -999},
  103117. {-999, -999, -999, -999, -999, -999, -999, -107,
  103118. -104, -101, -97, -92, -88, -84, -80, -64,
  103119. -66, -63, -64, -66, -69, -73, -77, -83,
  103120. -83, -86, -91, -98, -104, -111, -999, -999,
  103121. -999, -999, -999, -999, -999, -999, -999, -999,
  103122. -999, -999, -999, -999, -999, -999, -999, -999,
  103123. -999, -999, -999, -999, -999, -999, -999, -999},
  103124. {-999, -999, -999, -999, -999, -999, -999, -107,
  103125. -104, -101, -97, -92, -90, -84, -74, -57,
  103126. -58, -52, -55, -54, -50, -52, -50, -52,
  103127. -63, -62, -69, -76, -77, -78, -78, -79,
  103128. -82, -88, -94, -100, -106, -111, -999, -999,
  103129. -999, -999, -999, -999, -999, -999, -999, -999,
  103130. -999, -999, -999, -999, -999, -999, -999, -999},
  103131. {-999, -999, -999, -999, -999, -999, -106, -102,
  103132. -98, -95, -90, -85, -83, -78, -70, -50,
  103133. -50, -41, -44, -49, -47, -50, -50, -44,
  103134. -55, -46, -47, -48, -48, -54, -49, -49,
  103135. -58, -62, -71, -81, -87, -92, -97, -102,
  103136. -108, -114, -999, -999, -999, -999, -999, -999,
  103137. -999, -999, -999, -999, -999, -999, -999, -999},
  103138. {-999, -999, -999, -999, -999, -999, -106, -102,
  103139. -98, -95, -90, -85, -83, -78, -70, -45,
  103140. -43, -41, -47, -50, -51, -50, -49, -45,
  103141. -47, -41, -44, -41, -39, -43, -38, -37,
  103142. -40, -41, -44, -50, -58, -65, -73, -79,
  103143. -85, -92, -97, -101, -105, -109, -113, -999,
  103144. -999, -999, -999, -999, -999, -999, -999, -999}},
  103145. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103146. -999, -999, -999, -107, -100, -95, -87, -81,
  103147. -85, -83, -88, -93, -100, -107, -114, -999,
  103148. -999, -999, -999, -999, -999, -999, -999, -999,
  103149. -999, -999, -999, -999, -999, -999, -999, -999,
  103150. -999, -999, -999, -999, -999, -999, -999, -999,
  103151. -999, -999, -999, -999, -999, -999, -999, -999},
  103152. {-999, -999, -999, -999, -999, -999, -999, -999,
  103153. -999, -999, -107, -101, -95, -88, -83, -76,
  103154. -73, -72, -79, -84, -90, -95, -100, -105,
  103155. -110, -115, -999, -999, -999, -999, -999, -999,
  103156. -999, -999, -999, -999, -999, -999, -999, -999,
  103157. -999, -999, -999, -999, -999, -999, -999, -999,
  103158. -999, -999, -999, -999, -999, -999, -999, -999},
  103159. {-999, -999, -999, -999, -999, -999, -999, -999,
  103160. -999, -999, -104, -98, -92, -87, -81, -70,
  103161. -65, -62, -67, -71, -74, -80, -85, -91,
  103162. -95, -99, -103, -108, -111, -114, -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, -999, -999, -999, -999, -999, -999,
  103167. -999, -999, -103, -97, -90, -85, -76, -60,
  103168. -56, -54, -60, -62, -61, -56, -63, -65,
  103169. -73, -74, -77, -75, -78, -81, -86, -87,
  103170. -88, -91, -94, -98, -103, -110, -999, -999,
  103171. -999, -999, -999, -999, -999, -999, -999, -999,
  103172. -999, -999, -999, -999, -999, -999, -999, -999},
  103173. {-999, -999, -999, -999, -999, -999, -999, -105,
  103174. -100, -97, -92, -86, -81, -79, -70, -57,
  103175. -51, -47, -51, -58, -60, -56, -53, -50,
  103176. -58, -52, -50, -50, -53, -55, -64, -69,
  103177. -71, -85, -82, -78, -81, -85, -95, -102,
  103178. -112, -999, -999, -999, -999, -999, -999, -999,
  103179. -999, -999, -999, -999, -999, -999, -999, -999},
  103180. {-999, -999, -999, -999, -999, -999, -999, -105,
  103181. -100, -97, -92, -85, -83, -79, -72, -49,
  103182. -40, -43, -43, -54, -56, -51, -50, -40,
  103183. -43, -38, -36, -35, -37, -38, -37, -44,
  103184. -54, -60, -57, -60, -70, -75, -84, -92,
  103185. -103, -112, -999, -999, -999, -999, -999, -999,
  103186. -999, -999, -999, -999, -999, -999, -999, -999}},
  103187. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103188. -999, -999, -999, -110, -102, -95, -89, -82,
  103189. -83, -84, -90, -92, -99, -107, -113, -999,
  103190. -999, -999, -999, -999, -999, -999, -999, -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, -999, -999, -999, -999, -999, -999, -999,
  103195. -999, -999, -107, -101, -95, -89, -83, -72,
  103196. -74, -78, -85, -88, -88, -90, -92, -98,
  103197. -105, -111, -999, -999, -999, -999, -999, -999,
  103198. -999, -999, -999, -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, -999, -999, -999, -999,
  103202. -999, -109, -103, -97, -93, -87, -81, -70,
  103203. -70, -67, -75, -73, -76, -79, -81, -83,
  103204. -88, -89, -97, -103, -110, -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, -999, -999, -999, -999,
  103209. -999, -107, -100, -94, -88, -83, -75, -63,
  103210. -59, -59, -63, -66, -60, -62, -67, -67,
  103211. -77, -76, -81, -88, -86, -92, -96, -102,
  103212. -109, -116, -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, -999, -999, -999, -999,
  103216. -999, -105, -98, -92, -86, -81, -73, -56,
  103217. -52, -47, -55, -60, -58, -52, -51, -45,
  103218. -49, -50, -53, -54, -61, -71, -70, -69,
  103219. -78, -79, -87, -90, -96, -104, -112, -999,
  103220. -999, -999, -999, -999, -999, -999, -999, -999,
  103221. -999, -999, -999, -999, -999, -999, -999, -999},
  103222. {-999, -999, -999, -999, -999, -999, -999, -999,
  103223. -999, -103, -96, -90, -86, -78, -70, -51,
  103224. -42, -47, -48, -55, -54, -54, -53, -42,
  103225. -35, -28, -33, -38, -37, -44, -47, -49,
  103226. -54, -63, -68, -78, -82, -89, -94, -99,
  103227. -104, -109, -114, -999, -999, -999, -999, -999,
  103228. -999, -999, -999, -999, -999, -999, -999, -999}},
  103229. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103230. -999, -999, -999, -999, -110, -100, -90, -79,
  103231. -85, -81, -82, -82, -89, -94, -99, -103,
  103232. -109, -115, -999, -999, -999, -999, -999, -999,
  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, -999, -999, -999, -999, -999, -999,
  103237. -999, -999, -999, -999, -105, -97, -85, -72,
  103238. -74, -70, -70, -70, -76, -85, -91, -93,
  103239. -97, -103, -109, -115, -999, -999, -999, -999,
  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, -999, -999, -999,
  103244. -999, -999, -999, -999, -112, -93, -81, -68,
  103245. -62, -60, -60, -57, -63, -70, -77, -82,
  103246. -90, -93, -98, -104, -109, -113, -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, -999, -999, -999,
  103251. -999, -999, -999, -113, -100, -93, -84, -63,
  103252. -58, -48, -53, -54, -52, -52, -57, -64,
  103253. -66, -76, -83, -81, -85, -85, -90, -95,
  103254. -98, -101, -103, -106, -108, -111, -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, -999, -999, -999, -999,
  103258. -999, -999, -999, -105, -95, -86, -74, -53,
  103259. -50, -38, -43, -49, -43, -42, -39, -39,
  103260. -46, -52, -57, -56, -72, -69, -74, -81,
  103261. -87, -92, -94, -97, -99, -102, -105, -108,
  103262. -999, -999, -999, -999, -999, -999, -999, -999,
  103263. -999, -999, -999, -999, -999, -999, -999, -999},
  103264. {-999, -999, -999, -999, -999, -999, -999, -999,
  103265. -999, -999, -108, -99, -90, -76, -66, -45,
  103266. -43, -41, -44, -47, -43, -47, -40, -30,
  103267. -31, -31, -39, -33, -40, -41, -43, -53,
  103268. -59, -70, -73, -77, -79, -82, -84, -87,
  103269. -999, -999, -999, -999, -999, -999, -999, -999,
  103270. -999, -999, -999, -999, -999, -999, -999, -999}},
  103271. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103272. -999, -999, -999, -999, -999, -110, -91, -76,
  103273. -75, -85, -93, -98, -104, -110, -999, -999,
  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, -999, -999, -999, -999, -999,
  103279. -999, -999, -999, -999, -999, -110, -91, -70,
  103280. -70, -75, -86, -89, -94, -98, -101, -106,
  103281. -110, -999, -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, -999, -999, -999, -999, -999,
  103286. -999, -999, -999, -999, -110, -95, -80, -60,
  103287. -65, -64, -74, -83, -88, -91, -95, -99,
  103288. -103, -107, -110, -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, -999, -999, -999, -999, -999, -999,
  103293. -999, -999, -999, -999, -110, -95, -80, -58,
  103294. -55, -49, -66, -68, -71, -78, -78, -80,
  103295. -88, -85, -89, -97, -100, -105, -110, -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, -999, -999, -999, -999, -999, -999,
  103300. -999, -999, -999, -999, -110, -95, -80, -53,
  103301. -52, -41, -59, -59, -49, -58, -56, -63,
  103302. -86, -79, -90, -93, -98, -103, -107, -112,
  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, -999, -999, -999, -999, -999, -999,
  103307. -999, -999, -999, -110, -97, -91, -73, -45,
  103308. -40, -33, -53, -61, -49, -54, -50, -50,
  103309. -60, -52, -67, -74, -81, -92, -96, -100,
  103310. -105, -110, -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, -999, -999, -999, -999, -999, -999,
  103314. -999, -999, -999, -113, -106, -99, -92, -77,
  103315. -80, -88, -97, -106, -115, -999, -999, -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, -999, -999, -999, -999, -999, -999, -999,
  103321. -999, -999, -116, -109, -102, -95, -89, -74,
  103322. -72, -88, -87, -95, -102, -109, -116, -999,
  103323. -999, -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, -999, -999, -999, -999,
  103328. -999, -999, -116, -109, -102, -95, -89, -75,
  103329. -66, -74, -77, -78, -86, -87, -90, -96,
  103330. -105, -115, -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, -999, -999, -999, -999,
  103335. -999, -999, -115, -108, -101, -94, -88, -66,
  103336. -56, -61, -70, -65, -78, -72, -83, -84,
  103337. -93, -98, -105, -110, -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, -999, -999, -999, -999, -999,
  103342. -999, -999, -110, -105, -95, -89, -82, -57,
  103343. -52, -52, -59, -56, -59, -58, -69, -67,
  103344. -88, -82, -82, -89, -94, -100, -108, -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, -999, -999, -999, -999, -999,
  103349. -999, -110, -101, -96, -90, -83, -77, -54,
  103350. -43, -38, -50, -48, -52, -48, -42, -42,
  103351. -51, -52, -53, -59, -65, -71, -78, -85,
  103352. -95, -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, -999, -999, -999, -999, -999,
  103356. -999, -999, -999, -999, -120, -105, -86, -68,
  103357. -78, -79, -90, -100, -110, -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, -999, -999, -999, -999, -999,
  103363. -999, -999, -999, -999, -120, -105, -86, -66,
  103364. -73, -77, -88, -96, -105, -115, -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, -999, -999, -999,
  103370. -999, -999, -999, -120, -105, -92, -80, -61,
  103371. -64, -68, -80, -87, -92, -100, -110, -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, -999, -999, -999,
  103377. -999, -999, -999, -120, -104, -91, -79, -52,
  103378. -60, -54, -64, -69, -77, -80, -82, -84,
  103379. -85, -87, -88, -90, -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, -999, -999, -999,
  103384. -999, -999, -999, -118, -100, -87, -77, -49,
  103385. -50, -44, -58, -61, -61, -67, -65, -62,
  103386. -62, -62, -65, -68, -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, -999, -999, -999,
  103391. -999, -999, -999, -115, -98, -84, -62, -49,
  103392. -44, -38, -46, -49, -49, -46, -39, -37,
  103393. -39, -40, -42, -43, -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, -999, -999, -999, -999,
  103398. -999, -999, -999, -999, -999, -110, -88, -74,
  103399. -77, -82, -82, -85, -90, -94, -99, -104,
  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, -999, -999, -999, -999,
  103405. -999, -999, -999, -999, -999, -110, -88, -66,
  103406. -70, -81, -80, -81, -84, -88, -91, -93,
  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, -999, -999, -999, -999, -999,
  103412. -999, -999, -999, -999, -999, -110, -88, -61,
  103413. -63, -70, -71, -74, -77, -80, -83, -85,
  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, -999, -999, -999, -999, -999,
  103419. -999, -999, -999, -999, -999, -110, -86, -62,
  103420. -63, -62, -62, -58, -52, -50, -50, -52,
  103421. -54, -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, -999, -999, -999, -999, -999,
  103426. -999, -999, -999, -999, -118, -108, -84, -53,
  103427. -50, -50, -50, -55, -47, -45, -40, -40,
  103428. -40, -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, -999, -999, -999, -999, -999,
  103433. -999, -999, -999, -999, -118, -100, -73, -43,
  103434. -37, -42, -43, -53, -38, -37, -35, -35,
  103435. -38, -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, -999, -999, -999, -999, -999,
  103440. -999, -999, -999, -110, -100, -91, -84, -74,
  103441. -80, -80, -80, -80, -80, -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, -999, -999, -999, -999, -999,
  103447. -999, -999, -999, -110, -100, -91, -84, -74,
  103448. -68, -68, -68, -68, -68, -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. -999, -999, -999, -999, -999, -999, -999, -999},
  103453. {-999, -999, -999, -999, -999, -999, -999, -999,
  103454. -999, -999, -999, -110, -100, -86, -78, -70,
  103455. -60, -45, -30, -21, -999, -999, -999, -999,
  103456. -999, -999, -999, -999, -999, -999, -999, -999,
  103457. -999, -999, -999, -999, -999, -999, -999, -999,
  103458. -999, -999, -999, -999, -999, -999, -999, -999,
  103459. -999, -999, -999, -999, -999, -999, -999, -999},
  103460. {-999, -999, -999, -999, -999, -999, -999, -999,
  103461. -999, -999, -999, -110, -100, -87, -78, -67,
  103462. -48, -38, -29, -21, -999, -999, -999, -999,
  103463. -999, -999, -999, -999, -999, -999, -999, -999,
  103464. -999, -999, -999, -999, -999, -999, -999, -999,
  103465. -999, -999, -999, -999, -999, -999, -999, -999,
  103466. -999, -999, -999, -999, -999, -999, -999, -999},
  103467. {-999, -999, -999, -999, -999, -999, -999, -999,
  103468. -999, -999, -999, -110, -100, -86, -69, -56,
  103469. -45, -35, -33, -29, -999, -999, -999, -999,
  103470. -999, -999, -999, -999, -999, -999, -999, -999,
  103471. -999, -999, -999, -999, -999, -999, -999, -999,
  103472. -999, -999, -999, -999, -999, -999, -999, -999,
  103473. -999, -999, -999, -999, -999, -999, -999, -999},
  103474. {-999, -999, -999, -999, -999, -999, -999, -999,
  103475. -999, -999, -999, -110, -100, -83, -71, -48,
  103476. -27, -38, -37, -34, -999, -999, -999, -999,
  103477. -999, -999, -999, -999, -999, -999, -999, -999,
  103478. -999, -999, -999, -999, -999, -999, -999, -999,
  103479. -999, -999, -999, -999, -999, -999, -999, -999,
  103480. -999, -999, -999, -999, -999, -999, -999, -999}}
  103481. };
  103482. #endif
  103483. /*** End of inlined file: masking.h ***/
  103484. #define NEGINF -9999.f
  103485. static double stereo_threshholds[]={0.0, .5, 1.0, 1.5, 2.5, 4.5, 8.5, 16.5, 9e10};
  103486. static double stereo_threshholds_limited[]={0.0, .5, 1.0, 1.5, 2.0, 2.5, 4.5, 8.5, 9e10};
  103487. vorbis_look_psy_global *_vp_global_look(vorbis_info *vi){
  103488. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  103489. vorbis_info_psy_global *gi=&ci->psy_g_param;
  103490. vorbis_look_psy_global *look=(vorbis_look_psy_global*)_ogg_calloc(1,sizeof(*look));
  103491. look->channels=vi->channels;
  103492. look->ampmax=-9999.;
  103493. look->gi=gi;
  103494. return(look);
  103495. }
  103496. void _vp_global_free(vorbis_look_psy_global *look){
  103497. if(look){
  103498. memset(look,0,sizeof(*look));
  103499. _ogg_free(look);
  103500. }
  103501. }
  103502. void _vi_gpsy_free(vorbis_info_psy_global *i){
  103503. if(i){
  103504. memset(i,0,sizeof(*i));
  103505. _ogg_free(i);
  103506. }
  103507. }
  103508. void _vi_psy_free(vorbis_info_psy *i){
  103509. if(i){
  103510. memset(i,0,sizeof(*i));
  103511. _ogg_free(i);
  103512. }
  103513. }
  103514. static void min_curve(float *c,
  103515. float *c2){
  103516. int i;
  103517. for(i=0;i<EHMER_MAX;i++)if(c2[i]<c[i])c[i]=c2[i];
  103518. }
  103519. static void max_curve(float *c,
  103520. float *c2){
  103521. int i;
  103522. for(i=0;i<EHMER_MAX;i++)if(c2[i]>c[i])c[i]=c2[i];
  103523. }
  103524. static void attenuate_curve(float *c,float att){
  103525. int i;
  103526. for(i=0;i<EHMER_MAX;i++)
  103527. c[i]+=att;
  103528. }
  103529. static float ***setup_tone_curves(float curveatt_dB[P_BANDS],float binHz,int n,
  103530. float center_boost, float center_decay_rate){
  103531. int i,j,k,m;
  103532. float ath[EHMER_MAX];
  103533. float workc[P_BANDS][P_LEVELS][EHMER_MAX];
  103534. float athc[P_LEVELS][EHMER_MAX];
  103535. float *brute_buffer=(float*) alloca(n*sizeof(*brute_buffer));
  103536. float ***ret=(float***) _ogg_malloc(sizeof(*ret)*P_BANDS);
  103537. memset(workc,0,sizeof(workc));
  103538. for(i=0;i<P_BANDS;i++){
  103539. int ath_offset=i*4;
  103540. for(j=0;j<EHMER_MAX;j++){
  103541. float min=999.;
  103542. for(k=0;k<4;k++)
  103543. if(j+k+ath_offset<MAX_ATH){
  103544. if(min>ATH[j+k+ath_offset])min=ATH[j+k+ath_offset];
  103545. }else{
  103546. if(min>ATH[MAX_ATH-1])min=ATH[MAX_ATH-1];
  103547. }
  103548. ath[j]=min;
  103549. }
  103550. for(j=0;j<6;j++)
  103551. memcpy(workc[i][j+2],tonemasks[i][j],EHMER_MAX*sizeof(*tonemasks[i][j]));
  103552. memcpy(workc[i][0],tonemasks[i][0],EHMER_MAX*sizeof(*tonemasks[i][0]));
  103553. memcpy(workc[i][1],tonemasks[i][0],EHMER_MAX*sizeof(*tonemasks[i][0]));
  103554. for(j=0;j<P_LEVELS;j++){
  103555. for(k=0;k<EHMER_MAX;k++){
  103556. float adj=center_boost+abs(EHMER_OFFSET-k)*center_decay_rate;
  103557. if(adj<0. && center_boost>0)adj=0.;
  103558. if(adj>0. && center_boost<0)adj=0.;
  103559. workc[i][j][k]+=adj;
  103560. }
  103561. }
  103562. for(j=0;j<P_LEVELS;j++){
  103563. attenuate_curve(workc[i][j],curveatt_dB[i]+100.-(j<2?2:j)*10.-P_LEVEL_0);
  103564. memcpy(athc[j],ath,EHMER_MAX*sizeof(**athc));
  103565. attenuate_curve(athc[j],+100.-j*10.f-P_LEVEL_0);
  103566. max_curve(athc[j],workc[i][j]);
  103567. }
  103568. for(j=1;j<P_LEVELS;j++){
  103569. min_curve(athc[j],athc[j-1]);
  103570. min_curve(workc[i][j],athc[j]);
  103571. }
  103572. }
  103573. for(i=0;i<P_BANDS;i++){
  103574. int hi_curve,lo_curve,bin;
  103575. ret[i]=(float**)_ogg_malloc(sizeof(**ret)*P_LEVELS);
  103576. bin=floor(fromOC(i*.5)/binHz);
  103577. lo_curve= ceil(toOC(bin*binHz+1)*2);
  103578. hi_curve= floor(toOC((bin+1)*binHz)*2);
  103579. if(lo_curve>i)lo_curve=i;
  103580. if(lo_curve<0)lo_curve=0;
  103581. if(hi_curve>=P_BANDS)hi_curve=P_BANDS-1;
  103582. for(m=0;m<P_LEVELS;m++){
  103583. ret[i][m]=(float*)_ogg_malloc(sizeof(***ret)*(EHMER_MAX+2));
  103584. for(j=0;j<n;j++)brute_buffer[j]=999.;
  103585. for(k=lo_curve;k<=hi_curve;k++){
  103586. int l=0;
  103587. for(j=0;j<EHMER_MAX;j++){
  103588. int lo_bin= fromOC(j*.125+k*.5-2.0625)/binHz;
  103589. int hi_bin= fromOC(j*.125+k*.5-1.9375)/binHz+1;
  103590. if(lo_bin<0)lo_bin=0;
  103591. if(lo_bin>n)lo_bin=n;
  103592. if(lo_bin<l)l=lo_bin;
  103593. if(hi_bin<0)hi_bin=0;
  103594. if(hi_bin>n)hi_bin=n;
  103595. for(;l<hi_bin && l<n;l++)
  103596. if(brute_buffer[l]>workc[k][m][j])
  103597. brute_buffer[l]=workc[k][m][j];
  103598. }
  103599. for(;l<n;l++)
  103600. if(brute_buffer[l]>workc[k][m][EHMER_MAX-1])
  103601. brute_buffer[l]=workc[k][m][EHMER_MAX-1];
  103602. }
  103603. if(i+1<P_BANDS){
  103604. int l=0;
  103605. k=i+1;
  103606. for(j=0;j<EHMER_MAX;j++){
  103607. int lo_bin= fromOC(j*.125+i*.5-2.0625)/binHz;
  103608. int hi_bin= fromOC(j*.125+i*.5-1.9375)/binHz+1;
  103609. if(lo_bin<0)lo_bin=0;
  103610. if(lo_bin>n)lo_bin=n;
  103611. if(lo_bin<l)l=lo_bin;
  103612. if(hi_bin<0)hi_bin=0;
  103613. if(hi_bin>n)hi_bin=n;
  103614. for(;l<hi_bin && l<n;l++)
  103615. if(brute_buffer[l]>workc[k][m][j])
  103616. brute_buffer[l]=workc[k][m][j];
  103617. }
  103618. for(;l<n;l++)
  103619. if(brute_buffer[l]>workc[k][m][EHMER_MAX-1])
  103620. brute_buffer[l]=workc[k][m][EHMER_MAX-1];
  103621. }
  103622. for(j=0;j<EHMER_MAX;j++){
  103623. int bin=fromOC(j*.125+i*.5-2.)/binHz;
  103624. if(bin<0){
  103625. ret[i][m][j+2]=-999.;
  103626. }else{
  103627. if(bin>=n){
  103628. ret[i][m][j+2]=-999.;
  103629. }else{
  103630. ret[i][m][j+2]=brute_buffer[bin];
  103631. }
  103632. }
  103633. }
  103634. for(j=0;j<EHMER_OFFSET;j++)
  103635. if(ret[i][m][j+2]>-200.f)break;
  103636. ret[i][m][0]=j;
  103637. for(j=EHMER_MAX-1;j>EHMER_OFFSET+1;j--)
  103638. if(ret[i][m][j+2]>-200.f)
  103639. break;
  103640. ret[i][m][1]=j;
  103641. }
  103642. }
  103643. return(ret);
  103644. }
  103645. void _vp_psy_init(vorbis_look_psy *p,vorbis_info_psy *vi,
  103646. vorbis_info_psy_global *gi,int n,long rate){
  103647. long i,j,lo=-99,hi=1;
  103648. long maxoc;
  103649. memset(p,0,sizeof(*p));
  103650. p->eighth_octave_lines=gi->eighth_octave_lines;
  103651. p->shiftoc=rint(log(gi->eighth_octave_lines*8.f)/log(2.f))-1;
  103652. p->firstoc=toOC(.25f*rate*.5/n)*(1<<(p->shiftoc+1))-gi->eighth_octave_lines;
  103653. maxoc=toOC((n+.25f)*rate*.5/n)*(1<<(p->shiftoc+1))+.5f;
  103654. p->total_octave_lines=maxoc-p->firstoc+1;
  103655. p->ath=(float*)_ogg_malloc(n*sizeof(*p->ath));
  103656. p->octave=(long*)_ogg_malloc(n*sizeof(*p->octave));
  103657. p->bark=(long*)_ogg_malloc(n*sizeof(*p->bark));
  103658. p->vi=vi;
  103659. p->n=n;
  103660. p->rate=rate;
  103661. p->m_val = 1.;
  103662. if(rate < 26000) p->m_val = 0;
  103663. else if(rate < 38000) p->m_val = .94; /* 32kHz */
  103664. else if(rate > 46000) p->m_val = 1.275; /* 48kHz */
  103665. for(i=0,j=0;i<MAX_ATH-1;i++){
  103666. int endpos=rint(fromOC((i+1)*.125-2.)*2*n/rate);
  103667. float base=ATH[i];
  103668. if(j<endpos){
  103669. float delta=(ATH[i+1]-base)/(endpos-j);
  103670. for(;j<endpos && j<n;j++){
  103671. p->ath[j]=base+100.;
  103672. base+=delta;
  103673. }
  103674. }
  103675. }
  103676. for(i=0;i<n;i++){
  103677. float bark=toBARK(rate/(2*n)*i);
  103678. for(;lo+vi->noisewindowlomin<i &&
  103679. toBARK(rate/(2*n)*lo)<(bark-vi->noisewindowlo);lo++);
  103680. for(;hi<=n && (hi<i+vi->noisewindowhimin ||
  103681. toBARK(rate/(2*n)*hi)<(bark+vi->noisewindowhi));hi++);
  103682. p->bark[i]=((lo-1)<<16)+(hi-1);
  103683. }
  103684. for(i=0;i<n;i++)
  103685. p->octave[i]=toOC((i+.25f)*.5*rate/n)*(1<<(p->shiftoc+1))+.5f;
  103686. p->tonecurves=setup_tone_curves(vi->toneatt,rate*.5/n,n,
  103687. vi->tone_centerboost,vi->tone_decay);
  103688. p->noiseoffset=(float**)_ogg_malloc(P_NOISECURVES*sizeof(*p->noiseoffset));
  103689. for(i=0;i<P_NOISECURVES;i++)
  103690. p->noiseoffset[i]=(float*)_ogg_malloc(n*sizeof(**p->noiseoffset));
  103691. for(i=0;i<n;i++){
  103692. float halfoc=toOC((i+.5)*rate/(2.*n))*2.;
  103693. int inthalfoc;
  103694. float del;
  103695. if(halfoc<0)halfoc=0;
  103696. if(halfoc>=P_BANDS-1)halfoc=P_BANDS-1;
  103697. inthalfoc=(int)halfoc;
  103698. del=halfoc-inthalfoc;
  103699. for(j=0;j<P_NOISECURVES;j++)
  103700. p->noiseoffset[j][i]=
  103701. p->vi->noiseoff[j][inthalfoc]*(1.-del) +
  103702. p->vi->noiseoff[j][inthalfoc+1]*del;
  103703. }
  103704. #if 0
  103705. {
  103706. static int ls=0;
  103707. _analysis_output_always("noiseoff0",ls,p->noiseoffset[0],n,1,0,0);
  103708. _analysis_output_always("noiseoff1",ls,p->noiseoffset[1],n,1,0,0);
  103709. _analysis_output_always("noiseoff2",ls++,p->noiseoffset[2],n,1,0,0);
  103710. }
  103711. #endif
  103712. }
  103713. void _vp_psy_clear(vorbis_look_psy *p){
  103714. int i,j;
  103715. if(p){
  103716. if(p->ath)_ogg_free(p->ath);
  103717. if(p->octave)_ogg_free(p->octave);
  103718. if(p->bark)_ogg_free(p->bark);
  103719. if(p->tonecurves){
  103720. for(i=0;i<P_BANDS;i++){
  103721. for(j=0;j<P_LEVELS;j++){
  103722. _ogg_free(p->tonecurves[i][j]);
  103723. }
  103724. _ogg_free(p->tonecurves[i]);
  103725. }
  103726. _ogg_free(p->tonecurves);
  103727. }
  103728. if(p->noiseoffset){
  103729. for(i=0;i<P_NOISECURVES;i++){
  103730. _ogg_free(p->noiseoffset[i]);
  103731. }
  103732. _ogg_free(p->noiseoffset);
  103733. }
  103734. memset(p,0,sizeof(*p));
  103735. }
  103736. }
  103737. static void seed_curve(float *seed,
  103738. const float **curves,
  103739. float amp,
  103740. int oc, int n,
  103741. int linesper,float dBoffset){
  103742. int i,post1;
  103743. int seedptr;
  103744. const float *posts,*curve;
  103745. int choice=(int)((amp+dBoffset-P_LEVEL_0)*.1f);
  103746. choice=max(choice,0);
  103747. choice=min(choice,P_LEVELS-1);
  103748. posts=curves[choice];
  103749. curve=posts+2;
  103750. post1=(int)posts[1];
  103751. seedptr=oc+(posts[0]-EHMER_OFFSET)*linesper-(linesper>>1);
  103752. for(i=posts[0];i<post1;i++){
  103753. if(seedptr>0){
  103754. float lin=amp+curve[i];
  103755. if(seed[seedptr]<lin)seed[seedptr]=lin;
  103756. }
  103757. seedptr+=linesper;
  103758. if(seedptr>=n)break;
  103759. }
  103760. }
  103761. static void seed_loop(vorbis_look_psy *p,
  103762. const float ***curves,
  103763. const float *f,
  103764. const float *flr,
  103765. float *seed,
  103766. float specmax){
  103767. vorbis_info_psy *vi=p->vi;
  103768. long n=p->n,i;
  103769. float dBoffset=vi->max_curve_dB-specmax;
  103770. for(i=0;i<n;i++){
  103771. float max=f[i];
  103772. long oc=p->octave[i];
  103773. while(i+1<n && p->octave[i+1]==oc){
  103774. i++;
  103775. if(f[i]>max)max=f[i];
  103776. }
  103777. if(max+6.f>flr[i]){
  103778. oc=oc>>p->shiftoc;
  103779. if(oc>=P_BANDS)oc=P_BANDS-1;
  103780. if(oc<0)oc=0;
  103781. seed_curve(seed,
  103782. curves[oc],
  103783. max,
  103784. p->octave[i]-p->firstoc,
  103785. p->total_octave_lines,
  103786. p->eighth_octave_lines,
  103787. dBoffset);
  103788. }
  103789. }
  103790. }
  103791. static void seed_chase(float *seeds, int linesper, long n){
  103792. long *posstack=(long*)alloca(n*sizeof(*posstack));
  103793. float *ampstack=(float*)alloca(n*sizeof(*ampstack));
  103794. long stack=0;
  103795. long pos=0;
  103796. long i;
  103797. for(i=0;i<n;i++){
  103798. if(stack<2){
  103799. posstack[stack]=i;
  103800. ampstack[stack++]=seeds[i];
  103801. }else{
  103802. while(1){
  103803. if(seeds[i]<ampstack[stack-1]){
  103804. posstack[stack]=i;
  103805. ampstack[stack++]=seeds[i];
  103806. break;
  103807. }else{
  103808. if(i<posstack[stack-1]+linesper){
  103809. if(stack>1 && ampstack[stack-1]<=ampstack[stack-2] &&
  103810. i<posstack[stack-2]+linesper){
  103811. stack--;
  103812. continue;
  103813. }
  103814. }
  103815. posstack[stack]=i;
  103816. ampstack[stack++]=seeds[i];
  103817. break;
  103818. }
  103819. }
  103820. }
  103821. }
  103822. for(i=0;i<stack;i++){
  103823. long endpos;
  103824. if(i<stack-1 && ampstack[i+1]>ampstack[i]){
  103825. endpos=posstack[i+1];
  103826. }else{
  103827. endpos=posstack[i]+linesper+1; /* +1 is important, else bin 0 is
  103828. discarded in short frames */
  103829. }
  103830. if(endpos>n)endpos=n;
  103831. for(;pos<endpos;pos++)
  103832. seeds[pos]=ampstack[i];
  103833. }
  103834. }
  103835. #include<stdio.h>
  103836. static void max_seeds(vorbis_look_psy *p,
  103837. float *seed,
  103838. float *flr){
  103839. long n=p->total_octave_lines;
  103840. int linesper=p->eighth_octave_lines;
  103841. long linpos=0;
  103842. long pos;
  103843. seed_chase(seed,linesper,n); /* for masking */
  103844. pos=p->octave[0]-p->firstoc-(linesper>>1);
  103845. while(linpos+1<p->n){
  103846. float minV=seed[pos];
  103847. long end=((p->octave[linpos]+p->octave[linpos+1])>>1)-p->firstoc;
  103848. if(minV>p->vi->tone_abs_limit)minV=p->vi->tone_abs_limit;
  103849. while(pos+1<=end){
  103850. pos++;
  103851. if((seed[pos]>NEGINF && seed[pos]<minV) || minV==NEGINF)
  103852. minV=seed[pos];
  103853. }
  103854. end=pos+p->firstoc;
  103855. for(;linpos<p->n && p->octave[linpos]<=end;linpos++)
  103856. if(flr[linpos]<minV)flr[linpos]=minV;
  103857. }
  103858. {
  103859. float minV=seed[p->total_octave_lines-1];
  103860. for(;linpos<p->n;linpos++)
  103861. if(flr[linpos]<minV)flr[linpos]=minV;
  103862. }
  103863. }
  103864. static void bark_noise_hybridmp(int n,const long *b,
  103865. const float *f,
  103866. float *noise,
  103867. const float offset,
  103868. const int fixed){
  103869. float *N=(float*) alloca(n*sizeof(*N));
  103870. float *X=(float*) alloca(n*sizeof(*N));
  103871. float *XX=(float*) alloca(n*sizeof(*N));
  103872. float *Y=(float*) alloca(n*sizeof(*N));
  103873. float *XY=(float*) alloca(n*sizeof(*N));
  103874. float tN, tX, tXX, tY, tXY;
  103875. int i;
  103876. int lo, hi;
  103877. float R, A, B, D;
  103878. float w, x, y;
  103879. tN = tX = tXX = tY = tXY = 0.f;
  103880. y = f[0] + offset;
  103881. if (y < 1.f) y = 1.f;
  103882. w = y * y * .5;
  103883. tN += w;
  103884. tX += w;
  103885. tY += w * y;
  103886. N[0] = tN;
  103887. X[0] = tX;
  103888. XX[0] = tXX;
  103889. Y[0] = tY;
  103890. XY[0] = tXY;
  103891. for (i = 1, x = 1.f; i < n; i++, x += 1.f) {
  103892. y = f[i] + offset;
  103893. if (y < 1.f) y = 1.f;
  103894. w = y * y;
  103895. tN += w;
  103896. tX += w * x;
  103897. tXX += w * x * x;
  103898. tY += w * y;
  103899. tXY += w * x * y;
  103900. N[i] = tN;
  103901. X[i] = tX;
  103902. XX[i] = tXX;
  103903. Y[i] = tY;
  103904. XY[i] = tXY;
  103905. }
  103906. for (i = 0, x = 0.f;; i++, x += 1.f) {
  103907. lo = b[i] >> 16;
  103908. if( lo>=0 ) break;
  103909. hi = b[i] & 0xffff;
  103910. tN = N[hi] + N[-lo];
  103911. tX = X[hi] - X[-lo];
  103912. tXX = XX[hi] + XX[-lo];
  103913. tY = Y[hi] + Y[-lo];
  103914. tXY = XY[hi] - XY[-lo];
  103915. A = tY * tXX - tX * tXY;
  103916. B = tN * tXY - tX * tY;
  103917. D = tN * tXX - tX * tX;
  103918. R = (A + x * B) / D;
  103919. if (R < 0.f)
  103920. R = 0.f;
  103921. noise[i] = R - offset;
  103922. }
  103923. for ( ;; i++, x += 1.f) {
  103924. lo = b[i] >> 16;
  103925. hi = b[i] & 0xffff;
  103926. if(hi>=n)break;
  103927. tN = N[hi] - N[lo];
  103928. tX = X[hi] - X[lo];
  103929. tXX = XX[hi] - XX[lo];
  103930. tY = Y[hi] - Y[lo];
  103931. tXY = XY[hi] - XY[lo];
  103932. A = tY * tXX - tX * tXY;
  103933. B = tN * tXY - tX * tY;
  103934. D = tN * tXX - tX * tX;
  103935. R = (A + x * B) / D;
  103936. if (R < 0.f) R = 0.f;
  103937. noise[i] = R - offset;
  103938. }
  103939. for ( ; i < n; i++, x += 1.f) {
  103940. R = (A + x * B) / D;
  103941. if (R < 0.f) R = 0.f;
  103942. noise[i] = R - offset;
  103943. }
  103944. if (fixed <= 0) return;
  103945. for (i = 0, x = 0.f;; i++, x += 1.f) {
  103946. hi = i + fixed / 2;
  103947. lo = hi - fixed;
  103948. if(lo>=0)break;
  103949. tN = N[hi] + N[-lo];
  103950. tX = X[hi] - X[-lo];
  103951. tXX = XX[hi] + XX[-lo];
  103952. tY = Y[hi] + Y[-lo];
  103953. tXY = XY[hi] - XY[-lo];
  103954. A = tY * tXX - tX * tXY;
  103955. B = tN * tXY - tX * tY;
  103956. D = tN * tXX - tX * tX;
  103957. R = (A + x * B) / D;
  103958. if (R - offset < noise[i]) noise[i] = R - offset;
  103959. }
  103960. for ( ;; i++, x += 1.f) {
  103961. hi = i + fixed / 2;
  103962. lo = hi - fixed;
  103963. if(hi>=n)break;
  103964. tN = N[hi] - N[lo];
  103965. tX = X[hi] - X[lo];
  103966. tXX = XX[hi] - XX[lo];
  103967. tY = Y[hi] - Y[lo];
  103968. tXY = XY[hi] - XY[lo];
  103969. A = tY * tXX - tX * tXY;
  103970. B = tN * tXY - tX * tY;
  103971. D = tN * tXX - tX * tX;
  103972. R = (A + x * B) / D;
  103973. if (R - offset < noise[i]) noise[i] = R - offset;
  103974. }
  103975. for ( ; i < n; i++, x += 1.f) {
  103976. R = (A + x * B) / D;
  103977. if (R - offset < noise[i]) noise[i] = R - offset;
  103978. }
  103979. }
  103980. static float FLOOR1_fromdB_INV_LOOKUP[256]={
  103981. 0.F, 8.81683e+06F, 8.27882e+06F, 7.77365e+06F,
  103982. 7.29930e+06F, 6.85389e+06F, 6.43567e+06F, 6.04296e+06F,
  103983. 5.67422e+06F, 5.32798e+06F, 5.00286e+06F, 4.69759e+06F,
  103984. 4.41094e+06F, 4.14178e+06F, 3.88905e+06F, 3.65174e+06F,
  103985. 3.42891e+06F, 3.21968e+06F, 3.02321e+06F, 2.83873e+06F,
  103986. 2.66551e+06F, 2.50286e+06F, 2.35014e+06F, 2.20673e+06F,
  103987. 2.07208e+06F, 1.94564e+06F, 1.82692e+06F, 1.71544e+06F,
  103988. 1.61076e+06F, 1.51247e+06F, 1.42018e+06F, 1.33352e+06F,
  103989. 1.25215e+06F, 1.17574e+06F, 1.10400e+06F, 1.03663e+06F,
  103990. 973377.F, 913981.F, 858210.F, 805842.F,
  103991. 756669.F, 710497.F, 667142.F, 626433.F,
  103992. 588208.F, 552316.F, 518613.F, 486967.F,
  103993. 457252.F, 429351.F, 403152.F, 378551.F,
  103994. 355452.F, 333762.F, 313396.F, 294273.F,
  103995. 276316.F, 259455.F, 243623.F, 228757.F,
  103996. 214798.F, 201691.F, 189384.F, 177828.F,
  103997. 166977.F, 156788.F, 147221.F, 138237.F,
  103998. 129802.F, 121881.F, 114444.F, 107461.F,
  103999. 100903.F, 94746.3F, 88964.9F, 83536.2F,
  104000. 78438.8F, 73652.5F, 69158.2F, 64938.1F,
  104001. 60975.6F, 57254.9F, 53761.2F, 50480.6F,
  104002. 47400.3F, 44507.9F, 41792.0F, 39241.9F,
  104003. 36847.3F, 34598.9F, 32487.7F, 30505.3F,
  104004. 28643.8F, 26896.0F, 25254.8F, 23713.7F,
  104005. 22266.7F, 20908.0F, 19632.2F, 18434.2F,
  104006. 17309.4F, 16253.1F, 15261.4F, 14330.1F,
  104007. 13455.7F, 12634.6F, 11863.7F, 11139.7F,
  104008. 10460.0F, 9821.72F, 9222.39F, 8659.64F,
  104009. 8131.23F, 7635.06F, 7169.17F, 6731.70F,
  104010. 6320.93F, 5935.23F, 5573.06F, 5232.99F,
  104011. 4913.67F, 4613.84F, 4332.30F, 4067.94F,
  104012. 3819.72F, 3586.64F, 3367.78F, 3162.28F,
  104013. 2969.31F, 2788.13F, 2617.99F, 2458.24F,
  104014. 2308.24F, 2167.39F, 2035.14F, 1910.95F,
  104015. 1794.35F, 1684.85F, 1582.04F, 1485.51F,
  104016. 1394.86F, 1309.75F, 1229.83F, 1154.78F,
  104017. 1084.32F, 1018.15F, 956.024F, 897.687F,
  104018. 842.910F, 791.475F, 743.179F, 697.830F,
  104019. 655.249F, 615.265F, 577.722F, 542.469F,
  104020. 509.367F, 478.286F, 449.101F, 421.696F,
  104021. 395.964F, 371.803F, 349.115F, 327.812F,
  104022. 307.809F, 289.026F, 271.390F, 254.830F,
  104023. 239.280F, 224.679F, 210.969F, 198.096F,
  104024. 186.008F, 174.658F, 164.000F, 153.993F,
  104025. 144.596F, 135.773F, 127.488F, 119.708F,
  104026. 112.404F, 105.545F, 99.1046F, 93.0572F,
  104027. 87.3788F, 82.0469F, 77.0404F, 72.3394F,
  104028. 67.9252F, 63.7804F, 59.8885F, 56.2341F,
  104029. 52.8027F, 49.5807F, 46.5553F, 43.7144F,
  104030. 41.0470F, 38.5423F, 36.1904F, 33.9821F,
  104031. 31.9085F, 29.9614F, 28.1332F, 26.4165F,
  104032. 24.8045F, 23.2910F, 21.8697F, 20.5352F,
  104033. 19.2822F, 18.1056F, 17.0008F, 15.9634F,
  104034. 14.9893F, 14.0746F, 13.2158F, 12.4094F,
  104035. 11.6522F, 10.9411F, 10.2735F, 9.64662F,
  104036. 9.05798F, 8.50526F, 7.98626F, 7.49894F,
  104037. 7.04135F, 6.61169F, 6.20824F, 5.82941F,
  104038. 5.47370F, 5.13970F, 4.82607F, 4.53158F,
  104039. 4.25507F, 3.99542F, 3.75162F, 3.52269F,
  104040. 3.30774F, 3.10590F, 2.91638F, 2.73842F,
  104041. 2.57132F, 2.41442F, 2.26709F, 2.12875F,
  104042. 1.99885F, 1.87688F, 1.76236F, 1.65482F,
  104043. 1.55384F, 1.45902F, 1.36999F, 1.28640F,
  104044. 1.20790F, 1.13419F, 1.06499F, 1.F
  104045. };
  104046. void _vp_remove_floor(vorbis_look_psy *p,
  104047. float *mdct,
  104048. int *codedflr,
  104049. float *residue,
  104050. int sliding_lowpass){
  104051. int i,n=p->n;
  104052. if(sliding_lowpass>n)sliding_lowpass=n;
  104053. for(i=0;i<sliding_lowpass;i++){
  104054. residue[i]=
  104055. mdct[i]*FLOOR1_fromdB_INV_LOOKUP[codedflr[i]];
  104056. }
  104057. for(;i<n;i++)
  104058. residue[i]=0.;
  104059. }
  104060. void _vp_noisemask(vorbis_look_psy *p,
  104061. float *logmdct,
  104062. float *logmask){
  104063. int i,n=p->n;
  104064. float *work=(float*) alloca(n*sizeof(*work));
  104065. bark_noise_hybridmp(n,p->bark,logmdct,logmask,
  104066. 140.,-1);
  104067. for(i=0;i<n;i++)work[i]=logmdct[i]-logmask[i];
  104068. bark_noise_hybridmp(n,p->bark,work,logmask,0.,
  104069. p->vi->noisewindowfixed);
  104070. for(i=0;i<n;i++)work[i]=logmdct[i]-work[i];
  104071. #if 0
  104072. {
  104073. static int seq=0;
  104074. float work2[n];
  104075. for(i=0;i<n;i++){
  104076. work2[i]=logmask[i]+work[i];
  104077. }
  104078. if(seq&1)
  104079. _analysis_output("median2R",seq/2,work,n,1,0,0);
  104080. else
  104081. _analysis_output("median2L",seq/2,work,n,1,0,0);
  104082. if(seq&1)
  104083. _analysis_output("envelope2R",seq/2,work2,n,1,0,0);
  104084. else
  104085. _analysis_output("envelope2L",seq/2,work2,n,1,0,0);
  104086. seq++;
  104087. }
  104088. #endif
  104089. for(i=0;i<n;i++){
  104090. int dB=logmask[i]+.5;
  104091. if(dB>=NOISE_COMPAND_LEVELS)dB=NOISE_COMPAND_LEVELS-1;
  104092. if(dB<0)dB=0;
  104093. logmask[i]= work[i]+p->vi->noisecompand[dB];
  104094. }
  104095. }
  104096. void _vp_tonemask(vorbis_look_psy *p,
  104097. float *logfft,
  104098. float *logmask,
  104099. float global_specmax,
  104100. float local_specmax){
  104101. int i,n=p->n;
  104102. float *seed=(float*) alloca(sizeof(*seed)*p->total_octave_lines);
  104103. float att=local_specmax+p->vi->ath_adjatt;
  104104. for(i=0;i<p->total_octave_lines;i++)seed[i]=NEGINF;
  104105. if(att<p->vi->ath_maxatt)att=p->vi->ath_maxatt;
  104106. for(i=0;i<n;i++)
  104107. logmask[i]=p->ath[i]+att;
  104108. seed_loop(p,(const float ***)p->tonecurves,logfft,logmask,seed,global_specmax);
  104109. max_seeds(p,seed,logmask);
  104110. }
  104111. void _vp_offset_and_mix(vorbis_look_psy *p,
  104112. float *noise,
  104113. float *tone,
  104114. int offset_select,
  104115. float *logmask,
  104116. float *mdct,
  104117. float *logmdct){
  104118. int i,n=p->n;
  104119. float de, coeffi, cx;/* AoTuV */
  104120. float toneatt=p->vi->tone_masteratt[offset_select];
  104121. cx = p->m_val;
  104122. for(i=0;i<n;i++){
  104123. float val= noise[i]+p->noiseoffset[offset_select][i];
  104124. if(val>p->vi->noisemaxsupp)val=p->vi->noisemaxsupp;
  104125. logmask[i]=max(val,tone[i]+toneatt);
  104126. if(offset_select == 1) {
  104127. coeffi = -17.2; /* coeffi is a -17.2dB threshold */
  104128. val = val - logmdct[i]; /* val == mdct line value relative to floor in dB */
  104129. if(val > coeffi){
  104130. de = 1.0-((val-coeffi)*0.005*cx);
  104131. if(de < 0) de = 0.0001;
  104132. }else
  104133. de = 1.0-((val-coeffi)*0.0003*cx);
  104134. mdct[i] *= de;
  104135. }
  104136. }
  104137. }
  104138. float _vp_ampmax_decay(float amp,vorbis_dsp_state *vd){
  104139. vorbis_info *vi=vd->vi;
  104140. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  104141. vorbis_info_psy_global *gi=&ci->psy_g_param;
  104142. int n=ci->blocksizes[vd->W]/2;
  104143. float secs=(float)n/vi->rate;
  104144. amp+=secs*gi->ampmax_att_per_sec;
  104145. if(amp<-9999)amp=-9999;
  104146. return(amp);
  104147. }
  104148. static void couple_lossless(float A, float B,
  104149. float *qA, float *qB){
  104150. int test1=fabs(*qA)>fabs(*qB);
  104151. test1-= fabs(*qA)<fabs(*qB);
  104152. if(!test1)test1=((fabs(A)>fabs(B))<<1)-1;
  104153. if(test1==1){
  104154. *qB=(*qA>0.f?*qA-*qB:*qB-*qA);
  104155. }else{
  104156. float temp=*qB;
  104157. *qB=(*qB>0.f?*qA-*qB:*qB-*qA);
  104158. *qA=temp;
  104159. }
  104160. if(*qB>fabs(*qA)*1.9999f){
  104161. *qB= -fabs(*qA)*2.f;
  104162. *qA= -*qA;
  104163. }
  104164. }
  104165. static float hypot_lookup[32]={
  104166. -0.009935, -0.011245, -0.012726, -0.014397,
  104167. -0.016282, -0.018407, -0.020800, -0.023494,
  104168. -0.026522, -0.029923, -0.033737, -0.038010,
  104169. -0.042787, -0.048121, -0.054064, -0.060671,
  104170. -0.068000, -0.076109, -0.085054, -0.094892,
  104171. -0.105675, -0.117451, -0.130260, -0.144134,
  104172. -0.159093, -0.175146, -0.192286, -0.210490,
  104173. -0.229718, -0.249913, -0.271001, -0.292893};
  104174. static void precomputed_couple_point(float premag,
  104175. int floorA,int floorB,
  104176. float *mag, float *ang){
  104177. int test=(floorA>floorB)-1;
  104178. int offset=31-abs(floorA-floorB);
  104179. float floormag=hypot_lookup[((offset<0)-1)&offset]+1.f;
  104180. floormag*=FLOOR1_fromdB_INV_LOOKUP[(floorB&test)|(floorA&(~test))];
  104181. *mag=premag*floormag;
  104182. *ang=0.f;
  104183. }
  104184. static float dipole_hypot(float a, float b){
  104185. if(a>0.){
  104186. if(b>0.)return sqrt(a*a+b*b);
  104187. if(a>-b)return sqrt(a*a-b*b);
  104188. return -sqrt(b*b-a*a);
  104189. }
  104190. if(b<0.)return -sqrt(a*a+b*b);
  104191. if(-a>b)return -sqrt(a*a-b*b);
  104192. return sqrt(b*b-a*a);
  104193. }
  104194. static float round_hypot(float a, float b){
  104195. if(a>0.){
  104196. if(b>0.)return sqrt(a*a+b*b);
  104197. if(a>-b)return sqrt(a*a+b*b);
  104198. return -sqrt(b*b+a*a);
  104199. }
  104200. if(b<0.)return -sqrt(a*a+b*b);
  104201. if(-a>b)return -sqrt(a*a+b*b);
  104202. return sqrt(b*b+a*a);
  104203. }
  104204. float **_vp_quantize_couple_memo(vorbis_block *vb,
  104205. vorbis_info_psy_global *g,
  104206. vorbis_look_psy *p,
  104207. vorbis_info_mapping0 *vi,
  104208. float **mdct){
  104209. int i,j,n=p->n;
  104210. float **ret=(float**) _vorbis_block_alloc(vb,vi->coupling_steps*sizeof(*ret));
  104211. int limit=g->coupling_pointlimit[p->vi->blockflag][PACKETBLOBS/2];
  104212. for(i=0;i<vi->coupling_steps;i++){
  104213. float *mdctM=mdct[vi->coupling_mag[i]];
  104214. float *mdctA=mdct[vi->coupling_ang[i]];
  104215. ret[i]=(float*) _vorbis_block_alloc(vb,n*sizeof(**ret));
  104216. for(j=0;j<limit;j++)
  104217. ret[i][j]=dipole_hypot(mdctM[j],mdctA[j]);
  104218. for(;j<n;j++)
  104219. ret[i][j]=round_hypot(mdctM[j],mdctA[j]);
  104220. }
  104221. return(ret);
  104222. }
  104223. static int apsort(const void *a, const void *b){
  104224. float f1=fabs(**(float**)a);
  104225. float f2=fabs(**(float**)b);
  104226. return (f1<f2)-(f1>f2);
  104227. }
  104228. int **_vp_quantize_couple_sort(vorbis_block *vb,
  104229. vorbis_look_psy *p,
  104230. vorbis_info_mapping0 *vi,
  104231. float **mags){
  104232. if(p->vi->normal_point_p){
  104233. int i,j,k,n=p->n;
  104234. int **ret=(int**) _vorbis_block_alloc(vb,vi->coupling_steps*sizeof(*ret));
  104235. int partition=p->vi->normal_partition;
  104236. float **work=(float**) alloca(sizeof(*work)*partition);
  104237. for(i=0;i<vi->coupling_steps;i++){
  104238. ret[i]=(int*) _vorbis_block_alloc(vb,n*sizeof(**ret));
  104239. for(j=0;j<n;j+=partition){
  104240. for(k=0;k<partition;k++)work[k]=mags[i]+k+j;
  104241. qsort(work,partition,sizeof(*work),apsort);
  104242. for(k=0;k<partition;k++)ret[i][k+j]=work[k]-mags[i];
  104243. }
  104244. }
  104245. return(ret);
  104246. }
  104247. return(NULL);
  104248. }
  104249. void _vp_noise_normalize_sort(vorbis_look_psy *p,
  104250. float *magnitudes,int *sortedindex){
  104251. int i,j,n=p->n;
  104252. vorbis_info_psy *vi=p->vi;
  104253. int partition=vi->normal_partition;
  104254. float **work=(float**) alloca(sizeof(*work)*partition);
  104255. int start=vi->normal_start;
  104256. for(j=start;j<n;j+=partition){
  104257. if(j+partition>n)partition=n-j;
  104258. for(i=0;i<partition;i++)work[i]=magnitudes+i+j;
  104259. qsort(work,partition,sizeof(*work),apsort);
  104260. for(i=0;i<partition;i++){
  104261. sortedindex[i+j-start]=work[i]-magnitudes;
  104262. }
  104263. }
  104264. }
  104265. void _vp_noise_normalize(vorbis_look_psy *p,
  104266. float *in,float *out,int *sortedindex){
  104267. int flag=0,i,j=0,n=p->n;
  104268. vorbis_info_psy *vi=p->vi;
  104269. int partition=vi->normal_partition;
  104270. int start=vi->normal_start;
  104271. if(start>n)start=n;
  104272. if(vi->normal_channel_p){
  104273. for(;j<start;j++)
  104274. out[j]=rint(in[j]);
  104275. for(;j+partition<=n;j+=partition){
  104276. float acc=0.;
  104277. int k;
  104278. for(i=j;i<j+partition;i++)
  104279. acc+=in[i]*in[i];
  104280. for(i=0;i<partition;i++){
  104281. k=sortedindex[i+j-start];
  104282. if(in[k]*in[k]>=.25f){
  104283. out[k]=rint(in[k]);
  104284. acc-=in[k]*in[k];
  104285. flag=1;
  104286. }else{
  104287. if(acc<vi->normal_thresh)break;
  104288. out[k]=unitnorm(in[k]);
  104289. acc-=1.;
  104290. }
  104291. }
  104292. for(;i<partition;i++){
  104293. k=sortedindex[i+j-start];
  104294. out[k]=0.;
  104295. }
  104296. }
  104297. }
  104298. for(;j<n;j++)
  104299. out[j]=rint(in[j]);
  104300. }
  104301. void _vp_couple(int blobno,
  104302. vorbis_info_psy_global *g,
  104303. vorbis_look_psy *p,
  104304. vorbis_info_mapping0 *vi,
  104305. float **res,
  104306. float **mag_memo,
  104307. int **mag_sort,
  104308. int **ifloor,
  104309. int *nonzero,
  104310. int sliding_lowpass){
  104311. int i,j,k,n=p->n;
  104312. for(i=0;i<vi->coupling_steps;i++){
  104313. if(nonzero[vi->coupling_mag[i]] ||
  104314. nonzero[vi->coupling_ang[i]]){
  104315. float *rM=res[vi->coupling_mag[i]];
  104316. float *rA=res[vi->coupling_ang[i]];
  104317. float *qM=rM+n;
  104318. float *qA=rA+n;
  104319. int *floorM=ifloor[vi->coupling_mag[i]];
  104320. int *floorA=ifloor[vi->coupling_ang[i]];
  104321. float prepoint=stereo_threshholds[g->coupling_prepointamp[blobno]];
  104322. float postpoint=stereo_threshholds[g->coupling_postpointamp[blobno]];
  104323. int partition=(p->vi->normal_point_p?p->vi->normal_partition:p->n);
  104324. int limit=g->coupling_pointlimit[p->vi->blockflag][blobno];
  104325. int pointlimit=limit;
  104326. nonzero[vi->coupling_mag[i]]=1;
  104327. nonzero[vi->coupling_ang[i]]=1;
  104328. if(n > 1000)
  104329. postpoint=stereo_threshholds_limited[g->coupling_postpointamp[blobno]];
  104330. for(j=0;j<p->n;j+=partition){
  104331. float acc=0.f;
  104332. for(k=0;k<partition;k++){
  104333. int l=k+j;
  104334. if(l<sliding_lowpass){
  104335. if((l>=limit && fabs(rM[l])<postpoint && fabs(rA[l])<postpoint) ||
  104336. (fabs(rM[l])<prepoint && fabs(rA[l])<prepoint)){
  104337. precomputed_couple_point(mag_memo[i][l],
  104338. floorM[l],floorA[l],
  104339. qM+l,qA+l);
  104340. if(rint(qM[l])==0.f)acc+=qM[l]*qM[l];
  104341. }else{
  104342. couple_lossless(rM[l],rA[l],qM+l,qA+l);
  104343. }
  104344. }else{
  104345. qM[l]=0.;
  104346. qA[l]=0.;
  104347. }
  104348. }
  104349. if(p->vi->normal_point_p){
  104350. for(k=0;k<partition && acc>=p->vi->normal_thresh;k++){
  104351. int l=mag_sort[i][j+k];
  104352. if(l<sliding_lowpass && l>=pointlimit && rint(qM[l])==0.f){
  104353. qM[l]=unitnorm(qM[l]);
  104354. acc-=1.f;
  104355. }
  104356. }
  104357. }
  104358. }
  104359. }
  104360. }
  104361. }
  104362. void hf_reduction(vorbis_info_psy_global *g,
  104363. vorbis_look_psy *p,
  104364. vorbis_info_mapping0 *vi,
  104365. float **mdct){
  104366. int i,j,n=p->n, de=0.3*p->m_val;
  104367. int limit=g->coupling_pointlimit[p->vi->blockflag][PACKETBLOBS/2];
  104368. for(i=0; i<vi->coupling_steps; i++){
  104369. for(j=limit; j<n; j++)
  104370. mdct[i][j] *= (1.0 - de*((float)(j-limit) / (float)(n-limit)));
  104371. }
  104372. }
  104373. #endif
  104374. /*** End of inlined file: psy.c ***/
  104375. /*** Start of inlined file: registry.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. extern vorbis_func_floor floor0_exportbundle;
  104385. extern vorbis_func_floor floor1_exportbundle;
  104386. extern vorbis_func_residue residue0_exportbundle;
  104387. extern vorbis_func_residue residue1_exportbundle;
  104388. extern vorbis_func_residue residue2_exportbundle;
  104389. extern vorbis_func_mapping mapping0_exportbundle;
  104390. vorbis_func_floor *_floor_P[]={
  104391. &floor0_exportbundle,
  104392. &floor1_exportbundle,
  104393. };
  104394. vorbis_func_residue *_residue_P[]={
  104395. &residue0_exportbundle,
  104396. &residue1_exportbundle,
  104397. &residue2_exportbundle,
  104398. };
  104399. vorbis_func_mapping *_mapping_P[]={
  104400. &mapping0_exportbundle,
  104401. };
  104402. #endif
  104403. /*** End of inlined file: registry.c ***/
  104404. /*** Start of inlined file: res0.c ***/
  104405. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  104406. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  104407. // tasks..
  104408. #if JUCE_MSVC
  104409. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  104410. #endif
  104411. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  104412. #if JUCE_USE_OGGVORBIS
  104413. #include <stdlib.h>
  104414. #include <string.h>
  104415. #include <math.h>
  104416. #if defined(TRAIN_RES) || defined (TRAIN_RESAUX)
  104417. #include <stdio.h>
  104418. #endif
  104419. typedef struct {
  104420. vorbis_info_residue0 *info;
  104421. int parts;
  104422. int stages;
  104423. codebook *fullbooks;
  104424. codebook *phrasebook;
  104425. codebook ***partbooks;
  104426. int partvals;
  104427. int **decodemap;
  104428. long postbits;
  104429. long phrasebits;
  104430. long frames;
  104431. #if defined(TRAIN_RES) || defined(TRAIN_RESAUX)
  104432. int train_seq;
  104433. long *training_data[8][64];
  104434. float training_max[8][64];
  104435. float training_min[8][64];
  104436. float tmin;
  104437. float tmax;
  104438. #endif
  104439. } vorbis_look_residue0;
  104440. void res0_free_info(vorbis_info_residue *i){
  104441. vorbis_info_residue0 *info=(vorbis_info_residue0 *)i;
  104442. if(info){
  104443. memset(info,0,sizeof(*info));
  104444. _ogg_free(info);
  104445. }
  104446. }
  104447. void res0_free_look(vorbis_look_residue *i){
  104448. int j;
  104449. if(i){
  104450. vorbis_look_residue0 *look=(vorbis_look_residue0 *)i;
  104451. #ifdef TRAIN_RES
  104452. {
  104453. int j,k,l;
  104454. for(j=0;j<look->parts;j++){
  104455. for(k=0;k<8;k++)
  104456. if(look->training_data[k][j]){
  104457. char buffer[80];
  104458. FILE *of;
  104459. codebook *statebook=look->partbooks[j][k];
  104460. sprintf(buffer,"res_part%d_pass%d.vqd",j,k);
  104461. of=fopen(buffer,"a");
  104462. for(l=0;l<statebook->entries;l++)
  104463. fprintf(of,"%d:%ld\n",l,look->training_data[k][j][l]);
  104464. fclose(of);
  104465. _ogg_free(look->training_data[k][j]);
  104466. look->training_data[k][j]=NULL;
  104467. }
  104468. }
  104469. }
  104470. fprintf(stderr,"min/max residue: %g::%g\n",look->tmin,look->tmax);
  104471. #endif
  104472. for(j=0;j<look->parts;j++)
  104473. if(look->partbooks[j])_ogg_free(look->partbooks[j]);
  104474. _ogg_free(look->partbooks);
  104475. for(j=0;j<look->partvals;j++)
  104476. _ogg_free(look->decodemap[j]);
  104477. _ogg_free(look->decodemap);
  104478. memset(look,0,sizeof(*look));
  104479. _ogg_free(look);
  104480. }
  104481. }
  104482. static int icount(unsigned int v){
  104483. int ret=0;
  104484. while(v){
  104485. ret+=v&1;
  104486. v>>=1;
  104487. }
  104488. return(ret);
  104489. }
  104490. void res0_pack(vorbis_info_residue *vr,oggpack_buffer *opb){
  104491. vorbis_info_residue0 *info=(vorbis_info_residue0 *)vr;
  104492. int j,acc=0;
  104493. oggpack_write(opb,info->begin,24);
  104494. oggpack_write(opb,info->end,24);
  104495. oggpack_write(opb,info->grouping-1,24); /* residue vectors to group and
  104496. code with a partitioned book */
  104497. oggpack_write(opb,info->partitions-1,6); /* possible partition choices */
  104498. oggpack_write(opb,info->groupbook,8); /* group huffman book */
  104499. for(j=0;j<info->partitions;j++){
  104500. if(ilog(info->secondstages[j])>3){
  104501. oggpack_write(opb,info->secondstages[j],3);
  104502. oggpack_write(opb,1,1);
  104503. oggpack_write(opb,info->secondstages[j]>>3,5);
  104504. }else
  104505. oggpack_write(opb,info->secondstages[j],4); /* trailing zero */
  104506. acc+=icount(info->secondstages[j]);
  104507. }
  104508. for(j=0;j<acc;j++)
  104509. oggpack_write(opb,info->booklist[j],8);
  104510. }
  104511. vorbis_info_residue *res0_unpack(vorbis_info *vi,oggpack_buffer *opb){
  104512. int j,acc=0;
  104513. vorbis_info_residue0 *info=(vorbis_info_residue0*) _ogg_calloc(1,sizeof(*info));
  104514. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  104515. info->begin=oggpack_read(opb,24);
  104516. info->end=oggpack_read(opb,24);
  104517. info->grouping=oggpack_read(opb,24)+1;
  104518. info->partitions=oggpack_read(opb,6)+1;
  104519. info->groupbook=oggpack_read(opb,8);
  104520. for(j=0;j<info->partitions;j++){
  104521. int cascade=oggpack_read(opb,3);
  104522. if(oggpack_read(opb,1))
  104523. cascade|=(oggpack_read(opb,5)<<3);
  104524. info->secondstages[j]=cascade;
  104525. acc+=icount(cascade);
  104526. }
  104527. for(j=0;j<acc;j++)
  104528. info->booklist[j]=oggpack_read(opb,8);
  104529. if(info->groupbook>=ci->books)goto errout;
  104530. for(j=0;j<acc;j++)
  104531. if(info->booklist[j]>=ci->books)goto errout;
  104532. return(info);
  104533. errout:
  104534. res0_free_info(info);
  104535. return(NULL);
  104536. }
  104537. vorbis_look_residue *res0_look(vorbis_dsp_state *vd,
  104538. vorbis_info_residue *vr){
  104539. vorbis_info_residue0 *info=(vorbis_info_residue0 *)vr;
  104540. vorbis_look_residue0 *look=(vorbis_look_residue0 *)_ogg_calloc(1,sizeof(*look));
  104541. codec_setup_info *ci=(codec_setup_info*)vd->vi->codec_setup;
  104542. int j,k,acc=0;
  104543. int dim;
  104544. int maxstage=0;
  104545. look->info=info;
  104546. look->parts=info->partitions;
  104547. look->fullbooks=ci->fullbooks;
  104548. look->phrasebook=ci->fullbooks+info->groupbook;
  104549. dim=look->phrasebook->dim;
  104550. look->partbooks=(codebook***)_ogg_calloc(look->parts,sizeof(*look->partbooks));
  104551. for(j=0;j<look->parts;j++){
  104552. int stages=ilog(info->secondstages[j]);
  104553. if(stages){
  104554. if(stages>maxstage)maxstage=stages;
  104555. look->partbooks[j]=(codebook**) _ogg_calloc(stages,sizeof(*look->partbooks[j]));
  104556. for(k=0;k<stages;k++)
  104557. if(info->secondstages[j]&(1<<k)){
  104558. look->partbooks[j][k]=ci->fullbooks+info->booklist[acc++];
  104559. #ifdef TRAIN_RES
  104560. look->training_data[k][j]=_ogg_calloc(look->partbooks[j][k]->entries,
  104561. sizeof(***look->training_data));
  104562. #endif
  104563. }
  104564. }
  104565. }
  104566. look->partvals=rint(pow((float)look->parts,(float)dim));
  104567. look->stages=maxstage;
  104568. look->decodemap=(int**)_ogg_malloc(look->partvals*sizeof(*look->decodemap));
  104569. for(j=0;j<look->partvals;j++){
  104570. long val=j;
  104571. long mult=look->partvals/look->parts;
  104572. look->decodemap[j]=(int*)_ogg_malloc(dim*sizeof(*look->decodemap[j]));
  104573. for(k=0;k<dim;k++){
  104574. long deco=val/mult;
  104575. val-=deco*mult;
  104576. mult/=look->parts;
  104577. look->decodemap[j][k]=deco;
  104578. }
  104579. }
  104580. #if defined(TRAIN_RES) || defined (TRAIN_RESAUX)
  104581. {
  104582. static int train_seq=0;
  104583. look->train_seq=train_seq++;
  104584. }
  104585. #endif
  104586. return(look);
  104587. }
  104588. static int local_book_besterror(codebook *book,float *a){
  104589. int dim=book->dim,i,k,o;
  104590. int best=0;
  104591. encode_aux_threshmatch *tt=book->c->thresh_tree;
  104592. for(k=0,o=dim;k<dim;++k){
  104593. float val=a[--o];
  104594. i=tt->threshvals>>1;
  104595. if(val<tt->quantthresh[i]){
  104596. if(val<tt->quantthresh[i-1]){
  104597. for(--i;i>0;--i)
  104598. if(val>=tt->quantthresh[i-1])
  104599. break;
  104600. }
  104601. }else{
  104602. for(++i;i<tt->threshvals-1;++i)
  104603. if(val<tt->quantthresh[i])break;
  104604. }
  104605. best=(best*tt->quantvals)+tt->quantmap[i];
  104606. }
  104607. if(book->c->lengthlist[best]<=0){
  104608. const static_codebook *c=book->c;
  104609. int i,j;
  104610. float bestf=0.f;
  104611. float *e=book->valuelist;
  104612. best=-1;
  104613. for(i=0;i<book->entries;i++){
  104614. if(c->lengthlist[i]>0){
  104615. float thisx=0.f;
  104616. for(j=0;j<dim;j++){
  104617. float val=(e[j]-a[j]);
  104618. thisx+=val*val;
  104619. }
  104620. if(best==-1 || thisx<bestf){
  104621. bestf=thisx;
  104622. best=i;
  104623. }
  104624. }
  104625. e+=dim;
  104626. }
  104627. }
  104628. {
  104629. float *ptr=book->valuelist+best*dim;
  104630. for(i=0;i<dim;i++)
  104631. *a++ -= *ptr++;
  104632. }
  104633. return(best);
  104634. }
  104635. static int _encodepart(oggpack_buffer *opb,float *vec, int n,
  104636. codebook *book,long *acc){
  104637. int i,bits=0;
  104638. int dim=book->dim;
  104639. int step=n/dim;
  104640. for(i=0;i<step;i++){
  104641. int entry=local_book_besterror(book,vec+i*dim);
  104642. #ifdef TRAIN_RES
  104643. acc[entry]++;
  104644. #endif
  104645. bits+=vorbis_book_encode(book,entry,opb);
  104646. }
  104647. return(bits);
  104648. }
  104649. static long **_01class(vorbis_block *vb,vorbis_look_residue *vl,
  104650. float **in,int ch){
  104651. long i,j,k;
  104652. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104653. vorbis_info_residue0 *info=look->info;
  104654. int samples_per_partition=info->grouping;
  104655. int possible_partitions=info->partitions;
  104656. int n=info->end-info->begin;
  104657. int partvals=n/samples_per_partition;
  104658. long **partword=(long**)_vorbis_block_alloc(vb,ch*sizeof(*partword));
  104659. float scale=100./samples_per_partition;
  104660. for(i=0;i<ch;i++){
  104661. partword[i]=(long*)_vorbis_block_alloc(vb,n/samples_per_partition*sizeof(*partword[i]));
  104662. memset(partword[i],0,n/samples_per_partition*sizeof(*partword[i]));
  104663. }
  104664. for(i=0;i<partvals;i++){
  104665. int offset=i*samples_per_partition+info->begin;
  104666. for(j=0;j<ch;j++){
  104667. float max=0.;
  104668. float ent=0.;
  104669. for(k=0;k<samples_per_partition;k++){
  104670. if(fabs(in[j][offset+k])>max)max=fabs(in[j][offset+k]);
  104671. ent+=fabs(rint(in[j][offset+k]));
  104672. }
  104673. ent*=scale;
  104674. for(k=0;k<possible_partitions-1;k++)
  104675. if(max<=info->classmetric1[k] &&
  104676. (info->classmetric2[k]<0 || (int)ent<info->classmetric2[k]))
  104677. break;
  104678. partword[j][i]=k;
  104679. }
  104680. }
  104681. #ifdef TRAIN_RESAUX
  104682. {
  104683. FILE *of;
  104684. char buffer[80];
  104685. for(i=0;i<ch;i++){
  104686. sprintf(buffer,"resaux_%d.vqd",look->train_seq);
  104687. of=fopen(buffer,"a");
  104688. for(j=0;j<partvals;j++)
  104689. fprintf(of,"%ld, ",partword[i][j]);
  104690. fprintf(of,"\n");
  104691. fclose(of);
  104692. }
  104693. }
  104694. #endif
  104695. look->frames++;
  104696. return(partword);
  104697. }
  104698. static long **_2class(vorbis_block *vb,vorbis_look_residue *vl,float **in,
  104699. int ch){
  104700. long i,j,k,l;
  104701. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104702. vorbis_info_residue0 *info=look->info;
  104703. int samples_per_partition=info->grouping;
  104704. int possible_partitions=info->partitions;
  104705. int n=info->end-info->begin;
  104706. int partvals=n/samples_per_partition;
  104707. long **partword=(long**)_vorbis_block_alloc(vb,sizeof(*partword));
  104708. #if defined(TRAIN_RES) || defined (TRAIN_RESAUX)
  104709. FILE *of;
  104710. char buffer[80];
  104711. #endif
  104712. partword[0]=(long*)_vorbis_block_alloc(vb,n*ch/samples_per_partition*sizeof(*partword[0]));
  104713. memset(partword[0],0,n*ch/samples_per_partition*sizeof(*partword[0]));
  104714. for(i=0,l=info->begin/ch;i<partvals;i++){
  104715. float magmax=0.f;
  104716. float angmax=0.f;
  104717. for(j=0;j<samples_per_partition;j+=ch){
  104718. if(fabs(in[0][l])>magmax)magmax=fabs(in[0][l]);
  104719. for(k=1;k<ch;k++)
  104720. if(fabs(in[k][l])>angmax)angmax=fabs(in[k][l]);
  104721. l++;
  104722. }
  104723. for(j=0;j<possible_partitions-1;j++)
  104724. if(magmax<=info->classmetric1[j] &&
  104725. angmax<=info->classmetric2[j])
  104726. break;
  104727. partword[0][i]=j;
  104728. }
  104729. #ifdef TRAIN_RESAUX
  104730. sprintf(buffer,"resaux_%d.vqd",look->train_seq);
  104731. of=fopen(buffer,"a");
  104732. for(i=0;i<partvals;i++)
  104733. fprintf(of,"%ld, ",partword[0][i]);
  104734. fprintf(of,"\n");
  104735. fclose(of);
  104736. #endif
  104737. look->frames++;
  104738. return(partword);
  104739. }
  104740. static int _01forward(oggpack_buffer *opb,
  104741. vorbis_block *vb,vorbis_look_residue *vl,
  104742. float **in,int ch,
  104743. long **partword,
  104744. int (*encode)(oggpack_buffer *,float *,int,
  104745. codebook *,long *)){
  104746. long i,j,k,s;
  104747. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104748. vorbis_info_residue0 *info=look->info;
  104749. int samples_per_partition=info->grouping;
  104750. int possible_partitions=info->partitions;
  104751. int partitions_per_word=look->phrasebook->dim;
  104752. int n=info->end-info->begin;
  104753. int partvals=n/samples_per_partition;
  104754. long resbits[128];
  104755. long resvals[128];
  104756. #ifdef TRAIN_RES
  104757. for(i=0;i<ch;i++)
  104758. for(j=info->begin;j<info->end;j++){
  104759. if(in[i][j]>look->tmax)look->tmax=in[i][j];
  104760. if(in[i][j]<look->tmin)look->tmin=in[i][j];
  104761. }
  104762. #endif
  104763. memset(resbits,0,sizeof(resbits));
  104764. memset(resvals,0,sizeof(resvals));
  104765. for(s=0;s<look->stages;s++){
  104766. for(i=0;i<partvals;){
  104767. if(s==0){
  104768. for(j=0;j<ch;j++){
  104769. long val=partword[j][i];
  104770. for(k=1;k<partitions_per_word;k++){
  104771. val*=possible_partitions;
  104772. if(i+k<partvals)
  104773. val+=partword[j][i+k];
  104774. }
  104775. if(val<look->phrasebook->entries)
  104776. look->phrasebits+=vorbis_book_encode(look->phrasebook,val,opb);
  104777. #if 0 /*def TRAIN_RES*/
  104778. else
  104779. fprintf(stderr,"!");
  104780. #endif
  104781. }
  104782. }
  104783. for(k=0;k<partitions_per_word && i<partvals;k++,i++){
  104784. long offset=i*samples_per_partition+info->begin;
  104785. for(j=0;j<ch;j++){
  104786. if(s==0)resvals[partword[j][i]]+=samples_per_partition;
  104787. if(info->secondstages[partword[j][i]]&(1<<s)){
  104788. codebook *statebook=look->partbooks[partword[j][i]][s];
  104789. if(statebook){
  104790. int ret;
  104791. long *accumulator=NULL;
  104792. #ifdef TRAIN_RES
  104793. accumulator=look->training_data[s][partword[j][i]];
  104794. {
  104795. int l;
  104796. float *samples=in[j]+offset;
  104797. for(l=0;l<samples_per_partition;l++){
  104798. if(samples[l]<look->training_min[s][partword[j][i]])
  104799. look->training_min[s][partword[j][i]]=samples[l];
  104800. if(samples[l]>look->training_max[s][partword[j][i]])
  104801. look->training_max[s][partword[j][i]]=samples[l];
  104802. }
  104803. }
  104804. #endif
  104805. ret=encode(opb,in[j]+offset,samples_per_partition,
  104806. statebook,accumulator);
  104807. look->postbits+=ret;
  104808. resbits[partword[j][i]]+=ret;
  104809. }
  104810. }
  104811. }
  104812. }
  104813. }
  104814. }
  104815. return(0);
  104816. }
  104817. static int _01inverse(vorbis_block *vb,vorbis_look_residue *vl,
  104818. float **in,int ch,
  104819. long (*decodepart)(codebook *, float *,
  104820. oggpack_buffer *,int)){
  104821. long i,j,k,l,s;
  104822. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104823. vorbis_info_residue0 *info=look->info;
  104824. int samples_per_partition=info->grouping;
  104825. int partitions_per_word=look->phrasebook->dim;
  104826. int n=info->end-info->begin;
  104827. int partvals=n/samples_per_partition;
  104828. int partwords=(partvals+partitions_per_word-1)/partitions_per_word;
  104829. int ***partword=(int***)alloca(ch*sizeof(*partword));
  104830. for(j=0;j<ch;j++)
  104831. partword[j]=(int**)_vorbis_block_alloc(vb,partwords*sizeof(*partword[j]));
  104832. for(s=0;s<look->stages;s++){
  104833. for(i=0,l=0;i<partvals;l++){
  104834. if(s==0){
  104835. for(j=0;j<ch;j++){
  104836. int temp=vorbis_book_decode(look->phrasebook,&vb->opb);
  104837. if(temp==-1)goto eopbreak;
  104838. partword[j][l]=look->decodemap[temp];
  104839. if(partword[j][l]==NULL)goto errout;
  104840. }
  104841. }
  104842. for(k=0;k<partitions_per_word && i<partvals;k++,i++)
  104843. for(j=0;j<ch;j++){
  104844. long offset=info->begin+i*samples_per_partition;
  104845. if(info->secondstages[partword[j][l][k]]&(1<<s)){
  104846. codebook *stagebook=look->partbooks[partword[j][l][k]][s];
  104847. if(stagebook){
  104848. if(decodepart(stagebook,in[j]+offset,&vb->opb,
  104849. samples_per_partition)==-1)goto eopbreak;
  104850. }
  104851. }
  104852. }
  104853. }
  104854. }
  104855. errout:
  104856. eopbreak:
  104857. return(0);
  104858. }
  104859. #if 0
  104860. long **res0_class(vorbis_block *vb,vorbis_look_residue *vl,
  104861. float **in,int *nonzero,int ch){
  104862. int i,used=0;
  104863. for(i=0;i<ch;i++)
  104864. if(nonzero[i])
  104865. in[used++]=in[i];
  104866. if(used)
  104867. return(_01class(vb,vl,in,used));
  104868. else
  104869. return(0);
  104870. }
  104871. int res0_forward(vorbis_block *vb,vorbis_look_residue *vl,
  104872. float **in,float **out,int *nonzero,int ch,
  104873. long **partword){
  104874. int i,j,used=0,n=vb->pcmend/2;
  104875. for(i=0;i<ch;i++)
  104876. if(nonzero[i]){
  104877. if(out)
  104878. for(j=0;j<n;j++)
  104879. out[i][j]+=in[i][j];
  104880. in[used++]=in[i];
  104881. }
  104882. if(used){
  104883. int ret=_01forward(vb,vl,in,used,partword,
  104884. _interleaved_encodepart);
  104885. if(out){
  104886. used=0;
  104887. for(i=0;i<ch;i++)
  104888. if(nonzero[i]){
  104889. for(j=0;j<n;j++)
  104890. out[i][j]-=in[used][j];
  104891. used++;
  104892. }
  104893. }
  104894. return(ret);
  104895. }else{
  104896. return(0);
  104897. }
  104898. }
  104899. #endif
  104900. int res0_inverse(vorbis_block *vb,vorbis_look_residue *vl,
  104901. float **in,int *nonzero,int ch){
  104902. int i,used=0;
  104903. for(i=0;i<ch;i++)
  104904. if(nonzero[i])
  104905. in[used++]=in[i];
  104906. if(used)
  104907. return(_01inverse(vb,vl,in,used,vorbis_book_decodevs_add));
  104908. else
  104909. return(0);
  104910. }
  104911. int res1_forward(oggpack_buffer *opb,vorbis_block *vb,vorbis_look_residue *vl,
  104912. float **in,float **out,int *nonzero,int ch,
  104913. long **partword){
  104914. int i,j,used=0,n=vb->pcmend/2;
  104915. for(i=0;i<ch;i++)
  104916. if(nonzero[i]){
  104917. if(out)
  104918. for(j=0;j<n;j++)
  104919. out[i][j]+=in[i][j];
  104920. in[used++]=in[i];
  104921. }
  104922. if(used){
  104923. int ret=_01forward(opb,vb,vl,in,used,partword,_encodepart);
  104924. if(out){
  104925. used=0;
  104926. for(i=0;i<ch;i++)
  104927. if(nonzero[i]){
  104928. for(j=0;j<n;j++)
  104929. out[i][j]-=in[used][j];
  104930. used++;
  104931. }
  104932. }
  104933. return(ret);
  104934. }else{
  104935. return(0);
  104936. }
  104937. }
  104938. long **res1_class(vorbis_block *vb,vorbis_look_residue *vl,
  104939. float **in,int *nonzero,int ch){
  104940. int i,used=0;
  104941. for(i=0;i<ch;i++)
  104942. if(nonzero[i])
  104943. in[used++]=in[i];
  104944. if(used)
  104945. return(_01class(vb,vl,in,used));
  104946. else
  104947. return(0);
  104948. }
  104949. int res1_inverse(vorbis_block *vb,vorbis_look_residue *vl,
  104950. float **in,int *nonzero,int ch){
  104951. int i,used=0;
  104952. for(i=0;i<ch;i++)
  104953. if(nonzero[i])
  104954. in[used++]=in[i];
  104955. if(used)
  104956. return(_01inverse(vb,vl,in,used,vorbis_book_decodev_add));
  104957. else
  104958. return(0);
  104959. }
  104960. long **res2_class(vorbis_block *vb,vorbis_look_residue *vl,
  104961. float **in,int *nonzero,int ch){
  104962. int i,used=0;
  104963. for(i=0;i<ch;i++)
  104964. if(nonzero[i])used++;
  104965. if(used)
  104966. return(_2class(vb,vl,in,ch));
  104967. else
  104968. return(0);
  104969. }
  104970. int res2_forward(oggpack_buffer *opb,
  104971. vorbis_block *vb,vorbis_look_residue *vl,
  104972. float **in,float **out,int *nonzero,int ch,
  104973. long **partword){
  104974. long i,j,k,n=vb->pcmend/2,used=0;
  104975. float *work=(float*)_vorbis_block_alloc(vb,ch*n*sizeof(*work));
  104976. for(i=0;i<ch;i++){
  104977. float *pcm=in[i];
  104978. if(nonzero[i])used++;
  104979. for(j=0,k=i;j<n;j++,k+=ch)
  104980. work[k]=pcm[j];
  104981. }
  104982. if(used){
  104983. int ret=_01forward(opb,vb,vl,&work,1,partword,_encodepart);
  104984. if(out){
  104985. for(i=0;i<ch;i++){
  104986. float *pcm=in[i];
  104987. float *sofar=out[i];
  104988. for(j=0,k=i;j<n;j++,k+=ch)
  104989. sofar[j]+=pcm[j]-work[k];
  104990. }
  104991. }
  104992. return(ret);
  104993. }else{
  104994. return(0);
  104995. }
  104996. }
  104997. int res2_inverse(vorbis_block *vb,vorbis_look_residue *vl,
  104998. float **in,int *nonzero,int ch){
  104999. long i,k,l,s;
  105000. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  105001. vorbis_info_residue0 *info=look->info;
  105002. int samples_per_partition=info->grouping;
  105003. int partitions_per_word=look->phrasebook->dim;
  105004. int n=info->end-info->begin;
  105005. int partvals=n/samples_per_partition;
  105006. int partwords=(partvals+partitions_per_word-1)/partitions_per_word;
  105007. int **partword=(int**)_vorbis_block_alloc(vb,partwords*sizeof(*partword));
  105008. for(i=0;i<ch;i++)if(nonzero[i])break;
  105009. if(i==ch)return(0); /* no nonzero vectors */
  105010. for(s=0;s<look->stages;s++){
  105011. for(i=0,l=0;i<partvals;l++){
  105012. if(s==0){
  105013. int temp=vorbis_book_decode(look->phrasebook,&vb->opb);
  105014. if(temp==-1)goto eopbreak;
  105015. partword[l]=look->decodemap[temp];
  105016. if(partword[l]==NULL)goto errout;
  105017. }
  105018. for(k=0;k<partitions_per_word && i<partvals;k++,i++)
  105019. if(info->secondstages[partword[l][k]]&(1<<s)){
  105020. codebook *stagebook=look->partbooks[partword[l][k]][s];
  105021. if(stagebook){
  105022. if(vorbis_book_decodevv_add(stagebook,in,
  105023. i*samples_per_partition+info->begin,ch,
  105024. &vb->opb,samples_per_partition)==-1)
  105025. goto eopbreak;
  105026. }
  105027. }
  105028. }
  105029. }
  105030. errout:
  105031. eopbreak:
  105032. return(0);
  105033. }
  105034. vorbis_func_residue residue0_exportbundle={
  105035. NULL,
  105036. &res0_unpack,
  105037. &res0_look,
  105038. &res0_free_info,
  105039. &res0_free_look,
  105040. NULL,
  105041. NULL,
  105042. &res0_inverse
  105043. };
  105044. vorbis_func_residue residue1_exportbundle={
  105045. &res0_pack,
  105046. &res0_unpack,
  105047. &res0_look,
  105048. &res0_free_info,
  105049. &res0_free_look,
  105050. &res1_class,
  105051. &res1_forward,
  105052. &res1_inverse
  105053. };
  105054. vorbis_func_residue residue2_exportbundle={
  105055. &res0_pack,
  105056. &res0_unpack,
  105057. &res0_look,
  105058. &res0_free_info,
  105059. &res0_free_look,
  105060. &res2_class,
  105061. &res2_forward,
  105062. &res2_inverse
  105063. };
  105064. #endif
  105065. /*** End of inlined file: res0.c ***/
  105066. /*** Start of inlined file: sharedbook.c ***/
  105067. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  105068. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  105069. // tasks..
  105070. #if JUCE_MSVC
  105071. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  105072. #endif
  105073. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  105074. #if JUCE_USE_OGGVORBIS
  105075. #include <stdlib.h>
  105076. #include <math.h>
  105077. #include <string.h>
  105078. int _ilog(unsigned int v){
  105079. int ret=0;
  105080. while(v){
  105081. ret++;
  105082. v>>=1;
  105083. }
  105084. return(ret);
  105085. }
  105086. #define VQ_FEXP 10
  105087. #define VQ_FMAN 21
  105088. #define VQ_FEXP_BIAS 768 /* bias toward values smaller than 1. */
  105089. long _float32_pack(float val){
  105090. int sign=0;
  105091. long exp;
  105092. long mant;
  105093. if(val<0){
  105094. sign=0x80000000;
  105095. val= -val;
  105096. }
  105097. exp= floor(log(val)/log(2.f));
  105098. mant=rint(ldexp(val,(VQ_FMAN-1)-exp));
  105099. exp=(exp+VQ_FEXP_BIAS)<<VQ_FMAN;
  105100. return(sign|exp|mant);
  105101. }
  105102. float _float32_unpack(long val){
  105103. double mant=val&0x1fffff;
  105104. int sign=val&0x80000000;
  105105. long exp =(val&0x7fe00000L)>>VQ_FMAN;
  105106. if(sign)mant= -mant;
  105107. return(ldexp(mant,exp-(VQ_FMAN-1)-VQ_FEXP_BIAS));
  105108. }
  105109. ogg_uint32_t *_make_words(long *l,long n,long sparsecount){
  105110. long i,j,count=0;
  105111. ogg_uint32_t marker[33];
  105112. ogg_uint32_t *r=(ogg_uint32_t*)_ogg_malloc((sparsecount?sparsecount:n)*sizeof(*r));
  105113. memset(marker,0,sizeof(marker));
  105114. for(i=0;i<n;i++){
  105115. long length=l[i];
  105116. if(length>0){
  105117. ogg_uint32_t entry=marker[length];
  105118. if(length<32 && (entry>>length)){
  105119. _ogg_free(r);
  105120. return(NULL);
  105121. }
  105122. r[count++]=entry;
  105123. {
  105124. for(j=length;j>0;j--){
  105125. if(marker[j]&1){
  105126. if(j==1)
  105127. marker[1]++;
  105128. else
  105129. marker[j]=marker[j-1]<<1;
  105130. break; /* invariant says next upper marker would already
  105131. have been moved if it was on the same path */
  105132. }
  105133. marker[j]++;
  105134. }
  105135. }
  105136. for(j=length+1;j<33;j++)
  105137. if((marker[j]>>1) == entry){
  105138. entry=marker[j];
  105139. marker[j]=marker[j-1]<<1;
  105140. }else
  105141. break;
  105142. }else
  105143. if(sparsecount==0)count++;
  105144. }
  105145. for(i=0,count=0;i<n;i++){
  105146. ogg_uint32_t temp=0;
  105147. for(j=0;j<l[i];j++){
  105148. temp<<=1;
  105149. temp|=(r[count]>>j)&1;
  105150. }
  105151. if(sparsecount){
  105152. if(l[i])
  105153. r[count++]=temp;
  105154. }else
  105155. r[count++]=temp;
  105156. }
  105157. return(r);
  105158. }
  105159. long _book_maptype1_quantvals(const static_codebook *b){
  105160. long vals=floor(pow((float)b->entries,1.f/b->dim));
  105161. while(1){
  105162. long acc=1;
  105163. long acc1=1;
  105164. int i;
  105165. for(i=0;i<b->dim;i++){
  105166. acc*=vals;
  105167. acc1*=vals+1;
  105168. }
  105169. if(acc<=b->entries && acc1>b->entries){
  105170. return(vals);
  105171. }else{
  105172. if(acc>b->entries){
  105173. vals--;
  105174. }else{
  105175. vals++;
  105176. }
  105177. }
  105178. }
  105179. }
  105180. float *_book_unquantize(const static_codebook *b,int n,int *sparsemap){
  105181. long j,k,count=0;
  105182. if(b->maptype==1 || b->maptype==2){
  105183. int quantvals;
  105184. float mindel=_float32_unpack(b->q_min);
  105185. float delta=_float32_unpack(b->q_delta);
  105186. float *r=(float*)_ogg_calloc(n*b->dim,sizeof(*r));
  105187. switch(b->maptype){
  105188. case 1:
  105189. quantvals=_book_maptype1_quantvals(b);
  105190. for(j=0;j<b->entries;j++){
  105191. if((sparsemap && b->lengthlist[j]) || !sparsemap){
  105192. float last=0.f;
  105193. int indexdiv=1;
  105194. for(k=0;k<b->dim;k++){
  105195. int index= (j/indexdiv)%quantvals;
  105196. float val=b->quantlist[index];
  105197. val=fabs(val)*delta+mindel+last;
  105198. if(b->q_sequencep)last=val;
  105199. if(sparsemap)
  105200. r[sparsemap[count]*b->dim+k]=val;
  105201. else
  105202. r[count*b->dim+k]=val;
  105203. indexdiv*=quantvals;
  105204. }
  105205. count++;
  105206. }
  105207. }
  105208. break;
  105209. case 2:
  105210. for(j=0;j<b->entries;j++){
  105211. if((sparsemap && b->lengthlist[j]) || !sparsemap){
  105212. float last=0.f;
  105213. for(k=0;k<b->dim;k++){
  105214. float val=b->quantlist[j*b->dim+k];
  105215. val=fabs(val)*delta+mindel+last;
  105216. if(b->q_sequencep)last=val;
  105217. if(sparsemap)
  105218. r[sparsemap[count]*b->dim+k]=val;
  105219. else
  105220. r[count*b->dim+k]=val;
  105221. }
  105222. count++;
  105223. }
  105224. }
  105225. break;
  105226. }
  105227. return(r);
  105228. }
  105229. return(NULL);
  105230. }
  105231. void vorbis_staticbook_clear(static_codebook *b){
  105232. if(b->allocedp){
  105233. if(b->quantlist)_ogg_free(b->quantlist);
  105234. if(b->lengthlist)_ogg_free(b->lengthlist);
  105235. if(b->nearest_tree){
  105236. _ogg_free(b->nearest_tree->ptr0);
  105237. _ogg_free(b->nearest_tree->ptr1);
  105238. _ogg_free(b->nearest_tree->p);
  105239. _ogg_free(b->nearest_tree->q);
  105240. memset(b->nearest_tree,0,sizeof(*b->nearest_tree));
  105241. _ogg_free(b->nearest_tree);
  105242. }
  105243. if(b->thresh_tree){
  105244. _ogg_free(b->thresh_tree->quantthresh);
  105245. _ogg_free(b->thresh_tree->quantmap);
  105246. memset(b->thresh_tree,0,sizeof(*b->thresh_tree));
  105247. _ogg_free(b->thresh_tree);
  105248. }
  105249. memset(b,0,sizeof(*b));
  105250. }
  105251. }
  105252. void vorbis_staticbook_destroy(static_codebook *b){
  105253. if(b->allocedp){
  105254. vorbis_staticbook_clear(b);
  105255. _ogg_free(b);
  105256. }
  105257. }
  105258. void vorbis_book_clear(codebook *b){
  105259. if(b->valuelist)_ogg_free(b->valuelist);
  105260. if(b->codelist)_ogg_free(b->codelist);
  105261. if(b->dec_index)_ogg_free(b->dec_index);
  105262. if(b->dec_codelengths)_ogg_free(b->dec_codelengths);
  105263. if(b->dec_firsttable)_ogg_free(b->dec_firsttable);
  105264. memset(b,0,sizeof(*b));
  105265. }
  105266. int vorbis_book_init_encode(codebook *c,const static_codebook *s){
  105267. memset(c,0,sizeof(*c));
  105268. c->c=s;
  105269. c->entries=s->entries;
  105270. c->used_entries=s->entries;
  105271. c->dim=s->dim;
  105272. c->codelist=_make_words(s->lengthlist,s->entries,0);
  105273. c->valuelist=_book_unquantize(s,s->entries,NULL);
  105274. return(0);
  105275. }
  105276. static int sort32a(const void *a,const void *b){
  105277. return ( **(ogg_uint32_t **)a>**(ogg_uint32_t **)b)-
  105278. ( **(ogg_uint32_t **)a<**(ogg_uint32_t **)b);
  105279. }
  105280. int vorbis_book_init_decode(codebook *c,const static_codebook *s){
  105281. int i,j,n=0,tabn;
  105282. int *sortindex;
  105283. memset(c,0,sizeof(*c));
  105284. for(i=0;i<s->entries;i++)
  105285. if(s->lengthlist[i]>0)
  105286. n++;
  105287. c->entries=s->entries;
  105288. c->used_entries=n;
  105289. c->dim=s->dim;
  105290. {
  105291. ogg_uint32_t *codes=_make_words(s->lengthlist,s->entries,c->used_entries);
  105292. ogg_uint32_t **codep=(ogg_uint32_t**)alloca(sizeof(*codep)*n);
  105293. if(codes==NULL)goto err_out;
  105294. for(i=0;i<n;i++){
  105295. codes[i]=ogg_bitreverse(codes[i]);
  105296. codep[i]=codes+i;
  105297. }
  105298. qsort(codep,n,sizeof(*codep),sort32a);
  105299. sortindex=(int*)alloca(n*sizeof(*sortindex));
  105300. c->codelist=(ogg_uint32_t*)_ogg_malloc(n*sizeof(*c->codelist));
  105301. for(i=0;i<n;i++){
  105302. int position=codep[i]-codes;
  105303. sortindex[position]=i;
  105304. }
  105305. for(i=0;i<n;i++)
  105306. c->codelist[sortindex[i]]=codes[i];
  105307. _ogg_free(codes);
  105308. }
  105309. c->valuelist=_book_unquantize(s,n,sortindex);
  105310. c->dec_index=(int*)_ogg_malloc(n*sizeof(*c->dec_index));
  105311. for(n=0,i=0;i<s->entries;i++)
  105312. if(s->lengthlist[i]>0)
  105313. c->dec_index[sortindex[n++]]=i;
  105314. c->dec_codelengths=(char*)_ogg_malloc(n*sizeof(*c->dec_codelengths));
  105315. for(n=0,i=0;i<s->entries;i++)
  105316. if(s->lengthlist[i]>0)
  105317. c->dec_codelengths[sortindex[n++]]=s->lengthlist[i];
  105318. c->dec_firsttablen=_ilog(c->used_entries)-4; /* this is magic */
  105319. if(c->dec_firsttablen<5)c->dec_firsttablen=5;
  105320. if(c->dec_firsttablen>8)c->dec_firsttablen=8;
  105321. tabn=1<<c->dec_firsttablen;
  105322. c->dec_firsttable=(ogg_uint32_t*)_ogg_calloc(tabn,sizeof(*c->dec_firsttable));
  105323. c->dec_maxlength=0;
  105324. for(i=0;i<n;i++){
  105325. if(c->dec_maxlength<c->dec_codelengths[i])
  105326. c->dec_maxlength=c->dec_codelengths[i];
  105327. if(c->dec_codelengths[i]<=c->dec_firsttablen){
  105328. ogg_uint32_t orig=ogg_bitreverse(c->codelist[i]);
  105329. for(j=0;j<(1<<(c->dec_firsttablen-c->dec_codelengths[i]));j++)
  105330. c->dec_firsttable[orig|(j<<c->dec_codelengths[i])]=i+1;
  105331. }
  105332. }
  105333. {
  105334. ogg_uint32_t mask=0xfffffffeUL<<(31-c->dec_firsttablen);
  105335. long lo=0,hi=0;
  105336. for(i=0;i<tabn;i++){
  105337. ogg_uint32_t word=i<<(32-c->dec_firsttablen);
  105338. if(c->dec_firsttable[ogg_bitreverse(word)]==0){
  105339. while((lo+1)<n && c->codelist[lo+1]<=word)lo++;
  105340. while( hi<n && word>=(c->codelist[hi]&mask))hi++;
  105341. {
  105342. unsigned long loval=lo;
  105343. unsigned long hival=n-hi;
  105344. if(loval>0x7fff)loval=0x7fff;
  105345. if(hival>0x7fff)hival=0x7fff;
  105346. c->dec_firsttable[ogg_bitreverse(word)]=
  105347. 0x80000000UL | (loval<<15) | hival;
  105348. }
  105349. }
  105350. }
  105351. }
  105352. return(0);
  105353. err_out:
  105354. vorbis_book_clear(c);
  105355. return(-1);
  105356. }
  105357. static float _dist(int el,float *ref, float *b,int step){
  105358. int i;
  105359. float acc=0.f;
  105360. for(i=0;i<el;i++){
  105361. float val=(ref[i]-b[i*step]);
  105362. acc+=val*val;
  105363. }
  105364. return(acc);
  105365. }
  105366. int _best(codebook *book, float *a, int step){
  105367. encode_aux_threshmatch *tt=book->c->thresh_tree;
  105368. #if 0
  105369. encode_aux_nearestmatch *nt=book->c->nearest_tree;
  105370. encode_aux_pigeonhole *pt=book->c->pigeon_tree;
  105371. #endif
  105372. int dim=book->dim;
  105373. int k,o;
  105374. if(tt){
  105375. int index=0,i;
  105376. for(k=0,o=step*(dim-1);k<dim;k++,o-=step){
  105377. i=tt->threshvals>>1;
  105378. if(a[o]<tt->quantthresh[i]){
  105379. for(;i>0;i--)
  105380. if(a[o]>=tt->quantthresh[i-1])
  105381. break;
  105382. }else{
  105383. for(i++;i<tt->threshvals-1;i++)
  105384. if(a[o]<tt->quantthresh[i])break;
  105385. }
  105386. index=(index*tt->quantvals)+tt->quantmap[i];
  105387. }
  105388. if(book->c->lengthlist[index]>0) /* is this unused? If so, we'll
  105389. use a decision tree after all
  105390. and fall through*/
  105391. return(index);
  105392. }
  105393. #if 0
  105394. if(pt){
  105395. const static_codebook *c=book->c;
  105396. int i,besti=-1;
  105397. float best=0.f;
  105398. int entry=0;
  105399. if(c->q_sequencep){
  105400. int pv;
  105401. long mul=1;
  105402. float qlast=0;
  105403. for(k=0,o=0;k<dim;k++,o+=step){
  105404. pv=(int)((a[o]-qlast-pt->min)/pt->del);
  105405. if(pv<0 || pv>=pt->mapentries)break;
  105406. entry+=pt->pigeonmap[pv]*mul;
  105407. mul*=pt->quantvals;
  105408. qlast+=pv*pt->del+pt->min;
  105409. }
  105410. }else{
  105411. for(k=0,o=step*(dim-1);k<dim;k++,o-=step){
  105412. int pv=(int)((a[o]-pt->min)/pt->del);
  105413. if(pv<0 || pv>=pt->mapentries)break;
  105414. entry=entry*pt->quantvals+pt->pigeonmap[pv];
  105415. }
  105416. }
  105417. if(k==dim && pt->fitlength[entry]){
  105418. long *list=pt->fitlist+pt->fitmap[entry];
  105419. for(i=0;i<pt->fitlength[entry];i++){
  105420. float this=_dist(dim,book->valuelist+list[i]*dim,a,step);
  105421. if(besti==-1 || this<best){
  105422. best=this;
  105423. besti=list[i];
  105424. }
  105425. }
  105426. return(besti);
  105427. }
  105428. }
  105429. if(nt){
  105430. while(1){
  105431. float c=0.f;
  105432. float *p=book->valuelist+nt->p[ptr];
  105433. float *q=book->valuelist+nt->q[ptr];
  105434. for(k=0,o=0;k<dim;k++,o+=step)
  105435. c+=(p[k]-q[k])*(a[o]-(p[k]+q[k])*.5);
  105436. if(c>0.f) /* in A */
  105437. ptr= -nt->ptr0[ptr];
  105438. else /* in B */
  105439. ptr= -nt->ptr1[ptr];
  105440. if(ptr<=0)break;
  105441. }
  105442. return(-ptr);
  105443. }
  105444. #endif
  105445. {
  105446. const static_codebook *c=book->c;
  105447. int i,besti=-1;
  105448. float best=0.f;
  105449. float *e=book->valuelist;
  105450. for(i=0;i<book->entries;i++){
  105451. if(c->lengthlist[i]>0){
  105452. float thisx=_dist(dim,e,a,step);
  105453. if(besti==-1 || thisx<best){
  105454. best=thisx;
  105455. besti=i;
  105456. }
  105457. }
  105458. e+=dim;
  105459. }
  105460. return(besti);
  105461. }
  105462. }
  105463. long vorbis_book_codeword(codebook *book,int entry){
  105464. if(book->c) /* only use with encode; decode optimizations are
  105465. allowed to break this */
  105466. return book->codelist[entry];
  105467. return -1;
  105468. }
  105469. long vorbis_book_codelen(codebook *book,int entry){
  105470. if(book->c) /* only use with encode; decode optimizations are
  105471. allowed to break this */
  105472. return book->c->lengthlist[entry];
  105473. return -1;
  105474. }
  105475. #ifdef _V_SELFTEST
  105476. #include <stdio.h>
  105477. static long full_quantlist1[]={0,1,2,3, 4,5,6,7, 8,3,6,1};
  105478. static long partial_quantlist1[]={0,7,2};
  105479. static_codebook test1={
  105480. 4,16,
  105481. NULL,
  105482. 0,
  105483. 0,0,0,0,
  105484. NULL,
  105485. NULL,NULL
  105486. };
  105487. static float *test1_result=NULL;
  105488. static_codebook test2={
  105489. 4,3,
  105490. NULL,
  105491. 2,
  105492. -533200896,1611661312,4,0,
  105493. full_quantlist1,
  105494. NULL,NULL
  105495. };
  105496. static float test2_result[]={-3,-2,-1,0, 1,2,3,4, 5,0,3,-2};
  105497. static_codebook test3={
  105498. 4,3,
  105499. NULL,
  105500. 2,
  105501. -533200896,1611661312,4,1,
  105502. full_quantlist1,
  105503. NULL,NULL
  105504. };
  105505. static float test3_result[]={-3,-5,-6,-6, 1,3,6,10, 5,5,8,6};
  105506. static_codebook test4={
  105507. 3,27,
  105508. NULL,
  105509. 1,
  105510. -533200896,1611661312,4,0,
  105511. partial_quantlist1,
  105512. NULL,NULL
  105513. };
  105514. static float test4_result[]={-3,-3,-3, 4,-3,-3, -1,-3,-3,
  105515. -3, 4,-3, 4, 4,-3, -1, 4,-3,
  105516. -3,-1,-3, 4,-1,-3, -1,-1,-3,
  105517. -3,-3, 4, 4,-3, 4, -1,-3, 4,
  105518. -3, 4, 4, 4, 4, 4, -1, 4, 4,
  105519. -3,-1, 4, 4,-1, 4, -1,-1, 4,
  105520. -3,-3,-1, 4,-3,-1, -1,-3,-1,
  105521. -3, 4,-1, 4, 4,-1, -1, 4,-1,
  105522. -3,-1,-1, 4,-1,-1, -1,-1,-1};
  105523. static_codebook test5={
  105524. 3,27,
  105525. NULL,
  105526. 1,
  105527. -533200896,1611661312,4,1,
  105528. partial_quantlist1,
  105529. NULL,NULL
  105530. };
  105531. static float test5_result[]={-3,-6,-9, 4, 1,-2, -1,-4,-7,
  105532. -3, 1,-2, 4, 8, 5, -1, 3, 0,
  105533. -3,-4,-7, 4, 3, 0, -1,-2,-5,
  105534. -3,-6,-2, 4, 1, 5, -1,-4, 0,
  105535. -3, 1, 5, 4, 8,12, -1, 3, 7,
  105536. -3,-4, 0, 4, 3, 7, -1,-2, 2,
  105537. -3,-6,-7, 4, 1, 0, -1,-4,-5,
  105538. -3, 1, 0, 4, 8, 7, -1, 3, 2,
  105539. -3,-4,-5, 4, 3, 2, -1,-2,-3};
  105540. void run_test(static_codebook *b,float *comp){
  105541. float *out=_book_unquantize(b,b->entries,NULL);
  105542. int i;
  105543. if(comp){
  105544. if(!out){
  105545. fprintf(stderr,"_book_unquantize incorrectly returned NULL\n");
  105546. exit(1);
  105547. }
  105548. for(i=0;i<b->entries*b->dim;i++)
  105549. if(fabs(out[i]-comp[i])>.0001){
  105550. fprintf(stderr,"disagreement in unquantized and reference data:\n"
  105551. "position %d, %g != %g\n",i,out[i],comp[i]);
  105552. exit(1);
  105553. }
  105554. }else{
  105555. if(out){
  105556. fprintf(stderr,"_book_unquantize returned a value array: \n"
  105557. " correct result should have been NULL\n");
  105558. exit(1);
  105559. }
  105560. }
  105561. }
  105562. int main(){
  105563. fprintf(stderr,"Dequant test 1... ");
  105564. run_test(&test1,test1_result);
  105565. fprintf(stderr,"OK\nDequant test 2... ");
  105566. run_test(&test2,test2_result);
  105567. fprintf(stderr,"OK\nDequant test 3... ");
  105568. run_test(&test3,test3_result);
  105569. fprintf(stderr,"OK\nDequant test 4... ");
  105570. run_test(&test4,test4_result);
  105571. fprintf(stderr,"OK\nDequant test 5... ");
  105572. run_test(&test5,test5_result);
  105573. fprintf(stderr,"OK\n\n");
  105574. return(0);
  105575. }
  105576. #endif
  105577. #endif
  105578. /*** End of inlined file: sharedbook.c ***/
  105579. /*** Start of inlined file: smallft.c ***/
  105580. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  105581. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  105582. // tasks..
  105583. #if JUCE_MSVC
  105584. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  105585. #endif
  105586. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  105587. #if JUCE_USE_OGGVORBIS
  105588. #include <stdlib.h>
  105589. #include <string.h>
  105590. #include <math.h>
  105591. static void drfti1(int n, float *wa, int *ifac){
  105592. static int ntryh[4] = { 4,2,3,5 };
  105593. static float tpi = 6.28318530717958648f;
  105594. float arg,argh,argld,fi;
  105595. int ntry=0,i,j=-1;
  105596. int k1, l1, l2, ib;
  105597. int ld, ii, ip, is, nq, nr;
  105598. int ido, ipm, nfm1;
  105599. int nl=n;
  105600. int nf=0;
  105601. L101:
  105602. j++;
  105603. if (j < 4)
  105604. ntry=ntryh[j];
  105605. else
  105606. ntry+=2;
  105607. L104:
  105608. nq=nl/ntry;
  105609. nr=nl-ntry*nq;
  105610. if (nr!=0) goto L101;
  105611. nf++;
  105612. ifac[nf+1]=ntry;
  105613. nl=nq;
  105614. if(ntry!=2)goto L107;
  105615. if(nf==1)goto L107;
  105616. for (i=1;i<nf;i++){
  105617. ib=nf-i+1;
  105618. ifac[ib+1]=ifac[ib];
  105619. }
  105620. ifac[2] = 2;
  105621. L107:
  105622. if(nl!=1)goto L104;
  105623. ifac[0]=n;
  105624. ifac[1]=nf;
  105625. argh=tpi/n;
  105626. is=0;
  105627. nfm1=nf-1;
  105628. l1=1;
  105629. if(nfm1==0)return;
  105630. for (k1=0;k1<nfm1;k1++){
  105631. ip=ifac[k1+2];
  105632. ld=0;
  105633. l2=l1*ip;
  105634. ido=n/l2;
  105635. ipm=ip-1;
  105636. for (j=0;j<ipm;j++){
  105637. ld+=l1;
  105638. i=is;
  105639. argld=(float)ld*argh;
  105640. fi=0.f;
  105641. for (ii=2;ii<ido;ii+=2){
  105642. fi+=1.f;
  105643. arg=fi*argld;
  105644. wa[i++]=cos(arg);
  105645. wa[i++]=sin(arg);
  105646. }
  105647. is+=ido;
  105648. }
  105649. l1=l2;
  105650. }
  105651. }
  105652. static void fdrffti(int n, float *wsave, int *ifac){
  105653. if (n == 1) return;
  105654. drfti1(n, wsave+n, ifac);
  105655. }
  105656. static void dradf2(int ido,int l1,float *cc,float *ch,float *wa1){
  105657. int i,k;
  105658. float ti2,tr2;
  105659. int t0,t1,t2,t3,t4,t5,t6;
  105660. t1=0;
  105661. t0=(t2=l1*ido);
  105662. t3=ido<<1;
  105663. for(k=0;k<l1;k++){
  105664. ch[t1<<1]=cc[t1]+cc[t2];
  105665. ch[(t1<<1)+t3-1]=cc[t1]-cc[t2];
  105666. t1+=ido;
  105667. t2+=ido;
  105668. }
  105669. if(ido<2)return;
  105670. if(ido==2)goto L105;
  105671. t1=0;
  105672. t2=t0;
  105673. for(k=0;k<l1;k++){
  105674. t3=t2;
  105675. t4=(t1<<1)+(ido<<1);
  105676. t5=t1;
  105677. t6=t1+t1;
  105678. for(i=2;i<ido;i+=2){
  105679. t3+=2;
  105680. t4-=2;
  105681. t5+=2;
  105682. t6+=2;
  105683. tr2=wa1[i-2]*cc[t3-1]+wa1[i-1]*cc[t3];
  105684. ti2=wa1[i-2]*cc[t3]-wa1[i-1]*cc[t3-1];
  105685. ch[t6]=cc[t5]+ti2;
  105686. ch[t4]=ti2-cc[t5];
  105687. ch[t6-1]=cc[t5-1]+tr2;
  105688. ch[t4-1]=cc[t5-1]-tr2;
  105689. }
  105690. t1+=ido;
  105691. t2+=ido;
  105692. }
  105693. if(ido%2==1)return;
  105694. L105:
  105695. t3=(t2=(t1=ido)-1);
  105696. t2+=t0;
  105697. for(k=0;k<l1;k++){
  105698. ch[t1]=-cc[t2];
  105699. ch[t1-1]=cc[t3];
  105700. t1+=ido<<1;
  105701. t2+=ido;
  105702. t3+=ido;
  105703. }
  105704. }
  105705. static void dradf4(int ido,int l1,float *cc,float *ch,float *wa1,
  105706. float *wa2,float *wa3){
  105707. static float hsqt2 = .70710678118654752f;
  105708. int i,k,t0,t1,t2,t3,t4,t5,t6;
  105709. float ci2,ci3,ci4,cr2,cr3,cr4,ti1,ti2,ti3,ti4,tr1,tr2,tr3,tr4;
  105710. t0=l1*ido;
  105711. t1=t0;
  105712. t4=t1<<1;
  105713. t2=t1+(t1<<1);
  105714. t3=0;
  105715. for(k=0;k<l1;k++){
  105716. tr1=cc[t1]+cc[t2];
  105717. tr2=cc[t3]+cc[t4];
  105718. ch[t5=t3<<2]=tr1+tr2;
  105719. ch[(ido<<2)+t5-1]=tr2-tr1;
  105720. ch[(t5+=(ido<<1))-1]=cc[t3]-cc[t4];
  105721. ch[t5]=cc[t2]-cc[t1];
  105722. t1+=ido;
  105723. t2+=ido;
  105724. t3+=ido;
  105725. t4+=ido;
  105726. }
  105727. if(ido<2)return;
  105728. if(ido==2)goto L105;
  105729. t1=0;
  105730. for(k=0;k<l1;k++){
  105731. t2=t1;
  105732. t4=t1<<2;
  105733. t5=(t6=ido<<1)+t4;
  105734. for(i=2;i<ido;i+=2){
  105735. t3=(t2+=2);
  105736. t4+=2;
  105737. t5-=2;
  105738. t3+=t0;
  105739. cr2=wa1[i-2]*cc[t3-1]+wa1[i-1]*cc[t3];
  105740. ci2=wa1[i-2]*cc[t3]-wa1[i-1]*cc[t3-1];
  105741. t3+=t0;
  105742. cr3=wa2[i-2]*cc[t3-1]+wa2[i-1]*cc[t3];
  105743. ci3=wa2[i-2]*cc[t3]-wa2[i-1]*cc[t3-1];
  105744. t3+=t0;
  105745. cr4=wa3[i-2]*cc[t3-1]+wa3[i-1]*cc[t3];
  105746. ci4=wa3[i-2]*cc[t3]-wa3[i-1]*cc[t3-1];
  105747. tr1=cr2+cr4;
  105748. tr4=cr4-cr2;
  105749. ti1=ci2+ci4;
  105750. ti4=ci2-ci4;
  105751. ti2=cc[t2]+ci3;
  105752. ti3=cc[t2]-ci3;
  105753. tr2=cc[t2-1]+cr3;
  105754. tr3=cc[t2-1]-cr3;
  105755. ch[t4-1]=tr1+tr2;
  105756. ch[t4]=ti1+ti2;
  105757. ch[t5-1]=tr3-ti4;
  105758. ch[t5]=tr4-ti3;
  105759. ch[t4+t6-1]=ti4+tr3;
  105760. ch[t4+t6]=tr4+ti3;
  105761. ch[t5+t6-1]=tr2-tr1;
  105762. ch[t5+t6]=ti1-ti2;
  105763. }
  105764. t1+=ido;
  105765. }
  105766. if(ido&1)return;
  105767. L105:
  105768. t2=(t1=t0+ido-1)+(t0<<1);
  105769. t3=ido<<2;
  105770. t4=ido;
  105771. t5=ido<<1;
  105772. t6=ido;
  105773. for(k=0;k<l1;k++){
  105774. ti1=-hsqt2*(cc[t1]+cc[t2]);
  105775. tr1=hsqt2*(cc[t1]-cc[t2]);
  105776. ch[t4-1]=tr1+cc[t6-1];
  105777. ch[t4+t5-1]=cc[t6-1]-tr1;
  105778. ch[t4]=ti1-cc[t1+t0];
  105779. ch[t4+t5]=ti1+cc[t1+t0];
  105780. t1+=ido;
  105781. t2+=ido;
  105782. t4+=t3;
  105783. t6+=ido;
  105784. }
  105785. }
  105786. static void dradfg(int ido,int ip,int l1,int idl1,float *cc,float *c1,
  105787. float *c2,float *ch,float *ch2,float *wa){
  105788. static float tpi=6.283185307179586f;
  105789. int idij,ipph,i,j,k,l,ic,ik,is;
  105790. int t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10;
  105791. float dc2,ai1,ai2,ar1,ar2,ds2;
  105792. int nbd;
  105793. float dcp,arg,dsp,ar1h,ar2h;
  105794. int idp2,ipp2;
  105795. arg=tpi/(float)ip;
  105796. dcp=cos(arg);
  105797. dsp=sin(arg);
  105798. ipph=(ip+1)>>1;
  105799. ipp2=ip;
  105800. idp2=ido;
  105801. nbd=(ido-1)>>1;
  105802. t0=l1*ido;
  105803. t10=ip*ido;
  105804. if(ido==1)goto L119;
  105805. for(ik=0;ik<idl1;ik++)ch2[ik]=c2[ik];
  105806. t1=0;
  105807. for(j=1;j<ip;j++){
  105808. t1+=t0;
  105809. t2=t1;
  105810. for(k=0;k<l1;k++){
  105811. ch[t2]=c1[t2];
  105812. t2+=ido;
  105813. }
  105814. }
  105815. is=-ido;
  105816. t1=0;
  105817. if(nbd>l1){
  105818. for(j=1;j<ip;j++){
  105819. t1+=t0;
  105820. is+=ido;
  105821. t2= -ido+t1;
  105822. for(k=0;k<l1;k++){
  105823. idij=is-1;
  105824. t2+=ido;
  105825. t3=t2;
  105826. for(i=2;i<ido;i+=2){
  105827. idij+=2;
  105828. t3+=2;
  105829. ch[t3-1]=wa[idij-1]*c1[t3-1]+wa[idij]*c1[t3];
  105830. ch[t3]=wa[idij-1]*c1[t3]-wa[idij]*c1[t3-1];
  105831. }
  105832. }
  105833. }
  105834. }else{
  105835. for(j=1;j<ip;j++){
  105836. is+=ido;
  105837. idij=is-1;
  105838. t1+=t0;
  105839. t2=t1;
  105840. for(i=2;i<ido;i+=2){
  105841. idij+=2;
  105842. t2+=2;
  105843. t3=t2;
  105844. for(k=0;k<l1;k++){
  105845. ch[t3-1]=wa[idij-1]*c1[t3-1]+wa[idij]*c1[t3];
  105846. ch[t3]=wa[idij-1]*c1[t3]-wa[idij]*c1[t3-1];
  105847. t3+=ido;
  105848. }
  105849. }
  105850. }
  105851. }
  105852. t1=0;
  105853. t2=ipp2*t0;
  105854. if(nbd<l1){
  105855. for(j=1;j<ipph;j++){
  105856. t1+=t0;
  105857. t2-=t0;
  105858. t3=t1;
  105859. t4=t2;
  105860. for(i=2;i<ido;i+=2){
  105861. t3+=2;
  105862. t4+=2;
  105863. t5=t3-ido;
  105864. t6=t4-ido;
  105865. for(k=0;k<l1;k++){
  105866. t5+=ido;
  105867. t6+=ido;
  105868. c1[t5-1]=ch[t5-1]+ch[t6-1];
  105869. c1[t6-1]=ch[t5]-ch[t6];
  105870. c1[t5]=ch[t5]+ch[t6];
  105871. c1[t6]=ch[t6-1]-ch[t5-1];
  105872. }
  105873. }
  105874. }
  105875. }else{
  105876. for(j=1;j<ipph;j++){
  105877. t1+=t0;
  105878. t2-=t0;
  105879. t3=t1;
  105880. t4=t2;
  105881. for(k=0;k<l1;k++){
  105882. t5=t3;
  105883. t6=t4;
  105884. for(i=2;i<ido;i+=2){
  105885. t5+=2;
  105886. t6+=2;
  105887. c1[t5-1]=ch[t5-1]+ch[t6-1];
  105888. c1[t6-1]=ch[t5]-ch[t6];
  105889. c1[t5]=ch[t5]+ch[t6];
  105890. c1[t6]=ch[t6-1]-ch[t5-1];
  105891. }
  105892. t3+=ido;
  105893. t4+=ido;
  105894. }
  105895. }
  105896. }
  105897. L119:
  105898. for(ik=0;ik<idl1;ik++)c2[ik]=ch2[ik];
  105899. t1=0;
  105900. t2=ipp2*idl1;
  105901. for(j=1;j<ipph;j++){
  105902. t1+=t0;
  105903. t2-=t0;
  105904. t3=t1-ido;
  105905. t4=t2-ido;
  105906. for(k=0;k<l1;k++){
  105907. t3+=ido;
  105908. t4+=ido;
  105909. c1[t3]=ch[t3]+ch[t4];
  105910. c1[t4]=ch[t4]-ch[t3];
  105911. }
  105912. }
  105913. ar1=1.f;
  105914. ai1=0.f;
  105915. t1=0;
  105916. t2=ipp2*idl1;
  105917. t3=(ip-1)*idl1;
  105918. for(l=1;l<ipph;l++){
  105919. t1+=idl1;
  105920. t2-=idl1;
  105921. ar1h=dcp*ar1-dsp*ai1;
  105922. ai1=dcp*ai1+dsp*ar1;
  105923. ar1=ar1h;
  105924. t4=t1;
  105925. t5=t2;
  105926. t6=t3;
  105927. t7=idl1;
  105928. for(ik=0;ik<idl1;ik++){
  105929. ch2[t4++]=c2[ik]+ar1*c2[t7++];
  105930. ch2[t5++]=ai1*c2[t6++];
  105931. }
  105932. dc2=ar1;
  105933. ds2=ai1;
  105934. ar2=ar1;
  105935. ai2=ai1;
  105936. t4=idl1;
  105937. t5=(ipp2-1)*idl1;
  105938. for(j=2;j<ipph;j++){
  105939. t4+=idl1;
  105940. t5-=idl1;
  105941. ar2h=dc2*ar2-ds2*ai2;
  105942. ai2=dc2*ai2+ds2*ar2;
  105943. ar2=ar2h;
  105944. t6=t1;
  105945. t7=t2;
  105946. t8=t4;
  105947. t9=t5;
  105948. for(ik=0;ik<idl1;ik++){
  105949. ch2[t6++]+=ar2*c2[t8++];
  105950. ch2[t7++]+=ai2*c2[t9++];
  105951. }
  105952. }
  105953. }
  105954. t1=0;
  105955. for(j=1;j<ipph;j++){
  105956. t1+=idl1;
  105957. t2=t1;
  105958. for(ik=0;ik<idl1;ik++)ch2[ik]+=c2[t2++];
  105959. }
  105960. if(ido<l1)goto L132;
  105961. t1=0;
  105962. t2=0;
  105963. for(k=0;k<l1;k++){
  105964. t3=t1;
  105965. t4=t2;
  105966. for(i=0;i<ido;i++)cc[t4++]=ch[t3++];
  105967. t1+=ido;
  105968. t2+=t10;
  105969. }
  105970. goto L135;
  105971. L132:
  105972. for(i=0;i<ido;i++){
  105973. t1=i;
  105974. t2=i;
  105975. for(k=0;k<l1;k++){
  105976. cc[t2]=ch[t1];
  105977. t1+=ido;
  105978. t2+=t10;
  105979. }
  105980. }
  105981. L135:
  105982. t1=0;
  105983. t2=ido<<1;
  105984. t3=0;
  105985. t4=ipp2*t0;
  105986. for(j=1;j<ipph;j++){
  105987. t1+=t2;
  105988. t3+=t0;
  105989. t4-=t0;
  105990. t5=t1;
  105991. t6=t3;
  105992. t7=t4;
  105993. for(k=0;k<l1;k++){
  105994. cc[t5-1]=ch[t6];
  105995. cc[t5]=ch[t7];
  105996. t5+=t10;
  105997. t6+=ido;
  105998. t7+=ido;
  105999. }
  106000. }
  106001. if(ido==1)return;
  106002. if(nbd<l1)goto 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. t6=t1;
  106013. t7=t3;
  106014. t8=t4;
  106015. t9=t5;
  106016. for(k=0;k<l1;k++){
  106017. for(i=2;i<ido;i+=2){
  106018. ic=idp2-i;
  106019. cc[i+t7-1]=ch[i+t8-1]+ch[i+t9-1];
  106020. cc[ic+t6-1]=ch[i+t8-1]-ch[i+t9-1];
  106021. cc[i+t7]=ch[i+t8]+ch[i+t9];
  106022. cc[ic+t6]=ch[i+t9]-ch[i+t8];
  106023. }
  106024. t6+=t10;
  106025. t7+=t10;
  106026. t8+=ido;
  106027. t9+=ido;
  106028. }
  106029. }
  106030. return;
  106031. L141:
  106032. t1=-ido;
  106033. t3=0;
  106034. t4=0;
  106035. t5=ipp2*t0;
  106036. for(j=1;j<ipph;j++){
  106037. t1+=t2;
  106038. t3+=t2;
  106039. t4+=t0;
  106040. t5-=t0;
  106041. for(i=2;i<ido;i+=2){
  106042. t6=idp2+t1-i;
  106043. t7=i+t3;
  106044. t8=i+t4;
  106045. t9=i+t5;
  106046. for(k=0;k<l1;k++){
  106047. cc[t7-1]=ch[t8-1]+ch[t9-1];
  106048. cc[t6-1]=ch[t8-1]-ch[t9-1];
  106049. cc[t7]=ch[t8]+ch[t9];
  106050. cc[t6]=ch[t9]-ch[t8];
  106051. t6+=t10;
  106052. t7+=t10;
  106053. t8+=ido;
  106054. t9+=ido;
  106055. }
  106056. }
  106057. }
  106058. }
  106059. static void drftf1(int n,float *c,float *ch,float *wa,int *ifac){
  106060. int i,k1,l1,l2;
  106061. int na,kh,nf;
  106062. int ip,iw,ido,idl1,ix2,ix3;
  106063. nf=ifac[1];
  106064. na=1;
  106065. l2=n;
  106066. iw=n;
  106067. for(k1=0;k1<nf;k1++){
  106068. kh=nf-k1;
  106069. ip=ifac[kh+1];
  106070. l1=l2/ip;
  106071. ido=n/l2;
  106072. idl1=ido*l1;
  106073. iw-=(ip-1)*ido;
  106074. na=1-na;
  106075. if(ip!=4)goto L102;
  106076. ix2=iw+ido;
  106077. ix3=ix2+ido;
  106078. if(na!=0)
  106079. dradf4(ido,l1,ch,c,wa+iw-1,wa+ix2-1,wa+ix3-1);
  106080. else
  106081. dradf4(ido,l1,c,ch,wa+iw-1,wa+ix2-1,wa+ix3-1);
  106082. goto L110;
  106083. L102:
  106084. if(ip!=2)goto L104;
  106085. if(na!=0)goto L103;
  106086. dradf2(ido,l1,c,ch,wa+iw-1);
  106087. goto L110;
  106088. L103:
  106089. dradf2(ido,l1,ch,c,wa+iw-1);
  106090. goto L110;
  106091. L104:
  106092. if(ido==1)na=1-na;
  106093. if(na!=0)goto L109;
  106094. dradfg(ido,ip,l1,idl1,c,c,c,ch,ch,wa+iw-1);
  106095. na=1;
  106096. goto L110;
  106097. L109:
  106098. dradfg(ido,ip,l1,idl1,ch,ch,ch,c,c,wa+iw-1);
  106099. na=0;
  106100. L110:
  106101. l2=l1;
  106102. }
  106103. if(na==1)return;
  106104. for(i=0;i<n;i++)c[i]=ch[i];
  106105. }
  106106. static void dradb2(int ido,int l1,float *cc,float *ch,float *wa1){
  106107. int i,k,t0,t1,t2,t3,t4,t5,t6;
  106108. float ti2,tr2;
  106109. t0=l1*ido;
  106110. t1=0;
  106111. t2=0;
  106112. t3=(ido<<1)-1;
  106113. for(k=0;k<l1;k++){
  106114. ch[t1]=cc[t2]+cc[t3+t2];
  106115. ch[t1+t0]=cc[t2]-cc[t3+t2];
  106116. t2=(t1+=ido)<<1;
  106117. }
  106118. if(ido<2)return;
  106119. if(ido==2)goto L105;
  106120. t1=0;
  106121. t2=0;
  106122. for(k=0;k<l1;k++){
  106123. t3=t1;
  106124. t5=(t4=t2)+(ido<<1);
  106125. t6=t0+t1;
  106126. for(i=2;i<ido;i+=2){
  106127. t3+=2;
  106128. t4+=2;
  106129. t5-=2;
  106130. t6+=2;
  106131. ch[t3-1]=cc[t4-1]+cc[t5-1];
  106132. tr2=cc[t4-1]-cc[t5-1];
  106133. ch[t3]=cc[t4]-cc[t5];
  106134. ti2=cc[t4]+cc[t5];
  106135. ch[t6-1]=wa1[i-2]*tr2-wa1[i-1]*ti2;
  106136. ch[t6]=wa1[i-2]*ti2+wa1[i-1]*tr2;
  106137. }
  106138. t2=(t1+=ido)<<1;
  106139. }
  106140. if(ido%2==1)return;
  106141. L105:
  106142. t1=ido-1;
  106143. t2=ido-1;
  106144. for(k=0;k<l1;k++){
  106145. ch[t1]=cc[t2]+cc[t2];
  106146. ch[t1+t0]=-(cc[t2+1]+cc[t2+1]);
  106147. t1+=ido;
  106148. t2+=ido<<1;
  106149. }
  106150. }
  106151. static void dradb3(int ido,int l1,float *cc,float *ch,float *wa1,
  106152. float *wa2){
  106153. static float taur = -.5f;
  106154. static float taui = .8660254037844386f;
  106155. int i,k,t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10;
  106156. float ci2,ci3,di2,di3,cr2,cr3,dr2,dr3,ti2,tr2;
  106157. t0=l1*ido;
  106158. t1=0;
  106159. t2=t0<<1;
  106160. t3=ido<<1;
  106161. t4=ido+(ido<<1);
  106162. t5=0;
  106163. for(k=0;k<l1;k++){
  106164. tr2=cc[t3-1]+cc[t3-1];
  106165. cr2=cc[t5]+(taur*tr2);
  106166. ch[t1]=cc[t5]+tr2;
  106167. ci3=taui*(cc[t3]+cc[t3]);
  106168. ch[t1+t0]=cr2-ci3;
  106169. ch[t1+t2]=cr2+ci3;
  106170. t1+=ido;
  106171. t3+=t4;
  106172. t5+=t4;
  106173. }
  106174. if(ido==1)return;
  106175. t1=0;
  106176. t3=ido<<1;
  106177. for(k=0;k<l1;k++){
  106178. t7=t1+(t1<<1);
  106179. t6=(t5=t7+t3);
  106180. t8=t1;
  106181. t10=(t9=t1+t0)+t0;
  106182. for(i=2;i<ido;i+=2){
  106183. t5+=2;
  106184. t6-=2;
  106185. t7+=2;
  106186. t8+=2;
  106187. t9+=2;
  106188. t10+=2;
  106189. tr2=cc[t5-1]+cc[t6-1];
  106190. cr2=cc[t7-1]+(taur*tr2);
  106191. ch[t8-1]=cc[t7-1]+tr2;
  106192. ti2=cc[t5]-cc[t6];
  106193. ci2=cc[t7]+(taur*ti2);
  106194. ch[t8]=cc[t7]+ti2;
  106195. cr3=taui*(cc[t5-1]-cc[t6-1]);
  106196. ci3=taui*(cc[t5]+cc[t6]);
  106197. dr2=cr2-ci3;
  106198. dr3=cr2+ci3;
  106199. di2=ci2+cr3;
  106200. di3=ci2-cr3;
  106201. ch[t9-1]=wa1[i-2]*dr2-wa1[i-1]*di2;
  106202. ch[t9]=wa1[i-2]*di2+wa1[i-1]*dr2;
  106203. ch[t10-1]=wa2[i-2]*dr3-wa2[i-1]*di3;
  106204. ch[t10]=wa2[i-2]*di3+wa2[i-1]*dr3;
  106205. }
  106206. t1+=ido;
  106207. }
  106208. }
  106209. static void dradb4(int ido,int l1,float *cc,float *ch,float *wa1,
  106210. float *wa2,float *wa3){
  106211. static float sqrt2=1.414213562373095f;
  106212. int i,k,t0,t1,t2,t3,t4,t5,t6,t7,t8;
  106213. float ci2,ci3,ci4,cr2,cr3,cr4,ti1,ti2,ti3,ti4,tr1,tr2,tr3,tr4;
  106214. t0=l1*ido;
  106215. t1=0;
  106216. t2=ido<<2;
  106217. t3=0;
  106218. t6=ido<<1;
  106219. for(k=0;k<l1;k++){
  106220. t4=t3+t6;
  106221. t5=t1;
  106222. tr3=cc[t4-1]+cc[t4-1];
  106223. tr4=cc[t4]+cc[t4];
  106224. tr1=cc[t3]-cc[(t4+=t6)-1];
  106225. tr2=cc[t3]+cc[t4-1];
  106226. ch[t5]=tr2+tr3;
  106227. ch[t5+=t0]=tr1-tr4;
  106228. ch[t5+=t0]=tr2-tr3;
  106229. ch[t5+=t0]=tr1+tr4;
  106230. t1+=ido;
  106231. t3+=t2;
  106232. }
  106233. if(ido<2)return;
  106234. if(ido==2)goto L105;
  106235. t1=0;
  106236. for(k=0;k<l1;k++){
  106237. t5=(t4=(t3=(t2=t1<<2)+t6))+t6;
  106238. t7=t1;
  106239. for(i=2;i<ido;i+=2){
  106240. t2+=2;
  106241. t3+=2;
  106242. t4-=2;
  106243. t5-=2;
  106244. t7+=2;
  106245. ti1=cc[t2]+cc[t5];
  106246. ti2=cc[t2]-cc[t5];
  106247. ti3=cc[t3]-cc[t4];
  106248. tr4=cc[t3]+cc[t4];
  106249. tr1=cc[t2-1]-cc[t5-1];
  106250. tr2=cc[t2-1]+cc[t5-1];
  106251. ti4=cc[t3-1]-cc[t4-1];
  106252. tr3=cc[t3-1]+cc[t4-1];
  106253. ch[t7-1]=tr2+tr3;
  106254. cr3=tr2-tr3;
  106255. ch[t7]=ti2+ti3;
  106256. ci3=ti2-ti3;
  106257. cr2=tr1-tr4;
  106258. cr4=tr1+tr4;
  106259. ci2=ti1+ti4;
  106260. ci4=ti1-ti4;
  106261. ch[(t8=t7+t0)-1]=wa1[i-2]*cr2-wa1[i-1]*ci2;
  106262. ch[t8]=wa1[i-2]*ci2+wa1[i-1]*cr2;
  106263. ch[(t8+=t0)-1]=wa2[i-2]*cr3-wa2[i-1]*ci3;
  106264. ch[t8]=wa2[i-2]*ci3+wa2[i-1]*cr3;
  106265. ch[(t8+=t0)-1]=wa3[i-2]*cr4-wa3[i-1]*ci4;
  106266. ch[t8]=wa3[i-2]*ci4+wa3[i-1]*cr4;
  106267. }
  106268. t1+=ido;
  106269. }
  106270. if(ido%2 == 1)return;
  106271. L105:
  106272. t1=ido;
  106273. t2=ido<<2;
  106274. t3=ido-1;
  106275. t4=ido+(ido<<1);
  106276. for(k=0;k<l1;k++){
  106277. t5=t3;
  106278. ti1=cc[t1]+cc[t4];
  106279. ti2=cc[t4]-cc[t1];
  106280. tr1=cc[t1-1]-cc[t4-1];
  106281. tr2=cc[t1-1]+cc[t4-1];
  106282. ch[t5]=tr2+tr2;
  106283. ch[t5+=t0]=sqrt2*(tr1-ti1);
  106284. ch[t5+=t0]=ti2+ti2;
  106285. ch[t5+=t0]=-sqrt2*(tr1+ti1);
  106286. t3+=ido;
  106287. t1+=t2;
  106288. t4+=t2;
  106289. }
  106290. }
  106291. static void dradbg(int ido,int ip,int l1,int idl1,float *cc,float *c1,
  106292. float *c2,float *ch,float *ch2,float *wa){
  106293. static float tpi=6.283185307179586f;
  106294. int idij,ipph,i,j,k,l,ik,is,t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,
  106295. t11,t12;
  106296. float dc2,ai1,ai2,ar1,ar2,ds2;
  106297. int nbd;
  106298. float dcp,arg,dsp,ar1h,ar2h;
  106299. int ipp2;
  106300. t10=ip*ido;
  106301. t0=l1*ido;
  106302. arg=tpi/(float)ip;
  106303. dcp=cos(arg);
  106304. dsp=sin(arg);
  106305. nbd=(ido-1)>>1;
  106306. ipp2=ip;
  106307. ipph=(ip+1)>>1;
  106308. if(ido<l1)goto L103;
  106309. t1=0;
  106310. t2=0;
  106311. for(k=0;k<l1;k++){
  106312. t3=t1;
  106313. t4=t2;
  106314. for(i=0;i<ido;i++){
  106315. ch[t3]=cc[t4];
  106316. t3++;
  106317. t4++;
  106318. }
  106319. t1+=ido;
  106320. t2+=t10;
  106321. }
  106322. goto L106;
  106323. L103:
  106324. t1=0;
  106325. for(i=0;i<ido;i++){
  106326. t2=t1;
  106327. t3=t1;
  106328. for(k=0;k<l1;k++){
  106329. ch[t2]=cc[t3];
  106330. t2+=ido;
  106331. t3+=t10;
  106332. }
  106333. t1++;
  106334. }
  106335. L106:
  106336. t1=0;
  106337. t2=ipp2*t0;
  106338. t7=(t5=ido<<1);
  106339. for(j=1;j<ipph;j++){
  106340. t1+=t0;
  106341. t2-=t0;
  106342. t3=t1;
  106343. t4=t2;
  106344. t6=t5;
  106345. for(k=0;k<l1;k++){
  106346. ch[t3]=cc[t6-1]+cc[t6-1];
  106347. ch[t4]=cc[t6]+cc[t6];
  106348. t3+=ido;
  106349. t4+=ido;
  106350. t6+=t10;
  106351. }
  106352. t5+=t7;
  106353. }
  106354. if (ido == 1)goto L116;
  106355. if(nbd<l1)goto L112;
  106356. t1=0;
  106357. t2=ipp2*t0;
  106358. t7=0;
  106359. for(j=1;j<ipph;j++){
  106360. t1+=t0;
  106361. t2-=t0;
  106362. t3=t1;
  106363. t4=t2;
  106364. t7+=(ido<<1);
  106365. t8=t7;
  106366. for(k=0;k<l1;k++){
  106367. t5=t3;
  106368. t6=t4;
  106369. t9=t8;
  106370. t11=t8;
  106371. for(i=2;i<ido;i+=2){
  106372. t5+=2;
  106373. t6+=2;
  106374. t9+=2;
  106375. t11-=2;
  106376. ch[t5-1]=cc[t9-1]+cc[t11-1];
  106377. ch[t6-1]=cc[t9-1]-cc[t11-1];
  106378. ch[t5]=cc[t9]-cc[t11];
  106379. ch[t6]=cc[t9]+cc[t11];
  106380. }
  106381. t3+=ido;
  106382. t4+=ido;
  106383. t8+=t10;
  106384. }
  106385. }
  106386. goto L116;
  106387. L112:
  106388. t1=0;
  106389. t2=ipp2*t0;
  106390. t7=0;
  106391. for(j=1;j<ipph;j++){
  106392. t1+=t0;
  106393. t2-=t0;
  106394. t3=t1;
  106395. t4=t2;
  106396. t7+=(ido<<1);
  106397. t8=t7;
  106398. t9=t7;
  106399. for(i=2;i<ido;i+=2){
  106400. t3+=2;
  106401. t4+=2;
  106402. t8+=2;
  106403. t9-=2;
  106404. t5=t3;
  106405. t6=t4;
  106406. t11=t8;
  106407. t12=t9;
  106408. for(k=0;k<l1;k++){
  106409. ch[t5-1]=cc[t11-1]+cc[t12-1];
  106410. ch[t6-1]=cc[t11-1]-cc[t12-1];
  106411. ch[t5]=cc[t11]-cc[t12];
  106412. ch[t6]=cc[t11]+cc[t12];
  106413. t5+=ido;
  106414. t6+=ido;
  106415. t11+=t10;
  106416. t12+=t10;
  106417. }
  106418. }
  106419. }
  106420. L116:
  106421. ar1=1.f;
  106422. ai1=0.f;
  106423. t1=0;
  106424. t9=(t2=ipp2*idl1);
  106425. t3=(ip-1)*idl1;
  106426. for(l=1;l<ipph;l++){
  106427. t1+=idl1;
  106428. t2-=idl1;
  106429. ar1h=dcp*ar1-dsp*ai1;
  106430. ai1=dcp*ai1+dsp*ar1;
  106431. ar1=ar1h;
  106432. t4=t1;
  106433. t5=t2;
  106434. t6=0;
  106435. t7=idl1;
  106436. t8=t3;
  106437. for(ik=0;ik<idl1;ik++){
  106438. c2[t4++]=ch2[t6++]+ar1*ch2[t7++];
  106439. c2[t5++]=ai1*ch2[t8++];
  106440. }
  106441. dc2=ar1;
  106442. ds2=ai1;
  106443. ar2=ar1;
  106444. ai2=ai1;
  106445. t6=idl1;
  106446. t7=t9-idl1;
  106447. for(j=2;j<ipph;j++){
  106448. t6+=idl1;
  106449. t7-=idl1;
  106450. ar2h=dc2*ar2-ds2*ai2;
  106451. ai2=dc2*ai2+ds2*ar2;
  106452. ar2=ar2h;
  106453. t4=t1;
  106454. t5=t2;
  106455. t11=t6;
  106456. t12=t7;
  106457. for(ik=0;ik<idl1;ik++){
  106458. c2[t4++]+=ar2*ch2[t11++];
  106459. c2[t5++]+=ai2*ch2[t12++];
  106460. }
  106461. }
  106462. }
  106463. t1=0;
  106464. for(j=1;j<ipph;j++){
  106465. t1+=idl1;
  106466. t2=t1;
  106467. for(ik=0;ik<idl1;ik++)ch2[ik]+=ch2[t2++];
  106468. }
  106469. t1=0;
  106470. t2=ipp2*t0;
  106471. for(j=1;j<ipph;j++){
  106472. t1+=t0;
  106473. t2-=t0;
  106474. t3=t1;
  106475. t4=t2;
  106476. for(k=0;k<l1;k++){
  106477. ch[t3]=c1[t3]-c1[t4];
  106478. ch[t4]=c1[t3]+c1[t4];
  106479. t3+=ido;
  106480. t4+=ido;
  106481. }
  106482. }
  106483. if(ido==1)goto L132;
  106484. if(nbd<l1)goto L128;
  106485. t1=0;
  106486. t2=ipp2*t0;
  106487. for(j=1;j<ipph;j++){
  106488. t1+=t0;
  106489. t2-=t0;
  106490. t3=t1;
  106491. t4=t2;
  106492. for(k=0;k<l1;k++){
  106493. t5=t3;
  106494. t6=t4;
  106495. for(i=2;i<ido;i+=2){
  106496. t5+=2;
  106497. t6+=2;
  106498. ch[t5-1]=c1[t5-1]-c1[t6];
  106499. ch[t6-1]=c1[t5-1]+c1[t6];
  106500. ch[t5]=c1[t5]+c1[t6-1];
  106501. ch[t6]=c1[t5]-c1[t6-1];
  106502. }
  106503. t3+=ido;
  106504. t4+=ido;
  106505. }
  106506. }
  106507. goto L132;
  106508. L128:
  106509. t1=0;
  106510. t2=ipp2*t0;
  106511. for(j=1;j<ipph;j++){
  106512. t1+=t0;
  106513. t2-=t0;
  106514. t3=t1;
  106515. t4=t2;
  106516. for(i=2;i<ido;i+=2){
  106517. t3+=2;
  106518. t4+=2;
  106519. t5=t3;
  106520. t6=t4;
  106521. for(k=0;k<l1;k++){
  106522. ch[t5-1]=c1[t5-1]-c1[t6];
  106523. ch[t6-1]=c1[t5-1]+c1[t6];
  106524. ch[t5]=c1[t5]+c1[t6-1];
  106525. ch[t6]=c1[t5]-c1[t6-1];
  106526. t5+=ido;
  106527. t6+=ido;
  106528. }
  106529. }
  106530. }
  106531. L132:
  106532. if(ido==1)return;
  106533. for(ik=0;ik<idl1;ik++)c2[ik]=ch2[ik];
  106534. t1=0;
  106535. for(j=1;j<ip;j++){
  106536. t2=(t1+=t0);
  106537. for(k=0;k<l1;k++){
  106538. c1[t2]=ch[t2];
  106539. t2+=ido;
  106540. }
  106541. }
  106542. if(nbd>l1)goto L139;
  106543. is= -ido-1;
  106544. t1=0;
  106545. for(j=1;j<ip;j++){
  106546. is+=ido;
  106547. t1+=t0;
  106548. idij=is;
  106549. t2=t1;
  106550. for(i=2;i<ido;i+=2){
  106551. t2+=2;
  106552. idij+=2;
  106553. t3=t2;
  106554. for(k=0;k<l1;k++){
  106555. c1[t3-1]=wa[idij-1]*ch[t3-1]-wa[idij]*ch[t3];
  106556. c1[t3]=wa[idij-1]*ch[t3]+wa[idij]*ch[t3-1];
  106557. t3+=ido;
  106558. }
  106559. }
  106560. }
  106561. return;
  106562. L139:
  106563. is= -ido-1;
  106564. t1=0;
  106565. for(j=1;j<ip;j++){
  106566. is+=ido;
  106567. t1+=t0;
  106568. t2=t1;
  106569. for(k=0;k<l1;k++){
  106570. idij=is;
  106571. t3=t2;
  106572. for(i=2;i<ido;i+=2){
  106573. idij+=2;
  106574. t3+=2;
  106575. c1[t3-1]=wa[idij-1]*ch[t3-1]-wa[idij]*ch[t3];
  106576. c1[t3]=wa[idij-1]*ch[t3]+wa[idij]*ch[t3-1];
  106577. }
  106578. t2+=ido;
  106579. }
  106580. }
  106581. }
  106582. static void drftb1(int n, float *c, float *ch, float *wa, int *ifac){
  106583. int i,k1,l1,l2;
  106584. int na;
  106585. int nf,ip,iw,ix2,ix3,ido,idl1;
  106586. nf=ifac[1];
  106587. na=0;
  106588. l1=1;
  106589. iw=1;
  106590. for(k1=0;k1<nf;k1++){
  106591. ip=ifac[k1 + 2];
  106592. l2=ip*l1;
  106593. ido=n/l2;
  106594. idl1=ido*l1;
  106595. if(ip!=4)goto L103;
  106596. ix2=iw+ido;
  106597. ix3=ix2+ido;
  106598. if(na!=0)
  106599. dradb4(ido,l1,ch,c,wa+iw-1,wa+ix2-1,wa+ix3-1);
  106600. else
  106601. dradb4(ido,l1,c,ch,wa+iw-1,wa+ix2-1,wa+ix3-1);
  106602. na=1-na;
  106603. goto L115;
  106604. L103:
  106605. if(ip!=2)goto L106;
  106606. if(na!=0)
  106607. dradb2(ido,l1,ch,c,wa+iw-1);
  106608. else
  106609. dradb2(ido,l1,c,ch,wa+iw-1);
  106610. na=1-na;
  106611. goto L115;
  106612. L106:
  106613. if(ip!=3)goto L109;
  106614. ix2=iw+ido;
  106615. if(na!=0)
  106616. dradb3(ido,l1,ch,c,wa+iw-1,wa+ix2-1);
  106617. else
  106618. dradb3(ido,l1,c,ch,wa+iw-1,wa+ix2-1);
  106619. na=1-na;
  106620. goto L115;
  106621. L109:
  106622. if(na!=0)
  106623. dradbg(ido,ip,l1,idl1,ch,ch,ch,c,c,wa+iw-1);
  106624. else
  106625. dradbg(ido,ip,l1,idl1,c,c,c,ch,ch,wa+iw-1);
  106626. if(ido==1)na=1-na;
  106627. L115:
  106628. l1=l2;
  106629. iw+=(ip-1)*ido;
  106630. }
  106631. if(na==0)return;
  106632. for(i=0;i<n;i++)c[i]=ch[i];
  106633. }
  106634. void drft_forward(drft_lookup *l,float *data){
  106635. if(l->n==1)return;
  106636. drftf1(l->n,data,l->trigcache,l->trigcache+l->n,l->splitcache);
  106637. }
  106638. void drft_backward(drft_lookup *l,float *data){
  106639. if (l->n==1)return;
  106640. drftb1(l->n,data,l->trigcache,l->trigcache+l->n,l->splitcache);
  106641. }
  106642. void drft_init(drft_lookup *l,int n){
  106643. l->n=n;
  106644. l->trigcache=(float*)_ogg_calloc(3*n,sizeof(*l->trigcache));
  106645. l->splitcache=(int*)_ogg_calloc(32,sizeof(*l->splitcache));
  106646. fdrffti(n, l->trigcache, l->splitcache);
  106647. }
  106648. void drft_clear(drft_lookup *l){
  106649. if(l){
  106650. if(l->trigcache)_ogg_free(l->trigcache);
  106651. if(l->splitcache)_ogg_free(l->splitcache);
  106652. memset(l,0,sizeof(*l));
  106653. }
  106654. }
  106655. #endif
  106656. /*** End of inlined file: smallft.c ***/
  106657. /*** Start of inlined file: synthesis.c ***/
  106658. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  106659. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  106660. // tasks..
  106661. #if JUCE_MSVC
  106662. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  106663. #endif
  106664. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  106665. #if JUCE_USE_OGGVORBIS
  106666. #include <stdio.h>
  106667. int vorbis_synthesis(vorbis_block *vb,ogg_packet *op){
  106668. vorbis_dsp_state *vd=vb->vd;
  106669. private_state *b=(private_state*)vd->backend_state;
  106670. vorbis_info *vi=vd->vi;
  106671. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  106672. oggpack_buffer *opb=&vb->opb;
  106673. int type,mode,i;
  106674. _vorbis_block_ripcord(vb);
  106675. oggpack_readinit(opb,op->packet,op->bytes);
  106676. if(oggpack_read(opb,1)!=0){
  106677. return(OV_ENOTAUDIO);
  106678. }
  106679. mode=oggpack_read(opb,b->modebits);
  106680. if(mode==-1)return(OV_EBADPACKET);
  106681. vb->mode=mode;
  106682. vb->W=ci->mode_param[mode]->blockflag;
  106683. if(vb->W){
  106684. vb->lW=oggpack_read(opb,1);
  106685. vb->nW=oggpack_read(opb,1);
  106686. if(vb->nW==-1) return(OV_EBADPACKET);
  106687. }else{
  106688. vb->lW=0;
  106689. vb->nW=0;
  106690. }
  106691. vb->granulepos=op->granulepos;
  106692. vb->sequence=op->packetno;
  106693. vb->eofflag=op->e_o_s;
  106694. vb->pcmend=ci->blocksizes[vb->W];
  106695. vb->pcm=(float**)_vorbis_block_alloc(vb,sizeof(*vb->pcm)*vi->channels);
  106696. for(i=0;i<vi->channels;i++)
  106697. vb->pcm[i]=(float*)_vorbis_block_alloc(vb,vb->pcmend*sizeof(*vb->pcm[i]));
  106698. type=ci->map_type[ci->mode_param[mode]->mapping];
  106699. return(_mapping_P[type]->inverse(vb,ci->map_param[ci->mode_param[mode]->
  106700. mapping]));
  106701. }
  106702. int vorbis_synthesis_trackonly(vorbis_block *vb,ogg_packet *op){
  106703. vorbis_dsp_state *vd=vb->vd;
  106704. private_state *b=(private_state*)vd->backend_state;
  106705. vorbis_info *vi=vd->vi;
  106706. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  106707. oggpack_buffer *opb=&vb->opb;
  106708. int mode;
  106709. _vorbis_block_ripcord(vb);
  106710. oggpack_readinit(opb,op->packet,op->bytes);
  106711. if(oggpack_read(opb,1)!=0){
  106712. return(OV_ENOTAUDIO);
  106713. }
  106714. mode=oggpack_read(opb,b->modebits);
  106715. if(mode==-1)return(OV_EBADPACKET);
  106716. vb->mode=mode;
  106717. vb->W=ci->mode_param[mode]->blockflag;
  106718. if(vb->W){
  106719. vb->lW=oggpack_read(opb,1);
  106720. vb->nW=oggpack_read(opb,1);
  106721. if(vb->nW==-1) return(OV_EBADPACKET);
  106722. }else{
  106723. vb->lW=0;
  106724. vb->nW=0;
  106725. }
  106726. vb->granulepos=op->granulepos;
  106727. vb->sequence=op->packetno;
  106728. vb->eofflag=op->e_o_s;
  106729. vb->pcmend=0;
  106730. vb->pcm=NULL;
  106731. return(0);
  106732. }
  106733. long vorbis_packet_blocksize(vorbis_info *vi,ogg_packet *op){
  106734. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  106735. oggpack_buffer opb;
  106736. int mode;
  106737. oggpack_readinit(&opb,op->packet,op->bytes);
  106738. if(oggpack_read(&opb,1)!=0){
  106739. return(OV_ENOTAUDIO);
  106740. }
  106741. {
  106742. int modebits=0;
  106743. int v=ci->modes;
  106744. while(v>1){
  106745. modebits++;
  106746. v>>=1;
  106747. }
  106748. mode=oggpack_read(&opb,modebits);
  106749. }
  106750. if(mode==-1)return(OV_EBADPACKET);
  106751. return(ci->blocksizes[ci->mode_param[mode]->blockflag]);
  106752. }
  106753. int vorbis_synthesis_halfrate(vorbis_info *vi,int flag){
  106754. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  106755. if(ci->blocksizes[0]<=64 && flag)return -1;
  106756. ci->halfrate_flag=(flag?1:0);
  106757. return 0;
  106758. }
  106759. int vorbis_synthesis_halfrate_p(vorbis_info *vi){
  106760. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  106761. return ci->halfrate_flag;
  106762. }
  106763. #endif
  106764. /*** End of inlined file: synthesis.c ***/
  106765. /*** Start of inlined file: vorbisenc.c ***/
  106766. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  106767. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  106768. // tasks..
  106769. #if JUCE_MSVC
  106770. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  106771. #endif
  106772. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  106773. #if JUCE_USE_OGGVORBIS
  106774. #include <stdlib.h>
  106775. #include <string.h>
  106776. #include <math.h>
  106777. typedef struct {
  106778. static_codebook *books[12][3];
  106779. } static_bookblock;
  106780. typedef struct {
  106781. int res_type;
  106782. int limit_type; /* 0 lowpass limited, 1 point stereo limited */
  106783. vorbis_info_residue0 *res;
  106784. static_codebook *book_aux;
  106785. static_codebook *book_aux_managed;
  106786. static_bookblock *books_base;
  106787. static_bookblock *books_base_managed;
  106788. } vorbis_residue_template;
  106789. typedef struct {
  106790. vorbis_info_mapping0 *map;
  106791. vorbis_residue_template *res;
  106792. } vorbis_mapping_template;
  106793. typedef struct vp_adjblock{
  106794. int block[P_BANDS];
  106795. } vp_adjblock;
  106796. typedef struct {
  106797. int data[NOISE_COMPAND_LEVELS];
  106798. } compandblock;
  106799. typedef struct {
  106800. int att[P_NOISECURVES];
  106801. float boost;
  106802. float decay;
  106803. } att3;
  106804. typedef struct { int data[P_NOISECURVES]; } adj3;
  106805. typedef struct {
  106806. int pre[PACKETBLOBS];
  106807. int post[PACKETBLOBS];
  106808. float kHz[PACKETBLOBS];
  106809. float lowpasskHz[PACKETBLOBS];
  106810. } adj_stereo;
  106811. typedef struct {
  106812. int lo;
  106813. int hi;
  106814. int fixed;
  106815. } noiseguard;
  106816. typedef struct {
  106817. int data[P_NOISECURVES][17];
  106818. } noise3;
  106819. typedef struct {
  106820. int mappings;
  106821. double *rate_mapping;
  106822. double *quality_mapping;
  106823. int coupling_restriction;
  106824. long samplerate_min_restriction;
  106825. long samplerate_max_restriction;
  106826. int *blocksize_short;
  106827. int *blocksize_long;
  106828. att3 *psy_tone_masteratt;
  106829. int *psy_tone_0dB;
  106830. int *psy_tone_dBsuppress;
  106831. vp_adjblock *psy_tone_adj_impulse;
  106832. vp_adjblock *psy_tone_adj_long;
  106833. vp_adjblock *psy_tone_adj_other;
  106834. noiseguard *psy_noiseguards;
  106835. noise3 *psy_noise_bias_impulse;
  106836. noise3 *psy_noise_bias_padding;
  106837. noise3 *psy_noise_bias_trans;
  106838. noise3 *psy_noise_bias_long;
  106839. int *psy_noise_dBsuppress;
  106840. compandblock *psy_noise_compand;
  106841. double *psy_noise_compand_short_mapping;
  106842. double *psy_noise_compand_long_mapping;
  106843. int *psy_noise_normal_start[2];
  106844. int *psy_noise_normal_partition[2];
  106845. double *psy_noise_normal_thresh;
  106846. int *psy_ath_float;
  106847. int *psy_ath_abs;
  106848. double *psy_lowpass;
  106849. vorbis_info_psy_global *global_params;
  106850. double *global_mapping;
  106851. adj_stereo *stereo_modes;
  106852. static_codebook ***floor_books;
  106853. vorbis_info_floor1 *floor_params;
  106854. int *floor_short_mapping;
  106855. int *floor_long_mapping;
  106856. vorbis_mapping_template *maps;
  106857. } ve_setup_data_template;
  106858. static vorbis_info_mode _mode_template[2]={
  106859. {0,0,0,0},
  106860. {1,0,0,1}
  106861. };
  106862. static vorbis_info_mapping0 _map_nominal[2]={
  106863. {1, {0,0}, {0}, {0}, 1,{0},{1}},
  106864. {1, {0,0}, {1}, {1}, 1,{0},{1}}
  106865. };
  106866. /*** Start of inlined file: setup_44.h ***/
  106867. /*** Start of inlined file: floor_all.h ***/
  106868. /*** Start of inlined file: floor_books.h ***/
  106869. static long _huff_lengthlist_line_256x7_0sub1[] = {
  106870. 0, 2, 3, 3, 3, 3, 4, 3, 4,
  106871. };
  106872. static static_codebook _huff_book_line_256x7_0sub1 = {
  106873. 1, 9,
  106874. _huff_lengthlist_line_256x7_0sub1,
  106875. 0, 0, 0, 0, 0,
  106876. NULL,
  106877. NULL,
  106878. NULL,
  106879. NULL,
  106880. 0
  106881. };
  106882. static long _huff_lengthlist_line_256x7_0sub2[] = {
  106883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 4, 3, 4, 3, 5, 3,
  106884. 6, 3, 6, 4, 6, 4, 7, 5, 7,
  106885. };
  106886. static static_codebook _huff_book_line_256x7_0sub2 = {
  106887. 1, 25,
  106888. _huff_lengthlist_line_256x7_0sub2,
  106889. 0, 0, 0, 0, 0,
  106890. NULL,
  106891. NULL,
  106892. NULL,
  106893. NULL,
  106894. 0
  106895. };
  106896. static long _huff_lengthlist_line_256x7_0sub3[] = {
  106897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 2, 5, 3, 5, 3,
  106899. 6, 3, 6, 4, 7, 6, 7, 8, 7, 9, 8, 9, 9, 9,10, 9,
  106900. 11,13,11,13,10,10,13,13,13,13,13,13,12,12,12,12,
  106901. };
  106902. static static_codebook _huff_book_line_256x7_0sub3 = {
  106903. 1, 64,
  106904. _huff_lengthlist_line_256x7_0sub3,
  106905. 0, 0, 0, 0, 0,
  106906. NULL,
  106907. NULL,
  106908. NULL,
  106909. NULL,
  106910. 0
  106911. };
  106912. static long _huff_lengthlist_line_256x7_1sub1[] = {
  106913. 0, 3, 3, 3, 3, 2, 4, 3, 4,
  106914. };
  106915. static static_codebook _huff_book_line_256x7_1sub1 = {
  106916. 1, 9,
  106917. _huff_lengthlist_line_256x7_1sub1,
  106918. 0, 0, 0, 0, 0,
  106919. NULL,
  106920. NULL,
  106921. NULL,
  106922. NULL,
  106923. 0
  106924. };
  106925. static long _huff_lengthlist_line_256x7_1sub2[] = {
  106926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 3, 4, 3, 4, 4,
  106927. 5, 4, 6, 5, 6, 7, 6, 8, 8,
  106928. };
  106929. static static_codebook _huff_book_line_256x7_1sub2 = {
  106930. 1, 25,
  106931. _huff_lengthlist_line_256x7_1sub2,
  106932. 0, 0, 0, 0, 0,
  106933. NULL,
  106934. NULL,
  106935. NULL,
  106936. NULL,
  106937. 0
  106938. };
  106939. static long _huff_lengthlist_line_256x7_1sub3[] = {
  106940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 2, 4, 3, 6, 3, 7,
  106942. 3, 8, 5, 8, 6, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  106943. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7,
  106944. };
  106945. static static_codebook _huff_book_line_256x7_1sub3 = {
  106946. 1, 64,
  106947. _huff_lengthlist_line_256x7_1sub3,
  106948. 0, 0, 0, 0, 0,
  106949. NULL,
  106950. NULL,
  106951. NULL,
  106952. NULL,
  106953. 0
  106954. };
  106955. static long _huff_lengthlist_line_256x7_class0[] = {
  106956. 7, 5, 5, 9, 9, 6, 6, 9,12, 8, 7, 8,11, 8, 9,15,
  106957. 6, 3, 3, 7, 7, 4, 3, 6, 9, 6, 5, 6, 8, 6, 8,15,
  106958. 8, 5, 5, 9, 8, 5, 4, 6,10, 7, 5, 5,11, 8, 7,15,
  106959. 14,15,13,13,13,13, 8,11,15,10, 7, 6,11, 9,10,15,
  106960. };
  106961. static static_codebook _huff_book_line_256x7_class0 = {
  106962. 1, 64,
  106963. _huff_lengthlist_line_256x7_class0,
  106964. 0, 0, 0, 0, 0,
  106965. NULL,
  106966. NULL,
  106967. NULL,
  106968. NULL,
  106969. 0
  106970. };
  106971. static long _huff_lengthlist_line_256x7_class1[] = {
  106972. 5, 6, 8,15, 6, 9,10,15,10,11,12,15,15,15,15,15,
  106973. 4, 6, 7,15, 6, 7, 8,15, 9, 8, 9,15,15,15,15,15,
  106974. 6, 8, 9,15, 7, 7, 8,15,10, 9,10,15,15,15,15,15,
  106975. 15,13,15,15,15,10,11,15,15,13,13,15,15,15,15,15,
  106976. 4, 6, 7,15, 6, 8, 9,15,10,10,12,15,15,15,15,15,
  106977. 2, 5, 6,15, 5, 6, 7,15, 8, 6, 7,15,15,15,15,15,
  106978. 5, 6, 8,15, 5, 6, 7,15, 9, 6, 7,15,15,15,15,15,
  106979. 14,12,13,15,12,10,11,15,15,15,15,15,15,15,15,15,
  106980. 7, 8, 9,15, 9,10,10,15,15,14,14,15,15,15,15,15,
  106981. 5, 6, 7,15, 7, 8, 9,15,12, 9,10,15,15,15,15,15,
  106982. 7, 7, 9,15, 7, 7, 8,15,12, 8, 9,15,15,15,15,15,
  106983. 13,13,14,15,12,11,12,15,15,15,15,15,15,15,15,15,
  106984. 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
  106985. 13,13,13,15,15,15,15,15,15,15,15,15,15,15,15,15,
  106986. 15,12,13,15,15,12,13,15,15,14,15,15,15,15,15,15,
  106987. 15,15,15,15,15,15,13,15,15,15,15,15,15,15,15,15,
  106988. };
  106989. static static_codebook _huff_book_line_256x7_class1 = {
  106990. 1, 256,
  106991. _huff_lengthlist_line_256x7_class1,
  106992. 0, 0, 0, 0, 0,
  106993. NULL,
  106994. NULL,
  106995. NULL,
  106996. NULL,
  106997. 0
  106998. };
  106999. static long _huff_lengthlist_line_512x17_0sub0[] = {
  107000. 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
  107001. 5, 6, 5, 6, 6, 6, 6, 5, 6, 6, 7, 6, 7, 6, 7, 6,
  107002. 7, 6, 8, 7, 8, 7, 8, 7, 8, 7, 8, 7, 9, 7, 9, 7,
  107003. 9, 7, 9, 8, 9, 8,10, 8,10, 8,10, 7,10, 6,10, 8,
  107004. 10, 8,11, 7,10, 7,11, 8,11,11,12,12,11,11,12,11,
  107005. 13,11,13,11,13,12,15,12,13,13,14,14,14,14,14,15,
  107006. 15,15,16,14,17,19,19,18,18,18,18,18,18,18,18,18,
  107007. 18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,
  107008. };
  107009. static static_codebook _huff_book_line_512x17_0sub0 = {
  107010. 1, 128,
  107011. _huff_lengthlist_line_512x17_0sub0,
  107012. 0, 0, 0, 0, 0,
  107013. NULL,
  107014. NULL,
  107015. NULL,
  107016. NULL,
  107017. 0
  107018. };
  107019. static long _huff_lengthlist_line_512x17_1sub0[] = {
  107020. 2, 4, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 5, 5, 6, 5,
  107021. 6, 5, 6, 6, 7, 6, 7, 6, 8, 7, 8, 7, 8, 7, 8, 7,
  107022. };
  107023. static static_codebook _huff_book_line_512x17_1sub0 = {
  107024. 1, 32,
  107025. _huff_lengthlist_line_512x17_1sub0,
  107026. 0, 0, 0, 0, 0,
  107027. NULL,
  107028. NULL,
  107029. NULL,
  107030. NULL,
  107031. 0
  107032. };
  107033. static long _huff_lengthlist_line_512x17_1sub1[] = {
  107034. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107035. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107036. 4, 3, 5, 3, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 6, 5,
  107037. 6, 5, 7, 5, 8, 6, 8, 6, 8, 6, 8, 6, 8, 7, 9, 7,
  107038. 9, 7,11, 9,11,11,12,11,14,12,14,16,14,16,13,16,
  107039. 14,16,12,15,13,16,14,16,13,14,12,15,13,15,13,13,
  107040. 13,15,12,14,14,15,13,15,12,15,15,15,15,15,15,15,
  107041. 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
  107042. };
  107043. static static_codebook _huff_book_line_512x17_1sub1 = {
  107044. 1, 128,
  107045. _huff_lengthlist_line_512x17_1sub1,
  107046. 0, 0, 0, 0, 0,
  107047. NULL,
  107048. NULL,
  107049. NULL,
  107050. NULL,
  107051. 0
  107052. };
  107053. static long _huff_lengthlist_line_512x17_2sub1[] = {
  107054. 0, 4, 5, 4, 4, 4, 5, 4, 4, 4, 5, 4, 5, 4, 5, 3,
  107055. 5, 3,
  107056. };
  107057. static static_codebook _huff_book_line_512x17_2sub1 = {
  107058. 1, 18,
  107059. _huff_lengthlist_line_512x17_2sub1,
  107060. 0, 0, 0, 0, 0,
  107061. NULL,
  107062. NULL,
  107063. NULL,
  107064. NULL,
  107065. 0
  107066. };
  107067. static long _huff_lengthlist_line_512x17_2sub2[] = {
  107068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107069. 0, 0, 4, 3, 4, 3, 4, 4, 5, 4, 5, 4, 6, 4, 6, 5,
  107070. 6, 5, 7, 5, 7, 6, 8, 6, 8, 6, 8, 7, 8, 7, 9, 7,
  107071. 9, 8,
  107072. };
  107073. static static_codebook _huff_book_line_512x17_2sub2 = {
  107074. 1, 50,
  107075. _huff_lengthlist_line_512x17_2sub2,
  107076. 0, 0, 0, 0, 0,
  107077. NULL,
  107078. NULL,
  107079. NULL,
  107080. NULL,
  107081. 0
  107082. };
  107083. static long _huff_lengthlist_line_512x17_2sub3[] = {
  107084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107087. 0, 0, 3, 3, 3, 3, 4, 3, 4, 4, 5, 5, 6, 6, 7, 7,
  107088. 7, 8, 8,11, 8, 9, 9, 9,10,11,11,11, 9,10,10,11,
  107089. 11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,
  107090. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  107091. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  107092. };
  107093. static static_codebook _huff_book_line_512x17_2sub3 = {
  107094. 1, 128,
  107095. _huff_lengthlist_line_512x17_2sub3,
  107096. 0, 0, 0, 0, 0,
  107097. NULL,
  107098. NULL,
  107099. NULL,
  107100. NULL,
  107101. 0
  107102. };
  107103. static long _huff_lengthlist_line_512x17_3sub1[] = {
  107104. 0, 4, 4, 4, 4, 4, 4, 3, 4, 4, 4, 4, 4, 5, 4, 5,
  107105. 5, 5,
  107106. };
  107107. static static_codebook _huff_book_line_512x17_3sub1 = {
  107108. 1, 18,
  107109. _huff_lengthlist_line_512x17_3sub1,
  107110. 0, 0, 0, 0, 0,
  107111. NULL,
  107112. NULL,
  107113. NULL,
  107114. NULL,
  107115. 0
  107116. };
  107117. static long _huff_lengthlist_line_512x17_3sub2[] = {
  107118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107119. 0, 0, 2, 3, 3, 4, 3, 5, 4, 6, 4, 6, 5, 7, 6, 7,
  107120. 6, 8, 6, 8, 7, 9, 8,10, 8,12, 9,13,10,15,10,15,
  107121. 11,14,
  107122. };
  107123. static static_codebook _huff_book_line_512x17_3sub2 = {
  107124. 1, 50,
  107125. _huff_lengthlist_line_512x17_3sub2,
  107126. 0, 0, 0, 0, 0,
  107127. NULL,
  107128. NULL,
  107129. NULL,
  107130. NULL,
  107131. 0
  107132. };
  107133. static long _huff_lengthlist_line_512x17_3sub3[] = {
  107134. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107135. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107136. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107137. 0, 0, 4, 8, 4, 8, 4, 8, 4, 8, 5, 8, 5, 8, 6, 8,
  107138. 4, 8, 4, 8, 5, 8, 5, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107139. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107140. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107141. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107142. };
  107143. static static_codebook _huff_book_line_512x17_3sub3 = {
  107144. 1, 128,
  107145. _huff_lengthlist_line_512x17_3sub3,
  107146. 0, 0, 0, 0, 0,
  107147. NULL,
  107148. NULL,
  107149. NULL,
  107150. NULL,
  107151. 0
  107152. };
  107153. static long _huff_lengthlist_line_512x17_class1[] = {
  107154. 1, 2, 3, 6, 5, 4, 7, 7,
  107155. };
  107156. static static_codebook _huff_book_line_512x17_class1 = {
  107157. 1, 8,
  107158. _huff_lengthlist_line_512x17_class1,
  107159. 0, 0, 0, 0, 0,
  107160. NULL,
  107161. NULL,
  107162. NULL,
  107163. NULL,
  107164. 0
  107165. };
  107166. static long _huff_lengthlist_line_512x17_class2[] = {
  107167. 3, 3, 3,14, 5, 4, 4,11, 8, 6, 6,10,17,12,11,17,
  107168. 6, 5, 5,15, 5, 3, 4,11, 8, 5, 5, 8,16, 9,10,14,
  107169. 10, 8, 9,17, 8, 6, 6,13,10, 7, 7,10,16,11,13,14,
  107170. 17,17,17,17,17,16,16,16,16,15,16,16,16,16,16,16,
  107171. };
  107172. static static_codebook _huff_book_line_512x17_class2 = {
  107173. 1, 64,
  107174. _huff_lengthlist_line_512x17_class2,
  107175. 0, 0, 0, 0, 0,
  107176. NULL,
  107177. NULL,
  107178. NULL,
  107179. NULL,
  107180. 0
  107181. };
  107182. static long _huff_lengthlist_line_512x17_class3[] = {
  107183. 2, 4, 6,17, 4, 5, 7,17, 8, 7,10,17,17,17,17,17,
  107184. 3, 4, 6,15, 3, 3, 6,15, 7, 6, 9,17,17,17,17,17,
  107185. 6, 8,10,17, 6, 6, 8,16, 9, 8,10,17,17,15,16,17,
  107186. 17,17,17,17,12,15,15,16,12,15,15,16,16,16,16,16,
  107187. };
  107188. static static_codebook _huff_book_line_512x17_class3 = {
  107189. 1, 64,
  107190. _huff_lengthlist_line_512x17_class3,
  107191. 0, 0, 0, 0, 0,
  107192. NULL,
  107193. NULL,
  107194. NULL,
  107195. NULL,
  107196. 0
  107197. };
  107198. static long _huff_lengthlist_line_128x4_class0[] = {
  107199. 7, 7, 7,11, 6, 6, 7,11, 7, 6, 6,10,12,10,10,13,
  107200. 7, 7, 8,11, 7, 7, 7,11, 7, 6, 7,10,11,10,10,13,
  107201. 10,10, 9,12, 9, 9, 9,11, 8, 8, 8,11,13,11,10,14,
  107202. 15,15,14,15,15,14,13,14,15,12,12,17,17,17,17,17,
  107203. 7, 7, 6, 9, 6, 6, 6, 9, 7, 6, 6, 8,11,11,10,12,
  107204. 7, 7, 7, 9, 7, 6, 6, 9, 7, 6, 6, 9,13,10,10,11,
  107205. 10, 9, 8,10, 9, 8, 8,10, 8, 8, 7, 9,13,12,10,11,
  107206. 17,14,14,13,15,14,12,13,17,13,12,15,17,17,14,17,
  107207. 7, 6, 6, 7, 6, 6, 5, 7, 6, 6, 6, 6,11, 9, 9, 9,
  107208. 7, 7, 6, 7, 7, 6, 6, 7, 6, 6, 6, 6,10, 9, 8, 9,
  107209. 10, 9, 8, 8, 9, 8, 7, 8, 8, 7, 6, 8,11,10, 9,10,
  107210. 17,17,12,15,15,15,12,14,14,14,10,12,15,13,12,13,
  107211. 11,10, 8,10,11,10, 8, 8,10, 9, 7, 7,10, 9, 9,11,
  107212. 11,11, 9,10,11,10, 8, 9,10, 8, 6, 8,10, 9, 9,11,
  107213. 14,13,10,12,12,11,10,10, 8, 7, 8,10,10,11,11,12,
  107214. 17,17,15,17,17,17,17,17,17,13,12,17,17,17,14,17,
  107215. };
  107216. static static_codebook _huff_book_line_128x4_class0 = {
  107217. 1, 256,
  107218. _huff_lengthlist_line_128x4_class0,
  107219. 0, 0, 0, 0, 0,
  107220. NULL,
  107221. NULL,
  107222. NULL,
  107223. NULL,
  107224. 0
  107225. };
  107226. static long _huff_lengthlist_line_128x4_0sub0[] = {
  107227. 2, 2, 2, 2,
  107228. };
  107229. static static_codebook _huff_book_line_128x4_0sub0 = {
  107230. 1, 4,
  107231. _huff_lengthlist_line_128x4_0sub0,
  107232. 0, 0, 0, 0, 0,
  107233. NULL,
  107234. NULL,
  107235. NULL,
  107236. NULL,
  107237. 0
  107238. };
  107239. static long _huff_lengthlist_line_128x4_0sub1[] = {
  107240. 0, 0, 0, 0, 3, 2, 3, 2, 3, 3,
  107241. };
  107242. static static_codebook _huff_book_line_128x4_0sub1 = {
  107243. 1, 10,
  107244. _huff_lengthlist_line_128x4_0sub1,
  107245. 0, 0, 0, 0, 0,
  107246. NULL,
  107247. NULL,
  107248. NULL,
  107249. NULL,
  107250. 0
  107251. };
  107252. static long _huff_lengthlist_line_128x4_0sub2[] = {
  107253. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 4, 3, 4, 3,
  107254. 4, 4, 5, 4, 5, 4, 6, 5, 6,
  107255. };
  107256. static static_codebook _huff_book_line_128x4_0sub2 = {
  107257. 1, 25,
  107258. _huff_lengthlist_line_128x4_0sub2,
  107259. 0, 0, 0, 0, 0,
  107260. NULL,
  107261. NULL,
  107262. NULL,
  107263. NULL,
  107264. 0
  107265. };
  107266. static long _huff_lengthlist_line_128x4_0sub3[] = {
  107267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107268. 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 4, 3, 5, 3, 5, 3,
  107269. 5, 4, 6, 5, 6, 5, 7, 6, 6, 7, 7, 9, 9,11,11,16,
  107270. 11,14,10,11,11,13,16,15,15,15,15,15,15,15,15,15,
  107271. };
  107272. static static_codebook _huff_book_line_128x4_0sub3 = {
  107273. 1, 64,
  107274. _huff_lengthlist_line_128x4_0sub3,
  107275. 0, 0, 0, 0, 0,
  107276. NULL,
  107277. NULL,
  107278. NULL,
  107279. NULL,
  107280. 0
  107281. };
  107282. static long _huff_lengthlist_line_256x4_class0[] = {
  107283. 6, 7, 7,12, 6, 6, 7,12, 7, 6, 6,10,15,12,11,13,
  107284. 7, 7, 8,13, 7, 7, 8,12, 7, 7, 7,11,12,12,11,13,
  107285. 10, 9, 9,11, 9, 9, 9,10,10, 8, 8,12,14,12,12,14,
  107286. 11,11,12,14,11,12,11,15,15,12,13,15,15,15,15,15,
  107287. 6, 6, 7,10, 6, 6, 6,11, 7, 6, 6, 9,14,12,11,13,
  107288. 7, 7, 7,10, 6, 6, 7, 9, 7, 7, 6,10,13,12,10,12,
  107289. 9, 9, 9,11, 9, 9, 8, 9, 9, 8, 8,10,13,12,10,12,
  107290. 12,12,11,13,12,12,11,12,15,13,12,15,15,15,14,14,
  107291. 6, 6, 6, 8, 6, 6, 5, 6, 7, 7, 6, 5,11,10, 9, 8,
  107292. 7, 6, 6, 7, 6, 6, 5, 6, 7, 7, 6, 6,11,10, 9, 8,
  107293. 8, 8, 8, 9, 8, 8, 7, 8, 8, 8, 6, 7,11,10, 9, 9,
  107294. 14,11,10,14,14,11,10,15,13,11, 9,11,15,12,12,11,
  107295. 11, 9, 8, 8,10, 9, 8, 9,11,10, 9, 8,12,11,12,11,
  107296. 13,10, 8, 9,11,10, 8, 9,10, 9, 8, 9,10, 8,12,12,
  107297. 15,11,10,10,13,11,10,10, 8, 8, 7,12,10, 9,11,12,
  107298. 15,12,11,15,13,11,11,15,12,14,11,13,15,15,13,13,
  107299. };
  107300. static static_codebook _huff_book_line_256x4_class0 = {
  107301. 1, 256,
  107302. _huff_lengthlist_line_256x4_class0,
  107303. 0, 0, 0, 0, 0,
  107304. NULL,
  107305. NULL,
  107306. NULL,
  107307. NULL,
  107308. 0
  107309. };
  107310. static long _huff_lengthlist_line_256x4_0sub0[] = {
  107311. 2, 2, 2, 2,
  107312. };
  107313. static static_codebook _huff_book_line_256x4_0sub0 = {
  107314. 1, 4,
  107315. _huff_lengthlist_line_256x4_0sub0,
  107316. 0, 0, 0, 0, 0,
  107317. NULL,
  107318. NULL,
  107319. NULL,
  107320. NULL,
  107321. 0
  107322. };
  107323. static long _huff_lengthlist_line_256x4_0sub1[] = {
  107324. 0, 0, 0, 0, 2, 2, 3, 3, 3, 3,
  107325. };
  107326. static static_codebook _huff_book_line_256x4_0sub1 = {
  107327. 1, 10,
  107328. _huff_lengthlist_line_256x4_0sub1,
  107329. 0, 0, 0, 0, 0,
  107330. NULL,
  107331. NULL,
  107332. NULL,
  107333. NULL,
  107334. 0
  107335. };
  107336. static long _huff_lengthlist_line_256x4_0sub2[] = {
  107337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 3, 4, 3, 4, 3,
  107338. 5, 3, 5, 4, 5, 4, 6, 4, 6,
  107339. };
  107340. static static_codebook _huff_book_line_256x4_0sub2 = {
  107341. 1, 25,
  107342. _huff_lengthlist_line_256x4_0sub2,
  107343. 0, 0, 0, 0, 0,
  107344. NULL,
  107345. NULL,
  107346. NULL,
  107347. NULL,
  107348. 0
  107349. };
  107350. static long _huff_lengthlist_line_256x4_0sub3[] = {
  107351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 4, 3, 5, 3, 5, 3,
  107353. 6, 4, 7, 4, 7, 5, 7, 6, 7, 6, 7, 8,10,13,13,13,
  107354. 13,13,13,13,13,13,13,13,13,13,13,12,12,12,12,12,
  107355. };
  107356. static static_codebook _huff_book_line_256x4_0sub3 = {
  107357. 1, 64,
  107358. _huff_lengthlist_line_256x4_0sub3,
  107359. 0, 0, 0, 0, 0,
  107360. NULL,
  107361. NULL,
  107362. NULL,
  107363. NULL,
  107364. 0
  107365. };
  107366. static long _huff_lengthlist_line_128x7_class0[] = {
  107367. 10, 7, 8,13, 9, 6, 7,11,10, 8, 8,12,17,17,17,17,
  107368. 7, 5, 5, 9, 6, 4, 4, 8, 8, 5, 5, 8,16,14,13,16,
  107369. 7, 5, 5, 7, 6, 3, 3, 5, 8, 5, 4, 7,14,12,12,15,
  107370. 10, 7, 8, 9, 7, 5, 5, 6, 9, 6, 5, 5,15,12, 9,10,
  107371. };
  107372. static static_codebook _huff_book_line_128x7_class0 = {
  107373. 1, 64,
  107374. _huff_lengthlist_line_128x7_class0,
  107375. 0, 0, 0, 0, 0,
  107376. NULL,
  107377. NULL,
  107378. NULL,
  107379. NULL,
  107380. 0
  107381. };
  107382. static long _huff_lengthlist_line_128x7_class1[] = {
  107383. 8,13,17,17, 8,11,17,17,11,13,17,17,17,17,17,17,
  107384. 6,10,16,17, 6,10,15,17, 8,10,16,17,17,17,17,17,
  107385. 9,13,15,17, 8,11,17,17,10,12,17,17,17,17,17,17,
  107386. 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,
  107387. 6,11,15,17, 7,10,15,17, 8,10,17,17,17,15,17,17,
  107388. 4, 8,13,17, 4, 7,13,17, 6, 8,15,17,16,15,17,17,
  107389. 6,11,15,17, 6, 9,13,17, 8,10,17,17,15,17,17,17,
  107390. 16,17,17,17,12,14,15,17,13,14,15,17,17,17,17,17,
  107391. 5,10,14,17, 5, 9,14,17, 7, 9,15,17,15,15,17,17,
  107392. 3, 7,12,17, 3, 6,11,17, 5, 7,13,17,12,12,17,17,
  107393. 5, 9,14,17, 3, 7,11,17, 5, 8,13,17,13,11,16,17,
  107394. 12,17,17,17, 9,14,15,17,10,11,14,17,16,14,17,17,
  107395. 8,12,17,17, 8,12,17,17,10,12,17,17,17,17,17,17,
  107396. 5,10,17,17, 5, 9,15,17, 7, 9,17,17,13,13,17,17,
  107397. 7,11,17,17, 6,10,15,17, 7, 9,15,17,12,11,17,17,
  107398. 12,15,17,17,11,14,17,17,11,10,15,17,17,16,17,17,
  107399. };
  107400. static static_codebook _huff_book_line_128x7_class1 = {
  107401. 1, 256,
  107402. _huff_lengthlist_line_128x7_class1,
  107403. 0, 0, 0, 0, 0,
  107404. NULL,
  107405. NULL,
  107406. NULL,
  107407. NULL,
  107408. 0
  107409. };
  107410. static long _huff_lengthlist_line_128x7_0sub1[] = {
  107411. 0, 3, 3, 3, 3, 3, 3, 3, 3,
  107412. };
  107413. static static_codebook _huff_book_line_128x7_0sub1 = {
  107414. 1, 9,
  107415. _huff_lengthlist_line_128x7_0sub1,
  107416. 0, 0, 0, 0, 0,
  107417. NULL,
  107418. NULL,
  107419. NULL,
  107420. NULL,
  107421. 0
  107422. };
  107423. static long _huff_lengthlist_line_128x7_0sub2[] = {
  107424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 4, 4, 4, 4,
  107425. 5, 4, 5, 4, 5, 4, 6, 4, 6,
  107426. };
  107427. static static_codebook _huff_book_line_128x7_0sub2 = {
  107428. 1, 25,
  107429. _huff_lengthlist_line_128x7_0sub2,
  107430. 0, 0, 0, 0, 0,
  107431. NULL,
  107432. NULL,
  107433. NULL,
  107434. NULL,
  107435. 0
  107436. };
  107437. static long _huff_lengthlist_line_128x7_0sub3[] = {
  107438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 3, 5, 3, 5, 4,
  107440. 5, 4, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107441. 7, 8, 9,11,13,13,13,13,13,13,13,13,13,13,13,13,
  107442. };
  107443. static static_codebook _huff_book_line_128x7_0sub3 = {
  107444. 1, 64,
  107445. _huff_lengthlist_line_128x7_0sub3,
  107446. 0, 0, 0, 0, 0,
  107447. NULL,
  107448. NULL,
  107449. NULL,
  107450. NULL,
  107451. 0
  107452. };
  107453. static long _huff_lengthlist_line_128x7_1sub1[] = {
  107454. 0, 3, 3, 2, 3, 3, 4, 3, 4,
  107455. };
  107456. static static_codebook _huff_book_line_128x7_1sub1 = {
  107457. 1, 9,
  107458. _huff_lengthlist_line_128x7_1sub1,
  107459. 0, 0, 0, 0, 0,
  107460. NULL,
  107461. NULL,
  107462. NULL,
  107463. NULL,
  107464. 0
  107465. };
  107466. static long _huff_lengthlist_line_128x7_1sub2[] = {
  107467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 4, 3, 6, 3, 6, 3,
  107468. 6, 3, 7, 3, 8, 4, 9, 4, 9,
  107469. };
  107470. static static_codebook _huff_book_line_128x7_1sub2 = {
  107471. 1, 25,
  107472. _huff_lengthlist_line_128x7_1sub2,
  107473. 0, 0, 0, 0, 0,
  107474. NULL,
  107475. NULL,
  107476. NULL,
  107477. NULL,
  107478. 0
  107479. };
  107480. static long _huff_lengthlist_line_128x7_1sub3[] = {
  107481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 7, 2, 7, 3, 8, 4,
  107483. 9, 5, 9, 8,10,11,11,12,14,14,14,14,14,14,14,14,
  107484. 14,14,14,14,14,14,14,14,14,14,14,14,13,13,13,13,
  107485. };
  107486. static static_codebook _huff_book_line_128x7_1sub3 = {
  107487. 1, 64,
  107488. _huff_lengthlist_line_128x7_1sub3,
  107489. 0, 0, 0, 0, 0,
  107490. NULL,
  107491. NULL,
  107492. NULL,
  107493. NULL,
  107494. 0
  107495. };
  107496. static long _huff_lengthlist_line_128x11_class1[] = {
  107497. 1, 6, 3, 7, 2, 4, 5, 7,
  107498. };
  107499. static static_codebook _huff_book_line_128x11_class1 = {
  107500. 1, 8,
  107501. _huff_lengthlist_line_128x11_class1,
  107502. 0, 0, 0, 0, 0,
  107503. NULL,
  107504. NULL,
  107505. NULL,
  107506. NULL,
  107507. 0
  107508. };
  107509. static long _huff_lengthlist_line_128x11_class2[] = {
  107510. 1, 6,12,16, 4,12,15,16, 9,15,16,16,16,16,16,16,
  107511. 2, 5,11,16, 5,11,13,16, 9,13,16,16,16,16,16,16,
  107512. 4, 8,12,16, 5, 9,12,16, 9,13,15,16,16,16,16,16,
  107513. 15,16,16,16,11,14,13,16,12,15,16,16,16,16,16,15,
  107514. };
  107515. static static_codebook _huff_book_line_128x11_class2 = {
  107516. 1, 64,
  107517. _huff_lengthlist_line_128x11_class2,
  107518. 0, 0, 0, 0, 0,
  107519. NULL,
  107520. NULL,
  107521. NULL,
  107522. NULL,
  107523. 0
  107524. };
  107525. static long _huff_lengthlist_line_128x11_class3[] = {
  107526. 7, 6, 9,17, 7, 6, 8,17,12, 9,11,16,16,16,16,16,
  107527. 5, 4, 7,16, 5, 3, 6,14, 9, 6, 8,15,16,16,16,16,
  107528. 5, 4, 6,13, 3, 2, 4,11, 7, 4, 6,13,16,11,10,14,
  107529. 12,12,12,16, 9, 7,10,15,12, 9,11,16,16,15,15,16,
  107530. };
  107531. static static_codebook _huff_book_line_128x11_class3 = {
  107532. 1, 64,
  107533. _huff_lengthlist_line_128x11_class3,
  107534. 0, 0, 0, 0, 0,
  107535. NULL,
  107536. NULL,
  107537. NULL,
  107538. NULL,
  107539. 0
  107540. };
  107541. static long _huff_lengthlist_line_128x11_0sub0[] = {
  107542. 5, 5, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107543. 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 6, 6, 6, 7, 6,
  107544. 7, 6, 7, 6, 7, 6, 7, 6, 7, 6, 8, 6, 8, 6, 8, 7,
  107545. 8, 7, 8, 7, 8, 7, 9, 7, 9, 8, 9, 8, 9, 8,10, 8,
  107546. 10, 9,10, 9,10, 9,11, 9,11, 9,10,10,11,10,11,10,
  107547. 11,11,11,11,11,11,12,13,14,14,14,15,15,16,16,16,
  107548. 17,15,16,15,16,16,17,17,16,17,17,17,17,17,17,17,
  107549. 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,
  107550. };
  107551. static static_codebook _huff_book_line_128x11_0sub0 = {
  107552. 1, 128,
  107553. _huff_lengthlist_line_128x11_0sub0,
  107554. 0, 0, 0, 0, 0,
  107555. NULL,
  107556. NULL,
  107557. NULL,
  107558. NULL,
  107559. 0
  107560. };
  107561. static long _huff_lengthlist_line_128x11_1sub0[] = {
  107562. 2, 5, 5, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5, 5, 5, 5,
  107563. 6, 5, 6, 5, 6, 5, 7, 6, 7, 6, 7, 6, 8, 6, 8, 6,
  107564. };
  107565. static static_codebook _huff_book_line_128x11_1sub0 = {
  107566. 1, 32,
  107567. _huff_lengthlist_line_128x11_1sub0,
  107568. 0, 0, 0, 0, 0,
  107569. NULL,
  107570. NULL,
  107571. NULL,
  107572. NULL,
  107573. 0
  107574. };
  107575. static long _huff_lengthlist_line_128x11_1sub1[] = {
  107576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107578. 5, 3, 5, 3, 6, 4, 6, 4, 7, 4, 7, 4, 7, 4, 8, 4,
  107579. 8, 4, 9, 5, 9, 5, 9, 5, 9, 6,10, 6,10, 6,11, 7,
  107580. 10, 7,10, 8,11, 9,11, 9,11,10,11,11,12,11,11,12,
  107581. 15,15,12,14,11,14,12,14,11,14,13,14,12,14,11,14,
  107582. 11,14,12,14,11,14,11,14,13,13,14,14,14,14,14,14,
  107583. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  107584. };
  107585. static static_codebook _huff_book_line_128x11_1sub1 = {
  107586. 1, 128,
  107587. _huff_lengthlist_line_128x11_1sub1,
  107588. 0, 0, 0, 0, 0,
  107589. NULL,
  107590. NULL,
  107591. NULL,
  107592. NULL,
  107593. 0
  107594. };
  107595. static long _huff_lengthlist_line_128x11_2sub1[] = {
  107596. 0, 4, 5, 4, 5, 4, 5, 3, 5, 3, 5, 3, 5, 4, 4, 4,
  107597. 5, 5,
  107598. };
  107599. static static_codebook _huff_book_line_128x11_2sub1 = {
  107600. 1, 18,
  107601. _huff_lengthlist_line_128x11_2sub1,
  107602. 0, 0, 0, 0, 0,
  107603. NULL,
  107604. NULL,
  107605. NULL,
  107606. NULL,
  107607. 0
  107608. };
  107609. static long _huff_lengthlist_line_128x11_2sub2[] = {
  107610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107611. 0, 0, 3, 3, 3, 4, 4, 4, 4, 5, 4, 5, 4, 6, 5, 7,
  107612. 5, 7, 6, 8, 6, 8, 6, 9, 7, 9, 7,10, 7, 9, 8,11,
  107613. 8,11,
  107614. };
  107615. static static_codebook _huff_book_line_128x11_2sub2 = {
  107616. 1, 50,
  107617. _huff_lengthlist_line_128x11_2sub2,
  107618. 0, 0, 0, 0, 0,
  107619. NULL,
  107620. NULL,
  107621. NULL,
  107622. NULL,
  107623. 0
  107624. };
  107625. static long _huff_lengthlist_line_128x11_2sub3[] = {
  107626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107629. 0, 0, 4, 8, 3, 8, 4, 8, 4, 8, 6, 8, 5, 8, 4, 8,
  107630. 4, 8, 6, 8, 7, 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107631. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107632. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107633. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107634. };
  107635. static static_codebook _huff_book_line_128x11_2sub3 = {
  107636. 1, 128,
  107637. _huff_lengthlist_line_128x11_2sub3,
  107638. 0, 0, 0, 0, 0,
  107639. NULL,
  107640. NULL,
  107641. NULL,
  107642. NULL,
  107643. 0
  107644. };
  107645. static long _huff_lengthlist_line_128x11_3sub1[] = {
  107646. 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 4,
  107647. 5, 4,
  107648. };
  107649. static static_codebook _huff_book_line_128x11_3sub1 = {
  107650. 1, 18,
  107651. _huff_lengthlist_line_128x11_3sub1,
  107652. 0, 0, 0, 0, 0,
  107653. NULL,
  107654. NULL,
  107655. NULL,
  107656. NULL,
  107657. 0
  107658. };
  107659. static long _huff_lengthlist_line_128x11_3sub2[] = {
  107660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107661. 0, 0, 5, 3, 5, 4, 6, 4, 6, 4, 7, 4, 7, 4, 8, 4,
  107662. 8, 4, 9, 4, 9, 4,10, 4,10, 5,10, 5,11, 5,12, 6,
  107663. 12, 6,
  107664. };
  107665. static static_codebook _huff_book_line_128x11_3sub2 = {
  107666. 1, 50,
  107667. _huff_lengthlist_line_128x11_3sub2,
  107668. 0, 0, 0, 0, 0,
  107669. NULL,
  107670. NULL,
  107671. NULL,
  107672. NULL,
  107673. 0
  107674. };
  107675. static long _huff_lengthlist_line_128x11_3sub3[] = {
  107676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107679. 0, 0, 7, 1, 6, 3, 7, 3, 8, 4, 8, 5, 8, 8, 8, 9,
  107680. 7, 8, 8, 7, 7, 7, 8, 9,10, 9, 9,10,10,10,10,10,
  107681. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  107682. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  107683. 10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9,
  107684. };
  107685. static static_codebook _huff_book_line_128x11_3sub3 = {
  107686. 1, 128,
  107687. _huff_lengthlist_line_128x11_3sub3,
  107688. 0, 0, 0, 0, 0,
  107689. NULL,
  107690. NULL,
  107691. NULL,
  107692. NULL,
  107693. 0
  107694. };
  107695. static long _huff_lengthlist_line_128x17_class1[] = {
  107696. 1, 3, 4, 7, 2, 5, 6, 7,
  107697. };
  107698. static static_codebook _huff_book_line_128x17_class1 = {
  107699. 1, 8,
  107700. _huff_lengthlist_line_128x17_class1,
  107701. 0, 0, 0, 0, 0,
  107702. NULL,
  107703. NULL,
  107704. NULL,
  107705. NULL,
  107706. 0
  107707. };
  107708. static long _huff_lengthlist_line_128x17_class2[] = {
  107709. 1, 4,10,19, 3, 8,13,19, 7,12,19,19,19,19,19,19,
  107710. 2, 6,11,19, 8,13,19,19, 9,11,19,19,19,19,19,19,
  107711. 6, 7,13,19, 9,13,19,19,10,13,18,18,18,18,18,18,
  107712. 18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,
  107713. };
  107714. static static_codebook _huff_book_line_128x17_class2 = {
  107715. 1, 64,
  107716. _huff_lengthlist_line_128x17_class2,
  107717. 0, 0, 0, 0, 0,
  107718. NULL,
  107719. NULL,
  107720. NULL,
  107721. NULL,
  107722. 0
  107723. };
  107724. static long _huff_lengthlist_line_128x17_class3[] = {
  107725. 3, 6,10,17, 4, 8,11,20, 8,10,11,20,20,20,20,20,
  107726. 2, 4, 8,18, 4, 6, 8,17, 7, 8,10,20,20,17,20,20,
  107727. 3, 5, 8,17, 3, 4, 6,17, 8, 8,10,17,17,12,16,20,
  107728. 13,13,15,20,10,10,12,20,15,14,15,20,20,20,19,19,
  107729. };
  107730. static static_codebook _huff_book_line_128x17_class3 = {
  107731. 1, 64,
  107732. _huff_lengthlist_line_128x17_class3,
  107733. 0, 0, 0, 0, 0,
  107734. NULL,
  107735. NULL,
  107736. NULL,
  107737. NULL,
  107738. 0
  107739. };
  107740. static long _huff_lengthlist_line_128x17_0sub0[] = {
  107741. 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107742. 7, 5, 7, 5, 7, 5, 7, 5, 7, 5, 7, 5, 8, 5, 8, 5,
  107743. 8, 5, 8, 5, 8, 6, 8, 6, 8, 6, 9, 6, 9, 6, 9, 6,
  107744. 9, 6, 9, 7, 9, 7, 9, 7, 9, 7,10, 7,10, 8,10, 8,
  107745. 10, 8,10, 8,10, 8,11, 8,11, 8,11, 8,11, 8,11, 9,
  107746. 12, 9,12, 9,12, 9,12, 9,12,10,12,10,13,11,13,11,
  107747. 14,12,14,13,15,14,16,14,17,15,18,16,20,20,20,20,
  107748. 20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
  107749. };
  107750. static static_codebook _huff_book_line_128x17_0sub0 = {
  107751. 1, 128,
  107752. _huff_lengthlist_line_128x17_0sub0,
  107753. 0, 0, 0, 0, 0,
  107754. NULL,
  107755. NULL,
  107756. NULL,
  107757. NULL,
  107758. 0
  107759. };
  107760. static long _huff_lengthlist_line_128x17_1sub0[] = {
  107761. 2, 5, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 5, 5, 6, 5,
  107762. 6, 5, 6, 5, 7, 6, 7, 6, 7, 6, 8, 6, 9, 7, 9, 7,
  107763. };
  107764. static static_codebook _huff_book_line_128x17_1sub0 = {
  107765. 1, 32,
  107766. _huff_lengthlist_line_128x17_1sub0,
  107767. 0, 0, 0, 0, 0,
  107768. NULL,
  107769. NULL,
  107770. NULL,
  107771. NULL,
  107772. 0
  107773. };
  107774. static long _huff_lengthlist_line_128x17_1sub1[] = {
  107775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107777. 4, 3, 5, 3, 5, 3, 6, 3, 6, 4, 6, 4, 7, 4, 7, 5,
  107778. 8, 5, 8, 6, 9, 7, 9, 7, 9, 8,10, 9,10, 9,11,10,
  107779. 11,11,11,11,11,11,12,12,12,13,12,13,12,14,12,15,
  107780. 12,14,12,16,13,17,13,17,14,17,14,16,13,17,14,17,
  107781. 14,17,15,17,15,15,16,17,17,17,17,17,17,17,17,17,
  107782. 17,17,17,17,17,17,16,16,16,16,16,16,16,16,16,16,
  107783. };
  107784. static static_codebook _huff_book_line_128x17_1sub1 = {
  107785. 1, 128,
  107786. _huff_lengthlist_line_128x17_1sub1,
  107787. 0, 0, 0, 0, 0,
  107788. NULL,
  107789. NULL,
  107790. NULL,
  107791. NULL,
  107792. 0
  107793. };
  107794. static long _huff_lengthlist_line_128x17_2sub1[] = {
  107795. 0, 4, 5, 4, 6, 4, 8, 3, 9, 3, 9, 2, 9, 3, 8, 4,
  107796. 9, 4,
  107797. };
  107798. static static_codebook _huff_book_line_128x17_2sub1 = {
  107799. 1, 18,
  107800. _huff_lengthlist_line_128x17_2sub1,
  107801. 0, 0, 0, 0, 0,
  107802. NULL,
  107803. NULL,
  107804. NULL,
  107805. NULL,
  107806. 0
  107807. };
  107808. static long _huff_lengthlist_line_128x17_2sub2[] = {
  107809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107810. 0, 0, 5, 1, 5, 3, 5, 3, 5, 4, 7, 5,10, 7,10, 7,
  107811. 12,10,14,10,14, 9,14,11,14,14,14,13,13,13,13,13,
  107812. 13,13,
  107813. };
  107814. static static_codebook _huff_book_line_128x17_2sub2 = {
  107815. 1, 50,
  107816. _huff_lengthlist_line_128x17_2sub2,
  107817. 0, 0, 0, 0, 0,
  107818. NULL,
  107819. NULL,
  107820. NULL,
  107821. NULL,
  107822. 0
  107823. };
  107824. static long _huff_lengthlist_line_128x17_2sub3[] = {
  107825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107828. 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107829. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 6, 6,
  107830. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  107831. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  107832. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  107833. };
  107834. static static_codebook _huff_book_line_128x17_2sub3 = {
  107835. 1, 128,
  107836. _huff_lengthlist_line_128x17_2sub3,
  107837. 0, 0, 0, 0, 0,
  107838. NULL,
  107839. NULL,
  107840. NULL,
  107841. NULL,
  107842. 0
  107843. };
  107844. static long _huff_lengthlist_line_128x17_3sub1[] = {
  107845. 0, 4, 4, 4, 4, 4, 4, 4, 5, 3, 5, 3, 5, 4, 6, 4,
  107846. 6, 4,
  107847. };
  107848. static static_codebook _huff_book_line_128x17_3sub1 = {
  107849. 1, 18,
  107850. _huff_lengthlist_line_128x17_3sub1,
  107851. 0, 0, 0, 0, 0,
  107852. NULL,
  107853. NULL,
  107854. NULL,
  107855. NULL,
  107856. 0
  107857. };
  107858. static long _huff_lengthlist_line_128x17_3sub2[] = {
  107859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107860. 0, 0, 5, 3, 6, 3, 6, 4, 7, 4, 7, 4, 7, 4, 8, 4,
  107861. 8, 4, 8, 4, 8, 4, 9, 4, 9, 5,10, 5,10, 7,10, 8,
  107862. 10, 8,
  107863. };
  107864. static static_codebook _huff_book_line_128x17_3sub2 = {
  107865. 1, 50,
  107866. _huff_lengthlist_line_128x17_3sub2,
  107867. 0, 0, 0, 0, 0,
  107868. NULL,
  107869. NULL,
  107870. NULL,
  107871. NULL,
  107872. 0
  107873. };
  107874. static long _huff_lengthlist_line_128x17_3sub3[] = {
  107875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107878. 0, 0, 3, 2, 4, 3, 4, 4, 4, 5, 4, 7, 5, 8, 5,11,
  107879. 6,10, 6,12, 7,12, 7,12, 8,12, 8,12,10,12,12,12,
  107880. 12,12,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  107881. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  107882. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  107883. };
  107884. static static_codebook _huff_book_line_128x17_3sub3 = {
  107885. 1, 128,
  107886. _huff_lengthlist_line_128x17_3sub3,
  107887. 0, 0, 0, 0, 0,
  107888. NULL,
  107889. NULL,
  107890. NULL,
  107891. NULL,
  107892. 0
  107893. };
  107894. static long _huff_lengthlist_line_1024x27_class1[] = {
  107895. 2,10, 8,14, 7,12,11,14, 1, 5, 3, 7, 4, 9, 7,13,
  107896. };
  107897. static static_codebook _huff_book_line_1024x27_class1 = {
  107898. 1, 16,
  107899. _huff_lengthlist_line_1024x27_class1,
  107900. 0, 0, 0, 0, 0,
  107901. NULL,
  107902. NULL,
  107903. NULL,
  107904. NULL,
  107905. 0
  107906. };
  107907. static long _huff_lengthlist_line_1024x27_class2[] = {
  107908. 1, 4, 2, 6, 3, 7, 5, 7,
  107909. };
  107910. static static_codebook _huff_book_line_1024x27_class2 = {
  107911. 1, 8,
  107912. _huff_lengthlist_line_1024x27_class2,
  107913. 0, 0, 0, 0, 0,
  107914. NULL,
  107915. NULL,
  107916. NULL,
  107917. NULL,
  107918. 0
  107919. };
  107920. static long _huff_lengthlist_line_1024x27_class3[] = {
  107921. 1, 5, 7,21, 5, 8, 9,21,10, 9,12,20,20,16,20,20,
  107922. 4, 8, 9,20, 6, 8, 9,20,11,11,13,20,20,15,17,20,
  107923. 9,11,14,20, 8,10,15,20,11,13,15,20,20,20,20,20,
  107924. 20,20,20,20,13,20,20,20,18,18,20,20,20,20,20,20,
  107925. 3, 6, 8,20, 6, 7, 9,20,10, 9,12,20,20,20,20,20,
  107926. 5, 7, 9,20, 6, 6, 9,20,10, 9,12,20,20,20,20,20,
  107927. 8,10,13,20, 8, 9,12,20,11,10,12,20,20,20,20,20,
  107928. 18,20,20,20,15,17,18,20,18,17,18,20,20,20,20,20,
  107929. 7,10,12,20, 8, 9,11,20,14,13,14,20,20,20,20,20,
  107930. 6, 9,12,20, 7, 8,11,20,12,11,13,20,20,20,20,20,
  107931. 9,11,15,20, 8,10,14,20,12,11,14,20,20,20,20,20,
  107932. 20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
  107933. 11,16,18,20,15,15,17,20,20,17,20,20,20,20,20,20,
  107934. 9,14,16,20,12,12,15,20,17,15,18,20,20,20,20,20,
  107935. 16,19,18,20,15,16,20,20,17,17,20,20,20,20,20,20,
  107936. 20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
  107937. };
  107938. static static_codebook _huff_book_line_1024x27_class3 = {
  107939. 1, 256,
  107940. _huff_lengthlist_line_1024x27_class3,
  107941. 0, 0, 0, 0, 0,
  107942. NULL,
  107943. NULL,
  107944. NULL,
  107945. NULL,
  107946. 0
  107947. };
  107948. static long _huff_lengthlist_line_1024x27_class4[] = {
  107949. 2, 3, 7,13, 4, 4, 7,15, 8, 6, 9,17,21,16,15,21,
  107950. 2, 5, 7,11, 5, 5, 7,14, 9, 7,10,16,17,15,16,21,
  107951. 4, 7,10,17, 7, 7, 9,15,11, 9,11,16,21,18,15,21,
  107952. 18,21,21,21,15,17,17,19,21,19,18,20,21,21,21,20,
  107953. };
  107954. static static_codebook _huff_book_line_1024x27_class4 = {
  107955. 1, 64,
  107956. _huff_lengthlist_line_1024x27_class4,
  107957. 0, 0, 0, 0, 0,
  107958. NULL,
  107959. NULL,
  107960. NULL,
  107961. NULL,
  107962. 0
  107963. };
  107964. static long _huff_lengthlist_line_1024x27_0sub0[] = {
  107965. 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107966. 6, 5, 6, 5, 6, 5, 6, 5, 7, 5, 7, 5, 7, 5, 7, 5,
  107967. 8, 6, 8, 6, 8, 6, 9, 6, 9, 6,10, 6,10, 6,11, 6,
  107968. 11, 7,11, 7,12, 7,12, 7,12, 7,12, 7,12, 7,12, 7,
  107969. 12, 7,12, 8,13, 8,12, 8,12, 8,13, 8,13, 9,13, 9,
  107970. 13, 9,13, 9,12,10,12,10,13,10,14,11,14,12,14,13,
  107971. 14,13,14,14,15,16,15,15,15,14,15,17,21,22,22,21,
  107972. 22,22,22,22,22,22,21,21,21,21,21,21,21,21,21,21,
  107973. };
  107974. static static_codebook _huff_book_line_1024x27_0sub0 = {
  107975. 1, 128,
  107976. _huff_lengthlist_line_1024x27_0sub0,
  107977. 0, 0, 0, 0, 0,
  107978. NULL,
  107979. NULL,
  107980. NULL,
  107981. NULL,
  107982. 0
  107983. };
  107984. static long _huff_lengthlist_line_1024x27_1sub0[] = {
  107985. 2, 5, 5, 4, 5, 4, 5, 4, 5, 4, 6, 5, 6, 5, 6, 5,
  107986. 6, 5, 7, 5, 7, 6, 8, 6, 8, 6, 8, 6, 9, 6, 9, 6,
  107987. };
  107988. static static_codebook _huff_book_line_1024x27_1sub0 = {
  107989. 1, 32,
  107990. _huff_lengthlist_line_1024x27_1sub0,
  107991. 0, 0, 0, 0, 0,
  107992. NULL,
  107993. NULL,
  107994. NULL,
  107995. NULL,
  107996. 0
  107997. };
  107998. static long _huff_lengthlist_line_1024x27_1sub1[] = {
  107999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108001. 8, 5, 8, 4, 9, 4, 9, 4, 9, 4, 9, 4, 9, 4, 9, 4,
  108002. 9, 4, 9, 4, 9, 4, 8, 4, 8, 4, 9, 5, 9, 5, 9, 5,
  108003. 9, 5, 9, 6,10, 6,10, 7,10, 8,11, 9,11,11,12,13,
  108004. 12,14,13,15,13,15,14,16,14,17,15,17,15,15,16,16,
  108005. 15,16,16,16,15,18,16,15,17,17,19,19,19,19,19,19,
  108006. 19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,
  108007. };
  108008. static static_codebook _huff_book_line_1024x27_1sub1 = {
  108009. 1, 128,
  108010. _huff_lengthlist_line_1024x27_1sub1,
  108011. 0, 0, 0, 0, 0,
  108012. NULL,
  108013. NULL,
  108014. NULL,
  108015. NULL,
  108016. 0
  108017. };
  108018. static long _huff_lengthlist_line_1024x27_2sub0[] = {
  108019. 1, 5, 5, 5, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  108020. 6, 6, 7, 7, 7, 7, 8, 7, 8, 8, 9, 8,10, 9,10, 9,
  108021. };
  108022. static static_codebook _huff_book_line_1024x27_2sub0 = {
  108023. 1, 32,
  108024. _huff_lengthlist_line_1024x27_2sub0,
  108025. 0, 0, 0, 0, 0,
  108026. NULL,
  108027. NULL,
  108028. NULL,
  108029. NULL,
  108030. 0
  108031. };
  108032. static long _huff_lengthlist_line_1024x27_2sub1[] = {
  108033. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108034. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108035. 4, 3, 4, 3, 4, 4, 5, 4, 5, 4, 5, 5, 6, 5, 6, 5,
  108036. 7, 5, 7, 6, 7, 6, 8, 7, 8, 7, 8, 7, 9, 8, 9, 9,
  108037. 9, 9,10,10,10,11, 9,12, 9,12, 9,15,10,14, 9,13,
  108038. 10,13,10,12,10,12,10,13,10,12,11,13,11,14,12,13,
  108039. 13,14,14,13,14,15,14,16,13,13,14,16,16,16,16,16,
  108040. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,15,15,
  108041. };
  108042. static static_codebook _huff_book_line_1024x27_2sub1 = {
  108043. 1, 128,
  108044. _huff_lengthlist_line_1024x27_2sub1,
  108045. 0, 0, 0, 0, 0,
  108046. NULL,
  108047. NULL,
  108048. NULL,
  108049. NULL,
  108050. 0
  108051. };
  108052. static long _huff_lengthlist_line_1024x27_3sub1[] = {
  108053. 0, 4, 5, 4, 5, 3, 5, 3, 5, 3, 5, 4, 4, 4, 4, 5,
  108054. 5, 5,
  108055. };
  108056. static static_codebook _huff_book_line_1024x27_3sub1 = {
  108057. 1, 18,
  108058. _huff_lengthlist_line_1024x27_3sub1,
  108059. 0, 0, 0, 0, 0,
  108060. NULL,
  108061. NULL,
  108062. NULL,
  108063. NULL,
  108064. 0
  108065. };
  108066. static long _huff_lengthlist_line_1024x27_3sub2[] = {
  108067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108068. 0, 0, 3, 3, 4, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6,
  108069. 5, 7, 5, 8, 6, 8, 6, 9, 7,10, 7,10, 8,10, 8,11,
  108070. 9,11,
  108071. };
  108072. static static_codebook _huff_book_line_1024x27_3sub2 = {
  108073. 1, 50,
  108074. _huff_lengthlist_line_1024x27_3sub2,
  108075. 0, 0, 0, 0, 0,
  108076. NULL,
  108077. NULL,
  108078. NULL,
  108079. NULL,
  108080. 0
  108081. };
  108082. static long _huff_lengthlist_line_1024x27_3sub3[] = {
  108083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108086. 0, 0, 3, 7, 3, 8, 3,10, 3, 8, 3, 9, 3, 8, 4, 9,
  108087. 4, 9, 5, 9, 6,10, 6, 9, 7,11, 7,12, 9,13,10,13,
  108088. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  108089. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  108090. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  108091. };
  108092. static static_codebook _huff_book_line_1024x27_3sub3 = {
  108093. 1, 128,
  108094. _huff_lengthlist_line_1024x27_3sub3,
  108095. 0, 0, 0, 0, 0,
  108096. NULL,
  108097. NULL,
  108098. NULL,
  108099. NULL,
  108100. 0
  108101. };
  108102. static long _huff_lengthlist_line_1024x27_4sub1[] = {
  108103. 0, 4, 5, 4, 5, 4, 5, 4, 5, 3, 5, 3, 5, 3, 5, 4,
  108104. 5, 4,
  108105. };
  108106. static static_codebook _huff_book_line_1024x27_4sub1 = {
  108107. 1, 18,
  108108. _huff_lengthlist_line_1024x27_4sub1,
  108109. 0, 0, 0, 0, 0,
  108110. NULL,
  108111. NULL,
  108112. NULL,
  108113. NULL,
  108114. 0
  108115. };
  108116. static long _huff_lengthlist_line_1024x27_4sub2[] = {
  108117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108118. 0, 0, 4, 2, 4, 2, 5, 3, 5, 4, 6, 6, 6, 7, 7, 8,
  108119. 7, 8, 7, 8, 7, 9, 8, 9, 8, 9, 8,10, 8,11, 9,12,
  108120. 9,12,
  108121. };
  108122. static static_codebook _huff_book_line_1024x27_4sub2 = {
  108123. 1, 50,
  108124. _huff_lengthlist_line_1024x27_4sub2,
  108125. 0, 0, 0, 0, 0,
  108126. NULL,
  108127. NULL,
  108128. NULL,
  108129. NULL,
  108130. 0
  108131. };
  108132. static long _huff_lengthlist_line_1024x27_4sub3[] = {
  108133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108134. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108135. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108136. 0, 0, 2, 5, 2, 6, 3, 6, 4, 7, 4, 7, 5, 9, 5,11,
  108137. 6,11, 6,11, 7,11, 6,11, 6,11, 9,11, 8,11,11,11,
  108138. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  108139. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  108140. 11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,
  108141. };
  108142. static static_codebook _huff_book_line_1024x27_4sub3 = {
  108143. 1, 128,
  108144. _huff_lengthlist_line_1024x27_4sub3,
  108145. 0, 0, 0, 0, 0,
  108146. NULL,
  108147. NULL,
  108148. NULL,
  108149. NULL,
  108150. 0
  108151. };
  108152. static long _huff_lengthlist_line_2048x27_class1[] = {
  108153. 2, 6, 8, 9, 7,11,13,13, 1, 3, 5, 5, 6, 6,12,10,
  108154. };
  108155. static static_codebook _huff_book_line_2048x27_class1 = {
  108156. 1, 16,
  108157. _huff_lengthlist_line_2048x27_class1,
  108158. 0, 0, 0, 0, 0,
  108159. NULL,
  108160. NULL,
  108161. NULL,
  108162. NULL,
  108163. 0
  108164. };
  108165. static long _huff_lengthlist_line_2048x27_class2[] = {
  108166. 1, 2, 3, 6, 4, 7, 5, 7,
  108167. };
  108168. static static_codebook _huff_book_line_2048x27_class2 = {
  108169. 1, 8,
  108170. _huff_lengthlist_line_2048x27_class2,
  108171. 0, 0, 0, 0, 0,
  108172. NULL,
  108173. NULL,
  108174. NULL,
  108175. NULL,
  108176. 0
  108177. };
  108178. static long _huff_lengthlist_line_2048x27_class3[] = {
  108179. 3, 3, 6,16, 5, 5, 7,16, 9, 8,11,16,16,16,16,16,
  108180. 5, 5, 8,16, 5, 5, 7,16, 8, 7, 9,16,16,16,16,16,
  108181. 9, 9,12,16, 6, 8,11,16, 9,10,11,16,16,16,16,16,
  108182. 16,16,16,16,13,16,16,16,15,16,16,16,16,16,16,16,
  108183. 5, 4, 7,16, 6, 5, 8,16, 9, 8,10,16,16,16,16,16,
  108184. 5, 5, 7,15, 5, 4, 6,15, 7, 6, 8,16,16,16,16,16,
  108185. 9, 9,11,15, 7, 7, 9,16, 8, 8, 9,16,16,16,16,16,
  108186. 16,16,16,16,15,15,15,16,15,15,14,16,16,16,16,16,
  108187. 8, 8,11,16, 8, 9,10,16,11,10,14,16,16,16,16,16,
  108188. 6, 8,10,16, 6, 7,10,16, 8, 8,11,16,14,16,16,16,
  108189. 10,11,14,16, 9, 9,11,16,10,10,11,16,16,16,16,16,
  108190. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
  108191. 16,16,16,16,15,16,16,16,16,16,16,16,16,16,16,16,
  108192. 12,16,15,16,12,14,16,16,16,16,16,16,16,16,16,16,
  108193. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
  108194. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
  108195. };
  108196. static static_codebook _huff_book_line_2048x27_class3 = {
  108197. 1, 256,
  108198. _huff_lengthlist_line_2048x27_class3,
  108199. 0, 0, 0, 0, 0,
  108200. NULL,
  108201. NULL,
  108202. NULL,
  108203. NULL,
  108204. 0
  108205. };
  108206. static long _huff_lengthlist_line_2048x27_class4[] = {
  108207. 2, 4, 7,13, 4, 5, 7,15, 8, 7,10,16,16,14,16,16,
  108208. 2, 4, 7,16, 3, 4, 7,14, 8, 8,10,16,16,16,15,16,
  108209. 6, 8,11,16, 7, 7, 9,16,11, 9,13,16,16,16,15,16,
  108210. 16,16,16,16,14,16,16,16,16,16,16,16,16,16,16,16,
  108211. };
  108212. static static_codebook _huff_book_line_2048x27_class4 = {
  108213. 1, 64,
  108214. _huff_lengthlist_line_2048x27_class4,
  108215. 0, 0, 0, 0, 0,
  108216. NULL,
  108217. NULL,
  108218. NULL,
  108219. NULL,
  108220. 0
  108221. };
  108222. static long _huff_lengthlist_line_2048x27_0sub0[] = {
  108223. 5, 5, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  108224. 6, 5, 7, 5, 7, 5, 7, 5, 8, 5, 8, 5, 8, 5, 9, 5,
  108225. 9, 6,10, 6,10, 6,11, 6,11, 6,11, 6,11, 6,11, 6,
  108226. 11, 6,11, 6,12, 7,11, 7,11, 7,11, 7,11, 7,10, 7,
  108227. 11, 7,11, 7,12, 7,11, 8,11, 8,11, 8,11, 8,13, 8,
  108228. 12, 9,11, 9,11, 9,11,10,12,10,12, 9,12,10,12,11,
  108229. 14,12,16,12,12,11,14,16,17,17,17,17,17,17,17,17,
  108230. 17,17,17,17,17,17,17,17,17,17,17,17,16,16,16,16,
  108231. };
  108232. static static_codebook _huff_book_line_2048x27_0sub0 = {
  108233. 1, 128,
  108234. _huff_lengthlist_line_2048x27_0sub0,
  108235. 0, 0, 0, 0, 0,
  108236. NULL,
  108237. NULL,
  108238. NULL,
  108239. NULL,
  108240. 0
  108241. };
  108242. static long _huff_lengthlist_line_2048x27_1sub0[] = {
  108243. 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5,
  108244. 5, 5, 6, 6, 6, 6, 6, 6, 7, 6, 7, 6, 7, 6, 7, 6,
  108245. };
  108246. static static_codebook _huff_book_line_2048x27_1sub0 = {
  108247. 1, 32,
  108248. _huff_lengthlist_line_2048x27_1sub0,
  108249. 0, 0, 0, 0, 0,
  108250. NULL,
  108251. NULL,
  108252. NULL,
  108253. NULL,
  108254. 0
  108255. };
  108256. static long _huff_lengthlist_line_2048x27_1sub1[] = {
  108257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108258. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108259. 6, 5, 7, 5, 7, 4, 7, 4, 8, 4, 8, 4, 8, 4, 8, 3,
  108260. 8, 4, 9, 4, 9, 4, 9, 4, 9, 4, 9, 5, 9, 5, 9, 6,
  108261. 9, 7, 9, 8, 9, 9, 9,10, 9,11, 9,14, 9,15,10,15,
  108262. 10,15,10,15,10,15,11,15,10,14,12,14,11,14,13,14,
  108263. 13,15,15,15,12,15,15,15,13,15,13,15,13,15,15,15,
  108264. 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,14,
  108265. };
  108266. static static_codebook _huff_book_line_2048x27_1sub1 = {
  108267. 1, 128,
  108268. _huff_lengthlist_line_2048x27_1sub1,
  108269. 0, 0, 0, 0, 0,
  108270. NULL,
  108271. NULL,
  108272. NULL,
  108273. NULL,
  108274. 0
  108275. };
  108276. static long _huff_lengthlist_line_2048x27_2sub0[] = {
  108277. 2, 4, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 5, 5, 6, 5,
  108278. 6, 5, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,
  108279. };
  108280. static static_codebook _huff_book_line_2048x27_2sub0 = {
  108281. 1, 32,
  108282. _huff_lengthlist_line_2048x27_2sub0,
  108283. 0, 0, 0, 0, 0,
  108284. NULL,
  108285. NULL,
  108286. NULL,
  108287. NULL,
  108288. 0
  108289. };
  108290. static long _huff_lengthlist_line_2048x27_2sub1[] = {
  108291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108293. 3, 4, 3, 4, 3, 4, 4, 5, 4, 5, 5, 5, 6, 6, 6, 7,
  108294. 6, 8, 6, 8, 6, 9, 7,10, 7,10, 7,10, 7,12, 7,12,
  108295. 7,12, 9,12,11,12,10,12,10,12,11,12,12,12,10,12,
  108296. 10,12,10,12, 9,12,11,12,12,12,12,12,11,12,11,12,
  108297. 12,12,12,12,12,12,12,12,10,10,12,12,12,12,12,10,
  108298. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  108299. };
  108300. static static_codebook _huff_book_line_2048x27_2sub1 = {
  108301. 1, 128,
  108302. _huff_lengthlist_line_2048x27_2sub1,
  108303. 0, 0, 0, 0, 0,
  108304. NULL,
  108305. NULL,
  108306. NULL,
  108307. NULL,
  108308. 0
  108309. };
  108310. static long _huff_lengthlist_line_2048x27_3sub1[] = {
  108311. 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
  108312. 5, 5,
  108313. };
  108314. static static_codebook _huff_book_line_2048x27_3sub1 = {
  108315. 1, 18,
  108316. _huff_lengthlist_line_2048x27_3sub1,
  108317. 0, 0, 0, 0, 0,
  108318. NULL,
  108319. NULL,
  108320. NULL,
  108321. NULL,
  108322. 0
  108323. };
  108324. static long _huff_lengthlist_line_2048x27_3sub2[] = {
  108325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108326. 0, 0, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6,
  108327. 6, 7, 6, 7, 6, 8, 6, 9, 7, 9, 7, 9, 9,11, 9,12,
  108328. 10,12,
  108329. };
  108330. static static_codebook _huff_book_line_2048x27_3sub2 = {
  108331. 1, 50,
  108332. _huff_lengthlist_line_2048x27_3sub2,
  108333. 0, 0, 0, 0, 0,
  108334. NULL,
  108335. NULL,
  108336. NULL,
  108337. NULL,
  108338. 0
  108339. };
  108340. static long _huff_lengthlist_line_2048x27_3sub3[] = {
  108341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108344. 0, 0, 3, 6, 3, 7, 3, 7, 5, 7, 7, 7, 7, 7, 6, 7,
  108345. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  108346. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  108347. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  108348. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  108349. };
  108350. static static_codebook _huff_book_line_2048x27_3sub3 = {
  108351. 1, 128,
  108352. _huff_lengthlist_line_2048x27_3sub3,
  108353. 0, 0, 0, 0, 0,
  108354. NULL,
  108355. NULL,
  108356. NULL,
  108357. NULL,
  108358. 0
  108359. };
  108360. static long _huff_lengthlist_line_2048x27_4sub1[] = {
  108361. 0, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5, 4, 5, 4, 5, 4,
  108362. 4, 5,
  108363. };
  108364. static static_codebook _huff_book_line_2048x27_4sub1 = {
  108365. 1, 18,
  108366. _huff_lengthlist_line_2048x27_4sub1,
  108367. 0, 0, 0, 0, 0,
  108368. NULL,
  108369. NULL,
  108370. NULL,
  108371. NULL,
  108372. 0
  108373. };
  108374. static long _huff_lengthlist_line_2048x27_4sub2[] = {
  108375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108376. 0, 0, 3, 2, 4, 3, 4, 4, 4, 5, 5, 6, 5, 6, 5, 7,
  108377. 6, 6, 6, 7, 7, 7, 8, 9, 9, 9,12,10,11,10,10,12,
  108378. 10,10,
  108379. };
  108380. static static_codebook _huff_book_line_2048x27_4sub2 = {
  108381. 1, 50,
  108382. _huff_lengthlist_line_2048x27_4sub2,
  108383. 0, 0, 0, 0, 0,
  108384. NULL,
  108385. NULL,
  108386. NULL,
  108387. NULL,
  108388. 0
  108389. };
  108390. static long _huff_lengthlist_line_2048x27_4sub3[] = {
  108391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108394. 0, 0, 3, 6, 5, 7, 5, 7, 7, 7, 7, 7, 5, 7, 5, 7,
  108395. 5, 7, 5, 7, 7, 7, 7, 7, 4, 7, 7, 7, 7, 7, 7, 7,
  108396. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  108397. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  108398. 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  108399. };
  108400. static static_codebook _huff_book_line_2048x27_4sub3 = {
  108401. 1, 128,
  108402. _huff_lengthlist_line_2048x27_4sub3,
  108403. 0, 0, 0, 0, 0,
  108404. NULL,
  108405. NULL,
  108406. NULL,
  108407. NULL,
  108408. 0
  108409. };
  108410. static long _huff_lengthlist_line_256x4low_class0[] = {
  108411. 4, 5, 6,11, 5, 5, 6,10, 7, 7, 6, 6,14,13, 9, 9,
  108412. 6, 6, 6,10, 6, 6, 6, 9, 8, 7, 7, 9,14,12, 8,11,
  108413. 8, 7, 7,11, 8, 8, 7,11, 9, 9, 7, 9,13,11, 9,13,
  108414. 19,19,18,19,15,16,16,19,11,11,10,13,10,10, 9,15,
  108415. 5, 5, 6,13, 6, 6, 6,11, 8, 7, 6, 7,14,11,10,11,
  108416. 6, 6, 6,12, 7, 6, 6,11, 8, 7, 7,11,13,11, 9,11,
  108417. 9, 7, 6,12, 8, 7, 6,12, 9, 8, 8,11,13,10, 7,13,
  108418. 19,19,17,19,17,14,14,19,12,10, 8,12,13,10, 9,16,
  108419. 7, 8, 7,12, 7, 7, 7,11, 8, 7, 7, 8,12,12,11,11,
  108420. 8, 8, 7,12, 8, 7, 6,11, 8, 7, 7,10,10,11,10,11,
  108421. 9, 8, 8,13, 9, 8, 7,12,10, 9, 7,11, 9, 8, 7,11,
  108422. 18,18,15,18,18,16,17,18,15,11,10,18,11, 9, 9,18,
  108423. 16,16,13,16,12,11,10,16,12,11, 9, 6,15,12,11,13,
  108424. 16,16,14,14,13,11,12,16,12, 9, 9,13,13,10,10,12,
  108425. 17,18,17,17,14,15,14,16,14,12,14,15,12,10,11,12,
  108426. 18,18,18,18,18,18,18,18,18,12,13,18,16,11, 9,18,
  108427. };
  108428. static static_codebook _huff_book_line_256x4low_class0 = {
  108429. 1, 256,
  108430. _huff_lengthlist_line_256x4low_class0,
  108431. 0, 0, 0, 0, 0,
  108432. NULL,
  108433. NULL,
  108434. NULL,
  108435. NULL,
  108436. 0
  108437. };
  108438. static long _huff_lengthlist_line_256x4low_0sub0[] = {
  108439. 1, 3, 2, 3,
  108440. };
  108441. static static_codebook _huff_book_line_256x4low_0sub0 = {
  108442. 1, 4,
  108443. _huff_lengthlist_line_256x4low_0sub0,
  108444. 0, 0, 0, 0, 0,
  108445. NULL,
  108446. NULL,
  108447. NULL,
  108448. NULL,
  108449. 0
  108450. };
  108451. static long _huff_lengthlist_line_256x4low_0sub1[] = {
  108452. 0, 0, 0, 0, 2, 3, 2, 3, 3, 3,
  108453. };
  108454. static static_codebook _huff_book_line_256x4low_0sub1 = {
  108455. 1, 10,
  108456. _huff_lengthlist_line_256x4low_0sub1,
  108457. 0, 0, 0, 0, 0,
  108458. NULL,
  108459. NULL,
  108460. NULL,
  108461. NULL,
  108462. 0
  108463. };
  108464. static long _huff_lengthlist_line_256x4low_0sub2[] = {
  108465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 4, 3, 4,
  108466. 4, 4, 4, 4, 5, 5, 5, 6, 6,
  108467. };
  108468. static static_codebook _huff_book_line_256x4low_0sub2 = {
  108469. 1, 25,
  108470. _huff_lengthlist_line_256x4low_0sub2,
  108471. 0, 0, 0, 0, 0,
  108472. NULL,
  108473. NULL,
  108474. NULL,
  108475. NULL,
  108476. 0
  108477. };
  108478. static long _huff_lengthlist_line_256x4low_0sub3[] = {
  108479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 4, 2, 4, 3, 5, 4,
  108481. 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 7, 7, 8, 6, 9,
  108482. 7,12,11,16,13,16,12,15,13,15,12,14,12,15,15,15,
  108483. };
  108484. static static_codebook _huff_book_line_256x4low_0sub3 = {
  108485. 1, 64,
  108486. _huff_lengthlist_line_256x4low_0sub3,
  108487. 0, 0, 0, 0, 0,
  108488. NULL,
  108489. NULL,
  108490. NULL,
  108491. NULL,
  108492. 0
  108493. };
  108494. /*** End of inlined file: floor_books.h ***/
  108495. static static_codebook *_floor_128x4_books[]={
  108496. &_huff_book_line_128x4_class0,
  108497. &_huff_book_line_128x4_0sub0,
  108498. &_huff_book_line_128x4_0sub1,
  108499. &_huff_book_line_128x4_0sub2,
  108500. &_huff_book_line_128x4_0sub3,
  108501. };
  108502. static static_codebook *_floor_256x4_books[]={
  108503. &_huff_book_line_256x4_class0,
  108504. &_huff_book_line_256x4_0sub0,
  108505. &_huff_book_line_256x4_0sub1,
  108506. &_huff_book_line_256x4_0sub2,
  108507. &_huff_book_line_256x4_0sub3,
  108508. };
  108509. static static_codebook *_floor_128x7_books[]={
  108510. &_huff_book_line_128x7_class0,
  108511. &_huff_book_line_128x7_class1,
  108512. &_huff_book_line_128x7_0sub1,
  108513. &_huff_book_line_128x7_0sub2,
  108514. &_huff_book_line_128x7_0sub3,
  108515. &_huff_book_line_128x7_1sub1,
  108516. &_huff_book_line_128x7_1sub2,
  108517. &_huff_book_line_128x7_1sub3,
  108518. };
  108519. static static_codebook *_floor_256x7_books[]={
  108520. &_huff_book_line_256x7_class0,
  108521. &_huff_book_line_256x7_class1,
  108522. &_huff_book_line_256x7_0sub1,
  108523. &_huff_book_line_256x7_0sub2,
  108524. &_huff_book_line_256x7_0sub3,
  108525. &_huff_book_line_256x7_1sub1,
  108526. &_huff_book_line_256x7_1sub2,
  108527. &_huff_book_line_256x7_1sub3,
  108528. };
  108529. static static_codebook *_floor_128x11_books[]={
  108530. &_huff_book_line_128x11_class1,
  108531. &_huff_book_line_128x11_class2,
  108532. &_huff_book_line_128x11_class3,
  108533. &_huff_book_line_128x11_0sub0,
  108534. &_huff_book_line_128x11_1sub0,
  108535. &_huff_book_line_128x11_1sub1,
  108536. &_huff_book_line_128x11_2sub1,
  108537. &_huff_book_line_128x11_2sub2,
  108538. &_huff_book_line_128x11_2sub3,
  108539. &_huff_book_line_128x11_3sub1,
  108540. &_huff_book_line_128x11_3sub2,
  108541. &_huff_book_line_128x11_3sub3,
  108542. };
  108543. static static_codebook *_floor_128x17_books[]={
  108544. &_huff_book_line_128x17_class1,
  108545. &_huff_book_line_128x17_class2,
  108546. &_huff_book_line_128x17_class3,
  108547. &_huff_book_line_128x17_0sub0,
  108548. &_huff_book_line_128x17_1sub0,
  108549. &_huff_book_line_128x17_1sub1,
  108550. &_huff_book_line_128x17_2sub1,
  108551. &_huff_book_line_128x17_2sub2,
  108552. &_huff_book_line_128x17_2sub3,
  108553. &_huff_book_line_128x17_3sub1,
  108554. &_huff_book_line_128x17_3sub2,
  108555. &_huff_book_line_128x17_3sub3,
  108556. };
  108557. static static_codebook *_floor_256x4low_books[]={
  108558. &_huff_book_line_256x4low_class0,
  108559. &_huff_book_line_256x4low_0sub0,
  108560. &_huff_book_line_256x4low_0sub1,
  108561. &_huff_book_line_256x4low_0sub2,
  108562. &_huff_book_line_256x4low_0sub3,
  108563. };
  108564. static static_codebook *_floor_1024x27_books[]={
  108565. &_huff_book_line_1024x27_class1,
  108566. &_huff_book_line_1024x27_class2,
  108567. &_huff_book_line_1024x27_class3,
  108568. &_huff_book_line_1024x27_class4,
  108569. &_huff_book_line_1024x27_0sub0,
  108570. &_huff_book_line_1024x27_1sub0,
  108571. &_huff_book_line_1024x27_1sub1,
  108572. &_huff_book_line_1024x27_2sub0,
  108573. &_huff_book_line_1024x27_2sub1,
  108574. &_huff_book_line_1024x27_3sub1,
  108575. &_huff_book_line_1024x27_3sub2,
  108576. &_huff_book_line_1024x27_3sub3,
  108577. &_huff_book_line_1024x27_4sub1,
  108578. &_huff_book_line_1024x27_4sub2,
  108579. &_huff_book_line_1024x27_4sub3,
  108580. };
  108581. static static_codebook *_floor_2048x27_books[]={
  108582. &_huff_book_line_2048x27_class1,
  108583. &_huff_book_line_2048x27_class2,
  108584. &_huff_book_line_2048x27_class3,
  108585. &_huff_book_line_2048x27_class4,
  108586. &_huff_book_line_2048x27_0sub0,
  108587. &_huff_book_line_2048x27_1sub0,
  108588. &_huff_book_line_2048x27_1sub1,
  108589. &_huff_book_line_2048x27_2sub0,
  108590. &_huff_book_line_2048x27_2sub1,
  108591. &_huff_book_line_2048x27_3sub1,
  108592. &_huff_book_line_2048x27_3sub2,
  108593. &_huff_book_line_2048x27_3sub3,
  108594. &_huff_book_line_2048x27_4sub1,
  108595. &_huff_book_line_2048x27_4sub2,
  108596. &_huff_book_line_2048x27_4sub3,
  108597. };
  108598. static static_codebook *_floor_512x17_books[]={
  108599. &_huff_book_line_512x17_class1,
  108600. &_huff_book_line_512x17_class2,
  108601. &_huff_book_line_512x17_class3,
  108602. &_huff_book_line_512x17_0sub0,
  108603. &_huff_book_line_512x17_1sub0,
  108604. &_huff_book_line_512x17_1sub1,
  108605. &_huff_book_line_512x17_2sub1,
  108606. &_huff_book_line_512x17_2sub2,
  108607. &_huff_book_line_512x17_2sub3,
  108608. &_huff_book_line_512x17_3sub1,
  108609. &_huff_book_line_512x17_3sub2,
  108610. &_huff_book_line_512x17_3sub3,
  108611. };
  108612. static static_codebook **_floor_books[10]={
  108613. _floor_128x4_books,
  108614. _floor_256x4_books,
  108615. _floor_128x7_books,
  108616. _floor_256x7_books,
  108617. _floor_128x11_books,
  108618. _floor_128x17_books,
  108619. _floor_256x4low_books,
  108620. _floor_1024x27_books,
  108621. _floor_2048x27_books,
  108622. _floor_512x17_books,
  108623. };
  108624. static vorbis_info_floor1 _floor[10]={
  108625. {
  108626. 1,{0},{4},{2},{0},
  108627. {{1,2,3,4}},
  108628. 4,{0,128, 33,8,16,70},
  108629. 60,30,500, 1.,18., -1
  108630. },
  108631. {
  108632. 1,{0},{4},{2},{0},
  108633. {{1,2,3,4}},
  108634. 4,{0,256, 66,16,32,140},
  108635. 60,30,500, 1.,18., -1
  108636. },
  108637. {
  108638. 2,{0,1},{3,4},{2,2},{0,1},
  108639. {{-1,2,3,4},{-1,5,6,7}},
  108640. 4,{0,128, 14,4,58, 2,8,28,90},
  108641. 60,30,500, 1.,18., -1
  108642. },
  108643. {
  108644. 2,{0,1},{3,4},{2,2},{0,1},
  108645. {{-1,2,3,4},{-1,5,6,7}},
  108646. 4,{0,256, 28,8,116, 4,16,56,180},
  108647. 60,30,500, 1.,18., -1
  108648. },
  108649. {
  108650. 4,{0,1,2,3},{2,3,3,3},{0,1,2,2},{-1,0,1,2},
  108651. {{3},{4,5},{-1,6,7,8},{-1,9,10,11}},
  108652. 2,{0,128, 8,33, 4,16,70, 2,6,12, 23,46,90},
  108653. 60,30,500, 1,18., -1
  108654. },
  108655. {
  108656. 6,{0,1,1,2,3,3},{2,3,3,3},{0,1,2,2},{-1,0,1,2},
  108657. {{3},{4,5},{-1,6,7,8},{-1,9,10,11}},
  108658. 2,{0,128, 12,46, 4,8,16, 23,33,70, 2,6,10, 14,19,28, 39,58,90},
  108659. 60,30,500, 1,18., -1
  108660. },
  108661. {
  108662. 1,{0},{4},{2},{0},
  108663. {{1,2,3,4}},
  108664. 4,{0,256, 66,16,32,140},
  108665. 60,30,500, 1.,18., -1
  108666. },
  108667. {
  108668. 8,{0,1,2,2,3,3,4,4},{3,4,3,4,3},{0,1,1,2,2},{-1,0,1,2,3},
  108669. {{4},{5,6},{7,8},{-1,9,10,11},{-1,12,13,14}},
  108670. 2,{0,1024, 93,23,372, 6,46,186,750, 14,33,65, 130,260,556,
  108671. 3,10,18,28, 39,55,79,111, 158,220,312, 464,650,850},
  108672. 60,30,500, 3,18., -1 /* lowpass */
  108673. },
  108674. {
  108675. 8,{0,1,2,2,3,3,4,4},{3,4,3,4,3},{0,1,1,2,2},{-1,0,1,2,3},
  108676. {{4},{5,6},{7,8},{-1,9,10,11},{-1,12,13,14}},
  108677. 2,{0,2048, 186,46,744, 12,92,372,1500, 28,66,130, 260,520,1112,
  108678. 6,20,36,56, 78,110,158,222, 316,440,624, 928,1300,1700},
  108679. 60,30,500, 3,18., -1 /* lowpass */
  108680. },
  108681. {
  108682. 6,{0,1,1,2,3,3},{2,3,3,3},{0,1,2,2},{-1,0,1,2},
  108683. {{3},{4,5},{-1,6,7,8},{-1,9,10,11}},
  108684. 2,{0,512, 46,186, 16,33,65, 93,130,278,
  108685. 7,23,39, 55,79,110, 156,232,360},
  108686. 60,30,500, 1,18., -1 /* lowpass! */
  108687. },
  108688. };
  108689. /*** End of inlined file: floor_all.h ***/
  108690. /*** Start of inlined file: residue_44.h ***/
  108691. /*** Start of inlined file: res_books_stereo.h ***/
  108692. static long _vq_quantlist__16c0_s_p1_0[] = {
  108693. 1,
  108694. 0,
  108695. 2,
  108696. };
  108697. static long _vq_lengthlist__16c0_s_p1_0[] = {
  108698. 1, 4, 4, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  108699. 0, 0, 5, 7, 7, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9,10, 0, 0, 0,
  108704. 0, 0, 0, 7, 9,10, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  108709. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0, 0, 0, 0,
  108744. 0, 0, 8,10,10, 0, 0, 0, 0, 0, 0, 8,10,10, 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, 7,10,10, 0, 0, 0,
  108749. 0, 0, 0, 9, 9,12, 0, 0, 0, 0, 0, 0,10,12,11, 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, 7,10,10, 0, 0,
  108754. 0, 0, 0, 0, 9,12,10, 0, 0, 0, 0, 0, 0,10,11,12,
  108755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108789. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0,
  108790. 0, 0, 0, 0, 8,10,10, 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, 7,10,10, 0, 0, 0, 0, 0, 0,10,12,11, 0,
  108795. 0, 0, 0, 0, 0, 9,10,12, 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, 7,10,10, 0, 0, 0, 0, 0, 0,10,11,12,
  108800. 0, 0, 0, 0, 0, 0, 9,12, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109080. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109091. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109093. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109094. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109098. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109099. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109100. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109101. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109102. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109108. 0,
  109109. };
  109110. static float _vq_quantthresh__16c0_s_p1_0[] = {
  109111. -0.5, 0.5,
  109112. };
  109113. static long _vq_quantmap__16c0_s_p1_0[] = {
  109114. 1, 0, 2,
  109115. };
  109116. static encode_aux_threshmatch _vq_auxt__16c0_s_p1_0 = {
  109117. _vq_quantthresh__16c0_s_p1_0,
  109118. _vq_quantmap__16c0_s_p1_0,
  109119. 3,
  109120. 3
  109121. };
  109122. static static_codebook _16c0_s_p1_0 = {
  109123. 8, 6561,
  109124. _vq_lengthlist__16c0_s_p1_0,
  109125. 1, -535822336, 1611661312, 2, 0,
  109126. _vq_quantlist__16c0_s_p1_0,
  109127. NULL,
  109128. &_vq_auxt__16c0_s_p1_0,
  109129. NULL,
  109130. 0
  109131. };
  109132. static long _vq_quantlist__16c0_s_p2_0[] = {
  109133. 2,
  109134. 1,
  109135. 3,
  109136. 0,
  109137. 4,
  109138. };
  109139. static long _vq_lengthlist__16c0_s_p2_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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109151. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109152. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109153. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109154. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109155. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109156. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109159. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109160. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109161. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109162. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109163. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109164. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109166. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109167. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109170. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109171. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109172. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109173. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109174. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109177. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109178. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109179. 0,
  109180. };
  109181. static float _vq_quantthresh__16c0_s_p2_0[] = {
  109182. -1.5, -0.5, 0.5, 1.5,
  109183. };
  109184. static long _vq_quantmap__16c0_s_p2_0[] = {
  109185. 3, 1, 0, 2, 4,
  109186. };
  109187. static encode_aux_threshmatch _vq_auxt__16c0_s_p2_0 = {
  109188. _vq_quantthresh__16c0_s_p2_0,
  109189. _vq_quantmap__16c0_s_p2_0,
  109190. 5,
  109191. 5
  109192. };
  109193. static static_codebook _16c0_s_p2_0 = {
  109194. 4, 625,
  109195. _vq_lengthlist__16c0_s_p2_0,
  109196. 1, -533725184, 1611661312, 3, 0,
  109197. _vq_quantlist__16c0_s_p2_0,
  109198. NULL,
  109199. &_vq_auxt__16c0_s_p2_0,
  109200. NULL,
  109201. 0
  109202. };
  109203. static long _vq_quantlist__16c0_s_p3_0[] = {
  109204. 2,
  109205. 1,
  109206. 3,
  109207. 0,
  109208. 4,
  109209. };
  109210. static long _vq_lengthlist__16c0_s_p3_0[] = {
  109211. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 6, 6, 7, 6, 0, 0,
  109213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109214. 0, 0, 4, 6, 6, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  109216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109217. 0, 0, 0, 0, 6, 6, 6, 9, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109229. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109234. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109246. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109247. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109248. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109250. 0,
  109251. };
  109252. static float _vq_quantthresh__16c0_s_p3_0[] = {
  109253. -1.5, -0.5, 0.5, 1.5,
  109254. };
  109255. static long _vq_quantmap__16c0_s_p3_0[] = {
  109256. 3, 1, 0, 2, 4,
  109257. };
  109258. static encode_aux_threshmatch _vq_auxt__16c0_s_p3_0 = {
  109259. _vq_quantthresh__16c0_s_p3_0,
  109260. _vq_quantmap__16c0_s_p3_0,
  109261. 5,
  109262. 5
  109263. };
  109264. static static_codebook _16c0_s_p3_0 = {
  109265. 4, 625,
  109266. _vq_lengthlist__16c0_s_p3_0,
  109267. 1, -533725184, 1611661312, 3, 0,
  109268. _vq_quantlist__16c0_s_p3_0,
  109269. NULL,
  109270. &_vq_auxt__16c0_s_p3_0,
  109271. NULL,
  109272. 0
  109273. };
  109274. static long _vq_quantlist__16c0_s_p4_0[] = {
  109275. 4,
  109276. 3,
  109277. 5,
  109278. 2,
  109279. 6,
  109280. 1,
  109281. 7,
  109282. 0,
  109283. 8,
  109284. };
  109285. static long _vq_lengthlist__16c0_s_p4_0[] = {
  109286. 1, 3, 2, 7, 8, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  109287. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  109288. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  109289. 8, 8, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  109290. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109291. 0,
  109292. };
  109293. static float _vq_quantthresh__16c0_s_p4_0[] = {
  109294. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  109295. };
  109296. static long _vq_quantmap__16c0_s_p4_0[] = {
  109297. 7, 5, 3, 1, 0, 2, 4, 6,
  109298. 8,
  109299. };
  109300. static encode_aux_threshmatch _vq_auxt__16c0_s_p4_0 = {
  109301. _vq_quantthresh__16c0_s_p4_0,
  109302. _vq_quantmap__16c0_s_p4_0,
  109303. 9,
  109304. 9
  109305. };
  109306. static static_codebook _16c0_s_p4_0 = {
  109307. 2, 81,
  109308. _vq_lengthlist__16c0_s_p4_0,
  109309. 1, -531628032, 1611661312, 4, 0,
  109310. _vq_quantlist__16c0_s_p4_0,
  109311. NULL,
  109312. &_vq_auxt__16c0_s_p4_0,
  109313. NULL,
  109314. 0
  109315. };
  109316. static long _vq_quantlist__16c0_s_p5_0[] = {
  109317. 4,
  109318. 3,
  109319. 5,
  109320. 2,
  109321. 6,
  109322. 1,
  109323. 7,
  109324. 0,
  109325. 8,
  109326. };
  109327. static long _vq_lengthlist__16c0_s_p5_0[] = {
  109328. 1, 3, 3, 6, 6, 6, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  109329. 8, 8, 0, 0, 0, 7, 7, 7, 7, 8, 8, 0, 0, 0, 7, 7,
  109330. 8, 8, 9, 9, 0, 0, 0, 7, 7, 8, 8, 9, 9, 0, 0, 0,
  109331. 8, 9, 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0,
  109332. 0, 0,10,10, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  109333. 10,
  109334. };
  109335. static float _vq_quantthresh__16c0_s_p5_0[] = {
  109336. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  109337. };
  109338. static long _vq_quantmap__16c0_s_p5_0[] = {
  109339. 7, 5, 3, 1, 0, 2, 4, 6,
  109340. 8,
  109341. };
  109342. static encode_aux_threshmatch _vq_auxt__16c0_s_p5_0 = {
  109343. _vq_quantthresh__16c0_s_p5_0,
  109344. _vq_quantmap__16c0_s_p5_0,
  109345. 9,
  109346. 9
  109347. };
  109348. static static_codebook _16c0_s_p5_0 = {
  109349. 2, 81,
  109350. _vq_lengthlist__16c0_s_p5_0,
  109351. 1, -531628032, 1611661312, 4, 0,
  109352. _vq_quantlist__16c0_s_p5_0,
  109353. NULL,
  109354. &_vq_auxt__16c0_s_p5_0,
  109355. NULL,
  109356. 0
  109357. };
  109358. static long _vq_quantlist__16c0_s_p6_0[] = {
  109359. 8,
  109360. 7,
  109361. 9,
  109362. 6,
  109363. 10,
  109364. 5,
  109365. 11,
  109366. 4,
  109367. 12,
  109368. 3,
  109369. 13,
  109370. 2,
  109371. 14,
  109372. 1,
  109373. 15,
  109374. 0,
  109375. 16,
  109376. };
  109377. static long _vq_lengthlist__16c0_s_p6_0[] = {
  109378. 1, 3, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  109379. 11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,11,
  109380. 11,11, 0, 0, 0, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,
  109381. 11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  109382. 11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  109383. 10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  109384. 11,11,12,12,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  109385. 10,11,11,12,12,12,13, 0, 0, 0, 9, 9, 9, 9,10,10,
  109386. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,10,10,10,
  109387. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  109388. 10,10,11,11,12,12,13,13,13,13, 0, 0, 0, 0, 0, 9,
  109389. 9,10,10,11,11,12,12,13,13,13,14, 0, 0, 0, 0, 0,
  109390. 10,10,10,11,11,11,12,12,13,13,13,14, 0, 0, 0, 0,
  109391. 0, 0, 0,10,10,11,11,12,12,13,13,14,14, 0, 0, 0,
  109392. 0, 0, 0, 0,11,11,12,12,13,13,13,13,14,14, 0, 0,
  109393. 0, 0, 0, 0, 0,11,11,12,12,12,13,13,14,15,14, 0,
  109394. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,14,14,15,
  109395. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,14,13,14,
  109396. 14,
  109397. };
  109398. static float _vq_quantthresh__16c0_s_p6_0[] = {
  109399. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  109400. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  109401. };
  109402. static long _vq_quantmap__16c0_s_p6_0[] = {
  109403. 15, 13, 11, 9, 7, 5, 3, 1,
  109404. 0, 2, 4, 6, 8, 10, 12, 14,
  109405. 16,
  109406. };
  109407. static encode_aux_threshmatch _vq_auxt__16c0_s_p6_0 = {
  109408. _vq_quantthresh__16c0_s_p6_0,
  109409. _vq_quantmap__16c0_s_p6_0,
  109410. 17,
  109411. 17
  109412. };
  109413. static static_codebook _16c0_s_p6_0 = {
  109414. 2, 289,
  109415. _vq_lengthlist__16c0_s_p6_0,
  109416. 1, -529530880, 1611661312, 5, 0,
  109417. _vq_quantlist__16c0_s_p6_0,
  109418. NULL,
  109419. &_vq_auxt__16c0_s_p6_0,
  109420. NULL,
  109421. 0
  109422. };
  109423. static long _vq_quantlist__16c0_s_p7_0[] = {
  109424. 1,
  109425. 0,
  109426. 2,
  109427. };
  109428. static long _vq_lengthlist__16c0_s_p7_0[] = {
  109429. 1, 4, 4, 6, 6, 6, 7, 6, 6, 4, 7, 7,11,10,10,11,
  109430. 11,10, 4, 7, 7,10,10,10,11,10,10, 6,10,10,11,11,
  109431. 11,11,11,10, 6, 9, 9,11,12,12,11, 9, 9, 6, 9,10,
  109432. 11,12,12,11, 9,10, 7,11,11,11,11,11,12,13,12, 6,
  109433. 9,10,11,10,10,12,13,13, 6,10, 9,11,10,10,11,12,
  109434. 13,
  109435. };
  109436. static float _vq_quantthresh__16c0_s_p7_0[] = {
  109437. -5.5, 5.5,
  109438. };
  109439. static long _vq_quantmap__16c0_s_p7_0[] = {
  109440. 1, 0, 2,
  109441. };
  109442. static encode_aux_threshmatch _vq_auxt__16c0_s_p7_0 = {
  109443. _vq_quantthresh__16c0_s_p7_0,
  109444. _vq_quantmap__16c0_s_p7_0,
  109445. 3,
  109446. 3
  109447. };
  109448. static static_codebook _16c0_s_p7_0 = {
  109449. 4, 81,
  109450. _vq_lengthlist__16c0_s_p7_0,
  109451. 1, -529137664, 1618345984, 2, 0,
  109452. _vq_quantlist__16c0_s_p7_0,
  109453. NULL,
  109454. &_vq_auxt__16c0_s_p7_0,
  109455. NULL,
  109456. 0
  109457. };
  109458. static long _vq_quantlist__16c0_s_p7_1[] = {
  109459. 5,
  109460. 4,
  109461. 6,
  109462. 3,
  109463. 7,
  109464. 2,
  109465. 8,
  109466. 1,
  109467. 9,
  109468. 0,
  109469. 10,
  109470. };
  109471. static long _vq_lengthlist__16c0_s_p7_1[] = {
  109472. 1, 3, 4, 6, 6, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7,
  109473. 8, 8, 8, 9, 9, 9,10,10,10, 6, 7, 8, 8, 8, 8, 9,
  109474. 8,10,10,10, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10, 7,
  109475. 7, 8, 8, 9, 9, 8, 9,10,10,10, 8, 8, 9, 9, 9, 9,
  109476. 9, 9,11,11,11, 8, 8, 9, 9, 9, 9, 9,10,10,11,11,
  109477. 9, 9, 9, 9, 9, 9, 9,10,11,11,11,10,11, 9, 9, 9,
  109478. 9,10, 9,11,11,11,10,11,10,10, 9, 9,10,10,11,11,
  109479. 11,11,11, 9, 9, 9, 9,10,10,
  109480. };
  109481. static float _vq_quantthresh__16c0_s_p7_1[] = {
  109482. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  109483. 3.5, 4.5,
  109484. };
  109485. static long _vq_quantmap__16c0_s_p7_1[] = {
  109486. 9, 7, 5, 3, 1, 0, 2, 4,
  109487. 6, 8, 10,
  109488. };
  109489. static encode_aux_threshmatch _vq_auxt__16c0_s_p7_1 = {
  109490. _vq_quantthresh__16c0_s_p7_1,
  109491. _vq_quantmap__16c0_s_p7_1,
  109492. 11,
  109493. 11
  109494. };
  109495. static static_codebook _16c0_s_p7_1 = {
  109496. 2, 121,
  109497. _vq_lengthlist__16c0_s_p7_1,
  109498. 1, -531365888, 1611661312, 4, 0,
  109499. _vq_quantlist__16c0_s_p7_1,
  109500. NULL,
  109501. &_vq_auxt__16c0_s_p7_1,
  109502. NULL,
  109503. 0
  109504. };
  109505. static long _vq_quantlist__16c0_s_p8_0[] = {
  109506. 6,
  109507. 5,
  109508. 7,
  109509. 4,
  109510. 8,
  109511. 3,
  109512. 9,
  109513. 2,
  109514. 10,
  109515. 1,
  109516. 11,
  109517. 0,
  109518. 12,
  109519. };
  109520. static long _vq_lengthlist__16c0_s_p8_0[] = {
  109521. 1, 4, 4, 7, 7, 7, 7, 7, 6, 8, 8,10,10, 6, 5, 6,
  109522. 8, 8, 8, 8, 8, 8, 8, 9,10,10, 7, 6, 6, 8, 8, 8,
  109523. 8, 8, 8, 8, 8,10,10, 0, 8, 8, 8, 8, 9, 8, 9, 9,
  109524. 9,10,10,10, 0, 9, 8, 8, 8, 9, 9, 8, 8, 9, 9,10,
  109525. 10, 0,12,11, 8, 8, 9, 9, 9, 9,10,10,11,10, 0,12,
  109526. 13, 8, 8, 9,10, 9, 9,11,11,11,12, 0, 0, 0, 8, 8,
  109527. 8, 8,10, 9,12,13,12,14, 0, 0, 0, 8, 8, 8, 9,10,
  109528. 10,12,12,13,14, 0, 0, 0,13,13, 9, 9,11,11, 0, 0,
  109529. 14, 0, 0, 0, 0,14,14,10,10,12,11,12,14,14,14, 0,
  109530. 0, 0, 0, 0,11,11,13,13,14,13,14,14, 0, 0, 0, 0,
  109531. 0,12,13,13,12,13,14,14,14,
  109532. };
  109533. static float _vq_quantthresh__16c0_s_p8_0[] = {
  109534. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  109535. 12.5, 17.5, 22.5, 27.5,
  109536. };
  109537. static long _vq_quantmap__16c0_s_p8_0[] = {
  109538. 11, 9, 7, 5, 3, 1, 0, 2,
  109539. 4, 6, 8, 10, 12,
  109540. };
  109541. static encode_aux_threshmatch _vq_auxt__16c0_s_p8_0 = {
  109542. _vq_quantthresh__16c0_s_p8_0,
  109543. _vq_quantmap__16c0_s_p8_0,
  109544. 13,
  109545. 13
  109546. };
  109547. static static_codebook _16c0_s_p8_0 = {
  109548. 2, 169,
  109549. _vq_lengthlist__16c0_s_p8_0,
  109550. 1, -526516224, 1616117760, 4, 0,
  109551. _vq_quantlist__16c0_s_p8_0,
  109552. NULL,
  109553. &_vq_auxt__16c0_s_p8_0,
  109554. NULL,
  109555. 0
  109556. };
  109557. static long _vq_quantlist__16c0_s_p8_1[] = {
  109558. 2,
  109559. 1,
  109560. 3,
  109561. 0,
  109562. 4,
  109563. };
  109564. static long _vq_lengthlist__16c0_s_p8_1[] = {
  109565. 1, 4, 3, 5, 5, 7, 7, 7, 6, 6, 7, 7, 7, 5, 5, 7,
  109566. 7, 7, 6, 6, 7, 7, 7, 6, 6,
  109567. };
  109568. static float _vq_quantthresh__16c0_s_p8_1[] = {
  109569. -1.5, -0.5, 0.5, 1.5,
  109570. };
  109571. static long _vq_quantmap__16c0_s_p8_1[] = {
  109572. 3, 1, 0, 2, 4,
  109573. };
  109574. static encode_aux_threshmatch _vq_auxt__16c0_s_p8_1 = {
  109575. _vq_quantthresh__16c0_s_p8_1,
  109576. _vq_quantmap__16c0_s_p8_1,
  109577. 5,
  109578. 5
  109579. };
  109580. static static_codebook _16c0_s_p8_1 = {
  109581. 2, 25,
  109582. _vq_lengthlist__16c0_s_p8_1,
  109583. 1, -533725184, 1611661312, 3, 0,
  109584. _vq_quantlist__16c0_s_p8_1,
  109585. NULL,
  109586. &_vq_auxt__16c0_s_p8_1,
  109587. NULL,
  109588. 0
  109589. };
  109590. static long _vq_quantlist__16c0_s_p9_0[] = {
  109591. 1,
  109592. 0,
  109593. 2,
  109594. };
  109595. static long _vq_lengthlist__16c0_s_p9_0[] = {
  109596. 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  109597. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  109598. 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  109599. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  109600. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  109601. 7,
  109602. };
  109603. static float _vq_quantthresh__16c0_s_p9_0[] = {
  109604. -157.5, 157.5,
  109605. };
  109606. static long _vq_quantmap__16c0_s_p9_0[] = {
  109607. 1, 0, 2,
  109608. };
  109609. static encode_aux_threshmatch _vq_auxt__16c0_s_p9_0 = {
  109610. _vq_quantthresh__16c0_s_p9_0,
  109611. _vq_quantmap__16c0_s_p9_0,
  109612. 3,
  109613. 3
  109614. };
  109615. static static_codebook _16c0_s_p9_0 = {
  109616. 4, 81,
  109617. _vq_lengthlist__16c0_s_p9_0,
  109618. 1, -518803456, 1628680192, 2, 0,
  109619. _vq_quantlist__16c0_s_p9_0,
  109620. NULL,
  109621. &_vq_auxt__16c0_s_p9_0,
  109622. NULL,
  109623. 0
  109624. };
  109625. static long _vq_quantlist__16c0_s_p9_1[] = {
  109626. 7,
  109627. 6,
  109628. 8,
  109629. 5,
  109630. 9,
  109631. 4,
  109632. 10,
  109633. 3,
  109634. 11,
  109635. 2,
  109636. 12,
  109637. 1,
  109638. 13,
  109639. 0,
  109640. 14,
  109641. };
  109642. static long _vq_lengthlist__16c0_s_p9_1[] = {
  109643. 1, 5, 5, 5, 5, 9,11,11,10,10,10,10,10,10,10, 7,
  109644. 6, 6, 6, 6,10,10,10,10,10,10,10,10,10,10, 7, 6,
  109645. 6, 6, 6,10, 9,10,10,10,10,10,10,10,10,10, 7, 7,
  109646. 8, 9,10,10,10,10,10,10,10,10,10,10,10, 8, 7,10,
  109647. 10,10, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109648. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109649. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109650. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109651. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109652. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109653. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109654. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109655. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109656. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109657. 10,
  109658. };
  109659. static float _vq_quantthresh__16c0_s_p9_1[] = {
  109660. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  109661. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  109662. };
  109663. static long _vq_quantmap__16c0_s_p9_1[] = {
  109664. 13, 11, 9, 7, 5, 3, 1, 0,
  109665. 2, 4, 6, 8, 10, 12, 14,
  109666. };
  109667. static encode_aux_threshmatch _vq_auxt__16c0_s_p9_1 = {
  109668. _vq_quantthresh__16c0_s_p9_1,
  109669. _vq_quantmap__16c0_s_p9_1,
  109670. 15,
  109671. 15
  109672. };
  109673. static static_codebook _16c0_s_p9_1 = {
  109674. 2, 225,
  109675. _vq_lengthlist__16c0_s_p9_1,
  109676. 1, -520986624, 1620377600, 4, 0,
  109677. _vq_quantlist__16c0_s_p9_1,
  109678. NULL,
  109679. &_vq_auxt__16c0_s_p9_1,
  109680. NULL,
  109681. 0
  109682. };
  109683. static long _vq_quantlist__16c0_s_p9_2[] = {
  109684. 10,
  109685. 9,
  109686. 11,
  109687. 8,
  109688. 12,
  109689. 7,
  109690. 13,
  109691. 6,
  109692. 14,
  109693. 5,
  109694. 15,
  109695. 4,
  109696. 16,
  109697. 3,
  109698. 17,
  109699. 2,
  109700. 18,
  109701. 1,
  109702. 19,
  109703. 0,
  109704. 20,
  109705. };
  109706. static long _vq_lengthlist__16c0_s_p9_2[] = {
  109707. 1, 5, 5, 7, 8, 8, 7, 9, 9, 9,12,12,11,12,12,10,
  109708. 10,11,12,12,12,11,12,12, 8, 9, 8, 7, 9,10,10,11,
  109709. 11,10,11,12,10,12,10,12,12,12,11,12,11, 9, 8, 8,
  109710. 9,10, 9, 8, 9,10,12,12,11,11,12,11,10,11,12,11,
  109711. 12,12, 8, 9, 9, 9,10,11,12,11,12,11,11,11,11,12,
  109712. 12,11,11,12,12,11,11, 9, 9, 8, 9, 9,11, 9, 9,10,
  109713. 9,11,11,11,11,12,11,11,10,12,12,12, 9,12,11,10,
  109714. 11,11,11,11,12,12,12,11,11,11,12,10,12,12,12,10,
  109715. 10, 9,10, 9,10,10, 9, 9, 9,10,10,12,10,11,11, 9,
  109716. 11,11,10,11,11,11,10,10,10, 9, 9,10,10, 9, 9,10,
  109717. 11,11,10,11,10,11,10,11,11,10,11,11,11,10, 9,10,
  109718. 10, 9,10, 9, 9,11, 9, 9,11,10,10,11,11,10,10,11,
  109719. 10,11, 8, 9,11,11,10, 9,10,11,11,10,11,11,10,10,
  109720. 10,11,10, 9,10,10,11, 9,10,10, 9,11,10,10,10,10,
  109721. 11,10,11,11, 9,11,10,11,10,10,11,11,10,10,10, 9,
  109722. 10,10,11,11,11, 9,10,10,10,10,10,11,10,10,10, 9,
  109723. 10,10,11,10,10,10,10,10, 9,10,11,10,10,10,10,11,
  109724. 11,11,10,10,10,10,10,11,10,11,10,11,10,10,10, 9,
  109725. 11,11,10,10,10,11,11,10,10,10,10,10,10,10,10,11,
  109726. 11, 9,10,10,10,11,10,11,10,10,10,11, 9,10,11,10,
  109727. 11,10,10, 9,10,10,10,11,10,11,10,10,10,10,10,11,
  109728. 11,10,11,11,10,10,11,11,10, 9, 9,10,10,10,10,10,
  109729. 9,11, 9,10,10,10,11,11,10,10,10,10,11,11,11,10,
  109730. 9, 9,10,10,11,10,10,10,10,10,11,11,11,10,10,10,
  109731. 11,11,11, 9,10,10,10,10, 9,10, 9,10,11,10,11,10,
  109732. 10,11,11,10,11,11,11,11,11,10,11,10,10,10, 9,11,
  109733. 11,10,11,11,11,11,11,11,11,11,11,10,11,10,10,10,
  109734. 10,11,10,10,11, 9,10,10,10,
  109735. };
  109736. static float _vq_quantthresh__16c0_s_p9_2[] = {
  109737. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  109738. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  109739. 6.5, 7.5, 8.5, 9.5,
  109740. };
  109741. static long _vq_quantmap__16c0_s_p9_2[] = {
  109742. 19, 17, 15, 13, 11, 9, 7, 5,
  109743. 3, 1, 0, 2, 4, 6, 8, 10,
  109744. 12, 14, 16, 18, 20,
  109745. };
  109746. static encode_aux_threshmatch _vq_auxt__16c0_s_p9_2 = {
  109747. _vq_quantthresh__16c0_s_p9_2,
  109748. _vq_quantmap__16c0_s_p9_2,
  109749. 21,
  109750. 21
  109751. };
  109752. static static_codebook _16c0_s_p9_2 = {
  109753. 2, 441,
  109754. _vq_lengthlist__16c0_s_p9_2,
  109755. 1, -529268736, 1611661312, 5, 0,
  109756. _vq_quantlist__16c0_s_p9_2,
  109757. NULL,
  109758. &_vq_auxt__16c0_s_p9_2,
  109759. NULL,
  109760. 0
  109761. };
  109762. static long _huff_lengthlist__16c0_s_single[] = {
  109763. 3, 4,19, 7, 9, 7, 8,11, 9,12, 4, 1,19, 6, 7, 7,
  109764. 8,10,11,13,18,18,18,18,18,18,18,18,18,18, 8, 6,
  109765. 18, 8, 9, 9,11,12,14,18, 9, 6,18, 9, 7, 8, 9,11,
  109766. 12,18, 7, 6,18, 8, 7, 7, 7, 9,11,17, 8, 8,18, 9,
  109767. 7, 6, 6, 8,11,17,10,10,18,12, 9, 8, 7, 9,12,18,
  109768. 13,15,18,15,13,11,10,11,15,18,14,18,18,18,18,18,
  109769. 16,16,18,18,
  109770. };
  109771. static static_codebook _huff_book__16c0_s_single = {
  109772. 2, 100,
  109773. _huff_lengthlist__16c0_s_single,
  109774. 0, 0, 0, 0, 0,
  109775. NULL,
  109776. NULL,
  109777. NULL,
  109778. NULL,
  109779. 0
  109780. };
  109781. static long _huff_lengthlist__16c1_s_long[] = {
  109782. 2, 5,20, 7,10, 7, 8,10,11,11, 4, 2,20, 5, 8, 6,
  109783. 7, 9,10,10,20,20,20,20,19,19,19,19,19,19, 7, 5,
  109784. 19, 6,10, 7, 9,11,13,17,11, 8,19,10, 7, 7, 8,10,
  109785. 11,15, 7, 5,19, 7, 7, 5, 6, 9,11,16, 7, 6,19, 8,
  109786. 7, 6, 6, 7, 9,13, 9, 9,19,11, 9, 8, 6, 7, 8,13,
  109787. 12,14,19,16,13,10, 9, 8, 9,13,14,17,19,18,18,17,
  109788. 12,11,11,13,
  109789. };
  109790. static static_codebook _huff_book__16c1_s_long = {
  109791. 2, 100,
  109792. _huff_lengthlist__16c1_s_long,
  109793. 0, 0, 0, 0, 0,
  109794. NULL,
  109795. NULL,
  109796. NULL,
  109797. NULL,
  109798. 0
  109799. };
  109800. static long _vq_quantlist__16c1_s_p1_0[] = {
  109801. 1,
  109802. 0,
  109803. 2,
  109804. };
  109805. static long _vq_lengthlist__16c1_s_p1_0[] = {
  109806. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  109807. 0, 0, 5, 7, 7, 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, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  109812. 0, 0, 0, 7, 8, 9, 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, 5, 7, 8, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  109817. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 7, 0, 0, 0, 0,
  109852. 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 7, 9, 9, 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, 7, 9, 9, 0, 0, 0,
  109857. 0, 0, 0, 9, 9,11, 0, 0, 0, 0, 0, 0, 9,11,10, 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, 7, 9, 9, 0, 0,
  109862. 0, 0, 0, 0, 8,11, 9, 0, 0, 0, 0, 0, 0, 9,10,11,
  109863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109880. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109897. 0, 0, 5, 7, 8, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  109898. 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,11,10, 0,
  109903. 0, 0, 0, 0, 0, 8, 9,11, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,11,
  109908. 0, 0, 0, 0, 0, 0, 9,11, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110201. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110203. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110207. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110216. 0,
  110217. };
  110218. static float _vq_quantthresh__16c1_s_p1_0[] = {
  110219. -0.5, 0.5,
  110220. };
  110221. static long _vq_quantmap__16c1_s_p1_0[] = {
  110222. 1, 0, 2,
  110223. };
  110224. static encode_aux_threshmatch _vq_auxt__16c1_s_p1_0 = {
  110225. _vq_quantthresh__16c1_s_p1_0,
  110226. _vq_quantmap__16c1_s_p1_0,
  110227. 3,
  110228. 3
  110229. };
  110230. static static_codebook _16c1_s_p1_0 = {
  110231. 8, 6561,
  110232. _vq_lengthlist__16c1_s_p1_0,
  110233. 1, -535822336, 1611661312, 2, 0,
  110234. _vq_quantlist__16c1_s_p1_0,
  110235. NULL,
  110236. &_vq_auxt__16c1_s_p1_0,
  110237. NULL,
  110238. 0
  110239. };
  110240. static long _vq_quantlist__16c1_s_p2_0[] = {
  110241. 2,
  110242. 1,
  110243. 3,
  110244. 0,
  110245. 4,
  110246. };
  110247. static long _vq_lengthlist__16c1_s_p2_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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110259. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110260. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110261. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110263. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110264. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110265. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110268. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110269. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110270. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110273. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110278. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110280. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110285. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110286. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110287. 0,
  110288. };
  110289. static float _vq_quantthresh__16c1_s_p2_0[] = {
  110290. -1.5, -0.5, 0.5, 1.5,
  110291. };
  110292. static long _vq_quantmap__16c1_s_p2_0[] = {
  110293. 3, 1, 0, 2, 4,
  110294. };
  110295. static encode_aux_threshmatch _vq_auxt__16c1_s_p2_0 = {
  110296. _vq_quantthresh__16c1_s_p2_0,
  110297. _vq_quantmap__16c1_s_p2_0,
  110298. 5,
  110299. 5
  110300. };
  110301. static static_codebook _16c1_s_p2_0 = {
  110302. 4, 625,
  110303. _vq_lengthlist__16c1_s_p2_0,
  110304. 1, -533725184, 1611661312, 3, 0,
  110305. _vq_quantlist__16c1_s_p2_0,
  110306. NULL,
  110307. &_vq_auxt__16c1_s_p2_0,
  110308. NULL,
  110309. 0
  110310. };
  110311. static long _vq_quantlist__16c1_s_p3_0[] = {
  110312. 2,
  110313. 1,
  110314. 3,
  110315. 0,
  110316. 4,
  110317. };
  110318. static long _vq_lengthlist__16c1_s_p3_0[] = {
  110319. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 7, 0, 0,
  110321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110322. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 7, 7, 9, 9,
  110324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110325. 0, 0, 0, 0, 6, 7, 7, 9, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110358. 0,
  110359. };
  110360. static float _vq_quantthresh__16c1_s_p3_0[] = {
  110361. -1.5, -0.5, 0.5, 1.5,
  110362. };
  110363. static long _vq_quantmap__16c1_s_p3_0[] = {
  110364. 3, 1, 0, 2, 4,
  110365. };
  110366. static encode_aux_threshmatch _vq_auxt__16c1_s_p3_0 = {
  110367. _vq_quantthresh__16c1_s_p3_0,
  110368. _vq_quantmap__16c1_s_p3_0,
  110369. 5,
  110370. 5
  110371. };
  110372. static static_codebook _16c1_s_p3_0 = {
  110373. 4, 625,
  110374. _vq_lengthlist__16c1_s_p3_0,
  110375. 1, -533725184, 1611661312, 3, 0,
  110376. _vq_quantlist__16c1_s_p3_0,
  110377. NULL,
  110378. &_vq_auxt__16c1_s_p3_0,
  110379. NULL,
  110380. 0
  110381. };
  110382. static long _vq_quantlist__16c1_s_p4_0[] = {
  110383. 4,
  110384. 3,
  110385. 5,
  110386. 2,
  110387. 6,
  110388. 1,
  110389. 7,
  110390. 0,
  110391. 8,
  110392. };
  110393. static long _vq_lengthlist__16c1_s_p4_0[] = {
  110394. 1, 2, 3, 7, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  110395. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  110396. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  110397. 8, 8, 0, 0, 0, 0, 0, 0, 0, 8, 9, 0, 0, 0, 0, 0,
  110398. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110399. 0,
  110400. };
  110401. static float _vq_quantthresh__16c1_s_p4_0[] = {
  110402. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  110403. };
  110404. static long _vq_quantmap__16c1_s_p4_0[] = {
  110405. 7, 5, 3, 1, 0, 2, 4, 6,
  110406. 8,
  110407. };
  110408. static encode_aux_threshmatch _vq_auxt__16c1_s_p4_0 = {
  110409. _vq_quantthresh__16c1_s_p4_0,
  110410. _vq_quantmap__16c1_s_p4_0,
  110411. 9,
  110412. 9
  110413. };
  110414. static static_codebook _16c1_s_p4_0 = {
  110415. 2, 81,
  110416. _vq_lengthlist__16c1_s_p4_0,
  110417. 1, -531628032, 1611661312, 4, 0,
  110418. _vq_quantlist__16c1_s_p4_0,
  110419. NULL,
  110420. &_vq_auxt__16c1_s_p4_0,
  110421. NULL,
  110422. 0
  110423. };
  110424. static long _vq_quantlist__16c1_s_p5_0[] = {
  110425. 4,
  110426. 3,
  110427. 5,
  110428. 2,
  110429. 6,
  110430. 1,
  110431. 7,
  110432. 0,
  110433. 8,
  110434. };
  110435. static long _vq_lengthlist__16c1_s_p5_0[] = {
  110436. 1, 3, 3, 5, 5, 6, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  110437. 9, 9, 0, 0, 0, 7, 7, 7, 7, 9, 9, 0, 0, 0, 8, 8,
  110438. 8, 8, 9, 9, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  110439. 9, 9, 8, 8,10,10, 0, 0, 0, 9, 9, 8, 8,10,10, 0,
  110440. 0, 0,10,10, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  110441. 10,
  110442. };
  110443. static float _vq_quantthresh__16c1_s_p5_0[] = {
  110444. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  110445. };
  110446. static long _vq_quantmap__16c1_s_p5_0[] = {
  110447. 7, 5, 3, 1, 0, 2, 4, 6,
  110448. 8,
  110449. };
  110450. static encode_aux_threshmatch _vq_auxt__16c1_s_p5_0 = {
  110451. _vq_quantthresh__16c1_s_p5_0,
  110452. _vq_quantmap__16c1_s_p5_0,
  110453. 9,
  110454. 9
  110455. };
  110456. static static_codebook _16c1_s_p5_0 = {
  110457. 2, 81,
  110458. _vq_lengthlist__16c1_s_p5_0,
  110459. 1, -531628032, 1611661312, 4, 0,
  110460. _vq_quantlist__16c1_s_p5_0,
  110461. NULL,
  110462. &_vq_auxt__16c1_s_p5_0,
  110463. NULL,
  110464. 0
  110465. };
  110466. static long _vq_quantlist__16c1_s_p6_0[] = {
  110467. 8,
  110468. 7,
  110469. 9,
  110470. 6,
  110471. 10,
  110472. 5,
  110473. 11,
  110474. 4,
  110475. 12,
  110476. 3,
  110477. 13,
  110478. 2,
  110479. 14,
  110480. 1,
  110481. 15,
  110482. 0,
  110483. 16,
  110484. };
  110485. static long _vq_lengthlist__16c1_s_p6_0[] = {
  110486. 1, 3, 3, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,11,12,
  110487. 12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  110488. 12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  110489. 11,12,12, 0, 0, 0, 8, 8, 8, 9,10, 9,10,10,10,10,
  110490. 11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,11,
  110491. 11,11,12,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  110492. 11,11,12,12,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  110493. 10,11,11,12,12,13,13, 0, 0, 0, 9, 9, 9, 9,10,10,
  110494. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,10,
  110495. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  110496. 10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0, 0, 9,
  110497. 9,10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0, 0,
  110498. 10,10,11,10,11,11,12,12,13,13,13,13, 0, 0, 0, 0,
  110499. 0, 0, 0,10,10,11,11,12,12,13,13,13,13, 0, 0, 0,
  110500. 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,14, 0, 0,
  110501. 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,14, 0,
  110502. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,13,14,14,
  110503. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,13,13,14,
  110504. 14,
  110505. };
  110506. static float _vq_quantthresh__16c1_s_p6_0[] = {
  110507. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  110508. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  110509. };
  110510. static long _vq_quantmap__16c1_s_p6_0[] = {
  110511. 15, 13, 11, 9, 7, 5, 3, 1,
  110512. 0, 2, 4, 6, 8, 10, 12, 14,
  110513. 16,
  110514. };
  110515. static encode_aux_threshmatch _vq_auxt__16c1_s_p6_0 = {
  110516. _vq_quantthresh__16c1_s_p6_0,
  110517. _vq_quantmap__16c1_s_p6_0,
  110518. 17,
  110519. 17
  110520. };
  110521. static static_codebook _16c1_s_p6_0 = {
  110522. 2, 289,
  110523. _vq_lengthlist__16c1_s_p6_0,
  110524. 1, -529530880, 1611661312, 5, 0,
  110525. _vq_quantlist__16c1_s_p6_0,
  110526. NULL,
  110527. &_vq_auxt__16c1_s_p6_0,
  110528. NULL,
  110529. 0
  110530. };
  110531. static long _vq_quantlist__16c1_s_p7_0[] = {
  110532. 1,
  110533. 0,
  110534. 2,
  110535. };
  110536. static long _vq_lengthlist__16c1_s_p7_0[] = {
  110537. 1, 4, 4, 6, 6, 6, 7, 6, 6, 4, 7, 7,10, 9,10,10,
  110538. 10, 9, 4, 7, 7,10,10,10,11,10,10, 6,10,10,11,11,
  110539. 11,11,10,10, 6,10, 9,11,11,11,11,10,10, 6,10,10,
  110540. 11,11,11,11,10,10, 7,11,11,11,11,11,12,12,11, 6,
  110541. 10,10,11,10,10,11,11,11, 6,10,10,10,11,10,11,11,
  110542. 11,
  110543. };
  110544. static float _vq_quantthresh__16c1_s_p7_0[] = {
  110545. -5.5, 5.5,
  110546. };
  110547. static long _vq_quantmap__16c1_s_p7_0[] = {
  110548. 1, 0, 2,
  110549. };
  110550. static encode_aux_threshmatch _vq_auxt__16c1_s_p7_0 = {
  110551. _vq_quantthresh__16c1_s_p7_0,
  110552. _vq_quantmap__16c1_s_p7_0,
  110553. 3,
  110554. 3
  110555. };
  110556. static static_codebook _16c1_s_p7_0 = {
  110557. 4, 81,
  110558. _vq_lengthlist__16c1_s_p7_0,
  110559. 1, -529137664, 1618345984, 2, 0,
  110560. _vq_quantlist__16c1_s_p7_0,
  110561. NULL,
  110562. &_vq_auxt__16c1_s_p7_0,
  110563. NULL,
  110564. 0
  110565. };
  110566. static long _vq_quantlist__16c1_s_p7_1[] = {
  110567. 5,
  110568. 4,
  110569. 6,
  110570. 3,
  110571. 7,
  110572. 2,
  110573. 8,
  110574. 1,
  110575. 9,
  110576. 0,
  110577. 10,
  110578. };
  110579. static long _vq_lengthlist__16c1_s_p7_1[] = {
  110580. 2, 3, 3, 5, 6, 7, 7, 7, 7, 8, 8,10,10,10, 6, 6,
  110581. 7, 7, 8, 8, 8, 8,10,10,10, 6, 6, 7, 7, 8, 8, 8,
  110582. 8,10,10,10, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  110583. 7, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  110584. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  110585. 8, 8, 8, 8, 8, 8, 9, 9,10,10,10,10,10, 8, 8, 8,
  110586. 8, 9, 9,10,10,10,10,10, 9, 9, 8, 8, 9, 9,10,10,
  110587. 10,10,10, 8, 8, 8, 8, 9, 9,
  110588. };
  110589. static float _vq_quantthresh__16c1_s_p7_1[] = {
  110590. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  110591. 3.5, 4.5,
  110592. };
  110593. static long _vq_quantmap__16c1_s_p7_1[] = {
  110594. 9, 7, 5, 3, 1, 0, 2, 4,
  110595. 6, 8, 10,
  110596. };
  110597. static encode_aux_threshmatch _vq_auxt__16c1_s_p7_1 = {
  110598. _vq_quantthresh__16c1_s_p7_1,
  110599. _vq_quantmap__16c1_s_p7_1,
  110600. 11,
  110601. 11
  110602. };
  110603. static static_codebook _16c1_s_p7_1 = {
  110604. 2, 121,
  110605. _vq_lengthlist__16c1_s_p7_1,
  110606. 1, -531365888, 1611661312, 4, 0,
  110607. _vq_quantlist__16c1_s_p7_1,
  110608. NULL,
  110609. &_vq_auxt__16c1_s_p7_1,
  110610. NULL,
  110611. 0
  110612. };
  110613. static long _vq_quantlist__16c1_s_p8_0[] = {
  110614. 6,
  110615. 5,
  110616. 7,
  110617. 4,
  110618. 8,
  110619. 3,
  110620. 9,
  110621. 2,
  110622. 10,
  110623. 1,
  110624. 11,
  110625. 0,
  110626. 12,
  110627. };
  110628. static long _vq_lengthlist__16c1_s_p8_0[] = {
  110629. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 6, 5, 5,
  110630. 7, 8, 8, 9, 8, 8, 9, 9,10,11, 6, 5, 5, 8, 8, 9,
  110631. 9, 8, 8, 9,10,10,11, 0, 8, 8, 8, 9, 9, 9, 9, 9,
  110632. 10,10,11,11, 0, 9, 9, 9, 8, 9, 9, 9, 9,10,10,11,
  110633. 11, 0,13,13, 9, 9,10,10,10,10,11,11,12,12, 0,14,
  110634. 13, 9, 9,10,10,10,10,11,11,12,12, 0, 0, 0,10,10,
  110635. 9, 9,11,11,12,12,13,12, 0, 0, 0,10,10, 9, 9,10,
  110636. 10,12,12,13,13, 0, 0, 0,13,14,11,10,11,11,12,12,
  110637. 13,14, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  110638. 0, 0, 0, 0,12,12,12,12,13,13,14,15, 0, 0, 0, 0,
  110639. 0,12,12,12,12,13,13,14,15,
  110640. };
  110641. static float _vq_quantthresh__16c1_s_p8_0[] = {
  110642. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  110643. 12.5, 17.5, 22.5, 27.5,
  110644. };
  110645. static long _vq_quantmap__16c1_s_p8_0[] = {
  110646. 11, 9, 7, 5, 3, 1, 0, 2,
  110647. 4, 6, 8, 10, 12,
  110648. };
  110649. static encode_aux_threshmatch _vq_auxt__16c1_s_p8_0 = {
  110650. _vq_quantthresh__16c1_s_p8_0,
  110651. _vq_quantmap__16c1_s_p8_0,
  110652. 13,
  110653. 13
  110654. };
  110655. static static_codebook _16c1_s_p8_0 = {
  110656. 2, 169,
  110657. _vq_lengthlist__16c1_s_p8_0,
  110658. 1, -526516224, 1616117760, 4, 0,
  110659. _vq_quantlist__16c1_s_p8_0,
  110660. NULL,
  110661. &_vq_auxt__16c1_s_p8_0,
  110662. NULL,
  110663. 0
  110664. };
  110665. static long _vq_quantlist__16c1_s_p8_1[] = {
  110666. 2,
  110667. 1,
  110668. 3,
  110669. 0,
  110670. 4,
  110671. };
  110672. static long _vq_lengthlist__16c1_s_p8_1[] = {
  110673. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  110674. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  110675. };
  110676. static float _vq_quantthresh__16c1_s_p8_1[] = {
  110677. -1.5, -0.5, 0.5, 1.5,
  110678. };
  110679. static long _vq_quantmap__16c1_s_p8_1[] = {
  110680. 3, 1, 0, 2, 4,
  110681. };
  110682. static encode_aux_threshmatch _vq_auxt__16c1_s_p8_1 = {
  110683. _vq_quantthresh__16c1_s_p8_1,
  110684. _vq_quantmap__16c1_s_p8_1,
  110685. 5,
  110686. 5
  110687. };
  110688. static static_codebook _16c1_s_p8_1 = {
  110689. 2, 25,
  110690. _vq_lengthlist__16c1_s_p8_1,
  110691. 1, -533725184, 1611661312, 3, 0,
  110692. _vq_quantlist__16c1_s_p8_1,
  110693. NULL,
  110694. &_vq_auxt__16c1_s_p8_1,
  110695. NULL,
  110696. 0
  110697. };
  110698. static long _vq_quantlist__16c1_s_p9_0[] = {
  110699. 6,
  110700. 5,
  110701. 7,
  110702. 4,
  110703. 8,
  110704. 3,
  110705. 9,
  110706. 2,
  110707. 10,
  110708. 1,
  110709. 11,
  110710. 0,
  110711. 12,
  110712. };
  110713. static long _vq_lengthlist__16c1_s_p9_0[] = {
  110714. 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110715. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110716. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110717. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110718. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110719. 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110720. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110721. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110722. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110723. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110724. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110725. };
  110726. static float _vq_quantthresh__16c1_s_p9_0[] = {
  110727. -1732.5, -1417.5, -1102.5, -787.5, -472.5, -157.5, 157.5, 472.5,
  110728. 787.5, 1102.5, 1417.5, 1732.5,
  110729. };
  110730. static long _vq_quantmap__16c1_s_p9_0[] = {
  110731. 11, 9, 7, 5, 3, 1, 0, 2,
  110732. 4, 6, 8, 10, 12,
  110733. };
  110734. static encode_aux_threshmatch _vq_auxt__16c1_s_p9_0 = {
  110735. _vq_quantthresh__16c1_s_p9_0,
  110736. _vq_quantmap__16c1_s_p9_0,
  110737. 13,
  110738. 13
  110739. };
  110740. static static_codebook _16c1_s_p9_0 = {
  110741. 2, 169,
  110742. _vq_lengthlist__16c1_s_p9_0,
  110743. 1, -513964032, 1628680192, 4, 0,
  110744. _vq_quantlist__16c1_s_p9_0,
  110745. NULL,
  110746. &_vq_auxt__16c1_s_p9_0,
  110747. NULL,
  110748. 0
  110749. };
  110750. static long _vq_quantlist__16c1_s_p9_1[] = {
  110751. 7,
  110752. 6,
  110753. 8,
  110754. 5,
  110755. 9,
  110756. 4,
  110757. 10,
  110758. 3,
  110759. 11,
  110760. 2,
  110761. 12,
  110762. 1,
  110763. 13,
  110764. 0,
  110765. 14,
  110766. };
  110767. static long _vq_lengthlist__16c1_s_p9_1[] = {
  110768. 1, 4, 4, 4, 4, 8, 8,12,13,14,14,14,14,14,14, 6,
  110769. 6, 6, 6, 6,10, 9,14,14,14,14,14,14,14,14, 7, 6,
  110770. 5, 6, 6,10, 9,12,13,13,13,13,13,13,13,13, 7, 7,
  110771. 9, 9,11,11,12,13,13,13,13,13,13,13,13, 7, 7, 8,
  110772. 8,11,12,13,13,13,13,13,13,13,13,13,12,12,10,10,
  110773. 13,12,13,13,13,13,13,13,13,13,13,12,12,10,10,13,
  110774. 13,13,13,13,13,13,13,13,13,13,13,13,13,12,13,12,
  110775. 13,13,13,13,13,13,13,13,13,13,13,13,12,13,13,13,
  110776. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  110777. 13,13,13,13,13,13,13,13,13,13,13,13,12,13,13,13,
  110778. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  110779. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  110780. 13,13,13,13,13,13,13,13,13,12,13,13,13,13,13,13,
  110781. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  110782. 13,
  110783. };
  110784. static float _vq_quantthresh__16c1_s_p9_1[] = {
  110785. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  110786. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  110787. };
  110788. static long _vq_quantmap__16c1_s_p9_1[] = {
  110789. 13, 11, 9, 7, 5, 3, 1, 0,
  110790. 2, 4, 6, 8, 10, 12, 14,
  110791. };
  110792. static encode_aux_threshmatch _vq_auxt__16c1_s_p9_1 = {
  110793. _vq_quantthresh__16c1_s_p9_1,
  110794. _vq_quantmap__16c1_s_p9_1,
  110795. 15,
  110796. 15
  110797. };
  110798. static static_codebook _16c1_s_p9_1 = {
  110799. 2, 225,
  110800. _vq_lengthlist__16c1_s_p9_1,
  110801. 1, -520986624, 1620377600, 4, 0,
  110802. _vq_quantlist__16c1_s_p9_1,
  110803. NULL,
  110804. &_vq_auxt__16c1_s_p9_1,
  110805. NULL,
  110806. 0
  110807. };
  110808. static long _vq_quantlist__16c1_s_p9_2[] = {
  110809. 10,
  110810. 9,
  110811. 11,
  110812. 8,
  110813. 12,
  110814. 7,
  110815. 13,
  110816. 6,
  110817. 14,
  110818. 5,
  110819. 15,
  110820. 4,
  110821. 16,
  110822. 3,
  110823. 17,
  110824. 2,
  110825. 18,
  110826. 1,
  110827. 19,
  110828. 0,
  110829. 20,
  110830. };
  110831. static long _vq_lengthlist__16c1_s_p9_2[] = {
  110832. 1, 4, 4, 6, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9,10,
  110833. 10,10, 9,10,10,11,12,12, 8, 8, 8, 8, 9, 9, 9, 9,
  110834. 10,10,10,10,10,11,11,10,12,11,11,13,11, 7, 7, 8,
  110835. 8, 8, 8, 9, 9, 9,10,10,10,10, 9,10,10,11,11,12,
  110836. 11,11, 8, 8, 8, 8, 9, 9,10,10,10,10,11,11,11,11,
  110837. 11,11,11,12,11,12,12, 8, 8, 9, 9, 9, 9, 9,10,10,
  110838. 10,10,10,10,11,11,11,11,11,11,12,11, 9, 9, 9, 9,
  110839. 10,10,10,10,11,10,11,11,11,11,11,11,12,12,12,12,
  110840. 11, 9, 9, 9, 9,10,10,10,10,11,11,11,11,11,11,11,
  110841. 11,11,12,12,12,13, 9,10,10, 9,11,10,10,10,10,11,
  110842. 11,11,11,11,10,11,12,11,12,12,11,12,11,10, 9,10,
  110843. 10,11,10,11,11,11,11,11,11,11,11,11,12,12,11,12,
  110844. 12,12,10,10,10,11,10,11,11,11,11,11,11,11,11,11,
  110845. 11,11,12,13,12,12,11, 9,10,10,11,11,10,11,11,11,
  110846. 12,11,11,11,11,11,12,12,13,13,12,13,10,10,12,10,
  110847. 11,11,11,11,11,11,11,11,11,12,12,11,13,12,12,12,
  110848. 12,13,12,11,11,11,11,11,11,12,11,12,11,11,11,11,
  110849. 12,12,13,12,11,12,12,11,11,11,11,11,12,11,11,11,
  110850. 11,12,11,11,12,11,12,13,13,12,12,12,12,11,11,11,
  110851. 11,11,12,11,11,12,11,12,11,11,11,11,13,12,12,12,
  110852. 12,13,11,11,11,12,12,11,11,11,12,11,12,12,12,11,
  110853. 12,13,12,11,11,12,12,11,12,11,11,11,12,12,11,12,
  110854. 11,11,11,12,12,12,12,13,12,13,12,12,12,12,11,11,
  110855. 12,11,11,11,11,11,11,12,12,12,13,12,11,13,13,12,
  110856. 12,11,12,10,11,11,11,11,12,11,12,12,11,12,12,13,
  110857. 12,12,13,12,12,12,12,12,11,12,12,12,11,12,11,11,
  110858. 11,12,13,12,13,13,13,13,13,12,13,13,12,12,13,11,
  110859. 11,11,11,11,12,11,11,12,11,
  110860. };
  110861. static float _vq_quantthresh__16c1_s_p9_2[] = {
  110862. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  110863. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  110864. 6.5, 7.5, 8.5, 9.5,
  110865. };
  110866. static long _vq_quantmap__16c1_s_p9_2[] = {
  110867. 19, 17, 15, 13, 11, 9, 7, 5,
  110868. 3, 1, 0, 2, 4, 6, 8, 10,
  110869. 12, 14, 16, 18, 20,
  110870. };
  110871. static encode_aux_threshmatch _vq_auxt__16c1_s_p9_2 = {
  110872. _vq_quantthresh__16c1_s_p9_2,
  110873. _vq_quantmap__16c1_s_p9_2,
  110874. 21,
  110875. 21
  110876. };
  110877. static static_codebook _16c1_s_p9_2 = {
  110878. 2, 441,
  110879. _vq_lengthlist__16c1_s_p9_2,
  110880. 1, -529268736, 1611661312, 5, 0,
  110881. _vq_quantlist__16c1_s_p9_2,
  110882. NULL,
  110883. &_vq_auxt__16c1_s_p9_2,
  110884. NULL,
  110885. 0
  110886. };
  110887. static long _huff_lengthlist__16c1_s_short[] = {
  110888. 5, 6,17, 8,12, 9,10,10,12,13, 5, 2,17, 4, 9, 5,
  110889. 7, 8,11,13,16,16,16,16,16,16,16,16,16,16, 6, 4,
  110890. 16, 5,10, 5, 7,10,14,16,13, 9,16,11, 8, 7, 8, 9,
  110891. 13,16, 7, 4,16, 5, 7, 4, 6, 8,11,13, 8, 6,16, 7,
  110892. 8, 5, 5, 7, 9,13, 9, 8,16, 9, 8, 6, 6, 7, 9,13,
  110893. 11,11,16,10,10, 7, 7, 7, 9,13,13,13,16,13,13, 9,
  110894. 9, 9,10,13,
  110895. };
  110896. static static_codebook _huff_book__16c1_s_short = {
  110897. 2, 100,
  110898. _huff_lengthlist__16c1_s_short,
  110899. 0, 0, 0, 0, 0,
  110900. NULL,
  110901. NULL,
  110902. NULL,
  110903. NULL,
  110904. 0
  110905. };
  110906. static long _huff_lengthlist__16c2_s_long[] = {
  110907. 4, 7, 9, 9, 9, 8, 9,10,15,19, 5, 4, 5, 6, 7, 7,
  110908. 8, 9,14,16, 6, 5, 4, 5, 6, 7, 8,10,12,19, 7, 6,
  110909. 5, 4, 5, 6, 7, 9,11,18, 8, 7, 6, 5, 5, 5, 7, 9,
  110910. 10,17, 8, 7, 7, 5, 5, 5, 6, 7,12,18, 8, 8, 8, 7,
  110911. 7, 5, 5, 7,12,18, 8, 9,10, 9, 9, 7, 6, 7,12,17,
  110912. 14,18,16,16,15,12,11,10,12,18,15,17,18,18,18,15,
  110913. 14,14,16,18,
  110914. };
  110915. static static_codebook _huff_book__16c2_s_long = {
  110916. 2, 100,
  110917. _huff_lengthlist__16c2_s_long,
  110918. 0, 0, 0, 0, 0,
  110919. NULL,
  110920. NULL,
  110921. NULL,
  110922. NULL,
  110923. 0
  110924. };
  110925. static long _vq_quantlist__16c2_s_p1_0[] = {
  110926. 1,
  110927. 0,
  110928. 2,
  110929. };
  110930. static long _vq_lengthlist__16c2_s_p1_0[] = {
  110931. 1, 3, 3, 0, 0, 0, 0, 0, 0, 4, 5, 5, 0, 0, 0, 0,
  110932. 0, 0, 4, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110934. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110936. 0,
  110937. };
  110938. static float _vq_quantthresh__16c2_s_p1_0[] = {
  110939. -0.5, 0.5,
  110940. };
  110941. static long _vq_quantmap__16c2_s_p1_0[] = {
  110942. 1, 0, 2,
  110943. };
  110944. static encode_aux_threshmatch _vq_auxt__16c2_s_p1_0 = {
  110945. _vq_quantthresh__16c2_s_p1_0,
  110946. _vq_quantmap__16c2_s_p1_0,
  110947. 3,
  110948. 3
  110949. };
  110950. static static_codebook _16c2_s_p1_0 = {
  110951. 4, 81,
  110952. _vq_lengthlist__16c2_s_p1_0,
  110953. 1, -535822336, 1611661312, 2, 0,
  110954. _vq_quantlist__16c2_s_p1_0,
  110955. NULL,
  110956. &_vq_auxt__16c2_s_p1_0,
  110957. NULL,
  110958. 0
  110959. };
  110960. static long _vq_quantlist__16c2_s_p2_0[] = {
  110961. 2,
  110962. 1,
  110963. 3,
  110964. 0,
  110965. 4,
  110966. };
  110967. static long _vq_lengthlist__16c2_s_p2_0[] = {
  110968. 2, 4, 3, 7, 7, 0, 0, 0, 7, 8, 0, 0, 0, 8, 8, 0,
  110969. 0, 0, 8, 8, 0, 0, 0, 8, 8, 4, 5, 4, 8, 8, 0, 0,
  110970. 0, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0, 9, 9, 0, 0, 0,
  110971. 9, 9, 4, 4, 5, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0, 8,
  110972. 8, 0, 0, 0, 9, 9, 0, 0, 0, 9, 9, 7, 8, 8,10,10,
  110973. 0, 0, 0,12,11, 0, 0, 0,11,11, 0, 0, 0,14,13, 0,
  110974. 0, 0,14,13, 7, 8, 8, 9,10, 0, 0, 0,11,12, 0, 0,
  110975. 0,11,11, 0, 0, 0,14,14, 0, 0, 0,13,14, 0, 0, 0,
  110976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110980. 0, 0, 0, 0, 0, 0, 0, 0, 8, 8, 8,11,11, 0, 0, 0,
  110981. 11,11, 0, 0, 0,12,11, 0, 0, 0,12,12, 0, 0, 0,13,
  110982. 13, 8, 8, 8,11,11, 0, 0, 0,11,11, 0, 0, 0,11,12,
  110983. 0, 0, 0,12,13, 0, 0, 0,13,13, 0, 0, 0, 0, 0, 0,
  110984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110988. 0, 0, 0, 0, 0, 8, 8, 8,12,11, 0, 0, 0,12,11, 0,
  110989. 0, 0,11,11, 0, 0, 0,13,13, 0, 0, 0,13,12, 8, 8,
  110990. 8,11,12, 0, 0, 0,11,12, 0, 0, 0,11,11, 0, 0, 0,
  110991. 13,13, 0, 0, 0,12,13, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110996. 0, 0, 8, 9, 9,14,13, 0, 0, 0,13,12, 0, 0, 0,13,
  110997. 13, 0, 0, 0,13,12, 0, 0, 0,13,13, 8, 9, 9,13,14,
  110998. 0, 0, 0,12,13, 0, 0, 0,13,13, 0, 0, 0,12,13, 0,
  110999. 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8,
  111004. 9, 9,14,13, 0, 0, 0,13,13, 0, 0, 0,13,12, 0, 0,
  111005. 0,13,13, 0, 0, 0,13,12, 8, 9, 9,14,14, 0, 0, 0,
  111006. 13,13, 0, 0, 0,12,13, 0, 0, 0,13,13, 0, 0, 0,12,
  111007. 13,
  111008. };
  111009. static float _vq_quantthresh__16c2_s_p2_0[] = {
  111010. -1.5, -0.5, 0.5, 1.5,
  111011. };
  111012. static long _vq_quantmap__16c2_s_p2_0[] = {
  111013. 3, 1, 0, 2, 4,
  111014. };
  111015. static encode_aux_threshmatch _vq_auxt__16c2_s_p2_0 = {
  111016. _vq_quantthresh__16c2_s_p2_0,
  111017. _vq_quantmap__16c2_s_p2_0,
  111018. 5,
  111019. 5
  111020. };
  111021. static static_codebook _16c2_s_p2_0 = {
  111022. 4, 625,
  111023. _vq_lengthlist__16c2_s_p2_0,
  111024. 1, -533725184, 1611661312, 3, 0,
  111025. _vq_quantlist__16c2_s_p2_0,
  111026. NULL,
  111027. &_vq_auxt__16c2_s_p2_0,
  111028. NULL,
  111029. 0
  111030. };
  111031. static long _vq_quantlist__16c2_s_p3_0[] = {
  111032. 4,
  111033. 3,
  111034. 5,
  111035. 2,
  111036. 6,
  111037. 1,
  111038. 7,
  111039. 0,
  111040. 8,
  111041. };
  111042. static long _vq_lengthlist__16c2_s_p3_0[] = {
  111043. 1, 3, 3, 6, 6, 7, 7, 8, 8, 0, 0, 0, 6, 6, 7, 7,
  111044. 9, 9, 0, 0, 0, 6, 6, 7, 7, 9, 9, 0, 0, 0, 7, 7,
  111045. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0, 0, 0,
  111046. 7, 7, 9, 9,10,10, 0, 0, 0, 7, 7, 9, 9,10,10, 0,
  111047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111048. 0,
  111049. };
  111050. static float _vq_quantthresh__16c2_s_p3_0[] = {
  111051. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  111052. };
  111053. static long _vq_quantmap__16c2_s_p3_0[] = {
  111054. 7, 5, 3, 1, 0, 2, 4, 6,
  111055. 8,
  111056. };
  111057. static encode_aux_threshmatch _vq_auxt__16c2_s_p3_0 = {
  111058. _vq_quantthresh__16c2_s_p3_0,
  111059. _vq_quantmap__16c2_s_p3_0,
  111060. 9,
  111061. 9
  111062. };
  111063. static static_codebook _16c2_s_p3_0 = {
  111064. 2, 81,
  111065. _vq_lengthlist__16c2_s_p3_0,
  111066. 1, -531628032, 1611661312, 4, 0,
  111067. _vq_quantlist__16c2_s_p3_0,
  111068. NULL,
  111069. &_vq_auxt__16c2_s_p3_0,
  111070. NULL,
  111071. 0
  111072. };
  111073. static long _vq_quantlist__16c2_s_p4_0[] = {
  111074. 8,
  111075. 7,
  111076. 9,
  111077. 6,
  111078. 10,
  111079. 5,
  111080. 11,
  111081. 4,
  111082. 12,
  111083. 3,
  111084. 13,
  111085. 2,
  111086. 14,
  111087. 1,
  111088. 15,
  111089. 0,
  111090. 16,
  111091. };
  111092. static long _vq_lengthlist__16c2_s_p4_0[] = {
  111093. 2, 3, 3, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9,10,
  111094. 10, 0, 0, 0, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,
  111095. 11,11, 0, 0, 0, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,
  111096. 10,10,11, 0, 0, 0, 6, 6, 8, 8, 8, 8, 9, 9,10,10,
  111097. 10,11,11,11, 0, 0, 0, 6, 6, 8, 8, 9, 9, 9, 9,10,
  111098. 10,11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,
  111099. 10,10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9,
  111100. 9,10,10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  111101. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 8, 8, 9,
  111102. 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 0, 0,
  111103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111111. 0,
  111112. };
  111113. static float _vq_quantthresh__16c2_s_p4_0[] = {
  111114. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  111115. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  111116. };
  111117. static long _vq_quantmap__16c2_s_p4_0[] = {
  111118. 15, 13, 11, 9, 7, 5, 3, 1,
  111119. 0, 2, 4, 6, 8, 10, 12, 14,
  111120. 16,
  111121. };
  111122. static encode_aux_threshmatch _vq_auxt__16c2_s_p4_0 = {
  111123. _vq_quantthresh__16c2_s_p4_0,
  111124. _vq_quantmap__16c2_s_p4_0,
  111125. 17,
  111126. 17
  111127. };
  111128. static static_codebook _16c2_s_p4_0 = {
  111129. 2, 289,
  111130. _vq_lengthlist__16c2_s_p4_0,
  111131. 1, -529530880, 1611661312, 5, 0,
  111132. _vq_quantlist__16c2_s_p4_0,
  111133. NULL,
  111134. &_vq_auxt__16c2_s_p4_0,
  111135. NULL,
  111136. 0
  111137. };
  111138. static long _vq_quantlist__16c2_s_p5_0[] = {
  111139. 1,
  111140. 0,
  111141. 2,
  111142. };
  111143. static long _vq_lengthlist__16c2_s_p5_0[] = {
  111144. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 6, 6,10,10,10,10,
  111145. 10,10, 4, 7, 6,10,10,10,10,10,10, 5, 9, 9, 9,12,
  111146. 11,10,11,12, 7,10,10,12,12,12,12,12,12, 7,10,10,
  111147. 11,12,12,12,12,13, 6,10,10,10,12,12,10,12,12, 7,
  111148. 10,10,11,13,12,12,12,12, 7,10,10,11,12,12,12,12,
  111149. 12,
  111150. };
  111151. static float _vq_quantthresh__16c2_s_p5_0[] = {
  111152. -5.5, 5.5,
  111153. };
  111154. static long _vq_quantmap__16c2_s_p5_0[] = {
  111155. 1, 0, 2,
  111156. };
  111157. static encode_aux_threshmatch _vq_auxt__16c2_s_p5_0 = {
  111158. _vq_quantthresh__16c2_s_p5_0,
  111159. _vq_quantmap__16c2_s_p5_0,
  111160. 3,
  111161. 3
  111162. };
  111163. static static_codebook _16c2_s_p5_0 = {
  111164. 4, 81,
  111165. _vq_lengthlist__16c2_s_p5_0,
  111166. 1, -529137664, 1618345984, 2, 0,
  111167. _vq_quantlist__16c2_s_p5_0,
  111168. NULL,
  111169. &_vq_auxt__16c2_s_p5_0,
  111170. NULL,
  111171. 0
  111172. };
  111173. static long _vq_quantlist__16c2_s_p5_1[] = {
  111174. 5,
  111175. 4,
  111176. 6,
  111177. 3,
  111178. 7,
  111179. 2,
  111180. 8,
  111181. 1,
  111182. 9,
  111183. 0,
  111184. 10,
  111185. };
  111186. static long _vq_lengthlist__16c2_s_p5_1[] = {
  111187. 2, 3, 3, 6, 6, 7, 7, 7, 7, 8, 8,11,11,11, 6, 6,
  111188. 7, 7, 8, 8, 8, 8,11,11,11, 6, 6, 7, 7, 8, 8, 8,
  111189. 8,11,11,11, 6, 6, 8, 8, 8, 8, 9, 9,11,11,11, 6,
  111190. 6, 8, 8, 8, 8, 9, 9,11,11,11, 7, 7, 8, 8, 8, 8,
  111191. 8, 8,11,11,11, 7, 7, 8, 8, 8, 8, 8, 9,11,11,11,
  111192. 8, 8, 8, 8, 8, 8, 8, 8,11,11,11,11,11, 8, 8, 8,
  111193. 8, 8, 8,11,11,11,11,11, 8, 8, 8, 8, 8, 8,11,11,
  111194. 11,11,11, 7, 7, 8, 8, 8, 8,
  111195. };
  111196. static float _vq_quantthresh__16c2_s_p5_1[] = {
  111197. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  111198. 3.5, 4.5,
  111199. };
  111200. static long _vq_quantmap__16c2_s_p5_1[] = {
  111201. 9, 7, 5, 3, 1, 0, 2, 4,
  111202. 6, 8, 10,
  111203. };
  111204. static encode_aux_threshmatch _vq_auxt__16c2_s_p5_1 = {
  111205. _vq_quantthresh__16c2_s_p5_1,
  111206. _vq_quantmap__16c2_s_p5_1,
  111207. 11,
  111208. 11
  111209. };
  111210. static static_codebook _16c2_s_p5_1 = {
  111211. 2, 121,
  111212. _vq_lengthlist__16c2_s_p5_1,
  111213. 1, -531365888, 1611661312, 4, 0,
  111214. _vq_quantlist__16c2_s_p5_1,
  111215. NULL,
  111216. &_vq_auxt__16c2_s_p5_1,
  111217. NULL,
  111218. 0
  111219. };
  111220. static long _vq_quantlist__16c2_s_p6_0[] = {
  111221. 6,
  111222. 5,
  111223. 7,
  111224. 4,
  111225. 8,
  111226. 3,
  111227. 9,
  111228. 2,
  111229. 10,
  111230. 1,
  111231. 11,
  111232. 0,
  111233. 12,
  111234. };
  111235. static long _vq_lengthlist__16c2_s_p6_0[] = {
  111236. 1, 4, 4, 7, 6, 8, 8, 9, 9,10,10,11,11, 5, 5, 5,
  111237. 7, 7, 9, 9, 9, 9,11,11,12,12, 6, 5, 5, 7, 7, 9,
  111238. 9,10,10,11,11,12,12, 0, 6, 6, 7, 7, 9, 9,10,10,
  111239. 11,11,12,12, 0, 7, 7, 7, 7, 9, 9,10,10,11,12,12,
  111240. 12, 0,11,11, 8, 8,10,10,11,11,12,12,13,13, 0,11,
  111241. 12, 8, 8,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  111242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111246. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111247. };
  111248. static float _vq_quantthresh__16c2_s_p6_0[] = {
  111249. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  111250. 12.5, 17.5, 22.5, 27.5,
  111251. };
  111252. static long _vq_quantmap__16c2_s_p6_0[] = {
  111253. 11, 9, 7, 5, 3, 1, 0, 2,
  111254. 4, 6, 8, 10, 12,
  111255. };
  111256. static encode_aux_threshmatch _vq_auxt__16c2_s_p6_0 = {
  111257. _vq_quantthresh__16c2_s_p6_0,
  111258. _vq_quantmap__16c2_s_p6_0,
  111259. 13,
  111260. 13
  111261. };
  111262. static static_codebook _16c2_s_p6_0 = {
  111263. 2, 169,
  111264. _vq_lengthlist__16c2_s_p6_0,
  111265. 1, -526516224, 1616117760, 4, 0,
  111266. _vq_quantlist__16c2_s_p6_0,
  111267. NULL,
  111268. &_vq_auxt__16c2_s_p6_0,
  111269. NULL,
  111270. 0
  111271. };
  111272. static long _vq_quantlist__16c2_s_p6_1[] = {
  111273. 2,
  111274. 1,
  111275. 3,
  111276. 0,
  111277. 4,
  111278. };
  111279. static long _vq_lengthlist__16c2_s_p6_1[] = {
  111280. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  111281. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  111282. };
  111283. static float _vq_quantthresh__16c2_s_p6_1[] = {
  111284. -1.5, -0.5, 0.5, 1.5,
  111285. };
  111286. static long _vq_quantmap__16c2_s_p6_1[] = {
  111287. 3, 1, 0, 2, 4,
  111288. };
  111289. static encode_aux_threshmatch _vq_auxt__16c2_s_p6_1 = {
  111290. _vq_quantthresh__16c2_s_p6_1,
  111291. _vq_quantmap__16c2_s_p6_1,
  111292. 5,
  111293. 5
  111294. };
  111295. static static_codebook _16c2_s_p6_1 = {
  111296. 2, 25,
  111297. _vq_lengthlist__16c2_s_p6_1,
  111298. 1, -533725184, 1611661312, 3, 0,
  111299. _vq_quantlist__16c2_s_p6_1,
  111300. NULL,
  111301. &_vq_auxt__16c2_s_p6_1,
  111302. NULL,
  111303. 0
  111304. };
  111305. static long _vq_quantlist__16c2_s_p7_0[] = {
  111306. 6,
  111307. 5,
  111308. 7,
  111309. 4,
  111310. 8,
  111311. 3,
  111312. 9,
  111313. 2,
  111314. 10,
  111315. 1,
  111316. 11,
  111317. 0,
  111318. 12,
  111319. };
  111320. static long _vq_lengthlist__16c2_s_p7_0[] = {
  111321. 1, 4, 4, 7, 7, 8, 8, 9, 9,10,10,11,11, 5, 5, 5,
  111322. 8, 8, 9, 9,10,10,11,11,12,12, 6, 5, 5, 8, 8, 9,
  111323. 9,10,10,11,11,12,13,18, 6, 6, 7, 7, 9, 9,10,10,
  111324. 12,12,13,13,18, 6, 6, 7, 7, 9, 9,10,10,12,12,13,
  111325. 13,18,11,10, 8, 8,10,10,11,11,12,12,13,13,18,11,
  111326. 11, 8, 8,10,10,11,11,12,13,13,13,18,18,18,10,11,
  111327. 11,11,12,12,13,13,14,14,18,18,18,11,11,11,11,12,
  111328. 12,13,13,14,14,18,18,18,14,14,12,12,12,12,14,14,
  111329. 15,14,18,18,18,15,15,11,12,12,12,13,13,15,15,18,
  111330. 18,18,18,18,13,13,13,13,13,14,17,16,18,18,18,18,
  111331. 18,13,14,13,13,14,13,15,14,
  111332. };
  111333. static float _vq_quantthresh__16c2_s_p7_0[] = {
  111334. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  111335. 27.5, 38.5, 49.5, 60.5,
  111336. };
  111337. static long _vq_quantmap__16c2_s_p7_0[] = {
  111338. 11, 9, 7, 5, 3, 1, 0, 2,
  111339. 4, 6, 8, 10, 12,
  111340. };
  111341. static encode_aux_threshmatch _vq_auxt__16c2_s_p7_0 = {
  111342. _vq_quantthresh__16c2_s_p7_0,
  111343. _vq_quantmap__16c2_s_p7_0,
  111344. 13,
  111345. 13
  111346. };
  111347. static static_codebook _16c2_s_p7_0 = {
  111348. 2, 169,
  111349. _vq_lengthlist__16c2_s_p7_0,
  111350. 1, -523206656, 1618345984, 4, 0,
  111351. _vq_quantlist__16c2_s_p7_0,
  111352. NULL,
  111353. &_vq_auxt__16c2_s_p7_0,
  111354. NULL,
  111355. 0
  111356. };
  111357. static long _vq_quantlist__16c2_s_p7_1[] = {
  111358. 5,
  111359. 4,
  111360. 6,
  111361. 3,
  111362. 7,
  111363. 2,
  111364. 8,
  111365. 1,
  111366. 9,
  111367. 0,
  111368. 10,
  111369. };
  111370. static long _vq_lengthlist__16c2_s_p7_1[] = {
  111371. 2, 4, 4, 6, 6, 7, 7, 7, 7, 7, 7, 9, 9, 9, 6, 6,
  111372. 7, 7, 8, 8, 8, 8, 9, 9, 9, 6, 6, 7, 7, 8, 8, 8,
  111373. 8, 9, 9, 9, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 7,
  111374. 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 7, 7, 7, 7, 8, 8,
  111375. 8, 8, 9, 9, 9, 7, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9,
  111376. 7, 7, 8, 8, 7, 7, 8, 8, 9, 9, 9, 9, 9, 7, 7, 7,
  111377. 7, 8, 8, 9, 9, 9, 9, 9, 8, 8, 7, 7, 8, 8, 9, 9,
  111378. 9, 9, 9, 7, 7, 7, 7, 8, 8,
  111379. };
  111380. static float _vq_quantthresh__16c2_s_p7_1[] = {
  111381. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  111382. 3.5, 4.5,
  111383. };
  111384. static long _vq_quantmap__16c2_s_p7_1[] = {
  111385. 9, 7, 5, 3, 1, 0, 2, 4,
  111386. 6, 8, 10,
  111387. };
  111388. static encode_aux_threshmatch _vq_auxt__16c2_s_p7_1 = {
  111389. _vq_quantthresh__16c2_s_p7_1,
  111390. _vq_quantmap__16c2_s_p7_1,
  111391. 11,
  111392. 11
  111393. };
  111394. static static_codebook _16c2_s_p7_1 = {
  111395. 2, 121,
  111396. _vq_lengthlist__16c2_s_p7_1,
  111397. 1, -531365888, 1611661312, 4, 0,
  111398. _vq_quantlist__16c2_s_p7_1,
  111399. NULL,
  111400. &_vq_auxt__16c2_s_p7_1,
  111401. NULL,
  111402. 0
  111403. };
  111404. static long _vq_quantlist__16c2_s_p8_0[] = {
  111405. 7,
  111406. 6,
  111407. 8,
  111408. 5,
  111409. 9,
  111410. 4,
  111411. 10,
  111412. 3,
  111413. 11,
  111414. 2,
  111415. 12,
  111416. 1,
  111417. 13,
  111418. 0,
  111419. 14,
  111420. };
  111421. static long _vq_lengthlist__16c2_s_p8_0[] = {
  111422. 1, 4, 4, 7, 6, 7, 7, 6, 6, 8, 8, 9, 9,10,10, 6,
  111423. 6, 6, 8, 8, 9, 8, 8, 8, 9, 9,11,10,11,11, 7, 6,
  111424. 6, 8, 8, 9, 8, 7, 7, 9, 9,10,10,12,11,14, 8, 8,
  111425. 8, 9, 9, 9, 9, 9,10, 9,10,10,11,13,14, 8, 8, 8,
  111426. 8, 9, 9, 8, 8, 9, 9,10,10,11,12,14,13,11, 9, 9,
  111427. 9, 9, 9, 9, 9,10,11,10,13,12,14,11,13, 8, 9, 9,
  111428. 9, 9, 9,10,10,11,10,13,12,14,14,14, 8, 9, 9, 9,
  111429. 11,11,11,11,11,12,13,13,14,14,14, 9, 8, 9, 9,10,
  111430. 10,12,10,11,12,12,14,14,14,14,11,12,10,10,12,12,
  111431. 12,12,13,14,12,12,14,14,14,12,12, 9,10,11,11,12,
  111432. 14,12,14,14,14,14,14,14,14,14,11,11,12,11,12,14,
  111433. 14,14,14,14,14,14,14,14,14,12,11,11,11,11,14,14,
  111434. 14,14,14,14,14,14,14,14,14,14,13,12,14,14,14,14,
  111435. 14,14,14,14,14,14,14,14,14,12,12,12,13,14,14,13,
  111436. 13,
  111437. };
  111438. static float _vq_quantthresh__16c2_s_p8_0[] = {
  111439. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  111440. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  111441. };
  111442. static long _vq_quantmap__16c2_s_p8_0[] = {
  111443. 13, 11, 9, 7, 5, 3, 1, 0,
  111444. 2, 4, 6, 8, 10, 12, 14,
  111445. };
  111446. static encode_aux_threshmatch _vq_auxt__16c2_s_p8_0 = {
  111447. _vq_quantthresh__16c2_s_p8_0,
  111448. _vq_quantmap__16c2_s_p8_0,
  111449. 15,
  111450. 15
  111451. };
  111452. static static_codebook _16c2_s_p8_0 = {
  111453. 2, 225,
  111454. _vq_lengthlist__16c2_s_p8_0,
  111455. 1, -520986624, 1620377600, 4, 0,
  111456. _vq_quantlist__16c2_s_p8_0,
  111457. NULL,
  111458. &_vq_auxt__16c2_s_p8_0,
  111459. NULL,
  111460. 0
  111461. };
  111462. static long _vq_quantlist__16c2_s_p8_1[] = {
  111463. 10,
  111464. 9,
  111465. 11,
  111466. 8,
  111467. 12,
  111468. 7,
  111469. 13,
  111470. 6,
  111471. 14,
  111472. 5,
  111473. 15,
  111474. 4,
  111475. 16,
  111476. 3,
  111477. 17,
  111478. 2,
  111479. 18,
  111480. 1,
  111481. 19,
  111482. 0,
  111483. 20,
  111484. };
  111485. static long _vq_lengthlist__16c2_s_p8_1[] = {
  111486. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 7, 8, 8, 8, 8, 8,
  111487. 8, 8, 8, 8, 8,11,12,11, 7, 7, 8, 8, 8, 8, 9, 9,
  111488. 9, 9, 9, 9, 9, 9, 9,10, 9, 9,11,11,10, 7, 7, 8,
  111489. 8, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
  111490. 11,11, 8, 7, 8, 8, 9, 9, 9, 9, 9, 9,10,10, 9,10,
  111491. 10, 9,10,10,11,11,12, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  111492. 9, 9, 9,10, 9,10,10,10,10,11,11,11, 8, 8, 9, 9,
  111493. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,11,11,
  111494. 11, 8, 8, 9, 8, 9, 9, 9, 9,10, 9, 9, 9,10,10,10,
  111495. 10, 9,10,11,11,11, 9, 9, 9, 9,10, 9, 9, 9,10,10,
  111496. 9,10, 9,10,10,10,10,10,11,12,11,11,11, 9, 9, 9,
  111497. 9, 9,10,10, 9,10,10,10,10,10,10,10,10,12,11,13,
  111498. 13,11, 9, 9, 9, 9,10,10, 9,10,10,10,10,11,10,10,
  111499. 10,10,11,12,11,12,11, 9, 9, 9,10,10, 9,10,10,10,
  111500. 10,10,10,10,10,10,10,11,11,11,12,11, 9,10,10,10,
  111501. 10,10,10,10,10,10,10,10,10,10,10,10,11,12,12,12,
  111502. 11,11,11,10, 9,10,10,10,10,10,10,10,10,11,10,10,
  111503. 10,11,11,11,11,11,11,11,10,10,10,11,10,10,10,10,
  111504. 10,10,10,10,10,10,11,11,11,11,12,12,11,10,10,10,
  111505. 10,10,10,10,10,11,10,10,10,11,10,12,11,11,12,11,
  111506. 11,11,10,10,10,10,10,11,10,10,10,10,10,11,10,10,
  111507. 11,11,11,12,11,12,11,11,12,10,10,10,10,10,10,10,
  111508. 11,10,10,11,10,12,11,11,11,12,11,11,11,11,10,10,
  111509. 10,10,10,10,10,11,11,11,10,11,12,11,11,11,12,11,
  111510. 12,11,12,10,11,10,10,10,10,11,10,10,10,10,10,10,
  111511. 12,11,11,11,11,11,12,12,10,10,10,10,10,11,10,10,
  111512. 11,10,11,11,11,11,11,11,11,11,11,11,11,11,12,11,
  111513. 10,11,10,10,10,10,10,10,10,
  111514. };
  111515. static float _vq_quantthresh__16c2_s_p8_1[] = {
  111516. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  111517. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  111518. 6.5, 7.5, 8.5, 9.5,
  111519. };
  111520. static long _vq_quantmap__16c2_s_p8_1[] = {
  111521. 19, 17, 15, 13, 11, 9, 7, 5,
  111522. 3, 1, 0, 2, 4, 6, 8, 10,
  111523. 12, 14, 16, 18, 20,
  111524. };
  111525. static encode_aux_threshmatch _vq_auxt__16c2_s_p8_1 = {
  111526. _vq_quantthresh__16c2_s_p8_1,
  111527. _vq_quantmap__16c2_s_p8_1,
  111528. 21,
  111529. 21
  111530. };
  111531. static static_codebook _16c2_s_p8_1 = {
  111532. 2, 441,
  111533. _vq_lengthlist__16c2_s_p8_1,
  111534. 1, -529268736, 1611661312, 5, 0,
  111535. _vq_quantlist__16c2_s_p8_1,
  111536. NULL,
  111537. &_vq_auxt__16c2_s_p8_1,
  111538. NULL,
  111539. 0
  111540. };
  111541. static long _vq_quantlist__16c2_s_p9_0[] = {
  111542. 6,
  111543. 5,
  111544. 7,
  111545. 4,
  111546. 8,
  111547. 3,
  111548. 9,
  111549. 2,
  111550. 10,
  111551. 1,
  111552. 11,
  111553. 0,
  111554. 12,
  111555. };
  111556. static long _vq_lengthlist__16c2_s_p9_0[] = {
  111557. 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111558. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111559. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111560. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111561. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111562. 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111563. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111564. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111565. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111566. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111567. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111568. };
  111569. static float _vq_quantthresh__16c2_s_p9_0[] = {
  111570. -5120.5, -4189.5, -3258.5, -2327.5, -1396.5, -465.5, 465.5, 1396.5,
  111571. 2327.5, 3258.5, 4189.5, 5120.5,
  111572. };
  111573. static long _vq_quantmap__16c2_s_p9_0[] = {
  111574. 11, 9, 7, 5, 3, 1, 0, 2,
  111575. 4, 6, 8, 10, 12,
  111576. };
  111577. static encode_aux_threshmatch _vq_auxt__16c2_s_p9_0 = {
  111578. _vq_quantthresh__16c2_s_p9_0,
  111579. _vq_quantmap__16c2_s_p9_0,
  111580. 13,
  111581. 13
  111582. };
  111583. static static_codebook _16c2_s_p9_0 = {
  111584. 2, 169,
  111585. _vq_lengthlist__16c2_s_p9_0,
  111586. 1, -510275072, 1631393792, 4, 0,
  111587. _vq_quantlist__16c2_s_p9_0,
  111588. NULL,
  111589. &_vq_auxt__16c2_s_p9_0,
  111590. NULL,
  111591. 0
  111592. };
  111593. static long _vq_quantlist__16c2_s_p9_1[] = {
  111594. 8,
  111595. 7,
  111596. 9,
  111597. 6,
  111598. 10,
  111599. 5,
  111600. 11,
  111601. 4,
  111602. 12,
  111603. 3,
  111604. 13,
  111605. 2,
  111606. 14,
  111607. 1,
  111608. 15,
  111609. 0,
  111610. 16,
  111611. };
  111612. static long _vq_lengthlist__16c2_s_p9_1[] = {
  111613. 1, 5, 5, 9, 8, 7, 7, 7, 6,10,11,11,11,11,11,11,
  111614. 11, 8, 7, 6, 8, 8,10, 9,10,10,10, 9,11,10,10,10,
  111615. 10,10, 8, 6, 6, 8, 8, 9, 8, 9, 8, 9,10,10,10,10,
  111616. 10,10,10,10, 8,10, 9, 9, 9, 9,10,10,10,10,10,10,
  111617. 10,10,10,10,10, 8, 9, 9, 9,10,10, 9,10,10,10,10,
  111618. 10,10,10,10,10,10,10,10, 9, 8, 9, 9,10,10,10,10,
  111619. 10,10,10,10,10,10,10,10, 9, 8, 8, 9, 9,10,10,10,
  111620. 10,10,10,10,10,10,10,10,10,10, 9,10, 9, 9,10,10,
  111621. 10,10,10,10,10,10,10,10,10,10,10, 9, 8, 9, 9,10,
  111622. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  111623. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111624. 8,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111625. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111626. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111627. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111628. 10,10,10,10, 9,10, 9,10,10,10,10,10,10,10,10,10,
  111629. 10,10,10,10,10,10,10,10,10, 9,10,10,10,10,10,10,
  111630. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111631. 10,
  111632. };
  111633. static float _vq_quantthresh__16c2_s_p9_1[] = {
  111634. -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5, -24.5,
  111635. 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5, 367.5,
  111636. };
  111637. static long _vq_quantmap__16c2_s_p9_1[] = {
  111638. 15, 13, 11, 9, 7, 5, 3, 1,
  111639. 0, 2, 4, 6, 8, 10, 12, 14,
  111640. 16,
  111641. };
  111642. static encode_aux_threshmatch _vq_auxt__16c2_s_p9_1 = {
  111643. _vq_quantthresh__16c2_s_p9_1,
  111644. _vq_quantmap__16c2_s_p9_1,
  111645. 17,
  111646. 17
  111647. };
  111648. static static_codebook _16c2_s_p9_1 = {
  111649. 2, 289,
  111650. _vq_lengthlist__16c2_s_p9_1,
  111651. 1, -518488064, 1622704128, 5, 0,
  111652. _vq_quantlist__16c2_s_p9_1,
  111653. NULL,
  111654. &_vq_auxt__16c2_s_p9_1,
  111655. NULL,
  111656. 0
  111657. };
  111658. static long _vq_quantlist__16c2_s_p9_2[] = {
  111659. 13,
  111660. 12,
  111661. 14,
  111662. 11,
  111663. 15,
  111664. 10,
  111665. 16,
  111666. 9,
  111667. 17,
  111668. 8,
  111669. 18,
  111670. 7,
  111671. 19,
  111672. 6,
  111673. 20,
  111674. 5,
  111675. 21,
  111676. 4,
  111677. 22,
  111678. 3,
  111679. 23,
  111680. 2,
  111681. 24,
  111682. 1,
  111683. 25,
  111684. 0,
  111685. 26,
  111686. };
  111687. static long _vq_lengthlist__16c2_s_p9_2[] = {
  111688. 1, 4, 4, 5, 5, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7,
  111689. 7, 7, 7, 7, 8, 7, 8, 7, 7, 4, 4,
  111690. };
  111691. static float _vq_quantthresh__16c2_s_p9_2[] = {
  111692. -12.5, -11.5, -10.5, -9.5, -8.5, -7.5, -6.5, -5.5,
  111693. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  111694. 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5,
  111695. 11.5, 12.5,
  111696. };
  111697. static long _vq_quantmap__16c2_s_p9_2[] = {
  111698. 25, 23, 21, 19, 17, 15, 13, 11,
  111699. 9, 7, 5, 3, 1, 0, 2, 4,
  111700. 6, 8, 10, 12, 14, 16, 18, 20,
  111701. 22, 24, 26,
  111702. };
  111703. static encode_aux_threshmatch _vq_auxt__16c2_s_p9_2 = {
  111704. _vq_quantthresh__16c2_s_p9_2,
  111705. _vq_quantmap__16c2_s_p9_2,
  111706. 27,
  111707. 27
  111708. };
  111709. static static_codebook _16c2_s_p9_2 = {
  111710. 1, 27,
  111711. _vq_lengthlist__16c2_s_p9_2,
  111712. 1, -528875520, 1611661312, 5, 0,
  111713. _vq_quantlist__16c2_s_p9_2,
  111714. NULL,
  111715. &_vq_auxt__16c2_s_p9_2,
  111716. NULL,
  111717. 0
  111718. };
  111719. static long _huff_lengthlist__16c2_s_short[] = {
  111720. 7,10,11,11,11,14,15,15,17,14, 8, 6, 7, 7, 8, 9,
  111721. 11,11,14,17, 9, 6, 6, 6, 7, 7,10,11,15,16, 9, 6,
  111722. 6, 4, 4, 5, 8, 9,12,16,10, 6, 6, 4, 4, 4, 6, 9,
  111723. 13,16,10, 7, 6, 5, 4, 3, 5, 7,13,16,11, 9, 8, 7,
  111724. 6, 5, 5, 6,12,15,10,10,10, 9, 7, 6, 6, 7,11,15,
  111725. 13,13,13,13,11,10,10, 9,12,16,16,16,16,14,16,15,
  111726. 15,12,14,14,
  111727. };
  111728. static static_codebook _huff_book__16c2_s_short = {
  111729. 2, 100,
  111730. _huff_lengthlist__16c2_s_short,
  111731. 0, 0, 0, 0, 0,
  111732. NULL,
  111733. NULL,
  111734. NULL,
  111735. NULL,
  111736. 0
  111737. };
  111738. static long _vq_quantlist__8c0_s_p1_0[] = {
  111739. 1,
  111740. 0,
  111741. 2,
  111742. };
  111743. static long _vq_lengthlist__8c0_s_p1_0[] = {
  111744. 1, 5, 4, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  111745. 0, 0, 5, 7, 7, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 9, 0, 0, 0,
  111750. 0, 0, 0, 7, 8, 9, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  111755. 0, 0, 0, 0, 7, 9, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0, 0, 0, 0,
  111790. 0, 0, 8,10,10, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 7,10, 9, 0, 0, 0,
  111795. 0, 0, 0, 8, 9,11, 0, 0, 0, 0, 0, 0, 9,11,11, 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, 7, 9,10, 0, 0,
  111800. 0, 0, 0, 0, 9,11,10, 0, 0, 0, 0, 0, 0, 9,11,11,
  111801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111835. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  111836. 0, 0, 0, 0, 8, 9,10, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,11,11, 0,
  111841. 0, 0, 0, 0, 0, 9,10,11, 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, 7, 9,10, 0, 0, 0, 0, 0, 0, 9,11,11,
  111846. 0, 0, 0, 0, 0, 0, 8,11, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112134. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112135. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112136. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112137. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112138. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112139. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112140. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112141. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112142. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112143. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112144. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112145. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112146. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112147. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112148. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112150. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112151. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112152. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112153. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112154. 0,
  112155. };
  112156. static float _vq_quantthresh__8c0_s_p1_0[] = {
  112157. -0.5, 0.5,
  112158. };
  112159. static long _vq_quantmap__8c0_s_p1_0[] = {
  112160. 1, 0, 2,
  112161. };
  112162. static encode_aux_threshmatch _vq_auxt__8c0_s_p1_0 = {
  112163. _vq_quantthresh__8c0_s_p1_0,
  112164. _vq_quantmap__8c0_s_p1_0,
  112165. 3,
  112166. 3
  112167. };
  112168. static static_codebook _8c0_s_p1_0 = {
  112169. 8, 6561,
  112170. _vq_lengthlist__8c0_s_p1_0,
  112171. 1, -535822336, 1611661312, 2, 0,
  112172. _vq_quantlist__8c0_s_p1_0,
  112173. NULL,
  112174. &_vq_auxt__8c0_s_p1_0,
  112175. NULL,
  112176. 0
  112177. };
  112178. static long _vq_quantlist__8c0_s_p2_0[] = {
  112179. 2,
  112180. 1,
  112181. 3,
  112182. 0,
  112183. 4,
  112184. };
  112185. static long _vq_lengthlist__8c0_s_p2_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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112201. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112203. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112207. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112225. 0,
  112226. };
  112227. static float _vq_quantthresh__8c0_s_p2_0[] = {
  112228. -1.5, -0.5, 0.5, 1.5,
  112229. };
  112230. static long _vq_quantmap__8c0_s_p2_0[] = {
  112231. 3, 1, 0, 2, 4,
  112232. };
  112233. static encode_aux_threshmatch _vq_auxt__8c0_s_p2_0 = {
  112234. _vq_quantthresh__8c0_s_p2_0,
  112235. _vq_quantmap__8c0_s_p2_0,
  112236. 5,
  112237. 5
  112238. };
  112239. static static_codebook _8c0_s_p2_0 = {
  112240. 4, 625,
  112241. _vq_lengthlist__8c0_s_p2_0,
  112242. 1, -533725184, 1611661312, 3, 0,
  112243. _vq_quantlist__8c0_s_p2_0,
  112244. NULL,
  112245. &_vq_auxt__8c0_s_p2_0,
  112246. NULL,
  112247. 0
  112248. };
  112249. static long _vq_quantlist__8c0_s_p3_0[] = {
  112250. 2,
  112251. 1,
  112252. 3,
  112253. 0,
  112254. 4,
  112255. };
  112256. static long _vq_lengthlist__8c0_s_p3_0[] = {
  112257. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112258. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 6, 7, 7, 0, 0,
  112259. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112260. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112261. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 8, 8,
  112262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112263. 0, 0, 0, 0, 6, 7, 7, 8, 8, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112268. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112269. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112270. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112273. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112278. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112280. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112285. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112286. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112288. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112293. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112296. 0,
  112297. };
  112298. static float _vq_quantthresh__8c0_s_p3_0[] = {
  112299. -1.5, -0.5, 0.5, 1.5,
  112300. };
  112301. static long _vq_quantmap__8c0_s_p3_0[] = {
  112302. 3, 1, 0, 2, 4,
  112303. };
  112304. static encode_aux_threshmatch _vq_auxt__8c0_s_p3_0 = {
  112305. _vq_quantthresh__8c0_s_p3_0,
  112306. _vq_quantmap__8c0_s_p3_0,
  112307. 5,
  112308. 5
  112309. };
  112310. static static_codebook _8c0_s_p3_0 = {
  112311. 4, 625,
  112312. _vq_lengthlist__8c0_s_p3_0,
  112313. 1, -533725184, 1611661312, 3, 0,
  112314. _vq_quantlist__8c0_s_p3_0,
  112315. NULL,
  112316. &_vq_auxt__8c0_s_p3_0,
  112317. NULL,
  112318. 0
  112319. };
  112320. static long _vq_quantlist__8c0_s_p4_0[] = {
  112321. 4,
  112322. 3,
  112323. 5,
  112324. 2,
  112325. 6,
  112326. 1,
  112327. 7,
  112328. 0,
  112329. 8,
  112330. };
  112331. static long _vq_lengthlist__8c0_s_p4_0[] = {
  112332. 1, 2, 3, 7, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  112333. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  112334. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  112335. 8, 8, 0, 0, 0, 0, 0, 0, 0, 9, 8, 0, 0, 0, 0, 0,
  112336. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112337. 0,
  112338. };
  112339. static float _vq_quantthresh__8c0_s_p4_0[] = {
  112340. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  112341. };
  112342. static long _vq_quantmap__8c0_s_p4_0[] = {
  112343. 7, 5, 3, 1, 0, 2, 4, 6,
  112344. 8,
  112345. };
  112346. static encode_aux_threshmatch _vq_auxt__8c0_s_p4_0 = {
  112347. _vq_quantthresh__8c0_s_p4_0,
  112348. _vq_quantmap__8c0_s_p4_0,
  112349. 9,
  112350. 9
  112351. };
  112352. static static_codebook _8c0_s_p4_0 = {
  112353. 2, 81,
  112354. _vq_lengthlist__8c0_s_p4_0,
  112355. 1, -531628032, 1611661312, 4, 0,
  112356. _vq_quantlist__8c0_s_p4_0,
  112357. NULL,
  112358. &_vq_auxt__8c0_s_p4_0,
  112359. NULL,
  112360. 0
  112361. };
  112362. static long _vq_quantlist__8c0_s_p5_0[] = {
  112363. 4,
  112364. 3,
  112365. 5,
  112366. 2,
  112367. 6,
  112368. 1,
  112369. 7,
  112370. 0,
  112371. 8,
  112372. };
  112373. static long _vq_lengthlist__8c0_s_p5_0[] = {
  112374. 1, 3, 3, 5, 5, 7, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  112375. 8, 8, 0, 0, 0, 7, 7, 7, 7, 8, 9, 0, 0, 0, 8, 8,
  112376. 8, 8, 9, 9, 0, 0, 0, 8, 8, 8, 8, 9, 9, 0, 0, 0,
  112377. 9, 9, 8, 8,10,10, 0, 0, 0, 9, 9, 8, 8,10,10, 0,
  112378. 0, 0,10,10, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  112379. 10,
  112380. };
  112381. static float _vq_quantthresh__8c0_s_p5_0[] = {
  112382. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  112383. };
  112384. static long _vq_quantmap__8c0_s_p5_0[] = {
  112385. 7, 5, 3, 1, 0, 2, 4, 6,
  112386. 8,
  112387. };
  112388. static encode_aux_threshmatch _vq_auxt__8c0_s_p5_0 = {
  112389. _vq_quantthresh__8c0_s_p5_0,
  112390. _vq_quantmap__8c0_s_p5_0,
  112391. 9,
  112392. 9
  112393. };
  112394. static static_codebook _8c0_s_p5_0 = {
  112395. 2, 81,
  112396. _vq_lengthlist__8c0_s_p5_0,
  112397. 1, -531628032, 1611661312, 4, 0,
  112398. _vq_quantlist__8c0_s_p5_0,
  112399. NULL,
  112400. &_vq_auxt__8c0_s_p5_0,
  112401. NULL,
  112402. 0
  112403. };
  112404. static long _vq_quantlist__8c0_s_p6_0[] = {
  112405. 8,
  112406. 7,
  112407. 9,
  112408. 6,
  112409. 10,
  112410. 5,
  112411. 11,
  112412. 4,
  112413. 12,
  112414. 3,
  112415. 13,
  112416. 2,
  112417. 14,
  112418. 1,
  112419. 15,
  112420. 0,
  112421. 16,
  112422. };
  112423. static long _vq_lengthlist__8c0_s_p6_0[] = {
  112424. 1, 3, 3, 6, 6, 8, 8, 9, 9, 8, 8,10, 9,10,10,11,
  112425. 11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  112426. 11,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  112427. 11,12,11, 0, 0, 0, 8, 8, 9, 9,10,10, 9, 9,10,10,
  112428. 11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10, 9, 9,11,
  112429. 10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,10,10,
  112430. 11,11,11,12,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,10,
  112431. 10,11,11,12,12,13,13, 0, 0, 0,10,10,10,10,11,11,
  112432. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,10, 9,10,
  112433. 11,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  112434. 10, 9,10,11,12,12,13,13,14,13, 0, 0, 0, 0, 0, 9,
  112435. 9, 9,10,10,10,11,11,13,12,13,13, 0, 0, 0, 0, 0,
  112436. 10,10,10,10,11,11,12,12,13,13,14,14, 0, 0, 0, 0,
  112437. 0, 0, 0,10,10,11,11,12,12,13,13,13,14, 0, 0, 0,
  112438. 0, 0, 0, 0,11,11,11,11,12,12,13,14,14,14, 0, 0,
  112439. 0, 0, 0, 0, 0,11,11,11,11,12,12,13,13,14,13, 0,
  112440. 0, 0, 0, 0, 0, 0,11,11,12,12,13,13,14,14,14,14,
  112441. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  112442. 14,
  112443. };
  112444. static float _vq_quantthresh__8c0_s_p6_0[] = {
  112445. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  112446. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  112447. };
  112448. static long _vq_quantmap__8c0_s_p6_0[] = {
  112449. 15, 13, 11, 9, 7, 5, 3, 1,
  112450. 0, 2, 4, 6, 8, 10, 12, 14,
  112451. 16,
  112452. };
  112453. static encode_aux_threshmatch _vq_auxt__8c0_s_p6_0 = {
  112454. _vq_quantthresh__8c0_s_p6_0,
  112455. _vq_quantmap__8c0_s_p6_0,
  112456. 17,
  112457. 17
  112458. };
  112459. static static_codebook _8c0_s_p6_0 = {
  112460. 2, 289,
  112461. _vq_lengthlist__8c0_s_p6_0,
  112462. 1, -529530880, 1611661312, 5, 0,
  112463. _vq_quantlist__8c0_s_p6_0,
  112464. NULL,
  112465. &_vq_auxt__8c0_s_p6_0,
  112466. NULL,
  112467. 0
  112468. };
  112469. static long _vq_quantlist__8c0_s_p7_0[] = {
  112470. 1,
  112471. 0,
  112472. 2,
  112473. };
  112474. static long _vq_lengthlist__8c0_s_p7_0[] = {
  112475. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,11, 9,10,12,
  112476. 9,10, 4, 7, 7,10,10,10,11, 9, 9, 6,11,10,11,11,
  112477. 12,11,11,11, 6,10,10,11,11,12,11,10,10, 6, 9,10,
  112478. 11,11,11,11,10,10, 7,10,11,12,11,11,12,11,12, 6,
  112479. 9, 9,10, 9, 9,11,10,10, 6, 9, 9,10,10,10,11,10,
  112480. 10,
  112481. };
  112482. static float _vq_quantthresh__8c0_s_p7_0[] = {
  112483. -5.5, 5.5,
  112484. };
  112485. static long _vq_quantmap__8c0_s_p7_0[] = {
  112486. 1, 0, 2,
  112487. };
  112488. static encode_aux_threshmatch _vq_auxt__8c0_s_p7_0 = {
  112489. _vq_quantthresh__8c0_s_p7_0,
  112490. _vq_quantmap__8c0_s_p7_0,
  112491. 3,
  112492. 3
  112493. };
  112494. static static_codebook _8c0_s_p7_0 = {
  112495. 4, 81,
  112496. _vq_lengthlist__8c0_s_p7_0,
  112497. 1, -529137664, 1618345984, 2, 0,
  112498. _vq_quantlist__8c0_s_p7_0,
  112499. NULL,
  112500. &_vq_auxt__8c0_s_p7_0,
  112501. NULL,
  112502. 0
  112503. };
  112504. static long _vq_quantlist__8c0_s_p7_1[] = {
  112505. 5,
  112506. 4,
  112507. 6,
  112508. 3,
  112509. 7,
  112510. 2,
  112511. 8,
  112512. 1,
  112513. 9,
  112514. 0,
  112515. 10,
  112516. };
  112517. static long _vq_lengthlist__8c0_s_p7_1[] = {
  112518. 1, 3, 3, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10, 7, 7,
  112519. 8, 8, 9, 9, 9, 9,10,10, 9, 7, 7, 8, 8, 9, 9, 9,
  112520. 9,10,10,10, 8, 8, 9, 9, 9, 9, 9, 9,10,10,10, 8,
  112521. 8, 9, 9, 9, 9, 8, 9,10,10,10, 8, 8, 9, 9, 9,10,
  112522. 10,10,10,10,10, 9, 9, 9, 9, 9, 9,10,10,11,10,11,
  112523. 9, 9, 9, 9,10,10,10,10,11,11,11,10,10, 9, 9,10,
  112524. 10,10, 9,11,10,10,10,10,10,10, 9, 9,10,10,11,11,
  112525. 10,10,10, 9, 9, 9,10,10,10,
  112526. };
  112527. static float _vq_quantthresh__8c0_s_p7_1[] = {
  112528. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  112529. 3.5, 4.5,
  112530. };
  112531. static long _vq_quantmap__8c0_s_p7_1[] = {
  112532. 9, 7, 5, 3, 1, 0, 2, 4,
  112533. 6, 8, 10,
  112534. };
  112535. static encode_aux_threshmatch _vq_auxt__8c0_s_p7_1 = {
  112536. _vq_quantthresh__8c0_s_p7_1,
  112537. _vq_quantmap__8c0_s_p7_1,
  112538. 11,
  112539. 11
  112540. };
  112541. static static_codebook _8c0_s_p7_1 = {
  112542. 2, 121,
  112543. _vq_lengthlist__8c0_s_p7_1,
  112544. 1, -531365888, 1611661312, 4, 0,
  112545. _vq_quantlist__8c0_s_p7_1,
  112546. NULL,
  112547. &_vq_auxt__8c0_s_p7_1,
  112548. NULL,
  112549. 0
  112550. };
  112551. static long _vq_quantlist__8c0_s_p8_0[] = {
  112552. 6,
  112553. 5,
  112554. 7,
  112555. 4,
  112556. 8,
  112557. 3,
  112558. 9,
  112559. 2,
  112560. 10,
  112561. 1,
  112562. 11,
  112563. 0,
  112564. 12,
  112565. };
  112566. static long _vq_lengthlist__8c0_s_p8_0[] = {
  112567. 1, 4, 4, 7, 6, 7, 7, 7, 7, 8, 8, 9, 9, 7, 6, 6,
  112568. 7, 7, 8, 8, 7, 7, 8, 9,10,10, 7, 6, 6, 7, 7, 8,
  112569. 7, 7, 7, 9, 9,10,12, 0, 8, 8, 8, 8, 8, 9, 8, 8,
  112570. 9, 9,10,10, 0, 8, 8, 8, 8, 8, 9, 8, 9, 9, 9,11,
  112571. 10, 0, 0,13, 9, 8, 9, 9, 9, 9,10,10,11,11, 0,13,
  112572. 0, 9, 9, 9, 9, 9, 9,11,10,11,11, 0, 0, 0, 8, 9,
  112573. 10, 9,10,10,13,11,12,12, 0, 0, 0, 8, 9, 9, 9,10,
  112574. 10,13,12,12,13, 0, 0, 0,12, 0,10,10,12,11,10,11,
  112575. 12,12, 0, 0, 0,13,13,10,10,10,11,12, 0,13, 0, 0,
  112576. 0, 0, 0, 0,13,11, 0,12,12,12,13,12, 0, 0, 0, 0,
  112577. 0, 0,13,13,11,13,13,11,12,
  112578. };
  112579. static float _vq_quantthresh__8c0_s_p8_0[] = {
  112580. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  112581. 12.5, 17.5, 22.5, 27.5,
  112582. };
  112583. static long _vq_quantmap__8c0_s_p8_0[] = {
  112584. 11, 9, 7, 5, 3, 1, 0, 2,
  112585. 4, 6, 8, 10, 12,
  112586. };
  112587. static encode_aux_threshmatch _vq_auxt__8c0_s_p8_0 = {
  112588. _vq_quantthresh__8c0_s_p8_0,
  112589. _vq_quantmap__8c0_s_p8_0,
  112590. 13,
  112591. 13
  112592. };
  112593. static static_codebook _8c0_s_p8_0 = {
  112594. 2, 169,
  112595. _vq_lengthlist__8c0_s_p8_0,
  112596. 1, -526516224, 1616117760, 4, 0,
  112597. _vq_quantlist__8c0_s_p8_0,
  112598. NULL,
  112599. &_vq_auxt__8c0_s_p8_0,
  112600. NULL,
  112601. 0
  112602. };
  112603. static long _vq_quantlist__8c0_s_p8_1[] = {
  112604. 2,
  112605. 1,
  112606. 3,
  112607. 0,
  112608. 4,
  112609. };
  112610. static long _vq_lengthlist__8c0_s_p8_1[] = {
  112611. 1, 3, 4, 5, 5, 7, 6, 6, 6, 5, 7, 7, 7, 6, 6, 7,
  112612. 7, 7, 6, 6, 7, 7, 7, 6, 6,
  112613. };
  112614. static float _vq_quantthresh__8c0_s_p8_1[] = {
  112615. -1.5, -0.5, 0.5, 1.5,
  112616. };
  112617. static long _vq_quantmap__8c0_s_p8_1[] = {
  112618. 3, 1, 0, 2, 4,
  112619. };
  112620. static encode_aux_threshmatch _vq_auxt__8c0_s_p8_1 = {
  112621. _vq_quantthresh__8c0_s_p8_1,
  112622. _vq_quantmap__8c0_s_p8_1,
  112623. 5,
  112624. 5
  112625. };
  112626. static static_codebook _8c0_s_p8_1 = {
  112627. 2, 25,
  112628. _vq_lengthlist__8c0_s_p8_1,
  112629. 1, -533725184, 1611661312, 3, 0,
  112630. _vq_quantlist__8c0_s_p8_1,
  112631. NULL,
  112632. &_vq_auxt__8c0_s_p8_1,
  112633. NULL,
  112634. 0
  112635. };
  112636. static long _vq_quantlist__8c0_s_p9_0[] = {
  112637. 1,
  112638. 0,
  112639. 2,
  112640. };
  112641. static long _vq_lengthlist__8c0_s_p9_0[] = {
  112642. 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  112643. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  112644. 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  112645. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  112646. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  112647. 7,
  112648. };
  112649. static float _vq_quantthresh__8c0_s_p9_0[] = {
  112650. -157.5, 157.5,
  112651. };
  112652. static long _vq_quantmap__8c0_s_p9_0[] = {
  112653. 1, 0, 2,
  112654. };
  112655. static encode_aux_threshmatch _vq_auxt__8c0_s_p9_0 = {
  112656. _vq_quantthresh__8c0_s_p9_0,
  112657. _vq_quantmap__8c0_s_p9_0,
  112658. 3,
  112659. 3
  112660. };
  112661. static static_codebook _8c0_s_p9_0 = {
  112662. 4, 81,
  112663. _vq_lengthlist__8c0_s_p9_0,
  112664. 1, -518803456, 1628680192, 2, 0,
  112665. _vq_quantlist__8c0_s_p9_0,
  112666. NULL,
  112667. &_vq_auxt__8c0_s_p9_0,
  112668. NULL,
  112669. 0
  112670. };
  112671. static long _vq_quantlist__8c0_s_p9_1[] = {
  112672. 7,
  112673. 6,
  112674. 8,
  112675. 5,
  112676. 9,
  112677. 4,
  112678. 10,
  112679. 3,
  112680. 11,
  112681. 2,
  112682. 12,
  112683. 1,
  112684. 13,
  112685. 0,
  112686. 14,
  112687. };
  112688. static long _vq_lengthlist__8c0_s_p9_1[] = {
  112689. 1, 4, 4, 5, 5,10, 8,11,11,11,11,11,11,11,11, 6,
  112690. 6, 6, 7, 6,11,10,11,11,11,11,11,11,11,11, 7, 5,
  112691. 6, 6, 6, 8, 7,11,11,11,11,11,11,11,11,11, 7, 8,
  112692. 8, 8, 9, 9,11,11,11,11,11,11,11,11,11, 9, 8, 7,
  112693. 8, 9,11,11,11,11,11,11,11,11,11,11,11,10,11,11,
  112694. 11,11,11,11,11,11,11,11,11,11,11,11,11,10,11,11,
  112695. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112696. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112697. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112698. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112699. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112700. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112701. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112702. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112703. 11,
  112704. };
  112705. static float _vq_quantthresh__8c0_s_p9_1[] = {
  112706. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  112707. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  112708. };
  112709. static long _vq_quantmap__8c0_s_p9_1[] = {
  112710. 13, 11, 9, 7, 5, 3, 1, 0,
  112711. 2, 4, 6, 8, 10, 12, 14,
  112712. };
  112713. static encode_aux_threshmatch _vq_auxt__8c0_s_p9_1 = {
  112714. _vq_quantthresh__8c0_s_p9_1,
  112715. _vq_quantmap__8c0_s_p9_1,
  112716. 15,
  112717. 15
  112718. };
  112719. static static_codebook _8c0_s_p9_1 = {
  112720. 2, 225,
  112721. _vq_lengthlist__8c0_s_p9_1,
  112722. 1, -520986624, 1620377600, 4, 0,
  112723. _vq_quantlist__8c0_s_p9_1,
  112724. NULL,
  112725. &_vq_auxt__8c0_s_p9_1,
  112726. NULL,
  112727. 0
  112728. };
  112729. static long _vq_quantlist__8c0_s_p9_2[] = {
  112730. 10,
  112731. 9,
  112732. 11,
  112733. 8,
  112734. 12,
  112735. 7,
  112736. 13,
  112737. 6,
  112738. 14,
  112739. 5,
  112740. 15,
  112741. 4,
  112742. 16,
  112743. 3,
  112744. 17,
  112745. 2,
  112746. 18,
  112747. 1,
  112748. 19,
  112749. 0,
  112750. 20,
  112751. };
  112752. static long _vq_lengthlist__8c0_s_p9_2[] = {
  112753. 1, 5, 5, 7, 7, 8, 7, 8, 8,10,10, 9, 9,10,10,10,
  112754. 11,11,10,12,11,12,12,12, 9, 8, 8, 8, 8, 8, 9,10,
  112755. 10,10,10,11,11,11,10,11,11,12,12,11,12, 8, 8, 7,
  112756. 7, 8, 9,10,10,10, 9,10,10, 9,10,10,11,11,11,11,
  112757. 11,11, 9, 9, 9, 9, 8, 9,10,10,11,10,10,11,11,12,
  112758. 10,10,12,12,11,11,10, 9, 9,10, 8, 9,10,10,10, 9,
  112759. 10,10,11,11,10,11,10,10,10,12,12,12, 9,10, 9,10,
  112760. 9, 9,10,10,11,11,11,11,10,10,10,11,12,11,12,11,
  112761. 12,10,11,10,11, 9,10, 9,10, 9,10,10, 9,10,10,11,
  112762. 10,11,11,11,11,12,11, 9,10,10,10,10,11,11,11,11,
  112763. 11,10,11,11,11,11,10,12,10,12,12,11,12,10,10,11,
  112764. 10, 9,11,10,11, 9,10,11,10,10,10,11,11,11,11,12,
  112765. 12,10, 9, 9,11,10, 9,12,11,10,12,12,11,11,11,11,
  112766. 10,11,11,12,11,10,12, 9,11,10,11,10,10,11,10,11,
  112767. 9,10,10,10,11,12,11,11,12,11,10,10,11,11, 9,10,
  112768. 10,12,10,11,10,10,10, 9,10,10,10,10, 9,10,10,11,
  112769. 11,11,11,12,11,10,10,10,10,11,11,10,11,11, 9,11,
  112770. 10,12,10,12,11,10,11,10,10,10,11,10,10,11,11,10,
  112771. 11,10,10,10,10,11,11,12,10,10,10,11,10,11,12,11,
  112772. 10,11,10,10,11,11,10,12,10, 9,10,10,11,11,11,10,
  112773. 12,10,10,11,11,11,10,10,11,10,10,10,11,10,11,10,
  112774. 12,11,11,10,10,10,12,10,10,11, 9,10,11,11,11,10,
  112775. 10,11,10,10, 9,11,11,12,12,11,12,11,11,11,11,11,
  112776. 11, 9,10,11,10,12,10,10,10,10,11,10,10,11,10,10,
  112777. 12,10,10,10,10,10, 9,12,10,10,10,10,12, 9,11,10,
  112778. 10,11,10,12,12,10,12,12,12,10,10,10,10, 9,10,11,
  112779. 10,10,12,10,10,12,11,10,11,10,10,12,11,10,12,10,
  112780. 10,11, 9,11,10, 9,10, 9,10,
  112781. };
  112782. static float _vq_quantthresh__8c0_s_p9_2[] = {
  112783. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  112784. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  112785. 6.5, 7.5, 8.5, 9.5,
  112786. };
  112787. static long _vq_quantmap__8c0_s_p9_2[] = {
  112788. 19, 17, 15, 13, 11, 9, 7, 5,
  112789. 3, 1, 0, 2, 4, 6, 8, 10,
  112790. 12, 14, 16, 18, 20,
  112791. };
  112792. static encode_aux_threshmatch _vq_auxt__8c0_s_p9_2 = {
  112793. _vq_quantthresh__8c0_s_p9_2,
  112794. _vq_quantmap__8c0_s_p9_2,
  112795. 21,
  112796. 21
  112797. };
  112798. static static_codebook _8c0_s_p9_2 = {
  112799. 2, 441,
  112800. _vq_lengthlist__8c0_s_p9_2,
  112801. 1, -529268736, 1611661312, 5, 0,
  112802. _vq_quantlist__8c0_s_p9_2,
  112803. NULL,
  112804. &_vq_auxt__8c0_s_p9_2,
  112805. NULL,
  112806. 0
  112807. };
  112808. static long _huff_lengthlist__8c0_s_single[] = {
  112809. 4, 5,18, 7,10, 6, 7, 8, 9,10, 5, 2,18, 5, 7, 5,
  112810. 6, 7, 8,11,17,17,17,17,17,17,17,17,17,17, 7, 4,
  112811. 17, 6, 9, 6, 8,10,12,15,11, 7,17, 9, 6, 6, 7, 9,
  112812. 11,15, 6, 4,17, 6, 6, 4, 5, 8,11,16, 6, 6,17, 8,
  112813. 6, 5, 6, 9,13,16, 8, 9,17,11, 9, 8, 8,11,13,17,
  112814. 9,12,17,15,14,13,12,13,14,17,12,15,17,17,17,17,
  112815. 17,16,17,17,
  112816. };
  112817. static static_codebook _huff_book__8c0_s_single = {
  112818. 2, 100,
  112819. _huff_lengthlist__8c0_s_single,
  112820. 0, 0, 0, 0, 0,
  112821. NULL,
  112822. NULL,
  112823. NULL,
  112824. NULL,
  112825. 0
  112826. };
  112827. static long _vq_quantlist__8c1_s_p1_0[] = {
  112828. 1,
  112829. 0,
  112830. 2,
  112831. };
  112832. static long _vq_lengthlist__8c1_s_p1_0[] = {
  112833. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  112834. 0, 0, 5, 7, 7, 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, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 8, 9, 0, 0, 0,
  112839. 0, 0, 0, 7, 8, 9, 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, 5, 7, 8, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  112844. 0, 0, 0, 0, 7, 9, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0, 0, 0, 0,
  112879. 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0,
  112884. 0, 0, 0, 8, 8,10, 0, 0, 0, 0, 0, 0, 9,10,10, 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, 7, 9, 9, 0, 0,
  112889. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  112890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112918. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112922. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112923. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112924. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  112925. 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  112930. 0, 0, 0, 0, 0, 8, 9,10, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  112935. 0, 0, 0, 0, 0, 0, 8,10, 8, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113229. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113234. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113243. 0,
  113244. };
  113245. static float _vq_quantthresh__8c1_s_p1_0[] = {
  113246. -0.5, 0.5,
  113247. };
  113248. static long _vq_quantmap__8c1_s_p1_0[] = {
  113249. 1, 0, 2,
  113250. };
  113251. static encode_aux_threshmatch _vq_auxt__8c1_s_p1_0 = {
  113252. _vq_quantthresh__8c1_s_p1_0,
  113253. _vq_quantmap__8c1_s_p1_0,
  113254. 3,
  113255. 3
  113256. };
  113257. static static_codebook _8c1_s_p1_0 = {
  113258. 8, 6561,
  113259. _vq_lengthlist__8c1_s_p1_0,
  113260. 1, -535822336, 1611661312, 2, 0,
  113261. _vq_quantlist__8c1_s_p1_0,
  113262. NULL,
  113263. &_vq_auxt__8c1_s_p1_0,
  113264. NULL,
  113265. 0
  113266. };
  113267. static long _vq_quantlist__8c1_s_p2_0[] = {
  113268. 2,
  113269. 1,
  113270. 3,
  113271. 0,
  113272. 4,
  113273. };
  113274. static long _vq_lengthlist__8c1_s_p2_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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113286. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113288. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113293. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113296. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113299. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113302. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113304. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113305. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113306. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113307. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113310. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113311. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113312. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113313. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113314. 0,
  113315. };
  113316. static float _vq_quantthresh__8c1_s_p2_0[] = {
  113317. -1.5, -0.5, 0.5, 1.5,
  113318. };
  113319. static long _vq_quantmap__8c1_s_p2_0[] = {
  113320. 3, 1, 0, 2, 4,
  113321. };
  113322. static encode_aux_threshmatch _vq_auxt__8c1_s_p2_0 = {
  113323. _vq_quantthresh__8c1_s_p2_0,
  113324. _vq_quantmap__8c1_s_p2_0,
  113325. 5,
  113326. 5
  113327. };
  113328. static static_codebook _8c1_s_p2_0 = {
  113329. 4, 625,
  113330. _vq_lengthlist__8c1_s_p2_0,
  113331. 1, -533725184, 1611661312, 3, 0,
  113332. _vq_quantlist__8c1_s_p2_0,
  113333. NULL,
  113334. &_vq_auxt__8c1_s_p2_0,
  113335. NULL,
  113336. 0
  113337. };
  113338. static long _vq_quantlist__8c1_s_p3_0[] = {
  113339. 2,
  113340. 1,
  113341. 3,
  113342. 0,
  113343. 4,
  113344. };
  113345. static long _vq_lengthlist__8c1_s_p3_0[] = {
  113346. 2, 4, 4, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  113348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113349. 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 7, 7,
  113351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113352. 0, 0, 0, 0, 6, 6, 6, 7, 7, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113385. 0,
  113386. };
  113387. static float _vq_quantthresh__8c1_s_p3_0[] = {
  113388. -1.5, -0.5, 0.5, 1.5,
  113389. };
  113390. static long _vq_quantmap__8c1_s_p3_0[] = {
  113391. 3, 1, 0, 2, 4,
  113392. };
  113393. static encode_aux_threshmatch _vq_auxt__8c1_s_p3_0 = {
  113394. _vq_quantthresh__8c1_s_p3_0,
  113395. _vq_quantmap__8c1_s_p3_0,
  113396. 5,
  113397. 5
  113398. };
  113399. static static_codebook _8c1_s_p3_0 = {
  113400. 4, 625,
  113401. _vq_lengthlist__8c1_s_p3_0,
  113402. 1, -533725184, 1611661312, 3, 0,
  113403. _vq_quantlist__8c1_s_p3_0,
  113404. NULL,
  113405. &_vq_auxt__8c1_s_p3_0,
  113406. NULL,
  113407. 0
  113408. };
  113409. static long _vq_quantlist__8c1_s_p4_0[] = {
  113410. 4,
  113411. 3,
  113412. 5,
  113413. 2,
  113414. 6,
  113415. 1,
  113416. 7,
  113417. 0,
  113418. 8,
  113419. };
  113420. static long _vq_lengthlist__8c1_s_p4_0[] = {
  113421. 1, 2, 3, 7, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  113422. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  113423. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  113424. 8, 8, 0, 0, 0, 0, 0, 0, 0, 9, 8, 0, 0, 0, 0, 0,
  113425. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113426. 0,
  113427. };
  113428. static float _vq_quantthresh__8c1_s_p4_0[] = {
  113429. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  113430. };
  113431. static long _vq_quantmap__8c1_s_p4_0[] = {
  113432. 7, 5, 3, 1, 0, 2, 4, 6,
  113433. 8,
  113434. };
  113435. static encode_aux_threshmatch _vq_auxt__8c1_s_p4_0 = {
  113436. _vq_quantthresh__8c1_s_p4_0,
  113437. _vq_quantmap__8c1_s_p4_0,
  113438. 9,
  113439. 9
  113440. };
  113441. static static_codebook _8c1_s_p4_0 = {
  113442. 2, 81,
  113443. _vq_lengthlist__8c1_s_p4_0,
  113444. 1, -531628032, 1611661312, 4, 0,
  113445. _vq_quantlist__8c1_s_p4_0,
  113446. NULL,
  113447. &_vq_auxt__8c1_s_p4_0,
  113448. NULL,
  113449. 0
  113450. };
  113451. static long _vq_quantlist__8c1_s_p5_0[] = {
  113452. 4,
  113453. 3,
  113454. 5,
  113455. 2,
  113456. 6,
  113457. 1,
  113458. 7,
  113459. 0,
  113460. 8,
  113461. };
  113462. static long _vq_lengthlist__8c1_s_p5_0[] = {
  113463. 1, 3, 3, 4, 5, 6, 6, 8, 8, 0, 0, 0, 8, 8, 7, 7,
  113464. 9, 9, 0, 0, 0, 8, 8, 7, 7, 9, 9, 0, 0, 0, 9,10,
  113465. 8, 8, 9, 9, 0, 0, 0,10,10, 8, 8, 9, 9, 0, 0, 0,
  113466. 11,10, 8, 8,10,10, 0, 0, 0,11,11, 8, 8,10,10, 0,
  113467. 0, 0,12,12, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  113468. 10,
  113469. };
  113470. static float _vq_quantthresh__8c1_s_p5_0[] = {
  113471. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  113472. };
  113473. static long _vq_quantmap__8c1_s_p5_0[] = {
  113474. 7, 5, 3, 1, 0, 2, 4, 6,
  113475. 8,
  113476. };
  113477. static encode_aux_threshmatch _vq_auxt__8c1_s_p5_0 = {
  113478. _vq_quantthresh__8c1_s_p5_0,
  113479. _vq_quantmap__8c1_s_p5_0,
  113480. 9,
  113481. 9
  113482. };
  113483. static static_codebook _8c1_s_p5_0 = {
  113484. 2, 81,
  113485. _vq_lengthlist__8c1_s_p5_0,
  113486. 1, -531628032, 1611661312, 4, 0,
  113487. _vq_quantlist__8c1_s_p5_0,
  113488. NULL,
  113489. &_vq_auxt__8c1_s_p5_0,
  113490. NULL,
  113491. 0
  113492. };
  113493. static long _vq_quantlist__8c1_s_p6_0[] = {
  113494. 8,
  113495. 7,
  113496. 9,
  113497. 6,
  113498. 10,
  113499. 5,
  113500. 11,
  113501. 4,
  113502. 12,
  113503. 3,
  113504. 13,
  113505. 2,
  113506. 14,
  113507. 1,
  113508. 15,
  113509. 0,
  113510. 16,
  113511. };
  113512. static long _vq_lengthlist__8c1_s_p6_0[] = {
  113513. 1, 3, 3, 5, 5, 8, 8, 8, 8, 9, 9,10,10,11,11,11,
  113514. 11, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,11,
  113515. 12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  113516. 11,12,12, 0, 0, 0, 9, 9, 8, 8,10,10,10,10,11,11,
  113517. 12,12,12,12, 0, 0, 0, 9, 9, 8, 8,10,10,10,10,11,
  113518. 11,12,12,12,12, 0, 0, 0,10,10, 9, 9,10,10,10,10,
  113519. 11,11,12,12,13,13, 0, 0, 0,10,10, 9, 9,10,10,10,
  113520. 10,11,11,12,12,13,13, 0, 0, 0,11,11, 9, 9,10,10,
  113521. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,10,
  113522. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  113523. 10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0, 0, 9,
  113524. 9,10,10,11,11,12,11,12,12,13,13, 0, 0, 0, 0, 0,
  113525. 10,10,11,11,11,11,12,12,13,12,13,13, 0, 0, 0, 0,
  113526. 0, 0, 0,11,10,11,11,12,12,13,13,13,13, 0, 0, 0,
  113527. 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0, 0,
  113528. 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,13, 0,
  113529. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,13,14,14,
  113530. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,13,13,14,
  113531. 14,
  113532. };
  113533. static float _vq_quantthresh__8c1_s_p6_0[] = {
  113534. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  113535. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  113536. };
  113537. static long _vq_quantmap__8c1_s_p6_0[] = {
  113538. 15, 13, 11, 9, 7, 5, 3, 1,
  113539. 0, 2, 4, 6, 8, 10, 12, 14,
  113540. 16,
  113541. };
  113542. static encode_aux_threshmatch _vq_auxt__8c1_s_p6_0 = {
  113543. _vq_quantthresh__8c1_s_p6_0,
  113544. _vq_quantmap__8c1_s_p6_0,
  113545. 17,
  113546. 17
  113547. };
  113548. static static_codebook _8c1_s_p6_0 = {
  113549. 2, 289,
  113550. _vq_lengthlist__8c1_s_p6_0,
  113551. 1, -529530880, 1611661312, 5, 0,
  113552. _vq_quantlist__8c1_s_p6_0,
  113553. NULL,
  113554. &_vq_auxt__8c1_s_p6_0,
  113555. NULL,
  113556. 0
  113557. };
  113558. static long _vq_quantlist__8c1_s_p7_0[] = {
  113559. 1,
  113560. 0,
  113561. 2,
  113562. };
  113563. static long _vq_lengthlist__8c1_s_p7_0[] = {
  113564. 1, 4, 4, 6, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,10,
  113565. 9, 9, 5, 7, 7,10, 9, 9,10, 9, 9, 6,10,10,10,10,
  113566. 10,11,10,10, 6, 9, 9,10, 9,10,11,10,10, 6, 9, 9,
  113567. 10, 9, 9,11, 9,10, 7,10,10,11,11,11,11,10,10, 6,
  113568. 9, 9,10,10,10,11, 9, 9, 6, 9, 9,10,10,10,10, 9,
  113569. 9,
  113570. };
  113571. static float _vq_quantthresh__8c1_s_p7_0[] = {
  113572. -5.5, 5.5,
  113573. };
  113574. static long _vq_quantmap__8c1_s_p7_0[] = {
  113575. 1, 0, 2,
  113576. };
  113577. static encode_aux_threshmatch _vq_auxt__8c1_s_p7_0 = {
  113578. _vq_quantthresh__8c1_s_p7_0,
  113579. _vq_quantmap__8c1_s_p7_0,
  113580. 3,
  113581. 3
  113582. };
  113583. static static_codebook _8c1_s_p7_0 = {
  113584. 4, 81,
  113585. _vq_lengthlist__8c1_s_p7_0,
  113586. 1, -529137664, 1618345984, 2, 0,
  113587. _vq_quantlist__8c1_s_p7_0,
  113588. NULL,
  113589. &_vq_auxt__8c1_s_p7_0,
  113590. NULL,
  113591. 0
  113592. };
  113593. static long _vq_quantlist__8c1_s_p7_1[] = {
  113594. 5,
  113595. 4,
  113596. 6,
  113597. 3,
  113598. 7,
  113599. 2,
  113600. 8,
  113601. 1,
  113602. 9,
  113603. 0,
  113604. 10,
  113605. };
  113606. static long _vq_lengthlist__8c1_s_p7_1[] = {
  113607. 2, 3, 3, 5, 5, 7, 7, 7, 7, 7, 7,10,10, 9, 7, 7,
  113608. 7, 7, 8, 8, 8, 8, 9, 9, 9, 7, 7, 7, 7, 8, 8, 8,
  113609. 8,10,10,10, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  113610. 7, 7, 7, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 8, 8,
  113611. 8, 8,10,10,10, 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  113612. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  113613. 8, 8, 8,10,10,10,10,10, 8, 8, 8, 8, 8, 8,10,10,
  113614. 10,10,10, 8, 8, 8, 8, 8, 8,
  113615. };
  113616. static float _vq_quantthresh__8c1_s_p7_1[] = {
  113617. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  113618. 3.5, 4.5,
  113619. };
  113620. static long _vq_quantmap__8c1_s_p7_1[] = {
  113621. 9, 7, 5, 3, 1, 0, 2, 4,
  113622. 6, 8, 10,
  113623. };
  113624. static encode_aux_threshmatch _vq_auxt__8c1_s_p7_1 = {
  113625. _vq_quantthresh__8c1_s_p7_1,
  113626. _vq_quantmap__8c1_s_p7_1,
  113627. 11,
  113628. 11
  113629. };
  113630. static static_codebook _8c1_s_p7_1 = {
  113631. 2, 121,
  113632. _vq_lengthlist__8c1_s_p7_1,
  113633. 1, -531365888, 1611661312, 4, 0,
  113634. _vq_quantlist__8c1_s_p7_1,
  113635. NULL,
  113636. &_vq_auxt__8c1_s_p7_1,
  113637. NULL,
  113638. 0
  113639. };
  113640. static long _vq_quantlist__8c1_s_p8_0[] = {
  113641. 6,
  113642. 5,
  113643. 7,
  113644. 4,
  113645. 8,
  113646. 3,
  113647. 9,
  113648. 2,
  113649. 10,
  113650. 1,
  113651. 11,
  113652. 0,
  113653. 12,
  113654. };
  113655. static long _vq_lengthlist__8c1_s_p8_0[] = {
  113656. 1, 4, 4, 6, 6, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 5,
  113657. 7, 7, 8, 8, 8, 8, 9,10,11,11, 7, 5, 5, 7, 7, 8,
  113658. 8, 9, 9,10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  113659. 9,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  113660. 11, 0,12,12, 9, 9, 9, 9,10, 9,10,11,11,11, 0,13,
  113661. 12, 9, 8, 9, 9,10,10,11,11,12,11, 0, 0, 0, 9, 9,
  113662. 9, 9,10,10,11,11,12,12, 0, 0, 0,10,10, 9, 9,10,
  113663. 10,11,11,12,12, 0, 0, 0,13,13,10,10,11,11,12,11,
  113664. 13,12, 0, 0, 0,14,14,10,10,11,10,11,11,12,12, 0,
  113665. 0, 0, 0, 0,12,12,11,11,12,12,13,13, 0, 0, 0, 0,
  113666. 0,12,12,11,10,12,11,13,12,
  113667. };
  113668. static float _vq_quantthresh__8c1_s_p8_0[] = {
  113669. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  113670. 12.5, 17.5, 22.5, 27.5,
  113671. };
  113672. static long _vq_quantmap__8c1_s_p8_0[] = {
  113673. 11, 9, 7, 5, 3, 1, 0, 2,
  113674. 4, 6, 8, 10, 12,
  113675. };
  113676. static encode_aux_threshmatch _vq_auxt__8c1_s_p8_0 = {
  113677. _vq_quantthresh__8c1_s_p8_0,
  113678. _vq_quantmap__8c1_s_p8_0,
  113679. 13,
  113680. 13
  113681. };
  113682. static static_codebook _8c1_s_p8_0 = {
  113683. 2, 169,
  113684. _vq_lengthlist__8c1_s_p8_0,
  113685. 1, -526516224, 1616117760, 4, 0,
  113686. _vq_quantlist__8c1_s_p8_0,
  113687. NULL,
  113688. &_vq_auxt__8c1_s_p8_0,
  113689. NULL,
  113690. 0
  113691. };
  113692. static long _vq_quantlist__8c1_s_p8_1[] = {
  113693. 2,
  113694. 1,
  113695. 3,
  113696. 0,
  113697. 4,
  113698. };
  113699. static long _vq_lengthlist__8c1_s_p8_1[] = {
  113700. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  113701. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  113702. };
  113703. static float _vq_quantthresh__8c1_s_p8_1[] = {
  113704. -1.5, -0.5, 0.5, 1.5,
  113705. };
  113706. static long _vq_quantmap__8c1_s_p8_1[] = {
  113707. 3, 1, 0, 2, 4,
  113708. };
  113709. static encode_aux_threshmatch _vq_auxt__8c1_s_p8_1 = {
  113710. _vq_quantthresh__8c1_s_p8_1,
  113711. _vq_quantmap__8c1_s_p8_1,
  113712. 5,
  113713. 5
  113714. };
  113715. static static_codebook _8c1_s_p8_1 = {
  113716. 2, 25,
  113717. _vq_lengthlist__8c1_s_p8_1,
  113718. 1, -533725184, 1611661312, 3, 0,
  113719. _vq_quantlist__8c1_s_p8_1,
  113720. NULL,
  113721. &_vq_auxt__8c1_s_p8_1,
  113722. NULL,
  113723. 0
  113724. };
  113725. static long _vq_quantlist__8c1_s_p9_0[] = {
  113726. 6,
  113727. 5,
  113728. 7,
  113729. 4,
  113730. 8,
  113731. 3,
  113732. 9,
  113733. 2,
  113734. 10,
  113735. 1,
  113736. 11,
  113737. 0,
  113738. 12,
  113739. };
  113740. static long _vq_lengthlist__8c1_s_p9_0[] = {
  113741. 1, 3, 3,10,10,10,10,10,10,10,10,10,10, 5, 6, 6,
  113742. 10,10,10,10,10,10,10,10,10,10, 6, 7, 8,10,10,10,
  113743. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113744. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113745. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113746. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113747. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113748. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113749. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113750. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113751. 10,10,10,10,10, 9, 9, 9, 9,
  113752. };
  113753. static float _vq_quantthresh__8c1_s_p9_0[] = {
  113754. -1732.5, -1417.5, -1102.5, -787.5, -472.5, -157.5, 157.5, 472.5,
  113755. 787.5, 1102.5, 1417.5, 1732.5,
  113756. };
  113757. static long _vq_quantmap__8c1_s_p9_0[] = {
  113758. 11, 9, 7, 5, 3, 1, 0, 2,
  113759. 4, 6, 8, 10, 12,
  113760. };
  113761. static encode_aux_threshmatch _vq_auxt__8c1_s_p9_0 = {
  113762. _vq_quantthresh__8c1_s_p9_0,
  113763. _vq_quantmap__8c1_s_p9_0,
  113764. 13,
  113765. 13
  113766. };
  113767. static static_codebook _8c1_s_p9_0 = {
  113768. 2, 169,
  113769. _vq_lengthlist__8c1_s_p9_0,
  113770. 1, -513964032, 1628680192, 4, 0,
  113771. _vq_quantlist__8c1_s_p9_0,
  113772. NULL,
  113773. &_vq_auxt__8c1_s_p9_0,
  113774. NULL,
  113775. 0
  113776. };
  113777. static long _vq_quantlist__8c1_s_p9_1[] = {
  113778. 7,
  113779. 6,
  113780. 8,
  113781. 5,
  113782. 9,
  113783. 4,
  113784. 10,
  113785. 3,
  113786. 11,
  113787. 2,
  113788. 12,
  113789. 1,
  113790. 13,
  113791. 0,
  113792. 14,
  113793. };
  113794. static long _vq_lengthlist__8c1_s_p9_1[] = {
  113795. 1, 4, 4, 5, 5, 7, 7, 9, 9,11,11,12,12,13,13, 6,
  113796. 5, 5, 6, 6, 9, 9,10,10,12,12,12,13,15,14, 6, 5,
  113797. 5, 7, 7, 9, 9,10,10,12,12,12,13,14,13,17, 7, 7,
  113798. 8, 8,10,10,11,11,12,13,13,13,13,13,17, 7, 7, 8,
  113799. 8,10,10,11,11,13,13,13,13,14,14,17,11,11, 9, 9,
  113800. 11,11,12,12,12,13,13,14,15,13,17,12,12, 9, 9,11,
  113801. 11,12,12,13,13,13,13,14,16,17,17,17,11,12,12,12,
  113802. 13,13,13,14,15,14,15,15,17,17,17,12,12,11,11,13,
  113803. 13,14,14,15,14,15,15,17,17,17,15,15,13,13,14,14,
  113804. 15,14,15,15,16,15,17,17,17,15,15,13,13,13,14,14,
  113805. 15,15,15,15,16,17,17,17,17,16,14,15,14,14,15,14,
  113806. 14,15,15,15,17,17,17,17,17,14,14,16,14,15,15,15,
  113807. 15,15,15,17,17,17,17,17,17,16,16,15,17,15,15,14,
  113808. 17,15,17,16,17,17,17,17,16,15,14,15,15,15,15,15,
  113809. 15,
  113810. };
  113811. static float _vq_quantthresh__8c1_s_p9_1[] = {
  113812. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  113813. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  113814. };
  113815. static long _vq_quantmap__8c1_s_p9_1[] = {
  113816. 13, 11, 9, 7, 5, 3, 1, 0,
  113817. 2, 4, 6, 8, 10, 12, 14,
  113818. };
  113819. static encode_aux_threshmatch _vq_auxt__8c1_s_p9_1 = {
  113820. _vq_quantthresh__8c1_s_p9_1,
  113821. _vq_quantmap__8c1_s_p9_1,
  113822. 15,
  113823. 15
  113824. };
  113825. static static_codebook _8c1_s_p9_1 = {
  113826. 2, 225,
  113827. _vq_lengthlist__8c1_s_p9_1,
  113828. 1, -520986624, 1620377600, 4, 0,
  113829. _vq_quantlist__8c1_s_p9_1,
  113830. NULL,
  113831. &_vq_auxt__8c1_s_p9_1,
  113832. NULL,
  113833. 0
  113834. };
  113835. static long _vq_quantlist__8c1_s_p9_2[] = {
  113836. 10,
  113837. 9,
  113838. 11,
  113839. 8,
  113840. 12,
  113841. 7,
  113842. 13,
  113843. 6,
  113844. 14,
  113845. 5,
  113846. 15,
  113847. 4,
  113848. 16,
  113849. 3,
  113850. 17,
  113851. 2,
  113852. 18,
  113853. 1,
  113854. 19,
  113855. 0,
  113856. 20,
  113857. };
  113858. static long _vq_lengthlist__8c1_s_p9_2[] = {
  113859. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 8, 9, 9, 9,
  113860. 9, 9, 9, 9, 9,11,11,12, 7, 7, 7, 7, 8, 8, 9, 9,
  113861. 9, 9,10,10,10,10,10,10,10,10,11,11,11, 7, 7, 7,
  113862. 7, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,11,
  113863. 11,12, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9,10,10,10,10,
  113864. 10,10,10,10,11,11,11, 7, 7, 8, 8, 8, 8, 9, 9, 9,
  113865. 9,10,10,10,10,10,10,10,10,11,11,11, 8, 8, 8, 8,
  113866. 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,11,11,
  113867. 11, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,10,
  113868. 10,10,10,11,12,11, 9, 9, 8, 9, 9, 9, 9, 9,10,10,
  113869. 10,10,10,10,10,10,10,10,11,11,11,11,11, 8, 8, 9,
  113870. 9, 9, 9,10,10,10,10,10,10,10,10,10,10,11,12,11,
  113871. 12,11, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,
  113872. 10,10,11,11,11,11,11, 9, 9, 9, 9,10,10,10,10,10,
  113873. 10,10,10,10,10,10,10,12,11,12,11,11, 9, 9, 9,10,
  113874. 10,10,10,10,10,10,10,10,10,10,10,10,12,11,11,11,
  113875. 11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113876. 11,11,11,12,11,11,12,11,10,10,10,10,10,10,10,10,
  113877. 10,10,10,10,11,10,11,11,11,11,11,11,11,10,10,10,
  113878. 10,10,10,10,10,10,10,10,10,10,10,11,11,12,11,12,
  113879. 11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113880. 11,11,12,11,12,11,11,11,11,10,10,10,10,10,10,10,
  113881. 10,10,10,10,10,11,11,12,11,11,12,11,11,12,10,10,
  113882. 11,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,
  113883. 11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,12,
  113884. 12,11,12,11,11,12,12,12,11,11,10,10,10,10,10,10,
  113885. 10,10,10,11,12,12,11,12,12,11,12,11,11,11,11,10,
  113886. 10,10,10,10,10,10,10,10,10,
  113887. };
  113888. static float _vq_quantthresh__8c1_s_p9_2[] = {
  113889. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  113890. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  113891. 6.5, 7.5, 8.5, 9.5,
  113892. };
  113893. static long _vq_quantmap__8c1_s_p9_2[] = {
  113894. 19, 17, 15, 13, 11, 9, 7, 5,
  113895. 3, 1, 0, 2, 4, 6, 8, 10,
  113896. 12, 14, 16, 18, 20,
  113897. };
  113898. static encode_aux_threshmatch _vq_auxt__8c1_s_p9_2 = {
  113899. _vq_quantthresh__8c1_s_p9_2,
  113900. _vq_quantmap__8c1_s_p9_2,
  113901. 21,
  113902. 21
  113903. };
  113904. static static_codebook _8c1_s_p9_2 = {
  113905. 2, 441,
  113906. _vq_lengthlist__8c1_s_p9_2,
  113907. 1, -529268736, 1611661312, 5, 0,
  113908. _vq_quantlist__8c1_s_p9_2,
  113909. NULL,
  113910. &_vq_auxt__8c1_s_p9_2,
  113911. NULL,
  113912. 0
  113913. };
  113914. static long _huff_lengthlist__8c1_s_single[] = {
  113915. 4, 6,18, 8,11, 8, 8, 9, 9,10, 4, 4,18, 5, 9, 5,
  113916. 6, 7, 8,10,18,18,18,18,17,17,17,17,17,17, 7, 5,
  113917. 17, 6,11, 6, 7, 8, 9,12,12, 9,17,12, 8, 8, 9,10,
  113918. 10,13, 7, 5,17, 6, 8, 4, 5, 6, 8,10, 6, 5,17, 6,
  113919. 8, 5, 4, 5, 7, 9, 7, 7,17, 8, 9, 6, 5, 5, 6, 8,
  113920. 8, 8,17, 9,11, 8, 6, 6, 6, 7, 9,10,17,12,12,10,
  113921. 9, 7, 7, 8,
  113922. };
  113923. static static_codebook _huff_book__8c1_s_single = {
  113924. 2, 100,
  113925. _huff_lengthlist__8c1_s_single,
  113926. 0, 0, 0, 0, 0,
  113927. NULL,
  113928. NULL,
  113929. NULL,
  113930. NULL,
  113931. 0
  113932. };
  113933. static long _huff_lengthlist__44c2_s_long[] = {
  113934. 6, 6,12,10,10,10, 9,10,12,12, 6, 1,10, 5, 6, 6,
  113935. 7, 9,11,14,12, 9, 8,11, 7, 8, 9,11,13,15,10, 5,
  113936. 12, 7, 8, 7, 9,12,14,15,10, 6, 7, 8, 5, 6, 7, 9,
  113937. 12,14, 9, 6, 8, 7, 6, 6, 7, 9,12,12, 9, 7, 9, 9,
  113938. 7, 6, 6, 7,10,10,10, 9,10,11, 8, 7, 6, 6, 8,10,
  113939. 12,11,13,13,11,10, 8, 8, 8,10,11,13,15,15,14,13,
  113940. 10, 8, 8, 9,
  113941. };
  113942. static static_codebook _huff_book__44c2_s_long = {
  113943. 2, 100,
  113944. _huff_lengthlist__44c2_s_long,
  113945. 0, 0, 0, 0, 0,
  113946. NULL,
  113947. NULL,
  113948. NULL,
  113949. NULL,
  113950. 0
  113951. };
  113952. static long _vq_quantlist__44c2_s_p1_0[] = {
  113953. 1,
  113954. 0,
  113955. 2,
  113956. };
  113957. static long _vq_lengthlist__44c2_s_p1_0[] = {
  113958. 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 0,
  113959. 0, 0, 5, 6, 7, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  113964. 0, 0, 0, 6, 8, 8, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 6, 8, 7, 0, 0,
  113969. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113974. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113980. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113981. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113982. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113983. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  114004. 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, 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, 7, 8, 8, 0, 0, 0,
  114009. 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 6, 8, 8, 0, 0,
  114014. 0, 0, 0, 0, 8, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  114015. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114016. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114017. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114018. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114020. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114022. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114023. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114025. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114026. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114027. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114028. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114029. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114030. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114031. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114032. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114033. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114034. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114035. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114036. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114037. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114039. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114040. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114041. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114042. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114043. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114044. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114045. 0, 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, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  114050. 0, 0, 0, 0, 7, 8, 8, 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, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  114055. 0, 0, 0, 0, 0, 8, 8, 9, 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, 7, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  114060. 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114368. 0,
  114369. };
  114370. static float _vq_quantthresh__44c2_s_p1_0[] = {
  114371. -0.5, 0.5,
  114372. };
  114373. static long _vq_quantmap__44c2_s_p1_0[] = {
  114374. 1, 0, 2,
  114375. };
  114376. static encode_aux_threshmatch _vq_auxt__44c2_s_p1_0 = {
  114377. _vq_quantthresh__44c2_s_p1_0,
  114378. _vq_quantmap__44c2_s_p1_0,
  114379. 3,
  114380. 3
  114381. };
  114382. static static_codebook _44c2_s_p1_0 = {
  114383. 8, 6561,
  114384. _vq_lengthlist__44c2_s_p1_0,
  114385. 1, -535822336, 1611661312, 2, 0,
  114386. _vq_quantlist__44c2_s_p1_0,
  114387. NULL,
  114388. &_vq_auxt__44c2_s_p1_0,
  114389. NULL,
  114390. 0
  114391. };
  114392. static long _vq_quantlist__44c2_s_p2_0[] = {
  114393. 2,
  114394. 1,
  114395. 3,
  114396. 0,
  114397. 4,
  114398. };
  114399. static long _vq_lengthlist__44c2_s_p2_0[] = {
  114400. 1, 4, 4, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0,
  114401. 8, 8, 0, 0, 0, 0, 0, 0, 0, 4, 6, 6, 0, 0, 0, 8,
  114402. 8, 0, 0, 0, 8, 8, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0,
  114403. 0, 0, 4, 6, 6, 0, 0, 0, 8, 8, 0, 0, 0, 8, 8, 0,
  114404. 0, 0, 9, 9, 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, 7, 8, 8, 0, 0, 0,11,11, 0, 0,
  114410. 0,11,11, 0, 0, 0,12,11, 0, 0, 0, 0, 0, 0, 0, 7,
  114411. 8, 8, 0, 0, 0,10,11, 0, 0, 0,11,11, 0, 0, 0,11,
  114412. 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114417. 0, 0, 0, 6, 8, 8, 0, 0, 0,11,11, 0, 0, 0,11,11,
  114418. 0, 0, 0,12,12, 0, 0, 0, 0, 0, 0, 0, 6, 8, 8, 0,
  114419. 0, 0,10,11, 0, 0, 0,10,11, 0, 0, 0,11,11, 0, 0,
  114420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114425. 8, 9, 9, 0, 0, 0,11,12, 0, 0, 0,11,12, 0, 0, 0,
  114426. 12,11, 0, 0, 0, 0, 0, 0, 0, 8,10, 9, 0, 0, 0,12,
  114427. 11, 0, 0, 0,12,11, 0, 0, 0,11,12, 0, 0, 0, 0, 0,
  114428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114439. 0,
  114440. };
  114441. static float _vq_quantthresh__44c2_s_p2_0[] = {
  114442. -1.5, -0.5, 0.5, 1.5,
  114443. };
  114444. static long _vq_quantmap__44c2_s_p2_0[] = {
  114445. 3, 1, 0, 2, 4,
  114446. };
  114447. static encode_aux_threshmatch _vq_auxt__44c2_s_p2_0 = {
  114448. _vq_quantthresh__44c2_s_p2_0,
  114449. _vq_quantmap__44c2_s_p2_0,
  114450. 5,
  114451. 5
  114452. };
  114453. static static_codebook _44c2_s_p2_0 = {
  114454. 4, 625,
  114455. _vq_lengthlist__44c2_s_p2_0,
  114456. 1, -533725184, 1611661312, 3, 0,
  114457. _vq_quantlist__44c2_s_p2_0,
  114458. NULL,
  114459. &_vq_auxt__44c2_s_p2_0,
  114460. NULL,
  114461. 0
  114462. };
  114463. static long _vq_quantlist__44c2_s_p3_0[] = {
  114464. 2,
  114465. 1,
  114466. 3,
  114467. 0,
  114468. 4,
  114469. };
  114470. static long _vq_lengthlist__44c2_s_p3_0[] = {
  114471. 2, 4, 3, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  114473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114474. 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  114476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114477. 0, 0, 0, 0, 6, 6, 7, 9, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114510. 0,
  114511. };
  114512. static float _vq_quantthresh__44c2_s_p3_0[] = {
  114513. -1.5, -0.5, 0.5, 1.5,
  114514. };
  114515. static long _vq_quantmap__44c2_s_p3_0[] = {
  114516. 3, 1, 0, 2, 4,
  114517. };
  114518. static encode_aux_threshmatch _vq_auxt__44c2_s_p3_0 = {
  114519. _vq_quantthresh__44c2_s_p3_0,
  114520. _vq_quantmap__44c2_s_p3_0,
  114521. 5,
  114522. 5
  114523. };
  114524. static static_codebook _44c2_s_p3_0 = {
  114525. 4, 625,
  114526. _vq_lengthlist__44c2_s_p3_0,
  114527. 1, -533725184, 1611661312, 3, 0,
  114528. _vq_quantlist__44c2_s_p3_0,
  114529. NULL,
  114530. &_vq_auxt__44c2_s_p3_0,
  114531. NULL,
  114532. 0
  114533. };
  114534. static long _vq_quantlist__44c2_s_p4_0[] = {
  114535. 4,
  114536. 3,
  114537. 5,
  114538. 2,
  114539. 6,
  114540. 1,
  114541. 7,
  114542. 0,
  114543. 8,
  114544. };
  114545. static long _vq_lengthlist__44c2_s_p4_0[] = {
  114546. 1, 3, 3, 6, 6, 0, 0, 0, 0, 0, 6, 6, 6, 6, 0, 0,
  114547. 0, 0, 0, 6, 6, 6, 6, 0, 0, 0, 0, 0, 7, 7, 6, 6,
  114548. 0, 0, 0, 0, 0, 0, 0, 6, 7, 0, 0, 0, 0, 0, 0, 0,
  114549. 7, 8, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  114550. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114551. 0,
  114552. };
  114553. static float _vq_quantthresh__44c2_s_p4_0[] = {
  114554. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  114555. };
  114556. static long _vq_quantmap__44c2_s_p4_0[] = {
  114557. 7, 5, 3, 1, 0, 2, 4, 6,
  114558. 8,
  114559. };
  114560. static encode_aux_threshmatch _vq_auxt__44c2_s_p4_0 = {
  114561. _vq_quantthresh__44c2_s_p4_0,
  114562. _vq_quantmap__44c2_s_p4_0,
  114563. 9,
  114564. 9
  114565. };
  114566. static static_codebook _44c2_s_p4_0 = {
  114567. 2, 81,
  114568. _vq_lengthlist__44c2_s_p4_0,
  114569. 1, -531628032, 1611661312, 4, 0,
  114570. _vq_quantlist__44c2_s_p4_0,
  114571. NULL,
  114572. &_vq_auxt__44c2_s_p4_0,
  114573. NULL,
  114574. 0
  114575. };
  114576. static long _vq_quantlist__44c2_s_p5_0[] = {
  114577. 4,
  114578. 3,
  114579. 5,
  114580. 2,
  114581. 6,
  114582. 1,
  114583. 7,
  114584. 0,
  114585. 8,
  114586. };
  114587. static long _vq_lengthlist__44c2_s_p5_0[] = {
  114588. 1, 3, 3, 6, 6, 7, 7, 9, 9, 0, 7, 7, 7, 7, 7, 7,
  114589. 9, 9, 0, 7, 7, 7, 7, 7, 7, 9, 9, 0, 8, 8, 7, 7,
  114590. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0, 0, 0,
  114591. 9, 9, 8, 8,10,10, 0, 0, 0, 9, 9, 8, 8,10,10, 0,
  114592. 0, 0,10,10, 9, 9,11,11, 0, 0, 0, 0, 0, 9, 9,11,
  114593. 11,
  114594. };
  114595. static float _vq_quantthresh__44c2_s_p5_0[] = {
  114596. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  114597. };
  114598. static long _vq_quantmap__44c2_s_p5_0[] = {
  114599. 7, 5, 3, 1, 0, 2, 4, 6,
  114600. 8,
  114601. };
  114602. static encode_aux_threshmatch _vq_auxt__44c2_s_p5_0 = {
  114603. _vq_quantthresh__44c2_s_p5_0,
  114604. _vq_quantmap__44c2_s_p5_0,
  114605. 9,
  114606. 9
  114607. };
  114608. static static_codebook _44c2_s_p5_0 = {
  114609. 2, 81,
  114610. _vq_lengthlist__44c2_s_p5_0,
  114611. 1, -531628032, 1611661312, 4, 0,
  114612. _vq_quantlist__44c2_s_p5_0,
  114613. NULL,
  114614. &_vq_auxt__44c2_s_p5_0,
  114615. NULL,
  114616. 0
  114617. };
  114618. static long _vq_quantlist__44c2_s_p6_0[] = {
  114619. 8,
  114620. 7,
  114621. 9,
  114622. 6,
  114623. 10,
  114624. 5,
  114625. 11,
  114626. 4,
  114627. 12,
  114628. 3,
  114629. 13,
  114630. 2,
  114631. 14,
  114632. 1,
  114633. 15,
  114634. 0,
  114635. 16,
  114636. };
  114637. static long _vq_lengthlist__44c2_s_p6_0[] = {
  114638. 1, 4, 3, 6, 6, 8, 8, 9, 9, 9, 9, 9, 9,10,10,11,
  114639. 11, 0, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  114640. 12,11, 0, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  114641. 11,11,12, 0, 8, 8, 7, 7, 9, 9,10,10, 9, 9,10,10,
  114642. 11,11,12,12, 0, 0, 0, 7, 7, 9, 9,10,10,10, 9,10,
  114643. 10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  114644. 11,11,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  114645. 10,11,11,12,12,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  114646. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  114647. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  114648. 10,10,11,11,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  114649. 9,10,10,11,11,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  114650. 10,10,10,10,11,11,12,12,13,12,13,13, 0, 0, 0, 0,
  114651. 0, 0, 0,10,10,11,11,12,12,13,13,13,13, 0, 0, 0,
  114652. 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0, 0,
  114653. 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0,
  114654. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,13,14,14,
  114655. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,13,13,14,
  114656. 14,
  114657. };
  114658. static float _vq_quantthresh__44c2_s_p6_0[] = {
  114659. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  114660. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  114661. };
  114662. static long _vq_quantmap__44c2_s_p6_0[] = {
  114663. 15, 13, 11, 9, 7, 5, 3, 1,
  114664. 0, 2, 4, 6, 8, 10, 12, 14,
  114665. 16,
  114666. };
  114667. static encode_aux_threshmatch _vq_auxt__44c2_s_p6_0 = {
  114668. _vq_quantthresh__44c2_s_p6_0,
  114669. _vq_quantmap__44c2_s_p6_0,
  114670. 17,
  114671. 17
  114672. };
  114673. static static_codebook _44c2_s_p6_0 = {
  114674. 2, 289,
  114675. _vq_lengthlist__44c2_s_p6_0,
  114676. 1, -529530880, 1611661312, 5, 0,
  114677. _vq_quantlist__44c2_s_p6_0,
  114678. NULL,
  114679. &_vq_auxt__44c2_s_p6_0,
  114680. NULL,
  114681. 0
  114682. };
  114683. static long _vq_quantlist__44c2_s_p7_0[] = {
  114684. 1,
  114685. 0,
  114686. 2,
  114687. };
  114688. static long _vq_lengthlist__44c2_s_p7_0[] = {
  114689. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  114690. 9, 9, 4, 7, 7,10, 9, 9,10, 9, 9, 7,10,10,11,10,
  114691. 11,11,10,11, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  114692. 11,10,11,11,10,10, 7,11,10,11,11,11,12,11,11, 6,
  114693. 9, 9,11,10,10,11,11,10, 6, 9, 9,11,10,10,12,10,
  114694. 11,
  114695. };
  114696. static float _vq_quantthresh__44c2_s_p7_0[] = {
  114697. -5.5, 5.5,
  114698. };
  114699. static long _vq_quantmap__44c2_s_p7_0[] = {
  114700. 1, 0, 2,
  114701. };
  114702. static encode_aux_threshmatch _vq_auxt__44c2_s_p7_0 = {
  114703. _vq_quantthresh__44c2_s_p7_0,
  114704. _vq_quantmap__44c2_s_p7_0,
  114705. 3,
  114706. 3
  114707. };
  114708. static static_codebook _44c2_s_p7_0 = {
  114709. 4, 81,
  114710. _vq_lengthlist__44c2_s_p7_0,
  114711. 1, -529137664, 1618345984, 2, 0,
  114712. _vq_quantlist__44c2_s_p7_0,
  114713. NULL,
  114714. &_vq_auxt__44c2_s_p7_0,
  114715. NULL,
  114716. 0
  114717. };
  114718. static long _vq_quantlist__44c2_s_p7_1[] = {
  114719. 5,
  114720. 4,
  114721. 6,
  114722. 3,
  114723. 7,
  114724. 2,
  114725. 8,
  114726. 1,
  114727. 9,
  114728. 0,
  114729. 10,
  114730. };
  114731. static long _vq_lengthlist__44c2_s_p7_1[] = {
  114732. 2, 3, 4, 6, 6, 7, 7, 7, 7, 7, 7, 9, 7, 7, 6, 6,
  114733. 7, 7, 8, 8, 8, 8, 9, 6, 6, 6, 6, 7, 7, 8, 8, 8,
  114734. 8,10, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  114735. 7, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  114736. 8, 8,10,10,10, 7, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  114737. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  114738. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  114739. 10,10,10, 8, 8, 8, 8, 8, 8,
  114740. };
  114741. static float _vq_quantthresh__44c2_s_p7_1[] = {
  114742. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  114743. 3.5, 4.5,
  114744. };
  114745. static long _vq_quantmap__44c2_s_p7_1[] = {
  114746. 9, 7, 5, 3, 1, 0, 2, 4,
  114747. 6, 8, 10,
  114748. };
  114749. static encode_aux_threshmatch _vq_auxt__44c2_s_p7_1 = {
  114750. _vq_quantthresh__44c2_s_p7_1,
  114751. _vq_quantmap__44c2_s_p7_1,
  114752. 11,
  114753. 11
  114754. };
  114755. static static_codebook _44c2_s_p7_1 = {
  114756. 2, 121,
  114757. _vq_lengthlist__44c2_s_p7_1,
  114758. 1, -531365888, 1611661312, 4, 0,
  114759. _vq_quantlist__44c2_s_p7_1,
  114760. NULL,
  114761. &_vq_auxt__44c2_s_p7_1,
  114762. NULL,
  114763. 0
  114764. };
  114765. static long _vq_quantlist__44c2_s_p8_0[] = {
  114766. 6,
  114767. 5,
  114768. 7,
  114769. 4,
  114770. 8,
  114771. 3,
  114772. 9,
  114773. 2,
  114774. 10,
  114775. 1,
  114776. 11,
  114777. 0,
  114778. 12,
  114779. };
  114780. static long _vq_lengthlist__44c2_s_p8_0[] = {
  114781. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 6, 5, 5,
  114782. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 6, 5, 7, 7, 8,
  114783. 8, 8, 8, 9, 9,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  114784. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  114785. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,11, 0,13,
  114786. 13, 9, 9,10,10,10,10,11,11,12,12, 0, 0, 0,10,10,
  114787. 10,10,11,11,12,12,12,13, 0, 0, 0,10,10,10,10,11,
  114788. 11,12,12,12,12, 0, 0, 0,14,14,10,11,11,11,12,12,
  114789. 13,13, 0, 0, 0,14,14,11,10,11,11,13,12,13,13, 0,
  114790. 0, 0, 0, 0,12,12,11,12,13,12,14,14, 0, 0, 0, 0,
  114791. 0,12,12,12,12,13,12,14,14,
  114792. };
  114793. static float _vq_quantthresh__44c2_s_p8_0[] = {
  114794. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  114795. 12.5, 17.5, 22.5, 27.5,
  114796. };
  114797. static long _vq_quantmap__44c2_s_p8_0[] = {
  114798. 11, 9, 7, 5, 3, 1, 0, 2,
  114799. 4, 6, 8, 10, 12,
  114800. };
  114801. static encode_aux_threshmatch _vq_auxt__44c2_s_p8_0 = {
  114802. _vq_quantthresh__44c2_s_p8_0,
  114803. _vq_quantmap__44c2_s_p8_0,
  114804. 13,
  114805. 13
  114806. };
  114807. static static_codebook _44c2_s_p8_0 = {
  114808. 2, 169,
  114809. _vq_lengthlist__44c2_s_p8_0,
  114810. 1, -526516224, 1616117760, 4, 0,
  114811. _vq_quantlist__44c2_s_p8_0,
  114812. NULL,
  114813. &_vq_auxt__44c2_s_p8_0,
  114814. NULL,
  114815. 0
  114816. };
  114817. static long _vq_quantlist__44c2_s_p8_1[] = {
  114818. 2,
  114819. 1,
  114820. 3,
  114821. 0,
  114822. 4,
  114823. };
  114824. static long _vq_lengthlist__44c2_s_p8_1[] = {
  114825. 2, 4, 4, 5, 4, 6, 5, 5, 5, 5, 6, 5, 5, 5, 5, 6,
  114826. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  114827. };
  114828. static float _vq_quantthresh__44c2_s_p8_1[] = {
  114829. -1.5, -0.5, 0.5, 1.5,
  114830. };
  114831. static long _vq_quantmap__44c2_s_p8_1[] = {
  114832. 3, 1, 0, 2, 4,
  114833. };
  114834. static encode_aux_threshmatch _vq_auxt__44c2_s_p8_1 = {
  114835. _vq_quantthresh__44c2_s_p8_1,
  114836. _vq_quantmap__44c2_s_p8_1,
  114837. 5,
  114838. 5
  114839. };
  114840. static static_codebook _44c2_s_p8_1 = {
  114841. 2, 25,
  114842. _vq_lengthlist__44c2_s_p8_1,
  114843. 1, -533725184, 1611661312, 3, 0,
  114844. _vq_quantlist__44c2_s_p8_1,
  114845. NULL,
  114846. &_vq_auxt__44c2_s_p8_1,
  114847. NULL,
  114848. 0
  114849. };
  114850. static long _vq_quantlist__44c2_s_p9_0[] = {
  114851. 6,
  114852. 5,
  114853. 7,
  114854. 4,
  114855. 8,
  114856. 3,
  114857. 9,
  114858. 2,
  114859. 10,
  114860. 1,
  114861. 11,
  114862. 0,
  114863. 12,
  114864. };
  114865. static long _vq_lengthlist__44c2_s_p9_0[] = {
  114866. 1, 5, 4,12,12,12,12,12,12,12,12,12,12, 4, 9, 8,
  114867. 11,11,11,11,11,11,11,11,11,11, 2, 8, 7,11,11,11,
  114868. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114869. 11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,
  114870. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114871. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114872. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114873. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114874. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114875. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114876. 11,11,11,11,11,11,11,11,11,
  114877. };
  114878. static float _vq_quantthresh__44c2_s_p9_0[] = {
  114879. -1215.5, -994.5, -773.5, -552.5, -331.5, -110.5, 110.5, 331.5,
  114880. 552.5, 773.5, 994.5, 1215.5,
  114881. };
  114882. static long _vq_quantmap__44c2_s_p9_0[] = {
  114883. 11, 9, 7, 5, 3, 1, 0, 2,
  114884. 4, 6, 8, 10, 12,
  114885. };
  114886. static encode_aux_threshmatch _vq_auxt__44c2_s_p9_0 = {
  114887. _vq_quantthresh__44c2_s_p9_0,
  114888. _vq_quantmap__44c2_s_p9_0,
  114889. 13,
  114890. 13
  114891. };
  114892. static static_codebook _44c2_s_p9_0 = {
  114893. 2, 169,
  114894. _vq_lengthlist__44c2_s_p9_0,
  114895. 1, -514541568, 1627103232, 4, 0,
  114896. _vq_quantlist__44c2_s_p9_0,
  114897. NULL,
  114898. &_vq_auxt__44c2_s_p9_0,
  114899. NULL,
  114900. 0
  114901. };
  114902. static long _vq_quantlist__44c2_s_p9_1[] = {
  114903. 6,
  114904. 5,
  114905. 7,
  114906. 4,
  114907. 8,
  114908. 3,
  114909. 9,
  114910. 2,
  114911. 10,
  114912. 1,
  114913. 11,
  114914. 0,
  114915. 12,
  114916. };
  114917. static long _vq_lengthlist__44c2_s_p9_1[] = {
  114918. 1, 4, 4, 6, 6, 7, 6, 8, 8,10, 9,10,10, 6, 5, 5,
  114919. 7, 7, 8, 7,10, 9,11,11,12,13, 6, 5, 5, 7, 7, 8,
  114920. 8,10,10,11,11,13,13,18, 8, 8, 8, 8, 9, 9,10,10,
  114921. 12,12,12,13,18, 8, 8, 8, 8, 9, 9,10,10,12,12,13,
  114922. 13,18,11,11, 8, 8,10,10,11,11,12,11,13,12,18,11,
  114923. 11, 9, 7,10,10,11,11,11,12,12,13,17,17,17,10,10,
  114924. 11,11,12,12,12,10,12,12,17,17,17,11,10,11,10,13,
  114925. 12,11,12,12,12,17,17,17,15,14,11,11,12,11,13,10,
  114926. 13,12,17,17,17,14,14,12,10,11,11,13,13,13,13,17,
  114927. 17,16,17,16,13,13,12,10,13,10,14,13,17,16,17,16,
  114928. 17,13,12,12,10,13,11,14,14,
  114929. };
  114930. static float _vq_quantthresh__44c2_s_p9_1[] = {
  114931. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  114932. 42.5, 59.5, 76.5, 93.5,
  114933. };
  114934. static long _vq_quantmap__44c2_s_p9_1[] = {
  114935. 11, 9, 7, 5, 3, 1, 0, 2,
  114936. 4, 6, 8, 10, 12,
  114937. };
  114938. static encode_aux_threshmatch _vq_auxt__44c2_s_p9_1 = {
  114939. _vq_quantthresh__44c2_s_p9_1,
  114940. _vq_quantmap__44c2_s_p9_1,
  114941. 13,
  114942. 13
  114943. };
  114944. static static_codebook _44c2_s_p9_1 = {
  114945. 2, 169,
  114946. _vq_lengthlist__44c2_s_p9_1,
  114947. 1, -522616832, 1620115456, 4, 0,
  114948. _vq_quantlist__44c2_s_p9_1,
  114949. NULL,
  114950. &_vq_auxt__44c2_s_p9_1,
  114951. NULL,
  114952. 0
  114953. };
  114954. static long _vq_quantlist__44c2_s_p9_2[] = {
  114955. 8,
  114956. 7,
  114957. 9,
  114958. 6,
  114959. 10,
  114960. 5,
  114961. 11,
  114962. 4,
  114963. 12,
  114964. 3,
  114965. 13,
  114966. 2,
  114967. 14,
  114968. 1,
  114969. 15,
  114970. 0,
  114971. 16,
  114972. };
  114973. static long _vq_lengthlist__44c2_s_p9_2[] = {
  114974. 2, 4, 4, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8,
  114975. 8,10, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
  114976. 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9,
  114977. 9, 9, 9,10, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9,
  114978. 9, 9, 9, 9,10,10,10, 8, 7, 8, 8, 8, 8, 9, 9, 9,
  114979. 9, 9, 9, 9, 9,10,11,11, 8, 8, 8, 8, 9, 9, 9, 9,
  114980. 9, 9,10, 9, 9, 9,10,11,10, 8, 8, 8, 8, 9, 9, 9,
  114981. 9, 9, 9, 9,10,10,10,10,11,10, 8, 8, 9, 9, 9, 9,
  114982. 9, 9,10, 9, 9,10, 9,10,11,10,11,11,11, 8, 8, 9,
  114983. 9, 9, 9, 9, 9, 9, 9,10,10,11,11,11,11,11, 9, 9,
  114984. 9, 9, 9, 9,10, 9, 9, 9,10,10,11,11,11,11,11, 9,
  114985. 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,11,11,11,11,11,
  114986. 9, 9, 9, 9,10,10, 9, 9, 9,10,10,10,11,11,11,11,
  114987. 11,11,11, 9, 9, 9,10, 9, 9,10,10,10,10,11,11,10,
  114988. 11,11,11,11,10, 9,10,10, 9, 9, 9, 9,10,10,11,10,
  114989. 11,11,11,11,11, 9, 9, 9, 9,10, 9,10,10,10,10,11,
  114990. 10,11,11,11,11,11,10,10, 9, 9,10, 9,10,10,10,10,
  114991. 10,10,10,11,11,11,11,11,11, 9, 9,10, 9,10, 9,10,
  114992. 10,
  114993. };
  114994. static float _vq_quantthresh__44c2_s_p9_2[] = {
  114995. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  114996. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  114997. };
  114998. static long _vq_quantmap__44c2_s_p9_2[] = {
  114999. 15, 13, 11, 9, 7, 5, 3, 1,
  115000. 0, 2, 4, 6, 8, 10, 12, 14,
  115001. 16,
  115002. };
  115003. static encode_aux_threshmatch _vq_auxt__44c2_s_p9_2 = {
  115004. _vq_quantthresh__44c2_s_p9_2,
  115005. _vq_quantmap__44c2_s_p9_2,
  115006. 17,
  115007. 17
  115008. };
  115009. static static_codebook _44c2_s_p9_2 = {
  115010. 2, 289,
  115011. _vq_lengthlist__44c2_s_p9_2,
  115012. 1, -529530880, 1611661312, 5, 0,
  115013. _vq_quantlist__44c2_s_p9_2,
  115014. NULL,
  115015. &_vq_auxt__44c2_s_p9_2,
  115016. NULL,
  115017. 0
  115018. };
  115019. static long _huff_lengthlist__44c2_s_short[] = {
  115020. 11, 9,13,12,12,11,12,12,13,15, 8, 2,11, 4, 8, 5,
  115021. 7,10,12,15,13, 7,10, 9, 8, 8,10,13,17,17,11, 4,
  115022. 12, 5, 9, 5, 8,11,14,16,12, 6, 8, 7, 6, 6, 8,11,
  115023. 13,16,11, 4, 9, 5, 6, 4, 6,10,13,16,11, 6,11, 7,
  115024. 7, 6, 7,10,13,15,13, 9,12, 9, 8, 6, 8,10,12,14,
  115025. 14,10,10, 8, 6, 5, 6, 9,11,13,15,11,11, 9, 6, 5,
  115026. 6, 8, 9,12,
  115027. };
  115028. static static_codebook _huff_book__44c2_s_short = {
  115029. 2, 100,
  115030. _huff_lengthlist__44c2_s_short,
  115031. 0, 0, 0, 0, 0,
  115032. NULL,
  115033. NULL,
  115034. NULL,
  115035. NULL,
  115036. 0
  115037. };
  115038. static long _huff_lengthlist__44c3_s_long[] = {
  115039. 5, 6,11,11,11,11,10,10,12,11, 5, 2,11, 5, 6, 6,
  115040. 7, 9,11,13,13,10, 7,11, 6, 7, 8, 9,10,12,11, 5,
  115041. 11, 6, 8, 7, 9,11,14,15,11, 6, 6, 8, 4, 5, 7, 8,
  115042. 10,13,10, 5, 7, 7, 5, 5, 6, 8,10,11,10, 7, 7, 8,
  115043. 6, 5, 5, 7, 9, 9,11, 8, 8,11, 8, 7, 6, 6, 7, 9,
  115044. 12,11,10,13, 9, 9, 7, 7, 7, 9,11,13,12,15,12,11,
  115045. 9, 8, 8, 8,
  115046. };
  115047. static static_codebook _huff_book__44c3_s_long = {
  115048. 2, 100,
  115049. _huff_lengthlist__44c3_s_long,
  115050. 0, 0, 0, 0, 0,
  115051. NULL,
  115052. NULL,
  115053. NULL,
  115054. NULL,
  115055. 0
  115056. };
  115057. static long _vq_quantlist__44c3_s_p1_0[] = {
  115058. 1,
  115059. 0,
  115060. 2,
  115061. };
  115062. static long _vq_lengthlist__44c3_s_p1_0[] = {
  115063. 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 0,
  115064. 0, 0, 5, 6, 6, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  115069. 0, 0, 0, 6, 7, 8, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 6, 8, 7, 0, 0,
  115074. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115080. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115091. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115093. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115094. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115098. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115099. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115100. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115101. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115102. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  115109. 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, 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, 7, 8, 8, 0, 0, 0,
  115114. 0, 0, 0, 8, 8, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 6, 8, 8, 0, 0,
  115119. 0, 0, 0, 0, 7, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  115120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115125. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115134. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115135. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115136. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115137. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115138. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115139. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115140. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115141. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115142. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115143. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115144. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115145. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115146. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115147. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115148. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115150. 0, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  115155. 0, 0, 0, 0, 7, 8, 8, 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, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  115160. 0, 0, 0, 0, 0, 7, 8, 9, 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, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  115165. 0, 0, 0, 0, 0, 0, 8, 9, 8, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115473. 0,
  115474. };
  115475. static float _vq_quantthresh__44c3_s_p1_0[] = {
  115476. -0.5, 0.5,
  115477. };
  115478. static long _vq_quantmap__44c3_s_p1_0[] = {
  115479. 1, 0, 2,
  115480. };
  115481. static encode_aux_threshmatch _vq_auxt__44c3_s_p1_0 = {
  115482. _vq_quantthresh__44c3_s_p1_0,
  115483. _vq_quantmap__44c3_s_p1_0,
  115484. 3,
  115485. 3
  115486. };
  115487. static static_codebook _44c3_s_p1_0 = {
  115488. 8, 6561,
  115489. _vq_lengthlist__44c3_s_p1_0,
  115490. 1, -535822336, 1611661312, 2, 0,
  115491. _vq_quantlist__44c3_s_p1_0,
  115492. NULL,
  115493. &_vq_auxt__44c3_s_p1_0,
  115494. NULL,
  115495. 0
  115496. };
  115497. static long _vq_quantlist__44c3_s_p2_0[] = {
  115498. 2,
  115499. 1,
  115500. 3,
  115501. 0,
  115502. 4,
  115503. };
  115504. static long _vq_lengthlist__44c3_s_p2_0[] = {
  115505. 2, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0,
  115506. 7, 8, 0, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 7,
  115507. 7, 0, 0, 0, 7, 7, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  115508. 0, 0, 5, 6, 6, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0,
  115509. 0, 0,10,10, 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, 5, 7, 7, 0, 0, 0, 7, 7, 0, 0,
  115515. 0, 7, 7, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5,
  115516. 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9,
  115517. 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115522. 0, 0, 0, 5, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7,
  115523. 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0,
  115524. 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9, 9, 0, 0,
  115525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115530. 8,10,10, 0, 0, 0, 9, 9, 0, 0, 0, 9, 9, 0, 0, 0,
  115531. 10,10, 0, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0, 0, 9,
  115532. 9, 0, 0, 0, 9, 9, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  115533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115544. 0,
  115545. };
  115546. static float _vq_quantthresh__44c3_s_p2_0[] = {
  115547. -1.5, -0.5, 0.5, 1.5,
  115548. };
  115549. static long _vq_quantmap__44c3_s_p2_0[] = {
  115550. 3, 1, 0, 2, 4,
  115551. };
  115552. static encode_aux_threshmatch _vq_auxt__44c3_s_p2_0 = {
  115553. _vq_quantthresh__44c3_s_p2_0,
  115554. _vq_quantmap__44c3_s_p2_0,
  115555. 5,
  115556. 5
  115557. };
  115558. static static_codebook _44c3_s_p2_0 = {
  115559. 4, 625,
  115560. _vq_lengthlist__44c3_s_p2_0,
  115561. 1, -533725184, 1611661312, 3, 0,
  115562. _vq_quantlist__44c3_s_p2_0,
  115563. NULL,
  115564. &_vq_auxt__44c3_s_p2_0,
  115565. NULL,
  115566. 0
  115567. };
  115568. static long _vq_quantlist__44c3_s_p3_0[] = {
  115569. 2,
  115570. 1,
  115571. 3,
  115572. 0,
  115573. 4,
  115574. };
  115575. static long _vq_lengthlist__44c3_s_p3_0[] = {
  115576. 2, 4, 3, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  115578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115579. 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  115581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115582. 0, 0, 0, 0, 6, 6, 7, 9, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115615. 0,
  115616. };
  115617. static float _vq_quantthresh__44c3_s_p3_0[] = {
  115618. -1.5, -0.5, 0.5, 1.5,
  115619. };
  115620. static long _vq_quantmap__44c3_s_p3_0[] = {
  115621. 3, 1, 0, 2, 4,
  115622. };
  115623. static encode_aux_threshmatch _vq_auxt__44c3_s_p3_0 = {
  115624. _vq_quantthresh__44c3_s_p3_0,
  115625. _vq_quantmap__44c3_s_p3_0,
  115626. 5,
  115627. 5
  115628. };
  115629. static static_codebook _44c3_s_p3_0 = {
  115630. 4, 625,
  115631. _vq_lengthlist__44c3_s_p3_0,
  115632. 1, -533725184, 1611661312, 3, 0,
  115633. _vq_quantlist__44c3_s_p3_0,
  115634. NULL,
  115635. &_vq_auxt__44c3_s_p3_0,
  115636. NULL,
  115637. 0
  115638. };
  115639. static long _vq_quantlist__44c3_s_p4_0[] = {
  115640. 4,
  115641. 3,
  115642. 5,
  115643. 2,
  115644. 6,
  115645. 1,
  115646. 7,
  115647. 0,
  115648. 8,
  115649. };
  115650. static long _vq_lengthlist__44c3_s_p4_0[] = {
  115651. 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 4, 4, 6, 6, 0, 0,
  115652. 0, 0, 0, 4, 4, 6, 6, 0, 0, 0, 0, 0, 5, 5, 6, 6,
  115653. 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0,
  115654. 7, 8, 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0,
  115655. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115656. 0,
  115657. };
  115658. static float _vq_quantthresh__44c3_s_p4_0[] = {
  115659. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  115660. };
  115661. static long _vq_quantmap__44c3_s_p4_0[] = {
  115662. 7, 5, 3, 1, 0, 2, 4, 6,
  115663. 8,
  115664. };
  115665. static encode_aux_threshmatch _vq_auxt__44c3_s_p4_0 = {
  115666. _vq_quantthresh__44c3_s_p4_0,
  115667. _vq_quantmap__44c3_s_p4_0,
  115668. 9,
  115669. 9
  115670. };
  115671. static static_codebook _44c3_s_p4_0 = {
  115672. 2, 81,
  115673. _vq_lengthlist__44c3_s_p4_0,
  115674. 1, -531628032, 1611661312, 4, 0,
  115675. _vq_quantlist__44c3_s_p4_0,
  115676. NULL,
  115677. &_vq_auxt__44c3_s_p4_0,
  115678. NULL,
  115679. 0
  115680. };
  115681. static long _vq_quantlist__44c3_s_p5_0[] = {
  115682. 4,
  115683. 3,
  115684. 5,
  115685. 2,
  115686. 6,
  115687. 1,
  115688. 7,
  115689. 0,
  115690. 8,
  115691. };
  115692. static long _vq_lengthlist__44c3_s_p5_0[] = {
  115693. 1, 3, 4, 6, 6, 7, 7, 9, 9, 0, 5, 5, 7, 7, 7, 8,
  115694. 9, 9, 0, 5, 5, 7, 7, 8, 8, 9, 9, 0, 7, 7, 8, 8,
  115695. 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  115696. 9, 9, 9, 9,10,10, 0, 0, 0, 9, 9, 9, 9,10,10, 0,
  115697. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0,10,10,11,
  115698. 11,
  115699. };
  115700. static float _vq_quantthresh__44c3_s_p5_0[] = {
  115701. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  115702. };
  115703. static long _vq_quantmap__44c3_s_p5_0[] = {
  115704. 7, 5, 3, 1, 0, 2, 4, 6,
  115705. 8,
  115706. };
  115707. static encode_aux_threshmatch _vq_auxt__44c3_s_p5_0 = {
  115708. _vq_quantthresh__44c3_s_p5_0,
  115709. _vq_quantmap__44c3_s_p5_0,
  115710. 9,
  115711. 9
  115712. };
  115713. static static_codebook _44c3_s_p5_0 = {
  115714. 2, 81,
  115715. _vq_lengthlist__44c3_s_p5_0,
  115716. 1, -531628032, 1611661312, 4, 0,
  115717. _vq_quantlist__44c3_s_p5_0,
  115718. NULL,
  115719. &_vq_auxt__44c3_s_p5_0,
  115720. NULL,
  115721. 0
  115722. };
  115723. static long _vq_quantlist__44c3_s_p6_0[] = {
  115724. 8,
  115725. 7,
  115726. 9,
  115727. 6,
  115728. 10,
  115729. 5,
  115730. 11,
  115731. 4,
  115732. 12,
  115733. 3,
  115734. 13,
  115735. 2,
  115736. 14,
  115737. 1,
  115738. 15,
  115739. 0,
  115740. 16,
  115741. };
  115742. static long _vq_lengthlist__44c3_s_p6_0[] = {
  115743. 2, 3, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  115744. 10, 0, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,10,
  115745. 11,11, 0, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  115746. 10,11,11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  115747. 11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  115748. 10,11,11,11,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  115749. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9,
  115750. 9,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  115751. 10,10,11,10,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  115752. 10,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 8,
  115753. 9, 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 8,
  115754. 8, 9, 9,10,10,11,11,12,11,12,12, 0, 0, 0, 0, 0,
  115755. 9,10,10,10,11,11,11,11,12,12,13,13, 0, 0, 0, 0,
  115756. 0, 0, 0,10,10,10,10,11,11,12,12,13,13, 0, 0, 0,
  115757. 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0, 0,
  115758. 0, 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0,
  115759. 0, 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,13,
  115760. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,
  115761. 13,
  115762. };
  115763. static float _vq_quantthresh__44c3_s_p6_0[] = {
  115764. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  115765. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  115766. };
  115767. static long _vq_quantmap__44c3_s_p6_0[] = {
  115768. 15, 13, 11, 9, 7, 5, 3, 1,
  115769. 0, 2, 4, 6, 8, 10, 12, 14,
  115770. 16,
  115771. };
  115772. static encode_aux_threshmatch _vq_auxt__44c3_s_p6_0 = {
  115773. _vq_quantthresh__44c3_s_p6_0,
  115774. _vq_quantmap__44c3_s_p6_0,
  115775. 17,
  115776. 17
  115777. };
  115778. static static_codebook _44c3_s_p6_0 = {
  115779. 2, 289,
  115780. _vq_lengthlist__44c3_s_p6_0,
  115781. 1, -529530880, 1611661312, 5, 0,
  115782. _vq_quantlist__44c3_s_p6_0,
  115783. NULL,
  115784. &_vq_auxt__44c3_s_p6_0,
  115785. NULL,
  115786. 0
  115787. };
  115788. static long _vq_quantlist__44c3_s_p7_0[] = {
  115789. 1,
  115790. 0,
  115791. 2,
  115792. };
  115793. static long _vq_lengthlist__44c3_s_p7_0[] = {
  115794. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  115795. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,11,11,
  115796. 10,12,11,11, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  115797. 11,10,10,11,10,10, 7,11,11,11,11,11,12,11,11, 6,
  115798. 9, 9,11,10,10,11,10,10, 6, 9, 9,11,10,10,11,10,
  115799. 10,
  115800. };
  115801. static float _vq_quantthresh__44c3_s_p7_0[] = {
  115802. -5.5, 5.5,
  115803. };
  115804. static long _vq_quantmap__44c3_s_p7_0[] = {
  115805. 1, 0, 2,
  115806. };
  115807. static encode_aux_threshmatch _vq_auxt__44c3_s_p7_0 = {
  115808. _vq_quantthresh__44c3_s_p7_0,
  115809. _vq_quantmap__44c3_s_p7_0,
  115810. 3,
  115811. 3
  115812. };
  115813. static static_codebook _44c3_s_p7_0 = {
  115814. 4, 81,
  115815. _vq_lengthlist__44c3_s_p7_0,
  115816. 1, -529137664, 1618345984, 2, 0,
  115817. _vq_quantlist__44c3_s_p7_0,
  115818. NULL,
  115819. &_vq_auxt__44c3_s_p7_0,
  115820. NULL,
  115821. 0
  115822. };
  115823. static long _vq_quantlist__44c3_s_p7_1[] = {
  115824. 5,
  115825. 4,
  115826. 6,
  115827. 3,
  115828. 7,
  115829. 2,
  115830. 8,
  115831. 1,
  115832. 9,
  115833. 0,
  115834. 10,
  115835. };
  115836. static long _vq_lengthlist__44c3_s_p7_1[] = {
  115837. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8,10, 5, 5, 6, 6,
  115838. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  115839. 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  115840. 7, 8, 7, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 8, 8,
  115841. 8, 8,10,10,10, 7, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  115842. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  115843. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 9, 8,10,10,
  115844. 10,10,10, 8, 8, 8, 8, 8, 8,
  115845. };
  115846. static float _vq_quantthresh__44c3_s_p7_1[] = {
  115847. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  115848. 3.5, 4.5,
  115849. };
  115850. static long _vq_quantmap__44c3_s_p7_1[] = {
  115851. 9, 7, 5, 3, 1, 0, 2, 4,
  115852. 6, 8, 10,
  115853. };
  115854. static encode_aux_threshmatch _vq_auxt__44c3_s_p7_1 = {
  115855. _vq_quantthresh__44c3_s_p7_1,
  115856. _vq_quantmap__44c3_s_p7_1,
  115857. 11,
  115858. 11
  115859. };
  115860. static static_codebook _44c3_s_p7_1 = {
  115861. 2, 121,
  115862. _vq_lengthlist__44c3_s_p7_1,
  115863. 1, -531365888, 1611661312, 4, 0,
  115864. _vq_quantlist__44c3_s_p7_1,
  115865. NULL,
  115866. &_vq_auxt__44c3_s_p7_1,
  115867. NULL,
  115868. 0
  115869. };
  115870. static long _vq_quantlist__44c3_s_p8_0[] = {
  115871. 6,
  115872. 5,
  115873. 7,
  115874. 4,
  115875. 8,
  115876. 3,
  115877. 9,
  115878. 2,
  115879. 10,
  115880. 1,
  115881. 11,
  115882. 0,
  115883. 12,
  115884. };
  115885. static long _vq_lengthlist__44c3_s_p8_0[] = {
  115886. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  115887. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 5, 7, 7, 8,
  115888. 8, 8, 8, 9, 9,11,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  115889. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  115890. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,12, 0,13,
  115891. 13, 9, 9,10,10,10,10,11,11,12,12, 0, 0, 0,10,10,
  115892. 10,10,11,11,12,12,12,12, 0, 0, 0,10,10,10,10,11,
  115893. 11,12,12,12,12, 0, 0, 0,14,14,11,11,11,11,12,12,
  115894. 13,13, 0, 0, 0,14,14,11,11,11,11,12,12,13,13, 0,
  115895. 0, 0, 0, 0,12,12,12,12,13,13,14,13, 0, 0, 0, 0,
  115896. 0,13,13,12,12,13,12,14,13,
  115897. };
  115898. static float _vq_quantthresh__44c3_s_p8_0[] = {
  115899. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  115900. 12.5, 17.5, 22.5, 27.5,
  115901. };
  115902. static long _vq_quantmap__44c3_s_p8_0[] = {
  115903. 11, 9, 7, 5, 3, 1, 0, 2,
  115904. 4, 6, 8, 10, 12,
  115905. };
  115906. static encode_aux_threshmatch _vq_auxt__44c3_s_p8_0 = {
  115907. _vq_quantthresh__44c3_s_p8_0,
  115908. _vq_quantmap__44c3_s_p8_0,
  115909. 13,
  115910. 13
  115911. };
  115912. static static_codebook _44c3_s_p8_0 = {
  115913. 2, 169,
  115914. _vq_lengthlist__44c3_s_p8_0,
  115915. 1, -526516224, 1616117760, 4, 0,
  115916. _vq_quantlist__44c3_s_p8_0,
  115917. NULL,
  115918. &_vq_auxt__44c3_s_p8_0,
  115919. NULL,
  115920. 0
  115921. };
  115922. static long _vq_quantlist__44c3_s_p8_1[] = {
  115923. 2,
  115924. 1,
  115925. 3,
  115926. 0,
  115927. 4,
  115928. };
  115929. static long _vq_lengthlist__44c3_s_p8_1[] = {
  115930. 2, 4, 4, 5, 5, 6, 5, 5, 5, 5, 6, 4, 5, 5, 5, 6,
  115931. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  115932. };
  115933. static float _vq_quantthresh__44c3_s_p8_1[] = {
  115934. -1.5, -0.5, 0.5, 1.5,
  115935. };
  115936. static long _vq_quantmap__44c3_s_p8_1[] = {
  115937. 3, 1, 0, 2, 4,
  115938. };
  115939. static encode_aux_threshmatch _vq_auxt__44c3_s_p8_1 = {
  115940. _vq_quantthresh__44c3_s_p8_1,
  115941. _vq_quantmap__44c3_s_p8_1,
  115942. 5,
  115943. 5
  115944. };
  115945. static static_codebook _44c3_s_p8_1 = {
  115946. 2, 25,
  115947. _vq_lengthlist__44c3_s_p8_1,
  115948. 1, -533725184, 1611661312, 3, 0,
  115949. _vq_quantlist__44c3_s_p8_1,
  115950. NULL,
  115951. &_vq_auxt__44c3_s_p8_1,
  115952. NULL,
  115953. 0
  115954. };
  115955. static long _vq_quantlist__44c3_s_p9_0[] = {
  115956. 6,
  115957. 5,
  115958. 7,
  115959. 4,
  115960. 8,
  115961. 3,
  115962. 9,
  115963. 2,
  115964. 10,
  115965. 1,
  115966. 11,
  115967. 0,
  115968. 12,
  115969. };
  115970. static long _vq_lengthlist__44c3_s_p9_0[] = {
  115971. 1, 4, 4,12,12,12,12,12,12,12,12,12,12, 4, 9, 8,
  115972. 12,12,12,12,12,12,12,12,12,12, 2, 9, 7,12,12,12,
  115973. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115974. 12,12,12,12,12,12,11,12,12,12,12,12,12,12,12,12,
  115975. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115976. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115977. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115978. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115979. 12,12,12,12,12,12,12,12,12,12,11,11,11,11,11,11,
  115980. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  115981. 11,11,11,11,11,11,11,11,11,
  115982. };
  115983. static float _vq_quantthresh__44c3_s_p9_0[] = {
  115984. -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5, 382.5,
  115985. 637.5, 892.5, 1147.5, 1402.5,
  115986. };
  115987. static long _vq_quantmap__44c3_s_p9_0[] = {
  115988. 11, 9, 7, 5, 3, 1, 0, 2,
  115989. 4, 6, 8, 10, 12,
  115990. };
  115991. static encode_aux_threshmatch _vq_auxt__44c3_s_p9_0 = {
  115992. _vq_quantthresh__44c3_s_p9_0,
  115993. _vq_quantmap__44c3_s_p9_0,
  115994. 13,
  115995. 13
  115996. };
  115997. static static_codebook _44c3_s_p9_0 = {
  115998. 2, 169,
  115999. _vq_lengthlist__44c3_s_p9_0,
  116000. 1, -514332672, 1627381760, 4, 0,
  116001. _vq_quantlist__44c3_s_p9_0,
  116002. NULL,
  116003. &_vq_auxt__44c3_s_p9_0,
  116004. NULL,
  116005. 0
  116006. };
  116007. static long _vq_quantlist__44c3_s_p9_1[] = {
  116008. 7,
  116009. 6,
  116010. 8,
  116011. 5,
  116012. 9,
  116013. 4,
  116014. 10,
  116015. 3,
  116016. 11,
  116017. 2,
  116018. 12,
  116019. 1,
  116020. 13,
  116021. 0,
  116022. 14,
  116023. };
  116024. static long _vq_lengthlist__44c3_s_p9_1[] = {
  116025. 1, 4, 4, 6, 6, 7, 7, 8, 7, 9, 9,10,10,10,10, 6,
  116026. 5, 5, 7, 7, 8, 8,10, 8,11,10,12,12,13,13, 6, 5,
  116027. 5, 7, 7, 8, 8,10, 9,11,11,12,12,13,12,18, 8, 8,
  116028. 8, 8, 9, 9,10, 9,11,10,12,12,13,13,18, 8, 8, 8,
  116029. 8, 9, 9,10,10,11,11,13,12,14,13,18,11,11, 9, 9,
  116030. 10,10,11,11,11,12,13,12,13,14,18,11,11, 9, 8,11,
  116031. 10,11,11,11,11,12,12,14,13,18,18,18,10,11,10,11,
  116032. 12,12,12,12,13,12,14,13,18,18,18,10,11,11, 9,12,
  116033. 11,12,12,12,13,13,13,18,18,17,14,14,11,11,12,12,
  116034. 13,12,14,12,14,13,18,18,18,14,14,11,10,12, 9,12,
  116035. 13,13,13,13,13,18,18,17,16,18,13,13,12,12,13,11,
  116036. 14,12,14,14,17,18,18,17,18,13,12,13,10,12,11,14,
  116037. 14,14,14,17,18,18,18,18,15,16,12,12,13,10,14,12,
  116038. 14,15,18,18,18,16,17,16,14,12,11,13,10,13,13,14,
  116039. 15,
  116040. };
  116041. static float _vq_quantthresh__44c3_s_p9_1[] = {
  116042. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  116043. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  116044. };
  116045. static long _vq_quantmap__44c3_s_p9_1[] = {
  116046. 13, 11, 9, 7, 5, 3, 1, 0,
  116047. 2, 4, 6, 8, 10, 12, 14,
  116048. };
  116049. static encode_aux_threshmatch _vq_auxt__44c3_s_p9_1 = {
  116050. _vq_quantthresh__44c3_s_p9_1,
  116051. _vq_quantmap__44c3_s_p9_1,
  116052. 15,
  116053. 15
  116054. };
  116055. static static_codebook _44c3_s_p9_1 = {
  116056. 2, 225,
  116057. _vq_lengthlist__44c3_s_p9_1,
  116058. 1, -522338304, 1620115456, 4, 0,
  116059. _vq_quantlist__44c3_s_p9_1,
  116060. NULL,
  116061. &_vq_auxt__44c3_s_p9_1,
  116062. NULL,
  116063. 0
  116064. };
  116065. static long _vq_quantlist__44c3_s_p9_2[] = {
  116066. 8,
  116067. 7,
  116068. 9,
  116069. 6,
  116070. 10,
  116071. 5,
  116072. 11,
  116073. 4,
  116074. 12,
  116075. 3,
  116076. 13,
  116077. 2,
  116078. 14,
  116079. 1,
  116080. 15,
  116081. 0,
  116082. 16,
  116083. };
  116084. static long _vq_lengthlist__44c3_s_p9_2[] = {
  116085. 2, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8,
  116086. 8,10, 6, 6, 7, 7, 8, 7, 8, 8, 8, 8, 8, 9, 9, 9,
  116087. 9, 9,10, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9,
  116088. 9, 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
  116089. 9, 9, 9, 9,10,10,10, 7, 7, 8, 8, 8, 9, 9, 9, 9,
  116090. 9, 9, 9, 9, 9,11,11,11, 8, 8, 8, 8, 9, 9, 9, 9,
  116091. 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9,
  116092. 9, 9, 9, 9, 9, 9, 9,10,10,10, 8, 9, 9, 9, 9, 9,
  116093. 9, 9, 9, 9, 9, 9,10, 9,10,10,10,11,11, 9, 9, 9,
  116094. 9, 9, 9, 9, 9, 9, 9, 9, 9,11,10,11,11,11, 9, 9,
  116095. 9, 9, 9, 9,10,10, 9, 9,10, 9,11,10,11,11,11, 9,
  116096. 9, 9, 9, 9, 9, 9, 9,10,10,10, 9,11,11,11,11,11,
  116097. 9, 9, 9, 9,10,10, 9, 9, 9, 9,10, 9,11,11,11,11,
  116098. 11,11,11, 9, 9, 9, 9, 9, 9,10,10,10,10,11,11,11,
  116099. 11,11,11,11,10, 9,10,10, 9,10, 9, 9,10, 9,11,10,
  116100. 10,11,11,11,11, 9,10, 9, 9, 9, 9,10,10,10,10,11,
  116101. 11,11,11,11,11,10,10,10, 9, 9,10, 9,10, 9,10,10,
  116102. 10,10,11,11,11,11,11,11,11, 9, 9, 9, 9, 9,10,10,
  116103. 10,
  116104. };
  116105. static float _vq_quantthresh__44c3_s_p9_2[] = {
  116106. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  116107. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  116108. };
  116109. static long _vq_quantmap__44c3_s_p9_2[] = {
  116110. 15, 13, 11, 9, 7, 5, 3, 1,
  116111. 0, 2, 4, 6, 8, 10, 12, 14,
  116112. 16,
  116113. };
  116114. static encode_aux_threshmatch _vq_auxt__44c3_s_p9_2 = {
  116115. _vq_quantthresh__44c3_s_p9_2,
  116116. _vq_quantmap__44c3_s_p9_2,
  116117. 17,
  116118. 17
  116119. };
  116120. static static_codebook _44c3_s_p9_2 = {
  116121. 2, 289,
  116122. _vq_lengthlist__44c3_s_p9_2,
  116123. 1, -529530880, 1611661312, 5, 0,
  116124. _vq_quantlist__44c3_s_p9_2,
  116125. NULL,
  116126. &_vq_auxt__44c3_s_p9_2,
  116127. NULL,
  116128. 0
  116129. };
  116130. static long _huff_lengthlist__44c3_s_short[] = {
  116131. 10, 9,13,11,14,10,12,13,13,14, 7, 2,12, 5,10, 5,
  116132. 7,10,12,14,12, 6, 9, 8, 7, 7, 9,11,13,16,10, 4,
  116133. 12, 5,10, 6, 8,12,14,16,12, 6, 8, 7, 6, 5, 7,11,
  116134. 12,16,10, 4, 8, 5, 6, 4, 6, 9,13,16,10, 6,10, 7,
  116135. 7, 6, 7, 9,13,15,12, 9,11, 9, 8, 6, 7,10,12,14,
  116136. 14,11,10, 9, 6, 5, 6, 9,11,13,15,13,11,10, 6, 5,
  116137. 6, 8, 9,11,
  116138. };
  116139. static static_codebook _huff_book__44c3_s_short = {
  116140. 2, 100,
  116141. _huff_lengthlist__44c3_s_short,
  116142. 0, 0, 0, 0, 0,
  116143. NULL,
  116144. NULL,
  116145. NULL,
  116146. NULL,
  116147. 0
  116148. };
  116149. static long _huff_lengthlist__44c4_s_long[] = {
  116150. 4, 7,11,11,11,11,10,11,12,11, 5, 2,11, 5, 6, 6,
  116151. 7, 9,11,12,11, 9, 6,10, 6, 7, 8, 9,10,11,11, 5,
  116152. 11, 7, 8, 8, 9,11,13,14,11, 6, 5, 8, 4, 5, 7, 8,
  116153. 10,11,10, 6, 7, 7, 5, 5, 6, 8, 9,11,10, 7, 8, 9,
  116154. 6, 6, 6, 7, 8, 9,11, 9, 9,11, 7, 7, 6, 6, 7, 9,
  116155. 12,12,10,13, 9, 8, 7, 7, 7, 8,11,13,11,14,11,10,
  116156. 9, 8, 7, 7,
  116157. };
  116158. static static_codebook _huff_book__44c4_s_long = {
  116159. 2, 100,
  116160. _huff_lengthlist__44c4_s_long,
  116161. 0, 0, 0, 0, 0,
  116162. NULL,
  116163. NULL,
  116164. NULL,
  116165. NULL,
  116166. 0
  116167. };
  116168. static long _vq_quantlist__44c4_s_p1_0[] = {
  116169. 1,
  116170. 0,
  116171. 2,
  116172. };
  116173. static long _vq_lengthlist__44c4_s_p1_0[] = {
  116174. 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 0,
  116175. 0, 0, 5, 6, 7, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  116180. 0, 0, 0, 6, 8, 8, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 6, 8, 7, 0, 0,
  116185. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116201. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116203. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116207. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  116220. 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, 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, 7, 8, 8, 0, 0, 0,
  116225. 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 6, 8, 8, 0, 0,
  116230. 0, 0, 0, 0, 8, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  116231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116234. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116246. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116247. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116248. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116250. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116251. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116252. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116253. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116254. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116255. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116256. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116258. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116259. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116260. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116261. 0, 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, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  116266. 0, 0, 0, 0, 7, 8, 8, 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, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  116271. 0, 0, 0, 0, 0, 8, 8, 9, 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, 7, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  116276. 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116584. 0,
  116585. };
  116586. static float _vq_quantthresh__44c4_s_p1_0[] = {
  116587. -0.5, 0.5,
  116588. };
  116589. static long _vq_quantmap__44c4_s_p1_0[] = {
  116590. 1, 0, 2,
  116591. };
  116592. static encode_aux_threshmatch _vq_auxt__44c4_s_p1_0 = {
  116593. _vq_quantthresh__44c4_s_p1_0,
  116594. _vq_quantmap__44c4_s_p1_0,
  116595. 3,
  116596. 3
  116597. };
  116598. static static_codebook _44c4_s_p1_0 = {
  116599. 8, 6561,
  116600. _vq_lengthlist__44c4_s_p1_0,
  116601. 1, -535822336, 1611661312, 2, 0,
  116602. _vq_quantlist__44c4_s_p1_0,
  116603. NULL,
  116604. &_vq_auxt__44c4_s_p1_0,
  116605. NULL,
  116606. 0
  116607. };
  116608. static long _vq_quantlist__44c4_s_p2_0[] = {
  116609. 2,
  116610. 1,
  116611. 3,
  116612. 0,
  116613. 4,
  116614. };
  116615. static long _vq_lengthlist__44c4_s_p2_0[] = {
  116616. 2, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0,
  116617. 7, 7, 0, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 7,
  116618. 7, 0, 0, 0, 7, 7, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  116619. 0, 0, 5, 6, 6, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0,
  116620. 0, 0,10,10, 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, 5, 8, 7, 0, 0, 0, 7, 7, 0, 0,
  116626. 0, 7, 7, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5,
  116627. 7, 8, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9,
  116628. 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116633. 0, 0, 0, 5, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7,
  116634. 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0,
  116635. 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9, 9, 0, 0,
  116636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116641. 7,10,10, 0, 0, 0, 9, 9, 0, 0, 0, 9, 9, 0, 0, 0,
  116642. 10,10, 0, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0, 0, 9,
  116643. 9, 0, 0, 0, 9, 9, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  116644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116655. 0,
  116656. };
  116657. static float _vq_quantthresh__44c4_s_p2_0[] = {
  116658. -1.5, -0.5, 0.5, 1.5,
  116659. };
  116660. static long _vq_quantmap__44c4_s_p2_0[] = {
  116661. 3, 1, 0, 2, 4,
  116662. };
  116663. static encode_aux_threshmatch _vq_auxt__44c4_s_p2_0 = {
  116664. _vq_quantthresh__44c4_s_p2_0,
  116665. _vq_quantmap__44c4_s_p2_0,
  116666. 5,
  116667. 5
  116668. };
  116669. static static_codebook _44c4_s_p2_0 = {
  116670. 4, 625,
  116671. _vq_lengthlist__44c4_s_p2_0,
  116672. 1, -533725184, 1611661312, 3, 0,
  116673. _vq_quantlist__44c4_s_p2_0,
  116674. NULL,
  116675. &_vq_auxt__44c4_s_p2_0,
  116676. NULL,
  116677. 0
  116678. };
  116679. static long _vq_quantlist__44c4_s_p3_0[] = {
  116680. 2,
  116681. 1,
  116682. 3,
  116683. 0,
  116684. 4,
  116685. };
  116686. static long _vq_lengthlist__44c4_s_p3_0[] = {
  116687. 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 4, 6, 6, 0, 0,
  116689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116690. 0, 0, 4, 4, 5, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  116692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116693. 0, 0, 0, 0, 6, 6, 7, 9, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116726. 0,
  116727. };
  116728. static float _vq_quantthresh__44c4_s_p3_0[] = {
  116729. -1.5, -0.5, 0.5, 1.5,
  116730. };
  116731. static long _vq_quantmap__44c4_s_p3_0[] = {
  116732. 3, 1, 0, 2, 4,
  116733. };
  116734. static encode_aux_threshmatch _vq_auxt__44c4_s_p3_0 = {
  116735. _vq_quantthresh__44c4_s_p3_0,
  116736. _vq_quantmap__44c4_s_p3_0,
  116737. 5,
  116738. 5
  116739. };
  116740. static static_codebook _44c4_s_p3_0 = {
  116741. 4, 625,
  116742. _vq_lengthlist__44c4_s_p3_0,
  116743. 1, -533725184, 1611661312, 3, 0,
  116744. _vq_quantlist__44c4_s_p3_0,
  116745. NULL,
  116746. &_vq_auxt__44c4_s_p3_0,
  116747. NULL,
  116748. 0
  116749. };
  116750. static long _vq_quantlist__44c4_s_p4_0[] = {
  116751. 4,
  116752. 3,
  116753. 5,
  116754. 2,
  116755. 6,
  116756. 1,
  116757. 7,
  116758. 0,
  116759. 8,
  116760. };
  116761. static long _vq_lengthlist__44c4_s_p4_0[] = {
  116762. 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 4, 4, 6, 6, 0, 0,
  116763. 0, 0, 0, 4, 4, 6, 6, 0, 0, 0, 0, 0, 5, 5, 6, 6,
  116764. 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0,
  116765. 7, 8, 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0,
  116766. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116767. 0,
  116768. };
  116769. static float _vq_quantthresh__44c4_s_p4_0[] = {
  116770. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  116771. };
  116772. static long _vq_quantmap__44c4_s_p4_0[] = {
  116773. 7, 5, 3, 1, 0, 2, 4, 6,
  116774. 8,
  116775. };
  116776. static encode_aux_threshmatch _vq_auxt__44c4_s_p4_0 = {
  116777. _vq_quantthresh__44c4_s_p4_0,
  116778. _vq_quantmap__44c4_s_p4_0,
  116779. 9,
  116780. 9
  116781. };
  116782. static static_codebook _44c4_s_p4_0 = {
  116783. 2, 81,
  116784. _vq_lengthlist__44c4_s_p4_0,
  116785. 1, -531628032, 1611661312, 4, 0,
  116786. _vq_quantlist__44c4_s_p4_0,
  116787. NULL,
  116788. &_vq_auxt__44c4_s_p4_0,
  116789. NULL,
  116790. 0
  116791. };
  116792. static long _vq_quantlist__44c4_s_p5_0[] = {
  116793. 4,
  116794. 3,
  116795. 5,
  116796. 2,
  116797. 6,
  116798. 1,
  116799. 7,
  116800. 0,
  116801. 8,
  116802. };
  116803. static long _vq_lengthlist__44c4_s_p5_0[] = {
  116804. 2, 3, 3, 6, 6, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  116805. 9, 9, 0, 4, 5, 6, 6, 7, 7, 9, 9, 0, 6, 6, 7, 7,
  116806. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10, 9, 0, 0, 0,
  116807. 9, 8, 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0,
  116808. 0, 0,10,10, 9, 9,11,11, 0, 0, 0, 0, 0, 9, 9,10,
  116809. 10,
  116810. };
  116811. static float _vq_quantthresh__44c4_s_p5_0[] = {
  116812. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  116813. };
  116814. static long _vq_quantmap__44c4_s_p5_0[] = {
  116815. 7, 5, 3, 1, 0, 2, 4, 6,
  116816. 8,
  116817. };
  116818. static encode_aux_threshmatch _vq_auxt__44c4_s_p5_0 = {
  116819. _vq_quantthresh__44c4_s_p5_0,
  116820. _vq_quantmap__44c4_s_p5_0,
  116821. 9,
  116822. 9
  116823. };
  116824. static static_codebook _44c4_s_p5_0 = {
  116825. 2, 81,
  116826. _vq_lengthlist__44c4_s_p5_0,
  116827. 1, -531628032, 1611661312, 4, 0,
  116828. _vq_quantlist__44c4_s_p5_0,
  116829. NULL,
  116830. &_vq_auxt__44c4_s_p5_0,
  116831. NULL,
  116832. 0
  116833. };
  116834. static long _vq_quantlist__44c4_s_p6_0[] = {
  116835. 8,
  116836. 7,
  116837. 9,
  116838. 6,
  116839. 10,
  116840. 5,
  116841. 11,
  116842. 4,
  116843. 12,
  116844. 3,
  116845. 13,
  116846. 2,
  116847. 14,
  116848. 1,
  116849. 15,
  116850. 0,
  116851. 16,
  116852. };
  116853. static long _vq_lengthlist__44c4_s_p6_0[] = {
  116854. 2, 4, 4, 6, 6, 8, 8, 9, 9, 8, 8, 9, 9,10,10,11,
  116855. 11, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,11,
  116856. 11,11, 0, 4, 4, 7, 6, 8, 8, 9, 9, 9, 9,10,10,11,
  116857. 11,11,11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  116858. 11,11,11,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  116859. 10,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  116860. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9,
  116861. 9,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  116862. 10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  116863. 10,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,
  116864. 9,10,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9,
  116865. 9, 9, 9,10,10,11,11,11,12,12,12, 0, 0, 0, 0, 0,
  116866. 10,10,10,10,11,11,11,11,12,12,13,12, 0, 0, 0, 0,
  116867. 0, 0, 0,10,10,11,11,11,11,12,12,12,12, 0, 0, 0,
  116868. 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0, 0,
  116869. 0, 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0,
  116870. 0, 0, 0, 0, 0, 0,12,12,12,12,12,12,13,13,13,13,
  116871. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,12,13,13,
  116872. 13,
  116873. };
  116874. static float _vq_quantthresh__44c4_s_p6_0[] = {
  116875. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  116876. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  116877. };
  116878. static long _vq_quantmap__44c4_s_p6_0[] = {
  116879. 15, 13, 11, 9, 7, 5, 3, 1,
  116880. 0, 2, 4, 6, 8, 10, 12, 14,
  116881. 16,
  116882. };
  116883. static encode_aux_threshmatch _vq_auxt__44c4_s_p6_0 = {
  116884. _vq_quantthresh__44c4_s_p6_0,
  116885. _vq_quantmap__44c4_s_p6_0,
  116886. 17,
  116887. 17
  116888. };
  116889. static static_codebook _44c4_s_p6_0 = {
  116890. 2, 289,
  116891. _vq_lengthlist__44c4_s_p6_0,
  116892. 1, -529530880, 1611661312, 5, 0,
  116893. _vq_quantlist__44c4_s_p6_0,
  116894. NULL,
  116895. &_vq_auxt__44c4_s_p6_0,
  116896. NULL,
  116897. 0
  116898. };
  116899. static long _vq_quantlist__44c4_s_p7_0[] = {
  116900. 1,
  116901. 0,
  116902. 2,
  116903. };
  116904. static long _vq_lengthlist__44c4_s_p7_0[] = {
  116905. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  116906. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,11,11,
  116907. 10,11,11,11, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  116908. 11,10,10,11,10,10, 7,11,11,12,11,11,12,11,11, 6,
  116909. 9, 9,11,10,10,11,10,10, 6, 9, 9,11,10,10,11,10,
  116910. 10,
  116911. };
  116912. static float _vq_quantthresh__44c4_s_p7_0[] = {
  116913. -5.5, 5.5,
  116914. };
  116915. static long _vq_quantmap__44c4_s_p7_0[] = {
  116916. 1, 0, 2,
  116917. };
  116918. static encode_aux_threshmatch _vq_auxt__44c4_s_p7_0 = {
  116919. _vq_quantthresh__44c4_s_p7_0,
  116920. _vq_quantmap__44c4_s_p7_0,
  116921. 3,
  116922. 3
  116923. };
  116924. static static_codebook _44c4_s_p7_0 = {
  116925. 4, 81,
  116926. _vq_lengthlist__44c4_s_p7_0,
  116927. 1, -529137664, 1618345984, 2, 0,
  116928. _vq_quantlist__44c4_s_p7_0,
  116929. NULL,
  116930. &_vq_auxt__44c4_s_p7_0,
  116931. NULL,
  116932. 0
  116933. };
  116934. static long _vq_quantlist__44c4_s_p7_1[] = {
  116935. 5,
  116936. 4,
  116937. 6,
  116938. 3,
  116939. 7,
  116940. 2,
  116941. 8,
  116942. 1,
  116943. 9,
  116944. 0,
  116945. 10,
  116946. };
  116947. static long _vq_lengthlist__44c4_s_p7_1[] = {
  116948. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8,10, 5, 5, 6, 6,
  116949. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  116950. 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  116951. 7, 8, 8, 8, 8, 8, 8,10,10,10, 8, 7, 8, 8, 8, 8,
  116952. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  116953. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  116954. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 9, 8,10,10,
  116955. 10,10,10, 8, 8, 8, 8, 9, 9,
  116956. };
  116957. static float _vq_quantthresh__44c4_s_p7_1[] = {
  116958. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  116959. 3.5, 4.5,
  116960. };
  116961. static long _vq_quantmap__44c4_s_p7_1[] = {
  116962. 9, 7, 5, 3, 1, 0, 2, 4,
  116963. 6, 8, 10,
  116964. };
  116965. static encode_aux_threshmatch _vq_auxt__44c4_s_p7_1 = {
  116966. _vq_quantthresh__44c4_s_p7_1,
  116967. _vq_quantmap__44c4_s_p7_1,
  116968. 11,
  116969. 11
  116970. };
  116971. static static_codebook _44c4_s_p7_1 = {
  116972. 2, 121,
  116973. _vq_lengthlist__44c4_s_p7_1,
  116974. 1, -531365888, 1611661312, 4, 0,
  116975. _vq_quantlist__44c4_s_p7_1,
  116976. NULL,
  116977. &_vq_auxt__44c4_s_p7_1,
  116978. NULL,
  116979. 0
  116980. };
  116981. static long _vq_quantlist__44c4_s_p8_0[] = {
  116982. 6,
  116983. 5,
  116984. 7,
  116985. 4,
  116986. 8,
  116987. 3,
  116988. 9,
  116989. 2,
  116990. 10,
  116991. 1,
  116992. 11,
  116993. 0,
  116994. 12,
  116995. };
  116996. static long _vq_lengthlist__44c4_s_p8_0[] = {
  116997. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  116998. 7, 7, 8, 8, 8, 8, 9,10,11,11, 7, 5, 5, 7, 7, 8,
  116999. 8, 9, 9,10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  117000. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  117001. 11, 0,12,12, 9, 9, 9, 9,10,10,10,10,11,11, 0,13,
  117002. 13, 9, 9,10, 9,10,10,11,11,11,12, 0, 0, 0,10,10,
  117003. 10,10,10,10,11,11,12,12, 0, 0, 0,10,10,10,10,10,
  117004. 10,11,11,12,12, 0, 0, 0,14,14,11,11,11,11,12,12,
  117005. 12,12, 0, 0, 0,14,14,11,11,11,11,12,12,12,13, 0,
  117006. 0, 0, 0, 0,12,12,12,12,12,12,13,13, 0, 0, 0, 0,
  117007. 0,13,12,12,12,12,12,13,13,
  117008. };
  117009. static float _vq_quantthresh__44c4_s_p8_0[] = {
  117010. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  117011. 12.5, 17.5, 22.5, 27.5,
  117012. };
  117013. static long _vq_quantmap__44c4_s_p8_0[] = {
  117014. 11, 9, 7, 5, 3, 1, 0, 2,
  117015. 4, 6, 8, 10, 12,
  117016. };
  117017. static encode_aux_threshmatch _vq_auxt__44c4_s_p8_0 = {
  117018. _vq_quantthresh__44c4_s_p8_0,
  117019. _vq_quantmap__44c4_s_p8_0,
  117020. 13,
  117021. 13
  117022. };
  117023. static static_codebook _44c4_s_p8_0 = {
  117024. 2, 169,
  117025. _vq_lengthlist__44c4_s_p8_0,
  117026. 1, -526516224, 1616117760, 4, 0,
  117027. _vq_quantlist__44c4_s_p8_0,
  117028. NULL,
  117029. &_vq_auxt__44c4_s_p8_0,
  117030. NULL,
  117031. 0
  117032. };
  117033. static long _vq_quantlist__44c4_s_p8_1[] = {
  117034. 2,
  117035. 1,
  117036. 3,
  117037. 0,
  117038. 4,
  117039. };
  117040. static long _vq_lengthlist__44c4_s_p8_1[] = {
  117041. 2, 4, 4, 5, 5, 6, 5, 5, 5, 5, 6, 5, 4, 5, 5, 6,
  117042. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  117043. };
  117044. static float _vq_quantthresh__44c4_s_p8_1[] = {
  117045. -1.5, -0.5, 0.5, 1.5,
  117046. };
  117047. static long _vq_quantmap__44c4_s_p8_1[] = {
  117048. 3, 1, 0, 2, 4,
  117049. };
  117050. static encode_aux_threshmatch _vq_auxt__44c4_s_p8_1 = {
  117051. _vq_quantthresh__44c4_s_p8_1,
  117052. _vq_quantmap__44c4_s_p8_1,
  117053. 5,
  117054. 5
  117055. };
  117056. static static_codebook _44c4_s_p8_1 = {
  117057. 2, 25,
  117058. _vq_lengthlist__44c4_s_p8_1,
  117059. 1, -533725184, 1611661312, 3, 0,
  117060. _vq_quantlist__44c4_s_p8_1,
  117061. NULL,
  117062. &_vq_auxt__44c4_s_p8_1,
  117063. NULL,
  117064. 0
  117065. };
  117066. static long _vq_quantlist__44c4_s_p9_0[] = {
  117067. 6,
  117068. 5,
  117069. 7,
  117070. 4,
  117071. 8,
  117072. 3,
  117073. 9,
  117074. 2,
  117075. 10,
  117076. 1,
  117077. 11,
  117078. 0,
  117079. 12,
  117080. };
  117081. static long _vq_lengthlist__44c4_s_p9_0[] = {
  117082. 1, 3, 3,12,12,12,12,12,12,12,12,12,12, 4, 7, 7,
  117083. 12,12,12,12,12,12,12,12,12,12, 3, 8, 8,12,12,12,
  117084. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  117085. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  117086. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  117087. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  117088. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  117089. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  117090. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  117091. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  117092. 12,12,12,12,12,12,12,12,12,
  117093. };
  117094. static float _vq_quantthresh__44c4_s_p9_0[] = {
  117095. -1732.5, -1417.5, -1102.5, -787.5, -472.5, -157.5, 157.5, 472.5,
  117096. 787.5, 1102.5, 1417.5, 1732.5,
  117097. };
  117098. static long _vq_quantmap__44c4_s_p9_0[] = {
  117099. 11, 9, 7, 5, 3, 1, 0, 2,
  117100. 4, 6, 8, 10, 12,
  117101. };
  117102. static encode_aux_threshmatch _vq_auxt__44c4_s_p9_0 = {
  117103. _vq_quantthresh__44c4_s_p9_0,
  117104. _vq_quantmap__44c4_s_p9_0,
  117105. 13,
  117106. 13
  117107. };
  117108. static static_codebook _44c4_s_p9_0 = {
  117109. 2, 169,
  117110. _vq_lengthlist__44c4_s_p9_0,
  117111. 1, -513964032, 1628680192, 4, 0,
  117112. _vq_quantlist__44c4_s_p9_0,
  117113. NULL,
  117114. &_vq_auxt__44c4_s_p9_0,
  117115. NULL,
  117116. 0
  117117. };
  117118. static long _vq_quantlist__44c4_s_p9_1[] = {
  117119. 7,
  117120. 6,
  117121. 8,
  117122. 5,
  117123. 9,
  117124. 4,
  117125. 10,
  117126. 3,
  117127. 11,
  117128. 2,
  117129. 12,
  117130. 1,
  117131. 13,
  117132. 0,
  117133. 14,
  117134. };
  117135. static long _vq_lengthlist__44c4_s_p9_1[] = {
  117136. 1, 4, 4, 5, 5, 7, 7, 9, 8,10, 9,10,10,10,10, 6,
  117137. 5, 5, 7, 7, 9, 8,10, 9,11,10,12,12,13,13, 6, 5,
  117138. 5, 7, 7, 9, 9,10,10,11,11,12,12,12,13,19, 8, 8,
  117139. 8, 8, 9, 9,10,10,12,11,12,12,13,13,19, 8, 8, 8,
  117140. 8, 9, 9,11,11,12,12,13,13,13,13,19,12,12, 9, 9,
  117141. 11,11,11,11,12,11,13,12,13,13,18,12,12, 9, 9,11,
  117142. 10,11,11,12,12,12,13,13,14,19,18,18,11,11,11,11,
  117143. 12,12,13,12,13,13,14,14,16,18,18,11,11,11,10,12,
  117144. 11,13,13,13,13,13,14,17,18,18,14,15,11,12,12,13,
  117145. 13,13,13,14,14,14,18,18,18,15,15,12,10,13,10,13,
  117146. 13,13,13,13,14,18,17,18,17,18,12,13,12,13,13,13,
  117147. 14,14,16,14,18,17,18,18,17,13,12,13,10,12,12,14,
  117148. 14,14,14,17,18,18,18,18,14,15,12,12,13,12,14,14,
  117149. 15,15,18,18,18,17,18,15,14,12,11,12,12,14,14,14,
  117150. 15,
  117151. };
  117152. static float _vq_quantthresh__44c4_s_p9_1[] = {
  117153. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  117154. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  117155. };
  117156. static long _vq_quantmap__44c4_s_p9_1[] = {
  117157. 13, 11, 9, 7, 5, 3, 1, 0,
  117158. 2, 4, 6, 8, 10, 12, 14,
  117159. };
  117160. static encode_aux_threshmatch _vq_auxt__44c4_s_p9_1 = {
  117161. _vq_quantthresh__44c4_s_p9_1,
  117162. _vq_quantmap__44c4_s_p9_1,
  117163. 15,
  117164. 15
  117165. };
  117166. static static_codebook _44c4_s_p9_1 = {
  117167. 2, 225,
  117168. _vq_lengthlist__44c4_s_p9_1,
  117169. 1, -520986624, 1620377600, 4, 0,
  117170. _vq_quantlist__44c4_s_p9_1,
  117171. NULL,
  117172. &_vq_auxt__44c4_s_p9_1,
  117173. NULL,
  117174. 0
  117175. };
  117176. static long _vq_quantlist__44c4_s_p9_2[] = {
  117177. 10,
  117178. 9,
  117179. 11,
  117180. 8,
  117181. 12,
  117182. 7,
  117183. 13,
  117184. 6,
  117185. 14,
  117186. 5,
  117187. 15,
  117188. 4,
  117189. 16,
  117190. 3,
  117191. 17,
  117192. 2,
  117193. 18,
  117194. 1,
  117195. 19,
  117196. 0,
  117197. 20,
  117198. };
  117199. static long _vq_lengthlist__44c4_s_p9_2[] = {
  117200. 2, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  117201. 8, 9, 9, 9, 9,11, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  117202. 9, 9, 9, 9, 9, 9,10,10,10,10,11, 6, 6, 7, 7, 8,
  117203. 8, 8, 8, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,11,
  117204. 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  117205. 10,10,10,10,12,11,11, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  117206. 9,10,10,10,10,10,10,10,10,12,11,12, 8, 8, 8, 8,
  117207. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,11,11,
  117208. 11, 8, 8, 8, 8, 9, 9, 9, 9,10,10,10,10,10,10,10,
  117209. 10,10,10,11,11,12, 9, 9, 9, 9, 9, 9,10, 9,10,10,
  117210. 10,10,10,10,10,10,10,10,11,11,11,11,11, 9, 9, 9,
  117211. 9,10,10,10,10,10,10,10,10,10,10,10,10,11,12,11,
  117212. 11,11, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  117213. 10,10,11,11,11,11,11, 9, 9, 9, 9,10,10,10,10,10,
  117214. 10,10,10,10,10,10,10,11,11,11,12,12,10,10,10,10,
  117215. 10,10,10,10,10,10,10,10,10,10,10,10,11,12,11,12,
  117216. 11,11,11, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  117217. 10,11,12,11,11,11,11,11,10,10,10,10,10,10,10,10,
  117218. 10,10,10,10,10,10,11,11,11,12,11,11,11,10,10,10,
  117219. 10,10,10,10,10,10,10,10,10,10,10,12,11,11,12,11,
  117220. 11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  117221. 11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,
  117222. 10,10,10,10,10,11,11,11,11,12,12,11,11,11,11,11,
  117223. 11,11,10,10,10,10,10,10,10,10,12,12,12,11,11,11,
  117224. 12,11,11,11,10,10,10,10,10,10,10,10,10,10,10,12,
  117225. 11,12,12,12,12,12,11,12,11,11,10,10,10,10,10,10,
  117226. 10,10,10,10,12,12,12,12,11,11,11,11,11,11,11,10,
  117227. 10,10,10,10,10,10,10,10,10,
  117228. };
  117229. static float _vq_quantthresh__44c4_s_p9_2[] = {
  117230. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  117231. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  117232. 6.5, 7.5, 8.5, 9.5,
  117233. };
  117234. static long _vq_quantmap__44c4_s_p9_2[] = {
  117235. 19, 17, 15, 13, 11, 9, 7, 5,
  117236. 3, 1, 0, 2, 4, 6, 8, 10,
  117237. 12, 14, 16, 18, 20,
  117238. };
  117239. static encode_aux_threshmatch _vq_auxt__44c4_s_p9_2 = {
  117240. _vq_quantthresh__44c4_s_p9_2,
  117241. _vq_quantmap__44c4_s_p9_2,
  117242. 21,
  117243. 21
  117244. };
  117245. static static_codebook _44c4_s_p9_2 = {
  117246. 2, 441,
  117247. _vq_lengthlist__44c4_s_p9_2,
  117248. 1, -529268736, 1611661312, 5, 0,
  117249. _vq_quantlist__44c4_s_p9_2,
  117250. NULL,
  117251. &_vq_auxt__44c4_s_p9_2,
  117252. NULL,
  117253. 0
  117254. };
  117255. static long _huff_lengthlist__44c4_s_short[] = {
  117256. 4, 7,14,10,15,10,12,15,16,15, 4, 2,11, 5,10, 6,
  117257. 8,11,14,14,14,10, 7,11, 6, 8,10,11,13,15, 9, 4,
  117258. 11, 5, 9, 6, 9,12,14,15,14, 9, 6, 9, 4, 5, 7,10,
  117259. 12,13, 9, 5, 7, 6, 5, 5, 7,10,13,13,10, 8, 9, 8,
  117260. 7, 6, 8,10,14,14,13,11,10,10, 7, 7, 8,11,14,15,
  117261. 13,12, 9, 9, 6, 5, 7,10,14,17,15,13,11,10, 6, 6,
  117262. 7, 9,12,17,
  117263. };
  117264. static static_codebook _huff_book__44c4_s_short = {
  117265. 2, 100,
  117266. _huff_lengthlist__44c4_s_short,
  117267. 0, 0, 0, 0, 0,
  117268. NULL,
  117269. NULL,
  117270. NULL,
  117271. NULL,
  117272. 0
  117273. };
  117274. static long _huff_lengthlist__44c5_s_long[] = {
  117275. 3, 8, 9,13,10,12,12,12,12,12, 6, 4, 6, 8, 6, 8,
  117276. 10,10,11,12, 8, 5, 4,10, 4, 7, 8, 9,10,11,13, 8,
  117277. 10, 8, 9, 9,11,12,13,14,10, 6, 4, 9, 3, 5, 6, 8,
  117278. 10,11,11, 8, 6, 9, 5, 5, 6, 7, 9,11,12, 9, 7,11,
  117279. 6, 6, 6, 7, 8,10,12,11, 9,12, 7, 7, 6, 6, 7, 9,
  117280. 13,12,10,13, 9, 8, 7, 7, 7, 8,11,15,11,15,11,10,
  117281. 9, 8, 7, 7,
  117282. };
  117283. static static_codebook _huff_book__44c5_s_long = {
  117284. 2, 100,
  117285. _huff_lengthlist__44c5_s_long,
  117286. 0, 0, 0, 0, 0,
  117287. NULL,
  117288. NULL,
  117289. NULL,
  117290. NULL,
  117291. 0
  117292. };
  117293. static long _vq_quantlist__44c5_s_p1_0[] = {
  117294. 1,
  117295. 0,
  117296. 2,
  117297. };
  117298. static long _vq_lengthlist__44c5_s_p1_0[] = {
  117299. 2, 4, 4, 0, 0, 0, 0, 0, 0, 4, 7, 7, 0, 0, 0, 0,
  117300. 0, 0, 4, 6, 7, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  117305. 0, 0, 0, 7, 8, 9, 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, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  117310. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117311. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117312. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117313. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117318. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 7, 7, 0, 0, 0, 0,
  117345. 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 7, 9, 9, 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, 7, 9, 9, 0, 0, 0,
  117350. 0, 0, 0, 9,10,11, 0, 0, 0, 0, 0, 0, 9,10,10, 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, 7, 9, 9, 0, 0,
  117355. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,11,
  117356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117386. 0, 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, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  117391. 0, 0, 0, 0, 7, 9, 9, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,11,10, 0,
  117396. 0, 0, 0, 0, 0, 8, 9,10, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  117401. 0, 0, 0, 0, 0, 0, 9,11,10, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117709. 0,
  117710. };
  117711. static float _vq_quantthresh__44c5_s_p1_0[] = {
  117712. -0.5, 0.5,
  117713. };
  117714. static long _vq_quantmap__44c5_s_p1_0[] = {
  117715. 1, 0, 2,
  117716. };
  117717. static encode_aux_threshmatch _vq_auxt__44c5_s_p1_0 = {
  117718. _vq_quantthresh__44c5_s_p1_0,
  117719. _vq_quantmap__44c5_s_p1_0,
  117720. 3,
  117721. 3
  117722. };
  117723. static static_codebook _44c5_s_p1_0 = {
  117724. 8, 6561,
  117725. _vq_lengthlist__44c5_s_p1_0,
  117726. 1, -535822336, 1611661312, 2, 0,
  117727. _vq_quantlist__44c5_s_p1_0,
  117728. NULL,
  117729. &_vq_auxt__44c5_s_p1_0,
  117730. NULL,
  117731. 0
  117732. };
  117733. static long _vq_quantlist__44c5_s_p2_0[] = {
  117734. 2,
  117735. 1,
  117736. 3,
  117737. 0,
  117738. 4,
  117739. };
  117740. static long _vq_lengthlist__44c5_s_p2_0[] = {
  117741. 2, 4, 4, 0, 0, 0, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0,
  117742. 8, 7, 0, 0, 0, 0, 0, 0, 0, 4, 6, 6, 0, 0, 0, 8,
  117743. 8, 0, 0, 0, 8, 7, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  117744. 0, 0, 4, 6, 6, 0, 0, 0, 8, 8, 0, 0, 0, 7, 8, 0,
  117745. 0, 0,10,10, 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, 5, 8, 7, 0, 0, 0, 8, 8, 0, 0,
  117751. 0, 8, 8, 0, 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 5,
  117752. 7, 8, 0, 0, 0, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0,10,
  117753. 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117758. 0, 0, 0, 5, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0, 8, 8,
  117759. 0, 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0,
  117760. 0, 0, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0,10,10, 0, 0,
  117761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117766. 8,10,10, 0, 0, 0,10,10, 0, 0, 0, 9,10, 0, 0, 0,
  117767. 11,10, 0, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0, 0,10,
  117768. 10, 0, 0, 0,10,10, 0, 0, 0,10,11, 0, 0, 0, 0, 0,
  117769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117780. 0,
  117781. };
  117782. static float _vq_quantthresh__44c5_s_p2_0[] = {
  117783. -1.5, -0.5, 0.5, 1.5,
  117784. };
  117785. static long _vq_quantmap__44c5_s_p2_0[] = {
  117786. 3, 1, 0, 2, 4,
  117787. };
  117788. static encode_aux_threshmatch _vq_auxt__44c5_s_p2_0 = {
  117789. _vq_quantthresh__44c5_s_p2_0,
  117790. _vq_quantmap__44c5_s_p2_0,
  117791. 5,
  117792. 5
  117793. };
  117794. static static_codebook _44c5_s_p2_0 = {
  117795. 4, 625,
  117796. _vq_lengthlist__44c5_s_p2_0,
  117797. 1, -533725184, 1611661312, 3, 0,
  117798. _vq_quantlist__44c5_s_p2_0,
  117799. NULL,
  117800. &_vq_auxt__44c5_s_p2_0,
  117801. NULL,
  117802. 0
  117803. };
  117804. static long _vq_quantlist__44c5_s_p3_0[] = {
  117805. 2,
  117806. 1,
  117807. 3,
  117808. 0,
  117809. 4,
  117810. };
  117811. static long _vq_lengthlist__44c5_s_p3_0[] = {
  117812. 2, 4, 3, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 6, 6, 0, 0,
  117814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117815. 0, 0, 3, 5, 5, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 8, 8,
  117817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117818. 0, 0, 0, 0, 5, 6, 6, 8, 8, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117851. 0,
  117852. };
  117853. static float _vq_quantthresh__44c5_s_p3_0[] = {
  117854. -1.5, -0.5, 0.5, 1.5,
  117855. };
  117856. static long _vq_quantmap__44c5_s_p3_0[] = {
  117857. 3, 1, 0, 2, 4,
  117858. };
  117859. static encode_aux_threshmatch _vq_auxt__44c5_s_p3_0 = {
  117860. _vq_quantthresh__44c5_s_p3_0,
  117861. _vq_quantmap__44c5_s_p3_0,
  117862. 5,
  117863. 5
  117864. };
  117865. static static_codebook _44c5_s_p3_0 = {
  117866. 4, 625,
  117867. _vq_lengthlist__44c5_s_p3_0,
  117868. 1, -533725184, 1611661312, 3, 0,
  117869. _vq_quantlist__44c5_s_p3_0,
  117870. NULL,
  117871. &_vq_auxt__44c5_s_p3_0,
  117872. NULL,
  117873. 0
  117874. };
  117875. static long _vq_quantlist__44c5_s_p4_0[] = {
  117876. 4,
  117877. 3,
  117878. 5,
  117879. 2,
  117880. 6,
  117881. 1,
  117882. 7,
  117883. 0,
  117884. 8,
  117885. };
  117886. static long _vq_lengthlist__44c5_s_p4_0[] = {
  117887. 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 4, 4, 6, 6, 0, 0,
  117888. 0, 0, 0, 4, 4, 6, 6, 0, 0, 0, 0, 0, 5, 5, 6, 6,
  117889. 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0,
  117890. 7, 7, 0, 0, 0, 0, 0, 0, 0, 8, 7, 0, 0, 0, 0, 0,
  117891. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117892. 0,
  117893. };
  117894. static float _vq_quantthresh__44c5_s_p4_0[] = {
  117895. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  117896. };
  117897. static long _vq_quantmap__44c5_s_p4_0[] = {
  117898. 7, 5, 3, 1, 0, 2, 4, 6,
  117899. 8,
  117900. };
  117901. static encode_aux_threshmatch _vq_auxt__44c5_s_p4_0 = {
  117902. _vq_quantthresh__44c5_s_p4_0,
  117903. _vq_quantmap__44c5_s_p4_0,
  117904. 9,
  117905. 9
  117906. };
  117907. static static_codebook _44c5_s_p4_0 = {
  117908. 2, 81,
  117909. _vq_lengthlist__44c5_s_p4_0,
  117910. 1, -531628032, 1611661312, 4, 0,
  117911. _vq_quantlist__44c5_s_p4_0,
  117912. NULL,
  117913. &_vq_auxt__44c5_s_p4_0,
  117914. NULL,
  117915. 0
  117916. };
  117917. static long _vq_quantlist__44c5_s_p5_0[] = {
  117918. 4,
  117919. 3,
  117920. 5,
  117921. 2,
  117922. 6,
  117923. 1,
  117924. 7,
  117925. 0,
  117926. 8,
  117927. };
  117928. static long _vq_lengthlist__44c5_s_p5_0[] = {
  117929. 2, 4, 3, 6, 6, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  117930. 9, 9, 0, 4, 4, 6, 6, 7, 7, 9, 9, 0, 6, 6, 7, 7,
  117931. 7, 7, 9, 9, 0, 0, 0, 7, 6, 7, 7, 9, 9, 0, 0, 0,
  117932. 8, 8, 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0,
  117933. 0, 0, 9, 9, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  117934. 10,
  117935. };
  117936. static float _vq_quantthresh__44c5_s_p5_0[] = {
  117937. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  117938. };
  117939. static long _vq_quantmap__44c5_s_p5_0[] = {
  117940. 7, 5, 3, 1, 0, 2, 4, 6,
  117941. 8,
  117942. };
  117943. static encode_aux_threshmatch _vq_auxt__44c5_s_p5_0 = {
  117944. _vq_quantthresh__44c5_s_p5_0,
  117945. _vq_quantmap__44c5_s_p5_0,
  117946. 9,
  117947. 9
  117948. };
  117949. static static_codebook _44c5_s_p5_0 = {
  117950. 2, 81,
  117951. _vq_lengthlist__44c5_s_p5_0,
  117952. 1, -531628032, 1611661312, 4, 0,
  117953. _vq_quantlist__44c5_s_p5_0,
  117954. NULL,
  117955. &_vq_auxt__44c5_s_p5_0,
  117956. NULL,
  117957. 0
  117958. };
  117959. static long _vq_quantlist__44c5_s_p6_0[] = {
  117960. 8,
  117961. 7,
  117962. 9,
  117963. 6,
  117964. 10,
  117965. 5,
  117966. 11,
  117967. 4,
  117968. 12,
  117969. 3,
  117970. 13,
  117971. 2,
  117972. 14,
  117973. 1,
  117974. 15,
  117975. 0,
  117976. 16,
  117977. };
  117978. static long _vq_lengthlist__44c5_s_p6_0[] = {
  117979. 2, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,10,11,
  117980. 11, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,11,
  117981. 12,12, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,
  117982. 11,12,12, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  117983. 11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  117984. 10,11,11,12,12, 0, 0, 0, 7, 7, 9, 9,10,10,10,10,
  117985. 11,11,11,11,12,12, 0, 0, 0, 7, 7, 8, 9,10,10,10,
  117986. 10,11,11,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,
  117987. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  117988. 10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,
  117989. 10,10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9,
  117990. 9, 9,10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0,
  117991. 10,10,10,10,11,11,11,12,12,12,13,13, 0, 0, 0, 0,
  117992. 0, 0, 0,10,10,11,11,11,11,12,12,13,13, 0, 0, 0,
  117993. 0, 0, 0, 0,11,11,11,11,12,12,12,13,13,13, 0, 0,
  117994. 0, 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0,
  117995. 0, 0, 0, 0, 0, 0,12,12,12,12,13,12,13,13,13,13,
  117996. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,
  117997. 13,
  117998. };
  117999. static float _vq_quantthresh__44c5_s_p6_0[] = {
  118000. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  118001. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  118002. };
  118003. static long _vq_quantmap__44c5_s_p6_0[] = {
  118004. 15, 13, 11, 9, 7, 5, 3, 1,
  118005. 0, 2, 4, 6, 8, 10, 12, 14,
  118006. 16,
  118007. };
  118008. static encode_aux_threshmatch _vq_auxt__44c5_s_p6_0 = {
  118009. _vq_quantthresh__44c5_s_p6_0,
  118010. _vq_quantmap__44c5_s_p6_0,
  118011. 17,
  118012. 17
  118013. };
  118014. static static_codebook _44c5_s_p6_0 = {
  118015. 2, 289,
  118016. _vq_lengthlist__44c5_s_p6_0,
  118017. 1, -529530880, 1611661312, 5, 0,
  118018. _vq_quantlist__44c5_s_p6_0,
  118019. NULL,
  118020. &_vq_auxt__44c5_s_p6_0,
  118021. NULL,
  118022. 0
  118023. };
  118024. static long _vq_quantlist__44c5_s_p7_0[] = {
  118025. 1,
  118026. 0,
  118027. 2,
  118028. };
  118029. static long _vq_lengthlist__44c5_s_p7_0[] = {
  118030. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  118031. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,11,11,
  118032. 10,11,11,11, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  118033. 11,10,10,11,10,10, 7,11,11,12,11,11,12,11,11, 6,
  118034. 9, 9,11,10,10,11,10,10, 6, 9, 9,11,10,10,11,10,
  118035. 10,
  118036. };
  118037. static float _vq_quantthresh__44c5_s_p7_0[] = {
  118038. -5.5, 5.5,
  118039. };
  118040. static long _vq_quantmap__44c5_s_p7_0[] = {
  118041. 1, 0, 2,
  118042. };
  118043. static encode_aux_threshmatch _vq_auxt__44c5_s_p7_0 = {
  118044. _vq_quantthresh__44c5_s_p7_0,
  118045. _vq_quantmap__44c5_s_p7_0,
  118046. 3,
  118047. 3
  118048. };
  118049. static static_codebook _44c5_s_p7_0 = {
  118050. 4, 81,
  118051. _vq_lengthlist__44c5_s_p7_0,
  118052. 1, -529137664, 1618345984, 2, 0,
  118053. _vq_quantlist__44c5_s_p7_0,
  118054. NULL,
  118055. &_vq_auxt__44c5_s_p7_0,
  118056. NULL,
  118057. 0
  118058. };
  118059. static long _vq_quantlist__44c5_s_p7_1[] = {
  118060. 5,
  118061. 4,
  118062. 6,
  118063. 3,
  118064. 7,
  118065. 2,
  118066. 8,
  118067. 1,
  118068. 9,
  118069. 0,
  118070. 10,
  118071. };
  118072. static long _vq_lengthlist__44c5_s_p7_1[] = {
  118073. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6,
  118074. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  118075. 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  118076. 7, 8, 8, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  118077. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  118078. 8, 8, 8, 8, 8, 8, 8, 9,10,10,10,10,10, 8, 8, 8,
  118079. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  118080. 10,10,10, 8, 8, 8, 8, 8, 8,
  118081. };
  118082. static float _vq_quantthresh__44c5_s_p7_1[] = {
  118083. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  118084. 3.5, 4.5,
  118085. };
  118086. static long _vq_quantmap__44c5_s_p7_1[] = {
  118087. 9, 7, 5, 3, 1, 0, 2, 4,
  118088. 6, 8, 10,
  118089. };
  118090. static encode_aux_threshmatch _vq_auxt__44c5_s_p7_1 = {
  118091. _vq_quantthresh__44c5_s_p7_1,
  118092. _vq_quantmap__44c5_s_p7_1,
  118093. 11,
  118094. 11
  118095. };
  118096. static static_codebook _44c5_s_p7_1 = {
  118097. 2, 121,
  118098. _vq_lengthlist__44c5_s_p7_1,
  118099. 1, -531365888, 1611661312, 4, 0,
  118100. _vq_quantlist__44c5_s_p7_1,
  118101. NULL,
  118102. &_vq_auxt__44c5_s_p7_1,
  118103. NULL,
  118104. 0
  118105. };
  118106. static long _vq_quantlist__44c5_s_p8_0[] = {
  118107. 6,
  118108. 5,
  118109. 7,
  118110. 4,
  118111. 8,
  118112. 3,
  118113. 9,
  118114. 2,
  118115. 10,
  118116. 1,
  118117. 11,
  118118. 0,
  118119. 12,
  118120. };
  118121. static long _vq_lengthlist__44c5_s_p8_0[] = {
  118122. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  118123. 7, 7, 8, 8, 8, 9,10,10,10,10, 7, 5, 5, 7, 7, 8,
  118124. 8, 9, 9,10,10,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  118125. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  118126. 11, 0,12,12, 9, 9, 9,10,10,10,10,10,11,11, 0,13,
  118127. 13, 9, 9, 9, 9,10,10,11,11,11,11, 0, 0, 0,10,10,
  118128. 10,10,10,10,11,11,11,11, 0, 0, 0,10,10,10,10,10,
  118129. 10,11,11,12,12, 0, 0, 0,14,14,11,11,11,11,12,12,
  118130. 12,12, 0, 0, 0,14,14,11,11,11,11,12,12,12,12, 0,
  118131. 0, 0, 0, 0,12,12,12,12,12,12,13,13, 0, 0, 0, 0,
  118132. 0,12,12,12,12,12,12,13,13,
  118133. };
  118134. static float _vq_quantthresh__44c5_s_p8_0[] = {
  118135. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  118136. 12.5, 17.5, 22.5, 27.5,
  118137. };
  118138. static long _vq_quantmap__44c5_s_p8_0[] = {
  118139. 11, 9, 7, 5, 3, 1, 0, 2,
  118140. 4, 6, 8, 10, 12,
  118141. };
  118142. static encode_aux_threshmatch _vq_auxt__44c5_s_p8_0 = {
  118143. _vq_quantthresh__44c5_s_p8_0,
  118144. _vq_quantmap__44c5_s_p8_0,
  118145. 13,
  118146. 13
  118147. };
  118148. static static_codebook _44c5_s_p8_0 = {
  118149. 2, 169,
  118150. _vq_lengthlist__44c5_s_p8_0,
  118151. 1, -526516224, 1616117760, 4, 0,
  118152. _vq_quantlist__44c5_s_p8_0,
  118153. NULL,
  118154. &_vq_auxt__44c5_s_p8_0,
  118155. NULL,
  118156. 0
  118157. };
  118158. static long _vq_quantlist__44c5_s_p8_1[] = {
  118159. 2,
  118160. 1,
  118161. 3,
  118162. 0,
  118163. 4,
  118164. };
  118165. static long _vq_lengthlist__44c5_s_p8_1[] = {
  118166. 2, 4, 4, 5, 5, 6, 5, 5, 5, 5, 6, 4, 5, 5, 5, 6,
  118167. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  118168. };
  118169. static float _vq_quantthresh__44c5_s_p8_1[] = {
  118170. -1.5, -0.5, 0.5, 1.5,
  118171. };
  118172. static long _vq_quantmap__44c5_s_p8_1[] = {
  118173. 3, 1, 0, 2, 4,
  118174. };
  118175. static encode_aux_threshmatch _vq_auxt__44c5_s_p8_1 = {
  118176. _vq_quantthresh__44c5_s_p8_1,
  118177. _vq_quantmap__44c5_s_p8_1,
  118178. 5,
  118179. 5
  118180. };
  118181. static static_codebook _44c5_s_p8_1 = {
  118182. 2, 25,
  118183. _vq_lengthlist__44c5_s_p8_1,
  118184. 1, -533725184, 1611661312, 3, 0,
  118185. _vq_quantlist__44c5_s_p8_1,
  118186. NULL,
  118187. &_vq_auxt__44c5_s_p8_1,
  118188. NULL,
  118189. 0
  118190. };
  118191. static long _vq_quantlist__44c5_s_p9_0[] = {
  118192. 7,
  118193. 6,
  118194. 8,
  118195. 5,
  118196. 9,
  118197. 4,
  118198. 10,
  118199. 3,
  118200. 11,
  118201. 2,
  118202. 12,
  118203. 1,
  118204. 13,
  118205. 0,
  118206. 14,
  118207. };
  118208. static long _vq_lengthlist__44c5_s_p9_0[] = {
  118209. 1, 3, 3,13,13,13,13,13,13,13,13,13,13,13,13, 4,
  118210. 7, 7,13,13,13,13,13,13,13,13,13,13,13,13, 3, 8,
  118211. 6,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118212. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118213. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118214. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118215. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118216. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118217. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118218. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118219. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118220. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118221. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118222. 13,13,13,13,13,13,13,13,13,12,12,12,12,12,12,12,
  118223. 12,
  118224. };
  118225. static float _vq_quantthresh__44c5_s_p9_0[] = {
  118226. -2320.5, -1963.5, -1606.5, -1249.5, -892.5, -535.5, -178.5, 178.5,
  118227. 535.5, 892.5, 1249.5, 1606.5, 1963.5, 2320.5,
  118228. };
  118229. static long _vq_quantmap__44c5_s_p9_0[] = {
  118230. 13, 11, 9, 7, 5, 3, 1, 0,
  118231. 2, 4, 6, 8, 10, 12, 14,
  118232. };
  118233. static encode_aux_threshmatch _vq_auxt__44c5_s_p9_0 = {
  118234. _vq_quantthresh__44c5_s_p9_0,
  118235. _vq_quantmap__44c5_s_p9_0,
  118236. 15,
  118237. 15
  118238. };
  118239. static static_codebook _44c5_s_p9_0 = {
  118240. 2, 225,
  118241. _vq_lengthlist__44c5_s_p9_0,
  118242. 1, -512522752, 1628852224, 4, 0,
  118243. _vq_quantlist__44c5_s_p9_0,
  118244. NULL,
  118245. &_vq_auxt__44c5_s_p9_0,
  118246. NULL,
  118247. 0
  118248. };
  118249. static long _vq_quantlist__44c5_s_p9_1[] = {
  118250. 8,
  118251. 7,
  118252. 9,
  118253. 6,
  118254. 10,
  118255. 5,
  118256. 11,
  118257. 4,
  118258. 12,
  118259. 3,
  118260. 13,
  118261. 2,
  118262. 14,
  118263. 1,
  118264. 15,
  118265. 0,
  118266. 16,
  118267. };
  118268. static long _vq_lengthlist__44c5_s_p9_1[] = {
  118269. 1, 4, 4, 5, 5, 7, 7, 9, 8,10, 9,10,10,11,10,11,
  118270. 11, 6, 5, 5, 7, 7, 8, 9,10,10,11,10,12,11,12,11,
  118271. 13,12, 6, 5, 5, 7, 7, 9, 9,10,10,11,11,12,12,13,
  118272. 12,13,13,18, 8, 8, 8, 8, 9, 9,10,11,11,11,12,11,
  118273. 13,11,13,12,18, 8, 8, 8, 8,10,10,11,11,12,12,13,
  118274. 13,13,13,13,14,18,12,12, 9, 9,11,11,11,11,12,12,
  118275. 13,12,13,12,13,13,20,13,12, 9, 9,11,11,11,11,12,
  118276. 12,13,13,13,14,14,13,20,18,19,11,12,11,11,12,12,
  118277. 13,13,13,13,13,13,14,13,18,19,19,12,11,11,11,12,
  118278. 12,13,12,13,13,13,14,14,13,18,17,19,14,15,12,12,
  118279. 12,13,13,13,14,14,14,14,14,14,19,19,19,16,15,12,
  118280. 11,13,12,14,14,14,13,13,14,14,14,19,18,19,18,19,
  118281. 13,13,13,13,14,14,14,13,14,14,14,14,18,17,19,19,
  118282. 19,13,13,13,11,13,11,13,14,14,14,14,14,19,17,17,
  118283. 18,18,16,16,13,13,13,13,14,13,15,15,14,14,19,19,
  118284. 17,17,18,16,16,13,11,14,10,13,12,14,14,14,14,19,
  118285. 19,19,19,19,18,17,13,14,13,11,14,13,14,14,15,15,
  118286. 19,19,19,17,19,18,18,14,13,12,11,14,11,15,15,15,
  118287. 15,
  118288. };
  118289. static float _vq_quantthresh__44c5_s_p9_1[] = {
  118290. -157.5, -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5,
  118291. 10.5, 31.5, 52.5, 73.5, 94.5, 115.5, 136.5, 157.5,
  118292. };
  118293. static long _vq_quantmap__44c5_s_p9_1[] = {
  118294. 15, 13, 11, 9, 7, 5, 3, 1,
  118295. 0, 2, 4, 6, 8, 10, 12, 14,
  118296. 16,
  118297. };
  118298. static encode_aux_threshmatch _vq_auxt__44c5_s_p9_1 = {
  118299. _vq_quantthresh__44c5_s_p9_1,
  118300. _vq_quantmap__44c5_s_p9_1,
  118301. 17,
  118302. 17
  118303. };
  118304. static static_codebook _44c5_s_p9_1 = {
  118305. 2, 289,
  118306. _vq_lengthlist__44c5_s_p9_1,
  118307. 1, -520814592, 1620377600, 5, 0,
  118308. _vq_quantlist__44c5_s_p9_1,
  118309. NULL,
  118310. &_vq_auxt__44c5_s_p9_1,
  118311. NULL,
  118312. 0
  118313. };
  118314. static long _vq_quantlist__44c5_s_p9_2[] = {
  118315. 10,
  118316. 9,
  118317. 11,
  118318. 8,
  118319. 12,
  118320. 7,
  118321. 13,
  118322. 6,
  118323. 14,
  118324. 5,
  118325. 15,
  118326. 4,
  118327. 16,
  118328. 3,
  118329. 17,
  118330. 2,
  118331. 18,
  118332. 1,
  118333. 19,
  118334. 0,
  118335. 20,
  118336. };
  118337. static long _vq_lengthlist__44c5_s_p9_2[] = {
  118338. 3, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  118339. 8, 8, 8, 8, 9,11, 5, 6, 7, 7, 8, 7, 8, 8, 8, 8,
  118340. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11, 5, 5, 7, 7, 7,
  118341. 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
  118342. 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9,
  118343. 9,10, 9,10,11,11,11, 7, 7, 8, 8, 8, 8, 9, 9, 9,
  118344. 9, 9, 9,10,10,10,10,10,10,11,11,11, 8, 8, 8, 8,
  118345. 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,11,11,
  118346. 11, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,10,
  118347. 10,10,10,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  118348. 10,10,10,10,10,10,10,10,11,11,11,11,11, 9, 9, 9,
  118349. 9, 9, 9,10, 9,10,10,10,10,10,10,10,10,11,11,11,
  118350. 11,11, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,
  118351. 10,10,11,11,11,11,11, 9, 9, 9, 9, 9, 9,10,10,10,
  118352. 10,10,10,10,10,10,10,11,11,11,11,11, 9, 9,10, 9,
  118353. 10,10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,
  118354. 11,11,11, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  118355. 10,11,11,11,11,11,11,11,10,10,10,10,10,10,10,10,
  118356. 10,10,10,10,10,10,11,11,11,11,11,11,11,10,10,10,
  118357. 10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,
  118358. 11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118359. 11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,
  118360. 10,10,10,10,10,11,11,11,11,11,11,11,11,11,10,10,
  118361. 10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,
  118362. 11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,11,
  118363. 11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,10,
  118364. 10,10,10,10,11,11,11,11,11,11,11,11,11,11,11,10,
  118365. 10,10,10,10,10,10,10,10,10,
  118366. };
  118367. static float _vq_quantthresh__44c5_s_p9_2[] = {
  118368. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  118369. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  118370. 6.5, 7.5, 8.5, 9.5,
  118371. };
  118372. static long _vq_quantmap__44c5_s_p9_2[] = {
  118373. 19, 17, 15, 13, 11, 9, 7, 5,
  118374. 3, 1, 0, 2, 4, 6, 8, 10,
  118375. 12, 14, 16, 18, 20,
  118376. };
  118377. static encode_aux_threshmatch _vq_auxt__44c5_s_p9_2 = {
  118378. _vq_quantthresh__44c5_s_p9_2,
  118379. _vq_quantmap__44c5_s_p9_2,
  118380. 21,
  118381. 21
  118382. };
  118383. static static_codebook _44c5_s_p9_2 = {
  118384. 2, 441,
  118385. _vq_lengthlist__44c5_s_p9_2,
  118386. 1, -529268736, 1611661312, 5, 0,
  118387. _vq_quantlist__44c5_s_p9_2,
  118388. NULL,
  118389. &_vq_auxt__44c5_s_p9_2,
  118390. NULL,
  118391. 0
  118392. };
  118393. static long _huff_lengthlist__44c5_s_short[] = {
  118394. 5, 8,10,14,11,11,12,16,15,17, 5, 5, 7, 9, 7, 8,
  118395. 10,13,17,17, 7, 5, 5,10, 5, 7, 8,11,13,15,10, 8,
  118396. 10, 8, 8, 8,11,15,18,18, 8, 5, 5, 8, 3, 4, 6,10,
  118397. 14,16, 9, 7, 6, 7, 4, 3, 5, 9,14,18,10, 9, 8,10,
  118398. 6, 5, 6, 9,14,18,12,12,11,12, 8, 7, 8,11,14,18,
  118399. 14,13,12,10, 7, 5, 6, 9,14,18,14,14,13,10, 6, 5,
  118400. 6, 8,11,16,
  118401. };
  118402. static static_codebook _huff_book__44c5_s_short = {
  118403. 2, 100,
  118404. _huff_lengthlist__44c5_s_short,
  118405. 0, 0, 0, 0, 0,
  118406. NULL,
  118407. NULL,
  118408. NULL,
  118409. NULL,
  118410. 0
  118411. };
  118412. static long _huff_lengthlist__44c6_s_long[] = {
  118413. 3, 8,11,13,14,14,13,13,16,14, 6, 3, 4, 7, 9, 9,
  118414. 10,11,14,13,10, 4, 3, 5, 7, 7, 9,10,13,15,12, 7,
  118415. 4, 4, 6, 6, 8,10,13,15,12, 8, 6, 6, 6, 6, 8,10,
  118416. 13,14,11, 9, 7, 6, 6, 6, 7, 8,12,11,13,10, 9, 8,
  118417. 7, 6, 6, 7,11,11,13,11,10, 9, 9, 7, 7, 6,10,11,
  118418. 13,13,13,13,13,11, 9, 8,10,12,12,15,15,16,15,12,
  118419. 11,10,10,12,
  118420. };
  118421. static static_codebook _huff_book__44c6_s_long = {
  118422. 2, 100,
  118423. _huff_lengthlist__44c6_s_long,
  118424. 0, 0, 0, 0, 0,
  118425. NULL,
  118426. NULL,
  118427. NULL,
  118428. NULL,
  118429. 0
  118430. };
  118431. static long _vq_quantlist__44c6_s_p1_0[] = {
  118432. 1,
  118433. 0,
  118434. 2,
  118435. };
  118436. static long _vq_lengthlist__44c6_s_p1_0[] = {
  118437. 1, 5, 5, 0, 5, 5, 0, 5, 5, 5, 8, 7, 0, 9, 9, 0,
  118438. 9, 8, 5, 7, 8, 0, 9, 9, 0, 8, 9, 0, 0, 0, 0, 0,
  118439. 0, 0, 0, 0, 5, 9, 8, 0, 8, 8, 0, 8, 8, 5, 8, 9,
  118440. 0, 8, 8, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
  118441. 9, 9, 0, 8, 8, 0, 8, 8, 5, 9, 9, 0, 8, 8, 0, 8,
  118442. 8,
  118443. };
  118444. static float _vq_quantthresh__44c6_s_p1_0[] = {
  118445. -0.5, 0.5,
  118446. };
  118447. static long _vq_quantmap__44c6_s_p1_0[] = {
  118448. 1, 0, 2,
  118449. };
  118450. static encode_aux_threshmatch _vq_auxt__44c6_s_p1_0 = {
  118451. _vq_quantthresh__44c6_s_p1_0,
  118452. _vq_quantmap__44c6_s_p1_0,
  118453. 3,
  118454. 3
  118455. };
  118456. static static_codebook _44c6_s_p1_0 = {
  118457. 4, 81,
  118458. _vq_lengthlist__44c6_s_p1_0,
  118459. 1, -535822336, 1611661312, 2, 0,
  118460. _vq_quantlist__44c6_s_p1_0,
  118461. NULL,
  118462. &_vq_auxt__44c6_s_p1_0,
  118463. NULL,
  118464. 0
  118465. };
  118466. static long _vq_quantlist__44c6_s_p2_0[] = {
  118467. 2,
  118468. 1,
  118469. 3,
  118470. 0,
  118471. 4,
  118472. };
  118473. static long _vq_lengthlist__44c6_s_p2_0[] = {
  118474. 3, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0,
  118475. 7, 7, 9, 9, 0, 0, 0, 9, 9, 5, 7, 7, 9, 9, 0, 8,
  118476. 8,10,10, 0, 8, 7,10, 9, 0,10,10,11,11, 0, 0, 0,
  118477. 11,11, 5, 7, 7, 9, 9, 0, 8, 8,10,10, 0, 7, 8, 9,
  118478. 10, 0,10,10,11,11, 0, 0, 0,11,11, 8, 9, 9,11,11,
  118479. 0,11,11,12,12, 0,11,10,12,12, 0,13,14,14,14, 0,
  118480. 0, 0,14,13, 8, 9, 9,11,11, 0,11,11,12,12, 0,10,
  118481. 11,12,12, 0,14,13,14,14, 0, 0, 0,13,14, 0, 0, 0,
  118482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118483. 0, 0, 0, 0, 0, 0, 5, 8, 7,11,10, 0, 7, 7,10,10,
  118484. 0, 7, 7,10,10, 0, 9, 9,11,10, 0, 0, 0,11,11, 5,
  118485. 7, 8,10,11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9,
  118486. 9,10,11, 0, 0, 0,11,11, 8,10, 9,12,12, 0,10,10,
  118487. 12,12, 0,10,10,12,12, 0,12,12,13,13, 0, 0, 0,13,
  118488. 13, 8, 9,10,12,12, 0,10,10,11,12, 0,10,10,12,12,
  118489. 0,12,12,13,13, 0, 0, 0,13,13, 0, 0, 0, 0, 0, 0,
  118490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118491. 0, 0, 0, 5, 8, 8,11,11, 0, 7, 7,10,10, 0, 7, 7,
  118492. 10,10, 0, 9, 9,10,11, 0, 0, 0,11,10, 5, 8, 8,11,
  118493. 11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9, 9,11,11,
  118494. 0, 0, 0,10,11, 8,10,10,12,12, 0,10,10,12,12, 0,
  118495. 10,10,12,12, 0,12,13,13,13, 0, 0, 0,14,13, 8,10,
  118496. 10,12,12, 0,10,10,12,12, 0,10,10,12,12, 0,13,12,
  118497. 13,13, 0, 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118499. 7,10,10,14,13, 0, 9, 9,13,12, 0, 9, 9,12,12, 0,
  118500. 10,10,12,12, 0, 0, 0,12,12, 7,10,10,13,14, 0, 9,
  118501. 9,12,13, 0, 9, 9,12,12, 0,10,10,12,12, 0, 0, 0,
  118502. 12,12, 9,11,11,14,13, 0,11,10,14,13, 0,11,11,13,
  118503. 13, 0,12,12,13,13, 0, 0, 0,13,13, 9,11,11,13,14,
  118504. 0,10,11,13,14, 0,11,11,13,13, 0,12,12,13,13, 0,
  118505. 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
  118510. 11,11,14,14, 0,11,11,13,13, 0,11,10,13,13, 0,12,
  118511. 12,13,13, 0, 0, 0,13,13, 9,11,11,14,14, 0,11,11,
  118512. 13,13, 0,10,11,13,13, 0,12,12,14,13, 0, 0, 0,13,
  118513. 13,
  118514. };
  118515. static float _vq_quantthresh__44c6_s_p2_0[] = {
  118516. -1.5, -0.5, 0.5, 1.5,
  118517. };
  118518. static long _vq_quantmap__44c6_s_p2_0[] = {
  118519. 3, 1, 0, 2, 4,
  118520. };
  118521. static encode_aux_threshmatch _vq_auxt__44c6_s_p2_0 = {
  118522. _vq_quantthresh__44c6_s_p2_0,
  118523. _vq_quantmap__44c6_s_p2_0,
  118524. 5,
  118525. 5
  118526. };
  118527. static static_codebook _44c6_s_p2_0 = {
  118528. 4, 625,
  118529. _vq_lengthlist__44c6_s_p2_0,
  118530. 1, -533725184, 1611661312, 3, 0,
  118531. _vq_quantlist__44c6_s_p2_0,
  118532. NULL,
  118533. &_vq_auxt__44c6_s_p2_0,
  118534. NULL,
  118535. 0
  118536. };
  118537. static long _vq_quantlist__44c6_s_p3_0[] = {
  118538. 4,
  118539. 3,
  118540. 5,
  118541. 2,
  118542. 6,
  118543. 1,
  118544. 7,
  118545. 0,
  118546. 8,
  118547. };
  118548. static long _vq_lengthlist__44c6_s_p3_0[] = {
  118549. 2, 3, 4, 6, 6, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  118550. 9,10, 0, 4, 4, 6, 6, 7, 7,10, 9, 0, 5, 5, 7, 7,
  118551. 8, 8,10,10, 0, 0, 0, 7, 6, 8, 8,10,10, 0, 0, 0,
  118552. 7, 7, 9, 9,11,11, 0, 0, 0, 7, 7, 9, 9,11,11, 0,
  118553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118554. 0,
  118555. };
  118556. static float _vq_quantthresh__44c6_s_p3_0[] = {
  118557. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  118558. };
  118559. static long _vq_quantmap__44c6_s_p3_0[] = {
  118560. 7, 5, 3, 1, 0, 2, 4, 6,
  118561. 8,
  118562. };
  118563. static encode_aux_threshmatch _vq_auxt__44c6_s_p3_0 = {
  118564. _vq_quantthresh__44c6_s_p3_0,
  118565. _vq_quantmap__44c6_s_p3_0,
  118566. 9,
  118567. 9
  118568. };
  118569. static static_codebook _44c6_s_p3_0 = {
  118570. 2, 81,
  118571. _vq_lengthlist__44c6_s_p3_0,
  118572. 1, -531628032, 1611661312, 4, 0,
  118573. _vq_quantlist__44c6_s_p3_0,
  118574. NULL,
  118575. &_vq_auxt__44c6_s_p3_0,
  118576. NULL,
  118577. 0
  118578. };
  118579. static long _vq_quantlist__44c6_s_p4_0[] = {
  118580. 8,
  118581. 7,
  118582. 9,
  118583. 6,
  118584. 10,
  118585. 5,
  118586. 11,
  118587. 4,
  118588. 12,
  118589. 3,
  118590. 13,
  118591. 2,
  118592. 14,
  118593. 1,
  118594. 15,
  118595. 0,
  118596. 16,
  118597. };
  118598. static long _vq_lengthlist__44c6_s_p4_0[] = {
  118599. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9,10,10,
  118600. 10, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,10,
  118601. 11,11, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,
  118602. 10,11,11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  118603. 11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  118604. 10,11,11,11,11, 0, 0, 0, 7, 7, 9, 9,10,10,10,10,
  118605. 11,11,11,11,12,12, 0, 0, 0, 7, 7, 9, 9,10,10,10,
  118606. 10,11,11,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  118607. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 8, 8, 9,
  118608. 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 0, 0,
  118609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118617. 0,
  118618. };
  118619. static float _vq_quantthresh__44c6_s_p4_0[] = {
  118620. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  118621. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  118622. };
  118623. static long _vq_quantmap__44c6_s_p4_0[] = {
  118624. 15, 13, 11, 9, 7, 5, 3, 1,
  118625. 0, 2, 4, 6, 8, 10, 12, 14,
  118626. 16,
  118627. };
  118628. static encode_aux_threshmatch _vq_auxt__44c6_s_p4_0 = {
  118629. _vq_quantthresh__44c6_s_p4_0,
  118630. _vq_quantmap__44c6_s_p4_0,
  118631. 17,
  118632. 17
  118633. };
  118634. static static_codebook _44c6_s_p4_0 = {
  118635. 2, 289,
  118636. _vq_lengthlist__44c6_s_p4_0,
  118637. 1, -529530880, 1611661312, 5, 0,
  118638. _vq_quantlist__44c6_s_p4_0,
  118639. NULL,
  118640. &_vq_auxt__44c6_s_p4_0,
  118641. NULL,
  118642. 0
  118643. };
  118644. static long _vq_quantlist__44c6_s_p5_0[] = {
  118645. 1,
  118646. 0,
  118647. 2,
  118648. };
  118649. static long _vq_lengthlist__44c6_s_p5_0[] = {
  118650. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 6, 6, 9, 9,10,10,
  118651. 10, 9, 4, 6, 6, 9,10, 9,10, 9,10, 6, 9, 9,10,12,
  118652. 11,10,11,11, 7,10, 9,11,12,12,12,12,12, 7,10,10,
  118653. 11,12,12,12,12,12, 6,10,10,10,12,12,11,12,12, 7,
  118654. 9,10,11,12,12,12,12,12, 7,10, 9,12,12,12,12,12,
  118655. 12,
  118656. };
  118657. static float _vq_quantthresh__44c6_s_p5_0[] = {
  118658. -5.5, 5.5,
  118659. };
  118660. static long _vq_quantmap__44c6_s_p5_0[] = {
  118661. 1, 0, 2,
  118662. };
  118663. static encode_aux_threshmatch _vq_auxt__44c6_s_p5_0 = {
  118664. _vq_quantthresh__44c6_s_p5_0,
  118665. _vq_quantmap__44c6_s_p5_0,
  118666. 3,
  118667. 3
  118668. };
  118669. static static_codebook _44c6_s_p5_0 = {
  118670. 4, 81,
  118671. _vq_lengthlist__44c6_s_p5_0,
  118672. 1, -529137664, 1618345984, 2, 0,
  118673. _vq_quantlist__44c6_s_p5_0,
  118674. NULL,
  118675. &_vq_auxt__44c6_s_p5_0,
  118676. NULL,
  118677. 0
  118678. };
  118679. static long _vq_quantlist__44c6_s_p5_1[] = {
  118680. 5,
  118681. 4,
  118682. 6,
  118683. 3,
  118684. 7,
  118685. 2,
  118686. 8,
  118687. 1,
  118688. 9,
  118689. 0,
  118690. 10,
  118691. };
  118692. static long _vq_lengthlist__44c6_s_p5_1[] = {
  118693. 3, 5, 4, 6, 6, 7, 7, 8, 8, 8, 8,11, 4, 4, 6, 6,
  118694. 7, 7, 8, 8, 8, 8,11, 4, 4, 6, 6, 7, 7, 8, 8, 8,
  118695. 8,11, 6, 6, 6, 6, 8, 8, 8, 8, 9, 9,11,11,11, 6,
  118696. 6, 7, 8, 8, 8, 8, 9,11,11,11, 7, 7, 8, 8, 8, 8,
  118697. 8, 8,11,11,11, 7, 7, 8, 8, 8, 8, 8, 8,11,11,11,
  118698. 8, 8, 8, 8, 8, 8, 8, 8,11,11,11,10,10, 8, 8, 8,
  118699. 8, 8, 8,11,11,11,10,10, 8, 8, 8, 8, 8, 8,11,11,
  118700. 11,10,10, 7, 7, 8, 8, 8, 8,
  118701. };
  118702. static float _vq_quantthresh__44c6_s_p5_1[] = {
  118703. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  118704. 3.5, 4.5,
  118705. };
  118706. static long _vq_quantmap__44c6_s_p5_1[] = {
  118707. 9, 7, 5, 3, 1, 0, 2, 4,
  118708. 6, 8, 10,
  118709. };
  118710. static encode_aux_threshmatch _vq_auxt__44c6_s_p5_1 = {
  118711. _vq_quantthresh__44c6_s_p5_1,
  118712. _vq_quantmap__44c6_s_p5_1,
  118713. 11,
  118714. 11
  118715. };
  118716. static static_codebook _44c6_s_p5_1 = {
  118717. 2, 121,
  118718. _vq_lengthlist__44c6_s_p5_1,
  118719. 1, -531365888, 1611661312, 4, 0,
  118720. _vq_quantlist__44c6_s_p5_1,
  118721. NULL,
  118722. &_vq_auxt__44c6_s_p5_1,
  118723. NULL,
  118724. 0
  118725. };
  118726. static long _vq_quantlist__44c6_s_p6_0[] = {
  118727. 6,
  118728. 5,
  118729. 7,
  118730. 4,
  118731. 8,
  118732. 3,
  118733. 9,
  118734. 2,
  118735. 10,
  118736. 1,
  118737. 11,
  118738. 0,
  118739. 12,
  118740. };
  118741. static long _vq_lengthlist__44c6_s_p6_0[] = {
  118742. 1, 4, 4, 6, 6, 8, 8, 8, 8,10, 9,10,10, 6, 5, 5,
  118743. 7, 7, 9, 9, 9, 9,10,10,11,11, 6, 5, 5, 7, 7, 9,
  118744. 9,10, 9,11,10,11,11, 0, 6, 6, 7, 7, 9, 9,10,10,
  118745. 11,11,12,12, 0, 7, 7, 7, 7, 9, 9,10,10,11,11,12,
  118746. 12, 0,11,11, 8, 8,10,10,11,11,12,12,12,12, 0,11,
  118747. 12, 9, 8,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  118748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118752. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118753. };
  118754. static float _vq_quantthresh__44c6_s_p6_0[] = {
  118755. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  118756. 12.5, 17.5, 22.5, 27.5,
  118757. };
  118758. static long _vq_quantmap__44c6_s_p6_0[] = {
  118759. 11, 9, 7, 5, 3, 1, 0, 2,
  118760. 4, 6, 8, 10, 12,
  118761. };
  118762. static encode_aux_threshmatch _vq_auxt__44c6_s_p6_0 = {
  118763. _vq_quantthresh__44c6_s_p6_0,
  118764. _vq_quantmap__44c6_s_p6_0,
  118765. 13,
  118766. 13
  118767. };
  118768. static static_codebook _44c6_s_p6_0 = {
  118769. 2, 169,
  118770. _vq_lengthlist__44c6_s_p6_0,
  118771. 1, -526516224, 1616117760, 4, 0,
  118772. _vq_quantlist__44c6_s_p6_0,
  118773. NULL,
  118774. &_vq_auxt__44c6_s_p6_0,
  118775. NULL,
  118776. 0
  118777. };
  118778. static long _vq_quantlist__44c6_s_p6_1[] = {
  118779. 2,
  118780. 1,
  118781. 3,
  118782. 0,
  118783. 4,
  118784. };
  118785. static long _vq_lengthlist__44c6_s_p6_1[] = {
  118786. 3, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 5, 6,
  118787. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  118788. };
  118789. static float _vq_quantthresh__44c6_s_p6_1[] = {
  118790. -1.5, -0.5, 0.5, 1.5,
  118791. };
  118792. static long _vq_quantmap__44c6_s_p6_1[] = {
  118793. 3, 1, 0, 2, 4,
  118794. };
  118795. static encode_aux_threshmatch _vq_auxt__44c6_s_p6_1 = {
  118796. _vq_quantthresh__44c6_s_p6_1,
  118797. _vq_quantmap__44c6_s_p6_1,
  118798. 5,
  118799. 5
  118800. };
  118801. static static_codebook _44c6_s_p6_1 = {
  118802. 2, 25,
  118803. _vq_lengthlist__44c6_s_p6_1,
  118804. 1, -533725184, 1611661312, 3, 0,
  118805. _vq_quantlist__44c6_s_p6_1,
  118806. NULL,
  118807. &_vq_auxt__44c6_s_p6_1,
  118808. NULL,
  118809. 0
  118810. };
  118811. static long _vq_quantlist__44c6_s_p7_0[] = {
  118812. 6,
  118813. 5,
  118814. 7,
  118815. 4,
  118816. 8,
  118817. 3,
  118818. 9,
  118819. 2,
  118820. 10,
  118821. 1,
  118822. 11,
  118823. 0,
  118824. 12,
  118825. };
  118826. static long _vq_lengthlist__44c6_s_p7_0[] = {
  118827. 1, 4, 4, 6, 6, 8, 8, 8, 8,10,10,11,10, 6, 5, 5,
  118828. 7, 7, 8, 8, 9, 9,10,10,12,11, 6, 5, 5, 7, 7, 8,
  118829. 8, 9, 9,10,10,12,11,21, 7, 7, 7, 7, 9, 9,10,10,
  118830. 11,11,12,12,21, 7, 7, 7, 7, 9, 9,10,10,11,11,12,
  118831. 12,21,12,12, 9, 9,10,10,11,11,11,11,12,12,21,12,
  118832. 12, 9, 9,10,10,11,11,12,12,12,12,21,21,21,11,11,
  118833. 10,10,11,12,12,12,13,13,21,21,21,11,11,10,10,12,
  118834. 12,12,12,13,13,21,21,21,15,15,11,11,12,12,13,13,
  118835. 13,13,21,21,21,15,16,11,11,12,12,13,13,14,14,21,
  118836. 21,21,21,20,13,13,13,13,13,13,14,14,20,20,20,20,
  118837. 20,13,13,13,13,13,13,14,14,
  118838. };
  118839. static float _vq_quantthresh__44c6_s_p7_0[] = {
  118840. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  118841. 27.5, 38.5, 49.5, 60.5,
  118842. };
  118843. static long _vq_quantmap__44c6_s_p7_0[] = {
  118844. 11, 9, 7, 5, 3, 1, 0, 2,
  118845. 4, 6, 8, 10, 12,
  118846. };
  118847. static encode_aux_threshmatch _vq_auxt__44c6_s_p7_0 = {
  118848. _vq_quantthresh__44c6_s_p7_0,
  118849. _vq_quantmap__44c6_s_p7_0,
  118850. 13,
  118851. 13
  118852. };
  118853. static static_codebook _44c6_s_p7_0 = {
  118854. 2, 169,
  118855. _vq_lengthlist__44c6_s_p7_0,
  118856. 1, -523206656, 1618345984, 4, 0,
  118857. _vq_quantlist__44c6_s_p7_0,
  118858. NULL,
  118859. &_vq_auxt__44c6_s_p7_0,
  118860. NULL,
  118861. 0
  118862. };
  118863. static long _vq_quantlist__44c6_s_p7_1[] = {
  118864. 5,
  118865. 4,
  118866. 6,
  118867. 3,
  118868. 7,
  118869. 2,
  118870. 8,
  118871. 1,
  118872. 9,
  118873. 0,
  118874. 10,
  118875. };
  118876. static long _vq_lengthlist__44c6_s_p7_1[] = {
  118877. 3, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 9, 5, 5, 6, 6,
  118878. 7, 7, 7, 7, 8, 7, 8, 5, 5, 6, 6, 7, 7, 7, 7, 7,
  118879. 7, 9, 6, 6, 7, 7, 7, 7, 8, 7, 7, 8, 9, 9, 9, 7,
  118880. 7, 7, 7, 7, 7, 7, 8, 9, 9, 9, 7, 7, 7, 7, 8, 8,
  118881. 8, 8, 9, 9, 9, 7, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9,
  118882. 8, 8, 8, 8, 7, 7, 8, 8, 9, 9, 9, 9, 8, 8, 8, 7,
  118883. 7, 8, 8, 9, 9, 9, 8, 8, 8, 8, 7, 7, 8, 8, 9, 9,
  118884. 9, 8, 8, 7, 7, 7, 7, 8, 8,
  118885. };
  118886. static float _vq_quantthresh__44c6_s_p7_1[] = {
  118887. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  118888. 3.5, 4.5,
  118889. };
  118890. static long _vq_quantmap__44c6_s_p7_1[] = {
  118891. 9, 7, 5, 3, 1, 0, 2, 4,
  118892. 6, 8, 10,
  118893. };
  118894. static encode_aux_threshmatch _vq_auxt__44c6_s_p7_1 = {
  118895. _vq_quantthresh__44c6_s_p7_1,
  118896. _vq_quantmap__44c6_s_p7_1,
  118897. 11,
  118898. 11
  118899. };
  118900. static static_codebook _44c6_s_p7_1 = {
  118901. 2, 121,
  118902. _vq_lengthlist__44c6_s_p7_1,
  118903. 1, -531365888, 1611661312, 4, 0,
  118904. _vq_quantlist__44c6_s_p7_1,
  118905. NULL,
  118906. &_vq_auxt__44c6_s_p7_1,
  118907. NULL,
  118908. 0
  118909. };
  118910. static long _vq_quantlist__44c6_s_p8_0[] = {
  118911. 7,
  118912. 6,
  118913. 8,
  118914. 5,
  118915. 9,
  118916. 4,
  118917. 10,
  118918. 3,
  118919. 11,
  118920. 2,
  118921. 12,
  118922. 1,
  118923. 13,
  118924. 0,
  118925. 14,
  118926. };
  118927. static long _vq_lengthlist__44c6_s_p8_0[] = {
  118928. 1, 4, 4, 7, 7, 8, 8, 7, 7, 8, 7, 9, 8,10, 9, 6,
  118929. 5, 5, 8, 8, 9, 9, 8, 8, 9, 9,11,10,11,10, 6, 5,
  118930. 5, 8, 8, 9, 9, 8, 8, 9, 9,10,10,11,11,18, 8, 8,
  118931. 9, 8,10,10, 9, 9,10,10,10,10,11,10,18, 8, 8, 9,
  118932. 9,10,10, 9, 9,10,10,11,11,12,12,18,12,13, 9,10,
  118933. 10,10, 9,10,10,10,11,11,12,11,18,13,13, 9, 9,10,
  118934. 10,10,10,10,10,11,11,12,12,18,18,18,10,10, 9, 9,
  118935. 11,11,11,11,11,12,12,12,18,18,18,10, 9,10, 9,11,
  118936. 10,11,11,11,11,13,12,18,18,18,14,13,10,10,11,11,
  118937. 12,12,12,12,12,12,18,18,18,14,13,10,10,11,10,12,
  118938. 12,12,12,12,12,18,18,18,18,18,12,12,11,11,12,12,
  118939. 13,13,13,14,18,18,18,18,18,12,12,11,11,12,11,13,
  118940. 13,14,13,18,18,18,18,18,16,16,11,12,12,13,13,13,
  118941. 14,13,18,18,18,18,18,16,15,12,11,12,11,13,11,15,
  118942. 14,
  118943. };
  118944. static float _vq_quantthresh__44c6_s_p8_0[] = {
  118945. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  118946. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  118947. };
  118948. static long _vq_quantmap__44c6_s_p8_0[] = {
  118949. 13, 11, 9, 7, 5, 3, 1, 0,
  118950. 2, 4, 6, 8, 10, 12, 14,
  118951. };
  118952. static encode_aux_threshmatch _vq_auxt__44c6_s_p8_0 = {
  118953. _vq_quantthresh__44c6_s_p8_0,
  118954. _vq_quantmap__44c6_s_p8_0,
  118955. 15,
  118956. 15
  118957. };
  118958. static static_codebook _44c6_s_p8_0 = {
  118959. 2, 225,
  118960. _vq_lengthlist__44c6_s_p8_0,
  118961. 1, -520986624, 1620377600, 4, 0,
  118962. _vq_quantlist__44c6_s_p8_0,
  118963. NULL,
  118964. &_vq_auxt__44c6_s_p8_0,
  118965. NULL,
  118966. 0
  118967. };
  118968. static long _vq_quantlist__44c6_s_p8_1[] = {
  118969. 10,
  118970. 9,
  118971. 11,
  118972. 8,
  118973. 12,
  118974. 7,
  118975. 13,
  118976. 6,
  118977. 14,
  118978. 5,
  118979. 15,
  118980. 4,
  118981. 16,
  118982. 3,
  118983. 17,
  118984. 2,
  118985. 18,
  118986. 1,
  118987. 19,
  118988. 0,
  118989. 20,
  118990. };
  118991. static long _vq_lengthlist__44c6_s_p8_1[] = {
  118992. 3, 5, 5, 6, 6, 7, 7, 7, 7, 8, 7, 8, 8, 8, 8, 8,
  118993. 8, 8, 8, 8, 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8,
  118994. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 6, 6, 7, 7, 8,
  118995. 8, 8, 8, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9,10,
  118996. 7, 7, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  118997. 9, 9, 9, 9,10,11,11, 8, 7, 8, 8, 8, 9, 9, 9, 9,
  118998. 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,11, 8, 8, 8, 8,
  118999. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,
  119000. 11, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  119001. 9, 9, 9,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  119002. 9, 9, 9, 9, 9, 9, 9, 9,11,11,11,11,11, 9, 9, 9,
  119003. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,11,11,11,
  119004. 11,11, 9, 9, 9, 9, 9, 9,10, 9, 9,10, 9,10, 9, 9,
  119005. 10, 9,11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9,10,10,
  119006. 10,10, 9,10,10, 9,10,11,11,11,11,11, 9, 9, 9, 9,
  119007. 10,10,10, 9,10,10,10,10, 9,10,10, 9,11,11,11,11,
  119008. 11,11,11, 9, 9, 9, 9,10,10,10,10, 9,10,10,10,10,
  119009. 10,11,11,11,11,11,11,11,10, 9,10,10,10,10,10,10,
  119010. 10, 9,10, 9,10,10,11,11,11,11,11,11,11,10, 9,10,
  119011. 9,10,10, 9,10,10,10,10,10,10,10,11,11,11,11,11,
  119012. 11,11,10,10,10,10,10,10,10, 9,10,10,10,10,10, 9,
  119013. 11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,
  119014. 10,10,10,10,10,11,11,11,11,11,11,11,11,11,10,10,
  119015. 10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,
  119016. 11,11,11,10,10,10,10,10,10,10,10,10, 9,10,10,11,
  119017. 11,11,11,11,11,11,11,11,10,10,10, 9,10,10,10,10,
  119018. 10,10,10,10,10,11,11,11,11,11,11,11,11,10,11, 9,
  119019. 10,10,10,10,10,10,10,10,10,
  119020. };
  119021. static float _vq_quantthresh__44c6_s_p8_1[] = {
  119022. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  119023. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  119024. 6.5, 7.5, 8.5, 9.5,
  119025. };
  119026. static long _vq_quantmap__44c6_s_p8_1[] = {
  119027. 19, 17, 15, 13, 11, 9, 7, 5,
  119028. 3, 1, 0, 2, 4, 6, 8, 10,
  119029. 12, 14, 16, 18, 20,
  119030. };
  119031. static encode_aux_threshmatch _vq_auxt__44c6_s_p8_1 = {
  119032. _vq_quantthresh__44c6_s_p8_1,
  119033. _vq_quantmap__44c6_s_p8_1,
  119034. 21,
  119035. 21
  119036. };
  119037. static static_codebook _44c6_s_p8_1 = {
  119038. 2, 441,
  119039. _vq_lengthlist__44c6_s_p8_1,
  119040. 1, -529268736, 1611661312, 5, 0,
  119041. _vq_quantlist__44c6_s_p8_1,
  119042. NULL,
  119043. &_vq_auxt__44c6_s_p8_1,
  119044. NULL,
  119045. 0
  119046. };
  119047. static long _vq_quantlist__44c6_s_p9_0[] = {
  119048. 6,
  119049. 5,
  119050. 7,
  119051. 4,
  119052. 8,
  119053. 3,
  119054. 9,
  119055. 2,
  119056. 10,
  119057. 1,
  119058. 11,
  119059. 0,
  119060. 12,
  119061. };
  119062. static long _vq_lengthlist__44c6_s_p9_0[] = {
  119063. 1, 3, 3,11,11,11,11,11,11,11,11,11,11, 4, 7, 7,
  119064. 11,11,11,11,11,11,11,11,11,11, 5, 8, 9,11,11,11,
  119065. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119066. 11,11,11,11,11,10,10,10,10,10,10,10,10,10,10,10,
  119067. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  119068. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  119069. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  119070. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  119071. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  119072. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  119073. 10,10,10,10,10,10,10,10,10,
  119074. };
  119075. static float _vq_quantthresh__44c6_s_p9_0[] = {
  119076. -3503.5, -2866.5, -2229.5, -1592.5, -955.5, -318.5, 318.5, 955.5,
  119077. 1592.5, 2229.5, 2866.5, 3503.5,
  119078. };
  119079. static long _vq_quantmap__44c6_s_p9_0[] = {
  119080. 11, 9, 7, 5, 3, 1, 0, 2,
  119081. 4, 6, 8, 10, 12,
  119082. };
  119083. static encode_aux_threshmatch _vq_auxt__44c6_s_p9_0 = {
  119084. _vq_quantthresh__44c6_s_p9_0,
  119085. _vq_quantmap__44c6_s_p9_0,
  119086. 13,
  119087. 13
  119088. };
  119089. static static_codebook _44c6_s_p9_0 = {
  119090. 2, 169,
  119091. _vq_lengthlist__44c6_s_p9_0,
  119092. 1, -511845376, 1630791680, 4, 0,
  119093. _vq_quantlist__44c6_s_p9_0,
  119094. NULL,
  119095. &_vq_auxt__44c6_s_p9_0,
  119096. NULL,
  119097. 0
  119098. };
  119099. static long _vq_quantlist__44c6_s_p9_1[] = {
  119100. 6,
  119101. 5,
  119102. 7,
  119103. 4,
  119104. 8,
  119105. 3,
  119106. 9,
  119107. 2,
  119108. 10,
  119109. 1,
  119110. 11,
  119111. 0,
  119112. 12,
  119113. };
  119114. static long _vq_lengthlist__44c6_s_p9_1[] = {
  119115. 1, 4, 4, 7, 7, 7, 7, 7, 6, 8, 8, 8, 8, 6, 6, 6,
  119116. 8, 8, 8, 8, 8, 7, 9, 8,10,10, 5, 6, 6, 8, 8, 9,
  119117. 9, 8, 8,10,10,10,10,16, 9, 9, 9, 9, 9, 9, 9, 8,
  119118. 10, 9,11,11,16, 8, 9, 9, 9, 9, 9, 9, 9,10,10,11,
  119119. 11,16,13,13, 9, 9,10, 9, 9,10,11,11,11,12,16,13,
  119120. 14, 9, 8,10, 8, 9, 9,10,10,12,11,16,14,16, 9, 9,
  119121. 9, 9,11,11,12,11,12,11,16,16,16, 9, 7, 9, 6,11,
  119122. 11,11,10,11,11,16,16,16,11,12, 9,10,11,11,12,11,
  119123. 13,13,16,16,16,12,11,10, 7,12,10,12,12,12,12,16,
  119124. 16,15,16,16,10,11,10,11,13,13,14,12,16,16,16,15,
  119125. 15,12,10,11,11,13,11,12,13,
  119126. };
  119127. static float _vq_quantthresh__44c6_s_p9_1[] = {
  119128. -269.5, -220.5, -171.5, -122.5, -73.5, -24.5, 24.5, 73.5,
  119129. 122.5, 171.5, 220.5, 269.5,
  119130. };
  119131. static long _vq_quantmap__44c6_s_p9_1[] = {
  119132. 11, 9, 7, 5, 3, 1, 0, 2,
  119133. 4, 6, 8, 10, 12,
  119134. };
  119135. static encode_aux_threshmatch _vq_auxt__44c6_s_p9_1 = {
  119136. _vq_quantthresh__44c6_s_p9_1,
  119137. _vq_quantmap__44c6_s_p9_1,
  119138. 13,
  119139. 13
  119140. };
  119141. static static_codebook _44c6_s_p9_1 = {
  119142. 2, 169,
  119143. _vq_lengthlist__44c6_s_p9_1,
  119144. 1, -518889472, 1622704128, 4, 0,
  119145. _vq_quantlist__44c6_s_p9_1,
  119146. NULL,
  119147. &_vq_auxt__44c6_s_p9_1,
  119148. NULL,
  119149. 0
  119150. };
  119151. static long _vq_quantlist__44c6_s_p9_2[] = {
  119152. 24,
  119153. 23,
  119154. 25,
  119155. 22,
  119156. 26,
  119157. 21,
  119158. 27,
  119159. 20,
  119160. 28,
  119161. 19,
  119162. 29,
  119163. 18,
  119164. 30,
  119165. 17,
  119166. 31,
  119167. 16,
  119168. 32,
  119169. 15,
  119170. 33,
  119171. 14,
  119172. 34,
  119173. 13,
  119174. 35,
  119175. 12,
  119176. 36,
  119177. 11,
  119178. 37,
  119179. 10,
  119180. 38,
  119181. 9,
  119182. 39,
  119183. 8,
  119184. 40,
  119185. 7,
  119186. 41,
  119187. 6,
  119188. 42,
  119189. 5,
  119190. 43,
  119191. 4,
  119192. 44,
  119193. 3,
  119194. 45,
  119195. 2,
  119196. 46,
  119197. 1,
  119198. 47,
  119199. 0,
  119200. 48,
  119201. };
  119202. static long _vq_lengthlist__44c6_s_p9_2[] = {
  119203. 2, 4, 3, 4, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  119204. 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  119205. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  119206. 7,
  119207. };
  119208. static float _vq_quantthresh__44c6_s_p9_2[] = {
  119209. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  119210. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  119211. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  119212. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  119213. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  119214. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  119215. };
  119216. static long _vq_quantmap__44c6_s_p9_2[] = {
  119217. 47, 45, 43, 41, 39, 37, 35, 33,
  119218. 31, 29, 27, 25, 23, 21, 19, 17,
  119219. 15, 13, 11, 9, 7, 5, 3, 1,
  119220. 0, 2, 4, 6, 8, 10, 12, 14,
  119221. 16, 18, 20, 22, 24, 26, 28, 30,
  119222. 32, 34, 36, 38, 40, 42, 44, 46,
  119223. 48,
  119224. };
  119225. static encode_aux_threshmatch _vq_auxt__44c6_s_p9_2 = {
  119226. _vq_quantthresh__44c6_s_p9_2,
  119227. _vq_quantmap__44c6_s_p9_2,
  119228. 49,
  119229. 49
  119230. };
  119231. static static_codebook _44c6_s_p9_2 = {
  119232. 1, 49,
  119233. _vq_lengthlist__44c6_s_p9_2,
  119234. 1, -526909440, 1611661312, 6, 0,
  119235. _vq_quantlist__44c6_s_p9_2,
  119236. NULL,
  119237. &_vq_auxt__44c6_s_p9_2,
  119238. NULL,
  119239. 0
  119240. };
  119241. static long _huff_lengthlist__44c6_s_short[] = {
  119242. 3, 9,11,11,13,14,19,17,17,19, 5, 4, 5, 8,10,10,
  119243. 13,16,18,19, 7, 4, 4, 5, 8, 9,12,14,17,19, 8, 6,
  119244. 5, 5, 7, 7,10,13,16,18,10, 8, 7, 6, 5, 5, 8,11,
  119245. 17,19,11, 9, 7, 7, 5, 4, 5, 8,17,19,13,11, 8, 7,
  119246. 7, 5, 5, 7,16,18,14,13, 8, 6, 6, 5, 5, 7,16,18,
  119247. 18,16,10, 8, 8, 7, 7, 9,16,18,18,18,12,10,10, 9,
  119248. 9,10,17,18,
  119249. };
  119250. static static_codebook _huff_book__44c6_s_short = {
  119251. 2, 100,
  119252. _huff_lengthlist__44c6_s_short,
  119253. 0, 0, 0, 0, 0,
  119254. NULL,
  119255. NULL,
  119256. NULL,
  119257. NULL,
  119258. 0
  119259. };
  119260. static long _huff_lengthlist__44c7_s_long[] = {
  119261. 3, 8,11,13,15,14,14,13,15,14, 6, 4, 5, 7, 9,10,
  119262. 11,11,14,13,10, 4, 3, 5, 7, 8, 9,10,13,13,12, 7,
  119263. 4, 4, 5, 6, 8, 9,12,14,13, 9, 6, 5, 5, 6, 8, 9,
  119264. 12,14,12, 9, 7, 6, 5, 5, 6, 8,11,11,12,11, 9, 8,
  119265. 7, 6, 6, 7,10,11,13,11,10, 9, 8, 7, 6, 6, 9,11,
  119266. 13,13,12,12,12,10, 9, 8, 9,11,12,14,15,15,14,12,
  119267. 11,10,10,12,
  119268. };
  119269. static static_codebook _huff_book__44c7_s_long = {
  119270. 2, 100,
  119271. _huff_lengthlist__44c7_s_long,
  119272. 0, 0, 0, 0, 0,
  119273. NULL,
  119274. NULL,
  119275. NULL,
  119276. NULL,
  119277. 0
  119278. };
  119279. static long _vq_quantlist__44c7_s_p1_0[] = {
  119280. 1,
  119281. 0,
  119282. 2,
  119283. };
  119284. static long _vq_lengthlist__44c7_s_p1_0[] = {
  119285. 1, 5, 5, 0, 5, 5, 0, 5, 5, 5, 8, 7, 0, 9, 9, 0,
  119286. 9, 8, 5, 7, 8, 0, 9, 9, 0, 8, 9, 0, 0, 0, 0, 0,
  119287. 0, 0, 0, 0, 5, 9, 9, 0, 8, 8, 0, 8, 8, 5, 8, 9,
  119288. 0, 8, 8, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
  119289. 9, 9, 0, 8, 8, 0, 8, 8, 5, 8, 9, 0, 8, 8, 0, 8,
  119290. 8,
  119291. };
  119292. static float _vq_quantthresh__44c7_s_p1_0[] = {
  119293. -0.5, 0.5,
  119294. };
  119295. static long _vq_quantmap__44c7_s_p1_0[] = {
  119296. 1, 0, 2,
  119297. };
  119298. static encode_aux_threshmatch _vq_auxt__44c7_s_p1_0 = {
  119299. _vq_quantthresh__44c7_s_p1_0,
  119300. _vq_quantmap__44c7_s_p1_0,
  119301. 3,
  119302. 3
  119303. };
  119304. static static_codebook _44c7_s_p1_0 = {
  119305. 4, 81,
  119306. _vq_lengthlist__44c7_s_p1_0,
  119307. 1, -535822336, 1611661312, 2, 0,
  119308. _vq_quantlist__44c7_s_p1_0,
  119309. NULL,
  119310. &_vq_auxt__44c7_s_p1_0,
  119311. NULL,
  119312. 0
  119313. };
  119314. static long _vq_quantlist__44c7_s_p2_0[] = {
  119315. 2,
  119316. 1,
  119317. 3,
  119318. 0,
  119319. 4,
  119320. };
  119321. static long _vq_lengthlist__44c7_s_p2_0[] = {
  119322. 3, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0,
  119323. 7, 7, 9, 9, 0, 0, 0, 9, 9, 5, 7, 7, 9, 9, 0, 8,
  119324. 8,10,10, 0, 8, 7,10, 9, 0,10,10,11,11, 0, 0, 0,
  119325. 11,11, 5, 7, 7, 9, 9, 0, 8, 8,10,10, 0, 7, 8, 9,
  119326. 10, 0,10,10,11,11, 0, 0, 0,11,11, 8, 9, 9,11,10,
  119327. 0,11,11,12,12, 0,11,10,12,12, 0,13,14,14,14, 0,
  119328. 0, 0,14,13, 8, 9, 9,10,11, 0,11,11,12,12, 0,10,
  119329. 11,12,12, 0,13,13,14,14, 0, 0, 0,13,14, 0, 0, 0,
  119330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119331. 0, 0, 0, 0, 0, 0, 5, 8, 7,11,10, 0, 7, 7,10,10,
  119332. 0, 7, 7,10,10, 0, 9, 9,11,10, 0, 0, 0,11,11, 5,
  119333. 7, 8,10,11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9,
  119334. 9,10,11, 0, 0, 0,11,11, 8,10, 9,12,12, 0,10,10,
  119335. 12,12, 0,10,10,12,12, 0,12,12,13,13, 0, 0, 0,13,
  119336. 13, 8, 9,10,12,12, 0,10,10,12,12, 0,10,10,11,12,
  119337. 0,12,12,13,13, 0, 0, 0,13,13, 0, 0, 0, 0, 0, 0,
  119338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119339. 0, 0, 0, 5, 8, 8,11,11, 0, 7, 7,10,10, 0, 7, 7,
  119340. 10,10, 0, 9, 9,10,11, 0, 0, 0,11,10, 5, 8, 8,10,
  119341. 11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9, 9,11,10,
  119342. 0, 0, 0,10,11, 9,10,10,12,12, 0,10,10,12,12, 0,
  119343. 10,10,12,12, 0,12,13,13,13, 0, 0, 0,13,12, 9,10,
  119344. 10,12,12, 0,10,10,12,12, 0,10,10,12,12, 0,13,12,
  119345. 13,13, 0, 0, 0,12,13, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119347. 7,10,10,14,13, 0, 9, 9,12,12, 0, 9, 9,12,12, 0,
  119348. 10,10,12,12, 0, 0, 0,12,12, 7,10,10,13,14, 0, 9,
  119349. 9,12,13, 0, 9, 9,12,12, 0,10,10,12,12, 0, 0, 0,
  119350. 12,12, 9,11,11,14,13, 0,11,10,13,12, 0,11,11,13,
  119351. 13, 0,12,12,13,13, 0, 0, 0,13,13, 9,11,11,13,14,
  119352. 0,10,11,12,13, 0,11,11,13,13, 0,12,12,13,13, 0,
  119353. 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
  119358. 11,11,14,14, 0,10,11,13,13, 0,11,10,13,13, 0,12,
  119359. 12,13,13, 0, 0, 0,13,12, 9,11,11,14,14, 0,11,10,
  119360. 13,13, 0,10,11,13,13, 0,12,12,14,13, 0, 0, 0,13,
  119361. 13,
  119362. };
  119363. static float _vq_quantthresh__44c7_s_p2_0[] = {
  119364. -1.5, -0.5, 0.5, 1.5,
  119365. };
  119366. static long _vq_quantmap__44c7_s_p2_0[] = {
  119367. 3, 1, 0, 2, 4,
  119368. };
  119369. static encode_aux_threshmatch _vq_auxt__44c7_s_p2_0 = {
  119370. _vq_quantthresh__44c7_s_p2_0,
  119371. _vq_quantmap__44c7_s_p2_0,
  119372. 5,
  119373. 5
  119374. };
  119375. static static_codebook _44c7_s_p2_0 = {
  119376. 4, 625,
  119377. _vq_lengthlist__44c7_s_p2_0,
  119378. 1, -533725184, 1611661312, 3, 0,
  119379. _vq_quantlist__44c7_s_p2_0,
  119380. NULL,
  119381. &_vq_auxt__44c7_s_p2_0,
  119382. NULL,
  119383. 0
  119384. };
  119385. static long _vq_quantlist__44c7_s_p3_0[] = {
  119386. 4,
  119387. 3,
  119388. 5,
  119389. 2,
  119390. 6,
  119391. 1,
  119392. 7,
  119393. 0,
  119394. 8,
  119395. };
  119396. static long _vq_lengthlist__44c7_s_p3_0[] = {
  119397. 2, 4, 4, 5, 5, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  119398. 9, 9, 0, 4, 4, 6, 6, 7, 7, 9, 9, 0, 5, 5, 6, 6,
  119399. 8, 8,10,10, 0, 0, 0, 6, 6, 8, 8,10,10, 0, 0, 0,
  119400. 7, 7, 9, 9,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0,
  119401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119402. 0,
  119403. };
  119404. static float _vq_quantthresh__44c7_s_p3_0[] = {
  119405. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  119406. };
  119407. static long _vq_quantmap__44c7_s_p3_0[] = {
  119408. 7, 5, 3, 1, 0, 2, 4, 6,
  119409. 8,
  119410. };
  119411. static encode_aux_threshmatch _vq_auxt__44c7_s_p3_0 = {
  119412. _vq_quantthresh__44c7_s_p3_0,
  119413. _vq_quantmap__44c7_s_p3_0,
  119414. 9,
  119415. 9
  119416. };
  119417. static static_codebook _44c7_s_p3_0 = {
  119418. 2, 81,
  119419. _vq_lengthlist__44c7_s_p3_0,
  119420. 1, -531628032, 1611661312, 4, 0,
  119421. _vq_quantlist__44c7_s_p3_0,
  119422. NULL,
  119423. &_vq_auxt__44c7_s_p3_0,
  119424. NULL,
  119425. 0
  119426. };
  119427. static long _vq_quantlist__44c7_s_p4_0[] = {
  119428. 8,
  119429. 7,
  119430. 9,
  119431. 6,
  119432. 10,
  119433. 5,
  119434. 11,
  119435. 4,
  119436. 12,
  119437. 3,
  119438. 13,
  119439. 2,
  119440. 14,
  119441. 1,
  119442. 15,
  119443. 0,
  119444. 16,
  119445. };
  119446. static long _vq_lengthlist__44c7_s_p4_0[] = {
  119447. 3, 4, 4, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  119448. 11, 0, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,
  119449. 12,12, 0, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,
  119450. 11,12,12, 0, 5, 5, 6, 6, 8, 8, 9, 9, 9, 9,10,10,
  119451. 11,12,12,12, 0, 0, 0, 6, 6, 8, 7, 9, 9, 9, 9,10,
  119452. 10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,10,
  119453. 11,11,12,12,13,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,
  119454. 10,11,11,12,12,12,13, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  119455. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 8, 8, 9,
  119456. 9,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 0, 0,
  119457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119465. 0,
  119466. };
  119467. static float _vq_quantthresh__44c7_s_p4_0[] = {
  119468. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  119469. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  119470. };
  119471. static long _vq_quantmap__44c7_s_p4_0[] = {
  119472. 15, 13, 11, 9, 7, 5, 3, 1,
  119473. 0, 2, 4, 6, 8, 10, 12, 14,
  119474. 16,
  119475. };
  119476. static encode_aux_threshmatch _vq_auxt__44c7_s_p4_0 = {
  119477. _vq_quantthresh__44c7_s_p4_0,
  119478. _vq_quantmap__44c7_s_p4_0,
  119479. 17,
  119480. 17
  119481. };
  119482. static static_codebook _44c7_s_p4_0 = {
  119483. 2, 289,
  119484. _vq_lengthlist__44c7_s_p4_0,
  119485. 1, -529530880, 1611661312, 5, 0,
  119486. _vq_quantlist__44c7_s_p4_0,
  119487. NULL,
  119488. &_vq_auxt__44c7_s_p4_0,
  119489. NULL,
  119490. 0
  119491. };
  119492. static long _vq_quantlist__44c7_s_p5_0[] = {
  119493. 1,
  119494. 0,
  119495. 2,
  119496. };
  119497. static long _vq_lengthlist__44c7_s_p5_0[] = {
  119498. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 6, 7,10,10,10,10,
  119499. 10, 9, 4, 6, 6,10,10,10,10, 9,10, 5,10,10, 9,11,
  119500. 12,10,11,12, 7,10,10,11,12,12,12,12,12, 7,10,10,
  119501. 11,12,12,12,12,12, 6,10,10,10,12,12,11,12,12, 7,
  119502. 10,10,12,12,12,12,11,12, 7,10,10,11,12,12,12,12,
  119503. 12,
  119504. };
  119505. static float _vq_quantthresh__44c7_s_p5_0[] = {
  119506. -5.5, 5.5,
  119507. };
  119508. static long _vq_quantmap__44c7_s_p5_0[] = {
  119509. 1, 0, 2,
  119510. };
  119511. static encode_aux_threshmatch _vq_auxt__44c7_s_p5_0 = {
  119512. _vq_quantthresh__44c7_s_p5_0,
  119513. _vq_quantmap__44c7_s_p5_0,
  119514. 3,
  119515. 3
  119516. };
  119517. static static_codebook _44c7_s_p5_0 = {
  119518. 4, 81,
  119519. _vq_lengthlist__44c7_s_p5_0,
  119520. 1, -529137664, 1618345984, 2, 0,
  119521. _vq_quantlist__44c7_s_p5_0,
  119522. NULL,
  119523. &_vq_auxt__44c7_s_p5_0,
  119524. NULL,
  119525. 0
  119526. };
  119527. static long _vq_quantlist__44c7_s_p5_1[] = {
  119528. 5,
  119529. 4,
  119530. 6,
  119531. 3,
  119532. 7,
  119533. 2,
  119534. 8,
  119535. 1,
  119536. 9,
  119537. 0,
  119538. 10,
  119539. };
  119540. static long _vq_lengthlist__44c7_s_p5_1[] = {
  119541. 3, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8,11, 4, 4, 6, 6,
  119542. 7, 7, 8, 8, 9, 9,11, 4, 4, 6, 6, 7, 7, 8, 8, 9,
  119543. 9,12, 5, 5, 6, 6, 7, 7, 9, 9, 9, 9,12,12,12, 6,
  119544. 6, 7, 7, 9, 9, 9, 9,11,11,11, 7, 7, 7, 7, 8, 8,
  119545. 9, 9,11,11,11, 7, 7, 7, 7, 8, 8, 9, 9,11,11,11,
  119546. 7, 7, 8, 8, 8, 8, 9, 9,11,11,11,11,11, 8, 8, 8,
  119547. 8, 8, 9,11,11,11,11,11, 8, 8, 8, 8, 8, 8,11,11,
  119548. 11,11,11, 7, 7, 8, 8, 8, 8,
  119549. };
  119550. static float _vq_quantthresh__44c7_s_p5_1[] = {
  119551. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  119552. 3.5, 4.5,
  119553. };
  119554. static long _vq_quantmap__44c7_s_p5_1[] = {
  119555. 9, 7, 5, 3, 1, 0, 2, 4,
  119556. 6, 8, 10,
  119557. };
  119558. static encode_aux_threshmatch _vq_auxt__44c7_s_p5_1 = {
  119559. _vq_quantthresh__44c7_s_p5_1,
  119560. _vq_quantmap__44c7_s_p5_1,
  119561. 11,
  119562. 11
  119563. };
  119564. static static_codebook _44c7_s_p5_1 = {
  119565. 2, 121,
  119566. _vq_lengthlist__44c7_s_p5_1,
  119567. 1, -531365888, 1611661312, 4, 0,
  119568. _vq_quantlist__44c7_s_p5_1,
  119569. NULL,
  119570. &_vq_auxt__44c7_s_p5_1,
  119571. NULL,
  119572. 0
  119573. };
  119574. static long _vq_quantlist__44c7_s_p6_0[] = {
  119575. 6,
  119576. 5,
  119577. 7,
  119578. 4,
  119579. 8,
  119580. 3,
  119581. 9,
  119582. 2,
  119583. 10,
  119584. 1,
  119585. 11,
  119586. 0,
  119587. 12,
  119588. };
  119589. static long _vq_lengthlist__44c7_s_p6_0[] = {
  119590. 1, 4, 4, 6, 6, 7, 7, 8, 7, 9, 8,10,10, 6, 5, 5,
  119591. 7, 7, 8, 8, 9, 9, 9,10,11,11, 7, 5, 5, 7, 7, 8,
  119592. 8, 9, 9,10,10,11,11, 0, 7, 7, 7, 7, 9, 8, 9, 9,
  119593. 10,10,11,11, 0, 8, 8, 7, 7, 8, 9, 9, 9,10,10,11,
  119594. 11, 0,11,11, 9, 9,10,10,11,10,11,11,12,12, 0,12,
  119595. 12, 9, 9,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0,
  119596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119600. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119601. };
  119602. static float _vq_quantthresh__44c7_s_p6_0[] = {
  119603. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  119604. 12.5, 17.5, 22.5, 27.5,
  119605. };
  119606. static long _vq_quantmap__44c7_s_p6_0[] = {
  119607. 11, 9, 7, 5, 3, 1, 0, 2,
  119608. 4, 6, 8, 10, 12,
  119609. };
  119610. static encode_aux_threshmatch _vq_auxt__44c7_s_p6_0 = {
  119611. _vq_quantthresh__44c7_s_p6_0,
  119612. _vq_quantmap__44c7_s_p6_0,
  119613. 13,
  119614. 13
  119615. };
  119616. static static_codebook _44c7_s_p6_0 = {
  119617. 2, 169,
  119618. _vq_lengthlist__44c7_s_p6_0,
  119619. 1, -526516224, 1616117760, 4, 0,
  119620. _vq_quantlist__44c7_s_p6_0,
  119621. NULL,
  119622. &_vq_auxt__44c7_s_p6_0,
  119623. NULL,
  119624. 0
  119625. };
  119626. static long _vq_quantlist__44c7_s_p6_1[] = {
  119627. 2,
  119628. 1,
  119629. 3,
  119630. 0,
  119631. 4,
  119632. };
  119633. static long _vq_lengthlist__44c7_s_p6_1[] = {
  119634. 3, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 5, 6,
  119635. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  119636. };
  119637. static float _vq_quantthresh__44c7_s_p6_1[] = {
  119638. -1.5, -0.5, 0.5, 1.5,
  119639. };
  119640. static long _vq_quantmap__44c7_s_p6_1[] = {
  119641. 3, 1, 0, 2, 4,
  119642. };
  119643. static encode_aux_threshmatch _vq_auxt__44c7_s_p6_1 = {
  119644. _vq_quantthresh__44c7_s_p6_1,
  119645. _vq_quantmap__44c7_s_p6_1,
  119646. 5,
  119647. 5
  119648. };
  119649. static static_codebook _44c7_s_p6_1 = {
  119650. 2, 25,
  119651. _vq_lengthlist__44c7_s_p6_1,
  119652. 1, -533725184, 1611661312, 3, 0,
  119653. _vq_quantlist__44c7_s_p6_1,
  119654. NULL,
  119655. &_vq_auxt__44c7_s_p6_1,
  119656. NULL,
  119657. 0
  119658. };
  119659. static long _vq_quantlist__44c7_s_p7_0[] = {
  119660. 6,
  119661. 5,
  119662. 7,
  119663. 4,
  119664. 8,
  119665. 3,
  119666. 9,
  119667. 2,
  119668. 10,
  119669. 1,
  119670. 11,
  119671. 0,
  119672. 12,
  119673. };
  119674. static long _vq_lengthlist__44c7_s_p7_0[] = {
  119675. 1, 4, 4, 6, 6, 7, 8, 9, 9,10,10,12,11, 6, 5, 5,
  119676. 7, 7, 8, 8, 9,10,11,11,12,12, 7, 5, 5, 7, 7, 8,
  119677. 8,10,10,11,11,12,12,20, 7, 7, 7, 7, 8, 9,10,10,
  119678. 11,11,12,13,20, 7, 7, 7, 7, 9, 9,10,10,11,12,13,
  119679. 13,20,11,11, 8, 8, 9, 9,11,11,12,12,13,13,20,11,
  119680. 11, 8, 8, 9, 9,11,11,12,12,13,13,20,20,20,10,10,
  119681. 10,10,12,12,13,13,13,13,20,20,20,10,10,10,10,12,
  119682. 12,13,13,13,14,20,20,20,14,14,11,11,12,12,13,13,
  119683. 14,14,20,20,20,14,14,11,11,12,12,13,13,14,14,20,
  119684. 20,20,20,19,13,13,13,13,14,14,15,14,19,19,19,19,
  119685. 19,13,13,13,13,14,14,15,15,
  119686. };
  119687. static float _vq_quantthresh__44c7_s_p7_0[] = {
  119688. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  119689. 27.5, 38.5, 49.5, 60.5,
  119690. };
  119691. static long _vq_quantmap__44c7_s_p7_0[] = {
  119692. 11, 9, 7, 5, 3, 1, 0, 2,
  119693. 4, 6, 8, 10, 12,
  119694. };
  119695. static encode_aux_threshmatch _vq_auxt__44c7_s_p7_0 = {
  119696. _vq_quantthresh__44c7_s_p7_0,
  119697. _vq_quantmap__44c7_s_p7_0,
  119698. 13,
  119699. 13
  119700. };
  119701. static static_codebook _44c7_s_p7_0 = {
  119702. 2, 169,
  119703. _vq_lengthlist__44c7_s_p7_0,
  119704. 1, -523206656, 1618345984, 4, 0,
  119705. _vq_quantlist__44c7_s_p7_0,
  119706. NULL,
  119707. &_vq_auxt__44c7_s_p7_0,
  119708. NULL,
  119709. 0
  119710. };
  119711. static long _vq_quantlist__44c7_s_p7_1[] = {
  119712. 5,
  119713. 4,
  119714. 6,
  119715. 3,
  119716. 7,
  119717. 2,
  119718. 8,
  119719. 1,
  119720. 9,
  119721. 0,
  119722. 10,
  119723. };
  119724. static long _vq_lengthlist__44c7_s_p7_1[] = {
  119725. 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 8, 6, 6, 7, 7,
  119726. 7, 7, 7, 7, 7, 7, 8, 6, 6, 6, 7, 7, 7, 7, 7, 7,
  119727. 7, 8, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7,
  119728. 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7,
  119729. 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
  119730. 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  119731. 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 8, 8,
  119732. 8, 8, 8, 7, 7, 7, 7, 7, 7,
  119733. };
  119734. static float _vq_quantthresh__44c7_s_p7_1[] = {
  119735. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  119736. 3.5, 4.5,
  119737. };
  119738. static long _vq_quantmap__44c7_s_p7_1[] = {
  119739. 9, 7, 5, 3, 1, 0, 2, 4,
  119740. 6, 8, 10,
  119741. };
  119742. static encode_aux_threshmatch _vq_auxt__44c7_s_p7_1 = {
  119743. _vq_quantthresh__44c7_s_p7_1,
  119744. _vq_quantmap__44c7_s_p7_1,
  119745. 11,
  119746. 11
  119747. };
  119748. static static_codebook _44c7_s_p7_1 = {
  119749. 2, 121,
  119750. _vq_lengthlist__44c7_s_p7_1,
  119751. 1, -531365888, 1611661312, 4, 0,
  119752. _vq_quantlist__44c7_s_p7_1,
  119753. NULL,
  119754. &_vq_auxt__44c7_s_p7_1,
  119755. NULL,
  119756. 0
  119757. };
  119758. static long _vq_quantlist__44c7_s_p8_0[] = {
  119759. 7,
  119760. 6,
  119761. 8,
  119762. 5,
  119763. 9,
  119764. 4,
  119765. 10,
  119766. 3,
  119767. 11,
  119768. 2,
  119769. 12,
  119770. 1,
  119771. 13,
  119772. 0,
  119773. 14,
  119774. };
  119775. static long _vq_lengthlist__44c7_s_p8_0[] = {
  119776. 1, 4, 4, 7, 7, 8, 8, 8, 7, 9, 8, 9, 9,10,10, 6,
  119777. 5, 5, 7, 7, 9, 9, 8, 8,10, 9,11,10,12,11, 6, 5,
  119778. 5, 8, 7, 9, 9, 8, 8,10,10,11,11,12,11,19, 8, 8,
  119779. 8, 8,10,10, 9, 9,10,10,11,11,12,11,19, 8, 8, 8,
  119780. 8,10,10, 9, 9,10,10,11,11,12,12,19,12,12, 9, 9,
  119781. 10,10, 9,10,10,10,11,11,12,12,19,12,12, 9, 9,10,
  119782. 10,10,10,10,10,12,12,12,12,19,19,19, 9, 9, 9, 9,
  119783. 11,10,11,11,12,11,13,13,19,19,19, 9, 9, 9, 9,11,
  119784. 10,11,11,11,12,13,13,19,19,19,13,13,10,10,11,11,
  119785. 12,12,12,12,13,12,19,19,19,14,13,10,10,11,11,12,
  119786. 12,12,13,13,13,19,19,19,19,19,12,12,12,11,12,13,
  119787. 14,13,13,13,19,19,19,19,19,12,12,12,11,12,12,13,
  119788. 14,13,14,19,19,19,19,19,16,16,12,13,12,13,13,14,
  119789. 15,14,19,18,18,18,18,16,15,12,11,12,11,14,12,14,
  119790. 14,
  119791. };
  119792. static float _vq_quantthresh__44c7_s_p8_0[] = {
  119793. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  119794. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  119795. };
  119796. static long _vq_quantmap__44c7_s_p8_0[] = {
  119797. 13, 11, 9, 7, 5, 3, 1, 0,
  119798. 2, 4, 6, 8, 10, 12, 14,
  119799. };
  119800. static encode_aux_threshmatch _vq_auxt__44c7_s_p8_0 = {
  119801. _vq_quantthresh__44c7_s_p8_0,
  119802. _vq_quantmap__44c7_s_p8_0,
  119803. 15,
  119804. 15
  119805. };
  119806. static static_codebook _44c7_s_p8_0 = {
  119807. 2, 225,
  119808. _vq_lengthlist__44c7_s_p8_0,
  119809. 1, -520986624, 1620377600, 4, 0,
  119810. _vq_quantlist__44c7_s_p8_0,
  119811. NULL,
  119812. &_vq_auxt__44c7_s_p8_0,
  119813. NULL,
  119814. 0
  119815. };
  119816. static long _vq_quantlist__44c7_s_p8_1[] = {
  119817. 10,
  119818. 9,
  119819. 11,
  119820. 8,
  119821. 12,
  119822. 7,
  119823. 13,
  119824. 6,
  119825. 14,
  119826. 5,
  119827. 15,
  119828. 4,
  119829. 16,
  119830. 3,
  119831. 17,
  119832. 2,
  119833. 18,
  119834. 1,
  119835. 19,
  119836. 0,
  119837. 20,
  119838. };
  119839. static long _vq_lengthlist__44c7_s_p8_1[] = {
  119840. 3, 5, 5, 7, 6, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  119841. 8, 8, 8, 8, 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  119842. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 6, 6, 7, 7, 8,
  119843. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,
  119844. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  119845. 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  119846. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 9,
  119847. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,
  119848. 10, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  119849. 9, 9, 9,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  119850. 9, 9, 9, 9, 9, 9, 9, 9,10,11,10,10,10, 9, 9, 9,
  119851. 9, 9, 9, 9, 9, 9, 9,10, 9, 9,10, 9, 9,10,11,10,
  119852. 11,10, 9, 9, 9, 9, 9, 9, 9,10,10,10, 9,10, 9, 9,
  119853. 9, 9,11,10,11,10,10, 9, 9, 9, 9, 9, 9,10, 9, 9,
  119854. 10, 9, 9,10, 9, 9,10,11,10,10,11,10, 9, 9, 9, 9,
  119855. 9,10,10, 9,10,10,10,10, 9,10,10,10,10,10,10,11,
  119856. 11,11,10, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,
  119857. 10,10,10,11,11,10,10,10,10,10,10,10,10,10,10,10,
  119858. 10, 9,10,10, 9,10,11,11,10,11,10,11,10, 9,10,10,
  119859. 9,10,10,10,10,10,10,10,10,10,10,11,11,11,11,10,
  119860. 11,11,10,10,10,10,10,10, 9,10, 9,10,10, 9,10, 9,
  119861. 10,10,10,11,10,11,10,11,11,10,10,10,10,10,10, 9,
  119862. 10,10,10,10,10,10,10,11,10,10,10,10,10,10,10,10,
  119863. 10,10,10,10,10,10,10,10,10,10,10,10,10,11,10,11,
  119864. 11,10,10,10,10, 9, 9,10,10, 9, 9,10, 9,10,10,10,
  119865. 10,11,11,10,10,10,10,10,10,10, 9, 9,10,10,10, 9,
  119866. 9,10,10,10,10,10,11,10,11,10,10,10,10,10,10, 9,
  119867. 10,10,10,10,10,10,10,10,10,
  119868. };
  119869. static float _vq_quantthresh__44c7_s_p8_1[] = {
  119870. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  119871. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  119872. 6.5, 7.5, 8.5, 9.5,
  119873. };
  119874. static long _vq_quantmap__44c7_s_p8_1[] = {
  119875. 19, 17, 15, 13, 11, 9, 7, 5,
  119876. 3, 1, 0, 2, 4, 6, 8, 10,
  119877. 12, 14, 16, 18, 20,
  119878. };
  119879. static encode_aux_threshmatch _vq_auxt__44c7_s_p8_1 = {
  119880. _vq_quantthresh__44c7_s_p8_1,
  119881. _vq_quantmap__44c7_s_p8_1,
  119882. 21,
  119883. 21
  119884. };
  119885. static static_codebook _44c7_s_p8_1 = {
  119886. 2, 441,
  119887. _vq_lengthlist__44c7_s_p8_1,
  119888. 1, -529268736, 1611661312, 5, 0,
  119889. _vq_quantlist__44c7_s_p8_1,
  119890. NULL,
  119891. &_vq_auxt__44c7_s_p8_1,
  119892. NULL,
  119893. 0
  119894. };
  119895. static long _vq_quantlist__44c7_s_p9_0[] = {
  119896. 6,
  119897. 5,
  119898. 7,
  119899. 4,
  119900. 8,
  119901. 3,
  119902. 9,
  119903. 2,
  119904. 10,
  119905. 1,
  119906. 11,
  119907. 0,
  119908. 12,
  119909. };
  119910. static long _vq_lengthlist__44c7_s_p9_0[] = {
  119911. 1, 3, 3,11,11,11,11,11,11,11,11,11,11, 4, 6, 6,
  119912. 11,11,11,11,11,11,11,11,11,11, 4, 7, 7,11,11,11,
  119913. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119914. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119915. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119916. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119917. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119918. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119919. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119920. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119921. 11,11,11,11,11,11,11,11,11,
  119922. };
  119923. static float _vq_quantthresh__44c7_s_p9_0[] = {
  119924. -3503.5, -2866.5, -2229.5, -1592.5, -955.5, -318.5, 318.5, 955.5,
  119925. 1592.5, 2229.5, 2866.5, 3503.5,
  119926. };
  119927. static long _vq_quantmap__44c7_s_p9_0[] = {
  119928. 11, 9, 7, 5, 3, 1, 0, 2,
  119929. 4, 6, 8, 10, 12,
  119930. };
  119931. static encode_aux_threshmatch _vq_auxt__44c7_s_p9_0 = {
  119932. _vq_quantthresh__44c7_s_p9_0,
  119933. _vq_quantmap__44c7_s_p9_0,
  119934. 13,
  119935. 13
  119936. };
  119937. static static_codebook _44c7_s_p9_0 = {
  119938. 2, 169,
  119939. _vq_lengthlist__44c7_s_p9_0,
  119940. 1, -511845376, 1630791680, 4, 0,
  119941. _vq_quantlist__44c7_s_p9_0,
  119942. NULL,
  119943. &_vq_auxt__44c7_s_p9_0,
  119944. NULL,
  119945. 0
  119946. };
  119947. static long _vq_quantlist__44c7_s_p9_1[] = {
  119948. 6,
  119949. 5,
  119950. 7,
  119951. 4,
  119952. 8,
  119953. 3,
  119954. 9,
  119955. 2,
  119956. 10,
  119957. 1,
  119958. 11,
  119959. 0,
  119960. 12,
  119961. };
  119962. static long _vq_lengthlist__44c7_s_p9_1[] = {
  119963. 1, 4, 4, 7, 7, 7, 7, 7, 6, 8, 8, 8, 8, 6, 6, 6,
  119964. 8, 8, 9, 8, 8, 7, 9, 8,11,10, 5, 6, 6, 8, 8, 9,
  119965. 8, 8, 8,10, 9,11,11,16, 8, 8, 9, 8, 9, 9, 9, 8,
  119966. 10, 9,11,10,16, 8, 8, 9, 9,10,10, 9, 9,10,10,11,
  119967. 11,16,13,13, 9, 9,10,10, 9,10,11,11,12,11,16,13,
  119968. 13, 9, 8,10, 9,10,10,10,10,11,11,16,14,16, 8, 9,
  119969. 9, 9,11,10,11,11,12,11,16,16,16, 9, 7,10, 7,11,
  119970. 10,11,11,12,11,16,16,16,12,12, 9,10,11,11,12,11,
  119971. 12,12,16,16,16,12,10,10, 7,11, 8,12,11,12,12,16,
  119972. 16,15,16,16,11,12,10,10,12,11,12,12,16,16,16,15,
  119973. 15,11,11,10,10,12,12,12,12,
  119974. };
  119975. static float _vq_quantthresh__44c7_s_p9_1[] = {
  119976. -269.5, -220.5, -171.5, -122.5, -73.5, -24.5, 24.5, 73.5,
  119977. 122.5, 171.5, 220.5, 269.5,
  119978. };
  119979. static long _vq_quantmap__44c7_s_p9_1[] = {
  119980. 11, 9, 7, 5, 3, 1, 0, 2,
  119981. 4, 6, 8, 10, 12,
  119982. };
  119983. static encode_aux_threshmatch _vq_auxt__44c7_s_p9_1 = {
  119984. _vq_quantthresh__44c7_s_p9_1,
  119985. _vq_quantmap__44c7_s_p9_1,
  119986. 13,
  119987. 13
  119988. };
  119989. static static_codebook _44c7_s_p9_1 = {
  119990. 2, 169,
  119991. _vq_lengthlist__44c7_s_p9_1,
  119992. 1, -518889472, 1622704128, 4, 0,
  119993. _vq_quantlist__44c7_s_p9_1,
  119994. NULL,
  119995. &_vq_auxt__44c7_s_p9_1,
  119996. NULL,
  119997. 0
  119998. };
  119999. static long _vq_quantlist__44c7_s_p9_2[] = {
  120000. 24,
  120001. 23,
  120002. 25,
  120003. 22,
  120004. 26,
  120005. 21,
  120006. 27,
  120007. 20,
  120008. 28,
  120009. 19,
  120010. 29,
  120011. 18,
  120012. 30,
  120013. 17,
  120014. 31,
  120015. 16,
  120016. 32,
  120017. 15,
  120018. 33,
  120019. 14,
  120020. 34,
  120021. 13,
  120022. 35,
  120023. 12,
  120024. 36,
  120025. 11,
  120026. 37,
  120027. 10,
  120028. 38,
  120029. 9,
  120030. 39,
  120031. 8,
  120032. 40,
  120033. 7,
  120034. 41,
  120035. 6,
  120036. 42,
  120037. 5,
  120038. 43,
  120039. 4,
  120040. 44,
  120041. 3,
  120042. 45,
  120043. 2,
  120044. 46,
  120045. 1,
  120046. 47,
  120047. 0,
  120048. 48,
  120049. };
  120050. static long _vq_lengthlist__44c7_s_p9_2[] = {
  120051. 2, 4, 3, 4, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  120052. 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  120053. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  120054. 7,
  120055. };
  120056. static float _vq_quantthresh__44c7_s_p9_2[] = {
  120057. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  120058. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  120059. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  120060. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  120061. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  120062. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  120063. };
  120064. static long _vq_quantmap__44c7_s_p9_2[] = {
  120065. 47, 45, 43, 41, 39, 37, 35, 33,
  120066. 31, 29, 27, 25, 23, 21, 19, 17,
  120067. 15, 13, 11, 9, 7, 5, 3, 1,
  120068. 0, 2, 4, 6, 8, 10, 12, 14,
  120069. 16, 18, 20, 22, 24, 26, 28, 30,
  120070. 32, 34, 36, 38, 40, 42, 44, 46,
  120071. 48,
  120072. };
  120073. static encode_aux_threshmatch _vq_auxt__44c7_s_p9_2 = {
  120074. _vq_quantthresh__44c7_s_p9_2,
  120075. _vq_quantmap__44c7_s_p9_2,
  120076. 49,
  120077. 49
  120078. };
  120079. static static_codebook _44c7_s_p9_2 = {
  120080. 1, 49,
  120081. _vq_lengthlist__44c7_s_p9_2,
  120082. 1, -526909440, 1611661312, 6, 0,
  120083. _vq_quantlist__44c7_s_p9_2,
  120084. NULL,
  120085. &_vq_auxt__44c7_s_p9_2,
  120086. NULL,
  120087. 0
  120088. };
  120089. static long _huff_lengthlist__44c7_s_short[] = {
  120090. 4,11,12,14,15,15,17,17,18,18, 5, 6, 6, 8, 9,10,
  120091. 13,17,18,19, 7, 5, 4, 6, 8, 9,11,15,19,19, 8, 6,
  120092. 5, 5, 6, 7,11,14,16,17, 9, 7, 7, 6, 7, 7,10,13,
  120093. 15,19,10, 8, 7, 6, 7, 6, 7, 9,14,16,12,10, 9, 7,
  120094. 7, 6, 4, 5,10,15,14,13,11, 7, 6, 6, 4, 2, 7,13,
  120095. 16,16,15, 9, 8, 8, 8, 6, 9,13,19,19,17,12,11,10,
  120096. 10, 9,11,14,
  120097. };
  120098. static static_codebook _huff_book__44c7_s_short = {
  120099. 2, 100,
  120100. _huff_lengthlist__44c7_s_short,
  120101. 0, 0, 0, 0, 0,
  120102. NULL,
  120103. NULL,
  120104. NULL,
  120105. NULL,
  120106. 0
  120107. };
  120108. static long _huff_lengthlist__44c8_s_long[] = {
  120109. 3, 8,12,13,14,14,14,13,14,14, 6, 4, 5, 8,10,10,
  120110. 11,11,14,13, 9, 5, 4, 5, 7, 8, 9,10,13,13,12, 7,
  120111. 5, 4, 5, 6, 8, 9,12,13,13, 9, 6, 5, 5, 5, 7, 9,
  120112. 11,14,12,10, 7, 6, 5, 4, 6, 7,10,11,12,11, 9, 8,
  120113. 7, 5, 5, 6,10,10,13,12,10, 9, 8, 6, 6, 5, 8,10,
  120114. 14,13,12,12,11,10, 9, 7, 8,10,12,13,14,14,13,12,
  120115. 11, 9, 9,10,
  120116. };
  120117. static static_codebook _huff_book__44c8_s_long = {
  120118. 2, 100,
  120119. _huff_lengthlist__44c8_s_long,
  120120. 0, 0, 0, 0, 0,
  120121. NULL,
  120122. NULL,
  120123. NULL,
  120124. NULL,
  120125. 0
  120126. };
  120127. static long _vq_quantlist__44c8_s_p1_0[] = {
  120128. 1,
  120129. 0,
  120130. 2,
  120131. };
  120132. static long _vq_lengthlist__44c8_s_p1_0[] = {
  120133. 1, 5, 5, 0, 5, 5, 0, 5, 5, 5, 7, 7, 0, 9, 8, 0,
  120134. 9, 8, 6, 7, 7, 0, 8, 9, 0, 8, 9, 0, 0, 0, 0, 0,
  120135. 0, 0, 0, 0, 5, 9, 8, 0, 8, 8, 0, 8, 8, 5, 8, 9,
  120136. 0, 8, 8, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
  120137. 9, 8, 0, 8, 8, 0, 8, 8, 5, 8, 9, 0, 8, 8, 0, 8,
  120138. 8,
  120139. };
  120140. static float _vq_quantthresh__44c8_s_p1_0[] = {
  120141. -0.5, 0.5,
  120142. };
  120143. static long _vq_quantmap__44c8_s_p1_0[] = {
  120144. 1, 0, 2,
  120145. };
  120146. static encode_aux_threshmatch _vq_auxt__44c8_s_p1_0 = {
  120147. _vq_quantthresh__44c8_s_p1_0,
  120148. _vq_quantmap__44c8_s_p1_0,
  120149. 3,
  120150. 3
  120151. };
  120152. static static_codebook _44c8_s_p1_0 = {
  120153. 4, 81,
  120154. _vq_lengthlist__44c8_s_p1_0,
  120155. 1, -535822336, 1611661312, 2, 0,
  120156. _vq_quantlist__44c8_s_p1_0,
  120157. NULL,
  120158. &_vq_auxt__44c8_s_p1_0,
  120159. NULL,
  120160. 0
  120161. };
  120162. static long _vq_quantlist__44c8_s_p2_0[] = {
  120163. 2,
  120164. 1,
  120165. 3,
  120166. 0,
  120167. 4,
  120168. };
  120169. static long _vq_lengthlist__44c8_s_p2_0[] = {
  120170. 3, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0,
  120171. 7, 7, 9, 9, 0, 0, 0, 9, 9, 5, 7, 7, 9, 9, 0, 8,
  120172. 7,10, 9, 0, 8, 7,10, 9, 0,10,10,11,11, 0, 0, 0,
  120173. 11,11, 5, 7, 7, 9, 9, 0, 7, 8, 9,10, 0, 7, 8, 9,
  120174. 10, 0,10,10,11,11, 0, 0, 0,11,11, 8, 9, 9,11,10,
  120175. 0,11,10,12,11, 0,11,10,12,12, 0,13,13,14,14, 0,
  120176. 0, 0,14,13, 8, 9, 9,10,11, 0,10,11,12,12, 0,10,
  120177. 11,12,12, 0,13,13,14,14, 0, 0, 0,13,14, 0, 0, 0,
  120178. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120179. 0, 0, 0, 0, 0, 0, 5, 8, 7,11,10, 0, 7, 7,10,10,
  120180. 0, 7, 7,10,10, 0, 9, 9,10,10, 0, 0, 0,11,10, 5,
  120181. 7, 8,10,11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9,
  120182. 9,10,10, 0, 0, 0,10,10, 8,10, 9,12,12, 0,10,10,
  120183. 12,11, 0,10,10,12,12, 0,12,12,13,12, 0, 0, 0,13,
  120184. 12, 8, 9,10,12,12, 0,10,10,11,12, 0,10,10,11,12,
  120185. 0,12,12,13,13, 0, 0, 0,12,13, 0, 0, 0, 0, 0, 0,
  120186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120187. 0, 0, 0, 6, 8, 7,11,10, 0, 7, 7,10,10, 0, 7, 7,
  120188. 10,10, 0, 9, 9,10,11, 0, 0, 0,10,10, 6, 7, 8,10,
  120189. 11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9, 9,10,10,
  120190. 0, 0, 0,10,10, 9,10, 9,12,12, 0,10,10,12,12, 0,
  120191. 10,10,12,11, 0,12,12,13,13, 0, 0, 0,13,12, 8, 9,
  120192. 10,12,12, 0,10,10,12,12, 0,10,10,11,12, 0,12,12,
  120193. 13,13, 0, 0, 0,12,13, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120195. 7,10,10,13,13, 0, 9, 9,12,12, 0, 9, 9,12,12, 0,
  120196. 10,10,12,12, 0, 0, 0,12,12, 7,10,10,13,13, 0, 9,
  120197. 9,12,12, 0, 9, 9,12,12, 0,10,10,12,12, 0, 0, 0,
  120198. 12,12, 9,11,11,14,13, 0,10,10,13,12, 0,11,10,13,
  120199. 12, 0,12,12,13,12, 0, 0, 0,13,13, 9,11,11,13,14,
  120200. 0,10,11,12,13, 0,10,11,13,13, 0,12,12,12,13, 0,
  120201. 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120203. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
  120206. 11,11,14,14, 0,10,11,13,13, 0,11,10,13,13, 0,11,
  120207. 12,13,13, 0, 0, 0,13,12, 9,11,11,14,14, 0,11,10,
  120208. 13,13, 0,10,11,13,13, 0,12,12,13,13, 0, 0, 0,12,
  120209. 13,
  120210. };
  120211. static float _vq_quantthresh__44c8_s_p2_0[] = {
  120212. -1.5, -0.5, 0.5, 1.5,
  120213. };
  120214. static long _vq_quantmap__44c8_s_p2_0[] = {
  120215. 3, 1, 0, 2, 4,
  120216. };
  120217. static encode_aux_threshmatch _vq_auxt__44c8_s_p2_0 = {
  120218. _vq_quantthresh__44c8_s_p2_0,
  120219. _vq_quantmap__44c8_s_p2_0,
  120220. 5,
  120221. 5
  120222. };
  120223. static static_codebook _44c8_s_p2_0 = {
  120224. 4, 625,
  120225. _vq_lengthlist__44c8_s_p2_0,
  120226. 1, -533725184, 1611661312, 3, 0,
  120227. _vq_quantlist__44c8_s_p2_0,
  120228. NULL,
  120229. &_vq_auxt__44c8_s_p2_0,
  120230. NULL,
  120231. 0
  120232. };
  120233. static long _vq_quantlist__44c8_s_p3_0[] = {
  120234. 4,
  120235. 3,
  120236. 5,
  120237. 2,
  120238. 6,
  120239. 1,
  120240. 7,
  120241. 0,
  120242. 8,
  120243. };
  120244. static long _vq_lengthlist__44c8_s_p3_0[] = {
  120245. 2, 4, 4, 5, 5, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  120246. 9, 9, 0, 4, 4, 6, 6, 7, 7, 9, 9, 0, 5, 5, 6, 6,
  120247. 8, 8,10,10, 0, 0, 0, 6, 6, 8, 8,10,10, 0, 0, 0,
  120248. 7, 7, 9, 9,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0,
  120249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120250. 0,
  120251. };
  120252. static float _vq_quantthresh__44c8_s_p3_0[] = {
  120253. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  120254. };
  120255. static long _vq_quantmap__44c8_s_p3_0[] = {
  120256. 7, 5, 3, 1, 0, 2, 4, 6,
  120257. 8,
  120258. };
  120259. static encode_aux_threshmatch _vq_auxt__44c8_s_p3_0 = {
  120260. _vq_quantthresh__44c8_s_p3_0,
  120261. _vq_quantmap__44c8_s_p3_0,
  120262. 9,
  120263. 9
  120264. };
  120265. static static_codebook _44c8_s_p3_0 = {
  120266. 2, 81,
  120267. _vq_lengthlist__44c8_s_p3_0,
  120268. 1, -531628032, 1611661312, 4, 0,
  120269. _vq_quantlist__44c8_s_p3_0,
  120270. NULL,
  120271. &_vq_auxt__44c8_s_p3_0,
  120272. NULL,
  120273. 0
  120274. };
  120275. static long _vq_quantlist__44c8_s_p4_0[] = {
  120276. 8,
  120277. 7,
  120278. 9,
  120279. 6,
  120280. 10,
  120281. 5,
  120282. 11,
  120283. 4,
  120284. 12,
  120285. 3,
  120286. 13,
  120287. 2,
  120288. 14,
  120289. 1,
  120290. 15,
  120291. 0,
  120292. 16,
  120293. };
  120294. static long _vq_lengthlist__44c8_s_p4_0[] = {
  120295. 3, 4, 4, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  120296. 11, 0, 4, 4, 6, 6, 7, 7, 8, 8, 9, 8,10,10,11,11,
  120297. 11,11, 0, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,
  120298. 11,11,11, 0, 6, 5, 6, 6, 7, 7, 9, 9, 9, 9,10,10,
  120299. 11,11,12,12, 0, 0, 0, 6, 6, 7, 7, 9, 9, 9, 9,10,
  120300. 10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,10,
  120301. 11,11,11,12,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,
  120302. 10,11,11,11,12,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  120303. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 8, 8, 9,
  120304. 9,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 0, 0,
  120305. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120306. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120307. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120310. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120311. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120312. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120313. 0,
  120314. };
  120315. static float _vq_quantthresh__44c8_s_p4_0[] = {
  120316. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  120317. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  120318. };
  120319. static long _vq_quantmap__44c8_s_p4_0[] = {
  120320. 15, 13, 11, 9, 7, 5, 3, 1,
  120321. 0, 2, 4, 6, 8, 10, 12, 14,
  120322. 16,
  120323. };
  120324. static encode_aux_threshmatch _vq_auxt__44c8_s_p4_0 = {
  120325. _vq_quantthresh__44c8_s_p4_0,
  120326. _vq_quantmap__44c8_s_p4_0,
  120327. 17,
  120328. 17
  120329. };
  120330. static static_codebook _44c8_s_p4_0 = {
  120331. 2, 289,
  120332. _vq_lengthlist__44c8_s_p4_0,
  120333. 1, -529530880, 1611661312, 5, 0,
  120334. _vq_quantlist__44c8_s_p4_0,
  120335. NULL,
  120336. &_vq_auxt__44c8_s_p4_0,
  120337. NULL,
  120338. 0
  120339. };
  120340. static long _vq_quantlist__44c8_s_p5_0[] = {
  120341. 1,
  120342. 0,
  120343. 2,
  120344. };
  120345. static long _vq_lengthlist__44c8_s_p5_0[] = {
  120346. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 7, 6,10,10,10,10,
  120347. 10,10, 4, 6, 6,10,10,10,10, 9,10, 5,10,10, 9,11,
  120348. 11,10,11,11, 7,10,10,11,12,12,12,12,12, 7,10,10,
  120349. 11,12,12,12,12,12, 6,10,10,10,12,12,10,12,12, 7,
  120350. 10,10,11,12,12,12,12,12, 7,10,10,11,12,12,12,12,
  120351. 12,
  120352. };
  120353. static float _vq_quantthresh__44c8_s_p5_0[] = {
  120354. -5.5, 5.5,
  120355. };
  120356. static long _vq_quantmap__44c8_s_p5_0[] = {
  120357. 1, 0, 2,
  120358. };
  120359. static encode_aux_threshmatch _vq_auxt__44c8_s_p5_0 = {
  120360. _vq_quantthresh__44c8_s_p5_0,
  120361. _vq_quantmap__44c8_s_p5_0,
  120362. 3,
  120363. 3
  120364. };
  120365. static static_codebook _44c8_s_p5_0 = {
  120366. 4, 81,
  120367. _vq_lengthlist__44c8_s_p5_0,
  120368. 1, -529137664, 1618345984, 2, 0,
  120369. _vq_quantlist__44c8_s_p5_0,
  120370. NULL,
  120371. &_vq_auxt__44c8_s_p5_0,
  120372. NULL,
  120373. 0
  120374. };
  120375. static long _vq_quantlist__44c8_s_p5_1[] = {
  120376. 5,
  120377. 4,
  120378. 6,
  120379. 3,
  120380. 7,
  120381. 2,
  120382. 8,
  120383. 1,
  120384. 9,
  120385. 0,
  120386. 10,
  120387. };
  120388. static long _vq_lengthlist__44c8_s_p5_1[] = {
  120389. 3, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8,11, 4, 5, 6, 6,
  120390. 7, 7, 8, 8, 8, 8,11, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  120391. 9,12, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,12,12,12, 6,
  120392. 6, 7, 7, 8, 8, 9, 9,11,11,11, 6, 6, 7, 7, 8, 8,
  120393. 8, 8,11,11,11, 6, 6, 7, 7, 8, 8, 8, 8,11,11,11,
  120394. 7, 7, 7, 8, 8, 8, 8, 8,11,11,11,11,11, 7, 7, 8,
  120395. 8, 8, 8,11,11,11,11,11, 7, 7, 7, 7, 8, 8,11,11,
  120396. 11,11,11, 7, 7, 7, 7, 8, 8,
  120397. };
  120398. static float _vq_quantthresh__44c8_s_p5_1[] = {
  120399. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  120400. 3.5, 4.5,
  120401. };
  120402. static long _vq_quantmap__44c8_s_p5_1[] = {
  120403. 9, 7, 5, 3, 1, 0, 2, 4,
  120404. 6, 8, 10,
  120405. };
  120406. static encode_aux_threshmatch _vq_auxt__44c8_s_p5_1 = {
  120407. _vq_quantthresh__44c8_s_p5_1,
  120408. _vq_quantmap__44c8_s_p5_1,
  120409. 11,
  120410. 11
  120411. };
  120412. static static_codebook _44c8_s_p5_1 = {
  120413. 2, 121,
  120414. _vq_lengthlist__44c8_s_p5_1,
  120415. 1, -531365888, 1611661312, 4, 0,
  120416. _vq_quantlist__44c8_s_p5_1,
  120417. NULL,
  120418. &_vq_auxt__44c8_s_p5_1,
  120419. NULL,
  120420. 0
  120421. };
  120422. static long _vq_quantlist__44c8_s_p6_0[] = {
  120423. 6,
  120424. 5,
  120425. 7,
  120426. 4,
  120427. 8,
  120428. 3,
  120429. 9,
  120430. 2,
  120431. 10,
  120432. 1,
  120433. 11,
  120434. 0,
  120435. 12,
  120436. };
  120437. static long _vq_lengthlist__44c8_s_p6_0[] = {
  120438. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  120439. 7, 7, 8, 8, 9, 9,10,10,11,11, 6, 5, 5, 7, 7, 8,
  120440. 8, 9, 9,10,10,11,11, 0, 7, 7, 7, 7, 9, 9,10,10,
  120441. 10,10,11,11, 0, 7, 7, 7, 7, 9, 9,10,10,10,10,11,
  120442. 11, 0,11,11, 9, 9,10,10,11,11,11,11,12,12, 0,12,
  120443. 12, 9, 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0,
  120444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120448. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120449. };
  120450. static float _vq_quantthresh__44c8_s_p6_0[] = {
  120451. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  120452. 12.5, 17.5, 22.5, 27.5,
  120453. };
  120454. static long _vq_quantmap__44c8_s_p6_0[] = {
  120455. 11, 9, 7, 5, 3, 1, 0, 2,
  120456. 4, 6, 8, 10, 12,
  120457. };
  120458. static encode_aux_threshmatch _vq_auxt__44c8_s_p6_0 = {
  120459. _vq_quantthresh__44c8_s_p6_0,
  120460. _vq_quantmap__44c8_s_p6_0,
  120461. 13,
  120462. 13
  120463. };
  120464. static static_codebook _44c8_s_p6_0 = {
  120465. 2, 169,
  120466. _vq_lengthlist__44c8_s_p6_0,
  120467. 1, -526516224, 1616117760, 4, 0,
  120468. _vq_quantlist__44c8_s_p6_0,
  120469. NULL,
  120470. &_vq_auxt__44c8_s_p6_0,
  120471. NULL,
  120472. 0
  120473. };
  120474. static long _vq_quantlist__44c8_s_p6_1[] = {
  120475. 2,
  120476. 1,
  120477. 3,
  120478. 0,
  120479. 4,
  120480. };
  120481. static long _vq_lengthlist__44c8_s_p6_1[] = {
  120482. 3, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 5, 6,
  120483. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  120484. };
  120485. static float _vq_quantthresh__44c8_s_p6_1[] = {
  120486. -1.5, -0.5, 0.5, 1.5,
  120487. };
  120488. static long _vq_quantmap__44c8_s_p6_1[] = {
  120489. 3, 1, 0, 2, 4,
  120490. };
  120491. static encode_aux_threshmatch _vq_auxt__44c8_s_p6_1 = {
  120492. _vq_quantthresh__44c8_s_p6_1,
  120493. _vq_quantmap__44c8_s_p6_1,
  120494. 5,
  120495. 5
  120496. };
  120497. static static_codebook _44c8_s_p6_1 = {
  120498. 2, 25,
  120499. _vq_lengthlist__44c8_s_p6_1,
  120500. 1, -533725184, 1611661312, 3, 0,
  120501. _vq_quantlist__44c8_s_p6_1,
  120502. NULL,
  120503. &_vq_auxt__44c8_s_p6_1,
  120504. NULL,
  120505. 0
  120506. };
  120507. static long _vq_quantlist__44c8_s_p7_0[] = {
  120508. 6,
  120509. 5,
  120510. 7,
  120511. 4,
  120512. 8,
  120513. 3,
  120514. 9,
  120515. 2,
  120516. 10,
  120517. 1,
  120518. 11,
  120519. 0,
  120520. 12,
  120521. };
  120522. static long _vq_lengthlist__44c8_s_p7_0[] = {
  120523. 1, 4, 4, 6, 6, 8, 7, 9, 9,10,10,12,12, 6, 5, 5,
  120524. 7, 7, 8, 8,10,10,11,11,12,12, 7, 5, 5, 7, 7, 8,
  120525. 8,10,10,11,11,12,12,21, 7, 7, 7, 7, 8, 9,10,10,
  120526. 11,11,12,12,21, 7, 7, 7, 7, 9, 9,10,10,12,12,13,
  120527. 13,21,11,11, 8, 8, 9, 9,11,11,12,12,13,13,21,11,
  120528. 11, 8, 8, 9, 9,11,11,12,12,13,13,21,21,21,10,10,
  120529. 10,10,11,11,12,13,13,13,21,21,21,10,10,10,10,11,
  120530. 11,13,13,14,13,21,21,21,13,13,11,11,12,12,13,13,
  120531. 14,14,21,21,21,14,14,11,11,12,12,13,13,14,14,21,
  120532. 21,21,21,20,13,13,13,12,14,14,16,15,20,20,20,20,
  120533. 20,13,13,13,13,14,13,15,15,
  120534. };
  120535. static float _vq_quantthresh__44c8_s_p7_0[] = {
  120536. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  120537. 27.5, 38.5, 49.5, 60.5,
  120538. };
  120539. static long _vq_quantmap__44c8_s_p7_0[] = {
  120540. 11, 9, 7, 5, 3, 1, 0, 2,
  120541. 4, 6, 8, 10, 12,
  120542. };
  120543. static encode_aux_threshmatch _vq_auxt__44c8_s_p7_0 = {
  120544. _vq_quantthresh__44c8_s_p7_0,
  120545. _vq_quantmap__44c8_s_p7_0,
  120546. 13,
  120547. 13
  120548. };
  120549. static static_codebook _44c8_s_p7_0 = {
  120550. 2, 169,
  120551. _vq_lengthlist__44c8_s_p7_0,
  120552. 1, -523206656, 1618345984, 4, 0,
  120553. _vq_quantlist__44c8_s_p7_0,
  120554. NULL,
  120555. &_vq_auxt__44c8_s_p7_0,
  120556. NULL,
  120557. 0
  120558. };
  120559. static long _vq_quantlist__44c8_s_p7_1[] = {
  120560. 5,
  120561. 4,
  120562. 6,
  120563. 3,
  120564. 7,
  120565. 2,
  120566. 8,
  120567. 1,
  120568. 9,
  120569. 0,
  120570. 10,
  120571. };
  120572. static long _vq_lengthlist__44c8_s_p7_1[] = {
  120573. 4, 5, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 6, 6, 6, 7,
  120574. 7, 7, 7, 7, 7, 7, 8, 6, 6, 6, 6, 7, 7, 7, 7, 7,
  120575. 7, 8, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7,
  120576. 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7,
  120577. 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
  120578. 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  120579. 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 8, 8,
  120580. 8, 8, 8, 7, 7, 7, 7, 7, 7,
  120581. };
  120582. static float _vq_quantthresh__44c8_s_p7_1[] = {
  120583. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  120584. 3.5, 4.5,
  120585. };
  120586. static long _vq_quantmap__44c8_s_p7_1[] = {
  120587. 9, 7, 5, 3, 1, 0, 2, 4,
  120588. 6, 8, 10,
  120589. };
  120590. static encode_aux_threshmatch _vq_auxt__44c8_s_p7_1 = {
  120591. _vq_quantthresh__44c8_s_p7_1,
  120592. _vq_quantmap__44c8_s_p7_1,
  120593. 11,
  120594. 11
  120595. };
  120596. static static_codebook _44c8_s_p7_1 = {
  120597. 2, 121,
  120598. _vq_lengthlist__44c8_s_p7_1,
  120599. 1, -531365888, 1611661312, 4, 0,
  120600. _vq_quantlist__44c8_s_p7_1,
  120601. NULL,
  120602. &_vq_auxt__44c8_s_p7_1,
  120603. NULL,
  120604. 0
  120605. };
  120606. static long _vq_quantlist__44c8_s_p8_0[] = {
  120607. 7,
  120608. 6,
  120609. 8,
  120610. 5,
  120611. 9,
  120612. 4,
  120613. 10,
  120614. 3,
  120615. 11,
  120616. 2,
  120617. 12,
  120618. 1,
  120619. 13,
  120620. 0,
  120621. 14,
  120622. };
  120623. static long _vq_lengthlist__44c8_s_p8_0[] = {
  120624. 1, 4, 4, 7, 6, 8, 8, 8, 7, 9, 8,10,10,11,10, 6,
  120625. 5, 5, 7, 7, 9, 9, 8, 8,10,10,11,11,12,11, 6, 5,
  120626. 5, 7, 7, 9, 9, 9, 9,10,10,11,11,12,12,20, 8, 8,
  120627. 8, 8, 9, 9, 9, 9,10,10,11,11,12,12,20, 8, 8, 8,
  120628. 8,10, 9, 9, 9,10,10,11,11,12,12,20,12,12, 9, 9,
  120629. 10,10,10,10,10,11,12,12,12,12,20,12,12, 9, 9,10,
  120630. 10,10,10,11,11,12,12,13,13,20,20,20, 9, 9, 9, 9,
  120631. 11,10,11,11,12,12,12,13,20,19,19, 9, 9, 9, 9,11,
  120632. 11,11,12,12,12,13,13,19,19,19,13,13,10,10,11,11,
  120633. 12,12,13,13,13,13,19,19,19,14,13,11,10,11,11,12,
  120634. 12,12,13,13,13,19,19,19,19,19,12,12,12,12,13,13,
  120635. 13,13,14,13,19,19,19,19,19,12,12,12,11,12,12,13,
  120636. 14,14,14,19,19,19,19,19,16,15,13,12,13,13,13,14,
  120637. 14,14,19,19,19,19,19,17,17,13,12,13,11,14,13,15,
  120638. 15,
  120639. };
  120640. static float _vq_quantthresh__44c8_s_p8_0[] = {
  120641. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  120642. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  120643. };
  120644. static long _vq_quantmap__44c8_s_p8_0[] = {
  120645. 13, 11, 9, 7, 5, 3, 1, 0,
  120646. 2, 4, 6, 8, 10, 12, 14,
  120647. };
  120648. static encode_aux_threshmatch _vq_auxt__44c8_s_p8_0 = {
  120649. _vq_quantthresh__44c8_s_p8_0,
  120650. _vq_quantmap__44c8_s_p8_0,
  120651. 15,
  120652. 15
  120653. };
  120654. static static_codebook _44c8_s_p8_0 = {
  120655. 2, 225,
  120656. _vq_lengthlist__44c8_s_p8_0,
  120657. 1, -520986624, 1620377600, 4, 0,
  120658. _vq_quantlist__44c8_s_p8_0,
  120659. NULL,
  120660. &_vq_auxt__44c8_s_p8_0,
  120661. NULL,
  120662. 0
  120663. };
  120664. static long _vq_quantlist__44c8_s_p8_1[] = {
  120665. 10,
  120666. 9,
  120667. 11,
  120668. 8,
  120669. 12,
  120670. 7,
  120671. 13,
  120672. 6,
  120673. 14,
  120674. 5,
  120675. 15,
  120676. 4,
  120677. 16,
  120678. 3,
  120679. 17,
  120680. 2,
  120681. 18,
  120682. 1,
  120683. 19,
  120684. 0,
  120685. 20,
  120686. };
  120687. static long _vq_lengthlist__44c8_s_p8_1[] = {
  120688. 4, 5, 5, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  120689. 8, 8, 8, 8, 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  120690. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 6, 6, 7, 7, 8,
  120691. 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,
  120692. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120693. 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  120694. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 9,
  120695. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,
  120696. 10, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120697. 9, 9, 9,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120698. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9,
  120699. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  120700. 10,10, 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9, 9, 9,
  120701. 9, 9,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120702. 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9, 9,
  120703. 9, 9, 9, 9,10,10,10, 9, 9, 9, 9, 9,10,10,10,10,
  120704. 10,10,10, 9, 9, 9, 9, 9,10,10,10, 9, 9, 9, 9, 9,
  120705. 9,10,10,10,10,10,10,10, 9,10,10, 9,10,10,10,10,
  120706. 9,10, 9,10,10, 9,10,10,10,10,10,10,10, 9,10,10,
  120707. 10,10,10,10, 9, 9,10,10, 9,10,10,10,10,10,10,10,
  120708. 10,10,10,10,10,10,10,10, 9, 9, 9,10, 9, 9, 9, 9,
  120709. 10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9,
  120710. 10, 9,10, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  120711. 10,10,10,10, 9, 9,10, 9, 9, 9,10,10,10,10,10,10,
  120712. 10,10,10,10,10, 9, 9, 9, 9, 9, 9,10, 9, 9,10,10,
  120713. 10,10,10,10,10,10,10,10,10,10,10,10,10, 9,10, 9,
  120714. 9,10, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  120715. 10, 9, 9,10,10, 9,10, 9, 9,
  120716. };
  120717. static float _vq_quantthresh__44c8_s_p8_1[] = {
  120718. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  120719. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  120720. 6.5, 7.5, 8.5, 9.5,
  120721. };
  120722. static long _vq_quantmap__44c8_s_p8_1[] = {
  120723. 19, 17, 15, 13, 11, 9, 7, 5,
  120724. 3, 1, 0, 2, 4, 6, 8, 10,
  120725. 12, 14, 16, 18, 20,
  120726. };
  120727. static encode_aux_threshmatch _vq_auxt__44c8_s_p8_1 = {
  120728. _vq_quantthresh__44c8_s_p8_1,
  120729. _vq_quantmap__44c8_s_p8_1,
  120730. 21,
  120731. 21
  120732. };
  120733. static static_codebook _44c8_s_p8_1 = {
  120734. 2, 441,
  120735. _vq_lengthlist__44c8_s_p8_1,
  120736. 1, -529268736, 1611661312, 5, 0,
  120737. _vq_quantlist__44c8_s_p8_1,
  120738. NULL,
  120739. &_vq_auxt__44c8_s_p8_1,
  120740. NULL,
  120741. 0
  120742. };
  120743. static long _vq_quantlist__44c8_s_p9_0[] = {
  120744. 8,
  120745. 7,
  120746. 9,
  120747. 6,
  120748. 10,
  120749. 5,
  120750. 11,
  120751. 4,
  120752. 12,
  120753. 3,
  120754. 13,
  120755. 2,
  120756. 14,
  120757. 1,
  120758. 15,
  120759. 0,
  120760. 16,
  120761. };
  120762. static long _vq_lengthlist__44c8_s_p9_0[] = {
  120763. 1, 4, 3,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120764. 11, 4, 7, 7,11,11,11,11,11,11,11,11,11,11,11,11,
  120765. 11,11, 4, 8,11,11,11,11,11,11,11,11,11,11,11,11,
  120766. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120767. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120768. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120769. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120770. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120771. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120772. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120773. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120774. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120775. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120776. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120777. 11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  120778. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  120779. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  120780. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  120781. 10,
  120782. };
  120783. static float _vq_quantthresh__44c8_s_p9_0[] = {
  120784. -6982.5, -6051.5, -5120.5, -4189.5, -3258.5, -2327.5, -1396.5, -465.5,
  120785. 465.5, 1396.5, 2327.5, 3258.5, 4189.5, 5120.5, 6051.5, 6982.5,
  120786. };
  120787. static long _vq_quantmap__44c8_s_p9_0[] = {
  120788. 15, 13, 11, 9, 7, 5, 3, 1,
  120789. 0, 2, 4, 6, 8, 10, 12, 14,
  120790. 16,
  120791. };
  120792. static encode_aux_threshmatch _vq_auxt__44c8_s_p9_0 = {
  120793. _vq_quantthresh__44c8_s_p9_0,
  120794. _vq_quantmap__44c8_s_p9_0,
  120795. 17,
  120796. 17
  120797. };
  120798. static static_codebook _44c8_s_p9_0 = {
  120799. 2, 289,
  120800. _vq_lengthlist__44c8_s_p9_0,
  120801. 1, -509798400, 1631393792, 5, 0,
  120802. _vq_quantlist__44c8_s_p9_0,
  120803. NULL,
  120804. &_vq_auxt__44c8_s_p9_0,
  120805. NULL,
  120806. 0
  120807. };
  120808. static long _vq_quantlist__44c8_s_p9_1[] = {
  120809. 9,
  120810. 8,
  120811. 10,
  120812. 7,
  120813. 11,
  120814. 6,
  120815. 12,
  120816. 5,
  120817. 13,
  120818. 4,
  120819. 14,
  120820. 3,
  120821. 15,
  120822. 2,
  120823. 16,
  120824. 1,
  120825. 17,
  120826. 0,
  120827. 18,
  120828. };
  120829. static long _vq_lengthlist__44c8_s_p9_1[] = {
  120830. 1, 4, 4, 7, 6, 7, 7, 7, 7, 8, 8, 9, 9,10,10,10,
  120831. 10,11,11, 6, 6, 6, 8, 8, 9, 8, 8, 7,10, 8,11,10,
  120832. 12,11,12,12,13,13, 5, 5, 6, 8, 8, 9, 9, 8, 8,10,
  120833. 9,11,11,12,12,13,13,13,13,17, 8, 8, 9, 9, 9, 9,
  120834. 9, 9,10, 9,12,10,12,12,13,12,13,13,17, 9, 8, 9,
  120835. 9, 9, 9, 9, 9,10,10,12,12,12,12,13,13,13,13,17,
  120836. 13,13, 9, 9,10,10,10,10,11,11,12,11,13,12,13,13,
  120837. 14,15,17,13,13, 9, 8,10, 9,10,10,11,11,12,12,14,
  120838. 13,15,13,14,15,17,17,17, 9,10, 9,10,11,11,12,12,
  120839. 12,12,13,13,14,14,15,15,17,17,17, 9, 8, 9, 8,11,
  120840. 11,12,12,12,12,14,13,14,14,14,15,17,17,17,12,14,
  120841. 9,10,11,11,12,12,14,13,13,14,15,13,15,15,17,17,
  120842. 17,13,11,10, 8,11, 9,13,12,13,13,13,13,13,14,14,
  120843. 14,17,17,17,17,17,11,12,11,11,13,13,14,13,15,14,
  120844. 13,15,16,15,17,17,17,17,17,11,11,12, 8,13,12,14,
  120845. 13,17,14,15,14,15,14,17,17,17,17,17,15,15,12,12,
  120846. 12,12,13,14,14,14,15,14,17,14,17,17,17,17,17,16,
  120847. 17,12,12,13,12,13,13,14,14,14,14,14,14,17,17,17,
  120848. 17,17,17,17,14,14,13,12,13,13,15,15,14,13,15,17,
  120849. 17,17,17,17,17,17,17,13,14,13,13,13,13,14,15,15,
  120850. 15,14,15,17,17,17,17,17,17,17,16,15,13,14,13,13,
  120851. 14,14,15,14,14,16,17,17,17,17,17,17,17,16,16,13,
  120852. 14,13,13,14,14,15,14,15,14,
  120853. };
  120854. static float _vq_quantthresh__44c8_s_p9_1[] = {
  120855. -416.5, -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5,
  120856. -24.5, 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5,
  120857. 367.5, 416.5,
  120858. };
  120859. static long _vq_quantmap__44c8_s_p9_1[] = {
  120860. 17, 15, 13, 11, 9, 7, 5, 3,
  120861. 1, 0, 2, 4, 6, 8, 10, 12,
  120862. 14, 16, 18,
  120863. };
  120864. static encode_aux_threshmatch _vq_auxt__44c8_s_p9_1 = {
  120865. _vq_quantthresh__44c8_s_p9_1,
  120866. _vq_quantmap__44c8_s_p9_1,
  120867. 19,
  120868. 19
  120869. };
  120870. static static_codebook _44c8_s_p9_1 = {
  120871. 2, 361,
  120872. _vq_lengthlist__44c8_s_p9_1,
  120873. 1, -518287360, 1622704128, 5, 0,
  120874. _vq_quantlist__44c8_s_p9_1,
  120875. NULL,
  120876. &_vq_auxt__44c8_s_p9_1,
  120877. NULL,
  120878. 0
  120879. };
  120880. static long _vq_quantlist__44c8_s_p9_2[] = {
  120881. 24,
  120882. 23,
  120883. 25,
  120884. 22,
  120885. 26,
  120886. 21,
  120887. 27,
  120888. 20,
  120889. 28,
  120890. 19,
  120891. 29,
  120892. 18,
  120893. 30,
  120894. 17,
  120895. 31,
  120896. 16,
  120897. 32,
  120898. 15,
  120899. 33,
  120900. 14,
  120901. 34,
  120902. 13,
  120903. 35,
  120904. 12,
  120905. 36,
  120906. 11,
  120907. 37,
  120908. 10,
  120909. 38,
  120910. 9,
  120911. 39,
  120912. 8,
  120913. 40,
  120914. 7,
  120915. 41,
  120916. 6,
  120917. 42,
  120918. 5,
  120919. 43,
  120920. 4,
  120921. 44,
  120922. 3,
  120923. 45,
  120924. 2,
  120925. 46,
  120926. 1,
  120927. 47,
  120928. 0,
  120929. 48,
  120930. };
  120931. static long _vq_lengthlist__44c8_s_p9_2[] = {
  120932. 2, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6,
  120933. 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  120934. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  120935. 7,
  120936. };
  120937. static float _vq_quantthresh__44c8_s_p9_2[] = {
  120938. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  120939. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  120940. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  120941. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  120942. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  120943. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  120944. };
  120945. static long _vq_quantmap__44c8_s_p9_2[] = {
  120946. 47, 45, 43, 41, 39, 37, 35, 33,
  120947. 31, 29, 27, 25, 23, 21, 19, 17,
  120948. 15, 13, 11, 9, 7, 5, 3, 1,
  120949. 0, 2, 4, 6, 8, 10, 12, 14,
  120950. 16, 18, 20, 22, 24, 26, 28, 30,
  120951. 32, 34, 36, 38, 40, 42, 44, 46,
  120952. 48,
  120953. };
  120954. static encode_aux_threshmatch _vq_auxt__44c8_s_p9_2 = {
  120955. _vq_quantthresh__44c8_s_p9_2,
  120956. _vq_quantmap__44c8_s_p9_2,
  120957. 49,
  120958. 49
  120959. };
  120960. static static_codebook _44c8_s_p9_2 = {
  120961. 1, 49,
  120962. _vq_lengthlist__44c8_s_p9_2,
  120963. 1, -526909440, 1611661312, 6, 0,
  120964. _vq_quantlist__44c8_s_p9_2,
  120965. NULL,
  120966. &_vq_auxt__44c8_s_p9_2,
  120967. NULL,
  120968. 0
  120969. };
  120970. static long _huff_lengthlist__44c8_s_short[] = {
  120971. 4,11,13,14,15,15,18,17,19,17, 5, 6, 8, 9,10,10,
  120972. 12,15,19,19, 6, 6, 6, 6, 8, 8,11,14,18,19, 8, 6,
  120973. 5, 4, 6, 7,10,13,16,17, 9, 7, 6, 5, 6, 7, 9,12,
  120974. 15,19,10, 8, 7, 6, 6, 6, 7, 9,13,15,12,10, 9, 8,
  120975. 7, 6, 4, 5,10,15,13,13,11, 8, 6, 6, 4, 2, 7,12,
  120976. 17,15,16,10, 8, 8, 7, 6, 9,12,19,18,17,13,11,10,
  120977. 10, 9,11,14,
  120978. };
  120979. static static_codebook _huff_book__44c8_s_short = {
  120980. 2, 100,
  120981. _huff_lengthlist__44c8_s_short,
  120982. 0, 0, 0, 0, 0,
  120983. NULL,
  120984. NULL,
  120985. NULL,
  120986. NULL,
  120987. 0
  120988. };
  120989. static long _huff_lengthlist__44c9_s_long[] = {
  120990. 3, 8,12,14,15,15,15,13,15,15, 6, 5, 8,10,12,12,
  120991. 13,12,14,13,10, 6, 5, 6, 8, 9,11,11,13,13,13, 8,
  120992. 5, 4, 5, 6, 8,10,11,13,14,10, 7, 5, 4, 5, 7, 9,
  120993. 11,12,13,11, 8, 6, 5, 4, 5, 7, 9,11,12,11,10, 8,
  120994. 7, 5, 4, 5, 9,10,13,13,11,10, 8, 6, 5, 4, 7, 9,
  120995. 15,14,13,12,10, 9, 8, 7, 8, 9,12,12,14,13,12,11,
  120996. 10, 9, 8, 9,
  120997. };
  120998. static static_codebook _huff_book__44c9_s_long = {
  120999. 2, 100,
  121000. _huff_lengthlist__44c9_s_long,
  121001. 0, 0, 0, 0, 0,
  121002. NULL,
  121003. NULL,
  121004. NULL,
  121005. NULL,
  121006. 0
  121007. };
  121008. static long _vq_quantlist__44c9_s_p1_0[] = {
  121009. 1,
  121010. 0,
  121011. 2,
  121012. };
  121013. static long _vq_lengthlist__44c9_s_p1_0[] = {
  121014. 1, 5, 5, 0, 5, 5, 0, 5, 5, 6, 8, 8, 0, 9, 8, 0,
  121015. 9, 8, 6, 8, 8, 0, 8, 9, 0, 8, 9, 0, 0, 0, 0, 0,
  121016. 0, 0, 0, 0, 5, 8, 8, 0, 7, 7, 0, 8, 8, 5, 8, 8,
  121017. 0, 7, 8, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
  121018. 9, 8, 0, 8, 8, 0, 7, 7, 5, 8, 9, 0, 8, 8, 0, 7,
  121019. 7,
  121020. };
  121021. static float _vq_quantthresh__44c9_s_p1_0[] = {
  121022. -0.5, 0.5,
  121023. };
  121024. static long _vq_quantmap__44c9_s_p1_0[] = {
  121025. 1, 0, 2,
  121026. };
  121027. static encode_aux_threshmatch _vq_auxt__44c9_s_p1_0 = {
  121028. _vq_quantthresh__44c9_s_p1_0,
  121029. _vq_quantmap__44c9_s_p1_0,
  121030. 3,
  121031. 3
  121032. };
  121033. static static_codebook _44c9_s_p1_0 = {
  121034. 4, 81,
  121035. _vq_lengthlist__44c9_s_p1_0,
  121036. 1, -535822336, 1611661312, 2, 0,
  121037. _vq_quantlist__44c9_s_p1_0,
  121038. NULL,
  121039. &_vq_auxt__44c9_s_p1_0,
  121040. NULL,
  121041. 0
  121042. };
  121043. static long _vq_quantlist__44c9_s_p2_0[] = {
  121044. 2,
  121045. 1,
  121046. 3,
  121047. 0,
  121048. 4,
  121049. };
  121050. static long _vq_lengthlist__44c9_s_p2_0[] = {
  121051. 3, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0,
  121052. 7, 7, 9, 9, 0, 0, 0, 9, 9, 6, 7, 7, 9, 8, 0, 8,
  121053. 8, 9, 9, 0, 8, 7, 9, 9, 0, 9,10,10,10, 0, 0, 0,
  121054. 11,10, 6, 7, 7, 8, 9, 0, 8, 8, 9, 9, 0, 7, 8, 9,
  121055. 9, 0,10, 9,11,10, 0, 0, 0,10,10, 8, 9, 8,10,10,
  121056. 0,10,10,12,11, 0,10,10,11,11, 0,12,13,13,13, 0,
  121057. 0, 0,13,12, 8, 8, 9,10,10, 0,10,10,11,12, 0,10,
  121058. 10,11,11, 0,13,12,13,13, 0, 0, 0,13,13, 0, 0, 0,
  121059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121060. 0, 0, 0, 0, 0, 0, 6, 8, 7,10,10, 0, 7, 7,10, 9,
  121061. 0, 7, 7,10,10, 0, 9, 9,10,10, 0, 0, 0,10,10, 6,
  121062. 7, 8,10,10, 0, 7, 7, 9,10, 0, 7, 7,10,10, 0, 9,
  121063. 9,10,10, 0, 0, 0,10,10, 8, 9, 9,11,11, 0,10,10,
  121064. 11,11, 0,10,10,11,11, 0,12,12,12,12, 0, 0, 0,12,
  121065. 12, 8, 9,10,11,11, 0, 9,10,11,11, 0,10,10,11,11,
  121066. 0,12,12,12,12, 0, 0, 0,12,12, 0, 0, 0, 0, 0, 0,
  121067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121068. 0, 0, 0, 5, 8, 7,10,10, 0, 7, 7,10,10, 0, 7, 7,
  121069. 10, 9, 0, 9, 9,10,10, 0, 0, 0,10,10, 6, 7, 8,10,
  121070. 10, 0, 7, 7,10,10, 0, 7, 7, 9,10, 0, 9, 9,10,10,
  121071. 0, 0, 0,10,10, 8,10, 9,12,11, 0,10,10,12,11, 0,
  121072. 10, 9,11,11, 0,11,12,12,12, 0, 0, 0,12,12, 8, 9,
  121073. 10,11,12, 0,10,10,11,11, 0, 9,10,11,11, 0,12,11,
  121074. 12,12, 0, 0, 0,12,12, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121076. 7,10, 9,12,12, 0, 9, 9,12,11, 0, 9, 9,11,11, 0,
  121077. 10,10,12,11, 0, 0, 0,11,12, 7, 9,10,12,12, 0, 9,
  121078. 9,11,12, 0, 9, 9,11,11, 0,10,10,11,12, 0, 0, 0,
  121079. 11,11, 9,11,10,13,12, 0,10,10,12,12, 0,10,10,12,
  121080. 12, 0,11,11,12,12, 0, 0, 0,13,12, 9,10,11,12,13,
  121081. 0,10,10,12,12, 0,10,10,12,12, 0,11,12,12,12, 0,
  121082. 0, 0,12,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
  121087. 11,10,13,13, 0,10,10,12,12, 0,10,10,12,12, 0,11,
  121088. 12,12,12, 0, 0, 0,12,12, 9,10,11,13,13, 0,10,10,
  121089. 12,12, 0,10,10,12,12, 0,12,11,13,12, 0, 0, 0,12,
  121090. 12,
  121091. };
  121092. static float _vq_quantthresh__44c9_s_p2_0[] = {
  121093. -1.5, -0.5, 0.5, 1.5,
  121094. };
  121095. static long _vq_quantmap__44c9_s_p2_0[] = {
  121096. 3, 1, 0, 2, 4,
  121097. };
  121098. static encode_aux_threshmatch _vq_auxt__44c9_s_p2_0 = {
  121099. _vq_quantthresh__44c9_s_p2_0,
  121100. _vq_quantmap__44c9_s_p2_0,
  121101. 5,
  121102. 5
  121103. };
  121104. static static_codebook _44c9_s_p2_0 = {
  121105. 4, 625,
  121106. _vq_lengthlist__44c9_s_p2_0,
  121107. 1, -533725184, 1611661312, 3, 0,
  121108. _vq_quantlist__44c9_s_p2_0,
  121109. NULL,
  121110. &_vq_auxt__44c9_s_p2_0,
  121111. NULL,
  121112. 0
  121113. };
  121114. static long _vq_quantlist__44c9_s_p3_0[] = {
  121115. 4,
  121116. 3,
  121117. 5,
  121118. 2,
  121119. 6,
  121120. 1,
  121121. 7,
  121122. 0,
  121123. 8,
  121124. };
  121125. static long _vq_lengthlist__44c9_s_p3_0[] = {
  121126. 3, 4, 4, 5, 5, 6, 6, 8, 8, 0, 4, 4, 5, 5, 6, 7,
  121127. 8, 8, 0, 4, 4, 5, 5, 7, 7, 8, 8, 0, 5, 5, 6, 6,
  121128. 7, 7, 9, 9, 0, 0, 0, 6, 6, 7, 7, 9, 9, 0, 0, 0,
  121129. 7, 7, 8, 8, 9, 9, 0, 0, 0, 7, 7, 8, 8, 9, 9, 0,
  121130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121131. 0,
  121132. };
  121133. static float _vq_quantthresh__44c9_s_p3_0[] = {
  121134. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  121135. };
  121136. static long _vq_quantmap__44c9_s_p3_0[] = {
  121137. 7, 5, 3, 1, 0, 2, 4, 6,
  121138. 8,
  121139. };
  121140. static encode_aux_threshmatch _vq_auxt__44c9_s_p3_0 = {
  121141. _vq_quantthresh__44c9_s_p3_0,
  121142. _vq_quantmap__44c9_s_p3_0,
  121143. 9,
  121144. 9
  121145. };
  121146. static static_codebook _44c9_s_p3_0 = {
  121147. 2, 81,
  121148. _vq_lengthlist__44c9_s_p3_0,
  121149. 1, -531628032, 1611661312, 4, 0,
  121150. _vq_quantlist__44c9_s_p3_0,
  121151. NULL,
  121152. &_vq_auxt__44c9_s_p3_0,
  121153. NULL,
  121154. 0
  121155. };
  121156. static long _vq_quantlist__44c9_s_p4_0[] = {
  121157. 8,
  121158. 7,
  121159. 9,
  121160. 6,
  121161. 10,
  121162. 5,
  121163. 11,
  121164. 4,
  121165. 12,
  121166. 3,
  121167. 13,
  121168. 2,
  121169. 14,
  121170. 1,
  121171. 15,
  121172. 0,
  121173. 16,
  121174. };
  121175. static long _vq_lengthlist__44c9_s_p4_0[] = {
  121176. 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,10,
  121177. 10, 0, 5, 4, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9,10,10,
  121178. 11,11, 0, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,
  121179. 10,11,11, 0, 6, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,
  121180. 11,11,11,12, 0, 0, 0, 6, 6, 7, 7, 8, 8, 9, 9,10,
  121181. 10,11,11,12,12, 0, 0, 0, 7, 7, 7, 7, 9, 9, 9, 9,
  121182. 10,10,11,11,12,12, 0, 0, 0, 7, 7, 7, 8, 9, 9, 9,
  121183. 9,10,10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  121184. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 8, 8, 9,
  121185. 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 0, 0,
  121186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121194. 0,
  121195. };
  121196. static float _vq_quantthresh__44c9_s_p4_0[] = {
  121197. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  121198. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  121199. };
  121200. static long _vq_quantmap__44c9_s_p4_0[] = {
  121201. 15, 13, 11, 9, 7, 5, 3, 1,
  121202. 0, 2, 4, 6, 8, 10, 12, 14,
  121203. 16,
  121204. };
  121205. static encode_aux_threshmatch _vq_auxt__44c9_s_p4_0 = {
  121206. _vq_quantthresh__44c9_s_p4_0,
  121207. _vq_quantmap__44c9_s_p4_0,
  121208. 17,
  121209. 17
  121210. };
  121211. static static_codebook _44c9_s_p4_0 = {
  121212. 2, 289,
  121213. _vq_lengthlist__44c9_s_p4_0,
  121214. 1, -529530880, 1611661312, 5, 0,
  121215. _vq_quantlist__44c9_s_p4_0,
  121216. NULL,
  121217. &_vq_auxt__44c9_s_p4_0,
  121218. NULL,
  121219. 0
  121220. };
  121221. static long _vq_quantlist__44c9_s_p5_0[] = {
  121222. 1,
  121223. 0,
  121224. 2,
  121225. };
  121226. static long _vq_lengthlist__44c9_s_p5_0[] = {
  121227. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 7, 6, 9,10,10,10,
  121228. 10, 9, 4, 6, 7, 9,10,10,10, 9,10, 5, 9, 9, 9,11,
  121229. 11,10,11,11, 7,10, 9,11,12,11,12,12,12, 7, 9,10,
  121230. 11,11,12,12,12,12, 6,10,10,10,12,12,10,12,11, 7,
  121231. 10,10,11,12,12,11,12,12, 7,10,10,11,12,12,12,12,
  121232. 12,
  121233. };
  121234. static float _vq_quantthresh__44c9_s_p5_0[] = {
  121235. -5.5, 5.5,
  121236. };
  121237. static long _vq_quantmap__44c9_s_p5_0[] = {
  121238. 1, 0, 2,
  121239. };
  121240. static encode_aux_threshmatch _vq_auxt__44c9_s_p5_0 = {
  121241. _vq_quantthresh__44c9_s_p5_0,
  121242. _vq_quantmap__44c9_s_p5_0,
  121243. 3,
  121244. 3
  121245. };
  121246. static static_codebook _44c9_s_p5_0 = {
  121247. 4, 81,
  121248. _vq_lengthlist__44c9_s_p5_0,
  121249. 1, -529137664, 1618345984, 2, 0,
  121250. _vq_quantlist__44c9_s_p5_0,
  121251. NULL,
  121252. &_vq_auxt__44c9_s_p5_0,
  121253. NULL,
  121254. 0
  121255. };
  121256. static long _vq_quantlist__44c9_s_p5_1[] = {
  121257. 5,
  121258. 4,
  121259. 6,
  121260. 3,
  121261. 7,
  121262. 2,
  121263. 8,
  121264. 1,
  121265. 9,
  121266. 0,
  121267. 10,
  121268. };
  121269. static long _vq_lengthlist__44c9_s_p5_1[] = {
  121270. 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7,11, 5, 5, 6, 6,
  121271. 7, 7, 7, 7, 8, 8,11, 5, 5, 6, 6, 7, 7, 7, 7, 8,
  121272. 8,11, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8,11,11,11, 6,
  121273. 6, 7, 7, 7, 8, 8, 8,11,11,11, 6, 6, 7, 7, 7, 8,
  121274. 8, 8,11,11,11, 6, 6, 7, 7, 7, 7, 8, 8,11,11,11,
  121275. 7, 7, 7, 7, 7, 7, 8, 8,11,11,11,10,10, 7, 7, 7,
  121276. 7, 8, 8,11,11,11,11,11, 7, 7, 7, 7, 7, 7,11,11,
  121277. 11,11,11, 7, 7, 7, 7, 7, 7,
  121278. };
  121279. static float _vq_quantthresh__44c9_s_p5_1[] = {
  121280. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  121281. 3.5, 4.5,
  121282. };
  121283. static long _vq_quantmap__44c9_s_p5_1[] = {
  121284. 9, 7, 5, 3, 1, 0, 2, 4,
  121285. 6, 8, 10,
  121286. };
  121287. static encode_aux_threshmatch _vq_auxt__44c9_s_p5_1 = {
  121288. _vq_quantthresh__44c9_s_p5_1,
  121289. _vq_quantmap__44c9_s_p5_1,
  121290. 11,
  121291. 11
  121292. };
  121293. static static_codebook _44c9_s_p5_1 = {
  121294. 2, 121,
  121295. _vq_lengthlist__44c9_s_p5_1,
  121296. 1, -531365888, 1611661312, 4, 0,
  121297. _vq_quantlist__44c9_s_p5_1,
  121298. NULL,
  121299. &_vq_auxt__44c9_s_p5_1,
  121300. NULL,
  121301. 0
  121302. };
  121303. static long _vq_quantlist__44c9_s_p6_0[] = {
  121304. 6,
  121305. 5,
  121306. 7,
  121307. 4,
  121308. 8,
  121309. 3,
  121310. 9,
  121311. 2,
  121312. 10,
  121313. 1,
  121314. 11,
  121315. 0,
  121316. 12,
  121317. };
  121318. static long _vq_lengthlist__44c9_s_p6_0[] = {
  121319. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 5, 4, 4,
  121320. 6, 6, 8, 8, 9, 9, 9, 9,10,10, 6, 4, 4, 6, 6, 8,
  121321. 8, 9, 9, 9, 9,10,10, 0, 6, 6, 7, 7, 8, 8, 9, 9,
  121322. 10,10,11,11, 0, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,
  121323. 11, 0,10,10, 8, 8, 9, 9,10,10,11,11,12,12, 0,11,
  121324. 11, 8, 8, 9, 9,10,10,11,11,12,12, 0, 0, 0, 0, 0,
  121325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121329. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121330. };
  121331. static float _vq_quantthresh__44c9_s_p6_0[] = {
  121332. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  121333. 12.5, 17.5, 22.5, 27.5,
  121334. };
  121335. static long _vq_quantmap__44c9_s_p6_0[] = {
  121336. 11, 9, 7, 5, 3, 1, 0, 2,
  121337. 4, 6, 8, 10, 12,
  121338. };
  121339. static encode_aux_threshmatch _vq_auxt__44c9_s_p6_0 = {
  121340. _vq_quantthresh__44c9_s_p6_0,
  121341. _vq_quantmap__44c9_s_p6_0,
  121342. 13,
  121343. 13
  121344. };
  121345. static static_codebook _44c9_s_p6_0 = {
  121346. 2, 169,
  121347. _vq_lengthlist__44c9_s_p6_0,
  121348. 1, -526516224, 1616117760, 4, 0,
  121349. _vq_quantlist__44c9_s_p6_0,
  121350. NULL,
  121351. &_vq_auxt__44c9_s_p6_0,
  121352. NULL,
  121353. 0
  121354. };
  121355. static long _vq_quantlist__44c9_s_p6_1[] = {
  121356. 2,
  121357. 1,
  121358. 3,
  121359. 0,
  121360. 4,
  121361. };
  121362. static long _vq_lengthlist__44c9_s_p6_1[] = {
  121363. 4, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5,
  121364. 5, 5, 5, 5, 5, 5, 5, 5, 5,
  121365. };
  121366. static float _vq_quantthresh__44c9_s_p6_1[] = {
  121367. -1.5, -0.5, 0.5, 1.5,
  121368. };
  121369. static long _vq_quantmap__44c9_s_p6_1[] = {
  121370. 3, 1, 0, 2, 4,
  121371. };
  121372. static encode_aux_threshmatch _vq_auxt__44c9_s_p6_1 = {
  121373. _vq_quantthresh__44c9_s_p6_1,
  121374. _vq_quantmap__44c9_s_p6_1,
  121375. 5,
  121376. 5
  121377. };
  121378. static static_codebook _44c9_s_p6_1 = {
  121379. 2, 25,
  121380. _vq_lengthlist__44c9_s_p6_1,
  121381. 1, -533725184, 1611661312, 3, 0,
  121382. _vq_quantlist__44c9_s_p6_1,
  121383. NULL,
  121384. &_vq_auxt__44c9_s_p6_1,
  121385. NULL,
  121386. 0
  121387. };
  121388. static long _vq_quantlist__44c9_s_p7_0[] = {
  121389. 6,
  121390. 5,
  121391. 7,
  121392. 4,
  121393. 8,
  121394. 3,
  121395. 9,
  121396. 2,
  121397. 10,
  121398. 1,
  121399. 11,
  121400. 0,
  121401. 12,
  121402. };
  121403. static long _vq_lengthlist__44c9_s_p7_0[] = {
  121404. 2, 4, 4, 6, 6, 7, 7, 8, 8,10,10,11,11, 6, 4, 4,
  121405. 6, 6, 8, 8, 9, 9,10,10,12,12, 6, 4, 5, 6, 6, 8,
  121406. 8, 9, 9,10,10,12,12,20, 6, 6, 6, 6, 8, 8, 9,10,
  121407. 11,11,12,12,20, 6, 6, 6, 6, 8, 8,10,10,11,11,12,
  121408. 12,20,10,10, 7, 7, 9, 9,10,10,11,11,12,12,20,11,
  121409. 11, 7, 7, 9, 9,10,10,11,11,12,12,20,20,20, 9, 9,
  121410. 9, 9,11,11,12,12,13,13,20,20,20, 9, 9, 9, 9,11,
  121411. 11,12,12,13,13,20,20,20,13,13,10,10,11,11,12,13,
  121412. 13,13,20,20,20,13,13,10,10,11,11,12,13,13,13,20,
  121413. 20,20,20,19,12,12,12,12,13,13,14,15,19,19,19,19,
  121414. 19,12,12,12,12,13,13,14,14,
  121415. };
  121416. static float _vq_quantthresh__44c9_s_p7_0[] = {
  121417. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  121418. 27.5, 38.5, 49.5, 60.5,
  121419. };
  121420. static long _vq_quantmap__44c9_s_p7_0[] = {
  121421. 11, 9, 7, 5, 3, 1, 0, 2,
  121422. 4, 6, 8, 10, 12,
  121423. };
  121424. static encode_aux_threshmatch _vq_auxt__44c9_s_p7_0 = {
  121425. _vq_quantthresh__44c9_s_p7_0,
  121426. _vq_quantmap__44c9_s_p7_0,
  121427. 13,
  121428. 13
  121429. };
  121430. static static_codebook _44c9_s_p7_0 = {
  121431. 2, 169,
  121432. _vq_lengthlist__44c9_s_p7_0,
  121433. 1, -523206656, 1618345984, 4, 0,
  121434. _vq_quantlist__44c9_s_p7_0,
  121435. NULL,
  121436. &_vq_auxt__44c9_s_p7_0,
  121437. NULL,
  121438. 0
  121439. };
  121440. static long _vq_quantlist__44c9_s_p7_1[] = {
  121441. 5,
  121442. 4,
  121443. 6,
  121444. 3,
  121445. 7,
  121446. 2,
  121447. 8,
  121448. 1,
  121449. 9,
  121450. 0,
  121451. 10,
  121452. };
  121453. static long _vq_lengthlist__44c9_s_p7_1[] = {
  121454. 5, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6,
  121455. 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 7, 7, 7, 7, 7,
  121456. 7, 8, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 6,
  121457. 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7,
  121458. 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
  121459. 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  121460. 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 8, 8,
  121461. 8, 8, 8, 7, 7, 7, 7, 7, 7,
  121462. };
  121463. static float _vq_quantthresh__44c9_s_p7_1[] = {
  121464. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  121465. 3.5, 4.5,
  121466. };
  121467. static long _vq_quantmap__44c9_s_p7_1[] = {
  121468. 9, 7, 5, 3, 1, 0, 2, 4,
  121469. 6, 8, 10,
  121470. };
  121471. static encode_aux_threshmatch _vq_auxt__44c9_s_p7_1 = {
  121472. _vq_quantthresh__44c9_s_p7_1,
  121473. _vq_quantmap__44c9_s_p7_1,
  121474. 11,
  121475. 11
  121476. };
  121477. static static_codebook _44c9_s_p7_1 = {
  121478. 2, 121,
  121479. _vq_lengthlist__44c9_s_p7_1,
  121480. 1, -531365888, 1611661312, 4, 0,
  121481. _vq_quantlist__44c9_s_p7_1,
  121482. NULL,
  121483. &_vq_auxt__44c9_s_p7_1,
  121484. NULL,
  121485. 0
  121486. };
  121487. static long _vq_quantlist__44c9_s_p8_0[] = {
  121488. 7,
  121489. 6,
  121490. 8,
  121491. 5,
  121492. 9,
  121493. 4,
  121494. 10,
  121495. 3,
  121496. 11,
  121497. 2,
  121498. 12,
  121499. 1,
  121500. 13,
  121501. 0,
  121502. 14,
  121503. };
  121504. static long _vq_lengthlist__44c9_s_p8_0[] = {
  121505. 1, 4, 4, 7, 6, 8, 8, 8, 8, 9, 9,10,10,11,10, 6,
  121506. 5, 5, 7, 7, 9, 9, 8, 9,10,10,11,11,12,12, 6, 5,
  121507. 5, 7, 7, 9, 9, 9, 9,10,10,11,11,12,12,21, 7, 8,
  121508. 8, 8, 9, 9, 9, 9,10,10,11,11,12,12,21, 8, 8, 8,
  121509. 8, 9, 9, 9, 9,10,10,11,11,12,12,21,11,12, 9, 9,
  121510. 10,10,10,10,10,11,11,12,12,12,21,12,12, 9, 8,10,
  121511. 10,10,10,11,11,12,12,13,13,21,21,21, 9, 9, 9, 9,
  121512. 11,11,11,11,12,12,12,13,21,20,20, 9, 9, 9, 9,10,
  121513. 11,11,11,12,12,13,13,20,20,20,13,13,10,10,11,11,
  121514. 12,12,13,13,13,13,20,20,20,13,13,10,10,11,11,12,
  121515. 12,13,13,13,13,20,20,20,20,20,12,12,12,12,12,12,
  121516. 13,13,14,14,20,20,20,20,20,12,12,12,11,13,12,13,
  121517. 13,14,14,20,20,20,20,20,15,16,13,12,13,13,14,13,
  121518. 14,14,20,20,20,20,20,16,15,12,12,13,12,14,13,14,
  121519. 14,
  121520. };
  121521. static float _vq_quantthresh__44c9_s_p8_0[] = {
  121522. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  121523. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  121524. };
  121525. static long _vq_quantmap__44c9_s_p8_0[] = {
  121526. 13, 11, 9, 7, 5, 3, 1, 0,
  121527. 2, 4, 6, 8, 10, 12, 14,
  121528. };
  121529. static encode_aux_threshmatch _vq_auxt__44c9_s_p8_0 = {
  121530. _vq_quantthresh__44c9_s_p8_0,
  121531. _vq_quantmap__44c9_s_p8_0,
  121532. 15,
  121533. 15
  121534. };
  121535. static static_codebook _44c9_s_p8_0 = {
  121536. 2, 225,
  121537. _vq_lengthlist__44c9_s_p8_0,
  121538. 1, -520986624, 1620377600, 4, 0,
  121539. _vq_quantlist__44c9_s_p8_0,
  121540. NULL,
  121541. &_vq_auxt__44c9_s_p8_0,
  121542. NULL,
  121543. 0
  121544. };
  121545. static long _vq_quantlist__44c9_s_p8_1[] = {
  121546. 10,
  121547. 9,
  121548. 11,
  121549. 8,
  121550. 12,
  121551. 7,
  121552. 13,
  121553. 6,
  121554. 14,
  121555. 5,
  121556. 15,
  121557. 4,
  121558. 16,
  121559. 3,
  121560. 17,
  121561. 2,
  121562. 18,
  121563. 1,
  121564. 19,
  121565. 0,
  121566. 20,
  121567. };
  121568. static long _vq_lengthlist__44c9_s_p8_1[] = {
  121569. 4, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  121570. 8, 8, 8, 8, 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  121571. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 6, 6, 7, 7, 8,
  121572. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,
  121573. 7, 7, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121574. 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  121575. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 8,
  121576. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,
  121577. 10, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121578. 9, 9, 9,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121579. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9,
  121580. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  121581. 10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121582. 9, 9,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121583. 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9, 9,
  121584. 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9,10,10,10,10,
  121585. 10,10,10, 9, 9, 9, 9, 9, 9,10, 9, 9, 9, 9, 9, 9,
  121586. 9,10,10,10,10,10,10,10, 9, 9, 9,10,10,10,10,10,
  121587. 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10, 9, 9,10,
  121588. 9,10, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,
  121589. 10,10,10,10, 9, 9,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  121590. 10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  121591. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  121592. 10,10, 9, 9,10, 9, 9, 9, 9, 9,10,10,10,10,10,10,
  121593. 10,10,10,10,10, 9, 9,10,10, 9, 9,10, 9, 9, 9,10,
  121594. 10,10,10,10,10,10,10,10,10,10, 9, 9,10, 9, 9, 9,
  121595. 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10, 9,
  121596. 9, 9, 9,10, 9, 9, 9, 9, 9,
  121597. };
  121598. static float _vq_quantthresh__44c9_s_p8_1[] = {
  121599. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  121600. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  121601. 6.5, 7.5, 8.5, 9.5,
  121602. };
  121603. static long _vq_quantmap__44c9_s_p8_1[] = {
  121604. 19, 17, 15, 13, 11, 9, 7, 5,
  121605. 3, 1, 0, 2, 4, 6, 8, 10,
  121606. 12, 14, 16, 18, 20,
  121607. };
  121608. static encode_aux_threshmatch _vq_auxt__44c9_s_p8_1 = {
  121609. _vq_quantthresh__44c9_s_p8_1,
  121610. _vq_quantmap__44c9_s_p8_1,
  121611. 21,
  121612. 21
  121613. };
  121614. static static_codebook _44c9_s_p8_1 = {
  121615. 2, 441,
  121616. _vq_lengthlist__44c9_s_p8_1,
  121617. 1, -529268736, 1611661312, 5, 0,
  121618. _vq_quantlist__44c9_s_p8_1,
  121619. NULL,
  121620. &_vq_auxt__44c9_s_p8_1,
  121621. NULL,
  121622. 0
  121623. };
  121624. static long _vq_quantlist__44c9_s_p9_0[] = {
  121625. 9,
  121626. 8,
  121627. 10,
  121628. 7,
  121629. 11,
  121630. 6,
  121631. 12,
  121632. 5,
  121633. 13,
  121634. 4,
  121635. 14,
  121636. 3,
  121637. 15,
  121638. 2,
  121639. 16,
  121640. 1,
  121641. 17,
  121642. 0,
  121643. 18,
  121644. };
  121645. static long _vq_lengthlist__44c9_s_p9_0[] = {
  121646. 1, 4, 3,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121647. 12,12,12, 4, 5, 6,12,12,12,12,12,12,12,12,12,12,
  121648. 12,12,12,12,12,12, 4, 6, 6,12,12,12,12,12,12,12,
  121649. 12,12,12,12,12,12,12,12,12,12,12,11,12,12,12,12,
  121650. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121651. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121652. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121653. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121654. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121655. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121656. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121657. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121658. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121659. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121660. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121661. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121662. 12,12,12,12,12,12,12,12,12,12,11,11,11,11,11,11,
  121663. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121664. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121665. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121666. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121667. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121668. 11,11,11,11,11,11,11,11,11,
  121669. };
  121670. static float _vq_quantthresh__44c9_s_p9_0[] = {
  121671. -7913.5, -6982.5, -6051.5, -5120.5, -4189.5, -3258.5, -2327.5, -1396.5,
  121672. -465.5, 465.5, 1396.5, 2327.5, 3258.5, 4189.5, 5120.5, 6051.5,
  121673. 6982.5, 7913.5,
  121674. };
  121675. static long _vq_quantmap__44c9_s_p9_0[] = {
  121676. 17, 15, 13, 11, 9, 7, 5, 3,
  121677. 1, 0, 2, 4, 6, 8, 10, 12,
  121678. 14, 16, 18,
  121679. };
  121680. static encode_aux_threshmatch _vq_auxt__44c9_s_p9_0 = {
  121681. _vq_quantthresh__44c9_s_p9_0,
  121682. _vq_quantmap__44c9_s_p9_0,
  121683. 19,
  121684. 19
  121685. };
  121686. static static_codebook _44c9_s_p9_0 = {
  121687. 2, 361,
  121688. _vq_lengthlist__44c9_s_p9_0,
  121689. 1, -508535424, 1631393792, 5, 0,
  121690. _vq_quantlist__44c9_s_p9_0,
  121691. NULL,
  121692. &_vq_auxt__44c9_s_p9_0,
  121693. NULL,
  121694. 0
  121695. };
  121696. static long _vq_quantlist__44c9_s_p9_1[] = {
  121697. 9,
  121698. 8,
  121699. 10,
  121700. 7,
  121701. 11,
  121702. 6,
  121703. 12,
  121704. 5,
  121705. 13,
  121706. 4,
  121707. 14,
  121708. 3,
  121709. 15,
  121710. 2,
  121711. 16,
  121712. 1,
  121713. 17,
  121714. 0,
  121715. 18,
  121716. };
  121717. static long _vq_lengthlist__44c9_s_p9_1[] = {
  121718. 1, 4, 4, 7, 7, 7, 7, 8, 7, 9, 8, 9, 9,10,10,11,
  121719. 11,11,11, 6, 5, 5, 8, 8, 9, 9, 9, 8,10, 9,11,10,
  121720. 12,12,13,12,13,13, 5, 5, 5, 8, 8, 9, 9, 9, 9,10,
  121721. 10,11,11,12,12,13,12,13,13,17, 8, 8, 9, 9, 9, 9,
  121722. 9, 9,10,10,12,11,13,12,13,13,13,13,18, 8, 8, 9,
  121723. 9, 9, 9, 9, 9,11,11,12,12,13,13,13,13,13,13,17,
  121724. 13,12, 9, 9,10,10,10,10,11,11,12,12,12,13,13,13,
  121725. 14,14,18,13,12, 9, 9,10,10,10,10,11,11,12,12,13,
  121726. 13,13,14,14,14,17,18,18,10,10,10,10,11,11,11,12,
  121727. 12,12,14,13,14,13,13,14,18,18,18,10, 9,10, 9,11,
  121728. 11,12,12,12,12,13,13,15,14,14,14,18,18,16,13,14,
  121729. 10,11,11,11,12,13,13,13,13,14,13,13,14,14,18,18,
  121730. 18,14,12,11, 9,11,10,13,12,13,13,13,14,14,14,13,
  121731. 14,18,18,17,18,18,11,12,12,12,13,13,14,13,14,14,
  121732. 13,14,14,14,18,18,18,18,17,12,10,12, 9,13,11,13,
  121733. 14,14,14,14,14,15,14,18,18,17,17,18,14,15,12,13,
  121734. 13,13,14,13,14,14,15,14,15,14,18,17,18,18,18,15,
  121735. 15,12,10,14,10,14,14,13,13,14,14,14,14,18,16,18,
  121736. 18,18,18,17,14,14,13,14,14,13,13,14,14,14,15,15,
  121737. 18,18,18,18,17,17,17,14,14,14,12,14,13,14,14,15,
  121738. 14,15,14,18,18,18,18,18,18,18,17,16,13,13,13,14,
  121739. 14,14,14,15,16,15,18,18,18,18,18,18,18,17,17,13,
  121740. 13,13,13,14,13,14,15,15,15,
  121741. };
  121742. static float _vq_quantthresh__44c9_s_p9_1[] = {
  121743. -416.5, -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5,
  121744. -24.5, 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5,
  121745. 367.5, 416.5,
  121746. };
  121747. static long _vq_quantmap__44c9_s_p9_1[] = {
  121748. 17, 15, 13, 11, 9, 7, 5, 3,
  121749. 1, 0, 2, 4, 6, 8, 10, 12,
  121750. 14, 16, 18,
  121751. };
  121752. static encode_aux_threshmatch _vq_auxt__44c9_s_p9_1 = {
  121753. _vq_quantthresh__44c9_s_p9_1,
  121754. _vq_quantmap__44c9_s_p9_1,
  121755. 19,
  121756. 19
  121757. };
  121758. static static_codebook _44c9_s_p9_1 = {
  121759. 2, 361,
  121760. _vq_lengthlist__44c9_s_p9_1,
  121761. 1, -518287360, 1622704128, 5, 0,
  121762. _vq_quantlist__44c9_s_p9_1,
  121763. NULL,
  121764. &_vq_auxt__44c9_s_p9_1,
  121765. NULL,
  121766. 0
  121767. };
  121768. static long _vq_quantlist__44c9_s_p9_2[] = {
  121769. 24,
  121770. 23,
  121771. 25,
  121772. 22,
  121773. 26,
  121774. 21,
  121775. 27,
  121776. 20,
  121777. 28,
  121778. 19,
  121779. 29,
  121780. 18,
  121781. 30,
  121782. 17,
  121783. 31,
  121784. 16,
  121785. 32,
  121786. 15,
  121787. 33,
  121788. 14,
  121789. 34,
  121790. 13,
  121791. 35,
  121792. 12,
  121793. 36,
  121794. 11,
  121795. 37,
  121796. 10,
  121797. 38,
  121798. 9,
  121799. 39,
  121800. 8,
  121801. 40,
  121802. 7,
  121803. 41,
  121804. 6,
  121805. 42,
  121806. 5,
  121807. 43,
  121808. 4,
  121809. 44,
  121810. 3,
  121811. 45,
  121812. 2,
  121813. 46,
  121814. 1,
  121815. 47,
  121816. 0,
  121817. 48,
  121818. };
  121819. static long _vq_lengthlist__44c9_s_p9_2[] = {
  121820. 2, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6,
  121821. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7,
  121822. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  121823. 7,
  121824. };
  121825. static float _vq_quantthresh__44c9_s_p9_2[] = {
  121826. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  121827. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  121828. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  121829. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  121830. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  121831. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  121832. };
  121833. static long _vq_quantmap__44c9_s_p9_2[] = {
  121834. 47, 45, 43, 41, 39, 37, 35, 33,
  121835. 31, 29, 27, 25, 23, 21, 19, 17,
  121836. 15, 13, 11, 9, 7, 5, 3, 1,
  121837. 0, 2, 4, 6, 8, 10, 12, 14,
  121838. 16, 18, 20, 22, 24, 26, 28, 30,
  121839. 32, 34, 36, 38, 40, 42, 44, 46,
  121840. 48,
  121841. };
  121842. static encode_aux_threshmatch _vq_auxt__44c9_s_p9_2 = {
  121843. _vq_quantthresh__44c9_s_p9_2,
  121844. _vq_quantmap__44c9_s_p9_2,
  121845. 49,
  121846. 49
  121847. };
  121848. static static_codebook _44c9_s_p9_2 = {
  121849. 1, 49,
  121850. _vq_lengthlist__44c9_s_p9_2,
  121851. 1, -526909440, 1611661312, 6, 0,
  121852. _vq_quantlist__44c9_s_p9_2,
  121853. NULL,
  121854. &_vq_auxt__44c9_s_p9_2,
  121855. NULL,
  121856. 0
  121857. };
  121858. static long _huff_lengthlist__44c9_s_short[] = {
  121859. 5,13,18,16,17,17,19,18,19,19, 5, 7,10,11,12,12,
  121860. 13,16,17,18, 6, 6, 7, 7, 9, 9,10,14,17,19, 8, 7,
  121861. 6, 5, 6, 7, 9,12,19,17, 8, 7, 7, 6, 5, 6, 8,11,
  121862. 15,19, 9, 8, 7, 6, 5, 5, 6, 8,13,15,11,10, 8, 8,
  121863. 7, 5, 4, 4,10,14,12,13,11, 9, 7, 6, 4, 2, 6,12,
  121864. 18,16,16,13, 8, 7, 7, 5, 8,13,16,17,18,15,11, 9,
  121865. 9, 8,10,13,
  121866. };
  121867. static static_codebook _huff_book__44c9_s_short = {
  121868. 2, 100,
  121869. _huff_lengthlist__44c9_s_short,
  121870. 0, 0, 0, 0, 0,
  121871. NULL,
  121872. NULL,
  121873. NULL,
  121874. NULL,
  121875. 0
  121876. };
  121877. static long _huff_lengthlist__44c0_s_long[] = {
  121878. 5, 4, 8, 9, 8, 9,10,12,15, 4, 1, 5, 5, 6, 8,11,
  121879. 12,12, 8, 5, 8, 9, 9,11,13,12,12, 9, 5, 8, 5, 7,
  121880. 9,12,13,13, 8, 6, 8, 7, 7, 9,11,11,11, 9, 7, 9,
  121881. 7, 7, 7, 7,10,12,10,10,11, 9, 8, 7, 7, 9,11,11,
  121882. 12,13,12,11, 9, 8, 9,11,13,16,16,15,15,12,10,11,
  121883. 12,
  121884. };
  121885. static static_codebook _huff_book__44c0_s_long = {
  121886. 2, 81,
  121887. _huff_lengthlist__44c0_s_long,
  121888. 0, 0, 0, 0, 0,
  121889. NULL,
  121890. NULL,
  121891. NULL,
  121892. NULL,
  121893. 0
  121894. };
  121895. static long _vq_quantlist__44c0_s_p1_0[] = {
  121896. 1,
  121897. 0,
  121898. 2,
  121899. };
  121900. static long _vq_lengthlist__44c0_s_p1_0[] = {
  121901. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  121902. 0, 0, 5, 7, 7, 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, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  121907. 0, 0, 0, 7, 9, 9, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  121912. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121918. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121922. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121923. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121924. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121928. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121929. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121931. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121932. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121934. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121936. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121937. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121938. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  121947. 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 7, 9, 9, 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, 7, 9, 9, 0, 0, 0,
  121952. 0, 0, 0, 9,10,11, 0, 0, 0, 0, 0, 0, 9,11,10, 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, 7, 9, 9, 0, 0,
  121957. 0, 0, 0, 0, 9,11, 9, 0, 0, 0, 0, 0, 0, 9,10,11,
  121958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121963. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121964. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121968. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121969. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121974. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121980. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121981. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121982. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121983. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121988. 0, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  121993. 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,11,10, 0,
  121998. 0, 0, 0, 0, 0, 9, 9,11, 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, 7, 9,10, 0, 0, 0, 0, 0, 0, 9,10,11,
  122003. 0, 0, 0, 0, 0, 0, 9,11,10, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122285. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122286. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122288. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122293. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122296. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122299. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122302. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122304. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122305. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122306. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122307. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122310. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122311. 0,
  122312. };
  122313. static float _vq_quantthresh__44c0_s_p1_0[] = {
  122314. -0.5, 0.5,
  122315. };
  122316. static long _vq_quantmap__44c0_s_p1_0[] = {
  122317. 1, 0, 2,
  122318. };
  122319. static encode_aux_threshmatch _vq_auxt__44c0_s_p1_0 = {
  122320. _vq_quantthresh__44c0_s_p1_0,
  122321. _vq_quantmap__44c0_s_p1_0,
  122322. 3,
  122323. 3
  122324. };
  122325. static static_codebook _44c0_s_p1_0 = {
  122326. 8, 6561,
  122327. _vq_lengthlist__44c0_s_p1_0,
  122328. 1, -535822336, 1611661312, 2, 0,
  122329. _vq_quantlist__44c0_s_p1_0,
  122330. NULL,
  122331. &_vq_auxt__44c0_s_p1_0,
  122332. NULL,
  122333. 0
  122334. };
  122335. static long _vq_quantlist__44c0_s_p2_0[] = {
  122336. 2,
  122337. 1,
  122338. 3,
  122339. 0,
  122340. 4,
  122341. };
  122342. static long _vq_lengthlist__44c0_s_p2_0[] = {
  122343. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 6, 0, 0,
  122345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122346. 0, 0, 4, 5, 6, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 9,
  122348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122349. 0, 0, 0, 0, 6, 7, 7, 9, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122382. 0,
  122383. };
  122384. static float _vq_quantthresh__44c0_s_p2_0[] = {
  122385. -1.5, -0.5, 0.5, 1.5,
  122386. };
  122387. static long _vq_quantmap__44c0_s_p2_0[] = {
  122388. 3, 1, 0, 2, 4,
  122389. };
  122390. static encode_aux_threshmatch _vq_auxt__44c0_s_p2_0 = {
  122391. _vq_quantthresh__44c0_s_p2_0,
  122392. _vq_quantmap__44c0_s_p2_0,
  122393. 5,
  122394. 5
  122395. };
  122396. static static_codebook _44c0_s_p2_0 = {
  122397. 4, 625,
  122398. _vq_lengthlist__44c0_s_p2_0,
  122399. 1, -533725184, 1611661312, 3, 0,
  122400. _vq_quantlist__44c0_s_p2_0,
  122401. NULL,
  122402. &_vq_auxt__44c0_s_p2_0,
  122403. NULL,
  122404. 0
  122405. };
  122406. static long _vq_quantlist__44c0_s_p3_0[] = {
  122407. 4,
  122408. 3,
  122409. 5,
  122410. 2,
  122411. 6,
  122412. 1,
  122413. 7,
  122414. 0,
  122415. 8,
  122416. };
  122417. static long _vq_lengthlist__44c0_s_p3_0[] = {
  122418. 1, 3, 2, 8, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  122419. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  122420. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  122421. 8, 8, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  122422. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122423. 0,
  122424. };
  122425. static float _vq_quantthresh__44c0_s_p3_0[] = {
  122426. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  122427. };
  122428. static long _vq_quantmap__44c0_s_p3_0[] = {
  122429. 7, 5, 3, 1, 0, 2, 4, 6,
  122430. 8,
  122431. };
  122432. static encode_aux_threshmatch _vq_auxt__44c0_s_p3_0 = {
  122433. _vq_quantthresh__44c0_s_p3_0,
  122434. _vq_quantmap__44c0_s_p3_0,
  122435. 9,
  122436. 9
  122437. };
  122438. static static_codebook _44c0_s_p3_0 = {
  122439. 2, 81,
  122440. _vq_lengthlist__44c0_s_p3_0,
  122441. 1, -531628032, 1611661312, 4, 0,
  122442. _vq_quantlist__44c0_s_p3_0,
  122443. NULL,
  122444. &_vq_auxt__44c0_s_p3_0,
  122445. NULL,
  122446. 0
  122447. };
  122448. static long _vq_quantlist__44c0_s_p4_0[] = {
  122449. 4,
  122450. 3,
  122451. 5,
  122452. 2,
  122453. 6,
  122454. 1,
  122455. 7,
  122456. 0,
  122457. 8,
  122458. };
  122459. static long _vq_lengthlist__44c0_s_p4_0[] = {
  122460. 1, 3, 3, 6, 6, 6, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  122461. 9, 9, 0, 0, 0, 7, 7, 7, 7, 9, 9, 0, 0, 0, 7, 7,
  122462. 7, 8, 9, 9, 0, 0, 0, 7, 7, 7, 7, 9, 9, 0, 0, 0,
  122463. 9, 9, 8, 8,10,10, 0, 0, 0, 8, 9, 8, 8,10,10, 0,
  122464. 0, 0,10,10, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  122465. 10,
  122466. };
  122467. static float _vq_quantthresh__44c0_s_p4_0[] = {
  122468. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  122469. };
  122470. static long _vq_quantmap__44c0_s_p4_0[] = {
  122471. 7, 5, 3, 1, 0, 2, 4, 6,
  122472. 8,
  122473. };
  122474. static encode_aux_threshmatch _vq_auxt__44c0_s_p4_0 = {
  122475. _vq_quantthresh__44c0_s_p4_0,
  122476. _vq_quantmap__44c0_s_p4_0,
  122477. 9,
  122478. 9
  122479. };
  122480. static static_codebook _44c0_s_p4_0 = {
  122481. 2, 81,
  122482. _vq_lengthlist__44c0_s_p4_0,
  122483. 1, -531628032, 1611661312, 4, 0,
  122484. _vq_quantlist__44c0_s_p4_0,
  122485. NULL,
  122486. &_vq_auxt__44c0_s_p4_0,
  122487. NULL,
  122488. 0
  122489. };
  122490. static long _vq_quantlist__44c0_s_p5_0[] = {
  122491. 8,
  122492. 7,
  122493. 9,
  122494. 6,
  122495. 10,
  122496. 5,
  122497. 11,
  122498. 4,
  122499. 12,
  122500. 3,
  122501. 13,
  122502. 2,
  122503. 14,
  122504. 1,
  122505. 15,
  122506. 0,
  122507. 16,
  122508. };
  122509. static long _vq_lengthlist__44c0_s_p5_0[] = {
  122510. 1, 4, 3, 6, 6, 8, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  122511. 11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9, 9,10,10,10,
  122512. 11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  122513. 10,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  122514. 11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  122515. 10,11,11,11,11, 0, 0, 0, 8, 8, 9, 9, 9, 9,10,10,
  122516. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9, 9, 9,10,
  122517. 10,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  122518. 10,10,11,11,11,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  122519. 10,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,
  122520. 10,10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  122521. 9,10,10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  122522. 10,10,11,11,11,11,11,12,12,12,13,13, 0, 0, 0, 0,
  122523. 0, 0, 0,11,10,11,11,11,11,12,12,13,13, 0, 0, 0,
  122524. 0, 0, 0, 0,11,11,12,11,12,12,12,12,13,13, 0, 0,
  122525. 0, 0, 0, 0, 0,11,11,11,12,12,12,12,13,13,13, 0,
  122526. 0, 0, 0, 0, 0, 0,12,12,12,12,12,13,13,13,14,14,
  122527. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  122528. 14,
  122529. };
  122530. static float _vq_quantthresh__44c0_s_p5_0[] = {
  122531. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  122532. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  122533. };
  122534. static long _vq_quantmap__44c0_s_p5_0[] = {
  122535. 15, 13, 11, 9, 7, 5, 3, 1,
  122536. 0, 2, 4, 6, 8, 10, 12, 14,
  122537. 16,
  122538. };
  122539. static encode_aux_threshmatch _vq_auxt__44c0_s_p5_0 = {
  122540. _vq_quantthresh__44c0_s_p5_0,
  122541. _vq_quantmap__44c0_s_p5_0,
  122542. 17,
  122543. 17
  122544. };
  122545. static static_codebook _44c0_s_p5_0 = {
  122546. 2, 289,
  122547. _vq_lengthlist__44c0_s_p5_0,
  122548. 1, -529530880, 1611661312, 5, 0,
  122549. _vq_quantlist__44c0_s_p5_0,
  122550. NULL,
  122551. &_vq_auxt__44c0_s_p5_0,
  122552. NULL,
  122553. 0
  122554. };
  122555. static long _vq_quantlist__44c0_s_p6_0[] = {
  122556. 1,
  122557. 0,
  122558. 2,
  122559. };
  122560. static long _vq_lengthlist__44c0_s_p6_0[] = {
  122561. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,10,
  122562. 9, 9, 4, 6, 7,10, 9, 9,11, 9, 9, 7,10,10,11,11,
  122563. 11,12,10,11, 6, 9, 9,11,10,11,11,10,10, 6, 9, 9,
  122564. 11,10,11,11,10,10, 7,11,10,12,11,11,11,11,11, 7,
  122565. 9, 9,10,10,10,11,11,10, 6, 9, 9,11,10,10,11,10,
  122566. 10,
  122567. };
  122568. static float _vq_quantthresh__44c0_s_p6_0[] = {
  122569. -5.5, 5.5,
  122570. };
  122571. static long _vq_quantmap__44c0_s_p6_0[] = {
  122572. 1, 0, 2,
  122573. };
  122574. static encode_aux_threshmatch _vq_auxt__44c0_s_p6_0 = {
  122575. _vq_quantthresh__44c0_s_p6_0,
  122576. _vq_quantmap__44c0_s_p6_0,
  122577. 3,
  122578. 3
  122579. };
  122580. static static_codebook _44c0_s_p6_0 = {
  122581. 4, 81,
  122582. _vq_lengthlist__44c0_s_p6_0,
  122583. 1, -529137664, 1618345984, 2, 0,
  122584. _vq_quantlist__44c0_s_p6_0,
  122585. NULL,
  122586. &_vq_auxt__44c0_s_p6_0,
  122587. NULL,
  122588. 0
  122589. };
  122590. static long _vq_quantlist__44c0_s_p6_1[] = {
  122591. 5,
  122592. 4,
  122593. 6,
  122594. 3,
  122595. 7,
  122596. 2,
  122597. 8,
  122598. 1,
  122599. 9,
  122600. 0,
  122601. 10,
  122602. };
  122603. static long _vq_lengthlist__44c0_s_p6_1[] = {
  122604. 2, 3, 3, 6, 6, 7, 7, 7, 7, 7, 8,10,10,10, 6, 6,
  122605. 7, 7, 8, 8, 8, 8,10,10,10, 6, 6, 7, 7, 8, 8, 8,
  122606. 8,10,10,10, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  122607. 7, 7, 7, 8, 8, 8, 8,10,10,10, 8, 7, 8, 8, 8, 8,
  122608. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  122609. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  122610. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  122611. 10,10,10, 8, 8, 8, 8, 8, 8,
  122612. };
  122613. static float _vq_quantthresh__44c0_s_p6_1[] = {
  122614. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  122615. 3.5, 4.5,
  122616. };
  122617. static long _vq_quantmap__44c0_s_p6_1[] = {
  122618. 9, 7, 5, 3, 1, 0, 2, 4,
  122619. 6, 8, 10,
  122620. };
  122621. static encode_aux_threshmatch _vq_auxt__44c0_s_p6_1 = {
  122622. _vq_quantthresh__44c0_s_p6_1,
  122623. _vq_quantmap__44c0_s_p6_1,
  122624. 11,
  122625. 11
  122626. };
  122627. static static_codebook _44c0_s_p6_1 = {
  122628. 2, 121,
  122629. _vq_lengthlist__44c0_s_p6_1,
  122630. 1, -531365888, 1611661312, 4, 0,
  122631. _vq_quantlist__44c0_s_p6_1,
  122632. NULL,
  122633. &_vq_auxt__44c0_s_p6_1,
  122634. NULL,
  122635. 0
  122636. };
  122637. static long _vq_quantlist__44c0_s_p7_0[] = {
  122638. 6,
  122639. 5,
  122640. 7,
  122641. 4,
  122642. 8,
  122643. 3,
  122644. 9,
  122645. 2,
  122646. 10,
  122647. 1,
  122648. 11,
  122649. 0,
  122650. 12,
  122651. };
  122652. static long _vq_lengthlist__44c0_s_p7_0[] = {
  122653. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 7, 5, 5,
  122654. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 6, 7, 7, 8,
  122655. 8, 8, 8, 9, 9,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  122656. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  122657. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,11, 0,13,
  122658. 13, 9, 9, 9, 9,10,10,11,11,11,12, 0, 0, 0,10,10,
  122659. 10,10,11,11,11,11,12,12, 0, 0, 0,10,10, 9, 9,11,
  122660. 11,11,12,12,12, 0, 0, 0,13,13,10,10,11,11,12,12,
  122661. 13,13, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  122662. 0, 0, 0, 0,11,11,11,11,13,12,13,13, 0, 0, 0, 0,
  122663. 0,12,12,11,11,12,12,13,13,
  122664. };
  122665. static float _vq_quantthresh__44c0_s_p7_0[] = {
  122666. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  122667. 12.5, 17.5, 22.5, 27.5,
  122668. };
  122669. static long _vq_quantmap__44c0_s_p7_0[] = {
  122670. 11, 9, 7, 5, 3, 1, 0, 2,
  122671. 4, 6, 8, 10, 12,
  122672. };
  122673. static encode_aux_threshmatch _vq_auxt__44c0_s_p7_0 = {
  122674. _vq_quantthresh__44c0_s_p7_0,
  122675. _vq_quantmap__44c0_s_p7_0,
  122676. 13,
  122677. 13
  122678. };
  122679. static static_codebook _44c0_s_p7_0 = {
  122680. 2, 169,
  122681. _vq_lengthlist__44c0_s_p7_0,
  122682. 1, -526516224, 1616117760, 4, 0,
  122683. _vq_quantlist__44c0_s_p7_0,
  122684. NULL,
  122685. &_vq_auxt__44c0_s_p7_0,
  122686. NULL,
  122687. 0
  122688. };
  122689. static long _vq_quantlist__44c0_s_p7_1[] = {
  122690. 2,
  122691. 1,
  122692. 3,
  122693. 0,
  122694. 4,
  122695. };
  122696. static long _vq_lengthlist__44c0_s_p7_1[] = {
  122697. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  122698. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  122699. };
  122700. static float _vq_quantthresh__44c0_s_p7_1[] = {
  122701. -1.5, -0.5, 0.5, 1.5,
  122702. };
  122703. static long _vq_quantmap__44c0_s_p7_1[] = {
  122704. 3, 1, 0, 2, 4,
  122705. };
  122706. static encode_aux_threshmatch _vq_auxt__44c0_s_p7_1 = {
  122707. _vq_quantthresh__44c0_s_p7_1,
  122708. _vq_quantmap__44c0_s_p7_1,
  122709. 5,
  122710. 5
  122711. };
  122712. static static_codebook _44c0_s_p7_1 = {
  122713. 2, 25,
  122714. _vq_lengthlist__44c0_s_p7_1,
  122715. 1, -533725184, 1611661312, 3, 0,
  122716. _vq_quantlist__44c0_s_p7_1,
  122717. NULL,
  122718. &_vq_auxt__44c0_s_p7_1,
  122719. NULL,
  122720. 0
  122721. };
  122722. static long _vq_quantlist__44c0_s_p8_0[] = {
  122723. 2,
  122724. 1,
  122725. 3,
  122726. 0,
  122727. 4,
  122728. };
  122729. static long _vq_lengthlist__44c0_s_p8_0[] = {
  122730. 1, 5, 5,10,10, 6, 9, 8,10,10, 6,10, 9,10,10,10,
  122731. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122732. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122733. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122734. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122735. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122736. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122737. 10,10,10,10,10,10,10,10,10,10,10,10,10, 8,10,10,
  122738. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122739. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122740. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122741. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122742. 10,10,10,10,10,10,10,10,11,11,11,11,11,11,11,11,
  122743. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122744. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122745. 11,11,11,11,11,11,11,11,11,11,10,11,11,11,11,11,
  122746. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122747. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122748. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122749. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122750. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122751. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122752. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122753. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122754. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122755. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122756. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122757. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122758. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122759. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122760. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122761. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122762. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122763. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122764. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122765. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122766. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122767. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122768. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122769. 11,
  122770. };
  122771. static float _vq_quantthresh__44c0_s_p8_0[] = {
  122772. -331.5, -110.5, 110.5, 331.5,
  122773. };
  122774. static long _vq_quantmap__44c0_s_p8_0[] = {
  122775. 3, 1, 0, 2, 4,
  122776. };
  122777. static encode_aux_threshmatch _vq_auxt__44c0_s_p8_0 = {
  122778. _vq_quantthresh__44c0_s_p8_0,
  122779. _vq_quantmap__44c0_s_p8_0,
  122780. 5,
  122781. 5
  122782. };
  122783. static static_codebook _44c0_s_p8_0 = {
  122784. 4, 625,
  122785. _vq_lengthlist__44c0_s_p8_0,
  122786. 1, -518283264, 1627103232, 3, 0,
  122787. _vq_quantlist__44c0_s_p8_0,
  122788. NULL,
  122789. &_vq_auxt__44c0_s_p8_0,
  122790. NULL,
  122791. 0
  122792. };
  122793. static long _vq_quantlist__44c0_s_p8_1[] = {
  122794. 6,
  122795. 5,
  122796. 7,
  122797. 4,
  122798. 8,
  122799. 3,
  122800. 9,
  122801. 2,
  122802. 10,
  122803. 1,
  122804. 11,
  122805. 0,
  122806. 12,
  122807. };
  122808. static long _vq_lengthlist__44c0_s_p8_1[] = {
  122809. 1, 4, 4, 6, 6, 7, 7, 9, 9,11,12,13,12, 6, 5, 5,
  122810. 7, 7, 8, 8,10, 9,12,12,12,12, 6, 5, 5, 7, 7, 8,
  122811. 8,10, 9,12,11,11,13,16, 7, 7, 8, 8, 9, 9,10,10,
  122812. 12,12,13,12,16, 7, 7, 8, 7, 9, 9,10,10,11,12,12,
  122813. 13,16,10,10, 8, 8,10,10,11,12,12,12,13,13,16,11,
  122814. 10, 8, 7,11,10,11,11,12,11,13,13,16,16,16,10,10,
  122815. 10,10,11,11,13,12,13,13,16,16,16,11, 9,11, 9,15,
  122816. 13,12,13,13,13,16,16,16,15,13,11,11,12,13,12,12,
  122817. 14,13,16,16,16,14,13,11,11,13,12,14,13,13,13,16,
  122818. 16,16,16,16,13,13,13,12,14,13,14,14,16,16,16,16,
  122819. 16,13,13,12,12,14,14,15,13,
  122820. };
  122821. static float _vq_quantthresh__44c0_s_p8_1[] = {
  122822. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  122823. 42.5, 59.5, 76.5, 93.5,
  122824. };
  122825. static long _vq_quantmap__44c0_s_p8_1[] = {
  122826. 11, 9, 7, 5, 3, 1, 0, 2,
  122827. 4, 6, 8, 10, 12,
  122828. };
  122829. static encode_aux_threshmatch _vq_auxt__44c0_s_p8_1 = {
  122830. _vq_quantthresh__44c0_s_p8_1,
  122831. _vq_quantmap__44c0_s_p8_1,
  122832. 13,
  122833. 13
  122834. };
  122835. static static_codebook _44c0_s_p8_1 = {
  122836. 2, 169,
  122837. _vq_lengthlist__44c0_s_p8_1,
  122838. 1, -522616832, 1620115456, 4, 0,
  122839. _vq_quantlist__44c0_s_p8_1,
  122840. NULL,
  122841. &_vq_auxt__44c0_s_p8_1,
  122842. NULL,
  122843. 0
  122844. };
  122845. static long _vq_quantlist__44c0_s_p8_2[] = {
  122846. 8,
  122847. 7,
  122848. 9,
  122849. 6,
  122850. 10,
  122851. 5,
  122852. 11,
  122853. 4,
  122854. 12,
  122855. 3,
  122856. 13,
  122857. 2,
  122858. 14,
  122859. 1,
  122860. 15,
  122861. 0,
  122862. 16,
  122863. };
  122864. static long _vq_lengthlist__44c0_s_p8_2[] = {
  122865. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  122866. 8,10,10,10, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  122867. 9, 9,10,10,10, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  122868. 9, 9, 9,10,10,10, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
  122869. 9,10, 9, 9,10,10,10, 7, 7, 8, 8, 9, 8, 9, 9, 9,
  122870. 9,10, 9, 9,10,10,10,10, 8, 8, 8, 8, 9, 8, 9, 9,
  122871. 9, 9, 9,10, 9,10,10,10,10, 7, 7, 8, 8, 9, 9, 9,
  122872. 9, 9, 9,10, 9,10,10,10,10,10, 8, 8, 8, 9, 9, 9,
  122873. 9, 9, 9, 9,10,10,10, 9,11,10,10,10,10, 8, 8, 9,
  122874. 9, 9, 9, 9,10, 9, 9, 9,10,10,10,10,11,11, 9, 9,
  122875. 9, 9, 9, 9, 9, 9,10, 9, 9,10,11,10,10,11,11, 9,
  122876. 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,11,10,11,11,
  122877. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,10,10,11,
  122878. 11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  122879. 11,11,11,11, 9,10, 9,10, 9, 9, 9, 9,10, 9,10,11,
  122880. 10,11,10,10,10,10,10, 9, 9, 9,10, 9, 9, 9,10,11,
  122881. 11,10,11,11,10,11,10,10,10, 9, 9, 9, 9,10, 9, 9,
  122882. 10,11,10,11,11,11,11,10,11,10,10, 9,10, 9, 9, 9,
  122883. 10,
  122884. };
  122885. static float _vq_quantthresh__44c0_s_p8_2[] = {
  122886. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  122887. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  122888. };
  122889. static long _vq_quantmap__44c0_s_p8_2[] = {
  122890. 15, 13, 11, 9, 7, 5, 3, 1,
  122891. 0, 2, 4, 6, 8, 10, 12, 14,
  122892. 16,
  122893. };
  122894. static encode_aux_threshmatch _vq_auxt__44c0_s_p8_2 = {
  122895. _vq_quantthresh__44c0_s_p8_2,
  122896. _vq_quantmap__44c0_s_p8_2,
  122897. 17,
  122898. 17
  122899. };
  122900. static static_codebook _44c0_s_p8_2 = {
  122901. 2, 289,
  122902. _vq_lengthlist__44c0_s_p8_2,
  122903. 1, -529530880, 1611661312, 5, 0,
  122904. _vq_quantlist__44c0_s_p8_2,
  122905. NULL,
  122906. &_vq_auxt__44c0_s_p8_2,
  122907. NULL,
  122908. 0
  122909. };
  122910. static long _huff_lengthlist__44c0_s_short[] = {
  122911. 9, 8,12,11,12,13,14,14,16, 6, 1, 5, 6, 6, 9,12,
  122912. 14,17, 9, 4, 5, 9, 7, 9,13,15,16, 8, 5, 8, 6, 8,
  122913. 10,13,17,17, 9, 6, 7, 7, 8, 9,13,15,17,11, 8, 9,
  122914. 9, 9,10,12,16,16,13, 7, 8, 7, 7, 9,12,14,15,13,
  122915. 6, 7, 5, 5, 7,10,13,13,14, 7, 8, 5, 6, 7, 9,10,
  122916. 12,
  122917. };
  122918. static static_codebook _huff_book__44c0_s_short = {
  122919. 2, 81,
  122920. _huff_lengthlist__44c0_s_short,
  122921. 0, 0, 0, 0, 0,
  122922. NULL,
  122923. NULL,
  122924. NULL,
  122925. NULL,
  122926. 0
  122927. };
  122928. static long _huff_lengthlist__44c0_sm_long[] = {
  122929. 5, 4, 9,10, 9,10,11,12,13, 4, 1, 5, 7, 7, 9,11,
  122930. 12,14, 8, 5, 7, 9, 8,10,13,13,13,10, 7, 9, 4, 6,
  122931. 7,10,12,14, 9, 6, 7, 6, 6, 7,10,12,12, 9, 8, 9,
  122932. 7, 6, 7, 8,11,12,11,11,11, 9, 8, 7, 8,10,12,12,
  122933. 13,14,12,11, 9, 9, 9,12,12,17,17,15,16,12,10,11,
  122934. 13,
  122935. };
  122936. static static_codebook _huff_book__44c0_sm_long = {
  122937. 2, 81,
  122938. _huff_lengthlist__44c0_sm_long,
  122939. 0, 0, 0, 0, 0,
  122940. NULL,
  122941. NULL,
  122942. NULL,
  122943. NULL,
  122944. 0
  122945. };
  122946. static long _vq_quantlist__44c0_sm_p1_0[] = {
  122947. 1,
  122948. 0,
  122949. 2,
  122950. };
  122951. static long _vq_lengthlist__44c0_sm_p1_0[] = {
  122952. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  122953. 0, 0, 5, 7, 7, 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, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  122958. 0, 0, 0, 7, 8, 9, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  122963. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122964. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122968. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122969. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122974. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122980. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122981. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122982. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122983. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 7, 0, 0, 0, 0,
  122998. 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0,
  123003. 0, 0, 0, 9,10,10, 0, 0, 0, 0, 0, 0, 9,10,10, 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, 7, 9, 9, 0, 0,
  123008. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  123009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123011. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123014. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123015. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123016. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123017. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123018. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123020. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123022. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123023. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123025. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123026. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123027. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123028. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123029. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123030. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123031. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123032. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123033. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123034. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123035. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123036. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123037. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123039. 0, 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, 5, 7, 8, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  123044. 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  123049. 0, 0, 0, 0, 0, 9, 9,10, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  123054. 0, 0, 0, 0, 0, 0, 9,10,10, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123362. 0,
  123363. };
  123364. static float _vq_quantthresh__44c0_sm_p1_0[] = {
  123365. -0.5, 0.5,
  123366. };
  123367. static long _vq_quantmap__44c0_sm_p1_0[] = {
  123368. 1, 0, 2,
  123369. };
  123370. static encode_aux_threshmatch _vq_auxt__44c0_sm_p1_0 = {
  123371. _vq_quantthresh__44c0_sm_p1_0,
  123372. _vq_quantmap__44c0_sm_p1_0,
  123373. 3,
  123374. 3
  123375. };
  123376. static static_codebook _44c0_sm_p1_0 = {
  123377. 8, 6561,
  123378. _vq_lengthlist__44c0_sm_p1_0,
  123379. 1, -535822336, 1611661312, 2, 0,
  123380. _vq_quantlist__44c0_sm_p1_0,
  123381. NULL,
  123382. &_vq_auxt__44c0_sm_p1_0,
  123383. NULL,
  123384. 0
  123385. };
  123386. static long _vq_quantlist__44c0_sm_p2_0[] = {
  123387. 2,
  123388. 1,
  123389. 3,
  123390. 0,
  123391. 4,
  123392. };
  123393. static long _vq_lengthlist__44c0_sm_p2_0[] = {
  123394. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 7, 0, 0,
  123396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123397. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 9,
  123399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123400. 0, 0, 0, 0, 7, 7, 7, 9, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123433. 0,
  123434. };
  123435. static float _vq_quantthresh__44c0_sm_p2_0[] = {
  123436. -1.5, -0.5, 0.5, 1.5,
  123437. };
  123438. static long _vq_quantmap__44c0_sm_p2_0[] = {
  123439. 3, 1, 0, 2, 4,
  123440. };
  123441. static encode_aux_threshmatch _vq_auxt__44c0_sm_p2_0 = {
  123442. _vq_quantthresh__44c0_sm_p2_0,
  123443. _vq_quantmap__44c0_sm_p2_0,
  123444. 5,
  123445. 5
  123446. };
  123447. static static_codebook _44c0_sm_p2_0 = {
  123448. 4, 625,
  123449. _vq_lengthlist__44c0_sm_p2_0,
  123450. 1, -533725184, 1611661312, 3, 0,
  123451. _vq_quantlist__44c0_sm_p2_0,
  123452. NULL,
  123453. &_vq_auxt__44c0_sm_p2_0,
  123454. NULL,
  123455. 0
  123456. };
  123457. static long _vq_quantlist__44c0_sm_p3_0[] = {
  123458. 4,
  123459. 3,
  123460. 5,
  123461. 2,
  123462. 6,
  123463. 1,
  123464. 7,
  123465. 0,
  123466. 8,
  123467. };
  123468. static long _vq_lengthlist__44c0_sm_p3_0[] = {
  123469. 1, 3, 3, 7, 7, 0, 0, 0, 0, 0, 5, 4, 7, 7, 0, 0,
  123470. 0, 0, 0, 5, 5, 7, 7, 0, 0, 0, 0, 0, 6, 7, 8, 8,
  123471. 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  123472. 9,10, 0, 0, 0, 0, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0,
  123473. 0, 0,11,11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123474. 0,
  123475. };
  123476. static float _vq_quantthresh__44c0_sm_p3_0[] = {
  123477. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  123478. };
  123479. static long _vq_quantmap__44c0_sm_p3_0[] = {
  123480. 7, 5, 3, 1, 0, 2, 4, 6,
  123481. 8,
  123482. };
  123483. static encode_aux_threshmatch _vq_auxt__44c0_sm_p3_0 = {
  123484. _vq_quantthresh__44c0_sm_p3_0,
  123485. _vq_quantmap__44c0_sm_p3_0,
  123486. 9,
  123487. 9
  123488. };
  123489. static static_codebook _44c0_sm_p3_0 = {
  123490. 2, 81,
  123491. _vq_lengthlist__44c0_sm_p3_0,
  123492. 1, -531628032, 1611661312, 4, 0,
  123493. _vq_quantlist__44c0_sm_p3_0,
  123494. NULL,
  123495. &_vq_auxt__44c0_sm_p3_0,
  123496. NULL,
  123497. 0
  123498. };
  123499. static long _vq_quantlist__44c0_sm_p4_0[] = {
  123500. 4,
  123501. 3,
  123502. 5,
  123503. 2,
  123504. 6,
  123505. 1,
  123506. 7,
  123507. 0,
  123508. 8,
  123509. };
  123510. static long _vq_lengthlist__44c0_sm_p4_0[] = {
  123511. 1, 4, 3, 6, 6, 7, 7, 9, 9, 0, 5, 5, 7, 7, 8, 7,
  123512. 9, 9, 0, 5, 5, 7, 7, 8, 8, 9, 9, 0, 7, 7, 8, 8,
  123513. 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  123514. 9, 9, 9, 9,11,11, 0, 0, 0, 9, 9, 9, 9,11,11, 0,
  123515. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0, 9, 9,11,
  123516. 11,
  123517. };
  123518. static float _vq_quantthresh__44c0_sm_p4_0[] = {
  123519. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  123520. };
  123521. static long _vq_quantmap__44c0_sm_p4_0[] = {
  123522. 7, 5, 3, 1, 0, 2, 4, 6,
  123523. 8,
  123524. };
  123525. static encode_aux_threshmatch _vq_auxt__44c0_sm_p4_0 = {
  123526. _vq_quantthresh__44c0_sm_p4_0,
  123527. _vq_quantmap__44c0_sm_p4_0,
  123528. 9,
  123529. 9
  123530. };
  123531. static static_codebook _44c0_sm_p4_0 = {
  123532. 2, 81,
  123533. _vq_lengthlist__44c0_sm_p4_0,
  123534. 1, -531628032, 1611661312, 4, 0,
  123535. _vq_quantlist__44c0_sm_p4_0,
  123536. NULL,
  123537. &_vq_auxt__44c0_sm_p4_0,
  123538. NULL,
  123539. 0
  123540. };
  123541. static long _vq_quantlist__44c0_sm_p5_0[] = {
  123542. 8,
  123543. 7,
  123544. 9,
  123545. 6,
  123546. 10,
  123547. 5,
  123548. 11,
  123549. 4,
  123550. 12,
  123551. 3,
  123552. 13,
  123553. 2,
  123554. 14,
  123555. 1,
  123556. 15,
  123557. 0,
  123558. 16,
  123559. };
  123560. static long _vq_lengthlist__44c0_sm_p5_0[] = {
  123561. 1, 4, 4, 6, 6, 8, 8, 8, 8, 8, 8, 9, 9,10,10,11,
  123562. 11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,11,
  123563. 11,11, 0, 5, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  123564. 11,11,11, 0, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,10,
  123565. 11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,
  123566. 10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  123567. 11,11,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  123568. 10,11,11,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  123569. 10,10,11,11,12,12,12,13, 0, 0, 0, 0, 0, 9, 9,10,
  123570. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  123571. 10,10,11,11,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  123572. 9,10,10,11,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  123573. 10,10,10,10,11,11,12,12,12,13,13,13, 0, 0, 0, 0,
  123574. 0, 0, 0,10,10,11,11,12,12,12,13,13,13, 0, 0, 0,
  123575. 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,14, 0, 0,
  123576. 0, 0, 0, 0, 0,11,11,12,11,12,12,13,13,13,13, 0,
  123577. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,13,14,14,
  123578. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  123579. 14,
  123580. };
  123581. static float _vq_quantthresh__44c0_sm_p5_0[] = {
  123582. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  123583. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  123584. };
  123585. static long _vq_quantmap__44c0_sm_p5_0[] = {
  123586. 15, 13, 11, 9, 7, 5, 3, 1,
  123587. 0, 2, 4, 6, 8, 10, 12, 14,
  123588. 16,
  123589. };
  123590. static encode_aux_threshmatch _vq_auxt__44c0_sm_p5_0 = {
  123591. _vq_quantthresh__44c0_sm_p5_0,
  123592. _vq_quantmap__44c0_sm_p5_0,
  123593. 17,
  123594. 17
  123595. };
  123596. static static_codebook _44c0_sm_p5_0 = {
  123597. 2, 289,
  123598. _vq_lengthlist__44c0_sm_p5_0,
  123599. 1, -529530880, 1611661312, 5, 0,
  123600. _vq_quantlist__44c0_sm_p5_0,
  123601. NULL,
  123602. &_vq_auxt__44c0_sm_p5_0,
  123603. NULL,
  123604. 0
  123605. };
  123606. static long _vq_quantlist__44c0_sm_p6_0[] = {
  123607. 1,
  123608. 0,
  123609. 2,
  123610. };
  123611. static long _vq_lengthlist__44c0_sm_p6_0[] = {
  123612. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  123613. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,10,11,
  123614. 11,11,10,10, 6, 9, 9,11,11,10,11,10,10, 6, 9, 9,
  123615. 11,10,11,11,10,10, 7,11,10,11,11,11,11,11,11, 6,
  123616. 9, 9,11,10,10,11,11,10, 6, 9, 9,11,10,10,11,10,
  123617. 11,
  123618. };
  123619. static float _vq_quantthresh__44c0_sm_p6_0[] = {
  123620. -5.5, 5.5,
  123621. };
  123622. static long _vq_quantmap__44c0_sm_p6_0[] = {
  123623. 1, 0, 2,
  123624. };
  123625. static encode_aux_threshmatch _vq_auxt__44c0_sm_p6_0 = {
  123626. _vq_quantthresh__44c0_sm_p6_0,
  123627. _vq_quantmap__44c0_sm_p6_0,
  123628. 3,
  123629. 3
  123630. };
  123631. static static_codebook _44c0_sm_p6_0 = {
  123632. 4, 81,
  123633. _vq_lengthlist__44c0_sm_p6_0,
  123634. 1, -529137664, 1618345984, 2, 0,
  123635. _vq_quantlist__44c0_sm_p6_0,
  123636. NULL,
  123637. &_vq_auxt__44c0_sm_p6_0,
  123638. NULL,
  123639. 0
  123640. };
  123641. static long _vq_quantlist__44c0_sm_p6_1[] = {
  123642. 5,
  123643. 4,
  123644. 6,
  123645. 3,
  123646. 7,
  123647. 2,
  123648. 8,
  123649. 1,
  123650. 9,
  123651. 0,
  123652. 10,
  123653. };
  123654. static long _vq_lengthlist__44c0_sm_p6_1[] = {
  123655. 2, 4, 4, 6, 6, 7, 7, 7, 7, 7, 8, 9, 5, 5, 6, 6,
  123656. 7, 7, 8, 8, 8, 8, 9, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  123657. 8,10, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  123658. 7, 7, 7, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 8, 8,
  123659. 8, 8,10,10,10, 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  123660. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  123661. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  123662. 10,10,10, 8, 8, 8, 8, 8, 8,
  123663. };
  123664. static float _vq_quantthresh__44c0_sm_p6_1[] = {
  123665. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  123666. 3.5, 4.5,
  123667. };
  123668. static long _vq_quantmap__44c0_sm_p6_1[] = {
  123669. 9, 7, 5, 3, 1, 0, 2, 4,
  123670. 6, 8, 10,
  123671. };
  123672. static encode_aux_threshmatch _vq_auxt__44c0_sm_p6_1 = {
  123673. _vq_quantthresh__44c0_sm_p6_1,
  123674. _vq_quantmap__44c0_sm_p6_1,
  123675. 11,
  123676. 11
  123677. };
  123678. static static_codebook _44c0_sm_p6_1 = {
  123679. 2, 121,
  123680. _vq_lengthlist__44c0_sm_p6_1,
  123681. 1, -531365888, 1611661312, 4, 0,
  123682. _vq_quantlist__44c0_sm_p6_1,
  123683. NULL,
  123684. &_vq_auxt__44c0_sm_p6_1,
  123685. NULL,
  123686. 0
  123687. };
  123688. static long _vq_quantlist__44c0_sm_p7_0[] = {
  123689. 6,
  123690. 5,
  123691. 7,
  123692. 4,
  123693. 8,
  123694. 3,
  123695. 9,
  123696. 2,
  123697. 10,
  123698. 1,
  123699. 11,
  123700. 0,
  123701. 12,
  123702. };
  123703. static long _vq_lengthlist__44c0_sm_p7_0[] = {
  123704. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 7, 5, 5,
  123705. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 6, 5, 7, 7, 8,
  123706. 8, 8, 8, 9, 9,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  123707. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  123708. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,11, 0,13,
  123709. 13, 9, 9, 9, 9,10,10,11,11,11,12, 0, 0, 0, 9,10,
  123710. 10,10,11,11,12,11,12,12, 0, 0, 0,10,10, 9, 9,11,
  123711. 11,12,12,12,12, 0, 0, 0,13,13,10,10,11,11,12,12,
  123712. 13,13, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  123713. 0, 0, 0, 0,11,12,11,11,13,12,13,13, 0, 0, 0, 0,
  123714. 0,12,12,11,11,13,12,14,14,
  123715. };
  123716. static float _vq_quantthresh__44c0_sm_p7_0[] = {
  123717. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  123718. 12.5, 17.5, 22.5, 27.5,
  123719. };
  123720. static long _vq_quantmap__44c0_sm_p7_0[] = {
  123721. 11, 9, 7, 5, 3, 1, 0, 2,
  123722. 4, 6, 8, 10, 12,
  123723. };
  123724. static encode_aux_threshmatch _vq_auxt__44c0_sm_p7_0 = {
  123725. _vq_quantthresh__44c0_sm_p7_0,
  123726. _vq_quantmap__44c0_sm_p7_0,
  123727. 13,
  123728. 13
  123729. };
  123730. static static_codebook _44c0_sm_p7_0 = {
  123731. 2, 169,
  123732. _vq_lengthlist__44c0_sm_p7_0,
  123733. 1, -526516224, 1616117760, 4, 0,
  123734. _vq_quantlist__44c0_sm_p7_0,
  123735. NULL,
  123736. &_vq_auxt__44c0_sm_p7_0,
  123737. NULL,
  123738. 0
  123739. };
  123740. static long _vq_quantlist__44c0_sm_p7_1[] = {
  123741. 2,
  123742. 1,
  123743. 3,
  123744. 0,
  123745. 4,
  123746. };
  123747. static long _vq_lengthlist__44c0_sm_p7_1[] = {
  123748. 2, 4, 4, 4, 4, 6, 5, 5, 5, 5, 6, 5, 5, 5, 5, 6,
  123749. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  123750. };
  123751. static float _vq_quantthresh__44c0_sm_p7_1[] = {
  123752. -1.5, -0.5, 0.5, 1.5,
  123753. };
  123754. static long _vq_quantmap__44c0_sm_p7_1[] = {
  123755. 3, 1, 0, 2, 4,
  123756. };
  123757. static encode_aux_threshmatch _vq_auxt__44c0_sm_p7_1 = {
  123758. _vq_quantthresh__44c0_sm_p7_1,
  123759. _vq_quantmap__44c0_sm_p7_1,
  123760. 5,
  123761. 5
  123762. };
  123763. static static_codebook _44c0_sm_p7_1 = {
  123764. 2, 25,
  123765. _vq_lengthlist__44c0_sm_p7_1,
  123766. 1, -533725184, 1611661312, 3, 0,
  123767. _vq_quantlist__44c0_sm_p7_1,
  123768. NULL,
  123769. &_vq_auxt__44c0_sm_p7_1,
  123770. NULL,
  123771. 0
  123772. };
  123773. static long _vq_quantlist__44c0_sm_p8_0[] = {
  123774. 4,
  123775. 3,
  123776. 5,
  123777. 2,
  123778. 6,
  123779. 1,
  123780. 7,
  123781. 0,
  123782. 8,
  123783. };
  123784. static long _vq_lengthlist__44c0_sm_p8_0[] = {
  123785. 1, 3, 3,11,11,11,11,11,11, 3, 7, 6,11,11,11,11,
  123786. 11,11, 4, 8, 7,11,11,11,11,11,11,11,11,11,11,11,
  123787. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  123788. 11,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  123789. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  123790. 12,
  123791. };
  123792. static float _vq_quantthresh__44c0_sm_p8_0[] = {
  123793. -773.5, -552.5, -331.5, -110.5, 110.5, 331.5, 552.5, 773.5,
  123794. };
  123795. static long _vq_quantmap__44c0_sm_p8_0[] = {
  123796. 7, 5, 3, 1, 0, 2, 4, 6,
  123797. 8,
  123798. };
  123799. static encode_aux_threshmatch _vq_auxt__44c0_sm_p8_0 = {
  123800. _vq_quantthresh__44c0_sm_p8_0,
  123801. _vq_quantmap__44c0_sm_p8_0,
  123802. 9,
  123803. 9
  123804. };
  123805. static static_codebook _44c0_sm_p8_0 = {
  123806. 2, 81,
  123807. _vq_lengthlist__44c0_sm_p8_0,
  123808. 1, -516186112, 1627103232, 4, 0,
  123809. _vq_quantlist__44c0_sm_p8_0,
  123810. NULL,
  123811. &_vq_auxt__44c0_sm_p8_0,
  123812. NULL,
  123813. 0
  123814. };
  123815. static long _vq_quantlist__44c0_sm_p8_1[] = {
  123816. 6,
  123817. 5,
  123818. 7,
  123819. 4,
  123820. 8,
  123821. 3,
  123822. 9,
  123823. 2,
  123824. 10,
  123825. 1,
  123826. 11,
  123827. 0,
  123828. 12,
  123829. };
  123830. static long _vq_lengthlist__44c0_sm_p8_1[] = {
  123831. 1, 4, 4, 6, 6, 7, 7, 9, 9,10,11,12,12, 6, 5, 5,
  123832. 7, 7, 8, 8,10,10,12,11,12,12, 6, 5, 5, 7, 7, 8,
  123833. 8,10,10,12,11,12,12,17, 7, 7, 8, 8, 9, 9,10,10,
  123834. 12,12,13,13,18, 7, 7, 8, 7, 9, 9,10,10,12,12,12,
  123835. 13,19,10,10, 8, 8,10,10,11,11,12,12,13,14,19,11,
  123836. 10, 8, 7,10,10,11,11,12,12,13,12,19,19,19,10,10,
  123837. 10,10,11,11,12,12,13,13,19,19,19,11, 9,11, 9,14,
  123838. 12,13,12,13,13,19,20,18,13,14,11,11,12,12,13,13,
  123839. 14,13,20,20,20,15,13,11,10,13,11,13,13,14,13,20,
  123840. 20,20,20,20,13,14,12,12,13,13,13,13,20,20,20,20,
  123841. 20,13,13,12,12,16,13,15,13,
  123842. };
  123843. static float _vq_quantthresh__44c0_sm_p8_1[] = {
  123844. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  123845. 42.5, 59.5, 76.5, 93.5,
  123846. };
  123847. static long _vq_quantmap__44c0_sm_p8_1[] = {
  123848. 11, 9, 7, 5, 3, 1, 0, 2,
  123849. 4, 6, 8, 10, 12,
  123850. };
  123851. static encode_aux_threshmatch _vq_auxt__44c0_sm_p8_1 = {
  123852. _vq_quantthresh__44c0_sm_p8_1,
  123853. _vq_quantmap__44c0_sm_p8_1,
  123854. 13,
  123855. 13
  123856. };
  123857. static static_codebook _44c0_sm_p8_1 = {
  123858. 2, 169,
  123859. _vq_lengthlist__44c0_sm_p8_1,
  123860. 1, -522616832, 1620115456, 4, 0,
  123861. _vq_quantlist__44c0_sm_p8_1,
  123862. NULL,
  123863. &_vq_auxt__44c0_sm_p8_1,
  123864. NULL,
  123865. 0
  123866. };
  123867. static long _vq_quantlist__44c0_sm_p8_2[] = {
  123868. 8,
  123869. 7,
  123870. 9,
  123871. 6,
  123872. 10,
  123873. 5,
  123874. 11,
  123875. 4,
  123876. 12,
  123877. 3,
  123878. 13,
  123879. 2,
  123880. 14,
  123881. 1,
  123882. 15,
  123883. 0,
  123884. 16,
  123885. };
  123886. static long _vq_lengthlist__44c0_sm_p8_2[] = {
  123887. 2, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  123888. 8,10, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  123889. 9, 9,10, 6, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  123890. 9, 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9,
  123891. 9, 9, 9, 9,10,10,10, 7, 7, 8, 8, 9, 8, 9, 9, 9,
  123892. 9,10, 9, 9,10,10,10,11, 8, 8, 8, 8, 9, 9, 9, 9,
  123893. 9, 9, 9,10, 9,10,10,10,10, 8, 8, 8, 8, 9, 9, 9,
  123894. 9, 9, 9, 9, 9,10,10,11,10,10, 8, 8, 9, 9, 9, 9,
  123895. 9, 9, 9, 9, 9, 9,10,10,10,10,10,11,11, 8, 8, 9,
  123896. 9, 9, 9, 9, 9, 9, 9, 9,10,11,11,11,11,11, 9, 9,
  123897. 9, 9, 9, 9, 9, 9,10, 9,10, 9,11,11,10,11,11, 9,
  123898. 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,11,10,11,11,
  123899. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,10,11,11,
  123900. 11,11,11, 9, 9,10, 9, 9, 9, 9, 9, 9, 9,10,11,10,
  123901. 11,11,11,11,10,10,10,10, 9, 9, 9, 9, 9, 9,10,11,
  123902. 11,11,11,11,11, 9,10, 9, 9, 9, 9, 9, 9, 9, 9,11,
  123903. 11,10,11,11,11,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  123904. 10,11,10,11,11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9,
  123905. 9,
  123906. };
  123907. static float _vq_quantthresh__44c0_sm_p8_2[] = {
  123908. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  123909. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  123910. };
  123911. static long _vq_quantmap__44c0_sm_p8_2[] = {
  123912. 15, 13, 11, 9, 7, 5, 3, 1,
  123913. 0, 2, 4, 6, 8, 10, 12, 14,
  123914. 16,
  123915. };
  123916. static encode_aux_threshmatch _vq_auxt__44c0_sm_p8_2 = {
  123917. _vq_quantthresh__44c0_sm_p8_2,
  123918. _vq_quantmap__44c0_sm_p8_2,
  123919. 17,
  123920. 17
  123921. };
  123922. static static_codebook _44c0_sm_p8_2 = {
  123923. 2, 289,
  123924. _vq_lengthlist__44c0_sm_p8_2,
  123925. 1, -529530880, 1611661312, 5, 0,
  123926. _vq_quantlist__44c0_sm_p8_2,
  123927. NULL,
  123928. &_vq_auxt__44c0_sm_p8_2,
  123929. NULL,
  123930. 0
  123931. };
  123932. static long _huff_lengthlist__44c0_sm_short[] = {
  123933. 6, 6,12,13,13,14,16,17,17, 4, 2, 5, 8, 7, 9,12,
  123934. 15,15, 9, 4, 5, 9, 7, 9,12,16,18,11, 6, 7, 4, 6,
  123935. 8,11,14,18,10, 5, 6, 5, 5, 7,10,14,17,10, 5, 7,
  123936. 7, 6, 7,10,13,16,11, 5, 7, 7, 7, 8,10,12,15,13,
  123937. 6, 7, 5, 5, 7, 9,12,13,16, 8, 9, 6, 6, 7, 9,10,
  123938. 12,
  123939. };
  123940. static static_codebook _huff_book__44c0_sm_short = {
  123941. 2, 81,
  123942. _huff_lengthlist__44c0_sm_short,
  123943. 0, 0, 0, 0, 0,
  123944. NULL,
  123945. NULL,
  123946. NULL,
  123947. NULL,
  123948. 0
  123949. };
  123950. static long _huff_lengthlist__44c1_s_long[] = {
  123951. 5, 5, 9,10, 9, 9,10,11,12, 5, 1, 5, 6, 6, 7,10,
  123952. 12,14, 9, 5, 6, 8, 8,10,12,14,14,10, 5, 8, 5, 6,
  123953. 8,11,13,14, 9, 5, 7, 6, 6, 8,10,12,11, 9, 7, 9,
  123954. 7, 6, 6, 7,10,10,10, 9,12, 9, 8, 7, 7,10,12,11,
  123955. 11,13,12,10, 9, 8, 9,11,11,14,15,15,13,11, 9, 9,
  123956. 11,
  123957. };
  123958. static static_codebook _huff_book__44c1_s_long = {
  123959. 2, 81,
  123960. _huff_lengthlist__44c1_s_long,
  123961. 0, 0, 0, 0, 0,
  123962. NULL,
  123963. NULL,
  123964. NULL,
  123965. NULL,
  123966. 0
  123967. };
  123968. static long _vq_quantlist__44c1_s_p1_0[] = {
  123969. 1,
  123970. 0,
  123971. 2,
  123972. };
  123973. static long _vq_lengthlist__44c1_s_p1_0[] = {
  123974. 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 7, 6, 0, 0, 0, 0,
  123975. 0, 0, 5, 6, 7, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  123980. 0, 0, 0, 7, 8, 8, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  123985. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124011. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124014. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124015. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124016. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124017. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124018. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 7, 7, 0, 0, 0, 0,
  124020. 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, 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, 7, 8, 8, 0, 0, 0,
  124025. 0, 0, 0, 8, 9,10, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 6, 8, 8, 0, 0,
  124030. 0, 0, 0, 0, 8, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  124031. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124032. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124033. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124034. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124035. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124036. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124037. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124039. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124040. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124041. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124042. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124043. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124044. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124045. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124046. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124048. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124049. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124050. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124055. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124060. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124061. 0, 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, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  124066. 0, 0, 0, 0, 7, 8, 9, 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, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8,10, 9, 0,
  124071. 0, 0, 0, 0, 0, 8, 8, 9, 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, 7, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  124076. 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124384. 0,
  124385. };
  124386. static float _vq_quantthresh__44c1_s_p1_0[] = {
  124387. -0.5, 0.5,
  124388. };
  124389. static long _vq_quantmap__44c1_s_p1_0[] = {
  124390. 1, 0, 2,
  124391. };
  124392. static encode_aux_threshmatch _vq_auxt__44c1_s_p1_0 = {
  124393. _vq_quantthresh__44c1_s_p1_0,
  124394. _vq_quantmap__44c1_s_p1_0,
  124395. 3,
  124396. 3
  124397. };
  124398. static static_codebook _44c1_s_p1_0 = {
  124399. 8, 6561,
  124400. _vq_lengthlist__44c1_s_p1_0,
  124401. 1, -535822336, 1611661312, 2, 0,
  124402. _vq_quantlist__44c1_s_p1_0,
  124403. NULL,
  124404. &_vq_auxt__44c1_s_p1_0,
  124405. NULL,
  124406. 0
  124407. };
  124408. static long _vq_quantlist__44c1_s_p2_0[] = {
  124409. 2,
  124410. 1,
  124411. 3,
  124412. 0,
  124413. 4,
  124414. };
  124415. static long _vq_lengthlist__44c1_s_p2_0[] = {
  124416. 2, 3, 4, 6, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  124418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124419. 0, 0, 4, 4, 5, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 8, 8,
  124421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124422. 0, 0, 0, 0, 6, 6, 6, 8, 8, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124455. 0,
  124456. };
  124457. static float _vq_quantthresh__44c1_s_p2_0[] = {
  124458. -1.5, -0.5, 0.5, 1.5,
  124459. };
  124460. static long _vq_quantmap__44c1_s_p2_0[] = {
  124461. 3, 1, 0, 2, 4,
  124462. };
  124463. static encode_aux_threshmatch _vq_auxt__44c1_s_p2_0 = {
  124464. _vq_quantthresh__44c1_s_p2_0,
  124465. _vq_quantmap__44c1_s_p2_0,
  124466. 5,
  124467. 5
  124468. };
  124469. static static_codebook _44c1_s_p2_0 = {
  124470. 4, 625,
  124471. _vq_lengthlist__44c1_s_p2_0,
  124472. 1, -533725184, 1611661312, 3, 0,
  124473. _vq_quantlist__44c1_s_p2_0,
  124474. NULL,
  124475. &_vq_auxt__44c1_s_p2_0,
  124476. NULL,
  124477. 0
  124478. };
  124479. static long _vq_quantlist__44c1_s_p3_0[] = {
  124480. 4,
  124481. 3,
  124482. 5,
  124483. 2,
  124484. 6,
  124485. 1,
  124486. 7,
  124487. 0,
  124488. 8,
  124489. };
  124490. static long _vq_lengthlist__44c1_s_p3_0[] = {
  124491. 1, 3, 2, 7, 7, 0, 0, 0, 0, 0,13,13, 6, 6, 0, 0,
  124492. 0, 0, 0,12, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  124493. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  124494. 8, 9, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  124495. 0, 0,11,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124496. 0,
  124497. };
  124498. static float _vq_quantthresh__44c1_s_p3_0[] = {
  124499. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  124500. };
  124501. static long _vq_quantmap__44c1_s_p3_0[] = {
  124502. 7, 5, 3, 1, 0, 2, 4, 6,
  124503. 8,
  124504. };
  124505. static encode_aux_threshmatch _vq_auxt__44c1_s_p3_0 = {
  124506. _vq_quantthresh__44c1_s_p3_0,
  124507. _vq_quantmap__44c1_s_p3_0,
  124508. 9,
  124509. 9
  124510. };
  124511. static static_codebook _44c1_s_p3_0 = {
  124512. 2, 81,
  124513. _vq_lengthlist__44c1_s_p3_0,
  124514. 1, -531628032, 1611661312, 4, 0,
  124515. _vq_quantlist__44c1_s_p3_0,
  124516. NULL,
  124517. &_vq_auxt__44c1_s_p3_0,
  124518. NULL,
  124519. 0
  124520. };
  124521. static long _vq_quantlist__44c1_s_p4_0[] = {
  124522. 4,
  124523. 3,
  124524. 5,
  124525. 2,
  124526. 6,
  124527. 1,
  124528. 7,
  124529. 0,
  124530. 8,
  124531. };
  124532. static long _vq_lengthlist__44c1_s_p4_0[] = {
  124533. 1, 3, 3, 6, 5, 6, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  124534. 9, 9, 0, 0, 0, 7, 7, 7, 7, 9, 9, 0, 0, 0, 7, 7,
  124535. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0, 0, 0,
  124536. 9, 9, 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0,
  124537. 0, 0,10,10, 9, 9,11,11, 0, 0, 0, 0, 0, 9, 9,11,
  124538. 11,
  124539. };
  124540. static float _vq_quantthresh__44c1_s_p4_0[] = {
  124541. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  124542. };
  124543. static long _vq_quantmap__44c1_s_p4_0[] = {
  124544. 7, 5, 3, 1, 0, 2, 4, 6,
  124545. 8,
  124546. };
  124547. static encode_aux_threshmatch _vq_auxt__44c1_s_p4_0 = {
  124548. _vq_quantthresh__44c1_s_p4_0,
  124549. _vq_quantmap__44c1_s_p4_0,
  124550. 9,
  124551. 9
  124552. };
  124553. static static_codebook _44c1_s_p4_0 = {
  124554. 2, 81,
  124555. _vq_lengthlist__44c1_s_p4_0,
  124556. 1, -531628032, 1611661312, 4, 0,
  124557. _vq_quantlist__44c1_s_p4_0,
  124558. NULL,
  124559. &_vq_auxt__44c1_s_p4_0,
  124560. NULL,
  124561. 0
  124562. };
  124563. static long _vq_quantlist__44c1_s_p5_0[] = {
  124564. 8,
  124565. 7,
  124566. 9,
  124567. 6,
  124568. 10,
  124569. 5,
  124570. 11,
  124571. 4,
  124572. 12,
  124573. 3,
  124574. 13,
  124575. 2,
  124576. 14,
  124577. 1,
  124578. 15,
  124579. 0,
  124580. 16,
  124581. };
  124582. static long _vq_lengthlist__44c1_s_p5_0[] = {
  124583. 1, 4, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  124584. 11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,10,
  124585. 11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  124586. 10,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  124587. 11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  124588. 10,11,11,12,11, 0, 0, 0, 8, 8, 9, 9, 9,10,10,10,
  124589. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10, 9,10,
  124590. 10,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  124591. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  124592. 10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,
  124593. 10,10,10,11,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  124594. 9,10,10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  124595. 10,10,10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0,
  124596. 0, 0, 0,10,10,11,11,12,12,12,12,13,13, 0, 0, 0,
  124597. 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,13, 0, 0,
  124598. 0, 0, 0, 0, 0,11,11,11,11,12,12,13,13,13,13, 0,
  124599. 0, 0, 0, 0, 0, 0,12,12,12,12,12,12,13,13,14,14,
  124600. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  124601. 14,
  124602. };
  124603. static float _vq_quantthresh__44c1_s_p5_0[] = {
  124604. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  124605. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  124606. };
  124607. static long _vq_quantmap__44c1_s_p5_0[] = {
  124608. 15, 13, 11, 9, 7, 5, 3, 1,
  124609. 0, 2, 4, 6, 8, 10, 12, 14,
  124610. 16,
  124611. };
  124612. static encode_aux_threshmatch _vq_auxt__44c1_s_p5_0 = {
  124613. _vq_quantthresh__44c1_s_p5_0,
  124614. _vq_quantmap__44c1_s_p5_0,
  124615. 17,
  124616. 17
  124617. };
  124618. static static_codebook _44c1_s_p5_0 = {
  124619. 2, 289,
  124620. _vq_lengthlist__44c1_s_p5_0,
  124621. 1, -529530880, 1611661312, 5, 0,
  124622. _vq_quantlist__44c1_s_p5_0,
  124623. NULL,
  124624. &_vq_auxt__44c1_s_p5_0,
  124625. NULL,
  124626. 0
  124627. };
  124628. static long _vq_quantlist__44c1_s_p6_0[] = {
  124629. 1,
  124630. 0,
  124631. 2,
  124632. };
  124633. static long _vq_lengthlist__44c1_s_p6_0[] = {
  124634. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  124635. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 6,10,10,11,11,
  124636. 11,11,10,10, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  124637. 11,10,11,11,10,10, 7,11,10,11,11,11,12,11,11, 7,
  124638. 9, 9,11,10,10,11,11,10, 6, 9, 9,10,10,10,12,10,
  124639. 11,
  124640. };
  124641. static float _vq_quantthresh__44c1_s_p6_0[] = {
  124642. -5.5, 5.5,
  124643. };
  124644. static long _vq_quantmap__44c1_s_p6_0[] = {
  124645. 1, 0, 2,
  124646. };
  124647. static encode_aux_threshmatch _vq_auxt__44c1_s_p6_0 = {
  124648. _vq_quantthresh__44c1_s_p6_0,
  124649. _vq_quantmap__44c1_s_p6_0,
  124650. 3,
  124651. 3
  124652. };
  124653. static static_codebook _44c1_s_p6_0 = {
  124654. 4, 81,
  124655. _vq_lengthlist__44c1_s_p6_0,
  124656. 1, -529137664, 1618345984, 2, 0,
  124657. _vq_quantlist__44c1_s_p6_0,
  124658. NULL,
  124659. &_vq_auxt__44c1_s_p6_0,
  124660. NULL,
  124661. 0
  124662. };
  124663. static long _vq_quantlist__44c1_s_p6_1[] = {
  124664. 5,
  124665. 4,
  124666. 6,
  124667. 3,
  124668. 7,
  124669. 2,
  124670. 8,
  124671. 1,
  124672. 9,
  124673. 0,
  124674. 10,
  124675. };
  124676. static long _vq_lengthlist__44c1_s_p6_1[] = {
  124677. 2, 3, 3, 6, 6, 7, 7, 7, 7, 8, 8,10,10,10, 6, 6,
  124678. 7, 7, 8, 8, 8, 8,10,10,10, 6, 6, 7, 7, 8, 8, 8,
  124679. 8,10,10,10, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  124680. 7, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  124681. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  124682. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  124683. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  124684. 10,10,10, 8, 8, 8, 8, 8, 8,
  124685. };
  124686. static float _vq_quantthresh__44c1_s_p6_1[] = {
  124687. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  124688. 3.5, 4.5,
  124689. };
  124690. static long _vq_quantmap__44c1_s_p6_1[] = {
  124691. 9, 7, 5, 3, 1, 0, 2, 4,
  124692. 6, 8, 10,
  124693. };
  124694. static encode_aux_threshmatch _vq_auxt__44c1_s_p6_1 = {
  124695. _vq_quantthresh__44c1_s_p6_1,
  124696. _vq_quantmap__44c1_s_p6_1,
  124697. 11,
  124698. 11
  124699. };
  124700. static static_codebook _44c1_s_p6_1 = {
  124701. 2, 121,
  124702. _vq_lengthlist__44c1_s_p6_1,
  124703. 1, -531365888, 1611661312, 4, 0,
  124704. _vq_quantlist__44c1_s_p6_1,
  124705. NULL,
  124706. &_vq_auxt__44c1_s_p6_1,
  124707. NULL,
  124708. 0
  124709. };
  124710. static long _vq_quantlist__44c1_s_p7_0[] = {
  124711. 6,
  124712. 5,
  124713. 7,
  124714. 4,
  124715. 8,
  124716. 3,
  124717. 9,
  124718. 2,
  124719. 10,
  124720. 1,
  124721. 11,
  124722. 0,
  124723. 12,
  124724. };
  124725. static long _vq_lengthlist__44c1_s_p7_0[] = {
  124726. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8,10, 9, 7, 5, 6,
  124727. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 5, 7, 7, 8,
  124728. 8, 8, 8, 9, 9,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  124729. 10,10,11,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  124730. 11, 0,12,12, 9, 9, 9,10,10,10,11,11,11,11, 0,13,
  124731. 13, 9, 9, 9, 9,10,10,11,11,11,11, 0, 0, 0,10,10,
  124732. 10,10,11,11,12,11,12,12, 0, 0, 0,10,10,10, 9,11,
  124733. 11,12,11,13,12, 0, 0, 0,13,13,10,10,11,11,12,12,
  124734. 13,13, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  124735. 0, 0, 0, 0,11,12,11,11,12,12,14,13, 0, 0, 0, 0,
  124736. 0,12,11,11,11,13,10,14,13,
  124737. };
  124738. static float _vq_quantthresh__44c1_s_p7_0[] = {
  124739. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  124740. 12.5, 17.5, 22.5, 27.5,
  124741. };
  124742. static long _vq_quantmap__44c1_s_p7_0[] = {
  124743. 11, 9, 7, 5, 3, 1, 0, 2,
  124744. 4, 6, 8, 10, 12,
  124745. };
  124746. static encode_aux_threshmatch _vq_auxt__44c1_s_p7_0 = {
  124747. _vq_quantthresh__44c1_s_p7_0,
  124748. _vq_quantmap__44c1_s_p7_0,
  124749. 13,
  124750. 13
  124751. };
  124752. static static_codebook _44c1_s_p7_0 = {
  124753. 2, 169,
  124754. _vq_lengthlist__44c1_s_p7_0,
  124755. 1, -526516224, 1616117760, 4, 0,
  124756. _vq_quantlist__44c1_s_p7_0,
  124757. NULL,
  124758. &_vq_auxt__44c1_s_p7_0,
  124759. NULL,
  124760. 0
  124761. };
  124762. static long _vq_quantlist__44c1_s_p7_1[] = {
  124763. 2,
  124764. 1,
  124765. 3,
  124766. 0,
  124767. 4,
  124768. };
  124769. static long _vq_lengthlist__44c1_s_p7_1[] = {
  124770. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  124771. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  124772. };
  124773. static float _vq_quantthresh__44c1_s_p7_1[] = {
  124774. -1.5, -0.5, 0.5, 1.5,
  124775. };
  124776. static long _vq_quantmap__44c1_s_p7_1[] = {
  124777. 3, 1, 0, 2, 4,
  124778. };
  124779. static encode_aux_threshmatch _vq_auxt__44c1_s_p7_1 = {
  124780. _vq_quantthresh__44c1_s_p7_1,
  124781. _vq_quantmap__44c1_s_p7_1,
  124782. 5,
  124783. 5
  124784. };
  124785. static static_codebook _44c1_s_p7_1 = {
  124786. 2, 25,
  124787. _vq_lengthlist__44c1_s_p7_1,
  124788. 1, -533725184, 1611661312, 3, 0,
  124789. _vq_quantlist__44c1_s_p7_1,
  124790. NULL,
  124791. &_vq_auxt__44c1_s_p7_1,
  124792. NULL,
  124793. 0
  124794. };
  124795. static long _vq_quantlist__44c1_s_p8_0[] = {
  124796. 6,
  124797. 5,
  124798. 7,
  124799. 4,
  124800. 8,
  124801. 3,
  124802. 9,
  124803. 2,
  124804. 10,
  124805. 1,
  124806. 11,
  124807. 0,
  124808. 12,
  124809. };
  124810. static long _vq_lengthlist__44c1_s_p8_0[] = {
  124811. 1, 4, 3,10,10,10,10,10,10,10,10,10,10, 4, 8, 6,
  124812. 10,10,10,10,10,10,10,10,10,10, 4, 8, 7,10,10,10,
  124813. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124814. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124815. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124816. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124817. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124818. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124819. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124820. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124821. 10,10,10,10,10,10,10,10,10,
  124822. };
  124823. static float _vq_quantthresh__44c1_s_p8_0[] = {
  124824. -1215.5, -994.5, -773.5, -552.5, -331.5, -110.5, 110.5, 331.5,
  124825. 552.5, 773.5, 994.5, 1215.5,
  124826. };
  124827. static long _vq_quantmap__44c1_s_p8_0[] = {
  124828. 11, 9, 7, 5, 3, 1, 0, 2,
  124829. 4, 6, 8, 10, 12,
  124830. };
  124831. static encode_aux_threshmatch _vq_auxt__44c1_s_p8_0 = {
  124832. _vq_quantthresh__44c1_s_p8_0,
  124833. _vq_quantmap__44c1_s_p8_0,
  124834. 13,
  124835. 13
  124836. };
  124837. static static_codebook _44c1_s_p8_0 = {
  124838. 2, 169,
  124839. _vq_lengthlist__44c1_s_p8_0,
  124840. 1, -514541568, 1627103232, 4, 0,
  124841. _vq_quantlist__44c1_s_p8_0,
  124842. NULL,
  124843. &_vq_auxt__44c1_s_p8_0,
  124844. NULL,
  124845. 0
  124846. };
  124847. static long _vq_quantlist__44c1_s_p8_1[] = {
  124848. 6,
  124849. 5,
  124850. 7,
  124851. 4,
  124852. 8,
  124853. 3,
  124854. 9,
  124855. 2,
  124856. 10,
  124857. 1,
  124858. 11,
  124859. 0,
  124860. 12,
  124861. };
  124862. static long _vq_lengthlist__44c1_s_p8_1[] = {
  124863. 1, 4, 4, 6, 5, 7, 7, 9, 9,10,10,12,12, 6, 5, 5,
  124864. 7, 7, 8, 8,10,10,12,11,12,12, 6, 5, 5, 7, 7, 8,
  124865. 8,10,10,11,11,12,12,15, 7, 7, 8, 8, 9, 9,11,11,
  124866. 12,12,13,12,15, 8, 8, 8, 7, 9, 9,10,10,12,12,13,
  124867. 13,16,11,10, 8, 8,10,10,11,11,12,12,13,13,16,11,
  124868. 11, 9, 8,11,10,11,11,12,12,13,12,16,16,16,10,11,
  124869. 10,11,12,12,12,12,13,13,16,16,16,11, 9,11, 9,14,
  124870. 12,12,12,13,13,16,16,16,12,14,11,12,12,12,13,13,
  124871. 14,13,16,16,16,15,13,12,10,13,10,13,14,13,13,16,
  124872. 16,16,16,16,13,14,12,13,13,12,13,13,16,16,16,16,
  124873. 16,13,12,12,11,14,12,15,13,
  124874. };
  124875. static float _vq_quantthresh__44c1_s_p8_1[] = {
  124876. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  124877. 42.5, 59.5, 76.5, 93.5,
  124878. };
  124879. static long _vq_quantmap__44c1_s_p8_1[] = {
  124880. 11, 9, 7, 5, 3, 1, 0, 2,
  124881. 4, 6, 8, 10, 12,
  124882. };
  124883. static encode_aux_threshmatch _vq_auxt__44c1_s_p8_1 = {
  124884. _vq_quantthresh__44c1_s_p8_1,
  124885. _vq_quantmap__44c1_s_p8_1,
  124886. 13,
  124887. 13
  124888. };
  124889. static static_codebook _44c1_s_p8_1 = {
  124890. 2, 169,
  124891. _vq_lengthlist__44c1_s_p8_1,
  124892. 1, -522616832, 1620115456, 4, 0,
  124893. _vq_quantlist__44c1_s_p8_1,
  124894. NULL,
  124895. &_vq_auxt__44c1_s_p8_1,
  124896. NULL,
  124897. 0
  124898. };
  124899. static long _vq_quantlist__44c1_s_p8_2[] = {
  124900. 8,
  124901. 7,
  124902. 9,
  124903. 6,
  124904. 10,
  124905. 5,
  124906. 11,
  124907. 4,
  124908. 12,
  124909. 3,
  124910. 13,
  124911. 2,
  124912. 14,
  124913. 1,
  124914. 15,
  124915. 0,
  124916. 16,
  124917. };
  124918. static long _vq_lengthlist__44c1_s_p8_2[] = {
  124919. 2, 4, 4, 6, 6, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  124920. 8,10,10,10, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  124921. 9, 9,10,10,10, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  124922. 9, 9, 9,10,10,10, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9,
  124923. 9,10, 9, 9,10,10,10, 7, 7, 8, 8, 9, 8, 9, 9, 9,
  124924. 9,10, 9, 9,10,10,11,11, 8, 8, 8, 8, 9, 9, 9, 9,
  124925. 9, 9,10, 9, 9,10,10,10,10, 8, 8, 8, 8, 9, 9, 9,
  124926. 9, 9, 9, 9, 9,10,10,11,11,11, 8, 8, 9, 9, 9, 9,
  124927. 9, 9, 9, 9, 9, 9,10,10,10,10,11,11,11, 8, 8, 9,
  124928. 9, 9, 9,10, 9, 9, 9, 9, 9,11,11,11,11,11, 9, 9,
  124929. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,10,10,11,11, 9,
  124930. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,11,10,11,11,
  124931. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,10,10,11,11,
  124932. 11,11,11, 9, 9, 9,10, 9, 9, 9, 9, 9, 9,10,11,11,
  124933. 11,11,11,11,10,10,10,10, 9, 9, 9, 9, 9, 9,10,11,
  124934. 11,11,11,11,11, 9,10, 9, 9, 9, 9,10, 9, 9, 9,11,
  124935. 11,11,11,11,11,11,10,10, 9, 9, 9, 9, 9, 9,10, 9,
  124936. 11,11,10,11,11,11,11,10,11, 9, 9, 9, 9, 9, 9, 9,
  124937. 9,
  124938. };
  124939. static float _vq_quantthresh__44c1_s_p8_2[] = {
  124940. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  124941. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  124942. };
  124943. static long _vq_quantmap__44c1_s_p8_2[] = {
  124944. 15, 13, 11, 9, 7, 5, 3, 1,
  124945. 0, 2, 4, 6, 8, 10, 12, 14,
  124946. 16,
  124947. };
  124948. static encode_aux_threshmatch _vq_auxt__44c1_s_p8_2 = {
  124949. _vq_quantthresh__44c1_s_p8_2,
  124950. _vq_quantmap__44c1_s_p8_2,
  124951. 17,
  124952. 17
  124953. };
  124954. static static_codebook _44c1_s_p8_2 = {
  124955. 2, 289,
  124956. _vq_lengthlist__44c1_s_p8_2,
  124957. 1, -529530880, 1611661312, 5, 0,
  124958. _vq_quantlist__44c1_s_p8_2,
  124959. NULL,
  124960. &_vq_auxt__44c1_s_p8_2,
  124961. NULL,
  124962. 0
  124963. };
  124964. static long _huff_lengthlist__44c1_s_short[] = {
  124965. 6, 8,13,12,13,14,15,16,16, 4, 2, 4, 7, 6, 8,11,
  124966. 13,15,10, 4, 4, 8, 6, 8,11,14,17,11, 5, 6, 5, 6,
  124967. 8,12,14,17,11, 5, 5, 6, 5, 7,10,13,16,12, 6, 7,
  124968. 8, 7, 8,10,13,15,13, 8, 8, 7, 7, 8,10,12,15,15,
  124969. 7, 7, 5, 5, 7, 9,12,14,15, 8, 8, 6, 6, 7, 8,10,
  124970. 11,
  124971. };
  124972. static static_codebook _huff_book__44c1_s_short = {
  124973. 2, 81,
  124974. _huff_lengthlist__44c1_s_short,
  124975. 0, 0, 0, 0, 0,
  124976. NULL,
  124977. NULL,
  124978. NULL,
  124979. NULL,
  124980. 0
  124981. };
  124982. static long _huff_lengthlist__44c1_sm_long[] = {
  124983. 5, 4, 8,10, 9, 9,10,11,12, 4, 2, 5, 6, 6, 8,10,
  124984. 11,13, 8, 4, 6, 8, 7, 9,12,12,14,10, 6, 8, 4, 5,
  124985. 6, 9,11,12, 9, 5, 6, 5, 5, 6, 9,11,11, 9, 7, 9,
  124986. 6, 5, 5, 7,10,10,10, 9,11, 8, 7, 6, 7, 9,11,11,
  124987. 12,13,10,10, 9, 8, 9,11,11,15,15,12,13,11, 9,10,
  124988. 11,
  124989. };
  124990. static static_codebook _huff_book__44c1_sm_long = {
  124991. 2, 81,
  124992. _huff_lengthlist__44c1_sm_long,
  124993. 0, 0, 0, 0, 0,
  124994. NULL,
  124995. NULL,
  124996. NULL,
  124997. NULL,
  124998. 0
  124999. };
  125000. static long _vq_quantlist__44c1_sm_p1_0[] = {
  125001. 1,
  125002. 0,
  125003. 2,
  125004. };
  125005. static long _vq_lengthlist__44c1_sm_p1_0[] = {
  125006. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  125007. 0, 0, 5, 7, 7, 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, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  125012. 0, 0, 0, 7, 8, 9, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  125017. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125018. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125020. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125022. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125023. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125025. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125026. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125027. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125028. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125029. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125030. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125031. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125032. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125033. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125034. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125035. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125036. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125037. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125039. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125040. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125041. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125042. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125043. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125044. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125045. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125046. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125048. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125049. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125050. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 7, 0, 0, 0, 0,
  125052. 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0,
  125057. 0, 0, 0, 9, 9,10, 0, 0, 0, 0, 0, 0, 9,10,10, 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, 7, 9, 9, 0, 0,
  125062. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  125063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125080. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125091. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125093. 0, 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, 5, 7, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  125098. 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  125103. 0, 0, 0, 0, 0, 8, 9,10, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  125108. 0, 0, 0, 0, 0, 0, 9,10, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125416. 0,
  125417. };
  125418. static float _vq_quantthresh__44c1_sm_p1_0[] = {
  125419. -0.5, 0.5,
  125420. };
  125421. static long _vq_quantmap__44c1_sm_p1_0[] = {
  125422. 1, 0, 2,
  125423. };
  125424. static encode_aux_threshmatch _vq_auxt__44c1_sm_p1_0 = {
  125425. _vq_quantthresh__44c1_sm_p1_0,
  125426. _vq_quantmap__44c1_sm_p1_0,
  125427. 3,
  125428. 3
  125429. };
  125430. static static_codebook _44c1_sm_p1_0 = {
  125431. 8, 6561,
  125432. _vq_lengthlist__44c1_sm_p1_0,
  125433. 1, -535822336, 1611661312, 2, 0,
  125434. _vq_quantlist__44c1_sm_p1_0,
  125435. NULL,
  125436. &_vq_auxt__44c1_sm_p1_0,
  125437. NULL,
  125438. 0
  125439. };
  125440. static long _vq_quantlist__44c1_sm_p2_0[] = {
  125441. 2,
  125442. 1,
  125443. 3,
  125444. 0,
  125445. 4,
  125446. };
  125447. static long _vq_lengthlist__44c1_sm_p2_0[] = {
  125448. 2, 3, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  125450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125451. 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  125453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125454. 0, 0, 0, 0, 6, 6, 7, 9, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125487. 0,
  125488. };
  125489. static float _vq_quantthresh__44c1_sm_p2_0[] = {
  125490. -1.5, -0.5, 0.5, 1.5,
  125491. };
  125492. static long _vq_quantmap__44c1_sm_p2_0[] = {
  125493. 3, 1, 0, 2, 4,
  125494. };
  125495. static encode_aux_threshmatch _vq_auxt__44c1_sm_p2_0 = {
  125496. _vq_quantthresh__44c1_sm_p2_0,
  125497. _vq_quantmap__44c1_sm_p2_0,
  125498. 5,
  125499. 5
  125500. };
  125501. static static_codebook _44c1_sm_p2_0 = {
  125502. 4, 625,
  125503. _vq_lengthlist__44c1_sm_p2_0,
  125504. 1, -533725184, 1611661312, 3, 0,
  125505. _vq_quantlist__44c1_sm_p2_0,
  125506. NULL,
  125507. &_vq_auxt__44c1_sm_p2_0,
  125508. NULL,
  125509. 0
  125510. };
  125511. static long _vq_quantlist__44c1_sm_p3_0[] = {
  125512. 4,
  125513. 3,
  125514. 5,
  125515. 2,
  125516. 6,
  125517. 1,
  125518. 7,
  125519. 0,
  125520. 8,
  125521. };
  125522. static long _vq_lengthlist__44c1_sm_p3_0[] = {
  125523. 1, 3, 3, 7, 7, 0, 0, 0, 0, 0, 5, 5, 6, 6, 0, 0,
  125524. 0, 0, 0, 5, 5, 7, 7, 0, 0, 0, 0, 0, 7, 7, 7, 7,
  125525. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  125526. 8, 9, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  125527. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125528. 0,
  125529. };
  125530. static float _vq_quantthresh__44c1_sm_p3_0[] = {
  125531. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  125532. };
  125533. static long _vq_quantmap__44c1_sm_p3_0[] = {
  125534. 7, 5, 3, 1, 0, 2, 4, 6,
  125535. 8,
  125536. };
  125537. static encode_aux_threshmatch _vq_auxt__44c1_sm_p3_0 = {
  125538. _vq_quantthresh__44c1_sm_p3_0,
  125539. _vq_quantmap__44c1_sm_p3_0,
  125540. 9,
  125541. 9
  125542. };
  125543. static static_codebook _44c1_sm_p3_0 = {
  125544. 2, 81,
  125545. _vq_lengthlist__44c1_sm_p3_0,
  125546. 1, -531628032, 1611661312, 4, 0,
  125547. _vq_quantlist__44c1_sm_p3_0,
  125548. NULL,
  125549. &_vq_auxt__44c1_sm_p3_0,
  125550. NULL,
  125551. 0
  125552. };
  125553. static long _vq_quantlist__44c1_sm_p4_0[] = {
  125554. 4,
  125555. 3,
  125556. 5,
  125557. 2,
  125558. 6,
  125559. 1,
  125560. 7,
  125561. 0,
  125562. 8,
  125563. };
  125564. static long _vq_lengthlist__44c1_sm_p4_0[] = {
  125565. 1, 3, 3, 6, 6, 7, 7, 9, 9, 0, 6, 6, 7, 7, 8, 8,
  125566. 9, 9, 0, 6, 6, 7, 7, 8, 8, 9, 9, 0, 7, 7, 8, 8,
  125567. 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  125568. 8, 8, 9, 9,11,11, 0, 0, 0, 9, 9, 9, 9,11,11, 0,
  125569. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0, 9, 9,11,
  125570. 11,
  125571. };
  125572. static float _vq_quantthresh__44c1_sm_p4_0[] = {
  125573. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  125574. };
  125575. static long _vq_quantmap__44c1_sm_p4_0[] = {
  125576. 7, 5, 3, 1, 0, 2, 4, 6,
  125577. 8,
  125578. };
  125579. static encode_aux_threshmatch _vq_auxt__44c1_sm_p4_0 = {
  125580. _vq_quantthresh__44c1_sm_p4_0,
  125581. _vq_quantmap__44c1_sm_p4_0,
  125582. 9,
  125583. 9
  125584. };
  125585. static static_codebook _44c1_sm_p4_0 = {
  125586. 2, 81,
  125587. _vq_lengthlist__44c1_sm_p4_0,
  125588. 1, -531628032, 1611661312, 4, 0,
  125589. _vq_quantlist__44c1_sm_p4_0,
  125590. NULL,
  125591. &_vq_auxt__44c1_sm_p4_0,
  125592. NULL,
  125593. 0
  125594. };
  125595. static long _vq_quantlist__44c1_sm_p5_0[] = {
  125596. 8,
  125597. 7,
  125598. 9,
  125599. 6,
  125600. 10,
  125601. 5,
  125602. 11,
  125603. 4,
  125604. 12,
  125605. 3,
  125606. 13,
  125607. 2,
  125608. 14,
  125609. 1,
  125610. 15,
  125611. 0,
  125612. 16,
  125613. };
  125614. static long _vq_lengthlist__44c1_sm_p5_0[] = {
  125615. 2, 3, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  125616. 11, 0, 5, 5, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,10,
  125617. 11,11, 0, 5, 5, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,
  125618. 10,11,11, 0, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  125619. 11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  125620. 10,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9,10,10,
  125621. 10,11,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9,10,
  125622. 10,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  125623. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  125624. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  125625. 9, 9,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  125626. 9, 9, 9,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  125627. 9, 9,10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0,
  125628. 0, 0, 0,10,10,11,11,12,12,12,12,13,13, 0, 0, 0,
  125629. 0, 0, 0, 0,11,11,11,11,12,12,13,13,13,13, 0, 0,
  125630. 0, 0, 0, 0, 0,11,11,11,11,12,12,13,13,13,13, 0,
  125631. 0, 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,14,
  125632. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  125633. 14,
  125634. };
  125635. static float _vq_quantthresh__44c1_sm_p5_0[] = {
  125636. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  125637. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  125638. };
  125639. static long _vq_quantmap__44c1_sm_p5_0[] = {
  125640. 15, 13, 11, 9, 7, 5, 3, 1,
  125641. 0, 2, 4, 6, 8, 10, 12, 14,
  125642. 16,
  125643. };
  125644. static encode_aux_threshmatch _vq_auxt__44c1_sm_p5_0 = {
  125645. _vq_quantthresh__44c1_sm_p5_0,
  125646. _vq_quantmap__44c1_sm_p5_0,
  125647. 17,
  125648. 17
  125649. };
  125650. static static_codebook _44c1_sm_p5_0 = {
  125651. 2, 289,
  125652. _vq_lengthlist__44c1_sm_p5_0,
  125653. 1, -529530880, 1611661312, 5, 0,
  125654. _vq_quantlist__44c1_sm_p5_0,
  125655. NULL,
  125656. &_vq_auxt__44c1_sm_p5_0,
  125657. NULL,
  125658. 0
  125659. };
  125660. static long _vq_quantlist__44c1_sm_p6_0[] = {
  125661. 1,
  125662. 0,
  125663. 2,
  125664. };
  125665. static long _vq_lengthlist__44c1_sm_p6_0[] = {
  125666. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  125667. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,10,11,
  125668. 11,11,10,10, 6, 9, 9,11,11,10,11,10,10, 6, 9, 9,
  125669. 11,10,11,11,10,10, 7,11,11,11,11,11,11,11,11, 6,
  125670. 9, 9,11,10,10,11,11,10, 6, 9, 9,10,10,10,11,10,
  125671. 11,
  125672. };
  125673. static float _vq_quantthresh__44c1_sm_p6_0[] = {
  125674. -5.5, 5.5,
  125675. };
  125676. static long _vq_quantmap__44c1_sm_p6_0[] = {
  125677. 1, 0, 2,
  125678. };
  125679. static encode_aux_threshmatch _vq_auxt__44c1_sm_p6_0 = {
  125680. _vq_quantthresh__44c1_sm_p6_0,
  125681. _vq_quantmap__44c1_sm_p6_0,
  125682. 3,
  125683. 3
  125684. };
  125685. static static_codebook _44c1_sm_p6_0 = {
  125686. 4, 81,
  125687. _vq_lengthlist__44c1_sm_p6_0,
  125688. 1, -529137664, 1618345984, 2, 0,
  125689. _vq_quantlist__44c1_sm_p6_0,
  125690. NULL,
  125691. &_vq_auxt__44c1_sm_p6_0,
  125692. NULL,
  125693. 0
  125694. };
  125695. static long _vq_quantlist__44c1_sm_p6_1[] = {
  125696. 5,
  125697. 4,
  125698. 6,
  125699. 3,
  125700. 7,
  125701. 2,
  125702. 8,
  125703. 1,
  125704. 9,
  125705. 0,
  125706. 10,
  125707. };
  125708. static long _vq_lengthlist__44c1_sm_p6_1[] = {
  125709. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8,10, 5, 5, 6, 6,
  125710. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  125711. 8,10, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  125712. 7, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  125713. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  125714. 8, 8, 8, 8, 8, 8, 9, 8,10,10,10,10,10, 8, 8, 8,
  125715. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  125716. 10,10,10, 8, 8, 8, 8, 8, 8,
  125717. };
  125718. static float _vq_quantthresh__44c1_sm_p6_1[] = {
  125719. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  125720. 3.5, 4.5,
  125721. };
  125722. static long _vq_quantmap__44c1_sm_p6_1[] = {
  125723. 9, 7, 5, 3, 1, 0, 2, 4,
  125724. 6, 8, 10,
  125725. };
  125726. static encode_aux_threshmatch _vq_auxt__44c1_sm_p6_1 = {
  125727. _vq_quantthresh__44c1_sm_p6_1,
  125728. _vq_quantmap__44c1_sm_p6_1,
  125729. 11,
  125730. 11
  125731. };
  125732. static static_codebook _44c1_sm_p6_1 = {
  125733. 2, 121,
  125734. _vq_lengthlist__44c1_sm_p6_1,
  125735. 1, -531365888, 1611661312, 4, 0,
  125736. _vq_quantlist__44c1_sm_p6_1,
  125737. NULL,
  125738. &_vq_auxt__44c1_sm_p6_1,
  125739. NULL,
  125740. 0
  125741. };
  125742. static long _vq_quantlist__44c1_sm_p7_0[] = {
  125743. 6,
  125744. 5,
  125745. 7,
  125746. 4,
  125747. 8,
  125748. 3,
  125749. 9,
  125750. 2,
  125751. 10,
  125752. 1,
  125753. 11,
  125754. 0,
  125755. 12,
  125756. };
  125757. static long _vq_lengthlist__44c1_sm_p7_0[] = {
  125758. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 7, 5, 5,
  125759. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 6, 7, 7, 8,
  125760. 8, 8, 8, 9, 9,11,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  125761. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  125762. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,11, 0,13,
  125763. 13, 9, 9, 9, 9,10,10,11,11,12,12, 0, 0, 0, 9,10,
  125764. 9,10,11,11,12,11,13,12, 0, 0, 0,10,10, 9, 9,11,
  125765. 11,12,12,13,12, 0, 0, 0,13,13,10,10,11,11,12,12,
  125766. 13,13, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  125767. 0, 0, 0, 0,11,12,11,11,12,13,14,13, 0, 0, 0, 0,
  125768. 0,12,12,11,11,13,12,14,13,
  125769. };
  125770. static float _vq_quantthresh__44c1_sm_p7_0[] = {
  125771. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  125772. 12.5, 17.5, 22.5, 27.5,
  125773. };
  125774. static long _vq_quantmap__44c1_sm_p7_0[] = {
  125775. 11, 9, 7, 5, 3, 1, 0, 2,
  125776. 4, 6, 8, 10, 12,
  125777. };
  125778. static encode_aux_threshmatch _vq_auxt__44c1_sm_p7_0 = {
  125779. _vq_quantthresh__44c1_sm_p7_0,
  125780. _vq_quantmap__44c1_sm_p7_0,
  125781. 13,
  125782. 13
  125783. };
  125784. static static_codebook _44c1_sm_p7_0 = {
  125785. 2, 169,
  125786. _vq_lengthlist__44c1_sm_p7_0,
  125787. 1, -526516224, 1616117760, 4, 0,
  125788. _vq_quantlist__44c1_sm_p7_0,
  125789. NULL,
  125790. &_vq_auxt__44c1_sm_p7_0,
  125791. NULL,
  125792. 0
  125793. };
  125794. static long _vq_quantlist__44c1_sm_p7_1[] = {
  125795. 2,
  125796. 1,
  125797. 3,
  125798. 0,
  125799. 4,
  125800. };
  125801. static long _vq_lengthlist__44c1_sm_p7_1[] = {
  125802. 2, 4, 4, 4, 5, 6, 5, 5, 5, 5, 6, 5, 5, 5, 5, 6,
  125803. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  125804. };
  125805. static float _vq_quantthresh__44c1_sm_p7_1[] = {
  125806. -1.5, -0.5, 0.5, 1.5,
  125807. };
  125808. static long _vq_quantmap__44c1_sm_p7_1[] = {
  125809. 3, 1, 0, 2, 4,
  125810. };
  125811. static encode_aux_threshmatch _vq_auxt__44c1_sm_p7_1 = {
  125812. _vq_quantthresh__44c1_sm_p7_1,
  125813. _vq_quantmap__44c1_sm_p7_1,
  125814. 5,
  125815. 5
  125816. };
  125817. static static_codebook _44c1_sm_p7_1 = {
  125818. 2, 25,
  125819. _vq_lengthlist__44c1_sm_p7_1,
  125820. 1, -533725184, 1611661312, 3, 0,
  125821. _vq_quantlist__44c1_sm_p7_1,
  125822. NULL,
  125823. &_vq_auxt__44c1_sm_p7_1,
  125824. NULL,
  125825. 0
  125826. };
  125827. static long _vq_quantlist__44c1_sm_p8_0[] = {
  125828. 6,
  125829. 5,
  125830. 7,
  125831. 4,
  125832. 8,
  125833. 3,
  125834. 9,
  125835. 2,
  125836. 10,
  125837. 1,
  125838. 11,
  125839. 0,
  125840. 12,
  125841. };
  125842. static long _vq_lengthlist__44c1_sm_p8_0[] = {
  125843. 1, 3, 3,13,13,13,13,13,13,13,13,13,13, 3, 6, 6,
  125844. 13,13,13,13,13,13,13,13,13,13, 4, 8, 7,13,13,13,
  125845. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125846. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125847. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125848. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125849. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125850. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125851. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125852. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125853. 13,13,13,13,13,13,13,13,13,
  125854. };
  125855. static float _vq_quantthresh__44c1_sm_p8_0[] = {
  125856. -1215.5, -994.5, -773.5, -552.5, -331.5, -110.5, 110.5, 331.5,
  125857. 552.5, 773.5, 994.5, 1215.5,
  125858. };
  125859. static long _vq_quantmap__44c1_sm_p8_0[] = {
  125860. 11, 9, 7, 5, 3, 1, 0, 2,
  125861. 4, 6, 8, 10, 12,
  125862. };
  125863. static encode_aux_threshmatch _vq_auxt__44c1_sm_p8_0 = {
  125864. _vq_quantthresh__44c1_sm_p8_0,
  125865. _vq_quantmap__44c1_sm_p8_0,
  125866. 13,
  125867. 13
  125868. };
  125869. static static_codebook _44c1_sm_p8_0 = {
  125870. 2, 169,
  125871. _vq_lengthlist__44c1_sm_p8_0,
  125872. 1, -514541568, 1627103232, 4, 0,
  125873. _vq_quantlist__44c1_sm_p8_0,
  125874. NULL,
  125875. &_vq_auxt__44c1_sm_p8_0,
  125876. NULL,
  125877. 0
  125878. };
  125879. static long _vq_quantlist__44c1_sm_p8_1[] = {
  125880. 6,
  125881. 5,
  125882. 7,
  125883. 4,
  125884. 8,
  125885. 3,
  125886. 9,
  125887. 2,
  125888. 10,
  125889. 1,
  125890. 11,
  125891. 0,
  125892. 12,
  125893. };
  125894. static long _vq_lengthlist__44c1_sm_p8_1[] = {
  125895. 1, 4, 4, 6, 6, 7, 7, 9, 9,10,11,12,12, 6, 5, 5,
  125896. 7, 7, 8, 7,10,10,11,11,12,12, 6, 5, 5, 7, 7, 8,
  125897. 8,10,10,11,11,12,12,16, 7, 7, 8, 8, 9, 9,11,11,
  125898. 12,12,13,13,17, 7, 7, 8, 7, 9, 9,11,10,12,12,13,
  125899. 13,19,11,10, 8, 8,10,10,11,11,12,12,13,13,19,11,
  125900. 11, 9, 7,11,10,11,11,12,12,13,12,19,19,19,10,10,
  125901. 10,10,11,12,12,12,13,14,18,19,19,11, 9,11, 9,13,
  125902. 12,12,12,13,13,19,20,19,13,15,11,11,12,12,13,13,
  125903. 14,13,18,19,20,15,13,12,10,13,10,13,13,13,14,20,
  125904. 20,20,20,20,13,14,12,12,13,12,13,13,20,20,20,20,
  125905. 20,13,12,12,12,14,12,14,13,
  125906. };
  125907. static float _vq_quantthresh__44c1_sm_p8_1[] = {
  125908. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  125909. 42.5, 59.5, 76.5, 93.5,
  125910. };
  125911. static long _vq_quantmap__44c1_sm_p8_1[] = {
  125912. 11, 9, 7, 5, 3, 1, 0, 2,
  125913. 4, 6, 8, 10, 12,
  125914. };
  125915. static encode_aux_threshmatch _vq_auxt__44c1_sm_p8_1 = {
  125916. _vq_quantthresh__44c1_sm_p8_1,
  125917. _vq_quantmap__44c1_sm_p8_1,
  125918. 13,
  125919. 13
  125920. };
  125921. static static_codebook _44c1_sm_p8_1 = {
  125922. 2, 169,
  125923. _vq_lengthlist__44c1_sm_p8_1,
  125924. 1, -522616832, 1620115456, 4, 0,
  125925. _vq_quantlist__44c1_sm_p8_1,
  125926. NULL,
  125927. &_vq_auxt__44c1_sm_p8_1,
  125928. NULL,
  125929. 0
  125930. };
  125931. static long _vq_quantlist__44c1_sm_p8_2[] = {
  125932. 8,
  125933. 7,
  125934. 9,
  125935. 6,
  125936. 10,
  125937. 5,
  125938. 11,
  125939. 4,
  125940. 12,
  125941. 3,
  125942. 13,
  125943. 2,
  125944. 14,
  125945. 1,
  125946. 15,
  125947. 0,
  125948. 16,
  125949. };
  125950. static long _vq_lengthlist__44c1_sm_p8_2[] = {
  125951. 2, 5, 5, 6, 6, 7, 6, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  125952. 8,10, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  125953. 9, 9,10, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  125954. 9, 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9,
  125955. 9, 9, 9, 9,10,10,10, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  125956. 9, 9, 9, 9, 9,10,11,11, 8, 8, 8, 8, 9, 9, 9, 9,
  125957. 9, 9,10,10, 9,10,10,10,10, 8, 8, 8, 8, 9, 9, 9,
  125958. 9, 9, 9, 9, 9,10,10,11,10,10, 8, 8, 9, 9, 9, 9,
  125959. 9, 9, 9, 9, 9, 9,10, 9,10,10,10,11,11, 8, 8, 9,
  125960. 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,11,11,11, 9, 9,
  125961. 9, 9, 9, 9, 9, 9,10, 9,10, 9,11,11,11,11,11, 9,
  125962. 8, 9, 9, 9, 9, 9, 9, 9,10,10, 9,11,11,10,11,11,
  125963. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,11,11,11,11,
  125964. 11,11,11, 9, 9,10, 9, 9, 9, 9,10, 9,10,10,11,10,
  125965. 11,11,11,11, 9,10,10,10, 9, 9, 9, 9, 9, 9,10,11,
  125966. 11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,
  125967. 11,10,11,11,11,11,10,10, 9, 9, 9, 9, 9, 9,10, 9,
  125968. 10,11,10,11,11,11,11,11,11, 9, 9,10, 9, 9, 9, 9,
  125969. 9,
  125970. };
  125971. static float _vq_quantthresh__44c1_sm_p8_2[] = {
  125972. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  125973. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  125974. };
  125975. static long _vq_quantmap__44c1_sm_p8_2[] = {
  125976. 15, 13, 11, 9, 7, 5, 3, 1,
  125977. 0, 2, 4, 6, 8, 10, 12, 14,
  125978. 16,
  125979. };
  125980. static encode_aux_threshmatch _vq_auxt__44c1_sm_p8_2 = {
  125981. _vq_quantthresh__44c1_sm_p8_2,
  125982. _vq_quantmap__44c1_sm_p8_2,
  125983. 17,
  125984. 17
  125985. };
  125986. static static_codebook _44c1_sm_p8_2 = {
  125987. 2, 289,
  125988. _vq_lengthlist__44c1_sm_p8_2,
  125989. 1, -529530880, 1611661312, 5, 0,
  125990. _vq_quantlist__44c1_sm_p8_2,
  125991. NULL,
  125992. &_vq_auxt__44c1_sm_p8_2,
  125993. NULL,
  125994. 0
  125995. };
  125996. static long _huff_lengthlist__44c1_sm_short[] = {
  125997. 4, 7,13,14,14,15,16,18,18, 4, 2, 5, 8, 7, 9,12,
  125998. 15,15,10, 4, 5,10, 6, 8,11,15,17,12, 5, 7, 5, 6,
  125999. 8,11,14,17,11, 5, 6, 6, 5, 6, 9,13,17,12, 6, 7,
  126000. 6, 5, 6, 8,12,14,14, 7, 8, 6, 6, 7, 9,11,14,14,
  126001. 8, 9, 6, 5, 6, 9,11,13,16,10,10, 7, 6, 7, 8,10,
  126002. 11,
  126003. };
  126004. static static_codebook _huff_book__44c1_sm_short = {
  126005. 2, 81,
  126006. _huff_lengthlist__44c1_sm_short,
  126007. 0, 0, 0, 0, 0,
  126008. NULL,
  126009. NULL,
  126010. NULL,
  126011. NULL,
  126012. 0
  126013. };
  126014. static long _huff_lengthlist__44cn1_s_long[] = {
  126015. 4, 4, 7, 8, 7, 8,10,12,17, 3, 1, 6, 6, 7, 8,10,
  126016. 12,15, 7, 6, 9, 9, 9,11,12,14,17, 8, 6, 9, 6, 7,
  126017. 9,11,13,17, 7, 6, 9, 7, 7, 8, 9,12,15, 8, 8,10,
  126018. 8, 7, 7, 7,10,14, 9,10,12,10, 8, 8, 8,10,14,11,
  126019. 13,15,13,12,11,11,12,16,17,18,18,19,20,18,16,16,
  126020. 20,
  126021. };
  126022. static static_codebook _huff_book__44cn1_s_long = {
  126023. 2, 81,
  126024. _huff_lengthlist__44cn1_s_long,
  126025. 0, 0, 0, 0, 0,
  126026. NULL,
  126027. NULL,
  126028. NULL,
  126029. NULL,
  126030. 0
  126031. };
  126032. static long _vq_quantlist__44cn1_s_p1_0[] = {
  126033. 1,
  126034. 0,
  126035. 2,
  126036. };
  126037. static long _vq_lengthlist__44cn1_s_p1_0[] = {
  126038. 1, 4, 4, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  126039. 0, 0, 5, 7, 7, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0,
  126044. 0, 0, 0, 7, 9,10, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7,10, 9, 0, 0,
  126049. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126050. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126055. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126060. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126080. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0, 0, 0, 0,
  126084. 0, 0, 8,10,10, 0, 0, 0, 0, 0, 0, 8, 9,10, 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, 7,10,10, 0, 0, 0,
  126089. 0, 0, 0, 9, 9,11, 0, 0, 0, 0, 0, 0,10,11,11, 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, 7,10,10, 0, 0,
  126094. 0, 0, 0, 0, 9,11, 9, 0, 0, 0, 0, 0, 0,10,11,11,
  126095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126098. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126099. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126100. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126101. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126102. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126125. 0, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0,
  126130. 0, 0, 0, 0, 8,10,10, 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, 7,10,10, 0, 0, 0, 0, 0, 0,10,11,11, 0,
  126135. 0, 0, 0, 0, 0, 9, 9,11, 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, 7,10,10, 0, 0, 0, 0, 0, 0,10,11,11,
  126140. 0, 0, 0, 0, 0, 0, 9,11, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126448. 0,
  126449. };
  126450. static float _vq_quantthresh__44cn1_s_p1_0[] = {
  126451. -0.5, 0.5,
  126452. };
  126453. static long _vq_quantmap__44cn1_s_p1_0[] = {
  126454. 1, 0, 2,
  126455. };
  126456. static encode_aux_threshmatch _vq_auxt__44cn1_s_p1_0 = {
  126457. _vq_quantthresh__44cn1_s_p1_0,
  126458. _vq_quantmap__44cn1_s_p1_0,
  126459. 3,
  126460. 3
  126461. };
  126462. static static_codebook _44cn1_s_p1_0 = {
  126463. 8, 6561,
  126464. _vq_lengthlist__44cn1_s_p1_0,
  126465. 1, -535822336, 1611661312, 2, 0,
  126466. _vq_quantlist__44cn1_s_p1_0,
  126467. NULL,
  126468. &_vq_auxt__44cn1_s_p1_0,
  126469. NULL,
  126470. 0
  126471. };
  126472. static long _vq_quantlist__44cn1_s_p2_0[] = {
  126473. 2,
  126474. 1,
  126475. 3,
  126476. 0,
  126477. 4,
  126478. };
  126479. static long _vq_lengthlist__44cn1_s_p2_0[] = {
  126480. 1, 4, 4, 7, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 7, 0, 0,
  126482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126483. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 9,
  126485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126486. 0, 0, 0, 0, 6, 7, 7, 9, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126519. 0,
  126520. };
  126521. static float _vq_quantthresh__44cn1_s_p2_0[] = {
  126522. -1.5, -0.5, 0.5, 1.5,
  126523. };
  126524. static long _vq_quantmap__44cn1_s_p2_0[] = {
  126525. 3, 1, 0, 2, 4,
  126526. };
  126527. static encode_aux_threshmatch _vq_auxt__44cn1_s_p2_0 = {
  126528. _vq_quantthresh__44cn1_s_p2_0,
  126529. _vq_quantmap__44cn1_s_p2_0,
  126530. 5,
  126531. 5
  126532. };
  126533. static static_codebook _44cn1_s_p2_0 = {
  126534. 4, 625,
  126535. _vq_lengthlist__44cn1_s_p2_0,
  126536. 1, -533725184, 1611661312, 3, 0,
  126537. _vq_quantlist__44cn1_s_p2_0,
  126538. NULL,
  126539. &_vq_auxt__44cn1_s_p2_0,
  126540. NULL,
  126541. 0
  126542. };
  126543. static long _vq_quantlist__44cn1_s_p3_0[] = {
  126544. 4,
  126545. 3,
  126546. 5,
  126547. 2,
  126548. 6,
  126549. 1,
  126550. 7,
  126551. 0,
  126552. 8,
  126553. };
  126554. static long _vq_lengthlist__44cn1_s_p3_0[] = {
  126555. 1, 2, 3, 7, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  126556. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  126557. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  126558. 9, 8, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  126559. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126560. 0,
  126561. };
  126562. static float _vq_quantthresh__44cn1_s_p3_0[] = {
  126563. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  126564. };
  126565. static long _vq_quantmap__44cn1_s_p3_0[] = {
  126566. 7, 5, 3, 1, 0, 2, 4, 6,
  126567. 8,
  126568. };
  126569. static encode_aux_threshmatch _vq_auxt__44cn1_s_p3_0 = {
  126570. _vq_quantthresh__44cn1_s_p3_0,
  126571. _vq_quantmap__44cn1_s_p3_0,
  126572. 9,
  126573. 9
  126574. };
  126575. static static_codebook _44cn1_s_p3_0 = {
  126576. 2, 81,
  126577. _vq_lengthlist__44cn1_s_p3_0,
  126578. 1, -531628032, 1611661312, 4, 0,
  126579. _vq_quantlist__44cn1_s_p3_0,
  126580. NULL,
  126581. &_vq_auxt__44cn1_s_p3_0,
  126582. NULL,
  126583. 0
  126584. };
  126585. static long _vq_quantlist__44cn1_s_p4_0[] = {
  126586. 4,
  126587. 3,
  126588. 5,
  126589. 2,
  126590. 6,
  126591. 1,
  126592. 7,
  126593. 0,
  126594. 8,
  126595. };
  126596. static long _vq_lengthlist__44cn1_s_p4_0[] = {
  126597. 1, 3, 3, 6, 6, 6, 6, 8, 8, 0, 0, 0, 6, 6, 7, 7,
  126598. 9, 9, 0, 0, 0, 6, 6, 7, 7, 9, 9, 0, 0, 0, 7, 7,
  126599. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0, 0, 0,
  126600. 9, 9, 9, 9,10,10, 0, 0, 0, 9, 9, 9, 9,10,10, 0,
  126601. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0,10,10,11,
  126602. 11,
  126603. };
  126604. static float _vq_quantthresh__44cn1_s_p4_0[] = {
  126605. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  126606. };
  126607. static long _vq_quantmap__44cn1_s_p4_0[] = {
  126608. 7, 5, 3, 1, 0, 2, 4, 6,
  126609. 8,
  126610. };
  126611. static encode_aux_threshmatch _vq_auxt__44cn1_s_p4_0 = {
  126612. _vq_quantthresh__44cn1_s_p4_0,
  126613. _vq_quantmap__44cn1_s_p4_0,
  126614. 9,
  126615. 9
  126616. };
  126617. static static_codebook _44cn1_s_p4_0 = {
  126618. 2, 81,
  126619. _vq_lengthlist__44cn1_s_p4_0,
  126620. 1, -531628032, 1611661312, 4, 0,
  126621. _vq_quantlist__44cn1_s_p4_0,
  126622. NULL,
  126623. &_vq_auxt__44cn1_s_p4_0,
  126624. NULL,
  126625. 0
  126626. };
  126627. static long _vq_quantlist__44cn1_s_p5_0[] = {
  126628. 8,
  126629. 7,
  126630. 9,
  126631. 6,
  126632. 10,
  126633. 5,
  126634. 11,
  126635. 4,
  126636. 12,
  126637. 3,
  126638. 13,
  126639. 2,
  126640. 14,
  126641. 1,
  126642. 15,
  126643. 0,
  126644. 16,
  126645. };
  126646. static long _vq_lengthlist__44cn1_s_p5_0[] = {
  126647. 1, 4, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,10,
  126648. 10, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,10,
  126649. 11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  126650. 10,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  126651. 11,11,11,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  126652. 10,11,11,11,11, 0, 0, 0, 8, 8, 9, 9, 9, 9,10,10,
  126653. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9, 9, 9,10,
  126654. 10,10,11,11,11,12,12, 0, 0, 0, 9, 9,10, 9,10,10,
  126655. 10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  126656. 10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,
  126657. 10,10,10,11,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  126658. 9,10,10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  126659. 10,10,11,10,11,11,11,12,13,12,13,13, 0, 0, 0, 0,
  126660. 0, 0, 0,11,10,11,11,12,12,12,12,13,13, 0, 0, 0,
  126661. 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0, 0,
  126662. 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0,
  126663. 0, 0, 0, 0, 0, 0,12,12,12,13,13,13,13,13,14,14,
  126664. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,12,13,13,14,
  126665. 14,
  126666. };
  126667. static float _vq_quantthresh__44cn1_s_p5_0[] = {
  126668. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  126669. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  126670. };
  126671. static long _vq_quantmap__44cn1_s_p5_0[] = {
  126672. 15, 13, 11, 9, 7, 5, 3, 1,
  126673. 0, 2, 4, 6, 8, 10, 12, 14,
  126674. 16,
  126675. };
  126676. static encode_aux_threshmatch _vq_auxt__44cn1_s_p5_0 = {
  126677. _vq_quantthresh__44cn1_s_p5_0,
  126678. _vq_quantmap__44cn1_s_p5_0,
  126679. 17,
  126680. 17
  126681. };
  126682. static static_codebook _44cn1_s_p5_0 = {
  126683. 2, 289,
  126684. _vq_lengthlist__44cn1_s_p5_0,
  126685. 1, -529530880, 1611661312, 5, 0,
  126686. _vq_quantlist__44cn1_s_p5_0,
  126687. NULL,
  126688. &_vq_auxt__44cn1_s_p5_0,
  126689. NULL,
  126690. 0
  126691. };
  126692. static long _vq_quantlist__44cn1_s_p6_0[] = {
  126693. 1,
  126694. 0,
  126695. 2,
  126696. };
  126697. static long _vq_lengthlist__44cn1_s_p6_0[] = {
  126698. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 6, 6,10, 9, 9,11,
  126699. 9, 9, 4, 6, 6,10, 9, 9,10, 9, 9, 7,10,10,11,11,
  126700. 11,12,11,11, 7, 9, 9,11,11,10,11,10,10, 7, 9, 9,
  126701. 11,10,11,11,10,10, 7,10,10,11,11,11,12,11,11, 7,
  126702. 9, 9,11,10,10,11,10,10, 7, 9, 9,11,10,10,11,10,
  126703. 10,
  126704. };
  126705. static float _vq_quantthresh__44cn1_s_p6_0[] = {
  126706. -5.5, 5.5,
  126707. };
  126708. static long _vq_quantmap__44cn1_s_p6_0[] = {
  126709. 1, 0, 2,
  126710. };
  126711. static encode_aux_threshmatch _vq_auxt__44cn1_s_p6_0 = {
  126712. _vq_quantthresh__44cn1_s_p6_0,
  126713. _vq_quantmap__44cn1_s_p6_0,
  126714. 3,
  126715. 3
  126716. };
  126717. static static_codebook _44cn1_s_p6_0 = {
  126718. 4, 81,
  126719. _vq_lengthlist__44cn1_s_p6_0,
  126720. 1, -529137664, 1618345984, 2, 0,
  126721. _vq_quantlist__44cn1_s_p6_0,
  126722. NULL,
  126723. &_vq_auxt__44cn1_s_p6_0,
  126724. NULL,
  126725. 0
  126726. };
  126727. static long _vq_quantlist__44cn1_s_p6_1[] = {
  126728. 5,
  126729. 4,
  126730. 6,
  126731. 3,
  126732. 7,
  126733. 2,
  126734. 8,
  126735. 1,
  126736. 9,
  126737. 0,
  126738. 10,
  126739. };
  126740. static long _vq_lengthlist__44cn1_s_p6_1[] = {
  126741. 1, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8,10,10,10, 7, 6,
  126742. 8, 8, 8, 8, 8, 8,10,10,10, 7, 6, 7, 7, 8, 8, 8,
  126743. 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  126744. 7, 8, 8, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 9, 9,
  126745. 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9, 9,10,10,10,
  126746. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9,
  126747. 9, 9, 9,10,10,10,10,10, 9, 9, 9, 9, 9, 9,10,10,
  126748. 10,10,10, 9, 9, 9, 9, 9, 9,
  126749. };
  126750. static float _vq_quantthresh__44cn1_s_p6_1[] = {
  126751. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  126752. 3.5, 4.5,
  126753. };
  126754. static long _vq_quantmap__44cn1_s_p6_1[] = {
  126755. 9, 7, 5, 3, 1, 0, 2, 4,
  126756. 6, 8, 10,
  126757. };
  126758. static encode_aux_threshmatch _vq_auxt__44cn1_s_p6_1 = {
  126759. _vq_quantthresh__44cn1_s_p6_1,
  126760. _vq_quantmap__44cn1_s_p6_1,
  126761. 11,
  126762. 11
  126763. };
  126764. static static_codebook _44cn1_s_p6_1 = {
  126765. 2, 121,
  126766. _vq_lengthlist__44cn1_s_p6_1,
  126767. 1, -531365888, 1611661312, 4, 0,
  126768. _vq_quantlist__44cn1_s_p6_1,
  126769. NULL,
  126770. &_vq_auxt__44cn1_s_p6_1,
  126771. NULL,
  126772. 0
  126773. };
  126774. static long _vq_quantlist__44cn1_s_p7_0[] = {
  126775. 6,
  126776. 5,
  126777. 7,
  126778. 4,
  126779. 8,
  126780. 3,
  126781. 9,
  126782. 2,
  126783. 10,
  126784. 1,
  126785. 11,
  126786. 0,
  126787. 12,
  126788. };
  126789. static long _vq_lengthlist__44cn1_s_p7_0[] = {
  126790. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  126791. 7, 7, 8, 8, 8, 8, 9, 9,11,11, 7, 5, 5, 7, 7, 8,
  126792. 8, 8, 8, 9,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  126793. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  126794. 11, 0,12,12, 9, 9, 9,10,10,10,11,11,11,12, 0,13,
  126795. 13, 9, 9, 9, 9,10,10,11,11,11,12, 0, 0, 0,10,10,
  126796. 10,10,11,11,12,12,12,13, 0, 0, 0,10,10,10,10,11,
  126797. 11,12,12,13,12, 0, 0, 0,14,14,11,10,11,12,12,13,
  126798. 13,14, 0, 0, 0,15,15,11,11,12,11,12,12,14,13, 0,
  126799. 0, 0, 0, 0,12,12,12,12,13,13,14,14, 0, 0, 0, 0,
  126800. 0,13,13,12,12,13,13,13,14,
  126801. };
  126802. static float _vq_quantthresh__44cn1_s_p7_0[] = {
  126803. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  126804. 12.5, 17.5, 22.5, 27.5,
  126805. };
  126806. static long _vq_quantmap__44cn1_s_p7_0[] = {
  126807. 11, 9, 7, 5, 3, 1, 0, 2,
  126808. 4, 6, 8, 10, 12,
  126809. };
  126810. static encode_aux_threshmatch _vq_auxt__44cn1_s_p7_0 = {
  126811. _vq_quantthresh__44cn1_s_p7_0,
  126812. _vq_quantmap__44cn1_s_p7_0,
  126813. 13,
  126814. 13
  126815. };
  126816. static static_codebook _44cn1_s_p7_0 = {
  126817. 2, 169,
  126818. _vq_lengthlist__44cn1_s_p7_0,
  126819. 1, -526516224, 1616117760, 4, 0,
  126820. _vq_quantlist__44cn1_s_p7_0,
  126821. NULL,
  126822. &_vq_auxt__44cn1_s_p7_0,
  126823. NULL,
  126824. 0
  126825. };
  126826. static long _vq_quantlist__44cn1_s_p7_1[] = {
  126827. 2,
  126828. 1,
  126829. 3,
  126830. 0,
  126831. 4,
  126832. };
  126833. static long _vq_lengthlist__44cn1_s_p7_1[] = {
  126834. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  126835. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  126836. };
  126837. static float _vq_quantthresh__44cn1_s_p7_1[] = {
  126838. -1.5, -0.5, 0.5, 1.5,
  126839. };
  126840. static long _vq_quantmap__44cn1_s_p7_1[] = {
  126841. 3, 1, 0, 2, 4,
  126842. };
  126843. static encode_aux_threshmatch _vq_auxt__44cn1_s_p7_1 = {
  126844. _vq_quantthresh__44cn1_s_p7_1,
  126845. _vq_quantmap__44cn1_s_p7_1,
  126846. 5,
  126847. 5
  126848. };
  126849. static static_codebook _44cn1_s_p7_1 = {
  126850. 2, 25,
  126851. _vq_lengthlist__44cn1_s_p7_1,
  126852. 1, -533725184, 1611661312, 3, 0,
  126853. _vq_quantlist__44cn1_s_p7_1,
  126854. NULL,
  126855. &_vq_auxt__44cn1_s_p7_1,
  126856. NULL,
  126857. 0
  126858. };
  126859. static long _vq_quantlist__44cn1_s_p8_0[] = {
  126860. 2,
  126861. 1,
  126862. 3,
  126863. 0,
  126864. 4,
  126865. };
  126866. static long _vq_lengthlist__44cn1_s_p8_0[] = {
  126867. 1, 7, 7,11,11, 8,11,11,11,11, 4,11, 3,11,11,11,
  126868. 11,11,11,11,11,11,11,11,11,11,11,10,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,10,11,11,11,11,11,11,11,11,11,11,11,11,
  126871. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126872. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126873. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126874. 11,11,11,11,11,11,11,11,11,11,11,11,11, 7,11,11,
  126875. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126876. 11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,
  126877. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,
  126878. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126879. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126880. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126881. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126882. 11,11,11,11,11,11,11,11,11,11, 8,11,11,11,11,11,
  126883. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126884. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126885. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126886. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126887. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126888. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126889. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126890. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126891. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126892. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126893. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126894. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126895. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126896. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126897. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126898. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126899. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126900. 11,11,11,11,11,11,11,12,12,12,12,12,12,12,12,12,
  126901. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126902. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126903. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126904. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126905. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126906. 12,
  126907. };
  126908. static float _vq_quantthresh__44cn1_s_p8_0[] = {
  126909. -331.5, -110.5, 110.5, 331.5,
  126910. };
  126911. static long _vq_quantmap__44cn1_s_p8_0[] = {
  126912. 3, 1, 0, 2, 4,
  126913. };
  126914. static encode_aux_threshmatch _vq_auxt__44cn1_s_p8_0 = {
  126915. _vq_quantthresh__44cn1_s_p8_0,
  126916. _vq_quantmap__44cn1_s_p8_0,
  126917. 5,
  126918. 5
  126919. };
  126920. static static_codebook _44cn1_s_p8_0 = {
  126921. 4, 625,
  126922. _vq_lengthlist__44cn1_s_p8_0,
  126923. 1, -518283264, 1627103232, 3, 0,
  126924. _vq_quantlist__44cn1_s_p8_0,
  126925. NULL,
  126926. &_vq_auxt__44cn1_s_p8_0,
  126927. NULL,
  126928. 0
  126929. };
  126930. static long _vq_quantlist__44cn1_s_p8_1[] = {
  126931. 6,
  126932. 5,
  126933. 7,
  126934. 4,
  126935. 8,
  126936. 3,
  126937. 9,
  126938. 2,
  126939. 10,
  126940. 1,
  126941. 11,
  126942. 0,
  126943. 12,
  126944. };
  126945. static long _vq_lengthlist__44cn1_s_p8_1[] = {
  126946. 1, 4, 4, 6, 6, 8, 8, 9,10,10,11,11,11, 6, 5, 5,
  126947. 7, 7, 8, 8, 9,10, 9,11,11,12, 5, 5, 5, 7, 7, 8,
  126948. 9,10,10,12,12,14,13,15, 7, 7, 8, 8, 9,10,11,11,
  126949. 10,12,10,11,15, 7, 8, 8, 8, 9, 9,11,11,13,12,12,
  126950. 13,15,10,10, 8, 8,10,10,12,12,11,14,10,10,15,11,
  126951. 11, 8, 8,10,10,12,13,13,14,15,13,15,15,15,10,10,
  126952. 10,10,12,12,13,12,13,10,15,15,15,10,10,11,10,13,
  126953. 11,13,13,15,13,15,15,15,13,13,10,11,11,11,12,10,
  126954. 14,11,15,15,14,14,13,10,10,12,11,13,13,14,14,15,
  126955. 15,15,15,15,11,11,11,11,12,11,15,12,15,15,15,15,
  126956. 15,12,12,11,11,14,12,13,14,
  126957. };
  126958. static float _vq_quantthresh__44cn1_s_p8_1[] = {
  126959. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  126960. 42.5, 59.5, 76.5, 93.5,
  126961. };
  126962. static long _vq_quantmap__44cn1_s_p8_1[] = {
  126963. 11, 9, 7, 5, 3, 1, 0, 2,
  126964. 4, 6, 8, 10, 12,
  126965. };
  126966. static encode_aux_threshmatch _vq_auxt__44cn1_s_p8_1 = {
  126967. _vq_quantthresh__44cn1_s_p8_1,
  126968. _vq_quantmap__44cn1_s_p8_1,
  126969. 13,
  126970. 13
  126971. };
  126972. static static_codebook _44cn1_s_p8_1 = {
  126973. 2, 169,
  126974. _vq_lengthlist__44cn1_s_p8_1,
  126975. 1, -522616832, 1620115456, 4, 0,
  126976. _vq_quantlist__44cn1_s_p8_1,
  126977. NULL,
  126978. &_vq_auxt__44cn1_s_p8_1,
  126979. NULL,
  126980. 0
  126981. };
  126982. static long _vq_quantlist__44cn1_s_p8_2[] = {
  126983. 8,
  126984. 7,
  126985. 9,
  126986. 6,
  126987. 10,
  126988. 5,
  126989. 11,
  126990. 4,
  126991. 12,
  126992. 3,
  126993. 13,
  126994. 2,
  126995. 14,
  126996. 1,
  126997. 15,
  126998. 0,
  126999. 16,
  127000. };
  127001. static long _vq_lengthlist__44cn1_s_p8_2[] = {
  127002. 3, 4, 3, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  127003. 9,10,11,11, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  127004. 9, 9,10,10,10, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  127005. 9, 9, 9,10,10,10, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9,
  127006. 9, 9,10, 9,10,11,10, 7, 6, 7, 7, 8, 8, 9, 9, 9,
  127007. 9, 9, 9, 9,10,10,10,11, 7, 7, 8, 8, 8, 8, 9, 9,
  127008. 9, 9, 9, 9, 9, 9,10,10,10, 7, 7, 8, 8, 8, 8, 9,
  127009. 9, 9, 9, 9, 9, 9,10,11,11,11, 8, 8, 8, 8, 8, 8,
  127010. 9, 9, 9, 9, 9, 9, 9, 9,11,10,10,11,11, 8, 8, 8,
  127011. 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,11,11, 9, 9,
  127012. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,10,11,11, 9,
  127013. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,11,10,11,11,
  127014. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,10,10,11,
  127015. 11,11,11, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,11,11,
  127016. 10,11,11,11, 9,10,10, 9, 9, 9, 9, 9, 9, 9,10,11,
  127017. 11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
  127018. 11,11,11,11,11,11,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  127019. 11,11,11,10,11,11,11,11,11, 9, 9, 9,10, 9, 9, 9,
  127020. 9,
  127021. };
  127022. static float _vq_quantthresh__44cn1_s_p8_2[] = {
  127023. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  127024. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  127025. };
  127026. static long _vq_quantmap__44cn1_s_p8_2[] = {
  127027. 15, 13, 11, 9, 7, 5, 3, 1,
  127028. 0, 2, 4, 6, 8, 10, 12, 14,
  127029. 16,
  127030. };
  127031. static encode_aux_threshmatch _vq_auxt__44cn1_s_p8_2 = {
  127032. _vq_quantthresh__44cn1_s_p8_2,
  127033. _vq_quantmap__44cn1_s_p8_2,
  127034. 17,
  127035. 17
  127036. };
  127037. static static_codebook _44cn1_s_p8_2 = {
  127038. 2, 289,
  127039. _vq_lengthlist__44cn1_s_p8_2,
  127040. 1, -529530880, 1611661312, 5, 0,
  127041. _vq_quantlist__44cn1_s_p8_2,
  127042. NULL,
  127043. &_vq_auxt__44cn1_s_p8_2,
  127044. NULL,
  127045. 0
  127046. };
  127047. static long _huff_lengthlist__44cn1_s_short[] = {
  127048. 10, 9,12,15,12,13,16,14,16, 7, 1, 5,14, 7,10,13,
  127049. 16,16, 9, 4, 6,16, 8,11,16,16,16,14, 4, 7,16, 9,
  127050. 12,14,16,16,10, 5, 7,14, 9,12,14,15,15,13, 8, 9,
  127051. 14,10,12,13,14,15,13, 9, 9, 7, 6, 8,11,12,12,14,
  127052. 8, 8, 5, 4, 5, 8,11,12,16,10,10, 6, 5, 6, 8, 9,
  127053. 10,
  127054. };
  127055. static static_codebook _huff_book__44cn1_s_short = {
  127056. 2, 81,
  127057. _huff_lengthlist__44cn1_s_short,
  127058. 0, 0, 0, 0, 0,
  127059. NULL,
  127060. NULL,
  127061. NULL,
  127062. NULL,
  127063. 0
  127064. };
  127065. static long _huff_lengthlist__44cn1_sm_long[] = {
  127066. 3, 3, 8, 8, 8, 8,10,12,14, 3, 2, 6, 7, 7, 8,10,
  127067. 12,16, 7, 6, 7, 9, 8,10,12,14,16, 8, 6, 8, 4, 5,
  127068. 7, 9,11,13, 7, 6, 8, 5, 6, 7, 9,11,14, 8, 8,10,
  127069. 7, 7, 6, 8,10,13, 9,11,12, 9, 9, 7, 8,10,12,10,
  127070. 13,15,11,11,10, 9,10,13,13,16,17,14,15,14,13,14,
  127071. 17,
  127072. };
  127073. static static_codebook _huff_book__44cn1_sm_long = {
  127074. 2, 81,
  127075. _huff_lengthlist__44cn1_sm_long,
  127076. 0, 0, 0, 0, 0,
  127077. NULL,
  127078. NULL,
  127079. NULL,
  127080. NULL,
  127081. 0
  127082. };
  127083. static long _vq_quantlist__44cn1_sm_p1_0[] = {
  127084. 1,
  127085. 0,
  127086. 2,
  127087. };
  127088. static long _vq_lengthlist__44cn1_sm_p1_0[] = {
  127089. 1, 4, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  127090. 0, 0, 5, 7, 7, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0,
  127095. 0, 0, 0, 7, 8, 9, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  127100. 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127101. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127102. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127125. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127134. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0, 0, 0, 0,
  127135. 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 7,10, 9, 0, 0, 0,
  127140. 0, 0, 0, 9, 9,10, 0, 0, 0, 0, 0, 0, 9,10,10, 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, 7, 9, 9, 0, 0,
  127145. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  127146. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127147. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127148. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127150. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127151. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127152. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127153. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127154. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127155. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127156. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127159. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127160. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127161. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127162. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127163. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127164. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127166. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127167. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127170. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127171. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127172. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127173. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127174. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127176. 0, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  127181. 0, 0, 0, 0, 8, 9,10, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  127186. 0, 0, 0, 0, 0, 8, 9,10, 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, 7, 9,10, 0, 0, 0, 0, 0, 0, 9,10,10,
  127191. 0, 0, 0, 0, 0, 0, 9,10, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127499. 0,
  127500. };
  127501. static float _vq_quantthresh__44cn1_sm_p1_0[] = {
  127502. -0.5, 0.5,
  127503. };
  127504. static long _vq_quantmap__44cn1_sm_p1_0[] = {
  127505. 1, 0, 2,
  127506. };
  127507. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p1_0 = {
  127508. _vq_quantthresh__44cn1_sm_p1_0,
  127509. _vq_quantmap__44cn1_sm_p1_0,
  127510. 3,
  127511. 3
  127512. };
  127513. static static_codebook _44cn1_sm_p1_0 = {
  127514. 8, 6561,
  127515. _vq_lengthlist__44cn1_sm_p1_0,
  127516. 1, -535822336, 1611661312, 2, 0,
  127517. _vq_quantlist__44cn1_sm_p1_0,
  127518. NULL,
  127519. &_vq_auxt__44cn1_sm_p1_0,
  127520. NULL,
  127521. 0
  127522. };
  127523. static long _vq_quantlist__44cn1_sm_p2_0[] = {
  127524. 2,
  127525. 1,
  127526. 3,
  127527. 0,
  127528. 4,
  127529. };
  127530. static long _vq_lengthlist__44cn1_sm_p2_0[] = {
  127531. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 7, 0, 0,
  127533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127534. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 9,
  127536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127537. 0, 0, 0, 0, 7, 7, 7, 9, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127570. 0,
  127571. };
  127572. static float _vq_quantthresh__44cn1_sm_p2_0[] = {
  127573. -1.5, -0.5, 0.5, 1.5,
  127574. };
  127575. static long _vq_quantmap__44cn1_sm_p2_0[] = {
  127576. 3, 1, 0, 2, 4,
  127577. };
  127578. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p2_0 = {
  127579. _vq_quantthresh__44cn1_sm_p2_0,
  127580. _vq_quantmap__44cn1_sm_p2_0,
  127581. 5,
  127582. 5
  127583. };
  127584. static static_codebook _44cn1_sm_p2_0 = {
  127585. 4, 625,
  127586. _vq_lengthlist__44cn1_sm_p2_0,
  127587. 1, -533725184, 1611661312, 3, 0,
  127588. _vq_quantlist__44cn1_sm_p2_0,
  127589. NULL,
  127590. &_vq_auxt__44cn1_sm_p2_0,
  127591. NULL,
  127592. 0
  127593. };
  127594. static long _vq_quantlist__44cn1_sm_p3_0[] = {
  127595. 4,
  127596. 3,
  127597. 5,
  127598. 2,
  127599. 6,
  127600. 1,
  127601. 7,
  127602. 0,
  127603. 8,
  127604. };
  127605. static long _vq_lengthlist__44cn1_sm_p3_0[] = {
  127606. 1, 3, 4, 7, 7, 0, 0, 0, 0, 0, 4, 4, 7, 7, 0, 0,
  127607. 0, 0, 0, 4, 5, 7, 7, 0, 0, 0, 0, 0, 6, 7, 8, 8,
  127608. 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  127609. 9, 9, 0, 0, 0, 0, 0, 0, 0,10, 9, 0, 0, 0, 0, 0,
  127610. 0, 0,11,11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127611. 0,
  127612. };
  127613. static float _vq_quantthresh__44cn1_sm_p3_0[] = {
  127614. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  127615. };
  127616. static long _vq_quantmap__44cn1_sm_p3_0[] = {
  127617. 7, 5, 3, 1, 0, 2, 4, 6,
  127618. 8,
  127619. };
  127620. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p3_0 = {
  127621. _vq_quantthresh__44cn1_sm_p3_0,
  127622. _vq_quantmap__44cn1_sm_p3_0,
  127623. 9,
  127624. 9
  127625. };
  127626. static static_codebook _44cn1_sm_p3_0 = {
  127627. 2, 81,
  127628. _vq_lengthlist__44cn1_sm_p3_0,
  127629. 1, -531628032, 1611661312, 4, 0,
  127630. _vq_quantlist__44cn1_sm_p3_0,
  127631. NULL,
  127632. &_vq_auxt__44cn1_sm_p3_0,
  127633. NULL,
  127634. 0
  127635. };
  127636. static long _vq_quantlist__44cn1_sm_p4_0[] = {
  127637. 4,
  127638. 3,
  127639. 5,
  127640. 2,
  127641. 6,
  127642. 1,
  127643. 7,
  127644. 0,
  127645. 8,
  127646. };
  127647. static long _vq_lengthlist__44cn1_sm_p4_0[] = {
  127648. 1, 4, 3, 6, 6, 7, 7, 9, 9, 0, 5, 5, 7, 7, 8, 7,
  127649. 9, 9, 0, 5, 5, 7, 7, 8, 8, 9, 9, 0, 7, 7, 8, 8,
  127650. 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  127651. 9, 9, 9, 9,10,10, 0, 0, 0, 9, 9, 9, 9,10,10, 0,
  127652. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0,10,10,11,
  127653. 11,
  127654. };
  127655. static float _vq_quantthresh__44cn1_sm_p4_0[] = {
  127656. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  127657. };
  127658. static long _vq_quantmap__44cn1_sm_p4_0[] = {
  127659. 7, 5, 3, 1, 0, 2, 4, 6,
  127660. 8,
  127661. };
  127662. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p4_0 = {
  127663. _vq_quantthresh__44cn1_sm_p4_0,
  127664. _vq_quantmap__44cn1_sm_p4_0,
  127665. 9,
  127666. 9
  127667. };
  127668. static static_codebook _44cn1_sm_p4_0 = {
  127669. 2, 81,
  127670. _vq_lengthlist__44cn1_sm_p4_0,
  127671. 1, -531628032, 1611661312, 4, 0,
  127672. _vq_quantlist__44cn1_sm_p4_0,
  127673. NULL,
  127674. &_vq_auxt__44cn1_sm_p4_0,
  127675. NULL,
  127676. 0
  127677. };
  127678. static long _vq_quantlist__44cn1_sm_p5_0[] = {
  127679. 8,
  127680. 7,
  127681. 9,
  127682. 6,
  127683. 10,
  127684. 5,
  127685. 11,
  127686. 4,
  127687. 12,
  127688. 3,
  127689. 13,
  127690. 2,
  127691. 14,
  127692. 1,
  127693. 15,
  127694. 0,
  127695. 16,
  127696. };
  127697. static long _vq_lengthlist__44cn1_sm_p5_0[] = {
  127698. 1, 4, 4, 6, 6, 8, 8, 9, 9, 8, 8, 9, 9,10,10,11,
  127699. 11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  127700. 12,12, 0, 6, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  127701. 11,12,12, 0, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  127702. 11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,10,11,
  127703. 11,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  127704. 11,11,12,12,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  127705. 10,11,11,12,12,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  127706. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,10,
  127707. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  127708. 10,10,11,11,12,12,13,13,13,13, 0, 0, 0, 0, 0, 9,
  127709. 9,10,10,11,11,12,12,12,13,13,13, 0, 0, 0, 0, 0,
  127710. 10,10,11,11,11,11,12,12,13,13,14,14, 0, 0, 0, 0,
  127711. 0, 0, 0,11,11,11,11,12,12,13,13,14,14, 0, 0, 0,
  127712. 0, 0, 0, 0,11,11,12,12,13,13,13,13,14,14, 0, 0,
  127713. 0, 0, 0, 0, 0,11,11,12,12,13,13,13,13,14,14, 0,
  127714. 0, 0, 0, 0, 0, 0,12,12,12,13,13,13,14,14,14,14,
  127715. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,14,14,14,
  127716. 14,
  127717. };
  127718. static float _vq_quantthresh__44cn1_sm_p5_0[] = {
  127719. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  127720. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  127721. };
  127722. static long _vq_quantmap__44cn1_sm_p5_0[] = {
  127723. 15, 13, 11, 9, 7, 5, 3, 1,
  127724. 0, 2, 4, 6, 8, 10, 12, 14,
  127725. 16,
  127726. };
  127727. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p5_0 = {
  127728. _vq_quantthresh__44cn1_sm_p5_0,
  127729. _vq_quantmap__44cn1_sm_p5_0,
  127730. 17,
  127731. 17
  127732. };
  127733. static static_codebook _44cn1_sm_p5_0 = {
  127734. 2, 289,
  127735. _vq_lengthlist__44cn1_sm_p5_0,
  127736. 1, -529530880, 1611661312, 5, 0,
  127737. _vq_quantlist__44cn1_sm_p5_0,
  127738. NULL,
  127739. &_vq_auxt__44cn1_sm_p5_0,
  127740. NULL,
  127741. 0
  127742. };
  127743. static long _vq_quantlist__44cn1_sm_p6_0[] = {
  127744. 1,
  127745. 0,
  127746. 2,
  127747. };
  127748. static long _vq_lengthlist__44cn1_sm_p6_0[] = {
  127749. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 6,10, 9, 9,11,
  127750. 9, 9, 4, 6, 7,10, 9, 9,11, 9, 9, 7,10,10,10,11,
  127751. 11,11,11,10, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  127752. 11,10,11,11,10,10, 7,11,11,11,11,11,12,11,11, 7,
  127753. 9, 9,11,10,10,12,10,10, 7, 9, 9,11,10,10,11,10,
  127754. 10,
  127755. };
  127756. static float _vq_quantthresh__44cn1_sm_p6_0[] = {
  127757. -5.5, 5.5,
  127758. };
  127759. static long _vq_quantmap__44cn1_sm_p6_0[] = {
  127760. 1, 0, 2,
  127761. };
  127762. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p6_0 = {
  127763. _vq_quantthresh__44cn1_sm_p6_0,
  127764. _vq_quantmap__44cn1_sm_p6_0,
  127765. 3,
  127766. 3
  127767. };
  127768. static static_codebook _44cn1_sm_p6_0 = {
  127769. 4, 81,
  127770. _vq_lengthlist__44cn1_sm_p6_0,
  127771. 1, -529137664, 1618345984, 2, 0,
  127772. _vq_quantlist__44cn1_sm_p6_0,
  127773. NULL,
  127774. &_vq_auxt__44cn1_sm_p6_0,
  127775. NULL,
  127776. 0
  127777. };
  127778. static long _vq_quantlist__44cn1_sm_p6_1[] = {
  127779. 5,
  127780. 4,
  127781. 6,
  127782. 3,
  127783. 7,
  127784. 2,
  127785. 8,
  127786. 1,
  127787. 9,
  127788. 0,
  127789. 10,
  127790. };
  127791. static long _vq_lengthlist__44cn1_sm_p6_1[] = {
  127792. 2, 4, 4, 5, 5, 7, 7, 7, 7, 8, 8,10, 5, 5, 6, 6,
  127793. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  127794. 8,10, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  127795. 7, 7, 7, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 8, 8,
  127796. 8, 8,10,10,10, 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  127797. 8, 8, 8, 8, 8, 8, 9, 9,10,10,10,10,10, 8, 8, 8,
  127798. 8, 9, 9,10,10,10,10,10, 9, 9, 9, 9, 8, 9,10,10,
  127799. 10,10,10, 8, 9, 8, 8, 9, 8,
  127800. };
  127801. static float _vq_quantthresh__44cn1_sm_p6_1[] = {
  127802. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  127803. 3.5, 4.5,
  127804. };
  127805. static long _vq_quantmap__44cn1_sm_p6_1[] = {
  127806. 9, 7, 5, 3, 1, 0, 2, 4,
  127807. 6, 8, 10,
  127808. };
  127809. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p6_1 = {
  127810. _vq_quantthresh__44cn1_sm_p6_1,
  127811. _vq_quantmap__44cn1_sm_p6_1,
  127812. 11,
  127813. 11
  127814. };
  127815. static static_codebook _44cn1_sm_p6_1 = {
  127816. 2, 121,
  127817. _vq_lengthlist__44cn1_sm_p6_1,
  127818. 1, -531365888, 1611661312, 4, 0,
  127819. _vq_quantlist__44cn1_sm_p6_1,
  127820. NULL,
  127821. &_vq_auxt__44cn1_sm_p6_1,
  127822. NULL,
  127823. 0
  127824. };
  127825. static long _vq_quantlist__44cn1_sm_p7_0[] = {
  127826. 6,
  127827. 5,
  127828. 7,
  127829. 4,
  127830. 8,
  127831. 3,
  127832. 9,
  127833. 2,
  127834. 10,
  127835. 1,
  127836. 11,
  127837. 0,
  127838. 12,
  127839. };
  127840. static long _vq_lengthlist__44cn1_sm_p7_0[] = {
  127841. 1, 4, 4, 6, 6, 7, 7, 7, 7, 9, 9,10,10, 7, 5, 5,
  127842. 7, 7, 8, 8, 8, 8,10, 9,11,10, 7, 5, 5, 7, 7, 8,
  127843. 8, 8, 8, 9,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  127844. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  127845. 11, 0,12,12, 9, 9, 9,10,10,10,11,11,12,12, 0,13,
  127846. 13, 9, 9, 9, 9,10,10,11,11,12,12, 0, 0, 0,10,10,
  127847. 10,10,11,11,12,12,12,13, 0, 0, 0,10,10,10,10,11,
  127848. 11,12,12,12,12, 0, 0, 0,14,14,11,11,11,11,12,13,
  127849. 13,13, 0, 0, 0,14,14,11,10,11,11,12,12,13,13, 0,
  127850. 0, 0, 0, 0,12,12,12,12,13,13,13,14, 0, 0, 0, 0,
  127851. 0,13,12,12,12,13,13,13,14,
  127852. };
  127853. static float _vq_quantthresh__44cn1_sm_p7_0[] = {
  127854. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  127855. 12.5, 17.5, 22.5, 27.5,
  127856. };
  127857. static long _vq_quantmap__44cn1_sm_p7_0[] = {
  127858. 11, 9, 7, 5, 3, 1, 0, 2,
  127859. 4, 6, 8, 10, 12,
  127860. };
  127861. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p7_0 = {
  127862. _vq_quantthresh__44cn1_sm_p7_0,
  127863. _vq_quantmap__44cn1_sm_p7_0,
  127864. 13,
  127865. 13
  127866. };
  127867. static static_codebook _44cn1_sm_p7_0 = {
  127868. 2, 169,
  127869. _vq_lengthlist__44cn1_sm_p7_0,
  127870. 1, -526516224, 1616117760, 4, 0,
  127871. _vq_quantlist__44cn1_sm_p7_0,
  127872. NULL,
  127873. &_vq_auxt__44cn1_sm_p7_0,
  127874. NULL,
  127875. 0
  127876. };
  127877. static long _vq_quantlist__44cn1_sm_p7_1[] = {
  127878. 2,
  127879. 1,
  127880. 3,
  127881. 0,
  127882. 4,
  127883. };
  127884. static long _vq_lengthlist__44cn1_sm_p7_1[] = {
  127885. 2, 4, 4, 4, 5, 6, 5, 5, 5, 5, 6, 5, 5, 5, 5, 6,
  127886. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  127887. };
  127888. static float _vq_quantthresh__44cn1_sm_p7_1[] = {
  127889. -1.5, -0.5, 0.5, 1.5,
  127890. };
  127891. static long _vq_quantmap__44cn1_sm_p7_1[] = {
  127892. 3, 1, 0, 2, 4,
  127893. };
  127894. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p7_1 = {
  127895. _vq_quantthresh__44cn1_sm_p7_1,
  127896. _vq_quantmap__44cn1_sm_p7_1,
  127897. 5,
  127898. 5
  127899. };
  127900. static static_codebook _44cn1_sm_p7_1 = {
  127901. 2, 25,
  127902. _vq_lengthlist__44cn1_sm_p7_1,
  127903. 1, -533725184, 1611661312, 3, 0,
  127904. _vq_quantlist__44cn1_sm_p7_1,
  127905. NULL,
  127906. &_vq_auxt__44cn1_sm_p7_1,
  127907. NULL,
  127908. 0
  127909. };
  127910. static long _vq_quantlist__44cn1_sm_p8_0[] = {
  127911. 4,
  127912. 3,
  127913. 5,
  127914. 2,
  127915. 6,
  127916. 1,
  127917. 7,
  127918. 0,
  127919. 8,
  127920. };
  127921. static long _vq_lengthlist__44cn1_sm_p8_0[] = {
  127922. 1, 4, 4,12,11,13,13,14,14, 4, 7, 7,11,13,14,14,
  127923. 14,14, 3, 8, 3,14,14,14,14,14,14,14,10,12,14,14,
  127924. 14,14,14,14,14,14, 5,14, 8,14,14,14,14,14,12,14,
  127925. 13,14,14,14,14,14,14,14,13,14,10,14,14,14,14,14,
  127926. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  127927. 14,
  127928. };
  127929. static float _vq_quantthresh__44cn1_sm_p8_0[] = {
  127930. -773.5, -552.5, -331.5, -110.5, 110.5, 331.5, 552.5, 773.5,
  127931. };
  127932. static long _vq_quantmap__44cn1_sm_p8_0[] = {
  127933. 7, 5, 3, 1, 0, 2, 4, 6,
  127934. 8,
  127935. };
  127936. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p8_0 = {
  127937. _vq_quantthresh__44cn1_sm_p8_0,
  127938. _vq_quantmap__44cn1_sm_p8_0,
  127939. 9,
  127940. 9
  127941. };
  127942. static static_codebook _44cn1_sm_p8_0 = {
  127943. 2, 81,
  127944. _vq_lengthlist__44cn1_sm_p8_0,
  127945. 1, -516186112, 1627103232, 4, 0,
  127946. _vq_quantlist__44cn1_sm_p8_0,
  127947. NULL,
  127948. &_vq_auxt__44cn1_sm_p8_0,
  127949. NULL,
  127950. 0
  127951. };
  127952. static long _vq_quantlist__44cn1_sm_p8_1[] = {
  127953. 6,
  127954. 5,
  127955. 7,
  127956. 4,
  127957. 8,
  127958. 3,
  127959. 9,
  127960. 2,
  127961. 10,
  127962. 1,
  127963. 11,
  127964. 0,
  127965. 12,
  127966. };
  127967. static long _vq_lengthlist__44cn1_sm_p8_1[] = {
  127968. 1, 4, 4, 6, 6, 8, 8, 9, 9,10,11,11,11, 6, 5, 5,
  127969. 7, 7, 8, 8,10,10,10,11,11,11, 6, 5, 5, 7, 7, 8,
  127970. 8,10,10,11,12,12,12,14, 7, 7, 7, 8, 9, 9,11,11,
  127971. 11,12,11,12,17, 7, 7, 8, 7, 9, 9,11,11,12,12,12,
  127972. 12,14,11,11, 8, 8,10,10,11,12,12,13,11,12,14,11,
  127973. 11, 8, 8,10,10,11,12,12,13,13,12,14,15,14,10,10,
  127974. 10,10,11,12,12,12,12,11,14,13,16,10,10,10, 9,12,
  127975. 11,12,12,13,14,14,15,14,14,13,10,10,11,11,12,11,
  127976. 13,11,14,12,15,13,14,11,10,12,10,12,12,13,13,13,
  127977. 13,14,15,15,12,12,11,11,12,11,13,12,14,14,14,14,
  127978. 17,12,12,11,10,13,11,13,13,
  127979. };
  127980. static float _vq_quantthresh__44cn1_sm_p8_1[] = {
  127981. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  127982. 42.5, 59.5, 76.5, 93.5,
  127983. };
  127984. static long _vq_quantmap__44cn1_sm_p8_1[] = {
  127985. 11, 9, 7, 5, 3, 1, 0, 2,
  127986. 4, 6, 8, 10, 12,
  127987. };
  127988. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p8_1 = {
  127989. _vq_quantthresh__44cn1_sm_p8_1,
  127990. _vq_quantmap__44cn1_sm_p8_1,
  127991. 13,
  127992. 13
  127993. };
  127994. static static_codebook _44cn1_sm_p8_1 = {
  127995. 2, 169,
  127996. _vq_lengthlist__44cn1_sm_p8_1,
  127997. 1, -522616832, 1620115456, 4, 0,
  127998. _vq_quantlist__44cn1_sm_p8_1,
  127999. NULL,
  128000. &_vq_auxt__44cn1_sm_p8_1,
  128001. NULL,
  128002. 0
  128003. };
  128004. static long _vq_quantlist__44cn1_sm_p8_2[] = {
  128005. 8,
  128006. 7,
  128007. 9,
  128008. 6,
  128009. 10,
  128010. 5,
  128011. 11,
  128012. 4,
  128013. 12,
  128014. 3,
  128015. 13,
  128016. 2,
  128017. 14,
  128018. 1,
  128019. 15,
  128020. 0,
  128021. 16,
  128022. };
  128023. static long _vq_lengthlist__44cn1_sm_p8_2[] = {
  128024. 3, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  128025. 9,10, 6, 6, 6, 6, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9,
  128026. 9, 9,10, 6, 6, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9,
  128027. 9, 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
  128028. 9, 9, 9, 9,10,10,10, 7, 7, 7, 8, 8, 8, 9, 9, 9,
  128029. 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 8, 8, 9, 9,
  128030. 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 8, 8, 9,
  128031. 9, 9, 9, 9, 9, 9, 9,11,10,11, 8, 8, 8, 8, 8, 8,
  128032. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,11,11, 8, 8, 8,
  128033. 8, 9, 9, 9, 9, 9, 9, 9, 9,11,10,11,11,11, 9, 9,
  128034. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,11,10,11,11, 9,
  128035. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,11,11,10,11,11,
  128036. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,10,11,11,
  128037. 11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,11,11,
  128038. 11,11,11,11, 9,10,10,10, 9, 9, 9, 9, 9, 9,11,10,
  128039. 11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
  128040. 11,11,11,11,11,11,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  128041. 10,11,11,11,11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9,
  128042. 9,
  128043. };
  128044. static float _vq_quantthresh__44cn1_sm_p8_2[] = {
  128045. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  128046. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  128047. };
  128048. static long _vq_quantmap__44cn1_sm_p8_2[] = {
  128049. 15, 13, 11, 9, 7, 5, 3, 1,
  128050. 0, 2, 4, 6, 8, 10, 12, 14,
  128051. 16,
  128052. };
  128053. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p8_2 = {
  128054. _vq_quantthresh__44cn1_sm_p8_2,
  128055. _vq_quantmap__44cn1_sm_p8_2,
  128056. 17,
  128057. 17
  128058. };
  128059. static static_codebook _44cn1_sm_p8_2 = {
  128060. 2, 289,
  128061. _vq_lengthlist__44cn1_sm_p8_2,
  128062. 1, -529530880, 1611661312, 5, 0,
  128063. _vq_quantlist__44cn1_sm_p8_2,
  128064. NULL,
  128065. &_vq_auxt__44cn1_sm_p8_2,
  128066. NULL,
  128067. 0
  128068. };
  128069. static long _huff_lengthlist__44cn1_sm_short[] = {
  128070. 5, 6,12,14,12,14,16,17,18, 4, 2, 5,11, 7,10,12,
  128071. 14,15, 9, 4, 5,11, 7,10,13,15,18,15, 6, 7, 5, 6,
  128072. 8,11,13,16,11, 5, 6, 5, 5, 6, 9,13,15,12, 5, 7,
  128073. 6, 5, 6, 9,12,14,12, 6, 7, 8, 6, 7, 9,12,13,14,
  128074. 8, 8, 7, 5, 5, 8,10,12,16, 9, 9, 8, 6, 6, 7, 9,
  128075. 9,
  128076. };
  128077. static static_codebook _huff_book__44cn1_sm_short = {
  128078. 2, 81,
  128079. _huff_lengthlist__44cn1_sm_short,
  128080. 0, 0, 0, 0, 0,
  128081. NULL,
  128082. NULL,
  128083. NULL,
  128084. NULL,
  128085. 0
  128086. };
  128087. /*** End of inlined file: res_books_stereo.h ***/
  128088. static vorbis_info_residue0 _residue_44_low={
  128089. 0,-1, -1, 9,-1,
  128090. {0},
  128091. {-1},
  128092. { .5, 1.5, 2.5, 2.5, 4.5, 8.5, 16.5, 32.5},
  128093. { .5, .5, .5, 999., 4.5, 8.5, 16.5, 32.5},
  128094. };
  128095. static vorbis_info_residue0 _residue_44_mid={
  128096. 0,-1, -1, 10,-1,
  128097. {0},
  128098. {-1},
  128099. { .5, 1.5, 1.5, 2.5, 2.5, 4.5, 8.5, 16.5, 32.5},
  128100. { .5, .5, 999., .5, 999., 4.5, 8.5, 16.5, 32.5},
  128101. };
  128102. static vorbis_info_residue0 _residue_44_high={
  128103. 0,-1, -1, 10,-1,
  128104. {0},
  128105. {-1},
  128106. { .5, 1.5, 2.5, 4.5, 8.5, 16.5, 32.5, 71.5,157.5},
  128107. { .5, 1.5, 2.5, 3.5, 4.5, 8.5, 16.5, 71.5,157.5},
  128108. };
  128109. static static_bookblock _resbook_44s_n1={
  128110. {
  128111. {0},{0,0,&_44cn1_s_p1_0},{0,0,&_44cn1_s_p2_0},
  128112. {0,0,&_44cn1_s_p3_0},{0,0,&_44cn1_s_p4_0},{0,0,&_44cn1_s_p5_0},
  128113. {&_44cn1_s_p6_0,&_44cn1_s_p6_1},{&_44cn1_s_p7_0,&_44cn1_s_p7_1},
  128114. {&_44cn1_s_p8_0,&_44cn1_s_p8_1,&_44cn1_s_p8_2}
  128115. }
  128116. };
  128117. static static_bookblock _resbook_44sm_n1={
  128118. {
  128119. {0},{0,0,&_44cn1_sm_p1_0},{0,0,&_44cn1_sm_p2_0},
  128120. {0,0,&_44cn1_sm_p3_0},{0,0,&_44cn1_sm_p4_0},{0,0,&_44cn1_sm_p5_0},
  128121. {&_44cn1_sm_p6_0,&_44cn1_sm_p6_1},{&_44cn1_sm_p7_0,&_44cn1_sm_p7_1},
  128122. {&_44cn1_sm_p8_0,&_44cn1_sm_p8_1,&_44cn1_sm_p8_2}
  128123. }
  128124. };
  128125. static static_bookblock _resbook_44s_0={
  128126. {
  128127. {0},{0,0,&_44c0_s_p1_0},{0,0,&_44c0_s_p2_0},
  128128. {0,0,&_44c0_s_p3_0},{0,0,&_44c0_s_p4_0},{0,0,&_44c0_s_p5_0},
  128129. {&_44c0_s_p6_0,&_44c0_s_p6_1},{&_44c0_s_p7_0,&_44c0_s_p7_1},
  128130. {&_44c0_s_p8_0,&_44c0_s_p8_1,&_44c0_s_p8_2}
  128131. }
  128132. };
  128133. static static_bookblock _resbook_44sm_0={
  128134. {
  128135. {0},{0,0,&_44c0_sm_p1_0},{0,0,&_44c0_sm_p2_0},
  128136. {0,0,&_44c0_sm_p3_0},{0,0,&_44c0_sm_p4_0},{0,0,&_44c0_sm_p5_0},
  128137. {&_44c0_sm_p6_0,&_44c0_sm_p6_1},{&_44c0_sm_p7_0,&_44c0_sm_p7_1},
  128138. {&_44c0_sm_p8_0,&_44c0_sm_p8_1,&_44c0_sm_p8_2}
  128139. }
  128140. };
  128141. static static_bookblock _resbook_44s_1={
  128142. {
  128143. {0},{0,0,&_44c1_s_p1_0},{0,0,&_44c1_s_p2_0},
  128144. {0,0,&_44c1_s_p3_0},{0,0,&_44c1_s_p4_0},{0,0,&_44c1_s_p5_0},
  128145. {&_44c1_s_p6_0,&_44c1_s_p6_1},{&_44c1_s_p7_0,&_44c1_s_p7_1},
  128146. {&_44c1_s_p8_0,&_44c1_s_p8_1,&_44c1_s_p8_2}
  128147. }
  128148. };
  128149. static static_bookblock _resbook_44sm_1={
  128150. {
  128151. {0},{0,0,&_44c1_sm_p1_0},{0,0,&_44c1_sm_p2_0},
  128152. {0,0,&_44c1_sm_p3_0},{0,0,&_44c1_sm_p4_0},{0,0,&_44c1_sm_p5_0},
  128153. {&_44c1_sm_p6_0,&_44c1_sm_p6_1},{&_44c1_sm_p7_0,&_44c1_sm_p7_1},
  128154. {&_44c1_sm_p8_0,&_44c1_sm_p8_1,&_44c1_sm_p8_2}
  128155. }
  128156. };
  128157. static static_bookblock _resbook_44s_2={
  128158. {
  128159. {0},{0,0,&_44c2_s_p1_0},{0,0,&_44c2_s_p2_0},{0,0,&_44c2_s_p3_0},
  128160. {0,0,&_44c2_s_p4_0},{0,0,&_44c2_s_p5_0},{0,0,&_44c2_s_p6_0},
  128161. {&_44c2_s_p7_0,&_44c2_s_p7_1},{&_44c2_s_p8_0,&_44c2_s_p8_1},
  128162. {&_44c2_s_p9_0,&_44c2_s_p9_1,&_44c2_s_p9_2}
  128163. }
  128164. };
  128165. static static_bookblock _resbook_44s_3={
  128166. {
  128167. {0},{0,0,&_44c3_s_p1_0},{0,0,&_44c3_s_p2_0},{0,0,&_44c3_s_p3_0},
  128168. {0,0,&_44c3_s_p4_0},{0,0,&_44c3_s_p5_0},{0,0,&_44c3_s_p6_0},
  128169. {&_44c3_s_p7_0,&_44c3_s_p7_1},{&_44c3_s_p8_0,&_44c3_s_p8_1},
  128170. {&_44c3_s_p9_0,&_44c3_s_p9_1,&_44c3_s_p9_2}
  128171. }
  128172. };
  128173. static static_bookblock _resbook_44s_4={
  128174. {
  128175. {0},{0,0,&_44c4_s_p1_0},{0,0,&_44c4_s_p2_0},{0,0,&_44c4_s_p3_0},
  128176. {0,0,&_44c4_s_p4_0},{0,0,&_44c4_s_p5_0},{0,0,&_44c4_s_p6_0},
  128177. {&_44c4_s_p7_0,&_44c4_s_p7_1},{&_44c4_s_p8_0,&_44c4_s_p8_1},
  128178. {&_44c4_s_p9_0,&_44c4_s_p9_1,&_44c4_s_p9_2}
  128179. }
  128180. };
  128181. static static_bookblock _resbook_44s_5={
  128182. {
  128183. {0},{0,0,&_44c5_s_p1_0},{0,0,&_44c5_s_p2_0},{0,0,&_44c5_s_p3_0},
  128184. {0,0,&_44c5_s_p4_0},{0,0,&_44c5_s_p5_0},{0,0,&_44c5_s_p6_0},
  128185. {&_44c5_s_p7_0,&_44c5_s_p7_1},{&_44c5_s_p8_0,&_44c5_s_p8_1},
  128186. {&_44c5_s_p9_0,&_44c5_s_p9_1,&_44c5_s_p9_2}
  128187. }
  128188. };
  128189. static static_bookblock _resbook_44s_6={
  128190. {
  128191. {0},{0,0,&_44c6_s_p1_0},{0,0,&_44c6_s_p2_0},{0,0,&_44c6_s_p3_0},
  128192. {0,0,&_44c6_s_p4_0},
  128193. {&_44c6_s_p5_0,&_44c6_s_p5_1},
  128194. {&_44c6_s_p6_0,&_44c6_s_p6_1},
  128195. {&_44c6_s_p7_0,&_44c6_s_p7_1},
  128196. {&_44c6_s_p8_0,&_44c6_s_p8_1},
  128197. {&_44c6_s_p9_0,&_44c6_s_p9_1,&_44c6_s_p9_2}
  128198. }
  128199. };
  128200. static static_bookblock _resbook_44s_7={
  128201. {
  128202. {0},{0,0,&_44c7_s_p1_0},{0,0,&_44c7_s_p2_0},{0,0,&_44c7_s_p3_0},
  128203. {0,0,&_44c7_s_p4_0},
  128204. {&_44c7_s_p5_0,&_44c7_s_p5_1},
  128205. {&_44c7_s_p6_0,&_44c7_s_p6_1},
  128206. {&_44c7_s_p7_0,&_44c7_s_p7_1},
  128207. {&_44c7_s_p8_0,&_44c7_s_p8_1},
  128208. {&_44c7_s_p9_0,&_44c7_s_p9_1,&_44c7_s_p9_2}
  128209. }
  128210. };
  128211. static static_bookblock _resbook_44s_8={
  128212. {
  128213. {0},{0,0,&_44c8_s_p1_0},{0,0,&_44c8_s_p2_0},{0,0,&_44c8_s_p3_0},
  128214. {0,0,&_44c8_s_p4_0},
  128215. {&_44c8_s_p5_0,&_44c8_s_p5_1},
  128216. {&_44c8_s_p6_0,&_44c8_s_p6_1},
  128217. {&_44c8_s_p7_0,&_44c8_s_p7_1},
  128218. {&_44c8_s_p8_0,&_44c8_s_p8_1},
  128219. {&_44c8_s_p9_0,&_44c8_s_p9_1,&_44c8_s_p9_2}
  128220. }
  128221. };
  128222. static static_bookblock _resbook_44s_9={
  128223. {
  128224. {0},{0,0,&_44c9_s_p1_0},{0,0,&_44c9_s_p2_0},{0,0,&_44c9_s_p3_0},
  128225. {0,0,&_44c9_s_p4_0},
  128226. {&_44c9_s_p5_0,&_44c9_s_p5_1},
  128227. {&_44c9_s_p6_0,&_44c9_s_p6_1},
  128228. {&_44c9_s_p7_0,&_44c9_s_p7_1},
  128229. {&_44c9_s_p8_0,&_44c9_s_p8_1},
  128230. {&_44c9_s_p9_0,&_44c9_s_p9_1,&_44c9_s_p9_2}
  128231. }
  128232. };
  128233. static vorbis_residue_template _res_44s_n1[]={
  128234. {2,0, &_residue_44_low,
  128235. &_huff_book__44cn1_s_short,&_huff_book__44cn1_sm_short,
  128236. &_resbook_44s_n1,&_resbook_44sm_n1},
  128237. {2,0, &_residue_44_low,
  128238. &_huff_book__44cn1_s_long,&_huff_book__44cn1_sm_long,
  128239. &_resbook_44s_n1,&_resbook_44sm_n1}
  128240. };
  128241. static vorbis_residue_template _res_44s_0[]={
  128242. {2,0, &_residue_44_low,
  128243. &_huff_book__44c0_s_short,&_huff_book__44c0_sm_short,
  128244. &_resbook_44s_0,&_resbook_44sm_0},
  128245. {2,0, &_residue_44_low,
  128246. &_huff_book__44c0_s_long,&_huff_book__44c0_sm_long,
  128247. &_resbook_44s_0,&_resbook_44sm_0}
  128248. };
  128249. static vorbis_residue_template _res_44s_1[]={
  128250. {2,0, &_residue_44_low,
  128251. &_huff_book__44c1_s_short,&_huff_book__44c1_sm_short,
  128252. &_resbook_44s_1,&_resbook_44sm_1},
  128253. {2,0, &_residue_44_low,
  128254. &_huff_book__44c1_s_long,&_huff_book__44c1_sm_long,
  128255. &_resbook_44s_1,&_resbook_44sm_1}
  128256. };
  128257. static vorbis_residue_template _res_44s_2[]={
  128258. {2,0, &_residue_44_mid,
  128259. &_huff_book__44c2_s_short,&_huff_book__44c2_s_short,
  128260. &_resbook_44s_2,&_resbook_44s_2},
  128261. {2,0, &_residue_44_mid,
  128262. &_huff_book__44c2_s_long,&_huff_book__44c2_s_long,
  128263. &_resbook_44s_2,&_resbook_44s_2}
  128264. };
  128265. static vorbis_residue_template _res_44s_3[]={
  128266. {2,0, &_residue_44_mid,
  128267. &_huff_book__44c3_s_short,&_huff_book__44c3_s_short,
  128268. &_resbook_44s_3,&_resbook_44s_3},
  128269. {2,0, &_residue_44_mid,
  128270. &_huff_book__44c3_s_long,&_huff_book__44c3_s_long,
  128271. &_resbook_44s_3,&_resbook_44s_3}
  128272. };
  128273. static vorbis_residue_template _res_44s_4[]={
  128274. {2,0, &_residue_44_mid,
  128275. &_huff_book__44c4_s_short,&_huff_book__44c4_s_short,
  128276. &_resbook_44s_4,&_resbook_44s_4},
  128277. {2,0, &_residue_44_mid,
  128278. &_huff_book__44c4_s_long,&_huff_book__44c4_s_long,
  128279. &_resbook_44s_4,&_resbook_44s_4}
  128280. };
  128281. static vorbis_residue_template _res_44s_5[]={
  128282. {2,0, &_residue_44_mid,
  128283. &_huff_book__44c5_s_short,&_huff_book__44c5_s_short,
  128284. &_resbook_44s_5,&_resbook_44s_5},
  128285. {2,0, &_residue_44_mid,
  128286. &_huff_book__44c5_s_long,&_huff_book__44c5_s_long,
  128287. &_resbook_44s_5,&_resbook_44s_5}
  128288. };
  128289. static vorbis_residue_template _res_44s_6[]={
  128290. {2,0, &_residue_44_high,
  128291. &_huff_book__44c6_s_short,&_huff_book__44c6_s_short,
  128292. &_resbook_44s_6,&_resbook_44s_6},
  128293. {2,0, &_residue_44_high,
  128294. &_huff_book__44c6_s_long,&_huff_book__44c6_s_long,
  128295. &_resbook_44s_6,&_resbook_44s_6}
  128296. };
  128297. static vorbis_residue_template _res_44s_7[]={
  128298. {2,0, &_residue_44_high,
  128299. &_huff_book__44c7_s_short,&_huff_book__44c7_s_short,
  128300. &_resbook_44s_7,&_resbook_44s_7},
  128301. {2,0, &_residue_44_high,
  128302. &_huff_book__44c7_s_long,&_huff_book__44c7_s_long,
  128303. &_resbook_44s_7,&_resbook_44s_7}
  128304. };
  128305. static vorbis_residue_template _res_44s_8[]={
  128306. {2,0, &_residue_44_high,
  128307. &_huff_book__44c8_s_short,&_huff_book__44c8_s_short,
  128308. &_resbook_44s_8,&_resbook_44s_8},
  128309. {2,0, &_residue_44_high,
  128310. &_huff_book__44c8_s_long,&_huff_book__44c8_s_long,
  128311. &_resbook_44s_8,&_resbook_44s_8}
  128312. };
  128313. static vorbis_residue_template _res_44s_9[]={
  128314. {2,0, &_residue_44_high,
  128315. &_huff_book__44c9_s_short,&_huff_book__44c9_s_short,
  128316. &_resbook_44s_9,&_resbook_44s_9},
  128317. {2,0, &_residue_44_high,
  128318. &_huff_book__44c9_s_long,&_huff_book__44c9_s_long,
  128319. &_resbook_44s_9,&_resbook_44s_9}
  128320. };
  128321. static vorbis_mapping_template _mapres_template_44_stereo[]={
  128322. { _map_nominal, _res_44s_n1 }, /* -1 */
  128323. { _map_nominal, _res_44s_0 }, /* 0 */
  128324. { _map_nominal, _res_44s_1 }, /* 1 */
  128325. { _map_nominal, _res_44s_2 }, /* 2 */
  128326. { _map_nominal, _res_44s_3 }, /* 3 */
  128327. { _map_nominal, _res_44s_4 }, /* 4 */
  128328. { _map_nominal, _res_44s_5 }, /* 5 */
  128329. { _map_nominal, _res_44s_6 }, /* 6 */
  128330. { _map_nominal, _res_44s_7 }, /* 7 */
  128331. { _map_nominal, _res_44s_8 }, /* 8 */
  128332. { _map_nominal, _res_44s_9 }, /* 9 */
  128333. };
  128334. /*** End of inlined file: residue_44.h ***/
  128335. /*** Start of inlined file: psych_44.h ***/
  128336. static vorbis_info_psy_global _psy_global_44[5]={
  128337. {8, /* lines per eighth octave */
  128338. {20.f,14.f,12.f,12.f,12.f,12.f,12.f},
  128339. {-60.f,-30.f,-40.f,-40.f,-40.f,-40.f,-40.f}, 2,-75.f,
  128340. -6.f,
  128341. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  128342. },
  128343. {8, /* lines per eighth octave */
  128344. {14.f,10.f,10.f,10.f,10.f,10.f,10.f},
  128345. {-40.f,-30.f,-25.f,-25.f,-25.f,-25.f,-25.f}, 2,-80.f,
  128346. -6.f,
  128347. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  128348. },
  128349. {8, /* lines per eighth octave */
  128350. {12.f,10.f,10.f,10.f,10.f,10.f,10.f},
  128351. {-20.f,-20.f,-15.f,-15.f,-15.f,-15.f,-15.f}, 0,-80.f,
  128352. -6.f,
  128353. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  128354. },
  128355. {8, /* lines per eighth octave */
  128356. {10.f,8.f,8.f,8.f,8.f,8.f,8.f},
  128357. {-20.f,-15.f,-12.f,-12.f,-12.f,-12.f,-12.f}, 0,-80.f,
  128358. -6.f,
  128359. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  128360. },
  128361. {8, /* lines per eighth octave */
  128362. {10.f,6.f,6.f,6.f,6.f,6.f,6.f},
  128363. {-15.f,-15.f,-12.f,-12.f,-12.f,-12.f,-12.f}, 0,-85.f,
  128364. -6.f,
  128365. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  128366. },
  128367. };
  128368. static compandblock _psy_compand_44[6]={
  128369. {{
  128370. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  128371. 8, 9,10,11,12,13,14, 15, /* 15dB */
  128372. 16,17,18,19,20,21,22, 23, /* 23dB */
  128373. 24,25,26,27,28,29,30, 31, /* 31dB */
  128374. 32,33,34,35,36,37,38, 39, /* 39dB */
  128375. }},
  128376. {{
  128377. 0, 1, 2, 3, 4, 5, 6, 6, /* 7dB */
  128378. 7, 7, 7, 7, 6, 6, 6, 7, /* 15dB */
  128379. 7, 8, 9,10,11,12,13, 14, /* 23dB */
  128380. 15,16,17,17,17,18,18, 19, /* 31dB */
  128381. 19,19,20,21,22,23,24, 25, /* 39dB */
  128382. }},
  128383. {{
  128384. 0, 1, 2, 3, 4, 5, 5, 5, /* 7dB */
  128385. 6, 6, 6, 5, 4, 4, 4, 4, /* 15dB */
  128386. 4, 4, 5, 5, 5, 6, 6, 6, /* 23dB */
  128387. 7, 7, 7, 8, 8, 8, 9, 10, /* 31dB */
  128388. 11,12,13,14,15,16,17, 18, /* 39dB */
  128389. }},
  128390. {{
  128391. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  128392. 8, 9,10,11,12,13,14, 15, /* 15dB */
  128393. 16,17,18,19,20,21,22, 23, /* 23dB */
  128394. 24,25,26,27,28,29,30, 31, /* 31dB */
  128395. 32,33,34,35,36,37,38, 39, /* 39dB */
  128396. }},
  128397. {{
  128398. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  128399. 8, 9,10,11,12,12,13, 13, /* 15dB */
  128400. 13,14,14,14,15,15,15, 15, /* 23dB */
  128401. 16,16,17,17,17,18,18, 19, /* 31dB */
  128402. 19,19,20,21,22,23,24, 25, /* 39dB */
  128403. }},
  128404. {{
  128405. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  128406. 8, 8, 7, 6, 5, 4, 4, 4, /* 15dB */
  128407. 4, 4, 5, 5, 5, 6, 6, 6, /* 23dB */
  128408. 7, 7, 7, 8, 8, 8, 9, 10, /* 31dB */
  128409. 11,12,13,14,15,16,17, 18, /* 39dB */
  128410. }}
  128411. };
  128412. static vp_adjblock _vp_tonemask_adj_longblock[12]={
  128413. {{ -3, -8,-13,-15,-10,-10,-10,-10,-10,-10,-10, 0, 0, 0, 0, 0, 0}}, /* -1 */
  128414. {{ -4,-10,-14,-16,-15,-14,-13,-12,-12,-12,-11, -1, -1, -1, -1, -1, 0}}, /* 0 */
  128415. {{ -6,-12,-14,-16,-15,-15,-14,-13,-13,-12,-12, -2, -2, -1, -1, -1, 0}}, /* 1 */
  128416. {{-12,-13,-14,-16,-16,-16,-15,-14,-13,-12,-12, -6, -3, -1, -1, -1, 0}}, /* 2 */
  128417. {{-15,-15,-15,-16,-16,-16,-16,-14,-13,-13,-13,-10, -4, -2, -1, -1, 0}}, /* 3 */
  128418. /* 4 */
  128419. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-13,-11, -7 -3, -1, -1 , 0}}, /* 4 */
  128420. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-13,-11, -7 -3, -1, -1 , 0}}, /* 5 */
  128421. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -8, -4, -2, -2, 0}}, /* 6 */
  128422. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 7 */
  128423. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 8 */
  128424. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 9 */
  128425. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 10 */
  128426. };
  128427. static vp_adjblock _vp_tonemask_adj_otherblock[12]={
  128428. {{ -3, -8,-13,-15,-10,-10, -9, -9, -9, -9, -9, 1, 1, 1, 1, 1, 1}}, /* -1 */
  128429. {{ -4,-10,-14,-16,-14,-13,-12,-12,-11,-11,-10, 0, 0, 0, 0, 0, 0}}, /* 0 */
  128430. {{ -6,-12,-14,-16,-15,-15,-14,-13,-13,-12,-12, -2, -2, -1, 0, 0, 0}}, /* 1 */
  128431. {{-12,-13,-14,-16,-16,-16,-15,-14,-13,-12,-12, -5, -2, -1, 0, 0, 0}}, /* 2 */
  128432. {{-15,-15,-15,-16,-16,-16,-16,-14,-13,-13,-13,-10, -4, -2, 0, 0, 0}}, /* 3 */
  128433. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-13,-11, -7 -3, -1, -1 , 0}}, /* 4 */
  128434. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-13,-11, -7 -3, -1, -1 , 0}}, /* 5 */
  128435. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -8, -4, -2, -2, 0}}, /* 6 */
  128436. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 7 */
  128437. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 8 */
  128438. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 9 */
  128439. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 10 */
  128440. };
  128441. static noise3 _psy_noisebias_trans[12]={
  128442. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 8, 8, 8, 8, 10, 12, 14, 20},
  128443. {-30,-30,-30,-30,-26,-20,-16, -8, -6, -6, -2, 2, 2, 3, 6, 6, 15},
  128444. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
  128445. {{{-15,-15,-15,-15,-15,-12, -6, -4, 0, 2, 4, 4, 5, 5, 5, 8, 10},
  128446. {-30,-30,-30,-30,-26,-22,-20,-14, -8, -4, 0, 0, 0, 0, 2, 3, 6},
  128447. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -6, -4, -4, -4, -2}}},
  128448. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 5, 8, 10},
  128449. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -2, -2, -2, -2, 0, 1, 4},
  128450. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -6, -6, -6, -4}}},
  128451. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 2, 2, 4, 4, 5, 6, 10},
  128452. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -3, -3, -3, -2, -1, 0, 3},
  128453. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10, -8, -8, -7, -4}}},
  128454. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 2, 2, 4, 4, 4, 5, 8},
  128455. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -3, -3, -3, -3, -2, 0, 2},
  128456. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -4}}},
  128457. {{{-20,-20,-20,-20,-20,-18,-14, -8, -1, 1, 1, 1, 2, 3, 3, 4, 7},
  128458. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -3, -3, -3, -3, -2, -1, 1},
  128459. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -4}}},
  128460. {{{-24,-24,-24,-24,-20,-18,-14, -8, -1, 1, 1, 1, 2, 3, 3, 4, 7},
  128461. {-32,-32,-32,-32,-28,-24,-22,-16,-12, -6, -4, -4, -4, -4, -3, -1, 0},
  128462. {-34,-34,-34,-34,-30,-24,-24,-18,-14,-12,-12,-12,-12,-10,-10, -9, -5}}},
  128463. {{{-24,-24,-24,-24,-20,-18,-14, -8, -1, 1, 1, 1, 2, 3, 3, 4, 7},
  128464. {-32,-32,-32,-32,-28,-24,-24,-18,-14, -8, -6, -6, -6, -6, -5, -2, 0},
  128465. {-34,-34,-34,-34,-30,-26,-26,-24,-22,-19,-19,-19,-19,-18,-17,-16,-12}}},
  128466. {{{-24,-24,-24,-24,-20,-18,-14, -8, -1, 1, 1, 1, 2, 3, 3, 4, 7},
  128467. {-32,-32,-32,-32,-28,-24,-24,-24,-18,-14,-12,-10,-10,-10, -8, -6, -2},
  128468. {-34,-34,-34,-34,-30,-26,-26,-26,-24,-24,-24,-24,-24,-24,-24,-20,-16}}},
  128469. {{{-24,-24,-24,-24,-22,-20,-15,-10, -8, -2, 0, 0, 0, 1, 2, 3, 7},
  128470. {-36,-36,-36,-36,-30,-30,-30,-24,-20,-16,-16,-16,-16,-14,-12,-10, -7},
  128471. {-36,-36,-36,-36,-34,-30,-28,-26,-24,-30,-30,-30,-30,-30,-30,-24,-20}}},
  128472. {{{-28,-28,-28,-28,-28,-28,-28,-20,-14, -8, -4, -4, -4, -4, -4, -2, 2},
  128473. {-38,-38,-38,-38,-36,-34,-34,-30,-24,-20,-20,-20,-20,-18,-16,-12,-10},
  128474. {-40,-40,-40,-40,-40,-40,-40,-38,-35,-35,-35,-35,-35,-35,-35,-35,-30}}},
  128475. {{{-30,-30,-30,-30,-30,-30,-30,-28,-20,-14,-14,-14,-14,-14,-14,-12,-10},
  128476. {-40,-40,-40,-40,-40,-40,-40,-40,-35,-30,-30,-30,-30,-30,-30,-30,-20},
  128477. {-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40}}},
  128478. };
  128479. static noise3 _psy_noisebias_long[12]={
  128480. {{{-10,-10,-10,-10,-10, -4, 0, 0, 0, 6, 6, 6, 6, 10, 10, 12, 20},
  128481. {-20,-20,-20,-20,-20,-20,-10, -2, 0, 0, 0, 0, 0, 2, 4, 6, 15},
  128482. {-20,-20,-20,-20,-20,-20,-20,-10, -6, -6, -6, -6, -6, -4, -4, -4, -2}}},
  128483. {{{-10,-10,-10,-10,-10,-10, -8, 2, 2, 2, 4, 4, 5, 5, 5, 8, 10},
  128484. {-20,-20,-20,-20,-20,-20,-20,-14, -6, 0, 0, 0, 0, 0, 2, 3, 6},
  128485. {-20,-20,-20,-20,-20,-20,-20,-14, -8, -6, -6, -6, -6, -4, -4, -4, -2}}},
  128486. {{{-10,-10,-10,-10,-10,-10, -8, -4, 0, 2, 4, 4, 5, 5, 5, 8, 10},
  128487. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -2, -2, -2, -2, 0, 1, 4},
  128488. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -8, -8, -8, -8, -6, -6, -6, -4}}},
  128489. {{{-10,-10,-10,-10,-10,-10,-10, -8, 0, 2, 2, 2, 4, 4, 5, 6, 10},
  128490. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -3, -3, -3, -2, -1, 0, 3},
  128491. {-20,-20,-20,-20,-20,-20,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -4}}},
  128492. {{{-10,-10,-10,-10,-10,-10,-10, -8, 0, 2, 2, 2, 4, 4, 4, 5, 8},
  128493. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -3, -3, -3, -3, -2, 0, 2},
  128494. {-20,-20,-20,-20,-20,-20,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -5}}},
  128495. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 1, 1, 1, 2, 3, 3, 4, 7},
  128496. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -3, -3, -3, -3, -2, -1, 1},
  128497. {-20,-20,-20,-20,-20,-20,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -7}}},
  128498. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 1, 1, 1, 2, 3, 3, 4, 7},
  128499. {-22,-22,-22,-22,-22,-22,-22,-16,-12, -6, -4, -4, -4, -4, -3, -1, 0},
  128500. {-24,-24,-24,-24,-24,-24,-24,-18,-14,-12,-12,-12,-12,-10,-10, -9, -8}}},
  128501. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 1, 1, 1, 2, 3, 3, 4, 7},
  128502. {-24,-24,-24,-24,-24,-24,-24,-18,-14, -8, -6, -6, -6, -6, -5, -2, 0},
  128503. {-26,-26,-26,-26,-26,-26,-26,-18,-16,-15,-15,-15,-15,-13,-13,-12,-10}}},
  128504. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 1, 1, 1, 2, 3, 3, 4, 7},
  128505. {-24,-24,-24,-24,-24,-24,-24,-18,-14,-10, -8, -8, -8, -8, -6, -4, 0},
  128506. {-26,-26,-26,-26,-26,-26,-26,-22,-20,-19,-19,-19,-19,-18,-17,-16,-12}}},
  128507. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 0, 0, 0, 0, 1, 2, 3, 7},
  128508. {-26,-26,-26,-26,-26,-26,-26,-20,-16,-12,-10,-10,-10,-10, -8, -6, -2},
  128509. {-28,-28,-28,-28,-28,-28,-28,-26,-24,-24,-24,-24,-24,-24,-24,-20,-16}}},
  128510. {{{-22,-22,-22,-22,-22,-22,-22,-18,-14, -8, -4, -4, -4, -4, -4, -2, 2},
  128511. {-26,-26,-26,-26,-26,-26,-26,-22,-18,-16,-16,-16,-16,-14,-12,-10, -7},
  128512. {-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-24,-20}}},
  128513. {{{-24,-24,-24,-24,-24,-24,-24,-24,-24,-18,-14,-14,-14,-14,-14,-12,-10},
  128514. {-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-20},
  128515. {-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40}}},
  128516. };
  128517. static noise3 _psy_noisebias_impulse[12]={
  128518. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 8, 8, 8, 8, 10, 12, 14, 20},
  128519. {-30,-30,-30,-30,-26,-20,-16, -8, -6, -6, -2, 2, 2, 3, 6, 6, 15},
  128520. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
  128521. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 4, 8, 8, 8, 10, 12, 14, 20},
  128522. {-30,-30,-30,-30,-26,-22,-20,-14, -6, -2, 0, 0, 0, 0, 2, 3, 6},
  128523. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
  128524. {{{-12,-12,-12,-12,-12, -8, -6, -4, 0, 4, 4, 4, 4, 10, 12, 14, 20},
  128525. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -4, -4, -2, -2, -2, -2, 2},
  128526. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8,-10,-10, -8, -8, -8, -6, -4}}},
  128527. {{{-14,-14,-14,-14,-14,-10, -8, -6, -2, 2, 2, 2, 2, 8, 10, 10, 16},
  128528. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -4, -4, -4, -2, 0},
  128529. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10,-10,-10, -8, -4}}},
  128530. {{{-14,-14,-14,-14,-14,-10, -8, -6, -2, 2, 2, 2, 2, 6, 8, 8, 14},
  128531. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -4, -4, -4, -2, 0},
  128532. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10,-10,-10, -8, -4}}},
  128533. {{{-16,-16,-16,-16,-16,-12,-10, -6, -2, 0, 0, 0, 0, 4, 6, 6, 12},
  128534. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -4, -4, -4, -2, 0},
  128535. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10,-10,-10, -8, -4}}},
  128536. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 4, 6, 11},
  128537. {-32,-32,-32,-32,-28,-24,-22,-16,-10, -6, -8, -8, -6, -6, -6, -4, -2},
  128538. {-34,-34,-34,-34,-30,-26,-24,-18,-14,-12,-12,-12,-12,-12,-10, -9, -5}}},
  128539. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 4, 6, 11},
  128540. {-34,-34,-34,-34,-30,-30,-30,-24,-16,-16,-16,-16,-16,-16,-14,-14,-12},
  128541. {-36,-36,-36,-36,-36,-34,-28,-24,-20,-20,-20,-20,-20,-20,-20,-18,-16}}},
  128542. {{{-22,-22,-22,-22,-22,-20,-14,-10, -6, 0, 0, 0, 0, 4, 4, 6, 11},
  128543. {-34,-34,-34,-34,-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-24,-22},
  128544. {-40,-40,-40,-40,-40,-40,-40,-32,-30,-30,-30,-30,-30,-30,-30,-30,-24}}},
  128545. {{{-24,-24,-24,-24,-24,-22,-14,-10, -6, -1, -1, -1, -1, 3, 3, 5, 10},
  128546. {-34,-34,-34,-34,-34,-32,-32,-30,-26,-26,-26,-26,-26,-26,-26,-26,-24},
  128547. {-40,-40,-40,-40,-40,-40,-40,-32,-30,-30,-30,-30,-30,-30,-30,-30,-24}}},
  128548. {{{-28,-28,-28,-28,-28,-28,-28,-20,-14, -8, -4, -4, -4, -4, -4, -2, 2},
  128549. {-36,-36,-36,-36,-34,-32,-32,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26},
  128550. {-40,-40,-40,-40,-40,-40,-40,-32,-30,-30,-30,-30,-30,-30,-30,-24,-20}}},
  128551. {{{-30,-30,-30,-30,-30,-26,-24,-24,-24,-20,-16,-16,-16,-16,-16,-14,-12},
  128552. {-40,-40,-40,-40,-40,-40,-40,-40,-35,-30,-30,-30,-30,-30,-30,-30,-26},
  128553. {-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40}}},
  128554. };
  128555. static noise3 _psy_noisebias_padding[12]={
  128556. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 8, 8, 8, 8, 10, 12, 14, 20},
  128557. {-30,-30,-30,-30,-26,-20,-16, -8, -6, -6, -2, 2, 2, 3, 6, 6, 15},
  128558. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
  128559. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 8, 8, 8, 8, 10, 12, 14, 20},
  128560. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -2, 2, 3, 6, 6, 8, 10},
  128561. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -4, -4, -4, -4, -2, 0, 2}}},
  128562. {{{-12,-12,-12,-12,-12, -8, -6, -4, 0, 4, 4, 4, 4, 10, 12, 14, 20},
  128563. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, 0, 0, 0, 2, 2, 4, 8},
  128564. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -6, -6, -4, -2, 0}}},
  128565. {{{-14,-14,-14,-14,-14,-10, -8, -6, -2, 2, 2, 2, 2, 8, 10, 10, 16},
  128566. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -1, -1, -1, 0, 0, 2, 6},
  128567. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -8, -6, -4, -2}}},
  128568. {{{-14,-14,-14,-14,-14,-10, -8, -6, -2, 2, 2, 2, 2, 6, 8, 8, 14},
  128569. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -1, -1, -1, 0, 0, 2, 6},
  128570. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -8, -6, -4, -2}}},
  128571. {{{-16,-16,-16,-16,-16,-12,-10, -6, -2, 0, 0, 0, 0, 4, 6, 6, 12},
  128572. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -1, -1, -1, -1, 0, 2, 6},
  128573. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -8, -6, -4, -2}}},
  128574. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 6, 6, 12},
  128575. {-32,-32,-32,-32,-28,-24,-22,-16,-12, -6, -3, -3, -3, -3, -2, 0, 4},
  128576. {-34,-34,-34,-34,-30,-26,-24,-18,-14,-10,-10,-10,-10,-10, -8, -5, -3}}},
  128577. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 6, 6, 12},
  128578. {-34,-34,-34,-34,-30,-30,-24,-20,-14, -8, -4, -4, -4, -4, -3, -1, 4},
  128579. {-34,-34,-34,-34,-34,-30,-26,-20,-16,-13,-13,-13,-13,-13,-11, -8, -6}}},
  128580. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 6, 6, 12},
  128581. {-34,-34,-34,-34,-30,-30,-30,-24,-16,-10, -8, -6, -6, -6, -5, -3, 1},
  128582. {-34,-34,-34,-34,-32,-32,-28,-22,-18,-16,-16,-16,-16,-16,-14,-12,-10}}},
  128583. {{{-22,-22,-22,-22,-22,-20,-14,-10, -4, 0, 0, 0, 0, 3, 5, 5, 11},
  128584. {-34,-34,-34,-34,-30,-30,-30,-24,-16,-12,-10, -8, -8, -8, -7, -5, -2},
  128585. {-36,-36,-36,-36,-36,-34,-28,-22,-20,-20,-20,-20,-20,-20,-20,-16,-14}}},
  128586. {{{-28,-28,-28,-28,-28,-28,-28,-20,-14, -8, -2, -2, -2, -2, 0, 2, 6},
  128587. {-36,-36,-36,-36,-34,-32,-32,-24,-16,-12,-12,-12,-12,-12,-10, -8, -5},
  128588. {-40,-40,-40,-40,-40,-40,-40,-32,-26,-24,-24,-24,-24,-24,-24,-20,-18}}},
  128589. {{{-30,-30,-30,-30,-30,-26,-24,-24,-24,-20,-12,-12,-12,-12,-12,-10, -8},
  128590. {-40,-40,-40,-40,-40,-40,-40,-40,-35,-30,-25,-25,-25,-25,-25,-25,-15},
  128591. {-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40}}},
  128592. };
  128593. static noiseguard _psy_noiseguards_44[4]={
  128594. {3,3,15},
  128595. {3,3,15},
  128596. {10,10,100},
  128597. {10,10,100},
  128598. };
  128599. static int _psy_tone_suppress[12]={
  128600. -20,-20,-20,-20,-20,-24,-30,-40,-40,-45,-45,-45,
  128601. };
  128602. static int _psy_tone_0dB[12]={
  128603. 90,90,95,95,95,95,105,105,105,105,105,105,
  128604. };
  128605. static int _psy_noise_suppress[12]={
  128606. -20,-20,-24,-24,-24,-24,-30,-40,-40,-45,-45,-45,
  128607. };
  128608. static vorbis_info_psy _psy_info_template={
  128609. -1,
  128610. -140.,-140.,
  128611. {0.f,0.f,0.f}, 0.,0., -40.f, {0.},
  128612. 1, -0.f, .5f, .5f, 0,0,0,
  128613. {{-1},{-1},{-1}},{-1},105.f,
  128614. 0,0,-1,-1,0.,
  128615. };
  128616. static int _psy_ath_floater[12]={
  128617. -100,-100,-100,-100,-100,-100,-105,-105,-105,-105,-110,-120,
  128618. };
  128619. static int _psy_ath_abs[12]={
  128620. -130,-130,-130,-130,-140,-140,-140,-140,-140,-140,-140,-150,
  128621. };
  128622. static adj_stereo _psy_stereo_modes_44[12]={
  128623. {{ 4, 4, 4, 4, 4, 4, 4, 3, 2, 2, 1, 0, 0, 0, 0},
  128624. { 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 5, 4, 3},
  128625. { 1, 2, 3, 4, 4, 4, 4, 4, 4, 5, 6, 7, 8, 8, 8},
  128626. { 12,12.5, 13,13.5, 14,14.5, 15, 99, 99, 99, 99, 99, 99, 99, 99}},
  128627. {{ 4, 4, 4, 4, 4, 4, 4, 3, 2, 1, 0, 0, 0, 0, 0},
  128628. { 8, 8, 8, 8, 6, 6, 5, 5, 5, 5, 5, 5, 5, 4, 3},
  128629. { 1, 2, 3, 4, 4, 5, 6, 6, 6, 6, 6, 8, 8, 8, 8},
  128630. { 12,12.5, 13,13.5, 14,14.5, 15, 99, 99, 99, 99, 99, 99, 99, 99}},
  128631. {{ 3, 3, 3, 3, 3, 3, 3, 3, 2, 1, 0, 0, 0, 0, 0},
  128632. { 8, 8, 8, 8, 6, 6, 5, 5, 5, 5, 5, 5, 5, 4, 3},
  128633. { 1, 2, 3, 4, 4, 5, 6, 6, 6, 6, 6, 8, 8, 8, 8},
  128634. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128635. {{ 3, 3, 3, 3, 3, 3, 3, 2, 1, 1, 0, 0, 0, 0, 0},
  128636. { 8, 8, 6, 6, 5, 5, 4, 4, 4, 4, 4, 4, 3, 2, 1},
  128637. { 3, 4, 4, 5, 5, 6, 6, 6, 6, 6, 6, 8, 8, 8, 8},
  128638. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128639. {{ 2, 2, 2, 2, 2, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0},
  128640. { 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 2, 1},
  128641. { 4, 4, 5, 6, 6, 6, 6, 6, 8, 8, 10, 10, 10, 10, 10},
  128642. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128643. {{ 2, 2, 2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128644. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 2, 1, 0},
  128645. { 6, 6, 6, 8, 8, 8, 8, 8, 8, 8, 10, 10, 10, 10, 10},
  128646. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128647. {{ 2, 2, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128648. { 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0},
  128649. { 6, 7, 8, 8, 8, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12},
  128650. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128651. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128652. { 3, 3, 3, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128653. { 8, 8, 8, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12},
  128654. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128655. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128656. { 3, 3, 3, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128657. { 8, 8, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12},
  128658. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128659. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128660. { 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128661. { 8, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12},
  128662. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128663. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128664. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128665. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  128666. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128667. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128668. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128669. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  128670. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128671. };
  128672. static att3 _psy_tone_masteratt_44[12]={
  128673. {{ 35, 21, 9}, 0, 0}, /* -1 */
  128674. {{ 30, 20, 8}, -2, 1.25}, /* 0 */
  128675. /* 1 */
  128676. {{ 25, 12, 2}, 0, 0}, /* 1 */
  128677. /* 2 */
  128678. {{ 20, 9, -3}, 0, 0}, /* 2 */
  128679. {{ 20, 9, -4}, 0, 0}, /* 3 */
  128680. {{ 20, 9, -4}, 0, 0}, /* 4 */
  128681. {{ 20, 6, -6}, 0, 0}, /* 5 */
  128682. {{ 20, 3, -10}, 0, 0}, /* 6 */
  128683. {{ 18, 1, -14}, 0, 0}, /* 7 */
  128684. {{ 18, 0, -16}, 0, 0}, /* 8 */
  128685. {{ 18, -2, -16}, 0, 0}, /* 9 */
  128686. {{ 12, -2, -20}, 0, 0}, /* 10 */
  128687. };
  128688. static double _psy_lowpass_44[12]={
  128689. 13.9,15.1,15.8,16.5,17.2,18.9,20.1,48.,999.,999.,999.,999.
  128690. };
  128691. static int _noise_start_short_44[11]={
  128692. 32,16,16,16,32,9999,9999,9999,9999,9999,9999
  128693. };
  128694. static int _noise_start_long_44[11]={
  128695. 256,128,128,256,512,9999,9999,9999,9999,9999,9999
  128696. };
  128697. static int _noise_part_short_44[11]={
  128698. 8,8,8,8,8,8,8,8,8,8,8
  128699. };
  128700. static int _noise_part_long_44[11]={
  128701. 32,32,32,32,32,32,32,32,32,32,32
  128702. };
  128703. static double _noise_thresh_44[11]={
  128704. .2,.2,.2,.4,.6,9999.,9999.,9999.,9999.,9999.,9999.,
  128705. };
  128706. static double _noise_thresh_5only[2]={
  128707. .5,.5,
  128708. };
  128709. /*** End of inlined file: psych_44.h ***/
  128710. static double rate_mapping_44_stereo[12]={
  128711. 22500.,32000.,40000.,48000.,56000.,64000.,
  128712. 80000.,96000.,112000.,128000.,160000.,250001.
  128713. };
  128714. static double quality_mapping_44[12]={
  128715. -.1,.0,.1,.2,.3,.4,.5,.6,.7,.8,.9,1.0
  128716. };
  128717. static int blocksize_short_44[11]={
  128718. 512,256,256,256,256,256,256,256,256,256,256
  128719. };
  128720. static int blocksize_long_44[11]={
  128721. 4096,2048,2048,2048,2048,2048,2048,2048,2048,2048,2048
  128722. };
  128723. static double _psy_compand_short_mapping[12]={
  128724. 0.5, 1., 1., 1.3, 1.6, 2., 2., 2., 2., 2., 2., 2.
  128725. };
  128726. static double _psy_compand_long_mapping[12]={
  128727. 3.5, 4., 4., 4.3, 4.6, 5., 5., 5., 5., 5., 5., 5.
  128728. };
  128729. static double _global_mapping_44[12]={
  128730. 0., 1., 1., 1.5, 2., 2., 2.5, 2.7, 3.0, 3.7, 4., 4.
  128731. };
  128732. static int _floor_short_mapping_44[11]={
  128733. 1,0,0,2,2,4,5,5,5,5,5
  128734. };
  128735. static int _floor_long_mapping_44[11]={
  128736. 8,7,7,7,7,7,7,7,7,7,7
  128737. };
  128738. ve_setup_data_template ve_setup_44_stereo={
  128739. 11,
  128740. rate_mapping_44_stereo,
  128741. quality_mapping_44,
  128742. 2,
  128743. 40000,
  128744. 50000,
  128745. blocksize_short_44,
  128746. blocksize_long_44,
  128747. _psy_tone_masteratt_44,
  128748. _psy_tone_0dB,
  128749. _psy_tone_suppress,
  128750. _vp_tonemask_adj_otherblock,
  128751. _vp_tonemask_adj_longblock,
  128752. _vp_tonemask_adj_otherblock,
  128753. _psy_noiseguards_44,
  128754. _psy_noisebias_impulse,
  128755. _psy_noisebias_padding,
  128756. _psy_noisebias_trans,
  128757. _psy_noisebias_long,
  128758. _psy_noise_suppress,
  128759. _psy_compand_44,
  128760. _psy_compand_short_mapping,
  128761. _psy_compand_long_mapping,
  128762. {_noise_start_short_44,_noise_start_long_44},
  128763. {_noise_part_short_44,_noise_part_long_44},
  128764. _noise_thresh_44,
  128765. _psy_ath_floater,
  128766. _psy_ath_abs,
  128767. _psy_lowpass_44,
  128768. _psy_global_44,
  128769. _global_mapping_44,
  128770. _psy_stereo_modes_44,
  128771. _floor_books,
  128772. _floor,
  128773. _floor_short_mapping_44,
  128774. _floor_long_mapping_44,
  128775. _mapres_template_44_stereo
  128776. };
  128777. /*** End of inlined file: setup_44.h ***/
  128778. /*** Start of inlined file: setup_44u.h ***/
  128779. /*** Start of inlined file: residue_44u.h ***/
  128780. /*** Start of inlined file: res_books_uncoupled.h ***/
  128781. static long _vq_quantlist__16u0__p1_0[] = {
  128782. 1,
  128783. 0,
  128784. 2,
  128785. };
  128786. static long _vq_lengthlist__16u0__p1_0[] = {
  128787. 1, 4, 4, 5, 7, 7, 5, 7, 8, 5, 8, 8, 8,10,10, 8,
  128788. 10,11, 5, 8, 8, 8,10,10, 8,10,10, 4, 9, 9, 9,12,
  128789. 11, 8,11,11, 8,12,11,10,12,14,10,13,13, 7,11,11,
  128790. 10,14,12,11,14,14, 4, 9, 9, 8,11,11, 9,11,12, 7,
  128791. 11,11,10,13,14,10,12,14, 8,11,12,10,14,14,10,13,
  128792. 12,
  128793. };
  128794. static float _vq_quantthresh__16u0__p1_0[] = {
  128795. -0.5, 0.5,
  128796. };
  128797. static long _vq_quantmap__16u0__p1_0[] = {
  128798. 1, 0, 2,
  128799. };
  128800. static encode_aux_threshmatch _vq_auxt__16u0__p1_0 = {
  128801. _vq_quantthresh__16u0__p1_0,
  128802. _vq_quantmap__16u0__p1_0,
  128803. 3,
  128804. 3
  128805. };
  128806. static static_codebook _16u0__p1_0 = {
  128807. 4, 81,
  128808. _vq_lengthlist__16u0__p1_0,
  128809. 1, -535822336, 1611661312, 2, 0,
  128810. _vq_quantlist__16u0__p1_0,
  128811. NULL,
  128812. &_vq_auxt__16u0__p1_0,
  128813. NULL,
  128814. 0
  128815. };
  128816. static long _vq_quantlist__16u0__p2_0[] = {
  128817. 1,
  128818. 0,
  128819. 2,
  128820. };
  128821. static long _vq_lengthlist__16u0__p2_0[] = {
  128822. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 7, 8, 9, 7,
  128823. 8, 9, 5, 7, 7, 7, 9, 8, 7, 9, 7, 4, 7, 7, 7, 9,
  128824. 9, 7, 8, 8, 6, 9, 8, 7, 8,11, 9,11,10, 6, 8, 9,
  128825. 8,11, 8, 9,10,11, 4, 7, 7, 7, 8, 8, 7, 9, 9, 6,
  128826. 9, 8, 9,11,10, 8, 8,11, 6, 8, 9, 9,10,11, 8,11,
  128827. 8,
  128828. };
  128829. static float _vq_quantthresh__16u0__p2_0[] = {
  128830. -0.5, 0.5,
  128831. };
  128832. static long _vq_quantmap__16u0__p2_0[] = {
  128833. 1, 0, 2,
  128834. };
  128835. static encode_aux_threshmatch _vq_auxt__16u0__p2_0 = {
  128836. _vq_quantthresh__16u0__p2_0,
  128837. _vq_quantmap__16u0__p2_0,
  128838. 3,
  128839. 3
  128840. };
  128841. static static_codebook _16u0__p2_0 = {
  128842. 4, 81,
  128843. _vq_lengthlist__16u0__p2_0,
  128844. 1, -535822336, 1611661312, 2, 0,
  128845. _vq_quantlist__16u0__p2_0,
  128846. NULL,
  128847. &_vq_auxt__16u0__p2_0,
  128848. NULL,
  128849. 0
  128850. };
  128851. static long _vq_quantlist__16u0__p3_0[] = {
  128852. 2,
  128853. 1,
  128854. 3,
  128855. 0,
  128856. 4,
  128857. };
  128858. static long _vq_lengthlist__16u0__p3_0[] = {
  128859. 1, 5, 5, 7, 7, 6, 7, 7, 8, 8, 6, 7, 8, 8, 8, 8,
  128860. 9, 9,11,11, 8, 9, 9,11,11, 6, 9, 8,10,10, 8,10,
  128861. 10,11,11, 8,10,10,11,11,10,11,10,13,12, 9,11,10,
  128862. 13,13, 6, 8, 9,10,10, 8,10,10,11,11, 8,10,10,11,
  128863. 11, 9,10,11,13,12,10,10,11,12,12, 8,11,11,14,13,
  128864. 10,12,11,15,13, 9,12,11,15,14,12,14,13,16,14,12,
  128865. 13,13,17,14, 8,11,11,13,14, 9,11,12,14,15,10,11,
  128866. 12,13,15,11,13,13,14,16,12,13,14,14,16, 5, 9, 9,
  128867. 11,11, 9,11,11,12,12, 8,11,11,12,12,11,12,12,15,
  128868. 14,10,12,12,15,15, 8,11,11,13,12,10,12,12,13,13,
  128869. 10,12,12,14,13,12,12,13,14,15,11,13,13,17,16, 7,
  128870. 11,11,13,13,10,12,12,14,13,10,12,12,13,14,12,13,
  128871. 12,15,14,11,13,13,15,14, 9,12,12,16,15,11,13,13,
  128872. 17,16,10,13,13,16,16,13,14,15,15,16,13,15,14,19,
  128873. 17, 9,12,12,14,16,11,13,13,15,16,10,13,13,17,16,
  128874. 13,14,13,17,15,12,15,15,16,17, 5, 9, 9,11,11, 8,
  128875. 11,11,13,12, 9,11,11,12,12,10,12,12,14,15,11,12,
  128876. 12,14,14, 7,11,10,13,12,10,12,12,14,13,10,11,12,
  128877. 13,13,11,13,13,15,16,12,12,13,15,15, 7,11,11,13,
  128878. 13,10,13,13,14,14,10,12,12,13,13,11,13,13,16,15,
  128879. 12,13,13,15,14, 9,12,12,15,15,10,13,13,17,16,11,
  128880. 12,13,15,15,12,15,14,18,18,13,14,14,16,17, 9,12,
  128881. 12,15,16,10,13,13,15,16,11,13,13,15,16,13,15,15,
  128882. 17,17,13,15,14,16,15, 7,11,11,15,16,10,13,12,16,
  128883. 17,10,12,13,15,17,15,16,16,18,17,13,15,15,17,18,
  128884. 8,12,12,16,16,11,13,14,17,18,11,13,13,18,16,15,
  128885. 17,16,17,19,14,15,15,17,16, 8,12,12,16,15,11,14,
  128886. 13,18,17,11,13,14,18,17,15,16,16,18,17,13,16,16,
  128887. 18,18,11,15,14,18,17,13,14,15,18, 0,12,15,15, 0,
  128888. 17,17,16,17,17,18,14,16,18,18, 0,11,14,14,17, 0,
  128889. 12,15,14,17,19,12,15,14,18, 0,15,18,16, 0,17,14,
  128890. 18,16,18, 0, 7,11,11,16,15,10,12,12,18,16,10,13,
  128891. 13,16,15,13,15,14,17,17,14,16,16,19,18, 8,12,12,
  128892. 16,16,11,13,13,18,16,11,13,14,17,16,14,15,15,19,
  128893. 18,15,16,16, 0,19, 8,12,12,16,17,11,13,13,17,17,
  128894. 11,14,13,17,17,13,15,15,17,19,15,17,17,19, 0,11,
  128895. 14,15,19,17,12,15,16,18,18,12,14,15,19,17,14,16,
  128896. 17, 0,18,16,16,19,17, 0,11,14,14,18,19,12,15,14,
  128897. 17,17,13,16,14,17,16,14,17,16,18,18,15,18,15, 0,
  128898. 18,
  128899. };
  128900. static float _vq_quantthresh__16u0__p3_0[] = {
  128901. -1.5, -0.5, 0.5, 1.5,
  128902. };
  128903. static long _vq_quantmap__16u0__p3_0[] = {
  128904. 3, 1, 0, 2, 4,
  128905. };
  128906. static encode_aux_threshmatch _vq_auxt__16u0__p3_0 = {
  128907. _vq_quantthresh__16u0__p3_0,
  128908. _vq_quantmap__16u0__p3_0,
  128909. 5,
  128910. 5
  128911. };
  128912. static static_codebook _16u0__p3_0 = {
  128913. 4, 625,
  128914. _vq_lengthlist__16u0__p3_0,
  128915. 1, -533725184, 1611661312, 3, 0,
  128916. _vq_quantlist__16u0__p3_0,
  128917. NULL,
  128918. &_vq_auxt__16u0__p3_0,
  128919. NULL,
  128920. 0
  128921. };
  128922. static long _vq_quantlist__16u0__p4_0[] = {
  128923. 2,
  128924. 1,
  128925. 3,
  128926. 0,
  128927. 4,
  128928. };
  128929. static long _vq_lengthlist__16u0__p4_0[] = {
  128930. 3, 5, 5, 8, 8, 6, 6, 6, 9, 9, 6, 6, 6, 9, 9, 9,
  128931. 10, 9,11,11, 9, 9, 9,11,11, 6, 7, 7,10,10, 7, 7,
  128932. 8,10,10, 7, 7, 8,10,10,10,10,10,11,12, 9,10,10,
  128933. 11,12, 6, 7, 7,10,10, 7, 8, 7,10,10, 7, 8, 7,10,
  128934. 10,10,11,10,12,11,10,10,10,13,10, 9,10,10,12,12,
  128935. 10,11,10,14,12, 9,11,11,13,13,11,12,13,13,13,11,
  128936. 12,12,15,13, 9,10,10,12,13, 9,11,10,12,13,10,10,
  128937. 11,12,13,11,12,12,12,13,11,12,12,13,13, 5, 7, 7,
  128938. 10,10, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,10,12,
  128939. 13,10,10,11,12,12, 6, 8, 8,11,10, 7, 8, 9,10,12,
  128940. 8, 9, 9,11,11,11,10,11,11,12,10,11,11,13,12, 7,
  128941. 8, 8,10,11, 8, 9, 8,11,10, 8, 9, 9,11,11,10,12,
  128942. 10,13,11,10,11,11,13,13,10,11,10,14,13,10,10,11,
  128943. 13,13,10,12,11,14,13,12,11,13,12,13,13,12,13,14,
  128944. 14,10,11,11,13,13,10,11,10,12,13,10,12,12,12,14,
  128945. 12,12,12,14,12,12,13,12,17,15, 5, 7, 7,10,10, 7,
  128946. 8, 8,10,10, 7, 8, 8,11,10,10,10,11,12,12,10,11,
  128947. 11,12,13, 6, 8, 8,11,10, 8, 9, 9,11,11, 7, 8, 9,
  128948. 10,11,11,11,11,12,12,10,10,11,12,13, 6, 8, 8,10,
  128949. 11, 8, 9, 9,11,11, 7, 9, 7,11,10,10,12,12,13,13,
  128950. 11,11,10,13,11, 9,11,10,14,13,11,11,11,15,13,10,
  128951. 10,11,13,13,12,13,13,14,14,12,11,12,12,13,10,11,
  128952. 11,12,13,10,11,12,13,13,10,11,10,13,12,12,12,13,
  128953. 14, 0,12,13,11,13,11, 8,10,10,13,13,10,11,11,14,
  128954. 13,10,11,11,13,12,13,14,14,14,15,12,12,12,15,14,
  128955. 9,11,10,13,12,10,10,11,13,14,11,11,11,15,12,13,
  128956. 12,14,15,16,13,13,13,14,13, 9,11,11,12,12,10,12,
  128957. 11,13,13,10,11,11,13,14,13,13,13,15,15,13,13,14,
  128958. 17,15,11,12,12,14,14,10,11,12,13,15,12,13,13, 0,
  128959. 15,13,11,14,12,16,14,16,14, 0,15,11,12,12,14,16,
  128960. 11,13,12,16,15,12,13,13,14,15,12,14,12,15,13,15,
  128961. 14,14,16,16, 8,10,10,13,13,10,11,10,13,14,10,11,
  128962. 11,13,13,13,13,12,14,14,14,13,13,16,17, 9,10,10,
  128963. 12,14,10,12,11,14,13,10,11,12,13,14,12,12,12,15,
  128964. 15,13,13,13,14,14, 9,10,10,13,13,10,11,12,12,14,
  128965. 10,11,10,13,13,13,13,13,14,16,13,13,13,14,14,11,
  128966. 12,13,15,13,12,14,13,14,16,12,12,13,13,14,13,14,
  128967. 14,17,15,13,12,17,13,16,11,12,13,14,15,12,13,14,
  128968. 14,17,11,12,11,14,14,13,16,14,16, 0,14,15,11,15,
  128969. 11,
  128970. };
  128971. static float _vq_quantthresh__16u0__p4_0[] = {
  128972. -1.5, -0.5, 0.5, 1.5,
  128973. };
  128974. static long _vq_quantmap__16u0__p4_0[] = {
  128975. 3, 1, 0, 2, 4,
  128976. };
  128977. static encode_aux_threshmatch _vq_auxt__16u0__p4_0 = {
  128978. _vq_quantthresh__16u0__p4_0,
  128979. _vq_quantmap__16u0__p4_0,
  128980. 5,
  128981. 5
  128982. };
  128983. static static_codebook _16u0__p4_0 = {
  128984. 4, 625,
  128985. _vq_lengthlist__16u0__p4_0,
  128986. 1, -533725184, 1611661312, 3, 0,
  128987. _vq_quantlist__16u0__p4_0,
  128988. NULL,
  128989. &_vq_auxt__16u0__p4_0,
  128990. NULL,
  128991. 0
  128992. };
  128993. static long _vq_quantlist__16u0__p5_0[] = {
  128994. 4,
  128995. 3,
  128996. 5,
  128997. 2,
  128998. 6,
  128999. 1,
  129000. 7,
  129001. 0,
  129002. 8,
  129003. };
  129004. static long _vq_lengthlist__16u0__p5_0[] = {
  129005. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 8, 8, 8,
  129006. 9, 9, 4, 6, 6, 8, 8, 8, 8, 9, 9, 7, 8, 8, 9, 9,
  129007. 9, 9,11,10, 7, 8, 8, 9, 9, 9, 9,10,11, 7, 8, 8,
  129008. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  129009. 9, 9,10,10,11,11,12,12, 9, 9, 9,10,10,11,11,12,
  129010. 12,
  129011. };
  129012. static float _vq_quantthresh__16u0__p5_0[] = {
  129013. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  129014. };
  129015. static long _vq_quantmap__16u0__p5_0[] = {
  129016. 7, 5, 3, 1, 0, 2, 4, 6,
  129017. 8,
  129018. };
  129019. static encode_aux_threshmatch _vq_auxt__16u0__p5_0 = {
  129020. _vq_quantthresh__16u0__p5_0,
  129021. _vq_quantmap__16u0__p5_0,
  129022. 9,
  129023. 9
  129024. };
  129025. static static_codebook _16u0__p5_0 = {
  129026. 2, 81,
  129027. _vq_lengthlist__16u0__p5_0,
  129028. 1, -531628032, 1611661312, 4, 0,
  129029. _vq_quantlist__16u0__p5_0,
  129030. NULL,
  129031. &_vq_auxt__16u0__p5_0,
  129032. NULL,
  129033. 0
  129034. };
  129035. static long _vq_quantlist__16u0__p6_0[] = {
  129036. 6,
  129037. 5,
  129038. 7,
  129039. 4,
  129040. 8,
  129041. 3,
  129042. 9,
  129043. 2,
  129044. 10,
  129045. 1,
  129046. 11,
  129047. 0,
  129048. 12,
  129049. };
  129050. static long _vq_lengthlist__16u0__p6_0[] = {
  129051. 1, 4, 4, 7, 7,10,10,12,12,13,13,18,17, 3, 6, 6,
  129052. 9, 9,11,11,13,13,14,14,18,17, 3, 6, 6, 9, 9,11,
  129053. 11,13,13,14,14,17,18, 7, 9, 9,11,11,13,13,14,14,
  129054. 15,15, 0, 0, 7, 9, 9,11,11,13,13,14,14,15,16,19,
  129055. 18,10,11,11,13,13,14,14,16,15,17,18, 0, 0,10,11,
  129056. 11,13,13,14,14,15,15,16,18, 0, 0,11,13,13,14,14,
  129057. 15,15,17,17, 0,19, 0, 0,11,13,13,14,14,14,15,16,
  129058. 18, 0,19, 0, 0,13,14,14,15,15,18,17,18,18, 0,19,
  129059. 0, 0,13,14,14,15,16,16,16,18,18,19, 0, 0, 0,16,
  129060. 17,17, 0,17,19,19, 0,19, 0, 0, 0, 0,16,19,16,17,
  129061. 18, 0,19, 0, 0, 0, 0, 0, 0,
  129062. };
  129063. static float _vq_quantthresh__16u0__p6_0[] = {
  129064. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  129065. 12.5, 17.5, 22.5, 27.5,
  129066. };
  129067. static long _vq_quantmap__16u0__p6_0[] = {
  129068. 11, 9, 7, 5, 3, 1, 0, 2,
  129069. 4, 6, 8, 10, 12,
  129070. };
  129071. static encode_aux_threshmatch _vq_auxt__16u0__p6_0 = {
  129072. _vq_quantthresh__16u0__p6_0,
  129073. _vq_quantmap__16u0__p6_0,
  129074. 13,
  129075. 13
  129076. };
  129077. static static_codebook _16u0__p6_0 = {
  129078. 2, 169,
  129079. _vq_lengthlist__16u0__p6_0,
  129080. 1, -526516224, 1616117760, 4, 0,
  129081. _vq_quantlist__16u0__p6_0,
  129082. NULL,
  129083. &_vq_auxt__16u0__p6_0,
  129084. NULL,
  129085. 0
  129086. };
  129087. static long _vq_quantlist__16u0__p6_1[] = {
  129088. 2,
  129089. 1,
  129090. 3,
  129091. 0,
  129092. 4,
  129093. };
  129094. static long _vq_lengthlist__16u0__p6_1[] = {
  129095. 1, 4, 5, 6, 6, 4, 6, 6, 6, 6, 4, 6, 6, 6, 6, 6,
  129096. 6, 6, 7, 7, 6, 6, 6, 7, 7,
  129097. };
  129098. static float _vq_quantthresh__16u0__p6_1[] = {
  129099. -1.5, -0.5, 0.5, 1.5,
  129100. };
  129101. static long _vq_quantmap__16u0__p6_1[] = {
  129102. 3, 1, 0, 2, 4,
  129103. };
  129104. static encode_aux_threshmatch _vq_auxt__16u0__p6_1 = {
  129105. _vq_quantthresh__16u0__p6_1,
  129106. _vq_quantmap__16u0__p6_1,
  129107. 5,
  129108. 5
  129109. };
  129110. static static_codebook _16u0__p6_1 = {
  129111. 2, 25,
  129112. _vq_lengthlist__16u0__p6_1,
  129113. 1, -533725184, 1611661312, 3, 0,
  129114. _vq_quantlist__16u0__p6_1,
  129115. NULL,
  129116. &_vq_auxt__16u0__p6_1,
  129117. NULL,
  129118. 0
  129119. };
  129120. static long _vq_quantlist__16u0__p7_0[] = {
  129121. 1,
  129122. 0,
  129123. 2,
  129124. };
  129125. static long _vq_lengthlist__16u0__p7_0[] = {
  129126. 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  129127. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  129128. 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  129129. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  129130. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  129131. 7,
  129132. };
  129133. static float _vq_quantthresh__16u0__p7_0[] = {
  129134. -157.5, 157.5,
  129135. };
  129136. static long _vq_quantmap__16u0__p7_0[] = {
  129137. 1, 0, 2,
  129138. };
  129139. static encode_aux_threshmatch _vq_auxt__16u0__p7_0 = {
  129140. _vq_quantthresh__16u0__p7_0,
  129141. _vq_quantmap__16u0__p7_0,
  129142. 3,
  129143. 3
  129144. };
  129145. static static_codebook _16u0__p7_0 = {
  129146. 4, 81,
  129147. _vq_lengthlist__16u0__p7_0,
  129148. 1, -518803456, 1628680192, 2, 0,
  129149. _vq_quantlist__16u0__p7_0,
  129150. NULL,
  129151. &_vq_auxt__16u0__p7_0,
  129152. NULL,
  129153. 0
  129154. };
  129155. static long _vq_quantlist__16u0__p7_1[] = {
  129156. 7,
  129157. 6,
  129158. 8,
  129159. 5,
  129160. 9,
  129161. 4,
  129162. 10,
  129163. 3,
  129164. 11,
  129165. 2,
  129166. 12,
  129167. 1,
  129168. 13,
  129169. 0,
  129170. 14,
  129171. };
  129172. static long _vq_lengthlist__16u0__p7_1[] = {
  129173. 1, 5, 5, 6, 5, 9,10,11,11,10,10,10,10,10,10, 5,
  129174. 8, 8, 8,10,10,10,10,10,10,10,10,10,10,10, 5, 8,
  129175. 9, 9, 9,10,10,10,10,10,10,10,10,10,10, 5,10, 8,
  129176. 10,10,10,10,10,10,10,10,10,10,10,10, 4, 8, 9,10,
  129177. 10,10,10,10,10,10,10,10,10,10,10, 9,10,10,10,10,
  129178. 10,10,10,10,10,10,10,10,10,10, 9,10,10,10,10,10,
  129179. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129180. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129181. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129182. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129183. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129184. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129185. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129186. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129187. 10,
  129188. };
  129189. static float _vq_quantthresh__16u0__p7_1[] = {
  129190. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  129191. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  129192. };
  129193. static long _vq_quantmap__16u0__p7_1[] = {
  129194. 13, 11, 9, 7, 5, 3, 1, 0,
  129195. 2, 4, 6, 8, 10, 12, 14,
  129196. };
  129197. static encode_aux_threshmatch _vq_auxt__16u0__p7_1 = {
  129198. _vq_quantthresh__16u0__p7_1,
  129199. _vq_quantmap__16u0__p7_1,
  129200. 15,
  129201. 15
  129202. };
  129203. static static_codebook _16u0__p7_1 = {
  129204. 2, 225,
  129205. _vq_lengthlist__16u0__p7_1,
  129206. 1, -520986624, 1620377600, 4, 0,
  129207. _vq_quantlist__16u0__p7_1,
  129208. NULL,
  129209. &_vq_auxt__16u0__p7_1,
  129210. NULL,
  129211. 0
  129212. };
  129213. static long _vq_quantlist__16u0__p7_2[] = {
  129214. 10,
  129215. 9,
  129216. 11,
  129217. 8,
  129218. 12,
  129219. 7,
  129220. 13,
  129221. 6,
  129222. 14,
  129223. 5,
  129224. 15,
  129225. 4,
  129226. 16,
  129227. 3,
  129228. 17,
  129229. 2,
  129230. 18,
  129231. 1,
  129232. 19,
  129233. 0,
  129234. 20,
  129235. };
  129236. static long _vq_lengthlist__16u0__p7_2[] = {
  129237. 1, 6, 6, 7, 8, 7, 7,10, 9,10, 9,11,10, 9,11,10,
  129238. 9, 9, 9, 9,10, 6, 8, 7, 9, 9, 8, 8,10,10, 9,11,
  129239. 11,12,12,10, 9,11, 9,12,10, 9, 6, 9, 8, 9,12, 8,
  129240. 8,11, 9,11,11,12,11,12,12,10,11,11,10,10,11, 7,
  129241. 10, 9, 9, 9, 9, 9,10, 9,10, 9,10,10,12,10,10,10,
  129242. 11,12,10,10, 7, 9, 9, 9,10, 9, 9,10,10, 9, 9, 9,
  129243. 11,11,10,10,10,10, 9, 9,12, 7, 9,10, 9,11, 9,10,
  129244. 9,10,11,11,11,10,11,12, 9,12,11,10,10,10, 7, 9,
  129245. 9, 9, 9,10,12,10, 9,11,12,10,11,12,12,11, 9,10,
  129246. 11,10,11, 7, 9,10,10,11,10, 9,10,11,11,11,10,12,
  129247. 12,12,11,11,10,11,11,12, 8, 9,10,12,11,10,10,12,
  129248. 12,12,12,12,10,11,11, 9,11,10,12,11,11, 8, 9,10,
  129249. 10,11,12,11,11,10,10,10,12,12,12, 9,10,12,12,12,
  129250. 12,12, 8,10,11,10,10,12, 9,11,12,12,11,12,12,12,
  129251. 12,10,12,10,10,10,10, 8,12,11,11,11,10,10,11,12,
  129252. 12,12,12,11,12,12,12,11,11,11,12,10, 9,10,10,12,
  129253. 10,12,10,12,12,10,10,10,11,12,12,12,11,12,12,12,
  129254. 11,10,11,12,12,12,11,12,12,11,12,12,11,12,12,12,
  129255. 12,11,12,12,10,10,10,10,11,11,12,11,12,12,12,12,
  129256. 12,12,12,11,12,11,10,11,11,12,11,11, 9,10,10,10,
  129257. 12,10,10,11, 9,11,12,11,12,11,12,12,10,11,10,12,
  129258. 9, 9, 9,12,11,10,11,10,12,10,12,10,12,12,12,11,
  129259. 11,11,11,11,10, 9,10,10,11,10,11,11,12,11,10,11,
  129260. 12,12,12,11,11, 9,12,10,12, 9,10,12,10,10,11,10,
  129261. 11,11,12,11,10,11,10,11,11,11,11,12,11,11,10, 9,
  129262. 10,10,10, 9,11,11,10, 9,12,10,11,12,11,12,12,11,
  129263. 12,11,12,11,10,11,10,12,11,12,11,12,11,12,10,11,
  129264. 10,10,12,11,10,11,11,11,10,
  129265. };
  129266. static float _vq_quantthresh__16u0__p7_2[] = {
  129267. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  129268. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  129269. 6.5, 7.5, 8.5, 9.5,
  129270. };
  129271. static long _vq_quantmap__16u0__p7_2[] = {
  129272. 19, 17, 15, 13, 11, 9, 7, 5,
  129273. 3, 1, 0, 2, 4, 6, 8, 10,
  129274. 12, 14, 16, 18, 20,
  129275. };
  129276. static encode_aux_threshmatch _vq_auxt__16u0__p7_2 = {
  129277. _vq_quantthresh__16u0__p7_2,
  129278. _vq_quantmap__16u0__p7_2,
  129279. 21,
  129280. 21
  129281. };
  129282. static static_codebook _16u0__p7_2 = {
  129283. 2, 441,
  129284. _vq_lengthlist__16u0__p7_2,
  129285. 1, -529268736, 1611661312, 5, 0,
  129286. _vq_quantlist__16u0__p7_2,
  129287. NULL,
  129288. &_vq_auxt__16u0__p7_2,
  129289. NULL,
  129290. 0
  129291. };
  129292. static long _huff_lengthlist__16u0__single[] = {
  129293. 3, 5, 8, 7,14, 8, 9,19, 5, 2, 5, 5, 9, 6, 9,19,
  129294. 8, 4, 5, 7, 8, 9,13,19, 7, 4, 6, 5, 9, 6, 9,19,
  129295. 12, 8, 7, 9,10,11,13,19, 8, 5, 8, 6, 9, 6, 7,19,
  129296. 8, 8,10, 7, 7, 4, 5,19,12,17,19,15,18,13,11,18,
  129297. };
  129298. static static_codebook _huff_book__16u0__single = {
  129299. 2, 64,
  129300. _huff_lengthlist__16u0__single,
  129301. 0, 0, 0, 0, 0,
  129302. NULL,
  129303. NULL,
  129304. NULL,
  129305. NULL,
  129306. 0
  129307. };
  129308. static long _huff_lengthlist__16u1__long[] = {
  129309. 3, 6,10, 8,12, 8,14, 8,14,19, 5, 3, 5, 5, 7, 6,
  129310. 11, 7,16,19, 7, 5, 6, 7, 7, 9,11,12,19,19, 6, 4,
  129311. 7, 5, 7, 6,10, 7,18,18, 8, 6, 7, 7, 7, 7, 8, 9,
  129312. 18,18, 7, 5, 8, 5, 7, 5, 8, 6,18,18,12, 9,10, 9,
  129313. 9, 9, 8, 9,18,18, 8, 7,10, 6, 8, 5, 6, 4,11,18,
  129314. 11,15,16,12,11, 8, 8, 6, 9,18,14,18,18,18,16,16,
  129315. 16,13,16,18,
  129316. };
  129317. static static_codebook _huff_book__16u1__long = {
  129318. 2, 100,
  129319. _huff_lengthlist__16u1__long,
  129320. 0, 0, 0, 0, 0,
  129321. NULL,
  129322. NULL,
  129323. NULL,
  129324. NULL,
  129325. 0
  129326. };
  129327. static long _vq_quantlist__16u1__p1_0[] = {
  129328. 1,
  129329. 0,
  129330. 2,
  129331. };
  129332. static long _vq_lengthlist__16u1__p1_0[] = {
  129333. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 7, 7,10,10, 7,
  129334. 9,10, 5, 7, 8, 7,10, 9, 7,10,10, 5, 8, 8, 8,10,
  129335. 10, 8,10,10, 7,10,10,10,11,12,10,12,13, 7,10,10,
  129336. 9,13,11,10,12,13, 5, 8, 8, 8,10,10, 8,10,10, 7,
  129337. 10,10,10,12,12, 9,11,12, 7,10,11,10,12,12,10,13,
  129338. 11,
  129339. };
  129340. static float _vq_quantthresh__16u1__p1_0[] = {
  129341. -0.5, 0.5,
  129342. };
  129343. static long _vq_quantmap__16u1__p1_0[] = {
  129344. 1, 0, 2,
  129345. };
  129346. static encode_aux_threshmatch _vq_auxt__16u1__p1_0 = {
  129347. _vq_quantthresh__16u1__p1_0,
  129348. _vq_quantmap__16u1__p1_0,
  129349. 3,
  129350. 3
  129351. };
  129352. static static_codebook _16u1__p1_0 = {
  129353. 4, 81,
  129354. _vq_lengthlist__16u1__p1_0,
  129355. 1, -535822336, 1611661312, 2, 0,
  129356. _vq_quantlist__16u1__p1_0,
  129357. NULL,
  129358. &_vq_auxt__16u1__p1_0,
  129359. NULL,
  129360. 0
  129361. };
  129362. static long _vq_quantlist__16u1__p2_0[] = {
  129363. 1,
  129364. 0,
  129365. 2,
  129366. };
  129367. static long _vq_lengthlist__16u1__p2_0[] = {
  129368. 3, 4, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 6, 7, 8, 6,
  129369. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 7, 5, 6, 6, 6, 8,
  129370. 8, 6, 8, 8, 6, 8, 8, 7, 7,10, 8, 9, 9, 6, 8, 8,
  129371. 7, 9, 8, 8, 9,10, 5, 6, 6, 6, 8, 8, 7, 8, 8, 6,
  129372. 8, 8, 8,10, 9, 7, 8, 9, 6, 8, 8, 8, 9, 9, 7,10,
  129373. 8,
  129374. };
  129375. static float _vq_quantthresh__16u1__p2_0[] = {
  129376. -0.5, 0.5,
  129377. };
  129378. static long _vq_quantmap__16u1__p2_0[] = {
  129379. 1, 0, 2,
  129380. };
  129381. static encode_aux_threshmatch _vq_auxt__16u1__p2_0 = {
  129382. _vq_quantthresh__16u1__p2_0,
  129383. _vq_quantmap__16u1__p2_0,
  129384. 3,
  129385. 3
  129386. };
  129387. static static_codebook _16u1__p2_0 = {
  129388. 4, 81,
  129389. _vq_lengthlist__16u1__p2_0,
  129390. 1, -535822336, 1611661312, 2, 0,
  129391. _vq_quantlist__16u1__p2_0,
  129392. NULL,
  129393. &_vq_auxt__16u1__p2_0,
  129394. NULL,
  129395. 0
  129396. };
  129397. static long _vq_quantlist__16u1__p3_0[] = {
  129398. 2,
  129399. 1,
  129400. 3,
  129401. 0,
  129402. 4,
  129403. };
  129404. static long _vq_lengthlist__16u1__p3_0[] = {
  129405. 1, 5, 5, 8, 8, 6, 7, 7, 9, 9, 5, 7, 7, 9, 9, 9,
  129406. 10, 9,11,11, 9, 9,10,11,11, 6, 8, 8,10,10, 8, 9,
  129407. 10,11,11, 8, 9,10,11,11,10,11,11,12,13,10,11,11,
  129408. 13,13, 6, 8, 8,10,10, 8,10, 9,11,11, 8,10, 9,11,
  129409. 11,10,11,11,13,13,10,11,11,13,12, 9,11,11,14,13,
  129410. 10,12,12,15,14,10,12,11,14,13,12,13,13,15,15,12,
  129411. 13,13,16,14, 9,11,11,13,14,10,11,12,14,14,10,12,
  129412. 12,14,15,12,13,13,14,15,12,13,14,15,16, 5, 8, 8,
  129413. 11,11, 8,10,10,12,12, 8,10,10,12,12,11,12,12,14,
  129414. 14,11,12,12,14,14, 8,10,10,12,12, 9,11,12,12,13,
  129415. 10,12,12,13,13,12,12,13,14,15,11,13,13,15,15, 7,
  129416. 10,10,12,12, 9,12,11,13,12,10,11,12,13,13,12,13,
  129417. 12,15,14,11,12,13,15,15,10,12,12,15,14,11,13,13,
  129418. 16,15,11,13,13,16,15,14,13,14,15,16,13,15,15,17,
  129419. 17,10,12,12,14,15,11,12,12,15,15,11,13,13,15,16,
  129420. 13,15,13,16,15,13,15,15,16,17, 5, 8, 8,11,11, 8,
  129421. 10,10,12,12, 8,10,10,12,12,11,12,12,14,14,11,12,
  129422. 12,14,14, 7,10,10,12,12,10,12,12,14,13, 9,11,12,
  129423. 12,13,12,13,13,15,15,12,12,13,13,15, 7,10,10,12,
  129424. 13,10,11,12,13,13,10,12,11,13,13,11,13,13,15,15,
  129425. 12,13,12,15,14, 9,12,12,15,14,11,13,13,15,15,11,
  129426. 12,13,15,15,13,14,14,17,19,13,13,14,16,16,10,12,
  129427. 12,14,15,11,13,13,15,16,11,13,12,16,15,13,15,15,
  129428. 17,18,14,15,13,16,15, 8,11,11,15,14,10,12,12,16,
  129429. 15,10,12,12,16,16,14,15,15,18,17,13,14,15,16,18,
  129430. 9,12,12,15,15,11,12,14,16,17,11,13,13,16,15,15,
  129431. 15,15,17,18,14,15,16,17,17, 9,12,12,15,15,11,14,
  129432. 13,16,16,11,13,13,16,16,15,16,15,17,18,14,16,15,
  129433. 17,16,12,14,14,17,16,12,14,15,18,17,13,15,15,17,
  129434. 17,15,15,18,16,20,15,16,17,18,18,11,14,14,16,17,
  129435. 13,15,14,18,17,13,15,15,17,17,15,17,15,18,17,15,
  129436. 17,16,19,18, 8,11,11,14,15,10,12,12,15,15,10,12,
  129437. 12,16,16,13,14,14,17,16,14,15,15,17,17, 9,12,12,
  129438. 15,16,11,13,13,16,16,11,12,13,16,16,14,16,15,20,
  129439. 17,14,16,16,17,17, 9,12,12,15,16,11,13,13,16,17,
  129440. 11,13,13,17,16,14,15,15,17,18,15,15,15,18,18,11,
  129441. 14,14,17,16,13,15,15,17,17,13,14,14,18,17,15,16,
  129442. 16,18,19,15,15,17,17,19,11,14,14,16,17,13,15,14,
  129443. 17,19,13,15,14,18,17,15,17,16,18,18,15,17,15,18,
  129444. 16,
  129445. };
  129446. static float _vq_quantthresh__16u1__p3_0[] = {
  129447. -1.5, -0.5, 0.5, 1.5,
  129448. };
  129449. static long _vq_quantmap__16u1__p3_0[] = {
  129450. 3, 1, 0, 2, 4,
  129451. };
  129452. static encode_aux_threshmatch _vq_auxt__16u1__p3_0 = {
  129453. _vq_quantthresh__16u1__p3_0,
  129454. _vq_quantmap__16u1__p3_0,
  129455. 5,
  129456. 5
  129457. };
  129458. static static_codebook _16u1__p3_0 = {
  129459. 4, 625,
  129460. _vq_lengthlist__16u1__p3_0,
  129461. 1, -533725184, 1611661312, 3, 0,
  129462. _vq_quantlist__16u1__p3_0,
  129463. NULL,
  129464. &_vq_auxt__16u1__p3_0,
  129465. NULL,
  129466. 0
  129467. };
  129468. static long _vq_quantlist__16u1__p4_0[] = {
  129469. 2,
  129470. 1,
  129471. 3,
  129472. 0,
  129473. 4,
  129474. };
  129475. static long _vq_lengthlist__16u1__p4_0[] = {
  129476. 4, 5, 5, 8, 8, 6, 6, 7, 9, 9, 6, 6, 6, 9, 9, 9,
  129477. 10, 9,11,11, 9, 9,10,11,11, 6, 7, 7,10, 9, 7, 7,
  129478. 8, 9,10, 7, 7, 8,10,10,10,10,10,10,12, 9, 9,10,
  129479. 11,12, 6, 7, 7, 9, 9, 7, 8, 7,10,10, 7, 8, 7,10,
  129480. 10, 9,10, 9,12,11,10,10, 9,12,10, 9,10,10,12,11,
  129481. 10,10,10,12,12, 9,10,10,12,12,12,11,12,13,13,11,
  129482. 11,12,12,13, 9,10,10,11,12, 9,10,10,12,12,10,10,
  129483. 10,12,12,11,12,11,14,13,11,12,12,14,13, 5, 7, 7,
  129484. 10,10, 7, 8, 8,10,10, 7, 8, 7,10,10,10,10,10,12,
  129485. 12,10,10,10,12,12, 6, 8, 7,10,10, 7, 7, 9,10,11,
  129486. 8, 9, 9,11,10,10,10,11,11,13,10,10,11,12,13, 6,
  129487. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,10,11,10,11,
  129488. 10,13,11,10,11,10,12,12,10,11,10,12,11,10,10,10,
  129489. 12,13,10,11,11,13,12,11,11,13,11,14,12,12,13,14,
  129490. 14, 9,10,10,12,13,10,11,10,13,12,10,11,11,12,13,
  129491. 11,12,11,14,12,12,13,13,15,14, 5, 7, 7,10,10, 7,
  129492. 7, 8,10,10, 7, 8, 8,10,10,10,10,10,11,12,10,10,
  129493. 10,12,12, 7, 8, 8,10,10, 8, 9, 8,11,10, 7, 8, 9,
  129494. 10,11,10,11,11,12,12,10,10,11,11,13, 7, 7, 8,10,
  129495. 10, 8, 8, 9,10,11, 7, 9, 7,11,10,10,11,11,13,12,
  129496. 11,11,10,13,11, 9,10,10,12,12,10,11,11,13,12,10,
  129497. 10,11,12,12,12,13,13,14,14,11,11,12,12,14,10,10,
  129498. 11,12,12,10,11,11,12,13,10,10,10,13,12,12,13,13,
  129499. 15,14,12,13,10,14,11, 8,10,10,12,12,10,11,10,13,
  129500. 13, 9,10,10,12,12,12,13,13,15,14,11,12,12,13,13,
  129501. 9,10,10,13,12,10,10,11,13,13,10,11,10,13,12,12,
  129502. 12,13,14,15,12,13,12,15,13, 9,10,10,12,13,10,11,
  129503. 10,13,12,10,10,11,12,13,12,14,12,15,13,12,12,13,
  129504. 14,15,11,12,11,14,13,11,11,12,14,15,12,13,12,15,
  129505. 14,13,11,15,11,16,13,14,14,16,15,11,12,12,14,14,
  129506. 11,12,11,14,13,12,12,13,14,15,13,14,12,16,12,14,
  129507. 14,14,15,15, 8,10,10,12,12, 9,10,10,12,12,10,10,
  129508. 11,13,13,11,12,12,13,13,12,13,13,14,15, 9,10,10,
  129509. 13,12,10,11,11,13,12,10,10,11,13,13,12,13,12,15,
  129510. 14,12,12,13,13,16, 9, 9,10,12,13,10,10,11,12,13,
  129511. 10,11,10,13,13,12,12,13,13,15,13,13,12,15,13,11,
  129512. 12,12,14,14,12,13,12,15,14,11,11,12,13,14,14,14,
  129513. 14,16,15,13,12,15,12,16,11,11,12,13,14,12,13,13,
  129514. 14,15,10,12,11,14,13,14,15,14,16,16,13,14,11,15,
  129515. 11,
  129516. };
  129517. static float _vq_quantthresh__16u1__p4_0[] = {
  129518. -1.5, -0.5, 0.5, 1.5,
  129519. };
  129520. static long _vq_quantmap__16u1__p4_0[] = {
  129521. 3, 1, 0, 2, 4,
  129522. };
  129523. static encode_aux_threshmatch _vq_auxt__16u1__p4_0 = {
  129524. _vq_quantthresh__16u1__p4_0,
  129525. _vq_quantmap__16u1__p4_0,
  129526. 5,
  129527. 5
  129528. };
  129529. static static_codebook _16u1__p4_0 = {
  129530. 4, 625,
  129531. _vq_lengthlist__16u1__p4_0,
  129532. 1, -533725184, 1611661312, 3, 0,
  129533. _vq_quantlist__16u1__p4_0,
  129534. NULL,
  129535. &_vq_auxt__16u1__p4_0,
  129536. NULL,
  129537. 0
  129538. };
  129539. static long _vq_quantlist__16u1__p5_0[] = {
  129540. 4,
  129541. 3,
  129542. 5,
  129543. 2,
  129544. 6,
  129545. 1,
  129546. 7,
  129547. 0,
  129548. 8,
  129549. };
  129550. static long _vq_lengthlist__16u1__p5_0[] = {
  129551. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 8, 8, 8,
  129552. 10,10, 4, 5, 6, 8, 8, 8, 8,10,10, 7, 8, 8, 9, 9,
  129553. 9, 9,11,11, 7, 8, 8, 9, 9, 9, 9,11,11, 7, 8, 8,
  129554. 10, 9,11,11,12,11, 7, 8, 8, 9, 9,11,11,12,12, 9,
  129555. 10,10,11,11,12,12,13,12, 9,10,10,11,11,12,12,12,
  129556. 13,
  129557. };
  129558. static float _vq_quantthresh__16u1__p5_0[] = {
  129559. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  129560. };
  129561. static long _vq_quantmap__16u1__p5_0[] = {
  129562. 7, 5, 3, 1, 0, 2, 4, 6,
  129563. 8,
  129564. };
  129565. static encode_aux_threshmatch _vq_auxt__16u1__p5_0 = {
  129566. _vq_quantthresh__16u1__p5_0,
  129567. _vq_quantmap__16u1__p5_0,
  129568. 9,
  129569. 9
  129570. };
  129571. static static_codebook _16u1__p5_0 = {
  129572. 2, 81,
  129573. _vq_lengthlist__16u1__p5_0,
  129574. 1, -531628032, 1611661312, 4, 0,
  129575. _vq_quantlist__16u1__p5_0,
  129576. NULL,
  129577. &_vq_auxt__16u1__p5_0,
  129578. NULL,
  129579. 0
  129580. };
  129581. static long _vq_quantlist__16u1__p6_0[] = {
  129582. 4,
  129583. 3,
  129584. 5,
  129585. 2,
  129586. 6,
  129587. 1,
  129588. 7,
  129589. 0,
  129590. 8,
  129591. };
  129592. static long _vq_lengthlist__16u1__p6_0[] = {
  129593. 3, 4, 4, 6, 6, 7, 7, 9, 9, 4, 4, 4, 6, 6, 8, 8,
  129594. 9, 9, 4, 4, 4, 6, 6, 7, 7, 9, 9, 6, 6, 6, 7, 7,
  129595. 8, 8,10, 9, 6, 6, 6, 7, 7, 8, 8, 9,10, 7, 8, 7,
  129596. 8, 8, 9, 9,10,10, 7, 8, 8, 8, 8, 9, 9,10,10, 9,
  129597. 9, 9,10,10,10,10,11,11, 9, 9, 9,10,10,10,10,11,
  129598. 11,
  129599. };
  129600. static float _vq_quantthresh__16u1__p6_0[] = {
  129601. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  129602. };
  129603. static long _vq_quantmap__16u1__p6_0[] = {
  129604. 7, 5, 3, 1, 0, 2, 4, 6,
  129605. 8,
  129606. };
  129607. static encode_aux_threshmatch _vq_auxt__16u1__p6_0 = {
  129608. _vq_quantthresh__16u1__p6_0,
  129609. _vq_quantmap__16u1__p6_0,
  129610. 9,
  129611. 9
  129612. };
  129613. static static_codebook _16u1__p6_0 = {
  129614. 2, 81,
  129615. _vq_lengthlist__16u1__p6_0,
  129616. 1, -531628032, 1611661312, 4, 0,
  129617. _vq_quantlist__16u1__p6_0,
  129618. NULL,
  129619. &_vq_auxt__16u1__p6_0,
  129620. NULL,
  129621. 0
  129622. };
  129623. static long _vq_quantlist__16u1__p7_0[] = {
  129624. 1,
  129625. 0,
  129626. 2,
  129627. };
  129628. static long _vq_lengthlist__16u1__p7_0[] = {
  129629. 1, 4, 4, 4, 8, 8, 4, 8, 8, 5,11, 9, 8,12,11, 8,
  129630. 12,11, 5,10,11, 8,11,12, 8,11,12, 4,11,11,11,14,
  129631. 13,10,13,13, 8,14,13,12,14,16,12,16,15, 8,14,14,
  129632. 13,16,14,12,15,16, 4,11,11,10,14,13,11,14,14, 8,
  129633. 15,14,12,15,15,12,14,16, 8,14,14,11,16,15,12,15,
  129634. 13,
  129635. };
  129636. static float _vq_quantthresh__16u1__p7_0[] = {
  129637. -5.5, 5.5,
  129638. };
  129639. static long _vq_quantmap__16u1__p7_0[] = {
  129640. 1, 0, 2,
  129641. };
  129642. static encode_aux_threshmatch _vq_auxt__16u1__p7_0 = {
  129643. _vq_quantthresh__16u1__p7_0,
  129644. _vq_quantmap__16u1__p7_0,
  129645. 3,
  129646. 3
  129647. };
  129648. static static_codebook _16u1__p7_0 = {
  129649. 4, 81,
  129650. _vq_lengthlist__16u1__p7_0,
  129651. 1, -529137664, 1618345984, 2, 0,
  129652. _vq_quantlist__16u1__p7_0,
  129653. NULL,
  129654. &_vq_auxt__16u1__p7_0,
  129655. NULL,
  129656. 0
  129657. };
  129658. static long _vq_quantlist__16u1__p7_1[] = {
  129659. 5,
  129660. 4,
  129661. 6,
  129662. 3,
  129663. 7,
  129664. 2,
  129665. 8,
  129666. 1,
  129667. 9,
  129668. 0,
  129669. 10,
  129670. };
  129671. static long _vq_lengthlist__16u1__p7_1[] = {
  129672. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 6, 5, 7, 7,
  129673. 8, 8, 8, 8, 8, 8, 4, 5, 6, 7, 7, 8, 8, 8, 8, 8,
  129674. 8, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 6, 7, 7, 8,
  129675. 8, 8, 8, 9, 9, 9, 9, 7, 8, 8, 8, 8, 9, 9, 9,10,
  129676. 9,10, 7, 8, 8, 8, 8, 9, 9, 9, 9,10, 9, 8, 8, 8,
  129677. 9, 9,10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9,10,
  129678. 10,10,10, 8, 8, 8, 9, 9, 9,10,10,10,10,10, 8, 8,
  129679. 8, 9, 9,10,10,10,10,10,10,
  129680. };
  129681. static float _vq_quantthresh__16u1__p7_1[] = {
  129682. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  129683. 3.5, 4.5,
  129684. };
  129685. static long _vq_quantmap__16u1__p7_1[] = {
  129686. 9, 7, 5, 3, 1, 0, 2, 4,
  129687. 6, 8, 10,
  129688. };
  129689. static encode_aux_threshmatch _vq_auxt__16u1__p7_1 = {
  129690. _vq_quantthresh__16u1__p7_1,
  129691. _vq_quantmap__16u1__p7_1,
  129692. 11,
  129693. 11
  129694. };
  129695. static static_codebook _16u1__p7_1 = {
  129696. 2, 121,
  129697. _vq_lengthlist__16u1__p7_1,
  129698. 1, -531365888, 1611661312, 4, 0,
  129699. _vq_quantlist__16u1__p7_1,
  129700. NULL,
  129701. &_vq_auxt__16u1__p7_1,
  129702. NULL,
  129703. 0
  129704. };
  129705. static long _vq_quantlist__16u1__p8_0[] = {
  129706. 5,
  129707. 4,
  129708. 6,
  129709. 3,
  129710. 7,
  129711. 2,
  129712. 8,
  129713. 1,
  129714. 9,
  129715. 0,
  129716. 10,
  129717. };
  129718. static long _vq_lengthlist__16u1__p8_0[] = {
  129719. 1, 4, 4, 5, 5, 8, 8,10,10,12,12, 4, 7, 7, 8, 8,
  129720. 9, 9,12,11,14,13, 4, 7, 7, 7, 8, 9,10,11,11,13,
  129721. 12, 5, 8, 8, 9, 9,11,11,12,13,15,14, 5, 7, 8, 9,
  129722. 9,11,11,13,13,17,15, 8, 9,10,11,11,12,13,17,14,
  129723. 17,16, 8,10, 9,11,11,12,12,13,15,15,17,10,11,11,
  129724. 12,13,14,15,15,16,16,17, 9,11,11,12,12,14,15,17,
  129725. 15,15,16,11,14,12,14,15,16,15,16,16,16,15,11,13,
  129726. 13,14,14,15,15,16,16,15,16,
  129727. };
  129728. static float _vq_quantthresh__16u1__p8_0[] = {
  129729. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  129730. 38.5, 49.5,
  129731. };
  129732. static long _vq_quantmap__16u1__p8_0[] = {
  129733. 9, 7, 5, 3, 1, 0, 2, 4,
  129734. 6, 8, 10,
  129735. };
  129736. static encode_aux_threshmatch _vq_auxt__16u1__p8_0 = {
  129737. _vq_quantthresh__16u1__p8_0,
  129738. _vq_quantmap__16u1__p8_0,
  129739. 11,
  129740. 11
  129741. };
  129742. static static_codebook _16u1__p8_0 = {
  129743. 2, 121,
  129744. _vq_lengthlist__16u1__p8_0,
  129745. 1, -524582912, 1618345984, 4, 0,
  129746. _vq_quantlist__16u1__p8_0,
  129747. NULL,
  129748. &_vq_auxt__16u1__p8_0,
  129749. NULL,
  129750. 0
  129751. };
  129752. static long _vq_quantlist__16u1__p8_1[] = {
  129753. 5,
  129754. 4,
  129755. 6,
  129756. 3,
  129757. 7,
  129758. 2,
  129759. 8,
  129760. 1,
  129761. 9,
  129762. 0,
  129763. 10,
  129764. };
  129765. static long _vq_lengthlist__16u1__p8_1[] = {
  129766. 2, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 4, 6, 6, 7, 7,
  129767. 8, 7, 8, 8, 8, 8, 4, 6, 6, 7, 7, 7, 7, 8, 8, 8,
  129768. 8, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 9, 6, 7, 7, 7,
  129769. 7, 8, 8, 8, 8, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9,
  129770. 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 8, 8, 8,
  129771. 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9,
  129772. 9, 9, 9, 8, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9, 8, 8,
  129773. 8, 9, 9, 9, 9, 9, 9, 9, 9,
  129774. };
  129775. static float _vq_quantthresh__16u1__p8_1[] = {
  129776. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  129777. 3.5, 4.5,
  129778. };
  129779. static long _vq_quantmap__16u1__p8_1[] = {
  129780. 9, 7, 5, 3, 1, 0, 2, 4,
  129781. 6, 8, 10,
  129782. };
  129783. static encode_aux_threshmatch _vq_auxt__16u1__p8_1 = {
  129784. _vq_quantthresh__16u1__p8_1,
  129785. _vq_quantmap__16u1__p8_1,
  129786. 11,
  129787. 11
  129788. };
  129789. static static_codebook _16u1__p8_1 = {
  129790. 2, 121,
  129791. _vq_lengthlist__16u1__p8_1,
  129792. 1, -531365888, 1611661312, 4, 0,
  129793. _vq_quantlist__16u1__p8_1,
  129794. NULL,
  129795. &_vq_auxt__16u1__p8_1,
  129796. NULL,
  129797. 0
  129798. };
  129799. static long _vq_quantlist__16u1__p9_0[] = {
  129800. 7,
  129801. 6,
  129802. 8,
  129803. 5,
  129804. 9,
  129805. 4,
  129806. 10,
  129807. 3,
  129808. 11,
  129809. 2,
  129810. 12,
  129811. 1,
  129812. 13,
  129813. 0,
  129814. 14,
  129815. };
  129816. static long _vq_lengthlist__16u1__p9_0[] = {
  129817. 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129818. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129819. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129820. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129821. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129822. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129823. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129824. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129825. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129826. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129827. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129828. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129829. 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  129830. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  129831. 8,
  129832. };
  129833. static float _vq_quantthresh__16u1__p9_0[] = {
  129834. -1657.5, -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5,
  129835. 382.5, 637.5, 892.5, 1147.5, 1402.5, 1657.5,
  129836. };
  129837. static long _vq_quantmap__16u1__p9_0[] = {
  129838. 13, 11, 9, 7, 5, 3, 1, 0,
  129839. 2, 4, 6, 8, 10, 12, 14,
  129840. };
  129841. static encode_aux_threshmatch _vq_auxt__16u1__p9_0 = {
  129842. _vq_quantthresh__16u1__p9_0,
  129843. _vq_quantmap__16u1__p9_0,
  129844. 15,
  129845. 15
  129846. };
  129847. static static_codebook _16u1__p9_0 = {
  129848. 2, 225,
  129849. _vq_lengthlist__16u1__p9_0,
  129850. 1, -514071552, 1627381760, 4, 0,
  129851. _vq_quantlist__16u1__p9_0,
  129852. NULL,
  129853. &_vq_auxt__16u1__p9_0,
  129854. NULL,
  129855. 0
  129856. };
  129857. static long _vq_quantlist__16u1__p9_1[] = {
  129858. 7,
  129859. 6,
  129860. 8,
  129861. 5,
  129862. 9,
  129863. 4,
  129864. 10,
  129865. 3,
  129866. 11,
  129867. 2,
  129868. 12,
  129869. 1,
  129870. 13,
  129871. 0,
  129872. 14,
  129873. };
  129874. static long _vq_lengthlist__16u1__p9_1[] = {
  129875. 1, 6, 5, 9, 9,10,10, 6, 7, 9, 9,10,10,10,10, 5,
  129876. 10, 8,10, 8,10,10, 8, 8,10, 9,10,10,10,10, 5, 8,
  129877. 9,10,10,10,10, 8,10,10,10,10,10,10,10, 9,10,10,
  129878. 10,10,10,10, 9, 9,10,10,10,10,10,10, 9, 9, 8, 9,
  129879. 10,10,10, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  129880. 10,10,10,10,10,10,10,10,10,10,10, 8,10,10,10,10,
  129881. 10,10,10,10,10,10,10,10,10, 6, 8, 8,10,10,10, 8,
  129882. 10,10,10,10,10,10,10,10, 5, 8, 8,10,10,10, 9, 9,
  129883. 10,10,10,10,10,10,10,10, 9,10,10,10,10,10,10,10,
  129884. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129885. 10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  129886. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129887. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129888. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129889. 9,
  129890. };
  129891. static float _vq_quantthresh__16u1__p9_1[] = {
  129892. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  129893. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  129894. };
  129895. static long _vq_quantmap__16u1__p9_1[] = {
  129896. 13, 11, 9, 7, 5, 3, 1, 0,
  129897. 2, 4, 6, 8, 10, 12, 14,
  129898. };
  129899. static encode_aux_threshmatch _vq_auxt__16u1__p9_1 = {
  129900. _vq_quantthresh__16u1__p9_1,
  129901. _vq_quantmap__16u1__p9_1,
  129902. 15,
  129903. 15
  129904. };
  129905. static static_codebook _16u1__p9_1 = {
  129906. 2, 225,
  129907. _vq_lengthlist__16u1__p9_1,
  129908. 1, -522338304, 1620115456, 4, 0,
  129909. _vq_quantlist__16u1__p9_1,
  129910. NULL,
  129911. &_vq_auxt__16u1__p9_1,
  129912. NULL,
  129913. 0
  129914. };
  129915. static long _vq_quantlist__16u1__p9_2[] = {
  129916. 8,
  129917. 7,
  129918. 9,
  129919. 6,
  129920. 10,
  129921. 5,
  129922. 11,
  129923. 4,
  129924. 12,
  129925. 3,
  129926. 13,
  129927. 2,
  129928. 14,
  129929. 1,
  129930. 15,
  129931. 0,
  129932. 16,
  129933. };
  129934. static long _vq_lengthlist__16u1__p9_2[] = {
  129935. 1, 6, 6, 7, 8, 8,11,10, 9, 9,11, 9,10, 9,11,11,
  129936. 9, 6, 7, 6,11, 8,11, 9,10,10,11, 9,11,10,10,10,
  129937. 11, 9, 5, 7, 7, 8, 8,10,11, 8, 8,11, 9, 9,10,11,
  129938. 9,10,11, 8, 9, 6, 8, 8, 9, 9,10,10,11,11,11, 9,
  129939. 11,10, 9,11, 8, 8, 8, 9, 8, 9,10,11, 9, 9,11,11,
  129940. 10, 9, 9,11,10, 8,11, 8, 9, 8,11, 9,10, 9,10,11,
  129941. 11,10,10, 9,10,10, 8, 8, 9,10,10,10, 9,11, 9,10,
  129942. 11,11,11,11,10, 9,11, 9, 9,11,11,10, 8,11,11,11,
  129943. 9,10,10,11,10,11,11, 9,11,10, 9,11,10,10,10,10,
  129944. 9,11,10,11,10, 9, 9,10,11, 9, 8,10,11,11,10,10,
  129945. 11, 9,11,10,11,11,10,11, 9, 9, 8,10, 8, 9,11, 9,
  129946. 8,10,10, 9,11,10,11,10,11, 9,11, 8,10,11,11,11,
  129947. 11,10,10,11,11,11,11,10,11,11,10, 9, 8,10,10, 9,
  129948. 11,10,11,11,11, 9, 9, 9,11,11,11,10,10, 9, 9,10,
  129949. 9,11,11,11,11, 8,10,11,10,11,11,10,11,11, 9, 9,
  129950. 9,10, 9,11, 9,11,11,11,11,11,10,11,11,10,11,10,
  129951. 11,11, 9,11,10,11,10, 9,10, 9,10,10,11,11,11,11,
  129952. 9,10, 9,10,11,11,10,11,11,11,11,11,11,10,11,11,
  129953. 10,
  129954. };
  129955. static float _vq_quantthresh__16u1__p9_2[] = {
  129956. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  129957. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  129958. };
  129959. static long _vq_quantmap__16u1__p9_2[] = {
  129960. 15, 13, 11, 9, 7, 5, 3, 1,
  129961. 0, 2, 4, 6, 8, 10, 12, 14,
  129962. 16,
  129963. };
  129964. static encode_aux_threshmatch _vq_auxt__16u1__p9_2 = {
  129965. _vq_quantthresh__16u1__p9_2,
  129966. _vq_quantmap__16u1__p9_2,
  129967. 17,
  129968. 17
  129969. };
  129970. static static_codebook _16u1__p9_2 = {
  129971. 2, 289,
  129972. _vq_lengthlist__16u1__p9_2,
  129973. 1, -529530880, 1611661312, 5, 0,
  129974. _vq_quantlist__16u1__p9_2,
  129975. NULL,
  129976. &_vq_auxt__16u1__p9_2,
  129977. NULL,
  129978. 0
  129979. };
  129980. static long _huff_lengthlist__16u1__short[] = {
  129981. 5, 7,10, 9,11,10,15,11,13,16, 6, 4, 6, 6, 7, 7,
  129982. 10, 9,12,16,10, 6, 5, 6, 6, 7,10,11,16,16, 9, 6,
  129983. 7, 6, 7, 7,10, 8,14,16,11, 6, 5, 4, 5, 6, 8, 9,
  129984. 15,16, 9, 6, 6, 5, 6, 6, 9, 8,14,16,12, 7, 6, 6,
  129985. 5, 6, 6, 7,13,16, 8, 6, 7, 6, 5, 5, 4, 4,11,16,
  129986. 9, 8, 9, 9, 7, 7, 6, 5,13,16,14,14,16,15,16,15,
  129987. 16,16,16,16,
  129988. };
  129989. static static_codebook _huff_book__16u1__short = {
  129990. 2, 100,
  129991. _huff_lengthlist__16u1__short,
  129992. 0, 0, 0, 0, 0,
  129993. NULL,
  129994. NULL,
  129995. NULL,
  129996. NULL,
  129997. 0
  129998. };
  129999. static long _huff_lengthlist__16u2__long[] = {
  130000. 5, 7,10,10,10,11,11,13,18,19, 6, 5, 5, 6, 7, 8,
  130001. 9,12,19,19, 8, 5, 4, 4, 6, 7, 9,13,19,19, 8, 5,
  130002. 4, 4, 5, 6, 8,12,17,19, 7, 5, 5, 4, 4, 5, 7,12,
  130003. 18,18, 8, 7, 7, 6, 5, 5, 6,10,18,18, 9, 9, 9, 8,
  130004. 6, 5, 6, 9,18,18,11,13,13,13, 8, 7, 7, 9,16,18,
  130005. 13,17,18,16,11, 9, 9, 9,17,18,15,18,18,18,15,13,
  130006. 13,14,18,18,
  130007. };
  130008. static static_codebook _huff_book__16u2__long = {
  130009. 2, 100,
  130010. _huff_lengthlist__16u2__long,
  130011. 0, 0, 0, 0, 0,
  130012. NULL,
  130013. NULL,
  130014. NULL,
  130015. NULL,
  130016. 0
  130017. };
  130018. static long _huff_lengthlist__16u2__short[] = {
  130019. 8,11,12,12,14,15,16,16,16,16, 9, 7, 7, 8, 9,11,
  130020. 13,14,16,16,13, 7, 6, 6, 7, 9,12,13,15,16,15, 7,
  130021. 6, 5, 4, 6,10,11,14,16,12, 8, 7, 4, 2, 4, 7,10,
  130022. 14,16,11, 9, 7, 5, 3, 4, 6, 9,14,16,11,10, 9, 7,
  130023. 5, 5, 6, 9,16,16,10,10, 9, 8, 6, 6, 7,10,16,16,
  130024. 11,11,11,10,10,10,11,14,16,16,16,14,14,13,14,16,
  130025. 16,16,16,16,
  130026. };
  130027. static static_codebook _huff_book__16u2__short = {
  130028. 2, 100,
  130029. _huff_lengthlist__16u2__short,
  130030. 0, 0, 0, 0, 0,
  130031. NULL,
  130032. NULL,
  130033. NULL,
  130034. NULL,
  130035. 0
  130036. };
  130037. static long _vq_quantlist__16u2_p1_0[] = {
  130038. 1,
  130039. 0,
  130040. 2,
  130041. };
  130042. static long _vq_lengthlist__16u2_p1_0[] = {
  130043. 1, 5, 5, 5, 7, 7, 5, 7, 7, 5, 7, 7, 7, 9, 9, 7,
  130044. 9, 9, 5, 7, 7, 7, 9, 9, 7, 9, 9, 5, 7, 7, 8, 9,
  130045. 9, 7, 9, 9, 7, 9, 9, 9,10,10, 9,10,10, 7, 9, 9,
  130046. 9,10,10, 9,10,11, 5, 7, 8, 8, 9, 9, 8, 9, 9, 7,
  130047. 9, 9, 9,10,10, 9, 9,10, 7, 9, 9, 9,10,10, 9,11,
  130048. 10,
  130049. };
  130050. static float _vq_quantthresh__16u2_p1_0[] = {
  130051. -0.5, 0.5,
  130052. };
  130053. static long _vq_quantmap__16u2_p1_0[] = {
  130054. 1, 0, 2,
  130055. };
  130056. static encode_aux_threshmatch _vq_auxt__16u2_p1_0 = {
  130057. _vq_quantthresh__16u2_p1_0,
  130058. _vq_quantmap__16u2_p1_0,
  130059. 3,
  130060. 3
  130061. };
  130062. static static_codebook _16u2_p1_0 = {
  130063. 4, 81,
  130064. _vq_lengthlist__16u2_p1_0,
  130065. 1, -535822336, 1611661312, 2, 0,
  130066. _vq_quantlist__16u2_p1_0,
  130067. NULL,
  130068. &_vq_auxt__16u2_p1_0,
  130069. NULL,
  130070. 0
  130071. };
  130072. static long _vq_quantlist__16u2_p2_0[] = {
  130073. 2,
  130074. 1,
  130075. 3,
  130076. 0,
  130077. 4,
  130078. };
  130079. static long _vq_lengthlist__16u2_p2_0[] = {
  130080. 3, 5, 5, 8, 8, 5, 7, 7, 9, 9, 5, 7, 7, 9, 9, 9,
  130081. 10, 9,11,11, 9, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  130082. 8,10,10, 7, 8, 8,10,10,10,10,10,12,12, 9,10,10,
  130083. 11,12, 5, 7, 7, 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,
  130084. 10, 9,10,10,12,11,10,10,10,12,12, 9,10,10,12,12,
  130085. 10,11,10,13,12, 9,10,10,12,12,12,12,12,14,14,11,
  130086. 12,12,13,14, 9,10,10,12,12, 9,10,10,12,12,10,10,
  130087. 10,12,12,11,12,12,14,13,12,13,12,14,14, 5, 7, 7,
  130088. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,10,12,
  130089. 12,10,10,11,12,12, 7, 8, 8,10,10, 8, 9, 9,11,11,
  130090. 8, 9, 9,11,11,11,11,11,12,13,10,11,11,12,13, 7,
  130091. 8, 8,10,10, 8, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  130092. 10,13,12,10,11,11,13,13, 9,11,10,13,13,10,11,11,
  130093. 13,13,10,11,11,13,13,12,12,13,13,15,12,12,13,14,
  130094. 15, 9,10,10,12,12,10,11,10,13,12,10,11,11,13,13,
  130095. 11,13,11,14,13,12,13,13,15,15, 5, 7, 7, 9, 9, 7,
  130096. 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,12,10,10,
  130097. 11,12,12, 7, 8, 8,10,10, 8, 9, 9,11,11, 8, 8, 9,
  130098. 10,11,10,11,11,13,13,10,10,11,12,13, 7, 8, 8,10,
  130099. 11, 8, 9, 9,11,11, 8, 9, 9,11,11,10,11,11,13,12,
  130100. 11,11,11,13,12, 9,10,10,12,12,10,11,11,13,13,10,
  130101. 10,11,12,13,12,13,13,15,14,11,11,13,12,14,10,10,
  130102. 11,13,13,10,11,11,13,13,10,11,11,13,13,12,13,13,
  130103. 14,14,12,13,12,14,13, 8,10, 9,12,12, 9,11,10,13,
  130104. 13, 9,10,10,12,13,12,13,13,14,14,12,12,13,14,14,
  130105. 9,11,10,13,13,10,11,11,13,13,10,11,11,13,13,12,
  130106. 13,13,15,15,13,13,13,14,15, 9,10,10,12,13,10,11,
  130107. 10,13,12,10,11,11,13,13,12,13,12,15,14,13,13,13,
  130108. 14,15,11,12,12,15,14,12,12,13,15,15,12,13,13,15,
  130109. 14,14,13,15,14,16,13,14,15,16,16,11,12,12,14,14,
  130110. 11,12,12,15,14,12,13,13,15,15,13,14,13,16,14,14,
  130111. 14,14,16,16, 8, 9, 9,12,12, 9,10,10,13,12, 9,10,
  130112. 10,13,13,12,12,12,14,14,12,12,13,15,15, 9,10,10,
  130113. 13,12,10,11,11,13,13,10,10,11,13,14,12,13,13,15,
  130114. 15,12,12,13,14,15, 9,10,10,13,13,10,11,11,13,13,
  130115. 10,11,11,13,13,12,13,13,14,14,13,14,13,15,14,11,
  130116. 12,12,14,14,12,13,13,15,14,11,12,12,14,15,14,14,
  130117. 14,16,15,13,12,14,14,16,11,12,13,14,15,12,13,13,
  130118. 14,16,12,13,12,15,14,13,15,14,16,16,14,15,13,16,
  130119. 13,
  130120. };
  130121. static float _vq_quantthresh__16u2_p2_0[] = {
  130122. -1.5, -0.5, 0.5, 1.5,
  130123. };
  130124. static long _vq_quantmap__16u2_p2_0[] = {
  130125. 3, 1, 0, 2, 4,
  130126. };
  130127. static encode_aux_threshmatch _vq_auxt__16u2_p2_0 = {
  130128. _vq_quantthresh__16u2_p2_0,
  130129. _vq_quantmap__16u2_p2_0,
  130130. 5,
  130131. 5
  130132. };
  130133. static static_codebook _16u2_p2_0 = {
  130134. 4, 625,
  130135. _vq_lengthlist__16u2_p2_0,
  130136. 1, -533725184, 1611661312, 3, 0,
  130137. _vq_quantlist__16u2_p2_0,
  130138. NULL,
  130139. &_vq_auxt__16u2_p2_0,
  130140. NULL,
  130141. 0
  130142. };
  130143. static long _vq_quantlist__16u2_p3_0[] = {
  130144. 4,
  130145. 3,
  130146. 5,
  130147. 2,
  130148. 6,
  130149. 1,
  130150. 7,
  130151. 0,
  130152. 8,
  130153. };
  130154. static long _vq_lengthlist__16u2_p3_0[] = {
  130155. 2, 4, 4, 6, 6, 7, 7, 9, 9, 4, 5, 5, 6, 6, 8, 7,
  130156. 9, 9, 4, 5, 5, 6, 6, 7, 8, 9, 9, 6, 6, 6, 7, 7,
  130157. 8, 8,10,10, 6, 6, 6, 7, 7, 8, 8, 9,10, 7, 8, 7,
  130158. 8, 8, 9, 9,10,10, 7, 8, 8, 8, 8, 9, 9,10,10, 9,
  130159. 9, 9,10, 9,10,10,11,11, 9, 9, 9,10,10,10,10,11,
  130160. 11,
  130161. };
  130162. static float _vq_quantthresh__16u2_p3_0[] = {
  130163. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  130164. };
  130165. static long _vq_quantmap__16u2_p3_0[] = {
  130166. 7, 5, 3, 1, 0, 2, 4, 6,
  130167. 8,
  130168. };
  130169. static encode_aux_threshmatch _vq_auxt__16u2_p3_0 = {
  130170. _vq_quantthresh__16u2_p3_0,
  130171. _vq_quantmap__16u2_p3_0,
  130172. 9,
  130173. 9
  130174. };
  130175. static static_codebook _16u2_p3_0 = {
  130176. 2, 81,
  130177. _vq_lengthlist__16u2_p3_0,
  130178. 1, -531628032, 1611661312, 4, 0,
  130179. _vq_quantlist__16u2_p3_0,
  130180. NULL,
  130181. &_vq_auxt__16u2_p3_0,
  130182. NULL,
  130183. 0
  130184. };
  130185. static long _vq_quantlist__16u2_p4_0[] = {
  130186. 8,
  130187. 7,
  130188. 9,
  130189. 6,
  130190. 10,
  130191. 5,
  130192. 11,
  130193. 4,
  130194. 12,
  130195. 3,
  130196. 13,
  130197. 2,
  130198. 14,
  130199. 1,
  130200. 15,
  130201. 0,
  130202. 16,
  130203. };
  130204. static long _vq_lengthlist__16u2_p4_0[] = {
  130205. 2, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,11,
  130206. 11, 5, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  130207. 12,11, 5, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  130208. 11,12,12, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  130209. 11,11,12,12, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,
  130210. 10,11,11,12,12, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,10,
  130211. 11,11,12,12,12,12, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,
  130212. 10,11,11,11,12,12,12, 9, 9, 9, 9, 9, 9,10,10,10,
  130213. 10,10,11,11,12,12,13,13, 8, 9, 9, 9, 9,10, 9,10,
  130214. 10,10,10,11,11,12,12,13,13, 9, 9, 9, 9, 9,10,10,
  130215. 10,10,11,11,11,12,12,12,13,13, 9, 9, 9, 9, 9,10,
  130216. 10,10,10,11,11,12,11,12,12,13,13,10,10,10,10,10,
  130217. 11,11,11,11,11,12,12,12,12,13,13,14,10,10,10,10,
  130218. 10,11,11,11,11,12,11,12,12,13,12,13,13,11,11,11,
  130219. 11,11,12,12,12,12,12,12,13,13,13,13,14,14,11,11,
  130220. 11,11,11,12,12,12,12,12,12,13,12,13,13,14,14,11,
  130221. 12,12,12,12,12,12,13,13,13,13,13,13,14,14,14,14,
  130222. 11,12,12,12,12,12,12,13,13,13,13,14,13,14,14,14,
  130223. 14,
  130224. };
  130225. static float _vq_quantthresh__16u2_p4_0[] = {
  130226. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  130227. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  130228. };
  130229. static long _vq_quantmap__16u2_p4_0[] = {
  130230. 15, 13, 11, 9, 7, 5, 3, 1,
  130231. 0, 2, 4, 6, 8, 10, 12, 14,
  130232. 16,
  130233. };
  130234. static encode_aux_threshmatch _vq_auxt__16u2_p4_0 = {
  130235. _vq_quantthresh__16u2_p4_0,
  130236. _vq_quantmap__16u2_p4_0,
  130237. 17,
  130238. 17
  130239. };
  130240. static static_codebook _16u2_p4_0 = {
  130241. 2, 289,
  130242. _vq_lengthlist__16u2_p4_0,
  130243. 1, -529530880, 1611661312, 5, 0,
  130244. _vq_quantlist__16u2_p4_0,
  130245. NULL,
  130246. &_vq_auxt__16u2_p4_0,
  130247. NULL,
  130248. 0
  130249. };
  130250. static long _vq_quantlist__16u2_p5_0[] = {
  130251. 1,
  130252. 0,
  130253. 2,
  130254. };
  130255. static long _vq_lengthlist__16u2_p5_0[] = {
  130256. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 8, 7,10, 9, 7,
  130257. 10, 9, 5, 8, 9, 7, 9,10, 7, 9,10, 4, 9, 9, 9,11,
  130258. 11, 8,11,11, 7,11,11,10,10,13,10,14,13, 7,11,11,
  130259. 10,13,11,10,13,14, 5, 9, 9, 8,11,11, 9,11,11, 7,
  130260. 11,11,10,14,13,10,12,14, 7,11,11,10,13,13,10,13,
  130261. 10,
  130262. };
  130263. static float _vq_quantthresh__16u2_p5_0[] = {
  130264. -5.5, 5.5,
  130265. };
  130266. static long _vq_quantmap__16u2_p5_0[] = {
  130267. 1, 0, 2,
  130268. };
  130269. static encode_aux_threshmatch _vq_auxt__16u2_p5_0 = {
  130270. _vq_quantthresh__16u2_p5_0,
  130271. _vq_quantmap__16u2_p5_0,
  130272. 3,
  130273. 3
  130274. };
  130275. static static_codebook _16u2_p5_0 = {
  130276. 4, 81,
  130277. _vq_lengthlist__16u2_p5_0,
  130278. 1, -529137664, 1618345984, 2, 0,
  130279. _vq_quantlist__16u2_p5_0,
  130280. NULL,
  130281. &_vq_auxt__16u2_p5_0,
  130282. NULL,
  130283. 0
  130284. };
  130285. static long _vq_quantlist__16u2_p5_1[] = {
  130286. 5,
  130287. 4,
  130288. 6,
  130289. 3,
  130290. 7,
  130291. 2,
  130292. 8,
  130293. 1,
  130294. 9,
  130295. 0,
  130296. 10,
  130297. };
  130298. static long _vq_lengthlist__16u2_p5_1[] = {
  130299. 2, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 5, 5, 5, 7, 7,
  130300. 7, 7, 8, 8, 8, 8, 5, 5, 6, 7, 7, 7, 7, 8, 8, 8,
  130301. 8, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 6, 7, 7, 7,
  130302. 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 9, 9,
  130303. 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 8, 8, 8,
  130304. 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9,
  130305. 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 8,
  130306. 8, 8, 8, 9, 9, 9, 9, 9, 9,
  130307. };
  130308. static float _vq_quantthresh__16u2_p5_1[] = {
  130309. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  130310. 3.5, 4.5,
  130311. };
  130312. static long _vq_quantmap__16u2_p5_1[] = {
  130313. 9, 7, 5, 3, 1, 0, 2, 4,
  130314. 6, 8, 10,
  130315. };
  130316. static encode_aux_threshmatch _vq_auxt__16u2_p5_1 = {
  130317. _vq_quantthresh__16u2_p5_1,
  130318. _vq_quantmap__16u2_p5_1,
  130319. 11,
  130320. 11
  130321. };
  130322. static static_codebook _16u2_p5_1 = {
  130323. 2, 121,
  130324. _vq_lengthlist__16u2_p5_1,
  130325. 1, -531365888, 1611661312, 4, 0,
  130326. _vq_quantlist__16u2_p5_1,
  130327. NULL,
  130328. &_vq_auxt__16u2_p5_1,
  130329. NULL,
  130330. 0
  130331. };
  130332. static long _vq_quantlist__16u2_p6_0[] = {
  130333. 6,
  130334. 5,
  130335. 7,
  130336. 4,
  130337. 8,
  130338. 3,
  130339. 9,
  130340. 2,
  130341. 10,
  130342. 1,
  130343. 11,
  130344. 0,
  130345. 12,
  130346. };
  130347. static long _vq_lengthlist__16u2_p6_0[] = {
  130348. 1, 4, 4, 7, 7, 8, 8, 8, 8, 9, 9,10,10, 4, 6, 6,
  130349. 8, 8, 9, 9, 9, 9,10,10,12,11, 4, 6, 6, 8, 8, 9,
  130350. 9, 9, 9,10,10,11,12, 7, 8, 8, 9, 9,10,10,10,10,
  130351. 12,12,13,12, 7, 8, 8, 9, 9,10,10,10,10,11,12,12,
  130352. 12, 8, 9, 9,10,10,11,11,11,11,12,12,13,13, 8, 9,
  130353. 9,10,10,11,11,11,11,12,13,13,13, 8, 9, 9,10,10,
  130354. 11,11,12,12,13,13,14,14, 8, 9, 9,10,10,11,11,12,
  130355. 12,13,13,14,14, 9,10,10,11,12,13,12,13,14,14,14,
  130356. 14,14, 9,10,10,11,12,12,13,13,13,14,14,14,14,10,
  130357. 11,11,12,12,13,13,14,14,15,15,15,15,10,11,11,12,
  130358. 12,13,13,14,14,14,14,15,15,
  130359. };
  130360. static float _vq_quantthresh__16u2_p6_0[] = {
  130361. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  130362. 12.5, 17.5, 22.5, 27.5,
  130363. };
  130364. static long _vq_quantmap__16u2_p6_0[] = {
  130365. 11, 9, 7, 5, 3, 1, 0, 2,
  130366. 4, 6, 8, 10, 12,
  130367. };
  130368. static encode_aux_threshmatch _vq_auxt__16u2_p6_0 = {
  130369. _vq_quantthresh__16u2_p6_0,
  130370. _vq_quantmap__16u2_p6_0,
  130371. 13,
  130372. 13
  130373. };
  130374. static static_codebook _16u2_p6_0 = {
  130375. 2, 169,
  130376. _vq_lengthlist__16u2_p6_0,
  130377. 1, -526516224, 1616117760, 4, 0,
  130378. _vq_quantlist__16u2_p6_0,
  130379. NULL,
  130380. &_vq_auxt__16u2_p6_0,
  130381. NULL,
  130382. 0
  130383. };
  130384. static long _vq_quantlist__16u2_p6_1[] = {
  130385. 2,
  130386. 1,
  130387. 3,
  130388. 0,
  130389. 4,
  130390. };
  130391. static long _vq_lengthlist__16u2_p6_1[] = {
  130392. 2, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
  130393. 5, 5, 6, 6, 5, 5, 5, 6, 6,
  130394. };
  130395. static float _vq_quantthresh__16u2_p6_1[] = {
  130396. -1.5, -0.5, 0.5, 1.5,
  130397. };
  130398. static long _vq_quantmap__16u2_p6_1[] = {
  130399. 3, 1, 0, 2, 4,
  130400. };
  130401. static encode_aux_threshmatch _vq_auxt__16u2_p6_1 = {
  130402. _vq_quantthresh__16u2_p6_1,
  130403. _vq_quantmap__16u2_p6_1,
  130404. 5,
  130405. 5
  130406. };
  130407. static static_codebook _16u2_p6_1 = {
  130408. 2, 25,
  130409. _vq_lengthlist__16u2_p6_1,
  130410. 1, -533725184, 1611661312, 3, 0,
  130411. _vq_quantlist__16u2_p6_1,
  130412. NULL,
  130413. &_vq_auxt__16u2_p6_1,
  130414. NULL,
  130415. 0
  130416. };
  130417. static long _vq_quantlist__16u2_p7_0[] = {
  130418. 6,
  130419. 5,
  130420. 7,
  130421. 4,
  130422. 8,
  130423. 3,
  130424. 9,
  130425. 2,
  130426. 10,
  130427. 1,
  130428. 11,
  130429. 0,
  130430. 12,
  130431. };
  130432. static long _vq_lengthlist__16u2_p7_0[] = {
  130433. 1, 4, 4, 7, 7, 7, 7, 8, 8, 9, 9,10,10, 4, 6, 6,
  130434. 9, 9, 9, 9, 9, 9,10,10,11,11, 4, 6, 6, 8, 9, 9,
  130435. 9, 9, 9,10,11,12,11, 7, 8, 9,10,10,10,10,11,10,
  130436. 11,12,12,13, 7, 9, 9,10,10,10,10,10,10,11,12,13,
  130437. 13, 7, 9, 8,10,10,11,11,11,12,12,13,13,14, 7, 9,
  130438. 9,10,10,11,11,11,12,13,13,13,13, 8, 9, 9,10,11,
  130439. 11,12,12,12,13,13,13,13, 8, 9, 9,10,11,11,11,12,
  130440. 12,13,13,14,14, 9,10,10,12,11,12,13,13,13,14,13,
  130441. 13,13, 9,10,10,11,11,12,12,13,14,13,13,14,13,10,
  130442. 11,11,12,13,14,14,14,15,14,14,14,14,10,11,11,12,
  130443. 12,13,13,13,14,14,14,15,14,
  130444. };
  130445. static float _vq_quantthresh__16u2_p7_0[] = {
  130446. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  130447. 27.5, 38.5, 49.5, 60.5,
  130448. };
  130449. static long _vq_quantmap__16u2_p7_0[] = {
  130450. 11, 9, 7, 5, 3, 1, 0, 2,
  130451. 4, 6, 8, 10, 12,
  130452. };
  130453. static encode_aux_threshmatch _vq_auxt__16u2_p7_0 = {
  130454. _vq_quantthresh__16u2_p7_0,
  130455. _vq_quantmap__16u2_p7_0,
  130456. 13,
  130457. 13
  130458. };
  130459. static static_codebook _16u2_p7_0 = {
  130460. 2, 169,
  130461. _vq_lengthlist__16u2_p7_0,
  130462. 1, -523206656, 1618345984, 4, 0,
  130463. _vq_quantlist__16u2_p7_0,
  130464. NULL,
  130465. &_vq_auxt__16u2_p7_0,
  130466. NULL,
  130467. 0
  130468. };
  130469. static long _vq_quantlist__16u2_p7_1[] = {
  130470. 5,
  130471. 4,
  130472. 6,
  130473. 3,
  130474. 7,
  130475. 2,
  130476. 8,
  130477. 1,
  130478. 9,
  130479. 0,
  130480. 10,
  130481. };
  130482. static long _vq_lengthlist__16u2_p7_1[] = {
  130483. 3, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 6, 7, 7,
  130484. 7, 7, 7, 7, 8, 8, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8,
  130485. 8, 6, 6, 7, 7, 7, 8, 7, 8, 8, 8, 8, 6, 7, 7, 7,
  130486. 7, 7, 7, 8, 8, 8, 8, 7, 7, 7, 7, 7, 8, 8, 8, 8,
  130487. 8, 8, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7,
  130488. 8, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8,
  130489. 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8,
  130490. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  130491. };
  130492. static float _vq_quantthresh__16u2_p7_1[] = {
  130493. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  130494. 3.5, 4.5,
  130495. };
  130496. static long _vq_quantmap__16u2_p7_1[] = {
  130497. 9, 7, 5, 3, 1, 0, 2, 4,
  130498. 6, 8, 10,
  130499. };
  130500. static encode_aux_threshmatch _vq_auxt__16u2_p7_1 = {
  130501. _vq_quantthresh__16u2_p7_1,
  130502. _vq_quantmap__16u2_p7_1,
  130503. 11,
  130504. 11
  130505. };
  130506. static static_codebook _16u2_p7_1 = {
  130507. 2, 121,
  130508. _vq_lengthlist__16u2_p7_1,
  130509. 1, -531365888, 1611661312, 4, 0,
  130510. _vq_quantlist__16u2_p7_1,
  130511. NULL,
  130512. &_vq_auxt__16u2_p7_1,
  130513. NULL,
  130514. 0
  130515. };
  130516. static long _vq_quantlist__16u2_p8_0[] = {
  130517. 7,
  130518. 6,
  130519. 8,
  130520. 5,
  130521. 9,
  130522. 4,
  130523. 10,
  130524. 3,
  130525. 11,
  130526. 2,
  130527. 12,
  130528. 1,
  130529. 13,
  130530. 0,
  130531. 14,
  130532. };
  130533. static long _vq_lengthlist__16u2_p8_0[] = {
  130534. 1, 5, 5, 7, 7, 8, 8, 7, 7, 8, 8,10, 9,11,11, 4,
  130535. 6, 6, 8, 8,10, 9, 9, 8, 9, 9,10,10,12,14, 4, 6,
  130536. 7, 8, 9, 9,10, 9, 8, 9, 9,10,12,12,11, 7, 8, 8,
  130537. 10,10,10,10, 9, 9,10,10,11,13,13,12, 7, 8, 8, 9,
  130538. 11,11,10, 9, 9,11,10,12,11,11,14, 8, 9, 9,11,10,
  130539. 11,11,10,10,11,11,13,12,14,12, 8, 9, 9,11,12,11,
  130540. 11,10,10,12,11,12,12,12,14, 7, 8, 8, 9, 9,10,10,
  130541. 10,11,12,11,13,13,14,12, 7, 8, 9, 9, 9,10,10,11,
  130542. 11,11,12,12,14,14,14, 8,10, 9,10,11,11,11,11,14,
  130543. 12,12,13,14,14,13, 9, 9, 9,10,11,11,11,12,12,12,
  130544. 14,12,14,13,14,10,10,10,12,11,12,11,14,13,14,13,
  130545. 14,14,13,14, 9,10,10,11,12,11,13,12,13,13,14,14,
  130546. 14,13,14,10,13,13,12,12,11,12,14,13,14,13,14,12,
  130547. 14,13,10,11,11,12,11,12,12,14,14,14,13,14,14,14,
  130548. 14,
  130549. };
  130550. static float _vq_quantthresh__16u2_p8_0[] = {
  130551. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  130552. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  130553. };
  130554. static long _vq_quantmap__16u2_p8_0[] = {
  130555. 13, 11, 9, 7, 5, 3, 1, 0,
  130556. 2, 4, 6, 8, 10, 12, 14,
  130557. };
  130558. static encode_aux_threshmatch _vq_auxt__16u2_p8_0 = {
  130559. _vq_quantthresh__16u2_p8_0,
  130560. _vq_quantmap__16u2_p8_0,
  130561. 15,
  130562. 15
  130563. };
  130564. static static_codebook _16u2_p8_0 = {
  130565. 2, 225,
  130566. _vq_lengthlist__16u2_p8_0,
  130567. 1, -520986624, 1620377600, 4, 0,
  130568. _vq_quantlist__16u2_p8_0,
  130569. NULL,
  130570. &_vq_auxt__16u2_p8_0,
  130571. NULL,
  130572. 0
  130573. };
  130574. static long _vq_quantlist__16u2_p8_1[] = {
  130575. 10,
  130576. 9,
  130577. 11,
  130578. 8,
  130579. 12,
  130580. 7,
  130581. 13,
  130582. 6,
  130583. 14,
  130584. 5,
  130585. 15,
  130586. 4,
  130587. 16,
  130588. 3,
  130589. 17,
  130590. 2,
  130591. 18,
  130592. 1,
  130593. 19,
  130594. 0,
  130595. 20,
  130596. };
  130597. static long _vq_lengthlist__16u2_p8_1[] = {
  130598. 2, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9,10, 9,10, 9, 9,
  130599. 9,10,10,10,10, 5, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,
  130600. 10, 9,10,10,10,10,10,10,11,10, 5, 6, 6, 7, 7, 8,
  130601. 8, 8, 9, 9,10,10,10,10,10,10,10,10,10,10,10, 7,
  130602. 7, 7, 8, 8, 9, 8, 9, 9,10, 9,10,10,10,10,10,10,
  130603. 11,10,11,10, 7, 7, 7, 8, 8, 8, 9, 9, 9,10, 9,10,
  130604. 10,10,10,10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9,
  130605. 10, 9,10,10,10,10,10,10,10,11,10,10,11,10, 8, 8,
  130606. 8, 8, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,11,
  130607. 11,10,10, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,
  130608. 11,10,11,10,11,10,11,10, 8, 9, 9, 9, 9, 9,10,10,
  130609. 10,10,10,10,10,10,10,10,11,11,10,10,10, 9,10, 9,
  130610. 9,10,10,10,11,10,10,10,10,10,10,10,10,11,11,11,
  130611. 11,11, 9, 9, 9,10, 9,10,10,10,10,10,10,11,10,11,
  130612. 10,11,11,11,11,10,10, 9,10, 9,10,10,10,10,11,10,
  130613. 10,10,10,10,11,10,11,10,11,10,10,11, 9,10,10,10,
  130614. 10,10,10,10,10,10,11,10,10,11,11,10,11,11,11,11,
  130615. 11, 9, 9,10,10,10,10,10,11,10,10,11,10,10,11,10,
  130616. 10,11,11,11,11,11, 9,10,10,10,10,10,10,10,11,10,
  130617. 11,10,11,10,11,11,11,11,11,10,11,10,10,10,10,10,
  130618. 10,10,10,10,11,11,11,11,11,11,11,11,11,10,11,11,
  130619. 10,10,10,10,10,11,10,10,10,11,10,11,11,11,11,10,
  130620. 12,11,11,11,10,10,10,10,10,10,11,10,10,10,11,11,
  130621. 12,11,11,11,11,11,11,11,11,11,10,10,10,11,10,11,
  130622. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,
  130623. 10,10,11,10,11,10,10,11,11,11,11,11,11,11,11,11,
  130624. 11,11,11,10,10,10,10,10,10,10,11,11,10,11,11,10,
  130625. 11,11,10,11,11,11,10,11,11,
  130626. };
  130627. static float _vq_quantthresh__16u2_p8_1[] = {
  130628. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  130629. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  130630. 6.5, 7.5, 8.5, 9.5,
  130631. };
  130632. static long _vq_quantmap__16u2_p8_1[] = {
  130633. 19, 17, 15, 13, 11, 9, 7, 5,
  130634. 3, 1, 0, 2, 4, 6, 8, 10,
  130635. 12, 14, 16, 18, 20,
  130636. };
  130637. static encode_aux_threshmatch _vq_auxt__16u2_p8_1 = {
  130638. _vq_quantthresh__16u2_p8_1,
  130639. _vq_quantmap__16u2_p8_1,
  130640. 21,
  130641. 21
  130642. };
  130643. static static_codebook _16u2_p8_1 = {
  130644. 2, 441,
  130645. _vq_lengthlist__16u2_p8_1,
  130646. 1, -529268736, 1611661312, 5, 0,
  130647. _vq_quantlist__16u2_p8_1,
  130648. NULL,
  130649. &_vq_auxt__16u2_p8_1,
  130650. NULL,
  130651. 0
  130652. };
  130653. static long _vq_quantlist__16u2_p9_0[] = {
  130654. 5586,
  130655. 4655,
  130656. 6517,
  130657. 3724,
  130658. 7448,
  130659. 2793,
  130660. 8379,
  130661. 1862,
  130662. 9310,
  130663. 931,
  130664. 10241,
  130665. 0,
  130666. 11172,
  130667. 5521,
  130668. 5651,
  130669. };
  130670. static long _vq_lengthlist__16u2_p9_0[] = {
  130671. 1,10,10,10,10,10,10,10,10,10,10,10,10, 5, 4,10,
  130672. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130673. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130674. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130675. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130676. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130677. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130678. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130679. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130680. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130681. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130682. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130683. 10,10,10, 4,10,10,10,10,10,10,10,10,10,10,10,10,
  130684. 6, 6, 5,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 5,
  130685. 5,
  130686. };
  130687. static float _vq_quantthresh__16u2_p9_0[] = {
  130688. -5120.5, -4189.5, -3258.5, -2327.5, -1396.5, -498, -32.5, 32.5,
  130689. 498, 1396.5, 2327.5, 3258.5, 4189.5, 5120.5,
  130690. };
  130691. static long _vq_quantmap__16u2_p9_0[] = {
  130692. 11, 9, 7, 5, 3, 1, 13, 0,
  130693. 14, 2, 4, 6, 8, 10, 12,
  130694. };
  130695. static encode_aux_threshmatch _vq_auxt__16u2_p9_0 = {
  130696. _vq_quantthresh__16u2_p9_0,
  130697. _vq_quantmap__16u2_p9_0,
  130698. 15,
  130699. 15
  130700. };
  130701. static static_codebook _16u2_p9_0 = {
  130702. 2, 225,
  130703. _vq_lengthlist__16u2_p9_0,
  130704. 1, -510275072, 1611661312, 14, 0,
  130705. _vq_quantlist__16u2_p9_0,
  130706. NULL,
  130707. &_vq_auxt__16u2_p9_0,
  130708. NULL,
  130709. 0
  130710. };
  130711. static long _vq_quantlist__16u2_p9_1[] = {
  130712. 392,
  130713. 343,
  130714. 441,
  130715. 294,
  130716. 490,
  130717. 245,
  130718. 539,
  130719. 196,
  130720. 588,
  130721. 147,
  130722. 637,
  130723. 98,
  130724. 686,
  130725. 49,
  130726. 735,
  130727. 0,
  130728. 784,
  130729. 388,
  130730. 396,
  130731. };
  130732. static long _vq_lengthlist__16u2_p9_1[] = {
  130733. 1,12,10,12,10,12,10,12,11,12,12,12,12,12,12,12,
  130734. 12, 5, 5, 9,10,12,11,11,12,12,12,12,12,12,12,12,
  130735. 12,12,12,12,10, 9, 9,11, 9,11,11,12,11,12,12,12,
  130736. 12,12,12,12,12,12,12, 8, 8,10,11, 9,12,11,12,12,
  130737. 12,12,12,12,12,12,12,12,12,12, 9, 8,10,11,12,11,
  130738. 12,11,12,12,12,12,12,12,12,12,12,12,12, 8, 9,11,
  130739. 11,10,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130740. 9,10,11,12,11,12,11,12,12,12,12,12,12,12,12,12,
  130741. 12,12,12, 9, 9,11,12,12,12,12,12,12,12,12,12,12,
  130742. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130743. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130744. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130745. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130746. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130747. 12,12,12,12,11,11,11,11,11,11,11,11,11,11,11,11,
  130748. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130749. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130750. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130751. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130752. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130753. 11,11,11, 5, 8, 9, 9, 8,11, 9,11,11,11,11,11,11,
  130754. 11,11,11,11, 5, 5, 4, 8, 8, 8, 8,10, 9,10,10,11,
  130755. 11,11,11,11,11,11,11, 5, 4,
  130756. };
  130757. static float _vq_quantthresh__16u2_p9_1[] = {
  130758. -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5, -26.5,
  130759. -2, 2, 26.5, 73.5, 122.5, 171.5, 220.5, 269.5,
  130760. 318.5, 367.5,
  130761. };
  130762. static long _vq_quantmap__16u2_p9_1[] = {
  130763. 15, 13, 11, 9, 7, 5, 3, 1,
  130764. 17, 0, 18, 2, 4, 6, 8, 10,
  130765. 12, 14, 16,
  130766. };
  130767. static encode_aux_threshmatch _vq_auxt__16u2_p9_1 = {
  130768. _vq_quantthresh__16u2_p9_1,
  130769. _vq_quantmap__16u2_p9_1,
  130770. 19,
  130771. 19
  130772. };
  130773. static static_codebook _16u2_p9_1 = {
  130774. 2, 361,
  130775. _vq_lengthlist__16u2_p9_1,
  130776. 1, -518488064, 1611661312, 10, 0,
  130777. _vq_quantlist__16u2_p9_1,
  130778. NULL,
  130779. &_vq_auxt__16u2_p9_1,
  130780. NULL,
  130781. 0
  130782. };
  130783. static long _vq_quantlist__16u2_p9_2[] = {
  130784. 24,
  130785. 23,
  130786. 25,
  130787. 22,
  130788. 26,
  130789. 21,
  130790. 27,
  130791. 20,
  130792. 28,
  130793. 19,
  130794. 29,
  130795. 18,
  130796. 30,
  130797. 17,
  130798. 31,
  130799. 16,
  130800. 32,
  130801. 15,
  130802. 33,
  130803. 14,
  130804. 34,
  130805. 13,
  130806. 35,
  130807. 12,
  130808. 36,
  130809. 11,
  130810. 37,
  130811. 10,
  130812. 38,
  130813. 9,
  130814. 39,
  130815. 8,
  130816. 40,
  130817. 7,
  130818. 41,
  130819. 6,
  130820. 42,
  130821. 5,
  130822. 43,
  130823. 4,
  130824. 44,
  130825. 3,
  130826. 45,
  130827. 2,
  130828. 46,
  130829. 1,
  130830. 47,
  130831. 0,
  130832. 48,
  130833. };
  130834. static long _vq_lengthlist__16u2_p9_2[] = {
  130835. 1, 3, 3, 4, 7, 7, 7, 8, 7, 7, 7, 7, 8, 8, 8, 8,
  130836. 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 9, 9, 8, 9, 9,
  130837. 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,12,12,10,
  130838. 11,
  130839. };
  130840. static float _vq_quantthresh__16u2_p9_2[] = {
  130841. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  130842. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  130843. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  130844. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  130845. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  130846. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  130847. };
  130848. static long _vq_quantmap__16u2_p9_2[] = {
  130849. 47, 45, 43, 41, 39, 37, 35, 33,
  130850. 31, 29, 27, 25, 23, 21, 19, 17,
  130851. 15, 13, 11, 9, 7, 5, 3, 1,
  130852. 0, 2, 4, 6, 8, 10, 12, 14,
  130853. 16, 18, 20, 22, 24, 26, 28, 30,
  130854. 32, 34, 36, 38, 40, 42, 44, 46,
  130855. 48,
  130856. };
  130857. static encode_aux_threshmatch _vq_auxt__16u2_p9_2 = {
  130858. _vq_quantthresh__16u2_p9_2,
  130859. _vq_quantmap__16u2_p9_2,
  130860. 49,
  130861. 49
  130862. };
  130863. static static_codebook _16u2_p9_2 = {
  130864. 1, 49,
  130865. _vq_lengthlist__16u2_p9_2,
  130866. 1, -526909440, 1611661312, 6, 0,
  130867. _vq_quantlist__16u2_p9_2,
  130868. NULL,
  130869. &_vq_auxt__16u2_p9_2,
  130870. NULL,
  130871. 0
  130872. };
  130873. static long _vq_quantlist__8u0__p1_0[] = {
  130874. 1,
  130875. 0,
  130876. 2,
  130877. };
  130878. static long _vq_lengthlist__8u0__p1_0[] = {
  130879. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 8, 8,10,10, 7,
  130880. 10,10, 5, 8, 8, 7,10,10, 8,10,10, 4, 9, 8, 8,11,
  130881. 11, 8,11,11, 7,11,11,10,11,13,10,13,13, 7,11,11,
  130882. 10,13,12,10,13,13, 5, 9, 8, 8,11,11, 8,11,11, 7,
  130883. 11,11, 9,13,13,10,12,13, 7,11,11,10,13,13,10,13,
  130884. 11,
  130885. };
  130886. static float _vq_quantthresh__8u0__p1_0[] = {
  130887. -0.5, 0.5,
  130888. };
  130889. static long _vq_quantmap__8u0__p1_0[] = {
  130890. 1, 0, 2,
  130891. };
  130892. static encode_aux_threshmatch _vq_auxt__8u0__p1_0 = {
  130893. _vq_quantthresh__8u0__p1_0,
  130894. _vq_quantmap__8u0__p1_0,
  130895. 3,
  130896. 3
  130897. };
  130898. static static_codebook _8u0__p1_0 = {
  130899. 4, 81,
  130900. _vq_lengthlist__8u0__p1_0,
  130901. 1, -535822336, 1611661312, 2, 0,
  130902. _vq_quantlist__8u0__p1_0,
  130903. NULL,
  130904. &_vq_auxt__8u0__p1_0,
  130905. NULL,
  130906. 0
  130907. };
  130908. static long _vq_quantlist__8u0__p2_0[] = {
  130909. 1,
  130910. 0,
  130911. 2,
  130912. };
  130913. static long _vq_lengthlist__8u0__p2_0[] = {
  130914. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 6, 7, 8, 6,
  130915. 7, 8, 5, 7, 7, 6, 8, 8, 7, 9, 7, 5, 7, 7, 7, 9,
  130916. 9, 7, 8, 8, 6, 9, 8, 7, 7,10, 8,10,10, 6, 8, 8,
  130917. 8,10, 8, 8,10,10, 5, 7, 7, 7, 8, 8, 7, 8, 9, 6,
  130918. 8, 8, 8,10,10, 8, 8,10, 6, 8, 9, 8,10,10, 7,10,
  130919. 8,
  130920. };
  130921. static float _vq_quantthresh__8u0__p2_0[] = {
  130922. -0.5, 0.5,
  130923. };
  130924. static long _vq_quantmap__8u0__p2_0[] = {
  130925. 1, 0, 2,
  130926. };
  130927. static encode_aux_threshmatch _vq_auxt__8u0__p2_0 = {
  130928. _vq_quantthresh__8u0__p2_0,
  130929. _vq_quantmap__8u0__p2_0,
  130930. 3,
  130931. 3
  130932. };
  130933. static static_codebook _8u0__p2_0 = {
  130934. 4, 81,
  130935. _vq_lengthlist__8u0__p2_0,
  130936. 1, -535822336, 1611661312, 2, 0,
  130937. _vq_quantlist__8u0__p2_0,
  130938. NULL,
  130939. &_vq_auxt__8u0__p2_0,
  130940. NULL,
  130941. 0
  130942. };
  130943. static long _vq_quantlist__8u0__p3_0[] = {
  130944. 2,
  130945. 1,
  130946. 3,
  130947. 0,
  130948. 4,
  130949. };
  130950. static long _vq_lengthlist__8u0__p3_0[] = {
  130951. 1, 5, 5, 7, 7, 6, 7, 7, 9, 9, 6, 7, 7, 9, 9, 8,
  130952. 10, 9,11,11, 8, 9, 9,11,11, 6, 8, 8,10,10, 8,10,
  130953. 10,11,11, 8,10,10,11,11,10,11,11,12,12,10,11,11,
  130954. 12,13, 6, 8, 8,10,10, 8,10,10,11,11, 8,10,10,11,
  130955. 11, 9,10,11,12,12,10,11,11,12,12, 8,11,11,14,13,
  130956. 10,12,11,15,13,10,12,11,14,14,12,13,12,16,14,12,
  130957. 14,12,16,15, 8,11,11,13,14,10,11,12,13,15,10,11,
  130958. 12,13,15,11,12,13,14,15,12,12,14,14,16, 5, 8, 8,
  130959. 11,11, 9,11,11,12,12, 8,10,11,12,12,11,12,12,15,
  130960. 14,11,12,12,14,14, 7,11,10,13,12,10,11,12,13,14,
  130961. 10,12,12,14,13,12,13,13,14,15,12,13,13,15,15, 7,
  130962. 10,11,12,13,10,12,11,14,13,10,12,13,13,15,12,13,
  130963. 12,14,14,11,13,13,15,16, 9,12,12,15,14,11,13,13,
  130964. 15,16,11,13,13,16,16,13,14,15,15,15,12,14,15,17,
  130965. 16, 9,12,12,14,15,11,13,13,15,16,11,13,13,16,18,
  130966. 13,14,14,17,16,13,15,15,17,18, 5, 8, 9,11,11, 8,
  130967. 11,11,12,12, 8,10,11,12,12,11,12,12,14,14,11,12,
  130968. 12,14,15, 7,11,10,12,13,10,12,12,14,13,10,11,12,
  130969. 13,14,11,13,13,15,14,12,13,13,14,15, 7,10,11,13,
  130970. 13,10,12,12,13,14,10,12,12,13,13,11,13,13,16,16,
  130971. 12,13,13,15,14, 9,12,12,16,15,10,13,13,15,15,11,
  130972. 13,13,17,15,12,15,15,18,17,13,14,14,15,16, 9,12,
  130973. 12,15,15,11,13,13,15,16,11,13,13,15,15,12,15,15,
  130974. 16,16,13,15,14,17,15, 7,11,11,15,15,10,13,13,16,
  130975. 15,10,13,13,15,16,14,15,15,17,19,13,15,14,15,18,
  130976. 9,12,12,16,16,11,13,14,17,16,11,13,13,17,16,15,
  130977. 15,16,17,19,13,15,16, 0,18, 9,12,12,16,15,11,14,
  130978. 13,17,17,11,13,14,16,16,15,16,16,19,18,13,15,15,
  130979. 17,19,11,14,14,19,16,12,14,15, 0,18,12,16,15,18,
  130980. 17,15,15,18,16,19,14,15,17,19,19,11,14,14,18,19,
  130981. 13,15,14,19,19,12,16,15,18,17,15,17,15, 0,16,14,
  130982. 17,16,19, 0, 7,11,11,14,14,10,12,12,15,15,10,13,
  130983. 13,16,15,13,15,15,17, 0,14,15,15,16,19, 9,12,12,
  130984. 16,16,11,14,14,16,16,11,13,13,16,16,14,17,16,19,
  130985. 0,14,18,17,17,19, 9,12,12,15,16,11,13,13,15,17,
  130986. 12,14,13,19,16,13,15,15,17,19,15,17,16,17,19,11,
  130987. 14,14,19,16,12,15,15,19,17,13,14,15,17,19,14,16,
  130988. 17,19,19,16,15,16,17,19,11,15,14,16,16,12,15,15,
  130989. 19, 0,12,14,15,19,19,14,16,16, 0,18,15,19,14,18,
  130990. 16,
  130991. };
  130992. static float _vq_quantthresh__8u0__p3_0[] = {
  130993. -1.5, -0.5, 0.5, 1.5,
  130994. };
  130995. static long _vq_quantmap__8u0__p3_0[] = {
  130996. 3, 1, 0, 2, 4,
  130997. };
  130998. static encode_aux_threshmatch _vq_auxt__8u0__p3_0 = {
  130999. _vq_quantthresh__8u0__p3_0,
  131000. _vq_quantmap__8u0__p3_0,
  131001. 5,
  131002. 5
  131003. };
  131004. static static_codebook _8u0__p3_0 = {
  131005. 4, 625,
  131006. _vq_lengthlist__8u0__p3_0,
  131007. 1, -533725184, 1611661312, 3, 0,
  131008. _vq_quantlist__8u0__p3_0,
  131009. NULL,
  131010. &_vq_auxt__8u0__p3_0,
  131011. NULL,
  131012. 0
  131013. };
  131014. static long _vq_quantlist__8u0__p4_0[] = {
  131015. 2,
  131016. 1,
  131017. 3,
  131018. 0,
  131019. 4,
  131020. };
  131021. static long _vq_lengthlist__8u0__p4_0[] = {
  131022. 3, 5, 5, 8, 8, 5, 6, 7, 9, 9, 6, 7, 6, 9, 9, 9,
  131023. 9, 9,10,11, 9, 9, 9,11,10, 6, 7, 7,10,10, 7, 7,
  131024. 8,10,10, 7, 8, 8,10,10,10,10,10,10,11, 9,10,10,
  131025. 11,12, 6, 7, 7,10,10, 7, 8, 8,10,10, 7, 8, 7,10,
  131026. 10, 9,10,10,12,11,10,10,10,11,10, 9,10,10,12,11,
  131027. 10,10,10,13,11, 9,10,10,12,12,11,11,12,12,13,11,
  131028. 11,11,12,13, 9,10,10,12,12,10,10,11,12,12,10,10,
  131029. 11,12,12,11,11,11,13,13,11,12,12,13,13, 5, 7, 7,
  131030. 10,10, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,11,12,
  131031. 12,10,11,10,12,12, 7, 8, 8,11,11, 7, 8, 9,10,11,
  131032. 8, 9, 9,11,11,11,10,11,10,12,10,11,11,12,13, 7,
  131033. 8, 8,10,11, 8, 9, 8,12,10, 8, 9, 9,11,12,10,11,
  131034. 10,13,11,10,11,11,13,12, 9,11,10,13,12,10,10,11,
  131035. 12,12,10,11,11,13,13,12,10,13,11,14,11,12,12,15,
  131036. 13, 9,11,11,13,13,10,11,11,13,12,10,11,11,12,14,
  131037. 12,13,11,14,12,12,12,12,14,14, 5, 7, 7,10,10, 7,
  131038. 8, 8,10,10, 7, 8, 8,11,10,10,11,11,12,12,10,11,
  131039. 10,12,12, 7, 8, 8,10,11, 8, 9, 9,12,11, 8, 8, 9,
  131040. 10,11,10,11,11,12,13,11,10,11,11,13, 6, 8, 8,10,
  131041. 11, 8, 9, 9,11,11, 7, 9, 7,11,10,10,11,11,12,12,
  131042. 10,11,10,13,10, 9,11,10,13,12,10,12,11,13,13,10,
  131043. 10,11,12,13,11,12,13,15,14,11,11,13,12,13, 9,10,
  131044. 11,12,13,10,11,11,12,13,10,11,10,13,12,12,13,13,
  131045. 13,14,12,12,11,14,11, 8,10,10,12,13,10,11,11,13,
  131046. 13,10,11,10,13,13,12,13,14,15,14,12,12,12,14,13,
  131047. 9,10,10,13,12,10,10,12,13,13,10,11,11,15,12,12,
  131048. 12,13,15,14,12,13,13,15,13, 9,10,11,12,13,10,12,
  131049. 10,13,12,10,11,11,12,13,12,14,12,15,13,12,12,12,
  131050. 15,14,11,12,11,14,13,11,11,12,14,14,12,13,13,14,
  131051. 13,13,11,15,11,15,14,14,14,16,15,11,12,12,13,14,
  131052. 11,13,11,14,14,12,12,13,14,15,12,14,12,15,12,13,
  131053. 15,14,16,15, 8,10,10,12,12,10,10,10,12,13,10,11,
  131054. 11,13,13,12,12,12,13,14,13,13,13,15,15, 9,10,10,
  131055. 12,12,10,11,11,13,12,10,10,11,13,13,12,12,12,14,
  131056. 14,12,12,13,15,14, 9,10,10,13,12,10,10,12,12,13,
  131057. 10,11,10,13,13,12,13,13,14,14,12,13,12,14,13,11,
  131058. 12,12,14,13,12,13,12,14,14,10,12,12,14,14,14,14,
  131059. 14,16,14,13,12,14,12,15,10,12,12,14,15,12,13,13,
  131060. 14,16,11,12,11,15,14,13,14,14,14,15,13,14,11,14,
  131061. 12,
  131062. };
  131063. static float _vq_quantthresh__8u0__p4_0[] = {
  131064. -1.5, -0.5, 0.5, 1.5,
  131065. };
  131066. static long _vq_quantmap__8u0__p4_0[] = {
  131067. 3, 1, 0, 2, 4,
  131068. };
  131069. static encode_aux_threshmatch _vq_auxt__8u0__p4_0 = {
  131070. _vq_quantthresh__8u0__p4_0,
  131071. _vq_quantmap__8u0__p4_0,
  131072. 5,
  131073. 5
  131074. };
  131075. static static_codebook _8u0__p4_0 = {
  131076. 4, 625,
  131077. _vq_lengthlist__8u0__p4_0,
  131078. 1, -533725184, 1611661312, 3, 0,
  131079. _vq_quantlist__8u0__p4_0,
  131080. NULL,
  131081. &_vq_auxt__8u0__p4_0,
  131082. NULL,
  131083. 0
  131084. };
  131085. static long _vq_quantlist__8u0__p5_0[] = {
  131086. 4,
  131087. 3,
  131088. 5,
  131089. 2,
  131090. 6,
  131091. 1,
  131092. 7,
  131093. 0,
  131094. 8,
  131095. };
  131096. static long _vq_lengthlist__8u0__p5_0[] = {
  131097. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 7, 8, 8,
  131098. 10,10, 4, 6, 6, 8, 8, 8, 8,10,10, 6, 8, 8, 9, 9,
  131099. 9, 9,11,11, 7, 8, 8, 9, 9, 9, 9,11,11, 7, 8, 8,
  131100. 9, 9,10,10,12,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  131101. 10,10,11,11,11,12,12,12, 9,10,10,11,11,12,12,12,
  131102. 12,
  131103. };
  131104. static float _vq_quantthresh__8u0__p5_0[] = {
  131105. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  131106. };
  131107. static long _vq_quantmap__8u0__p5_0[] = {
  131108. 7, 5, 3, 1, 0, 2, 4, 6,
  131109. 8,
  131110. };
  131111. static encode_aux_threshmatch _vq_auxt__8u0__p5_0 = {
  131112. _vq_quantthresh__8u0__p5_0,
  131113. _vq_quantmap__8u0__p5_0,
  131114. 9,
  131115. 9
  131116. };
  131117. static static_codebook _8u0__p5_0 = {
  131118. 2, 81,
  131119. _vq_lengthlist__8u0__p5_0,
  131120. 1, -531628032, 1611661312, 4, 0,
  131121. _vq_quantlist__8u0__p5_0,
  131122. NULL,
  131123. &_vq_auxt__8u0__p5_0,
  131124. NULL,
  131125. 0
  131126. };
  131127. static long _vq_quantlist__8u0__p6_0[] = {
  131128. 6,
  131129. 5,
  131130. 7,
  131131. 4,
  131132. 8,
  131133. 3,
  131134. 9,
  131135. 2,
  131136. 10,
  131137. 1,
  131138. 11,
  131139. 0,
  131140. 12,
  131141. };
  131142. static long _vq_lengthlist__8u0__p6_0[] = {
  131143. 1, 4, 4, 7, 7, 9, 9,11,11,12,12,16,16, 3, 6, 6,
  131144. 9, 9,11,11,12,12,13,14,18,16, 3, 6, 7, 9, 9,11,
  131145. 11,13,12,14,14,17,16, 7, 9, 9,11,11,12,12,14,14,
  131146. 14,14,17,16, 7, 9, 9,11,11,13,12,13,13,14,14,17,
  131147. 0, 9,11,11,12,13,14,14,14,13,15,14,17,17, 9,11,
  131148. 11,12,12,14,14,13,14,14,15, 0, 0,11,12,12,15,14,
  131149. 15,14,15,14,15,16,17, 0,11,12,13,13,13,14,14,15,
  131150. 14,15,15, 0, 0,12,14,14,15,15,14,16,15,15,17,16,
  131151. 0,18,13,14,14,15,14,15,14,15,16,17,16, 0, 0,17,
  131152. 17,18, 0,16,18,16, 0, 0, 0,17, 0, 0,16, 0, 0,16,
  131153. 16, 0,15, 0,17, 0, 0, 0, 0,
  131154. };
  131155. static float _vq_quantthresh__8u0__p6_0[] = {
  131156. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  131157. 12.5, 17.5, 22.5, 27.5,
  131158. };
  131159. static long _vq_quantmap__8u0__p6_0[] = {
  131160. 11, 9, 7, 5, 3, 1, 0, 2,
  131161. 4, 6, 8, 10, 12,
  131162. };
  131163. static encode_aux_threshmatch _vq_auxt__8u0__p6_0 = {
  131164. _vq_quantthresh__8u0__p6_0,
  131165. _vq_quantmap__8u0__p6_0,
  131166. 13,
  131167. 13
  131168. };
  131169. static static_codebook _8u0__p6_0 = {
  131170. 2, 169,
  131171. _vq_lengthlist__8u0__p6_0,
  131172. 1, -526516224, 1616117760, 4, 0,
  131173. _vq_quantlist__8u0__p6_0,
  131174. NULL,
  131175. &_vq_auxt__8u0__p6_0,
  131176. NULL,
  131177. 0
  131178. };
  131179. static long _vq_quantlist__8u0__p6_1[] = {
  131180. 2,
  131181. 1,
  131182. 3,
  131183. 0,
  131184. 4,
  131185. };
  131186. static long _vq_lengthlist__8u0__p6_1[] = {
  131187. 1, 4, 4, 6, 6, 4, 6, 5, 7, 7, 4, 5, 6, 7, 7, 6,
  131188. 7, 7, 7, 7, 6, 7, 7, 7, 7,
  131189. };
  131190. static float _vq_quantthresh__8u0__p6_1[] = {
  131191. -1.5, -0.5, 0.5, 1.5,
  131192. };
  131193. static long _vq_quantmap__8u0__p6_1[] = {
  131194. 3, 1, 0, 2, 4,
  131195. };
  131196. static encode_aux_threshmatch _vq_auxt__8u0__p6_1 = {
  131197. _vq_quantthresh__8u0__p6_1,
  131198. _vq_quantmap__8u0__p6_1,
  131199. 5,
  131200. 5
  131201. };
  131202. static static_codebook _8u0__p6_1 = {
  131203. 2, 25,
  131204. _vq_lengthlist__8u0__p6_1,
  131205. 1, -533725184, 1611661312, 3, 0,
  131206. _vq_quantlist__8u0__p6_1,
  131207. NULL,
  131208. &_vq_auxt__8u0__p6_1,
  131209. NULL,
  131210. 0
  131211. };
  131212. static long _vq_quantlist__8u0__p7_0[] = {
  131213. 1,
  131214. 0,
  131215. 2,
  131216. };
  131217. static long _vq_lengthlist__8u0__p7_0[] = {
  131218. 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  131219. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  131220. 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  131221. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  131222. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  131223. 7,
  131224. };
  131225. static float _vq_quantthresh__8u0__p7_0[] = {
  131226. -157.5, 157.5,
  131227. };
  131228. static long _vq_quantmap__8u0__p7_0[] = {
  131229. 1, 0, 2,
  131230. };
  131231. static encode_aux_threshmatch _vq_auxt__8u0__p7_0 = {
  131232. _vq_quantthresh__8u0__p7_0,
  131233. _vq_quantmap__8u0__p7_0,
  131234. 3,
  131235. 3
  131236. };
  131237. static static_codebook _8u0__p7_0 = {
  131238. 4, 81,
  131239. _vq_lengthlist__8u0__p7_0,
  131240. 1, -518803456, 1628680192, 2, 0,
  131241. _vq_quantlist__8u0__p7_0,
  131242. NULL,
  131243. &_vq_auxt__8u0__p7_0,
  131244. NULL,
  131245. 0
  131246. };
  131247. static long _vq_quantlist__8u0__p7_1[] = {
  131248. 7,
  131249. 6,
  131250. 8,
  131251. 5,
  131252. 9,
  131253. 4,
  131254. 10,
  131255. 3,
  131256. 11,
  131257. 2,
  131258. 12,
  131259. 1,
  131260. 13,
  131261. 0,
  131262. 14,
  131263. };
  131264. static long _vq_lengthlist__8u0__p7_1[] = {
  131265. 1, 5, 5, 5, 5,10,10,11,11,11,11,11,11,11,11, 5,
  131266. 7, 6, 8, 8, 9,10,11,11,11,11,11,11,11,11, 6, 6,
  131267. 7, 9, 7,11,10,11,11,11,11,11,11,11,11, 5, 6, 6,
  131268. 11, 8,11,11,11,11,11,11,11,11,11,11, 5, 6, 6, 9,
  131269. 10,11,10,11,11,11,11,11,11,11,11, 7,10,10,11,11,
  131270. 11,11,11,11,11,11,11,11,11,11, 7,11, 8,11,11,11,
  131271. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131272. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131273. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131274. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131275. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131276. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131277. 11,11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,
  131278. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131279. 10,
  131280. };
  131281. static float _vq_quantthresh__8u0__p7_1[] = {
  131282. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  131283. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  131284. };
  131285. static long _vq_quantmap__8u0__p7_1[] = {
  131286. 13, 11, 9, 7, 5, 3, 1, 0,
  131287. 2, 4, 6, 8, 10, 12, 14,
  131288. };
  131289. static encode_aux_threshmatch _vq_auxt__8u0__p7_1 = {
  131290. _vq_quantthresh__8u0__p7_1,
  131291. _vq_quantmap__8u0__p7_1,
  131292. 15,
  131293. 15
  131294. };
  131295. static static_codebook _8u0__p7_1 = {
  131296. 2, 225,
  131297. _vq_lengthlist__8u0__p7_1,
  131298. 1, -520986624, 1620377600, 4, 0,
  131299. _vq_quantlist__8u0__p7_1,
  131300. NULL,
  131301. &_vq_auxt__8u0__p7_1,
  131302. NULL,
  131303. 0
  131304. };
  131305. static long _vq_quantlist__8u0__p7_2[] = {
  131306. 10,
  131307. 9,
  131308. 11,
  131309. 8,
  131310. 12,
  131311. 7,
  131312. 13,
  131313. 6,
  131314. 14,
  131315. 5,
  131316. 15,
  131317. 4,
  131318. 16,
  131319. 3,
  131320. 17,
  131321. 2,
  131322. 18,
  131323. 1,
  131324. 19,
  131325. 0,
  131326. 20,
  131327. };
  131328. static long _vq_lengthlist__8u0__p7_2[] = {
  131329. 1, 6, 5, 7, 7, 9, 9, 9, 9,10,12,12,10,11,11,10,
  131330. 11,11,11,10,11, 6, 8, 8, 9, 9,10,10, 9,10,11,11,
  131331. 10,11,11,11,11,10,11,11,11,11, 6, 7, 8, 9, 9, 9,
  131332. 10,11,10,11,12,11,10,11,11,11,11,11,11,12,10, 8,
  131333. 9, 9,10, 9,10,10, 9,10,10,10,10,10, 9,10,10,10,
  131334. 10, 9,10,10, 9, 9, 9, 9,10,10, 9, 9,10,10,11,10,
  131335. 9,12,10,11,10, 9,10,10,10, 8, 9, 9,10, 9,10, 9,
  131336. 9,10,10, 9,10, 9,11,10,10,10,10,10, 9,10, 8, 8,
  131337. 9, 9,10, 9,11, 9, 8, 9, 9,10,11,10,10,10,11,12,
  131338. 9, 9,11, 8, 9, 8,11,10,11,10,10, 9,11,10,10,10,
  131339. 10,10,10,10,11,11,11,11, 8, 9, 9, 9,10,10,10,11,
  131340. 11,12,11,12,11,10,10,10,12,11,11,11,10, 8,10, 9,
  131341. 11,10,10,11,12,10,11,12,11,11,12,11,12,12,10,11,
  131342. 11,10, 9, 9,10,11,12,10,10,10,11,10,11,11,10,12,
  131343. 12,10,11,10,11,12,10, 9,10,10,11,10,11,11,11,11,
  131344. 11,12,11,11,11, 9,11,10,11,10,11,10, 9, 9,10,11,
  131345. 11,11,10,10,11,12,12,11,12,11,11,11,12,12,12,12,
  131346. 11, 9,11,11,12,10,11,11,11,11,11,11,12,11,11,12,
  131347. 11,11,11,10,11,11, 9,11,10,11,11,11,10,10,10,11,
  131348. 11,11,12,10,11,10,11,11,11,11,12, 9,11,10,11,11,
  131349. 10,10,11,11, 9,11,11,12,10,10,10,10,10,11,11,10,
  131350. 9,10,11,11,12,11,10,10,12,11,11,12,11,12,11,11,
  131351. 10,10,11,11,10,12,11,10,11,10,11,10,10,10,11,11,
  131352. 10,10,11,11,11,11,10,10,10,12,11,11,11,11,10, 9,
  131353. 10,11,11,11,12,11,11,11,12,10,11,11,11, 9,10,11,
  131354. 11,11,11,11,11,10,10,11,11,12,11,10,11,12,11,10,
  131355. 10,11, 9,10,11,11,11,11,11,10,11,11,10,12,11,11,
  131356. 11,12,11,11,11,10,10,11,11,
  131357. };
  131358. static float _vq_quantthresh__8u0__p7_2[] = {
  131359. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  131360. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  131361. 6.5, 7.5, 8.5, 9.5,
  131362. };
  131363. static long _vq_quantmap__8u0__p7_2[] = {
  131364. 19, 17, 15, 13, 11, 9, 7, 5,
  131365. 3, 1, 0, 2, 4, 6, 8, 10,
  131366. 12, 14, 16, 18, 20,
  131367. };
  131368. static encode_aux_threshmatch _vq_auxt__8u0__p7_2 = {
  131369. _vq_quantthresh__8u0__p7_2,
  131370. _vq_quantmap__8u0__p7_2,
  131371. 21,
  131372. 21
  131373. };
  131374. static static_codebook _8u0__p7_2 = {
  131375. 2, 441,
  131376. _vq_lengthlist__8u0__p7_2,
  131377. 1, -529268736, 1611661312, 5, 0,
  131378. _vq_quantlist__8u0__p7_2,
  131379. NULL,
  131380. &_vq_auxt__8u0__p7_2,
  131381. NULL,
  131382. 0
  131383. };
  131384. static long _huff_lengthlist__8u0__single[] = {
  131385. 4, 7,11, 9,12, 8, 7,10, 6, 4, 5, 5, 7, 5, 6,16,
  131386. 9, 5, 5, 6, 7, 7, 9,16, 7, 4, 6, 5, 7, 5, 7,17,
  131387. 10, 7, 7, 8, 7, 7, 8,18, 7, 5, 6, 4, 5, 4, 5,15,
  131388. 7, 6, 7, 5, 6, 4, 5,15,12,13,18,12,17,11, 9,17,
  131389. };
  131390. static static_codebook _huff_book__8u0__single = {
  131391. 2, 64,
  131392. _huff_lengthlist__8u0__single,
  131393. 0, 0, 0, 0, 0,
  131394. NULL,
  131395. NULL,
  131396. NULL,
  131397. NULL,
  131398. 0
  131399. };
  131400. static long _vq_quantlist__8u1__p1_0[] = {
  131401. 1,
  131402. 0,
  131403. 2,
  131404. };
  131405. static long _vq_lengthlist__8u1__p1_0[] = {
  131406. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 8, 7, 9,10, 7,
  131407. 9, 9, 5, 8, 8, 7,10, 9, 7, 9, 9, 5, 8, 8, 8,10,
  131408. 10, 8,10,10, 7,10,10, 9,10,12,10,12,12, 7,10,10,
  131409. 9,12,11,10,12,12, 5, 8, 8, 8,10,10, 8,10,10, 7,
  131410. 10,10,10,12,12, 9,11,12, 7,10,10,10,12,12, 9,12,
  131411. 10,
  131412. };
  131413. static float _vq_quantthresh__8u1__p1_0[] = {
  131414. -0.5, 0.5,
  131415. };
  131416. static long _vq_quantmap__8u1__p1_0[] = {
  131417. 1, 0, 2,
  131418. };
  131419. static encode_aux_threshmatch _vq_auxt__8u1__p1_0 = {
  131420. _vq_quantthresh__8u1__p1_0,
  131421. _vq_quantmap__8u1__p1_0,
  131422. 3,
  131423. 3
  131424. };
  131425. static static_codebook _8u1__p1_0 = {
  131426. 4, 81,
  131427. _vq_lengthlist__8u1__p1_0,
  131428. 1, -535822336, 1611661312, 2, 0,
  131429. _vq_quantlist__8u1__p1_0,
  131430. NULL,
  131431. &_vq_auxt__8u1__p1_0,
  131432. NULL,
  131433. 0
  131434. };
  131435. static long _vq_quantlist__8u1__p2_0[] = {
  131436. 1,
  131437. 0,
  131438. 2,
  131439. };
  131440. static long _vq_lengthlist__8u1__p2_0[] = {
  131441. 3, 4, 5, 5, 6, 6, 5, 6, 6, 5, 7, 6, 6, 7, 8, 6,
  131442. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 7, 5, 6, 6, 7, 8,
  131443. 8, 6, 7, 7, 6, 8, 7, 7, 7, 9, 8, 9, 9, 6, 7, 8,
  131444. 7, 9, 7, 8, 9, 9, 5, 6, 6, 6, 7, 7, 7, 8, 8, 6,
  131445. 8, 7, 8, 9, 9, 7, 7, 9, 6, 7, 8, 8, 9, 9, 7, 9,
  131446. 7,
  131447. };
  131448. static float _vq_quantthresh__8u1__p2_0[] = {
  131449. -0.5, 0.5,
  131450. };
  131451. static long _vq_quantmap__8u1__p2_0[] = {
  131452. 1, 0, 2,
  131453. };
  131454. static encode_aux_threshmatch _vq_auxt__8u1__p2_0 = {
  131455. _vq_quantthresh__8u1__p2_0,
  131456. _vq_quantmap__8u1__p2_0,
  131457. 3,
  131458. 3
  131459. };
  131460. static static_codebook _8u1__p2_0 = {
  131461. 4, 81,
  131462. _vq_lengthlist__8u1__p2_0,
  131463. 1, -535822336, 1611661312, 2, 0,
  131464. _vq_quantlist__8u1__p2_0,
  131465. NULL,
  131466. &_vq_auxt__8u1__p2_0,
  131467. NULL,
  131468. 0
  131469. };
  131470. static long _vq_quantlist__8u1__p3_0[] = {
  131471. 2,
  131472. 1,
  131473. 3,
  131474. 0,
  131475. 4,
  131476. };
  131477. static long _vq_lengthlist__8u1__p3_0[] = {
  131478. 1, 5, 5, 7, 7, 6, 7, 7, 9, 9, 6, 7, 7, 9, 9, 8,
  131479. 10, 9,11,11, 9, 9, 9,11,11, 6, 8, 8,10,10, 8,10,
  131480. 10,11,11, 8, 9,10,11,11,10,11,11,12,12,10,11,11,
  131481. 12,13, 6, 8, 8,10,10, 8,10, 9,11,11, 8,10, 9,11,
  131482. 11,10,11,11,12,12,10,11,11,12,12, 9,11,11,14,13,
  131483. 10,12,11,14,14,10,12,11,14,13,12,13,13,15,14,12,
  131484. 13,13,15,14, 8,11,11,13,14,10,11,12,13,15,10,11,
  131485. 12,14,14,12,13,13,14,15,12,13,13,14,15, 5, 8, 8,
  131486. 11,11, 8,10,10,12,12, 8,10,10,12,12,11,12,12,14,
  131487. 13,11,12,12,13,14, 8,10,10,12,12, 9,11,12,13,14,
  131488. 10,12,12,13,13,12,12,13,14,14,11,13,13,15,15, 7,
  131489. 10,10,12,12, 9,12,11,14,12,10,11,12,13,14,12,13,
  131490. 12,14,14,12,13,13,15,16,10,12,12,15,14,11,12,13,
  131491. 15,15,11,13,13,15,16,14,14,15,15,16,13,14,15,17,
  131492. 15, 9,12,12,14,15,11,13,12,15,15,11,13,13,15,15,
  131493. 13,14,13,15,14,13,14,14,17, 0, 5, 8, 8,11,11, 8,
  131494. 10,10,12,12, 8,10,10,12,12,11,12,12,14,14,11,12,
  131495. 12,14,14, 7,10,10,12,12,10,12,12,13,13, 9,11,12,
  131496. 12,13,11,12,13,15,15,11,12,13,14,15, 8,10,10,12,
  131497. 12,10,12,11,13,13,10,12,11,13,13,11,13,13,15,14,
  131498. 12,13,12,15,13, 9,12,12,14,14,11,13,13,16,15,11,
  131499. 12,13,16,15,13,14,15,16,16,13,13,15,15,16,10,12,
  131500. 12,15,14,11,13,13,14,16,11,13,13,15,16,13,15,15,
  131501. 16,17,13,15,14,16,15, 8,11,11,14,15,10,12,12,15,
  131502. 15,10,12,12,15,16,14,15,15,16,17,13,14,14,16,16,
  131503. 9,12,12,15,15,11,13,14,15,17,11,13,13,15,16,14,
  131504. 15,16,19,17,13,15,15, 0,17, 9,12,12,15,15,11,14,
  131505. 13,16,15,11,13,13,15,16,15,15,15,18,17,13,15,15,
  131506. 17,17,11,15,14,18,16,12,14,15,17,17,12,15,15,18,
  131507. 18,15,15,16,15,19,14,16,16, 0, 0,11,14,14,16,17,
  131508. 12,15,14,18,17,12,15,15,18,18,15,17,15,18,16,14,
  131509. 16,16,18,18, 7,11,11,14,14,10,12,12,15,15,10,12,
  131510. 13,15,15,13,14,15,16,16,14,15,15,18,18, 9,12,12,
  131511. 15,15,11,13,13,16,15,11,12,13,16,16,14,15,15,17,
  131512. 16,15,16,16,17,17, 9,12,12,15,15,11,13,13,15,17,
  131513. 11,14,13,16,15,13,15,15,17,17,15,15,15,18,17,11,
  131514. 14,14,17,15,12,14,15,17,18,13,13,15,17,17,14,16,
  131515. 16,19,18,16,15,17,17, 0,11,14,14,17,17,12,15,15,
  131516. 18, 0,12,15,14,18,16,14,17,17,19, 0,16,18,15, 0,
  131517. 16,
  131518. };
  131519. static float _vq_quantthresh__8u1__p3_0[] = {
  131520. -1.5, -0.5, 0.5, 1.5,
  131521. };
  131522. static long _vq_quantmap__8u1__p3_0[] = {
  131523. 3, 1, 0, 2, 4,
  131524. };
  131525. static encode_aux_threshmatch _vq_auxt__8u1__p3_0 = {
  131526. _vq_quantthresh__8u1__p3_0,
  131527. _vq_quantmap__8u1__p3_0,
  131528. 5,
  131529. 5
  131530. };
  131531. static static_codebook _8u1__p3_0 = {
  131532. 4, 625,
  131533. _vq_lengthlist__8u1__p3_0,
  131534. 1, -533725184, 1611661312, 3, 0,
  131535. _vq_quantlist__8u1__p3_0,
  131536. NULL,
  131537. &_vq_auxt__8u1__p3_0,
  131538. NULL,
  131539. 0
  131540. };
  131541. static long _vq_quantlist__8u1__p4_0[] = {
  131542. 2,
  131543. 1,
  131544. 3,
  131545. 0,
  131546. 4,
  131547. };
  131548. static long _vq_lengthlist__8u1__p4_0[] = {
  131549. 4, 5, 5, 9, 9, 6, 7, 7, 9, 9, 6, 7, 7, 9, 9, 9,
  131550. 9, 9,11,11, 9, 9, 9,11,11, 6, 7, 7, 9, 9, 7, 7,
  131551. 8, 9,10, 7, 7, 8, 9,10, 9, 9,10,10,11, 9, 9,10,
  131552. 10,12, 6, 7, 7, 9, 9, 7, 8, 7,10, 9, 7, 8, 7,10,
  131553. 9, 9,10, 9,12,11,10,10, 9,12,10, 9,10,10,12,11,
  131554. 9,10,10,12,11, 9,10,10,12,12,11,11,12,12,13,11,
  131555. 11,12,12,13, 9, 9,10,12,11, 9,10,10,12,12,10,10,
  131556. 10,12,12,11,12,11,13,12,11,12,11,13,12, 6, 7, 7,
  131557. 9, 9, 7, 8, 8,10,10, 7, 8, 7,10, 9,10,10,10,12,
  131558. 12,10,10,10,12,11, 7, 8, 7,10,10, 7, 7, 9,10,11,
  131559. 8, 9, 9,11,10,10,10,11,10,12,10,10,11,12,12, 7,
  131560. 8, 8,10,10, 7, 9, 8,11,10, 8, 8, 9,11,11,10,11,
  131561. 10,12,11,10,11,11,12,12, 9,10,10,12,12, 9,10,10,
  131562. 12,12,10,11,11,13,12,11,10,12,10,14,12,12,12,13,
  131563. 14, 9,10,10,12,12, 9,11,10,12,12,10,11,11,12,12,
  131564. 11,12,11,14,12,12,12,12,14,14, 5, 7, 7, 9, 9, 7,
  131565. 7, 7, 9,10, 7, 8, 8,10,10,10,10,10,11,11,10,10,
  131566. 10,12,12, 7, 8, 8,10,10, 8, 9, 8,11,10, 7, 8, 9,
  131567. 10,11,10,10,10,11,12,10,10,11,11,13, 6, 7, 8,10,
  131568. 10, 8, 9, 9,10,10, 7, 9, 7,11,10,10,11,10,12,12,
  131569. 10,11,10,12,10, 9,10,10,12,12,10,11,11,13,12, 9,
  131570. 10,10,12,12,12,12,12,14,13,11,11,12,11,14, 9,10,
  131571. 10,11,12,10,11,11,12,13, 9,10,10,12,12,12,12,12,
  131572. 14,13,11,12,10,14,11, 9, 9,10,11,12, 9,10,10,12,
  131573. 12, 9,10,10,12,12,12,12,12,14,14,11,12,12,13,12,
  131574. 9,10, 9,12,12, 9,10,11,12,13,10,11,10,13,11,12,
  131575. 12,13,13,14,12,12,12,13,13, 9,10,10,12,12,10,11,
  131576. 10,13,12,10,10,11,12,13,12,13,12,14,13,12,12,12,
  131577. 13,14,11,12,11,14,13,10,10,11,13,13,12,12,12,14,
  131578. 13,12,10,14,10,15,13,14,14,14,14,11,11,12,13,14,
  131579. 10,12,11,13,13,12,12,12,13,15,12,13,11,15,12,13,
  131580. 13,14,14,14, 9,10, 9,12,12, 9,10,10,12,12,10,10,
  131581. 10,12,12,11,11,12,12,13,12,12,12,14,14, 9,10,10,
  131582. 12,12,10,11,10,13,12,10,10,11,12,13,12,12,12,14,
  131583. 13,12,12,13,13,14, 9,10,10,12,13,10,10,11,11,12,
  131584. 9,11,10,13,12,12,12,12,13,14,12,13,12,14,13,11,
  131585. 12,11,13,13,12,13,12,14,13,10,11,12,13,13,13,13,
  131586. 13,14,15,12,11,14,12,14,11,11,12,12,13,12,12,12,
  131587. 13,14,10,12,10,14,13,13,13,13,14,15,12,14,11,15,
  131588. 10,
  131589. };
  131590. static float _vq_quantthresh__8u1__p4_0[] = {
  131591. -1.5, -0.5, 0.5, 1.5,
  131592. };
  131593. static long _vq_quantmap__8u1__p4_0[] = {
  131594. 3, 1, 0, 2, 4,
  131595. };
  131596. static encode_aux_threshmatch _vq_auxt__8u1__p4_0 = {
  131597. _vq_quantthresh__8u1__p4_0,
  131598. _vq_quantmap__8u1__p4_0,
  131599. 5,
  131600. 5
  131601. };
  131602. static static_codebook _8u1__p4_0 = {
  131603. 4, 625,
  131604. _vq_lengthlist__8u1__p4_0,
  131605. 1, -533725184, 1611661312, 3, 0,
  131606. _vq_quantlist__8u1__p4_0,
  131607. NULL,
  131608. &_vq_auxt__8u1__p4_0,
  131609. NULL,
  131610. 0
  131611. };
  131612. static long _vq_quantlist__8u1__p5_0[] = {
  131613. 4,
  131614. 3,
  131615. 5,
  131616. 2,
  131617. 6,
  131618. 1,
  131619. 7,
  131620. 0,
  131621. 8,
  131622. };
  131623. static long _vq_lengthlist__8u1__p5_0[] = {
  131624. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 5, 8, 7, 8, 8,
  131625. 10,10, 4, 6, 6, 8, 8, 8, 8,10,10, 7, 8, 8, 9, 9,
  131626. 9, 9,11,11, 7, 8, 8, 9, 9, 9, 9,11,11, 8, 8, 8,
  131627. 9, 9,10,10,12,11, 8, 8, 8, 9, 9,10,10,11,11, 9,
  131628. 10,10,11,11,11,11,13,12, 9,10,10,11,11,12,12,12,
  131629. 13,
  131630. };
  131631. static float _vq_quantthresh__8u1__p5_0[] = {
  131632. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  131633. };
  131634. static long _vq_quantmap__8u1__p5_0[] = {
  131635. 7, 5, 3, 1, 0, 2, 4, 6,
  131636. 8,
  131637. };
  131638. static encode_aux_threshmatch _vq_auxt__8u1__p5_0 = {
  131639. _vq_quantthresh__8u1__p5_0,
  131640. _vq_quantmap__8u1__p5_0,
  131641. 9,
  131642. 9
  131643. };
  131644. static static_codebook _8u1__p5_0 = {
  131645. 2, 81,
  131646. _vq_lengthlist__8u1__p5_0,
  131647. 1, -531628032, 1611661312, 4, 0,
  131648. _vq_quantlist__8u1__p5_0,
  131649. NULL,
  131650. &_vq_auxt__8u1__p5_0,
  131651. NULL,
  131652. 0
  131653. };
  131654. static long _vq_quantlist__8u1__p6_0[] = {
  131655. 4,
  131656. 3,
  131657. 5,
  131658. 2,
  131659. 6,
  131660. 1,
  131661. 7,
  131662. 0,
  131663. 8,
  131664. };
  131665. static long _vq_lengthlist__8u1__p6_0[] = {
  131666. 3, 4, 4, 6, 6, 7, 7, 9, 9, 4, 4, 5, 6, 6, 7, 7,
  131667. 9, 9, 4, 4, 4, 6, 6, 7, 7, 9, 9, 6, 6, 6, 7, 7,
  131668. 8, 8, 9, 9, 6, 6, 6, 7, 7, 8, 8, 9, 9, 7, 7, 7,
  131669. 8, 8, 8, 9,10,10, 7, 7, 7, 8, 8, 9, 8,10,10, 9,
  131670. 9, 9, 9, 9,10,10,10,10, 9, 9, 9, 9, 9,10,10,10,
  131671. 10,
  131672. };
  131673. static float _vq_quantthresh__8u1__p6_0[] = {
  131674. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  131675. };
  131676. static long _vq_quantmap__8u1__p6_0[] = {
  131677. 7, 5, 3, 1, 0, 2, 4, 6,
  131678. 8,
  131679. };
  131680. static encode_aux_threshmatch _vq_auxt__8u1__p6_0 = {
  131681. _vq_quantthresh__8u1__p6_0,
  131682. _vq_quantmap__8u1__p6_0,
  131683. 9,
  131684. 9
  131685. };
  131686. static static_codebook _8u1__p6_0 = {
  131687. 2, 81,
  131688. _vq_lengthlist__8u1__p6_0,
  131689. 1, -531628032, 1611661312, 4, 0,
  131690. _vq_quantlist__8u1__p6_0,
  131691. NULL,
  131692. &_vq_auxt__8u1__p6_0,
  131693. NULL,
  131694. 0
  131695. };
  131696. static long _vq_quantlist__8u1__p7_0[] = {
  131697. 1,
  131698. 0,
  131699. 2,
  131700. };
  131701. static long _vq_lengthlist__8u1__p7_0[] = {
  131702. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 9, 8,10,10, 8,
  131703. 10,10, 5, 9, 9, 7,10,10, 8,10,10, 4,10,10, 9,12,
  131704. 12, 9,11,11, 7,12,11,10,11,13,10,13,13, 7,12,12,
  131705. 10,13,12,10,13,13, 4,10,10, 9,12,12, 9,12,12, 7,
  131706. 12,12,10,13,13,10,12,13, 7,11,12,10,13,13,10,13,
  131707. 11,
  131708. };
  131709. static float _vq_quantthresh__8u1__p7_0[] = {
  131710. -5.5, 5.5,
  131711. };
  131712. static long _vq_quantmap__8u1__p7_0[] = {
  131713. 1, 0, 2,
  131714. };
  131715. static encode_aux_threshmatch _vq_auxt__8u1__p7_0 = {
  131716. _vq_quantthresh__8u1__p7_0,
  131717. _vq_quantmap__8u1__p7_0,
  131718. 3,
  131719. 3
  131720. };
  131721. static static_codebook _8u1__p7_0 = {
  131722. 4, 81,
  131723. _vq_lengthlist__8u1__p7_0,
  131724. 1, -529137664, 1618345984, 2, 0,
  131725. _vq_quantlist__8u1__p7_0,
  131726. NULL,
  131727. &_vq_auxt__8u1__p7_0,
  131728. NULL,
  131729. 0
  131730. };
  131731. static long _vq_quantlist__8u1__p7_1[] = {
  131732. 5,
  131733. 4,
  131734. 6,
  131735. 3,
  131736. 7,
  131737. 2,
  131738. 8,
  131739. 1,
  131740. 9,
  131741. 0,
  131742. 10,
  131743. };
  131744. static long _vq_lengthlist__8u1__p7_1[] = {
  131745. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 5, 5, 7, 7,
  131746. 8, 8, 9, 9, 9, 9, 4, 5, 5, 7, 7, 8, 8, 9, 9, 9,
  131747. 9, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 6, 7, 7, 8,
  131748. 8, 8, 8, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9,
  131749. 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 9, 9,
  131750. 9, 9, 9, 9,10,10,10,10, 8, 9, 9, 9, 9, 9, 9,10,
  131751. 10,10,10, 8, 9, 9, 9, 9, 9, 9,10,10,10,10, 8, 9,
  131752. 9, 9, 9, 9, 9,10,10,10,10,
  131753. };
  131754. static float _vq_quantthresh__8u1__p7_1[] = {
  131755. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  131756. 3.5, 4.5,
  131757. };
  131758. static long _vq_quantmap__8u1__p7_1[] = {
  131759. 9, 7, 5, 3, 1, 0, 2, 4,
  131760. 6, 8, 10,
  131761. };
  131762. static encode_aux_threshmatch _vq_auxt__8u1__p7_1 = {
  131763. _vq_quantthresh__8u1__p7_1,
  131764. _vq_quantmap__8u1__p7_1,
  131765. 11,
  131766. 11
  131767. };
  131768. static static_codebook _8u1__p7_1 = {
  131769. 2, 121,
  131770. _vq_lengthlist__8u1__p7_1,
  131771. 1, -531365888, 1611661312, 4, 0,
  131772. _vq_quantlist__8u1__p7_1,
  131773. NULL,
  131774. &_vq_auxt__8u1__p7_1,
  131775. NULL,
  131776. 0
  131777. };
  131778. static long _vq_quantlist__8u1__p8_0[] = {
  131779. 5,
  131780. 4,
  131781. 6,
  131782. 3,
  131783. 7,
  131784. 2,
  131785. 8,
  131786. 1,
  131787. 9,
  131788. 0,
  131789. 10,
  131790. };
  131791. static long _vq_lengthlist__8u1__p8_0[] = {
  131792. 1, 4, 4, 6, 6, 8, 8,10,10,11,11, 4, 6, 6, 7, 7,
  131793. 9, 9,11,11,13,12, 4, 6, 6, 7, 7, 9, 9,11,11,12,
  131794. 12, 6, 7, 7, 9, 9,11,11,12,12,13,13, 6, 7, 7, 9,
  131795. 9,11,11,12,12,13,13, 8, 9, 9,11,11,12,12,13,13,
  131796. 14,14, 8, 9, 9,11,11,12,12,13,13,14,14, 9,11,11,
  131797. 12,12,13,13,14,14,15,15, 9,11,11,12,12,13,13,14,
  131798. 14,15,14,11,12,12,13,13,14,14,15,15,16,16,11,12,
  131799. 12,13,13,14,14,15,15,15,15,
  131800. };
  131801. static float _vq_quantthresh__8u1__p8_0[] = {
  131802. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  131803. 38.5, 49.5,
  131804. };
  131805. static long _vq_quantmap__8u1__p8_0[] = {
  131806. 9, 7, 5, 3, 1, 0, 2, 4,
  131807. 6, 8, 10,
  131808. };
  131809. static encode_aux_threshmatch _vq_auxt__8u1__p8_0 = {
  131810. _vq_quantthresh__8u1__p8_0,
  131811. _vq_quantmap__8u1__p8_0,
  131812. 11,
  131813. 11
  131814. };
  131815. static static_codebook _8u1__p8_0 = {
  131816. 2, 121,
  131817. _vq_lengthlist__8u1__p8_0,
  131818. 1, -524582912, 1618345984, 4, 0,
  131819. _vq_quantlist__8u1__p8_0,
  131820. NULL,
  131821. &_vq_auxt__8u1__p8_0,
  131822. NULL,
  131823. 0
  131824. };
  131825. static long _vq_quantlist__8u1__p8_1[] = {
  131826. 5,
  131827. 4,
  131828. 6,
  131829. 3,
  131830. 7,
  131831. 2,
  131832. 8,
  131833. 1,
  131834. 9,
  131835. 0,
  131836. 10,
  131837. };
  131838. static long _vq_lengthlist__8u1__p8_1[] = {
  131839. 2, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 5, 6, 6, 7, 7,
  131840. 7, 7, 8, 8, 8, 8, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8,
  131841. 8, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 6, 7, 7, 7,
  131842. 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8,
  131843. 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  131844. 8, 8, 8, 8, 9, 8, 9, 9, 7, 8, 8, 8, 8, 8, 8, 9,
  131845. 8, 9, 9, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 8, 8,
  131846. 8, 8, 8, 8, 8, 9, 9, 9, 9,
  131847. };
  131848. static float _vq_quantthresh__8u1__p8_1[] = {
  131849. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  131850. 3.5, 4.5,
  131851. };
  131852. static long _vq_quantmap__8u1__p8_1[] = {
  131853. 9, 7, 5, 3, 1, 0, 2, 4,
  131854. 6, 8, 10,
  131855. };
  131856. static encode_aux_threshmatch _vq_auxt__8u1__p8_1 = {
  131857. _vq_quantthresh__8u1__p8_1,
  131858. _vq_quantmap__8u1__p8_1,
  131859. 11,
  131860. 11
  131861. };
  131862. static static_codebook _8u1__p8_1 = {
  131863. 2, 121,
  131864. _vq_lengthlist__8u1__p8_1,
  131865. 1, -531365888, 1611661312, 4, 0,
  131866. _vq_quantlist__8u1__p8_1,
  131867. NULL,
  131868. &_vq_auxt__8u1__p8_1,
  131869. NULL,
  131870. 0
  131871. };
  131872. static long _vq_quantlist__8u1__p9_0[] = {
  131873. 7,
  131874. 6,
  131875. 8,
  131876. 5,
  131877. 9,
  131878. 4,
  131879. 10,
  131880. 3,
  131881. 11,
  131882. 2,
  131883. 12,
  131884. 1,
  131885. 13,
  131886. 0,
  131887. 14,
  131888. };
  131889. static long _vq_lengthlist__8u1__p9_0[] = {
  131890. 1, 4, 4,11,11,11,11,11,11,11,11,11,11,11,11, 3,
  131891. 11, 8,11,11,11,11,11,11,11,11,11,11,11,11, 3, 9,
  131892. 9,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131893. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131894. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131895. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131896. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131897. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131898. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131899. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131900. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131901. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131902. 11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,
  131903. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131904. 10,
  131905. };
  131906. static float _vq_quantthresh__8u1__p9_0[] = {
  131907. -1657.5, -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5,
  131908. 382.5, 637.5, 892.5, 1147.5, 1402.5, 1657.5,
  131909. };
  131910. static long _vq_quantmap__8u1__p9_0[] = {
  131911. 13, 11, 9, 7, 5, 3, 1, 0,
  131912. 2, 4, 6, 8, 10, 12, 14,
  131913. };
  131914. static encode_aux_threshmatch _vq_auxt__8u1__p9_0 = {
  131915. _vq_quantthresh__8u1__p9_0,
  131916. _vq_quantmap__8u1__p9_0,
  131917. 15,
  131918. 15
  131919. };
  131920. static static_codebook _8u1__p9_0 = {
  131921. 2, 225,
  131922. _vq_lengthlist__8u1__p9_0,
  131923. 1, -514071552, 1627381760, 4, 0,
  131924. _vq_quantlist__8u1__p9_0,
  131925. NULL,
  131926. &_vq_auxt__8u1__p9_0,
  131927. NULL,
  131928. 0
  131929. };
  131930. static long _vq_quantlist__8u1__p9_1[] = {
  131931. 7,
  131932. 6,
  131933. 8,
  131934. 5,
  131935. 9,
  131936. 4,
  131937. 10,
  131938. 3,
  131939. 11,
  131940. 2,
  131941. 12,
  131942. 1,
  131943. 13,
  131944. 0,
  131945. 14,
  131946. };
  131947. static long _vq_lengthlist__8u1__p9_1[] = {
  131948. 1, 4, 4, 7, 7, 9, 9, 7, 7, 8, 8,10,10,11,11, 4,
  131949. 7, 7, 9, 9,10,10, 8, 8,10,10,10,11,10,11, 4, 7,
  131950. 7, 9, 9,10,10, 8, 8,10, 9,11,11,11,11, 7, 9, 9,
  131951. 12,12,11,12,10,10,11,10,12,11,11,11, 7, 9, 9,11,
  131952. 11,13,12, 9, 9,11,10,11,11,12,11, 9,10,10,12,12,
  131953. 14,14,10,10,11,12,12,11,11,11, 9,10,11,11,13,14,
  131954. 13,10,11,11,11,12,11,12,12, 7, 8, 8,10, 9,11,10,
  131955. 11,12,12,11,12,14,12,13, 7, 8, 8, 9,10,10,11,12,
  131956. 12,12,11,12,12,12,13, 9, 9, 9,11,11,13,12,12,12,
  131957. 12,11,12,12,13,12, 8,10,10,11,10,11,12,12,12,12,
  131958. 12,12,14,12,12, 9,11,11,11,12,12,12,12,13,13,12,
  131959. 12,13,13,12,10,11,11,12,11,12,12,12,11,12,13,12,
  131960. 12,12,13,11,11,12,12,12,13,12,12,11,12,13,13,12,
  131961. 12,13,12,11,12,12,13,13,12,13,12,13,13,13,13,14,
  131962. 13,
  131963. };
  131964. static float _vq_quantthresh__8u1__p9_1[] = {
  131965. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  131966. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  131967. };
  131968. static long _vq_quantmap__8u1__p9_1[] = {
  131969. 13, 11, 9, 7, 5, 3, 1, 0,
  131970. 2, 4, 6, 8, 10, 12, 14,
  131971. };
  131972. static encode_aux_threshmatch _vq_auxt__8u1__p9_1 = {
  131973. _vq_quantthresh__8u1__p9_1,
  131974. _vq_quantmap__8u1__p9_1,
  131975. 15,
  131976. 15
  131977. };
  131978. static static_codebook _8u1__p9_1 = {
  131979. 2, 225,
  131980. _vq_lengthlist__8u1__p9_1,
  131981. 1, -522338304, 1620115456, 4, 0,
  131982. _vq_quantlist__8u1__p9_1,
  131983. NULL,
  131984. &_vq_auxt__8u1__p9_1,
  131985. NULL,
  131986. 0
  131987. };
  131988. static long _vq_quantlist__8u1__p9_2[] = {
  131989. 8,
  131990. 7,
  131991. 9,
  131992. 6,
  131993. 10,
  131994. 5,
  131995. 11,
  131996. 4,
  131997. 12,
  131998. 3,
  131999. 13,
  132000. 2,
  132001. 14,
  132002. 1,
  132003. 15,
  132004. 0,
  132005. 16,
  132006. };
  132007. static long _vq_lengthlist__8u1__p9_2[] = {
  132008. 2, 5, 4, 6, 6, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  132009. 9, 5, 6, 6, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9,
  132010. 9, 9, 5, 6, 6, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  132011. 9, 9, 9, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9,
  132012. 9,10,10, 9, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  132013. 9, 9, 9,10,10, 8, 8, 8, 9, 9, 9, 9,10,10,10, 9,
  132014. 10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  132015. 10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9,10,
  132016. 10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,10,10,
  132017. 10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9,10,
  132018. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,
  132019. 10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,10,
  132020. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  132021. 9,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  132022. 10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,10,
  132023. 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  132024. 10, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132025. 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132026. 10,
  132027. };
  132028. static float _vq_quantthresh__8u1__p9_2[] = {
  132029. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  132030. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  132031. };
  132032. static long _vq_quantmap__8u1__p9_2[] = {
  132033. 15, 13, 11, 9, 7, 5, 3, 1,
  132034. 0, 2, 4, 6, 8, 10, 12, 14,
  132035. 16,
  132036. };
  132037. static encode_aux_threshmatch _vq_auxt__8u1__p9_2 = {
  132038. _vq_quantthresh__8u1__p9_2,
  132039. _vq_quantmap__8u1__p9_2,
  132040. 17,
  132041. 17
  132042. };
  132043. static static_codebook _8u1__p9_2 = {
  132044. 2, 289,
  132045. _vq_lengthlist__8u1__p9_2,
  132046. 1, -529530880, 1611661312, 5, 0,
  132047. _vq_quantlist__8u1__p9_2,
  132048. NULL,
  132049. &_vq_auxt__8u1__p9_2,
  132050. NULL,
  132051. 0
  132052. };
  132053. static long _huff_lengthlist__8u1__single[] = {
  132054. 4, 7,13, 9,15, 9,16, 8,10,13, 7, 5, 8, 6, 9, 7,
  132055. 10, 7,10,11,11, 6, 7, 8, 8, 9, 9, 9,12,16, 8, 5,
  132056. 8, 6, 8, 6, 9, 7,10,12,11, 7, 7, 7, 6, 7, 7, 7,
  132057. 11,15, 7, 5, 8, 6, 7, 5, 7, 6, 9,13,13, 9, 9, 8,
  132058. 6, 6, 5, 5, 9,14, 8, 6, 8, 6, 6, 4, 5, 3, 5,13,
  132059. 9, 9,11, 8,10, 7, 8, 4, 5,12,11,16,17,15,17,12,
  132060. 13, 8, 8,15,
  132061. };
  132062. static static_codebook _huff_book__8u1__single = {
  132063. 2, 100,
  132064. _huff_lengthlist__8u1__single,
  132065. 0, 0, 0, 0, 0,
  132066. NULL,
  132067. NULL,
  132068. NULL,
  132069. NULL,
  132070. 0
  132071. };
  132072. static long _huff_lengthlist__44u0__long[] = {
  132073. 5, 8,13,10,17,11,11,15, 7, 2, 4, 5, 8, 7, 9,16,
  132074. 13, 4, 3, 5, 6, 8,11,20,10, 4, 5, 5, 7, 6, 8,18,
  132075. 15, 7, 6, 7, 8,10,14,20,10, 6, 7, 6, 9, 7, 8,17,
  132076. 9, 8,10, 8,10, 5, 4,11,12,17,19,14,16,10, 7,12,
  132077. };
  132078. static static_codebook _huff_book__44u0__long = {
  132079. 2, 64,
  132080. _huff_lengthlist__44u0__long,
  132081. 0, 0, 0, 0, 0,
  132082. NULL,
  132083. NULL,
  132084. NULL,
  132085. NULL,
  132086. 0
  132087. };
  132088. static long _vq_quantlist__44u0__p1_0[] = {
  132089. 1,
  132090. 0,
  132091. 2,
  132092. };
  132093. static long _vq_lengthlist__44u0__p1_0[] = {
  132094. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,11,11, 8,
  132095. 10,10, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  132096. 11, 8,11,11, 8,12,11,11,13,13,11,13,14, 7,11,11,
  132097. 10,13,12,11,13,14, 4, 8, 8, 8,11,11, 8,11,12, 8,
  132098. 11,11,11,13,13,10,12,13, 8,11,11,11,14,13,11,14,
  132099. 13,
  132100. };
  132101. static float _vq_quantthresh__44u0__p1_0[] = {
  132102. -0.5, 0.5,
  132103. };
  132104. static long _vq_quantmap__44u0__p1_0[] = {
  132105. 1, 0, 2,
  132106. };
  132107. static encode_aux_threshmatch _vq_auxt__44u0__p1_0 = {
  132108. _vq_quantthresh__44u0__p1_0,
  132109. _vq_quantmap__44u0__p1_0,
  132110. 3,
  132111. 3
  132112. };
  132113. static static_codebook _44u0__p1_0 = {
  132114. 4, 81,
  132115. _vq_lengthlist__44u0__p1_0,
  132116. 1, -535822336, 1611661312, 2, 0,
  132117. _vq_quantlist__44u0__p1_0,
  132118. NULL,
  132119. &_vq_auxt__44u0__p1_0,
  132120. NULL,
  132121. 0
  132122. };
  132123. static long _vq_quantlist__44u0__p2_0[] = {
  132124. 1,
  132125. 0,
  132126. 2,
  132127. };
  132128. static long _vq_lengthlist__44u0__p2_0[] = {
  132129. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 7, 8, 8, 6,
  132130. 8, 8, 5, 7, 7, 6, 8, 8, 7, 8, 8, 4, 7, 7, 7, 8,
  132131. 8, 7, 8, 8, 7, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  132132. 8,10, 8, 8,10,10, 5, 7, 7, 7, 8, 8, 7, 8, 8, 6,
  132133. 8, 8, 8,10,10, 8, 8,10, 6, 8, 8, 8,10,10, 8,10,
  132134. 9,
  132135. };
  132136. static float _vq_quantthresh__44u0__p2_0[] = {
  132137. -0.5, 0.5,
  132138. };
  132139. static long _vq_quantmap__44u0__p2_0[] = {
  132140. 1, 0, 2,
  132141. };
  132142. static encode_aux_threshmatch _vq_auxt__44u0__p2_0 = {
  132143. _vq_quantthresh__44u0__p2_0,
  132144. _vq_quantmap__44u0__p2_0,
  132145. 3,
  132146. 3
  132147. };
  132148. static static_codebook _44u0__p2_0 = {
  132149. 4, 81,
  132150. _vq_lengthlist__44u0__p2_0,
  132151. 1, -535822336, 1611661312, 2, 0,
  132152. _vq_quantlist__44u0__p2_0,
  132153. NULL,
  132154. &_vq_auxt__44u0__p2_0,
  132155. NULL,
  132156. 0
  132157. };
  132158. static long _vq_quantlist__44u0__p3_0[] = {
  132159. 2,
  132160. 1,
  132161. 3,
  132162. 0,
  132163. 4,
  132164. };
  132165. static long _vq_lengthlist__44u0__p3_0[] = {
  132166. 1, 5, 5, 8, 8, 5, 8, 7, 9, 9, 5, 7, 8, 9, 9, 9,
  132167. 10, 9,12,12, 9, 9,10,12,12, 6, 8, 8,11,10, 8,10,
  132168. 10,11,11, 8, 9,10,11,11,10,11,11,14,13,10,11,11,
  132169. 13,13, 5, 8, 8,10,10, 8,10,10,11,11, 8,10,10,11,
  132170. 11,10,11,11,13,13,10,11,11,13,13, 9,11,11,15,14,
  132171. 10,12,12,15,14,10,12,11,15,14,13,14,14,16,16,12,
  132172. 14,13,17,15, 9,11,11,14,15,10,11,12,14,16,10,11,
  132173. 12,14,16,12,13,14,16,16,13,13,15,15,18, 5, 8, 8,
  132174. 11,11, 8,10,10,12,12, 8,10,10,12,13,11,12,12,14,
  132175. 14,11,12,12,15,15, 8,10,10,13,13,10,12,12,13,13,
  132176. 10,12,12,14,14,12,13,13,15,15,12,13,13,16,16, 7,
  132177. 10,10,12,12,10,12,11,13,13,10,12,12,13,14,12,13,
  132178. 12,15,14,12,13,13,16,16,10,12,12,17,16,12,13,13,
  132179. 16,15,11,13,13,17,17,15,15,15,16,17,14,15,15,19,
  132180. 19,10,12,12,15,16,11,13,12,15,18,11,13,13,16,16,
  132181. 14,15,15,17,17,14,15,15,17,19, 5, 8, 8,11,11, 8,
  132182. 10,10,12,12, 8,10,10,12,12,11,12,12,16,15,11,12,
  132183. 12,14,15, 7,10,10,13,13,10,12,12,14,13,10,11,12,
  132184. 13,13,12,13,13,16,16,12,12,13,15,15, 8,10,10,13,
  132185. 13,10,12,12,14,14,10,12,12,13,13,12,13,13,16,16,
  132186. 12,13,13,15,15,10,12,12,16,15,11,13,13,17,16,11,
  132187. 12,13,16,15,13,15,15,19,17,14,15,14,17,16,10,12,
  132188. 12,16,16,11,13,13,16,17,12,13,13,15,17,14,15,15,
  132189. 17,19,14,15,15,17,17, 8,11,11,16,16,10,13,12,17,
  132190. 17,10,12,13,16,16,15,17,16,20,19,14,15,17,18,19,
  132191. 9,12,12,16,17,11,13,14,17,18,11,13,13,19,18,16,
  132192. 17,18,19,19,15,16,16,19,19, 9,12,12,16,17,11,14,
  132193. 13,18,17,11,13,13,17,17,16,17,16,20,19,14,16,16,
  132194. 18,18,12,15,15,19,17,14,15,16, 0,20,13,15,16,20,
  132195. 17,18,16,20, 0, 0,15,16,19,20, 0,12,15,14,18,19,
  132196. 13,16,15,20,19,13,16,15,20,18,17,18,17, 0,20,16,
  132197. 17,16, 0, 0, 8,11,11,16,15,10,12,12,17,17,10,13,
  132198. 13,17,16,14,16,15,18,20,15,16,16,19,19, 9,12,12,
  132199. 16,16,11,13,13,17,16,11,13,14,17,18,15,15,16,20,
  132200. 20,16,16,17,19,19, 9,13,12,16,17,11,14,13,17,17,
  132201. 11,14,14,18,17,14,16,15,18,19,16,17,18,18,19,12,
  132202. 14,15,19,18,13,15,16,18, 0,13,14,15, 0, 0,16,16,
  132203. 17,20, 0,17,17,20,20, 0,12,15,15,19,20,13,15,15,
  132204. 0, 0,14,16,15, 0, 0,15,18,16, 0, 0,17,18,16, 0,
  132205. 19,
  132206. };
  132207. static float _vq_quantthresh__44u0__p3_0[] = {
  132208. -1.5, -0.5, 0.5, 1.5,
  132209. };
  132210. static long _vq_quantmap__44u0__p3_0[] = {
  132211. 3, 1, 0, 2, 4,
  132212. };
  132213. static encode_aux_threshmatch _vq_auxt__44u0__p3_0 = {
  132214. _vq_quantthresh__44u0__p3_0,
  132215. _vq_quantmap__44u0__p3_0,
  132216. 5,
  132217. 5
  132218. };
  132219. static static_codebook _44u0__p3_0 = {
  132220. 4, 625,
  132221. _vq_lengthlist__44u0__p3_0,
  132222. 1, -533725184, 1611661312, 3, 0,
  132223. _vq_quantlist__44u0__p3_0,
  132224. NULL,
  132225. &_vq_auxt__44u0__p3_0,
  132226. NULL,
  132227. 0
  132228. };
  132229. static long _vq_quantlist__44u0__p4_0[] = {
  132230. 2,
  132231. 1,
  132232. 3,
  132233. 0,
  132234. 4,
  132235. };
  132236. static long _vq_lengthlist__44u0__p4_0[] = {
  132237. 4, 5, 5, 9, 9, 5, 6, 6, 9, 9, 5, 6, 6, 9, 9, 9,
  132238. 10, 9,12,12, 9, 9,10,12,12, 5, 7, 7,10,10, 7, 7,
  132239. 8,10,10, 6, 7, 8,10,10,10,10,10,11,13,10, 9,10,
  132240. 12,13, 5, 7, 7,10,10, 6, 8, 7,10,10, 7, 8, 7,10,
  132241. 10, 9,10,10,12,12,10,10,10,13,11, 9,10,10,13,13,
  132242. 10,11,10,13,13,10,10,10,13,13,12,12,13,14,14,12,
  132243. 12,13,14,14, 9,10,10,13,13,10,10,10,13,13,10,10,
  132244. 10,13,13,12,13,12,15,14,12,13,12,15,15, 5, 7, 6,
  132245. 10,10, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,10,13,
  132246. 13,10,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,10,11,
  132247. 8, 9, 9,11,11,11,10,11,11,14,11,11,11,13,13, 6,
  132248. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  132249. 10,14,11,10,11,11,13,13,10,11,11,14,13,10,10,11,
  132250. 14,13,10,11,11,14,14,12,11,13,12,16,13,14,14,15,
  132251. 15,10,10,11,13,14,10,11,10,14,13,10,11,11,14,14,
  132252. 12,13,12,15,13,13,13,14,15,16, 5, 7, 7,10,10, 7,
  132253. 8, 8,10,10, 7, 8, 8,10,10,10,10,10,13,13,10,10,
  132254. 11,12,13, 6, 8, 8,11,10, 8, 9, 9,11,11, 7, 8, 9,
  132255. 10,11,10,11,11,13,13,10,10,11,11,13, 6, 8, 8,10,
  132256. 11, 8, 9, 9,11,11, 8, 9, 8,12,10,10,11,11,13,13,
  132257. 10,11,10,14,11,10,10,10,14,13,10,11,11,14,13,10,
  132258. 10,11,13,13,12,14,14,16,16,12,12,13,13,15,10,11,
  132259. 11,13,14,10,11,11,14,15,10,11,10,13,13,13,14,13,
  132260. 16,16,12,13,11,15,12, 9,10,10,13,13,10,11,11,14,
  132261. 13,10,10,11,13,14,13,14,13,16,16,13,13,13,15,16,
  132262. 9,10,10,13,13,10,10,11,13,14,10,11,11,15,13,13,
  132263. 13,14,14,18,13,13,14,16,15, 9,10,10,13,14,10,11,
  132264. 10,14,13,10,11,11,13,14,13,14,13,16,15,13,13,14,
  132265. 15,16,12,13,12,16,14,11,11,13,15,15,13,14,13,16,
  132266. 15,15,12,16,12,17,14,15,15,17,17,12,13,13,14,16,
  132267. 11,13,11,16,15,12,13,14,15,16,14,15,13, 0,14,14,
  132268. 16,16, 0, 0, 9,10,10,13,13,10,11,10,14,14,10,11,
  132269. 11,13,13,12,13,13,14,16,13,14,14,16,16, 9,10,10,
  132270. 14,14,11,11,11,14,13,10,10,11,14,14,13,13,13,16,
  132271. 16,13,13,14,14,17, 9,10,10,13,14,10,11,11,13,15,
  132272. 10,11,10,14,14,13,13,13,14,17,13,14,13,17,14,12,
  132273. 13,13,16,14,13,14,13,16,15,12,12,13,15,16,15,15,
  132274. 16,18,16,15,13,15,14, 0,12,12,13,14,16,13,13,14,
  132275. 15,16,11,12,11,16,14,15,16,16,17,17,14,15,12,17,
  132276. 12,
  132277. };
  132278. static float _vq_quantthresh__44u0__p4_0[] = {
  132279. -1.5, -0.5, 0.5, 1.5,
  132280. };
  132281. static long _vq_quantmap__44u0__p4_0[] = {
  132282. 3, 1, 0, 2, 4,
  132283. };
  132284. static encode_aux_threshmatch _vq_auxt__44u0__p4_0 = {
  132285. _vq_quantthresh__44u0__p4_0,
  132286. _vq_quantmap__44u0__p4_0,
  132287. 5,
  132288. 5
  132289. };
  132290. static static_codebook _44u0__p4_0 = {
  132291. 4, 625,
  132292. _vq_lengthlist__44u0__p4_0,
  132293. 1, -533725184, 1611661312, 3, 0,
  132294. _vq_quantlist__44u0__p4_0,
  132295. NULL,
  132296. &_vq_auxt__44u0__p4_0,
  132297. NULL,
  132298. 0
  132299. };
  132300. static long _vq_quantlist__44u0__p5_0[] = {
  132301. 4,
  132302. 3,
  132303. 5,
  132304. 2,
  132305. 6,
  132306. 1,
  132307. 7,
  132308. 0,
  132309. 8,
  132310. };
  132311. static long _vq_lengthlist__44u0__p5_0[] = {
  132312. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 8, 8, 8,
  132313. 9, 9, 4, 6, 6, 8, 8, 8, 8, 9, 9, 7, 8, 8, 9, 9,
  132314. 9, 9,11,10, 7, 8, 8, 9, 9, 9, 9,10,10, 7, 8, 8,
  132315. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  132316. 9, 9,10,10,11,11,12,12, 9, 9, 9,10,11,11,11,12,
  132317. 12,
  132318. };
  132319. static float _vq_quantthresh__44u0__p5_0[] = {
  132320. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  132321. };
  132322. static long _vq_quantmap__44u0__p5_0[] = {
  132323. 7, 5, 3, 1, 0, 2, 4, 6,
  132324. 8,
  132325. };
  132326. static encode_aux_threshmatch _vq_auxt__44u0__p5_0 = {
  132327. _vq_quantthresh__44u0__p5_0,
  132328. _vq_quantmap__44u0__p5_0,
  132329. 9,
  132330. 9
  132331. };
  132332. static static_codebook _44u0__p5_0 = {
  132333. 2, 81,
  132334. _vq_lengthlist__44u0__p5_0,
  132335. 1, -531628032, 1611661312, 4, 0,
  132336. _vq_quantlist__44u0__p5_0,
  132337. NULL,
  132338. &_vq_auxt__44u0__p5_0,
  132339. NULL,
  132340. 0
  132341. };
  132342. static long _vq_quantlist__44u0__p6_0[] = {
  132343. 6,
  132344. 5,
  132345. 7,
  132346. 4,
  132347. 8,
  132348. 3,
  132349. 9,
  132350. 2,
  132351. 10,
  132352. 1,
  132353. 11,
  132354. 0,
  132355. 12,
  132356. };
  132357. static long _vq_lengthlist__44u0__p6_0[] = {
  132358. 1, 4, 4, 6, 6, 8, 8,10, 9,11,10,14,13, 4, 6, 5,
  132359. 8, 8, 9, 9,11,10,11,11,14,14, 4, 5, 6, 8, 8, 9,
  132360. 9,10,10,11,11,14,14, 6, 8, 8, 9, 9,10,10,11,11,
  132361. 12,12,16,15, 7, 8, 8, 9, 9,10,10,11,11,12,12,15,
  132362. 15, 9,10,10,10,10,11,11,12,12,12,12,15,15, 9,10,
  132363. 9,10,11,11,11,12,12,12,13,15,15,10,10,11,11,11,
  132364. 12,12,13,12,13,13,16,15,10,11,11,11,11,12,12,13,
  132365. 12,13,13,16,17,11,11,12,12,12,13,13,13,14,14,15,
  132366. 17,17,11,11,12,12,12,13,13,13,14,14,14,16,18,14,
  132367. 15,15,15,15,16,16,16,16,17,18, 0, 0,14,15,15,15,
  132368. 15,17,16,17,18,17,17,18, 0,
  132369. };
  132370. static float _vq_quantthresh__44u0__p6_0[] = {
  132371. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  132372. 12.5, 17.5, 22.5, 27.5,
  132373. };
  132374. static long _vq_quantmap__44u0__p6_0[] = {
  132375. 11, 9, 7, 5, 3, 1, 0, 2,
  132376. 4, 6, 8, 10, 12,
  132377. };
  132378. static encode_aux_threshmatch _vq_auxt__44u0__p6_0 = {
  132379. _vq_quantthresh__44u0__p6_0,
  132380. _vq_quantmap__44u0__p6_0,
  132381. 13,
  132382. 13
  132383. };
  132384. static static_codebook _44u0__p6_0 = {
  132385. 2, 169,
  132386. _vq_lengthlist__44u0__p6_0,
  132387. 1, -526516224, 1616117760, 4, 0,
  132388. _vq_quantlist__44u0__p6_0,
  132389. NULL,
  132390. &_vq_auxt__44u0__p6_0,
  132391. NULL,
  132392. 0
  132393. };
  132394. static long _vq_quantlist__44u0__p6_1[] = {
  132395. 2,
  132396. 1,
  132397. 3,
  132398. 0,
  132399. 4,
  132400. };
  132401. static long _vq_lengthlist__44u0__p6_1[] = {
  132402. 2, 4, 4, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5,
  132403. 6, 6, 6, 6, 5, 6, 6, 6, 6,
  132404. };
  132405. static float _vq_quantthresh__44u0__p6_1[] = {
  132406. -1.5, -0.5, 0.5, 1.5,
  132407. };
  132408. static long _vq_quantmap__44u0__p6_1[] = {
  132409. 3, 1, 0, 2, 4,
  132410. };
  132411. static encode_aux_threshmatch _vq_auxt__44u0__p6_1 = {
  132412. _vq_quantthresh__44u0__p6_1,
  132413. _vq_quantmap__44u0__p6_1,
  132414. 5,
  132415. 5
  132416. };
  132417. static static_codebook _44u0__p6_1 = {
  132418. 2, 25,
  132419. _vq_lengthlist__44u0__p6_1,
  132420. 1, -533725184, 1611661312, 3, 0,
  132421. _vq_quantlist__44u0__p6_1,
  132422. NULL,
  132423. &_vq_auxt__44u0__p6_1,
  132424. NULL,
  132425. 0
  132426. };
  132427. static long _vq_quantlist__44u0__p7_0[] = {
  132428. 2,
  132429. 1,
  132430. 3,
  132431. 0,
  132432. 4,
  132433. };
  132434. static long _vq_lengthlist__44u0__p7_0[] = {
  132435. 1, 4, 4,11,11, 9,11,11,11,11,11,11,11,11,11,11,
  132436. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132437. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132438. 11,11, 9,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132439. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132440. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132441. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132442. 11,11,11,11,11,11,11,11,11,11,11,11,11,10,11,11,
  132443. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132444. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132445. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132446. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132447. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132448. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132449. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132450. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132451. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132452. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132453. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132454. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132455. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132456. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132457. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132458. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132459. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132460. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132461. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132462. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132463. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132464. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132465. 11,11,11,11,11,11,10,10,10,10,10,10,10,10,10,10,
  132466. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132467. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132468. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132469. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132470. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132471. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132472. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132473. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132474. 10,
  132475. };
  132476. static float _vq_quantthresh__44u0__p7_0[] = {
  132477. -253.5, -84.5, 84.5, 253.5,
  132478. };
  132479. static long _vq_quantmap__44u0__p7_0[] = {
  132480. 3, 1, 0, 2, 4,
  132481. };
  132482. static encode_aux_threshmatch _vq_auxt__44u0__p7_0 = {
  132483. _vq_quantthresh__44u0__p7_0,
  132484. _vq_quantmap__44u0__p7_0,
  132485. 5,
  132486. 5
  132487. };
  132488. static static_codebook _44u0__p7_0 = {
  132489. 4, 625,
  132490. _vq_lengthlist__44u0__p7_0,
  132491. 1, -518709248, 1626677248, 3, 0,
  132492. _vq_quantlist__44u0__p7_0,
  132493. NULL,
  132494. &_vq_auxt__44u0__p7_0,
  132495. NULL,
  132496. 0
  132497. };
  132498. static long _vq_quantlist__44u0__p7_1[] = {
  132499. 6,
  132500. 5,
  132501. 7,
  132502. 4,
  132503. 8,
  132504. 3,
  132505. 9,
  132506. 2,
  132507. 10,
  132508. 1,
  132509. 11,
  132510. 0,
  132511. 12,
  132512. };
  132513. static long _vq_lengthlist__44u0__p7_1[] = {
  132514. 1, 4, 4, 6, 6, 6, 6, 7, 7, 8, 8, 9, 9, 5, 7, 7,
  132515. 8, 7, 7, 7, 9, 8,10, 9,10,11, 5, 7, 7, 8, 8, 7,
  132516. 7, 8, 9,10,10,11,11, 6, 8, 8, 9, 9, 9, 9,11,10,
  132517. 12,12,15,12, 6, 8, 8, 9, 9, 9, 9,11,11,12,11,14,
  132518. 12, 7, 8, 8,10,10,12,12,13,13,13,15,13,13, 7, 8,
  132519. 8,10,10,11,11,13,12,14,15,15,15, 9,10,10,11,12,
  132520. 13,13,14,15,14,15,14,15, 8,10,10,12,12,14,14,15,
  132521. 14,14,15,15,14,10,12,12,14,14,15,14,15,15,15,14,
  132522. 15,15,10,12,12,13,14,15,14,15,15,14,15,15,15,12,
  132523. 15,13,15,14,15,15,15,15,15,15,15,15,13,13,15,15,
  132524. 15,15,15,15,15,15,15,15,15,
  132525. };
  132526. static float _vq_quantthresh__44u0__p7_1[] = {
  132527. -71.5, -58.5, -45.5, -32.5, -19.5, -6.5, 6.5, 19.5,
  132528. 32.5, 45.5, 58.5, 71.5,
  132529. };
  132530. static long _vq_quantmap__44u0__p7_1[] = {
  132531. 11, 9, 7, 5, 3, 1, 0, 2,
  132532. 4, 6, 8, 10, 12,
  132533. };
  132534. static encode_aux_threshmatch _vq_auxt__44u0__p7_1 = {
  132535. _vq_quantthresh__44u0__p7_1,
  132536. _vq_quantmap__44u0__p7_1,
  132537. 13,
  132538. 13
  132539. };
  132540. static static_codebook _44u0__p7_1 = {
  132541. 2, 169,
  132542. _vq_lengthlist__44u0__p7_1,
  132543. 1, -523010048, 1618608128, 4, 0,
  132544. _vq_quantlist__44u0__p7_1,
  132545. NULL,
  132546. &_vq_auxt__44u0__p7_1,
  132547. NULL,
  132548. 0
  132549. };
  132550. static long _vq_quantlist__44u0__p7_2[] = {
  132551. 6,
  132552. 5,
  132553. 7,
  132554. 4,
  132555. 8,
  132556. 3,
  132557. 9,
  132558. 2,
  132559. 10,
  132560. 1,
  132561. 11,
  132562. 0,
  132563. 12,
  132564. };
  132565. static long _vq_lengthlist__44u0__p7_2[] = {
  132566. 2, 5, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 8, 5, 5, 6,
  132567. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 5, 6, 5, 7, 7, 8,
  132568. 8, 8, 8, 9, 9, 9, 9, 6, 7, 7, 8, 8, 8, 8, 9, 8,
  132569. 9, 9, 9, 9, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  132570. 9, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 7, 8,
  132571. 8, 9, 8, 9, 8, 9, 9, 9, 9, 9, 9, 8, 9, 8, 9, 9,
  132572. 9, 9, 9, 9, 9, 9,10,10, 8, 8, 9, 9, 9, 9, 9, 9,
  132573. 9, 9,10, 9,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132574. 9, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132575. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 9, 9, 9, 9, 9,
  132576. 9, 9, 9,10, 9, 9,10,10, 9,
  132577. };
  132578. static float _vq_quantthresh__44u0__p7_2[] = {
  132579. -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
  132580. 2.5, 3.5, 4.5, 5.5,
  132581. };
  132582. static long _vq_quantmap__44u0__p7_2[] = {
  132583. 11, 9, 7, 5, 3, 1, 0, 2,
  132584. 4, 6, 8, 10, 12,
  132585. };
  132586. static encode_aux_threshmatch _vq_auxt__44u0__p7_2 = {
  132587. _vq_quantthresh__44u0__p7_2,
  132588. _vq_quantmap__44u0__p7_2,
  132589. 13,
  132590. 13
  132591. };
  132592. static static_codebook _44u0__p7_2 = {
  132593. 2, 169,
  132594. _vq_lengthlist__44u0__p7_2,
  132595. 1, -531103744, 1611661312, 4, 0,
  132596. _vq_quantlist__44u0__p7_2,
  132597. NULL,
  132598. &_vq_auxt__44u0__p7_2,
  132599. NULL,
  132600. 0
  132601. };
  132602. static long _huff_lengthlist__44u0__short[] = {
  132603. 12,13,14,13,17,12,15,17, 5, 5, 6,10,10,11,15,16,
  132604. 4, 3, 3, 7, 5, 7,10,16, 7, 7, 7,10, 9,11,12,16,
  132605. 6, 5, 5, 9, 5, 6,10,16, 8, 7, 7, 9, 6, 7, 9,16,
  132606. 11, 7, 3, 6, 4, 5, 8,16,12, 9, 4, 8, 5, 7, 9,16,
  132607. };
  132608. static static_codebook _huff_book__44u0__short = {
  132609. 2, 64,
  132610. _huff_lengthlist__44u0__short,
  132611. 0, 0, 0, 0, 0,
  132612. NULL,
  132613. NULL,
  132614. NULL,
  132615. NULL,
  132616. 0
  132617. };
  132618. static long _huff_lengthlist__44u1__long[] = {
  132619. 5, 8,13,10,17,11,11,15, 7, 2, 4, 5, 8, 7, 9,16,
  132620. 13, 4, 3, 5, 6, 8,11,20,10, 4, 5, 5, 7, 6, 8,18,
  132621. 15, 7, 6, 7, 8,10,14,20,10, 6, 7, 6, 9, 7, 8,17,
  132622. 9, 8,10, 8,10, 5, 4,11,12,17,19,14,16,10, 7,12,
  132623. };
  132624. static static_codebook _huff_book__44u1__long = {
  132625. 2, 64,
  132626. _huff_lengthlist__44u1__long,
  132627. 0, 0, 0, 0, 0,
  132628. NULL,
  132629. NULL,
  132630. NULL,
  132631. NULL,
  132632. 0
  132633. };
  132634. static long _vq_quantlist__44u1__p1_0[] = {
  132635. 1,
  132636. 0,
  132637. 2,
  132638. };
  132639. static long _vq_lengthlist__44u1__p1_0[] = {
  132640. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,11,11, 8,
  132641. 10,10, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  132642. 11, 8,11,11, 8,12,11,11,13,13,11,13,14, 7,11,11,
  132643. 10,13,12,11,13,14, 4, 8, 8, 8,11,11, 8,11,12, 8,
  132644. 11,11,11,13,13,10,12,13, 8,11,11,11,14,13,11,14,
  132645. 13,
  132646. };
  132647. static float _vq_quantthresh__44u1__p1_0[] = {
  132648. -0.5, 0.5,
  132649. };
  132650. static long _vq_quantmap__44u1__p1_0[] = {
  132651. 1, 0, 2,
  132652. };
  132653. static encode_aux_threshmatch _vq_auxt__44u1__p1_0 = {
  132654. _vq_quantthresh__44u1__p1_0,
  132655. _vq_quantmap__44u1__p1_0,
  132656. 3,
  132657. 3
  132658. };
  132659. static static_codebook _44u1__p1_0 = {
  132660. 4, 81,
  132661. _vq_lengthlist__44u1__p1_0,
  132662. 1, -535822336, 1611661312, 2, 0,
  132663. _vq_quantlist__44u1__p1_0,
  132664. NULL,
  132665. &_vq_auxt__44u1__p1_0,
  132666. NULL,
  132667. 0
  132668. };
  132669. static long _vq_quantlist__44u1__p2_0[] = {
  132670. 1,
  132671. 0,
  132672. 2,
  132673. };
  132674. static long _vq_lengthlist__44u1__p2_0[] = {
  132675. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 7, 8, 8, 6,
  132676. 8, 8, 5, 7, 7, 6, 8, 8, 7, 8, 8, 4, 7, 7, 7, 8,
  132677. 8, 7, 8, 8, 7, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  132678. 8,10, 8, 8,10,10, 5, 7, 7, 7, 8, 8, 7, 8, 8, 6,
  132679. 8, 8, 8,10,10, 8, 8,10, 6, 8, 8, 8,10,10, 8,10,
  132680. 9,
  132681. };
  132682. static float _vq_quantthresh__44u1__p2_0[] = {
  132683. -0.5, 0.5,
  132684. };
  132685. static long _vq_quantmap__44u1__p2_0[] = {
  132686. 1, 0, 2,
  132687. };
  132688. static encode_aux_threshmatch _vq_auxt__44u1__p2_0 = {
  132689. _vq_quantthresh__44u1__p2_0,
  132690. _vq_quantmap__44u1__p2_0,
  132691. 3,
  132692. 3
  132693. };
  132694. static static_codebook _44u1__p2_0 = {
  132695. 4, 81,
  132696. _vq_lengthlist__44u1__p2_0,
  132697. 1, -535822336, 1611661312, 2, 0,
  132698. _vq_quantlist__44u1__p2_0,
  132699. NULL,
  132700. &_vq_auxt__44u1__p2_0,
  132701. NULL,
  132702. 0
  132703. };
  132704. static long _vq_quantlist__44u1__p3_0[] = {
  132705. 2,
  132706. 1,
  132707. 3,
  132708. 0,
  132709. 4,
  132710. };
  132711. static long _vq_lengthlist__44u1__p3_0[] = {
  132712. 1, 5, 5, 8, 8, 5, 8, 7, 9, 9, 5, 7, 8, 9, 9, 9,
  132713. 10, 9,12,12, 9, 9,10,12,12, 6, 8, 8,11,10, 8,10,
  132714. 10,11,11, 8, 9,10,11,11,10,11,11,14,13,10,11,11,
  132715. 13,13, 5, 8, 8,10,10, 8,10,10,11,11, 8,10,10,11,
  132716. 11,10,11,11,13,13,10,11,11,13,13, 9,11,11,15,14,
  132717. 10,12,12,15,14,10,12,11,15,14,13,14,14,16,16,12,
  132718. 14,13,17,15, 9,11,11,14,15,10,11,12,14,16,10,11,
  132719. 12,14,16,12,13,14,16,16,13,13,15,15,18, 5, 8, 8,
  132720. 11,11, 8,10,10,12,12, 8,10,10,12,13,11,12,12,14,
  132721. 14,11,12,12,15,15, 8,10,10,13,13,10,12,12,13,13,
  132722. 10,12,12,14,14,12,13,13,15,15,12,13,13,16,16, 7,
  132723. 10,10,12,12,10,12,11,13,13,10,12,12,13,14,12,13,
  132724. 12,15,14,12,13,13,16,16,10,12,12,17,16,12,13,13,
  132725. 16,15,11,13,13,17,17,15,15,15,16,17,14,15,15,19,
  132726. 19,10,12,12,15,16,11,13,12,15,18,11,13,13,16,16,
  132727. 14,15,15,17,17,14,15,15,17,19, 5, 8, 8,11,11, 8,
  132728. 10,10,12,12, 8,10,10,12,12,11,12,12,16,15,11,12,
  132729. 12,14,15, 7,10,10,13,13,10,12,12,14,13,10,11,12,
  132730. 13,13,12,13,13,16,16,12,12,13,15,15, 8,10,10,13,
  132731. 13,10,12,12,14,14,10,12,12,13,13,12,13,13,16,16,
  132732. 12,13,13,15,15,10,12,12,16,15,11,13,13,17,16,11,
  132733. 12,13,16,15,13,15,15,19,17,14,15,14,17,16,10,12,
  132734. 12,16,16,11,13,13,16,17,12,13,13,15,17,14,15,15,
  132735. 17,19,14,15,15,17,17, 8,11,11,16,16,10,13,12,17,
  132736. 17,10,12,13,16,16,15,17,16,20,19,14,15,17,18,19,
  132737. 9,12,12,16,17,11,13,14,17,18,11,13,13,19,18,16,
  132738. 17,18,19,19,15,16,16,19,19, 9,12,12,16,17,11,14,
  132739. 13,18,17,11,13,13,17,17,16,17,16,20,19,14,16,16,
  132740. 18,18,12,15,15,19,17,14,15,16, 0,20,13,15,16,20,
  132741. 17,18,16,20, 0, 0,15,16,19,20, 0,12,15,14,18,19,
  132742. 13,16,15,20,19,13,16,15,20,18,17,18,17, 0,20,16,
  132743. 17,16, 0, 0, 8,11,11,16,15,10,12,12,17,17,10,13,
  132744. 13,17,16,14,16,15,18,20,15,16,16,19,19, 9,12,12,
  132745. 16,16,11,13,13,17,16,11,13,14,17,18,15,15,16,20,
  132746. 20,16,16,17,19,19, 9,13,12,16,17,11,14,13,17,17,
  132747. 11,14,14,18,17,14,16,15,18,19,16,17,18,18,19,12,
  132748. 14,15,19,18,13,15,16,18, 0,13,14,15, 0, 0,16,16,
  132749. 17,20, 0,17,17,20,20, 0,12,15,15,19,20,13,15,15,
  132750. 0, 0,14,16,15, 0, 0,15,18,16, 0, 0,17,18,16, 0,
  132751. 19,
  132752. };
  132753. static float _vq_quantthresh__44u1__p3_0[] = {
  132754. -1.5, -0.5, 0.5, 1.5,
  132755. };
  132756. static long _vq_quantmap__44u1__p3_0[] = {
  132757. 3, 1, 0, 2, 4,
  132758. };
  132759. static encode_aux_threshmatch _vq_auxt__44u1__p3_0 = {
  132760. _vq_quantthresh__44u1__p3_0,
  132761. _vq_quantmap__44u1__p3_0,
  132762. 5,
  132763. 5
  132764. };
  132765. static static_codebook _44u1__p3_0 = {
  132766. 4, 625,
  132767. _vq_lengthlist__44u1__p3_0,
  132768. 1, -533725184, 1611661312, 3, 0,
  132769. _vq_quantlist__44u1__p3_0,
  132770. NULL,
  132771. &_vq_auxt__44u1__p3_0,
  132772. NULL,
  132773. 0
  132774. };
  132775. static long _vq_quantlist__44u1__p4_0[] = {
  132776. 2,
  132777. 1,
  132778. 3,
  132779. 0,
  132780. 4,
  132781. };
  132782. static long _vq_lengthlist__44u1__p4_0[] = {
  132783. 4, 5, 5, 9, 9, 5, 6, 6, 9, 9, 5, 6, 6, 9, 9, 9,
  132784. 10, 9,12,12, 9, 9,10,12,12, 5, 7, 7,10,10, 7, 7,
  132785. 8,10,10, 6, 7, 8,10,10,10,10,10,11,13,10, 9,10,
  132786. 12,13, 5, 7, 7,10,10, 6, 8, 7,10,10, 7, 8, 7,10,
  132787. 10, 9,10,10,12,12,10,10,10,13,11, 9,10,10,13,13,
  132788. 10,11,10,13,13,10,10,10,13,13,12,12,13,14,14,12,
  132789. 12,13,14,14, 9,10,10,13,13,10,10,10,13,13,10,10,
  132790. 10,13,13,12,13,12,15,14,12,13,12,15,15, 5, 7, 6,
  132791. 10,10, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,10,13,
  132792. 13,10,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,10,11,
  132793. 8, 9, 9,11,11,11,10,11,11,14,11,11,11,13,13, 6,
  132794. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  132795. 10,14,11,10,11,11,13,13,10,11,11,14,13,10,10,11,
  132796. 14,13,10,11,11,14,14,12,11,13,12,16,13,14,14,15,
  132797. 15,10,10,11,13,14,10,11,10,14,13,10,11,11,14,14,
  132798. 12,13,12,15,13,13,13,14,15,16, 5, 7, 7,10,10, 7,
  132799. 8, 8,10,10, 7, 8, 8,10,10,10,10,10,13,13,10,10,
  132800. 11,12,13, 6, 8, 8,11,10, 8, 9, 9,11,11, 7, 8, 9,
  132801. 10,11,10,11,11,13,13,10,10,11,11,13, 6, 8, 8,10,
  132802. 11, 8, 9, 9,11,11, 8, 9, 8,12,10,10,11,11,13,13,
  132803. 10,11,10,14,11,10,10,10,14,13,10,11,11,14,13,10,
  132804. 10,11,13,13,12,14,14,16,16,12,12,13,13,15,10,11,
  132805. 11,13,14,10,11,11,14,15,10,11,10,13,13,13,14,13,
  132806. 16,16,12,13,11,15,12, 9,10,10,13,13,10,11,11,14,
  132807. 13,10,10,11,13,14,13,14,13,16,16,13,13,13,15,16,
  132808. 9,10,10,13,13,10,10,11,13,14,10,11,11,15,13,13,
  132809. 13,14,14,18,13,13,14,16,15, 9,10,10,13,14,10,11,
  132810. 10,14,13,10,11,11,13,14,13,14,13,16,15,13,13,14,
  132811. 15,16,12,13,12,16,14,11,11,13,15,15,13,14,13,16,
  132812. 15,15,12,16,12,17,14,15,15,17,17,12,13,13,14,16,
  132813. 11,13,11,16,15,12,13,14,15,16,14,15,13, 0,14,14,
  132814. 16,16, 0, 0, 9,10,10,13,13,10,11,10,14,14,10,11,
  132815. 11,13,13,12,13,13,14,16,13,14,14,16,16, 9,10,10,
  132816. 14,14,11,11,11,14,13,10,10,11,14,14,13,13,13,16,
  132817. 16,13,13,14,14,17, 9,10,10,13,14,10,11,11,13,15,
  132818. 10,11,10,14,14,13,13,13,14,17,13,14,13,17,14,12,
  132819. 13,13,16,14,13,14,13,16,15,12,12,13,15,16,15,15,
  132820. 16,18,16,15,13,15,14, 0,12,12,13,14,16,13,13,14,
  132821. 15,16,11,12,11,16,14,15,16,16,17,17,14,15,12,17,
  132822. 12,
  132823. };
  132824. static float _vq_quantthresh__44u1__p4_0[] = {
  132825. -1.5, -0.5, 0.5, 1.5,
  132826. };
  132827. static long _vq_quantmap__44u1__p4_0[] = {
  132828. 3, 1, 0, 2, 4,
  132829. };
  132830. static encode_aux_threshmatch _vq_auxt__44u1__p4_0 = {
  132831. _vq_quantthresh__44u1__p4_0,
  132832. _vq_quantmap__44u1__p4_0,
  132833. 5,
  132834. 5
  132835. };
  132836. static static_codebook _44u1__p4_0 = {
  132837. 4, 625,
  132838. _vq_lengthlist__44u1__p4_0,
  132839. 1, -533725184, 1611661312, 3, 0,
  132840. _vq_quantlist__44u1__p4_0,
  132841. NULL,
  132842. &_vq_auxt__44u1__p4_0,
  132843. NULL,
  132844. 0
  132845. };
  132846. static long _vq_quantlist__44u1__p5_0[] = {
  132847. 4,
  132848. 3,
  132849. 5,
  132850. 2,
  132851. 6,
  132852. 1,
  132853. 7,
  132854. 0,
  132855. 8,
  132856. };
  132857. static long _vq_lengthlist__44u1__p5_0[] = {
  132858. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 8, 8, 8,
  132859. 9, 9, 4, 6, 6, 8, 8, 8, 8, 9, 9, 7, 8, 8, 9, 9,
  132860. 9, 9,11,10, 7, 8, 8, 9, 9, 9, 9,10,10, 7, 8, 8,
  132861. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  132862. 9, 9,10,10,11,11,12,12, 9, 9, 9,10,11,11,11,12,
  132863. 12,
  132864. };
  132865. static float _vq_quantthresh__44u1__p5_0[] = {
  132866. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  132867. };
  132868. static long _vq_quantmap__44u1__p5_0[] = {
  132869. 7, 5, 3, 1, 0, 2, 4, 6,
  132870. 8,
  132871. };
  132872. static encode_aux_threshmatch _vq_auxt__44u1__p5_0 = {
  132873. _vq_quantthresh__44u1__p5_0,
  132874. _vq_quantmap__44u1__p5_0,
  132875. 9,
  132876. 9
  132877. };
  132878. static static_codebook _44u1__p5_0 = {
  132879. 2, 81,
  132880. _vq_lengthlist__44u1__p5_0,
  132881. 1, -531628032, 1611661312, 4, 0,
  132882. _vq_quantlist__44u1__p5_0,
  132883. NULL,
  132884. &_vq_auxt__44u1__p5_0,
  132885. NULL,
  132886. 0
  132887. };
  132888. static long _vq_quantlist__44u1__p6_0[] = {
  132889. 6,
  132890. 5,
  132891. 7,
  132892. 4,
  132893. 8,
  132894. 3,
  132895. 9,
  132896. 2,
  132897. 10,
  132898. 1,
  132899. 11,
  132900. 0,
  132901. 12,
  132902. };
  132903. static long _vq_lengthlist__44u1__p6_0[] = {
  132904. 1, 4, 4, 6, 6, 8, 8,10, 9,11,10,14,13, 4, 6, 5,
  132905. 8, 8, 9, 9,11,10,11,11,14,14, 4, 5, 6, 8, 8, 9,
  132906. 9,10,10,11,11,14,14, 6, 8, 8, 9, 9,10,10,11,11,
  132907. 12,12,16,15, 7, 8, 8, 9, 9,10,10,11,11,12,12,15,
  132908. 15, 9,10,10,10,10,11,11,12,12,12,12,15,15, 9,10,
  132909. 9,10,11,11,11,12,12,12,13,15,15,10,10,11,11,11,
  132910. 12,12,13,12,13,13,16,15,10,11,11,11,11,12,12,13,
  132911. 12,13,13,16,17,11,11,12,12,12,13,13,13,14,14,15,
  132912. 17,17,11,11,12,12,12,13,13,13,14,14,14,16,18,14,
  132913. 15,15,15,15,16,16,16,16,17,18, 0, 0,14,15,15,15,
  132914. 15,17,16,17,18,17,17,18, 0,
  132915. };
  132916. static float _vq_quantthresh__44u1__p6_0[] = {
  132917. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  132918. 12.5, 17.5, 22.5, 27.5,
  132919. };
  132920. static long _vq_quantmap__44u1__p6_0[] = {
  132921. 11, 9, 7, 5, 3, 1, 0, 2,
  132922. 4, 6, 8, 10, 12,
  132923. };
  132924. static encode_aux_threshmatch _vq_auxt__44u1__p6_0 = {
  132925. _vq_quantthresh__44u1__p6_0,
  132926. _vq_quantmap__44u1__p6_0,
  132927. 13,
  132928. 13
  132929. };
  132930. static static_codebook _44u1__p6_0 = {
  132931. 2, 169,
  132932. _vq_lengthlist__44u1__p6_0,
  132933. 1, -526516224, 1616117760, 4, 0,
  132934. _vq_quantlist__44u1__p6_0,
  132935. NULL,
  132936. &_vq_auxt__44u1__p6_0,
  132937. NULL,
  132938. 0
  132939. };
  132940. static long _vq_quantlist__44u1__p6_1[] = {
  132941. 2,
  132942. 1,
  132943. 3,
  132944. 0,
  132945. 4,
  132946. };
  132947. static long _vq_lengthlist__44u1__p6_1[] = {
  132948. 2, 4, 4, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5,
  132949. 6, 6, 6, 6, 5, 6, 6, 6, 6,
  132950. };
  132951. static float _vq_quantthresh__44u1__p6_1[] = {
  132952. -1.5, -0.5, 0.5, 1.5,
  132953. };
  132954. static long _vq_quantmap__44u1__p6_1[] = {
  132955. 3, 1, 0, 2, 4,
  132956. };
  132957. static encode_aux_threshmatch _vq_auxt__44u1__p6_1 = {
  132958. _vq_quantthresh__44u1__p6_1,
  132959. _vq_quantmap__44u1__p6_1,
  132960. 5,
  132961. 5
  132962. };
  132963. static static_codebook _44u1__p6_1 = {
  132964. 2, 25,
  132965. _vq_lengthlist__44u1__p6_1,
  132966. 1, -533725184, 1611661312, 3, 0,
  132967. _vq_quantlist__44u1__p6_1,
  132968. NULL,
  132969. &_vq_auxt__44u1__p6_1,
  132970. NULL,
  132971. 0
  132972. };
  132973. static long _vq_quantlist__44u1__p7_0[] = {
  132974. 3,
  132975. 2,
  132976. 4,
  132977. 1,
  132978. 5,
  132979. 0,
  132980. 6,
  132981. };
  132982. static long _vq_lengthlist__44u1__p7_0[] = {
  132983. 1, 3, 2, 9, 9, 7, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132984. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132985. 9, 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  132986. 8,
  132987. };
  132988. static float _vq_quantthresh__44u1__p7_0[] = {
  132989. -422.5, -253.5, -84.5, 84.5, 253.5, 422.5,
  132990. };
  132991. static long _vq_quantmap__44u1__p7_0[] = {
  132992. 5, 3, 1, 0, 2, 4, 6,
  132993. };
  132994. static encode_aux_threshmatch _vq_auxt__44u1__p7_0 = {
  132995. _vq_quantthresh__44u1__p7_0,
  132996. _vq_quantmap__44u1__p7_0,
  132997. 7,
  132998. 7
  132999. };
  133000. static static_codebook _44u1__p7_0 = {
  133001. 2, 49,
  133002. _vq_lengthlist__44u1__p7_0,
  133003. 1, -518017024, 1626677248, 3, 0,
  133004. _vq_quantlist__44u1__p7_0,
  133005. NULL,
  133006. &_vq_auxt__44u1__p7_0,
  133007. NULL,
  133008. 0
  133009. };
  133010. static long _vq_quantlist__44u1__p7_1[] = {
  133011. 6,
  133012. 5,
  133013. 7,
  133014. 4,
  133015. 8,
  133016. 3,
  133017. 9,
  133018. 2,
  133019. 10,
  133020. 1,
  133021. 11,
  133022. 0,
  133023. 12,
  133024. };
  133025. static long _vq_lengthlist__44u1__p7_1[] = {
  133026. 1, 4, 4, 6, 6, 6, 6, 7, 7, 8, 8, 9, 9, 5, 7, 7,
  133027. 8, 7, 7, 7, 9, 8,10, 9,10,11, 5, 7, 7, 8, 8, 7,
  133028. 7, 8, 9,10,10,11,11, 6, 8, 8, 9, 9, 9, 9,11,10,
  133029. 12,12,15,12, 6, 8, 8, 9, 9, 9, 9,11,11,12,11,14,
  133030. 12, 7, 8, 8,10,10,12,12,13,13,13,15,13,13, 7, 8,
  133031. 8,10,10,11,11,13,12,14,15,15,15, 9,10,10,11,12,
  133032. 13,13,14,15,14,15,14,15, 8,10,10,12,12,14,14,15,
  133033. 14,14,15,15,14,10,12,12,14,14,15,14,15,15,15,14,
  133034. 15,15,10,12,12,13,14,15,14,15,15,14,15,15,15,12,
  133035. 15,13,15,14,15,15,15,15,15,15,15,15,13,13,15,15,
  133036. 15,15,15,15,15,15,15,15,15,
  133037. };
  133038. static float _vq_quantthresh__44u1__p7_1[] = {
  133039. -71.5, -58.5, -45.5, -32.5, -19.5, -6.5, 6.5, 19.5,
  133040. 32.5, 45.5, 58.5, 71.5,
  133041. };
  133042. static long _vq_quantmap__44u1__p7_1[] = {
  133043. 11, 9, 7, 5, 3, 1, 0, 2,
  133044. 4, 6, 8, 10, 12,
  133045. };
  133046. static encode_aux_threshmatch _vq_auxt__44u1__p7_1 = {
  133047. _vq_quantthresh__44u1__p7_1,
  133048. _vq_quantmap__44u1__p7_1,
  133049. 13,
  133050. 13
  133051. };
  133052. static static_codebook _44u1__p7_1 = {
  133053. 2, 169,
  133054. _vq_lengthlist__44u1__p7_1,
  133055. 1, -523010048, 1618608128, 4, 0,
  133056. _vq_quantlist__44u1__p7_1,
  133057. NULL,
  133058. &_vq_auxt__44u1__p7_1,
  133059. NULL,
  133060. 0
  133061. };
  133062. static long _vq_quantlist__44u1__p7_2[] = {
  133063. 6,
  133064. 5,
  133065. 7,
  133066. 4,
  133067. 8,
  133068. 3,
  133069. 9,
  133070. 2,
  133071. 10,
  133072. 1,
  133073. 11,
  133074. 0,
  133075. 12,
  133076. };
  133077. static long _vq_lengthlist__44u1__p7_2[] = {
  133078. 2, 5, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 8, 5, 5, 6,
  133079. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 5, 6, 5, 7, 7, 8,
  133080. 8, 8, 8, 9, 9, 9, 9, 6, 7, 7, 8, 8, 8, 8, 9, 8,
  133081. 9, 9, 9, 9, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  133082. 9, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 7, 8,
  133083. 8, 9, 8, 9, 8, 9, 9, 9, 9, 9, 9, 8, 9, 8, 9, 9,
  133084. 9, 9, 9, 9, 9, 9,10,10, 8, 8, 9, 9, 9, 9, 9, 9,
  133085. 9, 9,10, 9,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133086. 9, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133087. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 9, 9, 9, 9, 9,
  133088. 9, 9, 9,10, 9, 9,10,10, 9,
  133089. };
  133090. static float _vq_quantthresh__44u1__p7_2[] = {
  133091. -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
  133092. 2.5, 3.5, 4.5, 5.5,
  133093. };
  133094. static long _vq_quantmap__44u1__p7_2[] = {
  133095. 11, 9, 7, 5, 3, 1, 0, 2,
  133096. 4, 6, 8, 10, 12,
  133097. };
  133098. static encode_aux_threshmatch _vq_auxt__44u1__p7_2 = {
  133099. _vq_quantthresh__44u1__p7_2,
  133100. _vq_quantmap__44u1__p7_2,
  133101. 13,
  133102. 13
  133103. };
  133104. static static_codebook _44u1__p7_2 = {
  133105. 2, 169,
  133106. _vq_lengthlist__44u1__p7_2,
  133107. 1, -531103744, 1611661312, 4, 0,
  133108. _vq_quantlist__44u1__p7_2,
  133109. NULL,
  133110. &_vq_auxt__44u1__p7_2,
  133111. NULL,
  133112. 0
  133113. };
  133114. static long _huff_lengthlist__44u1__short[] = {
  133115. 12,13,14,13,17,12,15,17, 5, 5, 6,10,10,11,15,16,
  133116. 4, 3, 3, 7, 5, 7,10,16, 7, 7, 7,10, 9,11,12,16,
  133117. 6, 5, 5, 9, 5, 6,10,16, 8, 7, 7, 9, 6, 7, 9,16,
  133118. 11, 7, 3, 6, 4, 5, 8,16,12, 9, 4, 8, 5, 7, 9,16,
  133119. };
  133120. static static_codebook _huff_book__44u1__short = {
  133121. 2, 64,
  133122. _huff_lengthlist__44u1__short,
  133123. 0, 0, 0, 0, 0,
  133124. NULL,
  133125. NULL,
  133126. NULL,
  133127. NULL,
  133128. 0
  133129. };
  133130. static long _huff_lengthlist__44u2__long[] = {
  133131. 5, 9,14,12,15,13,10,13, 7, 4, 5, 6, 8, 7, 8,12,
  133132. 13, 4, 3, 5, 5, 6, 9,15,12, 6, 5, 6, 6, 6, 7,14,
  133133. 14, 7, 4, 6, 4, 6, 8,15,12, 6, 6, 5, 5, 5, 6,14,
  133134. 9, 7, 8, 6, 7, 5, 4,10,10,13,14,14,15,10, 6, 8,
  133135. };
  133136. static static_codebook _huff_book__44u2__long = {
  133137. 2, 64,
  133138. _huff_lengthlist__44u2__long,
  133139. 0, 0, 0, 0, 0,
  133140. NULL,
  133141. NULL,
  133142. NULL,
  133143. NULL,
  133144. 0
  133145. };
  133146. static long _vq_quantlist__44u2__p1_0[] = {
  133147. 1,
  133148. 0,
  133149. 2,
  133150. };
  133151. static long _vq_lengthlist__44u2__p1_0[] = {
  133152. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,11,11, 8,
  133153. 10,11, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  133154. 11, 8,11,11, 8,11,11,11,13,14,11,13,13, 7,11,11,
  133155. 10,13,12,11,14,14, 4, 8, 8, 8,11,11, 8,11,11, 8,
  133156. 11,11,11,14,13,10,12,13, 8,11,11,11,13,13,11,13,
  133157. 13,
  133158. };
  133159. static float _vq_quantthresh__44u2__p1_0[] = {
  133160. -0.5, 0.5,
  133161. };
  133162. static long _vq_quantmap__44u2__p1_0[] = {
  133163. 1, 0, 2,
  133164. };
  133165. static encode_aux_threshmatch _vq_auxt__44u2__p1_0 = {
  133166. _vq_quantthresh__44u2__p1_0,
  133167. _vq_quantmap__44u2__p1_0,
  133168. 3,
  133169. 3
  133170. };
  133171. static static_codebook _44u2__p1_0 = {
  133172. 4, 81,
  133173. _vq_lengthlist__44u2__p1_0,
  133174. 1, -535822336, 1611661312, 2, 0,
  133175. _vq_quantlist__44u2__p1_0,
  133176. NULL,
  133177. &_vq_auxt__44u2__p1_0,
  133178. NULL,
  133179. 0
  133180. };
  133181. static long _vq_quantlist__44u2__p2_0[] = {
  133182. 1,
  133183. 0,
  133184. 2,
  133185. };
  133186. static long _vq_lengthlist__44u2__p2_0[] = {
  133187. 2, 5, 5, 5, 6, 6, 5, 6, 6, 5, 6, 6, 7, 8, 8, 6,
  133188. 8, 8, 5, 6, 6, 6, 8, 7, 7, 8, 8, 5, 6, 6, 7, 8,
  133189. 8, 6, 8, 8, 6, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  133190. 7,10, 8, 8,10,10, 5, 6, 6, 6, 8, 8, 7, 8, 8, 6,
  133191. 8, 8, 8,10,10, 8, 8,10, 6, 8, 8, 8,10,10, 8,10,
  133192. 9,
  133193. };
  133194. static float _vq_quantthresh__44u2__p2_0[] = {
  133195. -0.5, 0.5,
  133196. };
  133197. static long _vq_quantmap__44u2__p2_0[] = {
  133198. 1, 0, 2,
  133199. };
  133200. static encode_aux_threshmatch _vq_auxt__44u2__p2_0 = {
  133201. _vq_quantthresh__44u2__p2_0,
  133202. _vq_quantmap__44u2__p2_0,
  133203. 3,
  133204. 3
  133205. };
  133206. static static_codebook _44u2__p2_0 = {
  133207. 4, 81,
  133208. _vq_lengthlist__44u2__p2_0,
  133209. 1, -535822336, 1611661312, 2, 0,
  133210. _vq_quantlist__44u2__p2_0,
  133211. NULL,
  133212. &_vq_auxt__44u2__p2_0,
  133213. NULL,
  133214. 0
  133215. };
  133216. static long _vq_quantlist__44u2__p3_0[] = {
  133217. 2,
  133218. 1,
  133219. 3,
  133220. 0,
  133221. 4,
  133222. };
  133223. static long _vq_lengthlist__44u2__p3_0[] = {
  133224. 2, 4, 4, 7, 8, 5, 7, 7, 9, 9, 5, 7, 7, 9, 9, 8,
  133225. 9, 9,12,11, 8, 9, 9,11,12, 5, 7, 7,10,10, 7, 9,
  133226. 9,11,11, 7, 9, 9,10,11,10,11,11,13,13, 9,10,11,
  133227. 12,13, 5, 7, 7,10,10, 7, 9, 9,11,10, 7, 9, 9,11,
  133228. 11, 9,11,10,13,13,10,11,11,13,13, 8,10,10,14,13,
  133229. 10,11,11,15,14, 9,11,11,15,14,13,14,13,16,14,12,
  133230. 13,13,15,16, 8,10,10,13,14, 9,11,11,14,15,10,11,
  133231. 11,14,15,12,13,13,15,15,12,13,14,15,16, 5, 7, 7,
  133232. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,12,10,11,11,14,
  133233. 13,10,11,11,14,14, 7, 9, 9,12,12, 9,11,11,13,13,
  133234. 9,11,11,13,13,12,13,12,14,14,11,12,13,15,15, 7,
  133235. 9, 9,12,12, 8,11,10,13,12, 9,11,11,13,13,11,13,
  133236. 12,15,13,11,13,13,15,16, 9,12,11,15,15,11,12,12,
  133237. 16,15,11,12,13,16,16,13,14,15,16,15,13,15,15,17,
  133238. 17, 9,11,11,14,15,10,12,12,15,15,11,13,12,15,16,
  133239. 13,15,14,16,16,13,15,15,17,19, 5, 7, 7,10,10, 7,
  133240. 9, 9,12,11, 7, 9, 9,11,11,10,11,11,14,14,10,11,
  133241. 11,13,14, 7, 9, 9,12,12, 9,11,11,13,13, 9,10,11,
  133242. 12,13,11,13,12,16,15,11,12,12,14,15, 7, 9, 9,12,
  133243. 12, 9,11,11,13,13, 9,11,11,13,12,11,13,12,15,16,
  133244. 12,13,13,15,14, 9,11,11,15,14,11,13,12,16,15,10,
  133245. 11,12,15,15,13,14,14,18,17,13,14,14,15,17,10,11,
  133246. 11,14,15,11,13,12,15,17,11,13,12,15,16,13,15,14,
  133247. 18,17,14,15,15,16,18, 7,10,10,14,14,10,12,12,15,
  133248. 15,10,12,12,15,15,14,15,15,18,17,13,15,15,16,16,
  133249. 9,11,11,16,15,11,13,13,16,18,11,13,13,16,16,15,
  133250. 16,16, 0, 0,14,15,16,18,17, 9,11,11,15,15,10,13,
  133251. 12,17,16,11,12,13,16,17,14,15,16,19,19,14,15,15,
  133252. 0,20,12,14,14, 0, 0,13,14,16,19,18,13,15,16,20,
  133253. 17,16,18, 0, 0, 0,15,16,17,18,19,11,14,14, 0,19,
  133254. 12,15,14,17,17,13,15,15, 0, 0,16,17,15,20,19,15,
  133255. 17,16,19, 0, 8,10,10,14,15,10,12,11,15,15,10,11,
  133256. 12,16,15,13,14,14,19,17,14,15,15, 0, 0, 9,11,11,
  133257. 16,15,11,13,13,17,16,10,12,13,16,17,14,15,15,18,
  133258. 18,14,15,16,20,19, 9,12,12, 0,15,11,13,13,16,17,
  133259. 11,13,13,19,17,14,16,16,18,17,15,16,16,17,19,11,
  133260. 14,14,18,18,13,14,15, 0, 0,12,14,15,19,18,15,16,
  133261. 19, 0,19,15,16,19,19,17,12,14,14,16,19,13,15,15,
  133262. 0,17,13,15,14,18,18,15,16,15, 0,18,16,17,17, 0,
  133263. 0,
  133264. };
  133265. static float _vq_quantthresh__44u2__p3_0[] = {
  133266. -1.5, -0.5, 0.5, 1.5,
  133267. };
  133268. static long _vq_quantmap__44u2__p3_0[] = {
  133269. 3, 1, 0, 2, 4,
  133270. };
  133271. static encode_aux_threshmatch _vq_auxt__44u2__p3_0 = {
  133272. _vq_quantthresh__44u2__p3_0,
  133273. _vq_quantmap__44u2__p3_0,
  133274. 5,
  133275. 5
  133276. };
  133277. static static_codebook _44u2__p3_0 = {
  133278. 4, 625,
  133279. _vq_lengthlist__44u2__p3_0,
  133280. 1, -533725184, 1611661312, 3, 0,
  133281. _vq_quantlist__44u2__p3_0,
  133282. NULL,
  133283. &_vq_auxt__44u2__p3_0,
  133284. NULL,
  133285. 0
  133286. };
  133287. static long _vq_quantlist__44u2__p4_0[] = {
  133288. 2,
  133289. 1,
  133290. 3,
  133291. 0,
  133292. 4,
  133293. };
  133294. static long _vq_lengthlist__44u2__p4_0[] = {
  133295. 4, 5, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 9,
  133296. 9, 9,11,11, 9, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  133297. 8,10,10, 7, 7, 8,10,10,10,10,10,11,12, 9,10,10,
  133298. 11,12, 5, 7, 7, 9, 9, 6, 8, 7,10,10, 7, 8, 8,10,
  133299. 10, 9,10,10,12,11, 9,10,10,12,11, 9,10,10,12,12,
  133300. 10,10,10,13,12, 9,10,10,12,13,12,12,12,14,14,11,
  133301. 12,12,13,14, 9,10,10,12,12, 9,10,10,12,13,10,10,
  133302. 10,12,13,11,12,12,14,13,12,12,12,14,13, 5, 7, 7,
  133303. 10, 9, 7, 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,
  133304. 12,10,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,11,11,
  133305. 8, 9, 9,11,11,10,11,11,12,13,10,11,11,13,13, 6,
  133306. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  133307. 10,13,11,10,11,11,13,13, 9,10,10,13,13,10,11,11,
  133308. 13,13,10,11,11,14,13,12,11,13,12,15,12,13,13,15,
  133309. 15, 9,10,10,12,13,10,11,10,13,13,10,11,11,13,13,
  133310. 12,13,11,15,13,12,13,13,15,15, 5, 7, 7, 9,10, 7,
  133311. 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,12,10,10,
  133312. 11,12,12, 6, 8, 8,10,10, 8, 9, 9,11,11, 7, 8, 9,
  133313. 10,11,10,11,11,13,13,10,10,11,11,13, 7, 8, 8,10,
  133314. 11, 8, 9, 9,11,11, 8, 9, 8,11,11,10,11,11,13,13,
  133315. 10,11,11,13,12, 9,10,10,13,12,10,11,11,14,13,10,
  133316. 10,11,13,13,12,13,13,15,15,12,11,13,12,14, 9,10,
  133317. 10,12,13,10,11,11,13,14,10,11,11,13,13,12,13,13,
  133318. 15,15,12,13,12,15,12, 8, 9, 9,12,12, 9,11,10,13,
  133319. 13, 9,10,10,13,13,12,13,13,15,15,12,12,12,14,14,
  133320. 9,10,10,13,13,10,11,11,13,14,10,11,11,14,12,13,
  133321. 13,14,14,16,12,13,13,15,14, 9,10,10,13,13,10,11,
  133322. 10,14,13,10,11,11,13,14,12,14,13,16,14,13,13,13,
  133323. 14,15,11,13,12,15,14,11,12,13,14,15,12,13,13,16,
  133324. 15,14,12,15,12,16,14,15,15,17,16,11,12,12,14,15,
  133325. 11,13,11,15,14,12,13,13,15,16,13,15,12,17,13,14,
  133326. 15,15,16,16, 8, 9, 9,12,12, 9,10,10,13,13, 9,10,
  133327. 10,13,13,12,13,12,14,14,12,13,13,15,15, 9,10,10,
  133328. 13,13,10,11,11,14,13,10,10,11,13,14,12,13,13,15,
  133329. 14,12,12,14,14,16, 9,10,10,13,13,10,11,11,13,14,
  133330. 10,11,11,14,13,13,13,13,15,15,13,14,13,16,14,11,
  133331. 12,12,14,14,12,13,13,16,15,11,12,13,14,15,14,15,
  133332. 15,16,16,14,13,15,13,17,11,12,12,14,15,12,13,13,
  133333. 15,16,11,13,12,15,15,14,15,14,16,16,14,15,12,17,
  133334. 13,
  133335. };
  133336. static float _vq_quantthresh__44u2__p4_0[] = {
  133337. -1.5, -0.5, 0.5, 1.5,
  133338. };
  133339. static long _vq_quantmap__44u2__p4_0[] = {
  133340. 3, 1, 0, 2, 4,
  133341. };
  133342. static encode_aux_threshmatch _vq_auxt__44u2__p4_0 = {
  133343. _vq_quantthresh__44u2__p4_0,
  133344. _vq_quantmap__44u2__p4_0,
  133345. 5,
  133346. 5
  133347. };
  133348. static static_codebook _44u2__p4_0 = {
  133349. 4, 625,
  133350. _vq_lengthlist__44u2__p4_0,
  133351. 1, -533725184, 1611661312, 3, 0,
  133352. _vq_quantlist__44u2__p4_0,
  133353. NULL,
  133354. &_vq_auxt__44u2__p4_0,
  133355. NULL,
  133356. 0
  133357. };
  133358. static long _vq_quantlist__44u2__p5_0[] = {
  133359. 4,
  133360. 3,
  133361. 5,
  133362. 2,
  133363. 6,
  133364. 1,
  133365. 7,
  133366. 0,
  133367. 8,
  133368. };
  133369. static long _vq_lengthlist__44u2__p5_0[] = {
  133370. 1, 4, 4, 7, 7, 8, 8, 9, 9, 4, 6, 5, 8, 8, 8, 8,
  133371. 10,10, 4, 5, 6, 8, 8, 8, 8,10,10, 7, 8, 8, 9, 9,
  133372. 9, 9,11,11, 7, 8, 8, 9, 9, 9, 9,11,11, 8, 8, 8,
  133373. 9, 9,10,11,12,12, 8, 8, 8, 9, 9,10,10,12,12,10,
  133374. 10,10,11,11,12,12,13,13,10,10,10,11,11,12,12,13,
  133375. 13,
  133376. };
  133377. static float _vq_quantthresh__44u2__p5_0[] = {
  133378. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  133379. };
  133380. static long _vq_quantmap__44u2__p5_0[] = {
  133381. 7, 5, 3, 1, 0, 2, 4, 6,
  133382. 8,
  133383. };
  133384. static encode_aux_threshmatch _vq_auxt__44u2__p5_0 = {
  133385. _vq_quantthresh__44u2__p5_0,
  133386. _vq_quantmap__44u2__p5_0,
  133387. 9,
  133388. 9
  133389. };
  133390. static static_codebook _44u2__p5_0 = {
  133391. 2, 81,
  133392. _vq_lengthlist__44u2__p5_0,
  133393. 1, -531628032, 1611661312, 4, 0,
  133394. _vq_quantlist__44u2__p5_0,
  133395. NULL,
  133396. &_vq_auxt__44u2__p5_0,
  133397. NULL,
  133398. 0
  133399. };
  133400. static long _vq_quantlist__44u2__p6_0[] = {
  133401. 6,
  133402. 5,
  133403. 7,
  133404. 4,
  133405. 8,
  133406. 3,
  133407. 9,
  133408. 2,
  133409. 10,
  133410. 1,
  133411. 11,
  133412. 0,
  133413. 12,
  133414. };
  133415. static long _vq_lengthlist__44u2__p6_0[] = {
  133416. 1, 4, 4, 6, 6, 8, 8,10,10,11,11,14,13, 4, 6, 5,
  133417. 8, 8, 9, 9,11,10,12,11,15,14, 4, 5, 6, 8, 8, 9,
  133418. 9,11,11,11,11,14,14, 6, 8, 8,10, 9,11,11,11,11,
  133419. 12,12,15,15, 6, 8, 8, 9, 9,11,11,11,12,12,12,15,
  133420. 15, 8,10,10,11,11,11,11,12,12,13,13,15,16, 8,10,
  133421. 10,11,11,11,11,12,12,13,13,16,16,10,11,11,12,12,
  133422. 12,12,13,13,13,13,17,16,10,11,11,12,12,12,12,13,
  133423. 13,13,14,16,17,11,12,12,13,13,13,13,14,14,15,14,
  133424. 18,17,11,12,12,13,13,13,13,14,14,14,15,19,18,14,
  133425. 15,15,15,15,16,16,18,19,18,18, 0, 0,14,15,15,16,
  133426. 15,17,17,16,18,17,18, 0, 0,
  133427. };
  133428. static float _vq_quantthresh__44u2__p6_0[] = {
  133429. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  133430. 12.5, 17.5, 22.5, 27.5,
  133431. };
  133432. static long _vq_quantmap__44u2__p6_0[] = {
  133433. 11, 9, 7, 5, 3, 1, 0, 2,
  133434. 4, 6, 8, 10, 12,
  133435. };
  133436. static encode_aux_threshmatch _vq_auxt__44u2__p6_0 = {
  133437. _vq_quantthresh__44u2__p6_0,
  133438. _vq_quantmap__44u2__p6_0,
  133439. 13,
  133440. 13
  133441. };
  133442. static static_codebook _44u2__p6_0 = {
  133443. 2, 169,
  133444. _vq_lengthlist__44u2__p6_0,
  133445. 1, -526516224, 1616117760, 4, 0,
  133446. _vq_quantlist__44u2__p6_0,
  133447. NULL,
  133448. &_vq_auxt__44u2__p6_0,
  133449. NULL,
  133450. 0
  133451. };
  133452. static long _vq_quantlist__44u2__p6_1[] = {
  133453. 2,
  133454. 1,
  133455. 3,
  133456. 0,
  133457. 4,
  133458. };
  133459. static long _vq_lengthlist__44u2__p6_1[] = {
  133460. 2, 4, 4, 5, 5, 4, 5, 5, 6, 5, 4, 5, 5, 5, 6, 5,
  133461. 6, 5, 6, 6, 5, 5, 6, 6, 6,
  133462. };
  133463. static float _vq_quantthresh__44u2__p6_1[] = {
  133464. -1.5, -0.5, 0.5, 1.5,
  133465. };
  133466. static long _vq_quantmap__44u2__p6_1[] = {
  133467. 3, 1, 0, 2, 4,
  133468. };
  133469. static encode_aux_threshmatch _vq_auxt__44u2__p6_1 = {
  133470. _vq_quantthresh__44u2__p6_1,
  133471. _vq_quantmap__44u2__p6_1,
  133472. 5,
  133473. 5
  133474. };
  133475. static static_codebook _44u2__p6_1 = {
  133476. 2, 25,
  133477. _vq_lengthlist__44u2__p6_1,
  133478. 1, -533725184, 1611661312, 3, 0,
  133479. _vq_quantlist__44u2__p6_1,
  133480. NULL,
  133481. &_vq_auxt__44u2__p6_1,
  133482. NULL,
  133483. 0
  133484. };
  133485. static long _vq_quantlist__44u2__p7_0[] = {
  133486. 4,
  133487. 3,
  133488. 5,
  133489. 2,
  133490. 6,
  133491. 1,
  133492. 7,
  133493. 0,
  133494. 8,
  133495. };
  133496. static long _vq_lengthlist__44u2__p7_0[] = {
  133497. 1, 3, 2,12,12,12,12,12,12, 4,12,12,12,12,12,12,
  133498. 12,12, 5,12,12,12,12,12,12,12,12,12,12,11,11,11,
  133499. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  133500. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  133501. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  133502. 11,
  133503. };
  133504. static float _vq_quantthresh__44u2__p7_0[] = {
  133505. -591.5, -422.5, -253.5, -84.5, 84.5, 253.5, 422.5, 591.5,
  133506. };
  133507. static long _vq_quantmap__44u2__p7_0[] = {
  133508. 7, 5, 3, 1, 0, 2, 4, 6,
  133509. 8,
  133510. };
  133511. static encode_aux_threshmatch _vq_auxt__44u2__p7_0 = {
  133512. _vq_quantthresh__44u2__p7_0,
  133513. _vq_quantmap__44u2__p7_0,
  133514. 9,
  133515. 9
  133516. };
  133517. static static_codebook _44u2__p7_0 = {
  133518. 2, 81,
  133519. _vq_lengthlist__44u2__p7_0,
  133520. 1, -516612096, 1626677248, 4, 0,
  133521. _vq_quantlist__44u2__p7_0,
  133522. NULL,
  133523. &_vq_auxt__44u2__p7_0,
  133524. NULL,
  133525. 0
  133526. };
  133527. static long _vq_quantlist__44u2__p7_1[] = {
  133528. 6,
  133529. 5,
  133530. 7,
  133531. 4,
  133532. 8,
  133533. 3,
  133534. 9,
  133535. 2,
  133536. 10,
  133537. 1,
  133538. 11,
  133539. 0,
  133540. 12,
  133541. };
  133542. static long _vq_lengthlist__44u2__p7_1[] = {
  133543. 1, 4, 4, 7, 6, 7, 6, 8, 7, 9, 7, 9, 8, 4, 7, 6,
  133544. 8, 8, 9, 8,10, 9,10,10,11,11, 4, 7, 7, 8, 8, 8,
  133545. 8, 9,10,11,11,11,11, 6, 8, 8,10,10,10,10,11,11,
  133546. 12,12,12,12, 7, 8, 8,10,10,10,10,11,11,12,12,13,
  133547. 13, 7, 9, 9,11,10,12,12,13,13,14,13,14,14, 7, 9,
  133548. 9,10,11,11,12,13,13,13,13,16,14, 9,10,10,12,12,
  133549. 13,13,14,14,15,16,15,16, 9,10,10,12,12,12,13,14,
  133550. 14,14,15,16,15,10,12,12,13,13,15,13,16,16,15,17,
  133551. 17,17,10,11,11,12,14,14,14,15,15,17,17,15,17,11,
  133552. 12,12,14,14,14,15,15,15,17,16,17,17,10,12,12,13,
  133553. 14,14,14,17,15,17,17,17,17,
  133554. };
  133555. static float _vq_quantthresh__44u2__p7_1[] = {
  133556. -71.5, -58.5, -45.5, -32.5, -19.5, -6.5, 6.5, 19.5,
  133557. 32.5, 45.5, 58.5, 71.5,
  133558. };
  133559. static long _vq_quantmap__44u2__p7_1[] = {
  133560. 11, 9, 7, 5, 3, 1, 0, 2,
  133561. 4, 6, 8, 10, 12,
  133562. };
  133563. static encode_aux_threshmatch _vq_auxt__44u2__p7_1 = {
  133564. _vq_quantthresh__44u2__p7_1,
  133565. _vq_quantmap__44u2__p7_1,
  133566. 13,
  133567. 13
  133568. };
  133569. static static_codebook _44u2__p7_1 = {
  133570. 2, 169,
  133571. _vq_lengthlist__44u2__p7_1,
  133572. 1, -523010048, 1618608128, 4, 0,
  133573. _vq_quantlist__44u2__p7_1,
  133574. NULL,
  133575. &_vq_auxt__44u2__p7_1,
  133576. NULL,
  133577. 0
  133578. };
  133579. static long _vq_quantlist__44u2__p7_2[] = {
  133580. 6,
  133581. 5,
  133582. 7,
  133583. 4,
  133584. 8,
  133585. 3,
  133586. 9,
  133587. 2,
  133588. 10,
  133589. 1,
  133590. 11,
  133591. 0,
  133592. 12,
  133593. };
  133594. static long _vq_lengthlist__44u2__p7_2[] = {
  133595. 2, 5, 5, 6, 6, 7, 7, 8, 7, 8, 8, 8, 8, 5, 6, 6,
  133596. 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 5, 6, 6, 7, 7, 8,
  133597. 7, 8, 8, 8, 8, 8, 8, 6, 7, 7, 7, 8, 8, 8, 8, 8,
  133598. 9, 9, 9, 9, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  133599. 9, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 7, 8,
  133600. 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 9,
  133601. 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 9, 9, 9, 9, 9,
  133602. 9, 9, 9, 9, 9, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133603. 9, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8,
  133604. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 9, 9, 9,
  133605. 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133606. };
  133607. static float _vq_quantthresh__44u2__p7_2[] = {
  133608. -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
  133609. 2.5, 3.5, 4.5, 5.5,
  133610. };
  133611. static long _vq_quantmap__44u2__p7_2[] = {
  133612. 11, 9, 7, 5, 3, 1, 0, 2,
  133613. 4, 6, 8, 10, 12,
  133614. };
  133615. static encode_aux_threshmatch _vq_auxt__44u2__p7_2 = {
  133616. _vq_quantthresh__44u2__p7_2,
  133617. _vq_quantmap__44u2__p7_2,
  133618. 13,
  133619. 13
  133620. };
  133621. static static_codebook _44u2__p7_2 = {
  133622. 2, 169,
  133623. _vq_lengthlist__44u2__p7_2,
  133624. 1, -531103744, 1611661312, 4, 0,
  133625. _vq_quantlist__44u2__p7_2,
  133626. NULL,
  133627. &_vq_auxt__44u2__p7_2,
  133628. NULL,
  133629. 0
  133630. };
  133631. static long _huff_lengthlist__44u2__short[] = {
  133632. 13,15,17,17,15,15,12,17,11, 9, 7,10,10, 9,12,17,
  133633. 10, 6, 3, 6, 5, 7,10,17,15,10, 6, 9, 8, 9,11,17,
  133634. 15, 8, 4, 7, 3, 5, 9,16,16,10, 5, 8, 4, 5, 8,16,
  133635. 13,11, 5, 8, 3, 3, 5,14,13,12, 7,10, 5, 5, 7,14,
  133636. };
  133637. static static_codebook _huff_book__44u2__short = {
  133638. 2, 64,
  133639. _huff_lengthlist__44u2__short,
  133640. 0, 0, 0, 0, 0,
  133641. NULL,
  133642. NULL,
  133643. NULL,
  133644. NULL,
  133645. 0
  133646. };
  133647. static long _huff_lengthlist__44u3__long[] = {
  133648. 6, 9,13,12,14,11,10,13, 8, 4, 5, 7, 8, 7, 8,12,
  133649. 11, 4, 3, 5, 5, 7, 9,14,11, 6, 5, 6, 6, 6, 7,13,
  133650. 13, 7, 5, 6, 4, 5, 7,14,11, 7, 6, 6, 5, 5, 6,13,
  133651. 9, 7, 8, 6, 7, 5, 3, 9, 9,12,13,12,14,10, 6, 7,
  133652. };
  133653. static static_codebook _huff_book__44u3__long = {
  133654. 2, 64,
  133655. _huff_lengthlist__44u3__long,
  133656. 0, 0, 0, 0, 0,
  133657. NULL,
  133658. NULL,
  133659. NULL,
  133660. NULL,
  133661. 0
  133662. };
  133663. static long _vq_quantlist__44u3__p1_0[] = {
  133664. 1,
  133665. 0,
  133666. 2,
  133667. };
  133668. static long _vq_lengthlist__44u3__p1_0[] = {
  133669. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,10,11, 8,
  133670. 10,11, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  133671. 11, 8,11,11, 8,11,11,11,13,14,11,14,14, 8,11,11,
  133672. 10,14,12,11,14,14, 4, 8, 8, 8,11,11, 8,11,11, 7,
  133673. 11,11,11,14,14,10,12,14, 8,11,11,11,14,14,11,14,
  133674. 13,
  133675. };
  133676. static float _vq_quantthresh__44u3__p1_0[] = {
  133677. -0.5, 0.5,
  133678. };
  133679. static long _vq_quantmap__44u3__p1_0[] = {
  133680. 1, 0, 2,
  133681. };
  133682. static encode_aux_threshmatch _vq_auxt__44u3__p1_0 = {
  133683. _vq_quantthresh__44u3__p1_0,
  133684. _vq_quantmap__44u3__p1_0,
  133685. 3,
  133686. 3
  133687. };
  133688. static static_codebook _44u3__p1_0 = {
  133689. 4, 81,
  133690. _vq_lengthlist__44u3__p1_0,
  133691. 1, -535822336, 1611661312, 2, 0,
  133692. _vq_quantlist__44u3__p1_0,
  133693. NULL,
  133694. &_vq_auxt__44u3__p1_0,
  133695. NULL,
  133696. 0
  133697. };
  133698. static long _vq_quantlist__44u3__p2_0[] = {
  133699. 1,
  133700. 0,
  133701. 2,
  133702. };
  133703. static long _vq_lengthlist__44u3__p2_0[] = {
  133704. 2, 5, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 7, 8, 8, 6,
  133705. 8, 8, 5, 6, 6, 6, 8, 8, 7, 8, 8, 5, 7, 6, 7, 8,
  133706. 8, 6, 8, 8, 7, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  133707. 8,10, 8, 8,10,10, 5, 6, 6, 6, 8, 8, 7, 8, 8, 6,
  133708. 8, 8, 8,10,10, 8, 8,10, 7, 8, 8, 8,10,10, 8,10,
  133709. 9,
  133710. };
  133711. static float _vq_quantthresh__44u3__p2_0[] = {
  133712. -0.5, 0.5,
  133713. };
  133714. static long _vq_quantmap__44u3__p2_0[] = {
  133715. 1, 0, 2,
  133716. };
  133717. static encode_aux_threshmatch _vq_auxt__44u3__p2_0 = {
  133718. _vq_quantthresh__44u3__p2_0,
  133719. _vq_quantmap__44u3__p2_0,
  133720. 3,
  133721. 3
  133722. };
  133723. static static_codebook _44u3__p2_0 = {
  133724. 4, 81,
  133725. _vq_lengthlist__44u3__p2_0,
  133726. 1, -535822336, 1611661312, 2, 0,
  133727. _vq_quantlist__44u3__p2_0,
  133728. NULL,
  133729. &_vq_auxt__44u3__p2_0,
  133730. NULL,
  133731. 0
  133732. };
  133733. static long _vq_quantlist__44u3__p3_0[] = {
  133734. 2,
  133735. 1,
  133736. 3,
  133737. 0,
  133738. 4,
  133739. };
  133740. static long _vq_lengthlist__44u3__p3_0[] = {
  133741. 2, 4, 4, 7, 7, 5, 7, 7, 9, 9, 5, 7, 7, 9, 9, 8,
  133742. 9, 9,12,12, 8, 9, 9,11,12, 5, 7, 7,10,10, 7, 9,
  133743. 9,11,11, 7, 9, 9,10,11,10,11,11,13,13, 9,10,11,
  133744. 13,13, 5, 7, 7,10,10, 7, 9, 9,11,10, 7, 9, 9,11,
  133745. 11, 9,11,10,13,13,10,11,11,14,13, 8,10,10,14,13,
  133746. 10,11,11,15,14, 9,11,11,14,14,13,14,13,16,16,12,
  133747. 13,13,15,15, 8,10,10,13,14, 9,11,11,14,14,10,11,
  133748. 11,14,15,12,13,13,15,15,13,14,14,15,16, 5, 7, 7,
  133749. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,12,10,11,11,14,
  133750. 14,10,11,11,14,14, 7, 9, 9,12,12, 9,11,11,13,13,
  133751. 9,11,11,13,13,12,12,13,15,15,11,12,13,15,16, 7,
  133752. 9, 9,11,11, 8,11,10,13,12, 9,11,11,13,13,11,13,
  133753. 12,15,13,11,13,13,15,16, 9,12,11,15,14,11,12,13,
  133754. 16,15,11,13,13,15,16,14,14,15,17,16,13,15,16, 0,
  133755. 17, 9,11,11,15,15,10,13,12,15,15,11,13,13,15,16,
  133756. 13,15,13,16,15,14,16,15, 0,19, 5, 7, 7,10,10, 7,
  133757. 9, 9,11,11, 7, 9, 9,11,11,10,12,11,14,14,10,11,
  133758. 12,14,14, 7, 9, 9,12,12, 9,11,11,14,13, 9,10,11,
  133759. 12,13,11,13,13,16,16,11,12,13,13,16, 7, 9, 9,12,
  133760. 12, 9,11,11,13,13, 9,11,11,13,13,11,13,13,15,15,
  133761. 12,13,12,15,14, 9,11,11,15,14,11,13,12,16,16,10,
  133762. 12,12,15,15,13,15,15,17,19,13,14,15,16,17,10,12,
  133763. 12,15,15,11,13,13,16,16,11,13,13,15,16,13,15,15,
  133764. 0, 0,14,15,15,16,16, 8,10,10,14,14,10,12,12,15,
  133765. 15,10,12,11,15,16,14,15,15,19,20,13,14,14,18,16,
  133766. 9,11,11,15,15,11,13,13,17,16,11,13,13,16,16,15,
  133767. 17,17,20,20,14,15,16,17,20, 9,11,11,15,15,10,13,
  133768. 12,16,15,11,13,13,15,17,14,16,15,18, 0,14,16,15,
  133769. 18,20,12,14,14, 0, 0,14,14,16, 0, 0,13,16,15, 0,
  133770. 0,17,17,18, 0, 0,16,17,19,19, 0,12,14,14,18, 0,
  133771. 12,16,14, 0,17,13,15,15,18, 0,16,18,17, 0,17,16,
  133772. 18,17, 0, 0, 7,10,10,14,14,10,12,11,15,15,10,12,
  133773. 12,16,15,13,15,15,18, 0,14,15,15,17, 0, 9,11,11,
  133774. 15,15,11,13,13,16,16,11,12,13,16,16,14,15,16,17,
  133775. 17,14,16,16,16,18, 9,11,12,16,16,11,13,13,17,17,
  133776. 11,14,13,20,17,15,16,16,19, 0,15,16,17, 0,19,11,
  133777. 13,14,17,16,14,15,15,20,18,13,14,15,17,19,16,18,
  133778. 18, 0,20,16,16,19,17, 0,12,15,14,17, 0,14,15,15,
  133779. 18,19,13,16,15,19,20,15,18,18, 0,20,17, 0,16, 0,
  133780. 0,
  133781. };
  133782. static float _vq_quantthresh__44u3__p3_0[] = {
  133783. -1.5, -0.5, 0.5, 1.5,
  133784. };
  133785. static long _vq_quantmap__44u3__p3_0[] = {
  133786. 3, 1, 0, 2, 4,
  133787. };
  133788. static encode_aux_threshmatch _vq_auxt__44u3__p3_0 = {
  133789. _vq_quantthresh__44u3__p3_0,
  133790. _vq_quantmap__44u3__p3_0,
  133791. 5,
  133792. 5
  133793. };
  133794. static static_codebook _44u3__p3_0 = {
  133795. 4, 625,
  133796. _vq_lengthlist__44u3__p3_0,
  133797. 1, -533725184, 1611661312, 3, 0,
  133798. _vq_quantlist__44u3__p3_0,
  133799. NULL,
  133800. &_vq_auxt__44u3__p3_0,
  133801. NULL,
  133802. 0
  133803. };
  133804. static long _vq_quantlist__44u3__p4_0[] = {
  133805. 2,
  133806. 1,
  133807. 3,
  133808. 0,
  133809. 4,
  133810. };
  133811. static long _vq_lengthlist__44u3__p4_0[] = {
  133812. 4, 5, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 9,
  133813. 9, 9,11,11, 9, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  133814. 8,10,10, 7, 7, 8,10,10, 9,10,10,11,12, 9,10,10,
  133815. 11,12, 5, 7, 7, 9, 9, 7, 8, 7,10,10, 7, 8, 8,10,
  133816. 10, 9,10, 9,12,11, 9,10,10,12,11, 9,10, 9,12,12,
  133817. 9,10,10,13,12, 9,10,10,12,13,12,12,12,14,14,11,
  133818. 12,12,13,14, 9, 9,10,12,12, 9,10,10,12,12, 9,10,
  133819. 10,12,13,11,12,11,14,13,12,12,12,14,13, 5, 7, 7,
  133820. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,
  133821. 12, 9,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,11,11,
  133822. 8, 9, 9,11,11,11,11,11,12,13,10,11,11,13,13, 6,
  133823. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  133824. 10,13,11,10,11,11,13,13, 9,11,10,13,12,10,11,11,
  133825. 13,13,10,11,11,13,13,12,12,13,12,15,12,13,13,15,
  133826. 15, 9,10,10,12,13,10,11,10,13,12,10,11,11,13,14,
  133827. 12,13,11,15,13,12,13,13,15,15, 5, 7, 7, 9, 9, 7,
  133828. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12,10,10,
  133829. 11,12,12, 6, 8, 8,10,10, 8, 9, 9,11,11, 7, 8, 9,
  133830. 10,11,10,11,11,13,13,10,10,11,11,13, 7, 8, 8,10,
  133831. 10, 8, 9, 9,11,11, 8, 9, 9,11,11,10,11,11,13,13,
  133832. 11,11,11,13,12, 9,10,10,13,12,10,11,11,14,13,10,
  133833. 10,11,12,13,12,13,13,15,15,12,11,13,13,14, 9,10,
  133834. 11,12,13,10,11,11,13,13,10,11,11,13,13,12,13,13,
  133835. 15,15,12,13,12,15,12, 8, 9, 9,12,12, 9,11,10,13,
  133836. 13, 9,10,10,13,13,12,13,13,15,14,12,12,12,14,13,
  133837. 9,10,10,13,12,10,11,11,13,13,10,11,11,14,12,13,
  133838. 13,14,14,16,12,13,13,15,15, 9,10,10,13,13,10,11,
  133839. 10,14,13,10,11,11,13,14,12,14,13,15,14,13,13,13,
  133840. 15,15,11,13,12,15,14,11,12,13,14,15,12,13,13,16,
  133841. 14,14,12,15,12,16,14,15,15,17,15,11,12,12,14,14,
  133842. 11,13,11,15,14,12,13,13,15,15,13,15,12,17,13,14,
  133843. 15,15,16,16, 8, 9, 9,12,12, 9,10,10,12,13, 9,10,
  133844. 10,13,13,12,12,12,14,14,12,13,13,15,15, 9,10,10,
  133845. 13,12,10,11,11,14,13,10,10,11,13,14,12,13,13,15,
  133846. 15,12,12,13,14,16, 9,10,10,13,13,10,11,11,13,14,
  133847. 10,11,11,14,13,12,13,13,14,15,13,14,13,16,14,11,
  133848. 12,12,14,14,12,13,13,15,14,11,12,13,14,15,14,15,
  133849. 15,16,16,13,13,15,13,16,11,12,12,14,15,12,13,13,
  133850. 14,15,11,13,12,15,14,14,15,15,16,16,14,15,12,16,
  133851. 13,
  133852. };
  133853. static float _vq_quantthresh__44u3__p4_0[] = {
  133854. -1.5, -0.5, 0.5, 1.5,
  133855. };
  133856. static long _vq_quantmap__44u3__p4_0[] = {
  133857. 3, 1, 0, 2, 4,
  133858. };
  133859. static encode_aux_threshmatch _vq_auxt__44u3__p4_0 = {
  133860. _vq_quantthresh__44u3__p4_0,
  133861. _vq_quantmap__44u3__p4_0,
  133862. 5,
  133863. 5
  133864. };
  133865. static static_codebook _44u3__p4_0 = {
  133866. 4, 625,
  133867. _vq_lengthlist__44u3__p4_0,
  133868. 1, -533725184, 1611661312, 3, 0,
  133869. _vq_quantlist__44u3__p4_0,
  133870. NULL,
  133871. &_vq_auxt__44u3__p4_0,
  133872. NULL,
  133873. 0
  133874. };
  133875. static long _vq_quantlist__44u3__p5_0[] = {
  133876. 4,
  133877. 3,
  133878. 5,
  133879. 2,
  133880. 6,
  133881. 1,
  133882. 7,
  133883. 0,
  133884. 8,
  133885. };
  133886. static long _vq_lengthlist__44u3__p5_0[] = {
  133887. 2, 3, 3, 6, 6, 7, 7, 9, 9, 4, 5, 5, 7, 7, 8, 8,
  133888. 10,10, 4, 5, 5, 7, 7, 8, 8,10,10, 6, 7, 7, 8, 8,
  133889. 9, 9,11,10, 6, 7, 7, 8, 8, 9, 9,10,10, 7, 8, 8,
  133890. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  133891. 10,10,11,10,11,11,12,12, 9,10,10,10,10,11,11,12,
  133892. 12,
  133893. };
  133894. static float _vq_quantthresh__44u3__p5_0[] = {
  133895. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  133896. };
  133897. static long _vq_quantmap__44u3__p5_0[] = {
  133898. 7, 5, 3, 1, 0, 2, 4, 6,
  133899. 8,
  133900. };
  133901. static encode_aux_threshmatch _vq_auxt__44u3__p5_0 = {
  133902. _vq_quantthresh__44u3__p5_0,
  133903. _vq_quantmap__44u3__p5_0,
  133904. 9,
  133905. 9
  133906. };
  133907. static static_codebook _44u3__p5_0 = {
  133908. 2, 81,
  133909. _vq_lengthlist__44u3__p5_0,
  133910. 1, -531628032, 1611661312, 4, 0,
  133911. _vq_quantlist__44u3__p5_0,
  133912. NULL,
  133913. &_vq_auxt__44u3__p5_0,
  133914. NULL,
  133915. 0
  133916. };
  133917. static long _vq_quantlist__44u3__p6_0[] = {
  133918. 6,
  133919. 5,
  133920. 7,
  133921. 4,
  133922. 8,
  133923. 3,
  133924. 9,
  133925. 2,
  133926. 10,
  133927. 1,
  133928. 11,
  133929. 0,
  133930. 12,
  133931. };
  133932. static long _vq_lengthlist__44u3__p6_0[] = {
  133933. 1, 4, 4, 6, 6, 8, 8, 9, 9,10,11,13,14, 4, 6, 5,
  133934. 8, 8, 9, 9,10,10,11,11,14,14, 4, 6, 6, 8, 8, 9,
  133935. 9,10,10,11,11,14,14, 6, 8, 8, 9, 9,10,10,11,11,
  133936. 12,12,15,15, 6, 8, 8, 9, 9,10,11,11,11,12,12,15,
  133937. 15, 8, 9, 9,11,10,11,11,12,12,13,13,15,16, 8, 9,
  133938. 9,10,11,11,11,12,12,13,13,16,16,10,10,11,11,11,
  133939. 12,12,13,13,13,14,17,16, 9,10,11,12,11,12,12,13,
  133940. 13,13,13,16,18,11,12,11,12,12,13,13,13,14,15,14,
  133941. 17,17,11,11,12,12,12,13,13,13,14,14,15,18,17,14,
  133942. 15,15,15,15,16,16,17,17,19,18, 0,20,14,15,14,15,
  133943. 15,16,16,16,17,18,16,20,18,
  133944. };
  133945. static float _vq_quantthresh__44u3__p6_0[] = {
  133946. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  133947. 12.5, 17.5, 22.5, 27.5,
  133948. };
  133949. static long _vq_quantmap__44u3__p6_0[] = {
  133950. 11, 9, 7, 5, 3, 1, 0, 2,
  133951. 4, 6, 8, 10, 12,
  133952. };
  133953. static encode_aux_threshmatch _vq_auxt__44u3__p6_0 = {
  133954. _vq_quantthresh__44u3__p6_0,
  133955. _vq_quantmap__44u3__p6_0,
  133956. 13,
  133957. 13
  133958. };
  133959. static static_codebook _44u3__p6_0 = {
  133960. 2, 169,
  133961. _vq_lengthlist__44u3__p6_0,
  133962. 1, -526516224, 1616117760, 4, 0,
  133963. _vq_quantlist__44u3__p6_0,
  133964. NULL,
  133965. &_vq_auxt__44u3__p6_0,
  133966. NULL,
  133967. 0
  133968. };
  133969. static long _vq_quantlist__44u3__p6_1[] = {
  133970. 2,
  133971. 1,
  133972. 3,
  133973. 0,
  133974. 4,
  133975. };
  133976. static long _vq_lengthlist__44u3__p6_1[] = {
  133977. 2, 4, 4, 5, 5, 4, 5, 5, 6, 5, 4, 5, 5, 5, 6, 5,
  133978. 6, 5, 6, 6, 5, 5, 6, 6, 6,
  133979. };
  133980. static float _vq_quantthresh__44u3__p6_1[] = {
  133981. -1.5, -0.5, 0.5, 1.5,
  133982. };
  133983. static long _vq_quantmap__44u3__p6_1[] = {
  133984. 3, 1, 0, 2, 4,
  133985. };
  133986. static encode_aux_threshmatch _vq_auxt__44u3__p6_1 = {
  133987. _vq_quantthresh__44u3__p6_1,
  133988. _vq_quantmap__44u3__p6_1,
  133989. 5,
  133990. 5
  133991. };
  133992. static static_codebook _44u3__p6_1 = {
  133993. 2, 25,
  133994. _vq_lengthlist__44u3__p6_1,
  133995. 1, -533725184, 1611661312, 3, 0,
  133996. _vq_quantlist__44u3__p6_1,
  133997. NULL,
  133998. &_vq_auxt__44u3__p6_1,
  133999. NULL,
  134000. 0
  134001. };
  134002. static long _vq_quantlist__44u3__p7_0[] = {
  134003. 4,
  134004. 3,
  134005. 5,
  134006. 2,
  134007. 6,
  134008. 1,
  134009. 7,
  134010. 0,
  134011. 8,
  134012. };
  134013. static long _vq_lengthlist__44u3__p7_0[] = {
  134014. 1, 3, 3,10,10,10,10,10,10, 4,10,10,10,10,10,10,
  134015. 10,10, 4,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  134016. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  134017. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  134018. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  134019. 9,
  134020. };
  134021. static float _vq_quantthresh__44u3__p7_0[] = {
  134022. -892.5, -637.5, -382.5, -127.5, 127.5, 382.5, 637.5, 892.5,
  134023. };
  134024. static long _vq_quantmap__44u3__p7_0[] = {
  134025. 7, 5, 3, 1, 0, 2, 4, 6,
  134026. 8,
  134027. };
  134028. static encode_aux_threshmatch _vq_auxt__44u3__p7_0 = {
  134029. _vq_quantthresh__44u3__p7_0,
  134030. _vq_quantmap__44u3__p7_0,
  134031. 9,
  134032. 9
  134033. };
  134034. static static_codebook _44u3__p7_0 = {
  134035. 2, 81,
  134036. _vq_lengthlist__44u3__p7_0,
  134037. 1, -515907584, 1627381760, 4, 0,
  134038. _vq_quantlist__44u3__p7_0,
  134039. NULL,
  134040. &_vq_auxt__44u3__p7_0,
  134041. NULL,
  134042. 0
  134043. };
  134044. static long _vq_quantlist__44u3__p7_1[] = {
  134045. 7,
  134046. 6,
  134047. 8,
  134048. 5,
  134049. 9,
  134050. 4,
  134051. 10,
  134052. 3,
  134053. 11,
  134054. 2,
  134055. 12,
  134056. 1,
  134057. 13,
  134058. 0,
  134059. 14,
  134060. };
  134061. static long _vq_lengthlist__44u3__p7_1[] = {
  134062. 1, 4, 4, 6, 6, 7, 6, 8, 7, 9, 8,10, 9,11,11, 4,
  134063. 7, 7, 8, 7, 9, 9,10,10,11,11,11,11,12,12, 4, 7,
  134064. 7, 7, 7, 9, 9,10,10,11,11,12,12,12,11, 6, 8, 8,
  134065. 9, 9,10,10,11,11,12,12,13,12,13,13, 6, 8, 8, 9,
  134066. 9,10,11,11,11,12,12,13,14,13,13, 8, 9, 9,11,11,
  134067. 12,12,12,13,14,13,14,14,14,15, 8, 9, 9,11,11,11,
  134068. 12,13,14,13,14,15,17,14,15, 9,10,10,12,12,13,13,
  134069. 13,14,15,15,15,16,16,16, 9,11,11,12,12,13,13,14,
  134070. 14,14,15,16,16,16,16,10,12,12,13,13,14,14,15,15,
  134071. 15,16,17,17,17,17,10,12,11,13,13,15,14,15,14,16,
  134072. 17,16,16,16,16,11,13,12,14,14,14,14,15,16,17,16,
  134073. 17,17,17,17,11,13,12,14,14,14,15,17,16,17,17,17,
  134074. 17,17,17,12,13,13,15,16,15,16,17,17,16,16,17,17,
  134075. 17,17,12,13,13,15,15,15,16,17,17,17,16,17,16,17,
  134076. 17,
  134077. };
  134078. static float _vq_quantthresh__44u3__p7_1[] = {
  134079. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  134080. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  134081. };
  134082. static long _vq_quantmap__44u3__p7_1[] = {
  134083. 13, 11, 9, 7, 5, 3, 1, 0,
  134084. 2, 4, 6, 8, 10, 12, 14,
  134085. };
  134086. static encode_aux_threshmatch _vq_auxt__44u3__p7_1 = {
  134087. _vq_quantthresh__44u3__p7_1,
  134088. _vq_quantmap__44u3__p7_1,
  134089. 15,
  134090. 15
  134091. };
  134092. static static_codebook _44u3__p7_1 = {
  134093. 2, 225,
  134094. _vq_lengthlist__44u3__p7_1,
  134095. 1, -522338304, 1620115456, 4, 0,
  134096. _vq_quantlist__44u3__p7_1,
  134097. NULL,
  134098. &_vq_auxt__44u3__p7_1,
  134099. NULL,
  134100. 0
  134101. };
  134102. static long _vq_quantlist__44u3__p7_2[] = {
  134103. 8,
  134104. 7,
  134105. 9,
  134106. 6,
  134107. 10,
  134108. 5,
  134109. 11,
  134110. 4,
  134111. 12,
  134112. 3,
  134113. 13,
  134114. 2,
  134115. 14,
  134116. 1,
  134117. 15,
  134118. 0,
  134119. 16,
  134120. };
  134121. static long _vq_lengthlist__44u3__p7_2[] = {
  134122. 2, 5, 5, 7, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  134123. 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134124. 10,10, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 8, 9, 9, 9,
  134125. 9,10, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134126. 10,10,10,10, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,
  134127. 9,10,10,10,10, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134128. 10,10,10,10,10,10, 7, 8, 8, 9, 8, 9, 9, 9, 9,10,
  134129. 9,10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134130. 9,10,10,10,10,10,10,10, 8, 9, 8, 9, 9, 9, 9,10,
  134131. 9,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9,10,
  134132. 9,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,
  134133. 9,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,10, 9,
  134134. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,10,
  134135. 10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  134136. 10,10,10,10,10,10,10,10,10,10,10,10,10,11, 9,10,
  134137. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,11, 9,
  134138. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  134139. 9,10,10,10,10,10,10,10,10,10,10,10,11,11,11,10,
  134140. 11,
  134141. };
  134142. static float _vq_quantthresh__44u3__p7_2[] = {
  134143. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  134144. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  134145. };
  134146. static long _vq_quantmap__44u3__p7_2[] = {
  134147. 15, 13, 11, 9, 7, 5, 3, 1,
  134148. 0, 2, 4, 6, 8, 10, 12, 14,
  134149. 16,
  134150. };
  134151. static encode_aux_threshmatch _vq_auxt__44u3__p7_2 = {
  134152. _vq_quantthresh__44u3__p7_2,
  134153. _vq_quantmap__44u3__p7_2,
  134154. 17,
  134155. 17
  134156. };
  134157. static static_codebook _44u3__p7_2 = {
  134158. 2, 289,
  134159. _vq_lengthlist__44u3__p7_2,
  134160. 1, -529530880, 1611661312, 5, 0,
  134161. _vq_quantlist__44u3__p7_2,
  134162. NULL,
  134163. &_vq_auxt__44u3__p7_2,
  134164. NULL,
  134165. 0
  134166. };
  134167. static long _huff_lengthlist__44u3__short[] = {
  134168. 14,14,14,15,13,15,12,16,10, 8, 7, 9, 9, 8,12,16,
  134169. 10, 5, 4, 6, 5, 6, 9,16,14, 8, 6, 8, 7, 8,10,16,
  134170. 14, 7, 4, 6, 3, 5, 8,16,15, 9, 5, 7, 4, 4, 7,16,
  134171. 13,10, 6, 7, 4, 3, 4,13,13,12, 7, 9, 5, 5, 6,12,
  134172. };
  134173. static static_codebook _huff_book__44u3__short = {
  134174. 2, 64,
  134175. _huff_lengthlist__44u3__short,
  134176. 0, 0, 0, 0, 0,
  134177. NULL,
  134178. NULL,
  134179. NULL,
  134180. NULL,
  134181. 0
  134182. };
  134183. static long _huff_lengthlist__44u4__long[] = {
  134184. 3, 8,12,12,13,12,11,13, 5, 4, 6, 7, 8, 8, 9,13,
  134185. 9, 5, 4, 5, 5, 7, 9,13, 9, 6, 5, 6, 6, 7, 8,12,
  134186. 12, 7, 5, 6, 4, 5, 8,13,11, 7, 6, 6, 5, 5, 6,12,
  134187. 10, 8, 8, 7, 7, 5, 3, 8,10,12,13,12,12, 9, 6, 7,
  134188. };
  134189. static static_codebook _huff_book__44u4__long = {
  134190. 2, 64,
  134191. _huff_lengthlist__44u4__long,
  134192. 0, 0, 0, 0, 0,
  134193. NULL,
  134194. NULL,
  134195. NULL,
  134196. NULL,
  134197. 0
  134198. };
  134199. static long _vq_quantlist__44u4__p1_0[] = {
  134200. 1,
  134201. 0,
  134202. 2,
  134203. };
  134204. static long _vq_lengthlist__44u4__p1_0[] = {
  134205. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,10,11, 8,
  134206. 10,11, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  134207. 11, 8,11,11, 8,11,11,11,13,14,11,15,14, 8,11,11,
  134208. 10,13,12,11,14,14, 4, 8, 8, 8,11,11, 8,11,11, 7,
  134209. 11,11,11,15,14,10,12,14, 8,11,11,11,14,14,11,14,
  134210. 13,
  134211. };
  134212. static float _vq_quantthresh__44u4__p1_0[] = {
  134213. -0.5, 0.5,
  134214. };
  134215. static long _vq_quantmap__44u4__p1_0[] = {
  134216. 1, 0, 2,
  134217. };
  134218. static encode_aux_threshmatch _vq_auxt__44u4__p1_0 = {
  134219. _vq_quantthresh__44u4__p1_0,
  134220. _vq_quantmap__44u4__p1_0,
  134221. 3,
  134222. 3
  134223. };
  134224. static static_codebook _44u4__p1_0 = {
  134225. 4, 81,
  134226. _vq_lengthlist__44u4__p1_0,
  134227. 1, -535822336, 1611661312, 2, 0,
  134228. _vq_quantlist__44u4__p1_0,
  134229. NULL,
  134230. &_vq_auxt__44u4__p1_0,
  134231. NULL,
  134232. 0
  134233. };
  134234. static long _vq_quantlist__44u4__p2_0[] = {
  134235. 1,
  134236. 0,
  134237. 2,
  134238. };
  134239. static long _vq_lengthlist__44u4__p2_0[] = {
  134240. 2, 5, 5, 5, 6, 6, 5, 6, 6, 5, 6, 6, 7, 8, 8, 6,
  134241. 8, 8, 5, 6, 6, 6, 8, 8, 7, 8, 8, 5, 7, 6, 6, 8,
  134242. 8, 6, 8, 8, 6, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  134243. 8,10, 8, 8,10,10, 5, 6, 6, 6, 8, 8, 6, 8, 8, 6,
  134244. 8, 8, 8,10,10, 8, 8,10, 6, 8, 8, 8,10,10, 8,10,
  134245. 9,
  134246. };
  134247. static float _vq_quantthresh__44u4__p2_0[] = {
  134248. -0.5, 0.5,
  134249. };
  134250. static long _vq_quantmap__44u4__p2_0[] = {
  134251. 1, 0, 2,
  134252. };
  134253. static encode_aux_threshmatch _vq_auxt__44u4__p2_0 = {
  134254. _vq_quantthresh__44u4__p2_0,
  134255. _vq_quantmap__44u4__p2_0,
  134256. 3,
  134257. 3
  134258. };
  134259. static static_codebook _44u4__p2_0 = {
  134260. 4, 81,
  134261. _vq_lengthlist__44u4__p2_0,
  134262. 1, -535822336, 1611661312, 2, 0,
  134263. _vq_quantlist__44u4__p2_0,
  134264. NULL,
  134265. &_vq_auxt__44u4__p2_0,
  134266. NULL,
  134267. 0
  134268. };
  134269. static long _vq_quantlist__44u4__p3_0[] = {
  134270. 2,
  134271. 1,
  134272. 3,
  134273. 0,
  134274. 4,
  134275. };
  134276. static long _vq_lengthlist__44u4__p3_0[] = {
  134277. 2, 4, 4, 8, 8, 5, 7, 7, 9, 9, 5, 7, 7, 9, 9, 8,
  134278. 10, 9,12,12, 8, 9,10,12,12, 5, 7, 7,10,10, 7, 9,
  134279. 9,11,11, 7, 9, 9,11,11,10,12,11,14,14, 9,10,11,
  134280. 13,14, 5, 7, 7,10,10, 7, 9, 9,11,11, 7, 9, 9,11,
  134281. 11, 9,11,10,14,13,10,11,11,14,14, 8,10,10,14,13,
  134282. 10,12,12,15,14, 9,11,11,15,14,13,14,14,17,17,12,
  134283. 14,14,16,16, 8,10,10,14,14, 9,11,11,14,15,10,12,
  134284. 12,14,15,12,14,13,16,16,13,14,15,15,18, 4, 7, 7,
  134285. 10,10, 7, 9, 9,12,11, 7, 9, 9,11,12,10,12,11,15,
  134286. 14,10,11,12,14,15, 7, 9, 9,12,12, 9,11,12,13,13,
  134287. 9,11,12,13,13,12,13,13,15,16,11,13,13,15,16, 7,
  134288. 9, 9,12,12, 9,11,10,13,12, 9,11,12,13,14,11,13,
  134289. 12,16,14,12,13,13,15,16,10,12,12,16,15,11,13,13,
  134290. 17,16,11,13,13,17,16,14,15,15,17,17,14,16,16,18,
  134291. 20, 9,11,11,15,16,11,13,12,16,16,11,13,13,16,17,
  134292. 14,15,14,18,16,14,16,16,17,20, 5, 7, 7,10,10, 7,
  134293. 9, 9,12,11, 7, 9,10,11,12,10,12,11,15,15,10,12,
  134294. 12,14,14, 7, 9, 9,12,12, 9,12,11,14,13, 9,10,11,
  134295. 12,13,12,13,14,16,16,11,12,13,14,16, 7, 9, 9,12,
  134296. 12, 9,12,11,13,13, 9,12,11,13,13,11,13,13,16,16,
  134297. 12,13,13,16,15, 9,11,11,16,14,11,13,13,16,16,11,
  134298. 12,13,16,16,14,16,16,17,17,13,14,15,16,17,10,12,
  134299. 12,15,15,11,13,13,16,17,11,13,13,16,16,14,16,15,
  134300. 19,19,14,15,15,17,18, 8,10,10,14,14,10,12,12,15,
  134301. 15,10,12,12,16,16,14,16,15,20,19,13,15,15,17,16,
  134302. 9,12,12,16,16,11,13,13,16,18,11,14,13,16,17,16,
  134303. 17,16,20, 0,15,16,18,18,20, 9,11,11,15,15,11,14,
  134304. 12,17,16,11,13,13,17,17,15,17,15,20,20,14,16,16,
  134305. 17, 0,13,15,14,18,16,14,15,16, 0,18,14,16,16, 0,
  134306. 0,18,16, 0, 0,20,16,18,18, 0, 0,12,14,14,17,18,
  134307. 13,15,14,20,18,14,16,15,19,19,16,20,16, 0,18,16,
  134308. 19,17,19, 0, 8,10,10,14,14,10,12,12,16,15,10,12,
  134309. 12,16,16,13,15,15,18,17,14,16,16,19, 0, 9,11,11,
  134310. 16,15,11,14,13,18,17,11,12,13,17,18,14,17,16,18,
  134311. 18,15,16,17,18,18, 9,12,12,16,16,11,13,13,16,18,
  134312. 11,14,13,17,17,15,16,16,18,20,16,17,17,20,20,12,
  134313. 14,14,18,17,14,16,16, 0,19,13,14,15,18, 0,16, 0,
  134314. 0, 0, 0,16,16, 0,19,20,13,15,14, 0, 0,14,16,16,
  134315. 18,19,14,16,15, 0,20,16,20,18, 0,20,17,20,17, 0,
  134316. 0,
  134317. };
  134318. static float _vq_quantthresh__44u4__p3_0[] = {
  134319. -1.5, -0.5, 0.5, 1.5,
  134320. };
  134321. static long _vq_quantmap__44u4__p3_0[] = {
  134322. 3, 1, 0, 2, 4,
  134323. };
  134324. static encode_aux_threshmatch _vq_auxt__44u4__p3_0 = {
  134325. _vq_quantthresh__44u4__p3_0,
  134326. _vq_quantmap__44u4__p3_0,
  134327. 5,
  134328. 5
  134329. };
  134330. static static_codebook _44u4__p3_0 = {
  134331. 4, 625,
  134332. _vq_lengthlist__44u4__p3_0,
  134333. 1, -533725184, 1611661312, 3, 0,
  134334. _vq_quantlist__44u4__p3_0,
  134335. NULL,
  134336. &_vq_auxt__44u4__p3_0,
  134337. NULL,
  134338. 0
  134339. };
  134340. static long _vq_quantlist__44u4__p4_0[] = {
  134341. 2,
  134342. 1,
  134343. 3,
  134344. 0,
  134345. 4,
  134346. };
  134347. static long _vq_lengthlist__44u4__p4_0[] = {
  134348. 4, 5, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 9,
  134349. 9, 9,11,11, 8, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  134350. 8,10,10, 7, 7, 8,10,10, 9,10,10,11,12, 9,10,10,
  134351. 11,12, 5, 7, 7, 9, 9, 7, 8, 7,10,10, 7, 8, 8,10,
  134352. 10, 9,10,10,12,11, 9,10,10,12,11, 9,10, 9,12,12,
  134353. 9,10,10,13,12, 9,10,10,12,12,12,12,12,14,14,11,
  134354. 12,12,13,14, 9, 9,10,12,12, 9,10,10,13,13, 9,10,
  134355. 10,12,13,11,12,12,14,13,11,12,12,14,14, 5, 7, 7,
  134356. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,
  134357. 12, 9,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,11,11,
  134358. 8, 9, 9,11,11,11,11,11,12,13,10,11,11,13,13, 6,
  134359. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  134360. 10,13,11,10,11,11,13,13, 9,11,10,13,12,10,11,11,
  134361. 13,14,10,11,11,14,13,12,12,13,12,15,12,13,13,15,
  134362. 15, 9,10,10,12,13,10,11,10,13,12,10,11,11,13,14,
  134363. 12,13,11,15,13,13,13,13,15,15, 5, 7, 7, 9, 9, 7,
  134364. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12,10,10,
  134365. 11,12,13, 6, 8, 8,10,10, 8, 9, 9,11,11, 7, 8, 9,
  134366. 10,11,10,11,11,13,13,10,10,11,11,13, 7, 8, 8,10,
  134367. 11, 8, 9, 9,11,11, 8, 9, 8,11,11,10,11,11,13,13,
  134368. 11,12,11,13,12, 9,10,10,13,12,10,11,11,14,13,10,
  134369. 10,11,12,13,12,13,13,15,15,12,11,13,13,14, 9,10,
  134370. 11,12,13,10,11,11,13,14,10,11,11,13,13,12,13,13,
  134371. 15,15,12,13,12,15,12, 8, 9, 9,12,12, 9,11,10,13,
  134372. 13, 9,10,10,13,13,12,13,13,15,15,12,12,12,14,14,
  134373. 9,10,10,13,13,10,11,11,13,14,10,11,11,14,13,13,
  134374. 13,14,14,16,13,13,13,15,15, 9,10,10,13,13,10,11,
  134375. 10,14,13,10,11,11,13,14,12,14,13,16,14,12,13,13,
  134376. 14,15,11,12,12,15,14,11,12,13,14,15,12,13,13,16,
  134377. 15,14,12,15,12,16,14,15,15,16,16,11,12,12,14,14,
  134378. 11,13,12,15,14,12,13,13,15,16,13,15,13,17,13,14,
  134379. 15,15,16,17, 8, 9, 9,12,12, 9,10,10,12,13, 9,10,
  134380. 10,13,13,12,12,12,14,14,12,13,13,15,15, 9,10,10,
  134381. 13,12,10,11,11,14,13,10,10,11,13,14,13,13,13,15,
  134382. 15,12,13,14,14,16, 9,10,10,13,13,10,11,11,13,14,
  134383. 10,11,11,14,14,13,13,13,15,15,13,14,13,16,14,11,
  134384. 12,12,15,14,12,13,13,16,15,11,12,13,14,15,14,15,
  134385. 15,17,16,13,13,15,13,16,11,12,13,14,15,13,13,13,
  134386. 15,16,11,13,12,15,14,14,15,15,16,16,14,15,12,17,
  134387. 13,
  134388. };
  134389. static float _vq_quantthresh__44u4__p4_0[] = {
  134390. -1.5, -0.5, 0.5, 1.5,
  134391. };
  134392. static long _vq_quantmap__44u4__p4_0[] = {
  134393. 3, 1, 0, 2, 4,
  134394. };
  134395. static encode_aux_threshmatch _vq_auxt__44u4__p4_0 = {
  134396. _vq_quantthresh__44u4__p4_0,
  134397. _vq_quantmap__44u4__p4_0,
  134398. 5,
  134399. 5
  134400. };
  134401. static static_codebook _44u4__p4_0 = {
  134402. 4, 625,
  134403. _vq_lengthlist__44u4__p4_0,
  134404. 1, -533725184, 1611661312, 3, 0,
  134405. _vq_quantlist__44u4__p4_0,
  134406. NULL,
  134407. &_vq_auxt__44u4__p4_0,
  134408. NULL,
  134409. 0
  134410. };
  134411. static long _vq_quantlist__44u4__p5_0[] = {
  134412. 4,
  134413. 3,
  134414. 5,
  134415. 2,
  134416. 6,
  134417. 1,
  134418. 7,
  134419. 0,
  134420. 8,
  134421. };
  134422. static long _vq_lengthlist__44u4__p5_0[] = {
  134423. 2, 3, 3, 6, 6, 7, 7, 9, 9, 4, 5, 5, 7, 7, 8, 8,
  134424. 10, 9, 4, 5, 5, 7, 7, 8, 8,10,10, 6, 7, 7, 8, 8,
  134425. 9, 9,11,10, 6, 7, 7, 8, 8, 9, 9,10,11, 7, 8, 8,
  134426. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  134427. 10,10,11,10,11,11,12,12, 9,10,10,10,11,11,11,12,
  134428. 12,
  134429. };
  134430. static float _vq_quantthresh__44u4__p5_0[] = {
  134431. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  134432. };
  134433. static long _vq_quantmap__44u4__p5_0[] = {
  134434. 7, 5, 3, 1, 0, 2, 4, 6,
  134435. 8,
  134436. };
  134437. static encode_aux_threshmatch _vq_auxt__44u4__p5_0 = {
  134438. _vq_quantthresh__44u4__p5_0,
  134439. _vq_quantmap__44u4__p5_0,
  134440. 9,
  134441. 9
  134442. };
  134443. static static_codebook _44u4__p5_0 = {
  134444. 2, 81,
  134445. _vq_lengthlist__44u4__p5_0,
  134446. 1, -531628032, 1611661312, 4, 0,
  134447. _vq_quantlist__44u4__p5_0,
  134448. NULL,
  134449. &_vq_auxt__44u4__p5_0,
  134450. NULL,
  134451. 0
  134452. };
  134453. static long _vq_quantlist__44u4__p6_0[] = {
  134454. 6,
  134455. 5,
  134456. 7,
  134457. 4,
  134458. 8,
  134459. 3,
  134460. 9,
  134461. 2,
  134462. 10,
  134463. 1,
  134464. 11,
  134465. 0,
  134466. 12,
  134467. };
  134468. static long _vq_lengthlist__44u4__p6_0[] = {
  134469. 1, 4, 4, 6, 6, 8, 8, 9, 9,11,10,13,13, 4, 6, 5,
  134470. 8, 8, 9, 9,10,10,11,11,14,14, 4, 6, 6, 8, 8, 9,
  134471. 9,10,10,11,11,14,14, 6, 8, 8, 9, 9,10,10,11,11,
  134472. 12,12,15,15, 6, 8, 8, 9, 9,10,11,11,11,12,12,15,
  134473. 15, 8, 9, 9,11,10,11,11,12,12,13,13,16,16, 8, 9,
  134474. 9,10,10,11,11,12,12,13,13,16,16,10,10,10,12,11,
  134475. 12,12,13,13,14,14,16,16,10,10,10,11,12,12,12,13,
  134476. 13,13,14,16,17,11,12,11,12,12,13,13,14,14,15,14,
  134477. 18,17,11,11,12,12,12,13,13,14,14,14,15,19,18,14,
  134478. 15,14,15,15,17,16,17,17,17,17,21, 0,14,15,15,16,
  134479. 16,16,16,17,17,18,17,20,21,
  134480. };
  134481. static float _vq_quantthresh__44u4__p6_0[] = {
  134482. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  134483. 12.5, 17.5, 22.5, 27.5,
  134484. };
  134485. static long _vq_quantmap__44u4__p6_0[] = {
  134486. 11, 9, 7, 5, 3, 1, 0, 2,
  134487. 4, 6, 8, 10, 12,
  134488. };
  134489. static encode_aux_threshmatch _vq_auxt__44u4__p6_0 = {
  134490. _vq_quantthresh__44u4__p6_0,
  134491. _vq_quantmap__44u4__p6_0,
  134492. 13,
  134493. 13
  134494. };
  134495. static static_codebook _44u4__p6_0 = {
  134496. 2, 169,
  134497. _vq_lengthlist__44u4__p6_0,
  134498. 1, -526516224, 1616117760, 4, 0,
  134499. _vq_quantlist__44u4__p6_0,
  134500. NULL,
  134501. &_vq_auxt__44u4__p6_0,
  134502. NULL,
  134503. 0
  134504. };
  134505. static long _vq_quantlist__44u4__p6_1[] = {
  134506. 2,
  134507. 1,
  134508. 3,
  134509. 0,
  134510. 4,
  134511. };
  134512. static long _vq_lengthlist__44u4__p6_1[] = {
  134513. 2, 4, 4, 5, 5, 4, 5, 5, 6, 5, 4, 5, 5, 5, 6, 5,
  134514. 6, 5, 6, 6, 5, 5, 6, 6, 6,
  134515. };
  134516. static float _vq_quantthresh__44u4__p6_1[] = {
  134517. -1.5, -0.5, 0.5, 1.5,
  134518. };
  134519. static long _vq_quantmap__44u4__p6_1[] = {
  134520. 3, 1, 0, 2, 4,
  134521. };
  134522. static encode_aux_threshmatch _vq_auxt__44u4__p6_1 = {
  134523. _vq_quantthresh__44u4__p6_1,
  134524. _vq_quantmap__44u4__p6_1,
  134525. 5,
  134526. 5
  134527. };
  134528. static static_codebook _44u4__p6_1 = {
  134529. 2, 25,
  134530. _vq_lengthlist__44u4__p6_1,
  134531. 1, -533725184, 1611661312, 3, 0,
  134532. _vq_quantlist__44u4__p6_1,
  134533. NULL,
  134534. &_vq_auxt__44u4__p6_1,
  134535. NULL,
  134536. 0
  134537. };
  134538. static long _vq_quantlist__44u4__p7_0[] = {
  134539. 6,
  134540. 5,
  134541. 7,
  134542. 4,
  134543. 8,
  134544. 3,
  134545. 9,
  134546. 2,
  134547. 10,
  134548. 1,
  134549. 11,
  134550. 0,
  134551. 12,
  134552. };
  134553. static long _vq_lengthlist__44u4__p7_0[] = {
  134554. 1, 3, 3,12,12,12,12,12,12,12,12,12,12, 3,12,11,
  134555. 12,12,12,12,12,12,12,12,12,12, 4,11,10,12,12,12,
  134556. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  134557. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  134558. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  134559. 12,12,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  134560. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  134561. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  134562. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  134563. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  134564. 11,11,11,11,11,11,11,11,11,
  134565. };
  134566. static float _vq_quantthresh__44u4__p7_0[] = {
  134567. -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5, 382.5,
  134568. 637.5, 892.5, 1147.5, 1402.5,
  134569. };
  134570. static long _vq_quantmap__44u4__p7_0[] = {
  134571. 11, 9, 7, 5, 3, 1, 0, 2,
  134572. 4, 6, 8, 10, 12,
  134573. };
  134574. static encode_aux_threshmatch _vq_auxt__44u4__p7_0 = {
  134575. _vq_quantthresh__44u4__p7_0,
  134576. _vq_quantmap__44u4__p7_0,
  134577. 13,
  134578. 13
  134579. };
  134580. static static_codebook _44u4__p7_0 = {
  134581. 2, 169,
  134582. _vq_lengthlist__44u4__p7_0,
  134583. 1, -514332672, 1627381760, 4, 0,
  134584. _vq_quantlist__44u4__p7_0,
  134585. NULL,
  134586. &_vq_auxt__44u4__p7_0,
  134587. NULL,
  134588. 0
  134589. };
  134590. static long _vq_quantlist__44u4__p7_1[] = {
  134591. 7,
  134592. 6,
  134593. 8,
  134594. 5,
  134595. 9,
  134596. 4,
  134597. 10,
  134598. 3,
  134599. 11,
  134600. 2,
  134601. 12,
  134602. 1,
  134603. 13,
  134604. 0,
  134605. 14,
  134606. };
  134607. static long _vq_lengthlist__44u4__p7_1[] = {
  134608. 1, 4, 4, 6, 6, 7, 7, 9, 8,10, 8,10, 9,11,11, 4,
  134609. 7, 6, 8, 7, 9, 9,10,10,11,10,11,10,12,10, 4, 6,
  134610. 7, 8, 8, 9, 9,10,10,11,11,11,11,12,12, 6, 8, 8,
  134611. 10, 9,11,10,12,11,12,12,12,12,13,13, 6, 8, 8,10,
  134612. 10,10,11,11,11,12,12,13,12,13,13, 8, 9, 9,11,11,
  134613. 12,11,12,12,13,13,13,13,13,13, 8, 9, 9,11,11,11,
  134614. 12,12,12,13,13,13,13,13,13, 9,10,10,12,11,13,13,
  134615. 13,13,14,13,13,14,14,14, 9,10,11,11,12,12,13,13,
  134616. 13,13,13,14,15,14,14,10,11,11,12,12,13,13,14,14,
  134617. 14,14,14,15,16,16,10,11,11,12,13,13,13,13,15,14,
  134618. 14,15,16,15,16,10,12,12,13,13,14,14,14,15,15,15,
  134619. 15,15,15,16,11,12,12,13,13,14,14,14,15,15,15,16,
  134620. 15,17,16,11,12,12,13,13,13,15,15,14,16,16,16,16,
  134621. 16,17,11,12,12,13,13,14,14,15,14,15,15,17,17,16,
  134622. 16,
  134623. };
  134624. static float _vq_quantthresh__44u4__p7_1[] = {
  134625. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  134626. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  134627. };
  134628. static long _vq_quantmap__44u4__p7_1[] = {
  134629. 13, 11, 9, 7, 5, 3, 1, 0,
  134630. 2, 4, 6, 8, 10, 12, 14,
  134631. };
  134632. static encode_aux_threshmatch _vq_auxt__44u4__p7_1 = {
  134633. _vq_quantthresh__44u4__p7_1,
  134634. _vq_quantmap__44u4__p7_1,
  134635. 15,
  134636. 15
  134637. };
  134638. static static_codebook _44u4__p7_1 = {
  134639. 2, 225,
  134640. _vq_lengthlist__44u4__p7_1,
  134641. 1, -522338304, 1620115456, 4, 0,
  134642. _vq_quantlist__44u4__p7_1,
  134643. NULL,
  134644. &_vq_auxt__44u4__p7_1,
  134645. NULL,
  134646. 0
  134647. };
  134648. static long _vq_quantlist__44u4__p7_2[] = {
  134649. 8,
  134650. 7,
  134651. 9,
  134652. 6,
  134653. 10,
  134654. 5,
  134655. 11,
  134656. 4,
  134657. 12,
  134658. 3,
  134659. 13,
  134660. 2,
  134661. 14,
  134662. 1,
  134663. 15,
  134664. 0,
  134665. 16,
  134666. };
  134667. static long _vq_lengthlist__44u4__p7_2[] = {
  134668. 2, 5, 5, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  134669. 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134670. 9, 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  134671. 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134672. 10,10,10,10, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,
  134673. 9,10, 9,10,10, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134674. 10,10,10,10,10,10, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  134675. 9,10,10,10,10,10,10, 8, 9, 8, 9, 9, 9, 9, 9, 9,
  134676. 10,10,10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9, 9,
  134677. 10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,10,
  134678. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,
  134679. 10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,10,
  134680. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  134681. 10,10,10,10,10,10,10,10,10,11,10,10,10, 9, 9, 9,
  134682. 10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9,
  134683. 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  134684. 10, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  134685. 9,10, 9,10,10,10,10,10,10,10,10,10,10,11,10,10,
  134686. 10,
  134687. };
  134688. static float _vq_quantthresh__44u4__p7_2[] = {
  134689. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  134690. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  134691. };
  134692. static long _vq_quantmap__44u4__p7_2[] = {
  134693. 15, 13, 11, 9, 7, 5, 3, 1,
  134694. 0, 2, 4, 6, 8, 10, 12, 14,
  134695. 16,
  134696. };
  134697. static encode_aux_threshmatch _vq_auxt__44u4__p7_2 = {
  134698. _vq_quantthresh__44u4__p7_2,
  134699. _vq_quantmap__44u4__p7_2,
  134700. 17,
  134701. 17
  134702. };
  134703. static static_codebook _44u4__p7_2 = {
  134704. 2, 289,
  134705. _vq_lengthlist__44u4__p7_2,
  134706. 1, -529530880, 1611661312, 5, 0,
  134707. _vq_quantlist__44u4__p7_2,
  134708. NULL,
  134709. &_vq_auxt__44u4__p7_2,
  134710. NULL,
  134711. 0
  134712. };
  134713. static long _huff_lengthlist__44u4__short[] = {
  134714. 14,17,15,17,16,14,13,16,10, 7, 7,10,13,10,15,16,
  134715. 9, 4, 4, 6, 5, 7, 9,16,12, 8, 7, 8, 8, 8,11,16,
  134716. 14, 7, 4, 6, 3, 5, 8,15,13, 8, 5, 7, 4, 5, 7,16,
  134717. 12, 9, 6, 8, 3, 3, 5,16,14,13, 7,10, 5, 5, 7,15,
  134718. };
  134719. static static_codebook _huff_book__44u4__short = {
  134720. 2, 64,
  134721. _huff_lengthlist__44u4__short,
  134722. 0, 0, 0, 0, 0,
  134723. NULL,
  134724. NULL,
  134725. NULL,
  134726. NULL,
  134727. 0
  134728. };
  134729. static long _huff_lengthlist__44u5__long[] = {
  134730. 3, 8,13,12,14,12,16,11,13,14, 5, 4, 5, 6, 7, 8,
  134731. 10, 9,12,15,10, 5, 5, 5, 6, 8, 9, 9,13,15,10, 5,
  134732. 5, 6, 6, 7, 8, 8,11,13,12, 7, 5, 6, 4, 6, 7, 7,
  134733. 11,14,11, 7, 7, 6, 6, 6, 7, 6,10,14,14, 9, 8, 8,
  134734. 6, 7, 7, 7,11,16,11, 8, 8, 7, 6, 6, 7, 4, 7,12,
  134735. 10,10,12,10,10, 9,10, 5, 6, 9,10,12,15,13,14,14,
  134736. 14, 8, 7, 8,
  134737. };
  134738. static static_codebook _huff_book__44u5__long = {
  134739. 2, 100,
  134740. _huff_lengthlist__44u5__long,
  134741. 0, 0, 0, 0, 0,
  134742. NULL,
  134743. NULL,
  134744. NULL,
  134745. NULL,
  134746. 0
  134747. };
  134748. static long _vq_quantlist__44u5__p1_0[] = {
  134749. 1,
  134750. 0,
  134751. 2,
  134752. };
  134753. static long _vq_lengthlist__44u5__p1_0[] = {
  134754. 1, 4, 4, 5, 8, 7, 5, 7, 7, 5, 8, 8, 8,10,10, 7,
  134755. 9,10, 5, 8, 8, 7,10, 9, 8,10,10, 5, 8, 8, 8,10,
  134756. 10, 8,10,10, 8,10,10,10,12,13,10,13,13, 7,10,10,
  134757. 10,13,11,10,13,13, 4, 8, 8, 8,11,10, 8,10,10, 7,
  134758. 10,10,10,13,13,10,11,13, 8,10,11,10,13,13,10,13,
  134759. 12,
  134760. };
  134761. static float _vq_quantthresh__44u5__p1_0[] = {
  134762. -0.5, 0.5,
  134763. };
  134764. static long _vq_quantmap__44u5__p1_0[] = {
  134765. 1, 0, 2,
  134766. };
  134767. static encode_aux_threshmatch _vq_auxt__44u5__p1_0 = {
  134768. _vq_quantthresh__44u5__p1_0,
  134769. _vq_quantmap__44u5__p1_0,
  134770. 3,
  134771. 3
  134772. };
  134773. static static_codebook _44u5__p1_0 = {
  134774. 4, 81,
  134775. _vq_lengthlist__44u5__p1_0,
  134776. 1, -535822336, 1611661312, 2, 0,
  134777. _vq_quantlist__44u5__p1_0,
  134778. NULL,
  134779. &_vq_auxt__44u5__p1_0,
  134780. NULL,
  134781. 0
  134782. };
  134783. static long _vq_quantlist__44u5__p2_0[] = {
  134784. 1,
  134785. 0,
  134786. 2,
  134787. };
  134788. static long _vq_lengthlist__44u5__p2_0[] = {
  134789. 3, 4, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 6, 8, 8, 6,
  134790. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 8, 5, 6, 6, 6, 8,
  134791. 8, 6, 8, 8, 6, 8, 8, 8, 9, 9, 8, 9, 9, 6, 8, 7,
  134792. 7, 9, 8, 8, 9, 9, 5, 6, 6, 6, 8, 7, 6, 8, 8, 6,
  134793. 8, 7, 8, 9, 9, 7, 8, 9, 6, 8, 8, 8, 9, 9, 8, 9,
  134794. 9,
  134795. };
  134796. static float _vq_quantthresh__44u5__p2_0[] = {
  134797. -0.5, 0.5,
  134798. };
  134799. static long _vq_quantmap__44u5__p2_0[] = {
  134800. 1, 0, 2,
  134801. };
  134802. static encode_aux_threshmatch _vq_auxt__44u5__p2_0 = {
  134803. _vq_quantthresh__44u5__p2_0,
  134804. _vq_quantmap__44u5__p2_0,
  134805. 3,
  134806. 3
  134807. };
  134808. static static_codebook _44u5__p2_0 = {
  134809. 4, 81,
  134810. _vq_lengthlist__44u5__p2_0,
  134811. 1, -535822336, 1611661312, 2, 0,
  134812. _vq_quantlist__44u5__p2_0,
  134813. NULL,
  134814. &_vq_auxt__44u5__p2_0,
  134815. NULL,
  134816. 0
  134817. };
  134818. static long _vq_quantlist__44u5__p3_0[] = {
  134819. 2,
  134820. 1,
  134821. 3,
  134822. 0,
  134823. 4,
  134824. };
  134825. static long _vq_lengthlist__44u5__p3_0[] = {
  134826. 2, 4, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 8,
  134827. 10, 9,13,12, 8, 9,10,12,12, 5, 7, 7,10,10, 7, 9,
  134828. 9,11,11, 6, 8, 9,11,11,10,11,11,14,14, 9,10,11,
  134829. 13,14, 5, 7, 7, 9,10, 7, 9, 8,11,11, 7, 9, 9,11,
  134830. 11, 9,11,10,14,13,10,11,11,14,14, 8,10,10,13,13,
  134831. 10,11,11,15,14, 9,11,11,14,14,13,14,14,17,16,12,
  134832. 13,13,15,16, 8,10,10,13,13, 9,11,11,14,15,10,11,
  134833. 11,14,15,12,14,13,16,16,13,15,14,15,17, 5, 7, 7,
  134834. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,11,10,11,11,14,
  134835. 14,10,11,12,14,14, 7, 9, 9,12,11, 9,11,11,13,13,
  134836. 9,11,11,13,13,12,13,13,15,16,11,12,13,15,16, 6,
  134837. 9, 9,11,11, 8,11,10,13,12, 9,11,11,13,14,11,13,
  134838. 12,16,14,11,13,13,16,17,10,12,11,15,15,11,13,13,
  134839. 16,16,11,13,13,17,16,14,15,15,17,17,14,16,16,17,
  134840. 18, 9,11,11,14,15,10,12,12,15,15,11,13,13,16,17,
  134841. 13,15,13,17,15,14,15,16,18, 0, 5, 7, 7,10,10, 7,
  134842. 9, 9,11,11, 7, 9, 9,11,11,10,11,11,14,14,10,11,
  134843. 12,14,15, 6, 9, 9,12,11, 9,11,11,13,13, 8,10,11,
  134844. 12,13,11,13,13,16,15,11,12,13,14,15, 7, 9, 9,11,
  134845. 12, 9,11,11,13,13, 9,11,11,13,13,11,13,13,15,16,
  134846. 11,13,13,15,14, 9,11,11,15,14,11,13,13,17,15,10,
  134847. 12,12,15,15,14,16,16,17,17,13,13,15,15,17,10,11,
  134848. 12,15,15,11,13,13,16,16,11,13,13,15,15,14,15,15,
  134849. 18,18,14,15,15,17,17, 8,10,10,13,13,10,12,11,15,
  134850. 15,10,11,12,15,15,14,15,15,18,18,13,14,14,18,18,
  134851. 9,11,11,15,16,11,13,13,17,17,11,13,13,16,16,15,
  134852. 15,16,17, 0,14,15,17, 0, 0, 9,11,11,15,15,10,13,
  134853. 12,18,16,11,13,13,15,16,14,16,15,20,20,14,15,16,
  134854. 17, 0,13,14,14,20,16,14,15,16,19,18,14,15,15,19,
  134855. 0,18,16, 0,20,20,16,18,18, 0, 0,12,14,14,18,18,
  134856. 13,15,14,18,16,14,15,16,18,20,16,19,16, 0,17,17,
  134857. 18,18,19, 0, 8,10,10,14,14,10,11,11,14,15,10,11,
  134858. 12,15,15,13,15,14,19,17,13,15,15,17, 0, 9,11,11,
  134859. 16,15,11,13,13,16,16,10,12,13,15,17,14,16,16,18,
  134860. 18,14,15,15,18, 0, 9,11,11,15,15,11,13,13,16,17,
  134861. 11,13,13,18,17,14,18,16,18,18,15,17,17,18, 0,12,
  134862. 14,14,18,18,14,15,15,20, 0,13,14,15,17, 0,16,18,
  134863. 17, 0, 0,16,16, 0,17,20,12,14,14,18,18,14,16,15,
  134864. 0,18,14,16,15,18, 0,16,19,17, 0, 0,17,18,16, 0,
  134865. 0,
  134866. };
  134867. static float _vq_quantthresh__44u5__p3_0[] = {
  134868. -1.5, -0.5, 0.5, 1.5,
  134869. };
  134870. static long _vq_quantmap__44u5__p3_0[] = {
  134871. 3, 1, 0, 2, 4,
  134872. };
  134873. static encode_aux_threshmatch _vq_auxt__44u5__p3_0 = {
  134874. _vq_quantthresh__44u5__p3_0,
  134875. _vq_quantmap__44u5__p3_0,
  134876. 5,
  134877. 5
  134878. };
  134879. static static_codebook _44u5__p3_0 = {
  134880. 4, 625,
  134881. _vq_lengthlist__44u5__p3_0,
  134882. 1, -533725184, 1611661312, 3, 0,
  134883. _vq_quantlist__44u5__p3_0,
  134884. NULL,
  134885. &_vq_auxt__44u5__p3_0,
  134886. NULL,
  134887. 0
  134888. };
  134889. static long _vq_quantlist__44u5__p4_0[] = {
  134890. 2,
  134891. 1,
  134892. 3,
  134893. 0,
  134894. 4,
  134895. };
  134896. static long _vq_lengthlist__44u5__p4_0[] = {
  134897. 4, 5, 5, 8, 8, 6, 7, 6, 9, 9, 6, 6, 7, 9, 9, 8,
  134898. 9, 9,11,11, 8, 9, 9,11,11, 6, 7, 7, 9, 9, 7, 8,
  134899. 8,10,10, 6, 7, 8, 9,10, 9,10,10,11,12, 9, 9,10,
  134900. 11,12, 6, 7, 7, 9, 9, 6, 8, 7,10, 9, 7, 8, 8,10,
  134901. 10, 9,10, 9,12,11, 9,10,10,12,11, 8, 9, 9,12,11,
  134902. 9,10,10,12,12, 9,10,10,12,12,11,12,12,13,14,11,
  134903. 11,12,13,14, 8, 9, 9,11,12, 9,10,10,12,12, 9,10,
  134904. 10,12,12,11,12,11,14,13,11,12,12,13,13, 5, 7, 7,
  134905. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,
  134906. 12, 9,10,10,12,12, 7, 8, 8,10,10, 8, 8, 9,10,11,
  134907. 8, 9, 9,11,11,10,10,11,11,13,10,11,11,12,13, 6,
  134908. 7, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  134909. 10,13,11,10,11,11,12,12, 9,10,10,12,12,10,10,11,
  134910. 12,13,10,11,11,13,13,12,11,13,12,15,12,13,13,14,
  134911. 15, 9,10,10,12,12, 9,11,10,13,12,10,11,11,13,13,
  134912. 11,13,11,14,12,12,13,13,14,15, 5, 7, 7, 9, 9, 7,
  134913. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12, 9,10,
  134914. 10,12,12, 6, 8, 7,10,10, 8, 9, 9,11,11, 7, 8, 9,
  134915. 10,11,10,11,11,12,12,10,10,11,11,13, 7, 8, 8,10,
  134916. 10, 8, 9, 9,11,11, 8, 9, 8,11,10,10,11,11,13,12,
  134917. 10,11,10,13,11, 9,10,10,12,12,10,11,11,13,12, 9,
  134918. 10,10,12,13,12,13,13,14,15,11,11,13,12,14, 9,10,
  134919. 10,12,12,10,11,11,13,13,10,11,10,13,12,12,13,13,
  134920. 14,14,12,13,11,14,12, 8, 9, 9,12,12, 9,10,10,12,
  134921. 12, 9,10,10,12,12,12,12,12,14,14,11,12,12,14,13,
  134922. 9,10,10,12,12,10,11,11,13,13,10,11,11,13,12,12,
  134923. 12,13,14,15,12,13,13,15,14, 9,10,10,12,12,10,11,
  134924. 10,13,12,10,11,11,12,13,12,13,12,15,13,12,13,13,
  134925. 14,15,11,12,12,14,13,11,12,12,14,15,12,13,13,15,
  134926. 14,13,12,14,12,16,13,14,14,15,15,11,11,12,14,14,
  134927. 11,12,11,14,13,12,13,13,14,15,13,14,12,16,12,14,
  134928. 14,15,16,16, 8, 9, 9,11,12, 9,10,10,12,12, 9,10,
  134929. 10,12,13,11,12,12,13,13,12,12,13,14,14, 9,10,10,
  134930. 12,12,10,11,10,13,12,10,10,11,12,13,12,13,13,15,
  134931. 14,12,12,13,13,15, 9,10,10,12,13,10,11,11,12,13,
  134932. 10,11,11,13,13,12,13,13,14,15,12,13,12,15,14,11,
  134933. 12,11,14,13,12,13,13,15,14,11,11,12,13,14,14,15,
  134934. 14,16,15,13,12,14,13,16,11,12,12,13,14,12,13,13,
  134935. 14,15,11,12,11,14,14,14,14,14,15,16,13,15,12,16,
  134936. 12,
  134937. };
  134938. static float _vq_quantthresh__44u5__p4_0[] = {
  134939. -1.5, -0.5, 0.5, 1.5,
  134940. };
  134941. static long _vq_quantmap__44u5__p4_0[] = {
  134942. 3, 1, 0, 2, 4,
  134943. };
  134944. static encode_aux_threshmatch _vq_auxt__44u5__p4_0 = {
  134945. _vq_quantthresh__44u5__p4_0,
  134946. _vq_quantmap__44u5__p4_0,
  134947. 5,
  134948. 5
  134949. };
  134950. static static_codebook _44u5__p4_0 = {
  134951. 4, 625,
  134952. _vq_lengthlist__44u5__p4_0,
  134953. 1, -533725184, 1611661312, 3, 0,
  134954. _vq_quantlist__44u5__p4_0,
  134955. NULL,
  134956. &_vq_auxt__44u5__p4_0,
  134957. NULL,
  134958. 0
  134959. };
  134960. static long _vq_quantlist__44u5__p5_0[] = {
  134961. 4,
  134962. 3,
  134963. 5,
  134964. 2,
  134965. 6,
  134966. 1,
  134967. 7,
  134968. 0,
  134969. 8,
  134970. };
  134971. static long _vq_lengthlist__44u5__p5_0[] = {
  134972. 2, 3, 3, 6, 6, 8, 8,10,10, 4, 5, 5, 8, 7, 8, 8,
  134973. 11,10, 3, 5, 5, 7, 8, 8, 8,10,11, 6, 8, 7,10, 9,
  134974. 10,10,11,11, 6, 7, 8, 9, 9, 9,10,11,12, 8, 8, 8,
  134975. 10,10,11,11,13,12, 8, 8, 9, 9,10,11,11,12,13,10,
  134976. 11,10,12,11,13,12,14,14,10,10,11,11,12,12,13,14,
  134977. 14,
  134978. };
  134979. static float _vq_quantthresh__44u5__p5_0[] = {
  134980. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  134981. };
  134982. static long _vq_quantmap__44u5__p5_0[] = {
  134983. 7, 5, 3, 1, 0, 2, 4, 6,
  134984. 8,
  134985. };
  134986. static encode_aux_threshmatch _vq_auxt__44u5__p5_0 = {
  134987. _vq_quantthresh__44u5__p5_0,
  134988. _vq_quantmap__44u5__p5_0,
  134989. 9,
  134990. 9
  134991. };
  134992. static static_codebook _44u5__p5_0 = {
  134993. 2, 81,
  134994. _vq_lengthlist__44u5__p5_0,
  134995. 1, -531628032, 1611661312, 4, 0,
  134996. _vq_quantlist__44u5__p5_0,
  134997. NULL,
  134998. &_vq_auxt__44u5__p5_0,
  134999. NULL,
  135000. 0
  135001. };
  135002. static long _vq_quantlist__44u5__p6_0[] = {
  135003. 4,
  135004. 3,
  135005. 5,
  135006. 2,
  135007. 6,
  135008. 1,
  135009. 7,
  135010. 0,
  135011. 8,
  135012. };
  135013. static long _vq_lengthlist__44u5__p6_0[] = {
  135014. 3, 4, 4, 5, 5, 7, 7, 9, 9, 4, 5, 4, 6, 6, 7, 7,
  135015. 9, 9, 4, 4, 5, 6, 6, 7, 7, 9, 9, 5, 6, 6, 7, 7,
  135016. 8, 8,10,10, 6, 6, 6, 7, 7, 8, 8,10,10, 7, 7, 7,
  135017. 8, 8, 9, 9,11,10, 7, 7, 7, 8, 8, 9, 9,10,11, 9,
  135018. 9, 9,10,10,11,10,11,11, 9, 9, 9,10,10,11,10,11,
  135019. 11,
  135020. };
  135021. static float _vq_quantthresh__44u5__p6_0[] = {
  135022. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  135023. };
  135024. static long _vq_quantmap__44u5__p6_0[] = {
  135025. 7, 5, 3, 1, 0, 2, 4, 6,
  135026. 8,
  135027. };
  135028. static encode_aux_threshmatch _vq_auxt__44u5__p6_0 = {
  135029. _vq_quantthresh__44u5__p6_0,
  135030. _vq_quantmap__44u5__p6_0,
  135031. 9,
  135032. 9
  135033. };
  135034. static static_codebook _44u5__p6_0 = {
  135035. 2, 81,
  135036. _vq_lengthlist__44u5__p6_0,
  135037. 1, -531628032, 1611661312, 4, 0,
  135038. _vq_quantlist__44u5__p6_0,
  135039. NULL,
  135040. &_vq_auxt__44u5__p6_0,
  135041. NULL,
  135042. 0
  135043. };
  135044. static long _vq_quantlist__44u5__p7_0[] = {
  135045. 1,
  135046. 0,
  135047. 2,
  135048. };
  135049. static long _vq_lengthlist__44u5__p7_0[] = {
  135050. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 9, 8,11,10, 7,
  135051. 11,10, 5, 9, 9, 7,10,10, 8,10,11, 4, 9, 9, 9,12,
  135052. 12, 9,12,12, 8,12,12,11,12,12,10,12,13, 7,12,12,
  135053. 11,12,12,10,12,13, 4, 9, 9, 9,12,12, 9,12,12, 7,
  135054. 12,11,10,13,13,11,12,12, 7,12,12,10,13,13,11,12,
  135055. 12,
  135056. };
  135057. static float _vq_quantthresh__44u5__p7_0[] = {
  135058. -5.5, 5.5,
  135059. };
  135060. static long _vq_quantmap__44u5__p7_0[] = {
  135061. 1, 0, 2,
  135062. };
  135063. static encode_aux_threshmatch _vq_auxt__44u5__p7_0 = {
  135064. _vq_quantthresh__44u5__p7_0,
  135065. _vq_quantmap__44u5__p7_0,
  135066. 3,
  135067. 3
  135068. };
  135069. static static_codebook _44u5__p7_0 = {
  135070. 4, 81,
  135071. _vq_lengthlist__44u5__p7_0,
  135072. 1, -529137664, 1618345984, 2, 0,
  135073. _vq_quantlist__44u5__p7_0,
  135074. NULL,
  135075. &_vq_auxt__44u5__p7_0,
  135076. NULL,
  135077. 0
  135078. };
  135079. static long _vq_quantlist__44u5__p7_1[] = {
  135080. 5,
  135081. 4,
  135082. 6,
  135083. 3,
  135084. 7,
  135085. 2,
  135086. 8,
  135087. 1,
  135088. 9,
  135089. 0,
  135090. 10,
  135091. };
  135092. static long _vq_lengthlist__44u5__p7_1[] = {
  135093. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 5, 5, 7, 7,
  135094. 8, 8, 9, 8, 8, 9, 4, 5, 5, 7, 7, 8, 8, 9, 9, 8,
  135095. 9, 6, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 6, 7, 7, 8,
  135096. 8, 9, 9, 9, 9, 9, 9, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  135097. 9, 9, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 8, 9, 9,
  135098. 9, 9, 9, 9,10,10,10,10, 8, 9, 9, 9, 9, 9, 9,10,
  135099. 10,10,10, 8, 9, 9, 9, 9, 9, 9,10,10,10,10, 8, 9,
  135100. 9, 9, 9, 9, 9,10,10,10,10,
  135101. };
  135102. static float _vq_quantthresh__44u5__p7_1[] = {
  135103. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  135104. 3.5, 4.5,
  135105. };
  135106. static long _vq_quantmap__44u5__p7_1[] = {
  135107. 9, 7, 5, 3, 1, 0, 2, 4,
  135108. 6, 8, 10,
  135109. };
  135110. static encode_aux_threshmatch _vq_auxt__44u5__p7_1 = {
  135111. _vq_quantthresh__44u5__p7_1,
  135112. _vq_quantmap__44u5__p7_1,
  135113. 11,
  135114. 11
  135115. };
  135116. static static_codebook _44u5__p7_1 = {
  135117. 2, 121,
  135118. _vq_lengthlist__44u5__p7_1,
  135119. 1, -531365888, 1611661312, 4, 0,
  135120. _vq_quantlist__44u5__p7_1,
  135121. NULL,
  135122. &_vq_auxt__44u5__p7_1,
  135123. NULL,
  135124. 0
  135125. };
  135126. static long _vq_quantlist__44u5__p8_0[] = {
  135127. 5,
  135128. 4,
  135129. 6,
  135130. 3,
  135131. 7,
  135132. 2,
  135133. 8,
  135134. 1,
  135135. 9,
  135136. 0,
  135137. 10,
  135138. };
  135139. static long _vq_lengthlist__44u5__p8_0[] = {
  135140. 1, 4, 4, 6, 6, 8, 8, 9, 9,10,10, 4, 6, 6, 7, 7,
  135141. 9, 9,10,10,11,11, 4, 6, 6, 7, 7, 9, 9,10,10,11,
  135142. 11, 6, 8, 7, 9, 9,10,10,11,11,13,12, 6, 8, 8, 9,
  135143. 9,10,10,11,11,12,13, 8, 9, 9,10,10,12,12,13,12,
  135144. 14,13, 8, 9, 9,10,10,12,12,13,13,14,14, 9,11,11,
  135145. 12,12,13,13,14,14,15,14, 9,11,11,12,12,13,13,14,
  135146. 14,15,14,11,12,12,13,13,14,14,15,14,15,14,11,11,
  135147. 12,13,13,14,14,14,14,15,15,
  135148. };
  135149. static float _vq_quantthresh__44u5__p8_0[] = {
  135150. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  135151. 38.5, 49.5,
  135152. };
  135153. static long _vq_quantmap__44u5__p8_0[] = {
  135154. 9, 7, 5, 3, 1, 0, 2, 4,
  135155. 6, 8, 10,
  135156. };
  135157. static encode_aux_threshmatch _vq_auxt__44u5__p8_0 = {
  135158. _vq_quantthresh__44u5__p8_0,
  135159. _vq_quantmap__44u5__p8_0,
  135160. 11,
  135161. 11
  135162. };
  135163. static static_codebook _44u5__p8_0 = {
  135164. 2, 121,
  135165. _vq_lengthlist__44u5__p8_0,
  135166. 1, -524582912, 1618345984, 4, 0,
  135167. _vq_quantlist__44u5__p8_0,
  135168. NULL,
  135169. &_vq_auxt__44u5__p8_0,
  135170. NULL,
  135171. 0
  135172. };
  135173. static long _vq_quantlist__44u5__p8_1[] = {
  135174. 5,
  135175. 4,
  135176. 6,
  135177. 3,
  135178. 7,
  135179. 2,
  135180. 8,
  135181. 1,
  135182. 9,
  135183. 0,
  135184. 10,
  135185. };
  135186. static long _vq_lengthlist__44u5__p8_1[] = {
  135187. 3, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 5, 7, 6,
  135188. 7, 7, 8, 8, 8, 8, 5, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  135189. 8, 6, 7, 6, 7, 7, 8, 8, 8, 8, 8, 8, 6, 6, 7, 7,
  135190. 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8,
  135191. 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8,
  135192. 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8,
  135193. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  135194. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  135195. };
  135196. static float _vq_quantthresh__44u5__p8_1[] = {
  135197. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  135198. 3.5, 4.5,
  135199. };
  135200. static long _vq_quantmap__44u5__p8_1[] = {
  135201. 9, 7, 5, 3, 1, 0, 2, 4,
  135202. 6, 8, 10,
  135203. };
  135204. static encode_aux_threshmatch _vq_auxt__44u5__p8_1 = {
  135205. _vq_quantthresh__44u5__p8_1,
  135206. _vq_quantmap__44u5__p8_1,
  135207. 11,
  135208. 11
  135209. };
  135210. static static_codebook _44u5__p8_1 = {
  135211. 2, 121,
  135212. _vq_lengthlist__44u5__p8_1,
  135213. 1, -531365888, 1611661312, 4, 0,
  135214. _vq_quantlist__44u5__p8_1,
  135215. NULL,
  135216. &_vq_auxt__44u5__p8_1,
  135217. NULL,
  135218. 0
  135219. };
  135220. static long _vq_quantlist__44u5__p9_0[] = {
  135221. 6,
  135222. 5,
  135223. 7,
  135224. 4,
  135225. 8,
  135226. 3,
  135227. 9,
  135228. 2,
  135229. 10,
  135230. 1,
  135231. 11,
  135232. 0,
  135233. 12,
  135234. };
  135235. static long _vq_lengthlist__44u5__p9_0[] = {
  135236. 1, 3, 2,12,10,13,13,13,13,13,13,13,13, 4, 9, 9,
  135237. 13,13,13,13,13,13,13,13,13,13, 5,10, 9,13,13,13,
  135238. 13,13,13,13,13,13,13,12,13,13,13,13,13,13,13,13,
  135239. 13,13,13,13,11,13,13,13,13,13,13,13,13,13,13,13,
  135240. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  135241. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  135242. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  135243. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  135244. 13,13,13,13,13,13,13,13,13,13,13,13,13,12,12,12,
  135245. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  135246. 12,12,12,12,12,12,12,12,12,
  135247. };
  135248. static float _vq_quantthresh__44u5__p9_0[] = {
  135249. -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5, 382.5,
  135250. 637.5, 892.5, 1147.5, 1402.5,
  135251. };
  135252. static long _vq_quantmap__44u5__p9_0[] = {
  135253. 11, 9, 7, 5, 3, 1, 0, 2,
  135254. 4, 6, 8, 10, 12,
  135255. };
  135256. static encode_aux_threshmatch _vq_auxt__44u5__p9_0 = {
  135257. _vq_quantthresh__44u5__p9_0,
  135258. _vq_quantmap__44u5__p9_0,
  135259. 13,
  135260. 13
  135261. };
  135262. static static_codebook _44u5__p9_0 = {
  135263. 2, 169,
  135264. _vq_lengthlist__44u5__p9_0,
  135265. 1, -514332672, 1627381760, 4, 0,
  135266. _vq_quantlist__44u5__p9_0,
  135267. NULL,
  135268. &_vq_auxt__44u5__p9_0,
  135269. NULL,
  135270. 0
  135271. };
  135272. static long _vq_quantlist__44u5__p9_1[] = {
  135273. 7,
  135274. 6,
  135275. 8,
  135276. 5,
  135277. 9,
  135278. 4,
  135279. 10,
  135280. 3,
  135281. 11,
  135282. 2,
  135283. 12,
  135284. 1,
  135285. 13,
  135286. 0,
  135287. 14,
  135288. };
  135289. static long _vq_lengthlist__44u5__p9_1[] = {
  135290. 1, 4, 4, 7, 7, 8, 8, 8, 7, 8, 7, 9, 8, 9, 9, 4,
  135291. 7, 6, 9, 8,10,10, 9, 8, 9, 9, 9, 9, 9, 8, 5, 6,
  135292. 6, 8, 9,10,10, 9, 9, 9,10,10,10,10,11, 7, 8, 8,
  135293. 10,10,11,11,10,10,11,11,11,12,11,11, 7, 8, 8,10,
  135294. 10,11,11,10,10,11,11,12,11,11,11, 8, 9, 9,11,11,
  135295. 12,12,11,11,12,11,12,12,12,12, 8, 9,10,11,11,12,
  135296. 12,11,11,12,12,12,12,12,12, 8, 9, 9,10,10,12,11,
  135297. 12,12,12,12,12,12,12,13, 8, 9, 9,11,11,11,11,12,
  135298. 12,12,12,13,12,13,13, 9,10,10,11,11,12,12,12,13,
  135299. 12,13,13,13,14,13, 9,10,10,11,11,12,12,12,13,13,
  135300. 12,13,13,14,13, 9,11,10,12,11,13,12,12,13,13,13,
  135301. 13,13,13,14, 9,10,10,12,12,12,12,12,13,13,13,13,
  135302. 13,14,14,10,11,11,12,12,12,13,13,13,14,14,13,14,
  135303. 14,14,10,11,11,12,12,12,12,13,12,13,14,13,14,14,
  135304. 14,
  135305. };
  135306. static float _vq_quantthresh__44u5__p9_1[] = {
  135307. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  135308. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  135309. };
  135310. static long _vq_quantmap__44u5__p9_1[] = {
  135311. 13, 11, 9, 7, 5, 3, 1, 0,
  135312. 2, 4, 6, 8, 10, 12, 14,
  135313. };
  135314. static encode_aux_threshmatch _vq_auxt__44u5__p9_1 = {
  135315. _vq_quantthresh__44u5__p9_1,
  135316. _vq_quantmap__44u5__p9_1,
  135317. 15,
  135318. 15
  135319. };
  135320. static static_codebook _44u5__p9_1 = {
  135321. 2, 225,
  135322. _vq_lengthlist__44u5__p9_1,
  135323. 1, -522338304, 1620115456, 4, 0,
  135324. _vq_quantlist__44u5__p9_1,
  135325. NULL,
  135326. &_vq_auxt__44u5__p9_1,
  135327. NULL,
  135328. 0
  135329. };
  135330. static long _vq_quantlist__44u5__p9_2[] = {
  135331. 8,
  135332. 7,
  135333. 9,
  135334. 6,
  135335. 10,
  135336. 5,
  135337. 11,
  135338. 4,
  135339. 12,
  135340. 3,
  135341. 13,
  135342. 2,
  135343. 14,
  135344. 1,
  135345. 15,
  135346. 0,
  135347. 16,
  135348. };
  135349. static long _vq_lengthlist__44u5__p9_2[] = {
  135350. 2, 5, 5, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  135351. 9, 5, 6, 6, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9,
  135352. 9, 9, 5, 6, 6, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9,
  135353. 9, 9, 9, 7, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9,
  135354. 9, 9, 9, 9, 7, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9,
  135355. 9, 9, 9, 9, 9, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  135356. 9,10, 9,10,10,10, 8, 8, 8, 9, 8, 9, 9, 9, 9, 9,
  135357. 9, 9,10, 9,10, 9,10, 8, 9, 9, 9, 9, 9, 9, 9, 9,
  135358. 9,10, 9,10,10,10,10,10, 8, 9, 9, 9, 9, 9, 9,10,
  135359. 9,10, 9,10,10,10,10,10,10, 9, 9, 9, 9, 9,10, 9,
  135360. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9,
  135361. 9,10, 9,10, 9,10,10,10,10,10,10, 9, 9, 9, 9, 9,
  135362. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  135363. 9, 9,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  135364. 9,10,10, 9,10,10,10,10,10,10,10,10,10,10, 9, 9,
  135365. 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  135366. 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  135367. 9, 9, 9,10, 9,10,10,10,10,10,10,10,10,10,10,10,
  135368. 10,
  135369. };
  135370. static float _vq_quantthresh__44u5__p9_2[] = {
  135371. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  135372. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  135373. };
  135374. static long _vq_quantmap__44u5__p9_2[] = {
  135375. 15, 13, 11, 9, 7, 5, 3, 1,
  135376. 0, 2, 4, 6, 8, 10, 12, 14,
  135377. 16,
  135378. };
  135379. static encode_aux_threshmatch _vq_auxt__44u5__p9_2 = {
  135380. _vq_quantthresh__44u5__p9_2,
  135381. _vq_quantmap__44u5__p9_2,
  135382. 17,
  135383. 17
  135384. };
  135385. static static_codebook _44u5__p9_2 = {
  135386. 2, 289,
  135387. _vq_lengthlist__44u5__p9_2,
  135388. 1, -529530880, 1611661312, 5, 0,
  135389. _vq_quantlist__44u5__p9_2,
  135390. NULL,
  135391. &_vq_auxt__44u5__p9_2,
  135392. NULL,
  135393. 0
  135394. };
  135395. static long _huff_lengthlist__44u5__short[] = {
  135396. 4,10,17,13,17,13,17,17,17,17, 3, 6, 8, 9,11, 9,
  135397. 15,12,16,17, 6, 5, 5, 7, 7, 8,10,11,17,17, 7, 8,
  135398. 7, 9, 9,10,13,13,17,17, 8, 6, 5, 7, 4, 7, 5, 8,
  135399. 14,17, 9, 9, 8, 9, 7, 9, 8,10,16,17,12,10, 7, 8,
  135400. 4, 7, 4, 7,16,17,12,11, 9,10, 6, 9, 5, 7,14,17,
  135401. 14,13,10,15, 4, 8, 3, 5,14,17,17,14,11,15, 6,10,
  135402. 6, 8,15,17,
  135403. };
  135404. static static_codebook _huff_book__44u5__short = {
  135405. 2, 100,
  135406. _huff_lengthlist__44u5__short,
  135407. 0, 0, 0, 0, 0,
  135408. NULL,
  135409. NULL,
  135410. NULL,
  135411. NULL,
  135412. 0
  135413. };
  135414. static long _huff_lengthlist__44u6__long[] = {
  135415. 3, 9,14,13,14,13,16,12,13,14, 5, 4, 6, 6, 8, 9,
  135416. 11,10,12,15,10, 5, 5, 6, 6, 8,10,10,13,16,10, 6,
  135417. 6, 6, 6, 8, 9, 9,12,14,13, 7, 6, 6, 4, 6, 6, 7,
  135418. 11,14,10, 7, 7, 7, 6, 6, 6, 7,10,13,15,10, 9, 8,
  135419. 5, 6, 5, 6,10,14,10, 9, 8, 8, 6, 6, 5, 4, 6,11,
  135420. 11,11,12,11,10, 9, 9, 5, 5, 9,10,12,15,13,13,13,
  135421. 13, 8, 7, 7,
  135422. };
  135423. static static_codebook _huff_book__44u6__long = {
  135424. 2, 100,
  135425. _huff_lengthlist__44u6__long,
  135426. 0, 0, 0, 0, 0,
  135427. NULL,
  135428. NULL,
  135429. NULL,
  135430. NULL,
  135431. 0
  135432. };
  135433. static long _vq_quantlist__44u6__p1_0[] = {
  135434. 1,
  135435. 0,
  135436. 2,
  135437. };
  135438. static long _vq_lengthlist__44u6__p1_0[] = {
  135439. 1, 4, 4, 4, 8, 7, 5, 7, 7, 5, 8, 8, 8,10,10, 7,
  135440. 9,10, 5, 8, 8, 7,10, 9, 8,10,10, 5, 8, 8, 8,10,
  135441. 10, 8,10,10, 8,10,10,10,12,13,10,13,13, 7,10,10,
  135442. 10,13,11,10,13,13, 5, 8, 8, 8,11,10, 8,10,10, 7,
  135443. 10,10,10,13,13,10,11,13, 8,10,11,10,13,13,10,13,
  135444. 12,
  135445. };
  135446. static float _vq_quantthresh__44u6__p1_0[] = {
  135447. -0.5, 0.5,
  135448. };
  135449. static long _vq_quantmap__44u6__p1_0[] = {
  135450. 1, 0, 2,
  135451. };
  135452. static encode_aux_threshmatch _vq_auxt__44u6__p1_0 = {
  135453. _vq_quantthresh__44u6__p1_0,
  135454. _vq_quantmap__44u6__p1_0,
  135455. 3,
  135456. 3
  135457. };
  135458. static static_codebook _44u6__p1_0 = {
  135459. 4, 81,
  135460. _vq_lengthlist__44u6__p1_0,
  135461. 1, -535822336, 1611661312, 2, 0,
  135462. _vq_quantlist__44u6__p1_0,
  135463. NULL,
  135464. &_vq_auxt__44u6__p1_0,
  135465. NULL,
  135466. 0
  135467. };
  135468. static long _vq_quantlist__44u6__p2_0[] = {
  135469. 1,
  135470. 0,
  135471. 2,
  135472. };
  135473. static long _vq_lengthlist__44u6__p2_0[] = {
  135474. 3, 4, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 6, 8, 8, 6,
  135475. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 8, 5, 6, 6, 6, 8,
  135476. 8, 6, 8, 8, 6, 8, 8, 8, 9, 9, 8, 9, 9, 6, 7, 7,
  135477. 7, 9, 8, 8, 9, 9, 5, 6, 6, 6, 8, 7, 6, 8, 8, 6,
  135478. 8, 8, 8, 9, 9, 7, 8, 9, 6, 8, 8, 8, 9, 9, 8, 9,
  135479. 9,
  135480. };
  135481. static float _vq_quantthresh__44u6__p2_0[] = {
  135482. -0.5, 0.5,
  135483. };
  135484. static long _vq_quantmap__44u6__p2_0[] = {
  135485. 1, 0, 2,
  135486. };
  135487. static encode_aux_threshmatch _vq_auxt__44u6__p2_0 = {
  135488. _vq_quantthresh__44u6__p2_0,
  135489. _vq_quantmap__44u6__p2_0,
  135490. 3,
  135491. 3
  135492. };
  135493. static static_codebook _44u6__p2_0 = {
  135494. 4, 81,
  135495. _vq_lengthlist__44u6__p2_0,
  135496. 1, -535822336, 1611661312, 2, 0,
  135497. _vq_quantlist__44u6__p2_0,
  135498. NULL,
  135499. &_vq_auxt__44u6__p2_0,
  135500. NULL,
  135501. 0
  135502. };
  135503. static long _vq_quantlist__44u6__p3_0[] = {
  135504. 2,
  135505. 1,
  135506. 3,
  135507. 0,
  135508. 4,
  135509. };
  135510. static long _vq_lengthlist__44u6__p3_0[] = {
  135511. 2, 5, 4, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 8,
  135512. 9, 9,13,12, 8, 9,10,12,13, 5, 7, 7,10, 9, 7, 9,
  135513. 9,11,11, 7, 8, 9,11,11,10,11,11,14,14, 9,10,11,
  135514. 13,14, 5, 7, 7, 9,10, 6, 9, 8,11,11, 7, 9, 9,11,
  135515. 11, 9,11,10,14,13,10,11,11,14,13, 8,10,10,13,13,
  135516. 10,11,11,15,15, 9,11,11,14,14,13,14,14,17,16,12,
  135517. 13,14,16,16, 8,10,10,13,14, 9,11,11,14,15,10,11,
  135518. 12,14,15,12,14,13,16,15,13,14,14,15,17, 5, 7, 7,
  135519. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,11,10,12,11,14,
  135520. 14,10,11,11,14,14, 7, 9, 9,12,11, 9,11,11,13,13,
  135521. 9,11,11,13,13,11,13,13,14,15,11,12,13,15,16, 6,
  135522. 9, 9,11,12, 8,11,10,13,12, 9,11,11,13,14,11,13,
  135523. 12,16,14,11,13,13,15,16,10,12,11,14,15,11,13,13,
  135524. 15,17,11,13,13,17,16,15,15,16,17,16,14,15,16,18,
  135525. 0, 9,11,11,14,15,10,12,12,16,15,11,13,13,16,16,
  135526. 13,15,14,18,15,14,16,16, 0, 0, 5, 7, 7,10,10, 7,
  135527. 9, 9,11,11, 7, 9, 9,11,11,10,11,11,14,14,10,11,
  135528. 12,14,14, 6, 9, 9,11,11, 9,11,11,13,13, 8,10,11,
  135529. 12,13,11,13,13,16,15,11,12,13,14,16, 7, 9, 9,11,
  135530. 12, 9,11,11,13,13, 9,11,11,13,13,11,13,13,16,15,
  135531. 11,13,12,15,15, 9,11,11,15,14,11,13,13,17,16,10,
  135532. 12,13,15,16,14,16,16, 0,18,14,14,15,15,17,10,11,
  135533. 12,15,15,11,13,13,16,16,11,13,13,16,16,14,16,16,
  135534. 19,17,14,15,15,17,17, 8,10,10,14,14,10,12,11,15,
  135535. 15,10,11,12,16,15,14,15,15,18,20,13,14,16,17,18,
  135536. 9,11,11,15,16,11,13,13,17,17,11,13,13,17,16,15,
  135537. 16,16, 0, 0,15,16,16, 0, 0, 9,11,11,15,15,10,13,
  135538. 12,17,15,11,13,13,17,16,15,17,15,20,19,15,16,16,
  135539. 19, 0,13,15,14, 0,17,14,15,16, 0,20,15,16,16, 0,
  135540. 19,17,18, 0, 0, 0,16,17,18, 0, 0,12,14,14,19,18,
  135541. 13,15,14, 0,17,14,15,16,19,19,16,18,16, 0,19,19,
  135542. 20,17,20, 0, 8,10,10,13,14,10,11,11,15,15,10,12,
  135543. 12,15,16,14,15,14,19,16,14,15,15, 0,18, 9,11,11,
  135544. 16,15,11,13,13, 0,16,11,12,13,16,17,14,16,17, 0,
  135545. 19,15,16,16,18, 0, 9,11,11,15,16,11,13,13,16,16,
  135546. 11,14,13,18,17,15,16,16,18,20,15,17,19, 0, 0,12,
  135547. 14,14,17,17,14,16,15, 0, 0,13,14,15,19, 0,16,18,
  135548. 20, 0, 0,16,16,18,18, 0,12,14,14,17,20,14,16,16,
  135549. 19, 0,14,16,14, 0,20,16,20,17, 0, 0,17, 0,15, 0,
  135550. 19,
  135551. };
  135552. static float _vq_quantthresh__44u6__p3_0[] = {
  135553. -1.5, -0.5, 0.5, 1.5,
  135554. };
  135555. static long _vq_quantmap__44u6__p3_0[] = {
  135556. 3, 1, 0, 2, 4,
  135557. };
  135558. static encode_aux_threshmatch _vq_auxt__44u6__p3_0 = {
  135559. _vq_quantthresh__44u6__p3_0,
  135560. _vq_quantmap__44u6__p3_0,
  135561. 5,
  135562. 5
  135563. };
  135564. static static_codebook _44u6__p3_0 = {
  135565. 4, 625,
  135566. _vq_lengthlist__44u6__p3_0,
  135567. 1, -533725184, 1611661312, 3, 0,
  135568. _vq_quantlist__44u6__p3_0,
  135569. NULL,
  135570. &_vq_auxt__44u6__p3_0,
  135571. NULL,
  135572. 0
  135573. };
  135574. static long _vq_quantlist__44u6__p4_0[] = {
  135575. 2,
  135576. 1,
  135577. 3,
  135578. 0,
  135579. 4,
  135580. };
  135581. static long _vq_lengthlist__44u6__p4_0[] = {
  135582. 4, 5, 5, 8, 8, 6, 7, 6, 9, 9, 6, 6, 7, 9, 9, 8,
  135583. 9, 9,11,11, 8, 9, 9,11,11, 6, 7, 7, 9, 9, 7, 8,
  135584. 8,10,10, 7, 7, 8, 9,10, 9,10,10,11,11, 9, 9,10,
  135585. 11,12, 6, 7, 7, 9, 9, 7, 8, 7,10, 9, 7, 8, 8,10,
  135586. 10, 9,10, 9,12,11, 9,10,10,12,11, 8, 9, 9,11,11,
  135587. 9,10,10,12,12, 9,10,10,12,12,11,12,12,14,13,11,
  135588. 11,12,13,13, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  135589. 10,12,12,11,12,11,13,12,11,12,12,13,13, 5, 7, 7,
  135590. 9, 9, 7, 8, 7,10,10, 7, 7, 8,10,10, 9,10,10,12,
  135591. 11, 9,10,10,11,12, 7, 8, 8,10,10, 8, 8, 9,11,11,
  135592. 8, 9, 9,11,11,10,10,11,12,13,10,10,11,12,12, 6,
  135593. 7, 7,10,10, 7, 9, 8,11,10, 8, 8, 9,10,11,10,11,
  135594. 10,13,11,10,11,11,12,12, 9,10,10,12,12,10,10,11,
  135595. 13,13,10,11,11,12,13,12,12,12,13,14,12,12,13,14,
  135596. 14, 9,10,10,12,12, 9,10,10,13,12,10,11,11,13,13,
  135597. 11,12,11,14,12,12,13,13,14,14, 6, 7, 7, 9, 9, 7,
  135598. 8, 7,10,10, 7, 8, 8,10,10, 9,10,10,12,11, 9,10,
  135599. 10,11,12, 6, 7, 7,10,10, 8, 9, 8,11,10, 7, 8, 9,
  135600. 10,11,10,11,11,12,12,10,10,11,11,13, 7, 8, 8,10,
  135601. 10, 8, 9, 9,11,11, 8, 9, 8,11,11,10,11,10,13,12,
  135602. 10,11,11,13,12, 9,10,10,12,12,10,11,11,13,12, 9,
  135603. 10,10,12,13,12,13,12,14,14,11,11,12,12,14, 9,10,
  135604. 10,12,12,10,11,11,13,13,10,11,10,13,12,12,12,12,
  135605. 14,14,12,13,12,14,13, 8, 9, 9,11,11, 9,10,10,12,
  135606. 12, 9,10,10,12,12,11,12,12,14,13,11,12,12,13,14,
  135607. 9,10,10,12,12,10,11,11,13,13,10,11,11,13,13,12,
  135608. 12,13,14,15,12,12,13,14,14, 9,10,10,12,12, 9,11,
  135609. 10,13,12,10,10,11,12,13,12,13,12,14,13,12,12,13,
  135610. 14,15,11,12,12,14,13,11,12,12,14,14,12,13,13,14,
  135611. 14,13,13,14,14,16,13,14,14,15,15,11,12,11,13,13,
  135612. 11,12,11,14,13,12,12,13,14,15,12,14,12,15,12,13,
  135613. 14,15,15,16, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  135614. 10,12,12,11,12,12,14,13,11,12,12,13,13, 9,10,10,
  135615. 12,12,10,11,10,13,12, 9,10,11,12,13,12,13,12,14,
  135616. 14,12,12,13,13,14, 9,10,10,12,12,10,11,11,13,13,
  135617. 10,11,11,13,13,12,13,12,14,14,12,13,13,14,14,11,
  135618. 11,11,13,13,12,13,12,14,14,11,11,12,13,14,14,14,
  135619. 14,16,15,12,12,14,12,15,11,12,12,13,14,12,13,13,
  135620. 14,15,11,12,12,14,14,13,14,14,16,16,13,14,13,16,
  135621. 13,
  135622. };
  135623. static float _vq_quantthresh__44u6__p4_0[] = {
  135624. -1.5, -0.5, 0.5, 1.5,
  135625. };
  135626. static long _vq_quantmap__44u6__p4_0[] = {
  135627. 3, 1, 0, 2, 4,
  135628. };
  135629. static encode_aux_threshmatch _vq_auxt__44u6__p4_0 = {
  135630. _vq_quantthresh__44u6__p4_0,
  135631. _vq_quantmap__44u6__p4_0,
  135632. 5,
  135633. 5
  135634. };
  135635. static static_codebook _44u6__p4_0 = {
  135636. 4, 625,
  135637. _vq_lengthlist__44u6__p4_0,
  135638. 1, -533725184, 1611661312, 3, 0,
  135639. _vq_quantlist__44u6__p4_0,
  135640. NULL,
  135641. &_vq_auxt__44u6__p4_0,
  135642. NULL,
  135643. 0
  135644. };
  135645. static long _vq_quantlist__44u6__p5_0[] = {
  135646. 4,
  135647. 3,
  135648. 5,
  135649. 2,
  135650. 6,
  135651. 1,
  135652. 7,
  135653. 0,
  135654. 8,
  135655. };
  135656. static long _vq_lengthlist__44u6__p5_0[] = {
  135657. 2, 3, 3, 6, 6, 8, 8,10,10, 4, 5, 5, 8, 7, 8, 8,
  135658. 11,11, 3, 5, 5, 7, 8, 8, 8,11,11, 6, 8, 7, 9, 9,
  135659. 10, 9,12,11, 6, 7, 8, 9, 9, 9,10,11,12, 8, 8, 8,
  135660. 10, 9,12,11,13,13, 8, 8, 9, 9,10,11,12,13,13,10,
  135661. 11,11,12,12,13,13,14,14,10,10,11,11,12,13,13,14,
  135662. 14,
  135663. };
  135664. static float _vq_quantthresh__44u6__p5_0[] = {
  135665. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  135666. };
  135667. static long _vq_quantmap__44u6__p5_0[] = {
  135668. 7, 5, 3, 1, 0, 2, 4, 6,
  135669. 8,
  135670. };
  135671. static encode_aux_threshmatch _vq_auxt__44u6__p5_0 = {
  135672. _vq_quantthresh__44u6__p5_0,
  135673. _vq_quantmap__44u6__p5_0,
  135674. 9,
  135675. 9
  135676. };
  135677. static static_codebook _44u6__p5_0 = {
  135678. 2, 81,
  135679. _vq_lengthlist__44u6__p5_0,
  135680. 1, -531628032, 1611661312, 4, 0,
  135681. _vq_quantlist__44u6__p5_0,
  135682. NULL,
  135683. &_vq_auxt__44u6__p5_0,
  135684. NULL,
  135685. 0
  135686. };
  135687. static long _vq_quantlist__44u6__p6_0[] = {
  135688. 4,
  135689. 3,
  135690. 5,
  135691. 2,
  135692. 6,
  135693. 1,
  135694. 7,
  135695. 0,
  135696. 8,
  135697. };
  135698. static long _vq_lengthlist__44u6__p6_0[] = {
  135699. 3, 4, 4, 5, 5, 7, 7, 9, 9, 4, 5, 4, 6, 6, 7, 7,
  135700. 9, 9, 4, 4, 5, 6, 6, 7, 8, 9, 9, 5, 6, 6, 7, 7,
  135701. 8, 8,10,10, 5, 6, 6, 7, 7, 8, 8,10,10, 7, 8, 7,
  135702. 8, 8,10, 9,11,11, 7, 7, 8, 8, 8, 9,10,10,11, 9,
  135703. 9, 9,10,10,11,11,12,11, 9, 9, 9,10,10,11,11,11,
  135704. 12,
  135705. };
  135706. static float _vq_quantthresh__44u6__p6_0[] = {
  135707. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  135708. };
  135709. static long _vq_quantmap__44u6__p6_0[] = {
  135710. 7, 5, 3, 1, 0, 2, 4, 6,
  135711. 8,
  135712. };
  135713. static encode_aux_threshmatch _vq_auxt__44u6__p6_0 = {
  135714. _vq_quantthresh__44u6__p6_0,
  135715. _vq_quantmap__44u6__p6_0,
  135716. 9,
  135717. 9
  135718. };
  135719. static static_codebook _44u6__p6_0 = {
  135720. 2, 81,
  135721. _vq_lengthlist__44u6__p6_0,
  135722. 1, -531628032, 1611661312, 4, 0,
  135723. _vq_quantlist__44u6__p6_0,
  135724. NULL,
  135725. &_vq_auxt__44u6__p6_0,
  135726. NULL,
  135727. 0
  135728. };
  135729. static long _vq_quantlist__44u6__p7_0[] = {
  135730. 1,
  135731. 0,
  135732. 2,
  135733. };
  135734. static long _vq_lengthlist__44u6__p7_0[] = {
  135735. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 8, 7,10,10, 8,
  135736. 10,10, 5, 8, 9, 7,10,10, 7,10, 9, 4, 8, 8, 9,11,
  135737. 11, 8,11,11, 7,11,11,10,10,13,10,13,13, 7,11,11,
  135738. 10,13,12,10,13,13, 5, 9, 8, 8,11,11, 9,11,11, 7,
  135739. 11,11,10,13,13,10,12,13, 7,11,11,10,13,13, 9,13,
  135740. 10,
  135741. };
  135742. static float _vq_quantthresh__44u6__p7_0[] = {
  135743. -5.5, 5.5,
  135744. };
  135745. static long _vq_quantmap__44u6__p7_0[] = {
  135746. 1, 0, 2,
  135747. };
  135748. static encode_aux_threshmatch _vq_auxt__44u6__p7_0 = {
  135749. _vq_quantthresh__44u6__p7_0,
  135750. _vq_quantmap__44u6__p7_0,
  135751. 3,
  135752. 3
  135753. };
  135754. static static_codebook _44u6__p7_0 = {
  135755. 4, 81,
  135756. _vq_lengthlist__44u6__p7_0,
  135757. 1, -529137664, 1618345984, 2, 0,
  135758. _vq_quantlist__44u6__p7_0,
  135759. NULL,
  135760. &_vq_auxt__44u6__p7_0,
  135761. NULL,
  135762. 0
  135763. };
  135764. static long _vq_quantlist__44u6__p7_1[] = {
  135765. 5,
  135766. 4,
  135767. 6,
  135768. 3,
  135769. 7,
  135770. 2,
  135771. 8,
  135772. 1,
  135773. 9,
  135774. 0,
  135775. 10,
  135776. };
  135777. static long _vq_lengthlist__44u6__p7_1[] = {
  135778. 3, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 5, 5, 7, 6,
  135779. 8, 8, 8, 8, 8, 8, 4, 5, 5, 6, 7, 8, 8, 8, 8, 8,
  135780. 8, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 6, 7, 7, 7,
  135781. 7, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 9, 9,
  135782. 9, 9, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 8, 8, 8,
  135783. 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9,
  135784. 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 8,
  135785. 8, 8, 8, 9, 9, 9, 9, 9, 9,
  135786. };
  135787. static float _vq_quantthresh__44u6__p7_1[] = {
  135788. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  135789. 3.5, 4.5,
  135790. };
  135791. static long _vq_quantmap__44u6__p7_1[] = {
  135792. 9, 7, 5, 3, 1, 0, 2, 4,
  135793. 6, 8, 10,
  135794. };
  135795. static encode_aux_threshmatch _vq_auxt__44u6__p7_1 = {
  135796. _vq_quantthresh__44u6__p7_1,
  135797. _vq_quantmap__44u6__p7_1,
  135798. 11,
  135799. 11
  135800. };
  135801. static static_codebook _44u6__p7_1 = {
  135802. 2, 121,
  135803. _vq_lengthlist__44u6__p7_1,
  135804. 1, -531365888, 1611661312, 4, 0,
  135805. _vq_quantlist__44u6__p7_1,
  135806. NULL,
  135807. &_vq_auxt__44u6__p7_1,
  135808. NULL,
  135809. 0
  135810. };
  135811. static long _vq_quantlist__44u6__p8_0[] = {
  135812. 5,
  135813. 4,
  135814. 6,
  135815. 3,
  135816. 7,
  135817. 2,
  135818. 8,
  135819. 1,
  135820. 9,
  135821. 0,
  135822. 10,
  135823. };
  135824. static long _vq_lengthlist__44u6__p8_0[] = {
  135825. 1, 4, 4, 6, 6, 8, 8, 9, 9,10,10, 4, 6, 6, 7, 7,
  135826. 9, 9,10,10,11,11, 4, 6, 6, 7, 7, 9, 9,10,10,11,
  135827. 11, 6, 8, 8, 9, 9,10,10,11,11,12,12, 6, 8, 8, 9,
  135828. 9,10,10,11,11,12,12, 8, 9, 9,10,10,11,11,12,12,
  135829. 13,13, 8, 9, 9,10,10,11,11,12,12,13,13,10,10,10,
  135830. 11,11,13,13,13,13,15,14, 9,10,10,12,11,12,13,13,
  135831. 13,14,15,11,12,12,13,13,13,13,15,14,15,15,11,11,
  135832. 12,13,13,14,14,14,15,15,15,
  135833. };
  135834. static float _vq_quantthresh__44u6__p8_0[] = {
  135835. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  135836. 38.5, 49.5,
  135837. };
  135838. static long _vq_quantmap__44u6__p8_0[] = {
  135839. 9, 7, 5, 3, 1, 0, 2, 4,
  135840. 6, 8, 10,
  135841. };
  135842. static encode_aux_threshmatch _vq_auxt__44u6__p8_0 = {
  135843. _vq_quantthresh__44u6__p8_0,
  135844. _vq_quantmap__44u6__p8_0,
  135845. 11,
  135846. 11
  135847. };
  135848. static static_codebook _44u6__p8_0 = {
  135849. 2, 121,
  135850. _vq_lengthlist__44u6__p8_0,
  135851. 1, -524582912, 1618345984, 4, 0,
  135852. _vq_quantlist__44u6__p8_0,
  135853. NULL,
  135854. &_vq_auxt__44u6__p8_0,
  135855. NULL,
  135856. 0
  135857. };
  135858. static long _vq_quantlist__44u6__p8_1[] = {
  135859. 5,
  135860. 4,
  135861. 6,
  135862. 3,
  135863. 7,
  135864. 2,
  135865. 8,
  135866. 1,
  135867. 9,
  135868. 0,
  135869. 10,
  135870. };
  135871. static long _vq_lengthlist__44u6__p8_1[] = {
  135872. 3, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 5, 7, 7,
  135873. 7, 7, 8, 7, 8, 8, 5, 5, 6, 6, 7, 7, 7, 7, 7, 8,
  135874. 8, 6, 7, 7, 7, 7, 8, 7, 8, 8, 8, 8, 6, 6, 7, 7,
  135875. 7, 7, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8,
  135876. 8, 8, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7,
  135877. 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8,
  135878. 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8,
  135879. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  135880. };
  135881. static float _vq_quantthresh__44u6__p8_1[] = {
  135882. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  135883. 3.5, 4.5,
  135884. };
  135885. static long _vq_quantmap__44u6__p8_1[] = {
  135886. 9, 7, 5, 3, 1, 0, 2, 4,
  135887. 6, 8, 10,
  135888. };
  135889. static encode_aux_threshmatch _vq_auxt__44u6__p8_1 = {
  135890. _vq_quantthresh__44u6__p8_1,
  135891. _vq_quantmap__44u6__p8_1,
  135892. 11,
  135893. 11
  135894. };
  135895. static static_codebook _44u6__p8_1 = {
  135896. 2, 121,
  135897. _vq_lengthlist__44u6__p8_1,
  135898. 1, -531365888, 1611661312, 4, 0,
  135899. _vq_quantlist__44u6__p8_1,
  135900. NULL,
  135901. &_vq_auxt__44u6__p8_1,
  135902. NULL,
  135903. 0
  135904. };
  135905. static long _vq_quantlist__44u6__p9_0[] = {
  135906. 7,
  135907. 6,
  135908. 8,
  135909. 5,
  135910. 9,
  135911. 4,
  135912. 10,
  135913. 3,
  135914. 11,
  135915. 2,
  135916. 12,
  135917. 1,
  135918. 13,
  135919. 0,
  135920. 14,
  135921. };
  135922. static long _vq_lengthlist__44u6__p9_0[] = {
  135923. 1, 3, 2, 9, 8,15,15,15,15,15,15,15,15,15,15, 4,
  135924. 8, 9,13,14,14,14,14,14,14,14,14,14,14,14, 5, 8,
  135925. 9,14,14,14,14,14,14,14,14,14,14,14,14,11,14,14,
  135926. 14,14,14,14,14,14,14,14,14,14,14,14,11,14,14,14,
  135927. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135928. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135929. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135930. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135931. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135932. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135933. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135934. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135935. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135936. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135937. 14,
  135938. };
  135939. static float _vq_quantthresh__44u6__p9_0[] = {
  135940. -1657.5, -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5,
  135941. 382.5, 637.5, 892.5, 1147.5, 1402.5, 1657.5,
  135942. };
  135943. static long _vq_quantmap__44u6__p9_0[] = {
  135944. 13, 11, 9, 7, 5, 3, 1, 0,
  135945. 2, 4, 6, 8, 10, 12, 14,
  135946. };
  135947. static encode_aux_threshmatch _vq_auxt__44u6__p9_0 = {
  135948. _vq_quantthresh__44u6__p9_0,
  135949. _vq_quantmap__44u6__p9_0,
  135950. 15,
  135951. 15
  135952. };
  135953. static static_codebook _44u6__p9_0 = {
  135954. 2, 225,
  135955. _vq_lengthlist__44u6__p9_0,
  135956. 1, -514071552, 1627381760, 4, 0,
  135957. _vq_quantlist__44u6__p9_0,
  135958. NULL,
  135959. &_vq_auxt__44u6__p9_0,
  135960. NULL,
  135961. 0
  135962. };
  135963. static long _vq_quantlist__44u6__p9_1[] = {
  135964. 7,
  135965. 6,
  135966. 8,
  135967. 5,
  135968. 9,
  135969. 4,
  135970. 10,
  135971. 3,
  135972. 11,
  135973. 2,
  135974. 12,
  135975. 1,
  135976. 13,
  135977. 0,
  135978. 14,
  135979. };
  135980. static long _vq_lengthlist__44u6__p9_1[] = {
  135981. 1, 4, 4, 7, 7, 8, 9, 8, 8, 9, 8, 9, 8, 9, 9, 4,
  135982. 7, 6, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 4, 7,
  135983. 6, 9, 9,10,10, 9, 9,10,10,10,10,11,11, 7, 9, 8,
  135984. 10,10,11,11,10,10,11,11,11,11,11,11, 7, 8, 9,10,
  135985. 10,11,11,10,10,11,11,11,11,11,12, 8,10,10,11,11,
  135986. 12,12,11,11,12,12,12,12,13,12, 8,10,10,11,11,12,
  135987. 11,11,11,11,12,12,12,12,13, 8, 9, 9,11,10,11,11,
  135988. 12,12,12,12,13,12,13,12, 8, 9, 9,11,11,11,11,12,
  135989. 12,12,12,12,13,13,13, 9,10,10,11,12,12,12,12,12,
  135990. 13,13,13,13,13,13, 9,10,10,11,11,12,12,12,12,13,
  135991. 13,13,13,14,13,10,10,10,12,11,12,12,13,13,13,13,
  135992. 13,13,13,13,10,10,11,11,11,12,12,13,13,13,13,13,
  135993. 13,13,13,10,11,11,12,12,13,12,12,13,13,13,13,13,
  135994. 13,14,10,11,11,12,12,13,12,13,13,13,14,13,13,14,
  135995. 13,
  135996. };
  135997. static float _vq_quantthresh__44u6__p9_1[] = {
  135998. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  135999. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  136000. };
  136001. static long _vq_quantmap__44u6__p9_1[] = {
  136002. 13, 11, 9, 7, 5, 3, 1, 0,
  136003. 2, 4, 6, 8, 10, 12, 14,
  136004. };
  136005. static encode_aux_threshmatch _vq_auxt__44u6__p9_1 = {
  136006. _vq_quantthresh__44u6__p9_1,
  136007. _vq_quantmap__44u6__p9_1,
  136008. 15,
  136009. 15
  136010. };
  136011. static static_codebook _44u6__p9_1 = {
  136012. 2, 225,
  136013. _vq_lengthlist__44u6__p9_1,
  136014. 1, -522338304, 1620115456, 4, 0,
  136015. _vq_quantlist__44u6__p9_1,
  136016. NULL,
  136017. &_vq_auxt__44u6__p9_1,
  136018. NULL,
  136019. 0
  136020. };
  136021. static long _vq_quantlist__44u6__p9_2[] = {
  136022. 8,
  136023. 7,
  136024. 9,
  136025. 6,
  136026. 10,
  136027. 5,
  136028. 11,
  136029. 4,
  136030. 12,
  136031. 3,
  136032. 13,
  136033. 2,
  136034. 14,
  136035. 1,
  136036. 15,
  136037. 0,
  136038. 16,
  136039. };
  136040. static long _vq_lengthlist__44u6__p9_2[] = {
  136041. 3, 5, 5, 7, 7, 8, 8, 8, 8, 8, 8, 9, 8, 8, 9, 9,
  136042. 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9,
  136043. 9, 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9,
  136044. 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  136045. 9, 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  136046. 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  136047. 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  136048. 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  136049. 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 9, 9, 9, 9, 9,
  136050. 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 9, 9, 9, 9, 9, 9,
  136051. 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 8, 9, 9, 9, 9, 9,
  136052. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  136053. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9, 9, 9, 9, 9,
  136054. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9,
  136055. 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9,10, 9, 9, 9,
  136056. 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9,10, 9, 9,10, 9,
  136057. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 9,10, 9,10,10,
  136058. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,10,10, 9, 9,
  136059. 10,
  136060. };
  136061. static float _vq_quantthresh__44u6__p9_2[] = {
  136062. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  136063. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  136064. };
  136065. static long _vq_quantmap__44u6__p9_2[] = {
  136066. 15, 13, 11, 9, 7, 5, 3, 1,
  136067. 0, 2, 4, 6, 8, 10, 12, 14,
  136068. 16,
  136069. };
  136070. static encode_aux_threshmatch _vq_auxt__44u6__p9_2 = {
  136071. _vq_quantthresh__44u6__p9_2,
  136072. _vq_quantmap__44u6__p9_2,
  136073. 17,
  136074. 17
  136075. };
  136076. static static_codebook _44u6__p9_2 = {
  136077. 2, 289,
  136078. _vq_lengthlist__44u6__p9_2,
  136079. 1, -529530880, 1611661312, 5, 0,
  136080. _vq_quantlist__44u6__p9_2,
  136081. NULL,
  136082. &_vq_auxt__44u6__p9_2,
  136083. NULL,
  136084. 0
  136085. };
  136086. static long _huff_lengthlist__44u6__short[] = {
  136087. 4,11,16,13,17,13,17,16,17,17, 4, 7, 9, 9,13,10,
  136088. 16,12,16,17, 7, 6, 5, 7, 8, 9,12,12,16,17, 6, 9,
  136089. 7, 9,10,10,15,15,17,17, 6, 7, 5, 7, 5, 7, 7,10,
  136090. 16,17, 7, 9, 8, 9, 8,10,11,11,15,17, 7, 7, 7, 8,
  136091. 5, 8, 8, 9,15,17, 8, 7, 9, 9, 7, 8, 7, 2, 7,15,
  136092. 14,13,13,15, 5,10, 4, 3, 6,17,17,15,13,17, 7,11,
  136093. 7, 6, 9,16,
  136094. };
  136095. static static_codebook _huff_book__44u6__short = {
  136096. 2, 100,
  136097. _huff_lengthlist__44u6__short,
  136098. 0, 0, 0, 0, 0,
  136099. NULL,
  136100. NULL,
  136101. NULL,
  136102. NULL,
  136103. 0
  136104. };
  136105. static long _huff_lengthlist__44u7__long[] = {
  136106. 3, 9,14,13,15,14,16,13,13,14, 5, 5, 7, 7, 8, 9,
  136107. 11,10,12,15,10, 6, 5, 6, 6, 9,10,10,13,16,10, 6,
  136108. 6, 6, 6, 8, 9, 9,12,15,14, 7, 6, 6, 5, 6, 6, 8,
  136109. 12,15,10, 8, 7, 7, 6, 7, 7, 7,11,13,14,10, 9, 8,
  136110. 5, 6, 4, 5, 9,12,10, 9, 9, 8, 6, 6, 5, 3, 6,11,
  136111. 12,11,12,12,10, 9, 8, 5, 5, 8,10,11,15,13,13,13,
  136112. 12, 8, 6, 7,
  136113. };
  136114. static static_codebook _huff_book__44u7__long = {
  136115. 2, 100,
  136116. _huff_lengthlist__44u7__long,
  136117. 0, 0, 0, 0, 0,
  136118. NULL,
  136119. NULL,
  136120. NULL,
  136121. NULL,
  136122. 0
  136123. };
  136124. static long _vq_quantlist__44u7__p1_0[] = {
  136125. 1,
  136126. 0,
  136127. 2,
  136128. };
  136129. static long _vq_lengthlist__44u7__p1_0[] = {
  136130. 1, 4, 4, 4, 7, 7, 5, 7, 7, 5, 8, 8, 8,10,10, 7,
  136131. 10,10, 5, 8, 8, 7,10,10, 8,10,10, 5, 8, 8, 8,11,
  136132. 10, 8,10,10, 8,10,10,10,12,13,10,13,13, 7,10,10,
  136133. 10,13,12,10,13,13, 5, 8, 8, 8,11,10, 8,10,11, 7,
  136134. 10,10,10,13,13,10,12,13, 8,11,11,10,13,13,10,13,
  136135. 12,
  136136. };
  136137. static float _vq_quantthresh__44u7__p1_0[] = {
  136138. -0.5, 0.5,
  136139. };
  136140. static long _vq_quantmap__44u7__p1_0[] = {
  136141. 1, 0, 2,
  136142. };
  136143. static encode_aux_threshmatch _vq_auxt__44u7__p1_0 = {
  136144. _vq_quantthresh__44u7__p1_0,
  136145. _vq_quantmap__44u7__p1_0,
  136146. 3,
  136147. 3
  136148. };
  136149. static static_codebook _44u7__p1_0 = {
  136150. 4, 81,
  136151. _vq_lengthlist__44u7__p1_0,
  136152. 1, -535822336, 1611661312, 2, 0,
  136153. _vq_quantlist__44u7__p1_0,
  136154. NULL,
  136155. &_vq_auxt__44u7__p1_0,
  136156. NULL,
  136157. 0
  136158. };
  136159. static long _vq_quantlist__44u7__p2_0[] = {
  136160. 1,
  136161. 0,
  136162. 2,
  136163. };
  136164. static long _vq_lengthlist__44u7__p2_0[] = {
  136165. 3, 4, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 6, 8, 8, 6,
  136166. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 8, 5, 6, 6, 6, 8,
  136167. 7, 6, 8, 8, 6, 8, 8, 8, 9, 9, 8, 9, 9, 6, 8, 7,
  136168. 7, 9, 8, 8, 9, 9, 5, 6, 6, 6, 8, 7, 6, 8, 8, 6,
  136169. 8, 8, 8, 9, 9, 7, 8, 9, 6, 8, 8, 8, 9, 9, 8, 9,
  136170. 9,
  136171. };
  136172. static float _vq_quantthresh__44u7__p2_0[] = {
  136173. -0.5, 0.5,
  136174. };
  136175. static long _vq_quantmap__44u7__p2_0[] = {
  136176. 1, 0, 2,
  136177. };
  136178. static encode_aux_threshmatch _vq_auxt__44u7__p2_0 = {
  136179. _vq_quantthresh__44u7__p2_0,
  136180. _vq_quantmap__44u7__p2_0,
  136181. 3,
  136182. 3
  136183. };
  136184. static static_codebook _44u7__p2_0 = {
  136185. 4, 81,
  136186. _vq_lengthlist__44u7__p2_0,
  136187. 1, -535822336, 1611661312, 2, 0,
  136188. _vq_quantlist__44u7__p2_0,
  136189. NULL,
  136190. &_vq_auxt__44u7__p2_0,
  136191. NULL,
  136192. 0
  136193. };
  136194. static long _vq_quantlist__44u7__p3_0[] = {
  136195. 2,
  136196. 1,
  136197. 3,
  136198. 0,
  136199. 4,
  136200. };
  136201. static long _vq_lengthlist__44u7__p3_0[] = {
  136202. 2, 5, 4, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 8,
  136203. 9, 9,13,12, 8, 9,10,12,13, 5, 7, 7,10, 9, 7, 9,
  136204. 9,11,11, 6, 8, 9,11,11,10,11,11,14,14, 9,10,11,
  136205. 13,14, 5, 7, 7, 9, 9, 7, 9, 8,11,11, 7, 9, 9,11,
  136206. 11, 9,11,10,14,13,10,11,11,14,14, 8,10,10,14,13,
  136207. 10,11,12,15,14, 9,11,11,15,14,13,14,14,16,16,12,
  136208. 13,14,17,16, 8,10,10,13,13, 9,11,11,14,15,10,11,
  136209. 12,14,15,12,14,13,16,16,13,14,15,15,17, 5, 7, 7,
  136210. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,11,10,12,11,15,
  136211. 14,10,11,12,14,14, 7, 9, 9,12,12, 9,11,11,13,13,
  136212. 9,11,11,13,13,11,13,13,14,17,11,13,13,15,16, 6,
  136213. 9, 9,11,11, 8,11,10,13,12, 9,11,11,13,13,11,13,
  136214. 12,16,14,11,13,13,16,16,10,12,12,15,15,11,13,13,
  136215. 16,16,11,13,13,16,15,14,16,17,17,19,14,16,16,18,
  136216. 0, 9,11,11,14,15,10,13,12,16,15,11,13,13,16,16,
  136217. 14,15,14, 0,16,14,16,16,18, 0, 5, 7, 7,10,10, 7,
  136218. 9, 9,12,11, 7, 9, 9,11,12,10,11,11,15,14,10,11,
  136219. 12,14,14, 6, 9, 9,11,11, 9,11,11,13,13, 8,10,11,
  136220. 12,13,11,13,13,17,15,11,12,13,14,15, 7, 9, 9,11,
  136221. 12, 9,11,11,13,13, 9,11,11,13,13,11,13,12,16,16,
  136222. 11,13,13,15,14, 9,11,11,14,15,11,13,13,16,15,10,
  136223. 12,13,16,16,15,16,16, 0, 0,14,13,15,16,18,10,11,
  136224. 11,15,15,11,13,14,16,18,11,13,13,16,15,15,16,16,
  136225. 19, 0,14,15,15,16,16, 8,10,10,13,13,10,12,11,16,
  136226. 15,10,11,11,16,15,13,15,16,18, 0,13,14,15,17,17,
  136227. 9,11,11,15,15,11,13,13,16,18,11,13,13,16,17,15,
  136228. 16,16, 0, 0,15,18,16, 0,17, 9,11,11,15,15,11,13,
  136229. 12,17,15,11,13,14,16,17,15,18,15, 0,17,15,16,16,
  136230. 18,19,13,15,14, 0,18,14,16,16,19,18,14,16,15,19,
  136231. 19,16,18,19, 0, 0,16,17, 0, 0, 0,12,14,14,17,17,
  136232. 13,16,14, 0,18,14,16,15,18, 0,16,18,16,19,17,18,
  136233. 19,17, 0, 0, 8,10,10,14,14, 9,12,11,15,15,10,11,
  136234. 12,15,17,13,15,15,18,16,14,16,15,18,17, 9,11,11,
  136235. 16,15,11,13,13, 0,16,11,12,13,16,15,15,16,16, 0,
  136236. 17,15,15,16,18,17, 9,12,11,15,17,11,13,13,16,16,
  136237. 11,14,13,16,16,15,15,16,18,19,16,18,16, 0, 0,12,
  136238. 14,14, 0,16,14,16,16, 0,18,13,14,15,16, 0,17,16,
  136239. 18, 0, 0,16,16,17,19, 0,13,14,14,17, 0,14,17,16,
  136240. 0,19,14,15,15,18,19,17,16,18, 0, 0,15,19,16, 0,
  136241. 0,
  136242. };
  136243. static float _vq_quantthresh__44u7__p3_0[] = {
  136244. -1.5, -0.5, 0.5, 1.5,
  136245. };
  136246. static long _vq_quantmap__44u7__p3_0[] = {
  136247. 3, 1, 0, 2, 4,
  136248. };
  136249. static encode_aux_threshmatch _vq_auxt__44u7__p3_0 = {
  136250. _vq_quantthresh__44u7__p3_0,
  136251. _vq_quantmap__44u7__p3_0,
  136252. 5,
  136253. 5
  136254. };
  136255. static static_codebook _44u7__p3_0 = {
  136256. 4, 625,
  136257. _vq_lengthlist__44u7__p3_0,
  136258. 1, -533725184, 1611661312, 3, 0,
  136259. _vq_quantlist__44u7__p3_0,
  136260. NULL,
  136261. &_vq_auxt__44u7__p3_0,
  136262. NULL,
  136263. 0
  136264. };
  136265. static long _vq_quantlist__44u7__p4_0[] = {
  136266. 2,
  136267. 1,
  136268. 3,
  136269. 0,
  136270. 4,
  136271. };
  136272. static long _vq_lengthlist__44u7__p4_0[] = {
  136273. 4, 5, 5, 8, 8, 6, 7, 6, 9, 9, 6, 6, 7, 9, 9, 8,
  136274. 9, 9,11,11, 8, 9, 9,10,11, 6, 7, 7, 9, 9, 7, 8,
  136275. 8,10,10, 6, 7, 8, 9,10, 9,10,10,12,12, 9, 9,10,
  136276. 11,12, 6, 7, 7, 9, 9, 6, 8, 7,10, 9, 7, 8, 8,10,
  136277. 10, 9,10, 9,12,11, 9,10,10,12,11, 8, 9, 9,11,11,
  136278. 9,10,10,12,12, 9,10,10,12,12,11,12,12,13,14,11,
  136279. 11,12,13,13, 8, 9, 9,11,11, 9,10,10,12,11, 9,10,
  136280. 10,12,12,11,12,11,13,13,11,12,12,13,13, 6, 7, 7,
  136281. 9, 9, 7, 8, 7,10,10, 7, 7, 8,10,10, 9,10,10,12,
  136282. 11, 9,10,10,12,12, 7, 8, 8,10,10, 8, 8, 9,11,11,
  136283. 8, 9, 9,11,11,10,11,11,12,12,10,10,11,12,13, 6,
  136284. 7, 7,10,10, 7, 9, 8,11,10, 8, 8, 9,10,11,10,11,
  136285. 10,13,11,10,11,11,12,12, 9,10,10,12,12,10,10,11,
  136286. 13,13,10,11,11,13,12,12,12,13,13,14,12,12,13,14,
  136287. 14, 9,10,10,12,12, 9,10,10,12,12,10,11,11,13,13,
  136288. 11,12,11,14,12,12,13,13,14,14, 6, 7, 7, 9, 9, 7,
  136289. 8, 7,10,10, 7, 7, 8,10,10, 9,10,10,12,11, 9,10,
  136290. 10,11,12, 6, 7, 7,10,10, 8, 9, 8,11,10, 7, 8, 9,
  136291. 10,11,10,11,11,13,12,10,10,11,11,13, 7, 8, 8,10,
  136292. 10, 8, 9, 9,11,11, 8, 9, 9,11,11,10,11,10,13,12,
  136293. 10,11,11,12,12, 9,10,10,12,12,10,11,11,13,12, 9,
  136294. 10,10,12,13,12,13,12,14,14,11,11,12,12,14, 9,10,
  136295. 10,12,12,10,11,11,13,13,10,11,11,13,13,12,13,12,
  136296. 14,14,12,13,12,14,13, 8, 9, 9,11,11, 9,10,10,12,
  136297. 12, 9,10,10,12,12,11,12,12,14,13,11,12,12,13,13,
  136298. 9,10,10,12,12,10,11,11,13,13,10,11,11,13,12,12,
  136299. 13,13,14,14,12,12,13,14,14, 9,10,10,12,12, 9,11,
  136300. 10,13,12,10,10,11,12,13,11,13,12,14,13,12,12,13,
  136301. 14,14,11,12,12,13,13,11,12,13,14,14,12,13,13,14,
  136302. 14,13,13,14,14,16,13,14,14,16,16,11,11,11,13,13,
  136303. 11,12,11,14,13,12,12,13,14,15,13,14,12,16,13,14,
  136304. 14,14,15,16, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  136305. 10,12,12,11,12,12,14,13,11,12,12,13,14, 9,10,10,
  136306. 12,12,10,11,10,13,12, 9,10,11,12,13,12,13,12,14,
  136307. 14,12,12,13,13,14, 9,10,10,12,12,10,11,11,12,13,
  136308. 10,11,11,13,13,12,13,12,14,14,12,13,13,14,14,11,
  136309. 12,12,13,13,12,13,12,14,14,11,11,12,13,14,13,15,
  136310. 14,16,15,13,12,14,13,16,11,12,12,13,13,12,13,13,
  136311. 14,14,12,12,12,14,14,13,14,14,15,15,13,14,13,16,
  136312. 14,
  136313. };
  136314. static float _vq_quantthresh__44u7__p4_0[] = {
  136315. -1.5, -0.5, 0.5, 1.5,
  136316. };
  136317. static long _vq_quantmap__44u7__p4_0[] = {
  136318. 3, 1, 0, 2, 4,
  136319. };
  136320. static encode_aux_threshmatch _vq_auxt__44u7__p4_0 = {
  136321. _vq_quantthresh__44u7__p4_0,
  136322. _vq_quantmap__44u7__p4_0,
  136323. 5,
  136324. 5
  136325. };
  136326. static static_codebook _44u7__p4_0 = {
  136327. 4, 625,
  136328. _vq_lengthlist__44u7__p4_0,
  136329. 1, -533725184, 1611661312, 3, 0,
  136330. _vq_quantlist__44u7__p4_0,
  136331. NULL,
  136332. &_vq_auxt__44u7__p4_0,
  136333. NULL,
  136334. 0
  136335. };
  136336. static long _vq_quantlist__44u7__p5_0[] = {
  136337. 4,
  136338. 3,
  136339. 5,
  136340. 2,
  136341. 6,
  136342. 1,
  136343. 7,
  136344. 0,
  136345. 8,
  136346. };
  136347. static long _vq_lengthlist__44u7__p5_0[] = {
  136348. 2, 3, 3, 6, 6, 7, 8,10,10, 4, 5, 5, 8, 7, 8, 8,
  136349. 11,11, 3, 5, 5, 7, 7, 8, 9,11,11, 6, 8, 7, 9, 9,
  136350. 10,10,12,12, 6, 7, 8, 9,10,10,10,12,12, 8, 8, 8,
  136351. 10,10,12,11,13,13, 8, 8, 9,10,10,11,11,13,13,10,
  136352. 11,11,12,12,13,13,14,14,10,11,11,12,12,13,13,14,
  136353. 14,
  136354. };
  136355. static float _vq_quantthresh__44u7__p5_0[] = {
  136356. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  136357. };
  136358. static long _vq_quantmap__44u7__p5_0[] = {
  136359. 7, 5, 3, 1, 0, 2, 4, 6,
  136360. 8,
  136361. };
  136362. static encode_aux_threshmatch _vq_auxt__44u7__p5_0 = {
  136363. _vq_quantthresh__44u7__p5_0,
  136364. _vq_quantmap__44u7__p5_0,
  136365. 9,
  136366. 9
  136367. };
  136368. static static_codebook _44u7__p5_0 = {
  136369. 2, 81,
  136370. _vq_lengthlist__44u7__p5_0,
  136371. 1, -531628032, 1611661312, 4, 0,
  136372. _vq_quantlist__44u7__p5_0,
  136373. NULL,
  136374. &_vq_auxt__44u7__p5_0,
  136375. NULL,
  136376. 0
  136377. };
  136378. static long _vq_quantlist__44u7__p6_0[] = {
  136379. 4,
  136380. 3,
  136381. 5,
  136382. 2,
  136383. 6,
  136384. 1,
  136385. 7,
  136386. 0,
  136387. 8,
  136388. };
  136389. static long _vq_lengthlist__44u7__p6_0[] = {
  136390. 3, 4, 4, 5, 5, 7, 7, 9, 9, 4, 5, 4, 6, 6, 8, 7,
  136391. 9, 9, 4, 4, 5, 6, 6, 7, 7, 9, 9, 5, 6, 6, 7, 7,
  136392. 8, 8,10,10, 5, 6, 6, 7, 7, 8, 8,10,10, 7, 8, 7,
  136393. 8, 8,10, 9,11,11, 7, 7, 8, 8, 8, 9,10,11,11, 9,
  136394. 9, 9,10,10,11,10,12,11, 9, 9, 9,10,10,11,11,11,
  136395. 12,
  136396. };
  136397. static float _vq_quantthresh__44u7__p6_0[] = {
  136398. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  136399. };
  136400. static long _vq_quantmap__44u7__p6_0[] = {
  136401. 7, 5, 3, 1, 0, 2, 4, 6,
  136402. 8,
  136403. };
  136404. static encode_aux_threshmatch _vq_auxt__44u7__p6_0 = {
  136405. _vq_quantthresh__44u7__p6_0,
  136406. _vq_quantmap__44u7__p6_0,
  136407. 9,
  136408. 9
  136409. };
  136410. static static_codebook _44u7__p6_0 = {
  136411. 2, 81,
  136412. _vq_lengthlist__44u7__p6_0,
  136413. 1, -531628032, 1611661312, 4, 0,
  136414. _vq_quantlist__44u7__p6_0,
  136415. NULL,
  136416. &_vq_auxt__44u7__p6_0,
  136417. NULL,
  136418. 0
  136419. };
  136420. static long _vq_quantlist__44u7__p7_0[] = {
  136421. 1,
  136422. 0,
  136423. 2,
  136424. };
  136425. static long _vq_lengthlist__44u7__p7_0[] = {
  136426. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 8, 8, 9, 9, 7,
  136427. 10,10, 5, 8, 9, 7, 9,10, 8, 9, 9, 4, 9, 9, 9,11,
  136428. 10, 8,10,10, 7,11,10,10,10,12,10,12,12, 7,10,10,
  136429. 10,12,11,10,12,12, 5, 9, 9, 8,10,10, 9,11,11, 7,
  136430. 11,10,10,12,12,10,11,12, 7,10,11,10,12,12,10,12,
  136431. 10,
  136432. };
  136433. static float _vq_quantthresh__44u7__p7_0[] = {
  136434. -5.5, 5.5,
  136435. };
  136436. static long _vq_quantmap__44u7__p7_0[] = {
  136437. 1, 0, 2,
  136438. };
  136439. static encode_aux_threshmatch _vq_auxt__44u7__p7_0 = {
  136440. _vq_quantthresh__44u7__p7_0,
  136441. _vq_quantmap__44u7__p7_0,
  136442. 3,
  136443. 3
  136444. };
  136445. static static_codebook _44u7__p7_0 = {
  136446. 4, 81,
  136447. _vq_lengthlist__44u7__p7_0,
  136448. 1, -529137664, 1618345984, 2, 0,
  136449. _vq_quantlist__44u7__p7_0,
  136450. NULL,
  136451. &_vq_auxt__44u7__p7_0,
  136452. NULL,
  136453. 0
  136454. };
  136455. static long _vq_quantlist__44u7__p7_1[] = {
  136456. 5,
  136457. 4,
  136458. 6,
  136459. 3,
  136460. 7,
  136461. 2,
  136462. 8,
  136463. 1,
  136464. 9,
  136465. 0,
  136466. 10,
  136467. };
  136468. static long _vq_lengthlist__44u7__p7_1[] = {
  136469. 3, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 5, 5, 6, 6,
  136470. 8, 7, 8, 8, 8, 8, 4, 5, 5, 6, 6, 7, 8, 8, 8, 8,
  136471. 8, 6, 7, 6, 7, 7, 8, 8, 9, 9, 9, 9, 6, 6, 7, 7,
  136472. 7, 8, 8, 9, 9, 9, 9, 7, 8, 7, 8, 8, 9, 9, 9, 9,
  136473. 9, 9, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8,
  136474. 9, 9, 9, 9,10, 9, 9, 9, 8, 8, 8, 9, 9, 9, 9, 9,
  136475. 9, 9,10, 8, 8, 8, 9, 9, 9, 9,10, 9,10,10, 8, 8,
  136476. 8, 9, 9, 9, 9, 9,10,10,10,
  136477. };
  136478. static float _vq_quantthresh__44u7__p7_1[] = {
  136479. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  136480. 3.5, 4.5,
  136481. };
  136482. static long _vq_quantmap__44u7__p7_1[] = {
  136483. 9, 7, 5, 3, 1, 0, 2, 4,
  136484. 6, 8, 10,
  136485. };
  136486. static encode_aux_threshmatch _vq_auxt__44u7__p7_1 = {
  136487. _vq_quantthresh__44u7__p7_1,
  136488. _vq_quantmap__44u7__p7_1,
  136489. 11,
  136490. 11
  136491. };
  136492. static static_codebook _44u7__p7_1 = {
  136493. 2, 121,
  136494. _vq_lengthlist__44u7__p7_1,
  136495. 1, -531365888, 1611661312, 4, 0,
  136496. _vq_quantlist__44u7__p7_1,
  136497. NULL,
  136498. &_vq_auxt__44u7__p7_1,
  136499. NULL,
  136500. 0
  136501. };
  136502. static long _vq_quantlist__44u7__p8_0[] = {
  136503. 5,
  136504. 4,
  136505. 6,
  136506. 3,
  136507. 7,
  136508. 2,
  136509. 8,
  136510. 1,
  136511. 9,
  136512. 0,
  136513. 10,
  136514. };
  136515. static long _vq_lengthlist__44u7__p8_0[] = {
  136516. 1, 4, 4, 6, 6, 8, 8,10,10,11,11, 4, 6, 6, 7, 7,
  136517. 9, 9,11,10,12,12, 5, 6, 5, 7, 7, 9, 9,10,11,12,
  136518. 12, 6, 7, 7, 8, 8,10,10,11,11,13,13, 6, 7, 7, 8,
  136519. 8,10,10,11,12,13,13, 8, 9, 9,10,10,11,11,12,12,
  136520. 14,14, 8, 9, 9,10,10,11,11,12,12,14,14,10,10,10,
  136521. 11,11,13,12,14,14,15,15,10,10,10,12,12,13,13,14,
  136522. 14,15,15,11,12,12,13,13,14,14,15,14,16,15,11,12,
  136523. 12,13,13,14,14,15,15,15,16,
  136524. };
  136525. static float _vq_quantthresh__44u7__p8_0[] = {
  136526. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  136527. 38.5, 49.5,
  136528. };
  136529. static long _vq_quantmap__44u7__p8_0[] = {
  136530. 9, 7, 5, 3, 1, 0, 2, 4,
  136531. 6, 8, 10,
  136532. };
  136533. static encode_aux_threshmatch _vq_auxt__44u7__p8_0 = {
  136534. _vq_quantthresh__44u7__p8_0,
  136535. _vq_quantmap__44u7__p8_0,
  136536. 11,
  136537. 11
  136538. };
  136539. static static_codebook _44u7__p8_0 = {
  136540. 2, 121,
  136541. _vq_lengthlist__44u7__p8_0,
  136542. 1, -524582912, 1618345984, 4, 0,
  136543. _vq_quantlist__44u7__p8_0,
  136544. NULL,
  136545. &_vq_auxt__44u7__p8_0,
  136546. NULL,
  136547. 0
  136548. };
  136549. static long _vq_quantlist__44u7__p8_1[] = {
  136550. 5,
  136551. 4,
  136552. 6,
  136553. 3,
  136554. 7,
  136555. 2,
  136556. 8,
  136557. 1,
  136558. 9,
  136559. 0,
  136560. 10,
  136561. };
  136562. static long _vq_lengthlist__44u7__p8_1[] = {
  136563. 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 6, 7, 7,
  136564. 7, 7, 7, 7, 7, 7, 5, 6, 6, 6, 7, 7, 7, 7, 7, 7,
  136565. 7, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 6, 7, 7, 7,
  136566. 7, 7, 7, 7, 7, 8, 8, 7, 7, 7, 7, 7, 8, 7, 8, 8,
  136567. 8, 8, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  136568. 7, 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 8, 8, 8,
  136569. 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7,
  136570. 7, 8, 8, 8, 8, 8, 8, 8, 8,
  136571. };
  136572. static float _vq_quantthresh__44u7__p8_1[] = {
  136573. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  136574. 3.5, 4.5,
  136575. };
  136576. static long _vq_quantmap__44u7__p8_1[] = {
  136577. 9, 7, 5, 3, 1, 0, 2, 4,
  136578. 6, 8, 10,
  136579. };
  136580. static encode_aux_threshmatch _vq_auxt__44u7__p8_1 = {
  136581. _vq_quantthresh__44u7__p8_1,
  136582. _vq_quantmap__44u7__p8_1,
  136583. 11,
  136584. 11
  136585. };
  136586. static static_codebook _44u7__p8_1 = {
  136587. 2, 121,
  136588. _vq_lengthlist__44u7__p8_1,
  136589. 1, -531365888, 1611661312, 4, 0,
  136590. _vq_quantlist__44u7__p8_1,
  136591. NULL,
  136592. &_vq_auxt__44u7__p8_1,
  136593. NULL,
  136594. 0
  136595. };
  136596. static long _vq_quantlist__44u7__p9_0[] = {
  136597. 5,
  136598. 4,
  136599. 6,
  136600. 3,
  136601. 7,
  136602. 2,
  136603. 8,
  136604. 1,
  136605. 9,
  136606. 0,
  136607. 10,
  136608. };
  136609. static long _vq_lengthlist__44u7__p9_0[] = {
  136610. 1, 3, 3,10,10,10,10,10,10,10,10, 4,10,10,10,10,
  136611. 10,10,10,10,10,10, 4,10,10,10,10,10,10,10,10,10,
  136612. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  136613. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  136614. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  136615. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  136616. 10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  136617. 9, 9, 9, 9, 9, 9, 9, 9, 9,
  136618. };
  136619. static float _vq_quantthresh__44u7__p9_0[] = {
  136620. -2866.5, -2229.5, -1592.5, -955.5, -318.5, 318.5, 955.5, 1592.5,
  136621. 2229.5, 2866.5,
  136622. };
  136623. static long _vq_quantmap__44u7__p9_0[] = {
  136624. 9, 7, 5, 3, 1, 0, 2, 4,
  136625. 6, 8, 10,
  136626. };
  136627. static encode_aux_threshmatch _vq_auxt__44u7__p9_0 = {
  136628. _vq_quantthresh__44u7__p9_0,
  136629. _vq_quantmap__44u7__p9_0,
  136630. 11,
  136631. 11
  136632. };
  136633. static static_codebook _44u7__p9_0 = {
  136634. 2, 121,
  136635. _vq_lengthlist__44u7__p9_0,
  136636. 1, -512171520, 1630791680, 4, 0,
  136637. _vq_quantlist__44u7__p9_0,
  136638. NULL,
  136639. &_vq_auxt__44u7__p9_0,
  136640. NULL,
  136641. 0
  136642. };
  136643. static long _vq_quantlist__44u7__p9_1[] = {
  136644. 6,
  136645. 5,
  136646. 7,
  136647. 4,
  136648. 8,
  136649. 3,
  136650. 9,
  136651. 2,
  136652. 10,
  136653. 1,
  136654. 11,
  136655. 0,
  136656. 12,
  136657. };
  136658. static long _vq_lengthlist__44u7__p9_1[] = {
  136659. 1, 4, 4, 6, 5, 8, 6, 9, 8,10, 9,11,10, 4, 6, 6,
  136660. 8, 8, 9, 9,11,10,11,11,11,11, 4, 6, 6, 8, 8,10,
  136661. 9,11,11,11,11,11,12, 6, 8, 8,10,10,11,11,12,12,
  136662. 13,12,13,13, 6, 8, 8,10,10,11,11,12,12,12,13,14,
  136663. 13, 8,10,10,11,11,12,13,14,14,14,14,15,15, 8,10,
  136664. 10,11,12,12,13,13,14,14,14,14,15, 9,11,11,13,13,
  136665. 14,14,15,14,16,15,17,15, 9,11,11,12,13,14,14,15,
  136666. 14,15,15,15,16,10,12,12,13,14,15,15,15,15,16,17,
  136667. 16,17,10,13,12,13,14,14,16,16,16,16,15,16,17,11,
  136668. 13,13,14,15,14,17,15,16,17,17,17,17,11,13,13,14,
  136669. 15,15,15,15,17,17,16,17,16,
  136670. };
  136671. static float _vq_quantthresh__44u7__p9_1[] = {
  136672. -269.5, -220.5, -171.5, -122.5, -73.5, -24.5, 24.5, 73.5,
  136673. 122.5, 171.5, 220.5, 269.5,
  136674. };
  136675. static long _vq_quantmap__44u7__p9_1[] = {
  136676. 11, 9, 7, 5, 3, 1, 0, 2,
  136677. 4, 6, 8, 10, 12,
  136678. };
  136679. static encode_aux_threshmatch _vq_auxt__44u7__p9_1 = {
  136680. _vq_quantthresh__44u7__p9_1,
  136681. _vq_quantmap__44u7__p9_1,
  136682. 13,
  136683. 13
  136684. };
  136685. static static_codebook _44u7__p9_1 = {
  136686. 2, 169,
  136687. _vq_lengthlist__44u7__p9_1,
  136688. 1, -518889472, 1622704128, 4, 0,
  136689. _vq_quantlist__44u7__p9_1,
  136690. NULL,
  136691. &_vq_auxt__44u7__p9_1,
  136692. NULL,
  136693. 0
  136694. };
  136695. static long _vq_quantlist__44u7__p9_2[] = {
  136696. 24,
  136697. 23,
  136698. 25,
  136699. 22,
  136700. 26,
  136701. 21,
  136702. 27,
  136703. 20,
  136704. 28,
  136705. 19,
  136706. 29,
  136707. 18,
  136708. 30,
  136709. 17,
  136710. 31,
  136711. 16,
  136712. 32,
  136713. 15,
  136714. 33,
  136715. 14,
  136716. 34,
  136717. 13,
  136718. 35,
  136719. 12,
  136720. 36,
  136721. 11,
  136722. 37,
  136723. 10,
  136724. 38,
  136725. 9,
  136726. 39,
  136727. 8,
  136728. 40,
  136729. 7,
  136730. 41,
  136731. 6,
  136732. 42,
  136733. 5,
  136734. 43,
  136735. 4,
  136736. 44,
  136737. 3,
  136738. 45,
  136739. 2,
  136740. 46,
  136741. 1,
  136742. 47,
  136743. 0,
  136744. 48,
  136745. };
  136746. static long _vq_lengthlist__44u7__p9_2[] = {
  136747. 2, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6,
  136748. 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  136749. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
  136750. 8,
  136751. };
  136752. static float _vq_quantthresh__44u7__p9_2[] = {
  136753. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  136754. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  136755. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  136756. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  136757. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  136758. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  136759. };
  136760. static long _vq_quantmap__44u7__p9_2[] = {
  136761. 47, 45, 43, 41, 39, 37, 35, 33,
  136762. 31, 29, 27, 25, 23, 21, 19, 17,
  136763. 15, 13, 11, 9, 7, 5, 3, 1,
  136764. 0, 2, 4, 6, 8, 10, 12, 14,
  136765. 16, 18, 20, 22, 24, 26, 28, 30,
  136766. 32, 34, 36, 38, 40, 42, 44, 46,
  136767. 48,
  136768. };
  136769. static encode_aux_threshmatch _vq_auxt__44u7__p9_2 = {
  136770. _vq_quantthresh__44u7__p9_2,
  136771. _vq_quantmap__44u7__p9_2,
  136772. 49,
  136773. 49
  136774. };
  136775. static static_codebook _44u7__p9_2 = {
  136776. 1, 49,
  136777. _vq_lengthlist__44u7__p9_2,
  136778. 1, -526909440, 1611661312, 6, 0,
  136779. _vq_quantlist__44u7__p9_2,
  136780. NULL,
  136781. &_vq_auxt__44u7__p9_2,
  136782. NULL,
  136783. 0
  136784. };
  136785. static long _huff_lengthlist__44u7__short[] = {
  136786. 5,12,17,16,16,17,17,17,17,17, 4, 7,11,11,12, 9,
  136787. 17,10,17,17, 7, 7, 8, 9, 7, 9,11,10,15,17, 7, 9,
  136788. 10,11,10,12,14,12,16,17, 7, 8, 5, 7, 4, 7, 7, 8,
  136789. 16,16, 6,10, 9,10, 7,10,11,11,16,17, 6, 8, 8, 9,
  136790. 5, 7, 5, 8,16,17, 5, 5, 8, 7, 6, 7, 7, 6, 6,14,
  136791. 12,10,12,11, 7,11, 4, 4, 2, 7,17,15,15,15, 8,15,
  136792. 6, 8, 5, 9,
  136793. };
  136794. static static_codebook _huff_book__44u7__short = {
  136795. 2, 100,
  136796. _huff_lengthlist__44u7__short,
  136797. 0, 0, 0, 0, 0,
  136798. NULL,
  136799. NULL,
  136800. NULL,
  136801. NULL,
  136802. 0
  136803. };
  136804. static long _huff_lengthlist__44u8__long[] = {
  136805. 3, 9,13,14,14,15,14,14,15,15, 5, 4, 6, 8,10,12,
  136806. 12,14,15,15, 9, 5, 4, 5, 8,10,11,13,16,16,10, 7,
  136807. 4, 3, 5, 7, 9,11,13,13,10, 9, 7, 4, 4, 6, 8,10,
  136808. 12,14,13,11, 9, 6, 5, 5, 6, 8,12,14,13,11,10, 8,
  136809. 7, 6, 6, 7,10,14,13,11,12,10, 8, 7, 6, 6, 9,13,
  136810. 12,11,14,12,11, 9, 8, 7, 9,11,11,12,14,13,14,11,
  136811. 10, 8, 8, 9,
  136812. };
  136813. static static_codebook _huff_book__44u8__long = {
  136814. 2, 100,
  136815. _huff_lengthlist__44u8__long,
  136816. 0, 0, 0, 0, 0,
  136817. NULL,
  136818. NULL,
  136819. NULL,
  136820. NULL,
  136821. 0
  136822. };
  136823. static long _huff_lengthlist__44u8__short[] = {
  136824. 6,14,18,18,17,17,17,17,17,17, 4, 7, 9, 9,10,13,
  136825. 15,17,17,17, 6, 7, 5, 6, 8,11,16,17,16,17, 5, 7,
  136826. 5, 4, 6,10,14,17,17,17, 6, 6, 6, 5, 7,10,13,16,
  136827. 17,17, 7, 6, 7, 7, 7, 8, 7,10,15,16,12, 9, 9, 6,
  136828. 6, 5, 3, 5,11,15,14,14,13, 5, 5, 7, 3, 4, 8,15,
  136829. 17,17,13, 7, 7,10, 6, 6,10,15,17,17,16,10,11,14,
  136830. 10,10,15,17,
  136831. };
  136832. static static_codebook _huff_book__44u8__short = {
  136833. 2, 100,
  136834. _huff_lengthlist__44u8__short,
  136835. 0, 0, 0, 0, 0,
  136836. NULL,
  136837. NULL,
  136838. NULL,
  136839. NULL,
  136840. 0
  136841. };
  136842. static long _vq_quantlist__44u8_p1_0[] = {
  136843. 1,
  136844. 0,
  136845. 2,
  136846. };
  136847. static long _vq_lengthlist__44u8_p1_0[] = {
  136848. 1, 5, 5, 5, 7, 7, 5, 7, 7, 5, 7, 7, 8, 9, 9, 7,
  136849. 9, 9, 5, 7, 7, 7, 9, 9, 8, 9, 9, 5, 7, 7, 7, 9,
  136850. 9, 7, 9, 9, 7, 9, 9, 9,10,11, 9,11,10, 7, 9, 9,
  136851. 9,11,10, 9,10,11, 5, 7, 7, 7, 9, 9, 7, 9, 9, 7,
  136852. 9, 9, 9,11,10, 9,10,10, 8, 9, 9, 9,11,11, 9,11,
  136853. 10,
  136854. };
  136855. static float _vq_quantthresh__44u8_p1_0[] = {
  136856. -0.5, 0.5,
  136857. };
  136858. static long _vq_quantmap__44u8_p1_0[] = {
  136859. 1, 0, 2,
  136860. };
  136861. static encode_aux_threshmatch _vq_auxt__44u8_p1_0 = {
  136862. _vq_quantthresh__44u8_p1_0,
  136863. _vq_quantmap__44u8_p1_0,
  136864. 3,
  136865. 3
  136866. };
  136867. static static_codebook _44u8_p1_0 = {
  136868. 4, 81,
  136869. _vq_lengthlist__44u8_p1_0,
  136870. 1, -535822336, 1611661312, 2, 0,
  136871. _vq_quantlist__44u8_p1_0,
  136872. NULL,
  136873. &_vq_auxt__44u8_p1_0,
  136874. NULL,
  136875. 0
  136876. };
  136877. static long _vq_quantlist__44u8_p2_0[] = {
  136878. 2,
  136879. 1,
  136880. 3,
  136881. 0,
  136882. 4,
  136883. };
  136884. static long _vq_lengthlist__44u8_p2_0[] = {
  136885. 4, 5, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 8,
  136886. 9, 9,11,11, 8, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  136887. 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12, 9,10,10,
  136888. 11,12, 5, 7, 7, 9, 9, 7, 8, 7,10,10, 7, 8, 8,10,
  136889. 10, 9,10, 9,12,11, 9,10,10,12,12, 8, 9, 9,12,11,
  136890. 9,10,10,12,12, 9,10,10,12,12,11,12,12,14,14,11,
  136891. 11,12,13,14, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  136892. 10,12,12,11,12,11,13,13,11,12,12,14,14, 5, 7, 7,
  136893. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,
  136894. 12, 9,10,10,11,12, 7, 8, 8,10,10, 8, 9, 9,11,11,
  136895. 8, 9, 9,11,11,10,11,11,12,13,10,11,11,12,13, 6,
  136896. 8, 8,10,10, 8, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  136897. 10,13,12,10,11,11,13,13, 9,10,10,12,12,10,11,11,
  136898. 13,13,10,11,11,13,13,12,12,13,13,14,12,13,13,14,
  136899. 14, 9,10,10,12,12,10,11,10,13,12,10,11,11,13,13,
  136900. 11,13,12,14,13,12,13,13,14,14, 5, 7, 7, 9, 9, 7,
  136901. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12, 9,10,
  136902. 10,12,12, 7, 8, 8,10,10, 8, 9, 9,11,11, 8, 8, 9,
  136903. 10,11,10,11,11,13,13,10,10,11,12,13, 7, 8, 8,10,
  136904. 10, 8, 9, 9,11,11, 8, 9, 9,11,11,10,11,11,13,13,
  136905. 10,11,11,13,12, 9,10,10,12,12,10,11,11,13,13,10,
  136906. 10,11,12,13,12,13,13,14,14,12,12,13,13,14, 9,10,
  136907. 10,12,12,10,11,11,13,13,10,11,11,13,13,12,13,13,
  136908. 15,14,12,13,13,14,13, 8, 9, 9,11,11, 9,10,10,12,
  136909. 12, 9,10,10,12,12,12,12,12,14,13,11,12,12,14,14,
  136910. 9,10,10,12,12,10,11,11,13,13,10,11,11,13,13,12,
  136911. 13,13,14,15,12,13,13,14,15, 9,10,10,12,12,10,11,
  136912. 10,13,12,10,11,11,13,13,12,13,12,15,14,12,13,13,
  136913. 14,15,11,12,12,14,14,12,13,13,14,14,12,13,13,15,
  136914. 14,14,14,14,14,16,14,14,15,16,16,11,12,12,14,14,
  136915. 11,12,12,14,14,12,13,13,14,15,13,14,13,16,14,14,
  136916. 14,14,16,16, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  136917. 10,12,12,11,12,12,14,13,11,12,12,14,14, 9,10,10,
  136918. 12,12,10,11,11,13,13,10,10,11,12,13,12,13,13,15,
  136919. 14,12,12,13,13,14, 9,10,10,12,12,10,11,11,13,13,
  136920. 10,11,11,13,13,12,13,13,14,14,12,13,13,15,14,11,
  136921. 12,12,14,13,12,13,13,15,14,11,12,12,13,14,14,15,
  136922. 14,16,15,13,13,14,13,16,11,12,12,14,14,12,13,13,
  136923. 14,15,12,13,12,15,14,14,14,14,16,15,14,15,13,16,
  136924. 14,
  136925. };
  136926. static float _vq_quantthresh__44u8_p2_0[] = {
  136927. -1.5, -0.5, 0.5, 1.5,
  136928. };
  136929. static long _vq_quantmap__44u8_p2_0[] = {
  136930. 3, 1, 0, 2, 4,
  136931. };
  136932. static encode_aux_threshmatch _vq_auxt__44u8_p2_0 = {
  136933. _vq_quantthresh__44u8_p2_0,
  136934. _vq_quantmap__44u8_p2_0,
  136935. 5,
  136936. 5
  136937. };
  136938. static static_codebook _44u8_p2_0 = {
  136939. 4, 625,
  136940. _vq_lengthlist__44u8_p2_0,
  136941. 1, -533725184, 1611661312, 3, 0,
  136942. _vq_quantlist__44u8_p2_0,
  136943. NULL,
  136944. &_vq_auxt__44u8_p2_0,
  136945. NULL,
  136946. 0
  136947. };
  136948. static long _vq_quantlist__44u8_p3_0[] = {
  136949. 4,
  136950. 3,
  136951. 5,
  136952. 2,
  136953. 6,
  136954. 1,
  136955. 7,
  136956. 0,
  136957. 8,
  136958. };
  136959. static long _vq_lengthlist__44u8_p3_0[] = {
  136960. 3, 4, 4, 5, 5, 7, 7, 9, 9, 4, 5, 4, 6, 6, 7, 7,
  136961. 9, 9, 4, 4, 5, 6, 6, 7, 7, 9, 9, 5, 6, 6, 7, 7,
  136962. 8, 8,10,10, 6, 6, 6, 7, 7, 8, 8,10,10, 7, 7, 7,
  136963. 8, 8, 9, 9,11,10, 7, 7, 7, 8, 8, 9, 9,10,11, 9,
  136964. 9, 9,10,10,11,10,12,11, 9, 9, 9, 9,10,11,11,11,
  136965. 12,
  136966. };
  136967. static float _vq_quantthresh__44u8_p3_0[] = {
  136968. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  136969. };
  136970. static long _vq_quantmap__44u8_p3_0[] = {
  136971. 7, 5, 3, 1, 0, 2, 4, 6,
  136972. 8,
  136973. };
  136974. static encode_aux_threshmatch _vq_auxt__44u8_p3_0 = {
  136975. _vq_quantthresh__44u8_p3_0,
  136976. _vq_quantmap__44u8_p3_0,
  136977. 9,
  136978. 9
  136979. };
  136980. static static_codebook _44u8_p3_0 = {
  136981. 2, 81,
  136982. _vq_lengthlist__44u8_p3_0,
  136983. 1, -531628032, 1611661312, 4, 0,
  136984. _vq_quantlist__44u8_p3_0,
  136985. NULL,
  136986. &_vq_auxt__44u8_p3_0,
  136987. NULL,
  136988. 0
  136989. };
  136990. static long _vq_quantlist__44u8_p4_0[] = {
  136991. 8,
  136992. 7,
  136993. 9,
  136994. 6,
  136995. 10,
  136996. 5,
  136997. 11,
  136998. 4,
  136999. 12,
  137000. 3,
  137001. 13,
  137002. 2,
  137003. 14,
  137004. 1,
  137005. 15,
  137006. 0,
  137007. 16,
  137008. };
  137009. static long _vq_lengthlist__44u8_p4_0[] = {
  137010. 4, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8,10,10,11,11,11,
  137011. 11, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,
  137012. 12,12, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,
  137013. 11,12,12, 6, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  137014. 11,11,12,12, 6, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,
  137015. 10,11,11,12,12, 7, 7, 7, 8, 8, 9, 8,10, 9,10, 9,
  137016. 11,10,12,11,13,12, 7, 7, 7, 8, 8, 8, 9, 9,10, 9,
  137017. 10,10,11,11,12,12,13, 8, 8, 8, 9, 9, 9, 9,10,10,
  137018. 11,10,11,11,12,12,13,13, 8, 8, 8, 9, 9, 9,10,10,
  137019. 10,10,11,11,11,12,12,12,13, 8, 9, 9, 9, 9,10, 9,
  137020. 11,10,11,11,12,11,13,12,13,13, 8, 9, 9, 9, 9, 9,
  137021. 10,10,11,11,11,11,12,12,13,13,13,10,10,10,10,10,
  137022. 11,10,11,11,12,11,13,12,13,13,14,13,10,10,10,10,
  137023. 10,10,11,11,11,11,12,12,13,13,13,13,14,11,11,11,
  137024. 11,11,12,11,12,12,13,12,13,13,14,13,14,14,11,11,
  137025. 11,11,11,11,12,12,12,12,13,13,13,13,14,14,14,11,
  137026. 12,12,12,12,13,12,13,12,13,13,14,13,14,14,14,14,
  137027. 11,12,12,12,12,12,12,13,13,13,13,13,14,14,14,14,
  137028. 14,
  137029. };
  137030. static float _vq_quantthresh__44u8_p4_0[] = {
  137031. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  137032. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  137033. };
  137034. static long _vq_quantmap__44u8_p4_0[] = {
  137035. 15, 13, 11, 9, 7, 5, 3, 1,
  137036. 0, 2, 4, 6, 8, 10, 12, 14,
  137037. 16,
  137038. };
  137039. static encode_aux_threshmatch _vq_auxt__44u8_p4_0 = {
  137040. _vq_quantthresh__44u8_p4_0,
  137041. _vq_quantmap__44u8_p4_0,
  137042. 17,
  137043. 17
  137044. };
  137045. static static_codebook _44u8_p4_0 = {
  137046. 2, 289,
  137047. _vq_lengthlist__44u8_p4_0,
  137048. 1, -529530880, 1611661312, 5, 0,
  137049. _vq_quantlist__44u8_p4_0,
  137050. NULL,
  137051. &_vq_auxt__44u8_p4_0,
  137052. NULL,
  137053. 0
  137054. };
  137055. static long _vq_quantlist__44u8_p5_0[] = {
  137056. 1,
  137057. 0,
  137058. 2,
  137059. };
  137060. static long _vq_lengthlist__44u8_p5_0[] = {
  137061. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 8, 8, 9, 9, 7,
  137062. 9, 9, 5, 8, 8, 7, 9, 9, 8, 9, 9, 5, 8, 8, 8,10,
  137063. 10, 8,10,10, 7,10,10, 9,10,12, 9,12,11, 7,10,10,
  137064. 9,11,10, 9,11,12, 5, 8, 8, 8,10,10, 8,10,10, 7,
  137065. 10,10, 9,11,11, 9,10,11, 7,10,10, 9,11,11,10,12,
  137066. 10,
  137067. };
  137068. static float _vq_quantthresh__44u8_p5_0[] = {
  137069. -5.5, 5.5,
  137070. };
  137071. static long _vq_quantmap__44u8_p5_0[] = {
  137072. 1, 0, 2,
  137073. };
  137074. static encode_aux_threshmatch _vq_auxt__44u8_p5_0 = {
  137075. _vq_quantthresh__44u8_p5_0,
  137076. _vq_quantmap__44u8_p5_0,
  137077. 3,
  137078. 3
  137079. };
  137080. static static_codebook _44u8_p5_0 = {
  137081. 4, 81,
  137082. _vq_lengthlist__44u8_p5_0,
  137083. 1, -529137664, 1618345984, 2, 0,
  137084. _vq_quantlist__44u8_p5_0,
  137085. NULL,
  137086. &_vq_auxt__44u8_p5_0,
  137087. NULL,
  137088. 0
  137089. };
  137090. static long _vq_quantlist__44u8_p5_1[] = {
  137091. 5,
  137092. 4,
  137093. 6,
  137094. 3,
  137095. 7,
  137096. 2,
  137097. 8,
  137098. 1,
  137099. 9,
  137100. 0,
  137101. 10,
  137102. };
  137103. static long _vq_lengthlist__44u8_p5_1[] = {
  137104. 4, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 5, 5, 5, 6, 6,
  137105. 7, 7, 8, 8, 8, 8, 5, 5, 5, 6, 6, 7, 7, 7, 8, 8,
  137106. 8, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 6, 6, 6, 7,
  137107. 7, 7, 7, 8, 8, 8, 8, 7, 7, 7, 7, 7, 8, 8, 8, 8,
  137108. 8, 8, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 7, 8, 7,
  137109. 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8,
  137110. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 8, 8,
  137111. 8, 8, 8, 8, 8, 8, 8, 9, 9,
  137112. };
  137113. static float _vq_quantthresh__44u8_p5_1[] = {
  137114. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  137115. 3.5, 4.5,
  137116. };
  137117. static long _vq_quantmap__44u8_p5_1[] = {
  137118. 9, 7, 5, 3, 1, 0, 2, 4,
  137119. 6, 8, 10,
  137120. };
  137121. static encode_aux_threshmatch _vq_auxt__44u8_p5_1 = {
  137122. _vq_quantthresh__44u8_p5_1,
  137123. _vq_quantmap__44u8_p5_1,
  137124. 11,
  137125. 11
  137126. };
  137127. static static_codebook _44u8_p5_1 = {
  137128. 2, 121,
  137129. _vq_lengthlist__44u8_p5_1,
  137130. 1, -531365888, 1611661312, 4, 0,
  137131. _vq_quantlist__44u8_p5_1,
  137132. NULL,
  137133. &_vq_auxt__44u8_p5_1,
  137134. NULL,
  137135. 0
  137136. };
  137137. static long _vq_quantlist__44u8_p6_0[] = {
  137138. 6,
  137139. 5,
  137140. 7,
  137141. 4,
  137142. 8,
  137143. 3,
  137144. 9,
  137145. 2,
  137146. 10,
  137147. 1,
  137148. 11,
  137149. 0,
  137150. 12,
  137151. };
  137152. static long _vq_lengthlist__44u8_p6_0[] = {
  137153. 2, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 4, 6, 5,
  137154. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 4, 6, 6, 7, 7, 8,
  137155. 8, 8, 8, 9, 9,10,10, 6, 7, 7, 7, 8, 8, 8, 8, 9,
  137156. 9,10,10,10, 6, 7, 7, 8, 8, 8, 8, 9, 8,10, 9,11,
  137157. 10, 7, 8, 8, 8, 8, 8, 9, 9, 9,10,10,11,11, 7, 8,
  137158. 8, 8, 8, 9, 8, 9, 9,10,10,11,11, 8, 8, 8, 9, 9,
  137159. 9, 9, 9,10,10,10,11,11, 8, 8, 8, 9, 9, 9, 9,10,
  137160. 9,10,10,11,11, 9, 9, 9, 9,10,10,10,10,10,10,11,
  137161. 11,12, 9, 9, 9,10, 9,10,10,10,10,11,10,12,11,10,
  137162. 10,10,10,10,11,11,11,11,11,12,12,12,10,10,10,10,
  137163. 11,11,11,11,11,12,11,12,12,
  137164. };
  137165. static float _vq_quantthresh__44u8_p6_0[] = {
  137166. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  137167. 12.5, 17.5, 22.5, 27.5,
  137168. };
  137169. static long _vq_quantmap__44u8_p6_0[] = {
  137170. 11, 9, 7, 5, 3, 1, 0, 2,
  137171. 4, 6, 8, 10, 12,
  137172. };
  137173. static encode_aux_threshmatch _vq_auxt__44u8_p6_0 = {
  137174. _vq_quantthresh__44u8_p6_0,
  137175. _vq_quantmap__44u8_p6_0,
  137176. 13,
  137177. 13
  137178. };
  137179. static static_codebook _44u8_p6_0 = {
  137180. 2, 169,
  137181. _vq_lengthlist__44u8_p6_0,
  137182. 1, -526516224, 1616117760, 4, 0,
  137183. _vq_quantlist__44u8_p6_0,
  137184. NULL,
  137185. &_vq_auxt__44u8_p6_0,
  137186. NULL,
  137187. 0
  137188. };
  137189. static long _vq_quantlist__44u8_p6_1[] = {
  137190. 2,
  137191. 1,
  137192. 3,
  137193. 0,
  137194. 4,
  137195. };
  137196. static long _vq_lengthlist__44u8_p6_1[] = {
  137197. 3, 4, 4, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5,
  137198. 5, 5, 5, 5, 5, 5, 5, 5, 5,
  137199. };
  137200. static float _vq_quantthresh__44u8_p6_1[] = {
  137201. -1.5, -0.5, 0.5, 1.5,
  137202. };
  137203. static long _vq_quantmap__44u8_p6_1[] = {
  137204. 3, 1, 0, 2, 4,
  137205. };
  137206. static encode_aux_threshmatch _vq_auxt__44u8_p6_1 = {
  137207. _vq_quantthresh__44u8_p6_1,
  137208. _vq_quantmap__44u8_p6_1,
  137209. 5,
  137210. 5
  137211. };
  137212. static static_codebook _44u8_p6_1 = {
  137213. 2, 25,
  137214. _vq_lengthlist__44u8_p6_1,
  137215. 1, -533725184, 1611661312, 3, 0,
  137216. _vq_quantlist__44u8_p6_1,
  137217. NULL,
  137218. &_vq_auxt__44u8_p6_1,
  137219. NULL,
  137220. 0
  137221. };
  137222. static long _vq_quantlist__44u8_p7_0[] = {
  137223. 6,
  137224. 5,
  137225. 7,
  137226. 4,
  137227. 8,
  137228. 3,
  137229. 9,
  137230. 2,
  137231. 10,
  137232. 1,
  137233. 11,
  137234. 0,
  137235. 12,
  137236. };
  137237. static long _vq_lengthlist__44u8_p7_0[] = {
  137238. 1, 4, 5, 6, 6, 7, 7, 8, 8,10,10,11,11, 5, 6, 6,
  137239. 7, 7, 8, 8, 9, 9,11,10,12,11, 5, 6, 6, 7, 7, 8,
  137240. 8, 9, 9,10,11,11,12, 6, 7, 7, 8, 8, 9, 9,10,10,
  137241. 11,11,12,12, 6, 7, 7, 8, 8, 9, 9,10,10,11,12,13,
  137242. 12, 7, 8, 8, 9, 9,10,10,11,11,12,12,13,13, 8, 8,
  137243. 8, 9, 9,10,10,11,11,12,12,13,13, 9, 9, 9,10,10,
  137244. 11,11,12,12,13,13,14,14, 9, 9, 9,10,10,11,11,12,
  137245. 12,13,13,14,14,10,11,11,12,11,13,12,13,13,14,14,
  137246. 15,15,10,11,11,11,12,12,13,13,14,14,14,15,15,11,
  137247. 12,12,13,13,14,13,15,14,15,15,16,15,11,11,12,13,
  137248. 13,13,14,14,14,15,15,15,16,
  137249. };
  137250. static float _vq_quantthresh__44u8_p7_0[] = {
  137251. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  137252. 27.5, 38.5, 49.5, 60.5,
  137253. };
  137254. static long _vq_quantmap__44u8_p7_0[] = {
  137255. 11, 9, 7, 5, 3, 1, 0, 2,
  137256. 4, 6, 8, 10, 12,
  137257. };
  137258. static encode_aux_threshmatch _vq_auxt__44u8_p7_0 = {
  137259. _vq_quantthresh__44u8_p7_0,
  137260. _vq_quantmap__44u8_p7_0,
  137261. 13,
  137262. 13
  137263. };
  137264. static static_codebook _44u8_p7_0 = {
  137265. 2, 169,
  137266. _vq_lengthlist__44u8_p7_0,
  137267. 1, -523206656, 1618345984, 4, 0,
  137268. _vq_quantlist__44u8_p7_0,
  137269. NULL,
  137270. &_vq_auxt__44u8_p7_0,
  137271. NULL,
  137272. 0
  137273. };
  137274. static long _vq_quantlist__44u8_p7_1[] = {
  137275. 5,
  137276. 4,
  137277. 6,
  137278. 3,
  137279. 7,
  137280. 2,
  137281. 8,
  137282. 1,
  137283. 9,
  137284. 0,
  137285. 10,
  137286. };
  137287. static long _vq_lengthlist__44u8_p7_1[] = {
  137288. 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 6, 7, 7,
  137289. 7, 7, 7, 7, 7, 7, 5, 6, 6, 7, 7, 7, 7, 7, 7, 7,
  137290. 7, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 6, 7, 7, 7,
  137291. 7, 7, 7, 7, 7, 7, 8, 7, 7, 7, 7, 7, 7, 7, 8, 8,
  137292. 8, 8, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 7, 7, 7,
  137293. 8, 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 8, 8, 8,
  137294. 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7,
  137295. 7, 8, 8, 8, 8, 8, 8, 8, 8,
  137296. };
  137297. static float _vq_quantthresh__44u8_p7_1[] = {
  137298. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  137299. 3.5, 4.5,
  137300. };
  137301. static long _vq_quantmap__44u8_p7_1[] = {
  137302. 9, 7, 5, 3, 1, 0, 2, 4,
  137303. 6, 8, 10,
  137304. };
  137305. static encode_aux_threshmatch _vq_auxt__44u8_p7_1 = {
  137306. _vq_quantthresh__44u8_p7_1,
  137307. _vq_quantmap__44u8_p7_1,
  137308. 11,
  137309. 11
  137310. };
  137311. static static_codebook _44u8_p7_1 = {
  137312. 2, 121,
  137313. _vq_lengthlist__44u8_p7_1,
  137314. 1, -531365888, 1611661312, 4, 0,
  137315. _vq_quantlist__44u8_p7_1,
  137316. NULL,
  137317. &_vq_auxt__44u8_p7_1,
  137318. NULL,
  137319. 0
  137320. };
  137321. static long _vq_quantlist__44u8_p8_0[] = {
  137322. 7,
  137323. 6,
  137324. 8,
  137325. 5,
  137326. 9,
  137327. 4,
  137328. 10,
  137329. 3,
  137330. 11,
  137331. 2,
  137332. 12,
  137333. 1,
  137334. 13,
  137335. 0,
  137336. 14,
  137337. };
  137338. static long _vq_lengthlist__44u8_p8_0[] = {
  137339. 1, 4, 4, 7, 7, 8, 8, 8, 7, 9, 8,10, 9,11,10, 4,
  137340. 6, 6, 8, 8,10, 9, 9, 9,10,10,11,10,12,10, 4, 6,
  137341. 6, 8, 8,10,10, 9, 9,10,10,11,11,11,12, 7, 8, 8,
  137342. 10,10,11,11,11,10,12,11,12,12,13,11, 7, 8, 8,10,
  137343. 10,11,11,10,10,11,11,12,12,13,13, 8,10,10,11,11,
  137344. 12,11,12,11,13,12,13,12,14,13, 8,10, 9,11,11,12,
  137345. 12,12,12,12,12,13,13,14,13, 8, 9, 9,11,10,12,11,
  137346. 13,12,13,13,14,13,14,13, 8, 9, 9,10,11,12,12,12,
  137347. 12,13,13,14,15,14,14, 9,10,10,12,11,13,12,13,13,
  137348. 14,13,14,14,14,14, 9,10,10,12,12,12,12,13,13,14,
  137349. 14,14,15,14,14,10,11,11,13,12,13,12,14,14,14,14,
  137350. 14,14,15,15,10,11,11,12,12,13,13,14,14,14,15,15,
  137351. 14,16,15,11,12,12,13,12,14,14,14,13,15,14,15,15,
  137352. 15,17,11,12,12,13,13,14,14,14,15,15,14,15,15,14,
  137353. 17,
  137354. };
  137355. static float _vq_quantthresh__44u8_p8_0[] = {
  137356. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  137357. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  137358. };
  137359. static long _vq_quantmap__44u8_p8_0[] = {
  137360. 13, 11, 9, 7, 5, 3, 1, 0,
  137361. 2, 4, 6, 8, 10, 12, 14,
  137362. };
  137363. static encode_aux_threshmatch _vq_auxt__44u8_p8_0 = {
  137364. _vq_quantthresh__44u8_p8_0,
  137365. _vq_quantmap__44u8_p8_0,
  137366. 15,
  137367. 15
  137368. };
  137369. static static_codebook _44u8_p8_0 = {
  137370. 2, 225,
  137371. _vq_lengthlist__44u8_p8_0,
  137372. 1, -520986624, 1620377600, 4, 0,
  137373. _vq_quantlist__44u8_p8_0,
  137374. NULL,
  137375. &_vq_auxt__44u8_p8_0,
  137376. NULL,
  137377. 0
  137378. };
  137379. static long _vq_quantlist__44u8_p8_1[] = {
  137380. 10,
  137381. 9,
  137382. 11,
  137383. 8,
  137384. 12,
  137385. 7,
  137386. 13,
  137387. 6,
  137388. 14,
  137389. 5,
  137390. 15,
  137391. 4,
  137392. 16,
  137393. 3,
  137394. 17,
  137395. 2,
  137396. 18,
  137397. 1,
  137398. 19,
  137399. 0,
  137400. 20,
  137401. };
  137402. static long _vq_lengthlist__44u8_p8_1[] = {
  137403. 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  137404. 9, 9, 9, 9, 9, 6, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  137405. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 5, 6, 6, 7, 7, 8,
  137406. 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 7,
  137407. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137408. 9, 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  137409. 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9,
  137410. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,10, 8, 8,
  137411. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,
  137412. 10, 9,10, 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,
  137413. 10,10,10,10,10,10,10,10, 8, 9, 8, 9, 9, 9, 9, 9,
  137414. 9, 9, 9, 9, 9, 9,10,10,10,10, 9,10,10, 9, 9, 9,
  137415. 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,10,10,
  137416. 10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,
  137417. 10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9,10, 9,
  137418. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  137419. 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,
  137420. 10, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,
  137421. 10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  137422. 10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,
  137423. 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  137424. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  137425. 10,10,10,10,10, 9, 9, 9,10, 9,10,10,10,10,10,10,
  137426. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,
  137427. 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  137428. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  137429. 10,10,10,10, 9, 9, 9,10, 9,10, 9,10,10,10,10,10,
  137430. 10,10,10,10,10,10,10,10,10,
  137431. };
  137432. static float _vq_quantthresh__44u8_p8_1[] = {
  137433. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  137434. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  137435. 6.5, 7.5, 8.5, 9.5,
  137436. };
  137437. static long _vq_quantmap__44u8_p8_1[] = {
  137438. 19, 17, 15, 13, 11, 9, 7, 5,
  137439. 3, 1, 0, 2, 4, 6, 8, 10,
  137440. 12, 14, 16, 18, 20,
  137441. };
  137442. static encode_aux_threshmatch _vq_auxt__44u8_p8_1 = {
  137443. _vq_quantthresh__44u8_p8_1,
  137444. _vq_quantmap__44u8_p8_1,
  137445. 21,
  137446. 21
  137447. };
  137448. static static_codebook _44u8_p8_1 = {
  137449. 2, 441,
  137450. _vq_lengthlist__44u8_p8_1,
  137451. 1, -529268736, 1611661312, 5, 0,
  137452. _vq_quantlist__44u8_p8_1,
  137453. NULL,
  137454. &_vq_auxt__44u8_p8_1,
  137455. NULL,
  137456. 0
  137457. };
  137458. static long _vq_quantlist__44u8_p9_0[] = {
  137459. 4,
  137460. 3,
  137461. 5,
  137462. 2,
  137463. 6,
  137464. 1,
  137465. 7,
  137466. 0,
  137467. 8,
  137468. };
  137469. static long _vq_lengthlist__44u8_p9_0[] = {
  137470. 1, 3, 3, 9, 9, 9, 9, 9, 9, 4, 9, 9, 9, 9, 9, 9,
  137471. 9, 9, 5, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137472. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137473. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137474. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8,
  137475. 8,
  137476. };
  137477. static float _vq_quantthresh__44u8_p9_0[] = {
  137478. -3258.5, -2327.5, -1396.5, -465.5, 465.5, 1396.5, 2327.5, 3258.5,
  137479. };
  137480. static long _vq_quantmap__44u8_p9_0[] = {
  137481. 7, 5, 3, 1, 0, 2, 4, 6,
  137482. 8,
  137483. };
  137484. static encode_aux_threshmatch _vq_auxt__44u8_p9_0 = {
  137485. _vq_quantthresh__44u8_p9_0,
  137486. _vq_quantmap__44u8_p9_0,
  137487. 9,
  137488. 9
  137489. };
  137490. static static_codebook _44u8_p9_0 = {
  137491. 2, 81,
  137492. _vq_lengthlist__44u8_p9_0,
  137493. 1, -511895552, 1631393792, 4, 0,
  137494. _vq_quantlist__44u8_p9_0,
  137495. NULL,
  137496. &_vq_auxt__44u8_p9_0,
  137497. NULL,
  137498. 0
  137499. };
  137500. static long _vq_quantlist__44u8_p9_1[] = {
  137501. 9,
  137502. 8,
  137503. 10,
  137504. 7,
  137505. 11,
  137506. 6,
  137507. 12,
  137508. 5,
  137509. 13,
  137510. 4,
  137511. 14,
  137512. 3,
  137513. 15,
  137514. 2,
  137515. 16,
  137516. 1,
  137517. 17,
  137518. 0,
  137519. 18,
  137520. };
  137521. static long _vq_lengthlist__44u8_p9_1[] = {
  137522. 1, 4, 4, 7, 7, 8, 7, 8, 6, 9, 7,10, 8,11,10,11,
  137523. 11,11,11, 4, 7, 6, 9, 9,10, 9, 9, 9,10,10,11,10,
  137524. 11,10,11,11,13,11, 4, 7, 7, 9, 9, 9, 9, 9, 9,10,
  137525. 10,11,10,11,11,11,12,11,12, 7, 9, 8,11,11,11,11,
  137526. 10,10,11,11,12,12,12,12,12,12,14,13, 7, 8, 9,10,
  137527. 11,11,11,10,10,11,11,11,11,12,12,14,12,13,14, 8,
  137528. 9, 9,11,11,11,11,11,11,12,12,14,12,15,14,14,14,
  137529. 15,14, 8, 9, 9,11,11,11,11,12,11,12,12,13,13,13,
  137530. 13,13,13,14,14, 8, 9, 9,11,10,12,11,12,12,13,13,
  137531. 13,13,15,14,14,14,16,16, 8, 9, 9,10,11,11,12,12,
  137532. 12,13,13,13,14,14,14,15,16,15,15, 9,10,10,11,12,
  137533. 12,13,13,13,14,14,16,14,14,16,16,16,16,15, 9,10,
  137534. 10,11,11,12,13,13,14,15,14,16,14,15,16,16,16,16,
  137535. 15,10,11,11,12,13,13,14,15,15,15,15,15,16,15,16,
  137536. 15,16,15,15,10,11,11,13,13,14,13,13,15,14,15,15,
  137537. 16,15,15,15,16,15,16,10,12,12,14,14,14,14,14,16,
  137538. 16,15,15,15,16,16,16,16,16,16,11,12,12,14,14,14,
  137539. 14,15,15,16,15,16,15,16,15,16,16,16,16,12,12,13,
  137540. 14,14,15,16,16,16,16,16,16,15,16,16,16,16,16,16,
  137541. 12,13,13,14,14,14,14,15,16,15,16,16,16,16,16,16,
  137542. 16,16,16,12,13,14,14,14,16,15,16,15,16,16,16,16,
  137543. 16,16,16,16,16,16,12,14,13,14,15,15,15,16,15,16,
  137544. 16,15,16,16,16,16,16,16,16,
  137545. };
  137546. static float _vq_quantthresh__44u8_p9_1[] = {
  137547. -416.5, -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5,
  137548. -24.5, 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5,
  137549. 367.5, 416.5,
  137550. };
  137551. static long _vq_quantmap__44u8_p9_1[] = {
  137552. 17, 15, 13, 11, 9, 7, 5, 3,
  137553. 1, 0, 2, 4, 6, 8, 10, 12,
  137554. 14, 16, 18,
  137555. };
  137556. static encode_aux_threshmatch _vq_auxt__44u8_p9_1 = {
  137557. _vq_quantthresh__44u8_p9_1,
  137558. _vq_quantmap__44u8_p9_1,
  137559. 19,
  137560. 19
  137561. };
  137562. static static_codebook _44u8_p9_1 = {
  137563. 2, 361,
  137564. _vq_lengthlist__44u8_p9_1,
  137565. 1, -518287360, 1622704128, 5, 0,
  137566. _vq_quantlist__44u8_p9_1,
  137567. NULL,
  137568. &_vq_auxt__44u8_p9_1,
  137569. NULL,
  137570. 0
  137571. };
  137572. static long _vq_quantlist__44u8_p9_2[] = {
  137573. 24,
  137574. 23,
  137575. 25,
  137576. 22,
  137577. 26,
  137578. 21,
  137579. 27,
  137580. 20,
  137581. 28,
  137582. 19,
  137583. 29,
  137584. 18,
  137585. 30,
  137586. 17,
  137587. 31,
  137588. 16,
  137589. 32,
  137590. 15,
  137591. 33,
  137592. 14,
  137593. 34,
  137594. 13,
  137595. 35,
  137596. 12,
  137597. 36,
  137598. 11,
  137599. 37,
  137600. 10,
  137601. 38,
  137602. 9,
  137603. 39,
  137604. 8,
  137605. 40,
  137606. 7,
  137607. 41,
  137608. 6,
  137609. 42,
  137610. 5,
  137611. 43,
  137612. 4,
  137613. 44,
  137614. 3,
  137615. 45,
  137616. 2,
  137617. 46,
  137618. 1,
  137619. 47,
  137620. 0,
  137621. 48,
  137622. };
  137623. static long _vq_lengthlist__44u8_p9_2[] = {
  137624. 2, 3, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6,
  137625. 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137626. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137627. 7,
  137628. };
  137629. static float _vq_quantthresh__44u8_p9_2[] = {
  137630. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  137631. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  137632. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  137633. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  137634. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  137635. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  137636. };
  137637. static long _vq_quantmap__44u8_p9_2[] = {
  137638. 47, 45, 43, 41, 39, 37, 35, 33,
  137639. 31, 29, 27, 25, 23, 21, 19, 17,
  137640. 15, 13, 11, 9, 7, 5, 3, 1,
  137641. 0, 2, 4, 6, 8, 10, 12, 14,
  137642. 16, 18, 20, 22, 24, 26, 28, 30,
  137643. 32, 34, 36, 38, 40, 42, 44, 46,
  137644. 48,
  137645. };
  137646. static encode_aux_threshmatch _vq_auxt__44u8_p9_2 = {
  137647. _vq_quantthresh__44u8_p9_2,
  137648. _vq_quantmap__44u8_p9_2,
  137649. 49,
  137650. 49
  137651. };
  137652. static static_codebook _44u8_p9_2 = {
  137653. 1, 49,
  137654. _vq_lengthlist__44u8_p9_2,
  137655. 1, -526909440, 1611661312, 6, 0,
  137656. _vq_quantlist__44u8_p9_2,
  137657. NULL,
  137658. &_vq_auxt__44u8_p9_2,
  137659. NULL,
  137660. 0
  137661. };
  137662. static long _huff_lengthlist__44u9__long[] = {
  137663. 3, 9,13,13,14,15,14,14,15,15, 5, 5, 9,10,12,12,
  137664. 13,14,16,15,10, 6, 6, 6, 8,11,12,13,16,15,11, 7,
  137665. 5, 3, 5, 8,10,12,15,15,10,10, 7, 4, 3, 5, 8,10,
  137666. 12,12,12,12, 9, 7, 5, 4, 6, 8,10,13,13,12,11, 9,
  137667. 7, 5, 5, 6, 9,12,14,12,12,10, 8, 6, 6, 6, 7,11,
  137668. 13,12,14,13,10, 8, 7, 7, 7,10,11,11,12,13,12,11,
  137669. 10, 8, 8, 9,
  137670. };
  137671. static static_codebook _huff_book__44u9__long = {
  137672. 2, 100,
  137673. _huff_lengthlist__44u9__long,
  137674. 0, 0, 0, 0, 0,
  137675. NULL,
  137676. NULL,
  137677. NULL,
  137678. NULL,
  137679. 0
  137680. };
  137681. static long _huff_lengthlist__44u9__short[] = {
  137682. 9,16,18,18,17,17,17,17,17,17, 5, 8,11,12,11,12,
  137683. 17,17,16,16, 6, 6, 8, 8, 9,10,14,15,16,16, 6, 7,
  137684. 7, 4, 6, 9,13,16,16,16, 6, 6, 7, 4, 5, 8,11,15,
  137685. 17,16, 7, 6, 7, 6, 6, 8, 9,10,14,16,11, 8, 8, 7,
  137686. 6, 6, 3, 4,10,15,14,12,12,10, 5, 6, 3, 3, 8,13,
  137687. 15,17,15,11, 6, 8, 6, 6, 9,14,17,15,15,12, 8,10,
  137688. 9, 9,12,15,
  137689. };
  137690. static static_codebook _huff_book__44u9__short = {
  137691. 2, 100,
  137692. _huff_lengthlist__44u9__short,
  137693. 0, 0, 0, 0, 0,
  137694. NULL,
  137695. NULL,
  137696. NULL,
  137697. NULL,
  137698. 0
  137699. };
  137700. static long _vq_quantlist__44u9_p1_0[] = {
  137701. 1,
  137702. 0,
  137703. 2,
  137704. };
  137705. static long _vq_lengthlist__44u9_p1_0[] = {
  137706. 1, 5, 5, 5, 7, 7, 5, 7, 7, 5, 7, 7, 7, 9, 9, 7,
  137707. 9, 9, 5, 7, 7, 7, 9, 9, 7, 9, 9, 5, 7, 7, 7, 9,
  137708. 9, 7, 9, 9, 8, 9, 9, 9,10,11, 9,11,11, 7, 9, 9,
  137709. 9,11,10, 9,11,11, 5, 7, 7, 7, 9, 9, 8, 9,10, 7,
  137710. 9, 9, 9,11,11, 9,10,11, 7, 9,10, 9,11,11, 9,11,
  137711. 10,
  137712. };
  137713. static float _vq_quantthresh__44u9_p1_0[] = {
  137714. -0.5, 0.5,
  137715. };
  137716. static long _vq_quantmap__44u9_p1_0[] = {
  137717. 1, 0, 2,
  137718. };
  137719. static encode_aux_threshmatch _vq_auxt__44u9_p1_0 = {
  137720. _vq_quantthresh__44u9_p1_0,
  137721. _vq_quantmap__44u9_p1_0,
  137722. 3,
  137723. 3
  137724. };
  137725. static static_codebook _44u9_p1_0 = {
  137726. 4, 81,
  137727. _vq_lengthlist__44u9_p1_0,
  137728. 1, -535822336, 1611661312, 2, 0,
  137729. _vq_quantlist__44u9_p1_0,
  137730. NULL,
  137731. &_vq_auxt__44u9_p1_0,
  137732. NULL,
  137733. 0
  137734. };
  137735. static long _vq_quantlist__44u9_p2_0[] = {
  137736. 2,
  137737. 1,
  137738. 3,
  137739. 0,
  137740. 4,
  137741. };
  137742. static long _vq_lengthlist__44u9_p2_0[] = {
  137743. 3, 5, 5, 8, 8, 5, 7, 7, 9, 9, 6, 7, 7, 9, 9, 8,
  137744. 9, 9,11,10, 8, 9, 9,11,11, 6, 7, 7, 9, 9, 7, 8,
  137745. 8,10,10, 7, 8, 8, 9,10, 9,10,10,11,11, 9, 9,10,
  137746. 11,11, 6, 7, 7, 9, 9, 7, 8, 8,10, 9, 7, 8, 8,10,
  137747. 10, 9,10, 9,11,11, 9,10,10,11,11, 8, 9, 9,11,11,
  137748. 9,10,10,12,11, 9,10,10,11,12,11,11,11,13,13,11,
  137749. 11,11,12,13, 8, 9, 9,11,11, 9,10,10,11,11, 9,10,
  137750. 10,12,11,11,12,11,13,12,11,11,12,13,13, 6, 7, 7,
  137751. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,
  137752. 11, 9,10,10,11,12, 7, 8, 8,10,10, 8, 9, 9,11,11,
  137753. 8, 9, 9,10,10,10,11,11,12,12,10,10,11,12,12, 7,
  137754. 8, 8,10,10, 8, 9, 8,10,10, 8, 9, 9,10,10,10,11,
  137755. 10,12,11,10,10,11,12,12, 9,10,10,11,12,10,11,11,
  137756. 12,12,10,11,10,12,12,12,12,12,13,13,11,12,12,13,
  137757. 13, 9,10,10,11,11, 9,10,10,12,12,10,11,11,12,13,
  137758. 11,12,11,13,12,12,12,12,13,14, 6, 7, 7, 9, 9, 7,
  137759. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,11,11, 9,10,
  137760. 10,11,12, 7, 8, 8,10,10, 8, 9, 9,11,10, 8, 8, 9,
  137761. 10,10,10,11,10,12,12,10,10,11,11,12, 7, 8, 8,10,
  137762. 10, 8, 9, 9,10,10, 8, 9, 9,10,10,10,11,10,12,12,
  137763. 10,11,10,12,12, 9,10,10,12,11,10,11,11,12,12, 9,
  137764. 10,10,12,12,12,12,12,13,13,11,11,12,12,14, 9,10,
  137765. 10,11,12,10,11,11,12,12,10,11,11,12,12,11,12,12,
  137766. 14,14,12,12,12,13,13, 8, 9, 9,11,11, 9,10,10,12,
  137767. 11, 9,10,10,12,12,11,12,11,13,13,11,11,12,13,13,
  137768. 9,10,10,12,12,10,11,11,12,12,10,11,11,12,12,12,
  137769. 12,12,14,14,12,12,12,13,13, 9,10,10,12,11,10,11,
  137770. 10,12,12,10,11,11,12,12,11,12,12,14,13,12,12,12,
  137771. 13,14,11,12,11,13,13,11,12,12,13,13,12,12,12,14,
  137772. 14,13,13,13,13,15,13,13,14,15,15,11,11,11,13,13,
  137773. 11,12,11,13,13,11,12,12,13,13,12,13,12,15,13,13,
  137774. 13,14,14,15, 8, 9, 9,11,11, 9,10,10,11,12, 9,10,
  137775. 10,11,12,11,12,11,13,13,11,12,12,13,13, 9,10,10,
  137776. 11,12,10,11,10,12,12,10,10,11,12,13,12,12,12,14,
  137777. 13,11,12,12,13,14, 9,10,10,12,12,10,11,11,12,12,
  137778. 10,11,11,12,12,12,12,12,14,13,12,12,12,14,13,11,
  137779. 11,11,13,13,11,12,12,14,13,11,11,12,13,13,13,13,
  137780. 13,15,14,12,12,13,13,15,11,12,12,13,13,12,12,12,
  137781. 13,14,11,12,12,13,13,13,13,14,14,15,13,13,13,14,
  137782. 14,
  137783. };
  137784. static float _vq_quantthresh__44u9_p2_0[] = {
  137785. -1.5, -0.5, 0.5, 1.5,
  137786. };
  137787. static long _vq_quantmap__44u9_p2_0[] = {
  137788. 3, 1, 0, 2, 4,
  137789. };
  137790. static encode_aux_threshmatch _vq_auxt__44u9_p2_0 = {
  137791. _vq_quantthresh__44u9_p2_0,
  137792. _vq_quantmap__44u9_p2_0,
  137793. 5,
  137794. 5
  137795. };
  137796. static static_codebook _44u9_p2_0 = {
  137797. 4, 625,
  137798. _vq_lengthlist__44u9_p2_0,
  137799. 1, -533725184, 1611661312, 3, 0,
  137800. _vq_quantlist__44u9_p2_0,
  137801. NULL,
  137802. &_vq_auxt__44u9_p2_0,
  137803. NULL,
  137804. 0
  137805. };
  137806. static long _vq_quantlist__44u9_p3_0[] = {
  137807. 4,
  137808. 3,
  137809. 5,
  137810. 2,
  137811. 6,
  137812. 1,
  137813. 7,
  137814. 0,
  137815. 8,
  137816. };
  137817. static long _vq_lengthlist__44u9_p3_0[] = {
  137818. 3, 4, 4, 5, 5, 7, 7, 8, 8, 4, 5, 5, 6, 6, 7, 7,
  137819. 9, 9, 4, 4, 5, 6, 6, 7, 7, 9, 9, 5, 6, 6, 7, 7,
  137820. 8, 8, 9, 9, 5, 6, 6, 7, 7, 8, 8, 9, 9, 7, 7, 7,
  137821. 8, 8, 9, 9,10,10, 7, 7, 7, 8, 8, 9, 9,10,10, 8,
  137822. 9, 9,10, 9,10,10,11,11, 8, 9, 9, 9,10,10,10,11,
  137823. 11,
  137824. };
  137825. static float _vq_quantthresh__44u9_p3_0[] = {
  137826. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  137827. };
  137828. static long _vq_quantmap__44u9_p3_0[] = {
  137829. 7, 5, 3, 1, 0, 2, 4, 6,
  137830. 8,
  137831. };
  137832. static encode_aux_threshmatch _vq_auxt__44u9_p3_0 = {
  137833. _vq_quantthresh__44u9_p3_0,
  137834. _vq_quantmap__44u9_p3_0,
  137835. 9,
  137836. 9
  137837. };
  137838. static static_codebook _44u9_p3_0 = {
  137839. 2, 81,
  137840. _vq_lengthlist__44u9_p3_0,
  137841. 1, -531628032, 1611661312, 4, 0,
  137842. _vq_quantlist__44u9_p3_0,
  137843. NULL,
  137844. &_vq_auxt__44u9_p3_0,
  137845. NULL,
  137846. 0
  137847. };
  137848. static long _vq_quantlist__44u9_p4_0[] = {
  137849. 8,
  137850. 7,
  137851. 9,
  137852. 6,
  137853. 10,
  137854. 5,
  137855. 11,
  137856. 4,
  137857. 12,
  137858. 3,
  137859. 13,
  137860. 2,
  137861. 14,
  137862. 1,
  137863. 15,
  137864. 0,
  137865. 16,
  137866. };
  137867. static long _vq_lengthlist__44u9_p4_0[] = {
  137868. 4, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  137869. 11, 5, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,
  137870. 11,11, 5, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,
  137871. 10,11,11, 6, 6, 6, 7, 6, 7, 7, 8, 8, 9, 9,10,10,
  137872. 11,11,12,11, 6, 6, 6, 6, 7, 7, 7, 8, 8, 9, 9,10,
  137873. 10,11,11,11,12, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,
  137874. 10,10,11,11,12,12, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9,
  137875. 9,10,10,11,11,12,12, 8, 8, 8, 8, 8, 9, 8,10, 9,
  137876. 10,10,11,10,12,11,13,12, 8, 8, 8, 8, 8, 9, 9, 9,
  137877. 10,10,10,10,11,11,12,12,12, 8, 8, 8, 9, 9, 9, 9,
  137878. 10,10,11,10,12,11,12,12,13,12, 8, 8, 8, 9, 9, 9,
  137879. 9,10,10,10,11,11,11,12,12,12,13, 9, 9, 9,10,10,
  137880. 10,10,11,10,11,11,12,11,13,12,13,13, 9, 9,10,10,
  137881. 10,10,10,10,11,11,11,11,12,12,13,13,13,10,11,10,
  137882. 11,11,11,11,12,11,12,12,13,12,13,13,14,13,10,10,
  137883. 10,11,11,11,11,11,12,12,12,12,13,13,13,13,14,11,
  137884. 11,11,12,11,12,12,12,12,13,13,13,13,14,13,14,14,
  137885. 11,11,11,11,12,12,12,12,12,12,13,13,13,13,14,14,
  137886. 14,
  137887. };
  137888. static float _vq_quantthresh__44u9_p4_0[] = {
  137889. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  137890. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  137891. };
  137892. static long _vq_quantmap__44u9_p4_0[] = {
  137893. 15, 13, 11, 9, 7, 5, 3, 1,
  137894. 0, 2, 4, 6, 8, 10, 12, 14,
  137895. 16,
  137896. };
  137897. static encode_aux_threshmatch _vq_auxt__44u9_p4_0 = {
  137898. _vq_quantthresh__44u9_p4_0,
  137899. _vq_quantmap__44u9_p4_0,
  137900. 17,
  137901. 17
  137902. };
  137903. static static_codebook _44u9_p4_0 = {
  137904. 2, 289,
  137905. _vq_lengthlist__44u9_p4_0,
  137906. 1, -529530880, 1611661312, 5, 0,
  137907. _vq_quantlist__44u9_p4_0,
  137908. NULL,
  137909. &_vq_auxt__44u9_p4_0,
  137910. NULL,
  137911. 0
  137912. };
  137913. static long _vq_quantlist__44u9_p5_0[] = {
  137914. 1,
  137915. 0,
  137916. 2,
  137917. };
  137918. static long _vq_lengthlist__44u9_p5_0[] = {
  137919. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 8, 8, 9, 9, 7,
  137920. 9, 9, 5, 8, 8, 7, 9, 9, 8, 9, 9, 5, 8, 8, 8,10,
  137921. 10, 8,10,10, 7,10,10, 9,10,12, 9,11,11, 7,10,10,
  137922. 9,11,10, 9,11,12, 5, 8, 8, 8,10,10, 8,10,10, 7,
  137923. 10,10, 9,12,11, 9,10,11, 7,10,10, 9,11,11,10,12,
  137924. 10,
  137925. };
  137926. static float _vq_quantthresh__44u9_p5_0[] = {
  137927. -5.5, 5.5,
  137928. };
  137929. static long _vq_quantmap__44u9_p5_0[] = {
  137930. 1, 0, 2,
  137931. };
  137932. static encode_aux_threshmatch _vq_auxt__44u9_p5_0 = {
  137933. _vq_quantthresh__44u9_p5_0,
  137934. _vq_quantmap__44u9_p5_0,
  137935. 3,
  137936. 3
  137937. };
  137938. static static_codebook _44u9_p5_0 = {
  137939. 4, 81,
  137940. _vq_lengthlist__44u9_p5_0,
  137941. 1, -529137664, 1618345984, 2, 0,
  137942. _vq_quantlist__44u9_p5_0,
  137943. NULL,
  137944. &_vq_auxt__44u9_p5_0,
  137945. NULL,
  137946. 0
  137947. };
  137948. static long _vq_quantlist__44u9_p5_1[] = {
  137949. 5,
  137950. 4,
  137951. 6,
  137952. 3,
  137953. 7,
  137954. 2,
  137955. 8,
  137956. 1,
  137957. 9,
  137958. 0,
  137959. 10,
  137960. };
  137961. static long _vq_lengthlist__44u9_p5_1[] = {
  137962. 5, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 6, 6, 6,
  137963. 7, 7, 7, 7, 8, 7, 5, 6, 6, 6, 6, 7, 7, 7, 7, 7,
  137964. 7, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 6, 6, 6, 7,
  137965. 7, 7, 7, 7, 7, 8, 8, 7, 7, 7, 7, 7, 8, 7, 8, 8,
  137966. 8, 8, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  137967. 8, 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 8, 8, 8, 8,
  137968. 8, 8, 8, 7, 8, 7, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8,
  137969. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  137970. };
  137971. static float _vq_quantthresh__44u9_p5_1[] = {
  137972. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  137973. 3.5, 4.5,
  137974. };
  137975. static long _vq_quantmap__44u9_p5_1[] = {
  137976. 9, 7, 5, 3, 1, 0, 2, 4,
  137977. 6, 8, 10,
  137978. };
  137979. static encode_aux_threshmatch _vq_auxt__44u9_p5_1 = {
  137980. _vq_quantthresh__44u9_p5_1,
  137981. _vq_quantmap__44u9_p5_1,
  137982. 11,
  137983. 11
  137984. };
  137985. static static_codebook _44u9_p5_1 = {
  137986. 2, 121,
  137987. _vq_lengthlist__44u9_p5_1,
  137988. 1, -531365888, 1611661312, 4, 0,
  137989. _vq_quantlist__44u9_p5_1,
  137990. NULL,
  137991. &_vq_auxt__44u9_p5_1,
  137992. NULL,
  137993. 0
  137994. };
  137995. static long _vq_quantlist__44u9_p6_0[] = {
  137996. 6,
  137997. 5,
  137998. 7,
  137999. 4,
  138000. 8,
  138001. 3,
  138002. 9,
  138003. 2,
  138004. 10,
  138005. 1,
  138006. 11,
  138007. 0,
  138008. 12,
  138009. };
  138010. static long _vq_lengthlist__44u9_p6_0[] = {
  138011. 2, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 4, 6, 5,
  138012. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 4, 5, 6, 7, 7, 8,
  138013. 8, 8, 8, 9, 9,10,10, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  138014. 10,10,10,10, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,10,
  138015. 10, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,11, 7, 8,
  138016. 8, 8, 8, 9, 9, 9, 9,10,10,11,11, 8, 8, 8, 9, 9,
  138017. 9, 9, 9,10,10,10,11,11, 8, 8, 8, 9, 9, 9, 9,10,
  138018. 9,10,10,11,11, 9, 9, 9,10,10,10,10,10,11,11,11,
  138019. 11,12, 9, 9, 9,10,10,10,10,10,10,11,10,12,11,10,
  138020. 10,10,10,10,11,11,11,11,11,12,12,12,10,10,10,10,
  138021. 10,11,11,11,11,12,11,12,12,
  138022. };
  138023. static float _vq_quantthresh__44u9_p6_0[] = {
  138024. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  138025. 12.5, 17.5, 22.5, 27.5,
  138026. };
  138027. static long _vq_quantmap__44u9_p6_0[] = {
  138028. 11, 9, 7, 5, 3, 1, 0, 2,
  138029. 4, 6, 8, 10, 12,
  138030. };
  138031. static encode_aux_threshmatch _vq_auxt__44u9_p6_0 = {
  138032. _vq_quantthresh__44u9_p6_0,
  138033. _vq_quantmap__44u9_p6_0,
  138034. 13,
  138035. 13
  138036. };
  138037. static static_codebook _44u9_p6_0 = {
  138038. 2, 169,
  138039. _vq_lengthlist__44u9_p6_0,
  138040. 1, -526516224, 1616117760, 4, 0,
  138041. _vq_quantlist__44u9_p6_0,
  138042. NULL,
  138043. &_vq_auxt__44u9_p6_0,
  138044. NULL,
  138045. 0
  138046. };
  138047. static long _vq_quantlist__44u9_p6_1[] = {
  138048. 2,
  138049. 1,
  138050. 3,
  138051. 0,
  138052. 4,
  138053. };
  138054. static long _vq_lengthlist__44u9_p6_1[] = {
  138055. 4, 4, 4, 5, 5, 4, 5, 4, 5, 5, 4, 4, 5, 5, 5, 5,
  138056. 5, 5, 5, 5, 5, 5, 5, 5, 5,
  138057. };
  138058. static float _vq_quantthresh__44u9_p6_1[] = {
  138059. -1.5, -0.5, 0.5, 1.5,
  138060. };
  138061. static long _vq_quantmap__44u9_p6_1[] = {
  138062. 3, 1, 0, 2, 4,
  138063. };
  138064. static encode_aux_threshmatch _vq_auxt__44u9_p6_1 = {
  138065. _vq_quantthresh__44u9_p6_1,
  138066. _vq_quantmap__44u9_p6_1,
  138067. 5,
  138068. 5
  138069. };
  138070. static static_codebook _44u9_p6_1 = {
  138071. 2, 25,
  138072. _vq_lengthlist__44u9_p6_1,
  138073. 1, -533725184, 1611661312, 3, 0,
  138074. _vq_quantlist__44u9_p6_1,
  138075. NULL,
  138076. &_vq_auxt__44u9_p6_1,
  138077. NULL,
  138078. 0
  138079. };
  138080. static long _vq_quantlist__44u9_p7_0[] = {
  138081. 6,
  138082. 5,
  138083. 7,
  138084. 4,
  138085. 8,
  138086. 3,
  138087. 9,
  138088. 2,
  138089. 10,
  138090. 1,
  138091. 11,
  138092. 0,
  138093. 12,
  138094. };
  138095. static long _vq_lengthlist__44u9_p7_0[] = {
  138096. 1, 4, 5, 6, 6, 7, 7, 8, 9,10,10,11,11, 5, 6, 6,
  138097. 7, 7, 8, 8, 9, 9,10,10,11,11, 5, 6, 6, 7, 7, 8,
  138098. 8, 9, 9,10,10,11,11, 6, 7, 7, 8, 8, 9, 9,10,10,
  138099. 11,11,12,12, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,12,
  138100. 12, 8, 8, 8, 9, 9,10,10,11,11,12,12,13,13, 8, 8,
  138101. 8, 9, 9,10,10,11,11,12,12,13,13, 9, 9, 9,10,10,
  138102. 11,11,12,12,13,13,13,13, 9, 9, 9,10,10,11,11,12,
  138103. 12,13,13,14,14,10,10,10,11,11,12,12,13,13,14,13,
  138104. 15,14,10,10,10,11,11,12,12,13,13,14,14,14,14,11,
  138105. 11,12,12,12,13,13,14,14,14,14,15,15,11,11,12,12,
  138106. 12,13,13,14,14,14,15,15,15,
  138107. };
  138108. static float _vq_quantthresh__44u9_p7_0[] = {
  138109. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  138110. 27.5, 38.5, 49.5, 60.5,
  138111. };
  138112. static long _vq_quantmap__44u9_p7_0[] = {
  138113. 11, 9, 7, 5, 3, 1, 0, 2,
  138114. 4, 6, 8, 10, 12,
  138115. };
  138116. static encode_aux_threshmatch _vq_auxt__44u9_p7_0 = {
  138117. _vq_quantthresh__44u9_p7_0,
  138118. _vq_quantmap__44u9_p7_0,
  138119. 13,
  138120. 13
  138121. };
  138122. static static_codebook _44u9_p7_0 = {
  138123. 2, 169,
  138124. _vq_lengthlist__44u9_p7_0,
  138125. 1, -523206656, 1618345984, 4, 0,
  138126. _vq_quantlist__44u9_p7_0,
  138127. NULL,
  138128. &_vq_auxt__44u9_p7_0,
  138129. NULL,
  138130. 0
  138131. };
  138132. static long _vq_quantlist__44u9_p7_1[] = {
  138133. 5,
  138134. 4,
  138135. 6,
  138136. 3,
  138137. 7,
  138138. 2,
  138139. 8,
  138140. 1,
  138141. 9,
  138142. 0,
  138143. 10,
  138144. };
  138145. static long _vq_lengthlist__44u9_p7_1[] = {
  138146. 5, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 7, 7,
  138147. 7, 7, 7, 7, 7, 7, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7,
  138148. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 6, 7, 7, 7,
  138149. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  138150. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  138151. 7, 7, 7, 7, 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  138152. 7, 8, 8, 7, 7, 7, 7, 7, 7, 7, 8, 7, 8, 8, 7, 7,
  138153. 7, 7, 7, 7, 7, 8, 8, 8, 8,
  138154. };
  138155. static float _vq_quantthresh__44u9_p7_1[] = {
  138156. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  138157. 3.5, 4.5,
  138158. };
  138159. static long _vq_quantmap__44u9_p7_1[] = {
  138160. 9, 7, 5, 3, 1, 0, 2, 4,
  138161. 6, 8, 10,
  138162. };
  138163. static encode_aux_threshmatch _vq_auxt__44u9_p7_1 = {
  138164. _vq_quantthresh__44u9_p7_1,
  138165. _vq_quantmap__44u9_p7_1,
  138166. 11,
  138167. 11
  138168. };
  138169. static static_codebook _44u9_p7_1 = {
  138170. 2, 121,
  138171. _vq_lengthlist__44u9_p7_1,
  138172. 1, -531365888, 1611661312, 4, 0,
  138173. _vq_quantlist__44u9_p7_1,
  138174. NULL,
  138175. &_vq_auxt__44u9_p7_1,
  138176. NULL,
  138177. 0
  138178. };
  138179. static long _vq_quantlist__44u9_p8_0[] = {
  138180. 7,
  138181. 6,
  138182. 8,
  138183. 5,
  138184. 9,
  138185. 4,
  138186. 10,
  138187. 3,
  138188. 11,
  138189. 2,
  138190. 12,
  138191. 1,
  138192. 13,
  138193. 0,
  138194. 14,
  138195. };
  138196. static long _vq_lengthlist__44u9_p8_0[] = {
  138197. 1, 4, 4, 7, 7, 8, 8, 8, 8, 9, 9,10, 9,11,10, 4,
  138198. 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,10,12,10, 4, 6,
  138199. 6, 8, 8, 9,10, 9, 9,10,10,11,11,12,12, 7, 8, 8,
  138200. 10,10,11,11,10,10,11,11,12,12,13,12, 7, 8, 8,10,
  138201. 10,11,11,10,10,11,11,12,12,12,13, 8,10, 9,11,11,
  138202. 12,12,11,11,12,12,13,13,14,13, 8, 9, 9,11,11,12,
  138203. 12,11,12,12,12,13,13,14,13, 8, 9, 9,10,10,12,11,
  138204. 13,12,13,13,14,13,15,14, 8, 9, 9,10,10,11,12,12,
  138205. 12,13,13,13,14,14,14, 9,10,10,12,11,13,12,13,13,
  138206. 14,13,14,14,14,15, 9,10,10,11,12,12,12,13,13,14,
  138207. 14,14,15,15,15,10,11,11,12,12,13,13,14,14,14,14,
  138208. 15,14,16,15,10,11,11,12,12,13,13,13,14,14,14,14,
  138209. 14,15,16,11,12,12,13,13,14,13,14,14,15,14,15,16,
  138210. 16,16,11,12,12,13,13,14,13,14,14,15,15,15,16,15,
  138211. 15,
  138212. };
  138213. static float _vq_quantthresh__44u9_p8_0[] = {
  138214. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  138215. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  138216. };
  138217. static long _vq_quantmap__44u9_p8_0[] = {
  138218. 13, 11, 9, 7, 5, 3, 1, 0,
  138219. 2, 4, 6, 8, 10, 12, 14,
  138220. };
  138221. static encode_aux_threshmatch _vq_auxt__44u9_p8_0 = {
  138222. _vq_quantthresh__44u9_p8_0,
  138223. _vq_quantmap__44u9_p8_0,
  138224. 15,
  138225. 15
  138226. };
  138227. static static_codebook _44u9_p8_0 = {
  138228. 2, 225,
  138229. _vq_lengthlist__44u9_p8_0,
  138230. 1, -520986624, 1620377600, 4, 0,
  138231. _vq_quantlist__44u9_p8_0,
  138232. NULL,
  138233. &_vq_auxt__44u9_p8_0,
  138234. NULL,
  138235. 0
  138236. };
  138237. static long _vq_quantlist__44u9_p8_1[] = {
  138238. 10,
  138239. 9,
  138240. 11,
  138241. 8,
  138242. 12,
  138243. 7,
  138244. 13,
  138245. 6,
  138246. 14,
  138247. 5,
  138248. 15,
  138249. 4,
  138250. 16,
  138251. 3,
  138252. 17,
  138253. 2,
  138254. 18,
  138255. 1,
  138256. 19,
  138257. 0,
  138258. 20,
  138259. };
  138260. static long _vq_lengthlist__44u9_p8_1[] = {
  138261. 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  138262. 9, 9, 9, 9, 9, 6, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  138263. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 6, 6, 6, 7, 7, 8,
  138264. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 7,
  138265. 7, 7, 8, 8, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9,
  138266. 9, 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  138267. 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9,
  138268. 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10, 8, 8,
  138269. 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  138270. 9,10,10, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  138271. 10, 9,10, 9,10,10,10,10, 8, 8, 8, 9, 9, 9, 9, 9,
  138272. 9, 9, 9, 9, 9,10,10, 9,10,10,10,10,10, 9, 9, 9,
  138273. 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,10,10,
  138274. 10,10, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  138275. 10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  138276. 9, 9,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  138277. 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,
  138278. 10, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,10,10,
  138279. 10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9,10,10,
  138280. 10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,
  138281. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138282. 9, 9, 9, 9,10, 9, 9,10,10,10,10,10,10,10,10,10,
  138283. 10,10,10,10,10, 9, 9, 9,10, 9,10, 9,10,10,10,10,
  138284. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9,10, 9,10,
  138285. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  138286. 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  138287. 10,10,10,10, 9, 9, 9,10,10,10,10,10,10,10,10,10,
  138288. 10,10,10,10,10,10,10,10,10,
  138289. };
  138290. static float _vq_quantthresh__44u9_p8_1[] = {
  138291. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  138292. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  138293. 6.5, 7.5, 8.5, 9.5,
  138294. };
  138295. static long _vq_quantmap__44u9_p8_1[] = {
  138296. 19, 17, 15, 13, 11, 9, 7, 5,
  138297. 3, 1, 0, 2, 4, 6, 8, 10,
  138298. 12, 14, 16, 18, 20,
  138299. };
  138300. static encode_aux_threshmatch _vq_auxt__44u9_p8_1 = {
  138301. _vq_quantthresh__44u9_p8_1,
  138302. _vq_quantmap__44u9_p8_1,
  138303. 21,
  138304. 21
  138305. };
  138306. static static_codebook _44u9_p8_1 = {
  138307. 2, 441,
  138308. _vq_lengthlist__44u9_p8_1,
  138309. 1, -529268736, 1611661312, 5, 0,
  138310. _vq_quantlist__44u9_p8_1,
  138311. NULL,
  138312. &_vq_auxt__44u9_p8_1,
  138313. NULL,
  138314. 0
  138315. };
  138316. static long _vq_quantlist__44u9_p9_0[] = {
  138317. 7,
  138318. 6,
  138319. 8,
  138320. 5,
  138321. 9,
  138322. 4,
  138323. 10,
  138324. 3,
  138325. 11,
  138326. 2,
  138327. 12,
  138328. 1,
  138329. 13,
  138330. 0,
  138331. 14,
  138332. };
  138333. static long _vq_lengthlist__44u9_p9_0[] = {
  138334. 1, 3, 3,11,11,11,11,11,11,11,11,11,11,11,11, 4,
  138335. 10,11,11,11,11,11,11,11,11,11,11,11,11,11, 4,10,
  138336. 10,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138337. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138338. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138339. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138340. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138341. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138342. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138343. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138344. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138345. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138346. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138347. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138348. 10,
  138349. };
  138350. static float _vq_quantthresh__44u9_p9_0[] = {
  138351. -6051.5, -5120.5, -4189.5, -3258.5, -2327.5, -1396.5, -465.5, 465.5,
  138352. 1396.5, 2327.5, 3258.5, 4189.5, 5120.5, 6051.5,
  138353. };
  138354. static long _vq_quantmap__44u9_p9_0[] = {
  138355. 13, 11, 9, 7, 5, 3, 1, 0,
  138356. 2, 4, 6, 8, 10, 12, 14,
  138357. };
  138358. static encode_aux_threshmatch _vq_auxt__44u9_p9_0 = {
  138359. _vq_quantthresh__44u9_p9_0,
  138360. _vq_quantmap__44u9_p9_0,
  138361. 15,
  138362. 15
  138363. };
  138364. static static_codebook _44u9_p9_0 = {
  138365. 2, 225,
  138366. _vq_lengthlist__44u9_p9_0,
  138367. 1, -510036736, 1631393792, 4, 0,
  138368. _vq_quantlist__44u9_p9_0,
  138369. NULL,
  138370. &_vq_auxt__44u9_p9_0,
  138371. NULL,
  138372. 0
  138373. };
  138374. static long _vq_quantlist__44u9_p9_1[] = {
  138375. 9,
  138376. 8,
  138377. 10,
  138378. 7,
  138379. 11,
  138380. 6,
  138381. 12,
  138382. 5,
  138383. 13,
  138384. 4,
  138385. 14,
  138386. 3,
  138387. 15,
  138388. 2,
  138389. 16,
  138390. 1,
  138391. 17,
  138392. 0,
  138393. 18,
  138394. };
  138395. static long _vq_lengthlist__44u9_p9_1[] = {
  138396. 1, 4, 4, 7, 7, 8, 7, 8, 7, 9, 8,10, 9,10,10,11,
  138397. 11,12,12, 4, 7, 6, 9, 9,10, 9, 9, 8,10,10,11,10,
  138398. 12,10,13,12,13,12, 4, 6, 6, 9, 9, 9, 9, 9, 9,10,
  138399. 10,11,11,11,12,12,12,12,12, 7, 9, 8,11,10,10,10,
  138400. 11,10,11,11,12,12,13,12,13,13,13,13, 7, 8, 9,10,
  138401. 10,11,11,10,10,11,11,11,12,13,13,13,13,14,14, 8,
  138402. 9, 9,11,11,12,11,12,12,13,12,12,13,13,14,15,14,
  138403. 14,14, 8, 9, 9,10,11,11,11,12,12,13,12,13,13,14,
  138404. 14,14,15,14,16, 8, 9, 9,11,10,12,12,12,12,15,13,
  138405. 13,13,17,14,15,15,15,14, 8, 9, 9,10,11,11,12,13,
  138406. 12,13,13,13,14,15,14,14,14,16,15, 9,11,10,12,12,
  138407. 13,13,13,13,14,14,16,15,14,14,14,15,15,17, 9,10,
  138408. 10,11,11,13,13,13,14,14,13,15,14,15,14,15,16,15,
  138409. 16,10,11,11,12,12,13,14,15,14,15,14,14,15,17,16,
  138410. 15,15,17,17,10,12,11,13,12,14,14,13,14,15,15,15,
  138411. 15,16,17,17,15,17,16,11,12,12,14,13,15,14,15,16,
  138412. 17,15,17,15,17,15,15,16,17,15,11,11,12,14,14,14,
  138413. 14,14,15,15,16,15,17,17,17,16,17,16,15,12,12,13,
  138414. 14,14,14,15,14,15,15,16,16,17,16,17,15,17,17,16,
  138415. 12,14,12,14,14,15,15,15,14,14,16,16,16,15,16,16,
  138416. 15,17,15,12,13,13,14,15,14,15,17,15,17,16,17,17,
  138417. 17,16,17,16,17,17,12,13,13,14,16,15,15,15,16,15,
  138418. 17,17,15,17,15,17,16,16,17,
  138419. };
  138420. static float _vq_quantthresh__44u9_p9_1[] = {
  138421. -416.5, -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5,
  138422. -24.5, 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5,
  138423. 367.5, 416.5,
  138424. };
  138425. static long _vq_quantmap__44u9_p9_1[] = {
  138426. 17, 15, 13, 11, 9, 7, 5, 3,
  138427. 1, 0, 2, 4, 6, 8, 10, 12,
  138428. 14, 16, 18,
  138429. };
  138430. static encode_aux_threshmatch _vq_auxt__44u9_p9_1 = {
  138431. _vq_quantthresh__44u9_p9_1,
  138432. _vq_quantmap__44u9_p9_1,
  138433. 19,
  138434. 19
  138435. };
  138436. static static_codebook _44u9_p9_1 = {
  138437. 2, 361,
  138438. _vq_lengthlist__44u9_p9_1,
  138439. 1, -518287360, 1622704128, 5, 0,
  138440. _vq_quantlist__44u9_p9_1,
  138441. NULL,
  138442. &_vq_auxt__44u9_p9_1,
  138443. NULL,
  138444. 0
  138445. };
  138446. static long _vq_quantlist__44u9_p9_2[] = {
  138447. 24,
  138448. 23,
  138449. 25,
  138450. 22,
  138451. 26,
  138452. 21,
  138453. 27,
  138454. 20,
  138455. 28,
  138456. 19,
  138457. 29,
  138458. 18,
  138459. 30,
  138460. 17,
  138461. 31,
  138462. 16,
  138463. 32,
  138464. 15,
  138465. 33,
  138466. 14,
  138467. 34,
  138468. 13,
  138469. 35,
  138470. 12,
  138471. 36,
  138472. 11,
  138473. 37,
  138474. 10,
  138475. 38,
  138476. 9,
  138477. 39,
  138478. 8,
  138479. 40,
  138480. 7,
  138481. 41,
  138482. 6,
  138483. 42,
  138484. 5,
  138485. 43,
  138486. 4,
  138487. 44,
  138488. 3,
  138489. 45,
  138490. 2,
  138491. 46,
  138492. 1,
  138493. 47,
  138494. 0,
  138495. 48,
  138496. };
  138497. static long _vq_lengthlist__44u9_p9_2[] = {
  138498. 2, 4, 4, 5, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6,
  138499. 6, 6, 6, 7, 6, 7, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  138500. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  138501. 7,
  138502. };
  138503. static float _vq_quantthresh__44u9_p9_2[] = {
  138504. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  138505. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  138506. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  138507. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  138508. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  138509. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  138510. };
  138511. static long _vq_quantmap__44u9_p9_2[] = {
  138512. 47, 45, 43, 41, 39, 37, 35, 33,
  138513. 31, 29, 27, 25, 23, 21, 19, 17,
  138514. 15, 13, 11, 9, 7, 5, 3, 1,
  138515. 0, 2, 4, 6, 8, 10, 12, 14,
  138516. 16, 18, 20, 22, 24, 26, 28, 30,
  138517. 32, 34, 36, 38, 40, 42, 44, 46,
  138518. 48,
  138519. };
  138520. static encode_aux_threshmatch _vq_auxt__44u9_p9_2 = {
  138521. _vq_quantthresh__44u9_p9_2,
  138522. _vq_quantmap__44u9_p9_2,
  138523. 49,
  138524. 49
  138525. };
  138526. static static_codebook _44u9_p9_2 = {
  138527. 1, 49,
  138528. _vq_lengthlist__44u9_p9_2,
  138529. 1, -526909440, 1611661312, 6, 0,
  138530. _vq_quantlist__44u9_p9_2,
  138531. NULL,
  138532. &_vq_auxt__44u9_p9_2,
  138533. NULL,
  138534. 0
  138535. };
  138536. static long _huff_lengthlist__44un1__long[] = {
  138537. 5, 6,12, 9,14, 9, 9,19, 6, 1, 5, 5, 8, 7, 9,19,
  138538. 12, 4, 4, 7, 7, 9,11,18, 9, 5, 6, 6, 8, 7, 8,17,
  138539. 14, 8, 7, 8, 8,10,12,18, 9, 6, 8, 6, 8, 6, 8,18,
  138540. 9, 8,11, 8,11, 7, 5,15,16,18,18,18,17,15,11,18,
  138541. };
  138542. static static_codebook _huff_book__44un1__long = {
  138543. 2, 64,
  138544. _huff_lengthlist__44un1__long,
  138545. 0, 0, 0, 0, 0,
  138546. NULL,
  138547. NULL,
  138548. NULL,
  138549. NULL,
  138550. 0
  138551. };
  138552. static long _vq_quantlist__44un1__p1_0[] = {
  138553. 1,
  138554. 0,
  138555. 2,
  138556. };
  138557. static long _vq_lengthlist__44un1__p1_0[] = {
  138558. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,10,11, 8,
  138559. 10,11, 5, 8, 8, 8,11,10, 8,11,10, 4, 9, 9, 8,11,
  138560. 11, 8,11,11, 8,12,11,10,12,14,11,13,13, 7,11,11,
  138561. 10,13,11,11,13,14, 4, 8, 9, 8,11,11, 8,11,12, 7,
  138562. 11,11,11,14,13,10,11,13, 8,11,12,11,13,13,10,14,
  138563. 12,
  138564. };
  138565. static float _vq_quantthresh__44un1__p1_0[] = {
  138566. -0.5, 0.5,
  138567. };
  138568. static long _vq_quantmap__44un1__p1_0[] = {
  138569. 1, 0, 2,
  138570. };
  138571. static encode_aux_threshmatch _vq_auxt__44un1__p1_0 = {
  138572. _vq_quantthresh__44un1__p1_0,
  138573. _vq_quantmap__44un1__p1_0,
  138574. 3,
  138575. 3
  138576. };
  138577. static static_codebook _44un1__p1_0 = {
  138578. 4, 81,
  138579. _vq_lengthlist__44un1__p1_0,
  138580. 1, -535822336, 1611661312, 2, 0,
  138581. _vq_quantlist__44un1__p1_0,
  138582. NULL,
  138583. &_vq_auxt__44un1__p1_0,
  138584. NULL,
  138585. 0
  138586. };
  138587. static long _vq_quantlist__44un1__p2_0[] = {
  138588. 1,
  138589. 0,
  138590. 2,
  138591. };
  138592. static long _vq_lengthlist__44un1__p2_0[] = {
  138593. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 7, 8, 8, 6,
  138594. 7, 9, 5, 7, 7, 6, 8, 7, 7, 9, 8, 4, 7, 7, 7, 9,
  138595. 8, 7, 8, 8, 7, 9, 8, 8, 8,10, 9,10,10, 6, 8, 8,
  138596. 7,10, 8, 9,10,10, 5, 7, 7, 7, 8, 8, 7, 8, 9, 6,
  138597. 8, 8, 9,10,10, 7, 8,10, 6, 8, 9, 9,10,10, 8,10,
  138598. 8,
  138599. };
  138600. static float _vq_quantthresh__44un1__p2_0[] = {
  138601. -0.5, 0.5,
  138602. };
  138603. static long _vq_quantmap__44un1__p2_0[] = {
  138604. 1, 0, 2,
  138605. };
  138606. static encode_aux_threshmatch _vq_auxt__44un1__p2_0 = {
  138607. _vq_quantthresh__44un1__p2_0,
  138608. _vq_quantmap__44un1__p2_0,
  138609. 3,
  138610. 3
  138611. };
  138612. static static_codebook _44un1__p2_0 = {
  138613. 4, 81,
  138614. _vq_lengthlist__44un1__p2_0,
  138615. 1, -535822336, 1611661312, 2, 0,
  138616. _vq_quantlist__44un1__p2_0,
  138617. NULL,
  138618. &_vq_auxt__44un1__p2_0,
  138619. NULL,
  138620. 0
  138621. };
  138622. static long _vq_quantlist__44un1__p3_0[] = {
  138623. 2,
  138624. 1,
  138625. 3,
  138626. 0,
  138627. 4,
  138628. };
  138629. static long _vq_lengthlist__44un1__p3_0[] = {
  138630. 1, 5, 5, 8, 8, 5, 8, 7, 9, 9, 5, 7, 8, 9, 9, 9,
  138631. 10, 9,12,12, 9, 9,10,11,12, 6, 8, 8,10,10, 8,10,
  138632. 10,11,11, 8, 9,10,11,11,10,11,11,13,13,10,11,11,
  138633. 12,13, 6, 8, 8,10,10, 8,10, 9,11,11, 8,10,10,11,
  138634. 11,10,11,11,13,12,10,11,11,13,12, 9,11,11,15,13,
  138635. 10,12,11,15,13,10,11,11,15,14,12,14,13,16,15,12,
  138636. 13,13,17,16, 9,11,11,13,15,10,11,12,14,15,10,11,
  138637. 12,14,15,12,13,13,15,16,12,13,13,16,16, 5, 8, 8,
  138638. 11,11, 8,10,10,12,12, 8,10,10,12,12,11,12,12,14,
  138639. 14,11,12,12,14,14, 8,11,10,13,12,10,11,12,12,13,
  138640. 10,12,12,13,13,12,12,13,13,15,11,12,13,15,14, 7,
  138641. 10,10,12,12, 9,12,11,13,12,10,12,12,13,14,12,13,
  138642. 12,15,13,11,13,12,14,15,10,12,12,16,14,11,12,12,
  138643. 16,15,11,13,12,17,16,13,13,15,15,17,13,15,15,20,
  138644. 17,10,12,12,14,16,11,12,12,15,15,11,13,13,15,18,
  138645. 13,14,13,15,15,13,15,14,16,16, 5, 8, 8,11,11, 8,
  138646. 10,10,12,12, 8,10,10,12,12,11,12,12,14,14,11,12,
  138647. 12,14,15, 7,10,10,13,12,10,12,12,14,13, 9,10,12,
  138648. 12,13,11,13,13,15,15,11,12,13,13,15, 8,10,10,12,
  138649. 13,10,12,12,13,13,10,12,11,13,13,11,13,12,15,15,
  138650. 12,13,12,15,13,10,12,12,16,14,11,12,12,16,15,10,
  138651. 12,12,16,14,14,15,14,18,16,13,13,14,15,16,10,12,
  138652. 12,14,16,11,13,13,16,16,11,13,12,14,16,13,15,15,
  138653. 18,18,13,15,13,16,14, 8,11,11,16,16,10,13,13,17,
  138654. 16,10,12,12,16,15,14,16,15,20,17,13,14,14,17,17,
  138655. 9,12,12,16,16,11,13,14,16,17,11,13,13,16,16,15,
  138656. 15,19,18, 0,14,15,15,18,18, 9,12,12,17,16,11,13,
  138657. 12,17,16,11,12,13,15,17,15,16,15, 0,19,14,15,14,
  138658. 19,18,12,14,14, 0,16,13,14,14,19,18,13,15,16,17,
  138659. 16,15,15,17,18, 0,14,16,16,19, 0,12,14,14,16,18,
  138660. 13,15,13,17,18,13,15,14,17,18,15,18,14,18,18,16,
  138661. 17,16, 0,17, 8,11,11,15,15,10,12,12,16,16,10,13,
  138662. 13,16,16,13,15,14,17,17,14,15,17,17,18, 9,12,12,
  138663. 16,15,11,13,13,16,16,11,12,13,17,17,14,14,15,17,
  138664. 17,14,15,16, 0,18, 9,12,12,16,17,11,13,13,16,17,
  138665. 11,14,13,18,17,14,16,14,17,17,15,17,17,18,18,12,
  138666. 14,14, 0,16,13,15,15,19, 0,12,13,15, 0, 0,14,17,
  138667. 16,19, 0,16,15,18,18, 0,12,14,14,17, 0,13,14,14,
  138668. 17, 0,13,15,14, 0,18,15,16,16, 0,18,15,18,15, 0,
  138669. 17,
  138670. };
  138671. static float _vq_quantthresh__44un1__p3_0[] = {
  138672. -1.5, -0.5, 0.5, 1.5,
  138673. };
  138674. static long _vq_quantmap__44un1__p3_0[] = {
  138675. 3, 1, 0, 2, 4,
  138676. };
  138677. static encode_aux_threshmatch _vq_auxt__44un1__p3_0 = {
  138678. _vq_quantthresh__44un1__p3_0,
  138679. _vq_quantmap__44un1__p3_0,
  138680. 5,
  138681. 5
  138682. };
  138683. static static_codebook _44un1__p3_0 = {
  138684. 4, 625,
  138685. _vq_lengthlist__44un1__p3_0,
  138686. 1, -533725184, 1611661312, 3, 0,
  138687. _vq_quantlist__44un1__p3_0,
  138688. NULL,
  138689. &_vq_auxt__44un1__p3_0,
  138690. NULL,
  138691. 0
  138692. };
  138693. static long _vq_quantlist__44un1__p4_0[] = {
  138694. 2,
  138695. 1,
  138696. 3,
  138697. 0,
  138698. 4,
  138699. };
  138700. static long _vq_lengthlist__44un1__p4_0[] = {
  138701. 3, 5, 5, 9, 9, 5, 6, 6,10, 9, 5, 6, 6, 9,10,10,
  138702. 10,10,12,11, 9,10,10,12,12, 5, 7, 7,10,10, 7, 7,
  138703. 8,10,11, 7, 7, 8,10,11,10,10,11,11,13,10,10,11,
  138704. 11,13, 6, 7, 7,10,10, 7, 8, 7,11,10, 7, 8, 7,10,
  138705. 10,10,11, 9,13,11,10,11,10,13,11,10,10,10,14,13,
  138706. 10,11,11,14,13,10,10,11,13,14,12,12,13,15,15,12,
  138707. 12,13,13,14,10,10,10,12,13,10,11,10,13,13,10,11,
  138708. 11,13,13,12,13,12,14,13,12,13,13,14,13, 5, 7, 7,
  138709. 10,10, 7, 8, 8,11,10, 7, 8, 8,10,10,11,11,11,13,
  138710. 13,10,11,11,12,12, 7, 8, 8,11,11, 7, 8, 9,10,12,
  138711. 8, 9, 9,11,11,11,10,12,11,14,11,11,12,13,13, 6,
  138712. 8, 8,10,11, 7, 9, 7,12,10, 8, 9,10,11,12,10,12,
  138713. 10,14,11,11,12,11,13,13,10,11,11,14,14,10,10,11,
  138714. 13,14,11,12,12,15,13,12,11,14,12,16,12,13,14,15,
  138715. 16,10,10,11,13,14,10,11,10,14,12,11,12,12,13,14,
  138716. 12,13,11,15,12,14,14,14,15,15, 5, 7, 7,10,10, 7,
  138717. 8, 8,10,10, 7, 8, 8,10,11,10,11,10,12,12,10,11,
  138718. 11,12,13, 6, 8, 8,11,11, 8, 9, 9,12,11, 7, 7, 9,
  138719. 10,12,11,11,11,12,13,11,10,12,11,15, 7, 8, 8,11,
  138720. 11, 8, 9, 9,11,11, 7, 9, 8,12,10,11,12,11,13,12,
  138721. 11,12,10,15,11,10,11,10,14,12,11,12,11,14,13,10,
  138722. 10,11,13,14,13,13,13,17,15,12,11,14,12,15,10,10,
  138723. 11,13,14,11,12,12,14,14,10,11,10,14,13,13,14,13,
  138724. 16,17,12,14,11,16,12, 9,10,10,14,13,10,11,10,14,
  138725. 14,10,11,11,13,13,13,14,14,16,15,12,13,13,14,14,
  138726. 9,11,10,14,13,10,10,12,13,14,11,12,11,14,13,13,
  138727. 14,14,14,15,13,14,14,15,15, 9,10,11,13,14,10,11,
  138728. 10,15,13,11,11,12,12,15,13,14,12,15,14,13,13,14,
  138729. 14,15,12,13,12,16,14,11,11,12,15,14,13,15,13,16,
  138730. 14,13,12,15,12,17,15,16,15,16,16,12,12,13,13,15,
  138731. 11,13,11,15,14,13,13,14,15,17,13,14,12, 0,13,14,
  138732. 15,14,15, 0, 9,10,10,13,13,10,11,11,13,13,10,11,
  138733. 11,13,13,12,13,12,14,14,13,14,14,15,17, 9,10,10,
  138734. 13,13,11,12,11,15,12,10,10,11,13,16,13,14,13,15,
  138735. 14,13,13,14,15,16,10,10,11,13,14,11,11,12,13,14,
  138736. 10,12,11,14,14,13,13,13,14,15,13,15,13,16,15,12,
  138737. 13,12,15,13,12,15,13,15,15,11,11,13,14,15,15,15,
  138738. 15,15,17,13,12,14,13,17,12,12,14,14,15,13,13,14,
  138739. 14,16,11,13,11,16,15,14,16,16,17, 0,14,13,11,16,
  138740. 12,
  138741. };
  138742. static float _vq_quantthresh__44un1__p4_0[] = {
  138743. -1.5, -0.5, 0.5, 1.5,
  138744. };
  138745. static long _vq_quantmap__44un1__p4_0[] = {
  138746. 3, 1, 0, 2, 4,
  138747. };
  138748. static encode_aux_threshmatch _vq_auxt__44un1__p4_0 = {
  138749. _vq_quantthresh__44un1__p4_0,
  138750. _vq_quantmap__44un1__p4_0,
  138751. 5,
  138752. 5
  138753. };
  138754. static static_codebook _44un1__p4_0 = {
  138755. 4, 625,
  138756. _vq_lengthlist__44un1__p4_0,
  138757. 1, -533725184, 1611661312, 3, 0,
  138758. _vq_quantlist__44un1__p4_0,
  138759. NULL,
  138760. &_vq_auxt__44un1__p4_0,
  138761. NULL,
  138762. 0
  138763. };
  138764. static long _vq_quantlist__44un1__p5_0[] = {
  138765. 4,
  138766. 3,
  138767. 5,
  138768. 2,
  138769. 6,
  138770. 1,
  138771. 7,
  138772. 0,
  138773. 8,
  138774. };
  138775. static long _vq_lengthlist__44un1__p5_0[] = {
  138776. 1, 4, 4, 7, 7, 8, 8, 9, 9, 4, 6, 5, 8, 7, 8, 8,
  138777. 10, 9, 4, 6, 6, 8, 8, 8, 8,10,10, 7, 8, 7, 9, 9,
  138778. 9, 9,11,10, 7, 8, 8, 9, 9, 9, 9,10,11, 8, 8, 8,
  138779. 9, 9,10,10,11,11, 8, 8, 8, 9, 9,10,10,11,11, 9,
  138780. 10,10,11,10,11,11,12,12, 9,10,10,10,11,11,11,12,
  138781. 12,
  138782. };
  138783. static float _vq_quantthresh__44un1__p5_0[] = {
  138784. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  138785. };
  138786. static long _vq_quantmap__44un1__p5_0[] = {
  138787. 7, 5, 3, 1, 0, 2, 4, 6,
  138788. 8,
  138789. };
  138790. static encode_aux_threshmatch _vq_auxt__44un1__p5_0 = {
  138791. _vq_quantthresh__44un1__p5_0,
  138792. _vq_quantmap__44un1__p5_0,
  138793. 9,
  138794. 9
  138795. };
  138796. static static_codebook _44un1__p5_0 = {
  138797. 2, 81,
  138798. _vq_lengthlist__44un1__p5_0,
  138799. 1, -531628032, 1611661312, 4, 0,
  138800. _vq_quantlist__44un1__p5_0,
  138801. NULL,
  138802. &_vq_auxt__44un1__p5_0,
  138803. NULL,
  138804. 0
  138805. };
  138806. static long _vq_quantlist__44un1__p6_0[] = {
  138807. 6,
  138808. 5,
  138809. 7,
  138810. 4,
  138811. 8,
  138812. 3,
  138813. 9,
  138814. 2,
  138815. 10,
  138816. 1,
  138817. 11,
  138818. 0,
  138819. 12,
  138820. };
  138821. static long _vq_lengthlist__44un1__p6_0[] = {
  138822. 1, 4, 4, 6, 6, 8, 8,10,10,11,11,15,15, 4, 5, 5,
  138823. 8, 8, 9, 9,11,11,12,12,16,16, 4, 5, 6, 8, 8, 9,
  138824. 9,11,11,12,12,14,14, 7, 8, 8, 9, 9,10,10,11,12,
  138825. 13,13,16,17, 7, 8, 8, 9, 9,10,10,12,12,12,13,15,
  138826. 15, 9,10,10,10,10,11,11,12,12,13,13,15,16, 9, 9,
  138827. 9,10,10,11,11,13,12,13,13,17,17,10,11,11,11,12,
  138828. 12,12,13,13,14,15, 0,18,10,11,11,12,12,12,13,14,
  138829. 13,14,14,17,16,11,12,12,13,13,14,14,14,14,15,16,
  138830. 17,16,11,12,12,13,13,14,14,14,14,15,15,17,17,14,
  138831. 15,15,16,16,16,17,17,16, 0,17, 0,18,14,15,15,16,
  138832. 16, 0,15,18,18, 0,16, 0, 0,
  138833. };
  138834. static float _vq_quantthresh__44un1__p6_0[] = {
  138835. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  138836. 12.5, 17.5, 22.5, 27.5,
  138837. };
  138838. static long _vq_quantmap__44un1__p6_0[] = {
  138839. 11, 9, 7, 5, 3, 1, 0, 2,
  138840. 4, 6, 8, 10, 12,
  138841. };
  138842. static encode_aux_threshmatch _vq_auxt__44un1__p6_0 = {
  138843. _vq_quantthresh__44un1__p6_0,
  138844. _vq_quantmap__44un1__p6_0,
  138845. 13,
  138846. 13
  138847. };
  138848. static static_codebook _44un1__p6_0 = {
  138849. 2, 169,
  138850. _vq_lengthlist__44un1__p6_0,
  138851. 1, -526516224, 1616117760, 4, 0,
  138852. _vq_quantlist__44un1__p6_0,
  138853. NULL,
  138854. &_vq_auxt__44un1__p6_0,
  138855. NULL,
  138856. 0
  138857. };
  138858. static long _vq_quantlist__44un1__p6_1[] = {
  138859. 2,
  138860. 1,
  138861. 3,
  138862. 0,
  138863. 4,
  138864. };
  138865. static long _vq_lengthlist__44un1__p6_1[] = {
  138866. 2, 4, 4, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 6, 5, 5,
  138867. 6, 5, 6, 6, 5, 6, 6, 6, 6,
  138868. };
  138869. static float _vq_quantthresh__44un1__p6_1[] = {
  138870. -1.5, -0.5, 0.5, 1.5,
  138871. };
  138872. static long _vq_quantmap__44un1__p6_1[] = {
  138873. 3, 1, 0, 2, 4,
  138874. };
  138875. static encode_aux_threshmatch _vq_auxt__44un1__p6_1 = {
  138876. _vq_quantthresh__44un1__p6_1,
  138877. _vq_quantmap__44un1__p6_1,
  138878. 5,
  138879. 5
  138880. };
  138881. static static_codebook _44un1__p6_1 = {
  138882. 2, 25,
  138883. _vq_lengthlist__44un1__p6_1,
  138884. 1, -533725184, 1611661312, 3, 0,
  138885. _vq_quantlist__44un1__p6_1,
  138886. NULL,
  138887. &_vq_auxt__44un1__p6_1,
  138888. NULL,
  138889. 0
  138890. };
  138891. static long _vq_quantlist__44un1__p7_0[] = {
  138892. 2,
  138893. 1,
  138894. 3,
  138895. 0,
  138896. 4,
  138897. };
  138898. static long _vq_lengthlist__44un1__p7_0[] = {
  138899. 1, 5, 3,11,11,11,11,11,11,11, 8,11,11,11,11,11,
  138900. 11,11,11,11,11,11,11,11,11,10,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,10,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. 11,11,11,11,11,11,11,11,11,11,11,11,11, 8,11,11,
  138907. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138908. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138909. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,
  138910. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138911. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138912. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138913. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138914. 11,11,11,11,11,11,11,11,11,11, 7,11,11,11,11,11,
  138915. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138916. 11,11,11,10,11,11,11,11,11,11,11,11,11,11,11,11,
  138917. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138918. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138919. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138920. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138921. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138922. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138923. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138924. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138925. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138926. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138927. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138928. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138929. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138930. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138931. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138932. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138933. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138934. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138935. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138936. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138937. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138938. 10,
  138939. };
  138940. static float _vq_quantthresh__44un1__p7_0[] = {
  138941. -253.5, -84.5, 84.5, 253.5,
  138942. };
  138943. static long _vq_quantmap__44un1__p7_0[] = {
  138944. 3, 1, 0, 2, 4,
  138945. };
  138946. static encode_aux_threshmatch _vq_auxt__44un1__p7_0 = {
  138947. _vq_quantthresh__44un1__p7_0,
  138948. _vq_quantmap__44un1__p7_0,
  138949. 5,
  138950. 5
  138951. };
  138952. static static_codebook _44un1__p7_0 = {
  138953. 4, 625,
  138954. _vq_lengthlist__44un1__p7_0,
  138955. 1, -518709248, 1626677248, 3, 0,
  138956. _vq_quantlist__44un1__p7_0,
  138957. NULL,
  138958. &_vq_auxt__44un1__p7_0,
  138959. NULL,
  138960. 0
  138961. };
  138962. static long _vq_quantlist__44un1__p7_1[] = {
  138963. 6,
  138964. 5,
  138965. 7,
  138966. 4,
  138967. 8,
  138968. 3,
  138969. 9,
  138970. 2,
  138971. 10,
  138972. 1,
  138973. 11,
  138974. 0,
  138975. 12,
  138976. };
  138977. static long _vq_lengthlist__44un1__p7_1[] = {
  138978. 1, 4, 4, 6, 6, 6, 6, 9, 8, 9, 8, 8, 8, 5, 7, 7,
  138979. 7, 7, 8, 8, 8,10, 8,10, 8, 9, 5, 7, 7, 8, 7, 7,
  138980. 8,10,10,11,10,12,11, 7, 8, 8, 9, 9, 9,10,11,11,
  138981. 11,11,11,11, 7, 8, 8, 8, 9, 9, 9,10,10,10,11,11,
  138982. 12, 7, 8, 8, 9, 9,10,11,11,12,11,12,11,11, 7, 8,
  138983. 8, 9, 9,10,10,11,11,11,12,12,11, 8,10,10,10,10,
  138984. 11,11,14,11,12,12,12,13, 9,10,10,10,10,12,11,14,
  138985. 11,14,11,12,13,10,11,11,11,11,13,11,14,14,13,13,
  138986. 13,14,11,11,11,12,11,12,12,12,13,14,14,13,14,12,
  138987. 11,12,12,12,12,13,13,13,14,13,14,14,11,12,12,14,
  138988. 12,13,13,12,13,13,14,14,14,
  138989. };
  138990. static float _vq_quantthresh__44un1__p7_1[] = {
  138991. -71.5, -58.5, -45.5, -32.5, -19.5, -6.5, 6.5, 19.5,
  138992. 32.5, 45.5, 58.5, 71.5,
  138993. };
  138994. static long _vq_quantmap__44un1__p7_1[] = {
  138995. 11, 9, 7, 5, 3, 1, 0, 2,
  138996. 4, 6, 8, 10, 12,
  138997. };
  138998. static encode_aux_threshmatch _vq_auxt__44un1__p7_1 = {
  138999. _vq_quantthresh__44un1__p7_1,
  139000. _vq_quantmap__44un1__p7_1,
  139001. 13,
  139002. 13
  139003. };
  139004. static static_codebook _44un1__p7_1 = {
  139005. 2, 169,
  139006. _vq_lengthlist__44un1__p7_1,
  139007. 1, -523010048, 1618608128, 4, 0,
  139008. _vq_quantlist__44un1__p7_1,
  139009. NULL,
  139010. &_vq_auxt__44un1__p7_1,
  139011. NULL,
  139012. 0
  139013. };
  139014. static long _vq_quantlist__44un1__p7_2[] = {
  139015. 6,
  139016. 5,
  139017. 7,
  139018. 4,
  139019. 8,
  139020. 3,
  139021. 9,
  139022. 2,
  139023. 10,
  139024. 1,
  139025. 11,
  139026. 0,
  139027. 12,
  139028. };
  139029. static long _vq_lengthlist__44un1__p7_2[] = {
  139030. 3, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9, 9, 8, 4, 5, 5,
  139031. 6, 6, 8, 8, 9, 8, 9, 9, 9, 9, 4, 5, 5, 7, 6, 8,
  139032. 8, 8, 8, 9, 8, 9, 8, 6, 7, 7, 7, 8, 8, 8, 9, 9,
  139033. 9, 9, 9, 9, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  139034. 9, 7, 8, 8, 8, 8, 9, 8, 9, 9,10, 9, 9,10, 7, 8,
  139035. 8, 8, 8, 9, 9, 9, 9, 9, 9,10,10, 8, 9, 9, 9, 9,
  139036. 9, 9, 9, 9,10,10, 9,10, 8, 9, 9, 9, 9, 9, 9, 9,
  139037. 9, 9, 9,10,10, 9, 9, 9,10, 9, 9,10, 9, 9,10,10,
  139038. 10,10, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10, 9,
  139039. 9, 9,10, 9, 9,10,10, 9,10,10,10,10, 9, 9, 9,10,
  139040. 9, 9, 9,10,10,10,10,10,10,
  139041. };
  139042. static float _vq_quantthresh__44un1__p7_2[] = {
  139043. -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
  139044. 2.5, 3.5, 4.5, 5.5,
  139045. };
  139046. static long _vq_quantmap__44un1__p7_2[] = {
  139047. 11, 9, 7, 5, 3, 1, 0, 2,
  139048. 4, 6, 8, 10, 12,
  139049. };
  139050. static encode_aux_threshmatch _vq_auxt__44un1__p7_2 = {
  139051. _vq_quantthresh__44un1__p7_2,
  139052. _vq_quantmap__44un1__p7_2,
  139053. 13,
  139054. 13
  139055. };
  139056. static static_codebook _44un1__p7_2 = {
  139057. 2, 169,
  139058. _vq_lengthlist__44un1__p7_2,
  139059. 1, -531103744, 1611661312, 4, 0,
  139060. _vq_quantlist__44un1__p7_2,
  139061. NULL,
  139062. &_vq_auxt__44un1__p7_2,
  139063. NULL,
  139064. 0
  139065. };
  139066. static long _huff_lengthlist__44un1__short[] = {
  139067. 12,12,14,12,14,14,14,14,12, 6, 6, 8, 9, 9,11,14,
  139068. 12, 4, 2, 6, 6, 7,11,14,13, 6, 5, 7, 8, 9,11,14,
  139069. 13, 8, 5, 8, 6, 8,12,14,12, 7, 7, 8, 8, 8,10,14,
  139070. 12, 6, 3, 4, 4, 4, 7,14,11, 7, 4, 6, 6, 6, 8,14,
  139071. };
  139072. static static_codebook _huff_book__44un1__short = {
  139073. 2, 64,
  139074. _huff_lengthlist__44un1__short,
  139075. 0, 0, 0, 0, 0,
  139076. NULL,
  139077. NULL,
  139078. NULL,
  139079. NULL,
  139080. 0
  139081. };
  139082. /*** End of inlined file: res_books_uncoupled.h ***/
  139083. static vorbis_info_residue0 _residue_44_low_un={
  139084. 0,-1, -1, 8,-1,
  139085. {0},
  139086. {-1},
  139087. { .5, 1.5, 1.5, 2.5, 2.5, 4.5, 28.5},
  139088. { -1, 25, -1, 45, -1, -1, -1}
  139089. };
  139090. static vorbis_info_residue0 _residue_44_mid_un={
  139091. 0,-1, -1, 10,-1,
  139092. {0},
  139093. {-1},
  139094. { .5, 1.5, 1.5, 2.5, 2.5, 4.5, 4.5, 16.5, 60.5},
  139095. { -1, 30, -1, 50, -1, 80, -1, -1, -1}
  139096. };
  139097. static vorbis_info_residue0 _residue_44_hi_un={
  139098. 0,-1, -1, 10,-1,
  139099. {0},
  139100. {-1},
  139101. { .5, 1.5, 2.5, 4.5, 8.5, 16.5, 32.5, 71.5,157.5},
  139102. { -1, -1, -1, -1, -1, -1, -1, -1, -1}
  139103. };
  139104. static vorbis_info_mapping0 _map_nominal_u[2]={
  139105. {1, {0,0}, {0}, {0}, 0,{0},{0}},
  139106. {1, {0,0}, {1}, {1}, 0,{0},{0}}
  139107. };
  139108. static static_bookblock _resbook_44u_n1={
  139109. {
  139110. {0},
  139111. {0,0,&_44un1__p1_0},
  139112. {0,0,&_44un1__p2_0},
  139113. {0,0,&_44un1__p3_0},
  139114. {0,0,&_44un1__p4_0},
  139115. {0,0,&_44un1__p5_0},
  139116. {&_44un1__p6_0,&_44un1__p6_1},
  139117. {&_44un1__p7_0,&_44un1__p7_1,&_44un1__p7_2}
  139118. }
  139119. };
  139120. static static_bookblock _resbook_44u_0={
  139121. {
  139122. {0},
  139123. {0,0,&_44u0__p1_0},
  139124. {0,0,&_44u0__p2_0},
  139125. {0,0,&_44u0__p3_0},
  139126. {0,0,&_44u0__p4_0},
  139127. {0,0,&_44u0__p5_0},
  139128. {&_44u0__p6_0,&_44u0__p6_1},
  139129. {&_44u0__p7_0,&_44u0__p7_1,&_44u0__p7_2}
  139130. }
  139131. };
  139132. static static_bookblock _resbook_44u_1={
  139133. {
  139134. {0},
  139135. {0,0,&_44u1__p1_0},
  139136. {0,0,&_44u1__p2_0},
  139137. {0,0,&_44u1__p3_0},
  139138. {0,0,&_44u1__p4_0},
  139139. {0,0,&_44u1__p5_0},
  139140. {&_44u1__p6_0,&_44u1__p6_1},
  139141. {&_44u1__p7_0,&_44u1__p7_1,&_44u1__p7_2}
  139142. }
  139143. };
  139144. static static_bookblock _resbook_44u_2={
  139145. {
  139146. {0},
  139147. {0,0,&_44u2__p1_0},
  139148. {0,0,&_44u2__p2_0},
  139149. {0,0,&_44u2__p3_0},
  139150. {0,0,&_44u2__p4_0},
  139151. {0,0,&_44u2__p5_0},
  139152. {&_44u2__p6_0,&_44u2__p6_1},
  139153. {&_44u2__p7_0,&_44u2__p7_1,&_44u2__p7_2}
  139154. }
  139155. };
  139156. static static_bookblock _resbook_44u_3={
  139157. {
  139158. {0},
  139159. {0,0,&_44u3__p1_0},
  139160. {0,0,&_44u3__p2_0},
  139161. {0,0,&_44u3__p3_0},
  139162. {0,0,&_44u3__p4_0},
  139163. {0,0,&_44u3__p5_0},
  139164. {&_44u3__p6_0,&_44u3__p6_1},
  139165. {&_44u3__p7_0,&_44u3__p7_1,&_44u3__p7_2}
  139166. }
  139167. };
  139168. static static_bookblock _resbook_44u_4={
  139169. {
  139170. {0},
  139171. {0,0,&_44u4__p1_0},
  139172. {0,0,&_44u4__p2_0},
  139173. {0,0,&_44u4__p3_0},
  139174. {0,0,&_44u4__p4_0},
  139175. {0,0,&_44u4__p5_0},
  139176. {&_44u4__p6_0,&_44u4__p6_1},
  139177. {&_44u4__p7_0,&_44u4__p7_1,&_44u4__p7_2}
  139178. }
  139179. };
  139180. static static_bookblock _resbook_44u_5={
  139181. {
  139182. {0},
  139183. {0,0,&_44u5__p1_0},
  139184. {0,0,&_44u5__p2_0},
  139185. {0,0,&_44u5__p3_0},
  139186. {0,0,&_44u5__p4_0},
  139187. {0,0,&_44u5__p5_0},
  139188. {0,0,&_44u5__p6_0},
  139189. {&_44u5__p7_0,&_44u5__p7_1},
  139190. {&_44u5__p8_0,&_44u5__p8_1},
  139191. {&_44u5__p9_0,&_44u5__p9_1,&_44u5__p9_2}
  139192. }
  139193. };
  139194. static static_bookblock _resbook_44u_6={
  139195. {
  139196. {0},
  139197. {0,0,&_44u6__p1_0},
  139198. {0,0,&_44u6__p2_0},
  139199. {0,0,&_44u6__p3_0},
  139200. {0,0,&_44u6__p4_0},
  139201. {0,0,&_44u6__p5_0},
  139202. {0,0,&_44u6__p6_0},
  139203. {&_44u6__p7_0,&_44u6__p7_1},
  139204. {&_44u6__p8_0,&_44u6__p8_1},
  139205. {&_44u6__p9_0,&_44u6__p9_1,&_44u6__p9_2}
  139206. }
  139207. };
  139208. static static_bookblock _resbook_44u_7={
  139209. {
  139210. {0},
  139211. {0,0,&_44u7__p1_0},
  139212. {0,0,&_44u7__p2_0},
  139213. {0,0,&_44u7__p3_0},
  139214. {0,0,&_44u7__p4_0},
  139215. {0,0,&_44u7__p5_0},
  139216. {0,0,&_44u7__p6_0},
  139217. {&_44u7__p7_0,&_44u7__p7_1},
  139218. {&_44u7__p8_0,&_44u7__p8_1},
  139219. {&_44u7__p9_0,&_44u7__p9_1,&_44u7__p9_2}
  139220. }
  139221. };
  139222. static static_bookblock _resbook_44u_8={
  139223. {
  139224. {0},
  139225. {0,0,&_44u8_p1_0},
  139226. {0,0,&_44u8_p2_0},
  139227. {0,0,&_44u8_p3_0},
  139228. {0,0,&_44u8_p4_0},
  139229. {&_44u8_p5_0,&_44u8_p5_1},
  139230. {&_44u8_p6_0,&_44u8_p6_1},
  139231. {&_44u8_p7_0,&_44u8_p7_1},
  139232. {&_44u8_p8_0,&_44u8_p8_1},
  139233. {&_44u8_p9_0,&_44u8_p9_1,&_44u8_p9_2}
  139234. }
  139235. };
  139236. static static_bookblock _resbook_44u_9={
  139237. {
  139238. {0},
  139239. {0,0,&_44u9_p1_0},
  139240. {0,0,&_44u9_p2_0},
  139241. {0,0,&_44u9_p3_0},
  139242. {0,0,&_44u9_p4_0},
  139243. {&_44u9_p5_0,&_44u9_p5_1},
  139244. {&_44u9_p6_0,&_44u9_p6_1},
  139245. {&_44u9_p7_0,&_44u9_p7_1},
  139246. {&_44u9_p8_0,&_44u9_p8_1},
  139247. {&_44u9_p9_0,&_44u9_p9_1,&_44u9_p9_2}
  139248. }
  139249. };
  139250. static vorbis_residue_template _res_44u_n1[]={
  139251. {1,0, &_residue_44_low_un,
  139252. &_huff_book__44un1__short,&_huff_book__44un1__short,
  139253. &_resbook_44u_n1,&_resbook_44u_n1},
  139254. {1,0, &_residue_44_low_un,
  139255. &_huff_book__44un1__long,&_huff_book__44un1__long,
  139256. &_resbook_44u_n1,&_resbook_44u_n1}
  139257. };
  139258. static vorbis_residue_template _res_44u_0[]={
  139259. {1,0, &_residue_44_low_un,
  139260. &_huff_book__44u0__short,&_huff_book__44u0__short,
  139261. &_resbook_44u_0,&_resbook_44u_0},
  139262. {1,0, &_residue_44_low_un,
  139263. &_huff_book__44u0__long,&_huff_book__44u0__long,
  139264. &_resbook_44u_0,&_resbook_44u_0}
  139265. };
  139266. static vorbis_residue_template _res_44u_1[]={
  139267. {1,0, &_residue_44_low_un,
  139268. &_huff_book__44u1__short,&_huff_book__44u1__short,
  139269. &_resbook_44u_1,&_resbook_44u_1},
  139270. {1,0, &_residue_44_low_un,
  139271. &_huff_book__44u1__long,&_huff_book__44u1__long,
  139272. &_resbook_44u_1,&_resbook_44u_1}
  139273. };
  139274. static vorbis_residue_template _res_44u_2[]={
  139275. {1,0, &_residue_44_low_un,
  139276. &_huff_book__44u2__short,&_huff_book__44u2__short,
  139277. &_resbook_44u_2,&_resbook_44u_2},
  139278. {1,0, &_residue_44_low_un,
  139279. &_huff_book__44u2__long,&_huff_book__44u2__long,
  139280. &_resbook_44u_2,&_resbook_44u_2}
  139281. };
  139282. static vorbis_residue_template _res_44u_3[]={
  139283. {1,0, &_residue_44_low_un,
  139284. &_huff_book__44u3__short,&_huff_book__44u3__short,
  139285. &_resbook_44u_3,&_resbook_44u_3},
  139286. {1,0, &_residue_44_low_un,
  139287. &_huff_book__44u3__long,&_huff_book__44u3__long,
  139288. &_resbook_44u_3,&_resbook_44u_3}
  139289. };
  139290. static vorbis_residue_template _res_44u_4[]={
  139291. {1,0, &_residue_44_low_un,
  139292. &_huff_book__44u4__short,&_huff_book__44u4__short,
  139293. &_resbook_44u_4,&_resbook_44u_4},
  139294. {1,0, &_residue_44_low_un,
  139295. &_huff_book__44u4__long,&_huff_book__44u4__long,
  139296. &_resbook_44u_4,&_resbook_44u_4}
  139297. };
  139298. static vorbis_residue_template _res_44u_5[]={
  139299. {1,0, &_residue_44_mid_un,
  139300. &_huff_book__44u5__short,&_huff_book__44u5__short,
  139301. &_resbook_44u_5,&_resbook_44u_5},
  139302. {1,0, &_residue_44_mid_un,
  139303. &_huff_book__44u5__long,&_huff_book__44u5__long,
  139304. &_resbook_44u_5,&_resbook_44u_5}
  139305. };
  139306. static vorbis_residue_template _res_44u_6[]={
  139307. {1,0, &_residue_44_mid_un,
  139308. &_huff_book__44u6__short,&_huff_book__44u6__short,
  139309. &_resbook_44u_6,&_resbook_44u_6},
  139310. {1,0, &_residue_44_mid_un,
  139311. &_huff_book__44u6__long,&_huff_book__44u6__long,
  139312. &_resbook_44u_6,&_resbook_44u_6}
  139313. };
  139314. static vorbis_residue_template _res_44u_7[]={
  139315. {1,0, &_residue_44_mid_un,
  139316. &_huff_book__44u7__short,&_huff_book__44u7__short,
  139317. &_resbook_44u_7,&_resbook_44u_7},
  139318. {1,0, &_residue_44_mid_un,
  139319. &_huff_book__44u7__long,&_huff_book__44u7__long,
  139320. &_resbook_44u_7,&_resbook_44u_7}
  139321. };
  139322. static vorbis_residue_template _res_44u_8[]={
  139323. {1,0, &_residue_44_hi_un,
  139324. &_huff_book__44u8__short,&_huff_book__44u8__short,
  139325. &_resbook_44u_8,&_resbook_44u_8},
  139326. {1,0, &_residue_44_hi_un,
  139327. &_huff_book__44u8__long,&_huff_book__44u8__long,
  139328. &_resbook_44u_8,&_resbook_44u_8}
  139329. };
  139330. static vorbis_residue_template _res_44u_9[]={
  139331. {1,0, &_residue_44_hi_un,
  139332. &_huff_book__44u9__short,&_huff_book__44u9__short,
  139333. &_resbook_44u_9,&_resbook_44u_9},
  139334. {1,0, &_residue_44_hi_un,
  139335. &_huff_book__44u9__long,&_huff_book__44u9__long,
  139336. &_resbook_44u_9,&_resbook_44u_9}
  139337. };
  139338. static vorbis_mapping_template _mapres_template_44_uncoupled[]={
  139339. { _map_nominal_u, _res_44u_n1 }, /* -1 */
  139340. { _map_nominal_u, _res_44u_0 }, /* 0 */
  139341. { _map_nominal_u, _res_44u_1 }, /* 1 */
  139342. { _map_nominal_u, _res_44u_2 }, /* 2 */
  139343. { _map_nominal_u, _res_44u_3 }, /* 3 */
  139344. { _map_nominal_u, _res_44u_4 }, /* 4 */
  139345. { _map_nominal_u, _res_44u_5 }, /* 5 */
  139346. { _map_nominal_u, _res_44u_6 }, /* 6 */
  139347. { _map_nominal_u, _res_44u_7 }, /* 7 */
  139348. { _map_nominal_u, _res_44u_8 }, /* 8 */
  139349. { _map_nominal_u, _res_44u_9 }, /* 9 */
  139350. };
  139351. /*** End of inlined file: residue_44u.h ***/
  139352. static double rate_mapping_44_un[12]={
  139353. 32000.,48000.,60000.,70000.,80000.,86000.,
  139354. 96000.,110000.,120000.,140000.,160000.,240001.
  139355. };
  139356. ve_setup_data_template ve_setup_44_uncoupled={
  139357. 11,
  139358. rate_mapping_44_un,
  139359. quality_mapping_44,
  139360. -1,
  139361. 40000,
  139362. 50000,
  139363. blocksize_short_44,
  139364. blocksize_long_44,
  139365. _psy_tone_masteratt_44,
  139366. _psy_tone_0dB,
  139367. _psy_tone_suppress,
  139368. _vp_tonemask_adj_otherblock,
  139369. _vp_tonemask_adj_longblock,
  139370. _vp_tonemask_adj_otherblock,
  139371. _psy_noiseguards_44,
  139372. _psy_noisebias_impulse,
  139373. _psy_noisebias_padding,
  139374. _psy_noisebias_trans,
  139375. _psy_noisebias_long,
  139376. _psy_noise_suppress,
  139377. _psy_compand_44,
  139378. _psy_compand_short_mapping,
  139379. _psy_compand_long_mapping,
  139380. {_noise_start_short_44,_noise_start_long_44},
  139381. {_noise_part_short_44,_noise_part_long_44},
  139382. _noise_thresh_44,
  139383. _psy_ath_floater,
  139384. _psy_ath_abs,
  139385. _psy_lowpass_44,
  139386. _psy_global_44,
  139387. _global_mapping_44,
  139388. NULL,
  139389. _floor_books,
  139390. _floor,
  139391. _floor_short_mapping_44,
  139392. _floor_long_mapping_44,
  139393. _mapres_template_44_uncoupled
  139394. };
  139395. /*** End of inlined file: setup_44u.h ***/
  139396. /*** Start of inlined file: setup_32.h ***/
  139397. static double rate_mapping_32[12]={
  139398. 18000.,28000.,35000.,45000.,56000.,60000.,
  139399. 75000.,90000.,100000.,115000.,150000.,190000.,
  139400. };
  139401. static double rate_mapping_32_un[12]={
  139402. 30000.,42000.,52000.,64000.,72000.,78000.,
  139403. 86000.,92000.,110000.,120000.,140000.,190000.,
  139404. };
  139405. static double _psy_lowpass_32[12]={
  139406. 12.3,13.,13.,14.,15.,99.,99.,99.,99.,99.,99.,99.
  139407. };
  139408. ve_setup_data_template ve_setup_32_stereo={
  139409. 11,
  139410. rate_mapping_32,
  139411. quality_mapping_44,
  139412. 2,
  139413. 26000,
  139414. 40000,
  139415. blocksize_short_44,
  139416. blocksize_long_44,
  139417. _psy_tone_masteratt_44,
  139418. _psy_tone_0dB,
  139419. _psy_tone_suppress,
  139420. _vp_tonemask_adj_otherblock,
  139421. _vp_tonemask_adj_longblock,
  139422. _vp_tonemask_adj_otherblock,
  139423. _psy_noiseguards_44,
  139424. _psy_noisebias_impulse,
  139425. _psy_noisebias_padding,
  139426. _psy_noisebias_trans,
  139427. _psy_noisebias_long,
  139428. _psy_noise_suppress,
  139429. _psy_compand_44,
  139430. _psy_compand_short_mapping,
  139431. _psy_compand_long_mapping,
  139432. {_noise_start_short_44,_noise_start_long_44},
  139433. {_noise_part_short_44,_noise_part_long_44},
  139434. _noise_thresh_44,
  139435. _psy_ath_floater,
  139436. _psy_ath_abs,
  139437. _psy_lowpass_32,
  139438. _psy_global_44,
  139439. _global_mapping_44,
  139440. _psy_stereo_modes_44,
  139441. _floor_books,
  139442. _floor,
  139443. _floor_short_mapping_44,
  139444. _floor_long_mapping_44,
  139445. _mapres_template_44_stereo
  139446. };
  139447. ve_setup_data_template ve_setup_32_uncoupled={
  139448. 11,
  139449. rate_mapping_32_un,
  139450. quality_mapping_44,
  139451. -1,
  139452. 26000,
  139453. 40000,
  139454. blocksize_short_44,
  139455. blocksize_long_44,
  139456. _psy_tone_masteratt_44,
  139457. _psy_tone_0dB,
  139458. _psy_tone_suppress,
  139459. _vp_tonemask_adj_otherblock,
  139460. _vp_tonemask_adj_longblock,
  139461. _vp_tonemask_adj_otherblock,
  139462. _psy_noiseguards_44,
  139463. _psy_noisebias_impulse,
  139464. _psy_noisebias_padding,
  139465. _psy_noisebias_trans,
  139466. _psy_noisebias_long,
  139467. _psy_noise_suppress,
  139468. _psy_compand_44,
  139469. _psy_compand_short_mapping,
  139470. _psy_compand_long_mapping,
  139471. {_noise_start_short_44,_noise_start_long_44},
  139472. {_noise_part_short_44,_noise_part_long_44},
  139473. _noise_thresh_44,
  139474. _psy_ath_floater,
  139475. _psy_ath_abs,
  139476. _psy_lowpass_32,
  139477. _psy_global_44,
  139478. _global_mapping_44,
  139479. NULL,
  139480. _floor_books,
  139481. _floor,
  139482. _floor_short_mapping_44,
  139483. _floor_long_mapping_44,
  139484. _mapres_template_44_uncoupled
  139485. };
  139486. /*** End of inlined file: setup_32.h ***/
  139487. /*** Start of inlined file: setup_8.h ***/
  139488. /*** Start of inlined file: psych_8.h ***/
  139489. static att3 _psy_tone_masteratt_8[3]={
  139490. {{ 32, 25, 12}, 0, 0}, /* 0 */
  139491. {{ 30, 25, 12}, 0, 0}, /* 0 */
  139492. {{ 20, 0, -14}, 0, 0}, /* 0 */
  139493. };
  139494. static vp_adjblock _vp_tonemask_adj_8[3]={
  139495. {{-15,-15,-15,-15,-10,-10, -6, 0, 0, 0, 0,10, 0, 0,99,99,99}}, /* 1 */
  139496. {{-15,-15,-15,-15,-10,-10, -6, 0, 0, 0, 0,10, 0, 0,99,99,99}}, /* 1 */
  139497. {{-15,-15,-15,-15,-10,-10, -6, 0, 0, 0, 0, 0, 0, 0,99,99,99}}, /* 1 */
  139498. };
  139499. static noise3 _psy_noisebias_8[3]={
  139500. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 8, 8, 8, 10, 10, 99, 99, 99},
  139501. {-10,-10,-10,-10, -5, -5, -5, 0, 0, 4, 4, 4, 4, 4, 99, 99, 99},
  139502. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}},
  139503. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 8, 8, 8, 10, 10, 99, 99, 99},
  139504. {-10,-10,-10,-10,-10,-10, -5, -5, -5, 0, 0, 0, 0, 0, 99, 99, 99},
  139505. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}},
  139506. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 99, 99, 99},
  139507. {-30,-30,-30,-30,-26,-22,-20,-14,-12,-12,-10,-10,-10,-10, 99, 99, 99},
  139508. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24, 99, 99, 99}}},
  139509. };
  139510. static adj_stereo _psy_stereo_modes_8[3]={
  139511. {{ 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139512. { 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139513. { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
  139514. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139515. {{ 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139516. { 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139517. { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
  139518. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139519. {{ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139520. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139521. { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
  139522. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139523. };
  139524. static noiseguard _psy_noiseguards_8[2]={
  139525. {10,10,-1},
  139526. {10,10,-1},
  139527. };
  139528. static compandblock _psy_compand_8[2]={
  139529. {{
  139530. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  139531. 8, 8, 9, 9,10,10,11, 11, /* 15dB */
  139532. 12,12,13,13,14,14,15, 15, /* 23dB */
  139533. 16,16,17,17,17,18,18, 19, /* 31dB */
  139534. 19,19,20,21,22,23,24, 25, /* 39dB */
  139535. }},
  139536. {{
  139537. 0, 1, 2, 3, 4, 5, 6, 6, /* 7dB */
  139538. 7, 7, 6, 6, 5, 5, 4, 4, /* 15dB */
  139539. 3, 3, 3, 4, 5, 6, 7, 8, /* 23dB */
  139540. 9,10,11,12,13,14,15, 16, /* 31dB */
  139541. 17,18,19,20,21,22,23, 24, /* 39dB */
  139542. }},
  139543. };
  139544. static double _psy_lowpass_8[3]={3.,4.,4.};
  139545. static int _noise_start_8[2]={
  139546. 64,64,
  139547. };
  139548. static int _noise_part_8[2]={
  139549. 8,8,
  139550. };
  139551. static int _psy_ath_floater_8[3]={
  139552. -100,-100,-105,
  139553. };
  139554. static int _psy_ath_abs_8[3]={
  139555. -130,-130,-140,
  139556. };
  139557. /*** End of inlined file: psych_8.h ***/
  139558. /*** Start of inlined file: residue_8.h ***/
  139559. static static_bookblock _resbook_8s_0={
  139560. {
  139561. {0},{0,0,&_8c0_s_p1_0},{0,0,&_8c0_s_p2_0},{0,0,&_8c0_s_p3_0},
  139562. {0,0,&_8c0_s_p4_0},{0,0,&_8c0_s_p5_0},{0,0,&_8c0_s_p6_0},
  139563. {&_8c0_s_p7_0,&_8c0_s_p7_1},{&_8c0_s_p8_0,&_8c0_s_p8_1},
  139564. {&_8c0_s_p9_0,&_8c0_s_p9_1,&_8c0_s_p9_2}
  139565. }
  139566. };
  139567. static static_bookblock _resbook_8s_1={
  139568. {
  139569. {0},{0,0,&_8c1_s_p1_0},{0,0,&_8c1_s_p2_0},{0,0,&_8c1_s_p3_0},
  139570. {0,0,&_8c1_s_p4_0},{0,0,&_8c1_s_p5_0},{0,0,&_8c1_s_p6_0},
  139571. {&_8c1_s_p7_0,&_8c1_s_p7_1},{&_8c1_s_p8_0,&_8c1_s_p8_1},
  139572. {&_8c1_s_p9_0,&_8c1_s_p9_1,&_8c1_s_p9_2}
  139573. }
  139574. };
  139575. static vorbis_residue_template _res_8s_0[]={
  139576. {2,0, &_residue_44_mid,
  139577. &_huff_book__8c0_s_single,&_huff_book__8c0_s_single,
  139578. &_resbook_8s_0,&_resbook_8s_0},
  139579. };
  139580. static vorbis_residue_template _res_8s_1[]={
  139581. {2,0, &_residue_44_mid,
  139582. &_huff_book__8c1_s_single,&_huff_book__8c1_s_single,
  139583. &_resbook_8s_1,&_resbook_8s_1},
  139584. };
  139585. static vorbis_mapping_template _mapres_template_8_stereo[2]={
  139586. { _map_nominal, _res_8s_0 }, /* 0 */
  139587. { _map_nominal, _res_8s_1 }, /* 1 */
  139588. };
  139589. static static_bookblock _resbook_8u_0={
  139590. {
  139591. {0},
  139592. {0,0,&_8u0__p1_0},
  139593. {0,0,&_8u0__p2_0},
  139594. {0,0,&_8u0__p3_0},
  139595. {0,0,&_8u0__p4_0},
  139596. {0,0,&_8u0__p5_0},
  139597. {&_8u0__p6_0,&_8u0__p6_1},
  139598. {&_8u0__p7_0,&_8u0__p7_1,&_8u0__p7_2}
  139599. }
  139600. };
  139601. static static_bookblock _resbook_8u_1={
  139602. {
  139603. {0},
  139604. {0,0,&_8u1__p1_0},
  139605. {0,0,&_8u1__p2_0},
  139606. {0,0,&_8u1__p3_0},
  139607. {0,0,&_8u1__p4_0},
  139608. {0,0,&_8u1__p5_0},
  139609. {0,0,&_8u1__p6_0},
  139610. {&_8u1__p7_0,&_8u1__p7_1},
  139611. {&_8u1__p8_0,&_8u1__p8_1},
  139612. {&_8u1__p9_0,&_8u1__p9_1,&_8u1__p9_2}
  139613. }
  139614. };
  139615. static vorbis_residue_template _res_8u_0[]={
  139616. {1,0, &_residue_44_low_un,
  139617. &_huff_book__8u0__single,&_huff_book__8u0__single,
  139618. &_resbook_8u_0,&_resbook_8u_0},
  139619. };
  139620. static vorbis_residue_template _res_8u_1[]={
  139621. {1,0, &_residue_44_mid_un,
  139622. &_huff_book__8u1__single,&_huff_book__8u1__single,
  139623. &_resbook_8u_1,&_resbook_8u_1},
  139624. };
  139625. static vorbis_mapping_template _mapres_template_8_uncoupled[2]={
  139626. { _map_nominal_u, _res_8u_0 }, /* 0 */
  139627. { _map_nominal_u, _res_8u_1 }, /* 1 */
  139628. };
  139629. /*** End of inlined file: residue_8.h ***/
  139630. static int blocksize_8[2]={
  139631. 512,512
  139632. };
  139633. static int _floor_mapping_8[2]={
  139634. 6,6,
  139635. };
  139636. static double rate_mapping_8[3]={
  139637. 6000.,9000.,32000.,
  139638. };
  139639. static double rate_mapping_8_uncoupled[3]={
  139640. 8000.,14000.,42000.,
  139641. };
  139642. static double quality_mapping_8[3]={
  139643. -.1,.0,1.
  139644. };
  139645. static double _psy_compand_8_mapping[3]={ 0., 1., 1.};
  139646. static double _global_mapping_8[3]={ 1., 2., 3. };
  139647. ve_setup_data_template ve_setup_8_stereo={
  139648. 2,
  139649. rate_mapping_8,
  139650. quality_mapping_8,
  139651. 2,
  139652. 8000,
  139653. 9000,
  139654. blocksize_8,
  139655. blocksize_8,
  139656. _psy_tone_masteratt_8,
  139657. _psy_tone_0dB,
  139658. _psy_tone_suppress,
  139659. _vp_tonemask_adj_8,
  139660. NULL,
  139661. _vp_tonemask_adj_8,
  139662. _psy_noiseguards_8,
  139663. _psy_noisebias_8,
  139664. _psy_noisebias_8,
  139665. NULL,
  139666. NULL,
  139667. _psy_noise_suppress,
  139668. _psy_compand_8,
  139669. _psy_compand_8_mapping,
  139670. NULL,
  139671. {_noise_start_8,_noise_start_8},
  139672. {_noise_part_8,_noise_part_8},
  139673. _noise_thresh_5only,
  139674. _psy_ath_floater_8,
  139675. _psy_ath_abs_8,
  139676. _psy_lowpass_8,
  139677. _psy_global_44,
  139678. _global_mapping_8,
  139679. _psy_stereo_modes_8,
  139680. _floor_books,
  139681. _floor,
  139682. _floor_mapping_8,
  139683. NULL,
  139684. _mapres_template_8_stereo
  139685. };
  139686. ve_setup_data_template ve_setup_8_uncoupled={
  139687. 2,
  139688. rate_mapping_8_uncoupled,
  139689. quality_mapping_8,
  139690. -1,
  139691. 8000,
  139692. 9000,
  139693. blocksize_8,
  139694. blocksize_8,
  139695. _psy_tone_masteratt_8,
  139696. _psy_tone_0dB,
  139697. _psy_tone_suppress,
  139698. _vp_tonemask_adj_8,
  139699. NULL,
  139700. _vp_tonemask_adj_8,
  139701. _psy_noiseguards_8,
  139702. _psy_noisebias_8,
  139703. _psy_noisebias_8,
  139704. NULL,
  139705. NULL,
  139706. _psy_noise_suppress,
  139707. _psy_compand_8,
  139708. _psy_compand_8_mapping,
  139709. NULL,
  139710. {_noise_start_8,_noise_start_8},
  139711. {_noise_part_8,_noise_part_8},
  139712. _noise_thresh_5only,
  139713. _psy_ath_floater_8,
  139714. _psy_ath_abs_8,
  139715. _psy_lowpass_8,
  139716. _psy_global_44,
  139717. _global_mapping_8,
  139718. _psy_stereo_modes_8,
  139719. _floor_books,
  139720. _floor,
  139721. _floor_mapping_8,
  139722. NULL,
  139723. _mapres_template_8_uncoupled
  139724. };
  139725. /*** End of inlined file: setup_8.h ***/
  139726. /*** Start of inlined file: setup_11.h ***/
  139727. /*** Start of inlined file: psych_11.h ***/
  139728. static double _psy_lowpass_11[3]={4.5,5.5,30.,};
  139729. static att3 _psy_tone_masteratt_11[3]={
  139730. {{ 30, 25, 12}, 0, 0}, /* 0 */
  139731. {{ 30, 25, 12}, 0, 0}, /* 0 */
  139732. {{ 20, 0, -14}, 0, 0}, /* 0 */
  139733. };
  139734. static vp_adjblock _vp_tonemask_adj_11[3]={
  139735. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0,10, 2, 0,99,99,99}}, /* 0 */
  139736. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0, 5, 0, 0,99,99,99}}, /* 1 */
  139737. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0, 0, 0, 0,99,99,99}}, /* 2 */
  139738. };
  139739. static noise3 _psy_noisebias_11[3]={
  139740. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 10, 10, 12, 12, 12, 99, 99, 99},
  139741. {-15,-15,-15,-15,-10,-10, -5, 0, 0, 4, 4, 5, 5, 10, 99, 99, 99},
  139742. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}},
  139743. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 10, 10, 12, 12, 12, 99, 99, 99},
  139744. {-15,-15,-15,-15,-10,-10, -5, -5, -5, 0, 0, 0, 0, 0, 99, 99, 99},
  139745. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}},
  139746. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 99, 99, 99},
  139747. {-30,-30,-30,-30,-26,-22,-20,-14,-12,-12,-10,-10,-10,-10, 99, 99, 99},
  139748. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24, 99, 99, 99}}},
  139749. };
  139750. static double _noise_thresh_11[3]={ .3,.5,.5 };
  139751. /*** End of inlined file: psych_11.h ***/
  139752. static int blocksize_11[2]={
  139753. 512,512
  139754. };
  139755. static int _floor_mapping_11[2]={
  139756. 6,6,
  139757. };
  139758. static double rate_mapping_11[3]={
  139759. 8000.,13000.,44000.,
  139760. };
  139761. static double rate_mapping_11_uncoupled[3]={
  139762. 12000.,20000.,50000.,
  139763. };
  139764. static double quality_mapping_11[3]={
  139765. -.1,.0,1.
  139766. };
  139767. ve_setup_data_template ve_setup_11_stereo={
  139768. 2,
  139769. rate_mapping_11,
  139770. quality_mapping_11,
  139771. 2,
  139772. 9000,
  139773. 15000,
  139774. blocksize_11,
  139775. blocksize_11,
  139776. _psy_tone_masteratt_11,
  139777. _psy_tone_0dB,
  139778. _psy_tone_suppress,
  139779. _vp_tonemask_adj_11,
  139780. NULL,
  139781. _vp_tonemask_adj_11,
  139782. _psy_noiseguards_8,
  139783. _psy_noisebias_11,
  139784. _psy_noisebias_11,
  139785. NULL,
  139786. NULL,
  139787. _psy_noise_suppress,
  139788. _psy_compand_8,
  139789. _psy_compand_8_mapping,
  139790. NULL,
  139791. {_noise_start_8,_noise_start_8},
  139792. {_noise_part_8,_noise_part_8},
  139793. _noise_thresh_11,
  139794. _psy_ath_floater_8,
  139795. _psy_ath_abs_8,
  139796. _psy_lowpass_11,
  139797. _psy_global_44,
  139798. _global_mapping_8,
  139799. _psy_stereo_modes_8,
  139800. _floor_books,
  139801. _floor,
  139802. _floor_mapping_11,
  139803. NULL,
  139804. _mapres_template_8_stereo
  139805. };
  139806. ve_setup_data_template ve_setup_11_uncoupled={
  139807. 2,
  139808. rate_mapping_11_uncoupled,
  139809. quality_mapping_11,
  139810. -1,
  139811. 9000,
  139812. 15000,
  139813. blocksize_11,
  139814. blocksize_11,
  139815. _psy_tone_masteratt_11,
  139816. _psy_tone_0dB,
  139817. _psy_tone_suppress,
  139818. _vp_tonemask_adj_11,
  139819. NULL,
  139820. _vp_tonemask_adj_11,
  139821. _psy_noiseguards_8,
  139822. _psy_noisebias_11,
  139823. _psy_noisebias_11,
  139824. NULL,
  139825. NULL,
  139826. _psy_noise_suppress,
  139827. _psy_compand_8,
  139828. _psy_compand_8_mapping,
  139829. NULL,
  139830. {_noise_start_8,_noise_start_8},
  139831. {_noise_part_8,_noise_part_8},
  139832. _noise_thresh_11,
  139833. _psy_ath_floater_8,
  139834. _psy_ath_abs_8,
  139835. _psy_lowpass_11,
  139836. _psy_global_44,
  139837. _global_mapping_8,
  139838. _psy_stereo_modes_8,
  139839. _floor_books,
  139840. _floor,
  139841. _floor_mapping_11,
  139842. NULL,
  139843. _mapres_template_8_uncoupled
  139844. };
  139845. /*** End of inlined file: setup_11.h ***/
  139846. /*** Start of inlined file: setup_16.h ***/
  139847. /*** Start of inlined file: psych_16.h ***/
  139848. static adj_stereo _psy_stereo_modes_16[4]={
  139849. {{ 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139850. { 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139851. { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 4, 4},
  139852. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139853. {{ 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139854. { 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139855. { 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 4, 4, 4, 4, 4},
  139856. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139857. {{ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139858. { 5, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139859. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139860. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139861. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  139862. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  139863. { 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8},
  139864. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139865. };
  139866. static double _psy_lowpass_16[4]={6.5,8,30.,99.};
  139867. static att3 _psy_tone_masteratt_16[4]={
  139868. {{ 30, 25, 12}, 0, 0}, /* 0 */
  139869. {{ 25, 22, 12}, 0, 0}, /* 0 */
  139870. {{ 20, 12, 0}, 0, 0}, /* 0 */
  139871. {{ 15, 0, -14}, 0, 0}, /* 0 */
  139872. };
  139873. static vp_adjblock _vp_tonemask_adj_16[4]={
  139874. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0,10, 0, 0, 0, 0, 0}}, /* 0 */
  139875. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0,10, 0, 0, 0, 0, 0}}, /* 1 */
  139876. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}, /* 2 */
  139877. {{-30,-30,-30,-30,-30,-26,-20,-10, -5, 0, 0, 0, 0, 0, 0, 0, 0}}, /* 2 */
  139878. };
  139879. static noise3 _psy_noisebias_16_short[4]={
  139880. {{{-15,-15,-15,-15,-15,-10,-10,-5, 4, 10, 10, 10, 10, 12, 12, 14, 20},
  139881. {-15,-15,-15,-15,-15,-10,-10, -5, 0, 0, 4, 5, 5, 6, 8, 8, 15},
  139882. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -6, -6}}},
  139883. {{{-15,-15,-15,-15,-15,-10,-10,-5, 4, 6, 6, 6, 6, 8, 10, 12, 20},
  139884. {-15,-15,-15,-15,-15,-15,-15,-10, -5, -5, -5, 4, 5, 6, 8, 8, 15},
  139885. {-30,-30,-30,-30,-30,-24,-20,-14,-10,-10,-10,-10,-10,-10,-10,-10,-10}}},
  139886. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 5, 8, 12},
  139887. {-20,-20,-20,-20,-16,-12,-20,-14,-10,-10, -8, 0, 0, 0, 0, 2, 5},
  139888. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139889. {{{-15,-15,-15,-15,-15,-12,-10, -8, -5, -5, -5, -5, -5, 0, 0, 0, 6},
  139890. {-30,-30,-30,-30,-26,-22,-20,-14,-12,-12,-10,-10,-10,-10,-10,-10, -6},
  139891. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139892. };
  139893. static noise3 _psy_noisebias_16_impulse[4]={
  139894. {{{-15,-15,-15,-15,-15,-10,-10,-5, 4, 10, 10, 10, 10, 12, 12, 14, 20},
  139895. {-15,-15,-15,-15,-15,-10,-10, -5, 0, 0, 4, 5, 5, 6, 8, 8, 15},
  139896. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -6, -6}}},
  139897. {{{-15,-15,-15,-15,-15,-10,-10,-5, 4, 4, 4, 4, 5, 5, 6, 8, 15},
  139898. {-15,-15,-15,-15,-15,-15,-15,-10, -5, -5, -5, 0, 0, 0, 0, 4, 10},
  139899. {-30,-30,-30,-30,-30,-24,-20,-14,-10,-10,-10,-10,-10,-10,-10,-10,-10}}},
  139900. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 0, 0, 0, 0, 0, 0, 4, 10},
  139901. {-20,-20,-20,-20,-16,-12,-20,-14,-10,-10,-10,-10,-10,-10,-10, -7, -5},
  139902. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139903. {{{-15,-15,-15,-15,-15,-12,-10, -8, -5, -5, -5, -5, -5, 0, 0, 0, 6},
  139904. {-30,-30,-30,-30,-26,-22,-20,-18,-18,-18,-20,-20,-20,-20,-20,-20,-16},
  139905. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139906. };
  139907. static noise3 _psy_noisebias_16[4]={
  139908. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 6, 8, 8, 10, 10, 10, 14, 20},
  139909. {-10,-10,-10,-10,-10, -5, -2, -2, 0, 0, 0, 4, 5, 6, 8, 8, 15},
  139910. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -6, -6}}},
  139911. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 6, 6, 6, 6, 8, 10, 12, 20},
  139912. {-15,-15,-15,-15,-15,-10, -5, -5, 0, 0, 0, 4, 5, 6, 8, 8, 15},
  139913. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -6, -6}}},
  139914. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 5, 8, 12},
  139915. {-20,-20,-20,-20,-16,-12,-20,-10, -5, -5, 0, 0, 0, 0, 0, 2, 5},
  139916. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139917. {{{-15,-15,-15,-15,-15,-12,-10, -8, -5, -5, -5, -5, -5, 0, 0, 0, 6},
  139918. {-30,-30,-30,-30,-26,-22,-20,-14,-12,-12,-10,-10,-10,-10,-10,-10, -6},
  139919. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139920. };
  139921. static double _noise_thresh_16[4]={ .3,.5,.5,.5 };
  139922. static int _noise_start_16[3]={ 256,256,9999 };
  139923. static int _noise_part_16[4]={ 8,8,8,8 };
  139924. static int _psy_ath_floater_16[4]={
  139925. -100,-100,-100,-105,
  139926. };
  139927. static int _psy_ath_abs_16[4]={
  139928. -130,-130,-130,-140,
  139929. };
  139930. /*** End of inlined file: psych_16.h ***/
  139931. /*** Start of inlined file: residue_16.h ***/
  139932. static static_bookblock _resbook_16s_0={
  139933. {
  139934. {0},
  139935. {0,0,&_16c0_s_p1_0},
  139936. {0,0,&_16c0_s_p2_0},
  139937. {0,0,&_16c0_s_p3_0},
  139938. {0,0,&_16c0_s_p4_0},
  139939. {0,0,&_16c0_s_p5_0},
  139940. {0,0,&_16c0_s_p6_0},
  139941. {&_16c0_s_p7_0,&_16c0_s_p7_1},
  139942. {&_16c0_s_p8_0,&_16c0_s_p8_1},
  139943. {&_16c0_s_p9_0,&_16c0_s_p9_1,&_16c0_s_p9_2}
  139944. }
  139945. };
  139946. static static_bookblock _resbook_16s_1={
  139947. {
  139948. {0},
  139949. {0,0,&_16c1_s_p1_0},
  139950. {0,0,&_16c1_s_p2_0},
  139951. {0,0,&_16c1_s_p3_0},
  139952. {0,0,&_16c1_s_p4_0},
  139953. {0,0,&_16c1_s_p5_0},
  139954. {0,0,&_16c1_s_p6_0},
  139955. {&_16c1_s_p7_0,&_16c1_s_p7_1},
  139956. {&_16c1_s_p8_0,&_16c1_s_p8_1},
  139957. {&_16c1_s_p9_0,&_16c1_s_p9_1,&_16c1_s_p9_2}
  139958. }
  139959. };
  139960. static static_bookblock _resbook_16s_2={
  139961. {
  139962. {0},
  139963. {0,0,&_16c2_s_p1_0},
  139964. {0,0,&_16c2_s_p2_0},
  139965. {0,0,&_16c2_s_p3_0},
  139966. {0,0,&_16c2_s_p4_0},
  139967. {&_16c2_s_p5_0,&_16c2_s_p5_1},
  139968. {&_16c2_s_p6_0,&_16c2_s_p6_1},
  139969. {&_16c2_s_p7_0,&_16c2_s_p7_1},
  139970. {&_16c2_s_p8_0,&_16c2_s_p8_1},
  139971. {&_16c2_s_p9_0,&_16c2_s_p9_1,&_16c2_s_p9_2}
  139972. }
  139973. };
  139974. static vorbis_residue_template _res_16s_0[]={
  139975. {2,0, &_residue_44_mid,
  139976. &_huff_book__16c0_s_single,&_huff_book__16c0_s_single,
  139977. &_resbook_16s_0,&_resbook_16s_0},
  139978. };
  139979. static vorbis_residue_template _res_16s_1[]={
  139980. {2,0, &_residue_44_mid,
  139981. &_huff_book__16c1_s_short,&_huff_book__16c1_s_short,
  139982. &_resbook_16s_1,&_resbook_16s_1},
  139983. {2,0, &_residue_44_mid,
  139984. &_huff_book__16c1_s_long,&_huff_book__16c1_s_long,
  139985. &_resbook_16s_1,&_resbook_16s_1}
  139986. };
  139987. static vorbis_residue_template _res_16s_2[]={
  139988. {2,0, &_residue_44_high,
  139989. &_huff_book__16c2_s_short,&_huff_book__16c2_s_short,
  139990. &_resbook_16s_2,&_resbook_16s_2},
  139991. {2,0, &_residue_44_high,
  139992. &_huff_book__16c2_s_long,&_huff_book__16c2_s_long,
  139993. &_resbook_16s_2,&_resbook_16s_2}
  139994. };
  139995. static vorbis_mapping_template _mapres_template_16_stereo[3]={
  139996. { _map_nominal, _res_16s_0 }, /* 0 */
  139997. { _map_nominal, _res_16s_1 }, /* 1 */
  139998. { _map_nominal, _res_16s_2 }, /* 2 */
  139999. };
  140000. static static_bookblock _resbook_16u_0={
  140001. {
  140002. {0},
  140003. {0,0,&_16u0__p1_0},
  140004. {0,0,&_16u0__p2_0},
  140005. {0,0,&_16u0__p3_0},
  140006. {0,0,&_16u0__p4_0},
  140007. {0,0,&_16u0__p5_0},
  140008. {&_16u0__p6_0,&_16u0__p6_1},
  140009. {&_16u0__p7_0,&_16u0__p7_1,&_16u0__p7_2}
  140010. }
  140011. };
  140012. static static_bookblock _resbook_16u_1={
  140013. {
  140014. {0},
  140015. {0,0,&_16u1__p1_0},
  140016. {0,0,&_16u1__p2_0},
  140017. {0,0,&_16u1__p3_0},
  140018. {0,0,&_16u1__p4_0},
  140019. {0,0,&_16u1__p5_0},
  140020. {0,0,&_16u1__p6_0},
  140021. {&_16u1__p7_0,&_16u1__p7_1},
  140022. {&_16u1__p8_0,&_16u1__p8_1},
  140023. {&_16u1__p9_0,&_16u1__p9_1,&_16u1__p9_2}
  140024. }
  140025. };
  140026. static static_bookblock _resbook_16u_2={
  140027. {
  140028. {0},
  140029. {0,0,&_16u2_p1_0},
  140030. {0,0,&_16u2_p2_0},
  140031. {0,0,&_16u2_p3_0},
  140032. {0,0,&_16u2_p4_0},
  140033. {&_16u2_p5_0,&_16u2_p5_1},
  140034. {&_16u2_p6_0,&_16u2_p6_1},
  140035. {&_16u2_p7_0,&_16u2_p7_1},
  140036. {&_16u2_p8_0,&_16u2_p8_1},
  140037. {&_16u2_p9_0,&_16u2_p9_1,&_16u2_p9_2}
  140038. }
  140039. };
  140040. static vorbis_residue_template _res_16u_0[]={
  140041. {1,0, &_residue_44_low_un,
  140042. &_huff_book__16u0__single,&_huff_book__16u0__single,
  140043. &_resbook_16u_0,&_resbook_16u_0},
  140044. };
  140045. static vorbis_residue_template _res_16u_1[]={
  140046. {1,0, &_residue_44_mid_un,
  140047. &_huff_book__16u1__short,&_huff_book__16u1__short,
  140048. &_resbook_16u_1,&_resbook_16u_1},
  140049. {1,0, &_residue_44_mid_un,
  140050. &_huff_book__16u1__long,&_huff_book__16u1__long,
  140051. &_resbook_16u_1,&_resbook_16u_1}
  140052. };
  140053. static vorbis_residue_template _res_16u_2[]={
  140054. {1,0, &_residue_44_hi_un,
  140055. &_huff_book__16u2__short,&_huff_book__16u2__short,
  140056. &_resbook_16u_2,&_resbook_16u_2},
  140057. {1,0, &_residue_44_hi_un,
  140058. &_huff_book__16u2__long,&_huff_book__16u2__long,
  140059. &_resbook_16u_2,&_resbook_16u_2}
  140060. };
  140061. static vorbis_mapping_template _mapres_template_16_uncoupled[3]={
  140062. { _map_nominal_u, _res_16u_0 }, /* 0 */
  140063. { _map_nominal_u, _res_16u_1 }, /* 1 */
  140064. { _map_nominal_u, _res_16u_2 }, /* 2 */
  140065. };
  140066. /*** End of inlined file: residue_16.h ***/
  140067. static int blocksize_16_short[3]={
  140068. 1024,512,512
  140069. };
  140070. static int blocksize_16_long[3]={
  140071. 1024,1024,1024
  140072. };
  140073. static int _floor_mapping_16_short[3]={
  140074. 9,3,3
  140075. };
  140076. static int _floor_mapping_16[3]={
  140077. 9,9,9
  140078. };
  140079. static double rate_mapping_16[4]={
  140080. 12000.,20000.,44000.,86000.
  140081. };
  140082. static double rate_mapping_16_uncoupled[4]={
  140083. 16000.,28000.,64000.,100000.
  140084. };
  140085. static double _global_mapping_16[4]={ 1., 2., 3., 4. };
  140086. static double quality_mapping_16[4]={ -.1,.05,.5,1. };
  140087. static double _psy_compand_16_mapping[4]={ 0., .8, 1., 1.};
  140088. ve_setup_data_template ve_setup_16_stereo={
  140089. 3,
  140090. rate_mapping_16,
  140091. quality_mapping_16,
  140092. 2,
  140093. 15000,
  140094. 19000,
  140095. blocksize_16_short,
  140096. blocksize_16_long,
  140097. _psy_tone_masteratt_16,
  140098. _psy_tone_0dB,
  140099. _psy_tone_suppress,
  140100. _vp_tonemask_adj_16,
  140101. _vp_tonemask_adj_16,
  140102. _vp_tonemask_adj_16,
  140103. _psy_noiseguards_8,
  140104. _psy_noisebias_16_impulse,
  140105. _psy_noisebias_16_short,
  140106. _psy_noisebias_16_short,
  140107. _psy_noisebias_16,
  140108. _psy_noise_suppress,
  140109. _psy_compand_8,
  140110. _psy_compand_16_mapping,
  140111. _psy_compand_16_mapping,
  140112. {_noise_start_16,_noise_start_16},
  140113. { _noise_part_16, _noise_part_16},
  140114. _noise_thresh_16,
  140115. _psy_ath_floater_16,
  140116. _psy_ath_abs_16,
  140117. _psy_lowpass_16,
  140118. _psy_global_44,
  140119. _global_mapping_16,
  140120. _psy_stereo_modes_16,
  140121. _floor_books,
  140122. _floor,
  140123. _floor_mapping_16_short,
  140124. _floor_mapping_16,
  140125. _mapres_template_16_stereo
  140126. };
  140127. ve_setup_data_template ve_setup_16_uncoupled={
  140128. 3,
  140129. rate_mapping_16_uncoupled,
  140130. quality_mapping_16,
  140131. -1,
  140132. 15000,
  140133. 19000,
  140134. blocksize_16_short,
  140135. blocksize_16_long,
  140136. _psy_tone_masteratt_16,
  140137. _psy_tone_0dB,
  140138. _psy_tone_suppress,
  140139. _vp_tonemask_adj_16,
  140140. _vp_tonemask_adj_16,
  140141. _vp_tonemask_adj_16,
  140142. _psy_noiseguards_8,
  140143. _psy_noisebias_16_impulse,
  140144. _psy_noisebias_16_short,
  140145. _psy_noisebias_16_short,
  140146. _psy_noisebias_16,
  140147. _psy_noise_suppress,
  140148. _psy_compand_8,
  140149. _psy_compand_16_mapping,
  140150. _psy_compand_16_mapping,
  140151. {_noise_start_16,_noise_start_16},
  140152. { _noise_part_16, _noise_part_16},
  140153. _noise_thresh_16,
  140154. _psy_ath_floater_16,
  140155. _psy_ath_abs_16,
  140156. _psy_lowpass_16,
  140157. _psy_global_44,
  140158. _global_mapping_16,
  140159. _psy_stereo_modes_16,
  140160. _floor_books,
  140161. _floor,
  140162. _floor_mapping_16_short,
  140163. _floor_mapping_16,
  140164. _mapres_template_16_uncoupled
  140165. };
  140166. /*** End of inlined file: setup_16.h ***/
  140167. /*** Start of inlined file: setup_22.h ***/
  140168. static double rate_mapping_22[4]={
  140169. 15000.,20000.,44000.,86000.
  140170. };
  140171. static double rate_mapping_22_uncoupled[4]={
  140172. 16000.,28000.,50000.,90000.
  140173. };
  140174. static double _psy_lowpass_22[4]={9.5,11.,30.,99.};
  140175. ve_setup_data_template ve_setup_22_stereo={
  140176. 3,
  140177. rate_mapping_22,
  140178. quality_mapping_16,
  140179. 2,
  140180. 19000,
  140181. 26000,
  140182. blocksize_16_short,
  140183. blocksize_16_long,
  140184. _psy_tone_masteratt_16,
  140185. _psy_tone_0dB,
  140186. _psy_tone_suppress,
  140187. _vp_tonemask_adj_16,
  140188. _vp_tonemask_adj_16,
  140189. _vp_tonemask_adj_16,
  140190. _psy_noiseguards_8,
  140191. _psy_noisebias_16_impulse,
  140192. _psy_noisebias_16_short,
  140193. _psy_noisebias_16_short,
  140194. _psy_noisebias_16,
  140195. _psy_noise_suppress,
  140196. _psy_compand_8,
  140197. _psy_compand_8_mapping,
  140198. _psy_compand_8_mapping,
  140199. {_noise_start_16,_noise_start_16},
  140200. { _noise_part_16, _noise_part_16},
  140201. _noise_thresh_16,
  140202. _psy_ath_floater_16,
  140203. _psy_ath_abs_16,
  140204. _psy_lowpass_22,
  140205. _psy_global_44,
  140206. _global_mapping_16,
  140207. _psy_stereo_modes_16,
  140208. _floor_books,
  140209. _floor,
  140210. _floor_mapping_16_short,
  140211. _floor_mapping_16,
  140212. _mapres_template_16_stereo
  140213. };
  140214. ve_setup_data_template ve_setup_22_uncoupled={
  140215. 3,
  140216. rate_mapping_22_uncoupled,
  140217. quality_mapping_16,
  140218. -1,
  140219. 19000,
  140220. 26000,
  140221. blocksize_16_short,
  140222. blocksize_16_long,
  140223. _psy_tone_masteratt_16,
  140224. _psy_tone_0dB,
  140225. _psy_tone_suppress,
  140226. _vp_tonemask_adj_16,
  140227. _vp_tonemask_adj_16,
  140228. _vp_tonemask_adj_16,
  140229. _psy_noiseguards_8,
  140230. _psy_noisebias_16_impulse,
  140231. _psy_noisebias_16_short,
  140232. _psy_noisebias_16_short,
  140233. _psy_noisebias_16,
  140234. _psy_noise_suppress,
  140235. _psy_compand_8,
  140236. _psy_compand_8_mapping,
  140237. _psy_compand_8_mapping,
  140238. {_noise_start_16,_noise_start_16},
  140239. { _noise_part_16, _noise_part_16},
  140240. _noise_thresh_16,
  140241. _psy_ath_floater_16,
  140242. _psy_ath_abs_16,
  140243. _psy_lowpass_22,
  140244. _psy_global_44,
  140245. _global_mapping_16,
  140246. _psy_stereo_modes_16,
  140247. _floor_books,
  140248. _floor,
  140249. _floor_mapping_16_short,
  140250. _floor_mapping_16,
  140251. _mapres_template_16_uncoupled
  140252. };
  140253. /*** End of inlined file: setup_22.h ***/
  140254. /*** Start of inlined file: setup_X.h ***/
  140255. static double rate_mapping_X[12]={
  140256. -1.,-1.,-1.,-1.,-1.,-1.,
  140257. -1.,-1.,-1.,-1.,-1.,-1.
  140258. };
  140259. ve_setup_data_template ve_setup_X_stereo={
  140260. 11,
  140261. rate_mapping_X,
  140262. quality_mapping_44,
  140263. 2,
  140264. 50000,
  140265. 200000,
  140266. blocksize_short_44,
  140267. blocksize_long_44,
  140268. _psy_tone_masteratt_44,
  140269. _psy_tone_0dB,
  140270. _psy_tone_suppress,
  140271. _vp_tonemask_adj_otherblock,
  140272. _vp_tonemask_adj_longblock,
  140273. _vp_tonemask_adj_otherblock,
  140274. _psy_noiseguards_44,
  140275. _psy_noisebias_impulse,
  140276. _psy_noisebias_padding,
  140277. _psy_noisebias_trans,
  140278. _psy_noisebias_long,
  140279. _psy_noise_suppress,
  140280. _psy_compand_44,
  140281. _psy_compand_short_mapping,
  140282. _psy_compand_long_mapping,
  140283. {_noise_start_short_44,_noise_start_long_44},
  140284. {_noise_part_short_44,_noise_part_long_44},
  140285. _noise_thresh_44,
  140286. _psy_ath_floater,
  140287. _psy_ath_abs,
  140288. _psy_lowpass_44,
  140289. _psy_global_44,
  140290. _global_mapping_44,
  140291. _psy_stereo_modes_44,
  140292. _floor_books,
  140293. _floor,
  140294. _floor_short_mapping_44,
  140295. _floor_long_mapping_44,
  140296. _mapres_template_44_stereo
  140297. };
  140298. ve_setup_data_template ve_setup_X_uncoupled={
  140299. 11,
  140300. rate_mapping_X,
  140301. quality_mapping_44,
  140302. -1,
  140303. 50000,
  140304. 200000,
  140305. blocksize_short_44,
  140306. blocksize_long_44,
  140307. _psy_tone_masteratt_44,
  140308. _psy_tone_0dB,
  140309. _psy_tone_suppress,
  140310. _vp_tonemask_adj_otherblock,
  140311. _vp_tonemask_adj_longblock,
  140312. _vp_tonemask_adj_otherblock,
  140313. _psy_noiseguards_44,
  140314. _psy_noisebias_impulse,
  140315. _psy_noisebias_padding,
  140316. _psy_noisebias_trans,
  140317. _psy_noisebias_long,
  140318. _psy_noise_suppress,
  140319. _psy_compand_44,
  140320. _psy_compand_short_mapping,
  140321. _psy_compand_long_mapping,
  140322. {_noise_start_short_44,_noise_start_long_44},
  140323. {_noise_part_short_44,_noise_part_long_44},
  140324. _noise_thresh_44,
  140325. _psy_ath_floater,
  140326. _psy_ath_abs,
  140327. _psy_lowpass_44,
  140328. _psy_global_44,
  140329. _global_mapping_44,
  140330. NULL,
  140331. _floor_books,
  140332. _floor,
  140333. _floor_short_mapping_44,
  140334. _floor_long_mapping_44,
  140335. _mapres_template_44_uncoupled
  140336. };
  140337. ve_setup_data_template ve_setup_XX_stereo={
  140338. 2,
  140339. rate_mapping_X,
  140340. quality_mapping_8,
  140341. 2,
  140342. 0,
  140343. 8000,
  140344. blocksize_8,
  140345. blocksize_8,
  140346. _psy_tone_masteratt_8,
  140347. _psy_tone_0dB,
  140348. _psy_tone_suppress,
  140349. _vp_tonemask_adj_8,
  140350. NULL,
  140351. _vp_tonemask_adj_8,
  140352. _psy_noiseguards_8,
  140353. _psy_noisebias_8,
  140354. _psy_noisebias_8,
  140355. NULL,
  140356. NULL,
  140357. _psy_noise_suppress,
  140358. _psy_compand_8,
  140359. _psy_compand_8_mapping,
  140360. NULL,
  140361. {_noise_start_8,_noise_start_8},
  140362. {_noise_part_8,_noise_part_8},
  140363. _noise_thresh_5only,
  140364. _psy_ath_floater_8,
  140365. _psy_ath_abs_8,
  140366. _psy_lowpass_8,
  140367. _psy_global_44,
  140368. _global_mapping_8,
  140369. _psy_stereo_modes_8,
  140370. _floor_books,
  140371. _floor,
  140372. _floor_mapping_8,
  140373. NULL,
  140374. _mapres_template_8_stereo
  140375. };
  140376. ve_setup_data_template ve_setup_XX_uncoupled={
  140377. 2,
  140378. rate_mapping_X,
  140379. quality_mapping_8,
  140380. -1,
  140381. 0,
  140382. 8000,
  140383. blocksize_8,
  140384. blocksize_8,
  140385. _psy_tone_masteratt_8,
  140386. _psy_tone_0dB,
  140387. _psy_tone_suppress,
  140388. _vp_tonemask_adj_8,
  140389. NULL,
  140390. _vp_tonemask_adj_8,
  140391. _psy_noiseguards_8,
  140392. _psy_noisebias_8,
  140393. _psy_noisebias_8,
  140394. NULL,
  140395. NULL,
  140396. _psy_noise_suppress,
  140397. _psy_compand_8,
  140398. _psy_compand_8_mapping,
  140399. NULL,
  140400. {_noise_start_8,_noise_start_8},
  140401. {_noise_part_8,_noise_part_8},
  140402. _noise_thresh_5only,
  140403. _psy_ath_floater_8,
  140404. _psy_ath_abs_8,
  140405. _psy_lowpass_8,
  140406. _psy_global_44,
  140407. _global_mapping_8,
  140408. _psy_stereo_modes_8,
  140409. _floor_books,
  140410. _floor,
  140411. _floor_mapping_8,
  140412. NULL,
  140413. _mapres_template_8_uncoupled
  140414. };
  140415. /*** End of inlined file: setup_X.h ***/
  140416. static ve_setup_data_template *setup_list[]={
  140417. &ve_setup_44_stereo,
  140418. &ve_setup_44_uncoupled,
  140419. &ve_setup_32_stereo,
  140420. &ve_setup_32_uncoupled,
  140421. &ve_setup_22_stereo,
  140422. &ve_setup_22_uncoupled,
  140423. &ve_setup_16_stereo,
  140424. &ve_setup_16_uncoupled,
  140425. &ve_setup_11_stereo,
  140426. &ve_setup_11_uncoupled,
  140427. &ve_setup_8_stereo,
  140428. &ve_setup_8_uncoupled,
  140429. &ve_setup_X_stereo,
  140430. &ve_setup_X_uncoupled,
  140431. &ve_setup_XX_stereo,
  140432. &ve_setup_XX_uncoupled,
  140433. 0
  140434. };
  140435. static int vorbis_encode_toplevel_setup(vorbis_info *vi,int ch,long rate){
  140436. if(vi && vi->codec_setup){
  140437. vi->version=0;
  140438. vi->channels=ch;
  140439. vi->rate=rate;
  140440. return(0);
  140441. }
  140442. return(OV_EINVAL);
  140443. }
  140444. static void vorbis_encode_floor_setup(vorbis_info *vi,double s,int block,
  140445. static_codebook ***books,
  140446. vorbis_info_floor1 *in,
  140447. int *x){
  140448. int i,k,is=s;
  140449. vorbis_info_floor1 *f=(vorbis_info_floor1*) _ogg_calloc(1,sizeof(*f));
  140450. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140451. memcpy(f,in+x[is],sizeof(*f));
  140452. f->n=ci->blocksizes[block]>>1;
  140453. {
  140454. int partitions=f->partitions;
  140455. int maxclass=-1;
  140456. int maxbook=-1;
  140457. for(i=0;i<partitions;i++)
  140458. if(f->partitionclass[i]>maxclass)maxclass=f->partitionclass[i];
  140459. for(i=0;i<=maxclass;i++){
  140460. if(f->class_book[i]>maxbook)maxbook=f->class_book[i];
  140461. f->class_book[i]+=ci->books;
  140462. for(k=0;k<(1<<f->class_subs[i]);k++){
  140463. if(f->class_subbook[i][k]>maxbook)maxbook=f->class_subbook[i][k];
  140464. if(f->class_subbook[i][k]>=0)f->class_subbook[i][k]+=ci->books;
  140465. }
  140466. }
  140467. for(i=0;i<=maxbook;i++)
  140468. ci->book_param[ci->books++]=books[x[is]][i];
  140469. }
  140470. ci->floor_type[ci->floors]=1;
  140471. ci->floor_param[ci->floors]=f;
  140472. ci->floors++;
  140473. return;
  140474. }
  140475. static void vorbis_encode_global_psych_setup(vorbis_info *vi,double s,
  140476. vorbis_info_psy_global *in,
  140477. double *x){
  140478. int i,is=s;
  140479. double ds=s-is;
  140480. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140481. vorbis_info_psy_global *g=&ci->psy_g_param;
  140482. memcpy(g,in+(int)x[is],sizeof(*g));
  140483. ds=x[is]*(1.-ds)+x[is+1]*ds;
  140484. is=(int)ds;
  140485. ds-=is;
  140486. if(ds==0 && is>0){
  140487. is--;
  140488. ds=1.;
  140489. }
  140490. for(i=0;i<4;i++){
  140491. g->preecho_thresh[i]=in[is].preecho_thresh[i]*(1.-ds)+in[is+1].preecho_thresh[i]*ds;
  140492. g->postecho_thresh[i]=in[is].postecho_thresh[i]*(1.-ds)+in[is+1].postecho_thresh[i]*ds;
  140493. }
  140494. g->ampmax_att_per_sec=ci->hi.amplitude_track_dBpersec;
  140495. return;
  140496. }
  140497. static void vorbis_encode_global_stereo(vorbis_info *vi,
  140498. highlevel_encode_setup *hi,
  140499. adj_stereo *p){
  140500. float s=hi->stereo_point_setting;
  140501. int i,is=s;
  140502. double ds=s-is;
  140503. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140504. vorbis_info_psy_global *g=&ci->psy_g_param;
  140505. if(p){
  140506. memcpy(g->coupling_prepointamp,p[is].pre,sizeof(*p[is].pre)*PACKETBLOBS);
  140507. memcpy(g->coupling_postpointamp,p[is].post,sizeof(*p[is].post)*PACKETBLOBS);
  140508. if(hi->managed){
  140509. for(i=0;i<PACKETBLOBS;i++){
  140510. float kHz=p[is].kHz[i]*(1.-ds)+p[is+1].kHz[i]*ds;
  140511. g->coupling_pointlimit[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  140512. g->coupling_pointlimit[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  140513. g->coupling_pkHz[i]=kHz;
  140514. kHz=p[is].lowpasskHz[i]*(1.-ds)+p[is+1].lowpasskHz[i]*ds;
  140515. g->sliding_lowpass[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  140516. g->sliding_lowpass[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  140517. }
  140518. }else{
  140519. float kHz=p[is].kHz[PACKETBLOBS/2]*(1.-ds)+p[is+1].kHz[PACKETBLOBS/2]*ds;
  140520. for(i=0;i<PACKETBLOBS;i++){
  140521. g->coupling_pointlimit[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  140522. g->coupling_pointlimit[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  140523. g->coupling_pkHz[i]=kHz;
  140524. }
  140525. kHz=p[is].lowpasskHz[PACKETBLOBS/2]*(1.-ds)+p[is+1].lowpasskHz[PACKETBLOBS/2]*ds;
  140526. for(i=0;i<PACKETBLOBS;i++){
  140527. g->sliding_lowpass[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  140528. g->sliding_lowpass[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  140529. }
  140530. }
  140531. }else{
  140532. for(i=0;i<PACKETBLOBS;i++){
  140533. g->sliding_lowpass[0][i]=ci->blocksizes[0];
  140534. g->sliding_lowpass[1][i]=ci->blocksizes[1];
  140535. }
  140536. }
  140537. return;
  140538. }
  140539. static void vorbis_encode_psyset_setup(vorbis_info *vi,double s,
  140540. int *nn_start,
  140541. int *nn_partition,
  140542. double *nn_thresh,
  140543. int block){
  140544. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140545. vorbis_info_psy *p=ci->psy_param[block];
  140546. highlevel_encode_setup *hi=&ci->hi;
  140547. int is=s;
  140548. if(block>=ci->psys)
  140549. ci->psys=block+1;
  140550. if(!p){
  140551. p=(vorbis_info_psy*)_ogg_calloc(1,sizeof(*p));
  140552. ci->psy_param[block]=p;
  140553. }
  140554. memcpy(p,&_psy_info_template,sizeof(*p));
  140555. p->blockflag=block>>1;
  140556. if(hi->noise_normalize_p){
  140557. p->normal_channel_p=1;
  140558. p->normal_point_p=1;
  140559. p->normal_start=nn_start[is];
  140560. p->normal_partition=nn_partition[is];
  140561. p->normal_thresh=nn_thresh[is];
  140562. }
  140563. return;
  140564. }
  140565. static void vorbis_encode_tonemask_setup(vorbis_info *vi,double s,int block,
  140566. att3 *att,
  140567. int *max,
  140568. vp_adjblock *in){
  140569. int i,is=s;
  140570. double ds=s-is;
  140571. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140572. vorbis_info_psy *p=ci->psy_param[block];
  140573. p->tone_masteratt[0]=att[is].att[0]*(1.-ds)+att[is+1].att[0]*ds;
  140574. p->tone_masteratt[1]=att[is].att[1]*(1.-ds)+att[is+1].att[1]*ds;
  140575. p->tone_masteratt[2]=att[is].att[2]*(1.-ds)+att[is+1].att[2]*ds;
  140576. p->tone_centerboost=att[is].boost*(1.-ds)+att[is+1].boost*ds;
  140577. p->tone_decay=att[is].decay*(1.-ds)+att[is+1].decay*ds;
  140578. p->max_curve_dB=max[is]*(1.-ds)+max[is+1]*ds;
  140579. for(i=0;i<P_BANDS;i++)
  140580. p->toneatt[i]=in[is].block[i]*(1.-ds)+in[is+1].block[i]*ds;
  140581. return;
  140582. }
  140583. static void vorbis_encode_compand_setup(vorbis_info *vi,double s,int block,
  140584. compandblock *in, double *x){
  140585. int i,is=s;
  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. ds=x[is]*(1.-ds)+x[is+1]*ds;
  140590. is=(int)ds;
  140591. ds-=is;
  140592. if(ds==0 && is>0){
  140593. is--;
  140594. ds=1.;
  140595. }
  140596. for(i=0;i<NOISE_COMPAND_LEVELS;i++)
  140597. p->noisecompand[i]=in[is].data[i]*(1.-ds)+in[is+1].data[i]*ds;
  140598. return;
  140599. }
  140600. static void vorbis_encode_peak_setup(vorbis_info *vi,double s,int block,
  140601. int *suppress){
  140602. int is=s;
  140603. double ds=s-is;
  140604. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140605. vorbis_info_psy *p=ci->psy_param[block];
  140606. p->tone_abs_limit=suppress[is]*(1.-ds)+suppress[is+1]*ds;
  140607. return;
  140608. }
  140609. static void vorbis_encode_noisebias_setup(vorbis_info *vi,double s,int block,
  140610. int *suppress,
  140611. noise3 *in,
  140612. noiseguard *guard,
  140613. double userbias){
  140614. int i,is=s,j;
  140615. double ds=s-is;
  140616. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140617. vorbis_info_psy *p=ci->psy_param[block];
  140618. p->noisemaxsupp=suppress[is]*(1.-ds)+suppress[is+1]*ds;
  140619. p->noisewindowlomin=guard[block].lo;
  140620. p->noisewindowhimin=guard[block].hi;
  140621. p->noisewindowfixed=guard[block].fixed;
  140622. for(j=0;j<P_NOISECURVES;j++)
  140623. for(i=0;i<P_BANDS;i++)
  140624. p->noiseoff[j][i]=in[is].data[j][i]*(1.-ds)+in[is+1].data[j][i]*ds;
  140625. for(j=0;j<P_NOISECURVES;j++){
  140626. float min=p->noiseoff[j][0]+6; /* the lowest it can go */
  140627. for(i=0;i<P_BANDS;i++){
  140628. p->noiseoff[j][i]+=userbias;
  140629. if(p->noiseoff[j][i]<min)p->noiseoff[j][i]=min;
  140630. }
  140631. }
  140632. return;
  140633. }
  140634. static void vorbis_encode_ath_setup(vorbis_info *vi,int block){
  140635. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140636. vorbis_info_psy *p=ci->psy_param[block];
  140637. p->ath_adjatt=ci->hi.ath_floating_dB;
  140638. p->ath_maxatt=ci->hi.ath_absolute_dB;
  140639. return;
  140640. }
  140641. static int book_dup_or_new(codec_setup_info *ci,static_codebook *book){
  140642. int i;
  140643. for(i=0;i<ci->books;i++)
  140644. if(ci->book_param[i]==book)return(i);
  140645. return(ci->books++);
  140646. }
  140647. static void vorbis_encode_blocksize_setup(vorbis_info *vi,double s,
  140648. int *shortb,int *longb){
  140649. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140650. int is=s;
  140651. int blockshort=shortb[is];
  140652. int blocklong=longb[is];
  140653. ci->blocksizes[0]=blockshort;
  140654. ci->blocksizes[1]=blocklong;
  140655. }
  140656. static void vorbis_encode_residue_setup(vorbis_info *vi,
  140657. int number, int block,
  140658. vorbis_residue_template *res){
  140659. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140660. int i,n;
  140661. vorbis_info_residue0 *r=(vorbis_info_residue0*)(ci->residue_param[number]=
  140662. (vorbis_info_residue0*)_ogg_malloc(sizeof(*r)));
  140663. memcpy(r,res->res,sizeof(*r));
  140664. if(ci->residues<=number)ci->residues=number+1;
  140665. switch(ci->blocksizes[block]){
  140666. case 64:case 128:case 256:
  140667. r->grouping=16;
  140668. break;
  140669. default:
  140670. r->grouping=32;
  140671. break;
  140672. }
  140673. ci->residue_type[number]=res->res_type;
  140674. n=r->end=ci->blocksizes[block]>>1;
  140675. if(res->res_type==2)
  140676. n=r->end*=vi->channels;
  140677. {
  140678. int booklist=0,k;
  140679. if(ci->hi.managed){
  140680. for(i=0;i<r->partitions;i++)
  140681. for(k=0;k<3;k++)
  140682. if(res->books_base_managed->books[i][k])
  140683. r->secondstages[i]|=(1<<k);
  140684. r->groupbook=book_dup_or_new(ci,res->book_aux_managed);
  140685. ci->book_param[r->groupbook]=res->book_aux_managed;
  140686. for(i=0;i<r->partitions;i++){
  140687. for(k=0;k<3;k++){
  140688. if(res->books_base_managed->books[i][k]){
  140689. int bookid=book_dup_or_new(ci,res->books_base_managed->books[i][k]);
  140690. r->booklist[booklist++]=bookid;
  140691. ci->book_param[bookid]=res->books_base_managed->books[i][k];
  140692. }
  140693. }
  140694. }
  140695. }else{
  140696. for(i=0;i<r->partitions;i++)
  140697. for(k=0;k<3;k++)
  140698. if(res->books_base->books[i][k])
  140699. r->secondstages[i]|=(1<<k);
  140700. r->groupbook=book_dup_or_new(ci,res->book_aux);
  140701. ci->book_param[r->groupbook]=res->book_aux;
  140702. for(i=0;i<r->partitions;i++){
  140703. for(k=0;k<3;k++){
  140704. if(res->books_base->books[i][k]){
  140705. int bookid=book_dup_or_new(ci,res->books_base->books[i][k]);
  140706. r->booklist[booklist++]=bookid;
  140707. ci->book_param[bookid]=res->books_base->books[i][k];
  140708. }
  140709. }
  140710. }
  140711. }
  140712. }
  140713. {
  140714. double freq=ci->hi.lowpass_kHz*1000.;
  140715. vorbis_info_floor1 *f=(vorbis_info_floor1*)ci->floor_param[block]; /* by convention */
  140716. double nyq=vi->rate/2.;
  140717. long blocksize=ci->blocksizes[block]>>1;
  140718. if(freq>nyq)freq=nyq;
  140719. f->n=freq/nyq*blocksize;
  140720. if(res->limit_type){
  140721. if(ci->hi.managed)
  140722. freq=ci->psy_g_param.coupling_pkHz[PACKETBLOBS-1]*1000.;
  140723. else
  140724. freq=ci->psy_g_param.coupling_pkHz[PACKETBLOBS/2]*1000.;
  140725. if(freq>nyq)freq=nyq;
  140726. }
  140727. if(ci->residue_type[block]==2)
  140728. r->end=(int)((freq/nyq*blocksize*2)/r->grouping+.9)* /* round up only if we're well past */
  140729. r->grouping;
  140730. else
  140731. r->end=(int)((freq/nyq*blocksize)/r->grouping+.9)* /* round up only if we're well past */
  140732. r->grouping;
  140733. }
  140734. }
  140735. static void vorbis_encode_map_n_res_setup(vorbis_info *vi,double s,
  140736. vorbis_mapping_template *maps){
  140737. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140738. int i,j,is=s,modes=2;
  140739. vorbis_info_mapping0 *map=maps[is].map;
  140740. vorbis_info_mode *mode=_mode_template;
  140741. vorbis_residue_template *res=maps[is].res;
  140742. if(ci->blocksizes[0]==ci->blocksizes[1])modes=1;
  140743. for(i=0;i<modes;i++){
  140744. ci->map_param[i]=_ogg_calloc(1,sizeof(*map));
  140745. ci->mode_param[i]=(vorbis_info_mode*)_ogg_calloc(1,sizeof(*mode));
  140746. memcpy(ci->mode_param[i],mode+i,sizeof(*_mode_template));
  140747. if(i>=ci->modes)ci->modes=i+1;
  140748. ci->map_type[i]=0;
  140749. memcpy(ci->map_param[i],map+i,sizeof(*map));
  140750. if(i>=ci->maps)ci->maps=i+1;
  140751. for(j=0;j<map[i].submaps;j++)
  140752. vorbis_encode_residue_setup(vi,map[i].residuesubmap[j],i
  140753. ,res+map[i].residuesubmap[j]);
  140754. }
  140755. }
  140756. static double setting_to_approx_bitrate(vorbis_info *vi){
  140757. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140758. highlevel_encode_setup *hi=&ci->hi;
  140759. ve_setup_data_template *setup=(ve_setup_data_template *)hi->setup;
  140760. int is=hi->base_setting;
  140761. double ds=hi->base_setting-is;
  140762. int ch=vi->channels;
  140763. double *r=setup->rate_mapping;
  140764. if(r==NULL)
  140765. return(-1);
  140766. return((r[is]*(1.-ds)+r[is+1]*ds)*ch);
  140767. }
  140768. static void get_setup_template(vorbis_info *vi,
  140769. long ch,long srate,
  140770. double req,int q_or_bitrate){
  140771. int i=0,j;
  140772. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140773. highlevel_encode_setup *hi=&ci->hi;
  140774. if(q_or_bitrate)req/=ch;
  140775. while(setup_list[i]){
  140776. if(setup_list[i]->coupling_restriction==-1 ||
  140777. setup_list[i]->coupling_restriction==ch){
  140778. if(srate>=setup_list[i]->samplerate_min_restriction &&
  140779. srate<=setup_list[i]->samplerate_max_restriction){
  140780. int mappings=setup_list[i]->mappings;
  140781. double *map=(q_or_bitrate?
  140782. setup_list[i]->rate_mapping:
  140783. setup_list[i]->quality_mapping);
  140784. if(req<map[0]){++i;continue;}
  140785. if(req>map[setup_list[i]->mappings]){++i;continue;}
  140786. for(j=0;j<mappings;j++)
  140787. if(req>=map[j] && req<map[j+1])break;
  140788. hi->setup=setup_list[i];
  140789. if(j==mappings)
  140790. hi->base_setting=j-.001;
  140791. else{
  140792. float low=map[j];
  140793. float high=map[j+1];
  140794. float del=(req-low)/(high-low);
  140795. hi->base_setting=j+del;
  140796. }
  140797. return;
  140798. }
  140799. }
  140800. i++;
  140801. }
  140802. hi->setup=NULL;
  140803. }
  140804. int vorbis_encode_setup_init(vorbis_info *vi){
  140805. int i0=0,singleblock=0;
  140806. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140807. ve_setup_data_template *setup=NULL;
  140808. highlevel_encode_setup *hi=&ci->hi;
  140809. if(ci==NULL)return(OV_EINVAL);
  140810. if(!hi->impulse_block_p)i0=1;
  140811. if(hi->ath_floating_dB>-80)hi->ath_floating_dB=-80;
  140812. if(hi->ath_floating_dB<-200)hi->ath_floating_dB=-200;
  140813. if(hi->amplitude_track_dBpersec>0.)hi->amplitude_track_dBpersec=0.;
  140814. if(hi->amplitude_track_dBpersec<-99999.)hi->amplitude_track_dBpersec=-99999.;
  140815. setup=(ve_setup_data_template *)hi->setup;
  140816. if(setup==NULL)return(OV_EINVAL);
  140817. hi->set_in_stone=1;
  140818. vorbis_encode_blocksize_setup(vi,hi->base_setting,
  140819. setup->blocksize_short,
  140820. setup->blocksize_long);
  140821. if(ci->blocksizes[0]==ci->blocksizes[1])singleblock=1;
  140822. vorbis_encode_floor_setup(vi,hi->short_setting,0,
  140823. setup->floor_books,
  140824. setup->floor_params,
  140825. setup->floor_short_mapping);
  140826. if(!singleblock)
  140827. vorbis_encode_floor_setup(vi,hi->long_setting,1,
  140828. setup->floor_books,
  140829. setup->floor_params,
  140830. setup->floor_long_mapping);
  140831. vorbis_encode_global_psych_setup(vi,hi->trigger_setting,
  140832. setup->global_params,
  140833. setup->global_mapping);
  140834. vorbis_encode_global_stereo(vi,hi,setup->stereo_modes);
  140835. vorbis_encode_psyset_setup(vi,hi->short_setting,
  140836. setup->psy_noise_normal_start[0],
  140837. setup->psy_noise_normal_partition[0],
  140838. setup->psy_noise_normal_thresh,
  140839. 0);
  140840. vorbis_encode_psyset_setup(vi,hi->short_setting,
  140841. setup->psy_noise_normal_start[0],
  140842. setup->psy_noise_normal_partition[0],
  140843. setup->psy_noise_normal_thresh,
  140844. 1);
  140845. if(!singleblock){
  140846. vorbis_encode_psyset_setup(vi,hi->long_setting,
  140847. setup->psy_noise_normal_start[1],
  140848. setup->psy_noise_normal_partition[1],
  140849. setup->psy_noise_normal_thresh,
  140850. 2);
  140851. vorbis_encode_psyset_setup(vi,hi->long_setting,
  140852. setup->psy_noise_normal_start[1],
  140853. setup->psy_noise_normal_partition[1],
  140854. setup->psy_noise_normal_thresh,
  140855. 3);
  140856. }
  140857. vorbis_encode_tonemask_setup(vi,hi->block[i0].tone_mask_setting,0,
  140858. setup->psy_tone_masteratt,
  140859. setup->psy_tone_0dB,
  140860. setup->psy_tone_adj_impulse);
  140861. vorbis_encode_tonemask_setup(vi,hi->block[1].tone_mask_setting,1,
  140862. setup->psy_tone_masteratt,
  140863. setup->psy_tone_0dB,
  140864. setup->psy_tone_adj_other);
  140865. if(!singleblock){
  140866. vorbis_encode_tonemask_setup(vi,hi->block[2].tone_mask_setting,2,
  140867. setup->psy_tone_masteratt,
  140868. setup->psy_tone_0dB,
  140869. setup->psy_tone_adj_other);
  140870. vorbis_encode_tonemask_setup(vi,hi->block[3].tone_mask_setting,3,
  140871. setup->psy_tone_masteratt,
  140872. setup->psy_tone_0dB,
  140873. setup->psy_tone_adj_long);
  140874. }
  140875. vorbis_encode_compand_setup(vi,hi->block[i0].noise_compand_setting,0,
  140876. setup->psy_noise_compand,
  140877. setup->psy_noise_compand_short_mapping);
  140878. vorbis_encode_compand_setup(vi,hi->block[1].noise_compand_setting,1,
  140879. setup->psy_noise_compand,
  140880. setup->psy_noise_compand_short_mapping);
  140881. if(!singleblock){
  140882. vorbis_encode_compand_setup(vi,hi->block[2].noise_compand_setting,2,
  140883. setup->psy_noise_compand,
  140884. setup->psy_noise_compand_long_mapping);
  140885. vorbis_encode_compand_setup(vi,hi->block[3].noise_compand_setting,3,
  140886. setup->psy_noise_compand,
  140887. setup->psy_noise_compand_long_mapping);
  140888. }
  140889. vorbis_encode_peak_setup(vi,hi->block[i0].tone_peaklimit_setting,0,
  140890. setup->psy_tone_dBsuppress);
  140891. vorbis_encode_peak_setup(vi,hi->block[1].tone_peaklimit_setting,1,
  140892. setup->psy_tone_dBsuppress);
  140893. if(!singleblock){
  140894. vorbis_encode_peak_setup(vi,hi->block[2].tone_peaklimit_setting,2,
  140895. setup->psy_tone_dBsuppress);
  140896. vorbis_encode_peak_setup(vi,hi->block[3].tone_peaklimit_setting,3,
  140897. setup->psy_tone_dBsuppress);
  140898. }
  140899. vorbis_encode_noisebias_setup(vi,hi->block[i0].noise_bias_setting,0,
  140900. setup->psy_noise_dBsuppress,
  140901. setup->psy_noise_bias_impulse,
  140902. setup->psy_noiseguards,
  140903. (i0==0?hi->impulse_noisetune:0.));
  140904. vorbis_encode_noisebias_setup(vi,hi->block[1].noise_bias_setting,1,
  140905. setup->psy_noise_dBsuppress,
  140906. setup->psy_noise_bias_padding,
  140907. setup->psy_noiseguards,0.);
  140908. if(!singleblock){
  140909. vorbis_encode_noisebias_setup(vi,hi->block[2].noise_bias_setting,2,
  140910. setup->psy_noise_dBsuppress,
  140911. setup->psy_noise_bias_trans,
  140912. setup->psy_noiseguards,0.);
  140913. vorbis_encode_noisebias_setup(vi,hi->block[3].noise_bias_setting,3,
  140914. setup->psy_noise_dBsuppress,
  140915. setup->psy_noise_bias_long,
  140916. setup->psy_noiseguards,0.);
  140917. }
  140918. vorbis_encode_ath_setup(vi,0);
  140919. vorbis_encode_ath_setup(vi,1);
  140920. if(!singleblock){
  140921. vorbis_encode_ath_setup(vi,2);
  140922. vorbis_encode_ath_setup(vi,3);
  140923. }
  140924. vorbis_encode_map_n_res_setup(vi,hi->base_setting,setup->maps);
  140925. if(hi->bitrate_av>0)
  140926. vi->bitrate_nominal=hi->bitrate_av;
  140927. else{
  140928. vi->bitrate_nominal=setting_to_approx_bitrate(vi);
  140929. }
  140930. vi->bitrate_lower=hi->bitrate_min;
  140931. vi->bitrate_upper=hi->bitrate_max;
  140932. if(hi->bitrate_av)
  140933. vi->bitrate_window=(double)hi->bitrate_reservoir/hi->bitrate_av;
  140934. else
  140935. vi->bitrate_window=0.;
  140936. if(hi->managed){
  140937. ci->bi.avg_rate=hi->bitrate_av;
  140938. ci->bi.min_rate=hi->bitrate_min;
  140939. ci->bi.max_rate=hi->bitrate_max;
  140940. ci->bi.reservoir_bits=hi->bitrate_reservoir;
  140941. ci->bi.reservoir_bias=
  140942. hi->bitrate_reservoir_bias;
  140943. ci->bi.slew_damp=hi->bitrate_av_damp;
  140944. }
  140945. return(0);
  140946. }
  140947. static int vorbis_encode_setup_setting(vorbis_info *vi,
  140948. long channels,
  140949. long rate){
  140950. int ret=0,i,is;
  140951. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140952. highlevel_encode_setup *hi=&ci->hi;
  140953. ve_setup_data_template *setup=(ve_setup_data_template*) hi->setup;
  140954. double ds;
  140955. ret=vorbis_encode_toplevel_setup(vi,channels,rate);
  140956. if(ret)return(ret);
  140957. is=hi->base_setting;
  140958. ds=hi->base_setting-is;
  140959. hi->short_setting=hi->base_setting;
  140960. hi->long_setting=hi->base_setting;
  140961. hi->managed=0;
  140962. hi->impulse_block_p=1;
  140963. hi->noise_normalize_p=1;
  140964. hi->stereo_point_setting=hi->base_setting;
  140965. hi->lowpass_kHz=
  140966. setup->psy_lowpass[is]*(1.-ds)+setup->psy_lowpass[is+1]*ds;
  140967. hi->ath_floating_dB=setup->psy_ath_float[is]*(1.-ds)+
  140968. setup->psy_ath_float[is+1]*ds;
  140969. hi->ath_absolute_dB=setup->psy_ath_abs[is]*(1.-ds)+
  140970. setup->psy_ath_abs[is+1]*ds;
  140971. hi->amplitude_track_dBpersec=-6.;
  140972. hi->trigger_setting=hi->base_setting;
  140973. for(i=0;i<4;i++){
  140974. hi->block[i].tone_mask_setting=hi->base_setting;
  140975. hi->block[i].tone_peaklimit_setting=hi->base_setting;
  140976. hi->block[i].noise_bias_setting=hi->base_setting;
  140977. hi->block[i].noise_compand_setting=hi->base_setting;
  140978. }
  140979. return(ret);
  140980. }
  140981. int vorbis_encode_setup_vbr(vorbis_info *vi,
  140982. long channels,
  140983. long rate,
  140984. float quality){
  140985. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140986. highlevel_encode_setup *hi=&ci->hi;
  140987. quality+=.0000001;
  140988. if(quality>=1.)quality=.9999;
  140989. get_setup_template(vi,channels,rate,quality,0);
  140990. if(!hi->setup)return OV_EIMPL;
  140991. return vorbis_encode_setup_setting(vi,channels,rate);
  140992. }
  140993. int vorbis_encode_init_vbr(vorbis_info *vi,
  140994. long channels,
  140995. long rate,
  140996. float base_quality /* 0. to 1. */
  140997. ){
  140998. int ret=0;
  140999. ret=vorbis_encode_setup_vbr(vi,channels,rate,base_quality);
  141000. if(ret){
  141001. vorbis_info_clear(vi);
  141002. return ret;
  141003. }
  141004. ret=vorbis_encode_setup_init(vi);
  141005. if(ret)
  141006. vorbis_info_clear(vi);
  141007. return(ret);
  141008. }
  141009. int vorbis_encode_setup_managed(vorbis_info *vi,
  141010. long channels,
  141011. long rate,
  141012. long max_bitrate,
  141013. long nominal_bitrate,
  141014. long min_bitrate){
  141015. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  141016. highlevel_encode_setup *hi=&ci->hi;
  141017. double tnominal=nominal_bitrate;
  141018. int ret=0;
  141019. if(nominal_bitrate<=0.){
  141020. if(max_bitrate>0.){
  141021. if(min_bitrate>0.)
  141022. nominal_bitrate=(max_bitrate+min_bitrate)*.5;
  141023. else
  141024. nominal_bitrate=max_bitrate*.875;
  141025. }else{
  141026. if(min_bitrate>0.){
  141027. nominal_bitrate=min_bitrate;
  141028. }else{
  141029. return(OV_EINVAL);
  141030. }
  141031. }
  141032. }
  141033. get_setup_template(vi,channels,rate,nominal_bitrate,1);
  141034. if(!hi->setup)return OV_EIMPL;
  141035. ret=vorbis_encode_setup_setting(vi,channels,rate);
  141036. if(ret){
  141037. vorbis_info_clear(vi);
  141038. return ret;
  141039. }
  141040. hi->managed=1;
  141041. hi->bitrate_min=min_bitrate;
  141042. hi->bitrate_max=max_bitrate;
  141043. hi->bitrate_av=tnominal;
  141044. hi->bitrate_av_damp=1.5f; /* full range in no less than 1.5 second */
  141045. hi->bitrate_reservoir=nominal_bitrate*2;
  141046. hi->bitrate_reservoir_bias=.1; /* bias toward hoarding bits */
  141047. return(ret);
  141048. }
  141049. int vorbis_encode_init(vorbis_info *vi,
  141050. long channels,
  141051. long rate,
  141052. long max_bitrate,
  141053. long nominal_bitrate,
  141054. long min_bitrate){
  141055. int ret=vorbis_encode_setup_managed(vi,channels,rate,
  141056. max_bitrate,
  141057. nominal_bitrate,
  141058. min_bitrate);
  141059. if(ret){
  141060. vorbis_info_clear(vi);
  141061. return(ret);
  141062. }
  141063. ret=vorbis_encode_setup_init(vi);
  141064. if(ret)
  141065. vorbis_info_clear(vi);
  141066. return(ret);
  141067. }
  141068. int vorbis_encode_ctl(vorbis_info *vi,int number,void *arg){
  141069. if(vi){
  141070. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  141071. highlevel_encode_setup *hi=&ci->hi;
  141072. int setp=(number&0xf); /* a read request has a low nibble of 0 */
  141073. if(setp && hi->set_in_stone)return(OV_EINVAL);
  141074. switch(number){
  141075. case OV_ECTL_RATEMANAGE_GET:
  141076. {
  141077. struct ovectl_ratemanage_arg *ai=
  141078. (struct ovectl_ratemanage_arg *)arg;
  141079. ai->management_active=hi->managed;
  141080. ai->bitrate_hard_window=ai->bitrate_av_window=
  141081. (double)hi->bitrate_reservoir/vi->rate;
  141082. ai->bitrate_av_window_center=1.;
  141083. ai->bitrate_hard_min=hi->bitrate_min;
  141084. ai->bitrate_hard_max=hi->bitrate_max;
  141085. ai->bitrate_av_lo=hi->bitrate_av;
  141086. ai->bitrate_av_hi=hi->bitrate_av;
  141087. }
  141088. return(0);
  141089. case OV_ECTL_RATEMANAGE_SET:
  141090. {
  141091. struct ovectl_ratemanage_arg *ai=
  141092. (struct ovectl_ratemanage_arg *)arg;
  141093. if(ai==NULL){
  141094. hi->managed=0;
  141095. }else{
  141096. hi->managed=ai->management_active;
  141097. vorbis_encode_ctl(vi,OV_ECTL_RATEMANAGE_AVG,arg);
  141098. vorbis_encode_ctl(vi,OV_ECTL_RATEMANAGE_HARD,arg);
  141099. }
  141100. }
  141101. return 0;
  141102. case OV_ECTL_RATEMANAGE_AVG:
  141103. {
  141104. struct ovectl_ratemanage_arg *ai=
  141105. (struct ovectl_ratemanage_arg *)arg;
  141106. if(ai==NULL){
  141107. hi->bitrate_av=0;
  141108. }else{
  141109. hi->bitrate_av=(ai->bitrate_av_lo+ai->bitrate_av_hi)*.5;
  141110. }
  141111. }
  141112. return(0);
  141113. case OV_ECTL_RATEMANAGE_HARD:
  141114. {
  141115. struct ovectl_ratemanage_arg *ai=
  141116. (struct ovectl_ratemanage_arg *)arg;
  141117. if(ai==NULL){
  141118. hi->bitrate_min=0;
  141119. hi->bitrate_max=0;
  141120. }else{
  141121. hi->bitrate_min=ai->bitrate_hard_min;
  141122. hi->bitrate_max=ai->bitrate_hard_max;
  141123. hi->bitrate_reservoir=ai->bitrate_hard_window*
  141124. (hi->bitrate_max+hi->bitrate_min)*.5;
  141125. }
  141126. if(hi->bitrate_reservoir<128.)
  141127. hi->bitrate_reservoir=128.;
  141128. }
  141129. return(0);
  141130. case OV_ECTL_RATEMANAGE2_GET:
  141131. {
  141132. struct ovectl_ratemanage2_arg *ai=
  141133. (struct ovectl_ratemanage2_arg *)arg;
  141134. if(ai==NULL)return OV_EINVAL;
  141135. ai->management_active=hi->managed;
  141136. ai->bitrate_limit_min_kbps=hi->bitrate_min/1000;
  141137. ai->bitrate_limit_max_kbps=hi->bitrate_max/1000;
  141138. ai->bitrate_average_kbps=hi->bitrate_av/1000;
  141139. ai->bitrate_average_damping=hi->bitrate_av_damp;
  141140. ai->bitrate_limit_reservoir_bits=hi->bitrate_reservoir;
  141141. ai->bitrate_limit_reservoir_bias=hi->bitrate_reservoir_bias;
  141142. }
  141143. return (0);
  141144. case OV_ECTL_RATEMANAGE2_SET:
  141145. {
  141146. struct ovectl_ratemanage2_arg *ai=
  141147. (struct ovectl_ratemanage2_arg *)arg;
  141148. if(ai==NULL){
  141149. hi->managed=0;
  141150. }else{
  141151. if(ai->bitrate_limit_min_kbps>0 &&
  141152. ai->bitrate_average_kbps>0 &&
  141153. ai->bitrate_limit_min_kbps>ai->bitrate_average_kbps)
  141154. return OV_EINVAL;
  141155. if(ai->bitrate_limit_max_kbps>0 &&
  141156. ai->bitrate_average_kbps>0 &&
  141157. ai->bitrate_limit_max_kbps<ai->bitrate_average_kbps)
  141158. return OV_EINVAL;
  141159. if(ai->bitrate_limit_min_kbps>0 &&
  141160. ai->bitrate_limit_max_kbps>0 &&
  141161. ai->bitrate_limit_min_kbps>ai->bitrate_limit_max_kbps)
  141162. return OV_EINVAL;
  141163. if(ai->bitrate_average_damping <= 0.)
  141164. return OV_EINVAL;
  141165. if(ai->bitrate_limit_reservoir_bits < 0)
  141166. return OV_EINVAL;
  141167. if(ai->bitrate_limit_reservoir_bias < 0.)
  141168. return OV_EINVAL;
  141169. if(ai->bitrate_limit_reservoir_bias > 1.)
  141170. return OV_EINVAL;
  141171. hi->managed=ai->management_active;
  141172. hi->bitrate_min=ai->bitrate_limit_min_kbps * 1000;
  141173. hi->bitrate_max=ai->bitrate_limit_max_kbps * 1000;
  141174. hi->bitrate_av=ai->bitrate_average_kbps * 1000;
  141175. hi->bitrate_av_damp=ai->bitrate_average_damping;
  141176. hi->bitrate_reservoir=ai->bitrate_limit_reservoir_bits;
  141177. hi->bitrate_reservoir_bias=ai->bitrate_limit_reservoir_bias;
  141178. }
  141179. }
  141180. return 0;
  141181. case OV_ECTL_LOWPASS_GET:
  141182. {
  141183. double *farg=(double *)arg;
  141184. *farg=hi->lowpass_kHz;
  141185. }
  141186. return(0);
  141187. case OV_ECTL_LOWPASS_SET:
  141188. {
  141189. double *farg=(double *)arg;
  141190. hi->lowpass_kHz=*farg;
  141191. if(hi->lowpass_kHz<2.)hi->lowpass_kHz=2.;
  141192. if(hi->lowpass_kHz>99.)hi->lowpass_kHz=99.;
  141193. }
  141194. return(0);
  141195. case OV_ECTL_IBLOCK_GET:
  141196. {
  141197. double *farg=(double *)arg;
  141198. *farg=hi->impulse_noisetune;
  141199. }
  141200. return(0);
  141201. case OV_ECTL_IBLOCK_SET:
  141202. {
  141203. double *farg=(double *)arg;
  141204. hi->impulse_noisetune=*farg;
  141205. if(hi->impulse_noisetune>0.)hi->impulse_noisetune=0.;
  141206. if(hi->impulse_noisetune<-15.)hi->impulse_noisetune=-15.;
  141207. }
  141208. return(0);
  141209. }
  141210. return(OV_EIMPL);
  141211. }
  141212. return(OV_EINVAL);
  141213. }
  141214. #endif
  141215. /*** End of inlined file: vorbisenc.c ***/
  141216. /*** Start of inlined file: vorbisfile.c ***/
  141217. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  141218. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  141219. // tasks..
  141220. #if JUCE_MSVC
  141221. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  141222. #endif
  141223. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  141224. #if JUCE_USE_OGGVORBIS
  141225. #include <stdlib.h>
  141226. #include <stdio.h>
  141227. #include <errno.h>
  141228. #include <string.h>
  141229. #include <math.h>
  141230. #define CHUNKSIZE 8500 /* a shade over 8k; anyone using pages well
  141231. over 8k gets what they deserve */
  141232. static long _get_data(OggVorbis_File *vf){
  141233. errno=0;
  141234. if(vf->datasource){
  141235. char *buffer=ogg_sync_buffer(&vf->oy,CHUNKSIZE);
  141236. long bytes=(vf->callbacks.read_func)(buffer,1,CHUNKSIZE,vf->datasource);
  141237. if(bytes>0)ogg_sync_wrote(&vf->oy,bytes);
  141238. if(bytes==0 && errno)return(-1);
  141239. return(bytes);
  141240. }else
  141241. return(0);
  141242. }
  141243. static void _seek_helper(OggVorbis_File *vf,ogg_int64_t offset){
  141244. if(vf->datasource){
  141245. (vf->callbacks.seek_func)(vf->datasource, offset, SEEK_SET);
  141246. vf->offset=offset;
  141247. ogg_sync_reset(&vf->oy);
  141248. }else{
  141249. return;
  141250. }
  141251. }
  141252. static ogg_int64_t _get_next_page(OggVorbis_File *vf,ogg_page *og,
  141253. ogg_int64_t boundary){
  141254. if(boundary>0)boundary+=vf->offset;
  141255. while(1){
  141256. long more;
  141257. if(boundary>0 && vf->offset>=boundary)return(OV_FALSE);
  141258. more=ogg_sync_pageseek(&vf->oy,og);
  141259. if(more<0){
  141260. vf->offset-=more;
  141261. }else{
  141262. if(more==0){
  141263. if(!boundary)return(OV_FALSE);
  141264. {
  141265. long ret=_get_data(vf);
  141266. if(ret==0)return(OV_EOF);
  141267. if(ret<0)return(OV_EREAD);
  141268. }
  141269. }else{
  141270. ogg_int64_t ret=vf->offset;
  141271. vf->offset+=more;
  141272. return(ret);
  141273. }
  141274. }
  141275. }
  141276. }
  141277. static ogg_int64_t _get_prev_page(OggVorbis_File *vf,ogg_page *og){
  141278. ogg_int64_t begin=vf->offset;
  141279. ogg_int64_t end=begin;
  141280. ogg_int64_t ret;
  141281. ogg_int64_t offset=-1;
  141282. while(offset==-1){
  141283. begin-=CHUNKSIZE;
  141284. if(begin<0)
  141285. begin=0;
  141286. _seek_helper(vf,begin);
  141287. while(vf->offset<end){
  141288. ret=_get_next_page(vf,og,end-vf->offset);
  141289. if(ret==OV_EREAD)return(OV_EREAD);
  141290. if(ret<0){
  141291. break;
  141292. }else{
  141293. offset=ret;
  141294. }
  141295. }
  141296. }
  141297. _seek_helper(vf,offset);
  141298. ret=_get_next_page(vf,og,CHUNKSIZE);
  141299. if(ret<0)
  141300. return(OV_EFAULT);
  141301. return(offset);
  141302. }
  141303. static int _bisect_forward_serialno(OggVorbis_File *vf,
  141304. ogg_int64_t begin,
  141305. ogg_int64_t searched,
  141306. ogg_int64_t end,
  141307. long currentno,
  141308. long m){
  141309. ogg_int64_t endsearched=end;
  141310. ogg_int64_t next=end;
  141311. ogg_page og;
  141312. ogg_int64_t ret;
  141313. while(searched<endsearched){
  141314. ogg_int64_t bisect;
  141315. if(endsearched-searched<CHUNKSIZE){
  141316. bisect=searched;
  141317. }else{
  141318. bisect=(searched+endsearched)/2;
  141319. }
  141320. _seek_helper(vf,bisect);
  141321. ret=_get_next_page(vf,&og,-1);
  141322. if(ret==OV_EREAD)return(OV_EREAD);
  141323. if(ret<0 || ogg_page_serialno(&og)!=currentno){
  141324. endsearched=bisect;
  141325. if(ret>=0)next=ret;
  141326. }else{
  141327. searched=ret+og.header_len+og.body_len;
  141328. }
  141329. }
  141330. _seek_helper(vf,next);
  141331. ret=_get_next_page(vf,&og,-1);
  141332. if(ret==OV_EREAD)return(OV_EREAD);
  141333. if(searched>=end || ret<0){
  141334. vf->links=m+1;
  141335. vf->offsets=(ogg_int64_t*)_ogg_malloc((vf->links+1)*sizeof(*vf->offsets));
  141336. vf->serialnos=(long*)_ogg_malloc(vf->links*sizeof(*vf->serialnos));
  141337. vf->offsets[m+1]=searched;
  141338. }else{
  141339. ret=_bisect_forward_serialno(vf,next,vf->offset,
  141340. end,ogg_page_serialno(&og),m+1);
  141341. if(ret==OV_EREAD)return(OV_EREAD);
  141342. }
  141343. vf->offsets[m]=begin;
  141344. vf->serialnos[m]=currentno;
  141345. return(0);
  141346. }
  141347. static int _fetch_headers(OggVorbis_File *vf,vorbis_info *vi,vorbis_comment *vc,
  141348. long *serialno,ogg_page *og_ptr){
  141349. ogg_page og;
  141350. ogg_packet op;
  141351. int i,ret;
  141352. if(!og_ptr){
  141353. ogg_int64_t llret=_get_next_page(vf,&og,CHUNKSIZE);
  141354. if(llret==OV_EREAD)return(OV_EREAD);
  141355. if(llret<0)return OV_ENOTVORBIS;
  141356. og_ptr=&og;
  141357. }
  141358. ogg_stream_reset_serialno(&vf->os,ogg_page_serialno(og_ptr));
  141359. if(serialno)*serialno=vf->os.serialno;
  141360. vf->ready_state=STREAMSET;
  141361. vorbis_info_init(vi);
  141362. vorbis_comment_init(vc);
  141363. i=0;
  141364. while(i<3){
  141365. ogg_stream_pagein(&vf->os,og_ptr);
  141366. while(i<3){
  141367. int result=ogg_stream_packetout(&vf->os,&op);
  141368. if(result==0)break;
  141369. if(result==-1){
  141370. ret=OV_EBADHEADER;
  141371. goto bail_header;
  141372. }
  141373. if((ret=vorbis_synthesis_headerin(vi,vc,&op))){
  141374. goto bail_header;
  141375. }
  141376. i++;
  141377. }
  141378. if(i<3)
  141379. if(_get_next_page(vf,og_ptr,CHUNKSIZE)<0){
  141380. ret=OV_EBADHEADER;
  141381. goto bail_header;
  141382. }
  141383. }
  141384. return 0;
  141385. bail_header:
  141386. vorbis_info_clear(vi);
  141387. vorbis_comment_clear(vc);
  141388. vf->ready_state=OPENED;
  141389. return ret;
  141390. }
  141391. static void _prefetch_all_headers(OggVorbis_File *vf, ogg_int64_t dataoffset){
  141392. ogg_page og;
  141393. int i;
  141394. ogg_int64_t ret;
  141395. vf->vi=(vorbis_info*) _ogg_realloc(vf->vi,vf->links*sizeof(*vf->vi));
  141396. vf->vc=(vorbis_comment*) _ogg_realloc(vf->vc,vf->links*sizeof(*vf->vc));
  141397. vf->dataoffsets=(ogg_int64_t*) _ogg_malloc(vf->links*sizeof(*vf->dataoffsets));
  141398. vf->pcmlengths=(ogg_int64_t*) _ogg_malloc(vf->links*2*sizeof(*vf->pcmlengths));
  141399. for(i=0;i<vf->links;i++){
  141400. if(i==0){
  141401. vf->dataoffsets[i]=dataoffset;
  141402. _seek_helper(vf,dataoffset);
  141403. }else{
  141404. _seek_helper(vf,vf->offsets[i]);
  141405. if(_fetch_headers(vf,vf->vi+i,vf->vc+i,NULL,NULL)<0){
  141406. vf->dataoffsets[i]=-1;
  141407. }else{
  141408. vf->dataoffsets[i]=vf->offset;
  141409. }
  141410. }
  141411. if(vf->dataoffsets[i]!=-1){
  141412. ogg_int64_t accumulated=0;
  141413. long lastblock=-1;
  141414. int result;
  141415. ogg_stream_reset_serialno(&vf->os,vf->serialnos[i]);
  141416. while(1){
  141417. ogg_packet op;
  141418. ret=_get_next_page(vf,&og,-1);
  141419. if(ret<0)
  141420. break;
  141421. if(ogg_page_serialno(&og)!=vf->serialnos[i])
  141422. break;
  141423. ogg_stream_pagein(&vf->os,&og);
  141424. while((result=ogg_stream_packetout(&vf->os,&op))){
  141425. if(result>0){ /* ignore holes */
  141426. long thisblock=vorbis_packet_blocksize(vf->vi+i,&op);
  141427. if(lastblock!=-1)
  141428. accumulated+=(lastblock+thisblock)>>2;
  141429. lastblock=thisblock;
  141430. }
  141431. }
  141432. if(ogg_page_granulepos(&og)!=-1){
  141433. accumulated= ogg_page_granulepos(&og)-accumulated;
  141434. break;
  141435. }
  141436. }
  141437. if(accumulated<0)accumulated=0;
  141438. vf->pcmlengths[i*2]=accumulated;
  141439. }
  141440. {
  141441. ogg_int64_t end=vf->offsets[i+1];
  141442. _seek_helper(vf,end);
  141443. while(1){
  141444. ret=_get_prev_page(vf,&og);
  141445. if(ret<0){
  141446. vorbis_info_clear(vf->vi+i);
  141447. vorbis_comment_clear(vf->vc+i);
  141448. break;
  141449. }
  141450. if(ogg_page_granulepos(&og)!=-1){
  141451. vf->pcmlengths[i*2+1]=ogg_page_granulepos(&og)-vf->pcmlengths[i*2];
  141452. break;
  141453. }
  141454. vf->offset=ret;
  141455. }
  141456. }
  141457. }
  141458. }
  141459. static int _make_decode_ready(OggVorbis_File *vf){
  141460. if(vf->ready_state>STREAMSET)return 0;
  141461. if(vf->ready_state<STREAMSET)return OV_EFAULT;
  141462. if(vf->seekable){
  141463. if(vorbis_synthesis_init(&vf->vd,vf->vi+vf->current_link))
  141464. return OV_EBADLINK;
  141465. }else{
  141466. if(vorbis_synthesis_init(&vf->vd,vf->vi))
  141467. return OV_EBADLINK;
  141468. }
  141469. vorbis_block_init(&vf->vd,&vf->vb);
  141470. vf->ready_state=INITSET;
  141471. vf->bittrack=0.f;
  141472. vf->samptrack=0.f;
  141473. return 0;
  141474. }
  141475. static int _open_seekable2(OggVorbis_File *vf){
  141476. long serialno=vf->current_serialno;
  141477. ogg_int64_t dataoffset=vf->offset, end;
  141478. ogg_page og;
  141479. (vf->callbacks.seek_func)(vf->datasource,0,SEEK_END);
  141480. vf->offset=vf->end=(vf->callbacks.tell_func)(vf->datasource);
  141481. end=_get_prev_page(vf,&og);
  141482. if(end<0)return(end);
  141483. if(ogg_page_serialno(&og)!=serialno){
  141484. if(_bisect_forward_serialno(vf,0,0,end+1,serialno,0)<0)return(OV_EREAD);
  141485. }else{
  141486. if(_bisect_forward_serialno(vf,0,end,end+1,serialno,0))return(OV_EREAD);
  141487. }
  141488. _prefetch_all_headers(vf,dataoffset);
  141489. return(ov_raw_seek(vf,0));
  141490. }
  141491. static void _decode_clear(OggVorbis_File *vf){
  141492. vorbis_dsp_clear(&vf->vd);
  141493. vorbis_block_clear(&vf->vb);
  141494. vf->ready_state=OPENED;
  141495. }
  141496. static int _fetch_and_process_packet(OggVorbis_File *vf,
  141497. ogg_packet *op_in,
  141498. int readp,
  141499. int spanp){
  141500. ogg_page og;
  141501. while(1){
  141502. if(vf->ready_state==INITSET){
  141503. while(1) {
  141504. ogg_packet op;
  141505. ogg_packet *op_ptr=(op_in?op_in:&op);
  141506. int result=ogg_stream_packetout(&vf->os,op_ptr);
  141507. ogg_int64_t granulepos;
  141508. op_in=NULL;
  141509. if(result==-1)return(OV_HOLE); /* hole in the data. */
  141510. if(result>0){
  141511. granulepos=op_ptr->granulepos;
  141512. if(!vorbis_synthesis(&vf->vb,op_ptr)){ /* lazy check for lazy
  141513. header handling. The
  141514. header packets aren't
  141515. audio, so if/when we
  141516. submit them,
  141517. vorbis_synthesis will
  141518. reject them */
  141519. {
  141520. int oldsamples=vorbis_synthesis_pcmout(&vf->vd,NULL);
  141521. if(oldsamples)return(OV_EFAULT);
  141522. vorbis_synthesis_blockin(&vf->vd,&vf->vb);
  141523. vf->samptrack+=vorbis_synthesis_pcmout(&vf->vd,NULL)-oldsamples;
  141524. vf->bittrack+=op_ptr->bytes*8;
  141525. }
  141526. if(granulepos!=-1 && !op_ptr->e_o_s){
  141527. int link=(vf->seekable?vf->current_link:0);
  141528. int i,samples;
  141529. if(vf->seekable && link>0)
  141530. granulepos-=vf->pcmlengths[link*2];
  141531. if(granulepos<0)granulepos=0; /* actually, this
  141532. shouldn't be possible
  141533. here unless the stream
  141534. is very broken */
  141535. samples=vorbis_synthesis_pcmout(&vf->vd,NULL);
  141536. granulepos-=samples;
  141537. for(i=0;i<link;i++)
  141538. granulepos+=vf->pcmlengths[i*2+1];
  141539. vf->pcm_offset=granulepos;
  141540. }
  141541. return(1);
  141542. }
  141543. }
  141544. else
  141545. break;
  141546. }
  141547. }
  141548. if(vf->ready_state>=OPENED){
  141549. ogg_int64_t ret;
  141550. if(!readp)return(0);
  141551. if((ret=_get_next_page(vf,&og,-1))<0){
  141552. return(OV_EOF); /* eof.
  141553. leave unitialized */
  141554. }
  141555. vf->bittrack+=og.header_len*8;
  141556. if(vf->ready_state==INITSET){
  141557. if(vf->current_serialno!=ogg_page_serialno(&og)){
  141558. if(!spanp)
  141559. return(OV_EOF);
  141560. _decode_clear(vf);
  141561. if(!vf->seekable){
  141562. vorbis_info_clear(vf->vi);
  141563. vorbis_comment_clear(vf->vc);
  141564. }
  141565. }
  141566. }
  141567. }
  141568. if(vf->ready_state!=INITSET){
  141569. int link;
  141570. if(vf->ready_state<STREAMSET){
  141571. if(vf->seekable){
  141572. vf->current_serialno=ogg_page_serialno(&og);
  141573. for(link=0;link<vf->links;link++)
  141574. if(vf->serialnos[link]==vf->current_serialno)break;
  141575. if(link==vf->links)return(OV_EBADLINK); /* sign of a bogus
  141576. stream. error out,
  141577. leave machine
  141578. uninitialized */
  141579. vf->current_link=link;
  141580. ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
  141581. vf->ready_state=STREAMSET;
  141582. }else{
  141583. int ret=_fetch_headers(vf,vf->vi,vf->vc,&vf->current_serialno,&og);
  141584. if(ret)return(ret);
  141585. vf->current_link++;
  141586. link=0;
  141587. }
  141588. }
  141589. {
  141590. int ret=_make_decode_ready(vf);
  141591. if(ret<0)return ret;
  141592. }
  141593. }
  141594. ogg_stream_pagein(&vf->os,&og);
  141595. }
  141596. }
  141597. static int _fseek64_wrap(FILE *f,ogg_int64_t off,int whence){
  141598. if(f==NULL)return(-1);
  141599. return fseek(f,off,whence);
  141600. }
  141601. static int _ov_open1(void *f,OggVorbis_File *vf,char *initial,
  141602. long ibytes, ov_callbacks callbacks){
  141603. int offsettest=(f?callbacks.seek_func(f,0,SEEK_CUR):-1);
  141604. int ret;
  141605. memset(vf,0,sizeof(*vf));
  141606. vf->datasource=f;
  141607. vf->callbacks = callbacks;
  141608. ogg_sync_init(&vf->oy);
  141609. if(initial){
  141610. char *buffer=ogg_sync_buffer(&vf->oy,ibytes);
  141611. memcpy(buffer,initial,ibytes);
  141612. ogg_sync_wrote(&vf->oy,ibytes);
  141613. }
  141614. if(offsettest!=-1)vf->seekable=1;
  141615. vf->links=1;
  141616. vf->vi=(vorbis_info*) _ogg_calloc(vf->links,sizeof(*vf->vi));
  141617. vf->vc=(vorbis_comment*) _ogg_calloc(vf->links,sizeof(*vf->vc));
  141618. ogg_stream_init(&vf->os,-1); /* fill in the serialno later */
  141619. if((ret=_fetch_headers(vf,vf->vi,vf->vc,&vf->current_serialno,NULL))<0){
  141620. vf->datasource=NULL;
  141621. ov_clear(vf);
  141622. }else
  141623. vf->ready_state=PARTOPEN;
  141624. return(ret);
  141625. }
  141626. static int _ov_open2(OggVorbis_File *vf){
  141627. if(vf->ready_state != PARTOPEN) return OV_EINVAL;
  141628. vf->ready_state=OPENED;
  141629. if(vf->seekable){
  141630. int ret=_open_seekable2(vf);
  141631. if(ret){
  141632. vf->datasource=NULL;
  141633. ov_clear(vf);
  141634. }
  141635. return(ret);
  141636. }else
  141637. vf->ready_state=STREAMSET;
  141638. return 0;
  141639. }
  141640. int ov_clear(OggVorbis_File *vf){
  141641. if(vf){
  141642. vorbis_block_clear(&vf->vb);
  141643. vorbis_dsp_clear(&vf->vd);
  141644. ogg_stream_clear(&vf->os);
  141645. if(vf->vi && vf->links){
  141646. int i;
  141647. for(i=0;i<vf->links;i++){
  141648. vorbis_info_clear(vf->vi+i);
  141649. vorbis_comment_clear(vf->vc+i);
  141650. }
  141651. _ogg_free(vf->vi);
  141652. _ogg_free(vf->vc);
  141653. }
  141654. if(vf->dataoffsets)_ogg_free(vf->dataoffsets);
  141655. if(vf->pcmlengths)_ogg_free(vf->pcmlengths);
  141656. if(vf->serialnos)_ogg_free(vf->serialnos);
  141657. if(vf->offsets)_ogg_free(vf->offsets);
  141658. ogg_sync_clear(&vf->oy);
  141659. if(vf->datasource)(vf->callbacks.close_func)(vf->datasource);
  141660. memset(vf,0,sizeof(*vf));
  141661. }
  141662. #ifdef DEBUG_LEAKS
  141663. _VDBG_dump();
  141664. #endif
  141665. return(0);
  141666. }
  141667. int ov_open_callbacks(void *f,OggVorbis_File *vf,char *initial,long ibytes,
  141668. ov_callbacks callbacks){
  141669. int ret=_ov_open1(f,vf,initial,ibytes,callbacks);
  141670. if(ret)return ret;
  141671. return _ov_open2(vf);
  141672. }
  141673. int ov_open(FILE *f,OggVorbis_File *vf,char *initial,long ibytes){
  141674. ov_callbacks callbacks = {
  141675. (size_t (*)(void *, size_t, size_t, void *)) fread,
  141676. (int (*)(void *, ogg_int64_t, int)) _fseek64_wrap,
  141677. (int (*)(void *)) fclose,
  141678. (long (*)(void *)) ftell
  141679. };
  141680. return ov_open_callbacks((void *)f, vf, initial, ibytes, callbacks);
  141681. }
  141682. int ov_halfrate(OggVorbis_File *vf,int flag){
  141683. int i;
  141684. if(vf->vi==NULL)return OV_EINVAL;
  141685. if(!vf->seekable)return OV_EINVAL;
  141686. if(vf->ready_state>=STREAMSET)
  141687. _decode_clear(vf); /* clear out stream state; later on libvorbis
  141688. will be able to swap this on the fly, but
  141689. for now dumping the decode machine is needed
  141690. to reinit the MDCT lookups. 1.1 libvorbis
  141691. is planned to be able to switch on the fly */
  141692. for(i=0;i<vf->links;i++){
  141693. if(vorbis_synthesis_halfrate(vf->vi+i,flag)){
  141694. ov_halfrate(vf,0);
  141695. return OV_EINVAL;
  141696. }
  141697. }
  141698. return 0;
  141699. }
  141700. int ov_halfrate_p(OggVorbis_File *vf){
  141701. if(vf->vi==NULL)return OV_EINVAL;
  141702. return vorbis_synthesis_halfrate_p(vf->vi);
  141703. }
  141704. int ov_test_callbacks(void *f,OggVorbis_File *vf,char *initial,long ibytes,
  141705. ov_callbacks callbacks)
  141706. {
  141707. return _ov_open1(f,vf,initial,ibytes,callbacks);
  141708. }
  141709. int ov_test(FILE *f,OggVorbis_File *vf,char *initial,long ibytes){
  141710. ov_callbacks callbacks = {
  141711. (size_t (*)(void *, size_t, size_t, void *)) fread,
  141712. (int (*)(void *, ogg_int64_t, int)) _fseek64_wrap,
  141713. (int (*)(void *)) fclose,
  141714. (long (*)(void *)) ftell
  141715. };
  141716. return ov_test_callbacks((void *)f, vf, initial, ibytes, callbacks);
  141717. }
  141718. int ov_test_open(OggVorbis_File *vf){
  141719. if(vf->ready_state!=PARTOPEN)return(OV_EINVAL);
  141720. return _ov_open2(vf);
  141721. }
  141722. long ov_streams(OggVorbis_File *vf){
  141723. return vf->links;
  141724. }
  141725. long ov_seekable(OggVorbis_File *vf){
  141726. return vf->seekable;
  141727. }
  141728. long ov_bitrate(OggVorbis_File *vf,int i){
  141729. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141730. if(i>=vf->links)return(OV_EINVAL);
  141731. if(!vf->seekable && i!=0)return(ov_bitrate(vf,0));
  141732. if(i<0){
  141733. ogg_int64_t bits=0;
  141734. int i;
  141735. float br;
  141736. for(i=0;i<vf->links;i++)
  141737. bits+=(vf->offsets[i+1]-vf->dataoffsets[i])*8;
  141738. br = bits/ov_time_total(vf,-1);
  141739. return(rint(br));
  141740. }else{
  141741. if(vf->seekable){
  141742. return(rint((vf->offsets[i+1]-vf->dataoffsets[i])*8/ov_time_total(vf,i)));
  141743. }else{
  141744. if(vf->vi[i].bitrate_nominal>0){
  141745. return vf->vi[i].bitrate_nominal;
  141746. }else{
  141747. if(vf->vi[i].bitrate_upper>0){
  141748. if(vf->vi[i].bitrate_lower>0){
  141749. return (vf->vi[i].bitrate_upper+vf->vi[i].bitrate_lower)/2;
  141750. }else{
  141751. return vf->vi[i].bitrate_upper;
  141752. }
  141753. }
  141754. return(OV_FALSE);
  141755. }
  141756. }
  141757. }
  141758. }
  141759. long ov_bitrate_instant(OggVorbis_File *vf){
  141760. int link=(vf->seekable?vf->current_link:0);
  141761. long ret;
  141762. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141763. if(vf->samptrack==0)return(OV_FALSE);
  141764. ret=vf->bittrack/vf->samptrack*vf->vi[link].rate+.5;
  141765. vf->bittrack=0.f;
  141766. vf->samptrack=0.f;
  141767. return(ret);
  141768. }
  141769. long ov_serialnumber(OggVorbis_File *vf,int i){
  141770. if(i>=vf->links)return(ov_serialnumber(vf,vf->links-1));
  141771. if(!vf->seekable && i>=0)return(ov_serialnumber(vf,-1));
  141772. if(i<0){
  141773. return(vf->current_serialno);
  141774. }else{
  141775. return(vf->serialnos[i]);
  141776. }
  141777. }
  141778. ogg_int64_t ov_raw_total(OggVorbis_File *vf,int i){
  141779. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141780. if(!vf->seekable || i>=vf->links)return(OV_EINVAL);
  141781. if(i<0){
  141782. ogg_int64_t acc=0;
  141783. int i;
  141784. for(i=0;i<vf->links;i++)
  141785. acc+=ov_raw_total(vf,i);
  141786. return(acc);
  141787. }else{
  141788. return(vf->offsets[i+1]-vf->offsets[i]);
  141789. }
  141790. }
  141791. ogg_int64_t ov_pcm_total(OggVorbis_File *vf,int i){
  141792. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141793. if(!vf->seekable || i>=vf->links)return(OV_EINVAL);
  141794. if(i<0){
  141795. ogg_int64_t acc=0;
  141796. int i;
  141797. for(i=0;i<vf->links;i++)
  141798. acc+=ov_pcm_total(vf,i);
  141799. return(acc);
  141800. }else{
  141801. return(vf->pcmlengths[i*2+1]);
  141802. }
  141803. }
  141804. double ov_time_total(OggVorbis_File *vf,int i){
  141805. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141806. if(!vf->seekable || i>=vf->links)return(OV_EINVAL);
  141807. if(i<0){
  141808. double acc=0;
  141809. int i;
  141810. for(i=0;i<vf->links;i++)
  141811. acc+=ov_time_total(vf,i);
  141812. return(acc);
  141813. }else{
  141814. return((double)(vf->pcmlengths[i*2+1])/vf->vi[i].rate);
  141815. }
  141816. }
  141817. int ov_raw_seek(OggVorbis_File *vf,ogg_int64_t pos){
  141818. ogg_stream_state work_os;
  141819. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141820. if(!vf->seekable)
  141821. return(OV_ENOSEEK); /* don't dump machine if we can't seek */
  141822. if(pos<0 || pos>vf->end)return(OV_EINVAL);
  141823. vf->pcm_offset=-1;
  141824. ogg_stream_reset_serialno(&vf->os,
  141825. vf->current_serialno); /* must set serialno */
  141826. vorbis_synthesis_restart(&vf->vd);
  141827. _seek_helper(vf,pos);
  141828. {
  141829. ogg_page og;
  141830. ogg_packet op;
  141831. int lastblock=0;
  141832. int accblock=0;
  141833. int thisblock;
  141834. int eosflag;
  141835. ogg_stream_init(&work_os,vf->current_serialno); /* get the memory ready */
  141836. ogg_stream_reset(&work_os); /* eliminate the spurious OV_HOLE
  141837. return from not necessarily
  141838. starting from the beginning */
  141839. while(1){
  141840. if(vf->ready_state>=STREAMSET){
  141841. int result=ogg_stream_packetout(&work_os,&op);
  141842. if(result>0){
  141843. if(vf->vi[vf->current_link].codec_setup){
  141844. thisblock=vorbis_packet_blocksize(vf->vi+vf->current_link,&op);
  141845. if(thisblock<0){
  141846. ogg_stream_packetout(&vf->os,NULL);
  141847. thisblock=0;
  141848. }else{
  141849. if(eosflag)
  141850. ogg_stream_packetout(&vf->os,NULL);
  141851. else
  141852. if(lastblock)accblock+=(lastblock+thisblock)>>2;
  141853. }
  141854. if(op.granulepos!=-1){
  141855. int i,link=vf->current_link;
  141856. ogg_int64_t granulepos=op.granulepos-vf->pcmlengths[link*2];
  141857. if(granulepos<0)granulepos=0;
  141858. for(i=0;i<link;i++)
  141859. granulepos+=vf->pcmlengths[i*2+1];
  141860. vf->pcm_offset=granulepos-accblock;
  141861. break;
  141862. }
  141863. lastblock=thisblock;
  141864. continue;
  141865. }else
  141866. ogg_stream_packetout(&vf->os,NULL);
  141867. }
  141868. }
  141869. if(!lastblock){
  141870. if(_get_next_page(vf,&og,-1)<0){
  141871. vf->pcm_offset=ov_pcm_total(vf,-1);
  141872. break;
  141873. }
  141874. }else{
  141875. vf->pcm_offset=-1;
  141876. break;
  141877. }
  141878. if(vf->ready_state>=STREAMSET)
  141879. if(vf->current_serialno!=ogg_page_serialno(&og)){
  141880. _decode_clear(vf); /* clear out stream state */
  141881. ogg_stream_clear(&work_os);
  141882. }
  141883. if(vf->ready_state<STREAMSET){
  141884. int link;
  141885. vf->current_serialno=ogg_page_serialno(&og);
  141886. for(link=0;link<vf->links;link++)
  141887. if(vf->serialnos[link]==vf->current_serialno)break;
  141888. if(link==vf->links)goto seek_error; /* sign of a bogus stream.
  141889. error out, leave
  141890. machine uninitialized */
  141891. vf->current_link=link;
  141892. ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
  141893. ogg_stream_reset_serialno(&work_os,vf->current_serialno);
  141894. vf->ready_state=STREAMSET;
  141895. }
  141896. ogg_stream_pagein(&vf->os,&og);
  141897. ogg_stream_pagein(&work_os,&og);
  141898. eosflag=ogg_page_eos(&og);
  141899. }
  141900. }
  141901. ogg_stream_clear(&work_os);
  141902. vf->bittrack=0.f;
  141903. vf->samptrack=0.f;
  141904. return(0);
  141905. seek_error:
  141906. vf->pcm_offset=-1;
  141907. ogg_stream_clear(&work_os);
  141908. _decode_clear(vf);
  141909. return OV_EBADLINK;
  141910. }
  141911. int ov_pcm_seek_page(OggVorbis_File *vf,ogg_int64_t pos){
  141912. int link=-1;
  141913. ogg_int64_t result=0;
  141914. ogg_int64_t total=ov_pcm_total(vf,-1);
  141915. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141916. if(!vf->seekable)return(OV_ENOSEEK);
  141917. if(pos<0 || pos>total)return(OV_EINVAL);
  141918. for(link=vf->links-1;link>=0;link--){
  141919. total-=vf->pcmlengths[link*2+1];
  141920. if(pos>=total)break;
  141921. }
  141922. {
  141923. ogg_int64_t end=vf->offsets[link+1];
  141924. ogg_int64_t begin=vf->offsets[link];
  141925. ogg_int64_t begintime = vf->pcmlengths[link*2];
  141926. ogg_int64_t endtime = vf->pcmlengths[link*2+1]+begintime;
  141927. ogg_int64_t target=pos-total+begintime;
  141928. ogg_int64_t best=begin;
  141929. ogg_page og;
  141930. while(begin<end){
  141931. ogg_int64_t bisect;
  141932. if(end-begin<CHUNKSIZE){
  141933. bisect=begin;
  141934. }else{
  141935. bisect=begin +
  141936. (target-begintime)*(end-begin)/(endtime-begintime) - CHUNKSIZE;
  141937. if(bisect<=begin)
  141938. bisect=begin+1;
  141939. }
  141940. _seek_helper(vf,bisect);
  141941. while(begin<end){
  141942. result=_get_next_page(vf,&og,end-vf->offset);
  141943. if(result==OV_EREAD) goto seek_error;
  141944. if(result<0){
  141945. if(bisect<=begin+1)
  141946. end=begin; /* found it */
  141947. else{
  141948. if(bisect==0) goto seek_error;
  141949. bisect-=CHUNKSIZE;
  141950. if(bisect<=begin)bisect=begin+1;
  141951. _seek_helper(vf,bisect);
  141952. }
  141953. }else{
  141954. ogg_int64_t granulepos=ogg_page_granulepos(&og);
  141955. if(granulepos==-1)continue;
  141956. if(granulepos<target){
  141957. best=result; /* raw offset of packet with granulepos */
  141958. begin=vf->offset; /* raw offset of next page */
  141959. begintime=granulepos;
  141960. if(target-begintime>44100)break;
  141961. bisect=begin; /* *not* begin + 1 */
  141962. }else{
  141963. if(bisect<=begin+1)
  141964. end=begin; /* found it */
  141965. else{
  141966. if(end==vf->offset){ /* we're pretty close - we'd be stuck in */
  141967. end=result;
  141968. bisect-=CHUNKSIZE; /* an endless loop otherwise. */
  141969. if(bisect<=begin)bisect=begin+1;
  141970. _seek_helper(vf,bisect);
  141971. }else{
  141972. end=result;
  141973. endtime=granulepos;
  141974. break;
  141975. }
  141976. }
  141977. }
  141978. }
  141979. }
  141980. }
  141981. {
  141982. ogg_page og;
  141983. ogg_packet op;
  141984. _seek_helper(vf,best);
  141985. vf->pcm_offset=-1;
  141986. if(_get_next_page(vf,&og,-1)<0)return(OV_EOF); /* shouldn't happen */
  141987. if(link!=vf->current_link){
  141988. _decode_clear(vf);
  141989. vf->current_link=link;
  141990. vf->current_serialno=ogg_page_serialno(&og);
  141991. vf->ready_state=STREAMSET;
  141992. }else{
  141993. vorbis_synthesis_restart(&vf->vd);
  141994. }
  141995. ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
  141996. ogg_stream_pagein(&vf->os,&og);
  141997. while(1){
  141998. result=ogg_stream_packetpeek(&vf->os,&op);
  141999. if(result==0){
  142000. _seek_helper(vf,best);
  142001. while(1){
  142002. result=_get_prev_page(vf,&og);
  142003. if(result<0) goto seek_error;
  142004. if(ogg_page_granulepos(&og)>-1 ||
  142005. !ogg_page_continued(&og)){
  142006. return ov_raw_seek(vf,result);
  142007. }
  142008. vf->offset=result;
  142009. }
  142010. }
  142011. if(result<0){
  142012. result = OV_EBADPACKET;
  142013. goto seek_error;
  142014. }
  142015. if(op.granulepos!=-1){
  142016. vf->pcm_offset=op.granulepos-vf->pcmlengths[vf->current_link*2];
  142017. if(vf->pcm_offset<0)vf->pcm_offset=0;
  142018. vf->pcm_offset+=total;
  142019. break;
  142020. }else
  142021. result=ogg_stream_packetout(&vf->os,NULL);
  142022. }
  142023. }
  142024. }
  142025. if(vf->pcm_offset>pos || pos>ov_pcm_total(vf,-1)){
  142026. result=OV_EFAULT;
  142027. goto seek_error;
  142028. }
  142029. vf->bittrack=0.f;
  142030. vf->samptrack=0.f;
  142031. return(0);
  142032. seek_error:
  142033. vf->pcm_offset=-1;
  142034. _decode_clear(vf);
  142035. return (int)result;
  142036. }
  142037. int ov_pcm_seek(OggVorbis_File *vf,ogg_int64_t pos){
  142038. int thisblock,lastblock=0;
  142039. int ret=ov_pcm_seek_page(vf,pos);
  142040. if(ret<0)return(ret);
  142041. if((ret=_make_decode_ready(vf)))return ret;
  142042. while(1){
  142043. ogg_packet op;
  142044. ogg_page og;
  142045. int ret=ogg_stream_packetpeek(&vf->os,&op);
  142046. if(ret>0){
  142047. thisblock=vorbis_packet_blocksize(vf->vi+vf->current_link,&op);
  142048. if(thisblock<0){
  142049. ogg_stream_packetout(&vf->os,NULL);
  142050. continue; /* non audio packet */
  142051. }
  142052. if(lastblock)vf->pcm_offset+=(lastblock+thisblock)>>2;
  142053. if(vf->pcm_offset+((thisblock+
  142054. vorbis_info_blocksize(vf->vi,1))>>2)>=pos)break;
  142055. ogg_stream_packetout(&vf->os,NULL);
  142056. vorbis_synthesis_trackonly(&vf->vb,&op); /* set up a vb with
  142057. only tracking, no
  142058. pcm_decode */
  142059. vorbis_synthesis_blockin(&vf->vd,&vf->vb);
  142060. if(op.granulepos>-1){
  142061. int i;
  142062. vf->pcm_offset=op.granulepos-vf->pcmlengths[vf->current_link*2];
  142063. if(vf->pcm_offset<0)vf->pcm_offset=0;
  142064. for(i=0;i<vf->current_link;i++)
  142065. vf->pcm_offset+=vf->pcmlengths[i*2+1];
  142066. }
  142067. lastblock=thisblock;
  142068. }else{
  142069. if(ret<0 && ret!=OV_HOLE)break;
  142070. if(_get_next_page(vf,&og,-1)<0)break;
  142071. if(vf->current_serialno!=ogg_page_serialno(&og))_decode_clear(vf);
  142072. if(vf->ready_state<STREAMSET){
  142073. int link;
  142074. vf->current_serialno=ogg_page_serialno(&og);
  142075. for(link=0;link<vf->links;link++)
  142076. if(vf->serialnos[link]==vf->current_serialno)break;
  142077. if(link==vf->links)return(OV_EBADLINK);
  142078. vf->current_link=link;
  142079. ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
  142080. vf->ready_state=STREAMSET;
  142081. ret=_make_decode_ready(vf);
  142082. if(ret)return ret;
  142083. lastblock=0;
  142084. }
  142085. ogg_stream_pagein(&vf->os,&og);
  142086. }
  142087. }
  142088. vf->bittrack=0.f;
  142089. vf->samptrack=0.f;
  142090. while(vf->pcm_offset<pos){
  142091. ogg_int64_t target=pos-vf->pcm_offset;
  142092. long samples=vorbis_synthesis_pcmout(&vf->vd,NULL);
  142093. if(samples>target)samples=target;
  142094. vorbis_synthesis_read(&vf->vd,samples);
  142095. vf->pcm_offset+=samples;
  142096. if(samples<target)
  142097. if(_fetch_and_process_packet(vf,NULL,1,1)<=0)
  142098. vf->pcm_offset=ov_pcm_total(vf,-1); /* eof */
  142099. }
  142100. return 0;
  142101. }
  142102. int ov_time_seek(OggVorbis_File *vf,double seconds){
  142103. int link=-1;
  142104. ogg_int64_t pcm_total=ov_pcm_total(vf,-1);
  142105. double time_total=ov_time_total(vf,-1);
  142106. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142107. if(!vf->seekable)return(OV_ENOSEEK);
  142108. if(seconds<0 || seconds>time_total)return(OV_EINVAL);
  142109. for(link=vf->links-1;link>=0;link--){
  142110. pcm_total-=vf->pcmlengths[link*2+1];
  142111. time_total-=ov_time_total(vf,link);
  142112. if(seconds>=time_total)break;
  142113. }
  142114. {
  142115. ogg_int64_t target=pcm_total+(seconds-time_total)*vf->vi[link].rate;
  142116. return(ov_pcm_seek(vf,target));
  142117. }
  142118. }
  142119. int ov_time_seek_page(OggVorbis_File *vf,double seconds){
  142120. int link=-1;
  142121. ogg_int64_t pcm_total=ov_pcm_total(vf,-1);
  142122. double time_total=ov_time_total(vf,-1);
  142123. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142124. if(!vf->seekable)return(OV_ENOSEEK);
  142125. if(seconds<0 || seconds>time_total)return(OV_EINVAL);
  142126. for(link=vf->links-1;link>=0;link--){
  142127. pcm_total-=vf->pcmlengths[link*2+1];
  142128. time_total-=ov_time_total(vf,link);
  142129. if(seconds>=time_total)break;
  142130. }
  142131. {
  142132. ogg_int64_t target=pcm_total+(seconds-time_total)*vf->vi[link].rate;
  142133. return(ov_pcm_seek_page(vf,target));
  142134. }
  142135. }
  142136. ogg_int64_t ov_raw_tell(OggVorbis_File *vf){
  142137. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142138. return(vf->offset);
  142139. }
  142140. ogg_int64_t ov_pcm_tell(OggVorbis_File *vf){
  142141. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142142. return(vf->pcm_offset);
  142143. }
  142144. double ov_time_tell(OggVorbis_File *vf){
  142145. int link=0;
  142146. ogg_int64_t pcm_total=0;
  142147. double time_total=0.f;
  142148. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142149. if(vf->seekable){
  142150. pcm_total=ov_pcm_total(vf,-1);
  142151. time_total=ov_time_total(vf,-1);
  142152. for(link=vf->links-1;link>=0;link--){
  142153. pcm_total-=vf->pcmlengths[link*2+1];
  142154. time_total-=ov_time_total(vf,link);
  142155. if(vf->pcm_offset>=pcm_total)break;
  142156. }
  142157. }
  142158. return((double)time_total+(double)(vf->pcm_offset-pcm_total)/vf->vi[link].rate);
  142159. }
  142160. vorbis_info *ov_info(OggVorbis_File *vf,int link){
  142161. if(vf->seekable){
  142162. if(link<0)
  142163. if(vf->ready_state>=STREAMSET)
  142164. return vf->vi+vf->current_link;
  142165. else
  142166. return vf->vi;
  142167. else
  142168. if(link>=vf->links)
  142169. return NULL;
  142170. else
  142171. return vf->vi+link;
  142172. }else{
  142173. return vf->vi;
  142174. }
  142175. }
  142176. vorbis_comment *ov_comment(OggVorbis_File *vf,int link){
  142177. if(vf->seekable){
  142178. if(link<0)
  142179. if(vf->ready_state>=STREAMSET)
  142180. return vf->vc+vf->current_link;
  142181. else
  142182. return vf->vc;
  142183. else
  142184. if(link>=vf->links)
  142185. return NULL;
  142186. else
  142187. return vf->vc+link;
  142188. }else{
  142189. return vf->vc;
  142190. }
  142191. }
  142192. static int host_is_big_endian() {
  142193. ogg_int32_t pattern = 0xfeedface; /* deadbeef */
  142194. unsigned char *bytewise = (unsigned char *)&pattern;
  142195. if (bytewise[0] == 0xfe) return 1;
  142196. return 0;
  142197. }
  142198. long ov_read(OggVorbis_File *vf,char *buffer,int length,
  142199. int bigendianp,int word,int sgned,int *bitstream){
  142200. int i,j;
  142201. int host_endian = host_is_big_endian();
  142202. float **pcm;
  142203. long samples;
  142204. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142205. while(1){
  142206. if(vf->ready_state==INITSET){
  142207. samples=vorbis_synthesis_pcmout(&vf->vd,&pcm);
  142208. if(samples)break;
  142209. }
  142210. {
  142211. int ret=_fetch_and_process_packet(vf,NULL,1,1);
  142212. if(ret==OV_EOF)
  142213. return(0);
  142214. if(ret<=0)
  142215. return(ret);
  142216. }
  142217. }
  142218. if(samples>0){
  142219. long channels=ov_info(vf,-1)->channels;
  142220. long bytespersample=word * channels;
  142221. vorbis_fpu_control fpu;
  142222. (void) fpu; // (to avoid a warning about it being unused)
  142223. if(samples>length/bytespersample)samples=length/bytespersample;
  142224. if(samples <= 0)
  142225. return OV_EINVAL;
  142226. {
  142227. int val;
  142228. if(word==1){
  142229. int off=(sgned?0:128);
  142230. vorbis_fpu_setround(&fpu);
  142231. for(j=0;j<samples;j++)
  142232. for(i=0;i<channels;i++){
  142233. val=vorbis_ftoi(pcm[i][j]*128.f);
  142234. if(val>127)val=127;
  142235. else if(val<-128)val=-128;
  142236. *buffer++=val+off;
  142237. }
  142238. vorbis_fpu_restore(fpu);
  142239. }else{
  142240. int off=(sgned?0:32768);
  142241. if(host_endian==bigendianp){
  142242. if(sgned){
  142243. vorbis_fpu_setround(&fpu);
  142244. for(i=0;i<channels;i++) { /* It's faster in this order */
  142245. float *src=pcm[i];
  142246. short *dest=((short *)buffer)+i;
  142247. for(j=0;j<samples;j++) {
  142248. val=vorbis_ftoi(src[j]*32768.f);
  142249. if(val>32767)val=32767;
  142250. else if(val<-32768)val=-32768;
  142251. *dest=val;
  142252. dest+=channels;
  142253. }
  142254. }
  142255. vorbis_fpu_restore(fpu);
  142256. }else{
  142257. vorbis_fpu_setround(&fpu);
  142258. for(i=0;i<channels;i++) {
  142259. float *src=pcm[i];
  142260. short *dest=((short *)buffer)+i;
  142261. for(j=0;j<samples;j++) {
  142262. val=vorbis_ftoi(src[j]*32768.f);
  142263. if(val>32767)val=32767;
  142264. else if(val<-32768)val=-32768;
  142265. *dest=val+off;
  142266. dest+=channels;
  142267. }
  142268. }
  142269. vorbis_fpu_restore(fpu);
  142270. }
  142271. }else if(bigendianp){
  142272. vorbis_fpu_setround(&fpu);
  142273. for(j=0;j<samples;j++)
  142274. for(i=0;i<channels;i++){
  142275. val=vorbis_ftoi(pcm[i][j]*32768.f);
  142276. if(val>32767)val=32767;
  142277. else if(val<-32768)val=-32768;
  142278. val+=off;
  142279. *buffer++=(val>>8);
  142280. *buffer++=(val&0xff);
  142281. }
  142282. vorbis_fpu_restore(fpu);
  142283. }else{
  142284. int val;
  142285. vorbis_fpu_setround(&fpu);
  142286. for(j=0;j<samples;j++)
  142287. for(i=0;i<channels;i++){
  142288. val=vorbis_ftoi(pcm[i][j]*32768.f);
  142289. if(val>32767)val=32767;
  142290. else if(val<-32768)val=-32768;
  142291. val+=off;
  142292. *buffer++=(val&0xff);
  142293. *buffer++=(val>>8);
  142294. }
  142295. vorbis_fpu_restore(fpu);
  142296. }
  142297. }
  142298. }
  142299. vorbis_synthesis_read(&vf->vd,samples);
  142300. vf->pcm_offset+=samples;
  142301. if(bitstream)*bitstream=vf->current_link;
  142302. return(samples*bytespersample);
  142303. }else{
  142304. return(samples);
  142305. }
  142306. }
  142307. long ov_read_float(OggVorbis_File *vf,float ***pcm_channels,int length,
  142308. int *bitstream){
  142309. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142310. while(1){
  142311. if(vf->ready_state==INITSET){
  142312. float **pcm;
  142313. long samples=vorbis_synthesis_pcmout(&vf->vd,&pcm);
  142314. if(samples){
  142315. if(pcm_channels)*pcm_channels=pcm;
  142316. if(samples>length)samples=length;
  142317. vorbis_synthesis_read(&vf->vd,samples);
  142318. vf->pcm_offset+=samples;
  142319. if(bitstream)*bitstream=vf->current_link;
  142320. return samples;
  142321. }
  142322. }
  142323. {
  142324. int ret=_fetch_and_process_packet(vf,NULL,1,1);
  142325. if(ret==OV_EOF)return(0);
  142326. if(ret<=0)return(ret);
  142327. }
  142328. }
  142329. }
  142330. extern float *vorbis_window(vorbis_dsp_state *v,int W);
  142331. extern void _analysis_output_always(const char *base,int i,float *v,int n,int bark,int dB,
  142332. ogg_int64_t off);
  142333. static void _ov_splice(float **pcm,float **lappcm,
  142334. int n1, int n2,
  142335. int ch1, int ch2,
  142336. float *w1, float *w2){
  142337. int i,j;
  142338. float *w=w1;
  142339. int n=n1;
  142340. if(n1>n2){
  142341. n=n2;
  142342. w=w2;
  142343. }
  142344. for(j=0;j<ch1 && j<ch2;j++){
  142345. float *s=lappcm[j];
  142346. float *d=pcm[j];
  142347. for(i=0;i<n;i++){
  142348. float wd=w[i]*w[i];
  142349. float ws=1.-wd;
  142350. d[i]=d[i]*wd + s[i]*ws;
  142351. }
  142352. }
  142353. for(;j<ch2;j++){
  142354. float *d=pcm[j];
  142355. for(i=0;i<n;i++){
  142356. float wd=w[i]*w[i];
  142357. d[i]=d[i]*wd;
  142358. }
  142359. }
  142360. }
  142361. static int _ov_initset(OggVorbis_File *vf){
  142362. while(1){
  142363. if(vf->ready_state==INITSET)break;
  142364. {
  142365. int ret=_fetch_and_process_packet(vf,NULL,1,0);
  142366. if(ret<0 && ret!=OV_HOLE)return(ret);
  142367. }
  142368. }
  142369. return 0;
  142370. }
  142371. static int _ov_initprime(OggVorbis_File *vf){
  142372. vorbis_dsp_state *vd=&vf->vd;
  142373. while(1){
  142374. if(vf->ready_state==INITSET)
  142375. if(vorbis_synthesis_pcmout(vd,NULL))break;
  142376. {
  142377. int ret=_fetch_and_process_packet(vf,NULL,1,0);
  142378. if(ret<0 && ret!=OV_HOLE)return(ret);
  142379. }
  142380. }
  142381. return 0;
  142382. }
  142383. static void _ov_getlap(OggVorbis_File *vf,vorbis_info *vi,vorbis_dsp_state *vd,
  142384. float **lappcm,int lapsize){
  142385. int lapcount=0,i;
  142386. float **pcm;
  142387. while(lapcount<lapsize){
  142388. int samples=vorbis_synthesis_pcmout(vd,&pcm);
  142389. if(samples){
  142390. if(samples>lapsize-lapcount)samples=lapsize-lapcount;
  142391. for(i=0;i<vi->channels;i++)
  142392. memcpy(lappcm[i]+lapcount,pcm[i],sizeof(**pcm)*samples);
  142393. lapcount+=samples;
  142394. vorbis_synthesis_read(vd,samples);
  142395. }else{
  142396. int ret=_fetch_and_process_packet(vf,NULL,1,0); /* do *not* span */
  142397. if(ret==OV_EOF)break;
  142398. }
  142399. }
  142400. if(lapcount<lapsize){
  142401. int samples=vorbis_synthesis_lapout(&vf->vd,&pcm);
  142402. if(samples==0){
  142403. for(i=0;i<vi->channels;i++)
  142404. memset(lappcm[i]+lapcount,0,sizeof(**pcm)*lapsize-lapcount);
  142405. lapcount=lapsize;
  142406. }else{
  142407. if(samples>lapsize-lapcount)samples=lapsize-lapcount;
  142408. for(i=0;i<vi->channels;i++)
  142409. memcpy(lappcm[i]+lapcount,pcm[i],sizeof(**pcm)*samples);
  142410. lapcount+=samples;
  142411. }
  142412. }
  142413. }
  142414. int ov_crosslap(OggVorbis_File *vf1, OggVorbis_File *vf2){
  142415. vorbis_info *vi1,*vi2;
  142416. float **lappcm;
  142417. float **pcm;
  142418. float *w1,*w2;
  142419. int n1,n2,i,ret,hs1,hs2;
  142420. if(vf1==vf2)return(0); /* degenerate case */
  142421. if(vf1->ready_state<OPENED)return(OV_EINVAL);
  142422. if(vf2->ready_state<OPENED)return(OV_EINVAL);
  142423. ret=_ov_initset(vf1);
  142424. if(ret)return(ret);
  142425. ret=_ov_initprime(vf2);
  142426. if(ret)return(ret);
  142427. vi1=ov_info(vf1,-1);
  142428. vi2=ov_info(vf2,-1);
  142429. hs1=ov_halfrate_p(vf1);
  142430. hs2=ov_halfrate_p(vf2);
  142431. lappcm=(float**) alloca(sizeof(*lappcm)*vi1->channels);
  142432. n1=vorbis_info_blocksize(vi1,0)>>(1+hs1);
  142433. n2=vorbis_info_blocksize(vi2,0)>>(1+hs2);
  142434. w1=vorbis_window(&vf1->vd,0);
  142435. w2=vorbis_window(&vf2->vd,0);
  142436. for(i=0;i<vi1->channels;i++)
  142437. lappcm[i]=(float*) alloca(sizeof(**lappcm)*n1);
  142438. _ov_getlap(vf1,vi1,&vf1->vd,lappcm,n1);
  142439. vorbis_synthesis_lapout(&vf2->vd,&pcm);
  142440. _analysis_output_always("pcmL",0,pcm[0],n1*2,0,0,0);
  142441. _analysis_output_always("pcmR",0,pcm[1],n1*2,0,0,0);
  142442. _ov_splice(pcm,lappcm,n1,n2,vi1->channels,vi2->channels,w1,w2);
  142443. return(0);
  142444. }
  142445. static int _ov_64_seek_lap(OggVorbis_File *vf,ogg_int64_t pos,
  142446. int (*localseek)(OggVorbis_File *,ogg_int64_t)){
  142447. vorbis_info *vi;
  142448. float **lappcm;
  142449. float **pcm;
  142450. float *w1,*w2;
  142451. int n1,n2,ch1,ch2,hs;
  142452. int i,ret;
  142453. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142454. ret=_ov_initset(vf);
  142455. if(ret)return(ret);
  142456. vi=ov_info(vf,-1);
  142457. hs=ov_halfrate_p(vf);
  142458. ch1=vi->channels;
  142459. n1=vorbis_info_blocksize(vi,0)>>(1+hs);
  142460. w1=vorbis_window(&vf->vd,0); /* window arrays from libvorbis are
  142461. persistent; even if the decode state
  142462. from this link gets dumped, this
  142463. window array continues to exist */
  142464. lappcm=(float**) alloca(sizeof(*lappcm)*ch1);
  142465. for(i=0;i<ch1;i++)
  142466. lappcm[i]=(float*) alloca(sizeof(**lappcm)*n1);
  142467. _ov_getlap(vf,vi,&vf->vd,lappcm,n1);
  142468. ret=localseek(vf,pos);
  142469. if(ret)return ret;
  142470. ret=_ov_initprime(vf);
  142471. if(ret)return(ret);
  142472. vi=ov_info(vf,-1);
  142473. ch2=vi->channels;
  142474. n2=vorbis_info_blocksize(vi,0)>>(1+hs);
  142475. w2=vorbis_window(&vf->vd,0);
  142476. vorbis_synthesis_lapout(&vf->vd,&pcm);
  142477. _ov_splice(pcm,lappcm,n1,n2,ch1,ch2,w1,w2);
  142478. return(0);
  142479. }
  142480. int ov_raw_seek_lap(OggVorbis_File *vf,ogg_int64_t pos){
  142481. return _ov_64_seek_lap(vf,pos,ov_raw_seek);
  142482. }
  142483. int ov_pcm_seek_lap(OggVorbis_File *vf,ogg_int64_t pos){
  142484. return _ov_64_seek_lap(vf,pos,ov_pcm_seek);
  142485. }
  142486. int ov_pcm_seek_page_lap(OggVorbis_File *vf,ogg_int64_t pos){
  142487. return _ov_64_seek_lap(vf,pos,ov_pcm_seek_page);
  142488. }
  142489. static int _ov_d_seek_lap(OggVorbis_File *vf,double pos,
  142490. int (*localseek)(OggVorbis_File *,double)){
  142491. vorbis_info *vi;
  142492. float **lappcm;
  142493. float **pcm;
  142494. float *w1,*w2;
  142495. int n1,n2,ch1,ch2,hs;
  142496. int i,ret;
  142497. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142498. ret=_ov_initset(vf);
  142499. if(ret)return(ret);
  142500. vi=ov_info(vf,-1);
  142501. hs=ov_halfrate_p(vf);
  142502. ch1=vi->channels;
  142503. n1=vorbis_info_blocksize(vi,0)>>(1+hs);
  142504. w1=vorbis_window(&vf->vd,0); /* window arrays from libvorbis are
  142505. persistent; even if the decode state
  142506. from this link gets dumped, this
  142507. window array continues to exist */
  142508. lappcm=(float**) alloca(sizeof(*lappcm)*ch1);
  142509. for(i=0;i<ch1;i++)
  142510. lappcm[i]=(float*) alloca(sizeof(**lappcm)*n1);
  142511. _ov_getlap(vf,vi,&vf->vd,lappcm,n1);
  142512. ret=localseek(vf,pos);
  142513. if(ret)return ret;
  142514. ret=_ov_initprime(vf);
  142515. if(ret)return(ret);
  142516. vi=ov_info(vf,-1);
  142517. ch2=vi->channels;
  142518. n2=vorbis_info_blocksize(vi,0)>>(1+hs);
  142519. w2=vorbis_window(&vf->vd,0);
  142520. vorbis_synthesis_lapout(&vf->vd,&pcm);
  142521. _ov_splice(pcm,lappcm,n1,n2,ch1,ch2,w1,w2);
  142522. return(0);
  142523. }
  142524. int ov_time_seek_lap(OggVorbis_File *vf,double pos){
  142525. return _ov_d_seek_lap(vf,pos,ov_time_seek);
  142526. }
  142527. int ov_time_seek_page_lap(OggVorbis_File *vf,double pos){
  142528. return _ov_d_seek_lap(vf,pos,ov_time_seek_page);
  142529. }
  142530. #endif
  142531. /*** End of inlined file: vorbisfile.c ***/
  142532. /*** Start of inlined file: window.c ***/
  142533. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  142534. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  142535. // tasks..
  142536. #if JUCE_MSVC
  142537. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  142538. #endif
  142539. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  142540. #if JUCE_USE_OGGVORBIS
  142541. #include <stdlib.h>
  142542. #include <math.h>
  142543. static float vwin64[32] = {
  142544. 0.0009460463F, 0.0085006468F, 0.0235352254F, 0.0458950567F,
  142545. 0.0753351908F, 0.1115073077F, 0.1539457973F, 0.2020557475F,
  142546. 0.2551056759F, 0.3122276645F, 0.3724270287F, 0.4346027792F,
  142547. 0.4975789974F, 0.5601459521F, 0.6211085051F, 0.6793382689F,
  142548. 0.7338252629F, 0.7837245849F, 0.8283939355F, 0.8674186656F,
  142549. 0.9006222429F, 0.9280614787F, 0.9500073081F, 0.9669131782F,
  142550. 0.9793740220F, 0.9880792941F, 0.9937636139F, 0.9971582668F,
  142551. 0.9989462667F, 0.9997230082F, 0.9999638688F, 0.9999995525F,
  142552. };
  142553. static float vwin128[64] = {
  142554. 0.0002365472F, 0.0021280687F, 0.0059065254F, 0.0115626550F,
  142555. 0.0190823442F, 0.0284463735F, 0.0396300935F, 0.0526030430F,
  142556. 0.0673285281F, 0.0837631763F, 0.1018564887F, 0.1215504095F,
  142557. 0.1427789367F, 0.1654677960F, 0.1895342001F, 0.2148867160F,
  142558. 0.2414252576F, 0.2690412240F, 0.2976177952F, 0.3270303960F,
  142559. 0.3571473350F, 0.3878306189F, 0.4189369387F, 0.4503188188F,
  142560. 0.4818259135F, 0.5133064334F, 0.5446086751F, 0.5755826278F,
  142561. 0.6060816248F, 0.6359640047F, 0.6650947483F, 0.6933470543F,
  142562. 0.7206038179F, 0.7467589810F, 0.7717187213F, 0.7954024542F,
  142563. 0.8177436264F, 0.8386902831F, 0.8582053981F, 0.8762669622F,
  142564. 0.8928678298F, 0.9080153310F, 0.9217306608F, 0.9340480615F,
  142565. 0.9450138200F, 0.9546851041F, 0.9631286621F, 0.9704194171F,
  142566. 0.9766389810F, 0.9818741197F, 0.9862151938F, 0.9897546035F,
  142567. 0.9925852598F, 0.9947991032F, 0.9964856900F, 0.9977308602F,
  142568. 0.9986155015F, 0.9992144193F, 0.9995953200F, 0.9998179155F,
  142569. 0.9999331503F, 0.9999825563F, 0.9999977357F, 0.9999999720F,
  142570. };
  142571. static float vwin256[128] = {
  142572. 0.0000591390F, 0.0005321979F, 0.0014780301F, 0.0028960636F,
  142573. 0.0047854363F, 0.0071449926F, 0.0099732775F, 0.0132685298F,
  142574. 0.0170286741F, 0.0212513119F, 0.0259337111F, 0.0310727950F,
  142575. 0.0366651302F, 0.0427069140F, 0.0491939614F, 0.0561216907F,
  142576. 0.0634851102F, 0.0712788035F, 0.0794969160F, 0.0881331402F,
  142577. 0.0971807028F, 0.1066323515F, 0.1164803426F, 0.1267164297F,
  142578. 0.1373318534F, 0.1483173323F, 0.1596630553F, 0.1713586755F,
  142579. 0.1833933062F, 0.1957555184F, 0.2084333404F, 0.2214142599F,
  142580. 0.2346852280F, 0.2482326664F, 0.2620424757F, 0.2761000481F,
  142581. 0.2903902813F, 0.3048975959F, 0.3196059553F, 0.3344988887F,
  142582. 0.3495595160F, 0.3647705766F, 0.3801144597F, 0.3955732382F,
  142583. 0.4111287047F, 0.4267624093F, 0.4424557009F, 0.4581897696F,
  142584. 0.4739456913F, 0.4897044744F, 0.5054471075F, 0.5211546088F,
  142585. 0.5368080763F, 0.5523887395F, 0.5678780103F, 0.5832575361F,
  142586. 0.5985092508F, 0.6136154277F, 0.6285587300F, 0.6433222619F,
  142587. 0.6578896175F, 0.6722449294F, 0.6863729144F, 0.7002589187F,
  142588. 0.7138889597F, 0.7272497662F, 0.7403288154F, 0.7531143679F,
  142589. 0.7655954985F, 0.7777621249F, 0.7896050322F, 0.8011158947F,
  142590. 0.8122872932F, 0.8231127294F, 0.8335866365F, 0.8437043850F,
  142591. 0.8534622861F, 0.8628575905F, 0.8718884835F, 0.8805540765F,
  142592. 0.8888543947F, 0.8967903616F, 0.9043637797F, 0.9115773078F,
  142593. 0.9184344360F, 0.9249394562F, 0.9310974312F, 0.9369141608F,
  142594. 0.9423961446F, 0.9475505439F, 0.9523851406F, 0.9569082947F,
  142595. 0.9611289005F, 0.9650563408F, 0.9687004405F, 0.9720714191F,
  142596. 0.9751798427F, 0.9780365753F, 0.9806527301F, 0.9830396204F,
  142597. 0.9852087111F, 0.9871715701F, 0.9889398207F, 0.9905250941F,
  142598. 0.9919389832F, 0.9931929973F, 0.9942985174F, 0.9952667537F,
  142599. 0.9961087037F, 0.9968351119F, 0.9974564312F, 0.9979827858F,
  142600. 0.9984239359F, 0.9987892441F, 0.9990876435F, 0.9993276081F,
  142601. 0.9995171241F, 0.9996636648F, 0.9997741654F, 0.9998550016F,
  142602. 0.9999119692F, 0.9999502656F, 0.9999744742F, 0.9999885497F,
  142603. 0.9999958064F, 0.9999989077F, 0.9999998584F, 0.9999999983F,
  142604. };
  142605. static float vwin512[256] = {
  142606. 0.0000147849F, 0.0001330607F, 0.0003695946F, 0.0007243509F,
  142607. 0.0011972759F, 0.0017882983F, 0.0024973285F, 0.0033242588F,
  142608. 0.0042689632F, 0.0053312973F, 0.0065110982F, 0.0078081841F,
  142609. 0.0092223540F, 0.0107533880F, 0.0124010466F, 0.0141650703F,
  142610. 0.0160451800F, 0.0180410758F, 0.0201524373F, 0.0223789233F,
  142611. 0.0247201710F, 0.0271757958F, 0.0297453914F, 0.0324285286F,
  142612. 0.0352247556F, 0.0381335972F, 0.0411545545F, 0.0442871045F,
  142613. 0.0475306997F, 0.0508847676F, 0.0543487103F, 0.0579219038F,
  142614. 0.0616036982F, 0.0653934164F, 0.0692903546F, 0.0732937809F,
  142615. 0.0774029356F, 0.0816170305F, 0.0859352485F, 0.0903567428F,
  142616. 0.0948806375F, 0.0995060259F, 0.1042319712F, 0.1090575056F,
  142617. 0.1139816300F, 0.1190033137F, 0.1241214941F, 0.1293350764F,
  142618. 0.1346429333F, 0.1400439046F, 0.1455367974F, 0.1511203852F,
  142619. 0.1567934083F, 0.1625545735F, 0.1684025537F, 0.1743359881F,
  142620. 0.1803534820F, 0.1864536069F, 0.1926349000F, 0.1988958650F,
  142621. 0.2052349715F, 0.2116506555F, 0.2181413191F, 0.2247053313F,
  142622. 0.2313410275F, 0.2380467105F, 0.2448206500F, 0.2516610835F,
  142623. 0.2585662164F, 0.2655342226F, 0.2725632448F, 0.2796513950F,
  142624. 0.2867967551F, 0.2939973773F, 0.3012512852F, 0.3085564739F,
  142625. 0.3159109111F, 0.3233125375F, 0.3307592680F, 0.3382489922F,
  142626. 0.3457795756F, 0.3533488602F, 0.3609546657F, 0.3685947904F,
  142627. 0.3762670121F, 0.3839690896F, 0.3916987634F, 0.3994537572F,
  142628. 0.4072317788F, 0.4150305215F, 0.4228476653F, 0.4306808783F,
  142629. 0.4385278181F, 0.4463861329F, 0.4542534630F, 0.4621274424F,
  142630. 0.4700057001F, 0.4778858615F, 0.4857655502F, 0.4936423891F,
  142631. 0.5015140023F, 0.5093780165F, 0.5172320626F, 0.5250737772F,
  142632. 0.5329008043F, 0.5407107971F, 0.5485014192F, 0.5562703465F,
  142633. 0.5640152688F, 0.5717338914F, 0.5794239366F, 0.5870831457F,
  142634. 0.5947092801F, 0.6023001235F, 0.6098534829F, 0.6173671907F,
  142635. 0.6248391059F, 0.6322671161F, 0.6396491384F, 0.6469831217F,
  142636. 0.6542670475F, 0.6614989319F, 0.6686768267F, 0.6757988210F,
  142637. 0.6828630426F, 0.6898676592F, 0.6968108799F, 0.7036909564F,
  142638. 0.7105061843F, 0.7172549043F, 0.7239355032F, 0.7305464154F,
  142639. 0.7370861235F, 0.7435531598F, 0.7499461068F, 0.7562635986F,
  142640. 0.7625043214F, 0.7686670148F, 0.7747504721F, 0.7807535410F,
  142641. 0.7866751247F, 0.7925141825F, 0.7982697296F, 0.8039408387F,
  142642. 0.8095266395F, 0.8150263196F, 0.8204391248F, 0.8257643590F,
  142643. 0.8310013848F, 0.8361496236F, 0.8412085555F, 0.8461777194F,
  142644. 0.8510567129F, 0.8558451924F, 0.8605428730F, 0.8651495278F,
  142645. 0.8696649882F, 0.8740891432F, 0.8784219392F, 0.8826633797F,
  142646. 0.8868135244F, 0.8908724888F, 0.8948404441F, 0.8987176157F,
  142647. 0.9025042831F, 0.9062007791F, 0.9098074886F, 0.9133248482F,
  142648. 0.9167533451F, 0.9200935163F, 0.9233459472F, 0.9265112712F,
  142649. 0.9295901680F, 0.9325833632F, 0.9354916263F, 0.9383157705F,
  142650. 0.9410566504F, 0.9437151618F, 0.9462922398F, 0.9487888576F,
  142651. 0.9512060252F, 0.9535447882F, 0.9558062262F, 0.9579914516F,
  142652. 0.9601016078F, 0.9621378683F, 0.9641014348F, 0.9659935361F,
  142653. 0.9678154261F, 0.9695683830F, 0.9712537071F, 0.9728727198F,
  142654. 0.9744267618F, 0.9759171916F, 0.9773453842F, 0.9787127293F,
  142655. 0.9800206298F, 0.9812705006F, 0.9824637665F, 0.9836018613F,
  142656. 0.9846862258F, 0.9857183066F, 0.9866995544F, 0.9876314227F,
  142657. 0.9885153662F, 0.9893528393F, 0.9901452948F, 0.9908941823F,
  142658. 0.9916009470F, 0.9922670279F, 0.9928938570F, 0.9934828574F,
  142659. 0.9940354423F, 0.9945530133F, 0.9950369595F, 0.9954886562F,
  142660. 0.9959094633F, 0.9963007242F, 0.9966637649F, 0.9969998925F,
  142661. 0.9973103939F, 0.9975965351F, 0.9978595598F, 0.9981006885F,
  142662. 0.9983211172F, 0.9985220166F, 0.9987045311F, 0.9988697776F,
  142663. 0.9990188449F, 0.9991527924F, 0.9992726499F, 0.9993794157F,
  142664. 0.9994740570F, 0.9995575079F, 0.9996306699F, 0.9996944099F,
  142665. 0.9997495605F, 0.9997969190F, 0.9998372465F, 0.9998712678F,
  142666. 0.9998996704F, 0.9999231041F, 0.9999421807F, 0.9999574732F,
  142667. 0.9999695157F, 0.9999788026F, 0.9999857885F, 0.9999908879F,
  142668. 0.9999944746F, 0.9999968817F, 0.9999984010F, 0.9999992833F,
  142669. 0.9999997377F, 0.9999999317F, 0.9999999911F, 0.9999999999F,
  142670. };
  142671. static float vwin1024[512] = {
  142672. 0.0000036962F, 0.0000332659F, 0.0000924041F, 0.0001811086F,
  142673. 0.0002993761F, 0.0004472021F, 0.0006245811F, 0.0008315063F,
  142674. 0.0010679699F, 0.0013339631F, 0.0016294757F, 0.0019544965F,
  142675. 0.0023090133F, 0.0026930125F, 0.0031064797F, 0.0035493989F,
  142676. 0.0040217533F, 0.0045235250F, 0.0050546946F, 0.0056152418F,
  142677. 0.0062051451F, 0.0068243817F, 0.0074729278F, 0.0081507582F,
  142678. 0.0088578466F, 0.0095941655F, 0.0103596863F, 0.0111543789F,
  142679. 0.0119782122F, 0.0128311538F, 0.0137131701F, 0.0146242260F,
  142680. 0.0155642855F, 0.0165333111F, 0.0175312640F, 0.0185581042F,
  142681. 0.0196137903F, 0.0206982797F, 0.0218115284F, 0.0229534910F,
  142682. 0.0241241208F, 0.0253233698F, 0.0265511886F, 0.0278075263F,
  142683. 0.0290923308F, 0.0304055484F, 0.0317471241F, 0.0331170013F,
  142684. 0.0345151222F, 0.0359414274F, 0.0373958560F, 0.0388783456F,
  142685. 0.0403888325F, 0.0419272511F, 0.0434935347F, 0.0450876148F,
  142686. 0.0467094213F, 0.0483588828F, 0.0500359261F, 0.0517404765F,
  142687. 0.0534724575F, 0.0552317913F, 0.0570183983F, 0.0588321971F,
  142688. 0.0606731048F, 0.0625410369F, 0.0644359070F, 0.0663576272F,
  142689. 0.0683061077F, 0.0702812571F, 0.0722829821F, 0.0743111878F,
  142690. 0.0763657775F, 0.0784466526F, 0.0805537129F, 0.0826868561F,
  142691. 0.0848459782F, 0.0870309736F, 0.0892417345F, 0.0914781514F,
  142692. 0.0937401128F, 0.0960275056F, 0.0983402145F, 0.1006781223F,
  142693. 0.1030411101F, 0.1054290568F, 0.1078418397F, 0.1102793336F,
  142694. 0.1127414119F, 0.1152279457F, 0.1177388042F, 0.1202738544F,
  142695. 0.1228329618F, 0.1254159892F, 0.1280227980F, 0.1306532471F,
  142696. 0.1333071937F, 0.1359844927F, 0.1386849970F, 0.1414085575F,
  142697. 0.1441550230F, 0.1469242403F, 0.1497160539F, 0.1525303063F,
  142698. 0.1553668381F, 0.1582254875F, 0.1611060909F, 0.1640084822F,
  142699. 0.1669324936F, 0.1698779549F, 0.1728446939F, 0.1758325362F,
  142700. 0.1788413055F, 0.1818708232F, 0.1849209084F, 0.1879913785F,
  142701. 0.1910820485F, 0.1941927312F, 0.1973232376F, 0.2004733764F,
  142702. 0.2036429541F, 0.2068317752F, 0.2100396421F, 0.2132663552F,
  142703. 0.2165117125F, 0.2197755102F, 0.2230575422F, 0.2263576007F,
  142704. 0.2296754753F, 0.2330109540F, 0.2363638225F, 0.2397338646F,
  142705. 0.2431208619F, 0.2465245941F, 0.2499448389F, 0.2533813719F,
  142706. 0.2568339669F, 0.2603023956F, 0.2637864277F, 0.2672858312F,
  142707. 0.2708003718F, 0.2743298135F, 0.2778739186F, 0.2814324472F,
  142708. 0.2850051576F, 0.2885918065F, 0.2921921485F, 0.2958059366F,
  142709. 0.2994329219F, 0.3030728538F, 0.3067254799F, 0.3103905462F,
  142710. 0.3140677969F, 0.3177569747F, 0.3214578205F, 0.3251700736F,
  142711. 0.3288934718F, 0.3326277513F, 0.3363726468F, 0.3401278914F,
  142712. 0.3438932168F, 0.3476683533F, 0.3514530297F, 0.3552469734F,
  142713. 0.3590499106F, 0.3628615659F, 0.3666816630F, 0.3705099239F,
  142714. 0.3743460698F, 0.3781898204F, 0.3820408945F, 0.3858990095F,
  142715. 0.3897638820F, 0.3936352274F, 0.3975127601F, 0.4013961936F,
  142716. 0.4052852405F, 0.4091796123F, 0.4130790198F, 0.4169831732F,
  142717. 0.4208917815F, 0.4248045534F, 0.4287211965F, 0.4326414181F,
  142718. 0.4365649248F, 0.4404914225F, 0.4444206167F, 0.4483522125F,
  142719. 0.4522859146F, 0.4562214270F, 0.4601584538F, 0.4640966984F,
  142720. 0.4680358644F, 0.4719756548F, 0.4759157726F, 0.4798559209F,
  142721. 0.4837958024F, 0.4877351199F, 0.4916735765F, 0.4956108751F,
  142722. 0.4995467188F, 0.5034808109F, 0.5074128550F, 0.5113425550F,
  142723. 0.5152696149F, 0.5191937395F, 0.5231146336F, 0.5270320028F,
  142724. 0.5309455530F, 0.5348549910F, 0.5387600239F, 0.5426603597F,
  142725. 0.5465557070F, 0.5504457754F, 0.5543302752F, 0.5582089175F,
  142726. 0.5620814145F, 0.5659474793F, 0.5698068262F, 0.5736591704F,
  142727. 0.5775042283F, 0.5813417176F, 0.5851713571F, 0.5889928670F,
  142728. 0.5928059689F, 0.5966103856F, 0.6004058415F, 0.6041920626F,
  142729. 0.6079687761F, 0.6117357113F, 0.6154925986F, 0.6192391705F,
  142730. 0.6229751612F, 0.6267003064F, 0.6304143441F, 0.6341170137F,
  142731. 0.6378080569F, 0.6414872173F, 0.6451542405F, 0.6488088741F,
  142732. 0.6524508681F, 0.6560799742F, 0.6596959469F, 0.6632985424F,
  142733. 0.6668875197F, 0.6704626398F, 0.6740236662F, 0.6775703649F,
  142734. 0.6811025043F, 0.6846198554F, 0.6881221916F, 0.6916092892F,
  142735. 0.6950809269F, 0.6985368861F, 0.7019769510F, 0.7054009085F,
  142736. 0.7088085484F, 0.7121996632F, 0.7155740484F, 0.7189315023F,
  142737. 0.7222718263F, 0.7255948245F, 0.7289003043F, 0.7321880760F,
  142738. 0.7354579530F, 0.7387097518F, 0.7419432921F, 0.7451583966F,
  142739. 0.7483548915F, 0.7515326059F, 0.7546913723F, 0.7578310265F,
  142740. 0.7609514077F, 0.7640523581F, 0.7671337237F, 0.7701953535F,
  142741. 0.7732371001F, 0.7762588195F, 0.7792603711F, 0.7822416178F,
  142742. 0.7852024259F, 0.7881426654F, 0.7910622097F, 0.7939609356F,
  142743. 0.7968387237F, 0.7996954579F, 0.8025310261F, 0.8053453193F,
  142744. 0.8081382324F, 0.8109096638F, 0.8136595156F, 0.8163876936F,
  142745. 0.8190941071F, 0.8217786690F, 0.8244412960F, 0.8270819086F,
  142746. 0.8297004305F, 0.8322967896F, 0.8348709171F, 0.8374227481F,
  142747. 0.8399522213F, 0.8424592789F, 0.8449438672F, 0.8474059356F,
  142748. 0.8498454378F, 0.8522623306F, 0.8546565748F, 0.8570281348F,
  142749. 0.8593769787F, 0.8617030779F, 0.8640064080F, 0.8662869477F,
  142750. 0.8685446796F, 0.8707795899F, 0.8729916682F, 0.8751809079F,
  142751. 0.8773473059F, 0.8794908626F, 0.8816115819F, 0.8837094713F,
  142752. 0.8857845418F, 0.8878368079F, 0.8898662874F, 0.8918730019F,
  142753. 0.8938569760F, 0.8958182380F, 0.8977568194F, 0.8996727552F,
  142754. 0.9015660837F, 0.9034368465F, 0.9052850885F, 0.9071108577F,
  142755. 0.9089142057F, 0.9106951869F, 0.9124538591F, 0.9141902832F,
  142756. 0.9159045233F, 0.9175966464F, 0.9192667228F, 0.9209148257F,
  142757. 0.9225410313F, 0.9241454187F, 0.9257280701F, 0.9272890704F,
  142758. 0.9288285075F, 0.9303464720F, 0.9318430576F, 0.9333183603F,
  142759. 0.9347724792F, 0.9362055158F, 0.9376175745F, 0.9390087622F,
  142760. 0.9403791881F, 0.9417289644F, 0.9430582055F, 0.9443670283F,
  142761. 0.9456555521F, 0.9469238986F, 0.9481721917F, 0.9494005577F,
  142762. 0.9506091252F, 0.9517980248F, 0.9529673894F, 0.9541173540F,
  142763. 0.9552480557F, 0.9563596334F, 0.9574522282F, 0.9585259830F,
  142764. 0.9595810428F, 0.9606175542F, 0.9616356656F, 0.9626355274F,
  142765. 0.9636172915F, 0.9645811114F, 0.9655271425F, 0.9664555414F,
  142766. 0.9673664664F, 0.9682600774F, 0.9691365355F, 0.9699960034F,
  142767. 0.9708386448F, 0.9716646250F, 0.9724741103F, 0.9732672685F,
  142768. 0.9740442683F, 0.9748052795F, 0.9755504729F, 0.9762800205F,
  142769. 0.9769940950F, 0.9776928703F, 0.9783765210F, 0.9790452223F,
  142770. 0.9796991504F, 0.9803384823F, 0.9809633954F, 0.9815740679F,
  142771. 0.9821706784F, 0.9827534063F, 0.9833224312F, 0.9838779332F,
  142772. 0.9844200928F, 0.9849490910F, 0.9854651087F, 0.9859683274F,
  142773. 0.9864589286F, 0.9869370940F, 0.9874030054F, 0.9878568447F,
  142774. 0.9882987937F, 0.9887290343F, 0.9891477481F, 0.9895551169F,
  142775. 0.9899513220F, 0.9903365446F, 0.9907109658F, 0.9910747662F,
  142776. 0.9914281260F, 0.9917712252F, 0.9921042433F, 0.9924273593F,
  142777. 0.9927407516F, 0.9930445982F, 0.9933390763F, 0.9936243626F,
  142778. 0.9939006331F, 0.9941680631F, 0.9944268269F, 0.9946770982F,
  142779. 0.9949190498F, 0.9951528537F, 0.9953786808F, 0.9955967011F,
  142780. 0.9958070836F, 0.9960099963F, 0.9962056061F, 0.9963940787F,
  142781. 0.9965755786F, 0.9967502693F, 0.9969183129F, 0.9970798704F,
  142782. 0.9972351013F, 0.9973841640F, 0.9975272151F, 0.9976644103F,
  142783. 0.9977959036F, 0.9979218476F, 0.9980423932F, 0.9981576901F,
  142784. 0.9982678862F, 0.9983731278F, 0.9984735596F, 0.9985693247F,
  142785. 0.9986605645F, 0.9987474186F, 0.9988300248F, 0.9989085193F,
  142786. 0.9989830364F, 0.9990537085F, 0.9991206662F, 0.9991840382F,
  142787. 0.9992439513F, 0.9993005303F, 0.9993538982F, 0.9994041757F,
  142788. 0.9994514817F, 0.9994959330F, 0.9995376444F, 0.9995767286F,
  142789. 0.9996132960F, 0.9996474550F, 0.9996793121F, 0.9997089710F,
  142790. 0.9997365339F, 0.9997621003F, 0.9997857677F, 0.9998076311F,
  142791. 0.9998277836F, 0.9998463156F, 0.9998633155F, 0.9998788692F,
  142792. 0.9998930603F, 0.9999059701F, 0.9999176774F, 0.9999282586F,
  142793. 0.9999377880F, 0.9999463370F, 0.9999539749F, 0.9999607685F,
  142794. 0.9999667820F, 0.9999720773F, 0.9999767136F, 0.9999807479F,
  142795. 0.9999842344F, 0.9999872249F, 0.9999897688F, 0.9999919127F,
  142796. 0.9999937009F, 0.9999951749F, 0.9999963738F, 0.9999973342F,
  142797. 0.9999980900F, 0.9999986724F, 0.9999991103F, 0.9999994297F,
  142798. 0.9999996543F, 0.9999998049F, 0.9999999000F, 0.9999999552F,
  142799. 0.9999999836F, 0.9999999957F, 0.9999999994F, 1.0000000000F,
  142800. };
  142801. static float vwin2048[1024] = {
  142802. 0.0000009241F, 0.0000083165F, 0.0000231014F, 0.0000452785F,
  142803. 0.0000748476F, 0.0001118085F, 0.0001561608F, 0.0002079041F,
  142804. 0.0002670379F, 0.0003335617F, 0.0004074748F, 0.0004887765F,
  142805. 0.0005774661F, 0.0006735427F, 0.0007770054F, 0.0008878533F,
  142806. 0.0010060853F, 0.0011317002F, 0.0012646969F, 0.0014050742F,
  142807. 0.0015528307F, 0.0017079650F, 0.0018704756F, 0.0020403610F,
  142808. 0.0022176196F, 0.0024022497F, 0.0025942495F, 0.0027936173F,
  142809. 0.0030003511F, 0.0032144490F, 0.0034359088F, 0.0036647286F,
  142810. 0.0039009061F, 0.0041444391F, 0.0043953253F, 0.0046535621F,
  142811. 0.0049191472F, 0.0051920781F, 0.0054723520F, 0.0057599664F,
  142812. 0.0060549184F, 0.0063572052F, 0.0066668239F, 0.0069837715F,
  142813. 0.0073080449F, 0.0076396410F, 0.0079785566F, 0.0083247884F,
  142814. 0.0086783330F, 0.0090391871F, 0.0094073470F, 0.0097828092F,
  142815. 0.0101655700F, 0.0105556258F, 0.0109529726F, 0.0113576065F,
  142816. 0.0117695237F, 0.0121887200F, 0.0126151913F, 0.0130489335F,
  142817. 0.0134899422F, 0.0139382130F, 0.0143937415F, 0.0148565233F,
  142818. 0.0153265536F, 0.0158038279F, 0.0162883413F, 0.0167800889F,
  142819. 0.0172790660F, 0.0177852675F, 0.0182986882F, 0.0188193231F,
  142820. 0.0193471668F, 0.0198822141F, 0.0204244594F, 0.0209738974F,
  142821. 0.0215305225F, 0.0220943289F, 0.0226653109F, 0.0232434627F,
  142822. 0.0238287784F, 0.0244212519F, 0.0250208772F, 0.0256276481F,
  142823. 0.0262415582F, 0.0268626014F, 0.0274907711F, 0.0281260608F,
  142824. 0.0287684638F, 0.0294179736F, 0.0300745833F, 0.0307382859F,
  142825. 0.0314090747F, 0.0320869424F, 0.0327718819F, 0.0334638860F,
  142826. 0.0341629474F, 0.0348690586F, 0.0355822122F, 0.0363024004F,
  142827. 0.0370296157F, 0.0377638502F, 0.0385050960F, 0.0392533451F,
  142828. 0.0400085896F, 0.0407708211F, 0.0415400315F, 0.0423162123F,
  142829. 0.0430993552F, 0.0438894515F, 0.0446864926F, 0.0454904698F,
  142830. 0.0463013742F, 0.0471191969F, 0.0479439288F, 0.0487755607F,
  142831. 0.0496140836F, 0.0504594879F, 0.0513117642F, 0.0521709031F,
  142832. 0.0530368949F, 0.0539097297F, 0.0547893979F, 0.0556758894F,
  142833. 0.0565691941F, 0.0574693019F, 0.0583762026F, 0.0592898858F,
  142834. 0.0602103410F, 0.0611375576F, 0.0620715250F, 0.0630122324F,
  142835. 0.0639596688F, 0.0649138234F, 0.0658746848F, 0.0668422421F,
  142836. 0.0678164838F, 0.0687973985F, 0.0697849746F, 0.0707792005F,
  142837. 0.0717800645F, 0.0727875547F, 0.0738016591F, 0.0748223656F,
  142838. 0.0758496620F, 0.0768835359F, 0.0779239751F, 0.0789709668F,
  142839. 0.0800244985F, 0.0810845574F, 0.0821511306F, 0.0832242052F,
  142840. 0.0843037679F, 0.0853898056F, 0.0864823050F, 0.0875812525F,
  142841. 0.0886866347F, 0.0897984378F, 0.0909166480F, 0.0920412513F,
  142842. 0.0931722338F, 0.0943095813F, 0.0954532795F, 0.0966033140F,
  142843. 0.0977596702F, 0.0989223336F, 0.1000912894F, 0.1012665227F,
  142844. 0.1024480185F, 0.1036357616F, 0.1048297369F, 0.1060299290F,
  142845. 0.1072363224F, 0.1084489014F, 0.1096676504F, 0.1108925534F,
  142846. 0.1121235946F, 0.1133607577F, 0.1146040267F, 0.1158533850F,
  142847. 0.1171088163F, 0.1183703040F, 0.1196378312F, 0.1209113812F,
  142848. 0.1221909370F, 0.1234764815F, 0.1247679974F, 0.1260654674F,
  142849. 0.1273688740F, 0.1286781995F, 0.1299934263F, 0.1313145365F,
  142850. 0.1326415121F, 0.1339743349F, 0.1353129866F, 0.1366574490F,
  142851. 0.1380077035F, 0.1393637315F, 0.1407255141F, 0.1420930325F,
  142852. 0.1434662677F, 0.1448452004F, 0.1462298115F, 0.1476200814F,
  142853. 0.1490159906F, 0.1504175195F, 0.1518246482F, 0.1532373569F,
  142854. 0.1546556253F, 0.1560794333F, 0.1575087606F, 0.1589435866F,
  142855. 0.1603838909F, 0.1618296526F, 0.1632808509F, 0.1647374648F,
  142856. 0.1661994731F, 0.1676668546F, 0.1691395880F, 0.1706176516F,
  142857. 0.1721010238F, 0.1735896829F, 0.1750836068F, 0.1765827736F,
  142858. 0.1780871610F, 0.1795967468F, 0.1811115084F, 0.1826314234F,
  142859. 0.1841564689F, 0.1856866221F, 0.1872218600F, 0.1887621595F,
  142860. 0.1903074974F, 0.1918578503F, 0.1934131947F, 0.1949735068F,
  142861. 0.1965387630F, 0.1981089393F, 0.1996840117F, 0.2012639560F,
  142862. 0.2028487479F, 0.2044383630F, 0.2060327766F, 0.2076319642F,
  142863. 0.2092359007F, 0.2108445614F, 0.2124579211F, 0.2140759545F,
  142864. 0.2156986364F, 0.2173259411F, 0.2189578432F, 0.2205943168F,
  142865. 0.2222353361F, 0.2238808751F, 0.2255309076F, 0.2271854073F,
  142866. 0.2288443480F, 0.2305077030F, 0.2321754457F, 0.2338475493F,
  142867. 0.2355239869F, 0.2372047315F, 0.2388897560F, 0.2405790329F,
  142868. 0.2422725350F, 0.2439702347F, 0.2456721043F, 0.2473781159F,
  142869. 0.2490882418F, 0.2508024539F, 0.2525207240F, 0.2542430237F,
  142870. 0.2559693248F, 0.2576995986F, 0.2594338166F, 0.2611719498F,
  142871. 0.2629139695F, 0.2646598466F, 0.2664095520F, 0.2681630564F,
  142872. 0.2699203304F, 0.2716813445F, 0.2734460691F, 0.2752144744F,
  142873. 0.2769865307F, 0.2787622079F, 0.2805414760F, 0.2823243047F,
  142874. 0.2841106637F, 0.2859005227F, 0.2876938509F, 0.2894906179F,
  142875. 0.2912907928F, 0.2930943447F, 0.2949012426F, 0.2967114554F,
  142876. 0.2985249520F, 0.3003417009F, 0.3021616708F, 0.3039848301F,
  142877. 0.3058111471F, 0.3076405901F, 0.3094731273F, 0.3113087266F,
  142878. 0.3131473560F, 0.3149889833F, 0.3168335762F, 0.3186811024F,
  142879. 0.3205315294F, 0.3223848245F, 0.3242409552F, 0.3260998886F,
  142880. 0.3279615918F, 0.3298260319F, 0.3316931758F, 0.3335629903F,
  142881. 0.3354354423F, 0.3373104982F, 0.3391881247F, 0.3410682882F,
  142882. 0.3429509551F, 0.3448360917F, 0.3467236642F, 0.3486136387F,
  142883. 0.3505059811F, 0.3524006575F, 0.3542976336F, 0.3561968753F,
  142884. 0.3580983482F, 0.3600020179F, 0.3619078499F, 0.3638158096F,
  142885. 0.3657258625F, 0.3676379737F, 0.3695521086F, 0.3714682321F,
  142886. 0.3733863094F, 0.3753063055F, 0.3772281852F, 0.3791519134F,
  142887. 0.3810774548F, 0.3830047742F, 0.3849338362F, 0.3868646053F,
  142888. 0.3887970459F, 0.3907311227F, 0.3926667998F, 0.3946040417F,
  142889. 0.3965428125F, 0.3984830765F, 0.4004247978F, 0.4023679403F,
  142890. 0.4043124683F, 0.4062583455F, 0.4082055359F, 0.4101540034F,
  142891. 0.4121037117F, 0.4140546246F, 0.4160067058F, 0.4179599190F,
  142892. 0.4199142277F, 0.4218695956F, 0.4238259861F, 0.4257833627F,
  142893. 0.4277416888F, 0.4297009279F, 0.4316610433F, 0.4336219983F,
  142894. 0.4355837562F, 0.4375462803F, 0.4395095337F, 0.4414734797F,
  142895. 0.4434380815F, 0.4454033021F, 0.4473691046F, 0.4493354521F,
  142896. 0.4513023078F, 0.4532696345F, 0.4552373954F, 0.4572055533F,
  142897. 0.4591740713F, 0.4611429123F, 0.4631120393F, 0.4650814151F,
  142898. 0.4670510028F, 0.4690207650F, 0.4709906649F, 0.4729606651F,
  142899. 0.4749307287F, 0.4769008185F, 0.4788708972F, 0.4808409279F,
  142900. 0.4828108732F, 0.4847806962F, 0.4867503597F, 0.4887198264F,
  142901. 0.4906890593F, 0.4926580213F, 0.4946266753F, 0.4965949840F,
  142902. 0.4985629105F, 0.5005304176F, 0.5024974683F, 0.5044640255F,
  142903. 0.5064300522F, 0.5083955114F, 0.5103603659F, 0.5123245790F,
  142904. 0.5142881136F, 0.5162509328F, 0.5182129997F, 0.5201742774F,
  142905. 0.5221347290F, 0.5240943178F, 0.5260530070F, 0.5280107598F,
  142906. 0.5299675395F, 0.5319233095F, 0.5338780330F, 0.5358316736F,
  142907. 0.5377841946F, 0.5397355596F, 0.5416857320F, 0.5436346755F,
  142908. 0.5455823538F, 0.5475287304F, 0.5494737691F, 0.5514174337F,
  142909. 0.5533596881F, 0.5553004962F, 0.5572398218F, 0.5591776291F,
  142910. 0.5611138821F, 0.5630485449F, 0.5649815818F, 0.5669129570F,
  142911. 0.5688426349F, 0.5707705799F, 0.5726967564F, 0.5746211290F,
  142912. 0.5765436624F, 0.5784643212F, 0.5803830702F, 0.5822998743F,
  142913. 0.5842146984F, 0.5861275076F, 0.5880382669F, 0.5899469416F,
  142914. 0.5918534968F, 0.5937578981F, 0.5956601107F, 0.5975601004F,
  142915. 0.5994578326F, 0.6013532732F, 0.6032463880F, 0.6051371429F,
  142916. 0.6070255039F, 0.6089114372F, 0.6107949090F, 0.6126758856F,
  142917. 0.6145543334F, 0.6164302191F, 0.6183035092F, 0.6201741706F,
  142918. 0.6220421700F, 0.6239074745F, 0.6257700513F, 0.6276298674F,
  142919. 0.6294868903F, 0.6313410873F, 0.6331924262F, 0.6350408745F,
  142920. 0.6368864001F, 0.6387289710F, 0.6405685552F, 0.6424051209F,
  142921. 0.6442386364F, 0.6460690702F, 0.6478963910F, 0.6497205673F,
  142922. 0.6515415682F, 0.6533593625F, 0.6551739194F, 0.6569852082F,
  142923. 0.6587931984F, 0.6605978593F, 0.6623991609F, 0.6641970728F,
  142924. 0.6659915652F, 0.6677826081F, 0.6695701718F, 0.6713542268F,
  142925. 0.6731347437F, 0.6749116932F, 0.6766850461F, 0.6784547736F,
  142926. 0.6802208469F, 0.6819832374F, 0.6837419164F, 0.6854968559F,
  142927. 0.6872480275F, 0.6889954034F, 0.6907389556F, 0.6924786566F,
  142928. 0.6942144788F, 0.6959463950F, 0.6976743780F, 0.6993984008F,
  142929. 0.7011184365F, 0.7028344587F, 0.7045464407F, 0.7062543564F,
  142930. 0.7079581796F, 0.7096578844F, 0.7113534450F, 0.7130448359F,
  142931. 0.7147320316F, 0.7164150070F, 0.7180937371F, 0.7197681970F,
  142932. 0.7214383620F, 0.7231042077F, 0.7247657098F, 0.7264228443F,
  142933. 0.7280755871F, 0.7297239147F, 0.7313678035F, 0.7330072301F,
  142934. 0.7346421715F, 0.7362726046F, 0.7378985069F, 0.7395198556F,
  142935. 0.7411366285F, 0.7427488034F, 0.7443563584F, 0.7459592717F,
  142936. 0.7475575218F, 0.7491510873F, 0.7507399471F, 0.7523240803F,
  142937. 0.7539034661F, 0.7554780839F, 0.7570479136F, 0.7586129349F,
  142938. 0.7601731279F, 0.7617284730F, 0.7632789506F, 0.7648245416F,
  142939. 0.7663652267F, 0.7679009872F, 0.7694318044F, 0.7709576599F,
  142940. 0.7724785354F, 0.7739944130F, 0.7755052749F, 0.7770111035F,
  142941. 0.7785118815F, 0.7800075916F, 0.7814982170F, 0.7829837410F,
  142942. 0.7844641472F, 0.7859394191F, 0.7874095408F, 0.7888744965F,
  142943. 0.7903342706F, 0.7917888476F, 0.7932382124F, 0.7946823501F,
  142944. 0.7961212460F, 0.7975548855F, 0.7989832544F, 0.8004063386F,
  142945. 0.8018241244F, 0.8032365981F, 0.8046437463F, 0.8060455560F,
  142946. 0.8074420141F, 0.8088331080F, 0.8102188253F, 0.8115991536F,
  142947. 0.8129740810F, 0.8143435957F, 0.8157076861F, 0.8170663409F,
  142948. 0.8184195489F, 0.8197672994F, 0.8211095817F, 0.8224463853F,
  142949. 0.8237777001F, 0.8251035161F, 0.8264238235F, 0.8277386129F,
  142950. 0.8290478750F, 0.8303516008F, 0.8316497814F, 0.8329424083F,
  142951. 0.8342294731F, 0.8355109677F, 0.8367868841F, 0.8380572148F,
  142952. 0.8393219523F, 0.8405810893F, 0.8418346190F, 0.8430825345F,
  142953. 0.8443248294F, 0.8455614974F, 0.8467925323F, 0.8480179285F,
  142954. 0.8492376802F, 0.8504517822F, 0.8516602292F, 0.8528630164F,
  142955. 0.8540601391F, 0.8552515928F, 0.8564373733F, 0.8576174766F,
  142956. 0.8587918990F, 0.8599606368F, 0.8611236868F, 0.8622810460F,
  142957. 0.8634327113F, 0.8645786802F, 0.8657189504F, 0.8668535195F,
  142958. 0.8679823857F, 0.8691055472F, 0.8702230025F, 0.8713347503F,
  142959. 0.8724407896F, 0.8735411194F, 0.8746357394F, 0.8757246489F,
  142960. 0.8768078479F, 0.8778853364F, 0.8789571146F, 0.8800231832F,
  142961. 0.8810835427F, 0.8821381942F, 0.8831871387F, 0.8842303777F,
  142962. 0.8852679127F, 0.8862997456F, 0.8873258784F, 0.8883463132F,
  142963. 0.8893610527F, 0.8903700994F, 0.8913734562F, 0.8923711263F,
  142964. 0.8933631129F, 0.8943494196F, 0.8953300500F, 0.8963050083F,
  142965. 0.8972742985F, 0.8982379249F, 0.8991958922F, 0.9001482052F,
  142966. 0.9010948688F, 0.9020358883F, 0.9029712690F, 0.9039010165F,
  142967. 0.9048251367F, 0.9057436357F, 0.9066565195F, 0.9075637946F,
  142968. 0.9084654678F, 0.9093615456F, 0.9102520353F, 0.9111369440F,
  142969. 0.9120162792F, 0.9128900484F, 0.9137582595F, 0.9146209204F,
  142970. 0.9154780394F, 0.9163296248F, 0.9171756853F, 0.9180162296F,
  142971. 0.9188512667F, 0.9196808057F, 0.9205048559F, 0.9213234270F,
  142972. 0.9221365285F, 0.9229441704F, 0.9237463629F, 0.9245431160F,
  142973. 0.9253344404F, 0.9261203465F, 0.9269008453F, 0.9276759477F,
  142974. 0.9284456648F, 0.9292100080F, 0.9299689889F, 0.9307226190F,
  142975. 0.9314709103F, 0.9322138747F, 0.9329515245F, 0.9336838721F,
  142976. 0.9344109300F, 0.9351327108F, 0.9358492275F, 0.9365604931F,
  142977. 0.9372665208F, 0.9379673239F, 0.9386629160F, 0.9393533107F,
  142978. 0.9400385220F, 0.9407185637F, 0.9413934501F, 0.9420631954F,
  142979. 0.9427278141F, 0.9433873208F, 0.9440417304F, 0.9446910576F,
  142980. 0.9453353176F, 0.9459745255F, 0.9466086968F, 0.9472378469F,
  142981. 0.9478619915F, 0.9484811463F, 0.9490953274F, 0.9497045506F,
  142982. 0.9503088323F, 0.9509081888F, 0.9515026365F, 0.9520921921F,
  142983. 0.9526768723F, 0.9532566940F, 0.9538316742F, 0.9544018300F,
  142984. 0.9549671786F, 0.9555277375F, 0.9560835241F, 0.9566345562F,
  142985. 0.9571808513F, 0.9577224275F, 0.9582593027F, 0.9587914949F,
  142986. 0.9593190225F, 0.9598419038F, 0.9603601571F, 0.9608738012F,
  142987. 0.9613828546F, 0.9618873361F, 0.9623872646F, 0.9628826591F,
  142988. 0.9633735388F, 0.9638599227F, 0.9643418303F, 0.9648192808F,
  142989. 0.9652922939F, 0.9657608890F, 0.9662250860F, 0.9666849046F,
  142990. 0.9671403646F, 0.9675914861F, 0.9680382891F, 0.9684807937F,
  142991. 0.9689190202F, 0.9693529890F, 0.9697827203F, 0.9702082347F,
  142992. 0.9706295529F, 0.9710466953F, 0.9714596828F, 0.9718685362F,
  142993. 0.9722732762F, 0.9726739240F, 0.9730705005F, 0.9734630267F,
  142994. 0.9738515239F, 0.9742360134F, 0.9746165163F, 0.9749930540F,
  142995. 0.9753656481F, 0.9757343198F, 0.9760990909F, 0.9764599829F,
  142996. 0.9768170175F, 0.9771702164F, 0.9775196013F, 0.9778651941F,
  142997. 0.9782070167F, 0.9785450909F, 0.9788794388F, 0.9792100824F,
  142998. 0.9795370437F, 0.9798603449F, 0.9801800080F, 0.9804960554F,
  142999. 0.9808085092F, 0.9811173916F, 0.9814227251F, 0.9817245318F,
  143000. 0.9820228343F, 0.9823176549F, 0.9826090160F, 0.9828969402F,
  143001. 0.9831814498F, 0.9834625674F, 0.9837403156F, 0.9840147169F,
  143002. 0.9842857939F, 0.9845535692F, 0.9848180654F, 0.9850793052F,
  143003. 0.9853373113F, 0.9855921062F, 0.9858437127F, 0.9860921535F,
  143004. 0.9863374512F, 0.9865796287F, 0.9868187085F, 0.9870547136F,
  143005. 0.9872876664F, 0.9875175899F, 0.9877445067F, 0.9879684396F,
  143006. 0.9881894112F, 0.9884074444F, 0.9886225619F, 0.9888347863F,
  143007. 0.9890441404F, 0.9892506468F, 0.9894543284F, 0.9896552077F,
  143008. 0.9898533074F, 0.9900486502F, 0.9902412587F, 0.9904311555F,
  143009. 0.9906183633F, 0.9908029045F, 0.9909848019F, 0.9911640779F,
  143010. 0.9913407550F, 0.9915148557F, 0.9916864025F, 0.9918554179F,
  143011. 0.9920219241F, 0.9921859437F, 0.9923474989F, 0.9925066120F,
  143012. 0.9926633054F, 0.9928176012F, 0.9929695218F, 0.9931190891F,
  143013. 0.9932663254F, 0.9934112527F, 0.9935538932F, 0.9936942686F,
  143014. 0.9938324012F, 0.9939683126F, 0.9941020248F, 0.9942335597F,
  143015. 0.9943629388F, 0.9944901841F, 0.9946153170F, 0.9947383593F,
  143016. 0.9948593325F, 0.9949782579F, 0.9950951572F, 0.9952100516F,
  143017. 0.9953229625F, 0.9954339111F, 0.9955429186F, 0.9956500062F,
  143018. 0.9957551948F, 0.9958585056F, 0.9959599593F, 0.9960595769F,
  143019. 0.9961573792F, 0.9962533869F, 0.9963476206F, 0.9964401009F,
  143020. 0.9965308483F, 0.9966198833F, 0.9967072261F, 0.9967928971F,
  143021. 0.9968769164F, 0.9969593041F, 0.9970400804F, 0.9971192651F,
  143022. 0.9971968781F, 0.9972729391F, 0.9973474680F, 0.9974204842F,
  143023. 0.9974920074F, 0.9975620569F, 0.9976306521F, 0.9976978122F,
  143024. 0.9977635565F, 0.9978279039F, 0.9978908736F, 0.9979524842F,
  143025. 0.9980127547F, 0.9980717037F, 0.9981293499F, 0.9981857116F,
  143026. 0.9982408073F, 0.9982946554F, 0.9983472739F, 0.9983986810F,
  143027. 0.9984488947F, 0.9984979328F, 0.9985458132F, 0.9985925534F,
  143028. 0.9986381711F, 0.9986826838F, 0.9987261086F, 0.9987684630F,
  143029. 0.9988097640F, 0.9988500286F, 0.9988892738F, 0.9989275163F,
  143030. 0.9989647727F, 0.9990010597F, 0.9990363938F, 0.9990707911F,
  143031. 0.9991042679F, 0.9991368404F, 0.9991685244F, 0.9991993358F,
  143032. 0.9992292905F, 0.9992584038F, 0.9992866914F, 0.9993141686F,
  143033. 0.9993408506F, 0.9993667526F, 0.9993918895F, 0.9994162761F,
  143034. 0.9994399273F, 0.9994628576F, 0.9994850815F, 0.9995066133F,
  143035. 0.9995274672F, 0.9995476574F, 0.9995671978F, 0.9995861021F,
  143036. 0.9996043841F, 0.9996220573F, 0.9996391352F, 0.9996556310F,
  143037. 0.9996715579F, 0.9996869288F, 0.9997017568F, 0.9997160543F,
  143038. 0.9997298342F, 0.9997431088F, 0.9997558905F, 0.9997681914F,
  143039. 0.9997800236F, 0.9997913990F, 0.9998023292F, 0.9998128261F,
  143040. 0.9998229009F, 0.9998325650F, 0.9998418296F, 0.9998507058F,
  143041. 0.9998592044F, 0.9998673362F, 0.9998751117F, 0.9998825415F,
  143042. 0.9998896358F, 0.9998964047F, 0.9999028584F, 0.9999090066F,
  143043. 0.9999148590F, 0.9999204253F, 0.9999257148F, 0.9999307368F,
  143044. 0.9999355003F, 0.9999400144F, 0.9999442878F, 0.9999483293F,
  143045. 0.9999521472F, 0.9999557499F, 0.9999591457F, 0.9999623426F,
  143046. 0.9999653483F, 0.9999681708F, 0.9999708175F, 0.9999732959F,
  143047. 0.9999756132F, 0.9999777765F, 0.9999797928F, 0.9999816688F,
  143048. 0.9999834113F, 0.9999850266F, 0.9999865211F, 0.9999879009F,
  143049. 0.9999891721F, 0.9999903405F, 0.9999914118F, 0.9999923914F,
  143050. 0.9999932849F, 0.9999940972F, 0.9999948336F, 0.9999954989F,
  143051. 0.9999960978F, 0.9999966349F, 0.9999971146F, 0.9999975411F,
  143052. 0.9999979185F, 0.9999982507F, 0.9999985414F, 0.9999987944F,
  143053. 0.9999990129F, 0.9999992003F, 0.9999993596F, 0.9999994939F,
  143054. 0.9999996059F, 0.9999996981F, 0.9999997732F, 0.9999998333F,
  143055. 0.9999998805F, 0.9999999170F, 0.9999999444F, 0.9999999643F,
  143056. 0.9999999784F, 0.9999999878F, 0.9999999937F, 0.9999999972F,
  143057. 0.9999999990F, 0.9999999997F, 1.0000000000F, 1.0000000000F,
  143058. };
  143059. static float vwin4096[2048] = {
  143060. 0.0000002310F, 0.0000020791F, 0.0000057754F, 0.0000113197F,
  143061. 0.0000187121F, 0.0000279526F, 0.0000390412F, 0.0000519777F,
  143062. 0.0000667623F, 0.0000833949F, 0.0001018753F, 0.0001222036F,
  143063. 0.0001443798F, 0.0001684037F, 0.0001942754F, 0.0002219947F,
  143064. 0.0002515616F, 0.0002829761F, 0.0003162380F, 0.0003513472F,
  143065. 0.0003883038F, 0.0004271076F, 0.0004677584F, 0.0005102563F,
  143066. 0.0005546011F, 0.0006007928F, 0.0006488311F, 0.0006987160F,
  143067. 0.0007504474F, 0.0008040251F, 0.0008594490F, 0.0009167191F,
  143068. 0.0009758351F, 0.0010367969F, 0.0010996044F, 0.0011642574F,
  143069. 0.0012307558F, 0.0012990994F, 0.0013692880F, 0.0014413216F,
  143070. 0.0015151998F, 0.0015909226F, 0.0016684898F, 0.0017479011F,
  143071. 0.0018291565F, 0.0019122556F, 0.0019971983F, 0.0020839845F,
  143072. 0.0021726138F, 0.0022630861F, 0.0023554012F, 0.0024495588F,
  143073. 0.0025455588F, 0.0026434008F, 0.0027430847F, 0.0028446103F,
  143074. 0.0029479772F, 0.0030531853F, 0.0031602342F, 0.0032691238F,
  143075. 0.0033798538F, 0.0034924239F, 0.0036068338F, 0.0037230833F,
  143076. 0.0038411721F, 0.0039610999F, 0.0040828664F, 0.0042064714F,
  143077. 0.0043319145F, 0.0044591954F, 0.0045883139F, 0.0047192696F,
  143078. 0.0048520622F, 0.0049866914F, 0.0051231569F, 0.0052614583F,
  143079. 0.0054015953F, 0.0055435676F, 0.0056873748F, 0.0058330166F,
  143080. 0.0059804926F, 0.0061298026F, 0.0062809460F, 0.0064339226F,
  143081. 0.0065887320F, 0.0067453738F, 0.0069038476F, 0.0070641531F,
  143082. 0.0072262899F, 0.0073902575F, 0.0075560556F, 0.0077236838F,
  143083. 0.0078931417F, 0.0080644288F, 0.0082375447F, 0.0084124891F,
  143084. 0.0085892615F, 0.0087678614F, 0.0089482885F, 0.0091305422F,
  143085. 0.0093146223F, 0.0095005281F, 0.0096882592F, 0.0098778153F,
  143086. 0.0100691958F, 0.0102624002F, 0.0104574281F, 0.0106542791F,
  143087. 0.0108529525F, 0.0110534480F, 0.0112557651F, 0.0114599032F,
  143088. 0.0116658618F, 0.0118736405F, 0.0120832387F, 0.0122946560F,
  143089. 0.0125078917F, 0.0127229454F, 0.0129398166F, 0.0131585046F,
  143090. 0.0133790090F, 0.0136013292F, 0.0138254647F, 0.0140514149F,
  143091. 0.0142791792F, 0.0145087572F, 0.0147401481F, 0.0149733515F,
  143092. 0.0152083667F, 0.0154451932F, 0.0156838304F, 0.0159242777F,
  143093. 0.0161665345F, 0.0164106001F, 0.0166564741F, 0.0169041557F,
  143094. 0.0171536443F, 0.0174049393F, 0.0176580401F, 0.0179129461F,
  143095. 0.0181696565F, 0.0184281708F, 0.0186884883F, 0.0189506084F,
  143096. 0.0192145303F, 0.0194802535F, 0.0197477772F, 0.0200171008F,
  143097. 0.0202882236F, 0.0205611449F, 0.0208358639F, 0.0211123801F,
  143098. 0.0213906927F, 0.0216708011F, 0.0219527043F, 0.0222364019F,
  143099. 0.0225218930F, 0.0228091769F, 0.0230982529F, 0.0233891203F,
  143100. 0.0236817782F, 0.0239762259F, 0.0242724628F, 0.0245704880F,
  143101. 0.0248703007F, 0.0251719002F, 0.0254752858F, 0.0257804565F,
  143102. 0.0260874117F, 0.0263961506F, 0.0267066722F, 0.0270189760F,
  143103. 0.0273330609F, 0.0276489263F, 0.0279665712F, 0.0282859949F,
  143104. 0.0286071966F, 0.0289301753F, 0.0292549303F, 0.0295814607F,
  143105. 0.0299097656F, 0.0302398442F, 0.0305716957F, 0.0309053191F,
  143106. 0.0312407135F, 0.0315778782F, 0.0319168122F, 0.0322575145F,
  143107. 0.0325999844F, 0.0329442209F, 0.0332902231F, 0.0336379900F,
  143108. 0.0339875208F, 0.0343388146F, 0.0346918703F, 0.0350466871F,
  143109. 0.0354032640F, 0.0357616000F, 0.0361216943F, 0.0364835458F,
  143110. 0.0368471535F, 0.0372125166F, 0.0375796339F, 0.0379485046F,
  143111. 0.0383191276F, 0.0386915020F, 0.0390656267F, 0.0394415008F,
  143112. 0.0398191231F, 0.0401984927F, 0.0405796086F, 0.0409624698F,
  143113. 0.0413470751F, 0.0417334235F, 0.0421215141F, 0.0425113457F,
  143114. 0.0429029172F, 0.0432962277F, 0.0436912760F, 0.0440880610F,
  143115. 0.0444865817F, 0.0448868370F, 0.0452888257F, 0.0456925468F,
  143116. 0.0460979992F, 0.0465051816F, 0.0469140931F, 0.0473247325F,
  143117. 0.0477370986F, 0.0481511902F, 0.0485670064F, 0.0489845458F,
  143118. 0.0494038074F, 0.0498247899F, 0.0502474922F, 0.0506719131F,
  143119. 0.0510980514F, 0.0515259060F, 0.0519554756F, 0.0523867590F,
  143120. 0.0528197550F, 0.0532544624F, 0.0536908800F, 0.0541290066F,
  143121. 0.0545688408F, 0.0550103815F, 0.0554536274F, 0.0558985772F,
  143122. 0.0563452297F, 0.0567935837F, 0.0572436377F, 0.0576953907F,
  143123. 0.0581488412F, 0.0586039880F, 0.0590608297F, 0.0595193651F,
  143124. 0.0599795929F, 0.0604415117F, 0.0609051202F, 0.0613704170F,
  143125. 0.0618374009F, 0.0623060704F, 0.0627764243F, 0.0632484611F,
  143126. 0.0637221795F, 0.0641975781F, 0.0646746555F, 0.0651534104F,
  143127. 0.0656338413F, 0.0661159469F, 0.0665997257F, 0.0670851763F,
  143128. 0.0675722973F, 0.0680610873F, 0.0685515448F, 0.0690436684F,
  143129. 0.0695374567F, 0.0700329081F, 0.0705300213F, 0.0710287947F,
  143130. 0.0715292269F, 0.0720313163F, 0.0725350616F, 0.0730404612F,
  143131. 0.0735475136F, 0.0740562172F, 0.0745665707F, 0.0750785723F,
  143132. 0.0755922207F, 0.0761075143F, 0.0766244515F, 0.0771430307F,
  143133. 0.0776632505F, 0.0781851092F, 0.0787086052F, 0.0792337371F,
  143134. 0.0797605032F, 0.0802889018F, 0.0808189315F, 0.0813505905F,
  143135. 0.0818838773F, 0.0824187903F, 0.0829553277F, 0.0834934881F,
  143136. 0.0840332697F, 0.0845746708F, 0.0851176899F, 0.0856623252F,
  143137. 0.0862085751F, 0.0867564379F, 0.0873059119F, 0.0878569954F,
  143138. 0.0884096867F, 0.0889639840F, 0.0895198858F, 0.0900773902F,
  143139. 0.0906364955F, 0.0911972000F, 0.0917595019F, 0.0923233995F,
  143140. 0.0928888909F, 0.0934559745F, 0.0940246485F, 0.0945949110F,
  143141. 0.0951667604F, 0.0957401946F, 0.0963152121F, 0.0968918109F,
  143142. 0.0974699893F, 0.0980497454F, 0.0986310773F, 0.0992139832F,
  143143. 0.0997984614F, 0.1003845098F, 0.1009721267F, 0.1015613101F,
  143144. 0.1021520582F, 0.1027443692F, 0.1033382410F, 0.1039336718F,
  143145. 0.1045306597F, 0.1051292027F, 0.1057292990F, 0.1063309466F,
  143146. 0.1069341435F, 0.1075388878F, 0.1081451776F, 0.1087530108F,
  143147. 0.1093623856F, 0.1099732998F, 0.1105857516F, 0.1111997389F,
  143148. 0.1118152597F, 0.1124323121F, 0.1130508939F, 0.1136710032F,
  143149. 0.1142926379F, 0.1149157960F, 0.1155404755F, 0.1161666742F,
  143150. 0.1167943901F, 0.1174236211F, 0.1180543652F, 0.1186866202F,
  143151. 0.1193203841F, 0.1199556548F, 0.1205924300F, 0.1212307078F,
  143152. 0.1218704860F, 0.1225117624F, 0.1231545349F, 0.1237988013F,
  143153. 0.1244445596F, 0.1250918074F, 0.1257405427F, 0.1263907632F,
  143154. 0.1270424667F, 0.1276956512F, 0.1283503142F, 0.1290064537F,
  143155. 0.1296640674F, 0.1303231530F, 0.1309837084F, 0.1316457312F,
  143156. 0.1323092193F, 0.1329741703F, 0.1336405820F, 0.1343084520F,
  143157. 0.1349777782F, 0.1356485582F, 0.1363207897F, 0.1369944704F,
  143158. 0.1376695979F, 0.1383461700F, 0.1390241842F, 0.1397036384F,
  143159. 0.1403845300F, 0.1410668567F, 0.1417506162F, 0.1424358061F,
  143160. 0.1431224240F, 0.1438104674F, 0.1444999341F, 0.1451908216F,
  143161. 0.1458831274F, 0.1465768492F, 0.1472719844F, 0.1479685308F,
  143162. 0.1486664857F, 0.1493658468F, 0.1500666115F, 0.1507687775F,
  143163. 0.1514723422F, 0.1521773031F, 0.1528836577F, 0.1535914035F,
  143164. 0.1543005380F, 0.1550110587F, 0.1557229631F, 0.1564362485F,
  143165. 0.1571509124F, 0.1578669524F, 0.1585843657F, 0.1593031499F,
  143166. 0.1600233024F, 0.1607448205F, 0.1614677017F, 0.1621919433F,
  143167. 0.1629175428F, 0.1636444975F, 0.1643728047F, 0.1651024619F,
  143168. 0.1658334665F, 0.1665658156F, 0.1672995067F, 0.1680345371F,
  143169. 0.1687709041F, 0.1695086050F, 0.1702476372F, 0.1709879978F,
  143170. 0.1717296843F, 0.1724726938F, 0.1732170237F, 0.1739626711F,
  143171. 0.1747096335F, 0.1754579079F, 0.1762074916F, 0.1769583819F,
  143172. 0.1777105760F, 0.1784640710F, 0.1792188642F, 0.1799749529F,
  143173. 0.1807323340F, 0.1814910049F, 0.1822509628F, 0.1830122046F,
  143174. 0.1837747277F, 0.1845385292F, 0.1853036062F, 0.1860699558F,
  143175. 0.1868375751F, 0.1876064613F, 0.1883766114F, 0.1891480226F,
  143176. 0.1899206919F, 0.1906946164F, 0.1914697932F, 0.1922462194F,
  143177. 0.1930238919F, 0.1938028079F, 0.1945829643F, 0.1953643583F,
  143178. 0.1961469868F, 0.1969308468F, 0.1977159353F, 0.1985022494F,
  143179. 0.1992897859F, 0.2000785420F, 0.2008685145F, 0.2016597005F,
  143180. 0.2024520968F, 0.2032457005F, 0.2040405084F, 0.2048365175F,
  143181. 0.2056337247F, 0.2064321269F, 0.2072317211F, 0.2080325041F,
  143182. 0.2088344727F, 0.2096376240F, 0.2104419547F, 0.2112474618F,
  143183. 0.2120541420F, 0.2128619923F, 0.2136710094F, 0.2144811902F,
  143184. 0.2152925315F, 0.2161050301F, 0.2169186829F, 0.2177334866F,
  143185. 0.2185494381F, 0.2193665340F, 0.2201847712F, 0.2210041465F,
  143186. 0.2218246565F, 0.2226462981F, 0.2234690680F, 0.2242929629F,
  143187. 0.2251179796F, 0.2259441147F, 0.2267713650F, 0.2275997272F,
  143188. 0.2284291979F, 0.2292597739F, 0.2300914518F, 0.2309242283F,
  143189. 0.2317581001F, 0.2325930638F, 0.2334291160F, 0.2342662534F,
  143190. 0.2351044727F, 0.2359437703F, 0.2367841431F, 0.2376255875F,
  143191. 0.2384681001F, 0.2393116776F, 0.2401563165F, 0.2410020134F,
  143192. 0.2418487649F, 0.2426965675F, 0.2435454178F, 0.2443953122F,
  143193. 0.2452462474F, 0.2460982199F, 0.2469512262F, 0.2478052628F,
  143194. 0.2486603262F, 0.2495164129F, 0.2503735194F, 0.2512316421F,
  143195. 0.2520907776F, 0.2529509222F, 0.2538120726F, 0.2546742250F,
  143196. 0.2555373760F, 0.2564015219F, 0.2572666593F, 0.2581327845F,
  143197. 0.2589998939F, 0.2598679840F, 0.2607370510F, 0.2616070916F,
  143198. 0.2624781019F, 0.2633500783F, 0.2642230173F, 0.2650969152F,
  143199. 0.2659717684F, 0.2668475731F, 0.2677243257F, 0.2686020226F,
  143200. 0.2694806601F, 0.2703602344F, 0.2712407419F, 0.2721221789F,
  143201. 0.2730045417F, 0.2738878265F, 0.2747720297F, 0.2756571474F,
  143202. 0.2765431760F, 0.2774301117F, 0.2783179508F, 0.2792066895F,
  143203. 0.2800963240F, 0.2809868505F, 0.2818782654F, 0.2827705647F,
  143204. 0.2836637447F, 0.2845578016F, 0.2854527315F, 0.2863485307F,
  143205. 0.2872451953F, 0.2881427215F, 0.2890411055F, 0.2899403433F,
  143206. 0.2908404312F, 0.2917413654F, 0.2926431418F, 0.2935457567F,
  143207. 0.2944492061F, 0.2953534863F, 0.2962585932F, 0.2971645230F,
  143208. 0.2980712717F, 0.2989788356F, 0.2998872105F, 0.3007963927F,
  143209. 0.3017063781F, 0.3026171629F, 0.3035287430F, 0.3044411145F,
  143210. 0.3053542736F, 0.3062682161F, 0.3071829381F, 0.3080984356F,
  143211. 0.3090147047F, 0.3099317413F, 0.3108495414F, 0.3117681011F,
  143212. 0.3126874163F, 0.3136074830F, 0.3145282972F, 0.3154498548F,
  143213. 0.3163721517F, 0.3172951841F, 0.3182189477F, 0.3191434385F,
  143214. 0.3200686525F, 0.3209945856F, 0.3219212336F, 0.3228485927F,
  143215. 0.3237766585F, 0.3247054271F, 0.3256348943F, 0.3265650560F,
  143216. 0.3274959081F, 0.3284274465F, 0.3293596671F, 0.3302925657F,
  143217. 0.3312261382F, 0.3321603804F, 0.3330952882F, 0.3340308574F,
  143218. 0.3349670838F, 0.3359039634F, 0.3368414919F, 0.3377796651F,
  143219. 0.3387184789F, 0.3396579290F, 0.3405980113F, 0.3415387216F,
  143220. 0.3424800556F, 0.3434220091F, 0.3443645779F, 0.3453077578F,
  143221. 0.3462515446F, 0.3471959340F, 0.3481409217F, 0.3490865036F,
  143222. 0.3500326754F, 0.3509794328F, 0.3519267715F, 0.3528746873F,
  143223. 0.3538231759F, 0.3547722330F, 0.3557218544F, 0.3566720357F,
  143224. 0.3576227727F, 0.3585740610F, 0.3595258964F, 0.3604782745F,
  143225. 0.3614311910F, 0.3623846417F, 0.3633386221F, 0.3642931280F,
  143226. 0.3652481549F, 0.3662036987F, 0.3671597548F, 0.3681163191F,
  143227. 0.3690733870F, 0.3700309544F, 0.3709890167F, 0.3719475696F,
  143228. 0.3729066089F, 0.3738661299F, 0.3748261285F, 0.3757866002F,
  143229. 0.3767475406F, 0.3777089453F, 0.3786708100F, 0.3796331302F,
  143230. 0.3805959014F, 0.3815591194F, 0.3825227796F, 0.3834868777F,
  143231. 0.3844514093F, 0.3854163698F, 0.3863817549F, 0.3873475601F,
  143232. 0.3883137810F, 0.3892804131F, 0.3902474521F, 0.3912148933F,
  143233. 0.3921827325F, 0.3931509650F, 0.3941195865F, 0.3950885925F,
  143234. 0.3960579785F, 0.3970277400F, 0.3979978725F, 0.3989683716F,
  143235. 0.3999392328F, 0.4009104516F, 0.4018820234F, 0.4028539438F,
  143236. 0.4038262084F, 0.4047988125F, 0.4057717516F, 0.4067450214F,
  143237. 0.4077186172F, 0.4086925345F, 0.4096667688F, 0.4106413155F,
  143238. 0.4116161703F, 0.4125913284F, 0.4135667854F, 0.4145425368F,
  143239. 0.4155185780F, 0.4164949044F, 0.4174715116F, 0.4184483949F,
  143240. 0.4194255498F, 0.4204029718F, 0.4213806563F, 0.4223585987F,
  143241. 0.4233367946F, 0.4243152392F, 0.4252939281F, 0.4262728566F,
  143242. 0.4272520202F, 0.4282314144F, 0.4292110345F, 0.4301908760F,
  143243. 0.4311709343F, 0.4321512047F, 0.4331316828F, 0.4341123639F,
  143244. 0.4350932435F, 0.4360743168F, 0.4370555794F, 0.4380370267F,
  143245. 0.4390186540F, 0.4400004567F, 0.4409824303F, 0.4419645701F,
  143246. 0.4429468716F, 0.4439293300F, 0.4449119409F, 0.4458946996F,
  143247. 0.4468776014F, 0.4478606418F, 0.4488438162F, 0.4498271199F,
  143248. 0.4508105483F, 0.4517940967F, 0.4527777607F, 0.4537615355F,
  143249. 0.4547454165F, 0.4557293991F, 0.4567134786F, 0.4576976505F,
  143250. 0.4586819101F, 0.4596662527F, 0.4606506738F, 0.4616351687F,
  143251. 0.4626197328F, 0.4636043614F, 0.4645890499F, 0.4655737936F,
  143252. 0.4665585880F, 0.4675434284F, 0.4685283101F, 0.4695132286F,
  143253. 0.4704981791F, 0.4714831570F, 0.4724681577F, 0.4734531766F,
  143254. 0.4744382089F, 0.4754232501F, 0.4764082956F, 0.4773933406F,
  143255. 0.4783783806F, 0.4793634108F, 0.4803484267F, 0.4813334237F,
  143256. 0.4823183969F, 0.4833033419F, 0.4842882540F, 0.4852731285F,
  143257. 0.4862579608F, 0.4872427462F, 0.4882274802F, 0.4892121580F,
  143258. 0.4901967751F, 0.4911813267F, 0.4921658083F, 0.4931502151F,
  143259. 0.4941345427F, 0.4951187863F, 0.4961029412F, 0.4970870029F,
  143260. 0.4980709667F, 0.4990548280F, 0.5000385822F, 0.5010222245F,
  143261. 0.5020057505F, 0.5029891553F, 0.5039724345F, 0.5049555834F,
  143262. 0.5059385973F, 0.5069214716F, 0.5079042018F, 0.5088867831F,
  143263. 0.5098692110F, 0.5108514808F, 0.5118335879F, 0.5128155277F,
  143264. 0.5137972956F, 0.5147788869F, 0.5157602971F, 0.5167415215F,
  143265. 0.5177225555F, 0.5187033945F, 0.5196840339F, 0.5206644692F,
  143266. 0.5216446956F, 0.5226247086F, 0.5236045035F, 0.5245840759F,
  143267. 0.5255634211F, 0.5265425344F, 0.5275214114F, 0.5285000474F,
  143268. 0.5294784378F, 0.5304565781F, 0.5314344637F, 0.5324120899F,
  143269. 0.5333894522F, 0.5343665461F, 0.5353433670F, 0.5363199102F,
  143270. 0.5372961713F, 0.5382721457F, 0.5392478287F, 0.5402232159F,
  143271. 0.5411983027F, 0.5421730845F, 0.5431475569F, 0.5441217151F,
  143272. 0.5450955548F, 0.5460690714F, 0.5470422602F, 0.5480151169F,
  143273. 0.5489876368F, 0.5499598155F, 0.5509316484F, 0.5519031310F,
  143274. 0.5528742587F, 0.5538450271F, 0.5548154317F, 0.5557854680F,
  143275. 0.5567551314F, 0.5577244174F, 0.5586933216F, 0.5596618395F,
  143276. 0.5606299665F, 0.5615976983F, 0.5625650302F, 0.5635319580F,
  143277. 0.5644984770F, 0.5654645828F, 0.5664302709F, 0.5673955370F,
  143278. 0.5683603765F, 0.5693247850F, 0.5702887580F, 0.5712522912F,
  143279. 0.5722153800F, 0.5731780200F, 0.5741402069F, 0.5751019362F,
  143280. 0.5760632034F, 0.5770240042F, 0.5779843341F, 0.5789441889F,
  143281. 0.5799035639F, 0.5808624549F, 0.5818208575F, 0.5827787673F,
  143282. 0.5837361800F, 0.5846930910F, 0.5856494961F, 0.5866053910F,
  143283. 0.5875607712F, 0.5885156324F, 0.5894699703F, 0.5904237804F,
  143284. 0.5913770586F, 0.5923298004F, 0.5932820016F, 0.5942336578F,
  143285. 0.5951847646F, 0.5961353179F, 0.5970853132F, 0.5980347464F,
  143286. 0.5989836131F, 0.5999319090F, 0.6008796298F, 0.6018267713F,
  143287. 0.6027733292F, 0.6037192993F, 0.6046646773F, 0.6056094589F,
  143288. 0.6065536400F, 0.6074972162F, 0.6084401833F, 0.6093825372F,
  143289. 0.6103242736F, 0.6112653884F, 0.6122058772F, 0.6131457359F,
  143290. 0.6140849604F, 0.6150235464F, 0.6159614897F, 0.6168987862F,
  143291. 0.6178354318F, 0.6187714223F, 0.6197067535F, 0.6206414213F,
  143292. 0.6215754215F, 0.6225087501F, 0.6234414028F, 0.6243733757F,
  143293. 0.6253046646F, 0.6262352654F, 0.6271651739F, 0.6280943862F,
  143294. 0.6290228982F, 0.6299507057F, 0.6308778048F, 0.6318041913F,
  143295. 0.6327298612F, 0.6336548105F, 0.6345790352F, 0.6355025312F,
  143296. 0.6364252945F, 0.6373473211F, 0.6382686070F, 0.6391891483F,
  143297. 0.6401089409F, 0.6410279808F, 0.6419462642F, 0.6428637869F,
  143298. 0.6437805452F, 0.6446965350F, 0.6456117524F, 0.6465261935F,
  143299. 0.6474398544F, 0.6483527311F, 0.6492648197F, 0.6501761165F,
  143300. 0.6510866174F, 0.6519963186F, 0.6529052162F, 0.6538133064F,
  143301. 0.6547205854F, 0.6556270492F, 0.6565326941F, 0.6574375162F,
  143302. 0.6583415117F, 0.6592446769F, 0.6601470079F, 0.6610485009F,
  143303. 0.6619491521F, 0.6628489578F, 0.6637479143F, 0.6646460177F,
  143304. 0.6655432643F, 0.6664396505F, 0.6673351724F, 0.6682298264F,
  143305. 0.6691236087F, 0.6700165157F, 0.6709085436F, 0.6717996889F,
  143306. 0.6726899478F, 0.6735793167F, 0.6744677918F, 0.6753553697F,
  143307. 0.6762420466F, 0.6771278190F, 0.6780126832F, 0.6788966357F,
  143308. 0.6797796728F, 0.6806617909F, 0.6815429866F, 0.6824232562F,
  143309. 0.6833025961F, 0.6841810030F, 0.6850584731F, 0.6859350031F,
  143310. 0.6868105894F, 0.6876852284F, 0.6885589168F, 0.6894316510F,
  143311. 0.6903034275F, 0.6911742430F, 0.6920440939F, 0.6929129769F,
  143312. 0.6937808884F, 0.6946478251F, 0.6955137837F, 0.6963787606F,
  143313. 0.6972427525F, 0.6981057560F, 0.6989677678F, 0.6998287845F,
  143314. 0.7006888028F, 0.7015478194F, 0.7024058309F, 0.7032628340F,
  143315. 0.7041188254F, 0.7049738019F, 0.7058277601F, 0.7066806969F,
  143316. 0.7075326089F, 0.7083834929F, 0.7092333457F, 0.7100821640F,
  143317. 0.7109299447F, 0.7117766846F, 0.7126223804F, 0.7134670291F,
  143318. 0.7143106273F, 0.7151531721F, 0.7159946602F, 0.7168350885F,
  143319. 0.7176744539F, 0.7185127534F, 0.7193499837F, 0.7201861418F,
  143320. 0.7210212247F, 0.7218552293F, 0.7226881526F, 0.7235199914F,
  143321. 0.7243507428F, 0.7251804039F, 0.7260089715F, 0.7268364426F,
  143322. 0.7276628144F, 0.7284880839F, 0.7293122481F, 0.7301353040F,
  143323. 0.7309572487F, 0.7317780794F, 0.7325977930F, 0.7334163868F,
  143324. 0.7342338579F, 0.7350502033F, 0.7358654202F, 0.7366795059F,
  143325. 0.7374924573F, 0.7383042718F, 0.7391149465F, 0.7399244787F,
  143326. 0.7407328655F, 0.7415401041F, 0.7423461920F, 0.7431511261F,
  143327. 0.7439549040F, 0.7447575227F, 0.7455589797F, 0.7463592723F,
  143328. 0.7471583976F, 0.7479563532F, 0.7487531363F, 0.7495487443F,
  143329. 0.7503431745F, 0.7511364244F, 0.7519284913F, 0.7527193726F,
  143330. 0.7535090658F, 0.7542975683F, 0.7550848776F, 0.7558709910F,
  143331. 0.7566559062F, 0.7574396205F, 0.7582221314F, 0.7590034366F,
  143332. 0.7597835334F, 0.7605624194F, 0.7613400923F, 0.7621165495F,
  143333. 0.7628917886F, 0.7636658072F, 0.7644386030F, 0.7652101735F,
  143334. 0.7659805164F, 0.7667496292F, 0.7675175098F, 0.7682841556F,
  143335. 0.7690495645F, 0.7698137341F, 0.7705766622F, 0.7713383463F,
  143336. 0.7720987844F, 0.7728579741F, 0.7736159132F, 0.7743725994F,
  143337. 0.7751280306F, 0.7758822046F, 0.7766351192F, 0.7773867722F,
  143338. 0.7781371614F, 0.7788862848F, 0.7796341401F, 0.7803807253F,
  143339. 0.7811260383F, 0.7818700769F, 0.7826128392F, 0.7833543230F,
  143340. 0.7840945263F, 0.7848334471F, 0.7855710833F, 0.7863074330F,
  143341. 0.7870424941F, 0.7877762647F, 0.7885087428F, 0.7892399264F,
  143342. 0.7899698137F, 0.7906984026F, 0.7914256914F, 0.7921516780F,
  143343. 0.7928763607F, 0.7935997375F, 0.7943218065F, 0.7950425661F,
  143344. 0.7957620142F, 0.7964801492F, 0.7971969692F, 0.7979124724F,
  143345. 0.7986266570F, 0.7993395214F, 0.8000510638F, 0.8007612823F,
  143346. 0.8014701754F, 0.8021777413F, 0.8028839784F, 0.8035888849F,
  143347. 0.8042924592F, 0.8049946997F, 0.8056956048F, 0.8063951727F,
  143348. 0.8070934020F, 0.8077902910F, 0.8084858381F, 0.8091800419F,
  143349. 0.8098729007F, 0.8105644130F, 0.8112545774F, 0.8119433922F,
  143350. 0.8126308561F, 0.8133169676F, 0.8140017251F, 0.8146851272F,
  143351. 0.8153671726F, 0.8160478598F, 0.8167271874F, 0.8174051539F,
  143352. 0.8180817582F, 0.8187569986F, 0.8194308741F, 0.8201033831F,
  143353. 0.8207745244F, 0.8214442966F, 0.8221126986F, 0.8227797290F,
  143354. 0.8234453865F, 0.8241096700F, 0.8247725781F, 0.8254341097F,
  143355. 0.8260942636F, 0.8267530385F, 0.8274104334F, 0.8280664470F,
  143356. 0.8287210782F, 0.8293743259F, 0.8300261889F, 0.8306766662F,
  143357. 0.8313257566F, 0.8319734591F, 0.8326197727F, 0.8332646963F,
  143358. 0.8339082288F, 0.8345503692F, 0.8351911167F, 0.8358304700F,
  143359. 0.8364684284F, 0.8371049907F, 0.8377401562F, 0.8383739238F,
  143360. 0.8390062927F, 0.8396372618F, 0.8402668305F, 0.8408949977F,
  143361. 0.8415217626F, 0.8421471245F, 0.8427710823F, 0.8433936354F,
  143362. 0.8440147830F, 0.8446345242F, 0.8452528582F, 0.8458697844F,
  143363. 0.8464853020F, 0.8470994102F, 0.8477121084F, 0.8483233958F,
  143364. 0.8489332718F, 0.8495417356F, 0.8501487866F, 0.8507544243F,
  143365. 0.8513586479F, 0.8519614568F, 0.8525628505F, 0.8531628283F,
  143366. 0.8537613897F, 0.8543585341F, 0.8549542611F, 0.8555485699F,
  143367. 0.8561414603F, 0.8567329315F, 0.8573229832F, 0.8579116149F,
  143368. 0.8584988262F, 0.8590846165F, 0.8596689855F, 0.8602519327F,
  143369. 0.8608334577F, 0.8614135603F, 0.8619922399F, 0.8625694962F,
  143370. 0.8631453289F, 0.8637197377F, 0.8642927222F, 0.8648642821F,
  143371. 0.8654344172F, 0.8660031272F, 0.8665704118F, 0.8671362708F,
  143372. 0.8677007039F, 0.8682637109F, 0.8688252917F, 0.8693854460F,
  143373. 0.8699441737F, 0.8705014745F, 0.8710573485F, 0.8716117953F,
  143374. 0.8721648150F, 0.8727164073F, 0.8732665723F, 0.8738153098F,
  143375. 0.8743626197F, 0.8749085021F, 0.8754529569F, 0.8759959840F,
  143376. 0.8765375835F, 0.8770777553F, 0.8776164996F, 0.8781538162F,
  143377. 0.8786897054F, 0.8792241670F, 0.8797572013F, 0.8802888082F,
  143378. 0.8808189880F, 0.8813477407F, 0.8818750664F, 0.8824009653F,
  143379. 0.8829254375F, 0.8834484833F, 0.8839701028F, 0.8844902961F,
  143380. 0.8850090636F, 0.8855264054F, 0.8860423218F, 0.8865568131F,
  143381. 0.8870698794F, 0.8875815212F, 0.8880917386F, 0.8886005319F,
  143382. 0.8891079016F, 0.8896138479F, 0.8901183712F, 0.8906214719F,
  143383. 0.8911231503F, 0.8916234067F, 0.8921222417F, 0.8926196556F,
  143384. 0.8931156489F, 0.8936102219F, 0.8941033752F, 0.8945951092F,
  143385. 0.8950854244F, 0.8955743212F, 0.8960618003F, 0.8965478621F,
  143386. 0.8970325071F, 0.8975157359F, 0.8979975490F, 0.8984779471F,
  143387. 0.8989569307F, 0.8994345004F, 0.8999106568F, 0.9003854005F,
  143388. 0.9008587323F, 0.9013306526F, 0.9018011623F, 0.9022702619F,
  143389. 0.9027379521F, 0.9032042337F, 0.9036691074F, 0.9041325739F,
  143390. 0.9045946339F, 0.9050552882F, 0.9055145376F, 0.9059723828F,
  143391. 0.9064288246F, 0.9068838638F, 0.9073375013F, 0.9077897379F,
  143392. 0.9082405743F, 0.9086900115F, 0.9091380503F, 0.9095846917F,
  143393. 0.9100299364F, 0.9104737854F, 0.9109162397F, 0.9113573001F,
  143394. 0.9117969675F, 0.9122352430F, 0.9126721275F, 0.9131076219F,
  143395. 0.9135417273F, 0.9139744447F, 0.9144057750F, 0.9148357194F,
  143396. 0.9152642787F, 0.9156914542F, 0.9161172468F, 0.9165416576F,
  143397. 0.9169646877F, 0.9173863382F, 0.9178066102F, 0.9182255048F,
  143398. 0.9186430232F, 0.9190591665F, 0.9194739359F, 0.9198873324F,
  143399. 0.9202993574F, 0.9207100120F, 0.9211192973F, 0.9215272147F,
  143400. 0.9219337653F, 0.9223389504F, 0.9227427713F, 0.9231452290F,
  143401. 0.9235463251F, 0.9239460607F, 0.9243444371F, 0.9247414557F,
  143402. 0.9251371177F, 0.9255314245F, 0.9259243774F, 0.9263159778F,
  143403. 0.9267062270F, 0.9270951264F, 0.9274826774F, 0.9278688814F,
  143404. 0.9282537398F, 0.9286372540F, 0.9290194254F, 0.9294002555F,
  143405. 0.9297797458F, 0.9301578976F, 0.9305347125F, 0.9309101919F,
  143406. 0.9312843373F, 0.9316571503F, 0.9320286323F, 0.9323987849F,
  143407. 0.9327676097F, 0.9331351080F, 0.9335012816F, 0.9338661320F,
  143408. 0.9342296607F, 0.9345918694F, 0.9349527596F, 0.9353123330F,
  143409. 0.9356705911F, 0.9360275357F, 0.9363831683F, 0.9367374905F,
  143410. 0.9370905042F, 0.9374422108F, 0.9377926122F, 0.9381417099F,
  143411. 0.9384895057F, 0.9388360014F, 0.9391811985F, 0.9395250989F,
  143412. 0.9398677043F, 0.9402090165F, 0.9405490371F, 0.9408877680F,
  143413. 0.9412252110F, 0.9415613678F, 0.9418962402F, 0.9422298301F,
  143414. 0.9425621392F, 0.9428931695F, 0.9432229226F, 0.9435514005F,
  143415. 0.9438786050F, 0.9442045381F, 0.9445292014F, 0.9448525971F,
  143416. 0.9451747268F, 0.9454955926F, 0.9458151963F, 0.9461335399F,
  143417. 0.9464506253F, 0.9467664545F, 0.9470810293F, 0.9473943517F,
  143418. 0.9477064238F, 0.9480172474F, 0.9483268246F, 0.9486351573F,
  143419. 0.9489422475F, 0.9492480973F, 0.9495527087F, 0.9498560837F,
  143420. 0.9501582243F, 0.9504591325F, 0.9507588105F, 0.9510572603F,
  143421. 0.9513544839F, 0.9516504834F, 0.9519452609F, 0.9522388186F,
  143422. 0.9525311584F, 0.9528222826F, 0.9531121932F, 0.9534008923F,
  143423. 0.9536883821F, 0.9539746647F, 0.9542597424F, 0.9545436171F,
  143424. 0.9548262912F, 0.9551077667F, 0.9553880459F, 0.9556671309F,
  143425. 0.9559450239F, 0.9562217272F, 0.9564972429F, 0.9567715733F,
  143426. 0.9570447206F, 0.9573166871F, 0.9575874749F, 0.9578570863F,
  143427. 0.9581255236F, 0.9583927890F, 0.9586588849F, 0.9589238134F,
  143428. 0.9591875769F, 0.9594501777F, 0.9597116180F, 0.9599719003F,
  143429. 0.9602310267F, 0.9604889995F, 0.9607458213F, 0.9610014942F,
  143430. 0.9612560206F, 0.9615094028F, 0.9617616433F, 0.9620127443F,
  143431. 0.9622627083F, 0.9625115376F, 0.9627592345F, 0.9630058016F,
  143432. 0.9632512411F, 0.9634955555F, 0.9637387471F, 0.9639808185F,
  143433. 0.9642217720F, 0.9644616100F, 0.9647003349F, 0.9649379493F,
  143434. 0.9651744556F, 0.9654098561F, 0.9656441534F, 0.9658773499F,
  143435. 0.9661094480F, 0.9663404504F, 0.9665703593F, 0.9667991774F,
  143436. 0.9670269071F, 0.9672535509F, 0.9674791114F, 0.9677035909F,
  143437. 0.9679269921F, 0.9681493174F, 0.9683705694F, 0.9685907506F,
  143438. 0.9688098636F, 0.9690279108F, 0.9692448948F, 0.9694608182F,
  143439. 0.9696756836F, 0.9698894934F, 0.9701022503F, 0.9703139569F,
  143440. 0.9705246156F, 0.9707342291F, 0.9709428000F, 0.9711503309F,
  143441. 0.9713568243F, 0.9715622829F, 0.9717667093F, 0.9719701060F,
  143442. 0.9721724757F, 0.9723738210F, 0.9725741446F, 0.9727734490F,
  143443. 0.9729717369F, 0.9731690109F, 0.9733652737F, 0.9735605279F,
  143444. 0.9737547762F, 0.9739480212F, 0.9741402656F, 0.9743315120F,
  143445. 0.9745217631F, 0.9747110216F, 0.9748992901F, 0.9750865714F,
  143446. 0.9752728681F, 0.9754581829F, 0.9756425184F, 0.9758258775F,
  143447. 0.9760082627F, 0.9761896768F, 0.9763701224F, 0.9765496024F,
  143448. 0.9767281193F, 0.9769056760F, 0.9770822751F, 0.9772579193F,
  143449. 0.9774326114F, 0.9776063542F, 0.9777791502F, 0.9779510023F,
  143450. 0.9781219133F, 0.9782918858F, 0.9784609226F, 0.9786290264F,
  143451. 0.9787962000F, 0.9789624461F, 0.9791277676F, 0.9792921671F,
  143452. 0.9794556474F, 0.9796182113F, 0.9797798615F, 0.9799406009F,
  143453. 0.9801004321F, 0.9802593580F, 0.9804173813F, 0.9805745049F,
  143454. 0.9807307314F, 0.9808860637F, 0.9810405046F, 0.9811940568F,
  143455. 0.9813467232F, 0.9814985065F, 0.9816494095F, 0.9817994351F,
  143456. 0.9819485860F, 0.9820968650F, 0.9822442750F, 0.9823908186F,
  143457. 0.9825364988F, 0.9826813184F, 0.9828252801F, 0.9829683868F,
  143458. 0.9831106413F, 0.9832520463F, 0.9833926048F, 0.9835323195F,
  143459. 0.9836711932F, 0.9838092288F, 0.9839464291F, 0.9840827969F,
  143460. 0.9842183351F, 0.9843530464F, 0.9844869337F, 0.9846199998F,
  143461. 0.9847522475F, 0.9848836798F, 0.9850142993F, 0.9851441090F,
  143462. 0.9852731117F, 0.9854013101F, 0.9855287073F, 0.9856553058F,
  143463. 0.9857811087F, 0.9859061188F, 0.9860303388F, 0.9861537717F,
  143464. 0.9862764202F, 0.9863982872F, 0.9865193756F, 0.9866396882F,
  143465. 0.9867592277F, 0.9868779972F, 0.9869959993F, 0.9871132370F,
  143466. 0.9872297131F, 0.9873454304F, 0.9874603918F, 0.9875746001F,
  143467. 0.9876880581F, 0.9878007688F, 0.9879127348F, 0.9880239592F,
  143468. 0.9881344447F, 0.9882441941F, 0.9883532104F, 0.9884614962F,
  143469. 0.9885690546F, 0.9886758883F, 0.9887820001F, 0.9888873930F,
  143470. 0.9889920697F, 0.9890960331F, 0.9891992859F, 0.9893018312F,
  143471. 0.9894036716F, 0.9895048100F, 0.9896052493F, 0.9897049923F,
  143472. 0.9898040418F, 0.9899024006F, 0.9900000717F, 0.9900970577F,
  143473. 0.9901933616F, 0.9902889862F, 0.9903839343F, 0.9904782087F,
  143474. 0.9905718122F, 0.9906647477F, 0.9907570180F, 0.9908486259F,
  143475. 0.9909395742F, 0.9910298658F, 0.9911195034F, 0.9912084899F,
  143476. 0.9912968281F, 0.9913845208F, 0.9914715708F, 0.9915579810F,
  143477. 0.9916437540F, 0.9917288928F, 0.9918134001F, 0.9918972788F,
  143478. 0.9919805316F, 0.9920631613F, 0.9921451707F, 0.9922265626F,
  143479. 0.9923073399F, 0.9923875052F, 0.9924670615F, 0.9925460114F,
  143480. 0.9926243577F, 0.9927021033F, 0.9927792508F, 0.9928558032F,
  143481. 0.9929317631F, 0.9930071333F, 0.9930819167F, 0.9931561158F,
  143482. 0.9932297337F, 0.9933027728F, 0.9933752362F, 0.9934471264F,
  143483. 0.9935184462F, 0.9935891985F, 0.9936593859F, 0.9937290112F,
  143484. 0.9937980771F, 0.9938665864F, 0.9939345418F, 0.9940019460F,
  143485. 0.9940688018F, 0.9941351118F, 0.9942008789F, 0.9942661057F,
  143486. 0.9943307950F, 0.9943949494F, 0.9944585717F, 0.9945216645F,
  143487. 0.9945842307F, 0.9946462728F, 0.9947077936F, 0.9947687957F,
  143488. 0.9948292820F, 0.9948892550F, 0.9949487174F, 0.9950076719F,
  143489. 0.9950661212F, 0.9951240679F, 0.9951815148F, 0.9952384645F,
  143490. 0.9952949196F, 0.9953508828F, 0.9954063568F, 0.9954613442F,
  143491. 0.9955158476F, 0.9955698697F, 0.9956234132F, 0.9956764806F,
  143492. 0.9957290746F, 0.9957811978F, 0.9958328528F, 0.9958840423F,
  143493. 0.9959347688F, 0.9959850351F, 0.9960348435F, 0.9960841969F,
  143494. 0.9961330977F, 0.9961815486F, 0.9962295521F, 0.9962771108F,
  143495. 0.9963242274F, 0.9963709043F, 0.9964171441F, 0.9964629494F,
  143496. 0.9965083228F, 0.9965532668F, 0.9965977840F, 0.9966418768F,
  143497. 0.9966855479F, 0.9967287998F, 0.9967716350F, 0.9968140559F,
  143498. 0.9968560653F, 0.9968976655F, 0.9969388591F, 0.9969796485F,
  143499. 0.9970200363F, 0.9970600250F, 0.9970996170F, 0.9971388149F,
  143500. 0.9971776211F, 0.9972160380F, 0.9972540683F, 0.9972917142F,
  143501. 0.9973289783F, 0.9973658631F, 0.9974023709F, 0.9974385042F,
  143502. 0.9974742655F, 0.9975096571F, 0.9975446816F, 0.9975793413F,
  143503. 0.9976136386F, 0.9976475759F, 0.9976811557F, 0.9977143803F,
  143504. 0.9977472521F, 0.9977797736F, 0.9978119470F, 0.9978437748F,
  143505. 0.9978752593F, 0.9979064029F, 0.9979372079F, 0.9979676768F,
  143506. 0.9979978117F, 0.9980276151F, 0.9980570893F, 0.9980862367F,
  143507. 0.9981150595F, 0.9981435600F, 0.9981717406F, 0.9981996035F,
  143508. 0.9982271511F, 0.9982543856F, 0.9982813093F, 0.9983079246F,
  143509. 0.9983342336F, 0.9983602386F, 0.9983859418F, 0.9984113456F,
  143510. 0.9984364522F, 0.9984612638F, 0.9984857825F, 0.9985100108F,
  143511. 0.9985339507F, 0.9985576044F, 0.9985809743F, 0.9986040624F,
  143512. 0.9986268710F, 0.9986494022F, 0.9986716583F, 0.9986936413F,
  143513. 0.9987153535F, 0.9987367969F, 0.9987579738F, 0.9987788864F,
  143514. 0.9987995366F, 0.9988199267F, 0.9988400587F, 0.9988599348F,
  143515. 0.9988795572F, 0.9988989278F, 0.9989180487F, 0.9989369222F,
  143516. 0.9989555501F, 0.9989739347F, 0.9989920780F, 0.9990099820F,
  143517. 0.9990276487F, 0.9990450803F, 0.9990622787F, 0.9990792460F,
  143518. 0.9990959841F, 0.9991124952F, 0.9991287812F, 0.9991448440F,
  143519. 0.9991606858F, 0.9991763084F, 0.9991917139F, 0.9992069042F,
  143520. 0.9992218813F, 0.9992366471F, 0.9992512035F, 0.9992655525F,
  143521. 0.9992796961F, 0.9992936361F, 0.9993073744F, 0.9993209131F,
  143522. 0.9993342538F, 0.9993473987F, 0.9993603494F, 0.9993731080F,
  143523. 0.9993856762F, 0.9993980559F, 0.9994102490F, 0.9994222573F,
  143524. 0.9994340827F, 0.9994457269F, 0.9994571918F, 0.9994684793F,
  143525. 0.9994795910F, 0.9994905288F, 0.9995012945F, 0.9995118898F,
  143526. 0.9995223165F, 0.9995325765F, 0.9995426713F, 0.9995526029F,
  143527. 0.9995623728F, 0.9995719829F, 0.9995814349F, 0.9995907304F,
  143528. 0.9995998712F, 0.9996088590F, 0.9996176954F, 0.9996263821F,
  143529. 0.9996349208F, 0.9996433132F, 0.9996515609F, 0.9996596656F,
  143530. 0.9996676288F, 0.9996754522F, 0.9996831375F, 0.9996906862F,
  143531. 0.9996981000F, 0.9997053804F, 0.9997125290F, 0.9997195474F,
  143532. 0.9997264371F, 0.9997331998F, 0.9997398369F, 0.9997463500F,
  143533. 0.9997527406F, 0.9997590103F, 0.9997651606F, 0.9997711930F,
  143534. 0.9997771089F, 0.9997829098F, 0.9997885973F, 0.9997941728F,
  143535. 0.9997996378F, 0.9998049936F, 0.9998102419F, 0.9998153839F,
  143536. 0.9998204211F, 0.9998253550F, 0.9998301868F, 0.9998349182F,
  143537. 0.9998395503F, 0.9998440847F, 0.9998485226F, 0.9998528654F,
  143538. 0.9998571146F, 0.9998612713F, 0.9998653370F, 0.9998693130F,
  143539. 0.9998732007F, 0.9998770012F, 0.9998807159F, 0.9998843461F,
  143540. 0.9998878931F, 0.9998913581F, 0.9998947424F, 0.9998980473F,
  143541. 0.9999012740F, 0.9999044237F, 0.9999074976F, 0.9999104971F,
  143542. 0.9999134231F, 0.9999162771F, 0.9999190601F, 0.9999217733F,
  143543. 0.9999244179F, 0.9999269950F, 0.9999295058F, 0.9999319515F,
  143544. 0.9999343332F, 0.9999366519F, 0.9999389088F, 0.9999411050F,
  143545. 0.9999432416F, 0.9999453196F, 0.9999473402F, 0.9999493044F,
  143546. 0.9999512132F, 0.9999530677F, 0.9999548690F, 0.9999566180F,
  143547. 0.9999583157F, 0.9999599633F, 0.9999615616F, 0.9999631116F,
  143548. 0.9999646144F, 0.9999660709F, 0.9999674820F, 0.9999688487F,
  143549. 0.9999701719F, 0.9999714526F, 0.9999726917F, 0.9999738900F,
  143550. 0.9999750486F, 0.9999761682F, 0.9999772497F, 0.9999782941F,
  143551. 0.9999793021F, 0.9999802747F, 0.9999812126F, 0.9999821167F,
  143552. 0.9999829878F, 0.9999838268F, 0.9999846343F, 0.9999854113F,
  143553. 0.9999861584F, 0.9999868765F, 0.9999875664F, 0.9999882287F,
  143554. 0.9999888642F, 0.9999894736F, 0.9999900577F, 0.9999906172F,
  143555. 0.9999911528F, 0.9999916651F, 0.9999921548F, 0.9999926227F,
  143556. 0.9999930693F, 0.9999934954F, 0.9999939015F, 0.9999942883F,
  143557. 0.9999946564F, 0.9999950064F, 0.9999953390F, 0.9999956547F,
  143558. 0.9999959541F, 0.9999962377F, 0.9999965062F, 0.9999967601F,
  143559. 0.9999969998F, 0.9999972260F, 0.9999974392F, 0.9999976399F,
  143560. 0.9999978285F, 0.9999980056F, 0.9999981716F, 0.9999983271F,
  143561. 0.9999984724F, 0.9999986081F, 0.9999987345F, 0.9999988521F,
  143562. 0.9999989613F, 0.9999990625F, 0.9999991562F, 0.9999992426F,
  143563. 0.9999993223F, 0.9999993954F, 0.9999994625F, 0.9999995239F,
  143564. 0.9999995798F, 0.9999996307F, 0.9999996768F, 0.9999997184F,
  143565. 0.9999997559F, 0.9999997895F, 0.9999998195F, 0.9999998462F,
  143566. 0.9999998698F, 0.9999998906F, 0.9999999088F, 0.9999999246F,
  143567. 0.9999999383F, 0.9999999500F, 0.9999999600F, 0.9999999684F,
  143568. 0.9999999754F, 0.9999999811F, 0.9999999858F, 0.9999999896F,
  143569. 0.9999999925F, 0.9999999948F, 0.9999999965F, 0.9999999978F,
  143570. 0.9999999986F, 0.9999999992F, 0.9999999996F, 0.9999999998F,
  143571. 0.9999999999F, 1.0000000000F, 1.0000000000F, 1.0000000000F,
  143572. };
  143573. static float vwin8192[4096] = {
  143574. 0.0000000578F, 0.0000005198F, 0.0000014438F, 0.0000028299F,
  143575. 0.0000046780F, 0.0000069882F, 0.0000097604F, 0.0000129945F,
  143576. 0.0000166908F, 0.0000208490F, 0.0000254692F, 0.0000305515F,
  143577. 0.0000360958F, 0.0000421021F, 0.0000485704F, 0.0000555006F,
  143578. 0.0000628929F, 0.0000707472F, 0.0000790635F, 0.0000878417F,
  143579. 0.0000970820F, 0.0001067842F, 0.0001169483F, 0.0001275744F,
  143580. 0.0001386625F, 0.0001502126F, 0.0001622245F, 0.0001746984F,
  143581. 0.0001876343F, 0.0002010320F, 0.0002148917F, 0.0002292132F,
  143582. 0.0002439967F, 0.0002592421F, 0.0002749493F, 0.0002911184F,
  143583. 0.0003077493F, 0.0003248421F, 0.0003423967F, 0.0003604132F,
  143584. 0.0003788915F, 0.0003978316F, 0.0004172335F, 0.0004370971F,
  143585. 0.0004574226F, 0.0004782098F, 0.0004994587F, 0.0005211694F,
  143586. 0.0005433418F, 0.0005659759F, 0.0005890717F, 0.0006126292F,
  143587. 0.0006366484F, 0.0006611292F, 0.0006860716F, 0.0007114757F,
  143588. 0.0007373414F, 0.0007636687F, 0.0007904576F, 0.0008177080F,
  143589. 0.0008454200F, 0.0008735935F, 0.0009022285F, 0.0009313250F,
  143590. 0.0009608830F, 0.0009909025F, 0.0010213834F, 0.0010523257F,
  143591. 0.0010837295F, 0.0011155946F, 0.0011479211F, 0.0011807090F,
  143592. 0.0012139582F, 0.0012476687F, 0.0012818405F, 0.0013164736F,
  143593. 0.0013515679F, 0.0013871235F, 0.0014231402F, 0.0014596182F,
  143594. 0.0014965573F, 0.0015339576F, 0.0015718190F, 0.0016101415F,
  143595. 0.0016489251F, 0.0016881698F, 0.0017278754F, 0.0017680421F,
  143596. 0.0018086698F, 0.0018497584F, 0.0018913080F, 0.0019333185F,
  143597. 0.0019757898F, 0.0020187221F, 0.0020621151F, 0.0021059690F,
  143598. 0.0021502837F, 0.0021950591F, 0.0022402953F, 0.0022859921F,
  143599. 0.0023321497F, 0.0023787679F, 0.0024258467F, 0.0024733861F,
  143600. 0.0025213861F, 0.0025698466F, 0.0026187676F, 0.0026681491F,
  143601. 0.0027179911F, 0.0027682935F, 0.0028190562F, 0.0028702794F,
  143602. 0.0029219628F, 0.0029741066F, 0.0030267107F, 0.0030797749F,
  143603. 0.0031332994F, 0.0031872841F, 0.0032417289F, 0.0032966338F,
  143604. 0.0033519988F, 0.0034078238F, 0.0034641089F, 0.0035208539F,
  143605. 0.0035780589F, 0.0036357237F, 0.0036938485F, 0.0037524331F,
  143606. 0.0038114775F, 0.0038709817F, 0.0039309456F, 0.0039913692F,
  143607. 0.0040522524F, 0.0041135953F, 0.0041753978F, 0.0042376599F,
  143608. 0.0043003814F, 0.0043635624F, 0.0044272029F, 0.0044913028F,
  143609. 0.0045558620F, 0.0046208806F, 0.0046863585F, 0.0047522955F,
  143610. 0.0048186919F, 0.0048855473F, 0.0049528619F, 0.0050206356F,
  143611. 0.0050888684F, 0.0051575601F, 0.0052267108F, 0.0052963204F,
  143612. 0.0053663890F, 0.0054369163F, 0.0055079025F, 0.0055793474F,
  143613. 0.0056512510F, 0.0057236133F, 0.0057964342F, 0.0058697137F,
  143614. 0.0059434517F, 0.0060176482F, 0.0060923032F, 0.0061674166F,
  143615. 0.0062429883F, 0.0063190183F, 0.0063955066F, 0.0064724532F,
  143616. 0.0065498579F, 0.0066277207F, 0.0067060416F, 0.0067848205F,
  143617. 0.0068640575F, 0.0069437523F, 0.0070239051F, 0.0071045157F,
  143618. 0.0071855840F, 0.0072671102F, 0.0073490940F, 0.0074315355F,
  143619. 0.0075144345F, 0.0075977911F, 0.0076816052F, 0.0077658768F,
  143620. 0.0078506057F, 0.0079357920F, 0.0080214355F, 0.0081075363F,
  143621. 0.0081940943F, 0.0082811094F, 0.0083685816F, 0.0084565108F,
  143622. 0.0085448970F, 0.0086337401F, 0.0087230401F, 0.0088127969F,
  143623. 0.0089030104F, 0.0089936807F, 0.0090848076F, 0.0091763911F,
  143624. 0.0092684311F, 0.0093609276F, 0.0094538805F, 0.0095472898F,
  143625. 0.0096411554F, 0.0097354772F, 0.0098302552F, 0.0099254894F,
  143626. 0.0100211796F, 0.0101173259F, 0.0102139281F, 0.0103109863F,
  143627. 0.0104085002F, 0.0105064700F, 0.0106048955F, 0.0107037766F,
  143628. 0.0108031133F, 0.0109029056F, 0.0110031534F, 0.0111038565F,
  143629. 0.0112050151F, 0.0113066289F, 0.0114086980F, 0.0115112222F,
  143630. 0.0116142015F, 0.0117176359F, 0.0118215252F, 0.0119258695F,
  143631. 0.0120306686F, 0.0121359225F, 0.0122416312F, 0.0123477944F,
  143632. 0.0124544123F, 0.0125614847F, 0.0126690116F, 0.0127769928F,
  143633. 0.0128854284F, 0.0129943182F, 0.0131036623F, 0.0132134604F,
  143634. 0.0133237126F, 0.0134344188F, 0.0135455790F, 0.0136571929F,
  143635. 0.0137692607F, 0.0138817821F, 0.0139947572F, 0.0141081859F,
  143636. 0.0142220681F, 0.0143364037F, 0.0144511927F, 0.0145664350F,
  143637. 0.0146821304F, 0.0147982791F, 0.0149148808F, 0.0150319355F,
  143638. 0.0151494431F, 0.0152674036F, 0.0153858168F, 0.0155046828F,
  143639. 0.0156240014F, 0.0157437726F, 0.0158639962F, 0.0159846723F,
  143640. 0.0161058007F, 0.0162273814F, 0.0163494142F, 0.0164718991F,
  143641. 0.0165948361F, 0.0167182250F, 0.0168420658F, 0.0169663584F,
  143642. 0.0170911027F, 0.0172162987F, 0.0173419462F, 0.0174680452F,
  143643. 0.0175945956F, 0.0177215974F, 0.0178490504F, 0.0179769545F,
  143644. 0.0181053098F, 0.0182341160F, 0.0183633732F, 0.0184930812F,
  143645. 0.0186232399F, 0.0187538494F, 0.0188849094F, 0.0190164200F,
  143646. 0.0191483809F, 0.0192807923F, 0.0194136539F, 0.0195469656F,
  143647. 0.0196807275F, 0.0198149394F, 0.0199496012F, 0.0200847128F,
  143648. 0.0202202742F, 0.0203562853F, 0.0204927460F, 0.0206296561F,
  143649. 0.0207670157F, 0.0209048245F, 0.0210430826F, 0.0211817899F,
  143650. 0.0213209462F, 0.0214605515F, 0.0216006057F, 0.0217411086F,
  143651. 0.0218820603F, 0.0220234605F, 0.0221653093F, 0.0223076066F,
  143652. 0.0224503521F, 0.0225935459F, 0.0227371879F, 0.0228812779F,
  143653. 0.0230258160F, 0.0231708018F, 0.0233162355F, 0.0234621169F,
  143654. 0.0236084459F, 0.0237552224F, 0.0239024462F, 0.0240501175F,
  143655. 0.0241982359F, 0.0243468015F, 0.0244958141F, 0.0246452736F,
  143656. 0.0247951800F, 0.0249455331F, 0.0250963329F, 0.0252475792F,
  143657. 0.0253992720F, 0.0255514111F, 0.0257039965F, 0.0258570281F,
  143658. 0.0260105057F, 0.0261644293F, 0.0263187987F, 0.0264736139F,
  143659. 0.0266288747F, 0.0267845811F, 0.0269407330F, 0.0270973302F,
  143660. 0.0272543727F, 0.0274118604F, 0.0275697930F, 0.0277281707F,
  143661. 0.0278869932F, 0.0280462604F, 0.0282059723F, 0.0283661287F,
  143662. 0.0285267295F, 0.0286877747F, 0.0288492641F, 0.0290111976F,
  143663. 0.0291735751F, 0.0293363965F, 0.0294996617F, 0.0296633706F,
  143664. 0.0298275231F, 0.0299921190F, 0.0301571583F, 0.0303226409F,
  143665. 0.0304885667F, 0.0306549354F, 0.0308217472F, 0.0309890017F,
  143666. 0.0311566989F, 0.0313248388F, 0.0314934211F, 0.0316624459F,
  143667. 0.0318319128F, 0.0320018220F, 0.0321721732F, 0.0323429663F,
  143668. 0.0325142013F, 0.0326858779F, 0.0328579962F, 0.0330305559F,
  143669. 0.0332035570F, 0.0333769994F, 0.0335508829F, 0.0337252074F,
  143670. 0.0338999728F, 0.0340751790F, 0.0342508259F, 0.0344269134F,
  143671. 0.0346034412F, 0.0347804094F, 0.0349578178F, 0.0351356663F,
  143672. 0.0353139548F, 0.0354926831F, 0.0356718511F, 0.0358514588F,
  143673. 0.0360315059F, 0.0362119924F, 0.0363929182F, 0.0365742831F,
  143674. 0.0367560870F, 0.0369383297F, 0.0371210113F, 0.0373041315F,
  143675. 0.0374876902F, 0.0376716873F, 0.0378561226F, 0.0380409961F,
  143676. 0.0382263077F, 0.0384120571F, 0.0385982443F, 0.0387848691F,
  143677. 0.0389719315F, 0.0391594313F, 0.0393473683F, 0.0395357425F,
  143678. 0.0397245537F, 0.0399138017F, 0.0401034866F, 0.0402936080F,
  143679. 0.0404841660F, 0.0406751603F, 0.0408665909F, 0.0410584576F,
  143680. 0.0412507603F, 0.0414434988F, 0.0416366731F, 0.0418302829F,
  143681. 0.0420243282F, 0.0422188088F, 0.0424137246F, 0.0426090755F,
  143682. 0.0428048613F, 0.0430010819F, 0.0431977371F, 0.0433948269F,
  143683. 0.0435923511F, 0.0437903095F, 0.0439887020F, 0.0441875285F,
  143684. 0.0443867889F, 0.0445864830F, 0.0447866106F, 0.0449871717F,
  143685. 0.0451881661F, 0.0453895936F, 0.0455914542F, 0.0457937477F,
  143686. 0.0459964738F, 0.0461996326F, 0.0464032239F, 0.0466072475F,
  143687. 0.0468117032F, 0.0470165910F, 0.0472219107F, 0.0474276622F,
  143688. 0.0476338452F, 0.0478404597F, 0.0480475056F, 0.0482549827F,
  143689. 0.0484628907F, 0.0486712297F, 0.0488799994F, 0.0490891998F,
  143690. 0.0492988306F, 0.0495088917F, 0.0497193830F, 0.0499303043F,
  143691. 0.0501416554F, 0.0503534363F, 0.0505656468F, 0.0507782867F,
  143692. 0.0509913559F, 0.0512048542F, 0.0514187815F, 0.0516331376F,
  143693. 0.0518479225F, 0.0520631358F, 0.0522787775F, 0.0524948475F,
  143694. 0.0527113455F, 0.0529282715F, 0.0531456252F, 0.0533634066F,
  143695. 0.0535816154F, 0.0538002515F, 0.0540193148F, 0.0542388051F,
  143696. 0.0544587222F, 0.0546790660F, 0.0548998364F, 0.0551210331F,
  143697. 0.0553426561F, 0.0555647051F, 0.0557871801F, 0.0560100807F,
  143698. 0.0562334070F, 0.0564571587F, 0.0566813357F, 0.0569059378F,
  143699. 0.0571309649F, 0.0573564168F, 0.0575822933F, 0.0578085942F,
  143700. 0.0580353195F, 0.0582624689F, 0.0584900423F, 0.0587180396F,
  143701. 0.0589464605F, 0.0591753049F, 0.0594045726F, 0.0596342635F,
  143702. 0.0598643774F, 0.0600949141F, 0.0603258735F, 0.0605572555F,
  143703. 0.0607890597F, 0.0610212862F, 0.0612539346F, 0.0614870049F,
  143704. 0.0617204968F, 0.0619544103F, 0.0621887451F, 0.0624235010F,
  143705. 0.0626586780F, 0.0628942758F, 0.0631302942F, 0.0633667331F,
  143706. 0.0636035923F, 0.0638408717F, 0.0640785710F, 0.0643166901F,
  143707. 0.0645552288F, 0.0647941870F, 0.0650335645F, 0.0652733610F,
  143708. 0.0655135765F, 0.0657542108F, 0.0659952636F, 0.0662367348F,
  143709. 0.0664786242F, 0.0667209316F, 0.0669636570F, 0.0672068000F,
  143710. 0.0674503605F, 0.0676943384F, 0.0679387334F, 0.0681835454F,
  143711. 0.0684287742F, 0.0686744196F, 0.0689204814F, 0.0691669595F,
  143712. 0.0694138536F, 0.0696611637F, 0.0699088894F, 0.0701570307F,
  143713. 0.0704055873F, 0.0706545590F, 0.0709039458F, 0.0711537473F,
  143714. 0.0714039634F, 0.0716545939F, 0.0719056387F, 0.0721570975F,
  143715. 0.0724089702F, 0.0726612565F, 0.0729139563F, 0.0731670694F,
  143716. 0.0734205956F, 0.0736745347F, 0.0739288866F, 0.0741836510F,
  143717. 0.0744388277F, 0.0746944166F, 0.0749504175F, 0.0752068301F,
  143718. 0.0754636543F, 0.0757208899F, 0.0759785367F, 0.0762365946F,
  143719. 0.0764950632F, 0.0767539424F, 0.0770132320F, 0.0772729319F,
  143720. 0.0775330418F, 0.0777935616F, 0.0780544909F, 0.0783158298F,
  143721. 0.0785775778F, 0.0788397349F, 0.0791023009F, 0.0793652755F,
  143722. 0.0796286585F, 0.0798924498F, 0.0801566492F, 0.0804212564F,
  143723. 0.0806862712F, 0.0809516935F, 0.0812175231F, 0.0814837597F,
  143724. 0.0817504031F, 0.0820174532F, 0.0822849097F, 0.0825527724F,
  143725. 0.0828210412F, 0.0830897158F, 0.0833587960F, 0.0836282816F,
  143726. 0.0838981724F, 0.0841684682F, 0.0844391688F, 0.0847102740F,
  143727. 0.0849817835F, 0.0852536973F, 0.0855260150F, 0.0857987364F,
  143728. 0.0860718614F, 0.0863453897F, 0.0866193211F, 0.0868936554F,
  143729. 0.0871683924F, 0.0874435319F, 0.0877190737F, 0.0879950175F,
  143730. 0.0882713632F, 0.0885481105F, 0.0888252592F, 0.0891028091F,
  143731. 0.0893807600F, 0.0896591117F, 0.0899378639F, 0.0902170165F,
  143732. 0.0904965692F, 0.0907765218F, 0.0910568740F, 0.0913376258F,
  143733. 0.0916187767F, 0.0919003268F, 0.0921822756F, 0.0924646230F,
  143734. 0.0927473687F, 0.0930305126F, 0.0933140545F, 0.0935979940F,
  143735. 0.0938823310F, 0.0941670653F, 0.0944521966F, 0.0947377247F,
  143736. 0.0950236494F, 0.0953099704F, 0.0955966876F, 0.0958838007F,
  143737. 0.0961713094F, 0.0964592136F, 0.0967475131F, 0.0970362075F,
  143738. 0.0973252967F, 0.0976147805F, 0.0979046585F, 0.0981949307F,
  143739. 0.0984855967F, 0.0987766563F, 0.0990681093F, 0.0993599555F,
  143740. 0.0996521945F, 0.0999448263F, 0.1002378506F, 0.1005312671F,
  143741. 0.1008250755F, 0.1011192757F, 0.1014138675F, 0.1017088505F,
  143742. 0.1020042246F, 0.1022999895F, 0.1025961450F, 0.1028926909F,
  143743. 0.1031896268F, 0.1034869526F, 0.1037846680F, 0.1040827729F,
  143744. 0.1043812668F, 0.1046801497F, 0.1049794213F, 0.1052790813F,
  143745. 0.1055791294F, 0.1058795656F, 0.1061803894F, 0.1064816006F,
  143746. 0.1067831991F, 0.1070851846F, 0.1073875568F, 0.1076903155F,
  143747. 0.1079934604F, 0.1082969913F, 0.1086009079F, 0.1089052101F,
  143748. 0.1092098975F, 0.1095149699F, 0.1098204270F, 0.1101262687F,
  143749. 0.1104324946F, 0.1107391045F, 0.1110460982F, 0.1113534754F,
  143750. 0.1116612359F, 0.1119693793F, 0.1122779055F, 0.1125868142F,
  143751. 0.1128961052F, 0.1132057781F, 0.1135158328F, 0.1138262690F,
  143752. 0.1141370863F, 0.1144482847F, 0.1147598638F, 0.1150718233F,
  143753. 0.1153841631F, 0.1156968828F, 0.1160099822F, 0.1163234610F,
  143754. 0.1166373190F, 0.1169515559F, 0.1172661714F, 0.1175811654F,
  143755. 0.1178965374F, 0.1182122874F, 0.1185284149F, 0.1188449198F,
  143756. 0.1191618018F, 0.1194790606F, 0.1197966960F, 0.1201147076F,
  143757. 0.1204330953F, 0.1207518587F, 0.1210709976F, 0.1213905118F,
  143758. 0.1217104009F, 0.1220306647F, 0.1223513029F, 0.1226723153F,
  143759. 0.1229937016F, 0.1233154615F, 0.1236375948F, 0.1239601011F,
  143760. 0.1242829803F, 0.1246062319F, 0.1249298559F, 0.1252538518F,
  143761. 0.1255782195F, 0.1259029586F, 0.1262280689F, 0.1265535501F,
  143762. 0.1268794019F, 0.1272056241F, 0.1275322163F, 0.1278591784F,
  143763. 0.1281865099F, 0.1285142108F, 0.1288422805F, 0.1291707190F,
  143764. 0.1294995259F, 0.1298287009F, 0.1301582437F, 0.1304881542F,
  143765. 0.1308184319F, 0.1311490766F, 0.1314800881F, 0.1318114660F,
  143766. 0.1321432100F, 0.1324753200F, 0.1328077955F, 0.1331406364F,
  143767. 0.1334738422F, 0.1338074129F, 0.1341413479F, 0.1344756472F,
  143768. 0.1348103103F, 0.1351453370F, 0.1354807270F, 0.1358164801F,
  143769. 0.1361525959F, 0.1364890741F, 0.1368259145F, 0.1371631167F,
  143770. 0.1375006805F, 0.1378386056F, 0.1381768917F, 0.1385155384F,
  143771. 0.1388545456F, 0.1391939129F, 0.1395336400F, 0.1398737266F,
  143772. 0.1402141724F, 0.1405549772F, 0.1408961406F, 0.1412376623F,
  143773. 0.1415795421F, 0.1419217797F, 0.1422643746F, 0.1426073268F,
  143774. 0.1429506358F, 0.1432943013F, 0.1436383231F, 0.1439827008F,
  143775. 0.1443274342F, 0.1446725229F, 0.1450179667F, 0.1453637652F,
  143776. 0.1457099181F, 0.1460564252F, 0.1464032861F, 0.1467505006F,
  143777. 0.1470980682F, 0.1474459888F, 0.1477942620F, 0.1481428875F,
  143778. 0.1484918651F, 0.1488411942F, 0.1491908748F, 0.1495409065F,
  143779. 0.1498912889F, 0.1502420218F, 0.1505931048F, 0.1509445376F,
  143780. 0.1512963200F, 0.1516484516F, 0.1520009321F, 0.1523537612F,
  143781. 0.1527069385F, 0.1530604638F, 0.1534143368F, 0.1537685571F,
  143782. 0.1541231244F, 0.1544780384F, 0.1548332987F, 0.1551889052F,
  143783. 0.1555448574F, 0.1559011550F, 0.1562577978F, 0.1566147853F,
  143784. 0.1569721173F, 0.1573297935F, 0.1576878135F, 0.1580461771F,
  143785. 0.1584048838F, 0.1587639334F, 0.1591233255F, 0.1594830599F,
  143786. 0.1598431361F, 0.1602035540F, 0.1605643131F, 0.1609254131F,
  143787. 0.1612868537F, 0.1616486346F, 0.1620107555F, 0.1623732160F,
  143788. 0.1627360158F, 0.1630991545F, 0.1634626319F, 0.1638264476F,
  143789. 0.1641906013F, 0.1645550926F, 0.1649199212F, 0.1652850869F,
  143790. 0.1656505892F, 0.1660164278F, 0.1663826024F, 0.1667491127F,
  143791. 0.1671159583F, 0.1674831388F, 0.1678506541F, 0.1682185036F,
  143792. 0.1685866872F, 0.1689552044F, 0.1693240549F, 0.1696932384F,
  143793. 0.1700627545F, 0.1704326029F, 0.1708027833F, 0.1711732952F,
  143794. 0.1715441385F, 0.1719153127F, 0.1722868175F, 0.1726586526F,
  143795. 0.1730308176F, 0.1734033121F, 0.1737761359F, 0.1741492886F,
  143796. 0.1745227698F, 0.1748965792F, 0.1752707164F, 0.1756451812F,
  143797. 0.1760199731F, 0.1763950918F, 0.1767705370F, 0.1771463083F,
  143798. 0.1775224054F, 0.1778988279F, 0.1782755754F, 0.1786526477F,
  143799. 0.1790300444F, 0.1794077651F, 0.1797858094F, 0.1801641771F,
  143800. 0.1805428677F, 0.1809218810F, 0.1813012165F, 0.1816808739F,
  143801. 0.1820608528F, 0.1824411530F, 0.1828217739F, 0.1832027154F,
  143802. 0.1835839770F, 0.1839655584F, 0.1843474592F, 0.1847296790F,
  143803. 0.1851122175F, 0.1854950744F, 0.1858782492F, 0.1862617417F,
  143804. 0.1866455514F, 0.1870296780F, 0.1874141211F, 0.1877988804F,
  143805. 0.1881839555F, 0.1885693461F, 0.1889550517F, 0.1893410721F,
  143806. 0.1897274068F, 0.1901140555F, 0.1905010178F, 0.1908882933F,
  143807. 0.1912758818F, 0.1916637828F, 0.1920519959F, 0.1924405208F,
  143808. 0.1928293571F, 0.1932185044F, 0.1936079625F, 0.1939977308F,
  143809. 0.1943878091F, 0.1947781969F, 0.1951688939F, 0.1955598998F,
  143810. 0.1959512141F, 0.1963428364F, 0.1967347665F, 0.1971270038F,
  143811. 0.1975195482F, 0.1979123990F, 0.1983055561F, 0.1986990190F,
  143812. 0.1990927873F, 0.1994868607F, 0.1998812388F, 0.2002759212F,
  143813. 0.2006709075F, 0.2010661974F, 0.2014617904F, 0.2018576862F,
  143814. 0.2022538844F, 0.2026503847F, 0.2030471865F, 0.2034442897F,
  143815. 0.2038416937F, 0.2042393982F, 0.2046374028F, 0.2050357071F,
  143816. 0.2054343107F, 0.2058332133F, 0.2062324145F, 0.2066319138F,
  143817. 0.2070317110F, 0.2074318055F, 0.2078321970F, 0.2082328852F,
  143818. 0.2086338696F, 0.2090351498F, 0.2094367255F, 0.2098385962F,
  143819. 0.2102407617F, 0.2106432213F, 0.2110459749F, 0.2114490220F,
  143820. 0.2118523621F, 0.2122559950F, 0.2126599202F, 0.2130641373F,
  143821. 0.2134686459F, 0.2138734456F, 0.2142785361F, 0.2146839168F,
  143822. 0.2150895875F, 0.2154955478F, 0.2159017972F, 0.2163083353F,
  143823. 0.2167151617F, 0.2171222761F, 0.2175296780F, 0.2179373670F,
  143824. 0.2183453428F, 0.2187536049F, 0.2191621529F, 0.2195709864F,
  143825. 0.2199801051F, 0.2203895085F, 0.2207991961F, 0.2212091677F,
  143826. 0.2216194228F, 0.2220299610F, 0.2224407818F, 0.2228518850F,
  143827. 0.2232632699F, 0.2236749364F, 0.2240868839F, 0.2244991121F,
  143828. 0.2249116204F, 0.2253244086F, 0.2257374763F, 0.2261508229F,
  143829. 0.2265644481F, 0.2269783514F, 0.2273925326F, 0.2278069911F,
  143830. 0.2282217265F, 0.2286367384F, 0.2290520265F, 0.2294675902F,
  143831. 0.2298834292F, 0.2302995431F, 0.2307159314F, 0.2311325937F,
  143832. 0.2315495297F, 0.2319667388F, 0.2323842207F, 0.2328019749F,
  143833. 0.2332200011F, 0.2336382988F, 0.2340568675F, 0.2344757070F,
  143834. 0.2348948166F, 0.2353141961F, 0.2357338450F, 0.2361537629F,
  143835. 0.2365739493F, 0.2369944038F, 0.2374151261F, 0.2378361156F,
  143836. 0.2382573720F, 0.2386788948F, 0.2391006836F, 0.2395227380F,
  143837. 0.2399450575F, 0.2403676417F, 0.2407904902F, 0.2412136026F,
  143838. 0.2416369783F, 0.2420606171F, 0.2424845185F, 0.2429086820F,
  143839. 0.2433331072F, 0.2437577936F, 0.2441827409F, 0.2446079486F,
  143840. 0.2450334163F, 0.2454591435F, 0.2458851298F, 0.2463113747F,
  143841. 0.2467378779F, 0.2471646389F, 0.2475916573F, 0.2480189325F,
  143842. 0.2484464643F, 0.2488742521F, 0.2493022955F, 0.2497305940F,
  143843. 0.2501591473F, 0.2505879549F, 0.2510170163F, 0.2514463311F,
  143844. 0.2518758989F, 0.2523057193F, 0.2527357916F, 0.2531661157F,
  143845. 0.2535966909F, 0.2540275169F, 0.2544585931F, 0.2548899193F,
  143846. 0.2553214948F, 0.2557533193F, 0.2561853924F, 0.2566177135F,
  143847. 0.2570502822F, 0.2574830981F, 0.2579161608F, 0.2583494697F,
  143848. 0.2587830245F, 0.2592168246F, 0.2596508697F, 0.2600851593F,
  143849. 0.2605196929F, 0.2609544701F, 0.2613894904F, 0.2618247534F,
  143850. 0.2622602586F, 0.2626960055F, 0.2631319938F, 0.2635682230F,
  143851. 0.2640046925F, 0.2644414021F, 0.2648783511F, 0.2653155391F,
  143852. 0.2657529657F, 0.2661906305F, 0.2666285329F, 0.2670666725F,
  143853. 0.2675050489F, 0.2679436616F, 0.2683825101F, 0.2688215940F,
  143854. 0.2692609127F, 0.2697004660F, 0.2701402532F, 0.2705802739F,
  143855. 0.2710205278F, 0.2714610142F, 0.2719017327F, 0.2723426830F,
  143856. 0.2727838644F, 0.2732252766F, 0.2736669191F, 0.2741087914F,
  143857. 0.2745508930F, 0.2749932235F, 0.2754357824F, 0.2758785693F,
  143858. 0.2763215837F, 0.2767648251F, 0.2772082930F, 0.2776519870F,
  143859. 0.2780959066F, 0.2785400513F, 0.2789844207F, 0.2794290143F,
  143860. 0.2798738316F, 0.2803188722F, 0.2807641355F, 0.2812096211F,
  143861. 0.2816553286F, 0.2821012574F, 0.2825474071F, 0.2829937773F,
  143862. 0.2834403673F, 0.2838871768F, 0.2843342053F, 0.2847814523F,
  143863. 0.2852289174F, 0.2856765999F, 0.2861244996F, 0.2865726159F,
  143864. 0.2870209482F, 0.2874694962F, 0.2879182594F, 0.2883672372F,
  143865. 0.2888164293F, 0.2892658350F, 0.2897154540F, 0.2901652858F,
  143866. 0.2906153298F, 0.2910655856F, 0.2915160527F, 0.2919667306F,
  143867. 0.2924176189F, 0.2928687171F, 0.2933200246F, 0.2937715409F,
  143868. 0.2942232657F, 0.2946751984F, 0.2951273386F, 0.2955796856F,
  143869. 0.2960322391F, 0.2964849986F, 0.2969379636F, 0.2973911335F,
  143870. 0.2978445080F, 0.2982980864F, 0.2987518684F, 0.2992058534F,
  143871. 0.2996600409F, 0.3001144305F, 0.3005690217F, 0.3010238139F,
  143872. 0.3014788067F, 0.3019339995F, 0.3023893920F, 0.3028449835F,
  143873. 0.3033007736F, 0.3037567618F, 0.3042129477F, 0.3046693306F,
  143874. 0.3051259102F, 0.3055826859F, 0.3060396572F, 0.3064968236F,
  143875. 0.3069541847F, 0.3074117399F, 0.3078694887F, 0.3083274307F,
  143876. 0.3087855653F, 0.3092438920F, 0.3097024104F, 0.3101611199F,
  143877. 0.3106200200F, 0.3110791103F, 0.3115383902F, 0.3119978592F,
  143878. 0.3124575169F, 0.3129173627F, 0.3133773961F, 0.3138376166F,
  143879. 0.3142980238F, 0.3147586170F, 0.3152193959F, 0.3156803598F,
  143880. 0.3161415084F, 0.3166028410F, 0.3170643573F, 0.3175260566F,
  143881. 0.3179879384F, 0.3184500023F, 0.3189122478F, 0.3193746743F,
  143882. 0.3198372814F, 0.3203000685F, 0.3207630351F, 0.3212261807F,
  143883. 0.3216895048F, 0.3221530069F, 0.3226166865F, 0.3230805430F,
  143884. 0.3235445760F, 0.3240087849F, 0.3244731693F, 0.3249377285F,
  143885. 0.3254024622F, 0.3258673698F, 0.3263324507F, 0.3267977045F,
  143886. 0.3272631306F, 0.3277287286F, 0.3281944978F, 0.3286604379F,
  143887. 0.3291265482F, 0.3295928284F, 0.3300592777F, 0.3305258958F,
  143888. 0.3309926821F, 0.3314596361F, 0.3319267573F, 0.3323940451F,
  143889. 0.3328614990F, 0.3333291186F, 0.3337969033F, 0.3342648525F,
  143890. 0.3347329658F, 0.3352012427F, 0.3356696825F, 0.3361382849F,
  143891. 0.3366070492F, 0.3370759749F, 0.3375450616F, 0.3380143087F,
  143892. 0.3384837156F, 0.3389532819F, 0.3394230071F, 0.3398928905F,
  143893. 0.3403629317F, 0.3408331302F, 0.3413034854F, 0.3417739967F,
  143894. 0.3422446638F, 0.3427154860F, 0.3431864628F, 0.3436575938F,
  143895. 0.3441288782F, 0.3446003158F, 0.3450719058F, 0.3455436478F,
  143896. 0.3460155412F, 0.3464875856F, 0.3469597804F, 0.3474321250F,
  143897. 0.3479046189F, 0.3483772617F, 0.3488500527F, 0.3493229914F,
  143898. 0.3497960774F, 0.3502693100F, 0.3507426887F, 0.3512162131F,
  143899. 0.3516898825F, 0.3521636965F, 0.3526376545F, 0.3531117559F,
  143900. 0.3535860003F, 0.3540603870F, 0.3545349157F, 0.3550095856F,
  143901. 0.3554843964F, 0.3559593474F, 0.3564344381F, 0.3569096680F,
  143902. 0.3573850366F, 0.3578605432F, 0.3583361875F, 0.3588119687F,
  143903. 0.3592878865F, 0.3597639402F, 0.3602401293F, 0.3607164533F,
  143904. 0.3611929117F, 0.3616695038F, 0.3621462292F, 0.3626230873F,
  143905. 0.3631000776F, 0.3635771995F, 0.3640544525F, 0.3645318360F,
  143906. 0.3650093496F, 0.3654869926F, 0.3659647645F, 0.3664426648F,
  143907. 0.3669206930F, 0.3673988484F, 0.3678771306F, 0.3683555390F,
  143908. 0.3688340731F, 0.3693127322F, 0.3697915160F, 0.3702704237F,
  143909. 0.3707494549F, 0.3712286091F, 0.3717078857F, 0.3721872840F,
  143910. 0.3726668037F, 0.3731464441F, 0.3736262047F, 0.3741060850F,
  143911. 0.3745860843F, 0.3750662023F, 0.3755464382F, 0.3760267915F,
  143912. 0.3765072618F, 0.3769878484F, 0.3774685509F, 0.3779493686F,
  143913. 0.3784303010F, 0.3789113475F, 0.3793925076F, 0.3798737809F,
  143914. 0.3803551666F, 0.3808366642F, 0.3813182733F, 0.3817999932F,
  143915. 0.3822818234F, 0.3827637633F, 0.3832458124F, 0.3837279702F,
  143916. 0.3842102360F, 0.3846926093F, 0.3851750897F, 0.3856576764F,
  143917. 0.3861403690F, 0.3866231670F, 0.3871060696F, 0.3875890765F,
  143918. 0.3880721870F, 0.3885554007F, 0.3890387168F, 0.3895221349F,
  143919. 0.3900056544F, 0.3904892748F, 0.3909729955F, 0.3914568160F,
  143920. 0.3919407356F, 0.3924247539F, 0.3929088702F, 0.3933930841F,
  143921. 0.3938773949F, 0.3943618021F, 0.3948463052F, 0.3953309035F,
  143922. 0.3958155966F, 0.3963003838F, 0.3967852646F, 0.3972702385F,
  143923. 0.3977553048F, 0.3982404631F, 0.3987257127F, 0.3992110531F,
  143924. 0.3996964838F, 0.4001820041F, 0.4006676136F, 0.4011533116F,
  143925. 0.4016390976F, 0.4021249710F, 0.4026109313F, 0.4030969779F,
  143926. 0.4035831102F, 0.4040693277F, 0.4045556299F, 0.4050420160F,
  143927. 0.4055284857F, 0.4060150383F, 0.4065016732F, 0.4069883899F,
  143928. 0.4074751879F, 0.4079620665F, 0.4084490252F, 0.4089360635F,
  143929. 0.4094231807F, 0.4099103763F, 0.4103976498F, 0.4108850005F,
  143930. 0.4113724280F, 0.4118599315F, 0.4123475107F, 0.4128351648F,
  143931. 0.4133228934F, 0.4138106959F, 0.4142985716F, 0.4147865201F,
  143932. 0.4152745408F, 0.4157626330F, 0.4162507963F, 0.4167390301F,
  143933. 0.4172273337F, 0.4177157067F, 0.4182041484F, 0.4186926583F,
  143934. 0.4191812359F, 0.4196698805F, 0.4201585915F, 0.4206473685F,
  143935. 0.4211362108F, 0.4216251179F, 0.4221140892F, 0.4226031241F,
  143936. 0.4230922221F, 0.4235813826F, 0.4240706050F, 0.4245598887F,
  143937. 0.4250492332F, 0.4255386379F, 0.4260281022F, 0.4265176256F,
  143938. 0.4270072075F, 0.4274968473F, 0.4279865445F, 0.4284762984F,
  143939. 0.4289661086F, 0.4294559743F, 0.4299458951F, 0.4304358704F,
  143940. 0.4309258996F, 0.4314159822F, 0.4319061175F, 0.4323963050F,
  143941. 0.4328865441F, 0.4333768342F, 0.4338671749F, 0.4343575654F,
  143942. 0.4348480052F, 0.4353384938F, 0.4358290306F, 0.4363196149F,
  143943. 0.4368102463F, 0.4373009241F, 0.4377916478F, 0.4382824168F,
  143944. 0.4387732305F, 0.4392640884F, 0.4397549899F, 0.4402459343F,
  143945. 0.4407369212F, 0.4412279499F, 0.4417190198F, 0.4422101305F,
  143946. 0.4427012813F, 0.4431924717F, 0.4436837010F, 0.4441749686F,
  143947. 0.4446662742F, 0.4451576169F, 0.4456489963F, 0.4461404118F,
  143948. 0.4466318628F, 0.4471233487F, 0.4476148690F, 0.4481064230F,
  143949. 0.4485980103F, 0.4490896302F, 0.4495812821F, 0.4500729654F,
  143950. 0.4505646797F, 0.4510564243F, 0.4515481986F, 0.4520400021F,
  143951. 0.4525318341F, 0.4530236942F, 0.4535155816F, 0.4540074959F,
  143952. 0.4544994365F, 0.4549914028F, 0.4554833941F, 0.4559754100F,
  143953. 0.4564674499F, 0.4569595131F, 0.4574515991F, 0.4579437074F,
  143954. 0.4584358372F, 0.4589279881F, 0.4594201595F, 0.4599123508F,
  143955. 0.4604045615F, 0.4608967908F, 0.4613890383F, 0.4618813034F,
  143956. 0.4623735855F, 0.4628658841F, 0.4633581984F, 0.4638505281F,
  143957. 0.4643428724F, 0.4648352308F, 0.4653276028F, 0.4658199877F,
  143958. 0.4663123849F, 0.4668047940F, 0.4672972143F, 0.4677896451F,
  143959. 0.4682820861F, 0.4687745365F, 0.4692669958F, 0.4697594634F,
  143960. 0.4702519387F, 0.4707444211F, 0.4712369102F, 0.4717294052F,
  143961. 0.4722219056F, 0.4727144109F, 0.4732069204F, 0.4736994336F,
  143962. 0.4741919498F, 0.4746844686F, 0.4751769893F, 0.4756695113F,
  143963. 0.4761620341F, 0.4766545571F, 0.4771470797F, 0.4776396013F,
  143964. 0.4781321213F, 0.4786246392F, 0.4791171544F, 0.4796096663F,
  143965. 0.4801021744F, 0.4805946779F, 0.4810871765F, 0.4815796694F,
  143966. 0.4820721561F, 0.4825646360F, 0.4830571086F, 0.4835495732F,
  143967. 0.4840420293F, 0.4845344763F, 0.4850269136F, 0.4855193407F,
  143968. 0.4860117569F, 0.4865041617F, 0.4869965545F, 0.4874889347F,
  143969. 0.4879813018F, 0.4884736551F, 0.4889659941F, 0.4894583182F,
  143970. 0.4899506268F, 0.4904429193F, 0.4909351952F, 0.4914274538F,
  143971. 0.4919196947F, 0.4924119172F, 0.4929041207F, 0.4933963046F,
  143972. 0.4938884685F, 0.4943806116F, 0.4948727335F, 0.4953648335F,
  143973. 0.4958569110F, 0.4963489656F, 0.4968409965F, 0.4973330032F,
  143974. 0.4978249852F, 0.4983169419F, 0.4988088726F, 0.4993007768F,
  143975. 0.4997926539F, 0.5002845034F, 0.5007763247F, 0.5012681171F,
  143976. 0.5017598801F, 0.5022516132F, 0.5027433157F, 0.5032349871F,
  143977. 0.5037266268F, 0.5042182341F, 0.5047098086F, 0.5052013497F,
  143978. 0.5056928567F, 0.5061843292F, 0.5066757664F, 0.5071671679F,
  143979. 0.5076585330F, 0.5081498613F, 0.5086411520F, 0.5091324047F,
  143980. 0.5096236187F, 0.5101147934F, 0.5106059284F, 0.5110970230F,
  143981. 0.5115880766F, 0.5120790887F, 0.5125700587F, 0.5130609860F,
  143982. 0.5135518700F, 0.5140427102F, 0.5145335059F, 0.5150242566F,
  143983. 0.5155149618F, 0.5160056208F, 0.5164962331F, 0.5169867980F,
  143984. 0.5174773151F, 0.5179677837F, 0.5184582033F, 0.5189485733F,
  143985. 0.5194388931F, 0.5199291621F, 0.5204193798F, 0.5209095455F,
  143986. 0.5213996588F, 0.5218897190F, 0.5223797256F, 0.5228696779F,
  143987. 0.5233595755F, 0.5238494177F, 0.5243392039F, 0.5248289337F,
  143988. 0.5253186063F, 0.5258082213F, 0.5262977781F, 0.5267872760F,
  143989. 0.5272767146F, 0.5277660932F, 0.5282554112F, 0.5287446682F,
  143990. 0.5292338635F, 0.5297229965F, 0.5302120667F, 0.5307010736F,
  143991. 0.5311900164F, 0.5316788947F, 0.5321677079F, 0.5326564554F,
  143992. 0.5331451366F, 0.5336337511F, 0.5341222981F, 0.5346107771F,
  143993. 0.5350991876F, 0.5355875290F, 0.5360758007F, 0.5365640021F,
  143994. 0.5370521327F, 0.5375401920F, 0.5380281792F, 0.5385160939F,
  143995. 0.5390039355F, 0.5394917034F, 0.5399793971F, 0.5404670159F,
  143996. 0.5409545594F, 0.5414420269F, 0.5419294179F, 0.5424167318F,
  143997. 0.5429039680F, 0.5433911261F, 0.5438782053F, 0.5443652051F,
  143998. 0.5448521250F, 0.5453389644F, 0.5458257228F, 0.5463123995F,
  143999. 0.5467989940F, 0.5472855057F, 0.5477719341F, 0.5482582786F,
  144000. 0.5487445387F, 0.5492307137F, 0.5497168031F, 0.5502028063F,
  144001. 0.5506887228F, 0.5511745520F, 0.5516602934F, 0.5521459463F,
  144002. 0.5526315103F, 0.5531169847F, 0.5536023690F, 0.5540876626F,
  144003. 0.5545728649F, 0.5550579755F, 0.5555429937F, 0.5560279189F,
  144004. 0.5565127507F, 0.5569974884F, 0.5574821315F, 0.5579666794F,
  144005. 0.5584511316F, 0.5589354875F, 0.5594197465F, 0.5599039080F,
  144006. 0.5603879716F, 0.5608719367F, 0.5613558026F, 0.5618395689F,
  144007. 0.5623232350F, 0.5628068002F, 0.5632902642F, 0.5637736262F,
  144008. 0.5642568858F, 0.5647400423F, 0.5652230953F, 0.5657060442F,
  144009. 0.5661888883F, 0.5666716272F, 0.5671542603F, 0.5676367870F,
  144010. 0.5681192069F, 0.5686015192F, 0.5690837235F, 0.5695658192F,
  144011. 0.5700478058F, 0.5705296827F, 0.5710114494F, 0.5714931052F,
  144012. 0.5719746497F, 0.5724560822F, 0.5729374023F, 0.5734186094F,
  144013. 0.5738997029F, 0.5743806823F, 0.5748615470F, 0.5753422965F,
  144014. 0.5758229301F, 0.5763034475F, 0.5767838480F, 0.5772641310F,
  144015. 0.5777442960F, 0.5782243426F, 0.5787042700F, 0.5791840778F,
  144016. 0.5796637654F, 0.5801433322F, 0.5806227778F, 0.5811021016F,
  144017. 0.5815813029F, 0.5820603814F, 0.5825393363F, 0.5830181673F,
  144018. 0.5834968737F, 0.5839754549F, 0.5844539105F, 0.5849322399F,
  144019. 0.5854104425F, 0.5858885179F, 0.5863664653F, 0.5868442844F,
  144020. 0.5873219746F, 0.5877995353F, 0.5882769660F, 0.5887542661F,
  144021. 0.5892314351F, 0.5897084724F, 0.5901853776F, 0.5906621500F,
  144022. 0.5911387892F, 0.5916152945F, 0.5920916655F, 0.5925679016F,
  144023. 0.5930440022F, 0.5935199669F, 0.5939957950F, 0.5944714861F,
  144024. 0.5949470396F, 0.5954224550F, 0.5958977317F, 0.5963728692F,
  144025. 0.5968478669F, 0.5973227244F, 0.5977974411F, 0.5982720163F,
  144026. 0.5987464497F, 0.5992207407F, 0.5996948887F, 0.6001688932F,
  144027. 0.6006427537F, 0.6011164696F, 0.6015900405F, 0.6020634657F,
  144028. 0.6025367447F, 0.6030098770F, 0.6034828621F, 0.6039556995F,
  144029. 0.6044283885F, 0.6049009288F, 0.6053733196F, 0.6058455606F,
  144030. 0.6063176512F, 0.6067895909F, 0.6072613790F, 0.6077330152F,
  144031. 0.6082044989F, 0.6086758295F, 0.6091470065F, 0.6096180294F,
  144032. 0.6100888977F, 0.6105596108F, 0.6110301682F, 0.6115005694F,
  144033. 0.6119708139F, 0.6124409011F, 0.6129108305F, 0.6133806017F,
  144034. 0.6138502139F, 0.6143196669F, 0.6147889599F, 0.6152580926F,
  144035. 0.6157270643F, 0.6161958746F, 0.6166645230F, 0.6171330088F,
  144036. 0.6176013317F, 0.6180694910F, 0.6185374863F, 0.6190053171F,
  144037. 0.6194729827F, 0.6199404828F, 0.6204078167F, 0.6208749841F,
  144038. 0.6213419842F, 0.6218088168F, 0.6222754811F, 0.6227419768F,
  144039. 0.6232083032F, 0.6236744600F, 0.6241404465F, 0.6246062622F,
  144040. 0.6250719067F, 0.6255373795F, 0.6260026799F, 0.6264678076F,
  144041. 0.6269327619F, 0.6273975425F, 0.6278621487F, 0.6283265800F,
  144042. 0.6287908361F, 0.6292549163F, 0.6297188201F, 0.6301825471F,
  144043. 0.6306460966F, 0.6311094683F, 0.6315726617F, 0.6320356761F,
  144044. 0.6324985111F, 0.6329611662F, 0.6334236410F, 0.6338859348F,
  144045. 0.6343480472F, 0.6348099777F, 0.6352717257F, 0.6357332909F,
  144046. 0.6361946726F, 0.6366558704F, 0.6371168837F, 0.6375777122F,
  144047. 0.6380383552F, 0.6384988123F, 0.6389590830F, 0.6394191668F,
  144048. 0.6398790631F, 0.6403387716F, 0.6407982916F, 0.6412576228F,
  144049. 0.6417167645F, 0.6421757163F, 0.6426344778F, 0.6430930483F,
  144050. 0.6435514275F, 0.6440096149F, 0.6444676098F, 0.6449254119F,
  144051. 0.6453830207F, 0.6458404356F, 0.6462976562F, 0.6467546820F,
  144052. 0.6472115125F, 0.6476681472F, 0.6481245856F, 0.6485808273F,
  144053. 0.6490368717F, 0.6494927183F, 0.6499483667F, 0.6504038164F,
  144054. 0.6508590670F, 0.6513141178F, 0.6517689684F, 0.6522236185F,
  144055. 0.6526780673F, 0.6531323146F, 0.6535863598F, 0.6540402024F,
  144056. 0.6544938419F, 0.6549472779F, 0.6554005099F, 0.6558535373F,
  144057. 0.6563063598F, 0.6567589769F, 0.6572113880F, 0.6576635927F,
  144058. 0.6581155906F, 0.6585673810F, 0.6590189637F, 0.6594703380F,
  144059. 0.6599215035F, 0.6603724598F, 0.6608232064F, 0.6612737427F,
  144060. 0.6617240684F, 0.6621741829F, 0.6626240859F, 0.6630737767F,
  144061. 0.6635232550F, 0.6639725202F, 0.6644215720F, 0.6648704098F,
  144062. 0.6653190332F, 0.6657674417F, 0.6662156348F, 0.6666636121F,
  144063. 0.6671113731F, 0.6675589174F, 0.6680062445F, 0.6684533538F,
  144064. 0.6689002450F, 0.6693469177F, 0.6697933712F, 0.6702396052F,
  144065. 0.6706856193F, 0.6711314129F, 0.6715769855F, 0.6720223369F,
  144066. 0.6724674664F, 0.6729123736F, 0.6733570581F, 0.6738015194F,
  144067. 0.6742457570F, 0.6746897706F, 0.6751335596F, 0.6755771236F,
  144068. 0.6760204621F, 0.6764635747F, 0.6769064609F, 0.6773491204F,
  144069. 0.6777915525F, 0.6782337570F, 0.6786757332F, 0.6791174809F,
  144070. 0.6795589995F, 0.6800002886F, 0.6804413477F, 0.6808821765F,
  144071. 0.6813227743F, 0.6817631409F, 0.6822032758F, 0.6826431785F,
  144072. 0.6830828485F, 0.6835222855F, 0.6839614890F, 0.6844004585F,
  144073. 0.6848391936F, 0.6852776939F, 0.6857159589F, 0.6861539883F,
  144074. 0.6865917815F, 0.6870293381F, 0.6874666576F, 0.6879037398F,
  144075. 0.6883405840F, 0.6887771899F, 0.6892135571F, 0.6896496850F,
  144076. 0.6900855733F, 0.6905212216F, 0.6909566294F, 0.6913917963F,
  144077. 0.6918267218F, 0.6922614055F, 0.6926958471F, 0.6931300459F,
  144078. 0.6935640018F, 0.6939977141F, 0.6944311825F, 0.6948644066F,
  144079. 0.6952973859F, 0.6957301200F, 0.6961626085F, 0.6965948510F,
  144080. 0.6970268470F, 0.6974585961F, 0.6978900980F, 0.6983213521F,
  144081. 0.6987523580F, 0.6991831154F, 0.6996136238F, 0.7000438828F,
  144082. 0.7004738921F, 0.7009036510F, 0.7013331594F, 0.7017624166F,
  144083. 0.7021914224F, 0.7026201763F, 0.7030486779F, 0.7034769268F,
  144084. 0.7039049226F, 0.7043326648F, 0.7047601531F, 0.7051873870F,
  144085. 0.7056143662F, 0.7060410902F, 0.7064675586F, 0.7068937711F,
  144086. 0.7073197271F, 0.7077454264F, 0.7081708684F, 0.7085960529F,
  144087. 0.7090209793F, 0.7094456474F, 0.7098700566F, 0.7102942066F,
  144088. 0.7107180970F, 0.7111417274F, 0.7115650974F, 0.7119882066F,
  144089. 0.7124110545F, 0.7128336409F, 0.7132559653F, 0.7136780272F,
  144090. 0.7140998264F, 0.7145213624F, 0.7149426348F, 0.7153636433F,
  144091. 0.7157843874F, 0.7162048668F, 0.7166250810F, 0.7170450296F,
  144092. 0.7174647124F, 0.7178841289F, 0.7183032786F, 0.7187221613F,
  144093. 0.7191407765F, 0.7195591239F, 0.7199772030F, 0.7203950135F,
  144094. 0.7208125550F, 0.7212298271F, 0.7216468294F, 0.7220635616F,
  144095. 0.7224800233F, 0.7228962140F, 0.7233121335F, 0.7237277813F,
  144096. 0.7241431571F, 0.7245582604F, 0.7249730910F, 0.7253876484F,
  144097. 0.7258019322F, 0.7262159422F, 0.7266296778F, 0.7270431388F,
  144098. 0.7274563247F, 0.7278692353F, 0.7282818700F, 0.7286942287F,
  144099. 0.7291063108F, 0.7295181160F, 0.7299296440F, 0.7303408944F,
  144100. 0.7307518669F, 0.7311625609F, 0.7315729763F, 0.7319831126F,
  144101. 0.7323929695F, 0.7328025466F, 0.7332118435F, 0.7336208600F,
  144102. 0.7340295955F, 0.7344380499F, 0.7348462226F, 0.7352541134F,
  144103. 0.7356617220F, 0.7360690478F, 0.7364760907F, 0.7368828502F,
  144104. 0.7372893259F, 0.7376955176F, 0.7381014249F, 0.7385070475F,
  144105. 0.7389123849F, 0.7393174368F, 0.7397222029F, 0.7401266829F,
  144106. 0.7405308763F, 0.7409347829F, 0.7413384023F, 0.7417417341F,
  144107. 0.7421447780F, 0.7425475338F, 0.7429500009F, 0.7433521791F,
  144108. 0.7437540681F, 0.7441556674F, 0.7445569769F, 0.7449579960F,
  144109. 0.7453587245F, 0.7457591621F, 0.7461593084F, 0.7465591631F,
  144110. 0.7469587259F, 0.7473579963F, 0.7477569741F, 0.7481556590F,
  144111. 0.7485540506F, 0.7489521486F, 0.7493499526F, 0.7497474623F,
  144112. 0.7501446775F, 0.7505415977F, 0.7509382227F, 0.7513345521F,
  144113. 0.7517305856F, 0.7521263229F, 0.7525217636F, 0.7529169074F,
  144114. 0.7533117541F, 0.7537063032F, 0.7541005545F, 0.7544945076F,
  144115. 0.7548881623F, 0.7552815182F, 0.7556745749F, 0.7560673323F,
  144116. 0.7564597899F, 0.7568519474F, 0.7572438046F, 0.7576353611F,
  144117. 0.7580266166F, 0.7584175708F, 0.7588082235F, 0.7591985741F,
  144118. 0.7595886226F, 0.7599783685F, 0.7603678116F, 0.7607569515F,
  144119. 0.7611457879F, 0.7615343206F, 0.7619225493F, 0.7623104735F,
  144120. 0.7626980931F, 0.7630854078F, 0.7634724171F, 0.7638591209F,
  144121. 0.7642455188F, 0.7646316106F, 0.7650173959F, 0.7654028744F,
  144122. 0.7657880459F, 0.7661729100F, 0.7665574664F, 0.7669417150F,
  144123. 0.7673256553F, 0.7677092871F, 0.7680926100F, 0.7684756239F,
  144124. 0.7688583284F, 0.7692407232F, 0.7696228080F, 0.7700045826F,
  144125. 0.7703860467F, 0.7707671999F, 0.7711480420F, 0.7715285728F,
  144126. 0.7719087918F, 0.7722886989F, 0.7726682938F, 0.7730475762F,
  144127. 0.7734265458F, 0.7738052023F, 0.7741835454F, 0.7745615750F,
  144128. 0.7749392906F, 0.7753166921F, 0.7756937791F, 0.7760705514F,
  144129. 0.7764470087F, 0.7768231508F, 0.7771989773F, 0.7775744880F,
  144130. 0.7779496827F, 0.7783245610F, 0.7786991227F, 0.7790733676F,
  144131. 0.7794472953F, 0.7798209056F, 0.7801941982F, 0.7805671729F,
  144132. 0.7809398294F, 0.7813121675F, 0.7816841869F, 0.7820558873F,
  144133. 0.7824272684F, 0.7827983301F, 0.7831690720F, 0.7835394940F,
  144134. 0.7839095957F, 0.7842793768F, 0.7846488373F, 0.7850179767F,
  144135. 0.7853867948F, 0.7857552914F, 0.7861234663F, 0.7864913191F,
  144136. 0.7868588497F, 0.7872260578F, 0.7875929431F, 0.7879595055F,
  144137. 0.7883257445F, 0.7886916601F, 0.7890572520F, 0.7894225198F,
  144138. 0.7897874635F, 0.7901520827F, 0.7905163772F, 0.7908803468F,
  144139. 0.7912439912F, 0.7916073102F, 0.7919703035F, 0.7923329710F,
  144140. 0.7926953124F, 0.7930573274F, 0.7934190158F, 0.7937803774F,
  144141. 0.7941414120F, 0.7945021193F, 0.7948624991F, 0.7952225511F,
  144142. 0.7955822752F, 0.7959416711F, 0.7963007387F, 0.7966594775F,
  144143. 0.7970178875F, 0.7973759685F, 0.7977337201F, 0.7980911422F,
  144144. 0.7984482346F, 0.7988049970F, 0.7991614292F, 0.7995175310F,
  144145. 0.7998733022F, 0.8002287426F, 0.8005838519F, 0.8009386299F,
  144146. 0.8012930765F, 0.8016471914F, 0.8020009744F, 0.8023544253F,
  144147. 0.8027075438F, 0.8030603298F, 0.8034127831F, 0.8037649035F,
  144148. 0.8041166906F, 0.8044681445F, 0.8048192647F, 0.8051700512F,
  144149. 0.8055205038F, 0.8058706222F, 0.8062204062F, 0.8065698556F,
  144150. 0.8069189702F, 0.8072677499F, 0.8076161944F, 0.8079643036F,
  144151. 0.8083120772F, 0.8086595151F, 0.8090066170F, 0.8093533827F,
  144152. 0.8096998122F, 0.8100459051F, 0.8103916613F, 0.8107370806F,
  144153. 0.8110821628F, 0.8114269077F, 0.8117713151F, 0.8121153849F,
  144154. 0.8124591169F, 0.8128025108F, 0.8131455666F, 0.8134882839F,
  144155. 0.8138306627F, 0.8141727027F, 0.8145144038F, 0.8148557658F,
  144156. 0.8151967886F, 0.8155374718F, 0.8158778154F, 0.8162178192F,
  144157. 0.8165574830F, 0.8168968067F, 0.8172357900F, 0.8175744328F,
  144158. 0.8179127349F, 0.8182506962F, 0.8185883164F, 0.8189255955F,
  144159. 0.8192625332F, 0.8195991295F, 0.8199353840F, 0.8202712967F,
  144160. 0.8206068673F, 0.8209420958F, 0.8212769820F, 0.8216115256F,
  144161. 0.8219457266F, 0.8222795848F, 0.8226131000F, 0.8229462721F,
  144162. 0.8232791009F, 0.8236115863F, 0.8239437280F, 0.8242755260F,
  144163. 0.8246069801F, 0.8249380901F, 0.8252688559F, 0.8255992774F,
  144164. 0.8259293544F, 0.8262590867F, 0.8265884741F, 0.8269175167F,
  144165. 0.8272462141F, 0.8275745663F, 0.8279025732F, 0.8282302344F,
  144166. 0.8285575501F, 0.8288845199F, 0.8292111437F, 0.8295374215F,
  144167. 0.8298633530F, 0.8301889382F, 0.8305141768F, 0.8308390688F,
  144168. 0.8311636141F, 0.8314878124F, 0.8318116637F, 0.8321351678F,
  144169. 0.8324583246F, 0.8327811340F, 0.8331035957F, 0.8334257098F,
  144170. 0.8337474761F, 0.8340688944F, 0.8343899647F, 0.8347106867F,
  144171. 0.8350310605F, 0.8353510857F, 0.8356707624F, 0.8359900904F,
  144172. 0.8363090696F, 0.8366276999F, 0.8369459811F, 0.8372639131F,
  144173. 0.8375814958F, 0.8378987292F, 0.8382156130F, 0.8385321472F,
  144174. 0.8388483316F, 0.8391641662F, 0.8394796508F, 0.8397947853F,
  144175. 0.8401095697F, 0.8404240037F, 0.8407380873F, 0.8410518204F,
  144176. 0.8413652029F, 0.8416782347F, 0.8419909156F, 0.8423032456F,
  144177. 0.8426152245F, 0.8429268523F, 0.8432381289F, 0.8435490541F,
  144178. 0.8438596279F, 0.8441698502F, 0.8444797208F, 0.8447892396F,
  144179. 0.8450984067F, 0.8454072218F, 0.8457156849F, 0.8460237959F,
  144180. 0.8463315547F, 0.8466389612F, 0.8469460154F, 0.8472527170F,
  144181. 0.8475590661F, 0.8478650625F, 0.8481707063F, 0.8484759971F,
  144182. 0.8487809351F, 0.8490855201F, 0.8493897521F, 0.8496936308F,
  144183. 0.8499971564F, 0.8503003286F, 0.8506031474F, 0.8509056128F,
  144184. 0.8512077246F, 0.8515094828F, 0.8518108872F, 0.8521119379F,
  144185. 0.8524126348F, 0.8527129777F, 0.8530129666F, 0.8533126015F,
  144186. 0.8536118822F, 0.8539108087F, 0.8542093809F, 0.8545075988F,
  144187. 0.8548054623F, 0.8551029712F, 0.8554001257F, 0.8556969255F,
  144188. 0.8559933707F, 0.8562894611F, 0.8565851968F, 0.8568805775F,
  144189. 0.8571756034F, 0.8574702743F, 0.8577645902F, 0.8580585509F,
  144190. 0.8583521566F, 0.8586454070F, 0.8589383021F, 0.8592308420F,
  144191. 0.8595230265F, 0.8598148556F, 0.8601063292F, 0.8603974473F,
  144192. 0.8606882098F, 0.8609786167F, 0.8612686680F, 0.8615583636F,
  144193. 0.8618477034F, 0.8621366874F, 0.8624253156F, 0.8627135878F,
  144194. 0.8630015042F, 0.8632890646F, 0.8635762690F, 0.8638631173F,
  144195. 0.8641496096F, 0.8644357457F, 0.8647215257F, 0.8650069495F,
  144196. 0.8652920171F, 0.8655767283F, 0.8658610833F, 0.8661450820F,
  144197. 0.8664287243F, 0.8667120102F, 0.8669949397F, 0.8672775127F,
  144198. 0.8675597293F, 0.8678415894F, 0.8681230929F, 0.8684042398F,
  144199. 0.8686850302F, 0.8689654640F, 0.8692455412F, 0.8695252617F,
  144200. 0.8698046255F, 0.8700836327F, 0.8703622831F, 0.8706405768F,
  144201. 0.8709185138F, 0.8711960940F, 0.8714733174F, 0.8717501840F,
  144202. 0.8720266939F, 0.8723028469F, 0.8725786430F, 0.8728540824F,
  144203. 0.8731291648F, 0.8734038905F, 0.8736782592F, 0.8739522711F,
  144204. 0.8742259261F, 0.8744992242F, 0.8747721653F, 0.8750447496F,
  144205. 0.8753169770F, 0.8755888475F, 0.8758603611F, 0.8761315177F,
  144206. 0.8764023175F, 0.8766727603F, 0.8769428462F, 0.8772125752F,
  144207. 0.8774819474F, 0.8777509626F, 0.8780196209F, 0.8782879224F,
  144208. 0.8785558669F, 0.8788234546F, 0.8790906854F, 0.8793575594F,
  144209. 0.8796240765F, 0.8798902368F, 0.8801560403F, 0.8804214870F,
  144210. 0.8806865768F, 0.8809513099F, 0.8812156863F, 0.8814797059F,
  144211. 0.8817433687F, 0.8820066749F, 0.8822696243F, 0.8825322171F,
  144212. 0.8827944532F, 0.8830563327F, 0.8833178556F, 0.8835790219F,
  144213. 0.8838398316F, 0.8841002848F, 0.8843603815F, 0.8846201217F,
  144214. 0.8848795054F, 0.8851385327F, 0.8853972036F, 0.8856555182F,
  144215. 0.8859134764F, 0.8861710783F, 0.8864283239F, 0.8866852133F,
  144216. 0.8869417464F, 0.8871979234F, 0.8874537443F, 0.8877092090F,
  144217. 0.8879643177F, 0.8882190704F, 0.8884734671F, 0.8887275078F,
  144218. 0.8889811927F, 0.8892345216F, 0.8894874948F, 0.8897401122F,
  144219. 0.8899923738F, 0.8902442798F, 0.8904958301F, 0.8907470248F,
  144220. 0.8909978640F, 0.8912483477F, 0.8914984759F, 0.8917482487F,
  144221. 0.8919976662F, 0.8922467284F, 0.8924954353F, 0.8927437871F,
  144222. 0.8929917837F, 0.8932394252F, 0.8934867118F, 0.8937336433F,
  144223. 0.8939802199F, 0.8942264417F, 0.8944723087F, 0.8947178210F,
  144224. 0.8949629785F, 0.8952077815F, 0.8954522299F, 0.8956963239F,
  144225. 0.8959400634F, 0.8961834486F, 0.8964264795F, 0.8966691561F,
  144226. 0.8969114786F, 0.8971534470F, 0.8973950614F, 0.8976363219F,
  144227. 0.8978772284F, 0.8981177812F, 0.8983579802F, 0.8985978256F,
  144228. 0.8988373174F, 0.8990764556F, 0.8993152405F, 0.8995536720F,
  144229. 0.8997917502F, 0.9000294751F, 0.9002668470F, 0.9005038658F,
  144230. 0.9007405317F, 0.9009768446F, 0.9012128048F, 0.9014484123F,
  144231. 0.9016836671F, 0.9019185693F, 0.9021531191F, 0.9023873165F,
  144232. 0.9026211616F, 0.9028546546F, 0.9030877954F, 0.9033205841F,
  144233. 0.9035530210F, 0.9037851059F, 0.9040168392F, 0.9042482207F,
  144234. 0.9044792507F, 0.9047099293F, 0.9049402564F, 0.9051702323F,
  144235. 0.9053998569F, 0.9056291305F, 0.9058580531F, 0.9060866248F,
  144236. 0.9063148457F, 0.9065427159F, 0.9067702355F, 0.9069974046F,
  144237. 0.9072242233F, 0.9074506917F, 0.9076768100F, 0.9079025782F,
  144238. 0.9081279964F, 0.9083530647F, 0.9085777833F, 0.9088021523F,
  144239. 0.9090261717F, 0.9092498417F, 0.9094731623F, 0.9096961338F,
  144240. 0.9099187561F, 0.9101410295F, 0.9103629540F, 0.9105845297F,
  144241. 0.9108057568F, 0.9110266354F, 0.9112471656F, 0.9114673475F,
  144242. 0.9116871812F, 0.9119066668F, 0.9121258046F, 0.9123445945F,
  144243. 0.9125630367F, 0.9127811314F, 0.9129988786F, 0.9132162785F,
  144244. 0.9134333312F, 0.9136500368F, 0.9138663954F, 0.9140824073F,
  144245. 0.9142980724F, 0.9145133910F, 0.9147283632F, 0.9149429890F,
  144246. 0.9151572687F, 0.9153712023F, 0.9155847900F, 0.9157980319F,
  144247. 0.9160109282F, 0.9162234790F, 0.9164356844F, 0.9166475445F,
  144248. 0.9168590595F, 0.9170702296F, 0.9172810548F, 0.9174915354F,
  144249. 0.9177016714F, 0.9179114629F, 0.9181209102F, 0.9183300134F,
  144250. 0.9185387726F, 0.9187471879F, 0.9189552595F, 0.9191629876F,
  144251. 0.9193703723F, 0.9195774136F, 0.9197841119F, 0.9199904672F,
  144252. 0.9201964797F, 0.9204021495F, 0.9206074767F, 0.9208124616F,
  144253. 0.9210171043F, 0.9212214049F, 0.9214253636F, 0.9216289805F,
  144254. 0.9218322558F, 0.9220351896F, 0.9222377821F, 0.9224400335F,
  144255. 0.9226419439F, 0.9228435134F, 0.9230447423F, 0.9232456307F,
  144256. 0.9234461787F, 0.9236463865F, 0.9238462543F, 0.9240457822F,
  144257. 0.9242449704F, 0.9244438190F, 0.9246423282F, 0.9248404983F,
  144258. 0.9250383293F, 0.9252358214F, 0.9254329747F, 0.9256297896F,
  144259. 0.9258262660F, 0.9260224042F, 0.9262182044F, 0.9264136667F,
  144260. 0.9266087913F, 0.9268035783F, 0.9269980280F, 0.9271921405F,
  144261. 0.9273859160F, 0.9275793546F, 0.9277724566F, 0.9279652221F,
  144262. 0.9281576513F, 0.9283497443F, 0.9285415014F, 0.9287329227F,
  144263. 0.9289240084F, 0.9291147586F, 0.9293051737F, 0.9294952536F,
  144264. 0.9296849987F, 0.9298744091F, 0.9300634850F, 0.9302522266F,
  144265. 0.9304406340F, 0.9306287074F, 0.9308164471F, 0.9310038532F,
  144266. 0.9311909259F, 0.9313776654F, 0.9315640719F, 0.9317501455F,
  144267. 0.9319358865F, 0.9321212951F, 0.9323063713F, 0.9324911155F,
  144268. 0.9326755279F, 0.9328596085F, 0.9330433577F, 0.9332267756F,
  144269. 0.9334098623F, 0.9335926182F, 0.9337750434F, 0.9339571380F,
  144270. 0.9341389023F, 0.9343203366F, 0.9345014409F, 0.9346822155F,
  144271. 0.9348626606F, 0.9350427763F, 0.9352225630F, 0.9354020207F,
  144272. 0.9355811498F, 0.9357599503F, 0.9359384226F, 0.9361165667F,
  144273. 0.9362943830F, 0.9364718716F, 0.9366490327F, 0.9368258666F,
  144274. 0.9370023733F, 0.9371785533F, 0.9373544066F, 0.9375299335F,
  144275. 0.9377051341F, 0.9378800087F, 0.9380545576F, 0.9382287809F,
  144276. 0.9384026787F, 0.9385762515F, 0.9387494993F, 0.9389224223F,
  144277. 0.9390950209F, 0.9392672951F, 0.9394392453F, 0.9396108716F,
  144278. 0.9397821743F, 0.9399531536F, 0.9401238096F, 0.9402941427F,
  144279. 0.9404641530F, 0.9406338407F, 0.9408032061F, 0.9409722495F,
  144280. 0.9411409709F, 0.9413093707F, 0.9414774491F, 0.9416452062F,
  144281. 0.9418126424F, 0.9419797579F, 0.9421465528F, 0.9423130274F,
  144282. 0.9424791819F, 0.9426450166F, 0.9428105317F, 0.9429757274F,
  144283. 0.9431406039F, 0.9433051616F, 0.9434694005F, 0.9436333209F,
  144284. 0.9437969232F, 0.9439602074F, 0.9441231739F, 0.9442858229F,
  144285. 0.9444481545F, 0.9446101691F, 0.9447718669F, 0.9449332481F,
  144286. 0.9450943129F, 0.9452550617F, 0.9454154945F, 0.9455756118F,
  144287. 0.9457354136F, 0.9458949003F, 0.9460540721F, 0.9462129292F,
  144288. 0.9463714719F, 0.9465297003F, 0.9466876149F, 0.9468452157F,
  144289. 0.9470025031F, 0.9471594772F, 0.9473161384F, 0.9474724869F,
  144290. 0.9476285229F, 0.9477842466F, 0.9479396584F, 0.9480947585F,
  144291. 0.9482495470F, 0.9484040243F, 0.9485581906F, 0.9487120462F,
  144292. 0.9488655913F, 0.9490188262F, 0.9491717511F, 0.9493243662F,
  144293. 0.9494766718F, 0.9496286683F, 0.9497803557F, 0.9499317345F,
  144294. 0.9500828047F, 0.9502335668F, 0.9503840209F, 0.9505341673F,
  144295. 0.9506840062F, 0.9508335380F, 0.9509827629F, 0.9511316810F,
  144296. 0.9512802928F, 0.9514285984F, 0.9515765982F, 0.9517242923F,
  144297. 0.9518716810F, 0.9520187646F, 0.9521655434F, 0.9523120176F,
  144298. 0.9524581875F, 0.9526040534F, 0.9527496154F, 0.9528948739F,
  144299. 0.9530398292F, 0.9531844814F, 0.9533288310F, 0.9534728780F,
  144300. 0.9536166229F, 0.9537600659F, 0.9539032071F, 0.9540460470F,
  144301. 0.9541885858F, 0.9543308237F, 0.9544727611F, 0.9546143981F,
  144302. 0.9547557351F, 0.9548967723F, 0.9550375100F, 0.9551779485F,
  144303. 0.9553180881F, 0.9554579290F, 0.9555974714F, 0.9557367158F,
  144304. 0.9558756623F, 0.9560143112F, 0.9561526628F, 0.9562907174F,
  144305. 0.9564284752F, 0.9565659366F, 0.9567031017F, 0.9568399710F,
  144306. 0.9569765446F, 0.9571128229F, 0.9572488061F, 0.9573844944F,
  144307. 0.9575198883F, 0.9576549879F, 0.9577897936F, 0.9579243056F,
  144308. 0.9580585242F, 0.9581924497F, 0.9583260824F, 0.9584594226F,
  144309. 0.9585924705F, 0.9587252264F, 0.9588576906F, 0.9589898634F,
  144310. 0.9591217452F, 0.9592533360F, 0.9593846364F, 0.9595156465F,
  144311. 0.9596463666F, 0.9597767971F, 0.9599069382F, 0.9600367901F,
  144312. 0.9601663533F, 0.9602956279F, 0.9604246143F, 0.9605533128F,
  144313. 0.9606817236F, 0.9608098471F, 0.9609376835F, 0.9610652332F,
  144314. 0.9611924963F, 0.9613194733F, 0.9614461644F, 0.9615725699F,
  144315. 0.9616986901F, 0.9618245253F, 0.9619500757F, 0.9620753418F,
  144316. 0.9622003238F, 0.9623250219F, 0.9624494365F, 0.9625735679F,
  144317. 0.9626974163F, 0.9628209821F, 0.9629442656F, 0.9630672671F,
  144318. 0.9631899868F, 0.9633124251F, 0.9634345822F, 0.9635564585F,
  144319. 0.9636780543F, 0.9637993699F, 0.9639204056F, 0.9640411616F,
  144320. 0.9641616383F, 0.9642818359F, 0.9644017549F, 0.9645213955F,
  144321. 0.9646407579F, 0.9647598426F, 0.9648786497F, 0.9649971797F,
  144322. 0.9651154328F, 0.9652334092F, 0.9653511095F, 0.9654685337F,
  144323. 0.9655856823F, 0.9657025556F, 0.9658191538F, 0.9659354773F,
  144324. 0.9660515263F, 0.9661673013F, 0.9662828024F, 0.9663980300F,
  144325. 0.9665129845F, 0.9666276660F, 0.9667420750F, 0.9668562118F,
  144326. 0.9669700766F, 0.9670836698F, 0.9671969917F, 0.9673100425F,
  144327. 0.9674228227F, 0.9675353325F, 0.9676475722F, 0.9677595422F,
  144328. 0.9678712428F, 0.9679826742F, 0.9680938368F, 0.9682047309F,
  144329. 0.9683153569F, 0.9684257150F, 0.9685358056F, 0.9686456289F,
  144330. 0.9687551853F, 0.9688644752F, 0.9689734987F, 0.9690822564F,
  144331. 0.9691907483F, 0.9692989750F, 0.9694069367F, 0.9695146337F,
  144332. 0.9696220663F, 0.9697292349F, 0.9698361398F, 0.9699427813F,
  144333. 0.9700491597F, 0.9701552754F, 0.9702611286F, 0.9703667197F,
  144334. 0.9704720490F, 0.9705771169F, 0.9706819236F, 0.9707864695F,
  144335. 0.9708907549F, 0.9709947802F, 0.9710985456F, 0.9712020514F,
  144336. 0.9713052981F, 0.9714082859F, 0.9715110151F, 0.9716134862F,
  144337. 0.9717156993F, 0.9718176549F, 0.9719193532F, 0.9720207946F,
  144338. 0.9721219794F, 0.9722229080F, 0.9723235806F, 0.9724239976F,
  144339. 0.9725241593F, 0.9726240661F, 0.9727237183F, 0.9728231161F,
  144340. 0.9729222601F, 0.9730211503F, 0.9731197873F, 0.9732181713F,
  144341. 0.9733163027F, 0.9734141817F, 0.9735118088F, 0.9736091842F,
  144342. 0.9737063083F, 0.9738031814F, 0.9738998039F, 0.9739961760F,
  144343. 0.9740922981F, 0.9741881706F, 0.9742837938F, 0.9743791680F,
  144344. 0.9744742935F, 0.9745691707F, 0.9746637999F, 0.9747581814F,
  144345. 0.9748523157F, 0.9749462029F, 0.9750398435F, 0.9751332378F,
  144346. 0.9752263861F, 0.9753192887F, 0.9754119461F, 0.9755043585F,
  144347. 0.9755965262F, 0.9756884496F, 0.9757801291F, 0.9758715650F,
  144348. 0.9759627575F, 0.9760537071F, 0.9761444141F, 0.9762348789F,
  144349. 0.9763251016F, 0.9764150828F, 0.9765048228F, 0.9765943218F,
  144350. 0.9766835802F, 0.9767725984F, 0.9768613767F, 0.9769499154F,
  144351. 0.9770382149F, 0.9771262755F, 0.9772140976F, 0.9773016815F,
  144352. 0.9773890275F, 0.9774761360F, 0.9775630073F, 0.9776496418F,
  144353. 0.9777360398F, 0.9778222016F, 0.9779081277F, 0.9779938182F,
  144354. 0.9780792736F, 0.9781644943F, 0.9782494805F, 0.9783342326F,
  144355. 0.9784187509F, 0.9785030359F, 0.9785870877F, 0.9786709069F,
  144356. 0.9787544936F, 0.9788378484F, 0.9789209714F, 0.9790038631F,
  144357. 0.9790865238F, 0.9791689538F, 0.9792511535F, 0.9793331232F,
  144358. 0.9794148633F, 0.9794963742F, 0.9795776561F, 0.9796587094F,
  144359. 0.9797395345F, 0.9798201316F, 0.9799005013F, 0.9799806437F,
  144360. 0.9800605593F, 0.9801402483F, 0.9802197112F, 0.9802989483F,
  144361. 0.9803779600F, 0.9804567465F, 0.9805353082F, 0.9806136455F,
  144362. 0.9806917587F, 0.9807696482F, 0.9808473143F, 0.9809247574F,
  144363. 0.9810019778F, 0.9810789759F, 0.9811557519F, 0.9812323064F,
  144364. 0.9813086395F, 0.9813847517F, 0.9814606433F, 0.9815363147F,
  144365. 0.9816117662F, 0.9816869981F, 0.9817620108F, 0.9818368047F,
  144366. 0.9819113801F, 0.9819857374F, 0.9820598769F, 0.9821337989F,
  144367. 0.9822075038F, 0.9822809920F, 0.9823542638F, 0.9824273195F,
  144368. 0.9825001596F, 0.9825727843F, 0.9826451940F, 0.9827173891F,
  144369. 0.9827893700F, 0.9828611368F, 0.9829326901F, 0.9830040302F,
  144370. 0.9830751574F, 0.9831460720F, 0.9832167745F, 0.9832872652F,
  144371. 0.9833575444F, 0.9834276124F, 0.9834974697F, 0.9835671166F,
  144372. 0.9836365535F, 0.9837057806F, 0.9837747983F, 0.9838436071F,
  144373. 0.9839122072F, 0.9839805990F, 0.9840487829F, 0.9841167591F,
  144374. 0.9841845282F, 0.9842520903F, 0.9843194459F, 0.9843865953F,
  144375. 0.9844535389F, 0.9845202771F, 0.9845868101F, 0.9846531383F,
  144376. 0.9847192622F, 0.9847851820F, 0.9848508980F, 0.9849164108F,
  144377. 0.9849817205F, 0.9850468276F, 0.9851117324F, 0.9851764352F,
  144378. 0.9852409365F, 0.9853052366F, 0.9853693358F, 0.9854332344F,
  144379. 0.9854969330F, 0.9855604317F, 0.9856237309F, 0.9856868310F,
  144380. 0.9857497325F, 0.9858124355F, 0.9858749404F, 0.9859372477F,
  144381. 0.9859993577F, 0.9860612707F, 0.9861229871F, 0.9861845072F,
  144382. 0.9862458315F, 0.9863069601F, 0.9863678936F, 0.9864286322F,
  144383. 0.9864891764F, 0.9865495264F, 0.9866096826F, 0.9866696454F,
  144384. 0.9867294152F, 0.9867889922F, 0.9868483769F, 0.9869075695F,
  144385. 0.9869665706F, 0.9870253803F, 0.9870839991F, 0.9871424273F,
  144386. 0.9872006653F, 0.9872587135F, 0.9873165721F, 0.9873742415F,
  144387. 0.9874317222F, 0.9874890144F, 0.9875461185F, 0.9876030348F,
  144388. 0.9876597638F, 0.9877163057F, 0.9877726610F, 0.9878288300F,
  144389. 0.9878848130F, 0.9879406104F, 0.9879962225F, 0.9880516497F,
  144390. 0.9881068924F, 0.9881619509F, 0.9882168256F, 0.9882715168F,
  144391. 0.9883260249F, 0.9883803502F, 0.9884344931F, 0.9884884539F,
  144392. 0.9885422331F, 0.9885958309F, 0.9886492477F, 0.9887024838F,
  144393. 0.9887555397F, 0.9888084157F, 0.9888611120F, 0.9889136292F,
  144394. 0.9889659675F, 0.9890181273F, 0.9890701089F, 0.9891219128F,
  144395. 0.9891735392F, 0.9892249885F, 0.9892762610F, 0.9893273572F,
  144396. 0.9893782774F, 0.9894290219F, 0.9894795911F, 0.9895299853F,
  144397. 0.9895802049F, 0.9896302502F, 0.9896801217F, 0.9897298196F,
  144398. 0.9897793443F, 0.9898286961F, 0.9898778755F, 0.9899268828F,
  144399. 0.9899757183F, 0.9900243823F, 0.9900728753F, 0.9901211976F,
  144400. 0.9901693495F, 0.9902173314F, 0.9902651436F, 0.9903127865F,
  144401. 0.9903602605F, 0.9904075659F, 0.9904547031F, 0.9905016723F,
  144402. 0.9905484740F, 0.9905951086F, 0.9906415763F, 0.9906878775F,
  144403. 0.9907340126F, 0.9907799819F, 0.9908257858F, 0.9908714247F,
  144404. 0.9909168988F, 0.9909622086F, 0.9910073543F, 0.9910523364F,
  144405. 0.9910971552F, 0.9911418110F, 0.9911863042F, 0.9912306351F,
  144406. 0.9912748042F, 0.9913188117F, 0.9913626580F, 0.9914063435F,
  144407. 0.9914498684F, 0.9914932333F, 0.9915364383F, 0.9915794839F,
  144408. 0.9916223703F, 0.9916650981F, 0.9917076674F, 0.9917500787F,
  144409. 0.9917923323F, 0.9918344286F, 0.9918763679F, 0.9919181505F,
  144410. 0.9919597769F, 0.9920012473F, 0.9920425621F, 0.9920837217F,
  144411. 0.9921247263F, 0.9921655765F, 0.9922062724F, 0.9922468145F,
  144412. 0.9922872030F, 0.9923274385F, 0.9923675211F, 0.9924074513F,
  144413. 0.9924472294F, 0.9924868557F, 0.9925263306F, 0.9925656544F,
  144414. 0.9926048275F, 0.9926438503F, 0.9926827230F, 0.9927214461F,
  144415. 0.9927600199F, 0.9927984446F, 0.9928367208F, 0.9928748486F,
  144416. 0.9929128285F, 0.9929506608F, 0.9929883459F, 0.9930258841F,
  144417. 0.9930632757F, 0.9931005211F, 0.9931376207F, 0.9931745747F,
  144418. 0.9932113836F, 0.9932480476F, 0.9932845671F, 0.9933209425F,
  144419. 0.9933571742F, 0.9933932623F, 0.9934292074F, 0.9934650097F,
  144420. 0.9935006696F, 0.9935361874F, 0.9935715635F, 0.9936067982F,
  144421. 0.9936418919F, 0.9936768448F, 0.9937116574F, 0.9937463300F,
  144422. 0.9937808629F, 0.9938152565F, 0.9938495111F, 0.9938836271F,
  144423. 0.9939176047F, 0.9939514444F, 0.9939851465F, 0.9940187112F,
  144424. 0.9940521391F, 0.9940854303F, 0.9941185853F, 0.9941516044F,
  144425. 0.9941844879F, 0.9942172361F, 0.9942498495F, 0.9942823283F,
  144426. 0.9943146729F, 0.9943468836F, 0.9943789608F, 0.9944109047F,
  144427. 0.9944427158F, 0.9944743944F, 0.9945059408F, 0.9945373553F,
  144428. 0.9945686384F, 0.9945997902F, 0.9946308112F, 0.9946617017F,
  144429. 0.9946924621F, 0.9947230926F, 0.9947535937F, 0.9947839656F,
  144430. 0.9948142086F, 0.9948443232F, 0.9948743097F, 0.9949041683F,
  144431. 0.9949338995F, 0.9949635035F, 0.9949929807F, 0.9950223315F,
  144432. 0.9950515561F, 0.9950806549F, 0.9951096282F, 0.9951384764F,
  144433. 0.9951671998F, 0.9951957987F, 0.9952242735F, 0.9952526245F,
  144434. 0.9952808520F, 0.9953089564F, 0.9953369380F, 0.9953647971F,
  144435. 0.9953925340F, 0.9954201491F, 0.9954476428F, 0.9954750153F,
  144436. 0.9955022670F, 0.9955293981F, 0.9955564092F, 0.9955833003F,
  144437. 0.9956100720F, 0.9956367245F, 0.9956632582F, 0.9956896733F,
  144438. 0.9957159703F, 0.9957421494F, 0.9957682110F, 0.9957941553F,
  144439. 0.9958199828F, 0.9958456937F, 0.9958712884F, 0.9958967672F,
  144440. 0.9959221305F, 0.9959473784F, 0.9959725115F, 0.9959975300F,
  144441. 0.9960224342F, 0.9960472244F, 0.9960719011F, 0.9960964644F,
  144442. 0.9961209148F, 0.9961452525F, 0.9961694779F, 0.9961935913F,
  144443. 0.9962175930F, 0.9962414834F, 0.9962652627F, 0.9962889313F,
  144444. 0.9963124895F, 0.9963359377F, 0.9963592761F, 0.9963825051F,
  144445. 0.9964056250F, 0.9964286361F, 0.9964515387F, 0.9964743332F,
  144446. 0.9964970198F, 0.9965195990F, 0.9965420709F, 0.9965644360F,
  144447. 0.9965866946F, 0.9966088469F, 0.9966308932F, 0.9966528340F,
  144448. 0.9966746695F, 0.9966964001F, 0.9967180260F, 0.9967395475F,
  144449. 0.9967609651F, 0.9967822789F, 0.9968034894F, 0.9968245968F,
  144450. 0.9968456014F, 0.9968665036F, 0.9968873037F, 0.9969080019F,
  144451. 0.9969285987F, 0.9969490942F, 0.9969694889F, 0.9969897830F,
  144452. 0.9970099769F, 0.9970300708F, 0.9970500651F, 0.9970699601F,
  144453. 0.9970897561F, 0.9971094533F, 0.9971290522F, 0.9971485531F,
  144454. 0.9971679561F, 0.9971872617F, 0.9972064702F, 0.9972255818F,
  144455. 0.9972445968F, 0.9972635157F, 0.9972823386F, 0.9973010659F,
  144456. 0.9973196980F, 0.9973382350F, 0.9973566773F, 0.9973750253F,
  144457. 0.9973932791F, 0.9974114392F, 0.9974295059F, 0.9974474793F,
  144458. 0.9974653599F, 0.9974831480F, 0.9975008438F, 0.9975184476F,
  144459. 0.9975359598F, 0.9975533806F, 0.9975707104F, 0.9975879495F,
  144460. 0.9976050981F, 0.9976221566F, 0.9976391252F, 0.9976560043F,
  144461. 0.9976727941F, 0.9976894950F, 0.9977061073F, 0.9977226312F,
  144462. 0.9977390671F, 0.9977554152F, 0.9977716759F, 0.9977878495F,
  144463. 0.9978039361F, 0.9978199363F, 0.9978358501F, 0.9978516780F,
  144464. 0.9978674202F, 0.9978830771F, 0.9978986488F, 0.9979141358F,
  144465. 0.9979295383F, 0.9979448566F, 0.9979600909F, 0.9979752417F,
  144466. 0.9979903091F, 0.9980052936F, 0.9980201952F, 0.9980350145F,
  144467. 0.9980497515F, 0.9980644067F, 0.9980789804F, 0.9980934727F,
  144468. 0.9981078841F, 0.9981222147F, 0.9981364649F, 0.9981506350F,
  144469. 0.9981647253F, 0.9981787360F, 0.9981926674F, 0.9982065199F,
  144470. 0.9982202936F, 0.9982339890F, 0.9982476062F, 0.9982611456F,
  144471. 0.9982746074F, 0.9982879920F, 0.9983012996F, 0.9983145304F,
  144472. 0.9983276849F, 0.9983407632F, 0.9983537657F, 0.9983666926F,
  144473. 0.9983795442F, 0.9983923208F, 0.9984050226F, 0.9984176501F,
  144474. 0.9984302033F, 0.9984426827F, 0.9984550884F, 0.9984674208F,
  144475. 0.9984796802F, 0.9984918667F, 0.9985039808F, 0.9985160227F,
  144476. 0.9985279926F, 0.9985398909F, 0.9985517177F, 0.9985634734F,
  144477. 0.9985751583F, 0.9985867727F, 0.9985983167F, 0.9986097907F,
  144478. 0.9986211949F, 0.9986325297F, 0.9986437953F, 0.9986549919F,
  144479. 0.9986661199F, 0.9986771795F, 0.9986881710F, 0.9986990946F,
  144480. 0.9987099507F, 0.9987207394F, 0.9987314611F, 0.9987421161F,
  144481. 0.9987527045F, 0.9987632267F, 0.9987736829F, 0.9987840734F,
  144482. 0.9987943985F, 0.9988046584F, 0.9988148534F, 0.9988249838F,
  144483. 0.9988350498F, 0.9988450516F, 0.9988549897F, 0.9988648641F,
  144484. 0.9988746753F, 0.9988844233F, 0.9988941086F, 0.9989037313F,
  144485. 0.9989132918F, 0.9989227902F, 0.9989322269F, 0.9989416021F,
  144486. 0.9989509160F, 0.9989601690F, 0.9989693613F, 0.9989784931F,
  144487. 0.9989875647F, 0.9989965763F, 0.9990055283F, 0.9990144208F,
  144488. 0.9990232541F, 0.9990320286F, 0.9990407443F, 0.9990494016F,
  144489. 0.9990580008F, 0.9990665421F, 0.9990750257F, 0.9990834519F,
  144490. 0.9990918209F, 0.9991001331F, 0.9991083886F, 0.9991165877F,
  144491. 0.9991247307F, 0.9991328177F, 0.9991408491F, 0.9991488251F,
  144492. 0.9991567460F, 0.9991646119F, 0.9991724232F, 0.9991801801F,
  144493. 0.9991878828F, 0.9991955316F, 0.9992031267F, 0.9992106684F,
  144494. 0.9992181569F, 0.9992255925F, 0.9992329753F, 0.9992403057F,
  144495. 0.9992475839F, 0.9992548101F, 0.9992619846F, 0.9992691076F,
  144496. 0.9992761793F, 0.9992832001F, 0.9992901701F, 0.9992970895F,
  144497. 0.9993039587F, 0.9993107777F, 0.9993175470F, 0.9993242667F,
  144498. 0.9993309371F, 0.9993375583F, 0.9993441307F, 0.9993506545F,
  144499. 0.9993571298F, 0.9993635570F, 0.9993699362F, 0.9993762678F,
  144500. 0.9993825519F, 0.9993887887F, 0.9993949785F, 0.9994011216F,
  144501. 0.9994072181F, 0.9994132683F, 0.9994192725F, 0.9994252307F,
  144502. 0.9994311434F, 0.9994370107F, 0.9994428327F, 0.9994486099F,
  144503. 0.9994543423F, 0.9994600303F, 0.9994656739F, 0.9994712736F,
  144504. 0.9994768294F, 0.9994823417F, 0.9994878105F, 0.9994932363F,
  144505. 0.9994986191F, 0.9995039592F, 0.9995092568F, 0.9995145122F,
  144506. 0.9995197256F, 0.9995248971F, 0.9995300270F, 0.9995351156F,
  144507. 0.9995401630F, 0.9995451695F, 0.9995501352F, 0.9995550604F,
  144508. 0.9995599454F, 0.9995647903F, 0.9995695953F, 0.9995743607F,
  144509. 0.9995790866F, 0.9995837734F, 0.9995884211F, 0.9995930300F,
  144510. 0.9995976004F, 0.9996021324F, 0.9996066263F, 0.9996110822F,
  144511. 0.9996155004F, 0.9996198810F, 0.9996242244F, 0.9996285306F,
  144512. 0.9996327999F, 0.9996370326F, 0.9996412287F, 0.9996453886F,
  144513. 0.9996495125F, 0.9996536004F, 0.9996576527F, 0.9996616696F,
  144514. 0.9996656512F, 0.9996695977F, 0.9996735094F, 0.9996773865F,
  144515. 0.9996812291F, 0.9996850374F, 0.9996888118F, 0.9996925523F,
  144516. 0.9996962591F, 0.9996999325F, 0.9997035727F, 0.9997071798F,
  144517. 0.9997107541F, 0.9997142957F, 0.9997178049F, 0.9997212818F,
  144518. 0.9997247266F, 0.9997281396F, 0.9997315209F, 0.9997348708F,
  144519. 0.9997381893F, 0.9997414767F, 0.9997447333F, 0.9997479591F,
  144520. 0.9997511544F, 0.9997543194F, 0.9997574542F, 0.9997605591F,
  144521. 0.9997636342F, 0.9997666797F, 0.9997696958F, 0.9997726828F,
  144522. 0.9997756407F, 0.9997785698F, 0.9997814703F, 0.9997843423F,
  144523. 0.9997871860F, 0.9997900016F, 0.9997927894F, 0.9997955494F,
  144524. 0.9997982818F, 0.9998009869F, 0.9998036648F, 0.9998063157F,
  144525. 0.9998089398F, 0.9998115373F, 0.9998141082F, 0.9998166529F,
  144526. 0.9998191715F, 0.9998216642F, 0.9998241311F, 0.9998265724F,
  144527. 0.9998289884F, 0.9998313790F, 0.9998337447F, 0.9998360854F,
  144528. 0.9998384015F, 0.9998406930F, 0.9998429602F, 0.9998452031F,
  144529. 0.9998474221F, 0.9998496171F, 0.9998517885F, 0.9998539364F,
  144530. 0.9998560610F, 0.9998581624F, 0.9998602407F, 0.9998622962F,
  144531. 0.9998643291F, 0.9998663394F, 0.9998683274F, 0.9998702932F,
  144532. 0.9998722370F, 0.9998741589F, 0.9998760591F, 0.9998779378F,
  144533. 0.9998797952F, 0.9998816313F, 0.9998834464F, 0.9998852406F,
  144534. 0.9998870141F, 0.9998887670F, 0.9998904995F, 0.9998922117F,
  144535. 0.9998939039F, 0.9998955761F, 0.9998972285F, 0.9998988613F,
  144536. 0.9999004746F, 0.9999020686F, 0.9999036434F, 0.9999051992F,
  144537. 0.9999067362F, 0.9999082544F, 0.9999097541F, 0.9999112354F,
  144538. 0.9999126984F, 0.9999141433F, 0.9999155703F, 0.9999169794F,
  144539. 0.9999183709F, 0.9999197449F, 0.9999211014F, 0.9999224408F,
  144540. 0.9999237631F, 0.9999250684F, 0.9999263570F, 0.9999276289F,
  144541. 0.9999288843F, 0.9999301233F, 0.9999313461F, 0.9999325529F,
  144542. 0.9999337437F, 0.9999349187F, 0.9999360780F, 0.9999372218F,
  144543. 0.9999383503F, 0.9999394635F, 0.9999405616F, 0.9999416447F,
  144544. 0.9999427129F, 0.9999437665F, 0.9999448055F, 0.9999458301F,
  144545. 0.9999468404F, 0.9999478365F, 0.9999488185F, 0.9999497867F,
  144546. 0.9999507411F, 0.9999516819F, 0.9999526091F, 0.9999535230F,
  144547. 0.9999544236F, 0.9999553111F, 0.9999561856F, 0.9999570472F,
  144548. 0.9999578960F, 0.9999587323F, 0.9999595560F, 0.9999603674F,
  144549. 0.9999611666F, 0.9999619536F, 0.9999627286F, 0.9999634917F,
  144550. 0.9999642431F, 0.9999649828F, 0.9999657110F, 0.9999664278F,
  144551. 0.9999671334F, 0.9999678278F, 0.9999685111F, 0.9999691835F,
  144552. 0.9999698451F, 0.9999704960F, 0.9999711364F, 0.9999717662F,
  144553. 0.9999723858F, 0.9999729950F, 0.9999735942F, 0.9999741834F,
  144554. 0.9999747626F, 0.9999753321F, 0.9999758919F, 0.9999764421F,
  144555. 0.9999769828F, 0.9999775143F, 0.9999780364F, 0.9999785495F,
  144556. 0.9999790535F, 0.9999795485F, 0.9999800348F, 0.9999805124F,
  144557. 0.9999809813F, 0.9999814417F, 0.9999818938F, 0.9999823375F,
  144558. 0.9999827731F, 0.9999832005F, 0.9999836200F, 0.9999840316F,
  144559. 0.9999844353F, 0.9999848314F, 0.9999852199F, 0.9999856008F,
  144560. 0.9999859744F, 0.9999863407F, 0.9999866997F, 0.9999870516F,
  144561. 0.9999873965F, 0.9999877345F, 0.9999880656F, 0.9999883900F,
  144562. 0.9999887078F, 0.9999890190F, 0.9999893237F, 0.9999896220F,
  144563. 0.9999899140F, 0.9999901999F, 0.9999904796F, 0.9999907533F,
  144564. 0.9999910211F, 0.9999912830F, 0.9999915391F, 0.9999917896F,
  144565. 0.9999920345F, 0.9999922738F, 0.9999925077F, 0.9999927363F,
  144566. 0.9999929596F, 0.9999931777F, 0.9999933907F, 0.9999935987F,
  144567. 0.9999938018F, 0.9999940000F, 0.9999941934F, 0.9999943820F,
  144568. 0.9999945661F, 0.9999947456F, 0.9999949206F, 0.9999950912F,
  144569. 0.9999952575F, 0.9999954195F, 0.9999955773F, 0.9999957311F,
  144570. 0.9999958807F, 0.9999960265F, 0.9999961683F, 0.9999963063F,
  144571. 0.9999964405F, 0.9999965710F, 0.9999966979F, 0.9999968213F,
  144572. 0.9999969412F, 0.9999970576F, 0.9999971707F, 0.9999972805F,
  144573. 0.9999973871F, 0.9999974905F, 0.9999975909F, 0.9999976881F,
  144574. 0.9999977824F, 0.9999978738F, 0.9999979624F, 0.9999980481F,
  144575. 0.9999981311F, 0.9999982115F, 0.9999982892F, 0.9999983644F,
  144576. 0.9999984370F, 0.9999985072F, 0.9999985750F, 0.9999986405F,
  144577. 0.9999987037F, 0.9999987647F, 0.9999988235F, 0.9999988802F,
  144578. 0.9999989348F, 0.9999989873F, 0.9999990379F, 0.9999990866F,
  144579. 0.9999991334F, 0.9999991784F, 0.9999992217F, 0.9999992632F,
  144580. 0.9999993030F, 0.9999993411F, 0.9999993777F, 0.9999994128F,
  144581. 0.9999994463F, 0.9999994784F, 0.9999995091F, 0.9999995384F,
  144582. 0.9999995663F, 0.9999995930F, 0.9999996184F, 0.9999996426F,
  144583. 0.9999996657F, 0.9999996876F, 0.9999997084F, 0.9999997282F,
  144584. 0.9999997469F, 0.9999997647F, 0.9999997815F, 0.9999997973F,
  144585. 0.9999998123F, 0.9999998265F, 0.9999998398F, 0.9999998524F,
  144586. 0.9999998642F, 0.9999998753F, 0.9999998857F, 0.9999998954F,
  144587. 0.9999999045F, 0.9999999130F, 0.9999999209F, 0.9999999282F,
  144588. 0.9999999351F, 0.9999999414F, 0.9999999472F, 0.9999999526F,
  144589. 0.9999999576F, 0.9999999622F, 0.9999999664F, 0.9999999702F,
  144590. 0.9999999737F, 0.9999999769F, 0.9999999798F, 0.9999999824F,
  144591. 0.9999999847F, 0.9999999868F, 0.9999999887F, 0.9999999904F,
  144592. 0.9999999919F, 0.9999999932F, 0.9999999943F, 0.9999999953F,
  144593. 0.9999999961F, 0.9999999969F, 0.9999999975F, 0.9999999980F,
  144594. 0.9999999985F, 0.9999999988F, 0.9999999991F, 0.9999999993F,
  144595. 0.9999999995F, 0.9999999997F, 0.9999999998F, 0.9999999999F,
  144596. 0.9999999999F, 1.0000000000F, 1.0000000000F, 1.0000000000F,
  144597. 1.0000000000F, 1.0000000000F, 1.0000000000F, 1.0000000000F,
  144598. };
  144599. static float *vwin[8] = {
  144600. vwin64,
  144601. vwin128,
  144602. vwin256,
  144603. vwin512,
  144604. vwin1024,
  144605. vwin2048,
  144606. vwin4096,
  144607. vwin8192,
  144608. };
  144609. float *_vorbis_window_get(int n){
  144610. return vwin[n];
  144611. }
  144612. void _vorbis_apply_window(float *d,int *winno,long *blocksizes,
  144613. int lW,int W,int nW){
  144614. lW=(W?lW:0);
  144615. nW=(W?nW:0);
  144616. {
  144617. float *windowLW=vwin[winno[lW]];
  144618. float *windowNW=vwin[winno[nW]];
  144619. long n=blocksizes[W];
  144620. long ln=blocksizes[lW];
  144621. long rn=blocksizes[nW];
  144622. long leftbegin=n/4-ln/4;
  144623. long leftend=leftbegin+ln/2;
  144624. long rightbegin=n/2+n/4-rn/4;
  144625. long rightend=rightbegin+rn/2;
  144626. int i,p;
  144627. for(i=0;i<leftbegin;i++)
  144628. d[i]=0.f;
  144629. for(p=0;i<leftend;i++,p++)
  144630. d[i]*=windowLW[p];
  144631. for(i=rightbegin,p=rn/2-1;i<rightend;i++,p--)
  144632. d[i]*=windowNW[p];
  144633. for(;i<n;i++)
  144634. d[i]=0.f;
  144635. }
  144636. }
  144637. #endif
  144638. /*** End of inlined file: window.c ***/
  144639. #else
  144640. #include <vorbis/vorbisenc.h>
  144641. #include <vorbis/codec.h>
  144642. #include <vorbis/vorbisfile.h>
  144643. #endif
  144644. }
  144645. BEGIN_JUCE_NAMESPACE
  144646. using namespace OggVorbisNamespace;
  144647. static const char* const oggFormatName = "Ogg-Vorbis file";
  144648. static const tchar* const oggExtensions[] = { T(".ogg"), 0 };
  144649. class OggReader : public AudioFormatReader
  144650. {
  144651. OggVorbis_File ovFile;
  144652. ov_callbacks callbacks;
  144653. AudioSampleBuffer reservoir;
  144654. int reservoirStart, samplesInReservoir;
  144655. public:
  144656. OggReader (InputStream* const inp)
  144657. : AudioFormatReader (inp, TRANS (oggFormatName)),
  144658. reservoir (2, 4096),
  144659. reservoirStart (0),
  144660. samplesInReservoir (0)
  144661. {
  144662. sampleRate = 0;
  144663. usesFloatingPointData = true;
  144664. callbacks.read_func = &oggReadCallback;
  144665. callbacks.seek_func = &oggSeekCallback;
  144666. callbacks.close_func = &oggCloseCallback;
  144667. callbacks.tell_func = &oggTellCallback;
  144668. const int err = ov_open_callbacks (input, &ovFile, 0, 0, callbacks);
  144669. if (err == 0)
  144670. {
  144671. vorbis_info* info = ov_info (&ovFile, -1);
  144672. lengthInSamples = (uint32) ov_pcm_total (&ovFile, -1);
  144673. numChannels = info->channels;
  144674. bitsPerSample = 16;
  144675. sampleRate = info->rate;
  144676. reservoir.setSize (numChannels,
  144677. (int) jmin (lengthInSamples, (int64) reservoir.getNumSamples()));
  144678. }
  144679. }
  144680. ~OggReader()
  144681. {
  144682. ov_clear (&ovFile);
  144683. }
  144684. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  144685. int64 startSampleInFile, int numSamples)
  144686. {
  144687. while (numSamples > 0)
  144688. {
  144689. const int numAvailable = reservoirStart + samplesInReservoir - startSampleInFile;
  144690. if (startSampleInFile >= reservoirStart && numAvailable > 0)
  144691. {
  144692. // got a few samples overlapping, so use them before seeking..
  144693. const int numToUse = jmin (numSamples, numAvailable);
  144694. for (int i = jmin (numDestChannels, reservoir.getNumChannels()); --i >= 0;)
  144695. if (destSamples[i] != 0)
  144696. memcpy (destSamples[i] + startOffsetInDestBuffer,
  144697. reservoir.getSampleData (i, (int) (startSampleInFile - reservoirStart)),
  144698. sizeof (float) * numToUse);
  144699. startSampleInFile += numToUse;
  144700. numSamples -= numToUse;
  144701. startOffsetInDestBuffer += numToUse;
  144702. if (numSamples == 0)
  144703. break;
  144704. }
  144705. if (startSampleInFile < reservoirStart
  144706. || startSampleInFile + numSamples > reservoirStart + samplesInReservoir)
  144707. {
  144708. // buffer miss, so refill the reservoir
  144709. int bitStream = 0;
  144710. reservoirStart = jmax (0, (int) startSampleInFile);
  144711. samplesInReservoir = reservoir.getNumSamples();
  144712. if (reservoirStart != (int) ov_pcm_tell (&ovFile))
  144713. ov_pcm_seek (&ovFile, reservoirStart);
  144714. int offset = 0;
  144715. int numToRead = samplesInReservoir;
  144716. while (numToRead > 0)
  144717. {
  144718. float** dataIn = 0;
  144719. const int samps = ov_read_float (&ovFile, &dataIn, numToRead, &bitStream);
  144720. if (samps <= 0)
  144721. break;
  144722. jassert (samps <= numToRead);
  144723. for (int i = jmin ((int) numChannels, reservoir.getNumChannels()); --i >= 0;)
  144724. {
  144725. memcpy (reservoir.getSampleData (i, offset),
  144726. dataIn[i],
  144727. sizeof (float) * samps);
  144728. }
  144729. numToRead -= samps;
  144730. offset += samps;
  144731. }
  144732. if (numToRead > 0)
  144733. reservoir.clear (offset, numToRead);
  144734. }
  144735. }
  144736. if (numSamples > 0)
  144737. {
  144738. for (int i = numDestChannels; --i >= 0;)
  144739. if (destSamples[i] != 0)
  144740. zeromem (destSamples[i] + startOffsetInDestBuffer,
  144741. sizeof (int) * numSamples);
  144742. }
  144743. return true;
  144744. }
  144745. static size_t oggReadCallback (void* ptr, size_t size, size_t nmemb, void* datasource)
  144746. {
  144747. return (size_t) (((InputStream*) datasource)->read (ptr, (int) (size * nmemb)) / size);
  144748. }
  144749. static int oggSeekCallback (void* datasource, ogg_int64_t offset, int whence)
  144750. {
  144751. InputStream* const in = (InputStream*) datasource;
  144752. if (whence == SEEK_CUR)
  144753. offset += in->getPosition();
  144754. else if (whence == SEEK_END)
  144755. offset += in->getTotalLength();
  144756. in->setPosition (offset);
  144757. return 0;
  144758. }
  144759. static int oggCloseCallback (void*)
  144760. {
  144761. return 0;
  144762. }
  144763. static long oggTellCallback (void* datasource)
  144764. {
  144765. return (long) ((InputStream*) datasource)->getPosition();
  144766. }
  144767. juce_UseDebuggingNewOperator
  144768. };
  144769. class OggWriter : public AudioFormatWriter
  144770. {
  144771. ogg_stream_state os;
  144772. ogg_page og;
  144773. ogg_packet op;
  144774. vorbis_info vi;
  144775. vorbis_comment vc;
  144776. vorbis_dsp_state vd;
  144777. vorbis_block vb;
  144778. public:
  144779. bool ok;
  144780. OggWriter (OutputStream* const out,
  144781. const double sampleRate,
  144782. const int numChannels,
  144783. const int bitsPerSample,
  144784. const int qualityIndex)
  144785. : AudioFormatWriter (out, TRANS (oggFormatName),
  144786. sampleRate,
  144787. numChannels,
  144788. bitsPerSample)
  144789. {
  144790. ok = false;
  144791. vorbis_info_init (&vi);
  144792. if (vorbis_encode_init_vbr (&vi,
  144793. numChannels,
  144794. (int) sampleRate,
  144795. jlimit (0.0f, 1.0f, qualityIndex * 0.5f)) == 0)
  144796. {
  144797. vorbis_comment_init (&vc);
  144798. if (JUCEApplication::getInstance() != 0)
  144799. vorbis_comment_add_tag (&vc, "ENCODER",
  144800. (char*) (const char*) JUCEApplication::getInstance()->getApplicationName());
  144801. vorbis_analysis_init (&vd, &vi);
  144802. vorbis_block_init (&vd, &vb);
  144803. ogg_stream_init (&os, Random::getSystemRandom().nextInt());
  144804. ogg_packet header;
  144805. ogg_packet header_comm;
  144806. ogg_packet header_code;
  144807. vorbis_analysis_headerout (&vd, &vc, &header, &header_comm, &header_code);
  144808. ogg_stream_packetin (&os, &header);
  144809. ogg_stream_packetin (&os, &header_comm);
  144810. ogg_stream_packetin (&os, &header_code);
  144811. for (;;)
  144812. {
  144813. if (ogg_stream_flush (&os, &og) == 0)
  144814. break;
  144815. output->write (og.header, og.header_len);
  144816. output->write (og.body, og.body_len);
  144817. }
  144818. ok = true;
  144819. }
  144820. }
  144821. ~OggWriter()
  144822. {
  144823. if (ok)
  144824. {
  144825. // write a zero-length packet to show ogg that we're finished..
  144826. write (0, 0);
  144827. ogg_stream_clear (&os);
  144828. vorbis_block_clear (&vb);
  144829. vorbis_dsp_clear (&vd);
  144830. vorbis_comment_clear (&vc);
  144831. vorbis_info_clear (&vi);
  144832. output->flush();
  144833. }
  144834. else
  144835. {
  144836. vorbis_info_clear (&vi);
  144837. output = 0; // to stop the base class deleting this, as it needs to be returned
  144838. // to the caller of createWriter()
  144839. }
  144840. }
  144841. bool write (const int** samplesToWrite, int numSamples)
  144842. {
  144843. if (! ok)
  144844. return false;
  144845. if (numSamples > 0)
  144846. {
  144847. const double gain = 1.0 / 0x80000000u;
  144848. float** const vorbisBuffer = vorbis_analysis_buffer (&vd, numSamples);
  144849. for (int i = numChannels; --i >= 0;)
  144850. {
  144851. float* const dst = vorbisBuffer[i];
  144852. const int* const src = samplesToWrite [i];
  144853. if (src != 0 && dst != 0)
  144854. {
  144855. for (int j = 0; j < numSamples; ++j)
  144856. dst[j] = (float) (src[j] * gain);
  144857. }
  144858. }
  144859. }
  144860. vorbis_analysis_wrote (&vd, numSamples);
  144861. while (vorbis_analysis_blockout (&vd, &vb) == 1)
  144862. {
  144863. vorbis_analysis (&vb, 0);
  144864. vorbis_bitrate_addblock (&vb);
  144865. while (vorbis_bitrate_flushpacket (&vd, &op))
  144866. {
  144867. ogg_stream_packetin (&os, &op);
  144868. for (;;)
  144869. {
  144870. if (ogg_stream_pageout (&os, &og) == 0)
  144871. break;
  144872. output->write (og.header, og.header_len);
  144873. output->write (og.body, og.body_len);
  144874. if (ogg_page_eos (&og))
  144875. break;
  144876. }
  144877. }
  144878. }
  144879. return true;
  144880. }
  144881. juce_UseDebuggingNewOperator
  144882. };
  144883. OggVorbisAudioFormat::OggVorbisAudioFormat()
  144884. : AudioFormat (TRANS (oggFormatName), (const tchar**) oggExtensions)
  144885. {
  144886. }
  144887. OggVorbisAudioFormat::~OggVorbisAudioFormat()
  144888. {
  144889. }
  144890. const Array <int> OggVorbisAudioFormat::getPossibleSampleRates()
  144891. {
  144892. const int rates[] = { 22050, 32000, 44100, 48000, 0 };
  144893. return Array <int> (rates);
  144894. }
  144895. const Array <int> OggVorbisAudioFormat::getPossibleBitDepths()
  144896. {
  144897. Array <int> depths;
  144898. depths.add (32);
  144899. return depths;
  144900. }
  144901. bool OggVorbisAudioFormat::canDoStereo()
  144902. {
  144903. return true;
  144904. }
  144905. bool OggVorbisAudioFormat::canDoMono()
  144906. {
  144907. return true;
  144908. }
  144909. AudioFormatReader* OggVorbisAudioFormat::createReaderFor (InputStream* in,
  144910. const bool deleteStreamIfOpeningFails)
  144911. {
  144912. ScopedPointer <OggReader> r (new OggReader (in));
  144913. if (r->sampleRate != 0)
  144914. return r.release();
  144915. if (! deleteStreamIfOpeningFails)
  144916. r->input = 0;
  144917. return 0;
  144918. }
  144919. AudioFormatWriter* OggVorbisAudioFormat::createWriterFor (OutputStream* out,
  144920. double sampleRate,
  144921. unsigned int numChannels,
  144922. int bitsPerSample,
  144923. const StringPairArray& /*metadataValues*/,
  144924. int qualityOptionIndex)
  144925. {
  144926. ScopedPointer <OggWriter> w (new OggWriter (out,
  144927. sampleRate,
  144928. numChannels,
  144929. bitsPerSample,
  144930. qualityOptionIndex));
  144931. return w->ok ? w.release() : 0;
  144932. }
  144933. bool OggVorbisAudioFormat::isCompressed()
  144934. {
  144935. return true;
  144936. }
  144937. const StringArray OggVorbisAudioFormat::getQualityOptions()
  144938. {
  144939. StringArray s;
  144940. s.add ("Low Quality");
  144941. s.add ("Medium Quality");
  144942. s.add ("High Quality");
  144943. return s;
  144944. }
  144945. int OggVorbisAudioFormat::estimateOggFileQuality (const File& source)
  144946. {
  144947. FileInputStream* const in = source.createInputStream();
  144948. if (in != 0)
  144949. {
  144950. ScopedPointer <AudioFormatReader> r (createReaderFor (in, true));
  144951. if (r != 0)
  144952. {
  144953. const int64 numSamps = r->lengthInSamples;
  144954. r = 0;
  144955. const int64 fileNumSamps = source.getSize() / 4;
  144956. const double ratio = numSamps / (double) fileNumSamps;
  144957. if (ratio > 12.0)
  144958. return 0;
  144959. else if (ratio > 6.0)
  144960. return 1;
  144961. else
  144962. return 2;
  144963. }
  144964. }
  144965. return 1;
  144966. }
  144967. END_JUCE_NAMESPACE
  144968. #endif
  144969. /*** End of inlined file: juce_OggVorbisAudioFormat.cpp ***/
  144970. #endif
  144971. #if JUCE_BUILD_CORE && ! JUCE_ONLY_BUILD_CORE_LIBRARY // do these in the core section to help balance the sizes
  144972. /*** Start of inlined file: juce_JPEGLoader.cpp ***/
  144973. #if JUCE_MSVC
  144974. #pragma warning (push)
  144975. #endif
  144976. namespace jpeglibNamespace
  144977. {
  144978. #if JUCE_INCLUDE_JPEGLIB_CODE
  144979. #if JUCE_MINGW
  144980. typedef unsigned char boolean;
  144981. #endif
  144982. extern "C"
  144983. {
  144984. #define JPEG_INTERNALS
  144985. #undef FAR
  144986. /*** Start of inlined file: jpeglib.h ***/
  144987. #ifndef JPEGLIB_H
  144988. #define JPEGLIB_H
  144989. #ifndef JCONFIG_INCLUDED /* in case jinclude.h already did */
  144990. /*** Start of inlined file: jconfig.h ***/
  144991. // disable all the warnings under MSVC
  144992. #ifdef _MSC_VER
  144993. #pragma warning (disable: 4996 4267 4100 4127 4702 4244)
  144994. #endif
  144995. #ifdef __BORLANDC__
  144996. #pragma warn -8057
  144997. #pragma warn -8019
  144998. #pragma warn -8004
  144999. #pragma warn -8008
  145000. #endif
  145001. #define HAVE_PROTOTYPES
  145002. #define HAVE_UNSIGNED_CHAR
  145003. #define HAVE_UNSIGNED_SHORT
  145004. #undef CHAR_IS_UNSIGNED
  145005. #define HAVE_STDDEF_H
  145006. #define HAVE_STDLIB_H
  145007. #undef NEED_BSD_STRINGS
  145008. #undef NEED_SYS_TYPES_H
  145009. #undef NEED_FAR_POINTERS /* we presume a 32-bit flat memory model */
  145010. #undef NEED_SHORT_EXTERNAL_NAMES
  145011. #undef INCOMPLETE_TYPES_BROKEN
  145012. #ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */
  145013. typedef unsigned char boolean;
  145014. #endif
  145015. #define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */
  145016. #ifdef JPEG_INTERNALS
  145017. #undef RIGHT_SHIFT_IS_UNSIGNED
  145018. #endif /* JPEG_INTERNALS */
  145019. #ifdef JPEG_CJPEG_DJPEG
  145020. #define BMP_SUPPORTED /* BMP image file format */
  145021. #define GIF_SUPPORTED /* GIF image file format */
  145022. #define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */
  145023. #undef RLE_SUPPORTED /* Utah RLE image file format */
  145024. #define TARGA_SUPPORTED /* Targa image file format */
  145025. #define TWO_FILE_COMMANDLINE /* optional */
  145026. #define USE_SETMODE /* Microsoft has setmode() */
  145027. #undef NEED_SIGNAL_CATCHER
  145028. #undef DONT_USE_B_MODE
  145029. #undef PROGRESS_REPORT /* optional */
  145030. #endif /* JPEG_CJPEG_DJPEG */
  145031. /*** End of inlined file: jconfig.h ***/
  145032. /* widely used configuration options */
  145033. #endif
  145034. /*** Start of inlined file: jmorecfg.h ***/
  145035. #define BITS_IN_JSAMPLE 8 /* use 8 or 12 */
  145036. #define MAX_COMPONENTS 10 /* maximum number of image components */
  145037. #if BITS_IN_JSAMPLE == 8
  145038. #ifdef HAVE_UNSIGNED_CHAR
  145039. typedef unsigned char JSAMPLE;
  145040. #define GETJSAMPLE(value) ((int) (value))
  145041. #else /* not HAVE_UNSIGNED_CHAR */
  145042. typedef char JSAMPLE;
  145043. #ifdef CHAR_IS_UNSIGNED
  145044. #define GETJSAMPLE(value) ((int) (value))
  145045. #else
  145046. #define GETJSAMPLE(value) ((int) (value) & 0xFF)
  145047. #endif /* CHAR_IS_UNSIGNED */
  145048. #endif /* HAVE_UNSIGNED_CHAR */
  145049. #define MAXJSAMPLE 255
  145050. #define CENTERJSAMPLE 128
  145051. #endif /* BITS_IN_JSAMPLE == 8 */
  145052. #if BITS_IN_JSAMPLE == 12
  145053. typedef short JSAMPLE;
  145054. #define GETJSAMPLE(value) ((int) (value))
  145055. #define MAXJSAMPLE 4095
  145056. #define CENTERJSAMPLE 2048
  145057. #endif /* BITS_IN_JSAMPLE == 12 */
  145058. typedef short JCOEF;
  145059. #ifdef HAVE_UNSIGNED_CHAR
  145060. typedef unsigned char JOCTET;
  145061. #define GETJOCTET(value) (value)
  145062. #else /* not HAVE_UNSIGNED_CHAR */
  145063. typedef char JOCTET;
  145064. #ifdef CHAR_IS_UNSIGNED
  145065. #define GETJOCTET(value) (value)
  145066. #else
  145067. #define GETJOCTET(value) ((value) & 0xFF)
  145068. #endif /* CHAR_IS_UNSIGNED */
  145069. #endif /* HAVE_UNSIGNED_CHAR */
  145070. #ifdef HAVE_UNSIGNED_CHAR
  145071. typedef unsigned char UINT8;
  145072. #else /* not HAVE_UNSIGNED_CHAR */
  145073. #ifdef CHAR_IS_UNSIGNED
  145074. typedef char UINT8;
  145075. #else /* not CHAR_IS_UNSIGNED */
  145076. typedef short UINT8;
  145077. #endif /* CHAR_IS_UNSIGNED */
  145078. #endif /* HAVE_UNSIGNED_CHAR */
  145079. #ifdef HAVE_UNSIGNED_SHORT
  145080. typedef unsigned short UINT16;
  145081. #else /* not HAVE_UNSIGNED_SHORT */
  145082. typedef unsigned int UINT16;
  145083. #endif /* HAVE_UNSIGNED_SHORT */
  145084. #ifndef XMD_H /* X11/xmd.h correctly defines INT16 */
  145085. typedef short INT16;
  145086. #endif
  145087. #ifndef XMD_H /* X11/xmd.h correctly defines INT32 */
  145088. typedef long INT32;
  145089. #endif
  145090. typedef unsigned int JDIMENSION;
  145091. #define JPEG_MAX_DIMENSION 65500L /* a tad under 64K to prevent overflows */
  145092. #define METHODDEF(type) static type
  145093. #define LOCAL(type) static type
  145094. #define GLOBAL(type) type
  145095. #define EXTERN(type) extern type
  145096. #ifdef HAVE_PROTOTYPES
  145097. #define JMETHOD(type,methodname,arglist) type (*methodname) arglist
  145098. #else
  145099. #define JMETHOD(type,methodname,arglist) type (*methodname) ()
  145100. #endif
  145101. #ifdef NEED_FAR_POINTERS
  145102. #define FAR far
  145103. #else
  145104. #define FAR
  145105. #endif
  145106. #ifndef HAVE_BOOLEAN
  145107. typedef int boolean;
  145108. #endif
  145109. #ifndef FALSE /* in case these macros already exist */
  145110. #define FALSE 0 /* values of boolean */
  145111. #endif
  145112. #ifndef TRUE
  145113. #define TRUE 1
  145114. #endif
  145115. #ifdef JPEG_INTERNALS
  145116. #define JPEG_INTERNAL_OPTIONS
  145117. #endif
  145118. #ifdef JPEG_INTERNAL_OPTIONS
  145119. #define DCT_ISLOW_SUPPORTED /* slow but accurate integer algorithm */
  145120. #define DCT_IFAST_SUPPORTED /* faster, less accurate integer method */
  145121. #define DCT_FLOAT_SUPPORTED /* floating-point: accurate, fast on fast HW */
  145122. #undef C_ARITH_CODING_SUPPORTED /* Arithmetic coding back end? */
  145123. #define C_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */
  145124. #define C_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/
  145125. #define ENTROPY_OPT_SUPPORTED /* Optimization of entropy coding parms? */
  145126. #define INPUT_SMOOTHING_SUPPORTED /* Input image smoothing option? */
  145127. #undef D_ARITH_CODING_SUPPORTED /* Arithmetic coding back end? */
  145128. #define D_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */
  145129. #define D_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/
  145130. #define SAVE_MARKERS_SUPPORTED /* jpeg_save_markers() needed? */
  145131. #define BLOCK_SMOOTHING_SUPPORTED /* Block smoothing? (Progressive only) */
  145132. #define IDCT_SCALING_SUPPORTED /* Output rescaling via IDCT? */
  145133. #undef UPSAMPLE_SCALING_SUPPORTED /* Output rescaling at upsample stage? */
  145134. #define UPSAMPLE_MERGING_SUPPORTED /* Fast path for sloppy upsampling? */
  145135. #define QUANT_1PASS_SUPPORTED /* 1-pass color quantization? */
  145136. #define QUANT_2PASS_SUPPORTED /* 2-pass color quantization? */
  145137. #define RGB_RED 0 /* Offset of Red in an RGB scanline element */
  145138. #define RGB_GREEN 1 /* Offset of Green */
  145139. #define RGB_BLUE 2 /* Offset of Blue */
  145140. #define RGB_PIXELSIZE 3 /* JSAMPLEs per RGB scanline element */
  145141. #ifndef INLINE
  145142. #ifdef __GNUC__ /* for instance, GNU C knows about inline */
  145143. #define INLINE __inline__
  145144. #endif
  145145. #ifndef INLINE
  145146. #define INLINE /* default is to define it as empty */
  145147. #endif
  145148. #endif
  145149. #ifndef MULTIPLIER
  145150. #define MULTIPLIER int /* type for fastest integer multiply */
  145151. #endif
  145152. #ifndef FAST_FLOAT
  145153. #ifdef HAVE_PROTOTYPES
  145154. #define FAST_FLOAT float
  145155. #else
  145156. #define FAST_FLOAT double
  145157. #endif
  145158. #endif
  145159. #endif /* JPEG_INTERNAL_OPTIONS */
  145160. /*** End of inlined file: jmorecfg.h ***/
  145161. /* seldom changed options */
  145162. #define JPEG_LIB_VERSION 62 /* Version 6b */
  145163. #define DCTSIZE 8 /* The basic DCT block is 8x8 samples */
  145164. #define DCTSIZE2 64 /* DCTSIZE squared; # of elements in a block */
  145165. #define NUM_QUANT_TBLS 4 /* Quantization tables are numbered 0..3 */
  145166. #define NUM_HUFF_TBLS 4 /* Huffman tables are numbered 0..3 */
  145167. #define NUM_ARITH_TBLS 16 /* Arith-coding tables are numbered 0..15 */
  145168. #define MAX_COMPS_IN_SCAN 4 /* JPEG limit on # of components in one scan */
  145169. #define MAX_SAMP_FACTOR 4 /* JPEG limit on sampling factors */
  145170. #define C_MAX_BLOCKS_IN_MCU 10 /* compressor's limit on blocks per MCU */
  145171. #ifndef D_MAX_BLOCKS_IN_MCU
  145172. #define D_MAX_BLOCKS_IN_MCU 10 /* decompressor's limit on blocks per MCU */
  145173. #endif
  145174. typedef JSAMPLE FAR *JSAMPROW; /* ptr to one image row of pixel samples. */
  145175. typedef JSAMPROW *JSAMPARRAY; /* ptr to some rows (a 2-D sample array) */
  145176. typedef JSAMPARRAY *JSAMPIMAGE; /* a 3-D sample array: top index is color */
  145177. typedef JCOEF JBLOCK[DCTSIZE2]; /* one block of coefficients */
  145178. typedef JBLOCK FAR *JBLOCKROW; /* pointer to one row of coefficient blocks */
  145179. typedef JBLOCKROW *JBLOCKARRAY; /* a 2-D array of coefficient blocks */
  145180. typedef JBLOCKARRAY *JBLOCKIMAGE; /* a 3-D array of coefficient blocks */
  145181. typedef JCOEF FAR *JCOEFPTR; /* useful in a couple of places */
  145182. typedef struct {
  145183. UINT16 quantval[DCTSIZE2]; /* quantization step for each coefficient */
  145184. boolean sent_table; /* TRUE when table has been output */
  145185. } JQUANT_TBL;
  145186. typedef struct {
  145187. UINT8 bits[17]; /* bits[k] = # of symbols with codes of */
  145188. UINT8 huffval[256]; /* The symbols, in order of incr code length */
  145189. boolean sent_table; /* TRUE when table has been output */
  145190. } JHUFF_TBL;
  145191. typedef struct {
  145192. int component_id; /* identifier for this component (0..255) */
  145193. int component_index; /* its index in SOF or cinfo->comp_info[] */
  145194. int h_samp_factor; /* horizontal sampling factor (1..4) */
  145195. int v_samp_factor; /* vertical sampling factor (1..4) */
  145196. int quant_tbl_no; /* quantization table selector (0..3) */
  145197. int dc_tbl_no; /* DC entropy table selector (0..3) */
  145198. int ac_tbl_no; /* AC entropy table selector (0..3) */
  145199. JDIMENSION width_in_blocks;
  145200. JDIMENSION height_in_blocks;
  145201. int DCT_scaled_size;
  145202. JDIMENSION downsampled_width; /* actual width in samples */
  145203. JDIMENSION downsampled_height; /* actual height in samples */
  145204. boolean component_needed; /* do we need the value of this component? */
  145205. int MCU_width; /* number of blocks per MCU, horizontally */
  145206. int MCU_height; /* number of blocks per MCU, vertically */
  145207. int MCU_blocks; /* MCU_width * MCU_height */
  145208. int MCU_sample_width; /* MCU width in samples, MCU_width*DCT_scaled_size */
  145209. int last_col_width; /* # of non-dummy blocks across in last MCU */
  145210. int last_row_height; /* # of non-dummy blocks down in last MCU */
  145211. JQUANT_TBL * quant_table;
  145212. void * dct_table;
  145213. } jpeg_component_info;
  145214. typedef struct {
  145215. int comps_in_scan; /* number of components encoded in this scan */
  145216. int component_index[MAX_COMPS_IN_SCAN]; /* their SOF/comp_info[] indexes */
  145217. int Ss, Se; /* progressive JPEG spectral selection parms */
  145218. int Ah, Al; /* progressive JPEG successive approx. parms */
  145219. } jpeg_scan_info;
  145220. typedef struct jpeg_marker_struct FAR * jpeg_saved_marker_ptr;
  145221. struct jpeg_marker_struct {
  145222. jpeg_saved_marker_ptr next; /* next in list, or NULL */
  145223. UINT8 marker; /* marker code: JPEG_COM, or JPEG_APP0+n */
  145224. unsigned int original_length; /* # bytes of data in the file */
  145225. unsigned int data_length; /* # bytes of data saved at data[] */
  145226. JOCTET FAR * data; /* the data contained in the marker */
  145227. };
  145228. typedef enum {
  145229. JCS_UNKNOWN, /* error/unspecified */
  145230. JCS_GRAYSCALE, /* monochrome */
  145231. JCS_RGB, /* red/green/blue */
  145232. JCS_YCbCr, /* Y/Cb/Cr (also known as YUV) */
  145233. JCS_CMYK, /* C/M/Y/K */
  145234. JCS_YCCK /* Y/Cb/Cr/K */
  145235. } J_COLOR_SPACE;
  145236. typedef enum {
  145237. JDCT_ISLOW, /* slow but accurate integer algorithm */
  145238. JDCT_IFAST, /* faster, less accurate integer method */
  145239. JDCT_FLOAT /* floating-point: accurate, fast on fast HW */
  145240. } J_DCT_METHOD;
  145241. #ifndef JDCT_DEFAULT /* may be overridden in jconfig.h */
  145242. #define JDCT_DEFAULT JDCT_ISLOW
  145243. #endif
  145244. #ifndef JDCT_FASTEST /* may be overridden in jconfig.h */
  145245. #define JDCT_FASTEST JDCT_IFAST
  145246. #endif
  145247. typedef enum {
  145248. JDITHER_NONE, /* no dithering */
  145249. JDITHER_ORDERED, /* simple ordered dither */
  145250. JDITHER_FS /* Floyd-Steinberg error diffusion dither */
  145251. } J_DITHER_MODE;
  145252. #define jpeg_common_fields \
  145253. struct jpeg_error_mgr * err; /* Error handler module */\
  145254. struct jpeg_memory_mgr * mem; /* Memory manager module */\
  145255. struct jpeg_progress_mgr * progress; /* Progress monitor, or NULL if none */\
  145256. void * client_data; /* Available for use by application */\
  145257. boolean is_decompressor; /* So common code can tell which is which */\
  145258. int global_state /* For checking call sequence validity */
  145259. struct jpeg_common_struct {
  145260. jpeg_common_fields; /* Fields common to both master struct types */
  145261. };
  145262. typedef struct jpeg_common_struct * j_common_ptr;
  145263. typedef struct jpeg_compress_struct * j_compress_ptr;
  145264. typedef struct jpeg_decompress_struct * j_decompress_ptr;
  145265. struct jpeg_compress_struct {
  145266. jpeg_common_fields; /* Fields shared with jpeg_decompress_struct */
  145267. struct jpeg_destination_mgr * dest;
  145268. JDIMENSION image_width; /* input image width */
  145269. JDIMENSION image_height; /* input image height */
  145270. int input_components; /* # of color components in input image */
  145271. J_COLOR_SPACE in_color_space; /* colorspace of input image */
  145272. double input_gamma; /* image gamma of input image */
  145273. int data_precision; /* bits of precision in image data */
  145274. int num_components; /* # of color components in JPEG image */
  145275. J_COLOR_SPACE jpeg_color_space; /* colorspace of JPEG image */
  145276. jpeg_component_info * comp_info;
  145277. JQUANT_TBL * quant_tbl_ptrs[NUM_QUANT_TBLS];
  145278. JHUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS];
  145279. JHUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS];
  145280. UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */
  145281. UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */
  145282. UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */
  145283. int num_scans; /* # of entries in scan_info array */
  145284. const jpeg_scan_info * scan_info; /* script for multi-scan file, or NULL */
  145285. boolean raw_data_in; /* TRUE=caller supplies downsampled data */
  145286. boolean arith_code; /* TRUE=arithmetic coding, FALSE=Huffman */
  145287. boolean optimize_coding; /* TRUE=optimize entropy encoding parms */
  145288. boolean CCIR601_sampling; /* TRUE=first samples are cosited */
  145289. int smoothing_factor; /* 1..100, or 0 for no input smoothing */
  145290. J_DCT_METHOD dct_method; /* DCT algorithm selector */
  145291. unsigned int restart_interval; /* MCUs per restart, or 0 for no restart */
  145292. int restart_in_rows; /* if > 0, MCU rows per restart interval */
  145293. boolean write_JFIF_header; /* should a JFIF marker be written? */
  145294. UINT8 JFIF_major_version; /* What to write for the JFIF version number */
  145295. UINT8 JFIF_minor_version;
  145296. UINT8 density_unit; /* JFIF code for pixel size units */
  145297. UINT16 X_density; /* Horizontal pixel density */
  145298. UINT16 Y_density; /* Vertical pixel density */
  145299. boolean write_Adobe_marker; /* should an Adobe marker be written? */
  145300. JDIMENSION next_scanline; /* 0 .. image_height-1 */
  145301. boolean progressive_mode; /* TRUE if scan script uses progressive mode */
  145302. int max_h_samp_factor; /* largest h_samp_factor */
  145303. int max_v_samp_factor; /* largest v_samp_factor */
  145304. JDIMENSION total_iMCU_rows; /* # of iMCU rows to be input to coef ctlr */
  145305. int comps_in_scan; /* # of JPEG components in this scan */
  145306. jpeg_component_info * cur_comp_info[MAX_COMPS_IN_SCAN];
  145307. JDIMENSION MCUs_per_row; /* # of MCUs across the image */
  145308. JDIMENSION MCU_rows_in_scan; /* # of MCU rows in the image */
  145309. int blocks_in_MCU; /* # of DCT blocks per MCU */
  145310. int MCU_membership[C_MAX_BLOCKS_IN_MCU];
  145311. int Ss, Se, Ah, Al; /* progressive JPEG parameters for scan */
  145312. struct jpeg_comp_master * master;
  145313. struct jpeg_c_main_controller * main;
  145314. struct jpeg_c_prep_controller * prep;
  145315. struct jpeg_c_coef_controller * coef;
  145316. struct jpeg_marker_writer * marker;
  145317. struct jpeg_color_converter * cconvert;
  145318. struct jpeg_downsampler * downsample;
  145319. struct jpeg_forward_dct * fdct;
  145320. struct jpeg_entropy_encoder * entropy;
  145321. jpeg_scan_info * script_space; /* workspace for jpeg_simple_progression */
  145322. int script_space_size;
  145323. };
  145324. struct jpeg_decompress_struct {
  145325. jpeg_common_fields; /* Fields shared with jpeg_compress_struct */
  145326. struct jpeg_source_mgr * src;
  145327. JDIMENSION image_width; /* nominal image width (from SOF marker) */
  145328. JDIMENSION image_height; /* nominal image height */
  145329. int num_components; /* # of color components in JPEG image */
  145330. J_COLOR_SPACE jpeg_color_space; /* colorspace of JPEG image */
  145331. J_COLOR_SPACE out_color_space; /* colorspace for output */
  145332. unsigned int scale_num, scale_denom; /* fraction by which to scale image */
  145333. double output_gamma; /* image gamma wanted in output */
  145334. boolean buffered_image; /* TRUE=multiple output passes */
  145335. boolean raw_data_out; /* TRUE=downsampled data wanted */
  145336. J_DCT_METHOD dct_method; /* IDCT algorithm selector */
  145337. boolean do_fancy_upsampling; /* TRUE=apply fancy upsampling */
  145338. boolean do_block_smoothing; /* TRUE=apply interblock smoothing */
  145339. boolean quantize_colors; /* TRUE=colormapped output wanted */
  145340. J_DITHER_MODE dither_mode; /* type of color dithering to use */
  145341. boolean two_pass_quantize; /* TRUE=use two-pass color quantization */
  145342. int desired_number_of_colors; /* max # colors to use in created colormap */
  145343. boolean enable_1pass_quant; /* enable future use of 1-pass quantizer */
  145344. boolean enable_external_quant;/* enable future use of external colormap */
  145345. boolean enable_2pass_quant; /* enable future use of 2-pass quantizer */
  145346. JDIMENSION output_width; /* scaled image width */
  145347. JDIMENSION output_height; /* scaled image height */
  145348. int out_color_components; /* # of color components in out_color_space */
  145349. int output_components; /* # of color components returned */
  145350. int rec_outbuf_height; /* min recommended height of scanline buffer */
  145351. int actual_number_of_colors; /* number of entries in use */
  145352. JSAMPARRAY colormap; /* The color map as a 2-D pixel array */
  145353. JDIMENSION output_scanline; /* 0 .. output_height-1 */
  145354. int input_scan_number; /* Number of SOS markers seen so far */
  145355. JDIMENSION input_iMCU_row; /* Number of iMCU rows completed */
  145356. int output_scan_number; /* Nominal scan number being displayed */
  145357. JDIMENSION output_iMCU_row; /* Number of iMCU rows read */
  145358. int (*coef_bits)[DCTSIZE2]; /* -1 or current Al value for each coef */
  145359. JQUANT_TBL * quant_tbl_ptrs[NUM_QUANT_TBLS];
  145360. JHUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS];
  145361. JHUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS];
  145362. int data_precision; /* bits of precision in image data */
  145363. jpeg_component_info * comp_info;
  145364. boolean progressive_mode; /* TRUE if SOFn specifies progressive mode */
  145365. boolean arith_code; /* TRUE=arithmetic coding, FALSE=Huffman */
  145366. UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */
  145367. UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */
  145368. UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */
  145369. unsigned int restart_interval; /* MCUs per restart interval, or 0 for no restart */
  145370. boolean saw_JFIF_marker; /* TRUE iff a JFIF APP0 marker was found */
  145371. UINT8 JFIF_major_version; /* JFIF version number */
  145372. UINT8 JFIF_minor_version;
  145373. UINT8 density_unit; /* JFIF code for pixel size units */
  145374. UINT16 X_density; /* Horizontal pixel density */
  145375. UINT16 Y_density; /* Vertical pixel density */
  145376. boolean saw_Adobe_marker; /* TRUE iff an Adobe APP14 marker was found */
  145377. UINT8 Adobe_transform; /* Color transform code from Adobe marker */
  145378. boolean CCIR601_sampling; /* TRUE=first samples are cosited */
  145379. jpeg_saved_marker_ptr marker_list; /* Head of list of saved markers */
  145380. int max_h_samp_factor; /* largest h_samp_factor */
  145381. int max_v_samp_factor; /* largest v_samp_factor */
  145382. int min_DCT_scaled_size; /* smallest DCT_scaled_size of any component */
  145383. JDIMENSION total_iMCU_rows; /* # of iMCU rows in image */
  145384. JSAMPLE * sample_range_limit; /* table for fast range-limiting */
  145385. int comps_in_scan; /* # of JPEG components in this scan */
  145386. jpeg_component_info * cur_comp_info[MAX_COMPS_IN_SCAN];
  145387. JDIMENSION MCUs_per_row; /* # of MCUs across the image */
  145388. JDIMENSION MCU_rows_in_scan; /* # of MCU rows in the image */
  145389. int blocks_in_MCU; /* # of DCT blocks per MCU */
  145390. int MCU_membership[D_MAX_BLOCKS_IN_MCU];
  145391. int Ss, Se, Ah, Al; /* progressive JPEG parameters for scan */
  145392. int unread_marker;
  145393. struct jpeg_decomp_master * master;
  145394. struct jpeg_d_main_controller * main;
  145395. struct jpeg_d_coef_controller * coef;
  145396. struct jpeg_d_post_controller * post;
  145397. struct jpeg_input_controller * inputctl;
  145398. struct jpeg_marker_reader * marker;
  145399. struct jpeg_entropy_decoder * entropy;
  145400. struct jpeg_inverse_dct * idct;
  145401. struct jpeg_upsampler * upsample;
  145402. struct jpeg_color_deconverter * cconvert;
  145403. struct jpeg_color_quantizer * cquantize;
  145404. };
  145405. struct jpeg_error_mgr {
  145406. JMETHOD(void, error_exit, (j_common_ptr cinfo));
  145407. JMETHOD(void, emit_message, (j_common_ptr cinfo, int msg_level));
  145408. JMETHOD(void, output_message, (j_common_ptr cinfo));
  145409. JMETHOD(void, format_message, (j_common_ptr cinfo, char * buffer));
  145410. #define JMSG_LENGTH_MAX 200 /* recommended size of format_message buffer */
  145411. JMETHOD(void, reset_error_mgr, (j_common_ptr cinfo));
  145412. int msg_code;
  145413. #define JMSG_STR_PARM_MAX 80
  145414. union {
  145415. int i[8];
  145416. char s[JMSG_STR_PARM_MAX];
  145417. } msg_parm;
  145418. int trace_level; /* max msg_level that will be displayed */
  145419. long num_warnings; /* number of corrupt-data warnings */
  145420. const char * const * jpeg_message_table; /* Library errors */
  145421. int last_jpeg_message; /* Table contains strings 0..last_jpeg_message */
  145422. const char * const * addon_message_table; /* Non-library errors */
  145423. int first_addon_message; /* code for first string in addon table */
  145424. int last_addon_message; /* code for last string in addon table */
  145425. };
  145426. struct jpeg_progress_mgr {
  145427. JMETHOD(void, progress_monitor, (j_common_ptr cinfo));
  145428. long pass_counter; /* work units completed in this pass */
  145429. long pass_limit; /* total number of work units in this pass */
  145430. int completed_passes; /* passes completed so far */
  145431. int total_passes; /* total number of passes expected */
  145432. };
  145433. struct jpeg_destination_mgr {
  145434. JOCTET * next_output_byte; /* => next byte to write in buffer */
  145435. size_t free_in_buffer; /* # of byte spaces remaining in buffer */
  145436. JMETHOD(void, init_destination, (j_compress_ptr cinfo));
  145437. JMETHOD(boolean, empty_output_buffer, (j_compress_ptr cinfo));
  145438. JMETHOD(void, term_destination, (j_compress_ptr cinfo));
  145439. };
  145440. struct jpeg_source_mgr {
  145441. const JOCTET * next_input_byte; /* => next byte to read from buffer */
  145442. size_t bytes_in_buffer; /* # of bytes remaining in buffer */
  145443. JMETHOD(void, init_source, (j_decompress_ptr cinfo));
  145444. JMETHOD(boolean, fill_input_buffer, (j_decompress_ptr cinfo));
  145445. JMETHOD(void, skip_input_data, (j_decompress_ptr cinfo, long num_bytes));
  145446. JMETHOD(boolean, resync_to_restart, (j_decompress_ptr cinfo, int desired));
  145447. JMETHOD(void, term_source, (j_decompress_ptr cinfo));
  145448. };
  145449. #define JPOOL_PERMANENT 0 /* lasts until master record is destroyed */
  145450. #define JPOOL_IMAGE 1 /* lasts until done with image/datastream */
  145451. #define JPOOL_NUMPOOLS 2
  145452. typedef struct jvirt_sarray_control * jvirt_sarray_ptr;
  145453. typedef struct jvirt_barray_control * jvirt_barray_ptr;
  145454. struct jpeg_memory_mgr {
  145455. JMETHOD(void *, alloc_small, (j_common_ptr cinfo, int pool_id,
  145456. size_t sizeofobject));
  145457. JMETHOD(void FAR *, alloc_large, (j_common_ptr cinfo, int pool_id,
  145458. size_t sizeofobject));
  145459. JMETHOD(JSAMPARRAY, alloc_sarray, (j_common_ptr cinfo, int pool_id,
  145460. JDIMENSION samplesperrow,
  145461. JDIMENSION numrows));
  145462. JMETHOD(JBLOCKARRAY, alloc_barray, (j_common_ptr cinfo, int pool_id,
  145463. JDIMENSION blocksperrow,
  145464. JDIMENSION numrows));
  145465. JMETHOD(jvirt_sarray_ptr, request_virt_sarray, (j_common_ptr cinfo,
  145466. int pool_id,
  145467. boolean pre_zero,
  145468. JDIMENSION samplesperrow,
  145469. JDIMENSION numrows,
  145470. JDIMENSION maxaccess));
  145471. JMETHOD(jvirt_barray_ptr, request_virt_barray, (j_common_ptr cinfo,
  145472. int pool_id,
  145473. boolean pre_zero,
  145474. JDIMENSION blocksperrow,
  145475. JDIMENSION numrows,
  145476. JDIMENSION maxaccess));
  145477. JMETHOD(void, realize_virt_arrays, (j_common_ptr cinfo));
  145478. JMETHOD(JSAMPARRAY, access_virt_sarray, (j_common_ptr cinfo,
  145479. jvirt_sarray_ptr ptr,
  145480. JDIMENSION start_row,
  145481. JDIMENSION num_rows,
  145482. boolean writable));
  145483. JMETHOD(JBLOCKARRAY, access_virt_barray, (j_common_ptr cinfo,
  145484. jvirt_barray_ptr ptr,
  145485. JDIMENSION start_row,
  145486. JDIMENSION num_rows,
  145487. boolean writable));
  145488. JMETHOD(void, free_pool, (j_common_ptr cinfo, int pool_id));
  145489. JMETHOD(void, self_destruct, (j_common_ptr cinfo));
  145490. long max_memory_to_use;
  145491. long max_alloc_chunk;
  145492. };
  145493. typedef JMETHOD(boolean, jpeg_marker_parser_method, (j_decompress_ptr cinfo));
  145494. #ifdef HAVE_PROTOTYPES
  145495. #define JPP(arglist) arglist
  145496. #else
  145497. #define JPP(arglist) ()
  145498. #endif
  145499. #ifdef NEED_SHORT_EXTERNAL_NAMES
  145500. #define jpeg_std_error jStdError
  145501. #define jpeg_CreateCompress jCreaCompress
  145502. #define jpeg_CreateDecompress jCreaDecompress
  145503. #define jpeg_destroy_compress jDestCompress
  145504. #define jpeg_destroy_decompress jDestDecompress
  145505. #define jpeg_stdio_dest jStdDest
  145506. #define jpeg_stdio_src jStdSrc
  145507. #define jpeg_set_defaults jSetDefaults
  145508. #define jpeg_set_colorspace jSetColorspace
  145509. #define jpeg_default_colorspace jDefColorspace
  145510. #define jpeg_set_quality jSetQuality
  145511. #define jpeg_set_linear_quality jSetLQuality
  145512. #define jpeg_add_quant_table jAddQuantTable
  145513. #define jpeg_quality_scaling jQualityScaling
  145514. #define jpeg_simple_progression jSimProgress
  145515. #define jpeg_suppress_tables jSuppressTables
  145516. #define jpeg_alloc_quant_table jAlcQTable
  145517. #define jpeg_alloc_huff_table jAlcHTable
  145518. #define jpeg_start_compress jStrtCompress
  145519. #define jpeg_write_scanlines jWrtScanlines
  145520. #define jpeg_finish_compress jFinCompress
  145521. #define jpeg_write_raw_data jWrtRawData
  145522. #define jpeg_write_marker jWrtMarker
  145523. #define jpeg_write_m_header jWrtMHeader
  145524. #define jpeg_write_m_byte jWrtMByte
  145525. #define jpeg_write_tables jWrtTables
  145526. #define jpeg_read_header jReadHeader
  145527. #define jpeg_start_decompress jStrtDecompress
  145528. #define jpeg_read_scanlines jReadScanlines
  145529. #define jpeg_finish_decompress jFinDecompress
  145530. #define jpeg_read_raw_data jReadRawData
  145531. #define jpeg_has_multiple_scans jHasMultScn
  145532. #define jpeg_start_output jStrtOutput
  145533. #define jpeg_finish_output jFinOutput
  145534. #define jpeg_input_complete jInComplete
  145535. #define jpeg_new_colormap jNewCMap
  145536. #define jpeg_consume_input jConsumeInput
  145537. #define jpeg_calc_output_dimensions jCalcDimensions
  145538. #define jpeg_save_markers jSaveMarkers
  145539. #define jpeg_set_marker_processor jSetMarker
  145540. #define jpeg_read_coefficients jReadCoefs
  145541. #define jpeg_write_coefficients jWrtCoefs
  145542. #define jpeg_copy_critical_parameters jCopyCrit
  145543. #define jpeg_abort_compress jAbrtCompress
  145544. #define jpeg_abort_decompress jAbrtDecompress
  145545. #define jpeg_abort jAbort
  145546. #define jpeg_destroy jDestroy
  145547. #define jpeg_resync_to_restart jResyncRestart
  145548. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  145549. EXTERN(struct jpeg_error_mgr *) jpeg_std_error
  145550. JPP((struct jpeg_error_mgr * err));
  145551. #define jpeg_create_compress(cinfo) \
  145552. jpeg_CreateCompress((cinfo), JPEG_LIB_VERSION, \
  145553. (size_t) sizeof(struct jpeg_compress_struct))
  145554. #define jpeg_create_decompress(cinfo) \
  145555. jpeg_CreateDecompress((cinfo), JPEG_LIB_VERSION, \
  145556. (size_t) sizeof(struct jpeg_decompress_struct))
  145557. EXTERN(void) jpeg_CreateCompress JPP((j_compress_ptr cinfo,
  145558. int version, size_t structsize));
  145559. EXTERN(void) jpeg_CreateDecompress JPP((j_decompress_ptr cinfo,
  145560. int version, size_t structsize));
  145561. EXTERN(void) jpeg_destroy_compress JPP((j_compress_ptr cinfo));
  145562. EXTERN(void) jpeg_destroy_decompress JPP((j_decompress_ptr cinfo));
  145563. EXTERN(void) jpeg_stdio_dest JPP((j_compress_ptr cinfo, FILE * outfile));
  145564. EXTERN(void) jpeg_stdio_src JPP((j_decompress_ptr cinfo, FILE * infile));
  145565. EXTERN(void) jpeg_set_defaults JPP((j_compress_ptr cinfo));
  145566. EXTERN(void) jpeg_set_colorspace JPP((j_compress_ptr cinfo,
  145567. J_COLOR_SPACE colorspace));
  145568. EXTERN(void) jpeg_default_colorspace JPP((j_compress_ptr cinfo));
  145569. EXTERN(void) jpeg_set_quality JPP((j_compress_ptr cinfo, int quality,
  145570. boolean force_baseline));
  145571. EXTERN(void) jpeg_set_linear_quality JPP((j_compress_ptr cinfo,
  145572. int scale_factor,
  145573. boolean force_baseline));
  145574. EXTERN(void) jpeg_add_quant_table JPP((j_compress_ptr cinfo, int which_tbl,
  145575. const unsigned int *basic_table,
  145576. int scale_factor,
  145577. boolean force_baseline));
  145578. EXTERN(int) jpeg_quality_scaling JPP((int quality));
  145579. EXTERN(void) jpeg_simple_progression JPP((j_compress_ptr cinfo));
  145580. EXTERN(void) jpeg_suppress_tables JPP((j_compress_ptr cinfo,
  145581. boolean suppress));
  145582. EXTERN(JQUANT_TBL *) jpeg_alloc_quant_table JPP((j_common_ptr cinfo));
  145583. EXTERN(JHUFF_TBL *) jpeg_alloc_huff_table JPP((j_common_ptr cinfo));
  145584. EXTERN(void) jpeg_start_compress JPP((j_compress_ptr cinfo,
  145585. boolean write_all_tables));
  145586. EXTERN(JDIMENSION) jpeg_write_scanlines JPP((j_compress_ptr cinfo,
  145587. JSAMPARRAY scanlines,
  145588. JDIMENSION num_lines));
  145589. EXTERN(void) jpeg_finish_compress JPP((j_compress_ptr cinfo));
  145590. EXTERN(JDIMENSION) jpeg_write_raw_data JPP((j_compress_ptr cinfo,
  145591. JSAMPIMAGE data,
  145592. JDIMENSION num_lines));
  145593. EXTERN(void) jpeg_write_marker
  145594. JPP((j_compress_ptr cinfo, int marker,
  145595. const JOCTET * dataptr, unsigned int datalen));
  145596. EXTERN(void) jpeg_write_m_header
  145597. JPP((j_compress_ptr cinfo, int marker, unsigned int datalen));
  145598. EXTERN(void) jpeg_write_m_byte
  145599. JPP((j_compress_ptr cinfo, int val));
  145600. EXTERN(void) jpeg_write_tables JPP((j_compress_ptr cinfo));
  145601. EXTERN(int) jpeg_read_header JPP((j_decompress_ptr cinfo,
  145602. boolean require_image));
  145603. #define JPEG_SUSPENDED 0 /* Suspended due to lack of input data */
  145604. #define JPEG_HEADER_OK 1 /* Found valid image datastream */
  145605. #define JPEG_HEADER_TABLES_ONLY 2 /* Found valid table-specs-only datastream */
  145606. EXTERN(boolean) jpeg_start_decompress JPP((j_decompress_ptr cinfo));
  145607. EXTERN(JDIMENSION) jpeg_read_scanlines JPP((j_decompress_ptr cinfo,
  145608. JSAMPARRAY scanlines,
  145609. JDIMENSION max_lines));
  145610. EXTERN(boolean) jpeg_finish_decompress JPP((j_decompress_ptr cinfo));
  145611. EXTERN(JDIMENSION) jpeg_read_raw_data JPP((j_decompress_ptr cinfo,
  145612. JSAMPIMAGE data,
  145613. JDIMENSION max_lines));
  145614. EXTERN(boolean) jpeg_has_multiple_scans JPP((j_decompress_ptr cinfo));
  145615. EXTERN(boolean) jpeg_start_output JPP((j_decompress_ptr cinfo,
  145616. int scan_number));
  145617. EXTERN(boolean) jpeg_finish_output JPP((j_decompress_ptr cinfo));
  145618. EXTERN(boolean) jpeg_input_complete JPP((j_decompress_ptr cinfo));
  145619. EXTERN(void) jpeg_new_colormap JPP((j_decompress_ptr cinfo));
  145620. EXTERN(int) jpeg_consume_input JPP((j_decompress_ptr cinfo));
  145621. #define JPEG_REACHED_SOS 1 /* Reached start of new scan */
  145622. #define JPEG_REACHED_EOI 2 /* Reached end of image */
  145623. #define JPEG_ROW_COMPLETED 3 /* Completed one iMCU row */
  145624. #define JPEG_SCAN_COMPLETED 4 /* Completed last iMCU row of a scan */
  145625. EXTERN(void) jpeg_calc_output_dimensions JPP((j_decompress_ptr cinfo));
  145626. EXTERN(void) jpeg_save_markers
  145627. JPP((j_decompress_ptr cinfo, int marker_code,
  145628. unsigned int length_limit));
  145629. EXTERN(void) jpeg_set_marker_processor
  145630. JPP((j_decompress_ptr cinfo, int marker_code,
  145631. jpeg_marker_parser_method routine));
  145632. EXTERN(jvirt_barray_ptr *) jpeg_read_coefficients JPP((j_decompress_ptr cinfo));
  145633. EXTERN(void) jpeg_write_coefficients JPP((j_compress_ptr cinfo,
  145634. jvirt_barray_ptr * coef_arrays));
  145635. EXTERN(void) jpeg_copy_critical_parameters JPP((j_decompress_ptr srcinfo,
  145636. j_compress_ptr dstinfo));
  145637. EXTERN(void) jpeg_abort_compress JPP((j_compress_ptr cinfo));
  145638. EXTERN(void) jpeg_abort_decompress JPP((j_decompress_ptr cinfo));
  145639. EXTERN(void) jpeg_abort JPP((j_common_ptr cinfo));
  145640. EXTERN(void) jpeg_destroy JPP((j_common_ptr cinfo));
  145641. EXTERN(boolean) jpeg_resync_to_restart JPP((j_decompress_ptr cinfo,
  145642. int desired));
  145643. #define JPEG_RST0 0xD0 /* RST0 marker code */
  145644. #define JPEG_EOI 0xD9 /* EOI marker code */
  145645. #define JPEG_APP0 0xE0 /* APP0 marker code */
  145646. #define JPEG_COM 0xFE /* COM marker code */
  145647. #ifdef INCOMPLETE_TYPES_BROKEN
  145648. #ifndef JPEG_INTERNALS /* will be defined in jpegint.h */
  145649. struct jvirt_sarray_control { long dummy; };
  145650. struct jvirt_barray_control { long dummy; };
  145651. struct jpeg_comp_master { long dummy; };
  145652. struct jpeg_c_main_controller { long dummy; };
  145653. struct jpeg_c_prep_controller { long dummy; };
  145654. struct jpeg_c_coef_controller { long dummy; };
  145655. struct jpeg_marker_writer { long dummy; };
  145656. struct jpeg_color_converter { long dummy; };
  145657. struct jpeg_downsampler { long dummy; };
  145658. struct jpeg_forward_dct { long dummy; };
  145659. struct jpeg_entropy_encoder { long dummy; };
  145660. struct jpeg_decomp_master { long dummy; };
  145661. struct jpeg_d_main_controller { long dummy; };
  145662. struct jpeg_d_coef_controller { long dummy; };
  145663. struct jpeg_d_post_controller { long dummy; };
  145664. struct jpeg_input_controller { long dummy; };
  145665. struct jpeg_marker_reader { long dummy; };
  145666. struct jpeg_entropy_decoder { long dummy; };
  145667. struct jpeg_inverse_dct { long dummy; };
  145668. struct jpeg_upsampler { long dummy; };
  145669. struct jpeg_color_deconverter { long dummy; };
  145670. struct jpeg_color_quantizer { long dummy; };
  145671. #endif /* JPEG_INTERNALS */
  145672. #endif /* INCOMPLETE_TYPES_BROKEN */
  145673. #ifdef JPEG_INTERNALS
  145674. /*** Start of inlined file: jpegint.h ***/
  145675. typedef enum { /* Operating modes for buffer controllers */
  145676. JBUF_PASS_THRU, /* Plain stripwise operation */
  145677. JBUF_SAVE_SOURCE, /* Run source subobject only, save output */
  145678. JBUF_CRANK_DEST, /* Run dest subobject only, using saved data */
  145679. JBUF_SAVE_AND_PASS /* Run both subobjects, save output */
  145680. } J_BUF_MODE;
  145681. #define CSTATE_START 100 /* after create_compress */
  145682. #define CSTATE_SCANNING 101 /* start_compress done, write_scanlines OK */
  145683. #define CSTATE_RAW_OK 102 /* start_compress done, write_raw_data OK */
  145684. #define CSTATE_WRCOEFS 103 /* jpeg_write_coefficients done */
  145685. #define DSTATE_START 200 /* after create_decompress */
  145686. #define DSTATE_INHEADER 201 /* reading header markers, no SOS yet */
  145687. #define DSTATE_READY 202 /* found SOS, ready for start_decompress */
  145688. #define DSTATE_PRELOAD 203 /* reading multiscan file in start_decompress*/
  145689. #define DSTATE_PRESCAN 204 /* performing dummy pass for 2-pass quant */
  145690. #define DSTATE_SCANNING 205 /* start_decompress done, read_scanlines OK */
  145691. #define DSTATE_RAW_OK 206 /* start_decompress done, read_raw_data OK */
  145692. #define DSTATE_BUFIMAGE 207 /* expecting jpeg_start_output */
  145693. #define DSTATE_BUFPOST 208 /* looking for SOS/EOI in jpeg_finish_output */
  145694. #define DSTATE_RDCOEFS 209 /* reading file in jpeg_read_coefficients */
  145695. #define DSTATE_STOPPING 210 /* looking for EOI in jpeg_finish_decompress */
  145696. struct jpeg_comp_master {
  145697. JMETHOD(void, prepare_for_pass, (j_compress_ptr cinfo));
  145698. JMETHOD(void, pass_startup, (j_compress_ptr cinfo));
  145699. JMETHOD(void, finish_pass, (j_compress_ptr cinfo));
  145700. boolean call_pass_startup; /* True if pass_startup must be called */
  145701. boolean is_last_pass; /* True during last pass */
  145702. };
  145703. struct jpeg_c_main_controller {
  145704. JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
  145705. JMETHOD(void, process_data, (j_compress_ptr cinfo,
  145706. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  145707. JDIMENSION in_rows_avail));
  145708. };
  145709. struct jpeg_c_prep_controller {
  145710. JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
  145711. JMETHOD(void, pre_process_data, (j_compress_ptr cinfo,
  145712. JSAMPARRAY input_buf,
  145713. JDIMENSION *in_row_ctr,
  145714. JDIMENSION in_rows_avail,
  145715. JSAMPIMAGE output_buf,
  145716. JDIMENSION *out_row_group_ctr,
  145717. JDIMENSION out_row_groups_avail));
  145718. };
  145719. struct jpeg_c_coef_controller {
  145720. JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
  145721. JMETHOD(boolean, compress_data, (j_compress_ptr cinfo,
  145722. JSAMPIMAGE input_buf));
  145723. };
  145724. struct jpeg_color_converter {
  145725. JMETHOD(void, start_pass, (j_compress_ptr cinfo));
  145726. JMETHOD(void, color_convert, (j_compress_ptr cinfo,
  145727. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  145728. JDIMENSION output_row, int num_rows));
  145729. };
  145730. struct jpeg_downsampler {
  145731. JMETHOD(void, start_pass, (j_compress_ptr cinfo));
  145732. JMETHOD(void, downsample, (j_compress_ptr cinfo,
  145733. JSAMPIMAGE input_buf, JDIMENSION in_row_index,
  145734. JSAMPIMAGE output_buf,
  145735. JDIMENSION out_row_group_index));
  145736. boolean need_context_rows; /* TRUE if need rows above & below */
  145737. };
  145738. struct jpeg_forward_dct {
  145739. JMETHOD(void, start_pass, (j_compress_ptr cinfo));
  145740. JMETHOD(void, forward_DCT, (j_compress_ptr cinfo,
  145741. jpeg_component_info * compptr,
  145742. JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
  145743. JDIMENSION start_row, JDIMENSION start_col,
  145744. JDIMENSION num_blocks));
  145745. };
  145746. struct jpeg_entropy_encoder {
  145747. JMETHOD(void, start_pass, (j_compress_ptr cinfo, boolean gather_statistics));
  145748. JMETHOD(boolean, encode_mcu, (j_compress_ptr cinfo, JBLOCKROW *MCU_data));
  145749. JMETHOD(void, finish_pass, (j_compress_ptr cinfo));
  145750. };
  145751. struct jpeg_marker_writer {
  145752. JMETHOD(void, write_file_header, (j_compress_ptr cinfo));
  145753. JMETHOD(void, write_frame_header, (j_compress_ptr cinfo));
  145754. JMETHOD(void, write_scan_header, (j_compress_ptr cinfo));
  145755. JMETHOD(void, write_file_trailer, (j_compress_ptr cinfo));
  145756. JMETHOD(void, write_tables_only, (j_compress_ptr cinfo));
  145757. JMETHOD(void, write_marker_header, (j_compress_ptr cinfo, int marker,
  145758. unsigned int datalen));
  145759. JMETHOD(void, write_marker_byte, (j_compress_ptr cinfo, int val));
  145760. };
  145761. struct jpeg_decomp_master {
  145762. JMETHOD(void, prepare_for_output_pass, (j_decompress_ptr cinfo));
  145763. JMETHOD(void, finish_output_pass, (j_decompress_ptr cinfo));
  145764. boolean is_dummy_pass; /* True during 1st pass for 2-pass quant */
  145765. };
  145766. struct jpeg_input_controller {
  145767. JMETHOD(int, consume_input, (j_decompress_ptr cinfo));
  145768. JMETHOD(void, reset_input_controller, (j_decompress_ptr cinfo));
  145769. JMETHOD(void, start_input_pass, (j_decompress_ptr cinfo));
  145770. JMETHOD(void, finish_input_pass, (j_decompress_ptr cinfo));
  145771. boolean has_multiple_scans; /* True if file has multiple scans */
  145772. boolean eoi_reached; /* True when EOI has been consumed */
  145773. };
  145774. struct jpeg_d_main_controller {
  145775. JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode));
  145776. JMETHOD(void, process_data, (j_decompress_ptr cinfo,
  145777. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  145778. JDIMENSION out_rows_avail));
  145779. };
  145780. struct jpeg_d_coef_controller {
  145781. JMETHOD(void, start_input_pass, (j_decompress_ptr cinfo));
  145782. JMETHOD(int, consume_data, (j_decompress_ptr cinfo));
  145783. JMETHOD(void, start_output_pass, (j_decompress_ptr cinfo));
  145784. JMETHOD(int, decompress_data, (j_decompress_ptr cinfo,
  145785. JSAMPIMAGE output_buf));
  145786. jvirt_barray_ptr *coef_arrays;
  145787. };
  145788. struct jpeg_d_post_controller {
  145789. JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode));
  145790. JMETHOD(void, post_process_data, (j_decompress_ptr cinfo,
  145791. JSAMPIMAGE input_buf,
  145792. JDIMENSION *in_row_group_ctr,
  145793. JDIMENSION in_row_groups_avail,
  145794. JSAMPARRAY output_buf,
  145795. JDIMENSION *out_row_ctr,
  145796. JDIMENSION out_rows_avail));
  145797. };
  145798. struct jpeg_marker_reader {
  145799. JMETHOD(void, reset_marker_reader, (j_decompress_ptr cinfo));
  145800. JMETHOD(int, read_markers, (j_decompress_ptr cinfo));
  145801. jpeg_marker_parser_method read_restart_marker;
  145802. boolean saw_SOI; /* found SOI? */
  145803. boolean saw_SOF; /* found SOF? */
  145804. int next_restart_num; /* next restart number expected (0-7) */
  145805. unsigned int discarded_bytes; /* # of bytes skipped looking for a marker */
  145806. };
  145807. struct jpeg_entropy_decoder {
  145808. JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  145809. JMETHOD(boolean, decode_mcu, (j_decompress_ptr cinfo,
  145810. JBLOCKROW *MCU_data));
  145811. boolean insufficient_data; /* set TRUE after emitting warning */
  145812. };
  145813. typedef JMETHOD(void, inverse_DCT_method_ptr,
  145814. (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  145815. JCOEFPTR coef_block,
  145816. JSAMPARRAY output_buf, JDIMENSION output_col));
  145817. struct jpeg_inverse_dct {
  145818. JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  145819. inverse_DCT_method_ptr inverse_DCT[MAX_COMPONENTS];
  145820. };
  145821. struct jpeg_upsampler {
  145822. JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  145823. JMETHOD(void, upsample, (j_decompress_ptr cinfo,
  145824. JSAMPIMAGE input_buf,
  145825. JDIMENSION *in_row_group_ctr,
  145826. JDIMENSION in_row_groups_avail,
  145827. JSAMPARRAY output_buf,
  145828. JDIMENSION *out_row_ctr,
  145829. JDIMENSION out_rows_avail));
  145830. boolean need_context_rows; /* TRUE if need rows above & below */
  145831. };
  145832. struct jpeg_color_deconverter {
  145833. JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  145834. JMETHOD(void, color_convert, (j_decompress_ptr cinfo,
  145835. JSAMPIMAGE input_buf, JDIMENSION input_row,
  145836. JSAMPARRAY output_buf, int num_rows));
  145837. };
  145838. struct jpeg_color_quantizer {
  145839. JMETHOD(void, start_pass, (j_decompress_ptr cinfo, boolean is_pre_scan));
  145840. JMETHOD(void, color_quantize, (j_decompress_ptr cinfo,
  145841. JSAMPARRAY input_buf, JSAMPARRAY output_buf,
  145842. int num_rows));
  145843. JMETHOD(void, finish_pass, (j_decompress_ptr cinfo));
  145844. JMETHOD(void, new_color_map, (j_decompress_ptr cinfo));
  145845. };
  145846. #undef MAX
  145847. #define MAX(a,b) ((a) > (b) ? (a) : (b))
  145848. #undef MIN
  145849. #define MIN(a,b) ((a) < (b) ? (a) : (b))
  145850. #ifdef RIGHT_SHIFT_IS_UNSIGNED
  145851. #define SHIFT_TEMPS INT32 shift_temp;
  145852. #define RIGHT_SHIFT(x,shft) \
  145853. ((shift_temp = (x)) < 0 ? \
  145854. (shift_temp >> (shft)) | ((~((INT32) 0)) << (32-(shft))) : \
  145855. (shift_temp >> (shft)))
  145856. #else
  145857. #define SHIFT_TEMPS
  145858. #define RIGHT_SHIFT(x,shft) ((x) >> (shft))
  145859. #endif
  145860. #ifdef NEED_SHORT_EXTERNAL_NAMES
  145861. #define jinit_compress_master jICompress
  145862. #define jinit_c_master_control jICMaster
  145863. #define jinit_c_main_controller jICMainC
  145864. #define jinit_c_prep_controller jICPrepC
  145865. #define jinit_c_coef_controller jICCoefC
  145866. #define jinit_color_converter jICColor
  145867. #define jinit_downsampler jIDownsampler
  145868. #define jinit_forward_dct jIFDCT
  145869. #define jinit_huff_encoder jIHEncoder
  145870. #define jinit_phuff_encoder jIPHEncoder
  145871. #define jinit_marker_writer jIMWriter
  145872. #define jinit_master_decompress jIDMaster
  145873. #define jinit_d_main_controller jIDMainC
  145874. #define jinit_d_coef_controller jIDCoefC
  145875. #define jinit_d_post_controller jIDPostC
  145876. #define jinit_input_controller jIInCtlr
  145877. #define jinit_marker_reader jIMReader
  145878. #define jinit_huff_decoder jIHDecoder
  145879. #define jinit_phuff_decoder jIPHDecoder
  145880. #define jinit_inverse_dct jIIDCT
  145881. #define jinit_upsampler jIUpsampler
  145882. #define jinit_color_deconverter jIDColor
  145883. #define jinit_1pass_quantizer jI1Quant
  145884. #define jinit_2pass_quantizer jI2Quant
  145885. #define jinit_merged_upsampler jIMUpsampler
  145886. #define jinit_memory_mgr jIMemMgr
  145887. #define jdiv_round_up jDivRound
  145888. #define jround_up jRound
  145889. #define jcopy_sample_rows jCopySamples
  145890. #define jcopy_block_row jCopyBlocks
  145891. #define jzero_far jZeroFar
  145892. #define jpeg_zigzag_order jZIGTable
  145893. #define jpeg_natural_order jZAGTable
  145894. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  145895. EXTERN(void) jinit_compress_master JPP((j_compress_ptr cinfo));
  145896. EXTERN(void) jinit_c_master_control JPP((j_compress_ptr cinfo,
  145897. boolean transcode_only));
  145898. EXTERN(void) jinit_c_main_controller JPP((j_compress_ptr cinfo,
  145899. boolean need_full_buffer));
  145900. EXTERN(void) jinit_c_prep_controller JPP((j_compress_ptr cinfo,
  145901. boolean need_full_buffer));
  145902. EXTERN(void) jinit_c_coef_controller JPP((j_compress_ptr cinfo,
  145903. boolean need_full_buffer));
  145904. EXTERN(void) jinit_color_converter JPP((j_compress_ptr cinfo));
  145905. EXTERN(void) jinit_downsampler JPP((j_compress_ptr cinfo));
  145906. EXTERN(void) jinit_forward_dct JPP((j_compress_ptr cinfo));
  145907. EXTERN(void) jinit_huff_encoder JPP((j_compress_ptr cinfo));
  145908. EXTERN(void) jinit_phuff_encoder JPP((j_compress_ptr cinfo));
  145909. EXTERN(void) jinit_marker_writer JPP((j_compress_ptr cinfo));
  145910. EXTERN(void) jinit_master_decompress JPP((j_decompress_ptr cinfo));
  145911. EXTERN(void) jinit_d_main_controller JPP((j_decompress_ptr cinfo,
  145912. boolean need_full_buffer));
  145913. EXTERN(void) jinit_d_coef_controller JPP((j_decompress_ptr cinfo,
  145914. boolean need_full_buffer));
  145915. EXTERN(void) jinit_d_post_controller JPP((j_decompress_ptr cinfo,
  145916. boolean need_full_buffer));
  145917. EXTERN(void) jinit_input_controller JPP((j_decompress_ptr cinfo));
  145918. EXTERN(void) jinit_marker_reader JPP((j_decompress_ptr cinfo));
  145919. EXTERN(void) jinit_huff_decoder JPP((j_decompress_ptr cinfo));
  145920. EXTERN(void) jinit_phuff_decoder JPP((j_decompress_ptr cinfo));
  145921. EXTERN(void) jinit_inverse_dct JPP((j_decompress_ptr cinfo));
  145922. EXTERN(void) jinit_upsampler JPP((j_decompress_ptr cinfo));
  145923. EXTERN(void) jinit_color_deconverter JPP((j_decompress_ptr cinfo));
  145924. EXTERN(void) jinit_1pass_quantizer JPP((j_decompress_ptr cinfo));
  145925. EXTERN(void) jinit_2pass_quantizer JPP((j_decompress_ptr cinfo));
  145926. EXTERN(void) jinit_merged_upsampler JPP((j_decompress_ptr cinfo));
  145927. EXTERN(void) jinit_memory_mgr JPP((j_common_ptr cinfo));
  145928. EXTERN(long) jdiv_round_up JPP((long a, long b));
  145929. EXTERN(long) jround_up JPP((long a, long b));
  145930. EXTERN(void) jcopy_sample_rows JPP((JSAMPARRAY input_array, int source_row,
  145931. JSAMPARRAY output_array, int dest_row,
  145932. int num_rows, JDIMENSION num_cols));
  145933. EXTERN(void) jcopy_block_row JPP((JBLOCKROW input_row, JBLOCKROW output_row,
  145934. JDIMENSION num_blocks));
  145935. EXTERN(void) jzero_far JPP((void FAR * target, size_t bytestozero));
  145936. #if 0 /* This table is not actually needed in v6a */
  145937. extern const int jpeg_zigzag_order[]; /* natural coef order to zigzag order */
  145938. #endif
  145939. extern const int jpeg_natural_order[]; /* zigzag coef order to natural order */
  145940. #ifdef INCOMPLETE_TYPES_BROKEN
  145941. #ifndef AM_MEMORY_MANAGER /* only jmemmgr.c defines these */
  145942. struct jvirt_sarray_control { long dummy; };
  145943. struct jvirt_barray_control { long dummy; };
  145944. #endif
  145945. #endif /* INCOMPLETE_TYPES_BROKEN */
  145946. /*** End of inlined file: jpegint.h ***/
  145947. /* fetch private declarations */
  145948. /*** Start of inlined file: jerror.h ***/
  145949. #ifndef JMESSAGE
  145950. #ifndef JERROR_H
  145951. #define JMAKE_ENUM_LIST
  145952. #else
  145953. #define JMESSAGE(code,string)
  145954. #endif /* JERROR_H */
  145955. #endif /* JMESSAGE */
  145956. #ifdef JMAKE_ENUM_LIST
  145957. typedef enum {
  145958. #define JMESSAGE(code,string) code ,
  145959. #endif /* JMAKE_ENUM_LIST */
  145960. JMESSAGE(JMSG_NOMESSAGE, "Bogus message code %d") /* Must be first entry! */
  145961. JMESSAGE(JERR_ARITH_NOTIMPL,
  145962. "Sorry, there are legal restrictions on arithmetic coding")
  145963. JMESSAGE(JERR_BAD_ALIGN_TYPE, "ALIGN_TYPE is wrong, please fix")
  145964. JMESSAGE(JERR_BAD_ALLOC_CHUNK, "MAX_ALLOC_CHUNK is wrong, please fix")
  145965. JMESSAGE(JERR_BAD_BUFFER_MODE, "Bogus buffer control mode")
  145966. JMESSAGE(JERR_BAD_COMPONENT_ID, "Invalid component ID %d in SOS")
  145967. JMESSAGE(JERR_BAD_DCT_COEF, "DCT coefficient out of range")
  145968. JMESSAGE(JERR_BAD_DCTSIZE, "IDCT output block size %d not supported")
  145969. JMESSAGE(JERR_BAD_HUFF_TABLE, "Bogus Huffman table definition")
  145970. JMESSAGE(JERR_BAD_IN_COLORSPACE, "Bogus input colorspace")
  145971. JMESSAGE(JERR_BAD_J_COLORSPACE, "Bogus JPEG colorspace")
  145972. JMESSAGE(JERR_BAD_LENGTH, "Bogus marker length")
  145973. JMESSAGE(JERR_BAD_LIB_VERSION,
  145974. "Wrong JPEG library version: library is %d, caller expects %d")
  145975. JMESSAGE(JERR_BAD_MCU_SIZE, "Sampling factors too large for interleaved scan")
  145976. JMESSAGE(JERR_BAD_POOL_ID, "Invalid memory pool code %d")
  145977. JMESSAGE(JERR_BAD_PRECISION, "Unsupported JPEG data precision %d")
  145978. JMESSAGE(JERR_BAD_PROGRESSION,
  145979. "Invalid progressive parameters Ss=%d Se=%d Ah=%d Al=%d")
  145980. JMESSAGE(JERR_BAD_PROG_SCRIPT,
  145981. "Invalid progressive parameters at scan script entry %d")
  145982. JMESSAGE(JERR_BAD_SAMPLING, "Bogus sampling factors")
  145983. JMESSAGE(JERR_BAD_SCAN_SCRIPT, "Invalid scan script at entry %d")
  145984. JMESSAGE(JERR_BAD_STATE, "Improper call to JPEG library in state %d")
  145985. JMESSAGE(JERR_BAD_STRUCT_SIZE,
  145986. "JPEG parameter struct mismatch: library thinks size is %u, caller expects %u")
  145987. JMESSAGE(JERR_BAD_VIRTUAL_ACCESS, "Bogus virtual array access")
  145988. JMESSAGE(JERR_BUFFER_SIZE, "Buffer passed to JPEG library is too small")
  145989. JMESSAGE(JERR_CANT_SUSPEND, "Suspension not allowed here")
  145990. JMESSAGE(JERR_CCIR601_NOTIMPL, "CCIR601 sampling not implemented yet")
  145991. JMESSAGE(JERR_COMPONENT_COUNT, "Too many color components: %d, max %d")
  145992. JMESSAGE(JERR_CONVERSION_NOTIMPL, "Unsupported color conversion request")
  145993. JMESSAGE(JERR_DAC_INDEX, "Bogus DAC index %d")
  145994. JMESSAGE(JERR_DAC_VALUE, "Bogus DAC value 0x%x")
  145995. JMESSAGE(JERR_DHT_INDEX, "Bogus DHT index %d")
  145996. JMESSAGE(JERR_DQT_INDEX, "Bogus DQT index %d")
  145997. JMESSAGE(JERR_EMPTY_IMAGE, "Empty JPEG image (DNL not supported)")
  145998. JMESSAGE(JERR_EMS_READ, "Read from EMS failed")
  145999. JMESSAGE(JERR_EMS_WRITE, "Write to EMS failed")
  146000. JMESSAGE(JERR_EOI_EXPECTED, "Didn't expect more than one scan")
  146001. JMESSAGE(JERR_FILE_READ, "Input file read error")
  146002. JMESSAGE(JERR_FILE_WRITE, "Output file write error --- out of disk space?")
  146003. JMESSAGE(JERR_FRACT_SAMPLE_NOTIMPL, "Fractional sampling not implemented yet")
  146004. JMESSAGE(JERR_HUFF_CLEN_OVERFLOW, "Huffman code size table overflow")
  146005. JMESSAGE(JERR_HUFF_MISSING_CODE, "Missing Huffman code table entry")
  146006. JMESSAGE(JERR_IMAGE_TOO_BIG, "Maximum supported image dimension is %u pixels")
  146007. JMESSAGE(JERR_INPUT_EMPTY, "Empty input file")
  146008. JMESSAGE(JERR_INPUT_EOF, "Premature end of input file")
  146009. JMESSAGE(JERR_MISMATCHED_QUANT_TABLE,
  146010. "Cannot transcode due to multiple use of quantization table %d")
  146011. JMESSAGE(JERR_MISSING_DATA, "Scan script does not transmit all data")
  146012. JMESSAGE(JERR_MODE_CHANGE, "Invalid color quantization mode change")
  146013. JMESSAGE(JERR_NOTIMPL, "Not implemented yet")
  146014. JMESSAGE(JERR_NOT_COMPILED, "Requested feature was omitted at compile time")
  146015. JMESSAGE(JERR_NO_BACKING_STORE, "Backing store not supported")
  146016. JMESSAGE(JERR_NO_HUFF_TABLE, "Huffman table 0x%02x was not defined")
  146017. JMESSAGE(JERR_NO_IMAGE, "JPEG datastream contains no image")
  146018. JMESSAGE(JERR_NO_QUANT_TABLE, "Quantization table 0x%02x was not defined")
  146019. JMESSAGE(JERR_NO_SOI, "Not a JPEG file: starts with 0x%02x 0x%02x")
  146020. JMESSAGE(JERR_OUT_OF_MEMORY, "Insufficient memory (case %d)")
  146021. JMESSAGE(JERR_QUANT_COMPONENTS,
  146022. "Cannot quantize more than %d color components")
  146023. JMESSAGE(JERR_QUANT_FEW_COLORS, "Cannot quantize to fewer than %d colors")
  146024. JMESSAGE(JERR_QUANT_MANY_COLORS, "Cannot quantize to more than %d colors")
  146025. JMESSAGE(JERR_SOF_DUPLICATE, "Invalid JPEG file structure: two SOF markers")
  146026. JMESSAGE(JERR_SOF_NO_SOS, "Invalid JPEG file structure: missing SOS marker")
  146027. JMESSAGE(JERR_SOF_UNSUPPORTED, "Unsupported JPEG process: SOF type 0x%02x")
  146028. JMESSAGE(JERR_SOI_DUPLICATE, "Invalid JPEG file structure: two SOI markers")
  146029. JMESSAGE(JERR_SOS_NO_SOF, "Invalid JPEG file structure: SOS before SOF")
  146030. JMESSAGE(JERR_TFILE_CREATE, "Failed to create temporary file %s")
  146031. JMESSAGE(JERR_TFILE_READ, "Read failed on temporary file")
  146032. JMESSAGE(JERR_TFILE_SEEK, "Seek failed on temporary file")
  146033. JMESSAGE(JERR_TFILE_WRITE,
  146034. "Write failed on temporary file --- out of disk space?")
  146035. JMESSAGE(JERR_TOO_LITTLE_DATA, "Application transferred too few scanlines")
  146036. JMESSAGE(JERR_UNKNOWN_MARKER, "Unsupported marker type 0x%02x")
  146037. JMESSAGE(JERR_VIRTUAL_BUG, "Virtual array controller messed up")
  146038. JMESSAGE(JERR_WIDTH_OVERFLOW, "Image too wide for this implementation")
  146039. JMESSAGE(JERR_XMS_READ, "Read from XMS failed")
  146040. JMESSAGE(JERR_XMS_WRITE, "Write to XMS failed")
  146041. JMESSAGE(JMSG_COPYRIGHT, JCOPYRIGHT)
  146042. JMESSAGE(JMSG_VERSION, JVERSION)
  146043. JMESSAGE(JTRC_16BIT_TABLES,
  146044. "Caution: quantization tables are too coarse for baseline JPEG")
  146045. JMESSAGE(JTRC_ADOBE,
  146046. "Adobe APP14 marker: version %d, flags 0x%04x 0x%04x, transform %d")
  146047. JMESSAGE(JTRC_APP0, "Unknown APP0 marker (not JFIF), length %u")
  146048. JMESSAGE(JTRC_APP14, "Unknown APP14 marker (not Adobe), length %u")
  146049. JMESSAGE(JTRC_DAC, "Define Arithmetic Table 0x%02x: 0x%02x")
  146050. JMESSAGE(JTRC_DHT, "Define Huffman Table 0x%02x")
  146051. JMESSAGE(JTRC_DQT, "Define Quantization Table %d precision %d")
  146052. JMESSAGE(JTRC_DRI, "Define Restart Interval %u")
  146053. JMESSAGE(JTRC_EMS_CLOSE, "Freed EMS handle %u")
  146054. JMESSAGE(JTRC_EMS_OPEN, "Obtained EMS handle %u")
  146055. JMESSAGE(JTRC_EOI, "End Of Image")
  146056. JMESSAGE(JTRC_HUFFBITS, " %3d %3d %3d %3d %3d %3d %3d %3d")
  146057. JMESSAGE(JTRC_JFIF, "JFIF APP0 marker: version %d.%02d, density %dx%d %d")
  146058. JMESSAGE(JTRC_JFIF_BADTHUMBNAILSIZE,
  146059. "Warning: thumbnail image size does not match data length %u")
  146060. JMESSAGE(JTRC_JFIF_EXTENSION,
  146061. "JFIF extension marker: type 0x%02x, length %u")
  146062. JMESSAGE(JTRC_JFIF_THUMBNAIL, " with %d x %d thumbnail image")
  146063. JMESSAGE(JTRC_MISC_MARKER, "Miscellaneous marker 0x%02x, length %u")
  146064. JMESSAGE(JTRC_PARMLESS_MARKER, "Unexpected marker 0x%02x")
  146065. JMESSAGE(JTRC_QUANTVALS, " %4u %4u %4u %4u %4u %4u %4u %4u")
  146066. JMESSAGE(JTRC_QUANT_3_NCOLORS, "Quantizing to %d = %d*%d*%d colors")
  146067. JMESSAGE(JTRC_QUANT_NCOLORS, "Quantizing to %d colors")
  146068. JMESSAGE(JTRC_QUANT_SELECTED, "Selected %d colors for quantization")
  146069. JMESSAGE(JTRC_RECOVERY_ACTION, "At marker 0x%02x, recovery action %d")
  146070. JMESSAGE(JTRC_RST, "RST%d")
  146071. JMESSAGE(JTRC_SMOOTH_NOTIMPL,
  146072. "Smoothing not supported with nonstandard sampling ratios")
  146073. JMESSAGE(JTRC_SOF, "Start Of Frame 0x%02x: width=%u, height=%u, components=%d")
  146074. JMESSAGE(JTRC_SOF_COMPONENT, " Component %d: %dhx%dv q=%d")
  146075. JMESSAGE(JTRC_SOI, "Start of Image")
  146076. JMESSAGE(JTRC_SOS, "Start Of Scan: %d components")
  146077. JMESSAGE(JTRC_SOS_COMPONENT, " Component %d: dc=%d ac=%d")
  146078. JMESSAGE(JTRC_SOS_PARAMS, " Ss=%d, Se=%d, Ah=%d, Al=%d")
  146079. JMESSAGE(JTRC_TFILE_CLOSE, "Closed temporary file %s")
  146080. JMESSAGE(JTRC_TFILE_OPEN, "Opened temporary file %s")
  146081. JMESSAGE(JTRC_THUMB_JPEG,
  146082. "JFIF extension marker: JPEG-compressed thumbnail image, length %u")
  146083. JMESSAGE(JTRC_THUMB_PALETTE,
  146084. "JFIF extension marker: palette thumbnail image, length %u")
  146085. JMESSAGE(JTRC_THUMB_RGB,
  146086. "JFIF extension marker: RGB thumbnail image, length %u")
  146087. JMESSAGE(JTRC_UNKNOWN_IDS,
  146088. "Unrecognized component IDs %d %d %d, assuming YCbCr")
  146089. JMESSAGE(JTRC_XMS_CLOSE, "Freed XMS handle %u")
  146090. JMESSAGE(JTRC_XMS_OPEN, "Obtained XMS handle %u")
  146091. JMESSAGE(JWRN_ADOBE_XFORM, "Unknown Adobe color transform code %d")
  146092. JMESSAGE(JWRN_BOGUS_PROGRESSION,
  146093. "Inconsistent progression sequence for component %d coefficient %d")
  146094. JMESSAGE(JWRN_EXTRANEOUS_DATA,
  146095. "Corrupt JPEG data: %u extraneous bytes before marker 0x%02x")
  146096. JMESSAGE(JWRN_HIT_MARKER, "Corrupt JPEG data: premature end of data segment")
  146097. JMESSAGE(JWRN_HUFF_BAD_CODE, "Corrupt JPEG data: bad Huffman code")
  146098. JMESSAGE(JWRN_JFIF_MAJOR, "Warning: unknown JFIF revision number %d.%02d")
  146099. JMESSAGE(JWRN_JPEG_EOF, "Premature end of JPEG file")
  146100. JMESSAGE(JWRN_MUST_RESYNC,
  146101. "Corrupt JPEG data: found marker 0x%02x instead of RST%d")
  146102. JMESSAGE(JWRN_NOT_SEQUENTIAL, "Invalid SOS parameters for sequential JPEG")
  146103. JMESSAGE(JWRN_TOO_MUCH_DATA, "Application transferred too many scanlines")
  146104. #ifdef JMAKE_ENUM_LIST
  146105. JMSG_LASTMSGCODE
  146106. } J_MESSAGE_CODE;
  146107. #undef JMAKE_ENUM_LIST
  146108. #endif /* JMAKE_ENUM_LIST */
  146109. #undef JMESSAGE
  146110. #ifndef JERROR_H
  146111. #define JERROR_H
  146112. #define ERREXIT(cinfo,code) \
  146113. ((cinfo)->err->msg_code = (code), \
  146114. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  146115. #define ERREXIT1(cinfo,code,p1) \
  146116. ((cinfo)->err->msg_code = (code), \
  146117. (cinfo)->err->msg_parm.i[0] = (p1), \
  146118. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  146119. #define ERREXIT2(cinfo,code,p1,p2) \
  146120. ((cinfo)->err->msg_code = (code), \
  146121. (cinfo)->err->msg_parm.i[0] = (p1), \
  146122. (cinfo)->err->msg_parm.i[1] = (p2), \
  146123. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  146124. #define ERREXIT3(cinfo,code,p1,p2,p3) \
  146125. ((cinfo)->err->msg_code = (code), \
  146126. (cinfo)->err->msg_parm.i[0] = (p1), \
  146127. (cinfo)->err->msg_parm.i[1] = (p2), \
  146128. (cinfo)->err->msg_parm.i[2] = (p3), \
  146129. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  146130. #define ERREXIT4(cinfo,code,p1,p2,p3,p4) \
  146131. ((cinfo)->err->msg_code = (code), \
  146132. (cinfo)->err->msg_parm.i[0] = (p1), \
  146133. (cinfo)->err->msg_parm.i[1] = (p2), \
  146134. (cinfo)->err->msg_parm.i[2] = (p3), \
  146135. (cinfo)->err->msg_parm.i[3] = (p4), \
  146136. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  146137. #define ERREXITS(cinfo,code,str) \
  146138. ((cinfo)->err->msg_code = (code), \
  146139. strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
  146140. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  146141. #define MAKESTMT(stuff) do { stuff } while (0)
  146142. #define WARNMS(cinfo,code) \
  146143. ((cinfo)->err->msg_code = (code), \
  146144. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  146145. #define WARNMS1(cinfo,code,p1) \
  146146. ((cinfo)->err->msg_code = (code), \
  146147. (cinfo)->err->msg_parm.i[0] = (p1), \
  146148. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  146149. #define WARNMS2(cinfo,code,p1,p2) \
  146150. ((cinfo)->err->msg_code = (code), \
  146151. (cinfo)->err->msg_parm.i[0] = (p1), \
  146152. (cinfo)->err->msg_parm.i[1] = (p2), \
  146153. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  146154. #define TRACEMS(cinfo,lvl,code) \
  146155. ((cinfo)->err->msg_code = (code), \
  146156. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  146157. #define TRACEMS1(cinfo,lvl,code,p1) \
  146158. ((cinfo)->err->msg_code = (code), \
  146159. (cinfo)->err->msg_parm.i[0] = (p1), \
  146160. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  146161. #define TRACEMS2(cinfo,lvl,code,p1,p2) \
  146162. ((cinfo)->err->msg_code = (code), \
  146163. (cinfo)->err->msg_parm.i[0] = (p1), \
  146164. (cinfo)->err->msg_parm.i[1] = (p2), \
  146165. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  146166. #define TRACEMS3(cinfo,lvl,code,p1,p2,p3) \
  146167. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  146168. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); \
  146169. (cinfo)->err->msg_code = (code); \
  146170. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  146171. #define TRACEMS4(cinfo,lvl,code,p1,p2,p3,p4) \
  146172. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  146173. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  146174. (cinfo)->err->msg_code = (code); \
  146175. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  146176. #define TRACEMS5(cinfo,lvl,code,p1,p2,p3,p4,p5) \
  146177. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  146178. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  146179. _mp[4] = (p5); \
  146180. (cinfo)->err->msg_code = (code); \
  146181. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  146182. #define TRACEMS8(cinfo,lvl,code,p1,p2,p3,p4,p5,p6,p7,p8) \
  146183. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  146184. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  146185. _mp[4] = (p5); _mp[5] = (p6); _mp[6] = (p7); _mp[7] = (p8); \
  146186. (cinfo)->err->msg_code = (code); \
  146187. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  146188. #define TRACEMSS(cinfo,lvl,code,str) \
  146189. ((cinfo)->err->msg_code = (code), \
  146190. strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
  146191. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  146192. #endif /* JERROR_H */
  146193. /*** End of inlined file: jerror.h ***/
  146194. /* fetch error codes too */
  146195. #endif
  146196. #endif /* JPEGLIB_H */
  146197. /*** End of inlined file: jpeglib.h ***/
  146198. /*** Start of inlined file: jcapimin.c ***/
  146199. #define JPEG_INTERNALS
  146200. /*** Start of inlined file: jinclude.h ***/
  146201. #ifndef __jinclude_h__
  146202. #define __jinclude_h__
  146203. /*** Start of inlined file: jconfig.h ***/
  146204. // disable all the warnings under MSVC
  146205. #ifdef _MSC_VER
  146206. #pragma warning (disable: 4996 4267 4100 4127 4702 4244)
  146207. #endif
  146208. #ifdef __BORLANDC__
  146209. #pragma warn -8057
  146210. #pragma warn -8019
  146211. #pragma warn -8004
  146212. #pragma warn -8008
  146213. #endif
  146214. #define HAVE_PROTOTYPES
  146215. #define HAVE_UNSIGNED_CHAR
  146216. #define HAVE_UNSIGNED_SHORT
  146217. #undef CHAR_IS_UNSIGNED
  146218. #define HAVE_STDDEF_H
  146219. #define HAVE_STDLIB_H
  146220. #undef NEED_BSD_STRINGS
  146221. #undef NEED_SYS_TYPES_H
  146222. #undef NEED_FAR_POINTERS /* we presume a 32-bit flat memory model */
  146223. #undef NEED_SHORT_EXTERNAL_NAMES
  146224. #undef INCOMPLETE_TYPES_BROKEN
  146225. #ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */
  146226. typedef unsigned char boolean;
  146227. #endif
  146228. #define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */
  146229. #ifdef JPEG_INTERNALS
  146230. #undef RIGHT_SHIFT_IS_UNSIGNED
  146231. #endif /* JPEG_INTERNALS */
  146232. #ifdef JPEG_CJPEG_DJPEG
  146233. #define BMP_SUPPORTED /* BMP image file format */
  146234. #define GIF_SUPPORTED /* GIF image file format */
  146235. #define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */
  146236. #undef RLE_SUPPORTED /* Utah RLE image file format */
  146237. #define TARGA_SUPPORTED /* Targa image file format */
  146238. #define TWO_FILE_COMMANDLINE /* optional */
  146239. #define USE_SETMODE /* Microsoft has setmode() */
  146240. #undef NEED_SIGNAL_CATCHER
  146241. #undef DONT_USE_B_MODE
  146242. #undef PROGRESS_REPORT /* optional */
  146243. #endif /* JPEG_CJPEG_DJPEG */
  146244. /*** End of inlined file: jconfig.h ***/
  146245. /* auto configuration options */
  146246. #define JCONFIG_INCLUDED /* so that jpeglib.h doesn't do it again */
  146247. #ifdef HAVE_STDDEF_H
  146248. #include <stddef.h>
  146249. #endif
  146250. #ifdef HAVE_STDLIB_H
  146251. #include <stdlib.h>
  146252. #endif
  146253. #ifdef NEED_SYS_TYPES_H
  146254. #include <sys/types.h>
  146255. #endif
  146256. #include <stdio.h>
  146257. #ifdef NEED_BSD_STRINGS
  146258. #include <strings.h>
  146259. #define MEMZERO(target,size) bzero((void *)(target), (size_t)(size))
  146260. #define MEMCOPY(dest,src,size) bcopy((const void *)(src), (void *)(dest), (size_t)(size))
  146261. #else /* not BSD, assume ANSI/SysV string lib */
  146262. #include <string.h>
  146263. #define MEMZERO(target,size) memset((void *)(target), 0, (size_t)(size))
  146264. #define MEMCOPY(dest,src,size) memcpy((void *)(dest), (const void *)(src), (size_t)(size))
  146265. #endif
  146266. #define SIZEOF(object) ((size_t) sizeof(object))
  146267. #define JFREAD(file,buf,sizeofbuf) \
  146268. ((size_t) fread((void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))
  146269. #define JFWRITE(file,buf,sizeofbuf) \
  146270. ((size_t) fwrite((const void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))
  146271. typedef enum { /* JPEG marker codes */
  146272. M_SOF0 = 0xc0,
  146273. M_SOF1 = 0xc1,
  146274. M_SOF2 = 0xc2,
  146275. M_SOF3 = 0xc3,
  146276. M_SOF5 = 0xc5,
  146277. M_SOF6 = 0xc6,
  146278. M_SOF7 = 0xc7,
  146279. M_JPG = 0xc8,
  146280. M_SOF9 = 0xc9,
  146281. M_SOF10 = 0xca,
  146282. M_SOF11 = 0xcb,
  146283. M_SOF13 = 0xcd,
  146284. M_SOF14 = 0xce,
  146285. M_SOF15 = 0xcf,
  146286. M_DHT = 0xc4,
  146287. M_DAC = 0xcc,
  146288. M_RST0 = 0xd0,
  146289. M_RST1 = 0xd1,
  146290. M_RST2 = 0xd2,
  146291. M_RST3 = 0xd3,
  146292. M_RST4 = 0xd4,
  146293. M_RST5 = 0xd5,
  146294. M_RST6 = 0xd6,
  146295. M_RST7 = 0xd7,
  146296. M_SOI = 0xd8,
  146297. M_EOI = 0xd9,
  146298. M_SOS = 0xda,
  146299. M_DQT = 0xdb,
  146300. M_DNL = 0xdc,
  146301. M_DRI = 0xdd,
  146302. M_DHP = 0xde,
  146303. M_EXP = 0xdf,
  146304. M_APP0 = 0xe0,
  146305. M_APP1 = 0xe1,
  146306. M_APP2 = 0xe2,
  146307. M_APP3 = 0xe3,
  146308. M_APP4 = 0xe4,
  146309. M_APP5 = 0xe5,
  146310. M_APP6 = 0xe6,
  146311. M_APP7 = 0xe7,
  146312. M_APP8 = 0xe8,
  146313. M_APP9 = 0xe9,
  146314. M_APP10 = 0xea,
  146315. M_APP11 = 0xeb,
  146316. M_APP12 = 0xec,
  146317. M_APP13 = 0xed,
  146318. M_APP14 = 0xee,
  146319. M_APP15 = 0xef,
  146320. M_JPG0 = 0xf0,
  146321. M_JPG13 = 0xfd,
  146322. M_COM = 0xfe,
  146323. M_TEM = 0x01,
  146324. M_ERROR = 0x100
  146325. } JPEG_MARKER;
  146326. #ifdef AVOID_TABLES
  146327. #define HUFF_EXTEND(x,s) ((x) < (1<<((s)-1)) ? (x) + (((-1)<<(s)) + 1) : (x))
  146328. #else
  146329. #define HUFF_EXTEND(x,s) ((x) < extend_test[s] ? (x) + extend_offset[s] : (x))
  146330. static const int extend_test[16] = /* entry n is 2**(n-1) */
  146331. { 0, 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
  146332. 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000 };
  146333. static const int extend_offset[16] = /* entry n is (-1 << n) + 1 */
  146334. { 0, ((-1)<<1) + 1, ((-1)<<2) + 1, ((-1)<<3) + 1, ((-1)<<4) + 1,
  146335. ((-1)<<5) + 1, ((-1)<<6) + 1, ((-1)<<7) + 1, ((-1)<<8) + 1,
  146336. ((-1)<<9) + 1, ((-1)<<10) + 1, ((-1)<<11) + 1, ((-1)<<12) + 1,
  146337. ((-1)<<13) + 1, ((-1)<<14) + 1, ((-1)<<15) + 1 };
  146338. #endif /* AVOID_TABLES */
  146339. #endif
  146340. /*** End of inlined file: jinclude.h ***/
  146341. GLOBAL(void)
  146342. jpeg_CreateCompress (j_compress_ptr cinfo, int version, size_t structsize)
  146343. {
  146344. int i;
  146345. cinfo->mem = NULL; /* so jpeg_destroy knows mem mgr not called */
  146346. if (version != JPEG_LIB_VERSION)
  146347. ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version);
  146348. if (structsize != SIZEOF(struct jpeg_compress_struct))
  146349. ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE,
  146350. (int) SIZEOF(struct jpeg_compress_struct), (int) structsize);
  146351. {
  146352. struct jpeg_error_mgr * err = cinfo->err;
  146353. void * client_data = cinfo->client_data; /* ignore Purify complaint here */
  146354. MEMZERO(cinfo, SIZEOF(struct jpeg_compress_struct));
  146355. cinfo->err = err;
  146356. cinfo->client_data = client_data;
  146357. }
  146358. cinfo->is_decompressor = FALSE;
  146359. jinit_memory_mgr((j_common_ptr) cinfo);
  146360. cinfo->progress = NULL;
  146361. cinfo->dest = NULL;
  146362. cinfo->comp_info = NULL;
  146363. for (i = 0; i < NUM_QUANT_TBLS; i++)
  146364. cinfo->quant_tbl_ptrs[i] = NULL;
  146365. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  146366. cinfo->dc_huff_tbl_ptrs[i] = NULL;
  146367. cinfo->ac_huff_tbl_ptrs[i] = NULL;
  146368. }
  146369. cinfo->script_space = NULL;
  146370. cinfo->input_gamma = 1.0; /* in case application forgets */
  146371. cinfo->global_state = CSTATE_START;
  146372. }
  146373. GLOBAL(void)
  146374. jpeg_destroy_compress (j_compress_ptr cinfo)
  146375. {
  146376. jpeg_destroy((j_common_ptr) cinfo); /* use common routine */
  146377. }
  146378. GLOBAL(void)
  146379. jpeg_abort_compress (j_compress_ptr cinfo)
  146380. {
  146381. jpeg_abort((j_common_ptr) cinfo); /* use common routine */
  146382. }
  146383. GLOBAL(void)
  146384. jpeg_suppress_tables (j_compress_ptr cinfo, boolean suppress)
  146385. {
  146386. int i;
  146387. JQUANT_TBL * qtbl;
  146388. JHUFF_TBL * htbl;
  146389. for (i = 0; i < NUM_QUANT_TBLS; i++) {
  146390. if ((qtbl = cinfo->quant_tbl_ptrs[i]) != NULL)
  146391. qtbl->sent_table = suppress;
  146392. }
  146393. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  146394. if ((htbl = cinfo->dc_huff_tbl_ptrs[i]) != NULL)
  146395. htbl->sent_table = suppress;
  146396. if ((htbl = cinfo->ac_huff_tbl_ptrs[i]) != NULL)
  146397. htbl->sent_table = suppress;
  146398. }
  146399. }
  146400. GLOBAL(void)
  146401. jpeg_finish_compress (j_compress_ptr cinfo)
  146402. {
  146403. JDIMENSION iMCU_row;
  146404. if (cinfo->global_state == CSTATE_SCANNING ||
  146405. cinfo->global_state == CSTATE_RAW_OK) {
  146406. if (cinfo->next_scanline < cinfo->image_height)
  146407. ERREXIT(cinfo, JERR_TOO_LITTLE_DATA);
  146408. (*cinfo->master->finish_pass) (cinfo);
  146409. } else if (cinfo->global_state != CSTATE_WRCOEFS)
  146410. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146411. while (! cinfo->master->is_last_pass) {
  146412. (*cinfo->master->prepare_for_pass) (cinfo);
  146413. for (iMCU_row = 0; iMCU_row < cinfo->total_iMCU_rows; iMCU_row++) {
  146414. if (cinfo->progress != NULL) {
  146415. cinfo->progress->pass_counter = (long) iMCU_row;
  146416. cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows;
  146417. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  146418. }
  146419. if (! (*cinfo->coef->compress_data) (cinfo, (JSAMPIMAGE) NULL))
  146420. ERREXIT(cinfo, JERR_CANT_SUSPEND);
  146421. }
  146422. (*cinfo->master->finish_pass) (cinfo);
  146423. }
  146424. (*cinfo->marker->write_file_trailer) (cinfo);
  146425. (*cinfo->dest->term_destination) (cinfo);
  146426. jpeg_abort((j_common_ptr) cinfo);
  146427. }
  146428. GLOBAL(void)
  146429. jpeg_write_marker (j_compress_ptr cinfo, int marker,
  146430. const JOCTET *dataptr, unsigned int datalen)
  146431. {
  146432. JMETHOD(void, write_marker_byte, (j_compress_ptr info, int val));
  146433. if (cinfo->next_scanline != 0 ||
  146434. (cinfo->global_state != CSTATE_SCANNING &&
  146435. cinfo->global_state != CSTATE_RAW_OK &&
  146436. cinfo->global_state != CSTATE_WRCOEFS))
  146437. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146438. (*cinfo->marker->write_marker_header) (cinfo, marker, datalen);
  146439. write_marker_byte = cinfo->marker->write_marker_byte; /* copy for speed */
  146440. while (datalen--) {
  146441. (*write_marker_byte) (cinfo, *dataptr);
  146442. dataptr++;
  146443. }
  146444. }
  146445. GLOBAL(void)
  146446. jpeg_write_m_header (j_compress_ptr cinfo, int marker, unsigned int datalen)
  146447. {
  146448. if (cinfo->next_scanline != 0 ||
  146449. (cinfo->global_state != CSTATE_SCANNING &&
  146450. cinfo->global_state != CSTATE_RAW_OK &&
  146451. cinfo->global_state != CSTATE_WRCOEFS))
  146452. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146453. (*cinfo->marker->write_marker_header) (cinfo, marker, datalen);
  146454. }
  146455. GLOBAL(void)
  146456. jpeg_write_m_byte (j_compress_ptr cinfo, int val)
  146457. {
  146458. (*cinfo->marker->write_marker_byte) (cinfo, val);
  146459. }
  146460. GLOBAL(void)
  146461. jpeg_write_tables (j_compress_ptr cinfo)
  146462. {
  146463. if (cinfo->global_state != CSTATE_START)
  146464. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146465. (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  146466. (*cinfo->dest->init_destination) (cinfo);
  146467. jinit_marker_writer(cinfo);
  146468. (*cinfo->marker->write_tables_only) (cinfo);
  146469. (*cinfo->dest->term_destination) (cinfo);
  146470. }
  146471. /*** End of inlined file: jcapimin.c ***/
  146472. /*** Start of inlined file: jcapistd.c ***/
  146473. #define JPEG_INTERNALS
  146474. GLOBAL(void)
  146475. jpeg_start_compress (j_compress_ptr cinfo, boolean write_all_tables)
  146476. {
  146477. if (cinfo->global_state != CSTATE_START)
  146478. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146479. if (write_all_tables)
  146480. jpeg_suppress_tables(cinfo, FALSE); /* mark all tables to be written */
  146481. (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  146482. (*cinfo->dest->init_destination) (cinfo);
  146483. jinit_compress_master(cinfo);
  146484. (*cinfo->master->prepare_for_pass) (cinfo);
  146485. cinfo->next_scanline = 0;
  146486. cinfo->global_state = (cinfo->raw_data_in ? CSTATE_RAW_OK : CSTATE_SCANNING);
  146487. }
  146488. GLOBAL(JDIMENSION)
  146489. jpeg_write_scanlines (j_compress_ptr cinfo, JSAMPARRAY scanlines,
  146490. JDIMENSION num_lines)
  146491. {
  146492. JDIMENSION row_ctr, rows_left;
  146493. if (cinfo->global_state != CSTATE_SCANNING)
  146494. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146495. if (cinfo->next_scanline >= cinfo->image_height)
  146496. WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
  146497. if (cinfo->progress != NULL) {
  146498. cinfo->progress->pass_counter = (long) cinfo->next_scanline;
  146499. cinfo->progress->pass_limit = (long) cinfo->image_height;
  146500. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  146501. }
  146502. if (cinfo->master->call_pass_startup)
  146503. (*cinfo->master->pass_startup) (cinfo);
  146504. rows_left = cinfo->image_height - cinfo->next_scanline;
  146505. if (num_lines > rows_left)
  146506. num_lines = rows_left;
  146507. row_ctr = 0;
  146508. (*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, num_lines);
  146509. cinfo->next_scanline += row_ctr;
  146510. return row_ctr;
  146511. }
  146512. GLOBAL(JDIMENSION)
  146513. jpeg_write_raw_data (j_compress_ptr cinfo, JSAMPIMAGE data,
  146514. JDIMENSION num_lines)
  146515. {
  146516. JDIMENSION lines_per_iMCU_row;
  146517. if (cinfo->global_state != CSTATE_RAW_OK)
  146518. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146519. if (cinfo->next_scanline >= cinfo->image_height) {
  146520. WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
  146521. return 0;
  146522. }
  146523. if (cinfo->progress != NULL) {
  146524. cinfo->progress->pass_counter = (long) cinfo->next_scanline;
  146525. cinfo->progress->pass_limit = (long) cinfo->image_height;
  146526. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  146527. }
  146528. if (cinfo->master->call_pass_startup)
  146529. (*cinfo->master->pass_startup) (cinfo);
  146530. lines_per_iMCU_row = cinfo->max_v_samp_factor * DCTSIZE;
  146531. if (num_lines < lines_per_iMCU_row)
  146532. ERREXIT(cinfo, JERR_BUFFER_SIZE);
  146533. if (! (*cinfo->coef->compress_data) (cinfo, data)) {
  146534. return 0;
  146535. }
  146536. cinfo->next_scanline += lines_per_iMCU_row;
  146537. return lines_per_iMCU_row;
  146538. }
  146539. /*** End of inlined file: jcapistd.c ***/
  146540. /*** Start of inlined file: jccoefct.c ***/
  146541. #define JPEG_INTERNALS
  146542. #ifdef ENTROPY_OPT_SUPPORTED
  146543. #define FULL_COEF_BUFFER_SUPPORTED
  146544. #else
  146545. #ifdef C_MULTISCAN_FILES_SUPPORTED
  146546. #define FULL_COEF_BUFFER_SUPPORTED
  146547. #endif
  146548. #endif
  146549. typedef struct {
  146550. struct jpeg_c_coef_controller pub; /* public fields */
  146551. JDIMENSION iMCU_row_num; /* iMCU row # within image */
  146552. JDIMENSION mcu_ctr; /* counts MCUs processed in current row */
  146553. int MCU_vert_offset; /* counts MCU rows within iMCU row */
  146554. int MCU_rows_per_iMCU_row; /* number of such rows needed */
  146555. JBLOCKROW MCU_buffer[C_MAX_BLOCKS_IN_MCU];
  146556. jvirt_barray_ptr whole_image[MAX_COMPONENTS];
  146557. } my_coef_controller;
  146558. typedef my_coef_controller * my_coef_ptr;
  146559. METHODDEF(boolean) compress_data
  146560. JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf));
  146561. #ifdef FULL_COEF_BUFFER_SUPPORTED
  146562. METHODDEF(boolean) compress_first_pass
  146563. JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf));
  146564. METHODDEF(boolean) compress_output
  146565. JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf));
  146566. #endif
  146567. LOCAL(void)
  146568. start_iMCU_row (j_compress_ptr cinfo)
  146569. {
  146570. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146571. if (cinfo->comps_in_scan > 1) {
  146572. coef->MCU_rows_per_iMCU_row = 1;
  146573. } else {
  146574. if (coef->iMCU_row_num < (cinfo->total_iMCU_rows-1))
  146575. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
  146576. else
  146577. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
  146578. }
  146579. coef->mcu_ctr = 0;
  146580. coef->MCU_vert_offset = 0;
  146581. }
  146582. METHODDEF(void)
  146583. start_pass_coef (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
  146584. {
  146585. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146586. coef->iMCU_row_num = 0;
  146587. start_iMCU_row(cinfo);
  146588. switch (pass_mode) {
  146589. case JBUF_PASS_THRU:
  146590. if (coef->whole_image[0] != NULL)
  146591. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146592. coef->pub.compress_data = compress_data;
  146593. break;
  146594. #ifdef FULL_COEF_BUFFER_SUPPORTED
  146595. case JBUF_SAVE_AND_PASS:
  146596. if (coef->whole_image[0] == NULL)
  146597. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146598. coef->pub.compress_data = compress_first_pass;
  146599. break;
  146600. case JBUF_CRANK_DEST:
  146601. if (coef->whole_image[0] == NULL)
  146602. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146603. coef->pub.compress_data = compress_output;
  146604. break;
  146605. #endif
  146606. default:
  146607. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146608. break;
  146609. }
  146610. }
  146611. METHODDEF(boolean)
  146612. compress_data (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  146613. {
  146614. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146615. JDIMENSION MCU_col_num; /* index of current MCU within row */
  146616. JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
  146617. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  146618. int blkn, bi, ci, yindex, yoffset, blockcnt;
  146619. JDIMENSION ypos, xpos;
  146620. jpeg_component_info *compptr;
  146621. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  146622. yoffset++) {
  146623. for (MCU_col_num = coef->mcu_ctr; MCU_col_num <= last_MCU_col;
  146624. MCU_col_num++) {
  146625. blkn = 0;
  146626. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  146627. compptr = cinfo->cur_comp_info[ci];
  146628. blockcnt = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
  146629. : compptr->last_col_width;
  146630. xpos = MCU_col_num * compptr->MCU_sample_width;
  146631. ypos = yoffset * DCTSIZE; /* ypos == (yoffset+yindex) * DCTSIZE */
  146632. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  146633. if (coef->iMCU_row_num < last_iMCU_row ||
  146634. yoffset+yindex < compptr->last_row_height) {
  146635. (*cinfo->fdct->forward_DCT) (cinfo, compptr,
  146636. input_buf[compptr->component_index],
  146637. coef->MCU_buffer[blkn],
  146638. ypos, xpos, (JDIMENSION) blockcnt);
  146639. if (blockcnt < compptr->MCU_width) {
  146640. jzero_far((void FAR *) coef->MCU_buffer[blkn + blockcnt],
  146641. (compptr->MCU_width - blockcnt) * SIZEOF(JBLOCK));
  146642. for (bi = blockcnt; bi < compptr->MCU_width; bi++) {
  146643. coef->MCU_buffer[blkn+bi][0][0] = coef->MCU_buffer[blkn+bi-1][0][0];
  146644. }
  146645. }
  146646. } else {
  146647. jzero_far((void FAR *) coef->MCU_buffer[blkn],
  146648. compptr->MCU_width * SIZEOF(JBLOCK));
  146649. for (bi = 0; bi < compptr->MCU_width; bi++) {
  146650. coef->MCU_buffer[blkn+bi][0][0] = coef->MCU_buffer[blkn-1][0][0];
  146651. }
  146652. }
  146653. blkn += compptr->MCU_width;
  146654. ypos += DCTSIZE;
  146655. }
  146656. }
  146657. if (! (*cinfo->entropy->encode_mcu) (cinfo, coef->MCU_buffer)) {
  146658. coef->MCU_vert_offset = yoffset;
  146659. coef->mcu_ctr = MCU_col_num;
  146660. return FALSE;
  146661. }
  146662. }
  146663. coef->mcu_ctr = 0;
  146664. }
  146665. coef->iMCU_row_num++;
  146666. start_iMCU_row(cinfo);
  146667. return TRUE;
  146668. }
  146669. #ifdef FULL_COEF_BUFFER_SUPPORTED
  146670. METHODDEF(boolean)
  146671. compress_first_pass (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  146672. {
  146673. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146674. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  146675. JDIMENSION blocks_across, MCUs_across, MCUindex;
  146676. int bi, ci, h_samp_factor, block_row, block_rows, ndummy;
  146677. JCOEF lastDC;
  146678. jpeg_component_info *compptr;
  146679. JBLOCKARRAY buffer;
  146680. JBLOCKROW thisblockrow, lastblockrow;
  146681. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  146682. ci++, compptr++) {
  146683. buffer = (*cinfo->mem->access_virt_barray)
  146684. ((j_common_ptr) cinfo, coef->whole_image[ci],
  146685. coef->iMCU_row_num * compptr->v_samp_factor,
  146686. (JDIMENSION) compptr->v_samp_factor, TRUE);
  146687. if (coef->iMCU_row_num < last_iMCU_row)
  146688. block_rows = compptr->v_samp_factor;
  146689. else {
  146690. block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  146691. if (block_rows == 0) block_rows = compptr->v_samp_factor;
  146692. }
  146693. blocks_across = compptr->width_in_blocks;
  146694. h_samp_factor = compptr->h_samp_factor;
  146695. ndummy = (int) (blocks_across % h_samp_factor);
  146696. if (ndummy > 0)
  146697. ndummy = h_samp_factor - ndummy;
  146698. for (block_row = 0; block_row < block_rows; block_row++) {
  146699. thisblockrow = buffer[block_row];
  146700. (*cinfo->fdct->forward_DCT) (cinfo, compptr,
  146701. input_buf[ci], thisblockrow,
  146702. (JDIMENSION) (block_row * DCTSIZE),
  146703. (JDIMENSION) 0, blocks_across);
  146704. if (ndummy > 0) {
  146705. thisblockrow += blocks_across; /* => first dummy block */
  146706. jzero_far((void FAR *) thisblockrow, ndummy * SIZEOF(JBLOCK));
  146707. lastDC = thisblockrow[-1][0];
  146708. for (bi = 0; bi < ndummy; bi++) {
  146709. thisblockrow[bi][0] = lastDC;
  146710. }
  146711. }
  146712. }
  146713. if (coef->iMCU_row_num == last_iMCU_row) {
  146714. blocks_across += ndummy; /* include lower right corner */
  146715. MCUs_across = blocks_across / h_samp_factor;
  146716. for (block_row = block_rows; block_row < compptr->v_samp_factor;
  146717. block_row++) {
  146718. thisblockrow = buffer[block_row];
  146719. lastblockrow = buffer[block_row-1];
  146720. jzero_far((void FAR *) thisblockrow,
  146721. (size_t) (blocks_across * SIZEOF(JBLOCK)));
  146722. for (MCUindex = 0; MCUindex < MCUs_across; MCUindex++) {
  146723. lastDC = lastblockrow[h_samp_factor-1][0];
  146724. for (bi = 0; bi < h_samp_factor; bi++) {
  146725. thisblockrow[bi][0] = lastDC;
  146726. }
  146727. thisblockrow += h_samp_factor; /* advance to next MCU in row */
  146728. lastblockrow += h_samp_factor;
  146729. }
  146730. }
  146731. }
  146732. }
  146733. return compress_output(cinfo, input_buf);
  146734. }
  146735. METHODDEF(boolean)
  146736. compress_output (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  146737. {
  146738. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146739. JDIMENSION MCU_col_num; /* index of current MCU within row */
  146740. int blkn, ci, xindex, yindex, yoffset;
  146741. JDIMENSION start_col;
  146742. JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
  146743. JBLOCKROW buffer_ptr;
  146744. jpeg_component_info *compptr;
  146745. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  146746. compptr = cinfo->cur_comp_info[ci];
  146747. buffer[ci] = (*cinfo->mem->access_virt_barray)
  146748. ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index],
  146749. coef->iMCU_row_num * compptr->v_samp_factor,
  146750. (JDIMENSION) compptr->v_samp_factor, FALSE);
  146751. }
  146752. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  146753. yoffset++) {
  146754. for (MCU_col_num = coef->mcu_ctr; MCU_col_num < cinfo->MCUs_per_row;
  146755. MCU_col_num++) {
  146756. blkn = 0; /* index of current DCT block within MCU */
  146757. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  146758. compptr = cinfo->cur_comp_info[ci];
  146759. start_col = MCU_col_num * compptr->MCU_width;
  146760. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  146761. buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
  146762. for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
  146763. coef->MCU_buffer[blkn++] = buffer_ptr++;
  146764. }
  146765. }
  146766. }
  146767. if (! (*cinfo->entropy->encode_mcu) (cinfo, coef->MCU_buffer)) {
  146768. coef->MCU_vert_offset = yoffset;
  146769. coef->mcu_ctr = MCU_col_num;
  146770. return FALSE;
  146771. }
  146772. }
  146773. coef->mcu_ctr = 0;
  146774. }
  146775. coef->iMCU_row_num++;
  146776. start_iMCU_row(cinfo);
  146777. return TRUE;
  146778. }
  146779. #endif /* FULL_COEF_BUFFER_SUPPORTED */
  146780. GLOBAL(void)
  146781. jinit_c_coef_controller (j_compress_ptr cinfo, boolean need_full_buffer)
  146782. {
  146783. my_coef_ptr coef;
  146784. coef = (my_coef_ptr)
  146785. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146786. SIZEOF(my_coef_controller));
  146787. cinfo->coef = (struct jpeg_c_coef_controller *) coef;
  146788. coef->pub.start_pass = start_pass_coef;
  146789. if (need_full_buffer) {
  146790. #ifdef FULL_COEF_BUFFER_SUPPORTED
  146791. int ci;
  146792. jpeg_component_info *compptr;
  146793. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  146794. ci++, compptr++) {
  146795. coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
  146796. ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
  146797. (JDIMENSION) jround_up((long) compptr->width_in_blocks,
  146798. (long) compptr->h_samp_factor),
  146799. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  146800. (long) compptr->v_samp_factor),
  146801. (JDIMENSION) compptr->v_samp_factor);
  146802. }
  146803. #else
  146804. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146805. #endif
  146806. } else {
  146807. JBLOCKROW buffer;
  146808. int i;
  146809. buffer = (JBLOCKROW)
  146810. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146811. C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
  146812. for (i = 0; i < C_MAX_BLOCKS_IN_MCU; i++) {
  146813. coef->MCU_buffer[i] = buffer + i;
  146814. }
  146815. coef->whole_image[0] = NULL; /* flag for no virtual arrays */
  146816. }
  146817. }
  146818. /*** End of inlined file: jccoefct.c ***/
  146819. /*** Start of inlined file: jccolor.c ***/
  146820. #define JPEG_INTERNALS
  146821. typedef struct {
  146822. struct jpeg_color_converter pub; /* public fields */
  146823. INT32 * rgb_ycc_tab; /* => table for RGB to YCbCr conversion */
  146824. } my_color_converter;
  146825. typedef my_color_converter * my_cconvert_ptr;
  146826. #define SCALEBITS 16 /* speediest right-shift on some machines */
  146827. #define CBCR_OFFSET ((INT32) CENTERJSAMPLE << SCALEBITS)
  146828. #define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
  146829. #define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
  146830. #define R_Y_OFF 0 /* offset to R => Y section */
  146831. #define G_Y_OFF (1*(MAXJSAMPLE+1)) /* offset to G => Y section */
  146832. #define B_Y_OFF (2*(MAXJSAMPLE+1)) /* etc. */
  146833. #define R_CB_OFF (3*(MAXJSAMPLE+1))
  146834. #define G_CB_OFF (4*(MAXJSAMPLE+1))
  146835. #define B_CB_OFF (5*(MAXJSAMPLE+1))
  146836. #define R_CR_OFF B_CB_OFF /* B=>Cb, R=>Cr are the same */
  146837. #define G_CR_OFF (6*(MAXJSAMPLE+1))
  146838. #define B_CR_OFF (7*(MAXJSAMPLE+1))
  146839. #define TABLE_SIZE (8*(MAXJSAMPLE+1))
  146840. METHODDEF(void)
  146841. rgb_ycc_start (j_compress_ptr cinfo)
  146842. {
  146843. my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  146844. INT32 * rgb_ycc_tab;
  146845. INT32 i;
  146846. cconvert->rgb_ycc_tab = rgb_ycc_tab = (INT32 *)
  146847. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146848. (TABLE_SIZE * SIZEOF(INT32)));
  146849. for (i = 0; i <= MAXJSAMPLE; i++) {
  146850. rgb_ycc_tab[i+R_Y_OFF] = FIX(0.29900) * i;
  146851. rgb_ycc_tab[i+G_Y_OFF] = FIX(0.58700) * i;
  146852. rgb_ycc_tab[i+B_Y_OFF] = FIX(0.11400) * i + ONE_HALF;
  146853. rgb_ycc_tab[i+R_CB_OFF] = (-FIX(0.16874)) * i;
  146854. rgb_ycc_tab[i+G_CB_OFF] = (-FIX(0.33126)) * i;
  146855. rgb_ycc_tab[i+B_CB_OFF] = FIX(0.50000) * i + CBCR_OFFSET + ONE_HALF-1;
  146856. rgb_ycc_tab[i+G_CR_OFF] = (-FIX(0.41869)) * i;
  146857. rgb_ycc_tab[i+B_CR_OFF] = (-FIX(0.08131)) * i;
  146858. }
  146859. }
  146860. METHODDEF(void)
  146861. rgb_ycc_convert (j_compress_ptr cinfo,
  146862. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146863. JDIMENSION output_row, int num_rows)
  146864. {
  146865. my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  146866. register int r, g, b;
  146867. register INT32 * ctab = cconvert->rgb_ycc_tab;
  146868. register JSAMPROW inptr;
  146869. register JSAMPROW outptr0, outptr1, outptr2;
  146870. register JDIMENSION col;
  146871. JDIMENSION num_cols = cinfo->image_width;
  146872. while (--num_rows >= 0) {
  146873. inptr = *input_buf++;
  146874. outptr0 = output_buf[0][output_row];
  146875. outptr1 = output_buf[1][output_row];
  146876. outptr2 = output_buf[2][output_row];
  146877. output_row++;
  146878. for (col = 0; col < num_cols; col++) {
  146879. r = GETJSAMPLE(inptr[RGB_RED]);
  146880. g = GETJSAMPLE(inptr[RGB_GREEN]);
  146881. b = GETJSAMPLE(inptr[RGB_BLUE]);
  146882. inptr += RGB_PIXELSIZE;
  146883. outptr0[col] = (JSAMPLE)
  146884. ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
  146885. >> SCALEBITS);
  146886. outptr1[col] = (JSAMPLE)
  146887. ((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF])
  146888. >> SCALEBITS);
  146889. outptr2[col] = (JSAMPLE)
  146890. ((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF])
  146891. >> SCALEBITS);
  146892. }
  146893. }
  146894. }
  146895. METHODDEF(void)
  146896. rgb_gray_convert (j_compress_ptr cinfo,
  146897. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146898. JDIMENSION output_row, int num_rows)
  146899. {
  146900. my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  146901. register int r, g, b;
  146902. register INT32 * ctab = cconvert->rgb_ycc_tab;
  146903. register JSAMPROW inptr;
  146904. register JSAMPROW outptr;
  146905. register JDIMENSION col;
  146906. JDIMENSION num_cols = cinfo->image_width;
  146907. while (--num_rows >= 0) {
  146908. inptr = *input_buf++;
  146909. outptr = output_buf[0][output_row];
  146910. output_row++;
  146911. for (col = 0; col < num_cols; col++) {
  146912. r = GETJSAMPLE(inptr[RGB_RED]);
  146913. g = GETJSAMPLE(inptr[RGB_GREEN]);
  146914. b = GETJSAMPLE(inptr[RGB_BLUE]);
  146915. inptr += RGB_PIXELSIZE;
  146916. outptr[col] = (JSAMPLE)
  146917. ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
  146918. >> SCALEBITS);
  146919. }
  146920. }
  146921. }
  146922. METHODDEF(void)
  146923. cmyk_ycck_convert (j_compress_ptr cinfo,
  146924. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146925. JDIMENSION output_row, int num_rows)
  146926. {
  146927. my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  146928. register int r, g, b;
  146929. register INT32 * ctab = cconvert->rgb_ycc_tab;
  146930. register JSAMPROW inptr;
  146931. register JSAMPROW outptr0, outptr1, outptr2, outptr3;
  146932. register JDIMENSION col;
  146933. JDIMENSION num_cols = cinfo->image_width;
  146934. while (--num_rows >= 0) {
  146935. inptr = *input_buf++;
  146936. outptr0 = output_buf[0][output_row];
  146937. outptr1 = output_buf[1][output_row];
  146938. outptr2 = output_buf[2][output_row];
  146939. outptr3 = output_buf[3][output_row];
  146940. output_row++;
  146941. for (col = 0; col < num_cols; col++) {
  146942. r = MAXJSAMPLE - GETJSAMPLE(inptr[0]);
  146943. g = MAXJSAMPLE - GETJSAMPLE(inptr[1]);
  146944. b = MAXJSAMPLE - GETJSAMPLE(inptr[2]);
  146945. outptr3[col] = inptr[3]; /* don't need GETJSAMPLE here */
  146946. inptr += 4;
  146947. outptr0[col] = (JSAMPLE)
  146948. ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
  146949. >> SCALEBITS);
  146950. outptr1[col] = (JSAMPLE)
  146951. ((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF])
  146952. >> SCALEBITS);
  146953. outptr2[col] = (JSAMPLE)
  146954. ((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF])
  146955. >> SCALEBITS);
  146956. }
  146957. }
  146958. }
  146959. METHODDEF(void)
  146960. grayscale_convert (j_compress_ptr cinfo,
  146961. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146962. JDIMENSION output_row, int num_rows)
  146963. {
  146964. register JSAMPROW inptr;
  146965. register JSAMPROW outptr;
  146966. register JDIMENSION col;
  146967. JDIMENSION num_cols = cinfo->image_width;
  146968. int instride = cinfo->input_components;
  146969. while (--num_rows >= 0) {
  146970. inptr = *input_buf++;
  146971. outptr = output_buf[0][output_row];
  146972. output_row++;
  146973. for (col = 0; col < num_cols; col++) {
  146974. outptr[col] = inptr[0]; /* don't need GETJSAMPLE() here */
  146975. inptr += instride;
  146976. }
  146977. }
  146978. }
  146979. METHODDEF(void)
  146980. null_convert (j_compress_ptr cinfo,
  146981. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146982. JDIMENSION output_row, int num_rows)
  146983. {
  146984. register JSAMPROW inptr;
  146985. register JSAMPROW outptr;
  146986. register JDIMENSION col;
  146987. register int ci;
  146988. int nc = cinfo->num_components;
  146989. JDIMENSION num_cols = cinfo->image_width;
  146990. while (--num_rows >= 0) {
  146991. for (ci = 0; ci < nc; ci++) {
  146992. inptr = *input_buf;
  146993. outptr = output_buf[ci][output_row];
  146994. for (col = 0; col < num_cols; col++) {
  146995. outptr[col] = inptr[ci]; /* don't need GETJSAMPLE() here */
  146996. inptr += nc;
  146997. }
  146998. }
  146999. input_buf++;
  147000. output_row++;
  147001. }
  147002. }
  147003. METHODDEF(void)
  147004. null_method (j_compress_ptr cinfo)
  147005. {
  147006. }
  147007. GLOBAL(void)
  147008. jinit_color_converter (j_compress_ptr cinfo)
  147009. {
  147010. my_cconvert_ptr cconvert;
  147011. cconvert = (my_cconvert_ptr)
  147012. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147013. SIZEOF(my_color_converter));
  147014. cinfo->cconvert = (struct jpeg_color_converter *) cconvert;
  147015. cconvert->pub.start_pass = null_method;
  147016. switch (cinfo->in_color_space) {
  147017. case JCS_GRAYSCALE:
  147018. if (cinfo->input_components != 1)
  147019. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  147020. break;
  147021. case JCS_RGB:
  147022. #if RGB_PIXELSIZE != 3
  147023. if (cinfo->input_components != RGB_PIXELSIZE)
  147024. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  147025. break;
  147026. #endif /* else share code with YCbCr */
  147027. case JCS_YCbCr:
  147028. if (cinfo->input_components != 3)
  147029. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  147030. break;
  147031. case JCS_CMYK:
  147032. case JCS_YCCK:
  147033. if (cinfo->input_components != 4)
  147034. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  147035. break;
  147036. default: /* JCS_UNKNOWN can be anything */
  147037. if (cinfo->input_components < 1)
  147038. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  147039. break;
  147040. }
  147041. switch (cinfo->jpeg_color_space) {
  147042. case JCS_GRAYSCALE:
  147043. if (cinfo->num_components != 1)
  147044. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  147045. if (cinfo->in_color_space == JCS_GRAYSCALE)
  147046. cconvert->pub.color_convert = grayscale_convert;
  147047. else if (cinfo->in_color_space == JCS_RGB) {
  147048. cconvert->pub.start_pass = rgb_ycc_start;
  147049. cconvert->pub.color_convert = rgb_gray_convert;
  147050. } else if (cinfo->in_color_space == JCS_YCbCr)
  147051. cconvert->pub.color_convert = grayscale_convert;
  147052. else
  147053. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  147054. break;
  147055. case JCS_RGB:
  147056. if (cinfo->num_components != 3)
  147057. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  147058. if (cinfo->in_color_space == JCS_RGB && RGB_PIXELSIZE == 3)
  147059. cconvert->pub.color_convert = null_convert;
  147060. else
  147061. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  147062. break;
  147063. case JCS_YCbCr:
  147064. if (cinfo->num_components != 3)
  147065. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  147066. if (cinfo->in_color_space == JCS_RGB) {
  147067. cconvert->pub.start_pass = rgb_ycc_start;
  147068. cconvert->pub.color_convert = rgb_ycc_convert;
  147069. } else if (cinfo->in_color_space == JCS_YCbCr)
  147070. cconvert->pub.color_convert = null_convert;
  147071. else
  147072. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  147073. break;
  147074. case JCS_CMYK:
  147075. if (cinfo->num_components != 4)
  147076. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  147077. if (cinfo->in_color_space == JCS_CMYK)
  147078. cconvert->pub.color_convert = null_convert;
  147079. else
  147080. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  147081. break;
  147082. case JCS_YCCK:
  147083. if (cinfo->num_components != 4)
  147084. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  147085. if (cinfo->in_color_space == JCS_CMYK) {
  147086. cconvert->pub.start_pass = rgb_ycc_start;
  147087. cconvert->pub.color_convert = cmyk_ycck_convert;
  147088. } else if (cinfo->in_color_space == JCS_YCCK)
  147089. cconvert->pub.color_convert = null_convert;
  147090. else
  147091. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  147092. break;
  147093. default: /* allow null conversion of JCS_UNKNOWN */
  147094. if (cinfo->jpeg_color_space != cinfo->in_color_space ||
  147095. cinfo->num_components != cinfo->input_components)
  147096. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  147097. cconvert->pub.color_convert = null_convert;
  147098. break;
  147099. }
  147100. }
  147101. /*** End of inlined file: jccolor.c ***/
  147102. #undef FIX
  147103. /*** Start of inlined file: jcdctmgr.c ***/
  147104. #define JPEG_INTERNALS
  147105. /*** Start of inlined file: jdct.h ***/
  147106. #ifndef __jdct_h__
  147107. #define __jdct_h__
  147108. #if BITS_IN_JSAMPLE == 8
  147109. typedef int DCTELEM; /* 16 or 32 bits is fine */
  147110. #else
  147111. typedef INT32 DCTELEM; /* must have 32 bits */
  147112. #endif
  147113. typedef JMETHOD(void, forward_DCT_method_ptr, (DCTELEM * data));
  147114. typedef JMETHOD(void, float_DCT_method_ptr, (FAST_FLOAT * data));
  147115. typedef MULTIPLIER ISLOW_MULT_TYPE; /* short or int, whichever is faster */
  147116. #if BITS_IN_JSAMPLE == 8
  147117. typedef MULTIPLIER IFAST_MULT_TYPE; /* 16 bits is OK, use short if faster */
  147118. #define IFAST_SCALE_BITS 2 /* fractional bits in scale factors */
  147119. #else
  147120. typedef INT32 IFAST_MULT_TYPE; /* need 32 bits for scaled quantizers */
  147121. #define IFAST_SCALE_BITS 13 /* fractional bits in scale factors */
  147122. #endif
  147123. typedef FAST_FLOAT FLOAT_MULT_TYPE; /* preferred floating type */
  147124. #define IDCT_range_limit(cinfo) ((cinfo)->sample_range_limit + CENTERJSAMPLE)
  147125. #define RANGE_MASK (MAXJSAMPLE * 4 + 3) /* 2 bits wider than legal samples */
  147126. #ifdef NEED_SHORT_EXTERNAL_NAMES
  147127. #define jpeg_fdct_islow jFDislow
  147128. #define jpeg_fdct_ifast jFDifast
  147129. #define jpeg_fdct_float jFDfloat
  147130. #define jpeg_idct_islow jRDislow
  147131. #define jpeg_idct_ifast jRDifast
  147132. #define jpeg_idct_float jRDfloat
  147133. #define jpeg_idct_4x4 jRD4x4
  147134. #define jpeg_idct_2x2 jRD2x2
  147135. #define jpeg_idct_1x1 jRD1x1
  147136. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  147137. EXTERN(void) jpeg_fdct_islow JPP((DCTELEM * data));
  147138. EXTERN(void) jpeg_fdct_ifast JPP((DCTELEM * data));
  147139. EXTERN(void) jpeg_fdct_float JPP((FAST_FLOAT * data));
  147140. EXTERN(void) jpeg_idct_islow
  147141. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  147142. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  147143. EXTERN(void) jpeg_idct_ifast
  147144. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  147145. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  147146. EXTERN(void) jpeg_idct_float
  147147. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  147148. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  147149. EXTERN(void) jpeg_idct_4x4
  147150. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  147151. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  147152. EXTERN(void) jpeg_idct_2x2
  147153. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  147154. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  147155. EXTERN(void) jpeg_idct_1x1
  147156. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  147157. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  147158. #define ONE ((INT32) 1)
  147159. #define CONST_SCALE (ONE << CONST_BITS)
  147160. #define FIX(x) ((INT32) ((x) * CONST_SCALE + 0.5))
  147161. #define DESCALE(x,n) RIGHT_SHIFT((x) + (ONE << ((n)-1)), n)
  147162. #ifdef SHORTxSHORT_32 /* may work if 'int' is 32 bits */
  147163. #define MULTIPLY16C16(var,const) (((INT16) (var)) * ((INT16) (const)))
  147164. #endif
  147165. #ifdef SHORTxLCONST_32 /* known to work with Microsoft C 6.0 */
  147166. #define MULTIPLY16C16(var,const) (((INT16) (var)) * ((INT32) (const)))
  147167. #endif
  147168. #ifndef MULTIPLY16C16 /* default definition */
  147169. #define MULTIPLY16C16(var,const) ((var) * (const))
  147170. #endif
  147171. #ifdef SHORTxSHORT_32 /* may work if 'int' is 32 bits */
  147172. #define MULTIPLY16V16(var1,var2) (((INT16) (var1)) * ((INT16) (var2)))
  147173. #endif
  147174. #ifndef MULTIPLY16V16 /* default definition */
  147175. #define MULTIPLY16V16(var1,var2) ((var1) * (var2))
  147176. #endif
  147177. #endif
  147178. /*** End of inlined file: jdct.h ***/
  147179. /* Private declarations for DCT subsystem */
  147180. typedef struct {
  147181. struct jpeg_forward_dct pub; /* public fields */
  147182. forward_DCT_method_ptr do_dct;
  147183. DCTELEM * divisors[NUM_QUANT_TBLS];
  147184. #ifdef DCT_FLOAT_SUPPORTED
  147185. float_DCT_method_ptr do_float_dct;
  147186. FAST_FLOAT * float_divisors[NUM_QUANT_TBLS];
  147187. #endif
  147188. } my_fdct_controller;
  147189. typedef my_fdct_controller * my_fdct_ptr;
  147190. METHODDEF(void)
  147191. start_pass_fdctmgr (j_compress_ptr cinfo)
  147192. {
  147193. my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
  147194. int ci, qtblno, i;
  147195. jpeg_component_info *compptr;
  147196. JQUANT_TBL * qtbl;
  147197. DCTELEM * dtbl;
  147198. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  147199. ci++, compptr++) {
  147200. qtblno = compptr->quant_tbl_no;
  147201. if (qtblno < 0 || qtblno >= NUM_QUANT_TBLS ||
  147202. cinfo->quant_tbl_ptrs[qtblno] == NULL)
  147203. ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno);
  147204. qtbl = cinfo->quant_tbl_ptrs[qtblno];
  147205. switch (cinfo->dct_method) {
  147206. #ifdef DCT_ISLOW_SUPPORTED
  147207. case JDCT_ISLOW:
  147208. if (fdct->divisors[qtblno] == NULL) {
  147209. fdct->divisors[qtblno] = (DCTELEM *)
  147210. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147211. DCTSIZE2 * SIZEOF(DCTELEM));
  147212. }
  147213. dtbl = fdct->divisors[qtblno];
  147214. for (i = 0; i < DCTSIZE2; i++) {
  147215. dtbl[i] = ((DCTELEM) qtbl->quantval[i]) << 3;
  147216. }
  147217. break;
  147218. #endif
  147219. #ifdef DCT_IFAST_SUPPORTED
  147220. case JDCT_IFAST:
  147221. {
  147222. #define CONST_BITS 14
  147223. static const INT16 aanscales[DCTSIZE2] = {
  147224. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  147225. 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270,
  147226. 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906,
  147227. 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315,
  147228. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  147229. 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552,
  147230. 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446,
  147231. 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247
  147232. };
  147233. SHIFT_TEMPS
  147234. if (fdct->divisors[qtblno] == NULL) {
  147235. fdct->divisors[qtblno] = (DCTELEM *)
  147236. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147237. DCTSIZE2 * SIZEOF(DCTELEM));
  147238. }
  147239. dtbl = fdct->divisors[qtblno];
  147240. for (i = 0; i < DCTSIZE2; i++) {
  147241. dtbl[i] = (DCTELEM)
  147242. DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i],
  147243. (INT32) aanscales[i]),
  147244. CONST_BITS-3);
  147245. }
  147246. }
  147247. break;
  147248. #endif
  147249. #ifdef DCT_FLOAT_SUPPORTED
  147250. case JDCT_FLOAT:
  147251. {
  147252. FAST_FLOAT * fdtbl;
  147253. int row, col;
  147254. static const double aanscalefactor[DCTSIZE] = {
  147255. 1.0, 1.387039845, 1.306562965, 1.175875602,
  147256. 1.0, 0.785694958, 0.541196100, 0.275899379
  147257. };
  147258. if (fdct->float_divisors[qtblno] == NULL) {
  147259. fdct->float_divisors[qtblno] = (FAST_FLOAT *)
  147260. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147261. DCTSIZE2 * SIZEOF(FAST_FLOAT));
  147262. }
  147263. fdtbl = fdct->float_divisors[qtblno];
  147264. i = 0;
  147265. for (row = 0; row < DCTSIZE; row++) {
  147266. for (col = 0; col < DCTSIZE; col++) {
  147267. fdtbl[i] = (FAST_FLOAT)
  147268. (1.0 / (((double) qtbl->quantval[i] *
  147269. aanscalefactor[row] * aanscalefactor[col] * 8.0)));
  147270. i++;
  147271. }
  147272. }
  147273. }
  147274. break;
  147275. #endif
  147276. default:
  147277. ERREXIT(cinfo, JERR_NOT_COMPILED);
  147278. break;
  147279. }
  147280. }
  147281. }
  147282. METHODDEF(void)
  147283. forward_DCT (j_compress_ptr cinfo, jpeg_component_info * compptr,
  147284. JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
  147285. JDIMENSION start_row, JDIMENSION start_col,
  147286. JDIMENSION num_blocks)
  147287. {
  147288. my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
  147289. forward_DCT_method_ptr do_dct = fdct->do_dct;
  147290. DCTELEM * divisors = fdct->divisors[compptr->quant_tbl_no];
  147291. DCTELEM workspace[DCTSIZE2]; /* work area for FDCT subroutine */
  147292. JDIMENSION bi;
  147293. sample_data += start_row; /* fold in the vertical offset once */
  147294. for (bi = 0; bi < num_blocks; bi++, start_col += DCTSIZE) {
  147295. { register DCTELEM *workspaceptr;
  147296. register JSAMPROW elemptr;
  147297. register int elemr;
  147298. workspaceptr = workspace;
  147299. for (elemr = 0; elemr < DCTSIZE; elemr++) {
  147300. elemptr = sample_data[elemr] + start_col;
  147301. #if DCTSIZE == 8 /* unroll the inner loop */
  147302. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  147303. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  147304. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  147305. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  147306. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  147307. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  147308. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  147309. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  147310. #else
  147311. { register int elemc;
  147312. for (elemc = DCTSIZE; elemc > 0; elemc--) {
  147313. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  147314. }
  147315. }
  147316. #endif
  147317. }
  147318. }
  147319. (*do_dct) (workspace);
  147320. { register DCTELEM temp, qval;
  147321. register int i;
  147322. register JCOEFPTR output_ptr = coef_blocks[bi];
  147323. for (i = 0; i < DCTSIZE2; i++) {
  147324. qval = divisors[i];
  147325. temp = workspace[i];
  147326. #ifdef FAST_DIVIDE
  147327. #define DIVIDE_BY(a,b) a /= b
  147328. #else
  147329. #define DIVIDE_BY(a,b) if (a >= b) a /= b; else a = 0
  147330. #endif
  147331. if (temp < 0) {
  147332. temp = -temp;
  147333. temp += qval>>1; /* for rounding */
  147334. DIVIDE_BY(temp, qval);
  147335. temp = -temp;
  147336. } else {
  147337. temp += qval>>1; /* for rounding */
  147338. DIVIDE_BY(temp, qval);
  147339. }
  147340. output_ptr[i] = (JCOEF) temp;
  147341. }
  147342. }
  147343. }
  147344. }
  147345. #ifdef DCT_FLOAT_SUPPORTED
  147346. METHODDEF(void)
  147347. forward_DCT_float (j_compress_ptr cinfo, jpeg_component_info * compptr,
  147348. JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
  147349. JDIMENSION start_row, JDIMENSION start_col,
  147350. JDIMENSION num_blocks)
  147351. {
  147352. my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
  147353. float_DCT_method_ptr do_dct = fdct->do_float_dct;
  147354. FAST_FLOAT * divisors = fdct->float_divisors[compptr->quant_tbl_no];
  147355. FAST_FLOAT workspace[DCTSIZE2]; /* work area for FDCT subroutine */
  147356. JDIMENSION bi;
  147357. sample_data += start_row; /* fold in the vertical offset once */
  147358. for (bi = 0; bi < num_blocks; bi++, start_col += DCTSIZE) {
  147359. { register FAST_FLOAT *workspaceptr;
  147360. register JSAMPROW elemptr;
  147361. register int elemr;
  147362. workspaceptr = workspace;
  147363. for (elemr = 0; elemr < DCTSIZE; elemr++) {
  147364. elemptr = sample_data[elemr] + start_col;
  147365. #if DCTSIZE == 8 /* unroll the inner loop */
  147366. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147367. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147368. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147369. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147370. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147371. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147372. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147373. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147374. #else
  147375. { register int elemc;
  147376. for (elemc = DCTSIZE; elemc > 0; elemc--) {
  147377. *workspaceptr++ = (FAST_FLOAT)
  147378. (GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147379. }
  147380. }
  147381. #endif
  147382. }
  147383. }
  147384. (*do_dct) (workspace);
  147385. { register FAST_FLOAT temp;
  147386. register int i;
  147387. register JCOEFPTR output_ptr = coef_blocks[bi];
  147388. for (i = 0; i < DCTSIZE2; i++) {
  147389. temp = workspace[i] * divisors[i];
  147390. output_ptr[i] = (JCOEF) ((int) (temp + (FAST_FLOAT) 16384.5) - 16384);
  147391. }
  147392. }
  147393. }
  147394. }
  147395. #endif /* DCT_FLOAT_SUPPORTED */
  147396. GLOBAL(void)
  147397. jinit_forward_dct (j_compress_ptr cinfo)
  147398. {
  147399. my_fdct_ptr fdct;
  147400. int i;
  147401. fdct = (my_fdct_ptr)
  147402. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147403. SIZEOF(my_fdct_controller));
  147404. cinfo->fdct = (struct jpeg_forward_dct *) fdct;
  147405. fdct->pub.start_pass = start_pass_fdctmgr;
  147406. switch (cinfo->dct_method) {
  147407. #ifdef DCT_ISLOW_SUPPORTED
  147408. case JDCT_ISLOW:
  147409. fdct->pub.forward_DCT = forward_DCT;
  147410. fdct->do_dct = jpeg_fdct_islow;
  147411. break;
  147412. #endif
  147413. #ifdef DCT_IFAST_SUPPORTED
  147414. case JDCT_IFAST:
  147415. fdct->pub.forward_DCT = forward_DCT;
  147416. fdct->do_dct = jpeg_fdct_ifast;
  147417. break;
  147418. #endif
  147419. #ifdef DCT_FLOAT_SUPPORTED
  147420. case JDCT_FLOAT:
  147421. fdct->pub.forward_DCT = forward_DCT_float;
  147422. fdct->do_float_dct = jpeg_fdct_float;
  147423. break;
  147424. #endif
  147425. default:
  147426. ERREXIT(cinfo, JERR_NOT_COMPILED);
  147427. break;
  147428. }
  147429. for (i = 0; i < NUM_QUANT_TBLS; i++) {
  147430. fdct->divisors[i] = NULL;
  147431. #ifdef DCT_FLOAT_SUPPORTED
  147432. fdct->float_divisors[i] = NULL;
  147433. #endif
  147434. }
  147435. }
  147436. /*** End of inlined file: jcdctmgr.c ***/
  147437. #undef CONST_BITS
  147438. /*** Start of inlined file: jchuff.c ***/
  147439. #define JPEG_INTERNALS
  147440. /*** Start of inlined file: jchuff.h ***/
  147441. #ifndef _jchuff_h_
  147442. #define _jchuff_h_
  147443. #if BITS_IN_JSAMPLE == 8
  147444. #define MAX_COEF_BITS 10
  147445. #else
  147446. #define MAX_COEF_BITS 14
  147447. #endif
  147448. typedef struct {
  147449. unsigned int ehufco[256]; /* code for each symbol */
  147450. char ehufsi[256]; /* length of code for each symbol */
  147451. } c_derived_tbl;
  147452. #ifdef NEED_SHORT_EXTERNAL_NAMES
  147453. #define jpeg_make_c_derived_tbl jMkCDerived
  147454. #define jpeg_gen_optimal_table jGenOptTbl
  147455. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  147456. EXTERN(void) jpeg_make_c_derived_tbl
  147457. JPP((j_compress_ptr cinfo, boolean isDC, int tblno,
  147458. c_derived_tbl ** pdtbl));
  147459. EXTERN(void) jpeg_gen_optimal_table
  147460. JPP((j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[]));
  147461. #endif
  147462. /*** End of inlined file: jchuff.h ***/
  147463. /* Declarations shared with jcphuff.c */
  147464. typedef struct {
  147465. INT32 put_buffer; /* current bit-accumulation buffer */
  147466. int put_bits; /* # of bits now in it */
  147467. int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
  147468. } savable_state;
  147469. #ifndef NO_STRUCT_ASSIGN
  147470. #define ASSIGN_STATE(dest,src) ((dest) = (src))
  147471. #else
  147472. #if MAX_COMPS_IN_SCAN == 4
  147473. #define ASSIGN_STATE(dest,src) \
  147474. ((dest).put_buffer = (src).put_buffer, \
  147475. (dest).put_bits = (src).put_bits, \
  147476. (dest).last_dc_val[0] = (src).last_dc_val[0], \
  147477. (dest).last_dc_val[1] = (src).last_dc_val[1], \
  147478. (dest).last_dc_val[2] = (src).last_dc_val[2], \
  147479. (dest).last_dc_val[3] = (src).last_dc_val[3])
  147480. #endif
  147481. #endif
  147482. typedef struct {
  147483. struct jpeg_entropy_encoder pub; /* public fields */
  147484. savable_state saved; /* Bit buffer & DC state at start of MCU */
  147485. unsigned int restarts_to_go; /* MCUs left in this restart interval */
  147486. int next_restart_num; /* next restart number to write (0-7) */
  147487. c_derived_tbl * dc_derived_tbls[NUM_HUFF_TBLS];
  147488. c_derived_tbl * ac_derived_tbls[NUM_HUFF_TBLS];
  147489. #ifdef ENTROPY_OPT_SUPPORTED /* Statistics tables for optimization */
  147490. long * dc_count_ptrs[NUM_HUFF_TBLS];
  147491. long * ac_count_ptrs[NUM_HUFF_TBLS];
  147492. #endif
  147493. } huff_entropy_encoder;
  147494. typedef huff_entropy_encoder * huff_entropy_ptr;
  147495. typedef struct {
  147496. JOCTET * next_output_byte; /* => next byte to write in buffer */
  147497. size_t free_in_buffer; /* # of byte spaces remaining in buffer */
  147498. savable_state cur; /* Current bit buffer & DC state */
  147499. j_compress_ptr cinfo; /* dump_buffer needs access to this */
  147500. } working_state;
  147501. METHODDEF(boolean) encode_mcu_huff JPP((j_compress_ptr cinfo,
  147502. JBLOCKROW *MCU_data));
  147503. METHODDEF(void) finish_pass_huff JPP((j_compress_ptr cinfo));
  147504. #ifdef ENTROPY_OPT_SUPPORTED
  147505. METHODDEF(boolean) encode_mcu_gather JPP((j_compress_ptr cinfo,
  147506. JBLOCKROW *MCU_data));
  147507. METHODDEF(void) finish_pass_gather JPP((j_compress_ptr cinfo));
  147508. #endif
  147509. METHODDEF(void)
  147510. start_pass_huff (j_compress_ptr cinfo, boolean gather_statistics)
  147511. {
  147512. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147513. int ci, dctbl, actbl;
  147514. jpeg_component_info * compptr;
  147515. if (gather_statistics) {
  147516. #ifdef ENTROPY_OPT_SUPPORTED
  147517. entropy->pub.encode_mcu = encode_mcu_gather;
  147518. entropy->pub.finish_pass = finish_pass_gather;
  147519. #else
  147520. ERREXIT(cinfo, JERR_NOT_COMPILED);
  147521. #endif
  147522. } else {
  147523. entropy->pub.encode_mcu = encode_mcu_huff;
  147524. entropy->pub.finish_pass = finish_pass_huff;
  147525. }
  147526. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  147527. compptr = cinfo->cur_comp_info[ci];
  147528. dctbl = compptr->dc_tbl_no;
  147529. actbl = compptr->ac_tbl_no;
  147530. if (gather_statistics) {
  147531. #ifdef ENTROPY_OPT_SUPPORTED
  147532. if (dctbl < 0 || dctbl >= NUM_HUFF_TBLS)
  147533. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, dctbl);
  147534. if (actbl < 0 || actbl >= NUM_HUFF_TBLS)
  147535. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, actbl);
  147536. if (entropy->dc_count_ptrs[dctbl] == NULL)
  147537. entropy->dc_count_ptrs[dctbl] = (long *)
  147538. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147539. 257 * SIZEOF(long));
  147540. MEMZERO(entropy->dc_count_ptrs[dctbl], 257 * SIZEOF(long));
  147541. if (entropy->ac_count_ptrs[actbl] == NULL)
  147542. entropy->ac_count_ptrs[actbl] = (long *)
  147543. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147544. 257 * SIZEOF(long));
  147545. MEMZERO(entropy->ac_count_ptrs[actbl], 257 * SIZEOF(long));
  147546. #endif
  147547. } else {
  147548. jpeg_make_c_derived_tbl(cinfo, TRUE, dctbl,
  147549. & entropy->dc_derived_tbls[dctbl]);
  147550. jpeg_make_c_derived_tbl(cinfo, FALSE, actbl,
  147551. & entropy->ac_derived_tbls[actbl]);
  147552. }
  147553. entropy->saved.last_dc_val[ci] = 0;
  147554. }
  147555. entropy->saved.put_buffer = 0;
  147556. entropy->saved.put_bits = 0;
  147557. entropy->restarts_to_go = cinfo->restart_interval;
  147558. entropy->next_restart_num = 0;
  147559. }
  147560. GLOBAL(void)
  147561. jpeg_make_c_derived_tbl (j_compress_ptr cinfo, boolean isDC, int tblno,
  147562. c_derived_tbl ** pdtbl)
  147563. {
  147564. JHUFF_TBL *htbl;
  147565. c_derived_tbl *dtbl;
  147566. int p, i, l, lastp, si, maxsymbol;
  147567. char huffsize[257];
  147568. unsigned int huffcode[257];
  147569. unsigned int code;
  147570. if (tblno < 0 || tblno >= NUM_HUFF_TBLS)
  147571. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  147572. htbl =
  147573. isDC ? cinfo->dc_huff_tbl_ptrs[tblno] : cinfo->ac_huff_tbl_ptrs[tblno];
  147574. if (htbl == NULL)
  147575. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  147576. if (*pdtbl == NULL)
  147577. *pdtbl = (c_derived_tbl *)
  147578. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147579. SIZEOF(c_derived_tbl));
  147580. dtbl = *pdtbl;
  147581. p = 0;
  147582. for (l = 1; l <= 16; l++) {
  147583. i = (int) htbl->bits[l];
  147584. if (i < 0 || p + i > 256) /* protect against table overrun */
  147585. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  147586. while (i--)
  147587. huffsize[p++] = (char) l;
  147588. }
  147589. huffsize[p] = 0;
  147590. lastp = p;
  147591. code = 0;
  147592. si = huffsize[0];
  147593. p = 0;
  147594. while (huffsize[p]) {
  147595. while (((int) huffsize[p]) == si) {
  147596. huffcode[p++] = code;
  147597. code++;
  147598. }
  147599. if (((INT32) code) >= (((INT32) 1) << si))
  147600. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  147601. code <<= 1;
  147602. si++;
  147603. }
  147604. MEMZERO(dtbl->ehufsi, SIZEOF(dtbl->ehufsi));
  147605. maxsymbol = isDC ? 15 : 255;
  147606. for (p = 0; p < lastp; p++) {
  147607. i = htbl->huffval[p];
  147608. if (i < 0 || i > maxsymbol || dtbl->ehufsi[i])
  147609. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  147610. dtbl->ehufco[i] = huffcode[p];
  147611. dtbl->ehufsi[i] = huffsize[p];
  147612. }
  147613. }
  147614. #define emit_byte(state,val,action) \
  147615. { *(state)->next_output_byte++ = (JOCTET) (val); \
  147616. if (--(state)->free_in_buffer == 0) \
  147617. if (! dump_buffer(state)) \
  147618. { action; } }
  147619. LOCAL(boolean)
  147620. dump_buffer (working_state * state)
  147621. {
  147622. struct jpeg_destination_mgr * dest = state->cinfo->dest;
  147623. if (! (*dest->empty_output_buffer) (state->cinfo))
  147624. return FALSE;
  147625. state->next_output_byte = dest->next_output_byte;
  147626. state->free_in_buffer = dest->free_in_buffer;
  147627. return TRUE;
  147628. }
  147629. INLINE
  147630. LOCAL(boolean)
  147631. emit_bits (working_state * state, unsigned int code, int size)
  147632. {
  147633. register INT32 put_buffer = (INT32) code;
  147634. register int put_bits = state->cur.put_bits;
  147635. if (size == 0)
  147636. ERREXIT(state->cinfo, JERR_HUFF_MISSING_CODE);
  147637. put_buffer &= (((INT32) 1)<<size) - 1; /* mask off any extra bits in code */
  147638. put_bits += size; /* new number of bits in buffer */
  147639. put_buffer <<= 24 - put_bits; /* align incoming bits */
  147640. put_buffer |= state->cur.put_buffer; /* and merge with old buffer contents */
  147641. while (put_bits >= 8) {
  147642. int c = (int) ((put_buffer >> 16) & 0xFF);
  147643. emit_byte(state, c, return FALSE);
  147644. if (c == 0xFF) { /* need to stuff a zero byte? */
  147645. emit_byte(state, 0, return FALSE);
  147646. }
  147647. put_buffer <<= 8;
  147648. put_bits -= 8;
  147649. }
  147650. state->cur.put_buffer = put_buffer; /* update state variables */
  147651. state->cur.put_bits = put_bits;
  147652. return TRUE;
  147653. }
  147654. LOCAL(boolean)
  147655. flush_bits (working_state * state)
  147656. {
  147657. if (! emit_bits(state, 0x7F, 7)) /* fill any partial byte with ones */
  147658. return FALSE;
  147659. state->cur.put_buffer = 0; /* and reset bit-buffer to empty */
  147660. state->cur.put_bits = 0;
  147661. return TRUE;
  147662. }
  147663. LOCAL(boolean)
  147664. encode_one_block (working_state * state, JCOEFPTR block, int last_dc_val,
  147665. c_derived_tbl *dctbl, c_derived_tbl *actbl)
  147666. {
  147667. register int temp, temp2;
  147668. register int nbits;
  147669. register int k, r, i;
  147670. temp = temp2 = block[0] - last_dc_val;
  147671. if (temp < 0) {
  147672. temp = -temp; /* temp is abs value of input */
  147673. temp2--;
  147674. }
  147675. nbits = 0;
  147676. while (temp) {
  147677. nbits++;
  147678. temp >>= 1;
  147679. }
  147680. if (nbits > MAX_COEF_BITS+1)
  147681. ERREXIT(state->cinfo, JERR_BAD_DCT_COEF);
  147682. if (! emit_bits(state, dctbl->ehufco[nbits], dctbl->ehufsi[nbits]))
  147683. return FALSE;
  147684. if (nbits) /* emit_bits rejects calls with size 0 */
  147685. if (! emit_bits(state, (unsigned int) temp2, nbits))
  147686. return FALSE;
  147687. r = 0; /* r = run length of zeros */
  147688. for (k = 1; k < DCTSIZE2; k++) {
  147689. if ((temp = block[jpeg_natural_order[k]]) == 0) {
  147690. r++;
  147691. } else {
  147692. while (r > 15) {
  147693. if (! emit_bits(state, actbl->ehufco[0xF0], actbl->ehufsi[0xF0]))
  147694. return FALSE;
  147695. r -= 16;
  147696. }
  147697. temp2 = temp;
  147698. if (temp < 0) {
  147699. temp = -temp; /* temp is abs value of input */
  147700. temp2--;
  147701. }
  147702. nbits = 1; /* there must be at least one 1 bit */
  147703. while ((temp >>= 1))
  147704. nbits++;
  147705. if (nbits > MAX_COEF_BITS)
  147706. ERREXIT(state->cinfo, JERR_BAD_DCT_COEF);
  147707. i = (r << 4) + nbits;
  147708. if (! emit_bits(state, actbl->ehufco[i], actbl->ehufsi[i]))
  147709. return FALSE;
  147710. if (! emit_bits(state, (unsigned int) temp2, nbits))
  147711. return FALSE;
  147712. r = 0;
  147713. }
  147714. }
  147715. if (r > 0)
  147716. if (! emit_bits(state, actbl->ehufco[0], actbl->ehufsi[0]))
  147717. return FALSE;
  147718. return TRUE;
  147719. }
  147720. LOCAL(boolean)
  147721. emit_restart (working_state * state, int restart_num)
  147722. {
  147723. int ci;
  147724. if (! flush_bits(state))
  147725. return FALSE;
  147726. emit_byte(state, 0xFF, return FALSE);
  147727. emit_byte(state, JPEG_RST0 + restart_num, return FALSE);
  147728. for (ci = 0; ci < state->cinfo->comps_in_scan; ci++)
  147729. state->cur.last_dc_val[ci] = 0;
  147730. return TRUE;
  147731. }
  147732. METHODDEF(boolean)
  147733. encode_mcu_huff (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  147734. {
  147735. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147736. working_state state;
  147737. int blkn, ci;
  147738. jpeg_component_info * compptr;
  147739. state.next_output_byte = cinfo->dest->next_output_byte;
  147740. state.free_in_buffer = cinfo->dest->free_in_buffer;
  147741. ASSIGN_STATE(state.cur, entropy->saved);
  147742. state.cinfo = cinfo;
  147743. if (cinfo->restart_interval) {
  147744. if (entropy->restarts_to_go == 0)
  147745. if (! emit_restart(&state, entropy->next_restart_num))
  147746. return FALSE;
  147747. }
  147748. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  147749. ci = cinfo->MCU_membership[blkn];
  147750. compptr = cinfo->cur_comp_info[ci];
  147751. if (! encode_one_block(&state,
  147752. MCU_data[blkn][0], state.cur.last_dc_val[ci],
  147753. entropy->dc_derived_tbls[compptr->dc_tbl_no],
  147754. entropy->ac_derived_tbls[compptr->ac_tbl_no]))
  147755. return FALSE;
  147756. state.cur.last_dc_val[ci] = MCU_data[blkn][0][0];
  147757. }
  147758. cinfo->dest->next_output_byte = state.next_output_byte;
  147759. cinfo->dest->free_in_buffer = state.free_in_buffer;
  147760. ASSIGN_STATE(entropy->saved, state.cur);
  147761. if (cinfo->restart_interval) {
  147762. if (entropy->restarts_to_go == 0) {
  147763. entropy->restarts_to_go = cinfo->restart_interval;
  147764. entropy->next_restart_num++;
  147765. entropy->next_restart_num &= 7;
  147766. }
  147767. entropy->restarts_to_go--;
  147768. }
  147769. return TRUE;
  147770. }
  147771. METHODDEF(void)
  147772. finish_pass_huff (j_compress_ptr cinfo)
  147773. {
  147774. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147775. working_state state;
  147776. state.next_output_byte = cinfo->dest->next_output_byte;
  147777. state.free_in_buffer = cinfo->dest->free_in_buffer;
  147778. ASSIGN_STATE(state.cur, entropy->saved);
  147779. state.cinfo = cinfo;
  147780. if (! flush_bits(&state))
  147781. ERREXIT(cinfo, JERR_CANT_SUSPEND);
  147782. cinfo->dest->next_output_byte = state.next_output_byte;
  147783. cinfo->dest->free_in_buffer = state.free_in_buffer;
  147784. ASSIGN_STATE(entropy->saved, state.cur);
  147785. }
  147786. #ifdef ENTROPY_OPT_SUPPORTED
  147787. LOCAL(void)
  147788. htest_one_block (j_compress_ptr cinfo, JCOEFPTR block, int last_dc_val,
  147789. long dc_counts[], long ac_counts[])
  147790. {
  147791. register int temp;
  147792. register int nbits;
  147793. register int k, r;
  147794. temp = block[0] - last_dc_val;
  147795. if (temp < 0)
  147796. temp = -temp;
  147797. nbits = 0;
  147798. while (temp) {
  147799. nbits++;
  147800. temp >>= 1;
  147801. }
  147802. if (nbits > MAX_COEF_BITS+1)
  147803. ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  147804. dc_counts[nbits]++;
  147805. r = 0; /* r = run length of zeros */
  147806. for (k = 1; k < DCTSIZE2; k++) {
  147807. if ((temp = block[jpeg_natural_order[k]]) == 0) {
  147808. r++;
  147809. } else {
  147810. while (r > 15) {
  147811. ac_counts[0xF0]++;
  147812. r -= 16;
  147813. }
  147814. if (temp < 0)
  147815. temp = -temp;
  147816. nbits = 1; /* there must be at least one 1 bit */
  147817. while ((temp >>= 1))
  147818. nbits++;
  147819. if (nbits > MAX_COEF_BITS)
  147820. ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  147821. ac_counts[(r << 4) + nbits]++;
  147822. r = 0;
  147823. }
  147824. }
  147825. if (r > 0)
  147826. ac_counts[0]++;
  147827. }
  147828. METHODDEF(boolean)
  147829. encode_mcu_gather (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  147830. {
  147831. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147832. int blkn, ci;
  147833. jpeg_component_info * compptr;
  147834. if (cinfo->restart_interval) {
  147835. if (entropy->restarts_to_go == 0) {
  147836. for (ci = 0; ci < cinfo->comps_in_scan; ci++)
  147837. entropy->saved.last_dc_val[ci] = 0;
  147838. entropy->restarts_to_go = cinfo->restart_interval;
  147839. }
  147840. entropy->restarts_to_go--;
  147841. }
  147842. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  147843. ci = cinfo->MCU_membership[blkn];
  147844. compptr = cinfo->cur_comp_info[ci];
  147845. htest_one_block(cinfo, MCU_data[blkn][0], entropy->saved.last_dc_val[ci],
  147846. entropy->dc_count_ptrs[compptr->dc_tbl_no],
  147847. entropy->ac_count_ptrs[compptr->ac_tbl_no]);
  147848. entropy->saved.last_dc_val[ci] = MCU_data[blkn][0][0];
  147849. }
  147850. return TRUE;
  147851. }
  147852. GLOBAL(void)
  147853. jpeg_gen_optimal_table (j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[])
  147854. {
  147855. #define MAX_CLEN 32 /* assumed maximum initial code length */
  147856. UINT8 bits[MAX_CLEN+1]; /* bits[k] = # of symbols with code length k */
  147857. int codesize[257]; /* codesize[k] = code length of symbol k */
  147858. int others[257]; /* next symbol in current branch of tree */
  147859. int c1, c2;
  147860. int p, i, j;
  147861. long v;
  147862. MEMZERO(bits, SIZEOF(bits));
  147863. MEMZERO(codesize, SIZEOF(codesize));
  147864. for (i = 0; i < 257; i++)
  147865. others[i] = -1; /* init links to empty */
  147866. freq[256] = 1; /* make sure 256 has a nonzero count */
  147867. for (;;) {
  147868. c1 = -1;
  147869. v = 1000000000L;
  147870. for (i = 0; i <= 256; i++) {
  147871. if (freq[i] && freq[i] <= v) {
  147872. v = freq[i];
  147873. c1 = i;
  147874. }
  147875. }
  147876. c2 = -1;
  147877. v = 1000000000L;
  147878. for (i = 0; i <= 256; i++) {
  147879. if (freq[i] && freq[i] <= v && i != c1) {
  147880. v = freq[i];
  147881. c2 = i;
  147882. }
  147883. }
  147884. if (c2 < 0)
  147885. break;
  147886. freq[c1] += freq[c2];
  147887. freq[c2] = 0;
  147888. codesize[c1]++;
  147889. while (others[c1] >= 0) {
  147890. c1 = others[c1];
  147891. codesize[c1]++;
  147892. }
  147893. others[c1] = c2; /* chain c2 onto c1's tree branch */
  147894. codesize[c2]++;
  147895. while (others[c2] >= 0) {
  147896. c2 = others[c2];
  147897. codesize[c2]++;
  147898. }
  147899. }
  147900. for (i = 0; i <= 256; i++) {
  147901. if (codesize[i]) {
  147902. if (codesize[i] > MAX_CLEN)
  147903. ERREXIT(cinfo, JERR_HUFF_CLEN_OVERFLOW);
  147904. bits[codesize[i]]++;
  147905. }
  147906. }
  147907. for (i = MAX_CLEN; i > 16; i--) {
  147908. while (bits[i] > 0) {
  147909. j = i - 2; /* find length of new prefix to be used */
  147910. while (bits[j] == 0)
  147911. j--;
  147912. bits[i] -= 2; /* remove two symbols */
  147913. bits[i-1]++; /* one goes in this length */
  147914. bits[j+1] += 2; /* two new symbols in this length */
  147915. bits[j]--; /* symbol of this length is now a prefix */
  147916. }
  147917. }
  147918. while (bits[i] == 0) /* find largest codelength still in use */
  147919. i--;
  147920. bits[i]--;
  147921. MEMCOPY(htbl->bits, bits, SIZEOF(htbl->bits));
  147922. p = 0;
  147923. for (i = 1; i <= MAX_CLEN; i++) {
  147924. for (j = 0; j <= 255; j++) {
  147925. if (codesize[j] == i) {
  147926. htbl->huffval[p] = (UINT8) j;
  147927. p++;
  147928. }
  147929. }
  147930. }
  147931. htbl->sent_table = FALSE;
  147932. }
  147933. METHODDEF(void)
  147934. finish_pass_gather (j_compress_ptr cinfo)
  147935. {
  147936. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147937. int ci, dctbl, actbl;
  147938. jpeg_component_info * compptr;
  147939. JHUFF_TBL **htblptr;
  147940. boolean did_dc[NUM_HUFF_TBLS];
  147941. boolean did_ac[NUM_HUFF_TBLS];
  147942. MEMZERO(did_dc, SIZEOF(did_dc));
  147943. MEMZERO(did_ac, SIZEOF(did_ac));
  147944. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  147945. compptr = cinfo->cur_comp_info[ci];
  147946. dctbl = compptr->dc_tbl_no;
  147947. actbl = compptr->ac_tbl_no;
  147948. if (! did_dc[dctbl]) {
  147949. htblptr = & cinfo->dc_huff_tbl_ptrs[dctbl];
  147950. if (*htblptr == NULL)
  147951. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  147952. jpeg_gen_optimal_table(cinfo, *htblptr, entropy->dc_count_ptrs[dctbl]);
  147953. did_dc[dctbl] = TRUE;
  147954. }
  147955. if (! did_ac[actbl]) {
  147956. htblptr = & cinfo->ac_huff_tbl_ptrs[actbl];
  147957. if (*htblptr == NULL)
  147958. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  147959. jpeg_gen_optimal_table(cinfo, *htblptr, entropy->ac_count_ptrs[actbl]);
  147960. did_ac[actbl] = TRUE;
  147961. }
  147962. }
  147963. }
  147964. #endif /* ENTROPY_OPT_SUPPORTED */
  147965. GLOBAL(void)
  147966. jinit_huff_encoder (j_compress_ptr cinfo)
  147967. {
  147968. huff_entropy_ptr entropy;
  147969. int i;
  147970. entropy = (huff_entropy_ptr)
  147971. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147972. SIZEOF(huff_entropy_encoder));
  147973. cinfo->entropy = (struct jpeg_entropy_encoder *) entropy;
  147974. entropy->pub.start_pass = start_pass_huff;
  147975. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  147976. entropy->dc_derived_tbls[i] = entropy->ac_derived_tbls[i] = NULL;
  147977. #ifdef ENTROPY_OPT_SUPPORTED
  147978. entropy->dc_count_ptrs[i] = entropy->ac_count_ptrs[i] = NULL;
  147979. #endif
  147980. }
  147981. }
  147982. /*** End of inlined file: jchuff.c ***/
  147983. #undef emit_byte
  147984. /*** Start of inlined file: jcinit.c ***/
  147985. #define JPEG_INTERNALS
  147986. GLOBAL(void)
  147987. jinit_compress_master (j_compress_ptr cinfo)
  147988. {
  147989. jinit_c_master_control(cinfo, FALSE /* full compression */);
  147990. if (! cinfo->raw_data_in) {
  147991. jinit_color_converter(cinfo);
  147992. jinit_downsampler(cinfo);
  147993. jinit_c_prep_controller(cinfo, FALSE /* never need full buffer here */);
  147994. }
  147995. jinit_forward_dct(cinfo);
  147996. if (cinfo->arith_code) {
  147997. ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
  147998. } else {
  147999. if (cinfo->progressive_mode) {
  148000. #ifdef C_PROGRESSIVE_SUPPORTED
  148001. jinit_phuff_encoder(cinfo);
  148002. #else
  148003. ERREXIT(cinfo, JERR_NOT_COMPILED);
  148004. #endif
  148005. } else
  148006. jinit_huff_encoder(cinfo);
  148007. }
  148008. jinit_c_coef_controller(cinfo,
  148009. (boolean) (cinfo->num_scans > 1 || cinfo->optimize_coding));
  148010. jinit_c_main_controller(cinfo, FALSE /* never need full buffer here */);
  148011. jinit_marker_writer(cinfo);
  148012. (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
  148013. (*cinfo->marker->write_file_header) (cinfo);
  148014. }
  148015. /*** End of inlined file: jcinit.c ***/
  148016. /*** Start of inlined file: jcmainct.c ***/
  148017. #define JPEG_INTERNALS
  148018. #undef FULL_MAIN_BUFFER_SUPPORTED
  148019. typedef struct {
  148020. struct jpeg_c_main_controller pub; /* public fields */
  148021. JDIMENSION cur_iMCU_row; /* number of current iMCU row */
  148022. JDIMENSION rowgroup_ctr; /* counts row groups received in iMCU row */
  148023. boolean suspended; /* remember if we suspended output */
  148024. J_BUF_MODE pass_mode; /* current operating mode */
  148025. JSAMPARRAY buffer[MAX_COMPONENTS];
  148026. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  148027. jvirt_sarray_ptr whole_image[MAX_COMPONENTS];
  148028. #endif
  148029. } my_main_controller;
  148030. typedef my_main_controller * my_main_ptr;
  148031. METHODDEF(void) process_data_simple_main
  148032. JPP((j_compress_ptr cinfo, JSAMPARRAY input_buf,
  148033. JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail));
  148034. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  148035. METHODDEF(void) process_data_buffer_main
  148036. JPP((j_compress_ptr cinfo, JSAMPARRAY input_buf,
  148037. JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail));
  148038. #endif
  148039. METHODDEF(void)
  148040. start_pass_main (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
  148041. {
  148042. my_main_ptr main_ = (my_main_ptr) cinfo->main;
  148043. if (cinfo->raw_data_in)
  148044. return;
  148045. main_->cur_iMCU_row = 0; /* initialize counters */
  148046. main_->rowgroup_ctr = 0;
  148047. main_->suspended = FALSE;
  148048. main_->pass_mode = pass_mode; /* save mode for use by process_data */
  148049. switch (pass_mode) {
  148050. case JBUF_PASS_THRU:
  148051. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  148052. if (main_->whole_image[0] != NULL)
  148053. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  148054. #endif
  148055. main_->pub.process_data = process_data_simple_main;
  148056. break;
  148057. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  148058. case JBUF_SAVE_SOURCE:
  148059. case JBUF_CRANK_DEST:
  148060. case JBUF_SAVE_AND_PASS:
  148061. if (main_->whole_image[0] == NULL)
  148062. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  148063. main_->pub.process_data = process_data_buffer_main;
  148064. break;
  148065. #endif
  148066. default:
  148067. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  148068. break;
  148069. }
  148070. }
  148071. METHODDEF(void)
  148072. process_data_simple_main (j_compress_ptr cinfo,
  148073. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  148074. JDIMENSION in_rows_avail)
  148075. {
  148076. my_main_ptr main_ = (my_main_ptr) cinfo->main;
  148077. while (main_->cur_iMCU_row < cinfo->total_iMCU_rows) {
  148078. if (main_->rowgroup_ctr < DCTSIZE)
  148079. (*cinfo->prep->pre_process_data) (cinfo,
  148080. input_buf, in_row_ctr, in_rows_avail,
  148081. main_->buffer, &main_->rowgroup_ctr,
  148082. (JDIMENSION) DCTSIZE);
  148083. if (main_->rowgroup_ctr != DCTSIZE)
  148084. return;
  148085. if (! (*cinfo->coef->compress_data) (cinfo, main_->buffer)) {
  148086. if (! main_->suspended) {
  148087. (*in_row_ctr)--;
  148088. main_->suspended = TRUE;
  148089. }
  148090. return;
  148091. }
  148092. if (main_->suspended) {
  148093. (*in_row_ctr)++;
  148094. main_->suspended = FALSE;
  148095. }
  148096. main_->rowgroup_ctr = 0;
  148097. main_->cur_iMCU_row++;
  148098. }
  148099. }
  148100. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  148101. METHODDEF(void)
  148102. process_data_buffer_main (j_compress_ptr cinfo,
  148103. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  148104. JDIMENSION in_rows_avail)
  148105. {
  148106. my_main_ptr main = (my_main_ptr) cinfo->main;
  148107. int ci;
  148108. jpeg_component_info *compptr;
  148109. boolean writing = (main->pass_mode != JBUF_CRANK_DEST);
  148110. while (main->cur_iMCU_row < cinfo->total_iMCU_rows) {
  148111. if (main->rowgroup_ctr == 0) {
  148112. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148113. ci++, compptr++) {
  148114. main->buffer[ci] = (*cinfo->mem->access_virt_sarray)
  148115. ((j_common_ptr) cinfo, main->whole_image[ci],
  148116. main->cur_iMCU_row * (compptr->v_samp_factor * DCTSIZE),
  148117. (JDIMENSION) (compptr->v_samp_factor * DCTSIZE), writing);
  148118. }
  148119. if (! writing) {
  148120. *in_row_ctr += cinfo->max_v_samp_factor * DCTSIZE;
  148121. main->rowgroup_ctr = DCTSIZE;
  148122. }
  148123. }
  148124. if (writing) {
  148125. (*cinfo->prep->pre_process_data) (cinfo,
  148126. input_buf, in_row_ctr, in_rows_avail,
  148127. main->buffer, &main->rowgroup_ctr,
  148128. (JDIMENSION) DCTSIZE);
  148129. if (main->rowgroup_ctr < DCTSIZE)
  148130. return;
  148131. }
  148132. if (main->pass_mode != JBUF_SAVE_SOURCE) {
  148133. if (! (*cinfo->coef->compress_data) (cinfo, main->buffer)) {
  148134. if (! main->suspended) {
  148135. (*in_row_ctr)--;
  148136. main->suspended = TRUE;
  148137. }
  148138. return;
  148139. }
  148140. if (main->suspended) {
  148141. (*in_row_ctr)++;
  148142. main->suspended = FALSE;
  148143. }
  148144. }
  148145. main->rowgroup_ctr = 0;
  148146. main->cur_iMCU_row++;
  148147. }
  148148. }
  148149. #endif /* FULL_MAIN_BUFFER_SUPPORTED */
  148150. GLOBAL(void)
  148151. jinit_c_main_controller (j_compress_ptr cinfo, boolean need_full_buffer)
  148152. {
  148153. my_main_ptr main_;
  148154. int ci;
  148155. jpeg_component_info *compptr;
  148156. main_ = (my_main_ptr)
  148157. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  148158. SIZEOF(my_main_controller));
  148159. cinfo->main = (struct jpeg_c_main_controller *) main_;
  148160. main_->pub.start_pass = start_pass_main;
  148161. if (cinfo->raw_data_in)
  148162. return;
  148163. if (need_full_buffer) {
  148164. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  148165. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148166. ci++, compptr++) {
  148167. main->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
  148168. ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
  148169. compptr->width_in_blocks * DCTSIZE,
  148170. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  148171. (long) compptr->v_samp_factor) * DCTSIZE,
  148172. (JDIMENSION) (compptr->v_samp_factor * DCTSIZE));
  148173. }
  148174. #else
  148175. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  148176. #endif
  148177. } else {
  148178. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  148179. main_->whole_image[0] = NULL; /* flag for no virtual arrays */
  148180. #endif
  148181. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148182. ci++, compptr++) {
  148183. main_->buffer[ci] = (*cinfo->mem->alloc_sarray)
  148184. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  148185. compptr->width_in_blocks * DCTSIZE,
  148186. (JDIMENSION) (compptr->v_samp_factor * DCTSIZE));
  148187. }
  148188. }
  148189. }
  148190. /*** End of inlined file: jcmainct.c ***/
  148191. /*** Start of inlined file: jcmarker.c ***/
  148192. #define JPEG_INTERNALS
  148193. typedef struct {
  148194. struct jpeg_marker_writer pub; /* public fields */
  148195. unsigned int last_restart_interval; /* last DRI value emitted; 0 after SOI */
  148196. } my_marker_writer;
  148197. typedef my_marker_writer * my_marker_ptr;
  148198. LOCAL(void)
  148199. emit_byte (j_compress_ptr cinfo, int val)
  148200. {
  148201. struct jpeg_destination_mgr * dest = cinfo->dest;
  148202. *(dest->next_output_byte)++ = (JOCTET) val;
  148203. if (--dest->free_in_buffer == 0) {
  148204. if (! (*dest->empty_output_buffer) (cinfo))
  148205. ERREXIT(cinfo, JERR_CANT_SUSPEND);
  148206. }
  148207. }
  148208. LOCAL(void)
  148209. emit_marker (j_compress_ptr cinfo, JPEG_MARKER mark)
  148210. {
  148211. emit_byte(cinfo, 0xFF);
  148212. emit_byte(cinfo, (int) mark);
  148213. }
  148214. LOCAL(void)
  148215. emit_2bytes (j_compress_ptr cinfo, int value)
  148216. {
  148217. emit_byte(cinfo, (value >> 8) & 0xFF);
  148218. emit_byte(cinfo, value & 0xFF);
  148219. }
  148220. LOCAL(int)
  148221. emit_dqt (j_compress_ptr cinfo, int index)
  148222. {
  148223. JQUANT_TBL * qtbl = cinfo->quant_tbl_ptrs[index];
  148224. int prec;
  148225. int i;
  148226. if (qtbl == NULL)
  148227. ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, index);
  148228. prec = 0;
  148229. for (i = 0; i < DCTSIZE2; i++) {
  148230. if (qtbl->quantval[i] > 255)
  148231. prec = 1;
  148232. }
  148233. if (! qtbl->sent_table) {
  148234. emit_marker(cinfo, M_DQT);
  148235. emit_2bytes(cinfo, prec ? DCTSIZE2*2 + 1 + 2 : DCTSIZE2 + 1 + 2);
  148236. emit_byte(cinfo, index + (prec<<4));
  148237. for (i = 0; i < DCTSIZE2; i++) {
  148238. unsigned int qval = qtbl->quantval[jpeg_natural_order[i]];
  148239. if (prec)
  148240. emit_byte(cinfo, (int) (qval >> 8));
  148241. emit_byte(cinfo, (int) (qval & 0xFF));
  148242. }
  148243. qtbl->sent_table = TRUE;
  148244. }
  148245. return prec;
  148246. }
  148247. LOCAL(void)
  148248. emit_dht (j_compress_ptr cinfo, int index, boolean is_ac)
  148249. {
  148250. JHUFF_TBL * htbl;
  148251. int length, i;
  148252. if (is_ac) {
  148253. htbl = cinfo->ac_huff_tbl_ptrs[index];
  148254. index += 0x10; /* output index has AC bit set */
  148255. } else {
  148256. htbl = cinfo->dc_huff_tbl_ptrs[index];
  148257. }
  148258. if (htbl == NULL)
  148259. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, index);
  148260. if (! htbl->sent_table) {
  148261. emit_marker(cinfo, M_DHT);
  148262. length = 0;
  148263. for (i = 1; i <= 16; i++)
  148264. length += htbl->bits[i];
  148265. emit_2bytes(cinfo, length + 2 + 1 + 16);
  148266. emit_byte(cinfo, index);
  148267. for (i = 1; i <= 16; i++)
  148268. emit_byte(cinfo, htbl->bits[i]);
  148269. for (i = 0; i < length; i++)
  148270. emit_byte(cinfo, htbl->huffval[i]);
  148271. htbl->sent_table = TRUE;
  148272. }
  148273. }
  148274. LOCAL(void)
  148275. emit_dac (j_compress_ptr cinfo)
  148276. {
  148277. #ifdef C_ARITH_CODING_SUPPORTED
  148278. char dc_in_use[NUM_ARITH_TBLS];
  148279. char ac_in_use[NUM_ARITH_TBLS];
  148280. int length, i;
  148281. jpeg_component_info *compptr;
  148282. for (i = 0; i < NUM_ARITH_TBLS; i++)
  148283. dc_in_use[i] = ac_in_use[i] = 0;
  148284. for (i = 0; i < cinfo->comps_in_scan; i++) {
  148285. compptr = cinfo->cur_comp_info[i];
  148286. dc_in_use[compptr->dc_tbl_no] = 1;
  148287. ac_in_use[compptr->ac_tbl_no] = 1;
  148288. }
  148289. length = 0;
  148290. for (i = 0; i < NUM_ARITH_TBLS; i++)
  148291. length += dc_in_use[i] + ac_in_use[i];
  148292. emit_marker(cinfo, M_DAC);
  148293. emit_2bytes(cinfo, length*2 + 2);
  148294. for (i = 0; i < NUM_ARITH_TBLS; i++) {
  148295. if (dc_in_use[i]) {
  148296. emit_byte(cinfo, i);
  148297. emit_byte(cinfo, cinfo->arith_dc_L[i] + (cinfo->arith_dc_U[i]<<4));
  148298. }
  148299. if (ac_in_use[i]) {
  148300. emit_byte(cinfo, i + 0x10);
  148301. emit_byte(cinfo, cinfo->arith_ac_K[i]);
  148302. }
  148303. }
  148304. #endif /* C_ARITH_CODING_SUPPORTED */
  148305. }
  148306. LOCAL(void)
  148307. emit_dri (j_compress_ptr cinfo)
  148308. {
  148309. emit_marker(cinfo, M_DRI);
  148310. emit_2bytes(cinfo, 4); /* fixed length */
  148311. emit_2bytes(cinfo, (int) cinfo->restart_interval);
  148312. }
  148313. LOCAL(void)
  148314. emit_sof (j_compress_ptr cinfo, JPEG_MARKER code)
  148315. {
  148316. int ci;
  148317. jpeg_component_info *compptr;
  148318. emit_marker(cinfo, code);
  148319. emit_2bytes(cinfo, 3 * cinfo->num_components + 2 + 5 + 1); /* length */
  148320. if ((long) cinfo->image_height > 65535L ||
  148321. (long) cinfo->image_width > 65535L)
  148322. ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) 65535);
  148323. emit_byte(cinfo, cinfo->data_precision);
  148324. emit_2bytes(cinfo, (int) cinfo->image_height);
  148325. emit_2bytes(cinfo, (int) cinfo->image_width);
  148326. emit_byte(cinfo, cinfo->num_components);
  148327. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148328. ci++, compptr++) {
  148329. emit_byte(cinfo, compptr->component_id);
  148330. emit_byte(cinfo, (compptr->h_samp_factor << 4) + compptr->v_samp_factor);
  148331. emit_byte(cinfo, compptr->quant_tbl_no);
  148332. }
  148333. }
  148334. LOCAL(void)
  148335. emit_sos (j_compress_ptr cinfo)
  148336. {
  148337. int i, td, ta;
  148338. jpeg_component_info *compptr;
  148339. emit_marker(cinfo, M_SOS);
  148340. emit_2bytes(cinfo, 2 * cinfo->comps_in_scan + 2 + 1 + 3); /* length */
  148341. emit_byte(cinfo, cinfo->comps_in_scan);
  148342. for (i = 0; i < cinfo->comps_in_scan; i++) {
  148343. compptr = cinfo->cur_comp_info[i];
  148344. emit_byte(cinfo, compptr->component_id);
  148345. td = compptr->dc_tbl_no;
  148346. ta = compptr->ac_tbl_no;
  148347. if (cinfo->progressive_mode) {
  148348. if (cinfo->Ss == 0) {
  148349. ta = 0; /* DC scan */
  148350. if (cinfo->Ah != 0 && !cinfo->arith_code)
  148351. td = 0; /* no DC table either */
  148352. } else {
  148353. td = 0; /* AC scan */
  148354. }
  148355. }
  148356. emit_byte(cinfo, (td << 4) + ta);
  148357. }
  148358. emit_byte(cinfo, cinfo->Ss);
  148359. emit_byte(cinfo, cinfo->Se);
  148360. emit_byte(cinfo, (cinfo->Ah << 4) + cinfo->Al);
  148361. }
  148362. LOCAL(void)
  148363. emit_jfif_app0 (j_compress_ptr cinfo)
  148364. {
  148365. emit_marker(cinfo, M_APP0);
  148366. emit_2bytes(cinfo, 2 + 4 + 1 + 2 + 1 + 2 + 2 + 1 + 1); /* length */
  148367. emit_byte(cinfo, 0x4A); /* Identifier: ASCII "JFIF" */
  148368. emit_byte(cinfo, 0x46);
  148369. emit_byte(cinfo, 0x49);
  148370. emit_byte(cinfo, 0x46);
  148371. emit_byte(cinfo, 0);
  148372. emit_byte(cinfo, cinfo->JFIF_major_version); /* Version fields */
  148373. emit_byte(cinfo, cinfo->JFIF_minor_version);
  148374. emit_byte(cinfo, cinfo->density_unit); /* Pixel size information */
  148375. emit_2bytes(cinfo, (int) cinfo->X_density);
  148376. emit_2bytes(cinfo, (int) cinfo->Y_density);
  148377. emit_byte(cinfo, 0); /* No thumbnail image */
  148378. emit_byte(cinfo, 0);
  148379. }
  148380. LOCAL(void)
  148381. emit_adobe_app14 (j_compress_ptr cinfo)
  148382. {
  148383. emit_marker(cinfo, M_APP14);
  148384. emit_2bytes(cinfo, 2 + 5 + 2 + 2 + 2 + 1); /* length */
  148385. emit_byte(cinfo, 0x41); /* Identifier: ASCII "Adobe" */
  148386. emit_byte(cinfo, 0x64);
  148387. emit_byte(cinfo, 0x6F);
  148388. emit_byte(cinfo, 0x62);
  148389. emit_byte(cinfo, 0x65);
  148390. emit_2bytes(cinfo, 100); /* Version */
  148391. emit_2bytes(cinfo, 0); /* Flags0 */
  148392. emit_2bytes(cinfo, 0); /* Flags1 */
  148393. switch (cinfo->jpeg_color_space) {
  148394. case JCS_YCbCr:
  148395. emit_byte(cinfo, 1); /* Color transform = 1 */
  148396. break;
  148397. case JCS_YCCK:
  148398. emit_byte(cinfo, 2); /* Color transform = 2 */
  148399. break;
  148400. default:
  148401. emit_byte(cinfo, 0); /* Color transform = 0 */
  148402. break;
  148403. }
  148404. }
  148405. METHODDEF(void)
  148406. write_marker_header (j_compress_ptr cinfo, int marker, unsigned int datalen)
  148407. {
  148408. if (datalen > (unsigned int) 65533) /* safety check */
  148409. ERREXIT(cinfo, JERR_BAD_LENGTH);
  148410. emit_marker(cinfo, (JPEG_MARKER) marker);
  148411. emit_2bytes(cinfo, (int) (datalen + 2)); /* total length */
  148412. }
  148413. METHODDEF(void)
  148414. write_marker_byte (j_compress_ptr cinfo, int val)
  148415. {
  148416. emit_byte(cinfo, val);
  148417. }
  148418. METHODDEF(void)
  148419. write_file_header (j_compress_ptr cinfo)
  148420. {
  148421. my_marker_ptr marker = (my_marker_ptr) cinfo->marker;
  148422. emit_marker(cinfo, M_SOI); /* first the SOI */
  148423. marker->last_restart_interval = 0;
  148424. if (cinfo->write_JFIF_header) /* next an optional JFIF APP0 */
  148425. emit_jfif_app0(cinfo);
  148426. if (cinfo->write_Adobe_marker) /* next an optional Adobe APP14 */
  148427. emit_adobe_app14(cinfo);
  148428. }
  148429. METHODDEF(void)
  148430. write_frame_header (j_compress_ptr cinfo)
  148431. {
  148432. int ci, prec;
  148433. boolean is_baseline;
  148434. jpeg_component_info *compptr;
  148435. prec = 0;
  148436. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148437. ci++, compptr++) {
  148438. prec += emit_dqt(cinfo, compptr->quant_tbl_no);
  148439. }
  148440. if (cinfo->arith_code || cinfo->progressive_mode ||
  148441. cinfo->data_precision != 8) {
  148442. is_baseline = FALSE;
  148443. } else {
  148444. is_baseline = TRUE;
  148445. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148446. ci++, compptr++) {
  148447. if (compptr->dc_tbl_no > 1 || compptr->ac_tbl_no > 1)
  148448. is_baseline = FALSE;
  148449. }
  148450. if (prec && is_baseline) {
  148451. is_baseline = FALSE;
  148452. TRACEMS(cinfo, 0, JTRC_16BIT_TABLES);
  148453. }
  148454. }
  148455. if (cinfo->arith_code) {
  148456. emit_sof(cinfo, M_SOF9); /* SOF code for arithmetic coding */
  148457. } else {
  148458. if (cinfo->progressive_mode)
  148459. emit_sof(cinfo, M_SOF2); /* SOF code for progressive Huffman */
  148460. else if (is_baseline)
  148461. emit_sof(cinfo, M_SOF0); /* SOF code for baseline implementation */
  148462. else
  148463. emit_sof(cinfo, M_SOF1); /* SOF code for non-baseline Huffman file */
  148464. }
  148465. }
  148466. METHODDEF(void)
  148467. write_scan_header (j_compress_ptr cinfo)
  148468. {
  148469. my_marker_ptr marker = (my_marker_ptr) cinfo->marker;
  148470. int i;
  148471. jpeg_component_info *compptr;
  148472. if (cinfo->arith_code) {
  148473. emit_dac(cinfo);
  148474. } else {
  148475. for (i = 0; i < cinfo->comps_in_scan; i++) {
  148476. compptr = cinfo->cur_comp_info[i];
  148477. if (cinfo->progressive_mode) {
  148478. if (cinfo->Ss == 0) {
  148479. if (cinfo->Ah == 0) /* DC needs no table for refinement scan */
  148480. emit_dht(cinfo, compptr->dc_tbl_no, FALSE);
  148481. } else {
  148482. emit_dht(cinfo, compptr->ac_tbl_no, TRUE);
  148483. }
  148484. } else {
  148485. emit_dht(cinfo, compptr->dc_tbl_no, FALSE);
  148486. emit_dht(cinfo, compptr->ac_tbl_no, TRUE);
  148487. }
  148488. }
  148489. }
  148490. if (cinfo->restart_interval != marker->last_restart_interval) {
  148491. emit_dri(cinfo);
  148492. marker->last_restart_interval = cinfo->restart_interval;
  148493. }
  148494. emit_sos(cinfo);
  148495. }
  148496. METHODDEF(void)
  148497. write_file_trailer (j_compress_ptr cinfo)
  148498. {
  148499. emit_marker(cinfo, M_EOI);
  148500. }
  148501. METHODDEF(void)
  148502. write_tables_only (j_compress_ptr cinfo)
  148503. {
  148504. int i;
  148505. emit_marker(cinfo, M_SOI);
  148506. for (i = 0; i < NUM_QUANT_TBLS; i++) {
  148507. if (cinfo->quant_tbl_ptrs[i] != NULL)
  148508. (void) emit_dqt(cinfo, i);
  148509. }
  148510. if (! cinfo->arith_code) {
  148511. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  148512. if (cinfo->dc_huff_tbl_ptrs[i] != NULL)
  148513. emit_dht(cinfo, i, FALSE);
  148514. if (cinfo->ac_huff_tbl_ptrs[i] != NULL)
  148515. emit_dht(cinfo, i, TRUE);
  148516. }
  148517. }
  148518. emit_marker(cinfo, M_EOI);
  148519. }
  148520. GLOBAL(void)
  148521. jinit_marker_writer (j_compress_ptr cinfo)
  148522. {
  148523. my_marker_ptr marker;
  148524. marker = (my_marker_ptr)
  148525. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  148526. SIZEOF(my_marker_writer));
  148527. cinfo->marker = (struct jpeg_marker_writer *) marker;
  148528. marker->pub.write_file_header = write_file_header;
  148529. marker->pub.write_frame_header = write_frame_header;
  148530. marker->pub.write_scan_header = write_scan_header;
  148531. marker->pub.write_file_trailer = write_file_trailer;
  148532. marker->pub.write_tables_only = write_tables_only;
  148533. marker->pub.write_marker_header = write_marker_header;
  148534. marker->pub.write_marker_byte = write_marker_byte;
  148535. marker->last_restart_interval = 0;
  148536. }
  148537. /*** End of inlined file: jcmarker.c ***/
  148538. /*** Start of inlined file: jcmaster.c ***/
  148539. #define JPEG_INTERNALS
  148540. typedef enum {
  148541. main_pass, /* input data, also do first output step */
  148542. huff_opt_pass, /* Huffman code optimization pass */
  148543. output_pass /* data output pass */
  148544. } c_pass_type;
  148545. typedef struct {
  148546. struct jpeg_comp_master pub; /* public fields */
  148547. c_pass_type pass_type; /* the type of the current pass */
  148548. int pass_number; /* # of passes completed */
  148549. int total_passes; /* total # of passes needed */
  148550. int scan_number; /* current index in scan_info[] */
  148551. } my_comp_master;
  148552. typedef my_comp_master * my_master_ptr;
  148553. LOCAL(void)
  148554. initial_setup (j_compress_ptr cinfo)
  148555. {
  148556. int ci;
  148557. jpeg_component_info *compptr;
  148558. long samplesperrow;
  148559. JDIMENSION jd_samplesperrow;
  148560. if (cinfo->image_height <= 0 || cinfo->image_width <= 0
  148561. || cinfo->num_components <= 0 || cinfo->input_components <= 0)
  148562. ERREXIT(cinfo, JERR_EMPTY_IMAGE);
  148563. if ((long) cinfo->image_height > (long) JPEG_MAX_DIMENSION ||
  148564. (long) cinfo->image_width > (long) JPEG_MAX_DIMENSION)
  148565. ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION);
  148566. samplesperrow = (long) cinfo->image_width * (long) cinfo->input_components;
  148567. jd_samplesperrow = (JDIMENSION) samplesperrow;
  148568. if ((long) jd_samplesperrow != samplesperrow)
  148569. ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  148570. if (cinfo->data_precision != BITS_IN_JSAMPLE)
  148571. ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
  148572. if (cinfo->num_components > MAX_COMPONENTS)
  148573. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  148574. MAX_COMPONENTS);
  148575. cinfo->max_h_samp_factor = 1;
  148576. cinfo->max_v_samp_factor = 1;
  148577. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148578. ci++, compptr++) {
  148579. if (compptr->h_samp_factor<=0 || compptr->h_samp_factor>MAX_SAMP_FACTOR ||
  148580. compptr->v_samp_factor<=0 || compptr->v_samp_factor>MAX_SAMP_FACTOR)
  148581. ERREXIT(cinfo, JERR_BAD_SAMPLING);
  148582. cinfo->max_h_samp_factor = MAX(cinfo->max_h_samp_factor,
  148583. compptr->h_samp_factor);
  148584. cinfo->max_v_samp_factor = MAX(cinfo->max_v_samp_factor,
  148585. compptr->v_samp_factor);
  148586. }
  148587. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148588. ci++, compptr++) {
  148589. compptr->component_index = ci;
  148590. compptr->DCT_scaled_size = DCTSIZE;
  148591. compptr->width_in_blocks = (JDIMENSION)
  148592. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  148593. (long) (cinfo->max_h_samp_factor * DCTSIZE));
  148594. compptr->height_in_blocks = (JDIMENSION)
  148595. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  148596. (long) (cinfo->max_v_samp_factor * DCTSIZE));
  148597. compptr->downsampled_width = (JDIMENSION)
  148598. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  148599. (long) cinfo->max_h_samp_factor);
  148600. compptr->downsampled_height = (JDIMENSION)
  148601. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  148602. (long) cinfo->max_v_samp_factor);
  148603. compptr->component_needed = TRUE;
  148604. }
  148605. cinfo->total_iMCU_rows = (JDIMENSION)
  148606. jdiv_round_up((long) cinfo->image_height,
  148607. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  148608. }
  148609. #ifdef C_MULTISCAN_FILES_SUPPORTED
  148610. LOCAL(void)
  148611. validate_script (j_compress_ptr cinfo)
  148612. {
  148613. const jpeg_scan_info * scanptr;
  148614. int scanno, ncomps, ci, coefi, thisi;
  148615. int Ss, Se, Ah, Al;
  148616. boolean component_sent[MAX_COMPONENTS];
  148617. #ifdef C_PROGRESSIVE_SUPPORTED
  148618. int * last_bitpos_ptr;
  148619. int last_bitpos[MAX_COMPONENTS][DCTSIZE2];
  148620. #endif
  148621. if (cinfo->num_scans <= 0)
  148622. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, 0);
  148623. scanptr = cinfo->scan_info;
  148624. if (scanptr->Ss != 0 || scanptr->Se != DCTSIZE2-1) {
  148625. #ifdef C_PROGRESSIVE_SUPPORTED
  148626. cinfo->progressive_mode = TRUE;
  148627. last_bitpos_ptr = & last_bitpos[0][0];
  148628. for (ci = 0; ci < cinfo->num_components; ci++)
  148629. for (coefi = 0; coefi < DCTSIZE2; coefi++)
  148630. *last_bitpos_ptr++ = -1;
  148631. #else
  148632. ERREXIT(cinfo, JERR_NOT_COMPILED);
  148633. #endif
  148634. } else {
  148635. cinfo->progressive_mode = FALSE;
  148636. for (ci = 0; ci < cinfo->num_components; ci++)
  148637. component_sent[ci] = FALSE;
  148638. }
  148639. for (scanno = 1; scanno <= cinfo->num_scans; scanptr++, scanno++) {
  148640. ncomps = scanptr->comps_in_scan;
  148641. if (ncomps <= 0 || ncomps > MAX_COMPS_IN_SCAN)
  148642. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, ncomps, MAX_COMPS_IN_SCAN);
  148643. for (ci = 0; ci < ncomps; ci++) {
  148644. thisi = scanptr->component_index[ci];
  148645. if (thisi < 0 || thisi >= cinfo->num_components)
  148646. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
  148647. if (ci > 0 && thisi <= scanptr->component_index[ci-1])
  148648. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
  148649. }
  148650. Ss = scanptr->Ss;
  148651. Se = scanptr->Se;
  148652. Ah = scanptr->Ah;
  148653. Al = scanptr->Al;
  148654. if (cinfo->progressive_mode) {
  148655. #ifdef C_PROGRESSIVE_SUPPORTED
  148656. #if BITS_IN_JSAMPLE == 8
  148657. #define MAX_AH_AL 10
  148658. #else
  148659. #define MAX_AH_AL 13
  148660. #endif
  148661. if (Ss < 0 || Ss >= DCTSIZE2 || Se < Ss || Se >= DCTSIZE2 ||
  148662. Ah < 0 || Ah > MAX_AH_AL || Al < 0 || Al > MAX_AH_AL)
  148663. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148664. if (Ss == 0) {
  148665. if (Se != 0) /* DC and AC together not OK */
  148666. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148667. } else {
  148668. if (ncomps != 1) /* AC scans must be for only one component */
  148669. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148670. }
  148671. for (ci = 0; ci < ncomps; ci++) {
  148672. last_bitpos_ptr = & last_bitpos[scanptr->component_index[ci]][0];
  148673. if (Ss != 0 && last_bitpos_ptr[0] < 0) /* AC without prior DC scan */
  148674. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148675. for (coefi = Ss; coefi <= Se; coefi++) {
  148676. if (last_bitpos_ptr[coefi] < 0) {
  148677. if (Ah != 0)
  148678. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148679. } else {
  148680. if (Ah != last_bitpos_ptr[coefi] || Al != Ah-1)
  148681. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148682. }
  148683. last_bitpos_ptr[coefi] = Al;
  148684. }
  148685. }
  148686. #endif
  148687. } else {
  148688. if (Ss != 0 || Se != DCTSIZE2-1 || Ah != 0 || Al != 0)
  148689. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148690. for (ci = 0; ci < ncomps; ci++) {
  148691. thisi = scanptr->component_index[ci];
  148692. if (component_sent[thisi])
  148693. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
  148694. component_sent[thisi] = TRUE;
  148695. }
  148696. }
  148697. }
  148698. if (cinfo->progressive_mode) {
  148699. #ifdef C_PROGRESSIVE_SUPPORTED
  148700. for (ci = 0; ci < cinfo->num_components; ci++) {
  148701. if (last_bitpos[ci][0] < 0)
  148702. ERREXIT(cinfo, JERR_MISSING_DATA);
  148703. }
  148704. #endif
  148705. } else {
  148706. for (ci = 0; ci < cinfo->num_components; ci++) {
  148707. if (! component_sent[ci])
  148708. ERREXIT(cinfo, JERR_MISSING_DATA);
  148709. }
  148710. }
  148711. }
  148712. #endif /* C_MULTISCAN_FILES_SUPPORTED */
  148713. LOCAL(void)
  148714. select_scan_parameters (j_compress_ptr cinfo)
  148715. {
  148716. int ci;
  148717. #ifdef C_MULTISCAN_FILES_SUPPORTED
  148718. if (cinfo->scan_info != NULL) {
  148719. my_master_ptr master = (my_master_ptr) cinfo->master;
  148720. const jpeg_scan_info * scanptr = cinfo->scan_info + master->scan_number;
  148721. cinfo->comps_in_scan = scanptr->comps_in_scan;
  148722. for (ci = 0; ci < scanptr->comps_in_scan; ci++) {
  148723. cinfo->cur_comp_info[ci] =
  148724. &cinfo->comp_info[scanptr->component_index[ci]];
  148725. }
  148726. cinfo->Ss = scanptr->Ss;
  148727. cinfo->Se = scanptr->Se;
  148728. cinfo->Ah = scanptr->Ah;
  148729. cinfo->Al = scanptr->Al;
  148730. }
  148731. else
  148732. #endif
  148733. {
  148734. if (cinfo->num_components > MAX_COMPS_IN_SCAN)
  148735. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  148736. MAX_COMPS_IN_SCAN);
  148737. cinfo->comps_in_scan = cinfo->num_components;
  148738. for (ci = 0; ci < cinfo->num_components; ci++) {
  148739. cinfo->cur_comp_info[ci] = &cinfo->comp_info[ci];
  148740. }
  148741. cinfo->Ss = 0;
  148742. cinfo->Se = DCTSIZE2-1;
  148743. cinfo->Ah = 0;
  148744. cinfo->Al = 0;
  148745. }
  148746. }
  148747. LOCAL(void)
  148748. per_scan_setup (j_compress_ptr cinfo)
  148749. {
  148750. int ci, mcublks, tmp;
  148751. jpeg_component_info *compptr;
  148752. if (cinfo->comps_in_scan == 1) {
  148753. compptr = cinfo->cur_comp_info[0];
  148754. cinfo->MCUs_per_row = compptr->width_in_blocks;
  148755. cinfo->MCU_rows_in_scan = compptr->height_in_blocks;
  148756. compptr->MCU_width = 1;
  148757. compptr->MCU_height = 1;
  148758. compptr->MCU_blocks = 1;
  148759. compptr->MCU_sample_width = DCTSIZE;
  148760. compptr->last_col_width = 1;
  148761. tmp = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  148762. if (tmp == 0) tmp = compptr->v_samp_factor;
  148763. compptr->last_row_height = tmp;
  148764. cinfo->blocks_in_MCU = 1;
  148765. cinfo->MCU_membership[0] = 0;
  148766. } else {
  148767. if (cinfo->comps_in_scan <= 0 || cinfo->comps_in_scan > MAX_COMPS_IN_SCAN)
  148768. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->comps_in_scan,
  148769. MAX_COMPS_IN_SCAN);
  148770. cinfo->MCUs_per_row = (JDIMENSION)
  148771. jdiv_round_up((long) cinfo->image_width,
  148772. (long) (cinfo->max_h_samp_factor*DCTSIZE));
  148773. cinfo->MCU_rows_in_scan = (JDIMENSION)
  148774. jdiv_round_up((long) cinfo->image_height,
  148775. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  148776. cinfo->blocks_in_MCU = 0;
  148777. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  148778. compptr = cinfo->cur_comp_info[ci];
  148779. compptr->MCU_width = compptr->h_samp_factor;
  148780. compptr->MCU_height = compptr->v_samp_factor;
  148781. compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height;
  148782. compptr->MCU_sample_width = compptr->MCU_width * DCTSIZE;
  148783. tmp = (int) (compptr->width_in_blocks % compptr->MCU_width);
  148784. if (tmp == 0) tmp = compptr->MCU_width;
  148785. compptr->last_col_width = tmp;
  148786. tmp = (int) (compptr->height_in_blocks % compptr->MCU_height);
  148787. if (tmp == 0) tmp = compptr->MCU_height;
  148788. compptr->last_row_height = tmp;
  148789. mcublks = compptr->MCU_blocks;
  148790. if (cinfo->blocks_in_MCU + mcublks > C_MAX_BLOCKS_IN_MCU)
  148791. ERREXIT(cinfo, JERR_BAD_MCU_SIZE);
  148792. while (mcublks-- > 0) {
  148793. cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci;
  148794. }
  148795. }
  148796. }
  148797. if (cinfo->restart_in_rows > 0) {
  148798. long nominal = (long) cinfo->restart_in_rows * (long) cinfo->MCUs_per_row;
  148799. cinfo->restart_interval = (unsigned int) MIN(nominal, 65535L);
  148800. }
  148801. }
  148802. METHODDEF(void)
  148803. prepare_for_pass (j_compress_ptr cinfo)
  148804. {
  148805. my_master_ptr master = (my_master_ptr) cinfo->master;
  148806. switch (master->pass_type) {
  148807. case main_pass:
  148808. select_scan_parameters(cinfo);
  148809. per_scan_setup(cinfo);
  148810. if (! cinfo->raw_data_in) {
  148811. (*cinfo->cconvert->start_pass) (cinfo);
  148812. (*cinfo->downsample->start_pass) (cinfo);
  148813. (*cinfo->prep->start_pass) (cinfo, JBUF_PASS_THRU);
  148814. }
  148815. (*cinfo->fdct->start_pass) (cinfo);
  148816. (*cinfo->entropy->start_pass) (cinfo, cinfo->optimize_coding);
  148817. (*cinfo->coef->start_pass) (cinfo,
  148818. (master->total_passes > 1 ?
  148819. JBUF_SAVE_AND_PASS : JBUF_PASS_THRU));
  148820. (*cinfo->main->start_pass) (cinfo, JBUF_PASS_THRU);
  148821. if (cinfo->optimize_coding) {
  148822. master->pub.call_pass_startup = FALSE;
  148823. } else {
  148824. master->pub.call_pass_startup = TRUE;
  148825. }
  148826. break;
  148827. #ifdef ENTROPY_OPT_SUPPORTED
  148828. case huff_opt_pass:
  148829. select_scan_parameters(cinfo);
  148830. per_scan_setup(cinfo);
  148831. if (cinfo->Ss != 0 || cinfo->Ah == 0 || cinfo->arith_code) {
  148832. (*cinfo->entropy->start_pass) (cinfo, TRUE);
  148833. (*cinfo->coef->start_pass) (cinfo, JBUF_CRANK_DEST);
  148834. master->pub.call_pass_startup = FALSE;
  148835. break;
  148836. }
  148837. master->pass_type = output_pass;
  148838. master->pass_number++;
  148839. #endif
  148840. case output_pass:
  148841. if (! cinfo->optimize_coding) {
  148842. select_scan_parameters(cinfo);
  148843. per_scan_setup(cinfo);
  148844. }
  148845. (*cinfo->entropy->start_pass) (cinfo, FALSE);
  148846. (*cinfo->coef->start_pass) (cinfo, JBUF_CRANK_DEST);
  148847. if (master->scan_number == 0)
  148848. (*cinfo->marker->write_frame_header) (cinfo);
  148849. (*cinfo->marker->write_scan_header) (cinfo);
  148850. master->pub.call_pass_startup = FALSE;
  148851. break;
  148852. default:
  148853. ERREXIT(cinfo, JERR_NOT_COMPILED);
  148854. }
  148855. master->pub.is_last_pass = (master->pass_number == master->total_passes-1);
  148856. if (cinfo->progress != NULL) {
  148857. cinfo->progress->completed_passes = master->pass_number;
  148858. cinfo->progress->total_passes = master->total_passes;
  148859. }
  148860. }
  148861. METHODDEF(void)
  148862. pass_startup (j_compress_ptr cinfo)
  148863. {
  148864. cinfo->master->call_pass_startup = FALSE; /* reset flag so call only once */
  148865. (*cinfo->marker->write_frame_header) (cinfo);
  148866. (*cinfo->marker->write_scan_header) (cinfo);
  148867. }
  148868. METHODDEF(void)
  148869. finish_pass_master (j_compress_ptr cinfo)
  148870. {
  148871. my_master_ptr master = (my_master_ptr) cinfo->master;
  148872. (*cinfo->entropy->finish_pass) (cinfo);
  148873. switch (master->pass_type) {
  148874. case main_pass:
  148875. master->pass_type = output_pass;
  148876. if (! cinfo->optimize_coding)
  148877. master->scan_number++;
  148878. break;
  148879. case huff_opt_pass:
  148880. master->pass_type = output_pass;
  148881. break;
  148882. case output_pass:
  148883. if (cinfo->optimize_coding)
  148884. master->pass_type = huff_opt_pass;
  148885. master->scan_number++;
  148886. break;
  148887. }
  148888. master->pass_number++;
  148889. }
  148890. GLOBAL(void)
  148891. jinit_c_master_control (j_compress_ptr cinfo, boolean transcode_only)
  148892. {
  148893. my_master_ptr master;
  148894. master = (my_master_ptr)
  148895. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  148896. SIZEOF(my_comp_master));
  148897. cinfo->master = (struct jpeg_comp_master *) master;
  148898. master->pub.prepare_for_pass = prepare_for_pass;
  148899. master->pub.pass_startup = pass_startup;
  148900. master->pub.finish_pass = finish_pass_master;
  148901. master->pub.is_last_pass = FALSE;
  148902. initial_setup(cinfo);
  148903. if (cinfo->scan_info != NULL) {
  148904. #ifdef C_MULTISCAN_FILES_SUPPORTED
  148905. validate_script(cinfo);
  148906. #else
  148907. ERREXIT(cinfo, JERR_NOT_COMPILED);
  148908. #endif
  148909. } else {
  148910. cinfo->progressive_mode = FALSE;
  148911. cinfo->num_scans = 1;
  148912. }
  148913. if (cinfo->progressive_mode) /* TEMPORARY HACK ??? */
  148914. cinfo->optimize_coding = TRUE; /* assume default tables no good for progressive mode */
  148915. if (transcode_only) {
  148916. if (cinfo->optimize_coding)
  148917. master->pass_type = huff_opt_pass;
  148918. else
  148919. master->pass_type = output_pass;
  148920. } else {
  148921. master->pass_type = main_pass;
  148922. }
  148923. master->scan_number = 0;
  148924. master->pass_number = 0;
  148925. if (cinfo->optimize_coding)
  148926. master->total_passes = cinfo->num_scans * 2;
  148927. else
  148928. master->total_passes = cinfo->num_scans;
  148929. }
  148930. /*** End of inlined file: jcmaster.c ***/
  148931. /*** Start of inlined file: jcomapi.c ***/
  148932. #define JPEG_INTERNALS
  148933. GLOBAL(void)
  148934. jpeg_abort (j_common_ptr cinfo)
  148935. {
  148936. int pool;
  148937. if (cinfo->mem == NULL)
  148938. return;
  148939. for (pool = JPOOL_NUMPOOLS-1; pool > JPOOL_PERMANENT; pool--) {
  148940. (*cinfo->mem->free_pool) (cinfo, pool);
  148941. }
  148942. if (cinfo->is_decompressor) {
  148943. cinfo->global_state = DSTATE_START;
  148944. ((j_decompress_ptr) cinfo)->marker_list = NULL;
  148945. } else {
  148946. cinfo->global_state = CSTATE_START;
  148947. }
  148948. }
  148949. GLOBAL(void)
  148950. jpeg_destroy (j_common_ptr cinfo)
  148951. {
  148952. if (cinfo->mem != NULL)
  148953. (*cinfo->mem->self_destruct) (cinfo);
  148954. cinfo->mem = NULL; /* be safe if jpeg_destroy is called twice */
  148955. cinfo->global_state = 0; /* mark it destroyed */
  148956. }
  148957. GLOBAL(JQUANT_TBL *)
  148958. jpeg_alloc_quant_table (j_common_ptr cinfo)
  148959. {
  148960. JQUANT_TBL *tbl;
  148961. tbl = (JQUANT_TBL *)
  148962. (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JQUANT_TBL));
  148963. tbl->sent_table = FALSE; /* make sure this is false in any new table */
  148964. return tbl;
  148965. }
  148966. GLOBAL(JHUFF_TBL *)
  148967. jpeg_alloc_huff_table (j_common_ptr cinfo)
  148968. {
  148969. JHUFF_TBL *tbl;
  148970. tbl = (JHUFF_TBL *)
  148971. (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JHUFF_TBL));
  148972. tbl->sent_table = FALSE; /* make sure this is false in any new table */
  148973. return tbl;
  148974. }
  148975. /*** End of inlined file: jcomapi.c ***/
  148976. /*** Start of inlined file: jcparam.c ***/
  148977. #define JPEG_INTERNALS
  148978. GLOBAL(void)
  148979. jpeg_add_quant_table (j_compress_ptr cinfo, int which_tbl,
  148980. const unsigned int *basic_table,
  148981. int scale_factor, boolean force_baseline)
  148982. {
  148983. JQUANT_TBL ** qtblptr;
  148984. int i;
  148985. long temp;
  148986. if (cinfo->global_state != CSTATE_START)
  148987. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  148988. if (which_tbl < 0 || which_tbl >= NUM_QUANT_TBLS)
  148989. ERREXIT1(cinfo, JERR_DQT_INDEX, which_tbl);
  148990. qtblptr = & cinfo->quant_tbl_ptrs[which_tbl];
  148991. if (*qtblptr == NULL)
  148992. *qtblptr = jpeg_alloc_quant_table((j_common_ptr) cinfo);
  148993. for (i = 0; i < DCTSIZE2; i++) {
  148994. temp = ((long) basic_table[i] * scale_factor + 50L) / 100L;
  148995. if (temp <= 0L) temp = 1L;
  148996. if (temp > 32767L) temp = 32767L; /* max quantizer needed for 12 bits */
  148997. if (force_baseline && temp > 255L)
  148998. temp = 255L; /* limit to baseline range if requested */
  148999. (*qtblptr)->quantval[i] = (UINT16) temp;
  149000. }
  149001. (*qtblptr)->sent_table = FALSE;
  149002. }
  149003. GLOBAL(void)
  149004. jpeg_set_linear_quality (j_compress_ptr cinfo, int scale_factor,
  149005. boolean force_baseline)
  149006. {
  149007. static const unsigned int std_luminance_quant_tbl[DCTSIZE2] = {
  149008. 16, 11, 10, 16, 24, 40, 51, 61,
  149009. 12, 12, 14, 19, 26, 58, 60, 55,
  149010. 14, 13, 16, 24, 40, 57, 69, 56,
  149011. 14, 17, 22, 29, 51, 87, 80, 62,
  149012. 18, 22, 37, 56, 68, 109, 103, 77,
  149013. 24, 35, 55, 64, 81, 104, 113, 92,
  149014. 49, 64, 78, 87, 103, 121, 120, 101,
  149015. 72, 92, 95, 98, 112, 100, 103, 99
  149016. };
  149017. static const unsigned int std_chrominance_quant_tbl[DCTSIZE2] = {
  149018. 17, 18, 24, 47, 99, 99, 99, 99,
  149019. 18, 21, 26, 66, 99, 99, 99, 99,
  149020. 24, 26, 56, 99, 99, 99, 99, 99,
  149021. 47, 66, 99, 99, 99, 99, 99, 99,
  149022. 99, 99, 99, 99, 99, 99, 99, 99,
  149023. 99, 99, 99, 99, 99, 99, 99, 99,
  149024. 99, 99, 99, 99, 99, 99, 99, 99,
  149025. 99, 99, 99, 99, 99, 99, 99, 99
  149026. };
  149027. jpeg_add_quant_table(cinfo, 0, std_luminance_quant_tbl,
  149028. scale_factor, force_baseline);
  149029. jpeg_add_quant_table(cinfo, 1, std_chrominance_quant_tbl,
  149030. scale_factor, force_baseline);
  149031. }
  149032. GLOBAL(int)
  149033. jpeg_quality_scaling (int quality)
  149034. {
  149035. if (quality <= 0) quality = 1;
  149036. if (quality > 100) quality = 100;
  149037. if (quality < 50)
  149038. quality = 5000 / quality;
  149039. else
  149040. quality = 200 - quality*2;
  149041. return quality;
  149042. }
  149043. GLOBAL(void)
  149044. jpeg_set_quality (j_compress_ptr cinfo, int quality, boolean force_baseline)
  149045. {
  149046. quality = jpeg_quality_scaling(quality);
  149047. jpeg_set_linear_quality(cinfo, quality, force_baseline);
  149048. }
  149049. LOCAL(void)
  149050. add_huff_table (j_compress_ptr cinfo,
  149051. JHUFF_TBL **htblptr, const UINT8 *bits, const UINT8 *val)
  149052. {
  149053. int nsymbols, len;
  149054. if (*htblptr == NULL)
  149055. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  149056. MEMCOPY((*htblptr)->bits, bits, SIZEOF((*htblptr)->bits));
  149057. nsymbols = 0;
  149058. for (len = 1; len <= 16; len++)
  149059. nsymbols += bits[len];
  149060. if (nsymbols < 1 || nsymbols > 256)
  149061. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  149062. MEMCOPY((*htblptr)->huffval, val, nsymbols * SIZEOF(UINT8));
  149063. (*htblptr)->sent_table = FALSE;
  149064. }
  149065. LOCAL(void)
  149066. std_huff_tables (j_compress_ptr cinfo)
  149067. {
  149068. static const UINT8 bits_dc_luminance[17] =
  149069. { /* 0-base */ 0, 0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 };
  149070. static const UINT8 val_dc_luminance[] =
  149071. { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
  149072. static const UINT8 bits_dc_chrominance[17] =
  149073. { /* 0-base */ 0, 0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 };
  149074. static const UINT8 val_dc_chrominance[] =
  149075. { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
  149076. static const UINT8 bits_ac_luminance[17] =
  149077. { /* 0-base */ 0, 0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 0x7d };
  149078. static const UINT8 val_ac_luminance[] =
  149079. { 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12,
  149080. 0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07,
  149081. 0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xa1, 0x08,
  149082. 0x23, 0x42, 0xb1, 0xc1, 0x15, 0x52, 0xd1, 0xf0,
  149083. 0x24, 0x33, 0x62, 0x72, 0x82, 0x09, 0x0a, 0x16,
  149084. 0x17, 0x18, 0x19, 0x1a, 0x25, 0x26, 0x27, 0x28,
  149085. 0x29, 0x2a, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39,
  149086. 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49,
  149087. 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59,
  149088. 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69,
  149089. 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79,
  149090. 0x7a, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89,
  149091. 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98,
  149092. 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
  149093. 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6,
  149094. 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5,
  149095. 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4,
  149096. 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe1, 0xe2,
  149097. 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea,
  149098. 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
  149099. 0xf9, 0xfa };
  149100. static const UINT8 bits_ac_chrominance[17] =
  149101. { /* 0-base */ 0, 0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 0x77 };
  149102. static const UINT8 val_ac_chrominance[] =
  149103. { 0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21,
  149104. 0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71,
  149105. 0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91,
  149106. 0xa1, 0xb1, 0xc1, 0x09, 0x23, 0x33, 0x52, 0xf0,
  149107. 0x15, 0x62, 0x72, 0xd1, 0x0a, 0x16, 0x24, 0x34,
  149108. 0xe1, 0x25, 0xf1, 0x17, 0x18, 0x19, 0x1a, 0x26,
  149109. 0x27, 0x28, 0x29, 0x2a, 0x35, 0x36, 0x37, 0x38,
  149110. 0x39, 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48,
  149111. 0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
  149112. 0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68,
  149113. 0x69, 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,
  149114. 0x79, 0x7a, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
  149115. 0x88, 0x89, 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96,
  149116. 0x97, 0x98, 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5,
  149117. 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4,
  149118. 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3,
  149119. 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2,
  149120. 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda,
  149121. 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9,
  149122. 0xea, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
  149123. 0xf9, 0xfa };
  149124. add_huff_table(cinfo, &cinfo->dc_huff_tbl_ptrs[0],
  149125. bits_dc_luminance, val_dc_luminance);
  149126. add_huff_table(cinfo, &cinfo->ac_huff_tbl_ptrs[0],
  149127. bits_ac_luminance, val_ac_luminance);
  149128. add_huff_table(cinfo, &cinfo->dc_huff_tbl_ptrs[1],
  149129. bits_dc_chrominance, val_dc_chrominance);
  149130. add_huff_table(cinfo, &cinfo->ac_huff_tbl_ptrs[1],
  149131. bits_ac_chrominance, val_ac_chrominance);
  149132. }
  149133. GLOBAL(void)
  149134. jpeg_set_defaults (j_compress_ptr cinfo)
  149135. {
  149136. int i;
  149137. if (cinfo->global_state != CSTATE_START)
  149138. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  149139. if (cinfo->comp_info == NULL)
  149140. cinfo->comp_info = (jpeg_component_info *)
  149141. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  149142. MAX_COMPONENTS * SIZEOF(jpeg_component_info));
  149143. cinfo->data_precision = BITS_IN_JSAMPLE;
  149144. jpeg_set_quality(cinfo, 75, TRUE);
  149145. std_huff_tables(cinfo);
  149146. for (i = 0; i < NUM_ARITH_TBLS; i++) {
  149147. cinfo->arith_dc_L[i] = 0;
  149148. cinfo->arith_dc_U[i] = 1;
  149149. cinfo->arith_ac_K[i] = 5;
  149150. }
  149151. cinfo->scan_info = NULL;
  149152. cinfo->num_scans = 0;
  149153. cinfo->raw_data_in = FALSE;
  149154. cinfo->arith_code = FALSE;
  149155. cinfo->optimize_coding = FALSE;
  149156. if (cinfo->data_precision > 8)
  149157. cinfo->optimize_coding = TRUE;
  149158. cinfo->CCIR601_sampling = FALSE;
  149159. cinfo->smoothing_factor = 0;
  149160. cinfo->dct_method = JDCT_DEFAULT;
  149161. cinfo->restart_interval = 0;
  149162. cinfo->restart_in_rows = 0;
  149163. cinfo->JFIF_major_version = 1; /* Default JFIF version = 1.01 */
  149164. cinfo->JFIF_minor_version = 1;
  149165. cinfo->density_unit = 0; /* Pixel size is unknown by default */
  149166. cinfo->X_density = 1; /* Pixel aspect ratio is square by default */
  149167. cinfo->Y_density = 1;
  149168. jpeg_default_colorspace(cinfo);
  149169. }
  149170. GLOBAL(void)
  149171. jpeg_default_colorspace (j_compress_ptr cinfo)
  149172. {
  149173. switch (cinfo->in_color_space) {
  149174. case JCS_GRAYSCALE:
  149175. jpeg_set_colorspace(cinfo, JCS_GRAYSCALE);
  149176. break;
  149177. case JCS_RGB:
  149178. jpeg_set_colorspace(cinfo, JCS_YCbCr);
  149179. break;
  149180. case JCS_YCbCr:
  149181. jpeg_set_colorspace(cinfo, JCS_YCbCr);
  149182. break;
  149183. case JCS_CMYK:
  149184. jpeg_set_colorspace(cinfo, JCS_CMYK); /* By default, no translation */
  149185. break;
  149186. case JCS_YCCK:
  149187. jpeg_set_colorspace(cinfo, JCS_YCCK);
  149188. break;
  149189. case JCS_UNKNOWN:
  149190. jpeg_set_colorspace(cinfo, JCS_UNKNOWN);
  149191. break;
  149192. default:
  149193. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  149194. }
  149195. }
  149196. GLOBAL(void)
  149197. jpeg_set_colorspace (j_compress_ptr cinfo, J_COLOR_SPACE colorspace)
  149198. {
  149199. jpeg_component_info * compptr;
  149200. int ci;
  149201. #define SET_COMP(index,id,hsamp,vsamp,quant,dctbl,actbl) \
  149202. (compptr = &cinfo->comp_info[index], \
  149203. compptr->component_id = (id), \
  149204. compptr->h_samp_factor = (hsamp), \
  149205. compptr->v_samp_factor = (vsamp), \
  149206. compptr->quant_tbl_no = (quant), \
  149207. compptr->dc_tbl_no = (dctbl), \
  149208. compptr->ac_tbl_no = (actbl) )
  149209. if (cinfo->global_state != CSTATE_START)
  149210. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  149211. cinfo->jpeg_color_space = colorspace;
  149212. cinfo->write_JFIF_header = FALSE; /* No marker for non-JFIF colorspaces */
  149213. cinfo->write_Adobe_marker = FALSE; /* write no Adobe marker by default */
  149214. switch (colorspace) {
  149215. case JCS_GRAYSCALE:
  149216. cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */
  149217. cinfo->num_components = 1;
  149218. SET_COMP(0, 1, 1,1, 0, 0,0);
  149219. break;
  149220. case JCS_RGB:
  149221. cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag RGB */
  149222. cinfo->num_components = 3;
  149223. SET_COMP(0, 0x52 /* 'R' */, 1,1, 0, 0,0);
  149224. SET_COMP(1, 0x47 /* 'G' */, 1,1, 0, 0,0);
  149225. SET_COMP(2, 0x42 /* 'B' */, 1,1, 0, 0,0);
  149226. break;
  149227. case JCS_YCbCr:
  149228. cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */
  149229. cinfo->num_components = 3;
  149230. SET_COMP(0, 1, 2,2, 0, 0,0);
  149231. SET_COMP(1, 2, 1,1, 1, 1,1);
  149232. SET_COMP(2, 3, 1,1, 1, 1,1);
  149233. break;
  149234. case JCS_CMYK:
  149235. cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag CMYK */
  149236. cinfo->num_components = 4;
  149237. SET_COMP(0, 0x43 /* 'C' */, 1,1, 0, 0,0);
  149238. SET_COMP(1, 0x4D /* 'M' */, 1,1, 0, 0,0);
  149239. SET_COMP(2, 0x59 /* 'Y' */, 1,1, 0, 0,0);
  149240. SET_COMP(3, 0x4B /* 'K' */, 1,1, 0, 0,0);
  149241. break;
  149242. case JCS_YCCK:
  149243. cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag YCCK */
  149244. cinfo->num_components = 4;
  149245. SET_COMP(0, 1, 2,2, 0, 0,0);
  149246. SET_COMP(1, 2, 1,1, 1, 1,1);
  149247. SET_COMP(2, 3, 1,1, 1, 1,1);
  149248. SET_COMP(3, 4, 2,2, 0, 0,0);
  149249. break;
  149250. case JCS_UNKNOWN:
  149251. cinfo->num_components = cinfo->input_components;
  149252. if (cinfo->num_components < 1 || cinfo->num_components > MAX_COMPONENTS)
  149253. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  149254. MAX_COMPONENTS);
  149255. for (ci = 0; ci < cinfo->num_components; ci++) {
  149256. SET_COMP(ci, ci, 1,1, 0, 0,0);
  149257. }
  149258. break;
  149259. default:
  149260. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  149261. }
  149262. }
  149263. #ifdef C_PROGRESSIVE_SUPPORTED
  149264. LOCAL(jpeg_scan_info *)
  149265. fill_a_scan (jpeg_scan_info * scanptr, int ci,
  149266. int Ss, int Se, int Ah, int Al)
  149267. {
  149268. scanptr->comps_in_scan = 1;
  149269. scanptr->component_index[0] = ci;
  149270. scanptr->Ss = Ss;
  149271. scanptr->Se = Se;
  149272. scanptr->Ah = Ah;
  149273. scanptr->Al = Al;
  149274. scanptr++;
  149275. return scanptr;
  149276. }
  149277. LOCAL(jpeg_scan_info *)
  149278. fill_scans (jpeg_scan_info * scanptr, int ncomps,
  149279. int Ss, int Se, int Ah, int Al)
  149280. {
  149281. int ci;
  149282. for (ci = 0; ci < ncomps; ci++) {
  149283. scanptr->comps_in_scan = 1;
  149284. scanptr->component_index[0] = ci;
  149285. scanptr->Ss = Ss;
  149286. scanptr->Se = Se;
  149287. scanptr->Ah = Ah;
  149288. scanptr->Al = Al;
  149289. scanptr++;
  149290. }
  149291. return scanptr;
  149292. }
  149293. LOCAL(jpeg_scan_info *)
  149294. fill_dc_scans (jpeg_scan_info * scanptr, int ncomps, int Ah, int Al)
  149295. {
  149296. int ci;
  149297. if (ncomps <= MAX_COMPS_IN_SCAN) {
  149298. scanptr->comps_in_scan = ncomps;
  149299. for (ci = 0; ci < ncomps; ci++)
  149300. scanptr->component_index[ci] = ci;
  149301. scanptr->Ss = scanptr->Se = 0;
  149302. scanptr->Ah = Ah;
  149303. scanptr->Al = Al;
  149304. scanptr++;
  149305. } else {
  149306. scanptr = fill_scans(scanptr, ncomps, 0, 0, Ah, Al);
  149307. }
  149308. return scanptr;
  149309. }
  149310. GLOBAL(void)
  149311. jpeg_simple_progression (j_compress_ptr cinfo)
  149312. {
  149313. int ncomps = cinfo->num_components;
  149314. int nscans;
  149315. jpeg_scan_info * scanptr;
  149316. if (cinfo->global_state != CSTATE_START)
  149317. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  149318. if (ncomps == 3 && cinfo->jpeg_color_space == JCS_YCbCr) {
  149319. nscans = 10;
  149320. } else {
  149321. if (ncomps > MAX_COMPS_IN_SCAN)
  149322. nscans = 6 * ncomps; /* 2 DC + 4 AC scans per component */
  149323. else
  149324. nscans = 2 + 4 * ncomps; /* 2 DC scans; 4 AC scans per component */
  149325. }
  149326. if (cinfo->script_space == NULL || cinfo->script_space_size < nscans) {
  149327. cinfo->script_space_size = MAX(nscans, 10);
  149328. cinfo->script_space = (jpeg_scan_info *)
  149329. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  149330. cinfo->script_space_size * SIZEOF(jpeg_scan_info));
  149331. }
  149332. scanptr = cinfo->script_space;
  149333. cinfo->scan_info = scanptr;
  149334. cinfo->num_scans = nscans;
  149335. if (ncomps == 3 && cinfo->jpeg_color_space == JCS_YCbCr) {
  149336. scanptr = fill_dc_scans(scanptr, ncomps, 0, 1);
  149337. scanptr = fill_a_scan(scanptr, 0, 1, 5, 0, 2);
  149338. scanptr = fill_a_scan(scanptr, 2, 1, 63, 0, 1);
  149339. scanptr = fill_a_scan(scanptr, 1, 1, 63, 0, 1);
  149340. scanptr = fill_a_scan(scanptr, 0, 6, 63, 0, 2);
  149341. scanptr = fill_a_scan(scanptr, 0, 1, 63, 2, 1);
  149342. scanptr = fill_dc_scans(scanptr, ncomps, 1, 0);
  149343. scanptr = fill_a_scan(scanptr, 2, 1, 63, 1, 0);
  149344. scanptr = fill_a_scan(scanptr, 1, 1, 63, 1, 0);
  149345. scanptr = fill_a_scan(scanptr, 0, 1, 63, 1, 0);
  149346. } else {
  149347. scanptr = fill_dc_scans(scanptr, ncomps, 0, 1);
  149348. scanptr = fill_scans(scanptr, ncomps, 1, 5, 0, 2);
  149349. scanptr = fill_scans(scanptr, ncomps, 6, 63, 0, 2);
  149350. scanptr = fill_scans(scanptr, ncomps, 1, 63, 2, 1);
  149351. scanptr = fill_dc_scans(scanptr, ncomps, 1, 0);
  149352. scanptr = fill_scans(scanptr, ncomps, 1, 63, 1, 0);
  149353. }
  149354. }
  149355. #endif /* C_PROGRESSIVE_SUPPORTED */
  149356. /*** End of inlined file: jcparam.c ***/
  149357. /*** Start of inlined file: jcphuff.c ***/
  149358. #define JPEG_INTERNALS
  149359. #ifdef C_PROGRESSIVE_SUPPORTED
  149360. typedef struct {
  149361. struct jpeg_entropy_encoder pub; /* public fields */
  149362. boolean gather_statistics;
  149363. JOCTET * next_output_byte; /* => next byte to write in buffer */
  149364. size_t free_in_buffer; /* # of byte spaces remaining in buffer */
  149365. INT32 put_buffer; /* current bit-accumulation buffer */
  149366. int put_bits; /* # of bits now in it */
  149367. j_compress_ptr cinfo; /* link to cinfo (needed for dump_buffer) */
  149368. int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
  149369. int ac_tbl_no; /* the table number of the single component */
  149370. unsigned int EOBRUN; /* run length of EOBs */
  149371. unsigned int BE; /* # of buffered correction bits before MCU */
  149372. char * bit_buffer; /* buffer for correction bits (1 per char) */
  149373. unsigned int restarts_to_go; /* MCUs left in this restart interval */
  149374. int next_restart_num; /* next restart number to write (0-7) */
  149375. c_derived_tbl * derived_tbls[NUM_HUFF_TBLS];
  149376. long * count_ptrs[NUM_HUFF_TBLS];
  149377. } phuff_entropy_encoder;
  149378. typedef phuff_entropy_encoder * phuff_entropy_ptr;
  149379. #define MAX_CORR_BITS 1000 /* Max # of correction bits I can buffer */
  149380. #ifdef RIGHT_SHIFT_IS_UNSIGNED
  149381. #define ISHIFT_TEMPS int ishift_temp;
  149382. #define IRIGHT_SHIFT(x,shft) \
  149383. ((ishift_temp = (x)) < 0 ? \
  149384. (ishift_temp >> (shft)) | ((~0) << (16-(shft))) : \
  149385. (ishift_temp >> (shft)))
  149386. #else
  149387. #define ISHIFT_TEMPS
  149388. #define IRIGHT_SHIFT(x,shft) ((x) >> (shft))
  149389. #endif
  149390. METHODDEF(boolean) encode_mcu_DC_first JPP((j_compress_ptr cinfo,
  149391. JBLOCKROW *MCU_data));
  149392. METHODDEF(boolean) encode_mcu_AC_first JPP((j_compress_ptr cinfo,
  149393. JBLOCKROW *MCU_data));
  149394. METHODDEF(boolean) encode_mcu_DC_refine JPP((j_compress_ptr cinfo,
  149395. JBLOCKROW *MCU_data));
  149396. METHODDEF(boolean) encode_mcu_AC_refine JPP((j_compress_ptr cinfo,
  149397. JBLOCKROW *MCU_data));
  149398. METHODDEF(void) finish_pass_phuff JPP((j_compress_ptr cinfo));
  149399. METHODDEF(void) finish_pass_gather_phuff JPP((j_compress_ptr cinfo));
  149400. METHODDEF(void)
  149401. start_pass_phuff (j_compress_ptr cinfo, boolean gather_statistics)
  149402. {
  149403. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149404. boolean is_DC_band;
  149405. int ci, tbl;
  149406. jpeg_component_info * compptr;
  149407. entropy->cinfo = cinfo;
  149408. entropy->gather_statistics = gather_statistics;
  149409. is_DC_band = (cinfo->Ss == 0);
  149410. if (cinfo->Ah == 0) {
  149411. if (is_DC_band)
  149412. entropy->pub.encode_mcu = encode_mcu_DC_first;
  149413. else
  149414. entropy->pub.encode_mcu = encode_mcu_AC_first;
  149415. } else {
  149416. if (is_DC_band)
  149417. entropy->pub.encode_mcu = encode_mcu_DC_refine;
  149418. else {
  149419. entropy->pub.encode_mcu = encode_mcu_AC_refine;
  149420. if (entropy->bit_buffer == NULL)
  149421. entropy->bit_buffer = (char *)
  149422. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149423. MAX_CORR_BITS * SIZEOF(char));
  149424. }
  149425. }
  149426. if (gather_statistics)
  149427. entropy->pub.finish_pass = finish_pass_gather_phuff;
  149428. else
  149429. entropy->pub.finish_pass = finish_pass_phuff;
  149430. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  149431. compptr = cinfo->cur_comp_info[ci];
  149432. entropy->last_dc_val[ci] = 0;
  149433. if (is_DC_band) {
  149434. if (cinfo->Ah != 0) /* DC refinement needs no table */
  149435. continue;
  149436. tbl = compptr->dc_tbl_no;
  149437. } else {
  149438. entropy->ac_tbl_no = tbl = compptr->ac_tbl_no;
  149439. }
  149440. if (gather_statistics) {
  149441. if (tbl < 0 || tbl >= NUM_HUFF_TBLS)
  149442. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tbl);
  149443. if (entropy->count_ptrs[tbl] == NULL)
  149444. entropy->count_ptrs[tbl] = (long *)
  149445. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149446. 257 * SIZEOF(long));
  149447. MEMZERO(entropy->count_ptrs[tbl], 257 * SIZEOF(long));
  149448. } else {
  149449. jpeg_make_c_derived_tbl(cinfo, is_DC_band, tbl,
  149450. & entropy->derived_tbls[tbl]);
  149451. }
  149452. }
  149453. entropy->EOBRUN = 0;
  149454. entropy->BE = 0;
  149455. entropy->put_buffer = 0;
  149456. entropy->put_bits = 0;
  149457. entropy->restarts_to_go = cinfo->restart_interval;
  149458. entropy->next_restart_num = 0;
  149459. }
  149460. #define emit_byte(entropy,val) \
  149461. { *(entropy)->next_output_byte++ = (JOCTET) (val); \
  149462. if (--(entropy)->free_in_buffer == 0) \
  149463. dump_buffer_p(entropy); }
  149464. LOCAL(void)
  149465. dump_buffer_p (phuff_entropy_ptr entropy)
  149466. {
  149467. struct jpeg_destination_mgr * dest = entropy->cinfo->dest;
  149468. if (! (*dest->empty_output_buffer) (entropy->cinfo))
  149469. ERREXIT(entropy->cinfo, JERR_CANT_SUSPEND);
  149470. entropy->next_output_byte = dest->next_output_byte;
  149471. entropy->free_in_buffer = dest->free_in_buffer;
  149472. }
  149473. INLINE
  149474. LOCAL(void)
  149475. emit_bits_p (phuff_entropy_ptr entropy, unsigned int code, int size)
  149476. {
  149477. register INT32 put_buffer = (INT32) code;
  149478. register int put_bits = entropy->put_bits;
  149479. if (size == 0)
  149480. ERREXIT(entropy->cinfo, JERR_HUFF_MISSING_CODE);
  149481. if (entropy->gather_statistics)
  149482. return; /* do nothing if we're only getting stats */
  149483. put_buffer &= (((INT32) 1)<<size) - 1; /* mask off any extra bits in code */
  149484. put_bits += size; /* new number of bits in buffer */
  149485. put_buffer <<= 24 - put_bits; /* align incoming bits */
  149486. put_buffer |= entropy->put_buffer; /* and merge with old buffer contents */
  149487. while (put_bits >= 8) {
  149488. int c = (int) ((put_buffer >> 16) & 0xFF);
  149489. emit_byte(entropy, c);
  149490. if (c == 0xFF) { /* need to stuff a zero byte? */
  149491. emit_byte(entropy, 0);
  149492. }
  149493. put_buffer <<= 8;
  149494. put_bits -= 8;
  149495. }
  149496. entropy->put_buffer = put_buffer; /* update variables */
  149497. entropy->put_bits = put_bits;
  149498. }
  149499. LOCAL(void)
  149500. flush_bits_p (phuff_entropy_ptr entropy)
  149501. {
  149502. emit_bits_p(entropy, 0x7F, 7); /* fill any partial byte with ones */
  149503. entropy->put_buffer = 0; /* and reset bit-buffer to empty */
  149504. entropy->put_bits = 0;
  149505. }
  149506. INLINE
  149507. LOCAL(void)
  149508. emit_symbol (phuff_entropy_ptr entropy, int tbl_no, int symbol)
  149509. {
  149510. if (entropy->gather_statistics)
  149511. entropy->count_ptrs[tbl_no][symbol]++;
  149512. else {
  149513. c_derived_tbl * tbl = entropy->derived_tbls[tbl_no];
  149514. emit_bits_p(entropy, tbl->ehufco[symbol], tbl->ehufsi[symbol]);
  149515. }
  149516. }
  149517. LOCAL(void)
  149518. emit_buffered_bits (phuff_entropy_ptr entropy, char * bufstart,
  149519. unsigned int nbits)
  149520. {
  149521. if (entropy->gather_statistics)
  149522. return; /* no real work */
  149523. while (nbits > 0) {
  149524. emit_bits_p(entropy, (unsigned int) (*bufstart), 1);
  149525. bufstart++;
  149526. nbits--;
  149527. }
  149528. }
  149529. LOCAL(void)
  149530. emit_eobrun (phuff_entropy_ptr entropy)
  149531. {
  149532. register int temp, nbits;
  149533. if (entropy->EOBRUN > 0) { /* if there is any pending EOBRUN */
  149534. temp = entropy->EOBRUN;
  149535. nbits = 0;
  149536. while ((temp >>= 1))
  149537. nbits++;
  149538. if (nbits > 14)
  149539. ERREXIT(entropy->cinfo, JERR_HUFF_MISSING_CODE);
  149540. emit_symbol(entropy, entropy->ac_tbl_no, nbits << 4);
  149541. if (nbits)
  149542. emit_bits_p(entropy, entropy->EOBRUN, nbits);
  149543. entropy->EOBRUN = 0;
  149544. emit_buffered_bits(entropy, entropy->bit_buffer, entropy->BE);
  149545. entropy->BE = 0;
  149546. }
  149547. }
  149548. LOCAL(void)
  149549. emit_restart_p (phuff_entropy_ptr entropy, int restart_num)
  149550. {
  149551. int ci;
  149552. emit_eobrun(entropy);
  149553. if (! entropy->gather_statistics) {
  149554. flush_bits_p(entropy);
  149555. emit_byte(entropy, 0xFF);
  149556. emit_byte(entropy, JPEG_RST0 + restart_num);
  149557. }
  149558. if (entropy->cinfo->Ss == 0) {
  149559. for (ci = 0; ci < entropy->cinfo->comps_in_scan; ci++)
  149560. entropy->last_dc_val[ci] = 0;
  149561. } else {
  149562. entropy->EOBRUN = 0;
  149563. entropy->BE = 0;
  149564. }
  149565. }
  149566. METHODDEF(boolean)
  149567. encode_mcu_DC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  149568. {
  149569. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149570. register int temp, temp2;
  149571. register int nbits;
  149572. int blkn, ci;
  149573. int Al = cinfo->Al;
  149574. JBLOCKROW block;
  149575. jpeg_component_info * compptr;
  149576. ISHIFT_TEMPS
  149577. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149578. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149579. if (cinfo->restart_interval)
  149580. if (entropy->restarts_to_go == 0)
  149581. emit_restart_p(entropy, entropy->next_restart_num);
  149582. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  149583. block = MCU_data[blkn];
  149584. ci = cinfo->MCU_membership[blkn];
  149585. compptr = cinfo->cur_comp_info[ci];
  149586. temp2 = IRIGHT_SHIFT((int) ((*block)[0]), Al);
  149587. temp = temp2 - entropy->last_dc_val[ci];
  149588. entropy->last_dc_val[ci] = temp2;
  149589. temp2 = temp;
  149590. if (temp < 0) {
  149591. temp = -temp; /* temp is abs value of input */
  149592. temp2--;
  149593. }
  149594. nbits = 0;
  149595. while (temp) {
  149596. nbits++;
  149597. temp >>= 1;
  149598. }
  149599. if (nbits > MAX_COEF_BITS+1)
  149600. ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  149601. emit_symbol(entropy, compptr->dc_tbl_no, nbits);
  149602. if (nbits) /* emit_bits rejects calls with size 0 */
  149603. emit_bits_p(entropy, (unsigned int) temp2, nbits);
  149604. }
  149605. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149606. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149607. if (cinfo->restart_interval) {
  149608. if (entropy->restarts_to_go == 0) {
  149609. entropy->restarts_to_go = cinfo->restart_interval;
  149610. entropy->next_restart_num++;
  149611. entropy->next_restart_num &= 7;
  149612. }
  149613. entropy->restarts_to_go--;
  149614. }
  149615. return TRUE;
  149616. }
  149617. METHODDEF(boolean)
  149618. encode_mcu_AC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  149619. {
  149620. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149621. register int temp, temp2;
  149622. register int nbits;
  149623. register int r, k;
  149624. int Se = cinfo->Se;
  149625. int Al = cinfo->Al;
  149626. JBLOCKROW block;
  149627. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149628. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149629. if (cinfo->restart_interval)
  149630. if (entropy->restarts_to_go == 0)
  149631. emit_restart_p(entropy, entropy->next_restart_num);
  149632. block = MCU_data[0];
  149633. r = 0; /* r = run length of zeros */
  149634. for (k = cinfo->Ss; k <= Se; k++) {
  149635. if ((temp = (*block)[jpeg_natural_order[k]]) == 0) {
  149636. r++;
  149637. continue;
  149638. }
  149639. if (temp < 0) {
  149640. temp = -temp; /* temp is abs value of input */
  149641. temp >>= Al; /* apply the point transform */
  149642. temp2 = ~temp;
  149643. } else {
  149644. temp >>= Al; /* apply the point transform */
  149645. temp2 = temp;
  149646. }
  149647. if (temp == 0) {
  149648. r++;
  149649. continue;
  149650. }
  149651. if (entropy->EOBRUN > 0)
  149652. emit_eobrun(entropy);
  149653. while (r > 15) {
  149654. emit_symbol(entropy, entropy->ac_tbl_no, 0xF0);
  149655. r -= 16;
  149656. }
  149657. nbits = 1; /* there must be at least one 1 bit */
  149658. while ((temp >>= 1))
  149659. nbits++;
  149660. if (nbits > MAX_COEF_BITS)
  149661. ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  149662. emit_symbol(entropy, entropy->ac_tbl_no, (r << 4) + nbits);
  149663. emit_bits_p(entropy, (unsigned int) temp2, nbits);
  149664. r = 0; /* reset zero run length */
  149665. }
  149666. if (r > 0) { /* If there are trailing zeroes, */
  149667. entropy->EOBRUN++; /* count an EOB */
  149668. if (entropy->EOBRUN == 0x7FFF)
  149669. emit_eobrun(entropy); /* force it out to avoid overflow */
  149670. }
  149671. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149672. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149673. if (cinfo->restart_interval) {
  149674. if (entropy->restarts_to_go == 0) {
  149675. entropy->restarts_to_go = cinfo->restart_interval;
  149676. entropy->next_restart_num++;
  149677. entropy->next_restart_num &= 7;
  149678. }
  149679. entropy->restarts_to_go--;
  149680. }
  149681. return TRUE;
  149682. }
  149683. METHODDEF(boolean)
  149684. encode_mcu_DC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  149685. {
  149686. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149687. register int temp;
  149688. int blkn;
  149689. int Al = cinfo->Al;
  149690. JBLOCKROW block;
  149691. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149692. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149693. if (cinfo->restart_interval)
  149694. if (entropy->restarts_to_go == 0)
  149695. emit_restart_p(entropy, entropy->next_restart_num);
  149696. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  149697. block = MCU_data[blkn];
  149698. temp = (*block)[0];
  149699. emit_bits_p(entropy, (unsigned int) (temp >> Al), 1);
  149700. }
  149701. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149702. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149703. if (cinfo->restart_interval) {
  149704. if (entropy->restarts_to_go == 0) {
  149705. entropy->restarts_to_go = cinfo->restart_interval;
  149706. entropy->next_restart_num++;
  149707. entropy->next_restart_num &= 7;
  149708. }
  149709. entropy->restarts_to_go--;
  149710. }
  149711. return TRUE;
  149712. }
  149713. METHODDEF(boolean)
  149714. encode_mcu_AC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  149715. {
  149716. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149717. register int temp;
  149718. register int r, k;
  149719. int EOB;
  149720. char *BR_buffer;
  149721. unsigned int BR;
  149722. int Se = cinfo->Se;
  149723. int Al = cinfo->Al;
  149724. JBLOCKROW block;
  149725. int absvalues[DCTSIZE2];
  149726. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149727. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149728. if (cinfo->restart_interval)
  149729. if (entropy->restarts_to_go == 0)
  149730. emit_restart_p(entropy, entropy->next_restart_num);
  149731. block = MCU_data[0];
  149732. EOB = 0;
  149733. for (k = cinfo->Ss; k <= Se; k++) {
  149734. temp = (*block)[jpeg_natural_order[k]];
  149735. if (temp < 0)
  149736. temp = -temp; /* temp is abs value of input */
  149737. temp >>= Al; /* apply the point transform */
  149738. absvalues[k] = temp; /* save abs value for main pass */
  149739. if (temp == 1)
  149740. EOB = k; /* EOB = index of last newly-nonzero coef */
  149741. }
  149742. r = 0; /* r = run length of zeros */
  149743. BR = 0; /* BR = count of buffered bits added now */
  149744. BR_buffer = entropy->bit_buffer + entropy->BE; /* Append bits to buffer */
  149745. for (k = cinfo->Ss; k <= Se; k++) {
  149746. if ((temp = absvalues[k]) == 0) {
  149747. r++;
  149748. continue;
  149749. }
  149750. while (r > 15 && k <= EOB) {
  149751. emit_eobrun(entropy);
  149752. emit_symbol(entropy, entropy->ac_tbl_no, 0xF0);
  149753. r -= 16;
  149754. emit_buffered_bits(entropy, BR_buffer, BR);
  149755. BR_buffer = entropy->bit_buffer; /* BE bits are gone now */
  149756. BR = 0;
  149757. }
  149758. if (temp > 1) {
  149759. BR_buffer[BR++] = (char) (temp & 1);
  149760. continue;
  149761. }
  149762. emit_eobrun(entropy);
  149763. emit_symbol(entropy, entropy->ac_tbl_no, (r << 4) + 1);
  149764. temp = ((*block)[jpeg_natural_order[k]] < 0) ? 0 : 1;
  149765. emit_bits_p(entropy, (unsigned int) temp, 1);
  149766. emit_buffered_bits(entropy, BR_buffer, BR);
  149767. BR_buffer = entropy->bit_buffer; /* BE bits are gone now */
  149768. BR = 0;
  149769. r = 0; /* reset zero run length */
  149770. }
  149771. if (r > 0 || BR > 0) { /* If there are trailing zeroes, */
  149772. entropy->EOBRUN++; /* count an EOB */
  149773. entropy->BE += BR; /* concat my correction bits to older ones */
  149774. if (entropy->EOBRUN == 0x7FFF || entropy->BE > (MAX_CORR_BITS-DCTSIZE2+1))
  149775. emit_eobrun(entropy);
  149776. }
  149777. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149778. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149779. if (cinfo->restart_interval) {
  149780. if (entropy->restarts_to_go == 0) {
  149781. entropy->restarts_to_go = cinfo->restart_interval;
  149782. entropy->next_restart_num++;
  149783. entropy->next_restart_num &= 7;
  149784. }
  149785. entropy->restarts_to_go--;
  149786. }
  149787. return TRUE;
  149788. }
  149789. METHODDEF(void)
  149790. finish_pass_phuff (j_compress_ptr cinfo)
  149791. {
  149792. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149793. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149794. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149795. emit_eobrun(entropy);
  149796. flush_bits_p(entropy);
  149797. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149798. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149799. }
  149800. METHODDEF(void)
  149801. finish_pass_gather_phuff (j_compress_ptr cinfo)
  149802. {
  149803. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149804. boolean is_DC_band;
  149805. int ci, tbl;
  149806. jpeg_component_info * compptr;
  149807. JHUFF_TBL **htblptr;
  149808. boolean did[NUM_HUFF_TBLS];
  149809. emit_eobrun(entropy);
  149810. is_DC_band = (cinfo->Ss == 0);
  149811. MEMZERO(did, SIZEOF(did));
  149812. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  149813. compptr = cinfo->cur_comp_info[ci];
  149814. if (is_DC_band) {
  149815. if (cinfo->Ah != 0) /* DC refinement needs no table */
  149816. continue;
  149817. tbl = compptr->dc_tbl_no;
  149818. } else {
  149819. tbl = compptr->ac_tbl_no;
  149820. }
  149821. if (! did[tbl]) {
  149822. if (is_DC_band)
  149823. htblptr = & cinfo->dc_huff_tbl_ptrs[tbl];
  149824. else
  149825. htblptr = & cinfo->ac_huff_tbl_ptrs[tbl];
  149826. if (*htblptr == NULL)
  149827. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  149828. jpeg_gen_optimal_table(cinfo, *htblptr, entropy->count_ptrs[tbl]);
  149829. did[tbl] = TRUE;
  149830. }
  149831. }
  149832. }
  149833. GLOBAL(void)
  149834. jinit_phuff_encoder (j_compress_ptr cinfo)
  149835. {
  149836. phuff_entropy_ptr entropy;
  149837. int i;
  149838. entropy = (phuff_entropy_ptr)
  149839. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149840. SIZEOF(phuff_entropy_encoder));
  149841. cinfo->entropy = (struct jpeg_entropy_encoder *) entropy;
  149842. entropy->pub.start_pass = start_pass_phuff;
  149843. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  149844. entropy->derived_tbls[i] = NULL;
  149845. entropy->count_ptrs[i] = NULL;
  149846. }
  149847. entropy->bit_buffer = NULL; /* needed only in AC refinement scan */
  149848. }
  149849. #endif /* C_PROGRESSIVE_SUPPORTED */
  149850. /*** End of inlined file: jcphuff.c ***/
  149851. /*** Start of inlined file: jcprepct.c ***/
  149852. #define JPEG_INTERNALS
  149853. #ifdef INPUT_SMOOTHING_SUPPORTED
  149854. #define CONTEXT_ROWS_SUPPORTED
  149855. #endif
  149856. typedef struct {
  149857. struct jpeg_c_prep_controller pub; /* public fields */
  149858. JSAMPARRAY color_buf[MAX_COMPONENTS];
  149859. JDIMENSION rows_to_go; /* counts rows remaining in source image */
  149860. int next_buf_row; /* index of next row to store in color_buf */
  149861. #ifdef CONTEXT_ROWS_SUPPORTED /* only needed for context case */
  149862. int this_row_group; /* starting row index of group to process */
  149863. int next_buf_stop; /* downsample when we reach this index */
  149864. #endif
  149865. } my_prep_controller;
  149866. typedef my_prep_controller * my_prep_ptr;
  149867. METHODDEF(void)
  149868. start_pass_prep (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
  149869. {
  149870. my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
  149871. if (pass_mode != JBUF_PASS_THRU)
  149872. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  149873. prep->rows_to_go = cinfo->image_height;
  149874. prep->next_buf_row = 0;
  149875. #ifdef CONTEXT_ROWS_SUPPORTED
  149876. prep->this_row_group = 0;
  149877. prep->next_buf_stop = 2 * cinfo->max_v_samp_factor;
  149878. #endif
  149879. }
  149880. LOCAL(void)
  149881. expand_bottom_edge (JSAMPARRAY image_data, JDIMENSION num_cols,
  149882. int input_rows, int output_rows)
  149883. {
  149884. register int row;
  149885. for (row = input_rows; row < output_rows; row++) {
  149886. jcopy_sample_rows(image_data, input_rows-1, image_data, row,
  149887. 1, num_cols);
  149888. }
  149889. }
  149890. METHODDEF(void)
  149891. pre_process_data (j_compress_ptr cinfo,
  149892. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  149893. JDIMENSION in_rows_avail,
  149894. JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr,
  149895. JDIMENSION out_row_groups_avail)
  149896. {
  149897. my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
  149898. int numrows, ci;
  149899. JDIMENSION inrows;
  149900. jpeg_component_info * compptr;
  149901. while (*in_row_ctr < in_rows_avail &&
  149902. *out_row_group_ctr < out_row_groups_avail) {
  149903. inrows = in_rows_avail - *in_row_ctr;
  149904. numrows = cinfo->max_v_samp_factor - prep->next_buf_row;
  149905. numrows = (int) MIN((JDIMENSION) numrows, inrows);
  149906. (*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr,
  149907. prep->color_buf,
  149908. (JDIMENSION) prep->next_buf_row,
  149909. numrows);
  149910. *in_row_ctr += numrows;
  149911. prep->next_buf_row += numrows;
  149912. prep->rows_to_go -= numrows;
  149913. if (prep->rows_to_go == 0 &&
  149914. prep->next_buf_row < cinfo->max_v_samp_factor) {
  149915. for (ci = 0; ci < cinfo->num_components; ci++) {
  149916. expand_bottom_edge(prep->color_buf[ci], cinfo->image_width,
  149917. prep->next_buf_row, cinfo->max_v_samp_factor);
  149918. }
  149919. prep->next_buf_row = cinfo->max_v_samp_factor;
  149920. }
  149921. if (prep->next_buf_row == cinfo->max_v_samp_factor) {
  149922. (*cinfo->downsample->downsample) (cinfo,
  149923. prep->color_buf, (JDIMENSION) 0,
  149924. output_buf, *out_row_group_ctr);
  149925. prep->next_buf_row = 0;
  149926. (*out_row_group_ctr)++;
  149927. }
  149928. if (prep->rows_to_go == 0 &&
  149929. *out_row_group_ctr < out_row_groups_avail) {
  149930. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  149931. ci++, compptr++) {
  149932. expand_bottom_edge(output_buf[ci],
  149933. compptr->width_in_blocks * DCTSIZE,
  149934. (int) (*out_row_group_ctr * compptr->v_samp_factor),
  149935. (int) (out_row_groups_avail * compptr->v_samp_factor));
  149936. }
  149937. *out_row_group_ctr = out_row_groups_avail;
  149938. break; /* can exit outer loop without test */
  149939. }
  149940. }
  149941. }
  149942. #ifdef CONTEXT_ROWS_SUPPORTED
  149943. METHODDEF(void)
  149944. pre_process_context (j_compress_ptr cinfo,
  149945. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  149946. JDIMENSION in_rows_avail,
  149947. JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr,
  149948. JDIMENSION out_row_groups_avail)
  149949. {
  149950. my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
  149951. int numrows, ci;
  149952. int buf_height = cinfo->max_v_samp_factor * 3;
  149953. JDIMENSION inrows;
  149954. while (*out_row_group_ctr < out_row_groups_avail) {
  149955. if (*in_row_ctr < in_rows_avail) {
  149956. inrows = in_rows_avail - *in_row_ctr;
  149957. numrows = prep->next_buf_stop - prep->next_buf_row;
  149958. numrows = (int) MIN((JDIMENSION) numrows, inrows);
  149959. (*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr,
  149960. prep->color_buf,
  149961. (JDIMENSION) prep->next_buf_row,
  149962. numrows);
  149963. if (prep->rows_to_go == cinfo->image_height) {
  149964. for (ci = 0; ci < cinfo->num_components; ci++) {
  149965. int row;
  149966. for (row = 1; row <= cinfo->max_v_samp_factor; row++) {
  149967. jcopy_sample_rows(prep->color_buf[ci], 0,
  149968. prep->color_buf[ci], -row,
  149969. 1, cinfo->image_width);
  149970. }
  149971. }
  149972. }
  149973. *in_row_ctr += numrows;
  149974. prep->next_buf_row += numrows;
  149975. prep->rows_to_go -= numrows;
  149976. } else {
  149977. if (prep->rows_to_go != 0)
  149978. break;
  149979. if (prep->next_buf_row < prep->next_buf_stop) {
  149980. for (ci = 0; ci < cinfo->num_components; ci++) {
  149981. expand_bottom_edge(prep->color_buf[ci], cinfo->image_width,
  149982. prep->next_buf_row, prep->next_buf_stop);
  149983. }
  149984. prep->next_buf_row = prep->next_buf_stop;
  149985. }
  149986. }
  149987. if (prep->next_buf_row == prep->next_buf_stop) {
  149988. (*cinfo->downsample->downsample) (cinfo,
  149989. prep->color_buf,
  149990. (JDIMENSION) prep->this_row_group,
  149991. output_buf, *out_row_group_ctr);
  149992. (*out_row_group_ctr)++;
  149993. prep->this_row_group += cinfo->max_v_samp_factor;
  149994. if (prep->this_row_group >= buf_height)
  149995. prep->this_row_group = 0;
  149996. if (prep->next_buf_row >= buf_height)
  149997. prep->next_buf_row = 0;
  149998. prep->next_buf_stop = prep->next_buf_row + cinfo->max_v_samp_factor;
  149999. }
  150000. }
  150001. }
  150002. LOCAL(void)
  150003. create_context_buffer (j_compress_ptr cinfo)
  150004. {
  150005. my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
  150006. int rgroup_height = cinfo->max_v_samp_factor;
  150007. int ci, i;
  150008. jpeg_component_info * compptr;
  150009. JSAMPARRAY true_buffer, fake_buffer;
  150010. fake_buffer = (JSAMPARRAY)
  150011. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  150012. (cinfo->num_components * 5 * rgroup_height) *
  150013. SIZEOF(JSAMPROW));
  150014. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  150015. ci++, compptr++) {
  150016. true_buffer = (*cinfo->mem->alloc_sarray)
  150017. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  150018. (JDIMENSION) (((long) compptr->width_in_blocks * DCTSIZE *
  150019. cinfo->max_h_samp_factor) / compptr->h_samp_factor),
  150020. (JDIMENSION) (3 * rgroup_height));
  150021. MEMCOPY(fake_buffer + rgroup_height, true_buffer,
  150022. 3 * rgroup_height * SIZEOF(JSAMPROW));
  150023. for (i = 0; i < rgroup_height; i++) {
  150024. fake_buffer[i] = true_buffer[2 * rgroup_height + i];
  150025. fake_buffer[4 * rgroup_height + i] = true_buffer[i];
  150026. }
  150027. prep->color_buf[ci] = fake_buffer + rgroup_height;
  150028. fake_buffer += 5 * rgroup_height; /* point to space for next component */
  150029. }
  150030. }
  150031. #endif /* CONTEXT_ROWS_SUPPORTED */
  150032. GLOBAL(void)
  150033. jinit_c_prep_controller (j_compress_ptr cinfo, boolean need_full_buffer)
  150034. {
  150035. my_prep_ptr prep;
  150036. int ci;
  150037. jpeg_component_info * compptr;
  150038. if (need_full_buffer) /* safety check */
  150039. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  150040. prep = (my_prep_ptr)
  150041. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  150042. SIZEOF(my_prep_controller));
  150043. cinfo->prep = (struct jpeg_c_prep_controller *) prep;
  150044. prep->pub.start_pass = start_pass_prep;
  150045. if (cinfo->downsample->need_context_rows) {
  150046. #ifdef CONTEXT_ROWS_SUPPORTED
  150047. prep->pub.pre_process_data = pre_process_context;
  150048. create_context_buffer(cinfo);
  150049. #else
  150050. ERREXIT(cinfo, JERR_NOT_COMPILED);
  150051. #endif
  150052. } else {
  150053. prep->pub.pre_process_data = pre_process_data;
  150054. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  150055. ci++, compptr++) {
  150056. prep->color_buf[ci] = (*cinfo->mem->alloc_sarray)
  150057. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  150058. (JDIMENSION) (((long) compptr->width_in_blocks * DCTSIZE *
  150059. cinfo->max_h_samp_factor) / compptr->h_samp_factor),
  150060. (JDIMENSION) cinfo->max_v_samp_factor);
  150061. }
  150062. }
  150063. }
  150064. /*** End of inlined file: jcprepct.c ***/
  150065. /*** Start of inlined file: jcsample.c ***/
  150066. #define JPEG_INTERNALS
  150067. typedef JMETHOD(void, downsample1_ptr,
  150068. (j_compress_ptr cinfo, jpeg_component_info * compptr,
  150069. JSAMPARRAY input_data, JSAMPARRAY output_data));
  150070. typedef struct {
  150071. struct jpeg_downsampler pub; /* public fields */
  150072. downsample1_ptr methods[MAX_COMPONENTS];
  150073. } my_downsampler;
  150074. typedef my_downsampler * my_downsample_ptr;
  150075. METHODDEF(void)
  150076. start_pass_downsample (j_compress_ptr cinfo)
  150077. {
  150078. }
  150079. LOCAL(void)
  150080. expand_right_edge (JSAMPARRAY image_data, int num_rows,
  150081. JDIMENSION input_cols, JDIMENSION output_cols)
  150082. {
  150083. register JSAMPROW ptr;
  150084. register JSAMPLE pixval;
  150085. register int count;
  150086. int row;
  150087. int numcols = (int) (output_cols - input_cols);
  150088. if (numcols > 0) {
  150089. for (row = 0; row < num_rows; row++) {
  150090. ptr = image_data[row] + input_cols;
  150091. pixval = ptr[-1]; /* don't need GETJSAMPLE() here */
  150092. for (count = numcols; count > 0; count--)
  150093. *ptr++ = pixval;
  150094. }
  150095. }
  150096. }
  150097. METHODDEF(void)
  150098. sep_downsample (j_compress_ptr cinfo,
  150099. JSAMPIMAGE input_buf, JDIMENSION in_row_index,
  150100. JSAMPIMAGE output_buf, JDIMENSION out_row_group_index)
  150101. {
  150102. my_downsample_ptr downsample = (my_downsample_ptr) cinfo->downsample;
  150103. int ci;
  150104. jpeg_component_info * compptr;
  150105. JSAMPARRAY in_ptr, out_ptr;
  150106. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  150107. ci++, compptr++) {
  150108. in_ptr = input_buf[ci] + in_row_index;
  150109. out_ptr = output_buf[ci] + (out_row_group_index * compptr->v_samp_factor);
  150110. (*downsample->methods[ci]) (cinfo, compptr, in_ptr, out_ptr);
  150111. }
  150112. }
  150113. METHODDEF(void)
  150114. int_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  150115. JSAMPARRAY input_data, JSAMPARRAY output_data)
  150116. {
  150117. int inrow, outrow, h_expand, v_expand, numpix, numpix2, h, v;
  150118. JDIMENSION outcol, outcol_h; /* outcol_h == outcol*h_expand */
  150119. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  150120. JSAMPROW inptr, outptr;
  150121. INT32 outvalue;
  150122. h_expand = cinfo->max_h_samp_factor / compptr->h_samp_factor;
  150123. v_expand = cinfo->max_v_samp_factor / compptr->v_samp_factor;
  150124. numpix = h_expand * v_expand;
  150125. numpix2 = numpix/2;
  150126. expand_right_edge(input_data, cinfo->max_v_samp_factor,
  150127. cinfo->image_width, output_cols * h_expand);
  150128. inrow = 0;
  150129. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  150130. outptr = output_data[outrow];
  150131. for (outcol = 0, outcol_h = 0; outcol < output_cols;
  150132. outcol++, outcol_h += h_expand) {
  150133. outvalue = 0;
  150134. for (v = 0; v < v_expand; v++) {
  150135. inptr = input_data[inrow+v] + outcol_h;
  150136. for (h = 0; h < h_expand; h++) {
  150137. outvalue += (INT32) GETJSAMPLE(*inptr++);
  150138. }
  150139. }
  150140. *outptr++ = (JSAMPLE) ((outvalue + numpix2) / numpix);
  150141. }
  150142. inrow += v_expand;
  150143. }
  150144. }
  150145. METHODDEF(void)
  150146. fullsize_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  150147. JSAMPARRAY input_data, JSAMPARRAY output_data)
  150148. {
  150149. jcopy_sample_rows(input_data, 0, output_data, 0,
  150150. cinfo->max_v_samp_factor, cinfo->image_width);
  150151. expand_right_edge(output_data, cinfo->max_v_samp_factor,
  150152. cinfo->image_width, compptr->width_in_blocks * DCTSIZE);
  150153. }
  150154. METHODDEF(void)
  150155. h2v1_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  150156. JSAMPARRAY input_data, JSAMPARRAY output_data)
  150157. {
  150158. int outrow;
  150159. JDIMENSION outcol;
  150160. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  150161. register JSAMPROW inptr, outptr;
  150162. register int bias;
  150163. expand_right_edge(input_data, cinfo->max_v_samp_factor,
  150164. cinfo->image_width, output_cols * 2);
  150165. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  150166. outptr = output_data[outrow];
  150167. inptr = input_data[outrow];
  150168. bias = 0; /* bias = 0,1,0,1,... for successive samples */
  150169. for (outcol = 0; outcol < output_cols; outcol++) {
  150170. *outptr++ = (JSAMPLE) ((GETJSAMPLE(*inptr) + GETJSAMPLE(inptr[1])
  150171. + bias) >> 1);
  150172. bias ^= 1; /* 0=>1, 1=>0 */
  150173. inptr += 2;
  150174. }
  150175. }
  150176. }
  150177. METHODDEF(void)
  150178. h2v2_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  150179. JSAMPARRAY input_data, JSAMPARRAY output_data)
  150180. {
  150181. int inrow, outrow;
  150182. JDIMENSION outcol;
  150183. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  150184. register JSAMPROW inptr0, inptr1, outptr;
  150185. register int bias;
  150186. expand_right_edge(input_data, cinfo->max_v_samp_factor,
  150187. cinfo->image_width, output_cols * 2);
  150188. inrow = 0;
  150189. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  150190. outptr = output_data[outrow];
  150191. inptr0 = input_data[inrow];
  150192. inptr1 = input_data[inrow+1];
  150193. bias = 1; /* bias = 1,2,1,2,... for successive samples */
  150194. for (outcol = 0; outcol < output_cols; outcol++) {
  150195. *outptr++ = (JSAMPLE) ((GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  150196. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1])
  150197. + bias) >> 2);
  150198. bias ^= 3; /* 1=>2, 2=>1 */
  150199. inptr0 += 2; inptr1 += 2;
  150200. }
  150201. inrow += 2;
  150202. }
  150203. }
  150204. #ifdef INPUT_SMOOTHING_SUPPORTED
  150205. METHODDEF(void)
  150206. h2v2_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  150207. JSAMPARRAY input_data, JSAMPARRAY output_data)
  150208. {
  150209. int inrow, outrow;
  150210. JDIMENSION colctr;
  150211. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  150212. register JSAMPROW inptr0, inptr1, above_ptr, below_ptr, outptr;
  150213. INT32 membersum, neighsum, memberscale, neighscale;
  150214. expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2,
  150215. cinfo->image_width, output_cols * 2);
  150216. memberscale = 16384 - cinfo->smoothing_factor * 80; /* scaled (1-5*SF)/4 */
  150217. neighscale = cinfo->smoothing_factor * 16; /* scaled SF/4 */
  150218. inrow = 0;
  150219. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  150220. outptr = output_data[outrow];
  150221. inptr0 = input_data[inrow];
  150222. inptr1 = input_data[inrow+1];
  150223. above_ptr = input_data[inrow-1];
  150224. below_ptr = input_data[inrow+2];
  150225. membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  150226. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
  150227. neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
  150228. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
  150229. GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[2]) +
  150230. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[2]);
  150231. neighsum += neighsum;
  150232. neighsum += GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[2]) +
  150233. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[2]);
  150234. membersum = membersum * memberscale + neighsum * neighscale;
  150235. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  150236. inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2;
  150237. for (colctr = output_cols - 2; colctr > 0; colctr--) {
  150238. membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  150239. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
  150240. neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
  150241. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
  150242. GETJSAMPLE(inptr0[-1]) + GETJSAMPLE(inptr0[2]) +
  150243. GETJSAMPLE(inptr1[-1]) + GETJSAMPLE(inptr1[2]);
  150244. neighsum += neighsum;
  150245. neighsum += GETJSAMPLE(above_ptr[-1]) + GETJSAMPLE(above_ptr[2]) +
  150246. GETJSAMPLE(below_ptr[-1]) + GETJSAMPLE(below_ptr[2]);
  150247. membersum = membersum * memberscale + neighsum * neighscale;
  150248. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  150249. inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2;
  150250. }
  150251. membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  150252. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
  150253. neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
  150254. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
  150255. GETJSAMPLE(inptr0[-1]) + GETJSAMPLE(inptr0[1]) +
  150256. GETJSAMPLE(inptr1[-1]) + GETJSAMPLE(inptr1[1]);
  150257. neighsum += neighsum;
  150258. neighsum += GETJSAMPLE(above_ptr[-1]) + GETJSAMPLE(above_ptr[1]) +
  150259. GETJSAMPLE(below_ptr[-1]) + GETJSAMPLE(below_ptr[1]);
  150260. membersum = membersum * memberscale + neighsum * neighscale;
  150261. *outptr = (JSAMPLE) ((membersum + 32768) >> 16);
  150262. inrow += 2;
  150263. }
  150264. }
  150265. METHODDEF(void)
  150266. fullsize_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info *compptr,
  150267. JSAMPARRAY input_data, JSAMPARRAY output_data)
  150268. {
  150269. int outrow;
  150270. JDIMENSION colctr;
  150271. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  150272. register JSAMPROW inptr, above_ptr, below_ptr, outptr;
  150273. INT32 membersum, neighsum, memberscale, neighscale;
  150274. int colsum, lastcolsum, nextcolsum;
  150275. expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2,
  150276. cinfo->image_width, output_cols);
  150277. memberscale = 65536L - cinfo->smoothing_factor * 512L; /* scaled 1-8*SF */
  150278. neighscale = cinfo->smoothing_factor * 64; /* scaled SF */
  150279. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  150280. outptr = output_data[outrow];
  150281. inptr = input_data[outrow];
  150282. above_ptr = input_data[outrow-1];
  150283. below_ptr = input_data[outrow+1];
  150284. colsum = GETJSAMPLE(*above_ptr++) + GETJSAMPLE(*below_ptr++) +
  150285. GETJSAMPLE(*inptr);
  150286. membersum = GETJSAMPLE(*inptr++);
  150287. nextcolsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(*below_ptr) +
  150288. GETJSAMPLE(*inptr);
  150289. neighsum = colsum + (colsum - membersum) + nextcolsum;
  150290. membersum = membersum * memberscale + neighsum * neighscale;
  150291. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  150292. lastcolsum = colsum; colsum = nextcolsum;
  150293. for (colctr = output_cols - 2; colctr > 0; colctr--) {
  150294. membersum = GETJSAMPLE(*inptr++);
  150295. above_ptr++; below_ptr++;
  150296. nextcolsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(*below_ptr) +
  150297. GETJSAMPLE(*inptr);
  150298. neighsum = lastcolsum + (colsum - membersum) + nextcolsum;
  150299. membersum = membersum * memberscale + neighsum * neighscale;
  150300. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  150301. lastcolsum = colsum; colsum = nextcolsum;
  150302. }
  150303. membersum = GETJSAMPLE(*inptr);
  150304. neighsum = lastcolsum + (colsum - membersum) + colsum;
  150305. membersum = membersum * memberscale + neighsum * neighscale;
  150306. *outptr = (JSAMPLE) ((membersum + 32768) >> 16);
  150307. }
  150308. }
  150309. #endif /* INPUT_SMOOTHING_SUPPORTED */
  150310. GLOBAL(void)
  150311. jinit_downsampler (j_compress_ptr cinfo)
  150312. {
  150313. my_downsample_ptr downsample;
  150314. int ci;
  150315. jpeg_component_info * compptr;
  150316. boolean smoothok = TRUE;
  150317. downsample = (my_downsample_ptr)
  150318. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  150319. SIZEOF(my_downsampler));
  150320. cinfo->downsample = (struct jpeg_downsampler *) downsample;
  150321. downsample->pub.start_pass = start_pass_downsample;
  150322. downsample->pub.downsample = sep_downsample;
  150323. downsample->pub.need_context_rows = FALSE;
  150324. if (cinfo->CCIR601_sampling)
  150325. ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);
  150326. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  150327. ci++, compptr++) {
  150328. if (compptr->h_samp_factor == cinfo->max_h_samp_factor &&
  150329. compptr->v_samp_factor == cinfo->max_v_samp_factor) {
  150330. #ifdef INPUT_SMOOTHING_SUPPORTED
  150331. if (cinfo->smoothing_factor) {
  150332. downsample->methods[ci] = fullsize_smooth_downsample;
  150333. downsample->pub.need_context_rows = TRUE;
  150334. } else
  150335. #endif
  150336. downsample->methods[ci] = fullsize_downsample;
  150337. } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
  150338. compptr->v_samp_factor == cinfo->max_v_samp_factor) {
  150339. smoothok = FALSE;
  150340. downsample->methods[ci] = h2v1_downsample;
  150341. } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
  150342. compptr->v_samp_factor * 2 == cinfo->max_v_samp_factor) {
  150343. #ifdef INPUT_SMOOTHING_SUPPORTED
  150344. if (cinfo->smoothing_factor) {
  150345. downsample->methods[ci] = h2v2_smooth_downsample;
  150346. downsample->pub.need_context_rows = TRUE;
  150347. } else
  150348. #endif
  150349. downsample->methods[ci] = h2v2_downsample;
  150350. } else if ((cinfo->max_h_samp_factor % compptr->h_samp_factor) == 0 &&
  150351. (cinfo->max_v_samp_factor % compptr->v_samp_factor) == 0) {
  150352. smoothok = FALSE;
  150353. downsample->methods[ci] = int_downsample;
  150354. } else
  150355. ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
  150356. }
  150357. #ifdef INPUT_SMOOTHING_SUPPORTED
  150358. if (cinfo->smoothing_factor && !smoothok)
  150359. TRACEMS(cinfo, 0, JTRC_SMOOTH_NOTIMPL);
  150360. #endif
  150361. }
  150362. /*** End of inlined file: jcsample.c ***/
  150363. /*** Start of inlined file: jctrans.c ***/
  150364. #define JPEG_INTERNALS
  150365. LOCAL(void) transencode_master_selection
  150366. JPP((j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays));
  150367. LOCAL(void) transencode_coef_controller
  150368. JPP((j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays));
  150369. GLOBAL(void)
  150370. jpeg_write_coefficients (j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays)
  150371. {
  150372. if (cinfo->global_state != CSTATE_START)
  150373. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150374. jpeg_suppress_tables(cinfo, FALSE);
  150375. (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  150376. (*cinfo->dest->init_destination) (cinfo);
  150377. transencode_master_selection(cinfo, coef_arrays);
  150378. cinfo->next_scanline = 0; /* so jpeg_write_marker works */
  150379. cinfo->global_state = CSTATE_WRCOEFS;
  150380. }
  150381. GLOBAL(void)
  150382. jpeg_copy_critical_parameters (j_decompress_ptr srcinfo,
  150383. j_compress_ptr dstinfo)
  150384. {
  150385. JQUANT_TBL ** qtblptr;
  150386. jpeg_component_info *incomp, *outcomp;
  150387. JQUANT_TBL *c_quant, *slot_quant;
  150388. int tblno, ci, coefi;
  150389. if (dstinfo->global_state != CSTATE_START)
  150390. ERREXIT1(dstinfo, JERR_BAD_STATE, dstinfo->global_state);
  150391. dstinfo->image_width = srcinfo->image_width;
  150392. dstinfo->image_height = srcinfo->image_height;
  150393. dstinfo->input_components = srcinfo->num_components;
  150394. dstinfo->in_color_space = srcinfo->jpeg_color_space;
  150395. jpeg_set_defaults(dstinfo);
  150396. jpeg_set_colorspace(dstinfo, srcinfo->jpeg_color_space);
  150397. dstinfo->data_precision = srcinfo->data_precision;
  150398. dstinfo->CCIR601_sampling = srcinfo->CCIR601_sampling;
  150399. for (tblno = 0; tblno < NUM_QUANT_TBLS; tblno++) {
  150400. if (srcinfo->quant_tbl_ptrs[tblno] != NULL) {
  150401. qtblptr = & dstinfo->quant_tbl_ptrs[tblno];
  150402. if (*qtblptr == NULL)
  150403. *qtblptr = jpeg_alloc_quant_table((j_common_ptr) dstinfo);
  150404. MEMCOPY((*qtblptr)->quantval,
  150405. srcinfo->quant_tbl_ptrs[tblno]->quantval,
  150406. SIZEOF((*qtblptr)->quantval));
  150407. (*qtblptr)->sent_table = FALSE;
  150408. }
  150409. }
  150410. dstinfo->num_components = srcinfo->num_components;
  150411. if (dstinfo->num_components < 1 || dstinfo->num_components > MAX_COMPONENTS)
  150412. ERREXIT2(dstinfo, JERR_COMPONENT_COUNT, dstinfo->num_components,
  150413. MAX_COMPONENTS);
  150414. for (ci = 0, incomp = srcinfo->comp_info, outcomp = dstinfo->comp_info;
  150415. ci < dstinfo->num_components; ci++, incomp++, outcomp++) {
  150416. outcomp->component_id = incomp->component_id;
  150417. outcomp->h_samp_factor = incomp->h_samp_factor;
  150418. outcomp->v_samp_factor = incomp->v_samp_factor;
  150419. outcomp->quant_tbl_no = incomp->quant_tbl_no;
  150420. tblno = outcomp->quant_tbl_no;
  150421. if (tblno < 0 || tblno >= NUM_QUANT_TBLS ||
  150422. srcinfo->quant_tbl_ptrs[tblno] == NULL)
  150423. ERREXIT1(dstinfo, JERR_NO_QUANT_TABLE, tblno);
  150424. slot_quant = srcinfo->quant_tbl_ptrs[tblno];
  150425. c_quant = incomp->quant_table;
  150426. if (c_quant != NULL) {
  150427. for (coefi = 0; coefi < DCTSIZE2; coefi++) {
  150428. if (c_quant->quantval[coefi] != slot_quant->quantval[coefi])
  150429. ERREXIT1(dstinfo, JERR_MISMATCHED_QUANT_TABLE, tblno);
  150430. }
  150431. }
  150432. }
  150433. if (srcinfo->saw_JFIF_marker) {
  150434. if (srcinfo->JFIF_major_version == 1) {
  150435. dstinfo->JFIF_major_version = srcinfo->JFIF_major_version;
  150436. dstinfo->JFIF_minor_version = srcinfo->JFIF_minor_version;
  150437. }
  150438. dstinfo->density_unit = srcinfo->density_unit;
  150439. dstinfo->X_density = srcinfo->X_density;
  150440. dstinfo->Y_density = srcinfo->Y_density;
  150441. }
  150442. }
  150443. LOCAL(void)
  150444. transencode_master_selection (j_compress_ptr cinfo,
  150445. jvirt_barray_ptr * coef_arrays)
  150446. {
  150447. cinfo->input_components = 1;
  150448. jinit_c_master_control(cinfo, TRUE /* transcode only */);
  150449. if (cinfo->arith_code) {
  150450. ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
  150451. } else {
  150452. if (cinfo->progressive_mode) {
  150453. #ifdef C_PROGRESSIVE_SUPPORTED
  150454. jinit_phuff_encoder(cinfo);
  150455. #else
  150456. ERREXIT(cinfo, JERR_NOT_COMPILED);
  150457. #endif
  150458. } else
  150459. jinit_huff_encoder(cinfo);
  150460. }
  150461. transencode_coef_controller(cinfo, coef_arrays);
  150462. jinit_marker_writer(cinfo);
  150463. (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
  150464. (*cinfo->marker->write_file_header) (cinfo);
  150465. }
  150466. typedef struct {
  150467. struct jpeg_c_coef_controller pub; /* public fields */
  150468. JDIMENSION iMCU_row_num; /* iMCU row # within image */
  150469. JDIMENSION mcu_ctr; /* counts MCUs processed in current row */
  150470. int MCU_vert_offset; /* counts MCU rows within iMCU row */
  150471. int MCU_rows_per_iMCU_row; /* number of such rows needed */
  150472. jvirt_barray_ptr * whole_image;
  150473. JBLOCKROW dummy_buffer[C_MAX_BLOCKS_IN_MCU];
  150474. } my_coef_controller2;
  150475. typedef my_coef_controller2 * my_coef_ptr2;
  150476. LOCAL(void)
  150477. start_iMCU_row2 (j_compress_ptr cinfo)
  150478. {
  150479. my_coef_ptr2 coef = (my_coef_ptr2) cinfo->coef;
  150480. if (cinfo->comps_in_scan > 1) {
  150481. coef->MCU_rows_per_iMCU_row = 1;
  150482. } else {
  150483. if (coef->iMCU_row_num < (cinfo->total_iMCU_rows-1))
  150484. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
  150485. else
  150486. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
  150487. }
  150488. coef->mcu_ctr = 0;
  150489. coef->MCU_vert_offset = 0;
  150490. }
  150491. METHODDEF(void)
  150492. start_pass_coef2 (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
  150493. {
  150494. my_coef_ptr2 coef = (my_coef_ptr2) cinfo->coef;
  150495. if (pass_mode != JBUF_CRANK_DEST)
  150496. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  150497. coef->iMCU_row_num = 0;
  150498. start_iMCU_row2(cinfo);
  150499. }
  150500. METHODDEF(boolean)
  150501. compress_output2 (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  150502. {
  150503. my_coef_ptr2 coef = (my_coef_ptr2) cinfo->coef;
  150504. JDIMENSION MCU_col_num; /* index of current MCU within row */
  150505. JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
  150506. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  150507. int blkn, ci, xindex, yindex, yoffset, blockcnt;
  150508. JDIMENSION start_col;
  150509. JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
  150510. JBLOCKROW MCU_buffer[C_MAX_BLOCKS_IN_MCU];
  150511. JBLOCKROW buffer_ptr;
  150512. jpeg_component_info *compptr;
  150513. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  150514. compptr = cinfo->cur_comp_info[ci];
  150515. buffer[ci] = (*cinfo->mem->access_virt_barray)
  150516. ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index],
  150517. coef->iMCU_row_num * compptr->v_samp_factor,
  150518. (JDIMENSION) compptr->v_samp_factor, FALSE);
  150519. }
  150520. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  150521. yoffset++) {
  150522. for (MCU_col_num = coef->mcu_ctr; MCU_col_num < cinfo->MCUs_per_row;
  150523. MCU_col_num++) {
  150524. blkn = 0; /* index of current DCT block within MCU */
  150525. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  150526. compptr = cinfo->cur_comp_info[ci];
  150527. start_col = MCU_col_num * compptr->MCU_width;
  150528. blockcnt = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
  150529. : compptr->last_col_width;
  150530. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  150531. if (coef->iMCU_row_num < last_iMCU_row ||
  150532. yindex+yoffset < compptr->last_row_height) {
  150533. buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
  150534. for (xindex = 0; xindex < blockcnt; xindex++)
  150535. MCU_buffer[blkn++] = buffer_ptr++;
  150536. } else {
  150537. xindex = 0;
  150538. }
  150539. for (; xindex < compptr->MCU_width; xindex++) {
  150540. MCU_buffer[blkn] = coef->dummy_buffer[blkn];
  150541. MCU_buffer[blkn][0][0] = MCU_buffer[blkn-1][0][0];
  150542. blkn++;
  150543. }
  150544. }
  150545. }
  150546. if (! (*cinfo->entropy->encode_mcu) (cinfo, MCU_buffer)) {
  150547. coef->MCU_vert_offset = yoffset;
  150548. coef->mcu_ctr = MCU_col_num;
  150549. return FALSE;
  150550. }
  150551. }
  150552. coef->mcu_ctr = 0;
  150553. }
  150554. coef->iMCU_row_num++;
  150555. start_iMCU_row2(cinfo);
  150556. return TRUE;
  150557. }
  150558. LOCAL(void)
  150559. transencode_coef_controller (j_compress_ptr cinfo,
  150560. jvirt_barray_ptr * coef_arrays)
  150561. {
  150562. my_coef_ptr2 coef;
  150563. JBLOCKROW buffer;
  150564. int i;
  150565. coef = (my_coef_ptr2)
  150566. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  150567. SIZEOF(my_coef_controller2));
  150568. cinfo->coef = (struct jpeg_c_coef_controller *) coef;
  150569. coef->pub.start_pass = start_pass_coef2;
  150570. coef->pub.compress_data = compress_output2;
  150571. coef->whole_image = coef_arrays;
  150572. buffer = (JBLOCKROW)
  150573. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  150574. C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
  150575. jzero_far((void FAR *) buffer, C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
  150576. for (i = 0; i < C_MAX_BLOCKS_IN_MCU; i++) {
  150577. coef->dummy_buffer[i] = buffer + i;
  150578. }
  150579. }
  150580. /*** End of inlined file: jctrans.c ***/
  150581. /*** Start of inlined file: jdapistd.c ***/
  150582. #define JPEG_INTERNALS
  150583. LOCAL(boolean) output_pass_setup JPP((j_decompress_ptr cinfo));
  150584. GLOBAL(boolean)
  150585. jpeg_start_decompress (j_decompress_ptr cinfo)
  150586. {
  150587. if (cinfo->global_state == DSTATE_READY) {
  150588. jinit_master_decompress(cinfo);
  150589. if (cinfo->buffered_image) {
  150590. cinfo->global_state = DSTATE_BUFIMAGE;
  150591. return TRUE;
  150592. }
  150593. cinfo->global_state = DSTATE_PRELOAD;
  150594. }
  150595. if (cinfo->global_state == DSTATE_PRELOAD) {
  150596. if (cinfo->inputctl->has_multiple_scans) {
  150597. #ifdef D_MULTISCAN_FILES_SUPPORTED
  150598. for (;;) {
  150599. int retcode;
  150600. if (cinfo->progress != NULL)
  150601. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  150602. retcode = (*cinfo->inputctl->consume_input) (cinfo);
  150603. if (retcode == JPEG_SUSPENDED)
  150604. return FALSE;
  150605. if (retcode == JPEG_REACHED_EOI)
  150606. break;
  150607. if (cinfo->progress != NULL &&
  150608. (retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) {
  150609. if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) {
  150610. cinfo->progress->pass_limit += (long) cinfo->total_iMCU_rows;
  150611. }
  150612. }
  150613. }
  150614. #else
  150615. ERREXIT(cinfo, JERR_NOT_COMPILED);
  150616. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  150617. }
  150618. cinfo->output_scan_number = cinfo->input_scan_number;
  150619. } else if (cinfo->global_state != DSTATE_PRESCAN)
  150620. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150621. return output_pass_setup(cinfo);
  150622. }
  150623. LOCAL(boolean)
  150624. output_pass_setup (j_decompress_ptr cinfo)
  150625. {
  150626. if (cinfo->global_state != DSTATE_PRESCAN) {
  150627. (*cinfo->master->prepare_for_output_pass) (cinfo);
  150628. cinfo->output_scanline = 0;
  150629. cinfo->global_state = DSTATE_PRESCAN;
  150630. }
  150631. while (cinfo->master->is_dummy_pass) {
  150632. #ifdef QUANT_2PASS_SUPPORTED
  150633. while (cinfo->output_scanline < cinfo->output_height) {
  150634. JDIMENSION last_scanline;
  150635. if (cinfo->progress != NULL) {
  150636. cinfo->progress->pass_counter = (long) cinfo->output_scanline;
  150637. cinfo->progress->pass_limit = (long) cinfo->output_height;
  150638. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  150639. }
  150640. last_scanline = cinfo->output_scanline;
  150641. (*cinfo->main->process_data) (cinfo, (JSAMPARRAY) NULL,
  150642. &cinfo->output_scanline, (JDIMENSION) 0);
  150643. if (cinfo->output_scanline == last_scanline)
  150644. return FALSE; /* No progress made, must suspend */
  150645. }
  150646. (*cinfo->master->finish_output_pass) (cinfo);
  150647. (*cinfo->master->prepare_for_output_pass) (cinfo);
  150648. cinfo->output_scanline = 0;
  150649. #else
  150650. ERREXIT(cinfo, JERR_NOT_COMPILED);
  150651. #endif /* QUANT_2PASS_SUPPORTED */
  150652. }
  150653. cinfo->global_state = cinfo->raw_data_out ? DSTATE_RAW_OK : DSTATE_SCANNING;
  150654. return TRUE;
  150655. }
  150656. GLOBAL(JDIMENSION)
  150657. jpeg_read_scanlines (j_decompress_ptr cinfo, JSAMPARRAY scanlines,
  150658. JDIMENSION max_lines)
  150659. {
  150660. JDIMENSION row_ctr;
  150661. if (cinfo->global_state != DSTATE_SCANNING)
  150662. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150663. if (cinfo->output_scanline >= cinfo->output_height) {
  150664. WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
  150665. return 0;
  150666. }
  150667. if (cinfo->progress != NULL) {
  150668. cinfo->progress->pass_counter = (long) cinfo->output_scanline;
  150669. cinfo->progress->pass_limit = (long) cinfo->output_height;
  150670. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  150671. }
  150672. row_ctr = 0;
  150673. (*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, max_lines);
  150674. cinfo->output_scanline += row_ctr;
  150675. return row_ctr;
  150676. }
  150677. GLOBAL(JDIMENSION)
  150678. jpeg_read_raw_data (j_decompress_ptr cinfo, JSAMPIMAGE data,
  150679. JDIMENSION max_lines)
  150680. {
  150681. JDIMENSION lines_per_iMCU_row;
  150682. if (cinfo->global_state != DSTATE_RAW_OK)
  150683. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150684. if (cinfo->output_scanline >= cinfo->output_height) {
  150685. WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
  150686. return 0;
  150687. }
  150688. if (cinfo->progress != NULL) {
  150689. cinfo->progress->pass_counter = (long) cinfo->output_scanline;
  150690. cinfo->progress->pass_limit = (long) cinfo->output_height;
  150691. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  150692. }
  150693. lines_per_iMCU_row = cinfo->max_v_samp_factor * cinfo->min_DCT_scaled_size;
  150694. if (max_lines < lines_per_iMCU_row)
  150695. ERREXIT(cinfo, JERR_BUFFER_SIZE);
  150696. if (! (*cinfo->coef->decompress_data) (cinfo, data))
  150697. return 0; /* suspension forced, can do nothing more */
  150698. cinfo->output_scanline += lines_per_iMCU_row;
  150699. return lines_per_iMCU_row;
  150700. }
  150701. #ifdef D_MULTISCAN_FILES_SUPPORTED
  150702. GLOBAL(boolean)
  150703. jpeg_start_output (j_decompress_ptr cinfo, int scan_number)
  150704. {
  150705. if (cinfo->global_state != DSTATE_BUFIMAGE &&
  150706. cinfo->global_state != DSTATE_PRESCAN)
  150707. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150708. if (scan_number <= 0)
  150709. scan_number = 1;
  150710. if (cinfo->inputctl->eoi_reached &&
  150711. scan_number > cinfo->input_scan_number)
  150712. scan_number = cinfo->input_scan_number;
  150713. cinfo->output_scan_number = scan_number;
  150714. return output_pass_setup(cinfo);
  150715. }
  150716. GLOBAL(boolean)
  150717. jpeg_finish_output (j_decompress_ptr cinfo)
  150718. {
  150719. if ((cinfo->global_state == DSTATE_SCANNING ||
  150720. cinfo->global_state == DSTATE_RAW_OK) && cinfo->buffered_image) {
  150721. (*cinfo->master->finish_output_pass) (cinfo);
  150722. cinfo->global_state = DSTATE_BUFPOST;
  150723. } else if (cinfo->global_state != DSTATE_BUFPOST) {
  150724. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150725. }
  150726. while (cinfo->input_scan_number <= cinfo->output_scan_number &&
  150727. ! cinfo->inputctl->eoi_reached) {
  150728. if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
  150729. return FALSE; /* Suspend, come back later */
  150730. }
  150731. cinfo->global_state = DSTATE_BUFIMAGE;
  150732. return TRUE;
  150733. }
  150734. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  150735. /*** End of inlined file: jdapistd.c ***/
  150736. /*** Start of inlined file: jdapimin.c ***/
  150737. #define JPEG_INTERNALS
  150738. GLOBAL(void)
  150739. jpeg_CreateDecompress (j_decompress_ptr cinfo, int version, size_t structsize)
  150740. {
  150741. int i;
  150742. cinfo->mem = NULL; /* so jpeg_destroy knows mem mgr not called */
  150743. if (version != JPEG_LIB_VERSION)
  150744. ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version);
  150745. if (structsize != SIZEOF(struct jpeg_decompress_struct))
  150746. ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE,
  150747. (int) SIZEOF(struct jpeg_decompress_struct), (int) structsize);
  150748. {
  150749. struct jpeg_error_mgr * err = cinfo->err;
  150750. void * client_data = cinfo->client_data; /* ignore Purify complaint here */
  150751. MEMZERO(cinfo, SIZEOF(struct jpeg_decompress_struct));
  150752. cinfo->err = err;
  150753. cinfo->client_data = client_data;
  150754. }
  150755. cinfo->is_decompressor = TRUE;
  150756. jinit_memory_mgr((j_common_ptr) cinfo);
  150757. cinfo->progress = NULL;
  150758. cinfo->src = NULL;
  150759. for (i = 0; i < NUM_QUANT_TBLS; i++)
  150760. cinfo->quant_tbl_ptrs[i] = NULL;
  150761. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  150762. cinfo->dc_huff_tbl_ptrs[i] = NULL;
  150763. cinfo->ac_huff_tbl_ptrs[i] = NULL;
  150764. }
  150765. cinfo->marker_list = NULL;
  150766. jinit_marker_reader(cinfo);
  150767. jinit_input_controller(cinfo);
  150768. cinfo->global_state = DSTATE_START;
  150769. }
  150770. GLOBAL(void)
  150771. jpeg_destroy_decompress (j_decompress_ptr cinfo)
  150772. {
  150773. jpeg_destroy((j_common_ptr) cinfo); /* use common routine */
  150774. }
  150775. GLOBAL(void)
  150776. jpeg_abort_decompress (j_decompress_ptr cinfo)
  150777. {
  150778. jpeg_abort((j_common_ptr) cinfo); /* use common routine */
  150779. }
  150780. LOCAL(void)
  150781. default_decompress_parms (j_decompress_ptr cinfo)
  150782. {
  150783. switch (cinfo->num_components) {
  150784. case 1:
  150785. cinfo->jpeg_color_space = JCS_GRAYSCALE;
  150786. cinfo->out_color_space = JCS_GRAYSCALE;
  150787. break;
  150788. case 3:
  150789. if (cinfo->saw_JFIF_marker) {
  150790. cinfo->jpeg_color_space = JCS_YCbCr; /* JFIF implies YCbCr */
  150791. } else if (cinfo->saw_Adobe_marker) {
  150792. switch (cinfo->Adobe_transform) {
  150793. case 0:
  150794. cinfo->jpeg_color_space = JCS_RGB;
  150795. break;
  150796. case 1:
  150797. cinfo->jpeg_color_space = JCS_YCbCr;
  150798. break;
  150799. default:
  150800. WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform);
  150801. cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */
  150802. break;
  150803. }
  150804. } else {
  150805. int cid0 = cinfo->comp_info[0].component_id;
  150806. int cid1 = cinfo->comp_info[1].component_id;
  150807. int cid2 = cinfo->comp_info[2].component_id;
  150808. if (cid0 == 1 && cid1 == 2 && cid2 == 3)
  150809. cinfo->jpeg_color_space = JCS_YCbCr; /* assume JFIF w/out marker */
  150810. else if (cid0 == 82 && cid1 == 71 && cid2 == 66)
  150811. cinfo->jpeg_color_space = JCS_RGB; /* ASCII 'R', 'G', 'B' */
  150812. else {
  150813. TRACEMS3(cinfo, 1, JTRC_UNKNOWN_IDS, cid0, cid1, cid2);
  150814. cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */
  150815. }
  150816. }
  150817. cinfo->out_color_space = JCS_RGB;
  150818. break;
  150819. case 4:
  150820. if (cinfo->saw_Adobe_marker) {
  150821. switch (cinfo->Adobe_transform) {
  150822. case 0:
  150823. cinfo->jpeg_color_space = JCS_CMYK;
  150824. break;
  150825. case 2:
  150826. cinfo->jpeg_color_space = JCS_YCCK;
  150827. break;
  150828. default:
  150829. WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform);
  150830. cinfo->jpeg_color_space = JCS_YCCK; /* assume it's YCCK */
  150831. break;
  150832. }
  150833. } else {
  150834. cinfo->jpeg_color_space = JCS_CMYK;
  150835. }
  150836. cinfo->out_color_space = JCS_CMYK;
  150837. break;
  150838. default:
  150839. cinfo->jpeg_color_space = JCS_UNKNOWN;
  150840. cinfo->out_color_space = JCS_UNKNOWN;
  150841. break;
  150842. }
  150843. cinfo->scale_num = 1; /* 1:1 scaling */
  150844. cinfo->scale_denom = 1;
  150845. cinfo->output_gamma = 1.0;
  150846. cinfo->buffered_image = FALSE;
  150847. cinfo->raw_data_out = FALSE;
  150848. cinfo->dct_method = JDCT_DEFAULT;
  150849. cinfo->do_fancy_upsampling = TRUE;
  150850. cinfo->do_block_smoothing = TRUE;
  150851. cinfo->quantize_colors = FALSE;
  150852. cinfo->dither_mode = JDITHER_FS;
  150853. #ifdef QUANT_2PASS_SUPPORTED
  150854. cinfo->two_pass_quantize = TRUE;
  150855. #else
  150856. cinfo->two_pass_quantize = FALSE;
  150857. #endif
  150858. cinfo->desired_number_of_colors = 256;
  150859. cinfo->colormap = NULL;
  150860. cinfo->enable_1pass_quant = FALSE;
  150861. cinfo->enable_external_quant = FALSE;
  150862. cinfo->enable_2pass_quant = FALSE;
  150863. }
  150864. GLOBAL(int)
  150865. jpeg_read_header (j_decompress_ptr cinfo, boolean require_image)
  150866. {
  150867. int retcode;
  150868. if (cinfo->global_state != DSTATE_START &&
  150869. cinfo->global_state != DSTATE_INHEADER)
  150870. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150871. retcode = jpeg_consume_input(cinfo);
  150872. switch (retcode) {
  150873. case JPEG_REACHED_SOS:
  150874. retcode = JPEG_HEADER_OK;
  150875. break;
  150876. case JPEG_REACHED_EOI:
  150877. if (require_image) /* Complain if application wanted an image */
  150878. ERREXIT(cinfo, JERR_NO_IMAGE);
  150879. jpeg_abort((j_common_ptr) cinfo); /* sets state = DSTATE_START */
  150880. retcode = JPEG_HEADER_TABLES_ONLY;
  150881. break;
  150882. case JPEG_SUSPENDED:
  150883. break;
  150884. }
  150885. return retcode;
  150886. }
  150887. GLOBAL(int)
  150888. jpeg_consume_input (j_decompress_ptr cinfo)
  150889. {
  150890. int retcode = JPEG_SUSPENDED;
  150891. switch (cinfo->global_state) {
  150892. case DSTATE_START:
  150893. (*cinfo->inputctl->reset_input_controller) (cinfo);
  150894. (*cinfo->src->init_source) (cinfo);
  150895. cinfo->global_state = DSTATE_INHEADER;
  150896. case DSTATE_INHEADER:
  150897. retcode = (*cinfo->inputctl->consume_input) (cinfo);
  150898. if (retcode == JPEG_REACHED_SOS) { /* Found SOS, prepare to decompress */
  150899. default_decompress_parms(cinfo);
  150900. cinfo->global_state = DSTATE_READY;
  150901. }
  150902. break;
  150903. case DSTATE_READY:
  150904. retcode = JPEG_REACHED_SOS;
  150905. break;
  150906. case DSTATE_PRELOAD:
  150907. case DSTATE_PRESCAN:
  150908. case DSTATE_SCANNING:
  150909. case DSTATE_RAW_OK:
  150910. case DSTATE_BUFIMAGE:
  150911. case DSTATE_BUFPOST:
  150912. case DSTATE_STOPPING:
  150913. retcode = (*cinfo->inputctl->consume_input) (cinfo);
  150914. break;
  150915. default:
  150916. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150917. }
  150918. return retcode;
  150919. }
  150920. GLOBAL(boolean)
  150921. jpeg_input_complete (j_decompress_ptr cinfo)
  150922. {
  150923. if (cinfo->global_state < DSTATE_START ||
  150924. cinfo->global_state > DSTATE_STOPPING)
  150925. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150926. return cinfo->inputctl->eoi_reached;
  150927. }
  150928. GLOBAL(boolean)
  150929. jpeg_has_multiple_scans (j_decompress_ptr cinfo)
  150930. {
  150931. if (cinfo->global_state < DSTATE_READY ||
  150932. cinfo->global_state > DSTATE_STOPPING)
  150933. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150934. return cinfo->inputctl->has_multiple_scans;
  150935. }
  150936. GLOBAL(boolean)
  150937. jpeg_finish_decompress (j_decompress_ptr cinfo)
  150938. {
  150939. if ((cinfo->global_state == DSTATE_SCANNING ||
  150940. cinfo->global_state == DSTATE_RAW_OK) && ! cinfo->buffered_image) {
  150941. if (cinfo->output_scanline < cinfo->output_height)
  150942. ERREXIT(cinfo, JERR_TOO_LITTLE_DATA);
  150943. (*cinfo->master->finish_output_pass) (cinfo);
  150944. cinfo->global_state = DSTATE_STOPPING;
  150945. } else if (cinfo->global_state == DSTATE_BUFIMAGE) {
  150946. cinfo->global_state = DSTATE_STOPPING;
  150947. } else if (cinfo->global_state != DSTATE_STOPPING) {
  150948. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150949. }
  150950. while (! cinfo->inputctl->eoi_reached) {
  150951. if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
  150952. return FALSE; /* Suspend, come back later */
  150953. }
  150954. (*cinfo->src->term_source) (cinfo);
  150955. jpeg_abort((j_common_ptr) cinfo);
  150956. return TRUE;
  150957. }
  150958. /*** End of inlined file: jdapimin.c ***/
  150959. /*** Start of inlined file: jdatasrc.c ***/
  150960. /*** Start of inlined file: jerror.h ***/
  150961. #ifndef JMESSAGE
  150962. #ifndef JERROR_H
  150963. #define JMAKE_ENUM_LIST
  150964. #else
  150965. #define JMESSAGE(code,string)
  150966. #endif /* JERROR_H */
  150967. #endif /* JMESSAGE */
  150968. #ifdef JMAKE_ENUM_LIST
  150969. typedef enum {
  150970. #define JMESSAGE(code,string) code ,
  150971. #endif /* JMAKE_ENUM_LIST */
  150972. JMESSAGE(JMSG_NOMESSAGE, "Bogus message code %d") /* Must be first entry! */
  150973. JMESSAGE(JERR_ARITH_NOTIMPL,
  150974. "Sorry, there are legal restrictions on arithmetic coding")
  150975. JMESSAGE(JERR_BAD_ALIGN_TYPE, "ALIGN_TYPE is wrong, please fix")
  150976. JMESSAGE(JERR_BAD_ALLOC_CHUNK, "MAX_ALLOC_CHUNK is wrong, please fix")
  150977. JMESSAGE(JERR_BAD_BUFFER_MODE, "Bogus buffer control mode")
  150978. JMESSAGE(JERR_BAD_COMPONENT_ID, "Invalid component ID %d in SOS")
  150979. JMESSAGE(JERR_BAD_DCT_COEF, "DCT coefficient out of range")
  150980. JMESSAGE(JERR_BAD_DCTSIZE, "IDCT output block size %d not supported")
  150981. JMESSAGE(JERR_BAD_HUFF_TABLE, "Bogus Huffman table definition")
  150982. JMESSAGE(JERR_BAD_IN_COLORSPACE, "Bogus input colorspace")
  150983. JMESSAGE(JERR_BAD_J_COLORSPACE, "Bogus JPEG colorspace")
  150984. JMESSAGE(JERR_BAD_LENGTH, "Bogus marker length")
  150985. JMESSAGE(JERR_BAD_LIB_VERSION,
  150986. "Wrong JPEG library version: library is %d, caller expects %d")
  150987. JMESSAGE(JERR_BAD_MCU_SIZE, "Sampling factors too large for interleaved scan")
  150988. JMESSAGE(JERR_BAD_POOL_ID, "Invalid memory pool code %d")
  150989. JMESSAGE(JERR_BAD_PRECISION, "Unsupported JPEG data precision %d")
  150990. JMESSAGE(JERR_BAD_PROGRESSION,
  150991. "Invalid progressive parameters Ss=%d Se=%d Ah=%d Al=%d")
  150992. JMESSAGE(JERR_BAD_PROG_SCRIPT,
  150993. "Invalid progressive parameters at scan script entry %d")
  150994. JMESSAGE(JERR_BAD_SAMPLING, "Bogus sampling factors")
  150995. JMESSAGE(JERR_BAD_SCAN_SCRIPT, "Invalid scan script at entry %d")
  150996. JMESSAGE(JERR_BAD_STATE, "Improper call to JPEG library in state %d")
  150997. JMESSAGE(JERR_BAD_STRUCT_SIZE,
  150998. "JPEG parameter struct mismatch: library thinks size is %u, caller expects %u")
  150999. JMESSAGE(JERR_BAD_VIRTUAL_ACCESS, "Bogus virtual array access")
  151000. JMESSAGE(JERR_BUFFER_SIZE, "Buffer passed to JPEG library is too small")
  151001. JMESSAGE(JERR_CANT_SUSPEND, "Suspension not allowed here")
  151002. JMESSAGE(JERR_CCIR601_NOTIMPL, "CCIR601 sampling not implemented yet")
  151003. JMESSAGE(JERR_COMPONENT_COUNT, "Too many color components: %d, max %d")
  151004. JMESSAGE(JERR_CONVERSION_NOTIMPL, "Unsupported color conversion request")
  151005. JMESSAGE(JERR_DAC_INDEX, "Bogus DAC index %d")
  151006. JMESSAGE(JERR_DAC_VALUE, "Bogus DAC value 0x%x")
  151007. JMESSAGE(JERR_DHT_INDEX, "Bogus DHT index %d")
  151008. JMESSAGE(JERR_DQT_INDEX, "Bogus DQT index %d")
  151009. JMESSAGE(JERR_EMPTY_IMAGE, "Empty JPEG image (DNL not supported)")
  151010. JMESSAGE(JERR_EMS_READ, "Read from EMS failed")
  151011. JMESSAGE(JERR_EMS_WRITE, "Write to EMS failed")
  151012. JMESSAGE(JERR_EOI_EXPECTED, "Didn't expect more than one scan")
  151013. JMESSAGE(JERR_FILE_READ, "Input file read error")
  151014. JMESSAGE(JERR_FILE_WRITE, "Output file write error --- out of disk space?")
  151015. JMESSAGE(JERR_FRACT_SAMPLE_NOTIMPL, "Fractional sampling not implemented yet")
  151016. JMESSAGE(JERR_HUFF_CLEN_OVERFLOW, "Huffman code size table overflow")
  151017. JMESSAGE(JERR_HUFF_MISSING_CODE, "Missing Huffman code table entry")
  151018. JMESSAGE(JERR_IMAGE_TOO_BIG, "Maximum supported image dimension is %u pixels")
  151019. JMESSAGE(JERR_INPUT_EMPTY, "Empty input file")
  151020. JMESSAGE(JERR_INPUT_EOF, "Premature end of input file")
  151021. JMESSAGE(JERR_MISMATCHED_QUANT_TABLE,
  151022. "Cannot transcode due to multiple use of quantization table %d")
  151023. JMESSAGE(JERR_MISSING_DATA, "Scan script does not transmit all data")
  151024. JMESSAGE(JERR_MODE_CHANGE, "Invalid color quantization mode change")
  151025. JMESSAGE(JERR_NOTIMPL, "Not implemented yet")
  151026. JMESSAGE(JERR_NOT_COMPILED, "Requested feature was omitted at compile time")
  151027. JMESSAGE(JERR_NO_BACKING_STORE, "Backing store not supported")
  151028. JMESSAGE(JERR_NO_HUFF_TABLE, "Huffman table 0x%02x was not defined")
  151029. JMESSAGE(JERR_NO_IMAGE, "JPEG datastream contains no image")
  151030. JMESSAGE(JERR_NO_QUANT_TABLE, "Quantization table 0x%02x was not defined")
  151031. JMESSAGE(JERR_NO_SOI, "Not a JPEG file: starts with 0x%02x 0x%02x")
  151032. JMESSAGE(JERR_OUT_OF_MEMORY, "Insufficient memory (case %d)")
  151033. JMESSAGE(JERR_QUANT_COMPONENTS,
  151034. "Cannot quantize more than %d color components")
  151035. JMESSAGE(JERR_QUANT_FEW_COLORS, "Cannot quantize to fewer than %d colors")
  151036. JMESSAGE(JERR_QUANT_MANY_COLORS, "Cannot quantize to more than %d colors")
  151037. JMESSAGE(JERR_SOF_DUPLICATE, "Invalid JPEG file structure: two SOF markers")
  151038. JMESSAGE(JERR_SOF_NO_SOS, "Invalid JPEG file structure: missing SOS marker")
  151039. JMESSAGE(JERR_SOF_UNSUPPORTED, "Unsupported JPEG process: SOF type 0x%02x")
  151040. JMESSAGE(JERR_SOI_DUPLICATE, "Invalid JPEG file structure: two SOI markers")
  151041. JMESSAGE(JERR_SOS_NO_SOF, "Invalid JPEG file structure: SOS before SOF")
  151042. JMESSAGE(JERR_TFILE_CREATE, "Failed to create temporary file %s")
  151043. JMESSAGE(JERR_TFILE_READ, "Read failed on temporary file")
  151044. JMESSAGE(JERR_TFILE_SEEK, "Seek failed on temporary file")
  151045. JMESSAGE(JERR_TFILE_WRITE,
  151046. "Write failed on temporary file --- out of disk space?")
  151047. JMESSAGE(JERR_TOO_LITTLE_DATA, "Application transferred too few scanlines")
  151048. JMESSAGE(JERR_UNKNOWN_MARKER, "Unsupported marker type 0x%02x")
  151049. JMESSAGE(JERR_VIRTUAL_BUG, "Virtual array controller messed up")
  151050. JMESSAGE(JERR_WIDTH_OVERFLOW, "Image too wide for this implementation")
  151051. JMESSAGE(JERR_XMS_READ, "Read from XMS failed")
  151052. JMESSAGE(JERR_XMS_WRITE, "Write to XMS failed")
  151053. JMESSAGE(JMSG_COPYRIGHT, JCOPYRIGHT)
  151054. JMESSAGE(JMSG_VERSION, JVERSION)
  151055. JMESSAGE(JTRC_16BIT_TABLES,
  151056. "Caution: quantization tables are too coarse for baseline JPEG")
  151057. JMESSAGE(JTRC_ADOBE,
  151058. "Adobe APP14 marker: version %d, flags 0x%04x 0x%04x, transform %d")
  151059. JMESSAGE(JTRC_APP0, "Unknown APP0 marker (not JFIF), length %u")
  151060. JMESSAGE(JTRC_APP14, "Unknown APP14 marker (not Adobe), length %u")
  151061. JMESSAGE(JTRC_DAC, "Define Arithmetic Table 0x%02x: 0x%02x")
  151062. JMESSAGE(JTRC_DHT, "Define Huffman Table 0x%02x")
  151063. JMESSAGE(JTRC_DQT, "Define Quantization Table %d precision %d")
  151064. JMESSAGE(JTRC_DRI, "Define Restart Interval %u")
  151065. JMESSAGE(JTRC_EMS_CLOSE, "Freed EMS handle %u")
  151066. JMESSAGE(JTRC_EMS_OPEN, "Obtained EMS handle %u")
  151067. JMESSAGE(JTRC_EOI, "End Of Image")
  151068. JMESSAGE(JTRC_HUFFBITS, " %3d %3d %3d %3d %3d %3d %3d %3d")
  151069. JMESSAGE(JTRC_JFIF, "JFIF APP0 marker: version %d.%02d, density %dx%d %d")
  151070. JMESSAGE(JTRC_JFIF_BADTHUMBNAILSIZE,
  151071. "Warning: thumbnail image size does not match data length %u")
  151072. JMESSAGE(JTRC_JFIF_EXTENSION,
  151073. "JFIF extension marker: type 0x%02x, length %u")
  151074. JMESSAGE(JTRC_JFIF_THUMBNAIL, " with %d x %d thumbnail image")
  151075. JMESSAGE(JTRC_MISC_MARKER, "Miscellaneous marker 0x%02x, length %u")
  151076. JMESSAGE(JTRC_PARMLESS_MARKER, "Unexpected marker 0x%02x")
  151077. JMESSAGE(JTRC_QUANTVALS, " %4u %4u %4u %4u %4u %4u %4u %4u")
  151078. JMESSAGE(JTRC_QUANT_3_NCOLORS, "Quantizing to %d = %d*%d*%d colors")
  151079. JMESSAGE(JTRC_QUANT_NCOLORS, "Quantizing to %d colors")
  151080. JMESSAGE(JTRC_QUANT_SELECTED, "Selected %d colors for quantization")
  151081. JMESSAGE(JTRC_RECOVERY_ACTION, "At marker 0x%02x, recovery action %d")
  151082. JMESSAGE(JTRC_RST, "RST%d")
  151083. JMESSAGE(JTRC_SMOOTH_NOTIMPL,
  151084. "Smoothing not supported with nonstandard sampling ratios")
  151085. JMESSAGE(JTRC_SOF, "Start Of Frame 0x%02x: width=%u, height=%u, components=%d")
  151086. JMESSAGE(JTRC_SOF_COMPONENT, " Component %d: %dhx%dv q=%d")
  151087. JMESSAGE(JTRC_SOI, "Start of Image")
  151088. JMESSAGE(JTRC_SOS, "Start Of Scan: %d components")
  151089. JMESSAGE(JTRC_SOS_COMPONENT, " Component %d: dc=%d ac=%d")
  151090. JMESSAGE(JTRC_SOS_PARAMS, " Ss=%d, Se=%d, Ah=%d, Al=%d")
  151091. JMESSAGE(JTRC_TFILE_CLOSE, "Closed temporary file %s")
  151092. JMESSAGE(JTRC_TFILE_OPEN, "Opened temporary file %s")
  151093. JMESSAGE(JTRC_THUMB_JPEG,
  151094. "JFIF extension marker: JPEG-compressed thumbnail image, length %u")
  151095. JMESSAGE(JTRC_THUMB_PALETTE,
  151096. "JFIF extension marker: palette thumbnail image, length %u")
  151097. JMESSAGE(JTRC_THUMB_RGB,
  151098. "JFIF extension marker: RGB thumbnail image, length %u")
  151099. JMESSAGE(JTRC_UNKNOWN_IDS,
  151100. "Unrecognized component IDs %d %d %d, assuming YCbCr")
  151101. JMESSAGE(JTRC_XMS_CLOSE, "Freed XMS handle %u")
  151102. JMESSAGE(JTRC_XMS_OPEN, "Obtained XMS handle %u")
  151103. JMESSAGE(JWRN_ADOBE_XFORM, "Unknown Adobe color transform code %d")
  151104. JMESSAGE(JWRN_BOGUS_PROGRESSION,
  151105. "Inconsistent progression sequence for component %d coefficient %d")
  151106. JMESSAGE(JWRN_EXTRANEOUS_DATA,
  151107. "Corrupt JPEG data: %u extraneous bytes before marker 0x%02x")
  151108. JMESSAGE(JWRN_HIT_MARKER, "Corrupt JPEG data: premature end of data segment")
  151109. JMESSAGE(JWRN_HUFF_BAD_CODE, "Corrupt JPEG data: bad Huffman code")
  151110. JMESSAGE(JWRN_JFIF_MAJOR, "Warning: unknown JFIF revision number %d.%02d")
  151111. JMESSAGE(JWRN_JPEG_EOF, "Premature end of JPEG file")
  151112. JMESSAGE(JWRN_MUST_RESYNC,
  151113. "Corrupt JPEG data: found marker 0x%02x instead of RST%d")
  151114. JMESSAGE(JWRN_NOT_SEQUENTIAL, "Invalid SOS parameters for sequential JPEG")
  151115. JMESSAGE(JWRN_TOO_MUCH_DATA, "Application transferred too many scanlines")
  151116. #ifdef JMAKE_ENUM_LIST
  151117. JMSG_LASTMSGCODE
  151118. } J_MESSAGE_CODE;
  151119. #undef JMAKE_ENUM_LIST
  151120. #endif /* JMAKE_ENUM_LIST */
  151121. #undef JMESSAGE
  151122. #ifndef JERROR_H
  151123. #define JERROR_H
  151124. #define ERREXIT(cinfo,code) \
  151125. ((cinfo)->err->msg_code = (code), \
  151126. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  151127. #define ERREXIT1(cinfo,code,p1) \
  151128. ((cinfo)->err->msg_code = (code), \
  151129. (cinfo)->err->msg_parm.i[0] = (p1), \
  151130. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  151131. #define ERREXIT2(cinfo,code,p1,p2) \
  151132. ((cinfo)->err->msg_code = (code), \
  151133. (cinfo)->err->msg_parm.i[0] = (p1), \
  151134. (cinfo)->err->msg_parm.i[1] = (p2), \
  151135. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  151136. #define ERREXIT3(cinfo,code,p1,p2,p3) \
  151137. ((cinfo)->err->msg_code = (code), \
  151138. (cinfo)->err->msg_parm.i[0] = (p1), \
  151139. (cinfo)->err->msg_parm.i[1] = (p2), \
  151140. (cinfo)->err->msg_parm.i[2] = (p3), \
  151141. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  151142. #define ERREXIT4(cinfo,code,p1,p2,p3,p4) \
  151143. ((cinfo)->err->msg_code = (code), \
  151144. (cinfo)->err->msg_parm.i[0] = (p1), \
  151145. (cinfo)->err->msg_parm.i[1] = (p2), \
  151146. (cinfo)->err->msg_parm.i[2] = (p3), \
  151147. (cinfo)->err->msg_parm.i[3] = (p4), \
  151148. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  151149. #define ERREXITS(cinfo,code,str) \
  151150. ((cinfo)->err->msg_code = (code), \
  151151. strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
  151152. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  151153. #define MAKESTMT(stuff) do { stuff } while (0)
  151154. #define WARNMS(cinfo,code) \
  151155. ((cinfo)->err->msg_code = (code), \
  151156. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  151157. #define WARNMS1(cinfo,code,p1) \
  151158. ((cinfo)->err->msg_code = (code), \
  151159. (cinfo)->err->msg_parm.i[0] = (p1), \
  151160. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  151161. #define WARNMS2(cinfo,code,p1,p2) \
  151162. ((cinfo)->err->msg_code = (code), \
  151163. (cinfo)->err->msg_parm.i[0] = (p1), \
  151164. (cinfo)->err->msg_parm.i[1] = (p2), \
  151165. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  151166. #define TRACEMS(cinfo,lvl,code) \
  151167. ((cinfo)->err->msg_code = (code), \
  151168. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  151169. #define TRACEMS1(cinfo,lvl,code,p1) \
  151170. ((cinfo)->err->msg_code = (code), \
  151171. (cinfo)->err->msg_parm.i[0] = (p1), \
  151172. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  151173. #define TRACEMS2(cinfo,lvl,code,p1,p2) \
  151174. ((cinfo)->err->msg_code = (code), \
  151175. (cinfo)->err->msg_parm.i[0] = (p1), \
  151176. (cinfo)->err->msg_parm.i[1] = (p2), \
  151177. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  151178. #define TRACEMS3(cinfo,lvl,code,p1,p2,p3) \
  151179. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  151180. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); \
  151181. (cinfo)->err->msg_code = (code); \
  151182. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  151183. #define TRACEMS4(cinfo,lvl,code,p1,p2,p3,p4) \
  151184. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  151185. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  151186. (cinfo)->err->msg_code = (code); \
  151187. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  151188. #define TRACEMS5(cinfo,lvl,code,p1,p2,p3,p4,p5) \
  151189. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  151190. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  151191. _mp[4] = (p5); \
  151192. (cinfo)->err->msg_code = (code); \
  151193. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  151194. #define TRACEMS8(cinfo,lvl,code,p1,p2,p3,p4,p5,p6,p7,p8) \
  151195. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  151196. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  151197. _mp[4] = (p5); _mp[5] = (p6); _mp[6] = (p7); _mp[7] = (p8); \
  151198. (cinfo)->err->msg_code = (code); \
  151199. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  151200. #define TRACEMSS(cinfo,lvl,code,str) \
  151201. ((cinfo)->err->msg_code = (code), \
  151202. strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
  151203. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  151204. #endif /* JERROR_H */
  151205. /*** End of inlined file: jerror.h ***/
  151206. typedef struct {
  151207. struct jpeg_source_mgr pub; /* public fields */
  151208. FILE * infile; /* source stream */
  151209. JOCTET * buffer; /* start of buffer */
  151210. boolean start_of_file; /* have we gotten any data yet? */
  151211. } my_source_mgr;
  151212. typedef my_source_mgr * my_src_ptr;
  151213. #define INPUT_BUF_SIZE 4096 /* choose an efficiently fread'able size */
  151214. METHODDEF(void)
  151215. init_source (j_decompress_ptr cinfo)
  151216. {
  151217. my_src_ptr src = (my_src_ptr) cinfo->src;
  151218. src->start_of_file = TRUE;
  151219. }
  151220. METHODDEF(boolean)
  151221. fill_input_buffer (j_decompress_ptr cinfo)
  151222. {
  151223. my_src_ptr src = (my_src_ptr) cinfo->src;
  151224. size_t nbytes;
  151225. nbytes = JFREAD(src->infile, src->buffer, INPUT_BUF_SIZE);
  151226. if (nbytes <= 0) {
  151227. if (src->start_of_file) /* Treat empty input file as fatal error */
  151228. ERREXIT(cinfo, JERR_INPUT_EMPTY);
  151229. WARNMS(cinfo, JWRN_JPEG_EOF);
  151230. src->buffer[0] = (JOCTET) 0xFF;
  151231. src->buffer[1] = (JOCTET) JPEG_EOI;
  151232. nbytes = 2;
  151233. }
  151234. src->pub.next_input_byte = src->buffer;
  151235. src->pub.bytes_in_buffer = nbytes;
  151236. src->start_of_file = FALSE;
  151237. return TRUE;
  151238. }
  151239. METHODDEF(void)
  151240. skip_input_data (j_decompress_ptr cinfo, long num_bytes)
  151241. {
  151242. my_src_ptr src = (my_src_ptr) cinfo->src;
  151243. if (num_bytes > 0) {
  151244. while (num_bytes > (long) src->pub.bytes_in_buffer) {
  151245. num_bytes -= (long) src->pub.bytes_in_buffer;
  151246. (void) fill_input_buffer(cinfo);
  151247. }
  151248. src->pub.next_input_byte += (size_t) num_bytes;
  151249. src->pub.bytes_in_buffer -= (size_t) num_bytes;
  151250. }
  151251. }
  151252. METHODDEF(void)
  151253. term_source (j_decompress_ptr cinfo)
  151254. {
  151255. }
  151256. GLOBAL(void)
  151257. jpeg_stdio_src (j_decompress_ptr cinfo, FILE * infile)
  151258. {
  151259. my_src_ptr src;
  151260. if (cinfo->src == NULL) { /* first time for this JPEG object? */
  151261. cinfo->src = (struct jpeg_source_mgr *)
  151262. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  151263. SIZEOF(my_source_mgr));
  151264. src = (my_src_ptr) cinfo->src;
  151265. src->buffer = (JOCTET *)
  151266. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  151267. INPUT_BUF_SIZE * SIZEOF(JOCTET));
  151268. }
  151269. src = (my_src_ptr) cinfo->src;
  151270. src->pub.init_source = init_source;
  151271. src->pub.fill_input_buffer = fill_input_buffer;
  151272. src->pub.skip_input_data = skip_input_data;
  151273. src->pub.resync_to_restart = jpeg_resync_to_restart; /* use default method */
  151274. src->pub.term_source = term_source;
  151275. src->infile = infile;
  151276. src->pub.bytes_in_buffer = 0; /* forces fill_input_buffer on first read */
  151277. src->pub.next_input_byte = NULL; /* until buffer loaded */
  151278. }
  151279. /*** End of inlined file: jdatasrc.c ***/
  151280. /*** Start of inlined file: jdcoefct.c ***/
  151281. #define JPEG_INTERNALS
  151282. #ifndef D_PROGRESSIVE_SUPPORTED
  151283. #undef BLOCK_SMOOTHING_SUPPORTED
  151284. #endif
  151285. typedef struct {
  151286. struct jpeg_d_coef_controller pub; /* public fields */
  151287. JDIMENSION MCU_ctr; /* counts MCUs processed in current row */
  151288. int MCU_vert_offset; /* counts MCU rows within iMCU row */
  151289. int MCU_rows_per_iMCU_row; /* number of such rows needed */
  151290. JBLOCKROW MCU_buffer[D_MAX_BLOCKS_IN_MCU];
  151291. #ifdef D_MULTISCAN_FILES_SUPPORTED
  151292. jvirt_barray_ptr whole_image[MAX_COMPONENTS];
  151293. #endif
  151294. #ifdef BLOCK_SMOOTHING_SUPPORTED
  151295. int * coef_bits_latch;
  151296. #define SAVED_COEFS 6 /* we save coef_bits[0..5] */
  151297. #endif
  151298. } my_coef_controller3;
  151299. typedef my_coef_controller3 * my_coef_ptr3;
  151300. METHODDEF(int) decompress_onepass
  151301. JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));
  151302. #ifdef D_MULTISCAN_FILES_SUPPORTED
  151303. METHODDEF(int) decompress_data
  151304. JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));
  151305. #endif
  151306. #ifdef BLOCK_SMOOTHING_SUPPORTED
  151307. LOCAL(boolean) smoothing_ok JPP((j_decompress_ptr cinfo));
  151308. METHODDEF(int) decompress_smooth_data
  151309. JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));
  151310. #endif
  151311. LOCAL(void)
  151312. start_iMCU_row3 (j_decompress_ptr cinfo)
  151313. {
  151314. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151315. if (cinfo->comps_in_scan > 1) {
  151316. coef->MCU_rows_per_iMCU_row = 1;
  151317. } else {
  151318. if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
  151319. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
  151320. else
  151321. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
  151322. }
  151323. coef->MCU_ctr = 0;
  151324. coef->MCU_vert_offset = 0;
  151325. }
  151326. METHODDEF(void)
  151327. start_input_pass (j_decompress_ptr cinfo)
  151328. {
  151329. cinfo->input_iMCU_row = 0;
  151330. start_iMCU_row3(cinfo);
  151331. }
  151332. METHODDEF(void)
  151333. start_output_pass (j_decompress_ptr cinfo)
  151334. {
  151335. #ifdef BLOCK_SMOOTHING_SUPPORTED
  151336. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151337. if (coef->pub.coef_arrays != NULL) {
  151338. if (cinfo->do_block_smoothing && smoothing_ok(cinfo))
  151339. coef->pub.decompress_data = decompress_smooth_data;
  151340. else
  151341. coef->pub.decompress_data = decompress_data;
  151342. }
  151343. #endif
  151344. cinfo->output_iMCU_row = 0;
  151345. }
  151346. METHODDEF(int)
  151347. decompress_onepass (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
  151348. {
  151349. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151350. JDIMENSION MCU_col_num; /* index of current MCU within row */
  151351. JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
  151352. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  151353. int blkn, ci, xindex, yindex, yoffset, useful_width;
  151354. JSAMPARRAY output_ptr;
  151355. JDIMENSION start_col, output_col;
  151356. jpeg_component_info *compptr;
  151357. inverse_DCT_method_ptr inverse_DCT;
  151358. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  151359. yoffset++) {
  151360. for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col;
  151361. MCU_col_num++) {
  151362. jzero_far((void FAR *) coef->MCU_buffer[0],
  151363. (size_t) (cinfo->blocks_in_MCU * SIZEOF(JBLOCK)));
  151364. if (! (*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
  151365. coef->MCU_vert_offset = yoffset;
  151366. coef->MCU_ctr = MCU_col_num;
  151367. return JPEG_SUSPENDED;
  151368. }
  151369. blkn = 0; /* index of current DCT block within MCU */
  151370. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  151371. compptr = cinfo->cur_comp_info[ci];
  151372. if (! compptr->component_needed) {
  151373. blkn += compptr->MCU_blocks;
  151374. continue;
  151375. }
  151376. inverse_DCT = cinfo->idct->inverse_DCT[compptr->component_index];
  151377. useful_width = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
  151378. : compptr->last_col_width;
  151379. output_ptr = output_buf[compptr->component_index] +
  151380. yoffset * compptr->DCT_scaled_size;
  151381. start_col = MCU_col_num * compptr->MCU_sample_width;
  151382. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  151383. if (cinfo->input_iMCU_row < last_iMCU_row ||
  151384. yoffset+yindex < compptr->last_row_height) {
  151385. output_col = start_col;
  151386. for (xindex = 0; xindex < useful_width; xindex++) {
  151387. (*inverse_DCT) (cinfo, compptr,
  151388. (JCOEFPTR) coef->MCU_buffer[blkn+xindex],
  151389. output_ptr, output_col);
  151390. output_col += compptr->DCT_scaled_size;
  151391. }
  151392. }
  151393. blkn += compptr->MCU_width;
  151394. output_ptr += compptr->DCT_scaled_size;
  151395. }
  151396. }
  151397. }
  151398. coef->MCU_ctr = 0;
  151399. }
  151400. cinfo->output_iMCU_row++;
  151401. if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
  151402. start_iMCU_row3(cinfo);
  151403. return JPEG_ROW_COMPLETED;
  151404. }
  151405. (*cinfo->inputctl->finish_input_pass) (cinfo);
  151406. return JPEG_SCAN_COMPLETED;
  151407. }
  151408. METHODDEF(int)
  151409. dummy_consume_data (j_decompress_ptr cinfo)
  151410. {
  151411. return JPEG_SUSPENDED; /* Always indicate nothing was done */
  151412. }
  151413. #ifdef D_MULTISCAN_FILES_SUPPORTED
  151414. METHODDEF(int)
  151415. consume_data (j_decompress_ptr cinfo)
  151416. {
  151417. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151418. JDIMENSION MCU_col_num; /* index of current MCU within row */
  151419. int blkn, ci, xindex, yindex, yoffset;
  151420. JDIMENSION start_col;
  151421. JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
  151422. JBLOCKROW buffer_ptr;
  151423. jpeg_component_info *compptr;
  151424. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  151425. compptr = cinfo->cur_comp_info[ci];
  151426. buffer[ci] = (*cinfo->mem->access_virt_barray)
  151427. ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index],
  151428. cinfo->input_iMCU_row * compptr->v_samp_factor,
  151429. (JDIMENSION) compptr->v_samp_factor, TRUE);
  151430. }
  151431. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  151432. yoffset++) {
  151433. for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
  151434. MCU_col_num++) {
  151435. blkn = 0; /* index of current DCT block within MCU */
  151436. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  151437. compptr = cinfo->cur_comp_info[ci];
  151438. start_col = MCU_col_num * compptr->MCU_width;
  151439. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  151440. buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
  151441. for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
  151442. coef->MCU_buffer[blkn++] = buffer_ptr++;
  151443. }
  151444. }
  151445. }
  151446. if (! (*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
  151447. coef->MCU_vert_offset = yoffset;
  151448. coef->MCU_ctr = MCU_col_num;
  151449. return JPEG_SUSPENDED;
  151450. }
  151451. }
  151452. coef->MCU_ctr = 0;
  151453. }
  151454. if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
  151455. start_iMCU_row3(cinfo);
  151456. return JPEG_ROW_COMPLETED;
  151457. }
  151458. (*cinfo->inputctl->finish_input_pass) (cinfo);
  151459. return JPEG_SCAN_COMPLETED;
  151460. }
  151461. METHODDEF(int)
  151462. decompress_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
  151463. {
  151464. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151465. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  151466. JDIMENSION block_num;
  151467. int ci, block_row, block_rows;
  151468. JBLOCKARRAY buffer;
  151469. JBLOCKROW buffer_ptr;
  151470. JSAMPARRAY output_ptr;
  151471. JDIMENSION output_col;
  151472. jpeg_component_info *compptr;
  151473. inverse_DCT_method_ptr inverse_DCT;
  151474. while (cinfo->input_scan_number < cinfo->output_scan_number ||
  151475. (cinfo->input_scan_number == cinfo->output_scan_number &&
  151476. cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) {
  151477. if ((*cinfo->inputctl->consume_input)(cinfo) == JPEG_SUSPENDED)
  151478. return JPEG_SUSPENDED;
  151479. }
  151480. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151481. ci++, compptr++) {
  151482. if (! compptr->component_needed)
  151483. continue;
  151484. buffer = (*cinfo->mem->access_virt_barray)
  151485. ((j_common_ptr) cinfo, coef->whole_image[ci],
  151486. cinfo->output_iMCU_row * compptr->v_samp_factor,
  151487. (JDIMENSION) compptr->v_samp_factor, FALSE);
  151488. if (cinfo->output_iMCU_row < last_iMCU_row)
  151489. block_rows = compptr->v_samp_factor;
  151490. else {
  151491. block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  151492. if (block_rows == 0) block_rows = compptr->v_samp_factor;
  151493. }
  151494. inverse_DCT = cinfo->idct->inverse_DCT[ci];
  151495. output_ptr = output_buf[ci];
  151496. for (block_row = 0; block_row < block_rows; block_row++) {
  151497. buffer_ptr = buffer[block_row];
  151498. output_col = 0;
  151499. for (block_num = 0; block_num < compptr->width_in_blocks; block_num++) {
  151500. (*inverse_DCT) (cinfo, compptr, (JCOEFPTR) buffer_ptr,
  151501. output_ptr, output_col);
  151502. buffer_ptr++;
  151503. output_col += compptr->DCT_scaled_size;
  151504. }
  151505. output_ptr += compptr->DCT_scaled_size;
  151506. }
  151507. }
  151508. if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
  151509. return JPEG_ROW_COMPLETED;
  151510. return JPEG_SCAN_COMPLETED;
  151511. }
  151512. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  151513. #ifdef BLOCK_SMOOTHING_SUPPORTED
  151514. #define Q01_POS 1
  151515. #define Q10_POS 8
  151516. #define Q20_POS 16
  151517. #define Q11_POS 9
  151518. #define Q02_POS 2
  151519. LOCAL(boolean)
  151520. smoothing_ok (j_decompress_ptr cinfo)
  151521. {
  151522. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151523. boolean smoothing_useful = FALSE;
  151524. int ci, coefi;
  151525. jpeg_component_info *compptr;
  151526. JQUANT_TBL * qtable;
  151527. int * coef_bits;
  151528. int * coef_bits_latch;
  151529. if (! cinfo->progressive_mode || cinfo->coef_bits == NULL)
  151530. return FALSE;
  151531. if (coef->coef_bits_latch == NULL)
  151532. coef->coef_bits_latch = (int *)
  151533. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151534. cinfo->num_components *
  151535. (SAVED_COEFS * SIZEOF(int)));
  151536. coef_bits_latch = coef->coef_bits_latch;
  151537. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151538. ci++, compptr++) {
  151539. if ((qtable = compptr->quant_table) == NULL)
  151540. return FALSE;
  151541. if (qtable->quantval[0] == 0 ||
  151542. qtable->quantval[Q01_POS] == 0 ||
  151543. qtable->quantval[Q10_POS] == 0 ||
  151544. qtable->quantval[Q20_POS] == 0 ||
  151545. qtable->quantval[Q11_POS] == 0 ||
  151546. qtable->quantval[Q02_POS] == 0)
  151547. return FALSE;
  151548. coef_bits = cinfo->coef_bits[ci];
  151549. if (coef_bits[0] < 0)
  151550. return FALSE;
  151551. for (coefi = 1; coefi <= 5; coefi++) {
  151552. coef_bits_latch[coefi] = coef_bits[coefi];
  151553. if (coef_bits[coefi] != 0)
  151554. smoothing_useful = TRUE;
  151555. }
  151556. coef_bits_latch += SAVED_COEFS;
  151557. }
  151558. return smoothing_useful;
  151559. }
  151560. METHODDEF(int)
  151561. decompress_smooth_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
  151562. {
  151563. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151564. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  151565. JDIMENSION block_num, last_block_column;
  151566. int ci, block_row, block_rows, access_rows;
  151567. JBLOCKARRAY buffer;
  151568. JBLOCKROW buffer_ptr, prev_block_row, next_block_row;
  151569. JSAMPARRAY output_ptr;
  151570. JDIMENSION output_col;
  151571. jpeg_component_info *compptr;
  151572. inverse_DCT_method_ptr inverse_DCT;
  151573. boolean first_row, last_row;
  151574. JBLOCK workspace;
  151575. int *coef_bits;
  151576. JQUANT_TBL *quanttbl;
  151577. INT32 Q00,Q01,Q02,Q10,Q11,Q20, num;
  151578. int DC1,DC2,DC3,DC4,DC5,DC6,DC7,DC8,DC9;
  151579. int Al, pred;
  151580. while (cinfo->input_scan_number <= cinfo->output_scan_number &&
  151581. ! cinfo->inputctl->eoi_reached) {
  151582. if (cinfo->input_scan_number == cinfo->output_scan_number) {
  151583. JDIMENSION delta = (cinfo->Ss == 0) ? 1 : 0;
  151584. if (cinfo->input_iMCU_row > cinfo->output_iMCU_row+delta)
  151585. break;
  151586. }
  151587. if ((*cinfo->inputctl->consume_input)(cinfo) == JPEG_SUSPENDED)
  151588. return JPEG_SUSPENDED;
  151589. }
  151590. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151591. ci++, compptr++) {
  151592. if (! compptr->component_needed)
  151593. continue;
  151594. if (cinfo->output_iMCU_row < last_iMCU_row) {
  151595. block_rows = compptr->v_samp_factor;
  151596. access_rows = block_rows * 2; /* this and next iMCU row */
  151597. last_row = FALSE;
  151598. } else {
  151599. block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  151600. if (block_rows == 0) block_rows = compptr->v_samp_factor;
  151601. access_rows = block_rows; /* this iMCU row only */
  151602. last_row = TRUE;
  151603. }
  151604. if (cinfo->output_iMCU_row > 0) {
  151605. access_rows += compptr->v_samp_factor; /* prior iMCU row too */
  151606. buffer = (*cinfo->mem->access_virt_barray)
  151607. ((j_common_ptr) cinfo, coef->whole_image[ci],
  151608. (cinfo->output_iMCU_row - 1) * compptr->v_samp_factor,
  151609. (JDIMENSION) access_rows, FALSE);
  151610. buffer += compptr->v_samp_factor; /* point to current iMCU row */
  151611. first_row = FALSE;
  151612. } else {
  151613. buffer = (*cinfo->mem->access_virt_barray)
  151614. ((j_common_ptr) cinfo, coef->whole_image[ci],
  151615. (JDIMENSION) 0, (JDIMENSION) access_rows, FALSE);
  151616. first_row = TRUE;
  151617. }
  151618. coef_bits = coef->coef_bits_latch + (ci * SAVED_COEFS);
  151619. quanttbl = compptr->quant_table;
  151620. Q00 = quanttbl->quantval[0];
  151621. Q01 = quanttbl->quantval[Q01_POS];
  151622. Q10 = quanttbl->quantval[Q10_POS];
  151623. Q20 = quanttbl->quantval[Q20_POS];
  151624. Q11 = quanttbl->quantval[Q11_POS];
  151625. Q02 = quanttbl->quantval[Q02_POS];
  151626. inverse_DCT = cinfo->idct->inverse_DCT[ci];
  151627. output_ptr = output_buf[ci];
  151628. for (block_row = 0; block_row < block_rows; block_row++) {
  151629. buffer_ptr = buffer[block_row];
  151630. if (first_row && block_row == 0)
  151631. prev_block_row = buffer_ptr;
  151632. else
  151633. prev_block_row = buffer[block_row-1];
  151634. if (last_row && block_row == block_rows-1)
  151635. next_block_row = buffer_ptr;
  151636. else
  151637. next_block_row = buffer[block_row+1];
  151638. DC1 = DC2 = DC3 = (int) prev_block_row[0][0];
  151639. DC4 = DC5 = DC6 = (int) buffer_ptr[0][0];
  151640. DC7 = DC8 = DC9 = (int) next_block_row[0][0];
  151641. output_col = 0;
  151642. last_block_column = compptr->width_in_blocks - 1;
  151643. for (block_num = 0; block_num <= last_block_column; block_num++) {
  151644. jcopy_block_row(buffer_ptr, (JBLOCKROW) workspace, (JDIMENSION) 1);
  151645. if (block_num < last_block_column) {
  151646. DC3 = (int) prev_block_row[1][0];
  151647. DC6 = (int) buffer_ptr[1][0];
  151648. DC9 = (int) next_block_row[1][0];
  151649. }
  151650. if ((Al=coef_bits[1]) != 0 && workspace[1] == 0) {
  151651. num = 36 * Q00 * (DC4 - DC6);
  151652. if (num >= 0) {
  151653. pred = (int) (((Q01<<7) + num) / (Q01<<8));
  151654. if (Al > 0 && pred >= (1<<Al))
  151655. pred = (1<<Al)-1;
  151656. } else {
  151657. pred = (int) (((Q01<<7) - num) / (Q01<<8));
  151658. if (Al > 0 && pred >= (1<<Al))
  151659. pred = (1<<Al)-1;
  151660. pred = -pred;
  151661. }
  151662. workspace[1] = (JCOEF) pred;
  151663. }
  151664. if ((Al=coef_bits[2]) != 0 && workspace[8] == 0) {
  151665. num = 36 * Q00 * (DC2 - DC8);
  151666. if (num >= 0) {
  151667. pred = (int) (((Q10<<7) + num) / (Q10<<8));
  151668. if (Al > 0 && pred >= (1<<Al))
  151669. pred = (1<<Al)-1;
  151670. } else {
  151671. pred = (int) (((Q10<<7) - num) / (Q10<<8));
  151672. if (Al > 0 && pred >= (1<<Al))
  151673. pred = (1<<Al)-1;
  151674. pred = -pred;
  151675. }
  151676. workspace[8] = (JCOEF) pred;
  151677. }
  151678. if ((Al=coef_bits[3]) != 0 && workspace[16] == 0) {
  151679. num = 9 * Q00 * (DC2 + DC8 - 2*DC5);
  151680. if (num >= 0) {
  151681. pred = (int) (((Q20<<7) + num) / (Q20<<8));
  151682. if (Al > 0 && pred >= (1<<Al))
  151683. pred = (1<<Al)-1;
  151684. } else {
  151685. pred = (int) (((Q20<<7) - num) / (Q20<<8));
  151686. if (Al > 0 && pred >= (1<<Al))
  151687. pred = (1<<Al)-1;
  151688. pred = -pred;
  151689. }
  151690. workspace[16] = (JCOEF) pred;
  151691. }
  151692. if ((Al=coef_bits[4]) != 0 && workspace[9] == 0) {
  151693. num = 5 * Q00 * (DC1 - DC3 - DC7 + DC9);
  151694. if (num >= 0) {
  151695. pred = (int) (((Q11<<7) + num) / (Q11<<8));
  151696. if (Al > 0 && pred >= (1<<Al))
  151697. pred = (1<<Al)-1;
  151698. } else {
  151699. pred = (int) (((Q11<<7) - num) / (Q11<<8));
  151700. if (Al > 0 && pred >= (1<<Al))
  151701. pred = (1<<Al)-1;
  151702. pred = -pred;
  151703. }
  151704. workspace[9] = (JCOEF) pred;
  151705. }
  151706. if ((Al=coef_bits[5]) != 0 && workspace[2] == 0) {
  151707. num = 9 * Q00 * (DC4 + DC6 - 2*DC5);
  151708. if (num >= 0) {
  151709. pred = (int) (((Q02<<7) + num) / (Q02<<8));
  151710. if (Al > 0 && pred >= (1<<Al))
  151711. pred = (1<<Al)-1;
  151712. } else {
  151713. pred = (int) (((Q02<<7) - num) / (Q02<<8));
  151714. if (Al > 0 && pred >= (1<<Al))
  151715. pred = (1<<Al)-1;
  151716. pred = -pred;
  151717. }
  151718. workspace[2] = (JCOEF) pred;
  151719. }
  151720. (*inverse_DCT) (cinfo, compptr, (JCOEFPTR) workspace,
  151721. output_ptr, output_col);
  151722. DC1 = DC2; DC2 = DC3;
  151723. DC4 = DC5; DC5 = DC6;
  151724. DC7 = DC8; DC8 = DC9;
  151725. buffer_ptr++, prev_block_row++, next_block_row++;
  151726. output_col += compptr->DCT_scaled_size;
  151727. }
  151728. output_ptr += compptr->DCT_scaled_size;
  151729. }
  151730. }
  151731. if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
  151732. return JPEG_ROW_COMPLETED;
  151733. return JPEG_SCAN_COMPLETED;
  151734. }
  151735. #endif /* BLOCK_SMOOTHING_SUPPORTED */
  151736. GLOBAL(void)
  151737. jinit_d_coef_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
  151738. {
  151739. my_coef_ptr3 coef;
  151740. coef = (my_coef_ptr3)
  151741. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151742. SIZEOF(my_coef_controller3));
  151743. cinfo->coef = (struct jpeg_d_coef_controller *) coef;
  151744. coef->pub.start_input_pass = start_input_pass;
  151745. coef->pub.start_output_pass = start_output_pass;
  151746. #ifdef BLOCK_SMOOTHING_SUPPORTED
  151747. coef->coef_bits_latch = NULL;
  151748. #endif
  151749. if (need_full_buffer) {
  151750. #ifdef D_MULTISCAN_FILES_SUPPORTED
  151751. int ci, access_rows;
  151752. jpeg_component_info *compptr;
  151753. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151754. ci++, compptr++) {
  151755. access_rows = compptr->v_samp_factor;
  151756. #ifdef BLOCK_SMOOTHING_SUPPORTED
  151757. if (cinfo->progressive_mode)
  151758. access_rows *= 3;
  151759. #endif
  151760. coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
  151761. ((j_common_ptr) cinfo, JPOOL_IMAGE, TRUE,
  151762. (JDIMENSION) jround_up((long) compptr->width_in_blocks,
  151763. (long) compptr->h_samp_factor),
  151764. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  151765. (long) compptr->v_samp_factor),
  151766. (JDIMENSION) access_rows);
  151767. }
  151768. coef->pub.consume_data = consume_data;
  151769. coef->pub.decompress_data = decompress_data;
  151770. coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */
  151771. #else
  151772. ERREXIT(cinfo, JERR_NOT_COMPILED);
  151773. #endif
  151774. } else {
  151775. JBLOCKROW buffer;
  151776. int i;
  151777. buffer = (JBLOCKROW)
  151778. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151779. D_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
  151780. for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
  151781. coef->MCU_buffer[i] = buffer + i;
  151782. }
  151783. coef->pub.consume_data = dummy_consume_data;
  151784. coef->pub.decompress_data = decompress_onepass;
  151785. coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
  151786. }
  151787. }
  151788. /*** End of inlined file: jdcoefct.c ***/
  151789. #undef FIX
  151790. /*** Start of inlined file: jdcolor.c ***/
  151791. #define JPEG_INTERNALS
  151792. typedef struct {
  151793. struct jpeg_color_deconverter pub; /* public fields */
  151794. int * Cr_r_tab; /* => table for Cr to R conversion */
  151795. int * Cb_b_tab; /* => table for Cb to B conversion */
  151796. INT32 * Cr_g_tab; /* => table for Cr to G conversion */
  151797. INT32 * Cb_g_tab; /* => table for Cb to G conversion */
  151798. } my_color_deconverter2;
  151799. typedef my_color_deconverter2 * my_cconvert_ptr2;
  151800. #define SCALEBITS 16 /* speediest right-shift on some machines */
  151801. #define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
  151802. #define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
  151803. LOCAL(void)
  151804. build_ycc_rgb_table (j_decompress_ptr cinfo)
  151805. {
  151806. my_cconvert_ptr2 cconvert = (my_cconvert_ptr2) cinfo->cconvert;
  151807. int i;
  151808. INT32 x;
  151809. SHIFT_TEMPS
  151810. cconvert->Cr_r_tab = (int *)
  151811. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151812. (MAXJSAMPLE+1) * SIZEOF(int));
  151813. cconvert->Cb_b_tab = (int *)
  151814. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151815. (MAXJSAMPLE+1) * SIZEOF(int));
  151816. cconvert->Cr_g_tab = (INT32 *)
  151817. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151818. (MAXJSAMPLE+1) * SIZEOF(INT32));
  151819. cconvert->Cb_g_tab = (INT32 *)
  151820. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151821. (MAXJSAMPLE+1) * SIZEOF(INT32));
  151822. for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) {
  151823. cconvert->Cr_r_tab[i] = (int)
  151824. RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS);
  151825. cconvert->Cb_b_tab[i] = (int)
  151826. RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS);
  151827. cconvert->Cr_g_tab[i] = (- FIX(0.71414)) * x;
  151828. cconvert->Cb_g_tab[i] = (- FIX(0.34414)) * x + ONE_HALF;
  151829. }
  151830. }
  151831. METHODDEF(void)
  151832. ycc_rgb_convert (j_decompress_ptr cinfo,
  151833. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151834. JSAMPARRAY output_buf, int num_rows)
  151835. {
  151836. my_cconvert_ptr2 cconvert = (my_cconvert_ptr2) cinfo->cconvert;
  151837. register int y, cb, cr;
  151838. register JSAMPROW outptr;
  151839. register JSAMPROW inptr0, inptr1, inptr2;
  151840. register JDIMENSION col;
  151841. JDIMENSION num_cols = cinfo->output_width;
  151842. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  151843. register int * Crrtab = cconvert->Cr_r_tab;
  151844. register int * Cbbtab = cconvert->Cb_b_tab;
  151845. register INT32 * Crgtab = cconvert->Cr_g_tab;
  151846. register INT32 * Cbgtab = cconvert->Cb_g_tab;
  151847. SHIFT_TEMPS
  151848. while (--num_rows >= 0) {
  151849. inptr0 = input_buf[0][input_row];
  151850. inptr1 = input_buf[1][input_row];
  151851. inptr2 = input_buf[2][input_row];
  151852. input_row++;
  151853. outptr = *output_buf++;
  151854. for (col = 0; col < num_cols; col++) {
  151855. y = GETJSAMPLE(inptr0[col]);
  151856. cb = GETJSAMPLE(inptr1[col]);
  151857. cr = GETJSAMPLE(inptr2[col]);
  151858. outptr[RGB_RED] = range_limit[y + Crrtab[cr]];
  151859. outptr[RGB_GREEN] = range_limit[y +
  151860. ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
  151861. SCALEBITS))];
  151862. outptr[RGB_BLUE] = range_limit[y + Cbbtab[cb]];
  151863. outptr += RGB_PIXELSIZE;
  151864. }
  151865. }
  151866. }
  151867. METHODDEF(void)
  151868. null_convert2 (j_decompress_ptr cinfo,
  151869. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151870. JSAMPARRAY output_buf, int num_rows)
  151871. {
  151872. register JSAMPROW inptr, outptr;
  151873. register JDIMENSION count;
  151874. register int num_components = cinfo->num_components;
  151875. JDIMENSION num_cols = cinfo->output_width;
  151876. int ci;
  151877. while (--num_rows >= 0) {
  151878. for (ci = 0; ci < num_components; ci++) {
  151879. inptr = input_buf[ci][input_row];
  151880. outptr = output_buf[0] + ci;
  151881. for (count = num_cols; count > 0; count--) {
  151882. *outptr = *inptr++; /* needn't bother with GETJSAMPLE() here */
  151883. outptr += num_components;
  151884. }
  151885. }
  151886. input_row++;
  151887. output_buf++;
  151888. }
  151889. }
  151890. METHODDEF(void)
  151891. grayscale_convert2 (j_decompress_ptr cinfo,
  151892. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151893. JSAMPARRAY output_buf, int num_rows)
  151894. {
  151895. jcopy_sample_rows(input_buf[0], (int) input_row, output_buf, 0,
  151896. num_rows, cinfo->output_width);
  151897. }
  151898. METHODDEF(void)
  151899. gray_rgb_convert (j_decompress_ptr cinfo,
  151900. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151901. JSAMPARRAY output_buf, int num_rows)
  151902. {
  151903. register JSAMPROW inptr, outptr;
  151904. register JDIMENSION col;
  151905. JDIMENSION num_cols = cinfo->output_width;
  151906. while (--num_rows >= 0) {
  151907. inptr = input_buf[0][input_row++];
  151908. outptr = *output_buf++;
  151909. for (col = 0; col < num_cols; col++) {
  151910. outptr[RGB_RED] = outptr[RGB_GREEN] = outptr[RGB_BLUE] = inptr[col];
  151911. outptr += RGB_PIXELSIZE;
  151912. }
  151913. }
  151914. }
  151915. METHODDEF(void)
  151916. ycck_cmyk_convert (j_decompress_ptr cinfo,
  151917. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151918. JSAMPARRAY output_buf, int num_rows)
  151919. {
  151920. my_cconvert_ptr2 cconvert = (my_cconvert_ptr2) cinfo->cconvert;
  151921. register int y, cb, cr;
  151922. register JSAMPROW outptr;
  151923. register JSAMPROW inptr0, inptr1, inptr2, inptr3;
  151924. register JDIMENSION col;
  151925. JDIMENSION num_cols = cinfo->output_width;
  151926. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  151927. register int * Crrtab = cconvert->Cr_r_tab;
  151928. register int * Cbbtab = cconvert->Cb_b_tab;
  151929. register INT32 * Crgtab = cconvert->Cr_g_tab;
  151930. register INT32 * Cbgtab = cconvert->Cb_g_tab;
  151931. SHIFT_TEMPS
  151932. while (--num_rows >= 0) {
  151933. inptr0 = input_buf[0][input_row];
  151934. inptr1 = input_buf[1][input_row];
  151935. inptr2 = input_buf[2][input_row];
  151936. inptr3 = input_buf[3][input_row];
  151937. input_row++;
  151938. outptr = *output_buf++;
  151939. for (col = 0; col < num_cols; col++) {
  151940. y = GETJSAMPLE(inptr0[col]);
  151941. cb = GETJSAMPLE(inptr1[col]);
  151942. cr = GETJSAMPLE(inptr2[col]);
  151943. outptr[0] = range_limit[MAXJSAMPLE - (y + Crrtab[cr])]; /* red */
  151944. outptr[1] = range_limit[MAXJSAMPLE - (y + /* green */
  151945. ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
  151946. SCALEBITS)))];
  151947. outptr[2] = range_limit[MAXJSAMPLE - (y + Cbbtab[cb])]; /* blue */
  151948. outptr[3] = inptr3[col]; /* don't need GETJSAMPLE here */
  151949. outptr += 4;
  151950. }
  151951. }
  151952. }
  151953. METHODDEF(void)
  151954. start_pass_dcolor (j_decompress_ptr cinfo)
  151955. {
  151956. }
  151957. GLOBAL(void)
  151958. jinit_color_deconverter (j_decompress_ptr cinfo)
  151959. {
  151960. my_cconvert_ptr2 cconvert;
  151961. int ci;
  151962. cconvert = (my_cconvert_ptr2)
  151963. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151964. SIZEOF(my_color_deconverter2));
  151965. cinfo->cconvert = (struct jpeg_color_deconverter *) cconvert;
  151966. cconvert->pub.start_pass = start_pass_dcolor;
  151967. switch (cinfo->jpeg_color_space) {
  151968. case JCS_GRAYSCALE:
  151969. if (cinfo->num_components != 1)
  151970. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  151971. break;
  151972. case JCS_RGB:
  151973. case JCS_YCbCr:
  151974. if (cinfo->num_components != 3)
  151975. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  151976. break;
  151977. case JCS_CMYK:
  151978. case JCS_YCCK:
  151979. if (cinfo->num_components != 4)
  151980. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  151981. break;
  151982. default: /* JCS_UNKNOWN can be anything */
  151983. if (cinfo->num_components < 1)
  151984. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  151985. break;
  151986. }
  151987. switch (cinfo->out_color_space) {
  151988. case JCS_GRAYSCALE:
  151989. cinfo->out_color_components = 1;
  151990. if (cinfo->jpeg_color_space == JCS_GRAYSCALE ||
  151991. cinfo->jpeg_color_space == JCS_YCbCr) {
  151992. cconvert->pub.color_convert = grayscale_convert2;
  151993. for (ci = 1; ci < cinfo->num_components; ci++)
  151994. cinfo->comp_info[ci].component_needed = FALSE;
  151995. } else
  151996. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  151997. break;
  151998. case JCS_RGB:
  151999. cinfo->out_color_components = RGB_PIXELSIZE;
  152000. if (cinfo->jpeg_color_space == JCS_YCbCr) {
  152001. cconvert->pub.color_convert = ycc_rgb_convert;
  152002. build_ycc_rgb_table(cinfo);
  152003. } else if (cinfo->jpeg_color_space == JCS_GRAYSCALE) {
  152004. cconvert->pub.color_convert = gray_rgb_convert;
  152005. } else if (cinfo->jpeg_color_space == JCS_RGB && RGB_PIXELSIZE == 3) {
  152006. cconvert->pub.color_convert = null_convert2;
  152007. } else
  152008. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  152009. break;
  152010. case JCS_CMYK:
  152011. cinfo->out_color_components = 4;
  152012. if (cinfo->jpeg_color_space == JCS_YCCK) {
  152013. cconvert->pub.color_convert = ycck_cmyk_convert;
  152014. build_ycc_rgb_table(cinfo);
  152015. } else if (cinfo->jpeg_color_space == JCS_CMYK) {
  152016. cconvert->pub.color_convert = null_convert2;
  152017. } else
  152018. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  152019. break;
  152020. default:
  152021. if (cinfo->out_color_space == cinfo->jpeg_color_space) {
  152022. cinfo->out_color_components = cinfo->num_components;
  152023. cconvert->pub.color_convert = null_convert2;
  152024. } else /* unsupported non-null conversion */
  152025. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  152026. break;
  152027. }
  152028. if (cinfo->quantize_colors)
  152029. cinfo->output_components = 1; /* single colormapped output component */
  152030. else
  152031. cinfo->output_components = cinfo->out_color_components;
  152032. }
  152033. /*** End of inlined file: jdcolor.c ***/
  152034. #undef FIX
  152035. /*** Start of inlined file: jddctmgr.c ***/
  152036. #define JPEG_INTERNALS
  152037. typedef struct {
  152038. struct jpeg_inverse_dct pub; /* public fields */
  152039. int cur_method[MAX_COMPONENTS];
  152040. } my_idct_controller;
  152041. typedef my_idct_controller * my_idct_ptr;
  152042. typedef union {
  152043. ISLOW_MULT_TYPE islow_array[DCTSIZE2];
  152044. #ifdef DCT_IFAST_SUPPORTED
  152045. IFAST_MULT_TYPE ifast_array[DCTSIZE2];
  152046. #endif
  152047. #ifdef DCT_FLOAT_SUPPORTED
  152048. FLOAT_MULT_TYPE float_array[DCTSIZE2];
  152049. #endif
  152050. } multiplier_table;
  152051. #ifdef DCT_ISLOW_SUPPORTED
  152052. #define PROVIDE_ISLOW_TABLES
  152053. #else
  152054. #ifdef IDCT_SCALING_SUPPORTED
  152055. #define PROVIDE_ISLOW_TABLES
  152056. #endif
  152057. #endif
  152058. METHODDEF(void)
  152059. start_pass (j_decompress_ptr cinfo)
  152060. {
  152061. my_idct_ptr idct = (my_idct_ptr) cinfo->idct;
  152062. int ci, i;
  152063. jpeg_component_info *compptr;
  152064. int method = 0;
  152065. inverse_DCT_method_ptr method_ptr = NULL;
  152066. JQUANT_TBL * qtbl;
  152067. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152068. ci++, compptr++) {
  152069. switch (compptr->DCT_scaled_size) {
  152070. #ifdef IDCT_SCALING_SUPPORTED
  152071. case 1:
  152072. method_ptr = jpeg_idct_1x1;
  152073. method = JDCT_ISLOW; /* jidctred uses islow-style table */
  152074. break;
  152075. case 2:
  152076. method_ptr = jpeg_idct_2x2;
  152077. method = JDCT_ISLOW; /* jidctred uses islow-style table */
  152078. break;
  152079. case 4:
  152080. method_ptr = jpeg_idct_4x4;
  152081. method = JDCT_ISLOW; /* jidctred uses islow-style table */
  152082. break;
  152083. #endif
  152084. case DCTSIZE:
  152085. switch (cinfo->dct_method) {
  152086. #ifdef DCT_ISLOW_SUPPORTED
  152087. case JDCT_ISLOW:
  152088. method_ptr = jpeg_idct_islow;
  152089. method = JDCT_ISLOW;
  152090. break;
  152091. #endif
  152092. #ifdef DCT_IFAST_SUPPORTED
  152093. case JDCT_IFAST:
  152094. method_ptr = jpeg_idct_ifast;
  152095. method = JDCT_IFAST;
  152096. break;
  152097. #endif
  152098. #ifdef DCT_FLOAT_SUPPORTED
  152099. case JDCT_FLOAT:
  152100. method_ptr = jpeg_idct_float;
  152101. method = JDCT_FLOAT;
  152102. break;
  152103. #endif
  152104. default:
  152105. ERREXIT(cinfo, JERR_NOT_COMPILED);
  152106. break;
  152107. }
  152108. break;
  152109. default:
  152110. ERREXIT1(cinfo, JERR_BAD_DCTSIZE, compptr->DCT_scaled_size);
  152111. break;
  152112. }
  152113. idct->pub.inverse_DCT[ci] = method_ptr;
  152114. if (! compptr->component_needed || idct->cur_method[ci] == method)
  152115. continue;
  152116. qtbl = compptr->quant_table;
  152117. if (qtbl == NULL) /* happens if no data yet for component */
  152118. continue;
  152119. idct->cur_method[ci] = method;
  152120. switch (method) {
  152121. #ifdef PROVIDE_ISLOW_TABLES
  152122. case JDCT_ISLOW:
  152123. {
  152124. ISLOW_MULT_TYPE * ismtbl = (ISLOW_MULT_TYPE *) compptr->dct_table;
  152125. for (i = 0; i < DCTSIZE2; i++) {
  152126. ismtbl[i] = (ISLOW_MULT_TYPE) qtbl->quantval[i];
  152127. }
  152128. }
  152129. break;
  152130. #endif
  152131. #ifdef DCT_IFAST_SUPPORTED
  152132. case JDCT_IFAST:
  152133. {
  152134. IFAST_MULT_TYPE * ifmtbl = (IFAST_MULT_TYPE *) compptr->dct_table;
  152135. #define CONST_BITS 14
  152136. static const INT16 aanscales[DCTSIZE2] = {
  152137. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  152138. 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270,
  152139. 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906,
  152140. 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315,
  152141. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  152142. 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552,
  152143. 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446,
  152144. 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247
  152145. };
  152146. SHIFT_TEMPS
  152147. for (i = 0; i < DCTSIZE2; i++) {
  152148. ifmtbl[i] = (IFAST_MULT_TYPE)
  152149. DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i],
  152150. (INT32) aanscales[i]),
  152151. CONST_BITS-IFAST_SCALE_BITS);
  152152. }
  152153. }
  152154. break;
  152155. #endif
  152156. #ifdef DCT_FLOAT_SUPPORTED
  152157. case JDCT_FLOAT:
  152158. {
  152159. FLOAT_MULT_TYPE * fmtbl = (FLOAT_MULT_TYPE *) compptr->dct_table;
  152160. int row, col;
  152161. static const double aanscalefactor[DCTSIZE] = {
  152162. 1.0, 1.387039845, 1.306562965, 1.175875602,
  152163. 1.0, 0.785694958, 0.541196100, 0.275899379
  152164. };
  152165. i = 0;
  152166. for (row = 0; row < DCTSIZE; row++) {
  152167. for (col = 0; col < DCTSIZE; col++) {
  152168. fmtbl[i] = (FLOAT_MULT_TYPE)
  152169. ((double) qtbl->quantval[i] *
  152170. aanscalefactor[row] * aanscalefactor[col]);
  152171. i++;
  152172. }
  152173. }
  152174. }
  152175. break;
  152176. #endif
  152177. default:
  152178. ERREXIT(cinfo, JERR_NOT_COMPILED);
  152179. break;
  152180. }
  152181. }
  152182. }
  152183. GLOBAL(void)
  152184. jinit_inverse_dct (j_decompress_ptr cinfo)
  152185. {
  152186. my_idct_ptr idct;
  152187. int ci;
  152188. jpeg_component_info *compptr;
  152189. idct = (my_idct_ptr)
  152190. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152191. SIZEOF(my_idct_controller));
  152192. cinfo->idct = (struct jpeg_inverse_dct *) idct;
  152193. idct->pub.start_pass = start_pass;
  152194. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152195. ci++, compptr++) {
  152196. compptr->dct_table =
  152197. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152198. SIZEOF(multiplier_table));
  152199. MEMZERO(compptr->dct_table, SIZEOF(multiplier_table));
  152200. idct->cur_method[ci] = -1;
  152201. }
  152202. }
  152203. /*** End of inlined file: jddctmgr.c ***/
  152204. #undef CONST_BITS
  152205. #undef ASSIGN_STATE
  152206. /*** Start of inlined file: jdhuff.c ***/
  152207. #define JPEG_INTERNALS
  152208. /*** Start of inlined file: jdhuff.h ***/
  152209. #ifndef __jdhuff_h__
  152210. #define __jdhuff_h__
  152211. #ifdef NEED_SHORT_EXTERNAL_NAMES
  152212. #define jpeg_make_d_derived_tbl jMkDDerived
  152213. #define jpeg_fill_bit_buffer jFilBitBuf
  152214. #define jpeg_huff_decode jHufDecode
  152215. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  152216. #define HUFF_LOOKAHEAD 8 /* # of bits of lookahead */
  152217. typedef struct {
  152218. INT32 maxcode[18]; /* largest code of length k (-1 if none) */
  152219. INT32 valoffset[17]; /* huffval[] offset for codes of length k */
  152220. JHUFF_TBL *pub;
  152221. int look_nbits[1<<HUFF_LOOKAHEAD]; /* # bits, or 0 if too long */
  152222. UINT8 look_sym[1<<HUFF_LOOKAHEAD]; /* symbol, or unused */
  152223. } d_derived_tbl;
  152224. EXTERN(void) jpeg_make_d_derived_tbl
  152225. JPP((j_decompress_ptr cinfo, boolean isDC, int tblno,
  152226. d_derived_tbl ** pdtbl));
  152227. typedef INT32 bit_buf_type; /* type of bit-extraction buffer */
  152228. #define BIT_BUF_SIZE 32 /* size of buffer in bits */
  152229. typedef struct { /* Bitreading state saved across MCUs */
  152230. bit_buf_type get_buffer; /* current bit-extraction buffer */
  152231. int bits_left; /* # of unused bits in it */
  152232. } bitread_perm_state;
  152233. typedef struct { /* Bitreading working state within an MCU */
  152234. const JOCTET * next_input_byte; /* => next byte to read from source */
  152235. size_t bytes_in_buffer; /* # of bytes remaining in source buffer */
  152236. bit_buf_type get_buffer; /* current bit-extraction buffer */
  152237. int bits_left; /* # of unused bits in it */
  152238. j_decompress_ptr cinfo; /* back link to decompress master record */
  152239. } bitread_working_state;
  152240. #define BITREAD_STATE_VARS \
  152241. register bit_buf_type get_buffer; \
  152242. register int bits_left; \
  152243. bitread_working_state br_state
  152244. #define BITREAD_LOAD_STATE(cinfop,permstate) \
  152245. br_state.cinfo = cinfop; \
  152246. br_state.next_input_byte = cinfop->src->next_input_byte; \
  152247. br_state.bytes_in_buffer = cinfop->src->bytes_in_buffer; \
  152248. get_buffer = permstate.get_buffer; \
  152249. bits_left = permstate.bits_left;
  152250. #define BITREAD_SAVE_STATE(cinfop,permstate) \
  152251. cinfop->src->next_input_byte = br_state.next_input_byte; \
  152252. cinfop->src->bytes_in_buffer = br_state.bytes_in_buffer; \
  152253. permstate.get_buffer = get_buffer; \
  152254. permstate.bits_left = bits_left
  152255. #define CHECK_BIT_BUFFER(state,nbits,action) \
  152256. { if (bits_left < (nbits)) { \
  152257. if (! jpeg_fill_bit_buffer(&(state),get_buffer,bits_left,nbits)) \
  152258. { action; } \
  152259. get_buffer = (state).get_buffer; bits_left = (state).bits_left; } }
  152260. #define GET_BITS(nbits) \
  152261. (((int) (get_buffer >> (bits_left -= (nbits)))) & ((1<<(nbits))-1))
  152262. #define PEEK_BITS(nbits) \
  152263. (((int) (get_buffer >> (bits_left - (nbits)))) & ((1<<(nbits))-1))
  152264. #define DROP_BITS(nbits) \
  152265. (bits_left -= (nbits))
  152266. EXTERN(boolean) jpeg_fill_bit_buffer
  152267. JPP((bitread_working_state * state, register bit_buf_type get_buffer,
  152268. register int bits_left, int nbits));
  152269. #define HUFF_DECODE(result,state,htbl,failaction,slowlabel) \
  152270. { register int nb, look; \
  152271. if (bits_left < HUFF_LOOKAHEAD) { \
  152272. if (! jpeg_fill_bit_buffer(&state,get_buffer,bits_left, 0)) {failaction;} \
  152273. get_buffer = state.get_buffer; bits_left = state.bits_left; \
  152274. if (bits_left < HUFF_LOOKAHEAD) { \
  152275. nb = 1; goto slowlabel; \
  152276. } \
  152277. } \
  152278. look = PEEK_BITS(HUFF_LOOKAHEAD); \
  152279. if ((nb = htbl->look_nbits[look]) != 0) { \
  152280. DROP_BITS(nb); \
  152281. result = htbl->look_sym[look]; \
  152282. } else { \
  152283. nb = HUFF_LOOKAHEAD+1; \
  152284. slowlabel: \
  152285. if ((result=jpeg_huff_decode(&state,get_buffer,bits_left,htbl,nb)) < 0) \
  152286. { failaction; } \
  152287. get_buffer = state.get_buffer; bits_left = state.bits_left; \
  152288. } \
  152289. }
  152290. EXTERN(int) jpeg_huff_decode
  152291. JPP((bitread_working_state * state, register bit_buf_type get_buffer,
  152292. register int bits_left, d_derived_tbl * htbl, int min_bits));
  152293. #endif
  152294. /*** End of inlined file: jdhuff.h ***/
  152295. /* Declarations shared with jdphuff.c */
  152296. typedef struct {
  152297. int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
  152298. } savable_state2;
  152299. #ifndef NO_STRUCT_ASSIGN
  152300. #define ASSIGN_STATE(dest,src) ((dest) = (src))
  152301. #else
  152302. #if MAX_COMPS_IN_SCAN == 4
  152303. #define ASSIGN_STATE(dest,src) \
  152304. ((dest).last_dc_val[0] = (src).last_dc_val[0], \
  152305. (dest).last_dc_val[1] = (src).last_dc_val[1], \
  152306. (dest).last_dc_val[2] = (src).last_dc_val[2], \
  152307. (dest).last_dc_val[3] = (src).last_dc_val[3])
  152308. #endif
  152309. #endif
  152310. typedef struct {
  152311. struct jpeg_entropy_decoder pub; /* public fields */
  152312. bitread_perm_state bitstate; /* Bit buffer at start of MCU */
  152313. savable_state2 saved; /* Other state at start of MCU */
  152314. unsigned int restarts_to_go; /* MCUs left in this restart interval */
  152315. d_derived_tbl * dc_derived_tbls[NUM_HUFF_TBLS];
  152316. d_derived_tbl * ac_derived_tbls[NUM_HUFF_TBLS];
  152317. d_derived_tbl * dc_cur_tbls[D_MAX_BLOCKS_IN_MCU];
  152318. d_derived_tbl * ac_cur_tbls[D_MAX_BLOCKS_IN_MCU];
  152319. boolean dc_needed[D_MAX_BLOCKS_IN_MCU];
  152320. boolean ac_needed[D_MAX_BLOCKS_IN_MCU];
  152321. } huff_entropy_decoder2;
  152322. typedef huff_entropy_decoder2 * huff_entropy_ptr2;
  152323. METHODDEF(void)
  152324. start_pass_huff_decoder (j_decompress_ptr cinfo)
  152325. {
  152326. huff_entropy_ptr2 entropy = (huff_entropy_ptr2) cinfo->entropy;
  152327. int ci, blkn, dctbl, actbl;
  152328. jpeg_component_info * compptr;
  152329. if (cinfo->Ss != 0 || cinfo->Se != DCTSIZE2-1 ||
  152330. cinfo->Ah != 0 || cinfo->Al != 0)
  152331. WARNMS(cinfo, JWRN_NOT_SEQUENTIAL);
  152332. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  152333. compptr = cinfo->cur_comp_info[ci];
  152334. dctbl = compptr->dc_tbl_no;
  152335. actbl = compptr->ac_tbl_no;
  152336. jpeg_make_d_derived_tbl(cinfo, TRUE, dctbl,
  152337. & entropy->dc_derived_tbls[dctbl]);
  152338. jpeg_make_d_derived_tbl(cinfo, FALSE, actbl,
  152339. & entropy->ac_derived_tbls[actbl]);
  152340. entropy->saved.last_dc_val[ci] = 0;
  152341. }
  152342. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  152343. ci = cinfo->MCU_membership[blkn];
  152344. compptr = cinfo->cur_comp_info[ci];
  152345. entropy->dc_cur_tbls[blkn] = entropy->dc_derived_tbls[compptr->dc_tbl_no];
  152346. entropy->ac_cur_tbls[blkn] = entropy->ac_derived_tbls[compptr->ac_tbl_no];
  152347. if (compptr->component_needed) {
  152348. entropy->dc_needed[blkn] = TRUE;
  152349. entropy->ac_needed[blkn] = (compptr->DCT_scaled_size > 1);
  152350. } else {
  152351. entropy->dc_needed[blkn] = entropy->ac_needed[blkn] = FALSE;
  152352. }
  152353. }
  152354. entropy->bitstate.bits_left = 0;
  152355. entropy->bitstate.get_buffer = 0; /* unnecessary, but keeps Purify quiet */
  152356. entropy->pub.insufficient_data = FALSE;
  152357. entropy->restarts_to_go = cinfo->restart_interval;
  152358. }
  152359. GLOBAL(void)
  152360. jpeg_make_d_derived_tbl (j_decompress_ptr cinfo, boolean isDC, int tblno,
  152361. d_derived_tbl ** pdtbl)
  152362. {
  152363. JHUFF_TBL *htbl;
  152364. d_derived_tbl *dtbl;
  152365. int p, i, l, si, numsymbols;
  152366. int lookbits, ctr;
  152367. char huffsize[257];
  152368. unsigned int huffcode[257];
  152369. unsigned int code;
  152370. if (tblno < 0 || tblno >= NUM_HUFF_TBLS)
  152371. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  152372. htbl =
  152373. isDC ? cinfo->dc_huff_tbl_ptrs[tblno] : cinfo->ac_huff_tbl_ptrs[tblno];
  152374. if (htbl == NULL)
  152375. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  152376. if (*pdtbl == NULL)
  152377. *pdtbl = (d_derived_tbl *)
  152378. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152379. SIZEOF(d_derived_tbl));
  152380. dtbl = *pdtbl;
  152381. dtbl->pub = htbl; /* fill in back link */
  152382. p = 0;
  152383. for (l = 1; l <= 16; l++) {
  152384. i = (int) htbl->bits[l];
  152385. if (i < 0 || p + i > 256) /* protect against table overrun */
  152386. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  152387. while (i--)
  152388. huffsize[p++] = (char) l;
  152389. }
  152390. huffsize[p] = 0;
  152391. numsymbols = p;
  152392. code = 0;
  152393. si = huffsize[0];
  152394. p = 0;
  152395. while (huffsize[p]) {
  152396. while (((int) huffsize[p]) == si) {
  152397. huffcode[p++] = code;
  152398. code++;
  152399. }
  152400. if (((INT32) code) >= (((INT32) 1) << si))
  152401. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  152402. code <<= 1;
  152403. si++;
  152404. }
  152405. p = 0;
  152406. for (l = 1; l <= 16; l++) {
  152407. if (htbl->bits[l]) {
  152408. dtbl->valoffset[l] = (INT32) p - (INT32) huffcode[p];
  152409. p += htbl->bits[l];
  152410. dtbl->maxcode[l] = huffcode[p-1]; /* maximum code of length l */
  152411. } else {
  152412. dtbl->maxcode[l] = -1; /* -1 if no codes of this length */
  152413. }
  152414. }
  152415. dtbl->maxcode[17] = 0xFFFFFL; /* ensures jpeg_huff_decode terminates */
  152416. MEMZERO(dtbl->look_nbits, SIZEOF(dtbl->look_nbits));
  152417. p = 0;
  152418. for (l = 1; l <= HUFF_LOOKAHEAD; l++) {
  152419. for (i = 1; i <= (int) htbl->bits[l]; i++, p++) {
  152420. lookbits = huffcode[p] << (HUFF_LOOKAHEAD-l);
  152421. for (ctr = 1 << (HUFF_LOOKAHEAD-l); ctr > 0; ctr--) {
  152422. dtbl->look_nbits[lookbits] = l;
  152423. dtbl->look_sym[lookbits] = htbl->huffval[p];
  152424. lookbits++;
  152425. }
  152426. }
  152427. }
  152428. if (isDC) {
  152429. for (i = 0; i < numsymbols; i++) {
  152430. int sym = htbl->huffval[i];
  152431. if (sym < 0 || sym > 15)
  152432. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  152433. }
  152434. }
  152435. }
  152436. #ifdef SLOW_SHIFT_32
  152437. #define MIN_GET_BITS 15 /* minimum allowable value */
  152438. #else
  152439. #define MIN_GET_BITS (BIT_BUF_SIZE-7)
  152440. #endif
  152441. GLOBAL(boolean)
  152442. jpeg_fill_bit_buffer (bitread_working_state * state,
  152443. register bit_buf_type get_buffer, register int bits_left,
  152444. int nbits)
  152445. {
  152446. register const JOCTET * next_input_byte = state->next_input_byte;
  152447. register size_t bytes_in_buffer = state->bytes_in_buffer;
  152448. j_decompress_ptr cinfo = state->cinfo;
  152449. if (cinfo->unread_marker == 0) { /* cannot advance past a marker */
  152450. while (bits_left < MIN_GET_BITS) {
  152451. register int c;
  152452. if (bytes_in_buffer == 0) {
  152453. if (! (*cinfo->src->fill_input_buffer) (cinfo))
  152454. return FALSE;
  152455. next_input_byte = cinfo->src->next_input_byte;
  152456. bytes_in_buffer = cinfo->src->bytes_in_buffer;
  152457. }
  152458. bytes_in_buffer--;
  152459. c = GETJOCTET(*next_input_byte++);
  152460. if (c == 0xFF) {
  152461. do {
  152462. if (bytes_in_buffer == 0) {
  152463. if (! (*cinfo->src->fill_input_buffer) (cinfo))
  152464. return FALSE;
  152465. next_input_byte = cinfo->src->next_input_byte;
  152466. bytes_in_buffer = cinfo->src->bytes_in_buffer;
  152467. }
  152468. bytes_in_buffer--;
  152469. c = GETJOCTET(*next_input_byte++);
  152470. } while (c == 0xFF);
  152471. if (c == 0) {
  152472. c = 0xFF;
  152473. } else {
  152474. cinfo->unread_marker = c;
  152475. goto no_more_bytes;
  152476. }
  152477. }
  152478. get_buffer = (get_buffer << 8) | c;
  152479. bits_left += 8;
  152480. } /* end while */
  152481. } else {
  152482. no_more_bytes:
  152483. if (nbits > bits_left) {
  152484. if (! cinfo->entropy->insufficient_data) {
  152485. WARNMS(cinfo, JWRN_HIT_MARKER);
  152486. cinfo->entropy->insufficient_data = TRUE;
  152487. }
  152488. get_buffer <<= MIN_GET_BITS - bits_left;
  152489. bits_left = MIN_GET_BITS;
  152490. }
  152491. }
  152492. state->next_input_byte = next_input_byte;
  152493. state->bytes_in_buffer = bytes_in_buffer;
  152494. state->get_buffer = get_buffer;
  152495. state->bits_left = bits_left;
  152496. return TRUE;
  152497. }
  152498. GLOBAL(int)
  152499. jpeg_huff_decode (bitread_working_state * state,
  152500. register bit_buf_type get_buffer, register int bits_left,
  152501. d_derived_tbl * htbl, int min_bits)
  152502. {
  152503. register int l = min_bits;
  152504. register INT32 code;
  152505. CHECK_BIT_BUFFER(*state, l, return -1);
  152506. code = GET_BITS(l);
  152507. while (code > htbl->maxcode[l]) {
  152508. code <<= 1;
  152509. CHECK_BIT_BUFFER(*state, 1, return -1);
  152510. code |= GET_BITS(1);
  152511. l++;
  152512. }
  152513. state->get_buffer = get_buffer;
  152514. state->bits_left = bits_left;
  152515. if (l > 16) {
  152516. WARNMS(state->cinfo, JWRN_HUFF_BAD_CODE);
  152517. return 0; /* fake a zero as the safest result */
  152518. }
  152519. return htbl->pub->huffval[ (int) (code + htbl->valoffset[l]) ];
  152520. }
  152521. LOCAL(boolean)
  152522. process_restart (j_decompress_ptr cinfo)
  152523. {
  152524. huff_entropy_ptr2 entropy = (huff_entropy_ptr2) cinfo->entropy;
  152525. int ci;
  152526. cinfo->marker->discarded_bytes += entropy->bitstate.bits_left / 8;
  152527. entropy->bitstate.bits_left = 0;
  152528. if (! (*cinfo->marker->read_restart_marker) (cinfo))
  152529. return FALSE;
  152530. for (ci = 0; ci < cinfo->comps_in_scan; ci++)
  152531. entropy->saved.last_dc_val[ci] = 0;
  152532. entropy->restarts_to_go = cinfo->restart_interval;
  152533. if (cinfo->unread_marker == 0)
  152534. entropy->pub.insufficient_data = FALSE;
  152535. return TRUE;
  152536. }
  152537. METHODDEF(boolean)
  152538. decode_mcu (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  152539. {
  152540. huff_entropy_ptr2 entropy = (huff_entropy_ptr2) cinfo->entropy;
  152541. int blkn;
  152542. BITREAD_STATE_VARS;
  152543. savable_state2 state;
  152544. if (cinfo->restart_interval) {
  152545. if (entropy->restarts_to_go == 0)
  152546. if (! process_restart(cinfo))
  152547. return FALSE;
  152548. }
  152549. if (! entropy->pub.insufficient_data) {
  152550. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  152551. ASSIGN_STATE(state, entropy->saved);
  152552. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  152553. JBLOCKROW block = MCU_data[blkn];
  152554. d_derived_tbl * dctbl = entropy->dc_cur_tbls[blkn];
  152555. d_derived_tbl * actbl = entropy->ac_cur_tbls[blkn];
  152556. register int s, k, r;
  152557. HUFF_DECODE(s, br_state, dctbl, return FALSE, label1);
  152558. if (s) {
  152559. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  152560. r = GET_BITS(s);
  152561. s = HUFF_EXTEND(r, s);
  152562. }
  152563. if (entropy->dc_needed[blkn]) {
  152564. int ci = cinfo->MCU_membership[blkn];
  152565. s += state.last_dc_val[ci];
  152566. state.last_dc_val[ci] = s;
  152567. (*block)[0] = (JCOEF) s;
  152568. }
  152569. if (entropy->ac_needed[blkn]) {
  152570. for (k = 1; k < DCTSIZE2; k++) {
  152571. HUFF_DECODE(s, br_state, actbl, return FALSE, label2);
  152572. r = s >> 4;
  152573. s &= 15;
  152574. if (s) {
  152575. k += r;
  152576. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  152577. r = GET_BITS(s);
  152578. s = HUFF_EXTEND(r, s);
  152579. (*block)[jpeg_natural_order[k]] = (JCOEF) s;
  152580. } else {
  152581. if (r != 15)
  152582. break;
  152583. k += 15;
  152584. }
  152585. }
  152586. } else {
  152587. for (k = 1; k < DCTSIZE2; k++) {
  152588. HUFF_DECODE(s, br_state, actbl, return FALSE, label3);
  152589. r = s >> 4;
  152590. s &= 15;
  152591. if (s) {
  152592. k += r;
  152593. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  152594. DROP_BITS(s);
  152595. } else {
  152596. if (r != 15)
  152597. break;
  152598. k += 15;
  152599. }
  152600. }
  152601. }
  152602. }
  152603. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  152604. ASSIGN_STATE(entropy->saved, state);
  152605. }
  152606. entropy->restarts_to_go--;
  152607. return TRUE;
  152608. }
  152609. GLOBAL(void)
  152610. jinit_huff_decoder (j_decompress_ptr cinfo)
  152611. {
  152612. huff_entropy_ptr2 entropy;
  152613. int i;
  152614. entropy = (huff_entropy_ptr2)
  152615. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152616. SIZEOF(huff_entropy_decoder2));
  152617. cinfo->entropy = (struct jpeg_entropy_decoder *) entropy;
  152618. entropy->pub.start_pass = start_pass_huff_decoder;
  152619. entropy->pub.decode_mcu = decode_mcu;
  152620. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  152621. entropy->dc_derived_tbls[i] = entropy->ac_derived_tbls[i] = NULL;
  152622. }
  152623. }
  152624. /*** End of inlined file: jdhuff.c ***/
  152625. /*** Start of inlined file: jdinput.c ***/
  152626. #define JPEG_INTERNALS
  152627. typedef struct {
  152628. struct jpeg_input_controller pub; /* public fields */
  152629. boolean inheaders; /* TRUE until first SOS is reached */
  152630. } my_input_controller;
  152631. typedef my_input_controller * my_inputctl_ptr;
  152632. METHODDEF(int) consume_markers JPP((j_decompress_ptr cinfo));
  152633. LOCAL(void)
  152634. initial_setup2 (j_decompress_ptr cinfo)
  152635. {
  152636. int ci;
  152637. jpeg_component_info *compptr;
  152638. if ((long) cinfo->image_height > (long) JPEG_MAX_DIMENSION ||
  152639. (long) cinfo->image_width > (long) JPEG_MAX_DIMENSION)
  152640. ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION);
  152641. if (cinfo->data_precision != BITS_IN_JSAMPLE)
  152642. ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
  152643. if (cinfo->num_components > MAX_COMPONENTS)
  152644. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  152645. MAX_COMPONENTS);
  152646. cinfo->max_h_samp_factor = 1;
  152647. cinfo->max_v_samp_factor = 1;
  152648. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152649. ci++, compptr++) {
  152650. if (compptr->h_samp_factor<=0 || compptr->h_samp_factor>MAX_SAMP_FACTOR ||
  152651. compptr->v_samp_factor<=0 || compptr->v_samp_factor>MAX_SAMP_FACTOR)
  152652. ERREXIT(cinfo, JERR_BAD_SAMPLING);
  152653. cinfo->max_h_samp_factor = MAX(cinfo->max_h_samp_factor,
  152654. compptr->h_samp_factor);
  152655. cinfo->max_v_samp_factor = MAX(cinfo->max_v_samp_factor,
  152656. compptr->v_samp_factor);
  152657. }
  152658. cinfo->min_DCT_scaled_size = DCTSIZE;
  152659. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152660. ci++, compptr++) {
  152661. compptr->DCT_scaled_size = DCTSIZE;
  152662. compptr->width_in_blocks = (JDIMENSION)
  152663. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  152664. (long) (cinfo->max_h_samp_factor * DCTSIZE));
  152665. compptr->height_in_blocks = (JDIMENSION)
  152666. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  152667. (long) (cinfo->max_v_samp_factor * DCTSIZE));
  152668. compptr->downsampled_width = (JDIMENSION)
  152669. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  152670. (long) cinfo->max_h_samp_factor);
  152671. compptr->downsampled_height = (JDIMENSION)
  152672. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  152673. (long) cinfo->max_v_samp_factor);
  152674. compptr->component_needed = TRUE;
  152675. compptr->quant_table = NULL;
  152676. }
  152677. cinfo->total_iMCU_rows = (JDIMENSION)
  152678. jdiv_round_up((long) cinfo->image_height,
  152679. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  152680. if (cinfo->comps_in_scan < cinfo->num_components || cinfo->progressive_mode)
  152681. cinfo->inputctl->has_multiple_scans = TRUE;
  152682. else
  152683. cinfo->inputctl->has_multiple_scans = FALSE;
  152684. }
  152685. LOCAL(void)
  152686. per_scan_setup2 (j_decompress_ptr cinfo)
  152687. {
  152688. int ci, mcublks, tmp;
  152689. jpeg_component_info *compptr;
  152690. if (cinfo->comps_in_scan == 1) {
  152691. compptr = cinfo->cur_comp_info[0];
  152692. cinfo->MCUs_per_row = compptr->width_in_blocks;
  152693. cinfo->MCU_rows_in_scan = compptr->height_in_blocks;
  152694. compptr->MCU_width = 1;
  152695. compptr->MCU_height = 1;
  152696. compptr->MCU_blocks = 1;
  152697. compptr->MCU_sample_width = compptr->DCT_scaled_size;
  152698. compptr->last_col_width = 1;
  152699. tmp = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  152700. if (tmp == 0) tmp = compptr->v_samp_factor;
  152701. compptr->last_row_height = tmp;
  152702. cinfo->blocks_in_MCU = 1;
  152703. cinfo->MCU_membership[0] = 0;
  152704. } else {
  152705. if (cinfo->comps_in_scan <= 0 || cinfo->comps_in_scan > MAX_COMPS_IN_SCAN)
  152706. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->comps_in_scan,
  152707. MAX_COMPS_IN_SCAN);
  152708. cinfo->MCUs_per_row = (JDIMENSION)
  152709. jdiv_round_up((long) cinfo->image_width,
  152710. (long) (cinfo->max_h_samp_factor*DCTSIZE));
  152711. cinfo->MCU_rows_in_scan = (JDIMENSION)
  152712. jdiv_round_up((long) cinfo->image_height,
  152713. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  152714. cinfo->blocks_in_MCU = 0;
  152715. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  152716. compptr = cinfo->cur_comp_info[ci];
  152717. compptr->MCU_width = compptr->h_samp_factor;
  152718. compptr->MCU_height = compptr->v_samp_factor;
  152719. compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height;
  152720. compptr->MCU_sample_width = compptr->MCU_width * compptr->DCT_scaled_size;
  152721. tmp = (int) (compptr->width_in_blocks % compptr->MCU_width);
  152722. if (tmp == 0) tmp = compptr->MCU_width;
  152723. compptr->last_col_width = tmp;
  152724. tmp = (int) (compptr->height_in_blocks % compptr->MCU_height);
  152725. if (tmp == 0) tmp = compptr->MCU_height;
  152726. compptr->last_row_height = tmp;
  152727. mcublks = compptr->MCU_blocks;
  152728. if (cinfo->blocks_in_MCU + mcublks > D_MAX_BLOCKS_IN_MCU)
  152729. ERREXIT(cinfo, JERR_BAD_MCU_SIZE);
  152730. while (mcublks-- > 0) {
  152731. cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci;
  152732. }
  152733. }
  152734. }
  152735. }
  152736. LOCAL(void)
  152737. latch_quant_tables (j_decompress_ptr cinfo)
  152738. {
  152739. int ci, qtblno;
  152740. jpeg_component_info *compptr;
  152741. JQUANT_TBL * qtbl;
  152742. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  152743. compptr = cinfo->cur_comp_info[ci];
  152744. if (compptr->quant_table != NULL)
  152745. continue;
  152746. qtblno = compptr->quant_tbl_no;
  152747. if (qtblno < 0 || qtblno >= NUM_QUANT_TBLS ||
  152748. cinfo->quant_tbl_ptrs[qtblno] == NULL)
  152749. ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno);
  152750. qtbl = (JQUANT_TBL *)
  152751. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152752. SIZEOF(JQUANT_TBL));
  152753. MEMCOPY(qtbl, cinfo->quant_tbl_ptrs[qtblno], SIZEOF(JQUANT_TBL));
  152754. compptr->quant_table = qtbl;
  152755. }
  152756. }
  152757. METHODDEF(void)
  152758. start_input_pass2 (j_decompress_ptr cinfo)
  152759. {
  152760. per_scan_setup2(cinfo);
  152761. latch_quant_tables(cinfo);
  152762. (*cinfo->entropy->start_pass) (cinfo);
  152763. (*cinfo->coef->start_input_pass) (cinfo);
  152764. cinfo->inputctl->consume_input = cinfo->coef->consume_data;
  152765. }
  152766. METHODDEF(void)
  152767. finish_input_pass (j_decompress_ptr cinfo)
  152768. {
  152769. cinfo->inputctl->consume_input = consume_markers;
  152770. }
  152771. METHODDEF(int)
  152772. consume_markers (j_decompress_ptr cinfo)
  152773. {
  152774. my_inputctl_ptr inputctl = (my_inputctl_ptr) cinfo->inputctl;
  152775. int val;
  152776. if (inputctl->pub.eoi_reached) /* After hitting EOI, read no further */
  152777. return JPEG_REACHED_EOI;
  152778. val = (*cinfo->marker->read_markers) (cinfo);
  152779. switch (val) {
  152780. case JPEG_REACHED_SOS: /* Found SOS */
  152781. if (inputctl->inheaders) { /* 1st SOS */
  152782. initial_setup2(cinfo);
  152783. inputctl->inheaders = FALSE;
  152784. } else { /* 2nd or later SOS marker */
  152785. if (! inputctl->pub.has_multiple_scans)
  152786. ERREXIT(cinfo, JERR_EOI_EXPECTED); /* Oops, I wasn't expecting this! */
  152787. start_input_pass2(cinfo);
  152788. }
  152789. break;
  152790. case JPEG_REACHED_EOI: /* Found EOI */
  152791. inputctl->pub.eoi_reached = TRUE;
  152792. if (inputctl->inheaders) { /* Tables-only datastream, apparently */
  152793. if (cinfo->marker->saw_SOF)
  152794. ERREXIT(cinfo, JERR_SOF_NO_SOS);
  152795. } else {
  152796. if (cinfo->output_scan_number > cinfo->input_scan_number)
  152797. cinfo->output_scan_number = cinfo->input_scan_number;
  152798. }
  152799. break;
  152800. case JPEG_SUSPENDED:
  152801. break;
  152802. }
  152803. return val;
  152804. }
  152805. METHODDEF(void)
  152806. reset_input_controller (j_decompress_ptr cinfo)
  152807. {
  152808. my_inputctl_ptr inputctl = (my_inputctl_ptr) cinfo->inputctl;
  152809. inputctl->pub.consume_input = consume_markers;
  152810. inputctl->pub.has_multiple_scans = FALSE; /* "unknown" would be better */
  152811. inputctl->pub.eoi_reached = FALSE;
  152812. inputctl->inheaders = TRUE;
  152813. (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  152814. (*cinfo->marker->reset_marker_reader) (cinfo);
  152815. cinfo->coef_bits = NULL;
  152816. }
  152817. GLOBAL(void)
  152818. jinit_input_controller (j_decompress_ptr cinfo)
  152819. {
  152820. my_inputctl_ptr inputctl;
  152821. inputctl = (my_inputctl_ptr)
  152822. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  152823. SIZEOF(my_input_controller));
  152824. cinfo->inputctl = (struct jpeg_input_controller *) inputctl;
  152825. inputctl->pub.consume_input = consume_markers;
  152826. inputctl->pub.reset_input_controller = reset_input_controller;
  152827. inputctl->pub.start_input_pass = start_input_pass2;
  152828. inputctl->pub.finish_input_pass = finish_input_pass;
  152829. inputctl->pub.has_multiple_scans = FALSE; /* "unknown" would be better */
  152830. inputctl->pub.eoi_reached = FALSE;
  152831. inputctl->inheaders = TRUE;
  152832. }
  152833. /*** End of inlined file: jdinput.c ***/
  152834. /*** Start of inlined file: jdmainct.c ***/
  152835. #define JPEG_INTERNALS
  152836. typedef struct {
  152837. struct jpeg_d_main_controller pub; /* public fields */
  152838. JSAMPARRAY buffer[MAX_COMPONENTS];
  152839. boolean buffer_full; /* Have we gotten an iMCU row from decoder? */
  152840. JDIMENSION rowgroup_ctr; /* counts row groups output to postprocessor */
  152841. JSAMPIMAGE xbuffer[2]; /* pointers to weird pointer lists */
  152842. int whichptr; /* indicates which pointer set is now in use */
  152843. int context_state; /* process_data state machine status */
  152844. JDIMENSION rowgroups_avail; /* row groups available to postprocessor */
  152845. JDIMENSION iMCU_row_ctr; /* counts iMCU rows to detect image top/bot */
  152846. } my_main_controller4;
  152847. typedef my_main_controller4 * my_main_ptr4;
  152848. #define CTX_PREPARE_FOR_IMCU 0 /* need to prepare for MCU row */
  152849. #define CTX_PROCESS_IMCU 1 /* feeding iMCU to postprocessor */
  152850. #define CTX_POSTPONED_ROW 2 /* feeding postponed row group */
  152851. METHODDEF(void) process_data_simple_main2
  152852. JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
  152853. JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
  152854. METHODDEF(void) process_data_context_main
  152855. JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
  152856. JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
  152857. #ifdef QUANT_2PASS_SUPPORTED
  152858. METHODDEF(void) process_data_crank_post
  152859. JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
  152860. JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
  152861. #endif
  152862. LOCAL(void)
  152863. alloc_funny_pointers (j_decompress_ptr cinfo)
  152864. {
  152865. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152866. int ci, rgroup;
  152867. int M = cinfo->min_DCT_scaled_size;
  152868. jpeg_component_info *compptr;
  152869. JSAMPARRAY xbuf;
  152870. main_->xbuffer[0] = (JSAMPIMAGE)
  152871. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152872. cinfo->num_components * 2 * SIZEOF(JSAMPARRAY));
  152873. main_->xbuffer[1] = main_->xbuffer[0] + cinfo->num_components;
  152874. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152875. ci++, compptr++) {
  152876. rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  152877. cinfo->min_DCT_scaled_size; /* height of a row group of component */
  152878. xbuf = (JSAMPARRAY)
  152879. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152880. 2 * (rgroup * (M + 4)) * SIZEOF(JSAMPROW));
  152881. xbuf += rgroup; /* want one row group at negative offsets */
  152882. main_->xbuffer[0][ci] = xbuf;
  152883. xbuf += rgroup * (M + 4);
  152884. main_->xbuffer[1][ci] = xbuf;
  152885. }
  152886. }
  152887. LOCAL(void)
  152888. make_funny_pointers (j_decompress_ptr cinfo)
  152889. {
  152890. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152891. int ci, i, rgroup;
  152892. int M = cinfo->min_DCT_scaled_size;
  152893. jpeg_component_info *compptr;
  152894. JSAMPARRAY buf, xbuf0, xbuf1;
  152895. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152896. ci++, compptr++) {
  152897. rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  152898. cinfo->min_DCT_scaled_size; /* height of a row group of component */
  152899. xbuf0 = main_->xbuffer[0][ci];
  152900. xbuf1 = main_->xbuffer[1][ci];
  152901. buf = main_->buffer[ci];
  152902. for (i = 0; i < rgroup * (M + 2); i++) {
  152903. xbuf0[i] = xbuf1[i] = buf[i];
  152904. }
  152905. for (i = 0; i < rgroup * 2; i++) {
  152906. xbuf1[rgroup*(M-2) + i] = buf[rgroup*M + i];
  152907. xbuf1[rgroup*M + i] = buf[rgroup*(M-2) + i];
  152908. }
  152909. for (i = 0; i < rgroup; i++) {
  152910. xbuf0[i - rgroup] = xbuf0[0];
  152911. }
  152912. }
  152913. }
  152914. LOCAL(void)
  152915. set_wraparound_pointers (j_decompress_ptr cinfo)
  152916. {
  152917. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152918. int ci, i, rgroup;
  152919. int M = cinfo->min_DCT_scaled_size;
  152920. jpeg_component_info *compptr;
  152921. JSAMPARRAY xbuf0, xbuf1;
  152922. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152923. ci++, compptr++) {
  152924. rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  152925. cinfo->min_DCT_scaled_size; /* height of a row group of component */
  152926. xbuf0 = main_->xbuffer[0][ci];
  152927. xbuf1 = main_->xbuffer[1][ci];
  152928. for (i = 0; i < rgroup; i++) {
  152929. xbuf0[i - rgroup] = xbuf0[rgroup*(M+1) + i];
  152930. xbuf1[i - rgroup] = xbuf1[rgroup*(M+1) + i];
  152931. xbuf0[rgroup*(M+2) + i] = xbuf0[i];
  152932. xbuf1[rgroup*(M+2) + i] = xbuf1[i];
  152933. }
  152934. }
  152935. }
  152936. LOCAL(void)
  152937. set_bottom_pointers (j_decompress_ptr cinfo)
  152938. {
  152939. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152940. int ci, i, rgroup, iMCUheight, rows_left;
  152941. jpeg_component_info *compptr;
  152942. JSAMPARRAY xbuf;
  152943. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152944. ci++, compptr++) {
  152945. iMCUheight = compptr->v_samp_factor * compptr->DCT_scaled_size;
  152946. rgroup = iMCUheight / cinfo->min_DCT_scaled_size;
  152947. rows_left = (int) (compptr->downsampled_height % (JDIMENSION) iMCUheight);
  152948. if (rows_left == 0) rows_left = iMCUheight;
  152949. if (ci == 0) {
  152950. main_->rowgroups_avail = (JDIMENSION) ((rows_left-1) / rgroup + 1);
  152951. }
  152952. xbuf = main_->xbuffer[main_->whichptr][ci];
  152953. for (i = 0; i < rgroup * 2; i++) {
  152954. xbuf[rows_left + i] = xbuf[rows_left-1];
  152955. }
  152956. }
  152957. }
  152958. METHODDEF(void)
  152959. start_pass_main2 (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
  152960. {
  152961. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152962. switch (pass_mode) {
  152963. case JBUF_PASS_THRU:
  152964. if (cinfo->upsample->need_context_rows) {
  152965. main_->pub.process_data = process_data_context_main;
  152966. make_funny_pointers(cinfo); /* Create the xbuffer[] lists */
  152967. main_->whichptr = 0; /* Read first iMCU row into xbuffer[0] */
  152968. main_->context_state = CTX_PREPARE_FOR_IMCU;
  152969. main_->iMCU_row_ctr = 0;
  152970. } else {
  152971. main_->pub.process_data = process_data_simple_main2;
  152972. }
  152973. main_->buffer_full = FALSE; /* Mark buffer empty */
  152974. main_->rowgroup_ctr = 0;
  152975. break;
  152976. #ifdef QUANT_2PASS_SUPPORTED
  152977. case JBUF_CRANK_DEST:
  152978. main_->pub.process_data = process_data_crank_post;
  152979. break;
  152980. #endif
  152981. default:
  152982. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  152983. break;
  152984. }
  152985. }
  152986. METHODDEF(void)
  152987. process_data_simple_main2 (j_decompress_ptr cinfo,
  152988. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  152989. JDIMENSION out_rows_avail)
  152990. {
  152991. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152992. JDIMENSION rowgroups_avail;
  152993. if (! main_->buffer_full) {
  152994. if (! (*cinfo->coef->decompress_data) (cinfo, main_->buffer))
  152995. return; /* suspension forced, can do nothing more */
  152996. main_->buffer_full = TRUE; /* OK, we have an iMCU row to work with */
  152997. }
  152998. rowgroups_avail = (JDIMENSION) cinfo->min_DCT_scaled_size;
  152999. (*cinfo->post->post_process_data) (cinfo, main_->buffer,
  153000. &main_->rowgroup_ctr, rowgroups_avail,
  153001. output_buf, out_row_ctr, out_rows_avail);
  153002. if (main_->rowgroup_ctr >= rowgroups_avail) {
  153003. main_->buffer_full = FALSE;
  153004. main_->rowgroup_ctr = 0;
  153005. }
  153006. }
  153007. METHODDEF(void)
  153008. process_data_context_main (j_decompress_ptr cinfo,
  153009. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  153010. JDIMENSION out_rows_avail)
  153011. {
  153012. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  153013. if (! main_->buffer_full) {
  153014. if (! (*cinfo->coef->decompress_data) (cinfo,
  153015. main_->xbuffer[main_->whichptr]))
  153016. return; /* suspension forced, can do nothing more */
  153017. main_->buffer_full = TRUE; /* OK, we have an iMCU row to work with */
  153018. main_->iMCU_row_ctr++; /* count rows received */
  153019. }
  153020. switch (main_->context_state) {
  153021. case CTX_POSTPONED_ROW:
  153022. (*cinfo->post->post_process_data) (cinfo, main_->xbuffer[main_->whichptr],
  153023. &main_->rowgroup_ctr, main_->rowgroups_avail,
  153024. output_buf, out_row_ctr, out_rows_avail);
  153025. if (main_->rowgroup_ctr < main_->rowgroups_avail)
  153026. return; /* Need to suspend */
  153027. main_->context_state = CTX_PREPARE_FOR_IMCU;
  153028. if (*out_row_ctr >= out_rows_avail)
  153029. return; /* Postprocessor exactly filled output buf */
  153030. case CTX_PREPARE_FOR_IMCU:
  153031. main_->rowgroup_ctr = 0;
  153032. main_->rowgroups_avail = (JDIMENSION) (cinfo->min_DCT_scaled_size - 1);
  153033. if (main_->iMCU_row_ctr == cinfo->total_iMCU_rows)
  153034. set_bottom_pointers(cinfo);
  153035. main_->context_state = CTX_PROCESS_IMCU;
  153036. case CTX_PROCESS_IMCU:
  153037. (*cinfo->post->post_process_data) (cinfo, main_->xbuffer[main_->whichptr],
  153038. &main_->rowgroup_ctr, main_->rowgroups_avail,
  153039. output_buf, out_row_ctr, out_rows_avail);
  153040. if (main_->rowgroup_ctr < main_->rowgroups_avail)
  153041. return; /* Need to suspend */
  153042. if (main_->iMCU_row_ctr == 1)
  153043. set_wraparound_pointers(cinfo);
  153044. main_->whichptr ^= 1; /* 0=>1 or 1=>0 */
  153045. main_->buffer_full = FALSE;
  153046. main_->rowgroup_ctr = (JDIMENSION) (cinfo->min_DCT_scaled_size + 1);
  153047. main_->rowgroups_avail = (JDIMENSION) (cinfo->min_DCT_scaled_size + 2);
  153048. main_->context_state = CTX_POSTPONED_ROW;
  153049. }
  153050. }
  153051. #ifdef QUANT_2PASS_SUPPORTED
  153052. METHODDEF(void)
  153053. process_data_crank_post (j_decompress_ptr cinfo,
  153054. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  153055. JDIMENSION out_rows_avail)
  153056. {
  153057. (*cinfo->post->post_process_data) (cinfo, (JSAMPIMAGE) NULL,
  153058. (JDIMENSION *) NULL, (JDIMENSION) 0,
  153059. output_buf, out_row_ctr, out_rows_avail);
  153060. }
  153061. #endif /* QUANT_2PASS_SUPPORTED */
  153062. GLOBAL(void)
  153063. jinit_d_main_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
  153064. {
  153065. my_main_ptr4 main_;
  153066. int ci, rgroup, ngroups;
  153067. jpeg_component_info *compptr;
  153068. main_ = (my_main_ptr4)
  153069. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153070. SIZEOF(my_main_controller4));
  153071. cinfo->main = (struct jpeg_d_main_controller *) main_;
  153072. main_->pub.start_pass = start_pass_main2;
  153073. if (need_full_buffer) /* shouldn't happen */
  153074. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  153075. if (cinfo->upsample->need_context_rows) {
  153076. if (cinfo->min_DCT_scaled_size < 2) /* unsupported, see comments above */
  153077. ERREXIT(cinfo, JERR_NOTIMPL);
  153078. alloc_funny_pointers(cinfo); /* Alloc space for xbuffer[] lists */
  153079. ngroups = cinfo->min_DCT_scaled_size + 2;
  153080. } else {
  153081. ngroups = cinfo->min_DCT_scaled_size;
  153082. }
  153083. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  153084. ci++, compptr++) {
  153085. rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  153086. cinfo->min_DCT_scaled_size; /* height of a row group of component */
  153087. main_->buffer[ci] = (*cinfo->mem->alloc_sarray)
  153088. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153089. compptr->width_in_blocks * compptr->DCT_scaled_size,
  153090. (JDIMENSION) (rgroup * ngroups));
  153091. }
  153092. }
  153093. /*** End of inlined file: jdmainct.c ***/
  153094. /*** Start of inlined file: jdmarker.c ***/
  153095. #define JPEG_INTERNALS
  153096. typedef struct {
  153097. struct jpeg_marker_reader pub; /* public fields */
  153098. jpeg_marker_parser_method process_COM;
  153099. jpeg_marker_parser_method process_APPn[16];
  153100. unsigned int length_limit_COM;
  153101. unsigned int length_limit_APPn[16];
  153102. jpeg_saved_marker_ptr cur_marker; /* NULL if not processing a marker */
  153103. unsigned int bytes_read; /* data bytes read so far in marker */
  153104. } my_marker_reader;
  153105. typedef my_marker_reader * my_marker_ptr2;
  153106. #define INPUT_VARS(cinfo) \
  153107. struct jpeg_source_mgr * datasrc = (cinfo)->src; \
  153108. const JOCTET * next_input_byte = datasrc->next_input_byte; \
  153109. size_t bytes_in_buffer = datasrc->bytes_in_buffer
  153110. #define INPUT_SYNC(cinfo) \
  153111. ( datasrc->next_input_byte = next_input_byte, \
  153112. datasrc->bytes_in_buffer = bytes_in_buffer )
  153113. #define INPUT_RELOAD(cinfo) \
  153114. ( next_input_byte = datasrc->next_input_byte, \
  153115. bytes_in_buffer = datasrc->bytes_in_buffer )
  153116. #define MAKE_BYTE_AVAIL(cinfo,action) \
  153117. if (bytes_in_buffer == 0) { \
  153118. if (! (*datasrc->fill_input_buffer) (cinfo)) \
  153119. { action; } \
  153120. INPUT_RELOAD(cinfo); \
  153121. }
  153122. #define INPUT_BYTE(cinfo,V,action) \
  153123. MAKESTMT( MAKE_BYTE_AVAIL(cinfo,action); \
  153124. bytes_in_buffer--; \
  153125. V = GETJOCTET(*next_input_byte++); )
  153126. #define INPUT_2BYTES(cinfo,V,action) \
  153127. MAKESTMT( MAKE_BYTE_AVAIL(cinfo,action); \
  153128. bytes_in_buffer--; \
  153129. V = ((unsigned int) GETJOCTET(*next_input_byte++)) << 8; \
  153130. MAKE_BYTE_AVAIL(cinfo,action); \
  153131. bytes_in_buffer--; \
  153132. V += GETJOCTET(*next_input_byte++); )
  153133. LOCAL(boolean)
  153134. get_soi (j_decompress_ptr cinfo)
  153135. {
  153136. int i;
  153137. TRACEMS(cinfo, 1, JTRC_SOI);
  153138. if (cinfo->marker->saw_SOI)
  153139. ERREXIT(cinfo, JERR_SOI_DUPLICATE);
  153140. for (i = 0; i < NUM_ARITH_TBLS; i++) {
  153141. cinfo->arith_dc_L[i] = 0;
  153142. cinfo->arith_dc_U[i] = 1;
  153143. cinfo->arith_ac_K[i] = 5;
  153144. }
  153145. cinfo->restart_interval = 0;
  153146. cinfo->jpeg_color_space = JCS_UNKNOWN;
  153147. cinfo->CCIR601_sampling = FALSE; /* Assume non-CCIR sampling??? */
  153148. cinfo->saw_JFIF_marker = FALSE;
  153149. cinfo->JFIF_major_version = 1; /* set default JFIF APP0 values */
  153150. cinfo->JFIF_minor_version = 1;
  153151. cinfo->density_unit = 0;
  153152. cinfo->X_density = 1;
  153153. cinfo->Y_density = 1;
  153154. cinfo->saw_Adobe_marker = FALSE;
  153155. cinfo->Adobe_transform = 0;
  153156. cinfo->marker->saw_SOI = TRUE;
  153157. return TRUE;
  153158. }
  153159. LOCAL(boolean)
  153160. get_sof (j_decompress_ptr cinfo, boolean is_prog, boolean is_arith)
  153161. {
  153162. INT32 length;
  153163. int c, ci;
  153164. jpeg_component_info * compptr;
  153165. INPUT_VARS(cinfo);
  153166. cinfo->progressive_mode = is_prog;
  153167. cinfo->arith_code = is_arith;
  153168. INPUT_2BYTES(cinfo, length, return FALSE);
  153169. INPUT_BYTE(cinfo, cinfo->data_precision, return FALSE);
  153170. INPUT_2BYTES(cinfo, cinfo->image_height, return FALSE);
  153171. INPUT_2BYTES(cinfo, cinfo->image_width, return FALSE);
  153172. INPUT_BYTE(cinfo, cinfo->num_components, return FALSE);
  153173. length -= 8;
  153174. TRACEMS4(cinfo, 1, JTRC_SOF, cinfo->unread_marker,
  153175. (int) cinfo->image_width, (int) cinfo->image_height,
  153176. cinfo->num_components);
  153177. if (cinfo->marker->saw_SOF)
  153178. ERREXIT(cinfo, JERR_SOF_DUPLICATE);
  153179. if (cinfo->image_height <= 0 || cinfo->image_width <= 0
  153180. || cinfo->num_components <= 0)
  153181. ERREXIT(cinfo, JERR_EMPTY_IMAGE);
  153182. if (length != (cinfo->num_components * 3))
  153183. ERREXIT(cinfo, JERR_BAD_LENGTH);
  153184. if (cinfo->comp_info == NULL) /* do only once, even if suspend */
  153185. cinfo->comp_info = (jpeg_component_info *) (*cinfo->mem->alloc_small)
  153186. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153187. cinfo->num_components * SIZEOF(jpeg_component_info));
  153188. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  153189. ci++, compptr++) {
  153190. compptr->component_index = ci;
  153191. INPUT_BYTE(cinfo, compptr->component_id, return FALSE);
  153192. INPUT_BYTE(cinfo, c, return FALSE);
  153193. compptr->h_samp_factor = (c >> 4) & 15;
  153194. compptr->v_samp_factor = (c ) & 15;
  153195. INPUT_BYTE(cinfo, compptr->quant_tbl_no, return FALSE);
  153196. TRACEMS4(cinfo, 1, JTRC_SOF_COMPONENT,
  153197. compptr->component_id, compptr->h_samp_factor,
  153198. compptr->v_samp_factor, compptr->quant_tbl_no);
  153199. }
  153200. cinfo->marker->saw_SOF = TRUE;
  153201. INPUT_SYNC(cinfo);
  153202. return TRUE;
  153203. }
  153204. LOCAL(boolean)
  153205. get_sos (j_decompress_ptr cinfo)
  153206. {
  153207. INT32 length;
  153208. int i, ci, n, c, cc;
  153209. jpeg_component_info * compptr;
  153210. INPUT_VARS(cinfo);
  153211. if (! cinfo->marker->saw_SOF)
  153212. ERREXIT(cinfo, JERR_SOS_NO_SOF);
  153213. INPUT_2BYTES(cinfo, length, return FALSE);
  153214. INPUT_BYTE(cinfo, n, return FALSE); /* Number of components */
  153215. TRACEMS1(cinfo, 1, JTRC_SOS, n);
  153216. if (length != (n * 2 + 6) || n < 1 || n > MAX_COMPS_IN_SCAN)
  153217. ERREXIT(cinfo, JERR_BAD_LENGTH);
  153218. cinfo->comps_in_scan = n;
  153219. for (i = 0; i < n; i++) {
  153220. INPUT_BYTE(cinfo, cc, return FALSE);
  153221. INPUT_BYTE(cinfo, c, return FALSE);
  153222. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  153223. ci++, compptr++) {
  153224. if (cc == compptr->component_id)
  153225. goto id_found;
  153226. }
  153227. ERREXIT1(cinfo, JERR_BAD_COMPONENT_ID, cc);
  153228. id_found:
  153229. cinfo->cur_comp_info[i] = compptr;
  153230. compptr->dc_tbl_no = (c >> 4) & 15;
  153231. compptr->ac_tbl_no = (c ) & 15;
  153232. TRACEMS3(cinfo, 1, JTRC_SOS_COMPONENT, cc,
  153233. compptr->dc_tbl_no, compptr->ac_tbl_no);
  153234. }
  153235. INPUT_BYTE(cinfo, c, return FALSE);
  153236. cinfo->Ss = c;
  153237. INPUT_BYTE(cinfo, c, return FALSE);
  153238. cinfo->Se = c;
  153239. INPUT_BYTE(cinfo, c, return FALSE);
  153240. cinfo->Ah = (c >> 4) & 15;
  153241. cinfo->Al = (c ) & 15;
  153242. TRACEMS4(cinfo, 1, JTRC_SOS_PARAMS, cinfo->Ss, cinfo->Se,
  153243. cinfo->Ah, cinfo->Al);
  153244. cinfo->marker->next_restart_num = 0;
  153245. cinfo->input_scan_number++;
  153246. INPUT_SYNC(cinfo);
  153247. return TRUE;
  153248. }
  153249. #ifdef D_ARITH_CODING_SUPPORTED
  153250. LOCAL(boolean)
  153251. get_dac (j_decompress_ptr cinfo)
  153252. {
  153253. INT32 length;
  153254. int index, val;
  153255. INPUT_VARS(cinfo);
  153256. INPUT_2BYTES(cinfo, length, return FALSE);
  153257. length -= 2;
  153258. while (length > 0) {
  153259. INPUT_BYTE(cinfo, index, return FALSE);
  153260. INPUT_BYTE(cinfo, val, return FALSE);
  153261. length -= 2;
  153262. TRACEMS2(cinfo, 1, JTRC_DAC, index, val);
  153263. if (index < 0 || index >= (2*NUM_ARITH_TBLS))
  153264. ERREXIT1(cinfo, JERR_DAC_INDEX, index);
  153265. if (index >= NUM_ARITH_TBLS) { /* define AC table */
  153266. cinfo->arith_ac_K[index-NUM_ARITH_TBLS] = (UINT8) val;
  153267. } else { /* define DC table */
  153268. cinfo->arith_dc_L[index] = (UINT8) (val & 0x0F);
  153269. cinfo->arith_dc_U[index] = (UINT8) (val >> 4);
  153270. if (cinfo->arith_dc_L[index] > cinfo->arith_dc_U[index])
  153271. ERREXIT1(cinfo, JERR_DAC_VALUE, val);
  153272. }
  153273. }
  153274. if (length != 0)
  153275. ERREXIT(cinfo, JERR_BAD_LENGTH);
  153276. INPUT_SYNC(cinfo);
  153277. return TRUE;
  153278. }
  153279. #else /* ! D_ARITH_CODING_SUPPORTED */
  153280. #define get_dac(cinfo) skip_variable(cinfo)
  153281. #endif /* D_ARITH_CODING_SUPPORTED */
  153282. LOCAL(boolean)
  153283. get_dht (j_decompress_ptr cinfo)
  153284. {
  153285. INT32 length;
  153286. UINT8 bits[17];
  153287. UINT8 huffval[256];
  153288. int i, index, count;
  153289. JHUFF_TBL **htblptr;
  153290. INPUT_VARS(cinfo);
  153291. INPUT_2BYTES(cinfo, length, return FALSE);
  153292. length -= 2;
  153293. while (length > 16) {
  153294. INPUT_BYTE(cinfo, index, return FALSE);
  153295. TRACEMS1(cinfo, 1, JTRC_DHT, index);
  153296. bits[0] = 0;
  153297. count = 0;
  153298. for (i = 1; i <= 16; i++) {
  153299. INPUT_BYTE(cinfo, bits[i], return FALSE);
  153300. count += bits[i];
  153301. }
  153302. length -= 1 + 16;
  153303. TRACEMS8(cinfo, 2, JTRC_HUFFBITS,
  153304. bits[1], bits[2], bits[3], bits[4],
  153305. bits[5], bits[6], bits[7], bits[8]);
  153306. TRACEMS8(cinfo, 2, JTRC_HUFFBITS,
  153307. bits[9], bits[10], bits[11], bits[12],
  153308. bits[13], bits[14], bits[15], bits[16]);
  153309. if (count > 256 || ((INT32) count) > length)
  153310. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  153311. for (i = 0; i < count; i++)
  153312. INPUT_BYTE(cinfo, huffval[i], return FALSE);
  153313. length -= count;
  153314. if (index & 0x10) { /* AC table definition */
  153315. index -= 0x10;
  153316. htblptr = &cinfo->ac_huff_tbl_ptrs[index];
  153317. } else { /* DC table definition */
  153318. htblptr = &cinfo->dc_huff_tbl_ptrs[index];
  153319. }
  153320. if (index < 0 || index >= NUM_HUFF_TBLS)
  153321. ERREXIT1(cinfo, JERR_DHT_INDEX, index);
  153322. if (*htblptr == NULL)
  153323. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  153324. MEMCOPY((*htblptr)->bits, bits, SIZEOF((*htblptr)->bits));
  153325. MEMCOPY((*htblptr)->huffval, huffval, SIZEOF((*htblptr)->huffval));
  153326. }
  153327. if (length != 0)
  153328. ERREXIT(cinfo, JERR_BAD_LENGTH);
  153329. INPUT_SYNC(cinfo);
  153330. return TRUE;
  153331. }
  153332. LOCAL(boolean)
  153333. get_dqt (j_decompress_ptr cinfo)
  153334. {
  153335. INT32 length;
  153336. int n, i, prec;
  153337. unsigned int tmp;
  153338. JQUANT_TBL *quant_ptr;
  153339. INPUT_VARS(cinfo);
  153340. INPUT_2BYTES(cinfo, length, return FALSE);
  153341. length -= 2;
  153342. while (length > 0) {
  153343. INPUT_BYTE(cinfo, n, return FALSE);
  153344. prec = n >> 4;
  153345. n &= 0x0F;
  153346. TRACEMS2(cinfo, 1, JTRC_DQT, n, prec);
  153347. if (n >= NUM_QUANT_TBLS)
  153348. ERREXIT1(cinfo, JERR_DQT_INDEX, n);
  153349. if (cinfo->quant_tbl_ptrs[n] == NULL)
  153350. cinfo->quant_tbl_ptrs[n] = jpeg_alloc_quant_table((j_common_ptr) cinfo);
  153351. quant_ptr = cinfo->quant_tbl_ptrs[n];
  153352. for (i = 0; i < DCTSIZE2; i++) {
  153353. if (prec)
  153354. INPUT_2BYTES(cinfo, tmp, return FALSE);
  153355. else
  153356. INPUT_BYTE(cinfo, tmp, return FALSE);
  153357. quant_ptr->quantval[jpeg_natural_order[i]] = (UINT16) tmp;
  153358. }
  153359. if (cinfo->err->trace_level >= 2) {
  153360. for (i = 0; i < DCTSIZE2; i += 8) {
  153361. TRACEMS8(cinfo, 2, JTRC_QUANTVALS,
  153362. quant_ptr->quantval[i], quant_ptr->quantval[i+1],
  153363. quant_ptr->quantval[i+2], quant_ptr->quantval[i+3],
  153364. quant_ptr->quantval[i+4], quant_ptr->quantval[i+5],
  153365. quant_ptr->quantval[i+6], quant_ptr->quantval[i+7]);
  153366. }
  153367. }
  153368. length -= DCTSIZE2+1;
  153369. if (prec) length -= DCTSIZE2;
  153370. }
  153371. if (length != 0)
  153372. ERREXIT(cinfo, JERR_BAD_LENGTH);
  153373. INPUT_SYNC(cinfo);
  153374. return TRUE;
  153375. }
  153376. LOCAL(boolean)
  153377. get_dri (j_decompress_ptr cinfo)
  153378. {
  153379. INT32 length;
  153380. unsigned int tmp;
  153381. INPUT_VARS(cinfo);
  153382. INPUT_2BYTES(cinfo, length, return FALSE);
  153383. if (length != 4)
  153384. ERREXIT(cinfo, JERR_BAD_LENGTH);
  153385. INPUT_2BYTES(cinfo, tmp, return FALSE);
  153386. TRACEMS1(cinfo, 1, JTRC_DRI, tmp);
  153387. cinfo->restart_interval = tmp;
  153388. INPUT_SYNC(cinfo);
  153389. return TRUE;
  153390. }
  153391. #define APP0_DATA_LEN 14 /* Length of interesting data in APP0 */
  153392. #define APP14_DATA_LEN 12 /* Length of interesting data in APP14 */
  153393. #define APPN_DATA_LEN 14 /* Must be the largest of the above!! */
  153394. LOCAL(void)
  153395. examine_app0 (j_decompress_ptr cinfo, JOCTET FAR * data,
  153396. unsigned int datalen, INT32 remaining)
  153397. {
  153398. INT32 totallen = (INT32) datalen + remaining;
  153399. if (datalen >= APP0_DATA_LEN &&
  153400. GETJOCTET(data[0]) == 0x4A &&
  153401. GETJOCTET(data[1]) == 0x46 &&
  153402. GETJOCTET(data[2]) == 0x49 &&
  153403. GETJOCTET(data[3]) == 0x46 &&
  153404. GETJOCTET(data[4]) == 0) {
  153405. cinfo->saw_JFIF_marker = TRUE;
  153406. cinfo->JFIF_major_version = GETJOCTET(data[5]);
  153407. cinfo->JFIF_minor_version = GETJOCTET(data[6]);
  153408. cinfo->density_unit = GETJOCTET(data[7]);
  153409. cinfo->X_density = (GETJOCTET(data[8]) << 8) + GETJOCTET(data[9]);
  153410. cinfo->Y_density = (GETJOCTET(data[10]) << 8) + GETJOCTET(data[11]);
  153411. if (cinfo->JFIF_major_version != 1)
  153412. WARNMS2(cinfo, JWRN_JFIF_MAJOR,
  153413. cinfo->JFIF_major_version, cinfo->JFIF_minor_version);
  153414. TRACEMS5(cinfo, 1, JTRC_JFIF,
  153415. cinfo->JFIF_major_version, cinfo->JFIF_minor_version,
  153416. cinfo->X_density, cinfo->Y_density, cinfo->density_unit);
  153417. if (GETJOCTET(data[12]) | GETJOCTET(data[13]))
  153418. TRACEMS2(cinfo, 1, JTRC_JFIF_THUMBNAIL,
  153419. GETJOCTET(data[12]), GETJOCTET(data[13]));
  153420. totallen -= APP0_DATA_LEN;
  153421. if (totallen !=
  153422. ((INT32)GETJOCTET(data[12]) * (INT32)GETJOCTET(data[13]) * (INT32) 3))
  153423. TRACEMS1(cinfo, 1, JTRC_JFIF_BADTHUMBNAILSIZE, (int) totallen);
  153424. } else if (datalen >= 6 &&
  153425. GETJOCTET(data[0]) == 0x4A &&
  153426. GETJOCTET(data[1]) == 0x46 &&
  153427. GETJOCTET(data[2]) == 0x58 &&
  153428. GETJOCTET(data[3]) == 0x58 &&
  153429. GETJOCTET(data[4]) == 0) {
  153430. switch (GETJOCTET(data[5])) {
  153431. case 0x10:
  153432. TRACEMS1(cinfo, 1, JTRC_THUMB_JPEG, (int) totallen);
  153433. break;
  153434. case 0x11:
  153435. TRACEMS1(cinfo, 1, JTRC_THUMB_PALETTE, (int) totallen);
  153436. break;
  153437. case 0x13:
  153438. TRACEMS1(cinfo, 1, JTRC_THUMB_RGB, (int) totallen);
  153439. break;
  153440. default:
  153441. TRACEMS2(cinfo, 1, JTRC_JFIF_EXTENSION,
  153442. GETJOCTET(data[5]), (int) totallen);
  153443. break;
  153444. }
  153445. } else {
  153446. TRACEMS1(cinfo, 1, JTRC_APP0, (int) totallen);
  153447. }
  153448. }
  153449. LOCAL(void)
  153450. examine_app14 (j_decompress_ptr cinfo, JOCTET FAR * data,
  153451. unsigned int datalen, INT32 remaining)
  153452. {
  153453. unsigned int version, flags0, flags1, transform;
  153454. if (datalen >= APP14_DATA_LEN &&
  153455. GETJOCTET(data[0]) == 0x41 &&
  153456. GETJOCTET(data[1]) == 0x64 &&
  153457. GETJOCTET(data[2]) == 0x6F &&
  153458. GETJOCTET(data[3]) == 0x62 &&
  153459. GETJOCTET(data[4]) == 0x65) {
  153460. version = (GETJOCTET(data[5]) << 8) + GETJOCTET(data[6]);
  153461. flags0 = (GETJOCTET(data[7]) << 8) + GETJOCTET(data[8]);
  153462. flags1 = (GETJOCTET(data[9]) << 8) + GETJOCTET(data[10]);
  153463. transform = GETJOCTET(data[11]);
  153464. TRACEMS4(cinfo, 1, JTRC_ADOBE, version, flags0, flags1, transform);
  153465. cinfo->saw_Adobe_marker = TRUE;
  153466. cinfo->Adobe_transform = (UINT8) transform;
  153467. } else {
  153468. TRACEMS1(cinfo, 1, JTRC_APP14, (int) (datalen + remaining));
  153469. }
  153470. }
  153471. METHODDEF(boolean)
  153472. get_interesting_appn (j_decompress_ptr cinfo)
  153473. {
  153474. INT32 length;
  153475. JOCTET b[APPN_DATA_LEN];
  153476. unsigned int i, numtoread;
  153477. INPUT_VARS(cinfo);
  153478. INPUT_2BYTES(cinfo, length, return FALSE);
  153479. length -= 2;
  153480. if (length >= APPN_DATA_LEN)
  153481. numtoread = APPN_DATA_LEN;
  153482. else if (length > 0)
  153483. numtoread = (unsigned int) length;
  153484. else
  153485. numtoread = 0;
  153486. for (i = 0; i < numtoread; i++)
  153487. INPUT_BYTE(cinfo, b[i], return FALSE);
  153488. length -= numtoread;
  153489. switch (cinfo->unread_marker) {
  153490. case M_APP0:
  153491. examine_app0(cinfo, (JOCTET FAR *) b, numtoread, length);
  153492. break;
  153493. case M_APP14:
  153494. examine_app14(cinfo, (JOCTET FAR *) b, numtoread, length);
  153495. break;
  153496. default:
  153497. ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, cinfo->unread_marker);
  153498. break;
  153499. }
  153500. INPUT_SYNC(cinfo);
  153501. if (length > 0)
  153502. (*cinfo->src->skip_input_data) (cinfo, (long) length);
  153503. return TRUE;
  153504. }
  153505. #ifdef SAVE_MARKERS_SUPPORTED
  153506. METHODDEF(boolean)
  153507. save_marker (j_decompress_ptr cinfo)
  153508. {
  153509. my_marker_ptr2 marker = (my_marker_ptr2) cinfo->marker;
  153510. jpeg_saved_marker_ptr cur_marker = marker->cur_marker;
  153511. unsigned int bytes_read, data_length;
  153512. JOCTET FAR * data;
  153513. INT32 length = 0;
  153514. INPUT_VARS(cinfo);
  153515. if (cur_marker == NULL) {
  153516. INPUT_2BYTES(cinfo, length, return FALSE);
  153517. length -= 2;
  153518. if (length >= 0) { /* watch out for bogus length word */
  153519. unsigned int limit;
  153520. if (cinfo->unread_marker == (int) M_COM)
  153521. limit = marker->length_limit_COM;
  153522. else
  153523. limit = marker->length_limit_APPn[cinfo->unread_marker - (int) M_APP0];
  153524. if ((unsigned int) length < limit)
  153525. limit = (unsigned int) length;
  153526. cur_marker = (jpeg_saved_marker_ptr)
  153527. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153528. SIZEOF(struct jpeg_marker_struct) + limit);
  153529. cur_marker->next = NULL;
  153530. cur_marker->marker = (UINT8) cinfo->unread_marker;
  153531. cur_marker->original_length = (unsigned int) length;
  153532. cur_marker->data_length = limit;
  153533. data = cur_marker->data = (JOCTET FAR *) (cur_marker + 1);
  153534. marker->cur_marker = cur_marker;
  153535. marker->bytes_read = 0;
  153536. bytes_read = 0;
  153537. data_length = limit;
  153538. } else {
  153539. bytes_read = data_length = 0;
  153540. data = NULL;
  153541. }
  153542. } else {
  153543. bytes_read = marker->bytes_read;
  153544. data_length = cur_marker->data_length;
  153545. data = cur_marker->data + bytes_read;
  153546. }
  153547. while (bytes_read < data_length) {
  153548. INPUT_SYNC(cinfo); /* move the restart point to here */
  153549. marker->bytes_read = bytes_read;
  153550. MAKE_BYTE_AVAIL(cinfo, return FALSE);
  153551. while (bytes_read < data_length && bytes_in_buffer > 0) {
  153552. *data++ = *next_input_byte++;
  153553. bytes_in_buffer--;
  153554. bytes_read++;
  153555. }
  153556. }
  153557. if (cur_marker != NULL) { /* will be NULL if bogus length word */
  153558. if (cinfo->marker_list == NULL) {
  153559. cinfo->marker_list = cur_marker;
  153560. } else {
  153561. jpeg_saved_marker_ptr prev = cinfo->marker_list;
  153562. while (prev->next != NULL)
  153563. prev = prev->next;
  153564. prev->next = cur_marker;
  153565. }
  153566. data = cur_marker->data;
  153567. length = cur_marker->original_length - data_length;
  153568. }
  153569. marker->cur_marker = NULL;
  153570. switch (cinfo->unread_marker) {
  153571. case M_APP0:
  153572. examine_app0(cinfo, data, data_length, length);
  153573. break;
  153574. case M_APP14:
  153575. examine_app14(cinfo, data, data_length, length);
  153576. break;
  153577. default:
  153578. TRACEMS2(cinfo, 1, JTRC_MISC_MARKER, cinfo->unread_marker,
  153579. (int) (data_length + length));
  153580. break;
  153581. }
  153582. INPUT_SYNC(cinfo); /* do before skip_input_data */
  153583. if (length > 0)
  153584. (*cinfo->src->skip_input_data) (cinfo, (long) length);
  153585. return TRUE;
  153586. }
  153587. #endif /* SAVE_MARKERS_SUPPORTED */
  153588. METHODDEF(boolean)
  153589. skip_variable (j_decompress_ptr cinfo)
  153590. {
  153591. INT32 length;
  153592. INPUT_VARS(cinfo);
  153593. INPUT_2BYTES(cinfo, length, return FALSE);
  153594. length -= 2;
  153595. TRACEMS2(cinfo, 1, JTRC_MISC_MARKER, cinfo->unread_marker, (int) length);
  153596. INPUT_SYNC(cinfo); /* do before skip_input_data */
  153597. if (length > 0)
  153598. (*cinfo->src->skip_input_data) (cinfo, (long) length);
  153599. return TRUE;
  153600. }
  153601. LOCAL(boolean)
  153602. next_marker (j_decompress_ptr cinfo)
  153603. {
  153604. int c;
  153605. INPUT_VARS(cinfo);
  153606. for (;;) {
  153607. INPUT_BYTE(cinfo, c, return FALSE);
  153608. while (c != 0xFF) {
  153609. cinfo->marker->discarded_bytes++;
  153610. INPUT_SYNC(cinfo);
  153611. INPUT_BYTE(cinfo, c, return FALSE);
  153612. }
  153613. do {
  153614. INPUT_BYTE(cinfo, c, return FALSE);
  153615. } while (c == 0xFF);
  153616. if (c != 0)
  153617. break; /* found a valid marker, exit loop */
  153618. cinfo->marker->discarded_bytes += 2;
  153619. INPUT_SYNC(cinfo);
  153620. }
  153621. if (cinfo->marker->discarded_bytes != 0) {
  153622. WARNMS2(cinfo, JWRN_EXTRANEOUS_DATA, cinfo->marker->discarded_bytes, c);
  153623. cinfo->marker->discarded_bytes = 0;
  153624. }
  153625. cinfo->unread_marker = c;
  153626. INPUT_SYNC(cinfo);
  153627. return TRUE;
  153628. }
  153629. LOCAL(boolean)
  153630. first_marker (j_decompress_ptr cinfo)
  153631. {
  153632. int c, c2;
  153633. INPUT_VARS(cinfo);
  153634. INPUT_BYTE(cinfo, c, return FALSE);
  153635. INPUT_BYTE(cinfo, c2, return FALSE);
  153636. if (c != 0xFF || c2 != (int) M_SOI)
  153637. ERREXIT2(cinfo, JERR_NO_SOI, c, c2);
  153638. cinfo->unread_marker = c2;
  153639. INPUT_SYNC(cinfo);
  153640. return TRUE;
  153641. }
  153642. METHODDEF(int)
  153643. read_markers (j_decompress_ptr cinfo)
  153644. {
  153645. for (;;) {
  153646. if (cinfo->unread_marker == 0) {
  153647. if (! cinfo->marker->saw_SOI) {
  153648. if (! first_marker(cinfo))
  153649. return JPEG_SUSPENDED;
  153650. } else {
  153651. if (! next_marker(cinfo))
  153652. return JPEG_SUSPENDED;
  153653. }
  153654. }
  153655. switch (cinfo->unread_marker) {
  153656. case M_SOI:
  153657. if (! get_soi(cinfo))
  153658. return JPEG_SUSPENDED;
  153659. break;
  153660. case M_SOF0: /* Baseline */
  153661. case M_SOF1: /* Extended sequential, Huffman */
  153662. if (! get_sof(cinfo, FALSE, FALSE))
  153663. return JPEG_SUSPENDED;
  153664. break;
  153665. case M_SOF2: /* Progressive, Huffman */
  153666. if (! get_sof(cinfo, TRUE, FALSE))
  153667. return JPEG_SUSPENDED;
  153668. break;
  153669. case M_SOF9: /* Extended sequential, arithmetic */
  153670. if (! get_sof(cinfo, FALSE, TRUE))
  153671. return JPEG_SUSPENDED;
  153672. break;
  153673. case M_SOF10: /* Progressive, arithmetic */
  153674. if (! get_sof(cinfo, TRUE, TRUE))
  153675. return JPEG_SUSPENDED;
  153676. break;
  153677. case M_SOF3: /* Lossless, Huffman */
  153678. case M_SOF5: /* Differential sequential, Huffman */
  153679. case M_SOF6: /* Differential progressive, Huffman */
  153680. case M_SOF7: /* Differential lossless, Huffman */
  153681. case M_JPG: /* Reserved for JPEG extensions */
  153682. case M_SOF11: /* Lossless, arithmetic */
  153683. case M_SOF13: /* Differential sequential, arithmetic */
  153684. case M_SOF14: /* Differential progressive, arithmetic */
  153685. case M_SOF15: /* Differential lossless, arithmetic */
  153686. ERREXIT1(cinfo, JERR_SOF_UNSUPPORTED, cinfo->unread_marker);
  153687. break;
  153688. case M_SOS:
  153689. if (! get_sos(cinfo))
  153690. return JPEG_SUSPENDED;
  153691. cinfo->unread_marker = 0; /* processed the marker */
  153692. return JPEG_REACHED_SOS;
  153693. case M_EOI:
  153694. TRACEMS(cinfo, 1, JTRC_EOI);
  153695. cinfo->unread_marker = 0; /* processed the marker */
  153696. return JPEG_REACHED_EOI;
  153697. case M_DAC:
  153698. if (! get_dac(cinfo))
  153699. return JPEG_SUSPENDED;
  153700. break;
  153701. case M_DHT:
  153702. if (! get_dht(cinfo))
  153703. return JPEG_SUSPENDED;
  153704. break;
  153705. case M_DQT:
  153706. if (! get_dqt(cinfo))
  153707. return JPEG_SUSPENDED;
  153708. break;
  153709. case M_DRI:
  153710. if (! get_dri(cinfo))
  153711. return JPEG_SUSPENDED;
  153712. break;
  153713. case M_APP0:
  153714. case M_APP1:
  153715. case M_APP2:
  153716. case M_APP3:
  153717. case M_APP4:
  153718. case M_APP5:
  153719. case M_APP6:
  153720. case M_APP7:
  153721. case M_APP8:
  153722. case M_APP9:
  153723. case M_APP10:
  153724. case M_APP11:
  153725. case M_APP12:
  153726. case M_APP13:
  153727. case M_APP14:
  153728. case M_APP15:
  153729. if (! (*((my_marker_ptr2) cinfo->marker)->process_APPn[
  153730. cinfo->unread_marker - (int) M_APP0]) (cinfo))
  153731. return JPEG_SUSPENDED;
  153732. break;
  153733. case M_COM:
  153734. if (! (*((my_marker_ptr2) cinfo->marker)->process_COM) (cinfo))
  153735. return JPEG_SUSPENDED;
  153736. break;
  153737. case M_RST0: /* these are all parameterless */
  153738. case M_RST1:
  153739. case M_RST2:
  153740. case M_RST3:
  153741. case M_RST4:
  153742. case M_RST5:
  153743. case M_RST6:
  153744. case M_RST7:
  153745. case M_TEM:
  153746. TRACEMS1(cinfo, 1, JTRC_PARMLESS_MARKER, cinfo->unread_marker);
  153747. break;
  153748. case M_DNL: /* Ignore DNL ... perhaps the wrong thing */
  153749. if (! skip_variable(cinfo))
  153750. return JPEG_SUSPENDED;
  153751. break;
  153752. default: /* must be DHP, EXP, JPGn, or RESn */
  153753. ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, cinfo->unread_marker);
  153754. break;
  153755. }
  153756. cinfo->unread_marker = 0;
  153757. } /* end loop */
  153758. }
  153759. METHODDEF(boolean)
  153760. read_restart_marker (j_decompress_ptr cinfo)
  153761. {
  153762. if (cinfo->unread_marker == 0) {
  153763. if (! next_marker(cinfo))
  153764. return FALSE;
  153765. }
  153766. if (cinfo->unread_marker ==
  153767. ((int) M_RST0 + cinfo->marker->next_restart_num)) {
  153768. TRACEMS1(cinfo, 3, JTRC_RST, cinfo->marker->next_restart_num);
  153769. cinfo->unread_marker = 0;
  153770. } else {
  153771. if (! (*cinfo->src->resync_to_restart) (cinfo,
  153772. cinfo->marker->next_restart_num))
  153773. return FALSE;
  153774. }
  153775. cinfo->marker->next_restart_num = (cinfo->marker->next_restart_num + 1) & 7;
  153776. return TRUE;
  153777. }
  153778. GLOBAL(boolean)
  153779. jpeg_resync_to_restart (j_decompress_ptr cinfo, int desired)
  153780. {
  153781. int marker = cinfo->unread_marker;
  153782. int action = 1;
  153783. WARNMS2(cinfo, JWRN_MUST_RESYNC, marker, desired);
  153784. for (;;) {
  153785. if (marker < (int) M_SOF0)
  153786. action = 2; /* invalid marker */
  153787. else if (marker < (int) M_RST0 || marker > (int) M_RST7)
  153788. action = 3; /* valid non-restart marker */
  153789. else {
  153790. if (marker == ((int) M_RST0 + ((desired+1) & 7)) ||
  153791. marker == ((int) M_RST0 + ((desired+2) & 7)))
  153792. action = 3; /* one of the next two expected restarts */
  153793. else if (marker == ((int) M_RST0 + ((desired-1) & 7)) ||
  153794. marker == ((int) M_RST0 + ((desired-2) & 7)))
  153795. action = 2; /* a prior restart, so advance */
  153796. else
  153797. action = 1; /* desired restart or too far away */
  153798. }
  153799. TRACEMS2(cinfo, 4, JTRC_RECOVERY_ACTION, marker, action);
  153800. switch (action) {
  153801. case 1:
  153802. cinfo->unread_marker = 0;
  153803. return TRUE;
  153804. case 2:
  153805. if (! next_marker(cinfo))
  153806. return FALSE;
  153807. marker = cinfo->unread_marker;
  153808. break;
  153809. case 3:
  153810. return TRUE;
  153811. }
  153812. } /* end loop */
  153813. }
  153814. METHODDEF(void)
  153815. reset_marker_reader (j_decompress_ptr cinfo)
  153816. {
  153817. my_marker_ptr2 marker = (my_marker_ptr2) cinfo->marker;
  153818. cinfo->comp_info = NULL; /* until allocated by get_sof */
  153819. cinfo->input_scan_number = 0; /* no SOS seen yet */
  153820. cinfo->unread_marker = 0; /* no pending marker */
  153821. marker->pub.saw_SOI = FALSE; /* set internal state too */
  153822. marker->pub.saw_SOF = FALSE;
  153823. marker->pub.discarded_bytes = 0;
  153824. marker->cur_marker = NULL;
  153825. }
  153826. GLOBAL(void)
  153827. jinit_marker_reader (j_decompress_ptr cinfo)
  153828. {
  153829. my_marker_ptr2 marker;
  153830. int i;
  153831. marker = (my_marker_ptr2)
  153832. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  153833. SIZEOF(my_marker_reader));
  153834. cinfo->marker = (struct jpeg_marker_reader *) marker;
  153835. marker->pub.reset_marker_reader = reset_marker_reader;
  153836. marker->pub.read_markers = read_markers;
  153837. marker->pub.read_restart_marker = read_restart_marker;
  153838. marker->process_COM = skip_variable;
  153839. marker->length_limit_COM = 0;
  153840. for (i = 0; i < 16; i++) {
  153841. marker->process_APPn[i] = skip_variable;
  153842. marker->length_limit_APPn[i] = 0;
  153843. }
  153844. marker->process_APPn[0] = get_interesting_appn;
  153845. marker->process_APPn[14] = get_interesting_appn;
  153846. reset_marker_reader(cinfo);
  153847. }
  153848. #ifdef SAVE_MARKERS_SUPPORTED
  153849. GLOBAL(void)
  153850. jpeg_save_markers (j_decompress_ptr cinfo, int marker_code,
  153851. unsigned int length_limit)
  153852. {
  153853. my_marker_ptr2 marker = (my_marker_ptr2) cinfo->marker;
  153854. long maxlength;
  153855. jpeg_marker_parser_method processor;
  153856. maxlength = cinfo->mem->max_alloc_chunk - SIZEOF(struct jpeg_marker_struct);
  153857. if (((long) length_limit) > maxlength)
  153858. length_limit = (unsigned int) maxlength;
  153859. if (length_limit) {
  153860. processor = save_marker;
  153861. if (marker_code == (int) M_APP0 && length_limit < APP0_DATA_LEN)
  153862. length_limit = APP0_DATA_LEN;
  153863. else if (marker_code == (int) M_APP14 && length_limit < APP14_DATA_LEN)
  153864. length_limit = APP14_DATA_LEN;
  153865. } else {
  153866. processor = skip_variable;
  153867. if (marker_code == (int) M_APP0 || marker_code == (int) M_APP14)
  153868. processor = get_interesting_appn;
  153869. }
  153870. if (marker_code == (int) M_COM) {
  153871. marker->process_COM = processor;
  153872. marker->length_limit_COM = length_limit;
  153873. } else if (marker_code >= (int) M_APP0 && marker_code <= (int) M_APP15) {
  153874. marker->process_APPn[marker_code - (int) M_APP0] = processor;
  153875. marker->length_limit_APPn[marker_code - (int) M_APP0] = length_limit;
  153876. } else
  153877. ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, marker_code);
  153878. }
  153879. #endif /* SAVE_MARKERS_SUPPORTED */
  153880. GLOBAL(void)
  153881. jpeg_set_marker_processor (j_decompress_ptr cinfo, int marker_code,
  153882. jpeg_marker_parser_method routine)
  153883. {
  153884. my_marker_ptr2 marker = (my_marker_ptr2) cinfo->marker;
  153885. if (marker_code == (int) M_COM)
  153886. marker->process_COM = routine;
  153887. else if (marker_code >= (int) M_APP0 && marker_code <= (int) M_APP15)
  153888. marker->process_APPn[marker_code - (int) M_APP0] = routine;
  153889. else
  153890. ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, marker_code);
  153891. }
  153892. /*** End of inlined file: jdmarker.c ***/
  153893. /*** Start of inlined file: jdmaster.c ***/
  153894. #define JPEG_INTERNALS
  153895. typedef struct {
  153896. struct jpeg_decomp_master pub; /* public fields */
  153897. int pass_number; /* # of passes completed */
  153898. boolean using_merged_upsample; /* TRUE if using merged upsample/cconvert */
  153899. struct jpeg_color_quantizer * quantizer_1pass;
  153900. struct jpeg_color_quantizer * quantizer_2pass;
  153901. } my_decomp_master;
  153902. typedef my_decomp_master * my_master_ptr6;
  153903. LOCAL(boolean)
  153904. use_merged_upsample (j_decompress_ptr cinfo)
  153905. {
  153906. #ifdef UPSAMPLE_MERGING_SUPPORTED
  153907. if (cinfo->do_fancy_upsampling || cinfo->CCIR601_sampling)
  153908. return FALSE;
  153909. if (cinfo->jpeg_color_space != JCS_YCbCr || cinfo->num_components != 3 ||
  153910. cinfo->out_color_space != JCS_RGB ||
  153911. cinfo->out_color_components != RGB_PIXELSIZE)
  153912. return FALSE;
  153913. if (cinfo->comp_info[0].h_samp_factor != 2 ||
  153914. cinfo->comp_info[1].h_samp_factor != 1 ||
  153915. cinfo->comp_info[2].h_samp_factor != 1 ||
  153916. cinfo->comp_info[0].v_samp_factor > 2 ||
  153917. cinfo->comp_info[1].v_samp_factor != 1 ||
  153918. cinfo->comp_info[2].v_samp_factor != 1)
  153919. return FALSE;
  153920. if (cinfo->comp_info[0].DCT_scaled_size != cinfo->min_DCT_scaled_size ||
  153921. cinfo->comp_info[1].DCT_scaled_size != cinfo->min_DCT_scaled_size ||
  153922. cinfo->comp_info[2].DCT_scaled_size != cinfo->min_DCT_scaled_size)
  153923. return FALSE;
  153924. return TRUE; /* by golly, it'll work... */
  153925. #else
  153926. return FALSE;
  153927. #endif
  153928. }
  153929. GLOBAL(void)
  153930. jpeg_calc_output_dimensions (j_decompress_ptr cinfo)
  153931. {
  153932. #ifdef IDCT_SCALING_SUPPORTED
  153933. int ci;
  153934. jpeg_component_info *compptr;
  153935. #endif
  153936. if (cinfo->global_state != DSTATE_READY)
  153937. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  153938. #ifdef IDCT_SCALING_SUPPORTED
  153939. if (cinfo->scale_num * 8 <= cinfo->scale_denom) {
  153940. cinfo->output_width = (JDIMENSION)
  153941. jdiv_round_up((long) cinfo->image_width, 8L);
  153942. cinfo->output_height = (JDIMENSION)
  153943. jdiv_round_up((long) cinfo->image_height, 8L);
  153944. cinfo->min_DCT_scaled_size = 1;
  153945. } else if (cinfo->scale_num * 4 <= cinfo->scale_denom) {
  153946. cinfo->output_width = (JDIMENSION)
  153947. jdiv_round_up((long) cinfo->image_width, 4L);
  153948. cinfo->output_height = (JDIMENSION)
  153949. jdiv_round_up((long) cinfo->image_height, 4L);
  153950. cinfo->min_DCT_scaled_size = 2;
  153951. } else if (cinfo->scale_num * 2 <= cinfo->scale_denom) {
  153952. cinfo->output_width = (JDIMENSION)
  153953. jdiv_round_up((long) cinfo->image_width, 2L);
  153954. cinfo->output_height = (JDIMENSION)
  153955. jdiv_round_up((long) cinfo->image_height, 2L);
  153956. cinfo->min_DCT_scaled_size = 4;
  153957. } else {
  153958. cinfo->output_width = cinfo->image_width;
  153959. cinfo->output_height = cinfo->image_height;
  153960. cinfo->min_DCT_scaled_size = DCTSIZE;
  153961. }
  153962. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  153963. ci++, compptr++) {
  153964. int ssize = cinfo->min_DCT_scaled_size;
  153965. while (ssize < DCTSIZE &&
  153966. (compptr->h_samp_factor * ssize * 2 <=
  153967. cinfo->max_h_samp_factor * cinfo->min_DCT_scaled_size) &&
  153968. (compptr->v_samp_factor * ssize * 2 <=
  153969. cinfo->max_v_samp_factor * cinfo->min_DCT_scaled_size)) {
  153970. ssize = ssize * 2;
  153971. }
  153972. compptr->DCT_scaled_size = ssize;
  153973. }
  153974. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  153975. ci++, compptr++) {
  153976. compptr->downsampled_width = (JDIMENSION)
  153977. jdiv_round_up((long) cinfo->image_width *
  153978. (long) (compptr->h_samp_factor * compptr->DCT_scaled_size),
  153979. (long) (cinfo->max_h_samp_factor * DCTSIZE));
  153980. compptr->downsampled_height = (JDIMENSION)
  153981. jdiv_round_up((long) cinfo->image_height *
  153982. (long) (compptr->v_samp_factor * compptr->DCT_scaled_size),
  153983. (long) (cinfo->max_v_samp_factor * DCTSIZE));
  153984. }
  153985. #else /* !IDCT_SCALING_SUPPORTED */
  153986. cinfo->output_width = cinfo->image_width;
  153987. cinfo->output_height = cinfo->image_height;
  153988. #endif /* IDCT_SCALING_SUPPORTED */
  153989. switch (cinfo->out_color_space) {
  153990. case JCS_GRAYSCALE:
  153991. cinfo->out_color_components = 1;
  153992. break;
  153993. case JCS_RGB:
  153994. #if RGB_PIXELSIZE != 3
  153995. cinfo->out_color_components = RGB_PIXELSIZE;
  153996. break;
  153997. #endif /* else share code with YCbCr */
  153998. case JCS_YCbCr:
  153999. cinfo->out_color_components = 3;
  154000. break;
  154001. case JCS_CMYK:
  154002. case JCS_YCCK:
  154003. cinfo->out_color_components = 4;
  154004. break;
  154005. default: /* else must be same colorspace as in file */
  154006. cinfo->out_color_components = cinfo->num_components;
  154007. break;
  154008. }
  154009. cinfo->output_components = (cinfo->quantize_colors ? 1 :
  154010. cinfo->out_color_components);
  154011. if (use_merged_upsample(cinfo))
  154012. cinfo->rec_outbuf_height = cinfo->max_v_samp_factor;
  154013. else
  154014. cinfo->rec_outbuf_height = 1;
  154015. }
  154016. LOCAL(void)
  154017. prepare_range_limit_table (j_decompress_ptr cinfo)
  154018. {
  154019. JSAMPLE * table;
  154020. int i;
  154021. table = (JSAMPLE *)
  154022. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154023. (5 * (MAXJSAMPLE+1) + CENTERJSAMPLE) * SIZEOF(JSAMPLE));
  154024. table += (MAXJSAMPLE+1); /* allow negative subscripts of simple table */
  154025. cinfo->sample_range_limit = table;
  154026. MEMZERO(table - (MAXJSAMPLE+1), (MAXJSAMPLE+1) * SIZEOF(JSAMPLE));
  154027. for (i = 0; i <= MAXJSAMPLE; i++)
  154028. table[i] = (JSAMPLE) i;
  154029. table += CENTERJSAMPLE; /* Point to where post-IDCT table starts */
  154030. for (i = CENTERJSAMPLE; i < 2*(MAXJSAMPLE+1); i++)
  154031. table[i] = MAXJSAMPLE;
  154032. MEMZERO(table + (2 * (MAXJSAMPLE+1)),
  154033. (2 * (MAXJSAMPLE+1) - CENTERJSAMPLE) * SIZEOF(JSAMPLE));
  154034. MEMCOPY(table + (4 * (MAXJSAMPLE+1) - CENTERJSAMPLE),
  154035. cinfo->sample_range_limit, CENTERJSAMPLE * SIZEOF(JSAMPLE));
  154036. }
  154037. LOCAL(void)
  154038. master_selection (j_decompress_ptr cinfo)
  154039. {
  154040. my_master_ptr6 master = (my_master_ptr6) cinfo->master;
  154041. boolean use_c_buffer;
  154042. long samplesperrow;
  154043. JDIMENSION jd_samplesperrow;
  154044. jpeg_calc_output_dimensions(cinfo);
  154045. prepare_range_limit_table(cinfo);
  154046. samplesperrow = (long) cinfo->output_width * (long) cinfo->out_color_components;
  154047. jd_samplesperrow = (JDIMENSION) samplesperrow;
  154048. if ((long) jd_samplesperrow != samplesperrow)
  154049. ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  154050. master->pass_number = 0;
  154051. master->using_merged_upsample = use_merged_upsample(cinfo);
  154052. master->quantizer_1pass = NULL;
  154053. master->quantizer_2pass = NULL;
  154054. if (! cinfo->quantize_colors || ! cinfo->buffered_image) {
  154055. cinfo->enable_1pass_quant = FALSE;
  154056. cinfo->enable_external_quant = FALSE;
  154057. cinfo->enable_2pass_quant = FALSE;
  154058. }
  154059. if (cinfo->quantize_colors) {
  154060. if (cinfo->raw_data_out)
  154061. ERREXIT(cinfo, JERR_NOTIMPL);
  154062. if (cinfo->out_color_components != 3) {
  154063. cinfo->enable_1pass_quant = TRUE;
  154064. cinfo->enable_external_quant = FALSE;
  154065. cinfo->enable_2pass_quant = FALSE;
  154066. cinfo->colormap = NULL;
  154067. } else if (cinfo->colormap != NULL) {
  154068. cinfo->enable_external_quant = TRUE;
  154069. } else if (cinfo->two_pass_quantize) {
  154070. cinfo->enable_2pass_quant = TRUE;
  154071. } else {
  154072. cinfo->enable_1pass_quant = TRUE;
  154073. }
  154074. if (cinfo->enable_1pass_quant) {
  154075. #ifdef QUANT_1PASS_SUPPORTED
  154076. jinit_1pass_quantizer(cinfo);
  154077. master->quantizer_1pass = cinfo->cquantize;
  154078. #else
  154079. ERREXIT(cinfo, JERR_NOT_COMPILED);
  154080. #endif
  154081. }
  154082. if (cinfo->enable_2pass_quant || cinfo->enable_external_quant) {
  154083. #ifdef QUANT_2PASS_SUPPORTED
  154084. jinit_2pass_quantizer(cinfo);
  154085. master->quantizer_2pass = cinfo->cquantize;
  154086. #else
  154087. ERREXIT(cinfo, JERR_NOT_COMPILED);
  154088. #endif
  154089. }
  154090. }
  154091. if (! cinfo->raw_data_out) {
  154092. if (master->using_merged_upsample) {
  154093. #ifdef UPSAMPLE_MERGING_SUPPORTED
  154094. jinit_merged_upsampler(cinfo); /* does color conversion too */
  154095. #else
  154096. ERREXIT(cinfo, JERR_NOT_COMPILED);
  154097. #endif
  154098. } else {
  154099. jinit_color_deconverter(cinfo);
  154100. jinit_upsampler(cinfo);
  154101. }
  154102. jinit_d_post_controller(cinfo, cinfo->enable_2pass_quant);
  154103. }
  154104. jinit_inverse_dct(cinfo);
  154105. if (cinfo->arith_code) {
  154106. ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
  154107. } else {
  154108. if (cinfo->progressive_mode) {
  154109. #ifdef D_PROGRESSIVE_SUPPORTED
  154110. jinit_phuff_decoder(cinfo);
  154111. #else
  154112. ERREXIT(cinfo, JERR_NOT_COMPILED);
  154113. #endif
  154114. } else
  154115. jinit_huff_decoder(cinfo);
  154116. }
  154117. use_c_buffer = cinfo->inputctl->has_multiple_scans || cinfo->buffered_image;
  154118. jinit_d_coef_controller(cinfo, use_c_buffer);
  154119. if (! cinfo->raw_data_out)
  154120. jinit_d_main_controller(cinfo, FALSE /* never need full buffer here */);
  154121. (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
  154122. (*cinfo->inputctl->start_input_pass) (cinfo);
  154123. #ifdef D_MULTISCAN_FILES_SUPPORTED
  154124. if (cinfo->progress != NULL && ! cinfo->buffered_image &&
  154125. cinfo->inputctl->has_multiple_scans) {
  154126. int nscans;
  154127. if (cinfo->progressive_mode) {
  154128. nscans = 2 + 3 * cinfo->num_components;
  154129. } else {
  154130. nscans = cinfo->num_components;
  154131. }
  154132. cinfo->progress->pass_counter = 0L;
  154133. cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows * nscans;
  154134. cinfo->progress->completed_passes = 0;
  154135. cinfo->progress->total_passes = (cinfo->enable_2pass_quant ? 3 : 2);
  154136. master->pass_number++;
  154137. }
  154138. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  154139. }
  154140. METHODDEF(void)
  154141. prepare_for_output_pass (j_decompress_ptr cinfo)
  154142. {
  154143. my_master_ptr6 master = (my_master_ptr6) cinfo->master;
  154144. if (master->pub.is_dummy_pass) {
  154145. #ifdef QUANT_2PASS_SUPPORTED
  154146. master->pub.is_dummy_pass = FALSE;
  154147. (*cinfo->cquantize->start_pass) (cinfo, FALSE);
  154148. (*cinfo->post->start_pass) (cinfo, JBUF_CRANK_DEST);
  154149. (*cinfo->main->start_pass) (cinfo, JBUF_CRANK_DEST);
  154150. #else
  154151. ERREXIT(cinfo, JERR_NOT_COMPILED);
  154152. #endif /* QUANT_2PASS_SUPPORTED */
  154153. } else {
  154154. if (cinfo->quantize_colors && cinfo->colormap == NULL) {
  154155. if (cinfo->two_pass_quantize && cinfo->enable_2pass_quant) {
  154156. cinfo->cquantize = master->quantizer_2pass;
  154157. master->pub.is_dummy_pass = TRUE;
  154158. } else if (cinfo->enable_1pass_quant) {
  154159. cinfo->cquantize = master->quantizer_1pass;
  154160. } else {
  154161. ERREXIT(cinfo, JERR_MODE_CHANGE);
  154162. }
  154163. }
  154164. (*cinfo->idct->start_pass) (cinfo);
  154165. (*cinfo->coef->start_output_pass) (cinfo);
  154166. if (! cinfo->raw_data_out) {
  154167. if (! master->using_merged_upsample)
  154168. (*cinfo->cconvert->start_pass) (cinfo);
  154169. (*cinfo->upsample->start_pass) (cinfo);
  154170. if (cinfo->quantize_colors)
  154171. (*cinfo->cquantize->start_pass) (cinfo, master->pub.is_dummy_pass);
  154172. (*cinfo->post->start_pass) (cinfo,
  154173. (master->pub.is_dummy_pass ? JBUF_SAVE_AND_PASS : JBUF_PASS_THRU));
  154174. (*cinfo->main->start_pass) (cinfo, JBUF_PASS_THRU);
  154175. }
  154176. }
  154177. if (cinfo->progress != NULL) {
  154178. cinfo->progress->completed_passes = master->pass_number;
  154179. cinfo->progress->total_passes = master->pass_number +
  154180. (master->pub.is_dummy_pass ? 2 : 1);
  154181. if (cinfo->buffered_image && ! cinfo->inputctl->eoi_reached) {
  154182. cinfo->progress->total_passes += (cinfo->enable_2pass_quant ? 2 : 1);
  154183. }
  154184. }
  154185. }
  154186. METHODDEF(void)
  154187. finish_output_pass (j_decompress_ptr cinfo)
  154188. {
  154189. my_master_ptr6 master = (my_master_ptr6) cinfo->master;
  154190. if (cinfo->quantize_colors)
  154191. (*cinfo->cquantize->finish_pass) (cinfo);
  154192. master->pass_number++;
  154193. }
  154194. #ifdef D_MULTISCAN_FILES_SUPPORTED
  154195. GLOBAL(void)
  154196. jpeg_new_colormap (j_decompress_ptr cinfo)
  154197. {
  154198. my_master_ptr6 master = (my_master_ptr6) cinfo->master;
  154199. if (cinfo->global_state != DSTATE_BUFIMAGE)
  154200. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  154201. if (cinfo->quantize_colors && cinfo->enable_external_quant &&
  154202. cinfo->colormap != NULL) {
  154203. cinfo->cquantize = master->quantizer_2pass;
  154204. (*cinfo->cquantize->new_color_map) (cinfo);
  154205. master->pub.is_dummy_pass = FALSE; /* just in case */
  154206. } else
  154207. ERREXIT(cinfo, JERR_MODE_CHANGE);
  154208. }
  154209. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  154210. GLOBAL(void)
  154211. jinit_master_decompress (j_decompress_ptr cinfo)
  154212. {
  154213. my_master_ptr6 master;
  154214. master = (my_master_ptr6)
  154215. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154216. SIZEOF(my_decomp_master));
  154217. cinfo->master = (struct jpeg_decomp_master *) master;
  154218. master->pub.prepare_for_output_pass = prepare_for_output_pass;
  154219. master->pub.finish_output_pass = finish_output_pass;
  154220. master->pub.is_dummy_pass = FALSE;
  154221. master_selection(cinfo);
  154222. }
  154223. /*** End of inlined file: jdmaster.c ***/
  154224. #undef FIX
  154225. /*** Start of inlined file: jdmerge.c ***/
  154226. #define JPEG_INTERNALS
  154227. #ifdef UPSAMPLE_MERGING_SUPPORTED
  154228. typedef struct {
  154229. struct jpeg_upsampler pub; /* public fields */
  154230. JMETHOD(void, upmethod, (j_decompress_ptr cinfo,
  154231. JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
  154232. JSAMPARRAY output_buf));
  154233. int * Cr_r_tab; /* => table for Cr to R conversion */
  154234. int * Cb_b_tab; /* => table for Cb to B conversion */
  154235. INT32 * Cr_g_tab; /* => table for Cr to G conversion */
  154236. INT32 * Cb_g_tab; /* => table for Cb to G conversion */
  154237. JSAMPROW spare_row;
  154238. boolean spare_full; /* T if spare buffer is occupied */
  154239. JDIMENSION out_row_width; /* samples per output row */
  154240. JDIMENSION rows_to_go; /* counts rows remaining in image */
  154241. } my_upsampler;
  154242. typedef my_upsampler * my_upsample_ptr;
  154243. #define SCALEBITS 16 /* speediest right-shift on some machines */
  154244. #define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
  154245. #define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
  154246. LOCAL(void)
  154247. build_ycc_rgb_table2 (j_decompress_ptr cinfo)
  154248. {
  154249. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  154250. int i;
  154251. INT32 x;
  154252. SHIFT_TEMPS
  154253. upsample->Cr_r_tab = (int *)
  154254. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154255. (MAXJSAMPLE+1) * SIZEOF(int));
  154256. upsample->Cb_b_tab = (int *)
  154257. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154258. (MAXJSAMPLE+1) * SIZEOF(int));
  154259. upsample->Cr_g_tab = (INT32 *)
  154260. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154261. (MAXJSAMPLE+1) * SIZEOF(INT32));
  154262. upsample->Cb_g_tab = (INT32 *)
  154263. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154264. (MAXJSAMPLE+1) * SIZEOF(INT32));
  154265. for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) {
  154266. upsample->Cr_r_tab[i] = (int)
  154267. RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS);
  154268. upsample->Cb_b_tab[i] = (int)
  154269. RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS);
  154270. upsample->Cr_g_tab[i] = (- FIX(0.71414)) * x;
  154271. upsample->Cb_g_tab[i] = (- FIX(0.34414)) * x + ONE_HALF;
  154272. }
  154273. }
  154274. METHODDEF(void)
  154275. start_pass_merged_upsample (j_decompress_ptr cinfo)
  154276. {
  154277. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  154278. upsample->spare_full = FALSE;
  154279. upsample->rows_to_go = cinfo->output_height;
  154280. }
  154281. METHODDEF(void)
  154282. merged_2v_upsample (j_decompress_ptr cinfo,
  154283. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154284. JDIMENSION in_row_groups_avail,
  154285. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154286. JDIMENSION out_rows_avail)
  154287. {
  154288. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  154289. JSAMPROW work_ptrs[2];
  154290. JDIMENSION num_rows; /* number of rows returned to caller */
  154291. if (upsample->spare_full) {
  154292. jcopy_sample_rows(& upsample->spare_row, 0, output_buf + *out_row_ctr, 0,
  154293. 1, upsample->out_row_width);
  154294. num_rows = 1;
  154295. upsample->spare_full = FALSE;
  154296. } else {
  154297. num_rows = 2;
  154298. if (num_rows > upsample->rows_to_go)
  154299. num_rows = upsample->rows_to_go;
  154300. out_rows_avail -= *out_row_ctr;
  154301. if (num_rows > out_rows_avail)
  154302. num_rows = out_rows_avail;
  154303. work_ptrs[0] = output_buf[*out_row_ctr];
  154304. if (num_rows > 1) {
  154305. work_ptrs[1] = output_buf[*out_row_ctr + 1];
  154306. } else {
  154307. work_ptrs[1] = upsample->spare_row;
  154308. upsample->spare_full = TRUE;
  154309. }
  154310. (*upsample->upmethod) (cinfo, input_buf, *in_row_group_ctr, work_ptrs);
  154311. }
  154312. *out_row_ctr += num_rows;
  154313. upsample->rows_to_go -= num_rows;
  154314. if (! upsample->spare_full)
  154315. (*in_row_group_ctr)++;
  154316. }
  154317. METHODDEF(void)
  154318. merged_1v_upsample (j_decompress_ptr cinfo,
  154319. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154320. JDIMENSION in_row_groups_avail,
  154321. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154322. JDIMENSION out_rows_avail)
  154323. {
  154324. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  154325. (*upsample->upmethod) (cinfo, input_buf, *in_row_group_ctr,
  154326. output_buf + *out_row_ctr);
  154327. (*out_row_ctr)++;
  154328. (*in_row_group_ctr)++;
  154329. }
  154330. METHODDEF(void)
  154331. h2v1_merged_upsample (j_decompress_ptr cinfo,
  154332. JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
  154333. JSAMPARRAY output_buf)
  154334. {
  154335. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  154336. register int y, cred, cgreen, cblue;
  154337. int cb, cr;
  154338. register JSAMPROW outptr;
  154339. JSAMPROW inptr0, inptr1, inptr2;
  154340. JDIMENSION col;
  154341. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  154342. int * Crrtab = upsample->Cr_r_tab;
  154343. int * Cbbtab = upsample->Cb_b_tab;
  154344. INT32 * Crgtab = upsample->Cr_g_tab;
  154345. INT32 * Cbgtab = upsample->Cb_g_tab;
  154346. SHIFT_TEMPS
  154347. inptr0 = input_buf[0][in_row_group_ctr];
  154348. inptr1 = input_buf[1][in_row_group_ctr];
  154349. inptr2 = input_buf[2][in_row_group_ctr];
  154350. outptr = output_buf[0];
  154351. for (col = cinfo->output_width >> 1; col > 0; col--) {
  154352. cb = GETJSAMPLE(*inptr1++);
  154353. cr = GETJSAMPLE(*inptr2++);
  154354. cred = Crrtab[cr];
  154355. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  154356. cblue = Cbbtab[cb];
  154357. y = GETJSAMPLE(*inptr0++);
  154358. outptr[RGB_RED] = range_limit[y + cred];
  154359. outptr[RGB_GREEN] = range_limit[y + cgreen];
  154360. outptr[RGB_BLUE] = range_limit[y + cblue];
  154361. outptr += RGB_PIXELSIZE;
  154362. y = GETJSAMPLE(*inptr0++);
  154363. outptr[RGB_RED] = range_limit[y + cred];
  154364. outptr[RGB_GREEN] = range_limit[y + cgreen];
  154365. outptr[RGB_BLUE] = range_limit[y + cblue];
  154366. outptr += RGB_PIXELSIZE;
  154367. }
  154368. if (cinfo->output_width & 1) {
  154369. cb = GETJSAMPLE(*inptr1);
  154370. cr = GETJSAMPLE(*inptr2);
  154371. cred = Crrtab[cr];
  154372. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  154373. cblue = Cbbtab[cb];
  154374. y = GETJSAMPLE(*inptr0);
  154375. outptr[RGB_RED] = range_limit[y + cred];
  154376. outptr[RGB_GREEN] = range_limit[y + cgreen];
  154377. outptr[RGB_BLUE] = range_limit[y + cblue];
  154378. }
  154379. }
  154380. METHODDEF(void)
  154381. h2v2_merged_upsample (j_decompress_ptr cinfo,
  154382. JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
  154383. JSAMPARRAY output_buf)
  154384. {
  154385. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  154386. register int y, cred, cgreen, cblue;
  154387. int cb, cr;
  154388. register JSAMPROW outptr0, outptr1;
  154389. JSAMPROW inptr00, inptr01, inptr1, inptr2;
  154390. JDIMENSION col;
  154391. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  154392. int * Crrtab = upsample->Cr_r_tab;
  154393. int * Cbbtab = upsample->Cb_b_tab;
  154394. INT32 * Crgtab = upsample->Cr_g_tab;
  154395. INT32 * Cbgtab = upsample->Cb_g_tab;
  154396. SHIFT_TEMPS
  154397. inptr00 = input_buf[0][in_row_group_ctr*2];
  154398. inptr01 = input_buf[0][in_row_group_ctr*2 + 1];
  154399. inptr1 = input_buf[1][in_row_group_ctr];
  154400. inptr2 = input_buf[2][in_row_group_ctr];
  154401. outptr0 = output_buf[0];
  154402. outptr1 = output_buf[1];
  154403. for (col = cinfo->output_width >> 1; col > 0; col--) {
  154404. cb = GETJSAMPLE(*inptr1++);
  154405. cr = GETJSAMPLE(*inptr2++);
  154406. cred = Crrtab[cr];
  154407. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  154408. cblue = Cbbtab[cb];
  154409. y = GETJSAMPLE(*inptr00++);
  154410. outptr0[RGB_RED] = range_limit[y + cred];
  154411. outptr0[RGB_GREEN] = range_limit[y + cgreen];
  154412. outptr0[RGB_BLUE] = range_limit[y + cblue];
  154413. outptr0 += RGB_PIXELSIZE;
  154414. y = GETJSAMPLE(*inptr00++);
  154415. outptr0[RGB_RED] = range_limit[y + cred];
  154416. outptr0[RGB_GREEN] = range_limit[y + cgreen];
  154417. outptr0[RGB_BLUE] = range_limit[y + cblue];
  154418. outptr0 += RGB_PIXELSIZE;
  154419. y = GETJSAMPLE(*inptr01++);
  154420. outptr1[RGB_RED] = range_limit[y + cred];
  154421. outptr1[RGB_GREEN] = range_limit[y + cgreen];
  154422. outptr1[RGB_BLUE] = range_limit[y + cblue];
  154423. outptr1 += RGB_PIXELSIZE;
  154424. y = GETJSAMPLE(*inptr01++);
  154425. outptr1[RGB_RED] = range_limit[y + cred];
  154426. outptr1[RGB_GREEN] = range_limit[y + cgreen];
  154427. outptr1[RGB_BLUE] = range_limit[y + cblue];
  154428. outptr1 += RGB_PIXELSIZE;
  154429. }
  154430. if (cinfo->output_width & 1) {
  154431. cb = GETJSAMPLE(*inptr1);
  154432. cr = GETJSAMPLE(*inptr2);
  154433. cred = Crrtab[cr];
  154434. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  154435. cblue = Cbbtab[cb];
  154436. y = GETJSAMPLE(*inptr00);
  154437. outptr0[RGB_RED] = range_limit[y + cred];
  154438. outptr0[RGB_GREEN] = range_limit[y + cgreen];
  154439. outptr0[RGB_BLUE] = range_limit[y + cblue];
  154440. y = GETJSAMPLE(*inptr01);
  154441. outptr1[RGB_RED] = range_limit[y + cred];
  154442. outptr1[RGB_GREEN] = range_limit[y + cgreen];
  154443. outptr1[RGB_BLUE] = range_limit[y + cblue];
  154444. }
  154445. }
  154446. GLOBAL(void)
  154447. jinit_merged_upsampler (j_decompress_ptr cinfo)
  154448. {
  154449. my_upsample_ptr upsample;
  154450. upsample = (my_upsample_ptr)
  154451. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154452. SIZEOF(my_upsampler));
  154453. cinfo->upsample = (struct jpeg_upsampler *) upsample;
  154454. upsample->pub.start_pass = start_pass_merged_upsample;
  154455. upsample->pub.need_context_rows = FALSE;
  154456. upsample->out_row_width = cinfo->output_width * cinfo->out_color_components;
  154457. if (cinfo->max_v_samp_factor == 2) {
  154458. upsample->pub.upsample = merged_2v_upsample;
  154459. upsample->upmethod = h2v2_merged_upsample;
  154460. upsample->spare_row = (JSAMPROW)
  154461. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154462. (size_t) (upsample->out_row_width * SIZEOF(JSAMPLE)));
  154463. } else {
  154464. upsample->pub.upsample = merged_1v_upsample;
  154465. upsample->upmethod = h2v1_merged_upsample;
  154466. upsample->spare_row = NULL;
  154467. }
  154468. build_ycc_rgb_table2(cinfo);
  154469. }
  154470. #endif /* UPSAMPLE_MERGING_SUPPORTED */
  154471. /*** End of inlined file: jdmerge.c ***/
  154472. #undef ASSIGN_STATE
  154473. /*** Start of inlined file: jdphuff.c ***/
  154474. #define JPEG_INTERNALS
  154475. #ifdef D_PROGRESSIVE_SUPPORTED
  154476. typedef struct {
  154477. unsigned int EOBRUN; /* remaining EOBs in EOBRUN */
  154478. int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
  154479. } savable_state3;
  154480. #ifndef NO_STRUCT_ASSIGN
  154481. #define ASSIGN_STATE(dest,src) ((dest) = (src))
  154482. #else
  154483. #if MAX_COMPS_IN_SCAN == 4
  154484. #define ASSIGN_STATE(dest,src) \
  154485. ((dest).EOBRUN = (src).EOBRUN, \
  154486. (dest).last_dc_val[0] = (src).last_dc_val[0], \
  154487. (dest).last_dc_val[1] = (src).last_dc_val[1], \
  154488. (dest).last_dc_val[2] = (src).last_dc_val[2], \
  154489. (dest).last_dc_val[3] = (src).last_dc_val[3])
  154490. #endif
  154491. #endif
  154492. typedef struct {
  154493. struct jpeg_entropy_decoder pub; /* public fields */
  154494. bitread_perm_state bitstate; /* Bit buffer at start of MCU */
  154495. savable_state3 saved; /* Other state at start of MCU */
  154496. unsigned int restarts_to_go; /* MCUs left in this restart interval */
  154497. d_derived_tbl * derived_tbls[NUM_HUFF_TBLS];
  154498. d_derived_tbl * ac_derived_tbl; /* active table during an AC scan */
  154499. } phuff_entropy_decoder;
  154500. typedef phuff_entropy_decoder * phuff_entropy_ptr2;
  154501. METHODDEF(boolean) decode_mcu_DC_first JPP((j_decompress_ptr cinfo,
  154502. JBLOCKROW *MCU_data));
  154503. METHODDEF(boolean) decode_mcu_AC_first JPP((j_decompress_ptr cinfo,
  154504. JBLOCKROW *MCU_data));
  154505. METHODDEF(boolean) decode_mcu_DC_refine JPP((j_decompress_ptr cinfo,
  154506. JBLOCKROW *MCU_data));
  154507. METHODDEF(boolean) decode_mcu_AC_refine JPP((j_decompress_ptr cinfo,
  154508. JBLOCKROW *MCU_data));
  154509. METHODDEF(void)
  154510. start_pass_phuff_decoder (j_decompress_ptr cinfo)
  154511. {
  154512. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154513. boolean is_DC_band, bad;
  154514. int ci, coefi, tbl;
  154515. int *coef_bit_ptr;
  154516. jpeg_component_info * compptr;
  154517. is_DC_band = (cinfo->Ss == 0);
  154518. bad = FALSE;
  154519. if (is_DC_band) {
  154520. if (cinfo->Se != 0)
  154521. bad = TRUE;
  154522. } else {
  154523. if (cinfo->Ss > cinfo->Se || cinfo->Se >= DCTSIZE2)
  154524. bad = TRUE;
  154525. if (cinfo->comps_in_scan != 1)
  154526. bad = TRUE;
  154527. }
  154528. if (cinfo->Ah != 0) {
  154529. if (cinfo->Al != cinfo->Ah-1)
  154530. bad = TRUE;
  154531. }
  154532. if (cinfo->Al > 13) /* need not check for < 0 */
  154533. bad = TRUE;
  154534. if (bad)
  154535. ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
  154536. cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
  154537. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  154538. int cindex = cinfo->cur_comp_info[ci]->component_index;
  154539. coef_bit_ptr = & cinfo->coef_bits[cindex][0];
  154540. if (!is_DC_band && coef_bit_ptr[0] < 0) /* AC without prior DC scan */
  154541. WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, 0);
  154542. for (coefi = cinfo->Ss; coefi <= cinfo->Se; coefi++) {
  154543. int expected = (coef_bit_ptr[coefi] < 0) ? 0 : coef_bit_ptr[coefi];
  154544. if (cinfo->Ah != expected)
  154545. WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, coefi);
  154546. coef_bit_ptr[coefi] = cinfo->Al;
  154547. }
  154548. }
  154549. if (cinfo->Ah == 0) {
  154550. if (is_DC_band)
  154551. entropy->pub.decode_mcu = decode_mcu_DC_first;
  154552. else
  154553. entropy->pub.decode_mcu = decode_mcu_AC_first;
  154554. } else {
  154555. if (is_DC_band)
  154556. entropy->pub.decode_mcu = decode_mcu_DC_refine;
  154557. else
  154558. entropy->pub.decode_mcu = decode_mcu_AC_refine;
  154559. }
  154560. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  154561. compptr = cinfo->cur_comp_info[ci];
  154562. if (is_DC_band) {
  154563. if (cinfo->Ah == 0) { /* DC refinement needs no table */
  154564. tbl = compptr->dc_tbl_no;
  154565. jpeg_make_d_derived_tbl(cinfo, TRUE, tbl,
  154566. & entropy->derived_tbls[tbl]);
  154567. }
  154568. } else {
  154569. tbl = compptr->ac_tbl_no;
  154570. jpeg_make_d_derived_tbl(cinfo, FALSE, tbl,
  154571. & entropy->derived_tbls[tbl]);
  154572. entropy->ac_derived_tbl = entropy->derived_tbls[tbl];
  154573. }
  154574. entropy->saved.last_dc_val[ci] = 0;
  154575. }
  154576. entropy->bitstate.bits_left = 0;
  154577. entropy->bitstate.get_buffer = 0; /* unnecessary, but keeps Purify quiet */
  154578. entropy->pub.insufficient_data = FALSE;
  154579. entropy->saved.EOBRUN = 0;
  154580. entropy->restarts_to_go = cinfo->restart_interval;
  154581. }
  154582. LOCAL(boolean)
  154583. process_restartp (j_decompress_ptr cinfo)
  154584. {
  154585. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154586. int ci;
  154587. cinfo->marker->discarded_bytes += entropy->bitstate.bits_left / 8;
  154588. entropy->bitstate.bits_left = 0;
  154589. if (! (*cinfo->marker->read_restart_marker) (cinfo))
  154590. return FALSE;
  154591. for (ci = 0; ci < cinfo->comps_in_scan; ci++)
  154592. entropy->saved.last_dc_val[ci] = 0;
  154593. entropy->saved.EOBRUN = 0;
  154594. entropy->restarts_to_go = cinfo->restart_interval;
  154595. if (cinfo->unread_marker == 0)
  154596. entropy->pub.insufficient_data = FALSE;
  154597. return TRUE;
  154598. }
  154599. METHODDEF(boolean)
  154600. decode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  154601. {
  154602. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154603. int Al = cinfo->Al;
  154604. register int s, r;
  154605. int blkn, ci;
  154606. JBLOCKROW block;
  154607. BITREAD_STATE_VARS;
  154608. savable_state3 state;
  154609. d_derived_tbl * tbl;
  154610. jpeg_component_info * compptr;
  154611. if (cinfo->restart_interval) {
  154612. if (entropy->restarts_to_go == 0)
  154613. if (! process_restartp(cinfo))
  154614. return FALSE;
  154615. }
  154616. if (! entropy->pub.insufficient_data) {
  154617. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  154618. ASSIGN_STATE(state, entropy->saved);
  154619. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  154620. block = MCU_data[blkn];
  154621. ci = cinfo->MCU_membership[blkn];
  154622. compptr = cinfo->cur_comp_info[ci];
  154623. tbl = entropy->derived_tbls[compptr->dc_tbl_no];
  154624. HUFF_DECODE(s, br_state, tbl, return FALSE, label1);
  154625. if (s) {
  154626. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  154627. r = GET_BITS(s);
  154628. s = HUFF_EXTEND(r, s);
  154629. }
  154630. s += state.last_dc_val[ci];
  154631. state.last_dc_val[ci] = s;
  154632. (*block)[0] = (JCOEF) (s << Al);
  154633. }
  154634. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  154635. ASSIGN_STATE(entropy->saved, state);
  154636. }
  154637. entropy->restarts_to_go--;
  154638. return TRUE;
  154639. }
  154640. METHODDEF(boolean)
  154641. decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  154642. {
  154643. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154644. int Se = cinfo->Se;
  154645. int Al = cinfo->Al;
  154646. register int s, k, r;
  154647. unsigned int EOBRUN;
  154648. JBLOCKROW block;
  154649. BITREAD_STATE_VARS;
  154650. d_derived_tbl * tbl;
  154651. if (cinfo->restart_interval) {
  154652. if (entropy->restarts_to_go == 0)
  154653. if (! process_restartp(cinfo))
  154654. return FALSE;
  154655. }
  154656. if (! entropy->pub.insufficient_data) {
  154657. EOBRUN = entropy->saved.EOBRUN; /* only part of saved state we need */
  154658. if (EOBRUN > 0) /* if it's a band of zeroes... */
  154659. EOBRUN--; /* ...process it now (we do nothing) */
  154660. else {
  154661. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  154662. block = MCU_data[0];
  154663. tbl = entropy->ac_derived_tbl;
  154664. for (k = cinfo->Ss; k <= Se; k++) {
  154665. HUFF_DECODE(s, br_state, tbl, return FALSE, label2);
  154666. r = s >> 4;
  154667. s &= 15;
  154668. if (s) {
  154669. k += r;
  154670. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  154671. r = GET_BITS(s);
  154672. s = HUFF_EXTEND(r, s);
  154673. (*block)[jpeg_natural_order[k]] = (JCOEF) (s << Al);
  154674. } else {
  154675. if (r == 15) { /* ZRL */
  154676. k += 15; /* skip 15 zeroes in band */
  154677. } else { /* EOBr, run length is 2^r + appended bits */
  154678. EOBRUN = 1 << r;
  154679. if (r) { /* EOBr, r > 0 */
  154680. CHECK_BIT_BUFFER(br_state, r, return FALSE);
  154681. r = GET_BITS(r);
  154682. EOBRUN += r;
  154683. }
  154684. EOBRUN--; /* this band is processed at this moment */
  154685. break; /* force end-of-band */
  154686. }
  154687. }
  154688. }
  154689. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  154690. }
  154691. entropy->saved.EOBRUN = EOBRUN; /* only part of saved state we need */
  154692. }
  154693. entropy->restarts_to_go--;
  154694. return TRUE;
  154695. }
  154696. METHODDEF(boolean)
  154697. decode_mcu_DC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  154698. {
  154699. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154700. int p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */
  154701. int blkn;
  154702. JBLOCKROW block;
  154703. BITREAD_STATE_VARS;
  154704. if (cinfo->restart_interval) {
  154705. if (entropy->restarts_to_go == 0)
  154706. if (! process_restartp(cinfo))
  154707. return FALSE;
  154708. }
  154709. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  154710. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  154711. block = MCU_data[blkn];
  154712. CHECK_BIT_BUFFER(br_state, 1, return FALSE);
  154713. if (GET_BITS(1))
  154714. (*block)[0] |= p1;
  154715. }
  154716. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  154717. entropy->restarts_to_go--;
  154718. return TRUE;
  154719. }
  154720. METHODDEF(boolean)
  154721. decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  154722. {
  154723. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154724. int Se = cinfo->Se;
  154725. int p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */
  154726. int m1 = (-1) << cinfo->Al; /* -1 in the bit position being coded */
  154727. register int s, k, r;
  154728. unsigned int EOBRUN;
  154729. JBLOCKROW block;
  154730. JCOEFPTR thiscoef;
  154731. BITREAD_STATE_VARS;
  154732. d_derived_tbl * tbl;
  154733. int num_newnz;
  154734. int newnz_pos[DCTSIZE2];
  154735. if (cinfo->restart_interval) {
  154736. if (entropy->restarts_to_go == 0)
  154737. if (! process_restartp(cinfo))
  154738. return FALSE;
  154739. }
  154740. if (! entropy->pub.insufficient_data) {
  154741. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  154742. EOBRUN = entropy->saved.EOBRUN; /* only part of saved state we need */
  154743. block = MCU_data[0];
  154744. tbl = entropy->ac_derived_tbl;
  154745. num_newnz = 0;
  154746. k = cinfo->Ss;
  154747. if (EOBRUN == 0) {
  154748. for (; k <= Se; k++) {
  154749. HUFF_DECODE(s, br_state, tbl, goto undoit, label3);
  154750. r = s >> 4;
  154751. s &= 15;
  154752. if (s) {
  154753. if (s != 1) /* size of new coef should always be 1 */
  154754. WARNMS(cinfo, JWRN_HUFF_BAD_CODE);
  154755. CHECK_BIT_BUFFER(br_state, 1, goto undoit);
  154756. if (GET_BITS(1))
  154757. s = p1; /* newly nonzero coef is positive */
  154758. else
  154759. s = m1; /* newly nonzero coef is negative */
  154760. } else {
  154761. if (r != 15) {
  154762. EOBRUN = 1 << r; /* EOBr, run length is 2^r + appended bits */
  154763. if (r) {
  154764. CHECK_BIT_BUFFER(br_state, r, goto undoit);
  154765. r = GET_BITS(r);
  154766. EOBRUN += r;
  154767. }
  154768. break; /* rest of block is handled by EOB logic */
  154769. }
  154770. }
  154771. do {
  154772. thiscoef = *block + jpeg_natural_order[k];
  154773. if (*thiscoef != 0) {
  154774. CHECK_BIT_BUFFER(br_state, 1, goto undoit);
  154775. if (GET_BITS(1)) {
  154776. if ((*thiscoef & p1) == 0) { /* do nothing if already set it */
  154777. if (*thiscoef >= 0)
  154778. *thiscoef += p1;
  154779. else
  154780. *thiscoef += m1;
  154781. }
  154782. }
  154783. } else {
  154784. if (--r < 0)
  154785. break; /* reached target zero coefficient */
  154786. }
  154787. k++;
  154788. } while (k <= Se);
  154789. if (s) {
  154790. int pos = jpeg_natural_order[k];
  154791. (*block)[pos] = (JCOEF) s;
  154792. newnz_pos[num_newnz++] = pos;
  154793. }
  154794. }
  154795. }
  154796. if (EOBRUN > 0) {
  154797. for (; k <= Se; k++) {
  154798. thiscoef = *block + jpeg_natural_order[k];
  154799. if (*thiscoef != 0) {
  154800. CHECK_BIT_BUFFER(br_state, 1, goto undoit);
  154801. if (GET_BITS(1)) {
  154802. if ((*thiscoef & p1) == 0) { /* do nothing if already changed it */
  154803. if (*thiscoef >= 0)
  154804. *thiscoef += p1;
  154805. else
  154806. *thiscoef += m1;
  154807. }
  154808. }
  154809. }
  154810. }
  154811. EOBRUN--;
  154812. }
  154813. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  154814. entropy->saved.EOBRUN = EOBRUN; /* only part of saved state we need */
  154815. }
  154816. entropy->restarts_to_go--;
  154817. return TRUE;
  154818. undoit:
  154819. while (num_newnz > 0)
  154820. (*block)[newnz_pos[--num_newnz]] = 0;
  154821. return FALSE;
  154822. }
  154823. GLOBAL(void)
  154824. jinit_phuff_decoder (j_decompress_ptr cinfo)
  154825. {
  154826. phuff_entropy_ptr2 entropy;
  154827. int *coef_bit_ptr;
  154828. int ci, i;
  154829. entropy = (phuff_entropy_ptr2)
  154830. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154831. SIZEOF(phuff_entropy_decoder));
  154832. cinfo->entropy = (struct jpeg_entropy_decoder *) entropy;
  154833. entropy->pub.start_pass = start_pass_phuff_decoder;
  154834. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  154835. entropy->derived_tbls[i] = NULL;
  154836. }
  154837. cinfo->coef_bits = (int (*)[DCTSIZE2])
  154838. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154839. cinfo->num_components*DCTSIZE2*SIZEOF(int));
  154840. coef_bit_ptr = & cinfo->coef_bits[0][0];
  154841. for (ci = 0; ci < cinfo->num_components; ci++)
  154842. for (i = 0; i < DCTSIZE2; i++)
  154843. *coef_bit_ptr++ = -1;
  154844. }
  154845. #endif /* D_PROGRESSIVE_SUPPORTED */
  154846. /*** End of inlined file: jdphuff.c ***/
  154847. /*** Start of inlined file: jdpostct.c ***/
  154848. #define JPEG_INTERNALS
  154849. typedef struct {
  154850. struct jpeg_d_post_controller pub; /* public fields */
  154851. jvirt_sarray_ptr whole_image; /* virtual array, or NULL if one-pass */
  154852. JSAMPARRAY buffer; /* strip buffer, or current strip of virtual */
  154853. JDIMENSION strip_height; /* buffer size in rows */
  154854. JDIMENSION starting_row; /* row # of first row in current strip */
  154855. JDIMENSION next_row; /* index of next row to fill/empty in strip */
  154856. } my_post_controller;
  154857. typedef my_post_controller * my_post_ptr;
  154858. METHODDEF(void) post_process_1pass
  154859. JPP((j_decompress_ptr cinfo,
  154860. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154861. JDIMENSION in_row_groups_avail,
  154862. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154863. JDIMENSION out_rows_avail));
  154864. #ifdef QUANT_2PASS_SUPPORTED
  154865. METHODDEF(void) post_process_prepass
  154866. JPP((j_decompress_ptr cinfo,
  154867. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154868. JDIMENSION in_row_groups_avail,
  154869. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154870. JDIMENSION out_rows_avail));
  154871. METHODDEF(void) post_process_2pass
  154872. JPP((j_decompress_ptr cinfo,
  154873. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154874. JDIMENSION in_row_groups_avail,
  154875. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154876. JDIMENSION out_rows_avail));
  154877. #endif
  154878. METHODDEF(void)
  154879. start_pass_dpost (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
  154880. {
  154881. my_post_ptr post = (my_post_ptr) cinfo->post;
  154882. switch (pass_mode) {
  154883. case JBUF_PASS_THRU:
  154884. if (cinfo->quantize_colors) {
  154885. post->pub.post_process_data = post_process_1pass;
  154886. if (post->buffer == NULL) {
  154887. post->buffer = (*cinfo->mem->access_virt_sarray)
  154888. ((j_common_ptr) cinfo, post->whole_image,
  154889. (JDIMENSION) 0, post->strip_height, TRUE);
  154890. }
  154891. } else {
  154892. post->pub.post_process_data = cinfo->upsample->upsample;
  154893. }
  154894. break;
  154895. #ifdef QUANT_2PASS_SUPPORTED
  154896. case JBUF_SAVE_AND_PASS:
  154897. if (post->whole_image == NULL)
  154898. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  154899. post->pub.post_process_data = post_process_prepass;
  154900. break;
  154901. case JBUF_CRANK_DEST:
  154902. if (post->whole_image == NULL)
  154903. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  154904. post->pub.post_process_data = post_process_2pass;
  154905. break;
  154906. #endif /* QUANT_2PASS_SUPPORTED */
  154907. default:
  154908. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  154909. break;
  154910. }
  154911. post->starting_row = post->next_row = 0;
  154912. }
  154913. METHODDEF(void)
  154914. post_process_1pass (j_decompress_ptr cinfo,
  154915. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154916. JDIMENSION in_row_groups_avail,
  154917. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154918. JDIMENSION out_rows_avail)
  154919. {
  154920. my_post_ptr post = (my_post_ptr) cinfo->post;
  154921. JDIMENSION num_rows, max_rows;
  154922. max_rows = out_rows_avail - *out_row_ctr;
  154923. if (max_rows > post->strip_height)
  154924. max_rows = post->strip_height;
  154925. num_rows = 0;
  154926. (*cinfo->upsample->upsample) (cinfo,
  154927. input_buf, in_row_group_ctr, in_row_groups_avail,
  154928. post->buffer, &num_rows, max_rows);
  154929. (*cinfo->cquantize->color_quantize) (cinfo,
  154930. post->buffer, output_buf + *out_row_ctr, (int) num_rows);
  154931. *out_row_ctr += num_rows;
  154932. }
  154933. #ifdef QUANT_2PASS_SUPPORTED
  154934. METHODDEF(void)
  154935. post_process_prepass (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 old_next_row, num_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, TRUE);
  154947. }
  154948. old_next_row = post->next_row;
  154949. (*cinfo->upsample->upsample) (cinfo,
  154950. input_buf, in_row_group_ctr, in_row_groups_avail,
  154951. post->buffer, &post->next_row, post->strip_height);
  154952. if (post->next_row > old_next_row) {
  154953. num_rows = post->next_row - old_next_row;
  154954. (*cinfo->cquantize->color_quantize) (cinfo, post->buffer + old_next_row,
  154955. (JSAMPARRAY) NULL, (int) num_rows);
  154956. *out_row_ctr += num_rows;
  154957. }
  154958. if (post->next_row >= post->strip_height) {
  154959. post->starting_row += post->strip_height;
  154960. post->next_row = 0;
  154961. }
  154962. }
  154963. METHODDEF(void)
  154964. post_process_2pass (j_decompress_ptr cinfo,
  154965. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154966. JDIMENSION in_row_groups_avail,
  154967. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154968. JDIMENSION out_rows_avail)
  154969. {
  154970. my_post_ptr post = (my_post_ptr) cinfo->post;
  154971. JDIMENSION num_rows, max_rows;
  154972. if (post->next_row == 0) {
  154973. post->buffer = (*cinfo->mem->access_virt_sarray)
  154974. ((j_common_ptr) cinfo, post->whole_image,
  154975. post->starting_row, post->strip_height, FALSE);
  154976. }
  154977. num_rows = post->strip_height - post->next_row; /* available in strip */
  154978. max_rows = out_rows_avail - *out_row_ctr; /* available in output area */
  154979. if (num_rows > max_rows)
  154980. num_rows = max_rows;
  154981. max_rows = cinfo->output_height - post->starting_row;
  154982. if (num_rows > max_rows)
  154983. num_rows = max_rows;
  154984. (*cinfo->cquantize->color_quantize) (cinfo,
  154985. post->buffer + post->next_row, output_buf + *out_row_ctr,
  154986. (int) num_rows);
  154987. *out_row_ctr += num_rows;
  154988. post->next_row += num_rows;
  154989. if (post->next_row >= post->strip_height) {
  154990. post->starting_row += post->strip_height;
  154991. post->next_row = 0;
  154992. }
  154993. }
  154994. #endif /* QUANT_2PASS_SUPPORTED */
  154995. GLOBAL(void)
  154996. jinit_d_post_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
  154997. {
  154998. my_post_ptr post;
  154999. post = (my_post_ptr)
  155000. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  155001. SIZEOF(my_post_controller));
  155002. cinfo->post = (struct jpeg_d_post_controller *) post;
  155003. post->pub.start_pass = start_pass_dpost;
  155004. post->whole_image = NULL; /* flag for no virtual arrays */
  155005. post->buffer = NULL; /* flag for no strip buffer */
  155006. if (cinfo->quantize_colors) {
  155007. post->strip_height = (JDIMENSION) cinfo->max_v_samp_factor;
  155008. if (need_full_buffer) {
  155009. #ifdef QUANT_2PASS_SUPPORTED
  155010. post->whole_image = (*cinfo->mem->request_virt_sarray)
  155011. ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
  155012. cinfo->output_width * cinfo->out_color_components,
  155013. (JDIMENSION) jround_up((long) cinfo->output_height,
  155014. (long) post->strip_height),
  155015. post->strip_height);
  155016. #else
  155017. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  155018. #endif /* QUANT_2PASS_SUPPORTED */
  155019. } else {
  155020. post->buffer = (*cinfo->mem->alloc_sarray)
  155021. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  155022. cinfo->output_width * cinfo->out_color_components,
  155023. post->strip_height);
  155024. }
  155025. }
  155026. }
  155027. /*** End of inlined file: jdpostct.c ***/
  155028. #undef FIX
  155029. /*** Start of inlined file: jdsample.c ***/
  155030. #define JPEG_INTERNALS
  155031. typedef JMETHOD(void, upsample1_ptr,
  155032. (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155033. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr));
  155034. typedef struct {
  155035. struct jpeg_upsampler pub; /* public fields */
  155036. JSAMPARRAY color_buf[MAX_COMPONENTS];
  155037. upsample1_ptr methods[MAX_COMPONENTS];
  155038. int next_row_out; /* counts rows emitted from color_buf */
  155039. JDIMENSION rows_to_go; /* counts rows remaining in image */
  155040. int rowgroup_height[MAX_COMPONENTS];
  155041. UINT8 h_expand[MAX_COMPONENTS];
  155042. UINT8 v_expand[MAX_COMPONENTS];
  155043. } my_upsampler2;
  155044. typedef my_upsampler2 * my_upsample_ptr2;
  155045. METHODDEF(void)
  155046. start_pass_upsample (j_decompress_ptr cinfo)
  155047. {
  155048. my_upsample_ptr2 upsample = (my_upsample_ptr2) cinfo->upsample;
  155049. upsample->next_row_out = cinfo->max_v_samp_factor;
  155050. upsample->rows_to_go = cinfo->output_height;
  155051. }
  155052. METHODDEF(void)
  155053. sep_upsample (j_decompress_ptr cinfo,
  155054. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  155055. JDIMENSION in_row_groups_avail,
  155056. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  155057. JDIMENSION out_rows_avail)
  155058. {
  155059. my_upsample_ptr2 upsample = (my_upsample_ptr2) cinfo->upsample;
  155060. int ci;
  155061. jpeg_component_info * compptr;
  155062. JDIMENSION num_rows;
  155063. if (upsample->next_row_out >= cinfo->max_v_samp_factor) {
  155064. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  155065. ci++, compptr++) {
  155066. (*upsample->methods[ci]) (cinfo, compptr,
  155067. input_buf[ci] + (*in_row_group_ctr * upsample->rowgroup_height[ci]),
  155068. upsample->color_buf + ci);
  155069. }
  155070. upsample->next_row_out = 0;
  155071. }
  155072. num_rows = (JDIMENSION) (cinfo->max_v_samp_factor - upsample->next_row_out);
  155073. if (num_rows > upsample->rows_to_go)
  155074. num_rows = upsample->rows_to_go;
  155075. out_rows_avail -= *out_row_ctr;
  155076. if (num_rows > out_rows_avail)
  155077. num_rows = out_rows_avail;
  155078. (*cinfo->cconvert->color_convert) (cinfo, upsample->color_buf,
  155079. (JDIMENSION) upsample->next_row_out,
  155080. output_buf + *out_row_ctr,
  155081. (int) num_rows);
  155082. *out_row_ctr += num_rows;
  155083. upsample->rows_to_go -= num_rows;
  155084. upsample->next_row_out += num_rows;
  155085. if (upsample->next_row_out >= cinfo->max_v_samp_factor)
  155086. (*in_row_group_ctr)++;
  155087. }
  155088. METHODDEF(void)
  155089. fullsize_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155090. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  155091. {
  155092. *output_data_ptr = input_data;
  155093. }
  155094. METHODDEF(void)
  155095. noop_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155096. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  155097. {
  155098. *output_data_ptr = NULL; /* safety check */
  155099. }
  155100. METHODDEF(void)
  155101. int_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155102. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  155103. {
  155104. my_upsample_ptr2 upsample = (my_upsample_ptr2) cinfo->upsample;
  155105. JSAMPARRAY output_data = *output_data_ptr;
  155106. register JSAMPROW inptr, outptr;
  155107. register JSAMPLE invalue;
  155108. register int h;
  155109. JSAMPROW outend;
  155110. int h_expand, v_expand;
  155111. int inrow, outrow;
  155112. h_expand = upsample->h_expand[compptr->component_index];
  155113. v_expand = upsample->v_expand[compptr->component_index];
  155114. inrow = outrow = 0;
  155115. while (outrow < cinfo->max_v_samp_factor) {
  155116. inptr = input_data[inrow];
  155117. outptr = output_data[outrow];
  155118. outend = outptr + cinfo->output_width;
  155119. while (outptr < outend) {
  155120. invalue = *inptr++; /* don't need GETJSAMPLE() here */
  155121. for (h = h_expand; h > 0; h--) {
  155122. *outptr++ = invalue;
  155123. }
  155124. }
  155125. if (v_expand > 1) {
  155126. jcopy_sample_rows(output_data, outrow, output_data, outrow+1,
  155127. v_expand-1, cinfo->output_width);
  155128. }
  155129. inrow++;
  155130. outrow += v_expand;
  155131. }
  155132. }
  155133. METHODDEF(void)
  155134. h2v1_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155135. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  155136. {
  155137. JSAMPARRAY output_data = *output_data_ptr;
  155138. register JSAMPROW inptr, outptr;
  155139. register JSAMPLE invalue;
  155140. JSAMPROW outend;
  155141. int inrow;
  155142. for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
  155143. inptr = input_data[inrow];
  155144. outptr = output_data[inrow];
  155145. outend = outptr + cinfo->output_width;
  155146. while (outptr < outend) {
  155147. invalue = *inptr++; /* don't need GETJSAMPLE() here */
  155148. *outptr++ = invalue;
  155149. *outptr++ = invalue;
  155150. }
  155151. }
  155152. }
  155153. METHODDEF(void)
  155154. h2v2_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155155. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  155156. {
  155157. JSAMPARRAY output_data = *output_data_ptr;
  155158. register JSAMPROW inptr, outptr;
  155159. register JSAMPLE invalue;
  155160. JSAMPROW outend;
  155161. int inrow, outrow;
  155162. inrow = outrow = 0;
  155163. while (outrow < cinfo->max_v_samp_factor) {
  155164. inptr = input_data[inrow];
  155165. outptr = output_data[outrow];
  155166. outend = outptr + cinfo->output_width;
  155167. while (outptr < outend) {
  155168. invalue = *inptr++; /* don't need GETJSAMPLE() here */
  155169. *outptr++ = invalue;
  155170. *outptr++ = invalue;
  155171. }
  155172. jcopy_sample_rows(output_data, outrow, output_data, outrow+1,
  155173. 1, cinfo->output_width);
  155174. inrow++;
  155175. outrow += 2;
  155176. }
  155177. }
  155178. METHODDEF(void)
  155179. h2v1_fancy_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155180. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  155181. {
  155182. JSAMPARRAY output_data = *output_data_ptr;
  155183. register JSAMPROW inptr, outptr;
  155184. register int invalue;
  155185. register JDIMENSION colctr;
  155186. int inrow;
  155187. for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
  155188. inptr = input_data[inrow];
  155189. outptr = output_data[inrow];
  155190. invalue = GETJSAMPLE(*inptr++);
  155191. *outptr++ = (JSAMPLE) invalue;
  155192. *outptr++ = (JSAMPLE) ((invalue * 3 + GETJSAMPLE(*inptr) + 2) >> 2);
  155193. for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
  155194. invalue = GETJSAMPLE(*inptr++) * 3;
  155195. *outptr++ = (JSAMPLE) ((invalue + GETJSAMPLE(inptr[-2]) + 1) >> 2);
  155196. *outptr++ = (JSAMPLE) ((invalue + GETJSAMPLE(*inptr) + 2) >> 2);
  155197. }
  155198. invalue = GETJSAMPLE(*inptr);
  155199. *outptr++ = (JSAMPLE) ((invalue * 3 + GETJSAMPLE(inptr[-1]) + 1) >> 2);
  155200. *outptr++ = (JSAMPLE) invalue;
  155201. }
  155202. }
  155203. METHODDEF(void)
  155204. h2v2_fancy_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155205. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  155206. {
  155207. JSAMPARRAY output_data = *output_data_ptr;
  155208. register JSAMPROW inptr0, inptr1, outptr;
  155209. #if BITS_IN_JSAMPLE == 8
  155210. register int thiscolsum, lastcolsum, nextcolsum;
  155211. #else
  155212. register INT32 thiscolsum, lastcolsum, nextcolsum;
  155213. #endif
  155214. register JDIMENSION colctr;
  155215. int inrow, outrow, v;
  155216. inrow = outrow = 0;
  155217. while (outrow < cinfo->max_v_samp_factor) {
  155218. for (v = 0; v < 2; v++) {
  155219. inptr0 = input_data[inrow];
  155220. if (v == 0) /* next nearest is row above */
  155221. inptr1 = input_data[inrow-1];
  155222. else /* next nearest is row below */
  155223. inptr1 = input_data[inrow+1];
  155224. outptr = output_data[outrow++];
  155225. thiscolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
  155226. nextcolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
  155227. *outptr++ = (JSAMPLE) ((thiscolsum * 4 + 8) >> 4);
  155228. *outptr++ = (JSAMPLE) ((thiscolsum * 3 + nextcolsum + 7) >> 4);
  155229. lastcolsum = thiscolsum; thiscolsum = nextcolsum;
  155230. for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
  155231. nextcolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
  155232. *outptr++ = (JSAMPLE) ((thiscolsum * 3 + lastcolsum + 8) >> 4);
  155233. *outptr++ = (JSAMPLE) ((thiscolsum * 3 + nextcolsum + 7) >> 4);
  155234. lastcolsum = thiscolsum; thiscolsum = nextcolsum;
  155235. }
  155236. *outptr++ = (JSAMPLE) ((thiscolsum * 3 + lastcolsum + 8) >> 4);
  155237. *outptr++ = (JSAMPLE) ((thiscolsum * 4 + 7) >> 4);
  155238. }
  155239. inrow++;
  155240. }
  155241. }
  155242. GLOBAL(void)
  155243. jinit_upsampler (j_decompress_ptr cinfo)
  155244. {
  155245. my_upsample_ptr2 upsample;
  155246. int ci;
  155247. jpeg_component_info * compptr;
  155248. boolean need_buffer, do_fancy;
  155249. int h_in_group, v_in_group, h_out_group, v_out_group;
  155250. upsample = (my_upsample_ptr2)
  155251. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  155252. SIZEOF(my_upsampler2));
  155253. cinfo->upsample = (struct jpeg_upsampler *) upsample;
  155254. upsample->pub.start_pass = start_pass_upsample;
  155255. upsample->pub.upsample = sep_upsample;
  155256. upsample->pub.need_context_rows = FALSE; /* until we find out differently */
  155257. if (cinfo->CCIR601_sampling) /* this isn't supported */
  155258. ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);
  155259. do_fancy = cinfo->do_fancy_upsampling && cinfo->min_DCT_scaled_size > 1;
  155260. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  155261. ci++, compptr++) {
  155262. h_in_group = (compptr->h_samp_factor * compptr->DCT_scaled_size) /
  155263. cinfo->min_DCT_scaled_size;
  155264. v_in_group = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  155265. cinfo->min_DCT_scaled_size;
  155266. h_out_group = cinfo->max_h_samp_factor;
  155267. v_out_group = cinfo->max_v_samp_factor;
  155268. upsample->rowgroup_height[ci] = v_in_group; /* save for use later */
  155269. need_buffer = TRUE;
  155270. if (! compptr->component_needed) {
  155271. upsample->methods[ci] = noop_upsample;
  155272. need_buffer = FALSE;
  155273. } else if (h_in_group == h_out_group && v_in_group == v_out_group) {
  155274. upsample->methods[ci] = fullsize_upsample;
  155275. need_buffer = FALSE;
  155276. } else if (h_in_group * 2 == h_out_group &&
  155277. v_in_group == v_out_group) {
  155278. if (do_fancy && compptr->downsampled_width > 2)
  155279. upsample->methods[ci] = h2v1_fancy_upsample;
  155280. else
  155281. upsample->methods[ci] = h2v1_upsample;
  155282. } else if (h_in_group * 2 == h_out_group &&
  155283. v_in_group * 2 == v_out_group) {
  155284. if (do_fancy && compptr->downsampled_width > 2) {
  155285. upsample->methods[ci] = h2v2_fancy_upsample;
  155286. upsample->pub.need_context_rows = TRUE;
  155287. } else
  155288. upsample->methods[ci] = h2v2_upsample;
  155289. } else if ((h_out_group % h_in_group) == 0 &&
  155290. (v_out_group % v_in_group) == 0) {
  155291. upsample->methods[ci] = int_upsample;
  155292. upsample->h_expand[ci] = (UINT8) (h_out_group / h_in_group);
  155293. upsample->v_expand[ci] = (UINT8) (v_out_group / v_in_group);
  155294. } else
  155295. ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
  155296. if (need_buffer) {
  155297. upsample->color_buf[ci] = (*cinfo->mem->alloc_sarray)
  155298. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  155299. (JDIMENSION) jround_up((long) cinfo->output_width,
  155300. (long) cinfo->max_h_samp_factor),
  155301. (JDIMENSION) cinfo->max_v_samp_factor);
  155302. }
  155303. }
  155304. }
  155305. /*** End of inlined file: jdsample.c ***/
  155306. /*** Start of inlined file: jdtrans.c ***/
  155307. #define JPEG_INTERNALS
  155308. LOCAL(void) transdecode_master_selection JPP((j_decompress_ptr cinfo));
  155309. GLOBAL(jvirt_barray_ptr *)
  155310. jpeg_read_coefficients (j_decompress_ptr cinfo)
  155311. {
  155312. if (cinfo->global_state == DSTATE_READY) {
  155313. transdecode_master_selection(cinfo);
  155314. cinfo->global_state = DSTATE_RDCOEFS;
  155315. }
  155316. if (cinfo->global_state == DSTATE_RDCOEFS) {
  155317. for (;;) {
  155318. int retcode;
  155319. if (cinfo->progress != NULL)
  155320. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  155321. retcode = (*cinfo->inputctl->consume_input) (cinfo);
  155322. if (retcode == JPEG_SUSPENDED)
  155323. return NULL;
  155324. if (retcode == JPEG_REACHED_EOI)
  155325. break;
  155326. if (cinfo->progress != NULL &&
  155327. (retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) {
  155328. if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) {
  155329. cinfo->progress->pass_limit += (long) cinfo->total_iMCU_rows;
  155330. }
  155331. }
  155332. }
  155333. cinfo->global_state = DSTATE_STOPPING;
  155334. }
  155335. if ((cinfo->global_state == DSTATE_STOPPING ||
  155336. cinfo->global_state == DSTATE_BUFIMAGE) && cinfo->buffered_image) {
  155337. return cinfo->coef->coef_arrays;
  155338. }
  155339. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  155340. return NULL; /* keep compiler happy */
  155341. }
  155342. LOCAL(void)
  155343. transdecode_master_selection (j_decompress_ptr cinfo)
  155344. {
  155345. cinfo->buffered_image = TRUE;
  155346. if (cinfo->arith_code) {
  155347. ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
  155348. } else {
  155349. if (cinfo->progressive_mode) {
  155350. #ifdef D_PROGRESSIVE_SUPPORTED
  155351. jinit_phuff_decoder(cinfo);
  155352. #else
  155353. ERREXIT(cinfo, JERR_NOT_COMPILED);
  155354. #endif
  155355. } else
  155356. jinit_huff_decoder(cinfo);
  155357. }
  155358. jinit_d_coef_controller(cinfo, TRUE);
  155359. (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
  155360. (*cinfo->inputctl->start_input_pass) (cinfo);
  155361. if (cinfo->progress != NULL) {
  155362. int nscans;
  155363. if (cinfo->progressive_mode) {
  155364. nscans = 2 + 3 * cinfo->num_components;
  155365. } else if (cinfo->inputctl->has_multiple_scans) {
  155366. nscans = cinfo->num_components;
  155367. } else {
  155368. nscans = 1;
  155369. }
  155370. cinfo->progress->pass_counter = 0L;
  155371. cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows * nscans;
  155372. cinfo->progress->completed_passes = 0;
  155373. cinfo->progress->total_passes = 1;
  155374. }
  155375. }
  155376. /*** End of inlined file: jdtrans.c ***/
  155377. /*** Start of inlined file: jfdctflt.c ***/
  155378. #define JPEG_INTERNALS
  155379. #ifdef DCT_FLOAT_SUPPORTED
  155380. #if DCTSIZE != 8
  155381. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155382. #endif
  155383. GLOBAL(void)
  155384. jpeg_fdct_float (FAST_FLOAT * data)
  155385. {
  155386. FAST_FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  155387. FAST_FLOAT tmp10, tmp11, tmp12, tmp13;
  155388. FAST_FLOAT z1, z2, z3, z4, z5, z11, z13;
  155389. FAST_FLOAT *dataptr;
  155390. int ctr;
  155391. dataptr = data;
  155392. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155393. tmp0 = dataptr[0] + dataptr[7];
  155394. tmp7 = dataptr[0] - dataptr[7];
  155395. tmp1 = dataptr[1] + dataptr[6];
  155396. tmp6 = dataptr[1] - dataptr[6];
  155397. tmp2 = dataptr[2] + dataptr[5];
  155398. tmp5 = dataptr[2] - dataptr[5];
  155399. tmp3 = dataptr[3] + dataptr[4];
  155400. tmp4 = dataptr[3] - dataptr[4];
  155401. tmp10 = tmp0 + tmp3; /* phase 2 */
  155402. tmp13 = tmp0 - tmp3;
  155403. tmp11 = tmp1 + tmp2;
  155404. tmp12 = tmp1 - tmp2;
  155405. dataptr[0] = tmp10 + tmp11; /* phase 3 */
  155406. dataptr[4] = tmp10 - tmp11;
  155407. z1 = (tmp12 + tmp13) * ((FAST_FLOAT) 0.707106781); /* c4 */
  155408. dataptr[2] = tmp13 + z1; /* phase 5 */
  155409. dataptr[6] = tmp13 - z1;
  155410. tmp10 = tmp4 + tmp5; /* phase 2 */
  155411. tmp11 = tmp5 + tmp6;
  155412. tmp12 = tmp6 + tmp7;
  155413. z5 = (tmp10 - tmp12) * ((FAST_FLOAT) 0.382683433); /* c6 */
  155414. z2 = ((FAST_FLOAT) 0.541196100) * tmp10 + z5; /* c2-c6 */
  155415. z4 = ((FAST_FLOAT) 1.306562965) * tmp12 + z5; /* c2+c6 */
  155416. z3 = tmp11 * ((FAST_FLOAT) 0.707106781); /* c4 */
  155417. z11 = tmp7 + z3; /* phase 5 */
  155418. z13 = tmp7 - z3;
  155419. dataptr[5] = z13 + z2; /* phase 6 */
  155420. dataptr[3] = z13 - z2;
  155421. dataptr[1] = z11 + z4;
  155422. dataptr[7] = z11 - z4;
  155423. dataptr += DCTSIZE; /* advance pointer to next row */
  155424. }
  155425. dataptr = data;
  155426. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155427. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
  155428. tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
  155429. tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
  155430. tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
  155431. tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
  155432. tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
  155433. tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
  155434. tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
  155435. tmp10 = tmp0 + tmp3; /* phase 2 */
  155436. tmp13 = tmp0 - tmp3;
  155437. tmp11 = tmp1 + tmp2;
  155438. tmp12 = tmp1 - tmp2;
  155439. dataptr[DCTSIZE*0] = tmp10 + tmp11; /* phase 3 */
  155440. dataptr[DCTSIZE*4] = tmp10 - tmp11;
  155441. z1 = (tmp12 + tmp13) * ((FAST_FLOAT) 0.707106781); /* c4 */
  155442. dataptr[DCTSIZE*2] = tmp13 + z1; /* phase 5 */
  155443. dataptr[DCTSIZE*6] = tmp13 - z1;
  155444. tmp10 = tmp4 + tmp5; /* phase 2 */
  155445. tmp11 = tmp5 + tmp6;
  155446. tmp12 = tmp6 + tmp7;
  155447. z5 = (tmp10 - tmp12) * ((FAST_FLOAT) 0.382683433); /* c6 */
  155448. z2 = ((FAST_FLOAT) 0.541196100) * tmp10 + z5; /* c2-c6 */
  155449. z4 = ((FAST_FLOAT) 1.306562965) * tmp12 + z5; /* c2+c6 */
  155450. z3 = tmp11 * ((FAST_FLOAT) 0.707106781); /* c4 */
  155451. z11 = tmp7 + z3; /* phase 5 */
  155452. z13 = tmp7 - z3;
  155453. dataptr[DCTSIZE*5] = z13 + z2; /* phase 6 */
  155454. dataptr[DCTSIZE*3] = z13 - z2;
  155455. dataptr[DCTSIZE*1] = z11 + z4;
  155456. dataptr[DCTSIZE*7] = z11 - z4;
  155457. dataptr++; /* advance pointer to next column */
  155458. }
  155459. }
  155460. #endif /* DCT_FLOAT_SUPPORTED */
  155461. /*** End of inlined file: jfdctflt.c ***/
  155462. /*** Start of inlined file: jfdctint.c ***/
  155463. #define JPEG_INTERNALS
  155464. #ifdef DCT_ISLOW_SUPPORTED
  155465. #if DCTSIZE != 8
  155466. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155467. #endif
  155468. #if BITS_IN_JSAMPLE == 8
  155469. #define CONST_BITS 13
  155470. #define PASS1_BITS 2
  155471. #else
  155472. #define CONST_BITS 13
  155473. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  155474. #endif
  155475. #if CONST_BITS == 13
  155476. #define FIX_0_298631336 ((INT32) 2446) /* FIX(0.298631336) */
  155477. #define FIX_0_390180644 ((INT32) 3196) /* FIX(0.390180644) */
  155478. #define FIX_0_541196100 ((INT32) 4433) /* FIX(0.541196100) */
  155479. #define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */
  155480. #define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */
  155481. #define FIX_1_175875602 ((INT32) 9633) /* FIX(1.175875602) */
  155482. #define FIX_1_501321110 ((INT32) 12299) /* FIX(1.501321110) */
  155483. #define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */
  155484. #define FIX_1_961570560 ((INT32) 16069) /* FIX(1.961570560) */
  155485. #define FIX_2_053119869 ((INT32) 16819) /* FIX(2.053119869) */
  155486. #define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */
  155487. #define FIX_3_072711026 ((INT32) 25172) /* FIX(3.072711026) */
  155488. #else
  155489. #define FIX_0_298631336 FIX(0.298631336)
  155490. #define FIX_0_390180644 FIX(0.390180644)
  155491. #define FIX_0_541196100 FIX(0.541196100)
  155492. #define FIX_0_765366865 FIX(0.765366865)
  155493. #define FIX_0_899976223 FIX(0.899976223)
  155494. #define FIX_1_175875602 FIX(1.175875602)
  155495. #define FIX_1_501321110 FIX(1.501321110)
  155496. #define FIX_1_847759065 FIX(1.847759065)
  155497. #define FIX_1_961570560 FIX(1.961570560)
  155498. #define FIX_2_053119869 FIX(2.053119869)
  155499. #define FIX_2_562915447 FIX(2.562915447)
  155500. #define FIX_3_072711026 FIX(3.072711026)
  155501. #endif
  155502. #if BITS_IN_JSAMPLE == 8
  155503. #define MULTIPLY(var,const) MULTIPLY16C16(var,const)
  155504. #else
  155505. #define MULTIPLY(var,const) ((var) * (const))
  155506. #endif
  155507. GLOBAL(void)
  155508. jpeg_fdct_islow (DCTELEM * data)
  155509. {
  155510. INT32 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  155511. INT32 tmp10, tmp11, tmp12, tmp13;
  155512. INT32 z1, z2, z3, z4, z5;
  155513. DCTELEM *dataptr;
  155514. int ctr;
  155515. SHIFT_TEMPS
  155516. dataptr = data;
  155517. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155518. tmp0 = dataptr[0] + dataptr[7];
  155519. tmp7 = dataptr[0] - dataptr[7];
  155520. tmp1 = dataptr[1] + dataptr[6];
  155521. tmp6 = dataptr[1] - dataptr[6];
  155522. tmp2 = dataptr[2] + dataptr[5];
  155523. tmp5 = dataptr[2] - dataptr[5];
  155524. tmp3 = dataptr[3] + dataptr[4];
  155525. tmp4 = dataptr[3] - dataptr[4];
  155526. tmp10 = tmp0 + tmp3;
  155527. tmp13 = tmp0 - tmp3;
  155528. tmp11 = tmp1 + tmp2;
  155529. tmp12 = tmp1 - tmp2;
  155530. dataptr[0] = (DCTELEM) ((tmp10 + tmp11) << PASS1_BITS);
  155531. dataptr[4] = (DCTELEM) ((tmp10 - tmp11) << PASS1_BITS);
  155532. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100);
  155533. dataptr[2] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865),
  155534. CONST_BITS-PASS1_BITS);
  155535. dataptr[6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065),
  155536. CONST_BITS-PASS1_BITS);
  155537. z1 = tmp4 + tmp7;
  155538. z2 = tmp5 + tmp6;
  155539. z3 = tmp4 + tmp6;
  155540. z4 = tmp5 + tmp7;
  155541. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  155542. tmp4 = MULTIPLY(tmp4, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  155543. tmp5 = MULTIPLY(tmp5, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  155544. tmp6 = MULTIPLY(tmp6, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  155545. tmp7 = MULTIPLY(tmp7, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  155546. z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  155547. z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  155548. z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  155549. z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  155550. z3 += z5;
  155551. z4 += z5;
  155552. dataptr[7] = (DCTELEM) DESCALE(tmp4 + z1 + z3, CONST_BITS-PASS1_BITS);
  155553. dataptr[5] = (DCTELEM) DESCALE(tmp5 + z2 + z4, CONST_BITS-PASS1_BITS);
  155554. dataptr[3] = (DCTELEM) DESCALE(tmp6 + z2 + z3, CONST_BITS-PASS1_BITS);
  155555. dataptr[1] = (DCTELEM) DESCALE(tmp7 + z1 + z4, CONST_BITS-PASS1_BITS);
  155556. dataptr += DCTSIZE; /* advance pointer to next row */
  155557. }
  155558. dataptr = data;
  155559. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155560. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
  155561. tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
  155562. tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
  155563. tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
  155564. tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
  155565. tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
  155566. tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
  155567. tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
  155568. tmp10 = tmp0 + tmp3;
  155569. tmp13 = tmp0 - tmp3;
  155570. tmp11 = tmp1 + tmp2;
  155571. tmp12 = tmp1 - tmp2;
  155572. dataptr[DCTSIZE*0] = (DCTELEM) DESCALE(tmp10 + tmp11, PASS1_BITS);
  155573. dataptr[DCTSIZE*4] = (DCTELEM) DESCALE(tmp10 - tmp11, PASS1_BITS);
  155574. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100);
  155575. dataptr[DCTSIZE*2] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865),
  155576. CONST_BITS+PASS1_BITS);
  155577. dataptr[DCTSIZE*6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065),
  155578. CONST_BITS+PASS1_BITS);
  155579. z1 = tmp4 + tmp7;
  155580. z2 = tmp5 + tmp6;
  155581. z3 = tmp4 + tmp6;
  155582. z4 = tmp5 + tmp7;
  155583. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  155584. tmp4 = MULTIPLY(tmp4, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  155585. tmp5 = MULTIPLY(tmp5, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  155586. tmp6 = MULTIPLY(tmp6, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  155587. tmp7 = MULTIPLY(tmp7, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  155588. z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  155589. z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  155590. z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  155591. z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  155592. z3 += z5;
  155593. z4 += z5;
  155594. dataptr[DCTSIZE*7] = (DCTELEM) DESCALE(tmp4 + z1 + z3,
  155595. CONST_BITS+PASS1_BITS);
  155596. dataptr[DCTSIZE*5] = (DCTELEM) DESCALE(tmp5 + z2 + z4,
  155597. CONST_BITS+PASS1_BITS);
  155598. dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(tmp6 + z2 + z3,
  155599. CONST_BITS+PASS1_BITS);
  155600. dataptr[DCTSIZE*1] = (DCTELEM) DESCALE(tmp7 + z1 + z4,
  155601. CONST_BITS+PASS1_BITS);
  155602. dataptr++; /* advance pointer to next column */
  155603. }
  155604. }
  155605. #endif /* DCT_ISLOW_SUPPORTED */
  155606. /*** End of inlined file: jfdctint.c ***/
  155607. #undef CONST_BITS
  155608. #undef MULTIPLY
  155609. #undef FIX_0_541196100
  155610. /*** Start of inlined file: jfdctfst.c ***/
  155611. #define JPEG_INTERNALS
  155612. #ifdef DCT_IFAST_SUPPORTED
  155613. #if DCTSIZE != 8
  155614. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155615. #endif
  155616. #define CONST_BITS 8
  155617. #if CONST_BITS == 8
  155618. #define FIX_0_382683433 ((INT32) 98) /* FIX(0.382683433) */
  155619. #define FIX_0_541196100 ((INT32) 139) /* FIX(0.541196100) */
  155620. #define FIX_0_707106781 ((INT32) 181) /* FIX(0.707106781) */
  155621. #define FIX_1_306562965 ((INT32) 334) /* FIX(1.306562965) */
  155622. #else
  155623. #define FIX_0_382683433 FIX(0.382683433)
  155624. #define FIX_0_541196100 FIX(0.541196100)
  155625. #define FIX_0_707106781 FIX(0.707106781)
  155626. #define FIX_1_306562965 FIX(1.306562965)
  155627. #endif
  155628. #ifndef USE_ACCURATE_ROUNDING
  155629. #undef DESCALE
  155630. #define DESCALE(x,n) RIGHT_SHIFT(x, n)
  155631. #endif
  155632. #define MULTIPLY(var,const) ((DCTELEM) DESCALE((var) * (const), CONST_BITS))
  155633. GLOBAL(void)
  155634. jpeg_fdct_ifast (DCTELEM * data)
  155635. {
  155636. DCTELEM tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  155637. DCTELEM tmp10, tmp11, tmp12, tmp13;
  155638. DCTELEM z1, z2, z3, z4, z5, z11, z13;
  155639. DCTELEM *dataptr;
  155640. int ctr;
  155641. SHIFT_TEMPS
  155642. dataptr = data;
  155643. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155644. tmp0 = dataptr[0] + dataptr[7];
  155645. tmp7 = dataptr[0] - dataptr[7];
  155646. tmp1 = dataptr[1] + dataptr[6];
  155647. tmp6 = dataptr[1] - dataptr[6];
  155648. tmp2 = dataptr[2] + dataptr[5];
  155649. tmp5 = dataptr[2] - dataptr[5];
  155650. tmp3 = dataptr[3] + dataptr[4];
  155651. tmp4 = dataptr[3] - dataptr[4];
  155652. tmp10 = tmp0 + tmp3; /* phase 2 */
  155653. tmp13 = tmp0 - tmp3;
  155654. tmp11 = tmp1 + tmp2;
  155655. tmp12 = tmp1 - tmp2;
  155656. dataptr[0] = tmp10 + tmp11; /* phase 3 */
  155657. dataptr[4] = tmp10 - tmp11;
  155658. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_707106781); /* c4 */
  155659. dataptr[2] = tmp13 + z1; /* phase 5 */
  155660. dataptr[6] = tmp13 - z1;
  155661. tmp10 = tmp4 + tmp5; /* phase 2 */
  155662. tmp11 = tmp5 + tmp6;
  155663. tmp12 = tmp6 + tmp7;
  155664. z5 = MULTIPLY(tmp10 - tmp12, FIX_0_382683433); /* c6 */
  155665. z2 = MULTIPLY(tmp10, FIX_0_541196100) + z5; /* c2-c6 */
  155666. z4 = MULTIPLY(tmp12, FIX_1_306562965) + z5; /* c2+c6 */
  155667. z3 = MULTIPLY(tmp11, FIX_0_707106781); /* c4 */
  155668. z11 = tmp7 + z3; /* phase 5 */
  155669. z13 = tmp7 - z3;
  155670. dataptr[5] = z13 + z2; /* phase 6 */
  155671. dataptr[3] = z13 - z2;
  155672. dataptr[1] = z11 + z4;
  155673. dataptr[7] = z11 - z4;
  155674. dataptr += DCTSIZE; /* advance pointer to next row */
  155675. }
  155676. dataptr = data;
  155677. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155678. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
  155679. tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
  155680. tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
  155681. tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
  155682. tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
  155683. tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
  155684. tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
  155685. tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
  155686. tmp10 = tmp0 + tmp3; /* phase 2 */
  155687. tmp13 = tmp0 - tmp3;
  155688. tmp11 = tmp1 + tmp2;
  155689. tmp12 = tmp1 - tmp2;
  155690. dataptr[DCTSIZE*0] = tmp10 + tmp11; /* phase 3 */
  155691. dataptr[DCTSIZE*4] = tmp10 - tmp11;
  155692. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_707106781); /* c4 */
  155693. dataptr[DCTSIZE*2] = tmp13 + z1; /* phase 5 */
  155694. dataptr[DCTSIZE*6] = tmp13 - z1;
  155695. tmp10 = tmp4 + tmp5; /* phase 2 */
  155696. tmp11 = tmp5 + tmp6;
  155697. tmp12 = tmp6 + tmp7;
  155698. z5 = MULTIPLY(tmp10 - tmp12, FIX_0_382683433); /* c6 */
  155699. z2 = MULTIPLY(tmp10, FIX_0_541196100) + z5; /* c2-c6 */
  155700. z4 = MULTIPLY(tmp12, FIX_1_306562965) + z5; /* c2+c6 */
  155701. z3 = MULTIPLY(tmp11, FIX_0_707106781); /* c4 */
  155702. z11 = tmp7 + z3; /* phase 5 */
  155703. z13 = tmp7 - z3;
  155704. dataptr[DCTSIZE*5] = z13 + z2; /* phase 6 */
  155705. dataptr[DCTSIZE*3] = z13 - z2;
  155706. dataptr[DCTSIZE*1] = z11 + z4;
  155707. dataptr[DCTSIZE*7] = z11 - z4;
  155708. dataptr++; /* advance pointer to next column */
  155709. }
  155710. }
  155711. #endif /* DCT_IFAST_SUPPORTED */
  155712. /*** End of inlined file: jfdctfst.c ***/
  155713. #undef FIX_0_541196100
  155714. /*** Start of inlined file: jidctflt.c ***/
  155715. #define JPEG_INTERNALS
  155716. #ifdef DCT_FLOAT_SUPPORTED
  155717. #if DCTSIZE != 8
  155718. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155719. #endif
  155720. #define DEQUANTIZE(coef,quantval) (((FAST_FLOAT) (coef)) * (quantval))
  155721. GLOBAL(void)
  155722. jpeg_idct_float (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155723. JCOEFPTR coef_block,
  155724. JSAMPARRAY output_buf, JDIMENSION output_col)
  155725. {
  155726. FAST_FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  155727. FAST_FLOAT tmp10, tmp11, tmp12, tmp13;
  155728. FAST_FLOAT z5, z10, z11, z12, z13;
  155729. JCOEFPTR inptr;
  155730. FLOAT_MULT_TYPE * quantptr;
  155731. FAST_FLOAT * wsptr;
  155732. JSAMPROW outptr;
  155733. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  155734. int ctr;
  155735. FAST_FLOAT workspace[DCTSIZE2]; /* buffers data between passes */
  155736. SHIFT_TEMPS
  155737. inptr = coef_block;
  155738. quantptr = (FLOAT_MULT_TYPE *) compptr->dct_table;
  155739. wsptr = workspace;
  155740. for (ctr = DCTSIZE; ctr > 0; ctr--) {
  155741. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
  155742. inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&
  155743. inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&
  155744. inptr[DCTSIZE*7] == 0) {
  155745. FAST_FLOAT dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155746. wsptr[DCTSIZE*0] = dcval;
  155747. wsptr[DCTSIZE*1] = dcval;
  155748. wsptr[DCTSIZE*2] = dcval;
  155749. wsptr[DCTSIZE*3] = dcval;
  155750. wsptr[DCTSIZE*4] = dcval;
  155751. wsptr[DCTSIZE*5] = dcval;
  155752. wsptr[DCTSIZE*6] = dcval;
  155753. wsptr[DCTSIZE*7] = dcval;
  155754. inptr++; /* advance pointers to next column */
  155755. quantptr++;
  155756. wsptr++;
  155757. continue;
  155758. }
  155759. tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155760. tmp1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  155761. tmp2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
  155762. tmp3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  155763. tmp10 = tmp0 + tmp2; /* phase 3 */
  155764. tmp11 = tmp0 - tmp2;
  155765. tmp13 = tmp1 + tmp3; /* phases 5-3 */
  155766. tmp12 = (tmp1 - tmp3) * ((FAST_FLOAT) 1.414213562) - tmp13; /* 2*c4 */
  155767. tmp0 = tmp10 + tmp13; /* phase 2 */
  155768. tmp3 = tmp10 - tmp13;
  155769. tmp1 = tmp11 + tmp12;
  155770. tmp2 = tmp11 - tmp12;
  155771. tmp4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  155772. tmp5 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  155773. tmp6 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  155774. tmp7 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  155775. z13 = tmp6 + tmp5; /* phase 6 */
  155776. z10 = tmp6 - tmp5;
  155777. z11 = tmp4 + tmp7;
  155778. z12 = tmp4 - tmp7;
  155779. tmp7 = z11 + z13; /* phase 5 */
  155780. tmp11 = (z11 - z13) * ((FAST_FLOAT) 1.414213562); /* 2*c4 */
  155781. z5 = (z10 + z12) * ((FAST_FLOAT) 1.847759065); /* 2*c2 */
  155782. tmp10 = ((FAST_FLOAT) 1.082392200) * z12 - z5; /* 2*(c2-c6) */
  155783. tmp12 = ((FAST_FLOAT) -2.613125930) * z10 + z5; /* -2*(c2+c6) */
  155784. tmp6 = tmp12 - tmp7; /* phase 2 */
  155785. tmp5 = tmp11 - tmp6;
  155786. tmp4 = tmp10 + tmp5;
  155787. wsptr[DCTSIZE*0] = tmp0 + tmp7;
  155788. wsptr[DCTSIZE*7] = tmp0 - tmp7;
  155789. wsptr[DCTSIZE*1] = tmp1 + tmp6;
  155790. wsptr[DCTSIZE*6] = tmp1 - tmp6;
  155791. wsptr[DCTSIZE*2] = tmp2 + tmp5;
  155792. wsptr[DCTSIZE*5] = tmp2 - tmp5;
  155793. wsptr[DCTSIZE*4] = tmp3 + tmp4;
  155794. wsptr[DCTSIZE*3] = tmp3 - tmp4;
  155795. inptr++; /* advance pointers to next column */
  155796. quantptr++;
  155797. wsptr++;
  155798. }
  155799. wsptr = workspace;
  155800. for (ctr = 0; ctr < DCTSIZE; ctr++) {
  155801. outptr = output_buf[ctr] + output_col;
  155802. tmp10 = wsptr[0] + wsptr[4];
  155803. tmp11 = wsptr[0] - wsptr[4];
  155804. tmp13 = wsptr[2] + wsptr[6];
  155805. tmp12 = (wsptr[2] - wsptr[6]) * ((FAST_FLOAT) 1.414213562) - tmp13;
  155806. tmp0 = tmp10 + tmp13;
  155807. tmp3 = tmp10 - tmp13;
  155808. tmp1 = tmp11 + tmp12;
  155809. tmp2 = tmp11 - tmp12;
  155810. z13 = wsptr[5] + wsptr[3];
  155811. z10 = wsptr[5] - wsptr[3];
  155812. z11 = wsptr[1] + wsptr[7];
  155813. z12 = wsptr[1] - wsptr[7];
  155814. tmp7 = z11 + z13;
  155815. tmp11 = (z11 - z13) * ((FAST_FLOAT) 1.414213562);
  155816. z5 = (z10 + z12) * ((FAST_FLOAT) 1.847759065); /* 2*c2 */
  155817. tmp10 = ((FAST_FLOAT) 1.082392200) * z12 - z5; /* 2*(c2-c6) */
  155818. tmp12 = ((FAST_FLOAT) -2.613125930) * z10 + z5; /* -2*(c2+c6) */
  155819. tmp6 = tmp12 - tmp7;
  155820. tmp5 = tmp11 - tmp6;
  155821. tmp4 = tmp10 + tmp5;
  155822. outptr[0] = range_limit[(int) DESCALE((INT32) (tmp0 + tmp7), 3)
  155823. & RANGE_MASK];
  155824. outptr[7] = range_limit[(int) DESCALE((INT32) (tmp0 - tmp7), 3)
  155825. & RANGE_MASK];
  155826. outptr[1] = range_limit[(int) DESCALE((INT32) (tmp1 + tmp6), 3)
  155827. & RANGE_MASK];
  155828. outptr[6] = range_limit[(int) DESCALE((INT32) (tmp1 - tmp6), 3)
  155829. & RANGE_MASK];
  155830. outptr[2] = range_limit[(int) DESCALE((INT32) (tmp2 + tmp5), 3)
  155831. & RANGE_MASK];
  155832. outptr[5] = range_limit[(int) DESCALE((INT32) (tmp2 - tmp5), 3)
  155833. & RANGE_MASK];
  155834. outptr[4] = range_limit[(int) DESCALE((INT32) (tmp3 + tmp4), 3)
  155835. & RANGE_MASK];
  155836. outptr[3] = range_limit[(int) DESCALE((INT32) (tmp3 - tmp4), 3)
  155837. & RANGE_MASK];
  155838. wsptr += DCTSIZE; /* advance pointer to next row */
  155839. }
  155840. }
  155841. #endif /* DCT_FLOAT_SUPPORTED */
  155842. /*** End of inlined file: jidctflt.c ***/
  155843. #undef CONST_BITS
  155844. #undef FIX_1_847759065
  155845. #undef MULTIPLY
  155846. #undef DEQUANTIZE
  155847. #undef DESCALE
  155848. /*** Start of inlined file: jidctfst.c ***/
  155849. #define JPEG_INTERNALS
  155850. #ifdef DCT_IFAST_SUPPORTED
  155851. #if DCTSIZE != 8
  155852. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155853. #endif
  155854. #if BITS_IN_JSAMPLE == 8
  155855. #define CONST_BITS 8
  155856. #define PASS1_BITS 2
  155857. #else
  155858. #define CONST_BITS 8
  155859. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  155860. #endif
  155861. #if CONST_BITS == 8
  155862. #define FIX_1_082392200 ((INT32) 277) /* FIX(1.082392200) */
  155863. #define FIX_1_414213562 ((INT32) 362) /* FIX(1.414213562) */
  155864. #define FIX_1_847759065 ((INT32) 473) /* FIX(1.847759065) */
  155865. #define FIX_2_613125930 ((INT32) 669) /* FIX(2.613125930) */
  155866. #else
  155867. #define FIX_1_082392200 FIX(1.082392200)
  155868. #define FIX_1_414213562 FIX(1.414213562)
  155869. #define FIX_1_847759065 FIX(1.847759065)
  155870. #define FIX_2_613125930 FIX(2.613125930)
  155871. #endif
  155872. #ifndef USE_ACCURATE_ROUNDING
  155873. #undef DESCALE
  155874. #define DESCALE(x,n) RIGHT_SHIFT(x, n)
  155875. #endif
  155876. #define MULTIPLY(var,const) ((DCTELEM) DESCALE((var) * (const), CONST_BITS))
  155877. #if BITS_IN_JSAMPLE == 8
  155878. #define DEQUANTIZE(coef,quantval) (((IFAST_MULT_TYPE) (coef)) * (quantval))
  155879. #else
  155880. #define DEQUANTIZE(coef,quantval) \
  155881. DESCALE((coef)*(quantval), IFAST_SCALE_BITS-PASS1_BITS)
  155882. #endif
  155883. #ifdef RIGHT_SHIFT_IS_UNSIGNED
  155884. #define ISHIFT_TEMPS DCTELEM ishift_temp;
  155885. #if BITS_IN_JSAMPLE == 8
  155886. #define DCTELEMBITS 16 /* DCTELEM may be 16 or 32 bits */
  155887. #else
  155888. #define DCTELEMBITS 32 /* DCTELEM must be 32 bits */
  155889. #endif
  155890. #define IRIGHT_SHIFT(x,shft) \
  155891. ((ishift_temp = (x)) < 0 ? \
  155892. (ishift_temp >> (shft)) | ((~((DCTELEM) 0)) << (DCTELEMBITS-(shft))) : \
  155893. (ishift_temp >> (shft)))
  155894. #else
  155895. #define ISHIFT_TEMPS
  155896. #define IRIGHT_SHIFT(x,shft) ((x) >> (shft))
  155897. #endif
  155898. #ifdef USE_ACCURATE_ROUNDING
  155899. #define IDESCALE(x,n) ((int) IRIGHT_SHIFT((x) + (1 << ((n)-1)), n))
  155900. #else
  155901. #define IDESCALE(x,n) ((int) IRIGHT_SHIFT(x, n))
  155902. #endif
  155903. GLOBAL(void)
  155904. jpeg_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155905. JCOEFPTR coef_block,
  155906. JSAMPARRAY output_buf, JDIMENSION output_col)
  155907. {
  155908. DCTELEM tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  155909. DCTELEM tmp10, tmp11, tmp12, tmp13;
  155910. DCTELEM z5, z10, z11, z12, z13;
  155911. JCOEFPTR inptr;
  155912. IFAST_MULT_TYPE * quantptr;
  155913. int * wsptr;
  155914. JSAMPROW outptr;
  155915. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  155916. int ctr;
  155917. int workspace[DCTSIZE2]; /* buffers data between passes */
  155918. SHIFT_TEMPS /* for DESCALE */
  155919. ISHIFT_TEMPS /* for IDESCALE */
  155920. inptr = coef_block;
  155921. quantptr = (IFAST_MULT_TYPE *) compptr->dct_table;
  155922. wsptr = workspace;
  155923. for (ctr = DCTSIZE; ctr > 0; ctr--) {
  155924. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
  155925. inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&
  155926. inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&
  155927. inptr[DCTSIZE*7] == 0) {
  155928. int dcval = (int) DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155929. wsptr[DCTSIZE*0] = dcval;
  155930. wsptr[DCTSIZE*1] = dcval;
  155931. wsptr[DCTSIZE*2] = dcval;
  155932. wsptr[DCTSIZE*3] = dcval;
  155933. wsptr[DCTSIZE*4] = dcval;
  155934. wsptr[DCTSIZE*5] = dcval;
  155935. wsptr[DCTSIZE*6] = dcval;
  155936. wsptr[DCTSIZE*7] = dcval;
  155937. inptr++; /* advance pointers to next column */
  155938. quantptr++;
  155939. wsptr++;
  155940. continue;
  155941. }
  155942. tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155943. tmp1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  155944. tmp2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
  155945. tmp3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  155946. tmp10 = tmp0 + tmp2; /* phase 3 */
  155947. tmp11 = tmp0 - tmp2;
  155948. tmp13 = tmp1 + tmp3; /* phases 5-3 */
  155949. tmp12 = MULTIPLY(tmp1 - tmp3, FIX_1_414213562) - tmp13; /* 2*c4 */
  155950. tmp0 = tmp10 + tmp13; /* phase 2 */
  155951. tmp3 = tmp10 - tmp13;
  155952. tmp1 = tmp11 + tmp12;
  155953. tmp2 = tmp11 - tmp12;
  155954. tmp4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  155955. tmp5 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  155956. tmp6 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  155957. tmp7 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  155958. z13 = tmp6 + tmp5; /* phase 6 */
  155959. z10 = tmp6 - tmp5;
  155960. z11 = tmp4 + tmp7;
  155961. z12 = tmp4 - tmp7;
  155962. tmp7 = z11 + z13; /* phase 5 */
  155963. tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562); /* 2*c4 */
  155964. z5 = MULTIPLY(z10 + z12, FIX_1_847759065); /* 2*c2 */
  155965. tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5; /* 2*(c2-c6) */
  155966. tmp12 = MULTIPLY(z10, - FIX_2_613125930) + z5; /* -2*(c2+c6) */
  155967. tmp6 = tmp12 - tmp7; /* phase 2 */
  155968. tmp5 = tmp11 - tmp6;
  155969. tmp4 = tmp10 + tmp5;
  155970. wsptr[DCTSIZE*0] = (int) (tmp0 + tmp7);
  155971. wsptr[DCTSIZE*7] = (int) (tmp0 - tmp7);
  155972. wsptr[DCTSIZE*1] = (int) (tmp1 + tmp6);
  155973. wsptr[DCTSIZE*6] = (int) (tmp1 - tmp6);
  155974. wsptr[DCTSIZE*2] = (int) (tmp2 + tmp5);
  155975. wsptr[DCTSIZE*5] = (int) (tmp2 - tmp5);
  155976. wsptr[DCTSIZE*4] = (int) (tmp3 + tmp4);
  155977. wsptr[DCTSIZE*3] = (int) (tmp3 - tmp4);
  155978. inptr++; /* advance pointers to next column */
  155979. quantptr++;
  155980. wsptr++;
  155981. }
  155982. wsptr = workspace;
  155983. for (ctr = 0; ctr < DCTSIZE; ctr++) {
  155984. outptr = output_buf[ctr] + output_col;
  155985. #ifndef NO_ZERO_ROW_TEST
  155986. if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 && wsptr[4] == 0 &&
  155987. wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
  155988. JSAMPLE dcval = range_limit[IDESCALE(wsptr[0], PASS1_BITS+3)
  155989. & RANGE_MASK];
  155990. outptr[0] = dcval;
  155991. outptr[1] = dcval;
  155992. outptr[2] = dcval;
  155993. outptr[3] = dcval;
  155994. outptr[4] = dcval;
  155995. outptr[5] = dcval;
  155996. outptr[6] = dcval;
  155997. outptr[7] = dcval;
  155998. wsptr += DCTSIZE; /* advance pointer to next row */
  155999. continue;
  156000. }
  156001. #endif
  156002. tmp10 = ((DCTELEM) wsptr[0] + (DCTELEM) wsptr[4]);
  156003. tmp11 = ((DCTELEM) wsptr[0] - (DCTELEM) wsptr[4]);
  156004. tmp13 = ((DCTELEM) wsptr[2] + (DCTELEM) wsptr[6]);
  156005. tmp12 = MULTIPLY((DCTELEM) wsptr[2] - (DCTELEM) wsptr[6], FIX_1_414213562)
  156006. - tmp13;
  156007. tmp0 = tmp10 + tmp13;
  156008. tmp3 = tmp10 - tmp13;
  156009. tmp1 = tmp11 + tmp12;
  156010. tmp2 = tmp11 - tmp12;
  156011. z13 = (DCTELEM) wsptr[5] + (DCTELEM) wsptr[3];
  156012. z10 = (DCTELEM) wsptr[5] - (DCTELEM) wsptr[3];
  156013. z11 = (DCTELEM) wsptr[1] + (DCTELEM) wsptr[7];
  156014. z12 = (DCTELEM) wsptr[1] - (DCTELEM) wsptr[7];
  156015. tmp7 = z11 + z13; /* phase 5 */
  156016. tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562); /* 2*c4 */
  156017. z5 = MULTIPLY(z10 + z12, FIX_1_847759065); /* 2*c2 */
  156018. tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5; /* 2*(c2-c6) */
  156019. tmp12 = MULTIPLY(z10, - FIX_2_613125930) + z5; /* -2*(c2+c6) */
  156020. tmp6 = tmp12 - tmp7; /* phase 2 */
  156021. tmp5 = tmp11 - tmp6;
  156022. tmp4 = tmp10 + tmp5;
  156023. outptr[0] = range_limit[IDESCALE(tmp0 + tmp7, PASS1_BITS+3)
  156024. & RANGE_MASK];
  156025. outptr[7] = range_limit[IDESCALE(tmp0 - tmp7, PASS1_BITS+3)
  156026. & RANGE_MASK];
  156027. outptr[1] = range_limit[IDESCALE(tmp1 + tmp6, PASS1_BITS+3)
  156028. & RANGE_MASK];
  156029. outptr[6] = range_limit[IDESCALE(tmp1 - tmp6, PASS1_BITS+3)
  156030. & RANGE_MASK];
  156031. outptr[2] = range_limit[IDESCALE(tmp2 + tmp5, PASS1_BITS+3)
  156032. & RANGE_MASK];
  156033. outptr[5] = range_limit[IDESCALE(tmp2 - tmp5, PASS1_BITS+3)
  156034. & RANGE_MASK];
  156035. outptr[4] = range_limit[IDESCALE(tmp3 + tmp4, PASS1_BITS+3)
  156036. & RANGE_MASK];
  156037. outptr[3] = range_limit[IDESCALE(tmp3 - tmp4, PASS1_BITS+3)
  156038. & RANGE_MASK];
  156039. wsptr += DCTSIZE; /* advance pointer to next row */
  156040. }
  156041. }
  156042. #endif /* DCT_IFAST_SUPPORTED */
  156043. /*** End of inlined file: jidctfst.c ***/
  156044. #undef CONST_BITS
  156045. #undef FIX_1_847759065
  156046. #undef MULTIPLY
  156047. #undef DEQUANTIZE
  156048. /*** Start of inlined file: jidctint.c ***/
  156049. #define JPEG_INTERNALS
  156050. #ifdef DCT_ISLOW_SUPPORTED
  156051. #if DCTSIZE != 8
  156052. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  156053. #endif
  156054. #if BITS_IN_JSAMPLE == 8
  156055. #define CONST_BITS 13
  156056. #define PASS1_BITS 2
  156057. #else
  156058. #define CONST_BITS 13
  156059. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  156060. #endif
  156061. #if CONST_BITS == 13
  156062. #define FIX_0_298631336 ((INT32) 2446) /* FIX(0.298631336) */
  156063. #define FIX_0_390180644 ((INT32) 3196) /* FIX(0.390180644) */
  156064. #define FIX_0_541196100 ((INT32) 4433) /* FIX(0.541196100) */
  156065. #define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */
  156066. #define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */
  156067. #define FIX_1_175875602 ((INT32) 9633) /* FIX(1.175875602) */
  156068. #define FIX_1_501321110 ((INT32) 12299) /* FIX(1.501321110) */
  156069. #define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */
  156070. #define FIX_1_961570560 ((INT32) 16069) /* FIX(1.961570560) */
  156071. #define FIX_2_053119869 ((INT32) 16819) /* FIX(2.053119869) */
  156072. #define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */
  156073. #define FIX_3_072711026 ((INT32) 25172) /* FIX(3.072711026) */
  156074. #else
  156075. #define FIX_0_298631336 FIX(0.298631336)
  156076. #define FIX_0_390180644 FIX(0.390180644)
  156077. #define FIX_0_541196100 FIX(0.541196100)
  156078. #define FIX_0_765366865 FIX(0.765366865)
  156079. #define FIX_0_899976223 FIX(0.899976223)
  156080. #define FIX_1_175875602 FIX(1.175875602)
  156081. #define FIX_1_501321110 FIX(1.501321110)
  156082. #define FIX_1_847759065 FIX(1.847759065)
  156083. #define FIX_1_961570560 FIX(1.961570560)
  156084. #define FIX_2_053119869 FIX(2.053119869)
  156085. #define FIX_2_562915447 FIX(2.562915447)
  156086. #define FIX_3_072711026 FIX(3.072711026)
  156087. #endif
  156088. #if BITS_IN_JSAMPLE == 8
  156089. #define MULTIPLY(var,const) MULTIPLY16C16(var,const)
  156090. #else
  156091. #define MULTIPLY(var,const) ((var) * (const))
  156092. #endif
  156093. #define DEQUANTIZE(coef,quantval) (((ISLOW_MULT_TYPE) (coef)) * (quantval))
  156094. GLOBAL(void)
  156095. jpeg_idct_islow (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  156096. JCOEFPTR coef_block,
  156097. JSAMPARRAY output_buf, JDIMENSION output_col)
  156098. {
  156099. INT32 tmp0, tmp1, tmp2, tmp3;
  156100. INT32 tmp10, tmp11, tmp12, tmp13;
  156101. INT32 z1, z2, z3, z4, z5;
  156102. JCOEFPTR inptr;
  156103. ISLOW_MULT_TYPE * quantptr;
  156104. int * wsptr;
  156105. JSAMPROW outptr;
  156106. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  156107. int ctr;
  156108. int workspace[DCTSIZE2]; /* buffers data between passes */
  156109. SHIFT_TEMPS
  156110. inptr = coef_block;
  156111. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  156112. wsptr = workspace;
  156113. for (ctr = DCTSIZE; ctr > 0; ctr--) {
  156114. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
  156115. inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&
  156116. inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&
  156117. inptr[DCTSIZE*7] == 0) {
  156118. int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
  156119. wsptr[DCTSIZE*0] = dcval;
  156120. wsptr[DCTSIZE*1] = dcval;
  156121. wsptr[DCTSIZE*2] = dcval;
  156122. wsptr[DCTSIZE*3] = dcval;
  156123. wsptr[DCTSIZE*4] = dcval;
  156124. wsptr[DCTSIZE*5] = dcval;
  156125. wsptr[DCTSIZE*6] = dcval;
  156126. wsptr[DCTSIZE*7] = dcval;
  156127. inptr++; /* advance pointers to next column */
  156128. quantptr++;
  156129. wsptr++;
  156130. continue;
  156131. }
  156132. z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  156133. z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  156134. z1 = MULTIPLY(z2 + z3, FIX_0_541196100);
  156135. tmp2 = z1 + MULTIPLY(z3, - FIX_1_847759065);
  156136. tmp3 = z1 + MULTIPLY(z2, FIX_0_765366865);
  156137. z2 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  156138. z3 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
  156139. tmp0 = (z2 + z3) << CONST_BITS;
  156140. tmp1 = (z2 - z3) << CONST_BITS;
  156141. tmp10 = tmp0 + tmp3;
  156142. tmp13 = tmp0 - tmp3;
  156143. tmp11 = tmp1 + tmp2;
  156144. tmp12 = tmp1 - tmp2;
  156145. tmp0 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  156146. tmp1 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  156147. tmp2 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  156148. tmp3 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  156149. z1 = tmp0 + tmp3;
  156150. z2 = tmp1 + tmp2;
  156151. z3 = tmp0 + tmp2;
  156152. z4 = tmp1 + tmp3;
  156153. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  156154. tmp0 = MULTIPLY(tmp0, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  156155. tmp1 = MULTIPLY(tmp1, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  156156. tmp2 = MULTIPLY(tmp2, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  156157. tmp3 = MULTIPLY(tmp3, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  156158. z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  156159. z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  156160. z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  156161. z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  156162. z3 += z5;
  156163. z4 += z5;
  156164. tmp0 += z1 + z3;
  156165. tmp1 += z2 + z4;
  156166. tmp2 += z2 + z3;
  156167. tmp3 += z1 + z4;
  156168. wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp3, CONST_BITS-PASS1_BITS);
  156169. wsptr[DCTSIZE*7] = (int) DESCALE(tmp10 - tmp3, CONST_BITS-PASS1_BITS);
  156170. wsptr[DCTSIZE*1] = (int) DESCALE(tmp11 + tmp2, CONST_BITS-PASS1_BITS);
  156171. wsptr[DCTSIZE*6] = (int) DESCALE(tmp11 - tmp2, CONST_BITS-PASS1_BITS);
  156172. wsptr[DCTSIZE*2] = (int) DESCALE(tmp12 + tmp1, CONST_BITS-PASS1_BITS);
  156173. wsptr[DCTSIZE*5] = (int) DESCALE(tmp12 - tmp1, CONST_BITS-PASS1_BITS);
  156174. wsptr[DCTSIZE*3] = (int) DESCALE(tmp13 + tmp0, CONST_BITS-PASS1_BITS);
  156175. wsptr[DCTSIZE*4] = (int) DESCALE(tmp13 - tmp0, CONST_BITS-PASS1_BITS);
  156176. inptr++; /* advance pointers to next column */
  156177. quantptr++;
  156178. wsptr++;
  156179. }
  156180. wsptr = workspace;
  156181. for (ctr = 0; ctr < DCTSIZE; ctr++) {
  156182. outptr = output_buf[ctr] + output_col;
  156183. #ifndef NO_ZERO_ROW_TEST
  156184. if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 && wsptr[4] == 0 &&
  156185. wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
  156186. JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3)
  156187. & RANGE_MASK];
  156188. outptr[0] = dcval;
  156189. outptr[1] = dcval;
  156190. outptr[2] = dcval;
  156191. outptr[3] = dcval;
  156192. outptr[4] = dcval;
  156193. outptr[5] = dcval;
  156194. outptr[6] = dcval;
  156195. outptr[7] = dcval;
  156196. wsptr += DCTSIZE; /* advance pointer to next row */
  156197. continue;
  156198. }
  156199. #endif
  156200. z2 = (INT32) wsptr[2];
  156201. z3 = (INT32) wsptr[6];
  156202. z1 = MULTIPLY(z2 + z3, FIX_0_541196100);
  156203. tmp2 = z1 + MULTIPLY(z3, - FIX_1_847759065);
  156204. tmp3 = z1 + MULTIPLY(z2, FIX_0_765366865);
  156205. tmp0 = ((INT32) wsptr[0] + (INT32) wsptr[4]) << CONST_BITS;
  156206. tmp1 = ((INT32) wsptr[0] - (INT32) wsptr[4]) << CONST_BITS;
  156207. tmp10 = tmp0 + tmp3;
  156208. tmp13 = tmp0 - tmp3;
  156209. tmp11 = tmp1 + tmp2;
  156210. tmp12 = tmp1 - tmp2;
  156211. tmp0 = (INT32) wsptr[7];
  156212. tmp1 = (INT32) wsptr[5];
  156213. tmp2 = (INT32) wsptr[3];
  156214. tmp3 = (INT32) wsptr[1];
  156215. z1 = tmp0 + tmp3;
  156216. z2 = tmp1 + tmp2;
  156217. z3 = tmp0 + tmp2;
  156218. z4 = tmp1 + tmp3;
  156219. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  156220. tmp0 = MULTIPLY(tmp0, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  156221. tmp1 = MULTIPLY(tmp1, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  156222. tmp2 = MULTIPLY(tmp2, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  156223. tmp3 = MULTIPLY(tmp3, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  156224. z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  156225. z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  156226. z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  156227. z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  156228. z3 += z5;
  156229. z4 += z5;
  156230. tmp0 += z1 + z3;
  156231. tmp1 += z2 + z4;
  156232. tmp2 += z2 + z3;
  156233. tmp3 += z1 + z4;
  156234. outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp3,
  156235. CONST_BITS+PASS1_BITS+3)
  156236. & RANGE_MASK];
  156237. outptr[7] = range_limit[(int) DESCALE(tmp10 - tmp3,
  156238. CONST_BITS+PASS1_BITS+3)
  156239. & RANGE_MASK];
  156240. outptr[1] = range_limit[(int) DESCALE(tmp11 + tmp2,
  156241. CONST_BITS+PASS1_BITS+3)
  156242. & RANGE_MASK];
  156243. outptr[6] = range_limit[(int) DESCALE(tmp11 - tmp2,
  156244. CONST_BITS+PASS1_BITS+3)
  156245. & RANGE_MASK];
  156246. outptr[2] = range_limit[(int) DESCALE(tmp12 + tmp1,
  156247. CONST_BITS+PASS1_BITS+3)
  156248. & RANGE_MASK];
  156249. outptr[5] = range_limit[(int) DESCALE(tmp12 - tmp1,
  156250. CONST_BITS+PASS1_BITS+3)
  156251. & RANGE_MASK];
  156252. outptr[3] = range_limit[(int) DESCALE(tmp13 + tmp0,
  156253. CONST_BITS+PASS1_BITS+3)
  156254. & RANGE_MASK];
  156255. outptr[4] = range_limit[(int) DESCALE(tmp13 - tmp0,
  156256. CONST_BITS+PASS1_BITS+3)
  156257. & RANGE_MASK];
  156258. wsptr += DCTSIZE; /* advance pointer to next row */
  156259. }
  156260. }
  156261. #endif /* DCT_ISLOW_SUPPORTED */
  156262. /*** End of inlined file: jidctint.c ***/
  156263. /*** Start of inlined file: jidctred.c ***/
  156264. #define JPEG_INTERNALS
  156265. #ifdef IDCT_SCALING_SUPPORTED
  156266. #if DCTSIZE != 8
  156267. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  156268. #endif
  156269. #if BITS_IN_JSAMPLE == 8
  156270. #define CONST_BITS 13
  156271. #define PASS1_BITS 2
  156272. #else
  156273. #define CONST_BITS 13
  156274. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  156275. #endif
  156276. #if CONST_BITS == 13
  156277. #define FIX_0_211164243 ((INT32) 1730) /* FIX(0.211164243) */
  156278. #define FIX_0_509795579 ((INT32) 4176) /* FIX(0.509795579) */
  156279. #define FIX_0_601344887 ((INT32) 4926) /* FIX(0.601344887) */
  156280. #define FIX_0_720959822 ((INT32) 5906) /* FIX(0.720959822) */
  156281. #define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */
  156282. #define FIX_0_850430095 ((INT32) 6967) /* FIX(0.850430095) */
  156283. #define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */
  156284. #define FIX_1_061594337 ((INT32) 8697) /* FIX(1.061594337) */
  156285. #define FIX_1_272758580 ((INT32) 10426) /* FIX(1.272758580) */
  156286. #define FIX_1_451774981 ((INT32) 11893) /* FIX(1.451774981) */
  156287. #define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */
  156288. #define FIX_2_172734803 ((INT32) 17799) /* FIX(2.172734803) */
  156289. #define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */
  156290. #define FIX_3_624509785 ((INT32) 29692) /* FIX(3.624509785) */
  156291. #else
  156292. #define FIX_0_211164243 FIX(0.211164243)
  156293. #define FIX_0_509795579 FIX(0.509795579)
  156294. #define FIX_0_601344887 FIX(0.601344887)
  156295. #define FIX_0_720959822 FIX(0.720959822)
  156296. #define FIX_0_765366865 FIX(0.765366865)
  156297. #define FIX_0_850430095 FIX(0.850430095)
  156298. #define FIX_0_899976223 FIX(0.899976223)
  156299. #define FIX_1_061594337 FIX(1.061594337)
  156300. #define FIX_1_272758580 FIX(1.272758580)
  156301. #define FIX_1_451774981 FIX(1.451774981)
  156302. #define FIX_1_847759065 FIX(1.847759065)
  156303. #define FIX_2_172734803 FIX(2.172734803)
  156304. #define FIX_2_562915447 FIX(2.562915447)
  156305. #define FIX_3_624509785 FIX(3.624509785)
  156306. #endif
  156307. #if BITS_IN_JSAMPLE == 8
  156308. #define MULTIPLY(var,const) MULTIPLY16C16(var,const)
  156309. #else
  156310. #define MULTIPLY(var,const) ((var) * (const))
  156311. #endif
  156312. #define DEQUANTIZE(coef,quantval) (((ISLOW_MULT_TYPE) (coef)) * (quantval))
  156313. GLOBAL(void)
  156314. jpeg_idct_4x4 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  156315. JCOEFPTR coef_block,
  156316. JSAMPARRAY output_buf, JDIMENSION output_col)
  156317. {
  156318. INT32 tmp0, tmp2, tmp10, tmp12;
  156319. INT32 z1, z2, z3, z4;
  156320. JCOEFPTR inptr;
  156321. ISLOW_MULT_TYPE * quantptr;
  156322. int * wsptr;
  156323. JSAMPROW outptr;
  156324. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  156325. int ctr;
  156326. int workspace[DCTSIZE*4]; /* buffers data between passes */
  156327. SHIFT_TEMPS
  156328. inptr = coef_block;
  156329. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  156330. wsptr = workspace;
  156331. for (ctr = DCTSIZE; ctr > 0; inptr++, quantptr++, wsptr++, ctr--) {
  156332. if (ctr == DCTSIZE-4)
  156333. continue;
  156334. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
  156335. inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*5] == 0 &&
  156336. inptr[DCTSIZE*6] == 0 && inptr[DCTSIZE*7] == 0) {
  156337. int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
  156338. wsptr[DCTSIZE*0] = dcval;
  156339. wsptr[DCTSIZE*1] = dcval;
  156340. wsptr[DCTSIZE*2] = dcval;
  156341. wsptr[DCTSIZE*3] = dcval;
  156342. continue;
  156343. }
  156344. tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  156345. tmp0 <<= (CONST_BITS+1);
  156346. z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  156347. z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  156348. tmp2 = MULTIPLY(z2, FIX_1_847759065) + MULTIPLY(z3, - FIX_0_765366865);
  156349. tmp10 = tmp0 + tmp2;
  156350. tmp12 = tmp0 - tmp2;
  156351. z1 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  156352. z2 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  156353. z3 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  156354. z4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  156355. tmp0 = MULTIPLY(z1, - FIX_0_211164243) /* sqrt(2) * (c3-c1) */
  156356. + MULTIPLY(z2, FIX_1_451774981) /* sqrt(2) * (c3+c7) */
  156357. + MULTIPLY(z3, - FIX_2_172734803) /* sqrt(2) * (-c1-c5) */
  156358. + MULTIPLY(z4, FIX_1_061594337); /* sqrt(2) * (c5+c7) */
  156359. tmp2 = MULTIPLY(z1, - FIX_0_509795579) /* sqrt(2) * (c7-c5) */
  156360. + MULTIPLY(z2, - FIX_0_601344887) /* sqrt(2) * (c5-c1) */
  156361. + MULTIPLY(z3, FIX_0_899976223) /* sqrt(2) * (c3-c7) */
  156362. + MULTIPLY(z4, FIX_2_562915447); /* sqrt(2) * (c1+c3) */
  156363. wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp2, CONST_BITS-PASS1_BITS+1);
  156364. wsptr[DCTSIZE*3] = (int) DESCALE(tmp10 - tmp2, CONST_BITS-PASS1_BITS+1);
  156365. wsptr[DCTSIZE*1] = (int) DESCALE(tmp12 + tmp0, CONST_BITS-PASS1_BITS+1);
  156366. wsptr[DCTSIZE*2] = (int) DESCALE(tmp12 - tmp0, CONST_BITS-PASS1_BITS+1);
  156367. }
  156368. wsptr = workspace;
  156369. for (ctr = 0; ctr < 4; ctr++) {
  156370. outptr = output_buf[ctr] + output_col;
  156371. #ifndef NO_ZERO_ROW_TEST
  156372. if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 &&
  156373. wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
  156374. JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3)
  156375. & RANGE_MASK];
  156376. outptr[0] = dcval;
  156377. outptr[1] = dcval;
  156378. outptr[2] = dcval;
  156379. outptr[3] = dcval;
  156380. wsptr += DCTSIZE; /* advance pointer to next row */
  156381. continue;
  156382. }
  156383. #endif
  156384. tmp0 = ((INT32) wsptr[0]) << (CONST_BITS+1);
  156385. tmp2 = MULTIPLY((INT32) wsptr[2], FIX_1_847759065)
  156386. + MULTIPLY((INT32) wsptr[6], - FIX_0_765366865);
  156387. tmp10 = tmp0 + tmp2;
  156388. tmp12 = tmp0 - tmp2;
  156389. z1 = (INT32) wsptr[7];
  156390. z2 = (INT32) wsptr[5];
  156391. z3 = (INT32) wsptr[3];
  156392. z4 = (INT32) wsptr[1];
  156393. tmp0 = MULTIPLY(z1, - FIX_0_211164243) /* sqrt(2) * (c3-c1) */
  156394. + MULTIPLY(z2, FIX_1_451774981) /* sqrt(2) * (c3+c7) */
  156395. + MULTIPLY(z3, - FIX_2_172734803) /* sqrt(2) * (-c1-c5) */
  156396. + MULTIPLY(z4, FIX_1_061594337); /* sqrt(2) * (c5+c7) */
  156397. tmp2 = MULTIPLY(z1, - FIX_0_509795579) /* sqrt(2) * (c7-c5) */
  156398. + MULTIPLY(z2, - FIX_0_601344887) /* sqrt(2) * (c5-c1) */
  156399. + MULTIPLY(z3, FIX_0_899976223) /* sqrt(2) * (c3-c7) */
  156400. + MULTIPLY(z4, FIX_2_562915447); /* sqrt(2) * (c1+c3) */
  156401. outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp2,
  156402. CONST_BITS+PASS1_BITS+3+1)
  156403. & RANGE_MASK];
  156404. outptr[3] = range_limit[(int) DESCALE(tmp10 - tmp2,
  156405. CONST_BITS+PASS1_BITS+3+1)
  156406. & RANGE_MASK];
  156407. outptr[1] = range_limit[(int) DESCALE(tmp12 + tmp0,
  156408. CONST_BITS+PASS1_BITS+3+1)
  156409. & RANGE_MASK];
  156410. outptr[2] = range_limit[(int) DESCALE(tmp12 - tmp0,
  156411. CONST_BITS+PASS1_BITS+3+1)
  156412. & RANGE_MASK];
  156413. wsptr += DCTSIZE; /* advance pointer to next row */
  156414. }
  156415. }
  156416. GLOBAL(void)
  156417. jpeg_idct_2x2 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  156418. JCOEFPTR coef_block,
  156419. JSAMPARRAY output_buf, JDIMENSION output_col)
  156420. {
  156421. INT32 tmp0, tmp10, z1;
  156422. JCOEFPTR inptr;
  156423. ISLOW_MULT_TYPE * quantptr;
  156424. int * wsptr;
  156425. JSAMPROW outptr;
  156426. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  156427. int ctr;
  156428. int workspace[DCTSIZE*2]; /* buffers data between passes */
  156429. SHIFT_TEMPS
  156430. inptr = coef_block;
  156431. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  156432. wsptr = workspace;
  156433. for (ctr = DCTSIZE; ctr > 0; inptr++, quantptr++, wsptr++, ctr--) {
  156434. if (ctr == DCTSIZE-2 || ctr == DCTSIZE-4 || ctr == DCTSIZE-6)
  156435. continue;
  156436. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*3] == 0 &&
  156437. inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*7] == 0) {
  156438. int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
  156439. wsptr[DCTSIZE*0] = dcval;
  156440. wsptr[DCTSIZE*1] = dcval;
  156441. continue;
  156442. }
  156443. z1 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  156444. tmp10 = z1 << (CONST_BITS+2);
  156445. z1 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  156446. tmp0 = MULTIPLY(z1, - FIX_0_720959822); /* sqrt(2) * (c7-c5+c3-c1) */
  156447. z1 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  156448. tmp0 += MULTIPLY(z1, FIX_0_850430095); /* sqrt(2) * (-c1+c3+c5+c7) */
  156449. z1 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  156450. tmp0 += MULTIPLY(z1, - FIX_1_272758580); /* sqrt(2) * (-c1+c3-c5-c7) */
  156451. z1 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  156452. tmp0 += MULTIPLY(z1, FIX_3_624509785); /* sqrt(2) * (c1+c3+c5+c7) */
  156453. wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp0, CONST_BITS-PASS1_BITS+2);
  156454. wsptr[DCTSIZE*1] = (int) DESCALE(tmp10 - tmp0, CONST_BITS-PASS1_BITS+2);
  156455. }
  156456. wsptr = workspace;
  156457. for (ctr = 0; ctr < 2; ctr++) {
  156458. outptr = output_buf[ctr] + output_col;
  156459. #ifndef NO_ZERO_ROW_TEST
  156460. if (wsptr[1] == 0 && wsptr[3] == 0 && wsptr[5] == 0 && wsptr[7] == 0) {
  156461. JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3)
  156462. & RANGE_MASK];
  156463. outptr[0] = dcval;
  156464. outptr[1] = dcval;
  156465. wsptr += DCTSIZE; /* advance pointer to next row */
  156466. continue;
  156467. }
  156468. #endif
  156469. tmp10 = ((INT32) wsptr[0]) << (CONST_BITS+2);
  156470. tmp0 = MULTIPLY((INT32) wsptr[7], - FIX_0_720959822) /* sqrt(2) * (c7-c5+c3-c1) */
  156471. + MULTIPLY((INT32) wsptr[5], FIX_0_850430095) /* sqrt(2) * (-c1+c3+c5+c7) */
  156472. + MULTIPLY((INT32) wsptr[3], - FIX_1_272758580) /* sqrt(2) * (-c1+c3-c5-c7) */
  156473. + MULTIPLY((INT32) wsptr[1], FIX_3_624509785); /* sqrt(2) * (c1+c3+c5+c7) */
  156474. outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp0,
  156475. CONST_BITS+PASS1_BITS+3+2)
  156476. & RANGE_MASK];
  156477. outptr[1] = range_limit[(int) DESCALE(tmp10 - tmp0,
  156478. CONST_BITS+PASS1_BITS+3+2)
  156479. & RANGE_MASK];
  156480. wsptr += DCTSIZE; /* advance pointer to next row */
  156481. }
  156482. }
  156483. GLOBAL(void)
  156484. jpeg_idct_1x1 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  156485. JCOEFPTR coef_block,
  156486. JSAMPARRAY output_buf, JDIMENSION output_col)
  156487. {
  156488. int dcval;
  156489. ISLOW_MULT_TYPE * quantptr;
  156490. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  156491. SHIFT_TEMPS
  156492. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  156493. dcval = DEQUANTIZE(coef_block[0], quantptr[0]);
  156494. dcval = (int) DESCALE((INT32) dcval, 3);
  156495. output_buf[0][output_col] = range_limit[dcval & RANGE_MASK];
  156496. }
  156497. #endif /* IDCT_SCALING_SUPPORTED */
  156498. /*** End of inlined file: jidctred.c ***/
  156499. /*** Start of inlined file: jmemmgr.c ***/
  156500. #define JPEG_INTERNALS
  156501. #define AM_MEMORY_MANAGER /* we define jvirt_Xarray_control structs */
  156502. /*** Start of inlined file: jmemsys.h ***/
  156503. #ifndef __jmemsys_h__
  156504. #define __jmemsys_h__
  156505. #ifdef NEED_SHORT_EXTERNAL_NAMES
  156506. #define jpeg_get_small jGetSmall
  156507. #define jpeg_free_small jFreeSmall
  156508. #define jpeg_get_large jGetLarge
  156509. #define jpeg_free_large jFreeLarge
  156510. #define jpeg_mem_available jMemAvail
  156511. #define jpeg_open_backing_store jOpenBackStore
  156512. #define jpeg_mem_init jMemInit
  156513. #define jpeg_mem_term jMemTerm
  156514. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  156515. EXTERN(void *) jpeg_get_small JPP((j_common_ptr cinfo, size_t sizeofobject));
  156516. EXTERN(void) jpeg_free_small JPP((j_common_ptr cinfo, void * object,
  156517. size_t sizeofobject));
  156518. EXTERN(void FAR *) jpeg_get_large JPP((j_common_ptr cinfo,
  156519. size_t sizeofobject));
  156520. EXTERN(void) jpeg_free_large JPP((j_common_ptr cinfo, void FAR * object,
  156521. size_t sizeofobject));
  156522. #ifndef MAX_ALLOC_CHUNK /* may be overridden in jconfig.h */
  156523. #define MAX_ALLOC_CHUNK 1000000000L
  156524. #endif
  156525. EXTERN(long) jpeg_mem_available JPP((j_common_ptr cinfo,
  156526. long min_bytes_needed,
  156527. long max_bytes_needed,
  156528. long already_allocated));
  156529. #define TEMP_NAME_LENGTH 64 /* max length of a temporary file's name */
  156530. #ifdef USE_MSDOS_MEMMGR /* DOS-specific junk */
  156531. typedef unsigned short XMSH; /* type of extended-memory handles */
  156532. typedef unsigned short EMSH; /* type of expanded-memory handles */
  156533. typedef union {
  156534. short file_handle; /* DOS file handle if it's a temp file */
  156535. XMSH xms_handle; /* handle if it's a chunk of XMS */
  156536. EMSH ems_handle; /* handle if it's a chunk of EMS */
  156537. } handle_union;
  156538. #endif /* USE_MSDOS_MEMMGR */
  156539. #ifdef USE_MAC_MEMMGR /* Mac-specific junk */
  156540. #include <Files.h>
  156541. #endif /* USE_MAC_MEMMGR */
  156542. //typedef struct backing_store_struct * backing_store_ptr;
  156543. typedef struct backing_store_struct {
  156544. JMETHOD(void, read_backing_store, (j_common_ptr cinfo,
  156545. struct backing_store_struct *info,
  156546. void FAR * buffer_address,
  156547. long file_offset, long byte_count));
  156548. JMETHOD(void, write_backing_store, (j_common_ptr cinfo,
  156549. struct backing_store_struct *info,
  156550. void FAR * buffer_address,
  156551. long file_offset, long byte_count));
  156552. JMETHOD(void, close_backing_store, (j_common_ptr cinfo,
  156553. struct backing_store_struct *info));
  156554. #ifdef USE_MSDOS_MEMMGR
  156555. handle_union handle; /* reference to backing-store storage object */
  156556. char temp_name[TEMP_NAME_LENGTH]; /* name if it's a file */
  156557. #else
  156558. #ifdef USE_MAC_MEMMGR
  156559. short temp_file; /* file reference number to temp file */
  156560. FSSpec tempSpec; /* the FSSpec for the temp file */
  156561. char temp_name[TEMP_NAME_LENGTH]; /* name if it's a file */
  156562. #else
  156563. FILE * temp_file; /* stdio reference to temp file */
  156564. char temp_name[TEMP_NAME_LENGTH]; /* name of temp file */
  156565. #endif
  156566. #endif
  156567. } backing_store_info;
  156568. EXTERN(void) jpeg_open_backing_store JPP((j_common_ptr cinfo,
  156569. struct backing_store_struct *info,
  156570. long total_bytes_needed));
  156571. EXTERN(long) jpeg_mem_init JPP((j_common_ptr cinfo));
  156572. EXTERN(void) jpeg_mem_term JPP((j_common_ptr cinfo));
  156573. #endif
  156574. /*** End of inlined file: jmemsys.h ***/
  156575. /* import the system-dependent declarations */
  156576. #ifndef NO_GETENV
  156577. #ifndef HAVE_STDLIB_H /* <stdlib.h> should declare getenv() */
  156578. extern char * getenv JPP((const char * name));
  156579. #endif
  156580. #endif
  156581. #ifndef ALIGN_TYPE /* so can override from jconfig.h */
  156582. #define ALIGN_TYPE double
  156583. #endif
  156584. typedef union small_pool_struct * small_pool_ptr;
  156585. typedef union small_pool_struct {
  156586. struct {
  156587. small_pool_ptr next; /* next in list of pools */
  156588. size_t bytes_used; /* how many bytes already used within pool */
  156589. size_t bytes_left; /* bytes still available in this pool */
  156590. } hdr;
  156591. ALIGN_TYPE dummy; /* included in union to ensure alignment */
  156592. } small_pool_hdr;
  156593. typedef union large_pool_struct FAR * large_pool_ptr;
  156594. typedef union large_pool_struct {
  156595. struct {
  156596. large_pool_ptr next; /* next in list of pools */
  156597. size_t bytes_used; /* how many bytes already used within pool */
  156598. size_t bytes_left; /* bytes still available in this pool */
  156599. } hdr;
  156600. ALIGN_TYPE dummy; /* included in union to ensure alignment */
  156601. } large_pool_hdr;
  156602. typedef struct {
  156603. struct jpeg_memory_mgr pub; /* public fields */
  156604. small_pool_ptr small_list[JPOOL_NUMPOOLS];
  156605. large_pool_ptr large_list[JPOOL_NUMPOOLS];
  156606. jvirt_sarray_ptr virt_sarray_list;
  156607. jvirt_barray_ptr virt_barray_list;
  156608. long total_space_allocated;
  156609. JDIMENSION last_rowsperchunk; /* from most recent alloc_sarray/barray */
  156610. } my_memory_mgr;
  156611. typedef my_memory_mgr * my_mem_ptr;
  156612. struct jvirt_sarray_control {
  156613. JSAMPARRAY mem_buffer; /* => the in-memory buffer */
  156614. JDIMENSION rows_in_array; /* total virtual array height */
  156615. JDIMENSION samplesperrow; /* width of array (and of memory buffer) */
  156616. JDIMENSION maxaccess; /* max rows accessed by access_virt_sarray */
  156617. JDIMENSION rows_in_mem; /* height of memory buffer */
  156618. JDIMENSION rowsperchunk; /* allocation chunk size in mem_buffer */
  156619. JDIMENSION cur_start_row; /* first logical row # in the buffer */
  156620. JDIMENSION first_undef_row; /* row # of first uninitialized row */
  156621. boolean pre_zero; /* pre-zero mode requested? */
  156622. boolean dirty; /* do current buffer contents need written? */
  156623. boolean b_s_open; /* is backing-store data valid? */
  156624. jvirt_sarray_ptr next; /* link to next virtual sarray control block */
  156625. backing_store_info b_s_info; /* System-dependent control info */
  156626. };
  156627. struct jvirt_barray_control {
  156628. JBLOCKARRAY mem_buffer; /* => the in-memory buffer */
  156629. JDIMENSION rows_in_array; /* total virtual array height */
  156630. JDIMENSION blocksperrow; /* width of array (and of memory buffer) */
  156631. JDIMENSION maxaccess; /* max rows accessed by access_virt_barray */
  156632. JDIMENSION rows_in_mem; /* height of memory buffer */
  156633. JDIMENSION rowsperchunk; /* allocation chunk size in mem_buffer */
  156634. JDIMENSION cur_start_row; /* first logical row # in the buffer */
  156635. JDIMENSION first_undef_row; /* row # of first uninitialized row */
  156636. boolean pre_zero; /* pre-zero mode requested? */
  156637. boolean dirty; /* do current buffer contents need written? */
  156638. boolean b_s_open; /* is backing-store data valid? */
  156639. jvirt_barray_ptr next; /* link to next virtual barray control block */
  156640. backing_store_info b_s_info; /* System-dependent control info */
  156641. };
  156642. #ifdef MEM_STATS /* optional extra stuff for statistics */
  156643. LOCAL(void)
  156644. print_mem_stats (j_common_ptr cinfo, int pool_id)
  156645. {
  156646. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156647. small_pool_ptr shdr_ptr;
  156648. large_pool_ptr lhdr_ptr;
  156649. fprintf(stderr, "Freeing pool %d, total space = %ld\n",
  156650. pool_id, mem->total_space_allocated);
  156651. for (lhdr_ptr = mem->large_list[pool_id]; lhdr_ptr != NULL;
  156652. lhdr_ptr = lhdr_ptr->hdr.next) {
  156653. fprintf(stderr, " Large chunk used %ld\n",
  156654. (long) lhdr_ptr->hdr.bytes_used);
  156655. }
  156656. for (shdr_ptr = mem->small_list[pool_id]; shdr_ptr != NULL;
  156657. shdr_ptr = shdr_ptr->hdr.next) {
  156658. fprintf(stderr, " Small chunk used %ld free %ld\n",
  156659. (long) shdr_ptr->hdr.bytes_used,
  156660. (long) shdr_ptr->hdr.bytes_left);
  156661. }
  156662. }
  156663. #endif /* MEM_STATS */
  156664. LOCAL(void)
  156665. out_of_memory (j_common_ptr cinfo, int which)
  156666. {
  156667. #ifdef MEM_STATS
  156668. cinfo->err->trace_level = 2; /* force self_destruct to report stats */
  156669. #endif
  156670. ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, which);
  156671. }
  156672. static const size_t first_pool_slop[JPOOL_NUMPOOLS] =
  156673. {
  156674. 1600, /* first PERMANENT pool */
  156675. 16000 /* first IMAGE pool */
  156676. };
  156677. static const size_t extra_pool_slop[JPOOL_NUMPOOLS] =
  156678. {
  156679. 0, /* additional PERMANENT pools */
  156680. 5000 /* additional IMAGE pools */
  156681. };
  156682. #define MIN_SLOP 50 /* greater than 0 to avoid futile looping */
  156683. METHODDEF(void *)
  156684. alloc_small (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
  156685. {
  156686. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156687. small_pool_ptr hdr_ptr, prev_hdr_ptr;
  156688. char * data_ptr;
  156689. size_t odd_bytes, min_request, slop;
  156690. if (sizeofobject > (size_t) (MAX_ALLOC_CHUNK-SIZEOF(small_pool_hdr)))
  156691. out_of_memory(cinfo, 1); /* request exceeds malloc's ability */
  156692. odd_bytes = sizeofobject % SIZEOF(ALIGN_TYPE);
  156693. if (odd_bytes > 0)
  156694. sizeofobject += SIZEOF(ALIGN_TYPE) - odd_bytes;
  156695. if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
  156696. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156697. prev_hdr_ptr = NULL;
  156698. hdr_ptr = mem->small_list[pool_id];
  156699. while (hdr_ptr != NULL) {
  156700. if (hdr_ptr->hdr.bytes_left >= sizeofobject)
  156701. break; /* found pool with enough space */
  156702. prev_hdr_ptr = hdr_ptr;
  156703. hdr_ptr = hdr_ptr->hdr.next;
  156704. }
  156705. if (hdr_ptr == NULL) {
  156706. min_request = sizeofobject + SIZEOF(small_pool_hdr);
  156707. if (prev_hdr_ptr == NULL) /* first pool in class? */
  156708. slop = first_pool_slop[pool_id];
  156709. else
  156710. slop = extra_pool_slop[pool_id];
  156711. if (slop > (size_t) (MAX_ALLOC_CHUNK-min_request))
  156712. slop = (size_t) (MAX_ALLOC_CHUNK-min_request);
  156713. for (;;) {
  156714. hdr_ptr = (small_pool_ptr) jpeg_get_small(cinfo, min_request + slop);
  156715. if (hdr_ptr != NULL)
  156716. break;
  156717. slop /= 2;
  156718. if (slop < MIN_SLOP) /* give up when it gets real small */
  156719. out_of_memory(cinfo, 2); /* jpeg_get_small failed */
  156720. }
  156721. mem->total_space_allocated += min_request + slop;
  156722. hdr_ptr->hdr.next = NULL;
  156723. hdr_ptr->hdr.bytes_used = 0;
  156724. hdr_ptr->hdr.bytes_left = sizeofobject + slop;
  156725. if (prev_hdr_ptr == NULL) /* first pool in class? */
  156726. mem->small_list[pool_id] = hdr_ptr;
  156727. else
  156728. prev_hdr_ptr->hdr.next = hdr_ptr;
  156729. }
  156730. data_ptr = (char *) (hdr_ptr + 1); /* point to first data byte in pool */
  156731. data_ptr += hdr_ptr->hdr.bytes_used; /* point to place for object */
  156732. hdr_ptr->hdr.bytes_used += sizeofobject;
  156733. hdr_ptr->hdr.bytes_left -= sizeofobject;
  156734. return (void *) data_ptr;
  156735. }
  156736. METHODDEF(void FAR *)
  156737. alloc_large (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
  156738. {
  156739. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156740. large_pool_ptr hdr_ptr;
  156741. size_t odd_bytes;
  156742. if (sizeofobject > (size_t) (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)))
  156743. out_of_memory(cinfo, 3); /* request exceeds malloc's ability */
  156744. odd_bytes = sizeofobject % SIZEOF(ALIGN_TYPE);
  156745. if (odd_bytes > 0)
  156746. sizeofobject += SIZEOF(ALIGN_TYPE) - odd_bytes;
  156747. if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
  156748. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156749. hdr_ptr = (large_pool_ptr) jpeg_get_large(cinfo, sizeofobject +
  156750. SIZEOF(large_pool_hdr));
  156751. if (hdr_ptr == NULL)
  156752. out_of_memory(cinfo, 4); /* jpeg_get_large failed */
  156753. mem->total_space_allocated += sizeofobject + SIZEOF(large_pool_hdr);
  156754. hdr_ptr->hdr.next = mem->large_list[pool_id];
  156755. hdr_ptr->hdr.bytes_used = sizeofobject;
  156756. hdr_ptr->hdr.bytes_left = 0;
  156757. mem->large_list[pool_id] = hdr_ptr;
  156758. return (void FAR *) (hdr_ptr + 1); /* point to first data byte in pool */
  156759. }
  156760. METHODDEF(JSAMPARRAY)
  156761. alloc_sarray (j_common_ptr cinfo, int pool_id,
  156762. JDIMENSION samplesperrow, JDIMENSION numrows)
  156763. {
  156764. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156765. JSAMPARRAY result;
  156766. JSAMPROW workspace;
  156767. JDIMENSION rowsperchunk, currow, i;
  156768. long ltemp;
  156769. ltemp = (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)) /
  156770. ((long) samplesperrow * SIZEOF(JSAMPLE));
  156771. if (ltemp <= 0)
  156772. ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  156773. if (ltemp < (long) numrows)
  156774. rowsperchunk = (JDIMENSION) ltemp;
  156775. else
  156776. rowsperchunk = numrows;
  156777. mem->last_rowsperchunk = rowsperchunk;
  156778. result = (JSAMPARRAY) alloc_small(cinfo, pool_id,
  156779. (size_t) (numrows * SIZEOF(JSAMPROW)));
  156780. currow = 0;
  156781. while (currow < numrows) {
  156782. rowsperchunk = MIN(rowsperchunk, numrows - currow);
  156783. workspace = (JSAMPROW) alloc_large(cinfo, pool_id,
  156784. (size_t) ((size_t) rowsperchunk * (size_t) samplesperrow
  156785. * SIZEOF(JSAMPLE)));
  156786. for (i = rowsperchunk; i > 0; i--) {
  156787. result[currow++] = workspace;
  156788. workspace += samplesperrow;
  156789. }
  156790. }
  156791. return result;
  156792. }
  156793. METHODDEF(JBLOCKARRAY)
  156794. alloc_barray (j_common_ptr cinfo, int pool_id,
  156795. JDIMENSION blocksperrow, JDIMENSION numrows)
  156796. {
  156797. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156798. JBLOCKARRAY result;
  156799. JBLOCKROW workspace;
  156800. JDIMENSION rowsperchunk, currow, i;
  156801. long ltemp;
  156802. ltemp = (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)) /
  156803. ((long) blocksperrow * SIZEOF(JBLOCK));
  156804. if (ltemp <= 0)
  156805. ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  156806. if (ltemp < (long) numrows)
  156807. rowsperchunk = (JDIMENSION) ltemp;
  156808. else
  156809. rowsperchunk = numrows;
  156810. mem->last_rowsperchunk = rowsperchunk;
  156811. result = (JBLOCKARRAY) alloc_small(cinfo, pool_id,
  156812. (size_t) (numrows * SIZEOF(JBLOCKROW)));
  156813. currow = 0;
  156814. while (currow < numrows) {
  156815. rowsperchunk = MIN(rowsperchunk, numrows - currow);
  156816. workspace = (JBLOCKROW) alloc_large(cinfo, pool_id,
  156817. (size_t) ((size_t) rowsperchunk * (size_t) blocksperrow
  156818. * SIZEOF(JBLOCK)));
  156819. for (i = rowsperchunk; i > 0; i--) {
  156820. result[currow++] = workspace;
  156821. workspace += blocksperrow;
  156822. }
  156823. }
  156824. return result;
  156825. }
  156826. METHODDEF(jvirt_sarray_ptr)
  156827. request_virt_sarray (j_common_ptr cinfo, int pool_id, boolean pre_zero,
  156828. JDIMENSION samplesperrow, JDIMENSION numrows,
  156829. JDIMENSION maxaccess)
  156830. {
  156831. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156832. jvirt_sarray_ptr result;
  156833. if (pool_id != JPOOL_IMAGE)
  156834. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156835. result = (jvirt_sarray_ptr) alloc_small(cinfo, pool_id,
  156836. SIZEOF(struct jvirt_sarray_control));
  156837. result->mem_buffer = NULL; /* marks array not yet realized */
  156838. result->rows_in_array = numrows;
  156839. result->samplesperrow = samplesperrow;
  156840. result->maxaccess = maxaccess;
  156841. result->pre_zero = pre_zero;
  156842. result->b_s_open = FALSE; /* no associated backing-store object */
  156843. result->next = mem->virt_sarray_list; /* add to list of virtual arrays */
  156844. mem->virt_sarray_list = result;
  156845. return result;
  156846. }
  156847. METHODDEF(jvirt_barray_ptr)
  156848. request_virt_barray (j_common_ptr cinfo, int pool_id, boolean pre_zero,
  156849. JDIMENSION blocksperrow, JDIMENSION numrows,
  156850. JDIMENSION maxaccess)
  156851. {
  156852. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156853. jvirt_barray_ptr result;
  156854. if (pool_id != JPOOL_IMAGE)
  156855. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156856. result = (jvirt_barray_ptr) alloc_small(cinfo, pool_id,
  156857. SIZEOF(struct jvirt_barray_control));
  156858. result->mem_buffer = NULL; /* marks array not yet realized */
  156859. result->rows_in_array = numrows;
  156860. result->blocksperrow = blocksperrow;
  156861. result->maxaccess = maxaccess;
  156862. result->pre_zero = pre_zero;
  156863. result->b_s_open = FALSE; /* no associated backing-store object */
  156864. result->next = mem->virt_barray_list; /* add to list of virtual arrays */
  156865. mem->virt_barray_list = result;
  156866. return result;
  156867. }
  156868. METHODDEF(void)
  156869. realize_virt_arrays (j_common_ptr cinfo)
  156870. {
  156871. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156872. long space_per_minheight, maximum_space, avail_mem;
  156873. long minheights, max_minheights;
  156874. jvirt_sarray_ptr sptr;
  156875. jvirt_barray_ptr bptr;
  156876. space_per_minheight = 0;
  156877. maximum_space = 0;
  156878. for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
  156879. if (sptr->mem_buffer == NULL) { /* if not realized yet */
  156880. space_per_minheight += (long) sptr->maxaccess *
  156881. (long) sptr->samplesperrow * SIZEOF(JSAMPLE);
  156882. maximum_space += (long) sptr->rows_in_array *
  156883. (long) sptr->samplesperrow * SIZEOF(JSAMPLE);
  156884. }
  156885. }
  156886. for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
  156887. if (bptr->mem_buffer == NULL) { /* if not realized yet */
  156888. space_per_minheight += (long) bptr->maxaccess *
  156889. (long) bptr->blocksperrow * SIZEOF(JBLOCK);
  156890. maximum_space += (long) bptr->rows_in_array *
  156891. (long) bptr->blocksperrow * SIZEOF(JBLOCK);
  156892. }
  156893. }
  156894. if (space_per_minheight <= 0)
  156895. return; /* no unrealized arrays, no work */
  156896. avail_mem = jpeg_mem_available(cinfo, space_per_minheight, maximum_space,
  156897. mem->total_space_allocated);
  156898. if (avail_mem >= maximum_space)
  156899. max_minheights = 1000000000L;
  156900. else {
  156901. max_minheights = avail_mem / space_per_minheight;
  156902. if (max_minheights <= 0)
  156903. max_minheights = 1;
  156904. }
  156905. for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
  156906. if (sptr->mem_buffer == NULL) { /* if not realized yet */
  156907. minheights = ((long) sptr->rows_in_array - 1L) / sptr->maxaccess + 1L;
  156908. if (minheights <= max_minheights) {
  156909. sptr->rows_in_mem = sptr->rows_in_array;
  156910. } else {
  156911. sptr->rows_in_mem = (JDIMENSION) (max_minheights * sptr->maxaccess);
  156912. jpeg_open_backing_store(cinfo, & sptr->b_s_info,
  156913. (long) sptr->rows_in_array *
  156914. (long) sptr->samplesperrow *
  156915. (long) SIZEOF(JSAMPLE));
  156916. sptr->b_s_open = TRUE;
  156917. }
  156918. sptr->mem_buffer = alloc_sarray(cinfo, JPOOL_IMAGE,
  156919. sptr->samplesperrow, sptr->rows_in_mem);
  156920. sptr->rowsperchunk = mem->last_rowsperchunk;
  156921. sptr->cur_start_row = 0;
  156922. sptr->first_undef_row = 0;
  156923. sptr->dirty = FALSE;
  156924. }
  156925. }
  156926. for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
  156927. if (bptr->mem_buffer == NULL) { /* if not realized yet */
  156928. minheights = ((long) bptr->rows_in_array - 1L) / bptr->maxaccess + 1L;
  156929. if (minheights <= max_minheights) {
  156930. bptr->rows_in_mem = bptr->rows_in_array;
  156931. } else {
  156932. bptr->rows_in_mem = (JDIMENSION) (max_minheights * bptr->maxaccess);
  156933. jpeg_open_backing_store(cinfo, & bptr->b_s_info,
  156934. (long) bptr->rows_in_array *
  156935. (long) bptr->blocksperrow *
  156936. (long) SIZEOF(JBLOCK));
  156937. bptr->b_s_open = TRUE;
  156938. }
  156939. bptr->mem_buffer = alloc_barray(cinfo, JPOOL_IMAGE,
  156940. bptr->blocksperrow, bptr->rows_in_mem);
  156941. bptr->rowsperchunk = mem->last_rowsperchunk;
  156942. bptr->cur_start_row = 0;
  156943. bptr->first_undef_row = 0;
  156944. bptr->dirty = FALSE;
  156945. }
  156946. }
  156947. }
  156948. LOCAL(void)
  156949. do_sarray_io (j_common_ptr cinfo, jvirt_sarray_ptr ptr, boolean writing)
  156950. {
  156951. long bytesperrow, file_offset, byte_count, rows, thisrow, i;
  156952. bytesperrow = (long) ptr->samplesperrow * SIZEOF(JSAMPLE);
  156953. file_offset = ptr->cur_start_row * bytesperrow;
  156954. for (i = 0; i < (long) ptr->rows_in_mem; i += ptr->rowsperchunk) {
  156955. rows = MIN((long) ptr->rowsperchunk, (long) ptr->rows_in_mem - i);
  156956. thisrow = (long) ptr->cur_start_row + i;
  156957. rows = MIN(rows, (long) ptr->first_undef_row - thisrow);
  156958. rows = MIN(rows, (long) ptr->rows_in_array - thisrow);
  156959. if (rows <= 0) /* this chunk might be past end of file! */
  156960. break;
  156961. byte_count = rows * bytesperrow;
  156962. if (writing)
  156963. (*ptr->b_s_info.write_backing_store) (cinfo, & ptr->b_s_info,
  156964. (void FAR *) ptr->mem_buffer[i],
  156965. file_offset, byte_count);
  156966. else
  156967. (*ptr->b_s_info.read_backing_store) (cinfo, & ptr->b_s_info,
  156968. (void FAR *) ptr->mem_buffer[i],
  156969. file_offset, byte_count);
  156970. file_offset += byte_count;
  156971. }
  156972. }
  156973. LOCAL(void)
  156974. do_barray_io (j_common_ptr cinfo, jvirt_barray_ptr ptr, boolean writing)
  156975. {
  156976. long bytesperrow, file_offset, byte_count, rows, thisrow, i;
  156977. bytesperrow = (long) ptr->blocksperrow * SIZEOF(JBLOCK);
  156978. file_offset = ptr->cur_start_row * bytesperrow;
  156979. for (i = 0; i < (long) ptr->rows_in_mem; i += ptr->rowsperchunk) {
  156980. rows = MIN((long) ptr->rowsperchunk, (long) ptr->rows_in_mem - i);
  156981. thisrow = (long) ptr->cur_start_row + i;
  156982. rows = MIN(rows, (long) ptr->first_undef_row - thisrow);
  156983. rows = MIN(rows, (long) ptr->rows_in_array - thisrow);
  156984. if (rows <= 0) /* this chunk might be past end of file! */
  156985. break;
  156986. byte_count = rows * bytesperrow;
  156987. if (writing)
  156988. (*ptr->b_s_info.write_backing_store) (cinfo, & ptr->b_s_info,
  156989. (void FAR *) ptr->mem_buffer[i],
  156990. file_offset, byte_count);
  156991. else
  156992. (*ptr->b_s_info.read_backing_store) (cinfo, & ptr->b_s_info,
  156993. (void FAR *) ptr->mem_buffer[i],
  156994. file_offset, byte_count);
  156995. file_offset += byte_count;
  156996. }
  156997. }
  156998. METHODDEF(JSAMPARRAY)
  156999. access_virt_sarray (j_common_ptr cinfo, jvirt_sarray_ptr ptr,
  157000. JDIMENSION start_row, JDIMENSION num_rows,
  157001. boolean writable)
  157002. {
  157003. JDIMENSION end_row = start_row + num_rows;
  157004. JDIMENSION undef_row;
  157005. if (end_row > ptr->rows_in_array || num_rows > ptr->maxaccess ||
  157006. ptr->mem_buffer == NULL)
  157007. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  157008. if (start_row < ptr->cur_start_row ||
  157009. end_row > ptr->cur_start_row+ptr->rows_in_mem) {
  157010. if (! ptr->b_s_open)
  157011. ERREXIT(cinfo, JERR_VIRTUAL_BUG);
  157012. if (ptr->dirty) {
  157013. do_sarray_io(cinfo, ptr, TRUE);
  157014. ptr->dirty = FALSE;
  157015. }
  157016. if (start_row > ptr->cur_start_row) {
  157017. ptr->cur_start_row = start_row;
  157018. } else {
  157019. long ltemp;
  157020. ltemp = (long) end_row - (long) ptr->rows_in_mem;
  157021. if (ltemp < 0)
  157022. ltemp = 0; /* don't fall off front end of file */
  157023. ptr->cur_start_row = (JDIMENSION) ltemp;
  157024. }
  157025. do_sarray_io(cinfo, ptr, FALSE);
  157026. }
  157027. if (ptr->first_undef_row < end_row) {
  157028. if (ptr->first_undef_row < start_row) {
  157029. if (writable) /* writer skipped over a section of array */
  157030. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  157031. undef_row = start_row; /* but reader is allowed to read ahead */
  157032. } else {
  157033. undef_row = ptr->first_undef_row;
  157034. }
  157035. if (writable)
  157036. ptr->first_undef_row = end_row;
  157037. if (ptr->pre_zero) {
  157038. size_t bytesperrow = (size_t) ptr->samplesperrow * SIZEOF(JSAMPLE);
  157039. undef_row -= ptr->cur_start_row; /* make indexes relative to buffer */
  157040. end_row -= ptr->cur_start_row;
  157041. while (undef_row < end_row) {
  157042. jzero_far((void FAR *) ptr->mem_buffer[undef_row], bytesperrow);
  157043. undef_row++;
  157044. }
  157045. } else {
  157046. if (! writable) /* reader looking at undefined data */
  157047. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  157048. }
  157049. }
  157050. if (writable)
  157051. ptr->dirty = TRUE;
  157052. return ptr->mem_buffer + (start_row - ptr->cur_start_row);
  157053. }
  157054. METHODDEF(JBLOCKARRAY)
  157055. access_virt_barray (j_common_ptr cinfo, jvirt_barray_ptr ptr,
  157056. JDIMENSION start_row, JDIMENSION num_rows,
  157057. boolean writable)
  157058. {
  157059. JDIMENSION end_row = start_row + num_rows;
  157060. JDIMENSION undef_row;
  157061. if (end_row > ptr->rows_in_array || num_rows > ptr->maxaccess ||
  157062. ptr->mem_buffer == NULL)
  157063. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  157064. if (start_row < ptr->cur_start_row ||
  157065. end_row > ptr->cur_start_row+ptr->rows_in_mem) {
  157066. if (! ptr->b_s_open)
  157067. ERREXIT(cinfo, JERR_VIRTUAL_BUG);
  157068. if (ptr->dirty) {
  157069. do_barray_io(cinfo, ptr, TRUE);
  157070. ptr->dirty = FALSE;
  157071. }
  157072. if (start_row > ptr->cur_start_row) {
  157073. ptr->cur_start_row = start_row;
  157074. } else {
  157075. long ltemp;
  157076. ltemp = (long) end_row - (long) ptr->rows_in_mem;
  157077. if (ltemp < 0)
  157078. ltemp = 0; /* don't fall off front end of file */
  157079. ptr->cur_start_row = (JDIMENSION) ltemp;
  157080. }
  157081. do_barray_io(cinfo, ptr, FALSE);
  157082. }
  157083. if (ptr->first_undef_row < end_row) {
  157084. if (ptr->first_undef_row < start_row) {
  157085. if (writable) /* writer skipped over a section of array */
  157086. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  157087. undef_row = start_row; /* but reader is allowed to read ahead */
  157088. } else {
  157089. undef_row = ptr->first_undef_row;
  157090. }
  157091. if (writable)
  157092. ptr->first_undef_row = end_row;
  157093. if (ptr->pre_zero) {
  157094. size_t bytesperrow = (size_t) ptr->blocksperrow * SIZEOF(JBLOCK);
  157095. undef_row -= ptr->cur_start_row; /* make indexes relative to buffer */
  157096. end_row -= ptr->cur_start_row;
  157097. while (undef_row < end_row) {
  157098. jzero_far((void FAR *) ptr->mem_buffer[undef_row], bytesperrow);
  157099. undef_row++;
  157100. }
  157101. } else {
  157102. if (! writable) /* reader looking at undefined data */
  157103. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  157104. }
  157105. }
  157106. if (writable)
  157107. ptr->dirty = TRUE;
  157108. return ptr->mem_buffer + (start_row - ptr->cur_start_row);
  157109. }
  157110. METHODDEF(void)
  157111. free_pool (j_common_ptr cinfo, int pool_id)
  157112. {
  157113. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  157114. small_pool_ptr shdr_ptr;
  157115. large_pool_ptr lhdr_ptr;
  157116. size_t space_freed;
  157117. if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
  157118. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  157119. #ifdef MEM_STATS
  157120. if (cinfo->err->trace_level > 1)
  157121. print_mem_stats(cinfo, pool_id); /* print pool's memory usage statistics */
  157122. #endif
  157123. if (pool_id == JPOOL_IMAGE) {
  157124. jvirt_sarray_ptr sptr;
  157125. jvirt_barray_ptr bptr;
  157126. for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
  157127. if (sptr->b_s_open) { /* there may be no backing store */
  157128. sptr->b_s_open = FALSE; /* prevent recursive close if error */
  157129. (*sptr->b_s_info.close_backing_store) (cinfo, & sptr->b_s_info);
  157130. }
  157131. }
  157132. mem->virt_sarray_list = NULL;
  157133. for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
  157134. if (bptr->b_s_open) { /* there may be no backing store */
  157135. bptr->b_s_open = FALSE; /* prevent recursive close if error */
  157136. (*bptr->b_s_info.close_backing_store) (cinfo, & bptr->b_s_info);
  157137. }
  157138. }
  157139. mem->virt_barray_list = NULL;
  157140. }
  157141. lhdr_ptr = mem->large_list[pool_id];
  157142. mem->large_list[pool_id] = NULL;
  157143. while (lhdr_ptr != NULL) {
  157144. large_pool_ptr next_lhdr_ptr = lhdr_ptr->hdr.next;
  157145. space_freed = lhdr_ptr->hdr.bytes_used +
  157146. lhdr_ptr->hdr.bytes_left +
  157147. SIZEOF(large_pool_hdr);
  157148. jpeg_free_large(cinfo, (void FAR *) lhdr_ptr, space_freed);
  157149. mem->total_space_allocated -= space_freed;
  157150. lhdr_ptr = next_lhdr_ptr;
  157151. }
  157152. shdr_ptr = mem->small_list[pool_id];
  157153. mem->small_list[pool_id] = NULL;
  157154. while (shdr_ptr != NULL) {
  157155. small_pool_ptr next_shdr_ptr = shdr_ptr->hdr.next;
  157156. space_freed = shdr_ptr->hdr.bytes_used +
  157157. shdr_ptr->hdr.bytes_left +
  157158. SIZEOF(small_pool_hdr);
  157159. jpeg_free_small(cinfo, (void *) shdr_ptr, space_freed);
  157160. mem->total_space_allocated -= space_freed;
  157161. shdr_ptr = next_shdr_ptr;
  157162. }
  157163. }
  157164. METHODDEF(void)
  157165. self_destruct (j_common_ptr cinfo)
  157166. {
  157167. int pool;
  157168. for (pool = JPOOL_NUMPOOLS-1; pool >= JPOOL_PERMANENT; pool--) {
  157169. free_pool(cinfo, pool);
  157170. }
  157171. jpeg_free_small(cinfo, (void *) cinfo->mem, SIZEOF(my_memory_mgr));
  157172. cinfo->mem = NULL; /* ensures I will be called only once */
  157173. jpeg_mem_term(cinfo); /* system-dependent cleanup */
  157174. }
  157175. GLOBAL(void)
  157176. jinit_memory_mgr (j_common_ptr cinfo)
  157177. {
  157178. my_mem_ptr mem;
  157179. long max_to_use;
  157180. int pool;
  157181. size_t test_mac;
  157182. cinfo->mem = NULL; /* for safety if init fails */
  157183. if ((SIZEOF(ALIGN_TYPE) & (SIZEOF(ALIGN_TYPE)-1)) != 0)
  157184. ERREXIT(cinfo, JERR_BAD_ALIGN_TYPE);
  157185. test_mac = (size_t) MAX_ALLOC_CHUNK;
  157186. if ((long) test_mac != MAX_ALLOC_CHUNK ||
  157187. (MAX_ALLOC_CHUNK % SIZEOF(ALIGN_TYPE)) != 0)
  157188. ERREXIT(cinfo, JERR_BAD_ALLOC_CHUNK);
  157189. max_to_use = jpeg_mem_init(cinfo); /* system-dependent initialization */
  157190. mem = (my_mem_ptr) jpeg_get_small(cinfo, SIZEOF(my_memory_mgr));
  157191. if (mem == NULL) {
  157192. jpeg_mem_term(cinfo); /* system-dependent cleanup */
  157193. ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 0);
  157194. }
  157195. mem->pub.alloc_small = alloc_small;
  157196. mem->pub.alloc_large = alloc_large;
  157197. mem->pub.alloc_sarray = alloc_sarray;
  157198. mem->pub.alloc_barray = alloc_barray;
  157199. mem->pub.request_virt_sarray = request_virt_sarray;
  157200. mem->pub.request_virt_barray = request_virt_barray;
  157201. mem->pub.realize_virt_arrays = realize_virt_arrays;
  157202. mem->pub.access_virt_sarray = access_virt_sarray;
  157203. mem->pub.access_virt_barray = access_virt_barray;
  157204. mem->pub.free_pool = free_pool;
  157205. mem->pub.self_destruct = self_destruct;
  157206. mem->pub.max_alloc_chunk = MAX_ALLOC_CHUNK;
  157207. mem->pub.max_memory_to_use = max_to_use;
  157208. for (pool = JPOOL_NUMPOOLS-1; pool >= JPOOL_PERMANENT; pool--) {
  157209. mem->small_list[pool] = NULL;
  157210. mem->large_list[pool] = NULL;
  157211. }
  157212. mem->virt_sarray_list = NULL;
  157213. mem->virt_barray_list = NULL;
  157214. mem->total_space_allocated = SIZEOF(my_memory_mgr);
  157215. cinfo->mem = & mem->pub;
  157216. #ifndef NO_GETENV
  157217. { char * memenv;
  157218. if ((memenv = getenv("JPEGMEM")) != NULL) {
  157219. char ch = 'x';
  157220. if (sscanf(memenv, "%ld%c", &max_to_use, &ch) > 0) {
  157221. if (ch == 'm' || ch == 'M')
  157222. max_to_use *= 1000L;
  157223. mem->pub.max_memory_to_use = max_to_use * 1000L;
  157224. }
  157225. }
  157226. }
  157227. #endif
  157228. }
  157229. /*** End of inlined file: jmemmgr.c ***/
  157230. /*** Start of inlined file: jmemnobs.c ***/
  157231. #define JPEG_INTERNALS
  157232. #ifndef HAVE_STDLIB_H /* <stdlib.h> should declare malloc(),free() */
  157233. extern void * malloc JPP((size_t size));
  157234. extern void free JPP((void *ptr));
  157235. #endif
  157236. GLOBAL(void *)
  157237. jpeg_get_small (j_common_ptr cinfo, size_t sizeofobject)
  157238. {
  157239. return (void *) malloc(sizeofobject);
  157240. }
  157241. GLOBAL(void)
  157242. jpeg_free_small (j_common_ptr cinfo, void * object, size_t sizeofobject)
  157243. {
  157244. free(object);
  157245. }
  157246. GLOBAL(void FAR *)
  157247. jpeg_get_large (j_common_ptr cinfo, size_t sizeofobject)
  157248. {
  157249. return (void FAR *) malloc(sizeofobject);
  157250. }
  157251. GLOBAL(void)
  157252. jpeg_free_large (j_common_ptr cinfo, void FAR * object, size_t sizeofobject)
  157253. {
  157254. free(object);
  157255. }
  157256. GLOBAL(long)
  157257. jpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed,
  157258. long max_bytes_needed, long already_allocated)
  157259. {
  157260. return max_bytes_needed;
  157261. }
  157262. GLOBAL(void)
  157263. jpeg_open_backing_store (j_common_ptr cinfo, struct backing_store_struct *info,
  157264. long total_bytes_needed)
  157265. {
  157266. ERREXIT(cinfo, JERR_NO_BACKING_STORE);
  157267. }
  157268. GLOBAL(long)
  157269. jpeg_mem_init (j_common_ptr cinfo)
  157270. {
  157271. return 0; /* just set max_memory_to_use to 0 */
  157272. }
  157273. GLOBAL(void)
  157274. jpeg_mem_term (j_common_ptr cinfo)
  157275. {
  157276. }
  157277. /*** End of inlined file: jmemnobs.c ***/
  157278. /*** Start of inlined file: jquant1.c ***/
  157279. #define JPEG_INTERNALS
  157280. #ifdef QUANT_1PASS_SUPPORTED
  157281. #define ODITHER_SIZE 16 /* dimension of dither matrix */
  157282. #define ODITHER_CELLS (ODITHER_SIZE*ODITHER_SIZE) /* # cells in matrix */
  157283. #define ODITHER_MASK (ODITHER_SIZE-1) /* mask for wrapping around counters */
  157284. typedef int ODITHER_MATRIX[ODITHER_SIZE][ODITHER_SIZE];
  157285. typedef int (*ODITHER_MATRIX_PTR)[ODITHER_SIZE];
  157286. static const UINT8 base_dither_matrix[ODITHER_SIZE][ODITHER_SIZE] = {
  157287. { 0,192, 48,240, 12,204, 60,252, 3,195, 51,243, 15,207, 63,255 },
  157288. { 128, 64,176,112,140, 76,188,124,131, 67,179,115,143, 79,191,127 },
  157289. { 32,224, 16,208, 44,236, 28,220, 35,227, 19,211, 47,239, 31,223 },
  157290. { 160, 96,144, 80,172,108,156, 92,163, 99,147, 83,175,111,159, 95 },
  157291. { 8,200, 56,248, 4,196, 52,244, 11,203, 59,251, 7,199, 55,247 },
  157292. { 136, 72,184,120,132, 68,180,116,139, 75,187,123,135, 71,183,119 },
  157293. { 40,232, 24,216, 36,228, 20,212, 43,235, 27,219, 39,231, 23,215 },
  157294. { 168,104,152, 88,164,100,148, 84,171,107,155, 91,167,103,151, 87 },
  157295. { 2,194, 50,242, 14,206, 62,254, 1,193, 49,241, 13,205, 61,253 },
  157296. { 130, 66,178,114,142, 78,190,126,129, 65,177,113,141, 77,189,125 },
  157297. { 34,226, 18,210, 46,238, 30,222, 33,225, 17,209, 45,237, 29,221 },
  157298. { 162, 98,146, 82,174,110,158, 94,161, 97,145, 81,173,109,157, 93 },
  157299. { 10,202, 58,250, 6,198, 54,246, 9,201, 57,249, 5,197, 53,245 },
  157300. { 138, 74,186,122,134, 70,182,118,137, 73,185,121,133, 69,181,117 },
  157301. { 42,234, 26,218, 38,230, 22,214, 41,233, 25,217, 37,229, 21,213 },
  157302. { 170,106,154, 90,166,102,150, 86,169,105,153, 89,165,101,149, 85 }
  157303. };
  157304. #if BITS_IN_JSAMPLE == 8
  157305. typedef INT16 FSERROR; /* 16 bits should be enough */
  157306. typedef int LOCFSERROR; /* use 'int' for calculation temps */
  157307. #else
  157308. typedef INT32 FSERROR; /* may need more than 16 bits */
  157309. typedef INT32 LOCFSERROR; /* be sure calculation temps are big enough */
  157310. #endif
  157311. typedef FSERROR FAR *FSERRPTR; /* pointer to error array (in FAR storage!) */
  157312. #define MAX_Q_COMPS 4 /* max components I can handle */
  157313. typedef struct {
  157314. struct jpeg_color_quantizer pub; /* public fields */
  157315. JSAMPARRAY sv_colormap; /* The color map as a 2-D pixel array */
  157316. int sv_actual; /* number of entries in use */
  157317. JSAMPARRAY colorindex; /* Precomputed mapping for speed */
  157318. boolean is_padded; /* is the colorindex padded for odither? */
  157319. int Ncolors[MAX_Q_COMPS]; /* # of values alloced to each component */
  157320. int row_index; /* cur row's vertical index in dither matrix */
  157321. ODITHER_MATRIX_PTR odither[MAX_Q_COMPS]; /* one dither array per component */
  157322. FSERRPTR fserrors[MAX_Q_COMPS]; /* accumulated errors */
  157323. boolean on_odd_row; /* flag to remember which row we are on */
  157324. } my_cquantizer;
  157325. typedef my_cquantizer * my_cquantize_ptr;
  157326. LOCAL(int)
  157327. select_ncolors (j_decompress_ptr cinfo, int Ncolors[])
  157328. {
  157329. int nc = cinfo->out_color_components; /* number of color components */
  157330. int max_colors = cinfo->desired_number_of_colors;
  157331. int total_colors, iroot, i, j;
  157332. boolean changed;
  157333. long temp;
  157334. static const int RGB_order[3] = { RGB_GREEN, RGB_RED, RGB_BLUE };
  157335. iroot = 1;
  157336. do {
  157337. iroot++;
  157338. temp = iroot; /* set temp = iroot ** nc */
  157339. for (i = 1; i < nc; i++)
  157340. temp *= iroot;
  157341. } while (temp <= (long) max_colors); /* repeat till iroot exceeds root */
  157342. iroot--; /* now iroot = floor(root) */
  157343. if (iroot < 2)
  157344. ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, (int) temp);
  157345. total_colors = 1;
  157346. for (i = 0; i < nc; i++) {
  157347. Ncolors[i] = iroot;
  157348. total_colors *= iroot;
  157349. }
  157350. do {
  157351. changed = FALSE;
  157352. for (i = 0; i < nc; i++) {
  157353. j = (cinfo->out_color_space == JCS_RGB ? RGB_order[i] : i);
  157354. temp = total_colors / Ncolors[j];
  157355. temp *= Ncolors[j]+1; /* done in long arith to avoid oflo */
  157356. if (temp > (long) max_colors)
  157357. break; /* won't fit, done with this pass */
  157358. Ncolors[j]++; /* OK, apply the increment */
  157359. total_colors = (int) temp;
  157360. changed = TRUE;
  157361. }
  157362. } while (changed);
  157363. return total_colors;
  157364. }
  157365. LOCAL(int)
  157366. output_value (j_decompress_ptr cinfo, int ci, int j, int maxj)
  157367. {
  157368. return (int) (((INT32) j * MAXJSAMPLE + maxj/2) / maxj);
  157369. }
  157370. LOCAL(int)
  157371. largest_input_value (j_decompress_ptr cinfo, int ci, int j, int maxj)
  157372. {
  157373. return (int) (((INT32) (2*j + 1) * MAXJSAMPLE + maxj) / (2*maxj));
  157374. }
  157375. LOCAL(void)
  157376. create_colormap (j_decompress_ptr cinfo)
  157377. {
  157378. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157379. JSAMPARRAY colormap; /* Created colormap */
  157380. int total_colors; /* Number of distinct output colors */
  157381. int i,j,k, nci, blksize, blkdist, ptr, val;
  157382. total_colors = select_ncolors(cinfo, cquantize->Ncolors);
  157383. if (cinfo->out_color_components == 3)
  157384. TRACEMS4(cinfo, 1, JTRC_QUANT_3_NCOLORS,
  157385. total_colors, cquantize->Ncolors[0],
  157386. cquantize->Ncolors[1], cquantize->Ncolors[2]);
  157387. else
  157388. TRACEMS1(cinfo, 1, JTRC_QUANT_NCOLORS, total_colors);
  157389. colormap = (*cinfo->mem->alloc_sarray)
  157390. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  157391. (JDIMENSION) total_colors, (JDIMENSION) cinfo->out_color_components);
  157392. blkdist = total_colors;
  157393. for (i = 0; i < cinfo->out_color_components; i++) {
  157394. nci = cquantize->Ncolors[i]; /* # of distinct values for this color */
  157395. blksize = blkdist / nci;
  157396. for (j = 0; j < nci; j++) {
  157397. val = output_value(cinfo, i, j, nci-1);
  157398. for (ptr = j * blksize; ptr < total_colors; ptr += blkdist) {
  157399. for (k = 0; k < blksize; k++)
  157400. colormap[i][ptr+k] = (JSAMPLE) val;
  157401. }
  157402. }
  157403. blkdist = blksize; /* blksize of this color is blkdist of next */
  157404. }
  157405. cquantize->sv_colormap = colormap;
  157406. cquantize->sv_actual = total_colors;
  157407. }
  157408. LOCAL(void)
  157409. create_colorindex (j_decompress_ptr cinfo)
  157410. {
  157411. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157412. JSAMPROW indexptr;
  157413. int i,j,k, nci, blksize, val, pad;
  157414. if (cinfo->dither_mode == JDITHER_ORDERED) {
  157415. pad = MAXJSAMPLE*2;
  157416. cquantize->is_padded = TRUE;
  157417. } else {
  157418. pad = 0;
  157419. cquantize->is_padded = FALSE;
  157420. }
  157421. cquantize->colorindex = (*cinfo->mem->alloc_sarray)
  157422. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  157423. (JDIMENSION) (MAXJSAMPLE+1 + pad),
  157424. (JDIMENSION) cinfo->out_color_components);
  157425. blksize = cquantize->sv_actual;
  157426. for (i = 0; i < cinfo->out_color_components; i++) {
  157427. nci = cquantize->Ncolors[i]; /* # of distinct values for this color */
  157428. blksize = blksize / nci;
  157429. if (pad)
  157430. cquantize->colorindex[i] += MAXJSAMPLE;
  157431. indexptr = cquantize->colorindex[i];
  157432. val = 0;
  157433. k = largest_input_value(cinfo, i, 0, nci-1);
  157434. for (j = 0; j <= MAXJSAMPLE; j++) {
  157435. while (j > k) /* advance val if past boundary */
  157436. k = largest_input_value(cinfo, i, ++val, nci-1);
  157437. indexptr[j] = (JSAMPLE) (val * blksize);
  157438. }
  157439. if (pad)
  157440. for (j = 1; j <= MAXJSAMPLE; j++) {
  157441. indexptr[-j] = indexptr[0];
  157442. indexptr[MAXJSAMPLE+j] = indexptr[MAXJSAMPLE];
  157443. }
  157444. }
  157445. }
  157446. LOCAL(ODITHER_MATRIX_PTR)
  157447. make_odither_array (j_decompress_ptr cinfo, int ncolors)
  157448. {
  157449. ODITHER_MATRIX_PTR odither;
  157450. int j,k;
  157451. INT32 num,den;
  157452. odither = (ODITHER_MATRIX_PTR)
  157453. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  157454. SIZEOF(ODITHER_MATRIX));
  157455. den = 2 * ODITHER_CELLS * ((INT32) (ncolors - 1));
  157456. for (j = 0; j < ODITHER_SIZE; j++) {
  157457. for (k = 0; k < ODITHER_SIZE; k++) {
  157458. num = ((INT32) (ODITHER_CELLS-1 - 2*((int)base_dither_matrix[j][k])))
  157459. * MAXJSAMPLE;
  157460. odither[j][k] = (int) (num<0 ? -((-num)/den) : num/den);
  157461. }
  157462. }
  157463. return odither;
  157464. }
  157465. LOCAL(void)
  157466. create_odither_tables (j_decompress_ptr cinfo)
  157467. {
  157468. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157469. ODITHER_MATRIX_PTR odither;
  157470. int i, j, nci;
  157471. for (i = 0; i < cinfo->out_color_components; i++) {
  157472. nci = cquantize->Ncolors[i]; /* # of distinct values for this color */
  157473. odither = NULL; /* search for matching prior component */
  157474. for (j = 0; j < i; j++) {
  157475. if (nci == cquantize->Ncolors[j]) {
  157476. odither = cquantize->odither[j];
  157477. break;
  157478. }
  157479. }
  157480. if (odither == NULL) /* need a new table? */
  157481. odither = make_odither_array(cinfo, nci);
  157482. cquantize->odither[i] = odither;
  157483. }
  157484. }
  157485. METHODDEF(void)
  157486. color_quantize (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157487. JSAMPARRAY output_buf, int num_rows)
  157488. {
  157489. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157490. JSAMPARRAY colorindex = cquantize->colorindex;
  157491. register int pixcode, ci;
  157492. register JSAMPROW ptrin, ptrout;
  157493. int row;
  157494. JDIMENSION col;
  157495. JDIMENSION width = cinfo->output_width;
  157496. register int nc = cinfo->out_color_components;
  157497. for (row = 0; row < num_rows; row++) {
  157498. ptrin = input_buf[row];
  157499. ptrout = output_buf[row];
  157500. for (col = width; col > 0; col--) {
  157501. pixcode = 0;
  157502. for (ci = 0; ci < nc; ci++) {
  157503. pixcode += GETJSAMPLE(colorindex[ci][GETJSAMPLE(*ptrin++)]);
  157504. }
  157505. *ptrout++ = (JSAMPLE) pixcode;
  157506. }
  157507. }
  157508. }
  157509. METHODDEF(void)
  157510. color_quantize3 (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157511. JSAMPARRAY output_buf, int num_rows)
  157512. {
  157513. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157514. register int pixcode;
  157515. register JSAMPROW ptrin, ptrout;
  157516. JSAMPROW colorindex0 = cquantize->colorindex[0];
  157517. JSAMPROW colorindex1 = cquantize->colorindex[1];
  157518. JSAMPROW colorindex2 = cquantize->colorindex[2];
  157519. int row;
  157520. JDIMENSION col;
  157521. JDIMENSION width = cinfo->output_width;
  157522. for (row = 0; row < num_rows; row++) {
  157523. ptrin = input_buf[row];
  157524. ptrout = output_buf[row];
  157525. for (col = width; col > 0; col--) {
  157526. pixcode = GETJSAMPLE(colorindex0[GETJSAMPLE(*ptrin++)]);
  157527. pixcode += GETJSAMPLE(colorindex1[GETJSAMPLE(*ptrin++)]);
  157528. pixcode += GETJSAMPLE(colorindex2[GETJSAMPLE(*ptrin++)]);
  157529. *ptrout++ = (JSAMPLE) pixcode;
  157530. }
  157531. }
  157532. }
  157533. METHODDEF(void)
  157534. quantize_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157535. JSAMPARRAY output_buf, int num_rows)
  157536. {
  157537. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157538. register JSAMPROW input_ptr;
  157539. register JSAMPROW output_ptr;
  157540. JSAMPROW colorindex_ci;
  157541. int * dither; /* points to active row of dither matrix */
  157542. int row_index, col_index; /* current indexes into dither matrix */
  157543. int nc = cinfo->out_color_components;
  157544. int ci;
  157545. int row;
  157546. JDIMENSION col;
  157547. JDIMENSION width = cinfo->output_width;
  157548. for (row = 0; row < num_rows; row++) {
  157549. jzero_far((void FAR *) output_buf[row],
  157550. (size_t) (width * SIZEOF(JSAMPLE)));
  157551. row_index = cquantize->row_index;
  157552. for (ci = 0; ci < nc; ci++) {
  157553. input_ptr = input_buf[row] + ci;
  157554. output_ptr = output_buf[row];
  157555. colorindex_ci = cquantize->colorindex[ci];
  157556. dither = cquantize->odither[ci][row_index];
  157557. col_index = 0;
  157558. for (col = width; col > 0; col--) {
  157559. *output_ptr += colorindex_ci[GETJSAMPLE(*input_ptr)+dither[col_index]];
  157560. input_ptr += nc;
  157561. output_ptr++;
  157562. col_index = (col_index + 1) & ODITHER_MASK;
  157563. }
  157564. }
  157565. row_index = (row_index + 1) & ODITHER_MASK;
  157566. cquantize->row_index = row_index;
  157567. }
  157568. }
  157569. METHODDEF(void)
  157570. quantize3_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157571. JSAMPARRAY output_buf, int num_rows)
  157572. {
  157573. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157574. register int pixcode;
  157575. register JSAMPROW input_ptr;
  157576. register JSAMPROW output_ptr;
  157577. JSAMPROW colorindex0 = cquantize->colorindex[0];
  157578. JSAMPROW colorindex1 = cquantize->colorindex[1];
  157579. JSAMPROW colorindex2 = cquantize->colorindex[2];
  157580. int * dither0; /* points to active row of dither matrix */
  157581. int * dither1;
  157582. int * dither2;
  157583. int row_index, col_index; /* current indexes into dither matrix */
  157584. int row;
  157585. JDIMENSION col;
  157586. JDIMENSION width = cinfo->output_width;
  157587. for (row = 0; row < num_rows; row++) {
  157588. row_index = cquantize->row_index;
  157589. input_ptr = input_buf[row];
  157590. output_ptr = output_buf[row];
  157591. dither0 = cquantize->odither[0][row_index];
  157592. dither1 = cquantize->odither[1][row_index];
  157593. dither2 = cquantize->odither[2][row_index];
  157594. col_index = 0;
  157595. for (col = width; col > 0; col--) {
  157596. pixcode = GETJSAMPLE(colorindex0[GETJSAMPLE(*input_ptr++) +
  157597. dither0[col_index]]);
  157598. pixcode += GETJSAMPLE(colorindex1[GETJSAMPLE(*input_ptr++) +
  157599. dither1[col_index]]);
  157600. pixcode += GETJSAMPLE(colorindex2[GETJSAMPLE(*input_ptr++) +
  157601. dither2[col_index]]);
  157602. *output_ptr++ = (JSAMPLE) pixcode;
  157603. col_index = (col_index + 1) & ODITHER_MASK;
  157604. }
  157605. row_index = (row_index + 1) & ODITHER_MASK;
  157606. cquantize->row_index = row_index;
  157607. }
  157608. }
  157609. METHODDEF(void)
  157610. quantize_fs_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157611. JSAMPARRAY output_buf, int num_rows)
  157612. {
  157613. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157614. register LOCFSERROR cur; /* current error or pixel value */
  157615. LOCFSERROR belowerr; /* error for pixel below cur */
  157616. LOCFSERROR bpreverr; /* error for below/prev col */
  157617. LOCFSERROR bnexterr; /* error for below/next col */
  157618. LOCFSERROR delta;
  157619. register FSERRPTR errorptr; /* => fserrors[] at column before current */
  157620. register JSAMPROW input_ptr;
  157621. register JSAMPROW output_ptr;
  157622. JSAMPROW colorindex_ci;
  157623. JSAMPROW colormap_ci;
  157624. int pixcode;
  157625. int nc = cinfo->out_color_components;
  157626. int dir; /* 1 for left-to-right, -1 for right-to-left */
  157627. int dirnc; /* dir * nc */
  157628. int ci;
  157629. int row;
  157630. JDIMENSION col;
  157631. JDIMENSION width = cinfo->output_width;
  157632. JSAMPLE *range_limit = cinfo->sample_range_limit;
  157633. SHIFT_TEMPS
  157634. for (row = 0; row < num_rows; row++) {
  157635. jzero_far((void FAR *) output_buf[row],
  157636. (size_t) (width * SIZEOF(JSAMPLE)));
  157637. for (ci = 0; ci < nc; ci++) {
  157638. input_ptr = input_buf[row] + ci;
  157639. output_ptr = output_buf[row];
  157640. if (cquantize->on_odd_row) {
  157641. input_ptr += (width-1) * nc; /* so point to rightmost pixel */
  157642. output_ptr += width-1;
  157643. dir = -1;
  157644. dirnc = -nc;
  157645. errorptr = cquantize->fserrors[ci] + (width+1); /* => entry after last column */
  157646. } else {
  157647. dir = 1;
  157648. dirnc = nc;
  157649. errorptr = cquantize->fserrors[ci]; /* => entry before first column */
  157650. }
  157651. colorindex_ci = cquantize->colorindex[ci];
  157652. colormap_ci = cquantize->sv_colormap[ci];
  157653. cur = 0;
  157654. belowerr = bpreverr = 0;
  157655. for (col = width; col > 0; col--) {
  157656. cur = RIGHT_SHIFT(cur + errorptr[dir] + 8, 4);
  157657. cur += GETJSAMPLE(*input_ptr);
  157658. cur = GETJSAMPLE(range_limit[cur]);
  157659. pixcode = GETJSAMPLE(colorindex_ci[cur]);
  157660. *output_ptr += (JSAMPLE) pixcode;
  157661. cur -= GETJSAMPLE(colormap_ci[pixcode]);
  157662. bnexterr = cur;
  157663. delta = cur * 2;
  157664. cur += delta; /* form error * 3 */
  157665. errorptr[0] = (FSERROR) (bpreverr + cur);
  157666. cur += delta; /* form error * 5 */
  157667. bpreverr = belowerr + cur;
  157668. belowerr = bnexterr;
  157669. cur += delta; /* form error * 7 */
  157670. input_ptr += dirnc; /* advance input ptr to next column */
  157671. output_ptr += dir; /* advance output ptr to next column */
  157672. errorptr += dir; /* advance errorptr to current column */
  157673. }
  157674. errorptr[0] = (FSERROR) bpreverr; /* unload prev err into array */
  157675. }
  157676. cquantize->on_odd_row = (cquantize->on_odd_row ? FALSE : TRUE);
  157677. }
  157678. }
  157679. LOCAL(void)
  157680. alloc_fs_workspace (j_decompress_ptr cinfo)
  157681. {
  157682. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157683. size_t arraysize;
  157684. int i;
  157685. arraysize = (size_t) ((cinfo->output_width + 2) * SIZEOF(FSERROR));
  157686. for (i = 0; i < cinfo->out_color_components; i++) {
  157687. cquantize->fserrors[i] = (FSERRPTR)
  157688. (*cinfo->mem->alloc_large)((j_common_ptr) cinfo, JPOOL_IMAGE, arraysize);
  157689. }
  157690. }
  157691. METHODDEF(void)
  157692. start_pass_1_quant (j_decompress_ptr cinfo, boolean is_pre_scan)
  157693. {
  157694. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157695. size_t arraysize;
  157696. int i;
  157697. cinfo->colormap = cquantize->sv_colormap;
  157698. cinfo->actual_number_of_colors = cquantize->sv_actual;
  157699. switch (cinfo->dither_mode) {
  157700. case JDITHER_NONE:
  157701. if (cinfo->out_color_components == 3)
  157702. cquantize->pub.color_quantize = color_quantize3;
  157703. else
  157704. cquantize->pub.color_quantize = color_quantize;
  157705. break;
  157706. case JDITHER_ORDERED:
  157707. if (cinfo->out_color_components == 3)
  157708. cquantize->pub.color_quantize = quantize3_ord_dither;
  157709. else
  157710. cquantize->pub.color_quantize = quantize_ord_dither;
  157711. cquantize->row_index = 0; /* initialize state for ordered dither */
  157712. if (! cquantize->is_padded)
  157713. create_colorindex(cinfo);
  157714. if (cquantize->odither[0] == NULL)
  157715. create_odither_tables(cinfo);
  157716. break;
  157717. case JDITHER_FS:
  157718. cquantize->pub.color_quantize = quantize_fs_dither;
  157719. cquantize->on_odd_row = FALSE; /* initialize state for F-S dither */
  157720. if (cquantize->fserrors[0] == NULL)
  157721. alloc_fs_workspace(cinfo);
  157722. arraysize = (size_t) ((cinfo->output_width + 2) * SIZEOF(FSERROR));
  157723. for (i = 0; i < cinfo->out_color_components; i++)
  157724. jzero_far((void FAR *) cquantize->fserrors[i], arraysize);
  157725. break;
  157726. default:
  157727. ERREXIT(cinfo, JERR_NOT_COMPILED);
  157728. break;
  157729. }
  157730. }
  157731. METHODDEF(void)
  157732. finish_pass_1_quant (j_decompress_ptr cinfo)
  157733. {
  157734. }
  157735. METHODDEF(void)
  157736. new_color_map_1_quant (j_decompress_ptr cinfo)
  157737. {
  157738. ERREXIT(cinfo, JERR_MODE_CHANGE);
  157739. }
  157740. GLOBAL(void)
  157741. jinit_1pass_quantizer (j_decompress_ptr cinfo)
  157742. {
  157743. my_cquantize_ptr cquantize;
  157744. cquantize = (my_cquantize_ptr)
  157745. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  157746. SIZEOF(my_cquantizer));
  157747. cinfo->cquantize = (struct jpeg_color_quantizer *) cquantize;
  157748. cquantize->pub.start_pass = start_pass_1_quant;
  157749. cquantize->pub.finish_pass = finish_pass_1_quant;
  157750. cquantize->pub.new_color_map = new_color_map_1_quant;
  157751. cquantize->fserrors[0] = NULL; /* Flag FS workspace not allocated */
  157752. cquantize->odither[0] = NULL; /* Also flag odither arrays not allocated */
  157753. if (cinfo->out_color_components > MAX_Q_COMPS)
  157754. ERREXIT1(cinfo, JERR_QUANT_COMPONENTS, MAX_Q_COMPS);
  157755. if (cinfo->desired_number_of_colors > (MAXJSAMPLE+1))
  157756. ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXJSAMPLE+1);
  157757. create_colormap(cinfo);
  157758. create_colorindex(cinfo);
  157759. if (cinfo->dither_mode == JDITHER_FS)
  157760. alloc_fs_workspace(cinfo);
  157761. }
  157762. #endif /* QUANT_1PASS_SUPPORTED */
  157763. /*** End of inlined file: jquant1.c ***/
  157764. /*** Start of inlined file: jquant2.c ***/
  157765. #define JPEG_INTERNALS
  157766. #ifdef QUANT_2PASS_SUPPORTED
  157767. #define R_SCALE 2 /* scale R distances by this much */
  157768. #define G_SCALE 3 /* scale G distances by this much */
  157769. #define B_SCALE 1 /* and B by this much */
  157770. #if RGB_RED == 0
  157771. #define C0_SCALE R_SCALE
  157772. #endif
  157773. #if RGB_BLUE == 0
  157774. #define C0_SCALE B_SCALE
  157775. #endif
  157776. #if RGB_GREEN == 1
  157777. #define C1_SCALE G_SCALE
  157778. #endif
  157779. #if RGB_RED == 2
  157780. #define C2_SCALE R_SCALE
  157781. #endif
  157782. #if RGB_BLUE == 2
  157783. #define C2_SCALE B_SCALE
  157784. #endif
  157785. #define MAXNUMCOLORS (MAXJSAMPLE+1) /* maximum size of colormap */
  157786. #define HIST_C0_BITS 5 /* bits of precision in R/B histogram */
  157787. #define HIST_C1_BITS 6 /* bits of precision in G histogram */
  157788. #define HIST_C2_BITS 5 /* bits of precision in B/R histogram */
  157789. #define HIST_C0_ELEMS (1<<HIST_C0_BITS)
  157790. #define HIST_C1_ELEMS (1<<HIST_C1_BITS)
  157791. #define HIST_C2_ELEMS (1<<HIST_C2_BITS)
  157792. #define C0_SHIFT (BITS_IN_JSAMPLE-HIST_C0_BITS)
  157793. #define C1_SHIFT (BITS_IN_JSAMPLE-HIST_C1_BITS)
  157794. #define C2_SHIFT (BITS_IN_JSAMPLE-HIST_C2_BITS)
  157795. typedef UINT16 histcell; /* histogram cell; prefer an unsigned type */
  157796. typedef histcell FAR * histptr; /* for pointers to histogram cells */
  157797. typedef histcell hist1d[HIST_C2_ELEMS]; /* typedefs for the array */
  157798. typedef hist1d FAR * hist2d; /* type for the 2nd-level pointers */
  157799. typedef hist2d * hist3d; /* type for top-level pointer */
  157800. #if BITS_IN_JSAMPLE == 8
  157801. typedef INT16 FSERROR; /* 16 bits should be enough */
  157802. typedef int LOCFSERROR; /* use 'int' for calculation temps */
  157803. #else
  157804. typedef INT32 FSERROR; /* may need more than 16 bits */
  157805. typedef INT32 LOCFSERROR; /* be sure calculation temps are big enough */
  157806. #endif
  157807. typedef FSERROR FAR *FSERRPTR; /* pointer to error array (in FAR storage!) */
  157808. typedef struct {
  157809. struct jpeg_color_quantizer pub; /* public fields */
  157810. JSAMPARRAY sv_colormap; /* colormap allocated at init time */
  157811. int desired; /* desired # of colors = size of colormap */
  157812. hist3d histogram; /* pointer to the histogram */
  157813. boolean needs_zeroed; /* TRUE if next pass must zero histogram */
  157814. FSERRPTR fserrors; /* accumulated errors */
  157815. boolean on_odd_row; /* flag to remember which row we are on */
  157816. int * error_limiter; /* table for clamping the applied error */
  157817. } my_cquantizer2;
  157818. typedef my_cquantizer2 * my_cquantize_ptr2;
  157819. METHODDEF(void)
  157820. prescan_quantize (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157821. JSAMPARRAY output_buf, int num_rows)
  157822. {
  157823. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157824. register JSAMPROW ptr;
  157825. register histptr histp;
  157826. register hist3d histogram = cquantize->histogram;
  157827. int row;
  157828. JDIMENSION col;
  157829. JDIMENSION width = cinfo->output_width;
  157830. for (row = 0; row < num_rows; row++) {
  157831. ptr = input_buf[row];
  157832. for (col = width; col > 0; col--) {
  157833. histp = & histogram[GETJSAMPLE(ptr[0]) >> C0_SHIFT]
  157834. [GETJSAMPLE(ptr[1]) >> C1_SHIFT]
  157835. [GETJSAMPLE(ptr[2]) >> C2_SHIFT];
  157836. if (++(*histp) <= 0)
  157837. (*histp)--;
  157838. ptr += 3;
  157839. }
  157840. }
  157841. }
  157842. typedef struct {
  157843. int c0min, c0max;
  157844. int c1min, c1max;
  157845. int c2min, c2max;
  157846. INT32 volume;
  157847. long colorcount;
  157848. } box;
  157849. typedef box * boxptr;
  157850. LOCAL(boxptr)
  157851. find_biggest_color_pop (boxptr boxlist, int numboxes)
  157852. {
  157853. register boxptr boxp;
  157854. register int i;
  157855. register long maxc = 0;
  157856. boxptr which = NULL;
  157857. for (i = 0, boxp = boxlist; i < numboxes; i++, boxp++) {
  157858. if (boxp->colorcount > maxc && boxp->volume > 0) {
  157859. which = boxp;
  157860. maxc = boxp->colorcount;
  157861. }
  157862. }
  157863. return which;
  157864. }
  157865. LOCAL(boxptr)
  157866. find_biggest_volume (boxptr boxlist, int numboxes)
  157867. {
  157868. register boxptr boxp;
  157869. register int i;
  157870. register INT32 maxv = 0;
  157871. boxptr which = NULL;
  157872. for (i = 0, boxp = boxlist; i < numboxes; i++, boxp++) {
  157873. if (boxp->volume > maxv) {
  157874. which = boxp;
  157875. maxv = boxp->volume;
  157876. }
  157877. }
  157878. return which;
  157879. }
  157880. LOCAL(void)
  157881. update_box (j_decompress_ptr cinfo, boxptr boxp)
  157882. {
  157883. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157884. hist3d histogram = cquantize->histogram;
  157885. histptr histp;
  157886. int c0,c1,c2;
  157887. int c0min,c0max,c1min,c1max,c2min,c2max;
  157888. INT32 dist0,dist1,dist2;
  157889. long ccount;
  157890. c0min = boxp->c0min; c0max = boxp->c0max;
  157891. c1min = boxp->c1min; c1max = boxp->c1max;
  157892. c2min = boxp->c2min; c2max = boxp->c2max;
  157893. if (c0max > c0min)
  157894. for (c0 = c0min; c0 <= c0max; c0++)
  157895. for (c1 = c1min; c1 <= c1max; c1++) {
  157896. histp = & histogram[c0][c1][c2min];
  157897. for (c2 = c2min; c2 <= c2max; c2++)
  157898. if (*histp++ != 0) {
  157899. boxp->c0min = c0min = c0;
  157900. goto have_c0min;
  157901. }
  157902. }
  157903. have_c0min:
  157904. if (c0max > c0min)
  157905. for (c0 = c0max; c0 >= c0min; c0--)
  157906. for (c1 = c1min; c1 <= c1max; c1++) {
  157907. histp = & histogram[c0][c1][c2min];
  157908. for (c2 = c2min; c2 <= c2max; c2++)
  157909. if (*histp++ != 0) {
  157910. boxp->c0max = c0max = c0;
  157911. goto have_c0max;
  157912. }
  157913. }
  157914. have_c0max:
  157915. if (c1max > c1min)
  157916. for (c1 = c1min; c1 <= c1max; c1++)
  157917. for (c0 = c0min; c0 <= c0max; c0++) {
  157918. histp = & histogram[c0][c1][c2min];
  157919. for (c2 = c2min; c2 <= c2max; c2++)
  157920. if (*histp++ != 0) {
  157921. boxp->c1min = c1min = c1;
  157922. goto have_c1min;
  157923. }
  157924. }
  157925. have_c1min:
  157926. if (c1max > c1min)
  157927. for (c1 = c1max; c1 >= c1min; c1--)
  157928. for (c0 = c0min; c0 <= c0max; c0++) {
  157929. histp = & histogram[c0][c1][c2min];
  157930. for (c2 = c2min; c2 <= c2max; c2++)
  157931. if (*histp++ != 0) {
  157932. boxp->c1max = c1max = c1;
  157933. goto have_c1max;
  157934. }
  157935. }
  157936. have_c1max:
  157937. if (c2max > c2min)
  157938. for (c2 = c2min; c2 <= c2max; c2++)
  157939. for (c0 = c0min; c0 <= c0max; c0++) {
  157940. histp = & histogram[c0][c1min][c2];
  157941. for (c1 = c1min; c1 <= c1max; c1++, histp += HIST_C2_ELEMS)
  157942. if (*histp != 0) {
  157943. boxp->c2min = c2min = c2;
  157944. goto have_c2min;
  157945. }
  157946. }
  157947. have_c2min:
  157948. if (c2max > c2min)
  157949. for (c2 = c2max; c2 >= c2min; c2--)
  157950. for (c0 = c0min; c0 <= c0max; c0++) {
  157951. histp = & histogram[c0][c1min][c2];
  157952. for (c1 = c1min; c1 <= c1max; c1++, histp += HIST_C2_ELEMS)
  157953. if (*histp != 0) {
  157954. boxp->c2max = c2max = c2;
  157955. goto have_c2max;
  157956. }
  157957. }
  157958. have_c2max:
  157959. dist0 = ((c0max - c0min) << C0_SHIFT) * C0_SCALE;
  157960. dist1 = ((c1max - c1min) << C1_SHIFT) * C1_SCALE;
  157961. dist2 = ((c2max - c2min) << C2_SHIFT) * C2_SCALE;
  157962. boxp->volume = dist0*dist0 + dist1*dist1 + dist2*dist2;
  157963. ccount = 0;
  157964. for (c0 = c0min; c0 <= c0max; c0++)
  157965. for (c1 = c1min; c1 <= c1max; c1++) {
  157966. histp = & histogram[c0][c1][c2min];
  157967. for (c2 = c2min; c2 <= c2max; c2++, histp++)
  157968. if (*histp != 0) {
  157969. ccount++;
  157970. }
  157971. }
  157972. boxp->colorcount = ccount;
  157973. }
  157974. LOCAL(int)
  157975. median_cut (j_decompress_ptr cinfo, boxptr boxlist, int numboxes,
  157976. int desired_colors)
  157977. {
  157978. int n,lb;
  157979. int c0,c1,c2,cmax;
  157980. register boxptr b1,b2;
  157981. while (numboxes < desired_colors) {
  157982. if (numboxes*2 <= desired_colors) {
  157983. b1 = find_biggest_color_pop(boxlist, numboxes);
  157984. } else {
  157985. b1 = find_biggest_volume(boxlist, numboxes);
  157986. }
  157987. if (b1 == NULL) /* no splittable boxes left! */
  157988. break;
  157989. b2 = &boxlist[numboxes]; /* where new box will go */
  157990. b2->c0max = b1->c0max; b2->c1max = b1->c1max; b2->c2max = b1->c2max;
  157991. b2->c0min = b1->c0min; b2->c1min = b1->c1min; b2->c2min = b1->c2min;
  157992. c0 = ((b1->c0max - b1->c0min) << C0_SHIFT) * C0_SCALE;
  157993. c1 = ((b1->c1max - b1->c1min) << C1_SHIFT) * C1_SCALE;
  157994. c2 = ((b1->c2max - b1->c2min) << C2_SHIFT) * C2_SCALE;
  157995. #if RGB_RED == 0
  157996. cmax = c1; n = 1;
  157997. if (c0 > cmax) { cmax = c0; n = 0; }
  157998. if (c2 > cmax) { n = 2; }
  157999. #else
  158000. cmax = c1; n = 1;
  158001. if (c2 > cmax) { cmax = c2; n = 2; }
  158002. if (c0 > cmax) { n = 0; }
  158003. #endif
  158004. switch (n) {
  158005. case 0:
  158006. lb = (b1->c0max + b1->c0min) / 2;
  158007. b1->c0max = lb;
  158008. b2->c0min = lb+1;
  158009. break;
  158010. case 1:
  158011. lb = (b1->c1max + b1->c1min) / 2;
  158012. b1->c1max = lb;
  158013. b2->c1min = lb+1;
  158014. break;
  158015. case 2:
  158016. lb = (b1->c2max + b1->c2min) / 2;
  158017. b1->c2max = lb;
  158018. b2->c2min = lb+1;
  158019. break;
  158020. }
  158021. update_box(cinfo, b1);
  158022. update_box(cinfo, b2);
  158023. numboxes++;
  158024. }
  158025. return numboxes;
  158026. }
  158027. LOCAL(void)
  158028. compute_color (j_decompress_ptr cinfo, boxptr boxp, int icolor)
  158029. {
  158030. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  158031. hist3d histogram = cquantize->histogram;
  158032. histptr histp;
  158033. int c0,c1,c2;
  158034. int c0min,c0max,c1min,c1max,c2min,c2max;
  158035. long count;
  158036. long total = 0;
  158037. long c0total = 0;
  158038. long c1total = 0;
  158039. long c2total = 0;
  158040. c0min = boxp->c0min; c0max = boxp->c0max;
  158041. c1min = boxp->c1min; c1max = boxp->c1max;
  158042. c2min = boxp->c2min; c2max = boxp->c2max;
  158043. for (c0 = c0min; c0 <= c0max; c0++)
  158044. for (c1 = c1min; c1 <= c1max; c1++) {
  158045. histp = & histogram[c0][c1][c2min];
  158046. for (c2 = c2min; c2 <= c2max; c2++) {
  158047. if ((count = *histp++) != 0) {
  158048. total += count;
  158049. c0total += ((c0 << C0_SHIFT) + ((1<<C0_SHIFT)>>1)) * count;
  158050. c1total += ((c1 << C1_SHIFT) + ((1<<C1_SHIFT)>>1)) * count;
  158051. c2total += ((c2 << C2_SHIFT) + ((1<<C2_SHIFT)>>1)) * count;
  158052. }
  158053. }
  158054. }
  158055. cinfo->colormap[0][icolor] = (JSAMPLE) ((c0total + (total>>1)) / total);
  158056. cinfo->colormap[1][icolor] = (JSAMPLE) ((c1total + (total>>1)) / total);
  158057. cinfo->colormap[2][icolor] = (JSAMPLE) ((c2total + (total>>1)) / total);
  158058. }
  158059. LOCAL(void)
  158060. select_colors (j_decompress_ptr cinfo, int desired_colors)
  158061. {
  158062. boxptr boxlist;
  158063. int numboxes;
  158064. int i;
  158065. boxlist = (boxptr) (*cinfo->mem->alloc_small)
  158066. ((j_common_ptr) cinfo, JPOOL_IMAGE, desired_colors * SIZEOF(box));
  158067. numboxes = 1;
  158068. boxlist[0].c0min = 0;
  158069. boxlist[0].c0max = MAXJSAMPLE >> C0_SHIFT;
  158070. boxlist[0].c1min = 0;
  158071. boxlist[0].c1max = MAXJSAMPLE >> C1_SHIFT;
  158072. boxlist[0].c2min = 0;
  158073. boxlist[0].c2max = MAXJSAMPLE >> C2_SHIFT;
  158074. update_box(cinfo, & boxlist[0]);
  158075. numboxes = median_cut(cinfo, boxlist, numboxes, desired_colors);
  158076. for (i = 0; i < numboxes; i++)
  158077. compute_color(cinfo, & boxlist[i], i);
  158078. cinfo->actual_number_of_colors = numboxes;
  158079. TRACEMS1(cinfo, 1, JTRC_QUANT_SELECTED, numboxes);
  158080. }
  158081. #define BOX_C0_LOG (HIST_C0_BITS-3)
  158082. #define BOX_C1_LOG (HIST_C1_BITS-3)
  158083. #define BOX_C2_LOG (HIST_C2_BITS-3)
  158084. #define BOX_C0_ELEMS (1<<BOX_C0_LOG) /* # of hist cells in update box */
  158085. #define BOX_C1_ELEMS (1<<BOX_C1_LOG)
  158086. #define BOX_C2_ELEMS (1<<BOX_C2_LOG)
  158087. #define BOX_C0_SHIFT (C0_SHIFT + BOX_C0_LOG)
  158088. #define BOX_C1_SHIFT (C1_SHIFT + BOX_C1_LOG)
  158089. #define BOX_C2_SHIFT (C2_SHIFT + BOX_C2_LOG)
  158090. LOCAL(int)
  158091. find_nearby_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
  158092. JSAMPLE colorlist[])
  158093. {
  158094. int numcolors = cinfo->actual_number_of_colors;
  158095. int maxc0, maxc1, maxc2;
  158096. int centerc0, centerc1, centerc2;
  158097. int i, x, ncolors;
  158098. INT32 minmaxdist, min_dist, max_dist, tdist;
  158099. INT32 mindist[MAXNUMCOLORS]; /* min distance to colormap entry i */
  158100. maxc0 = minc0 + ((1 << BOX_C0_SHIFT) - (1 << C0_SHIFT));
  158101. centerc0 = (minc0 + maxc0) >> 1;
  158102. maxc1 = minc1 + ((1 << BOX_C1_SHIFT) - (1 << C1_SHIFT));
  158103. centerc1 = (minc1 + maxc1) >> 1;
  158104. maxc2 = minc2 + ((1 << BOX_C2_SHIFT) - (1 << C2_SHIFT));
  158105. centerc2 = (minc2 + maxc2) >> 1;
  158106. minmaxdist = 0x7FFFFFFFL;
  158107. for (i = 0; i < numcolors; i++) {
  158108. x = GETJSAMPLE(cinfo->colormap[0][i]);
  158109. if (x < minc0) {
  158110. tdist = (x - minc0) * C0_SCALE;
  158111. min_dist = tdist*tdist;
  158112. tdist = (x - maxc0) * C0_SCALE;
  158113. max_dist = tdist*tdist;
  158114. } else if (x > maxc0) {
  158115. tdist = (x - maxc0) * C0_SCALE;
  158116. min_dist = tdist*tdist;
  158117. tdist = (x - minc0) * C0_SCALE;
  158118. max_dist = tdist*tdist;
  158119. } else {
  158120. min_dist = 0;
  158121. if (x <= centerc0) {
  158122. tdist = (x - maxc0) * C0_SCALE;
  158123. max_dist = tdist*tdist;
  158124. } else {
  158125. tdist = (x - minc0) * C0_SCALE;
  158126. max_dist = tdist*tdist;
  158127. }
  158128. }
  158129. x = GETJSAMPLE(cinfo->colormap[1][i]);
  158130. if (x < minc1) {
  158131. tdist = (x - minc1) * C1_SCALE;
  158132. min_dist += tdist*tdist;
  158133. tdist = (x - maxc1) * C1_SCALE;
  158134. max_dist += tdist*tdist;
  158135. } else if (x > maxc1) {
  158136. tdist = (x - maxc1) * C1_SCALE;
  158137. min_dist += tdist*tdist;
  158138. tdist = (x - minc1) * C1_SCALE;
  158139. max_dist += tdist*tdist;
  158140. } else {
  158141. if (x <= centerc1) {
  158142. tdist = (x - maxc1) * C1_SCALE;
  158143. max_dist += tdist*tdist;
  158144. } else {
  158145. tdist = (x - minc1) * C1_SCALE;
  158146. max_dist += tdist*tdist;
  158147. }
  158148. }
  158149. x = GETJSAMPLE(cinfo->colormap[2][i]);
  158150. if (x < minc2) {
  158151. tdist = (x - minc2) * C2_SCALE;
  158152. min_dist += tdist*tdist;
  158153. tdist = (x - maxc2) * C2_SCALE;
  158154. max_dist += tdist*tdist;
  158155. } else if (x > maxc2) {
  158156. tdist = (x - maxc2) * C2_SCALE;
  158157. min_dist += tdist*tdist;
  158158. tdist = (x - minc2) * C2_SCALE;
  158159. max_dist += tdist*tdist;
  158160. } else {
  158161. if (x <= centerc2) {
  158162. tdist = (x - maxc2) * C2_SCALE;
  158163. max_dist += tdist*tdist;
  158164. } else {
  158165. tdist = (x - minc2) * C2_SCALE;
  158166. max_dist += tdist*tdist;
  158167. }
  158168. }
  158169. mindist[i] = min_dist; /* save away the results */
  158170. if (max_dist < minmaxdist)
  158171. minmaxdist = max_dist;
  158172. }
  158173. ncolors = 0;
  158174. for (i = 0; i < numcolors; i++) {
  158175. if (mindist[i] <= minmaxdist)
  158176. colorlist[ncolors++] = (JSAMPLE) i;
  158177. }
  158178. return ncolors;
  158179. }
  158180. LOCAL(void)
  158181. find_best_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
  158182. int numcolors, JSAMPLE colorlist[], JSAMPLE bestcolor[])
  158183. {
  158184. int ic0, ic1, ic2;
  158185. int i, icolor;
  158186. register INT32 * bptr; /* pointer into bestdist[] array */
  158187. JSAMPLE * cptr; /* pointer into bestcolor[] array */
  158188. INT32 dist0, dist1; /* initial distance values */
  158189. register INT32 dist2; /* current distance in inner loop */
  158190. INT32 xx0, xx1; /* distance increments */
  158191. register INT32 xx2;
  158192. INT32 inc0, inc1, inc2; /* initial values for increments */
  158193. INT32 bestdist[BOX_C0_ELEMS * BOX_C1_ELEMS * BOX_C2_ELEMS];
  158194. bptr = bestdist;
  158195. for (i = BOX_C0_ELEMS*BOX_C1_ELEMS*BOX_C2_ELEMS-1; i >= 0; i--)
  158196. *bptr++ = 0x7FFFFFFFL;
  158197. #define STEP_C0 ((1 << C0_SHIFT) * C0_SCALE)
  158198. #define STEP_C1 ((1 << C1_SHIFT) * C1_SCALE)
  158199. #define STEP_C2 ((1 << C2_SHIFT) * C2_SCALE)
  158200. for (i = 0; i < numcolors; i++) {
  158201. icolor = GETJSAMPLE(colorlist[i]);
  158202. inc0 = (minc0 - GETJSAMPLE(cinfo->colormap[0][icolor])) * C0_SCALE;
  158203. dist0 = inc0*inc0;
  158204. inc1 = (minc1 - GETJSAMPLE(cinfo->colormap[1][icolor])) * C1_SCALE;
  158205. dist0 += inc1*inc1;
  158206. inc2 = (minc2 - GETJSAMPLE(cinfo->colormap[2][icolor])) * C2_SCALE;
  158207. dist0 += inc2*inc2;
  158208. inc0 = inc0 * (2 * STEP_C0) + STEP_C0 * STEP_C0;
  158209. inc1 = inc1 * (2 * STEP_C1) + STEP_C1 * STEP_C1;
  158210. inc2 = inc2 * (2 * STEP_C2) + STEP_C2 * STEP_C2;
  158211. bptr = bestdist;
  158212. cptr = bestcolor;
  158213. xx0 = inc0;
  158214. for (ic0 = BOX_C0_ELEMS-1; ic0 >= 0; ic0--) {
  158215. dist1 = dist0;
  158216. xx1 = inc1;
  158217. for (ic1 = BOX_C1_ELEMS-1; ic1 >= 0; ic1--) {
  158218. dist2 = dist1;
  158219. xx2 = inc2;
  158220. for (ic2 = BOX_C2_ELEMS-1; ic2 >= 0; ic2--) {
  158221. if (dist2 < *bptr) {
  158222. *bptr = dist2;
  158223. *cptr = (JSAMPLE) icolor;
  158224. }
  158225. dist2 += xx2;
  158226. xx2 += 2 * STEP_C2 * STEP_C2;
  158227. bptr++;
  158228. cptr++;
  158229. }
  158230. dist1 += xx1;
  158231. xx1 += 2 * STEP_C1 * STEP_C1;
  158232. }
  158233. dist0 += xx0;
  158234. xx0 += 2 * STEP_C0 * STEP_C0;
  158235. }
  158236. }
  158237. }
  158238. LOCAL(void)
  158239. fill_inverse_cmap (j_decompress_ptr cinfo, int c0, int c1, int c2)
  158240. {
  158241. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  158242. hist3d histogram = cquantize->histogram;
  158243. int minc0, minc1, minc2; /* lower left corner of update box */
  158244. int ic0, ic1, ic2;
  158245. register JSAMPLE * cptr; /* pointer into bestcolor[] array */
  158246. register histptr cachep; /* pointer into main cache array */
  158247. JSAMPLE colorlist[MAXNUMCOLORS];
  158248. int numcolors; /* number of candidate colors */
  158249. JSAMPLE bestcolor[BOX_C0_ELEMS * BOX_C1_ELEMS * BOX_C2_ELEMS];
  158250. c0 >>= BOX_C0_LOG;
  158251. c1 >>= BOX_C1_LOG;
  158252. c2 >>= BOX_C2_LOG;
  158253. minc0 = (c0 << BOX_C0_SHIFT) + ((1 << C0_SHIFT) >> 1);
  158254. minc1 = (c1 << BOX_C1_SHIFT) + ((1 << C1_SHIFT) >> 1);
  158255. minc2 = (c2 << BOX_C2_SHIFT) + ((1 << C2_SHIFT) >> 1);
  158256. numcolors = find_nearby_colors(cinfo, minc0, minc1, minc2, colorlist);
  158257. find_best_colors(cinfo, minc0, minc1, minc2, numcolors, colorlist,
  158258. bestcolor);
  158259. c0 <<= BOX_C0_LOG; /* convert ID back to base cell indexes */
  158260. c1 <<= BOX_C1_LOG;
  158261. c2 <<= BOX_C2_LOG;
  158262. cptr = bestcolor;
  158263. for (ic0 = 0; ic0 < BOX_C0_ELEMS; ic0++) {
  158264. for (ic1 = 0; ic1 < BOX_C1_ELEMS; ic1++) {
  158265. cachep = & histogram[c0+ic0][c1+ic1][c2];
  158266. for (ic2 = 0; ic2 < BOX_C2_ELEMS; ic2++) {
  158267. *cachep++ = (histcell) (GETJSAMPLE(*cptr++) + 1);
  158268. }
  158269. }
  158270. }
  158271. }
  158272. METHODDEF(void)
  158273. pass2_no_dither (j_decompress_ptr cinfo,
  158274. JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows)
  158275. {
  158276. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  158277. hist3d histogram = cquantize->histogram;
  158278. register JSAMPROW inptr, outptr;
  158279. register histptr cachep;
  158280. register int c0, c1, c2;
  158281. int row;
  158282. JDIMENSION col;
  158283. JDIMENSION width = cinfo->output_width;
  158284. for (row = 0; row < num_rows; row++) {
  158285. inptr = input_buf[row];
  158286. outptr = output_buf[row];
  158287. for (col = width; col > 0; col--) {
  158288. c0 = GETJSAMPLE(*inptr++) >> C0_SHIFT;
  158289. c1 = GETJSAMPLE(*inptr++) >> C1_SHIFT;
  158290. c2 = GETJSAMPLE(*inptr++) >> C2_SHIFT;
  158291. cachep = & histogram[c0][c1][c2];
  158292. if (*cachep == 0)
  158293. fill_inverse_cmap(cinfo, c0,c1,c2);
  158294. *outptr++ = (JSAMPLE) (*cachep - 1);
  158295. }
  158296. }
  158297. }
  158298. METHODDEF(void)
  158299. pass2_fs_dither (j_decompress_ptr cinfo,
  158300. JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows)
  158301. {
  158302. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  158303. hist3d histogram = cquantize->histogram;
  158304. register LOCFSERROR cur0, cur1, cur2; /* current error or pixel value */
  158305. LOCFSERROR belowerr0, belowerr1, belowerr2; /* error for pixel below cur */
  158306. LOCFSERROR bpreverr0, bpreverr1, bpreverr2; /* error for below/prev col */
  158307. register FSERRPTR errorptr; /* => fserrors[] at column before current */
  158308. JSAMPROW inptr; /* => current input pixel */
  158309. JSAMPROW outptr; /* => current output pixel */
  158310. histptr cachep;
  158311. int dir; /* +1 or -1 depending on direction */
  158312. int dir3; /* 3*dir, for advancing inptr & errorptr */
  158313. int row;
  158314. JDIMENSION col;
  158315. JDIMENSION width = cinfo->output_width;
  158316. JSAMPLE *range_limit = cinfo->sample_range_limit;
  158317. int *error_limit = cquantize->error_limiter;
  158318. JSAMPROW colormap0 = cinfo->colormap[0];
  158319. JSAMPROW colormap1 = cinfo->colormap[1];
  158320. JSAMPROW colormap2 = cinfo->colormap[2];
  158321. SHIFT_TEMPS
  158322. for (row = 0; row < num_rows; row++) {
  158323. inptr = input_buf[row];
  158324. outptr = output_buf[row];
  158325. if (cquantize->on_odd_row) {
  158326. inptr += (width-1) * 3; /* so point to rightmost pixel */
  158327. outptr += width-1;
  158328. dir = -1;
  158329. dir3 = -3;
  158330. errorptr = cquantize->fserrors + (width+1)*3; /* => entry after last column */
  158331. cquantize->on_odd_row = FALSE; /* flip for next time */
  158332. } else {
  158333. dir = 1;
  158334. dir3 = 3;
  158335. errorptr = cquantize->fserrors; /* => entry before first real column */
  158336. cquantize->on_odd_row = TRUE; /* flip for next time */
  158337. }
  158338. cur0 = cur1 = cur2 = 0;
  158339. belowerr0 = belowerr1 = belowerr2 = 0;
  158340. bpreverr0 = bpreverr1 = bpreverr2 = 0;
  158341. for (col = width; col > 0; col--) {
  158342. cur0 = RIGHT_SHIFT(cur0 + errorptr[dir3+0] + 8, 4);
  158343. cur1 = RIGHT_SHIFT(cur1 + errorptr[dir3+1] + 8, 4);
  158344. cur2 = RIGHT_SHIFT(cur2 + errorptr[dir3+2] + 8, 4);
  158345. cur0 = error_limit[cur0];
  158346. cur1 = error_limit[cur1];
  158347. cur2 = error_limit[cur2];
  158348. cur0 += GETJSAMPLE(inptr[0]);
  158349. cur1 += GETJSAMPLE(inptr[1]);
  158350. cur2 += GETJSAMPLE(inptr[2]);
  158351. cur0 = GETJSAMPLE(range_limit[cur0]);
  158352. cur1 = GETJSAMPLE(range_limit[cur1]);
  158353. cur2 = GETJSAMPLE(range_limit[cur2]);
  158354. cachep = & histogram[cur0>>C0_SHIFT][cur1>>C1_SHIFT][cur2>>C2_SHIFT];
  158355. if (*cachep == 0)
  158356. fill_inverse_cmap(cinfo, cur0>>C0_SHIFT,cur1>>C1_SHIFT,cur2>>C2_SHIFT);
  158357. { register int pixcode = *cachep - 1;
  158358. *outptr = (JSAMPLE) pixcode;
  158359. cur0 -= GETJSAMPLE(colormap0[pixcode]);
  158360. cur1 -= GETJSAMPLE(colormap1[pixcode]);
  158361. cur2 -= GETJSAMPLE(colormap2[pixcode]);
  158362. }
  158363. { register LOCFSERROR bnexterr, delta;
  158364. bnexterr = cur0; /* Process component 0 */
  158365. delta = cur0 * 2;
  158366. cur0 += delta; /* form error * 3 */
  158367. errorptr[0] = (FSERROR) (bpreverr0 + cur0);
  158368. cur0 += delta; /* form error * 5 */
  158369. bpreverr0 = belowerr0 + cur0;
  158370. belowerr0 = bnexterr;
  158371. cur0 += delta; /* form error * 7 */
  158372. bnexterr = cur1; /* Process component 1 */
  158373. delta = cur1 * 2;
  158374. cur1 += delta; /* form error * 3 */
  158375. errorptr[1] = (FSERROR) (bpreverr1 + cur1);
  158376. cur1 += delta; /* form error * 5 */
  158377. bpreverr1 = belowerr1 + cur1;
  158378. belowerr1 = bnexterr;
  158379. cur1 += delta; /* form error * 7 */
  158380. bnexterr = cur2; /* Process component 2 */
  158381. delta = cur2 * 2;
  158382. cur2 += delta; /* form error * 3 */
  158383. errorptr[2] = (FSERROR) (bpreverr2 + cur2);
  158384. cur2 += delta; /* form error * 5 */
  158385. bpreverr2 = belowerr2 + cur2;
  158386. belowerr2 = bnexterr;
  158387. cur2 += delta; /* form error * 7 */
  158388. }
  158389. inptr += dir3; /* Advance pixel pointers to next column */
  158390. outptr += dir;
  158391. errorptr += dir3; /* advance errorptr to current column */
  158392. }
  158393. errorptr[0] = (FSERROR) bpreverr0; /* unload prev errs into array */
  158394. errorptr[1] = (FSERROR) bpreverr1;
  158395. errorptr[2] = (FSERROR) bpreverr2;
  158396. }
  158397. }
  158398. LOCAL(void)
  158399. init_error_limit (j_decompress_ptr cinfo)
  158400. {
  158401. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  158402. int * table;
  158403. int in, out;
  158404. table = (int *) (*cinfo->mem->alloc_small)
  158405. ((j_common_ptr) cinfo, JPOOL_IMAGE, (MAXJSAMPLE*2+1) * SIZEOF(int));
  158406. table += MAXJSAMPLE; /* so can index -MAXJSAMPLE .. +MAXJSAMPLE */
  158407. cquantize->error_limiter = table;
  158408. #define STEPSIZE ((MAXJSAMPLE+1)/16)
  158409. out = 0;
  158410. for (in = 0; in < STEPSIZE; in++, out++) {
  158411. table[in] = out; table[-in] = -out;
  158412. }
  158413. for (; in < STEPSIZE*3; in++, out += (in&1) ? 0 : 1) {
  158414. table[in] = out; table[-in] = -out;
  158415. }
  158416. for (; in <= MAXJSAMPLE; in++) {
  158417. table[in] = out; table[-in] = -out;
  158418. }
  158419. #undef STEPSIZE
  158420. }
  158421. METHODDEF(void)
  158422. finish_pass1 (j_decompress_ptr cinfo)
  158423. {
  158424. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  158425. cinfo->colormap = cquantize->sv_colormap;
  158426. select_colors(cinfo, cquantize->desired);
  158427. cquantize->needs_zeroed = TRUE;
  158428. }
  158429. METHODDEF(void)
  158430. finish_pass2 (j_decompress_ptr cinfo)
  158431. {
  158432. }
  158433. METHODDEF(void)
  158434. start_pass_2_quant (j_decompress_ptr cinfo, boolean is_pre_scan)
  158435. {
  158436. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  158437. hist3d histogram = cquantize->histogram;
  158438. int i;
  158439. if (cinfo->dither_mode != JDITHER_NONE)
  158440. cinfo->dither_mode = JDITHER_FS;
  158441. if (is_pre_scan) {
  158442. cquantize->pub.color_quantize = prescan_quantize;
  158443. cquantize->pub.finish_pass = finish_pass1;
  158444. cquantize->needs_zeroed = TRUE; /* Always zero histogram */
  158445. } else {
  158446. if (cinfo->dither_mode == JDITHER_FS)
  158447. cquantize->pub.color_quantize = pass2_fs_dither;
  158448. else
  158449. cquantize->pub.color_quantize = pass2_no_dither;
  158450. cquantize->pub.finish_pass = finish_pass2;
  158451. i = cinfo->actual_number_of_colors;
  158452. if (i < 1)
  158453. ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, 1);
  158454. if (i > MAXNUMCOLORS)
  158455. ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXNUMCOLORS);
  158456. if (cinfo->dither_mode == JDITHER_FS) {
  158457. size_t arraysize = (size_t) ((cinfo->output_width + 2) *
  158458. (3 * SIZEOF(FSERROR)));
  158459. if (cquantize->fserrors == NULL)
  158460. cquantize->fserrors = (FSERRPTR) (*cinfo->mem->alloc_large)
  158461. ((j_common_ptr) cinfo, JPOOL_IMAGE, arraysize);
  158462. jzero_far((void FAR *) cquantize->fserrors, arraysize);
  158463. if (cquantize->error_limiter == NULL)
  158464. init_error_limit(cinfo);
  158465. cquantize->on_odd_row = FALSE;
  158466. }
  158467. }
  158468. if (cquantize->needs_zeroed) {
  158469. for (i = 0; i < HIST_C0_ELEMS; i++) {
  158470. jzero_far((void FAR *) histogram[i],
  158471. HIST_C1_ELEMS*HIST_C2_ELEMS * SIZEOF(histcell));
  158472. }
  158473. cquantize->needs_zeroed = FALSE;
  158474. }
  158475. }
  158476. METHODDEF(void)
  158477. new_color_map_2_quant (j_decompress_ptr cinfo)
  158478. {
  158479. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  158480. cquantize->needs_zeroed = TRUE;
  158481. }
  158482. GLOBAL(void)
  158483. jinit_2pass_quantizer (j_decompress_ptr cinfo)
  158484. {
  158485. my_cquantize_ptr2 cquantize;
  158486. int i;
  158487. cquantize = (my_cquantize_ptr2)
  158488. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  158489. SIZEOF(my_cquantizer2));
  158490. cinfo->cquantize = (struct jpeg_color_quantizer *) cquantize;
  158491. cquantize->pub.start_pass = start_pass_2_quant;
  158492. cquantize->pub.new_color_map = new_color_map_2_quant;
  158493. cquantize->fserrors = NULL; /* flag optional arrays not allocated */
  158494. cquantize->error_limiter = NULL;
  158495. if (cinfo->out_color_components != 3)
  158496. ERREXIT(cinfo, JERR_NOTIMPL);
  158497. cquantize->histogram = (hist3d) (*cinfo->mem->alloc_small)
  158498. ((j_common_ptr) cinfo, JPOOL_IMAGE, HIST_C0_ELEMS * SIZEOF(hist2d));
  158499. for (i = 0; i < HIST_C0_ELEMS; i++) {
  158500. cquantize->histogram[i] = (hist2d) (*cinfo->mem->alloc_large)
  158501. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  158502. HIST_C1_ELEMS*HIST_C2_ELEMS * SIZEOF(histcell));
  158503. }
  158504. cquantize->needs_zeroed = TRUE; /* histogram is garbage now */
  158505. if (cinfo->enable_2pass_quant) {
  158506. int desired = cinfo->desired_number_of_colors;
  158507. if (desired < 8)
  158508. ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, 8);
  158509. if (desired > MAXNUMCOLORS)
  158510. ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXNUMCOLORS);
  158511. cquantize->sv_colormap = (*cinfo->mem->alloc_sarray)
  158512. ((j_common_ptr) cinfo,JPOOL_IMAGE, (JDIMENSION) desired, (JDIMENSION) 3);
  158513. cquantize->desired = desired;
  158514. } else
  158515. cquantize->sv_colormap = NULL;
  158516. if (cinfo->dither_mode != JDITHER_NONE)
  158517. cinfo->dither_mode = JDITHER_FS;
  158518. if (cinfo->dither_mode == JDITHER_FS) {
  158519. cquantize->fserrors = (FSERRPTR) (*cinfo->mem->alloc_large)
  158520. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  158521. (size_t) ((cinfo->output_width + 2) * (3 * SIZEOF(FSERROR))));
  158522. init_error_limit(cinfo);
  158523. }
  158524. }
  158525. #endif /* QUANT_2PASS_SUPPORTED */
  158526. /*** End of inlined file: jquant2.c ***/
  158527. /*** Start of inlined file: jutils.c ***/
  158528. #define JPEG_INTERNALS
  158529. #if 0 /* This table is not actually needed in v6a */
  158530. const int jpeg_zigzag_order[DCTSIZE2] = {
  158531. 0, 1, 5, 6, 14, 15, 27, 28,
  158532. 2, 4, 7, 13, 16, 26, 29, 42,
  158533. 3, 8, 12, 17, 25, 30, 41, 43,
  158534. 9, 11, 18, 24, 31, 40, 44, 53,
  158535. 10, 19, 23, 32, 39, 45, 52, 54,
  158536. 20, 22, 33, 38, 46, 51, 55, 60,
  158537. 21, 34, 37, 47, 50, 56, 59, 61,
  158538. 35, 36, 48, 49, 57, 58, 62, 63
  158539. };
  158540. #endif
  158541. const int jpeg_natural_order[DCTSIZE2+16] = {
  158542. 0, 1, 8, 16, 9, 2, 3, 10,
  158543. 17, 24, 32, 25, 18, 11, 4, 5,
  158544. 12, 19, 26, 33, 40, 48, 41, 34,
  158545. 27, 20, 13, 6, 7, 14, 21, 28,
  158546. 35, 42, 49, 56, 57, 50, 43, 36,
  158547. 29, 22, 15, 23, 30, 37, 44, 51,
  158548. 58, 59, 52, 45, 38, 31, 39, 46,
  158549. 53, 60, 61, 54, 47, 55, 62, 63,
  158550. 63, 63, 63, 63, 63, 63, 63, 63, /* extra entries for safety in decoder */
  158551. 63, 63, 63, 63, 63, 63, 63, 63
  158552. };
  158553. GLOBAL(long)
  158554. jdiv_round_up (long a, long b)
  158555. {
  158556. return (a + b - 1L) / b;
  158557. }
  158558. GLOBAL(long)
  158559. jround_up (long a, long b)
  158560. {
  158561. a += b - 1L;
  158562. return a - (a % b);
  158563. }
  158564. #ifndef NEED_FAR_POINTERS /* normal case, same as regular macros */
  158565. #define FMEMCOPY(dest,src,size) MEMCOPY(dest,src,size)
  158566. #define FMEMZERO(target,size) MEMZERO(target,size)
  158567. #else /* 80x86 case, define if we can */
  158568. #ifdef USE_FMEM
  158569. #define FMEMCOPY(dest,src,size) _fmemcpy((void FAR *)(dest), (const void FAR *)(src), (size_t)(size))
  158570. #define FMEMZERO(target,size) _fmemset((void FAR *)(target), 0, (size_t)(size))
  158571. #endif
  158572. #endif
  158573. GLOBAL(void)
  158574. jcopy_sample_rows (JSAMPARRAY input_array, int source_row,
  158575. JSAMPARRAY output_array, int dest_row,
  158576. int num_rows, JDIMENSION num_cols)
  158577. {
  158578. register JSAMPROW inptr, outptr;
  158579. #ifdef FMEMCOPY
  158580. register size_t count = (size_t) (num_cols * SIZEOF(JSAMPLE));
  158581. #else
  158582. register JDIMENSION count;
  158583. #endif
  158584. register int row;
  158585. input_array += source_row;
  158586. output_array += dest_row;
  158587. for (row = num_rows; row > 0; row--) {
  158588. inptr = *input_array++;
  158589. outptr = *output_array++;
  158590. #ifdef FMEMCOPY
  158591. FMEMCOPY(outptr, inptr, count);
  158592. #else
  158593. for (count = num_cols; count > 0; count--)
  158594. *outptr++ = *inptr++; /* needn't bother with GETJSAMPLE() here */
  158595. #endif
  158596. }
  158597. }
  158598. GLOBAL(void)
  158599. jcopy_block_row (JBLOCKROW input_row, JBLOCKROW output_row,
  158600. JDIMENSION num_blocks)
  158601. {
  158602. #ifdef FMEMCOPY
  158603. FMEMCOPY(output_row, input_row, num_blocks * (DCTSIZE2 * SIZEOF(JCOEF)));
  158604. #else
  158605. register JCOEFPTR inptr, outptr;
  158606. register long count;
  158607. inptr = (JCOEFPTR) input_row;
  158608. outptr = (JCOEFPTR) output_row;
  158609. for (count = (long) num_blocks * DCTSIZE2; count > 0; count--) {
  158610. *outptr++ = *inptr++;
  158611. }
  158612. #endif
  158613. }
  158614. GLOBAL(void)
  158615. jzero_far (void FAR * target, size_t bytestozero)
  158616. {
  158617. #ifdef FMEMZERO
  158618. FMEMZERO(target, bytestozero);
  158619. #else
  158620. register char FAR * ptr = (char FAR *) target;
  158621. register size_t count;
  158622. for (count = bytestozero; count > 0; count--) {
  158623. *ptr++ = 0;
  158624. }
  158625. #endif
  158626. }
  158627. /*** End of inlined file: jutils.c ***/
  158628. /*** Start of inlined file: transupp.c ***/
  158629. #define JPEG_INTERNALS
  158630. /*** Start of inlined file: transupp.h ***/
  158631. #ifndef TRANSFORMS_SUPPORTED
  158632. #define TRANSFORMS_SUPPORTED 1 /* 0 disables transform code */
  158633. #endif
  158634. #ifdef NEED_SHORT_EXTERNAL_NAMES
  158635. #define jtransform_request_workspace jTrRequest
  158636. #define jtransform_adjust_parameters jTrAdjust
  158637. #define jtransform_execute_transformation jTrExec
  158638. #define jcopy_markers_setup jCMrkSetup
  158639. #define jcopy_markers_execute jCMrkExec
  158640. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  158641. typedef enum {
  158642. JXFORM_NONE, /* no transformation */
  158643. JXFORM_FLIP_H, /* horizontal flip */
  158644. JXFORM_FLIP_V, /* vertical flip */
  158645. JXFORM_TRANSPOSE, /* transpose across UL-to-LR axis */
  158646. JXFORM_TRANSVERSE, /* transpose across UR-to-LL axis */
  158647. JXFORM_ROT_90, /* 90-degree clockwise rotation */
  158648. JXFORM_ROT_180, /* 180-degree rotation */
  158649. JXFORM_ROT_270 /* 270-degree clockwise (or 90 ccw) */
  158650. } JXFORM_CODE;
  158651. typedef struct {
  158652. JXFORM_CODE transform; /* image transform operator */
  158653. boolean trim; /* if TRUE, trim partial MCUs as needed */
  158654. boolean force_grayscale; /* if TRUE, convert color image to grayscale */
  158655. int num_components; /* # of components in workspace */
  158656. jvirt_barray_ptr * workspace_coef_arrays; /* workspace for transformations */
  158657. } jpeg_transform_info;
  158658. #if TRANSFORMS_SUPPORTED
  158659. EXTERN(void) jtransform_request_workspace
  158660. JPP((j_decompress_ptr srcinfo, jpeg_transform_info *info));
  158661. EXTERN(jvirt_barray_ptr *) jtransform_adjust_parameters
  158662. JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158663. jvirt_barray_ptr *src_coef_arrays,
  158664. jpeg_transform_info *info));
  158665. EXTERN(void) jtransform_execute_transformation
  158666. JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158667. jvirt_barray_ptr *src_coef_arrays,
  158668. jpeg_transform_info *info));
  158669. #endif /* TRANSFORMS_SUPPORTED */
  158670. typedef enum {
  158671. JCOPYOPT_NONE, /* copy no optional markers */
  158672. JCOPYOPT_COMMENTS, /* copy only comment (COM) markers */
  158673. JCOPYOPT_ALL /* copy all optional markers */
  158674. } JCOPY_OPTION;
  158675. #define JCOPYOPT_DEFAULT JCOPYOPT_COMMENTS /* recommended default */
  158676. EXTERN(void) jcopy_markers_setup
  158677. JPP((j_decompress_ptr srcinfo, JCOPY_OPTION option));
  158678. EXTERN(void) jcopy_markers_execute
  158679. JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158680. JCOPY_OPTION option));
  158681. /*** End of inlined file: transupp.h ***/
  158682. /* My own external interface */
  158683. #if TRANSFORMS_SUPPORTED
  158684. LOCAL(void)
  158685. do_flip_h (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158686. jvirt_barray_ptr *src_coef_arrays)
  158687. {
  158688. JDIMENSION MCU_cols, comp_width, blk_x, blk_y;
  158689. int ci, k, offset_y;
  158690. JBLOCKARRAY buffer;
  158691. JCOEFPTR ptr1, ptr2;
  158692. JCOEF temp1, temp2;
  158693. jpeg_component_info *compptr;
  158694. MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
  158695. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158696. compptr = dstinfo->comp_info + ci;
  158697. comp_width = MCU_cols * compptr->h_samp_factor;
  158698. for (blk_y = 0; blk_y < compptr->height_in_blocks;
  158699. blk_y += compptr->v_samp_factor) {
  158700. buffer = (*srcinfo->mem->access_virt_barray)
  158701. ((j_common_ptr) srcinfo, src_coef_arrays[ci], blk_y,
  158702. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158703. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158704. for (blk_x = 0; blk_x * 2 < comp_width; blk_x++) {
  158705. ptr1 = buffer[offset_y][blk_x];
  158706. ptr2 = buffer[offset_y][comp_width - blk_x - 1];
  158707. for (k = 0; k < DCTSIZE2; k += 2) {
  158708. temp1 = *ptr1; /* swap even column */
  158709. temp2 = *ptr2;
  158710. *ptr1++ = temp2;
  158711. *ptr2++ = temp1;
  158712. temp1 = *ptr1; /* swap odd column with sign change */
  158713. temp2 = *ptr2;
  158714. *ptr1++ = -temp2;
  158715. *ptr2++ = -temp1;
  158716. }
  158717. }
  158718. }
  158719. }
  158720. }
  158721. }
  158722. LOCAL(void)
  158723. do_flip_v (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158724. jvirt_barray_ptr *src_coef_arrays,
  158725. jvirt_barray_ptr *dst_coef_arrays)
  158726. {
  158727. JDIMENSION MCU_rows, comp_height, dst_blk_x, dst_blk_y;
  158728. int ci, i, j, offset_y;
  158729. JBLOCKARRAY src_buffer, dst_buffer;
  158730. JBLOCKROW src_row_ptr, dst_row_ptr;
  158731. JCOEFPTR src_ptr, dst_ptr;
  158732. jpeg_component_info *compptr;
  158733. MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
  158734. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158735. compptr = dstinfo->comp_info + ci;
  158736. comp_height = MCU_rows * compptr->v_samp_factor;
  158737. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158738. dst_blk_y += compptr->v_samp_factor) {
  158739. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158740. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158741. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158742. if (dst_blk_y < comp_height) {
  158743. src_buffer = (*srcinfo->mem->access_virt_barray)
  158744. ((j_common_ptr) srcinfo, src_coef_arrays[ci],
  158745. comp_height - dst_blk_y - (JDIMENSION) compptr->v_samp_factor,
  158746. (JDIMENSION) compptr->v_samp_factor, FALSE);
  158747. } else {
  158748. src_buffer = (*srcinfo->mem->access_virt_barray)
  158749. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_y,
  158750. (JDIMENSION) compptr->v_samp_factor, FALSE);
  158751. }
  158752. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158753. if (dst_blk_y < comp_height) {
  158754. dst_row_ptr = dst_buffer[offset_y];
  158755. src_row_ptr = src_buffer[compptr->v_samp_factor - offset_y - 1];
  158756. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158757. dst_blk_x++) {
  158758. dst_ptr = dst_row_ptr[dst_blk_x];
  158759. src_ptr = src_row_ptr[dst_blk_x];
  158760. for (i = 0; i < DCTSIZE; i += 2) {
  158761. for (j = 0; j < DCTSIZE; j++)
  158762. *dst_ptr++ = *src_ptr++;
  158763. for (j = 0; j < DCTSIZE; j++)
  158764. *dst_ptr++ = - *src_ptr++;
  158765. }
  158766. }
  158767. } else {
  158768. jcopy_block_row(src_buffer[offset_y], dst_buffer[offset_y],
  158769. compptr->width_in_blocks);
  158770. }
  158771. }
  158772. }
  158773. }
  158774. }
  158775. LOCAL(void)
  158776. do_transpose (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158777. jvirt_barray_ptr *src_coef_arrays,
  158778. jvirt_barray_ptr *dst_coef_arrays)
  158779. {
  158780. JDIMENSION dst_blk_x, dst_blk_y;
  158781. int ci, i, j, offset_x, offset_y;
  158782. JBLOCKARRAY src_buffer, dst_buffer;
  158783. JCOEFPTR src_ptr, dst_ptr;
  158784. jpeg_component_info *compptr;
  158785. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158786. compptr = dstinfo->comp_info + ci;
  158787. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158788. dst_blk_y += compptr->v_samp_factor) {
  158789. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158790. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158791. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158792. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158793. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158794. dst_blk_x += compptr->h_samp_factor) {
  158795. src_buffer = (*srcinfo->mem->access_virt_barray)
  158796. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
  158797. (JDIMENSION) compptr->h_samp_factor, FALSE);
  158798. for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
  158799. src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
  158800. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  158801. for (i = 0; i < DCTSIZE; i++)
  158802. for (j = 0; j < DCTSIZE; j++)
  158803. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158804. }
  158805. }
  158806. }
  158807. }
  158808. }
  158809. }
  158810. LOCAL(void)
  158811. do_rot_90 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158812. jvirt_barray_ptr *src_coef_arrays,
  158813. jvirt_barray_ptr *dst_coef_arrays)
  158814. {
  158815. JDIMENSION MCU_cols, comp_width, dst_blk_x, dst_blk_y;
  158816. int ci, i, j, offset_x, offset_y;
  158817. JBLOCKARRAY src_buffer, dst_buffer;
  158818. JCOEFPTR src_ptr, dst_ptr;
  158819. jpeg_component_info *compptr;
  158820. MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
  158821. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158822. compptr = dstinfo->comp_info + ci;
  158823. comp_width = MCU_cols * compptr->h_samp_factor;
  158824. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158825. dst_blk_y += compptr->v_samp_factor) {
  158826. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158827. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158828. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158829. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158830. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158831. dst_blk_x += compptr->h_samp_factor) {
  158832. src_buffer = (*srcinfo->mem->access_virt_barray)
  158833. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
  158834. (JDIMENSION) compptr->h_samp_factor, FALSE);
  158835. for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
  158836. src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
  158837. if (dst_blk_x < comp_width) {
  158838. dst_ptr = dst_buffer[offset_y]
  158839. [comp_width - dst_blk_x - offset_x - 1];
  158840. for (i = 0; i < DCTSIZE; i++) {
  158841. for (j = 0; j < DCTSIZE; j++)
  158842. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158843. i++;
  158844. for (j = 0; j < DCTSIZE; j++)
  158845. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158846. }
  158847. } else {
  158848. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  158849. for (i = 0; i < DCTSIZE; i++)
  158850. for (j = 0; j < DCTSIZE; j++)
  158851. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158852. }
  158853. }
  158854. }
  158855. }
  158856. }
  158857. }
  158858. }
  158859. LOCAL(void)
  158860. do_rot_270 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158861. jvirt_barray_ptr *src_coef_arrays,
  158862. jvirt_barray_ptr *dst_coef_arrays)
  158863. {
  158864. JDIMENSION MCU_rows, comp_height, dst_blk_x, dst_blk_y;
  158865. int ci, i, j, offset_x, offset_y;
  158866. JBLOCKARRAY src_buffer, dst_buffer;
  158867. JCOEFPTR src_ptr, dst_ptr;
  158868. jpeg_component_info *compptr;
  158869. MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
  158870. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158871. compptr = dstinfo->comp_info + ci;
  158872. comp_height = MCU_rows * compptr->v_samp_factor;
  158873. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158874. dst_blk_y += compptr->v_samp_factor) {
  158875. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158876. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158877. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158878. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158879. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158880. dst_blk_x += compptr->h_samp_factor) {
  158881. src_buffer = (*srcinfo->mem->access_virt_barray)
  158882. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
  158883. (JDIMENSION) compptr->h_samp_factor, FALSE);
  158884. for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
  158885. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  158886. if (dst_blk_y < comp_height) {
  158887. src_ptr = src_buffer[offset_x]
  158888. [comp_height - dst_blk_y - offset_y - 1];
  158889. for (i = 0; i < DCTSIZE; i++) {
  158890. for (j = 0; j < DCTSIZE; j++) {
  158891. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158892. j++;
  158893. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158894. }
  158895. }
  158896. } else {
  158897. src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
  158898. for (i = 0; i < DCTSIZE; i++)
  158899. for (j = 0; j < DCTSIZE; j++)
  158900. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158901. }
  158902. }
  158903. }
  158904. }
  158905. }
  158906. }
  158907. }
  158908. LOCAL(void)
  158909. do_rot_180 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158910. jvirt_barray_ptr *src_coef_arrays,
  158911. jvirt_barray_ptr *dst_coef_arrays)
  158912. {
  158913. JDIMENSION MCU_cols, MCU_rows, comp_width, comp_height, dst_blk_x, dst_blk_y;
  158914. int ci, i, j, offset_y;
  158915. JBLOCKARRAY src_buffer, dst_buffer;
  158916. JBLOCKROW src_row_ptr, dst_row_ptr;
  158917. JCOEFPTR src_ptr, dst_ptr;
  158918. jpeg_component_info *compptr;
  158919. MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
  158920. MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
  158921. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158922. compptr = dstinfo->comp_info + ci;
  158923. comp_width = MCU_cols * compptr->h_samp_factor;
  158924. comp_height = MCU_rows * compptr->v_samp_factor;
  158925. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158926. dst_blk_y += compptr->v_samp_factor) {
  158927. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158928. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158929. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158930. if (dst_blk_y < comp_height) {
  158931. src_buffer = (*srcinfo->mem->access_virt_barray)
  158932. ((j_common_ptr) srcinfo, src_coef_arrays[ci],
  158933. comp_height - dst_blk_y - (JDIMENSION) compptr->v_samp_factor,
  158934. (JDIMENSION) compptr->v_samp_factor, FALSE);
  158935. } else {
  158936. src_buffer = (*srcinfo->mem->access_virt_barray)
  158937. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_y,
  158938. (JDIMENSION) compptr->v_samp_factor, FALSE);
  158939. }
  158940. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158941. if (dst_blk_y < comp_height) {
  158942. dst_row_ptr = dst_buffer[offset_y];
  158943. src_row_ptr = src_buffer[compptr->v_samp_factor - offset_y - 1];
  158944. for (dst_blk_x = 0; dst_blk_x < comp_width; dst_blk_x++) {
  158945. dst_ptr = dst_row_ptr[dst_blk_x];
  158946. src_ptr = src_row_ptr[comp_width - dst_blk_x - 1];
  158947. for (i = 0; i < DCTSIZE; i += 2) {
  158948. for (j = 0; j < DCTSIZE; j += 2) {
  158949. *dst_ptr++ = *src_ptr++;
  158950. *dst_ptr++ = - *src_ptr++;
  158951. }
  158952. for (j = 0; j < DCTSIZE; j += 2) {
  158953. *dst_ptr++ = - *src_ptr++;
  158954. *dst_ptr++ = *src_ptr++;
  158955. }
  158956. }
  158957. }
  158958. for (; dst_blk_x < compptr->width_in_blocks; dst_blk_x++) {
  158959. dst_ptr = dst_row_ptr[dst_blk_x];
  158960. src_ptr = src_row_ptr[dst_blk_x];
  158961. for (i = 0; i < DCTSIZE; i += 2) {
  158962. for (j = 0; j < DCTSIZE; j++)
  158963. *dst_ptr++ = *src_ptr++;
  158964. for (j = 0; j < DCTSIZE; j++)
  158965. *dst_ptr++ = - *src_ptr++;
  158966. }
  158967. }
  158968. } else {
  158969. dst_row_ptr = dst_buffer[offset_y];
  158970. src_row_ptr = src_buffer[offset_y];
  158971. for (dst_blk_x = 0; dst_blk_x < comp_width; dst_blk_x++) {
  158972. dst_ptr = dst_row_ptr[dst_blk_x];
  158973. src_ptr = src_row_ptr[comp_width - dst_blk_x - 1];
  158974. for (i = 0; i < DCTSIZE2; i += 2) {
  158975. *dst_ptr++ = *src_ptr++;
  158976. *dst_ptr++ = - *src_ptr++;
  158977. }
  158978. }
  158979. for (; dst_blk_x < compptr->width_in_blocks; dst_blk_x++) {
  158980. dst_ptr = dst_row_ptr[dst_blk_x];
  158981. src_ptr = src_row_ptr[dst_blk_x];
  158982. for (i = 0; i < DCTSIZE2; i++)
  158983. *dst_ptr++ = *src_ptr++;
  158984. }
  158985. }
  158986. }
  158987. }
  158988. }
  158989. }
  158990. LOCAL(void)
  158991. do_transverse (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158992. jvirt_barray_ptr *src_coef_arrays,
  158993. jvirt_barray_ptr *dst_coef_arrays)
  158994. {
  158995. JDIMENSION MCU_cols, MCU_rows, comp_width, comp_height, dst_blk_x, dst_blk_y;
  158996. int ci, i, j, offset_x, offset_y;
  158997. JBLOCKARRAY src_buffer, dst_buffer;
  158998. JCOEFPTR src_ptr, dst_ptr;
  158999. jpeg_component_info *compptr;
  159000. MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
  159001. MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
  159002. for (ci = 0; ci < dstinfo->num_components; ci++) {
  159003. compptr = dstinfo->comp_info + ci;
  159004. comp_width = MCU_cols * compptr->h_samp_factor;
  159005. comp_height = MCU_rows * compptr->v_samp_factor;
  159006. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  159007. dst_blk_y += compptr->v_samp_factor) {
  159008. dst_buffer = (*srcinfo->mem->access_virt_barray)
  159009. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  159010. (JDIMENSION) compptr->v_samp_factor, TRUE);
  159011. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  159012. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  159013. dst_blk_x += compptr->h_samp_factor) {
  159014. src_buffer = (*srcinfo->mem->access_virt_barray)
  159015. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
  159016. (JDIMENSION) compptr->h_samp_factor, FALSE);
  159017. for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
  159018. if (dst_blk_y < comp_height) {
  159019. src_ptr = src_buffer[offset_x]
  159020. [comp_height - dst_blk_y - offset_y - 1];
  159021. if (dst_blk_x < comp_width) {
  159022. dst_ptr = dst_buffer[offset_y]
  159023. [comp_width - dst_blk_x - offset_x - 1];
  159024. for (i = 0; i < DCTSIZE; i++) {
  159025. for (j = 0; j < DCTSIZE; j++) {
  159026. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  159027. j++;
  159028. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  159029. }
  159030. i++;
  159031. for (j = 0; j < DCTSIZE; j++) {
  159032. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  159033. j++;
  159034. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  159035. }
  159036. }
  159037. } else {
  159038. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  159039. for (i = 0; i < DCTSIZE; i++) {
  159040. for (j = 0; j < DCTSIZE; j++) {
  159041. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  159042. j++;
  159043. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  159044. }
  159045. }
  159046. }
  159047. } else {
  159048. src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
  159049. if (dst_blk_x < comp_width) {
  159050. dst_ptr = dst_buffer[offset_y]
  159051. [comp_width - dst_blk_x - offset_x - 1];
  159052. for (i = 0; i < DCTSIZE; i++) {
  159053. for (j = 0; j < DCTSIZE; j++)
  159054. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  159055. i++;
  159056. for (j = 0; j < DCTSIZE; j++)
  159057. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  159058. }
  159059. } else {
  159060. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  159061. for (i = 0; i < DCTSIZE; i++)
  159062. for (j = 0; j < DCTSIZE; j++)
  159063. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  159064. }
  159065. }
  159066. }
  159067. }
  159068. }
  159069. }
  159070. }
  159071. }
  159072. GLOBAL(void)
  159073. jtransform_request_workspace (j_decompress_ptr srcinfo,
  159074. jpeg_transform_info *info)
  159075. {
  159076. jvirt_barray_ptr *coef_arrays = NULL;
  159077. jpeg_component_info *compptr;
  159078. int ci;
  159079. if (info->force_grayscale &&
  159080. srcinfo->jpeg_color_space == JCS_YCbCr &&
  159081. srcinfo->num_components == 3) {
  159082. info->num_components = 1;
  159083. } else {
  159084. info->num_components = srcinfo->num_components;
  159085. }
  159086. switch (info->transform) {
  159087. case JXFORM_NONE:
  159088. case JXFORM_FLIP_H:
  159089. break;
  159090. case JXFORM_FLIP_V:
  159091. case JXFORM_ROT_180:
  159092. coef_arrays = (jvirt_barray_ptr *)
  159093. (*srcinfo->mem->alloc_small) ((j_common_ptr) srcinfo, JPOOL_IMAGE,
  159094. SIZEOF(jvirt_barray_ptr) * info->num_components);
  159095. for (ci = 0; ci < info->num_components; ci++) {
  159096. compptr = srcinfo->comp_info + ci;
  159097. coef_arrays[ci] = (*srcinfo->mem->request_virt_barray)
  159098. ((j_common_ptr) srcinfo, JPOOL_IMAGE, FALSE,
  159099. (JDIMENSION) jround_up((long) compptr->width_in_blocks,
  159100. (long) compptr->h_samp_factor),
  159101. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  159102. (long) compptr->v_samp_factor),
  159103. (JDIMENSION) compptr->v_samp_factor);
  159104. }
  159105. break;
  159106. case JXFORM_TRANSPOSE:
  159107. case JXFORM_TRANSVERSE:
  159108. case JXFORM_ROT_90:
  159109. case JXFORM_ROT_270:
  159110. coef_arrays = (jvirt_barray_ptr *)
  159111. (*srcinfo->mem->alloc_small) ((j_common_ptr) srcinfo, JPOOL_IMAGE,
  159112. SIZEOF(jvirt_barray_ptr) * info->num_components);
  159113. for (ci = 0; ci < info->num_components; ci++) {
  159114. compptr = srcinfo->comp_info + ci;
  159115. coef_arrays[ci] = (*srcinfo->mem->request_virt_barray)
  159116. ((j_common_ptr) srcinfo, JPOOL_IMAGE, FALSE,
  159117. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  159118. (long) compptr->v_samp_factor),
  159119. (JDIMENSION) jround_up((long) compptr->width_in_blocks,
  159120. (long) compptr->h_samp_factor),
  159121. (JDIMENSION) compptr->h_samp_factor);
  159122. }
  159123. break;
  159124. }
  159125. info->workspace_coef_arrays = coef_arrays;
  159126. }
  159127. LOCAL(void)
  159128. transpose_critical_parameters (j_compress_ptr dstinfo)
  159129. {
  159130. int tblno, i, j, ci, itemp;
  159131. jpeg_component_info *compptr;
  159132. JQUANT_TBL *qtblptr;
  159133. JDIMENSION dtemp;
  159134. UINT16 qtemp;
  159135. dtemp = dstinfo->image_width;
  159136. dstinfo->image_width = dstinfo->image_height;
  159137. dstinfo->image_height = dtemp;
  159138. for (ci = 0; ci < dstinfo->num_components; ci++) {
  159139. compptr = dstinfo->comp_info + ci;
  159140. itemp = compptr->h_samp_factor;
  159141. compptr->h_samp_factor = compptr->v_samp_factor;
  159142. compptr->v_samp_factor = itemp;
  159143. }
  159144. for (tblno = 0; tblno < NUM_QUANT_TBLS; tblno++) {
  159145. qtblptr = dstinfo->quant_tbl_ptrs[tblno];
  159146. if (qtblptr != NULL) {
  159147. for (i = 0; i < DCTSIZE; i++) {
  159148. for (j = 0; j < i; j++) {
  159149. qtemp = qtblptr->quantval[i*DCTSIZE+j];
  159150. qtblptr->quantval[i*DCTSIZE+j] = qtblptr->quantval[j*DCTSIZE+i];
  159151. qtblptr->quantval[j*DCTSIZE+i] = qtemp;
  159152. }
  159153. }
  159154. }
  159155. }
  159156. }
  159157. LOCAL(void)
  159158. trim_right_edge (j_compress_ptr dstinfo)
  159159. {
  159160. int ci, max_h_samp_factor;
  159161. JDIMENSION MCU_cols;
  159162. max_h_samp_factor = 1;
  159163. for (ci = 0; ci < dstinfo->num_components; ci++) {
  159164. int h_samp_factor = dstinfo->comp_info[ci].h_samp_factor;
  159165. max_h_samp_factor = MAX(max_h_samp_factor, h_samp_factor);
  159166. }
  159167. MCU_cols = dstinfo->image_width / (max_h_samp_factor * DCTSIZE);
  159168. if (MCU_cols > 0) /* can't trim to 0 pixels */
  159169. dstinfo->image_width = MCU_cols * (max_h_samp_factor * DCTSIZE);
  159170. }
  159171. LOCAL(void)
  159172. trim_bottom_edge (j_compress_ptr dstinfo)
  159173. {
  159174. int ci, max_v_samp_factor;
  159175. JDIMENSION MCU_rows;
  159176. max_v_samp_factor = 1;
  159177. for (ci = 0; ci < dstinfo->num_components; ci++) {
  159178. int v_samp_factor = dstinfo->comp_info[ci].v_samp_factor;
  159179. max_v_samp_factor = MAX(max_v_samp_factor, v_samp_factor);
  159180. }
  159181. MCU_rows = dstinfo->image_height / (max_v_samp_factor * DCTSIZE);
  159182. if (MCU_rows > 0) /* can't trim to 0 pixels */
  159183. dstinfo->image_height = MCU_rows * (max_v_samp_factor * DCTSIZE);
  159184. }
  159185. GLOBAL(jvirt_barray_ptr *)
  159186. jtransform_adjust_parameters (j_decompress_ptr srcinfo,
  159187. j_compress_ptr dstinfo,
  159188. jvirt_barray_ptr *src_coef_arrays,
  159189. jpeg_transform_info *info)
  159190. {
  159191. if (info->force_grayscale) {
  159192. if ((dstinfo->jpeg_color_space == JCS_YCbCr &&
  159193. dstinfo->num_components == 3) ||
  159194. (dstinfo->jpeg_color_space == JCS_GRAYSCALE &&
  159195. dstinfo->num_components == 1)) {
  159196. int sv_quant_tbl_no = dstinfo->comp_info[0].quant_tbl_no;
  159197. jpeg_set_colorspace(dstinfo, JCS_GRAYSCALE);
  159198. dstinfo->comp_info[0].quant_tbl_no = sv_quant_tbl_no;
  159199. } else {
  159200. ERREXIT(dstinfo, JERR_CONVERSION_NOTIMPL);
  159201. }
  159202. }
  159203. switch (info->transform) {
  159204. case JXFORM_NONE:
  159205. break;
  159206. case JXFORM_FLIP_H:
  159207. if (info->trim)
  159208. trim_right_edge(dstinfo);
  159209. break;
  159210. case JXFORM_FLIP_V:
  159211. if (info->trim)
  159212. trim_bottom_edge(dstinfo);
  159213. break;
  159214. case JXFORM_TRANSPOSE:
  159215. transpose_critical_parameters(dstinfo);
  159216. break;
  159217. case JXFORM_TRANSVERSE:
  159218. transpose_critical_parameters(dstinfo);
  159219. if (info->trim) {
  159220. trim_right_edge(dstinfo);
  159221. trim_bottom_edge(dstinfo);
  159222. }
  159223. break;
  159224. case JXFORM_ROT_90:
  159225. transpose_critical_parameters(dstinfo);
  159226. if (info->trim)
  159227. trim_right_edge(dstinfo);
  159228. break;
  159229. case JXFORM_ROT_180:
  159230. if (info->trim) {
  159231. trim_right_edge(dstinfo);
  159232. trim_bottom_edge(dstinfo);
  159233. }
  159234. break;
  159235. case JXFORM_ROT_270:
  159236. transpose_critical_parameters(dstinfo);
  159237. if (info->trim)
  159238. trim_bottom_edge(dstinfo);
  159239. break;
  159240. }
  159241. if (info->workspace_coef_arrays != NULL)
  159242. return info->workspace_coef_arrays;
  159243. return src_coef_arrays;
  159244. }
  159245. GLOBAL(void)
  159246. jtransform_execute_transformation (j_decompress_ptr srcinfo,
  159247. j_compress_ptr dstinfo,
  159248. jvirt_barray_ptr *src_coef_arrays,
  159249. jpeg_transform_info *info)
  159250. {
  159251. jvirt_barray_ptr *dst_coef_arrays = info->workspace_coef_arrays;
  159252. switch (info->transform) {
  159253. case JXFORM_NONE:
  159254. break;
  159255. case JXFORM_FLIP_H:
  159256. do_flip_h(srcinfo, dstinfo, src_coef_arrays);
  159257. break;
  159258. case JXFORM_FLIP_V:
  159259. do_flip_v(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  159260. break;
  159261. case JXFORM_TRANSPOSE:
  159262. do_transpose(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  159263. break;
  159264. case JXFORM_TRANSVERSE:
  159265. do_transverse(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  159266. break;
  159267. case JXFORM_ROT_90:
  159268. do_rot_90(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  159269. break;
  159270. case JXFORM_ROT_180:
  159271. do_rot_180(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  159272. break;
  159273. case JXFORM_ROT_270:
  159274. do_rot_270(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  159275. break;
  159276. }
  159277. }
  159278. #endif /* TRANSFORMS_SUPPORTED */
  159279. GLOBAL(void)
  159280. jcopy_markers_setup (j_decompress_ptr srcinfo, JCOPY_OPTION option)
  159281. {
  159282. #ifdef SAVE_MARKERS_SUPPORTED
  159283. int m;
  159284. if (option != JCOPYOPT_NONE) {
  159285. jpeg_save_markers(srcinfo, JPEG_COM, 0xFFFF);
  159286. }
  159287. if (option == JCOPYOPT_ALL) {
  159288. for (m = 0; m < 16; m++)
  159289. jpeg_save_markers(srcinfo, JPEG_APP0 + m, 0xFFFF);
  159290. }
  159291. #endif /* SAVE_MARKERS_SUPPORTED */
  159292. }
  159293. GLOBAL(void)
  159294. jcopy_markers_execute (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  159295. JCOPY_OPTION option)
  159296. {
  159297. jpeg_saved_marker_ptr marker;
  159298. for (marker = srcinfo->marker_list; marker != NULL; marker = marker->next) {
  159299. if (dstinfo->write_JFIF_header &&
  159300. marker->marker == JPEG_APP0 &&
  159301. marker->data_length >= 5 &&
  159302. GETJOCTET(marker->data[0]) == 0x4A &&
  159303. GETJOCTET(marker->data[1]) == 0x46 &&
  159304. GETJOCTET(marker->data[2]) == 0x49 &&
  159305. GETJOCTET(marker->data[3]) == 0x46 &&
  159306. GETJOCTET(marker->data[4]) == 0)
  159307. continue; /* reject duplicate JFIF */
  159308. if (dstinfo->write_Adobe_marker &&
  159309. marker->marker == JPEG_APP0+14 &&
  159310. marker->data_length >= 5 &&
  159311. GETJOCTET(marker->data[0]) == 0x41 &&
  159312. GETJOCTET(marker->data[1]) == 0x64 &&
  159313. GETJOCTET(marker->data[2]) == 0x6F &&
  159314. GETJOCTET(marker->data[3]) == 0x62 &&
  159315. GETJOCTET(marker->data[4]) == 0x65)
  159316. continue; /* reject duplicate Adobe */
  159317. #ifdef NEED_FAR_POINTERS
  159318. {
  159319. unsigned int i;
  159320. jpeg_write_m_header(dstinfo, marker->marker, marker->data_length);
  159321. for (i = 0; i < marker->data_length; i++)
  159322. jpeg_write_m_byte(dstinfo, marker->data[i]);
  159323. }
  159324. #else
  159325. jpeg_write_marker(dstinfo, marker->marker,
  159326. marker->data, marker->data_length);
  159327. #endif
  159328. }
  159329. }
  159330. /*** End of inlined file: transupp.c ***/
  159331. }
  159332. #else
  159333. #define JPEG_INTERNALS
  159334. #undef FAR
  159335. #include <jpeglib.h>
  159336. #endif
  159337. }
  159338. #if JUCE_MSVC
  159339. #pragma warning (pop)
  159340. #endif
  159341. BEGIN_JUCE_NAMESPACE
  159342. using namespace jpeglibNamespace;
  159343. #if ! JUCE_MSVC
  159344. using jpeglibNamespace::boolean;
  159345. #endif
  159346. struct JPEGDecodingFailure {};
  159347. static void fatalErrorHandler (j_common_ptr)
  159348. {
  159349. throw JPEGDecodingFailure();
  159350. }
  159351. static void silentErrorCallback1 (j_common_ptr) {}
  159352. static void silentErrorCallback2 (j_common_ptr, int) {}
  159353. static void silentErrorCallback3 (j_common_ptr, char*) {}
  159354. static void setupSilentErrorHandler (struct jpeg_error_mgr& err)
  159355. {
  159356. zerostruct (err);
  159357. err.error_exit = fatalErrorHandler;
  159358. err.emit_message = silentErrorCallback2;
  159359. err.output_message = silentErrorCallback1;
  159360. err.format_message = silentErrorCallback3;
  159361. err.reset_error_mgr = silentErrorCallback1;
  159362. }
  159363. static void dummyCallback1 (j_decompress_ptr)
  159364. {
  159365. }
  159366. static void jpegSkip (j_decompress_ptr decompStruct, long num)
  159367. {
  159368. decompStruct->src->next_input_byte += num;
  159369. num = jmin (num, (long) decompStruct->src->bytes_in_buffer);
  159370. decompStruct->src->bytes_in_buffer -= num;
  159371. }
  159372. static boolean jpegFill (j_decompress_ptr)
  159373. {
  159374. return 0;
  159375. }
  159376. Image* juce_loadJPEGImageFromStream (InputStream& in)
  159377. {
  159378. MemoryBlock mb;
  159379. in.readIntoMemoryBlock (mb);
  159380. Image* image = 0;
  159381. if (mb.getSize() > 16)
  159382. {
  159383. struct jpeg_decompress_struct jpegDecompStruct;
  159384. struct jpeg_error_mgr jerr;
  159385. setupSilentErrorHandler (jerr);
  159386. jpegDecompStruct.err = &jerr;
  159387. jpeg_create_decompress (&jpegDecompStruct);
  159388. jpegDecompStruct.src = (jpeg_source_mgr*)(jpegDecompStruct.mem->alloc_small)
  159389. ((j_common_ptr)(&jpegDecompStruct), JPOOL_PERMANENT, sizeof (jpeg_source_mgr));
  159390. jpegDecompStruct.src->init_source = dummyCallback1;
  159391. jpegDecompStruct.src->fill_input_buffer = jpegFill;
  159392. jpegDecompStruct.src->skip_input_data = jpegSkip;
  159393. jpegDecompStruct.src->resync_to_restart = jpeg_resync_to_restart;
  159394. jpegDecompStruct.src->term_source = dummyCallback1;
  159395. jpegDecompStruct.src->next_input_byte = (const unsigned char*) mb.getData();
  159396. jpegDecompStruct.src->bytes_in_buffer = mb.getSize();
  159397. try
  159398. {
  159399. jpeg_read_header (&jpegDecompStruct, TRUE);
  159400. jpeg_calc_output_dimensions (&jpegDecompStruct);
  159401. const int width = jpegDecompStruct.output_width;
  159402. const int height = jpegDecompStruct.output_height;
  159403. jpegDecompStruct.out_color_space = JCS_RGB;
  159404. JSAMPARRAY buffer
  159405. = (*jpegDecompStruct.mem->alloc_sarray) ((j_common_ptr) &jpegDecompStruct,
  159406. JPOOL_IMAGE,
  159407. width * 3, 1);
  159408. if (jpeg_start_decompress (&jpegDecompStruct))
  159409. {
  159410. image = Image::createNativeImage (Image::RGB, width, height, false);
  159411. const bool hasAlphaChan = image->hasAlphaChannel();
  159412. const Image::BitmapData destData (*image, 0, 0, width, height, true);
  159413. for (int y = 0; y < height; ++y)
  159414. {
  159415. jpeg_read_scanlines (&jpegDecompStruct, buffer, 1);
  159416. const uint8* src = *buffer;
  159417. uint8* dest = destData.getLinePointer (y);
  159418. if (hasAlphaChan)
  159419. {
  159420. for (int i = width; --i >= 0;)
  159421. {
  159422. ((PixelARGB*) dest)->setARGB (0xff, src[0], src[1], src[2]);
  159423. ((PixelARGB*) dest)->premultiply();
  159424. dest += destData.pixelStride;
  159425. src += 3;
  159426. }
  159427. }
  159428. else
  159429. {
  159430. for (int i = width; --i >= 0;)
  159431. {
  159432. ((PixelRGB*) dest)->setARGB (0xff, src[0], src[1], src[2]);
  159433. dest += destData.pixelStride;
  159434. src += 3;
  159435. }
  159436. }
  159437. }
  159438. jpeg_finish_decompress (&jpegDecompStruct);
  159439. in.setPosition (((char*) jpegDecompStruct.src->next_input_byte) - (char*) mb.getData());
  159440. }
  159441. jpeg_destroy_decompress (&jpegDecompStruct);
  159442. }
  159443. catch (...)
  159444. {}
  159445. }
  159446. return image;
  159447. }
  159448. static const int jpegBufferSize = 512;
  159449. struct JuceJpegDest : public jpeg_destination_mgr
  159450. {
  159451. OutputStream* output;
  159452. char* buffer;
  159453. };
  159454. static void jpegWriteInit (j_compress_ptr)
  159455. {
  159456. }
  159457. static void jpegWriteTerminate (j_compress_ptr cinfo)
  159458. {
  159459. JuceJpegDest* const dest = (JuceJpegDest*) cinfo->dest;
  159460. const size_t numToWrite = jpegBufferSize - dest->free_in_buffer;
  159461. dest->output->write (dest->buffer, (int) numToWrite);
  159462. }
  159463. static boolean jpegWriteFlush (j_compress_ptr cinfo)
  159464. {
  159465. JuceJpegDest* const dest = (JuceJpegDest*) cinfo->dest;
  159466. const int numToWrite = jpegBufferSize;
  159467. dest->next_output_byte = (JOCTET*) dest->buffer;
  159468. dest->free_in_buffer = jpegBufferSize;
  159469. return dest->output->write (dest->buffer, numToWrite);
  159470. }
  159471. bool juce_writeJPEGImageToStream (const Image& image,
  159472. OutputStream& out,
  159473. float quality)
  159474. {
  159475. if (image.hasAlphaChannel())
  159476. {
  159477. // this method could fill the background in white and still save the image..
  159478. jassertfalse
  159479. return true;
  159480. }
  159481. struct jpeg_compress_struct jpegCompStruct;
  159482. struct jpeg_error_mgr jerr;
  159483. setupSilentErrorHandler (jerr);
  159484. jpegCompStruct.err = &jerr;
  159485. jpeg_create_compress (&jpegCompStruct);
  159486. JuceJpegDest dest;
  159487. jpegCompStruct.dest = &dest;
  159488. dest.output = &out;
  159489. HeapBlock <char> tempBuffer (jpegBufferSize);
  159490. dest.buffer = (char*) tempBuffer;
  159491. dest.next_output_byte = (JOCTET*) dest.buffer;
  159492. dest.free_in_buffer = jpegBufferSize;
  159493. dest.init_destination = jpegWriteInit;
  159494. dest.empty_output_buffer = jpegWriteFlush;
  159495. dest.term_destination = jpegWriteTerminate;
  159496. jpegCompStruct.image_width = image.getWidth();
  159497. jpegCompStruct.image_height = image.getHeight();
  159498. jpegCompStruct.input_components = 3;
  159499. jpegCompStruct.in_color_space = JCS_RGB;
  159500. jpegCompStruct.write_JFIF_header = 1;
  159501. jpegCompStruct.X_density = 72;
  159502. jpegCompStruct.Y_density = 72;
  159503. jpeg_set_defaults (&jpegCompStruct);
  159504. jpegCompStruct.dct_method = JDCT_FLOAT;
  159505. jpegCompStruct.optimize_coding = 1;
  159506. // jpegCompStruct.smoothing_factor = 10;
  159507. if (quality < 0.0f)
  159508. quality = 0.85f;
  159509. jpeg_set_quality (&jpegCompStruct, jlimit (0, 100, roundToInt (quality * 100.0f)), TRUE);
  159510. jpeg_start_compress (&jpegCompStruct, TRUE);
  159511. const int strideBytes = jpegCompStruct.image_width * jpegCompStruct.input_components;
  159512. JSAMPARRAY buffer = (*jpegCompStruct.mem->alloc_sarray) ((j_common_ptr) &jpegCompStruct,
  159513. JPOOL_IMAGE,
  159514. strideBytes, 1);
  159515. const Image::BitmapData srcData (image, 0, 0, jpegCompStruct.image_width, jpegCompStruct.image_height);
  159516. while (jpegCompStruct.next_scanline < jpegCompStruct.image_height)
  159517. {
  159518. const uint8* src = srcData.getLinePointer (jpegCompStruct.next_scanline);
  159519. uint8* dst = *buffer;
  159520. for (int i = jpegCompStruct.image_width; --i >= 0;)
  159521. {
  159522. *dst++ = ((const PixelRGB*) src)->getRed();
  159523. *dst++ = ((const PixelRGB*) src)->getGreen();
  159524. *dst++ = ((const PixelRGB*) src)->getBlue();
  159525. src += srcData.pixelStride;
  159526. }
  159527. jpeg_write_scanlines (&jpegCompStruct, buffer, 1);
  159528. }
  159529. jpeg_finish_compress (&jpegCompStruct);
  159530. jpeg_destroy_compress (&jpegCompStruct);
  159531. out.flush();
  159532. return true;
  159533. }
  159534. END_JUCE_NAMESPACE
  159535. /*** End of inlined file: juce_JPEGLoader.cpp ***/
  159536. /*** Start of inlined file: juce_PNGLoader.cpp ***/
  159537. #ifdef _MSC_VER
  159538. #pragma warning (push)
  159539. #pragma warning (disable: 4390 4611)
  159540. #endif
  159541. namespace zlibNamespace
  159542. {
  159543. #if JUCE_INCLUDE_ZLIB_CODE
  159544. #undef OS_CODE
  159545. #undef fdopen
  159546. #undef OS_CODE
  159547. #else
  159548. #include <zlib.h>
  159549. #endif
  159550. }
  159551. namespace pnglibNamespace
  159552. {
  159553. using namespace zlibNamespace;
  159554. #if JUCE_INCLUDE_PNGLIB_CODE
  159555. #if _MSC_VER != 1310
  159556. using ::calloc; // (causes conflict in VS.NET 2003)
  159557. using ::malloc;
  159558. using ::free;
  159559. #endif
  159560. extern "C"
  159561. {
  159562. using ::abs;
  159563. #define PNG_INTERNAL
  159564. #define NO_DUMMY_DECL
  159565. #define PNG_SETJMP_NOT_SUPPORTED
  159566. /*** Start of inlined file: png.h ***/
  159567. #ifndef PNG_H
  159568. #define PNG_H
  159569. #define PNG_LIBPNG_VER_STRING "1.2.21"
  159570. #define PNG_HEADER_VERSION_STRING \
  159571. " libpng version 1.2.21 - October 4, 2007\n"
  159572. #define PNG_LIBPNG_VER_SONUM 0
  159573. #define PNG_LIBPNG_VER_DLLNUM 13
  159574. #define PNG_LIBPNG_VER_MAJOR 1
  159575. #define PNG_LIBPNG_VER_MINOR 2
  159576. #define PNG_LIBPNG_VER_RELEASE 21
  159577. #define PNG_LIBPNG_VER_BUILD 0
  159578. #define PNG_LIBPNG_BUILD_ALPHA 1
  159579. #define PNG_LIBPNG_BUILD_BETA 2
  159580. #define PNG_LIBPNG_BUILD_RC 3
  159581. #define PNG_LIBPNG_BUILD_STABLE 4
  159582. #define PNG_LIBPNG_BUILD_RELEASE_STATUS_MASK 7
  159583. #define PNG_LIBPNG_BUILD_PATCH 8 /* Can be OR'ed with
  159584. PNG_LIBPNG_BUILD_STABLE only */
  159585. #define PNG_LIBPNG_BUILD_PRIVATE 16 /* Cannot be OR'ed with
  159586. PNG_LIBPNG_BUILD_SPECIAL */
  159587. #define PNG_LIBPNG_BUILD_SPECIAL 32 /* Cannot be OR'ed with
  159588. PNG_LIBPNG_BUILD_PRIVATE */
  159589. #define PNG_LIBPNG_BUILD_BASE_TYPE PNG_LIBPNG_BUILD_STABLE
  159590. #define PNG_LIBPNG_VER 10221 /* 1.2.21 */
  159591. #ifndef PNG_VERSION_INFO_ONLY
  159592. #endif
  159593. /*** Start of inlined file: pngconf.h ***/
  159594. #ifndef PNGCONF_H
  159595. #define PNGCONF_H
  159596. #define PNG_1_2_X
  159597. // These are some Juce config settings that should remove any unnecessary code bloat..
  159598. #define PNG_NO_STDIO 1
  159599. #define PNG_DEBUG 0
  159600. #define PNG_NO_WARNINGS 1
  159601. #define PNG_NO_ERROR_TEXT 1
  159602. #define PNG_NO_ERROR_NUMBERS 1
  159603. #define PNG_NO_USER_MEM 1
  159604. #define PNG_NO_READ_iCCP 1
  159605. #define PNG_NO_READ_UNKNOWN_CHUNKS 1
  159606. #define PNG_NO_READ_USER_CHUNKS 1
  159607. #define PNG_NO_READ_iTXt 1
  159608. #define PNG_NO_READ_sCAL 1
  159609. #define PNG_NO_READ_sPLT 1
  159610. #define png_error(a, b) png_err(a)
  159611. #define png_warning(a, b)
  159612. #define png_chunk_error(a, b) png_err(a)
  159613. #define png_chunk_warning(a, b)
  159614. #ifdef PNG_USER_CONFIG
  159615. # ifndef PNG_USER_PRIVATEBUILD
  159616. # define PNG_USER_PRIVATEBUILD
  159617. # endif
  159618. #include "pngusr.h"
  159619. #endif
  159620. #ifdef PNG_CONFIGURE_LIBPNG
  159621. #ifdef HAVE_CONFIG_H
  159622. #include "config.h"
  159623. #endif
  159624. #endif
  159625. #ifdef __STDC__
  159626. #ifdef SPECIALBUILD
  159627. # pragma message("PNG_LIBPNG_SPECIALBUILD (and deprecated SPECIALBUILD)\
  159628. are now LIBPNG reserved macros. Use PNG_USER_PRIVATEBUILD instead.")
  159629. #endif
  159630. #ifdef PRIVATEBUILD
  159631. # pragma message("PRIVATEBUILD is deprecated.\
  159632. Use PNG_USER_PRIVATEBUILD instead.")
  159633. # define PNG_USER_PRIVATEBUILD PRIVATEBUILD
  159634. #endif
  159635. #endif /* __STDC__ */
  159636. #ifndef PNG_VERSION_INFO_ONLY
  159637. # define PNG_WARN_UNINITIALIZED_ROW 1
  159638. #ifndef PNG_ZBUF_SIZE
  159639. # define PNG_ZBUF_SIZE 8192
  159640. #endif
  159641. #ifndef PNG_NO_READ_SUPPORTED
  159642. # define PNG_READ_SUPPORTED
  159643. #endif
  159644. #ifndef PNG_NO_WRITE_SUPPORTED
  159645. # define PNG_WRITE_SUPPORTED
  159646. #endif
  159647. #if !defined(PNG_1_0_X) && !defined(PNG_NO_MNG_FEATURES)
  159648. # ifndef PNG_MNG_FEATURES_SUPPORTED
  159649. # define PNG_MNG_FEATURES_SUPPORTED
  159650. # endif
  159651. #endif
  159652. #ifndef PNG_NO_FLOATING_POINT_SUPPORTED
  159653. # ifndef PNG_FLOATING_POINT_SUPPORTED
  159654. # define PNG_FLOATING_POINT_SUPPORTED
  159655. # endif
  159656. #endif
  159657. #if defined(MAXSEG_64K) && !defined(PNG_MAX_MALLOC_64K)
  159658. # define PNG_MAX_MALLOC_64K
  159659. #endif
  159660. #if defined(__CYGWIN__)
  159661. # if defined(ALL_STATIC)
  159662. # if defined(PNG_BUILD_DLL)
  159663. # undef PNG_BUILD_DLL
  159664. # endif
  159665. # if defined(PNG_USE_DLL)
  159666. # undef PNG_USE_DLL
  159667. # endif
  159668. # if defined(PNG_DLL)
  159669. # undef PNG_DLL
  159670. # endif
  159671. # if !defined(PNG_STATIC)
  159672. # define PNG_STATIC
  159673. # endif
  159674. # else
  159675. # if defined (PNG_BUILD_DLL)
  159676. # if defined(PNG_STATIC)
  159677. # undef PNG_STATIC
  159678. # endif
  159679. # if defined(PNG_USE_DLL)
  159680. # undef PNG_USE_DLL
  159681. # endif
  159682. # if !defined(PNG_DLL)
  159683. # define PNG_DLL
  159684. # endif
  159685. # else
  159686. # if defined(PNG_STATIC)
  159687. # if defined(PNG_USE_DLL)
  159688. # undef PNG_USE_DLL
  159689. # endif
  159690. # if defined(PNG_DLL)
  159691. # undef PNG_DLL
  159692. # endif
  159693. # else
  159694. # if !defined(PNG_USE_DLL)
  159695. # define PNG_USE_DLL
  159696. # endif
  159697. # if !defined(PNG_DLL)
  159698. # define PNG_DLL
  159699. # endif
  159700. # endif
  159701. # endif
  159702. # endif
  159703. #endif
  159704. #if defined(_WIN32_WCE)
  159705. # include <windows.h>
  159706. # define PNG_NO_CONSOLE_IO
  159707. # ifdef PNG_DEBUG
  159708. # undef PNG_DEBUG
  159709. # endif
  159710. #endif
  159711. #ifdef PNG_BUILD_DLL
  159712. # ifndef PNG_CONSOLE_IO_SUPPORTED
  159713. # ifndef PNG_NO_CONSOLE_IO
  159714. # define PNG_NO_CONSOLE_IO
  159715. # endif
  159716. # endif
  159717. #endif
  159718. # ifdef PNG_NO_STDIO
  159719. # ifndef PNG_NO_CONSOLE_IO
  159720. # define PNG_NO_CONSOLE_IO
  159721. # endif
  159722. # ifdef PNG_DEBUG
  159723. # if (PNG_DEBUG > 0)
  159724. # include <stdio.h>
  159725. # endif
  159726. # endif
  159727. # else
  159728. # if !defined(_WIN32_WCE)
  159729. # include <stdio.h>
  159730. # endif
  159731. # endif
  159732. #ifndef PNGARG
  159733. #ifdef OF /* zlib prototype munger */
  159734. # define PNGARG(arglist) OF(arglist)
  159735. #else
  159736. #ifdef _NO_PROTO
  159737. # define PNGARG(arglist) ()
  159738. # ifndef PNG_TYPECAST_NULL
  159739. # define PNG_TYPECAST_NULL
  159740. # endif
  159741. #else
  159742. # define PNGARG(arglist) arglist
  159743. #endif /* _NO_PROTO */
  159744. #endif /* OF */
  159745. #endif /* PNGARG */
  159746. #ifndef MACOS
  159747. # if (defined(__MWERKS__) && defined(macintosh)) || defined(applec) || \
  159748. defined(THINK_C) || defined(__SC__) || defined(TARGET_OS_MAC)
  159749. # define MACOS
  159750. # endif
  159751. #endif
  159752. #if !defined(MACOS) && !defined(RISCOS) && !defined(_WIN32_WCE)
  159753. # include <sys/types.h>
  159754. #endif
  159755. #if !defined(PNG_SETJMP_NOT_SUPPORTED) && !defined(PNG_NO_SETJMP_SUPPORTED)
  159756. # define PNG_SETJMP_SUPPORTED
  159757. #endif
  159758. #ifdef PNG_SETJMP_SUPPORTED
  159759. # ifdef __linux__
  159760. # ifdef _BSD_SOURCE
  159761. # define PNG_SAVE_BSD_SOURCE
  159762. # undef _BSD_SOURCE
  159763. # endif
  159764. # ifdef _SETJMP_H
  159765. __png.h__ already includes setjmp.h;
  159766. __dont__ include it again.;
  159767. # endif
  159768. # endif /* __linux__ */
  159769. # include <setjmp.h>
  159770. # ifdef __linux__
  159771. # ifdef PNG_SAVE_BSD_SOURCE
  159772. # define _BSD_SOURCE
  159773. # undef PNG_SAVE_BSD_SOURCE
  159774. # endif
  159775. # endif /* __linux__ */
  159776. #endif /* PNG_SETJMP_SUPPORTED */
  159777. #ifdef BSD
  159778. #if ! JUCE_MAC
  159779. # include <strings.h>
  159780. #endif
  159781. #else
  159782. # include <string.h>
  159783. #endif
  159784. #ifdef PNG_INTERNAL
  159785. #include <stdlib.h>
  159786. #define PNG_EXTERN
  159787. #if defined(PNG_FLOATING_POINT_SUPPORTED)
  159788. # if defined(MACOS)
  159789. # if !defined(__MATH_H__) && !defined(__MATH_H) && !defined(__cmath__)
  159790. # include <fp.h>
  159791. # endif
  159792. # else
  159793. # include <math.h>
  159794. # endif
  159795. # if defined(_AMIGA) && defined(__SASC) && defined(_M68881)
  159796. # include <m68881.h>
  159797. # endif
  159798. #endif
  159799. #if (defined(__MWERKS__) && defined(WIN32)) || defined(__STDC__)
  159800. # define PNG_ALWAYS_EXTERN
  159801. #endif
  159802. #if defined(__TURBOC__) && defined(__MSDOS__)
  159803. # include <mem.h>
  159804. # include <alloc.h>
  159805. #endif
  159806. #if defined(_MSC_VER) && (defined(WIN32) || defined(_Windows) || \
  159807. defined(_WINDOWS) || defined(_WIN32) || defined(__WIN32__))
  159808. # include <malloc.h>
  159809. #endif
  159810. #ifndef PNG_DITHER_RED_BITS
  159811. # define PNG_DITHER_RED_BITS 5
  159812. #endif
  159813. #ifndef PNG_DITHER_GREEN_BITS
  159814. # define PNG_DITHER_GREEN_BITS 5
  159815. #endif
  159816. #ifndef PNG_DITHER_BLUE_BITS
  159817. # define PNG_DITHER_BLUE_BITS 5
  159818. #endif
  159819. #ifndef PNG_MAX_GAMMA_8
  159820. # define PNG_MAX_GAMMA_8 11
  159821. #endif
  159822. #ifndef PNG_GAMMA_THRESHOLD
  159823. # define PNG_GAMMA_THRESHOLD 0.05
  159824. #endif
  159825. #endif /* PNG_INTERNAL */
  159826. #ifndef PNG_NO_CONST
  159827. # define PNG_CONST const
  159828. #else
  159829. # define PNG_CONST
  159830. #endif
  159831. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  159832. # ifndef PNG_NO_iTXt_SUPPORTED
  159833. # define PNG_NO_iTXt_SUPPORTED
  159834. # endif
  159835. # ifndef PNG_NO_READ_iTXt
  159836. # define PNG_NO_READ_iTXt
  159837. # endif
  159838. # ifndef PNG_NO_WRITE_iTXt
  159839. # define PNG_NO_WRITE_iTXt
  159840. # endif
  159841. #endif
  159842. #if !defined(PNG_NO_iTXt_SUPPORTED)
  159843. # if !defined(PNG_READ_iTXt_SUPPORTED) && !defined(PNG_NO_READ_iTXt)
  159844. # define PNG_READ_iTXt
  159845. # endif
  159846. # if !defined(PNG_WRITE_iTXt_SUPPORTED) && !defined(PNG_NO_WRITE_iTXt)
  159847. # define PNG_WRITE_iTXt
  159848. # endif
  159849. #endif
  159850. #ifdef PNG_LEGACY_SUPPORTED
  159851. # define PNG_NO_FREE_ME
  159852. # define PNG_NO_READ_UNKNOWN_CHUNKS
  159853. # define PNG_NO_WRITE_UNKNOWN_CHUNKS
  159854. # define PNG_NO_READ_USER_CHUNKS
  159855. # define PNG_NO_READ_iCCP
  159856. # define PNG_NO_WRITE_iCCP
  159857. # define PNG_NO_READ_iTXt
  159858. # define PNG_NO_WRITE_iTXt
  159859. # define PNG_NO_READ_sCAL
  159860. # define PNG_NO_WRITE_sCAL
  159861. # define PNG_NO_READ_sPLT
  159862. # define PNG_NO_WRITE_sPLT
  159863. # define PNG_NO_INFO_IMAGE
  159864. # define PNG_NO_READ_RGB_TO_GRAY
  159865. # define PNG_NO_READ_USER_TRANSFORM
  159866. # define PNG_NO_WRITE_USER_TRANSFORM
  159867. # define PNG_NO_USER_MEM
  159868. # define PNG_NO_READ_EMPTY_PLTE
  159869. # define PNG_NO_MNG_FEATURES
  159870. # define PNG_NO_FIXED_POINT_SUPPORTED
  159871. #endif
  159872. #if !defined(PNG_FLOATING_POINT_SUPPORTED) || \
  159873. !defined(PNG_NO_FIXED_POINT_SUPPORTED)
  159874. # define PNG_FIXED_POINT_SUPPORTED
  159875. #endif
  159876. #ifndef PNG_NO_FREE_ME
  159877. # define PNG_FREE_ME_SUPPORTED
  159878. #endif
  159879. #if defined(PNG_READ_SUPPORTED)
  159880. #if !defined(PNG_READ_TRANSFORMS_NOT_SUPPORTED) && \
  159881. !defined(PNG_NO_READ_TRANSFORMS)
  159882. # define PNG_READ_TRANSFORMS_SUPPORTED
  159883. #endif
  159884. #ifdef PNG_READ_TRANSFORMS_SUPPORTED
  159885. # ifndef PNG_NO_READ_EXPAND
  159886. # define PNG_READ_EXPAND_SUPPORTED
  159887. # endif
  159888. # ifndef PNG_NO_READ_SHIFT
  159889. # define PNG_READ_SHIFT_SUPPORTED
  159890. # endif
  159891. # ifndef PNG_NO_READ_PACK
  159892. # define PNG_READ_PACK_SUPPORTED
  159893. # endif
  159894. # ifndef PNG_NO_READ_BGR
  159895. # define PNG_READ_BGR_SUPPORTED
  159896. # endif
  159897. # ifndef PNG_NO_READ_SWAP
  159898. # define PNG_READ_SWAP_SUPPORTED
  159899. # endif
  159900. # ifndef PNG_NO_READ_PACKSWAP
  159901. # define PNG_READ_PACKSWAP_SUPPORTED
  159902. # endif
  159903. # ifndef PNG_NO_READ_INVERT
  159904. # define PNG_READ_INVERT_SUPPORTED
  159905. # endif
  159906. # ifndef PNG_NO_READ_DITHER
  159907. # define PNG_READ_DITHER_SUPPORTED
  159908. # endif
  159909. # ifndef PNG_NO_READ_BACKGROUND
  159910. # define PNG_READ_BACKGROUND_SUPPORTED
  159911. # endif
  159912. # ifndef PNG_NO_READ_16_TO_8
  159913. # define PNG_READ_16_TO_8_SUPPORTED
  159914. # endif
  159915. # ifndef PNG_NO_READ_FILLER
  159916. # define PNG_READ_FILLER_SUPPORTED
  159917. # endif
  159918. # ifndef PNG_NO_READ_GAMMA
  159919. # define PNG_READ_GAMMA_SUPPORTED
  159920. # endif
  159921. # ifndef PNG_NO_READ_GRAY_TO_RGB
  159922. # define PNG_READ_GRAY_TO_RGB_SUPPORTED
  159923. # endif
  159924. # ifndef PNG_NO_READ_SWAP_ALPHA
  159925. # define PNG_READ_SWAP_ALPHA_SUPPORTED
  159926. # endif
  159927. # ifndef PNG_NO_READ_INVERT_ALPHA
  159928. # define PNG_READ_INVERT_ALPHA_SUPPORTED
  159929. # endif
  159930. # ifndef PNG_NO_READ_STRIP_ALPHA
  159931. # define PNG_READ_STRIP_ALPHA_SUPPORTED
  159932. # endif
  159933. # ifndef PNG_NO_READ_USER_TRANSFORM
  159934. # define PNG_READ_USER_TRANSFORM_SUPPORTED
  159935. # endif
  159936. # ifndef PNG_NO_READ_RGB_TO_GRAY
  159937. # define PNG_READ_RGB_TO_GRAY_SUPPORTED
  159938. # endif
  159939. #endif /* PNG_READ_TRANSFORMS_SUPPORTED */
  159940. #if !defined(PNG_NO_PROGRESSIVE_READ) && \
  159941. !defined(PNG_PROGRESSIVE_READ_SUPPORTED) /* if you don't do progressive */
  159942. # define PNG_PROGRESSIVE_READ_SUPPORTED /* reading. This is not talking */
  159943. #endif /* about interlacing capability! You'll */
  159944. #define PNG_READ_INTERLACING_SUPPORTED /* required in PNG-compliant decoders */
  159945. #ifndef PNG_NO_READ_COMPOSITE_NODIV
  159946. # ifndef PNG_NO_READ_COMPOSITED_NODIV /* libpng-1.0.x misspelling */
  159947. # define PNG_READ_COMPOSITE_NODIV_SUPPORTED /* well tested on Intel, SGI */
  159948. # endif
  159949. #endif
  159950. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  159951. #ifndef PNG_NO_READ_EMPTY_PLTE
  159952. # define PNG_READ_EMPTY_PLTE_SUPPORTED
  159953. #endif
  159954. #endif
  159955. #endif /* PNG_READ_SUPPORTED */
  159956. #if defined(PNG_WRITE_SUPPORTED)
  159957. # if !defined(PNG_WRITE_TRANSFORMS_NOT_SUPPORTED) && \
  159958. !defined(PNG_NO_WRITE_TRANSFORMS)
  159959. # define PNG_WRITE_TRANSFORMS_SUPPORTED
  159960. #endif
  159961. #ifdef PNG_WRITE_TRANSFORMS_SUPPORTED
  159962. # ifndef PNG_NO_WRITE_SHIFT
  159963. # define PNG_WRITE_SHIFT_SUPPORTED
  159964. # endif
  159965. # ifndef PNG_NO_WRITE_PACK
  159966. # define PNG_WRITE_PACK_SUPPORTED
  159967. # endif
  159968. # ifndef PNG_NO_WRITE_BGR
  159969. # define PNG_WRITE_BGR_SUPPORTED
  159970. # endif
  159971. # ifndef PNG_NO_WRITE_SWAP
  159972. # define PNG_WRITE_SWAP_SUPPORTED
  159973. # endif
  159974. # ifndef PNG_NO_WRITE_PACKSWAP
  159975. # define PNG_WRITE_PACKSWAP_SUPPORTED
  159976. # endif
  159977. # ifndef PNG_NO_WRITE_INVERT
  159978. # define PNG_WRITE_INVERT_SUPPORTED
  159979. # endif
  159980. # ifndef PNG_NO_WRITE_FILLER
  159981. # define PNG_WRITE_FILLER_SUPPORTED /* same as WRITE_STRIP_ALPHA */
  159982. # endif
  159983. # ifndef PNG_NO_WRITE_SWAP_ALPHA
  159984. # define PNG_WRITE_SWAP_ALPHA_SUPPORTED
  159985. # endif
  159986. # ifndef PNG_NO_WRITE_INVERT_ALPHA
  159987. # define PNG_WRITE_INVERT_ALPHA_SUPPORTED
  159988. # endif
  159989. # ifndef PNG_NO_WRITE_USER_TRANSFORM
  159990. # define PNG_WRITE_USER_TRANSFORM_SUPPORTED
  159991. # endif
  159992. #endif /* PNG_WRITE_TRANSFORMS_SUPPORTED */
  159993. #if !defined(PNG_NO_WRITE_INTERLACING_SUPPORTED) && \
  159994. !defined(PNG_WRITE_INTERLACING_SUPPORTED)
  159995. #define PNG_WRITE_INTERLACING_SUPPORTED /* not required for PNG-compliant
  159996. encoders, but can cause trouble
  159997. if left undefined */
  159998. #endif
  159999. #if !defined(PNG_NO_WRITE_WEIGHTED_FILTER) && \
  160000. !defined(PNG_WRITE_WEIGHTED_FILTER) && \
  160001. defined(PNG_FLOATING_POINT_SUPPORTED)
  160002. # define PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
  160003. #endif
  160004. #ifndef PNG_NO_WRITE_FLUSH
  160005. # define PNG_WRITE_FLUSH_SUPPORTED
  160006. #endif
  160007. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  160008. #ifndef PNG_NO_WRITE_EMPTY_PLTE
  160009. # define PNG_WRITE_EMPTY_PLTE_SUPPORTED
  160010. #endif
  160011. #endif
  160012. #endif /* PNG_WRITE_SUPPORTED */
  160013. #ifndef PNG_1_0_X
  160014. # ifndef PNG_NO_ERROR_NUMBERS
  160015. # define PNG_ERROR_NUMBERS_SUPPORTED
  160016. # endif
  160017. #endif /* PNG_1_0_X */
  160018. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  160019. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  160020. # ifndef PNG_NO_USER_TRANSFORM_PTR
  160021. # define PNG_USER_TRANSFORM_PTR_SUPPORTED
  160022. # endif
  160023. #endif
  160024. #ifndef PNG_NO_STDIO
  160025. # define PNG_TIME_RFC1123_SUPPORTED
  160026. #endif
  160027. #if !defined(PNG_NO_EASY_ACCESS) && !defined(PNG_EASY_ACCESS_SUPPORTED)
  160028. # define PNG_EASY_ACCESS_SUPPORTED
  160029. #endif
  160030. #if defined(PNG_READ_SUPPORTED) && !defined(PNG_NO_OPTIMIZED_CODE)
  160031. # ifndef PNG_OPTIMIZED_CODE_SUPPORTED
  160032. # define PNG_OPTIMIZED_CODE_SUPPORTED
  160033. # endif
  160034. #endif
  160035. #if defined(PNG_READ_SUPPORTED) && !defined(PNG_NO_ASSEMBLER_CODE)
  160036. # ifndef PNG_ASSEMBLER_CODE_SUPPORTED
  160037. # define PNG_ASSEMBLER_CODE_SUPPORTED
  160038. # endif
  160039. # if defined(__GNUC__) && defined(__x86_64__) && (__GNUC__ < 4)
  160040. # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
  160041. # define PNG_NO_MMX_CODE
  160042. # endif
  160043. # endif
  160044. # if defined(__APPLE__)
  160045. # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
  160046. # define PNG_NO_MMX_CODE
  160047. # endif
  160048. # endif
  160049. # if (defined(__MWERKS__) && ((__MWERKS__ < 0x0900) || macintosh))
  160050. # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
  160051. # define PNG_NO_MMX_CODE
  160052. # endif
  160053. # endif
  160054. # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
  160055. # define PNG_MMX_CODE_SUPPORTED
  160056. # endif
  160057. #endif
  160058. #if !defined(PNG_1_0_X)
  160059. #if !defined(PNG_NO_USER_MEM) && !defined(PNG_USER_MEM_SUPPORTED)
  160060. # define PNG_USER_MEM_SUPPORTED
  160061. #endif
  160062. #endif /* PNG_1_0_X */
  160063. #if !defined(PNG_1_0_X)
  160064. #ifndef PNG_SET_USER_LIMITS_SUPPORTED
  160065. #if !defined(PNG_NO_SET_USER_LIMITS) && !defined(PNG_SET_USER_LIMITS_SUPPORTED)
  160066. # define PNG_SET_USER_LIMITS_SUPPORTED
  160067. #endif
  160068. #endif
  160069. #endif /* PNG_1_0_X */
  160070. #ifndef PNG_USER_WIDTH_MAX
  160071. # define PNG_USER_WIDTH_MAX 1000000L
  160072. #endif
  160073. #ifndef PNG_USER_HEIGHT_MAX
  160074. # define PNG_USER_HEIGHT_MAX 1000000L
  160075. #endif
  160076. #if defined(PNG_READ_SUPPORTED) && \
  160077. !defined(PNG_READ_ANCILLARY_CHUNKS_NOT_SUPPORTED) && \
  160078. !defined(PNG_NO_READ_ANCILLARY_CHUNKS)
  160079. # define PNG_READ_ANCILLARY_CHUNKS_SUPPORTED
  160080. #endif
  160081. #if defined(PNG_WRITE_SUPPORTED) && \
  160082. !defined(PNG_WRITE_ANCILLARY_CHUNKS_NOT_SUPPORTED) && \
  160083. !defined(PNG_NO_WRITE_ANCILLARY_CHUNKS)
  160084. # define PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED
  160085. #endif
  160086. #ifdef PNG_READ_ANCILLARY_CHUNKS_SUPPORTED
  160087. #ifdef PNG_NO_READ_TEXT
  160088. # define PNG_NO_READ_iTXt
  160089. # define PNG_NO_READ_tEXt
  160090. # define PNG_NO_READ_zTXt
  160091. #endif
  160092. #ifndef PNG_NO_READ_bKGD
  160093. # define PNG_READ_bKGD_SUPPORTED
  160094. # define PNG_bKGD_SUPPORTED
  160095. #endif
  160096. #ifndef PNG_NO_READ_cHRM
  160097. # define PNG_READ_cHRM_SUPPORTED
  160098. # define PNG_cHRM_SUPPORTED
  160099. #endif
  160100. #ifndef PNG_NO_READ_gAMA
  160101. # define PNG_READ_gAMA_SUPPORTED
  160102. # define PNG_gAMA_SUPPORTED
  160103. #endif
  160104. #ifndef PNG_NO_READ_hIST
  160105. # define PNG_READ_hIST_SUPPORTED
  160106. # define PNG_hIST_SUPPORTED
  160107. #endif
  160108. #ifndef PNG_NO_READ_iCCP
  160109. # define PNG_READ_iCCP_SUPPORTED
  160110. # define PNG_iCCP_SUPPORTED
  160111. #endif
  160112. #ifndef PNG_NO_READ_iTXt
  160113. # ifndef PNG_READ_iTXt_SUPPORTED
  160114. # define PNG_READ_iTXt_SUPPORTED
  160115. # endif
  160116. # ifndef PNG_iTXt_SUPPORTED
  160117. # define PNG_iTXt_SUPPORTED
  160118. # endif
  160119. #endif
  160120. #ifndef PNG_NO_READ_oFFs
  160121. # define PNG_READ_oFFs_SUPPORTED
  160122. # define PNG_oFFs_SUPPORTED
  160123. #endif
  160124. #ifndef PNG_NO_READ_pCAL
  160125. # define PNG_READ_pCAL_SUPPORTED
  160126. # define PNG_pCAL_SUPPORTED
  160127. #endif
  160128. #ifndef PNG_NO_READ_sCAL
  160129. # define PNG_READ_sCAL_SUPPORTED
  160130. # define PNG_sCAL_SUPPORTED
  160131. #endif
  160132. #ifndef PNG_NO_READ_pHYs
  160133. # define PNG_READ_pHYs_SUPPORTED
  160134. # define PNG_pHYs_SUPPORTED
  160135. #endif
  160136. #ifndef PNG_NO_READ_sBIT
  160137. # define PNG_READ_sBIT_SUPPORTED
  160138. # define PNG_sBIT_SUPPORTED
  160139. #endif
  160140. #ifndef PNG_NO_READ_sPLT
  160141. # define PNG_READ_sPLT_SUPPORTED
  160142. # define PNG_sPLT_SUPPORTED
  160143. #endif
  160144. #ifndef PNG_NO_READ_sRGB
  160145. # define PNG_READ_sRGB_SUPPORTED
  160146. # define PNG_sRGB_SUPPORTED
  160147. #endif
  160148. #ifndef PNG_NO_READ_tEXt
  160149. # define PNG_READ_tEXt_SUPPORTED
  160150. # define PNG_tEXt_SUPPORTED
  160151. #endif
  160152. #ifndef PNG_NO_READ_tIME
  160153. # define PNG_READ_tIME_SUPPORTED
  160154. # define PNG_tIME_SUPPORTED
  160155. #endif
  160156. #ifndef PNG_NO_READ_tRNS
  160157. # define PNG_READ_tRNS_SUPPORTED
  160158. # define PNG_tRNS_SUPPORTED
  160159. #endif
  160160. #ifndef PNG_NO_READ_zTXt
  160161. # define PNG_READ_zTXt_SUPPORTED
  160162. # define PNG_zTXt_SUPPORTED
  160163. #endif
  160164. #ifndef PNG_NO_READ_UNKNOWN_CHUNKS
  160165. # define PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
  160166. # ifndef PNG_UNKNOWN_CHUNKS_SUPPORTED
  160167. # define PNG_UNKNOWN_CHUNKS_SUPPORTED
  160168. # endif
  160169. # ifndef PNG_NO_HANDLE_AS_UNKNOWN
  160170. # define PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  160171. # endif
  160172. #endif
  160173. #if !defined(PNG_NO_READ_USER_CHUNKS) && \
  160174. defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  160175. # define PNG_READ_USER_CHUNKS_SUPPORTED
  160176. # define PNG_USER_CHUNKS_SUPPORTED
  160177. # ifdef PNG_NO_READ_UNKNOWN_CHUNKS
  160178. # undef PNG_NO_READ_UNKNOWN_CHUNKS
  160179. # endif
  160180. # ifdef PNG_NO_HANDLE_AS_UNKNOWN
  160181. # undef PNG_NO_HANDLE_AS_UNKNOWN
  160182. # endif
  160183. #endif
  160184. #ifndef PNG_NO_READ_OPT_PLTE
  160185. # define PNG_READ_OPT_PLTE_SUPPORTED /* only affects support of the */
  160186. #endif /* optional PLTE chunk in RGB and RGBA images */
  160187. #if defined(PNG_READ_iTXt_SUPPORTED) || defined(PNG_READ_tEXt_SUPPORTED) || \
  160188. defined(PNG_READ_zTXt_SUPPORTED)
  160189. # define PNG_READ_TEXT_SUPPORTED
  160190. # define PNG_TEXT_SUPPORTED
  160191. #endif
  160192. #endif /* PNG_READ_ANCILLARY_CHUNKS_SUPPORTED */
  160193. #ifdef PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED
  160194. #ifdef PNG_NO_WRITE_TEXT
  160195. # define PNG_NO_WRITE_iTXt
  160196. # define PNG_NO_WRITE_tEXt
  160197. # define PNG_NO_WRITE_zTXt
  160198. #endif
  160199. #ifndef PNG_NO_WRITE_bKGD
  160200. # define PNG_WRITE_bKGD_SUPPORTED
  160201. # ifndef PNG_bKGD_SUPPORTED
  160202. # define PNG_bKGD_SUPPORTED
  160203. # endif
  160204. #endif
  160205. #ifndef PNG_NO_WRITE_cHRM
  160206. # define PNG_WRITE_cHRM_SUPPORTED
  160207. # ifndef PNG_cHRM_SUPPORTED
  160208. # define PNG_cHRM_SUPPORTED
  160209. # endif
  160210. #endif
  160211. #ifndef PNG_NO_WRITE_gAMA
  160212. # define PNG_WRITE_gAMA_SUPPORTED
  160213. # ifndef PNG_gAMA_SUPPORTED
  160214. # define PNG_gAMA_SUPPORTED
  160215. # endif
  160216. #endif
  160217. #ifndef PNG_NO_WRITE_hIST
  160218. # define PNG_WRITE_hIST_SUPPORTED
  160219. # ifndef PNG_hIST_SUPPORTED
  160220. # define PNG_hIST_SUPPORTED
  160221. # endif
  160222. #endif
  160223. #ifndef PNG_NO_WRITE_iCCP
  160224. # define PNG_WRITE_iCCP_SUPPORTED
  160225. # ifndef PNG_iCCP_SUPPORTED
  160226. # define PNG_iCCP_SUPPORTED
  160227. # endif
  160228. #endif
  160229. #ifndef PNG_NO_WRITE_iTXt
  160230. # ifndef PNG_WRITE_iTXt_SUPPORTED
  160231. # define PNG_WRITE_iTXt_SUPPORTED
  160232. # endif
  160233. # ifndef PNG_iTXt_SUPPORTED
  160234. # define PNG_iTXt_SUPPORTED
  160235. # endif
  160236. #endif
  160237. #ifndef PNG_NO_WRITE_oFFs
  160238. # define PNG_WRITE_oFFs_SUPPORTED
  160239. # ifndef PNG_oFFs_SUPPORTED
  160240. # define PNG_oFFs_SUPPORTED
  160241. # endif
  160242. #endif
  160243. #ifndef PNG_NO_WRITE_pCAL
  160244. # define PNG_WRITE_pCAL_SUPPORTED
  160245. # ifndef PNG_pCAL_SUPPORTED
  160246. # define PNG_pCAL_SUPPORTED
  160247. # endif
  160248. #endif
  160249. #ifndef PNG_NO_WRITE_sCAL
  160250. # define PNG_WRITE_sCAL_SUPPORTED
  160251. # ifndef PNG_sCAL_SUPPORTED
  160252. # define PNG_sCAL_SUPPORTED
  160253. # endif
  160254. #endif
  160255. #ifndef PNG_NO_WRITE_pHYs
  160256. # define PNG_WRITE_pHYs_SUPPORTED
  160257. # ifndef PNG_pHYs_SUPPORTED
  160258. # define PNG_pHYs_SUPPORTED
  160259. # endif
  160260. #endif
  160261. #ifndef PNG_NO_WRITE_sBIT
  160262. # define PNG_WRITE_sBIT_SUPPORTED
  160263. # ifndef PNG_sBIT_SUPPORTED
  160264. # define PNG_sBIT_SUPPORTED
  160265. # endif
  160266. #endif
  160267. #ifndef PNG_NO_WRITE_sPLT
  160268. # define PNG_WRITE_sPLT_SUPPORTED
  160269. # ifndef PNG_sPLT_SUPPORTED
  160270. # define PNG_sPLT_SUPPORTED
  160271. # endif
  160272. #endif
  160273. #ifndef PNG_NO_WRITE_sRGB
  160274. # define PNG_WRITE_sRGB_SUPPORTED
  160275. # ifndef PNG_sRGB_SUPPORTED
  160276. # define PNG_sRGB_SUPPORTED
  160277. # endif
  160278. #endif
  160279. #ifndef PNG_NO_WRITE_tEXt
  160280. # define PNG_WRITE_tEXt_SUPPORTED
  160281. # ifndef PNG_tEXt_SUPPORTED
  160282. # define PNG_tEXt_SUPPORTED
  160283. # endif
  160284. #endif
  160285. #ifndef PNG_NO_WRITE_tIME
  160286. # define PNG_WRITE_tIME_SUPPORTED
  160287. # ifndef PNG_tIME_SUPPORTED
  160288. # define PNG_tIME_SUPPORTED
  160289. # endif
  160290. #endif
  160291. #ifndef PNG_NO_WRITE_tRNS
  160292. # define PNG_WRITE_tRNS_SUPPORTED
  160293. # ifndef PNG_tRNS_SUPPORTED
  160294. # define PNG_tRNS_SUPPORTED
  160295. # endif
  160296. #endif
  160297. #ifndef PNG_NO_WRITE_zTXt
  160298. # define PNG_WRITE_zTXt_SUPPORTED
  160299. # ifndef PNG_zTXt_SUPPORTED
  160300. # define PNG_zTXt_SUPPORTED
  160301. # endif
  160302. #endif
  160303. #ifndef PNG_NO_WRITE_UNKNOWN_CHUNKS
  160304. # define PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
  160305. # ifndef PNG_UNKNOWN_CHUNKS_SUPPORTED
  160306. # define PNG_UNKNOWN_CHUNKS_SUPPORTED
  160307. # endif
  160308. # ifndef PNG_NO_HANDLE_AS_UNKNOWN
  160309. # ifndef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  160310. # define PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  160311. # endif
  160312. # endif
  160313. #endif
  160314. #if defined(PNG_WRITE_iTXt_SUPPORTED) || defined(PNG_WRITE_tEXt_SUPPORTED) || \
  160315. defined(PNG_WRITE_zTXt_SUPPORTED)
  160316. # define PNG_WRITE_TEXT_SUPPORTED
  160317. # ifndef PNG_TEXT_SUPPORTED
  160318. # define PNG_TEXT_SUPPORTED
  160319. # endif
  160320. #endif
  160321. #endif /* PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED */
  160322. #ifndef PNG_NO_INFO_IMAGE
  160323. # define PNG_INFO_IMAGE_SUPPORTED
  160324. #endif
  160325. #if defined(PNG_tIME_SUPPORTED)
  160326. # if !defined(_WIN32_WCE)
  160327. # include <time.h>
  160328. # endif
  160329. #endif
  160330. typedef unsigned long png_uint_32;
  160331. typedef long png_int_32;
  160332. typedef unsigned short png_uint_16;
  160333. typedef short png_int_16;
  160334. typedef unsigned char png_byte;
  160335. #ifdef PNG_SIZE_T
  160336. typedef PNG_SIZE_T png_size_t;
  160337. # define png_sizeof(x) png_convert_size(sizeof (x))
  160338. #else
  160339. typedef size_t png_size_t;
  160340. # define png_sizeof(x) sizeof (x)
  160341. #endif
  160342. #ifdef __BORLANDC__
  160343. # if defined(__LARGE__) || defined(__HUGE__) || defined(__COMPACT__)
  160344. # define LDATA 1
  160345. # else
  160346. # define LDATA 0
  160347. # endif
  160348. # if !defined(__WIN32__) && !defined(__FLAT__) && !defined(__CYGWIN__)
  160349. # define PNG_MAX_MALLOC_64K
  160350. # if (LDATA != 1)
  160351. # ifndef FAR
  160352. # define FAR __far
  160353. # endif
  160354. # define USE_FAR_KEYWORD
  160355. # endif /* LDATA != 1 */
  160356. # endif /* __WIN32__, __FLAT__, __CYGWIN__ */
  160357. #endif /* __BORLANDC__ */
  160358. #if defined(FAR)
  160359. # if defined(M_I86MM)
  160360. # define USE_FAR_KEYWORD
  160361. # define FARDATA FAR
  160362. # include <dos.h>
  160363. # endif
  160364. #endif
  160365. #ifndef FAR
  160366. # define FAR
  160367. #endif
  160368. #ifndef FARDATA
  160369. # define FARDATA
  160370. #endif
  160371. typedef png_int_32 png_fixed_point;
  160372. typedef void FAR * png_voidp;
  160373. typedef png_byte FAR * png_bytep;
  160374. typedef png_uint_32 FAR * png_uint_32p;
  160375. typedef png_int_32 FAR * png_int_32p;
  160376. typedef png_uint_16 FAR * png_uint_16p;
  160377. typedef png_int_16 FAR * png_int_16p;
  160378. typedef PNG_CONST char FAR * png_const_charp;
  160379. typedef char FAR * png_charp;
  160380. typedef png_fixed_point FAR * png_fixed_point_p;
  160381. #ifndef PNG_NO_STDIO
  160382. #if defined(_WIN32_WCE)
  160383. typedef HANDLE png_FILE_p;
  160384. #else
  160385. typedef FILE * png_FILE_p;
  160386. #endif
  160387. #endif
  160388. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160389. typedef double FAR * png_doublep;
  160390. #endif
  160391. typedef png_byte FAR * FAR * png_bytepp;
  160392. typedef png_uint_32 FAR * FAR * png_uint_32pp;
  160393. typedef png_int_32 FAR * FAR * png_int_32pp;
  160394. typedef png_uint_16 FAR * FAR * png_uint_16pp;
  160395. typedef png_int_16 FAR * FAR * png_int_16pp;
  160396. typedef PNG_CONST char FAR * FAR * png_const_charpp;
  160397. typedef char FAR * FAR * png_charpp;
  160398. typedef png_fixed_point FAR * FAR * png_fixed_point_pp;
  160399. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160400. typedef double FAR * FAR * png_doublepp;
  160401. #endif
  160402. typedef char FAR * FAR * FAR * png_charppp;
  160403. #if 0
  160404. typedef charf * png_zcharp;
  160405. typedef charf * FAR * png_zcharpp;
  160406. typedef z_stream FAR * png_zstreamp;
  160407. #endif /* (PNG_1_0_X) || defined(PNG_1_2_X) */
  160408. #if !defined(PNG_DLL) && (defined(PNG_BUILD_DLL) || defined(PNG_USE_DLL))
  160409. # define PNG_DLL
  160410. #endif
  160411. #if defined(__CYGWIN__)
  160412. # if !defined(PNG_STATIC)
  160413. # if defined(PNG_USE_GLOBAL_ARRAYS)
  160414. # undef PNG_USE_GLOBAL_ARRAYS
  160415. # endif
  160416. # if !defined(PNG_USE_LOCAL_ARRAYS)
  160417. # define PNG_USE_LOCAL_ARRAYS
  160418. # endif
  160419. # else
  160420. # if defined(PNG_USE_LOCAL_ARRAYS) || defined(PNG_NO_GLOBAL_ARRAYS)
  160421. # if defined(PNG_USE_GLOBAL_ARRAYS)
  160422. # undef PNG_USE_GLOBAL_ARRAYS
  160423. # endif
  160424. # endif
  160425. # endif
  160426. # if !defined(PNG_USE_LOCAL_ARRAYS) && !defined(PNG_USE_GLOBAL_ARRAYS)
  160427. # define PNG_USE_LOCAL_ARRAYS
  160428. # endif
  160429. #endif
  160430. #if !defined(PNG_USE_LOCAL_ARRAYS) && !defined(PNG_USE_GLOBAL_ARRAYS)
  160431. # if defined(PNG_NO_GLOBAL_ARRAYS) || \
  160432. (defined(__GNUC__) && defined(PNG_DLL)) || defined(_MSC_VER)
  160433. # define PNG_USE_LOCAL_ARRAYS
  160434. # else
  160435. # define PNG_USE_GLOBAL_ARRAYS
  160436. # endif
  160437. #endif
  160438. #if defined(__CYGWIN__)
  160439. # undef PNGAPI
  160440. # define PNGAPI __cdecl
  160441. # undef PNG_IMPEXP
  160442. # define PNG_IMPEXP
  160443. #endif
  160444. #if defined(__MINGW32__) && !defined(PNG_MODULEDEF)
  160445. # ifndef PNG_NO_MODULEDEF
  160446. # define PNG_NO_MODULEDEF
  160447. # endif
  160448. #endif
  160449. #if !defined(PNG_IMPEXP) && defined(PNG_BUILD_DLL) && !defined(PNG_NO_MODULEDEF)
  160450. # define PNG_IMPEXP
  160451. #endif
  160452. #if defined(PNG_DLL) || defined(_DLL) || defined(__DLL__ ) || \
  160453. (( defined(_Windows) || defined(_WINDOWS) || \
  160454. defined(WIN32) || defined(_WIN32) || defined(__WIN32__) ))
  160455. # ifndef PNGAPI
  160456. # if defined(__GNUC__) || (defined (_MSC_VER) && (_MSC_VER >= 800))
  160457. # define PNGAPI __cdecl
  160458. # else
  160459. # define PNGAPI _cdecl
  160460. # endif
  160461. # endif
  160462. # if !defined(PNG_IMPEXP) && (!defined(PNG_DLL) || \
  160463. 0 /* WINCOMPILER_WITH_NO_SUPPORT_FOR_DECLIMPEXP */)
  160464. # define PNG_IMPEXP
  160465. # endif
  160466. # if !defined(PNG_IMPEXP)
  160467. # define PNG_EXPORT_TYPE1(type,symbol) PNG_IMPEXP type PNGAPI symbol
  160468. # define PNG_EXPORT_TYPE2(type,symbol) type PNG_IMPEXP PNGAPI symbol
  160469. # if defined(_MSC_VER) || defined(__BORLANDC__)
  160470. # if (_MSC_VER >= 800) || (__BORLANDC__ >= 0x500)
  160471. # define PNG_EXPORT PNG_EXPORT_TYPE1
  160472. # else
  160473. # define PNG_EXPORT PNG_EXPORT_TYPE2
  160474. # if defined(PNG_BUILD_DLL)
  160475. # define PNG_IMPEXP __export
  160476. # else
  160477. # define PNG_IMPEXP /*__import */ /* doesn't exist AFAIK in
  160478. VC++ */
  160479. # endif /* Exists in Borland C++ for
  160480. C++ classes (== huge) */
  160481. # endif
  160482. # endif
  160483. # if !defined(PNG_IMPEXP)
  160484. # if defined(PNG_BUILD_DLL)
  160485. # define PNG_IMPEXP __declspec(dllexport)
  160486. # else
  160487. # define PNG_IMPEXP __declspec(dllimport)
  160488. # endif
  160489. # endif
  160490. # endif /* PNG_IMPEXP */
  160491. #else /* !(DLL || non-cygwin WINDOWS) */
  160492. # if (defined(__IBMC__) || defined(__IBMCPP__)) && defined(__OS2__)
  160493. # ifndef PNGAPI
  160494. # define PNGAPI _System
  160495. # endif
  160496. # else
  160497. # if 0 /* ... other platforms, with other meanings */
  160498. # endif
  160499. # endif
  160500. #endif
  160501. #ifndef PNGAPI
  160502. # define PNGAPI
  160503. #endif
  160504. #ifndef PNG_IMPEXP
  160505. # define PNG_IMPEXP
  160506. #endif
  160507. #ifdef PNG_BUILDSYMS
  160508. # ifndef PNG_EXPORT
  160509. # define PNG_EXPORT(type,symbol) PNG_FUNCTION_EXPORT symbol END
  160510. # endif
  160511. # ifdef PNG_USE_GLOBAL_ARRAYS
  160512. # ifndef PNG_EXPORT_VAR
  160513. # define PNG_EXPORT_VAR(type) PNG_DATA_EXPORT
  160514. # endif
  160515. # endif
  160516. #endif
  160517. #ifndef PNG_EXPORT
  160518. # define PNG_EXPORT(type,symbol) PNG_IMPEXP type PNGAPI symbol
  160519. #endif
  160520. #ifdef PNG_USE_GLOBAL_ARRAYS
  160521. # ifndef PNG_EXPORT_VAR
  160522. # define PNG_EXPORT_VAR(type) extern PNG_IMPEXP type
  160523. # endif
  160524. #endif
  160525. #ifndef PNG_ABORT
  160526. # define PNG_ABORT() abort()
  160527. #endif
  160528. #ifdef PNG_SETJMP_SUPPORTED
  160529. # define png_jmpbuf(png_ptr) ((png_ptr)->jmpbuf)
  160530. #else
  160531. # define png_jmpbuf(png_ptr) \
  160532. (LIBPNG_WAS_COMPILED_WITH__PNG_SETJMP_NOT_SUPPORTED)
  160533. #endif
  160534. #if defined(USE_FAR_KEYWORD) /* memory model independent fns */
  160535. # define CHECK 1
  160536. # define NOCHECK 0
  160537. # define CVT_PTR(ptr) (png_far_to_near(png_ptr,ptr,CHECK))
  160538. # define CVT_PTR_NOCHECK(ptr) (png_far_to_near(png_ptr,ptr,NOCHECK))
  160539. # define png_snprintf _fsnprintf /* Added to v 1.2.19 */
  160540. # define png_strcpy _fstrcpy
  160541. # define png_strncpy _fstrncpy /* Added to v 1.2.6 */
  160542. # define png_strlen _fstrlen
  160543. # define png_memcmp _fmemcmp /* SJT: added */
  160544. # define png_memcpy _fmemcpy
  160545. # define png_memset _fmemset
  160546. #else /* use the usual functions */
  160547. # define CVT_PTR(ptr) (ptr)
  160548. # define CVT_PTR_NOCHECK(ptr) (ptr)
  160549. # ifndef PNG_NO_SNPRINTF
  160550. # ifdef _MSC_VER
  160551. # define png_snprintf _snprintf /* Added to v 1.2.19 */
  160552. # define png_snprintf2 _snprintf
  160553. # define png_snprintf6 _snprintf
  160554. # else
  160555. # define png_snprintf snprintf /* Added to v 1.2.19 */
  160556. # define png_snprintf2 snprintf
  160557. # define png_snprintf6 snprintf
  160558. # endif
  160559. # else
  160560. # define png_snprintf(s1,n,fmt,x1) sprintf(s1,fmt,x1)
  160561. # define png_snprintf2(s1,n,fmt,x1,x2) sprintf(s1,fmt,x1,x2)
  160562. # define png_snprintf6(s1,n,fmt,x1,x2,x3,x4,x5,x6) \
  160563. sprintf(s1,fmt,x1,x2,x3,x4,x5,x6)
  160564. # endif
  160565. # define png_strcpy strcpy
  160566. # define png_strncpy strncpy /* Added to v 1.2.6 */
  160567. # define png_strlen strlen
  160568. # define png_memcmp memcmp /* SJT: added */
  160569. # define png_memcpy memcpy
  160570. # define png_memset memset
  160571. #endif
  160572. #if (PNG_ZBUF_SIZE > 65536L) && defined(PNG_MAX_MALLOC_64K)
  160573. # undef PNG_ZBUF_SIZE
  160574. # define PNG_ZBUF_SIZE 65536L
  160575. #endif
  160576. #endif /* PNG_VERSION_INFO_ONLY */
  160577. #endif /* PNGCONF_H */
  160578. /*** End of inlined file: pngconf.h ***/
  160579. #ifdef _MSC_VER
  160580. #pragma warning (disable: 4996 4100)
  160581. #endif
  160582. #if defined(PNG_USER_PRIVATEBUILD)
  160583. # define PNG_LIBPNG_BUILD_TYPE \
  160584. (PNG_LIBPNG_BUILD_BASE_TYPE | PNG_LIBPNG_BUILD_PRIVATE)
  160585. #else
  160586. # if defined(PNG_LIBPNG_SPECIALBUILD)
  160587. # define PNG_LIBPNG_BUILD_TYPE \
  160588. (PNG_LIBPNG_BUILD_BASE_TYPE | PNG_LIBPNG_BUILD_SPECIAL)
  160589. # else
  160590. # define PNG_LIBPNG_BUILD_TYPE (PNG_LIBPNG_BUILD_BASE_TYPE)
  160591. # endif
  160592. #endif
  160593. #ifndef PNG_VERSION_INFO_ONLY
  160594. #ifdef __cplusplus
  160595. extern "C" {
  160596. #endif /* __cplusplus */
  160597. #ifndef PNG_NO_TYPECAST_NULL
  160598. #define int_p_NULL (int *)NULL
  160599. #define png_bytep_NULL (png_bytep)NULL
  160600. #define png_bytepp_NULL (png_bytepp)NULL
  160601. #define png_doublep_NULL (png_doublep)NULL
  160602. #define png_error_ptr_NULL (png_error_ptr)NULL
  160603. #define png_flush_ptr_NULL (png_flush_ptr)NULL
  160604. #define png_free_ptr_NULL (png_free_ptr)NULL
  160605. #define png_infopp_NULL (png_infopp)NULL
  160606. #define png_malloc_ptr_NULL (png_malloc_ptr)NULL
  160607. #define png_read_status_ptr_NULL (png_read_status_ptr)NULL
  160608. #define png_rw_ptr_NULL (png_rw_ptr)NULL
  160609. #define png_structp_NULL (png_structp)NULL
  160610. #define png_uint_16p_NULL (png_uint_16p)NULL
  160611. #define png_voidp_NULL (png_voidp)NULL
  160612. #define png_write_status_ptr_NULL (png_write_status_ptr)NULL
  160613. #else
  160614. #define int_p_NULL NULL
  160615. #define png_bytep_NULL NULL
  160616. #define png_bytepp_NULL NULL
  160617. #define png_doublep_NULL NULL
  160618. #define png_error_ptr_NULL NULL
  160619. #define png_flush_ptr_NULL NULL
  160620. #define png_free_ptr_NULL NULL
  160621. #define png_infopp_NULL NULL
  160622. #define png_malloc_ptr_NULL NULL
  160623. #define png_read_status_ptr_NULL NULL
  160624. #define png_rw_ptr_NULL NULL
  160625. #define png_structp_NULL NULL
  160626. #define png_uint_16p_NULL NULL
  160627. #define png_voidp_NULL NULL
  160628. #define png_write_status_ptr_NULL NULL
  160629. #endif
  160630. #if !defined(PNG_NO_EXTERN) || defined(PNG_ALWAYS_EXTERN)
  160631. #ifdef PNG_USE_GLOBAL_ARRAYS
  160632. PNG_EXPORT_VAR (PNG_CONST char) png_libpng_ver[18];
  160633. #else
  160634. #define png_libpng_ver png_get_header_ver(NULL)
  160635. #endif
  160636. #ifdef PNG_USE_GLOBAL_ARRAYS
  160637. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_start[7];
  160638. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_inc[7];
  160639. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_ystart[7];
  160640. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_yinc[7];
  160641. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_mask[7];
  160642. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_dsp_mask[7];
  160643. #endif
  160644. #endif /* PNG_NO_EXTERN */
  160645. typedef struct png_color_struct
  160646. {
  160647. png_byte red;
  160648. png_byte green;
  160649. png_byte blue;
  160650. } png_color;
  160651. typedef png_color FAR * png_colorp;
  160652. typedef png_color FAR * FAR * png_colorpp;
  160653. typedef struct png_color_16_struct
  160654. {
  160655. png_byte index; /* used for palette files */
  160656. png_uint_16 red; /* for use in red green blue files */
  160657. png_uint_16 green;
  160658. png_uint_16 blue;
  160659. png_uint_16 gray; /* for use in grayscale files */
  160660. } png_color_16;
  160661. typedef png_color_16 FAR * png_color_16p;
  160662. typedef png_color_16 FAR * FAR * png_color_16pp;
  160663. typedef struct png_color_8_struct
  160664. {
  160665. png_byte red; /* for use in red green blue files */
  160666. png_byte green;
  160667. png_byte blue;
  160668. png_byte gray; /* for use in grayscale files */
  160669. png_byte alpha; /* for alpha channel files */
  160670. } png_color_8;
  160671. typedef png_color_8 FAR * png_color_8p;
  160672. typedef png_color_8 FAR * FAR * png_color_8pp;
  160673. typedef struct png_sPLT_entry_struct
  160674. {
  160675. png_uint_16 red;
  160676. png_uint_16 green;
  160677. png_uint_16 blue;
  160678. png_uint_16 alpha;
  160679. png_uint_16 frequency;
  160680. } png_sPLT_entry;
  160681. typedef png_sPLT_entry FAR * png_sPLT_entryp;
  160682. typedef png_sPLT_entry FAR * FAR * png_sPLT_entrypp;
  160683. typedef struct png_sPLT_struct
  160684. {
  160685. png_charp name; /* palette name */
  160686. png_byte depth; /* depth of palette samples */
  160687. png_sPLT_entryp entries; /* palette entries */
  160688. png_int_32 nentries; /* number of palette entries */
  160689. } png_sPLT_t;
  160690. typedef png_sPLT_t FAR * png_sPLT_tp;
  160691. typedef png_sPLT_t FAR * FAR * png_sPLT_tpp;
  160692. #ifdef PNG_TEXT_SUPPORTED
  160693. typedef struct png_text_struct
  160694. {
  160695. int compression; /* compression value:
  160696. -1: tEXt, none
  160697. 0: zTXt, deflate
  160698. 1: iTXt, none
  160699. 2: iTXt, deflate */
  160700. png_charp key; /* keyword, 1-79 character description of "text" */
  160701. png_charp text; /* comment, may be an empty string (ie "")
  160702. or a NULL pointer */
  160703. png_size_t text_length; /* length of the text string */
  160704. #ifdef PNG_iTXt_SUPPORTED
  160705. png_size_t itxt_length; /* length of the itxt string */
  160706. png_charp lang; /* language code, 0-79 characters
  160707. or a NULL pointer */
  160708. png_charp lang_key; /* keyword translated UTF-8 string, 0 or more
  160709. chars or a NULL pointer */
  160710. #endif
  160711. } png_text;
  160712. typedef png_text FAR * png_textp;
  160713. typedef png_text FAR * FAR * png_textpp;
  160714. #endif
  160715. #define PNG_TEXT_COMPRESSION_NONE_WR -3
  160716. #define PNG_TEXT_COMPRESSION_zTXt_WR -2
  160717. #define PNG_TEXT_COMPRESSION_NONE -1
  160718. #define PNG_TEXT_COMPRESSION_zTXt 0
  160719. #define PNG_ITXT_COMPRESSION_NONE 1
  160720. #define PNG_ITXT_COMPRESSION_zTXt 2
  160721. #define PNG_TEXT_COMPRESSION_LAST 3 /* Not a valid value */
  160722. typedef struct png_time_struct
  160723. {
  160724. png_uint_16 year; /* full year, as in, 1995 */
  160725. png_byte month; /* month of year, 1 - 12 */
  160726. png_byte day; /* day of month, 1 - 31 */
  160727. png_byte hour; /* hour of day, 0 - 23 */
  160728. png_byte minute; /* minute of hour, 0 - 59 */
  160729. png_byte second; /* second of minute, 0 - 60 (for leap seconds) */
  160730. } png_time;
  160731. typedef png_time FAR * png_timep;
  160732. typedef png_time FAR * FAR * png_timepp;
  160733. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  160734. typedef struct png_unknown_chunk_t
  160735. {
  160736. png_byte name[5];
  160737. png_byte *data;
  160738. png_size_t size;
  160739. png_byte location; /* mode of operation at read time */
  160740. }
  160741. png_unknown_chunk;
  160742. typedef png_unknown_chunk FAR * png_unknown_chunkp;
  160743. typedef png_unknown_chunk FAR * FAR * png_unknown_chunkpp;
  160744. #endif
  160745. typedef struct png_info_struct
  160746. {
  160747. png_uint_32 width; /* width of image in pixels (from IHDR) */
  160748. png_uint_32 height; /* height of image in pixels (from IHDR) */
  160749. png_uint_32 valid; /* valid chunk data (see PNG_INFO_ below) */
  160750. png_uint_32 rowbytes; /* bytes needed to hold an untransformed row */
  160751. png_colorp palette; /* array of color values (valid & PNG_INFO_PLTE) */
  160752. png_uint_16 num_palette; /* number of color entries in "palette" (PLTE) */
  160753. png_uint_16 num_trans; /* number of transparent palette color (tRNS) */
  160754. png_byte bit_depth; /* 1, 2, 4, 8, or 16 bits/channel (from IHDR) */
  160755. png_byte color_type; /* see PNG_COLOR_TYPE_ below (from IHDR) */
  160756. png_byte compression_type; /* must be PNG_COMPRESSION_TYPE_BASE (IHDR) */
  160757. png_byte filter_type; /* must be PNG_FILTER_TYPE_BASE (from IHDR) */
  160758. png_byte interlace_type; /* One of PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
  160759. png_byte channels; /* number of data channels per pixel (1, 2, 3, 4) */
  160760. png_byte pixel_depth; /* number of bits per pixel */
  160761. png_byte spare_byte; /* to align the data, and for future use */
  160762. png_byte signature[8]; /* magic bytes read by libpng from start of file */
  160763. #if defined(PNG_gAMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
  160764. float gamma; /* gamma value of image, if (valid & PNG_INFO_gAMA) */
  160765. #endif
  160766. #if defined(PNG_sRGB_SUPPORTED)
  160767. png_byte srgb_intent; /* sRGB rendering intent [0, 1, 2, or 3] */
  160768. #endif
  160769. #if defined(PNG_TEXT_SUPPORTED)
  160770. int num_text; /* number of comments read/to write */
  160771. int max_text; /* current size of text array */
  160772. png_textp text; /* array of comments read/to write */
  160773. #endif /* PNG_TEXT_SUPPORTED */
  160774. #if defined(PNG_tIME_SUPPORTED)
  160775. png_time mod_time;
  160776. #endif
  160777. #if defined(PNG_sBIT_SUPPORTED)
  160778. png_color_8 sig_bit; /* significant bits in color channels */
  160779. #endif
  160780. #if defined(PNG_tRNS_SUPPORTED) || defined(PNG_READ_EXPAND_SUPPORTED) || \
  160781. defined(PNG_READ_BACKGROUND_SUPPORTED)
  160782. png_bytep trans; /* transparent values for paletted image */
  160783. png_color_16 trans_values; /* transparent color for non-palette image */
  160784. #endif
  160785. #if defined(PNG_bKGD_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  160786. png_color_16 background;
  160787. #endif
  160788. #if defined(PNG_oFFs_SUPPORTED)
  160789. png_int_32 x_offset; /* x offset on page */
  160790. png_int_32 y_offset; /* y offset on page */
  160791. png_byte offset_unit_type; /* offset units type */
  160792. #endif
  160793. #if defined(PNG_pHYs_SUPPORTED)
  160794. png_uint_32 x_pixels_per_unit; /* horizontal pixel density */
  160795. png_uint_32 y_pixels_per_unit; /* vertical pixel density */
  160796. png_byte phys_unit_type; /* resolution type (see PNG_RESOLUTION_ below) */
  160797. #endif
  160798. #if defined(PNG_hIST_SUPPORTED)
  160799. png_uint_16p hist;
  160800. #endif
  160801. #ifdef PNG_cHRM_SUPPORTED
  160802. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160803. float x_white;
  160804. float y_white;
  160805. float x_red;
  160806. float y_red;
  160807. float x_green;
  160808. float y_green;
  160809. float x_blue;
  160810. float y_blue;
  160811. #endif
  160812. #endif
  160813. #if defined(PNG_pCAL_SUPPORTED)
  160814. png_charp pcal_purpose; /* pCAL chunk description string */
  160815. png_int_32 pcal_X0; /* minimum value */
  160816. png_int_32 pcal_X1; /* maximum value */
  160817. png_charp pcal_units; /* Latin-1 string giving physical units */
  160818. png_charpp pcal_params; /* ASCII strings containing parameter values */
  160819. png_byte pcal_type; /* equation type (see PNG_EQUATION_ below) */
  160820. png_byte pcal_nparams; /* number of parameters given in pcal_params */
  160821. #endif
  160822. #ifdef PNG_FREE_ME_SUPPORTED
  160823. png_uint_32 free_me; /* flags items libpng is responsible for freeing */
  160824. #endif
  160825. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  160826. png_unknown_chunkp unknown_chunks;
  160827. png_size_t unknown_chunks_num;
  160828. #endif
  160829. #if defined(PNG_iCCP_SUPPORTED)
  160830. png_charp iccp_name; /* profile name */
  160831. png_charp iccp_profile; /* International Color Consortium profile data */
  160832. png_uint_32 iccp_proflen; /* ICC profile data length */
  160833. png_byte iccp_compression; /* Always zero */
  160834. #endif
  160835. #if defined(PNG_sPLT_SUPPORTED)
  160836. png_sPLT_tp splt_palettes;
  160837. png_uint_32 splt_palettes_num;
  160838. #endif
  160839. #if defined(PNG_sCAL_SUPPORTED)
  160840. png_byte scal_unit; /* unit of physical scale */
  160841. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160842. double scal_pixel_width; /* width of one pixel */
  160843. double scal_pixel_height; /* height of one pixel */
  160844. #endif
  160845. #ifdef PNG_FIXED_POINT_SUPPORTED
  160846. png_charp scal_s_width; /* string containing height */
  160847. png_charp scal_s_height; /* string containing width */
  160848. #endif
  160849. #endif
  160850. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  160851. png_bytepp row_pointers; /* the image bits */
  160852. #endif
  160853. #if defined(PNG_FIXED_POINT_SUPPORTED) && defined(PNG_gAMA_SUPPORTED)
  160854. png_fixed_point int_gamma; /* gamma of image, if (valid & PNG_INFO_gAMA) */
  160855. #endif
  160856. #if defined(PNG_cHRM_SUPPORTED) && defined(PNG_FIXED_POINT_SUPPORTED)
  160857. png_fixed_point int_x_white;
  160858. png_fixed_point int_y_white;
  160859. png_fixed_point int_x_red;
  160860. png_fixed_point int_y_red;
  160861. png_fixed_point int_x_green;
  160862. png_fixed_point int_y_green;
  160863. png_fixed_point int_x_blue;
  160864. png_fixed_point int_y_blue;
  160865. #endif
  160866. } png_info;
  160867. typedef png_info FAR * png_infop;
  160868. typedef png_info FAR * FAR * png_infopp;
  160869. #define PNG_UINT_31_MAX ((png_uint_32)0x7fffffffL)
  160870. #define PNG_UINT_32_MAX ((png_uint_32)(-1))
  160871. #define PNG_SIZE_MAX ((png_size_t)(-1))
  160872. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  160873. #define PNG_MAX_UINT PNG_UINT_31_MAX
  160874. #endif
  160875. #define PNG_COLOR_MASK_PALETTE 1
  160876. #define PNG_COLOR_MASK_COLOR 2
  160877. #define PNG_COLOR_MASK_ALPHA 4
  160878. #define PNG_COLOR_TYPE_GRAY 0
  160879. #define PNG_COLOR_TYPE_PALETTE (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_PALETTE)
  160880. #define PNG_COLOR_TYPE_RGB (PNG_COLOR_MASK_COLOR)
  160881. #define PNG_COLOR_TYPE_RGB_ALPHA (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_ALPHA)
  160882. #define PNG_COLOR_TYPE_GRAY_ALPHA (PNG_COLOR_MASK_ALPHA)
  160883. #define PNG_COLOR_TYPE_RGBA PNG_COLOR_TYPE_RGB_ALPHA
  160884. #define PNG_COLOR_TYPE_GA PNG_COLOR_TYPE_GRAY_ALPHA
  160885. #define PNG_COMPRESSION_TYPE_BASE 0 /* Deflate method 8, 32K window */
  160886. #define PNG_COMPRESSION_TYPE_DEFAULT PNG_COMPRESSION_TYPE_BASE
  160887. #define PNG_FILTER_TYPE_BASE 0 /* Single row per-byte filtering */
  160888. #define PNG_INTRAPIXEL_DIFFERENCING 64 /* Used only in MNG datastreams */
  160889. #define PNG_FILTER_TYPE_DEFAULT PNG_FILTER_TYPE_BASE
  160890. #define PNG_INTERLACE_NONE 0 /* Non-interlaced image */
  160891. #define PNG_INTERLACE_ADAM7 1 /* Adam7 interlacing */
  160892. #define PNG_INTERLACE_LAST 2 /* Not a valid value */
  160893. #define PNG_OFFSET_PIXEL 0 /* Offset in pixels */
  160894. #define PNG_OFFSET_MICROMETER 1 /* Offset in micrometers (1/10^6 meter) */
  160895. #define PNG_OFFSET_LAST 2 /* Not a valid value */
  160896. #define PNG_EQUATION_LINEAR 0 /* Linear transformation */
  160897. #define PNG_EQUATION_BASE_E 1 /* Exponential base e transform */
  160898. #define PNG_EQUATION_ARBITRARY 2 /* Arbitrary base exponential transform */
  160899. #define PNG_EQUATION_HYPERBOLIC 3 /* Hyperbolic sine transformation */
  160900. #define PNG_EQUATION_LAST 4 /* Not a valid value */
  160901. #define PNG_SCALE_UNKNOWN 0 /* unknown unit (image scale) */
  160902. #define PNG_SCALE_METER 1 /* meters per pixel */
  160903. #define PNG_SCALE_RADIAN 2 /* radians per pixel */
  160904. #define PNG_SCALE_LAST 3 /* Not a valid value */
  160905. #define PNG_RESOLUTION_UNKNOWN 0 /* pixels/unknown unit (aspect ratio) */
  160906. #define PNG_RESOLUTION_METER 1 /* pixels/meter */
  160907. #define PNG_RESOLUTION_LAST 2 /* Not a valid value */
  160908. #define PNG_sRGB_INTENT_PERCEPTUAL 0
  160909. #define PNG_sRGB_INTENT_RELATIVE 1
  160910. #define PNG_sRGB_INTENT_SATURATION 2
  160911. #define PNG_sRGB_INTENT_ABSOLUTE 3
  160912. #define PNG_sRGB_INTENT_LAST 4 /* Not a valid value */
  160913. #define PNG_KEYWORD_MAX_LENGTH 79
  160914. #define PNG_MAX_PALETTE_LENGTH 256
  160915. #define PNG_INFO_gAMA 0x0001
  160916. #define PNG_INFO_sBIT 0x0002
  160917. #define PNG_INFO_cHRM 0x0004
  160918. #define PNG_INFO_PLTE 0x0008
  160919. #define PNG_INFO_tRNS 0x0010
  160920. #define PNG_INFO_bKGD 0x0020
  160921. #define PNG_INFO_hIST 0x0040
  160922. #define PNG_INFO_pHYs 0x0080
  160923. #define PNG_INFO_oFFs 0x0100
  160924. #define PNG_INFO_tIME 0x0200
  160925. #define PNG_INFO_pCAL 0x0400
  160926. #define PNG_INFO_sRGB 0x0800 /* GR-P, 0.96a */
  160927. #define PNG_INFO_iCCP 0x1000 /* ESR, 1.0.6 */
  160928. #define PNG_INFO_sPLT 0x2000 /* ESR, 1.0.6 */
  160929. #define PNG_INFO_sCAL 0x4000 /* ESR, 1.0.6 */
  160930. #define PNG_INFO_IDAT 0x8000L /* ESR, 1.0.6 */
  160931. typedef struct png_row_info_struct
  160932. {
  160933. png_uint_32 width; /* width of row */
  160934. png_uint_32 rowbytes; /* number of bytes in row */
  160935. png_byte color_type; /* color type of row */
  160936. png_byte bit_depth; /* bit depth of row */
  160937. png_byte channels; /* number of channels (1, 2, 3, or 4) */
  160938. png_byte pixel_depth; /* bits per pixel (depth * channels) */
  160939. } png_row_info;
  160940. typedef png_row_info FAR * png_row_infop;
  160941. typedef png_row_info FAR * FAR * png_row_infopp;
  160942. typedef struct png_struct_def png_struct;
  160943. typedef png_struct FAR * png_structp;
  160944. typedef void (PNGAPI *png_error_ptr) PNGARG((png_structp, png_const_charp));
  160945. typedef void (PNGAPI *png_rw_ptr) PNGARG((png_structp, png_bytep, png_size_t));
  160946. typedef void (PNGAPI *png_flush_ptr) PNGARG((png_structp));
  160947. typedef void (PNGAPI *png_read_status_ptr) PNGARG((png_structp, png_uint_32,
  160948. int));
  160949. typedef void (PNGAPI *png_write_status_ptr) PNGARG((png_structp, png_uint_32,
  160950. int));
  160951. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  160952. typedef void (PNGAPI *png_progressive_info_ptr) PNGARG((png_structp, png_infop));
  160953. typedef void (PNGAPI *png_progressive_end_ptr) PNGARG((png_structp, png_infop));
  160954. typedef void (PNGAPI *png_progressive_row_ptr) PNGARG((png_structp, png_bytep,
  160955. png_uint_32, int));
  160956. #endif
  160957. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  160958. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  160959. defined(PNG_LEGACY_SUPPORTED)
  160960. typedef void (PNGAPI *png_user_transform_ptr) PNGARG((png_structp,
  160961. png_row_infop, png_bytep));
  160962. #endif
  160963. #if defined(PNG_USER_CHUNKS_SUPPORTED)
  160964. typedef int (PNGAPI *png_user_chunk_ptr) PNGARG((png_structp, png_unknown_chunkp));
  160965. #endif
  160966. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  160967. typedef void (PNGAPI *png_unknown_chunk_ptr) PNGARG((png_structp));
  160968. #endif
  160969. #define PNG_TRANSFORM_IDENTITY 0x0000 /* read and write */
  160970. #define PNG_TRANSFORM_STRIP_16 0x0001 /* read only */
  160971. #define PNG_TRANSFORM_STRIP_ALPHA 0x0002 /* read only */
  160972. #define PNG_TRANSFORM_PACKING 0x0004 /* read and write */
  160973. #define PNG_TRANSFORM_PACKSWAP 0x0008 /* read and write */
  160974. #define PNG_TRANSFORM_EXPAND 0x0010 /* read only */
  160975. #define PNG_TRANSFORM_INVERT_MONO 0x0020 /* read and write */
  160976. #define PNG_TRANSFORM_SHIFT 0x0040 /* read and write */
  160977. #define PNG_TRANSFORM_BGR 0x0080 /* read and write */
  160978. #define PNG_TRANSFORM_SWAP_ALPHA 0x0100 /* read and write */
  160979. #define PNG_TRANSFORM_SWAP_ENDIAN 0x0200 /* read and write */
  160980. #define PNG_TRANSFORM_INVERT_ALPHA 0x0400 /* read and write */
  160981. #define PNG_TRANSFORM_STRIP_FILLER 0x0800 /* WRITE only */
  160982. #define PNG_FLAG_MNG_EMPTY_PLTE 0x01
  160983. #define PNG_FLAG_MNG_FILTER_64 0x04
  160984. #define PNG_ALL_MNG_FEATURES 0x05
  160985. typedef png_voidp (*png_malloc_ptr) PNGARG((png_structp, png_size_t));
  160986. typedef void (*png_free_ptr) PNGARG((png_structp, png_voidp));
  160987. struct png_struct_def
  160988. {
  160989. #ifdef PNG_SETJMP_SUPPORTED
  160990. jmp_buf jmpbuf; /* used in png_error */
  160991. #endif
  160992. png_error_ptr error_fn; /* function for printing errors and aborting */
  160993. png_error_ptr warning_fn; /* function for printing warnings */
  160994. png_voidp error_ptr; /* user supplied struct for error functions */
  160995. png_rw_ptr write_data_fn; /* function for writing output data */
  160996. png_rw_ptr read_data_fn; /* function for reading input data */
  160997. png_voidp io_ptr; /* ptr to application struct for I/O functions */
  160998. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
  160999. png_user_transform_ptr read_user_transform_fn; /* user read transform */
  161000. #endif
  161001. #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  161002. png_user_transform_ptr write_user_transform_fn; /* user write transform */
  161003. #endif
  161004. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  161005. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  161006. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  161007. png_voidp user_transform_ptr; /* user supplied struct for user transform */
  161008. png_byte user_transform_depth; /* bit depth of user transformed pixels */
  161009. png_byte user_transform_channels; /* channels in user transformed pixels */
  161010. #endif
  161011. #endif
  161012. png_uint_32 mode; /* tells us where we are in the PNG file */
  161013. png_uint_32 flags; /* flags indicating various things to libpng */
  161014. png_uint_32 transformations; /* which transformations to perform */
  161015. z_stream zstream; /* pointer to decompression structure (below) */
  161016. png_bytep zbuf; /* buffer for zlib */
  161017. png_size_t zbuf_size; /* size of zbuf */
  161018. int zlib_level; /* holds zlib compression level */
  161019. int zlib_method; /* holds zlib compression method */
  161020. int zlib_window_bits; /* holds zlib compression window bits */
  161021. int zlib_mem_level; /* holds zlib compression memory level */
  161022. int zlib_strategy; /* holds zlib compression strategy */
  161023. png_uint_32 width; /* width of image in pixels */
  161024. png_uint_32 height; /* height of image in pixels */
  161025. png_uint_32 num_rows; /* number of rows in current pass */
  161026. png_uint_32 usr_width; /* width of row at start of write */
  161027. png_uint_32 rowbytes; /* size of row in bytes */
  161028. png_uint_32 irowbytes; /* size of current interlaced row in bytes */
  161029. png_uint_32 iwidth; /* width of current interlaced row in pixels */
  161030. png_uint_32 row_number; /* current row in interlace pass */
  161031. png_bytep prev_row; /* buffer to save previous (unfiltered) row */
  161032. png_bytep row_buf; /* buffer to save current (unfiltered) row */
  161033. png_bytep sub_row; /* buffer to save "sub" row when filtering */
  161034. png_bytep up_row; /* buffer to save "up" row when filtering */
  161035. png_bytep avg_row; /* buffer to save "avg" row when filtering */
  161036. png_bytep paeth_row; /* buffer to save "Paeth" row when filtering */
  161037. png_row_info row_info; /* used for transformation routines */
  161038. png_uint_32 idat_size; /* current IDAT size for read */
  161039. png_uint_32 crc; /* current chunk CRC value */
  161040. png_colorp palette; /* palette from the input file */
  161041. png_uint_16 num_palette; /* number of color entries in palette */
  161042. png_uint_16 num_trans; /* number of transparency values */
  161043. png_byte chunk_name[5]; /* null-terminated name of current chunk */
  161044. png_byte compression; /* file compression type (always 0) */
  161045. png_byte filter; /* file filter type (always 0) */
  161046. png_byte interlaced; /* PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
  161047. png_byte pass; /* current interlace pass (0 - 6) */
  161048. png_byte do_filter; /* row filter flags (see PNG_FILTER_ below ) */
  161049. png_byte color_type; /* color type of file */
  161050. png_byte bit_depth; /* bit depth of file */
  161051. png_byte usr_bit_depth; /* bit depth of users row */
  161052. png_byte pixel_depth; /* number of bits per pixel */
  161053. png_byte channels; /* number of channels in file */
  161054. png_byte usr_channels; /* channels at start of write */
  161055. png_byte sig_bytes; /* magic bytes read/written from start of file */
  161056. #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
  161057. #ifdef PNG_LEGACY_SUPPORTED
  161058. png_byte filler; /* filler byte for pixel expansion */
  161059. #else
  161060. png_uint_16 filler; /* filler bytes for pixel expansion */
  161061. #endif
  161062. #endif
  161063. #if defined(PNG_bKGD_SUPPORTED)
  161064. png_byte background_gamma_type;
  161065. # ifdef PNG_FLOATING_POINT_SUPPORTED
  161066. float background_gamma;
  161067. # endif
  161068. png_color_16 background; /* background color in screen gamma space */
  161069. #if defined(PNG_READ_GAMMA_SUPPORTED)
  161070. png_color_16 background_1; /* background normalized to gamma 1.0 */
  161071. #endif
  161072. #endif /* PNG_bKGD_SUPPORTED */
  161073. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  161074. png_flush_ptr output_flush_fn;/* Function for flushing output */
  161075. png_uint_32 flush_dist; /* how many rows apart to flush, 0 - no flush */
  161076. png_uint_32 flush_rows; /* number of rows written since last flush */
  161077. #endif
  161078. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  161079. int gamma_shift; /* number of "insignificant" bits 16-bit gamma */
  161080. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161081. float gamma; /* file gamma value */
  161082. float screen_gamma; /* screen gamma value (display_exponent) */
  161083. #endif
  161084. #endif
  161085. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  161086. png_bytep gamma_table; /* gamma table for 8-bit depth files */
  161087. png_bytep gamma_from_1; /* converts from 1.0 to screen */
  161088. png_bytep gamma_to_1; /* converts from file to 1.0 */
  161089. png_uint_16pp gamma_16_table; /* gamma table for 16-bit depth files */
  161090. png_uint_16pp gamma_16_from_1; /* converts from 1.0 to screen */
  161091. png_uint_16pp gamma_16_to_1; /* converts from file to 1.0 */
  161092. #endif
  161093. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_sBIT_SUPPORTED)
  161094. png_color_8 sig_bit; /* significant bits in each available channel */
  161095. #endif
  161096. #if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
  161097. png_color_8 shift; /* shift for significant bit tranformation */
  161098. #endif
  161099. #if defined(PNG_tRNS_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) \
  161100. || defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  161101. png_bytep trans; /* transparency values for paletted files */
  161102. png_color_16 trans_values; /* transparency values for non-paletted files */
  161103. #endif
  161104. png_read_status_ptr read_row_fn; /* called after each row is decoded */
  161105. png_write_status_ptr write_row_fn; /* called after each row is encoded */
  161106. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  161107. png_progressive_info_ptr info_fn; /* called after header data fully read */
  161108. png_progressive_row_ptr row_fn; /* called after each prog. row is decoded */
  161109. png_progressive_end_ptr end_fn; /* called after image is complete */
  161110. png_bytep save_buffer_ptr; /* current location in save_buffer */
  161111. png_bytep save_buffer; /* buffer for previously read data */
  161112. png_bytep current_buffer_ptr; /* current location in current_buffer */
  161113. png_bytep current_buffer; /* buffer for recently used data */
  161114. png_uint_32 push_length; /* size of current input chunk */
  161115. png_uint_32 skip_length; /* bytes to skip in input data */
  161116. png_size_t save_buffer_size; /* amount of data now in save_buffer */
  161117. png_size_t save_buffer_max; /* total size of save_buffer */
  161118. png_size_t buffer_size; /* total amount of available input data */
  161119. png_size_t current_buffer_size; /* amount of data now in current_buffer */
  161120. int process_mode; /* what push library is currently doing */
  161121. int cur_palette; /* current push library palette index */
  161122. # if defined(PNG_TEXT_SUPPORTED)
  161123. png_size_t current_text_size; /* current size of text input data */
  161124. png_size_t current_text_left; /* how much text left to read in input */
  161125. png_charp current_text; /* current text chunk buffer */
  161126. png_charp current_text_ptr; /* current location in current_text */
  161127. # endif /* PNG_TEXT_SUPPORTED */
  161128. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  161129. #if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
  161130. png_bytepp offset_table_ptr;
  161131. png_bytep offset_table;
  161132. png_uint_16 offset_table_number;
  161133. png_uint_16 offset_table_count;
  161134. png_uint_16 offset_table_count_free;
  161135. #endif
  161136. #if defined(PNG_READ_DITHER_SUPPORTED)
  161137. png_bytep palette_lookup; /* lookup table for dithering */
  161138. png_bytep dither_index; /* index translation for palette files */
  161139. #endif
  161140. #if defined(PNG_READ_DITHER_SUPPORTED) || defined(PNG_hIST_SUPPORTED)
  161141. png_uint_16p hist; /* histogram */
  161142. #endif
  161143. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  161144. png_byte heuristic_method; /* heuristic for row filter selection */
  161145. png_byte num_prev_filters; /* number of weights for previous rows */
  161146. png_bytep prev_filters; /* filter type(s) of previous row(s) */
  161147. png_uint_16p filter_weights; /* weight(s) for previous line(s) */
  161148. png_uint_16p inv_filter_weights; /* 1/weight(s) for previous line(s) */
  161149. png_uint_16p filter_costs; /* relative filter calculation cost */
  161150. png_uint_16p inv_filter_costs; /* 1/relative filter calculation cost */
  161151. #endif
  161152. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  161153. png_charp time_buffer; /* String to hold RFC 1123 time text */
  161154. #endif
  161155. #ifdef PNG_FREE_ME_SUPPORTED
  161156. png_uint_32 free_me; /* flags items libpng is responsible for freeing */
  161157. #endif
  161158. #if defined(PNG_USER_CHUNKS_SUPPORTED)
  161159. png_voidp user_chunk_ptr;
  161160. png_user_chunk_ptr read_user_chunk_fn; /* user read chunk handler */
  161161. #endif
  161162. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  161163. int num_chunk_list;
  161164. png_bytep chunk_list;
  161165. #endif
  161166. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  161167. png_byte rgb_to_gray_status;
  161168. png_uint_16 rgb_to_gray_red_coeff;
  161169. png_uint_16 rgb_to_gray_green_coeff;
  161170. png_uint_16 rgb_to_gray_blue_coeff;
  161171. #endif
  161172. #if defined(PNG_MNG_FEATURES_SUPPORTED) || \
  161173. defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
  161174. defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
  161175. #ifdef PNG_1_0_X
  161176. png_byte mng_features_permitted;
  161177. #else
  161178. png_uint_32 mng_features_permitted;
  161179. #endif /* PNG_1_0_X */
  161180. #endif
  161181. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  161182. png_fixed_point int_gamma;
  161183. #endif
  161184. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  161185. png_byte filter_type;
  161186. #endif
  161187. #if defined(PNG_1_0_X)
  161188. png_uint_32 row_buf_size;
  161189. #endif
  161190. #if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  161191. # if !defined(PNG_1_0_X)
  161192. # if defined(PNG_MMX_CODE_SUPPORTED)
  161193. png_byte mmx_bitdepth_threshold;
  161194. png_uint_32 mmx_rowbytes_threshold;
  161195. # endif
  161196. png_uint_32 asm_flags;
  161197. # endif
  161198. #endif
  161199. #ifdef PNG_USER_MEM_SUPPORTED
  161200. png_voidp mem_ptr; /* user supplied struct for mem functions */
  161201. png_malloc_ptr malloc_fn; /* function for allocating memory */
  161202. png_free_ptr free_fn; /* function for freeing memory */
  161203. #endif
  161204. png_bytep big_row_buf; /* buffer to save current (unfiltered) row */
  161205. #if defined(PNG_READ_DITHER_SUPPORTED)
  161206. png_bytep dither_sort; /* working sort array */
  161207. png_bytep index_to_palette; /* where the original index currently is */
  161208. png_bytep palette_to_index; /* which original index points to this */
  161209. #endif
  161210. png_byte compression_type;
  161211. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  161212. png_uint_32 user_width_max;
  161213. png_uint_32 user_height_max;
  161214. #endif
  161215. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  161216. png_unknown_chunk unknown_chunk;
  161217. #endif
  161218. };
  161219. typedef png_structp version_1_2_21;
  161220. typedef png_struct FAR * FAR * png_structpp;
  161221. extern PNG_EXPORT(png_uint_32,png_access_version_number) PNGARG((void));
  161222. extern PNG_EXPORT(void,png_set_sig_bytes) PNGARG((png_structp png_ptr,
  161223. int num_bytes));
  161224. extern PNG_EXPORT(int,png_sig_cmp) PNGARG((png_bytep sig, png_size_t start,
  161225. png_size_t num_to_check));
  161226. extern PNG_EXPORT(int,png_check_sig) PNGARG((png_bytep sig, int num));
  161227. extern PNG_EXPORT(png_structp,png_create_read_struct)
  161228. PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
  161229. png_error_ptr error_fn, png_error_ptr warn_fn));
  161230. extern PNG_EXPORT(png_structp,png_create_write_struct)
  161231. PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
  161232. png_error_ptr error_fn, png_error_ptr warn_fn));
  161233. #ifdef PNG_WRITE_SUPPORTED
  161234. extern PNG_EXPORT(png_uint_32,png_get_compression_buffer_size)
  161235. PNGARG((png_structp png_ptr));
  161236. #endif
  161237. #ifdef PNG_WRITE_SUPPORTED
  161238. extern PNG_EXPORT(void,png_set_compression_buffer_size)
  161239. PNGARG((png_structp png_ptr, png_uint_32 size));
  161240. #endif
  161241. extern PNG_EXPORT(int,png_reset_zstream) PNGARG((png_structp png_ptr));
  161242. #ifdef PNG_USER_MEM_SUPPORTED
  161243. extern PNG_EXPORT(png_structp,png_create_read_struct_2)
  161244. PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
  161245. png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  161246. png_malloc_ptr malloc_fn, png_free_ptr free_fn));
  161247. extern PNG_EXPORT(png_structp,png_create_write_struct_2)
  161248. PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
  161249. png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  161250. png_malloc_ptr malloc_fn, png_free_ptr free_fn));
  161251. #endif
  161252. extern PNG_EXPORT(void,png_write_chunk) PNGARG((png_structp png_ptr,
  161253. png_bytep chunk_name, png_bytep data, png_size_t length));
  161254. extern PNG_EXPORT(void,png_write_chunk_start) PNGARG((png_structp png_ptr,
  161255. png_bytep chunk_name, png_uint_32 length));
  161256. extern PNG_EXPORT(void,png_write_chunk_data) PNGARG((png_structp png_ptr,
  161257. png_bytep data, png_size_t length));
  161258. extern PNG_EXPORT(void,png_write_chunk_end) PNGARG((png_structp png_ptr));
  161259. extern PNG_EXPORT(png_infop,png_create_info_struct)
  161260. PNGARG((png_structp png_ptr));
  161261. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  161262. extern PNG_EXPORT(void,png_info_init) PNGARG((png_infop info_ptr));
  161263. #undef png_info_init
  161264. #define png_info_init(info_ptr) png_info_init_3(&info_ptr,\
  161265. png_sizeof(png_info));
  161266. #endif
  161267. extern PNG_EXPORT(void,png_info_init_3) PNGARG((png_infopp info_ptr,
  161268. png_size_t png_info_struct_size));
  161269. extern PNG_EXPORT(void,png_write_info_before_PLTE) PNGARG((png_structp png_ptr,
  161270. png_infop info_ptr));
  161271. extern PNG_EXPORT(void,png_write_info) PNGARG((png_structp png_ptr,
  161272. png_infop info_ptr));
  161273. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  161274. extern PNG_EXPORT(void,png_read_info) PNGARG((png_structp png_ptr,
  161275. png_infop info_ptr));
  161276. #endif
  161277. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  161278. extern PNG_EXPORT(png_charp,png_convert_to_rfc1123)
  161279. PNGARG((png_structp png_ptr, png_timep ptime));
  161280. #endif
  161281. #if !defined(_WIN32_WCE)
  161282. #if defined(PNG_WRITE_tIME_SUPPORTED)
  161283. extern PNG_EXPORT(void,png_convert_from_struct_tm) PNGARG((png_timep ptime,
  161284. struct tm FAR * ttime));
  161285. extern PNG_EXPORT(void,png_convert_from_time_t) PNGARG((png_timep ptime,
  161286. time_t ttime));
  161287. #endif /* PNG_WRITE_tIME_SUPPORTED */
  161288. #endif /* _WIN32_WCE */
  161289. #if defined(PNG_READ_EXPAND_SUPPORTED)
  161290. extern PNG_EXPORT(void,png_set_expand) PNGARG((png_structp png_ptr));
  161291. #if !defined(PNG_1_0_X)
  161292. extern PNG_EXPORT(void,png_set_expand_gray_1_2_4_to_8) PNGARG((png_structp
  161293. png_ptr));
  161294. #endif
  161295. extern PNG_EXPORT(void,png_set_palette_to_rgb) PNGARG((png_structp png_ptr));
  161296. extern PNG_EXPORT(void,png_set_tRNS_to_alpha) PNGARG((png_structp png_ptr));
  161297. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  161298. extern PNG_EXPORT(void,png_set_gray_1_2_4_to_8) PNGARG((png_structp png_ptr));
  161299. #endif
  161300. #endif
  161301. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  161302. extern PNG_EXPORT(void,png_set_bgr) PNGARG((png_structp png_ptr));
  161303. #endif
  161304. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  161305. extern PNG_EXPORT(void,png_set_gray_to_rgb) PNGARG((png_structp png_ptr));
  161306. #endif
  161307. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  161308. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161309. extern PNG_EXPORT(void,png_set_rgb_to_gray) PNGARG((png_structp png_ptr,
  161310. int error_action, double red, double green ));
  161311. #endif
  161312. extern PNG_EXPORT(void,png_set_rgb_to_gray_fixed) PNGARG((png_structp png_ptr,
  161313. int error_action, png_fixed_point red, png_fixed_point green ));
  161314. extern PNG_EXPORT(png_byte,png_get_rgb_to_gray_status) PNGARG((png_structp
  161315. png_ptr));
  161316. #endif
  161317. extern PNG_EXPORT(void,png_build_grayscale_palette) PNGARG((int bit_depth,
  161318. png_colorp palette));
  161319. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  161320. extern PNG_EXPORT(void,png_set_strip_alpha) PNGARG((png_structp png_ptr));
  161321. #endif
  161322. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) || \
  161323. defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  161324. extern PNG_EXPORT(void,png_set_swap_alpha) PNGARG((png_structp png_ptr));
  161325. #endif
  161326. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) || \
  161327. defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  161328. extern PNG_EXPORT(void,png_set_invert_alpha) PNGARG((png_structp png_ptr));
  161329. #endif
  161330. #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
  161331. extern PNG_EXPORT(void,png_set_filler) PNGARG((png_structp png_ptr,
  161332. png_uint_32 filler, int flags));
  161333. #define PNG_FILLER_BEFORE 0
  161334. #define PNG_FILLER_AFTER 1
  161335. #if !defined(PNG_1_0_X)
  161336. extern PNG_EXPORT(void,png_set_add_alpha) PNGARG((png_structp png_ptr,
  161337. png_uint_32 filler, int flags));
  161338. #endif
  161339. #endif /* PNG_READ_FILLER_SUPPORTED || PNG_WRITE_FILLER_SUPPORTED */
  161340. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  161341. extern PNG_EXPORT(void,png_set_swap) PNGARG((png_structp png_ptr));
  161342. #endif
  161343. #if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
  161344. extern PNG_EXPORT(void,png_set_packing) PNGARG((png_structp png_ptr));
  161345. #endif
  161346. #if defined(PNG_READ_PACKSWAP_SUPPORTED) || defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  161347. extern PNG_EXPORT(void,png_set_packswap) PNGARG((png_structp png_ptr));
  161348. #endif
  161349. #if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
  161350. extern PNG_EXPORT(void,png_set_shift) PNGARG((png_structp png_ptr,
  161351. png_color_8p true_bits));
  161352. #endif
  161353. #if defined(PNG_READ_INTERLACING_SUPPORTED) || \
  161354. defined(PNG_WRITE_INTERLACING_SUPPORTED)
  161355. extern PNG_EXPORT(int,png_set_interlace_handling) PNGARG((png_structp png_ptr));
  161356. #endif
  161357. #if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
  161358. extern PNG_EXPORT(void,png_set_invert_mono) PNGARG((png_structp png_ptr));
  161359. #endif
  161360. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  161361. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161362. extern PNG_EXPORT(void,png_set_background) PNGARG((png_structp png_ptr,
  161363. png_color_16p background_color, int background_gamma_code,
  161364. int need_expand, double background_gamma));
  161365. #endif
  161366. #define PNG_BACKGROUND_GAMMA_UNKNOWN 0
  161367. #define PNG_BACKGROUND_GAMMA_SCREEN 1
  161368. #define PNG_BACKGROUND_GAMMA_FILE 2
  161369. #define PNG_BACKGROUND_GAMMA_UNIQUE 3
  161370. #endif
  161371. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  161372. extern PNG_EXPORT(void,png_set_strip_16) PNGARG((png_structp png_ptr));
  161373. #endif
  161374. #if defined(PNG_READ_DITHER_SUPPORTED)
  161375. extern PNG_EXPORT(void,png_set_dither) PNGARG((png_structp png_ptr,
  161376. png_colorp palette, int num_palette, int maximum_colors,
  161377. png_uint_16p histogram, int full_dither));
  161378. #endif
  161379. #if defined(PNG_READ_GAMMA_SUPPORTED)
  161380. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161381. extern PNG_EXPORT(void,png_set_gamma) PNGARG((png_structp png_ptr,
  161382. double screen_gamma, double default_file_gamma));
  161383. #endif
  161384. #endif
  161385. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  161386. #if defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
  161387. defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
  161388. extern PNG_EXPORT(void,png_permit_empty_plte) PNGARG((png_structp png_ptr,
  161389. int empty_plte_permitted));
  161390. #endif
  161391. #endif
  161392. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  161393. extern PNG_EXPORT(void,png_set_flush) PNGARG((png_structp png_ptr, int nrows));
  161394. extern PNG_EXPORT(void,png_write_flush) PNGARG((png_structp png_ptr));
  161395. #endif
  161396. extern PNG_EXPORT(void,png_start_read_image) PNGARG((png_structp png_ptr));
  161397. extern PNG_EXPORT(void,png_read_update_info) PNGARG((png_structp png_ptr,
  161398. png_infop info_ptr));
  161399. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  161400. extern PNG_EXPORT(void,png_read_rows) PNGARG((png_structp png_ptr,
  161401. png_bytepp row, png_bytepp display_row, png_uint_32 num_rows));
  161402. #endif
  161403. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  161404. extern PNG_EXPORT(void,png_read_row) PNGARG((png_structp png_ptr,
  161405. png_bytep row,
  161406. png_bytep display_row));
  161407. #endif
  161408. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  161409. extern PNG_EXPORT(void,png_read_image) PNGARG((png_structp png_ptr,
  161410. png_bytepp image));
  161411. #endif
  161412. extern PNG_EXPORT(void,png_write_row) PNGARG((png_structp png_ptr,
  161413. png_bytep row));
  161414. extern PNG_EXPORT(void,png_write_rows) PNGARG((png_structp png_ptr,
  161415. png_bytepp row, png_uint_32 num_rows));
  161416. extern PNG_EXPORT(void,png_write_image) PNGARG((png_structp png_ptr,
  161417. png_bytepp image));
  161418. extern PNG_EXPORT(void,png_write_end) PNGARG((png_structp png_ptr,
  161419. png_infop info_ptr));
  161420. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  161421. extern PNG_EXPORT(void,png_read_end) PNGARG((png_structp png_ptr,
  161422. png_infop info_ptr));
  161423. #endif
  161424. extern PNG_EXPORT(void,png_destroy_info_struct) PNGARG((png_structp png_ptr,
  161425. png_infopp info_ptr_ptr));
  161426. extern PNG_EXPORT(void,png_destroy_read_struct) PNGARG((png_structpp
  161427. png_ptr_ptr, png_infopp info_ptr_ptr, png_infopp end_info_ptr_ptr));
  161428. extern void png_read_destroy PNGARG((png_structp png_ptr, png_infop info_ptr,
  161429. png_infop end_info_ptr));
  161430. extern PNG_EXPORT(void,png_destroy_write_struct)
  161431. PNGARG((png_structpp png_ptr_ptr, png_infopp info_ptr_ptr));
  161432. extern void png_write_destroy PNGARG((png_structp png_ptr));
  161433. extern PNG_EXPORT(void,png_set_crc_action) PNGARG((png_structp png_ptr,
  161434. int crit_action, int ancil_action));
  161435. #define PNG_CRC_DEFAULT 0 /* error/quit warn/discard data */
  161436. #define PNG_CRC_ERROR_QUIT 1 /* error/quit error/quit */
  161437. #define PNG_CRC_WARN_DISCARD 2 /* (INVALID) warn/discard data */
  161438. #define PNG_CRC_WARN_USE 3 /* warn/use data warn/use data */
  161439. #define PNG_CRC_QUIET_USE 4 /* quiet/use data quiet/use data */
  161440. #define PNG_CRC_NO_CHANGE 5 /* use current value use current value */
  161441. extern PNG_EXPORT(void,png_set_filter) PNGARG((png_structp png_ptr, int method,
  161442. int filters));
  161443. #define PNG_NO_FILTERS 0x00
  161444. #define PNG_FILTER_NONE 0x08
  161445. #define PNG_FILTER_SUB 0x10
  161446. #define PNG_FILTER_UP 0x20
  161447. #define PNG_FILTER_AVG 0x40
  161448. #define PNG_FILTER_PAETH 0x80
  161449. #define PNG_ALL_FILTERS (PNG_FILTER_NONE | PNG_FILTER_SUB | PNG_FILTER_UP | \
  161450. PNG_FILTER_AVG | PNG_FILTER_PAETH)
  161451. #define PNG_FILTER_VALUE_NONE 0
  161452. #define PNG_FILTER_VALUE_SUB 1
  161453. #define PNG_FILTER_VALUE_UP 2
  161454. #define PNG_FILTER_VALUE_AVG 3
  161455. #define PNG_FILTER_VALUE_PAETH 4
  161456. #define PNG_FILTER_VALUE_LAST 5
  161457. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) /* EXPERIMENTAL */
  161458. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161459. extern PNG_EXPORT(void,png_set_filter_heuristics) PNGARG((png_structp png_ptr,
  161460. int heuristic_method, int num_weights, png_doublep filter_weights,
  161461. png_doublep filter_costs));
  161462. #endif
  161463. #endif /* PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */
  161464. #define PNG_FILTER_HEURISTIC_DEFAULT 0 /* Currently "UNWEIGHTED" */
  161465. #define PNG_FILTER_HEURISTIC_UNWEIGHTED 1 /* Used by libpng < 0.95 */
  161466. #define PNG_FILTER_HEURISTIC_WEIGHTED 2 /* Experimental feature */
  161467. #define PNG_FILTER_HEURISTIC_LAST 3 /* Not a valid value */
  161468. extern PNG_EXPORT(void,png_set_compression_level) PNGARG((png_structp png_ptr,
  161469. int level));
  161470. extern PNG_EXPORT(void,png_set_compression_mem_level)
  161471. PNGARG((png_structp png_ptr, int mem_level));
  161472. extern PNG_EXPORT(void,png_set_compression_strategy)
  161473. PNGARG((png_structp png_ptr, int strategy));
  161474. extern PNG_EXPORT(void,png_set_compression_window_bits)
  161475. PNGARG((png_structp png_ptr, int window_bits));
  161476. extern PNG_EXPORT(void,png_set_compression_method) PNGARG((png_structp png_ptr,
  161477. int method));
  161478. #if !defined(PNG_NO_STDIO)
  161479. extern PNG_EXPORT(void,png_init_io) PNGARG((png_structp png_ptr, png_FILE_p fp));
  161480. #endif
  161481. extern PNG_EXPORT(void,png_set_error_fn) PNGARG((png_structp png_ptr,
  161482. png_voidp error_ptr, png_error_ptr error_fn, png_error_ptr warning_fn));
  161483. extern PNG_EXPORT(png_voidp,png_get_error_ptr) PNGARG((png_structp png_ptr));
  161484. extern PNG_EXPORT(void,png_set_write_fn) PNGARG((png_structp png_ptr,
  161485. png_voidp io_ptr, png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn));
  161486. extern PNG_EXPORT(void,png_set_read_fn) PNGARG((png_structp png_ptr,
  161487. png_voidp io_ptr, png_rw_ptr read_data_fn));
  161488. extern PNG_EXPORT(png_voidp,png_get_io_ptr) PNGARG((png_structp png_ptr));
  161489. extern PNG_EXPORT(void,png_set_read_status_fn) PNGARG((png_structp png_ptr,
  161490. png_read_status_ptr read_row_fn));
  161491. extern PNG_EXPORT(void,png_set_write_status_fn) PNGARG((png_structp png_ptr,
  161492. png_write_status_ptr write_row_fn));
  161493. #ifdef PNG_USER_MEM_SUPPORTED
  161494. extern PNG_EXPORT(void,png_set_mem_fn) PNGARG((png_structp png_ptr,
  161495. png_voidp mem_ptr, png_malloc_ptr malloc_fn, png_free_ptr free_fn));
  161496. extern PNG_EXPORT(png_voidp,png_get_mem_ptr) PNGARG((png_structp png_ptr));
  161497. #endif
  161498. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  161499. defined(PNG_LEGACY_SUPPORTED)
  161500. extern PNG_EXPORT(void,png_set_read_user_transform_fn) PNGARG((png_structp
  161501. png_ptr, png_user_transform_ptr read_user_transform_fn));
  161502. #endif
  161503. #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  161504. defined(PNG_LEGACY_SUPPORTED)
  161505. extern PNG_EXPORT(void,png_set_write_user_transform_fn) PNGARG((png_structp
  161506. png_ptr, png_user_transform_ptr write_user_transform_fn));
  161507. #endif
  161508. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  161509. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  161510. defined(PNG_LEGACY_SUPPORTED)
  161511. extern PNG_EXPORT(void,png_set_user_transform_info) PNGARG((png_structp
  161512. png_ptr, png_voidp user_transform_ptr, int user_transform_depth,
  161513. int user_transform_channels));
  161514. extern PNG_EXPORT(png_voidp,png_get_user_transform_ptr)
  161515. PNGARG((png_structp png_ptr));
  161516. #endif
  161517. #ifdef PNG_USER_CHUNKS_SUPPORTED
  161518. extern PNG_EXPORT(void,png_set_read_user_chunk_fn) PNGARG((png_structp png_ptr,
  161519. png_voidp user_chunk_ptr, png_user_chunk_ptr read_user_chunk_fn));
  161520. extern PNG_EXPORT(png_voidp,png_get_user_chunk_ptr) PNGARG((png_structp
  161521. png_ptr));
  161522. #endif
  161523. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  161524. extern PNG_EXPORT(void,png_set_progressive_read_fn) PNGARG((png_structp png_ptr,
  161525. png_voidp progressive_ptr,
  161526. png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn,
  161527. png_progressive_end_ptr end_fn));
  161528. extern PNG_EXPORT(png_voidp,png_get_progressive_ptr)
  161529. PNGARG((png_structp png_ptr));
  161530. extern PNG_EXPORT(void,png_process_data) PNGARG((png_structp png_ptr,
  161531. png_infop info_ptr, png_bytep buffer, png_size_t buffer_size));
  161532. extern PNG_EXPORT(void,png_progressive_combine_row) PNGARG((png_structp png_ptr,
  161533. png_bytep old_row, png_bytep new_row));
  161534. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  161535. extern PNG_EXPORT(png_voidp,png_malloc) PNGARG((png_structp png_ptr,
  161536. png_uint_32 size));
  161537. #if defined(PNG_1_0_X)
  161538. # define png_malloc_warn png_malloc
  161539. #else
  161540. extern PNG_EXPORT(png_voidp,png_malloc_warn) PNGARG((png_structp png_ptr,
  161541. png_uint_32 size));
  161542. #endif
  161543. extern PNG_EXPORT(void,png_free) PNGARG((png_structp png_ptr, png_voidp ptr));
  161544. #if defined(PNG_1_0_X)
  161545. extern PNG_EXPORT(voidpf,png_zalloc) PNGARG((voidpf png_ptr, uInt items,
  161546. uInt size));
  161547. extern PNG_EXPORT(void,png_zfree) PNGARG((voidpf png_ptr, voidpf ptr));
  161548. #endif
  161549. extern PNG_EXPORT(void,png_free_data) PNGARG((png_structp png_ptr,
  161550. png_infop info_ptr, png_uint_32 free_me, int num));
  161551. #ifdef PNG_FREE_ME_SUPPORTED
  161552. extern PNG_EXPORT(void,png_data_freer) PNGARG((png_structp png_ptr,
  161553. png_infop info_ptr, int freer, png_uint_32 mask));
  161554. #endif
  161555. #define PNG_DESTROY_WILL_FREE_DATA 1
  161556. #define PNG_SET_WILL_FREE_DATA 1
  161557. #define PNG_USER_WILL_FREE_DATA 2
  161558. #define PNG_FREE_HIST 0x0008
  161559. #define PNG_FREE_ICCP 0x0010
  161560. #define PNG_FREE_SPLT 0x0020
  161561. #define PNG_FREE_ROWS 0x0040
  161562. #define PNG_FREE_PCAL 0x0080
  161563. #define PNG_FREE_SCAL 0x0100
  161564. #define PNG_FREE_UNKN 0x0200
  161565. #define PNG_FREE_LIST 0x0400
  161566. #define PNG_FREE_PLTE 0x1000
  161567. #define PNG_FREE_TRNS 0x2000
  161568. #define PNG_FREE_TEXT 0x4000
  161569. #define PNG_FREE_ALL 0x7fff
  161570. #define PNG_FREE_MUL 0x4220 /* PNG_FREE_SPLT|PNG_FREE_TEXT|PNG_FREE_UNKN */
  161571. #ifdef PNG_USER_MEM_SUPPORTED
  161572. extern PNG_EXPORT(png_voidp,png_malloc_default) PNGARG((png_structp png_ptr,
  161573. png_uint_32 size));
  161574. extern PNG_EXPORT(void,png_free_default) PNGARG((png_structp png_ptr,
  161575. png_voidp ptr));
  161576. #endif
  161577. extern PNG_EXPORT(png_voidp,png_memcpy_check) PNGARG((png_structp png_ptr,
  161578. png_voidp s1, png_voidp s2, png_uint_32 size));
  161579. extern PNG_EXPORT(png_voidp,png_memset_check) PNGARG((png_structp png_ptr,
  161580. png_voidp s1, int value, png_uint_32 size));
  161581. #if defined(USE_FAR_KEYWORD) /* memory model conversion function */
  161582. extern void *png_far_to_near PNGARG((png_structp png_ptr,png_voidp ptr,
  161583. int check));
  161584. #endif /* USE_FAR_KEYWORD */
  161585. #ifndef PNG_NO_ERROR_TEXT
  161586. extern PNG_EXPORT(void,png_error) PNGARG((png_structp png_ptr,
  161587. png_const_charp error_message));
  161588. extern PNG_EXPORT(void,png_chunk_error) PNGARG((png_structp png_ptr,
  161589. png_const_charp error_message));
  161590. #else
  161591. extern PNG_EXPORT(void,png_err) PNGARG((png_structp png_ptr));
  161592. #endif
  161593. #ifndef PNG_NO_WARNINGS
  161594. extern PNG_EXPORT(void,png_warning) PNGARG((png_structp png_ptr,
  161595. png_const_charp warning_message));
  161596. #ifdef PNG_READ_SUPPORTED
  161597. extern PNG_EXPORT(void,png_chunk_warning) PNGARG((png_structp png_ptr,
  161598. png_const_charp warning_message));
  161599. #endif /* PNG_READ_SUPPORTED */
  161600. #endif /* PNG_NO_WARNINGS */
  161601. extern PNG_EXPORT(png_uint_32,png_get_valid) PNGARG((png_structp png_ptr,
  161602. png_infop info_ptr, png_uint_32 flag));
  161603. extern PNG_EXPORT(png_uint_32,png_get_rowbytes) PNGARG((png_structp png_ptr,
  161604. png_infop info_ptr));
  161605. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  161606. extern PNG_EXPORT(png_bytepp,png_get_rows) PNGARG((png_structp png_ptr,
  161607. png_infop info_ptr));
  161608. extern PNG_EXPORT(void,png_set_rows) PNGARG((png_structp png_ptr,
  161609. png_infop info_ptr, png_bytepp row_pointers));
  161610. #endif
  161611. extern PNG_EXPORT(png_byte,png_get_channels) PNGARG((png_structp png_ptr,
  161612. png_infop info_ptr));
  161613. #ifdef PNG_EASY_ACCESS_SUPPORTED
  161614. extern PNG_EXPORT(png_uint_32, png_get_image_width) PNGARG((png_structp
  161615. png_ptr, png_infop info_ptr));
  161616. extern PNG_EXPORT(png_uint_32, png_get_image_height) PNGARG((png_structp
  161617. png_ptr, png_infop info_ptr));
  161618. extern PNG_EXPORT(png_byte, png_get_bit_depth) PNGARG((png_structp
  161619. png_ptr, png_infop info_ptr));
  161620. extern PNG_EXPORT(png_byte, png_get_color_type) PNGARG((png_structp
  161621. png_ptr, png_infop info_ptr));
  161622. extern PNG_EXPORT(png_byte, png_get_filter_type) PNGARG((png_structp
  161623. png_ptr, png_infop info_ptr));
  161624. extern PNG_EXPORT(png_byte, png_get_interlace_type) PNGARG((png_structp
  161625. png_ptr, png_infop info_ptr));
  161626. extern PNG_EXPORT(png_byte, png_get_compression_type) PNGARG((png_structp
  161627. png_ptr, png_infop info_ptr));
  161628. extern PNG_EXPORT(png_uint_32, png_get_pixels_per_meter) PNGARG((png_structp
  161629. png_ptr, png_infop info_ptr));
  161630. extern PNG_EXPORT(png_uint_32, png_get_x_pixels_per_meter) PNGARG((png_structp
  161631. png_ptr, png_infop info_ptr));
  161632. extern PNG_EXPORT(png_uint_32, png_get_y_pixels_per_meter) PNGARG((png_structp
  161633. png_ptr, png_infop info_ptr));
  161634. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161635. extern PNG_EXPORT(float, png_get_pixel_aspect_ratio) PNGARG((png_structp
  161636. png_ptr, png_infop info_ptr));
  161637. #endif
  161638. extern PNG_EXPORT(png_int_32, png_get_x_offset_pixels) PNGARG((png_structp
  161639. png_ptr, png_infop info_ptr));
  161640. extern PNG_EXPORT(png_int_32, png_get_y_offset_pixels) PNGARG((png_structp
  161641. png_ptr, png_infop info_ptr));
  161642. extern PNG_EXPORT(png_int_32, png_get_x_offset_microns) PNGARG((png_structp
  161643. png_ptr, png_infop info_ptr));
  161644. extern PNG_EXPORT(png_int_32, png_get_y_offset_microns) PNGARG((png_structp
  161645. png_ptr, png_infop info_ptr));
  161646. #endif /* PNG_EASY_ACCESS_SUPPORTED */
  161647. extern PNG_EXPORT(png_bytep,png_get_signature) PNGARG((png_structp png_ptr,
  161648. png_infop info_ptr));
  161649. #if defined(PNG_bKGD_SUPPORTED)
  161650. extern PNG_EXPORT(png_uint_32,png_get_bKGD) PNGARG((png_structp png_ptr,
  161651. png_infop info_ptr, png_color_16p *background));
  161652. #endif
  161653. #if defined(PNG_bKGD_SUPPORTED)
  161654. extern PNG_EXPORT(void,png_set_bKGD) PNGARG((png_structp png_ptr,
  161655. png_infop info_ptr, png_color_16p background));
  161656. #endif
  161657. #if defined(PNG_cHRM_SUPPORTED)
  161658. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161659. extern PNG_EXPORT(png_uint_32,png_get_cHRM) PNGARG((png_structp png_ptr,
  161660. png_infop info_ptr, double *white_x, double *white_y, double *red_x,
  161661. double *red_y, double *green_x, double *green_y, double *blue_x,
  161662. double *blue_y));
  161663. #endif
  161664. #ifdef PNG_FIXED_POINT_SUPPORTED
  161665. extern PNG_EXPORT(png_uint_32,png_get_cHRM_fixed) PNGARG((png_structp png_ptr,
  161666. png_infop info_ptr, png_fixed_point *int_white_x, png_fixed_point
  161667. *int_white_y, png_fixed_point *int_red_x, png_fixed_point *int_red_y,
  161668. png_fixed_point *int_green_x, png_fixed_point *int_green_y, png_fixed_point
  161669. *int_blue_x, png_fixed_point *int_blue_y));
  161670. #endif
  161671. #endif
  161672. #if defined(PNG_cHRM_SUPPORTED)
  161673. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161674. extern PNG_EXPORT(void,png_set_cHRM) PNGARG((png_structp png_ptr,
  161675. png_infop info_ptr, double white_x, double white_y, double red_x,
  161676. double red_y, double green_x, double green_y, double blue_x, double blue_y));
  161677. #endif
  161678. #ifdef PNG_FIXED_POINT_SUPPORTED
  161679. extern PNG_EXPORT(void,png_set_cHRM_fixed) PNGARG((png_structp png_ptr,
  161680. png_infop info_ptr, png_fixed_point int_white_x, png_fixed_point int_white_y,
  161681. png_fixed_point int_red_x, png_fixed_point int_red_y, png_fixed_point
  161682. int_green_x, png_fixed_point int_green_y, png_fixed_point int_blue_x,
  161683. png_fixed_point int_blue_y));
  161684. #endif
  161685. #endif
  161686. #if defined(PNG_gAMA_SUPPORTED)
  161687. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161688. extern PNG_EXPORT(png_uint_32,png_get_gAMA) PNGARG((png_structp png_ptr,
  161689. png_infop info_ptr, double *file_gamma));
  161690. #endif
  161691. extern PNG_EXPORT(png_uint_32,png_get_gAMA_fixed) PNGARG((png_structp png_ptr,
  161692. png_infop info_ptr, png_fixed_point *int_file_gamma));
  161693. #endif
  161694. #if defined(PNG_gAMA_SUPPORTED)
  161695. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161696. extern PNG_EXPORT(void,png_set_gAMA) PNGARG((png_structp png_ptr,
  161697. png_infop info_ptr, double file_gamma));
  161698. #endif
  161699. extern PNG_EXPORT(void,png_set_gAMA_fixed) PNGARG((png_structp png_ptr,
  161700. png_infop info_ptr, png_fixed_point int_file_gamma));
  161701. #endif
  161702. #if defined(PNG_hIST_SUPPORTED)
  161703. extern PNG_EXPORT(png_uint_32,png_get_hIST) PNGARG((png_structp png_ptr,
  161704. png_infop info_ptr, png_uint_16p *hist));
  161705. #endif
  161706. #if defined(PNG_hIST_SUPPORTED)
  161707. extern PNG_EXPORT(void,png_set_hIST) PNGARG((png_structp png_ptr,
  161708. png_infop info_ptr, png_uint_16p hist));
  161709. #endif
  161710. extern PNG_EXPORT(png_uint_32,png_get_IHDR) PNGARG((png_structp png_ptr,
  161711. png_infop info_ptr, png_uint_32 *width, png_uint_32 *height,
  161712. int *bit_depth, int *color_type, int *interlace_method,
  161713. int *compression_method, int *filter_method));
  161714. extern PNG_EXPORT(void,png_set_IHDR) PNGARG((png_structp png_ptr,
  161715. png_infop info_ptr, png_uint_32 width, png_uint_32 height, int bit_depth,
  161716. int color_type, int interlace_method, int compression_method,
  161717. int filter_method));
  161718. #if defined(PNG_oFFs_SUPPORTED)
  161719. extern PNG_EXPORT(png_uint_32,png_get_oFFs) PNGARG((png_structp png_ptr,
  161720. png_infop info_ptr, png_int_32 *offset_x, png_int_32 *offset_y,
  161721. int *unit_type));
  161722. #endif
  161723. #if defined(PNG_oFFs_SUPPORTED)
  161724. extern PNG_EXPORT(void,png_set_oFFs) PNGARG((png_structp png_ptr,
  161725. png_infop info_ptr, png_int_32 offset_x, png_int_32 offset_y,
  161726. int unit_type));
  161727. #endif
  161728. #if defined(PNG_pCAL_SUPPORTED)
  161729. extern PNG_EXPORT(png_uint_32,png_get_pCAL) PNGARG((png_structp png_ptr,
  161730. png_infop info_ptr, png_charp *purpose, png_int_32 *X0, png_int_32 *X1,
  161731. int *type, int *nparams, png_charp *units, png_charpp *params));
  161732. #endif
  161733. #if defined(PNG_pCAL_SUPPORTED)
  161734. extern PNG_EXPORT(void,png_set_pCAL) PNGARG((png_structp png_ptr,
  161735. png_infop info_ptr, png_charp purpose, png_int_32 X0, png_int_32 X1,
  161736. int type, int nparams, png_charp units, png_charpp params));
  161737. #endif
  161738. #if defined(PNG_pHYs_SUPPORTED)
  161739. extern PNG_EXPORT(png_uint_32,png_get_pHYs) PNGARG((png_structp png_ptr,
  161740. png_infop info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type));
  161741. #endif
  161742. #if defined(PNG_pHYs_SUPPORTED)
  161743. extern PNG_EXPORT(void,png_set_pHYs) PNGARG((png_structp png_ptr,
  161744. png_infop info_ptr, png_uint_32 res_x, png_uint_32 res_y, int unit_type));
  161745. #endif
  161746. extern PNG_EXPORT(png_uint_32,png_get_PLTE) PNGARG((png_structp png_ptr,
  161747. png_infop info_ptr, png_colorp *palette, int *num_palette));
  161748. extern PNG_EXPORT(void,png_set_PLTE) PNGARG((png_structp png_ptr,
  161749. png_infop info_ptr, png_colorp palette, int num_palette));
  161750. #if defined(PNG_sBIT_SUPPORTED)
  161751. extern PNG_EXPORT(png_uint_32,png_get_sBIT) PNGARG((png_structp png_ptr,
  161752. png_infop info_ptr, png_color_8p *sig_bit));
  161753. #endif
  161754. #if defined(PNG_sBIT_SUPPORTED)
  161755. extern PNG_EXPORT(void,png_set_sBIT) PNGARG((png_structp png_ptr,
  161756. png_infop info_ptr, png_color_8p sig_bit));
  161757. #endif
  161758. #if defined(PNG_sRGB_SUPPORTED)
  161759. extern PNG_EXPORT(png_uint_32,png_get_sRGB) PNGARG((png_structp png_ptr,
  161760. png_infop info_ptr, int *intent));
  161761. #endif
  161762. #if defined(PNG_sRGB_SUPPORTED)
  161763. extern PNG_EXPORT(void,png_set_sRGB) PNGARG((png_structp png_ptr,
  161764. png_infop info_ptr, int intent));
  161765. extern PNG_EXPORT(void,png_set_sRGB_gAMA_and_cHRM) PNGARG((png_structp png_ptr,
  161766. png_infop info_ptr, int intent));
  161767. #endif
  161768. #if defined(PNG_iCCP_SUPPORTED)
  161769. extern PNG_EXPORT(png_uint_32,png_get_iCCP) PNGARG((png_structp png_ptr,
  161770. png_infop info_ptr, png_charpp name, int *compression_type,
  161771. png_charpp profile, png_uint_32 *proflen));
  161772. #endif
  161773. #if defined(PNG_iCCP_SUPPORTED)
  161774. extern PNG_EXPORT(void,png_set_iCCP) PNGARG((png_structp png_ptr,
  161775. png_infop info_ptr, png_charp name, int compression_type,
  161776. png_charp profile, png_uint_32 proflen));
  161777. #endif
  161778. #if defined(PNG_sPLT_SUPPORTED)
  161779. extern PNG_EXPORT(png_uint_32,png_get_sPLT) PNGARG((png_structp png_ptr,
  161780. png_infop info_ptr, png_sPLT_tpp entries));
  161781. #endif
  161782. #if defined(PNG_sPLT_SUPPORTED)
  161783. extern PNG_EXPORT(void,png_set_sPLT) PNGARG((png_structp png_ptr,
  161784. png_infop info_ptr, png_sPLT_tp entries, int nentries));
  161785. #endif
  161786. #if defined(PNG_TEXT_SUPPORTED)
  161787. extern PNG_EXPORT(png_uint_32,png_get_text) PNGARG((png_structp png_ptr,
  161788. png_infop info_ptr, png_textp *text_ptr, int *num_text));
  161789. #endif
  161790. #if defined(PNG_TEXT_SUPPORTED)
  161791. extern PNG_EXPORT(void,png_set_text) PNGARG((png_structp png_ptr,
  161792. png_infop info_ptr, png_textp text_ptr, int num_text));
  161793. #endif
  161794. #if defined(PNG_tIME_SUPPORTED)
  161795. extern PNG_EXPORT(png_uint_32,png_get_tIME) PNGARG((png_structp png_ptr,
  161796. png_infop info_ptr, png_timep *mod_time));
  161797. #endif
  161798. #if defined(PNG_tIME_SUPPORTED)
  161799. extern PNG_EXPORT(void,png_set_tIME) PNGARG((png_structp png_ptr,
  161800. png_infop info_ptr, png_timep mod_time));
  161801. #endif
  161802. #if defined(PNG_tRNS_SUPPORTED)
  161803. extern PNG_EXPORT(png_uint_32,png_get_tRNS) PNGARG((png_structp png_ptr,
  161804. png_infop info_ptr, png_bytep *trans, int *num_trans,
  161805. png_color_16p *trans_values));
  161806. #endif
  161807. #if defined(PNG_tRNS_SUPPORTED)
  161808. extern PNG_EXPORT(void,png_set_tRNS) PNGARG((png_structp png_ptr,
  161809. png_infop info_ptr, png_bytep trans, int num_trans,
  161810. png_color_16p trans_values));
  161811. #endif
  161812. #if defined(PNG_tRNS_SUPPORTED)
  161813. #endif
  161814. #if defined(PNG_sCAL_SUPPORTED)
  161815. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161816. extern PNG_EXPORT(png_uint_32,png_get_sCAL) PNGARG((png_structp png_ptr,
  161817. png_infop info_ptr, int *unit, double *width, double *height));
  161818. #else
  161819. #ifdef PNG_FIXED_POINT_SUPPORTED
  161820. extern PNG_EXPORT(png_uint_32,png_get_sCAL_s) PNGARG((png_structp png_ptr,
  161821. png_infop info_ptr, int *unit, png_charpp swidth, png_charpp sheight));
  161822. #endif
  161823. #endif
  161824. #endif /* PNG_sCAL_SUPPORTED */
  161825. #if defined(PNG_sCAL_SUPPORTED)
  161826. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161827. extern PNG_EXPORT(void,png_set_sCAL) PNGARG((png_structp png_ptr,
  161828. png_infop info_ptr, int unit, double width, double height));
  161829. #else
  161830. #ifdef PNG_FIXED_POINT_SUPPORTED
  161831. extern PNG_EXPORT(void,png_set_sCAL_s) PNGARG((png_structp png_ptr,
  161832. png_infop info_ptr, int unit, png_charp swidth, png_charp sheight));
  161833. #endif
  161834. #endif
  161835. #endif /* PNG_sCAL_SUPPORTED || PNG_WRITE_sCAL_SUPPORTED */
  161836. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  161837. extern PNG_EXPORT(void, png_set_keep_unknown_chunks) PNGARG((png_structp
  161838. png_ptr, int keep, png_bytep chunk_list, int num_chunks));
  161839. extern PNG_EXPORT(void, png_set_unknown_chunks) PNGARG((png_structp png_ptr,
  161840. png_infop info_ptr, png_unknown_chunkp unknowns, int num_unknowns));
  161841. extern PNG_EXPORT(void, png_set_unknown_chunk_location)
  161842. PNGARG((png_structp png_ptr, png_infop info_ptr, int chunk, int location));
  161843. extern PNG_EXPORT(png_uint_32,png_get_unknown_chunks) PNGARG((png_structp
  161844. png_ptr, png_infop info_ptr, png_unknown_chunkpp entries));
  161845. #endif
  161846. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  161847. PNG_EXPORT(int,png_handle_as_unknown) PNGARG((png_structp png_ptr, png_bytep
  161848. chunk_name));
  161849. #endif
  161850. extern PNG_EXPORT(void, png_set_invalid) PNGARG((png_structp png_ptr,
  161851. png_infop info_ptr, int mask));
  161852. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  161853. extern PNG_EXPORT(void, png_read_png) PNGARG((png_structp png_ptr,
  161854. png_infop info_ptr,
  161855. int transforms,
  161856. png_voidp params));
  161857. extern PNG_EXPORT(void, png_write_png) PNGARG((png_structp png_ptr,
  161858. png_infop info_ptr,
  161859. int transforms,
  161860. png_voidp params));
  161861. #endif
  161862. #ifdef PNG_DEBUG
  161863. #if (PNG_DEBUG > 0)
  161864. #if !defined(PNG_DEBUG_FILE) && defined(_MSC_VER)
  161865. #include <crtdbg.h>
  161866. #if (PNG_DEBUG > 1)
  161867. #define png_debug(l,m) _RPT0(_CRT_WARN,m)
  161868. #define png_debug1(l,m,p1) _RPT1(_CRT_WARN,m,p1)
  161869. #define png_debug2(l,m,p1,p2) _RPT2(_CRT_WARN,m,p1,p2)
  161870. #endif
  161871. #else /* PNG_DEBUG_FILE || !_MSC_VER */
  161872. #ifndef PNG_DEBUG_FILE
  161873. #define PNG_DEBUG_FILE stderr
  161874. #endif /* PNG_DEBUG_FILE */
  161875. #if (PNG_DEBUG > 1)
  161876. #define png_debug(l,m) \
  161877. { \
  161878. int num_tabs=l; \
  161879. fprintf(PNG_DEBUG_FILE,"%s"m,(num_tabs==1 ? "\t" : \
  161880. (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":"")))); \
  161881. }
  161882. #define png_debug1(l,m,p1) \
  161883. { \
  161884. int num_tabs=l; \
  161885. fprintf(PNG_DEBUG_FILE,"%s"m,(num_tabs==1 ? "\t" : \
  161886. (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))),p1); \
  161887. }
  161888. #define png_debug2(l,m,p1,p2) \
  161889. { \
  161890. int num_tabs=l; \
  161891. fprintf(PNG_DEBUG_FILE,"%s"m,(num_tabs==1 ? "\t" : \
  161892. (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))),p1,p2); \
  161893. }
  161894. #endif /* (PNG_DEBUG > 1) */
  161895. #endif /* _MSC_VER */
  161896. #endif /* (PNG_DEBUG > 0) */
  161897. #endif /* PNG_DEBUG */
  161898. #ifndef png_debug
  161899. #define png_debug(l, m)
  161900. #endif
  161901. #ifndef png_debug1
  161902. #define png_debug1(l, m, p1)
  161903. #endif
  161904. #ifndef png_debug2
  161905. #define png_debug2(l, m, p1, p2)
  161906. #endif
  161907. extern PNG_EXPORT(png_charp,png_get_copyright) PNGARG((png_structp png_ptr));
  161908. extern PNG_EXPORT(png_charp,png_get_header_ver) PNGARG((png_structp png_ptr));
  161909. extern PNG_EXPORT(png_charp,png_get_header_version) PNGARG((png_structp png_ptr));
  161910. extern PNG_EXPORT(png_charp,png_get_libpng_ver) PNGARG((png_structp png_ptr));
  161911. #ifdef PNG_MNG_FEATURES_SUPPORTED
  161912. extern PNG_EXPORT(png_uint_32,png_permit_mng_features) PNGARG((png_structp
  161913. png_ptr, png_uint_32 mng_features_permitted));
  161914. #endif
  161915. #define PNG_HANDLE_CHUNK_AS_DEFAULT 0
  161916. #define PNG_HANDLE_CHUNK_NEVER 1
  161917. #define PNG_HANDLE_CHUNK_IF_SAFE 2
  161918. #define PNG_HANDLE_CHUNK_ALWAYS 3
  161919. #if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  161920. #if defined(PNG_MMX_CODE_SUPPORTED)
  161921. #define PNG_ASM_FLAG_MMX_SUPPORT_COMPILED 0x01 /* not user-settable */
  161922. #define PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU 0x02 /* not user-settable */
  161923. #define PNG_ASM_FLAG_MMX_READ_COMBINE_ROW 0x04
  161924. #define PNG_ASM_FLAG_MMX_READ_INTERLACE 0x08
  161925. #define PNG_ASM_FLAG_MMX_READ_FILTER_SUB 0x10
  161926. #define PNG_ASM_FLAG_MMX_READ_FILTER_UP 0x20
  161927. #define PNG_ASM_FLAG_MMX_READ_FILTER_AVG 0x40
  161928. #define PNG_ASM_FLAG_MMX_READ_FILTER_PAETH 0x80
  161929. #define PNG_ASM_FLAGS_INITIALIZED 0x80000000 /* not user-settable */
  161930. #define PNG_MMX_READ_FLAGS ( PNG_ASM_FLAG_MMX_READ_COMBINE_ROW \
  161931. | PNG_ASM_FLAG_MMX_READ_INTERLACE \
  161932. | PNG_ASM_FLAG_MMX_READ_FILTER_SUB \
  161933. | PNG_ASM_FLAG_MMX_READ_FILTER_UP \
  161934. | PNG_ASM_FLAG_MMX_READ_FILTER_AVG \
  161935. | PNG_ASM_FLAG_MMX_READ_FILTER_PAETH )
  161936. #define PNG_MMX_WRITE_FLAGS ( 0 )
  161937. #define PNG_MMX_FLAGS ( PNG_ASM_FLAG_MMX_SUPPORT_COMPILED \
  161938. | PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU \
  161939. | PNG_MMX_READ_FLAGS \
  161940. | PNG_MMX_WRITE_FLAGS )
  161941. #define PNG_SELECT_READ 1
  161942. #define PNG_SELECT_WRITE 2
  161943. #endif /* PNG_MMX_CODE_SUPPORTED */
  161944. #if !defined(PNG_1_0_X)
  161945. extern PNG_EXPORT(png_uint_32,png_get_mmx_flagmask)
  161946. PNGARG((int flag_select, int *compilerID));
  161947. extern PNG_EXPORT(png_uint_32,png_get_asm_flagmask)
  161948. PNGARG((int flag_select));
  161949. extern PNG_EXPORT(png_uint_32,png_get_asm_flags)
  161950. PNGARG((png_structp png_ptr));
  161951. extern PNG_EXPORT(png_byte,png_get_mmx_bitdepth_threshold)
  161952. PNGARG((png_structp png_ptr));
  161953. extern PNG_EXPORT(png_uint_32,png_get_mmx_rowbytes_threshold)
  161954. PNGARG((png_structp png_ptr));
  161955. extern PNG_EXPORT(void,png_set_asm_flags)
  161956. PNGARG((png_structp png_ptr, png_uint_32 asm_flags));
  161957. extern PNG_EXPORT(void,png_set_mmx_thresholds)
  161958. PNGARG((png_structp png_ptr, png_byte mmx_bitdepth_threshold,
  161959. png_uint_32 mmx_rowbytes_threshold));
  161960. #endif /* PNG_1_0_X */
  161961. #if !defined(PNG_1_0_X)
  161962. extern PNG_EXPORT(int,png_mmx_support) PNGARG((void));
  161963. #endif /* PNG_ASSEMBLER_CODE_SUPPORTED */
  161964. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  161965. extern PNG_EXPORT(void,png_set_strip_error_numbers) PNGARG((png_structp
  161966. png_ptr, png_uint_32 strip_mode));
  161967. #endif
  161968. #endif /* PNG_1_0_X */
  161969. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  161970. extern PNG_EXPORT(void,png_set_user_limits) PNGARG((png_structp
  161971. png_ptr, png_uint_32 user_width_max, png_uint_32 user_height_max));
  161972. extern PNG_EXPORT(png_uint_32,png_get_user_width_max) PNGARG((png_structp
  161973. png_ptr));
  161974. extern PNG_EXPORT(png_uint_32,png_get_user_height_max) PNGARG((png_structp
  161975. png_ptr));
  161976. #endif
  161977. #ifdef PNG_READ_COMPOSITE_NODIV_SUPPORTED
  161978. # define png_composite(composite, fg, alpha, bg) \
  161979. { png_uint_16 temp = (png_uint_16)((png_uint_16)(fg) * (png_uint_16)(alpha) \
  161980. + (png_uint_16)(bg)*(png_uint_16)(255 - \
  161981. (png_uint_16)(alpha)) + (png_uint_16)128); \
  161982. (composite) = (png_byte)((temp + (temp >> 8)) >> 8); }
  161983. # define png_composite_16(composite, fg, alpha, bg) \
  161984. { png_uint_32 temp = (png_uint_32)((png_uint_32)(fg) * (png_uint_32)(alpha) \
  161985. + (png_uint_32)(bg)*(png_uint_32)(65535L - \
  161986. (png_uint_32)(alpha)) + (png_uint_32)32768L); \
  161987. (composite) = (png_uint_16)((temp + (temp >> 16)) >> 16); }
  161988. #else /* standard method using integer division */
  161989. # define png_composite(composite, fg, alpha, bg) \
  161990. (composite) = (png_byte)(((png_uint_16)(fg) * (png_uint_16)(alpha) + \
  161991. (png_uint_16)(bg) * (png_uint_16)(255 - (png_uint_16)(alpha)) + \
  161992. (png_uint_16)127) / 255)
  161993. # define png_composite_16(composite, fg, alpha, bg) \
  161994. (composite) = (png_uint_16)(((png_uint_32)(fg) * (png_uint_32)(alpha) + \
  161995. (png_uint_32)(bg)*(png_uint_32)(65535L - (png_uint_32)(alpha)) + \
  161996. (png_uint_32)32767) / (png_uint_32)65535L)
  161997. #endif /* PNG_READ_COMPOSITE_NODIV_SUPPORTED */
  161998. #if defined(PNG_READ_BIG_ENDIAN_SUPPORTED)
  161999. # define png_get_uint_32(buf) ( *((png_uint_32p) (buf)))
  162000. # define png_get_uint_16(buf) ( *((png_uint_16p) (buf)))
  162001. # define png_get_int_32(buf) ( *((png_int_32p) (buf)))
  162002. #else
  162003. extern PNG_EXPORT(png_uint_32,png_get_uint_32) PNGARG((png_bytep buf));
  162004. extern PNG_EXPORT(png_uint_16,png_get_uint_16) PNGARG((png_bytep buf));
  162005. extern PNG_EXPORT(png_int_32,png_get_int_32) PNGARG((png_bytep buf));
  162006. #endif /* !PNG_READ_BIG_ENDIAN_SUPPORTED */
  162007. extern PNG_EXPORT(png_uint_32,png_get_uint_31)
  162008. PNGARG((png_structp png_ptr, png_bytep buf));
  162009. extern PNG_EXPORT(void,png_save_uint_32)
  162010. PNGARG((png_bytep buf, png_uint_32 i));
  162011. extern PNG_EXPORT(void,png_save_int_32)
  162012. PNGARG((png_bytep buf, png_int_32 i));
  162013. extern PNG_EXPORT(void,png_save_uint_16)
  162014. PNGARG((png_bytep buf, unsigned int i));
  162015. #define PNG_HAVE_IHDR 0x01
  162016. #define PNG_HAVE_PLTE 0x02
  162017. #define PNG_HAVE_IDAT 0x04
  162018. #define PNG_AFTER_IDAT 0x08 /* Have complete zlib datastream */
  162019. #define PNG_HAVE_IEND 0x10
  162020. #if defined(PNG_INTERNAL)
  162021. #define PNG_HAVE_gAMA 0x20
  162022. #define PNG_HAVE_cHRM 0x40
  162023. #define PNG_HAVE_sRGB 0x80
  162024. #define PNG_HAVE_CHUNK_HEADER 0x100
  162025. #define PNG_WROTE_tIME 0x200
  162026. #define PNG_WROTE_INFO_BEFORE_PLTE 0x400
  162027. #define PNG_BACKGROUND_IS_GRAY 0x800
  162028. #define PNG_HAVE_PNG_SIGNATURE 0x1000
  162029. #define PNG_HAVE_CHUNK_AFTER_IDAT 0x2000 /* Have another chunk after IDAT */
  162030. #define PNG_BGR 0x0001
  162031. #define PNG_INTERLACE 0x0002
  162032. #define PNG_PACK 0x0004
  162033. #define PNG_SHIFT 0x0008
  162034. #define PNG_SWAP_BYTES 0x0010
  162035. #define PNG_INVERT_MONO 0x0020
  162036. #define PNG_DITHER 0x0040
  162037. #define PNG_BACKGROUND 0x0080
  162038. #define PNG_BACKGROUND_EXPAND 0x0100
  162039. #define PNG_16_TO_8 0x0400
  162040. #define PNG_RGBA 0x0800
  162041. #define PNG_EXPAND 0x1000
  162042. #define PNG_GAMMA 0x2000
  162043. #define PNG_GRAY_TO_RGB 0x4000
  162044. #define PNG_FILLER 0x8000L
  162045. #define PNG_PACKSWAP 0x10000L
  162046. #define PNG_SWAP_ALPHA 0x20000L
  162047. #define PNG_STRIP_ALPHA 0x40000L
  162048. #define PNG_INVERT_ALPHA 0x80000L
  162049. #define PNG_USER_TRANSFORM 0x100000L
  162050. #define PNG_RGB_TO_GRAY_ERR 0x200000L
  162051. #define PNG_RGB_TO_GRAY_WARN 0x400000L
  162052. #define PNG_RGB_TO_GRAY 0x600000L /* two bits, RGB_TO_GRAY_ERR|WARN */
  162053. #define PNG_ADD_ALPHA 0x1000000L /* Added to libpng-1.2.7 */
  162054. #define PNG_EXPAND_tRNS 0x2000000L /* Added to libpng-1.2.9 */
  162055. #define PNG_STRUCT_PNG 0x0001
  162056. #define PNG_STRUCT_INFO 0x0002
  162057. #define PNG_WEIGHT_SHIFT 8
  162058. #define PNG_WEIGHT_FACTOR (1<<(PNG_WEIGHT_SHIFT))
  162059. #define PNG_COST_SHIFT 3
  162060. #define PNG_COST_FACTOR (1<<(PNG_COST_SHIFT))
  162061. #define PNG_FLAG_ZLIB_CUSTOM_STRATEGY 0x0001
  162062. #define PNG_FLAG_ZLIB_CUSTOM_LEVEL 0x0002
  162063. #define PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL 0x0004
  162064. #define PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS 0x0008
  162065. #define PNG_FLAG_ZLIB_CUSTOM_METHOD 0x0010
  162066. #define PNG_FLAG_ZLIB_FINISHED 0x0020
  162067. #define PNG_FLAG_ROW_INIT 0x0040
  162068. #define PNG_FLAG_FILLER_AFTER 0x0080
  162069. #define PNG_FLAG_CRC_ANCILLARY_USE 0x0100
  162070. #define PNG_FLAG_CRC_ANCILLARY_NOWARN 0x0200
  162071. #define PNG_FLAG_CRC_CRITICAL_USE 0x0400
  162072. #define PNG_FLAG_CRC_CRITICAL_IGNORE 0x0800
  162073. #define PNG_FLAG_FREE_PLTE 0x1000
  162074. #define PNG_FLAG_FREE_TRNS 0x2000
  162075. #define PNG_FLAG_FREE_HIST 0x4000
  162076. #define PNG_FLAG_KEEP_UNKNOWN_CHUNKS 0x8000L
  162077. #define PNG_FLAG_KEEP_UNSAFE_CHUNKS 0x10000L
  162078. #define PNG_FLAG_LIBRARY_MISMATCH 0x20000L
  162079. #define PNG_FLAG_STRIP_ERROR_NUMBERS 0x40000L
  162080. #define PNG_FLAG_STRIP_ERROR_TEXT 0x80000L
  162081. #define PNG_FLAG_MALLOC_NULL_MEM_OK 0x100000L
  162082. #define PNG_FLAG_ADD_ALPHA 0x200000L /* Added to libpng-1.2.8 */
  162083. #define PNG_FLAG_STRIP_ALPHA 0x400000L /* Added to libpng-1.2.8 */
  162084. #define PNG_FLAG_CRC_ANCILLARY_MASK (PNG_FLAG_CRC_ANCILLARY_USE | \
  162085. PNG_FLAG_CRC_ANCILLARY_NOWARN)
  162086. #define PNG_FLAG_CRC_CRITICAL_MASK (PNG_FLAG_CRC_CRITICAL_USE | \
  162087. PNG_FLAG_CRC_CRITICAL_IGNORE)
  162088. #define PNG_FLAG_CRC_MASK (PNG_FLAG_CRC_ANCILLARY_MASK | \
  162089. PNG_FLAG_CRC_CRITICAL_MASK)
  162090. #define PNG_COLOR_DIST(c1, c2) (abs((int)((c1).red) - (int)((c2).red)) + \
  162091. abs((int)((c1).green) - (int)((c2).green)) + \
  162092. abs((int)((c1).blue) - (int)((c2).blue)))
  162093. #define PNG_ROWBYTES(pixel_bits, width) \
  162094. ((pixel_bits) >= 8 ? \
  162095. ((width) * (((png_uint_32)(pixel_bits)) >> 3)) : \
  162096. (( ((width) * ((png_uint_32)(pixel_bits))) + 7) >> 3) )
  162097. #define PNG_OUT_OF_RANGE(value, ideal, delta) \
  162098. ( (value) < (ideal)-(delta) || (value) > (ideal)+(delta) )
  162099. #if !defined(PNG_NO_EXTERN) || defined(PNG_ALWAYS_EXTERN)
  162100. #ifdef PNG_USE_GLOBAL_ARRAYS
  162101. PNG_EXPORT_VAR (PNG_CONST png_byte FARDATA) png_sig[8];
  162102. #else
  162103. #endif
  162104. #endif /* PNG_NO_EXTERN */
  162105. #define PNG_IHDR png_byte png_IHDR[5] = { 73, 72, 68, 82, '\0'}
  162106. #define PNG_IDAT png_byte png_IDAT[5] = { 73, 68, 65, 84, '\0'}
  162107. #define PNG_IEND png_byte png_IEND[5] = { 73, 69, 78, 68, '\0'}
  162108. #define PNG_PLTE png_byte png_PLTE[5] = { 80, 76, 84, 69, '\0'}
  162109. #define PNG_bKGD png_byte png_bKGD[5] = { 98, 75, 71, 68, '\0'}
  162110. #define PNG_cHRM png_byte png_cHRM[5] = { 99, 72, 82, 77, '\0'}
  162111. #define PNG_gAMA png_byte png_gAMA[5] = {103, 65, 77, 65, '\0'}
  162112. #define PNG_hIST png_byte png_hIST[5] = {104, 73, 83, 84, '\0'}
  162113. #define PNG_iCCP png_byte png_iCCP[5] = {105, 67, 67, 80, '\0'}
  162114. #define PNG_iTXt png_byte png_iTXt[5] = {105, 84, 88, 116, '\0'}
  162115. #define PNG_oFFs png_byte png_oFFs[5] = {111, 70, 70, 115, '\0'}
  162116. #define PNG_pCAL png_byte png_pCAL[5] = {112, 67, 65, 76, '\0'}
  162117. #define PNG_sCAL png_byte png_sCAL[5] = {115, 67, 65, 76, '\0'}
  162118. #define PNG_pHYs png_byte png_pHYs[5] = {112, 72, 89, 115, '\0'}
  162119. #define PNG_sBIT png_byte png_sBIT[5] = {115, 66, 73, 84, '\0'}
  162120. #define PNG_sPLT png_byte png_sPLT[5] = {115, 80, 76, 84, '\0'}
  162121. #define PNG_sRGB png_byte png_sRGB[5] = {115, 82, 71, 66, '\0'}
  162122. #define PNG_tEXt png_byte png_tEXt[5] = {116, 69, 88, 116, '\0'}
  162123. #define PNG_tIME png_byte png_tIME[5] = {116, 73, 77, 69, '\0'}
  162124. #define PNG_tRNS png_byte png_tRNS[5] = {116, 82, 78, 83, '\0'}
  162125. #define PNG_zTXt png_byte png_zTXt[5] = {122, 84, 88, 116, '\0'}
  162126. #ifdef PNG_USE_GLOBAL_ARRAYS
  162127. PNG_EXPORT_VAR (png_byte FARDATA) png_IHDR[5];
  162128. PNG_EXPORT_VAR (png_byte FARDATA) png_IDAT[5];
  162129. PNG_EXPORT_VAR (png_byte FARDATA) png_IEND[5];
  162130. PNG_EXPORT_VAR (png_byte FARDATA) png_PLTE[5];
  162131. PNG_EXPORT_VAR (png_byte FARDATA) png_bKGD[5];
  162132. PNG_EXPORT_VAR (png_byte FARDATA) png_cHRM[5];
  162133. PNG_EXPORT_VAR (png_byte FARDATA) png_gAMA[5];
  162134. PNG_EXPORT_VAR (png_byte FARDATA) png_hIST[5];
  162135. PNG_EXPORT_VAR (png_byte FARDATA) png_iCCP[5];
  162136. PNG_EXPORT_VAR (png_byte FARDATA) png_iTXt[5];
  162137. PNG_EXPORT_VAR (png_byte FARDATA) png_oFFs[5];
  162138. PNG_EXPORT_VAR (png_byte FARDATA) png_pCAL[5];
  162139. PNG_EXPORT_VAR (png_byte FARDATA) png_sCAL[5];
  162140. PNG_EXPORT_VAR (png_byte FARDATA) png_pHYs[5];
  162141. PNG_EXPORT_VAR (png_byte FARDATA) png_sBIT[5];
  162142. PNG_EXPORT_VAR (png_byte FARDATA) png_sPLT[5];
  162143. PNG_EXPORT_VAR (png_byte FARDATA) png_sRGB[5];
  162144. PNG_EXPORT_VAR (png_byte FARDATA) png_tEXt[5];
  162145. PNG_EXPORT_VAR (png_byte FARDATA) png_tIME[5];
  162146. PNG_EXPORT_VAR (png_byte FARDATA) png_tRNS[5];
  162147. PNG_EXPORT_VAR (png_byte FARDATA) png_zTXt[5];
  162148. #endif /* PNG_USE_GLOBAL_ARRAYS */
  162149. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  162150. extern PNG_EXPORT(void,png_read_init) PNGARG((png_structp png_ptr));
  162151. #undef png_read_init
  162152. #define png_read_init(png_ptr) png_read_init_3(&png_ptr, \
  162153. PNG_LIBPNG_VER_STRING, png_sizeof(png_struct));
  162154. #endif
  162155. extern PNG_EXPORT(void,png_read_init_3) PNGARG((png_structpp ptr_ptr,
  162156. png_const_charp user_png_ver, png_size_t png_struct_size));
  162157. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  162158. extern PNG_EXPORT(void,png_read_init_2) PNGARG((png_structp png_ptr,
  162159. png_const_charp user_png_ver, png_size_t png_struct_size, png_size_t
  162160. png_info_size));
  162161. #endif
  162162. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  162163. extern PNG_EXPORT(void,png_write_init) PNGARG((png_structp png_ptr));
  162164. #undef png_write_init
  162165. #define png_write_init(png_ptr) png_write_init_3(&png_ptr, \
  162166. PNG_LIBPNG_VER_STRING, png_sizeof(png_struct));
  162167. #endif
  162168. extern PNG_EXPORT(void,png_write_init_3) PNGARG((png_structpp ptr_ptr,
  162169. png_const_charp user_png_ver, png_size_t png_struct_size));
  162170. extern PNG_EXPORT(void,png_write_init_2) PNGARG((png_structp png_ptr,
  162171. png_const_charp user_png_ver, png_size_t png_struct_size, png_size_t
  162172. png_info_size));
  162173. PNG_EXTERN png_voidp png_create_struct PNGARG((int type));
  162174. PNG_EXTERN void png_destroy_struct PNGARG((png_voidp struct_ptr));
  162175. PNG_EXTERN png_voidp png_create_struct_2 PNGARG((int type, png_malloc_ptr
  162176. malloc_fn, png_voidp mem_ptr));
  162177. PNG_EXTERN void png_destroy_struct_2 PNGARG((png_voidp struct_ptr,
  162178. png_free_ptr free_fn, png_voidp mem_ptr));
  162179. PNG_EXTERN void png_info_destroy PNGARG((png_structp png_ptr,
  162180. png_infop info_ptr));
  162181. #ifndef PNG_1_0_X
  162182. PNG_EXTERN voidpf png_zalloc PNGARG((voidpf png_ptr, uInt items, uInt size));
  162183. PNG_EXTERN void png_zfree PNGARG((voidpf png_ptr, voidpf ptr));
  162184. #ifdef PNG_SIZE_T
  162185. PNG_EXTERN png_size_t PNGAPI png_convert_size PNGARG((size_t size));
  162186. #endif
  162187. PNG_EXTERN void PNGAPI png_default_read_data PNGARG((png_structp png_ptr,
  162188. png_bytep data, png_size_t length));
  162189. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  162190. PNG_EXTERN void PNGAPI png_push_fill_buffer PNGARG((png_structp png_ptr,
  162191. png_bytep buffer, png_size_t length));
  162192. #endif
  162193. PNG_EXTERN void PNGAPI png_default_write_data PNGARG((png_structp png_ptr,
  162194. png_bytep data, png_size_t length));
  162195. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  162196. #if !defined(PNG_NO_STDIO)
  162197. PNG_EXTERN void PNGAPI png_default_flush PNGARG((png_structp png_ptr));
  162198. #endif
  162199. #endif
  162200. #else /* PNG_1_0_X */
  162201. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  162202. PNG_EXTERN void png_push_fill_buffer PNGARG((png_structp png_ptr,
  162203. png_bytep buffer, png_size_t length));
  162204. #endif
  162205. #endif /* PNG_1_0_X */
  162206. PNG_EXTERN void png_reset_crc PNGARG((png_structp png_ptr));
  162207. PNG_EXTERN void png_write_data PNGARG((png_structp png_ptr, png_bytep data,
  162208. png_size_t length));
  162209. PNG_EXTERN void png_read_data PNGARG((png_structp png_ptr, png_bytep data,
  162210. png_size_t length));
  162211. PNG_EXTERN void png_crc_read PNGARG((png_structp png_ptr, png_bytep buf,
  162212. png_size_t length));
  162213. #if defined(PNG_zTXt_SUPPORTED) || defined(PNG_iTXt_SUPPORTED) || \
  162214. defined(PNG_iCCP_SUPPORTED) || defined(PNG_sPLT_SUPPORTED)
  162215. PNG_EXTERN png_charp png_decompress_chunk PNGARG((png_structp png_ptr,
  162216. int comp_type, png_charp chunkdata, png_size_t chunklength,
  162217. png_size_t prefix_length, png_size_t *data_length));
  162218. #endif
  162219. PNG_EXTERN int png_crc_finish PNGARG((png_structp png_ptr, png_uint_32 skip));
  162220. PNG_EXTERN int png_crc_error PNGARG((png_structp png_ptr));
  162221. PNG_EXTERN void png_calculate_crc PNGARG((png_structp png_ptr, png_bytep ptr,
  162222. png_size_t length));
  162223. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  162224. PNG_EXTERN void png_flush PNGARG((png_structp png_ptr));
  162225. #endif
  162226. PNG_EXTERN void png_write_sig PNGARG((png_structp png_ptr));
  162227. PNG_EXTERN void png_write_IHDR PNGARG((png_structp png_ptr, png_uint_32 width,
  162228. png_uint_32 height,
  162229. int bit_depth, int color_type, int compression_method, int filter_method,
  162230. int interlace_method));
  162231. PNG_EXTERN void png_write_PLTE PNGARG((png_structp png_ptr, png_colorp palette,
  162232. png_uint_32 num_pal));
  162233. PNG_EXTERN void png_write_IDAT PNGARG((png_structp png_ptr, png_bytep data,
  162234. png_size_t length));
  162235. PNG_EXTERN void png_write_IEND PNGARG((png_structp png_ptr));
  162236. #if defined(PNG_WRITE_gAMA_SUPPORTED)
  162237. #ifdef PNG_FLOATING_POINT_SUPPORTED
  162238. PNG_EXTERN void png_write_gAMA PNGARG((png_structp png_ptr, double file_gamma));
  162239. #endif
  162240. #ifdef PNG_FIXED_POINT_SUPPORTED
  162241. PNG_EXTERN void png_write_gAMA_fixed PNGARG((png_structp png_ptr, png_fixed_point
  162242. file_gamma));
  162243. #endif
  162244. #endif
  162245. #if defined(PNG_WRITE_sBIT_SUPPORTED)
  162246. PNG_EXTERN void png_write_sBIT PNGARG((png_structp png_ptr, png_color_8p sbit,
  162247. int color_type));
  162248. #endif
  162249. #if defined(PNG_WRITE_cHRM_SUPPORTED)
  162250. #ifdef PNG_FLOATING_POINT_SUPPORTED
  162251. PNG_EXTERN void png_write_cHRM PNGARG((png_structp png_ptr,
  162252. double white_x, double white_y,
  162253. double red_x, double red_y, double green_x, double green_y,
  162254. double blue_x, double blue_y));
  162255. #endif
  162256. #ifdef PNG_FIXED_POINT_SUPPORTED
  162257. PNG_EXTERN void png_write_cHRM_fixed PNGARG((png_structp png_ptr,
  162258. png_fixed_point int_white_x, png_fixed_point int_white_y,
  162259. png_fixed_point int_red_x, png_fixed_point int_red_y, png_fixed_point
  162260. int_green_x, png_fixed_point int_green_y, png_fixed_point int_blue_x,
  162261. png_fixed_point int_blue_y));
  162262. #endif
  162263. #endif
  162264. #if defined(PNG_WRITE_sRGB_SUPPORTED)
  162265. PNG_EXTERN void png_write_sRGB PNGARG((png_structp png_ptr,
  162266. int intent));
  162267. #endif
  162268. #if defined(PNG_WRITE_iCCP_SUPPORTED)
  162269. PNG_EXTERN void png_write_iCCP PNGARG((png_structp png_ptr,
  162270. png_charp name, int compression_type,
  162271. png_charp profile, int proflen));
  162272. #endif
  162273. #if defined(PNG_WRITE_sPLT_SUPPORTED)
  162274. PNG_EXTERN void png_write_sPLT PNGARG((png_structp png_ptr,
  162275. png_sPLT_tp palette));
  162276. #endif
  162277. #if defined(PNG_WRITE_tRNS_SUPPORTED)
  162278. PNG_EXTERN void png_write_tRNS PNGARG((png_structp png_ptr, png_bytep trans,
  162279. png_color_16p values, int number, int color_type));
  162280. #endif
  162281. #if defined(PNG_WRITE_bKGD_SUPPORTED)
  162282. PNG_EXTERN void png_write_bKGD PNGARG((png_structp png_ptr,
  162283. png_color_16p values, int color_type));
  162284. #endif
  162285. #if defined(PNG_WRITE_hIST_SUPPORTED)
  162286. PNG_EXTERN void png_write_hIST PNGARG((png_structp png_ptr, png_uint_16p hist,
  162287. int num_hist));
  162288. #endif
  162289. #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_pCAL_SUPPORTED) || \
  162290. defined(PNG_WRITE_iCCP_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED)
  162291. PNG_EXTERN png_size_t png_check_keyword PNGARG((png_structp png_ptr,
  162292. png_charp key, png_charpp new_key));
  162293. #endif
  162294. #if defined(PNG_WRITE_tEXt_SUPPORTED)
  162295. PNG_EXTERN void png_write_tEXt PNGARG((png_structp png_ptr, png_charp key,
  162296. png_charp text, png_size_t text_len));
  162297. #endif
  162298. #if defined(PNG_WRITE_zTXt_SUPPORTED)
  162299. PNG_EXTERN void png_write_zTXt PNGARG((png_structp png_ptr, png_charp key,
  162300. png_charp text, png_size_t text_len, int compression));
  162301. #endif
  162302. #if defined(PNG_WRITE_iTXt_SUPPORTED)
  162303. PNG_EXTERN void png_write_iTXt PNGARG((png_structp png_ptr,
  162304. int compression, png_charp key, png_charp lang, png_charp lang_key,
  162305. png_charp text));
  162306. #endif
  162307. #if defined(PNG_TEXT_SUPPORTED) /* Added at version 1.0.14 and 1.2.4 */
  162308. PNG_EXTERN int png_set_text_2 PNGARG((png_structp png_ptr,
  162309. png_infop info_ptr, png_textp text_ptr, int num_text));
  162310. #endif
  162311. #if defined(PNG_WRITE_oFFs_SUPPORTED)
  162312. PNG_EXTERN void png_write_oFFs PNGARG((png_structp png_ptr,
  162313. png_int_32 x_offset, png_int_32 y_offset, int unit_type));
  162314. #endif
  162315. #if defined(PNG_WRITE_pCAL_SUPPORTED)
  162316. PNG_EXTERN void png_write_pCAL PNGARG((png_structp png_ptr, png_charp purpose,
  162317. png_int_32 X0, png_int_32 X1, int type, int nparams,
  162318. png_charp units, png_charpp params));
  162319. #endif
  162320. #if defined(PNG_WRITE_pHYs_SUPPORTED)
  162321. PNG_EXTERN void png_write_pHYs PNGARG((png_structp png_ptr,
  162322. png_uint_32 x_pixels_per_unit, png_uint_32 y_pixels_per_unit,
  162323. int unit_type));
  162324. #endif
  162325. #if defined(PNG_WRITE_tIME_SUPPORTED)
  162326. PNG_EXTERN void png_write_tIME PNGARG((png_structp png_ptr,
  162327. png_timep mod_time));
  162328. #endif
  162329. #if defined(PNG_WRITE_sCAL_SUPPORTED)
  162330. #if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO)
  162331. PNG_EXTERN void png_write_sCAL PNGARG((png_structp png_ptr,
  162332. int unit, double width, double height));
  162333. #else
  162334. #ifdef PNG_FIXED_POINT_SUPPORTED
  162335. PNG_EXTERN void png_write_sCAL_s PNGARG((png_structp png_ptr,
  162336. int unit, png_charp width, png_charp height));
  162337. #endif
  162338. #endif
  162339. #endif
  162340. PNG_EXTERN void png_write_finish_row PNGARG((png_structp png_ptr));
  162341. PNG_EXTERN void png_write_start_row PNGARG((png_structp png_ptr));
  162342. #if defined(PNG_READ_GAMMA_SUPPORTED)
  162343. PNG_EXTERN void png_build_gamma_table PNGARG((png_structp png_ptr));
  162344. #endif
  162345. PNG_EXTERN void png_combine_row PNGARG((png_structp png_ptr, png_bytep row,
  162346. int mask));
  162347. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  162348. PNG_EXTERN void png_do_read_interlace PNGARG((png_structp png_ptr));
  162349. #endif
  162350. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  162351. PNG_EXTERN void png_do_write_interlace PNGARG((png_row_infop row_info,
  162352. png_bytep row, int pass));
  162353. #endif
  162354. PNG_EXTERN void png_read_filter_row PNGARG((png_structp png_ptr,
  162355. png_row_infop row_info, png_bytep row, png_bytep prev_row, int filter));
  162356. PNG_EXTERN void png_write_find_filter PNGARG((png_structp png_ptr,
  162357. png_row_infop row_info));
  162358. PNG_EXTERN void png_write_filtered_row PNGARG((png_structp png_ptr,
  162359. png_bytep filtered_row));
  162360. PNG_EXTERN void png_read_finish_row PNGARG((png_structp png_ptr));
  162361. PNG_EXTERN void png_read_start_row PNGARG((png_structp png_ptr));
  162362. PNG_EXTERN void png_read_transform_info PNGARG((png_structp png_ptr,
  162363. png_infop info_ptr));
  162364. #if defined(PNG_READ_FILLER_SUPPORTED)
  162365. PNG_EXTERN void png_do_read_filler PNGARG((png_row_infop row_info,
  162366. png_bytep row, png_uint_32 filler, png_uint_32 flags));
  162367. #endif
  162368. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
  162369. PNG_EXTERN void png_do_read_swap_alpha PNGARG((png_row_infop row_info,
  162370. png_bytep row));
  162371. #endif
  162372. #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  162373. PNG_EXTERN void png_do_write_swap_alpha PNGARG((png_row_infop row_info,
  162374. png_bytep row));
  162375. #endif
  162376. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  162377. PNG_EXTERN void png_do_read_invert_alpha PNGARG((png_row_infop row_info,
  162378. png_bytep row));
  162379. #endif
  162380. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  162381. PNG_EXTERN void png_do_write_invert_alpha PNGARG((png_row_infop row_info,
  162382. png_bytep row));
  162383. #endif
  162384. #if defined(PNG_WRITE_FILLER_SUPPORTED) || \
  162385. defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  162386. PNG_EXTERN void png_do_strip_filler PNGARG((png_row_infop row_info,
  162387. png_bytep row, png_uint_32 flags));
  162388. #endif
  162389. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  162390. PNG_EXTERN void png_do_swap PNGARG((png_row_infop row_info, png_bytep row));
  162391. #endif
  162392. #if defined(PNG_READ_PACKSWAP_SUPPORTED) || defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  162393. PNG_EXTERN void png_do_packswap PNGARG((png_row_infop row_info, png_bytep row));
  162394. #endif
  162395. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  162396. PNG_EXTERN int png_do_rgb_to_gray PNGARG((png_structp png_ptr, png_row_infop
  162397. row_info, png_bytep row));
  162398. #endif
  162399. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  162400. PNG_EXTERN void png_do_gray_to_rgb PNGARG((png_row_infop row_info,
  162401. png_bytep row));
  162402. #endif
  162403. #if defined(PNG_READ_PACK_SUPPORTED)
  162404. PNG_EXTERN void png_do_unpack PNGARG((png_row_infop row_info, png_bytep row));
  162405. #endif
  162406. #if defined(PNG_READ_SHIFT_SUPPORTED)
  162407. PNG_EXTERN void png_do_unshift PNGARG((png_row_infop row_info, png_bytep row,
  162408. png_color_8p sig_bits));
  162409. #endif
  162410. #if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
  162411. PNG_EXTERN void png_do_invert PNGARG((png_row_infop row_info, png_bytep row));
  162412. #endif
  162413. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  162414. PNG_EXTERN void png_do_chop PNGARG((png_row_infop row_info, png_bytep row));
  162415. #endif
  162416. #if defined(PNG_READ_DITHER_SUPPORTED)
  162417. PNG_EXTERN void png_do_dither PNGARG((png_row_infop row_info,
  162418. png_bytep row, png_bytep palette_lookup, png_bytep dither_lookup));
  162419. # if defined(PNG_CORRECT_PALETTE_SUPPORTED)
  162420. PNG_EXTERN void png_correct_palette PNGARG((png_structp png_ptr,
  162421. png_colorp palette, int num_palette));
  162422. # endif
  162423. #endif
  162424. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  162425. PNG_EXTERN void png_do_bgr PNGARG((png_row_infop row_info, png_bytep row));
  162426. #endif
  162427. #if defined(PNG_WRITE_PACK_SUPPORTED)
  162428. PNG_EXTERN void png_do_pack PNGARG((png_row_infop row_info,
  162429. png_bytep row, png_uint_32 bit_depth));
  162430. #endif
  162431. #if defined(PNG_WRITE_SHIFT_SUPPORTED)
  162432. PNG_EXTERN void png_do_shift PNGARG((png_row_infop row_info, png_bytep row,
  162433. png_color_8p bit_depth));
  162434. #endif
  162435. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  162436. #if defined(PNG_READ_GAMMA_SUPPORTED)
  162437. PNG_EXTERN void png_do_background PNGARG((png_row_infop row_info, png_bytep row,
  162438. png_color_16p trans_values, png_color_16p background,
  162439. png_color_16p background_1,
  162440. png_bytep gamma_table, png_bytep gamma_from_1, png_bytep gamma_to_1,
  162441. png_uint_16pp gamma_16, png_uint_16pp gamma_16_from_1,
  162442. png_uint_16pp gamma_16_to_1, int gamma_shift));
  162443. #else
  162444. PNG_EXTERN void png_do_background PNGARG((png_row_infop row_info, png_bytep row,
  162445. png_color_16p trans_values, png_color_16p background));
  162446. #endif
  162447. #endif
  162448. #if defined(PNG_READ_GAMMA_SUPPORTED)
  162449. PNG_EXTERN void png_do_gamma PNGARG((png_row_infop row_info, png_bytep row,
  162450. png_bytep gamma_table, png_uint_16pp gamma_16_table,
  162451. int gamma_shift));
  162452. #endif
  162453. #if defined(PNG_READ_EXPAND_SUPPORTED)
  162454. PNG_EXTERN void png_do_expand_palette PNGARG((png_row_infop row_info,
  162455. png_bytep row, png_colorp palette, png_bytep trans, int num_trans));
  162456. PNG_EXTERN void png_do_expand PNGARG((png_row_infop row_info,
  162457. png_bytep row, png_color_16p trans_value));
  162458. #endif
  162459. PNG_EXTERN void png_handle_IHDR PNGARG((png_structp png_ptr, png_infop info_ptr,
  162460. png_uint_32 length));
  162461. PNG_EXTERN void png_handle_PLTE PNGARG((png_structp png_ptr, png_infop info_ptr,
  162462. png_uint_32 length));
  162463. PNG_EXTERN void png_handle_IEND PNGARG((png_structp png_ptr, png_infop info_ptr,
  162464. png_uint_32 length));
  162465. #if defined(PNG_READ_bKGD_SUPPORTED)
  162466. PNG_EXTERN void png_handle_bKGD PNGARG((png_structp png_ptr, png_infop info_ptr,
  162467. png_uint_32 length));
  162468. #endif
  162469. #if defined(PNG_READ_cHRM_SUPPORTED)
  162470. PNG_EXTERN void png_handle_cHRM PNGARG((png_structp png_ptr, png_infop info_ptr,
  162471. png_uint_32 length));
  162472. #endif
  162473. #if defined(PNG_READ_gAMA_SUPPORTED)
  162474. PNG_EXTERN void png_handle_gAMA PNGARG((png_structp png_ptr, png_infop info_ptr,
  162475. png_uint_32 length));
  162476. #endif
  162477. #if defined(PNG_READ_hIST_SUPPORTED)
  162478. PNG_EXTERN void png_handle_hIST PNGARG((png_structp png_ptr, png_infop info_ptr,
  162479. png_uint_32 length));
  162480. #endif
  162481. #if defined(PNG_READ_iCCP_SUPPORTED)
  162482. extern void png_handle_iCCP PNGARG((png_structp png_ptr, png_infop info_ptr,
  162483. png_uint_32 length));
  162484. #endif /* PNG_READ_iCCP_SUPPORTED */
  162485. #if defined(PNG_READ_iTXt_SUPPORTED)
  162486. PNG_EXTERN void png_handle_iTXt PNGARG((png_structp png_ptr, png_infop info_ptr,
  162487. png_uint_32 length));
  162488. #endif
  162489. #if defined(PNG_READ_oFFs_SUPPORTED)
  162490. PNG_EXTERN void png_handle_oFFs PNGARG((png_structp png_ptr, png_infop info_ptr,
  162491. png_uint_32 length));
  162492. #endif
  162493. #if defined(PNG_READ_pCAL_SUPPORTED)
  162494. PNG_EXTERN void png_handle_pCAL PNGARG((png_structp png_ptr, png_infop info_ptr,
  162495. png_uint_32 length));
  162496. #endif
  162497. #if defined(PNG_READ_pHYs_SUPPORTED)
  162498. PNG_EXTERN void png_handle_pHYs PNGARG((png_structp png_ptr, png_infop info_ptr,
  162499. png_uint_32 length));
  162500. #endif
  162501. #if defined(PNG_READ_sBIT_SUPPORTED)
  162502. PNG_EXTERN void png_handle_sBIT PNGARG((png_structp png_ptr, png_infop info_ptr,
  162503. png_uint_32 length));
  162504. #endif
  162505. #if defined(PNG_READ_sCAL_SUPPORTED)
  162506. PNG_EXTERN void png_handle_sCAL PNGARG((png_structp png_ptr, png_infop info_ptr,
  162507. png_uint_32 length));
  162508. #endif
  162509. #if defined(PNG_READ_sPLT_SUPPORTED)
  162510. extern void png_handle_sPLT PNGARG((png_structp png_ptr, png_infop info_ptr,
  162511. png_uint_32 length));
  162512. #endif /* PNG_READ_sPLT_SUPPORTED */
  162513. #if defined(PNG_READ_sRGB_SUPPORTED)
  162514. PNG_EXTERN void png_handle_sRGB PNGARG((png_structp png_ptr, png_infop info_ptr,
  162515. png_uint_32 length));
  162516. #endif
  162517. #if defined(PNG_READ_tEXt_SUPPORTED)
  162518. PNG_EXTERN void png_handle_tEXt PNGARG((png_structp png_ptr, png_infop info_ptr,
  162519. png_uint_32 length));
  162520. #endif
  162521. #if defined(PNG_READ_tIME_SUPPORTED)
  162522. PNG_EXTERN void png_handle_tIME PNGARG((png_structp png_ptr, png_infop info_ptr,
  162523. png_uint_32 length));
  162524. #endif
  162525. #if defined(PNG_READ_tRNS_SUPPORTED)
  162526. PNG_EXTERN void png_handle_tRNS PNGARG((png_structp png_ptr, png_infop info_ptr,
  162527. png_uint_32 length));
  162528. #endif
  162529. #if defined(PNG_READ_zTXt_SUPPORTED)
  162530. PNG_EXTERN void png_handle_zTXt PNGARG((png_structp png_ptr, png_infop info_ptr,
  162531. png_uint_32 length));
  162532. #endif
  162533. PNG_EXTERN void png_handle_unknown PNGARG((png_structp png_ptr,
  162534. png_infop info_ptr, png_uint_32 length));
  162535. PNG_EXTERN void png_check_chunk_name PNGARG((png_structp png_ptr,
  162536. png_bytep chunk_name));
  162537. PNG_EXTERN void png_do_read_transformations PNGARG((png_structp png_ptr));
  162538. PNG_EXTERN void png_do_write_transformations PNGARG((png_structp png_ptr));
  162539. PNG_EXTERN void png_init_read_transformations PNGARG((png_structp png_ptr));
  162540. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  162541. PNG_EXTERN void png_push_read_chunk PNGARG((png_structp png_ptr,
  162542. png_infop info_ptr));
  162543. PNG_EXTERN void png_push_read_sig PNGARG((png_structp png_ptr,
  162544. png_infop info_ptr));
  162545. PNG_EXTERN void png_push_check_crc PNGARG((png_structp png_ptr));
  162546. PNG_EXTERN void png_push_crc_skip PNGARG((png_structp png_ptr,
  162547. png_uint_32 length));
  162548. PNG_EXTERN void png_push_crc_finish PNGARG((png_structp png_ptr));
  162549. PNG_EXTERN void png_push_save_buffer PNGARG((png_structp png_ptr));
  162550. PNG_EXTERN void png_push_restore_buffer PNGARG((png_structp png_ptr,
  162551. png_bytep buffer, png_size_t buffer_length));
  162552. PNG_EXTERN void png_push_read_IDAT PNGARG((png_structp png_ptr));
  162553. PNG_EXTERN void png_process_IDAT_data PNGARG((png_structp png_ptr,
  162554. png_bytep buffer, png_size_t buffer_length));
  162555. PNG_EXTERN void png_push_process_row PNGARG((png_structp png_ptr));
  162556. PNG_EXTERN void png_push_handle_unknown PNGARG((png_structp png_ptr,
  162557. png_infop info_ptr, png_uint_32 length));
  162558. PNG_EXTERN void png_push_have_info PNGARG((png_structp png_ptr,
  162559. png_infop info_ptr));
  162560. PNG_EXTERN void png_push_have_end PNGARG((png_structp png_ptr,
  162561. png_infop info_ptr));
  162562. PNG_EXTERN void png_push_have_row PNGARG((png_structp png_ptr, png_bytep row));
  162563. PNG_EXTERN void png_push_read_end PNGARG((png_structp png_ptr,
  162564. png_infop info_ptr));
  162565. PNG_EXTERN void png_process_some_data PNGARG((png_structp png_ptr,
  162566. png_infop info_ptr));
  162567. PNG_EXTERN void png_read_push_finish_row PNGARG((png_structp png_ptr));
  162568. #if defined(PNG_READ_tEXt_SUPPORTED)
  162569. PNG_EXTERN void png_push_handle_tEXt PNGARG((png_structp png_ptr,
  162570. png_infop info_ptr, png_uint_32 length));
  162571. PNG_EXTERN void png_push_read_tEXt PNGARG((png_structp png_ptr,
  162572. png_infop info_ptr));
  162573. #endif
  162574. #if defined(PNG_READ_zTXt_SUPPORTED)
  162575. PNG_EXTERN void png_push_handle_zTXt PNGARG((png_structp png_ptr,
  162576. png_infop info_ptr, png_uint_32 length));
  162577. PNG_EXTERN void png_push_read_zTXt PNGARG((png_structp png_ptr,
  162578. png_infop info_ptr));
  162579. #endif
  162580. #if defined(PNG_READ_iTXt_SUPPORTED)
  162581. PNG_EXTERN void png_push_handle_iTXt PNGARG((png_structp png_ptr,
  162582. png_infop info_ptr, png_uint_32 length));
  162583. PNG_EXTERN void png_push_read_iTXt PNGARG((png_structp png_ptr,
  162584. png_infop info_ptr));
  162585. #endif
  162586. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  162587. #ifdef PNG_MNG_FEATURES_SUPPORTED
  162588. PNG_EXTERN void png_do_read_intrapixel PNGARG((png_row_infop row_info,
  162589. png_bytep row));
  162590. PNG_EXTERN void png_do_write_intrapixel PNGARG((png_row_infop row_info,
  162591. png_bytep row));
  162592. #endif
  162593. #if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  162594. #if defined(PNG_MMX_CODE_SUPPORTED)
  162595. /* PRIVATE */
  162596. PNG_EXTERN void png_init_mmx_flags PNGARG((png_structp png_ptr));
  162597. #endif
  162598. #endif
  162599. #if defined(PNG_INCH_CONVERSIONS) && defined(PNG_FLOATING_POINT_SUPPORTED)
  162600. PNG_EXTERN png_uint_32 png_get_pixels_per_inch PNGARG((png_structp png_ptr,
  162601. png_infop info_ptr));
  162602. PNG_EXTERN png_uint_32 png_get_x_pixels_per_inch PNGARG((png_structp png_ptr,
  162603. png_infop info_ptr));
  162604. PNG_EXTERN png_uint_32 png_get_y_pixels_per_inch PNGARG((png_structp png_ptr,
  162605. png_infop info_ptr));
  162606. PNG_EXTERN float png_get_x_offset_inches PNGARG((png_structp png_ptr,
  162607. png_infop info_ptr));
  162608. PNG_EXTERN float png_get_y_offset_inches PNGARG((png_structp png_ptr,
  162609. png_infop info_ptr));
  162610. #if defined(PNG_pHYs_SUPPORTED)
  162611. PNG_EXTERN png_uint_32 png_get_pHYs_dpi PNGARG((png_structp png_ptr,
  162612. png_infop info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type));
  162613. #endif /* PNG_pHYs_SUPPORTED */
  162614. #endif /* PNG_INCH_CONVERSIONS && PNG_FLOATING_POINT_SUPPORTED */
  162615. #endif /* PNG_INTERNAL */
  162616. #ifdef __cplusplus
  162617. }
  162618. #endif
  162619. #endif /* PNG_VERSION_INFO_ONLY */
  162620. #endif /* PNG_H */
  162621. /*** End of inlined file: png.h ***/
  162622. #define PNG_NO_EXTERN
  162623. /*** Start of inlined file: png.c ***/
  162624. #define PNG_INTERNAL
  162625. #define PNG_NO_EXTERN
  162626. typedef version_1_2_21 Your_png_h_is_not_version_1_2_21;
  162627. #ifdef PNG_USE_GLOBAL_ARRAYS
  162628. PNG_CONST char png_libpng_ver[18] = PNG_LIBPNG_VER_STRING;
  162629. #ifdef PNG_READ_SUPPORTED
  162630. PNG_CONST png_byte FARDATA png_sig[8] = {137, 80, 78, 71, 13, 10, 26, 10};
  162631. #endif /* PNG_READ_SUPPORTED */
  162632. PNG_IHDR;
  162633. PNG_IDAT;
  162634. PNG_IEND;
  162635. PNG_PLTE;
  162636. PNG_bKGD;
  162637. PNG_cHRM;
  162638. PNG_gAMA;
  162639. PNG_hIST;
  162640. PNG_iCCP;
  162641. PNG_iTXt;
  162642. PNG_oFFs;
  162643. PNG_pCAL;
  162644. PNG_sCAL;
  162645. PNG_pHYs;
  162646. PNG_sBIT;
  162647. PNG_sPLT;
  162648. PNG_sRGB;
  162649. PNG_tEXt;
  162650. PNG_tIME;
  162651. PNG_tRNS;
  162652. PNG_zTXt;
  162653. #ifdef PNG_READ_SUPPORTED
  162654. PNG_CONST int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
  162655. PNG_CONST int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
  162656. PNG_CONST int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
  162657. PNG_CONST int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
  162658. PNG_CONST int FARDATA png_pass_mask[] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
  162659. PNG_CONST int FARDATA png_pass_dsp_mask[]
  162660. = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
  162661. #endif /* PNG_READ_SUPPORTED */
  162662. #endif /* PNG_USE_GLOBAL_ARRAYS */
  162663. #ifdef PNG_READ_SUPPORTED
  162664. void PNGAPI
  162665. png_set_sig_bytes(png_structp png_ptr, int num_bytes)
  162666. {
  162667. if(png_ptr == NULL) return;
  162668. png_debug(1, "in png_set_sig_bytes\n");
  162669. if (num_bytes > 8)
  162670. png_error(png_ptr, "Too many bytes for PNG signature.");
  162671. png_ptr->sig_bytes = (png_byte)(num_bytes < 0 ? 0 : num_bytes);
  162672. }
  162673. int PNGAPI
  162674. png_sig_cmp(png_bytep sig, png_size_t start, png_size_t num_to_check)
  162675. {
  162676. png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};
  162677. if (num_to_check > 8)
  162678. num_to_check = 8;
  162679. else if (num_to_check < 1)
  162680. return (-1);
  162681. if (start > 7)
  162682. return (-1);
  162683. if (start + num_to_check > 8)
  162684. num_to_check = 8 - start;
  162685. return ((int)(png_memcmp(&sig[start], &png_signature[start], num_to_check)));
  162686. }
  162687. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  162688. int PNGAPI
  162689. png_check_sig(png_bytep sig, int num)
  162690. {
  162691. return ((int)!png_sig_cmp(sig, (png_size_t)0, (png_size_t)num));
  162692. }
  162693. #endif
  162694. #endif /* PNG_READ_SUPPORTED */
  162695. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  162696. #ifdef PNG_1_0_X
  162697. voidpf PNGAPI
  162698. #else
  162699. voidpf /* private */
  162700. #endif
  162701. png_zalloc(voidpf png_ptr, uInt items, uInt size)
  162702. {
  162703. png_voidp ptr;
  162704. png_structp p=(png_structp)png_ptr;
  162705. png_uint_32 save_flags=p->flags;
  162706. png_uint_32 num_bytes;
  162707. if(png_ptr == NULL) return (NULL);
  162708. if (items > PNG_UINT_32_MAX/size)
  162709. {
  162710. png_warning (p, "Potential overflow in png_zalloc()");
  162711. return (NULL);
  162712. }
  162713. num_bytes = (png_uint_32)items * size;
  162714. p->flags|=PNG_FLAG_MALLOC_NULL_MEM_OK;
  162715. ptr = (png_voidp)png_malloc((png_structp)png_ptr, num_bytes);
  162716. p->flags=save_flags;
  162717. #if defined(PNG_1_0_X) && !defined(PNG_NO_ZALLOC_ZERO)
  162718. if (ptr == NULL)
  162719. return ((voidpf)ptr);
  162720. if (num_bytes > (png_uint_32)0x8000L)
  162721. {
  162722. png_memset(ptr, 0, (png_size_t)0x8000L);
  162723. png_memset((png_bytep)ptr + (png_size_t)0x8000L, 0,
  162724. (png_size_t)(num_bytes - (png_uint_32)0x8000L));
  162725. }
  162726. else
  162727. {
  162728. png_memset(ptr, 0, (png_size_t)num_bytes);
  162729. }
  162730. #endif
  162731. return ((voidpf)ptr);
  162732. }
  162733. #ifdef PNG_1_0_X
  162734. void PNGAPI
  162735. #else
  162736. void /* private */
  162737. #endif
  162738. png_zfree(voidpf png_ptr, voidpf ptr)
  162739. {
  162740. png_free((png_structp)png_ptr, (png_voidp)ptr);
  162741. }
  162742. void /* PRIVATE */
  162743. png_reset_crc(png_structp png_ptr)
  162744. {
  162745. png_ptr->crc = crc32(0, Z_NULL, 0);
  162746. }
  162747. void /* PRIVATE */
  162748. png_calculate_crc(png_structp png_ptr, png_bytep ptr, png_size_t length)
  162749. {
  162750. int need_crc = 1;
  162751. if (png_ptr->chunk_name[0] & 0x20) /* ancillary */
  162752. {
  162753. if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_MASK) ==
  162754. (PNG_FLAG_CRC_ANCILLARY_USE | PNG_FLAG_CRC_ANCILLARY_NOWARN))
  162755. need_crc = 0;
  162756. }
  162757. else /* critical */
  162758. {
  162759. if (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE)
  162760. need_crc = 0;
  162761. }
  162762. if (need_crc)
  162763. png_ptr->crc = crc32(png_ptr->crc, ptr, (uInt)length);
  162764. }
  162765. png_infop PNGAPI
  162766. png_create_info_struct(png_structp png_ptr)
  162767. {
  162768. png_infop info_ptr;
  162769. png_debug(1, "in png_create_info_struct\n");
  162770. if(png_ptr == NULL) return (NULL);
  162771. #ifdef PNG_USER_MEM_SUPPORTED
  162772. info_ptr = (png_infop)png_create_struct_2(PNG_STRUCT_INFO,
  162773. png_ptr->malloc_fn, png_ptr->mem_ptr);
  162774. #else
  162775. info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO);
  162776. #endif
  162777. if (info_ptr != NULL)
  162778. png_info_init_3(&info_ptr, png_sizeof(png_info));
  162779. return (info_ptr);
  162780. }
  162781. void PNGAPI
  162782. png_destroy_info_struct(png_structp png_ptr, png_infopp info_ptr_ptr)
  162783. {
  162784. png_infop info_ptr = NULL;
  162785. if(png_ptr == NULL) return;
  162786. png_debug(1, "in png_destroy_info_struct\n");
  162787. if (info_ptr_ptr != NULL)
  162788. info_ptr = *info_ptr_ptr;
  162789. if (info_ptr != NULL)
  162790. {
  162791. png_info_destroy(png_ptr, info_ptr);
  162792. #ifdef PNG_USER_MEM_SUPPORTED
  162793. png_destroy_struct_2((png_voidp)info_ptr, png_ptr->free_fn,
  162794. png_ptr->mem_ptr);
  162795. #else
  162796. png_destroy_struct((png_voidp)info_ptr);
  162797. #endif
  162798. *info_ptr_ptr = NULL;
  162799. }
  162800. }
  162801. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  162802. #undef png_info_init
  162803. void PNGAPI
  162804. png_info_init(png_infop info_ptr)
  162805. {
  162806. png_info_init_3(&info_ptr, 0);
  162807. }
  162808. #endif
  162809. void PNGAPI
  162810. png_info_init_3(png_infopp ptr_ptr, png_size_t png_info_struct_size)
  162811. {
  162812. png_infop info_ptr = *ptr_ptr;
  162813. if(info_ptr == NULL) return;
  162814. png_debug(1, "in png_info_init_3\n");
  162815. if(png_sizeof(png_info) > png_info_struct_size)
  162816. {
  162817. png_destroy_struct(info_ptr);
  162818. info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO);
  162819. *ptr_ptr = info_ptr;
  162820. }
  162821. png_memset(info_ptr, 0, png_sizeof (png_info));
  162822. }
  162823. #ifdef PNG_FREE_ME_SUPPORTED
  162824. void PNGAPI
  162825. png_data_freer(png_structp png_ptr, png_infop info_ptr,
  162826. int freer, png_uint_32 mask)
  162827. {
  162828. png_debug(1, "in png_data_freer\n");
  162829. if (png_ptr == NULL || info_ptr == NULL)
  162830. return;
  162831. if(freer == PNG_DESTROY_WILL_FREE_DATA)
  162832. info_ptr->free_me |= mask;
  162833. else if(freer == PNG_USER_WILL_FREE_DATA)
  162834. info_ptr->free_me &= ~mask;
  162835. else
  162836. png_warning(png_ptr,
  162837. "Unknown freer parameter in png_data_freer.");
  162838. }
  162839. #endif
  162840. void PNGAPI
  162841. png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask,
  162842. int num)
  162843. {
  162844. png_debug(1, "in png_free_data\n");
  162845. if (png_ptr == NULL || info_ptr == NULL)
  162846. return;
  162847. #if defined(PNG_TEXT_SUPPORTED)
  162848. #ifdef PNG_FREE_ME_SUPPORTED
  162849. if ((mask & PNG_FREE_TEXT) & info_ptr->free_me)
  162850. #else
  162851. if (mask & PNG_FREE_TEXT)
  162852. #endif
  162853. {
  162854. if (num != -1)
  162855. {
  162856. if (info_ptr->text && info_ptr->text[num].key)
  162857. {
  162858. png_free(png_ptr, info_ptr->text[num].key);
  162859. info_ptr->text[num].key = NULL;
  162860. }
  162861. }
  162862. else
  162863. {
  162864. int i;
  162865. for (i = 0; i < info_ptr->num_text; i++)
  162866. png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, i);
  162867. png_free(png_ptr, info_ptr->text);
  162868. info_ptr->text = NULL;
  162869. info_ptr->num_text=0;
  162870. }
  162871. }
  162872. #endif
  162873. #if defined(PNG_tRNS_SUPPORTED)
  162874. #ifdef PNG_FREE_ME_SUPPORTED
  162875. if ((mask & PNG_FREE_TRNS) & info_ptr->free_me)
  162876. #else
  162877. if ((mask & PNG_FREE_TRNS) && (png_ptr->flags & PNG_FLAG_FREE_TRNS))
  162878. #endif
  162879. {
  162880. png_free(png_ptr, info_ptr->trans);
  162881. info_ptr->valid &= ~PNG_INFO_tRNS;
  162882. #ifndef PNG_FREE_ME_SUPPORTED
  162883. png_ptr->flags &= ~PNG_FLAG_FREE_TRNS;
  162884. #endif
  162885. info_ptr->trans = NULL;
  162886. }
  162887. #endif
  162888. #if defined(PNG_sCAL_SUPPORTED)
  162889. #ifdef PNG_FREE_ME_SUPPORTED
  162890. if ((mask & PNG_FREE_SCAL) & info_ptr->free_me)
  162891. #else
  162892. if (mask & PNG_FREE_SCAL)
  162893. #endif
  162894. {
  162895. #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
  162896. png_free(png_ptr, info_ptr->scal_s_width);
  162897. png_free(png_ptr, info_ptr->scal_s_height);
  162898. info_ptr->scal_s_width = NULL;
  162899. info_ptr->scal_s_height = NULL;
  162900. #endif
  162901. info_ptr->valid &= ~PNG_INFO_sCAL;
  162902. }
  162903. #endif
  162904. #if defined(PNG_pCAL_SUPPORTED)
  162905. #ifdef PNG_FREE_ME_SUPPORTED
  162906. if ((mask & PNG_FREE_PCAL) & info_ptr->free_me)
  162907. #else
  162908. if (mask & PNG_FREE_PCAL)
  162909. #endif
  162910. {
  162911. png_free(png_ptr, info_ptr->pcal_purpose);
  162912. png_free(png_ptr, info_ptr->pcal_units);
  162913. info_ptr->pcal_purpose = NULL;
  162914. info_ptr->pcal_units = NULL;
  162915. if (info_ptr->pcal_params != NULL)
  162916. {
  162917. int i;
  162918. for (i = 0; i < (int)info_ptr->pcal_nparams; i++)
  162919. {
  162920. png_free(png_ptr, info_ptr->pcal_params[i]);
  162921. info_ptr->pcal_params[i]=NULL;
  162922. }
  162923. png_free(png_ptr, info_ptr->pcal_params);
  162924. info_ptr->pcal_params = NULL;
  162925. }
  162926. info_ptr->valid &= ~PNG_INFO_pCAL;
  162927. }
  162928. #endif
  162929. #if defined(PNG_iCCP_SUPPORTED)
  162930. #ifdef PNG_FREE_ME_SUPPORTED
  162931. if ((mask & PNG_FREE_ICCP) & info_ptr->free_me)
  162932. #else
  162933. if (mask & PNG_FREE_ICCP)
  162934. #endif
  162935. {
  162936. png_free(png_ptr, info_ptr->iccp_name);
  162937. png_free(png_ptr, info_ptr->iccp_profile);
  162938. info_ptr->iccp_name = NULL;
  162939. info_ptr->iccp_profile = NULL;
  162940. info_ptr->valid &= ~PNG_INFO_iCCP;
  162941. }
  162942. #endif
  162943. #if defined(PNG_sPLT_SUPPORTED)
  162944. #ifdef PNG_FREE_ME_SUPPORTED
  162945. if ((mask & PNG_FREE_SPLT) & info_ptr->free_me)
  162946. #else
  162947. if (mask & PNG_FREE_SPLT)
  162948. #endif
  162949. {
  162950. if (num != -1)
  162951. {
  162952. if(info_ptr->splt_palettes)
  162953. {
  162954. png_free(png_ptr, info_ptr->splt_palettes[num].name);
  162955. png_free(png_ptr, info_ptr->splt_palettes[num].entries);
  162956. info_ptr->splt_palettes[num].name = NULL;
  162957. info_ptr->splt_palettes[num].entries = NULL;
  162958. }
  162959. }
  162960. else
  162961. {
  162962. if(info_ptr->splt_palettes_num)
  162963. {
  162964. int i;
  162965. for (i = 0; i < (int)info_ptr->splt_palettes_num; i++)
  162966. png_free_data(png_ptr, info_ptr, PNG_FREE_SPLT, i);
  162967. png_free(png_ptr, info_ptr->splt_palettes);
  162968. info_ptr->splt_palettes = NULL;
  162969. info_ptr->splt_palettes_num = 0;
  162970. }
  162971. info_ptr->valid &= ~PNG_INFO_sPLT;
  162972. }
  162973. }
  162974. #endif
  162975. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  162976. if(png_ptr->unknown_chunk.data)
  162977. {
  162978. png_free(png_ptr, png_ptr->unknown_chunk.data);
  162979. png_ptr->unknown_chunk.data = NULL;
  162980. }
  162981. #ifdef PNG_FREE_ME_SUPPORTED
  162982. if ((mask & PNG_FREE_UNKN) & info_ptr->free_me)
  162983. #else
  162984. if (mask & PNG_FREE_UNKN)
  162985. #endif
  162986. {
  162987. if (num != -1)
  162988. {
  162989. if(info_ptr->unknown_chunks)
  162990. {
  162991. png_free(png_ptr, info_ptr->unknown_chunks[num].data);
  162992. info_ptr->unknown_chunks[num].data = NULL;
  162993. }
  162994. }
  162995. else
  162996. {
  162997. int i;
  162998. if(info_ptr->unknown_chunks_num)
  162999. {
  163000. for (i = 0; i < (int)info_ptr->unknown_chunks_num; i++)
  163001. png_free_data(png_ptr, info_ptr, PNG_FREE_UNKN, i);
  163002. png_free(png_ptr, info_ptr->unknown_chunks);
  163003. info_ptr->unknown_chunks = NULL;
  163004. info_ptr->unknown_chunks_num = 0;
  163005. }
  163006. }
  163007. }
  163008. #endif
  163009. #if defined(PNG_hIST_SUPPORTED)
  163010. #ifdef PNG_FREE_ME_SUPPORTED
  163011. if ((mask & PNG_FREE_HIST) & info_ptr->free_me)
  163012. #else
  163013. if ((mask & PNG_FREE_HIST) && (png_ptr->flags & PNG_FLAG_FREE_HIST))
  163014. #endif
  163015. {
  163016. png_free(png_ptr, info_ptr->hist);
  163017. info_ptr->hist = NULL;
  163018. info_ptr->valid &= ~PNG_INFO_hIST;
  163019. #ifndef PNG_FREE_ME_SUPPORTED
  163020. png_ptr->flags &= ~PNG_FLAG_FREE_HIST;
  163021. #endif
  163022. }
  163023. #endif
  163024. #ifdef PNG_FREE_ME_SUPPORTED
  163025. if ((mask & PNG_FREE_PLTE) & info_ptr->free_me)
  163026. #else
  163027. if ((mask & PNG_FREE_PLTE) && (png_ptr->flags & PNG_FLAG_FREE_PLTE))
  163028. #endif
  163029. {
  163030. png_zfree(png_ptr, info_ptr->palette);
  163031. info_ptr->palette = NULL;
  163032. info_ptr->valid &= ~PNG_INFO_PLTE;
  163033. #ifndef PNG_FREE_ME_SUPPORTED
  163034. png_ptr->flags &= ~PNG_FLAG_FREE_PLTE;
  163035. #endif
  163036. info_ptr->num_palette = 0;
  163037. }
  163038. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  163039. #ifdef PNG_FREE_ME_SUPPORTED
  163040. if ((mask & PNG_FREE_ROWS) & info_ptr->free_me)
  163041. #else
  163042. if (mask & PNG_FREE_ROWS)
  163043. #endif
  163044. {
  163045. if(info_ptr->row_pointers)
  163046. {
  163047. int row;
  163048. for (row = 0; row < (int)info_ptr->height; row++)
  163049. {
  163050. png_free(png_ptr, info_ptr->row_pointers[row]);
  163051. info_ptr->row_pointers[row]=NULL;
  163052. }
  163053. png_free(png_ptr, info_ptr->row_pointers);
  163054. info_ptr->row_pointers=NULL;
  163055. }
  163056. info_ptr->valid &= ~PNG_INFO_IDAT;
  163057. }
  163058. #endif
  163059. #ifdef PNG_FREE_ME_SUPPORTED
  163060. if(num == -1)
  163061. info_ptr->free_me &= ~mask;
  163062. else
  163063. info_ptr->free_me &= ~(mask & ~PNG_FREE_MUL);
  163064. #endif
  163065. }
  163066. void /* PRIVATE */
  163067. png_info_destroy(png_structp png_ptr, png_infop info_ptr)
  163068. {
  163069. png_debug(1, "in png_info_destroy\n");
  163070. png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
  163071. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  163072. if (png_ptr->num_chunk_list)
  163073. {
  163074. png_free(png_ptr, png_ptr->chunk_list);
  163075. png_ptr->chunk_list=NULL;
  163076. png_ptr->num_chunk_list=0;
  163077. }
  163078. #endif
  163079. png_info_init_3(&info_ptr, png_sizeof(png_info));
  163080. }
  163081. #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
  163082. png_voidp PNGAPI
  163083. png_get_io_ptr(png_structp png_ptr)
  163084. {
  163085. if(png_ptr == NULL) return (NULL);
  163086. return (png_ptr->io_ptr);
  163087. }
  163088. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  163089. #if !defined(PNG_NO_STDIO)
  163090. void PNGAPI
  163091. png_init_io(png_structp png_ptr, png_FILE_p fp)
  163092. {
  163093. png_debug(1, "in png_init_io\n");
  163094. if(png_ptr == NULL) return;
  163095. png_ptr->io_ptr = (png_voidp)fp;
  163096. }
  163097. #endif
  163098. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  163099. png_charp PNGAPI
  163100. png_convert_to_rfc1123(png_structp png_ptr, png_timep ptime)
  163101. {
  163102. static PNG_CONST char short_months[12][4] =
  163103. {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
  163104. "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
  163105. if(png_ptr == NULL) return (NULL);
  163106. if (png_ptr->time_buffer == NULL)
  163107. {
  163108. png_ptr->time_buffer = (png_charp)png_malloc(png_ptr, (png_uint_32)(29*
  163109. png_sizeof(char)));
  163110. }
  163111. #if defined(_WIN32_WCE)
  163112. {
  163113. wchar_t time_buf[29];
  163114. wsprintf(time_buf, TEXT("%d %S %d %02d:%02d:%02d +0000"),
  163115. ptime->day % 32, short_months[(ptime->month - 1) % 12],
  163116. ptime->year, ptime->hour % 24, ptime->minute % 60,
  163117. ptime->second % 61);
  163118. WideCharToMultiByte(CP_ACP, 0, time_buf, -1, png_ptr->time_buffer, 29,
  163119. NULL, NULL);
  163120. }
  163121. #else
  163122. #ifdef USE_FAR_KEYWORD
  163123. {
  163124. char near_time_buf[29];
  163125. png_snprintf6(near_time_buf,29,"%d %s %d %02d:%02d:%02d +0000",
  163126. ptime->day % 32, short_months[(ptime->month - 1) % 12],
  163127. ptime->year, ptime->hour % 24, ptime->minute % 60,
  163128. ptime->second % 61);
  163129. png_memcpy(png_ptr->time_buffer, near_time_buf,
  163130. 29*png_sizeof(char));
  163131. }
  163132. #else
  163133. png_snprintf6(png_ptr->time_buffer,29,"%d %s %d %02d:%02d:%02d +0000",
  163134. ptime->day % 32, short_months[(ptime->month - 1) % 12],
  163135. ptime->year, ptime->hour % 24, ptime->minute % 60,
  163136. ptime->second % 61);
  163137. #endif
  163138. #endif /* _WIN32_WCE */
  163139. return ((png_charp)png_ptr->time_buffer);
  163140. }
  163141. #endif /* PNG_TIME_RFC1123_SUPPORTED */
  163142. #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
  163143. png_charp PNGAPI
  163144. png_get_copyright(png_structp png_ptr)
  163145. {
  163146. png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
  163147. return ((png_charp) "\n libpng version 1.2.21 - October 4, 2007\n\
  163148. Copyright (c) 1998-2007 Glenn Randers-Pehrson\n\
  163149. Copyright (c) 1996-1997 Andreas Dilger\n\
  163150. Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.\n");
  163151. }
  163152. png_charp PNGAPI
  163153. png_get_libpng_ver(png_structp png_ptr)
  163154. {
  163155. png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
  163156. return ((png_charp) PNG_LIBPNG_VER_STRING);
  163157. }
  163158. png_charp PNGAPI
  163159. png_get_header_ver(png_structp png_ptr)
  163160. {
  163161. png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
  163162. return ((png_charp) PNG_LIBPNG_VER_STRING);
  163163. }
  163164. png_charp PNGAPI
  163165. png_get_header_version(png_structp png_ptr)
  163166. {
  163167. png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
  163168. return ((png_charp) PNG_HEADER_VERSION_STRING
  163169. #ifndef PNG_READ_SUPPORTED
  163170. " (NO READ SUPPORT)"
  163171. #endif
  163172. "\n");
  163173. }
  163174. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  163175. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  163176. int PNGAPI
  163177. png_handle_as_unknown(png_structp png_ptr, png_bytep chunk_name)
  163178. {
  163179. int i;
  163180. png_bytep p;
  163181. if(png_ptr == NULL || chunk_name == NULL || png_ptr->num_chunk_list<=0)
  163182. return 0;
  163183. p=png_ptr->chunk_list+png_ptr->num_chunk_list*5-5;
  163184. for (i = png_ptr->num_chunk_list; i; i--, p-=5)
  163185. if (!png_memcmp(chunk_name, p, 4))
  163186. return ((int)*(p+4));
  163187. return 0;
  163188. }
  163189. #endif
  163190. int PNGAPI
  163191. png_reset_zstream(png_structp png_ptr)
  163192. {
  163193. if (png_ptr == NULL) return Z_STREAM_ERROR;
  163194. return (inflateReset(&png_ptr->zstream));
  163195. }
  163196. #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
  163197. png_uint_32 PNGAPI
  163198. png_access_version_number(void)
  163199. {
  163200. return((png_uint_32) PNG_LIBPNG_VER);
  163201. }
  163202. #if defined(PNG_READ_SUPPORTED) && defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  163203. #if !defined(PNG_1_0_X)
  163204. int PNGAPI
  163205. png_mmx_support(void)
  163206. {
  163207. return -1;
  163208. }
  163209. #endif /* PNG_1_0_X */
  163210. #endif /* PNG_READ_SUPPORTED && PNG_ASSEMBLER_CODE_SUPPORTED */
  163211. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  163212. #ifdef PNG_SIZE_T
  163213. PNG_EXTERN png_size_t PNGAPI png_convert_size PNGARG((size_t size));
  163214. png_size_t PNGAPI
  163215. png_convert_size(size_t size)
  163216. {
  163217. if (size > (png_size_t)-1)
  163218. PNG_ABORT(); /* We haven't got access to png_ptr, so no png_error() */
  163219. return ((png_size_t)size);
  163220. }
  163221. #endif /* PNG_SIZE_T */
  163222. #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
  163223. /*** End of inlined file: png.c ***/
  163224. /*** Start of inlined file: pngerror.c ***/
  163225. #define PNG_INTERNAL
  163226. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  163227. static void /* PRIVATE */
  163228. png_default_error PNGARG((png_structp png_ptr,
  163229. png_const_charp error_message));
  163230. #ifndef PNG_NO_WARNINGS
  163231. static void /* PRIVATE */
  163232. png_default_warning PNGARG((png_structp png_ptr,
  163233. png_const_charp warning_message));
  163234. #endif /* PNG_NO_WARNINGS */
  163235. #ifndef PNG_NO_ERROR_TEXT
  163236. void PNGAPI
  163237. png_error(png_structp png_ptr, png_const_charp error_message)
  163238. {
  163239. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  163240. char msg[16];
  163241. if (png_ptr != NULL)
  163242. {
  163243. if (png_ptr->flags&
  163244. (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
  163245. {
  163246. if (*error_message == '#')
  163247. {
  163248. int offset;
  163249. for (offset=1; offset<15; offset++)
  163250. if (*(error_message+offset) == ' ')
  163251. break;
  163252. if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
  163253. {
  163254. int i;
  163255. for (i=0; i<offset-1; i++)
  163256. msg[i]=error_message[i+1];
  163257. msg[i]='\0';
  163258. error_message=msg;
  163259. }
  163260. else
  163261. error_message+=offset;
  163262. }
  163263. else
  163264. {
  163265. if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
  163266. {
  163267. msg[0]='0';
  163268. msg[1]='\0';
  163269. error_message=msg;
  163270. }
  163271. }
  163272. }
  163273. }
  163274. #endif
  163275. if (png_ptr != NULL && png_ptr->error_fn != NULL)
  163276. (*(png_ptr->error_fn))(png_ptr, error_message);
  163277. png_default_error(png_ptr, error_message);
  163278. }
  163279. #else
  163280. void PNGAPI
  163281. png_err(png_structp png_ptr)
  163282. {
  163283. if (png_ptr != NULL && png_ptr->error_fn != NULL)
  163284. (*(png_ptr->error_fn))(png_ptr, '\0');
  163285. png_default_error(png_ptr, '\0');
  163286. }
  163287. #endif /* PNG_NO_ERROR_TEXT */
  163288. #ifndef PNG_NO_WARNINGS
  163289. void PNGAPI
  163290. png_warning(png_structp png_ptr, png_const_charp warning_message)
  163291. {
  163292. int offset = 0;
  163293. if (png_ptr != NULL)
  163294. {
  163295. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  163296. if (png_ptr->flags&
  163297. (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
  163298. #endif
  163299. {
  163300. if (*warning_message == '#')
  163301. {
  163302. for (offset=1; offset<15; offset++)
  163303. if (*(warning_message+offset) == ' ')
  163304. break;
  163305. }
  163306. }
  163307. if (png_ptr != NULL && png_ptr->warning_fn != NULL)
  163308. (*(png_ptr->warning_fn))(png_ptr, warning_message+offset);
  163309. }
  163310. else
  163311. png_default_warning(png_ptr, warning_message+offset);
  163312. }
  163313. #endif /* PNG_NO_WARNINGS */
  163314. #define isnonalpha(c) ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97))
  163315. #if !defined(PNG_NO_WARNINGS) || !defined(PNG_NO_ERROR_TEXT)
  163316. static void /* PRIVATE */
  163317. png_format_buffer(png_structp png_ptr, png_charp buffer, png_const_charp
  163318. error_message)
  163319. {
  163320. int iout = 0, iin = 0;
  163321. while (iin < 4)
  163322. {
  163323. int c = png_ptr->chunk_name[iin++];
  163324. if (isnonalpha(c))
  163325. {
  163326. buffer[iout++] = '[';
  163327. buffer[iout++] = png_digit[(c & 0xf0) >> 4];
  163328. buffer[iout++] = png_digit[c & 0x0f];
  163329. buffer[iout++] = ']';
  163330. }
  163331. else
  163332. {
  163333. buffer[iout++] = (png_byte)c;
  163334. }
  163335. }
  163336. if (error_message == NULL)
  163337. buffer[iout] = 0;
  163338. else
  163339. {
  163340. buffer[iout++] = ':';
  163341. buffer[iout++] = ' ';
  163342. png_strncpy(buffer+iout, error_message, 63);
  163343. buffer[iout+63] = 0;
  163344. }
  163345. }
  163346. #ifdef PNG_READ_SUPPORTED
  163347. void PNGAPI
  163348. png_chunk_error(png_structp png_ptr, png_const_charp error_message)
  163349. {
  163350. char msg[18+64];
  163351. if (png_ptr == NULL)
  163352. png_error(png_ptr, error_message);
  163353. else
  163354. {
  163355. png_format_buffer(png_ptr, msg, error_message);
  163356. png_error(png_ptr, msg);
  163357. }
  163358. }
  163359. #endif /* PNG_READ_SUPPORTED */
  163360. #endif /* !defined(PNG_NO_WARNINGS) || !defined(PNG_NO_ERROR_TEXT) */
  163361. #ifndef PNG_NO_WARNINGS
  163362. void PNGAPI
  163363. png_chunk_warning(png_structp png_ptr, png_const_charp warning_message)
  163364. {
  163365. char msg[18+64];
  163366. if (png_ptr == NULL)
  163367. png_warning(png_ptr, warning_message);
  163368. else
  163369. {
  163370. png_format_buffer(png_ptr, msg, warning_message);
  163371. png_warning(png_ptr, msg);
  163372. }
  163373. }
  163374. #endif /* PNG_NO_WARNINGS */
  163375. static void /* PRIVATE */
  163376. png_default_error(png_structp png_ptr, png_const_charp error_message)
  163377. {
  163378. #ifndef PNG_NO_CONSOLE_IO
  163379. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  163380. if (*error_message == '#')
  163381. {
  163382. int offset;
  163383. char error_number[16];
  163384. for (offset=0; offset<15; offset++)
  163385. {
  163386. error_number[offset] = *(error_message+offset+1);
  163387. if (*(error_message+offset) == ' ')
  163388. break;
  163389. }
  163390. if((offset > 1) && (offset < 15))
  163391. {
  163392. error_number[offset-1]='\0';
  163393. fprintf(stderr, "libpng error no. %s: %s\n", error_number,
  163394. error_message+offset);
  163395. }
  163396. else
  163397. fprintf(stderr, "libpng error: %s, offset=%d\n", error_message,offset);
  163398. }
  163399. else
  163400. #endif
  163401. fprintf(stderr, "libpng error: %s\n", error_message);
  163402. #endif
  163403. #ifdef PNG_SETJMP_SUPPORTED
  163404. if (png_ptr)
  163405. {
  163406. # ifdef USE_FAR_KEYWORD
  163407. {
  163408. jmp_buf jmpbuf;
  163409. png_memcpy(jmpbuf, png_ptr->jmpbuf, png_sizeof(jmp_buf));
  163410. longjmp(jmpbuf, 1);
  163411. }
  163412. # else
  163413. longjmp(png_ptr->jmpbuf, 1);
  163414. # endif
  163415. }
  163416. #else
  163417. PNG_ABORT();
  163418. #endif
  163419. #ifdef PNG_NO_CONSOLE_IO
  163420. error_message = error_message; /* make compiler happy */
  163421. #endif
  163422. }
  163423. #ifndef PNG_NO_WARNINGS
  163424. static void /* PRIVATE */
  163425. png_default_warning(png_structp png_ptr, png_const_charp warning_message)
  163426. {
  163427. #ifndef PNG_NO_CONSOLE_IO
  163428. # ifdef PNG_ERROR_NUMBERS_SUPPORTED
  163429. if (*warning_message == '#')
  163430. {
  163431. int offset;
  163432. char warning_number[16];
  163433. for (offset=0; offset<15; offset++)
  163434. {
  163435. warning_number[offset]=*(warning_message+offset+1);
  163436. if (*(warning_message+offset) == ' ')
  163437. break;
  163438. }
  163439. if((offset > 1) && (offset < 15))
  163440. {
  163441. warning_number[offset-1]='\0';
  163442. fprintf(stderr, "libpng warning no. %s: %s\n", warning_number,
  163443. warning_message+offset);
  163444. }
  163445. else
  163446. fprintf(stderr, "libpng warning: %s\n", warning_message);
  163447. }
  163448. else
  163449. # endif
  163450. fprintf(stderr, "libpng warning: %s\n", warning_message);
  163451. #else
  163452. warning_message = warning_message; /* make compiler happy */
  163453. #endif
  163454. png_ptr = png_ptr; /* make compiler happy */
  163455. }
  163456. #endif /* PNG_NO_WARNINGS */
  163457. void PNGAPI
  163458. png_set_error_fn(png_structp png_ptr, png_voidp error_ptr,
  163459. png_error_ptr error_fn, png_error_ptr warning_fn)
  163460. {
  163461. if (png_ptr == NULL)
  163462. return;
  163463. png_ptr->error_ptr = error_ptr;
  163464. png_ptr->error_fn = error_fn;
  163465. png_ptr->warning_fn = warning_fn;
  163466. }
  163467. png_voidp PNGAPI
  163468. png_get_error_ptr(png_structp png_ptr)
  163469. {
  163470. if (png_ptr == NULL)
  163471. return NULL;
  163472. return ((png_voidp)png_ptr->error_ptr);
  163473. }
  163474. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  163475. void PNGAPI
  163476. png_set_strip_error_numbers(png_structp png_ptr, png_uint_32 strip_mode)
  163477. {
  163478. if(png_ptr != NULL)
  163479. {
  163480. png_ptr->flags &=
  163481. ((~(PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))&strip_mode);
  163482. }
  163483. }
  163484. #endif
  163485. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  163486. /*** End of inlined file: pngerror.c ***/
  163487. /*** Start of inlined file: pngget.c ***/
  163488. #define PNG_INTERNAL
  163489. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  163490. png_uint_32 PNGAPI
  163491. png_get_valid(png_structp png_ptr, png_infop info_ptr, png_uint_32 flag)
  163492. {
  163493. if (png_ptr != NULL && info_ptr != NULL)
  163494. return(info_ptr->valid & flag);
  163495. else
  163496. return(0);
  163497. }
  163498. png_uint_32 PNGAPI
  163499. png_get_rowbytes(png_structp png_ptr, png_infop info_ptr)
  163500. {
  163501. if (png_ptr != NULL && info_ptr != NULL)
  163502. return(info_ptr->rowbytes);
  163503. else
  163504. return(0);
  163505. }
  163506. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  163507. png_bytepp PNGAPI
  163508. png_get_rows(png_structp png_ptr, png_infop info_ptr)
  163509. {
  163510. if (png_ptr != NULL && info_ptr != NULL)
  163511. return(info_ptr->row_pointers);
  163512. else
  163513. return(0);
  163514. }
  163515. #endif
  163516. #ifdef PNG_EASY_ACCESS_SUPPORTED
  163517. png_uint_32 PNGAPI
  163518. png_get_image_width(png_structp png_ptr, png_infop info_ptr)
  163519. {
  163520. if (png_ptr != NULL && info_ptr != NULL)
  163521. {
  163522. return info_ptr->width;
  163523. }
  163524. return (0);
  163525. }
  163526. png_uint_32 PNGAPI
  163527. png_get_image_height(png_structp png_ptr, png_infop info_ptr)
  163528. {
  163529. if (png_ptr != NULL && info_ptr != NULL)
  163530. {
  163531. return info_ptr->height;
  163532. }
  163533. return (0);
  163534. }
  163535. png_byte PNGAPI
  163536. png_get_bit_depth(png_structp png_ptr, png_infop info_ptr)
  163537. {
  163538. if (png_ptr != NULL && info_ptr != NULL)
  163539. {
  163540. return info_ptr->bit_depth;
  163541. }
  163542. return (0);
  163543. }
  163544. png_byte PNGAPI
  163545. png_get_color_type(png_structp png_ptr, png_infop info_ptr)
  163546. {
  163547. if (png_ptr != NULL && info_ptr != NULL)
  163548. {
  163549. return info_ptr->color_type;
  163550. }
  163551. return (0);
  163552. }
  163553. png_byte PNGAPI
  163554. png_get_filter_type(png_structp png_ptr, png_infop info_ptr)
  163555. {
  163556. if (png_ptr != NULL && info_ptr != NULL)
  163557. {
  163558. return info_ptr->filter_type;
  163559. }
  163560. return (0);
  163561. }
  163562. png_byte PNGAPI
  163563. png_get_interlace_type(png_structp png_ptr, png_infop info_ptr)
  163564. {
  163565. if (png_ptr != NULL && info_ptr != NULL)
  163566. {
  163567. return info_ptr->interlace_type;
  163568. }
  163569. return (0);
  163570. }
  163571. png_byte PNGAPI
  163572. png_get_compression_type(png_structp png_ptr, png_infop info_ptr)
  163573. {
  163574. if (png_ptr != NULL && info_ptr != NULL)
  163575. {
  163576. return info_ptr->compression_type;
  163577. }
  163578. return (0);
  163579. }
  163580. png_uint_32 PNGAPI
  163581. png_get_x_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
  163582. {
  163583. if (png_ptr != NULL && info_ptr != NULL)
  163584. #if defined(PNG_pHYs_SUPPORTED)
  163585. if (info_ptr->valid & PNG_INFO_pHYs)
  163586. {
  163587. png_debug1(1, "in %s retrieval function\n", "png_get_x_pixels_per_meter");
  163588. if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
  163589. return (0);
  163590. else return (info_ptr->x_pixels_per_unit);
  163591. }
  163592. #else
  163593. return (0);
  163594. #endif
  163595. return (0);
  163596. }
  163597. png_uint_32 PNGAPI
  163598. png_get_y_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
  163599. {
  163600. if (png_ptr != NULL && info_ptr != NULL)
  163601. #if defined(PNG_pHYs_SUPPORTED)
  163602. if (info_ptr->valid & PNG_INFO_pHYs)
  163603. {
  163604. png_debug1(1, "in %s retrieval function\n", "png_get_y_pixels_per_meter");
  163605. if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
  163606. return (0);
  163607. else return (info_ptr->y_pixels_per_unit);
  163608. }
  163609. #else
  163610. return (0);
  163611. #endif
  163612. return (0);
  163613. }
  163614. png_uint_32 PNGAPI
  163615. png_get_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
  163616. {
  163617. if (png_ptr != NULL && info_ptr != NULL)
  163618. #if defined(PNG_pHYs_SUPPORTED)
  163619. if (info_ptr->valid & PNG_INFO_pHYs)
  163620. {
  163621. png_debug1(1, "in %s retrieval function\n", "png_get_pixels_per_meter");
  163622. if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER ||
  163623. info_ptr->x_pixels_per_unit != info_ptr->y_pixels_per_unit)
  163624. return (0);
  163625. else return (info_ptr->x_pixels_per_unit);
  163626. }
  163627. #else
  163628. return (0);
  163629. #endif
  163630. return (0);
  163631. }
  163632. #ifdef PNG_FLOATING_POINT_SUPPORTED
  163633. float PNGAPI
  163634. png_get_pixel_aspect_ratio(png_structp png_ptr, png_infop info_ptr)
  163635. {
  163636. if (png_ptr != NULL && info_ptr != NULL)
  163637. #if defined(PNG_pHYs_SUPPORTED)
  163638. if (info_ptr->valid & PNG_INFO_pHYs)
  163639. {
  163640. png_debug1(1, "in %s retrieval function\n", "png_get_aspect_ratio");
  163641. if (info_ptr->x_pixels_per_unit == 0)
  163642. return ((float)0.0);
  163643. else
  163644. return ((float)((float)info_ptr->y_pixels_per_unit
  163645. /(float)info_ptr->x_pixels_per_unit));
  163646. }
  163647. #else
  163648. return (0.0);
  163649. #endif
  163650. return ((float)0.0);
  163651. }
  163652. #endif
  163653. png_int_32 PNGAPI
  163654. png_get_x_offset_microns(png_structp png_ptr, png_infop info_ptr)
  163655. {
  163656. if (png_ptr != NULL && info_ptr != NULL)
  163657. #if defined(PNG_oFFs_SUPPORTED)
  163658. if (info_ptr->valid & PNG_INFO_oFFs)
  163659. {
  163660. png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns");
  163661. if(info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
  163662. return (0);
  163663. else return (info_ptr->x_offset);
  163664. }
  163665. #else
  163666. return (0);
  163667. #endif
  163668. return (0);
  163669. }
  163670. png_int_32 PNGAPI
  163671. png_get_y_offset_microns(png_structp png_ptr, png_infop info_ptr)
  163672. {
  163673. if (png_ptr != NULL && info_ptr != NULL)
  163674. #if defined(PNG_oFFs_SUPPORTED)
  163675. if (info_ptr->valid & PNG_INFO_oFFs)
  163676. {
  163677. png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns");
  163678. if(info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
  163679. return (0);
  163680. else return (info_ptr->y_offset);
  163681. }
  163682. #else
  163683. return (0);
  163684. #endif
  163685. return (0);
  163686. }
  163687. png_int_32 PNGAPI
  163688. png_get_x_offset_pixels(png_structp png_ptr, png_infop info_ptr)
  163689. {
  163690. if (png_ptr != NULL && info_ptr != NULL)
  163691. #if defined(PNG_oFFs_SUPPORTED)
  163692. if (info_ptr->valid & PNG_INFO_oFFs)
  163693. {
  163694. png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns");
  163695. if(info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
  163696. return (0);
  163697. else return (info_ptr->x_offset);
  163698. }
  163699. #else
  163700. return (0);
  163701. #endif
  163702. return (0);
  163703. }
  163704. png_int_32 PNGAPI
  163705. png_get_y_offset_pixels(png_structp png_ptr, png_infop info_ptr)
  163706. {
  163707. if (png_ptr != NULL && info_ptr != NULL)
  163708. #if defined(PNG_oFFs_SUPPORTED)
  163709. if (info_ptr->valid & PNG_INFO_oFFs)
  163710. {
  163711. png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns");
  163712. if(info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
  163713. return (0);
  163714. else return (info_ptr->y_offset);
  163715. }
  163716. #else
  163717. return (0);
  163718. #endif
  163719. return (0);
  163720. }
  163721. #if defined(PNG_INCH_CONVERSIONS) && defined(PNG_FLOATING_POINT_SUPPORTED)
  163722. png_uint_32 PNGAPI
  163723. png_get_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
  163724. {
  163725. return ((png_uint_32)((float)png_get_pixels_per_meter(png_ptr, info_ptr)
  163726. *.0254 +.5));
  163727. }
  163728. png_uint_32 PNGAPI
  163729. png_get_x_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
  163730. {
  163731. return ((png_uint_32)((float)png_get_x_pixels_per_meter(png_ptr, info_ptr)
  163732. *.0254 +.5));
  163733. }
  163734. png_uint_32 PNGAPI
  163735. png_get_y_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
  163736. {
  163737. return ((png_uint_32)((float)png_get_y_pixels_per_meter(png_ptr, info_ptr)
  163738. *.0254 +.5));
  163739. }
  163740. float PNGAPI
  163741. png_get_x_offset_inches(png_structp png_ptr, png_infop info_ptr)
  163742. {
  163743. return ((float)png_get_x_offset_microns(png_ptr, info_ptr)
  163744. *.00003937);
  163745. }
  163746. float PNGAPI
  163747. png_get_y_offset_inches(png_structp png_ptr, png_infop info_ptr)
  163748. {
  163749. return ((float)png_get_y_offset_microns(png_ptr, info_ptr)
  163750. *.00003937);
  163751. }
  163752. #if defined(PNG_pHYs_SUPPORTED)
  163753. png_uint_32 PNGAPI
  163754. png_get_pHYs_dpi(png_structp png_ptr, png_infop info_ptr,
  163755. png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
  163756. {
  163757. png_uint_32 retval = 0;
  163758. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
  163759. {
  163760. png_debug1(1, "in %s retrieval function\n", "pHYs");
  163761. if (res_x != NULL)
  163762. {
  163763. *res_x = info_ptr->x_pixels_per_unit;
  163764. retval |= PNG_INFO_pHYs;
  163765. }
  163766. if (res_y != NULL)
  163767. {
  163768. *res_y = info_ptr->y_pixels_per_unit;
  163769. retval |= PNG_INFO_pHYs;
  163770. }
  163771. if (unit_type != NULL)
  163772. {
  163773. *unit_type = (int)info_ptr->phys_unit_type;
  163774. retval |= PNG_INFO_pHYs;
  163775. if(*unit_type == 1)
  163776. {
  163777. if (res_x != NULL) *res_x = (png_uint_32)(*res_x * .0254 + .50);
  163778. if (res_y != NULL) *res_y = (png_uint_32)(*res_y * .0254 + .50);
  163779. }
  163780. }
  163781. }
  163782. return (retval);
  163783. }
  163784. #endif /* PNG_pHYs_SUPPORTED */
  163785. #endif /* PNG_INCH_CONVERSIONS && PNG_FLOATING_POINT_SUPPORTED */
  163786. #endif /* PNG_EASY_ACCESS_SUPPORTED */
  163787. png_byte PNGAPI
  163788. png_get_channels(png_structp png_ptr, png_infop info_ptr)
  163789. {
  163790. if (png_ptr != NULL && info_ptr != NULL)
  163791. return(info_ptr->channels);
  163792. else
  163793. return (0);
  163794. }
  163795. png_bytep PNGAPI
  163796. png_get_signature(png_structp png_ptr, png_infop info_ptr)
  163797. {
  163798. if (png_ptr != NULL && info_ptr != NULL)
  163799. return(info_ptr->signature);
  163800. else
  163801. return (NULL);
  163802. }
  163803. #if defined(PNG_bKGD_SUPPORTED)
  163804. png_uint_32 PNGAPI
  163805. png_get_bKGD(png_structp png_ptr, png_infop info_ptr,
  163806. png_color_16p *background)
  163807. {
  163808. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD)
  163809. && background != NULL)
  163810. {
  163811. png_debug1(1, "in %s retrieval function\n", "bKGD");
  163812. *background = &(info_ptr->background);
  163813. return (PNG_INFO_bKGD);
  163814. }
  163815. return (0);
  163816. }
  163817. #endif
  163818. #if defined(PNG_cHRM_SUPPORTED)
  163819. #ifdef PNG_FLOATING_POINT_SUPPORTED
  163820. png_uint_32 PNGAPI
  163821. png_get_cHRM(png_structp png_ptr, png_infop info_ptr,
  163822. double *white_x, double *white_y, double *red_x, double *red_y,
  163823. double *green_x, double *green_y, double *blue_x, double *blue_y)
  163824. {
  163825. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
  163826. {
  163827. png_debug1(1, "in %s retrieval function\n", "cHRM");
  163828. if (white_x != NULL)
  163829. *white_x = (double)info_ptr->x_white;
  163830. if (white_y != NULL)
  163831. *white_y = (double)info_ptr->y_white;
  163832. if (red_x != NULL)
  163833. *red_x = (double)info_ptr->x_red;
  163834. if (red_y != NULL)
  163835. *red_y = (double)info_ptr->y_red;
  163836. if (green_x != NULL)
  163837. *green_x = (double)info_ptr->x_green;
  163838. if (green_y != NULL)
  163839. *green_y = (double)info_ptr->y_green;
  163840. if (blue_x != NULL)
  163841. *blue_x = (double)info_ptr->x_blue;
  163842. if (blue_y != NULL)
  163843. *blue_y = (double)info_ptr->y_blue;
  163844. return (PNG_INFO_cHRM);
  163845. }
  163846. return (0);
  163847. }
  163848. #endif
  163849. #ifdef PNG_FIXED_POINT_SUPPORTED
  163850. png_uint_32 PNGAPI
  163851. png_get_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
  163852. png_fixed_point *white_x, png_fixed_point *white_y, png_fixed_point *red_x,
  163853. png_fixed_point *red_y, png_fixed_point *green_x, png_fixed_point *green_y,
  163854. png_fixed_point *blue_x, png_fixed_point *blue_y)
  163855. {
  163856. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
  163857. {
  163858. png_debug1(1, "in %s retrieval function\n", "cHRM");
  163859. if (white_x != NULL)
  163860. *white_x = info_ptr->int_x_white;
  163861. if (white_y != NULL)
  163862. *white_y = info_ptr->int_y_white;
  163863. if (red_x != NULL)
  163864. *red_x = info_ptr->int_x_red;
  163865. if (red_y != NULL)
  163866. *red_y = info_ptr->int_y_red;
  163867. if (green_x != NULL)
  163868. *green_x = info_ptr->int_x_green;
  163869. if (green_y != NULL)
  163870. *green_y = info_ptr->int_y_green;
  163871. if (blue_x != NULL)
  163872. *blue_x = info_ptr->int_x_blue;
  163873. if (blue_y != NULL)
  163874. *blue_y = info_ptr->int_y_blue;
  163875. return (PNG_INFO_cHRM);
  163876. }
  163877. return (0);
  163878. }
  163879. #endif
  163880. #endif
  163881. #if defined(PNG_gAMA_SUPPORTED)
  163882. #ifdef PNG_FLOATING_POINT_SUPPORTED
  163883. png_uint_32 PNGAPI
  163884. png_get_gAMA(png_structp png_ptr, png_infop info_ptr, double *file_gamma)
  163885. {
  163886. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
  163887. && file_gamma != NULL)
  163888. {
  163889. png_debug1(1, "in %s retrieval function\n", "gAMA");
  163890. *file_gamma = (double)info_ptr->gamma;
  163891. return (PNG_INFO_gAMA);
  163892. }
  163893. return (0);
  163894. }
  163895. #endif
  163896. #ifdef PNG_FIXED_POINT_SUPPORTED
  163897. png_uint_32 PNGAPI
  163898. png_get_gAMA_fixed(png_structp png_ptr, png_infop info_ptr,
  163899. png_fixed_point *int_file_gamma)
  163900. {
  163901. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
  163902. && int_file_gamma != NULL)
  163903. {
  163904. png_debug1(1, "in %s retrieval function\n", "gAMA");
  163905. *int_file_gamma = info_ptr->int_gamma;
  163906. return (PNG_INFO_gAMA);
  163907. }
  163908. return (0);
  163909. }
  163910. #endif
  163911. #endif
  163912. #if defined(PNG_sRGB_SUPPORTED)
  163913. png_uint_32 PNGAPI
  163914. png_get_sRGB(png_structp png_ptr, png_infop info_ptr, int *file_srgb_intent)
  163915. {
  163916. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB)
  163917. && file_srgb_intent != NULL)
  163918. {
  163919. png_debug1(1, "in %s retrieval function\n", "sRGB");
  163920. *file_srgb_intent = (int)info_ptr->srgb_intent;
  163921. return (PNG_INFO_sRGB);
  163922. }
  163923. return (0);
  163924. }
  163925. #endif
  163926. #if defined(PNG_iCCP_SUPPORTED)
  163927. png_uint_32 PNGAPI
  163928. png_get_iCCP(png_structp png_ptr, png_infop info_ptr,
  163929. png_charpp name, int *compression_type,
  163930. png_charpp profile, png_uint_32 *proflen)
  163931. {
  163932. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP)
  163933. && name != NULL && profile != NULL && proflen != NULL)
  163934. {
  163935. png_debug1(1, "in %s retrieval function\n", "iCCP");
  163936. *name = info_ptr->iccp_name;
  163937. *profile = info_ptr->iccp_profile;
  163938. *proflen = (int)info_ptr->iccp_proflen;
  163939. *compression_type = (int)info_ptr->iccp_compression;
  163940. return (PNG_INFO_iCCP);
  163941. }
  163942. return (0);
  163943. }
  163944. #endif
  163945. #if defined(PNG_sPLT_SUPPORTED)
  163946. png_uint_32 PNGAPI
  163947. png_get_sPLT(png_structp png_ptr, png_infop info_ptr,
  163948. png_sPLT_tpp spalettes)
  163949. {
  163950. if (png_ptr != NULL && info_ptr != NULL && spalettes != NULL)
  163951. {
  163952. *spalettes = info_ptr->splt_palettes;
  163953. return ((png_uint_32)info_ptr->splt_palettes_num);
  163954. }
  163955. return (0);
  163956. }
  163957. #endif
  163958. #if defined(PNG_hIST_SUPPORTED)
  163959. png_uint_32 PNGAPI
  163960. png_get_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p *hist)
  163961. {
  163962. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST)
  163963. && hist != NULL)
  163964. {
  163965. png_debug1(1, "in %s retrieval function\n", "hIST");
  163966. *hist = info_ptr->hist;
  163967. return (PNG_INFO_hIST);
  163968. }
  163969. return (0);
  163970. }
  163971. #endif
  163972. png_uint_32 PNGAPI
  163973. png_get_IHDR(png_structp png_ptr, png_infop info_ptr,
  163974. png_uint_32 *width, png_uint_32 *height, int *bit_depth,
  163975. int *color_type, int *interlace_type, int *compression_type,
  163976. int *filter_type)
  163977. {
  163978. if (png_ptr != NULL && info_ptr != NULL && width != NULL && height != NULL &&
  163979. bit_depth != NULL && color_type != NULL)
  163980. {
  163981. png_debug1(1, "in %s retrieval function\n", "IHDR");
  163982. *width = info_ptr->width;
  163983. *height = info_ptr->height;
  163984. *bit_depth = info_ptr->bit_depth;
  163985. if (info_ptr->bit_depth < 1 || info_ptr->bit_depth > 16)
  163986. png_error(png_ptr, "Invalid bit depth");
  163987. *color_type = info_ptr->color_type;
  163988. if (info_ptr->color_type > 6)
  163989. png_error(png_ptr, "Invalid color type");
  163990. if (compression_type != NULL)
  163991. *compression_type = info_ptr->compression_type;
  163992. if (filter_type != NULL)
  163993. *filter_type = info_ptr->filter_type;
  163994. if (interlace_type != NULL)
  163995. *interlace_type = info_ptr->interlace_type;
  163996. if (*width == 0 || *width > PNG_UINT_31_MAX)
  163997. png_error(png_ptr, "Invalid image width");
  163998. if (*height == 0 || *height > PNG_UINT_31_MAX)
  163999. png_error(png_ptr, "Invalid image height");
  164000. if (info_ptr->width > (PNG_UINT_32_MAX
  164001. >> 3) /* 8-byte RGBA pixels */
  164002. - 64 /* bigrowbuf hack */
  164003. - 1 /* filter byte */
  164004. - 7*8 /* rounding of width to multiple of 8 pixels */
  164005. - 8) /* extra max_pixel_depth pad */
  164006. {
  164007. png_warning(png_ptr,
  164008. "Width too large for libpng to process image data.");
  164009. }
  164010. return (1);
  164011. }
  164012. return (0);
  164013. }
  164014. #if defined(PNG_oFFs_SUPPORTED)
  164015. png_uint_32 PNGAPI
  164016. png_get_oFFs(png_structp png_ptr, png_infop info_ptr,
  164017. png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type)
  164018. {
  164019. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)
  164020. && offset_x != NULL && offset_y != NULL && unit_type != NULL)
  164021. {
  164022. png_debug1(1, "in %s retrieval function\n", "oFFs");
  164023. *offset_x = info_ptr->x_offset;
  164024. *offset_y = info_ptr->y_offset;
  164025. *unit_type = (int)info_ptr->offset_unit_type;
  164026. return (PNG_INFO_oFFs);
  164027. }
  164028. return (0);
  164029. }
  164030. #endif
  164031. #if defined(PNG_pCAL_SUPPORTED)
  164032. png_uint_32 PNGAPI
  164033. png_get_pCAL(png_structp png_ptr, png_infop info_ptr,
  164034. png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams,
  164035. png_charp *units, png_charpp *params)
  164036. {
  164037. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL)
  164038. && purpose != NULL && X0 != NULL && X1 != NULL && type != NULL &&
  164039. nparams != NULL && units != NULL && params != NULL)
  164040. {
  164041. png_debug1(1, "in %s retrieval function\n", "pCAL");
  164042. *purpose = info_ptr->pcal_purpose;
  164043. *X0 = info_ptr->pcal_X0;
  164044. *X1 = info_ptr->pcal_X1;
  164045. *type = (int)info_ptr->pcal_type;
  164046. *nparams = (int)info_ptr->pcal_nparams;
  164047. *units = info_ptr->pcal_units;
  164048. *params = info_ptr->pcal_params;
  164049. return (PNG_INFO_pCAL);
  164050. }
  164051. return (0);
  164052. }
  164053. #endif
  164054. #if defined(PNG_sCAL_SUPPORTED)
  164055. #ifdef PNG_FLOATING_POINT_SUPPORTED
  164056. png_uint_32 PNGAPI
  164057. png_get_sCAL(png_structp png_ptr, png_infop info_ptr,
  164058. int *unit, double *width, double *height)
  164059. {
  164060. if (png_ptr != NULL && info_ptr != NULL &&
  164061. (info_ptr->valid & PNG_INFO_sCAL))
  164062. {
  164063. *unit = info_ptr->scal_unit;
  164064. *width = info_ptr->scal_pixel_width;
  164065. *height = info_ptr->scal_pixel_height;
  164066. return (PNG_INFO_sCAL);
  164067. }
  164068. return(0);
  164069. }
  164070. #else
  164071. #ifdef PNG_FIXED_POINT_SUPPORTED
  164072. png_uint_32 PNGAPI
  164073. png_get_sCAL_s(png_structp png_ptr, png_infop info_ptr,
  164074. int *unit, png_charpp width, png_charpp height)
  164075. {
  164076. if (png_ptr != NULL && info_ptr != NULL &&
  164077. (info_ptr->valid & PNG_INFO_sCAL))
  164078. {
  164079. *unit = info_ptr->scal_unit;
  164080. *width = info_ptr->scal_s_width;
  164081. *height = info_ptr->scal_s_height;
  164082. return (PNG_INFO_sCAL);
  164083. }
  164084. return(0);
  164085. }
  164086. #endif
  164087. #endif
  164088. #endif
  164089. #if defined(PNG_pHYs_SUPPORTED)
  164090. png_uint_32 PNGAPI
  164091. png_get_pHYs(png_structp png_ptr, png_infop info_ptr,
  164092. png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
  164093. {
  164094. png_uint_32 retval = 0;
  164095. if (png_ptr != NULL && info_ptr != NULL &&
  164096. (info_ptr->valid & PNG_INFO_pHYs))
  164097. {
  164098. png_debug1(1, "in %s retrieval function\n", "pHYs");
  164099. if (res_x != NULL)
  164100. {
  164101. *res_x = info_ptr->x_pixels_per_unit;
  164102. retval |= PNG_INFO_pHYs;
  164103. }
  164104. if (res_y != NULL)
  164105. {
  164106. *res_y = info_ptr->y_pixels_per_unit;
  164107. retval |= PNG_INFO_pHYs;
  164108. }
  164109. if (unit_type != NULL)
  164110. {
  164111. *unit_type = (int)info_ptr->phys_unit_type;
  164112. retval |= PNG_INFO_pHYs;
  164113. }
  164114. }
  164115. return (retval);
  164116. }
  164117. #endif
  164118. png_uint_32 PNGAPI
  164119. png_get_PLTE(png_structp png_ptr, png_infop info_ptr, png_colorp *palette,
  164120. int *num_palette)
  164121. {
  164122. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_PLTE)
  164123. && palette != NULL)
  164124. {
  164125. png_debug1(1, "in %s retrieval function\n", "PLTE");
  164126. *palette = info_ptr->palette;
  164127. *num_palette = info_ptr->num_palette;
  164128. png_debug1(3, "num_palette = %d\n", *num_palette);
  164129. return (PNG_INFO_PLTE);
  164130. }
  164131. return (0);
  164132. }
  164133. #if defined(PNG_sBIT_SUPPORTED)
  164134. png_uint_32 PNGAPI
  164135. png_get_sBIT(png_structp png_ptr, png_infop info_ptr, png_color_8p *sig_bit)
  164136. {
  164137. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT)
  164138. && sig_bit != NULL)
  164139. {
  164140. png_debug1(1, "in %s retrieval function\n", "sBIT");
  164141. *sig_bit = &(info_ptr->sig_bit);
  164142. return (PNG_INFO_sBIT);
  164143. }
  164144. return (0);
  164145. }
  164146. #endif
  164147. #if defined(PNG_TEXT_SUPPORTED)
  164148. png_uint_32 PNGAPI
  164149. png_get_text(png_structp png_ptr, png_infop info_ptr, png_textp *text_ptr,
  164150. int *num_text)
  164151. {
  164152. if (png_ptr != NULL && info_ptr != NULL && info_ptr->num_text > 0)
  164153. {
  164154. png_debug1(1, "in %s retrieval function\n",
  164155. (png_ptr->chunk_name[0] == '\0' ? "text"
  164156. : (png_const_charp)png_ptr->chunk_name));
  164157. if (text_ptr != NULL)
  164158. *text_ptr = info_ptr->text;
  164159. if (num_text != NULL)
  164160. *num_text = info_ptr->num_text;
  164161. return ((png_uint_32)info_ptr->num_text);
  164162. }
  164163. if (num_text != NULL)
  164164. *num_text = 0;
  164165. return(0);
  164166. }
  164167. #endif
  164168. #if defined(PNG_tIME_SUPPORTED)
  164169. png_uint_32 PNGAPI
  164170. png_get_tIME(png_structp png_ptr, png_infop info_ptr, png_timep *mod_time)
  164171. {
  164172. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME)
  164173. && mod_time != NULL)
  164174. {
  164175. png_debug1(1, "in %s retrieval function\n", "tIME");
  164176. *mod_time = &(info_ptr->mod_time);
  164177. return (PNG_INFO_tIME);
  164178. }
  164179. return (0);
  164180. }
  164181. #endif
  164182. #if defined(PNG_tRNS_SUPPORTED)
  164183. png_uint_32 PNGAPI
  164184. png_get_tRNS(png_structp png_ptr, png_infop info_ptr,
  164185. png_bytep *trans, int *num_trans, png_color_16p *trans_values)
  164186. {
  164187. png_uint_32 retval = 0;
  164188. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
  164189. {
  164190. png_debug1(1, "in %s retrieval function\n", "tRNS");
  164191. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  164192. {
  164193. if (trans != NULL)
  164194. {
  164195. *trans = info_ptr->trans;
  164196. retval |= PNG_INFO_tRNS;
  164197. }
  164198. if (trans_values != NULL)
  164199. *trans_values = &(info_ptr->trans_values);
  164200. }
  164201. else /* if (info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) */
  164202. {
  164203. if (trans_values != NULL)
  164204. {
  164205. *trans_values = &(info_ptr->trans_values);
  164206. retval |= PNG_INFO_tRNS;
  164207. }
  164208. if(trans != NULL)
  164209. *trans = NULL;
  164210. }
  164211. if(num_trans != NULL)
  164212. {
  164213. *num_trans = info_ptr->num_trans;
  164214. retval |= PNG_INFO_tRNS;
  164215. }
  164216. }
  164217. return (retval);
  164218. }
  164219. #endif
  164220. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  164221. png_uint_32 PNGAPI
  164222. png_get_unknown_chunks(png_structp png_ptr, png_infop info_ptr,
  164223. png_unknown_chunkpp unknowns)
  164224. {
  164225. if (png_ptr != NULL && info_ptr != NULL && unknowns != NULL)
  164226. {
  164227. *unknowns = info_ptr->unknown_chunks;
  164228. return ((png_uint_32)info_ptr->unknown_chunks_num);
  164229. }
  164230. return (0);
  164231. }
  164232. #endif
  164233. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  164234. png_byte PNGAPI
  164235. png_get_rgb_to_gray_status (png_structp png_ptr)
  164236. {
  164237. return (png_byte)(png_ptr? png_ptr->rgb_to_gray_status : 0);
  164238. }
  164239. #endif
  164240. #if defined(PNG_USER_CHUNKS_SUPPORTED)
  164241. png_voidp PNGAPI
  164242. png_get_user_chunk_ptr(png_structp png_ptr)
  164243. {
  164244. return (png_ptr? png_ptr->user_chunk_ptr : NULL);
  164245. }
  164246. #endif
  164247. #ifdef PNG_WRITE_SUPPORTED
  164248. png_uint_32 PNGAPI
  164249. png_get_compression_buffer_size(png_structp png_ptr)
  164250. {
  164251. return (png_uint_32)(png_ptr? png_ptr->zbuf_size : 0L);
  164252. }
  164253. #endif
  164254. #ifdef PNG_ASSEMBLER_CODE_SUPPORTED
  164255. #ifndef PNG_1_0_X
  164256. png_uint_32 PNGAPI
  164257. png_get_asm_flags (png_structp png_ptr)
  164258. {
  164259. return (png_ptr? 0L: 0L);
  164260. }
  164261. png_uint_32 PNGAPI
  164262. png_get_asm_flagmask (int flag_select)
  164263. {
  164264. flag_select=flag_select;
  164265. return 0L;
  164266. }
  164267. png_uint_32 PNGAPI
  164268. png_get_mmx_flagmask (int flag_select, int *compilerID)
  164269. {
  164270. flag_select=flag_select;
  164271. *compilerID = -1; /* unknown (i.e., no asm/MMX code compiled) */
  164272. return 0L;
  164273. }
  164274. png_byte PNGAPI
  164275. png_get_mmx_bitdepth_threshold (png_structp png_ptr)
  164276. {
  164277. return (png_ptr? 0: 0);
  164278. }
  164279. png_uint_32 PNGAPI
  164280. png_get_mmx_rowbytes_threshold (png_structp png_ptr)
  164281. {
  164282. return (png_ptr? 0L: 0L);
  164283. }
  164284. #endif /* ?PNG_1_0_X */
  164285. #endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */
  164286. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  164287. png_uint_32 PNGAPI
  164288. png_get_user_width_max (png_structp png_ptr)
  164289. {
  164290. return (png_ptr? png_ptr->user_width_max : 0);
  164291. }
  164292. png_uint_32 PNGAPI
  164293. png_get_user_height_max (png_structp png_ptr)
  164294. {
  164295. return (png_ptr? png_ptr->user_height_max : 0);
  164296. }
  164297. #endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
  164298. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  164299. /*** End of inlined file: pngget.c ***/
  164300. /*** Start of inlined file: pngmem.c ***/
  164301. #define PNG_INTERNAL
  164302. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  164303. #if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
  164304. png_voidp /* PRIVATE */
  164305. png_create_struct(int type)
  164306. {
  164307. #ifdef PNG_USER_MEM_SUPPORTED
  164308. return (png_create_struct_2(type, png_malloc_ptr_NULL, png_voidp_NULL));
  164309. }
  164310. png_voidp /* PRIVATE */
  164311. png_create_struct_2(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr)
  164312. {
  164313. #endif /* PNG_USER_MEM_SUPPORTED */
  164314. png_size_t size;
  164315. png_voidp struct_ptr;
  164316. if (type == PNG_STRUCT_INFO)
  164317. size = png_sizeof(png_info);
  164318. else if (type == PNG_STRUCT_PNG)
  164319. size = png_sizeof(png_struct);
  164320. else
  164321. return (png_get_copyright(NULL));
  164322. #ifdef PNG_USER_MEM_SUPPORTED
  164323. if(malloc_fn != NULL)
  164324. {
  164325. png_struct dummy_struct;
  164326. png_structp png_ptr = &dummy_struct;
  164327. png_ptr->mem_ptr=mem_ptr;
  164328. struct_ptr = (*(malloc_fn))(png_ptr, (png_uint_32)size);
  164329. }
  164330. else
  164331. #endif /* PNG_USER_MEM_SUPPORTED */
  164332. struct_ptr = (png_voidp)farmalloc(size);
  164333. if (struct_ptr != NULL)
  164334. png_memset(struct_ptr, 0, size);
  164335. return (struct_ptr);
  164336. }
  164337. void /* PRIVATE */
  164338. png_destroy_struct(png_voidp struct_ptr)
  164339. {
  164340. #ifdef PNG_USER_MEM_SUPPORTED
  164341. png_destroy_struct_2(struct_ptr, png_free_ptr_NULL, png_voidp_NULL);
  164342. }
  164343. void /* PRIVATE */
  164344. png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn,
  164345. png_voidp mem_ptr)
  164346. {
  164347. #endif
  164348. if (struct_ptr != NULL)
  164349. {
  164350. #ifdef PNG_USER_MEM_SUPPORTED
  164351. if(free_fn != NULL)
  164352. {
  164353. png_struct dummy_struct;
  164354. png_structp png_ptr = &dummy_struct;
  164355. png_ptr->mem_ptr=mem_ptr;
  164356. (*(free_fn))(png_ptr, struct_ptr);
  164357. return;
  164358. }
  164359. #endif /* PNG_USER_MEM_SUPPORTED */
  164360. farfree (struct_ptr);
  164361. }
  164362. }
  164363. png_voidp PNGAPI
  164364. png_malloc(png_structp png_ptr, png_uint_32 size)
  164365. {
  164366. png_voidp ret;
  164367. if (png_ptr == NULL || size == 0)
  164368. return (NULL);
  164369. #ifdef PNG_USER_MEM_SUPPORTED
  164370. if(png_ptr->malloc_fn != NULL)
  164371. ret = ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, (png_size_t)size));
  164372. else
  164373. ret = (png_malloc_default(png_ptr, size));
  164374. if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164375. png_error(png_ptr, "Out of memory!");
  164376. return (ret);
  164377. }
  164378. png_voidp PNGAPI
  164379. png_malloc_default(png_structp png_ptr, png_uint_32 size)
  164380. {
  164381. png_voidp ret;
  164382. #endif /* PNG_USER_MEM_SUPPORTED */
  164383. if (png_ptr == NULL || size == 0)
  164384. return (NULL);
  164385. #ifdef PNG_MAX_MALLOC_64K
  164386. if (size > (png_uint_32)65536L)
  164387. {
  164388. png_warning(png_ptr, "Cannot Allocate > 64K");
  164389. ret = NULL;
  164390. }
  164391. else
  164392. #endif
  164393. if (size != (size_t)size)
  164394. ret = NULL;
  164395. else if (size == (png_uint_32)65536L)
  164396. {
  164397. if (png_ptr->offset_table == NULL)
  164398. {
  164399. ret = farmalloc(size);
  164400. if (ret == NULL || ((png_size_t)ret & 0xffff))
  164401. {
  164402. int num_blocks;
  164403. png_uint_32 total_size;
  164404. png_bytep table;
  164405. int i;
  164406. png_byte huge * hptr;
  164407. if (ret != NULL)
  164408. {
  164409. farfree(ret);
  164410. ret = NULL;
  164411. }
  164412. if(png_ptr->zlib_window_bits > 14)
  164413. num_blocks = (int)(1 << (png_ptr->zlib_window_bits - 14));
  164414. else
  164415. num_blocks = 1;
  164416. if (png_ptr->zlib_mem_level >= 7)
  164417. num_blocks += (int)(1 << (png_ptr->zlib_mem_level - 7));
  164418. else
  164419. num_blocks++;
  164420. total_size = ((png_uint_32)65536L) * (png_uint_32)num_blocks+16;
  164421. table = farmalloc(total_size);
  164422. if (table == NULL)
  164423. {
  164424. #ifndef PNG_USER_MEM_SUPPORTED
  164425. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164426. png_error(png_ptr, "Out Of Memory."); /* Note "O" and "M" */
  164427. else
  164428. png_warning(png_ptr, "Out Of Memory.");
  164429. #endif
  164430. return (NULL);
  164431. }
  164432. if ((png_size_t)table & 0xfff0)
  164433. {
  164434. #ifndef PNG_USER_MEM_SUPPORTED
  164435. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164436. png_error(png_ptr,
  164437. "Farmalloc didn't return normalized pointer");
  164438. else
  164439. png_warning(png_ptr,
  164440. "Farmalloc didn't return normalized pointer");
  164441. #endif
  164442. return (NULL);
  164443. }
  164444. png_ptr->offset_table = table;
  164445. png_ptr->offset_table_ptr = farmalloc(num_blocks *
  164446. png_sizeof (png_bytep));
  164447. if (png_ptr->offset_table_ptr == NULL)
  164448. {
  164449. #ifndef PNG_USER_MEM_SUPPORTED
  164450. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164451. png_error(png_ptr, "Out Of memory."); /* Note "O" and "M" */
  164452. else
  164453. png_warning(png_ptr, "Out Of memory.");
  164454. #endif
  164455. return (NULL);
  164456. }
  164457. hptr = (png_byte huge *)table;
  164458. if ((png_size_t)hptr & 0xf)
  164459. {
  164460. hptr = (png_byte huge *)((long)(hptr) & 0xfffffff0L);
  164461. hptr = hptr + 16L; /* "hptr += 16L" fails on Turbo C++ 3.0 */
  164462. }
  164463. for (i = 0; i < num_blocks; i++)
  164464. {
  164465. png_ptr->offset_table_ptr[i] = (png_bytep)hptr;
  164466. hptr = hptr + (png_uint_32)65536L; /* "+=" fails on TC++3.0 */
  164467. }
  164468. png_ptr->offset_table_number = num_blocks;
  164469. png_ptr->offset_table_count = 0;
  164470. png_ptr->offset_table_count_free = 0;
  164471. }
  164472. }
  164473. if (png_ptr->offset_table_count >= png_ptr->offset_table_number)
  164474. {
  164475. #ifndef PNG_USER_MEM_SUPPORTED
  164476. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164477. png_error(png_ptr, "Out of Memory."); /* Note "o" and "M" */
  164478. else
  164479. png_warning(png_ptr, "Out of Memory.");
  164480. #endif
  164481. return (NULL);
  164482. }
  164483. ret = png_ptr->offset_table_ptr[png_ptr->offset_table_count++];
  164484. }
  164485. else
  164486. ret = farmalloc(size);
  164487. #ifndef PNG_USER_MEM_SUPPORTED
  164488. if (ret == NULL)
  164489. {
  164490. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164491. png_error(png_ptr, "Out of memory."); /* Note "o" and "m" */
  164492. else
  164493. png_warning(png_ptr, "Out of memory."); /* Note "o" and "m" */
  164494. }
  164495. #endif
  164496. return (ret);
  164497. }
  164498. void PNGAPI
  164499. png_free(png_structp png_ptr, png_voidp ptr)
  164500. {
  164501. if (png_ptr == NULL || ptr == NULL)
  164502. return;
  164503. #ifdef PNG_USER_MEM_SUPPORTED
  164504. if (png_ptr->free_fn != NULL)
  164505. {
  164506. (*(png_ptr->free_fn))(png_ptr, ptr);
  164507. return;
  164508. }
  164509. else png_free_default(png_ptr, ptr);
  164510. }
  164511. void PNGAPI
  164512. png_free_default(png_structp png_ptr, png_voidp ptr)
  164513. {
  164514. #endif /* PNG_USER_MEM_SUPPORTED */
  164515. if(png_ptr == NULL) return;
  164516. if (png_ptr->offset_table != NULL)
  164517. {
  164518. int i;
  164519. for (i = 0; i < png_ptr->offset_table_count; i++)
  164520. {
  164521. if (ptr == png_ptr->offset_table_ptr[i])
  164522. {
  164523. ptr = NULL;
  164524. png_ptr->offset_table_count_free++;
  164525. break;
  164526. }
  164527. }
  164528. if (png_ptr->offset_table_count_free == png_ptr->offset_table_count)
  164529. {
  164530. farfree(png_ptr->offset_table);
  164531. farfree(png_ptr->offset_table_ptr);
  164532. png_ptr->offset_table = NULL;
  164533. png_ptr->offset_table_ptr = NULL;
  164534. }
  164535. }
  164536. if (ptr != NULL)
  164537. {
  164538. farfree(ptr);
  164539. }
  164540. }
  164541. #else /* Not the Borland DOS special memory handler */
  164542. png_voidp /* PRIVATE */
  164543. png_create_struct(int type)
  164544. {
  164545. #ifdef PNG_USER_MEM_SUPPORTED
  164546. return (png_create_struct_2(type, png_malloc_ptr_NULL, png_voidp_NULL));
  164547. }
  164548. png_voidp /* PRIVATE */
  164549. png_create_struct_2(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr)
  164550. {
  164551. #endif /* PNG_USER_MEM_SUPPORTED */
  164552. png_size_t size;
  164553. png_voidp struct_ptr;
  164554. if (type == PNG_STRUCT_INFO)
  164555. size = png_sizeof(png_info);
  164556. else if (type == PNG_STRUCT_PNG)
  164557. size = png_sizeof(png_struct);
  164558. else
  164559. return (NULL);
  164560. #ifdef PNG_USER_MEM_SUPPORTED
  164561. if(malloc_fn != NULL)
  164562. {
  164563. png_struct dummy_struct;
  164564. png_structp png_ptr = &dummy_struct;
  164565. png_ptr->mem_ptr=mem_ptr;
  164566. struct_ptr = (*(malloc_fn))(png_ptr, size);
  164567. if (struct_ptr != NULL)
  164568. png_memset(struct_ptr, 0, size);
  164569. return (struct_ptr);
  164570. }
  164571. #endif /* PNG_USER_MEM_SUPPORTED */
  164572. #if defined(__TURBOC__) && !defined(__FLAT__)
  164573. struct_ptr = (png_voidp)farmalloc(size);
  164574. #else
  164575. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  164576. struct_ptr = (png_voidp)halloc(size,1);
  164577. # else
  164578. struct_ptr = (png_voidp)malloc(size);
  164579. # endif
  164580. #endif
  164581. if (struct_ptr != NULL)
  164582. png_memset(struct_ptr, 0, size);
  164583. return (struct_ptr);
  164584. }
  164585. void /* PRIVATE */
  164586. png_destroy_struct(png_voidp struct_ptr)
  164587. {
  164588. #ifdef PNG_USER_MEM_SUPPORTED
  164589. png_destroy_struct_2(struct_ptr, png_free_ptr_NULL, png_voidp_NULL);
  164590. }
  164591. void /* PRIVATE */
  164592. png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn,
  164593. png_voidp mem_ptr)
  164594. {
  164595. #endif /* PNG_USER_MEM_SUPPORTED */
  164596. if (struct_ptr != NULL)
  164597. {
  164598. #ifdef PNG_USER_MEM_SUPPORTED
  164599. if(free_fn != NULL)
  164600. {
  164601. png_struct dummy_struct;
  164602. png_structp png_ptr = &dummy_struct;
  164603. png_ptr->mem_ptr=mem_ptr;
  164604. (*(free_fn))(png_ptr, struct_ptr);
  164605. return;
  164606. }
  164607. #endif /* PNG_USER_MEM_SUPPORTED */
  164608. #if defined(__TURBOC__) && !defined(__FLAT__)
  164609. farfree(struct_ptr);
  164610. #else
  164611. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  164612. hfree(struct_ptr);
  164613. # else
  164614. free(struct_ptr);
  164615. # endif
  164616. #endif
  164617. }
  164618. }
  164619. png_voidp PNGAPI
  164620. png_malloc(png_structp png_ptr, png_uint_32 size)
  164621. {
  164622. png_voidp ret;
  164623. #ifdef PNG_USER_MEM_SUPPORTED
  164624. if (png_ptr == NULL || size == 0)
  164625. return (NULL);
  164626. if(png_ptr->malloc_fn != NULL)
  164627. ret = ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, (png_size_t)size));
  164628. else
  164629. ret = (png_malloc_default(png_ptr, size));
  164630. if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164631. png_error(png_ptr, "Out of Memory!");
  164632. return (ret);
  164633. }
  164634. png_voidp PNGAPI
  164635. png_malloc_default(png_structp png_ptr, png_uint_32 size)
  164636. {
  164637. png_voidp ret;
  164638. #endif /* PNG_USER_MEM_SUPPORTED */
  164639. if (png_ptr == NULL || size == 0)
  164640. return (NULL);
  164641. #ifdef PNG_MAX_MALLOC_64K
  164642. if (size > (png_uint_32)65536L)
  164643. {
  164644. #ifndef PNG_USER_MEM_SUPPORTED
  164645. if(png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164646. png_error(png_ptr, "Cannot Allocate > 64K");
  164647. else
  164648. #endif
  164649. return NULL;
  164650. }
  164651. #endif
  164652. #if defined(__TURBOC__) && !defined(__FLAT__)
  164653. if (size != (unsigned long)size)
  164654. ret = NULL;
  164655. else
  164656. ret = farmalloc(size);
  164657. #else
  164658. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  164659. if (size != (unsigned long)size)
  164660. ret = NULL;
  164661. else
  164662. ret = halloc(size, 1);
  164663. # else
  164664. if (size != (size_t)size)
  164665. ret = NULL;
  164666. else
  164667. ret = malloc((size_t)size);
  164668. # endif
  164669. #endif
  164670. #ifndef PNG_USER_MEM_SUPPORTED
  164671. if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164672. png_error(png_ptr, "Out of Memory");
  164673. #endif
  164674. return (ret);
  164675. }
  164676. void PNGAPI
  164677. png_free(png_structp png_ptr, png_voidp ptr)
  164678. {
  164679. if (png_ptr == NULL || ptr == NULL)
  164680. return;
  164681. #ifdef PNG_USER_MEM_SUPPORTED
  164682. if (png_ptr->free_fn != NULL)
  164683. {
  164684. (*(png_ptr->free_fn))(png_ptr, ptr);
  164685. return;
  164686. }
  164687. else png_free_default(png_ptr, ptr);
  164688. }
  164689. void PNGAPI
  164690. png_free_default(png_structp png_ptr, png_voidp ptr)
  164691. {
  164692. if (png_ptr == NULL || ptr == NULL)
  164693. return;
  164694. #endif /* PNG_USER_MEM_SUPPORTED */
  164695. #if defined(__TURBOC__) && !defined(__FLAT__)
  164696. farfree(ptr);
  164697. #else
  164698. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  164699. hfree(ptr);
  164700. # else
  164701. free(ptr);
  164702. # endif
  164703. #endif
  164704. }
  164705. #endif /* Not Borland DOS special memory handler */
  164706. #if defined(PNG_1_0_X)
  164707. # define png_malloc_warn png_malloc
  164708. #else
  164709. png_voidp PNGAPI
  164710. png_malloc_warn(png_structp png_ptr, png_uint_32 size)
  164711. {
  164712. png_voidp ptr;
  164713. png_uint_32 save_flags;
  164714. if(png_ptr == NULL) return (NULL);
  164715. save_flags=png_ptr->flags;
  164716. png_ptr->flags|=PNG_FLAG_MALLOC_NULL_MEM_OK;
  164717. ptr = (png_voidp)png_malloc((png_structp)png_ptr, size);
  164718. png_ptr->flags=save_flags;
  164719. return(ptr);
  164720. }
  164721. #endif
  164722. png_voidp PNGAPI
  164723. png_memcpy_check (png_structp png_ptr, png_voidp s1, png_voidp s2,
  164724. png_uint_32 length)
  164725. {
  164726. png_size_t size;
  164727. size = (png_size_t)length;
  164728. if ((png_uint_32)size != length)
  164729. png_error(png_ptr,"Overflow in png_memcpy_check.");
  164730. return(png_memcpy (s1, s2, size));
  164731. }
  164732. png_voidp PNGAPI
  164733. png_memset_check (png_structp png_ptr, png_voidp s1, int value,
  164734. png_uint_32 length)
  164735. {
  164736. png_size_t size;
  164737. size = (png_size_t)length;
  164738. if ((png_uint_32)size != length)
  164739. png_error(png_ptr,"Overflow in png_memset_check.");
  164740. return (png_memset (s1, value, size));
  164741. }
  164742. #ifdef PNG_USER_MEM_SUPPORTED
  164743. void PNGAPI
  164744. png_set_mem_fn(png_structp png_ptr, png_voidp mem_ptr, png_malloc_ptr
  164745. malloc_fn, png_free_ptr free_fn)
  164746. {
  164747. if(png_ptr != NULL) {
  164748. png_ptr->mem_ptr = mem_ptr;
  164749. png_ptr->malloc_fn = malloc_fn;
  164750. png_ptr->free_fn = free_fn;
  164751. }
  164752. }
  164753. png_voidp PNGAPI
  164754. png_get_mem_ptr(png_structp png_ptr)
  164755. {
  164756. if(png_ptr == NULL) return (NULL);
  164757. return ((png_voidp)png_ptr->mem_ptr);
  164758. }
  164759. #endif /* PNG_USER_MEM_SUPPORTED */
  164760. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  164761. /*** End of inlined file: pngmem.c ***/
  164762. /*** Start of inlined file: pngread.c ***/
  164763. #define PNG_INTERNAL
  164764. #if defined(PNG_READ_SUPPORTED)
  164765. png_structp PNGAPI
  164766. png_create_read_struct(png_const_charp user_png_ver, png_voidp error_ptr,
  164767. png_error_ptr error_fn, png_error_ptr warn_fn)
  164768. {
  164769. #ifdef PNG_USER_MEM_SUPPORTED
  164770. return (png_create_read_struct_2(user_png_ver, error_ptr, error_fn,
  164771. warn_fn, png_voidp_NULL, png_malloc_ptr_NULL, png_free_ptr_NULL));
  164772. }
  164773. png_structp PNGAPI
  164774. png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
  164775. png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  164776. png_malloc_ptr malloc_fn, png_free_ptr free_fn)
  164777. {
  164778. #endif /* PNG_USER_MEM_SUPPORTED */
  164779. png_structp png_ptr;
  164780. #ifdef PNG_SETJMP_SUPPORTED
  164781. #ifdef USE_FAR_KEYWORD
  164782. jmp_buf jmpbuf;
  164783. #endif
  164784. #endif
  164785. int i;
  164786. png_debug(1, "in png_create_read_struct\n");
  164787. #ifdef PNG_USER_MEM_SUPPORTED
  164788. png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG,
  164789. (png_malloc_ptr)malloc_fn, (png_voidp)mem_ptr);
  164790. #else
  164791. png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
  164792. #endif
  164793. if (png_ptr == NULL)
  164794. return (NULL);
  164795. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  164796. png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
  164797. png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
  164798. #endif
  164799. #ifdef PNG_SETJMP_SUPPORTED
  164800. #ifdef USE_FAR_KEYWORD
  164801. if (setjmp(jmpbuf))
  164802. #else
  164803. if (setjmp(png_ptr->jmpbuf))
  164804. #endif
  164805. {
  164806. png_free(png_ptr, png_ptr->zbuf);
  164807. png_ptr->zbuf=NULL;
  164808. #ifdef PNG_USER_MEM_SUPPORTED
  164809. png_destroy_struct_2((png_voidp)png_ptr,
  164810. (png_free_ptr)free_fn, (png_voidp)mem_ptr);
  164811. #else
  164812. png_destroy_struct((png_voidp)png_ptr);
  164813. #endif
  164814. return (NULL);
  164815. }
  164816. #ifdef USE_FAR_KEYWORD
  164817. png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
  164818. #endif
  164819. #endif
  164820. #ifdef PNG_USER_MEM_SUPPORTED
  164821. png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn);
  164822. #endif
  164823. png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn);
  164824. i=0;
  164825. do
  164826. {
  164827. if(user_png_ver[i] != png_libpng_ver[i])
  164828. png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
  164829. } while (png_libpng_ver[i++]);
  164830. if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH)
  164831. {
  164832. if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] ||
  164833. (user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) ||
  164834. (user_png_ver[0] == '0' && user_png_ver[2] < '9'))
  164835. {
  164836. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  164837. char msg[80];
  164838. if (user_png_ver)
  164839. {
  164840. png_snprintf(msg, 80,
  164841. "Application was compiled with png.h from libpng-%.20s",
  164842. user_png_ver);
  164843. png_warning(png_ptr, msg);
  164844. }
  164845. png_snprintf(msg, 80,
  164846. "Application is running with png.c from libpng-%.20s",
  164847. png_libpng_ver);
  164848. png_warning(png_ptr, msg);
  164849. #endif
  164850. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  164851. png_ptr->flags=0;
  164852. #endif
  164853. png_error(png_ptr,
  164854. "Incompatible libpng version in application and library");
  164855. }
  164856. }
  164857. png_ptr->zbuf_size = PNG_ZBUF_SIZE;
  164858. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
  164859. (png_uint_32)png_ptr->zbuf_size);
  164860. png_ptr->zstream.zalloc = png_zalloc;
  164861. png_ptr->zstream.zfree = png_zfree;
  164862. png_ptr->zstream.opaque = (voidpf)png_ptr;
  164863. switch (inflateInit(&png_ptr->zstream))
  164864. {
  164865. case Z_OK: /* Do nothing */ break;
  164866. case Z_MEM_ERROR:
  164867. case Z_STREAM_ERROR: png_error(png_ptr, "zlib memory error"); break;
  164868. case Z_VERSION_ERROR: png_error(png_ptr, "zlib version error"); break;
  164869. default: png_error(png_ptr, "Unknown zlib error");
  164870. }
  164871. png_ptr->zstream.next_out = png_ptr->zbuf;
  164872. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  164873. png_set_read_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL);
  164874. #ifdef PNG_SETJMP_SUPPORTED
  164875. #ifdef USE_FAR_KEYWORD
  164876. if (setjmp(jmpbuf))
  164877. PNG_ABORT();
  164878. png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
  164879. #else
  164880. if (setjmp(png_ptr->jmpbuf))
  164881. PNG_ABORT();
  164882. #endif
  164883. #endif
  164884. return (png_ptr);
  164885. }
  164886. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  164887. #undef png_read_init
  164888. void PNGAPI
  164889. png_read_init(png_structp png_ptr)
  164890. {
  164891. png_read_init_2(png_ptr, "1.0.6 or earlier", 0, 0);
  164892. }
  164893. void PNGAPI
  164894. png_read_init_2(png_structp png_ptr, png_const_charp user_png_ver,
  164895. png_size_t png_struct_size, png_size_t png_info_size)
  164896. {
  164897. if(png_ptr == NULL) return;
  164898. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  164899. if(png_sizeof(png_struct) > png_struct_size ||
  164900. png_sizeof(png_info) > png_info_size)
  164901. {
  164902. char msg[80];
  164903. png_ptr->warning_fn=NULL;
  164904. if (user_png_ver)
  164905. {
  164906. png_snprintf(msg, 80,
  164907. "Application was compiled with png.h from libpng-%.20s",
  164908. user_png_ver);
  164909. png_warning(png_ptr, msg);
  164910. }
  164911. png_snprintf(msg, 80,
  164912. "Application is running with png.c from libpng-%.20s",
  164913. png_libpng_ver);
  164914. png_warning(png_ptr, msg);
  164915. }
  164916. #endif
  164917. if(png_sizeof(png_struct) > png_struct_size)
  164918. {
  164919. png_ptr->error_fn=NULL;
  164920. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  164921. png_ptr->flags=0;
  164922. #endif
  164923. png_error(png_ptr,
  164924. "The png struct allocated by the application for reading is too small.");
  164925. }
  164926. if(png_sizeof(png_info) > png_info_size)
  164927. {
  164928. png_ptr->error_fn=NULL;
  164929. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  164930. png_ptr->flags=0;
  164931. #endif
  164932. png_error(png_ptr,
  164933. "The info struct allocated by application for reading is too small.");
  164934. }
  164935. png_read_init_3(&png_ptr, user_png_ver, png_struct_size);
  164936. }
  164937. #endif /* PNG_1_0_X || PNG_1_2_X */
  164938. void PNGAPI
  164939. png_read_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver,
  164940. png_size_t png_struct_size)
  164941. {
  164942. #ifdef PNG_SETJMP_SUPPORTED
  164943. jmp_buf tmp_jmp; /* to save current jump buffer */
  164944. #endif
  164945. int i=0;
  164946. png_structp png_ptr=*ptr_ptr;
  164947. if(png_ptr == NULL) return;
  164948. do
  164949. {
  164950. if(user_png_ver[i] != png_libpng_ver[i])
  164951. {
  164952. #ifdef PNG_LEGACY_SUPPORTED
  164953. png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
  164954. #else
  164955. png_ptr->warning_fn=NULL;
  164956. png_warning(png_ptr,
  164957. "Application uses deprecated png_read_init() and should be recompiled.");
  164958. break;
  164959. #endif
  164960. }
  164961. } while (png_libpng_ver[i++]);
  164962. png_debug(1, "in png_read_init_3\n");
  164963. #ifdef PNG_SETJMP_SUPPORTED
  164964. png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
  164965. #endif
  164966. if(png_sizeof(png_struct) > png_struct_size)
  164967. {
  164968. png_destroy_struct(png_ptr);
  164969. *ptr_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
  164970. png_ptr = *ptr_ptr;
  164971. }
  164972. png_memset(png_ptr, 0, png_sizeof (png_struct));
  164973. #ifdef PNG_SETJMP_SUPPORTED
  164974. png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
  164975. #endif
  164976. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  164977. png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
  164978. png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
  164979. #endif
  164980. png_ptr->zbuf_size = PNG_ZBUF_SIZE;
  164981. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
  164982. (png_uint_32)png_ptr->zbuf_size);
  164983. png_ptr->zstream.zalloc = png_zalloc;
  164984. png_ptr->zstream.zfree = png_zfree;
  164985. png_ptr->zstream.opaque = (voidpf)png_ptr;
  164986. switch (inflateInit(&png_ptr->zstream))
  164987. {
  164988. case Z_OK: /* Do nothing */ break;
  164989. case Z_MEM_ERROR:
  164990. case Z_STREAM_ERROR: png_error(png_ptr, "zlib memory"); break;
  164991. case Z_VERSION_ERROR: png_error(png_ptr, "zlib version"); break;
  164992. default: png_error(png_ptr, "Unknown zlib error");
  164993. }
  164994. png_ptr->zstream.next_out = png_ptr->zbuf;
  164995. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  164996. png_set_read_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL);
  164997. }
  164998. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  164999. void PNGAPI
  165000. png_read_info(png_structp png_ptr, png_infop info_ptr)
  165001. {
  165002. if(png_ptr == NULL) return;
  165003. png_debug(1, "in png_read_info\n");
  165004. if (png_ptr->sig_bytes < 8)
  165005. {
  165006. png_size_t num_checked = png_ptr->sig_bytes,
  165007. num_to_check = 8 - num_checked;
  165008. png_read_data(png_ptr, &(info_ptr->signature[num_checked]), num_to_check);
  165009. png_ptr->sig_bytes = 8;
  165010. if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check))
  165011. {
  165012. if (num_checked < 4 &&
  165013. png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4))
  165014. png_error(png_ptr, "Not a PNG file");
  165015. else
  165016. png_error(png_ptr, "PNG file corrupted by ASCII conversion");
  165017. }
  165018. if (num_checked < 3)
  165019. png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE;
  165020. }
  165021. for(;;)
  165022. {
  165023. #ifdef PNG_USE_LOCAL_ARRAYS
  165024. PNG_CONST PNG_IHDR;
  165025. PNG_CONST PNG_IDAT;
  165026. PNG_CONST PNG_IEND;
  165027. PNG_CONST PNG_PLTE;
  165028. #if defined(PNG_READ_bKGD_SUPPORTED)
  165029. PNG_CONST PNG_bKGD;
  165030. #endif
  165031. #if defined(PNG_READ_cHRM_SUPPORTED)
  165032. PNG_CONST PNG_cHRM;
  165033. #endif
  165034. #if defined(PNG_READ_gAMA_SUPPORTED)
  165035. PNG_CONST PNG_gAMA;
  165036. #endif
  165037. #if defined(PNG_READ_hIST_SUPPORTED)
  165038. PNG_CONST PNG_hIST;
  165039. #endif
  165040. #if defined(PNG_READ_iCCP_SUPPORTED)
  165041. PNG_CONST PNG_iCCP;
  165042. #endif
  165043. #if defined(PNG_READ_iTXt_SUPPORTED)
  165044. PNG_CONST PNG_iTXt;
  165045. #endif
  165046. #if defined(PNG_READ_oFFs_SUPPORTED)
  165047. PNG_CONST PNG_oFFs;
  165048. #endif
  165049. #if defined(PNG_READ_pCAL_SUPPORTED)
  165050. PNG_CONST PNG_pCAL;
  165051. #endif
  165052. #if defined(PNG_READ_pHYs_SUPPORTED)
  165053. PNG_CONST PNG_pHYs;
  165054. #endif
  165055. #if defined(PNG_READ_sBIT_SUPPORTED)
  165056. PNG_CONST PNG_sBIT;
  165057. #endif
  165058. #if defined(PNG_READ_sCAL_SUPPORTED)
  165059. PNG_CONST PNG_sCAL;
  165060. #endif
  165061. #if defined(PNG_READ_sPLT_SUPPORTED)
  165062. PNG_CONST PNG_sPLT;
  165063. #endif
  165064. #if defined(PNG_READ_sRGB_SUPPORTED)
  165065. PNG_CONST PNG_sRGB;
  165066. #endif
  165067. #if defined(PNG_READ_tEXt_SUPPORTED)
  165068. PNG_CONST PNG_tEXt;
  165069. #endif
  165070. #if defined(PNG_READ_tIME_SUPPORTED)
  165071. PNG_CONST PNG_tIME;
  165072. #endif
  165073. #if defined(PNG_READ_tRNS_SUPPORTED)
  165074. PNG_CONST PNG_tRNS;
  165075. #endif
  165076. #if defined(PNG_READ_zTXt_SUPPORTED)
  165077. PNG_CONST PNG_zTXt;
  165078. #endif
  165079. #endif /* PNG_USE_LOCAL_ARRAYS */
  165080. png_byte chunk_length[4];
  165081. png_uint_32 length;
  165082. png_read_data(png_ptr, chunk_length, 4);
  165083. length = png_get_uint_31(png_ptr,chunk_length);
  165084. png_reset_crc(png_ptr);
  165085. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  165086. png_debug2(0, "Reading %s chunk, length=%lu.\n", png_ptr->chunk_name,
  165087. length);
  165088. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165089. if(png_ptr->mode & PNG_AFTER_IDAT)
  165090. png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT;
  165091. if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4))
  165092. png_handle_IHDR(png_ptr, info_ptr, length);
  165093. else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
  165094. png_handle_IEND(png_ptr, info_ptr, length);
  165095. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  165096. else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name))
  165097. {
  165098. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165099. png_ptr->mode |= PNG_HAVE_IDAT;
  165100. png_handle_unknown(png_ptr, info_ptr, length);
  165101. if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  165102. png_ptr->mode |= PNG_HAVE_PLTE;
  165103. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165104. {
  165105. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  165106. png_error(png_ptr, "Missing IHDR before IDAT");
  165107. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  165108. !(png_ptr->mode & PNG_HAVE_PLTE))
  165109. png_error(png_ptr, "Missing PLTE before IDAT");
  165110. break;
  165111. }
  165112. }
  165113. #endif
  165114. else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  165115. png_handle_PLTE(png_ptr, info_ptr, length);
  165116. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165117. {
  165118. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  165119. png_error(png_ptr, "Missing IHDR before IDAT");
  165120. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  165121. !(png_ptr->mode & PNG_HAVE_PLTE))
  165122. png_error(png_ptr, "Missing PLTE before IDAT");
  165123. png_ptr->idat_size = length;
  165124. png_ptr->mode |= PNG_HAVE_IDAT;
  165125. break;
  165126. }
  165127. #if defined(PNG_READ_bKGD_SUPPORTED)
  165128. else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4))
  165129. png_handle_bKGD(png_ptr, info_ptr, length);
  165130. #endif
  165131. #if defined(PNG_READ_cHRM_SUPPORTED)
  165132. else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4))
  165133. png_handle_cHRM(png_ptr, info_ptr, length);
  165134. #endif
  165135. #if defined(PNG_READ_gAMA_SUPPORTED)
  165136. else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4))
  165137. png_handle_gAMA(png_ptr, info_ptr, length);
  165138. #endif
  165139. #if defined(PNG_READ_hIST_SUPPORTED)
  165140. else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4))
  165141. png_handle_hIST(png_ptr, info_ptr, length);
  165142. #endif
  165143. #if defined(PNG_READ_oFFs_SUPPORTED)
  165144. else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4))
  165145. png_handle_oFFs(png_ptr, info_ptr, length);
  165146. #endif
  165147. #if defined(PNG_READ_pCAL_SUPPORTED)
  165148. else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4))
  165149. png_handle_pCAL(png_ptr, info_ptr, length);
  165150. #endif
  165151. #if defined(PNG_READ_sCAL_SUPPORTED)
  165152. else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4))
  165153. png_handle_sCAL(png_ptr, info_ptr, length);
  165154. #endif
  165155. #if defined(PNG_READ_pHYs_SUPPORTED)
  165156. else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4))
  165157. png_handle_pHYs(png_ptr, info_ptr, length);
  165158. #endif
  165159. #if defined(PNG_READ_sBIT_SUPPORTED)
  165160. else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4))
  165161. png_handle_sBIT(png_ptr, info_ptr, length);
  165162. #endif
  165163. #if defined(PNG_READ_sRGB_SUPPORTED)
  165164. else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4))
  165165. png_handle_sRGB(png_ptr, info_ptr, length);
  165166. #endif
  165167. #if defined(PNG_READ_iCCP_SUPPORTED)
  165168. else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4))
  165169. png_handle_iCCP(png_ptr, info_ptr, length);
  165170. #endif
  165171. #if defined(PNG_READ_sPLT_SUPPORTED)
  165172. else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4))
  165173. png_handle_sPLT(png_ptr, info_ptr, length);
  165174. #endif
  165175. #if defined(PNG_READ_tEXt_SUPPORTED)
  165176. else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4))
  165177. png_handle_tEXt(png_ptr, info_ptr, length);
  165178. #endif
  165179. #if defined(PNG_READ_tIME_SUPPORTED)
  165180. else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4))
  165181. png_handle_tIME(png_ptr, info_ptr, length);
  165182. #endif
  165183. #if defined(PNG_READ_tRNS_SUPPORTED)
  165184. else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4))
  165185. png_handle_tRNS(png_ptr, info_ptr, length);
  165186. #endif
  165187. #if defined(PNG_READ_zTXt_SUPPORTED)
  165188. else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4))
  165189. png_handle_zTXt(png_ptr, info_ptr, length);
  165190. #endif
  165191. #if defined(PNG_READ_iTXt_SUPPORTED)
  165192. else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4))
  165193. png_handle_iTXt(png_ptr, info_ptr, length);
  165194. #endif
  165195. else
  165196. png_handle_unknown(png_ptr, info_ptr, length);
  165197. }
  165198. }
  165199. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165200. void PNGAPI
  165201. png_read_update_info(png_structp png_ptr, png_infop info_ptr)
  165202. {
  165203. png_debug(1, "in png_read_update_info\n");
  165204. if(png_ptr == NULL) return;
  165205. if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
  165206. png_read_start_row(png_ptr);
  165207. else
  165208. png_warning(png_ptr,
  165209. "Ignoring extra png_read_update_info() call; row buffer not reallocated");
  165210. png_read_transform_info(png_ptr, info_ptr);
  165211. }
  165212. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  165213. void PNGAPI
  165214. png_start_read_image(png_structp png_ptr)
  165215. {
  165216. png_debug(1, "in png_start_read_image\n");
  165217. if(png_ptr == NULL) return;
  165218. if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
  165219. png_read_start_row(png_ptr);
  165220. }
  165221. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165222. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  165223. void PNGAPI
  165224. png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
  165225. {
  165226. #ifdef PNG_USE_LOCAL_ARRAYS
  165227. PNG_CONST PNG_IDAT;
  165228. PNG_CONST int png_pass_dsp_mask[7] = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55,
  165229. 0xff};
  165230. PNG_CONST int png_pass_mask[7] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
  165231. #endif
  165232. int ret;
  165233. if(png_ptr == NULL) return;
  165234. png_debug2(1, "in png_read_row (row %lu, pass %d)\n",
  165235. png_ptr->row_number, png_ptr->pass);
  165236. if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
  165237. png_read_start_row(png_ptr);
  165238. if (png_ptr->row_number == 0 && png_ptr->pass == 0)
  165239. {
  165240. #if defined(PNG_WRITE_INVERT_SUPPORTED) && !defined(PNG_READ_INVERT_SUPPORTED)
  165241. if (png_ptr->transformations & PNG_INVERT_MONO)
  165242. png_warning(png_ptr, "PNG_READ_INVERT_SUPPORTED is not defined.");
  165243. #endif
  165244. #if defined(PNG_WRITE_FILLER_SUPPORTED) && !defined(PNG_READ_FILLER_SUPPORTED)
  165245. if (png_ptr->transformations & PNG_FILLER)
  165246. png_warning(png_ptr, "PNG_READ_FILLER_SUPPORTED is not defined.");
  165247. #endif
  165248. #if defined(PNG_WRITE_PACKSWAP_SUPPORTED) && !defined(PNG_READ_PACKSWAP_SUPPORTED)
  165249. if (png_ptr->transformations & PNG_PACKSWAP)
  165250. png_warning(png_ptr, "PNG_READ_PACKSWAP_SUPPORTED is not defined.");
  165251. #endif
  165252. #if defined(PNG_WRITE_PACK_SUPPORTED) && !defined(PNG_READ_PACK_SUPPORTED)
  165253. if (png_ptr->transformations & PNG_PACK)
  165254. png_warning(png_ptr, "PNG_READ_PACK_SUPPORTED is not defined.");
  165255. #endif
  165256. #if defined(PNG_WRITE_SHIFT_SUPPORTED) && !defined(PNG_READ_SHIFT_SUPPORTED)
  165257. if (png_ptr->transformations & PNG_SHIFT)
  165258. png_warning(png_ptr, "PNG_READ_SHIFT_SUPPORTED is not defined.");
  165259. #endif
  165260. #if defined(PNG_WRITE_BGR_SUPPORTED) && !defined(PNG_READ_BGR_SUPPORTED)
  165261. if (png_ptr->transformations & PNG_BGR)
  165262. png_warning(png_ptr, "PNG_READ_BGR_SUPPORTED is not defined.");
  165263. #endif
  165264. #if defined(PNG_WRITE_SWAP_SUPPORTED) && !defined(PNG_READ_SWAP_SUPPORTED)
  165265. if (png_ptr->transformations & PNG_SWAP_BYTES)
  165266. png_warning(png_ptr, "PNG_READ_SWAP_SUPPORTED is not defined.");
  165267. #endif
  165268. }
  165269. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  165270. if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
  165271. {
  165272. switch (png_ptr->pass)
  165273. {
  165274. case 0:
  165275. if (png_ptr->row_number & 0x07)
  165276. {
  165277. if (dsp_row != NULL)
  165278. png_combine_row(png_ptr, dsp_row,
  165279. png_pass_dsp_mask[png_ptr->pass]);
  165280. png_read_finish_row(png_ptr);
  165281. return;
  165282. }
  165283. break;
  165284. case 1:
  165285. if ((png_ptr->row_number & 0x07) || png_ptr->width < 5)
  165286. {
  165287. if (dsp_row != NULL)
  165288. png_combine_row(png_ptr, dsp_row,
  165289. png_pass_dsp_mask[png_ptr->pass]);
  165290. png_read_finish_row(png_ptr);
  165291. return;
  165292. }
  165293. break;
  165294. case 2:
  165295. if ((png_ptr->row_number & 0x07) != 4)
  165296. {
  165297. if (dsp_row != NULL && (png_ptr->row_number & 4))
  165298. png_combine_row(png_ptr, dsp_row,
  165299. png_pass_dsp_mask[png_ptr->pass]);
  165300. png_read_finish_row(png_ptr);
  165301. return;
  165302. }
  165303. break;
  165304. case 3:
  165305. if ((png_ptr->row_number & 3) || png_ptr->width < 3)
  165306. {
  165307. if (dsp_row != NULL)
  165308. png_combine_row(png_ptr, dsp_row,
  165309. png_pass_dsp_mask[png_ptr->pass]);
  165310. png_read_finish_row(png_ptr);
  165311. return;
  165312. }
  165313. break;
  165314. case 4:
  165315. if ((png_ptr->row_number & 3) != 2)
  165316. {
  165317. if (dsp_row != NULL && (png_ptr->row_number & 2))
  165318. png_combine_row(png_ptr, dsp_row,
  165319. png_pass_dsp_mask[png_ptr->pass]);
  165320. png_read_finish_row(png_ptr);
  165321. return;
  165322. }
  165323. break;
  165324. case 5:
  165325. if ((png_ptr->row_number & 1) || png_ptr->width < 2)
  165326. {
  165327. if (dsp_row != NULL)
  165328. png_combine_row(png_ptr, dsp_row,
  165329. png_pass_dsp_mask[png_ptr->pass]);
  165330. png_read_finish_row(png_ptr);
  165331. return;
  165332. }
  165333. break;
  165334. case 6:
  165335. if (!(png_ptr->row_number & 1))
  165336. {
  165337. png_read_finish_row(png_ptr);
  165338. return;
  165339. }
  165340. break;
  165341. }
  165342. }
  165343. #endif
  165344. if (!(png_ptr->mode & PNG_HAVE_IDAT))
  165345. png_error(png_ptr, "Invalid attempt to read row data");
  165346. png_ptr->zstream.next_out = png_ptr->row_buf;
  165347. png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
  165348. do
  165349. {
  165350. if (!(png_ptr->zstream.avail_in))
  165351. {
  165352. while (!png_ptr->idat_size)
  165353. {
  165354. png_byte chunk_length[4];
  165355. png_crc_finish(png_ptr, 0);
  165356. png_read_data(png_ptr, chunk_length, 4);
  165357. png_ptr->idat_size = png_get_uint_31(png_ptr,chunk_length);
  165358. png_reset_crc(png_ptr);
  165359. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  165360. if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165361. png_error(png_ptr, "Not enough image data");
  165362. }
  165363. png_ptr->zstream.avail_in = (uInt)png_ptr->zbuf_size;
  165364. png_ptr->zstream.next_in = png_ptr->zbuf;
  165365. if (png_ptr->zbuf_size > png_ptr->idat_size)
  165366. png_ptr->zstream.avail_in = (uInt)png_ptr->idat_size;
  165367. png_crc_read(png_ptr, png_ptr->zbuf,
  165368. (png_size_t)png_ptr->zstream.avail_in);
  165369. png_ptr->idat_size -= png_ptr->zstream.avail_in;
  165370. }
  165371. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  165372. if (ret == Z_STREAM_END)
  165373. {
  165374. if (png_ptr->zstream.avail_out || png_ptr->zstream.avail_in ||
  165375. png_ptr->idat_size)
  165376. png_error(png_ptr, "Extra compressed data");
  165377. png_ptr->mode |= PNG_AFTER_IDAT;
  165378. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  165379. break;
  165380. }
  165381. if (ret != Z_OK)
  165382. png_error(png_ptr, png_ptr->zstream.msg ? png_ptr->zstream.msg :
  165383. "Decompression error");
  165384. } while (png_ptr->zstream.avail_out);
  165385. png_ptr->row_info.color_type = png_ptr->color_type;
  165386. png_ptr->row_info.width = png_ptr->iwidth;
  165387. png_ptr->row_info.channels = png_ptr->channels;
  165388. png_ptr->row_info.bit_depth = png_ptr->bit_depth;
  165389. png_ptr->row_info.pixel_depth = png_ptr->pixel_depth;
  165390. png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
  165391. png_ptr->row_info.width);
  165392. if(png_ptr->row_buf[0])
  165393. png_read_filter_row(png_ptr, &(png_ptr->row_info),
  165394. png_ptr->row_buf + 1, png_ptr->prev_row + 1,
  165395. (int)(png_ptr->row_buf[0]));
  165396. png_memcpy_check(png_ptr, png_ptr->prev_row, png_ptr->row_buf,
  165397. png_ptr->rowbytes + 1);
  165398. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  165399. if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  165400. (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING))
  165401. {
  165402. png_do_read_intrapixel(&(png_ptr->row_info), png_ptr->row_buf + 1);
  165403. }
  165404. #endif
  165405. if (png_ptr->transformations || (png_ptr->flags&PNG_FLAG_STRIP_ALPHA))
  165406. png_do_read_transformations(png_ptr);
  165407. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  165408. if (png_ptr->interlaced &&
  165409. (png_ptr->transformations & PNG_INTERLACE))
  165410. {
  165411. if (png_ptr->pass < 6)
  165412. png_do_read_interlace(png_ptr);
  165413. if (dsp_row != NULL)
  165414. png_combine_row(png_ptr, dsp_row,
  165415. png_pass_dsp_mask[png_ptr->pass]);
  165416. if (row != NULL)
  165417. png_combine_row(png_ptr, row,
  165418. png_pass_mask[png_ptr->pass]);
  165419. }
  165420. else
  165421. #endif
  165422. {
  165423. if (row != NULL)
  165424. png_combine_row(png_ptr, row, 0xff);
  165425. if (dsp_row != NULL)
  165426. png_combine_row(png_ptr, dsp_row, 0xff);
  165427. }
  165428. png_read_finish_row(png_ptr);
  165429. if (png_ptr->read_row_fn != NULL)
  165430. (*(png_ptr->read_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass);
  165431. }
  165432. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165433. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  165434. void PNGAPI
  165435. png_read_rows(png_structp png_ptr, png_bytepp row,
  165436. png_bytepp display_row, png_uint_32 num_rows)
  165437. {
  165438. png_uint_32 i;
  165439. png_bytepp rp;
  165440. png_bytepp dp;
  165441. png_debug(1, "in png_read_rows\n");
  165442. if(png_ptr == NULL) return;
  165443. rp = row;
  165444. dp = display_row;
  165445. if (rp != NULL && dp != NULL)
  165446. for (i = 0; i < num_rows; i++)
  165447. {
  165448. png_bytep rptr = *rp++;
  165449. png_bytep dptr = *dp++;
  165450. png_read_row(png_ptr, rptr, dptr);
  165451. }
  165452. else if(rp != NULL)
  165453. for (i = 0; i < num_rows; i++)
  165454. {
  165455. png_bytep rptr = *rp;
  165456. png_read_row(png_ptr, rptr, png_bytep_NULL);
  165457. rp++;
  165458. }
  165459. else if(dp != NULL)
  165460. for (i = 0; i < num_rows; i++)
  165461. {
  165462. png_bytep dptr = *dp;
  165463. png_read_row(png_ptr, png_bytep_NULL, dptr);
  165464. dp++;
  165465. }
  165466. }
  165467. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165468. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  165469. void PNGAPI
  165470. png_read_image(png_structp png_ptr, png_bytepp image)
  165471. {
  165472. png_uint_32 i,image_height;
  165473. int pass, j;
  165474. png_bytepp rp;
  165475. png_debug(1, "in png_read_image\n");
  165476. if(png_ptr == NULL) return;
  165477. #ifdef PNG_READ_INTERLACING_SUPPORTED
  165478. pass = png_set_interlace_handling(png_ptr);
  165479. #else
  165480. if (png_ptr->interlaced)
  165481. png_error(png_ptr,
  165482. "Cannot read interlaced image -- interlace handler disabled.");
  165483. pass = 1;
  165484. #endif
  165485. image_height=png_ptr->height;
  165486. png_ptr->num_rows = image_height; /* Make sure this is set correctly */
  165487. for (j = 0; j < pass; j++)
  165488. {
  165489. rp = image;
  165490. for (i = 0; i < image_height; i++)
  165491. {
  165492. png_read_row(png_ptr, *rp, png_bytep_NULL);
  165493. rp++;
  165494. }
  165495. }
  165496. }
  165497. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165498. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  165499. void PNGAPI
  165500. png_read_end(png_structp png_ptr, png_infop info_ptr)
  165501. {
  165502. png_byte chunk_length[4];
  165503. png_uint_32 length;
  165504. png_debug(1, "in png_read_end\n");
  165505. if(png_ptr == NULL) return;
  165506. png_crc_finish(png_ptr, 0); /* Finish off CRC from last IDAT chunk */
  165507. do
  165508. {
  165509. #ifdef PNG_USE_LOCAL_ARRAYS
  165510. PNG_CONST PNG_IHDR;
  165511. PNG_CONST PNG_IDAT;
  165512. PNG_CONST PNG_IEND;
  165513. PNG_CONST PNG_PLTE;
  165514. #if defined(PNG_READ_bKGD_SUPPORTED)
  165515. PNG_CONST PNG_bKGD;
  165516. #endif
  165517. #if defined(PNG_READ_cHRM_SUPPORTED)
  165518. PNG_CONST PNG_cHRM;
  165519. #endif
  165520. #if defined(PNG_READ_gAMA_SUPPORTED)
  165521. PNG_CONST PNG_gAMA;
  165522. #endif
  165523. #if defined(PNG_READ_hIST_SUPPORTED)
  165524. PNG_CONST PNG_hIST;
  165525. #endif
  165526. #if defined(PNG_READ_iCCP_SUPPORTED)
  165527. PNG_CONST PNG_iCCP;
  165528. #endif
  165529. #if defined(PNG_READ_iTXt_SUPPORTED)
  165530. PNG_CONST PNG_iTXt;
  165531. #endif
  165532. #if defined(PNG_READ_oFFs_SUPPORTED)
  165533. PNG_CONST PNG_oFFs;
  165534. #endif
  165535. #if defined(PNG_READ_pCAL_SUPPORTED)
  165536. PNG_CONST PNG_pCAL;
  165537. #endif
  165538. #if defined(PNG_READ_pHYs_SUPPORTED)
  165539. PNG_CONST PNG_pHYs;
  165540. #endif
  165541. #if defined(PNG_READ_sBIT_SUPPORTED)
  165542. PNG_CONST PNG_sBIT;
  165543. #endif
  165544. #if defined(PNG_READ_sCAL_SUPPORTED)
  165545. PNG_CONST PNG_sCAL;
  165546. #endif
  165547. #if defined(PNG_READ_sPLT_SUPPORTED)
  165548. PNG_CONST PNG_sPLT;
  165549. #endif
  165550. #if defined(PNG_READ_sRGB_SUPPORTED)
  165551. PNG_CONST PNG_sRGB;
  165552. #endif
  165553. #if defined(PNG_READ_tEXt_SUPPORTED)
  165554. PNG_CONST PNG_tEXt;
  165555. #endif
  165556. #if defined(PNG_READ_tIME_SUPPORTED)
  165557. PNG_CONST PNG_tIME;
  165558. #endif
  165559. #if defined(PNG_READ_tRNS_SUPPORTED)
  165560. PNG_CONST PNG_tRNS;
  165561. #endif
  165562. #if defined(PNG_READ_zTXt_SUPPORTED)
  165563. PNG_CONST PNG_zTXt;
  165564. #endif
  165565. #endif /* PNG_USE_LOCAL_ARRAYS */
  165566. png_read_data(png_ptr, chunk_length, 4);
  165567. length = png_get_uint_31(png_ptr,chunk_length);
  165568. png_reset_crc(png_ptr);
  165569. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  165570. png_debug1(0, "Reading %s chunk.\n", png_ptr->chunk_name);
  165571. if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4))
  165572. png_handle_IHDR(png_ptr, info_ptr, length);
  165573. else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
  165574. png_handle_IEND(png_ptr, info_ptr, length);
  165575. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  165576. else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name))
  165577. {
  165578. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165579. {
  165580. if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
  165581. png_error(png_ptr, "Too many IDAT's found");
  165582. }
  165583. png_handle_unknown(png_ptr, info_ptr, length);
  165584. if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  165585. png_ptr->mode |= PNG_HAVE_PLTE;
  165586. }
  165587. #endif
  165588. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165589. {
  165590. if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
  165591. png_error(png_ptr, "Too many IDAT's found");
  165592. png_crc_finish(png_ptr, length);
  165593. }
  165594. else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  165595. png_handle_PLTE(png_ptr, info_ptr, length);
  165596. #if defined(PNG_READ_bKGD_SUPPORTED)
  165597. else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4))
  165598. png_handle_bKGD(png_ptr, info_ptr, length);
  165599. #endif
  165600. #if defined(PNG_READ_cHRM_SUPPORTED)
  165601. else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4))
  165602. png_handle_cHRM(png_ptr, info_ptr, length);
  165603. #endif
  165604. #if defined(PNG_READ_gAMA_SUPPORTED)
  165605. else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4))
  165606. png_handle_gAMA(png_ptr, info_ptr, length);
  165607. #endif
  165608. #if defined(PNG_READ_hIST_SUPPORTED)
  165609. else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4))
  165610. png_handle_hIST(png_ptr, info_ptr, length);
  165611. #endif
  165612. #if defined(PNG_READ_oFFs_SUPPORTED)
  165613. else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4))
  165614. png_handle_oFFs(png_ptr, info_ptr, length);
  165615. #endif
  165616. #if defined(PNG_READ_pCAL_SUPPORTED)
  165617. else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4))
  165618. png_handle_pCAL(png_ptr, info_ptr, length);
  165619. #endif
  165620. #if defined(PNG_READ_sCAL_SUPPORTED)
  165621. else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4))
  165622. png_handle_sCAL(png_ptr, info_ptr, length);
  165623. #endif
  165624. #if defined(PNG_READ_pHYs_SUPPORTED)
  165625. else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4))
  165626. png_handle_pHYs(png_ptr, info_ptr, length);
  165627. #endif
  165628. #if defined(PNG_READ_sBIT_SUPPORTED)
  165629. else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4))
  165630. png_handle_sBIT(png_ptr, info_ptr, length);
  165631. #endif
  165632. #if defined(PNG_READ_sRGB_SUPPORTED)
  165633. else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4))
  165634. png_handle_sRGB(png_ptr, info_ptr, length);
  165635. #endif
  165636. #if defined(PNG_READ_iCCP_SUPPORTED)
  165637. else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4))
  165638. png_handle_iCCP(png_ptr, info_ptr, length);
  165639. #endif
  165640. #if defined(PNG_READ_sPLT_SUPPORTED)
  165641. else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4))
  165642. png_handle_sPLT(png_ptr, info_ptr, length);
  165643. #endif
  165644. #if defined(PNG_READ_tEXt_SUPPORTED)
  165645. else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4))
  165646. png_handle_tEXt(png_ptr, info_ptr, length);
  165647. #endif
  165648. #if defined(PNG_READ_tIME_SUPPORTED)
  165649. else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4))
  165650. png_handle_tIME(png_ptr, info_ptr, length);
  165651. #endif
  165652. #if defined(PNG_READ_tRNS_SUPPORTED)
  165653. else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4))
  165654. png_handle_tRNS(png_ptr, info_ptr, length);
  165655. #endif
  165656. #if defined(PNG_READ_zTXt_SUPPORTED)
  165657. else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4))
  165658. png_handle_zTXt(png_ptr, info_ptr, length);
  165659. #endif
  165660. #if defined(PNG_READ_iTXt_SUPPORTED)
  165661. else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4))
  165662. png_handle_iTXt(png_ptr, info_ptr, length);
  165663. #endif
  165664. else
  165665. png_handle_unknown(png_ptr, info_ptr, length);
  165666. } while (!(png_ptr->mode & PNG_HAVE_IEND));
  165667. }
  165668. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165669. void PNGAPI
  165670. png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr,
  165671. png_infopp end_info_ptr_ptr)
  165672. {
  165673. png_structp png_ptr = NULL;
  165674. png_infop info_ptr = NULL, end_info_ptr = NULL;
  165675. #ifdef PNG_USER_MEM_SUPPORTED
  165676. png_free_ptr free_fn;
  165677. png_voidp mem_ptr;
  165678. #endif
  165679. png_debug(1, "in png_destroy_read_struct\n");
  165680. if (png_ptr_ptr != NULL)
  165681. png_ptr = *png_ptr_ptr;
  165682. if (info_ptr_ptr != NULL)
  165683. info_ptr = *info_ptr_ptr;
  165684. if (end_info_ptr_ptr != NULL)
  165685. end_info_ptr = *end_info_ptr_ptr;
  165686. #ifdef PNG_USER_MEM_SUPPORTED
  165687. free_fn = png_ptr->free_fn;
  165688. mem_ptr = png_ptr->mem_ptr;
  165689. #endif
  165690. png_read_destroy(png_ptr, info_ptr, end_info_ptr);
  165691. if (info_ptr != NULL)
  165692. {
  165693. #if defined(PNG_TEXT_SUPPORTED)
  165694. png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, -1);
  165695. #endif
  165696. #ifdef PNG_USER_MEM_SUPPORTED
  165697. png_destroy_struct_2((png_voidp)info_ptr, (png_free_ptr)free_fn,
  165698. (png_voidp)mem_ptr);
  165699. #else
  165700. png_destroy_struct((png_voidp)info_ptr);
  165701. #endif
  165702. *info_ptr_ptr = NULL;
  165703. }
  165704. if (end_info_ptr != NULL)
  165705. {
  165706. #if defined(PNG_READ_TEXT_SUPPORTED)
  165707. png_free_data(png_ptr, end_info_ptr, PNG_FREE_TEXT, -1);
  165708. #endif
  165709. #ifdef PNG_USER_MEM_SUPPORTED
  165710. png_destroy_struct_2((png_voidp)end_info_ptr, (png_free_ptr)free_fn,
  165711. (png_voidp)mem_ptr);
  165712. #else
  165713. png_destroy_struct((png_voidp)end_info_ptr);
  165714. #endif
  165715. *end_info_ptr_ptr = NULL;
  165716. }
  165717. if (png_ptr != NULL)
  165718. {
  165719. #ifdef PNG_USER_MEM_SUPPORTED
  165720. png_destroy_struct_2((png_voidp)png_ptr, (png_free_ptr)free_fn,
  165721. (png_voidp)mem_ptr);
  165722. #else
  165723. png_destroy_struct((png_voidp)png_ptr);
  165724. #endif
  165725. *png_ptr_ptr = NULL;
  165726. }
  165727. }
  165728. void /* PRIVATE */
  165729. png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr)
  165730. {
  165731. #ifdef PNG_SETJMP_SUPPORTED
  165732. jmp_buf tmp_jmp;
  165733. #endif
  165734. png_error_ptr error_fn;
  165735. png_error_ptr warning_fn;
  165736. png_voidp error_ptr;
  165737. #ifdef PNG_USER_MEM_SUPPORTED
  165738. png_free_ptr free_fn;
  165739. #endif
  165740. png_debug(1, "in png_read_destroy\n");
  165741. if (info_ptr != NULL)
  165742. png_info_destroy(png_ptr, info_ptr);
  165743. if (end_info_ptr != NULL)
  165744. png_info_destroy(png_ptr, end_info_ptr);
  165745. png_free(png_ptr, png_ptr->zbuf);
  165746. png_free(png_ptr, png_ptr->big_row_buf);
  165747. png_free(png_ptr, png_ptr->prev_row);
  165748. #if defined(PNG_READ_DITHER_SUPPORTED)
  165749. png_free(png_ptr, png_ptr->palette_lookup);
  165750. png_free(png_ptr, png_ptr->dither_index);
  165751. #endif
  165752. #if defined(PNG_READ_GAMMA_SUPPORTED)
  165753. png_free(png_ptr, png_ptr->gamma_table);
  165754. #endif
  165755. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  165756. png_free(png_ptr, png_ptr->gamma_from_1);
  165757. png_free(png_ptr, png_ptr->gamma_to_1);
  165758. #endif
  165759. #ifdef PNG_FREE_ME_SUPPORTED
  165760. if (png_ptr->free_me & PNG_FREE_PLTE)
  165761. png_zfree(png_ptr, png_ptr->palette);
  165762. png_ptr->free_me &= ~PNG_FREE_PLTE;
  165763. #else
  165764. if (png_ptr->flags & PNG_FLAG_FREE_PLTE)
  165765. png_zfree(png_ptr, png_ptr->palette);
  165766. png_ptr->flags &= ~PNG_FLAG_FREE_PLTE;
  165767. #endif
  165768. #if defined(PNG_tRNS_SUPPORTED) || \
  165769. defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  165770. #ifdef PNG_FREE_ME_SUPPORTED
  165771. if (png_ptr->free_me & PNG_FREE_TRNS)
  165772. png_free(png_ptr, png_ptr->trans);
  165773. png_ptr->free_me &= ~PNG_FREE_TRNS;
  165774. #else
  165775. if (png_ptr->flags & PNG_FLAG_FREE_TRNS)
  165776. png_free(png_ptr, png_ptr->trans);
  165777. png_ptr->flags &= ~PNG_FLAG_FREE_TRNS;
  165778. #endif
  165779. #endif
  165780. #if defined(PNG_READ_hIST_SUPPORTED)
  165781. #ifdef PNG_FREE_ME_SUPPORTED
  165782. if (png_ptr->free_me & PNG_FREE_HIST)
  165783. png_free(png_ptr, png_ptr->hist);
  165784. png_ptr->free_me &= ~PNG_FREE_HIST;
  165785. #else
  165786. if (png_ptr->flags & PNG_FLAG_FREE_HIST)
  165787. png_free(png_ptr, png_ptr->hist);
  165788. png_ptr->flags &= ~PNG_FLAG_FREE_HIST;
  165789. #endif
  165790. #endif
  165791. #if defined(PNG_READ_GAMMA_SUPPORTED)
  165792. if (png_ptr->gamma_16_table != NULL)
  165793. {
  165794. int i;
  165795. int istop = (1 << (8 - png_ptr->gamma_shift));
  165796. for (i = 0; i < istop; i++)
  165797. {
  165798. png_free(png_ptr, png_ptr->gamma_16_table[i]);
  165799. }
  165800. png_free(png_ptr, png_ptr->gamma_16_table);
  165801. }
  165802. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  165803. if (png_ptr->gamma_16_from_1 != NULL)
  165804. {
  165805. int i;
  165806. int istop = (1 << (8 - png_ptr->gamma_shift));
  165807. for (i = 0; i < istop; i++)
  165808. {
  165809. png_free(png_ptr, png_ptr->gamma_16_from_1[i]);
  165810. }
  165811. png_free(png_ptr, png_ptr->gamma_16_from_1);
  165812. }
  165813. if (png_ptr->gamma_16_to_1 != NULL)
  165814. {
  165815. int i;
  165816. int istop = (1 << (8 - png_ptr->gamma_shift));
  165817. for (i = 0; i < istop; i++)
  165818. {
  165819. png_free(png_ptr, png_ptr->gamma_16_to_1[i]);
  165820. }
  165821. png_free(png_ptr, png_ptr->gamma_16_to_1);
  165822. }
  165823. #endif
  165824. #endif
  165825. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  165826. png_free(png_ptr, png_ptr->time_buffer);
  165827. #endif
  165828. inflateEnd(&png_ptr->zstream);
  165829. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  165830. png_free(png_ptr, png_ptr->save_buffer);
  165831. #endif
  165832. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  165833. #ifdef PNG_TEXT_SUPPORTED
  165834. png_free(png_ptr, png_ptr->current_text);
  165835. #endif /* PNG_TEXT_SUPPORTED */
  165836. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  165837. #ifdef PNG_SETJMP_SUPPORTED
  165838. png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
  165839. #endif
  165840. error_fn = png_ptr->error_fn;
  165841. warning_fn = png_ptr->warning_fn;
  165842. error_ptr = png_ptr->error_ptr;
  165843. #ifdef PNG_USER_MEM_SUPPORTED
  165844. free_fn = png_ptr->free_fn;
  165845. #endif
  165846. png_memset(png_ptr, 0, png_sizeof (png_struct));
  165847. png_ptr->error_fn = error_fn;
  165848. png_ptr->warning_fn = warning_fn;
  165849. png_ptr->error_ptr = error_ptr;
  165850. #ifdef PNG_USER_MEM_SUPPORTED
  165851. png_ptr->free_fn = free_fn;
  165852. #endif
  165853. #ifdef PNG_SETJMP_SUPPORTED
  165854. png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
  165855. #endif
  165856. }
  165857. void PNGAPI
  165858. png_set_read_status_fn(png_structp png_ptr, png_read_status_ptr read_row_fn)
  165859. {
  165860. if(png_ptr == NULL) return;
  165861. png_ptr->read_row_fn = read_row_fn;
  165862. }
  165863. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  165864. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  165865. void PNGAPI
  165866. png_read_png(png_structp png_ptr, png_infop info_ptr,
  165867. int transforms,
  165868. voidp params)
  165869. {
  165870. int row;
  165871. if(png_ptr == NULL) return;
  165872. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  165873. if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
  165874. png_set_invert_alpha(png_ptr);
  165875. #endif
  165876. png_read_info(png_ptr, info_ptr);
  165877. if (info_ptr->height > PNG_UINT_32_MAX/png_sizeof(png_bytep))
  165878. png_error(png_ptr,"Image is too high to process with png_read_png()");
  165879. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  165880. if (transforms & PNG_TRANSFORM_STRIP_16)
  165881. png_set_strip_16(png_ptr);
  165882. #endif
  165883. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  165884. if (transforms & PNG_TRANSFORM_STRIP_ALPHA)
  165885. png_set_strip_alpha(png_ptr);
  165886. #endif
  165887. #if defined(PNG_READ_PACK_SUPPORTED) && !defined(PNG_READ_EXPAND_SUPPORTED)
  165888. if (transforms & PNG_TRANSFORM_PACKING)
  165889. png_set_packing(png_ptr);
  165890. #endif
  165891. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  165892. if (transforms & PNG_TRANSFORM_PACKSWAP)
  165893. png_set_packswap(png_ptr);
  165894. #endif
  165895. #if defined(PNG_READ_EXPAND_SUPPORTED)
  165896. if (transforms & PNG_TRANSFORM_EXPAND)
  165897. if ((png_ptr->bit_depth < 8) ||
  165898. (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) ||
  165899. (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)))
  165900. png_set_expand(png_ptr);
  165901. #endif
  165902. #if defined(PNG_READ_INVERT_SUPPORTED)
  165903. if (transforms & PNG_TRANSFORM_INVERT_MONO)
  165904. png_set_invert_mono(png_ptr);
  165905. #endif
  165906. #if defined(PNG_READ_SHIFT_SUPPORTED)
  165907. if ((transforms & PNG_TRANSFORM_SHIFT)
  165908. && png_get_valid(png_ptr, info_ptr, PNG_INFO_sBIT))
  165909. {
  165910. png_color_8p sig_bit;
  165911. png_get_sBIT(png_ptr, info_ptr, &sig_bit);
  165912. png_set_shift(png_ptr, sig_bit);
  165913. }
  165914. #endif
  165915. #if defined(PNG_READ_BGR_SUPPORTED)
  165916. if (transforms & PNG_TRANSFORM_BGR)
  165917. png_set_bgr(png_ptr);
  165918. #endif
  165919. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
  165920. if (transforms & PNG_TRANSFORM_SWAP_ALPHA)
  165921. png_set_swap_alpha(png_ptr);
  165922. #endif
  165923. #if defined(PNG_READ_SWAP_SUPPORTED)
  165924. if (transforms & PNG_TRANSFORM_SWAP_ENDIAN)
  165925. png_set_swap(png_ptr);
  165926. #endif
  165927. png_read_update_info(png_ptr, info_ptr);
  165928. #ifdef PNG_FREE_ME_SUPPORTED
  165929. png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0);
  165930. #endif
  165931. if(info_ptr->row_pointers == NULL)
  165932. {
  165933. info_ptr->row_pointers = (png_bytepp)png_malloc(png_ptr,
  165934. info_ptr->height * png_sizeof(png_bytep));
  165935. #ifdef PNG_FREE_ME_SUPPORTED
  165936. info_ptr->free_me |= PNG_FREE_ROWS;
  165937. #endif
  165938. for (row = 0; row < (int)info_ptr->height; row++)
  165939. {
  165940. info_ptr->row_pointers[row] = (png_bytep)png_malloc(png_ptr,
  165941. png_get_rowbytes(png_ptr, info_ptr));
  165942. }
  165943. }
  165944. png_read_image(png_ptr, info_ptr->row_pointers);
  165945. info_ptr->valid |= PNG_INFO_IDAT;
  165946. png_read_end(png_ptr, info_ptr);
  165947. transforms = transforms; /* quiet compiler warnings */
  165948. params = params;
  165949. }
  165950. #endif /* PNG_INFO_IMAGE_SUPPORTED */
  165951. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165952. #endif /* PNG_READ_SUPPORTED */
  165953. /*** End of inlined file: pngread.c ***/
  165954. /*** Start of inlined file: pngpread.c ***/
  165955. #define PNG_INTERNAL
  165956. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  165957. #define PNG_READ_SIG_MODE 0
  165958. #define PNG_READ_CHUNK_MODE 1
  165959. #define PNG_READ_IDAT_MODE 2
  165960. #define PNG_SKIP_MODE 3
  165961. #define PNG_READ_tEXt_MODE 4
  165962. #define PNG_READ_zTXt_MODE 5
  165963. #define PNG_READ_DONE_MODE 6
  165964. #define PNG_READ_iTXt_MODE 7
  165965. #define PNG_ERROR_MODE 8
  165966. void PNGAPI
  165967. png_process_data(png_structp png_ptr, png_infop info_ptr,
  165968. png_bytep buffer, png_size_t buffer_size)
  165969. {
  165970. if(png_ptr == NULL) return;
  165971. png_push_restore_buffer(png_ptr, buffer, buffer_size);
  165972. while (png_ptr->buffer_size)
  165973. {
  165974. png_process_some_data(png_ptr, info_ptr);
  165975. }
  165976. }
  165977. void /* PRIVATE */
  165978. png_process_some_data(png_structp png_ptr, png_infop info_ptr)
  165979. {
  165980. if(png_ptr == NULL) return;
  165981. switch (png_ptr->process_mode)
  165982. {
  165983. case PNG_READ_SIG_MODE:
  165984. {
  165985. png_push_read_sig(png_ptr, info_ptr);
  165986. break;
  165987. }
  165988. case PNG_READ_CHUNK_MODE:
  165989. {
  165990. png_push_read_chunk(png_ptr, info_ptr);
  165991. break;
  165992. }
  165993. case PNG_READ_IDAT_MODE:
  165994. {
  165995. png_push_read_IDAT(png_ptr);
  165996. break;
  165997. }
  165998. #if defined(PNG_READ_tEXt_SUPPORTED)
  165999. case PNG_READ_tEXt_MODE:
  166000. {
  166001. png_push_read_tEXt(png_ptr, info_ptr);
  166002. break;
  166003. }
  166004. #endif
  166005. #if defined(PNG_READ_zTXt_SUPPORTED)
  166006. case PNG_READ_zTXt_MODE:
  166007. {
  166008. png_push_read_zTXt(png_ptr, info_ptr);
  166009. break;
  166010. }
  166011. #endif
  166012. #if defined(PNG_READ_iTXt_SUPPORTED)
  166013. case PNG_READ_iTXt_MODE:
  166014. {
  166015. png_push_read_iTXt(png_ptr, info_ptr);
  166016. break;
  166017. }
  166018. #endif
  166019. case PNG_SKIP_MODE:
  166020. {
  166021. png_push_crc_finish(png_ptr);
  166022. break;
  166023. }
  166024. default:
  166025. {
  166026. png_ptr->buffer_size = 0;
  166027. break;
  166028. }
  166029. }
  166030. }
  166031. void /* PRIVATE */
  166032. png_push_read_sig(png_structp png_ptr, png_infop info_ptr)
  166033. {
  166034. png_size_t num_checked = png_ptr->sig_bytes,
  166035. num_to_check = 8 - num_checked;
  166036. if (png_ptr->buffer_size < num_to_check)
  166037. {
  166038. num_to_check = png_ptr->buffer_size;
  166039. }
  166040. png_push_fill_buffer(png_ptr, &(info_ptr->signature[num_checked]),
  166041. num_to_check);
  166042. png_ptr->sig_bytes = (png_byte)(png_ptr->sig_bytes+num_to_check);
  166043. if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check))
  166044. {
  166045. if (num_checked < 4 &&
  166046. png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4))
  166047. png_error(png_ptr, "Not a PNG file");
  166048. else
  166049. png_error(png_ptr, "PNG file corrupted by ASCII conversion");
  166050. }
  166051. else
  166052. {
  166053. if (png_ptr->sig_bytes >= 8)
  166054. {
  166055. png_ptr->process_mode = PNG_READ_CHUNK_MODE;
  166056. }
  166057. }
  166058. }
  166059. void /* PRIVATE */
  166060. png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
  166061. {
  166062. #ifdef PNG_USE_LOCAL_ARRAYS
  166063. PNG_CONST PNG_IHDR;
  166064. PNG_CONST PNG_IDAT;
  166065. PNG_CONST PNG_IEND;
  166066. PNG_CONST PNG_PLTE;
  166067. #if defined(PNG_READ_bKGD_SUPPORTED)
  166068. PNG_CONST PNG_bKGD;
  166069. #endif
  166070. #if defined(PNG_READ_cHRM_SUPPORTED)
  166071. PNG_CONST PNG_cHRM;
  166072. #endif
  166073. #if defined(PNG_READ_gAMA_SUPPORTED)
  166074. PNG_CONST PNG_gAMA;
  166075. #endif
  166076. #if defined(PNG_READ_hIST_SUPPORTED)
  166077. PNG_CONST PNG_hIST;
  166078. #endif
  166079. #if defined(PNG_READ_iCCP_SUPPORTED)
  166080. PNG_CONST PNG_iCCP;
  166081. #endif
  166082. #if defined(PNG_READ_iTXt_SUPPORTED)
  166083. PNG_CONST PNG_iTXt;
  166084. #endif
  166085. #if defined(PNG_READ_oFFs_SUPPORTED)
  166086. PNG_CONST PNG_oFFs;
  166087. #endif
  166088. #if defined(PNG_READ_pCAL_SUPPORTED)
  166089. PNG_CONST PNG_pCAL;
  166090. #endif
  166091. #if defined(PNG_READ_pHYs_SUPPORTED)
  166092. PNG_CONST PNG_pHYs;
  166093. #endif
  166094. #if defined(PNG_READ_sBIT_SUPPORTED)
  166095. PNG_CONST PNG_sBIT;
  166096. #endif
  166097. #if defined(PNG_READ_sCAL_SUPPORTED)
  166098. PNG_CONST PNG_sCAL;
  166099. #endif
  166100. #if defined(PNG_READ_sRGB_SUPPORTED)
  166101. PNG_CONST PNG_sRGB;
  166102. #endif
  166103. #if defined(PNG_READ_sPLT_SUPPORTED)
  166104. PNG_CONST PNG_sPLT;
  166105. #endif
  166106. #if defined(PNG_READ_tEXt_SUPPORTED)
  166107. PNG_CONST PNG_tEXt;
  166108. #endif
  166109. #if defined(PNG_READ_tIME_SUPPORTED)
  166110. PNG_CONST PNG_tIME;
  166111. #endif
  166112. #if defined(PNG_READ_tRNS_SUPPORTED)
  166113. PNG_CONST PNG_tRNS;
  166114. #endif
  166115. #if defined(PNG_READ_zTXt_SUPPORTED)
  166116. PNG_CONST PNG_zTXt;
  166117. #endif
  166118. #endif /* PNG_USE_LOCAL_ARRAYS */
  166119. if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER))
  166120. {
  166121. png_byte chunk_length[4];
  166122. if (png_ptr->buffer_size < 8)
  166123. {
  166124. png_push_save_buffer(png_ptr);
  166125. return;
  166126. }
  166127. png_push_fill_buffer(png_ptr, chunk_length, 4);
  166128. png_ptr->push_length = png_get_uint_31(png_ptr,chunk_length);
  166129. png_reset_crc(png_ptr);
  166130. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  166131. png_ptr->mode |= PNG_HAVE_CHUNK_HEADER;
  166132. }
  166133. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  166134. if(png_ptr->mode & PNG_AFTER_IDAT)
  166135. png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT;
  166136. if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4))
  166137. {
  166138. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166139. {
  166140. png_push_save_buffer(png_ptr);
  166141. return;
  166142. }
  166143. png_handle_IHDR(png_ptr, info_ptr, png_ptr->push_length);
  166144. }
  166145. else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
  166146. {
  166147. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166148. {
  166149. png_push_save_buffer(png_ptr);
  166150. return;
  166151. }
  166152. png_handle_IEND(png_ptr, info_ptr, png_ptr->push_length);
  166153. png_ptr->process_mode = PNG_READ_DONE_MODE;
  166154. png_push_have_end(png_ptr, info_ptr);
  166155. }
  166156. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  166157. else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name))
  166158. {
  166159. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166160. {
  166161. png_push_save_buffer(png_ptr);
  166162. return;
  166163. }
  166164. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  166165. png_ptr->mode |= PNG_HAVE_IDAT;
  166166. png_handle_unknown(png_ptr, info_ptr, png_ptr->push_length);
  166167. if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  166168. png_ptr->mode |= PNG_HAVE_PLTE;
  166169. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  166170. {
  166171. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  166172. png_error(png_ptr, "Missing IHDR before IDAT");
  166173. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  166174. !(png_ptr->mode & PNG_HAVE_PLTE))
  166175. png_error(png_ptr, "Missing PLTE before IDAT");
  166176. }
  166177. }
  166178. #endif
  166179. else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  166180. {
  166181. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166182. {
  166183. png_push_save_buffer(png_ptr);
  166184. return;
  166185. }
  166186. png_handle_PLTE(png_ptr, info_ptr, png_ptr->push_length);
  166187. }
  166188. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  166189. {
  166190. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  166191. png_error(png_ptr, "Missing IHDR before IDAT");
  166192. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  166193. !(png_ptr->mode & PNG_HAVE_PLTE))
  166194. png_error(png_ptr, "Missing PLTE before IDAT");
  166195. if (png_ptr->mode & PNG_HAVE_IDAT)
  166196. {
  166197. if (!(png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
  166198. if (png_ptr->push_length == 0)
  166199. return;
  166200. if (png_ptr->mode & PNG_AFTER_IDAT)
  166201. png_error(png_ptr, "Too many IDAT's found");
  166202. }
  166203. png_ptr->idat_size = png_ptr->push_length;
  166204. png_ptr->mode |= PNG_HAVE_IDAT;
  166205. png_ptr->process_mode = PNG_READ_IDAT_MODE;
  166206. png_push_have_info(png_ptr, info_ptr);
  166207. png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
  166208. png_ptr->zstream.next_out = png_ptr->row_buf;
  166209. return;
  166210. }
  166211. #if defined(PNG_READ_gAMA_SUPPORTED)
  166212. else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4))
  166213. {
  166214. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166215. {
  166216. png_push_save_buffer(png_ptr);
  166217. return;
  166218. }
  166219. png_handle_gAMA(png_ptr, info_ptr, png_ptr->push_length);
  166220. }
  166221. #endif
  166222. #if defined(PNG_READ_sBIT_SUPPORTED)
  166223. else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4))
  166224. {
  166225. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166226. {
  166227. png_push_save_buffer(png_ptr);
  166228. return;
  166229. }
  166230. png_handle_sBIT(png_ptr, info_ptr, png_ptr->push_length);
  166231. }
  166232. #endif
  166233. #if defined(PNG_READ_cHRM_SUPPORTED)
  166234. else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4))
  166235. {
  166236. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166237. {
  166238. png_push_save_buffer(png_ptr);
  166239. return;
  166240. }
  166241. png_handle_cHRM(png_ptr, info_ptr, png_ptr->push_length);
  166242. }
  166243. #endif
  166244. #if defined(PNG_READ_sRGB_SUPPORTED)
  166245. else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4))
  166246. {
  166247. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166248. {
  166249. png_push_save_buffer(png_ptr);
  166250. return;
  166251. }
  166252. png_handle_sRGB(png_ptr, info_ptr, png_ptr->push_length);
  166253. }
  166254. #endif
  166255. #if defined(PNG_READ_iCCP_SUPPORTED)
  166256. else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4))
  166257. {
  166258. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166259. {
  166260. png_push_save_buffer(png_ptr);
  166261. return;
  166262. }
  166263. png_handle_iCCP(png_ptr, info_ptr, png_ptr->push_length);
  166264. }
  166265. #endif
  166266. #if defined(PNG_READ_sPLT_SUPPORTED)
  166267. else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4))
  166268. {
  166269. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166270. {
  166271. png_push_save_buffer(png_ptr);
  166272. return;
  166273. }
  166274. png_handle_sPLT(png_ptr, info_ptr, png_ptr->push_length);
  166275. }
  166276. #endif
  166277. #if defined(PNG_READ_tRNS_SUPPORTED)
  166278. else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4))
  166279. {
  166280. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166281. {
  166282. png_push_save_buffer(png_ptr);
  166283. return;
  166284. }
  166285. png_handle_tRNS(png_ptr, info_ptr, png_ptr->push_length);
  166286. }
  166287. #endif
  166288. #if defined(PNG_READ_bKGD_SUPPORTED)
  166289. else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4))
  166290. {
  166291. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166292. {
  166293. png_push_save_buffer(png_ptr);
  166294. return;
  166295. }
  166296. png_handle_bKGD(png_ptr, info_ptr, png_ptr->push_length);
  166297. }
  166298. #endif
  166299. #if defined(PNG_READ_hIST_SUPPORTED)
  166300. else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4))
  166301. {
  166302. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166303. {
  166304. png_push_save_buffer(png_ptr);
  166305. return;
  166306. }
  166307. png_handle_hIST(png_ptr, info_ptr, png_ptr->push_length);
  166308. }
  166309. #endif
  166310. #if defined(PNG_READ_pHYs_SUPPORTED)
  166311. else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4))
  166312. {
  166313. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166314. {
  166315. png_push_save_buffer(png_ptr);
  166316. return;
  166317. }
  166318. png_handle_pHYs(png_ptr, info_ptr, png_ptr->push_length);
  166319. }
  166320. #endif
  166321. #if defined(PNG_READ_oFFs_SUPPORTED)
  166322. else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4))
  166323. {
  166324. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166325. {
  166326. png_push_save_buffer(png_ptr);
  166327. return;
  166328. }
  166329. png_handle_oFFs(png_ptr, info_ptr, png_ptr->push_length);
  166330. }
  166331. #endif
  166332. #if defined(PNG_READ_pCAL_SUPPORTED)
  166333. else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4))
  166334. {
  166335. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166336. {
  166337. png_push_save_buffer(png_ptr);
  166338. return;
  166339. }
  166340. png_handle_pCAL(png_ptr, info_ptr, png_ptr->push_length);
  166341. }
  166342. #endif
  166343. #if defined(PNG_READ_sCAL_SUPPORTED)
  166344. else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4))
  166345. {
  166346. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166347. {
  166348. png_push_save_buffer(png_ptr);
  166349. return;
  166350. }
  166351. png_handle_sCAL(png_ptr, info_ptr, png_ptr->push_length);
  166352. }
  166353. #endif
  166354. #if defined(PNG_READ_tIME_SUPPORTED)
  166355. else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4))
  166356. {
  166357. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166358. {
  166359. png_push_save_buffer(png_ptr);
  166360. return;
  166361. }
  166362. png_handle_tIME(png_ptr, info_ptr, png_ptr->push_length);
  166363. }
  166364. #endif
  166365. #if defined(PNG_READ_tEXt_SUPPORTED)
  166366. else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4))
  166367. {
  166368. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166369. {
  166370. png_push_save_buffer(png_ptr);
  166371. return;
  166372. }
  166373. png_push_handle_tEXt(png_ptr, info_ptr, png_ptr->push_length);
  166374. }
  166375. #endif
  166376. #if defined(PNG_READ_zTXt_SUPPORTED)
  166377. else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4))
  166378. {
  166379. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166380. {
  166381. png_push_save_buffer(png_ptr);
  166382. return;
  166383. }
  166384. png_push_handle_zTXt(png_ptr, info_ptr, png_ptr->push_length);
  166385. }
  166386. #endif
  166387. #if defined(PNG_READ_iTXt_SUPPORTED)
  166388. else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4))
  166389. {
  166390. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166391. {
  166392. png_push_save_buffer(png_ptr);
  166393. return;
  166394. }
  166395. png_push_handle_iTXt(png_ptr, info_ptr, png_ptr->push_length);
  166396. }
  166397. #endif
  166398. else
  166399. {
  166400. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166401. {
  166402. png_push_save_buffer(png_ptr);
  166403. return;
  166404. }
  166405. png_push_handle_unknown(png_ptr, info_ptr, png_ptr->push_length);
  166406. }
  166407. png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
  166408. }
  166409. void /* PRIVATE */
  166410. png_push_crc_skip(png_structp png_ptr, png_uint_32 skip)
  166411. {
  166412. png_ptr->process_mode = PNG_SKIP_MODE;
  166413. png_ptr->skip_length = skip;
  166414. }
  166415. void /* PRIVATE */
  166416. png_push_crc_finish(png_structp png_ptr)
  166417. {
  166418. if (png_ptr->skip_length && png_ptr->save_buffer_size)
  166419. {
  166420. png_size_t save_size;
  166421. if (png_ptr->skip_length < (png_uint_32)png_ptr->save_buffer_size)
  166422. save_size = (png_size_t)png_ptr->skip_length;
  166423. else
  166424. save_size = png_ptr->save_buffer_size;
  166425. png_calculate_crc(png_ptr, png_ptr->save_buffer_ptr, save_size);
  166426. png_ptr->skip_length -= save_size;
  166427. png_ptr->buffer_size -= save_size;
  166428. png_ptr->save_buffer_size -= save_size;
  166429. png_ptr->save_buffer_ptr += save_size;
  166430. }
  166431. if (png_ptr->skip_length && png_ptr->current_buffer_size)
  166432. {
  166433. png_size_t save_size;
  166434. if (png_ptr->skip_length < (png_uint_32)png_ptr->current_buffer_size)
  166435. save_size = (png_size_t)png_ptr->skip_length;
  166436. else
  166437. save_size = png_ptr->current_buffer_size;
  166438. png_calculate_crc(png_ptr, png_ptr->current_buffer_ptr, save_size);
  166439. png_ptr->skip_length -= save_size;
  166440. png_ptr->buffer_size -= save_size;
  166441. png_ptr->current_buffer_size -= save_size;
  166442. png_ptr->current_buffer_ptr += save_size;
  166443. }
  166444. if (!png_ptr->skip_length)
  166445. {
  166446. if (png_ptr->buffer_size < 4)
  166447. {
  166448. png_push_save_buffer(png_ptr);
  166449. return;
  166450. }
  166451. png_crc_finish(png_ptr, 0);
  166452. png_ptr->process_mode = PNG_READ_CHUNK_MODE;
  166453. }
  166454. }
  166455. void PNGAPI
  166456. png_push_fill_buffer(png_structp png_ptr, png_bytep buffer, png_size_t length)
  166457. {
  166458. png_bytep ptr;
  166459. if(png_ptr == NULL) return;
  166460. ptr = buffer;
  166461. if (png_ptr->save_buffer_size)
  166462. {
  166463. png_size_t save_size;
  166464. if (length < png_ptr->save_buffer_size)
  166465. save_size = length;
  166466. else
  166467. save_size = png_ptr->save_buffer_size;
  166468. png_memcpy(ptr, png_ptr->save_buffer_ptr, save_size);
  166469. length -= save_size;
  166470. ptr += save_size;
  166471. png_ptr->buffer_size -= save_size;
  166472. png_ptr->save_buffer_size -= save_size;
  166473. png_ptr->save_buffer_ptr += save_size;
  166474. }
  166475. if (length && png_ptr->current_buffer_size)
  166476. {
  166477. png_size_t save_size;
  166478. if (length < png_ptr->current_buffer_size)
  166479. save_size = length;
  166480. else
  166481. save_size = png_ptr->current_buffer_size;
  166482. png_memcpy(ptr, png_ptr->current_buffer_ptr, save_size);
  166483. png_ptr->buffer_size -= save_size;
  166484. png_ptr->current_buffer_size -= save_size;
  166485. png_ptr->current_buffer_ptr += save_size;
  166486. }
  166487. }
  166488. void /* PRIVATE */
  166489. png_push_save_buffer(png_structp png_ptr)
  166490. {
  166491. if (png_ptr->save_buffer_size)
  166492. {
  166493. if (png_ptr->save_buffer_ptr != png_ptr->save_buffer)
  166494. {
  166495. png_size_t i,istop;
  166496. png_bytep sp;
  166497. png_bytep dp;
  166498. istop = png_ptr->save_buffer_size;
  166499. for (i = 0, sp = png_ptr->save_buffer_ptr, dp = png_ptr->save_buffer;
  166500. i < istop; i++, sp++, dp++)
  166501. {
  166502. *dp = *sp;
  166503. }
  166504. }
  166505. }
  166506. if (png_ptr->save_buffer_size + png_ptr->current_buffer_size >
  166507. png_ptr->save_buffer_max)
  166508. {
  166509. png_size_t new_max;
  166510. png_bytep old_buffer;
  166511. if (png_ptr->save_buffer_size > PNG_SIZE_MAX -
  166512. (png_ptr->current_buffer_size + 256))
  166513. {
  166514. png_error(png_ptr, "Potential overflow of save_buffer");
  166515. }
  166516. new_max = png_ptr->save_buffer_size + png_ptr->current_buffer_size + 256;
  166517. old_buffer = png_ptr->save_buffer;
  166518. png_ptr->save_buffer = (png_bytep)png_malloc(png_ptr,
  166519. (png_uint_32)new_max);
  166520. png_memcpy(png_ptr->save_buffer, old_buffer, png_ptr->save_buffer_size);
  166521. png_free(png_ptr, old_buffer);
  166522. png_ptr->save_buffer_max = new_max;
  166523. }
  166524. if (png_ptr->current_buffer_size)
  166525. {
  166526. png_memcpy(png_ptr->save_buffer + png_ptr->save_buffer_size,
  166527. png_ptr->current_buffer_ptr, png_ptr->current_buffer_size);
  166528. png_ptr->save_buffer_size += png_ptr->current_buffer_size;
  166529. png_ptr->current_buffer_size = 0;
  166530. }
  166531. png_ptr->save_buffer_ptr = png_ptr->save_buffer;
  166532. png_ptr->buffer_size = 0;
  166533. }
  166534. void /* PRIVATE */
  166535. png_push_restore_buffer(png_structp png_ptr, png_bytep buffer,
  166536. png_size_t buffer_length)
  166537. {
  166538. png_ptr->current_buffer = buffer;
  166539. png_ptr->current_buffer_size = buffer_length;
  166540. png_ptr->buffer_size = buffer_length + png_ptr->save_buffer_size;
  166541. png_ptr->current_buffer_ptr = png_ptr->current_buffer;
  166542. }
  166543. void /* PRIVATE */
  166544. png_push_read_IDAT(png_structp png_ptr)
  166545. {
  166546. #ifdef PNG_USE_LOCAL_ARRAYS
  166547. PNG_CONST PNG_IDAT;
  166548. #endif
  166549. if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER))
  166550. {
  166551. png_byte chunk_length[4];
  166552. if (png_ptr->buffer_size < 8)
  166553. {
  166554. png_push_save_buffer(png_ptr);
  166555. return;
  166556. }
  166557. png_push_fill_buffer(png_ptr, chunk_length, 4);
  166558. png_ptr->push_length = png_get_uint_31(png_ptr,chunk_length);
  166559. png_reset_crc(png_ptr);
  166560. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  166561. png_ptr->mode |= PNG_HAVE_CHUNK_HEADER;
  166562. if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  166563. {
  166564. png_ptr->process_mode = PNG_READ_CHUNK_MODE;
  166565. if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
  166566. png_error(png_ptr, "Not enough compressed data");
  166567. return;
  166568. }
  166569. png_ptr->idat_size = png_ptr->push_length;
  166570. }
  166571. if (png_ptr->idat_size && png_ptr->save_buffer_size)
  166572. {
  166573. png_size_t save_size;
  166574. if (png_ptr->idat_size < (png_uint_32)png_ptr->save_buffer_size)
  166575. {
  166576. save_size = (png_size_t)png_ptr->idat_size;
  166577. if((png_uint_32)save_size != png_ptr->idat_size)
  166578. png_error(png_ptr, "save_size overflowed in pngpread");
  166579. }
  166580. else
  166581. save_size = png_ptr->save_buffer_size;
  166582. png_calculate_crc(png_ptr, png_ptr->save_buffer_ptr, save_size);
  166583. if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
  166584. png_process_IDAT_data(png_ptr, png_ptr->save_buffer_ptr, save_size);
  166585. png_ptr->idat_size -= save_size;
  166586. png_ptr->buffer_size -= save_size;
  166587. png_ptr->save_buffer_size -= save_size;
  166588. png_ptr->save_buffer_ptr += save_size;
  166589. }
  166590. if (png_ptr->idat_size && png_ptr->current_buffer_size)
  166591. {
  166592. png_size_t save_size;
  166593. if (png_ptr->idat_size < (png_uint_32)png_ptr->current_buffer_size)
  166594. {
  166595. save_size = (png_size_t)png_ptr->idat_size;
  166596. if((png_uint_32)save_size != png_ptr->idat_size)
  166597. png_error(png_ptr, "save_size overflowed in pngpread");
  166598. }
  166599. else
  166600. save_size = png_ptr->current_buffer_size;
  166601. png_calculate_crc(png_ptr, png_ptr->current_buffer_ptr, save_size);
  166602. if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
  166603. png_process_IDAT_data(png_ptr, png_ptr->current_buffer_ptr, save_size);
  166604. png_ptr->idat_size -= save_size;
  166605. png_ptr->buffer_size -= save_size;
  166606. png_ptr->current_buffer_size -= save_size;
  166607. png_ptr->current_buffer_ptr += save_size;
  166608. }
  166609. if (!png_ptr->idat_size)
  166610. {
  166611. if (png_ptr->buffer_size < 4)
  166612. {
  166613. png_push_save_buffer(png_ptr);
  166614. return;
  166615. }
  166616. png_crc_finish(png_ptr, 0);
  166617. png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
  166618. png_ptr->mode |= PNG_AFTER_IDAT;
  166619. }
  166620. }
  166621. void /* PRIVATE */
  166622. png_process_IDAT_data(png_structp png_ptr, png_bytep buffer,
  166623. png_size_t buffer_length)
  166624. {
  166625. int ret;
  166626. if ((png_ptr->flags & PNG_FLAG_ZLIB_FINISHED) && buffer_length)
  166627. png_error(png_ptr, "Extra compression data");
  166628. png_ptr->zstream.next_in = buffer;
  166629. png_ptr->zstream.avail_in = (uInt)buffer_length;
  166630. for(;;)
  166631. {
  166632. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  166633. if (ret != Z_OK)
  166634. {
  166635. if (ret == Z_STREAM_END)
  166636. {
  166637. if (png_ptr->zstream.avail_in)
  166638. png_error(png_ptr, "Extra compressed data");
  166639. if (!(png_ptr->zstream.avail_out))
  166640. {
  166641. png_push_process_row(png_ptr);
  166642. }
  166643. png_ptr->mode |= PNG_AFTER_IDAT;
  166644. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  166645. break;
  166646. }
  166647. else if (ret == Z_BUF_ERROR)
  166648. break;
  166649. else
  166650. png_error(png_ptr, "Decompression Error");
  166651. }
  166652. if (!(png_ptr->zstream.avail_out))
  166653. {
  166654. if ((
  166655. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  166656. png_ptr->interlaced && png_ptr->pass > 6) ||
  166657. (!png_ptr->interlaced &&
  166658. #endif
  166659. png_ptr->row_number == png_ptr->num_rows))
  166660. {
  166661. if (png_ptr->zstream.avail_in)
  166662. {
  166663. png_warning(png_ptr, "Too much data in IDAT chunks");
  166664. }
  166665. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  166666. break;
  166667. }
  166668. png_push_process_row(png_ptr);
  166669. png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
  166670. png_ptr->zstream.next_out = png_ptr->row_buf;
  166671. }
  166672. else
  166673. break;
  166674. }
  166675. }
  166676. void /* PRIVATE */
  166677. png_push_process_row(png_structp png_ptr)
  166678. {
  166679. png_ptr->row_info.color_type = png_ptr->color_type;
  166680. png_ptr->row_info.width = png_ptr->iwidth;
  166681. png_ptr->row_info.channels = png_ptr->channels;
  166682. png_ptr->row_info.bit_depth = png_ptr->bit_depth;
  166683. png_ptr->row_info.pixel_depth = png_ptr->pixel_depth;
  166684. png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
  166685. png_ptr->row_info.width);
  166686. png_read_filter_row(png_ptr, &(png_ptr->row_info),
  166687. png_ptr->row_buf + 1, png_ptr->prev_row + 1,
  166688. (int)(png_ptr->row_buf[0]));
  166689. png_memcpy_check(png_ptr, png_ptr->prev_row, png_ptr->row_buf,
  166690. png_ptr->rowbytes + 1);
  166691. if (png_ptr->transformations || (png_ptr->flags&PNG_FLAG_STRIP_ALPHA))
  166692. png_do_read_transformations(png_ptr);
  166693. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  166694. if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
  166695. {
  166696. if (png_ptr->pass < 6)
  166697. png_do_read_interlace(png_ptr);
  166698. switch (png_ptr->pass)
  166699. {
  166700. case 0:
  166701. {
  166702. int i;
  166703. for (i = 0; i < 8 && png_ptr->pass == 0; i++)
  166704. {
  166705. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166706. png_read_push_finish_row(png_ptr); /* updates png_ptr->pass */
  166707. }
  166708. if (png_ptr->pass == 2) /* pass 1 might be empty */
  166709. {
  166710. for (i = 0; i < 4 && png_ptr->pass == 2; i++)
  166711. {
  166712. png_push_have_row(png_ptr, png_bytep_NULL);
  166713. png_read_push_finish_row(png_ptr);
  166714. }
  166715. }
  166716. if (png_ptr->pass == 4 && png_ptr->height <= 4)
  166717. {
  166718. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166719. {
  166720. png_push_have_row(png_ptr, png_bytep_NULL);
  166721. png_read_push_finish_row(png_ptr);
  166722. }
  166723. }
  166724. if (png_ptr->pass == 6 && png_ptr->height <= 4)
  166725. {
  166726. png_push_have_row(png_ptr, png_bytep_NULL);
  166727. png_read_push_finish_row(png_ptr);
  166728. }
  166729. break;
  166730. }
  166731. case 1:
  166732. {
  166733. int i;
  166734. for (i = 0; i < 8 && png_ptr->pass == 1; i++)
  166735. {
  166736. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166737. png_read_push_finish_row(png_ptr);
  166738. }
  166739. if (png_ptr->pass == 2) /* skip top 4 generated rows */
  166740. {
  166741. for (i = 0; i < 4 && png_ptr->pass == 2; i++)
  166742. {
  166743. png_push_have_row(png_ptr, png_bytep_NULL);
  166744. png_read_push_finish_row(png_ptr);
  166745. }
  166746. }
  166747. break;
  166748. }
  166749. case 2:
  166750. {
  166751. int i;
  166752. for (i = 0; i < 4 && png_ptr->pass == 2; i++)
  166753. {
  166754. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166755. png_read_push_finish_row(png_ptr);
  166756. }
  166757. for (i = 0; i < 4 && png_ptr->pass == 2; i++)
  166758. {
  166759. png_push_have_row(png_ptr, png_bytep_NULL);
  166760. png_read_push_finish_row(png_ptr);
  166761. }
  166762. if (png_ptr->pass == 4) /* pass 3 might be empty */
  166763. {
  166764. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166765. {
  166766. png_push_have_row(png_ptr, png_bytep_NULL);
  166767. png_read_push_finish_row(png_ptr);
  166768. }
  166769. }
  166770. break;
  166771. }
  166772. case 3:
  166773. {
  166774. int i;
  166775. for (i = 0; i < 4 && png_ptr->pass == 3; i++)
  166776. {
  166777. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166778. png_read_push_finish_row(png_ptr);
  166779. }
  166780. if (png_ptr->pass == 4) /* skip top two generated rows */
  166781. {
  166782. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166783. {
  166784. png_push_have_row(png_ptr, png_bytep_NULL);
  166785. png_read_push_finish_row(png_ptr);
  166786. }
  166787. }
  166788. break;
  166789. }
  166790. case 4:
  166791. {
  166792. int i;
  166793. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166794. {
  166795. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166796. png_read_push_finish_row(png_ptr);
  166797. }
  166798. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166799. {
  166800. png_push_have_row(png_ptr, png_bytep_NULL);
  166801. png_read_push_finish_row(png_ptr);
  166802. }
  166803. if (png_ptr->pass == 6) /* pass 5 might be empty */
  166804. {
  166805. png_push_have_row(png_ptr, png_bytep_NULL);
  166806. png_read_push_finish_row(png_ptr);
  166807. }
  166808. break;
  166809. }
  166810. case 5:
  166811. {
  166812. int i;
  166813. for (i = 0; i < 2 && png_ptr->pass == 5; i++)
  166814. {
  166815. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166816. png_read_push_finish_row(png_ptr);
  166817. }
  166818. if (png_ptr->pass == 6) /* skip top generated row */
  166819. {
  166820. png_push_have_row(png_ptr, png_bytep_NULL);
  166821. png_read_push_finish_row(png_ptr);
  166822. }
  166823. break;
  166824. }
  166825. case 6:
  166826. {
  166827. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166828. png_read_push_finish_row(png_ptr);
  166829. if (png_ptr->pass != 6)
  166830. break;
  166831. png_push_have_row(png_ptr, png_bytep_NULL);
  166832. png_read_push_finish_row(png_ptr);
  166833. }
  166834. }
  166835. }
  166836. else
  166837. #endif
  166838. {
  166839. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166840. png_read_push_finish_row(png_ptr);
  166841. }
  166842. }
  166843. void /* PRIVATE */
  166844. png_read_push_finish_row(png_structp png_ptr)
  166845. {
  166846. #ifdef PNG_USE_LOCAL_ARRAYS
  166847. PNG_CONST int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
  166848. PNG_CONST int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
  166849. PNG_CONST int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
  166850. PNG_CONST int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
  166851. #endif
  166852. png_ptr->row_number++;
  166853. if (png_ptr->row_number < png_ptr->num_rows)
  166854. return;
  166855. if (png_ptr->interlaced)
  166856. {
  166857. png_ptr->row_number = 0;
  166858. png_memset_check(png_ptr, png_ptr->prev_row, 0,
  166859. png_ptr->rowbytes + 1);
  166860. do
  166861. {
  166862. png_ptr->pass++;
  166863. if ((png_ptr->pass == 1 && png_ptr->width < 5) ||
  166864. (png_ptr->pass == 3 && png_ptr->width < 3) ||
  166865. (png_ptr->pass == 5 && png_ptr->width < 2))
  166866. png_ptr->pass++;
  166867. if (png_ptr->pass > 7)
  166868. png_ptr->pass--;
  166869. if (png_ptr->pass >= 7)
  166870. break;
  166871. png_ptr->iwidth = (png_ptr->width +
  166872. png_pass_inc[png_ptr->pass] - 1 -
  166873. png_pass_start[png_ptr->pass]) /
  166874. png_pass_inc[png_ptr->pass];
  166875. png_ptr->irowbytes = PNG_ROWBYTES(png_ptr->pixel_depth,
  166876. png_ptr->iwidth) + 1;
  166877. if (png_ptr->transformations & PNG_INTERLACE)
  166878. break;
  166879. png_ptr->num_rows = (png_ptr->height +
  166880. png_pass_yinc[png_ptr->pass] - 1 -
  166881. png_pass_ystart[png_ptr->pass]) /
  166882. png_pass_yinc[png_ptr->pass];
  166883. } while (png_ptr->iwidth == 0 || png_ptr->num_rows == 0);
  166884. }
  166885. }
  166886. #if defined(PNG_READ_tEXt_SUPPORTED)
  166887. void /* PRIVATE */
  166888. png_push_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
  166889. length)
  166890. {
  166891. if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
  166892. {
  166893. png_error(png_ptr, "Out of place tEXt");
  166894. info_ptr = info_ptr; /* to quiet some compiler warnings */
  166895. }
  166896. #ifdef PNG_MAX_MALLOC_64K
  166897. png_ptr->skip_length = 0; /* This may not be necessary */
  166898. if (length > (png_uint_32)65535L) /* Can't hold entire string in memory */
  166899. {
  166900. png_warning(png_ptr, "tEXt chunk too large to fit in memory");
  166901. png_ptr->skip_length = length - (png_uint_32)65535L;
  166902. length = (png_uint_32)65535L;
  166903. }
  166904. #endif
  166905. png_ptr->current_text = (png_charp)png_malloc(png_ptr,
  166906. (png_uint_32)(length+1));
  166907. png_ptr->current_text[length] = '\0';
  166908. png_ptr->current_text_ptr = png_ptr->current_text;
  166909. png_ptr->current_text_size = (png_size_t)length;
  166910. png_ptr->current_text_left = (png_size_t)length;
  166911. png_ptr->process_mode = PNG_READ_tEXt_MODE;
  166912. }
  166913. void /* PRIVATE */
  166914. png_push_read_tEXt(png_structp png_ptr, png_infop info_ptr)
  166915. {
  166916. if (png_ptr->buffer_size && png_ptr->current_text_left)
  166917. {
  166918. png_size_t text_size;
  166919. if (png_ptr->buffer_size < png_ptr->current_text_left)
  166920. text_size = png_ptr->buffer_size;
  166921. else
  166922. text_size = png_ptr->current_text_left;
  166923. png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
  166924. png_ptr->current_text_left -= text_size;
  166925. png_ptr->current_text_ptr += text_size;
  166926. }
  166927. if (!(png_ptr->current_text_left))
  166928. {
  166929. png_textp text_ptr;
  166930. png_charp text;
  166931. png_charp key;
  166932. int ret;
  166933. if (png_ptr->buffer_size < 4)
  166934. {
  166935. png_push_save_buffer(png_ptr);
  166936. return;
  166937. }
  166938. png_push_crc_finish(png_ptr);
  166939. #if defined(PNG_MAX_MALLOC_64K)
  166940. if (png_ptr->skip_length)
  166941. return;
  166942. #endif
  166943. key = png_ptr->current_text;
  166944. for (text = key; *text; text++)
  166945. ;
  166946. if (text < key + png_ptr->current_text_size)
  166947. text++;
  166948. text_ptr = (png_textp)png_malloc(png_ptr,
  166949. (png_uint_32)png_sizeof(png_text));
  166950. text_ptr->compression = PNG_TEXT_COMPRESSION_NONE;
  166951. text_ptr->key = key;
  166952. #ifdef PNG_iTXt_SUPPORTED
  166953. text_ptr->lang = NULL;
  166954. text_ptr->lang_key = NULL;
  166955. #endif
  166956. text_ptr->text = text;
  166957. ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  166958. png_free(png_ptr, key);
  166959. png_free(png_ptr, text_ptr);
  166960. png_ptr->current_text = NULL;
  166961. if (ret)
  166962. png_warning(png_ptr, "Insufficient memory to store text chunk.");
  166963. }
  166964. }
  166965. #endif
  166966. #if defined(PNG_READ_zTXt_SUPPORTED)
  166967. void /* PRIVATE */
  166968. png_push_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
  166969. length)
  166970. {
  166971. if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
  166972. {
  166973. png_error(png_ptr, "Out of place zTXt");
  166974. info_ptr = info_ptr; /* to quiet some compiler warnings */
  166975. }
  166976. #ifdef PNG_MAX_MALLOC_64K
  166977. if (length > (png_uint_32)65535L)
  166978. {
  166979. png_warning(png_ptr, "zTXt chunk too large to fit in memory");
  166980. png_push_crc_skip(png_ptr, length);
  166981. return;
  166982. }
  166983. #endif
  166984. png_ptr->current_text = (png_charp)png_malloc(png_ptr,
  166985. (png_uint_32)(length+1));
  166986. png_ptr->current_text[length] = '\0';
  166987. png_ptr->current_text_ptr = png_ptr->current_text;
  166988. png_ptr->current_text_size = (png_size_t)length;
  166989. png_ptr->current_text_left = (png_size_t)length;
  166990. png_ptr->process_mode = PNG_READ_zTXt_MODE;
  166991. }
  166992. void /* PRIVATE */
  166993. png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr)
  166994. {
  166995. if (png_ptr->buffer_size && png_ptr->current_text_left)
  166996. {
  166997. png_size_t text_size;
  166998. if (png_ptr->buffer_size < (png_uint_32)png_ptr->current_text_left)
  166999. text_size = png_ptr->buffer_size;
  167000. else
  167001. text_size = png_ptr->current_text_left;
  167002. png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
  167003. png_ptr->current_text_left -= text_size;
  167004. png_ptr->current_text_ptr += text_size;
  167005. }
  167006. if (!(png_ptr->current_text_left))
  167007. {
  167008. png_textp text_ptr;
  167009. png_charp text;
  167010. png_charp key;
  167011. int ret;
  167012. png_size_t text_size, key_size;
  167013. if (png_ptr->buffer_size < 4)
  167014. {
  167015. png_push_save_buffer(png_ptr);
  167016. return;
  167017. }
  167018. png_push_crc_finish(png_ptr);
  167019. key = png_ptr->current_text;
  167020. for (text = key; *text; text++)
  167021. ;
  167022. if (text >= key + png_ptr->current_text_size)
  167023. {
  167024. png_ptr->current_text = NULL;
  167025. png_free(png_ptr, key);
  167026. return;
  167027. }
  167028. text++;
  167029. if (*text != PNG_TEXT_COMPRESSION_zTXt) /* check compression byte */
  167030. {
  167031. png_ptr->current_text = NULL;
  167032. png_free(png_ptr, key);
  167033. return;
  167034. }
  167035. text++;
  167036. png_ptr->zstream.next_in = (png_bytep )text;
  167037. png_ptr->zstream.avail_in = (uInt)(png_ptr->current_text_size -
  167038. (text - key));
  167039. png_ptr->zstream.next_out = png_ptr->zbuf;
  167040. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  167041. key_size = text - key;
  167042. text_size = 0;
  167043. text = NULL;
  167044. ret = Z_STREAM_END;
  167045. while (png_ptr->zstream.avail_in)
  167046. {
  167047. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  167048. if (ret != Z_OK && ret != Z_STREAM_END)
  167049. {
  167050. inflateReset(&png_ptr->zstream);
  167051. png_ptr->zstream.avail_in = 0;
  167052. png_ptr->current_text = NULL;
  167053. png_free(png_ptr, key);
  167054. png_free(png_ptr, text);
  167055. return;
  167056. }
  167057. if (!(png_ptr->zstream.avail_out) || ret == Z_STREAM_END)
  167058. {
  167059. if (text == NULL)
  167060. {
  167061. text = (png_charp)png_malloc(png_ptr,
  167062. (png_uint_32)(png_ptr->zbuf_size - png_ptr->zstream.avail_out
  167063. + key_size + 1));
  167064. png_memcpy(text + key_size, png_ptr->zbuf,
  167065. png_ptr->zbuf_size - png_ptr->zstream.avail_out);
  167066. png_memcpy(text, key, key_size);
  167067. text_size = key_size + png_ptr->zbuf_size -
  167068. png_ptr->zstream.avail_out;
  167069. *(text + text_size) = '\0';
  167070. }
  167071. else
  167072. {
  167073. png_charp tmp;
  167074. tmp = text;
  167075. text = (png_charp)png_malloc(png_ptr, text_size +
  167076. (png_uint_32)(png_ptr->zbuf_size - png_ptr->zstream.avail_out
  167077. + 1));
  167078. png_memcpy(text, tmp, text_size);
  167079. png_free(png_ptr, tmp);
  167080. png_memcpy(text + text_size, png_ptr->zbuf,
  167081. png_ptr->zbuf_size - png_ptr->zstream.avail_out);
  167082. text_size += png_ptr->zbuf_size - png_ptr->zstream.avail_out;
  167083. *(text + text_size) = '\0';
  167084. }
  167085. if (ret != Z_STREAM_END)
  167086. {
  167087. png_ptr->zstream.next_out = png_ptr->zbuf;
  167088. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  167089. }
  167090. }
  167091. else
  167092. {
  167093. break;
  167094. }
  167095. if (ret == Z_STREAM_END)
  167096. break;
  167097. }
  167098. inflateReset(&png_ptr->zstream);
  167099. png_ptr->zstream.avail_in = 0;
  167100. if (ret != Z_STREAM_END)
  167101. {
  167102. png_ptr->current_text = NULL;
  167103. png_free(png_ptr, key);
  167104. png_free(png_ptr, text);
  167105. return;
  167106. }
  167107. png_ptr->current_text = NULL;
  167108. png_free(png_ptr, key);
  167109. key = text;
  167110. text += key_size;
  167111. text_ptr = (png_textp)png_malloc(png_ptr,
  167112. (png_uint_32)png_sizeof(png_text));
  167113. text_ptr->compression = PNG_TEXT_COMPRESSION_zTXt;
  167114. text_ptr->key = key;
  167115. #ifdef PNG_iTXt_SUPPORTED
  167116. text_ptr->lang = NULL;
  167117. text_ptr->lang_key = NULL;
  167118. #endif
  167119. text_ptr->text = text;
  167120. ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  167121. png_free(png_ptr, key);
  167122. png_free(png_ptr, text_ptr);
  167123. if (ret)
  167124. png_warning(png_ptr, "Insufficient memory to store text chunk.");
  167125. }
  167126. }
  167127. #endif
  167128. #if defined(PNG_READ_iTXt_SUPPORTED)
  167129. void /* PRIVATE */
  167130. png_push_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
  167131. length)
  167132. {
  167133. if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
  167134. {
  167135. png_error(png_ptr, "Out of place iTXt");
  167136. info_ptr = info_ptr; /* to quiet some compiler warnings */
  167137. }
  167138. #ifdef PNG_MAX_MALLOC_64K
  167139. png_ptr->skip_length = 0; /* This may not be necessary */
  167140. if (length > (png_uint_32)65535L) /* Can't hold entire string in memory */
  167141. {
  167142. png_warning(png_ptr, "iTXt chunk too large to fit in memory");
  167143. png_ptr->skip_length = length - (png_uint_32)65535L;
  167144. length = (png_uint_32)65535L;
  167145. }
  167146. #endif
  167147. png_ptr->current_text = (png_charp)png_malloc(png_ptr,
  167148. (png_uint_32)(length+1));
  167149. png_ptr->current_text[length] = '\0';
  167150. png_ptr->current_text_ptr = png_ptr->current_text;
  167151. png_ptr->current_text_size = (png_size_t)length;
  167152. png_ptr->current_text_left = (png_size_t)length;
  167153. png_ptr->process_mode = PNG_READ_iTXt_MODE;
  167154. }
  167155. void /* PRIVATE */
  167156. png_push_read_iTXt(png_structp png_ptr, png_infop info_ptr)
  167157. {
  167158. if (png_ptr->buffer_size && png_ptr->current_text_left)
  167159. {
  167160. png_size_t text_size;
  167161. if (png_ptr->buffer_size < png_ptr->current_text_left)
  167162. text_size = png_ptr->buffer_size;
  167163. else
  167164. text_size = png_ptr->current_text_left;
  167165. png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
  167166. png_ptr->current_text_left -= text_size;
  167167. png_ptr->current_text_ptr += text_size;
  167168. }
  167169. if (!(png_ptr->current_text_left))
  167170. {
  167171. png_textp text_ptr;
  167172. png_charp key;
  167173. int comp_flag;
  167174. png_charp lang;
  167175. png_charp lang_key;
  167176. png_charp text;
  167177. int ret;
  167178. if (png_ptr->buffer_size < 4)
  167179. {
  167180. png_push_save_buffer(png_ptr);
  167181. return;
  167182. }
  167183. png_push_crc_finish(png_ptr);
  167184. #if defined(PNG_MAX_MALLOC_64K)
  167185. if (png_ptr->skip_length)
  167186. return;
  167187. #endif
  167188. key = png_ptr->current_text;
  167189. for (lang = key; *lang; lang++)
  167190. ;
  167191. if (lang < key + png_ptr->current_text_size - 3)
  167192. lang++;
  167193. comp_flag = *lang++;
  167194. lang++; /* skip comp_type, always zero */
  167195. for (lang_key = lang; *lang_key; lang_key++)
  167196. ;
  167197. lang_key++; /* skip NUL separator */
  167198. text=lang_key;
  167199. if (lang_key < key + png_ptr->current_text_size - 1)
  167200. {
  167201. for (; *text; text++)
  167202. ;
  167203. }
  167204. if (text < key + png_ptr->current_text_size)
  167205. text++;
  167206. text_ptr = (png_textp)png_malloc(png_ptr,
  167207. (png_uint_32)png_sizeof(png_text));
  167208. text_ptr->compression = comp_flag + 2;
  167209. text_ptr->key = key;
  167210. text_ptr->lang = lang;
  167211. text_ptr->lang_key = lang_key;
  167212. text_ptr->text = text;
  167213. text_ptr->text_length = 0;
  167214. text_ptr->itxt_length = png_strlen(text);
  167215. ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  167216. png_ptr->current_text = NULL;
  167217. png_free(png_ptr, text_ptr);
  167218. if (ret)
  167219. png_warning(png_ptr, "Insufficient memory to store iTXt chunk.");
  167220. }
  167221. }
  167222. #endif
  167223. void /* PRIVATE */
  167224. png_push_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32
  167225. length)
  167226. {
  167227. png_uint_32 skip=0;
  167228. png_check_chunk_name(png_ptr, png_ptr->chunk_name);
  167229. if (!(png_ptr->chunk_name[0] & 0x20))
  167230. {
  167231. #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  167232. if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
  167233. PNG_HANDLE_CHUNK_ALWAYS
  167234. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  167235. && png_ptr->read_user_chunk_fn == NULL
  167236. #endif
  167237. )
  167238. #endif
  167239. png_chunk_error(png_ptr, "unknown critical chunk");
  167240. info_ptr = info_ptr; /* to quiet some compiler warnings */
  167241. }
  167242. #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  167243. if (png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS)
  167244. {
  167245. #ifdef PNG_MAX_MALLOC_64K
  167246. if (length > (png_uint_32)65535L)
  167247. {
  167248. png_warning(png_ptr, "unknown chunk too large to fit in memory");
  167249. skip = length - (png_uint_32)65535L;
  167250. length = (png_uint_32)65535L;
  167251. }
  167252. #endif
  167253. png_strncpy((png_charp)png_ptr->unknown_chunk.name,
  167254. (png_charp)png_ptr->chunk_name, 5);
  167255. png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr, length);
  167256. png_ptr->unknown_chunk.size = (png_size_t)length;
  167257. png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data, length);
  167258. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  167259. if(png_ptr->read_user_chunk_fn != NULL)
  167260. {
  167261. int ret;
  167262. ret = (*(png_ptr->read_user_chunk_fn))
  167263. (png_ptr, &png_ptr->unknown_chunk);
  167264. if (ret < 0)
  167265. png_chunk_error(png_ptr, "error in user chunk");
  167266. if (ret == 0)
  167267. {
  167268. if (!(png_ptr->chunk_name[0] & 0x20))
  167269. if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
  167270. PNG_HANDLE_CHUNK_ALWAYS)
  167271. png_chunk_error(png_ptr, "unknown critical chunk");
  167272. png_set_unknown_chunks(png_ptr, info_ptr,
  167273. &png_ptr->unknown_chunk, 1);
  167274. }
  167275. }
  167276. #else
  167277. png_set_unknown_chunks(png_ptr, info_ptr, &png_ptr->unknown_chunk, 1);
  167278. #endif
  167279. png_free(png_ptr, png_ptr->unknown_chunk.data);
  167280. png_ptr->unknown_chunk.data = NULL;
  167281. }
  167282. else
  167283. #endif
  167284. skip=length;
  167285. png_push_crc_skip(png_ptr, skip);
  167286. }
  167287. void /* PRIVATE */
  167288. png_push_have_info(png_structp png_ptr, png_infop info_ptr)
  167289. {
  167290. if (png_ptr->info_fn != NULL)
  167291. (*(png_ptr->info_fn))(png_ptr, info_ptr);
  167292. }
  167293. void /* PRIVATE */
  167294. png_push_have_end(png_structp png_ptr, png_infop info_ptr)
  167295. {
  167296. if (png_ptr->end_fn != NULL)
  167297. (*(png_ptr->end_fn))(png_ptr, info_ptr);
  167298. }
  167299. void /* PRIVATE */
  167300. png_push_have_row(png_structp png_ptr, png_bytep row)
  167301. {
  167302. if (png_ptr->row_fn != NULL)
  167303. (*(png_ptr->row_fn))(png_ptr, row, png_ptr->row_number,
  167304. (int)png_ptr->pass);
  167305. }
  167306. void PNGAPI
  167307. png_progressive_combine_row (png_structp png_ptr,
  167308. png_bytep old_row, png_bytep new_row)
  167309. {
  167310. #ifdef PNG_USE_LOCAL_ARRAYS
  167311. PNG_CONST int FARDATA png_pass_dsp_mask[7] =
  167312. {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
  167313. #endif
  167314. if(png_ptr == NULL) return;
  167315. if (new_row != NULL) /* new_row must == png_ptr->row_buf here. */
  167316. png_combine_row(png_ptr, old_row, png_pass_dsp_mask[png_ptr->pass]);
  167317. }
  167318. void PNGAPI
  167319. png_set_progressive_read_fn(png_structp png_ptr, png_voidp progressive_ptr,
  167320. png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn,
  167321. png_progressive_end_ptr end_fn)
  167322. {
  167323. if(png_ptr == NULL) return;
  167324. png_ptr->info_fn = info_fn;
  167325. png_ptr->row_fn = row_fn;
  167326. png_ptr->end_fn = end_fn;
  167327. png_set_read_fn(png_ptr, progressive_ptr, png_push_fill_buffer);
  167328. }
  167329. png_voidp PNGAPI
  167330. png_get_progressive_ptr(png_structp png_ptr)
  167331. {
  167332. if(png_ptr == NULL) return (NULL);
  167333. return png_ptr->io_ptr;
  167334. }
  167335. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  167336. /*** End of inlined file: pngpread.c ***/
  167337. /*** Start of inlined file: pngrio.c ***/
  167338. #define PNG_INTERNAL
  167339. #if defined(PNG_READ_SUPPORTED)
  167340. void /* PRIVATE */
  167341. png_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
  167342. {
  167343. png_debug1(4,"reading %d bytes\n", (int)length);
  167344. if (png_ptr->read_data_fn != NULL)
  167345. (*(png_ptr->read_data_fn))(png_ptr, data, length);
  167346. else
  167347. png_error(png_ptr, "Call to NULL read function");
  167348. }
  167349. #if !defined(PNG_NO_STDIO)
  167350. #ifndef USE_FAR_KEYWORD
  167351. void PNGAPI
  167352. png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
  167353. {
  167354. png_size_t check;
  167355. if(png_ptr == NULL) return;
  167356. #if defined(_WIN32_WCE)
  167357. if ( !ReadFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) )
  167358. check = 0;
  167359. #else
  167360. check = (png_size_t)fread(data, (png_size_t)1, length,
  167361. (png_FILE_p)png_ptr->io_ptr);
  167362. #endif
  167363. if (check != length)
  167364. png_error(png_ptr, "Read Error");
  167365. }
  167366. #else
  167367. #define NEAR_BUF_SIZE 1024
  167368. #define MIN(a,b) (a <= b ? a : b)
  167369. static void PNGAPI
  167370. png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
  167371. {
  167372. int check;
  167373. png_byte *n_data;
  167374. png_FILE_p io_ptr;
  167375. if(png_ptr == NULL) return;
  167376. n_data = (png_byte *)CVT_PTR_NOCHECK(data);
  167377. io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr);
  167378. if ((png_bytep)n_data == data)
  167379. {
  167380. #if defined(_WIN32_WCE)
  167381. if ( !ReadFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) )
  167382. check = 0;
  167383. #else
  167384. check = fread(n_data, 1, length, io_ptr);
  167385. #endif
  167386. }
  167387. else
  167388. {
  167389. png_byte buf[NEAR_BUF_SIZE];
  167390. png_size_t read, remaining, err;
  167391. check = 0;
  167392. remaining = length;
  167393. do
  167394. {
  167395. read = MIN(NEAR_BUF_SIZE, remaining);
  167396. #if defined(_WIN32_WCE)
  167397. if ( !ReadFile((HANDLE)(io_ptr), buf, read, &err, NULL) )
  167398. err = 0;
  167399. #else
  167400. err = fread(buf, (png_size_t)1, read, io_ptr);
  167401. #endif
  167402. png_memcpy(data, buf, read); /* copy far buffer to near buffer */
  167403. if(err != read)
  167404. break;
  167405. else
  167406. check += err;
  167407. data += read;
  167408. remaining -= read;
  167409. }
  167410. while (remaining != 0);
  167411. }
  167412. if ((png_uint_32)check != (png_uint_32)length)
  167413. png_error(png_ptr, "read Error");
  167414. }
  167415. #endif
  167416. #endif
  167417. void PNGAPI
  167418. png_set_read_fn(png_structp png_ptr, png_voidp io_ptr,
  167419. png_rw_ptr read_data_fn)
  167420. {
  167421. if(png_ptr == NULL) return;
  167422. png_ptr->io_ptr = io_ptr;
  167423. #if !defined(PNG_NO_STDIO)
  167424. if (read_data_fn != NULL)
  167425. png_ptr->read_data_fn = read_data_fn;
  167426. else
  167427. png_ptr->read_data_fn = png_default_read_data;
  167428. #else
  167429. png_ptr->read_data_fn = read_data_fn;
  167430. #endif
  167431. if (png_ptr->write_data_fn != NULL)
  167432. {
  167433. png_ptr->write_data_fn = NULL;
  167434. png_warning(png_ptr,
  167435. "It's an error to set both read_data_fn and write_data_fn in the ");
  167436. png_warning(png_ptr,
  167437. "same structure. Resetting write_data_fn to NULL.");
  167438. }
  167439. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  167440. png_ptr->output_flush_fn = NULL;
  167441. #endif
  167442. }
  167443. #endif /* PNG_READ_SUPPORTED */
  167444. /*** End of inlined file: pngrio.c ***/
  167445. /*** Start of inlined file: pngrtran.c ***/
  167446. #define PNG_INTERNAL
  167447. #if defined(PNG_READ_SUPPORTED)
  167448. void PNGAPI
  167449. png_set_crc_action(png_structp png_ptr, int crit_action, int ancil_action)
  167450. {
  167451. png_debug(1, "in png_set_crc_action\n");
  167452. if(png_ptr == NULL) return;
  167453. switch (crit_action)
  167454. {
  167455. case PNG_CRC_NO_CHANGE: /* leave setting as is */
  167456. break;
  167457. case PNG_CRC_WARN_USE: /* warn/use data */
  167458. png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
  167459. png_ptr->flags |= PNG_FLAG_CRC_CRITICAL_USE;
  167460. break;
  167461. case PNG_CRC_QUIET_USE: /* quiet/use data */
  167462. png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
  167463. png_ptr->flags |= PNG_FLAG_CRC_CRITICAL_USE |
  167464. PNG_FLAG_CRC_CRITICAL_IGNORE;
  167465. break;
  167466. case PNG_CRC_WARN_DISCARD: /* not a valid action for critical data */
  167467. png_warning(png_ptr, "Can't discard critical data on CRC error.");
  167468. case PNG_CRC_ERROR_QUIT: /* error/quit */
  167469. case PNG_CRC_DEFAULT:
  167470. default:
  167471. png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
  167472. break;
  167473. }
  167474. switch (ancil_action)
  167475. {
  167476. case PNG_CRC_NO_CHANGE: /* leave setting as is */
  167477. break;
  167478. case PNG_CRC_WARN_USE: /* warn/use data */
  167479. png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  167480. png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_USE;
  167481. break;
  167482. case PNG_CRC_QUIET_USE: /* quiet/use data */
  167483. png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  167484. png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_USE |
  167485. PNG_FLAG_CRC_ANCILLARY_NOWARN;
  167486. break;
  167487. case PNG_CRC_ERROR_QUIT: /* error/quit */
  167488. png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  167489. png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_NOWARN;
  167490. break;
  167491. case PNG_CRC_WARN_DISCARD: /* warn/discard data */
  167492. case PNG_CRC_DEFAULT:
  167493. default:
  167494. png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  167495. break;
  167496. }
  167497. }
  167498. #if defined(PNG_READ_BACKGROUND_SUPPORTED) && \
  167499. defined(PNG_FLOATING_POINT_SUPPORTED)
  167500. void PNGAPI
  167501. png_set_background(png_structp png_ptr,
  167502. png_color_16p background_color, int background_gamma_code,
  167503. int need_expand, double background_gamma)
  167504. {
  167505. png_debug(1, "in png_set_background\n");
  167506. if(png_ptr == NULL) return;
  167507. if (background_gamma_code == PNG_BACKGROUND_GAMMA_UNKNOWN)
  167508. {
  167509. png_warning(png_ptr, "Application must supply a known background gamma");
  167510. return;
  167511. }
  167512. png_ptr->transformations |= PNG_BACKGROUND;
  167513. png_memcpy(&(png_ptr->background), background_color,
  167514. png_sizeof(png_color_16));
  167515. png_ptr->background_gamma = (float)background_gamma;
  167516. png_ptr->background_gamma_type = (png_byte)(background_gamma_code);
  167517. png_ptr->transformations |= (need_expand ? PNG_BACKGROUND_EXPAND : 0);
  167518. }
  167519. #endif
  167520. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  167521. void PNGAPI
  167522. png_set_strip_16(png_structp png_ptr)
  167523. {
  167524. png_debug(1, "in png_set_strip_16\n");
  167525. if(png_ptr == NULL) return;
  167526. png_ptr->transformations |= PNG_16_TO_8;
  167527. }
  167528. #endif
  167529. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  167530. void PNGAPI
  167531. png_set_strip_alpha(png_structp png_ptr)
  167532. {
  167533. png_debug(1, "in png_set_strip_alpha\n");
  167534. if(png_ptr == NULL) return;
  167535. png_ptr->flags |= PNG_FLAG_STRIP_ALPHA;
  167536. }
  167537. #endif
  167538. #if defined(PNG_READ_DITHER_SUPPORTED)
  167539. typedef struct png_dsort_struct
  167540. {
  167541. struct png_dsort_struct FAR * next;
  167542. png_byte left;
  167543. png_byte right;
  167544. } png_dsort;
  167545. typedef png_dsort FAR * png_dsortp;
  167546. typedef png_dsort FAR * FAR * png_dsortpp;
  167547. void PNGAPI
  167548. png_set_dither(png_structp png_ptr, png_colorp palette,
  167549. int num_palette, int maximum_colors, png_uint_16p histogram,
  167550. int full_dither)
  167551. {
  167552. png_debug(1, "in png_set_dither\n");
  167553. if(png_ptr == NULL) return;
  167554. png_ptr->transformations |= PNG_DITHER;
  167555. if (!full_dither)
  167556. {
  167557. int i;
  167558. png_ptr->dither_index = (png_bytep)png_malloc(png_ptr,
  167559. (png_uint_32)(num_palette * png_sizeof (png_byte)));
  167560. for (i = 0; i < num_palette; i++)
  167561. png_ptr->dither_index[i] = (png_byte)i;
  167562. }
  167563. if (num_palette > maximum_colors)
  167564. {
  167565. if (histogram != NULL)
  167566. {
  167567. int i;
  167568. png_ptr->dither_sort = (png_bytep)png_malloc(png_ptr,
  167569. (png_uint_32)(num_palette * png_sizeof (png_byte)));
  167570. for (i = 0; i < num_palette; i++)
  167571. png_ptr->dither_sort[i] = (png_byte)i;
  167572. for (i = num_palette - 1; i >= maximum_colors; i--)
  167573. {
  167574. int done; /* to stop early if the list is pre-sorted */
  167575. int j;
  167576. done = 1;
  167577. for (j = 0; j < i; j++)
  167578. {
  167579. if (histogram[png_ptr->dither_sort[j]]
  167580. < histogram[png_ptr->dither_sort[j + 1]])
  167581. {
  167582. png_byte t;
  167583. t = png_ptr->dither_sort[j];
  167584. png_ptr->dither_sort[j] = png_ptr->dither_sort[j + 1];
  167585. png_ptr->dither_sort[j + 1] = t;
  167586. done = 0;
  167587. }
  167588. }
  167589. if (done)
  167590. break;
  167591. }
  167592. if (full_dither)
  167593. {
  167594. int j = num_palette;
  167595. for (i = 0; i < maximum_colors; i++)
  167596. {
  167597. if ((int)png_ptr->dither_sort[i] >= maximum_colors)
  167598. {
  167599. do
  167600. j--;
  167601. while ((int)png_ptr->dither_sort[j] >= maximum_colors);
  167602. palette[i] = palette[j];
  167603. }
  167604. }
  167605. }
  167606. else
  167607. {
  167608. int j = num_palette;
  167609. for (i = 0; i < maximum_colors; i++)
  167610. {
  167611. if ((int)png_ptr->dither_sort[i] >= maximum_colors)
  167612. {
  167613. png_color tmp_color;
  167614. do
  167615. j--;
  167616. while ((int)png_ptr->dither_sort[j] >= maximum_colors);
  167617. tmp_color = palette[j];
  167618. palette[j] = palette[i];
  167619. palette[i] = tmp_color;
  167620. png_ptr->dither_index[j] = (png_byte)i;
  167621. png_ptr->dither_index[i] = (png_byte)j;
  167622. }
  167623. }
  167624. for (i = 0; i < num_palette; i++)
  167625. {
  167626. if ((int)png_ptr->dither_index[i] >= maximum_colors)
  167627. {
  167628. int min_d, k, min_k, d_index;
  167629. d_index = png_ptr->dither_index[i];
  167630. min_d = PNG_COLOR_DIST(palette[d_index], palette[0]);
  167631. for (k = 1, min_k = 0; k < maximum_colors; k++)
  167632. {
  167633. int d;
  167634. d = PNG_COLOR_DIST(palette[d_index], palette[k]);
  167635. if (d < min_d)
  167636. {
  167637. min_d = d;
  167638. min_k = k;
  167639. }
  167640. }
  167641. png_ptr->dither_index[i] = (png_byte)min_k;
  167642. }
  167643. }
  167644. }
  167645. png_free(png_ptr, png_ptr->dither_sort);
  167646. png_ptr->dither_sort=NULL;
  167647. }
  167648. else
  167649. {
  167650. int i;
  167651. int max_d;
  167652. int num_new_palette;
  167653. png_dsortp t;
  167654. png_dsortpp hash;
  167655. t=NULL;
  167656. png_ptr->index_to_palette = (png_bytep)png_malloc(png_ptr,
  167657. (png_uint_32)(num_palette * png_sizeof (png_byte)));
  167658. png_ptr->palette_to_index = (png_bytep)png_malloc(png_ptr,
  167659. (png_uint_32)(num_palette * png_sizeof (png_byte)));
  167660. for (i = 0; i < num_palette; i++)
  167661. {
  167662. png_ptr->index_to_palette[i] = (png_byte)i;
  167663. png_ptr->palette_to_index[i] = (png_byte)i;
  167664. }
  167665. hash = (png_dsortpp)png_malloc(png_ptr, (png_uint_32)(769 *
  167666. png_sizeof (png_dsortp)));
  167667. for (i = 0; i < 769; i++)
  167668. hash[i] = NULL;
  167669. num_new_palette = num_palette;
  167670. max_d = 96;
  167671. while (num_new_palette > maximum_colors)
  167672. {
  167673. for (i = 0; i < num_new_palette - 1; i++)
  167674. {
  167675. int j;
  167676. for (j = i + 1; j < num_new_palette; j++)
  167677. {
  167678. int d;
  167679. d = PNG_COLOR_DIST(palette[i], palette[j]);
  167680. if (d <= max_d)
  167681. {
  167682. t = (png_dsortp)png_malloc_warn(png_ptr,
  167683. (png_uint_32)(png_sizeof(png_dsort)));
  167684. if (t == NULL)
  167685. break;
  167686. t->next = hash[d];
  167687. t->left = (png_byte)i;
  167688. t->right = (png_byte)j;
  167689. hash[d] = t;
  167690. }
  167691. }
  167692. if (t == NULL)
  167693. break;
  167694. }
  167695. if (t != NULL)
  167696. for (i = 0; i <= max_d; i++)
  167697. {
  167698. if (hash[i] != NULL)
  167699. {
  167700. png_dsortp p;
  167701. for (p = hash[i]; p; p = p->next)
  167702. {
  167703. if ((int)png_ptr->index_to_palette[p->left]
  167704. < num_new_palette &&
  167705. (int)png_ptr->index_to_palette[p->right]
  167706. < num_new_palette)
  167707. {
  167708. int j, next_j;
  167709. if (num_new_palette & 0x01)
  167710. {
  167711. j = p->left;
  167712. next_j = p->right;
  167713. }
  167714. else
  167715. {
  167716. j = p->right;
  167717. next_j = p->left;
  167718. }
  167719. num_new_palette--;
  167720. palette[png_ptr->index_to_palette[j]]
  167721. = palette[num_new_palette];
  167722. if (!full_dither)
  167723. {
  167724. int k;
  167725. for (k = 0; k < num_palette; k++)
  167726. {
  167727. if (png_ptr->dither_index[k] ==
  167728. png_ptr->index_to_palette[j])
  167729. png_ptr->dither_index[k] =
  167730. png_ptr->index_to_palette[next_j];
  167731. if ((int)png_ptr->dither_index[k] ==
  167732. num_new_palette)
  167733. png_ptr->dither_index[k] =
  167734. png_ptr->index_to_palette[j];
  167735. }
  167736. }
  167737. png_ptr->index_to_palette[png_ptr->palette_to_index
  167738. [num_new_palette]] = png_ptr->index_to_palette[j];
  167739. png_ptr->palette_to_index[png_ptr->index_to_palette[j]]
  167740. = png_ptr->palette_to_index[num_new_palette];
  167741. png_ptr->index_to_palette[j] = (png_byte)num_new_palette;
  167742. png_ptr->palette_to_index[num_new_palette] = (png_byte)j;
  167743. }
  167744. if (num_new_palette <= maximum_colors)
  167745. break;
  167746. }
  167747. if (num_new_palette <= maximum_colors)
  167748. break;
  167749. }
  167750. }
  167751. for (i = 0; i < 769; i++)
  167752. {
  167753. if (hash[i] != NULL)
  167754. {
  167755. png_dsortp p = hash[i];
  167756. while (p)
  167757. {
  167758. t = p->next;
  167759. png_free(png_ptr, p);
  167760. p = t;
  167761. }
  167762. }
  167763. hash[i] = 0;
  167764. }
  167765. max_d += 96;
  167766. }
  167767. png_free(png_ptr, hash);
  167768. png_free(png_ptr, png_ptr->palette_to_index);
  167769. png_free(png_ptr, png_ptr->index_to_palette);
  167770. png_ptr->palette_to_index=NULL;
  167771. png_ptr->index_to_palette=NULL;
  167772. }
  167773. num_palette = maximum_colors;
  167774. }
  167775. if (png_ptr->palette == NULL)
  167776. {
  167777. png_ptr->palette = palette;
  167778. }
  167779. png_ptr->num_palette = (png_uint_16)num_palette;
  167780. if (full_dither)
  167781. {
  167782. int i;
  167783. png_bytep distance;
  167784. int total_bits = PNG_DITHER_RED_BITS + PNG_DITHER_GREEN_BITS +
  167785. PNG_DITHER_BLUE_BITS;
  167786. int num_red = (1 << PNG_DITHER_RED_BITS);
  167787. int num_green = (1 << PNG_DITHER_GREEN_BITS);
  167788. int num_blue = (1 << PNG_DITHER_BLUE_BITS);
  167789. png_size_t num_entries = ((png_size_t)1 << total_bits);
  167790. png_ptr->palette_lookup = (png_bytep )png_malloc(png_ptr,
  167791. (png_uint_32)(num_entries * png_sizeof (png_byte)));
  167792. png_memset(png_ptr->palette_lookup, 0, num_entries *
  167793. png_sizeof (png_byte));
  167794. distance = (png_bytep)png_malloc(png_ptr, (png_uint_32)(num_entries *
  167795. png_sizeof(png_byte)));
  167796. png_memset(distance, 0xff, num_entries * png_sizeof(png_byte));
  167797. for (i = 0; i < num_palette; i++)
  167798. {
  167799. int ir, ig, ib;
  167800. int r = (palette[i].red >> (8 - PNG_DITHER_RED_BITS));
  167801. int g = (palette[i].green >> (8 - PNG_DITHER_GREEN_BITS));
  167802. int b = (palette[i].blue >> (8 - PNG_DITHER_BLUE_BITS));
  167803. for (ir = 0; ir < num_red; ir++)
  167804. {
  167805. int dr = ((ir > r) ? ir - r : r - ir);
  167806. int index_r = (ir << (PNG_DITHER_BLUE_BITS + PNG_DITHER_GREEN_BITS));
  167807. for (ig = 0; ig < num_green; ig++)
  167808. {
  167809. int dg = ((ig > g) ? ig - g : g - ig);
  167810. int dt = dr + dg;
  167811. int dm = ((dr > dg) ? dr : dg);
  167812. int index_g = index_r | (ig << PNG_DITHER_BLUE_BITS);
  167813. for (ib = 0; ib < num_blue; ib++)
  167814. {
  167815. int d_index = index_g | ib;
  167816. int db = ((ib > b) ? ib - b : b - ib);
  167817. int dmax = ((dm > db) ? dm : db);
  167818. int d = dmax + dt + db;
  167819. if (d < (int)distance[d_index])
  167820. {
  167821. distance[d_index] = (png_byte)d;
  167822. png_ptr->palette_lookup[d_index] = (png_byte)i;
  167823. }
  167824. }
  167825. }
  167826. }
  167827. }
  167828. png_free(png_ptr, distance);
  167829. }
  167830. }
  167831. #endif
  167832. #if defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
  167833. void PNGAPI
  167834. png_set_gamma(png_structp png_ptr, double scrn_gamma, double file_gamma)
  167835. {
  167836. png_debug(1, "in png_set_gamma\n");
  167837. if(png_ptr == NULL) return;
  167838. if ((fabs(scrn_gamma * file_gamma - 1.0) > PNG_GAMMA_THRESHOLD) ||
  167839. (png_ptr->color_type & PNG_COLOR_MASK_ALPHA) ||
  167840. (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE))
  167841. png_ptr->transformations |= PNG_GAMMA;
  167842. png_ptr->gamma = (float)file_gamma;
  167843. png_ptr->screen_gamma = (float)scrn_gamma;
  167844. }
  167845. #endif
  167846. #if defined(PNG_READ_EXPAND_SUPPORTED)
  167847. void PNGAPI
  167848. png_set_expand(png_structp png_ptr)
  167849. {
  167850. png_debug(1, "in png_set_expand\n");
  167851. if(png_ptr == NULL) return;
  167852. png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
  167853. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167854. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167855. #endif
  167856. }
  167857. void PNGAPI
  167858. png_set_palette_to_rgb(png_structp png_ptr)
  167859. {
  167860. png_debug(1, "in png_set_palette_to_rgb\n");
  167861. if(png_ptr == NULL) return;
  167862. png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
  167863. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167864. png_ptr->flags &= !(PNG_FLAG_ROW_INIT);
  167865. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167866. #endif
  167867. }
  167868. #if !defined(PNG_1_0_X)
  167869. void PNGAPI
  167870. png_set_expand_gray_1_2_4_to_8(png_structp png_ptr)
  167871. {
  167872. png_debug(1, "in png_set_expand_gray_1_2_4_to_8\n");
  167873. if(png_ptr == NULL) return;
  167874. png_ptr->transformations |= PNG_EXPAND;
  167875. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167876. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167877. #endif
  167878. }
  167879. #endif
  167880. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  167881. void PNGAPI
  167882. png_set_gray_1_2_4_to_8(png_structp png_ptr)
  167883. {
  167884. png_debug(1, "in png_set_gray_1_2_4_to_8\n");
  167885. if(png_ptr == NULL) return;
  167886. png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
  167887. }
  167888. #endif
  167889. void PNGAPI
  167890. png_set_tRNS_to_alpha(png_structp png_ptr)
  167891. {
  167892. png_debug(1, "in png_set_tRNS_to_alpha\n");
  167893. png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
  167894. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167895. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167896. #endif
  167897. }
  167898. #endif /* defined(PNG_READ_EXPAND_SUPPORTED) */
  167899. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  167900. void PNGAPI
  167901. png_set_gray_to_rgb(png_structp png_ptr)
  167902. {
  167903. png_debug(1, "in png_set_gray_to_rgb\n");
  167904. png_ptr->transformations |= PNG_GRAY_TO_RGB;
  167905. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167906. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167907. #endif
  167908. }
  167909. #endif
  167910. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  167911. #if defined(PNG_FLOATING_POINT_SUPPORTED)
  167912. void PNGAPI
  167913. png_set_rgb_to_gray(png_structp png_ptr, int error_action, double red,
  167914. double green)
  167915. {
  167916. int red_fixed = (int)((float)red*100000.0 + 0.5);
  167917. int green_fixed = (int)((float)green*100000.0 + 0.5);
  167918. if(png_ptr == NULL) return;
  167919. png_set_rgb_to_gray_fixed(png_ptr, error_action, red_fixed, green_fixed);
  167920. }
  167921. #endif
  167922. void PNGAPI
  167923. png_set_rgb_to_gray_fixed(png_structp png_ptr, int error_action,
  167924. png_fixed_point red, png_fixed_point green)
  167925. {
  167926. png_debug(1, "in png_set_rgb_to_gray\n");
  167927. if(png_ptr == NULL) return;
  167928. switch(error_action)
  167929. {
  167930. case 1: png_ptr->transformations |= PNG_RGB_TO_GRAY;
  167931. break;
  167932. case 2: png_ptr->transformations |= PNG_RGB_TO_GRAY_WARN;
  167933. break;
  167934. case 3: png_ptr->transformations |= PNG_RGB_TO_GRAY_ERR;
  167935. }
  167936. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  167937. #if defined(PNG_READ_EXPAND_SUPPORTED)
  167938. png_ptr->transformations |= PNG_EXPAND;
  167939. #else
  167940. {
  167941. png_warning(png_ptr, "Cannot do RGB_TO_GRAY without EXPAND_SUPPORTED.");
  167942. png_ptr->transformations &= ~PNG_RGB_TO_GRAY;
  167943. }
  167944. #endif
  167945. {
  167946. png_uint_16 red_int, green_int;
  167947. if(red < 0 || green < 0)
  167948. {
  167949. red_int = 6968; /* .212671 * 32768 + .5 */
  167950. green_int = 23434; /* .715160 * 32768 + .5 */
  167951. }
  167952. else if(red + green < 100000L)
  167953. {
  167954. red_int = (png_uint_16)(((png_uint_32)red*32768L)/100000L);
  167955. green_int = (png_uint_16)(((png_uint_32)green*32768L)/100000L);
  167956. }
  167957. else
  167958. {
  167959. png_warning(png_ptr, "ignoring out of range rgb_to_gray coefficients");
  167960. red_int = 6968;
  167961. green_int = 23434;
  167962. }
  167963. png_ptr->rgb_to_gray_red_coeff = red_int;
  167964. png_ptr->rgb_to_gray_green_coeff = green_int;
  167965. png_ptr->rgb_to_gray_blue_coeff = (png_uint_16)(32768-red_int-green_int);
  167966. }
  167967. }
  167968. #endif
  167969. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  167970. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  167971. defined(PNG_LEGACY_SUPPORTED)
  167972. void PNGAPI
  167973. png_set_read_user_transform_fn(png_structp png_ptr, png_user_transform_ptr
  167974. read_user_transform_fn)
  167975. {
  167976. png_debug(1, "in png_set_read_user_transform_fn\n");
  167977. if(png_ptr == NULL) return;
  167978. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
  167979. png_ptr->transformations |= PNG_USER_TRANSFORM;
  167980. png_ptr->read_user_transform_fn = read_user_transform_fn;
  167981. #endif
  167982. #ifdef PNG_LEGACY_SUPPORTED
  167983. if(read_user_transform_fn)
  167984. png_warning(png_ptr,
  167985. "This version of libpng does not support user transforms");
  167986. #endif
  167987. }
  167988. #endif
  167989. void /* PRIVATE */
  167990. png_init_read_transformations(png_structp png_ptr)
  167991. {
  167992. png_debug(1, "in png_init_read_transformations\n");
  167993. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  167994. if(png_ptr != NULL)
  167995. #endif
  167996. {
  167997. #if defined(PNG_READ_BACKGROUND_SUPPORTED) || defined(PNG_READ_SHIFT_SUPPORTED) \
  167998. || defined(PNG_READ_GAMMA_SUPPORTED)
  167999. int color_type = png_ptr->color_type;
  168000. #endif
  168001. #if defined(PNG_READ_EXPAND_SUPPORTED) && defined(PNG_READ_BACKGROUND_SUPPORTED)
  168002. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  168003. if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
  168004. !(color_type & PNG_COLOR_MASK_COLOR))
  168005. {
  168006. png_ptr->mode |= PNG_BACKGROUND_IS_GRAY;
  168007. } else if ((png_ptr->transformations & PNG_BACKGROUND) &&
  168008. !(png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
  168009. (png_ptr->transformations & PNG_GRAY_TO_RGB) &&
  168010. png_ptr->background.red == png_ptr->background.green &&
  168011. png_ptr->background.red == png_ptr->background.blue)
  168012. {
  168013. png_ptr->mode |= PNG_BACKGROUND_IS_GRAY;
  168014. png_ptr->background.gray = png_ptr->background.red;
  168015. }
  168016. #endif
  168017. if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
  168018. (png_ptr->transformations & PNG_EXPAND))
  168019. {
  168020. if (!(color_type & PNG_COLOR_MASK_COLOR)) /* i.e., GRAY or GRAY_ALPHA */
  168021. {
  168022. switch (png_ptr->bit_depth)
  168023. {
  168024. case 1:
  168025. png_ptr->background.gray *= (png_uint_16)0xff;
  168026. png_ptr->background.red = png_ptr->background.green
  168027. = png_ptr->background.blue = png_ptr->background.gray;
  168028. if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
  168029. {
  168030. png_ptr->trans_values.gray *= (png_uint_16)0xff;
  168031. png_ptr->trans_values.red = png_ptr->trans_values.green
  168032. = png_ptr->trans_values.blue = png_ptr->trans_values.gray;
  168033. }
  168034. break;
  168035. case 2:
  168036. png_ptr->background.gray *= (png_uint_16)0x55;
  168037. png_ptr->background.red = png_ptr->background.green
  168038. = png_ptr->background.blue = png_ptr->background.gray;
  168039. if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
  168040. {
  168041. png_ptr->trans_values.gray *= (png_uint_16)0x55;
  168042. png_ptr->trans_values.red = png_ptr->trans_values.green
  168043. = png_ptr->trans_values.blue = png_ptr->trans_values.gray;
  168044. }
  168045. break;
  168046. case 4:
  168047. png_ptr->background.gray *= (png_uint_16)0x11;
  168048. png_ptr->background.red = png_ptr->background.green
  168049. = png_ptr->background.blue = png_ptr->background.gray;
  168050. if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
  168051. {
  168052. png_ptr->trans_values.gray *= (png_uint_16)0x11;
  168053. png_ptr->trans_values.red = png_ptr->trans_values.green
  168054. = png_ptr->trans_values.blue = png_ptr->trans_values.gray;
  168055. }
  168056. break;
  168057. case 8:
  168058. case 16:
  168059. png_ptr->background.red = png_ptr->background.green
  168060. = png_ptr->background.blue = png_ptr->background.gray;
  168061. break;
  168062. }
  168063. }
  168064. else if (color_type == PNG_COLOR_TYPE_PALETTE)
  168065. {
  168066. png_ptr->background.red =
  168067. png_ptr->palette[png_ptr->background.index].red;
  168068. png_ptr->background.green =
  168069. png_ptr->palette[png_ptr->background.index].green;
  168070. png_ptr->background.blue =
  168071. png_ptr->palette[png_ptr->background.index].blue;
  168072. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  168073. if (png_ptr->transformations & PNG_INVERT_ALPHA)
  168074. {
  168075. #if defined(PNG_READ_EXPAND_SUPPORTED)
  168076. if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
  168077. #endif
  168078. {
  168079. int i,istop;
  168080. istop=(int)png_ptr->num_trans;
  168081. for (i=0; i<istop; i++)
  168082. png_ptr->trans[i] = (png_byte)(255 - png_ptr->trans[i]);
  168083. }
  168084. }
  168085. #endif
  168086. }
  168087. }
  168088. #endif
  168089. #if defined(PNG_READ_BACKGROUND_SUPPORTED) && defined(PNG_READ_GAMMA_SUPPORTED)
  168090. png_ptr->background_1 = png_ptr->background;
  168091. #endif
  168092. #if defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
  168093. if ((color_type == PNG_COLOR_TYPE_PALETTE && png_ptr->num_trans != 0)
  168094. && (fabs(png_ptr->screen_gamma * png_ptr->gamma - 1.0)
  168095. < PNG_GAMMA_THRESHOLD))
  168096. {
  168097. int i,k;
  168098. k=0;
  168099. for (i=0; i<png_ptr->num_trans; i++)
  168100. {
  168101. if (png_ptr->trans[i] != 0 && png_ptr->trans[i] != 0xff)
  168102. k=1; /* partial transparency is present */
  168103. }
  168104. if (k == 0)
  168105. png_ptr->transformations &= (~PNG_GAMMA);
  168106. }
  168107. if ((png_ptr->transformations & (PNG_GAMMA | PNG_RGB_TO_GRAY)) &&
  168108. png_ptr->gamma != 0.0)
  168109. {
  168110. png_build_gamma_table(png_ptr);
  168111. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  168112. if (png_ptr->transformations & PNG_BACKGROUND)
  168113. {
  168114. if (color_type == PNG_COLOR_TYPE_PALETTE)
  168115. {
  168116. png_color back, back_1;
  168117. png_colorp palette = png_ptr->palette;
  168118. int num_palette = png_ptr->num_palette;
  168119. int i;
  168120. if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_FILE)
  168121. {
  168122. back.red = png_ptr->gamma_table[png_ptr->background.red];
  168123. back.green = png_ptr->gamma_table[png_ptr->background.green];
  168124. back.blue = png_ptr->gamma_table[png_ptr->background.blue];
  168125. back_1.red = png_ptr->gamma_to_1[png_ptr->background.red];
  168126. back_1.green = png_ptr->gamma_to_1[png_ptr->background.green];
  168127. back_1.blue = png_ptr->gamma_to_1[png_ptr->background.blue];
  168128. }
  168129. else
  168130. {
  168131. double g, gs;
  168132. switch (png_ptr->background_gamma_type)
  168133. {
  168134. case PNG_BACKGROUND_GAMMA_SCREEN:
  168135. g = (png_ptr->screen_gamma);
  168136. gs = 1.0;
  168137. break;
  168138. case PNG_BACKGROUND_GAMMA_FILE:
  168139. g = 1.0 / (png_ptr->gamma);
  168140. gs = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
  168141. break;
  168142. case PNG_BACKGROUND_GAMMA_UNIQUE:
  168143. g = 1.0 / (png_ptr->background_gamma);
  168144. gs = 1.0 / (png_ptr->background_gamma *
  168145. png_ptr->screen_gamma);
  168146. break;
  168147. default:
  168148. g = 1.0; /* back_1 */
  168149. gs = 1.0; /* back */
  168150. }
  168151. if ( fabs(gs - 1.0) < PNG_GAMMA_THRESHOLD)
  168152. {
  168153. back.red = (png_byte)png_ptr->background.red;
  168154. back.green = (png_byte)png_ptr->background.green;
  168155. back.blue = (png_byte)png_ptr->background.blue;
  168156. }
  168157. else
  168158. {
  168159. back.red = (png_byte)(pow(
  168160. (double)png_ptr->background.red/255, gs) * 255.0 + .5);
  168161. back.green = (png_byte)(pow(
  168162. (double)png_ptr->background.green/255, gs) * 255.0 + .5);
  168163. back.blue = (png_byte)(pow(
  168164. (double)png_ptr->background.blue/255, gs) * 255.0 + .5);
  168165. }
  168166. back_1.red = (png_byte)(pow(
  168167. (double)png_ptr->background.red/255, g) * 255.0 + .5);
  168168. back_1.green = (png_byte)(pow(
  168169. (double)png_ptr->background.green/255, g) * 255.0 + .5);
  168170. back_1.blue = (png_byte)(pow(
  168171. (double)png_ptr->background.blue/255, g) * 255.0 + .5);
  168172. }
  168173. for (i = 0; i < num_palette; i++)
  168174. {
  168175. if (i < (int)png_ptr->num_trans && png_ptr->trans[i] != 0xff)
  168176. {
  168177. if (png_ptr->trans[i] == 0)
  168178. {
  168179. palette[i] = back;
  168180. }
  168181. else /* if (png_ptr->trans[i] != 0xff) */
  168182. {
  168183. png_byte v, w;
  168184. v = png_ptr->gamma_to_1[palette[i].red];
  168185. png_composite(w, v, png_ptr->trans[i], back_1.red);
  168186. palette[i].red = png_ptr->gamma_from_1[w];
  168187. v = png_ptr->gamma_to_1[palette[i].green];
  168188. png_composite(w, v, png_ptr->trans[i], back_1.green);
  168189. palette[i].green = png_ptr->gamma_from_1[w];
  168190. v = png_ptr->gamma_to_1[palette[i].blue];
  168191. png_composite(w, v, png_ptr->trans[i], back_1.blue);
  168192. palette[i].blue = png_ptr->gamma_from_1[w];
  168193. }
  168194. }
  168195. else
  168196. {
  168197. palette[i].red = png_ptr->gamma_table[palette[i].red];
  168198. palette[i].green = png_ptr->gamma_table[palette[i].green];
  168199. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  168200. }
  168201. }
  168202. }
  168203. else
  168204. {
  168205. double m = (double)(((png_uint_32)1 << png_ptr->bit_depth) - 1);
  168206. double g = 1.0;
  168207. double gs = 1.0;
  168208. switch (png_ptr->background_gamma_type)
  168209. {
  168210. case PNG_BACKGROUND_GAMMA_SCREEN:
  168211. g = (png_ptr->screen_gamma);
  168212. gs = 1.0;
  168213. break;
  168214. case PNG_BACKGROUND_GAMMA_FILE:
  168215. g = 1.0 / (png_ptr->gamma);
  168216. gs = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
  168217. break;
  168218. case PNG_BACKGROUND_GAMMA_UNIQUE:
  168219. g = 1.0 / (png_ptr->background_gamma);
  168220. gs = 1.0 / (png_ptr->background_gamma *
  168221. png_ptr->screen_gamma);
  168222. break;
  168223. }
  168224. png_ptr->background_1.gray = (png_uint_16)(pow(
  168225. (double)png_ptr->background.gray / m, g) * m + .5);
  168226. png_ptr->background.gray = (png_uint_16)(pow(
  168227. (double)png_ptr->background.gray / m, gs) * m + .5);
  168228. if ((png_ptr->background.red != png_ptr->background.green) ||
  168229. (png_ptr->background.red != png_ptr->background.blue) ||
  168230. (png_ptr->background.red != png_ptr->background.gray))
  168231. {
  168232. png_ptr->background_1.red = (png_uint_16)(pow(
  168233. (double)png_ptr->background.red / m, g) * m + .5);
  168234. png_ptr->background_1.green = (png_uint_16)(pow(
  168235. (double)png_ptr->background.green / m, g) * m + .5);
  168236. png_ptr->background_1.blue = (png_uint_16)(pow(
  168237. (double)png_ptr->background.blue / m, g) * m + .5);
  168238. png_ptr->background.red = (png_uint_16)(pow(
  168239. (double)png_ptr->background.red / m, gs) * m + .5);
  168240. png_ptr->background.green = (png_uint_16)(pow(
  168241. (double)png_ptr->background.green / m, gs) * m + .5);
  168242. png_ptr->background.blue = (png_uint_16)(pow(
  168243. (double)png_ptr->background.blue / m, gs) * m + .5);
  168244. }
  168245. else
  168246. {
  168247. png_ptr->background_1.red = png_ptr->background_1.green
  168248. = png_ptr->background_1.blue = png_ptr->background_1.gray;
  168249. png_ptr->background.red = png_ptr->background.green
  168250. = png_ptr->background.blue = png_ptr->background.gray;
  168251. }
  168252. }
  168253. }
  168254. else
  168255. #endif /* PNG_READ_BACKGROUND_SUPPORTED */
  168256. if (color_type == PNG_COLOR_TYPE_PALETTE)
  168257. {
  168258. png_colorp palette = png_ptr->palette;
  168259. int num_palette = png_ptr->num_palette;
  168260. int i;
  168261. for (i = 0; i < num_palette; i++)
  168262. {
  168263. palette[i].red = png_ptr->gamma_table[palette[i].red];
  168264. palette[i].green = png_ptr->gamma_table[palette[i].green];
  168265. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  168266. }
  168267. }
  168268. }
  168269. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  168270. else
  168271. #endif
  168272. #endif /* PNG_READ_GAMMA_SUPPORTED && PNG_FLOATING_POINT_SUPPORTED */
  168273. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  168274. if ((png_ptr->transformations & PNG_BACKGROUND) &&
  168275. (color_type == PNG_COLOR_TYPE_PALETTE))
  168276. {
  168277. int i;
  168278. int istop = (int)png_ptr->num_trans;
  168279. png_color back;
  168280. png_colorp palette = png_ptr->palette;
  168281. back.red = (png_byte)png_ptr->background.red;
  168282. back.green = (png_byte)png_ptr->background.green;
  168283. back.blue = (png_byte)png_ptr->background.blue;
  168284. for (i = 0; i < istop; i++)
  168285. {
  168286. if (png_ptr->trans[i] == 0)
  168287. {
  168288. palette[i] = back;
  168289. }
  168290. else if (png_ptr->trans[i] != 0xff)
  168291. {
  168292. png_composite(palette[i].red, palette[i].red,
  168293. png_ptr->trans[i], back.red);
  168294. png_composite(palette[i].green, palette[i].green,
  168295. png_ptr->trans[i], back.green);
  168296. png_composite(palette[i].blue, palette[i].blue,
  168297. png_ptr->trans[i], back.blue);
  168298. }
  168299. }
  168300. }
  168301. #endif /* PNG_READ_BACKGROUND_SUPPORTED */
  168302. #if defined(PNG_READ_SHIFT_SUPPORTED)
  168303. if ((png_ptr->transformations & PNG_SHIFT) &&
  168304. (color_type == PNG_COLOR_TYPE_PALETTE))
  168305. {
  168306. png_uint_16 i;
  168307. png_uint_16 istop = png_ptr->num_palette;
  168308. int sr = 8 - png_ptr->sig_bit.red;
  168309. int sg = 8 - png_ptr->sig_bit.green;
  168310. int sb = 8 - png_ptr->sig_bit.blue;
  168311. if (sr < 0 || sr > 8)
  168312. sr = 0;
  168313. if (sg < 0 || sg > 8)
  168314. sg = 0;
  168315. if (sb < 0 || sb > 8)
  168316. sb = 0;
  168317. for (i = 0; i < istop; i++)
  168318. {
  168319. png_ptr->palette[i].red >>= sr;
  168320. png_ptr->palette[i].green >>= sg;
  168321. png_ptr->palette[i].blue >>= sb;
  168322. }
  168323. }
  168324. #endif /* PNG_READ_SHIFT_SUPPORTED */
  168325. }
  168326. #if !defined(PNG_READ_GAMMA_SUPPORTED) && !defined(PNG_READ_SHIFT_SUPPORTED) \
  168327. && !defined(PNG_READ_BACKGROUND_SUPPORTED)
  168328. if(png_ptr)
  168329. return;
  168330. #endif
  168331. }
  168332. void /* PRIVATE */
  168333. png_read_transform_info(png_structp png_ptr, png_infop info_ptr)
  168334. {
  168335. png_debug(1, "in png_read_transform_info\n");
  168336. #if defined(PNG_READ_EXPAND_SUPPORTED)
  168337. if (png_ptr->transformations & PNG_EXPAND)
  168338. {
  168339. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  168340. {
  168341. if (png_ptr->num_trans && (png_ptr->transformations & PNG_EXPAND_tRNS))
  168342. info_ptr->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
  168343. else
  168344. info_ptr->color_type = PNG_COLOR_TYPE_RGB;
  168345. info_ptr->bit_depth = 8;
  168346. info_ptr->num_trans = 0;
  168347. }
  168348. else
  168349. {
  168350. if (png_ptr->num_trans)
  168351. {
  168352. if (png_ptr->transformations & PNG_EXPAND_tRNS)
  168353. info_ptr->color_type |= PNG_COLOR_MASK_ALPHA;
  168354. else
  168355. info_ptr->color_type |= PNG_COLOR_MASK_COLOR;
  168356. }
  168357. if (info_ptr->bit_depth < 8)
  168358. info_ptr->bit_depth = 8;
  168359. info_ptr->num_trans = 0;
  168360. }
  168361. }
  168362. #endif
  168363. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  168364. if (png_ptr->transformations & PNG_BACKGROUND)
  168365. {
  168366. info_ptr->color_type &= ~PNG_COLOR_MASK_ALPHA;
  168367. info_ptr->num_trans = 0;
  168368. info_ptr->background = png_ptr->background;
  168369. }
  168370. #endif
  168371. #if defined(PNG_READ_GAMMA_SUPPORTED)
  168372. if (png_ptr->transformations & PNG_GAMMA)
  168373. {
  168374. #ifdef PNG_FLOATING_POINT_SUPPORTED
  168375. info_ptr->gamma = png_ptr->gamma;
  168376. #endif
  168377. #ifdef PNG_FIXED_POINT_SUPPORTED
  168378. info_ptr->int_gamma = png_ptr->int_gamma;
  168379. #endif
  168380. }
  168381. #endif
  168382. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  168383. if ((png_ptr->transformations & PNG_16_TO_8) && (info_ptr->bit_depth == 16))
  168384. info_ptr->bit_depth = 8;
  168385. #endif
  168386. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  168387. if (png_ptr->transformations & PNG_GRAY_TO_RGB)
  168388. info_ptr->color_type |= PNG_COLOR_MASK_COLOR;
  168389. #endif
  168390. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  168391. if (png_ptr->transformations & PNG_RGB_TO_GRAY)
  168392. info_ptr->color_type &= ~PNG_COLOR_MASK_COLOR;
  168393. #endif
  168394. #if defined(PNG_READ_DITHER_SUPPORTED)
  168395. if (png_ptr->transformations & PNG_DITHER)
  168396. {
  168397. if (((info_ptr->color_type == PNG_COLOR_TYPE_RGB) ||
  168398. (info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)) &&
  168399. png_ptr->palette_lookup && info_ptr->bit_depth == 8)
  168400. {
  168401. info_ptr->color_type = PNG_COLOR_TYPE_PALETTE;
  168402. }
  168403. }
  168404. #endif
  168405. #if defined(PNG_READ_PACK_SUPPORTED)
  168406. if ((png_ptr->transformations & PNG_PACK) && (info_ptr->bit_depth < 8))
  168407. info_ptr->bit_depth = 8;
  168408. #endif
  168409. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  168410. info_ptr->channels = 1;
  168411. else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR)
  168412. info_ptr->channels = 3;
  168413. else
  168414. info_ptr->channels = 1;
  168415. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  168416. if (png_ptr->flags & PNG_FLAG_STRIP_ALPHA)
  168417. info_ptr->color_type &= ~PNG_COLOR_MASK_ALPHA;
  168418. #endif
  168419. if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
  168420. info_ptr->channels++;
  168421. #if defined(PNG_READ_FILLER_SUPPORTED)
  168422. if ((png_ptr->transformations & PNG_FILLER) &&
  168423. ((info_ptr->color_type == PNG_COLOR_TYPE_RGB) ||
  168424. (info_ptr->color_type == PNG_COLOR_TYPE_GRAY)))
  168425. {
  168426. info_ptr->channels++;
  168427. #if !defined(PNG_1_0_X)
  168428. if (png_ptr->transformations & PNG_ADD_ALPHA)
  168429. info_ptr->color_type |= PNG_COLOR_MASK_ALPHA;
  168430. #endif
  168431. }
  168432. #endif
  168433. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED) && \
  168434. defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
  168435. if(png_ptr->transformations & PNG_USER_TRANSFORM)
  168436. {
  168437. if(info_ptr->bit_depth < png_ptr->user_transform_depth)
  168438. info_ptr->bit_depth = png_ptr->user_transform_depth;
  168439. if(info_ptr->channels < png_ptr->user_transform_channels)
  168440. info_ptr->channels = png_ptr->user_transform_channels;
  168441. }
  168442. #endif
  168443. info_ptr->pixel_depth = (png_byte)(info_ptr->channels *
  168444. info_ptr->bit_depth);
  168445. info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth,info_ptr->width);
  168446. #if !defined(PNG_READ_EXPAND_SUPPORTED)
  168447. if(png_ptr)
  168448. return;
  168449. #endif
  168450. }
  168451. void /* PRIVATE */
  168452. png_do_read_transformations(png_structp png_ptr)
  168453. {
  168454. png_debug(1, "in png_do_read_transformations\n");
  168455. if (png_ptr->row_buf == NULL)
  168456. {
  168457. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  168458. char msg[50];
  168459. png_snprintf2(msg, 50,
  168460. "NULL row buffer for row %ld, pass %d", png_ptr->row_number,
  168461. png_ptr->pass);
  168462. png_error(png_ptr, msg);
  168463. #else
  168464. png_error(png_ptr, "NULL row buffer");
  168465. #endif
  168466. }
  168467. #ifdef PNG_WARN_UNINITIALIZED_ROW
  168468. if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
  168469. #if (PNG_WARN_UNINITIALIZED_ROW==1)
  168470. png_error(png_ptr, "Uninitialized row");
  168471. #else
  168472. png_warning(png_ptr, "Uninitialized row");
  168473. #endif
  168474. #endif
  168475. #if defined(PNG_READ_EXPAND_SUPPORTED)
  168476. if (png_ptr->transformations & PNG_EXPAND)
  168477. {
  168478. if (png_ptr->row_info.color_type == PNG_COLOR_TYPE_PALETTE)
  168479. {
  168480. png_do_expand_palette(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168481. png_ptr->palette, png_ptr->trans, png_ptr->num_trans);
  168482. }
  168483. else
  168484. {
  168485. if (png_ptr->num_trans &&
  168486. (png_ptr->transformations & PNG_EXPAND_tRNS))
  168487. png_do_expand(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168488. &(png_ptr->trans_values));
  168489. else
  168490. png_do_expand(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168491. NULL);
  168492. }
  168493. }
  168494. #endif
  168495. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  168496. if (png_ptr->flags & PNG_FLAG_STRIP_ALPHA)
  168497. png_do_strip_filler(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168498. PNG_FLAG_FILLER_AFTER | (png_ptr->flags & PNG_FLAG_STRIP_ALPHA));
  168499. #endif
  168500. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  168501. if (png_ptr->transformations & PNG_RGB_TO_GRAY)
  168502. {
  168503. int rgb_error =
  168504. png_do_rgb_to_gray(png_ptr, &(png_ptr->row_info), png_ptr->row_buf + 1);
  168505. if(rgb_error)
  168506. {
  168507. png_ptr->rgb_to_gray_status=1;
  168508. if((png_ptr->transformations & PNG_RGB_TO_GRAY) ==
  168509. PNG_RGB_TO_GRAY_WARN)
  168510. png_warning(png_ptr, "png_do_rgb_to_gray found nongray pixel");
  168511. if((png_ptr->transformations & PNG_RGB_TO_GRAY) ==
  168512. PNG_RGB_TO_GRAY_ERR)
  168513. png_error(png_ptr, "png_do_rgb_to_gray found nongray pixel");
  168514. }
  168515. }
  168516. #endif
  168517. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  168518. if ((png_ptr->transformations & PNG_GRAY_TO_RGB) &&
  168519. !(png_ptr->mode & PNG_BACKGROUND_IS_GRAY))
  168520. png_do_gray_to_rgb(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168521. #endif
  168522. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  168523. if ((png_ptr->transformations & PNG_BACKGROUND) &&
  168524. ((png_ptr->num_trans != 0 ) ||
  168525. (png_ptr->color_type & PNG_COLOR_MASK_ALPHA)))
  168526. png_do_background(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168527. &(png_ptr->trans_values), &(png_ptr->background)
  168528. #if defined(PNG_READ_GAMMA_SUPPORTED)
  168529. , &(png_ptr->background_1),
  168530. png_ptr->gamma_table, png_ptr->gamma_from_1,
  168531. png_ptr->gamma_to_1, png_ptr->gamma_16_table,
  168532. png_ptr->gamma_16_from_1, png_ptr->gamma_16_to_1,
  168533. png_ptr->gamma_shift
  168534. #endif
  168535. );
  168536. #endif
  168537. #if defined(PNG_READ_GAMMA_SUPPORTED)
  168538. if ((png_ptr->transformations & PNG_GAMMA) &&
  168539. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  168540. !((png_ptr->transformations & PNG_BACKGROUND) &&
  168541. ((png_ptr->num_trans != 0) ||
  168542. (png_ptr->color_type & PNG_COLOR_MASK_ALPHA))) &&
  168543. #endif
  168544. (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE))
  168545. png_do_gamma(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168546. png_ptr->gamma_table, png_ptr->gamma_16_table,
  168547. png_ptr->gamma_shift);
  168548. #endif
  168549. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  168550. if (png_ptr->transformations & PNG_16_TO_8)
  168551. png_do_chop(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168552. #endif
  168553. #if defined(PNG_READ_DITHER_SUPPORTED)
  168554. if (png_ptr->transformations & PNG_DITHER)
  168555. {
  168556. png_do_dither((png_row_infop)&(png_ptr->row_info), png_ptr->row_buf + 1,
  168557. png_ptr->palette_lookup, png_ptr->dither_index);
  168558. if(png_ptr->row_info.rowbytes == (png_uint_32)0)
  168559. png_error(png_ptr, "png_do_dither returned rowbytes=0");
  168560. }
  168561. #endif
  168562. #if defined(PNG_READ_INVERT_SUPPORTED)
  168563. if (png_ptr->transformations & PNG_INVERT_MONO)
  168564. png_do_invert(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168565. #endif
  168566. #if defined(PNG_READ_SHIFT_SUPPORTED)
  168567. if (png_ptr->transformations & PNG_SHIFT)
  168568. png_do_unshift(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168569. &(png_ptr->shift));
  168570. #endif
  168571. #if defined(PNG_READ_PACK_SUPPORTED)
  168572. if (png_ptr->transformations & PNG_PACK)
  168573. png_do_unpack(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168574. #endif
  168575. #if defined(PNG_READ_BGR_SUPPORTED)
  168576. if (png_ptr->transformations & PNG_BGR)
  168577. png_do_bgr(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168578. #endif
  168579. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  168580. if (png_ptr->transformations & PNG_PACKSWAP)
  168581. png_do_packswap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168582. #endif
  168583. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  168584. if ((png_ptr->transformations & PNG_GRAY_TO_RGB) &&
  168585. (png_ptr->mode & PNG_BACKGROUND_IS_GRAY))
  168586. png_do_gray_to_rgb(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168587. #endif
  168588. #if defined(PNG_READ_FILLER_SUPPORTED)
  168589. if (png_ptr->transformations & PNG_FILLER)
  168590. png_do_read_filler(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168591. (png_uint_32)png_ptr->filler, png_ptr->flags);
  168592. #endif
  168593. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  168594. if (png_ptr->transformations & PNG_INVERT_ALPHA)
  168595. png_do_read_invert_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168596. #endif
  168597. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
  168598. if (png_ptr->transformations & PNG_SWAP_ALPHA)
  168599. png_do_read_swap_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168600. #endif
  168601. #if defined(PNG_READ_SWAP_SUPPORTED)
  168602. if (png_ptr->transformations & PNG_SWAP_BYTES)
  168603. png_do_swap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168604. #endif
  168605. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
  168606. if (png_ptr->transformations & PNG_USER_TRANSFORM)
  168607. {
  168608. if(png_ptr->read_user_transform_fn != NULL)
  168609. (*(png_ptr->read_user_transform_fn)) /* user read transform function */
  168610. (png_ptr, /* png_ptr */
  168611. &(png_ptr->row_info), /* row_info: */
  168612. png_ptr->row_buf + 1); /* start of pixel data for row */
  168613. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  168614. if(png_ptr->user_transform_depth)
  168615. png_ptr->row_info.bit_depth = png_ptr->user_transform_depth;
  168616. if(png_ptr->user_transform_channels)
  168617. png_ptr->row_info.channels = png_ptr->user_transform_channels;
  168618. #endif
  168619. png_ptr->row_info.pixel_depth = (png_byte)(png_ptr->row_info.bit_depth *
  168620. png_ptr->row_info.channels);
  168621. png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
  168622. png_ptr->row_info.width);
  168623. }
  168624. #endif
  168625. }
  168626. #if defined(PNG_READ_PACK_SUPPORTED)
  168627. void /* PRIVATE */
  168628. png_do_unpack(png_row_infop row_info, png_bytep row)
  168629. {
  168630. png_debug(1, "in png_do_unpack\n");
  168631. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168632. if (row != NULL && row_info != NULL && row_info->bit_depth < 8)
  168633. #else
  168634. if (row_info->bit_depth < 8)
  168635. #endif
  168636. {
  168637. png_uint_32 i;
  168638. png_uint_32 row_width=row_info->width;
  168639. switch (row_info->bit_depth)
  168640. {
  168641. case 1:
  168642. {
  168643. png_bytep sp = row + (png_size_t)((row_width - 1) >> 3);
  168644. png_bytep dp = row + (png_size_t)row_width - 1;
  168645. png_uint_32 shift = 7 - (int)((row_width + 7) & 0x07);
  168646. for (i = 0; i < row_width; i++)
  168647. {
  168648. *dp = (png_byte)((*sp >> shift) & 0x01);
  168649. if (shift == 7)
  168650. {
  168651. shift = 0;
  168652. sp--;
  168653. }
  168654. else
  168655. shift++;
  168656. dp--;
  168657. }
  168658. break;
  168659. }
  168660. case 2:
  168661. {
  168662. png_bytep sp = row + (png_size_t)((row_width - 1) >> 2);
  168663. png_bytep dp = row + (png_size_t)row_width - 1;
  168664. png_uint_32 shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
  168665. for (i = 0; i < row_width; i++)
  168666. {
  168667. *dp = (png_byte)((*sp >> shift) & 0x03);
  168668. if (shift == 6)
  168669. {
  168670. shift = 0;
  168671. sp--;
  168672. }
  168673. else
  168674. shift += 2;
  168675. dp--;
  168676. }
  168677. break;
  168678. }
  168679. case 4:
  168680. {
  168681. png_bytep sp = row + (png_size_t)((row_width - 1) >> 1);
  168682. png_bytep dp = row + (png_size_t)row_width - 1;
  168683. png_uint_32 shift = (int)((1 - ((row_width + 1) & 0x01)) << 2);
  168684. for (i = 0; i < row_width; i++)
  168685. {
  168686. *dp = (png_byte)((*sp >> shift) & 0x0f);
  168687. if (shift == 4)
  168688. {
  168689. shift = 0;
  168690. sp--;
  168691. }
  168692. else
  168693. shift = 4;
  168694. dp--;
  168695. }
  168696. break;
  168697. }
  168698. }
  168699. row_info->bit_depth = 8;
  168700. row_info->pixel_depth = (png_byte)(8 * row_info->channels);
  168701. row_info->rowbytes = row_width * row_info->channels;
  168702. }
  168703. }
  168704. #endif
  168705. #if defined(PNG_READ_SHIFT_SUPPORTED)
  168706. void /* PRIVATE */
  168707. png_do_unshift(png_row_infop row_info, png_bytep row, png_color_8p sig_bits)
  168708. {
  168709. png_debug(1, "in png_do_unshift\n");
  168710. if (
  168711. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168712. row != NULL && row_info != NULL && sig_bits != NULL &&
  168713. #endif
  168714. row_info->color_type != PNG_COLOR_TYPE_PALETTE)
  168715. {
  168716. int shift[4];
  168717. int channels = 0;
  168718. int c;
  168719. png_uint_16 value = 0;
  168720. png_uint_32 row_width = row_info->width;
  168721. if (row_info->color_type & PNG_COLOR_MASK_COLOR)
  168722. {
  168723. shift[channels++] = row_info->bit_depth - sig_bits->red;
  168724. shift[channels++] = row_info->bit_depth - sig_bits->green;
  168725. shift[channels++] = row_info->bit_depth - sig_bits->blue;
  168726. }
  168727. else
  168728. {
  168729. shift[channels++] = row_info->bit_depth - sig_bits->gray;
  168730. }
  168731. if (row_info->color_type & PNG_COLOR_MASK_ALPHA)
  168732. {
  168733. shift[channels++] = row_info->bit_depth - sig_bits->alpha;
  168734. }
  168735. for (c = 0; c < channels; c++)
  168736. {
  168737. if (shift[c] <= 0)
  168738. shift[c] = 0;
  168739. else
  168740. value = 1;
  168741. }
  168742. if (!value)
  168743. return;
  168744. switch (row_info->bit_depth)
  168745. {
  168746. case 2:
  168747. {
  168748. png_bytep bp;
  168749. png_uint_32 i;
  168750. png_uint_32 istop = row_info->rowbytes;
  168751. for (bp = row, i = 0; i < istop; i++)
  168752. {
  168753. *bp >>= 1;
  168754. *bp++ &= 0x55;
  168755. }
  168756. break;
  168757. }
  168758. case 4:
  168759. {
  168760. png_bytep bp = row;
  168761. png_uint_32 i;
  168762. png_uint_32 istop = row_info->rowbytes;
  168763. png_byte mask = (png_byte)((((int)0xf0 >> shift[0]) & (int)0xf0) |
  168764. (png_byte)((int)0xf >> shift[0]));
  168765. for (i = 0; i < istop; i++)
  168766. {
  168767. *bp >>= shift[0];
  168768. *bp++ &= mask;
  168769. }
  168770. break;
  168771. }
  168772. case 8:
  168773. {
  168774. png_bytep bp = row;
  168775. png_uint_32 i;
  168776. png_uint_32 istop = row_width * channels;
  168777. for (i = 0; i < istop; i++)
  168778. {
  168779. *bp++ >>= shift[i%channels];
  168780. }
  168781. break;
  168782. }
  168783. case 16:
  168784. {
  168785. png_bytep bp = row;
  168786. png_uint_32 i;
  168787. png_uint_32 istop = channels * row_width;
  168788. for (i = 0; i < istop; i++)
  168789. {
  168790. value = (png_uint_16)((*bp << 8) + *(bp + 1));
  168791. value >>= shift[i%channels];
  168792. *bp++ = (png_byte)(value >> 8);
  168793. *bp++ = (png_byte)(value & 0xff);
  168794. }
  168795. break;
  168796. }
  168797. }
  168798. }
  168799. }
  168800. #endif
  168801. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  168802. void /* PRIVATE */
  168803. png_do_chop(png_row_infop row_info, png_bytep row)
  168804. {
  168805. png_debug(1, "in png_do_chop\n");
  168806. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168807. if (row != NULL && row_info != NULL && row_info->bit_depth == 16)
  168808. #else
  168809. if (row_info->bit_depth == 16)
  168810. #endif
  168811. {
  168812. png_bytep sp = row;
  168813. png_bytep dp = row;
  168814. png_uint_32 i;
  168815. png_uint_32 istop = row_info->width * row_info->channels;
  168816. for (i = 0; i<istop; i++, sp += 2, dp++)
  168817. {
  168818. #if defined(PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED)
  168819. *dp = *sp + ((((int)(*(sp + 1)) - *sp) > 128) ? 1 : 0);
  168820. #else
  168821. *dp = *sp;
  168822. #endif
  168823. }
  168824. row_info->bit_depth = 8;
  168825. row_info->pixel_depth = (png_byte)(8 * row_info->channels);
  168826. row_info->rowbytes = row_info->width * row_info->channels;
  168827. }
  168828. }
  168829. #endif
  168830. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
  168831. void /* PRIVATE */
  168832. png_do_read_swap_alpha(png_row_infop row_info, png_bytep row)
  168833. {
  168834. png_debug(1, "in png_do_read_swap_alpha\n");
  168835. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168836. if (row != NULL && row_info != NULL)
  168837. #endif
  168838. {
  168839. png_uint_32 row_width = row_info->width;
  168840. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  168841. {
  168842. if (row_info->bit_depth == 8)
  168843. {
  168844. png_bytep sp = row + row_info->rowbytes;
  168845. png_bytep dp = sp;
  168846. png_byte save;
  168847. png_uint_32 i;
  168848. for (i = 0; i < row_width; i++)
  168849. {
  168850. save = *(--sp);
  168851. *(--dp) = *(--sp);
  168852. *(--dp) = *(--sp);
  168853. *(--dp) = *(--sp);
  168854. *(--dp) = save;
  168855. }
  168856. }
  168857. else
  168858. {
  168859. png_bytep sp = row + row_info->rowbytes;
  168860. png_bytep dp = sp;
  168861. png_byte save[2];
  168862. png_uint_32 i;
  168863. for (i = 0; i < row_width; i++)
  168864. {
  168865. save[0] = *(--sp);
  168866. save[1] = *(--sp);
  168867. *(--dp) = *(--sp);
  168868. *(--dp) = *(--sp);
  168869. *(--dp) = *(--sp);
  168870. *(--dp) = *(--sp);
  168871. *(--dp) = *(--sp);
  168872. *(--dp) = *(--sp);
  168873. *(--dp) = save[0];
  168874. *(--dp) = save[1];
  168875. }
  168876. }
  168877. }
  168878. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  168879. {
  168880. if (row_info->bit_depth == 8)
  168881. {
  168882. png_bytep sp = row + row_info->rowbytes;
  168883. png_bytep dp = sp;
  168884. png_byte save;
  168885. png_uint_32 i;
  168886. for (i = 0; i < row_width; i++)
  168887. {
  168888. save = *(--sp);
  168889. *(--dp) = *(--sp);
  168890. *(--dp) = save;
  168891. }
  168892. }
  168893. else
  168894. {
  168895. png_bytep sp = row + row_info->rowbytes;
  168896. png_bytep dp = sp;
  168897. png_byte save[2];
  168898. png_uint_32 i;
  168899. for (i = 0; i < row_width; i++)
  168900. {
  168901. save[0] = *(--sp);
  168902. save[1] = *(--sp);
  168903. *(--dp) = *(--sp);
  168904. *(--dp) = *(--sp);
  168905. *(--dp) = save[0];
  168906. *(--dp) = save[1];
  168907. }
  168908. }
  168909. }
  168910. }
  168911. }
  168912. #endif
  168913. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  168914. void /* PRIVATE */
  168915. png_do_read_invert_alpha(png_row_infop row_info, png_bytep row)
  168916. {
  168917. png_debug(1, "in png_do_read_invert_alpha\n");
  168918. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168919. if (row != NULL && row_info != NULL)
  168920. #endif
  168921. {
  168922. png_uint_32 row_width = row_info->width;
  168923. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  168924. {
  168925. if (row_info->bit_depth == 8)
  168926. {
  168927. png_bytep sp = row + row_info->rowbytes;
  168928. png_bytep dp = sp;
  168929. png_uint_32 i;
  168930. for (i = 0; i < row_width; i++)
  168931. {
  168932. *(--dp) = (png_byte)(255 - *(--sp));
  168933. sp-=3;
  168934. dp=sp;
  168935. }
  168936. }
  168937. else
  168938. {
  168939. png_bytep sp = row + row_info->rowbytes;
  168940. png_bytep dp = sp;
  168941. png_uint_32 i;
  168942. for (i = 0; i < row_width; i++)
  168943. {
  168944. *(--dp) = (png_byte)(255 - *(--sp));
  168945. *(--dp) = (png_byte)(255 - *(--sp));
  168946. sp-=6;
  168947. dp=sp;
  168948. }
  168949. }
  168950. }
  168951. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  168952. {
  168953. if (row_info->bit_depth == 8)
  168954. {
  168955. png_bytep sp = row + row_info->rowbytes;
  168956. png_bytep dp = sp;
  168957. png_uint_32 i;
  168958. for (i = 0; i < row_width; i++)
  168959. {
  168960. *(--dp) = (png_byte)(255 - *(--sp));
  168961. *(--dp) = *(--sp);
  168962. }
  168963. }
  168964. else
  168965. {
  168966. png_bytep sp = row + row_info->rowbytes;
  168967. png_bytep dp = sp;
  168968. png_uint_32 i;
  168969. for (i = 0; i < row_width; i++)
  168970. {
  168971. *(--dp) = (png_byte)(255 - *(--sp));
  168972. *(--dp) = (png_byte)(255 - *(--sp));
  168973. sp-=2;
  168974. dp=sp;
  168975. }
  168976. }
  168977. }
  168978. }
  168979. }
  168980. #endif
  168981. #if defined(PNG_READ_FILLER_SUPPORTED)
  168982. void /* PRIVATE */
  168983. png_do_read_filler(png_row_infop row_info, png_bytep row,
  168984. png_uint_32 filler, png_uint_32 flags)
  168985. {
  168986. png_uint_32 i;
  168987. png_uint_32 row_width = row_info->width;
  168988. png_byte hi_filler = (png_byte)((filler>>8) & 0xff);
  168989. png_byte lo_filler = (png_byte)(filler & 0xff);
  168990. png_debug(1, "in png_do_read_filler\n");
  168991. if (
  168992. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168993. row != NULL && row_info != NULL &&
  168994. #endif
  168995. row_info->color_type == PNG_COLOR_TYPE_GRAY)
  168996. {
  168997. if(row_info->bit_depth == 8)
  168998. {
  168999. if (flags & PNG_FLAG_FILLER_AFTER)
  169000. {
  169001. png_bytep sp = row + (png_size_t)row_width;
  169002. png_bytep dp = sp + (png_size_t)row_width;
  169003. for (i = 1; i < row_width; i++)
  169004. {
  169005. *(--dp) = lo_filler;
  169006. *(--dp) = *(--sp);
  169007. }
  169008. *(--dp) = lo_filler;
  169009. row_info->channels = 2;
  169010. row_info->pixel_depth = 16;
  169011. row_info->rowbytes = row_width * 2;
  169012. }
  169013. else
  169014. {
  169015. png_bytep sp = row + (png_size_t)row_width;
  169016. png_bytep dp = sp + (png_size_t)row_width;
  169017. for (i = 0; i < row_width; i++)
  169018. {
  169019. *(--dp) = *(--sp);
  169020. *(--dp) = lo_filler;
  169021. }
  169022. row_info->channels = 2;
  169023. row_info->pixel_depth = 16;
  169024. row_info->rowbytes = row_width * 2;
  169025. }
  169026. }
  169027. else if(row_info->bit_depth == 16)
  169028. {
  169029. if (flags & PNG_FLAG_FILLER_AFTER)
  169030. {
  169031. png_bytep sp = row + (png_size_t)row_width * 2;
  169032. png_bytep dp = sp + (png_size_t)row_width * 2;
  169033. for (i = 1; i < row_width; i++)
  169034. {
  169035. *(--dp) = hi_filler;
  169036. *(--dp) = lo_filler;
  169037. *(--dp) = *(--sp);
  169038. *(--dp) = *(--sp);
  169039. }
  169040. *(--dp) = hi_filler;
  169041. *(--dp) = lo_filler;
  169042. row_info->channels = 2;
  169043. row_info->pixel_depth = 32;
  169044. row_info->rowbytes = row_width * 4;
  169045. }
  169046. else
  169047. {
  169048. png_bytep sp = row + (png_size_t)row_width * 2;
  169049. png_bytep dp = sp + (png_size_t)row_width * 2;
  169050. for (i = 0; i < row_width; i++)
  169051. {
  169052. *(--dp) = *(--sp);
  169053. *(--dp) = *(--sp);
  169054. *(--dp) = hi_filler;
  169055. *(--dp) = lo_filler;
  169056. }
  169057. row_info->channels = 2;
  169058. row_info->pixel_depth = 32;
  169059. row_info->rowbytes = row_width * 4;
  169060. }
  169061. }
  169062. } /* COLOR_TYPE == GRAY */
  169063. else if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  169064. {
  169065. if(row_info->bit_depth == 8)
  169066. {
  169067. if (flags & PNG_FLAG_FILLER_AFTER)
  169068. {
  169069. png_bytep sp = row + (png_size_t)row_width * 3;
  169070. png_bytep dp = sp + (png_size_t)row_width;
  169071. for (i = 1; i < row_width; i++)
  169072. {
  169073. *(--dp) = lo_filler;
  169074. *(--dp) = *(--sp);
  169075. *(--dp) = *(--sp);
  169076. *(--dp) = *(--sp);
  169077. }
  169078. *(--dp) = lo_filler;
  169079. row_info->channels = 4;
  169080. row_info->pixel_depth = 32;
  169081. row_info->rowbytes = row_width * 4;
  169082. }
  169083. else
  169084. {
  169085. png_bytep sp = row + (png_size_t)row_width * 3;
  169086. png_bytep dp = sp + (png_size_t)row_width;
  169087. for (i = 0; i < row_width; i++)
  169088. {
  169089. *(--dp) = *(--sp);
  169090. *(--dp) = *(--sp);
  169091. *(--dp) = *(--sp);
  169092. *(--dp) = lo_filler;
  169093. }
  169094. row_info->channels = 4;
  169095. row_info->pixel_depth = 32;
  169096. row_info->rowbytes = row_width * 4;
  169097. }
  169098. }
  169099. else if(row_info->bit_depth == 16)
  169100. {
  169101. if (flags & PNG_FLAG_FILLER_AFTER)
  169102. {
  169103. png_bytep sp = row + (png_size_t)row_width * 6;
  169104. png_bytep dp = sp + (png_size_t)row_width * 2;
  169105. for (i = 1; i < row_width; i++)
  169106. {
  169107. *(--dp) = hi_filler;
  169108. *(--dp) = lo_filler;
  169109. *(--dp) = *(--sp);
  169110. *(--dp) = *(--sp);
  169111. *(--dp) = *(--sp);
  169112. *(--dp) = *(--sp);
  169113. *(--dp) = *(--sp);
  169114. *(--dp) = *(--sp);
  169115. }
  169116. *(--dp) = hi_filler;
  169117. *(--dp) = lo_filler;
  169118. row_info->channels = 4;
  169119. row_info->pixel_depth = 64;
  169120. row_info->rowbytes = row_width * 8;
  169121. }
  169122. else
  169123. {
  169124. png_bytep sp = row + (png_size_t)row_width * 6;
  169125. png_bytep dp = sp + (png_size_t)row_width * 2;
  169126. for (i = 0; i < row_width; i++)
  169127. {
  169128. *(--dp) = *(--sp);
  169129. *(--dp) = *(--sp);
  169130. *(--dp) = *(--sp);
  169131. *(--dp) = *(--sp);
  169132. *(--dp) = *(--sp);
  169133. *(--dp) = *(--sp);
  169134. *(--dp) = hi_filler;
  169135. *(--dp) = lo_filler;
  169136. }
  169137. row_info->channels = 4;
  169138. row_info->pixel_depth = 64;
  169139. row_info->rowbytes = row_width * 8;
  169140. }
  169141. }
  169142. } /* COLOR_TYPE == RGB */
  169143. }
  169144. #endif
  169145. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  169146. void /* PRIVATE */
  169147. png_do_gray_to_rgb(png_row_infop row_info, png_bytep row)
  169148. {
  169149. png_uint_32 i;
  169150. png_uint_32 row_width = row_info->width;
  169151. png_debug(1, "in png_do_gray_to_rgb\n");
  169152. if (row_info->bit_depth >= 8 &&
  169153. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  169154. row != NULL && row_info != NULL &&
  169155. #endif
  169156. !(row_info->color_type & PNG_COLOR_MASK_COLOR))
  169157. {
  169158. if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
  169159. {
  169160. if (row_info->bit_depth == 8)
  169161. {
  169162. png_bytep sp = row + (png_size_t)row_width - 1;
  169163. png_bytep dp = sp + (png_size_t)row_width * 2;
  169164. for (i = 0; i < row_width; i++)
  169165. {
  169166. *(dp--) = *sp;
  169167. *(dp--) = *sp;
  169168. *(dp--) = *(sp--);
  169169. }
  169170. }
  169171. else
  169172. {
  169173. png_bytep sp = row + (png_size_t)row_width * 2 - 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 - 1);
  169179. *(dp--) = *sp;
  169180. *(dp--) = *(sp - 1);
  169181. *(dp--) = *(sp--);
  169182. *(dp--) = *(sp--);
  169183. }
  169184. }
  169185. }
  169186. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  169187. {
  169188. if (row_info->bit_depth == 8)
  169189. {
  169190. png_bytep sp = row + (png_size_t)row_width * 2 - 1;
  169191. png_bytep dp = sp + (png_size_t)row_width * 2;
  169192. for (i = 0; i < row_width; i++)
  169193. {
  169194. *(dp--) = *(sp--);
  169195. *(dp--) = *sp;
  169196. *(dp--) = *sp;
  169197. *(dp--) = *(sp--);
  169198. }
  169199. }
  169200. else
  169201. {
  169202. png_bytep sp = row + (png_size_t)row_width * 4 - 1;
  169203. png_bytep dp = sp + (png_size_t)row_width * 4;
  169204. for (i = 0; i < row_width; i++)
  169205. {
  169206. *(dp--) = *(sp--);
  169207. *(dp--) = *(sp--);
  169208. *(dp--) = *sp;
  169209. *(dp--) = *(sp - 1);
  169210. *(dp--) = *sp;
  169211. *(dp--) = *(sp - 1);
  169212. *(dp--) = *(sp--);
  169213. *(dp--) = *(sp--);
  169214. }
  169215. }
  169216. }
  169217. row_info->channels += (png_byte)2;
  169218. row_info->color_type |= PNG_COLOR_MASK_COLOR;
  169219. row_info->pixel_depth = (png_byte)(row_info->channels *
  169220. row_info->bit_depth);
  169221. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  169222. }
  169223. }
  169224. #endif
  169225. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  169226. int /* PRIVATE */
  169227. png_do_rgb_to_gray(png_structp png_ptr, png_row_infop row_info, png_bytep row)
  169228. {
  169229. png_uint_32 i;
  169230. png_uint_32 row_width = row_info->width;
  169231. int rgb_error = 0;
  169232. png_debug(1, "in png_do_rgb_to_gray\n");
  169233. if (
  169234. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  169235. row != NULL && row_info != NULL &&
  169236. #endif
  169237. (row_info->color_type & PNG_COLOR_MASK_COLOR))
  169238. {
  169239. png_uint_32 rc = png_ptr->rgb_to_gray_red_coeff;
  169240. png_uint_32 gc = png_ptr->rgb_to_gray_green_coeff;
  169241. png_uint_32 bc = png_ptr->rgb_to_gray_blue_coeff;
  169242. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  169243. {
  169244. if (row_info->bit_depth == 8)
  169245. {
  169246. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  169247. if (png_ptr->gamma_from_1 != NULL && png_ptr->gamma_to_1 != NULL)
  169248. {
  169249. png_bytep sp = row;
  169250. png_bytep dp = row;
  169251. for (i = 0; i < row_width; i++)
  169252. {
  169253. png_byte red = png_ptr->gamma_to_1[*(sp++)];
  169254. png_byte green = png_ptr->gamma_to_1[*(sp++)];
  169255. png_byte blue = png_ptr->gamma_to_1[*(sp++)];
  169256. if(red != green || red != blue)
  169257. {
  169258. rgb_error |= 1;
  169259. *(dp++) = png_ptr->gamma_from_1[
  169260. (rc*red+gc*green+bc*blue)>>15];
  169261. }
  169262. else
  169263. *(dp++) = *(sp-1);
  169264. }
  169265. }
  169266. else
  169267. #endif
  169268. {
  169269. png_bytep sp = row;
  169270. png_bytep dp = row;
  169271. for (i = 0; i < row_width; i++)
  169272. {
  169273. png_byte red = *(sp++);
  169274. png_byte green = *(sp++);
  169275. png_byte blue = *(sp++);
  169276. if(red != green || red != blue)
  169277. {
  169278. rgb_error |= 1;
  169279. *(dp++) = (png_byte)((rc*red+gc*green+bc*blue)>>15);
  169280. }
  169281. else
  169282. *(dp++) = *(sp-1);
  169283. }
  169284. }
  169285. }
  169286. else /* RGB bit_depth == 16 */
  169287. {
  169288. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  169289. if (png_ptr->gamma_16_to_1 != NULL &&
  169290. png_ptr->gamma_16_from_1 != NULL)
  169291. {
  169292. png_bytep sp = row;
  169293. png_bytep dp = row;
  169294. for (i = 0; i < row_width; i++)
  169295. {
  169296. png_uint_16 red, green, blue, w;
  169297. red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169298. green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169299. blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169300. if(red == green && red == blue)
  169301. w = red;
  169302. else
  169303. {
  169304. png_uint_16 red_1 = png_ptr->gamma_16_to_1[(red&0xff) >>
  169305. png_ptr->gamma_shift][red>>8];
  169306. png_uint_16 green_1 = png_ptr->gamma_16_to_1[(green&0xff) >>
  169307. png_ptr->gamma_shift][green>>8];
  169308. png_uint_16 blue_1 = png_ptr->gamma_16_to_1[(blue&0xff) >>
  169309. png_ptr->gamma_shift][blue>>8];
  169310. png_uint_16 gray16 = (png_uint_16)((rc*red_1 + gc*green_1
  169311. + bc*blue_1)>>15);
  169312. w = png_ptr->gamma_16_from_1[(gray16&0xff) >>
  169313. png_ptr->gamma_shift][gray16 >> 8];
  169314. rgb_error |= 1;
  169315. }
  169316. *(dp++) = (png_byte)((w>>8) & 0xff);
  169317. *(dp++) = (png_byte)(w & 0xff);
  169318. }
  169319. }
  169320. else
  169321. #endif
  169322. {
  169323. png_bytep sp = row;
  169324. png_bytep dp = row;
  169325. for (i = 0; i < row_width; i++)
  169326. {
  169327. png_uint_16 red, green, blue, gray16;
  169328. red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169329. green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169330. blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169331. if(red != green || red != blue)
  169332. rgb_error |= 1;
  169333. gray16 = (png_uint_16)((rc*red + gc*green + bc*blue)>>15);
  169334. *(dp++) = (png_byte)((gray16>>8) & 0xff);
  169335. *(dp++) = (png_byte)(gray16 & 0xff);
  169336. }
  169337. }
  169338. }
  169339. }
  169340. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  169341. {
  169342. if (row_info->bit_depth == 8)
  169343. {
  169344. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  169345. if (png_ptr->gamma_from_1 != NULL && png_ptr->gamma_to_1 != NULL)
  169346. {
  169347. png_bytep sp = row;
  169348. png_bytep dp = row;
  169349. for (i = 0; i < row_width; i++)
  169350. {
  169351. png_byte red = png_ptr->gamma_to_1[*(sp++)];
  169352. png_byte green = png_ptr->gamma_to_1[*(sp++)];
  169353. png_byte blue = png_ptr->gamma_to_1[*(sp++)];
  169354. if(red != green || red != blue)
  169355. rgb_error |= 1;
  169356. *(dp++) = png_ptr->gamma_from_1
  169357. [(rc*red + gc*green + bc*blue)>>15];
  169358. *(dp++) = *(sp++); /* alpha */
  169359. }
  169360. }
  169361. else
  169362. #endif
  169363. {
  169364. png_bytep sp = row;
  169365. png_bytep dp = row;
  169366. for (i = 0; i < row_width; i++)
  169367. {
  169368. png_byte red = *(sp++);
  169369. png_byte green = *(sp++);
  169370. png_byte blue = *(sp++);
  169371. if(red != green || red != blue)
  169372. rgb_error |= 1;
  169373. *(dp++) = (png_byte)((rc*red + gc*green + bc*blue)>>15);
  169374. *(dp++) = *(sp++); /* alpha */
  169375. }
  169376. }
  169377. }
  169378. else /* RGBA bit_depth == 16 */
  169379. {
  169380. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  169381. if (png_ptr->gamma_16_to_1 != NULL &&
  169382. png_ptr->gamma_16_from_1 != NULL)
  169383. {
  169384. png_bytep sp = row;
  169385. png_bytep dp = row;
  169386. for (i = 0; i < row_width; i++)
  169387. {
  169388. png_uint_16 red, green, blue, w;
  169389. red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169390. green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169391. blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169392. if(red == green && red == blue)
  169393. w = red;
  169394. else
  169395. {
  169396. png_uint_16 red_1 = png_ptr->gamma_16_to_1[(red&0xff) >>
  169397. png_ptr->gamma_shift][red>>8];
  169398. png_uint_16 green_1 = png_ptr->gamma_16_to_1[(green&0xff) >>
  169399. png_ptr->gamma_shift][green>>8];
  169400. png_uint_16 blue_1 = png_ptr->gamma_16_to_1[(blue&0xff) >>
  169401. png_ptr->gamma_shift][blue>>8];
  169402. png_uint_16 gray16 = (png_uint_16)((rc * red_1
  169403. + gc * green_1 + bc * blue_1)>>15);
  169404. w = png_ptr->gamma_16_from_1[(gray16&0xff) >>
  169405. png_ptr->gamma_shift][gray16 >> 8];
  169406. rgb_error |= 1;
  169407. }
  169408. *(dp++) = (png_byte)((w>>8) & 0xff);
  169409. *(dp++) = (png_byte)(w & 0xff);
  169410. *(dp++) = *(sp++); /* alpha */
  169411. *(dp++) = *(sp++);
  169412. }
  169413. }
  169414. else
  169415. #endif
  169416. {
  169417. png_bytep sp = row;
  169418. png_bytep dp = row;
  169419. for (i = 0; i < row_width; i++)
  169420. {
  169421. png_uint_16 red, green, blue, gray16;
  169422. red = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2;
  169423. green = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2;
  169424. blue = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2;
  169425. if(red != green || red != blue)
  169426. rgb_error |= 1;
  169427. gray16 = (png_uint_16)((rc*red + gc*green + bc*blue)>>15);
  169428. *(dp++) = (png_byte)((gray16>>8) & 0xff);
  169429. *(dp++) = (png_byte)(gray16 & 0xff);
  169430. *(dp++) = *(sp++); /* alpha */
  169431. *(dp++) = *(sp++);
  169432. }
  169433. }
  169434. }
  169435. }
  169436. row_info->channels -= (png_byte)2;
  169437. row_info->color_type &= ~PNG_COLOR_MASK_COLOR;
  169438. row_info->pixel_depth = (png_byte)(row_info->channels *
  169439. row_info->bit_depth);
  169440. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  169441. }
  169442. return rgb_error;
  169443. }
  169444. #endif
  169445. void PNGAPI
  169446. png_build_grayscale_palette(int bit_depth, png_colorp palette)
  169447. {
  169448. int num_palette;
  169449. int color_inc;
  169450. int i;
  169451. int v;
  169452. png_debug(1, "in png_do_build_grayscale_palette\n");
  169453. if (palette == NULL)
  169454. return;
  169455. switch (bit_depth)
  169456. {
  169457. case 1:
  169458. num_palette = 2;
  169459. color_inc = 0xff;
  169460. break;
  169461. case 2:
  169462. num_palette = 4;
  169463. color_inc = 0x55;
  169464. break;
  169465. case 4:
  169466. num_palette = 16;
  169467. color_inc = 0x11;
  169468. break;
  169469. case 8:
  169470. num_palette = 256;
  169471. color_inc = 1;
  169472. break;
  169473. default:
  169474. num_palette = 0;
  169475. color_inc = 0;
  169476. break;
  169477. }
  169478. for (i = 0, v = 0; i < num_palette; i++, v += color_inc)
  169479. {
  169480. palette[i].red = (png_byte)v;
  169481. palette[i].green = (png_byte)v;
  169482. palette[i].blue = (png_byte)v;
  169483. }
  169484. }
  169485. #if defined(PNG_READ_DITHER_SUPPORTED) && defined(PNG_CORRECT_PALETTE_SUPPORTED)
  169486. void /* PRIVATE */
  169487. png_correct_palette(png_structp png_ptr, png_colorp palette,
  169488. int num_palette)
  169489. {
  169490. png_debug(1, "in png_correct_palette\n");
  169491. #if defined(PNG_READ_BACKGROUND_SUPPORTED) && \
  169492. defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
  169493. if (png_ptr->transformations & (PNG_GAMMA | PNG_BACKGROUND))
  169494. {
  169495. png_color back, back_1;
  169496. if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_FILE)
  169497. {
  169498. back.red = png_ptr->gamma_table[png_ptr->background.red];
  169499. back.green = png_ptr->gamma_table[png_ptr->background.green];
  169500. back.blue = png_ptr->gamma_table[png_ptr->background.blue];
  169501. back_1.red = png_ptr->gamma_to_1[png_ptr->background.red];
  169502. back_1.green = png_ptr->gamma_to_1[png_ptr->background.green];
  169503. back_1.blue = png_ptr->gamma_to_1[png_ptr->background.blue];
  169504. }
  169505. else
  169506. {
  169507. double g;
  169508. g = 1.0 / (png_ptr->background_gamma * png_ptr->screen_gamma);
  169509. if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_SCREEN ||
  169510. fabs(g - 1.0) < PNG_GAMMA_THRESHOLD)
  169511. {
  169512. back.red = png_ptr->background.red;
  169513. back.green = png_ptr->background.green;
  169514. back.blue = png_ptr->background.blue;
  169515. }
  169516. else
  169517. {
  169518. back.red =
  169519. (png_byte)(pow((double)png_ptr->background.red/255, g) *
  169520. 255.0 + 0.5);
  169521. back.green =
  169522. (png_byte)(pow((double)png_ptr->background.green/255, g) *
  169523. 255.0 + 0.5);
  169524. back.blue =
  169525. (png_byte)(pow((double)png_ptr->background.blue/255, g) *
  169526. 255.0 + 0.5);
  169527. }
  169528. g = 1.0 / png_ptr->background_gamma;
  169529. back_1.red =
  169530. (png_byte)(pow((double)png_ptr->background.red/255, g) *
  169531. 255.0 + 0.5);
  169532. back_1.green =
  169533. (png_byte)(pow((double)png_ptr->background.green/255, g) *
  169534. 255.0 + 0.5);
  169535. back_1.blue =
  169536. (png_byte)(pow((double)png_ptr->background.blue/255, g) *
  169537. 255.0 + 0.5);
  169538. }
  169539. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  169540. {
  169541. png_uint_32 i;
  169542. for (i = 0; i < (png_uint_32)num_palette; i++)
  169543. {
  169544. if (i < png_ptr->num_trans && png_ptr->trans[i] == 0)
  169545. {
  169546. palette[i] = back;
  169547. }
  169548. else if (i < png_ptr->num_trans && png_ptr->trans[i] != 0xff)
  169549. {
  169550. png_byte v, w;
  169551. v = png_ptr->gamma_to_1[png_ptr->palette[i].red];
  169552. png_composite(w, v, png_ptr->trans[i], back_1.red);
  169553. palette[i].red = png_ptr->gamma_from_1[w];
  169554. v = png_ptr->gamma_to_1[png_ptr->palette[i].green];
  169555. png_composite(w, v, png_ptr->trans[i], back_1.green);
  169556. palette[i].green = png_ptr->gamma_from_1[w];
  169557. v = png_ptr->gamma_to_1[png_ptr->palette[i].blue];
  169558. png_composite(w, v, png_ptr->trans[i], back_1.blue);
  169559. palette[i].blue = png_ptr->gamma_from_1[w];
  169560. }
  169561. else
  169562. {
  169563. palette[i].red = png_ptr->gamma_table[palette[i].red];
  169564. palette[i].green = png_ptr->gamma_table[palette[i].green];
  169565. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  169566. }
  169567. }
  169568. }
  169569. else
  169570. {
  169571. int i;
  169572. for (i = 0; i < num_palette; i++)
  169573. {
  169574. if (palette[i].red == (png_byte)png_ptr->trans_values.gray)
  169575. {
  169576. palette[i] = back;
  169577. }
  169578. else
  169579. {
  169580. palette[i].red = png_ptr->gamma_table[palette[i].red];
  169581. palette[i].green = png_ptr->gamma_table[palette[i].green];
  169582. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  169583. }
  169584. }
  169585. }
  169586. }
  169587. else
  169588. #endif
  169589. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169590. if (png_ptr->transformations & PNG_GAMMA)
  169591. {
  169592. int i;
  169593. for (i = 0; i < num_palette; i++)
  169594. {
  169595. palette[i].red = png_ptr->gamma_table[palette[i].red];
  169596. palette[i].green = png_ptr->gamma_table[palette[i].green];
  169597. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  169598. }
  169599. }
  169600. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  169601. else
  169602. #endif
  169603. #endif
  169604. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  169605. if (png_ptr->transformations & PNG_BACKGROUND)
  169606. {
  169607. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  169608. {
  169609. png_color back;
  169610. back.red = (png_byte)png_ptr->background.red;
  169611. back.green = (png_byte)png_ptr->background.green;
  169612. back.blue = (png_byte)png_ptr->background.blue;
  169613. for (i = 0; i < (int)png_ptr->num_trans; i++)
  169614. {
  169615. if (png_ptr->trans[i] == 0)
  169616. {
  169617. palette[i].red = back.red;
  169618. palette[i].green = back.green;
  169619. palette[i].blue = back.blue;
  169620. }
  169621. else if (png_ptr->trans[i] != 0xff)
  169622. {
  169623. png_composite(palette[i].red, png_ptr->palette[i].red,
  169624. png_ptr->trans[i], back.red);
  169625. png_composite(palette[i].green, png_ptr->palette[i].green,
  169626. png_ptr->trans[i], back.green);
  169627. png_composite(palette[i].blue, png_ptr->palette[i].blue,
  169628. png_ptr->trans[i], back.blue);
  169629. }
  169630. }
  169631. }
  169632. else /* assume grayscale palette (what else could it be?) */
  169633. {
  169634. int i;
  169635. for (i = 0; i < num_palette; i++)
  169636. {
  169637. if (i == (png_byte)png_ptr->trans_values.gray)
  169638. {
  169639. palette[i].red = (png_byte)png_ptr->background.red;
  169640. palette[i].green = (png_byte)png_ptr->background.green;
  169641. palette[i].blue = (png_byte)png_ptr->background.blue;
  169642. }
  169643. }
  169644. }
  169645. }
  169646. #endif
  169647. }
  169648. #endif
  169649. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  169650. void /* PRIVATE */
  169651. png_do_background(png_row_infop row_info, png_bytep row,
  169652. png_color_16p trans_values, png_color_16p background
  169653. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169654. , png_color_16p background_1,
  169655. png_bytep gamma_table, png_bytep gamma_from_1, png_bytep gamma_to_1,
  169656. png_uint_16pp gamma_16, png_uint_16pp gamma_16_from_1,
  169657. png_uint_16pp gamma_16_to_1, int gamma_shift
  169658. #endif
  169659. )
  169660. {
  169661. png_bytep sp, dp;
  169662. png_uint_32 i;
  169663. png_uint_32 row_width=row_info->width;
  169664. int shift;
  169665. png_debug(1, "in png_do_background\n");
  169666. if (background != NULL &&
  169667. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  169668. row != NULL && row_info != NULL &&
  169669. #endif
  169670. (!(row_info->color_type & PNG_COLOR_MASK_ALPHA) ||
  169671. (row_info->color_type != PNG_COLOR_TYPE_PALETTE && trans_values)))
  169672. {
  169673. switch (row_info->color_type)
  169674. {
  169675. case PNG_COLOR_TYPE_GRAY:
  169676. {
  169677. switch (row_info->bit_depth)
  169678. {
  169679. case 1:
  169680. {
  169681. sp = row;
  169682. shift = 7;
  169683. for (i = 0; i < row_width; i++)
  169684. {
  169685. if ((png_uint_16)((*sp >> shift) & 0x01)
  169686. == trans_values->gray)
  169687. {
  169688. *sp &= (png_byte)((0x7f7f >> (7 - shift)) & 0xff);
  169689. *sp |= (png_byte)(background->gray << shift);
  169690. }
  169691. if (!shift)
  169692. {
  169693. shift = 7;
  169694. sp++;
  169695. }
  169696. else
  169697. shift--;
  169698. }
  169699. break;
  169700. }
  169701. case 2:
  169702. {
  169703. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169704. if (gamma_table != NULL)
  169705. {
  169706. sp = row;
  169707. shift = 6;
  169708. for (i = 0; i < row_width; i++)
  169709. {
  169710. if ((png_uint_16)((*sp >> shift) & 0x03)
  169711. == trans_values->gray)
  169712. {
  169713. *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
  169714. *sp |= (png_byte)(background->gray << shift);
  169715. }
  169716. else
  169717. {
  169718. png_byte p = (png_byte)((*sp >> shift) & 0x03);
  169719. png_byte g = (png_byte)((gamma_table [p | (p << 2) |
  169720. (p << 4) | (p << 6)] >> 6) & 0x03);
  169721. *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
  169722. *sp |= (png_byte)(g << shift);
  169723. }
  169724. if (!shift)
  169725. {
  169726. shift = 6;
  169727. sp++;
  169728. }
  169729. else
  169730. shift -= 2;
  169731. }
  169732. }
  169733. else
  169734. #endif
  169735. {
  169736. sp = row;
  169737. shift = 6;
  169738. for (i = 0; i < row_width; i++)
  169739. {
  169740. if ((png_uint_16)((*sp >> shift) & 0x03)
  169741. == trans_values->gray)
  169742. {
  169743. *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
  169744. *sp |= (png_byte)(background->gray << shift);
  169745. }
  169746. if (!shift)
  169747. {
  169748. shift = 6;
  169749. sp++;
  169750. }
  169751. else
  169752. shift -= 2;
  169753. }
  169754. }
  169755. break;
  169756. }
  169757. case 4:
  169758. {
  169759. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169760. if (gamma_table != NULL)
  169761. {
  169762. sp = row;
  169763. shift = 4;
  169764. for (i = 0; i < row_width; i++)
  169765. {
  169766. if ((png_uint_16)((*sp >> shift) & 0x0f)
  169767. == trans_values->gray)
  169768. {
  169769. *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
  169770. *sp |= (png_byte)(background->gray << shift);
  169771. }
  169772. else
  169773. {
  169774. png_byte p = (png_byte)((*sp >> shift) & 0x0f);
  169775. png_byte g = (png_byte)((gamma_table[p |
  169776. (p << 4)] >> 4) & 0x0f);
  169777. *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
  169778. *sp |= (png_byte)(g << shift);
  169779. }
  169780. if (!shift)
  169781. {
  169782. shift = 4;
  169783. sp++;
  169784. }
  169785. else
  169786. shift -= 4;
  169787. }
  169788. }
  169789. else
  169790. #endif
  169791. {
  169792. sp = row;
  169793. shift = 4;
  169794. for (i = 0; i < row_width; i++)
  169795. {
  169796. if ((png_uint_16)((*sp >> shift) & 0x0f)
  169797. == trans_values->gray)
  169798. {
  169799. *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
  169800. *sp |= (png_byte)(background->gray << shift);
  169801. }
  169802. if (!shift)
  169803. {
  169804. shift = 4;
  169805. sp++;
  169806. }
  169807. else
  169808. shift -= 4;
  169809. }
  169810. }
  169811. break;
  169812. }
  169813. case 8:
  169814. {
  169815. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169816. if (gamma_table != NULL)
  169817. {
  169818. sp = row;
  169819. for (i = 0; i < row_width; i++, sp++)
  169820. {
  169821. if (*sp == trans_values->gray)
  169822. {
  169823. *sp = (png_byte)background->gray;
  169824. }
  169825. else
  169826. {
  169827. *sp = gamma_table[*sp];
  169828. }
  169829. }
  169830. }
  169831. else
  169832. #endif
  169833. {
  169834. sp = row;
  169835. for (i = 0; i < row_width; i++, sp++)
  169836. {
  169837. if (*sp == trans_values->gray)
  169838. {
  169839. *sp = (png_byte)background->gray;
  169840. }
  169841. }
  169842. }
  169843. break;
  169844. }
  169845. case 16:
  169846. {
  169847. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169848. if (gamma_16 != NULL)
  169849. {
  169850. sp = row;
  169851. for (i = 0; i < row_width; i++, sp += 2)
  169852. {
  169853. png_uint_16 v;
  169854. v = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  169855. if (v == trans_values->gray)
  169856. {
  169857. *sp = (png_byte)((background->gray >> 8) & 0xff);
  169858. *(sp + 1) = (png_byte)(background->gray & 0xff);
  169859. }
  169860. else
  169861. {
  169862. v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
  169863. *sp = (png_byte)((v >> 8) & 0xff);
  169864. *(sp + 1) = (png_byte)(v & 0xff);
  169865. }
  169866. }
  169867. }
  169868. else
  169869. #endif
  169870. {
  169871. sp = row;
  169872. for (i = 0; i < row_width; i++, sp += 2)
  169873. {
  169874. png_uint_16 v;
  169875. v = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  169876. if (v == trans_values->gray)
  169877. {
  169878. *sp = (png_byte)((background->gray >> 8) & 0xff);
  169879. *(sp + 1) = (png_byte)(background->gray & 0xff);
  169880. }
  169881. }
  169882. }
  169883. break;
  169884. }
  169885. }
  169886. break;
  169887. }
  169888. case PNG_COLOR_TYPE_RGB:
  169889. {
  169890. if (row_info->bit_depth == 8)
  169891. {
  169892. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169893. if (gamma_table != NULL)
  169894. {
  169895. sp = row;
  169896. for (i = 0; i < row_width; i++, sp += 3)
  169897. {
  169898. if (*sp == trans_values->red &&
  169899. *(sp + 1) == trans_values->green &&
  169900. *(sp + 2) == trans_values->blue)
  169901. {
  169902. *sp = (png_byte)background->red;
  169903. *(sp + 1) = (png_byte)background->green;
  169904. *(sp + 2) = (png_byte)background->blue;
  169905. }
  169906. else
  169907. {
  169908. *sp = gamma_table[*sp];
  169909. *(sp + 1) = gamma_table[*(sp + 1)];
  169910. *(sp + 2) = gamma_table[*(sp + 2)];
  169911. }
  169912. }
  169913. }
  169914. else
  169915. #endif
  169916. {
  169917. sp = row;
  169918. for (i = 0; i < row_width; i++, sp += 3)
  169919. {
  169920. if (*sp == trans_values->red &&
  169921. *(sp + 1) == trans_values->green &&
  169922. *(sp + 2) == trans_values->blue)
  169923. {
  169924. *sp = (png_byte)background->red;
  169925. *(sp + 1) = (png_byte)background->green;
  169926. *(sp + 2) = (png_byte)background->blue;
  169927. }
  169928. }
  169929. }
  169930. }
  169931. else /* if (row_info->bit_depth == 16) */
  169932. {
  169933. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169934. if (gamma_16 != NULL)
  169935. {
  169936. sp = row;
  169937. for (i = 0; i < row_width; i++, sp += 6)
  169938. {
  169939. png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  169940. png_uint_16 g = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
  169941. png_uint_16 b = (png_uint_16)(((*(sp+4)) << 8) + *(sp+5));
  169942. if (r == trans_values->red && g == trans_values->green &&
  169943. b == trans_values->blue)
  169944. {
  169945. *sp = (png_byte)((background->red >> 8) & 0xff);
  169946. *(sp + 1) = (png_byte)(background->red & 0xff);
  169947. *(sp + 2) = (png_byte)((background->green >> 8) & 0xff);
  169948. *(sp + 3) = (png_byte)(background->green & 0xff);
  169949. *(sp + 4) = (png_byte)((background->blue >> 8) & 0xff);
  169950. *(sp + 5) = (png_byte)(background->blue & 0xff);
  169951. }
  169952. else
  169953. {
  169954. png_uint_16 v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
  169955. *sp = (png_byte)((v >> 8) & 0xff);
  169956. *(sp + 1) = (png_byte)(v & 0xff);
  169957. v = gamma_16[*(sp + 3) >> gamma_shift][*(sp + 2)];
  169958. *(sp + 2) = (png_byte)((v >> 8) & 0xff);
  169959. *(sp + 3) = (png_byte)(v & 0xff);
  169960. v = gamma_16[*(sp + 5) >> gamma_shift][*(sp + 4)];
  169961. *(sp + 4) = (png_byte)((v >> 8) & 0xff);
  169962. *(sp + 5) = (png_byte)(v & 0xff);
  169963. }
  169964. }
  169965. }
  169966. else
  169967. #endif
  169968. {
  169969. sp = row;
  169970. for (i = 0; i < row_width; i++, sp += 6)
  169971. {
  169972. png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp+1));
  169973. png_uint_16 g = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
  169974. png_uint_16 b = (png_uint_16)(((*(sp+4)) << 8) + *(sp+5));
  169975. if (r == trans_values->red && g == trans_values->green &&
  169976. b == trans_values->blue)
  169977. {
  169978. *sp = (png_byte)((background->red >> 8) & 0xff);
  169979. *(sp + 1) = (png_byte)(background->red & 0xff);
  169980. *(sp + 2) = (png_byte)((background->green >> 8) & 0xff);
  169981. *(sp + 3) = (png_byte)(background->green & 0xff);
  169982. *(sp + 4) = (png_byte)((background->blue >> 8) & 0xff);
  169983. *(sp + 5) = (png_byte)(background->blue & 0xff);
  169984. }
  169985. }
  169986. }
  169987. }
  169988. break;
  169989. }
  169990. case PNG_COLOR_TYPE_GRAY_ALPHA:
  169991. {
  169992. if (row_info->bit_depth == 8)
  169993. {
  169994. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169995. if (gamma_to_1 != NULL && gamma_from_1 != NULL &&
  169996. gamma_table != NULL)
  169997. {
  169998. sp = row;
  169999. dp = row;
  170000. for (i = 0; i < row_width; i++, sp += 2, dp++)
  170001. {
  170002. png_uint_16 a = *(sp + 1);
  170003. if (a == 0xff)
  170004. {
  170005. *dp = gamma_table[*sp];
  170006. }
  170007. else if (a == 0)
  170008. {
  170009. *dp = (png_byte)background->gray;
  170010. }
  170011. else
  170012. {
  170013. png_byte v, w;
  170014. v = gamma_to_1[*sp];
  170015. png_composite(w, v, a, background_1->gray);
  170016. *dp = gamma_from_1[w];
  170017. }
  170018. }
  170019. }
  170020. else
  170021. #endif
  170022. {
  170023. sp = row;
  170024. dp = row;
  170025. for (i = 0; i < row_width; i++, sp += 2, dp++)
  170026. {
  170027. png_byte a = *(sp + 1);
  170028. if (a == 0xff)
  170029. {
  170030. *dp = *sp;
  170031. }
  170032. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170033. else if (a == 0)
  170034. {
  170035. *dp = (png_byte)background->gray;
  170036. }
  170037. else
  170038. {
  170039. png_composite(*dp, *sp, a, background_1->gray);
  170040. }
  170041. #else
  170042. *dp = (png_byte)background->gray;
  170043. #endif
  170044. }
  170045. }
  170046. }
  170047. else /* if (png_ptr->bit_depth == 16) */
  170048. {
  170049. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170050. if (gamma_16 != NULL && gamma_16_from_1 != NULL &&
  170051. gamma_16_to_1 != NULL)
  170052. {
  170053. sp = row;
  170054. dp = row;
  170055. for (i = 0; i < row_width; i++, sp += 4, dp += 2)
  170056. {
  170057. png_uint_16 a = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
  170058. if (a == (png_uint_16)0xffff)
  170059. {
  170060. png_uint_16 v;
  170061. v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
  170062. *dp = (png_byte)((v >> 8) & 0xff);
  170063. *(dp + 1) = (png_byte)(v & 0xff);
  170064. }
  170065. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170066. else if (a == 0)
  170067. #else
  170068. else
  170069. #endif
  170070. {
  170071. *dp = (png_byte)((background->gray >> 8) & 0xff);
  170072. *(dp + 1) = (png_byte)(background->gray & 0xff);
  170073. }
  170074. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170075. else
  170076. {
  170077. png_uint_16 g, v, w;
  170078. g = gamma_16_to_1[*(sp + 1) >> gamma_shift][*sp];
  170079. png_composite_16(v, g, a, background_1->gray);
  170080. w = gamma_16_from_1[(v&0xff) >> gamma_shift][v >> 8];
  170081. *dp = (png_byte)((w >> 8) & 0xff);
  170082. *(dp + 1) = (png_byte)(w & 0xff);
  170083. }
  170084. #endif
  170085. }
  170086. }
  170087. else
  170088. #endif
  170089. {
  170090. sp = row;
  170091. dp = row;
  170092. for (i = 0; i < row_width; i++, sp += 4, dp += 2)
  170093. {
  170094. png_uint_16 a = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
  170095. if (a == (png_uint_16)0xffff)
  170096. {
  170097. png_memcpy(dp, sp, 2);
  170098. }
  170099. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170100. else if (a == 0)
  170101. #else
  170102. else
  170103. #endif
  170104. {
  170105. *dp = (png_byte)((background->gray >> 8) & 0xff);
  170106. *(dp + 1) = (png_byte)(background->gray & 0xff);
  170107. }
  170108. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170109. else
  170110. {
  170111. png_uint_16 g, v;
  170112. g = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  170113. png_composite_16(v, g, a, background_1->gray);
  170114. *dp = (png_byte)((v >> 8) & 0xff);
  170115. *(dp + 1) = (png_byte)(v & 0xff);
  170116. }
  170117. #endif
  170118. }
  170119. }
  170120. }
  170121. break;
  170122. }
  170123. case PNG_COLOR_TYPE_RGB_ALPHA:
  170124. {
  170125. if (row_info->bit_depth == 8)
  170126. {
  170127. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170128. if (gamma_to_1 != NULL && gamma_from_1 != NULL &&
  170129. gamma_table != NULL)
  170130. {
  170131. sp = row;
  170132. dp = row;
  170133. for (i = 0; i < row_width; i++, sp += 4, dp += 3)
  170134. {
  170135. png_byte a = *(sp + 3);
  170136. if (a == 0xff)
  170137. {
  170138. *dp = gamma_table[*sp];
  170139. *(dp + 1) = gamma_table[*(sp + 1)];
  170140. *(dp + 2) = gamma_table[*(sp + 2)];
  170141. }
  170142. else if (a == 0)
  170143. {
  170144. *dp = (png_byte)background->red;
  170145. *(dp + 1) = (png_byte)background->green;
  170146. *(dp + 2) = (png_byte)background->blue;
  170147. }
  170148. else
  170149. {
  170150. png_byte v, w;
  170151. v = gamma_to_1[*sp];
  170152. png_composite(w, v, a, background_1->red);
  170153. *dp = gamma_from_1[w];
  170154. v = gamma_to_1[*(sp + 1)];
  170155. png_composite(w, v, a, background_1->green);
  170156. *(dp + 1) = gamma_from_1[w];
  170157. v = gamma_to_1[*(sp + 2)];
  170158. png_composite(w, v, a, background_1->blue);
  170159. *(dp + 2) = gamma_from_1[w];
  170160. }
  170161. }
  170162. }
  170163. else
  170164. #endif
  170165. {
  170166. sp = row;
  170167. dp = row;
  170168. for (i = 0; i < row_width; i++, sp += 4, dp += 3)
  170169. {
  170170. png_byte a = *(sp + 3);
  170171. if (a == 0xff)
  170172. {
  170173. *dp = *sp;
  170174. *(dp + 1) = *(sp + 1);
  170175. *(dp + 2) = *(sp + 2);
  170176. }
  170177. else if (a == 0)
  170178. {
  170179. *dp = (png_byte)background->red;
  170180. *(dp + 1) = (png_byte)background->green;
  170181. *(dp + 2) = (png_byte)background->blue;
  170182. }
  170183. else
  170184. {
  170185. png_composite(*dp, *sp, a, background->red);
  170186. png_composite(*(dp + 1), *(sp + 1), a,
  170187. background->green);
  170188. png_composite(*(dp + 2), *(sp + 2), a,
  170189. background->blue);
  170190. }
  170191. }
  170192. }
  170193. }
  170194. else /* if (row_info->bit_depth == 16) */
  170195. {
  170196. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170197. if (gamma_16 != NULL && gamma_16_from_1 != NULL &&
  170198. gamma_16_to_1 != NULL)
  170199. {
  170200. sp = row;
  170201. dp = row;
  170202. for (i = 0; i < row_width; i++, sp += 8, dp += 6)
  170203. {
  170204. png_uint_16 a = (png_uint_16)(((png_uint_16)(*(sp + 6))
  170205. << 8) + (png_uint_16)(*(sp + 7)));
  170206. if (a == (png_uint_16)0xffff)
  170207. {
  170208. png_uint_16 v;
  170209. v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
  170210. *dp = (png_byte)((v >> 8) & 0xff);
  170211. *(dp + 1) = (png_byte)(v & 0xff);
  170212. v = gamma_16[*(sp + 3) >> gamma_shift][*(sp + 2)];
  170213. *(dp + 2) = (png_byte)((v >> 8) & 0xff);
  170214. *(dp + 3) = (png_byte)(v & 0xff);
  170215. v = gamma_16[*(sp + 5) >> gamma_shift][*(sp + 4)];
  170216. *(dp + 4) = (png_byte)((v >> 8) & 0xff);
  170217. *(dp + 5) = (png_byte)(v & 0xff);
  170218. }
  170219. else if (a == 0)
  170220. {
  170221. *dp = (png_byte)((background->red >> 8) & 0xff);
  170222. *(dp + 1) = (png_byte)(background->red & 0xff);
  170223. *(dp + 2) = (png_byte)((background->green >> 8) & 0xff);
  170224. *(dp + 3) = (png_byte)(background->green & 0xff);
  170225. *(dp + 4) = (png_byte)((background->blue >> 8) & 0xff);
  170226. *(dp + 5) = (png_byte)(background->blue & 0xff);
  170227. }
  170228. else
  170229. {
  170230. png_uint_16 v, w, x;
  170231. v = gamma_16_to_1[*(sp + 1) >> gamma_shift][*sp];
  170232. png_composite_16(w, v, a, background_1->red);
  170233. x = gamma_16_from_1[((w&0xff) >> gamma_shift)][w >> 8];
  170234. *dp = (png_byte)((x >> 8) & 0xff);
  170235. *(dp + 1) = (png_byte)(x & 0xff);
  170236. v = gamma_16_to_1[*(sp + 3) >> gamma_shift][*(sp + 2)];
  170237. png_composite_16(w, v, a, background_1->green);
  170238. x = gamma_16_from_1[((w&0xff) >> gamma_shift)][w >> 8];
  170239. *(dp + 2) = (png_byte)((x >> 8) & 0xff);
  170240. *(dp + 3) = (png_byte)(x & 0xff);
  170241. v = gamma_16_to_1[*(sp + 5) >> gamma_shift][*(sp + 4)];
  170242. png_composite_16(w, v, a, background_1->blue);
  170243. x = gamma_16_from_1[(w & 0xff) >> gamma_shift][w >> 8];
  170244. *(dp + 4) = (png_byte)((x >> 8) & 0xff);
  170245. *(dp + 5) = (png_byte)(x & 0xff);
  170246. }
  170247. }
  170248. }
  170249. else
  170250. #endif
  170251. {
  170252. sp = row;
  170253. dp = row;
  170254. for (i = 0; i < row_width; i++, sp += 8, dp += 6)
  170255. {
  170256. png_uint_16 a = (png_uint_16)(((png_uint_16)(*(sp + 6))
  170257. << 8) + (png_uint_16)(*(sp + 7)));
  170258. if (a == (png_uint_16)0xffff)
  170259. {
  170260. png_memcpy(dp, sp, 6);
  170261. }
  170262. else if (a == 0)
  170263. {
  170264. *dp = (png_byte)((background->red >> 8) & 0xff);
  170265. *(dp + 1) = (png_byte)(background->red & 0xff);
  170266. *(dp + 2) = (png_byte)((background->green >> 8) & 0xff);
  170267. *(dp + 3) = (png_byte)(background->green & 0xff);
  170268. *(dp + 4) = (png_byte)((background->blue >> 8) & 0xff);
  170269. *(dp + 5) = (png_byte)(background->blue & 0xff);
  170270. }
  170271. else
  170272. {
  170273. png_uint_16 v;
  170274. png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  170275. png_uint_16 g = (png_uint_16)(((*(sp + 2)) << 8)
  170276. + *(sp + 3));
  170277. png_uint_16 b = (png_uint_16)(((*(sp + 4)) << 8)
  170278. + *(sp + 5));
  170279. png_composite_16(v, r, a, background->red);
  170280. *dp = (png_byte)((v >> 8) & 0xff);
  170281. *(dp + 1) = (png_byte)(v & 0xff);
  170282. png_composite_16(v, g, a, background->green);
  170283. *(dp + 2) = (png_byte)((v >> 8) & 0xff);
  170284. *(dp + 3) = (png_byte)(v & 0xff);
  170285. png_composite_16(v, b, a, background->blue);
  170286. *(dp + 4) = (png_byte)((v >> 8) & 0xff);
  170287. *(dp + 5) = (png_byte)(v & 0xff);
  170288. }
  170289. }
  170290. }
  170291. }
  170292. break;
  170293. }
  170294. }
  170295. if (row_info->color_type & PNG_COLOR_MASK_ALPHA)
  170296. {
  170297. row_info->color_type &= ~PNG_COLOR_MASK_ALPHA;
  170298. row_info->channels--;
  170299. row_info->pixel_depth = (png_byte)(row_info->channels *
  170300. row_info->bit_depth);
  170301. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  170302. }
  170303. }
  170304. }
  170305. #endif
  170306. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170307. void /* PRIVATE */
  170308. png_do_gamma(png_row_infop row_info, png_bytep row,
  170309. png_bytep gamma_table, png_uint_16pp gamma_16_table,
  170310. int gamma_shift)
  170311. {
  170312. png_bytep sp;
  170313. png_uint_32 i;
  170314. png_uint_32 row_width=row_info->width;
  170315. png_debug(1, "in png_do_gamma\n");
  170316. if (
  170317. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  170318. row != NULL && row_info != NULL &&
  170319. #endif
  170320. ((row_info->bit_depth <= 8 && gamma_table != NULL) ||
  170321. (row_info->bit_depth == 16 && gamma_16_table != NULL)))
  170322. {
  170323. switch (row_info->color_type)
  170324. {
  170325. case PNG_COLOR_TYPE_RGB:
  170326. {
  170327. if (row_info->bit_depth == 8)
  170328. {
  170329. sp = row;
  170330. for (i = 0; i < row_width; i++)
  170331. {
  170332. *sp = gamma_table[*sp];
  170333. sp++;
  170334. *sp = gamma_table[*sp];
  170335. sp++;
  170336. *sp = gamma_table[*sp];
  170337. sp++;
  170338. }
  170339. }
  170340. else /* if (row_info->bit_depth == 16) */
  170341. {
  170342. sp = row;
  170343. for (i = 0; i < row_width; i++)
  170344. {
  170345. png_uint_16 v;
  170346. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170347. *sp = (png_byte)((v >> 8) & 0xff);
  170348. *(sp + 1) = (png_byte)(v & 0xff);
  170349. sp += 2;
  170350. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170351. *sp = (png_byte)((v >> 8) & 0xff);
  170352. *(sp + 1) = (png_byte)(v & 0xff);
  170353. sp += 2;
  170354. 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. }
  170359. }
  170360. break;
  170361. }
  170362. case PNG_COLOR_TYPE_RGB_ALPHA:
  170363. {
  170364. if (row_info->bit_depth == 8)
  170365. {
  170366. sp = row;
  170367. for (i = 0; i < row_width; i++)
  170368. {
  170369. *sp = gamma_table[*sp];
  170370. sp++;
  170371. *sp = gamma_table[*sp];
  170372. sp++;
  170373. *sp = gamma_table[*sp];
  170374. sp++;
  170375. sp++;
  170376. }
  170377. }
  170378. else /* if (row_info->bit_depth == 16) */
  170379. {
  170380. sp = row;
  170381. for (i = 0; i < row_width; i++)
  170382. {
  170383. png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170384. *sp = (png_byte)((v >> 8) & 0xff);
  170385. *(sp + 1) = (png_byte)(v & 0xff);
  170386. sp += 2;
  170387. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170388. *sp = (png_byte)((v >> 8) & 0xff);
  170389. *(sp + 1) = (png_byte)(v & 0xff);
  170390. sp += 2;
  170391. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170392. *sp = (png_byte)((v >> 8) & 0xff);
  170393. *(sp + 1) = (png_byte)(v & 0xff);
  170394. sp += 4;
  170395. }
  170396. }
  170397. break;
  170398. }
  170399. case PNG_COLOR_TYPE_GRAY_ALPHA:
  170400. {
  170401. if (row_info->bit_depth == 8)
  170402. {
  170403. sp = row;
  170404. for (i = 0; i < row_width; i++)
  170405. {
  170406. *sp = gamma_table[*sp];
  170407. sp += 2;
  170408. }
  170409. }
  170410. else /* if (row_info->bit_depth == 16) */
  170411. {
  170412. sp = row;
  170413. for (i = 0; i < row_width; i++)
  170414. {
  170415. png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170416. *sp = (png_byte)((v >> 8) & 0xff);
  170417. *(sp + 1) = (png_byte)(v & 0xff);
  170418. sp += 4;
  170419. }
  170420. }
  170421. break;
  170422. }
  170423. case PNG_COLOR_TYPE_GRAY:
  170424. {
  170425. if (row_info->bit_depth == 2)
  170426. {
  170427. sp = row;
  170428. for (i = 0; i < row_width; i += 4)
  170429. {
  170430. int a = *sp & 0xc0;
  170431. int b = *sp & 0x30;
  170432. int c = *sp & 0x0c;
  170433. int d = *sp & 0x03;
  170434. *sp = (png_byte)(
  170435. ((((int)gamma_table[a|(a>>2)|(a>>4)|(a>>6)]) ) & 0xc0)|
  170436. ((((int)gamma_table[(b<<2)|b|(b>>2)|(b>>4)])>>2) & 0x30)|
  170437. ((((int)gamma_table[(c<<4)|(c<<2)|c|(c>>2)])>>4) & 0x0c)|
  170438. ((((int)gamma_table[(d<<6)|(d<<4)|(d<<2)|d])>>6) ));
  170439. sp++;
  170440. }
  170441. }
  170442. if (row_info->bit_depth == 4)
  170443. {
  170444. sp = row;
  170445. for (i = 0; i < row_width; i += 2)
  170446. {
  170447. int msb = *sp & 0xf0;
  170448. int lsb = *sp & 0x0f;
  170449. *sp = (png_byte)((((int)gamma_table[msb | (msb >> 4)]) & 0xf0)
  170450. | (((int)gamma_table[(lsb << 4) | lsb]) >> 4));
  170451. sp++;
  170452. }
  170453. }
  170454. else if (row_info->bit_depth == 8)
  170455. {
  170456. sp = row;
  170457. for (i = 0; i < row_width; i++)
  170458. {
  170459. *sp = gamma_table[*sp];
  170460. sp++;
  170461. }
  170462. }
  170463. else if (row_info->bit_depth == 16)
  170464. {
  170465. sp = row;
  170466. for (i = 0; i < row_width; i++)
  170467. {
  170468. png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170469. *sp = (png_byte)((v >> 8) & 0xff);
  170470. *(sp + 1) = (png_byte)(v & 0xff);
  170471. sp += 2;
  170472. }
  170473. }
  170474. break;
  170475. }
  170476. }
  170477. }
  170478. }
  170479. #endif
  170480. #if defined(PNG_READ_EXPAND_SUPPORTED)
  170481. void /* PRIVATE */
  170482. png_do_expand_palette(png_row_infop row_info, png_bytep row,
  170483. png_colorp palette, png_bytep trans, int num_trans)
  170484. {
  170485. int shift, value;
  170486. png_bytep sp, dp;
  170487. png_uint_32 i;
  170488. png_uint_32 row_width=row_info->width;
  170489. png_debug(1, "in png_do_expand_palette\n");
  170490. if (
  170491. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  170492. row != NULL && row_info != NULL &&
  170493. #endif
  170494. row_info->color_type == PNG_COLOR_TYPE_PALETTE)
  170495. {
  170496. if (row_info->bit_depth < 8)
  170497. {
  170498. switch (row_info->bit_depth)
  170499. {
  170500. case 1:
  170501. {
  170502. sp = row + (png_size_t)((row_width - 1) >> 3);
  170503. dp = row + (png_size_t)row_width - 1;
  170504. shift = 7 - (int)((row_width + 7) & 0x07);
  170505. for (i = 0; i < row_width; i++)
  170506. {
  170507. if ((*sp >> shift) & 0x01)
  170508. *dp = 1;
  170509. else
  170510. *dp = 0;
  170511. if (shift == 7)
  170512. {
  170513. shift = 0;
  170514. sp--;
  170515. }
  170516. else
  170517. shift++;
  170518. dp--;
  170519. }
  170520. break;
  170521. }
  170522. case 2:
  170523. {
  170524. sp = row + (png_size_t)((row_width - 1) >> 2);
  170525. dp = row + (png_size_t)row_width - 1;
  170526. shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
  170527. for (i = 0; i < row_width; i++)
  170528. {
  170529. value = (*sp >> shift) & 0x03;
  170530. *dp = (png_byte)value;
  170531. if (shift == 6)
  170532. {
  170533. shift = 0;
  170534. sp--;
  170535. }
  170536. else
  170537. shift += 2;
  170538. dp--;
  170539. }
  170540. break;
  170541. }
  170542. case 4:
  170543. {
  170544. sp = row + (png_size_t)((row_width - 1) >> 1);
  170545. dp = row + (png_size_t)row_width - 1;
  170546. shift = (int)((row_width & 0x01) << 2);
  170547. for (i = 0; i < row_width; i++)
  170548. {
  170549. value = (*sp >> shift) & 0x0f;
  170550. *dp = (png_byte)value;
  170551. if (shift == 4)
  170552. {
  170553. shift = 0;
  170554. sp--;
  170555. }
  170556. else
  170557. shift += 4;
  170558. dp--;
  170559. }
  170560. break;
  170561. }
  170562. }
  170563. row_info->bit_depth = 8;
  170564. row_info->pixel_depth = 8;
  170565. row_info->rowbytes = row_width;
  170566. }
  170567. switch (row_info->bit_depth)
  170568. {
  170569. case 8:
  170570. {
  170571. if (trans != NULL)
  170572. {
  170573. sp = row + (png_size_t)row_width - 1;
  170574. dp = row + (png_size_t)(row_width << 2) - 1;
  170575. for (i = 0; i < row_width; i++)
  170576. {
  170577. if ((int)(*sp) >= num_trans)
  170578. *dp-- = 0xff;
  170579. else
  170580. *dp-- = trans[*sp];
  170581. *dp-- = palette[*sp].blue;
  170582. *dp-- = palette[*sp].green;
  170583. *dp-- = palette[*sp].red;
  170584. sp--;
  170585. }
  170586. row_info->bit_depth = 8;
  170587. row_info->pixel_depth = 32;
  170588. row_info->rowbytes = row_width * 4;
  170589. row_info->color_type = 6;
  170590. row_info->channels = 4;
  170591. }
  170592. else
  170593. {
  170594. sp = row + (png_size_t)row_width - 1;
  170595. dp = row + (png_size_t)(row_width * 3) - 1;
  170596. for (i = 0; i < row_width; i++)
  170597. {
  170598. *dp-- = palette[*sp].blue;
  170599. *dp-- = palette[*sp].green;
  170600. *dp-- = palette[*sp].red;
  170601. sp--;
  170602. }
  170603. row_info->bit_depth = 8;
  170604. row_info->pixel_depth = 24;
  170605. row_info->rowbytes = row_width * 3;
  170606. row_info->color_type = 2;
  170607. row_info->channels = 3;
  170608. }
  170609. break;
  170610. }
  170611. }
  170612. }
  170613. }
  170614. void /* PRIVATE */
  170615. png_do_expand(png_row_infop row_info, png_bytep row,
  170616. png_color_16p trans_value)
  170617. {
  170618. int shift, value;
  170619. png_bytep sp, dp;
  170620. png_uint_32 i;
  170621. png_uint_32 row_width=row_info->width;
  170622. png_debug(1, "in png_do_expand\n");
  170623. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  170624. if (row != NULL && row_info != NULL)
  170625. #endif
  170626. {
  170627. if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
  170628. {
  170629. png_uint_16 gray = (png_uint_16)(trans_value ? trans_value->gray : 0);
  170630. if (row_info->bit_depth < 8)
  170631. {
  170632. switch (row_info->bit_depth)
  170633. {
  170634. case 1:
  170635. {
  170636. gray = (png_uint_16)((gray&0x01)*0xff);
  170637. sp = row + (png_size_t)((row_width - 1) >> 3);
  170638. dp = row + (png_size_t)row_width - 1;
  170639. shift = 7 - (int)((row_width + 7) & 0x07);
  170640. for (i = 0; i < row_width; i++)
  170641. {
  170642. if ((*sp >> shift) & 0x01)
  170643. *dp = 0xff;
  170644. else
  170645. *dp = 0;
  170646. if (shift == 7)
  170647. {
  170648. shift = 0;
  170649. sp--;
  170650. }
  170651. else
  170652. shift++;
  170653. dp--;
  170654. }
  170655. break;
  170656. }
  170657. case 2:
  170658. {
  170659. gray = (png_uint_16)((gray&0x03)*0x55);
  170660. sp = row + (png_size_t)((row_width - 1) >> 2);
  170661. dp = row + (png_size_t)row_width - 1;
  170662. shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
  170663. for (i = 0; i < row_width; i++)
  170664. {
  170665. value = (*sp >> shift) & 0x03;
  170666. *dp = (png_byte)(value | (value << 2) | (value << 4) |
  170667. (value << 6));
  170668. if (shift == 6)
  170669. {
  170670. shift = 0;
  170671. sp--;
  170672. }
  170673. else
  170674. shift += 2;
  170675. dp--;
  170676. }
  170677. break;
  170678. }
  170679. case 4:
  170680. {
  170681. gray = (png_uint_16)((gray&0x0f)*0x11);
  170682. sp = row + (png_size_t)((row_width - 1) >> 1);
  170683. dp = row + (png_size_t)row_width - 1;
  170684. shift = (int)((1 - ((row_width + 1) & 0x01)) << 2);
  170685. for (i = 0; i < row_width; i++)
  170686. {
  170687. value = (*sp >> shift) & 0x0f;
  170688. *dp = (png_byte)(value | (value << 4));
  170689. if (shift == 4)
  170690. {
  170691. shift = 0;
  170692. sp--;
  170693. }
  170694. else
  170695. shift = 4;
  170696. dp--;
  170697. }
  170698. break;
  170699. }
  170700. }
  170701. row_info->bit_depth = 8;
  170702. row_info->pixel_depth = 8;
  170703. row_info->rowbytes = row_width;
  170704. }
  170705. if (trans_value != NULL)
  170706. {
  170707. if (row_info->bit_depth == 8)
  170708. {
  170709. gray = gray & 0xff;
  170710. sp = row + (png_size_t)row_width - 1;
  170711. dp = row + (png_size_t)(row_width << 1) - 1;
  170712. for (i = 0; i < row_width; i++)
  170713. {
  170714. if (*sp == gray)
  170715. *dp-- = 0;
  170716. else
  170717. *dp-- = 0xff;
  170718. *dp-- = *sp--;
  170719. }
  170720. }
  170721. else if (row_info->bit_depth == 16)
  170722. {
  170723. png_byte gray_high = (gray >> 8) & 0xff;
  170724. png_byte gray_low = gray & 0xff;
  170725. sp = row + row_info->rowbytes - 1;
  170726. dp = row + (row_info->rowbytes << 1) - 1;
  170727. for (i = 0; i < row_width; i++)
  170728. {
  170729. if (*(sp-1) == gray_high && *(sp) == gray_low)
  170730. {
  170731. *dp-- = 0;
  170732. *dp-- = 0;
  170733. }
  170734. else
  170735. {
  170736. *dp-- = 0xff;
  170737. *dp-- = 0xff;
  170738. }
  170739. *dp-- = *sp--;
  170740. *dp-- = *sp--;
  170741. }
  170742. }
  170743. row_info->color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
  170744. row_info->channels = 2;
  170745. row_info->pixel_depth = (png_byte)(row_info->bit_depth << 1);
  170746. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
  170747. row_width);
  170748. }
  170749. }
  170750. else if (row_info->color_type == PNG_COLOR_TYPE_RGB && trans_value)
  170751. {
  170752. if (row_info->bit_depth == 8)
  170753. {
  170754. png_byte red = trans_value->red & 0xff;
  170755. png_byte green = trans_value->green & 0xff;
  170756. png_byte blue = trans_value->blue & 0xff;
  170757. sp = row + (png_size_t)row_info->rowbytes - 1;
  170758. dp = row + (png_size_t)(row_width << 2) - 1;
  170759. for (i = 0; i < row_width; i++)
  170760. {
  170761. if (*(sp - 2) == red && *(sp - 1) == green && *(sp) == blue)
  170762. *dp-- = 0;
  170763. else
  170764. *dp-- = 0xff;
  170765. *dp-- = *sp--;
  170766. *dp-- = *sp--;
  170767. *dp-- = *sp--;
  170768. }
  170769. }
  170770. else if (row_info->bit_depth == 16)
  170771. {
  170772. png_byte red_high = (trans_value->red >> 8) & 0xff;
  170773. png_byte green_high = (trans_value->green >> 8) & 0xff;
  170774. png_byte blue_high = (trans_value->blue >> 8) & 0xff;
  170775. png_byte red_low = trans_value->red & 0xff;
  170776. png_byte green_low = trans_value->green & 0xff;
  170777. png_byte blue_low = trans_value->blue & 0xff;
  170778. sp = row + row_info->rowbytes - 1;
  170779. dp = row + (png_size_t)(row_width << 3) - 1;
  170780. for (i = 0; i < row_width; i++)
  170781. {
  170782. if (*(sp - 5) == red_high &&
  170783. *(sp - 4) == red_low &&
  170784. *(sp - 3) == green_high &&
  170785. *(sp - 2) == green_low &&
  170786. *(sp - 1) == blue_high &&
  170787. *(sp ) == blue_low)
  170788. {
  170789. *dp-- = 0;
  170790. *dp-- = 0;
  170791. }
  170792. else
  170793. {
  170794. *dp-- = 0xff;
  170795. *dp-- = 0xff;
  170796. }
  170797. *dp-- = *sp--;
  170798. *dp-- = *sp--;
  170799. *dp-- = *sp--;
  170800. *dp-- = *sp--;
  170801. *dp-- = *sp--;
  170802. *dp-- = *sp--;
  170803. }
  170804. }
  170805. row_info->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
  170806. row_info->channels = 4;
  170807. row_info->pixel_depth = (png_byte)(row_info->bit_depth << 2);
  170808. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  170809. }
  170810. }
  170811. }
  170812. #endif
  170813. #if defined(PNG_READ_DITHER_SUPPORTED)
  170814. void /* PRIVATE */
  170815. png_do_dither(png_row_infop row_info, png_bytep row,
  170816. png_bytep palette_lookup, png_bytep dither_lookup)
  170817. {
  170818. png_bytep sp, dp;
  170819. png_uint_32 i;
  170820. png_uint_32 row_width=row_info->width;
  170821. png_debug(1, "in png_do_dither\n");
  170822. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  170823. if (row != NULL && row_info != NULL)
  170824. #endif
  170825. {
  170826. if (row_info->color_type == PNG_COLOR_TYPE_RGB &&
  170827. palette_lookup && row_info->bit_depth == 8)
  170828. {
  170829. int r, g, b, p;
  170830. sp = row;
  170831. dp = row;
  170832. for (i = 0; i < row_width; i++)
  170833. {
  170834. r = *sp++;
  170835. g = *sp++;
  170836. b = *sp++;
  170837. p = (((r >> (8 - PNG_DITHER_RED_BITS)) &
  170838. ((1 << PNG_DITHER_RED_BITS) - 1)) <<
  170839. (PNG_DITHER_GREEN_BITS + PNG_DITHER_BLUE_BITS)) |
  170840. (((g >> (8 - PNG_DITHER_GREEN_BITS)) &
  170841. ((1 << PNG_DITHER_GREEN_BITS) - 1)) <<
  170842. (PNG_DITHER_BLUE_BITS)) |
  170843. ((b >> (8 - PNG_DITHER_BLUE_BITS)) &
  170844. ((1 << PNG_DITHER_BLUE_BITS) - 1));
  170845. *dp++ = palette_lookup[p];
  170846. }
  170847. row_info->color_type = PNG_COLOR_TYPE_PALETTE;
  170848. row_info->channels = 1;
  170849. row_info->pixel_depth = row_info->bit_depth;
  170850. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  170851. }
  170852. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA &&
  170853. palette_lookup != NULL && row_info->bit_depth == 8)
  170854. {
  170855. int r, g, b, p;
  170856. sp = row;
  170857. dp = row;
  170858. for (i = 0; i < row_width; i++)
  170859. {
  170860. r = *sp++;
  170861. g = *sp++;
  170862. b = *sp++;
  170863. sp++;
  170864. p = (((r >> (8 - PNG_DITHER_RED_BITS)) &
  170865. ((1 << PNG_DITHER_RED_BITS) - 1)) <<
  170866. (PNG_DITHER_GREEN_BITS + PNG_DITHER_BLUE_BITS)) |
  170867. (((g >> (8 - PNG_DITHER_GREEN_BITS)) &
  170868. ((1 << PNG_DITHER_GREEN_BITS) - 1)) <<
  170869. (PNG_DITHER_BLUE_BITS)) |
  170870. ((b >> (8 - PNG_DITHER_BLUE_BITS)) &
  170871. ((1 << PNG_DITHER_BLUE_BITS) - 1));
  170872. *dp++ = palette_lookup[p];
  170873. }
  170874. row_info->color_type = PNG_COLOR_TYPE_PALETTE;
  170875. row_info->channels = 1;
  170876. row_info->pixel_depth = row_info->bit_depth;
  170877. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  170878. }
  170879. else if (row_info->color_type == PNG_COLOR_TYPE_PALETTE &&
  170880. dither_lookup && row_info->bit_depth == 8)
  170881. {
  170882. sp = row;
  170883. for (i = 0; i < row_width; i++, sp++)
  170884. {
  170885. *sp = dither_lookup[*sp];
  170886. }
  170887. }
  170888. }
  170889. }
  170890. #endif
  170891. #ifdef PNG_FLOATING_POINT_SUPPORTED
  170892. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170893. static PNG_CONST int png_gamma_shift[] =
  170894. {0x10, 0x21, 0x42, 0x84, 0x110, 0x248, 0x550, 0xff0, 0x00};
  170895. void /* PRIVATE */
  170896. png_build_gamma_table(png_structp png_ptr)
  170897. {
  170898. png_debug(1, "in png_build_gamma_table\n");
  170899. if (png_ptr->bit_depth <= 8)
  170900. {
  170901. int i;
  170902. double g;
  170903. if (png_ptr->screen_gamma > .000001)
  170904. g = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
  170905. else
  170906. g = 1.0;
  170907. png_ptr->gamma_table = (png_bytep)png_malloc(png_ptr,
  170908. (png_uint_32)256);
  170909. for (i = 0; i < 256; i++)
  170910. {
  170911. png_ptr->gamma_table[i] = (png_byte)(pow((double)i / 255.0,
  170912. g) * 255.0 + .5);
  170913. }
  170914. #if defined(PNG_READ_BACKGROUND_SUPPORTED) || \
  170915. defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  170916. if (png_ptr->transformations & ((PNG_BACKGROUND) | PNG_RGB_TO_GRAY))
  170917. {
  170918. g = 1.0 / (png_ptr->gamma);
  170919. png_ptr->gamma_to_1 = (png_bytep)png_malloc(png_ptr,
  170920. (png_uint_32)256);
  170921. for (i = 0; i < 256; i++)
  170922. {
  170923. png_ptr->gamma_to_1[i] = (png_byte)(pow((double)i / 255.0,
  170924. g) * 255.0 + .5);
  170925. }
  170926. png_ptr->gamma_from_1 = (png_bytep)png_malloc(png_ptr,
  170927. (png_uint_32)256);
  170928. if(png_ptr->screen_gamma > 0.000001)
  170929. g = 1.0 / png_ptr->screen_gamma;
  170930. else
  170931. g = png_ptr->gamma; /* probably doing rgb_to_gray */
  170932. for (i = 0; i < 256; i++)
  170933. {
  170934. png_ptr->gamma_from_1[i] = (png_byte)(pow((double)i / 255.0,
  170935. g) * 255.0 + .5);
  170936. }
  170937. }
  170938. #endif /* PNG_READ_BACKGROUND_SUPPORTED || PNG_RGB_TO_GRAY_SUPPORTED */
  170939. }
  170940. else
  170941. {
  170942. double g;
  170943. int i, j, shift, num;
  170944. int sig_bit;
  170945. png_uint_32 ig;
  170946. if (png_ptr->color_type & PNG_COLOR_MASK_COLOR)
  170947. {
  170948. sig_bit = (int)png_ptr->sig_bit.red;
  170949. if ((int)png_ptr->sig_bit.green > sig_bit)
  170950. sig_bit = png_ptr->sig_bit.green;
  170951. if ((int)png_ptr->sig_bit.blue > sig_bit)
  170952. sig_bit = png_ptr->sig_bit.blue;
  170953. }
  170954. else
  170955. {
  170956. sig_bit = (int)png_ptr->sig_bit.gray;
  170957. }
  170958. if (sig_bit > 0)
  170959. shift = 16 - sig_bit;
  170960. else
  170961. shift = 0;
  170962. if (png_ptr->transformations & PNG_16_TO_8)
  170963. {
  170964. if (shift < (16 - PNG_MAX_GAMMA_8))
  170965. shift = (16 - PNG_MAX_GAMMA_8);
  170966. }
  170967. if (shift > 8)
  170968. shift = 8;
  170969. if (shift < 0)
  170970. shift = 0;
  170971. png_ptr->gamma_shift = (png_byte)shift;
  170972. num = (1 << (8 - shift));
  170973. if (png_ptr->screen_gamma > .000001)
  170974. g = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
  170975. else
  170976. g = 1.0;
  170977. png_ptr->gamma_16_table = (png_uint_16pp)png_malloc(png_ptr,
  170978. (png_uint_32)(num * png_sizeof (png_uint_16p)));
  170979. if (png_ptr->transformations & (PNG_16_TO_8 | PNG_BACKGROUND))
  170980. {
  170981. double fin, fout;
  170982. png_uint_32 last, max;
  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. }
  170988. g = 1.0 / g;
  170989. last = 0;
  170990. for (i = 0; i < 256; i++)
  170991. {
  170992. fout = ((double)i + 0.5) / 256.0;
  170993. fin = pow(fout, g);
  170994. max = (png_uint_32)(fin * (double)((png_uint_32)num << 8));
  170995. while (last <= max)
  170996. {
  170997. png_ptr->gamma_16_table[(int)(last & (0xff >> shift))]
  170998. [(int)(last >> (8 - shift))] = (png_uint_16)(
  170999. (png_uint_16)i | ((png_uint_16)i << 8));
  171000. last++;
  171001. }
  171002. }
  171003. while (last < ((png_uint_32)num << 8))
  171004. {
  171005. png_ptr->gamma_16_table[(int)(last & (0xff >> shift))]
  171006. [(int)(last >> (8 - shift))] = (png_uint_16)65535L;
  171007. last++;
  171008. }
  171009. }
  171010. else
  171011. {
  171012. for (i = 0; i < num; i++)
  171013. {
  171014. png_ptr->gamma_16_table[i] = (png_uint_16p)png_malloc(png_ptr,
  171015. (png_uint_32)(256 * png_sizeof (png_uint_16)));
  171016. ig = (((png_uint_32)i * (png_uint_32)png_gamma_shift[shift]) >> 4);
  171017. for (j = 0; j < 256; j++)
  171018. {
  171019. png_ptr->gamma_16_table[i][j] =
  171020. (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) /
  171021. 65535.0, g) * 65535.0 + .5);
  171022. }
  171023. }
  171024. }
  171025. #if defined(PNG_READ_BACKGROUND_SUPPORTED) || \
  171026. defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  171027. if (png_ptr->transformations & (PNG_BACKGROUND | PNG_RGB_TO_GRAY))
  171028. {
  171029. g = 1.0 / (png_ptr->gamma);
  171030. png_ptr->gamma_16_to_1 = (png_uint_16pp)png_malloc(png_ptr,
  171031. (png_uint_32)(num * png_sizeof (png_uint_16p )));
  171032. for (i = 0; i < num; i++)
  171033. {
  171034. png_ptr->gamma_16_to_1[i] = (png_uint_16p)png_malloc(png_ptr,
  171035. (png_uint_32)(256 * png_sizeof (png_uint_16)));
  171036. ig = (((png_uint_32)i *
  171037. (png_uint_32)png_gamma_shift[shift]) >> 4);
  171038. for (j = 0; j < 256; j++)
  171039. {
  171040. png_ptr->gamma_16_to_1[i][j] =
  171041. (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) /
  171042. 65535.0, g) * 65535.0 + .5);
  171043. }
  171044. }
  171045. if(png_ptr->screen_gamma > 0.000001)
  171046. g = 1.0 / png_ptr->screen_gamma;
  171047. else
  171048. g = png_ptr->gamma; /* probably doing rgb_to_gray */
  171049. png_ptr->gamma_16_from_1 = (png_uint_16pp)png_malloc(png_ptr,
  171050. (png_uint_32)(num * png_sizeof (png_uint_16p)));
  171051. for (i = 0; i < num; i++)
  171052. {
  171053. png_ptr->gamma_16_from_1[i] = (png_uint_16p)png_malloc(png_ptr,
  171054. (png_uint_32)(256 * png_sizeof (png_uint_16)));
  171055. ig = (((png_uint_32)i *
  171056. (png_uint_32)png_gamma_shift[shift]) >> 4);
  171057. for (j = 0; j < 256; j++)
  171058. {
  171059. png_ptr->gamma_16_from_1[i][j] =
  171060. (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) /
  171061. 65535.0, g) * 65535.0 + .5);
  171062. }
  171063. }
  171064. }
  171065. #endif /* PNG_READ_BACKGROUND_SUPPORTED || PNG_RGB_TO_GRAY_SUPPORTED */
  171066. }
  171067. }
  171068. #endif
  171069. #endif
  171070. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  171071. void /* PRIVATE */
  171072. png_do_read_intrapixel(png_row_infop row_info, png_bytep row)
  171073. {
  171074. png_debug(1, "in png_do_read_intrapixel\n");
  171075. if (
  171076. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  171077. row != NULL && row_info != NULL &&
  171078. #endif
  171079. (row_info->color_type & PNG_COLOR_MASK_COLOR))
  171080. {
  171081. int bytes_per_pixel;
  171082. png_uint_32 row_width = row_info->width;
  171083. if (row_info->bit_depth == 8)
  171084. {
  171085. png_bytep rp;
  171086. png_uint_32 i;
  171087. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  171088. bytes_per_pixel = 3;
  171089. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  171090. bytes_per_pixel = 4;
  171091. else
  171092. return;
  171093. for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
  171094. {
  171095. *(rp) = (png_byte)((256 + *rp + *(rp+1))&0xff);
  171096. *(rp+2) = (png_byte)((256 + *(rp+2) + *(rp+1))&0xff);
  171097. }
  171098. }
  171099. else if (row_info->bit_depth == 16)
  171100. {
  171101. png_bytep rp;
  171102. png_uint_32 i;
  171103. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  171104. bytes_per_pixel = 6;
  171105. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  171106. bytes_per_pixel = 8;
  171107. else
  171108. return;
  171109. for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
  171110. {
  171111. png_uint_32 s0 = (*(rp ) << 8) | *(rp+1);
  171112. png_uint_32 s1 = (*(rp+2) << 8) | *(rp+3);
  171113. png_uint_32 s2 = (*(rp+4) << 8) | *(rp+5);
  171114. png_uint_32 red = (png_uint_32)((s0+s1+65536L) & 0xffffL);
  171115. png_uint_32 blue = (png_uint_32)((s2+s1+65536L) & 0xffffL);
  171116. *(rp ) = (png_byte)((red >> 8) & 0xff);
  171117. *(rp+1) = (png_byte)(red & 0xff);
  171118. *(rp+4) = (png_byte)((blue >> 8) & 0xff);
  171119. *(rp+5) = (png_byte)(blue & 0xff);
  171120. }
  171121. }
  171122. }
  171123. }
  171124. #endif /* PNG_MNG_FEATURES_SUPPORTED */
  171125. #endif /* PNG_READ_SUPPORTED */
  171126. /*** End of inlined file: pngrtran.c ***/
  171127. /*** Start of inlined file: pngrutil.c ***/
  171128. #define PNG_INTERNAL
  171129. #if defined(PNG_READ_SUPPORTED)
  171130. #if defined(_WIN32_WCE) && (_WIN32_WCE<0x500)
  171131. # define WIN32_WCE_OLD
  171132. #endif
  171133. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171134. # if defined(WIN32_WCE_OLD)
  171135. __inline double png_strtod(png_structp png_ptr, PNG_CONST char *nptr, char **endptr)
  171136. {
  171137. double result = 0;
  171138. int len;
  171139. wchar_t *str, *end;
  171140. len = MultiByteToWideChar(CP_ACP, 0, nptr, -1, NULL, 0);
  171141. str = (wchar_t *)png_malloc(png_ptr, len * sizeof(wchar_t));
  171142. if ( NULL != str )
  171143. {
  171144. MultiByteToWideChar(CP_ACP, 0, nptr, -1, str, len);
  171145. result = wcstod(str, &end);
  171146. len = WideCharToMultiByte(CP_ACP, 0, end, -1, NULL, 0, NULL, NULL);
  171147. *endptr = (char *)nptr + (png_strlen(nptr) - len + 1);
  171148. png_free(png_ptr, str);
  171149. }
  171150. return result;
  171151. }
  171152. # else
  171153. # define png_strtod(p,a,b) strtod(a,b)
  171154. # endif
  171155. #endif
  171156. png_uint_32 PNGAPI
  171157. png_get_uint_31(png_structp png_ptr, png_bytep buf)
  171158. {
  171159. png_uint_32 i = png_get_uint_32(buf);
  171160. if (i > PNG_UINT_31_MAX)
  171161. png_error(png_ptr, "PNG unsigned integer out of range.");
  171162. return (i);
  171163. }
  171164. #ifndef PNG_READ_BIG_ENDIAN_SUPPORTED
  171165. png_uint_32 PNGAPI
  171166. png_get_uint_32(png_bytep buf)
  171167. {
  171168. png_uint_32 i = ((png_uint_32)(*buf) << 24) +
  171169. ((png_uint_32)(*(buf + 1)) << 16) +
  171170. ((png_uint_32)(*(buf + 2)) << 8) +
  171171. (png_uint_32)(*(buf + 3));
  171172. return (i);
  171173. }
  171174. png_int_32 PNGAPI
  171175. png_get_int_32(png_bytep buf)
  171176. {
  171177. png_int_32 i = ((png_int_32)(*buf) << 24) +
  171178. ((png_int_32)(*(buf + 1)) << 16) +
  171179. ((png_int_32)(*(buf + 2)) << 8) +
  171180. (png_int_32)(*(buf + 3));
  171181. return (i);
  171182. }
  171183. png_uint_16 PNGAPI
  171184. png_get_uint_16(png_bytep buf)
  171185. {
  171186. png_uint_16 i = (png_uint_16)(((png_uint_16)(*buf) << 8) +
  171187. (png_uint_16)(*(buf + 1)));
  171188. return (i);
  171189. }
  171190. #endif /* PNG_READ_BIG_ENDIAN_SUPPORTED */
  171191. void /* PRIVATE */
  171192. png_crc_read(png_structp png_ptr, png_bytep buf, png_size_t length)
  171193. {
  171194. if(png_ptr == NULL) return;
  171195. png_read_data(png_ptr, buf, length);
  171196. png_calculate_crc(png_ptr, buf, length);
  171197. }
  171198. int /* PRIVATE */
  171199. png_crc_finish(png_structp png_ptr, png_uint_32 skip)
  171200. {
  171201. png_size_t i;
  171202. png_size_t istop = png_ptr->zbuf_size;
  171203. for (i = (png_size_t)skip; i > istop; i -= istop)
  171204. {
  171205. png_crc_read(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
  171206. }
  171207. if (i)
  171208. {
  171209. png_crc_read(png_ptr, png_ptr->zbuf, i);
  171210. }
  171211. if (png_crc_error(png_ptr))
  171212. {
  171213. if (((png_ptr->chunk_name[0] & 0x20) && /* Ancillary */
  171214. !(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN)) ||
  171215. (!(png_ptr->chunk_name[0] & 0x20) && /* Critical */
  171216. (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_USE)))
  171217. {
  171218. png_chunk_warning(png_ptr, "CRC error");
  171219. }
  171220. else
  171221. {
  171222. png_chunk_error(png_ptr, "CRC error");
  171223. }
  171224. return (1);
  171225. }
  171226. return (0);
  171227. }
  171228. int /* PRIVATE */
  171229. png_crc_error(png_structp png_ptr)
  171230. {
  171231. png_byte crc_bytes[4];
  171232. png_uint_32 crc;
  171233. int need_crc = 1;
  171234. if (png_ptr->chunk_name[0] & 0x20) /* ancillary */
  171235. {
  171236. if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_MASK) ==
  171237. (PNG_FLAG_CRC_ANCILLARY_USE | PNG_FLAG_CRC_ANCILLARY_NOWARN))
  171238. need_crc = 0;
  171239. }
  171240. else /* critical */
  171241. {
  171242. if (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE)
  171243. need_crc = 0;
  171244. }
  171245. png_read_data(png_ptr, crc_bytes, 4);
  171246. if (need_crc)
  171247. {
  171248. crc = png_get_uint_32(crc_bytes);
  171249. return ((int)(crc != png_ptr->crc));
  171250. }
  171251. else
  171252. return (0);
  171253. }
  171254. #if defined(PNG_READ_zTXt_SUPPORTED) || defined(PNG_READ_iTXt_SUPPORTED) || \
  171255. defined(PNG_READ_iCCP_SUPPORTED)
  171256. png_charp /* PRIVATE */
  171257. png_decompress_chunk(png_structp png_ptr, int comp_type,
  171258. png_charp chunkdata, png_size_t chunklength,
  171259. png_size_t prefix_size, png_size_t *newlength)
  171260. {
  171261. static PNG_CONST char msg[] = "Error decoding compressed text";
  171262. png_charp text;
  171263. png_size_t text_size;
  171264. if (comp_type == PNG_COMPRESSION_TYPE_BASE)
  171265. {
  171266. int ret = Z_OK;
  171267. png_ptr->zstream.next_in = (png_bytep)(chunkdata + prefix_size);
  171268. png_ptr->zstream.avail_in = (uInt)(chunklength - prefix_size);
  171269. png_ptr->zstream.next_out = png_ptr->zbuf;
  171270. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  171271. text_size = 0;
  171272. text = NULL;
  171273. while (png_ptr->zstream.avail_in)
  171274. {
  171275. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  171276. if (ret != Z_OK && ret != Z_STREAM_END)
  171277. {
  171278. if (png_ptr->zstream.msg != NULL)
  171279. png_warning(png_ptr, png_ptr->zstream.msg);
  171280. else
  171281. png_warning(png_ptr, msg);
  171282. inflateReset(&png_ptr->zstream);
  171283. png_ptr->zstream.avail_in = 0;
  171284. if (text == NULL)
  171285. {
  171286. text_size = prefix_size + png_sizeof(msg) + 1;
  171287. text = (png_charp)png_malloc_warn(png_ptr, text_size);
  171288. if (text == NULL)
  171289. {
  171290. png_free(png_ptr,chunkdata);
  171291. png_error(png_ptr,"Not enough memory to decompress chunk");
  171292. }
  171293. png_memcpy(text, chunkdata, prefix_size);
  171294. }
  171295. text[text_size - 1] = 0x00;
  171296. text_size = (png_size_t)(chunklength - (text - chunkdata) - 1);
  171297. text_size = png_sizeof(msg) > text_size ? text_size :
  171298. png_sizeof(msg);
  171299. png_memcpy(text + prefix_size, msg, text_size + 1);
  171300. break;
  171301. }
  171302. if (!png_ptr->zstream.avail_out || ret == Z_STREAM_END)
  171303. {
  171304. if (text == NULL)
  171305. {
  171306. text_size = prefix_size +
  171307. png_ptr->zbuf_size - png_ptr->zstream.avail_out;
  171308. text = (png_charp)png_malloc_warn(png_ptr, text_size + 1);
  171309. if (text == NULL)
  171310. {
  171311. png_free(png_ptr,chunkdata);
  171312. png_error(png_ptr,"Not enough memory to decompress chunk.");
  171313. }
  171314. png_memcpy(text + prefix_size, png_ptr->zbuf,
  171315. text_size - prefix_size);
  171316. png_memcpy(text, chunkdata, prefix_size);
  171317. *(text + text_size) = 0x00;
  171318. }
  171319. else
  171320. {
  171321. png_charp tmp;
  171322. tmp = text;
  171323. text = (png_charp)png_malloc_warn(png_ptr,
  171324. (png_uint_32)(text_size +
  171325. png_ptr->zbuf_size - png_ptr->zstream.avail_out + 1));
  171326. if (text == NULL)
  171327. {
  171328. png_free(png_ptr, tmp);
  171329. png_free(png_ptr, chunkdata);
  171330. png_error(png_ptr,"Not enough memory to decompress chunk..");
  171331. }
  171332. png_memcpy(text, tmp, text_size);
  171333. png_free(png_ptr, tmp);
  171334. png_memcpy(text + text_size, png_ptr->zbuf,
  171335. (png_ptr->zbuf_size - png_ptr->zstream.avail_out));
  171336. text_size += png_ptr->zbuf_size - png_ptr->zstream.avail_out;
  171337. *(text + text_size) = 0x00;
  171338. }
  171339. if (ret == Z_STREAM_END)
  171340. break;
  171341. else
  171342. {
  171343. png_ptr->zstream.next_out = png_ptr->zbuf;
  171344. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  171345. }
  171346. }
  171347. }
  171348. if (ret != Z_STREAM_END)
  171349. {
  171350. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  171351. char umsg[52];
  171352. if (ret == Z_BUF_ERROR)
  171353. png_snprintf(umsg, 52,
  171354. "Buffer error in compressed datastream in %s chunk",
  171355. png_ptr->chunk_name);
  171356. else if (ret == Z_DATA_ERROR)
  171357. png_snprintf(umsg, 52,
  171358. "Data error in compressed datastream in %s chunk",
  171359. png_ptr->chunk_name);
  171360. else
  171361. png_snprintf(umsg, 52,
  171362. "Incomplete compressed datastream in %s chunk",
  171363. png_ptr->chunk_name);
  171364. png_warning(png_ptr, umsg);
  171365. #else
  171366. png_warning(png_ptr,
  171367. "Incomplete compressed datastream in chunk other than IDAT");
  171368. #endif
  171369. text_size=prefix_size;
  171370. if (text == NULL)
  171371. {
  171372. text = (png_charp)png_malloc_warn(png_ptr, text_size+1);
  171373. if (text == NULL)
  171374. {
  171375. png_free(png_ptr, chunkdata);
  171376. png_error(png_ptr,"Not enough memory for text.");
  171377. }
  171378. png_memcpy(text, chunkdata, prefix_size);
  171379. }
  171380. *(text + text_size) = 0x00;
  171381. }
  171382. inflateReset(&png_ptr->zstream);
  171383. png_ptr->zstream.avail_in = 0;
  171384. png_free(png_ptr, chunkdata);
  171385. chunkdata = text;
  171386. *newlength=text_size;
  171387. }
  171388. else /* if (comp_type != PNG_COMPRESSION_TYPE_BASE) */
  171389. {
  171390. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  171391. char umsg[50];
  171392. png_snprintf(umsg, 50,
  171393. "Unknown zTXt compression type %d", comp_type);
  171394. png_warning(png_ptr, umsg);
  171395. #else
  171396. png_warning(png_ptr, "Unknown zTXt compression type");
  171397. #endif
  171398. *(chunkdata + prefix_size) = 0x00;
  171399. *newlength=prefix_size;
  171400. }
  171401. return chunkdata;
  171402. }
  171403. #endif
  171404. void /* PRIVATE */
  171405. png_handle_IHDR(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171406. {
  171407. png_byte buf[13];
  171408. png_uint_32 width, height;
  171409. int bit_depth, color_type, compression_type, filter_type;
  171410. int interlace_type;
  171411. png_debug(1, "in png_handle_IHDR\n");
  171412. if (png_ptr->mode & PNG_HAVE_IHDR)
  171413. png_error(png_ptr, "Out of place IHDR");
  171414. if (length != 13)
  171415. png_error(png_ptr, "Invalid IHDR chunk");
  171416. png_ptr->mode |= PNG_HAVE_IHDR;
  171417. png_crc_read(png_ptr, buf, 13);
  171418. png_crc_finish(png_ptr, 0);
  171419. width = png_get_uint_31(png_ptr, buf);
  171420. height = png_get_uint_31(png_ptr, buf + 4);
  171421. bit_depth = buf[8];
  171422. color_type = buf[9];
  171423. compression_type = buf[10];
  171424. filter_type = buf[11];
  171425. interlace_type = buf[12];
  171426. png_ptr->width = width;
  171427. png_ptr->height = height;
  171428. png_ptr->bit_depth = (png_byte)bit_depth;
  171429. png_ptr->interlaced = (png_byte)interlace_type;
  171430. png_ptr->color_type = (png_byte)color_type;
  171431. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  171432. png_ptr->filter_type = (png_byte)filter_type;
  171433. #endif
  171434. png_ptr->compression_type = (png_byte)compression_type;
  171435. switch (png_ptr->color_type)
  171436. {
  171437. case PNG_COLOR_TYPE_GRAY:
  171438. case PNG_COLOR_TYPE_PALETTE:
  171439. png_ptr->channels = 1;
  171440. break;
  171441. case PNG_COLOR_TYPE_RGB:
  171442. png_ptr->channels = 3;
  171443. break;
  171444. case PNG_COLOR_TYPE_GRAY_ALPHA:
  171445. png_ptr->channels = 2;
  171446. break;
  171447. case PNG_COLOR_TYPE_RGB_ALPHA:
  171448. png_ptr->channels = 4;
  171449. break;
  171450. }
  171451. png_ptr->pixel_depth = (png_byte)(png_ptr->bit_depth *
  171452. png_ptr->channels);
  171453. png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth,png_ptr->width);
  171454. png_debug1(3,"bit_depth = %d\n", png_ptr->bit_depth);
  171455. png_debug1(3,"channels = %d\n", png_ptr->channels);
  171456. png_debug1(3,"rowbytes = %lu\n", png_ptr->rowbytes);
  171457. png_set_IHDR(png_ptr, info_ptr, width, height, bit_depth,
  171458. color_type, interlace_type, compression_type, filter_type);
  171459. }
  171460. void /* PRIVATE */
  171461. png_handle_PLTE(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171462. {
  171463. png_color palette[PNG_MAX_PALETTE_LENGTH];
  171464. int num, i;
  171465. #ifndef PNG_NO_POINTER_INDEXING
  171466. png_colorp pal_ptr;
  171467. #endif
  171468. png_debug(1, "in png_handle_PLTE\n");
  171469. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171470. png_error(png_ptr, "Missing IHDR before PLTE");
  171471. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171472. {
  171473. png_warning(png_ptr, "Invalid PLTE after IDAT");
  171474. png_crc_finish(png_ptr, length);
  171475. return;
  171476. }
  171477. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171478. png_error(png_ptr, "Duplicate PLTE chunk");
  171479. png_ptr->mode |= PNG_HAVE_PLTE;
  171480. if (!(png_ptr->color_type&PNG_COLOR_MASK_COLOR))
  171481. {
  171482. png_warning(png_ptr,
  171483. "Ignoring PLTE chunk in grayscale PNG");
  171484. png_crc_finish(png_ptr, length);
  171485. return;
  171486. }
  171487. #if !defined(PNG_READ_OPT_PLTE_SUPPORTED)
  171488. if (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE)
  171489. {
  171490. png_crc_finish(png_ptr, length);
  171491. return;
  171492. }
  171493. #endif
  171494. if (length > 3*PNG_MAX_PALETTE_LENGTH || length % 3)
  171495. {
  171496. if (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE)
  171497. {
  171498. png_warning(png_ptr, "Invalid palette chunk");
  171499. png_crc_finish(png_ptr, length);
  171500. return;
  171501. }
  171502. else
  171503. {
  171504. png_error(png_ptr, "Invalid palette chunk");
  171505. }
  171506. }
  171507. num = (int)length / 3;
  171508. #ifndef PNG_NO_POINTER_INDEXING
  171509. for (i = 0, pal_ptr = palette; i < num; i++, pal_ptr++)
  171510. {
  171511. png_byte buf[3];
  171512. png_crc_read(png_ptr, buf, 3);
  171513. pal_ptr->red = buf[0];
  171514. pal_ptr->green = buf[1];
  171515. pal_ptr->blue = buf[2];
  171516. }
  171517. #else
  171518. for (i = 0; i < num; i++)
  171519. {
  171520. png_byte buf[3];
  171521. png_crc_read(png_ptr, buf, 3);
  171522. palette[i].red = buf[0];
  171523. palette[i].green = buf[1];
  171524. palette[i].blue = buf[2];
  171525. }
  171526. #endif
  171527. #if !defined(PNG_READ_OPT_PLTE_SUPPORTED)
  171528. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171529. #endif
  171530. {
  171531. png_crc_finish(png_ptr, 0);
  171532. }
  171533. #if !defined(PNG_READ_OPT_PLTE_SUPPORTED)
  171534. else if (png_crc_error(png_ptr)) /* Only if we have a CRC error */
  171535. {
  171536. if (!(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_USE))
  171537. {
  171538. if (png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN)
  171539. {
  171540. png_chunk_error(png_ptr, "CRC error");
  171541. }
  171542. else
  171543. {
  171544. png_chunk_warning(png_ptr, "CRC error");
  171545. return;
  171546. }
  171547. }
  171548. else if (!(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN))
  171549. {
  171550. png_chunk_warning(png_ptr, "CRC error");
  171551. }
  171552. }
  171553. #endif
  171554. png_set_PLTE(png_ptr, info_ptr, palette, num);
  171555. #if defined(PNG_READ_tRNS_SUPPORTED)
  171556. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171557. {
  171558. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
  171559. {
  171560. if (png_ptr->num_trans > (png_uint_16)num)
  171561. {
  171562. png_warning(png_ptr, "Truncating incorrect tRNS chunk length");
  171563. png_ptr->num_trans = (png_uint_16)num;
  171564. }
  171565. if (info_ptr->num_trans > (png_uint_16)num)
  171566. {
  171567. png_warning(png_ptr, "Truncating incorrect info tRNS chunk length");
  171568. info_ptr->num_trans = (png_uint_16)num;
  171569. }
  171570. }
  171571. }
  171572. #endif
  171573. }
  171574. void /* PRIVATE */
  171575. png_handle_IEND(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171576. {
  171577. png_debug(1, "in png_handle_IEND\n");
  171578. if (!(png_ptr->mode & PNG_HAVE_IHDR) || !(png_ptr->mode & PNG_HAVE_IDAT))
  171579. {
  171580. png_error(png_ptr, "No image in file");
  171581. }
  171582. png_ptr->mode |= (PNG_AFTER_IDAT | PNG_HAVE_IEND);
  171583. if (length != 0)
  171584. {
  171585. png_warning(png_ptr, "Incorrect IEND chunk length");
  171586. }
  171587. png_crc_finish(png_ptr, length);
  171588. info_ptr =info_ptr; /* quiet compiler warnings about unused info_ptr */
  171589. }
  171590. #if defined(PNG_READ_gAMA_SUPPORTED)
  171591. void /* PRIVATE */
  171592. png_handle_gAMA(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171593. {
  171594. png_fixed_point igamma;
  171595. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171596. float file_gamma;
  171597. #endif
  171598. png_byte buf[4];
  171599. png_debug(1, "in png_handle_gAMA\n");
  171600. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171601. png_error(png_ptr, "Missing IHDR before gAMA");
  171602. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171603. {
  171604. png_warning(png_ptr, "Invalid gAMA after IDAT");
  171605. png_crc_finish(png_ptr, length);
  171606. return;
  171607. }
  171608. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171609. png_warning(png_ptr, "Out of place gAMA chunk");
  171610. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
  171611. #if defined(PNG_READ_sRGB_SUPPORTED)
  171612. && !(info_ptr->valid & PNG_INFO_sRGB)
  171613. #endif
  171614. )
  171615. {
  171616. png_warning(png_ptr, "Duplicate gAMA chunk");
  171617. png_crc_finish(png_ptr, length);
  171618. return;
  171619. }
  171620. if (length != 4)
  171621. {
  171622. png_warning(png_ptr, "Incorrect gAMA chunk length");
  171623. png_crc_finish(png_ptr, length);
  171624. return;
  171625. }
  171626. png_crc_read(png_ptr, buf, 4);
  171627. if (png_crc_finish(png_ptr, 0))
  171628. return;
  171629. igamma = (png_fixed_point)png_get_uint_32(buf);
  171630. if (igamma == 0)
  171631. {
  171632. png_warning(png_ptr,
  171633. "Ignoring gAMA chunk with gamma=0");
  171634. return;
  171635. }
  171636. #if defined(PNG_READ_sRGB_SUPPORTED)
  171637. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB))
  171638. if (PNG_OUT_OF_RANGE(igamma, 45500L, 500))
  171639. {
  171640. png_warning(png_ptr,
  171641. "Ignoring incorrect gAMA value when sRGB is also present");
  171642. #ifndef PNG_NO_CONSOLE_IO
  171643. fprintf(stderr, "gamma = (%d/100000)\n", (int)igamma);
  171644. #endif
  171645. return;
  171646. }
  171647. #endif /* PNG_READ_sRGB_SUPPORTED */
  171648. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171649. file_gamma = (float)igamma / (float)100000.0;
  171650. # ifdef PNG_READ_GAMMA_SUPPORTED
  171651. png_ptr->gamma = file_gamma;
  171652. # endif
  171653. png_set_gAMA(png_ptr, info_ptr, file_gamma);
  171654. #endif
  171655. #ifdef PNG_FIXED_POINT_SUPPORTED
  171656. png_set_gAMA_fixed(png_ptr, info_ptr, igamma);
  171657. #endif
  171658. }
  171659. #endif
  171660. #if defined(PNG_READ_sBIT_SUPPORTED)
  171661. void /* PRIVATE */
  171662. png_handle_sBIT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171663. {
  171664. png_size_t truelen;
  171665. png_byte buf[4];
  171666. png_debug(1, "in png_handle_sBIT\n");
  171667. buf[0] = buf[1] = buf[2] = buf[3] = 0;
  171668. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171669. png_error(png_ptr, "Missing IHDR before sBIT");
  171670. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171671. {
  171672. png_warning(png_ptr, "Invalid sBIT after IDAT");
  171673. png_crc_finish(png_ptr, length);
  171674. return;
  171675. }
  171676. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171677. {
  171678. png_warning(png_ptr, "Out of place sBIT chunk");
  171679. }
  171680. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT))
  171681. {
  171682. png_warning(png_ptr, "Duplicate sBIT chunk");
  171683. png_crc_finish(png_ptr, length);
  171684. return;
  171685. }
  171686. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171687. truelen = 3;
  171688. else
  171689. truelen = (png_size_t)png_ptr->channels;
  171690. if (length != truelen || length > 4)
  171691. {
  171692. png_warning(png_ptr, "Incorrect sBIT chunk length");
  171693. png_crc_finish(png_ptr, length);
  171694. return;
  171695. }
  171696. png_crc_read(png_ptr, buf, truelen);
  171697. if (png_crc_finish(png_ptr, 0))
  171698. return;
  171699. if (png_ptr->color_type & PNG_COLOR_MASK_COLOR)
  171700. {
  171701. png_ptr->sig_bit.red = buf[0];
  171702. png_ptr->sig_bit.green = buf[1];
  171703. png_ptr->sig_bit.blue = buf[2];
  171704. png_ptr->sig_bit.alpha = buf[3];
  171705. }
  171706. else
  171707. {
  171708. png_ptr->sig_bit.gray = buf[0];
  171709. png_ptr->sig_bit.red = buf[0];
  171710. png_ptr->sig_bit.green = buf[0];
  171711. png_ptr->sig_bit.blue = buf[0];
  171712. png_ptr->sig_bit.alpha = buf[1];
  171713. }
  171714. png_set_sBIT(png_ptr, info_ptr, &(png_ptr->sig_bit));
  171715. }
  171716. #endif
  171717. #if defined(PNG_READ_cHRM_SUPPORTED)
  171718. void /* PRIVATE */
  171719. png_handle_cHRM(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171720. {
  171721. png_byte buf[4];
  171722. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171723. float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y;
  171724. #endif
  171725. png_fixed_point int_x_white, int_y_white, int_x_red, int_y_red, int_x_green,
  171726. int_y_green, int_x_blue, int_y_blue;
  171727. png_uint_32 uint_x, uint_y;
  171728. png_debug(1, "in png_handle_cHRM\n");
  171729. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171730. png_error(png_ptr, "Missing IHDR before cHRM");
  171731. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171732. {
  171733. png_warning(png_ptr, "Invalid cHRM after IDAT");
  171734. png_crc_finish(png_ptr, length);
  171735. return;
  171736. }
  171737. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171738. png_warning(png_ptr, "Missing PLTE before cHRM");
  171739. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM)
  171740. #if defined(PNG_READ_sRGB_SUPPORTED)
  171741. && !(info_ptr->valid & PNG_INFO_sRGB)
  171742. #endif
  171743. )
  171744. {
  171745. png_warning(png_ptr, "Duplicate cHRM chunk");
  171746. png_crc_finish(png_ptr, length);
  171747. return;
  171748. }
  171749. if (length != 32)
  171750. {
  171751. png_warning(png_ptr, "Incorrect cHRM chunk length");
  171752. png_crc_finish(png_ptr, length);
  171753. return;
  171754. }
  171755. png_crc_read(png_ptr, buf, 4);
  171756. uint_x = png_get_uint_32(buf);
  171757. png_crc_read(png_ptr, buf, 4);
  171758. uint_y = png_get_uint_32(buf);
  171759. if (uint_x > 80000L || uint_y > 80000L ||
  171760. uint_x + uint_y > 100000L)
  171761. {
  171762. png_warning(png_ptr, "Invalid cHRM white point");
  171763. png_crc_finish(png_ptr, 24);
  171764. return;
  171765. }
  171766. int_x_white = (png_fixed_point)uint_x;
  171767. int_y_white = (png_fixed_point)uint_y;
  171768. png_crc_read(png_ptr, buf, 4);
  171769. uint_x = png_get_uint_32(buf);
  171770. png_crc_read(png_ptr, buf, 4);
  171771. uint_y = png_get_uint_32(buf);
  171772. if (uint_x + uint_y > 100000L)
  171773. {
  171774. png_warning(png_ptr, "Invalid cHRM red point");
  171775. png_crc_finish(png_ptr, 16);
  171776. return;
  171777. }
  171778. int_x_red = (png_fixed_point)uint_x;
  171779. int_y_red = (png_fixed_point)uint_y;
  171780. png_crc_read(png_ptr, buf, 4);
  171781. uint_x = png_get_uint_32(buf);
  171782. png_crc_read(png_ptr, buf, 4);
  171783. uint_y = png_get_uint_32(buf);
  171784. if (uint_x + uint_y > 100000L)
  171785. {
  171786. png_warning(png_ptr, "Invalid cHRM green point");
  171787. png_crc_finish(png_ptr, 8);
  171788. return;
  171789. }
  171790. int_x_green = (png_fixed_point)uint_x;
  171791. int_y_green = (png_fixed_point)uint_y;
  171792. png_crc_read(png_ptr, buf, 4);
  171793. uint_x = png_get_uint_32(buf);
  171794. png_crc_read(png_ptr, buf, 4);
  171795. uint_y = png_get_uint_32(buf);
  171796. if (uint_x + uint_y > 100000L)
  171797. {
  171798. png_warning(png_ptr, "Invalid cHRM blue point");
  171799. png_crc_finish(png_ptr, 0);
  171800. return;
  171801. }
  171802. int_x_blue = (png_fixed_point)uint_x;
  171803. int_y_blue = (png_fixed_point)uint_y;
  171804. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171805. white_x = (float)int_x_white / (float)100000.0;
  171806. white_y = (float)int_y_white / (float)100000.0;
  171807. red_x = (float)int_x_red / (float)100000.0;
  171808. red_y = (float)int_y_red / (float)100000.0;
  171809. green_x = (float)int_x_green / (float)100000.0;
  171810. green_y = (float)int_y_green / (float)100000.0;
  171811. blue_x = (float)int_x_blue / (float)100000.0;
  171812. blue_y = (float)int_y_blue / (float)100000.0;
  171813. #endif
  171814. #if defined(PNG_READ_sRGB_SUPPORTED)
  171815. if ((info_ptr != NULL) && (info_ptr->valid & PNG_INFO_sRGB))
  171816. {
  171817. if (PNG_OUT_OF_RANGE(int_x_white, 31270, 1000) ||
  171818. PNG_OUT_OF_RANGE(int_y_white, 32900, 1000) ||
  171819. PNG_OUT_OF_RANGE(int_x_red, 64000L, 1000) ||
  171820. PNG_OUT_OF_RANGE(int_y_red, 33000, 1000) ||
  171821. PNG_OUT_OF_RANGE(int_x_green, 30000, 1000) ||
  171822. PNG_OUT_OF_RANGE(int_y_green, 60000L, 1000) ||
  171823. PNG_OUT_OF_RANGE(int_x_blue, 15000, 1000) ||
  171824. PNG_OUT_OF_RANGE(int_y_blue, 6000, 1000))
  171825. {
  171826. png_warning(png_ptr,
  171827. "Ignoring incorrect cHRM value when sRGB is also present");
  171828. #ifndef PNG_NO_CONSOLE_IO
  171829. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171830. fprintf(stderr,"wx=%f, wy=%f, rx=%f, ry=%f\n",
  171831. white_x, white_y, red_x, red_y);
  171832. fprintf(stderr,"gx=%f, gy=%f, bx=%f, by=%f\n",
  171833. green_x, green_y, blue_x, blue_y);
  171834. #else
  171835. fprintf(stderr,"wx=%ld, wy=%ld, rx=%ld, ry=%ld\n",
  171836. int_x_white, int_y_white, int_x_red, int_y_red);
  171837. fprintf(stderr,"gx=%ld, gy=%ld, bx=%ld, by=%ld\n",
  171838. int_x_green, int_y_green, int_x_blue, int_y_blue);
  171839. #endif
  171840. #endif /* PNG_NO_CONSOLE_IO */
  171841. }
  171842. png_crc_finish(png_ptr, 0);
  171843. return;
  171844. }
  171845. #endif /* PNG_READ_sRGB_SUPPORTED */
  171846. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171847. png_set_cHRM(png_ptr, info_ptr,
  171848. white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y);
  171849. #endif
  171850. #ifdef PNG_FIXED_POINT_SUPPORTED
  171851. png_set_cHRM_fixed(png_ptr, info_ptr,
  171852. int_x_white, int_y_white, int_x_red, int_y_red, int_x_green,
  171853. int_y_green, int_x_blue, int_y_blue);
  171854. #endif
  171855. if (png_crc_finish(png_ptr, 0))
  171856. return;
  171857. }
  171858. #endif
  171859. #if defined(PNG_READ_sRGB_SUPPORTED)
  171860. void /* PRIVATE */
  171861. png_handle_sRGB(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171862. {
  171863. int intent;
  171864. png_byte buf[1];
  171865. png_debug(1, "in png_handle_sRGB\n");
  171866. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171867. png_error(png_ptr, "Missing IHDR before sRGB");
  171868. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171869. {
  171870. png_warning(png_ptr, "Invalid sRGB after IDAT");
  171871. png_crc_finish(png_ptr, length);
  171872. return;
  171873. }
  171874. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171875. png_warning(png_ptr, "Out of place sRGB chunk");
  171876. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB))
  171877. {
  171878. png_warning(png_ptr, "Duplicate sRGB chunk");
  171879. png_crc_finish(png_ptr, length);
  171880. return;
  171881. }
  171882. if (length != 1)
  171883. {
  171884. png_warning(png_ptr, "Incorrect sRGB chunk length");
  171885. png_crc_finish(png_ptr, length);
  171886. return;
  171887. }
  171888. png_crc_read(png_ptr, buf, 1);
  171889. if (png_crc_finish(png_ptr, 0))
  171890. return;
  171891. intent = buf[0];
  171892. if (intent >= PNG_sRGB_INTENT_LAST)
  171893. {
  171894. png_warning(png_ptr, "Unknown sRGB intent");
  171895. return;
  171896. }
  171897. #if defined(PNG_READ_gAMA_SUPPORTED) && defined(PNG_READ_GAMMA_SUPPORTED)
  171898. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA))
  171899. {
  171900. png_fixed_point igamma;
  171901. #ifdef PNG_FIXED_POINT_SUPPORTED
  171902. igamma=info_ptr->int_gamma;
  171903. #else
  171904. # ifdef PNG_FLOATING_POINT_SUPPORTED
  171905. igamma=(png_fixed_point)(info_ptr->gamma * 100000.);
  171906. # endif
  171907. #endif
  171908. if (PNG_OUT_OF_RANGE(igamma, 45500L, 500))
  171909. {
  171910. png_warning(png_ptr,
  171911. "Ignoring incorrect gAMA value when sRGB is also present");
  171912. #ifndef PNG_NO_CONSOLE_IO
  171913. # ifdef PNG_FIXED_POINT_SUPPORTED
  171914. fprintf(stderr,"incorrect gamma=(%d/100000)\n",(int)png_ptr->int_gamma);
  171915. # else
  171916. # ifdef PNG_FLOATING_POINT_SUPPORTED
  171917. fprintf(stderr,"incorrect gamma=%f\n",png_ptr->gamma);
  171918. # endif
  171919. # endif
  171920. #endif
  171921. }
  171922. }
  171923. #endif /* PNG_READ_gAMA_SUPPORTED */
  171924. #ifdef PNG_READ_cHRM_SUPPORTED
  171925. #ifdef PNG_FIXED_POINT_SUPPORTED
  171926. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
  171927. if (PNG_OUT_OF_RANGE(info_ptr->int_x_white, 31270, 1000) ||
  171928. PNG_OUT_OF_RANGE(info_ptr->int_y_white, 32900, 1000) ||
  171929. PNG_OUT_OF_RANGE(info_ptr->int_x_red, 64000L, 1000) ||
  171930. PNG_OUT_OF_RANGE(info_ptr->int_y_red, 33000, 1000) ||
  171931. PNG_OUT_OF_RANGE(info_ptr->int_x_green, 30000, 1000) ||
  171932. PNG_OUT_OF_RANGE(info_ptr->int_y_green, 60000L, 1000) ||
  171933. PNG_OUT_OF_RANGE(info_ptr->int_x_blue, 15000, 1000) ||
  171934. PNG_OUT_OF_RANGE(info_ptr->int_y_blue, 6000, 1000))
  171935. {
  171936. png_warning(png_ptr,
  171937. "Ignoring incorrect cHRM value when sRGB is also present");
  171938. }
  171939. #endif /* PNG_FIXED_POINT_SUPPORTED */
  171940. #endif /* PNG_READ_cHRM_SUPPORTED */
  171941. png_set_sRGB_gAMA_and_cHRM(png_ptr, info_ptr, intent);
  171942. }
  171943. #endif /* PNG_READ_sRGB_SUPPORTED */
  171944. #if defined(PNG_READ_iCCP_SUPPORTED)
  171945. void /* PRIVATE */
  171946. png_handle_iCCP(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171947. {
  171948. png_charp chunkdata;
  171949. png_byte compression_type;
  171950. png_bytep pC;
  171951. png_charp profile;
  171952. png_uint_32 skip = 0;
  171953. png_uint_32 profile_size, profile_length;
  171954. png_size_t slength, prefix_length, data_length;
  171955. png_debug(1, "in png_handle_iCCP\n");
  171956. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171957. png_error(png_ptr, "Missing IHDR before iCCP");
  171958. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171959. {
  171960. png_warning(png_ptr, "Invalid iCCP after IDAT");
  171961. png_crc_finish(png_ptr, length);
  171962. return;
  171963. }
  171964. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171965. png_warning(png_ptr, "Out of place iCCP chunk");
  171966. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP))
  171967. {
  171968. png_warning(png_ptr, "Duplicate iCCP chunk");
  171969. png_crc_finish(png_ptr, length);
  171970. return;
  171971. }
  171972. #ifdef PNG_MAX_MALLOC_64K
  171973. if (length > (png_uint_32)65535L)
  171974. {
  171975. png_warning(png_ptr, "iCCP chunk too large to fit in memory");
  171976. skip = length - (png_uint_32)65535L;
  171977. length = (png_uint_32)65535L;
  171978. }
  171979. #endif
  171980. chunkdata = (png_charp)png_malloc(png_ptr, length + 1);
  171981. slength = (png_size_t)length;
  171982. png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
  171983. if (png_crc_finish(png_ptr, skip))
  171984. {
  171985. png_free(png_ptr, chunkdata);
  171986. return;
  171987. }
  171988. chunkdata[slength] = 0x00;
  171989. for (profile = chunkdata; *profile; profile++)
  171990. ;
  171991. ++profile;
  171992. if ( profile >= chunkdata + slength - 1)
  171993. {
  171994. png_free(png_ptr, chunkdata);
  171995. png_warning(png_ptr, "Malformed iCCP chunk");
  171996. return;
  171997. }
  171998. compression_type = *profile++;
  171999. if (compression_type)
  172000. {
  172001. png_warning(png_ptr, "Ignoring nonzero compression type in iCCP chunk");
  172002. compression_type=0x00; /* Reset it to zero (libpng-1.0.6 through 1.0.8
  172003. wrote nonzero) */
  172004. }
  172005. prefix_length = profile - chunkdata;
  172006. chunkdata = png_decompress_chunk(png_ptr, compression_type, chunkdata,
  172007. slength, prefix_length, &data_length);
  172008. profile_length = data_length - prefix_length;
  172009. if ( prefix_length > data_length || profile_length < 4)
  172010. {
  172011. png_free(png_ptr, chunkdata);
  172012. png_warning(png_ptr, "Profile size field missing from iCCP chunk");
  172013. return;
  172014. }
  172015. pC = (png_bytep)(chunkdata+prefix_length);
  172016. profile_size = ((*(pC ))<<24) |
  172017. ((*(pC+1))<<16) |
  172018. ((*(pC+2))<< 8) |
  172019. ((*(pC+3)) );
  172020. if(profile_size < profile_length)
  172021. profile_length = profile_size;
  172022. if(profile_size > profile_length)
  172023. {
  172024. png_free(png_ptr, chunkdata);
  172025. png_warning(png_ptr, "Ignoring truncated iCCP profile.");
  172026. return;
  172027. }
  172028. png_set_iCCP(png_ptr, info_ptr, chunkdata, compression_type,
  172029. chunkdata + prefix_length, profile_length);
  172030. png_free(png_ptr, chunkdata);
  172031. }
  172032. #endif /* PNG_READ_iCCP_SUPPORTED */
  172033. #if defined(PNG_READ_sPLT_SUPPORTED)
  172034. void /* PRIVATE */
  172035. png_handle_sPLT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172036. {
  172037. png_bytep chunkdata;
  172038. png_bytep entry_start;
  172039. png_sPLT_t new_palette;
  172040. #ifdef PNG_NO_POINTER_INDEXING
  172041. png_sPLT_entryp pp;
  172042. #endif
  172043. int data_length, entry_size, i;
  172044. png_uint_32 skip = 0;
  172045. png_size_t slength;
  172046. png_debug(1, "in png_handle_sPLT\n");
  172047. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172048. png_error(png_ptr, "Missing IHDR before sPLT");
  172049. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172050. {
  172051. png_warning(png_ptr, "Invalid sPLT after IDAT");
  172052. png_crc_finish(png_ptr, length);
  172053. return;
  172054. }
  172055. #ifdef PNG_MAX_MALLOC_64K
  172056. if (length > (png_uint_32)65535L)
  172057. {
  172058. png_warning(png_ptr, "sPLT chunk too large to fit in memory");
  172059. skip = length - (png_uint_32)65535L;
  172060. length = (png_uint_32)65535L;
  172061. }
  172062. #endif
  172063. chunkdata = (png_bytep)png_malloc(png_ptr, length + 1);
  172064. slength = (png_size_t)length;
  172065. png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
  172066. if (png_crc_finish(png_ptr, skip))
  172067. {
  172068. png_free(png_ptr, chunkdata);
  172069. return;
  172070. }
  172071. chunkdata[slength] = 0x00;
  172072. for (entry_start = chunkdata; *entry_start; entry_start++)
  172073. ;
  172074. ++entry_start;
  172075. if (entry_start > chunkdata + slength - 2)
  172076. {
  172077. png_free(png_ptr, chunkdata);
  172078. png_warning(png_ptr, "malformed sPLT chunk");
  172079. return;
  172080. }
  172081. new_palette.depth = *entry_start++;
  172082. entry_size = (new_palette.depth == 8 ? 6 : 10);
  172083. data_length = (slength - (entry_start - chunkdata));
  172084. if (data_length % entry_size)
  172085. {
  172086. png_free(png_ptr, chunkdata);
  172087. png_warning(png_ptr, "sPLT chunk has bad length");
  172088. return;
  172089. }
  172090. new_palette.nentries = (png_int_32) ( data_length / entry_size);
  172091. if ((png_uint_32) new_palette.nentries > (png_uint_32) (PNG_SIZE_MAX /
  172092. png_sizeof(png_sPLT_entry)))
  172093. {
  172094. png_warning(png_ptr, "sPLT chunk too long");
  172095. return;
  172096. }
  172097. new_palette.entries = (png_sPLT_entryp)png_malloc_warn(
  172098. png_ptr, new_palette.nentries * png_sizeof(png_sPLT_entry));
  172099. if (new_palette.entries == NULL)
  172100. {
  172101. png_warning(png_ptr, "sPLT chunk requires too much memory");
  172102. return;
  172103. }
  172104. #ifndef PNG_NO_POINTER_INDEXING
  172105. for (i = 0; i < new_palette.nentries; i++)
  172106. {
  172107. png_sPLT_entryp pp = new_palette.entries + i;
  172108. if (new_palette.depth == 8)
  172109. {
  172110. pp->red = *entry_start++;
  172111. pp->green = *entry_start++;
  172112. pp->blue = *entry_start++;
  172113. pp->alpha = *entry_start++;
  172114. }
  172115. else
  172116. {
  172117. pp->red = png_get_uint_16(entry_start); entry_start += 2;
  172118. pp->green = png_get_uint_16(entry_start); entry_start += 2;
  172119. pp->blue = png_get_uint_16(entry_start); entry_start += 2;
  172120. pp->alpha = png_get_uint_16(entry_start); entry_start += 2;
  172121. }
  172122. pp->frequency = png_get_uint_16(entry_start); entry_start += 2;
  172123. }
  172124. #else
  172125. pp = new_palette.entries;
  172126. for (i = 0; i < new_palette.nentries; i++)
  172127. {
  172128. if (new_palette.depth == 8)
  172129. {
  172130. pp[i].red = *entry_start++;
  172131. pp[i].green = *entry_start++;
  172132. pp[i].blue = *entry_start++;
  172133. pp[i].alpha = *entry_start++;
  172134. }
  172135. else
  172136. {
  172137. pp[i].red = png_get_uint_16(entry_start); entry_start += 2;
  172138. pp[i].green = png_get_uint_16(entry_start); entry_start += 2;
  172139. pp[i].blue = png_get_uint_16(entry_start); entry_start += 2;
  172140. pp[i].alpha = png_get_uint_16(entry_start); entry_start += 2;
  172141. }
  172142. pp->frequency = png_get_uint_16(entry_start); entry_start += 2;
  172143. }
  172144. #endif
  172145. new_palette.name = (png_charp)chunkdata;
  172146. png_set_sPLT(png_ptr, info_ptr, &new_palette, 1);
  172147. png_free(png_ptr, chunkdata);
  172148. png_free(png_ptr, new_palette.entries);
  172149. }
  172150. #endif /* PNG_READ_sPLT_SUPPORTED */
  172151. #if defined(PNG_READ_tRNS_SUPPORTED)
  172152. void /* PRIVATE */
  172153. png_handle_tRNS(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172154. {
  172155. png_byte readbuf[PNG_MAX_PALETTE_LENGTH];
  172156. int bit_mask;
  172157. png_debug(1, "in png_handle_tRNS\n");
  172158. bit_mask = (1 << png_ptr->bit_depth) - 1;
  172159. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172160. png_error(png_ptr, "Missing IHDR before tRNS");
  172161. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172162. {
  172163. png_warning(png_ptr, "Invalid tRNS after IDAT");
  172164. png_crc_finish(png_ptr, length);
  172165. return;
  172166. }
  172167. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
  172168. {
  172169. png_warning(png_ptr, "Duplicate tRNS chunk");
  172170. png_crc_finish(png_ptr, length);
  172171. return;
  172172. }
  172173. if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
  172174. {
  172175. png_byte buf[2];
  172176. if (length != 2)
  172177. {
  172178. png_warning(png_ptr, "Incorrect tRNS chunk length");
  172179. png_crc_finish(png_ptr, length);
  172180. return;
  172181. }
  172182. png_crc_read(png_ptr, buf, 2);
  172183. png_ptr->num_trans = 1;
  172184. png_ptr->trans_values.gray = png_get_uint_16(buf) & bit_mask;
  172185. }
  172186. else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
  172187. {
  172188. png_byte buf[6];
  172189. if (length != 6)
  172190. {
  172191. png_warning(png_ptr, "Incorrect tRNS chunk length");
  172192. png_crc_finish(png_ptr, length);
  172193. return;
  172194. }
  172195. png_crc_read(png_ptr, buf, (png_size_t)length);
  172196. png_ptr->num_trans = 1;
  172197. png_ptr->trans_values.red = png_get_uint_16(buf) & bit_mask;
  172198. png_ptr->trans_values.green = png_get_uint_16(buf + 2) & bit_mask;
  172199. png_ptr->trans_values.blue = png_get_uint_16(buf + 4) & bit_mask;
  172200. }
  172201. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  172202. {
  172203. if (!(png_ptr->mode & PNG_HAVE_PLTE))
  172204. {
  172205. png_warning(png_ptr, "Missing PLTE before tRNS");
  172206. }
  172207. if (length > (png_uint_32)png_ptr->num_palette ||
  172208. length > PNG_MAX_PALETTE_LENGTH)
  172209. {
  172210. png_warning(png_ptr, "Incorrect tRNS chunk length");
  172211. png_crc_finish(png_ptr, length);
  172212. return;
  172213. }
  172214. if (length == 0)
  172215. {
  172216. png_warning(png_ptr, "Zero length tRNS chunk");
  172217. png_crc_finish(png_ptr, length);
  172218. return;
  172219. }
  172220. png_crc_read(png_ptr, readbuf, (png_size_t)length);
  172221. png_ptr->num_trans = (png_uint_16)length;
  172222. }
  172223. else
  172224. {
  172225. png_warning(png_ptr, "tRNS chunk not allowed with alpha channel");
  172226. png_crc_finish(png_ptr, length);
  172227. return;
  172228. }
  172229. if (png_crc_finish(png_ptr, 0))
  172230. {
  172231. png_ptr->num_trans = 0;
  172232. return;
  172233. }
  172234. png_set_tRNS(png_ptr, info_ptr, readbuf, png_ptr->num_trans,
  172235. &(png_ptr->trans_values));
  172236. }
  172237. #endif
  172238. #if defined(PNG_READ_bKGD_SUPPORTED)
  172239. void /* PRIVATE */
  172240. png_handle_bKGD(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172241. {
  172242. png_size_t truelen;
  172243. png_byte buf[6];
  172244. png_debug(1, "in png_handle_bKGD\n");
  172245. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172246. png_error(png_ptr, "Missing IHDR before bKGD");
  172247. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172248. {
  172249. png_warning(png_ptr, "Invalid bKGD after IDAT");
  172250. png_crc_finish(png_ptr, length);
  172251. return;
  172252. }
  172253. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  172254. !(png_ptr->mode & PNG_HAVE_PLTE))
  172255. {
  172256. png_warning(png_ptr, "Missing PLTE before bKGD");
  172257. png_crc_finish(png_ptr, length);
  172258. return;
  172259. }
  172260. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD))
  172261. {
  172262. png_warning(png_ptr, "Duplicate bKGD chunk");
  172263. png_crc_finish(png_ptr, length);
  172264. return;
  172265. }
  172266. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  172267. truelen = 1;
  172268. else if (png_ptr->color_type & PNG_COLOR_MASK_COLOR)
  172269. truelen = 6;
  172270. else
  172271. truelen = 2;
  172272. if (length != truelen)
  172273. {
  172274. png_warning(png_ptr, "Incorrect bKGD chunk length");
  172275. png_crc_finish(png_ptr, length);
  172276. return;
  172277. }
  172278. png_crc_read(png_ptr, buf, truelen);
  172279. if (png_crc_finish(png_ptr, 0))
  172280. return;
  172281. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  172282. {
  172283. png_ptr->background.index = buf[0];
  172284. if(info_ptr->num_palette)
  172285. {
  172286. if(buf[0] > info_ptr->num_palette)
  172287. {
  172288. png_warning(png_ptr, "Incorrect bKGD chunk index value");
  172289. return;
  172290. }
  172291. png_ptr->background.red =
  172292. (png_uint_16)png_ptr->palette[buf[0]].red;
  172293. png_ptr->background.green =
  172294. (png_uint_16)png_ptr->palette[buf[0]].green;
  172295. png_ptr->background.blue =
  172296. (png_uint_16)png_ptr->palette[buf[0]].blue;
  172297. }
  172298. }
  172299. else if (!(png_ptr->color_type & PNG_COLOR_MASK_COLOR)) /* GRAY */
  172300. {
  172301. png_ptr->background.red =
  172302. png_ptr->background.green =
  172303. png_ptr->background.blue =
  172304. png_ptr->background.gray = png_get_uint_16(buf);
  172305. }
  172306. else
  172307. {
  172308. png_ptr->background.red = png_get_uint_16(buf);
  172309. png_ptr->background.green = png_get_uint_16(buf + 2);
  172310. png_ptr->background.blue = png_get_uint_16(buf + 4);
  172311. }
  172312. png_set_bKGD(png_ptr, info_ptr, &(png_ptr->background));
  172313. }
  172314. #endif
  172315. #if defined(PNG_READ_hIST_SUPPORTED)
  172316. void /* PRIVATE */
  172317. png_handle_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172318. {
  172319. unsigned int num, i;
  172320. png_uint_16 readbuf[PNG_MAX_PALETTE_LENGTH];
  172321. png_debug(1, "in png_handle_hIST\n");
  172322. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172323. png_error(png_ptr, "Missing IHDR before hIST");
  172324. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172325. {
  172326. png_warning(png_ptr, "Invalid hIST after IDAT");
  172327. png_crc_finish(png_ptr, length);
  172328. return;
  172329. }
  172330. else if (!(png_ptr->mode & PNG_HAVE_PLTE))
  172331. {
  172332. png_warning(png_ptr, "Missing PLTE before hIST");
  172333. png_crc_finish(png_ptr, length);
  172334. return;
  172335. }
  172336. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST))
  172337. {
  172338. png_warning(png_ptr, "Duplicate hIST chunk");
  172339. png_crc_finish(png_ptr, length);
  172340. return;
  172341. }
  172342. num = length / 2 ;
  172343. if (num != (unsigned int) png_ptr->num_palette || num >
  172344. (unsigned int) PNG_MAX_PALETTE_LENGTH)
  172345. {
  172346. png_warning(png_ptr, "Incorrect hIST chunk length");
  172347. png_crc_finish(png_ptr, length);
  172348. return;
  172349. }
  172350. for (i = 0; i < num; i++)
  172351. {
  172352. png_byte buf[2];
  172353. png_crc_read(png_ptr, buf, 2);
  172354. readbuf[i] = png_get_uint_16(buf);
  172355. }
  172356. if (png_crc_finish(png_ptr, 0))
  172357. return;
  172358. png_set_hIST(png_ptr, info_ptr, readbuf);
  172359. }
  172360. #endif
  172361. #if defined(PNG_READ_pHYs_SUPPORTED)
  172362. void /* PRIVATE */
  172363. png_handle_pHYs(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172364. {
  172365. png_byte buf[9];
  172366. png_uint_32 res_x, res_y;
  172367. int unit_type;
  172368. png_debug(1, "in png_handle_pHYs\n");
  172369. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172370. png_error(png_ptr, "Missing IHDR before pHYs");
  172371. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172372. {
  172373. png_warning(png_ptr, "Invalid pHYs after IDAT");
  172374. png_crc_finish(png_ptr, length);
  172375. return;
  172376. }
  172377. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
  172378. {
  172379. png_warning(png_ptr, "Duplicate pHYs chunk");
  172380. png_crc_finish(png_ptr, length);
  172381. return;
  172382. }
  172383. if (length != 9)
  172384. {
  172385. png_warning(png_ptr, "Incorrect pHYs chunk length");
  172386. png_crc_finish(png_ptr, length);
  172387. return;
  172388. }
  172389. png_crc_read(png_ptr, buf, 9);
  172390. if (png_crc_finish(png_ptr, 0))
  172391. return;
  172392. res_x = png_get_uint_32(buf);
  172393. res_y = png_get_uint_32(buf + 4);
  172394. unit_type = buf[8];
  172395. png_set_pHYs(png_ptr, info_ptr, res_x, res_y, unit_type);
  172396. }
  172397. #endif
  172398. #if defined(PNG_READ_oFFs_SUPPORTED)
  172399. void /* PRIVATE */
  172400. png_handle_oFFs(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172401. {
  172402. png_byte buf[9];
  172403. png_int_32 offset_x, offset_y;
  172404. int unit_type;
  172405. png_debug(1, "in png_handle_oFFs\n");
  172406. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172407. png_error(png_ptr, "Missing IHDR before oFFs");
  172408. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172409. {
  172410. png_warning(png_ptr, "Invalid oFFs after IDAT");
  172411. png_crc_finish(png_ptr, length);
  172412. return;
  172413. }
  172414. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
  172415. {
  172416. png_warning(png_ptr, "Duplicate oFFs chunk");
  172417. png_crc_finish(png_ptr, length);
  172418. return;
  172419. }
  172420. if (length != 9)
  172421. {
  172422. png_warning(png_ptr, "Incorrect oFFs chunk length");
  172423. png_crc_finish(png_ptr, length);
  172424. return;
  172425. }
  172426. png_crc_read(png_ptr, buf, 9);
  172427. if (png_crc_finish(png_ptr, 0))
  172428. return;
  172429. offset_x = png_get_int_32(buf);
  172430. offset_y = png_get_int_32(buf + 4);
  172431. unit_type = buf[8];
  172432. png_set_oFFs(png_ptr, info_ptr, offset_x, offset_y, unit_type);
  172433. }
  172434. #endif
  172435. #if defined(PNG_READ_pCAL_SUPPORTED)
  172436. void /* PRIVATE */
  172437. png_handle_pCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172438. {
  172439. png_charp purpose;
  172440. png_int_32 X0, X1;
  172441. png_byte type, nparams;
  172442. png_charp buf, units, endptr;
  172443. png_charpp params;
  172444. png_size_t slength;
  172445. int i;
  172446. png_debug(1, "in png_handle_pCAL\n");
  172447. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172448. png_error(png_ptr, "Missing IHDR before pCAL");
  172449. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172450. {
  172451. png_warning(png_ptr, "Invalid pCAL after IDAT");
  172452. png_crc_finish(png_ptr, length);
  172453. return;
  172454. }
  172455. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL))
  172456. {
  172457. png_warning(png_ptr, "Duplicate pCAL chunk");
  172458. png_crc_finish(png_ptr, length);
  172459. return;
  172460. }
  172461. png_debug1(2, "Allocating and reading pCAL chunk data (%lu bytes)\n",
  172462. length + 1);
  172463. purpose = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172464. if (purpose == NULL)
  172465. {
  172466. png_warning(png_ptr, "No memory for pCAL purpose.");
  172467. return;
  172468. }
  172469. slength = (png_size_t)length;
  172470. png_crc_read(png_ptr, (png_bytep)purpose, slength);
  172471. if (png_crc_finish(png_ptr, 0))
  172472. {
  172473. png_free(png_ptr, purpose);
  172474. return;
  172475. }
  172476. purpose[slength] = 0x00; /* null terminate the last string */
  172477. png_debug(3, "Finding end of pCAL purpose string\n");
  172478. for (buf = purpose; *buf; buf++)
  172479. ;
  172480. endptr = purpose + slength;
  172481. if (endptr <= buf + 12)
  172482. {
  172483. png_warning(png_ptr, "Invalid pCAL data");
  172484. png_free(png_ptr, purpose);
  172485. return;
  172486. }
  172487. png_debug(3, "Reading pCAL X0, X1, type, nparams, and units\n");
  172488. X0 = png_get_int_32((png_bytep)buf+1);
  172489. X1 = png_get_int_32((png_bytep)buf+5);
  172490. type = buf[9];
  172491. nparams = buf[10];
  172492. units = buf + 11;
  172493. png_debug(3, "Checking pCAL equation type and number of parameters\n");
  172494. if ((type == PNG_EQUATION_LINEAR && nparams != 2) ||
  172495. (type == PNG_EQUATION_BASE_E && nparams != 3) ||
  172496. (type == PNG_EQUATION_ARBITRARY && nparams != 3) ||
  172497. (type == PNG_EQUATION_HYPERBOLIC && nparams != 4))
  172498. {
  172499. png_warning(png_ptr, "Invalid pCAL parameters for equation type");
  172500. png_free(png_ptr, purpose);
  172501. return;
  172502. }
  172503. else if (type >= PNG_EQUATION_LAST)
  172504. {
  172505. png_warning(png_ptr, "Unrecognized equation type for pCAL chunk");
  172506. }
  172507. for (buf = units; *buf; buf++)
  172508. ;
  172509. png_debug(3, "Allocating pCAL parameters array\n");
  172510. params = (png_charpp)png_malloc_warn(png_ptr, (png_uint_32)(nparams
  172511. *png_sizeof(png_charp))) ;
  172512. if (params == NULL)
  172513. {
  172514. png_free(png_ptr, purpose);
  172515. png_warning(png_ptr, "No memory for pCAL params.");
  172516. return;
  172517. }
  172518. for (i = 0; i < (int)nparams; i++)
  172519. {
  172520. buf++; /* Skip the null string terminator from previous parameter. */
  172521. png_debug1(3, "Reading pCAL parameter %d\n", i);
  172522. for (params[i] = buf; buf <= endptr && *buf != 0x00; buf++)
  172523. ;
  172524. if (buf > endptr)
  172525. {
  172526. png_warning(png_ptr, "Invalid pCAL data");
  172527. png_free(png_ptr, purpose);
  172528. png_free(png_ptr, params);
  172529. return;
  172530. }
  172531. }
  172532. png_set_pCAL(png_ptr, info_ptr, purpose, X0, X1, type, nparams,
  172533. units, params);
  172534. png_free(png_ptr, purpose);
  172535. png_free(png_ptr, params);
  172536. }
  172537. #endif
  172538. #if defined(PNG_READ_sCAL_SUPPORTED)
  172539. void /* PRIVATE */
  172540. png_handle_sCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172541. {
  172542. png_charp buffer, ep;
  172543. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172544. double width, height;
  172545. png_charp vp;
  172546. #else
  172547. #ifdef PNG_FIXED_POINT_SUPPORTED
  172548. png_charp swidth, sheight;
  172549. #endif
  172550. #endif
  172551. png_size_t slength;
  172552. png_debug(1, "in png_handle_sCAL\n");
  172553. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172554. png_error(png_ptr, "Missing IHDR before sCAL");
  172555. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172556. {
  172557. png_warning(png_ptr, "Invalid sCAL after IDAT");
  172558. png_crc_finish(png_ptr, length);
  172559. return;
  172560. }
  172561. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sCAL))
  172562. {
  172563. png_warning(png_ptr, "Duplicate sCAL chunk");
  172564. png_crc_finish(png_ptr, length);
  172565. return;
  172566. }
  172567. png_debug1(2, "Allocating and reading sCAL chunk data (%lu bytes)\n",
  172568. length + 1);
  172569. buffer = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172570. if (buffer == NULL)
  172571. {
  172572. png_warning(png_ptr, "Out of memory while processing sCAL chunk");
  172573. return;
  172574. }
  172575. slength = (png_size_t)length;
  172576. png_crc_read(png_ptr, (png_bytep)buffer, slength);
  172577. if (png_crc_finish(png_ptr, 0))
  172578. {
  172579. png_free(png_ptr, buffer);
  172580. return;
  172581. }
  172582. buffer[slength] = 0x00; /* null terminate the last string */
  172583. ep = buffer + 1; /* skip unit byte */
  172584. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172585. width = png_strtod(png_ptr, ep, &vp);
  172586. if (*vp)
  172587. {
  172588. png_warning(png_ptr, "malformed width string in sCAL chunk");
  172589. return;
  172590. }
  172591. #else
  172592. #ifdef PNG_FIXED_POINT_SUPPORTED
  172593. swidth = (png_charp)png_malloc_warn(png_ptr, png_strlen(ep) + 1);
  172594. if (swidth == NULL)
  172595. {
  172596. png_warning(png_ptr, "Out of memory while processing sCAL chunk width");
  172597. return;
  172598. }
  172599. png_memcpy(swidth, ep, (png_size_t)png_strlen(ep));
  172600. #endif
  172601. #endif
  172602. for (ep = buffer; *ep; ep++)
  172603. ;
  172604. ep++;
  172605. if (buffer + slength < ep)
  172606. {
  172607. png_warning(png_ptr, "Truncated sCAL chunk");
  172608. #if defined(PNG_FIXED_POINT_SUPPORTED) && \
  172609. !defined(PNG_FLOATING_POINT_SUPPORTED)
  172610. png_free(png_ptr, swidth);
  172611. #endif
  172612. png_free(png_ptr, buffer);
  172613. return;
  172614. }
  172615. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172616. height = png_strtod(png_ptr, ep, &vp);
  172617. if (*vp)
  172618. {
  172619. png_warning(png_ptr, "malformed height string in sCAL chunk");
  172620. return;
  172621. }
  172622. #else
  172623. #ifdef PNG_FIXED_POINT_SUPPORTED
  172624. sheight = (png_charp)png_malloc_warn(png_ptr, png_strlen(ep) + 1);
  172625. if (swidth == NULL)
  172626. {
  172627. png_warning(png_ptr, "Out of memory while processing sCAL chunk height");
  172628. return;
  172629. }
  172630. png_memcpy(sheight, ep, (png_size_t)png_strlen(ep));
  172631. #endif
  172632. #endif
  172633. if (buffer + slength < ep
  172634. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172635. || width <= 0. || height <= 0.
  172636. #endif
  172637. )
  172638. {
  172639. png_warning(png_ptr, "Invalid sCAL data");
  172640. png_free(png_ptr, buffer);
  172641. #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
  172642. png_free(png_ptr, swidth);
  172643. png_free(png_ptr, sheight);
  172644. #endif
  172645. return;
  172646. }
  172647. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172648. png_set_sCAL(png_ptr, info_ptr, buffer[0], width, height);
  172649. #else
  172650. #ifdef PNG_FIXED_POINT_SUPPORTED
  172651. png_set_sCAL_s(png_ptr, info_ptr, buffer[0], swidth, sheight);
  172652. #endif
  172653. #endif
  172654. png_free(png_ptr, buffer);
  172655. #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
  172656. png_free(png_ptr, swidth);
  172657. png_free(png_ptr, sheight);
  172658. #endif
  172659. }
  172660. #endif
  172661. #if defined(PNG_READ_tIME_SUPPORTED)
  172662. void /* PRIVATE */
  172663. png_handle_tIME(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172664. {
  172665. png_byte buf[7];
  172666. png_time mod_time;
  172667. png_debug(1, "in png_handle_tIME\n");
  172668. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172669. png_error(png_ptr, "Out of place tIME chunk");
  172670. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME))
  172671. {
  172672. png_warning(png_ptr, "Duplicate tIME chunk");
  172673. png_crc_finish(png_ptr, length);
  172674. return;
  172675. }
  172676. if (png_ptr->mode & PNG_HAVE_IDAT)
  172677. png_ptr->mode |= PNG_AFTER_IDAT;
  172678. if (length != 7)
  172679. {
  172680. png_warning(png_ptr, "Incorrect tIME chunk length");
  172681. png_crc_finish(png_ptr, length);
  172682. return;
  172683. }
  172684. png_crc_read(png_ptr, buf, 7);
  172685. if (png_crc_finish(png_ptr, 0))
  172686. return;
  172687. mod_time.second = buf[6];
  172688. mod_time.minute = buf[5];
  172689. mod_time.hour = buf[4];
  172690. mod_time.day = buf[3];
  172691. mod_time.month = buf[2];
  172692. mod_time.year = png_get_uint_16(buf);
  172693. png_set_tIME(png_ptr, info_ptr, &mod_time);
  172694. }
  172695. #endif
  172696. #if defined(PNG_READ_tEXt_SUPPORTED)
  172697. void /* PRIVATE */
  172698. png_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172699. {
  172700. png_textp text_ptr;
  172701. png_charp key;
  172702. png_charp text;
  172703. png_uint_32 skip = 0;
  172704. png_size_t slength;
  172705. int ret;
  172706. png_debug(1, "in png_handle_tEXt\n");
  172707. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172708. png_error(png_ptr, "Missing IHDR before tEXt");
  172709. if (png_ptr->mode & PNG_HAVE_IDAT)
  172710. png_ptr->mode |= PNG_AFTER_IDAT;
  172711. #ifdef PNG_MAX_MALLOC_64K
  172712. if (length > (png_uint_32)65535L)
  172713. {
  172714. png_warning(png_ptr, "tEXt chunk too large to fit in memory");
  172715. skip = length - (png_uint_32)65535L;
  172716. length = (png_uint_32)65535L;
  172717. }
  172718. #endif
  172719. key = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172720. if (key == NULL)
  172721. {
  172722. png_warning(png_ptr, "No memory to process text chunk.");
  172723. return;
  172724. }
  172725. slength = (png_size_t)length;
  172726. png_crc_read(png_ptr, (png_bytep)key, slength);
  172727. if (png_crc_finish(png_ptr, skip))
  172728. {
  172729. png_free(png_ptr, key);
  172730. return;
  172731. }
  172732. key[slength] = 0x00;
  172733. for (text = key; *text; text++)
  172734. ;
  172735. if (text != key + slength)
  172736. text++;
  172737. text_ptr = (png_textp)png_malloc_warn(png_ptr,
  172738. (png_uint_32)png_sizeof(png_text));
  172739. if (text_ptr == NULL)
  172740. {
  172741. png_warning(png_ptr, "Not enough memory to process text chunk.");
  172742. png_free(png_ptr, key);
  172743. return;
  172744. }
  172745. text_ptr->compression = PNG_TEXT_COMPRESSION_NONE;
  172746. text_ptr->key = key;
  172747. #ifdef PNG_iTXt_SUPPORTED
  172748. text_ptr->lang = NULL;
  172749. text_ptr->lang_key = NULL;
  172750. text_ptr->itxt_length = 0;
  172751. #endif
  172752. text_ptr->text = text;
  172753. text_ptr->text_length = png_strlen(text);
  172754. ret=png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  172755. png_free(png_ptr, key);
  172756. png_free(png_ptr, text_ptr);
  172757. if (ret)
  172758. png_warning(png_ptr, "Insufficient memory to process text chunk.");
  172759. }
  172760. #endif
  172761. #if defined(PNG_READ_zTXt_SUPPORTED)
  172762. void /* PRIVATE */
  172763. png_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172764. {
  172765. png_textp text_ptr;
  172766. png_charp chunkdata;
  172767. png_charp text;
  172768. int comp_type;
  172769. int ret;
  172770. png_size_t slength, prefix_len, data_len;
  172771. png_debug(1, "in png_handle_zTXt\n");
  172772. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172773. png_error(png_ptr, "Missing IHDR before zTXt");
  172774. if (png_ptr->mode & PNG_HAVE_IDAT)
  172775. png_ptr->mode |= PNG_AFTER_IDAT;
  172776. #ifdef PNG_MAX_MALLOC_64K
  172777. if (length > (png_uint_32)65535L)
  172778. {
  172779. png_warning(png_ptr,"zTXt chunk too large to fit in memory");
  172780. png_crc_finish(png_ptr, length);
  172781. return;
  172782. }
  172783. #endif
  172784. chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172785. if (chunkdata == NULL)
  172786. {
  172787. png_warning(png_ptr,"Out of memory processing zTXt chunk.");
  172788. return;
  172789. }
  172790. slength = (png_size_t)length;
  172791. png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
  172792. if (png_crc_finish(png_ptr, 0))
  172793. {
  172794. png_free(png_ptr, chunkdata);
  172795. return;
  172796. }
  172797. chunkdata[slength] = 0x00;
  172798. for (text = chunkdata; *text; text++)
  172799. ;
  172800. if (text >= chunkdata + slength - 2)
  172801. {
  172802. png_warning(png_ptr, "Truncated zTXt chunk");
  172803. png_free(png_ptr, chunkdata);
  172804. return;
  172805. }
  172806. else
  172807. {
  172808. comp_type = *(++text);
  172809. if (comp_type != PNG_TEXT_COMPRESSION_zTXt)
  172810. {
  172811. png_warning(png_ptr, "Unknown compression type in zTXt chunk");
  172812. comp_type = PNG_TEXT_COMPRESSION_zTXt;
  172813. }
  172814. text++; /* skip the compression_method byte */
  172815. }
  172816. prefix_len = text - chunkdata;
  172817. chunkdata = (png_charp)png_decompress_chunk(png_ptr, comp_type, chunkdata,
  172818. (png_size_t)length, prefix_len, &data_len);
  172819. text_ptr = (png_textp)png_malloc_warn(png_ptr,
  172820. (png_uint_32)png_sizeof(png_text));
  172821. if (text_ptr == NULL)
  172822. {
  172823. png_warning(png_ptr,"Not enough memory to process zTXt chunk.");
  172824. png_free(png_ptr, chunkdata);
  172825. return;
  172826. }
  172827. text_ptr->compression = comp_type;
  172828. text_ptr->key = chunkdata;
  172829. #ifdef PNG_iTXt_SUPPORTED
  172830. text_ptr->lang = NULL;
  172831. text_ptr->lang_key = NULL;
  172832. text_ptr->itxt_length = 0;
  172833. #endif
  172834. text_ptr->text = chunkdata + prefix_len;
  172835. text_ptr->text_length = data_len;
  172836. ret=png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  172837. png_free(png_ptr, text_ptr);
  172838. png_free(png_ptr, chunkdata);
  172839. if (ret)
  172840. png_error(png_ptr, "Insufficient memory to store zTXt chunk.");
  172841. }
  172842. #endif
  172843. #if defined(PNG_READ_iTXt_SUPPORTED)
  172844. void /* PRIVATE */
  172845. png_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172846. {
  172847. png_textp text_ptr;
  172848. png_charp chunkdata;
  172849. png_charp key, lang, text, lang_key;
  172850. int comp_flag;
  172851. int comp_type = 0;
  172852. int ret;
  172853. png_size_t slength, prefix_len, data_len;
  172854. png_debug(1, "in png_handle_iTXt\n");
  172855. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172856. png_error(png_ptr, "Missing IHDR before iTXt");
  172857. if (png_ptr->mode & PNG_HAVE_IDAT)
  172858. png_ptr->mode |= PNG_AFTER_IDAT;
  172859. #ifdef PNG_MAX_MALLOC_64K
  172860. if (length > (png_uint_32)65535L)
  172861. {
  172862. png_warning(png_ptr,"iTXt chunk too large to fit in memory");
  172863. png_crc_finish(png_ptr, length);
  172864. return;
  172865. }
  172866. #endif
  172867. chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172868. if (chunkdata == NULL)
  172869. {
  172870. png_warning(png_ptr, "No memory to process iTXt chunk.");
  172871. return;
  172872. }
  172873. slength = (png_size_t)length;
  172874. png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
  172875. if (png_crc_finish(png_ptr, 0))
  172876. {
  172877. png_free(png_ptr, chunkdata);
  172878. return;
  172879. }
  172880. chunkdata[slength] = 0x00;
  172881. for (lang = chunkdata; *lang; lang++)
  172882. ;
  172883. lang++; /* skip NUL separator */
  172884. if (lang >= chunkdata + slength - 3)
  172885. {
  172886. png_warning(png_ptr, "Truncated iTXt chunk");
  172887. png_free(png_ptr, chunkdata);
  172888. return;
  172889. }
  172890. else
  172891. {
  172892. comp_flag = *lang++;
  172893. comp_type = *lang++;
  172894. }
  172895. for (lang_key = lang; *lang_key; lang_key++)
  172896. ;
  172897. lang_key++; /* skip NUL separator */
  172898. if (lang_key >= chunkdata + slength)
  172899. {
  172900. png_warning(png_ptr, "Truncated iTXt chunk");
  172901. png_free(png_ptr, chunkdata);
  172902. return;
  172903. }
  172904. for (text = lang_key; *text; text++)
  172905. ;
  172906. text++; /* skip NUL separator */
  172907. if (text >= chunkdata + slength)
  172908. {
  172909. png_warning(png_ptr, "Malformed iTXt chunk");
  172910. png_free(png_ptr, chunkdata);
  172911. return;
  172912. }
  172913. prefix_len = text - chunkdata;
  172914. key=chunkdata;
  172915. if (comp_flag)
  172916. chunkdata = png_decompress_chunk(png_ptr, comp_type, chunkdata,
  172917. (size_t)length, prefix_len, &data_len);
  172918. else
  172919. data_len=png_strlen(chunkdata + prefix_len);
  172920. text_ptr = (png_textp)png_malloc_warn(png_ptr,
  172921. (png_uint_32)png_sizeof(png_text));
  172922. if (text_ptr == NULL)
  172923. {
  172924. png_warning(png_ptr,"Not enough memory to process iTXt chunk.");
  172925. png_free(png_ptr, chunkdata);
  172926. return;
  172927. }
  172928. text_ptr->compression = (int)comp_flag + 1;
  172929. text_ptr->lang_key = chunkdata+(lang_key-key);
  172930. text_ptr->lang = chunkdata+(lang-key);
  172931. text_ptr->itxt_length = data_len;
  172932. text_ptr->text_length = 0;
  172933. text_ptr->key = chunkdata;
  172934. text_ptr->text = chunkdata + prefix_len;
  172935. ret=png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  172936. png_free(png_ptr, text_ptr);
  172937. png_free(png_ptr, chunkdata);
  172938. if (ret)
  172939. png_error(png_ptr, "Insufficient memory to store iTXt chunk.");
  172940. }
  172941. #endif
  172942. void /* PRIVATE */
  172943. png_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172944. {
  172945. png_uint_32 skip = 0;
  172946. png_debug(1, "in png_handle_unknown\n");
  172947. if (png_ptr->mode & PNG_HAVE_IDAT)
  172948. {
  172949. #ifdef PNG_USE_LOCAL_ARRAYS
  172950. PNG_CONST PNG_IDAT;
  172951. #endif
  172952. if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) /* not an IDAT */
  172953. png_ptr->mode |= PNG_AFTER_IDAT;
  172954. }
  172955. png_check_chunk_name(png_ptr, png_ptr->chunk_name);
  172956. if (!(png_ptr->chunk_name[0] & 0x20))
  172957. {
  172958. #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  172959. if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
  172960. PNG_HANDLE_CHUNK_ALWAYS
  172961. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  172962. && png_ptr->read_user_chunk_fn == NULL
  172963. #endif
  172964. )
  172965. #endif
  172966. png_chunk_error(png_ptr, "unknown critical chunk");
  172967. }
  172968. #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  172969. if ((png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS) ||
  172970. (png_ptr->read_user_chunk_fn != NULL))
  172971. {
  172972. #ifdef PNG_MAX_MALLOC_64K
  172973. if (length > (png_uint_32)65535L)
  172974. {
  172975. png_warning(png_ptr, "unknown chunk too large to fit in memory");
  172976. skip = length - (png_uint_32)65535L;
  172977. length = (png_uint_32)65535L;
  172978. }
  172979. #endif
  172980. png_strncpy((png_charp)png_ptr->unknown_chunk.name,
  172981. (png_charp)png_ptr->chunk_name, 5);
  172982. png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr, length);
  172983. png_ptr->unknown_chunk.size = (png_size_t)length;
  172984. png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data, length);
  172985. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  172986. if(png_ptr->read_user_chunk_fn != NULL)
  172987. {
  172988. int ret;
  172989. ret = (*(png_ptr->read_user_chunk_fn))
  172990. (png_ptr, &png_ptr->unknown_chunk);
  172991. if (ret < 0)
  172992. png_chunk_error(png_ptr, "error in user chunk");
  172993. if (ret == 0)
  172994. {
  172995. if (!(png_ptr->chunk_name[0] & 0x20))
  172996. if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
  172997. PNG_HANDLE_CHUNK_ALWAYS)
  172998. png_chunk_error(png_ptr, "unknown critical chunk");
  172999. png_set_unknown_chunks(png_ptr, info_ptr,
  173000. &png_ptr->unknown_chunk, 1);
  173001. }
  173002. }
  173003. #else
  173004. png_set_unknown_chunks(png_ptr, info_ptr, &png_ptr->unknown_chunk, 1);
  173005. #endif
  173006. png_free(png_ptr, png_ptr->unknown_chunk.data);
  173007. png_ptr->unknown_chunk.data = NULL;
  173008. }
  173009. else
  173010. #endif
  173011. skip = length;
  173012. png_crc_finish(png_ptr, skip);
  173013. #if !defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  173014. info_ptr = info_ptr; /* quiet compiler warnings about unused info_ptr */
  173015. #endif
  173016. }
  173017. #define isnonalpha(c) ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97))
  173018. void /* PRIVATE */
  173019. png_check_chunk_name(png_structp png_ptr, png_bytep chunk_name)
  173020. {
  173021. png_debug(1, "in png_check_chunk_name\n");
  173022. if (isnonalpha(chunk_name[0]) || isnonalpha(chunk_name[1]) ||
  173023. isnonalpha(chunk_name[2]) || isnonalpha(chunk_name[3]))
  173024. {
  173025. png_chunk_error(png_ptr, "invalid chunk type");
  173026. }
  173027. }
  173028. void /* PRIVATE */
  173029. png_combine_row(png_structp png_ptr, png_bytep row, int mask)
  173030. {
  173031. png_debug(1,"in png_combine_row\n");
  173032. if (mask == 0xff)
  173033. {
  173034. png_memcpy(row, png_ptr->row_buf + 1,
  173035. PNG_ROWBYTES(png_ptr->row_info.pixel_depth, png_ptr->width));
  173036. }
  173037. else
  173038. {
  173039. switch (png_ptr->row_info.pixel_depth)
  173040. {
  173041. case 1:
  173042. {
  173043. png_bytep sp = png_ptr->row_buf + 1;
  173044. png_bytep dp = row;
  173045. int s_inc, s_start, s_end;
  173046. int m = 0x80;
  173047. int shift;
  173048. png_uint_32 i;
  173049. png_uint_32 row_width = png_ptr->width;
  173050. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  173051. if (png_ptr->transformations & PNG_PACKSWAP)
  173052. {
  173053. s_start = 0;
  173054. s_end = 7;
  173055. s_inc = 1;
  173056. }
  173057. else
  173058. #endif
  173059. {
  173060. s_start = 7;
  173061. s_end = 0;
  173062. s_inc = -1;
  173063. }
  173064. shift = s_start;
  173065. for (i = 0; i < row_width; i++)
  173066. {
  173067. if (m & mask)
  173068. {
  173069. int value;
  173070. value = (*sp >> shift) & 0x01;
  173071. *dp &= (png_byte)((0x7f7f >> (7 - shift)) & 0xff);
  173072. *dp |= (png_byte)(value << shift);
  173073. }
  173074. if (shift == s_end)
  173075. {
  173076. shift = s_start;
  173077. sp++;
  173078. dp++;
  173079. }
  173080. else
  173081. shift += s_inc;
  173082. if (m == 1)
  173083. m = 0x80;
  173084. else
  173085. m >>= 1;
  173086. }
  173087. break;
  173088. }
  173089. case 2:
  173090. {
  173091. png_bytep sp = png_ptr->row_buf + 1;
  173092. png_bytep dp = row;
  173093. int s_start, s_end, s_inc;
  173094. int m = 0x80;
  173095. int shift;
  173096. png_uint_32 i;
  173097. png_uint_32 row_width = png_ptr->width;
  173098. int value;
  173099. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  173100. if (png_ptr->transformations & PNG_PACKSWAP)
  173101. {
  173102. s_start = 0;
  173103. s_end = 6;
  173104. s_inc = 2;
  173105. }
  173106. else
  173107. #endif
  173108. {
  173109. s_start = 6;
  173110. s_end = 0;
  173111. s_inc = -2;
  173112. }
  173113. shift = s_start;
  173114. for (i = 0; i < row_width; i++)
  173115. {
  173116. if (m & mask)
  173117. {
  173118. value = (*sp >> shift) & 0x03;
  173119. *dp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
  173120. *dp |= (png_byte)(value << shift);
  173121. }
  173122. if (shift == s_end)
  173123. {
  173124. shift = s_start;
  173125. sp++;
  173126. dp++;
  173127. }
  173128. else
  173129. shift += s_inc;
  173130. if (m == 1)
  173131. m = 0x80;
  173132. else
  173133. m >>= 1;
  173134. }
  173135. break;
  173136. }
  173137. case 4:
  173138. {
  173139. png_bytep sp = png_ptr->row_buf + 1;
  173140. png_bytep dp = row;
  173141. int s_start, s_end, s_inc;
  173142. int m = 0x80;
  173143. int shift;
  173144. png_uint_32 i;
  173145. png_uint_32 row_width = png_ptr->width;
  173146. int value;
  173147. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  173148. if (png_ptr->transformations & PNG_PACKSWAP)
  173149. {
  173150. s_start = 0;
  173151. s_end = 4;
  173152. s_inc = 4;
  173153. }
  173154. else
  173155. #endif
  173156. {
  173157. s_start = 4;
  173158. s_end = 0;
  173159. s_inc = -4;
  173160. }
  173161. shift = s_start;
  173162. for (i = 0; i < row_width; i++)
  173163. {
  173164. if (m & mask)
  173165. {
  173166. value = (*sp >> shift) & 0xf;
  173167. *dp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
  173168. *dp |= (png_byte)(value << shift);
  173169. }
  173170. if (shift == s_end)
  173171. {
  173172. shift = s_start;
  173173. sp++;
  173174. dp++;
  173175. }
  173176. else
  173177. shift += s_inc;
  173178. if (m == 1)
  173179. m = 0x80;
  173180. else
  173181. m >>= 1;
  173182. }
  173183. break;
  173184. }
  173185. default:
  173186. {
  173187. png_bytep sp = png_ptr->row_buf + 1;
  173188. png_bytep dp = row;
  173189. png_size_t pixel_bytes = (png_ptr->row_info.pixel_depth >> 3);
  173190. png_uint_32 i;
  173191. png_uint_32 row_width = png_ptr->width;
  173192. png_byte m = 0x80;
  173193. for (i = 0; i < row_width; i++)
  173194. {
  173195. if (m & mask)
  173196. {
  173197. png_memcpy(dp, sp, pixel_bytes);
  173198. }
  173199. sp += pixel_bytes;
  173200. dp += pixel_bytes;
  173201. if (m == 1)
  173202. m = 0x80;
  173203. else
  173204. m >>= 1;
  173205. }
  173206. break;
  173207. }
  173208. }
  173209. }
  173210. }
  173211. #ifdef PNG_READ_INTERLACING_SUPPORTED
  173212. void /* PRIVATE */
  173213. png_do_read_interlace(png_structp png_ptr)
  173214. {
  173215. png_row_infop row_info = &(png_ptr->row_info);
  173216. png_bytep row = png_ptr->row_buf + 1;
  173217. int pass = png_ptr->pass;
  173218. png_uint_32 transformations = png_ptr->transformations;
  173219. #ifdef PNG_USE_LOCAL_ARRAYS
  173220. PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  173221. #endif
  173222. png_debug(1,"in png_do_read_interlace\n");
  173223. if (row != NULL && row_info != NULL)
  173224. {
  173225. png_uint_32 final_width;
  173226. final_width = row_info->width * png_pass_inc[pass];
  173227. switch (row_info->pixel_depth)
  173228. {
  173229. case 1:
  173230. {
  173231. png_bytep sp = row + (png_size_t)((row_info->width - 1) >> 3);
  173232. png_bytep dp = row + (png_size_t)((final_width - 1) >> 3);
  173233. int sshift, dshift;
  173234. int s_start, s_end, s_inc;
  173235. int jstop = png_pass_inc[pass];
  173236. png_byte v;
  173237. png_uint_32 i;
  173238. int j;
  173239. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  173240. if (transformations & PNG_PACKSWAP)
  173241. {
  173242. sshift = (int)((row_info->width + 7) & 0x07);
  173243. dshift = (int)((final_width + 7) & 0x07);
  173244. s_start = 7;
  173245. s_end = 0;
  173246. s_inc = -1;
  173247. }
  173248. else
  173249. #endif
  173250. {
  173251. sshift = 7 - (int)((row_info->width + 7) & 0x07);
  173252. dshift = 7 - (int)((final_width + 7) & 0x07);
  173253. s_start = 0;
  173254. s_end = 7;
  173255. s_inc = 1;
  173256. }
  173257. for (i = 0; i < row_info->width; i++)
  173258. {
  173259. v = (png_byte)((*sp >> sshift) & 0x01);
  173260. for (j = 0; j < jstop; j++)
  173261. {
  173262. *dp &= (png_byte)((0x7f7f >> (7 - dshift)) & 0xff);
  173263. *dp |= (png_byte)(v << dshift);
  173264. if (dshift == s_end)
  173265. {
  173266. dshift = s_start;
  173267. dp--;
  173268. }
  173269. else
  173270. dshift += s_inc;
  173271. }
  173272. if (sshift == s_end)
  173273. {
  173274. sshift = s_start;
  173275. sp--;
  173276. }
  173277. else
  173278. sshift += s_inc;
  173279. }
  173280. break;
  173281. }
  173282. case 2:
  173283. {
  173284. png_bytep sp = row + (png_uint_32)((row_info->width - 1) >> 2);
  173285. png_bytep dp = row + (png_uint_32)((final_width - 1) >> 2);
  173286. int sshift, dshift;
  173287. int s_start, s_end, s_inc;
  173288. int jstop = png_pass_inc[pass];
  173289. png_uint_32 i;
  173290. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  173291. if (transformations & PNG_PACKSWAP)
  173292. {
  173293. sshift = (int)(((row_info->width + 3) & 0x03) << 1);
  173294. dshift = (int)(((final_width + 3) & 0x03) << 1);
  173295. s_start = 6;
  173296. s_end = 0;
  173297. s_inc = -2;
  173298. }
  173299. else
  173300. #endif
  173301. {
  173302. sshift = (int)((3 - ((row_info->width + 3) & 0x03)) << 1);
  173303. dshift = (int)((3 - ((final_width + 3) & 0x03)) << 1);
  173304. s_start = 0;
  173305. s_end = 6;
  173306. s_inc = 2;
  173307. }
  173308. for (i = 0; i < row_info->width; i++)
  173309. {
  173310. png_byte v;
  173311. int j;
  173312. v = (png_byte)((*sp >> sshift) & 0x03);
  173313. for (j = 0; j < jstop; j++)
  173314. {
  173315. *dp &= (png_byte)((0x3f3f >> (6 - dshift)) & 0xff);
  173316. *dp |= (png_byte)(v << dshift);
  173317. if (dshift == s_end)
  173318. {
  173319. dshift = s_start;
  173320. dp--;
  173321. }
  173322. else
  173323. dshift += s_inc;
  173324. }
  173325. if (sshift == s_end)
  173326. {
  173327. sshift = s_start;
  173328. sp--;
  173329. }
  173330. else
  173331. sshift += s_inc;
  173332. }
  173333. break;
  173334. }
  173335. case 4:
  173336. {
  173337. png_bytep sp = row + (png_size_t)((row_info->width - 1) >> 1);
  173338. png_bytep dp = row + (png_size_t)((final_width - 1) >> 1);
  173339. int sshift, dshift;
  173340. int s_start, s_end, s_inc;
  173341. png_uint_32 i;
  173342. int jstop = png_pass_inc[pass];
  173343. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  173344. if (transformations & PNG_PACKSWAP)
  173345. {
  173346. sshift = (int)(((row_info->width + 1) & 0x01) << 2);
  173347. dshift = (int)(((final_width + 1) & 0x01) << 2);
  173348. s_start = 4;
  173349. s_end = 0;
  173350. s_inc = -4;
  173351. }
  173352. else
  173353. #endif
  173354. {
  173355. sshift = (int)((1 - ((row_info->width + 1) & 0x01)) << 2);
  173356. dshift = (int)((1 - ((final_width + 1) & 0x01)) << 2);
  173357. s_start = 0;
  173358. s_end = 4;
  173359. s_inc = 4;
  173360. }
  173361. for (i = 0; i < row_info->width; i++)
  173362. {
  173363. png_byte v = (png_byte)((*sp >> sshift) & 0xf);
  173364. int j;
  173365. for (j = 0; j < jstop; j++)
  173366. {
  173367. *dp &= (png_byte)((0xf0f >> (4 - dshift)) & 0xff);
  173368. *dp |= (png_byte)(v << dshift);
  173369. if (dshift == s_end)
  173370. {
  173371. dshift = s_start;
  173372. dp--;
  173373. }
  173374. else
  173375. dshift += s_inc;
  173376. }
  173377. if (sshift == s_end)
  173378. {
  173379. sshift = s_start;
  173380. sp--;
  173381. }
  173382. else
  173383. sshift += s_inc;
  173384. }
  173385. break;
  173386. }
  173387. default:
  173388. {
  173389. png_size_t pixel_bytes = (row_info->pixel_depth >> 3);
  173390. png_bytep sp = row + (png_size_t)(row_info->width - 1) * pixel_bytes;
  173391. png_bytep dp = row + (png_size_t)(final_width - 1) * pixel_bytes;
  173392. int jstop = png_pass_inc[pass];
  173393. png_uint_32 i;
  173394. for (i = 0; i < row_info->width; i++)
  173395. {
  173396. png_byte v[8];
  173397. int j;
  173398. png_memcpy(v, sp, pixel_bytes);
  173399. for (j = 0; j < jstop; j++)
  173400. {
  173401. png_memcpy(dp, v, pixel_bytes);
  173402. dp -= pixel_bytes;
  173403. }
  173404. sp -= pixel_bytes;
  173405. }
  173406. break;
  173407. }
  173408. }
  173409. row_info->width = final_width;
  173410. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,final_width);
  173411. }
  173412. #if !defined(PNG_READ_PACKSWAP_SUPPORTED)
  173413. transformations = transformations; /* silence compiler warning */
  173414. #endif
  173415. }
  173416. #endif /* PNG_READ_INTERLACING_SUPPORTED */
  173417. void /* PRIVATE */
  173418. png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep row,
  173419. png_bytep prev_row, int filter)
  173420. {
  173421. png_debug(1, "in png_read_filter_row\n");
  173422. png_debug2(2,"row = %lu, filter = %d\n", png_ptr->row_number, filter);
  173423. switch (filter)
  173424. {
  173425. case PNG_FILTER_VALUE_NONE:
  173426. break;
  173427. case PNG_FILTER_VALUE_SUB:
  173428. {
  173429. png_uint_32 i;
  173430. png_uint_32 istop = row_info->rowbytes;
  173431. png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
  173432. png_bytep rp = row + bpp;
  173433. png_bytep lp = row;
  173434. for (i = bpp; i < istop; i++)
  173435. {
  173436. *rp = (png_byte)(((int)(*rp) + (int)(*lp++)) & 0xff);
  173437. rp++;
  173438. }
  173439. break;
  173440. }
  173441. case PNG_FILTER_VALUE_UP:
  173442. {
  173443. png_uint_32 i;
  173444. png_uint_32 istop = row_info->rowbytes;
  173445. png_bytep rp = row;
  173446. png_bytep pp = prev_row;
  173447. for (i = 0; i < istop; i++)
  173448. {
  173449. *rp = (png_byte)(((int)(*rp) + (int)(*pp++)) & 0xff);
  173450. rp++;
  173451. }
  173452. break;
  173453. }
  173454. case PNG_FILTER_VALUE_AVG:
  173455. {
  173456. png_uint_32 i;
  173457. png_bytep rp = row;
  173458. png_bytep pp = prev_row;
  173459. png_bytep lp = row;
  173460. png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
  173461. png_uint_32 istop = row_info->rowbytes - bpp;
  173462. for (i = 0; i < bpp; i++)
  173463. {
  173464. *rp = (png_byte)(((int)(*rp) +
  173465. ((int)(*pp++) / 2 )) & 0xff);
  173466. rp++;
  173467. }
  173468. for (i = 0; i < istop; i++)
  173469. {
  173470. *rp = (png_byte)(((int)(*rp) +
  173471. (int)(*pp++ + *lp++) / 2 ) & 0xff);
  173472. rp++;
  173473. }
  173474. break;
  173475. }
  173476. case PNG_FILTER_VALUE_PAETH:
  173477. {
  173478. png_uint_32 i;
  173479. png_bytep rp = row;
  173480. png_bytep pp = prev_row;
  173481. png_bytep lp = row;
  173482. png_bytep cp = prev_row;
  173483. png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
  173484. png_uint_32 istop=row_info->rowbytes - bpp;
  173485. for (i = 0; i < bpp; i++)
  173486. {
  173487. *rp = (png_byte)(((int)(*rp) + (int)(*pp++)) & 0xff);
  173488. rp++;
  173489. }
  173490. for (i = 0; i < istop; i++) /* use leftover rp,pp */
  173491. {
  173492. int a, b, c, pa, pb, pc, p;
  173493. a = *lp++;
  173494. b = *pp++;
  173495. c = *cp++;
  173496. p = b - c;
  173497. pc = a - c;
  173498. #ifdef PNG_USE_ABS
  173499. pa = abs(p);
  173500. pb = abs(pc);
  173501. pc = abs(p + pc);
  173502. #else
  173503. pa = p < 0 ? -p : p;
  173504. pb = pc < 0 ? -pc : pc;
  173505. pc = (p + pc) < 0 ? -(p + pc) : p + pc;
  173506. #endif
  173507. p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
  173508. *rp = (png_byte)(((int)(*rp) + p) & 0xff);
  173509. rp++;
  173510. }
  173511. break;
  173512. }
  173513. default:
  173514. png_warning(png_ptr, "Ignoring bad adaptive filter type");
  173515. *row=0;
  173516. break;
  173517. }
  173518. }
  173519. void /* PRIVATE */
  173520. png_read_finish_row(png_structp png_ptr)
  173521. {
  173522. #ifdef PNG_USE_LOCAL_ARRAYS
  173523. PNG_CONST int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  173524. PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  173525. PNG_CONST int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
  173526. PNG_CONST int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
  173527. #endif
  173528. png_debug(1, "in png_read_finish_row\n");
  173529. png_ptr->row_number++;
  173530. if (png_ptr->row_number < png_ptr->num_rows)
  173531. return;
  173532. if (png_ptr->interlaced)
  173533. {
  173534. png_ptr->row_number = 0;
  173535. png_memset_check(png_ptr, png_ptr->prev_row, 0,
  173536. png_ptr->rowbytes + 1);
  173537. do
  173538. {
  173539. png_ptr->pass++;
  173540. if (png_ptr->pass >= 7)
  173541. break;
  173542. png_ptr->iwidth = (png_ptr->width +
  173543. png_pass_inc[png_ptr->pass] - 1 -
  173544. png_pass_start[png_ptr->pass]) /
  173545. png_pass_inc[png_ptr->pass];
  173546. png_ptr->irowbytes = PNG_ROWBYTES(png_ptr->pixel_depth,
  173547. png_ptr->iwidth) + 1;
  173548. if (!(png_ptr->transformations & PNG_INTERLACE))
  173549. {
  173550. png_ptr->num_rows = (png_ptr->height +
  173551. png_pass_yinc[png_ptr->pass] - 1 -
  173552. png_pass_ystart[png_ptr->pass]) /
  173553. png_pass_yinc[png_ptr->pass];
  173554. if (!(png_ptr->num_rows))
  173555. continue;
  173556. }
  173557. else /* if (png_ptr->transformations & PNG_INTERLACE) */
  173558. break;
  173559. } while (png_ptr->iwidth == 0);
  173560. if (png_ptr->pass < 7)
  173561. return;
  173562. }
  173563. if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
  173564. {
  173565. #ifdef PNG_USE_LOCAL_ARRAYS
  173566. PNG_CONST PNG_IDAT;
  173567. #endif
  173568. char extra;
  173569. int ret;
  173570. png_ptr->zstream.next_out = (Bytef *)&extra;
  173571. png_ptr->zstream.avail_out = (uInt)1;
  173572. for(;;)
  173573. {
  173574. if (!(png_ptr->zstream.avail_in))
  173575. {
  173576. while (!png_ptr->idat_size)
  173577. {
  173578. png_byte chunk_length[4];
  173579. png_crc_finish(png_ptr, 0);
  173580. png_read_data(png_ptr, chunk_length, 4);
  173581. png_ptr->idat_size = png_get_uint_31(png_ptr, chunk_length);
  173582. png_reset_crc(png_ptr);
  173583. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  173584. if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  173585. png_error(png_ptr, "Not enough image data");
  173586. }
  173587. png_ptr->zstream.avail_in = (uInt)png_ptr->zbuf_size;
  173588. png_ptr->zstream.next_in = png_ptr->zbuf;
  173589. if (png_ptr->zbuf_size > png_ptr->idat_size)
  173590. png_ptr->zstream.avail_in = (uInt)png_ptr->idat_size;
  173591. png_crc_read(png_ptr, png_ptr->zbuf, png_ptr->zstream.avail_in);
  173592. png_ptr->idat_size -= png_ptr->zstream.avail_in;
  173593. }
  173594. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  173595. if (ret == Z_STREAM_END)
  173596. {
  173597. if (!(png_ptr->zstream.avail_out) || png_ptr->zstream.avail_in ||
  173598. png_ptr->idat_size)
  173599. png_warning(png_ptr, "Extra compressed data");
  173600. png_ptr->mode |= PNG_AFTER_IDAT;
  173601. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  173602. break;
  173603. }
  173604. if (ret != Z_OK)
  173605. png_error(png_ptr, png_ptr->zstream.msg ? png_ptr->zstream.msg :
  173606. "Decompression Error");
  173607. if (!(png_ptr->zstream.avail_out))
  173608. {
  173609. png_warning(png_ptr, "Extra compressed data.");
  173610. png_ptr->mode |= PNG_AFTER_IDAT;
  173611. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  173612. break;
  173613. }
  173614. }
  173615. png_ptr->zstream.avail_out = 0;
  173616. }
  173617. if (png_ptr->idat_size || png_ptr->zstream.avail_in)
  173618. png_warning(png_ptr, "Extra compression data");
  173619. inflateReset(&png_ptr->zstream);
  173620. png_ptr->mode |= PNG_AFTER_IDAT;
  173621. }
  173622. void /* PRIVATE */
  173623. png_read_start_row(png_structp png_ptr)
  173624. {
  173625. #ifdef PNG_USE_LOCAL_ARRAYS
  173626. PNG_CONST int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  173627. PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  173628. PNG_CONST int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
  173629. PNG_CONST int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
  173630. #endif
  173631. int max_pixel_depth;
  173632. png_uint_32 row_bytes;
  173633. png_debug(1, "in png_read_start_row\n");
  173634. png_ptr->zstream.avail_in = 0;
  173635. png_init_read_transformations(png_ptr);
  173636. if (png_ptr->interlaced)
  173637. {
  173638. if (!(png_ptr->transformations & PNG_INTERLACE))
  173639. png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 -
  173640. png_pass_ystart[0]) / png_pass_yinc[0];
  173641. else
  173642. png_ptr->num_rows = png_ptr->height;
  173643. png_ptr->iwidth = (png_ptr->width +
  173644. png_pass_inc[png_ptr->pass] - 1 -
  173645. png_pass_start[png_ptr->pass]) /
  173646. png_pass_inc[png_ptr->pass];
  173647. row_bytes = PNG_ROWBYTES(png_ptr->pixel_depth,png_ptr->iwidth) + 1;
  173648. png_ptr->irowbytes = (png_size_t)row_bytes;
  173649. if((png_uint_32)png_ptr->irowbytes != row_bytes)
  173650. png_error(png_ptr, "Rowbytes overflow in png_read_start_row");
  173651. }
  173652. else
  173653. {
  173654. png_ptr->num_rows = png_ptr->height;
  173655. png_ptr->iwidth = png_ptr->width;
  173656. png_ptr->irowbytes = png_ptr->rowbytes + 1;
  173657. }
  173658. max_pixel_depth = png_ptr->pixel_depth;
  173659. #if defined(PNG_READ_PACK_SUPPORTED)
  173660. if ((png_ptr->transformations & PNG_PACK) && png_ptr->bit_depth < 8)
  173661. max_pixel_depth = 8;
  173662. #endif
  173663. #if defined(PNG_READ_EXPAND_SUPPORTED)
  173664. if (png_ptr->transformations & PNG_EXPAND)
  173665. {
  173666. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  173667. {
  173668. if (png_ptr->num_trans)
  173669. max_pixel_depth = 32;
  173670. else
  173671. max_pixel_depth = 24;
  173672. }
  173673. else if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
  173674. {
  173675. if (max_pixel_depth < 8)
  173676. max_pixel_depth = 8;
  173677. if (png_ptr->num_trans)
  173678. max_pixel_depth *= 2;
  173679. }
  173680. else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
  173681. {
  173682. if (png_ptr->num_trans)
  173683. {
  173684. max_pixel_depth *= 4;
  173685. max_pixel_depth /= 3;
  173686. }
  173687. }
  173688. }
  173689. #endif
  173690. #if defined(PNG_READ_FILLER_SUPPORTED)
  173691. if (png_ptr->transformations & (PNG_FILLER))
  173692. {
  173693. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  173694. max_pixel_depth = 32;
  173695. else if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
  173696. {
  173697. if (max_pixel_depth <= 8)
  173698. max_pixel_depth = 16;
  173699. else
  173700. max_pixel_depth = 32;
  173701. }
  173702. else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
  173703. {
  173704. if (max_pixel_depth <= 32)
  173705. max_pixel_depth = 32;
  173706. else
  173707. max_pixel_depth = 64;
  173708. }
  173709. }
  173710. #endif
  173711. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  173712. if (png_ptr->transformations & PNG_GRAY_TO_RGB)
  173713. {
  173714. if (
  173715. #if defined(PNG_READ_EXPAND_SUPPORTED)
  173716. (png_ptr->num_trans && (png_ptr->transformations & PNG_EXPAND)) ||
  173717. #endif
  173718. #if defined(PNG_READ_FILLER_SUPPORTED)
  173719. (png_ptr->transformations & (PNG_FILLER)) ||
  173720. #endif
  173721. png_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  173722. {
  173723. if (max_pixel_depth <= 16)
  173724. max_pixel_depth = 32;
  173725. else
  173726. max_pixel_depth = 64;
  173727. }
  173728. else
  173729. {
  173730. if (max_pixel_depth <= 8)
  173731. {
  173732. if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  173733. max_pixel_depth = 32;
  173734. else
  173735. max_pixel_depth = 24;
  173736. }
  173737. else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  173738. max_pixel_depth = 64;
  173739. else
  173740. max_pixel_depth = 48;
  173741. }
  173742. }
  173743. #endif
  173744. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) && \
  173745. defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  173746. if(png_ptr->transformations & PNG_USER_TRANSFORM)
  173747. {
  173748. int user_pixel_depth=png_ptr->user_transform_depth*
  173749. png_ptr->user_transform_channels;
  173750. if(user_pixel_depth > max_pixel_depth)
  173751. max_pixel_depth=user_pixel_depth;
  173752. }
  173753. #endif
  173754. row_bytes = ((png_ptr->width + 7) & ~((png_uint_32)7));
  173755. row_bytes = PNG_ROWBYTES(max_pixel_depth,row_bytes) +
  173756. 1 + ((max_pixel_depth + 7) >> 3);
  173757. #ifdef PNG_MAX_MALLOC_64K
  173758. if (row_bytes > (png_uint_32)65536L)
  173759. png_error(png_ptr, "This image requires a row greater than 64KB");
  173760. #endif
  173761. png_ptr->big_row_buf = (png_bytep)png_malloc(png_ptr, row_bytes+64);
  173762. png_ptr->row_buf = png_ptr->big_row_buf+32;
  173763. #ifdef PNG_MAX_MALLOC_64K
  173764. if ((png_uint_32)png_ptr->rowbytes + 1 > (png_uint_32)65536L)
  173765. png_error(png_ptr, "This image requires a row greater than 64KB");
  173766. #endif
  173767. if ((png_uint_32)png_ptr->rowbytes > (png_uint_32)(PNG_SIZE_MAX - 1))
  173768. png_error(png_ptr, "Row has too many bytes to allocate in memory.");
  173769. png_ptr->prev_row = (png_bytep)png_malloc(png_ptr, (png_uint_32)(
  173770. png_ptr->rowbytes + 1));
  173771. png_memset_check(png_ptr, png_ptr->prev_row, 0, png_ptr->rowbytes + 1);
  173772. png_debug1(3, "width = %lu,\n", png_ptr->width);
  173773. png_debug1(3, "height = %lu,\n", png_ptr->height);
  173774. png_debug1(3, "iwidth = %lu,\n", png_ptr->iwidth);
  173775. png_debug1(3, "num_rows = %lu\n", png_ptr->num_rows);
  173776. png_debug1(3, "rowbytes = %lu,\n", png_ptr->rowbytes);
  173777. png_debug1(3, "irowbytes = %lu,\n", png_ptr->irowbytes);
  173778. png_ptr->flags |= PNG_FLAG_ROW_INIT;
  173779. }
  173780. #endif /* PNG_READ_SUPPORTED */
  173781. /*** End of inlined file: pngrutil.c ***/
  173782. /*** Start of inlined file: pngset.c ***/
  173783. #define PNG_INTERNAL
  173784. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  173785. #if defined(PNG_bKGD_SUPPORTED)
  173786. void PNGAPI
  173787. png_set_bKGD(png_structp png_ptr, png_infop info_ptr, png_color_16p background)
  173788. {
  173789. png_debug1(1, "in %s storage function\n", "bKGD");
  173790. if (png_ptr == NULL || info_ptr == NULL)
  173791. return;
  173792. png_memcpy(&(info_ptr->background), background, png_sizeof(png_color_16));
  173793. info_ptr->valid |= PNG_INFO_bKGD;
  173794. }
  173795. #endif
  173796. #if defined(PNG_cHRM_SUPPORTED)
  173797. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173798. void PNGAPI
  173799. png_set_cHRM(png_structp png_ptr, png_infop info_ptr,
  173800. double white_x, double white_y, double red_x, double red_y,
  173801. double green_x, double green_y, double blue_x, double blue_y)
  173802. {
  173803. png_debug1(1, "in %s storage function\n", "cHRM");
  173804. if (png_ptr == NULL || info_ptr == NULL)
  173805. return;
  173806. if (white_x < 0.0 || white_y < 0.0 ||
  173807. red_x < 0.0 || red_y < 0.0 ||
  173808. green_x < 0.0 || green_y < 0.0 ||
  173809. blue_x < 0.0 || blue_y < 0.0)
  173810. {
  173811. png_warning(png_ptr,
  173812. "Ignoring attempt to set negative chromaticity value");
  173813. return;
  173814. }
  173815. if (white_x > 21474.83 || white_y > 21474.83 ||
  173816. red_x > 21474.83 || red_y > 21474.83 ||
  173817. green_x > 21474.83 || green_y > 21474.83 ||
  173818. blue_x > 21474.83 || blue_y > 21474.83)
  173819. {
  173820. png_warning(png_ptr,
  173821. "Ignoring attempt to set chromaticity value exceeding 21474.83");
  173822. return;
  173823. }
  173824. info_ptr->x_white = (float)white_x;
  173825. info_ptr->y_white = (float)white_y;
  173826. info_ptr->x_red = (float)red_x;
  173827. info_ptr->y_red = (float)red_y;
  173828. info_ptr->x_green = (float)green_x;
  173829. info_ptr->y_green = (float)green_y;
  173830. info_ptr->x_blue = (float)blue_x;
  173831. info_ptr->y_blue = (float)blue_y;
  173832. #ifdef PNG_FIXED_POINT_SUPPORTED
  173833. info_ptr->int_x_white = (png_fixed_point)(white_x*100000.+0.5);
  173834. info_ptr->int_y_white = (png_fixed_point)(white_y*100000.+0.5);
  173835. info_ptr->int_x_red = (png_fixed_point)( red_x*100000.+0.5);
  173836. info_ptr->int_y_red = (png_fixed_point)( red_y*100000.+0.5);
  173837. info_ptr->int_x_green = (png_fixed_point)(green_x*100000.+0.5);
  173838. info_ptr->int_y_green = (png_fixed_point)(green_y*100000.+0.5);
  173839. info_ptr->int_x_blue = (png_fixed_point)( blue_x*100000.+0.5);
  173840. info_ptr->int_y_blue = (png_fixed_point)( blue_y*100000.+0.5);
  173841. #endif
  173842. info_ptr->valid |= PNG_INFO_cHRM;
  173843. }
  173844. #endif
  173845. #ifdef PNG_FIXED_POINT_SUPPORTED
  173846. void PNGAPI
  173847. png_set_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
  173848. png_fixed_point white_x, png_fixed_point white_y, png_fixed_point red_x,
  173849. png_fixed_point red_y, png_fixed_point green_x, png_fixed_point green_y,
  173850. png_fixed_point blue_x, png_fixed_point blue_y)
  173851. {
  173852. png_debug1(1, "in %s storage function\n", "cHRM");
  173853. if (png_ptr == NULL || info_ptr == NULL)
  173854. return;
  173855. if (white_x < 0 || white_y < 0 ||
  173856. red_x < 0 || red_y < 0 ||
  173857. green_x < 0 || green_y < 0 ||
  173858. blue_x < 0 || blue_y < 0)
  173859. {
  173860. png_warning(png_ptr,
  173861. "Ignoring attempt to set negative chromaticity value");
  173862. return;
  173863. }
  173864. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173865. if (white_x > (double) PNG_UINT_31_MAX ||
  173866. white_y > (double) PNG_UINT_31_MAX ||
  173867. red_x > (double) PNG_UINT_31_MAX ||
  173868. red_y > (double) PNG_UINT_31_MAX ||
  173869. green_x > (double) PNG_UINT_31_MAX ||
  173870. green_y > (double) PNG_UINT_31_MAX ||
  173871. blue_x > (double) PNG_UINT_31_MAX ||
  173872. blue_y > (double) PNG_UINT_31_MAX)
  173873. #else
  173874. if (white_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173875. white_y > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173876. red_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173877. red_y > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173878. green_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173879. green_y > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173880. blue_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173881. blue_y > (png_fixed_point) PNG_UINT_31_MAX/100000L)
  173882. #endif
  173883. {
  173884. png_warning(png_ptr,
  173885. "Ignoring attempt to set chromaticity value exceeding 21474.83");
  173886. return;
  173887. }
  173888. info_ptr->int_x_white = white_x;
  173889. info_ptr->int_y_white = white_y;
  173890. info_ptr->int_x_red = red_x;
  173891. info_ptr->int_y_red = red_y;
  173892. info_ptr->int_x_green = green_x;
  173893. info_ptr->int_y_green = green_y;
  173894. info_ptr->int_x_blue = blue_x;
  173895. info_ptr->int_y_blue = blue_y;
  173896. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173897. info_ptr->x_white = (float)(white_x/100000.);
  173898. info_ptr->y_white = (float)(white_y/100000.);
  173899. info_ptr->x_red = (float)( red_x/100000.);
  173900. info_ptr->y_red = (float)( red_y/100000.);
  173901. info_ptr->x_green = (float)(green_x/100000.);
  173902. info_ptr->y_green = (float)(green_y/100000.);
  173903. info_ptr->x_blue = (float)( blue_x/100000.);
  173904. info_ptr->y_blue = (float)( blue_y/100000.);
  173905. #endif
  173906. info_ptr->valid |= PNG_INFO_cHRM;
  173907. }
  173908. #endif
  173909. #endif
  173910. #if defined(PNG_gAMA_SUPPORTED)
  173911. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173912. void PNGAPI
  173913. png_set_gAMA(png_structp png_ptr, png_infop info_ptr, double file_gamma)
  173914. {
  173915. double gamma;
  173916. png_debug1(1, "in %s storage function\n", "gAMA");
  173917. if (png_ptr == NULL || info_ptr == NULL)
  173918. return;
  173919. if (file_gamma > 21474.83)
  173920. {
  173921. png_warning(png_ptr, "Limiting gamma to 21474.83");
  173922. gamma=21474.83;
  173923. }
  173924. else
  173925. gamma=file_gamma;
  173926. info_ptr->gamma = (float)gamma;
  173927. #ifdef PNG_FIXED_POINT_SUPPORTED
  173928. info_ptr->int_gamma = (int)(gamma*100000.+.5);
  173929. #endif
  173930. info_ptr->valid |= PNG_INFO_gAMA;
  173931. if(gamma == 0.0)
  173932. png_warning(png_ptr, "Setting gamma=0");
  173933. }
  173934. #endif
  173935. void PNGAPI
  173936. png_set_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, png_fixed_point
  173937. int_gamma)
  173938. {
  173939. png_fixed_point gamma;
  173940. png_debug1(1, "in %s storage function\n", "gAMA");
  173941. if (png_ptr == NULL || info_ptr == NULL)
  173942. return;
  173943. if (int_gamma > (png_fixed_point) PNG_UINT_31_MAX)
  173944. {
  173945. png_warning(png_ptr, "Limiting gamma to 21474.83");
  173946. gamma=PNG_UINT_31_MAX;
  173947. }
  173948. else
  173949. {
  173950. if (int_gamma < 0)
  173951. {
  173952. png_warning(png_ptr, "Setting negative gamma to zero");
  173953. gamma=0;
  173954. }
  173955. else
  173956. gamma=int_gamma;
  173957. }
  173958. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173959. info_ptr->gamma = (float)(gamma/100000.);
  173960. #endif
  173961. #ifdef PNG_FIXED_POINT_SUPPORTED
  173962. info_ptr->int_gamma = gamma;
  173963. #endif
  173964. info_ptr->valid |= PNG_INFO_gAMA;
  173965. if(gamma == 0)
  173966. png_warning(png_ptr, "Setting gamma=0");
  173967. }
  173968. #endif
  173969. #if defined(PNG_hIST_SUPPORTED)
  173970. void PNGAPI
  173971. png_set_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p hist)
  173972. {
  173973. int i;
  173974. png_debug1(1, "in %s storage function\n", "hIST");
  173975. if (png_ptr == NULL || info_ptr == NULL)
  173976. return;
  173977. if (info_ptr->num_palette == 0 || info_ptr->num_palette
  173978. > PNG_MAX_PALETTE_LENGTH)
  173979. {
  173980. png_warning(png_ptr,
  173981. "Invalid palette size, hIST allocation skipped.");
  173982. return;
  173983. }
  173984. #ifdef PNG_FREE_ME_SUPPORTED
  173985. png_free_data(png_ptr, info_ptr, PNG_FREE_HIST, 0);
  173986. #endif
  173987. png_ptr->hist = (png_uint_16p)png_malloc_warn(png_ptr,
  173988. (png_uint_32)(PNG_MAX_PALETTE_LENGTH * png_sizeof (png_uint_16)));
  173989. if (png_ptr->hist == NULL)
  173990. {
  173991. png_warning(png_ptr, "Insufficient memory for hIST chunk data.");
  173992. return;
  173993. }
  173994. for (i = 0; i < info_ptr->num_palette; i++)
  173995. png_ptr->hist[i] = hist[i];
  173996. info_ptr->hist = png_ptr->hist;
  173997. info_ptr->valid |= PNG_INFO_hIST;
  173998. #ifdef PNG_FREE_ME_SUPPORTED
  173999. info_ptr->free_me |= PNG_FREE_HIST;
  174000. #else
  174001. png_ptr->flags |= PNG_FLAG_FREE_HIST;
  174002. #endif
  174003. }
  174004. #endif
  174005. void PNGAPI
  174006. png_set_IHDR(png_structp png_ptr, png_infop info_ptr,
  174007. png_uint_32 width, png_uint_32 height, int bit_depth,
  174008. int color_type, int interlace_type, int compression_type,
  174009. int filter_type)
  174010. {
  174011. png_debug1(1, "in %s storage function\n", "IHDR");
  174012. if (png_ptr == NULL || info_ptr == NULL)
  174013. return;
  174014. if (width == 0 || height == 0)
  174015. png_error(png_ptr, "Image width or height is zero in IHDR");
  174016. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  174017. if (width > png_ptr->user_width_max || height > png_ptr->user_height_max)
  174018. png_error(png_ptr, "image size exceeds user limits in IHDR");
  174019. #else
  174020. if (width > PNG_USER_WIDTH_MAX || height > PNG_USER_HEIGHT_MAX)
  174021. png_error(png_ptr, "image size exceeds user limits in IHDR");
  174022. #endif
  174023. if (width > PNG_UINT_31_MAX || height > PNG_UINT_31_MAX)
  174024. png_error(png_ptr, "Invalid image size in IHDR");
  174025. if ( width > (PNG_UINT_32_MAX
  174026. >> 3) /* 8-byte RGBA pixels */
  174027. - 64 /* bigrowbuf hack */
  174028. - 1 /* filter byte */
  174029. - 7*8 /* rounding of width to multiple of 8 pixels */
  174030. - 8) /* extra max_pixel_depth pad */
  174031. png_warning(png_ptr, "Width is too large for libpng to process pixels");
  174032. if (bit_depth != 1 && bit_depth != 2 && bit_depth != 4 &&
  174033. bit_depth != 8 && bit_depth != 16)
  174034. png_error(png_ptr, "Invalid bit depth in IHDR");
  174035. if (color_type < 0 || color_type == 1 ||
  174036. color_type == 5 || color_type > 6)
  174037. png_error(png_ptr, "Invalid color type in IHDR");
  174038. if (((color_type == PNG_COLOR_TYPE_PALETTE) && bit_depth > 8) ||
  174039. ((color_type == PNG_COLOR_TYPE_RGB ||
  174040. color_type == PNG_COLOR_TYPE_GRAY_ALPHA ||
  174041. color_type == PNG_COLOR_TYPE_RGB_ALPHA) && bit_depth < 8))
  174042. png_error(png_ptr, "Invalid color type/bit depth combination in IHDR");
  174043. if (interlace_type >= PNG_INTERLACE_LAST)
  174044. png_error(png_ptr, "Unknown interlace method in IHDR");
  174045. if (compression_type != PNG_COMPRESSION_TYPE_BASE)
  174046. png_error(png_ptr, "Unknown compression method in IHDR");
  174047. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  174048. if((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&png_ptr->mng_features_permitted)
  174049. png_warning(png_ptr,"MNG features are not allowed in a PNG datastream");
  174050. if(filter_type != PNG_FILTER_TYPE_BASE)
  174051. {
  174052. if(!((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  174053. (filter_type == PNG_INTRAPIXEL_DIFFERENCING) &&
  174054. ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) &&
  174055. (color_type == PNG_COLOR_TYPE_RGB ||
  174056. color_type == PNG_COLOR_TYPE_RGB_ALPHA)))
  174057. png_error(png_ptr, "Unknown filter method in IHDR");
  174058. if(png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)
  174059. png_warning(png_ptr, "Invalid filter method in IHDR");
  174060. }
  174061. #else
  174062. if(filter_type != PNG_FILTER_TYPE_BASE)
  174063. png_error(png_ptr, "Unknown filter method in IHDR");
  174064. #endif
  174065. info_ptr->width = width;
  174066. info_ptr->height = height;
  174067. info_ptr->bit_depth = (png_byte)bit_depth;
  174068. info_ptr->color_type =(png_byte) color_type;
  174069. info_ptr->compression_type = (png_byte)compression_type;
  174070. info_ptr->filter_type = (png_byte)filter_type;
  174071. info_ptr->interlace_type = (png_byte)interlace_type;
  174072. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  174073. info_ptr->channels = 1;
  174074. else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR)
  174075. info_ptr->channels = 3;
  174076. else
  174077. info_ptr->channels = 1;
  174078. if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
  174079. info_ptr->channels++;
  174080. info_ptr->pixel_depth = (png_byte)(info_ptr->channels * info_ptr->bit_depth);
  174081. if (width > (PNG_UINT_32_MAX
  174082. >> 3) /* 8-byte RGBA pixels */
  174083. - 64 /* bigrowbuf hack */
  174084. - 1 /* filter byte */
  174085. - 7*8 /* rounding of width to multiple of 8 pixels */
  174086. - 8) /* extra max_pixel_depth pad */
  174087. info_ptr->rowbytes = (png_size_t)0;
  174088. else
  174089. info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth,width);
  174090. }
  174091. #if defined(PNG_oFFs_SUPPORTED)
  174092. void PNGAPI
  174093. png_set_oFFs(png_structp png_ptr, png_infop info_ptr,
  174094. png_int_32 offset_x, png_int_32 offset_y, int unit_type)
  174095. {
  174096. png_debug1(1, "in %s storage function\n", "oFFs");
  174097. if (png_ptr == NULL || info_ptr == NULL)
  174098. return;
  174099. info_ptr->x_offset = offset_x;
  174100. info_ptr->y_offset = offset_y;
  174101. info_ptr->offset_unit_type = (png_byte)unit_type;
  174102. info_ptr->valid |= PNG_INFO_oFFs;
  174103. }
  174104. #endif
  174105. #if defined(PNG_pCAL_SUPPORTED)
  174106. void PNGAPI
  174107. png_set_pCAL(png_structp png_ptr, png_infop info_ptr,
  174108. png_charp purpose, png_int_32 X0, png_int_32 X1, int type, int nparams,
  174109. png_charp units, png_charpp params)
  174110. {
  174111. png_uint_32 length;
  174112. int i;
  174113. png_debug1(1, "in %s storage function\n", "pCAL");
  174114. if (png_ptr == NULL || info_ptr == NULL)
  174115. return;
  174116. length = png_strlen(purpose) + 1;
  174117. png_debug1(3, "allocating purpose for info (%lu bytes)\n", length);
  174118. info_ptr->pcal_purpose = (png_charp)png_malloc_warn(png_ptr, length);
  174119. if (info_ptr->pcal_purpose == NULL)
  174120. {
  174121. png_warning(png_ptr, "Insufficient memory for pCAL purpose.");
  174122. return;
  174123. }
  174124. png_memcpy(info_ptr->pcal_purpose, purpose, (png_size_t)length);
  174125. png_debug(3, "storing X0, X1, type, and nparams in info\n");
  174126. info_ptr->pcal_X0 = X0;
  174127. info_ptr->pcal_X1 = X1;
  174128. info_ptr->pcal_type = (png_byte)type;
  174129. info_ptr->pcal_nparams = (png_byte)nparams;
  174130. length = png_strlen(units) + 1;
  174131. png_debug1(3, "allocating units for info (%lu bytes)\n", length);
  174132. info_ptr->pcal_units = (png_charp)png_malloc_warn(png_ptr, length);
  174133. if (info_ptr->pcal_units == NULL)
  174134. {
  174135. png_warning(png_ptr, "Insufficient memory for pCAL units.");
  174136. return;
  174137. }
  174138. png_memcpy(info_ptr->pcal_units, units, (png_size_t)length);
  174139. info_ptr->pcal_params = (png_charpp)png_malloc_warn(png_ptr,
  174140. (png_uint_32)((nparams + 1) * png_sizeof(png_charp)));
  174141. if (info_ptr->pcal_params == NULL)
  174142. {
  174143. png_warning(png_ptr, "Insufficient memory for pCAL params.");
  174144. return;
  174145. }
  174146. info_ptr->pcal_params[nparams] = NULL;
  174147. for (i = 0; i < nparams; i++)
  174148. {
  174149. length = png_strlen(params[i]) + 1;
  174150. png_debug2(3, "allocating parameter %d for info (%lu bytes)\n", i, length);
  174151. info_ptr->pcal_params[i] = (png_charp)png_malloc_warn(png_ptr, length);
  174152. if (info_ptr->pcal_params[i] == NULL)
  174153. {
  174154. png_warning(png_ptr, "Insufficient memory for pCAL parameter.");
  174155. return;
  174156. }
  174157. png_memcpy(info_ptr->pcal_params[i], params[i], (png_size_t)length);
  174158. }
  174159. info_ptr->valid |= PNG_INFO_pCAL;
  174160. #ifdef PNG_FREE_ME_SUPPORTED
  174161. info_ptr->free_me |= PNG_FREE_PCAL;
  174162. #endif
  174163. }
  174164. #endif
  174165. #if defined(PNG_READ_sCAL_SUPPORTED) || defined(PNG_WRITE_sCAL_SUPPORTED)
  174166. #ifdef PNG_FLOATING_POINT_SUPPORTED
  174167. void PNGAPI
  174168. png_set_sCAL(png_structp png_ptr, png_infop info_ptr,
  174169. int unit, double width, double height)
  174170. {
  174171. png_debug1(1, "in %s storage function\n", "sCAL");
  174172. if (png_ptr == NULL || info_ptr == NULL)
  174173. return;
  174174. info_ptr->scal_unit = (png_byte)unit;
  174175. info_ptr->scal_pixel_width = width;
  174176. info_ptr->scal_pixel_height = height;
  174177. info_ptr->valid |= PNG_INFO_sCAL;
  174178. }
  174179. #else
  174180. #ifdef PNG_FIXED_POINT_SUPPORTED
  174181. void PNGAPI
  174182. png_set_sCAL_s(png_structp png_ptr, png_infop info_ptr,
  174183. int unit, png_charp swidth, png_charp sheight)
  174184. {
  174185. png_uint_32 length;
  174186. png_debug1(1, "in %s storage function\n", "sCAL");
  174187. if (png_ptr == NULL || info_ptr == NULL)
  174188. return;
  174189. info_ptr->scal_unit = (png_byte)unit;
  174190. length = png_strlen(swidth) + 1;
  174191. png_debug1(3, "allocating unit for info (%d bytes)\n", length);
  174192. info_ptr->scal_s_width = (png_charp)png_malloc_warn(png_ptr, length);
  174193. if (info_ptr->scal_s_width == NULL)
  174194. {
  174195. png_warning(png_ptr,
  174196. "Memory allocation failed while processing sCAL.");
  174197. }
  174198. png_memcpy(info_ptr->scal_s_width, swidth, (png_size_t)length);
  174199. length = png_strlen(sheight) + 1;
  174200. png_debug1(3, "allocating unit for info (%d bytes)\n", length);
  174201. info_ptr->scal_s_height = (png_charp)png_malloc_warn(png_ptr, length);
  174202. if (info_ptr->scal_s_height == NULL)
  174203. {
  174204. png_free (png_ptr, info_ptr->scal_s_width);
  174205. png_warning(png_ptr,
  174206. "Memory allocation failed while processing sCAL.");
  174207. }
  174208. png_memcpy(info_ptr->scal_s_height, sheight, (png_size_t)length);
  174209. info_ptr->valid |= PNG_INFO_sCAL;
  174210. #ifdef PNG_FREE_ME_SUPPORTED
  174211. info_ptr->free_me |= PNG_FREE_SCAL;
  174212. #endif
  174213. }
  174214. #endif
  174215. #endif
  174216. #endif
  174217. #if defined(PNG_pHYs_SUPPORTED)
  174218. void PNGAPI
  174219. png_set_pHYs(png_structp png_ptr, png_infop info_ptr,
  174220. png_uint_32 res_x, png_uint_32 res_y, int unit_type)
  174221. {
  174222. png_debug1(1, "in %s storage function\n", "pHYs");
  174223. if (png_ptr == NULL || info_ptr == NULL)
  174224. return;
  174225. info_ptr->x_pixels_per_unit = res_x;
  174226. info_ptr->y_pixels_per_unit = res_y;
  174227. info_ptr->phys_unit_type = (png_byte)unit_type;
  174228. info_ptr->valid |= PNG_INFO_pHYs;
  174229. }
  174230. #endif
  174231. void PNGAPI
  174232. png_set_PLTE(png_structp png_ptr, png_infop info_ptr,
  174233. png_colorp palette, int num_palette)
  174234. {
  174235. png_debug1(1, "in %s storage function\n", "PLTE");
  174236. if (png_ptr == NULL || info_ptr == NULL)
  174237. return;
  174238. if (num_palette < 0 || num_palette > PNG_MAX_PALETTE_LENGTH)
  174239. {
  174240. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  174241. png_error(png_ptr, "Invalid palette length");
  174242. else
  174243. {
  174244. png_warning(png_ptr, "Invalid palette length");
  174245. return;
  174246. }
  174247. }
  174248. #ifdef PNG_FREE_ME_SUPPORTED
  174249. png_free_data(png_ptr, info_ptr, PNG_FREE_PLTE, 0);
  174250. #endif
  174251. png_ptr->palette = (png_colorp)png_malloc(png_ptr,
  174252. PNG_MAX_PALETTE_LENGTH * png_sizeof(png_color));
  174253. png_memset(png_ptr->palette, 0, PNG_MAX_PALETTE_LENGTH *
  174254. png_sizeof(png_color));
  174255. png_memcpy(png_ptr->palette, palette, num_palette * png_sizeof (png_color));
  174256. info_ptr->palette = png_ptr->palette;
  174257. info_ptr->num_palette = png_ptr->num_palette = (png_uint_16)num_palette;
  174258. #ifdef PNG_FREE_ME_SUPPORTED
  174259. info_ptr->free_me |= PNG_FREE_PLTE;
  174260. #else
  174261. png_ptr->flags |= PNG_FLAG_FREE_PLTE;
  174262. #endif
  174263. info_ptr->valid |= PNG_INFO_PLTE;
  174264. }
  174265. #if defined(PNG_sBIT_SUPPORTED)
  174266. void PNGAPI
  174267. png_set_sBIT(png_structp png_ptr, png_infop info_ptr,
  174268. png_color_8p sig_bit)
  174269. {
  174270. png_debug1(1, "in %s storage function\n", "sBIT");
  174271. if (png_ptr == NULL || info_ptr == NULL)
  174272. return;
  174273. png_memcpy(&(info_ptr->sig_bit), sig_bit, png_sizeof (png_color_8));
  174274. info_ptr->valid |= PNG_INFO_sBIT;
  174275. }
  174276. #endif
  174277. #if defined(PNG_sRGB_SUPPORTED)
  174278. void PNGAPI
  174279. png_set_sRGB(png_structp png_ptr, png_infop info_ptr, int intent)
  174280. {
  174281. png_debug1(1, "in %s storage function\n", "sRGB");
  174282. if (png_ptr == NULL || info_ptr == NULL)
  174283. return;
  174284. info_ptr->srgb_intent = (png_byte)intent;
  174285. info_ptr->valid |= PNG_INFO_sRGB;
  174286. }
  174287. void PNGAPI
  174288. png_set_sRGB_gAMA_and_cHRM(png_structp png_ptr, png_infop info_ptr,
  174289. int intent)
  174290. {
  174291. #if defined(PNG_gAMA_SUPPORTED)
  174292. #ifdef PNG_FLOATING_POINT_SUPPORTED
  174293. float file_gamma;
  174294. #endif
  174295. #ifdef PNG_FIXED_POINT_SUPPORTED
  174296. png_fixed_point int_file_gamma;
  174297. #endif
  174298. #endif
  174299. #if defined(PNG_cHRM_SUPPORTED)
  174300. #ifdef PNG_FLOATING_POINT_SUPPORTED
  174301. float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y;
  174302. #endif
  174303. #ifdef PNG_FIXED_POINT_SUPPORTED
  174304. png_fixed_point int_white_x, int_white_y, int_red_x, int_red_y, int_green_x,
  174305. int_green_y, int_blue_x, int_blue_y;
  174306. #endif
  174307. #endif
  174308. png_debug1(1, "in %s storage function\n", "sRGB_gAMA_and_cHRM");
  174309. if (png_ptr == NULL || info_ptr == NULL)
  174310. return;
  174311. png_set_sRGB(png_ptr, info_ptr, intent);
  174312. #if defined(PNG_gAMA_SUPPORTED)
  174313. #ifdef PNG_FLOATING_POINT_SUPPORTED
  174314. file_gamma = (float).45455;
  174315. png_set_gAMA(png_ptr, info_ptr, file_gamma);
  174316. #endif
  174317. #ifdef PNG_FIXED_POINT_SUPPORTED
  174318. int_file_gamma = 45455L;
  174319. png_set_gAMA_fixed(png_ptr, info_ptr, int_file_gamma);
  174320. #endif
  174321. #endif
  174322. #if defined(PNG_cHRM_SUPPORTED)
  174323. #ifdef PNG_FIXED_POINT_SUPPORTED
  174324. int_white_x = 31270L;
  174325. int_white_y = 32900L;
  174326. int_red_x = 64000L;
  174327. int_red_y = 33000L;
  174328. int_green_x = 30000L;
  174329. int_green_y = 60000L;
  174330. int_blue_x = 15000L;
  174331. int_blue_y = 6000L;
  174332. png_set_cHRM_fixed(png_ptr, info_ptr,
  174333. int_white_x, int_white_y, int_red_x, int_red_y, int_green_x, int_green_y,
  174334. int_blue_x, int_blue_y);
  174335. #endif
  174336. #ifdef PNG_FLOATING_POINT_SUPPORTED
  174337. white_x = (float).3127;
  174338. white_y = (float).3290;
  174339. red_x = (float).64;
  174340. red_y = (float).33;
  174341. green_x = (float).30;
  174342. green_y = (float).60;
  174343. blue_x = (float).15;
  174344. blue_y = (float).06;
  174345. png_set_cHRM(png_ptr, info_ptr,
  174346. white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y);
  174347. #endif
  174348. #endif
  174349. }
  174350. #endif
  174351. #if defined(PNG_iCCP_SUPPORTED)
  174352. void PNGAPI
  174353. png_set_iCCP(png_structp png_ptr, png_infop info_ptr,
  174354. png_charp name, int compression_type,
  174355. png_charp profile, png_uint_32 proflen)
  174356. {
  174357. png_charp new_iccp_name;
  174358. png_charp new_iccp_profile;
  174359. png_debug1(1, "in %s storage function\n", "iCCP");
  174360. if (png_ptr == NULL || info_ptr == NULL || name == NULL || profile == NULL)
  174361. return;
  174362. new_iccp_name = (png_charp)png_malloc_warn(png_ptr, png_strlen(name)+1);
  174363. if (new_iccp_name == NULL)
  174364. {
  174365. png_warning(png_ptr, "Insufficient memory to process iCCP chunk.");
  174366. return;
  174367. }
  174368. png_strncpy(new_iccp_name, name, png_strlen(name)+1);
  174369. new_iccp_profile = (png_charp)png_malloc_warn(png_ptr, proflen);
  174370. if (new_iccp_profile == NULL)
  174371. {
  174372. png_free (png_ptr, new_iccp_name);
  174373. png_warning(png_ptr, "Insufficient memory to process iCCP profile.");
  174374. return;
  174375. }
  174376. png_memcpy(new_iccp_profile, profile, (png_size_t)proflen);
  174377. png_free_data(png_ptr, info_ptr, PNG_FREE_ICCP, 0);
  174378. info_ptr->iccp_proflen = proflen;
  174379. info_ptr->iccp_name = new_iccp_name;
  174380. info_ptr->iccp_profile = new_iccp_profile;
  174381. info_ptr->iccp_compression = (png_byte)compression_type;
  174382. #ifdef PNG_FREE_ME_SUPPORTED
  174383. info_ptr->free_me |= PNG_FREE_ICCP;
  174384. #endif
  174385. info_ptr->valid |= PNG_INFO_iCCP;
  174386. }
  174387. #endif
  174388. #if defined(PNG_TEXT_SUPPORTED)
  174389. void PNGAPI
  174390. png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
  174391. int num_text)
  174392. {
  174393. int ret;
  174394. ret=png_set_text_2(png_ptr, info_ptr, text_ptr, num_text);
  174395. if (ret)
  174396. png_error(png_ptr, "Insufficient memory to store text");
  174397. }
  174398. int /* PRIVATE */
  174399. png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
  174400. int num_text)
  174401. {
  174402. int i;
  174403. png_debug1(1, "in %s storage function\n", (png_ptr->chunk_name[0] == '\0' ?
  174404. "text" : (png_const_charp)png_ptr->chunk_name));
  174405. if (png_ptr == NULL || info_ptr == NULL || num_text == 0)
  174406. return(0);
  174407. if (info_ptr->num_text + num_text > info_ptr->max_text)
  174408. {
  174409. if (info_ptr->text != NULL)
  174410. {
  174411. png_textp old_text;
  174412. int old_max;
  174413. old_max = info_ptr->max_text;
  174414. info_ptr->max_text = info_ptr->num_text + num_text + 8;
  174415. old_text = info_ptr->text;
  174416. info_ptr->text = (png_textp)png_malloc_warn(png_ptr,
  174417. (png_uint_32)(info_ptr->max_text * png_sizeof (png_text)));
  174418. if (info_ptr->text == NULL)
  174419. {
  174420. png_free(png_ptr, old_text);
  174421. return(1);
  174422. }
  174423. png_memcpy(info_ptr->text, old_text, (png_size_t)(old_max *
  174424. png_sizeof(png_text)));
  174425. png_free(png_ptr, old_text);
  174426. }
  174427. else
  174428. {
  174429. info_ptr->max_text = num_text + 8;
  174430. info_ptr->num_text = 0;
  174431. info_ptr->text = (png_textp)png_malloc_warn(png_ptr,
  174432. (png_uint_32)(info_ptr->max_text * png_sizeof (png_text)));
  174433. if (info_ptr->text == NULL)
  174434. return(1);
  174435. #ifdef PNG_FREE_ME_SUPPORTED
  174436. info_ptr->free_me |= PNG_FREE_TEXT;
  174437. #endif
  174438. }
  174439. png_debug1(3, "allocated %d entries for info_ptr->text\n",
  174440. info_ptr->max_text);
  174441. }
  174442. for (i = 0; i < num_text; i++)
  174443. {
  174444. png_size_t text_length,key_len;
  174445. png_size_t lang_len,lang_key_len;
  174446. png_textp textp = &(info_ptr->text[info_ptr->num_text]);
  174447. if (text_ptr[i].key == NULL)
  174448. continue;
  174449. key_len = png_strlen(text_ptr[i].key);
  174450. if(text_ptr[i].compression <= 0)
  174451. {
  174452. lang_len = 0;
  174453. lang_key_len = 0;
  174454. }
  174455. else
  174456. #ifdef PNG_iTXt_SUPPORTED
  174457. {
  174458. if (text_ptr[i].lang != NULL)
  174459. lang_len = png_strlen(text_ptr[i].lang);
  174460. else
  174461. lang_len = 0;
  174462. if (text_ptr[i].lang_key != NULL)
  174463. lang_key_len = png_strlen(text_ptr[i].lang_key);
  174464. else
  174465. lang_key_len = 0;
  174466. }
  174467. #else
  174468. {
  174469. png_warning(png_ptr, "iTXt chunk not supported.");
  174470. continue;
  174471. }
  174472. #endif
  174473. if (text_ptr[i].text == NULL || text_ptr[i].text[0] == '\0')
  174474. {
  174475. text_length = 0;
  174476. #ifdef PNG_iTXt_SUPPORTED
  174477. if(text_ptr[i].compression > 0)
  174478. textp->compression = PNG_ITXT_COMPRESSION_NONE;
  174479. else
  174480. #endif
  174481. textp->compression = PNG_TEXT_COMPRESSION_NONE;
  174482. }
  174483. else
  174484. {
  174485. text_length = png_strlen(text_ptr[i].text);
  174486. textp->compression = text_ptr[i].compression;
  174487. }
  174488. textp->key = (png_charp)png_malloc_warn(png_ptr,
  174489. (png_uint_32)(key_len + text_length + lang_len + lang_key_len + 4));
  174490. if (textp->key == NULL)
  174491. return(1);
  174492. png_debug2(2, "Allocated %lu bytes at %x in png_set_text\n",
  174493. (png_uint_32)(key_len + lang_len + lang_key_len + text_length + 4),
  174494. (int)textp->key);
  174495. png_memcpy(textp->key, text_ptr[i].key,
  174496. (png_size_t)(key_len));
  174497. *(textp->key+key_len) = '\0';
  174498. #ifdef PNG_iTXt_SUPPORTED
  174499. if (text_ptr[i].compression > 0)
  174500. {
  174501. textp->lang=textp->key + key_len + 1;
  174502. png_memcpy(textp->lang, text_ptr[i].lang, lang_len);
  174503. *(textp->lang+lang_len) = '\0';
  174504. textp->lang_key=textp->lang + lang_len + 1;
  174505. png_memcpy(textp->lang_key, text_ptr[i].lang_key, lang_key_len);
  174506. *(textp->lang_key+lang_key_len) = '\0';
  174507. textp->text=textp->lang_key + lang_key_len + 1;
  174508. }
  174509. else
  174510. #endif
  174511. {
  174512. #ifdef PNG_iTXt_SUPPORTED
  174513. textp->lang=NULL;
  174514. textp->lang_key=NULL;
  174515. #endif
  174516. textp->text=textp->key + key_len + 1;
  174517. }
  174518. if(text_length)
  174519. png_memcpy(textp->text, text_ptr[i].text,
  174520. (png_size_t)(text_length));
  174521. *(textp->text+text_length) = '\0';
  174522. #ifdef PNG_iTXt_SUPPORTED
  174523. if(textp->compression > 0)
  174524. {
  174525. textp->text_length = 0;
  174526. textp->itxt_length = text_length;
  174527. }
  174528. else
  174529. #endif
  174530. {
  174531. textp->text_length = text_length;
  174532. #ifdef PNG_iTXt_SUPPORTED
  174533. textp->itxt_length = 0;
  174534. #endif
  174535. }
  174536. info_ptr->num_text++;
  174537. png_debug1(3, "transferred text chunk %d\n", info_ptr->num_text);
  174538. }
  174539. return(0);
  174540. }
  174541. #endif
  174542. #if defined(PNG_tIME_SUPPORTED)
  174543. void PNGAPI
  174544. png_set_tIME(png_structp png_ptr, png_infop info_ptr, png_timep mod_time)
  174545. {
  174546. png_debug1(1, "in %s storage function\n", "tIME");
  174547. if (png_ptr == NULL || info_ptr == NULL ||
  174548. (png_ptr->mode & PNG_WROTE_tIME))
  174549. return;
  174550. png_memcpy(&(info_ptr->mod_time), mod_time, png_sizeof (png_time));
  174551. info_ptr->valid |= PNG_INFO_tIME;
  174552. }
  174553. #endif
  174554. #if defined(PNG_tRNS_SUPPORTED)
  174555. void PNGAPI
  174556. png_set_tRNS(png_structp png_ptr, png_infop info_ptr,
  174557. png_bytep trans, int num_trans, png_color_16p trans_values)
  174558. {
  174559. png_debug1(1, "in %s storage function\n", "tRNS");
  174560. if (png_ptr == NULL || info_ptr == NULL)
  174561. return;
  174562. if (trans != NULL)
  174563. {
  174564. #ifdef PNG_FREE_ME_SUPPORTED
  174565. png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, 0);
  174566. #endif
  174567. png_ptr->trans = info_ptr->trans = (png_bytep)png_malloc(png_ptr,
  174568. (png_uint_32)PNG_MAX_PALETTE_LENGTH);
  174569. if (num_trans <= PNG_MAX_PALETTE_LENGTH)
  174570. png_memcpy(info_ptr->trans, trans, (png_size_t)num_trans);
  174571. #ifdef PNG_FREE_ME_SUPPORTED
  174572. info_ptr->free_me |= PNG_FREE_TRNS;
  174573. #else
  174574. png_ptr->flags |= PNG_FLAG_FREE_TRNS;
  174575. #endif
  174576. }
  174577. if (trans_values != NULL)
  174578. {
  174579. png_memcpy(&(info_ptr->trans_values), trans_values,
  174580. png_sizeof(png_color_16));
  174581. if (num_trans == 0)
  174582. num_trans = 1;
  174583. }
  174584. info_ptr->num_trans = (png_uint_16)num_trans;
  174585. info_ptr->valid |= PNG_INFO_tRNS;
  174586. }
  174587. #endif
  174588. #if defined(PNG_sPLT_SUPPORTED)
  174589. void PNGAPI
  174590. png_set_sPLT(png_structp png_ptr,
  174591. png_infop info_ptr, png_sPLT_tp entries, int nentries)
  174592. {
  174593. png_sPLT_tp np;
  174594. int i;
  174595. if (png_ptr == NULL || info_ptr == NULL)
  174596. return;
  174597. np = (png_sPLT_tp)png_malloc_warn(png_ptr,
  174598. (info_ptr->splt_palettes_num + nentries) * png_sizeof(png_sPLT_t));
  174599. if (np == NULL)
  174600. {
  174601. png_warning(png_ptr, "No memory for sPLT palettes.");
  174602. return;
  174603. }
  174604. png_memcpy(np, info_ptr->splt_palettes,
  174605. info_ptr->splt_palettes_num * png_sizeof(png_sPLT_t));
  174606. png_free(png_ptr, info_ptr->splt_palettes);
  174607. info_ptr->splt_palettes=NULL;
  174608. for (i = 0; i < nentries; i++)
  174609. {
  174610. png_sPLT_tp to = np + info_ptr->splt_palettes_num + i;
  174611. png_sPLT_tp from = entries + i;
  174612. to->name = (png_charp)png_malloc_warn(png_ptr,
  174613. png_strlen(from->name) + 1);
  174614. if (to->name == NULL)
  174615. {
  174616. png_warning(png_ptr,
  174617. "Out of memory while processing sPLT chunk");
  174618. }
  174619. png_strncpy(to->name, from->name, png_strlen(from->name)+1);
  174620. to->entries = (png_sPLT_entryp)png_malloc_warn(png_ptr,
  174621. from->nentries * png_sizeof(png_sPLT_entry));
  174622. png_memcpy(to->entries, from->entries,
  174623. from->nentries * png_sizeof(png_sPLT_entry));
  174624. if (to->entries == NULL)
  174625. {
  174626. png_warning(png_ptr,
  174627. "Out of memory while processing sPLT chunk");
  174628. png_free(png_ptr,to->name);
  174629. to->name = NULL;
  174630. }
  174631. to->nentries = from->nentries;
  174632. to->depth = from->depth;
  174633. }
  174634. info_ptr->splt_palettes = np;
  174635. info_ptr->splt_palettes_num += nentries;
  174636. info_ptr->valid |= PNG_INFO_sPLT;
  174637. #ifdef PNG_FREE_ME_SUPPORTED
  174638. info_ptr->free_me |= PNG_FREE_SPLT;
  174639. #endif
  174640. }
  174641. #endif /* PNG_sPLT_SUPPORTED */
  174642. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  174643. void PNGAPI
  174644. png_set_unknown_chunks(png_structp png_ptr,
  174645. png_infop info_ptr, png_unknown_chunkp unknowns, int num_unknowns)
  174646. {
  174647. png_unknown_chunkp np;
  174648. int i;
  174649. if (png_ptr == NULL || info_ptr == NULL || num_unknowns == 0)
  174650. return;
  174651. np = (png_unknown_chunkp)png_malloc_warn(png_ptr,
  174652. (info_ptr->unknown_chunks_num + num_unknowns) *
  174653. png_sizeof(png_unknown_chunk));
  174654. if (np == NULL)
  174655. {
  174656. png_warning(png_ptr,
  174657. "Out of memory while processing unknown chunk.");
  174658. return;
  174659. }
  174660. png_memcpy(np, info_ptr->unknown_chunks,
  174661. info_ptr->unknown_chunks_num * png_sizeof(png_unknown_chunk));
  174662. png_free(png_ptr, info_ptr->unknown_chunks);
  174663. info_ptr->unknown_chunks=NULL;
  174664. for (i = 0; i < num_unknowns; i++)
  174665. {
  174666. png_unknown_chunkp to = np + info_ptr->unknown_chunks_num + i;
  174667. png_unknown_chunkp from = unknowns + i;
  174668. png_strncpy((png_charp)to->name, (png_charp)from->name, 5);
  174669. to->data = (png_bytep)png_malloc_warn(png_ptr, from->size);
  174670. if (to->data == NULL)
  174671. {
  174672. png_warning(png_ptr,
  174673. "Out of memory while processing unknown chunk.");
  174674. }
  174675. else
  174676. {
  174677. png_memcpy(to->data, from->data, from->size);
  174678. to->size = from->size;
  174679. to->location = (png_byte)(png_ptr->mode & 0xff);
  174680. }
  174681. }
  174682. info_ptr->unknown_chunks = np;
  174683. info_ptr->unknown_chunks_num += num_unknowns;
  174684. #ifdef PNG_FREE_ME_SUPPORTED
  174685. info_ptr->free_me |= PNG_FREE_UNKN;
  174686. #endif
  174687. }
  174688. void PNGAPI
  174689. png_set_unknown_chunk_location(png_structp png_ptr, png_infop info_ptr,
  174690. int chunk, int location)
  174691. {
  174692. if(png_ptr != NULL && info_ptr != NULL && chunk >= 0 && chunk <
  174693. (int)info_ptr->unknown_chunks_num)
  174694. info_ptr->unknown_chunks[chunk].location = (png_byte)location;
  174695. }
  174696. #endif
  174697. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  174698. #if defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
  174699. defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
  174700. void PNGAPI
  174701. png_permit_empty_plte (png_structp png_ptr, int empty_plte_permitted)
  174702. {
  174703. png_debug(1, "in png_permit_empty_plte, DEPRECATED.\n");
  174704. if (png_ptr == NULL)
  174705. return;
  174706. png_ptr->mng_features_permitted = (png_byte)
  174707. ((png_ptr->mng_features_permitted & (~(PNG_FLAG_MNG_EMPTY_PLTE))) |
  174708. ((empty_plte_permitted & PNG_FLAG_MNG_EMPTY_PLTE)));
  174709. }
  174710. #endif
  174711. #endif
  174712. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  174713. png_uint_32 PNGAPI
  174714. png_permit_mng_features (png_structp png_ptr, png_uint_32 mng_features)
  174715. {
  174716. png_debug(1, "in png_permit_mng_features\n");
  174717. if (png_ptr == NULL)
  174718. return (png_uint_32)0;
  174719. png_ptr->mng_features_permitted =
  174720. (png_byte)(mng_features & PNG_ALL_MNG_FEATURES);
  174721. return (png_uint_32)png_ptr->mng_features_permitted;
  174722. }
  174723. #endif
  174724. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  174725. void PNGAPI
  174726. png_set_keep_unknown_chunks(png_structp png_ptr, int keep, png_bytep
  174727. chunk_list, int num_chunks)
  174728. {
  174729. png_bytep new_list, p;
  174730. int i, old_num_chunks;
  174731. if (png_ptr == NULL)
  174732. return;
  174733. if (num_chunks == 0)
  174734. {
  174735. if(keep == PNG_HANDLE_CHUNK_ALWAYS || keep == PNG_HANDLE_CHUNK_IF_SAFE)
  174736. png_ptr->flags |= PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
  174737. else
  174738. png_ptr->flags &= ~PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
  174739. if(keep == PNG_HANDLE_CHUNK_ALWAYS)
  174740. png_ptr->flags |= PNG_FLAG_KEEP_UNSAFE_CHUNKS;
  174741. else
  174742. png_ptr->flags &= ~PNG_FLAG_KEEP_UNSAFE_CHUNKS;
  174743. return;
  174744. }
  174745. if (chunk_list == NULL)
  174746. return;
  174747. old_num_chunks=png_ptr->num_chunk_list;
  174748. new_list=(png_bytep)png_malloc(png_ptr,
  174749. (png_uint_32)(5*(num_chunks+old_num_chunks)));
  174750. if(png_ptr->chunk_list != NULL)
  174751. {
  174752. png_memcpy(new_list, png_ptr->chunk_list,
  174753. (png_size_t)(5*old_num_chunks));
  174754. png_free(png_ptr, png_ptr->chunk_list);
  174755. png_ptr->chunk_list=NULL;
  174756. }
  174757. png_memcpy(new_list+5*old_num_chunks, chunk_list,
  174758. (png_size_t)(5*num_chunks));
  174759. for (p=new_list+5*old_num_chunks+4, i=0; i<num_chunks; i++, p+=5)
  174760. *p=(png_byte)keep;
  174761. png_ptr->num_chunk_list=old_num_chunks+num_chunks;
  174762. png_ptr->chunk_list=new_list;
  174763. #ifdef PNG_FREE_ME_SUPPORTED
  174764. png_ptr->free_me |= PNG_FREE_LIST;
  174765. #endif
  174766. }
  174767. #endif
  174768. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  174769. void PNGAPI
  174770. png_set_read_user_chunk_fn(png_structp png_ptr, png_voidp user_chunk_ptr,
  174771. png_user_chunk_ptr read_user_chunk_fn)
  174772. {
  174773. png_debug(1, "in png_set_read_user_chunk_fn\n");
  174774. if (png_ptr == NULL)
  174775. return;
  174776. png_ptr->read_user_chunk_fn = read_user_chunk_fn;
  174777. png_ptr->user_chunk_ptr = user_chunk_ptr;
  174778. }
  174779. #endif
  174780. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  174781. void PNGAPI
  174782. png_set_rows(png_structp png_ptr, png_infop info_ptr, png_bytepp row_pointers)
  174783. {
  174784. png_debug1(1, "in %s storage function\n", "rows");
  174785. if (png_ptr == NULL || info_ptr == NULL)
  174786. return;
  174787. if(info_ptr->row_pointers && (info_ptr->row_pointers != row_pointers))
  174788. png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0);
  174789. info_ptr->row_pointers = row_pointers;
  174790. if(row_pointers)
  174791. info_ptr->valid |= PNG_INFO_IDAT;
  174792. }
  174793. #endif
  174794. #ifdef PNG_WRITE_SUPPORTED
  174795. void PNGAPI
  174796. png_set_compression_buffer_size(png_structp png_ptr, png_uint_32 size)
  174797. {
  174798. if (png_ptr == NULL)
  174799. return;
  174800. if(png_ptr->zbuf)
  174801. png_free(png_ptr, png_ptr->zbuf);
  174802. png_ptr->zbuf_size = (png_size_t)size;
  174803. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, size);
  174804. png_ptr->zstream.next_out = png_ptr->zbuf;
  174805. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  174806. }
  174807. #endif
  174808. void PNGAPI
  174809. png_set_invalid(png_structp png_ptr, png_infop info_ptr, int mask)
  174810. {
  174811. if (png_ptr && info_ptr)
  174812. info_ptr->valid &= ~(mask);
  174813. }
  174814. #ifndef PNG_1_0_X
  174815. #ifdef PNG_ASSEMBLER_CODE_SUPPORTED
  174816. void PNGAPI
  174817. png_set_asm_flags (png_structp png_ptr, png_uint_32 asm_flags)
  174818. {
  174819. if (png_ptr != NULL)
  174820. png_ptr->asm_flags = 0;
  174821. }
  174822. void PNGAPI
  174823. png_set_mmx_thresholds (png_structp png_ptr,
  174824. png_byte mmx_bitdepth_threshold,
  174825. png_uint_32 mmx_rowbytes_threshold)
  174826. {
  174827. if (png_ptr == NULL)
  174828. return;
  174829. }
  174830. #endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */
  174831. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  174832. void PNGAPI
  174833. png_set_user_limits (png_structp png_ptr, png_uint_32 user_width_max,
  174834. png_uint_32 user_height_max)
  174835. {
  174836. if(png_ptr == NULL) return;
  174837. png_ptr->user_width_max = user_width_max;
  174838. png_ptr->user_height_max = user_height_max;
  174839. }
  174840. #endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
  174841. #endif /* ?PNG_1_0_X */
  174842. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  174843. /*** End of inlined file: pngset.c ***/
  174844. /*** Start of inlined file: pngtrans.c ***/
  174845. #define PNG_INTERNAL
  174846. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  174847. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  174848. void PNGAPI
  174849. png_set_bgr(png_structp png_ptr)
  174850. {
  174851. png_debug(1, "in png_set_bgr\n");
  174852. if(png_ptr == NULL) return;
  174853. png_ptr->transformations |= PNG_BGR;
  174854. }
  174855. #endif
  174856. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  174857. void PNGAPI
  174858. png_set_swap(png_structp png_ptr)
  174859. {
  174860. png_debug(1, "in png_set_swap\n");
  174861. if(png_ptr == NULL) return;
  174862. if (png_ptr->bit_depth == 16)
  174863. png_ptr->transformations |= PNG_SWAP_BYTES;
  174864. }
  174865. #endif
  174866. #if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
  174867. void PNGAPI
  174868. png_set_packing(png_structp png_ptr)
  174869. {
  174870. png_debug(1, "in png_set_packing\n");
  174871. if(png_ptr == NULL) return;
  174872. if (png_ptr->bit_depth < 8)
  174873. {
  174874. png_ptr->transformations |= PNG_PACK;
  174875. png_ptr->usr_bit_depth = 8;
  174876. }
  174877. }
  174878. #endif
  174879. #if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  174880. void PNGAPI
  174881. png_set_packswap(png_structp png_ptr)
  174882. {
  174883. png_debug(1, "in png_set_packswap\n");
  174884. if(png_ptr == NULL) return;
  174885. if (png_ptr->bit_depth < 8)
  174886. png_ptr->transformations |= PNG_PACKSWAP;
  174887. }
  174888. #endif
  174889. #if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
  174890. void PNGAPI
  174891. png_set_shift(png_structp png_ptr, png_color_8p true_bits)
  174892. {
  174893. png_debug(1, "in png_set_shift\n");
  174894. if(png_ptr == NULL) return;
  174895. png_ptr->transformations |= PNG_SHIFT;
  174896. png_ptr->shift = *true_bits;
  174897. }
  174898. #endif
  174899. #if defined(PNG_READ_INTERLACING_SUPPORTED) || \
  174900. defined(PNG_WRITE_INTERLACING_SUPPORTED)
  174901. int PNGAPI
  174902. png_set_interlace_handling(png_structp png_ptr)
  174903. {
  174904. png_debug(1, "in png_set_interlace handling\n");
  174905. if (png_ptr && png_ptr->interlaced)
  174906. {
  174907. png_ptr->transformations |= PNG_INTERLACE;
  174908. return (7);
  174909. }
  174910. return (1);
  174911. }
  174912. #endif
  174913. #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
  174914. void PNGAPI
  174915. png_set_filler(png_structp png_ptr, png_uint_32 filler, int filler_loc)
  174916. {
  174917. png_debug(1, "in png_set_filler\n");
  174918. if(png_ptr == NULL) return;
  174919. png_ptr->transformations |= PNG_FILLER;
  174920. png_ptr->filler = (png_byte)filler;
  174921. if (filler_loc == PNG_FILLER_AFTER)
  174922. png_ptr->flags |= PNG_FLAG_FILLER_AFTER;
  174923. else
  174924. png_ptr->flags &= ~PNG_FLAG_FILLER_AFTER;
  174925. if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
  174926. {
  174927. png_ptr->usr_channels = 4;
  174928. }
  174929. if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY && png_ptr->bit_depth >= 8)
  174930. {
  174931. png_ptr->usr_channels = 2;
  174932. }
  174933. }
  174934. #if !defined(PNG_1_0_X)
  174935. void PNGAPI
  174936. png_set_add_alpha(png_structp png_ptr, png_uint_32 filler, int filler_loc)
  174937. {
  174938. png_debug(1, "in png_set_add_alpha\n");
  174939. if(png_ptr == NULL) return;
  174940. png_set_filler(png_ptr, filler, filler_loc);
  174941. png_ptr->transformations |= PNG_ADD_ALPHA;
  174942. }
  174943. #endif
  174944. #endif
  174945. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) || \
  174946. defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  174947. void PNGAPI
  174948. png_set_swap_alpha(png_structp png_ptr)
  174949. {
  174950. png_debug(1, "in png_set_swap_alpha\n");
  174951. if(png_ptr == NULL) return;
  174952. png_ptr->transformations |= PNG_SWAP_ALPHA;
  174953. }
  174954. #endif
  174955. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) || \
  174956. defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  174957. void PNGAPI
  174958. png_set_invert_alpha(png_structp png_ptr)
  174959. {
  174960. png_debug(1, "in png_set_invert_alpha\n");
  174961. if(png_ptr == NULL) return;
  174962. png_ptr->transformations |= PNG_INVERT_ALPHA;
  174963. }
  174964. #endif
  174965. #if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
  174966. void PNGAPI
  174967. png_set_invert_mono(png_structp png_ptr)
  174968. {
  174969. png_debug(1, "in png_set_invert_mono\n");
  174970. if(png_ptr == NULL) return;
  174971. png_ptr->transformations |= PNG_INVERT_MONO;
  174972. }
  174973. void /* PRIVATE */
  174974. png_do_invert(png_row_infop row_info, png_bytep row)
  174975. {
  174976. png_debug(1, "in png_do_invert\n");
  174977. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  174978. if (row == NULL || row_info == NULL)
  174979. return;
  174980. #endif
  174981. if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
  174982. {
  174983. png_bytep rp = row;
  174984. png_uint_32 i;
  174985. png_uint_32 istop = row_info->rowbytes;
  174986. for (i = 0; i < istop; i++)
  174987. {
  174988. *rp = (png_byte)(~(*rp));
  174989. rp++;
  174990. }
  174991. }
  174992. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
  174993. row_info->bit_depth == 8)
  174994. {
  174995. png_bytep rp = row;
  174996. png_uint_32 i;
  174997. png_uint_32 istop = row_info->rowbytes;
  174998. for (i = 0; i < istop; i+=2)
  174999. {
  175000. *rp = (png_byte)(~(*rp));
  175001. rp+=2;
  175002. }
  175003. }
  175004. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
  175005. row_info->bit_depth == 16)
  175006. {
  175007. png_bytep rp = row;
  175008. png_uint_32 i;
  175009. png_uint_32 istop = row_info->rowbytes;
  175010. for (i = 0; i < istop; i+=4)
  175011. {
  175012. *rp = (png_byte)(~(*rp));
  175013. *(rp+1) = (png_byte)(~(*(rp+1)));
  175014. rp+=4;
  175015. }
  175016. }
  175017. }
  175018. #endif
  175019. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  175020. void /* PRIVATE */
  175021. png_do_swap(png_row_infop row_info, png_bytep row)
  175022. {
  175023. png_debug(1, "in png_do_swap\n");
  175024. if (
  175025. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  175026. row != NULL && row_info != NULL &&
  175027. #endif
  175028. row_info->bit_depth == 16)
  175029. {
  175030. png_bytep rp = row;
  175031. png_uint_32 i;
  175032. png_uint_32 istop= row_info->width * row_info->channels;
  175033. for (i = 0; i < istop; i++, rp += 2)
  175034. {
  175035. png_byte t = *rp;
  175036. *rp = *(rp + 1);
  175037. *(rp + 1) = t;
  175038. }
  175039. }
  175040. }
  175041. #endif
  175042. #if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  175043. static PNG_CONST png_byte onebppswaptable[256] = {
  175044. 0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0,
  175045. 0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0,
  175046. 0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8,
  175047. 0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8,
  175048. 0x04, 0x84, 0x44, 0xC4, 0x24, 0xA4, 0x64, 0xE4,
  175049. 0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4,
  175050. 0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC,
  175051. 0x1C, 0x9C, 0x5C, 0xDC, 0x3C, 0xBC, 0x7C, 0xFC,
  175052. 0x02, 0x82, 0x42, 0xC2, 0x22, 0xA2, 0x62, 0xE2,
  175053. 0x12, 0x92, 0x52, 0xD2, 0x32, 0xB2, 0x72, 0xF2,
  175054. 0x0A, 0x8A, 0x4A, 0xCA, 0x2A, 0xAA, 0x6A, 0xEA,
  175055. 0x1A, 0x9A, 0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA,
  175056. 0x06, 0x86, 0x46, 0xC6, 0x26, 0xA6, 0x66, 0xE6,
  175057. 0x16, 0x96, 0x56, 0xD6, 0x36, 0xB6, 0x76, 0xF6,
  175058. 0x0E, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE,
  175059. 0x1E, 0x9E, 0x5E, 0xDE, 0x3E, 0xBE, 0x7E, 0xFE,
  175060. 0x01, 0x81, 0x41, 0xC1, 0x21, 0xA1, 0x61, 0xE1,
  175061. 0x11, 0x91, 0x51, 0xD1, 0x31, 0xB1, 0x71, 0xF1,
  175062. 0x09, 0x89, 0x49, 0xC9, 0x29, 0xA9, 0x69, 0xE9,
  175063. 0x19, 0x99, 0x59, 0xD9, 0x39, 0xB9, 0x79, 0xF9,
  175064. 0x05, 0x85, 0x45, 0xC5, 0x25, 0xA5, 0x65, 0xE5,
  175065. 0x15, 0x95, 0x55, 0xD5, 0x35, 0xB5, 0x75, 0xF5,
  175066. 0x0D, 0x8D, 0x4D, 0xCD, 0x2D, 0xAD, 0x6D, 0xED,
  175067. 0x1D, 0x9D, 0x5D, 0xDD, 0x3D, 0xBD, 0x7D, 0xFD,
  175068. 0x03, 0x83, 0x43, 0xC3, 0x23, 0xA3, 0x63, 0xE3,
  175069. 0x13, 0x93, 0x53, 0xD3, 0x33, 0xB3, 0x73, 0xF3,
  175070. 0x0B, 0x8B, 0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB,
  175071. 0x1B, 0x9B, 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB,
  175072. 0x07, 0x87, 0x47, 0xC7, 0x27, 0xA7, 0x67, 0xE7,
  175073. 0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7,
  175074. 0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF,
  175075. 0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF
  175076. };
  175077. static PNG_CONST png_byte twobppswaptable[256] = {
  175078. 0x00, 0x40, 0x80, 0xC0, 0x10, 0x50, 0x90, 0xD0,
  175079. 0x20, 0x60, 0xA0, 0xE0, 0x30, 0x70, 0xB0, 0xF0,
  175080. 0x04, 0x44, 0x84, 0xC4, 0x14, 0x54, 0x94, 0xD4,
  175081. 0x24, 0x64, 0xA4, 0xE4, 0x34, 0x74, 0xB4, 0xF4,
  175082. 0x08, 0x48, 0x88, 0xC8, 0x18, 0x58, 0x98, 0xD8,
  175083. 0x28, 0x68, 0xA8, 0xE8, 0x38, 0x78, 0xB8, 0xF8,
  175084. 0x0C, 0x4C, 0x8C, 0xCC, 0x1C, 0x5C, 0x9C, 0xDC,
  175085. 0x2C, 0x6C, 0xAC, 0xEC, 0x3C, 0x7C, 0xBC, 0xFC,
  175086. 0x01, 0x41, 0x81, 0xC1, 0x11, 0x51, 0x91, 0xD1,
  175087. 0x21, 0x61, 0xA1, 0xE1, 0x31, 0x71, 0xB1, 0xF1,
  175088. 0x05, 0x45, 0x85, 0xC5, 0x15, 0x55, 0x95, 0xD5,
  175089. 0x25, 0x65, 0xA5, 0xE5, 0x35, 0x75, 0xB5, 0xF5,
  175090. 0x09, 0x49, 0x89, 0xC9, 0x19, 0x59, 0x99, 0xD9,
  175091. 0x29, 0x69, 0xA9, 0xE9, 0x39, 0x79, 0xB9, 0xF9,
  175092. 0x0D, 0x4D, 0x8D, 0xCD, 0x1D, 0x5D, 0x9D, 0xDD,
  175093. 0x2D, 0x6D, 0xAD, 0xED, 0x3D, 0x7D, 0xBD, 0xFD,
  175094. 0x02, 0x42, 0x82, 0xC2, 0x12, 0x52, 0x92, 0xD2,
  175095. 0x22, 0x62, 0xA2, 0xE2, 0x32, 0x72, 0xB2, 0xF2,
  175096. 0x06, 0x46, 0x86, 0xC6, 0x16, 0x56, 0x96, 0xD6,
  175097. 0x26, 0x66, 0xA6, 0xE6, 0x36, 0x76, 0xB6, 0xF6,
  175098. 0x0A, 0x4A, 0x8A, 0xCA, 0x1A, 0x5A, 0x9A, 0xDA,
  175099. 0x2A, 0x6A, 0xAA, 0xEA, 0x3A, 0x7A, 0xBA, 0xFA,
  175100. 0x0E, 0x4E, 0x8E, 0xCE, 0x1E, 0x5E, 0x9E, 0xDE,
  175101. 0x2E, 0x6E, 0xAE, 0xEE, 0x3E, 0x7E, 0xBE, 0xFE,
  175102. 0x03, 0x43, 0x83, 0xC3, 0x13, 0x53, 0x93, 0xD3,
  175103. 0x23, 0x63, 0xA3, 0xE3, 0x33, 0x73, 0xB3, 0xF3,
  175104. 0x07, 0x47, 0x87, 0xC7, 0x17, 0x57, 0x97, 0xD7,
  175105. 0x27, 0x67, 0xA7, 0xE7, 0x37, 0x77, 0xB7, 0xF7,
  175106. 0x0B, 0x4B, 0x8B, 0xCB, 0x1B, 0x5B, 0x9B, 0xDB,
  175107. 0x2B, 0x6B, 0xAB, 0xEB, 0x3B, 0x7B, 0xBB, 0xFB,
  175108. 0x0F, 0x4F, 0x8F, 0xCF, 0x1F, 0x5F, 0x9F, 0xDF,
  175109. 0x2F, 0x6F, 0xAF, 0xEF, 0x3F, 0x7F, 0xBF, 0xFF
  175110. };
  175111. static PNG_CONST png_byte fourbppswaptable[256] = {
  175112. 0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70,
  175113. 0x80, 0x90, 0xA0, 0xB0, 0xC0, 0xD0, 0xE0, 0xF0,
  175114. 0x01, 0x11, 0x21, 0x31, 0x41, 0x51, 0x61, 0x71,
  175115. 0x81, 0x91, 0xA1, 0xB1, 0xC1, 0xD1, 0xE1, 0xF1,
  175116. 0x02, 0x12, 0x22, 0x32, 0x42, 0x52, 0x62, 0x72,
  175117. 0x82, 0x92, 0xA2, 0xB2, 0xC2, 0xD2, 0xE2, 0xF2,
  175118. 0x03, 0x13, 0x23, 0x33, 0x43, 0x53, 0x63, 0x73,
  175119. 0x83, 0x93, 0xA3, 0xB3, 0xC3, 0xD3, 0xE3, 0xF3,
  175120. 0x04, 0x14, 0x24, 0x34, 0x44, 0x54, 0x64, 0x74,
  175121. 0x84, 0x94, 0xA4, 0xB4, 0xC4, 0xD4, 0xE4, 0xF4,
  175122. 0x05, 0x15, 0x25, 0x35, 0x45, 0x55, 0x65, 0x75,
  175123. 0x85, 0x95, 0xA5, 0xB5, 0xC5, 0xD5, 0xE5, 0xF5,
  175124. 0x06, 0x16, 0x26, 0x36, 0x46, 0x56, 0x66, 0x76,
  175125. 0x86, 0x96, 0xA6, 0xB6, 0xC6, 0xD6, 0xE6, 0xF6,
  175126. 0x07, 0x17, 0x27, 0x37, 0x47, 0x57, 0x67, 0x77,
  175127. 0x87, 0x97, 0xA7, 0xB7, 0xC7, 0xD7, 0xE7, 0xF7,
  175128. 0x08, 0x18, 0x28, 0x38, 0x48, 0x58, 0x68, 0x78,
  175129. 0x88, 0x98, 0xA8, 0xB8, 0xC8, 0xD8, 0xE8, 0xF8,
  175130. 0x09, 0x19, 0x29, 0x39, 0x49, 0x59, 0x69, 0x79,
  175131. 0x89, 0x99, 0xA9, 0xB9, 0xC9, 0xD9, 0xE9, 0xF9,
  175132. 0x0A, 0x1A, 0x2A, 0x3A, 0x4A, 0x5A, 0x6A, 0x7A,
  175133. 0x8A, 0x9A, 0xAA, 0xBA, 0xCA, 0xDA, 0xEA, 0xFA,
  175134. 0x0B, 0x1B, 0x2B, 0x3B, 0x4B, 0x5B, 0x6B, 0x7B,
  175135. 0x8B, 0x9B, 0xAB, 0xBB, 0xCB, 0xDB, 0xEB, 0xFB,
  175136. 0x0C, 0x1C, 0x2C, 0x3C, 0x4C, 0x5C, 0x6C, 0x7C,
  175137. 0x8C, 0x9C, 0xAC, 0xBC, 0xCC, 0xDC, 0xEC, 0xFC,
  175138. 0x0D, 0x1D, 0x2D, 0x3D, 0x4D, 0x5D, 0x6D, 0x7D,
  175139. 0x8D, 0x9D, 0xAD, 0xBD, 0xCD, 0xDD, 0xED, 0xFD,
  175140. 0x0E, 0x1E, 0x2E, 0x3E, 0x4E, 0x5E, 0x6E, 0x7E,
  175141. 0x8E, 0x9E, 0xAE, 0xBE, 0xCE, 0xDE, 0xEE, 0xFE,
  175142. 0x0F, 0x1F, 0x2F, 0x3F, 0x4F, 0x5F, 0x6F, 0x7F,
  175143. 0x8F, 0x9F, 0xAF, 0xBF, 0xCF, 0xDF, 0xEF, 0xFF
  175144. };
  175145. void /* PRIVATE */
  175146. png_do_packswap(png_row_infop row_info, png_bytep row)
  175147. {
  175148. png_debug(1, "in png_do_packswap\n");
  175149. if (
  175150. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  175151. row != NULL && row_info != NULL &&
  175152. #endif
  175153. row_info->bit_depth < 8)
  175154. {
  175155. png_bytep rp, end, table;
  175156. end = row + row_info->rowbytes;
  175157. if (row_info->bit_depth == 1)
  175158. table = (png_bytep)onebppswaptable;
  175159. else if (row_info->bit_depth == 2)
  175160. table = (png_bytep)twobppswaptable;
  175161. else if (row_info->bit_depth == 4)
  175162. table = (png_bytep)fourbppswaptable;
  175163. else
  175164. return;
  175165. for (rp = row; rp < end; rp++)
  175166. *rp = table[*rp];
  175167. }
  175168. }
  175169. #endif /* PNG_READ_PACKSWAP_SUPPORTED or PNG_WRITE_PACKSWAP_SUPPORTED */
  175170. #if defined(PNG_WRITE_FILLER_SUPPORTED) || \
  175171. defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  175172. void /* PRIVATE */
  175173. png_do_strip_filler(png_row_infop row_info, png_bytep row, png_uint_32 flags)
  175174. {
  175175. png_debug(1, "in png_do_strip_filler\n");
  175176. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  175177. if (row != NULL && row_info != NULL)
  175178. #endif
  175179. {
  175180. png_bytep sp=row;
  175181. png_bytep dp=row;
  175182. png_uint_32 row_width=row_info->width;
  175183. png_uint_32 i;
  175184. if ((row_info->color_type == PNG_COLOR_TYPE_RGB ||
  175185. (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA &&
  175186. (flags & PNG_FLAG_STRIP_ALPHA))) &&
  175187. row_info->channels == 4)
  175188. {
  175189. if (row_info->bit_depth == 8)
  175190. {
  175191. if (flags & PNG_FLAG_FILLER_AFTER)
  175192. {
  175193. dp+=3; sp+=4;
  175194. for (i = 1; i < row_width; i++)
  175195. {
  175196. *dp++ = *sp++;
  175197. *dp++ = *sp++;
  175198. *dp++ = *sp++;
  175199. sp++;
  175200. }
  175201. }
  175202. else
  175203. {
  175204. for (i = 0; i < row_width; i++)
  175205. {
  175206. sp++;
  175207. *dp++ = *sp++;
  175208. *dp++ = *sp++;
  175209. *dp++ = *sp++;
  175210. }
  175211. }
  175212. row_info->pixel_depth = 24;
  175213. row_info->rowbytes = row_width * 3;
  175214. }
  175215. else /* if (row_info->bit_depth == 16) */
  175216. {
  175217. if (flags & PNG_FLAG_FILLER_AFTER)
  175218. {
  175219. sp += 8; dp += 6;
  175220. for (i = 1; i < row_width; i++)
  175221. {
  175222. *dp++ = *sp++;
  175223. *dp++ = *sp++;
  175224. *dp++ = *sp++;
  175225. *dp++ = *sp++;
  175226. *dp++ = *sp++;
  175227. *dp++ = *sp++;
  175228. sp += 2;
  175229. }
  175230. }
  175231. else
  175232. {
  175233. for (i = 0; i < row_width; i++)
  175234. {
  175235. sp+=2;
  175236. *dp++ = *sp++;
  175237. *dp++ = *sp++;
  175238. *dp++ = *sp++;
  175239. *dp++ = *sp++;
  175240. *dp++ = *sp++;
  175241. *dp++ = *sp++;
  175242. }
  175243. }
  175244. row_info->pixel_depth = 48;
  175245. row_info->rowbytes = row_width * 6;
  175246. }
  175247. row_info->channels = 3;
  175248. }
  175249. else if ((row_info->color_type == PNG_COLOR_TYPE_GRAY ||
  175250. (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
  175251. (flags & PNG_FLAG_STRIP_ALPHA))) &&
  175252. row_info->channels == 2)
  175253. {
  175254. if (row_info->bit_depth == 8)
  175255. {
  175256. if (flags & PNG_FLAG_FILLER_AFTER)
  175257. {
  175258. for (i = 0; i < row_width; i++)
  175259. {
  175260. *dp++ = *sp++;
  175261. sp++;
  175262. }
  175263. }
  175264. else
  175265. {
  175266. for (i = 0; i < row_width; i++)
  175267. {
  175268. sp++;
  175269. *dp++ = *sp++;
  175270. }
  175271. }
  175272. row_info->pixel_depth = 8;
  175273. row_info->rowbytes = row_width;
  175274. }
  175275. else /* if (row_info->bit_depth == 16) */
  175276. {
  175277. if (flags & PNG_FLAG_FILLER_AFTER)
  175278. {
  175279. sp += 4; dp += 2;
  175280. for (i = 1; i < row_width; i++)
  175281. {
  175282. *dp++ = *sp++;
  175283. *dp++ = *sp++;
  175284. sp += 2;
  175285. }
  175286. }
  175287. else
  175288. {
  175289. for (i = 0; i < row_width; i++)
  175290. {
  175291. sp += 2;
  175292. *dp++ = *sp++;
  175293. *dp++ = *sp++;
  175294. }
  175295. }
  175296. row_info->pixel_depth = 16;
  175297. row_info->rowbytes = row_width * 2;
  175298. }
  175299. row_info->channels = 1;
  175300. }
  175301. if (flags & PNG_FLAG_STRIP_ALPHA)
  175302. row_info->color_type &= ~PNG_COLOR_MASK_ALPHA;
  175303. }
  175304. }
  175305. #endif
  175306. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  175307. void /* PRIVATE */
  175308. png_do_bgr(png_row_infop row_info, png_bytep row)
  175309. {
  175310. png_debug(1, "in png_do_bgr\n");
  175311. if (
  175312. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  175313. row != NULL && row_info != NULL &&
  175314. #endif
  175315. (row_info->color_type & PNG_COLOR_MASK_COLOR))
  175316. {
  175317. png_uint_32 row_width = row_info->width;
  175318. if (row_info->bit_depth == 8)
  175319. {
  175320. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  175321. {
  175322. png_bytep rp;
  175323. png_uint_32 i;
  175324. for (i = 0, rp = row; i < row_width; i++, rp += 3)
  175325. {
  175326. png_byte save = *rp;
  175327. *rp = *(rp + 2);
  175328. *(rp + 2) = save;
  175329. }
  175330. }
  175331. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  175332. {
  175333. png_bytep rp;
  175334. png_uint_32 i;
  175335. for (i = 0, rp = row; i < row_width; i++, rp += 4)
  175336. {
  175337. png_byte save = *rp;
  175338. *rp = *(rp + 2);
  175339. *(rp + 2) = save;
  175340. }
  175341. }
  175342. }
  175343. else if (row_info->bit_depth == 16)
  175344. {
  175345. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  175346. {
  175347. png_bytep rp;
  175348. png_uint_32 i;
  175349. for (i = 0, rp = row; i < row_width; i++, rp += 6)
  175350. {
  175351. png_byte save = *rp;
  175352. *rp = *(rp + 4);
  175353. *(rp + 4) = save;
  175354. save = *(rp + 1);
  175355. *(rp + 1) = *(rp + 5);
  175356. *(rp + 5) = save;
  175357. }
  175358. }
  175359. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  175360. {
  175361. png_bytep rp;
  175362. png_uint_32 i;
  175363. for (i = 0, rp = row; i < row_width; i++, rp += 8)
  175364. {
  175365. png_byte save = *rp;
  175366. *rp = *(rp + 4);
  175367. *(rp + 4) = save;
  175368. save = *(rp + 1);
  175369. *(rp + 1) = *(rp + 5);
  175370. *(rp + 5) = save;
  175371. }
  175372. }
  175373. }
  175374. }
  175375. }
  175376. #endif /* PNG_READ_BGR_SUPPORTED or PNG_WRITE_BGR_SUPPORTED */
  175377. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  175378. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  175379. defined(PNG_LEGACY_SUPPORTED)
  175380. void PNGAPI
  175381. png_set_user_transform_info(png_structp png_ptr, png_voidp
  175382. user_transform_ptr, int user_transform_depth, int user_transform_channels)
  175383. {
  175384. png_debug(1, "in png_set_user_transform_info\n");
  175385. if(png_ptr == NULL) return;
  175386. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  175387. png_ptr->user_transform_ptr = user_transform_ptr;
  175388. png_ptr->user_transform_depth = (png_byte)user_transform_depth;
  175389. png_ptr->user_transform_channels = (png_byte)user_transform_channels;
  175390. #else
  175391. if(user_transform_ptr || user_transform_depth || user_transform_channels)
  175392. png_warning(png_ptr,
  175393. "This version of libpng does not support user transform info");
  175394. #endif
  175395. }
  175396. #endif
  175397. png_voidp PNGAPI
  175398. png_get_user_transform_ptr(png_structp png_ptr)
  175399. {
  175400. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  175401. if (png_ptr == NULL) return (NULL);
  175402. return ((png_voidp)png_ptr->user_transform_ptr);
  175403. #else
  175404. return (NULL);
  175405. #endif
  175406. }
  175407. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  175408. /*** End of inlined file: pngtrans.c ***/
  175409. /*** Start of inlined file: pngwio.c ***/
  175410. #define PNG_INTERNAL
  175411. #ifdef PNG_WRITE_SUPPORTED
  175412. void /* PRIVATE */
  175413. png_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
  175414. {
  175415. if (png_ptr->write_data_fn != NULL )
  175416. (*(png_ptr->write_data_fn))(png_ptr, data, length);
  175417. else
  175418. png_error(png_ptr, "Call to NULL write function");
  175419. }
  175420. #if !defined(PNG_NO_STDIO)
  175421. #ifndef USE_FAR_KEYWORD
  175422. void PNGAPI
  175423. png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
  175424. {
  175425. png_uint_32 check;
  175426. if(png_ptr == NULL) return;
  175427. #if defined(_WIN32_WCE)
  175428. if ( !WriteFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) )
  175429. check = 0;
  175430. #else
  175431. check = fwrite(data, 1, length, (png_FILE_p)(png_ptr->io_ptr));
  175432. #endif
  175433. if (check != length)
  175434. png_error(png_ptr, "Write Error");
  175435. }
  175436. #else
  175437. #define NEAR_BUF_SIZE 1024
  175438. #define MIN(a,b) (a <= b ? a : b)
  175439. void PNGAPI
  175440. png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
  175441. {
  175442. png_uint_32 check;
  175443. png_byte *near_data; /* Needs to be "png_byte *" instead of "png_bytep" */
  175444. png_FILE_p io_ptr;
  175445. if(png_ptr == NULL) return;
  175446. near_data = (png_byte *)CVT_PTR_NOCHECK(data);
  175447. io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr);
  175448. if ((png_bytep)near_data == data)
  175449. {
  175450. #if defined(_WIN32_WCE)
  175451. if ( !WriteFile(io_ptr, near_data, length, &check, NULL) )
  175452. check = 0;
  175453. #else
  175454. check = fwrite(near_data, 1, length, io_ptr);
  175455. #endif
  175456. }
  175457. else
  175458. {
  175459. png_byte buf[NEAR_BUF_SIZE];
  175460. png_size_t written, remaining, err;
  175461. check = 0;
  175462. remaining = length;
  175463. do
  175464. {
  175465. written = MIN(NEAR_BUF_SIZE, remaining);
  175466. png_memcpy(buf, data, written); /* copy far buffer to near buffer */
  175467. #if defined(_WIN32_WCE)
  175468. if ( !WriteFile(io_ptr, buf, written, &err, NULL) )
  175469. err = 0;
  175470. #else
  175471. err = fwrite(buf, 1, written, io_ptr);
  175472. #endif
  175473. if (err != written)
  175474. break;
  175475. else
  175476. check += err;
  175477. data += written;
  175478. remaining -= written;
  175479. }
  175480. while (remaining != 0);
  175481. }
  175482. if (check != length)
  175483. png_error(png_ptr, "Write Error");
  175484. }
  175485. #endif
  175486. #endif
  175487. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  175488. void /* PRIVATE */
  175489. png_flush(png_structp png_ptr)
  175490. {
  175491. if (png_ptr->output_flush_fn != NULL)
  175492. (*(png_ptr->output_flush_fn))(png_ptr);
  175493. }
  175494. #if !defined(PNG_NO_STDIO)
  175495. void PNGAPI
  175496. png_default_flush(png_structp png_ptr)
  175497. {
  175498. #if !defined(_WIN32_WCE)
  175499. png_FILE_p io_ptr;
  175500. #endif
  175501. if(png_ptr == NULL) return;
  175502. #if !defined(_WIN32_WCE)
  175503. io_ptr = (png_FILE_p)CVT_PTR((png_ptr->io_ptr));
  175504. if (io_ptr != NULL)
  175505. fflush(io_ptr);
  175506. #endif
  175507. }
  175508. #endif
  175509. #endif
  175510. void PNGAPI
  175511. png_set_write_fn(png_structp png_ptr, png_voidp io_ptr,
  175512. png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn)
  175513. {
  175514. if(png_ptr == NULL) return;
  175515. png_ptr->io_ptr = io_ptr;
  175516. #if !defined(PNG_NO_STDIO)
  175517. if (write_data_fn != NULL)
  175518. png_ptr->write_data_fn = write_data_fn;
  175519. else
  175520. png_ptr->write_data_fn = png_default_write_data;
  175521. #else
  175522. png_ptr->write_data_fn = write_data_fn;
  175523. #endif
  175524. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  175525. #if !defined(PNG_NO_STDIO)
  175526. if (output_flush_fn != NULL)
  175527. png_ptr->output_flush_fn = output_flush_fn;
  175528. else
  175529. png_ptr->output_flush_fn = png_default_flush;
  175530. #else
  175531. png_ptr->output_flush_fn = output_flush_fn;
  175532. #endif
  175533. #endif /* PNG_WRITE_FLUSH_SUPPORTED */
  175534. if (png_ptr->read_data_fn != NULL)
  175535. {
  175536. png_ptr->read_data_fn = NULL;
  175537. png_warning(png_ptr,
  175538. "Attempted to set both read_data_fn and write_data_fn in");
  175539. png_warning(png_ptr,
  175540. "the same structure. Resetting read_data_fn to NULL.");
  175541. }
  175542. }
  175543. #if defined(USE_FAR_KEYWORD)
  175544. #if defined(_MSC_VER)
  175545. void *png_far_to_near(png_structp png_ptr,png_voidp ptr, int check)
  175546. {
  175547. void *near_ptr;
  175548. void FAR *far_ptr;
  175549. FP_OFF(near_ptr) = FP_OFF(ptr);
  175550. far_ptr = (void FAR *)near_ptr;
  175551. if(check != 0)
  175552. if(FP_SEG(ptr) != FP_SEG(far_ptr))
  175553. png_error(png_ptr,"segment lost in conversion");
  175554. return(near_ptr);
  175555. }
  175556. # else
  175557. void *png_far_to_near(png_structp png_ptr,png_voidp ptr, int check)
  175558. {
  175559. void *near_ptr;
  175560. void FAR *far_ptr;
  175561. near_ptr = (void FAR *)ptr;
  175562. far_ptr = (void FAR *)near_ptr;
  175563. if(check != 0)
  175564. if(far_ptr != ptr)
  175565. png_error(png_ptr,"segment lost in conversion");
  175566. return(near_ptr);
  175567. }
  175568. # endif
  175569. # endif
  175570. #endif /* PNG_WRITE_SUPPORTED */
  175571. /*** End of inlined file: pngwio.c ***/
  175572. /*** Start of inlined file: pngwrite.c ***/
  175573. #define PNG_INTERNAL
  175574. #ifdef PNG_WRITE_SUPPORTED
  175575. void PNGAPI
  175576. png_write_info_before_PLTE(png_structp png_ptr, png_infop info_ptr)
  175577. {
  175578. png_debug(1, "in png_write_info_before_PLTE\n");
  175579. if (png_ptr == NULL || info_ptr == NULL)
  175580. return;
  175581. if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE))
  175582. {
  175583. png_write_sig(png_ptr); /* write PNG signature */
  175584. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  175585. if((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&(png_ptr->mng_features_permitted))
  175586. {
  175587. png_warning(png_ptr,"MNG features are not allowed in a PNG datastream");
  175588. png_ptr->mng_features_permitted=0;
  175589. }
  175590. #endif
  175591. png_write_IHDR(png_ptr, info_ptr->width, info_ptr->height,
  175592. info_ptr->bit_depth, info_ptr->color_type, info_ptr->compression_type,
  175593. info_ptr->filter_type,
  175594. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  175595. info_ptr->interlace_type);
  175596. #else
  175597. 0);
  175598. #endif
  175599. #if defined(PNG_WRITE_gAMA_SUPPORTED)
  175600. if (info_ptr->valid & PNG_INFO_gAMA)
  175601. {
  175602. # ifdef PNG_FLOATING_POINT_SUPPORTED
  175603. png_write_gAMA(png_ptr, info_ptr->gamma);
  175604. #else
  175605. #ifdef PNG_FIXED_POINT_SUPPORTED
  175606. png_write_gAMA_fixed(png_ptr, info_ptr->int_gamma);
  175607. # endif
  175608. #endif
  175609. }
  175610. #endif
  175611. #if defined(PNG_WRITE_sRGB_SUPPORTED)
  175612. if (info_ptr->valid & PNG_INFO_sRGB)
  175613. png_write_sRGB(png_ptr, (int)info_ptr->srgb_intent);
  175614. #endif
  175615. #if defined(PNG_WRITE_iCCP_SUPPORTED)
  175616. if (info_ptr->valid & PNG_INFO_iCCP)
  175617. png_write_iCCP(png_ptr, info_ptr->iccp_name, PNG_COMPRESSION_TYPE_BASE,
  175618. info_ptr->iccp_profile, (int)info_ptr->iccp_proflen);
  175619. #endif
  175620. #if defined(PNG_WRITE_sBIT_SUPPORTED)
  175621. if (info_ptr->valid & PNG_INFO_sBIT)
  175622. png_write_sBIT(png_ptr, &(info_ptr->sig_bit), info_ptr->color_type);
  175623. #endif
  175624. #if defined(PNG_WRITE_cHRM_SUPPORTED)
  175625. if (info_ptr->valid & PNG_INFO_cHRM)
  175626. {
  175627. #ifdef PNG_FLOATING_POINT_SUPPORTED
  175628. png_write_cHRM(png_ptr,
  175629. info_ptr->x_white, info_ptr->y_white,
  175630. info_ptr->x_red, info_ptr->y_red,
  175631. info_ptr->x_green, info_ptr->y_green,
  175632. info_ptr->x_blue, info_ptr->y_blue);
  175633. #else
  175634. # ifdef PNG_FIXED_POINT_SUPPORTED
  175635. png_write_cHRM_fixed(png_ptr,
  175636. info_ptr->int_x_white, info_ptr->int_y_white,
  175637. info_ptr->int_x_red, info_ptr->int_y_red,
  175638. info_ptr->int_x_green, info_ptr->int_y_green,
  175639. info_ptr->int_x_blue, info_ptr->int_y_blue);
  175640. # endif
  175641. #endif
  175642. }
  175643. #endif
  175644. #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
  175645. if (info_ptr->unknown_chunks_num)
  175646. {
  175647. png_unknown_chunk *up;
  175648. png_debug(5, "writing extra chunks\n");
  175649. for (up = info_ptr->unknown_chunks;
  175650. up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
  175651. up++)
  175652. {
  175653. int keep=png_handle_as_unknown(png_ptr, up->name);
  175654. if (keep != PNG_HANDLE_CHUNK_NEVER &&
  175655. up->location && !(up->location & PNG_HAVE_PLTE) &&
  175656. !(up->location & PNG_HAVE_IDAT) &&
  175657. ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
  175658. (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
  175659. {
  175660. png_write_chunk(png_ptr, up->name, up->data, up->size);
  175661. }
  175662. }
  175663. }
  175664. #endif
  175665. png_ptr->mode |= PNG_WROTE_INFO_BEFORE_PLTE;
  175666. }
  175667. }
  175668. void PNGAPI
  175669. png_write_info(png_structp png_ptr, png_infop info_ptr)
  175670. {
  175671. #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED)
  175672. int i;
  175673. #endif
  175674. png_debug(1, "in png_write_info\n");
  175675. if (png_ptr == NULL || info_ptr == NULL)
  175676. return;
  175677. png_write_info_before_PLTE(png_ptr, info_ptr);
  175678. if (info_ptr->valid & PNG_INFO_PLTE)
  175679. png_write_PLTE(png_ptr, info_ptr->palette,
  175680. (png_uint_32)info_ptr->num_palette);
  175681. else if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  175682. png_error(png_ptr, "Valid palette required for paletted images");
  175683. #if defined(PNG_WRITE_tRNS_SUPPORTED)
  175684. if (info_ptr->valid & PNG_INFO_tRNS)
  175685. {
  175686. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  175687. if ((png_ptr->transformations & PNG_INVERT_ALPHA) &&
  175688. info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  175689. {
  175690. int j;
  175691. for (j=0; j<(int)info_ptr->num_trans; j++)
  175692. info_ptr->trans[j] = (png_byte)(255 - info_ptr->trans[j]);
  175693. }
  175694. #endif
  175695. png_write_tRNS(png_ptr, info_ptr->trans, &(info_ptr->trans_values),
  175696. info_ptr->num_trans, info_ptr->color_type);
  175697. }
  175698. #endif
  175699. #if defined(PNG_WRITE_bKGD_SUPPORTED)
  175700. if (info_ptr->valid & PNG_INFO_bKGD)
  175701. png_write_bKGD(png_ptr, &(info_ptr->background), info_ptr->color_type);
  175702. #endif
  175703. #if defined(PNG_WRITE_hIST_SUPPORTED)
  175704. if (info_ptr->valid & PNG_INFO_hIST)
  175705. png_write_hIST(png_ptr, info_ptr->hist, info_ptr->num_palette);
  175706. #endif
  175707. #if defined(PNG_WRITE_oFFs_SUPPORTED)
  175708. if (info_ptr->valid & PNG_INFO_oFFs)
  175709. png_write_oFFs(png_ptr, info_ptr->x_offset, info_ptr->y_offset,
  175710. info_ptr->offset_unit_type);
  175711. #endif
  175712. #if defined(PNG_WRITE_pCAL_SUPPORTED)
  175713. if (info_ptr->valid & PNG_INFO_pCAL)
  175714. png_write_pCAL(png_ptr, info_ptr->pcal_purpose, info_ptr->pcal_X0,
  175715. info_ptr->pcal_X1, info_ptr->pcal_type, info_ptr->pcal_nparams,
  175716. info_ptr->pcal_units, info_ptr->pcal_params);
  175717. #endif
  175718. #if defined(PNG_WRITE_sCAL_SUPPORTED)
  175719. if (info_ptr->valid & PNG_INFO_sCAL)
  175720. #if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO)
  175721. png_write_sCAL(png_ptr, (int)info_ptr->scal_unit,
  175722. info_ptr->scal_pixel_width, info_ptr->scal_pixel_height);
  175723. #else
  175724. #ifdef PNG_FIXED_POINT_SUPPORTED
  175725. png_write_sCAL_s(png_ptr, (int)info_ptr->scal_unit,
  175726. info_ptr->scal_s_width, info_ptr->scal_s_height);
  175727. #else
  175728. png_warning(png_ptr,
  175729. "png_write_sCAL not supported; sCAL chunk not written.");
  175730. #endif
  175731. #endif
  175732. #endif
  175733. #if defined(PNG_WRITE_pHYs_SUPPORTED)
  175734. if (info_ptr->valid & PNG_INFO_pHYs)
  175735. png_write_pHYs(png_ptr, info_ptr->x_pixels_per_unit,
  175736. info_ptr->y_pixels_per_unit, info_ptr->phys_unit_type);
  175737. #endif
  175738. #if defined(PNG_WRITE_tIME_SUPPORTED)
  175739. if (info_ptr->valid & PNG_INFO_tIME)
  175740. {
  175741. png_write_tIME(png_ptr, &(info_ptr->mod_time));
  175742. png_ptr->mode |= PNG_WROTE_tIME;
  175743. }
  175744. #endif
  175745. #if defined(PNG_WRITE_sPLT_SUPPORTED)
  175746. if (info_ptr->valid & PNG_INFO_sPLT)
  175747. for (i = 0; i < (int)info_ptr->splt_palettes_num; i++)
  175748. png_write_sPLT(png_ptr, info_ptr->splt_palettes + i);
  175749. #endif
  175750. #if defined(PNG_WRITE_TEXT_SUPPORTED)
  175751. for (i = 0; i < info_ptr->num_text; i++)
  175752. {
  175753. png_debug2(2, "Writing header text chunk %d, type %d\n", i,
  175754. info_ptr->text[i].compression);
  175755. if (info_ptr->text[i].compression > 0)
  175756. {
  175757. #if defined(PNG_WRITE_iTXt_SUPPORTED)
  175758. png_write_iTXt(png_ptr,
  175759. info_ptr->text[i].compression,
  175760. info_ptr->text[i].key,
  175761. info_ptr->text[i].lang,
  175762. info_ptr->text[i].lang_key,
  175763. info_ptr->text[i].text);
  175764. #else
  175765. png_warning(png_ptr, "Unable to write international text");
  175766. #endif
  175767. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
  175768. }
  175769. else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_zTXt)
  175770. {
  175771. #if defined(PNG_WRITE_zTXt_SUPPORTED)
  175772. png_write_zTXt(png_ptr, info_ptr->text[i].key,
  175773. info_ptr->text[i].text, 0,
  175774. info_ptr->text[i].compression);
  175775. #else
  175776. png_warning(png_ptr, "Unable to write compressed text");
  175777. #endif
  175778. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR;
  175779. }
  175780. else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE)
  175781. {
  175782. #if defined(PNG_WRITE_tEXt_SUPPORTED)
  175783. png_write_tEXt(png_ptr, info_ptr->text[i].key,
  175784. info_ptr->text[i].text,
  175785. 0);
  175786. #else
  175787. png_warning(png_ptr, "Unable to write uncompressed text");
  175788. #endif
  175789. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
  175790. }
  175791. }
  175792. #endif
  175793. #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
  175794. if (info_ptr->unknown_chunks_num)
  175795. {
  175796. png_unknown_chunk *up;
  175797. png_debug(5, "writing extra chunks\n");
  175798. for (up = info_ptr->unknown_chunks;
  175799. up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
  175800. up++)
  175801. {
  175802. int keep=png_handle_as_unknown(png_ptr, up->name);
  175803. if (keep != PNG_HANDLE_CHUNK_NEVER &&
  175804. up->location && (up->location & PNG_HAVE_PLTE) &&
  175805. !(up->location & PNG_HAVE_IDAT) &&
  175806. ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
  175807. (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
  175808. {
  175809. png_write_chunk(png_ptr, up->name, up->data, up->size);
  175810. }
  175811. }
  175812. }
  175813. #endif
  175814. }
  175815. void PNGAPI
  175816. png_write_end(png_structp png_ptr, png_infop info_ptr)
  175817. {
  175818. png_debug(1, "in png_write_end\n");
  175819. if (png_ptr == NULL)
  175820. return;
  175821. if (!(png_ptr->mode & PNG_HAVE_IDAT))
  175822. png_error(png_ptr, "No IDATs written into file");
  175823. if (info_ptr != NULL)
  175824. {
  175825. #if defined(PNG_WRITE_TEXT_SUPPORTED)
  175826. int i; /* local index variable */
  175827. #endif
  175828. #if defined(PNG_WRITE_tIME_SUPPORTED)
  175829. if ((info_ptr->valid & PNG_INFO_tIME) &&
  175830. !(png_ptr->mode & PNG_WROTE_tIME))
  175831. png_write_tIME(png_ptr, &(info_ptr->mod_time));
  175832. #endif
  175833. #if defined(PNG_WRITE_TEXT_SUPPORTED)
  175834. for (i = 0; i < info_ptr->num_text; i++)
  175835. {
  175836. png_debug2(2, "Writing trailer text chunk %d, type %d\n", i,
  175837. info_ptr->text[i].compression);
  175838. if (info_ptr->text[i].compression > 0)
  175839. {
  175840. #if defined(PNG_WRITE_iTXt_SUPPORTED)
  175841. png_write_iTXt(png_ptr,
  175842. info_ptr->text[i].compression,
  175843. info_ptr->text[i].key,
  175844. info_ptr->text[i].lang,
  175845. info_ptr->text[i].lang_key,
  175846. info_ptr->text[i].text);
  175847. #else
  175848. png_warning(png_ptr, "Unable to write international text");
  175849. #endif
  175850. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
  175851. }
  175852. else if (info_ptr->text[i].compression >= PNG_TEXT_COMPRESSION_zTXt)
  175853. {
  175854. #if defined(PNG_WRITE_zTXt_SUPPORTED)
  175855. png_write_zTXt(png_ptr, info_ptr->text[i].key,
  175856. info_ptr->text[i].text, 0,
  175857. info_ptr->text[i].compression);
  175858. #else
  175859. png_warning(png_ptr, "Unable to write compressed text");
  175860. #endif
  175861. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR;
  175862. }
  175863. else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE)
  175864. {
  175865. #if defined(PNG_WRITE_tEXt_SUPPORTED)
  175866. png_write_tEXt(png_ptr, info_ptr->text[i].key,
  175867. info_ptr->text[i].text, 0);
  175868. #else
  175869. png_warning(png_ptr, "Unable to write uncompressed text");
  175870. #endif
  175871. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
  175872. }
  175873. }
  175874. #endif
  175875. #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
  175876. if (info_ptr->unknown_chunks_num)
  175877. {
  175878. png_unknown_chunk *up;
  175879. png_debug(5, "writing extra chunks\n");
  175880. for (up = info_ptr->unknown_chunks;
  175881. up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
  175882. up++)
  175883. {
  175884. int keep=png_handle_as_unknown(png_ptr, up->name);
  175885. if (keep != PNG_HANDLE_CHUNK_NEVER &&
  175886. up->location && (up->location & PNG_AFTER_IDAT) &&
  175887. ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
  175888. (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
  175889. {
  175890. png_write_chunk(png_ptr, up->name, up->data, up->size);
  175891. }
  175892. }
  175893. }
  175894. #endif
  175895. }
  175896. png_ptr->mode |= PNG_AFTER_IDAT;
  175897. png_write_IEND(png_ptr);
  175898. }
  175899. #if defined(PNG_WRITE_tIME_SUPPORTED)
  175900. #if !defined(_WIN32_WCE)
  175901. void PNGAPI
  175902. png_convert_from_struct_tm(png_timep ptime, struct tm FAR * ttime)
  175903. {
  175904. png_debug(1, "in png_convert_from_struct_tm\n");
  175905. ptime->year = (png_uint_16)(1900 + ttime->tm_year);
  175906. ptime->month = (png_byte)(ttime->tm_mon + 1);
  175907. ptime->day = (png_byte)ttime->tm_mday;
  175908. ptime->hour = (png_byte)ttime->tm_hour;
  175909. ptime->minute = (png_byte)ttime->tm_min;
  175910. ptime->second = (png_byte)ttime->tm_sec;
  175911. }
  175912. void PNGAPI
  175913. png_convert_from_time_t(png_timep ptime, time_t ttime)
  175914. {
  175915. struct tm *tbuf;
  175916. png_debug(1, "in png_convert_from_time_t\n");
  175917. tbuf = gmtime(&ttime);
  175918. png_convert_from_struct_tm(ptime, tbuf);
  175919. }
  175920. #endif
  175921. #endif
  175922. png_structp PNGAPI
  175923. png_create_write_struct(png_const_charp user_png_ver, png_voidp error_ptr,
  175924. png_error_ptr error_fn, png_error_ptr warn_fn)
  175925. {
  175926. #ifdef PNG_USER_MEM_SUPPORTED
  175927. return (png_create_write_struct_2(user_png_ver, error_ptr, error_fn,
  175928. warn_fn, png_voidp_NULL, png_malloc_ptr_NULL, png_free_ptr_NULL));
  175929. }
  175930. png_structp PNGAPI
  175931. png_create_write_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
  175932. png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  175933. png_malloc_ptr malloc_fn, png_free_ptr free_fn)
  175934. {
  175935. #endif /* PNG_USER_MEM_SUPPORTED */
  175936. png_structp png_ptr;
  175937. #ifdef PNG_SETJMP_SUPPORTED
  175938. #ifdef USE_FAR_KEYWORD
  175939. jmp_buf jmpbuf;
  175940. #endif
  175941. #endif
  175942. int i;
  175943. png_debug(1, "in png_create_write_struct\n");
  175944. #ifdef PNG_USER_MEM_SUPPORTED
  175945. png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG,
  175946. (png_malloc_ptr)malloc_fn, (png_voidp)mem_ptr);
  175947. #else
  175948. png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
  175949. #endif /* PNG_USER_MEM_SUPPORTED */
  175950. if (png_ptr == NULL)
  175951. return (NULL);
  175952. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  175953. png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
  175954. png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
  175955. #endif
  175956. #ifdef PNG_SETJMP_SUPPORTED
  175957. #ifdef USE_FAR_KEYWORD
  175958. if (setjmp(jmpbuf))
  175959. #else
  175960. if (setjmp(png_ptr->jmpbuf))
  175961. #endif
  175962. {
  175963. png_free(png_ptr, png_ptr->zbuf);
  175964. png_ptr->zbuf=NULL;
  175965. png_destroy_struct(png_ptr);
  175966. return (NULL);
  175967. }
  175968. #ifdef USE_FAR_KEYWORD
  175969. png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
  175970. #endif
  175971. #endif
  175972. #ifdef PNG_USER_MEM_SUPPORTED
  175973. png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn);
  175974. #endif /* PNG_USER_MEM_SUPPORTED */
  175975. png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn);
  175976. i=0;
  175977. do
  175978. {
  175979. if(user_png_ver[i] != png_libpng_ver[i])
  175980. png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
  175981. } while (png_libpng_ver[i++]);
  175982. if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH)
  175983. {
  175984. if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] ||
  175985. (user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) ||
  175986. (user_png_ver[0] == '0' && user_png_ver[2] < '9'))
  175987. {
  175988. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  175989. char msg[80];
  175990. if (user_png_ver)
  175991. {
  175992. png_snprintf(msg, 80,
  175993. "Application was compiled with png.h from libpng-%.20s",
  175994. user_png_ver);
  175995. png_warning(png_ptr, msg);
  175996. }
  175997. png_snprintf(msg, 80,
  175998. "Application is running with png.c from libpng-%.20s",
  175999. png_libpng_ver);
  176000. png_warning(png_ptr, msg);
  176001. #endif
  176002. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  176003. png_ptr->flags=0;
  176004. #endif
  176005. png_error(png_ptr,
  176006. "Incompatible libpng version in application and library");
  176007. }
  176008. }
  176009. png_ptr->zbuf_size = PNG_ZBUF_SIZE;
  176010. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
  176011. (png_uint_32)png_ptr->zbuf_size);
  176012. png_set_write_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL,
  176013. png_flush_ptr_NULL);
  176014. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  176015. png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT,
  176016. 1, png_doublep_NULL, png_doublep_NULL);
  176017. #endif
  176018. #ifdef PNG_SETJMP_SUPPORTED
  176019. #ifdef USE_FAR_KEYWORD
  176020. if (setjmp(jmpbuf))
  176021. PNG_ABORT();
  176022. png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
  176023. #else
  176024. if (setjmp(png_ptr->jmpbuf))
  176025. PNG_ABORT();
  176026. #endif
  176027. #endif
  176028. return (png_ptr);
  176029. }
  176030. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  176031. #undef png_write_init
  176032. void PNGAPI
  176033. png_write_init(png_structp png_ptr)
  176034. {
  176035. png_write_init_2(png_ptr, "1.0.6 or earlier", 0, 0);
  176036. }
  176037. void PNGAPI
  176038. png_write_init_2(png_structp png_ptr, png_const_charp user_png_ver,
  176039. png_size_t png_struct_size, png_size_t png_info_size)
  176040. {
  176041. if(png_ptr == NULL) return;
  176042. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  176043. if(png_sizeof(png_struct) > png_struct_size ||
  176044. png_sizeof(png_info) > png_info_size)
  176045. {
  176046. char msg[80];
  176047. png_ptr->warning_fn=NULL;
  176048. if (user_png_ver)
  176049. {
  176050. png_snprintf(msg, 80,
  176051. "Application was compiled with png.h from libpng-%.20s",
  176052. user_png_ver);
  176053. png_warning(png_ptr, msg);
  176054. }
  176055. png_snprintf(msg, 80,
  176056. "Application is running with png.c from libpng-%.20s",
  176057. png_libpng_ver);
  176058. png_warning(png_ptr, msg);
  176059. }
  176060. #endif
  176061. if(png_sizeof(png_struct) > png_struct_size)
  176062. {
  176063. png_ptr->error_fn=NULL;
  176064. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  176065. png_ptr->flags=0;
  176066. #endif
  176067. png_error(png_ptr,
  176068. "The png struct allocated by the application for writing is too small.");
  176069. }
  176070. if(png_sizeof(png_info) > png_info_size)
  176071. {
  176072. png_ptr->error_fn=NULL;
  176073. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  176074. png_ptr->flags=0;
  176075. #endif
  176076. png_error(png_ptr,
  176077. "The info struct allocated by the application for writing is too small.");
  176078. }
  176079. png_write_init_3(&png_ptr, user_png_ver, png_struct_size);
  176080. }
  176081. #endif /* PNG_1_0_X || PNG_1_2_X */
  176082. void PNGAPI
  176083. png_write_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver,
  176084. png_size_t png_struct_size)
  176085. {
  176086. png_structp png_ptr=*ptr_ptr;
  176087. #ifdef PNG_SETJMP_SUPPORTED
  176088. jmp_buf tmp_jmp; /* to save current jump buffer */
  176089. #endif
  176090. int i = 0;
  176091. if (png_ptr == NULL)
  176092. return;
  176093. do
  176094. {
  176095. if (user_png_ver[i] != png_libpng_ver[i])
  176096. {
  176097. #ifdef PNG_LEGACY_SUPPORTED
  176098. png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
  176099. #else
  176100. png_ptr->warning_fn=NULL;
  176101. png_warning(png_ptr,
  176102. "Application uses deprecated png_write_init() and should be recompiled.");
  176103. break;
  176104. #endif
  176105. }
  176106. } while (png_libpng_ver[i++]);
  176107. png_debug(1, "in png_write_init_3\n");
  176108. #ifdef PNG_SETJMP_SUPPORTED
  176109. png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
  176110. #endif
  176111. if (png_sizeof(png_struct) > png_struct_size)
  176112. {
  176113. png_destroy_struct(png_ptr);
  176114. png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
  176115. *ptr_ptr = png_ptr;
  176116. }
  176117. png_memset(png_ptr, 0, png_sizeof (png_struct));
  176118. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  176119. png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
  176120. png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
  176121. #endif
  176122. #ifdef PNG_SETJMP_SUPPORTED
  176123. png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
  176124. #endif
  176125. png_set_write_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL,
  176126. png_flush_ptr_NULL);
  176127. png_ptr->zbuf_size = PNG_ZBUF_SIZE;
  176128. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
  176129. (png_uint_32)png_ptr->zbuf_size);
  176130. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  176131. png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT,
  176132. 1, png_doublep_NULL, png_doublep_NULL);
  176133. #endif
  176134. }
  176135. void PNGAPI
  176136. png_write_rows(png_structp png_ptr, png_bytepp row,
  176137. png_uint_32 num_rows)
  176138. {
  176139. png_uint_32 i; /* row counter */
  176140. png_bytepp rp; /* row pointer */
  176141. png_debug(1, "in png_write_rows\n");
  176142. if (png_ptr == NULL)
  176143. return;
  176144. for (i = 0, rp = row; i < num_rows; i++, rp++)
  176145. {
  176146. png_write_row(png_ptr, *rp);
  176147. }
  176148. }
  176149. void PNGAPI
  176150. png_write_image(png_structp png_ptr, png_bytepp image)
  176151. {
  176152. png_uint_32 i; /* row index */
  176153. int pass, num_pass; /* pass variables */
  176154. png_bytepp rp; /* points to current row */
  176155. if (png_ptr == NULL)
  176156. return;
  176157. png_debug(1, "in png_write_image\n");
  176158. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  176159. num_pass = png_set_interlace_handling(png_ptr);
  176160. #else
  176161. num_pass = 1;
  176162. #endif
  176163. for (pass = 0; pass < num_pass; pass++)
  176164. {
  176165. for (i = 0, rp = image; i < png_ptr->height; i++, rp++)
  176166. {
  176167. png_write_row(png_ptr, *rp);
  176168. }
  176169. }
  176170. }
  176171. void PNGAPI
  176172. png_write_row(png_structp png_ptr, png_bytep row)
  176173. {
  176174. if (png_ptr == NULL)
  176175. return;
  176176. png_debug2(1, "in png_write_row (row %ld, pass %d)\n",
  176177. png_ptr->row_number, png_ptr->pass);
  176178. if (png_ptr->row_number == 0 && png_ptr->pass == 0)
  176179. {
  176180. if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE))
  176181. png_error(png_ptr,
  176182. "png_write_info was never called before png_write_row.");
  176183. #if !defined(PNG_WRITE_INVERT_SUPPORTED) && defined(PNG_READ_INVERT_SUPPORTED)
  176184. if (png_ptr->transformations & PNG_INVERT_MONO)
  176185. png_warning(png_ptr, "PNG_WRITE_INVERT_SUPPORTED is not defined.");
  176186. #endif
  176187. #if !defined(PNG_WRITE_FILLER_SUPPORTED) && defined(PNG_READ_FILLER_SUPPORTED)
  176188. if (png_ptr->transformations & PNG_FILLER)
  176189. png_warning(png_ptr, "PNG_WRITE_FILLER_SUPPORTED is not defined.");
  176190. #endif
  176191. #if !defined(PNG_WRITE_PACKSWAP_SUPPORTED) && defined(PNG_READ_PACKSWAP_SUPPORTED)
  176192. if (png_ptr->transformations & PNG_PACKSWAP)
  176193. png_warning(png_ptr, "PNG_WRITE_PACKSWAP_SUPPORTED is not defined.");
  176194. #endif
  176195. #if !defined(PNG_WRITE_PACK_SUPPORTED) && defined(PNG_READ_PACK_SUPPORTED)
  176196. if (png_ptr->transformations & PNG_PACK)
  176197. png_warning(png_ptr, "PNG_WRITE_PACK_SUPPORTED is not defined.");
  176198. #endif
  176199. #if !defined(PNG_WRITE_SHIFT_SUPPORTED) && defined(PNG_READ_SHIFT_SUPPORTED)
  176200. if (png_ptr->transformations & PNG_SHIFT)
  176201. png_warning(png_ptr, "PNG_WRITE_SHIFT_SUPPORTED is not defined.");
  176202. #endif
  176203. #if !defined(PNG_WRITE_BGR_SUPPORTED) && defined(PNG_READ_BGR_SUPPORTED)
  176204. if (png_ptr->transformations & PNG_BGR)
  176205. png_warning(png_ptr, "PNG_WRITE_BGR_SUPPORTED is not defined.");
  176206. #endif
  176207. #if !defined(PNG_WRITE_SWAP_SUPPORTED) && defined(PNG_READ_SWAP_SUPPORTED)
  176208. if (png_ptr->transformations & PNG_SWAP_BYTES)
  176209. png_warning(png_ptr, "PNG_WRITE_SWAP_SUPPORTED is not defined.");
  176210. #endif
  176211. png_write_start_row(png_ptr);
  176212. }
  176213. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  176214. if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
  176215. {
  176216. switch (png_ptr->pass)
  176217. {
  176218. case 0:
  176219. if (png_ptr->row_number & 0x07)
  176220. {
  176221. png_write_finish_row(png_ptr);
  176222. return;
  176223. }
  176224. break;
  176225. case 1:
  176226. if ((png_ptr->row_number & 0x07) || png_ptr->width < 5)
  176227. {
  176228. png_write_finish_row(png_ptr);
  176229. return;
  176230. }
  176231. break;
  176232. case 2:
  176233. if ((png_ptr->row_number & 0x07) != 4)
  176234. {
  176235. png_write_finish_row(png_ptr);
  176236. return;
  176237. }
  176238. break;
  176239. case 3:
  176240. if ((png_ptr->row_number & 0x03) || png_ptr->width < 3)
  176241. {
  176242. png_write_finish_row(png_ptr);
  176243. return;
  176244. }
  176245. break;
  176246. case 4:
  176247. if ((png_ptr->row_number & 0x03) != 2)
  176248. {
  176249. png_write_finish_row(png_ptr);
  176250. return;
  176251. }
  176252. break;
  176253. case 5:
  176254. if ((png_ptr->row_number & 0x01) || png_ptr->width < 2)
  176255. {
  176256. png_write_finish_row(png_ptr);
  176257. return;
  176258. }
  176259. break;
  176260. case 6:
  176261. if (!(png_ptr->row_number & 0x01))
  176262. {
  176263. png_write_finish_row(png_ptr);
  176264. return;
  176265. }
  176266. break;
  176267. }
  176268. }
  176269. #endif
  176270. png_ptr->row_info.color_type = png_ptr->color_type;
  176271. png_ptr->row_info.width = png_ptr->usr_width;
  176272. png_ptr->row_info.channels = png_ptr->usr_channels;
  176273. png_ptr->row_info.bit_depth = png_ptr->usr_bit_depth;
  176274. png_ptr->row_info.pixel_depth = (png_byte)(png_ptr->row_info.bit_depth *
  176275. png_ptr->row_info.channels);
  176276. png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
  176277. png_ptr->row_info.width);
  176278. png_debug1(3, "row_info->color_type = %d\n", png_ptr->row_info.color_type);
  176279. png_debug1(3, "row_info->width = %lu\n", png_ptr->row_info.width);
  176280. png_debug1(3, "row_info->channels = %d\n", png_ptr->row_info.channels);
  176281. png_debug1(3, "row_info->bit_depth = %d\n", png_ptr->row_info.bit_depth);
  176282. png_debug1(3, "row_info->pixel_depth = %d\n", png_ptr->row_info.pixel_depth);
  176283. png_debug1(3, "row_info->rowbytes = %lu\n", png_ptr->row_info.rowbytes);
  176284. png_memcpy_check(png_ptr, png_ptr->row_buf + 1, row,
  176285. png_ptr->row_info.rowbytes);
  176286. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  176287. if (png_ptr->interlaced && png_ptr->pass < 6 &&
  176288. (png_ptr->transformations & PNG_INTERLACE))
  176289. {
  176290. png_do_write_interlace(&(png_ptr->row_info),
  176291. png_ptr->row_buf + 1, png_ptr->pass);
  176292. if (!(png_ptr->row_info.width))
  176293. {
  176294. png_write_finish_row(png_ptr);
  176295. return;
  176296. }
  176297. }
  176298. #endif
  176299. if (png_ptr->transformations)
  176300. png_do_write_transformations(png_ptr);
  176301. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  176302. if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  176303. (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING))
  176304. {
  176305. png_do_write_intrapixel(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176306. }
  176307. #endif
  176308. png_write_find_filter(png_ptr, &(png_ptr->row_info));
  176309. if (png_ptr->write_row_fn != NULL)
  176310. (*(png_ptr->write_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass);
  176311. }
  176312. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  176313. void PNGAPI
  176314. png_set_flush(png_structp png_ptr, int nrows)
  176315. {
  176316. png_debug(1, "in png_set_flush\n");
  176317. if (png_ptr == NULL)
  176318. return;
  176319. png_ptr->flush_dist = (nrows < 0 ? 0 : nrows);
  176320. }
  176321. void PNGAPI
  176322. png_write_flush(png_structp png_ptr)
  176323. {
  176324. int wrote_IDAT;
  176325. png_debug(1, "in png_write_flush\n");
  176326. if (png_ptr == NULL)
  176327. return;
  176328. if (png_ptr->row_number >= png_ptr->num_rows)
  176329. return;
  176330. do
  176331. {
  176332. int ret;
  176333. ret = deflate(&png_ptr->zstream, Z_SYNC_FLUSH);
  176334. wrote_IDAT = 0;
  176335. if (ret != Z_OK)
  176336. {
  176337. if (png_ptr->zstream.msg != NULL)
  176338. png_error(png_ptr, png_ptr->zstream.msg);
  176339. else
  176340. png_error(png_ptr, "zlib error");
  176341. }
  176342. if (!(png_ptr->zstream.avail_out))
  176343. {
  176344. png_write_IDAT(png_ptr, png_ptr->zbuf,
  176345. png_ptr->zbuf_size);
  176346. png_ptr->zstream.next_out = png_ptr->zbuf;
  176347. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  176348. wrote_IDAT = 1;
  176349. }
  176350. } while(wrote_IDAT == 1);
  176351. if (png_ptr->zbuf_size != png_ptr->zstream.avail_out)
  176352. {
  176353. png_write_IDAT(png_ptr, png_ptr->zbuf,
  176354. png_ptr->zbuf_size - png_ptr->zstream.avail_out);
  176355. png_ptr->zstream.next_out = png_ptr->zbuf;
  176356. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  176357. }
  176358. png_ptr->flush_rows = 0;
  176359. png_flush(png_ptr);
  176360. }
  176361. #endif /* PNG_WRITE_FLUSH_SUPPORTED */
  176362. void PNGAPI
  176363. png_destroy_write_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr)
  176364. {
  176365. png_structp png_ptr = NULL;
  176366. png_infop info_ptr = NULL;
  176367. #ifdef PNG_USER_MEM_SUPPORTED
  176368. png_free_ptr free_fn = NULL;
  176369. png_voidp mem_ptr = NULL;
  176370. #endif
  176371. png_debug(1, "in png_destroy_write_struct\n");
  176372. if (png_ptr_ptr != NULL)
  176373. {
  176374. png_ptr = *png_ptr_ptr;
  176375. #ifdef PNG_USER_MEM_SUPPORTED
  176376. free_fn = png_ptr->free_fn;
  176377. mem_ptr = png_ptr->mem_ptr;
  176378. #endif
  176379. }
  176380. if (info_ptr_ptr != NULL)
  176381. info_ptr = *info_ptr_ptr;
  176382. if (info_ptr != NULL)
  176383. {
  176384. png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
  176385. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  176386. if (png_ptr->num_chunk_list)
  176387. {
  176388. png_free(png_ptr, png_ptr->chunk_list);
  176389. png_ptr->chunk_list=NULL;
  176390. png_ptr->num_chunk_list=0;
  176391. }
  176392. #endif
  176393. #ifdef PNG_USER_MEM_SUPPORTED
  176394. png_destroy_struct_2((png_voidp)info_ptr, (png_free_ptr)free_fn,
  176395. (png_voidp)mem_ptr);
  176396. #else
  176397. png_destroy_struct((png_voidp)info_ptr);
  176398. #endif
  176399. *info_ptr_ptr = NULL;
  176400. }
  176401. if (png_ptr != NULL)
  176402. {
  176403. png_write_destroy(png_ptr);
  176404. #ifdef PNG_USER_MEM_SUPPORTED
  176405. png_destroy_struct_2((png_voidp)png_ptr, (png_free_ptr)free_fn,
  176406. (png_voidp)mem_ptr);
  176407. #else
  176408. png_destroy_struct((png_voidp)png_ptr);
  176409. #endif
  176410. *png_ptr_ptr = NULL;
  176411. }
  176412. }
  176413. void /* PRIVATE */
  176414. png_write_destroy(png_structp png_ptr)
  176415. {
  176416. #ifdef PNG_SETJMP_SUPPORTED
  176417. jmp_buf tmp_jmp; /* save jump buffer */
  176418. #endif
  176419. png_error_ptr error_fn;
  176420. png_error_ptr warning_fn;
  176421. png_voidp error_ptr;
  176422. #ifdef PNG_USER_MEM_SUPPORTED
  176423. png_free_ptr free_fn;
  176424. #endif
  176425. png_debug(1, "in png_write_destroy\n");
  176426. deflateEnd(&png_ptr->zstream);
  176427. png_free(png_ptr, png_ptr->zbuf);
  176428. png_free(png_ptr, png_ptr->row_buf);
  176429. png_free(png_ptr, png_ptr->prev_row);
  176430. png_free(png_ptr, png_ptr->sub_row);
  176431. png_free(png_ptr, png_ptr->up_row);
  176432. png_free(png_ptr, png_ptr->avg_row);
  176433. png_free(png_ptr, png_ptr->paeth_row);
  176434. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  176435. png_free(png_ptr, png_ptr->time_buffer);
  176436. #endif
  176437. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  176438. png_free(png_ptr, png_ptr->prev_filters);
  176439. png_free(png_ptr, png_ptr->filter_weights);
  176440. png_free(png_ptr, png_ptr->inv_filter_weights);
  176441. png_free(png_ptr, png_ptr->filter_costs);
  176442. png_free(png_ptr, png_ptr->inv_filter_costs);
  176443. #endif
  176444. #ifdef PNG_SETJMP_SUPPORTED
  176445. png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
  176446. #endif
  176447. error_fn = png_ptr->error_fn;
  176448. warning_fn = png_ptr->warning_fn;
  176449. error_ptr = png_ptr->error_ptr;
  176450. #ifdef PNG_USER_MEM_SUPPORTED
  176451. free_fn = png_ptr->free_fn;
  176452. #endif
  176453. png_memset(png_ptr, 0, png_sizeof (png_struct));
  176454. png_ptr->error_fn = error_fn;
  176455. png_ptr->warning_fn = warning_fn;
  176456. png_ptr->error_ptr = error_ptr;
  176457. #ifdef PNG_USER_MEM_SUPPORTED
  176458. png_ptr->free_fn = free_fn;
  176459. #endif
  176460. #ifdef PNG_SETJMP_SUPPORTED
  176461. png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
  176462. #endif
  176463. }
  176464. void PNGAPI
  176465. png_set_filter(png_structp png_ptr, int method, int filters)
  176466. {
  176467. png_debug(1, "in png_set_filter\n");
  176468. if (png_ptr == NULL)
  176469. return;
  176470. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  176471. if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  176472. (method == PNG_INTRAPIXEL_DIFFERENCING))
  176473. method = PNG_FILTER_TYPE_BASE;
  176474. #endif
  176475. if (method == PNG_FILTER_TYPE_BASE)
  176476. {
  176477. switch (filters & (PNG_ALL_FILTERS | 0x07))
  176478. {
  176479. #ifndef PNG_NO_WRITE_FILTER
  176480. case 5:
  176481. case 6:
  176482. case 7: png_warning(png_ptr, "Unknown row filter for method 0");
  176483. #endif /* PNG_NO_WRITE_FILTER */
  176484. case PNG_FILTER_VALUE_NONE:
  176485. png_ptr->do_filter=PNG_FILTER_NONE; break;
  176486. #ifndef PNG_NO_WRITE_FILTER
  176487. case PNG_FILTER_VALUE_SUB:
  176488. png_ptr->do_filter=PNG_FILTER_SUB; break;
  176489. case PNG_FILTER_VALUE_UP:
  176490. png_ptr->do_filter=PNG_FILTER_UP; break;
  176491. case PNG_FILTER_VALUE_AVG:
  176492. png_ptr->do_filter=PNG_FILTER_AVG; break;
  176493. case PNG_FILTER_VALUE_PAETH:
  176494. png_ptr->do_filter=PNG_FILTER_PAETH; break;
  176495. default: png_ptr->do_filter = (png_byte)filters; break;
  176496. #else
  176497. default: png_warning(png_ptr, "Unknown row filter for method 0");
  176498. #endif /* PNG_NO_WRITE_FILTER */
  176499. }
  176500. if (png_ptr->row_buf != NULL)
  176501. {
  176502. #ifndef PNG_NO_WRITE_FILTER
  176503. if ((png_ptr->do_filter & PNG_FILTER_SUB) && png_ptr->sub_row == NULL)
  176504. {
  176505. png_ptr->sub_row = (png_bytep)png_malloc(png_ptr,
  176506. (png_ptr->rowbytes + 1));
  176507. png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB;
  176508. }
  176509. if ((png_ptr->do_filter & PNG_FILTER_UP) && png_ptr->up_row == NULL)
  176510. {
  176511. if (png_ptr->prev_row == NULL)
  176512. {
  176513. png_warning(png_ptr, "Can't add Up filter after starting");
  176514. png_ptr->do_filter &= ~PNG_FILTER_UP;
  176515. }
  176516. else
  176517. {
  176518. png_ptr->up_row = (png_bytep)png_malloc(png_ptr,
  176519. (png_ptr->rowbytes + 1));
  176520. png_ptr->up_row[0] = PNG_FILTER_VALUE_UP;
  176521. }
  176522. }
  176523. if ((png_ptr->do_filter & PNG_FILTER_AVG) && png_ptr->avg_row == NULL)
  176524. {
  176525. if (png_ptr->prev_row == NULL)
  176526. {
  176527. png_warning(png_ptr, "Can't add Average filter after starting");
  176528. png_ptr->do_filter &= ~PNG_FILTER_AVG;
  176529. }
  176530. else
  176531. {
  176532. png_ptr->avg_row = (png_bytep)png_malloc(png_ptr,
  176533. (png_ptr->rowbytes + 1));
  176534. png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG;
  176535. }
  176536. }
  176537. if ((png_ptr->do_filter & PNG_FILTER_PAETH) &&
  176538. png_ptr->paeth_row == NULL)
  176539. {
  176540. if (png_ptr->prev_row == NULL)
  176541. {
  176542. png_warning(png_ptr, "Can't add Paeth filter after starting");
  176543. png_ptr->do_filter &= (png_byte)(~PNG_FILTER_PAETH);
  176544. }
  176545. else
  176546. {
  176547. png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr,
  176548. (png_ptr->rowbytes + 1));
  176549. png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH;
  176550. }
  176551. }
  176552. if (png_ptr->do_filter == PNG_NO_FILTERS)
  176553. #endif /* PNG_NO_WRITE_FILTER */
  176554. png_ptr->do_filter = PNG_FILTER_NONE;
  176555. }
  176556. }
  176557. else
  176558. png_error(png_ptr, "Unknown custom filter method");
  176559. }
  176560. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) /* GRR 970116 */
  176561. void PNGAPI
  176562. png_set_filter_heuristics(png_structp png_ptr, int heuristic_method,
  176563. int num_weights, png_doublep filter_weights,
  176564. png_doublep filter_costs)
  176565. {
  176566. int i;
  176567. png_debug(1, "in png_set_filter_heuristics\n");
  176568. if (png_ptr == NULL)
  176569. return;
  176570. if (heuristic_method >= PNG_FILTER_HEURISTIC_LAST)
  176571. {
  176572. png_warning(png_ptr, "Unknown filter heuristic method");
  176573. return;
  176574. }
  176575. if (heuristic_method == PNG_FILTER_HEURISTIC_DEFAULT)
  176576. {
  176577. heuristic_method = PNG_FILTER_HEURISTIC_UNWEIGHTED;
  176578. }
  176579. if (num_weights < 0 || filter_weights == NULL ||
  176580. heuristic_method == PNG_FILTER_HEURISTIC_UNWEIGHTED)
  176581. {
  176582. num_weights = 0;
  176583. }
  176584. png_ptr->num_prev_filters = (png_byte)num_weights;
  176585. png_ptr->heuristic_method = (png_byte)heuristic_method;
  176586. if (num_weights > 0)
  176587. {
  176588. if (png_ptr->prev_filters == NULL)
  176589. {
  176590. png_ptr->prev_filters = (png_bytep)png_malloc(png_ptr,
  176591. (png_uint_32)(png_sizeof(png_byte) * num_weights));
  176592. for (i = 0; i < num_weights; i++)
  176593. {
  176594. png_ptr->prev_filters[i] = 255;
  176595. }
  176596. }
  176597. if (png_ptr->filter_weights == NULL)
  176598. {
  176599. png_ptr->filter_weights = (png_uint_16p)png_malloc(png_ptr,
  176600. (png_uint_32)(png_sizeof(png_uint_16) * num_weights));
  176601. png_ptr->inv_filter_weights = (png_uint_16p)png_malloc(png_ptr,
  176602. (png_uint_32)(png_sizeof(png_uint_16) * num_weights));
  176603. for (i = 0; i < num_weights; i++)
  176604. {
  176605. png_ptr->inv_filter_weights[i] =
  176606. png_ptr->filter_weights[i] = PNG_WEIGHT_FACTOR;
  176607. }
  176608. }
  176609. for (i = 0; i < num_weights; i++)
  176610. {
  176611. if (filter_weights[i] < 0.0)
  176612. {
  176613. png_ptr->inv_filter_weights[i] =
  176614. png_ptr->filter_weights[i] = PNG_WEIGHT_FACTOR;
  176615. }
  176616. else
  176617. {
  176618. png_ptr->inv_filter_weights[i] =
  176619. (png_uint_16)((double)PNG_WEIGHT_FACTOR*filter_weights[i]+0.5);
  176620. png_ptr->filter_weights[i] =
  176621. (png_uint_16)((double)PNG_WEIGHT_FACTOR/filter_weights[i]+0.5);
  176622. }
  176623. }
  176624. }
  176625. if (png_ptr->filter_costs == NULL)
  176626. {
  176627. png_ptr->filter_costs = (png_uint_16p)png_malloc(png_ptr,
  176628. (png_uint_32)(png_sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST));
  176629. png_ptr->inv_filter_costs = (png_uint_16p)png_malloc(png_ptr,
  176630. (png_uint_32)(png_sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST));
  176631. for (i = 0; i < PNG_FILTER_VALUE_LAST; i++)
  176632. {
  176633. png_ptr->inv_filter_costs[i] =
  176634. png_ptr->filter_costs[i] = PNG_COST_FACTOR;
  176635. }
  176636. }
  176637. for (i = 0; i < PNG_FILTER_VALUE_LAST; i++)
  176638. {
  176639. if (filter_costs == NULL || filter_costs[i] < 0.0)
  176640. {
  176641. png_ptr->inv_filter_costs[i] =
  176642. png_ptr->filter_costs[i] = PNG_COST_FACTOR;
  176643. }
  176644. else if (filter_costs[i] >= 1.0)
  176645. {
  176646. png_ptr->inv_filter_costs[i] =
  176647. (png_uint_16)((double)PNG_COST_FACTOR / filter_costs[i] + 0.5);
  176648. png_ptr->filter_costs[i] =
  176649. (png_uint_16)((double)PNG_COST_FACTOR * filter_costs[i] + 0.5);
  176650. }
  176651. }
  176652. }
  176653. #endif /* PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */
  176654. void PNGAPI
  176655. png_set_compression_level(png_structp png_ptr, int level)
  176656. {
  176657. png_debug(1, "in png_set_compression_level\n");
  176658. if (png_ptr == NULL)
  176659. return;
  176660. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_LEVEL;
  176661. png_ptr->zlib_level = level;
  176662. }
  176663. void PNGAPI
  176664. png_set_compression_mem_level(png_structp png_ptr, int mem_level)
  176665. {
  176666. png_debug(1, "in png_set_compression_mem_level\n");
  176667. if (png_ptr == NULL)
  176668. return;
  176669. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL;
  176670. png_ptr->zlib_mem_level = mem_level;
  176671. }
  176672. void PNGAPI
  176673. png_set_compression_strategy(png_structp png_ptr, int strategy)
  176674. {
  176675. png_debug(1, "in png_set_compression_strategy\n");
  176676. if (png_ptr == NULL)
  176677. return;
  176678. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_STRATEGY;
  176679. png_ptr->zlib_strategy = strategy;
  176680. }
  176681. void PNGAPI
  176682. png_set_compression_window_bits(png_structp png_ptr, int window_bits)
  176683. {
  176684. if (png_ptr == NULL)
  176685. return;
  176686. if (window_bits > 15)
  176687. png_warning(png_ptr, "Only compression windows <= 32k supported by PNG");
  176688. else if (window_bits < 8)
  176689. png_warning(png_ptr, "Only compression windows >= 256 supported by PNG");
  176690. #ifndef WBITS_8_OK
  176691. if (window_bits == 8)
  176692. {
  176693. png_warning(png_ptr, "Compression window is being reset to 512");
  176694. window_bits=9;
  176695. }
  176696. #endif
  176697. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS;
  176698. png_ptr->zlib_window_bits = window_bits;
  176699. }
  176700. void PNGAPI
  176701. png_set_compression_method(png_structp png_ptr, int method)
  176702. {
  176703. png_debug(1, "in png_set_compression_method\n");
  176704. if (png_ptr == NULL)
  176705. return;
  176706. if (method != 8)
  176707. png_warning(png_ptr, "Only compression method 8 is supported by PNG");
  176708. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_METHOD;
  176709. png_ptr->zlib_method = method;
  176710. }
  176711. void PNGAPI
  176712. png_set_write_status_fn(png_structp png_ptr, png_write_status_ptr write_row_fn)
  176713. {
  176714. if (png_ptr == NULL)
  176715. return;
  176716. png_ptr->write_row_fn = write_row_fn;
  176717. }
  176718. #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  176719. void PNGAPI
  176720. png_set_write_user_transform_fn(png_structp png_ptr, png_user_transform_ptr
  176721. write_user_transform_fn)
  176722. {
  176723. png_debug(1, "in png_set_write_user_transform_fn\n");
  176724. if (png_ptr == NULL)
  176725. return;
  176726. png_ptr->transformations |= PNG_USER_TRANSFORM;
  176727. png_ptr->write_user_transform_fn = write_user_transform_fn;
  176728. }
  176729. #endif
  176730. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  176731. void PNGAPI
  176732. png_write_png(png_structp png_ptr, png_infop info_ptr,
  176733. int transforms, voidp params)
  176734. {
  176735. if (png_ptr == NULL || info_ptr == NULL)
  176736. return;
  176737. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  176738. if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
  176739. png_set_invert_alpha(png_ptr);
  176740. #endif
  176741. png_write_info(png_ptr, info_ptr);
  176742. #if defined(PNG_WRITE_INVERT_SUPPORTED)
  176743. if (transforms & PNG_TRANSFORM_INVERT_MONO)
  176744. png_set_invert_mono(png_ptr);
  176745. #endif
  176746. #if defined(PNG_WRITE_SHIFT_SUPPORTED)
  176747. if ((transforms & PNG_TRANSFORM_SHIFT)
  176748. && (info_ptr->valid & PNG_INFO_sBIT))
  176749. png_set_shift(png_ptr, &info_ptr->sig_bit);
  176750. #endif
  176751. #if defined(PNG_WRITE_PACK_SUPPORTED)
  176752. if (transforms & PNG_TRANSFORM_PACKING)
  176753. png_set_packing(png_ptr);
  176754. #endif
  176755. #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  176756. if (transforms & PNG_TRANSFORM_SWAP_ALPHA)
  176757. png_set_swap_alpha(png_ptr);
  176758. #endif
  176759. #if defined(PNG_WRITE_FILLER_SUPPORTED)
  176760. if (transforms & PNG_TRANSFORM_STRIP_FILLER)
  176761. png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);
  176762. #endif
  176763. #if defined(PNG_WRITE_BGR_SUPPORTED)
  176764. if (transforms & PNG_TRANSFORM_BGR)
  176765. png_set_bgr(png_ptr);
  176766. #endif
  176767. #if defined(PNG_WRITE_SWAP_SUPPORTED)
  176768. if (transforms & PNG_TRANSFORM_SWAP_ENDIAN)
  176769. png_set_swap(png_ptr);
  176770. #endif
  176771. #if defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  176772. if (transforms & PNG_TRANSFORM_PACKSWAP)
  176773. png_set_packswap(png_ptr);
  176774. #endif
  176775. if (info_ptr->valid & PNG_INFO_IDAT)
  176776. png_write_image(png_ptr, info_ptr->row_pointers);
  176777. png_write_end(png_ptr, info_ptr);
  176778. transforms = transforms; /* quiet compiler warnings */
  176779. params = params;
  176780. }
  176781. #endif
  176782. #endif /* PNG_WRITE_SUPPORTED */
  176783. /*** End of inlined file: pngwrite.c ***/
  176784. /*** Start of inlined file: pngwtran.c ***/
  176785. #define PNG_INTERNAL
  176786. #ifdef PNG_WRITE_SUPPORTED
  176787. void /* PRIVATE */
  176788. png_do_write_transformations(png_structp png_ptr)
  176789. {
  176790. png_debug(1, "in png_do_write_transformations\n");
  176791. if (png_ptr == NULL)
  176792. return;
  176793. #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  176794. if (png_ptr->transformations & PNG_USER_TRANSFORM)
  176795. if(png_ptr->write_user_transform_fn != NULL)
  176796. (*(png_ptr->write_user_transform_fn)) /* user write transform function */
  176797. (png_ptr, /* png_ptr */
  176798. &(png_ptr->row_info), /* row_info: */
  176799. png_ptr->row_buf + 1); /* start of pixel data for row */
  176800. #endif
  176801. #if defined(PNG_WRITE_FILLER_SUPPORTED)
  176802. if (png_ptr->transformations & PNG_FILLER)
  176803. png_do_strip_filler(&(png_ptr->row_info), png_ptr->row_buf + 1,
  176804. png_ptr->flags);
  176805. #endif
  176806. #if defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  176807. if (png_ptr->transformations & PNG_PACKSWAP)
  176808. png_do_packswap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176809. #endif
  176810. #if defined(PNG_WRITE_PACK_SUPPORTED)
  176811. if (png_ptr->transformations & PNG_PACK)
  176812. png_do_pack(&(png_ptr->row_info), png_ptr->row_buf + 1,
  176813. (png_uint_32)png_ptr->bit_depth);
  176814. #endif
  176815. #if defined(PNG_WRITE_SWAP_SUPPORTED)
  176816. if (png_ptr->transformations & PNG_SWAP_BYTES)
  176817. png_do_swap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176818. #endif
  176819. #if defined(PNG_WRITE_SHIFT_SUPPORTED)
  176820. if (png_ptr->transformations & PNG_SHIFT)
  176821. png_do_shift(&(png_ptr->row_info), png_ptr->row_buf + 1,
  176822. &(png_ptr->shift));
  176823. #endif
  176824. #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  176825. if (png_ptr->transformations & PNG_SWAP_ALPHA)
  176826. png_do_write_swap_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176827. #endif
  176828. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  176829. if (png_ptr->transformations & PNG_INVERT_ALPHA)
  176830. png_do_write_invert_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176831. #endif
  176832. #if defined(PNG_WRITE_BGR_SUPPORTED)
  176833. if (png_ptr->transformations & PNG_BGR)
  176834. png_do_bgr(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176835. #endif
  176836. #if defined(PNG_WRITE_INVERT_SUPPORTED)
  176837. if (png_ptr->transformations & PNG_INVERT_MONO)
  176838. png_do_invert(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176839. #endif
  176840. }
  176841. #if defined(PNG_WRITE_PACK_SUPPORTED)
  176842. void /* PRIVATE */
  176843. png_do_pack(png_row_infop row_info, png_bytep row, png_uint_32 bit_depth)
  176844. {
  176845. png_debug(1, "in png_do_pack\n");
  176846. if (row_info->bit_depth == 8 &&
  176847. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  176848. row != NULL && row_info != NULL &&
  176849. #endif
  176850. row_info->channels == 1)
  176851. {
  176852. switch ((int)bit_depth)
  176853. {
  176854. case 1:
  176855. {
  176856. png_bytep sp, dp;
  176857. int mask, v;
  176858. png_uint_32 i;
  176859. png_uint_32 row_width = row_info->width;
  176860. sp = row;
  176861. dp = row;
  176862. mask = 0x80;
  176863. v = 0;
  176864. for (i = 0; i < row_width; i++)
  176865. {
  176866. if (*sp != 0)
  176867. v |= mask;
  176868. sp++;
  176869. if (mask > 1)
  176870. mask >>= 1;
  176871. else
  176872. {
  176873. mask = 0x80;
  176874. *dp = (png_byte)v;
  176875. dp++;
  176876. v = 0;
  176877. }
  176878. }
  176879. if (mask != 0x80)
  176880. *dp = (png_byte)v;
  176881. break;
  176882. }
  176883. case 2:
  176884. {
  176885. png_bytep sp, dp;
  176886. int shift, v;
  176887. png_uint_32 i;
  176888. png_uint_32 row_width = row_info->width;
  176889. sp = row;
  176890. dp = row;
  176891. shift = 6;
  176892. v = 0;
  176893. for (i = 0; i < row_width; i++)
  176894. {
  176895. png_byte value;
  176896. value = (png_byte)(*sp & 0x03);
  176897. v |= (value << shift);
  176898. if (shift == 0)
  176899. {
  176900. shift = 6;
  176901. *dp = (png_byte)v;
  176902. dp++;
  176903. v = 0;
  176904. }
  176905. else
  176906. shift -= 2;
  176907. sp++;
  176908. }
  176909. if (shift != 6)
  176910. *dp = (png_byte)v;
  176911. break;
  176912. }
  176913. case 4:
  176914. {
  176915. png_bytep sp, dp;
  176916. int shift, v;
  176917. png_uint_32 i;
  176918. png_uint_32 row_width = row_info->width;
  176919. sp = row;
  176920. dp = row;
  176921. shift = 4;
  176922. v = 0;
  176923. for (i = 0; i < row_width; i++)
  176924. {
  176925. png_byte value;
  176926. value = (png_byte)(*sp & 0x0f);
  176927. v |= (value << shift);
  176928. if (shift == 0)
  176929. {
  176930. shift = 4;
  176931. *dp = (png_byte)v;
  176932. dp++;
  176933. v = 0;
  176934. }
  176935. else
  176936. shift -= 4;
  176937. sp++;
  176938. }
  176939. if (shift != 4)
  176940. *dp = (png_byte)v;
  176941. break;
  176942. }
  176943. }
  176944. row_info->bit_depth = (png_byte)bit_depth;
  176945. row_info->pixel_depth = (png_byte)(bit_depth * row_info->channels);
  176946. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
  176947. row_info->width);
  176948. }
  176949. }
  176950. #endif
  176951. #if defined(PNG_WRITE_SHIFT_SUPPORTED)
  176952. void /* PRIVATE */
  176953. png_do_shift(png_row_infop row_info, png_bytep row, png_color_8p bit_depth)
  176954. {
  176955. png_debug(1, "in png_do_shift\n");
  176956. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  176957. if (row != NULL && row_info != NULL &&
  176958. #else
  176959. if (
  176960. #endif
  176961. row_info->color_type != PNG_COLOR_TYPE_PALETTE)
  176962. {
  176963. int shift_start[4], shift_dec[4];
  176964. int channels = 0;
  176965. if (row_info->color_type & PNG_COLOR_MASK_COLOR)
  176966. {
  176967. shift_start[channels] = row_info->bit_depth - bit_depth->red;
  176968. shift_dec[channels] = bit_depth->red;
  176969. channels++;
  176970. shift_start[channels] = row_info->bit_depth - bit_depth->green;
  176971. shift_dec[channels] = bit_depth->green;
  176972. channels++;
  176973. shift_start[channels] = row_info->bit_depth - bit_depth->blue;
  176974. shift_dec[channels] = bit_depth->blue;
  176975. channels++;
  176976. }
  176977. else
  176978. {
  176979. shift_start[channels] = row_info->bit_depth - bit_depth->gray;
  176980. shift_dec[channels] = bit_depth->gray;
  176981. channels++;
  176982. }
  176983. if (row_info->color_type & PNG_COLOR_MASK_ALPHA)
  176984. {
  176985. shift_start[channels] = row_info->bit_depth - bit_depth->alpha;
  176986. shift_dec[channels] = bit_depth->alpha;
  176987. channels++;
  176988. }
  176989. if (row_info->bit_depth < 8)
  176990. {
  176991. png_bytep bp = row;
  176992. png_uint_32 i;
  176993. png_byte mask;
  176994. png_uint_32 row_bytes = row_info->rowbytes;
  176995. if (bit_depth->gray == 1 && row_info->bit_depth == 2)
  176996. mask = 0x55;
  176997. else if (row_info->bit_depth == 4 && bit_depth->gray == 3)
  176998. mask = 0x11;
  176999. else
  177000. mask = 0xff;
  177001. for (i = 0; i < row_bytes; i++, bp++)
  177002. {
  177003. png_uint_16 v;
  177004. int j;
  177005. v = *bp;
  177006. *bp = 0;
  177007. for (j = shift_start[0]; j > -shift_dec[0]; j -= shift_dec[0])
  177008. {
  177009. if (j > 0)
  177010. *bp |= (png_byte)((v << j) & 0xff);
  177011. else
  177012. *bp |= (png_byte)((v >> (-j)) & mask);
  177013. }
  177014. }
  177015. }
  177016. else if (row_info->bit_depth == 8)
  177017. {
  177018. png_bytep bp = row;
  177019. png_uint_32 i;
  177020. png_uint_32 istop = channels * row_info->width;
  177021. for (i = 0; i < istop; i++, bp++)
  177022. {
  177023. png_uint_16 v;
  177024. int j;
  177025. int c = (int)(i%channels);
  177026. v = *bp;
  177027. *bp = 0;
  177028. for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c])
  177029. {
  177030. if (j > 0)
  177031. *bp |= (png_byte)((v << j) & 0xff);
  177032. else
  177033. *bp |= (png_byte)((v >> (-j)) & 0xff);
  177034. }
  177035. }
  177036. }
  177037. else
  177038. {
  177039. png_bytep bp;
  177040. png_uint_32 i;
  177041. png_uint_32 istop = channels * row_info->width;
  177042. for (bp = row, i = 0; i < istop; i++)
  177043. {
  177044. int c = (int)(i%channels);
  177045. png_uint_16 value, v;
  177046. int j;
  177047. v = (png_uint_16)(((png_uint_16)(*bp) << 8) + *(bp + 1));
  177048. value = 0;
  177049. for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c])
  177050. {
  177051. if (j > 0)
  177052. value |= (png_uint_16)((v << j) & (png_uint_16)0xffff);
  177053. else
  177054. value |= (png_uint_16)((v >> (-j)) & (png_uint_16)0xffff);
  177055. }
  177056. *bp++ = (png_byte)(value >> 8);
  177057. *bp++ = (png_byte)(value & 0xff);
  177058. }
  177059. }
  177060. }
  177061. }
  177062. #endif
  177063. #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  177064. void /* PRIVATE */
  177065. png_do_write_swap_alpha(png_row_infop row_info, png_bytep row)
  177066. {
  177067. png_debug(1, "in png_do_write_swap_alpha\n");
  177068. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  177069. if (row != NULL && row_info != NULL)
  177070. #endif
  177071. {
  177072. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  177073. {
  177074. if (row_info->bit_depth == 8)
  177075. {
  177076. png_bytep sp, dp;
  177077. png_uint_32 i;
  177078. png_uint_32 row_width = row_info->width;
  177079. for (i = 0, sp = dp = row; i < row_width; i++)
  177080. {
  177081. png_byte save = *(sp++);
  177082. *(dp++) = *(sp++);
  177083. *(dp++) = *(sp++);
  177084. *(dp++) = *(sp++);
  177085. *(dp++) = save;
  177086. }
  177087. }
  177088. else
  177089. {
  177090. png_bytep sp, dp;
  177091. png_uint_32 i;
  177092. png_uint_32 row_width = row_info->width;
  177093. for (i = 0, sp = dp = row; i < row_width; i++)
  177094. {
  177095. png_byte save[2];
  177096. save[0] = *(sp++);
  177097. save[1] = *(sp++);
  177098. *(dp++) = *(sp++);
  177099. *(dp++) = *(sp++);
  177100. *(dp++) = *(sp++);
  177101. *(dp++) = *(sp++);
  177102. *(dp++) = *(sp++);
  177103. *(dp++) = *(sp++);
  177104. *(dp++) = save[0];
  177105. *(dp++) = save[1];
  177106. }
  177107. }
  177108. }
  177109. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  177110. {
  177111. if (row_info->bit_depth == 8)
  177112. {
  177113. png_bytep sp, dp;
  177114. png_uint_32 i;
  177115. png_uint_32 row_width = row_info->width;
  177116. for (i = 0, sp = dp = row; i < row_width; i++)
  177117. {
  177118. png_byte save = *(sp++);
  177119. *(dp++) = *(sp++);
  177120. *(dp++) = save;
  177121. }
  177122. }
  177123. else
  177124. {
  177125. png_bytep sp, dp;
  177126. png_uint_32 i;
  177127. png_uint_32 row_width = row_info->width;
  177128. for (i = 0, sp = dp = row; i < row_width; i++)
  177129. {
  177130. png_byte save[2];
  177131. save[0] = *(sp++);
  177132. save[1] = *(sp++);
  177133. *(dp++) = *(sp++);
  177134. *(dp++) = *(sp++);
  177135. *(dp++) = save[0];
  177136. *(dp++) = save[1];
  177137. }
  177138. }
  177139. }
  177140. }
  177141. }
  177142. #endif
  177143. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  177144. void /* PRIVATE */
  177145. png_do_write_invert_alpha(png_row_infop row_info, png_bytep row)
  177146. {
  177147. png_debug(1, "in png_do_write_invert_alpha\n");
  177148. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  177149. if (row != NULL && row_info != NULL)
  177150. #endif
  177151. {
  177152. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  177153. {
  177154. if (row_info->bit_depth == 8)
  177155. {
  177156. png_bytep sp, dp;
  177157. png_uint_32 i;
  177158. png_uint_32 row_width = row_info->width;
  177159. for (i = 0, sp = dp = row; i < row_width; i++)
  177160. {
  177161. sp+=3; dp = sp;
  177162. *(dp++) = (png_byte)(255 - *(sp++));
  177163. }
  177164. }
  177165. else
  177166. {
  177167. png_bytep sp, dp;
  177168. png_uint_32 i;
  177169. png_uint_32 row_width = row_info->width;
  177170. for (i = 0, sp = dp = row; i < row_width; i++)
  177171. {
  177172. sp+=6; dp = sp;
  177173. *(dp++) = (png_byte)(255 - *(sp++));
  177174. *(dp++) = (png_byte)(255 - *(sp++));
  177175. }
  177176. }
  177177. }
  177178. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  177179. {
  177180. if (row_info->bit_depth == 8)
  177181. {
  177182. png_bytep sp, dp;
  177183. png_uint_32 i;
  177184. png_uint_32 row_width = row_info->width;
  177185. for (i = 0, sp = dp = row; i < row_width; i++)
  177186. {
  177187. *(dp++) = *(sp++);
  177188. *(dp++) = (png_byte)(255 - *(sp++));
  177189. }
  177190. }
  177191. else
  177192. {
  177193. png_bytep sp, dp;
  177194. png_uint_32 i;
  177195. png_uint_32 row_width = row_info->width;
  177196. for (i = 0, sp = dp = row; i < row_width; i++)
  177197. {
  177198. sp+=2; dp = sp;
  177199. *(dp++) = (png_byte)(255 - *(sp++));
  177200. *(dp++) = (png_byte)(255 - *(sp++));
  177201. }
  177202. }
  177203. }
  177204. }
  177205. }
  177206. #endif
  177207. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  177208. void /* PRIVATE */
  177209. png_do_write_intrapixel(png_row_infop row_info, png_bytep row)
  177210. {
  177211. png_debug(1, "in png_do_write_intrapixel\n");
  177212. if (
  177213. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  177214. row != NULL && row_info != NULL &&
  177215. #endif
  177216. (row_info->color_type & PNG_COLOR_MASK_COLOR))
  177217. {
  177218. int bytes_per_pixel;
  177219. png_uint_32 row_width = row_info->width;
  177220. if (row_info->bit_depth == 8)
  177221. {
  177222. png_bytep rp;
  177223. png_uint_32 i;
  177224. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  177225. bytes_per_pixel = 3;
  177226. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  177227. bytes_per_pixel = 4;
  177228. else
  177229. return;
  177230. for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
  177231. {
  177232. *(rp) = (png_byte)((*rp - *(rp+1))&0xff);
  177233. *(rp+2) = (png_byte)((*(rp+2) - *(rp+1))&0xff);
  177234. }
  177235. }
  177236. else if (row_info->bit_depth == 16)
  177237. {
  177238. png_bytep rp;
  177239. png_uint_32 i;
  177240. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  177241. bytes_per_pixel = 6;
  177242. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  177243. bytes_per_pixel = 8;
  177244. else
  177245. return;
  177246. for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
  177247. {
  177248. png_uint_32 s0 = (*(rp ) << 8) | *(rp+1);
  177249. png_uint_32 s1 = (*(rp+2) << 8) | *(rp+3);
  177250. png_uint_32 s2 = (*(rp+4) << 8) | *(rp+5);
  177251. png_uint_32 red = (png_uint_32)((s0-s1) & 0xffffL);
  177252. png_uint_32 blue = (png_uint_32)((s2-s1) & 0xffffL);
  177253. *(rp ) = (png_byte)((red >> 8) & 0xff);
  177254. *(rp+1) = (png_byte)(red & 0xff);
  177255. *(rp+4) = (png_byte)((blue >> 8) & 0xff);
  177256. *(rp+5) = (png_byte)(blue & 0xff);
  177257. }
  177258. }
  177259. }
  177260. }
  177261. #endif /* PNG_MNG_FEATURES_SUPPORTED */
  177262. #endif /* PNG_WRITE_SUPPORTED */
  177263. /*** End of inlined file: pngwtran.c ***/
  177264. /*** Start of inlined file: pngwutil.c ***/
  177265. #define PNG_INTERNAL
  177266. #ifdef PNG_WRITE_SUPPORTED
  177267. void PNGAPI
  177268. png_save_uint_32(png_bytep buf, png_uint_32 i)
  177269. {
  177270. buf[0] = (png_byte)((i >> 24) & 0xff);
  177271. buf[1] = (png_byte)((i >> 16) & 0xff);
  177272. buf[2] = (png_byte)((i >> 8) & 0xff);
  177273. buf[3] = (png_byte)(i & 0xff);
  177274. }
  177275. void PNGAPI
  177276. png_save_int_32(png_bytep buf, png_int_32 i)
  177277. {
  177278. buf[0] = (png_byte)((i >> 24) & 0xff);
  177279. buf[1] = (png_byte)((i >> 16) & 0xff);
  177280. buf[2] = (png_byte)((i >> 8) & 0xff);
  177281. buf[3] = (png_byte)(i & 0xff);
  177282. }
  177283. void PNGAPI
  177284. png_save_uint_16(png_bytep buf, unsigned int i)
  177285. {
  177286. buf[0] = (png_byte)((i >> 8) & 0xff);
  177287. buf[1] = (png_byte)(i & 0xff);
  177288. }
  177289. void PNGAPI
  177290. png_write_chunk(png_structp png_ptr, png_bytep chunk_name,
  177291. png_bytep data, png_size_t length)
  177292. {
  177293. if(png_ptr == NULL) return;
  177294. png_write_chunk_start(png_ptr, chunk_name, (png_uint_32)length);
  177295. png_write_chunk_data(png_ptr, data, length);
  177296. png_write_chunk_end(png_ptr);
  177297. }
  177298. void PNGAPI
  177299. png_write_chunk_start(png_structp png_ptr, png_bytep chunk_name,
  177300. png_uint_32 length)
  177301. {
  177302. png_byte buf[4];
  177303. png_debug2(0, "Writing %s chunk (%lu bytes)\n", chunk_name, length);
  177304. if(png_ptr == NULL) return;
  177305. png_save_uint_32(buf, length);
  177306. png_write_data(png_ptr, buf, (png_size_t)4);
  177307. png_write_data(png_ptr, chunk_name, (png_size_t)4);
  177308. png_reset_crc(png_ptr);
  177309. png_calculate_crc(png_ptr, chunk_name, (png_size_t)4);
  177310. }
  177311. void PNGAPI
  177312. png_write_chunk_data(png_structp png_ptr, png_bytep data, png_size_t length)
  177313. {
  177314. if(png_ptr == NULL) return;
  177315. if (data != NULL && length > 0)
  177316. {
  177317. png_calculate_crc(png_ptr, data, length);
  177318. png_write_data(png_ptr, data, length);
  177319. }
  177320. }
  177321. void PNGAPI
  177322. png_write_chunk_end(png_structp png_ptr)
  177323. {
  177324. png_byte buf[4];
  177325. if(png_ptr == NULL) return;
  177326. png_save_uint_32(buf, png_ptr->crc);
  177327. png_write_data(png_ptr, buf, (png_size_t)4);
  177328. }
  177329. void /* PRIVATE */
  177330. png_write_sig(png_structp png_ptr)
  177331. {
  177332. png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};
  177333. png_write_data(png_ptr, &png_signature[png_ptr->sig_bytes],
  177334. (png_size_t)8 - png_ptr->sig_bytes);
  177335. if(png_ptr->sig_bytes < 3)
  177336. png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE;
  177337. }
  177338. #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_iCCP_SUPPORTED)
  177339. typedef struct
  177340. {
  177341. char *input; /* the uncompressed input data */
  177342. int input_len; /* its length */
  177343. int num_output_ptr; /* number of output pointers used */
  177344. int max_output_ptr; /* size of output_ptr */
  177345. png_charpp output_ptr; /* array of pointers to output */
  177346. } compression_state;
  177347. static int /* PRIVATE */
  177348. png_text_compress(png_structp png_ptr,
  177349. png_charp text, png_size_t text_len, int compression,
  177350. compression_state *comp)
  177351. {
  177352. int ret;
  177353. comp->num_output_ptr = 0;
  177354. comp->max_output_ptr = 0;
  177355. comp->output_ptr = NULL;
  177356. comp->input = NULL;
  177357. comp->input_len = 0;
  177358. if (compression == PNG_TEXT_COMPRESSION_NONE)
  177359. {
  177360. comp->input = text;
  177361. comp->input_len = text_len;
  177362. return((int)text_len);
  177363. }
  177364. if (compression >= PNG_TEXT_COMPRESSION_LAST)
  177365. {
  177366. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  177367. char msg[50];
  177368. png_snprintf(msg, 50, "Unknown compression type %d", compression);
  177369. png_warning(png_ptr, msg);
  177370. #else
  177371. png_warning(png_ptr, "Unknown compression type");
  177372. #endif
  177373. }
  177374. png_ptr->zstream.avail_in = (uInt)text_len;
  177375. png_ptr->zstream.next_in = (Bytef *)text;
  177376. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  177377. png_ptr->zstream.next_out = (Bytef *)png_ptr->zbuf;
  177378. do
  177379. {
  177380. ret = deflate(&png_ptr->zstream, Z_NO_FLUSH);
  177381. if (ret != Z_OK)
  177382. {
  177383. if (png_ptr->zstream.msg != NULL)
  177384. png_error(png_ptr, png_ptr->zstream.msg);
  177385. else
  177386. png_error(png_ptr, "zlib error");
  177387. }
  177388. if (!(png_ptr->zstream.avail_out))
  177389. {
  177390. if (comp->num_output_ptr >= comp->max_output_ptr)
  177391. {
  177392. int old_max;
  177393. old_max = comp->max_output_ptr;
  177394. comp->max_output_ptr = comp->num_output_ptr + 4;
  177395. if (comp->output_ptr != NULL)
  177396. {
  177397. png_charpp old_ptr;
  177398. old_ptr = comp->output_ptr;
  177399. comp->output_ptr = (png_charpp)png_malloc(png_ptr,
  177400. (png_uint_32)(comp->max_output_ptr *
  177401. png_sizeof (png_charpp)));
  177402. png_memcpy(comp->output_ptr, old_ptr, old_max
  177403. * png_sizeof (png_charp));
  177404. png_free(png_ptr, old_ptr);
  177405. }
  177406. else
  177407. comp->output_ptr = (png_charpp)png_malloc(png_ptr,
  177408. (png_uint_32)(comp->max_output_ptr *
  177409. png_sizeof (png_charp)));
  177410. }
  177411. comp->output_ptr[comp->num_output_ptr] = (png_charp)png_malloc(png_ptr,
  177412. (png_uint_32)png_ptr->zbuf_size);
  177413. png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf,
  177414. png_ptr->zbuf_size);
  177415. comp->num_output_ptr++;
  177416. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  177417. png_ptr->zstream.next_out = png_ptr->zbuf;
  177418. }
  177419. } while (png_ptr->zstream.avail_in);
  177420. do
  177421. {
  177422. ret = deflate(&png_ptr->zstream, Z_FINISH);
  177423. if (ret == Z_OK)
  177424. {
  177425. if (!(png_ptr->zstream.avail_out))
  177426. {
  177427. if (comp->num_output_ptr >= comp->max_output_ptr)
  177428. {
  177429. int old_max;
  177430. old_max = comp->max_output_ptr;
  177431. comp->max_output_ptr = comp->num_output_ptr + 4;
  177432. if (comp->output_ptr != NULL)
  177433. {
  177434. png_charpp old_ptr;
  177435. old_ptr = comp->output_ptr;
  177436. comp->output_ptr = (png_charpp)png_malloc(png_ptr,
  177437. (png_uint_32)(comp->max_output_ptr *
  177438. png_sizeof (png_charpp)));
  177439. png_memcpy(comp->output_ptr, old_ptr,
  177440. old_max * png_sizeof (png_charp));
  177441. png_free(png_ptr, old_ptr);
  177442. }
  177443. else
  177444. comp->output_ptr = (png_charpp)png_malloc(png_ptr,
  177445. (png_uint_32)(comp->max_output_ptr *
  177446. png_sizeof (png_charp)));
  177447. }
  177448. comp->output_ptr[comp->num_output_ptr] =
  177449. (png_charp)png_malloc(png_ptr, (png_uint_32)png_ptr->zbuf_size);
  177450. png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf,
  177451. png_ptr->zbuf_size);
  177452. comp->num_output_ptr++;
  177453. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  177454. png_ptr->zstream.next_out = png_ptr->zbuf;
  177455. }
  177456. }
  177457. else if (ret != Z_STREAM_END)
  177458. {
  177459. if (png_ptr->zstream.msg != NULL)
  177460. png_error(png_ptr, png_ptr->zstream.msg);
  177461. else
  177462. png_error(png_ptr, "zlib error");
  177463. }
  177464. } while (ret != Z_STREAM_END);
  177465. text_len = png_ptr->zbuf_size * comp->num_output_ptr;
  177466. if (png_ptr->zstream.avail_out < png_ptr->zbuf_size)
  177467. text_len += png_ptr->zbuf_size - (png_size_t)png_ptr->zstream.avail_out;
  177468. return((int)text_len);
  177469. }
  177470. static void /* PRIVATE */
  177471. png_write_compressed_data_out(png_structp png_ptr, compression_state *comp)
  177472. {
  177473. int i;
  177474. if (comp->input)
  177475. {
  177476. png_write_chunk_data(png_ptr, (png_bytep)comp->input,
  177477. (png_size_t)comp->input_len);
  177478. return;
  177479. }
  177480. for (i = 0; i < comp->num_output_ptr; i++)
  177481. {
  177482. png_write_chunk_data(png_ptr,(png_bytep)comp->output_ptr[i],
  177483. png_ptr->zbuf_size);
  177484. png_free(png_ptr, comp->output_ptr[i]);
  177485. comp->output_ptr[i]=NULL;
  177486. }
  177487. if (comp->max_output_ptr != 0)
  177488. png_free(png_ptr, comp->output_ptr);
  177489. comp->output_ptr=NULL;
  177490. if (png_ptr->zstream.avail_out < (png_uint_32)png_ptr->zbuf_size)
  177491. png_write_chunk_data(png_ptr, png_ptr->zbuf,
  177492. png_ptr->zbuf_size - png_ptr->zstream.avail_out);
  177493. deflateReset(&png_ptr->zstream);
  177494. png_ptr->zstream.data_type = Z_BINARY;
  177495. }
  177496. #endif
  177497. void /* PRIVATE */
  177498. png_write_IHDR(png_structp png_ptr, png_uint_32 width, png_uint_32 height,
  177499. int bit_depth, int color_type, int compression_type, int filter_type,
  177500. int interlace_type)
  177501. {
  177502. #ifdef PNG_USE_LOCAL_ARRAYS
  177503. PNG_IHDR;
  177504. #endif
  177505. png_byte buf[13]; /* buffer to store the IHDR info */
  177506. png_debug(1, "in png_write_IHDR\n");
  177507. switch (color_type)
  177508. {
  177509. case PNG_COLOR_TYPE_GRAY:
  177510. switch (bit_depth)
  177511. {
  177512. case 1:
  177513. case 2:
  177514. case 4:
  177515. case 8:
  177516. case 16: png_ptr->channels = 1; break;
  177517. default: png_error(png_ptr,"Invalid bit depth for grayscale image");
  177518. }
  177519. break;
  177520. case PNG_COLOR_TYPE_RGB:
  177521. if (bit_depth != 8 && bit_depth != 16)
  177522. png_error(png_ptr, "Invalid bit depth for RGB image");
  177523. png_ptr->channels = 3;
  177524. break;
  177525. case PNG_COLOR_TYPE_PALETTE:
  177526. switch (bit_depth)
  177527. {
  177528. case 1:
  177529. case 2:
  177530. case 4:
  177531. case 8: png_ptr->channels = 1; break;
  177532. default: png_error(png_ptr, "Invalid bit depth for paletted image");
  177533. }
  177534. break;
  177535. case PNG_COLOR_TYPE_GRAY_ALPHA:
  177536. if (bit_depth != 8 && bit_depth != 16)
  177537. png_error(png_ptr, "Invalid bit depth for grayscale+alpha image");
  177538. png_ptr->channels = 2;
  177539. break;
  177540. case PNG_COLOR_TYPE_RGB_ALPHA:
  177541. if (bit_depth != 8 && bit_depth != 16)
  177542. png_error(png_ptr, "Invalid bit depth for RGBA image");
  177543. png_ptr->channels = 4;
  177544. break;
  177545. default:
  177546. png_error(png_ptr, "Invalid image color type specified");
  177547. }
  177548. if (compression_type != PNG_COMPRESSION_TYPE_BASE)
  177549. {
  177550. png_warning(png_ptr, "Invalid compression type specified");
  177551. compression_type = PNG_COMPRESSION_TYPE_BASE;
  177552. }
  177553. if (
  177554. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  177555. !((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  177556. ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) &&
  177557. (color_type == PNG_COLOR_TYPE_RGB ||
  177558. color_type == PNG_COLOR_TYPE_RGB_ALPHA) &&
  177559. (filter_type == PNG_INTRAPIXEL_DIFFERENCING)) &&
  177560. #endif
  177561. filter_type != PNG_FILTER_TYPE_BASE)
  177562. {
  177563. png_warning(png_ptr, "Invalid filter type specified");
  177564. filter_type = PNG_FILTER_TYPE_BASE;
  177565. }
  177566. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  177567. if (interlace_type != PNG_INTERLACE_NONE &&
  177568. interlace_type != PNG_INTERLACE_ADAM7)
  177569. {
  177570. png_warning(png_ptr, "Invalid interlace type specified");
  177571. interlace_type = PNG_INTERLACE_ADAM7;
  177572. }
  177573. #else
  177574. interlace_type=PNG_INTERLACE_NONE;
  177575. #endif
  177576. png_ptr->bit_depth = (png_byte)bit_depth;
  177577. png_ptr->color_type = (png_byte)color_type;
  177578. png_ptr->interlaced = (png_byte)interlace_type;
  177579. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  177580. png_ptr->filter_type = (png_byte)filter_type;
  177581. #endif
  177582. png_ptr->compression_type = (png_byte)compression_type;
  177583. png_ptr->width = width;
  177584. png_ptr->height = height;
  177585. png_ptr->pixel_depth = (png_byte)(bit_depth * png_ptr->channels);
  177586. png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth, width);
  177587. png_ptr->usr_width = png_ptr->width;
  177588. png_ptr->usr_bit_depth = png_ptr->bit_depth;
  177589. png_ptr->usr_channels = png_ptr->channels;
  177590. png_save_uint_32(buf, width);
  177591. png_save_uint_32(buf + 4, height);
  177592. buf[8] = (png_byte)bit_depth;
  177593. buf[9] = (png_byte)color_type;
  177594. buf[10] = (png_byte)compression_type;
  177595. buf[11] = (png_byte)filter_type;
  177596. buf[12] = (png_byte)interlace_type;
  177597. png_write_chunk(png_ptr, png_IHDR, buf, (png_size_t)13);
  177598. png_ptr->zstream.zalloc = png_zalloc;
  177599. png_ptr->zstream.zfree = png_zfree;
  177600. png_ptr->zstream.opaque = (voidpf)png_ptr;
  177601. if (!(png_ptr->do_filter))
  177602. {
  177603. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE ||
  177604. png_ptr->bit_depth < 8)
  177605. png_ptr->do_filter = PNG_FILTER_NONE;
  177606. else
  177607. png_ptr->do_filter = PNG_ALL_FILTERS;
  177608. }
  177609. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_STRATEGY))
  177610. {
  177611. if (png_ptr->do_filter != PNG_FILTER_NONE)
  177612. png_ptr->zlib_strategy = Z_FILTERED;
  177613. else
  177614. png_ptr->zlib_strategy = Z_DEFAULT_STRATEGY;
  177615. }
  177616. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_LEVEL))
  177617. png_ptr->zlib_level = Z_DEFAULT_COMPRESSION;
  177618. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL))
  177619. png_ptr->zlib_mem_level = 8;
  177620. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS))
  177621. png_ptr->zlib_window_bits = 15;
  177622. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_METHOD))
  177623. png_ptr->zlib_method = 8;
  177624. if (deflateInit2(&png_ptr->zstream, png_ptr->zlib_level,
  177625. png_ptr->zlib_method, png_ptr->zlib_window_bits,
  177626. png_ptr->zlib_mem_level, png_ptr->zlib_strategy) != Z_OK)
  177627. png_error(png_ptr, "zlib failed to initialize compressor");
  177628. png_ptr->zstream.next_out = png_ptr->zbuf;
  177629. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  177630. png_ptr->zstream.data_type = Z_BINARY;
  177631. png_ptr->mode = PNG_HAVE_IHDR;
  177632. }
  177633. void /* PRIVATE */
  177634. png_write_PLTE(png_structp png_ptr, png_colorp palette, png_uint_32 num_pal)
  177635. {
  177636. #ifdef PNG_USE_LOCAL_ARRAYS
  177637. PNG_PLTE;
  177638. #endif
  177639. png_uint_32 i;
  177640. png_colorp pal_ptr;
  177641. png_byte buf[3];
  177642. png_debug(1, "in png_write_PLTE\n");
  177643. if ((
  177644. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  177645. !(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE) &&
  177646. #endif
  177647. num_pal == 0) || num_pal > 256)
  177648. {
  177649. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  177650. {
  177651. png_error(png_ptr, "Invalid number of colors in palette");
  177652. }
  177653. else
  177654. {
  177655. png_warning(png_ptr, "Invalid number of colors in palette");
  177656. return;
  177657. }
  177658. }
  177659. if (!(png_ptr->color_type&PNG_COLOR_MASK_COLOR))
  177660. {
  177661. png_warning(png_ptr,
  177662. "Ignoring request to write a PLTE chunk in grayscale PNG");
  177663. return;
  177664. }
  177665. png_ptr->num_palette = (png_uint_16)num_pal;
  177666. png_debug1(3, "num_palette = %d\n", png_ptr->num_palette);
  177667. png_write_chunk_start(png_ptr, png_PLTE, num_pal * 3);
  177668. #ifndef PNG_NO_POINTER_INDEXING
  177669. for (i = 0, pal_ptr = palette; i < num_pal; i++, pal_ptr++)
  177670. {
  177671. buf[0] = pal_ptr->red;
  177672. buf[1] = pal_ptr->green;
  177673. buf[2] = pal_ptr->blue;
  177674. png_write_chunk_data(png_ptr, buf, (png_size_t)3);
  177675. }
  177676. #else
  177677. pal_ptr=palette;
  177678. for (i = 0; i < num_pal; i++)
  177679. {
  177680. buf[0] = pal_ptr[i].red;
  177681. buf[1] = pal_ptr[i].green;
  177682. buf[2] = pal_ptr[i].blue;
  177683. png_write_chunk_data(png_ptr, buf, (png_size_t)3);
  177684. }
  177685. #endif
  177686. png_write_chunk_end(png_ptr);
  177687. png_ptr->mode |= PNG_HAVE_PLTE;
  177688. }
  177689. void /* PRIVATE */
  177690. png_write_IDAT(png_structp png_ptr, png_bytep data, png_size_t length)
  177691. {
  177692. #ifdef PNG_USE_LOCAL_ARRAYS
  177693. PNG_IDAT;
  177694. #endif
  177695. png_debug(1, "in png_write_IDAT\n");
  177696. if (!(png_ptr->mode & PNG_HAVE_IDAT) &&
  177697. png_ptr->compression_type == PNG_COMPRESSION_TYPE_BASE)
  177698. {
  177699. unsigned int z_cmf = data[0]; /* zlib compression method and flags */
  177700. if ((z_cmf & 0x0f) == 8 && (z_cmf & 0xf0) <= 0x70)
  177701. {
  177702. if (length >= 2 &&
  177703. png_ptr->height < 16384 && png_ptr->width < 16384)
  177704. {
  177705. png_uint_32 uncompressed_idat_size = png_ptr->height *
  177706. ((png_ptr->width *
  177707. png_ptr->channels * png_ptr->bit_depth + 15) >> 3);
  177708. unsigned int z_cinfo = z_cmf >> 4;
  177709. unsigned int half_z_window_size = 1 << (z_cinfo + 7);
  177710. while (uncompressed_idat_size <= half_z_window_size &&
  177711. half_z_window_size >= 256)
  177712. {
  177713. z_cinfo--;
  177714. half_z_window_size >>= 1;
  177715. }
  177716. z_cmf = (z_cmf & 0x0f) | (z_cinfo << 4);
  177717. if (data[0] != (png_byte)z_cmf)
  177718. {
  177719. data[0] = (png_byte)z_cmf;
  177720. data[1] &= 0xe0;
  177721. data[1] += (png_byte)(0x1f - ((z_cmf << 8) + data[1]) % 0x1f);
  177722. }
  177723. }
  177724. }
  177725. else
  177726. png_error(png_ptr,
  177727. "Invalid zlib compression method or flags in IDAT");
  177728. }
  177729. png_write_chunk(png_ptr, png_IDAT, data, length);
  177730. png_ptr->mode |= PNG_HAVE_IDAT;
  177731. }
  177732. void /* PRIVATE */
  177733. png_write_IEND(png_structp png_ptr)
  177734. {
  177735. #ifdef PNG_USE_LOCAL_ARRAYS
  177736. PNG_IEND;
  177737. #endif
  177738. png_debug(1, "in png_write_IEND\n");
  177739. png_write_chunk(png_ptr, png_IEND, png_bytep_NULL,
  177740. (png_size_t)0);
  177741. png_ptr->mode |= PNG_HAVE_IEND;
  177742. }
  177743. #if defined(PNG_WRITE_gAMA_SUPPORTED)
  177744. #ifdef PNG_FLOATING_POINT_SUPPORTED
  177745. void /* PRIVATE */
  177746. png_write_gAMA(png_structp png_ptr, double file_gamma)
  177747. {
  177748. #ifdef PNG_USE_LOCAL_ARRAYS
  177749. PNG_gAMA;
  177750. #endif
  177751. png_uint_32 igamma;
  177752. png_byte buf[4];
  177753. png_debug(1, "in png_write_gAMA\n");
  177754. igamma = (png_uint_32)(file_gamma * 100000.0 + 0.5);
  177755. png_save_uint_32(buf, igamma);
  177756. png_write_chunk(png_ptr, png_gAMA, buf, (png_size_t)4);
  177757. }
  177758. #endif
  177759. #ifdef PNG_FIXED_POINT_SUPPORTED
  177760. void /* PRIVATE */
  177761. png_write_gAMA_fixed(png_structp png_ptr, png_fixed_point file_gamma)
  177762. {
  177763. #ifdef PNG_USE_LOCAL_ARRAYS
  177764. PNG_gAMA;
  177765. #endif
  177766. png_byte buf[4];
  177767. png_debug(1, "in png_write_gAMA\n");
  177768. png_save_uint_32(buf, (png_uint_32)file_gamma);
  177769. png_write_chunk(png_ptr, png_gAMA, buf, (png_size_t)4);
  177770. }
  177771. #endif
  177772. #endif
  177773. #if defined(PNG_WRITE_sRGB_SUPPORTED)
  177774. void /* PRIVATE */
  177775. png_write_sRGB(png_structp png_ptr, int srgb_intent)
  177776. {
  177777. #ifdef PNG_USE_LOCAL_ARRAYS
  177778. PNG_sRGB;
  177779. #endif
  177780. png_byte buf[1];
  177781. png_debug(1, "in png_write_sRGB\n");
  177782. if(srgb_intent >= PNG_sRGB_INTENT_LAST)
  177783. png_warning(png_ptr,
  177784. "Invalid sRGB rendering intent specified");
  177785. buf[0]=(png_byte)srgb_intent;
  177786. png_write_chunk(png_ptr, png_sRGB, buf, (png_size_t)1);
  177787. }
  177788. #endif
  177789. #if defined(PNG_WRITE_iCCP_SUPPORTED)
  177790. void /* PRIVATE */
  177791. png_write_iCCP(png_structp png_ptr, png_charp name, int compression_type,
  177792. png_charp profile, int profile_len)
  177793. {
  177794. #ifdef PNG_USE_LOCAL_ARRAYS
  177795. PNG_iCCP;
  177796. #endif
  177797. png_size_t name_len;
  177798. png_charp new_name;
  177799. compression_state comp;
  177800. int embedded_profile_len = 0;
  177801. png_debug(1, "in png_write_iCCP\n");
  177802. comp.num_output_ptr = 0;
  177803. comp.max_output_ptr = 0;
  177804. comp.output_ptr = NULL;
  177805. comp.input = NULL;
  177806. comp.input_len = 0;
  177807. if (name == NULL || (name_len = png_check_keyword(png_ptr, name,
  177808. &new_name)) == 0)
  177809. {
  177810. png_warning(png_ptr, "Empty keyword in iCCP chunk");
  177811. return;
  177812. }
  177813. if (compression_type != PNG_COMPRESSION_TYPE_BASE)
  177814. png_warning(png_ptr, "Unknown compression type in iCCP chunk");
  177815. if (profile == NULL)
  177816. profile_len = 0;
  177817. if (profile_len > 3)
  177818. embedded_profile_len =
  177819. ((*( (png_bytep)profile ))<<24) |
  177820. ((*( (png_bytep)profile+1))<<16) |
  177821. ((*( (png_bytep)profile+2))<< 8) |
  177822. ((*( (png_bytep)profile+3)) );
  177823. if (profile_len < embedded_profile_len)
  177824. {
  177825. png_warning(png_ptr,
  177826. "Embedded profile length too large in iCCP chunk");
  177827. return;
  177828. }
  177829. if (profile_len > embedded_profile_len)
  177830. {
  177831. png_warning(png_ptr,
  177832. "Truncating profile to actual length in iCCP chunk");
  177833. profile_len = embedded_profile_len;
  177834. }
  177835. if (profile_len)
  177836. profile_len = png_text_compress(png_ptr, profile, (png_size_t)profile_len,
  177837. PNG_COMPRESSION_TYPE_BASE, &comp);
  177838. png_write_chunk_start(png_ptr, png_iCCP,
  177839. (png_uint_32)name_len+profile_len+2);
  177840. new_name[name_len+1]=0x00;
  177841. png_write_chunk_data(png_ptr, (png_bytep)new_name, name_len + 2);
  177842. if (profile_len)
  177843. png_write_compressed_data_out(png_ptr, &comp);
  177844. png_write_chunk_end(png_ptr);
  177845. png_free(png_ptr, new_name);
  177846. }
  177847. #endif
  177848. #if defined(PNG_WRITE_sPLT_SUPPORTED)
  177849. void /* PRIVATE */
  177850. png_write_sPLT(png_structp png_ptr, png_sPLT_tp spalette)
  177851. {
  177852. #ifdef PNG_USE_LOCAL_ARRAYS
  177853. PNG_sPLT;
  177854. #endif
  177855. png_size_t name_len;
  177856. png_charp new_name;
  177857. png_byte entrybuf[10];
  177858. int entry_size = (spalette->depth == 8 ? 6 : 10);
  177859. int palette_size = entry_size * spalette->nentries;
  177860. png_sPLT_entryp ep;
  177861. #ifdef PNG_NO_POINTER_INDEXING
  177862. int i;
  177863. #endif
  177864. png_debug(1, "in png_write_sPLT\n");
  177865. if (spalette->name == NULL || (name_len = png_check_keyword(png_ptr,
  177866. spalette->name, &new_name))==0)
  177867. {
  177868. png_warning(png_ptr, "Empty keyword in sPLT chunk");
  177869. return;
  177870. }
  177871. png_write_chunk_start(png_ptr, png_sPLT,
  177872. (png_uint_32)(name_len + 2 + palette_size));
  177873. png_write_chunk_data(png_ptr, (png_bytep)new_name, name_len + 1);
  177874. png_write_chunk_data(png_ptr, (png_bytep)&spalette->depth, 1);
  177875. #ifndef PNG_NO_POINTER_INDEXING
  177876. for (ep = spalette->entries; ep<spalette->entries+spalette->nentries; ep++)
  177877. {
  177878. if (spalette->depth == 8)
  177879. {
  177880. entrybuf[0] = (png_byte)ep->red;
  177881. entrybuf[1] = (png_byte)ep->green;
  177882. entrybuf[2] = (png_byte)ep->blue;
  177883. entrybuf[3] = (png_byte)ep->alpha;
  177884. png_save_uint_16(entrybuf + 4, ep->frequency);
  177885. }
  177886. else
  177887. {
  177888. png_save_uint_16(entrybuf + 0, ep->red);
  177889. png_save_uint_16(entrybuf + 2, ep->green);
  177890. png_save_uint_16(entrybuf + 4, ep->blue);
  177891. png_save_uint_16(entrybuf + 6, ep->alpha);
  177892. png_save_uint_16(entrybuf + 8, ep->frequency);
  177893. }
  177894. png_write_chunk_data(png_ptr, entrybuf, (png_size_t)entry_size);
  177895. }
  177896. #else
  177897. ep=spalette->entries;
  177898. for (i=0; i>spalette->nentries; i++)
  177899. {
  177900. if (spalette->depth == 8)
  177901. {
  177902. entrybuf[0] = (png_byte)ep[i].red;
  177903. entrybuf[1] = (png_byte)ep[i].green;
  177904. entrybuf[2] = (png_byte)ep[i].blue;
  177905. entrybuf[3] = (png_byte)ep[i].alpha;
  177906. png_save_uint_16(entrybuf + 4, ep[i].frequency);
  177907. }
  177908. else
  177909. {
  177910. png_save_uint_16(entrybuf + 0, ep[i].red);
  177911. png_save_uint_16(entrybuf + 2, ep[i].green);
  177912. png_save_uint_16(entrybuf + 4, ep[i].blue);
  177913. png_save_uint_16(entrybuf + 6, ep[i].alpha);
  177914. png_save_uint_16(entrybuf + 8, ep[i].frequency);
  177915. }
  177916. png_write_chunk_data(png_ptr, entrybuf, entry_size);
  177917. }
  177918. #endif
  177919. png_write_chunk_end(png_ptr);
  177920. png_free(png_ptr, new_name);
  177921. }
  177922. #endif
  177923. #if defined(PNG_WRITE_sBIT_SUPPORTED)
  177924. void /* PRIVATE */
  177925. png_write_sBIT(png_structp png_ptr, png_color_8p sbit, int color_type)
  177926. {
  177927. #ifdef PNG_USE_LOCAL_ARRAYS
  177928. PNG_sBIT;
  177929. #endif
  177930. png_byte buf[4];
  177931. png_size_t size;
  177932. png_debug(1, "in png_write_sBIT\n");
  177933. if (color_type & PNG_COLOR_MASK_COLOR)
  177934. {
  177935. png_byte maxbits;
  177936. maxbits = (png_byte)(color_type==PNG_COLOR_TYPE_PALETTE ? 8 :
  177937. png_ptr->usr_bit_depth);
  177938. if (sbit->red == 0 || sbit->red > maxbits ||
  177939. sbit->green == 0 || sbit->green > maxbits ||
  177940. sbit->blue == 0 || sbit->blue > maxbits)
  177941. {
  177942. png_warning(png_ptr, "Invalid sBIT depth specified");
  177943. return;
  177944. }
  177945. buf[0] = sbit->red;
  177946. buf[1] = sbit->green;
  177947. buf[2] = sbit->blue;
  177948. size = 3;
  177949. }
  177950. else
  177951. {
  177952. if (sbit->gray == 0 || sbit->gray > png_ptr->usr_bit_depth)
  177953. {
  177954. png_warning(png_ptr, "Invalid sBIT depth specified");
  177955. return;
  177956. }
  177957. buf[0] = sbit->gray;
  177958. size = 1;
  177959. }
  177960. if (color_type & PNG_COLOR_MASK_ALPHA)
  177961. {
  177962. if (sbit->alpha == 0 || sbit->alpha > png_ptr->usr_bit_depth)
  177963. {
  177964. png_warning(png_ptr, "Invalid sBIT depth specified");
  177965. return;
  177966. }
  177967. buf[size++] = sbit->alpha;
  177968. }
  177969. png_write_chunk(png_ptr, png_sBIT, buf, size);
  177970. }
  177971. #endif
  177972. #if defined(PNG_WRITE_cHRM_SUPPORTED)
  177973. #ifdef PNG_FLOATING_POINT_SUPPORTED
  177974. void /* PRIVATE */
  177975. png_write_cHRM(png_structp png_ptr, double white_x, double white_y,
  177976. double red_x, double red_y, double green_x, double green_y,
  177977. double blue_x, double blue_y)
  177978. {
  177979. #ifdef PNG_USE_LOCAL_ARRAYS
  177980. PNG_cHRM;
  177981. #endif
  177982. png_byte buf[32];
  177983. png_uint_32 itemp;
  177984. png_debug(1, "in png_write_cHRM\n");
  177985. if (white_x < 0 || white_x > 0.8 || white_y < 0 || white_y > 0.8 ||
  177986. white_x + white_y > 1.0)
  177987. {
  177988. png_warning(png_ptr, "Invalid cHRM white point specified");
  177989. #if !defined(PNG_NO_CONSOLE_IO)
  177990. fprintf(stderr,"white_x=%f, white_y=%f\n",white_x, white_y);
  177991. #endif
  177992. return;
  177993. }
  177994. itemp = (png_uint_32)(white_x * 100000.0 + 0.5);
  177995. png_save_uint_32(buf, itemp);
  177996. itemp = (png_uint_32)(white_y * 100000.0 + 0.5);
  177997. png_save_uint_32(buf + 4, itemp);
  177998. if (red_x < 0 || red_y < 0 || red_x + red_y > 1.0)
  177999. {
  178000. png_warning(png_ptr, "Invalid cHRM red point specified");
  178001. return;
  178002. }
  178003. itemp = (png_uint_32)(red_x * 100000.0 + 0.5);
  178004. png_save_uint_32(buf + 8, itemp);
  178005. itemp = (png_uint_32)(red_y * 100000.0 + 0.5);
  178006. png_save_uint_32(buf + 12, itemp);
  178007. if (green_x < 0 || green_y < 0 || green_x + green_y > 1.0)
  178008. {
  178009. png_warning(png_ptr, "Invalid cHRM green point specified");
  178010. return;
  178011. }
  178012. itemp = (png_uint_32)(green_x * 100000.0 + 0.5);
  178013. png_save_uint_32(buf + 16, itemp);
  178014. itemp = (png_uint_32)(green_y * 100000.0 + 0.5);
  178015. png_save_uint_32(buf + 20, itemp);
  178016. if (blue_x < 0 || blue_y < 0 || blue_x + blue_y > 1.0)
  178017. {
  178018. png_warning(png_ptr, "Invalid cHRM blue point specified");
  178019. return;
  178020. }
  178021. itemp = (png_uint_32)(blue_x * 100000.0 + 0.5);
  178022. png_save_uint_32(buf + 24, itemp);
  178023. itemp = (png_uint_32)(blue_y * 100000.0 + 0.5);
  178024. png_save_uint_32(buf + 28, itemp);
  178025. png_write_chunk(png_ptr, png_cHRM, buf, (png_size_t)32);
  178026. }
  178027. #endif
  178028. #ifdef PNG_FIXED_POINT_SUPPORTED
  178029. void /* PRIVATE */
  178030. png_write_cHRM_fixed(png_structp png_ptr, png_fixed_point white_x,
  178031. png_fixed_point white_y, png_fixed_point red_x, png_fixed_point red_y,
  178032. png_fixed_point green_x, png_fixed_point green_y, png_fixed_point blue_x,
  178033. png_fixed_point blue_y)
  178034. {
  178035. #ifdef PNG_USE_LOCAL_ARRAYS
  178036. PNG_cHRM;
  178037. #endif
  178038. png_byte buf[32];
  178039. png_debug(1, "in png_write_cHRM\n");
  178040. if (white_x > 80000L || white_y > 80000L || white_x + white_y > 100000L)
  178041. {
  178042. png_warning(png_ptr, "Invalid fixed cHRM white point specified");
  178043. #if !defined(PNG_NO_CONSOLE_IO)
  178044. fprintf(stderr,"white_x=%ld, white_y=%ld\n",white_x, white_y);
  178045. #endif
  178046. return;
  178047. }
  178048. png_save_uint_32(buf, (png_uint_32)white_x);
  178049. png_save_uint_32(buf + 4, (png_uint_32)white_y);
  178050. if (red_x + red_y > 100000L)
  178051. {
  178052. png_warning(png_ptr, "Invalid cHRM fixed red point specified");
  178053. return;
  178054. }
  178055. png_save_uint_32(buf + 8, (png_uint_32)red_x);
  178056. png_save_uint_32(buf + 12, (png_uint_32)red_y);
  178057. if (green_x + green_y > 100000L)
  178058. {
  178059. png_warning(png_ptr, "Invalid fixed cHRM green point specified");
  178060. return;
  178061. }
  178062. png_save_uint_32(buf + 16, (png_uint_32)green_x);
  178063. png_save_uint_32(buf + 20, (png_uint_32)green_y);
  178064. if (blue_x + blue_y > 100000L)
  178065. {
  178066. png_warning(png_ptr, "Invalid fixed cHRM blue point specified");
  178067. return;
  178068. }
  178069. png_save_uint_32(buf + 24, (png_uint_32)blue_x);
  178070. png_save_uint_32(buf + 28, (png_uint_32)blue_y);
  178071. png_write_chunk(png_ptr, png_cHRM, buf, (png_size_t)32);
  178072. }
  178073. #endif
  178074. #endif
  178075. #if defined(PNG_WRITE_tRNS_SUPPORTED)
  178076. void /* PRIVATE */
  178077. png_write_tRNS(png_structp png_ptr, png_bytep trans, png_color_16p tran,
  178078. int num_trans, int color_type)
  178079. {
  178080. #ifdef PNG_USE_LOCAL_ARRAYS
  178081. PNG_tRNS;
  178082. #endif
  178083. png_byte buf[6];
  178084. png_debug(1, "in png_write_tRNS\n");
  178085. if (color_type == PNG_COLOR_TYPE_PALETTE)
  178086. {
  178087. if (num_trans <= 0 || num_trans > (int)png_ptr->num_palette)
  178088. {
  178089. png_warning(png_ptr,"Invalid number of transparent colors specified");
  178090. return;
  178091. }
  178092. png_write_chunk(png_ptr, png_tRNS, trans, (png_size_t)num_trans);
  178093. }
  178094. else if (color_type == PNG_COLOR_TYPE_GRAY)
  178095. {
  178096. if(tran->gray >= (1 << png_ptr->bit_depth))
  178097. {
  178098. png_warning(png_ptr,
  178099. "Ignoring attempt to write tRNS chunk out-of-range for bit_depth");
  178100. return;
  178101. }
  178102. png_save_uint_16(buf, tran->gray);
  178103. png_write_chunk(png_ptr, png_tRNS, buf, (png_size_t)2);
  178104. }
  178105. else if (color_type == PNG_COLOR_TYPE_RGB)
  178106. {
  178107. png_save_uint_16(buf, tran->red);
  178108. png_save_uint_16(buf + 2, tran->green);
  178109. png_save_uint_16(buf + 4, tran->blue);
  178110. if(png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4]))
  178111. {
  178112. png_warning(png_ptr,
  178113. "Ignoring attempt to write 16-bit tRNS chunk when bit_depth is 8");
  178114. return;
  178115. }
  178116. png_write_chunk(png_ptr, png_tRNS, buf, (png_size_t)6);
  178117. }
  178118. else
  178119. {
  178120. png_warning(png_ptr, "Can't write tRNS with an alpha channel");
  178121. }
  178122. }
  178123. #endif
  178124. #if defined(PNG_WRITE_bKGD_SUPPORTED)
  178125. void /* PRIVATE */
  178126. png_write_bKGD(png_structp png_ptr, png_color_16p back, int color_type)
  178127. {
  178128. #ifdef PNG_USE_LOCAL_ARRAYS
  178129. PNG_bKGD;
  178130. #endif
  178131. png_byte buf[6];
  178132. png_debug(1, "in png_write_bKGD\n");
  178133. if (color_type == PNG_COLOR_TYPE_PALETTE)
  178134. {
  178135. if (
  178136. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  178137. (png_ptr->num_palette ||
  178138. (!(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE))) &&
  178139. #endif
  178140. back->index > png_ptr->num_palette)
  178141. {
  178142. png_warning(png_ptr, "Invalid background palette index");
  178143. return;
  178144. }
  178145. buf[0] = back->index;
  178146. png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)1);
  178147. }
  178148. else if (color_type & PNG_COLOR_MASK_COLOR)
  178149. {
  178150. png_save_uint_16(buf, back->red);
  178151. png_save_uint_16(buf + 2, back->green);
  178152. png_save_uint_16(buf + 4, back->blue);
  178153. if(png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4]))
  178154. {
  178155. png_warning(png_ptr,
  178156. "Ignoring attempt to write 16-bit bKGD chunk when bit_depth is 8");
  178157. return;
  178158. }
  178159. png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)6);
  178160. }
  178161. else
  178162. {
  178163. if(back->gray >= (1 << png_ptr->bit_depth))
  178164. {
  178165. png_warning(png_ptr,
  178166. "Ignoring attempt to write bKGD chunk out-of-range for bit_depth");
  178167. return;
  178168. }
  178169. png_save_uint_16(buf, back->gray);
  178170. png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)2);
  178171. }
  178172. }
  178173. #endif
  178174. #if defined(PNG_WRITE_hIST_SUPPORTED)
  178175. void /* PRIVATE */
  178176. png_write_hIST(png_structp png_ptr, png_uint_16p hist, int num_hist)
  178177. {
  178178. #ifdef PNG_USE_LOCAL_ARRAYS
  178179. PNG_hIST;
  178180. #endif
  178181. int i;
  178182. png_byte buf[3];
  178183. png_debug(1, "in png_write_hIST\n");
  178184. if (num_hist > (int)png_ptr->num_palette)
  178185. {
  178186. png_debug2(3, "num_hist = %d, num_palette = %d\n", num_hist,
  178187. png_ptr->num_palette);
  178188. png_warning(png_ptr, "Invalid number of histogram entries specified");
  178189. return;
  178190. }
  178191. png_write_chunk_start(png_ptr, png_hIST, (png_uint_32)(num_hist * 2));
  178192. for (i = 0; i < num_hist; i++)
  178193. {
  178194. png_save_uint_16(buf, hist[i]);
  178195. png_write_chunk_data(png_ptr, buf, (png_size_t)2);
  178196. }
  178197. png_write_chunk_end(png_ptr);
  178198. }
  178199. #endif
  178200. #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_pCAL_SUPPORTED) || \
  178201. defined(PNG_WRITE_iCCP_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED)
  178202. png_size_t /* PRIVATE */
  178203. png_check_keyword(png_structp png_ptr, png_charp key, png_charpp new_key)
  178204. {
  178205. png_size_t key_len;
  178206. png_charp kp, dp;
  178207. int kflag;
  178208. int kwarn=0;
  178209. png_debug(1, "in png_check_keyword\n");
  178210. *new_key = NULL;
  178211. if (key == NULL || (key_len = png_strlen(key)) == 0)
  178212. {
  178213. png_warning(png_ptr, "zero length keyword");
  178214. return ((png_size_t)0);
  178215. }
  178216. png_debug1(2, "Keyword to be checked is '%s'\n", key);
  178217. *new_key = (png_charp)png_malloc_warn(png_ptr, (png_uint_32)(key_len + 2));
  178218. if (*new_key == NULL)
  178219. {
  178220. png_warning(png_ptr, "Out of memory while procesing keyword");
  178221. return ((png_size_t)0);
  178222. }
  178223. for (kp = key, dp = *new_key; *kp != '\0'; kp++, dp++)
  178224. {
  178225. if ((png_byte)*kp < 0x20 ||
  178226. ((png_byte)*kp > 0x7E && (png_byte)*kp < 0xA1))
  178227. {
  178228. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  178229. char msg[40];
  178230. png_snprintf(msg, 40,
  178231. "invalid keyword character 0x%02X", (png_byte)*kp);
  178232. png_warning(png_ptr, msg);
  178233. #else
  178234. png_warning(png_ptr, "invalid character in keyword");
  178235. #endif
  178236. *dp = ' ';
  178237. }
  178238. else
  178239. {
  178240. *dp = *kp;
  178241. }
  178242. }
  178243. *dp = '\0';
  178244. kp = *new_key + key_len - 1;
  178245. if (*kp == ' ')
  178246. {
  178247. png_warning(png_ptr, "trailing spaces removed from keyword");
  178248. while (*kp == ' ')
  178249. {
  178250. *(kp--) = '\0';
  178251. key_len--;
  178252. }
  178253. }
  178254. kp = *new_key;
  178255. if (*kp == ' ')
  178256. {
  178257. png_warning(png_ptr, "leading spaces removed from keyword");
  178258. while (*kp == ' ')
  178259. {
  178260. kp++;
  178261. key_len--;
  178262. }
  178263. }
  178264. png_debug1(2, "Checking for multiple internal spaces in '%s'\n", kp);
  178265. for (kflag = 0, dp = *new_key; *kp != '\0'; kp++)
  178266. {
  178267. if (*kp == ' ' && kflag == 0)
  178268. {
  178269. *(dp++) = *kp;
  178270. kflag = 1;
  178271. }
  178272. else if (*kp == ' ')
  178273. {
  178274. key_len--;
  178275. kwarn=1;
  178276. }
  178277. else
  178278. {
  178279. *(dp++) = *kp;
  178280. kflag = 0;
  178281. }
  178282. }
  178283. *dp = '\0';
  178284. if(kwarn)
  178285. png_warning(png_ptr, "extra interior spaces removed from keyword");
  178286. if (key_len == 0)
  178287. {
  178288. png_free(png_ptr, *new_key);
  178289. *new_key=NULL;
  178290. png_warning(png_ptr, "Zero length keyword");
  178291. }
  178292. if (key_len > 79)
  178293. {
  178294. png_warning(png_ptr, "keyword length must be 1 - 79 characters");
  178295. new_key[79] = '\0';
  178296. key_len = 79;
  178297. }
  178298. return (key_len);
  178299. }
  178300. #endif
  178301. #if defined(PNG_WRITE_tEXt_SUPPORTED)
  178302. void /* PRIVATE */
  178303. png_write_tEXt(png_structp png_ptr, png_charp key, png_charp text,
  178304. png_size_t text_len)
  178305. {
  178306. #ifdef PNG_USE_LOCAL_ARRAYS
  178307. PNG_tEXt;
  178308. #endif
  178309. png_size_t key_len;
  178310. png_charp new_key;
  178311. png_debug(1, "in png_write_tEXt\n");
  178312. if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0)
  178313. {
  178314. png_warning(png_ptr, "Empty keyword in tEXt chunk");
  178315. return;
  178316. }
  178317. if (text == NULL || *text == '\0')
  178318. text_len = 0;
  178319. else
  178320. text_len = png_strlen(text);
  178321. png_write_chunk_start(png_ptr, png_tEXt, (png_uint_32)key_len+text_len+1);
  178322. png_write_chunk_data(png_ptr, (png_bytep)new_key, key_len + 1);
  178323. if (text_len)
  178324. png_write_chunk_data(png_ptr, (png_bytep)text, text_len);
  178325. png_write_chunk_end(png_ptr);
  178326. png_free(png_ptr, new_key);
  178327. }
  178328. #endif
  178329. #if defined(PNG_WRITE_zTXt_SUPPORTED)
  178330. void /* PRIVATE */
  178331. png_write_zTXt(png_structp png_ptr, png_charp key, png_charp text,
  178332. png_size_t text_len, int compression)
  178333. {
  178334. #ifdef PNG_USE_LOCAL_ARRAYS
  178335. PNG_zTXt;
  178336. #endif
  178337. png_size_t key_len;
  178338. char buf[1];
  178339. png_charp new_key;
  178340. compression_state comp;
  178341. png_debug(1, "in png_write_zTXt\n");
  178342. comp.num_output_ptr = 0;
  178343. comp.max_output_ptr = 0;
  178344. comp.output_ptr = NULL;
  178345. comp.input = NULL;
  178346. comp.input_len = 0;
  178347. if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0)
  178348. {
  178349. png_warning(png_ptr, "Empty keyword in zTXt chunk");
  178350. return;
  178351. }
  178352. if (text == NULL || *text == '\0' || compression==PNG_TEXT_COMPRESSION_NONE)
  178353. {
  178354. png_write_tEXt(png_ptr, new_key, text, (png_size_t)0);
  178355. png_free(png_ptr, new_key);
  178356. return;
  178357. }
  178358. text_len = png_strlen(text);
  178359. text_len = png_text_compress(png_ptr, text, text_len, compression,
  178360. &comp);
  178361. png_write_chunk_start(png_ptr, png_zTXt, (png_uint_32)
  178362. (key_len+text_len+2));
  178363. png_write_chunk_data(png_ptr, (png_bytep)new_key, key_len + 1);
  178364. png_free(png_ptr, new_key);
  178365. buf[0] = (png_byte)compression;
  178366. png_write_chunk_data(png_ptr, (png_bytep)buf, (png_size_t)1);
  178367. png_write_compressed_data_out(png_ptr, &comp);
  178368. png_write_chunk_end(png_ptr);
  178369. }
  178370. #endif
  178371. #if defined(PNG_WRITE_iTXt_SUPPORTED)
  178372. void /* PRIVATE */
  178373. png_write_iTXt(png_structp png_ptr, int compression, png_charp key,
  178374. png_charp lang, png_charp lang_key, png_charp text)
  178375. {
  178376. #ifdef PNG_USE_LOCAL_ARRAYS
  178377. PNG_iTXt;
  178378. #endif
  178379. png_size_t lang_len, key_len, lang_key_len, text_len;
  178380. png_charp new_lang, new_key;
  178381. png_byte cbuf[2];
  178382. compression_state comp;
  178383. png_debug(1, "in png_write_iTXt\n");
  178384. comp.num_output_ptr = 0;
  178385. comp.max_output_ptr = 0;
  178386. comp.output_ptr = NULL;
  178387. comp.input = NULL;
  178388. if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0)
  178389. {
  178390. png_warning(png_ptr, "Empty keyword in iTXt chunk");
  178391. return;
  178392. }
  178393. if (lang == NULL || (lang_len = png_check_keyword(png_ptr, lang, &new_lang))==0)
  178394. {
  178395. png_warning(png_ptr, "Empty language field in iTXt chunk");
  178396. new_lang = NULL;
  178397. lang_len = 0;
  178398. }
  178399. if (lang_key == NULL)
  178400. lang_key_len = 0;
  178401. else
  178402. lang_key_len = png_strlen(lang_key);
  178403. if (text == NULL)
  178404. text_len = 0;
  178405. else
  178406. text_len = png_strlen(text);
  178407. text_len = png_text_compress(png_ptr, text, text_len, compression-2,
  178408. &comp);
  178409. png_write_chunk_start(png_ptr, png_iTXt,
  178410. (png_uint_32)(
  178411. 5 /* comp byte, comp flag, terminators for key, lang and lang_key */
  178412. + key_len
  178413. + lang_len
  178414. + lang_key_len
  178415. + text_len));
  178416. png_write_chunk_data(png_ptr, (png_bytep)new_key, key_len + 1);
  178417. if (compression == PNG_ITXT_COMPRESSION_NONE || \
  178418. compression == PNG_TEXT_COMPRESSION_NONE)
  178419. cbuf[0] = 0;
  178420. else /* compression == PNG_ITXT_COMPRESSION_zTXt */
  178421. cbuf[0] = 1;
  178422. cbuf[1] = 0;
  178423. png_write_chunk_data(png_ptr, cbuf, 2);
  178424. cbuf[0] = 0;
  178425. png_write_chunk_data(png_ptr, (new_lang ? (png_bytep)new_lang : cbuf), lang_len + 1);
  178426. png_write_chunk_data(png_ptr, (lang_key ? (png_bytep)lang_key : cbuf), lang_key_len + 1);
  178427. png_write_compressed_data_out(png_ptr, &comp);
  178428. png_write_chunk_end(png_ptr);
  178429. png_free(png_ptr, new_key);
  178430. if (new_lang)
  178431. png_free(png_ptr, new_lang);
  178432. }
  178433. #endif
  178434. #if defined(PNG_WRITE_oFFs_SUPPORTED)
  178435. void /* PRIVATE */
  178436. png_write_oFFs(png_structp png_ptr, png_int_32 x_offset, png_int_32 y_offset,
  178437. int unit_type)
  178438. {
  178439. #ifdef PNG_USE_LOCAL_ARRAYS
  178440. PNG_oFFs;
  178441. #endif
  178442. png_byte buf[9];
  178443. png_debug(1, "in png_write_oFFs\n");
  178444. if (unit_type >= PNG_OFFSET_LAST)
  178445. png_warning(png_ptr, "Unrecognized unit type for oFFs chunk");
  178446. png_save_int_32(buf, x_offset);
  178447. png_save_int_32(buf + 4, y_offset);
  178448. buf[8] = (png_byte)unit_type;
  178449. png_write_chunk(png_ptr, png_oFFs, buf, (png_size_t)9);
  178450. }
  178451. #endif
  178452. #if defined(PNG_WRITE_pCAL_SUPPORTED)
  178453. void /* PRIVATE */
  178454. png_write_pCAL(png_structp png_ptr, png_charp purpose, png_int_32 X0,
  178455. png_int_32 X1, int type, int nparams, png_charp units, png_charpp params)
  178456. {
  178457. #ifdef PNG_USE_LOCAL_ARRAYS
  178458. PNG_pCAL;
  178459. #endif
  178460. png_size_t purpose_len, units_len, total_len;
  178461. png_uint_32p params_len;
  178462. png_byte buf[10];
  178463. png_charp new_purpose;
  178464. int i;
  178465. png_debug1(1, "in png_write_pCAL (%d parameters)\n", nparams);
  178466. if (type >= PNG_EQUATION_LAST)
  178467. png_warning(png_ptr, "Unrecognized equation type for pCAL chunk");
  178468. purpose_len = png_check_keyword(png_ptr, purpose, &new_purpose) + 1;
  178469. png_debug1(3, "pCAL purpose length = %d\n", (int)purpose_len);
  178470. units_len = png_strlen(units) + (nparams == 0 ? 0 : 1);
  178471. png_debug1(3, "pCAL units length = %d\n", (int)units_len);
  178472. total_len = purpose_len + units_len + 10;
  178473. params_len = (png_uint_32p)png_malloc(png_ptr, (png_uint_32)(nparams
  178474. *png_sizeof(png_uint_32)));
  178475. for (i = 0; i < nparams; i++)
  178476. {
  178477. params_len[i] = png_strlen(params[i]) + (i == nparams - 1 ? 0 : 1);
  178478. png_debug2(3, "pCAL parameter %d length = %lu\n", i, params_len[i]);
  178479. total_len += (png_size_t)params_len[i];
  178480. }
  178481. png_debug1(3, "pCAL total length = %d\n", (int)total_len);
  178482. png_write_chunk_start(png_ptr, png_pCAL, (png_uint_32)total_len);
  178483. png_write_chunk_data(png_ptr, (png_bytep)new_purpose, purpose_len);
  178484. png_save_int_32(buf, X0);
  178485. png_save_int_32(buf + 4, X1);
  178486. buf[8] = (png_byte)type;
  178487. buf[9] = (png_byte)nparams;
  178488. png_write_chunk_data(png_ptr, buf, (png_size_t)10);
  178489. png_write_chunk_data(png_ptr, (png_bytep)units, (png_size_t)units_len);
  178490. png_free(png_ptr, new_purpose);
  178491. for (i = 0; i < nparams; i++)
  178492. {
  178493. png_write_chunk_data(png_ptr, (png_bytep)params[i],
  178494. (png_size_t)params_len[i]);
  178495. }
  178496. png_free(png_ptr, params_len);
  178497. png_write_chunk_end(png_ptr);
  178498. }
  178499. #endif
  178500. #if defined(PNG_WRITE_sCAL_SUPPORTED)
  178501. #if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO)
  178502. void /* PRIVATE */
  178503. png_write_sCAL(png_structp png_ptr, int unit, double width, double height)
  178504. {
  178505. #ifdef PNG_USE_LOCAL_ARRAYS
  178506. PNG_sCAL;
  178507. #endif
  178508. char buf[64];
  178509. png_size_t total_len;
  178510. png_debug(1, "in png_write_sCAL\n");
  178511. buf[0] = (char)unit;
  178512. #if defined(_WIN32_WCE)
  178513. {
  178514. wchar_t wc_buf[32];
  178515. size_t wc_len;
  178516. swprintf(wc_buf, TEXT("%12.12e"), width);
  178517. wc_len = wcslen(wc_buf);
  178518. WideCharToMultiByte(CP_ACP, 0, wc_buf, -1, buf + 1, wc_len, NULL, NULL);
  178519. total_len = wc_len + 2;
  178520. swprintf(wc_buf, TEXT("%12.12e"), height);
  178521. wc_len = wcslen(wc_buf);
  178522. WideCharToMultiByte(CP_ACP, 0, wc_buf, -1, buf + total_len, wc_len,
  178523. NULL, NULL);
  178524. total_len += wc_len;
  178525. }
  178526. #else
  178527. png_snprintf(buf + 1, 63, "%12.12e", width);
  178528. total_len = 1 + png_strlen(buf + 1) + 1;
  178529. png_snprintf(buf + total_len, 64-total_len, "%12.12e", height);
  178530. total_len += png_strlen(buf + total_len);
  178531. #endif
  178532. png_debug1(3, "sCAL total length = %u\n", (unsigned int)total_len);
  178533. png_write_chunk(png_ptr, png_sCAL, (png_bytep)buf, total_len);
  178534. }
  178535. #else
  178536. #ifdef PNG_FIXED_POINT_SUPPORTED
  178537. void /* PRIVATE */
  178538. png_write_sCAL_s(png_structp png_ptr, int unit, png_charp width,
  178539. png_charp height)
  178540. {
  178541. #ifdef PNG_USE_LOCAL_ARRAYS
  178542. PNG_sCAL;
  178543. #endif
  178544. png_byte buf[64];
  178545. png_size_t wlen, hlen, total_len;
  178546. png_debug(1, "in png_write_sCAL_s\n");
  178547. wlen = png_strlen(width);
  178548. hlen = png_strlen(height);
  178549. total_len = wlen + hlen + 2;
  178550. if (total_len > 64)
  178551. {
  178552. png_warning(png_ptr, "Can't write sCAL (buffer too small)");
  178553. return;
  178554. }
  178555. buf[0] = (png_byte)unit;
  178556. png_memcpy(buf + 1, width, wlen + 1); /* append the '\0' here */
  178557. png_memcpy(buf + wlen + 2, height, hlen); /* do NOT append the '\0' here */
  178558. png_debug1(3, "sCAL total length = %u\n", (unsigned int)total_len);
  178559. png_write_chunk(png_ptr, png_sCAL, buf, total_len);
  178560. }
  178561. #endif
  178562. #endif
  178563. #endif
  178564. #if defined(PNG_WRITE_pHYs_SUPPORTED)
  178565. void /* PRIVATE */
  178566. png_write_pHYs(png_structp png_ptr, png_uint_32 x_pixels_per_unit,
  178567. png_uint_32 y_pixels_per_unit,
  178568. int unit_type)
  178569. {
  178570. #ifdef PNG_USE_LOCAL_ARRAYS
  178571. PNG_pHYs;
  178572. #endif
  178573. png_byte buf[9];
  178574. png_debug(1, "in png_write_pHYs\n");
  178575. if (unit_type >= PNG_RESOLUTION_LAST)
  178576. png_warning(png_ptr, "Unrecognized unit type for pHYs chunk");
  178577. png_save_uint_32(buf, x_pixels_per_unit);
  178578. png_save_uint_32(buf + 4, y_pixels_per_unit);
  178579. buf[8] = (png_byte)unit_type;
  178580. png_write_chunk(png_ptr, png_pHYs, buf, (png_size_t)9);
  178581. }
  178582. #endif
  178583. #if defined(PNG_WRITE_tIME_SUPPORTED)
  178584. void /* PRIVATE */
  178585. png_write_tIME(png_structp png_ptr, png_timep mod_time)
  178586. {
  178587. #ifdef PNG_USE_LOCAL_ARRAYS
  178588. PNG_tIME;
  178589. #endif
  178590. png_byte buf[7];
  178591. png_debug(1, "in png_write_tIME\n");
  178592. if (mod_time->month > 12 || mod_time->month < 1 ||
  178593. mod_time->day > 31 || mod_time->day < 1 ||
  178594. mod_time->hour > 23 || mod_time->second > 60)
  178595. {
  178596. png_warning(png_ptr, "Invalid time specified for tIME chunk");
  178597. return;
  178598. }
  178599. png_save_uint_16(buf, mod_time->year);
  178600. buf[2] = mod_time->month;
  178601. buf[3] = mod_time->day;
  178602. buf[4] = mod_time->hour;
  178603. buf[5] = mod_time->minute;
  178604. buf[6] = mod_time->second;
  178605. png_write_chunk(png_ptr, png_tIME, buf, (png_size_t)7);
  178606. }
  178607. #endif
  178608. void /* PRIVATE */
  178609. png_write_start_row(png_structp png_ptr)
  178610. {
  178611. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  178612. #ifdef PNG_USE_LOCAL_ARRAYS
  178613. int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  178614. int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  178615. int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
  178616. int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
  178617. #endif
  178618. #endif
  178619. png_size_t buf_size;
  178620. png_debug(1, "in png_write_start_row\n");
  178621. buf_size = (png_size_t)(PNG_ROWBYTES(
  178622. png_ptr->usr_channels*png_ptr->usr_bit_depth,png_ptr->width)+1);
  178623. png_ptr->row_buf = (png_bytep)png_malloc(png_ptr, (png_uint_32)buf_size);
  178624. png_ptr->row_buf[0] = PNG_FILTER_VALUE_NONE;
  178625. #ifndef PNG_NO_WRITE_FILTERING
  178626. if (png_ptr->do_filter & PNG_FILTER_SUB)
  178627. {
  178628. png_ptr->sub_row = (png_bytep)png_malloc(png_ptr,
  178629. (png_ptr->rowbytes + 1));
  178630. png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB;
  178631. }
  178632. if (png_ptr->do_filter & (PNG_FILTER_AVG | PNG_FILTER_UP | PNG_FILTER_PAETH))
  178633. {
  178634. png_ptr->prev_row = (png_bytep)png_malloc(png_ptr, (png_uint_32)buf_size);
  178635. png_memset(png_ptr->prev_row, 0, buf_size);
  178636. if (png_ptr->do_filter & PNG_FILTER_UP)
  178637. {
  178638. png_ptr->up_row = (png_bytep)png_malloc(png_ptr,
  178639. (png_ptr->rowbytes + 1));
  178640. png_ptr->up_row[0] = PNG_FILTER_VALUE_UP;
  178641. }
  178642. if (png_ptr->do_filter & PNG_FILTER_AVG)
  178643. {
  178644. png_ptr->avg_row = (png_bytep)png_malloc(png_ptr,
  178645. (png_ptr->rowbytes + 1));
  178646. png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG;
  178647. }
  178648. if (png_ptr->do_filter & PNG_FILTER_PAETH)
  178649. {
  178650. png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr,
  178651. (png_ptr->rowbytes + 1));
  178652. png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH;
  178653. }
  178654. #endif /* PNG_NO_WRITE_FILTERING */
  178655. }
  178656. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  178657. if (png_ptr->interlaced)
  178658. {
  178659. if (!(png_ptr->transformations & PNG_INTERLACE))
  178660. {
  178661. png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 -
  178662. png_pass_ystart[0]) / png_pass_yinc[0];
  178663. png_ptr->usr_width = (png_ptr->width + png_pass_inc[0] - 1 -
  178664. png_pass_start[0]) / png_pass_inc[0];
  178665. }
  178666. else
  178667. {
  178668. png_ptr->num_rows = png_ptr->height;
  178669. png_ptr->usr_width = png_ptr->width;
  178670. }
  178671. }
  178672. else
  178673. #endif
  178674. {
  178675. png_ptr->num_rows = png_ptr->height;
  178676. png_ptr->usr_width = png_ptr->width;
  178677. }
  178678. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  178679. png_ptr->zstream.next_out = png_ptr->zbuf;
  178680. }
  178681. void /* PRIVATE */
  178682. png_write_finish_row(png_structp png_ptr)
  178683. {
  178684. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  178685. #ifdef PNG_USE_LOCAL_ARRAYS
  178686. int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  178687. int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  178688. int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
  178689. int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
  178690. #endif
  178691. #endif
  178692. int ret;
  178693. png_debug(1, "in png_write_finish_row\n");
  178694. png_ptr->row_number++;
  178695. if (png_ptr->row_number < png_ptr->num_rows)
  178696. return;
  178697. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  178698. if (png_ptr->interlaced)
  178699. {
  178700. png_ptr->row_number = 0;
  178701. if (png_ptr->transformations & PNG_INTERLACE)
  178702. {
  178703. png_ptr->pass++;
  178704. }
  178705. else
  178706. {
  178707. do
  178708. {
  178709. png_ptr->pass++;
  178710. if (png_ptr->pass >= 7)
  178711. break;
  178712. png_ptr->usr_width = (png_ptr->width +
  178713. png_pass_inc[png_ptr->pass] - 1 -
  178714. png_pass_start[png_ptr->pass]) /
  178715. png_pass_inc[png_ptr->pass];
  178716. png_ptr->num_rows = (png_ptr->height +
  178717. png_pass_yinc[png_ptr->pass] - 1 -
  178718. png_pass_ystart[png_ptr->pass]) /
  178719. png_pass_yinc[png_ptr->pass];
  178720. if (png_ptr->transformations & PNG_INTERLACE)
  178721. break;
  178722. } while (png_ptr->usr_width == 0 || png_ptr->num_rows == 0);
  178723. }
  178724. if (png_ptr->pass < 7)
  178725. {
  178726. if (png_ptr->prev_row != NULL)
  178727. png_memset(png_ptr->prev_row, 0,
  178728. (png_size_t)(PNG_ROWBYTES(png_ptr->usr_channels*
  178729. png_ptr->usr_bit_depth,png_ptr->width))+1);
  178730. return;
  178731. }
  178732. }
  178733. #endif
  178734. do
  178735. {
  178736. ret = deflate(&png_ptr->zstream, Z_FINISH);
  178737. if (ret == Z_OK)
  178738. {
  178739. if (!(png_ptr->zstream.avail_out))
  178740. {
  178741. png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
  178742. png_ptr->zstream.next_out = png_ptr->zbuf;
  178743. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  178744. }
  178745. }
  178746. else if (ret != Z_STREAM_END)
  178747. {
  178748. if (png_ptr->zstream.msg != NULL)
  178749. png_error(png_ptr, png_ptr->zstream.msg);
  178750. else
  178751. png_error(png_ptr, "zlib error");
  178752. }
  178753. } while (ret != Z_STREAM_END);
  178754. if (png_ptr->zstream.avail_out < png_ptr->zbuf_size)
  178755. {
  178756. png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size -
  178757. png_ptr->zstream.avail_out);
  178758. }
  178759. deflateReset(&png_ptr->zstream);
  178760. png_ptr->zstream.data_type = Z_BINARY;
  178761. }
  178762. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  178763. void /* PRIVATE */
  178764. png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass)
  178765. {
  178766. #ifdef PNG_USE_LOCAL_ARRAYS
  178767. int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  178768. int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  178769. #endif
  178770. png_debug(1, "in png_do_write_interlace\n");
  178771. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  178772. if (row != NULL && row_info != NULL && pass < 6)
  178773. #else
  178774. if (pass < 6)
  178775. #endif
  178776. {
  178777. switch (row_info->pixel_depth)
  178778. {
  178779. case 1:
  178780. {
  178781. png_bytep sp;
  178782. png_bytep dp;
  178783. int shift;
  178784. int d;
  178785. int value;
  178786. png_uint_32 i;
  178787. png_uint_32 row_width = row_info->width;
  178788. dp = row;
  178789. d = 0;
  178790. shift = 7;
  178791. for (i = png_pass_start[pass]; i < row_width;
  178792. i += png_pass_inc[pass])
  178793. {
  178794. sp = row + (png_size_t)(i >> 3);
  178795. value = (int)(*sp >> (7 - (int)(i & 0x07))) & 0x01;
  178796. d |= (value << shift);
  178797. if (shift == 0)
  178798. {
  178799. shift = 7;
  178800. *dp++ = (png_byte)d;
  178801. d = 0;
  178802. }
  178803. else
  178804. shift--;
  178805. }
  178806. if (shift != 7)
  178807. *dp = (png_byte)d;
  178808. break;
  178809. }
  178810. case 2:
  178811. {
  178812. png_bytep sp;
  178813. png_bytep dp;
  178814. int shift;
  178815. int d;
  178816. int value;
  178817. png_uint_32 i;
  178818. png_uint_32 row_width = row_info->width;
  178819. dp = row;
  178820. shift = 6;
  178821. d = 0;
  178822. for (i = png_pass_start[pass]; i < row_width;
  178823. i += png_pass_inc[pass])
  178824. {
  178825. sp = row + (png_size_t)(i >> 2);
  178826. value = (*sp >> ((3 - (int)(i & 0x03)) << 1)) & 0x03;
  178827. d |= (value << shift);
  178828. if (shift == 0)
  178829. {
  178830. shift = 6;
  178831. *dp++ = (png_byte)d;
  178832. d = 0;
  178833. }
  178834. else
  178835. shift -= 2;
  178836. }
  178837. if (shift != 6)
  178838. *dp = (png_byte)d;
  178839. break;
  178840. }
  178841. case 4:
  178842. {
  178843. png_bytep sp;
  178844. png_bytep dp;
  178845. int shift;
  178846. int d;
  178847. int value;
  178848. png_uint_32 i;
  178849. png_uint_32 row_width = row_info->width;
  178850. dp = row;
  178851. shift = 4;
  178852. d = 0;
  178853. for (i = png_pass_start[pass]; i < row_width;
  178854. i += png_pass_inc[pass])
  178855. {
  178856. sp = row + (png_size_t)(i >> 1);
  178857. value = (*sp >> ((1 - (int)(i & 0x01)) << 2)) & 0x0f;
  178858. d |= (value << shift);
  178859. if (shift == 0)
  178860. {
  178861. shift = 4;
  178862. *dp++ = (png_byte)d;
  178863. d = 0;
  178864. }
  178865. else
  178866. shift -= 4;
  178867. }
  178868. if (shift != 4)
  178869. *dp = (png_byte)d;
  178870. break;
  178871. }
  178872. default:
  178873. {
  178874. png_bytep sp;
  178875. png_bytep dp;
  178876. png_uint_32 i;
  178877. png_uint_32 row_width = row_info->width;
  178878. png_size_t pixel_bytes;
  178879. dp = row;
  178880. pixel_bytes = (row_info->pixel_depth >> 3);
  178881. for (i = png_pass_start[pass]; i < row_width;
  178882. i += png_pass_inc[pass])
  178883. {
  178884. sp = row + (png_size_t)i * pixel_bytes;
  178885. if (dp != sp)
  178886. png_memcpy(dp, sp, pixel_bytes);
  178887. dp += pixel_bytes;
  178888. }
  178889. break;
  178890. }
  178891. }
  178892. row_info->width = (row_info->width +
  178893. png_pass_inc[pass] - 1 -
  178894. png_pass_start[pass]) /
  178895. png_pass_inc[pass];
  178896. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
  178897. row_info->width);
  178898. }
  178899. }
  178900. #endif
  178901. #define PNG_MAXSUM (((png_uint_32)(-1)) >> 1)
  178902. #define PNG_HISHIFT 10
  178903. #define PNG_LOMASK ((png_uint_32)0xffffL)
  178904. #define PNG_HIMASK ((png_uint_32)(~PNG_LOMASK >> PNG_HISHIFT))
  178905. void /* PRIVATE */
  178906. png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
  178907. {
  178908. png_bytep best_row;
  178909. #ifndef PNG_NO_WRITE_FILTER
  178910. png_bytep prev_row, row_buf;
  178911. png_uint_32 mins, bpp;
  178912. png_byte filter_to_do = png_ptr->do_filter;
  178913. png_uint_32 row_bytes = row_info->rowbytes;
  178914. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178915. int num_p_filters = (int)png_ptr->num_prev_filters;
  178916. #endif
  178917. png_debug(1, "in png_write_find_filter\n");
  178918. bpp = (row_info->pixel_depth + 7) >> 3;
  178919. prev_row = png_ptr->prev_row;
  178920. #endif
  178921. best_row = png_ptr->row_buf;
  178922. #ifndef PNG_NO_WRITE_FILTER
  178923. row_buf = best_row;
  178924. mins = PNG_MAXSUM;
  178925. if ((filter_to_do & PNG_FILTER_NONE) &&
  178926. filter_to_do != PNG_FILTER_NONE)
  178927. {
  178928. png_bytep rp;
  178929. png_uint_32 sum = 0;
  178930. png_uint_32 i;
  178931. int v;
  178932. for (i = 0, rp = row_buf + 1; i < row_bytes; i++, rp++)
  178933. {
  178934. v = *rp;
  178935. sum += (v < 128) ? v : 256 - v;
  178936. }
  178937. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178938. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178939. {
  178940. png_uint_32 sumhi, sumlo;
  178941. int j;
  178942. sumlo = sum & PNG_LOMASK;
  178943. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK; /* Gives us some footroom */
  178944. for (j = 0; j < num_p_filters; j++)
  178945. {
  178946. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_NONE)
  178947. {
  178948. sumlo = (sumlo * png_ptr->filter_weights[j]) >>
  178949. PNG_WEIGHT_SHIFT;
  178950. sumhi = (sumhi * png_ptr->filter_weights[j]) >>
  178951. PNG_WEIGHT_SHIFT;
  178952. }
  178953. }
  178954. sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_NONE]) >>
  178955. PNG_COST_SHIFT;
  178956. sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_NONE]) >>
  178957. PNG_COST_SHIFT;
  178958. if (sumhi > PNG_HIMASK)
  178959. sum = PNG_MAXSUM;
  178960. else
  178961. sum = (sumhi << PNG_HISHIFT) + sumlo;
  178962. }
  178963. #endif
  178964. mins = sum;
  178965. }
  178966. if (filter_to_do == PNG_FILTER_SUB)
  178967. {
  178968. png_bytep rp, lp, dp;
  178969. png_uint_32 i;
  178970. for (i = 0, rp = row_buf + 1, dp = png_ptr->sub_row + 1; i < bpp;
  178971. i++, rp++, dp++)
  178972. {
  178973. *dp = *rp;
  178974. }
  178975. for (lp = row_buf + 1; i < row_bytes;
  178976. i++, rp++, lp++, dp++)
  178977. {
  178978. *dp = (png_byte)(((int)*rp - (int)*lp) & 0xff);
  178979. }
  178980. best_row = png_ptr->sub_row;
  178981. }
  178982. else if (filter_to_do & PNG_FILTER_SUB)
  178983. {
  178984. png_bytep rp, dp, lp;
  178985. png_uint_32 sum = 0, lmins = mins;
  178986. png_uint_32 i;
  178987. int v;
  178988. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178989. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178990. {
  178991. int j;
  178992. png_uint_32 lmhi, lmlo;
  178993. lmlo = lmins & PNG_LOMASK;
  178994. lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
  178995. for (j = 0; j < num_p_filters; j++)
  178996. {
  178997. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_SUB)
  178998. {
  178999. lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
  179000. PNG_WEIGHT_SHIFT;
  179001. lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
  179002. PNG_WEIGHT_SHIFT;
  179003. }
  179004. }
  179005. lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
  179006. PNG_COST_SHIFT;
  179007. lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
  179008. PNG_COST_SHIFT;
  179009. if (lmhi > PNG_HIMASK)
  179010. lmins = PNG_MAXSUM;
  179011. else
  179012. lmins = (lmhi << PNG_HISHIFT) + lmlo;
  179013. }
  179014. #endif
  179015. for (i = 0, rp = row_buf + 1, dp = png_ptr->sub_row + 1; i < bpp;
  179016. i++, rp++, dp++)
  179017. {
  179018. v = *dp = *rp;
  179019. sum += (v < 128) ? v : 256 - v;
  179020. }
  179021. for (lp = row_buf + 1; i < row_bytes;
  179022. i++, rp++, lp++, dp++)
  179023. {
  179024. v = *dp = (png_byte)(((int)*rp - (int)*lp) & 0xff);
  179025. sum += (v < 128) ? v : 256 - v;
  179026. if (sum > lmins) /* We are already worse, don't continue. */
  179027. break;
  179028. }
  179029. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  179030. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  179031. {
  179032. int j;
  179033. png_uint_32 sumhi, sumlo;
  179034. sumlo = sum & PNG_LOMASK;
  179035. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
  179036. for (j = 0; j < num_p_filters; j++)
  179037. {
  179038. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_SUB)
  179039. {
  179040. sumlo = (sumlo * png_ptr->inv_filter_weights[j]) >>
  179041. PNG_WEIGHT_SHIFT;
  179042. sumhi = (sumhi * png_ptr->inv_filter_weights[j]) >>
  179043. PNG_WEIGHT_SHIFT;
  179044. }
  179045. }
  179046. sumlo = (sumlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
  179047. PNG_COST_SHIFT;
  179048. sumhi = (sumhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
  179049. PNG_COST_SHIFT;
  179050. if (sumhi > PNG_HIMASK)
  179051. sum = PNG_MAXSUM;
  179052. else
  179053. sum = (sumhi << PNG_HISHIFT) + sumlo;
  179054. }
  179055. #endif
  179056. if (sum < mins)
  179057. {
  179058. mins = sum;
  179059. best_row = png_ptr->sub_row;
  179060. }
  179061. }
  179062. if (filter_to_do == PNG_FILTER_UP)
  179063. {
  179064. png_bytep rp, dp, pp;
  179065. png_uint_32 i;
  179066. for (i = 0, rp = row_buf + 1, dp = png_ptr->up_row + 1,
  179067. pp = prev_row + 1; i < row_bytes;
  179068. i++, rp++, pp++, dp++)
  179069. {
  179070. *dp = (png_byte)(((int)*rp - (int)*pp) & 0xff);
  179071. }
  179072. best_row = png_ptr->up_row;
  179073. }
  179074. else if (filter_to_do & PNG_FILTER_UP)
  179075. {
  179076. png_bytep rp, dp, pp;
  179077. png_uint_32 sum = 0, lmins = mins;
  179078. png_uint_32 i;
  179079. int v;
  179080. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  179081. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  179082. {
  179083. int j;
  179084. png_uint_32 lmhi, lmlo;
  179085. lmlo = lmins & PNG_LOMASK;
  179086. lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
  179087. for (j = 0; j < num_p_filters; j++)
  179088. {
  179089. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_UP)
  179090. {
  179091. lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
  179092. PNG_WEIGHT_SHIFT;
  179093. lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
  179094. PNG_WEIGHT_SHIFT;
  179095. }
  179096. }
  179097. lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_UP]) >>
  179098. PNG_COST_SHIFT;
  179099. lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_UP]) >>
  179100. PNG_COST_SHIFT;
  179101. if (lmhi > PNG_HIMASK)
  179102. lmins = PNG_MAXSUM;
  179103. else
  179104. lmins = (lmhi << PNG_HISHIFT) + lmlo;
  179105. }
  179106. #endif
  179107. for (i = 0, rp = row_buf + 1, dp = png_ptr->up_row + 1,
  179108. pp = prev_row + 1; i < row_bytes; i++)
  179109. {
  179110. v = *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
  179111. sum += (v < 128) ? v : 256 - v;
  179112. if (sum > lmins) /* We are already worse, don't continue. */
  179113. break;
  179114. }
  179115. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  179116. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  179117. {
  179118. int j;
  179119. png_uint_32 sumhi, sumlo;
  179120. sumlo = sum & PNG_LOMASK;
  179121. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
  179122. for (j = 0; j < num_p_filters; j++)
  179123. {
  179124. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_UP)
  179125. {
  179126. sumlo = (sumlo * png_ptr->filter_weights[j]) >>
  179127. PNG_WEIGHT_SHIFT;
  179128. sumhi = (sumhi * png_ptr->filter_weights[j]) >>
  179129. PNG_WEIGHT_SHIFT;
  179130. }
  179131. }
  179132. sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_UP]) >>
  179133. PNG_COST_SHIFT;
  179134. sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_UP]) >>
  179135. PNG_COST_SHIFT;
  179136. if (sumhi > PNG_HIMASK)
  179137. sum = PNG_MAXSUM;
  179138. else
  179139. sum = (sumhi << PNG_HISHIFT) + sumlo;
  179140. }
  179141. #endif
  179142. if (sum < mins)
  179143. {
  179144. mins = sum;
  179145. best_row = png_ptr->up_row;
  179146. }
  179147. }
  179148. if (filter_to_do == PNG_FILTER_AVG)
  179149. {
  179150. png_bytep rp, dp, pp, lp;
  179151. png_uint_32 i;
  179152. for (i = 0, rp = row_buf + 1, dp = png_ptr->avg_row + 1,
  179153. pp = prev_row + 1; i < bpp; i++)
  179154. {
  179155. *dp++ = (png_byte)(((int)*rp++ - ((int)*pp++ / 2)) & 0xff);
  179156. }
  179157. for (lp = row_buf + 1; i < row_bytes; i++)
  179158. {
  179159. *dp++ = (png_byte)(((int)*rp++ - (((int)*pp++ + (int)*lp++) / 2))
  179160. & 0xff);
  179161. }
  179162. best_row = png_ptr->avg_row;
  179163. }
  179164. else if (filter_to_do & PNG_FILTER_AVG)
  179165. {
  179166. png_bytep rp, dp, pp, lp;
  179167. png_uint_32 sum = 0, lmins = mins;
  179168. png_uint_32 i;
  179169. int v;
  179170. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  179171. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  179172. {
  179173. int j;
  179174. png_uint_32 lmhi, lmlo;
  179175. lmlo = lmins & PNG_LOMASK;
  179176. lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
  179177. for (j = 0; j < num_p_filters; j++)
  179178. {
  179179. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_AVG)
  179180. {
  179181. lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
  179182. PNG_WEIGHT_SHIFT;
  179183. lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
  179184. PNG_WEIGHT_SHIFT;
  179185. }
  179186. }
  179187. lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_AVG]) >>
  179188. PNG_COST_SHIFT;
  179189. lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_AVG]) >>
  179190. PNG_COST_SHIFT;
  179191. if (lmhi > PNG_HIMASK)
  179192. lmins = PNG_MAXSUM;
  179193. else
  179194. lmins = (lmhi << PNG_HISHIFT) + lmlo;
  179195. }
  179196. #endif
  179197. for (i = 0, rp = row_buf + 1, dp = png_ptr->avg_row + 1,
  179198. pp = prev_row + 1; i < bpp; i++)
  179199. {
  179200. v = *dp++ = (png_byte)(((int)*rp++ - ((int)*pp++ / 2)) & 0xff);
  179201. sum += (v < 128) ? v : 256 - v;
  179202. }
  179203. for (lp = row_buf + 1; i < row_bytes; i++)
  179204. {
  179205. v = *dp++ =
  179206. (png_byte)(((int)*rp++ - (((int)*pp++ + (int)*lp++) / 2)) & 0xff);
  179207. sum += (v < 128) ? v : 256 - v;
  179208. if (sum > lmins) /* We are already worse, don't continue. */
  179209. break;
  179210. }
  179211. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  179212. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  179213. {
  179214. int j;
  179215. png_uint_32 sumhi, sumlo;
  179216. sumlo = sum & PNG_LOMASK;
  179217. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
  179218. for (j = 0; j < num_p_filters; j++)
  179219. {
  179220. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_NONE)
  179221. {
  179222. sumlo = (sumlo * png_ptr->filter_weights[j]) >>
  179223. PNG_WEIGHT_SHIFT;
  179224. sumhi = (sumhi * png_ptr->filter_weights[j]) >>
  179225. PNG_WEIGHT_SHIFT;
  179226. }
  179227. }
  179228. sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_AVG]) >>
  179229. PNG_COST_SHIFT;
  179230. sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_AVG]) >>
  179231. PNG_COST_SHIFT;
  179232. if (sumhi > PNG_HIMASK)
  179233. sum = PNG_MAXSUM;
  179234. else
  179235. sum = (sumhi << PNG_HISHIFT) + sumlo;
  179236. }
  179237. #endif
  179238. if (sum < mins)
  179239. {
  179240. mins = sum;
  179241. best_row = png_ptr->avg_row;
  179242. }
  179243. }
  179244. if (filter_to_do == PNG_FILTER_PAETH)
  179245. {
  179246. png_bytep rp, dp, pp, cp, lp;
  179247. png_uint_32 i;
  179248. for (i = 0, rp = row_buf + 1, dp = png_ptr->paeth_row + 1,
  179249. pp = prev_row + 1; i < bpp; i++)
  179250. {
  179251. *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
  179252. }
  179253. for (lp = row_buf + 1, cp = prev_row + 1; i < row_bytes; i++)
  179254. {
  179255. int a, b, c, pa, pb, pc, p;
  179256. b = *pp++;
  179257. c = *cp++;
  179258. a = *lp++;
  179259. p = b - c;
  179260. pc = a - c;
  179261. #ifdef PNG_USE_ABS
  179262. pa = abs(p);
  179263. pb = abs(pc);
  179264. pc = abs(p + pc);
  179265. #else
  179266. pa = p < 0 ? -p : p;
  179267. pb = pc < 0 ? -pc : pc;
  179268. pc = (p + pc) < 0 ? -(p + pc) : p + pc;
  179269. #endif
  179270. p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
  179271. *dp++ = (png_byte)(((int)*rp++ - p) & 0xff);
  179272. }
  179273. best_row = png_ptr->paeth_row;
  179274. }
  179275. else if (filter_to_do & PNG_FILTER_PAETH)
  179276. {
  179277. png_bytep rp, dp, pp, cp, lp;
  179278. png_uint_32 sum = 0, lmins = mins;
  179279. png_uint_32 i;
  179280. int v;
  179281. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  179282. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  179283. {
  179284. int j;
  179285. png_uint_32 lmhi, lmlo;
  179286. lmlo = lmins & PNG_LOMASK;
  179287. lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
  179288. for (j = 0; j < num_p_filters; j++)
  179289. {
  179290. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_PAETH)
  179291. {
  179292. lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
  179293. PNG_WEIGHT_SHIFT;
  179294. lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
  179295. PNG_WEIGHT_SHIFT;
  179296. }
  179297. }
  179298. lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_PAETH]) >>
  179299. PNG_COST_SHIFT;
  179300. lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_PAETH]) >>
  179301. PNG_COST_SHIFT;
  179302. if (lmhi > PNG_HIMASK)
  179303. lmins = PNG_MAXSUM;
  179304. else
  179305. lmins = (lmhi << PNG_HISHIFT) + lmlo;
  179306. }
  179307. #endif
  179308. for (i = 0, rp = row_buf + 1, dp = png_ptr->paeth_row + 1,
  179309. pp = prev_row + 1; i < bpp; i++)
  179310. {
  179311. v = *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
  179312. sum += (v < 128) ? v : 256 - v;
  179313. }
  179314. for (lp = row_buf + 1, cp = prev_row + 1; i < row_bytes; i++)
  179315. {
  179316. int a, b, c, pa, pb, pc, p;
  179317. b = *pp++;
  179318. c = *cp++;
  179319. a = *lp++;
  179320. #ifndef PNG_SLOW_PAETH
  179321. p = b - c;
  179322. pc = a - c;
  179323. #ifdef PNG_USE_ABS
  179324. pa = abs(p);
  179325. pb = abs(pc);
  179326. pc = abs(p + pc);
  179327. #else
  179328. pa = p < 0 ? -p : p;
  179329. pb = pc < 0 ? -pc : pc;
  179330. pc = (p + pc) < 0 ? -(p + pc) : p + pc;
  179331. #endif
  179332. p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
  179333. #else /* PNG_SLOW_PAETH */
  179334. p = a + b - c;
  179335. pa = abs(p - a);
  179336. pb = abs(p - b);
  179337. pc = abs(p - c);
  179338. if (pa <= pb && pa <= pc)
  179339. p = a;
  179340. else if (pb <= pc)
  179341. p = b;
  179342. else
  179343. p = c;
  179344. #endif /* PNG_SLOW_PAETH */
  179345. v = *dp++ = (png_byte)(((int)*rp++ - p) & 0xff);
  179346. sum += (v < 128) ? v : 256 - v;
  179347. if (sum > lmins) /* We are already worse, don't continue. */
  179348. break;
  179349. }
  179350. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  179351. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  179352. {
  179353. int j;
  179354. png_uint_32 sumhi, sumlo;
  179355. sumlo = sum & PNG_LOMASK;
  179356. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
  179357. for (j = 0; j < num_p_filters; j++)
  179358. {
  179359. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_PAETH)
  179360. {
  179361. sumlo = (sumlo * png_ptr->filter_weights[j]) >>
  179362. PNG_WEIGHT_SHIFT;
  179363. sumhi = (sumhi * png_ptr->filter_weights[j]) >>
  179364. PNG_WEIGHT_SHIFT;
  179365. }
  179366. }
  179367. sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_PAETH]) >>
  179368. PNG_COST_SHIFT;
  179369. sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_PAETH]) >>
  179370. PNG_COST_SHIFT;
  179371. if (sumhi > PNG_HIMASK)
  179372. sum = PNG_MAXSUM;
  179373. else
  179374. sum = (sumhi << PNG_HISHIFT) + sumlo;
  179375. }
  179376. #endif
  179377. if (sum < mins)
  179378. {
  179379. best_row = png_ptr->paeth_row;
  179380. }
  179381. }
  179382. #endif /* PNG_NO_WRITE_FILTER */
  179383. png_write_filtered_row(png_ptr, best_row);
  179384. #ifndef PNG_NO_WRITE_FILTER
  179385. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  179386. if (png_ptr->num_prev_filters > 0)
  179387. {
  179388. int j;
  179389. for (j = 1; j < num_p_filters; j++)
  179390. {
  179391. png_ptr->prev_filters[j] = png_ptr->prev_filters[j - 1];
  179392. }
  179393. png_ptr->prev_filters[j] = best_row[0];
  179394. }
  179395. #endif
  179396. #endif /* PNG_NO_WRITE_FILTER */
  179397. }
  179398. void /* PRIVATE */
  179399. png_write_filtered_row(png_structp png_ptr, png_bytep filtered_row)
  179400. {
  179401. png_debug(1, "in png_write_filtered_row\n");
  179402. png_debug1(2, "filter = %d\n", filtered_row[0]);
  179403. png_ptr->zstream.next_in = filtered_row;
  179404. png_ptr->zstream.avail_in = (uInt)png_ptr->row_info.rowbytes + 1;
  179405. do
  179406. {
  179407. int ret; /* return of zlib */
  179408. ret = deflate(&png_ptr->zstream, Z_NO_FLUSH);
  179409. if (ret != Z_OK)
  179410. {
  179411. if (png_ptr->zstream.msg != NULL)
  179412. png_error(png_ptr, png_ptr->zstream.msg);
  179413. else
  179414. png_error(png_ptr, "zlib error");
  179415. }
  179416. if (!(png_ptr->zstream.avail_out))
  179417. {
  179418. png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
  179419. png_ptr->zstream.next_out = png_ptr->zbuf;
  179420. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  179421. }
  179422. } while (png_ptr->zstream.avail_in);
  179423. if (png_ptr->prev_row != NULL)
  179424. {
  179425. png_bytep tptr;
  179426. tptr = png_ptr->prev_row;
  179427. png_ptr->prev_row = png_ptr->row_buf;
  179428. png_ptr->row_buf = tptr;
  179429. }
  179430. png_write_finish_row(png_ptr);
  179431. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  179432. png_ptr->flush_rows++;
  179433. if (png_ptr->flush_dist > 0 &&
  179434. png_ptr->flush_rows >= png_ptr->flush_dist)
  179435. {
  179436. png_write_flush(png_ptr);
  179437. }
  179438. #endif
  179439. }
  179440. #endif /* PNG_WRITE_SUPPORTED */
  179441. /*** End of inlined file: pngwutil.c ***/
  179442. }
  179443. #else
  179444. #define PNG_INTERNAL
  179445. #define PNG_SETJMP_NOT_SUPPORTED
  179446. #include <png.h>
  179447. #include <pngconf.h>
  179448. #endif
  179449. }
  179450. #ifdef _MSC_VER
  179451. #pragma warning (pop)
  179452. #endif
  179453. BEGIN_JUCE_NAMESPACE
  179454. using namespace pnglibNamespace;
  179455. using ::calloc;
  179456. using ::malloc;
  179457. using ::free;
  179458. static void pngReadCallback (png_structp pngReadStruct, png_bytep data, png_size_t length)
  179459. {
  179460. InputStream* const in = (InputStream*) png_get_io_ptr (pngReadStruct);
  179461. in->read (data, (int) length);
  179462. }
  179463. struct PNGErrorStruct {};
  179464. static void pngErrorCallback (png_structp, png_const_charp)
  179465. {
  179466. throw PNGErrorStruct();
  179467. }
  179468. Image* juce_loadPNGImageFromStream (InputStream& in)
  179469. {
  179470. Image* image = 0;
  179471. png_structp pngReadStruct;
  179472. png_infop pngInfoStruct;
  179473. pngReadStruct = png_create_read_struct (PNG_LIBPNG_VER_STRING, 0, 0, 0);
  179474. if (pngReadStruct != 0)
  179475. {
  179476. pngInfoStruct = png_create_info_struct (pngReadStruct);
  179477. if (pngInfoStruct == 0)
  179478. {
  179479. png_destroy_read_struct (&pngReadStruct, 0, 0);
  179480. return 0;
  179481. }
  179482. png_set_error_fn (pngReadStruct, 0, pngErrorCallback, pngErrorCallback);
  179483. // read the header..
  179484. png_set_read_fn (pngReadStruct, &in, pngReadCallback);
  179485. png_uint_32 width, height;
  179486. int bitDepth, colorType, interlaceType;
  179487. png_read_info (pngReadStruct, pngInfoStruct);
  179488. png_get_IHDR (pngReadStruct, pngInfoStruct,
  179489. &width, &height,
  179490. &bitDepth, &colorType,
  179491. &interlaceType, 0, 0);
  179492. if (bitDepth == 16)
  179493. png_set_strip_16 (pngReadStruct);
  179494. if (colorType == PNG_COLOR_TYPE_PALETTE)
  179495. png_set_expand (pngReadStruct);
  179496. if (bitDepth < 8)
  179497. png_set_expand (pngReadStruct);
  179498. if (png_get_valid (pngReadStruct, pngInfoStruct, PNG_INFO_tRNS))
  179499. png_set_expand (pngReadStruct);
  179500. if (colorType == PNG_COLOR_TYPE_GRAY || colorType == PNG_COLOR_TYPE_GRAY_ALPHA)
  179501. png_set_gray_to_rgb (pngReadStruct);
  179502. png_set_add_alpha (pngReadStruct, 0xff, PNG_FILLER_AFTER);
  179503. bool hasAlphaChan = (colorType & PNG_COLOR_MASK_ALPHA) != 0
  179504. || pngInfoStruct->num_trans > 0;
  179505. // Load the image into a temp buffer in the pnglib format..
  179506. HeapBlock <uint8> tempBuffer (height * (width << 2));
  179507. {
  179508. HeapBlock <png_bytep> rows (height);
  179509. for (int y = (int) height; --y >= 0;)
  179510. rows[y] = (png_bytep) (tempBuffer + (width << 2) * y);
  179511. png_read_image (pngReadStruct, rows);
  179512. png_read_end (pngReadStruct, pngInfoStruct);
  179513. }
  179514. png_destroy_read_struct (&pngReadStruct, &pngInfoStruct, 0);
  179515. // now convert the data to a juce image format..
  179516. image = Image::createNativeImage (hasAlphaChan ? Image::ARGB : Image::RGB,
  179517. (int) width, (int) height, hasAlphaChan);
  179518. hasAlphaChan = image->hasAlphaChannel(); // (the native image creator may not give back what we expect)
  179519. const Image::BitmapData destData (*image, 0, 0, (int) width, (int) height, true);
  179520. uint8* srcRow = tempBuffer;
  179521. uint8* destRow = destData.data;
  179522. for (int y = 0; y < (int) height; ++y)
  179523. {
  179524. const uint8* src = srcRow;
  179525. srcRow += (width << 2);
  179526. uint8* dest = destRow;
  179527. destRow += destData.lineStride;
  179528. if (hasAlphaChan)
  179529. {
  179530. for (int i = (int) width; --i >= 0;)
  179531. {
  179532. ((PixelARGB*) dest)->setARGB (src[3], src[0], src[1], src[2]);
  179533. ((PixelARGB*) dest)->premultiply();
  179534. dest += destData.pixelStride;
  179535. src += 4;
  179536. }
  179537. }
  179538. else
  179539. {
  179540. for (int i = (int) width; --i >= 0;)
  179541. {
  179542. ((PixelRGB*) dest)->setARGB (0, src[0], src[1], src[2]);
  179543. dest += destData.pixelStride;
  179544. src += 4;
  179545. }
  179546. }
  179547. }
  179548. }
  179549. return image;
  179550. }
  179551. static void pngWriteDataCallback (png_structp png_ptr, png_bytep data, png_size_t length)
  179552. {
  179553. OutputStream* const out = (OutputStream*) png_ptr->io_ptr;
  179554. const bool ok = out->write (data, (int) length);
  179555. (void) ok;
  179556. jassert (ok);
  179557. }
  179558. bool juce_writePNGImageToStream (const Image& image, OutputStream& out)
  179559. {
  179560. const int width = image.getWidth();
  179561. const int height = image.getHeight();
  179562. png_structp pngWriteStruct = png_create_write_struct (PNG_LIBPNG_VER_STRING, 0, 0, 0);
  179563. if (pngWriteStruct == 0)
  179564. return false;
  179565. png_infop pngInfoStruct = png_create_info_struct (pngWriteStruct);
  179566. if (pngInfoStruct == 0)
  179567. {
  179568. png_destroy_write_struct (&pngWriteStruct, (png_infopp) 0);
  179569. return false;
  179570. }
  179571. png_set_write_fn (pngWriteStruct, &out, pngWriteDataCallback, 0);
  179572. png_set_IHDR (pngWriteStruct, pngInfoStruct, width, height, 8,
  179573. image.hasAlphaChannel() ? PNG_COLOR_TYPE_RGB_ALPHA
  179574. : PNG_COLOR_TYPE_RGB,
  179575. PNG_INTERLACE_NONE,
  179576. PNG_COMPRESSION_TYPE_BASE,
  179577. PNG_FILTER_TYPE_BASE);
  179578. HeapBlock <png_byte> rowData (width * 4);
  179579. png_color_8 sig_bit;
  179580. sig_bit.red = 8;
  179581. sig_bit.green = 8;
  179582. sig_bit.blue = 8;
  179583. sig_bit.alpha = 8;
  179584. png_set_sBIT (pngWriteStruct, pngInfoStruct, &sig_bit);
  179585. png_write_info (pngWriteStruct, pngInfoStruct);
  179586. png_set_shift (pngWriteStruct, &sig_bit);
  179587. png_set_packing (pngWriteStruct);
  179588. const Image::BitmapData srcData (image, 0, 0, width, height);
  179589. for (int y = 0; y < height; ++y)
  179590. {
  179591. uint8* dst = (uint8*) rowData;
  179592. const uint8* src = srcData.getLinePointer (y);
  179593. if (image.hasAlphaChannel())
  179594. {
  179595. for (int i = width; --i >= 0;)
  179596. {
  179597. PixelARGB p (*(const PixelARGB*) src);
  179598. p.unpremultiply();
  179599. *dst++ = p.getRed();
  179600. *dst++ = p.getGreen();
  179601. *dst++ = p.getBlue();
  179602. *dst++ = p.getAlpha();
  179603. src += srcData.pixelStride;
  179604. }
  179605. }
  179606. else
  179607. {
  179608. for (int i = width; --i >= 0;)
  179609. {
  179610. *dst++ = ((const PixelRGB*) src)->getRed();
  179611. *dst++ = ((const PixelRGB*) src)->getGreen();
  179612. *dst++ = ((const PixelRGB*) src)->getBlue();
  179613. src += srcData.pixelStride;
  179614. }
  179615. }
  179616. png_write_rows (pngWriteStruct, &rowData, 1);
  179617. }
  179618. png_write_end (pngWriteStruct, pngInfoStruct);
  179619. png_destroy_write_struct (&pngWriteStruct, &pngInfoStruct);
  179620. out.flush();
  179621. return true;
  179622. }
  179623. END_JUCE_NAMESPACE
  179624. /*** End of inlined file: juce_PNGLoader.cpp ***/
  179625. #endif
  179626. //==============================================================================
  179627. #if JUCE_BUILD_NATIVE
  179628. #if JUCE_WINDOWS
  179629. /*** Start of inlined file: juce_win32_NativeCode.cpp ***/
  179630. BEGIN_JUCE_NAMESPACE
  179631. #define JUCE_INCLUDED_FILE 1
  179632. // Now include the actual code files..
  179633. /*** Start of inlined file: juce_win32_DynamicLibraryLoader.cpp ***/
  179634. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  179635. // compiled on its own).
  179636. #if JUCE_INCLUDED_FILE
  179637. /*** Start of inlined file: juce_win32_DynamicLibraryLoader.h ***/
  179638. #ifndef __JUCE_WIN32_DYNAMICLIBRARYLOADER_JUCEHEADER__
  179639. #define __JUCE_WIN32_DYNAMICLIBRARYLOADER_JUCEHEADER__
  179640. #ifndef DOXYGEN
  179641. // use with DynamicLibraryLoader to simplify importing functions
  179642. //
  179643. // functionName: function to import
  179644. // localFunctionName: name you want to use to actually call it (must be different)
  179645. // returnType: the return type
  179646. // object: the DynamicLibraryLoader to use
  179647. // params: list of params (bracketed)
  179648. //
  179649. #define DynamicLibraryImport(functionName, localFunctionName, returnType, object, params) \
  179650. typedef returnType (WINAPI *type##localFunctionName) params; \
  179651. type##localFunctionName localFunctionName \
  179652. = (type##localFunctionName)object.findProcAddress (#functionName);
  179653. // loads and unloads a DLL automatically
  179654. class JUCE_API DynamicLibraryLoader
  179655. {
  179656. public:
  179657. DynamicLibraryLoader (const String& name);
  179658. ~DynamicLibraryLoader();
  179659. void* findProcAddress (const String& functionName);
  179660. private:
  179661. void* libHandle;
  179662. };
  179663. #endif
  179664. #endif // __JUCE_WIN32_DYNAMICLIBRARYLOADER_JUCEHEADER__
  179665. /*** End of inlined file: juce_win32_DynamicLibraryLoader.h ***/
  179666. DynamicLibraryLoader::DynamicLibraryLoader (const String& name)
  179667. {
  179668. libHandle = LoadLibrary (name);
  179669. }
  179670. DynamicLibraryLoader::~DynamicLibraryLoader()
  179671. {
  179672. FreeLibrary ((HMODULE) libHandle);
  179673. }
  179674. void* DynamicLibraryLoader::findProcAddress (const String& functionName)
  179675. {
  179676. return (void*) GetProcAddress ((HMODULE) libHandle, functionName);
  179677. }
  179678. #endif
  179679. /*** End of inlined file: juce_win32_DynamicLibraryLoader.cpp ***/
  179680. /*** Start of inlined file: juce_win32_SystemStats.cpp ***/
  179681. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  179682. // compiled on its own).
  179683. #if JUCE_INCLUDED_FILE
  179684. extern void juce_initialiseThreadEvents();
  179685. void Logger::outputDebugString (const String& text) throw()
  179686. {
  179687. OutputDebugString (text + T("\n"));
  179688. }
  179689. void Logger::outputDebugPrintf (const tchar* format, ...) throw()
  179690. {
  179691. String text;
  179692. va_list args;
  179693. va_start (args, format);
  179694. text.vprintf(format, args);
  179695. outputDebugString (text);
  179696. }
  179697. static int64 hiResTicksPerSecond;
  179698. static double hiResTicksScaleFactor;
  179699. #if JUCE_USE_INTRINSICS
  179700. // CPU info functions using intrinsics...
  179701. #pragma intrinsic (__cpuid)
  179702. #pragma intrinsic (__rdtsc)
  179703. const String SystemStats::getCpuVendor() throw()
  179704. {
  179705. int info [4];
  179706. __cpuid (info, 0);
  179707. char v [12];
  179708. memcpy (v, info + 1, 4);
  179709. memcpy (v + 4, info + 3, 4);
  179710. memcpy (v + 8, info + 2, 4);
  179711. return String (v, 12);
  179712. }
  179713. #else
  179714. // CPU info functions using old fashioned inline asm...
  179715. static void juce_getCpuVendor (char* const v)
  179716. {
  179717. int vendor[4];
  179718. zeromem (vendor, 16);
  179719. #ifdef JUCE_64BIT
  179720. #else
  179721. #ifndef __MINGW32__
  179722. __try
  179723. #endif
  179724. {
  179725. #if JUCE_GCC
  179726. unsigned int dummy = 0;
  179727. __asm__ ("cpuid" : "=a" (dummy), "=b" (vendor[0]), "=c" (vendor[2]),"=d" (vendor[1]) : "a" (0));
  179728. #else
  179729. __asm
  179730. {
  179731. mov eax, 0
  179732. cpuid
  179733. mov [vendor], ebx
  179734. mov [vendor + 4], edx
  179735. mov [vendor + 8], ecx
  179736. }
  179737. #endif
  179738. }
  179739. #ifndef __MINGW32__
  179740. __except (EXCEPTION_EXECUTE_HANDLER)
  179741. {
  179742. *v = 0;
  179743. }
  179744. #endif
  179745. #endif
  179746. memcpy (v, vendor, 16);
  179747. }
  179748. const String SystemStats::getCpuVendor() throw()
  179749. {
  179750. char v [16];
  179751. juce_getCpuVendor (v);
  179752. return String (v, 16);
  179753. }
  179754. #endif
  179755. struct CPUFlags
  179756. {
  179757. bool hasMMX : 1;
  179758. bool hasSSE : 1;
  179759. bool hasSSE2 : 1;
  179760. bool has3DNow : 1;
  179761. };
  179762. static CPUFlags cpuFlags;
  179763. bool SystemStats::hasMMX() throw()
  179764. {
  179765. return cpuFlags.hasMMX;
  179766. }
  179767. bool SystemStats::hasSSE() throw()
  179768. {
  179769. return cpuFlags.hasSSE;
  179770. }
  179771. bool SystemStats::hasSSE2() throw()
  179772. {
  179773. return cpuFlags.hasSSE2;
  179774. }
  179775. bool SystemStats::has3DNow() throw()
  179776. {
  179777. return cpuFlags.has3DNow;
  179778. }
  179779. void SystemStats::initialiseStats() throw()
  179780. {
  179781. juce_initialiseThreadEvents();
  179782. cpuFlags.hasMMX = IsProcessorFeaturePresent (PF_MMX_INSTRUCTIONS_AVAILABLE) != 0;
  179783. cpuFlags.hasSSE = IsProcessorFeaturePresent (PF_XMMI_INSTRUCTIONS_AVAILABLE) != 0;
  179784. cpuFlags.hasSSE2 = IsProcessorFeaturePresent (PF_XMMI64_INSTRUCTIONS_AVAILABLE) != 0;
  179785. #ifdef PF_AMD3D_INSTRUCTIONS_AVAILABLE
  179786. cpuFlags.has3DNow = IsProcessorFeaturePresent (PF_AMD3D_INSTRUCTIONS_AVAILABLE) != 0;
  179787. #else
  179788. cpuFlags.has3DNow = IsProcessorFeaturePresent (PF_3DNOW_INSTRUCTIONS_AVAILABLE) != 0;
  179789. #endif
  179790. LARGE_INTEGER f;
  179791. QueryPerformanceFrequency (&f);
  179792. hiResTicksPerSecond = f.QuadPart;
  179793. hiResTicksScaleFactor = 1000.0 / hiResTicksPerSecond;
  179794. String s (SystemStats::getJUCEVersion());
  179795. #ifdef JUCE_DEBUG
  179796. const MMRESULT res = timeBeginPeriod (1);
  179797. jassert (res == TIMERR_NOERROR);
  179798. #else
  179799. timeBeginPeriod (1);
  179800. #endif
  179801. #if defined (JUCE_DEBUG) && JUCE_MSVC && JUCE_CHECK_MEMORY_LEAKS
  179802. _CrtSetDbgFlag (_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
  179803. #endif
  179804. }
  179805. SystemStats::OperatingSystemType SystemStats::getOperatingSystemType() throw()
  179806. {
  179807. OSVERSIONINFO info;
  179808. info.dwOSVersionInfoSize = sizeof (info);
  179809. GetVersionEx (&info);
  179810. if (info.dwPlatformId == VER_PLATFORM_WIN32_NT)
  179811. {
  179812. switch (info.dwMajorVersion)
  179813. {
  179814. case 5: return (info.dwMinorVersion == 0) ? Win2000 : WinXP;
  179815. case 6: return (info.dwMinorVersion == 0) ? WinVista : Windows7;
  179816. default: jassertfalse; break; // !! not a supported OS!
  179817. }
  179818. }
  179819. else if (info.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
  179820. {
  179821. jassert (info.dwMinorVersion != 0); // !! still running on Windows 95??
  179822. return Win98;
  179823. }
  179824. return UnknownOS;
  179825. }
  179826. const String SystemStats::getOperatingSystemName() throw()
  179827. {
  179828. const char* name = "Unknown OS";
  179829. switch (getOperatingSystemType())
  179830. {
  179831. case Windows7: name = "Windows 7"; break;
  179832. case WinVista: name = "Windows Vista"; break;
  179833. case WinXP: name = "Windows XP"; break;
  179834. case Win2000: name = "Windows 2000"; break;
  179835. case Win98: name = "Windows 98"; break;
  179836. default: jassertfalse; break; // !! new type of OS?
  179837. }
  179838. return name;
  179839. }
  179840. bool SystemStats::isOperatingSystem64Bit() throw()
  179841. {
  179842. #ifdef _WIN64
  179843. return true;
  179844. #else
  179845. typedef BOOL (WINAPI* LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);
  179846. LPFN_ISWOW64PROCESS fnIsWow64Process = (LPFN_ISWOW64PROCESS) GetProcAddress (GetModuleHandle (L"kernel32"), "IsWow64Process");
  179847. BOOL isWow64 = FALSE;
  179848. return (fnIsWow64Process != 0)
  179849. && fnIsWow64Process (GetCurrentProcess(), &isWow64)
  179850. && (isWow64 != FALSE);
  179851. #endif
  179852. }
  179853. int SystemStats::getMemorySizeInMegabytes() throw()
  179854. {
  179855. MEMORYSTATUSEX mem;
  179856. mem.dwLength = sizeof (mem);
  179857. GlobalMemoryStatusEx (&mem);
  179858. return (int) (mem.ullTotalPhys / (1024 * 1024)) + 1;
  179859. }
  179860. int SystemStats::getNumCpus() throw()
  179861. {
  179862. SYSTEM_INFO systemInfo;
  179863. GetSystemInfo (&systemInfo);
  179864. return systemInfo.dwNumberOfProcessors;
  179865. }
  179866. uint32 juce_millisecondsSinceStartup() throw()
  179867. {
  179868. return (uint32) GetTickCount();
  179869. }
  179870. int64 Time::getHighResolutionTicks() throw()
  179871. {
  179872. LARGE_INTEGER ticks;
  179873. QueryPerformanceCounter (&ticks);
  179874. const int64 mainCounterAsHiResTicks = (GetTickCount() * hiResTicksPerSecond) / 1000;
  179875. const int64 newOffset = mainCounterAsHiResTicks - ticks.QuadPart;
  179876. // fix for a very obscure PCI hardware bug that can make the counter
  179877. // sometimes jump forwards by a few seconds..
  179878. static int64 hiResTicksOffset = 0;
  179879. const int64 offsetDrift = abs64 (newOffset - hiResTicksOffset);
  179880. if (offsetDrift > (hiResTicksPerSecond >> 1))
  179881. hiResTicksOffset = newOffset;
  179882. return ticks.QuadPart + hiResTicksOffset;
  179883. }
  179884. double Time::getMillisecondCounterHiRes() throw()
  179885. {
  179886. return getHighResolutionTicks() * hiResTicksScaleFactor;
  179887. }
  179888. int64 Time::getHighResolutionTicksPerSecond() throw()
  179889. {
  179890. return hiResTicksPerSecond;
  179891. }
  179892. int64 SystemStats::getClockCycleCounter() throw()
  179893. {
  179894. #if JUCE_USE_INTRINSICS
  179895. // MS intrinsics version...
  179896. return __rdtsc();
  179897. #elif JUCE_GCC
  179898. // GNU inline asm version...
  179899. unsigned int hi = 0, lo = 0;
  179900. __asm__ __volatile__ (
  179901. "xor %%eax, %%eax \n\
  179902. xor %%edx, %%edx \n\
  179903. rdtsc \n\
  179904. movl %%eax, %[lo] \n\
  179905. movl %%edx, %[hi]"
  179906. :
  179907. : [hi] "m" (hi),
  179908. [lo] "m" (lo)
  179909. : "cc", "eax", "ebx", "ecx", "edx", "memory");
  179910. return (int64) ((((uint64) hi) << 32) | lo);
  179911. #else
  179912. // MSVC inline asm version...
  179913. unsigned int hi = 0, lo = 0;
  179914. __asm
  179915. {
  179916. xor eax, eax
  179917. xor edx, edx
  179918. rdtsc
  179919. mov lo, eax
  179920. mov hi, edx
  179921. }
  179922. return (int64) ((((uint64) hi) << 32) | lo);
  179923. #endif
  179924. }
  179925. int SystemStats::getCpuSpeedInMegaherz() throw()
  179926. {
  179927. const int64 cycles = SystemStats::getClockCycleCounter();
  179928. const uint32 millis = Time::getMillisecondCounter();
  179929. int lastResult = 0;
  179930. for (;;)
  179931. {
  179932. int n = 1000000;
  179933. while (--n > 0) {}
  179934. const uint32 millisElapsed = Time::getMillisecondCounter() - millis;
  179935. const int64 cyclesNow = SystemStats::getClockCycleCounter();
  179936. if (millisElapsed > 80)
  179937. {
  179938. const int newResult = (int) (((cyclesNow - cycles) / millisElapsed) / 1000);
  179939. if (millisElapsed > 500 || (lastResult == newResult && newResult > 100))
  179940. return newResult;
  179941. lastResult = newResult;
  179942. }
  179943. }
  179944. }
  179945. bool Time::setSystemTimeToThisTime() const throw()
  179946. {
  179947. SYSTEMTIME st;
  179948. st.wDayOfWeek = 0;
  179949. st.wYear = (WORD) getYear();
  179950. st.wMonth = (WORD) (getMonth() + 1);
  179951. st.wDay = (WORD) getDayOfMonth();
  179952. st.wHour = (WORD) getHours();
  179953. st.wMinute = (WORD) getMinutes();
  179954. st.wSecond = (WORD) getSeconds();
  179955. st.wMilliseconds = (WORD) (millisSinceEpoch % 1000);
  179956. // do this twice because of daylight saving conversion problems - the
  179957. // first one sets it up, the second one kicks it in.
  179958. return SetLocalTime (&st) != 0
  179959. && SetLocalTime (&st) != 0;
  179960. }
  179961. int SystemStats::getPageSize() throw()
  179962. {
  179963. SYSTEM_INFO systemInfo;
  179964. GetSystemInfo (&systemInfo);
  179965. return systemInfo.dwPageSize;
  179966. }
  179967. const String SystemStats::getLogonName()
  179968. {
  179969. TCHAR text [256];
  179970. DWORD len = numElementsInArray (text) - 2;
  179971. zerostruct (text);
  179972. GetUserName (text, &len);
  179973. return String (text, len);
  179974. }
  179975. const String SystemStats::getFullUserName()
  179976. {
  179977. return getLogonName();
  179978. }
  179979. #endif
  179980. /*** End of inlined file: juce_win32_SystemStats.cpp ***/
  179981. /*** Start of inlined file: juce_win32_Threads.cpp ***/
  179982. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  179983. // compiled on its own).
  179984. #if JUCE_INCLUDED_FILE
  179985. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  179986. extern HWND juce_messageWindowHandle;
  179987. #endif
  179988. #if ! JUCE_USE_INTRINSICS
  179989. // In newer compilers, the inline versions of these are used (in juce_Atomic.h), but in
  179990. // older ones we have to actually call the ops as win32 functions..
  179991. void Atomic::increment (int32& variable) { InterlockedIncrement (reinterpret_cast <volatile long*> (&variable)); }
  179992. int32 Atomic::incrementAndReturn (int32& variable) { return InterlockedIncrement (reinterpret_cast <volatile long*> (&variable)); }
  179993. void Atomic::decrement (int32& variable) { InterlockedDecrement (reinterpret_cast <volatile long*> (&variable)); }
  179994. int32 Atomic::decrementAndReturn (int32& variable) { return InterlockedDecrement (reinterpret_cast <volatile long*> (&variable)); }
  179995. int32 Atomic::compareAndExchange (int32& destination, int32 newValue, int32 oldValue)
  179996. { return InterlockedCompareExchange (reinterpret_cast <volatile long*> (&destination), newValue, oldValue); }
  179997. #endif
  179998. void* Atomic::swapPointers (void* volatile* value1, void* volatile value2) { return InterlockedExchangePointer (value1, value2); }
  179999. CriticalSection::CriticalSection() throw()
  180000. {
  180001. // (just to check the MS haven't changed this structure and broken things...)
  180002. #if _MSC_VER >= 1400
  180003. static_jassert (sizeof (CRITICAL_SECTION) <= sizeof (internal));
  180004. #else
  180005. static_jassert (sizeof (CRITICAL_SECTION) <= 24);
  180006. #endif
  180007. InitializeCriticalSection ((CRITICAL_SECTION*) internal);
  180008. }
  180009. CriticalSection::~CriticalSection() throw()
  180010. {
  180011. DeleteCriticalSection ((CRITICAL_SECTION*) internal);
  180012. }
  180013. void CriticalSection::enter() const throw()
  180014. {
  180015. EnterCriticalSection ((CRITICAL_SECTION*) internal);
  180016. }
  180017. bool CriticalSection::tryEnter() const throw()
  180018. {
  180019. return TryEnterCriticalSection ((CRITICAL_SECTION*) internal) != FALSE;
  180020. }
  180021. void CriticalSection::exit() const throw()
  180022. {
  180023. LeaveCriticalSection ((CRITICAL_SECTION*) internal);
  180024. }
  180025. WaitableEvent::WaitableEvent() throw()
  180026. : internal (CreateEvent (0, FALSE, FALSE, 0))
  180027. {
  180028. }
  180029. WaitableEvent::~WaitableEvent() throw()
  180030. {
  180031. CloseHandle (internal);
  180032. }
  180033. bool WaitableEvent::wait (const int timeOutMillisecs) const throw()
  180034. {
  180035. return WaitForSingleObject (internal, timeOutMillisecs) == WAIT_OBJECT_0;
  180036. }
  180037. void WaitableEvent::signal() const throw()
  180038. {
  180039. SetEvent (internal);
  180040. }
  180041. void WaitableEvent::reset() const throw()
  180042. {
  180043. ResetEvent (internal);
  180044. }
  180045. void JUCE_API juce_threadEntryPoint (void*);
  180046. static unsigned int __stdcall threadEntryProc (void* userData)
  180047. {
  180048. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  180049. AttachThreadInput (GetWindowThreadProcessId (juce_messageWindowHandle, 0),
  180050. GetCurrentThreadId(), TRUE);
  180051. #endif
  180052. juce_threadEntryPoint (userData);
  180053. _endthreadex (0);
  180054. return 0;
  180055. }
  180056. void juce_CloseThreadHandle (void* handle)
  180057. {
  180058. CloseHandle ((HANDLE) handle);
  180059. }
  180060. void* juce_createThread (void* userData)
  180061. {
  180062. unsigned int threadId;
  180063. return (void*) _beginthreadex (0, 0,
  180064. &threadEntryProc,
  180065. userData,
  180066. 0, &threadId);
  180067. }
  180068. void juce_killThread (void* handle)
  180069. {
  180070. if (handle != 0)
  180071. {
  180072. #ifdef JUCE_DEBUG
  180073. OutputDebugString (_T("** Warning - Forced thread termination **\n"));
  180074. #endif
  180075. TerminateThread (handle, 0);
  180076. }
  180077. }
  180078. void juce_setCurrentThreadName (const String& name)
  180079. {
  180080. #if defined (JUCE_DEBUG) && JUCE_MSVC
  180081. struct
  180082. {
  180083. DWORD dwType;
  180084. LPCSTR szName;
  180085. DWORD dwThreadID;
  180086. DWORD dwFlags;
  180087. } info;
  180088. info.dwType = 0x1000;
  180089. info.szName = name;
  180090. info.dwThreadID = GetCurrentThreadId();
  180091. info.dwFlags = 0;
  180092. #define MS_VC_EXCEPTION 0x406d1388
  180093. __try
  180094. {
  180095. RaiseException (MS_VC_EXCEPTION, 0, sizeof (info) / sizeof (ULONG_PTR), (ULONG_PTR*) &info);
  180096. }
  180097. __except (EXCEPTION_CONTINUE_EXECUTION)
  180098. {}
  180099. #else
  180100. (void) name;
  180101. #endif
  180102. }
  180103. Thread::ThreadID Thread::getCurrentThreadId()
  180104. {
  180105. return (ThreadID) (pointer_sized_int) GetCurrentThreadId();
  180106. }
  180107. // priority 1 to 10 where 5=normal, 1=low
  180108. bool juce_setThreadPriority (void* threadHandle, int priority)
  180109. {
  180110. int pri = THREAD_PRIORITY_TIME_CRITICAL;
  180111. if (priority < 1)
  180112. pri = THREAD_PRIORITY_IDLE;
  180113. else if (priority < 2)
  180114. pri = THREAD_PRIORITY_LOWEST;
  180115. else if (priority < 5)
  180116. pri = THREAD_PRIORITY_BELOW_NORMAL;
  180117. else if (priority < 7)
  180118. pri = THREAD_PRIORITY_NORMAL;
  180119. else if (priority < 9)
  180120. pri = THREAD_PRIORITY_ABOVE_NORMAL;
  180121. else if (priority < 10)
  180122. pri = THREAD_PRIORITY_HIGHEST;
  180123. if (threadHandle == 0)
  180124. threadHandle = GetCurrentThread();
  180125. return SetThreadPriority (threadHandle, pri) != FALSE;
  180126. }
  180127. void Thread::setCurrentThreadAffinityMask (const uint32 affinityMask)
  180128. {
  180129. SetThreadAffinityMask (GetCurrentThread(), affinityMask);
  180130. }
  180131. static HANDLE sleepEvent = 0;
  180132. void juce_initialiseThreadEvents()
  180133. {
  180134. if (sleepEvent == 0)
  180135. #ifdef JUCE_DEBUG
  180136. sleepEvent = CreateEvent (0, 0, 0, _T("Juce Sleep Event"));
  180137. #else
  180138. sleepEvent = CreateEvent (0, 0, 0, 0);
  180139. #endif
  180140. }
  180141. void Thread::yield()
  180142. {
  180143. Sleep (0);
  180144. }
  180145. void JUCE_CALLTYPE Thread::sleep (const int millisecs)
  180146. {
  180147. if (millisecs >= 10)
  180148. {
  180149. Sleep (millisecs);
  180150. }
  180151. else
  180152. {
  180153. jassert (sleepEvent != 0);
  180154. // unlike Sleep() this is guaranteed to return to the current thread after
  180155. // the time expires, so we'll use this for short waits, which are more likely
  180156. // to need to be accurate
  180157. WaitForSingleObject (sleepEvent, millisecs);
  180158. }
  180159. }
  180160. static int lastProcessPriority = -1;
  180161. // called by WindowDriver because Windows does wierd things to process priority
  180162. // when you swap apps, and this forces an update when the app is brought to the front.
  180163. void juce_repeatLastProcessPriority()
  180164. {
  180165. if (lastProcessPriority >= 0) // (avoid changing this if it's not been explicitly set by the app..)
  180166. {
  180167. DWORD p;
  180168. switch (lastProcessPriority)
  180169. {
  180170. case Process::LowPriority:
  180171. p = IDLE_PRIORITY_CLASS;
  180172. break;
  180173. case Process::NormalPriority:
  180174. p = NORMAL_PRIORITY_CLASS;
  180175. break;
  180176. case Process::HighPriority:
  180177. p = HIGH_PRIORITY_CLASS;
  180178. break;
  180179. case Process::RealtimePriority:
  180180. p = REALTIME_PRIORITY_CLASS;
  180181. break;
  180182. default:
  180183. jassertfalse // bad priority value
  180184. return;
  180185. }
  180186. SetPriorityClass (GetCurrentProcess(), p);
  180187. }
  180188. }
  180189. void Process::setPriority (ProcessPriority prior)
  180190. {
  180191. if (lastProcessPriority != (int) prior)
  180192. {
  180193. lastProcessPriority = (int) prior;
  180194. juce_repeatLastProcessPriority();
  180195. }
  180196. }
  180197. bool JUCE_PUBLIC_FUNCTION juce_isRunningUnderDebugger()
  180198. {
  180199. return IsDebuggerPresent() != FALSE;
  180200. }
  180201. bool JUCE_CALLTYPE Process::isRunningUnderDebugger()
  180202. {
  180203. return juce_isRunningUnderDebugger();
  180204. }
  180205. void Process::raisePrivilege()
  180206. {
  180207. jassertfalse // xxx not implemented
  180208. }
  180209. void Process::lowerPrivilege()
  180210. {
  180211. jassertfalse // xxx not implemented
  180212. }
  180213. void Process::terminate()
  180214. {
  180215. #if defined (JUCE_DEBUG) && JUCE_MSVC && JUCE_CHECK_MEMORY_LEAKS
  180216. _CrtDumpMemoryLeaks();
  180217. #endif
  180218. // bullet in the head in case there's a problem shutting down..
  180219. ExitProcess (0);
  180220. }
  180221. void* PlatformUtilities::loadDynamicLibrary (const String& name)
  180222. {
  180223. void* result = 0;
  180224. JUCE_TRY
  180225. {
  180226. result = (void*) LoadLibrary (name);
  180227. }
  180228. JUCE_CATCH_ALL
  180229. return result;
  180230. }
  180231. void PlatformUtilities::freeDynamicLibrary (void* h)
  180232. {
  180233. JUCE_TRY
  180234. {
  180235. if (h != 0)
  180236. FreeLibrary ((HMODULE) h);
  180237. }
  180238. JUCE_CATCH_ALL
  180239. }
  180240. void* PlatformUtilities::getProcedureEntryPoint (void* h, const String& name)
  180241. {
  180242. return (h != 0) ? (void*) GetProcAddress ((HMODULE) h, name)
  180243. : 0;
  180244. }
  180245. InterProcessLock::InterProcessLock (const String& name_)
  180246. : internal (0),
  180247. name (name_),
  180248. reentrancyLevel (0)
  180249. {
  180250. }
  180251. InterProcessLock::~InterProcessLock()
  180252. {
  180253. exit();
  180254. }
  180255. bool InterProcessLock::enter (const int timeOutMillisecs)
  180256. {
  180257. if (reentrancyLevel++ == 0)
  180258. {
  180259. internal = CreateMutex (0, TRUE, "Global\\" + name);
  180260. if (internal != 0 && GetLastError() == ERROR_ALREADY_EXISTS)
  180261. {
  180262. if (timeOutMillisecs == 0
  180263. || WaitForSingleObject (internal, (timeOutMillisecs < 0) ? INFINITE : timeOutMillisecs)
  180264. == WAIT_TIMEOUT)
  180265. {
  180266. ReleaseMutex (internal);
  180267. CloseHandle (internal);
  180268. internal = 0;
  180269. }
  180270. }
  180271. }
  180272. return (internal != 0);
  180273. }
  180274. void InterProcessLock::exit()
  180275. {
  180276. if (--reentrancyLevel == 0 && internal != 0)
  180277. {
  180278. ReleaseMutex (internal);
  180279. CloseHandle (internal);
  180280. internal = 0;
  180281. }
  180282. }
  180283. #endif
  180284. /*** End of inlined file: juce_win32_Threads.cpp ***/
  180285. /*** Start of inlined file: juce_win32_Files.cpp ***/
  180286. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  180287. // compiled on its own).
  180288. #if JUCE_INCLUDED_FILE
  180289. #ifndef CSIDL_MYMUSIC
  180290. #define CSIDL_MYMUSIC 0x000d
  180291. #endif
  180292. #ifndef CSIDL_MYVIDEO
  180293. #define CSIDL_MYVIDEO 0x000e
  180294. #endif
  180295. const tchar File::separator = T('\\');
  180296. const tchar* File::separatorString = T("\\");
  180297. bool juce_fileExists (const String& fileName, const bool dontCountDirectories)
  180298. {
  180299. if (fileName.isEmpty())
  180300. return false;
  180301. const DWORD attr = GetFileAttributes (fileName);
  180302. return dontCountDirectories ? ((attr & FILE_ATTRIBUTE_DIRECTORY) == 0)
  180303. : (attr != 0xffffffff);
  180304. }
  180305. bool juce_isDirectory (const String& fileName)
  180306. {
  180307. const DWORD attr = GetFileAttributes (fileName);
  180308. return (attr != 0xffffffff)
  180309. && ((attr & FILE_ATTRIBUTE_DIRECTORY) != 0);
  180310. }
  180311. bool juce_canWriteToFile (const String& fileName)
  180312. {
  180313. const DWORD attr = GetFileAttributes (fileName);
  180314. return ((attr & FILE_ATTRIBUTE_READONLY) == 0);
  180315. }
  180316. bool juce_setFileReadOnly (const String& fileName, bool isReadOnly)
  180317. {
  180318. DWORD attr = GetFileAttributes (fileName);
  180319. if (attr == 0xffffffff)
  180320. return false;
  180321. if (isReadOnly != juce_canWriteToFile (fileName))
  180322. return true;
  180323. if (isReadOnly)
  180324. attr |= FILE_ATTRIBUTE_READONLY;
  180325. else
  180326. attr &= ~FILE_ATTRIBUTE_READONLY;
  180327. return SetFileAttributes (fileName, attr) != FALSE;
  180328. }
  180329. bool File::isHidden() const
  180330. {
  180331. return (GetFileAttributes (getFullPathName()) & FILE_ATTRIBUTE_HIDDEN) != 0;
  180332. }
  180333. bool juce_deleteFile (const String& fileName)
  180334. {
  180335. if (juce_isDirectory (fileName))
  180336. return RemoveDirectory (fileName) != 0;
  180337. return DeleteFile (fileName) != 0;
  180338. }
  180339. bool File::moveToTrash() const
  180340. {
  180341. if (! exists())
  180342. return true;
  180343. SHFILEOPSTRUCT fos;
  180344. zerostruct (fos);
  180345. // The string we pass in must be double null terminated..
  180346. String doubleNullTermPath (getFullPathName() + " ");
  180347. TCHAR* p = (TCHAR*) (const TCHAR*) doubleNullTermPath;
  180348. p [getFullPathName().length()] = 0;
  180349. fos.wFunc = FO_DELETE;
  180350. fos.hwnd = (HWND) 0;
  180351. fos.pFrom = p;
  180352. fos.pTo = NULL;
  180353. fos.fFlags = FOF_ALLOWUNDO | FOF_NOERRORUI | FOF_SILENT | FOF_NOCONFIRMATION
  180354. | FOF_NOCONFIRMMKDIR | FOF_RENAMEONCOLLISION;
  180355. return SHFileOperation (&fos) == 0;
  180356. }
  180357. bool juce_moveFile (const String& source, const String& dest)
  180358. {
  180359. return MoveFile (source, dest) != 0;
  180360. }
  180361. bool juce_copyFile (const String& source, const String& dest)
  180362. {
  180363. return CopyFile (source, dest, false) != 0;
  180364. }
  180365. void juce_createDirectory (const String& fileName)
  180366. {
  180367. if (! juce_fileExists (fileName, true))
  180368. {
  180369. CreateDirectory (fileName, 0);
  180370. }
  180371. }
  180372. // return 0 if not possible
  180373. void* juce_fileOpen (const String& fileName, bool forWriting)
  180374. {
  180375. HANDLE h;
  180376. if (forWriting)
  180377. {
  180378. h = CreateFile (fileName, GENERIC_WRITE, FILE_SHARE_READ, 0,
  180379. OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
  180380. if (h != INVALID_HANDLE_VALUE)
  180381. SetFilePointer (h, 0, 0, FILE_END);
  180382. else
  180383. h = 0;
  180384. }
  180385. else
  180386. {
  180387. h = CreateFile (fileName, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, 0,
  180388. OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, 0);
  180389. if (h == INVALID_HANDLE_VALUE)
  180390. h = 0;
  180391. }
  180392. return (void*) h;
  180393. }
  180394. void juce_fileClose (void* handle)
  180395. {
  180396. CloseHandle (handle);
  180397. }
  180398. int juce_fileRead (void* handle, void* buffer, int size)
  180399. {
  180400. DWORD num = 0;
  180401. ReadFile ((HANDLE) handle, buffer, size, &num, 0);
  180402. return num;
  180403. }
  180404. int juce_fileWrite (void* handle, const void* buffer, int size)
  180405. {
  180406. DWORD num;
  180407. WriteFile ((HANDLE) handle,
  180408. buffer, size,
  180409. &num, 0);
  180410. return num;
  180411. }
  180412. int64 juce_fileSetPosition (void* handle, int64 pos)
  180413. {
  180414. LARGE_INTEGER li;
  180415. li.QuadPart = pos;
  180416. li.LowPart = SetFilePointer ((HANDLE) handle,
  180417. li.LowPart,
  180418. &li.HighPart,
  180419. FILE_BEGIN); // (returns -1 if it fails)
  180420. return li.QuadPart;
  180421. }
  180422. int64 juce_fileGetPosition (void* handle)
  180423. {
  180424. LARGE_INTEGER li;
  180425. li.QuadPart = 0;
  180426. li.LowPart = SetFilePointer ((HANDLE) handle,
  180427. 0, &li.HighPart,
  180428. FILE_CURRENT); // (returns -1 if it fails)
  180429. return jmax ((int64) 0, li.QuadPart);
  180430. }
  180431. void juce_fileFlush (void* handle)
  180432. {
  180433. FlushFileBuffers ((HANDLE) handle);
  180434. }
  180435. int64 juce_getFileSize (const String& fileName)
  180436. {
  180437. WIN32_FILE_ATTRIBUTE_DATA attributes;
  180438. if (GetFileAttributesEx (fileName, GetFileExInfoStandard, &attributes))
  180439. {
  180440. return (((int64) attributes.nFileSizeHigh) << 32)
  180441. | attributes.nFileSizeLow;
  180442. }
  180443. return 0;
  180444. }
  180445. static int64 fileTimeToTime (const FILETIME* const ft)
  180446. {
  180447. // tell me if this fails!
  180448. static_jassert (sizeof (ULARGE_INTEGER) == sizeof (FILETIME));
  180449. #if JUCE_GCC
  180450. return (((const ULARGE_INTEGER*) ft)->QuadPart - 116444736000000000LL) / 10000;
  180451. #else
  180452. return (((const ULARGE_INTEGER*) ft)->QuadPart - 116444736000000000) / 10000;
  180453. #endif
  180454. }
  180455. static void timeToFileTime (const int64 time, FILETIME* const ft)
  180456. {
  180457. #if JUCE_GCC
  180458. ((ULARGE_INTEGER*) ft)->QuadPart = time * 10000 + 116444736000000000LL;
  180459. #else
  180460. ((ULARGE_INTEGER*) ft)->QuadPart = time * 10000 + 116444736000000000;
  180461. #endif
  180462. }
  180463. void juce_getFileTimes (const String& fileName,
  180464. int64& modificationTime,
  180465. int64& accessTime,
  180466. int64& creationTime)
  180467. {
  180468. WIN32_FILE_ATTRIBUTE_DATA attributes;
  180469. if (GetFileAttributesEx (fileName, GetFileExInfoStandard, &attributes))
  180470. {
  180471. modificationTime = fileTimeToTime (&attributes.ftLastWriteTime);
  180472. creationTime = fileTimeToTime (&attributes.ftCreationTime);
  180473. accessTime = fileTimeToTime (&attributes.ftLastAccessTime);
  180474. }
  180475. else
  180476. {
  180477. creationTime = accessTime = modificationTime = 0;
  180478. }
  180479. }
  180480. bool juce_setFileTimes (const String& fileName,
  180481. int64 modificationTime,
  180482. int64 accessTime,
  180483. int64 creationTime)
  180484. {
  180485. FILETIME m, a, c;
  180486. if (modificationTime > 0)
  180487. timeToFileTime (modificationTime, &m);
  180488. if (accessTime > 0)
  180489. timeToFileTime (accessTime, &a);
  180490. if (creationTime > 0)
  180491. timeToFileTime (creationTime, &c);
  180492. void* const h = juce_fileOpen (fileName, true);
  180493. bool ok = false;
  180494. if (h != 0)
  180495. {
  180496. ok = SetFileTime ((HANDLE) h,
  180497. (creationTime > 0) ? &c : 0,
  180498. (accessTime > 0) ? &a : 0,
  180499. (modificationTime > 0) ? &m : 0) != 0;
  180500. juce_fileClose (h);
  180501. }
  180502. return ok;
  180503. }
  180504. // return '\0' separated list of strings
  180505. const StringArray juce_getFileSystemRoots()
  180506. {
  180507. TCHAR buffer [2048];
  180508. buffer[0] = 0;
  180509. buffer[1] = 0;
  180510. GetLogicalDriveStrings (2048, buffer);
  180511. TCHAR* n = buffer;
  180512. StringArray roots;
  180513. while (*n != 0)
  180514. {
  180515. roots.add (String (n));
  180516. while (*n++ != 0)
  180517. {
  180518. }
  180519. }
  180520. roots.sort (true);
  180521. return roots;
  180522. }
  180523. const String juce_getVolumeLabel (const String& filenameOnVolume,
  180524. int& volumeSerialNumber)
  180525. {
  180526. TCHAR n [4];
  180527. n[0] = *(const TCHAR*) filenameOnVolume;
  180528. n[1] = L':';
  180529. n[2] = L'\\';
  180530. n[3] = 0;
  180531. TCHAR dest [64];
  180532. DWORD serialNum;
  180533. if (! GetVolumeInformation (n, dest, 64, (DWORD*) &serialNum, 0, 0, 0, 0))
  180534. {
  180535. dest[0] = 0;
  180536. serialNum = 0;
  180537. }
  180538. volumeSerialNumber = serialNum;
  180539. return String (dest);
  180540. }
  180541. static int64 getDiskSpaceInfo (String fn, const bool total)
  180542. {
  180543. if (fn[1] == T(':'))
  180544. fn = fn.substring (0, 2) + T("\\");
  180545. ULARGE_INTEGER spc, tot, totFree;
  180546. if (GetDiskFreeSpaceEx (fn, &spc, &tot, &totFree))
  180547. return (int64) (total ? tot.QuadPart
  180548. : spc.QuadPart);
  180549. return 0;
  180550. }
  180551. int64 File::getBytesFreeOnVolume() const
  180552. {
  180553. return getDiskSpaceInfo (getFullPathName(), false);
  180554. }
  180555. int64 File::getVolumeTotalSize() const
  180556. {
  180557. return getDiskSpaceInfo (getFullPathName(), true);
  180558. }
  180559. static unsigned int getWindowsDriveType (const String& fileName)
  180560. {
  180561. TCHAR n[4];
  180562. n[0] = *(const TCHAR*) fileName;
  180563. n[1] = L':';
  180564. n[2] = L'\\';
  180565. n[3] = 0;
  180566. return GetDriveType (n);
  180567. }
  180568. bool File::isOnCDRomDrive() const
  180569. {
  180570. return getWindowsDriveType (getFullPathName()) == DRIVE_CDROM;
  180571. }
  180572. bool File::isOnHardDisk() const
  180573. {
  180574. if (fullPath.isEmpty())
  180575. return false;
  180576. const unsigned int n = getWindowsDriveType (getFullPathName());
  180577. if (fullPath.toLowerCase()[0] <= 'b'
  180578. && fullPath[1] == T(':'))
  180579. {
  180580. return n != DRIVE_REMOVABLE;
  180581. }
  180582. else
  180583. {
  180584. return n != DRIVE_CDROM && n != DRIVE_REMOTE;
  180585. }
  180586. }
  180587. bool File::isOnRemovableDrive() const
  180588. {
  180589. if (fullPath.isEmpty())
  180590. return false;
  180591. const unsigned int n = getWindowsDriveType (getFullPathName());
  180592. return n == DRIVE_CDROM
  180593. || n == DRIVE_REMOTE
  180594. || n == DRIVE_REMOVABLE
  180595. || n == DRIVE_RAMDISK;
  180596. }
  180597. #define MAX_PATH_CHARS (MAX_PATH + 256)
  180598. static const File juce_getSpecialFolderPath (int type)
  180599. {
  180600. WCHAR path [MAX_PATH_CHARS];
  180601. if (SHGetSpecialFolderPath (0, path, type, 0))
  180602. return File (String (path));
  180603. return File::nonexistent;
  180604. }
  180605. const File JUCE_CALLTYPE File::getSpecialLocation (const SpecialLocationType type)
  180606. {
  180607. int csidlType = 0;
  180608. switch (type)
  180609. {
  180610. case userHomeDirectory:
  180611. csidlType = CSIDL_PROFILE;
  180612. break;
  180613. case userDocumentsDirectory:
  180614. csidlType = CSIDL_PERSONAL;
  180615. break;
  180616. case userDesktopDirectory:
  180617. csidlType = CSIDL_DESKTOP;
  180618. break;
  180619. case userApplicationDataDirectory:
  180620. csidlType = CSIDL_APPDATA;
  180621. break;
  180622. case commonApplicationDataDirectory:
  180623. csidlType = CSIDL_COMMON_APPDATA;
  180624. break;
  180625. case globalApplicationsDirectory:
  180626. csidlType = CSIDL_PROGRAM_FILES;
  180627. break;
  180628. case userMusicDirectory:
  180629. csidlType = CSIDL_MYMUSIC;
  180630. break;
  180631. case userMoviesDirectory:
  180632. csidlType = CSIDL_MYVIDEO;
  180633. break;
  180634. case tempDirectory:
  180635. {
  180636. WCHAR dest [2048];
  180637. dest[0] = 0;
  180638. GetTempPath (2048, dest);
  180639. return File (String (dest));
  180640. }
  180641. case invokedExecutableFile:
  180642. case currentExecutableFile:
  180643. case currentApplicationFile:
  180644. {
  180645. HINSTANCE moduleHandle = (HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle();
  180646. WCHAR dest [MAX_PATH_CHARS];
  180647. dest[0] = 0;
  180648. GetModuleFileName (moduleHandle, dest, MAX_PATH_CHARS);
  180649. return File (String (dest));
  180650. }
  180651. break;
  180652. default:
  180653. jassertfalse // unknown type?
  180654. return File::nonexistent;
  180655. }
  180656. return juce_getSpecialFolderPath (csidlType);
  180657. }
  180658. const File File::getCurrentWorkingDirectory()
  180659. {
  180660. WCHAR dest [MAX_PATH_CHARS];
  180661. dest[0] = 0;
  180662. GetCurrentDirectory (MAX_PATH_CHARS, dest);
  180663. return File (String (dest));
  180664. }
  180665. bool File::setAsCurrentWorkingDirectory() const
  180666. {
  180667. return SetCurrentDirectory (getFullPathName()) != FALSE;
  180668. }
  180669. const String File::getVersion() const
  180670. {
  180671. String result;
  180672. DWORD handle = 0;
  180673. DWORD bufferSize = GetFileVersionInfoSize (getFullPathName(), &handle);
  180674. HeapBlock <char> buffer;
  180675. buffer.calloc (bufferSize);
  180676. if (GetFileVersionInfo (getFullPathName(), 0, bufferSize, buffer))
  180677. {
  180678. VS_FIXEDFILEINFO* vffi;
  180679. UINT len = 0;
  180680. if (VerQueryValue (buffer, (LPTSTR) _T("\\"), (LPVOID*) &vffi, &len))
  180681. {
  180682. result << (int) HIWORD (vffi->dwFileVersionMS) << "."
  180683. << (int) LOWORD (vffi->dwFileVersionMS) << "."
  180684. << (int) HIWORD (vffi->dwFileVersionLS) << "."
  180685. << (int) LOWORD (vffi->dwFileVersionLS);
  180686. }
  180687. }
  180688. return result;
  180689. }
  180690. const File File::getLinkedTarget() const
  180691. {
  180692. File result (*this);
  180693. String p (getFullPathName());
  180694. if (! exists())
  180695. p += T(".lnk");
  180696. else if (getFileExtension() != T(".lnk"))
  180697. return result;
  180698. ComSmartPtr <IShellLink> shellLink;
  180699. if (SUCCEEDED (shellLink.CoCreateInstance (CLSID_ShellLink, CLSCTX_INPROC_SERVER)))
  180700. {
  180701. ComSmartPtr <IPersistFile> persistFile;
  180702. if (SUCCEEDED (shellLink->QueryInterface (IID_IPersistFile, (LPVOID*) &persistFile)))
  180703. {
  180704. if (SUCCEEDED (persistFile->Load ((const WCHAR*) p, STGM_READ))
  180705. && SUCCEEDED (shellLink->Resolve (0, SLR_ANY_MATCH | SLR_NO_UI)))
  180706. {
  180707. WIN32_FIND_DATA winFindData;
  180708. WCHAR resolvedPath [MAX_PATH];
  180709. if (SUCCEEDED (shellLink->GetPath (resolvedPath, MAX_PATH, &winFindData, SLGP_UNCPRIORITY)))
  180710. result = File (resolvedPath);
  180711. }
  180712. }
  180713. }
  180714. return result;
  180715. }
  180716. template <class FindDataType>
  180717. static void getFindFileInfo (FindDataType& findData,
  180718. String& filename, bool* const isDir, bool* const isHidden,
  180719. int64* const fileSize, Time* const modTime, Time* const creationTime,
  180720. bool* const isReadOnly)
  180721. {
  180722. filename = findData.cFileName;
  180723. if (isDir != 0)
  180724. *isDir = ((findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0);
  180725. if (isHidden != 0)
  180726. *isHidden = ((findData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) != 0);
  180727. if (fileSize != 0)
  180728. *fileSize = findData.nFileSizeLow + (((int64) findData.nFileSizeHigh) << 32);
  180729. if (modTime != 0)
  180730. *modTime = fileTimeToTime (&findData.ftLastWriteTime);
  180731. if (creationTime != 0)
  180732. *creationTime = fileTimeToTime (&findData.ftCreationTime);
  180733. if (isReadOnly != 0)
  180734. *isReadOnly = ((findData.dwFileAttributes & FILE_ATTRIBUTE_READONLY) != 0);
  180735. }
  180736. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResult,
  180737. bool* isDir, bool* isHidden, int64* fileSize,
  180738. Time* modTime, Time* creationTime, bool* isReadOnly)
  180739. {
  180740. String wc (directory);
  180741. if (! wc.endsWithChar (File::separator))
  180742. wc += File::separator;
  180743. wc += wildCard;
  180744. WIN32_FIND_DATA findData;
  180745. HANDLE h = FindFirstFile (wc, &findData);
  180746. if (h != INVALID_HANDLE_VALUE)
  180747. {
  180748. getFindFileInfo (findData, firstResult, isDir, isHidden, fileSize,
  180749. modTime, creationTime, isReadOnly);
  180750. return h;
  180751. }
  180752. firstResult = String::empty;
  180753. return 0;
  180754. }
  180755. bool juce_findFileNext (void* handle, String& resultFile,
  180756. bool* isDir, bool* isHidden, int64* fileSize,
  180757. Time* modTime, Time* creationTime, bool* isReadOnly)
  180758. {
  180759. WIN32_FIND_DATA findData;
  180760. if (handle != 0 && FindNextFile ((HANDLE) handle, &findData) != 0)
  180761. {
  180762. getFindFileInfo (findData, resultFile, isDir, isHidden, fileSize,
  180763. modTime, creationTime, isReadOnly);
  180764. return true;
  180765. }
  180766. resultFile = String::empty;
  180767. return false;
  180768. }
  180769. void juce_findFileClose (void* handle)
  180770. {
  180771. FindClose (handle);
  180772. }
  180773. bool juce_launchFile (const String& fileName,
  180774. const String& parameters)
  180775. {
  180776. HINSTANCE hInstance = 0;
  180777. JUCE_TRY
  180778. {
  180779. hInstance = ShellExecute (0, 0, fileName, parameters, 0, SW_SHOWDEFAULT);
  180780. }
  180781. JUCE_CATCH_ALL
  180782. return hInstance > (HINSTANCE) 32;
  180783. }
  180784. void File::revealToUser() const
  180785. {
  180786. if (isDirectory())
  180787. startAsProcess();
  180788. else if (getParentDirectory().exists())
  180789. getParentDirectory().startAsProcess();
  180790. }
  180791. struct NamedPipeInternal
  180792. {
  180793. HANDLE pipeH;
  180794. HANDLE cancelEvent;
  180795. bool connected, createdPipe;
  180796. NamedPipeInternal()
  180797. : pipeH (0),
  180798. cancelEvent (0),
  180799. connected (false),
  180800. createdPipe (false)
  180801. {
  180802. cancelEvent = CreateEvent (0, FALSE, FALSE, 0);
  180803. }
  180804. ~NamedPipeInternal()
  180805. {
  180806. disconnect();
  180807. if (pipeH != 0)
  180808. CloseHandle (pipeH);
  180809. CloseHandle (cancelEvent);
  180810. }
  180811. bool connect (const int timeOutMs)
  180812. {
  180813. if (! createdPipe)
  180814. return true;
  180815. if (! connected)
  180816. {
  180817. OVERLAPPED over;
  180818. zerostruct (over);
  180819. over.hEvent = CreateEvent (0, TRUE, FALSE, 0);
  180820. if (ConnectNamedPipe (pipeH, &over))
  180821. {
  180822. connected = false; // yes, you read that right. In overlapped mode it should always return 0.
  180823. }
  180824. else
  180825. {
  180826. const int err = GetLastError();
  180827. if (err == ERROR_IO_PENDING || err == ERROR_PIPE_LISTENING)
  180828. {
  180829. HANDLE handles[] = { over.hEvent, cancelEvent };
  180830. if (WaitForMultipleObjects (2, handles, FALSE,
  180831. timeOutMs >= 0 ? timeOutMs : INFINITE) == WAIT_OBJECT_0)
  180832. connected = true;
  180833. }
  180834. else if (err == ERROR_PIPE_CONNECTED)
  180835. {
  180836. connected = true;
  180837. }
  180838. }
  180839. CloseHandle (over.hEvent);
  180840. }
  180841. return connected;
  180842. }
  180843. void disconnect()
  180844. {
  180845. if (connected)
  180846. {
  180847. DisconnectNamedPipe (pipeH);
  180848. connected = false;
  180849. }
  180850. }
  180851. };
  180852. void NamedPipe::close()
  180853. {
  180854. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  180855. delete intern;
  180856. internal = 0;
  180857. }
  180858. bool NamedPipe::openInternal (const String& pipeName, const bool createPipe)
  180859. {
  180860. close();
  180861. NamedPipeInternal* const intern = new NamedPipeInternal();
  180862. String file ("\\\\.\\pipe\\");
  180863. file += pipeName;
  180864. intern->createdPipe = createPipe;
  180865. if (createPipe)
  180866. {
  180867. intern->pipeH = CreateNamedPipe (file, PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED, 0,
  180868. PIPE_UNLIMITED_INSTANCES,
  180869. 4096, 4096, 0, NULL);
  180870. }
  180871. else
  180872. {
  180873. intern->pipeH = CreateFile (file, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING,
  180874. FILE_FLAG_OVERLAPPED, 0);
  180875. }
  180876. if (intern->pipeH != INVALID_HANDLE_VALUE)
  180877. {
  180878. internal = intern;
  180879. return true;
  180880. }
  180881. delete intern;
  180882. return false;
  180883. }
  180884. int NamedPipe::read (void* destBuffer, int maxBytesToRead, int timeOutMilliseconds)
  180885. {
  180886. int bytesRead = -1;
  180887. bool waitAgain = true;
  180888. while (waitAgain && internal != 0)
  180889. {
  180890. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  180891. waitAgain = false;
  180892. if (! intern->connect (timeOutMilliseconds))
  180893. break;
  180894. if (maxBytesToRead <= 0)
  180895. return 0;
  180896. OVERLAPPED over;
  180897. zerostruct (over);
  180898. over.hEvent = CreateEvent (0, TRUE, FALSE, 0);
  180899. unsigned long numRead;
  180900. if (ReadFile (intern->pipeH, destBuffer, maxBytesToRead, &numRead, &over))
  180901. {
  180902. bytesRead = (int) numRead;
  180903. }
  180904. else if (GetLastError() == ERROR_IO_PENDING)
  180905. {
  180906. HANDLE handles[] = { over.hEvent, intern->cancelEvent };
  180907. DWORD waitResult = WaitForMultipleObjects (2, handles, FALSE,
  180908. timeOutMilliseconds >= 0 ? timeOutMilliseconds
  180909. : INFINITE);
  180910. if (waitResult != WAIT_OBJECT_0)
  180911. {
  180912. // if the operation timed out, let's cancel it...
  180913. CancelIo (intern->pipeH);
  180914. WaitForSingleObject (over.hEvent, INFINITE); // makes sure cancel is complete
  180915. }
  180916. if (GetOverlappedResult (intern->pipeH, &over, &numRead, FALSE))
  180917. {
  180918. bytesRead = (int) numRead;
  180919. }
  180920. else if (GetLastError() == ERROR_BROKEN_PIPE && intern->createdPipe)
  180921. {
  180922. intern->disconnect();
  180923. waitAgain = true;
  180924. }
  180925. }
  180926. else
  180927. {
  180928. waitAgain = internal != 0;
  180929. Sleep (5);
  180930. }
  180931. CloseHandle (over.hEvent);
  180932. }
  180933. return bytesRead;
  180934. }
  180935. int NamedPipe::write (const void* sourceBuffer, int numBytesToWrite, int timeOutMilliseconds)
  180936. {
  180937. int bytesWritten = -1;
  180938. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  180939. if (intern != 0 && intern->connect (timeOutMilliseconds))
  180940. {
  180941. if (numBytesToWrite <= 0)
  180942. return 0;
  180943. OVERLAPPED over;
  180944. zerostruct (over);
  180945. over.hEvent = CreateEvent (0, TRUE, FALSE, 0);
  180946. unsigned long numWritten;
  180947. if (WriteFile (intern->pipeH, sourceBuffer, numBytesToWrite, &numWritten, &over))
  180948. {
  180949. bytesWritten = (int) numWritten;
  180950. }
  180951. else if (GetLastError() == ERROR_IO_PENDING)
  180952. {
  180953. HANDLE handles[] = { over.hEvent, intern->cancelEvent };
  180954. DWORD waitResult;
  180955. waitResult = WaitForMultipleObjects (2, handles, FALSE,
  180956. timeOutMilliseconds >= 0 ? timeOutMilliseconds
  180957. : INFINITE);
  180958. if (waitResult != WAIT_OBJECT_0)
  180959. {
  180960. CancelIo (intern->pipeH);
  180961. WaitForSingleObject (over.hEvent, INFINITE);
  180962. }
  180963. if (GetOverlappedResult (intern->pipeH, &over, &numWritten, FALSE))
  180964. {
  180965. bytesWritten = (int) numWritten;
  180966. }
  180967. else if (GetLastError() == ERROR_BROKEN_PIPE && intern->createdPipe)
  180968. {
  180969. intern->disconnect();
  180970. }
  180971. }
  180972. CloseHandle (over.hEvent);
  180973. }
  180974. return bytesWritten;
  180975. }
  180976. void NamedPipe::cancelPendingReads()
  180977. {
  180978. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  180979. if (intern != 0)
  180980. SetEvent (intern->cancelEvent);
  180981. }
  180982. #endif
  180983. /*** End of inlined file: juce_win32_Files.cpp ***/
  180984. /*** Start of inlined file: juce_win32_Network.cpp ***/
  180985. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  180986. // compiled on its own).
  180987. #if JUCE_INCLUDED_FILE
  180988. #ifndef INTERNET_FLAG_NEED_FILE
  180989. #define INTERNET_FLAG_NEED_FILE 0x00000010
  180990. #endif
  180991. #ifndef INTERNET_OPTION_DISABLE_AUTODIAL
  180992. #define INTERNET_OPTION_DISABLE_AUTODIAL 70
  180993. #endif
  180994. bool juce_isOnLine()
  180995. {
  180996. DWORD connectionType;
  180997. return InternetGetConnectedState (&connectionType, 0) != 0
  180998. || (connectionType & (INTERNET_CONNECTION_LAN | INTERNET_CONNECTION_PROXY)) != 0;
  180999. }
  181000. struct ConnectionAndRequestStruct
  181001. {
  181002. HINTERNET connection, request;
  181003. };
  181004. static HINTERNET sessionHandle = 0;
  181005. #ifndef WORKAROUND_TIMEOUT_BUG
  181006. //#define WORKAROUND_TIMEOUT_BUG 1
  181007. #endif
  181008. #if WORKAROUND_TIMEOUT_BUG
  181009. // Required because of a Microsoft bug in setting a timeout
  181010. class InternetConnectThread : public Thread
  181011. {
  181012. public:
  181013. InternetConnectThread (URL_COMPONENTS& uc_, HINTERNET& connection_, const bool isFtp_)
  181014. : Thread ("Internet"), uc (uc_), connection (connection_), isFtp (isFtp_)
  181015. {
  181016. startThread();
  181017. }
  181018. ~InternetConnectThread()
  181019. {
  181020. stopThread (60000);
  181021. }
  181022. void run()
  181023. {
  181024. connection = InternetConnect (sessionHandle, uc.lpszHostName,
  181025. uc.nPort, _T(""), _T(""),
  181026. isFtp ? INTERNET_SERVICE_FTP
  181027. : INTERNET_SERVICE_HTTP,
  181028. 0, 0);
  181029. notify();
  181030. }
  181031. juce_UseDebuggingNewOperator
  181032. private:
  181033. URL_COMPONENTS& uc;
  181034. HINTERNET& connection;
  181035. const bool isFtp;
  181036. InternetConnectThread (const InternetConnectThread&);
  181037. InternetConnectThread& operator= (const InternetConnectThread&);
  181038. };
  181039. #endif
  181040. void* juce_openInternetFile (const String& url,
  181041. const String& headers,
  181042. const MemoryBlock& postData,
  181043. const bool isPost,
  181044. URL::OpenStreamProgressCallback* callback,
  181045. void* callbackContext,
  181046. int timeOutMs)
  181047. {
  181048. if (sessionHandle == 0)
  181049. sessionHandle = InternetOpen (_T("juce"),
  181050. INTERNET_OPEN_TYPE_PRECONFIG,
  181051. 0, 0, 0);
  181052. if (sessionHandle != 0)
  181053. {
  181054. // break up the url..
  181055. TCHAR file[1024], server[1024];
  181056. URL_COMPONENTS uc;
  181057. zerostruct (uc);
  181058. uc.dwStructSize = sizeof (uc);
  181059. uc.dwUrlPathLength = sizeof (file);
  181060. uc.dwHostNameLength = sizeof (server);
  181061. uc.lpszUrlPath = file;
  181062. uc.lpszHostName = server;
  181063. if (InternetCrackUrl (url, 0, 0, &uc))
  181064. {
  181065. int disable = 1;
  181066. InternetSetOption (sessionHandle, INTERNET_OPTION_DISABLE_AUTODIAL, &disable, sizeof (disable));
  181067. if (timeOutMs == 0)
  181068. timeOutMs = 30000;
  181069. else if (timeOutMs < 0)
  181070. timeOutMs = -1;
  181071. InternetSetOption (sessionHandle, INTERNET_OPTION_CONNECT_TIMEOUT, &timeOutMs, sizeof (timeOutMs));
  181072. const bool isFtp = url.startsWithIgnoreCase (T("ftp:"));
  181073. #if WORKAROUND_TIMEOUT_BUG
  181074. HINTERNET connection = 0;
  181075. {
  181076. InternetConnectThread connectThread (uc, connection, isFtp);
  181077. connectThread.wait (timeOutMs);
  181078. if (connection == 0)
  181079. {
  181080. InternetCloseHandle (sessionHandle);
  181081. sessionHandle = 0;
  181082. }
  181083. }
  181084. #else
  181085. HINTERNET connection = InternetConnect (sessionHandle,
  181086. uc.lpszHostName,
  181087. uc.nPort,
  181088. _T(""), _T(""),
  181089. isFtp ? INTERNET_SERVICE_FTP
  181090. : INTERNET_SERVICE_HTTP,
  181091. 0, 0);
  181092. #endif
  181093. if (connection != 0)
  181094. {
  181095. if (isFtp)
  181096. {
  181097. HINTERNET request = FtpOpenFile (connection,
  181098. uc.lpszUrlPath,
  181099. GENERIC_READ,
  181100. FTP_TRANSFER_TYPE_BINARY | INTERNET_FLAG_NEED_FILE,
  181101. 0);
  181102. ConnectionAndRequestStruct* const result = new ConnectionAndRequestStruct();
  181103. result->connection = connection;
  181104. result->request = request;
  181105. return result;
  181106. }
  181107. else
  181108. {
  181109. const TCHAR* mimeTypes[] = { _T("*/*"), 0 };
  181110. DWORD flags = INTERNET_FLAG_RELOAD | INTERNET_FLAG_NO_CACHE_WRITE;
  181111. if (url.startsWithIgnoreCase (T("https:")))
  181112. flags |= INTERNET_FLAG_SECURE; // (this flag only seems necessary if the OS is running IE6 -
  181113. // IE7 seems to automatically work out when it's https)
  181114. HINTERNET request = HttpOpenRequest (connection,
  181115. isPost ? _T("POST")
  181116. : _T("GET"),
  181117. uc.lpszUrlPath,
  181118. 0, 0, mimeTypes, flags, 0);
  181119. if (request != 0)
  181120. {
  181121. INTERNET_BUFFERS buffers;
  181122. zerostruct (buffers);
  181123. buffers.dwStructSize = sizeof (INTERNET_BUFFERS);
  181124. buffers.lpcszHeader = (LPCTSTR) headers;
  181125. buffers.dwHeadersLength = headers.length();
  181126. buffers.dwBufferTotal = (DWORD) postData.getSize();
  181127. ConnectionAndRequestStruct* result = 0;
  181128. if (HttpSendRequestEx (request, &buffers, 0, HSR_INITIATE, 0))
  181129. {
  181130. int bytesSent = 0;
  181131. for (;;)
  181132. {
  181133. const int bytesToDo = jmin (1024, (int) postData.getSize() - bytesSent);
  181134. DWORD bytesDone = 0;
  181135. if (bytesToDo > 0
  181136. && ! InternetWriteFile (request,
  181137. ((const char*) postData.getData()) + bytesSent,
  181138. bytesToDo, &bytesDone))
  181139. {
  181140. break;
  181141. }
  181142. if (bytesToDo == 0 || (int) bytesDone < bytesToDo)
  181143. {
  181144. result = new ConnectionAndRequestStruct();
  181145. result->connection = connection;
  181146. result->request = request;
  181147. HttpEndRequest (request, 0, 0, 0);
  181148. return result;
  181149. }
  181150. bytesSent += bytesDone;
  181151. if (callback != 0 && ! callback (callbackContext, bytesSent, postData.getSize()))
  181152. break;
  181153. }
  181154. }
  181155. InternetCloseHandle (request);
  181156. }
  181157. InternetCloseHandle (connection);
  181158. }
  181159. }
  181160. }
  181161. }
  181162. return 0;
  181163. }
  181164. int juce_readFromInternetFile (void* handle, void* buffer, int bytesToRead)
  181165. {
  181166. DWORD bytesRead = 0;
  181167. const ConnectionAndRequestStruct* const crs = (const ConnectionAndRequestStruct*) handle;
  181168. if (crs != 0)
  181169. InternetReadFile (crs->request,
  181170. buffer, bytesToRead,
  181171. &bytesRead);
  181172. return bytesRead;
  181173. }
  181174. int juce_seekInInternetFile (void* handle, int newPosition)
  181175. {
  181176. if (handle != 0)
  181177. {
  181178. const ConnectionAndRequestStruct* const crs = (const ConnectionAndRequestStruct*) handle;
  181179. return InternetSetFilePointer (crs->request,
  181180. newPosition, 0,
  181181. FILE_BEGIN, 0);
  181182. }
  181183. else
  181184. {
  181185. return -1;
  181186. }
  181187. }
  181188. int64 juce_getInternetFileContentLength (void* handle)
  181189. {
  181190. const ConnectionAndRequestStruct* const crs = (const ConnectionAndRequestStruct*) handle;
  181191. if (crs != 0)
  181192. {
  181193. DWORD index = 0;
  181194. DWORD result = 0;
  181195. DWORD size = sizeof (result);
  181196. if (HttpQueryInfo (crs->request,
  181197. HTTP_QUERY_CONTENT_LENGTH | HTTP_QUERY_FLAG_NUMBER,
  181198. &result,
  181199. &size,
  181200. &index))
  181201. {
  181202. return (int64) result;
  181203. }
  181204. }
  181205. return -1;
  181206. }
  181207. void juce_closeInternetFile (void* handle)
  181208. {
  181209. if (handle != 0)
  181210. {
  181211. ConnectionAndRequestStruct* const crs = (ConnectionAndRequestStruct*) handle;
  181212. InternetCloseHandle (crs->request);
  181213. InternetCloseHandle (crs->connection);
  181214. delete crs;
  181215. }
  181216. }
  181217. static int getMACAddressViaGetAdaptersInfo (int64* addresses, int maxNum, const bool littleEndian) throw()
  181218. {
  181219. int numFound = 0;
  181220. DynamicLibraryLoader dll ("iphlpapi.dll");
  181221. DynamicLibraryImport (GetAdaptersInfo, getAdaptersInfo, DWORD, dll, (PIP_ADAPTER_INFO, PULONG))
  181222. if (getAdaptersInfo != 0)
  181223. {
  181224. ULONG len = sizeof (IP_ADAPTER_INFO);
  181225. MemoryBlock mb;
  181226. PIP_ADAPTER_INFO adapterInfo = (PIP_ADAPTER_INFO) mb.getData();
  181227. if (getAdaptersInfo (adapterInfo, &len) == ERROR_BUFFER_OVERFLOW)
  181228. {
  181229. mb.setSize (len);
  181230. adapterInfo = (PIP_ADAPTER_INFO) mb.getData();
  181231. }
  181232. if (getAdaptersInfo (adapterInfo, &len) == NO_ERROR)
  181233. {
  181234. PIP_ADAPTER_INFO adapter = adapterInfo;
  181235. while (adapter != 0)
  181236. {
  181237. int64 mac = 0;
  181238. for (unsigned int i = 0; i < adapter->AddressLength; ++i)
  181239. mac = (mac << 8) | adapter->Address[i];
  181240. if (littleEndian)
  181241. mac = (int64) ByteOrder::swap ((uint64) mac);
  181242. if (numFound < maxNum && mac != 0)
  181243. addresses [numFound++] = mac;
  181244. adapter = adapter->Next;
  181245. }
  181246. }
  181247. }
  181248. return numFound;
  181249. }
  181250. struct ASTAT
  181251. {
  181252. ADAPTER_STATUS adapt;
  181253. NAME_BUFFER NameBuff [30];
  181254. };
  181255. static int getMACAddressesViaNetBios (int64* addresses, int maxNum, const bool littleEndian) throw()
  181256. {
  181257. int numFound = 0;
  181258. DynamicLibraryLoader dll ("netapi32.dll");
  181259. DynamicLibraryImport (Netbios, NetbiosCall, UCHAR, dll, (PNCB))
  181260. if (NetbiosCall != 0)
  181261. {
  181262. NCB ncb;
  181263. zerostruct (ncb);
  181264. ASTAT astat;
  181265. zerostruct (astat);
  181266. LANA_ENUM enums;
  181267. zerostruct (enums);
  181268. ncb.ncb_command = NCBENUM;
  181269. ncb.ncb_buffer = (unsigned char*) &enums;
  181270. ncb.ncb_length = sizeof (LANA_ENUM);
  181271. NetbiosCall (&ncb);
  181272. for (int i = 0; i < enums.length; ++i)
  181273. {
  181274. zerostruct (ncb);
  181275. ncb.ncb_command = NCBRESET;
  181276. ncb.ncb_lana_num = enums.lana[i];
  181277. if (NetbiosCall (&ncb) == 0)
  181278. {
  181279. zerostruct (ncb);
  181280. memcpy (ncb.ncb_callname, "* ", NCBNAMSZ);
  181281. ncb.ncb_command = NCBASTAT;
  181282. ncb.ncb_lana_num = enums.lana[i];
  181283. ncb.ncb_buffer = (unsigned char*) &astat;
  181284. ncb.ncb_length = sizeof (ASTAT);
  181285. if (NetbiosCall (&ncb) == 0)
  181286. {
  181287. if (astat.adapt.adapter_type == 0xfe)
  181288. {
  181289. uint64 mac = 0;
  181290. for (int i = 6; --i >= 0;)
  181291. mac = (mac << 8) | astat.adapt.adapter_address [littleEndian ? i : (5 - i)];
  181292. if (numFound < maxNum && mac != 0)
  181293. addresses [numFound++] = mac;
  181294. }
  181295. }
  181296. }
  181297. }
  181298. }
  181299. return numFound;
  181300. }
  181301. int SystemStats::getMACAddresses (int64* addresses, int maxNum, const bool littleEndian) throw()
  181302. {
  181303. int numFound = getMACAddressViaGetAdaptersInfo (addresses, maxNum, littleEndian);
  181304. if (numFound == 0)
  181305. numFound = getMACAddressesViaNetBios (addresses, maxNum, littleEndian);
  181306. return numFound;
  181307. }
  181308. typedef ULONG (WINAPI *MAPISendMailType) (LHANDLE, ULONG, lpMapiMessage, ::FLAGS, ULONG);
  181309. bool PlatformUtilities::launchEmailWithAttachments (const String& targetEmailAddress,
  181310. const String& emailSubject,
  181311. const String& bodyText,
  181312. const StringArray& filesToAttach)
  181313. {
  181314. HMODULE h = LoadLibraryA ("MAPI32.dll");
  181315. MAPISendMailType mapiSendMail = (MAPISendMailType) GetProcAddress (h, "MAPISendMail");
  181316. bool ok = false;
  181317. if (mapiSendMail != 0)
  181318. {
  181319. MapiMessage message;
  181320. zerostruct (message);
  181321. message.lpszSubject = (LPSTR) (LPCSTR) emailSubject;
  181322. message.lpszNoteText = (LPSTR) (LPCSTR) bodyText;
  181323. MapiRecipDesc recip;
  181324. zerostruct (recip);
  181325. recip.ulRecipClass = MAPI_TO;
  181326. String targetEmailAddress_ (targetEmailAddress);
  181327. if (targetEmailAddress_.isEmpty())
  181328. targetEmailAddress_ = " "; // (Windows Mail can't deal with a blank address)
  181329. recip.lpszName = (LPSTR) (LPCSTR) targetEmailAddress_;
  181330. message.nRecipCount = 1;
  181331. message.lpRecips = &recip;
  181332. MemoryBlock mb (sizeof (MapiFileDesc) * filesToAttach.size());
  181333. mb.fillWith (0);
  181334. MapiFileDesc* files = (MapiFileDesc*) mb.getData();
  181335. message.nFileCount = filesToAttach.size();
  181336. message.lpFiles = files;
  181337. for (int i = 0; i < filesToAttach.size(); ++i)
  181338. {
  181339. files[i].nPosition = (ULONG) -1;
  181340. files[i].lpszPathName = (LPSTR) (LPCSTR) filesToAttach [i];
  181341. }
  181342. ok = (mapiSendMail (0, 0, &message, MAPI_DIALOG | MAPI_LOGON_UI, 0) == SUCCESS_SUCCESS);
  181343. }
  181344. FreeLibrary (h);
  181345. return ok;
  181346. }
  181347. #endif
  181348. /*** End of inlined file: juce_win32_Network.cpp ***/
  181349. /*** Start of inlined file: juce_win32_PlatformUtils.cpp ***/
  181350. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  181351. // compiled on its own).
  181352. #if JUCE_INCLUDED_FILE
  181353. static HKEY findKeyForPath (String name,
  181354. const bool createForWriting,
  181355. String& valueName)
  181356. {
  181357. HKEY rootKey = 0;
  181358. if (name.startsWithIgnoreCase (T("HKEY_CURRENT_USER\\")))
  181359. rootKey = HKEY_CURRENT_USER;
  181360. else if (name.startsWithIgnoreCase (T("HKEY_LOCAL_MACHINE\\")))
  181361. rootKey = HKEY_LOCAL_MACHINE;
  181362. else if (name.startsWithIgnoreCase (T("HKEY_CLASSES_ROOT\\")))
  181363. rootKey = HKEY_CLASSES_ROOT;
  181364. if (rootKey != 0)
  181365. {
  181366. name = name.substring (name.indexOfChar (T('\\')) + 1);
  181367. const int lastSlash = name.lastIndexOfChar (T('\\'));
  181368. valueName = name.substring (lastSlash + 1);
  181369. name = name.substring (0, lastSlash);
  181370. HKEY key;
  181371. DWORD result;
  181372. if (createForWriting)
  181373. {
  181374. if (RegCreateKeyEx (rootKey, name, 0, 0, REG_OPTION_NON_VOLATILE,
  181375. (KEY_WRITE | KEY_QUERY_VALUE), 0, &key, &result) == ERROR_SUCCESS)
  181376. return key;
  181377. }
  181378. else
  181379. {
  181380. if (RegOpenKeyEx (rootKey, name, 0, KEY_READ, &key) == ERROR_SUCCESS)
  181381. return key;
  181382. }
  181383. }
  181384. return 0;
  181385. }
  181386. const String PlatformUtilities::getRegistryValue (const String& regValuePath,
  181387. const String& defaultValue)
  181388. {
  181389. String valueName, result (defaultValue);
  181390. HKEY k = findKeyForPath (regValuePath, false, valueName);
  181391. if (k != 0)
  181392. {
  181393. WCHAR buffer [2048];
  181394. unsigned long bufferSize = sizeof (buffer);
  181395. DWORD type = REG_SZ;
  181396. if (RegQueryValueEx (k, valueName, 0, &type, (LPBYTE) buffer, &bufferSize) == ERROR_SUCCESS)
  181397. {
  181398. if (type == REG_SZ)
  181399. result = buffer;
  181400. else if (type == REG_DWORD)
  181401. result = String ((int) *(DWORD*) buffer);
  181402. }
  181403. RegCloseKey (k);
  181404. }
  181405. return result;
  181406. }
  181407. void PlatformUtilities::setRegistryValue (const String& regValuePath,
  181408. const String& value)
  181409. {
  181410. String valueName;
  181411. HKEY k = findKeyForPath (regValuePath, true, valueName);
  181412. if (k != 0)
  181413. {
  181414. RegSetValueEx (k, valueName, 0, REG_SZ,
  181415. (const BYTE*) (const WCHAR*) value,
  181416. sizeof (WCHAR) * (value.length() + 1));
  181417. RegCloseKey (k);
  181418. }
  181419. }
  181420. bool PlatformUtilities::registryValueExists (const String& regValuePath)
  181421. {
  181422. bool exists = false;
  181423. String valueName;
  181424. HKEY k = findKeyForPath (regValuePath, false, valueName);
  181425. if (k != 0)
  181426. {
  181427. unsigned char buffer [2048];
  181428. unsigned long bufferSize = sizeof (buffer);
  181429. DWORD type = 0;
  181430. if (RegQueryValueEx (k, valueName, 0, &type, buffer, &bufferSize) == ERROR_SUCCESS)
  181431. exists = true;
  181432. RegCloseKey (k);
  181433. }
  181434. return exists;
  181435. }
  181436. void PlatformUtilities::deleteRegistryValue (const String& regValuePath)
  181437. {
  181438. String valueName;
  181439. HKEY k = findKeyForPath (regValuePath, true, valueName);
  181440. if (k != 0)
  181441. {
  181442. RegDeleteValue (k, valueName);
  181443. RegCloseKey (k);
  181444. }
  181445. }
  181446. void PlatformUtilities::deleteRegistryKey (const String& regKeyPath)
  181447. {
  181448. String valueName;
  181449. HKEY k = findKeyForPath (regKeyPath, true, valueName);
  181450. if (k != 0)
  181451. {
  181452. RegDeleteKey (k, valueName);
  181453. RegCloseKey (k);
  181454. }
  181455. }
  181456. void PlatformUtilities::registerFileAssociation (const String& fileExtension,
  181457. const String& symbolicDescription,
  181458. const String& fullDescription,
  181459. const File& targetExecutable,
  181460. int iconResourceNumber)
  181461. {
  181462. setRegistryValue ("HKEY_CLASSES_ROOT\\" + fileExtension + "\\", symbolicDescription);
  181463. const String key ("HKEY_CLASSES_ROOT\\" + symbolicDescription);
  181464. if (iconResourceNumber != 0)
  181465. setRegistryValue (key + "\\DefaultIcon\\",
  181466. targetExecutable.getFullPathName() + "," + String (-iconResourceNumber));
  181467. setRegistryValue (key + "\\", fullDescription);
  181468. setRegistryValue (key + "\\shell\\open\\command\\",
  181469. targetExecutable.getFullPathName() + " %1");
  181470. }
  181471. bool juce_IsRunningInWine()
  181472. {
  181473. HKEY key;
  181474. if (RegOpenKeyEx (HKEY_CURRENT_USER, _T("Software\\Wine"), 0, KEY_READ, &key) == ERROR_SUCCESS)
  181475. {
  181476. RegCloseKey (key);
  181477. return true;
  181478. }
  181479. return false;
  181480. }
  181481. const String JUCE_CALLTYPE PlatformUtilities::getCurrentCommandLineParams() throw()
  181482. {
  181483. String s (::GetCommandLineW());
  181484. StringArray tokens;
  181485. tokens.addTokens (s, true); // tokenise so that we can remove the initial filename argument
  181486. return tokens.joinIntoString (T(" "), 1);
  181487. }
  181488. static void* currentModuleHandle = 0;
  181489. void* PlatformUtilities::getCurrentModuleInstanceHandle() throw()
  181490. {
  181491. if (currentModuleHandle == 0)
  181492. currentModuleHandle = GetModuleHandle (0);
  181493. return currentModuleHandle;
  181494. }
  181495. void PlatformUtilities::setCurrentModuleInstanceHandle (void* const newHandle) throw()
  181496. {
  181497. currentModuleHandle = newHandle;
  181498. }
  181499. void PlatformUtilities::fpuReset()
  181500. {
  181501. #if JUCE_MSVC
  181502. _clearfp();
  181503. #endif
  181504. }
  181505. void PlatformUtilities::beep()
  181506. {
  181507. MessageBeep (MB_OK);
  181508. }
  181509. #endif
  181510. /*** End of inlined file: juce_win32_PlatformUtils.cpp ***/
  181511. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  181512. /*** Start of inlined file: juce_win32_Messaging.cpp ***/
  181513. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  181514. // compiled on its own).
  181515. #if JUCE_INCLUDED_FILE
  181516. static const unsigned int specialId = WM_APP + 0x4400;
  181517. static const unsigned int broadcastId = WM_APP + 0x4403;
  181518. static const unsigned int specialCallbackId = WM_APP + 0x4402;
  181519. static const TCHAR* const messageWindowName = _T("JUCEWindow");
  181520. HWND juce_messageWindowHandle = 0;
  181521. extern long improbableWindowNumber; // defined in windowing.cpp
  181522. #ifndef WM_APPCOMMAND
  181523. #define WM_APPCOMMAND 0x0319
  181524. #endif
  181525. static LRESULT CALLBACK juce_MessageWndProc (HWND h,
  181526. const UINT message,
  181527. const WPARAM wParam,
  181528. const LPARAM lParam) throw()
  181529. {
  181530. JUCE_TRY
  181531. {
  181532. if (h == juce_messageWindowHandle)
  181533. {
  181534. if (message == specialCallbackId)
  181535. {
  181536. MessageCallbackFunction* const func = (MessageCallbackFunction*) wParam;
  181537. return (LRESULT) (*func) ((void*) lParam);
  181538. }
  181539. else if (message == specialId)
  181540. {
  181541. // these are trapped early in the dispatch call, but must also be checked
  181542. // here in case there are windows modal dialog boxes doing their own
  181543. // dispatch loop and not calling our version
  181544. MessageManager::getInstance()->deliverMessage ((void*) lParam);
  181545. return 0;
  181546. }
  181547. else if (message == broadcastId)
  181548. {
  181549. const ScopedPointer <String> messageString ((String*) lParam);
  181550. MessageManager::getInstance()->deliverBroadcastMessage (*messageString);
  181551. return 0;
  181552. }
  181553. else if (message == WM_COPYDATA && ((const COPYDATASTRUCT*) lParam)->dwData == broadcastId)
  181554. {
  181555. const String messageString ((const juce_wchar*) ((const COPYDATASTRUCT*) lParam)->lpData,
  181556. ((const COPYDATASTRUCT*) lParam)->cbData / sizeof (juce_wchar));
  181557. PostMessage (juce_messageWindowHandle, broadcastId, 0, (LPARAM) new String (messageString));
  181558. return 0;
  181559. }
  181560. }
  181561. }
  181562. JUCE_CATCH_EXCEPTION
  181563. return DefWindowProc (h, message, wParam, lParam);
  181564. }
  181565. static bool isEventBlockedByModalComps (MSG& m)
  181566. {
  181567. if (Component::getNumCurrentlyModalComponents() == 0
  181568. || GetWindowLong (m.hwnd, GWLP_USERDATA) == improbableWindowNumber)
  181569. return false;
  181570. switch (m.message)
  181571. {
  181572. case WM_MOUSEMOVE:
  181573. case WM_NCMOUSEMOVE:
  181574. case 0x020A: /* WM_MOUSEWHEEL */
  181575. case 0x020E: /* WM_MOUSEHWHEEL */
  181576. case WM_KEYUP:
  181577. case WM_SYSKEYUP:
  181578. case WM_CHAR:
  181579. case WM_APPCOMMAND:
  181580. case WM_LBUTTONUP:
  181581. case WM_MBUTTONUP:
  181582. case WM_RBUTTONUP:
  181583. case WM_MOUSEACTIVATE:
  181584. case WM_NCMOUSEHOVER:
  181585. case WM_MOUSEHOVER:
  181586. return true;
  181587. case WM_NCLBUTTONDOWN:
  181588. case WM_NCLBUTTONDBLCLK:
  181589. case WM_NCRBUTTONDOWN:
  181590. case WM_NCRBUTTONDBLCLK:
  181591. case WM_NCMBUTTONDOWN:
  181592. case WM_NCMBUTTONDBLCLK:
  181593. case WM_LBUTTONDOWN:
  181594. case WM_LBUTTONDBLCLK:
  181595. case WM_MBUTTONDOWN:
  181596. case WM_MBUTTONDBLCLK:
  181597. case WM_RBUTTONDOWN:
  181598. case WM_RBUTTONDBLCLK:
  181599. case WM_KEYDOWN:
  181600. case WM_SYSKEYDOWN:
  181601. {
  181602. Component* const modal = Component::getCurrentlyModalComponent (0);
  181603. if (modal != 0)
  181604. modal->inputAttemptWhenModal();
  181605. return true;
  181606. }
  181607. default:
  181608. break;
  181609. }
  181610. return false;
  181611. }
  181612. bool juce_dispatchNextMessageOnSystemQueue (const bool returnIfNoPendingMessages)
  181613. {
  181614. MSG m;
  181615. if (returnIfNoPendingMessages && ! PeekMessage (&m, (HWND) 0, 0, 0, 0))
  181616. return false;
  181617. if (GetMessage (&m, (HWND) 0, 0, 0) >= 0)
  181618. {
  181619. if (m.message == specialId && m.hwnd == juce_messageWindowHandle)
  181620. {
  181621. MessageManager::getInstance()->deliverMessage ((void*) m.lParam);
  181622. }
  181623. else if (m.message == WM_QUIT)
  181624. {
  181625. if (JUCEApplication::getInstance())
  181626. JUCEApplication::getInstance()->systemRequestedQuit();
  181627. }
  181628. else if (! isEventBlockedByModalComps (m))
  181629. {
  181630. if ((m.message == WM_LBUTTONDOWN || m.message == WM_RBUTTONDOWN)
  181631. && GetWindowLong (m.hwnd, GWLP_USERDATA) != improbableWindowNumber)
  181632. {
  181633. // if it's someone else's window being clicked on, and the focus is
  181634. // currently on a juce window, pass the kb focus over..
  181635. HWND currentFocus = GetFocus();
  181636. if (currentFocus == 0 || GetWindowLong (currentFocus, GWLP_USERDATA) == improbableWindowNumber)
  181637. SetFocus (m.hwnd);
  181638. }
  181639. TranslateMessage (&m);
  181640. DispatchMessage (&m);
  181641. }
  181642. }
  181643. return true;
  181644. }
  181645. bool juce_postMessageToSystemQueue (void* message)
  181646. {
  181647. return PostMessage (juce_messageWindowHandle, specialId, 0, (LPARAM) message) != 0;
  181648. }
  181649. void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* callback,
  181650. void* userData)
  181651. {
  181652. if (MessageManager::getInstance()->isThisTheMessageThread())
  181653. {
  181654. return (*callback) (userData);
  181655. }
  181656. else
  181657. {
  181658. // If a thread has a MessageManagerLock and then tries to call this method, it'll
  181659. // deadlock because the message manager is blocked from running, and can't
  181660. // call your function..
  181661. jassert (! MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  181662. return (void*) SendMessage (juce_messageWindowHandle,
  181663. specialCallbackId,
  181664. (WPARAM) callback,
  181665. (LPARAM) userData);
  181666. }
  181667. }
  181668. static BOOL CALLBACK BroadcastEnumWindowProc (HWND hwnd, LPARAM lParam)
  181669. {
  181670. if (hwnd != juce_messageWindowHandle)
  181671. (reinterpret_cast <VoidArray*> (lParam))->add ((void*) hwnd);
  181672. return TRUE;
  181673. }
  181674. void MessageManager::broadcastMessage (const String& value) throw()
  181675. {
  181676. VoidArray windows;
  181677. EnumWindows (&BroadcastEnumWindowProc, (LPARAM) &windows);
  181678. const String localCopy (value);
  181679. COPYDATASTRUCT data;
  181680. data.dwData = broadcastId;
  181681. data.cbData = (localCopy.length() + 1) * sizeof (juce_wchar);
  181682. data.lpData = (void*) (const juce_wchar*) localCopy;
  181683. for (int i = windows.size(); --i >= 0;)
  181684. {
  181685. HWND hwnd = (HWND) windows.getUnchecked(i);
  181686. TCHAR windowName [64]; // no need to read longer strings than this
  181687. GetWindowText (hwnd, windowName, 64);
  181688. windowName [63] = 0;
  181689. if (String (windowName) == String (messageWindowName))
  181690. {
  181691. DWORD_PTR result;
  181692. SendMessageTimeout (hwnd, WM_COPYDATA,
  181693. (WPARAM) juce_messageWindowHandle,
  181694. (LPARAM) &data,
  181695. SMTO_BLOCK | SMTO_ABORTIFHUNG,
  181696. 8000,
  181697. &result);
  181698. }
  181699. }
  181700. }
  181701. static const String getMessageWindowClassName()
  181702. {
  181703. // this name has to be different for each app/dll instance because otherwise
  181704. // poor old Win32 can get a bit confused (even despite it not being a process-global
  181705. // window class).
  181706. static int number = 0;
  181707. if (number == 0)
  181708. number = 0x7fffffff & (int) Time::getHighResolutionTicks();
  181709. return T("JUCEcs_") + String (number);
  181710. }
  181711. void MessageManager::doPlatformSpecificInitialisation()
  181712. {
  181713. OleInitialize (0);
  181714. const String className (getMessageWindowClassName());
  181715. HMODULE hmod = (HMODULE) PlatformUtilities::getCurrentModuleInstanceHandle();
  181716. WNDCLASSEX wc;
  181717. zerostruct (wc);
  181718. wc.cbSize = sizeof (wc);
  181719. wc.lpfnWndProc = (WNDPROC) juce_MessageWndProc;
  181720. wc.cbWndExtra = 4;
  181721. wc.hInstance = hmod;
  181722. wc.lpszClassName = className;
  181723. RegisterClassEx (&wc);
  181724. juce_messageWindowHandle = CreateWindow (wc.lpszClassName,
  181725. messageWindowName,
  181726. 0, 0, 0, 0, 0, 0, 0,
  181727. hmod, 0);
  181728. }
  181729. void MessageManager::doPlatformSpecificShutdown()
  181730. {
  181731. DestroyWindow (juce_messageWindowHandle);
  181732. UnregisterClass (getMessageWindowClassName(), 0);
  181733. OleUninitialize();
  181734. }
  181735. #endif
  181736. /*** End of inlined file: juce_win32_Messaging.cpp ***/
  181737. /*** Start of inlined file: juce_win32_Windowing.cpp ***/
  181738. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  181739. // compiled on its own).
  181740. #if JUCE_INCLUDED_FILE
  181741. #undef GetSystemMetrics // multimon overrides this for some reason and causes a mess..
  181742. // these are in the windows SDK, but need to be repeated here for GCC..
  181743. #ifndef GET_APPCOMMAND_LPARAM
  181744. #define FAPPCOMMAND_MASK 0xF000
  181745. #define GET_APPCOMMAND_LPARAM(lParam) ((short) (HIWORD (lParam) & ~FAPPCOMMAND_MASK))
  181746. #define APPCOMMAND_MEDIA_NEXTTRACK 11
  181747. #define APPCOMMAND_MEDIA_PREVIOUSTRACK 12
  181748. #define APPCOMMAND_MEDIA_STOP 13
  181749. #define APPCOMMAND_MEDIA_PLAY_PAUSE 14
  181750. #define WM_APPCOMMAND 0x0319
  181751. #endif
  181752. extern void juce_repeatLastProcessPriority(); // in juce_win32_Threads.cpp
  181753. extern void juce_CheckCurrentlyFocusedTopLevelWindow(); // in juce_TopLevelWindow.cpp
  181754. extern bool juce_IsRunningInWine();
  181755. #ifndef ULW_ALPHA
  181756. #define ULW_ALPHA 0x00000002
  181757. #endif
  181758. #ifndef AC_SRC_ALPHA
  181759. #define AC_SRC_ALPHA 0x01
  181760. #endif
  181761. #define DEBUG_REPAINT_TIMES 0
  181762. static HPALETTE palette = 0;
  181763. static bool createPaletteIfNeeded = true;
  181764. static bool shouldDeactivateTitleBar = true;
  181765. static HICON createHICONFromImage (const Image& image, const BOOL isIcon, int hotspotX, int hotspotY) throw();
  181766. #define WM_TRAYNOTIFY WM_USER + 100
  181767. using ::abs;
  181768. typedef BOOL (WINAPI* UpdateLayeredWinFunc) (HWND, HDC, POINT*, SIZE*, HDC, POINT*, COLORREF, BLENDFUNCTION*, DWORD);
  181769. static UpdateLayeredWinFunc updateLayeredWindow = 0;
  181770. bool Desktop::canUseSemiTransparentWindows() throw()
  181771. {
  181772. if (updateLayeredWindow == 0)
  181773. {
  181774. if (! juce_IsRunningInWine())
  181775. {
  181776. HMODULE user32Mod = GetModuleHandle (_T("user32.dll"));
  181777. updateLayeredWindow = (UpdateLayeredWinFunc) GetProcAddress (user32Mod, "UpdateLayeredWindow");
  181778. }
  181779. }
  181780. return updateLayeredWindow != 0;
  181781. }
  181782. #undef DefWindowProc
  181783. #define DefWindowProc DefWindowProcW
  181784. const int extendedKeyModifier = 0x10000;
  181785. const int KeyPress::spaceKey = VK_SPACE;
  181786. const int KeyPress::returnKey = VK_RETURN;
  181787. const int KeyPress::escapeKey = VK_ESCAPE;
  181788. const int KeyPress::backspaceKey = VK_BACK;
  181789. const int KeyPress::deleteKey = VK_DELETE | extendedKeyModifier;
  181790. const int KeyPress::insertKey = VK_INSERT | extendedKeyModifier;
  181791. const int KeyPress::tabKey = VK_TAB;
  181792. const int KeyPress::leftKey = VK_LEFT | extendedKeyModifier;
  181793. const int KeyPress::rightKey = VK_RIGHT | extendedKeyModifier;
  181794. const int KeyPress::upKey = VK_UP | extendedKeyModifier;
  181795. const int KeyPress::downKey = VK_DOWN | extendedKeyModifier;
  181796. const int KeyPress::homeKey = VK_HOME | extendedKeyModifier;
  181797. const int KeyPress::endKey = VK_END | extendedKeyModifier;
  181798. const int KeyPress::pageUpKey = VK_PRIOR | extendedKeyModifier;
  181799. const int KeyPress::pageDownKey = VK_NEXT | extendedKeyModifier;
  181800. const int KeyPress::F1Key = VK_F1 | extendedKeyModifier;
  181801. const int KeyPress::F2Key = VK_F2 | extendedKeyModifier;
  181802. const int KeyPress::F3Key = VK_F3 | extendedKeyModifier;
  181803. const int KeyPress::F4Key = VK_F4 | extendedKeyModifier;
  181804. const int KeyPress::F5Key = VK_F5 | extendedKeyModifier;
  181805. const int KeyPress::F6Key = VK_F6 | extendedKeyModifier;
  181806. const int KeyPress::F7Key = VK_F7 | extendedKeyModifier;
  181807. const int KeyPress::F8Key = VK_F8 | extendedKeyModifier;
  181808. const int KeyPress::F9Key = VK_F9 | extendedKeyModifier;
  181809. const int KeyPress::F10Key = VK_F10 | extendedKeyModifier;
  181810. const int KeyPress::F11Key = VK_F11 | extendedKeyModifier;
  181811. const int KeyPress::F12Key = VK_F12 | extendedKeyModifier;
  181812. const int KeyPress::F13Key = VK_F13 | extendedKeyModifier;
  181813. const int KeyPress::F14Key = VK_F14 | extendedKeyModifier;
  181814. const int KeyPress::F15Key = VK_F15 | extendedKeyModifier;
  181815. const int KeyPress::F16Key = VK_F16 | extendedKeyModifier;
  181816. const int KeyPress::numberPad0 = VK_NUMPAD0 | extendedKeyModifier;
  181817. const int KeyPress::numberPad1 = VK_NUMPAD1 | extendedKeyModifier;
  181818. const int KeyPress::numberPad2 = VK_NUMPAD2 | extendedKeyModifier;
  181819. const int KeyPress::numberPad3 = VK_NUMPAD3 | extendedKeyModifier;
  181820. const int KeyPress::numberPad4 = VK_NUMPAD4 | extendedKeyModifier;
  181821. const int KeyPress::numberPad5 = VK_NUMPAD5 | extendedKeyModifier;
  181822. const int KeyPress::numberPad6 = VK_NUMPAD6 | extendedKeyModifier;
  181823. const int KeyPress::numberPad7 = VK_NUMPAD7 | extendedKeyModifier;
  181824. const int KeyPress::numberPad8 = VK_NUMPAD8 | extendedKeyModifier;
  181825. const int KeyPress::numberPad9 = VK_NUMPAD9 | extendedKeyModifier;
  181826. const int KeyPress::numberPadAdd = VK_ADD | extendedKeyModifier;
  181827. const int KeyPress::numberPadSubtract = VK_SUBTRACT | extendedKeyModifier;
  181828. const int KeyPress::numberPadMultiply = VK_MULTIPLY | extendedKeyModifier;
  181829. const int KeyPress::numberPadDivide = VK_DIVIDE | extendedKeyModifier;
  181830. const int KeyPress::numberPadSeparator = VK_SEPARATOR | extendedKeyModifier;
  181831. const int KeyPress::numberPadDecimalPoint = VK_DECIMAL | extendedKeyModifier;
  181832. const int KeyPress::numberPadEquals = 0x92 /*VK_OEM_NEC_EQUAL*/ | extendedKeyModifier;
  181833. const int KeyPress::numberPadDelete = VK_DELETE | extendedKeyModifier;
  181834. const int KeyPress::playKey = 0x30000;
  181835. const int KeyPress::stopKey = 0x30001;
  181836. const int KeyPress::fastForwardKey = 0x30002;
  181837. const int KeyPress::rewindKey = 0x30003;
  181838. class WindowsBitmapImage : public Image
  181839. {
  181840. public:
  181841. HBITMAP hBitmap;
  181842. BITMAPV4HEADER bitmapInfo;
  181843. HDC hdc;
  181844. unsigned char* bitmapData;
  181845. WindowsBitmapImage (const PixelFormat format_,
  181846. const int w, const int h, const bool clearImage)
  181847. : Image (format_, w, h)
  181848. {
  181849. jassert (format_ == RGB || format_ == ARGB);
  181850. pixelStride = (format_ == RGB) ? 3 : 4;
  181851. zerostruct (bitmapInfo);
  181852. bitmapInfo.bV4Size = sizeof (BITMAPV4HEADER);
  181853. bitmapInfo.bV4Width = w;
  181854. bitmapInfo.bV4Height = h;
  181855. bitmapInfo.bV4Planes = 1;
  181856. bitmapInfo.bV4CSType = 1;
  181857. bitmapInfo.bV4BitCount = (unsigned short) (pixelStride * 8);
  181858. if (format_ == ARGB)
  181859. {
  181860. bitmapInfo.bV4AlphaMask = 0xff000000;
  181861. bitmapInfo.bV4RedMask = 0xff0000;
  181862. bitmapInfo.bV4GreenMask = 0xff00;
  181863. bitmapInfo.bV4BlueMask = 0xff;
  181864. bitmapInfo.bV4V4Compression = BI_BITFIELDS;
  181865. }
  181866. else
  181867. {
  181868. bitmapInfo.bV4V4Compression = BI_RGB;
  181869. }
  181870. lineStride = -((w * pixelStride + 3) & ~3);
  181871. HDC dc = GetDC (0);
  181872. hdc = CreateCompatibleDC (dc);
  181873. ReleaseDC (0, dc);
  181874. SetMapMode (hdc, MM_TEXT);
  181875. hBitmap = CreateDIBSection (hdc,
  181876. (BITMAPINFO*) &(bitmapInfo),
  181877. DIB_RGB_COLORS,
  181878. (void**) &bitmapData,
  181879. 0, 0);
  181880. SelectObject (hdc, hBitmap);
  181881. if (format_ == ARGB && clearImage)
  181882. zeromem (bitmapData, abs (h * lineStride));
  181883. imageData = bitmapData - (lineStride * (h - 1));
  181884. }
  181885. ~WindowsBitmapImage()
  181886. {
  181887. DeleteDC (hdc);
  181888. DeleteObject (hBitmap);
  181889. }
  181890. void blitToWindow (HWND hwnd, HDC dc, const bool transparent,
  181891. const int x, const int y,
  181892. const RectangleList& maskedRegion) throw()
  181893. {
  181894. static HDRAWDIB hdd = 0;
  181895. static bool needToCreateDrawDib = true;
  181896. if (needToCreateDrawDib)
  181897. {
  181898. needToCreateDrawDib = false;
  181899. HDC dc = GetDC (0);
  181900. const int n = GetDeviceCaps (dc, BITSPIXEL);
  181901. ReleaseDC (0, dc);
  181902. // only open if we're not palettised
  181903. if (n > 8)
  181904. hdd = DrawDibOpen();
  181905. }
  181906. if (createPaletteIfNeeded)
  181907. {
  181908. HDC dc = GetDC (0);
  181909. const int n = GetDeviceCaps (dc, BITSPIXEL);
  181910. ReleaseDC (0, dc);
  181911. if (n <= 8)
  181912. palette = CreateHalftonePalette (dc);
  181913. createPaletteIfNeeded = false;
  181914. }
  181915. if (palette != 0)
  181916. {
  181917. SelectPalette (dc, palette, FALSE);
  181918. RealizePalette (dc);
  181919. SetStretchBltMode (dc, HALFTONE);
  181920. }
  181921. SetMapMode (dc, MM_TEXT);
  181922. if (transparent)
  181923. {
  181924. POINT p, pos;
  181925. SIZE size;
  181926. RECT windowBounds;
  181927. GetWindowRect (hwnd, &windowBounds);
  181928. p.x = -x;
  181929. p.y = -y;
  181930. pos.x = windowBounds.left;
  181931. pos.y = windowBounds.top;
  181932. size.cx = windowBounds.right - windowBounds.left;
  181933. size.cy = windowBounds.bottom - windowBounds.top;
  181934. BLENDFUNCTION bf;
  181935. bf.AlphaFormat = AC_SRC_ALPHA;
  181936. bf.BlendFlags = 0;
  181937. bf.BlendOp = AC_SRC_OVER;
  181938. bf.SourceConstantAlpha = 0xff;
  181939. if (! maskedRegion.isEmpty())
  181940. {
  181941. for (RectangleList::Iterator i (maskedRegion); i.next();)
  181942. {
  181943. const Rectangle<int>& r = *i.getRectangle();
  181944. ExcludeClipRect (hdc, r.getX(), r.getY(), r.getRight(), r.getBottom());
  181945. }
  181946. }
  181947. updateLayeredWindow (hwnd, 0, &pos, &size, hdc, &p, 0, &bf, ULW_ALPHA);
  181948. }
  181949. else
  181950. {
  181951. int savedDC = 0;
  181952. if (! maskedRegion.isEmpty())
  181953. {
  181954. savedDC = SaveDC (dc);
  181955. for (RectangleList::Iterator i (maskedRegion); i.next();)
  181956. {
  181957. const Rectangle<int>& r = *i.getRectangle();
  181958. ExcludeClipRect (dc, r.getX(), r.getY(), r.getRight(), r.getBottom());
  181959. }
  181960. }
  181961. const int w = getWidth();
  181962. const int h = getHeight();
  181963. if (hdd == 0)
  181964. {
  181965. StretchDIBits (dc,
  181966. x, y, w, h,
  181967. 0, 0, w, h,
  181968. bitmapData, (const BITMAPINFO*) &bitmapInfo,
  181969. DIB_RGB_COLORS, SRCCOPY);
  181970. }
  181971. else
  181972. {
  181973. DrawDibDraw (hdd, dc, x, y, -1, -1,
  181974. (BITMAPINFOHEADER*) &bitmapInfo, bitmapData,
  181975. 0, 0, w, h, 0);
  181976. }
  181977. if (! maskedRegion.isEmpty())
  181978. RestoreDC (dc, savedDC);
  181979. }
  181980. }
  181981. juce_UseDebuggingNewOperator
  181982. private:
  181983. WindowsBitmapImage (const WindowsBitmapImage&);
  181984. const WindowsBitmapImage& operator= (const WindowsBitmapImage&);
  181985. };
  181986. long improbableWindowNumber = 0xf965aa01; // also referenced by messaging.cpp
  181987. static int currentModifiers = 0;
  181988. static int modifiersAtLastCallback = 0;
  181989. static void updateKeyModifiers() throw()
  181990. {
  181991. currentModifiers &= ~(ModifierKeys::shiftModifier
  181992. | ModifierKeys::ctrlModifier
  181993. | ModifierKeys::altModifier);
  181994. if ((GetKeyState (VK_SHIFT) & 0x8000) != 0)
  181995. currentModifiers |= ModifierKeys::shiftModifier;
  181996. if ((GetKeyState (VK_CONTROL) & 0x8000) != 0)
  181997. currentModifiers |= ModifierKeys::ctrlModifier;
  181998. if ((GetKeyState (VK_MENU) & 0x8000) != 0)
  181999. currentModifiers |= ModifierKeys::altModifier;
  182000. if ((GetKeyState (VK_RMENU) & 0x8000) != 0)
  182001. currentModifiers &= ~(ModifierKeys::ctrlModifier | ModifierKeys::altModifier);
  182002. }
  182003. void ModifierKeys::updateCurrentModifiers() throw()
  182004. {
  182005. currentModifierFlags = currentModifiers;
  182006. }
  182007. bool KeyPress::isKeyCurrentlyDown (const int keyCode) throw()
  182008. {
  182009. SHORT k = (SHORT) keyCode;
  182010. if ((keyCode & extendedKeyModifier) == 0
  182011. && (k >= (SHORT) T('a') && k <= (SHORT) T('z')))
  182012. k += (SHORT) T('A') - (SHORT) T('a');
  182013. const SHORT translatedValues[] = { (SHORT) ',', VK_OEM_COMMA,
  182014. (SHORT) '+', VK_OEM_PLUS,
  182015. (SHORT) '-', VK_OEM_MINUS,
  182016. (SHORT) '.', VK_OEM_PERIOD,
  182017. (SHORT) ';', VK_OEM_1,
  182018. (SHORT) ':', VK_OEM_1,
  182019. (SHORT) '/', VK_OEM_2,
  182020. (SHORT) '?', VK_OEM_2,
  182021. (SHORT) '[', VK_OEM_4,
  182022. (SHORT) ']', VK_OEM_6 };
  182023. for (int i = 0; i < numElementsInArray (translatedValues); i += 2)
  182024. if (k == translatedValues [i])
  182025. k = translatedValues [i + 1];
  182026. return (GetKeyState (k) & 0x8000) != 0;
  182027. }
  182028. const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw()
  182029. {
  182030. updateKeyModifiers();
  182031. currentModifiers &= ~ModifierKeys::allMouseButtonModifiers;
  182032. if ((GetKeyState (VK_LBUTTON) & 0x8000) != 0)
  182033. currentModifiers |= ModifierKeys::leftButtonModifier;
  182034. if ((GetKeyState (VK_RBUTTON) & 0x8000) != 0)
  182035. currentModifiers |= ModifierKeys::rightButtonModifier;
  182036. if ((GetKeyState (VK_MBUTTON) & 0x8000) != 0)
  182037. currentModifiers |= ModifierKeys::middleButtonModifier;
  182038. return ModifierKeys (currentModifiers);
  182039. }
  182040. static int64 getMouseEventTime() throw()
  182041. {
  182042. static int64 eventTimeOffset = 0;
  182043. static DWORD lastMessageTime = 0;
  182044. const DWORD thisMessageTime = GetMessageTime();
  182045. if (thisMessageTime < lastMessageTime || lastMessageTime == 0)
  182046. {
  182047. lastMessageTime = thisMessageTime;
  182048. eventTimeOffset = Time::currentTimeMillis() - thisMessageTime;
  182049. }
  182050. return eventTimeOffset + thisMessageTime;
  182051. }
  182052. static void* callFunctionIfNotLocked (MessageCallbackFunction* callback, void* userData)
  182053. {
  182054. if (MessageManager::getInstance()->currentThreadHasLockedMessageManager())
  182055. return callback (userData);
  182056. else
  182057. return MessageManager::getInstance()->callFunctionOnMessageThread (callback, userData);
  182058. }
  182059. class Win32ComponentPeer : public ComponentPeer
  182060. {
  182061. public:
  182062. Win32ComponentPeer (Component* const component,
  182063. const int windowStyleFlags)
  182064. : ComponentPeer (component, windowStyleFlags),
  182065. dontRepaint (false),
  182066. fullScreen (false),
  182067. isDragging (false),
  182068. isMouseOver (false),
  182069. hasCreatedCaret (false),
  182070. currentWindowIcon (0),
  182071. taskBarIcon (0),
  182072. dropTarget (0)
  182073. {
  182074. callFunctionIfNotLocked (&createWindowCallback, (void*) this);
  182075. setTitle (component->getName());
  182076. if ((windowStyleFlags & windowHasDropShadow) != 0
  182077. && Desktop::canUseSemiTransparentWindows())
  182078. {
  182079. shadower = component->getLookAndFeel().createDropShadowerForComponent (component);
  182080. if (shadower != 0)
  182081. shadower->setOwner (component);
  182082. }
  182083. else
  182084. {
  182085. shadower = 0;
  182086. }
  182087. }
  182088. ~Win32ComponentPeer()
  182089. {
  182090. setTaskBarIcon (0);
  182091. deleteAndZero (shadower);
  182092. // do this before the next bit to avoid messages arriving for this window
  182093. // before it's destroyed
  182094. SetWindowLongPtr (hwnd, GWLP_USERDATA, 0);
  182095. callFunctionIfNotLocked (&destroyWindowCallback, (void*) hwnd);
  182096. if (currentWindowIcon != 0)
  182097. DestroyIcon (currentWindowIcon);
  182098. if (dropTarget != 0)
  182099. {
  182100. dropTarget->Release();
  182101. dropTarget = 0;
  182102. }
  182103. }
  182104. void* getNativeHandle() const
  182105. {
  182106. return (void*) hwnd;
  182107. }
  182108. void setVisible (bool shouldBeVisible)
  182109. {
  182110. ShowWindow (hwnd, shouldBeVisible ? SW_SHOWNA : SW_HIDE);
  182111. if (shouldBeVisible)
  182112. InvalidateRect (hwnd, 0, 0);
  182113. else
  182114. lastPaintTime = 0;
  182115. }
  182116. void setTitle (const String& title)
  182117. {
  182118. SetWindowText (hwnd, title);
  182119. }
  182120. void setPosition (int x, int y)
  182121. {
  182122. offsetWithinParent (x, y);
  182123. SetWindowPos (hwnd, 0,
  182124. x - windowBorder.getLeft(),
  182125. y - windowBorder.getTop(),
  182126. 0, 0,
  182127. SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  182128. }
  182129. void repaintNowIfTransparent()
  182130. {
  182131. if (isTransparent() && lastPaintTime > 0 && Time::getMillisecondCounter() > lastPaintTime + 30)
  182132. handlePaintMessage();
  182133. }
  182134. void updateBorderSize()
  182135. {
  182136. WINDOWINFO info;
  182137. info.cbSize = sizeof (info);
  182138. if (GetWindowInfo (hwnd, &info))
  182139. {
  182140. windowBorder = BorderSize (info.rcClient.top - info.rcWindow.top,
  182141. info.rcClient.left - info.rcWindow.left,
  182142. info.rcWindow.bottom - info.rcClient.bottom,
  182143. info.rcWindow.right - info.rcClient.right);
  182144. }
  182145. }
  182146. void setSize (int w, int h)
  182147. {
  182148. SetWindowPos (hwnd, 0, 0, 0,
  182149. w + windowBorder.getLeftAndRight(),
  182150. h + windowBorder.getTopAndBottom(),
  182151. SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  182152. updateBorderSize();
  182153. repaintNowIfTransparent();
  182154. }
  182155. void setBounds (int x, int y, int w, int h, const bool isNowFullScreen)
  182156. {
  182157. fullScreen = isNowFullScreen;
  182158. offsetWithinParent (x, y);
  182159. SetWindowPos (hwnd, 0,
  182160. x - windowBorder.getLeft(),
  182161. y - windowBorder.getTop(),
  182162. w + windowBorder.getLeftAndRight(),
  182163. h + windowBorder.getTopAndBottom(),
  182164. SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  182165. updateBorderSize();
  182166. repaintNowIfTransparent();
  182167. }
  182168. void getBounds (int& x, int& y, int& w, int& h) const
  182169. {
  182170. RECT r;
  182171. GetWindowRect (hwnd, &r);
  182172. x = r.left;
  182173. y = r.top;
  182174. w = r.right - x;
  182175. h = r.bottom - y;
  182176. HWND parentH = GetParent (hwnd);
  182177. if (parentH != 0)
  182178. {
  182179. GetWindowRect (parentH, &r);
  182180. x -= r.left;
  182181. y -= r.top;
  182182. }
  182183. x += windowBorder.getLeft();
  182184. y += windowBorder.getTop();
  182185. w -= windowBorder.getLeftAndRight();
  182186. h -= windowBorder.getTopAndBottom();
  182187. }
  182188. int getScreenX() const
  182189. {
  182190. RECT r;
  182191. GetWindowRect (hwnd, &r);
  182192. return r.left + windowBorder.getLeft();
  182193. }
  182194. int getScreenY() const
  182195. {
  182196. RECT r;
  182197. GetWindowRect (hwnd, &r);
  182198. return r.top + windowBorder.getTop();
  182199. }
  182200. void relativePositionToGlobal (int& x, int& y)
  182201. {
  182202. RECT r;
  182203. GetWindowRect (hwnd, &r);
  182204. x += r.left + windowBorder.getLeft();
  182205. y += r.top + windowBorder.getTop();
  182206. }
  182207. void globalPositionToRelative (int& x, int& y)
  182208. {
  182209. RECT r;
  182210. GetWindowRect (hwnd, &r);
  182211. x -= r.left + windowBorder.getLeft();
  182212. y -= r.top + windowBorder.getTop();
  182213. }
  182214. void setMinimised (bool shouldBeMinimised)
  182215. {
  182216. if (shouldBeMinimised != isMinimised())
  182217. ShowWindow (hwnd, shouldBeMinimised ? SW_MINIMIZE : SW_SHOWNORMAL);
  182218. }
  182219. bool isMinimised() const
  182220. {
  182221. WINDOWPLACEMENT wp;
  182222. wp.length = sizeof (WINDOWPLACEMENT);
  182223. GetWindowPlacement (hwnd, &wp);
  182224. return wp.showCmd == SW_SHOWMINIMIZED;
  182225. }
  182226. void setFullScreen (bool shouldBeFullScreen)
  182227. {
  182228. setMinimised (false);
  182229. if (fullScreen != shouldBeFullScreen)
  182230. {
  182231. fullScreen = shouldBeFullScreen;
  182232. const ComponentDeletionWatcher deletionChecker (component);
  182233. if (! fullScreen)
  182234. {
  182235. const Rectangle<int> boundsCopy (lastNonFullscreenBounds);
  182236. if (hasTitleBar())
  182237. ShowWindow (hwnd, SW_SHOWNORMAL);
  182238. if (! boundsCopy.isEmpty())
  182239. {
  182240. setBounds (boundsCopy.getX(),
  182241. boundsCopy.getY(),
  182242. boundsCopy.getWidth(),
  182243. boundsCopy.getHeight(),
  182244. false);
  182245. }
  182246. }
  182247. else
  182248. {
  182249. if (hasTitleBar())
  182250. ShowWindow (hwnd, SW_SHOWMAXIMIZED);
  182251. else
  182252. SendMessageW (hwnd, WM_SETTINGCHANGE, 0, 0);
  182253. }
  182254. if (! deletionChecker.hasBeenDeleted())
  182255. handleMovedOrResized();
  182256. }
  182257. }
  182258. bool isFullScreen() const
  182259. {
  182260. if (! hasTitleBar())
  182261. return fullScreen;
  182262. WINDOWPLACEMENT wp;
  182263. wp.length = sizeof (wp);
  182264. GetWindowPlacement (hwnd, &wp);
  182265. return wp.showCmd == SW_SHOWMAXIMIZED;
  182266. }
  182267. bool contains (int x, int y, bool trueIfInAChildWindow) const
  182268. {
  182269. RECT r;
  182270. GetWindowRect (hwnd, &r);
  182271. POINT p;
  182272. p.x = x + r.left + windowBorder.getLeft();
  182273. p.y = y + r.top + windowBorder.getTop();
  182274. HWND w = WindowFromPoint (p);
  182275. return w == hwnd || (trueIfInAChildWindow && (IsChild (hwnd, w) != 0));
  182276. }
  182277. const BorderSize getFrameSize() const
  182278. {
  182279. return windowBorder;
  182280. }
  182281. bool setAlwaysOnTop (bool alwaysOnTop)
  182282. {
  182283. const bool oldDeactivate = shouldDeactivateTitleBar;
  182284. shouldDeactivateTitleBar = ((styleFlags & windowIsTemporary) == 0);
  182285. SetWindowPos (hwnd, alwaysOnTop ? HWND_TOPMOST : HWND_NOTOPMOST,
  182286. 0, 0, 0, 0,
  182287. SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  182288. shouldDeactivateTitleBar = oldDeactivate;
  182289. if (shadower != 0)
  182290. shadower->componentBroughtToFront (*component);
  182291. return true;
  182292. }
  182293. void toFront (bool makeActive)
  182294. {
  182295. setMinimised (false);
  182296. const bool oldDeactivate = shouldDeactivateTitleBar;
  182297. shouldDeactivateTitleBar = ((styleFlags & windowIsTemporary) == 0);
  182298. callFunctionIfNotLocked (makeActive ? &toFrontCallback1
  182299. : &toFrontCallback2,
  182300. (void*) hwnd);
  182301. shouldDeactivateTitleBar = oldDeactivate;
  182302. if (! makeActive)
  182303. {
  182304. // in this case a broughttofront call won't have occured, so do it now..
  182305. handleBroughtToFront();
  182306. }
  182307. }
  182308. void toBehind (ComponentPeer* other)
  182309. {
  182310. Win32ComponentPeer* const otherPeer = dynamic_cast <Win32ComponentPeer*> (other);
  182311. jassert (otherPeer != 0); // wrong type of window?
  182312. if (otherPeer != 0)
  182313. {
  182314. setMinimised (false);
  182315. // must be careful not to try to put a topmost window behind a normal one, or win32
  182316. // promotes the normal one to be topmost!
  182317. if (getComponent()->isAlwaysOnTop() == otherPeer->getComponent()->isAlwaysOnTop())
  182318. SetWindowPos (hwnd, otherPeer->hwnd, 0, 0, 0, 0,
  182319. SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  182320. else if (otherPeer->getComponent()->isAlwaysOnTop())
  182321. SetWindowPos (hwnd, HWND_TOP, 0, 0, 0, 0,
  182322. SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  182323. }
  182324. }
  182325. bool isFocused() const
  182326. {
  182327. return callFunctionIfNotLocked (&getFocusCallback, 0) == (void*) hwnd;
  182328. }
  182329. void grabFocus()
  182330. {
  182331. const bool oldDeactivate = shouldDeactivateTitleBar;
  182332. shouldDeactivateTitleBar = ((styleFlags & windowIsTemporary) == 0);
  182333. callFunctionIfNotLocked (&setFocusCallback, (void*) hwnd);
  182334. shouldDeactivateTitleBar = oldDeactivate;
  182335. }
  182336. void textInputRequired (int /*x*/, int /*y*/)
  182337. {
  182338. if (! hasCreatedCaret)
  182339. {
  182340. hasCreatedCaret = true;
  182341. CreateCaret (hwnd, (HBITMAP) 1, 0, 0);
  182342. }
  182343. ShowCaret (hwnd);
  182344. SetCaretPos (0, 0);
  182345. }
  182346. void repaint (int x, int y, int w, int h)
  182347. {
  182348. const RECT r = { x, y, x + w, y + h };
  182349. InvalidateRect (hwnd, &r, FALSE);
  182350. }
  182351. void performAnyPendingRepaintsNow()
  182352. {
  182353. MSG m;
  182354. if (component->isVisible() && PeekMessage (&m, hwnd, WM_PAINT, WM_PAINT, PM_REMOVE))
  182355. DispatchMessage (&m);
  182356. }
  182357. static Win32ComponentPeer* getOwnerOfWindow (HWND h) throw()
  182358. {
  182359. if (h != 0 && GetWindowLongPtr (h, GWLP_USERDATA) == improbableWindowNumber)
  182360. return (Win32ComponentPeer*) (pointer_sized_int) GetWindowLongPtr (h, 8);
  182361. return 0;
  182362. }
  182363. void setTaskBarIcon (const Image* const image)
  182364. {
  182365. if (image != 0)
  182366. {
  182367. HICON hicon = createHICONFromImage (*image, TRUE, 0, 0);
  182368. if (taskBarIcon == 0)
  182369. {
  182370. taskBarIcon = new NOTIFYICONDATA();
  182371. taskBarIcon->cbSize = sizeof (NOTIFYICONDATA);
  182372. taskBarIcon->hWnd = (HWND) hwnd;
  182373. taskBarIcon->uID = (int) (pointer_sized_int) hwnd;
  182374. taskBarIcon->uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
  182375. taskBarIcon->uCallbackMessage = WM_TRAYNOTIFY;
  182376. taskBarIcon->hIcon = hicon;
  182377. taskBarIcon->szTip[0] = 0;
  182378. Shell_NotifyIcon (NIM_ADD, taskBarIcon);
  182379. }
  182380. else
  182381. {
  182382. HICON oldIcon = taskBarIcon->hIcon;
  182383. taskBarIcon->hIcon = hicon;
  182384. taskBarIcon->uFlags = NIF_ICON;
  182385. Shell_NotifyIcon (NIM_MODIFY, taskBarIcon);
  182386. DestroyIcon (oldIcon);
  182387. }
  182388. DestroyIcon (hicon);
  182389. }
  182390. else if (taskBarIcon != 0)
  182391. {
  182392. taskBarIcon->uFlags = 0;
  182393. Shell_NotifyIcon (NIM_DELETE, taskBarIcon);
  182394. DestroyIcon (taskBarIcon->hIcon);
  182395. deleteAndZero (taskBarIcon);
  182396. }
  182397. }
  182398. void setTaskBarIconToolTip (const String& toolTip) const
  182399. {
  182400. if (taskBarIcon != 0)
  182401. {
  182402. taskBarIcon->uFlags = NIF_TIP;
  182403. toolTip.copyToBuffer (taskBarIcon->szTip, sizeof (taskBarIcon->szTip) - 1);
  182404. Shell_NotifyIcon (NIM_MODIFY, taskBarIcon);
  182405. }
  182406. }
  182407. bool isInside (HWND h) const
  182408. {
  182409. return GetAncestor (hwnd, GA_ROOT) == h;
  182410. }
  182411. juce_UseDebuggingNewOperator
  182412. bool dontRepaint;
  182413. private:
  182414. HWND hwnd;
  182415. DropShadower* shadower;
  182416. bool fullScreen, isDragging, isMouseOver, hasCreatedCaret;
  182417. BorderSize windowBorder;
  182418. HICON currentWindowIcon;
  182419. NOTIFYICONDATA* taskBarIcon;
  182420. IDropTarget* dropTarget;
  182421. class TemporaryImage : public Timer
  182422. {
  182423. public:
  182424. TemporaryImage()
  182425. : image (0)
  182426. {
  182427. }
  182428. ~TemporaryImage()
  182429. {
  182430. delete image;
  182431. }
  182432. WindowsBitmapImage* getImage (const bool transparent, const int w, const int h) throw()
  182433. {
  182434. const Image::PixelFormat format = transparent ? Image::ARGB : Image::RGB;
  182435. if (image == 0 || image->getWidth() < w || image->getHeight() < h || image->getFormat() != format)
  182436. {
  182437. delete image;
  182438. image = new WindowsBitmapImage (format, (w + 31) & ~31, (h + 31) & ~31, false);
  182439. }
  182440. startTimer (3000);
  182441. return image;
  182442. }
  182443. void timerCallback()
  182444. {
  182445. stopTimer();
  182446. deleteAndZero (image);
  182447. }
  182448. private:
  182449. WindowsBitmapImage* image;
  182450. TemporaryImage (const TemporaryImage&);
  182451. const TemporaryImage& operator= (const TemporaryImage&);
  182452. };
  182453. TemporaryImage offscreenImageGenerator;
  182454. class WindowClassHolder : public DeletedAtShutdown
  182455. {
  182456. public:
  182457. WindowClassHolder()
  182458. : windowClassName ("JUCE_")
  182459. {
  182460. // this name has to be different for each app/dll instance because otherwise
  182461. // poor old Win32 can get a bit confused (even despite it not being a process-global
  182462. // window class).
  182463. windowClassName << (int) (Time::currentTimeMillis() & 0x7fffffff);
  182464. HINSTANCE moduleHandle = (HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle();
  182465. TCHAR moduleFile [1024];
  182466. moduleFile[0] = 0;
  182467. GetModuleFileName (moduleHandle, moduleFile, 1024);
  182468. WORD iconNum = 0;
  182469. WNDCLASSEX wcex;
  182470. wcex.cbSize = sizeof (wcex);
  182471. wcex.style = CS_OWNDC;
  182472. wcex.lpfnWndProc = (WNDPROC) windowProc;
  182473. wcex.lpszClassName = windowClassName;
  182474. wcex.cbClsExtra = 0;
  182475. wcex.cbWndExtra = 32;
  182476. wcex.hInstance = moduleHandle;
  182477. wcex.hIcon = ExtractAssociatedIcon (moduleHandle, moduleFile, &iconNum);
  182478. iconNum = 1;
  182479. wcex.hIconSm = ExtractAssociatedIcon (moduleHandle, moduleFile, &iconNum);
  182480. wcex.hCursor = 0;
  182481. wcex.hbrBackground = 0;
  182482. wcex.lpszMenuName = 0;
  182483. RegisterClassEx (&wcex);
  182484. }
  182485. ~WindowClassHolder()
  182486. {
  182487. if (ComponentPeer::getNumPeers() == 0)
  182488. UnregisterClass (windowClassName, (HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle());
  182489. clearSingletonInstance();
  182490. }
  182491. String windowClassName;
  182492. juce_DeclareSingleton_SingleThreaded_Minimal (WindowClassHolder);
  182493. };
  182494. static void* createWindowCallback (void* userData)
  182495. {
  182496. ((Win32ComponentPeer*) userData)->createWindow();
  182497. return 0;
  182498. }
  182499. void createWindow()
  182500. {
  182501. DWORD exstyle = WS_EX_ACCEPTFILES;
  182502. DWORD type = WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
  182503. if (hasTitleBar())
  182504. {
  182505. type |= WS_OVERLAPPED;
  182506. exstyle |= WS_EX_APPWINDOW;
  182507. if ((styleFlags & windowHasCloseButton) != 0)
  182508. {
  182509. type |= WS_SYSMENU;
  182510. }
  182511. else
  182512. {
  182513. // annoyingly, windows won't let you have a min/max button without a close button
  182514. jassert ((styleFlags & (windowHasMinimiseButton | windowHasMaximiseButton)) == 0);
  182515. }
  182516. if ((styleFlags & windowIsResizable) != 0)
  182517. type |= WS_THICKFRAME;
  182518. }
  182519. else
  182520. {
  182521. type |= WS_POPUP | WS_SYSMENU;
  182522. if ((styleFlags & windowAppearsOnTaskbar) == 0)
  182523. exstyle |= WS_EX_TOOLWINDOW;
  182524. else
  182525. exstyle |= WS_EX_APPWINDOW;
  182526. }
  182527. if ((styleFlags & windowHasMinimiseButton) != 0)
  182528. type |= WS_MINIMIZEBOX;
  182529. if ((styleFlags & windowHasMaximiseButton) != 0)
  182530. type |= WS_MAXIMIZEBOX;
  182531. if ((styleFlags & windowIgnoresMouseClicks) != 0)
  182532. exstyle |= WS_EX_TRANSPARENT;
  182533. if ((styleFlags & windowIsSemiTransparent) != 0
  182534. && Desktop::canUseSemiTransparentWindows())
  182535. exstyle |= WS_EX_LAYERED;
  182536. hwnd = CreateWindowEx (exstyle, WindowClassHolder::getInstance()->windowClassName, L"", type, 0, 0, 0, 0, 0, 0, 0, 0);
  182537. if (hwnd != 0)
  182538. {
  182539. SetWindowLongPtr (hwnd, 0, 0);
  182540. SetWindowLongPtr (hwnd, 8, (LONG_PTR) this);
  182541. SetWindowLongPtr (hwnd, GWLP_USERDATA, improbableWindowNumber);
  182542. if (dropTarget == 0)
  182543. dropTarget = new JuceDropTarget (this);
  182544. RegisterDragDrop (hwnd, dropTarget);
  182545. updateBorderSize();
  182546. // Calling this function here is (for some reason) necessary to make Windows
  182547. // correctly enable the menu items that we specify in the wm_initmenu message.
  182548. GetSystemMenu (hwnd, false);
  182549. }
  182550. else
  182551. {
  182552. jassertfalse
  182553. }
  182554. }
  182555. static void* destroyWindowCallback (void* handle)
  182556. {
  182557. RevokeDragDrop ((HWND) handle);
  182558. DestroyWindow ((HWND) handle);
  182559. return 0;
  182560. }
  182561. static void* toFrontCallback1 (void* h)
  182562. {
  182563. SetForegroundWindow ((HWND) h);
  182564. return 0;
  182565. }
  182566. static void* toFrontCallback2 (void* h)
  182567. {
  182568. SetWindowPos ((HWND) h, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  182569. return 0;
  182570. }
  182571. static void* setFocusCallback (void* h)
  182572. {
  182573. SetFocus ((HWND) h);
  182574. return 0;
  182575. }
  182576. static void* getFocusCallback (void*)
  182577. {
  182578. return (void*) GetFocus();
  182579. }
  182580. void offsetWithinParent (int& x, int& y) const
  182581. {
  182582. if (isTransparent())
  182583. {
  182584. HWND parentHwnd = GetParent (hwnd);
  182585. if (parentHwnd != 0)
  182586. {
  182587. RECT parentRect;
  182588. GetWindowRect (parentHwnd, &parentRect);
  182589. x += parentRect.left;
  182590. y += parentRect.top;
  182591. }
  182592. }
  182593. }
  182594. bool isTransparent() const
  182595. {
  182596. return (GetWindowLong (hwnd, GWL_EXSTYLE) & WS_EX_LAYERED) != 0;
  182597. }
  182598. inline bool hasTitleBar() const throw() { return (styleFlags & windowHasTitleBar) != 0; }
  182599. void setIcon (const Image& newIcon)
  182600. {
  182601. HICON hicon = createHICONFromImage (newIcon, TRUE, 0, 0);
  182602. if (hicon != 0)
  182603. {
  182604. SendMessage (hwnd, WM_SETICON, ICON_BIG, (LPARAM) hicon);
  182605. SendMessage (hwnd, WM_SETICON, ICON_SMALL, (LPARAM) hicon);
  182606. if (currentWindowIcon != 0)
  182607. DestroyIcon (currentWindowIcon);
  182608. currentWindowIcon = hicon;
  182609. }
  182610. }
  182611. void handlePaintMessage()
  182612. {
  182613. #if DEBUG_REPAINT_TIMES
  182614. const double paintStart = Time::getMillisecondCounterHiRes();
  182615. #endif
  182616. HRGN rgn = CreateRectRgn (0, 0, 0, 0);
  182617. const int regionType = GetUpdateRgn (hwnd, rgn, false);
  182618. PAINTSTRUCT paintStruct;
  182619. HDC dc = BeginPaint (hwnd, &paintStruct); // Note this can immediately generate a WM_NCPAINT
  182620. // message and become re-entrant, but that's OK
  182621. // if something in a paint handler calls, e.g. a message box, this can become reentrant and
  182622. // corrupt the image it's using to paint into, so do a check here.
  182623. static bool reentrant = false;
  182624. if (reentrant)
  182625. {
  182626. DeleteObject (rgn);
  182627. EndPaint (hwnd, &paintStruct);
  182628. return;
  182629. }
  182630. reentrant = true;
  182631. // this is the rectangle to update..
  182632. int x = paintStruct.rcPaint.left;
  182633. int y = paintStruct.rcPaint.top;
  182634. int w = paintStruct.rcPaint.right - x;
  182635. int h = paintStruct.rcPaint.bottom - y;
  182636. const bool transparent = isTransparent();
  182637. if (transparent)
  182638. {
  182639. // it's not possible to have a transparent window with a title bar at the moment!
  182640. jassert (! hasTitleBar());
  182641. RECT r;
  182642. GetWindowRect (hwnd, &r);
  182643. x = y = 0;
  182644. w = r.right - r.left;
  182645. h = r.bottom - r.top;
  182646. }
  182647. if (w > 0 && h > 0)
  182648. {
  182649. clearMaskedRegion();
  182650. WindowsBitmapImage* const offscreenImage = offscreenImageGenerator.getImage (transparent, w, h);
  182651. RectangleList contextClip;
  182652. bool needToPaintAll = true;
  182653. if (regionType == COMPLEXREGION && ! transparent)
  182654. {
  182655. HRGN clipRgn = CreateRectRgnIndirect (&paintStruct.rcPaint);
  182656. CombineRgn (rgn, rgn, clipRgn, RGN_AND);
  182657. DeleteObject (clipRgn);
  182658. char rgnData [8192];
  182659. const DWORD res = GetRegionData (rgn, sizeof (rgnData), (RGNDATA*) rgnData);
  182660. if (res > 0 && res <= sizeof (rgnData))
  182661. {
  182662. const RGNDATAHEADER* const hdr = &(((const RGNDATA*) rgnData)->rdh);
  182663. if (hdr->iType == RDH_RECTANGLES
  182664. && hdr->rcBound.right - hdr->rcBound.left >= w
  182665. && hdr->rcBound.bottom - hdr->rcBound.top >= h)
  182666. {
  182667. needToPaintAll = false;
  182668. const RECT* rects = (const RECT*) (rgnData + sizeof (RGNDATAHEADER));
  182669. int num = ((RGNDATA*) rgnData)->rdh.nCount;
  182670. while (--num >= 0)
  182671. {
  182672. // (need to move this one pixel to the left because of a win32 bug)
  182673. const int cx = jmax (x, (int) rects->left - 1);
  182674. const int cy = rects->top;
  182675. const int cw = rects->right - cx;
  182676. const int ch = rects->bottom - rects->top;
  182677. if (cx + cw - x <= w && cy + ch - y <= h)
  182678. {
  182679. contextClip.addWithoutMerging (Rectangle<int> (cx - x, cy - y, cw, ch));
  182680. }
  182681. else
  182682. {
  182683. needToPaintAll = true;
  182684. break;
  182685. }
  182686. ++rects;
  182687. }
  182688. }
  182689. }
  182690. }
  182691. if (needToPaintAll)
  182692. {
  182693. contextClip.clear();
  182694. contextClip.addWithoutMerging (Rectangle<int> (0, 0, w, h));
  182695. }
  182696. if (transparent)
  182697. {
  182698. RectangleList::Iterator i (contextClip);
  182699. while (i.next())
  182700. {
  182701. const Rectangle<int>& r = *i.getRectangle();
  182702. offscreenImage->clear (r.getX(), r.getY(), r.getWidth(), r.getHeight());
  182703. }
  182704. }
  182705. // if the component's not opaque, this won't draw properly unless the platform can support this
  182706. jassert (Desktop::canUseSemiTransparentWindows() || component->isOpaque());
  182707. updateCurrentModifiers();
  182708. LowLevelGraphicsSoftwareRenderer context (*offscreenImage);
  182709. context.clipToRectangleList (contextClip);
  182710. context.setOrigin (-x, -y);
  182711. handlePaint (context);
  182712. if (! dontRepaint)
  182713. offscreenImage->blitToWindow (hwnd, dc, transparent, x, y, maskedRegion);
  182714. }
  182715. DeleteObject (rgn);
  182716. EndPaint (hwnd, &paintStruct);
  182717. reentrant = false;
  182718. #ifndef JUCE_GCC //xxx should add this fn for gcc..
  182719. _fpreset(); // because some graphics cards can unmask FP exceptions
  182720. #endif
  182721. lastPaintTime = Time::getMillisecondCounter();
  182722. #if DEBUG_REPAINT_TIMES
  182723. const double elapsed = Time::getMillisecondCounterHiRes() - paintStart;
  182724. Logger::outputDebugString (T("repaint time: ") + String (elapsed, 2));
  182725. #endif
  182726. }
  182727. void doMouseMove (const int x, const int y)
  182728. {
  182729. static uint32 lastMouseTime = 0;
  182730. // this can be set to throttle the mouse-messages to less than a
  182731. // certain number per second, as things can get unresponsive
  182732. // if each drag or move callback has to do a lot of work.
  182733. const int maxMouseMovesPerSecond = 60;
  182734. const int64 mouseEventTime = getMouseEventTime();
  182735. if (! isMouseOver)
  182736. {
  182737. isMouseOver = true;
  182738. TRACKMOUSEEVENT tme;
  182739. tme.cbSize = sizeof (tme);
  182740. tme.dwFlags = TME_LEAVE;
  182741. tme.hwndTrack = hwnd;
  182742. tme.dwHoverTime = 0;
  182743. if (! TrackMouseEvent (&tme))
  182744. {
  182745. jassertfalse;
  182746. }
  182747. updateKeyModifiers();
  182748. handleMouseEnter (x, y, mouseEventTime);
  182749. }
  182750. else if (! isDragging)
  182751. {
  182752. if (((unsigned int) x) < (unsigned int) component->getWidth()
  182753. && ((unsigned int) y) < (unsigned int) component->getHeight())
  182754. {
  182755. RECT r;
  182756. GetWindowRect (hwnd, &r);
  182757. POINT p;
  182758. p.x = x + r.left + windowBorder.getLeft();
  182759. p.y = y + r.top + windowBorder.getTop();
  182760. if (WindowFromPoint (p) == hwnd)
  182761. {
  182762. const uint32 now = Time::getMillisecondCounter();
  182763. if (now > lastMouseTime + 1000 / maxMouseMovesPerSecond)
  182764. {
  182765. lastMouseTime = now;
  182766. handleMouseMove (x, y, mouseEventTime);
  182767. }
  182768. }
  182769. }
  182770. }
  182771. else
  182772. {
  182773. const uint32 now = Time::getMillisecondCounter();
  182774. if (now > lastMouseTime + 1000 / maxMouseMovesPerSecond)
  182775. {
  182776. lastMouseTime = now;
  182777. handleMouseDrag (x, y, mouseEventTime);
  182778. }
  182779. }
  182780. }
  182781. void doMouseDown (const int x, const int y, const WPARAM wParam)
  182782. {
  182783. if (GetCapture() != hwnd)
  182784. SetCapture (hwnd);
  182785. doMouseMove (x, y);
  182786. currentModifiers &= ~ModifierKeys::allMouseButtonModifiers;
  182787. if ((wParam & MK_LBUTTON) != 0)
  182788. currentModifiers |= ModifierKeys::leftButtonModifier;
  182789. if ((wParam & MK_RBUTTON) != 0)
  182790. currentModifiers |= ModifierKeys::rightButtonModifier;
  182791. if ((wParam & MK_MBUTTON) != 0)
  182792. currentModifiers |= ModifierKeys::middleButtonModifier;
  182793. updateKeyModifiers();
  182794. isDragging = true;
  182795. handleMouseDown (x, y, getMouseEventTime());
  182796. }
  182797. void doMouseUp (const int x, const int y, const WPARAM wParam)
  182798. {
  182799. int numButtons = 0;
  182800. if ((wParam & MK_LBUTTON) != 0)
  182801. ++numButtons;
  182802. if ((wParam & MK_RBUTTON) != 0)
  182803. ++numButtons;
  182804. if ((wParam & MK_MBUTTON) != 0)
  182805. ++numButtons;
  182806. const int oldModifiers = currentModifiers;
  182807. // update the currentmodifiers only after the callback, so the callback
  182808. // knows which button was released.
  182809. currentModifiers &= ~ModifierKeys::allMouseButtonModifiers;
  182810. if ((wParam & MK_LBUTTON) != 0)
  182811. currentModifiers |= ModifierKeys::leftButtonModifier;
  182812. if ((wParam & MK_RBUTTON) != 0)
  182813. currentModifiers |= ModifierKeys::rightButtonModifier;
  182814. if ((wParam & MK_MBUTTON) != 0)
  182815. currentModifiers |= ModifierKeys::middleButtonModifier;
  182816. updateKeyModifiers();
  182817. isDragging = false;
  182818. // release the mouse capture if the user's not still got a button down
  182819. if (numButtons == 0 && hwnd == GetCapture())
  182820. ReleaseCapture();
  182821. handleMouseUp (oldModifiers, x, y, getMouseEventTime());
  182822. }
  182823. void doCaptureChanged()
  182824. {
  182825. if (isDragging)
  182826. {
  182827. RECT wr;
  182828. GetWindowRect (hwnd, &wr);
  182829. const DWORD mp = GetMessagePos();
  182830. doMouseUp (GET_X_LPARAM (mp) - wr.left - windowBorder.getLeft(),
  182831. GET_Y_LPARAM (mp) - wr.top - windowBorder.getTop(),
  182832. (WPARAM) getMouseEventTime());
  182833. }
  182834. }
  182835. void doMouseExit()
  182836. {
  182837. if (isMouseOver)
  182838. {
  182839. isMouseOver = false;
  182840. RECT wr;
  182841. GetWindowRect (hwnd, &wr);
  182842. const DWORD mp = GetMessagePos();
  182843. handleMouseExit (GET_X_LPARAM (mp) - wr.left - windowBorder.getLeft(),
  182844. GET_Y_LPARAM (mp) - wr.top - windowBorder.getTop(),
  182845. getMouseEventTime());
  182846. }
  182847. }
  182848. void doMouseWheel (const WPARAM wParam, const bool isVertical)
  182849. {
  182850. updateKeyModifiers();
  182851. const int amount = jlimit (-1000, 1000, (int) (0.75f * (short) HIWORD (wParam)));
  182852. handleMouseWheel (isVertical ? 0 : amount,
  182853. isVertical ? amount : 0,
  182854. getMouseEventTime());
  182855. }
  182856. void sendModifierKeyChangeIfNeeded()
  182857. {
  182858. if (modifiersAtLastCallback != currentModifiers)
  182859. {
  182860. modifiersAtLastCallback = currentModifiers;
  182861. handleModifierKeysChange();
  182862. }
  182863. }
  182864. bool doKeyUp (const WPARAM key)
  182865. {
  182866. updateKeyModifiers();
  182867. switch (key)
  182868. {
  182869. case VK_SHIFT:
  182870. case VK_CONTROL:
  182871. case VK_MENU:
  182872. case VK_CAPITAL:
  182873. case VK_LWIN:
  182874. case VK_RWIN:
  182875. case VK_APPS:
  182876. case VK_NUMLOCK:
  182877. case VK_SCROLL:
  182878. case VK_LSHIFT:
  182879. case VK_RSHIFT:
  182880. case VK_LCONTROL:
  182881. case VK_LMENU:
  182882. case VK_RCONTROL:
  182883. case VK_RMENU:
  182884. sendModifierKeyChangeIfNeeded();
  182885. }
  182886. return handleKeyUpOrDown (false)
  182887. || Component::getCurrentlyModalComponent() != 0;
  182888. }
  182889. bool doKeyDown (const WPARAM key)
  182890. {
  182891. updateKeyModifiers();
  182892. bool used = false;
  182893. switch (key)
  182894. {
  182895. case VK_SHIFT:
  182896. case VK_LSHIFT:
  182897. case VK_RSHIFT:
  182898. case VK_CONTROL:
  182899. case VK_LCONTROL:
  182900. case VK_RCONTROL:
  182901. case VK_MENU:
  182902. case VK_LMENU:
  182903. case VK_RMENU:
  182904. case VK_LWIN:
  182905. case VK_RWIN:
  182906. case VK_CAPITAL:
  182907. case VK_NUMLOCK:
  182908. case VK_SCROLL:
  182909. case VK_APPS:
  182910. sendModifierKeyChangeIfNeeded();
  182911. break;
  182912. case VK_LEFT:
  182913. case VK_RIGHT:
  182914. case VK_UP:
  182915. case VK_DOWN:
  182916. case VK_PRIOR:
  182917. case VK_NEXT:
  182918. case VK_HOME:
  182919. case VK_END:
  182920. case VK_DELETE:
  182921. case VK_INSERT:
  182922. case VK_F1:
  182923. case VK_F2:
  182924. case VK_F3:
  182925. case VK_F4:
  182926. case VK_F5:
  182927. case VK_F6:
  182928. case VK_F7:
  182929. case VK_F8:
  182930. case VK_F9:
  182931. case VK_F10:
  182932. case VK_F11:
  182933. case VK_F12:
  182934. case VK_F13:
  182935. case VK_F14:
  182936. case VK_F15:
  182937. case VK_F16:
  182938. used = handleKeyUpOrDown (true);
  182939. used = handleKeyPress (extendedKeyModifier | (int) key, 0) || used;
  182940. break;
  182941. case VK_ADD:
  182942. case VK_SUBTRACT:
  182943. case VK_MULTIPLY:
  182944. case VK_DIVIDE:
  182945. case VK_SEPARATOR:
  182946. case VK_DECIMAL:
  182947. used = handleKeyUpOrDown (true);
  182948. break;
  182949. default:
  182950. used = handleKeyUpOrDown (true);
  182951. {
  182952. MSG msg;
  182953. if (! PeekMessage (&msg, hwnd, WM_CHAR, WM_DEADCHAR, PM_NOREMOVE))
  182954. {
  182955. // if there isn't a WM_CHAR or WM_DEADCHAR message pending, we need to
  182956. // manually generate the key-press event that matches this key-down.
  182957. const UINT keyChar = MapVirtualKey (key, 2);
  182958. used = handleKeyPress ((int) LOWORD (keyChar), 0) || used;
  182959. }
  182960. }
  182961. break;
  182962. }
  182963. if (Component::getCurrentlyModalComponent() != 0)
  182964. used = true;
  182965. return used;
  182966. }
  182967. bool doKeyChar (int key, const LPARAM flags)
  182968. {
  182969. updateKeyModifiers();
  182970. juce_wchar textChar = (juce_wchar) key;
  182971. const int virtualScanCode = (flags >> 16) & 0xff;
  182972. if (key >= '0' && key <= '9')
  182973. {
  182974. switch (virtualScanCode) // check for a numeric keypad scan-code
  182975. {
  182976. case 0x52:
  182977. case 0x4f:
  182978. case 0x50:
  182979. case 0x51:
  182980. case 0x4b:
  182981. case 0x4c:
  182982. case 0x4d:
  182983. case 0x47:
  182984. case 0x48:
  182985. case 0x49:
  182986. key = (key - '0') + KeyPress::numberPad0;
  182987. break;
  182988. default:
  182989. break;
  182990. }
  182991. }
  182992. else
  182993. {
  182994. // convert the scan code to an unmodified character code..
  182995. const UINT virtualKey = MapVirtualKey (virtualScanCode, 1);
  182996. UINT keyChar = MapVirtualKey (virtualKey, 2);
  182997. keyChar = LOWORD (keyChar);
  182998. if (keyChar != 0)
  182999. key = (int) keyChar;
  183000. // avoid sending junk text characters for some control-key combinations
  183001. if (textChar < ' ' && (currentModifiers & (ModifierKeys::ctrlModifier | ModifierKeys::altModifier)) != 0)
  183002. textChar = 0;
  183003. }
  183004. return handleKeyPress (key, textChar);
  183005. }
  183006. bool doAppCommand (const LPARAM lParam)
  183007. {
  183008. int key = 0;
  183009. switch (GET_APPCOMMAND_LPARAM (lParam))
  183010. {
  183011. case APPCOMMAND_MEDIA_PLAY_PAUSE:
  183012. key = KeyPress::playKey;
  183013. break;
  183014. case APPCOMMAND_MEDIA_STOP:
  183015. key = KeyPress::stopKey;
  183016. break;
  183017. case APPCOMMAND_MEDIA_NEXTTRACK:
  183018. key = KeyPress::fastForwardKey;
  183019. break;
  183020. case APPCOMMAND_MEDIA_PREVIOUSTRACK:
  183021. key = KeyPress::rewindKey;
  183022. break;
  183023. }
  183024. if (key != 0)
  183025. {
  183026. updateKeyModifiers();
  183027. if (hwnd == GetActiveWindow())
  183028. {
  183029. handleKeyPress (key, 0);
  183030. return true;
  183031. }
  183032. }
  183033. return false;
  183034. }
  183035. class JuceDropTarget : public IDropTarget
  183036. {
  183037. public:
  183038. JuceDropTarget (Win32ComponentPeer* const owner_)
  183039. : owner (owner_),
  183040. refCount (1)
  183041. {
  183042. }
  183043. virtual ~JuceDropTarget()
  183044. {
  183045. jassert (refCount == 0);
  183046. }
  183047. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  183048. {
  183049. if (id == IID_IUnknown || id == IID_IDropTarget)
  183050. {
  183051. AddRef();
  183052. *result = this;
  183053. return S_OK;
  183054. }
  183055. *result = 0;
  183056. return E_NOINTERFACE;
  183057. }
  183058. ULONG __stdcall AddRef() { return ++refCount; }
  183059. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  183060. HRESULT __stdcall DragEnter (IDataObject* pDataObject, DWORD /*grfKeyState*/, POINTL mousePos, DWORD* pdwEffect)
  183061. {
  183062. updateFileList (pDataObject);
  183063. int x = mousePos.x, y = mousePos.y;
  183064. owner->globalPositionToRelative (x, y);
  183065. owner->handleFileDragMove (files, x, y);
  183066. *pdwEffect = DROPEFFECT_COPY;
  183067. return S_OK;
  183068. }
  183069. HRESULT __stdcall DragLeave()
  183070. {
  183071. owner->handleFileDragExit (files);
  183072. return S_OK;
  183073. }
  183074. HRESULT __stdcall DragOver (DWORD /*grfKeyState*/, POINTL mousePos, DWORD* pdwEffect)
  183075. {
  183076. int x = mousePos.x, y = mousePos.y;
  183077. owner->globalPositionToRelative (x, y);
  183078. owner->handleFileDragMove (files, x, y);
  183079. *pdwEffect = DROPEFFECT_COPY;
  183080. return S_OK;
  183081. }
  183082. HRESULT __stdcall Drop (IDataObject* pDataObject, DWORD /*grfKeyState*/, POINTL mousePos, DWORD* pdwEffect)
  183083. {
  183084. updateFileList (pDataObject);
  183085. int x = mousePos.x, y = mousePos.y;
  183086. owner->globalPositionToRelative (x, y);
  183087. owner->handleFileDragDrop (files, x, y);
  183088. *pdwEffect = DROPEFFECT_COPY;
  183089. return S_OK;
  183090. }
  183091. private:
  183092. Win32ComponentPeer* const owner;
  183093. int refCount;
  183094. StringArray files;
  183095. void updateFileList (IDataObject* const pDataObject)
  183096. {
  183097. files.clear();
  183098. FORMATETC format = { CF_HDROP, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
  183099. STGMEDIUM medium = { TYMED_HGLOBAL, { 0 }, 0 };
  183100. if (pDataObject->GetData (&format, &medium) == S_OK)
  183101. {
  183102. const SIZE_T totalLen = GlobalSize (medium.hGlobal);
  183103. const LPDROPFILES pDropFiles = (const LPDROPFILES) GlobalLock (medium.hGlobal);
  183104. unsigned int i = 0;
  183105. if (pDropFiles->fWide)
  183106. {
  183107. const WCHAR* const fname = (WCHAR*) (((const char*) pDropFiles) + sizeof (DROPFILES));
  183108. for (;;)
  183109. {
  183110. unsigned int len = 0;
  183111. while (i + len < totalLen && fname [i + len] != 0)
  183112. ++len;
  183113. if (len == 0)
  183114. break;
  183115. files.add (String (fname + i, len));
  183116. i += len + 1;
  183117. }
  183118. }
  183119. else
  183120. {
  183121. const char* const fname = ((const char*) pDropFiles) + sizeof (DROPFILES);
  183122. for (;;)
  183123. {
  183124. unsigned int len = 0;
  183125. while (i + len < totalLen && fname [i + len] != 0)
  183126. ++len;
  183127. if (len == 0)
  183128. break;
  183129. files.add (String (fname + i, len));
  183130. i += len + 1;
  183131. }
  183132. }
  183133. GlobalUnlock (medium.hGlobal);
  183134. }
  183135. }
  183136. JuceDropTarget (const JuceDropTarget&);
  183137. const JuceDropTarget& operator= (const JuceDropTarget&);
  183138. };
  183139. void doSettingChange()
  183140. {
  183141. Desktop::getInstance().refreshMonitorSizes();
  183142. if (fullScreen && ! isMinimised())
  183143. {
  183144. const Rectangle<int> r (component->getParentMonitorArea());
  183145. SetWindowPos (hwnd, 0,
  183146. r.getX(), r.getY(), r.getWidth(), r.getHeight(),
  183147. SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER | SWP_NOSENDCHANGING);
  183148. }
  183149. }
  183150. public:
  183151. static LRESULT CALLBACK windowProc (HWND h, UINT message, WPARAM wParam, LPARAM lParam)
  183152. {
  183153. Win32ComponentPeer* const peer = getOwnerOfWindow (h);
  183154. if (peer != 0)
  183155. return peer->peerWindowProc (h, message, wParam, lParam);
  183156. return DefWindowProc (h, message, wParam, lParam);
  183157. }
  183158. private:
  183159. LRESULT peerWindowProc (HWND h, UINT message, WPARAM wParam, LPARAM lParam)
  183160. {
  183161. if (isValidPeer (this))
  183162. {
  183163. switch (message)
  183164. {
  183165. case WM_NCHITTEST:
  183166. if ((styleFlags & windowIgnoresMouseClicks) != 0)
  183167. return HTTRANSPARENT;
  183168. if (hasTitleBar())
  183169. break;
  183170. return HTCLIENT;
  183171. case WM_PAINT:
  183172. handlePaintMessage();
  183173. return 0;
  183174. case WM_NCPAINT:
  183175. if (wParam != 1)
  183176. handlePaintMessage();
  183177. if (hasTitleBar())
  183178. break;
  183179. return 0;
  183180. case WM_ERASEBKGND:
  183181. case WM_NCCALCSIZE:
  183182. if (hasTitleBar())
  183183. break;
  183184. return 1;
  183185. case WM_MOUSEMOVE:
  183186. doMouseMove (GET_X_LPARAM (lParam), GET_Y_LPARAM (lParam));
  183187. return 0;
  183188. case WM_MOUSELEAVE:
  183189. doMouseExit();
  183190. return 0;
  183191. case WM_LBUTTONDOWN:
  183192. case WM_MBUTTONDOWN:
  183193. case WM_RBUTTONDOWN:
  183194. doMouseDown (GET_X_LPARAM (lParam), GET_Y_LPARAM (lParam), wParam);
  183195. return 0;
  183196. case WM_LBUTTONUP:
  183197. case WM_MBUTTONUP:
  183198. case WM_RBUTTONUP:
  183199. doMouseUp (GET_X_LPARAM (lParam), GET_Y_LPARAM (lParam), wParam);
  183200. return 0;
  183201. case WM_CAPTURECHANGED:
  183202. doCaptureChanged();
  183203. return 0;
  183204. case WM_NCMOUSEMOVE:
  183205. if (hasTitleBar())
  183206. break;
  183207. return 0;
  183208. case 0x020A: /* WM_MOUSEWHEEL */
  183209. doMouseWheel (wParam, true);
  183210. return 0;
  183211. case 0x020E: /* WM_MOUSEHWHEEL */
  183212. doMouseWheel (wParam, false);
  183213. return 0;
  183214. case WM_WINDOWPOSCHANGING:
  183215. if ((styleFlags & (windowHasTitleBar | windowIsResizable)) == (windowHasTitleBar | windowIsResizable))
  183216. {
  183217. WINDOWPOS* const wp = (WINDOWPOS*) lParam;
  183218. if ((wp->flags & (SWP_NOMOVE | SWP_NOSIZE)) != (SWP_NOMOVE | SWP_NOSIZE))
  183219. {
  183220. if (constrainer != 0)
  183221. {
  183222. const Rectangle<int> current (component->getX() - windowBorder.getLeft(),
  183223. component->getY() - windowBorder.getTop(),
  183224. component->getWidth() + windowBorder.getLeftAndRight(),
  183225. component->getHeight() + windowBorder.getTopAndBottom());
  183226. Rectangle<int> pos (wp->x, wp->y, wp->cx, wp->cy);
  183227. constrainer->checkBounds (pos, current,
  183228. Desktop::getInstance().getAllMonitorDisplayAreas().getBounds(),
  183229. pos.getY() != current.getY() && pos.getBottom() == current.getBottom(),
  183230. pos.getX() != current.getX() && pos.getRight() == current.getRight(),
  183231. pos.getY() == current.getY() && pos.getBottom() != current.getBottom(),
  183232. pos.getX() == current.getX() && pos.getRight() != current.getRight());
  183233. wp->x = pos.getX();
  183234. wp->y = pos.getY();
  183235. wp->cx = pos.getWidth();
  183236. wp->cy = pos.getHeight();
  183237. }
  183238. }
  183239. }
  183240. return 0;
  183241. case WM_WINDOWPOSCHANGED:
  183242. handleMovedOrResized();
  183243. if (dontRepaint)
  183244. break; // needed for non-accelerated openGL windows to draw themselves correctly..
  183245. return 0;
  183246. case WM_KEYDOWN:
  183247. case WM_SYSKEYDOWN:
  183248. if (doKeyDown (wParam))
  183249. return 0;
  183250. break;
  183251. case WM_KEYUP:
  183252. case WM_SYSKEYUP:
  183253. if (doKeyUp (wParam))
  183254. return 0;
  183255. break;
  183256. case WM_CHAR:
  183257. if (doKeyChar ((int) wParam, lParam))
  183258. return 0;
  183259. break;
  183260. case WM_APPCOMMAND:
  183261. if (doAppCommand (lParam))
  183262. return TRUE;
  183263. break;
  183264. case WM_SETFOCUS:
  183265. updateKeyModifiers();
  183266. handleFocusGain();
  183267. break;
  183268. case WM_KILLFOCUS:
  183269. if (hasCreatedCaret)
  183270. {
  183271. hasCreatedCaret = false;
  183272. DestroyCaret();
  183273. }
  183274. handleFocusLoss();
  183275. break;
  183276. case WM_ACTIVATEAPP:
  183277. // Windows does weird things to process priority when you swap apps,
  183278. // so this forces an update when the app is brought to the front
  183279. if (wParam != FALSE)
  183280. juce_repeatLastProcessPriority();
  183281. else
  183282. Desktop::getInstance().setKioskModeComponent (0); // turn kiosk mode off if we lose focus
  183283. juce_CheckCurrentlyFocusedTopLevelWindow();
  183284. modifiersAtLastCallback = -1;
  183285. return 0;
  183286. case WM_ACTIVATE:
  183287. if (LOWORD (wParam) == WA_ACTIVE || LOWORD (wParam) == WA_CLICKACTIVE)
  183288. {
  183289. modifiersAtLastCallback = -1;
  183290. updateKeyModifiers();
  183291. if (isMinimised())
  183292. {
  183293. component->repaint();
  183294. handleMovedOrResized();
  183295. if (! isValidMessageListener())
  183296. return 0;
  183297. }
  183298. if (LOWORD (wParam) == WA_CLICKACTIVE
  183299. && component->isCurrentlyBlockedByAnotherModalComponent())
  183300. {
  183301. int mx, my;
  183302. component->getMouseXYRelative (mx, my);
  183303. Component* const underMouse = component->getComponentAt (mx, my);
  183304. if (underMouse != 0 && underMouse->isCurrentlyBlockedByAnotherModalComponent())
  183305. Component::getCurrentlyModalComponent()->inputAttemptWhenModal();
  183306. return 0;
  183307. }
  183308. handleBroughtToFront();
  183309. if (component->isCurrentlyBlockedByAnotherModalComponent())
  183310. Component::getCurrentlyModalComponent()->toFront (true);
  183311. return 0;
  183312. }
  183313. break;
  183314. case WM_NCACTIVATE:
  183315. // while a temporary window is being shown, prevent Windows from deactivating the
  183316. // title bars of our main windows.
  183317. if (wParam == 0 && ! shouldDeactivateTitleBar)
  183318. wParam = TRUE; // change this and let it get passed to the DefWindowProc.
  183319. break;
  183320. case WM_MOUSEACTIVATE:
  183321. if (! component->getMouseClickGrabsKeyboardFocus())
  183322. return MA_NOACTIVATE;
  183323. break;
  183324. case WM_SHOWWINDOW:
  183325. if (wParam != 0)
  183326. handleBroughtToFront();
  183327. break;
  183328. case WM_CLOSE:
  183329. if (! component->isCurrentlyBlockedByAnotherModalComponent())
  183330. handleUserClosingWindow();
  183331. return 0;
  183332. case WM_QUERYENDSESSION:
  183333. if (JUCEApplication::getInstance() != 0)
  183334. {
  183335. JUCEApplication::getInstance()->systemRequestedQuit();
  183336. return MessageManager::getInstance()->hasStopMessageBeenSent();
  183337. }
  183338. return TRUE;
  183339. case WM_TRAYNOTIFY:
  183340. if (component->isCurrentlyBlockedByAnotherModalComponent())
  183341. {
  183342. if (lParam == WM_LBUTTONDOWN || lParam == WM_RBUTTONDOWN
  183343. || lParam == WM_LBUTTONDBLCLK || lParam == WM_LBUTTONDBLCLK)
  183344. {
  183345. Component* const current = Component::getCurrentlyModalComponent();
  183346. if (current != 0)
  183347. current->inputAttemptWhenModal();
  183348. }
  183349. }
  183350. else
  183351. {
  183352. const int oldModifiers = currentModifiers;
  183353. MouseEvent e (0, 0, ModifierKeys::getCurrentModifiersRealtime(), component,
  183354. getMouseEventTime(), 0, 0, getMouseEventTime(), 1, false);
  183355. if (lParam == WM_LBUTTONDOWN || lParam == WM_LBUTTONDBLCLK)
  183356. e.mods = ModifierKeys (e.mods.getRawFlags() | ModifierKeys::leftButtonModifier);
  183357. else if (lParam == WM_RBUTTONDOWN || lParam == WM_RBUTTONDBLCLK)
  183358. e.mods = ModifierKeys (e.mods.getRawFlags() | ModifierKeys::rightButtonModifier);
  183359. if (lParam == WM_LBUTTONDOWN || lParam == WM_RBUTTONDOWN)
  183360. {
  183361. SetFocus (hwnd);
  183362. SetForegroundWindow (hwnd);
  183363. component->mouseDown (e);
  183364. }
  183365. else if (lParam == WM_LBUTTONUP || lParam == WM_RBUTTONUP)
  183366. {
  183367. e.mods = ModifierKeys (oldModifiers);
  183368. component->mouseUp (e);
  183369. }
  183370. else if (lParam == WM_LBUTTONDBLCLK || lParam == WM_LBUTTONDBLCLK)
  183371. {
  183372. e.mods = ModifierKeys (oldModifiers);
  183373. component->mouseDoubleClick (e);
  183374. }
  183375. else if (lParam == WM_MOUSEMOVE)
  183376. {
  183377. component->mouseMove (e);
  183378. }
  183379. }
  183380. break;
  183381. case WM_SYNCPAINT:
  183382. return 0;
  183383. case WM_PALETTECHANGED:
  183384. InvalidateRect (h, 0, 0);
  183385. break;
  183386. case WM_DISPLAYCHANGE:
  183387. InvalidateRect (h, 0, 0);
  183388. createPaletteIfNeeded = true;
  183389. // intentional fall-through...
  183390. case WM_SETTINGCHANGE: // note the fall-through in the previous case!
  183391. doSettingChange();
  183392. break;
  183393. case WM_INITMENU:
  183394. if (! hasTitleBar())
  183395. {
  183396. if (isFullScreen())
  183397. {
  183398. EnableMenuItem ((HMENU) wParam, SC_RESTORE, MF_BYCOMMAND | MF_ENABLED);
  183399. EnableMenuItem ((HMENU) wParam, SC_MOVE, MF_BYCOMMAND | MF_GRAYED);
  183400. }
  183401. else if (! isMinimised())
  183402. {
  183403. EnableMenuItem ((HMENU) wParam, SC_MAXIMIZE, MF_BYCOMMAND | MF_GRAYED);
  183404. }
  183405. }
  183406. break;
  183407. case WM_SYSCOMMAND:
  183408. switch (wParam & 0xfff0)
  183409. {
  183410. case SC_CLOSE:
  183411. if (sendInputAttemptWhenModalMessage())
  183412. return 0;
  183413. if (hasTitleBar())
  183414. {
  183415. PostMessage (h, WM_CLOSE, 0, 0);
  183416. return 0;
  183417. }
  183418. break;
  183419. case SC_KEYMENU:
  183420. // (NB mustn't call sendInputAttemptWhenModalMessage() here because of very
  183421. // obscure situations that can arise if a modal loop is started from an alt-key
  183422. // keypress).
  183423. if (hasTitleBar() && h == GetCapture())
  183424. ReleaseCapture();
  183425. break;
  183426. case SC_MAXIMIZE:
  183427. if (sendInputAttemptWhenModalMessage())
  183428. return 0;
  183429. setFullScreen (true);
  183430. return 0;
  183431. case SC_MINIMIZE:
  183432. if (sendInputAttemptWhenModalMessage())
  183433. return 0;
  183434. if (! hasTitleBar())
  183435. {
  183436. setMinimised (true);
  183437. return 0;
  183438. }
  183439. break;
  183440. case SC_RESTORE:
  183441. if (sendInputAttemptWhenModalMessage())
  183442. return 0;
  183443. if (hasTitleBar())
  183444. {
  183445. if (isFullScreen())
  183446. {
  183447. setFullScreen (false);
  183448. return 0;
  183449. }
  183450. }
  183451. else
  183452. {
  183453. if (isMinimised())
  183454. setMinimised (false);
  183455. else if (isFullScreen())
  183456. setFullScreen (false);
  183457. return 0;
  183458. }
  183459. break;
  183460. }
  183461. break;
  183462. case WM_NCLBUTTONDOWN:
  183463. case WM_NCRBUTTONDOWN:
  183464. case WM_NCMBUTTONDOWN:
  183465. sendInputAttemptWhenModalMessage();
  183466. break;
  183467. //case WM_IME_STARTCOMPOSITION;
  183468. // return 0;
  183469. case WM_GETDLGCODE:
  183470. return DLGC_WANTALLKEYS;
  183471. default:
  183472. break;
  183473. }
  183474. }
  183475. return DefWindowProc (h, message, wParam, lParam);
  183476. }
  183477. bool sendInputAttemptWhenModalMessage()
  183478. {
  183479. if (component->isCurrentlyBlockedByAnotherModalComponent())
  183480. {
  183481. Component* const current = Component::getCurrentlyModalComponent();
  183482. if (current != 0)
  183483. current->inputAttemptWhenModal();
  183484. return true;
  183485. }
  183486. return false;
  183487. }
  183488. Win32ComponentPeer (const Win32ComponentPeer&);
  183489. const Win32ComponentPeer& operator= (const Win32ComponentPeer&);
  183490. };
  183491. ComponentPeer* Component::createNewPeer (int styleFlags, void* /*nativeWindowToAttachTo*/)
  183492. {
  183493. return new Win32ComponentPeer (this, styleFlags);
  183494. }
  183495. juce_ImplementSingleton_SingleThreaded (Win32ComponentPeer::WindowClassHolder);
  183496. void SystemTrayIconComponent::setIconImage (const Image& newImage)
  183497. {
  183498. Win32ComponentPeer* const wp = dynamic_cast <Win32ComponentPeer*> (getPeer());
  183499. if (wp != 0)
  183500. wp->setTaskBarIcon (&newImage);
  183501. }
  183502. void SystemTrayIconComponent::setIconTooltip (const String& tooltip)
  183503. {
  183504. Win32ComponentPeer* const wp = dynamic_cast <Win32ComponentPeer*> (getPeer());
  183505. if (wp != 0)
  183506. wp->setTaskBarIconToolTip (tooltip);
  183507. }
  183508. void juce_setWindowStyleBit (HWND h, const int styleType, const int feature, const bool bitIsSet) throw()
  183509. {
  183510. DWORD val = GetWindowLong (h, styleType);
  183511. if (bitIsSet)
  183512. val |= feature;
  183513. else
  183514. val &= ~feature;
  183515. SetWindowLongPtr (h, styleType, val);
  183516. SetWindowPos (h, 0, 0, 0, 0, 0,
  183517. SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER
  183518. | SWP_NOOWNERZORDER | SWP_FRAMECHANGED | SWP_NOSENDCHANGING);
  183519. }
  183520. bool Process::isForegroundProcess()
  183521. {
  183522. HWND fg = GetForegroundWindow();
  183523. if (fg == 0)
  183524. return true;
  183525. // when running as a plugin in IE8, the browser UI runs in a different process to the plugin, so
  183526. // process ID isn't a reliable way to check if the foreground window belongs to us - instead, we
  183527. // have to see if any of our windows are children of the foreground window
  183528. fg = GetAncestor (fg, GA_ROOT);
  183529. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  183530. {
  183531. Win32ComponentPeer* const wp = dynamic_cast <Win32ComponentPeer*> (ComponentPeer::getPeer (i));
  183532. if (wp != 0 && wp->isInside (fg))
  183533. return true;
  183534. }
  183535. return false;
  183536. }
  183537. bool AlertWindow::showNativeDialogBox (const String& title,
  183538. const String& bodyText,
  183539. bool isOkCancel)
  183540. {
  183541. return MessageBox (0, bodyText, title,
  183542. MB_SETFOREGROUND | (isOkCancel ? MB_OKCANCEL
  183543. : MB_OK)) == IDOK;
  183544. }
  183545. void Desktop::getMousePosition (int& x, int& y) throw()
  183546. {
  183547. POINT mousePos;
  183548. GetCursorPos (&mousePos);
  183549. x = mousePos.x;
  183550. y = mousePos.y;
  183551. }
  183552. void Desktop::setMousePosition (int x, int y) throw()
  183553. {
  183554. SetCursorPos (x, y);
  183555. }
  183556. Image* Image::createNativeImage (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage)
  183557. {
  183558. return new Image (format, imageWidth, imageHeight, clearImage);
  183559. }
  183560. class ScreenSaverDefeater : public Timer,
  183561. public DeletedAtShutdown
  183562. {
  183563. public:
  183564. ScreenSaverDefeater() throw()
  183565. {
  183566. startTimer (10000);
  183567. timerCallback();
  183568. }
  183569. ~ScreenSaverDefeater() {}
  183570. void timerCallback()
  183571. {
  183572. if (Process::isForegroundProcess())
  183573. {
  183574. // simulate a shift key getting pressed..
  183575. INPUT input[2];
  183576. input[0].type = INPUT_KEYBOARD;
  183577. input[0].ki.wVk = VK_SHIFT;
  183578. input[0].ki.dwFlags = 0;
  183579. input[0].ki.dwExtraInfo = 0;
  183580. input[1].type = INPUT_KEYBOARD;
  183581. input[1].ki.wVk = VK_SHIFT;
  183582. input[1].ki.dwFlags = KEYEVENTF_KEYUP;
  183583. input[1].ki.dwExtraInfo = 0;
  183584. SendInput (2, input, sizeof (INPUT));
  183585. }
  183586. }
  183587. };
  183588. static ScreenSaverDefeater* screenSaverDefeater = 0;
  183589. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  183590. {
  183591. if (isEnabled)
  183592. {
  183593. deleteAndZero (screenSaverDefeater);
  183594. }
  183595. else if (screenSaverDefeater == 0)
  183596. {
  183597. screenSaverDefeater = new ScreenSaverDefeater();
  183598. }
  183599. }
  183600. bool Desktop::isScreenSaverEnabled() throw()
  183601. {
  183602. return screenSaverDefeater == 0;
  183603. }
  183604. void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool /*allowMenusAndBars*/)
  183605. {
  183606. if (enableOrDisable)
  183607. kioskModeComponent->setBounds (Desktop::getInstance().getMainMonitorArea (false));
  183608. }
  183609. static BOOL CALLBACK enumMonitorsProc (HMONITOR, HDC, LPRECT r, LPARAM userInfo)
  183610. {
  183611. Array <Rectangle<int> >* const monitorCoords = (Array <Rectangle<int> >*) userInfo;
  183612. monitorCoords->add (Rectangle<int> (r->left, r->top, r->right - r->left, r->bottom - r->top));
  183613. return TRUE;
  183614. }
  183615. void juce_updateMultiMonitorInfo (Array <Rectangle<int> >& monitorCoords, const bool clipToWorkArea)
  183616. {
  183617. EnumDisplayMonitors (0, 0, &enumMonitorsProc, (LPARAM) &monitorCoords);
  183618. // make sure the first in the list is the main monitor
  183619. for (int i = 1; i < monitorCoords.size(); ++i)
  183620. if (monitorCoords[i].getX() == 0 && monitorCoords[i].getY() == 0)
  183621. monitorCoords.swap (i, 0);
  183622. if (monitorCoords.size() == 0)
  183623. {
  183624. RECT r;
  183625. GetWindowRect (GetDesktopWindow(), &r);
  183626. monitorCoords.add (Rectangle<int> (r.left, r.top, r.right - r.left, r.bottom - r.top));
  183627. }
  183628. if (clipToWorkArea)
  183629. {
  183630. // clip the main monitor to the active non-taskbar area
  183631. RECT r;
  183632. SystemParametersInfo (SPI_GETWORKAREA, 0, &r, 0);
  183633. Rectangle<int>& screen = monitorCoords.getReference (0);
  183634. screen.setPosition (jmax (screen.getX(), (int) r.left),
  183635. jmax (screen.getY(), (int) r.top));
  183636. screen.setSize (jmin (screen.getRight(), (int) r.right) - screen.getX(),
  183637. jmin (screen.getBottom(), (int) r.bottom) - screen.getY());
  183638. }
  183639. }
  183640. static Image* createImageFromHBITMAP (HBITMAP bitmap) throw()
  183641. {
  183642. Image* im = 0;
  183643. if (bitmap != 0)
  183644. {
  183645. BITMAP bm;
  183646. if (GetObject (bitmap, sizeof (BITMAP), &bm)
  183647. && bm.bmWidth > 0 && bm.bmHeight > 0)
  183648. {
  183649. HDC tempDC = GetDC (0);
  183650. HDC dc = CreateCompatibleDC (tempDC);
  183651. ReleaseDC (0, tempDC);
  183652. SelectObject (dc, bitmap);
  183653. im = new Image (Image::ARGB, bm.bmWidth, bm.bmHeight, true);
  183654. for (int y = bm.bmHeight; --y >= 0;)
  183655. {
  183656. for (int x = bm.bmWidth; --x >= 0;)
  183657. {
  183658. COLORREF col = GetPixel (dc, x, y);
  183659. im->setPixelAt (x, y, Colour ((uint8) GetRValue (col),
  183660. (uint8) GetGValue (col),
  183661. (uint8) GetBValue (col)));
  183662. }
  183663. }
  183664. DeleteDC (dc);
  183665. }
  183666. }
  183667. return im;
  183668. }
  183669. static Image* createImageFromHICON (HICON icon) throw()
  183670. {
  183671. ICONINFO info;
  183672. if (GetIconInfo (icon, &info))
  183673. {
  183674. Image* const mask = createImageFromHBITMAP (info.hbmMask);
  183675. if (mask == 0)
  183676. return 0;
  183677. Image* const image = createImageFromHBITMAP (info.hbmColor);
  183678. if (image == 0)
  183679. return mask;
  183680. for (int y = image->getHeight(); --y >= 0;)
  183681. {
  183682. for (int x = image->getWidth(); --x >= 0;)
  183683. {
  183684. const float brightness = mask->getPixelAt (x, y).getBrightness();
  183685. if (brightness > 0.0f)
  183686. image->multiplyAlphaAt (x, y, 1.0f - brightness);
  183687. }
  183688. }
  183689. delete mask;
  183690. return image;
  183691. }
  183692. return 0;
  183693. }
  183694. static HICON createHICONFromImage (const Image& image, const BOOL isIcon, int hotspotX, int hotspotY) throw()
  183695. {
  183696. HBITMAP mask = CreateBitmap (image.getWidth(), image.getHeight(), 1, 1, 0);
  183697. ICONINFO info;
  183698. info.fIcon = isIcon;
  183699. info.xHotspot = hotspotX;
  183700. info.yHotspot = hotspotY;
  183701. info.hbmMask = mask;
  183702. HICON hi = 0;
  183703. if (SystemStats::getOperatingSystemType() >= SystemStats::WinXP)
  183704. {
  183705. WindowsBitmapImage bitmap (Image::ARGB, image.getWidth(), image.getHeight(), true);
  183706. Graphics g (bitmap);
  183707. g.drawImageAt (&image, 0, 0);
  183708. info.hbmColor = bitmap.hBitmap;
  183709. hi = CreateIconIndirect (&info);
  183710. }
  183711. else
  183712. {
  183713. HBITMAP colour = CreateCompatibleBitmap (GetDC (0), image.getWidth(), image.getHeight());
  183714. HDC colDC = CreateCompatibleDC (GetDC (0));
  183715. HDC alphaDC = CreateCompatibleDC (GetDC (0));
  183716. SelectObject (colDC, colour);
  183717. SelectObject (alphaDC, mask);
  183718. for (int y = image.getHeight(); --y >= 0;)
  183719. {
  183720. for (int x = image.getWidth(); --x >= 0;)
  183721. {
  183722. const Colour c (image.getPixelAt (x, y));
  183723. SetPixel (colDC, x, y, COLORREF (c.getRed() | (c.getGreen() << 8) | (c.getBlue() << 16)));
  183724. SetPixel (alphaDC, x, y, COLORREF (0xffffff - (c.getAlpha() | (c.getAlpha() << 8) | (c.getAlpha() << 16))));
  183725. }
  183726. }
  183727. DeleteDC (colDC);
  183728. DeleteDC (alphaDC);
  183729. info.hbmColor = colour;
  183730. hi = CreateIconIndirect (&info);
  183731. DeleteObject (colour);
  183732. }
  183733. DeleteObject (mask);
  183734. return hi;
  183735. }
  183736. Image* juce_createIconForFile (const File& file)
  183737. {
  183738. Image* image = 0;
  183739. TCHAR filename [1024];
  183740. file.getFullPathName().copyToBuffer (filename, 1023);
  183741. WORD iconNum = 0;
  183742. HICON icon = ExtractAssociatedIcon ((HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle(),
  183743. filename, &iconNum);
  183744. if (icon != 0)
  183745. {
  183746. image = createImageFromHICON (icon);
  183747. DestroyIcon (icon);
  183748. }
  183749. return image;
  183750. }
  183751. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw()
  183752. {
  183753. const int maxW = GetSystemMetrics (SM_CXCURSOR);
  183754. const int maxH = GetSystemMetrics (SM_CYCURSOR);
  183755. const Image* im = &image;
  183756. Image* newIm = 0;
  183757. if (image.getWidth() > maxW || image.getHeight() > maxH)
  183758. {
  183759. im = newIm = image.createCopy (maxW, maxH);
  183760. hotspotX = (hotspotX * maxW) / image.getWidth();
  183761. hotspotY = (hotspotY * maxH) / image.getHeight();
  183762. }
  183763. void* cursorH = 0;
  183764. const SystemStats::OperatingSystemType os = SystemStats::getOperatingSystemType();
  183765. if (os == SystemStats::WinXP)
  183766. {
  183767. cursorH = (void*) createHICONFromImage (*im, FALSE, hotspotX, hotspotY);
  183768. }
  183769. else
  183770. {
  183771. const int stride = (maxW + 7) >> 3;
  183772. HeapBlock <uint8> andPlane, xorPlane;
  183773. andPlane.calloc (stride * maxH);
  183774. xorPlane.calloc (stride * maxH);
  183775. int index = 0;
  183776. for (int y = 0; y < maxH; ++y)
  183777. {
  183778. for (int x = 0; x < maxW; ++x)
  183779. {
  183780. const unsigned char bit = (unsigned char) (1 << (7 - (x & 7)));
  183781. const Colour pixelColour (im->getPixelAt (x, y));
  183782. if (pixelColour.getAlpha() < 127)
  183783. andPlane [index + (x >> 3)] |= bit;
  183784. else if (pixelColour.getBrightness() >= 0.5f)
  183785. xorPlane [index + (x >> 3)] |= bit;
  183786. }
  183787. index += stride;
  183788. }
  183789. cursorH = CreateCursor (0, hotspotX, hotspotY, maxW, maxH, andPlane, xorPlane);
  183790. }
  183791. delete newIm;
  183792. return cursorH;
  183793. }
  183794. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw()
  183795. {
  183796. if (cursorHandle != 0 && ! isStandard)
  183797. DestroyCursor ((HCURSOR) cursorHandle);
  183798. }
  183799. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw()
  183800. {
  183801. LPCTSTR cursorName = IDC_ARROW;
  183802. switch (type)
  183803. {
  183804. case MouseCursor::NormalCursor:
  183805. cursorName = IDC_ARROW;
  183806. break;
  183807. case MouseCursor::NoCursor:
  183808. return 0;
  183809. case MouseCursor::DraggingHandCursor:
  183810. {
  183811. static void* dragHandCursor = 0;
  183812. if (dragHandCursor == 0)
  183813. {
  183814. static const unsigned char dragHandData[] =
  183815. { 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,
  183816. 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,
  183817. 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 };
  183818. const ScopedPointer <Image> image (ImageFileFormat::loadFrom ((const char*) dragHandData, sizeof (dragHandData)));
  183819. dragHandCursor = juce_createMouseCursorFromImage (*image, 8, 7);
  183820. }
  183821. return dragHandCursor;
  183822. }
  183823. case MouseCursor::WaitCursor:
  183824. cursorName = IDC_WAIT;
  183825. break;
  183826. case MouseCursor::IBeamCursor:
  183827. cursorName = IDC_IBEAM;
  183828. break;
  183829. case MouseCursor::PointingHandCursor:
  183830. cursorName = MAKEINTRESOURCE(32649);
  183831. break;
  183832. case MouseCursor::LeftRightResizeCursor:
  183833. case MouseCursor::LeftEdgeResizeCursor:
  183834. case MouseCursor::RightEdgeResizeCursor:
  183835. cursorName = IDC_SIZEWE;
  183836. break;
  183837. case MouseCursor::UpDownResizeCursor:
  183838. case MouseCursor::TopEdgeResizeCursor:
  183839. case MouseCursor::BottomEdgeResizeCursor:
  183840. cursorName = IDC_SIZENS;
  183841. break;
  183842. case MouseCursor::TopLeftCornerResizeCursor:
  183843. case MouseCursor::BottomRightCornerResizeCursor:
  183844. cursorName = IDC_SIZENWSE;
  183845. break;
  183846. case MouseCursor::TopRightCornerResizeCursor:
  183847. case MouseCursor::BottomLeftCornerResizeCursor:
  183848. cursorName = IDC_SIZENESW;
  183849. break;
  183850. case MouseCursor::UpDownLeftRightResizeCursor:
  183851. cursorName = IDC_SIZEALL;
  183852. break;
  183853. case MouseCursor::CrosshairCursor:
  183854. cursorName = IDC_CROSS;
  183855. break;
  183856. case MouseCursor::CopyingCursor:
  183857. // can't seem to find one of these in the win32 list..
  183858. break;
  183859. }
  183860. HCURSOR cursorH = LoadCursor (0, cursorName);
  183861. if (cursorH == 0)
  183862. cursorH = LoadCursor (0, IDC_ARROW);
  183863. return (void*) cursorH;
  183864. }
  183865. void MouseCursor::showInWindow (ComponentPeer*) const throw()
  183866. {
  183867. SetCursor ((HCURSOR) getHandle());
  183868. }
  183869. void MouseCursor::showInAllWindows() const throw()
  183870. {
  183871. showInWindow (0);
  183872. }
  183873. class JuceDropSource : public IDropSource
  183874. {
  183875. int refCount;
  183876. public:
  183877. JuceDropSource()
  183878. : refCount (1)
  183879. {
  183880. }
  183881. virtual ~JuceDropSource()
  183882. {
  183883. jassert (refCount == 0);
  183884. }
  183885. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  183886. {
  183887. if (id == IID_IUnknown || id == IID_IDropSource)
  183888. {
  183889. AddRef();
  183890. *result = this;
  183891. return S_OK;
  183892. }
  183893. *result = 0;
  183894. return E_NOINTERFACE;
  183895. }
  183896. ULONG __stdcall AddRef() { return ++refCount; }
  183897. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  183898. HRESULT __stdcall QueryContinueDrag (BOOL escapePressed, DWORD keys)
  183899. {
  183900. if (escapePressed)
  183901. return DRAGDROP_S_CANCEL;
  183902. if ((keys & (MK_LBUTTON | MK_RBUTTON)) == 0)
  183903. return DRAGDROP_S_DROP;
  183904. return S_OK;
  183905. }
  183906. HRESULT __stdcall GiveFeedback (DWORD)
  183907. {
  183908. return DRAGDROP_S_USEDEFAULTCURSORS;
  183909. }
  183910. };
  183911. class JuceEnumFormatEtc : public IEnumFORMATETC
  183912. {
  183913. public:
  183914. JuceEnumFormatEtc (const FORMATETC* const format_)
  183915. : refCount (1),
  183916. format (format_),
  183917. index (0)
  183918. {
  183919. }
  183920. virtual ~JuceEnumFormatEtc()
  183921. {
  183922. jassert (refCount == 0);
  183923. }
  183924. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  183925. {
  183926. if (id == IID_IUnknown || id == IID_IEnumFORMATETC)
  183927. {
  183928. AddRef();
  183929. *result = this;
  183930. return S_OK;
  183931. }
  183932. *result = 0;
  183933. return E_NOINTERFACE;
  183934. }
  183935. ULONG __stdcall AddRef() { return ++refCount; }
  183936. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  183937. HRESULT __stdcall Clone (IEnumFORMATETC** result)
  183938. {
  183939. if (result == 0)
  183940. return E_POINTER;
  183941. JuceEnumFormatEtc* const newOne = new JuceEnumFormatEtc (format);
  183942. newOne->index = index;
  183943. *result = newOne;
  183944. return S_OK;
  183945. }
  183946. HRESULT __stdcall Next (ULONG celt, LPFORMATETC lpFormatEtc, ULONG* pceltFetched)
  183947. {
  183948. if (pceltFetched != 0)
  183949. *pceltFetched = 0;
  183950. else if (celt != 1)
  183951. return S_FALSE;
  183952. if (index == 0 && celt > 0 && lpFormatEtc != 0)
  183953. {
  183954. copyFormatEtc (lpFormatEtc [0], *format);
  183955. ++index;
  183956. if (pceltFetched != 0)
  183957. *pceltFetched = 1;
  183958. return S_OK;
  183959. }
  183960. return S_FALSE;
  183961. }
  183962. HRESULT __stdcall Skip (ULONG celt)
  183963. {
  183964. if (index + (int) celt >= 1)
  183965. return S_FALSE;
  183966. index += celt;
  183967. return S_OK;
  183968. }
  183969. HRESULT __stdcall Reset()
  183970. {
  183971. index = 0;
  183972. return S_OK;
  183973. }
  183974. private:
  183975. int refCount;
  183976. const FORMATETC* const format;
  183977. int index;
  183978. static void copyFormatEtc (FORMATETC& dest, const FORMATETC& source)
  183979. {
  183980. dest = source;
  183981. if (source.ptd != 0)
  183982. {
  183983. dest.ptd = (DVTARGETDEVICE*) CoTaskMemAlloc (sizeof (DVTARGETDEVICE));
  183984. *(dest.ptd) = *(source.ptd);
  183985. }
  183986. }
  183987. JuceEnumFormatEtc (const JuceEnumFormatEtc&);
  183988. const JuceEnumFormatEtc& operator= (const JuceEnumFormatEtc&);
  183989. };
  183990. class JuceDataObject : public IDataObject
  183991. {
  183992. JuceDropSource* const dropSource;
  183993. const FORMATETC* const format;
  183994. const STGMEDIUM* const medium;
  183995. int refCount;
  183996. JuceDataObject (const JuceDataObject&);
  183997. const JuceDataObject& operator= (const JuceDataObject&);
  183998. public:
  183999. JuceDataObject (JuceDropSource* const dropSource_,
  184000. const FORMATETC* const format_,
  184001. const STGMEDIUM* const medium_)
  184002. : dropSource (dropSource_),
  184003. format (format_),
  184004. medium (medium_),
  184005. refCount (1)
  184006. {
  184007. }
  184008. virtual ~JuceDataObject()
  184009. {
  184010. jassert (refCount == 0);
  184011. }
  184012. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184013. {
  184014. if (id == IID_IUnknown || id == IID_IDataObject)
  184015. {
  184016. AddRef();
  184017. *result = this;
  184018. return S_OK;
  184019. }
  184020. *result = 0;
  184021. return E_NOINTERFACE;
  184022. }
  184023. ULONG __stdcall AddRef() { return ++refCount; }
  184024. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  184025. HRESULT __stdcall GetData (FORMATETC __RPC_FAR* pFormatEtc, STGMEDIUM __RPC_FAR* pMedium)
  184026. {
  184027. if (pFormatEtc->tymed == format->tymed
  184028. && pFormatEtc->cfFormat == format->cfFormat
  184029. && pFormatEtc->dwAspect == format->dwAspect)
  184030. {
  184031. pMedium->tymed = format->tymed;
  184032. pMedium->pUnkForRelease = 0;
  184033. if (format->tymed == TYMED_HGLOBAL)
  184034. {
  184035. const SIZE_T len = GlobalSize (medium->hGlobal);
  184036. void* const src = GlobalLock (medium->hGlobal);
  184037. void* const dst = GlobalAlloc (GMEM_FIXED, len);
  184038. memcpy (dst, src, len);
  184039. GlobalUnlock (medium->hGlobal);
  184040. pMedium->hGlobal = dst;
  184041. return S_OK;
  184042. }
  184043. }
  184044. return DV_E_FORMATETC;
  184045. }
  184046. HRESULT __stdcall QueryGetData (FORMATETC __RPC_FAR* f)
  184047. {
  184048. if (f == 0)
  184049. return E_INVALIDARG;
  184050. if (f->tymed == format->tymed
  184051. && f->cfFormat == format->cfFormat
  184052. && f->dwAspect == format->dwAspect)
  184053. return S_OK;
  184054. return DV_E_FORMATETC;
  184055. }
  184056. HRESULT __stdcall GetCanonicalFormatEtc (FORMATETC __RPC_FAR*, FORMATETC __RPC_FAR* pFormatEtcOut)
  184057. {
  184058. pFormatEtcOut->ptd = 0;
  184059. return E_NOTIMPL;
  184060. }
  184061. HRESULT __stdcall EnumFormatEtc (DWORD direction, IEnumFORMATETC __RPC_FAR *__RPC_FAR *result)
  184062. {
  184063. if (result == 0)
  184064. return E_POINTER;
  184065. if (direction == DATADIR_GET)
  184066. {
  184067. *result = new JuceEnumFormatEtc (format);
  184068. return S_OK;
  184069. }
  184070. *result = 0;
  184071. return E_NOTIMPL;
  184072. }
  184073. HRESULT __stdcall GetDataHere (FORMATETC __RPC_FAR*, STGMEDIUM __RPC_FAR*) { return DATA_E_FORMATETC; }
  184074. HRESULT __stdcall SetData (FORMATETC __RPC_FAR*, STGMEDIUM __RPC_FAR*, BOOL) { return E_NOTIMPL; }
  184075. HRESULT __stdcall DAdvise (FORMATETC __RPC_FAR*, DWORD, IAdviseSink __RPC_FAR*, DWORD __RPC_FAR*) { return OLE_E_ADVISENOTSUPPORTED; }
  184076. HRESULT __stdcall DUnadvise (DWORD) { return E_NOTIMPL; }
  184077. HRESULT __stdcall EnumDAdvise (IEnumSTATDATA __RPC_FAR *__RPC_FAR *) { return OLE_E_ADVISENOTSUPPORTED; }
  184078. };
  184079. static HDROP createHDrop (const StringArray& fileNames) throw()
  184080. {
  184081. int totalChars = 0;
  184082. for (int i = fileNames.size(); --i >= 0;)
  184083. totalChars += fileNames[i].length() + 1;
  184084. HDROP hDrop = (HDROP) GlobalAlloc (GMEM_MOVEABLE | GMEM_ZEROINIT,
  184085. sizeof (DROPFILES)
  184086. + sizeof (WCHAR) * (totalChars + 2));
  184087. if (hDrop != 0)
  184088. {
  184089. LPDROPFILES pDropFiles = (LPDROPFILES) GlobalLock (hDrop);
  184090. pDropFiles->pFiles = sizeof (DROPFILES);
  184091. pDropFiles->fWide = true;
  184092. WCHAR* fname = (WCHAR*) (((char*) pDropFiles) + sizeof (DROPFILES));
  184093. for (int i = 0; i < fileNames.size(); ++i)
  184094. {
  184095. fileNames[i].copyToBuffer (fname, 2048);
  184096. fname += fileNames[i].length() + 1;
  184097. }
  184098. *fname = 0;
  184099. GlobalUnlock (hDrop);
  184100. }
  184101. return hDrop;
  184102. }
  184103. static bool performDragDrop (FORMATETC* const format, STGMEDIUM* const medium, const DWORD whatToDo) throw()
  184104. {
  184105. JuceDropSource* const source = new JuceDropSource();
  184106. JuceDataObject* const data = new JuceDataObject (source, format, medium);
  184107. DWORD effect;
  184108. const HRESULT res = DoDragDrop (data, source, whatToDo, &effect);
  184109. data->Release();
  184110. source->Release();
  184111. return res == DRAGDROP_S_DROP;
  184112. }
  184113. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMove)
  184114. {
  184115. FORMATETC format = { CF_HDROP, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
  184116. STGMEDIUM medium = { TYMED_HGLOBAL, { 0 }, 0 };
  184117. medium.hGlobal = createHDrop (files);
  184118. return performDragDrop (&format, &medium, canMove ? (DROPEFFECT_COPY | DROPEFFECT_MOVE)
  184119. : DROPEFFECT_COPY);
  184120. }
  184121. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  184122. {
  184123. FORMATETC format = { CF_TEXT, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
  184124. STGMEDIUM medium = { TYMED_HGLOBAL, { 0 }, 0 };
  184125. const int numChars = text.length();
  184126. medium.hGlobal = GlobalAlloc (GMEM_MOVEABLE | GMEM_ZEROINIT, (numChars + 2) * sizeof (WCHAR));
  184127. char* d = (char*) GlobalLock (medium.hGlobal);
  184128. text.copyToBuffer ((WCHAR*) d, numChars + 1);
  184129. format.cfFormat = CF_UNICODETEXT;
  184130. GlobalUnlock (medium.hGlobal);
  184131. return performDragDrop (&format, &medium, DROPEFFECT_COPY | DROPEFFECT_MOVE);
  184132. }
  184133. #endif
  184134. /*** End of inlined file: juce_win32_Windowing.cpp ***/
  184135. /*** Start of inlined file: juce_win32_Fonts.cpp ***/
  184136. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  184137. // compiled on its own).
  184138. #if JUCE_INCLUDED_FILE
  184139. static int CALLBACK wfontEnum2 (ENUMLOGFONTEXW* lpelfe,
  184140. NEWTEXTMETRICEXW*,
  184141. int type,
  184142. LPARAM lParam)
  184143. {
  184144. if (lpelfe != 0 && (type & RASTER_FONTTYPE) == 0)
  184145. {
  184146. const String fontName (lpelfe->elfLogFont.lfFaceName);
  184147. ((StringArray*) lParam)->addIfNotAlreadyThere (fontName.removeCharacters (T("@")));
  184148. }
  184149. return 1;
  184150. }
  184151. static int CALLBACK wfontEnum1 (ENUMLOGFONTEXW* lpelfe,
  184152. NEWTEXTMETRICEXW*,
  184153. int type,
  184154. LPARAM lParam)
  184155. {
  184156. if (lpelfe != 0 && (type & RASTER_FONTTYPE) == 0)
  184157. {
  184158. LOGFONTW lf;
  184159. zerostruct (lf);
  184160. lf.lfWeight = FW_DONTCARE;
  184161. lf.lfOutPrecision = OUT_OUTLINE_PRECIS;
  184162. lf.lfQuality = DEFAULT_QUALITY;
  184163. lf.lfCharSet = DEFAULT_CHARSET;
  184164. lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  184165. lf.lfPitchAndFamily = FF_DONTCARE;
  184166. const String fontName (lpelfe->elfLogFont.lfFaceName);
  184167. fontName.copyToBuffer (lf.lfFaceName, LF_FACESIZE - 1);
  184168. HDC dc = CreateCompatibleDC (0);
  184169. EnumFontFamiliesEx (dc, &lf,
  184170. (FONTENUMPROCW) &wfontEnum2,
  184171. lParam, 0);
  184172. DeleteDC (dc);
  184173. }
  184174. return 1;
  184175. }
  184176. const StringArray Font::findAllTypefaceNames() throw()
  184177. {
  184178. StringArray results;
  184179. HDC dc = CreateCompatibleDC (0);
  184180. {
  184181. LOGFONTW lf;
  184182. zerostruct (lf);
  184183. lf.lfWeight = FW_DONTCARE;
  184184. lf.lfOutPrecision = OUT_OUTLINE_PRECIS;
  184185. lf.lfQuality = DEFAULT_QUALITY;
  184186. lf.lfCharSet = DEFAULT_CHARSET;
  184187. lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  184188. lf.lfPitchAndFamily = FF_DONTCARE;
  184189. lf.lfFaceName[0] = 0;
  184190. EnumFontFamiliesEx (dc, &lf,
  184191. (FONTENUMPROCW) &wfontEnum1,
  184192. (LPARAM) &results, 0);
  184193. }
  184194. DeleteDC (dc);
  184195. results.sort (true);
  184196. return results;
  184197. }
  184198. extern bool juce_IsRunningInWine();
  184199. void Font::getPlatformDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed) throw()
  184200. {
  184201. if (juce_IsRunningInWine())
  184202. {
  184203. // If we're running in Wine, then use fonts that might be available on Linux..
  184204. defaultSans = "Bitstream Vera Sans";
  184205. defaultSerif = "Bitstream Vera Serif";
  184206. defaultFixed = "Bitstream Vera Sans Mono";
  184207. }
  184208. else
  184209. {
  184210. defaultSans = "Verdana";
  184211. defaultSerif = "Times";
  184212. defaultFixed = "Lucida Console";
  184213. }
  184214. }
  184215. class FontDCHolder : private DeletedAtShutdown
  184216. {
  184217. public:
  184218. FontDCHolder() throw()
  184219. : dc (0), numKPs (0), size (0),
  184220. bold (false), italic (false)
  184221. {
  184222. }
  184223. ~FontDCHolder() throw()
  184224. {
  184225. if (dc != 0)
  184226. {
  184227. DeleteDC (dc);
  184228. DeleteObject (fontH);
  184229. }
  184230. clearSingletonInstance();
  184231. }
  184232. juce_DeclareSingleton_SingleThreaded_Minimal (FontDCHolder);
  184233. HDC loadFont (const String& fontName_, const bool bold_, const bool italic_, const int size_) throw()
  184234. {
  184235. if (fontName != fontName_ || bold != bold_ || italic != italic_ || size != size_)
  184236. {
  184237. fontName = fontName_;
  184238. bold = bold_;
  184239. italic = italic_;
  184240. size = size_;
  184241. if (dc != 0)
  184242. {
  184243. DeleteDC (dc);
  184244. DeleteObject (fontH);
  184245. kps.free();
  184246. }
  184247. fontH = 0;
  184248. dc = CreateCompatibleDC (0);
  184249. SetMapperFlags (dc, 0);
  184250. SetMapMode (dc, MM_TEXT);
  184251. LOGFONTW lfw;
  184252. zerostruct (lfw);
  184253. lfw.lfCharSet = DEFAULT_CHARSET;
  184254. lfw.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  184255. lfw.lfOutPrecision = OUT_OUTLINE_PRECIS;
  184256. lfw.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
  184257. lfw.lfQuality = PROOF_QUALITY;
  184258. lfw.lfItalic = (BYTE) (italic ? TRUE : FALSE);
  184259. lfw.lfWeight = bold ? FW_BOLD : FW_NORMAL;
  184260. fontName.copyToBuffer (lfw.lfFaceName, LF_FACESIZE - 1);
  184261. lfw.lfHeight = size > 0 ? size : -256;
  184262. HFONT standardSizedFont = CreateFontIndirect (&lfw);
  184263. if (standardSizedFont != 0)
  184264. {
  184265. if (SelectObject (dc, standardSizedFont) != 0)
  184266. {
  184267. fontH = standardSizedFont;
  184268. if (size == 0)
  184269. {
  184270. OUTLINETEXTMETRIC otm;
  184271. if (GetOutlineTextMetrics (dc, sizeof (otm), &otm) != 0)
  184272. {
  184273. lfw.lfHeight = -(int) otm.otmEMSquare;
  184274. fontH = CreateFontIndirect (&lfw);
  184275. SelectObject (dc, fontH);
  184276. DeleteObject (standardSizedFont);
  184277. }
  184278. }
  184279. }
  184280. else
  184281. {
  184282. jassertfalse
  184283. }
  184284. }
  184285. else
  184286. {
  184287. jassertfalse
  184288. }
  184289. }
  184290. return dc;
  184291. }
  184292. KERNINGPAIR* getKerningPairs (int& numKPs_) throw()
  184293. {
  184294. if (kps == 0)
  184295. {
  184296. numKPs = GetKerningPairs (dc, 0, 0);
  184297. kps.calloc (numKPs);
  184298. GetKerningPairs (dc, numKPs, kps);
  184299. }
  184300. numKPs_ = numKPs;
  184301. return kps;
  184302. }
  184303. private:
  184304. HFONT fontH;
  184305. HDC dc;
  184306. String fontName;
  184307. HeapBlock <KERNINGPAIR> kps;
  184308. int numKPs, size;
  184309. bool bold, italic;
  184310. FontDCHolder (const FontDCHolder&);
  184311. const FontDCHolder& operator= (const FontDCHolder&);
  184312. };
  184313. juce_ImplementSingleton_SingleThreaded (FontDCHolder);
  184314. class WindowsTypeface : public CustomTypeface
  184315. {
  184316. public:
  184317. WindowsTypeface (const Font& font)
  184318. {
  184319. HDC dc = FontDCHolder::getInstance()->loadFont (font.getTypefaceName(),
  184320. font.isBold(), font.isItalic(), 0);
  184321. TEXTMETRIC tm;
  184322. tm.tmAscent = tm.tmHeight = 1;
  184323. tm.tmDefaultChar = 0;
  184324. GetTextMetrics (dc, &tm);
  184325. setCharacteristics (font.getTypefaceName(),
  184326. tm.tmAscent / (float) tm.tmHeight,
  184327. font.isBold(), font.isItalic(),
  184328. tm.tmDefaultChar);
  184329. }
  184330. bool loadGlyphIfPossible (const juce_wchar character)
  184331. {
  184332. HDC dc = FontDCHolder::getInstance()->loadFont (name, isBold, isItalic, 0);
  184333. GLYPHMETRICS gm;
  184334. {
  184335. const WCHAR charToTest[] = { (WCHAR) character, 0 };
  184336. WORD index = 0;
  184337. if (GetGlyphIndices (dc, charToTest, 1, &index, GGI_MARK_NONEXISTING_GLYPHS) != GDI_ERROR
  184338. && index == 0xffff)
  184339. {
  184340. return false;
  184341. }
  184342. }
  184343. Path glyphPath;
  184344. TEXTMETRIC tm;
  184345. if (! GetTextMetrics (dc, &tm))
  184346. {
  184347. addGlyph (character, glyphPath, 0);
  184348. return true;
  184349. }
  184350. const float height = (float) tm.tmHeight;
  184351. static const MAT2 identityMatrix = { { 0, 1 }, { 0, 0 }, { 0, 0 }, { 0, 1 } };
  184352. const int bufSize = GetGlyphOutline (dc, character, GGO_NATIVE,
  184353. &gm, 0, 0, &identityMatrix);
  184354. if (bufSize > 0)
  184355. {
  184356. HeapBlock <char> data (bufSize);
  184357. GetGlyphOutline (dc, character, GGO_NATIVE, &gm,
  184358. bufSize, data, &identityMatrix);
  184359. const TTPOLYGONHEADER* pheader = (TTPOLYGONHEADER*) data;
  184360. const float scaleX = 1.0f / height;
  184361. const float scaleY = -1.0f / height;
  184362. while ((char*) pheader < data + bufSize)
  184363. {
  184364. #define remapX(v) (scaleX * (v).x.value)
  184365. #define remapY(v) (scaleY * (v).y.value)
  184366. float x = remapX (pheader->pfxStart);
  184367. float y = remapY (pheader->pfxStart);
  184368. glyphPath.startNewSubPath (x, y);
  184369. const TTPOLYCURVE* curve = (const TTPOLYCURVE*) ((const char*) pheader + sizeof (TTPOLYGONHEADER));
  184370. const char* const curveEnd = ((const char*) pheader) + pheader->cb;
  184371. while ((const char*) curve < curveEnd)
  184372. {
  184373. if (curve->wType == TT_PRIM_LINE)
  184374. {
  184375. for (int i = 0; i < curve->cpfx; ++i)
  184376. {
  184377. x = remapX (curve->apfx [i]);
  184378. y = remapY (curve->apfx [i]);
  184379. glyphPath.lineTo (x, y);
  184380. }
  184381. }
  184382. else if (curve->wType == TT_PRIM_QSPLINE)
  184383. {
  184384. for (int i = 0; i < curve->cpfx - 1; ++i)
  184385. {
  184386. const float x2 = remapX (curve->apfx [i]);
  184387. const float y2 = remapY (curve->apfx [i]);
  184388. float x3, y3;
  184389. if (i < curve->cpfx - 2)
  184390. {
  184391. x3 = 0.5f * (x2 + remapX (curve->apfx [i + 1]));
  184392. y3 = 0.5f * (y2 + remapY (curve->apfx [i + 1]));
  184393. }
  184394. else
  184395. {
  184396. x3 = remapX (curve->apfx [i + 1]);
  184397. y3 = remapY (curve->apfx [i + 1]);
  184398. }
  184399. glyphPath.quadraticTo (x2, y2, x3, y3);
  184400. x = x3;
  184401. y = y3;
  184402. }
  184403. }
  184404. curve = (const TTPOLYCURVE*) &(curve->apfx [curve->cpfx]);
  184405. }
  184406. pheader = (const TTPOLYGONHEADER*) curve;
  184407. glyphPath.closeSubPath();
  184408. }
  184409. }
  184410. addGlyph (character, glyphPath, gm.gmCellIncX / height);
  184411. int numKPs;
  184412. const KERNINGPAIR* const kps = FontDCHolder::getInstance()->getKerningPairs (numKPs);
  184413. for (int i = 0; i < numKPs; ++i)
  184414. {
  184415. if (kps[i].wFirst == character)
  184416. addKerningPair (kps[i].wFirst, kps[i].wSecond,
  184417. kps[i].iKernAmount / height);
  184418. }
  184419. return true;
  184420. }
  184421. };
  184422. const Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  184423. {
  184424. return new WindowsTypeface (font);
  184425. }
  184426. #endif
  184427. /*** End of inlined file: juce_win32_Fonts.cpp ***/
  184428. /*** Start of inlined file: juce_win32_FileChooser.cpp ***/
  184429. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  184430. // compiled on its own).
  184431. #if JUCE_INCLUDED_FILE
  184432. static const void* defaultDirPath = 0;
  184433. static String returnedString; // need this to get non-existent pathnames from the directory chooser
  184434. static Component* currentExtraFileWin = 0;
  184435. static bool areThereAnyAlwaysOnTopWindows()
  184436. {
  184437. for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
  184438. {
  184439. Component* c = Desktop::getInstance().getComponent (i);
  184440. if (c != 0 && c->isAlwaysOnTop() && c->isShowing())
  184441. return true;
  184442. }
  184443. return false;
  184444. }
  184445. static int CALLBACK browseCallbackProc (HWND hWnd, UINT msg, LPARAM lParam, LPARAM /*lpData*/)
  184446. {
  184447. if (msg == BFFM_INITIALIZED)
  184448. {
  184449. SendMessage (hWnd, BFFM_SETSELECTIONW, TRUE, (LPARAM) defaultDirPath);
  184450. }
  184451. else if (msg == BFFM_VALIDATEFAILEDW)
  184452. {
  184453. returnedString = (LPCWSTR) lParam;
  184454. }
  184455. else if (msg == BFFM_VALIDATEFAILEDA)
  184456. {
  184457. returnedString = (const char*) lParam;
  184458. }
  184459. return 0;
  184460. }
  184461. void juce_setWindowStyleBit (HWND h, const int styleType, const int feature, const bool bitIsSet) throw();
  184462. static UINT_PTR CALLBACK openCallback (HWND hdlg, UINT uiMsg, WPARAM /*wParam*/, LPARAM lParam)
  184463. {
  184464. if (currentExtraFileWin != 0)
  184465. {
  184466. if (uiMsg == WM_INITDIALOG)
  184467. {
  184468. HWND dialogH = GetParent (hdlg);
  184469. jassert (dialogH != 0);
  184470. if (dialogH == 0)
  184471. dialogH = hdlg;
  184472. RECT r, cr;
  184473. GetWindowRect (dialogH, &r);
  184474. GetClientRect (dialogH, &cr);
  184475. SetWindowPos (dialogH, 0,
  184476. r.left, r.top,
  184477. currentExtraFileWin->getWidth() + jmax (150, (int) (r.right - r.left)),
  184478. jmax (150, (int) (r.bottom - r.top)),
  184479. SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
  184480. currentExtraFileWin->setBounds (cr.right, cr.top, currentExtraFileWin->getWidth(), cr.bottom - cr.top);
  184481. currentExtraFileWin->getChildComponent(0)->setBounds (0, 0, currentExtraFileWin->getWidth(), currentExtraFileWin->getHeight());
  184482. SetParent ((HWND) currentExtraFileWin->getWindowHandle(), (HWND) dialogH);
  184483. juce_setWindowStyleBit ((HWND)currentExtraFileWin->getWindowHandle(), GWL_STYLE, WS_CHILD, (dialogH != 0));
  184484. juce_setWindowStyleBit ((HWND)currentExtraFileWin->getWindowHandle(), GWL_STYLE, WS_POPUP, (dialogH == 0));
  184485. }
  184486. else if (uiMsg == WM_NOTIFY)
  184487. {
  184488. LPOFNOTIFY ofn = (LPOFNOTIFY) lParam;
  184489. if (ofn->hdr.code == CDN_SELCHANGE)
  184490. {
  184491. FilePreviewComponent* comp = (FilePreviewComponent*) currentExtraFileWin->getChildComponent(0);
  184492. if (comp != 0)
  184493. {
  184494. TCHAR path [MAX_PATH * 2];
  184495. path[0] = 0;
  184496. CommDlg_OpenSave_GetFilePath (GetParent (hdlg), (LPARAM) &path, MAX_PATH);
  184497. const String fn ((const WCHAR*) path);
  184498. comp->selectedFileChanged (File (fn));
  184499. }
  184500. }
  184501. }
  184502. }
  184503. return 0;
  184504. }
  184505. class FPComponentHolder : public Component
  184506. {
  184507. public:
  184508. FPComponentHolder()
  184509. {
  184510. setVisible (true);
  184511. setOpaque (true);
  184512. }
  184513. ~FPComponentHolder()
  184514. {
  184515. }
  184516. void paint (Graphics& g)
  184517. {
  184518. g.fillAll (Colours::lightgrey);
  184519. }
  184520. private:
  184521. FPComponentHolder (const FPComponentHolder&);
  184522. const FPComponentHolder& operator= (const FPComponentHolder&);
  184523. };
  184524. void FileChooser::showPlatformDialog (Array<File>& results,
  184525. const String& title,
  184526. const File& currentFileOrDirectory,
  184527. const String& filter,
  184528. bool selectsDirectory,
  184529. bool /*selectsFiles*/,
  184530. bool isSaveDialogue,
  184531. bool warnAboutOverwritingExistingFiles,
  184532. bool selectMultipleFiles,
  184533. FilePreviewComponent* extraInfoComponent)
  184534. {
  184535. const int numCharsAvailable = 32768;
  184536. MemoryBlock filenameSpace ((numCharsAvailable + 1) * sizeof (WCHAR), true);
  184537. WCHAR* const fname = (WCHAR*) filenameSpace.getData();
  184538. int fnameIdx = 0;
  184539. JUCE_TRY
  184540. {
  184541. // use a modal window as the parent for this dialog box
  184542. // to block input from other app windows
  184543. const Rectangle<int> mainMon (Desktop::getInstance().getMainMonitorArea());
  184544. Component w (String::empty);
  184545. w.setBounds (mainMon.getX() + mainMon.getWidth() / 4,
  184546. mainMon.getY() + mainMon.getHeight() / 4,
  184547. 0, 0);
  184548. w.setOpaque (true);
  184549. w.setAlwaysOnTop (areThereAnyAlwaysOnTopWindows());
  184550. w.addToDesktop (0);
  184551. if (extraInfoComponent == 0)
  184552. w.enterModalState();
  184553. String initialDir;
  184554. if (currentFileOrDirectory.isDirectory())
  184555. {
  184556. initialDir = currentFileOrDirectory.getFullPathName();
  184557. }
  184558. else
  184559. {
  184560. currentFileOrDirectory.getFileName().copyToBuffer (fname, numCharsAvailable);
  184561. initialDir = currentFileOrDirectory.getParentDirectory().getFullPathName();
  184562. }
  184563. if (currentExtraFileWin->isValidComponent())
  184564. {
  184565. jassertfalse
  184566. return;
  184567. }
  184568. if (selectsDirectory)
  184569. {
  184570. LPITEMIDLIST list = 0;
  184571. filenameSpace.fillWith (0);
  184572. {
  184573. BROWSEINFO bi;
  184574. zerostruct (bi);
  184575. bi.hwndOwner = (HWND) w.getWindowHandle();
  184576. bi.pszDisplayName = fname;
  184577. bi.lpszTitle = title;
  184578. bi.lpfn = browseCallbackProc;
  184579. #ifdef BIF_USENEWUI
  184580. bi.ulFlags = BIF_USENEWUI | BIF_VALIDATE;
  184581. #else
  184582. bi.ulFlags = 0x50;
  184583. #endif
  184584. defaultDirPath = (const WCHAR*) initialDir;
  184585. list = SHBrowseForFolder (&bi);
  184586. if (! SHGetPathFromIDListW (list, fname))
  184587. {
  184588. fname[0] = 0;
  184589. returnedString = String::empty;
  184590. }
  184591. }
  184592. LPMALLOC al;
  184593. if (list != 0 && SUCCEEDED (SHGetMalloc (&al)))
  184594. al->Free (list);
  184595. defaultDirPath = 0;
  184596. if (returnedString.isNotEmpty())
  184597. {
  184598. const String stringFName (fname);
  184599. results.add (File (stringFName).getSiblingFile (returnedString));
  184600. returnedString = String::empty;
  184601. return;
  184602. }
  184603. }
  184604. else
  184605. {
  184606. DWORD flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
  184607. if (warnAboutOverwritingExistingFiles)
  184608. flags |= OFN_OVERWRITEPROMPT;
  184609. if (selectMultipleFiles)
  184610. flags |= OFN_ALLOWMULTISELECT;
  184611. if (extraInfoComponent != 0)
  184612. {
  184613. flags |= OFN_ENABLEHOOK;
  184614. currentExtraFileWin = new FPComponentHolder();
  184615. currentExtraFileWin->addAndMakeVisible (extraInfoComponent);
  184616. currentExtraFileWin->setSize (jlimit (20, 800, extraInfoComponent->getWidth()),
  184617. extraInfoComponent->getHeight());
  184618. currentExtraFileWin->addToDesktop (0);
  184619. currentExtraFileWin->enterModalState();
  184620. }
  184621. {
  184622. WCHAR filters [1024];
  184623. zeromem (filters, sizeof (filters));
  184624. filter.copyToBuffer (filters, 1024);
  184625. filter.copyToBuffer (filters + filter.length() + 1,
  184626. 1022 - filter.length());
  184627. OPENFILENAMEW of;
  184628. zerostruct (of);
  184629. #ifdef OPENFILENAME_SIZE_VERSION_400W
  184630. of.lStructSize = OPENFILENAME_SIZE_VERSION_400W;
  184631. #else
  184632. of.lStructSize = sizeof (of);
  184633. #endif
  184634. of.hwndOwner = (HWND) w.getWindowHandle();
  184635. of.lpstrFilter = filters;
  184636. of.nFilterIndex = 1;
  184637. of.lpstrFile = fname;
  184638. of.nMaxFile = numCharsAvailable;
  184639. of.lpstrInitialDir = initialDir;
  184640. of.lpstrTitle = title;
  184641. of.Flags = flags;
  184642. if (extraInfoComponent != 0)
  184643. of.lpfnHook = &openCallback;
  184644. if (isSaveDialogue)
  184645. {
  184646. if (! GetSaveFileName (&of))
  184647. fname[0] = 0;
  184648. else
  184649. fnameIdx = of.nFileOffset;
  184650. }
  184651. else
  184652. {
  184653. if (! GetOpenFileName (&of))
  184654. fname[0] = 0;
  184655. else
  184656. fnameIdx = of.nFileOffset;
  184657. }
  184658. }
  184659. }
  184660. }
  184661. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  184662. catch (...)
  184663. {
  184664. fname[0] = 0;
  184665. }
  184666. #endif
  184667. deleteAndZero (currentExtraFileWin);
  184668. const WCHAR* const files = fname;
  184669. if (selectMultipleFiles && fnameIdx > 0 && files [fnameIdx - 1] == 0)
  184670. {
  184671. const WCHAR* filename = files + fnameIdx;
  184672. while (*filename != 0)
  184673. {
  184674. const String filepath (String (files) + T("\\") + String (filename));
  184675. results.add (File (filepath));
  184676. filename += CharacterFunctions::length (filename) + 1;
  184677. }
  184678. }
  184679. else if (files[0] != 0)
  184680. {
  184681. results.add (File (files));
  184682. }
  184683. }
  184684. #endif
  184685. /*** End of inlined file: juce_win32_FileChooser.cpp ***/
  184686. /*** Start of inlined file: juce_win32_Misc.cpp ***/
  184687. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  184688. // compiled on its own).
  184689. #if JUCE_INCLUDED_FILE
  184690. void SystemClipboard::copyTextToClipboard (const String& text) throw()
  184691. {
  184692. if (OpenClipboard (0) != 0)
  184693. {
  184694. if (EmptyClipboard() != 0)
  184695. {
  184696. const int len = text.length();
  184697. if (len > 0)
  184698. {
  184699. HGLOBAL bufH = GlobalAlloc (GMEM_MOVEABLE | GMEM_DDESHARE,
  184700. (len + 1) * sizeof (wchar_t));
  184701. if (bufH != 0)
  184702. {
  184703. wchar_t* const data = (wchar_t*) GlobalLock (bufH);
  184704. text.copyToBuffer (data, len);
  184705. GlobalUnlock (bufH);
  184706. SetClipboardData (CF_UNICODETEXT, bufH);
  184707. }
  184708. }
  184709. }
  184710. CloseClipboard();
  184711. }
  184712. }
  184713. const String SystemClipboard::getTextFromClipboard() throw()
  184714. {
  184715. String result;
  184716. if (OpenClipboard (0) != 0)
  184717. {
  184718. HANDLE bufH = GetClipboardData (CF_UNICODETEXT);
  184719. if (bufH != 0)
  184720. {
  184721. const wchar_t* const data = (const wchar_t*) GlobalLock (bufH);
  184722. if (data != 0)
  184723. {
  184724. result = String (data, (int) (GlobalSize (bufH) / sizeof (tchar)));
  184725. GlobalUnlock (bufH);
  184726. }
  184727. }
  184728. CloseClipboard();
  184729. }
  184730. return result;
  184731. }
  184732. #endif
  184733. /*** End of inlined file: juce_win32_Misc.cpp ***/
  184734. /*** Start of inlined file: juce_win32_ActiveXComponent.cpp ***/
  184735. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  184736. // compiled on its own).
  184737. #if JUCE_INCLUDED_FILE
  184738. class JuceIStorage : public IStorage
  184739. {
  184740. int refCount;
  184741. public:
  184742. JuceIStorage() : refCount (1) {}
  184743. virtual ~JuceIStorage()
  184744. {
  184745. jassert (refCount == 0);
  184746. }
  184747. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184748. {
  184749. if (id == IID_IUnknown || id == IID_IStorage)
  184750. {
  184751. AddRef();
  184752. *result = this;
  184753. return S_OK;
  184754. }
  184755. *result = 0;
  184756. return E_NOINTERFACE;
  184757. }
  184758. ULONG __stdcall AddRef() { return ++refCount; }
  184759. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  184760. HRESULT __stdcall CreateStream (const WCHAR*, DWORD, DWORD, DWORD, IStream**) { return E_NOTIMPL; }
  184761. HRESULT __stdcall OpenStream (const WCHAR*, void*, DWORD, DWORD, IStream**) { return E_NOTIMPL; }
  184762. HRESULT __stdcall CreateStorage (const WCHAR*, DWORD, DWORD, DWORD, IStorage**) { return E_NOTIMPL; }
  184763. HRESULT __stdcall OpenStorage (const WCHAR*, IStorage*, DWORD, SNB, DWORD, IStorage**) { return E_NOTIMPL; }
  184764. HRESULT __stdcall CopyTo (DWORD, IID const*, SNB, IStorage*) { return E_NOTIMPL; }
  184765. HRESULT __stdcall MoveElementTo (const OLECHAR*,IStorage*, const OLECHAR*, DWORD) { return E_NOTIMPL; }
  184766. HRESULT __stdcall Commit (DWORD) { return E_NOTIMPL; }
  184767. HRESULT __stdcall Revert() { return E_NOTIMPL; }
  184768. HRESULT __stdcall EnumElements (DWORD, void*, DWORD, IEnumSTATSTG**) { return E_NOTIMPL; }
  184769. HRESULT __stdcall DestroyElement (const OLECHAR*) { return E_NOTIMPL; }
  184770. HRESULT __stdcall RenameElement (const WCHAR*, const WCHAR*) { return E_NOTIMPL; }
  184771. HRESULT __stdcall SetElementTimes (const WCHAR*, FILETIME const*, FILETIME const*, FILETIME const*) { return E_NOTIMPL; }
  184772. HRESULT __stdcall SetClass (REFCLSID) { return S_OK; }
  184773. HRESULT __stdcall SetStateBits (DWORD, DWORD) { return E_NOTIMPL; }
  184774. HRESULT __stdcall Stat (STATSTG*, DWORD) { return E_NOTIMPL; }
  184775. juce_UseDebuggingNewOperator
  184776. };
  184777. class JuceOleInPlaceFrame : public IOleInPlaceFrame
  184778. {
  184779. int refCount;
  184780. HWND window;
  184781. public:
  184782. JuceOleInPlaceFrame (HWND window_)
  184783. : refCount (1),
  184784. window (window_)
  184785. {
  184786. }
  184787. virtual ~JuceOleInPlaceFrame()
  184788. {
  184789. jassert (refCount == 0);
  184790. }
  184791. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184792. {
  184793. if (id == IID_IUnknown || id == IID_IOleInPlaceFrame)
  184794. {
  184795. AddRef();
  184796. *result = this;
  184797. return S_OK;
  184798. }
  184799. *result = 0;
  184800. return E_NOINTERFACE;
  184801. }
  184802. ULONG __stdcall AddRef() { return ++refCount; }
  184803. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  184804. HRESULT __stdcall GetWindow (HWND* lphwnd) { *lphwnd = window; return S_OK; }
  184805. HRESULT __stdcall ContextSensitiveHelp (BOOL) { return E_NOTIMPL; }
  184806. HRESULT __stdcall GetBorder (LPRECT) { return E_NOTIMPL; }
  184807. HRESULT __stdcall RequestBorderSpace (LPCBORDERWIDTHS) { return E_NOTIMPL; }
  184808. HRESULT __stdcall SetBorderSpace (LPCBORDERWIDTHS) { return E_NOTIMPL; }
  184809. HRESULT __stdcall SetActiveObject (IOleInPlaceActiveObject*, LPCOLESTR) { return S_OK; }
  184810. HRESULT __stdcall InsertMenus (HMENU, LPOLEMENUGROUPWIDTHS) { return E_NOTIMPL; }
  184811. HRESULT __stdcall SetMenu (HMENU, HOLEMENU, HWND) { return S_OK; }
  184812. HRESULT __stdcall RemoveMenus (HMENU) { return E_NOTIMPL; }
  184813. HRESULT __stdcall SetStatusText (LPCOLESTR) { return S_OK; }
  184814. HRESULT __stdcall EnableModeless (BOOL) { return S_OK; }
  184815. HRESULT __stdcall TranslateAccelerator(LPMSG, WORD) { return E_NOTIMPL; }
  184816. juce_UseDebuggingNewOperator
  184817. };
  184818. class JuceIOleInPlaceSite : public IOleInPlaceSite
  184819. {
  184820. int refCount;
  184821. HWND window;
  184822. JuceOleInPlaceFrame* frame;
  184823. public:
  184824. JuceIOleInPlaceSite (HWND window_)
  184825. : refCount (1),
  184826. window (window_)
  184827. {
  184828. frame = new JuceOleInPlaceFrame (window);
  184829. }
  184830. virtual ~JuceIOleInPlaceSite()
  184831. {
  184832. jassert (refCount == 0);
  184833. frame->Release();
  184834. }
  184835. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184836. {
  184837. if (id == IID_IUnknown || id == IID_IOleInPlaceSite)
  184838. {
  184839. AddRef();
  184840. *result = this;
  184841. return S_OK;
  184842. }
  184843. *result = 0;
  184844. return E_NOINTERFACE;
  184845. }
  184846. ULONG __stdcall AddRef() { return ++refCount; }
  184847. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  184848. HRESULT __stdcall GetWindow (HWND* lphwnd) { *lphwnd = window; return S_OK; }
  184849. HRESULT __stdcall ContextSensitiveHelp (BOOL) { return E_NOTIMPL; }
  184850. HRESULT __stdcall CanInPlaceActivate() { return S_OK; }
  184851. HRESULT __stdcall OnInPlaceActivate() { return S_OK; }
  184852. HRESULT __stdcall OnUIActivate() { return S_OK; }
  184853. HRESULT __stdcall GetWindowContext (LPOLEINPLACEFRAME* lplpFrame, LPOLEINPLACEUIWINDOW* lplpDoc, LPRECT, LPRECT, LPOLEINPLACEFRAMEINFO lpFrameInfo)
  184854. {
  184855. // frame->AddRef(); // MS docs are unclear about whether this is needed, but it seems to lead to a memory leak..
  184856. *lplpFrame = frame;
  184857. *lplpDoc = 0;
  184858. lpFrameInfo->fMDIApp = FALSE;
  184859. lpFrameInfo->hwndFrame = window;
  184860. lpFrameInfo->haccel = 0;
  184861. lpFrameInfo->cAccelEntries = 0;
  184862. return S_OK;
  184863. }
  184864. HRESULT __stdcall Scroll (SIZE) { return E_NOTIMPL; }
  184865. HRESULT __stdcall OnUIDeactivate (BOOL) { return S_OK; }
  184866. HRESULT __stdcall OnInPlaceDeactivate() { return S_OK; }
  184867. HRESULT __stdcall DiscardUndoState() { return E_NOTIMPL; }
  184868. HRESULT __stdcall DeactivateAndUndo() { return E_NOTIMPL; }
  184869. HRESULT __stdcall OnPosRectChange (LPCRECT) { return S_OK; }
  184870. juce_UseDebuggingNewOperator
  184871. };
  184872. class JuceIOleClientSite : public IOleClientSite
  184873. {
  184874. int refCount;
  184875. JuceIOleInPlaceSite* inplaceSite;
  184876. public:
  184877. JuceIOleClientSite (HWND window)
  184878. : refCount (1)
  184879. {
  184880. inplaceSite = new JuceIOleInPlaceSite (window);
  184881. }
  184882. virtual ~JuceIOleClientSite()
  184883. {
  184884. jassert (refCount == 0);
  184885. inplaceSite->Release();
  184886. }
  184887. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184888. {
  184889. if (id == IID_IUnknown || id == IID_IOleClientSite)
  184890. {
  184891. AddRef();
  184892. *result = this;
  184893. return S_OK;
  184894. }
  184895. else if (id == IID_IOleInPlaceSite)
  184896. {
  184897. inplaceSite->AddRef();
  184898. *result = inplaceSite;
  184899. return S_OK;
  184900. }
  184901. *result = 0;
  184902. return E_NOINTERFACE;
  184903. }
  184904. ULONG __stdcall AddRef() { return ++refCount; }
  184905. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  184906. HRESULT __stdcall SaveObject() { return E_NOTIMPL; }
  184907. HRESULT __stdcall GetMoniker (DWORD, DWORD, IMoniker**) { return E_NOTIMPL; }
  184908. HRESULT __stdcall GetContainer (LPOLECONTAINER* ppContainer) { *ppContainer = 0; return E_NOINTERFACE; }
  184909. HRESULT __stdcall ShowObject() { return S_OK; }
  184910. HRESULT __stdcall OnShowWindow (BOOL) { return E_NOTIMPL; }
  184911. HRESULT __stdcall RequestNewObjectLayout() { return E_NOTIMPL; }
  184912. juce_UseDebuggingNewOperator
  184913. };
  184914. class ActiveXControlData : public ComponentMovementWatcher
  184915. {
  184916. ActiveXControlComponent* const owner;
  184917. bool wasShowing;
  184918. public:
  184919. HWND controlHWND;
  184920. IStorage* storage;
  184921. IOleClientSite* clientSite;
  184922. IOleObject* control;
  184923. ActiveXControlData (HWND hwnd,
  184924. ActiveXControlComponent* const owner_)
  184925. : ComponentMovementWatcher (owner_),
  184926. owner (owner_),
  184927. wasShowing (owner_ != 0 && owner_->isShowing()),
  184928. controlHWND (0),
  184929. storage (new JuceIStorage()),
  184930. clientSite (new JuceIOleClientSite (hwnd)),
  184931. control (0)
  184932. {
  184933. }
  184934. ~ActiveXControlData()
  184935. {
  184936. if (control != 0)
  184937. {
  184938. control->Close (OLECLOSE_NOSAVE);
  184939. control->Release();
  184940. }
  184941. clientSite->Release();
  184942. storage->Release();
  184943. }
  184944. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  184945. {
  184946. Component* const topComp = owner->getTopLevelComponent();
  184947. if (topComp->getPeer() != 0)
  184948. {
  184949. int x = 0, y = 0;
  184950. owner->relativePositionToOtherComponent (topComp, x, y);
  184951. owner->setControlBounds (Rectangle<int> (x, y, owner->getWidth(), owner->getHeight()));
  184952. }
  184953. }
  184954. void componentPeerChanged()
  184955. {
  184956. const bool isShowingNow = owner->isShowing();
  184957. if (wasShowing != isShowingNow)
  184958. {
  184959. wasShowing = isShowingNow;
  184960. owner->setControlVisible (isShowingNow);
  184961. }
  184962. componentMovedOrResized (true, true);
  184963. }
  184964. void componentVisibilityChanged (Component&)
  184965. {
  184966. componentPeerChanged();
  184967. }
  184968. static bool doesWindowMatch (const ActiveXControlComponent* const ax, HWND hwnd)
  184969. {
  184970. return ((ActiveXControlData*) ax->control) != 0
  184971. && ((ActiveXControlData*) ax->control)->controlHWND == hwnd;
  184972. }
  184973. };
  184974. static VoidArray activeXComps;
  184975. static HWND getHWND (const ActiveXControlComponent* const component)
  184976. {
  184977. HWND hwnd = 0;
  184978. const IID iid = IID_IOleWindow;
  184979. IOleWindow* const window = (IOleWindow*) component->queryInterface (&iid);
  184980. if (window != 0)
  184981. {
  184982. window->GetWindow (&hwnd);
  184983. window->Release();
  184984. }
  184985. return hwnd;
  184986. }
  184987. static void offerActiveXMouseEventToPeer (ComponentPeer* const peer, HWND hwnd, UINT message, LPARAM lParam)
  184988. {
  184989. RECT activeXRect, peerRect;
  184990. GetWindowRect (hwnd, &activeXRect);
  184991. GetWindowRect ((HWND) peer->getNativeHandle(), &peerRect);
  184992. const int mx = GET_X_LPARAM (lParam) + activeXRect.left - peerRect.left;
  184993. const int my = GET_Y_LPARAM (lParam) + activeXRect.top - peerRect.top;
  184994. const int64 mouseEventTime = getMouseEventTime();
  184995. const int oldModifiers = currentModifiers;
  184996. ModifierKeys::getCurrentModifiersRealtime(); // to update the mouse button flags
  184997. switch (message)
  184998. {
  184999. case WM_MOUSEMOVE:
  185000. if (ModifierKeys (currentModifiers).isAnyMouseButtonDown())
  185001. peer->handleMouseDrag (mx, my, mouseEventTime);
  185002. else
  185003. peer->handleMouseMove (mx, my, mouseEventTime);
  185004. break;
  185005. case WM_LBUTTONDOWN:
  185006. case WM_MBUTTONDOWN:
  185007. case WM_RBUTTONDOWN:
  185008. peer->handleMouseDown (mx, my, mouseEventTime);
  185009. break;
  185010. case WM_LBUTTONUP:
  185011. case WM_MBUTTONUP:
  185012. case WM_RBUTTONUP:
  185013. peer->handleMouseUp (oldModifiers, mx, my, mouseEventTime);
  185014. break;
  185015. default:
  185016. break;
  185017. }
  185018. }
  185019. // intercepts events going to an activeX control, so we can sneakily use the mouse events
  185020. static LRESULT CALLBACK activeXHookWndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  185021. {
  185022. for (int i = activeXComps.size(); --i >= 0;)
  185023. {
  185024. const ActiveXControlComponent* const ax = (const ActiveXControlComponent*) activeXComps.getUnchecked(i);
  185025. if (ActiveXControlData::doesWindowMatch (ax, hwnd))
  185026. {
  185027. switch (message)
  185028. {
  185029. case WM_MOUSEMOVE:
  185030. case WM_LBUTTONDOWN:
  185031. case WM_MBUTTONDOWN:
  185032. case WM_RBUTTONDOWN:
  185033. case WM_LBUTTONUP:
  185034. case WM_MBUTTONUP:
  185035. case WM_RBUTTONUP:
  185036. case WM_LBUTTONDBLCLK:
  185037. case WM_MBUTTONDBLCLK:
  185038. case WM_RBUTTONDBLCLK:
  185039. if (ax->isShowing())
  185040. {
  185041. ComponentPeer* const peer = ax->getPeer();
  185042. if (peer != 0)
  185043. {
  185044. offerActiveXMouseEventToPeer (peer, hwnd, message, lParam);
  185045. if (! ax->areMouseEventsAllowed())
  185046. return 0;
  185047. }
  185048. }
  185049. break;
  185050. default:
  185051. break;
  185052. }
  185053. return CallWindowProc ((WNDPROC) (ax->originalWndProc), hwnd, message, wParam, lParam);
  185054. }
  185055. }
  185056. return DefWindowProc (hwnd, message, wParam, lParam);
  185057. }
  185058. ActiveXControlComponent::ActiveXControlComponent()
  185059. : originalWndProc (0),
  185060. control (0),
  185061. mouseEventsAllowed (true)
  185062. {
  185063. activeXComps.add (this);
  185064. }
  185065. ActiveXControlComponent::~ActiveXControlComponent()
  185066. {
  185067. deleteControl();
  185068. activeXComps.removeValue (this);
  185069. }
  185070. void ActiveXControlComponent::paint (Graphics& g)
  185071. {
  185072. if (control == 0)
  185073. g.fillAll (Colours::lightgrey);
  185074. }
  185075. bool ActiveXControlComponent::createControl (const void* controlIID)
  185076. {
  185077. deleteControl();
  185078. ComponentPeer* const peer = getPeer();
  185079. // the component must have already been added to a real window when you call this!
  185080. jassert (dynamic_cast <Win32ComponentPeer*> (peer) != 0);
  185081. if (dynamic_cast <Win32ComponentPeer*> (peer) != 0)
  185082. {
  185083. int x = 0, y = 0;
  185084. relativePositionToOtherComponent (getTopLevelComponent(), x, y);
  185085. HWND hwnd = (HWND) peer->getNativeHandle();
  185086. ScopedPointer <ActiveXControlData> info (new ActiveXControlData (hwnd, this));
  185087. HRESULT hr;
  185088. if ((hr = OleCreate (*(const IID*) controlIID, IID_IOleObject, 1 /*OLERENDER_DRAW*/, 0,
  185089. info->clientSite, info->storage,
  185090. (void**) &(info->control))) == S_OK)
  185091. {
  185092. info->control->SetHostNames (L"Juce", 0);
  185093. if (OleSetContainedObject (info->control, TRUE) == S_OK)
  185094. {
  185095. RECT rect;
  185096. rect.left = x;
  185097. rect.top = y;
  185098. rect.right = x + getWidth();
  185099. rect.bottom = y + getHeight();
  185100. if (info->control->DoVerb (OLEIVERB_SHOW, 0, info->clientSite, 0, hwnd, &rect) == S_OK)
  185101. {
  185102. control = info.release();
  185103. setControlBounds (Rectangle<int> (x, y, getWidth(), getHeight()));
  185104. ((ActiveXControlData*) control)->controlHWND = getHWND (this);
  185105. if (((ActiveXControlData*) control)->controlHWND != 0)
  185106. {
  185107. originalWndProc = (void*) (pointer_sized_int) GetWindowLongPtr ((HWND) ((ActiveXControlData*) control)->controlHWND, GWLP_WNDPROC);
  185108. SetWindowLongPtr ((HWND) ((ActiveXControlData*) control)->controlHWND, GWLP_WNDPROC, (LONG_PTR) activeXHookWndProc);
  185109. }
  185110. return true;
  185111. }
  185112. }
  185113. }
  185114. }
  185115. return false;
  185116. }
  185117. void ActiveXControlComponent::deleteControl()
  185118. {
  185119. ActiveXControlData* const info = (ActiveXControlData*) control;
  185120. if (info != 0)
  185121. {
  185122. delete info;
  185123. control = 0;
  185124. originalWndProc = 0;
  185125. }
  185126. }
  185127. void* ActiveXControlComponent::queryInterface (const void* iid) const
  185128. {
  185129. ActiveXControlData* const info = (ActiveXControlData*) control;
  185130. void* result = 0;
  185131. if (info != 0 && info->control != 0
  185132. && info->control->QueryInterface (*(const IID*) iid, &result) == S_OK)
  185133. return result;
  185134. return 0;
  185135. }
  185136. void ActiveXControlComponent::setControlBounds (const Rectangle<int>& newBounds) const
  185137. {
  185138. HWND hwnd = ((ActiveXControlData*) control)->controlHWND;
  185139. if (hwnd != 0)
  185140. MoveWindow (hwnd, newBounds.getX(), newBounds.getY(), newBounds.getWidth(), newBounds.getHeight(), TRUE);
  185141. }
  185142. void ActiveXControlComponent::setControlVisible (const bool shouldBeVisible) const
  185143. {
  185144. HWND hwnd = ((ActiveXControlData*) control)->controlHWND;
  185145. if (hwnd != 0)
  185146. ShowWindow (hwnd, shouldBeVisible ? SW_SHOWNA : SW_HIDE);
  185147. }
  185148. void ActiveXControlComponent::setMouseEventsAllowed (const bool eventsCanReachControl)
  185149. {
  185150. mouseEventsAllowed = eventsCanReachControl;
  185151. }
  185152. #endif
  185153. /*** End of inlined file: juce_win32_ActiveXComponent.cpp ***/
  185154. /*** Start of inlined file: juce_win32_QuickTimeMovieComponent.cpp ***/
  185155. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  185156. // compiled on its own).
  185157. #if JUCE_INCLUDED_FILE && JUCE_QUICKTIME
  185158. using namespace QTOLibrary;
  185159. using namespace QTOControlLib;
  185160. bool juce_OpenQuickTimeMovieFromStream (InputStream* input, Movie& movie, Handle& dataHandle);
  185161. static bool isQTAvailable = false;
  185162. struct QTMovieCompInternal
  185163. {
  185164. QTMovieCompInternal()
  185165. : dataHandle (0)
  185166. {
  185167. }
  185168. ~QTMovieCompInternal()
  185169. {
  185170. clearHandle();
  185171. }
  185172. IQTControlPtr qtControlInternal;
  185173. IQTMoviePtr qtMovieInternal;
  185174. Handle dataHandle;
  185175. void clearHandle()
  185176. {
  185177. if (dataHandle != 0)
  185178. {
  185179. DisposeHandle (dataHandle);
  185180. dataHandle = 0;
  185181. }
  185182. }
  185183. };
  185184. #define qtControl (((QTMovieCompInternal*) internal)->qtControlInternal)
  185185. #define qtMovie (((QTMovieCompInternal*) internal)->qtMovieInternal)
  185186. QuickTimeMovieComponent::QuickTimeMovieComponent()
  185187. : movieLoaded (false),
  185188. controllerVisible (true)
  185189. {
  185190. internal = new QTMovieCompInternal();
  185191. setMouseEventsAllowed (false);
  185192. }
  185193. QuickTimeMovieComponent::~QuickTimeMovieComponent()
  185194. {
  185195. closeMovie();
  185196. qtControl = 0;
  185197. deleteControl();
  185198. delete internal;
  185199. internal = 0;
  185200. }
  185201. bool QuickTimeMovieComponent::isQuickTimeAvailable() throw()
  185202. {
  185203. if (! isQTAvailable)
  185204. {
  185205. isQTAvailable = (InitializeQTML (0) == noErr)
  185206. && (EnterMovies() == noErr);
  185207. }
  185208. return isQTAvailable;
  185209. }
  185210. void QuickTimeMovieComponent::createControlIfNeeded()
  185211. {
  185212. if (isShowing() && ! isControlCreated())
  185213. {
  185214. const IID qtIID = __uuidof (QTControl);
  185215. if (createControl (&qtIID))
  185216. {
  185217. const IID qtInterfaceIID = __uuidof (IQTControl);
  185218. qtControl = (IQTControl*) queryInterface (&qtInterfaceIID);
  185219. if (qtControl != 0)
  185220. {
  185221. qtControl->Release(); // it has one ref too many at this point
  185222. qtControl->QuickTimeInitialize();
  185223. qtControl->PutSizing (qtMovieFitsControl);
  185224. if (movieFile != File::nonexistent)
  185225. loadMovie (movieFile, controllerVisible);
  185226. }
  185227. }
  185228. }
  185229. }
  185230. bool QuickTimeMovieComponent::isControlCreated() const
  185231. {
  185232. return isControlOpen();
  185233. }
  185234. bool QuickTimeMovieComponent::loadMovie (InputStream* movieStream,
  185235. const bool isControllerVisible)
  185236. {
  185237. movieFile = File::nonexistent;
  185238. movieLoaded = false;
  185239. qtMovie = 0;
  185240. controllerVisible = isControllerVisible;
  185241. createControlIfNeeded();
  185242. if (isControlCreated())
  185243. {
  185244. if (qtControl != 0)
  185245. {
  185246. qtControl->Put_MovieHandle (0);
  185247. ((QTMovieCompInternal*) internal)->clearHandle();
  185248. Movie movie;
  185249. if (juce_OpenQuickTimeMovieFromStream (movieStream, movie, ((QTMovieCompInternal*) internal)->dataHandle))
  185250. {
  185251. qtControl->Put_MovieHandle ((long) (pointer_sized_int) movie);
  185252. qtMovie = qtControl->GetMovie();
  185253. if (qtMovie != 0)
  185254. qtMovie->PutMovieControllerType (isControllerVisible ? qtMovieControllerTypeStandard
  185255. : qtMovieControllerTypeNone);
  185256. }
  185257. if (movie == 0)
  185258. ((QTMovieCompInternal*) internal)->clearHandle();
  185259. }
  185260. movieLoaded = (qtMovie != 0);
  185261. }
  185262. else
  185263. {
  185264. // You're trying to open a movie when the control hasn't yet been created, probably because
  185265. // you've not yet added this component to a Window and made the whole component hierarchy visible.
  185266. jassertfalse
  185267. }
  185268. delete movieStream;
  185269. return movieLoaded;
  185270. }
  185271. void QuickTimeMovieComponent::closeMovie()
  185272. {
  185273. stop();
  185274. movieFile = File::nonexistent;
  185275. movieLoaded = false;
  185276. qtMovie = 0;
  185277. if (qtControl != 0)
  185278. qtControl->Put_MovieHandle (0);
  185279. ((QTMovieCompInternal*) internal)->clearHandle();
  185280. }
  185281. const File QuickTimeMovieComponent::getCurrentMovieFile() const
  185282. {
  185283. return movieFile;
  185284. }
  185285. bool QuickTimeMovieComponent::isMovieOpen() const
  185286. {
  185287. return movieLoaded;
  185288. }
  185289. double QuickTimeMovieComponent::getMovieDuration() const
  185290. {
  185291. if (qtMovie != 0)
  185292. return qtMovie->GetDuration() / (double) qtMovie->GetTimeScale();
  185293. return 0.0;
  185294. }
  185295. void QuickTimeMovieComponent::getMovieNormalSize (int& width, int& height) const
  185296. {
  185297. if (qtMovie != 0)
  185298. {
  185299. struct QTRECT r = qtMovie->GetNaturalRect();
  185300. width = r.right - r.left;
  185301. height = r.bottom - r.top;
  185302. }
  185303. else
  185304. {
  185305. width = height = 0;
  185306. }
  185307. }
  185308. void QuickTimeMovieComponent::play()
  185309. {
  185310. if (qtMovie != 0)
  185311. qtMovie->Play();
  185312. }
  185313. void QuickTimeMovieComponent::stop()
  185314. {
  185315. if (qtMovie != 0)
  185316. qtMovie->Stop();
  185317. }
  185318. bool QuickTimeMovieComponent::isPlaying() const
  185319. {
  185320. return qtMovie != 0 && qtMovie->GetRate() != 0.0f;
  185321. }
  185322. void QuickTimeMovieComponent::setPosition (const double seconds)
  185323. {
  185324. if (qtMovie != 0)
  185325. qtMovie->PutTime ((long) (seconds * qtMovie->GetTimeScale()));
  185326. }
  185327. double QuickTimeMovieComponent::getPosition() const
  185328. {
  185329. if (qtMovie != 0)
  185330. return qtMovie->GetTime() / (double) qtMovie->GetTimeScale();
  185331. return 0.0;
  185332. }
  185333. void QuickTimeMovieComponent::setSpeed (const float newSpeed)
  185334. {
  185335. if (qtMovie != 0)
  185336. qtMovie->PutRate (newSpeed);
  185337. }
  185338. void QuickTimeMovieComponent::setMovieVolume (const float newVolume)
  185339. {
  185340. if (qtMovie != 0)
  185341. {
  185342. qtMovie->PutAudioVolume (newVolume);
  185343. qtMovie->PutAudioMute (newVolume <= 0);
  185344. }
  185345. }
  185346. float QuickTimeMovieComponent::getMovieVolume() const
  185347. {
  185348. if (qtMovie != 0)
  185349. return qtMovie->GetAudioVolume();
  185350. return 0.0f;
  185351. }
  185352. void QuickTimeMovieComponent::setLooping (const bool shouldLoop)
  185353. {
  185354. if (qtMovie != 0)
  185355. qtMovie->PutLoop (shouldLoop);
  185356. }
  185357. bool QuickTimeMovieComponent::isLooping() const
  185358. {
  185359. return qtMovie != 0 && qtMovie->GetLoop();
  185360. }
  185361. bool QuickTimeMovieComponent::isControllerVisible() const
  185362. {
  185363. return controllerVisible;
  185364. }
  185365. void QuickTimeMovieComponent::parentHierarchyChanged()
  185366. {
  185367. createControlIfNeeded();
  185368. QTCompBaseClass::parentHierarchyChanged();
  185369. }
  185370. void QuickTimeMovieComponent::visibilityChanged()
  185371. {
  185372. createControlIfNeeded();
  185373. QTCompBaseClass::visibilityChanged();
  185374. }
  185375. void QuickTimeMovieComponent::paint (Graphics& g)
  185376. {
  185377. if (! isControlCreated())
  185378. g.fillAll (Colours::black);
  185379. }
  185380. static Handle createHandleDataRef (Handle dataHandle, const char* fileName)
  185381. {
  185382. Handle dataRef = 0;
  185383. OSStatus err = PtrToHand (&dataHandle, &dataRef, sizeof (Handle));
  185384. if (err == noErr)
  185385. {
  185386. Str255 suffix;
  185387. CharacterFunctions::copy ((char*) suffix, fileName, 128);
  185388. StringPtr name = suffix;
  185389. err = PtrAndHand (name, dataRef, name[0] + 1);
  185390. if (err == noErr)
  185391. {
  185392. long atoms[3];
  185393. atoms[0] = EndianU32_NtoB (3 * sizeof (long));
  185394. atoms[1] = EndianU32_NtoB (kDataRefExtensionMacOSFileType);
  185395. atoms[2] = EndianU32_NtoB (MovieFileType);
  185396. err = PtrAndHand (atoms, dataRef, 3 * sizeof (long));
  185397. if (err == noErr)
  185398. return dataRef;
  185399. }
  185400. DisposeHandle (dataRef);
  185401. }
  185402. return 0;
  185403. }
  185404. static CFStringRef juceStringToCFString (const String& s)
  185405. {
  185406. const int len = s.length();
  185407. const juce_wchar* const t = (const juce_wchar*) s;
  185408. HeapBlock <UniChar> temp (len + 2);
  185409. for (int i = 0; i <= len; ++i)
  185410. temp[i] = t[i];
  185411. return CFStringCreateWithCharacters (kCFAllocatorDefault, temp, len);
  185412. }
  185413. static bool openMovie (QTNewMoviePropertyElement* props, int prop, Movie& movie)
  185414. {
  185415. Boolean trueBool = true;
  185416. props[prop].propClass = kQTPropertyClass_MovieInstantiation;
  185417. props[prop].propID = kQTMovieInstantiationPropertyID_DontResolveDataRefs;
  185418. props[prop].propValueSize = sizeof (trueBool);
  185419. props[prop].propValueAddress = &trueBool;
  185420. ++prop;
  185421. props[prop].propClass = kQTPropertyClass_MovieInstantiation;
  185422. props[prop].propID = kQTMovieInstantiationPropertyID_AsyncOK;
  185423. props[prop].propValueSize = sizeof (trueBool);
  185424. props[prop].propValueAddress = &trueBool;
  185425. ++prop;
  185426. Boolean isActive = true;
  185427. props[prop].propClass = kQTPropertyClass_NewMovieProperty;
  185428. props[prop].propID = kQTNewMoviePropertyID_Active;
  185429. props[prop].propValueSize = sizeof (isActive);
  185430. props[prop].propValueAddress = &isActive;
  185431. ++prop;
  185432. MacSetPort (0);
  185433. jassert (prop <= 5);
  185434. OSStatus err = NewMovieFromProperties (prop, props, 0, 0, &movie);
  185435. return err == noErr;
  185436. }
  185437. bool juce_OpenQuickTimeMovieFromStream (InputStream* input, Movie& movie, Handle& dataHandle)
  185438. {
  185439. if (input == 0)
  185440. return false;
  185441. dataHandle = 0;
  185442. bool ok = false;
  185443. QTNewMoviePropertyElement props[5];
  185444. zeromem (props, sizeof (props));
  185445. int prop = 0;
  185446. DataReferenceRecord dr;
  185447. props[prop].propClass = kQTPropertyClass_DataLocation;
  185448. props[prop].propID = kQTDataLocationPropertyID_DataReference;
  185449. props[prop].propValueSize = sizeof (dr);
  185450. props[prop].propValueAddress = (void*) &dr;
  185451. ++prop;
  185452. FileInputStream* const fin = dynamic_cast <FileInputStream*> (input);
  185453. if (fin != 0)
  185454. {
  185455. CFStringRef filePath = juceStringToCFString (fin->getFile().getFullPathName());
  185456. QTNewDataReferenceFromFullPathCFString (filePath, (QTPathStyle) kQTNativeDefaultPathStyle, 0,
  185457. &dr.dataRef, &dr.dataRefType);
  185458. ok = openMovie (props, prop, movie);
  185459. DisposeHandle (dr.dataRef);
  185460. CFRelease (filePath);
  185461. }
  185462. else
  185463. {
  185464. // sanity-check because this currently needs to load the whole stream into memory..
  185465. jassert (input->getTotalLength() < 50 * 1024 * 1024);
  185466. dataHandle = NewHandle ((Size) input->getTotalLength());
  185467. HLock (dataHandle);
  185468. // read the entire stream into memory - this is a pain, but can't get it to work
  185469. // properly using a custom callback to supply the data.
  185470. input->read (*dataHandle, (int) input->getTotalLength());
  185471. HUnlock (dataHandle);
  185472. // different types to get QT to try. (We should really be a bit smarter here by
  185473. // working out in advance which one the stream contains, rather than just trying
  185474. // each one)
  185475. const char* const suffixesToTry[] = { "\04.mov", "\04.mp3",
  185476. "\04.avi", "\04.m4a" };
  185477. for (int i = 0; i < numElementsInArray (suffixesToTry) && ! ok; ++i)
  185478. {
  185479. dr.dataRef = createHandleDataRef (dataHandle, suffixesToTry [i]);
  185480. dr.dataRefType = HandleDataHandlerSubType;
  185481. ok = openMovie (props, prop, movie);
  185482. DisposeHandle (dr.dataRef);
  185483. }
  185484. }
  185485. return ok;
  185486. }
  185487. bool QuickTimeMovieComponent::loadMovie (const File& movieFile_,
  185488. const bool isControllerVisible)
  185489. {
  185490. const bool ok = loadMovie ((InputStream*) movieFile_.createInputStream(), isControllerVisible);
  185491. movieFile = movieFile_;
  185492. return ok;
  185493. }
  185494. bool QuickTimeMovieComponent::loadMovie (const URL& movieURL,
  185495. const bool isControllerVisible)
  185496. {
  185497. return loadMovie ((InputStream*) movieURL.createInputStream (false), isControllerVisible);
  185498. }
  185499. void QuickTimeMovieComponent::goToStart()
  185500. {
  185501. setPosition (0.0);
  185502. }
  185503. void QuickTimeMovieComponent::setBoundsWithCorrectAspectRatio (const Rectangle<int>& spaceToFitWithin,
  185504. const RectanglePlacement& placement)
  185505. {
  185506. int normalWidth, normalHeight;
  185507. getMovieNormalSize (normalWidth, normalHeight);
  185508. if (normalWidth > 0 && normalHeight > 0 && ! spaceToFitWithin.isEmpty())
  185509. {
  185510. double x = 0.0, y = 0.0, w = normalWidth, h = normalHeight;
  185511. placement.applyTo (x, y, w, h,
  185512. spaceToFitWithin.getX(), spaceToFitWithin.getY(),
  185513. spaceToFitWithin.getWidth(), spaceToFitWithin.getHeight());
  185514. if (w > 0 && h > 0)
  185515. {
  185516. setBounds (roundToInt (x), roundToInt (y),
  185517. roundToInt (w), roundToInt (h));
  185518. }
  185519. }
  185520. else
  185521. {
  185522. setBounds (spaceToFitWithin);
  185523. }
  185524. }
  185525. #endif
  185526. /*** End of inlined file: juce_win32_QuickTimeMovieComponent.cpp ***/
  185527. /*** Start of inlined file: juce_win32_WebBrowserComponent.cpp ***/
  185528. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  185529. // compiled on its own).
  185530. #if JUCE_INCLUDED_FILE && JUCE_WEB_BROWSER
  185531. class WebBrowserComponentInternal : public ActiveXControlComponent
  185532. {
  185533. public:
  185534. WebBrowserComponentInternal()
  185535. : browser (0),
  185536. connectionPoint (0),
  185537. adviseCookie (0)
  185538. {
  185539. }
  185540. ~WebBrowserComponentInternal()
  185541. {
  185542. if (connectionPoint != 0)
  185543. connectionPoint->Unadvise (adviseCookie);
  185544. if (browser != 0)
  185545. browser->Release();
  185546. }
  185547. void createBrowser()
  185548. {
  185549. createControl (&CLSID_WebBrowser);
  185550. browser = (IWebBrowser2*) queryInterface (&IID_IWebBrowser2);
  185551. IConnectionPointContainer* connectionPointContainer = (IConnectionPointContainer*) queryInterface (&IID_IConnectionPointContainer);
  185552. if (connectionPointContainer != 0)
  185553. {
  185554. connectionPointContainer->FindConnectionPoint (DIID_DWebBrowserEvents2,
  185555. &connectionPoint);
  185556. if (connectionPoint != 0)
  185557. {
  185558. WebBrowserComponent* const owner = dynamic_cast <WebBrowserComponent*> (getParentComponent());
  185559. jassert (owner != 0);
  185560. EventHandler* handler = new EventHandler (owner);
  185561. connectionPoint->Advise (handler, &adviseCookie);
  185562. }
  185563. }
  185564. }
  185565. void goToURL (const String& url,
  185566. const StringArray* headers,
  185567. const MemoryBlock* postData)
  185568. {
  185569. if (browser != 0)
  185570. {
  185571. LPSAFEARRAY sa = 0;
  185572. VARIANT flags, frame, postDataVar, headersVar; // (_variant_t isn't available in all compilers)
  185573. VariantInit (&flags);
  185574. VariantInit (&frame);
  185575. VariantInit (&postDataVar);
  185576. VariantInit (&headersVar);
  185577. if (headers != 0)
  185578. {
  185579. V_VT (&headersVar) = VT_BSTR;
  185580. V_BSTR (&headersVar) = SysAllocString ((const tchar*) headers->joinIntoString ("\r\n"));
  185581. }
  185582. if (postData != 0 && postData->getSize() > 0)
  185583. {
  185584. LPSAFEARRAY sa = SafeArrayCreateVector (VT_UI1, 0, postData->getSize());
  185585. if (sa != 0)
  185586. {
  185587. void* data = 0;
  185588. SafeArrayAccessData (sa, &data);
  185589. jassert (data != 0);
  185590. if (data != 0)
  185591. {
  185592. postData->copyTo (data, 0, postData->getSize());
  185593. SafeArrayUnaccessData (sa);
  185594. VARIANT postDataVar2;
  185595. VariantInit (&postDataVar2);
  185596. V_VT (&postDataVar2) = VT_ARRAY | VT_UI1;
  185597. V_ARRAY (&postDataVar2) = sa;
  185598. postDataVar = postDataVar2;
  185599. }
  185600. }
  185601. }
  185602. browser->Navigate ((BSTR) (const OLECHAR*) url,
  185603. &flags, &frame,
  185604. &postDataVar, &headersVar);
  185605. if (sa != 0)
  185606. SafeArrayDestroy (sa);
  185607. VariantClear (&flags);
  185608. VariantClear (&frame);
  185609. VariantClear (&postDataVar);
  185610. VariantClear (&headersVar);
  185611. }
  185612. }
  185613. IWebBrowser2* browser;
  185614. juce_UseDebuggingNewOperator
  185615. private:
  185616. IConnectionPoint* connectionPoint;
  185617. DWORD adviseCookie;
  185618. class EventHandler : public IDispatch,
  185619. public ComponentMovementWatcher
  185620. {
  185621. public:
  185622. EventHandler (WebBrowserComponent* owner_)
  185623. : ComponentMovementWatcher (owner_),
  185624. owner (owner_),
  185625. refCount (0)
  185626. {
  185627. }
  185628. ~EventHandler()
  185629. {
  185630. }
  185631. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  185632. {
  185633. if (id == IID_IUnknown || id == IID_IDispatch || id == DIID_DWebBrowserEvents2)
  185634. {
  185635. AddRef();
  185636. *result = this;
  185637. return S_OK;
  185638. }
  185639. *result = 0;
  185640. return E_NOINTERFACE;
  185641. }
  185642. ULONG __stdcall AddRef() { return ++refCount; }
  185643. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  185644. HRESULT __stdcall GetTypeInfoCount (UINT __RPC_FAR*) { return E_NOTIMPL; }
  185645. HRESULT __stdcall GetTypeInfo (UINT, LCID, ITypeInfo __RPC_FAR *__RPC_FAR*) { return E_NOTIMPL; }
  185646. HRESULT __stdcall GetIDsOfNames (REFIID, LPOLESTR __RPC_FAR*, UINT, LCID, DISPID __RPC_FAR*) { return E_NOTIMPL; }
  185647. HRESULT __stdcall Invoke (DISPID dispIdMember, REFIID /*riid*/, LCID /*lcid*/,
  185648. WORD /*wFlags*/, DISPPARAMS __RPC_FAR* pDispParams,
  185649. VARIANT __RPC_FAR* /*pVarResult*/, EXCEPINFO __RPC_FAR* /*pExcepInfo*/,
  185650. UINT __RPC_FAR* /*puArgErr*/)
  185651. {
  185652. switch (dispIdMember)
  185653. {
  185654. case DISPID_BEFORENAVIGATE2:
  185655. {
  185656. VARIANT* const vurl = pDispParams->rgvarg[5].pvarVal;
  185657. String url;
  185658. if ((vurl->vt & VT_BYREF) != 0)
  185659. url = *vurl->pbstrVal;
  185660. else
  185661. url = vurl->bstrVal;
  185662. *pDispParams->rgvarg->pboolVal
  185663. = owner->pageAboutToLoad (url) ? VARIANT_FALSE
  185664. : VARIANT_TRUE;
  185665. return S_OK;
  185666. }
  185667. default:
  185668. break;
  185669. }
  185670. return E_NOTIMPL;
  185671. }
  185672. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/) {}
  185673. void componentPeerChanged() {}
  185674. void componentVisibilityChanged (Component&)
  185675. {
  185676. owner->visibilityChanged();
  185677. }
  185678. juce_UseDebuggingNewOperator
  185679. private:
  185680. WebBrowserComponent* const owner;
  185681. int refCount;
  185682. EventHandler (const EventHandler&);
  185683. const EventHandler& operator= (const EventHandler&);
  185684. };
  185685. };
  185686. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  185687. : browser (0),
  185688. blankPageShown (false),
  185689. unloadPageWhenBrowserIsHidden (unloadPageWhenBrowserIsHidden_)
  185690. {
  185691. setOpaque (true);
  185692. addAndMakeVisible (browser = new WebBrowserComponentInternal());
  185693. }
  185694. WebBrowserComponent::~WebBrowserComponent()
  185695. {
  185696. delete browser;
  185697. }
  185698. void WebBrowserComponent::goToURL (const String& url,
  185699. const StringArray* headers,
  185700. const MemoryBlock* postData)
  185701. {
  185702. lastURL = url;
  185703. lastHeaders.clear();
  185704. if (headers != 0)
  185705. lastHeaders = *headers;
  185706. lastPostData.setSize (0);
  185707. if (postData != 0)
  185708. lastPostData = *postData;
  185709. blankPageShown = false;
  185710. browser->goToURL (url, headers, postData);
  185711. }
  185712. void WebBrowserComponent::stop()
  185713. {
  185714. if (browser->browser != 0)
  185715. browser->browser->Stop();
  185716. }
  185717. void WebBrowserComponent::goBack()
  185718. {
  185719. lastURL = String::empty;
  185720. blankPageShown = false;
  185721. if (browser->browser != 0)
  185722. browser->browser->GoBack();
  185723. }
  185724. void WebBrowserComponent::goForward()
  185725. {
  185726. lastURL = String::empty;
  185727. if (browser->browser != 0)
  185728. browser->browser->GoForward();
  185729. }
  185730. void WebBrowserComponent::refresh()
  185731. {
  185732. if (browser->browser != 0)
  185733. browser->browser->Refresh();
  185734. }
  185735. void WebBrowserComponent::paint (Graphics& g)
  185736. {
  185737. if (browser->browser == 0)
  185738. g.fillAll (Colours::white);
  185739. }
  185740. void WebBrowserComponent::checkWindowAssociation()
  185741. {
  185742. if (isShowing())
  185743. {
  185744. if (browser->browser == 0 && getPeer() != 0)
  185745. {
  185746. browser->createBrowser();
  185747. reloadLastURL();
  185748. }
  185749. else
  185750. {
  185751. if (blankPageShown)
  185752. goBack();
  185753. }
  185754. }
  185755. else
  185756. {
  185757. if (browser != 0 && unloadPageWhenBrowserIsHidden && ! blankPageShown)
  185758. {
  185759. // when the component becomes invisible, some stuff like flash
  185760. // carries on playing audio, so we need to force it onto a blank
  185761. // page to avoid this..
  185762. blankPageShown = true;
  185763. browser->goToURL ("about:blank", 0, 0);
  185764. }
  185765. }
  185766. }
  185767. void WebBrowserComponent::reloadLastURL()
  185768. {
  185769. if (lastURL.isNotEmpty())
  185770. {
  185771. goToURL (lastURL, &lastHeaders, &lastPostData);
  185772. lastURL = String::empty;
  185773. }
  185774. }
  185775. void WebBrowserComponent::parentHierarchyChanged()
  185776. {
  185777. checkWindowAssociation();
  185778. }
  185779. void WebBrowserComponent::resized()
  185780. {
  185781. browser->setSize (getWidth(), getHeight());
  185782. }
  185783. void WebBrowserComponent::visibilityChanged()
  185784. {
  185785. checkWindowAssociation();
  185786. }
  185787. bool WebBrowserComponent::pageAboutToLoad (const String&)
  185788. {
  185789. return true;
  185790. }
  185791. #endif
  185792. /*** End of inlined file: juce_win32_WebBrowserComponent.cpp ***/
  185793. /*** Start of inlined file: juce_win32_OpenGLComponent.cpp ***/
  185794. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  185795. // compiled on its own).
  185796. #if JUCE_INCLUDED_FILE && JUCE_OPENGL
  185797. #define WGL_EXT_FUNCTION_INIT(extType, extFunc) \
  185798. ((extFunc = (extType) wglGetProcAddress (#extFunc)) != 0)
  185799. typedef const char* (WINAPI* PFNWGLGETEXTENSIONSSTRINGARBPROC) (HDC hdc);
  185800. typedef BOOL (WINAPI * PFNWGLGETPIXELFORMATATTRIBIVARBPROC) (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, int *piValues);
  185801. typedef BOOL (WINAPI * PFNWGLCHOOSEPIXELFORMATARBPROC) (HDC hdc, const int* piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats);
  185802. typedef BOOL (WINAPI * PFNWGLSWAPINTERVALEXTPROC) (int interval);
  185803. typedef int (WINAPI * PFNWGLGETSWAPINTERVALEXTPROC) (void);
  185804. #define WGL_NUMBER_PIXEL_FORMATS_ARB 0x2000
  185805. #define WGL_DRAW_TO_WINDOW_ARB 0x2001
  185806. #define WGL_ACCELERATION_ARB 0x2003
  185807. #define WGL_SWAP_METHOD_ARB 0x2007
  185808. #define WGL_SUPPORT_OPENGL_ARB 0x2010
  185809. #define WGL_PIXEL_TYPE_ARB 0x2013
  185810. #define WGL_DOUBLE_BUFFER_ARB 0x2011
  185811. #define WGL_COLOR_BITS_ARB 0x2014
  185812. #define WGL_RED_BITS_ARB 0x2015
  185813. #define WGL_GREEN_BITS_ARB 0x2017
  185814. #define WGL_BLUE_BITS_ARB 0x2019
  185815. #define WGL_ALPHA_BITS_ARB 0x201B
  185816. #define WGL_DEPTH_BITS_ARB 0x2022
  185817. #define WGL_STENCIL_BITS_ARB 0x2023
  185818. #define WGL_FULL_ACCELERATION_ARB 0x2027
  185819. #define WGL_ACCUM_RED_BITS_ARB 0x201E
  185820. #define WGL_ACCUM_GREEN_BITS_ARB 0x201F
  185821. #define WGL_ACCUM_BLUE_BITS_ARB 0x2020
  185822. #define WGL_ACCUM_ALPHA_BITS_ARB 0x2021
  185823. #define WGL_STEREO_ARB 0x2012
  185824. #define WGL_SAMPLE_BUFFERS_ARB 0x2041
  185825. #define WGL_SAMPLES_ARB 0x2042
  185826. #define WGL_TYPE_RGBA_ARB 0x202B
  185827. static void getWglExtensions (HDC dc, StringArray& result) throw()
  185828. {
  185829. PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB = 0;
  185830. if (WGL_EXT_FUNCTION_INIT (PFNWGLGETEXTENSIONSSTRINGARBPROC, wglGetExtensionsStringARB))
  185831. result.addTokens (String (wglGetExtensionsStringARB (dc)), false);
  185832. else
  185833. jassertfalse // If this fails, it may be because you didn't activate the openGL context
  185834. }
  185835. class WindowedGLContext : public OpenGLContext
  185836. {
  185837. public:
  185838. WindowedGLContext (Component* const component_,
  185839. HGLRC contextToShareWith,
  185840. const OpenGLPixelFormat& pixelFormat)
  185841. : renderContext (0),
  185842. nativeWindow (0),
  185843. dc (0),
  185844. component (component_)
  185845. {
  185846. jassert (component != 0);
  185847. createNativeWindow();
  185848. // Use a default pixel format that should be supported everywhere
  185849. PIXELFORMATDESCRIPTOR pfd;
  185850. zerostruct (pfd);
  185851. pfd.nSize = sizeof (pfd);
  185852. pfd.nVersion = 1;
  185853. pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
  185854. pfd.iPixelType = PFD_TYPE_RGBA;
  185855. pfd.cColorBits = 24;
  185856. pfd.cDepthBits = 16;
  185857. const int format = ChoosePixelFormat (dc, &pfd);
  185858. if (format != 0)
  185859. SetPixelFormat (dc, format, &pfd);
  185860. renderContext = wglCreateContext (dc);
  185861. makeActive();
  185862. setPixelFormat (pixelFormat);
  185863. if (contextToShareWith != 0 && renderContext != 0)
  185864. wglShareLists (contextToShareWith, renderContext);
  185865. }
  185866. ~WindowedGLContext()
  185867. {
  185868. makeInactive();
  185869. wglDeleteContext (renderContext);
  185870. ReleaseDC ((HWND) nativeWindow->getNativeHandle(), dc);
  185871. delete nativeWindow;
  185872. }
  185873. bool makeActive() const throw()
  185874. {
  185875. jassert (renderContext != 0);
  185876. return wglMakeCurrent (dc, renderContext) != 0;
  185877. }
  185878. bool makeInactive() const throw()
  185879. {
  185880. return (! isActive()) || (wglMakeCurrent (0, 0) != 0);
  185881. }
  185882. bool isActive() const throw()
  185883. {
  185884. return wglGetCurrentContext() == renderContext;
  185885. }
  185886. const OpenGLPixelFormat getPixelFormat() const
  185887. {
  185888. OpenGLPixelFormat pf;
  185889. makeActive();
  185890. StringArray availableExtensions;
  185891. getWglExtensions (dc, availableExtensions);
  185892. fillInPixelFormatDetails (GetPixelFormat (dc), pf, availableExtensions);
  185893. return pf;
  185894. }
  185895. void* getRawContext() const throw()
  185896. {
  185897. return renderContext;
  185898. }
  185899. bool setPixelFormat (const OpenGLPixelFormat& pixelFormat)
  185900. {
  185901. makeActive();
  185902. PIXELFORMATDESCRIPTOR pfd;
  185903. zerostruct (pfd);
  185904. pfd.nSize = sizeof (pfd);
  185905. pfd.nVersion = 1;
  185906. pfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW | PFD_DOUBLEBUFFER;
  185907. pfd.iPixelType = PFD_TYPE_RGBA;
  185908. pfd.iLayerType = PFD_MAIN_PLANE;
  185909. pfd.cColorBits = (BYTE) (pixelFormat.redBits + pixelFormat.greenBits + pixelFormat.blueBits);
  185910. pfd.cRedBits = (BYTE) pixelFormat.redBits;
  185911. pfd.cGreenBits = (BYTE) pixelFormat.greenBits;
  185912. pfd.cBlueBits = (BYTE) pixelFormat.blueBits;
  185913. pfd.cAlphaBits = (BYTE) pixelFormat.alphaBits;
  185914. pfd.cDepthBits = (BYTE) pixelFormat.depthBufferBits;
  185915. pfd.cStencilBits = (BYTE) pixelFormat.stencilBufferBits;
  185916. pfd.cAccumBits = (BYTE) (pixelFormat.accumulationBufferRedBits + pixelFormat.accumulationBufferGreenBits
  185917. + pixelFormat.accumulationBufferBlueBits + pixelFormat.accumulationBufferAlphaBits);
  185918. pfd.cAccumRedBits = (BYTE) pixelFormat.accumulationBufferRedBits;
  185919. pfd.cAccumGreenBits = (BYTE) pixelFormat.accumulationBufferGreenBits;
  185920. pfd.cAccumBlueBits = (BYTE) pixelFormat.accumulationBufferBlueBits;
  185921. pfd.cAccumAlphaBits = (BYTE) pixelFormat.accumulationBufferAlphaBits;
  185922. int format = 0;
  185923. PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB = 0;
  185924. StringArray availableExtensions;
  185925. getWglExtensions (dc, availableExtensions);
  185926. if (availableExtensions.contains ("WGL_ARB_pixel_format")
  185927. && WGL_EXT_FUNCTION_INIT (PFNWGLCHOOSEPIXELFORMATARBPROC, wglChoosePixelFormatARB))
  185928. {
  185929. int attributes[64];
  185930. int n = 0;
  185931. attributes[n++] = WGL_DRAW_TO_WINDOW_ARB;
  185932. attributes[n++] = GL_TRUE;
  185933. attributes[n++] = WGL_SUPPORT_OPENGL_ARB;
  185934. attributes[n++] = GL_TRUE;
  185935. attributes[n++] = WGL_ACCELERATION_ARB;
  185936. attributes[n++] = WGL_FULL_ACCELERATION_ARB;
  185937. attributes[n++] = WGL_DOUBLE_BUFFER_ARB;
  185938. attributes[n++] = GL_TRUE;
  185939. attributes[n++] = WGL_PIXEL_TYPE_ARB;
  185940. attributes[n++] = WGL_TYPE_RGBA_ARB;
  185941. attributes[n++] = WGL_COLOR_BITS_ARB;
  185942. attributes[n++] = pfd.cColorBits;
  185943. attributes[n++] = WGL_RED_BITS_ARB;
  185944. attributes[n++] = pixelFormat.redBits;
  185945. attributes[n++] = WGL_GREEN_BITS_ARB;
  185946. attributes[n++] = pixelFormat.greenBits;
  185947. attributes[n++] = WGL_BLUE_BITS_ARB;
  185948. attributes[n++] = pixelFormat.blueBits;
  185949. attributes[n++] = WGL_ALPHA_BITS_ARB;
  185950. attributes[n++] = pixelFormat.alphaBits;
  185951. attributes[n++] = WGL_DEPTH_BITS_ARB;
  185952. attributes[n++] = pixelFormat.depthBufferBits;
  185953. if (pixelFormat.stencilBufferBits > 0)
  185954. {
  185955. attributes[n++] = WGL_STENCIL_BITS_ARB;
  185956. attributes[n++] = pixelFormat.stencilBufferBits;
  185957. }
  185958. attributes[n++] = WGL_ACCUM_RED_BITS_ARB;
  185959. attributes[n++] = pixelFormat.accumulationBufferRedBits;
  185960. attributes[n++] = WGL_ACCUM_GREEN_BITS_ARB;
  185961. attributes[n++] = pixelFormat.accumulationBufferGreenBits;
  185962. attributes[n++] = WGL_ACCUM_BLUE_BITS_ARB;
  185963. attributes[n++] = pixelFormat.accumulationBufferBlueBits;
  185964. attributes[n++] = WGL_ACCUM_ALPHA_BITS_ARB;
  185965. attributes[n++] = pixelFormat.accumulationBufferAlphaBits;
  185966. if (availableExtensions.contains ("WGL_ARB_multisample")
  185967. && pixelFormat.fullSceneAntiAliasingNumSamples > 0)
  185968. {
  185969. attributes[n++] = WGL_SAMPLE_BUFFERS_ARB;
  185970. attributes[n++] = 1;
  185971. attributes[n++] = WGL_SAMPLES_ARB;
  185972. attributes[n++] = pixelFormat.fullSceneAntiAliasingNumSamples;
  185973. }
  185974. attributes[n++] = 0;
  185975. UINT formatsCount;
  185976. const BOOL ok = wglChoosePixelFormatARB (dc, attributes, 0, 1, &format, &formatsCount);
  185977. (void) ok;
  185978. jassert (ok);
  185979. }
  185980. else
  185981. {
  185982. format = ChoosePixelFormat (dc, &pfd);
  185983. }
  185984. if (format != 0)
  185985. {
  185986. makeInactive();
  185987. // win32 can't change the pixel format of a window, so need to delete the
  185988. // old one and create a new one..
  185989. jassert (nativeWindow != 0);
  185990. ReleaseDC ((HWND) nativeWindow->getNativeHandle(), dc);
  185991. delete nativeWindow;
  185992. createNativeWindow();
  185993. if (SetPixelFormat (dc, format, &pfd))
  185994. {
  185995. wglDeleteContext (renderContext);
  185996. renderContext = wglCreateContext (dc);
  185997. jassert (renderContext != 0);
  185998. return renderContext != 0;
  185999. }
  186000. }
  186001. return false;
  186002. }
  186003. void updateWindowPosition (int x, int y, int w, int h, int)
  186004. {
  186005. SetWindowPos ((HWND) nativeWindow->getNativeHandle(), 0,
  186006. x, y, w, h,
  186007. SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  186008. }
  186009. void repaint()
  186010. {
  186011. int x, y, w, h;
  186012. nativeWindow->getBounds (x, y, w, h);
  186013. nativeWindow->repaint (0, 0, w, h);
  186014. }
  186015. void swapBuffers()
  186016. {
  186017. SwapBuffers (dc);
  186018. }
  186019. bool setSwapInterval (const int numFramesPerSwap)
  186020. {
  186021. makeActive();
  186022. StringArray availableExtensions;
  186023. getWglExtensions (dc, availableExtensions);
  186024. PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT = 0;
  186025. return availableExtensions.contains ("WGL_EXT_swap_control")
  186026. && WGL_EXT_FUNCTION_INIT (PFNWGLSWAPINTERVALEXTPROC, wglSwapIntervalEXT)
  186027. && wglSwapIntervalEXT (numFramesPerSwap) != FALSE;
  186028. }
  186029. int getSwapInterval() const
  186030. {
  186031. makeActive();
  186032. StringArray availableExtensions;
  186033. getWglExtensions (dc, availableExtensions);
  186034. PFNWGLGETSWAPINTERVALEXTPROC wglGetSwapIntervalEXT = 0;
  186035. if (availableExtensions.contains ("WGL_EXT_swap_control")
  186036. && WGL_EXT_FUNCTION_INIT (PFNWGLGETSWAPINTERVALEXTPROC, wglGetSwapIntervalEXT))
  186037. return wglGetSwapIntervalEXT();
  186038. return 0;
  186039. }
  186040. void findAlternativeOpenGLPixelFormats (OwnedArray <OpenGLPixelFormat>& results)
  186041. {
  186042. jassert (isActive());
  186043. StringArray availableExtensions;
  186044. getWglExtensions (dc, availableExtensions);
  186045. PFNWGLGETPIXELFORMATATTRIBIVARBPROC wglGetPixelFormatAttribivARB = 0;
  186046. int numTypes = 0;
  186047. if (availableExtensions.contains("WGL_ARB_pixel_format")
  186048. && WGL_EXT_FUNCTION_INIT (PFNWGLGETPIXELFORMATATTRIBIVARBPROC, wglGetPixelFormatAttribivARB))
  186049. {
  186050. int attributes = WGL_NUMBER_PIXEL_FORMATS_ARB;
  186051. if (! wglGetPixelFormatAttribivARB (dc, 1, 0, 1, &attributes, &numTypes))
  186052. jassertfalse
  186053. }
  186054. else
  186055. {
  186056. numTypes = DescribePixelFormat (dc, 0, 0, 0);
  186057. }
  186058. OpenGLPixelFormat pf;
  186059. for (int i = 0; i < numTypes; ++i)
  186060. {
  186061. if (fillInPixelFormatDetails (i + 1, pf, availableExtensions))
  186062. {
  186063. bool alreadyListed = false;
  186064. for (int j = results.size(); --j >= 0;)
  186065. if (pf == *results.getUnchecked(j))
  186066. alreadyListed = true;
  186067. if (! alreadyListed)
  186068. results.add (new OpenGLPixelFormat (pf));
  186069. }
  186070. }
  186071. }
  186072. void* getNativeWindowHandle() const
  186073. {
  186074. return nativeWindow != 0 ? nativeWindow->getNativeHandle() : 0;
  186075. }
  186076. juce_UseDebuggingNewOperator
  186077. HGLRC renderContext;
  186078. private:
  186079. Win32ComponentPeer* nativeWindow;
  186080. Component* const component;
  186081. HDC dc;
  186082. void createNativeWindow()
  186083. {
  186084. nativeWindow = new Win32ComponentPeer (component, 0);
  186085. nativeWindow->dontRepaint = true;
  186086. nativeWindow->setVisible (true);
  186087. HWND hwnd = (HWND) nativeWindow->getNativeHandle();
  186088. Win32ComponentPeer* const peer = dynamic_cast <Win32ComponentPeer*> (component->getTopLevelComponent()->getPeer());
  186089. if (peer != 0)
  186090. {
  186091. SetParent (hwnd, (HWND) peer->getNativeHandle());
  186092. juce_setWindowStyleBit (hwnd, GWL_STYLE, WS_CHILD, true);
  186093. juce_setWindowStyleBit (hwnd, GWL_STYLE, WS_POPUP, false);
  186094. }
  186095. dc = GetDC (hwnd);
  186096. }
  186097. bool fillInPixelFormatDetails (const int pixelFormatIndex,
  186098. OpenGLPixelFormat& result,
  186099. const StringArray& availableExtensions) const throw()
  186100. {
  186101. PFNWGLGETPIXELFORMATATTRIBIVARBPROC wglGetPixelFormatAttribivARB = 0;
  186102. if (availableExtensions.contains ("WGL_ARB_pixel_format")
  186103. && WGL_EXT_FUNCTION_INIT (PFNWGLGETPIXELFORMATATTRIBIVARBPROC, wglGetPixelFormatAttribivARB))
  186104. {
  186105. int attributes[32];
  186106. int numAttributes = 0;
  186107. attributes[numAttributes++] = WGL_DRAW_TO_WINDOW_ARB;
  186108. attributes[numAttributes++] = WGL_SUPPORT_OPENGL_ARB;
  186109. attributes[numAttributes++] = WGL_ACCELERATION_ARB;
  186110. attributes[numAttributes++] = WGL_DOUBLE_BUFFER_ARB;
  186111. attributes[numAttributes++] = WGL_PIXEL_TYPE_ARB;
  186112. attributes[numAttributes++] = WGL_RED_BITS_ARB;
  186113. attributes[numAttributes++] = WGL_GREEN_BITS_ARB;
  186114. attributes[numAttributes++] = WGL_BLUE_BITS_ARB;
  186115. attributes[numAttributes++] = WGL_ALPHA_BITS_ARB;
  186116. attributes[numAttributes++] = WGL_DEPTH_BITS_ARB;
  186117. attributes[numAttributes++] = WGL_STENCIL_BITS_ARB;
  186118. attributes[numAttributes++] = WGL_ACCUM_RED_BITS_ARB;
  186119. attributes[numAttributes++] = WGL_ACCUM_GREEN_BITS_ARB;
  186120. attributes[numAttributes++] = WGL_ACCUM_BLUE_BITS_ARB;
  186121. attributes[numAttributes++] = WGL_ACCUM_ALPHA_BITS_ARB;
  186122. if (availableExtensions.contains ("WGL_ARB_multisample"))
  186123. attributes[numAttributes++] = WGL_SAMPLES_ARB;
  186124. int values[32];
  186125. zeromem (values, sizeof (values));
  186126. if (wglGetPixelFormatAttribivARB (dc, pixelFormatIndex, 0, numAttributes, attributes, values))
  186127. {
  186128. int n = 0;
  186129. bool isValidFormat = (values[n++] == GL_TRUE); // WGL_DRAW_TO_WINDOW_ARB
  186130. isValidFormat = (values[n++] == GL_TRUE) && isValidFormat; // WGL_SUPPORT_OPENGL_ARB
  186131. isValidFormat = (values[n++] == WGL_FULL_ACCELERATION_ARB) && isValidFormat; // WGL_ACCELERATION_ARB
  186132. isValidFormat = (values[n++] == GL_TRUE) && isValidFormat; // WGL_DOUBLE_BUFFER_ARB:
  186133. isValidFormat = (values[n++] == WGL_TYPE_RGBA_ARB) && isValidFormat; // WGL_PIXEL_TYPE_ARB
  186134. result.redBits = values[n++]; // WGL_RED_BITS_ARB
  186135. result.greenBits = values[n++]; // WGL_GREEN_BITS_ARB
  186136. result.blueBits = values[n++]; // WGL_BLUE_BITS_ARB
  186137. result.alphaBits = values[n++]; // WGL_ALPHA_BITS_ARB
  186138. result.depthBufferBits = values[n++]; // WGL_DEPTH_BITS_ARB
  186139. result.stencilBufferBits = values[n++]; // WGL_STENCIL_BITS_ARB
  186140. result.accumulationBufferRedBits = values[n++]; // WGL_ACCUM_RED_BITS_ARB
  186141. result.accumulationBufferGreenBits = values[n++]; // WGL_ACCUM_GREEN_BITS_ARB
  186142. result.accumulationBufferBlueBits = values[n++]; // WGL_ACCUM_BLUE_BITS_ARB
  186143. result.accumulationBufferAlphaBits = values[n++]; // WGL_ACCUM_ALPHA_BITS_ARB
  186144. result.fullSceneAntiAliasingNumSamples = (uint8) values[n++]; // WGL_SAMPLES_ARB
  186145. return isValidFormat;
  186146. }
  186147. else
  186148. {
  186149. jassertfalse
  186150. }
  186151. }
  186152. else
  186153. {
  186154. PIXELFORMATDESCRIPTOR pfd;
  186155. if (DescribePixelFormat (dc, pixelFormatIndex, sizeof (pfd), &pfd))
  186156. {
  186157. result.redBits = pfd.cRedBits;
  186158. result.greenBits = pfd.cGreenBits;
  186159. result.blueBits = pfd.cBlueBits;
  186160. result.alphaBits = pfd.cAlphaBits;
  186161. result.depthBufferBits = pfd.cDepthBits;
  186162. result.stencilBufferBits = pfd.cStencilBits;
  186163. result.accumulationBufferRedBits = pfd.cAccumRedBits;
  186164. result.accumulationBufferGreenBits = pfd.cAccumGreenBits;
  186165. result.accumulationBufferBlueBits = pfd.cAccumBlueBits;
  186166. result.accumulationBufferAlphaBits = pfd.cAccumAlphaBits;
  186167. result.fullSceneAntiAliasingNumSamples = 0;
  186168. return true;
  186169. }
  186170. else
  186171. {
  186172. jassertfalse
  186173. }
  186174. }
  186175. return false;
  186176. }
  186177. WindowedGLContext (const WindowedGLContext&);
  186178. const WindowedGLContext& operator= (const WindowedGLContext&);
  186179. };
  186180. OpenGLContext* OpenGLContext::createContextForWindow (Component* const component,
  186181. const OpenGLPixelFormat& pixelFormat,
  186182. const OpenGLContext* const contextToShareWith)
  186183. {
  186184. WindowedGLContext* c = new WindowedGLContext (component,
  186185. contextToShareWith != 0 ? (HGLRC) contextToShareWith->getRawContext() : 0,
  186186. pixelFormat);
  186187. if (c->renderContext == 0)
  186188. deleteAndZero (c);
  186189. return c;
  186190. }
  186191. void* OpenGLComponent::getNativeWindowHandle() const
  186192. {
  186193. return context != 0 ? ((WindowedGLContext*) context)->getNativeWindowHandle() : 0;
  186194. }
  186195. void juce_glViewport (const int w, const int h)
  186196. {
  186197. glViewport (0, 0, w, h);
  186198. }
  186199. void OpenGLPixelFormat::getAvailablePixelFormats (Component* component,
  186200. OwnedArray <OpenGLPixelFormat>& results)
  186201. {
  186202. Component tempComp;
  186203. {
  186204. WindowedGLContext wc (component, 0, OpenGLPixelFormat (8, 8, 16, 0));
  186205. wc.makeActive();
  186206. wc.findAlternativeOpenGLPixelFormats (results);
  186207. }
  186208. }
  186209. #endif
  186210. /*** End of inlined file: juce_win32_OpenGLComponent.cpp ***/
  186211. /*** Start of inlined file: juce_win32_AudioCDReader.cpp ***/
  186212. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  186213. // compiled on its own).
  186214. #if JUCE_INCLUDED_FILE
  186215. #if JUCE_USE_CDREADER
  186216. //***************************************************************************
  186217. // %%% TARGET STATUS VALUES %%%
  186218. //***************************************************************************
  186219. #define STATUS_GOOD 0x00 // Status Good
  186220. #define STATUS_CHKCOND 0x02 // Check Condition
  186221. #define STATUS_CONDMET 0x04 // Condition Met
  186222. #define STATUS_BUSY 0x08 // Busy
  186223. #define STATUS_INTERM 0x10 // Intermediate
  186224. #define STATUS_INTCDMET 0x14 // Intermediate-condition met
  186225. #define STATUS_RESCONF 0x18 // Reservation conflict
  186226. #define STATUS_COMTERM 0x22 // Command Terminated
  186227. #define STATUS_QFULL 0x28 // Queue full
  186228. //***************************************************************************
  186229. // %%% SCSI MISCELLANEOUS EQUATES %%%
  186230. //***************************************************************************
  186231. #define MAXLUN 7 // Maximum Logical Unit Id
  186232. #define MAXTARG 7 // Maximum Target Id
  186233. #define MAX_SCSI_LUNS 64 // Maximum Number of SCSI LUNs
  186234. #define MAX_NUM_HA 8 // Maximum Number of SCSI HA's
  186235. //***************************************************************************
  186236. // %%% Commands for all Device Types %%%
  186237. //***************************************************************************
  186238. #define SCSI_CHANGE_DEF 0x40 // Change Definition (Optional)
  186239. #define SCSI_COMPARE 0x39 // Compare (O)
  186240. #define SCSI_COPY 0x18 // Copy (O)
  186241. #define SCSI_COP_VERIFY 0x3A // Copy and Verify (O)
  186242. #define SCSI_INQUIRY 0x12 // Inquiry (MANDATORY)
  186243. #define SCSI_LOG_SELECT 0x4C // Log Select (O)
  186244. #define SCSI_LOG_SENSE 0x4D // Log Sense (O)
  186245. #define SCSI_MODE_SEL6 0x15 // Mode Select 6-byte (Device Specific)
  186246. #define SCSI_MODE_SEL10 0x55 // Mode Select 10-byte (Device Specific)
  186247. #define SCSI_MODE_SEN6 0x1A // Mode Sense 6-byte (Device Specific)
  186248. #define SCSI_MODE_SEN10 0x5A // Mode Sense 10-byte (Device Specific)
  186249. #define SCSI_READ_BUFF 0x3C // Read Buffer (O)
  186250. #define SCSI_REQ_SENSE 0x03 // Request Sense (MANDATORY)
  186251. #define SCSI_SEND_DIAG 0x1D // Send Diagnostic (O)
  186252. #define SCSI_TST_U_RDY 0x00 // Test Unit Ready (MANDATORY)
  186253. #define SCSI_WRITE_BUFF 0x3B // Write Buffer (O)
  186254. //***************************************************************************
  186255. // %%% Commands Unique to Direct Access Devices %%%
  186256. //***************************************************************************
  186257. #define SCSI_COMPARE 0x39 // Compare (O)
  186258. #define SCSI_FORMAT 0x04 // Format Unit (MANDATORY)
  186259. #define SCSI_LCK_UN_CAC 0x36 // Lock Unlock Cache (O)
  186260. #define SCSI_PREFETCH 0x34 // Prefetch (O)
  186261. #define SCSI_MED_REMOVL 0x1E // Prevent/Allow medium Removal (O)
  186262. #define SCSI_READ6 0x08 // Read 6-byte (MANDATORY)
  186263. #define SCSI_READ10 0x28 // Read 10-byte (MANDATORY)
  186264. #define SCSI_RD_CAPAC 0x25 // Read Capacity (MANDATORY)
  186265. #define SCSI_RD_DEFECT 0x37 // Read Defect Data (O)
  186266. #define SCSI_READ_LONG 0x3E // Read Long (O)
  186267. #define SCSI_REASS_BLK 0x07 // Reassign Blocks (O)
  186268. #define SCSI_RCV_DIAG 0x1C // Receive Diagnostic Results (O)
  186269. #define SCSI_RELEASE 0x17 // Release Unit (MANDATORY)
  186270. #define SCSI_REZERO 0x01 // Rezero Unit (O)
  186271. #define SCSI_SRCH_DAT_E 0x31 // Search Data Equal (O)
  186272. #define SCSI_SRCH_DAT_H 0x30 // Search Data High (O)
  186273. #define SCSI_SRCH_DAT_L 0x32 // Search Data Low (O)
  186274. #define SCSI_SEEK6 0x0B // Seek 6-Byte (O)
  186275. #define SCSI_SEEK10 0x2B // Seek 10-Byte (O)
  186276. #define SCSI_SEND_DIAG 0x1D // Send Diagnostics (MANDATORY)
  186277. #define SCSI_SET_LIMIT 0x33 // Set Limits (O)
  186278. #define SCSI_START_STP 0x1B // Start/Stop Unit (O)
  186279. #define SCSI_SYNC_CACHE 0x35 // Synchronize Cache (O)
  186280. #define SCSI_VERIFY 0x2F // Verify (O)
  186281. #define SCSI_WRITE6 0x0A // Write 6-Byte (MANDATORY)
  186282. #define SCSI_WRITE10 0x2A // Write 10-Byte (MANDATORY)
  186283. #define SCSI_WRT_VERIFY 0x2E // Write and Verify (O)
  186284. #define SCSI_WRITE_LONG 0x3F // Write Long (O)
  186285. #define SCSI_WRITE_SAME 0x41 // Write Same (O)
  186286. //***************************************************************************
  186287. // %%% Commands Unique to Sequential Access Devices %%%
  186288. //***************************************************************************
  186289. #define SCSI_ERASE 0x19 // Erase (MANDATORY)
  186290. #define SCSI_LOAD_UN 0x1b // Load/Unload (O)
  186291. #define SCSI_LOCATE 0x2B // Locate (O)
  186292. #define SCSI_RD_BLK_LIM 0x05 // Read Block Limits (MANDATORY)
  186293. #define SCSI_READ_POS 0x34 // Read Position (O)
  186294. #define SCSI_READ_REV 0x0F // Read Reverse (O)
  186295. #define SCSI_REC_BF_DAT 0x14 // Recover Buffer Data (O)
  186296. #define SCSI_RESERVE 0x16 // Reserve Unit (MANDATORY)
  186297. #define SCSI_REWIND 0x01 // Rewind (MANDATORY)
  186298. #define SCSI_SPACE 0x11 // Space (MANDATORY)
  186299. #define SCSI_VERIFY_T 0x13 // Verify (Tape) (O)
  186300. #define SCSI_WRT_FILE 0x10 // Write Filemarks (MANDATORY)
  186301. //***************************************************************************
  186302. // %%% Commands Unique to Printer Devices %%%
  186303. //***************************************************************************
  186304. #define SCSI_PRINT 0x0A // Print (MANDATORY)
  186305. #define SCSI_SLEW_PNT 0x0B // Slew and Print (O)
  186306. #define SCSI_STOP_PNT 0x1B // Stop Print (O)
  186307. #define SCSI_SYNC_BUFF 0x10 // Synchronize Buffer (O)
  186308. //***************************************************************************
  186309. // %%% Commands Unique to Processor Devices %%%
  186310. //***************************************************************************
  186311. #define SCSI_RECEIVE 0x08 // Receive (O)
  186312. #define SCSI_SEND 0x0A // Send (O)
  186313. //***************************************************************************
  186314. // %%% Commands Unique to Write-Once Devices %%%
  186315. //***************************************************************************
  186316. #define SCSI_MEDIUM_SCN 0x38 // Medium Scan (O)
  186317. #define SCSI_SRCHDATE10 0x31 // Search Data Equal 10-Byte (O)
  186318. #define SCSI_SRCHDATE12 0xB1 // Search Data Equal 12-Byte (O)
  186319. #define SCSI_SRCHDATH10 0x30 // Search Data High 10-Byte (O)
  186320. #define SCSI_SRCHDATH12 0xB0 // Search Data High 12-Byte (O)
  186321. #define SCSI_SRCHDATL10 0x32 // Search Data Low 10-Byte (O)
  186322. #define SCSI_SRCHDATL12 0xB2 // Search Data Low 12-Byte (O)
  186323. #define SCSI_SET_LIM_10 0x33 // Set Limits 10-Byte (O)
  186324. #define SCSI_SET_LIM_12 0xB3 // Set Limits 10-Byte (O)
  186325. #define SCSI_VERIFY10 0x2F // Verify 10-Byte (O)
  186326. #define SCSI_VERIFY12 0xAF // Verify 12-Byte (O)
  186327. #define SCSI_WRITE12 0xAA // Write 12-Byte (O)
  186328. #define SCSI_WRT_VER10 0x2E // Write and Verify 10-Byte (O)
  186329. #define SCSI_WRT_VER12 0xAE // Write and Verify 12-Byte (O)
  186330. //***************************************************************************
  186331. // %%% Commands Unique to CD-ROM Devices %%%
  186332. //***************************************************************************
  186333. #define SCSI_PLAYAUD_10 0x45 // Play Audio 10-Byte (O)
  186334. #define SCSI_PLAYAUD_12 0xA5 // Play Audio 12-Byte 12-Byte (O)
  186335. #define SCSI_PLAYAUDMSF 0x47 // Play Audio MSF (O)
  186336. #define SCSI_PLAYA_TKIN 0x48 // Play Audio Track/Index (O)
  186337. #define SCSI_PLYTKREL10 0x49 // Play Track Relative 10-Byte (O)
  186338. #define SCSI_PLYTKREL12 0xA9 // Play Track Relative 12-Byte (O)
  186339. #define SCSI_READCDCAP 0x25 // Read CD-ROM Capacity (MANDATORY)
  186340. #define SCSI_READHEADER 0x44 // Read Header (O)
  186341. #define SCSI_SUBCHANNEL 0x42 // Read Subchannel (O)
  186342. #define SCSI_READ_TOC 0x43 // Read TOC (O)
  186343. //***************************************************************************
  186344. // %%% Commands Unique to Scanner Devices %%%
  186345. //***************************************************************************
  186346. #define SCSI_GETDBSTAT 0x34 // Get Data Buffer Status (O)
  186347. #define SCSI_GETWINDOW 0x25 // Get Window (O)
  186348. #define SCSI_OBJECTPOS 0x31 // Object Postion (O)
  186349. #define SCSI_SCAN 0x1B // Scan (O)
  186350. #define SCSI_SETWINDOW 0x24 // Set Window (MANDATORY)
  186351. //***************************************************************************
  186352. // %%% Commands Unique to Optical Memory Devices %%%
  186353. //***************************************************************************
  186354. #define SCSI_UpdateBlk 0x3D // Update Block (O)
  186355. //***************************************************************************
  186356. // %%% Commands Unique to Medium Changer Devices %%%
  186357. //***************************************************************************
  186358. #define SCSI_EXCHMEDIUM 0xA6 // Exchange Medium (O)
  186359. #define SCSI_INITELSTAT 0x07 // Initialize Element Status (O)
  186360. #define SCSI_POSTOELEM 0x2B // Position to Element (O)
  186361. #define SCSI_REQ_VE_ADD 0xB5 // Request Volume Element Address (O)
  186362. #define SCSI_SENDVOLTAG 0xB6 // Send Volume Tag (O)
  186363. //***************************************************************************
  186364. // %%% Commands Unique to Communication Devices %%%
  186365. //***************************************************************************
  186366. #define SCSI_GET_MSG_6 0x08 // Get Message 6-Byte (MANDATORY)
  186367. #define SCSI_GET_MSG_10 0x28 // Get Message 10-Byte (O)
  186368. #define SCSI_GET_MSG_12 0xA8 // Get Message 12-Byte (O)
  186369. #define SCSI_SND_MSG_6 0x0A // Send Message 6-Byte (MANDATORY)
  186370. #define SCSI_SND_MSG_10 0x2A // Send Message 10-Byte (O)
  186371. #define SCSI_SND_MSG_12 0xAA // Send Message 12-Byte (O)
  186372. //***************************************************************************
  186373. // %%% Request Sense Data Format %%%
  186374. //***************************************************************************
  186375. typedef struct {
  186376. BYTE ErrorCode; // Error Code (70H or 71H)
  186377. BYTE SegmentNum; // Number of current segment descriptor
  186378. BYTE SenseKey; // Sense Key(See bit definitions too)
  186379. BYTE InfoByte0; // Information MSB
  186380. BYTE InfoByte1; // Information MID
  186381. BYTE InfoByte2; // Information MID
  186382. BYTE InfoByte3; // Information LSB
  186383. BYTE AddSenLen; // Additional Sense Length
  186384. BYTE ComSpecInf0; // Command Specific Information MSB
  186385. BYTE ComSpecInf1; // Command Specific Information MID
  186386. BYTE ComSpecInf2; // Command Specific Information MID
  186387. BYTE ComSpecInf3; // Command Specific Information LSB
  186388. BYTE AddSenseCode; // Additional Sense Code
  186389. BYTE AddSenQual; // Additional Sense Code Qualifier
  186390. BYTE FieldRepUCode; // Field Replaceable Unit Code
  186391. BYTE SenKeySpec15; // Sense Key Specific 15th byte
  186392. BYTE SenKeySpec16; // Sense Key Specific 16th byte
  186393. BYTE SenKeySpec17; // Sense Key Specific 17th byte
  186394. BYTE AddSenseBytes; // Additional Sense Bytes
  186395. } SENSE_DATA_FMT;
  186396. //***************************************************************************
  186397. // %%% REQUEST SENSE ERROR CODE %%%
  186398. //***************************************************************************
  186399. #define SERROR_CURRENT 0x70 // Current Errors
  186400. #define SERROR_DEFERED 0x71 // Deferred Errors
  186401. //***************************************************************************
  186402. // %%% REQUEST SENSE BIT DEFINITIONS %%%
  186403. //***************************************************************************
  186404. #define SENSE_VALID 0x80 // Byte 0 Bit 7
  186405. #define SENSE_FILEMRK 0x80 // Byte 2 Bit 7
  186406. #define SENSE_EOM 0x40 // Byte 2 Bit 6
  186407. #define SENSE_ILI 0x20 // Byte 2 Bit 5
  186408. //***************************************************************************
  186409. // %%% REQUEST SENSE SENSE KEY DEFINITIONS %%%
  186410. //***************************************************************************
  186411. #define KEY_NOSENSE 0x00 // No Sense
  186412. #define KEY_RECERROR 0x01 // Recovered Error
  186413. #define KEY_NOTREADY 0x02 // Not Ready
  186414. #define KEY_MEDIUMERR 0x03 // Medium Error
  186415. #define KEY_HARDERROR 0x04 // Hardware Error
  186416. #define KEY_ILLGLREQ 0x05 // Illegal Request
  186417. #define KEY_UNITATT 0x06 // Unit Attention
  186418. #define KEY_DATAPROT 0x07 // Data Protect
  186419. #define KEY_BLANKCHK 0x08 // Blank Check
  186420. #define KEY_VENDSPEC 0x09 // Vendor Specific
  186421. #define KEY_COPYABORT 0x0A // Copy Abort
  186422. #define KEY_EQUAL 0x0C // Equal (Search)
  186423. #define KEY_VOLOVRFLW 0x0D // Volume Overflow
  186424. #define KEY_MISCOMP 0x0E // Miscompare (Search)
  186425. #define KEY_RESERVED 0x0F // Reserved
  186426. //***************************************************************************
  186427. // %%% PERIPHERAL DEVICE TYPE DEFINITIONS %%%
  186428. //***************************************************************************
  186429. #define DTYPE_DASD 0x00 // Disk Device
  186430. #define DTYPE_SEQD 0x01 // Tape Device
  186431. #define DTYPE_PRNT 0x02 // Printer
  186432. #define DTYPE_PROC 0x03 // Processor
  186433. #define DTYPE_WORM 0x04 // Write-once read-multiple
  186434. #define DTYPE_CROM 0x05 // CD-ROM device
  186435. #define DTYPE_SCAN 0x06 // Scanner device
  186436. #define DTYPE_OPTI 0x07 // Optical memory device
  186437. #define DTYPE_JUKE 0x08 // Medium Changer device
  186438. #define DTYPE_COMM 0x09 // Communications device
  186439. #define DTYPE_RESL 0x0A // Reserved (low)
  186440. #define DTYPE_RESH 0x1E // Reserved (high)
  186441. #define DTYPE_UNKNOWN 0x1F // Unknown or no device type
  186442. //***************************************************************************
  186443. // %%% ANSI APPROVED VERSION DEFINITIONS %%%
  186444. //***************************************************************************
  186445. #define ANSI_MAYBE 0x0 // Device may or may not be ANSI approved stand
  186446. #define ANSI_SCSI1 0x1 // Device complies to ANSI X3.131-1986 (SCSI-1)
  186447. #define ANSI_SCSI2 0x2 // Device complies to SCSI-2
  186448. #define ANSI_RESLO 0x3 // Reserved (low)
  186449. #define ANSI_RESHI 0x7 // Reserved (high)
  186450. typedef struct
  186451. {
  186452. USHORT Length;
  186453. UCHAR ScsiStatus;
  186454. UCHAR PathId;
  186455. UCHAR TargetId;
  186456. UCHAR Lun;
  186457. UCHAR CdbLength;
  186458. UCHAR SenseInfoLength;
  186459. UCHAR DataIn;
  186460. ULONG DataTransferLength;
  186461. ULONG TimeOutValue;
  186462. ULONG DataBufferOffset;
  186463. ULONG SenseInfoOffset;
  186464. UCHAR Cdb[16];
  186465. } SCSI_PASS_THROUGH, *PSCSI_PASS_THROUGH;
  186466. typedef struct
  186467. {
  186468. USHORT Length;
  186469. UCHAR ScsiStatus;
  186470. UCHAR PathId;
  186471. UCHAR TargetId;
  186472. UCHAR Lun;
  186473. UCHAR CdbLength;
  186474. UCHAR SenseInfoLength;
  186475. UCHAR DataIn;
  186476. ULONG DataTransferLength;
  186477. ULONG TimeOutValue;
  186478. PVOID DataBuffer;
  186479. ULONG SenseInfoOffset;
  186480. UCHAR Cdb[16];
  186481. } SCSI_PASS_THROUGH_DIRECT, *PSCSI_PASS_THROUGH_DIRECT;
  186482. typedef struct
  186483. {
  186484. SCSI_PASS_THROUGH_DIRECT spt;
  186485. ULONG Filler;
  186486. UCHAR ucSenseBuf[32];
  186487. } SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER, *PSCSI_PASS_THROUGH_DIRECT_WITH_BUFFER;
  186488. typedef struct
  186489. {
  186490. ULONG Length;
  186491. UCHAR PortNumber;
  186492. UCHAR PathId;
  186493. UCHAR TargetId;
  186494. UCHAR Lun;
  186495. } SCSI_ADDRESS, *PSCSI_ADDRESS;
  186496. #define METHOD_BUFFERED 0
  186497. #define METHOD_IN_DIRECT 1
  186498. #define METHOD_OUT_DIRECT 2
  186499. #define METHOD_NEITHER 3
  186500. #define FILE_ANY_ACCESS 0
  186501. #ifndef FILE_READ_ACCESS
  186502. #define FILE_READ_ACCESS (0x0001)
  186503. #endif
  186504. #ifndef FILE_WRITE_ACCESS
  186505. #define FILE_WRITE_ACCESS (0x0002)
  186506. #endif
  186507. #define IOCTL_SCSI_BASE 0x00000004
  186508. #define SCSI_IOCTL_DATA_OUT 0
  186509. #define SCSI_IOCTL_DATA_IN 1
  186510. #define SCSI_IOCTL_DATA_UNSPECIFIED 2
  186511. #define CTL_CODE2( DevType, Function, Method, Access ) ( \
  186512. ((DevType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method) \
  186513. )
  186514. #define IOCTL_SCSI_PASS_THROUGH CTL_CODE2( IOCTL_SCSI_BASE, 0x0401, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS )
  186515. #define IOCTL_SCSI_GET_CAPABILITIES CTL_CODE2( IOCTL_SCSI_BASE, 0x0404, METHOD_BUFFERED, FILE_ANY_ACCESS)
  186516. #define IOCTL_SCSI_PASS_THROUGH_DIRECT CTL_CODE2( IOCTL_SCSI_BASE, 0x0405, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS )
  186517. #define IOCTL_SCSI_GET_ADDRESS CTL_CODE2( IOCTL_SCSI_BASE, 0x0406, METHOD_BUFFERED, FILE_ANY_ACCESS )
  186518. #define SENSE_LEN 14
  186519. #define SRB_DIR_SCSI 0x00
  186520. #define SRB_POSTING 0x01
  186521. #define SRB_ENABLE_RESIDUAL_COUNT 0x04
  186522. #define SRB_DIR_IN 0x08
  186523. #define SRB_DIR_OUT 0x10
  186524. #define SRB_EVENT_NOTIFY 0x40
  186525. #define RESIDUAL_COUNT_SUPPORTED 0x02
  186526. #define MAX_SRB_TIMEOUT 1080001u
  186527. #define DEFAULT_SRB_TIMEOUT 1080001u
  186528. #define SC_HA_INQUIRY 0x00
  186529. #define SC_GET_DEV_TYPE 0x01
  186530. #define SC_EXEC_SCSI_CMD 0x02
  186531. #define SC_ABORT_SRB 0x03
  186532. #define SC_RESET_DEV 0x04
  186533. #define SC_SET_HA_PARMS 0x05
  186534. #define SC_GET_DISK_INFO 0x06
  186535. #define SC_RESCAN_SCSI_BUS 0x07
  186536. #define SC_GETSET_TIMEOUTS 0x08
  186537. #define SS_PENDING 0x00
  186538. #define SS_COMP 0x01
  186539. #define SS_ABORTED 0x02
  186540. #define SS_ABORT_FAIL 0x03
  186541. #define SS_ERR 0x04
  186542. #define SS_INVALID_CMD 0x80
  186543. #define SS_INVALID_HA 0x81
  186544. #define SS_NO_DEVICE 0x82
  186545. #define SS_INVALID_SRB 0xE0
  186546. #define SS_OLD_MANAGER 0xE1
  186547. #define SS_BUFFER_ALIGN 0xE1
  186548. #define SS_ILLEGAL_MODE 0xE2
  186549. #define SS_NO_ASPI 0xE3
  186550. #define SS_FAILED_INIT 0xE4
  186551. #define SS_ASPI_IS_BUSY 0xE5
  186552. #define SS_BUFFER_TO_BIG 0xE6
  186553. #define SS_BUFFER_TOO_BIG 0xE6
  186554. #define SS_MISMATCHED_COMPONENTS 0xE7
  186555. #define SS_NO_ADAPTERS 0xE8
  186556. #define SS_INSUFFICIENT_RESOURCES 0xE9
  186557. #define SS_ASPI_IS_SHUTDOWN 0xEA
  186558. #define SS_BAD_INSTALL 0xEB
  186559. #define HASTAT_OK 0x00
  186560. #define HASTAT_SEL_TO 0x11
  186561. #define HASTAT_DO_DU 0x12
  186562. #define HASTAT_BUS_FREE 0x13
  186563. #define HASTAT_PHASE_ERR 0x14
  186564. #define HASTAT_TIMEOUT 0x09
  186565. #define HASTAT_COMMAND_TIMEOUT 0x0B
  186566. #define HASTAT_MESSAGE_REJECT 0x0D
  186567. #define HASTAT_BUS_RESET 0x0E
  186568. #define HASTAT_PARITY_ERROR 0x0F
  186569. #define HASTAT_REQUEST_SENSE_FAILED 0x10
  186570. #define PACKED
  186571. #pragma pack(1)
  186572. typedef struct
  186573. {
  186574. BYTE SRB_Cmd;
  186575. BYTE SRB_Status;
  186576. BYTE SRB_HaID;
  186577. BYTE SRB_Flags;
  186578. DWORD SRB_Hdr_Rsvd;
  186579. BYTE HA_Count;
  186580. BYTE HA_SCSI_ID;
  186581. BYTE HA_ManagerId[16];
  186582. BYTE HA_Identifier[16];
  186583. BYTE HA_Unique[16];
  186584. WORD HA_Rsvd1;
  186585. BYTE pad[20];
  186586. } PACKED SRB_HAInquiry, *PSRB_HAInquiry, FAR *LPSRB_HAInquiry;
  186587. typedef struct
  186588. {
  186589. BYTE SRB_Cmd;
  186590. BYTE SRB_Status;
  186591. BYTE SRB_HaID;
  186592. BYTE SRB_Flags;
  186593. DWORD SRB_Hdr_Rsvd;
  186594. BYTE SRB_Target;
  186595. BYTE SRB_Lun;
  186596. BYTE SRB_DeviceType;
  186597. BYTE SRB_Rsvd1;
  186598. BYTE pad[68];
  186599. } PACKED SRB_GDEVBlock, *PSRB_GDEVBlock, FAR *LPSRB_GDEVBlock;
  186600. typedef struct
  186601. {
  186602. BYTE SRB_Cmd;
  186603. BYTE SRB_Status;
  186604. BYTE SRB_HaID;
  186605. BYTE SRB_Flags;
  186606. DWORD SRB_Hdr_Rsvd;
  186607. BYTE SRB_Target;
  186608. BYTE SRB_Lun;
  186609. WORD SRB_Rsvd1;
  186610. DWORD SRB_BufLen;
  186611. BYTE FAR *SRB_BufPointer;
  186612. BYTE SRB_SenseLen;
  186613. BYTE SRB_CDBLen;
  186614. BYTE SRB_HaStat;
  186615. BYTE SRB_TargStat;
  186616. VOID FAR *SRB_PostProc;
  186617. BYTE SRB_Rsvd2[20];
  186618. BYTE CDBByte[16];
  186619. BYTE SenseArea[SENSE_LEN+2];
  186620. } PACKED SRB_ExecSCSICmd, *PSRB_ExecSCSICmd, FAR *LPSRB_ExecSCSICmd;
  186621. typedef struct
  186622. {
  186623. BYTE SRB_Cmd;
  186624. BYTE SRB_Status;
  186625. BYTE SRB_HaId;
  186626. BYTE SRB_Flags;
  186627. DWORD SRB_Hdr_Rsvd;
  186628. } PACKED SRB, *PSRB, FAR *LPSRB;
  186629. #pragma pack()
  186630. struct CDDeviceInfo
  186631. {
  186632. char vendor[9];
  186633. char productId[17];
  186634. char rev[5];
  186635. char vendorSpec[21];
  186636. BYTE ha;
  186637. BYTE tgt;
  186638. BYTE lun;
  186639. char scsiDriveLetter; // will be 0 if not using scsi
  186640. };
  186641. class CDReadBuffer
  186642. {
  186643. public:
  186644. int startFrame;
  186645. int numFrames;
  186646. int dataStartOffset;
  186647. int dataLength;
  186648. BYTE* buffer;
  186649. int bufferSize;
  186650. int index;
  186651. bool wantsIndex;
  186652. CDReadBuffer (const int numberOfFrames)
  186653. : startFrame (0),
  186654. numFrames (0),
  186655. dataStartOffset (0),
  186656. dataLength (0),
  186657. index (0),
  186658. wantsIndex (false)
  186659. {
  186660. bufferSize = 2352 * numberOfFrames;
  186661. buffer = (BYTE*) malloc (bufferSize);
  186662. }
  186663. ~CDReadBuffer()
  186664. {
  186665. free (buffer);
  186666. }
  186667. bool isZero() const
  186668. {
  186669. BYTE* p = buffer + dataStartOffset;
  186670. for (int i = dataLength; --i >= 0;)
  186671. if (*p++ != 0)
  186672. return false;
  186673. return true;
  186674. }
  186675. };
  186676. class CDDeviceHandle;
  186677. class CDController
  186678. {
  186679. public:
  186680. CDController();
  186681. virtual ~CDController();
  186682. virtual bool read (CDReadBuffer* t) = 0;
  186683. virtual void shutDown();
  186684. bool readAudio (CDReadBuffer* t, CDReadBuffer* overlapBuffer = 0);
  186685. int getLastIndex();
  186686. public:
  186687. bool initialised;
  186688. CDDeviceHandle* deviceInfo;
  186689. int framesToCheck, framesOverlap;
  186690. void prepare (SRB_ExecSCSICmd& s);
  186691. void perform (SRB_ExecSCSICmd& s);
  186692. void setPaused (bool paused);
  186693. };
  186694. #pragma pack(1)
  186695. struct TOCTRACK
  186696. {
  186697. BYTE rsvd;
  186698. BYTE ADR;
  186699. BYTE trackNumber;
  186700. BYTE rsvd2;
  186701. BYTE addr[4];
  186702. };
  186703. struct TOC
  186704. {
  186705. WORD tocLen;
  186706. BYTE firstTrack;
  186707. BYTE lastTrack;
  186708. TOCTRACK tracks[100];
  186709. };
  186710. #pragma pack()
  186711. enum
  186712. {
  186713. READTYPE_ANY = 0,
  186714. READTYPE_ATAPI1 = 1,
  186715. READTYPE_ATAPI2 = 2,
  186716. READTYPE_READ6 = 3,
  186717. READTYPE_READ10 = 4,
  186718. READTYPE_READ_D8 = 5,
  186719. READTYPE_READ_D4 = 6,
  186720. READTYPE_READ_D4_1 = 7,
  186721. READTYPE_READ10_2 = 8
  186722. };
  186723. class CDDeviceHandle
  186724. {
  186725. public:
  186726. CDDeviceHandle (const CDDeviceInfo* const device)
  186727. : scsiHandle (0),
  186728. readType (READTYPE_ANY),
  186729. controller (0)
  186730. {
  186731. memcpy (&info, device, sizeof (info));
  186732. }
  186733. ~CDDeviceHandle()
  186734. {
  186735. if (controller != 0)
  186736. {
  186737. controller->shutDown();
  186738. delete controller;
  186739. }
  186740. if (scsiHandle != 0)
  186741. CloseHandle (scsiHandle);
  186742. }
  186743. bool readTOC (TOC* lpToc, bool useMSF);
  186744. bool readAudio (CDReadBuffer* buffer, CDReadBuffer* overlapBuffer = 0);
  186745. void openDrawer (bool shouldBeOpen);
  186746. CDDeviceInfo info;
  186747. HANDLE scsiHandle;
  186748. BYTE readType;
  186749. private:
  186750. CDController* controller;
  186751. bool testController (const int readType,
  186752. CDController* const newController,
  186753. CDReadBuffer* const bufferToUse);
  186754. };
  186755. DWORD (*fGetASPI32SupportInfo)(void);
  186756. DWORD (*fSendASPI32Command)(LPSRB);
  186757. static HINSTANCE winAspiLib = 0;
  186758. static bool usingScsi = false;
  186759. static bool initialised = false;
  186760. static bool InitialiseCDRipper()
  186761. {
  186762. if (! initialised)
  186763. {
  186764. initialised = true;
  186765. OSVERSIONINFO info;
  186766. info.dwOSVersionInfoSize = sizeof (info);
  186767. GetVersionEx (&info);
  186768. usingScsi = (info.dwPlatformId == VER_PLATFORM_WIN32_NT) && (info.dwMajorVersion > 4);
  186769. if (! usingScsi)
  186770. {
  186771. fGetASPI32SupportInfo = 0;
  186772. fSendASPI32Command = 0;
  186773. winAspiLib = LoadLibrary (_T("WNASPI32.DLL"));
  186774. if (winAspiLib != 0)
  186775. {
  186776. fGetASPI32SupportInfo = (DWORD(*)(void)) GetProcAddress (winAspiLib, "GetASPI32SupportInfo");
  186777. fSendASPI32Command = (DWORD(*)(LPSRB)) GetProcAddress (winAspiLib, "SendASPI32Command");
  186778. if (fGetASPI32SupportInfo == 0 || fSendASPI32Command == 0)
  186779. return false;
  186780. }
  186781. else
  186782. {
  186783. usingScsi = true;
  186784. }
  186785. }
  186786. }
  186787. return true;
  186788. }
  186789. static void DeinitialiseCDRipper()
  186790. {
  186791. if (winAspiLib != 0)
  186792. {
  186793. fGetASPI32SupportInfo = 0;
  186794. fSendASPI32Command = 0;
  186795. FreeLibrary (winAspiLib);
  186796. winAspiLib = 0;
  186797. }
  186798. initialised = false;
  186799. }
  186800. static HANDLE CreateSCSIDeviceHandle (char driveLetter)
  186801. {
  186802. TCHAR devicePath[8];
  186803. devicePath[0] = '\\';
  186804. devicePath[1] = '\\';
  186805. devicePath[2] = '.';
  186806. devicePath[3] = '\\';
  186807. devicePath[4] = driveLetter;
  186808. devicePath[5] = ':';
  186809. devicePath[6] = 0;
  186810. OSVERSIONINFO info;
  186811. info.dwOSVersionInfoSize = sizeof (info);
  186812. GetVersionEx (&info);
  186813. DWORD flags = GENERIC_READ;
  186814. if ((info.dwPlatformId == VER_PLATFORM_WIN32_NT) && (info.dwMajorVersion > 4))
  186815. flags = GENERIC_READ | GENERIC_WRITE;
  186816. HANDLE h = CreateFile (devicePath, flags, FILE_SHARE_WRITE | FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
  186817. if (h == INVALID_HANDLE_VALUE)
  186818. {
  186819. flags ^= GENERIC_WRITE;
  186820. h = CreateFile (devicePath, flags, FILE_SHARE_WRITE | FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
  186821. }
  186822. return h;
  186823. }
  186824. static DWORD performScsiPassThroughCommand (const LPSRB_ExecSCSICmd srb,
  186825. const char driveLetter,
  186826. HANDLE& deviceHandle,
  186827. const bool retryOnFailure = true)
  186828. {
  186829. SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER s;
  186830. zerostruct (s);
  186831. s.spt.Length = sizeof (SCSI_PASS_THROUGH);
  186832. s.spt.CdbLength = srb->SRB_CDBLen;
  186833. s.spt.DataIn = (BYTE) ((srb->SRB_Flags & SRB_DIR_IN)
  186834. ? SCSI_IOCTL_DATA_IN
  186835. : ((srb->SRB_Flags & SRB_DIR_OUT)
  186836. ? SCSI_IOCTL_DATA_OUT
  186837. : SCSI_IOCTL_DATA_UNSPECIFIED));
  186838. s.spt.DataTransferLength = srb->SRB_BufLen;
  186839. s.spt.TimeOutValue = 5;
  186840. s.spt.DataBuffer = srb->SRB_BufPointer;
  186841. s.spt.SenseInfoOffset = offsetof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER, ucSenseBuf);
  186842. memcpy (s.spt.Cdb, srb->CDBByte, srb->SRB_CDBLen);
  186843. srb->SRB_Status = SS_ERR;
  186844. srb->SRB_TargStat = 0x0004;
  186845. DWORD bytesReturned = 0;
  186846. if (DeviceIoControl (deviceHandle, IOCTL_SCSI_PASS_THROUGH_DIRECT,
  186847. &s, sizeof (s),
  186848. &s, sizeof (s),
  186849. &bytesReturned, 0) != 0)
  186850. {
  186851. srb->SRB_Status = SS_COMP;
  186852. }
  186853. else if (retryOnFailure)
  186854. {
  186855. const DWORD error = GetLastError();
  186856. if ((error == ERROR_MEDIA_CHANGED) || (error == ERROR_INVALID_HANDLE))
  186857. {
  186858. if (error != ERROR_INVALID_HANDLE)
  186859. CloseHandle (deviceHandle);
  186860. deviceHandle = CreateSCSIDeviceHandle (driveLetter);
  186861. return performScsiPassThroughCommand (srb, driveLetter, deviceHandle, false);
  186862. }
  186863. }
  186864. return srb->SRB_Status;
  186865. }
  186866. // Controller types..
  186867. class ControllerType1 : public CDController
  186868. {
  186869. public:
  186870. ControllerType1() {}
  186871. ~ControllerType1() {}
  186872. bool read (CDReadBuffer* rb)
  186873. {
  186874. if (rb->numFrames * 2352 > rb->bufferSize)
  186875. return false;
  186876. SRB_ExecSCSICmd s;
  186877. prepare (s);
  186878. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186879. s.SRB_BufLen = rb->bufferSize;
  186880. s.SRB_BufPointer = rb->buffer;
  186881. s.SRB_CDBLen = 12;
  186882. s.CDBByte[0] = 0xBE;
  186883. s.CDBByte[3] = (BYTE)((rb->startFrame >> 16) & 0xFF);
  186884. s.CDBByte[4] = (BYTE)((rb->startFrame >> 8) & 0xFF);
  186885. s.CDBByte[5] = (BYTE)(rb->startFrame & 0xFF);
  186886. s.CDBByte[8] = (BYTE)(rb->numFrames & 0xFF);
  186887. s.CDBByte[9] = (BYTE)((deviceInfo->readType == READTYPE_ATAPI1) ? 0x10 : 0xF0);
  186888. perform (s);
  186889. if (s.SRB_Status != SS_COMP)
  186890. return false;
  186891. rb->dataLength = rb->numFrames * 2352;
  186892. rb->dataStartOffset = 0;
  186893. return true;
  186894. }
  186895. };
  186896. class ControllerType2 : public CDController
  186897. {
  186898. public:
  186899. ControllerType2() {}
  186900. ~ControllerType2() {}
  186901. void shutDown()
  186902. {
  186903. if (initialised)
  186904. {
  186905. BYTE bufPointer[] = { 0, 0, 0, 8, 83, 0, 0, 0, 0, 0, 8, 0 };
  186906. SRB_ExecSCSICmd s;
  186907. prepare (s);
  186908. s.SRB_Flags = SRB_EVENT_NOTIFY | SRB_ENABLE_RESIDUAL_COUNT;
  186909. s.SRB_BufLen = 0x0C;
  186910. s.SRB_BufPointer = bufPointer;
  186911. s.SRB_CDBLen = 6;
  186912. s.CDBByte[0] = 0x15;
  186913. s.CDBByte[4] = 0x0C;
  186914. perform (s);
  186915. }
  186916. }
  186917. bool init()
  186918. {
  186919. SRB_ExecSCSICmd s;
  186920. s.SRB_Status = SS_ERR;
  186921. if (deviceInfo->readType == READTYPE_READ10_2)
  186922. {
  186923. BYTE bufPointer1[] = { 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 9, 48, 35, 6, 0, 0, 0, 0, 0, 128 };
  186924. BYTE bufPointer2[] = { 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 9, 48, 1, 6, 32, 7, 0, 0, 0, 0 };
  186925. for (int i = 0; i < 2; ++i)
  186926. {
  186927. prepare (s);
  186928. s.SRB_Flags = SRB_EVENT_NOTIFY;
  186929. s.SRB_BufLen = 0x14;
  186930. s.SRB_BufPointer = (i == 0) ? bufPointer1 : bufPointer2;
  186931. s.SRB_CDBLen = 6;
  186932. s.CDBByte[0] = 0x15;
  186933. s.CDBByte[1] = 0x10;
  186934. s.CDBByte[4] = 0x14;
  186935. perform (s);
  186936. if (s.SRB_Status != SS_COMP)
  186937. return false;
  186938. }
  186939. }
  186940. else
  186941. {
  186942. BYTE bufPointer[] = { 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 9, 48 };
  186943. prepare (s);
  186944. s.SRB_Flags = SRB_EVENT_NOTIFY;
  186945. s.SRB_BufLen = 0x0C;
  186946. s.SRB_BufPointer = bufPointer;
  186947. s.SRB_CDBLen = 6;
  186948. s.CDBByte[0] = 0x15;
  186949. s.CDBByte[4] = 0x0C;
  186950. perform (s);
  186951. }
  186952. return s.SRB_Status == SS_COMP;
  186953. }
  186954. bool read (CDReadBuffer* rb)
  186955. {
  186956. if (rb->numFrames * 2352 > rb->bufferSize)
  186957. return false;
  186958. if (!initialised)
  186959. {
  186960. initialised = init();
  186961. if (!initialised)
  186962. return false;
  186963. }
  186964. SRB_ExecSCSICmd s;
  186965. prepare (s);
  186966. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186967. s.SRB_BufLen = rb->bufferSize;
  186968. s.SRB_BufPointer = rb->buffer;
  186969. s.SRB_CDBLen = 10;
  186970. s.CDBByte[0] = 0x28;
  186971. s.CDBByte[1] = (BYTE)(deviceInfo->info.lun << 5);
  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[8] = (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 ControllerType3 : public CDController
  186985. {
  186986. public:
  186987. ControllerType3() {}
  186988. ~ControllerType3() {}
  186989. bool read (CDReadBuffer* rb)
  186990. {
  186991. if (rb->numFrames * 2352 > rb->bufferSize)
  186992. return false;
  186993. if (!initialised)
  186994. {
  186995. setPaused (false);
  186996. initialised = true;
  186997. }
  186998. SRB_ExecSCSICmd s;
  186999. prepare (s);
  187000. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  187001. s.SRB_BufLen = rb->numFrames * 2352;
  187002. s.SRB_BufPointer = rb->buffer;
  187003. s.SRB_CDBLen = 12;
  187004. s.CDBByte[0] = 0xD8;
  187005. s.CDBByte[3] = (BYTE)((rb->startFrame >> 16) & 0xFF);
  187006. s.CDBByte[4] = (BYTE)((rb->startFrame >> 8) & 0xFF);
  187007. s.CDBByte[5] = (BYTE)(rb->startFrame & 0xFF);
  187008. s.CDBByte[9] = (BYTE)(rb->numFrames & 0xFF);
  187009. perform (s);
  187010. if (s.SRB_Status != SS_COMP)
  187011. return false;
  187012. rb->dataLength = rb->numFrames * 2352;
  187013. rb->dataStartOffset = 0;
  187014. return true;
  187015. }
  187016. };
  187017. class ControllerType4 : public CDController
  187018. {
  187019. public:
  187020. ControllerType4() {}
  187021. ~ControllerType4() {}
  187022. bool selectD4Mode()
  187023. {
  187024. BYTE bufPointer[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 48 };
  187025. SRB_ExecSCSICmd s;
  187026. prepare (s);
  187027. s.SRB_Flags = SRB_EVENT_NOTIFY;
  187028. s.SRB_CDBLen = 6;
  187029. s.SRB_BufLen = 12;
  187030. s.SRB_BufPointer = bufPointer;
  187031. s.CDBByte[0] = 0x15;
  187032. s.CDBByte[1] = 0x10;
  187033. s.CDBByte[4] = 0x08;
  187034. perform (s);
  187035. return s.SRB_Status == SS_COMP;
  187036. }
  187037. bool read (CDReadBuffer* rb)
  187038. {
  187039. if (rb->numFrames * 2352 > rb->bufferSize)
  187040. return false;
  187041. if (!initialised)
  187042. {
  187043. setPaused (true);
  187044. if (deviceInfo->readType == READTYPE_READ_D4_1)
  187045. selectD4Mode();
  187046. initialised = true;
  187047. }
  187048. SRB_ExecSCSICmd s;
  187049. prepare (s);
  187050. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  187051. s.SRB_BufLen = rb->bufferSize;
  187052. s.SRB_BufPointer = rb->buffer;
  187053. s.SRB_CDBLen = 10;
  187054. s.CDBByte[0] = 0xD4;
  187055. s.CDBByte[3] = (BYTE)((rb->startFrame >> 16) & 0xFF);
  187056. s.CDBByte[4] = (BYTE)((rb->startFrame >> 8) & 0xFF);
  187057. s.CDBByte[5] = (BYTE)(rb->startFrame & 0xFF);
  187058. s.CDBByte[8] = (BYTE)(rb->numFrames & 0xFF);
  187059. perform (s);
  187060. if (s.SRB_Status != SS_COMP)
  187061. return false;
  187062. rb->dataLength = rb->numFrames * 2352;
  187063. rb->dataStartOffset = 0;
  187064. return true;
  187065. }
  187066. };
  187067. CDController::CDController() : initialised (false)
  187068. {
  187069. }
  187070. CDController::~CDController()
  187071. {
  187072. }
  187073. void CDController::prepare (SRB_ExecSCSICmd& s)
  187074. {
  187075. zerostruct (s);
  187076. s.SRB_Cmd = SC_EXEC_SCSI_CMD;
  187077. s.SRB_HaID = deviceInfo->info.ha;
  187078. s.SRB_Target = deviceInfo->info.tgt;
  187079. s.SRB_Lun = deviceInfo->info.lun;
  187080. s.SRB_SenseLen = SENSE_LEN;
  187081. }
  187082. void CDController::perform (SRB_ExecSCSICmd& s)
  187083. {
  187084. HANDLE event = CreateEvent (0, TRUE, FALSE, 0);
  187085. s.SRB_PostProc = (void*)event;
  187086. ResetEvent (event);
  187087. DWORD status = (usingScsi) ? performScsiPassThroughCommand ((LPSRB_ExecSCSICmd)&s,
  187088. deviceInfo->info.scsiDriveLetter,
  187089. deviceInfo->scsiHandle)
  187090. : fSendASPI32Command ((LPSRB)&s);
  187091. if (status == SS_PENDING)
  187092. WaitForSingleObject (event, 4000);
  187093. CloseHandle (event);
  187094. }
  187095. void CDController::setPaused (bool paused)
  187096. {
  187097. SRB_ExecSCSICmd s;
  187098. prepare (s);
  187099. s.SRB_Flags = SRB_EVENT_NOTIFY;
  187100. s.SRB_CDBLen = 10;
  187101. s.CDBByte[0] = 0x4B;
  187102. s.CDBByte[8] = (BYTE) (paused ? 0 : 1);
  187103. perform (s);
  187104. }
  187105. void CDController::shutDown()
  187106. {
  187107. }
  187108. bool CDController::readAudio (CDReadBuffer* rb, CDReadBuffer* overlapBuffer)
  187109. {
  187110. if (overlapBuffer != 0)
  187111. {
  187112. const bool canDoJitter = (overlapBuffer->bufferSize >= 2352 * framesToCheck);
  187113. const bool doJitter = canDoJitter && ! overlapBuffer->isZero();
  187114. if (doJitter
  187115. && overlapBuffer->startFrame > 0
  187116. && overlapBuffer->numFrames > 0
  187117. && overlapBuffer->dataLength > 0)
  187118. {
  187119. const int numFrames = rb->numFrames;
  187120. if (overlapBuffer->startFrame == (rb->startFrame - framesToCheck))
  187121. {
  187122. rb->startFrame -= framesOverlap;
  187123. if (framesToCheck < framesOverlap
  187124. && numFrames + framesOverlap <= rb->bufferSize / 2352)
  187125. rb->numFrames += framesOverlap;
  187126. }
  187127. else
  187128. {
  187129. overlapBuffer->dataLength = 0;
  187130. overlapBuffer->startFrame = 0;
  187131. overlapBuffer->numFrames = 0;
  187132. }
  187133. }
  187134. if (! read (rb))
  187135. return false;
  187136. if (doJitter)
  187137. {
  187138. const int checkLen = framesToCheck * 2352;
  187139. const int maxToCheck = rb->dataLength - checkLen;
  187140. if (overlapBuffer->dataLength == 0 || overlapBuffer->isZero())
  187141. return true;
  187142. BYTE* const p = overlapBuffer->buffer + overlapBuffer->dataStartOffset;
  187143. bool found = false;
  187144. for (int i = 0; i < maxToCheck; ++i)
  187145. {
  187146. if (!memcmp (p, rb->buffer + i, checkLen))
  187147. {
  187148. i += checkLen;
  187149. rb->dataStartOffset = i;
  187150. rb->dataLength -= i;
  187151. rb->startFrame = overlapBuffer->startFrame + framesToCheck;
  187152. found = true;
  187153. break;
  187154. }
  187155. }
  187156. rb->numFrames = rb->dataLength / 2352;
  187157. rb->dataLength = 2352 * rb->numFrames;
  187158. if (!found)
  187159. return false;
  187160. }
  187161. if (canDoJitter)
  187162. {
  187163. memcpy (overlapBuffer->buffer,
  187164. rb->buffer + rb->dataStartOffset + 2352 * (rb->numFrames - framesToCheck),
  187165. 2352 * framesToCheck);
  187166. overlapBuffer->startFrame = rb->startFrame + rb->numFrames - framesToCheck;
  187167. overlapBuffer->numFrames = framesToCheck;
  187168. overlapBuffer->dataLength = 2352 * framesToCheck;
  187169. overlapBuffer->dataStartOffset = 0;
  187170. }
  187171. else
  187172. {
  187173. overlapBuffer->startFrame = 0;
  187174. overlapBuffer->numFrames = 0;
  187175. overlapBuffer->dataLength = 0;
  187176. }
  187177. return true;
  187178. }
  187179. else
  187180. {
  187181. return read (rb);
  187182. }
  187183. }
  187184. int CDController::getLastIndex()
  187185. {
  187186. char qdata[100];
  187187. SRB_ExecSCSICmd s;
  187188. prepare (s);
  187189. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  187190. s.SRB_BufLen = sizeof (qdata);
  187191. s.SRB_BufPointer = (BYTE*)qdata;
  187192. s.SRB_CDBLen = 12;
  187193. s.CDBByte[0] = 0x42;
  187194. s.CDBByte[1] = (BYTE)(deviceInfo->info.lun << 5);
  187195. s.CDBByte[2] = 64;
  187196. s.CDBByte[3] = 1; // get current position
  187197. s.CDBByte[7] = 0;
  187198. s.CDBByte[8] = (BYTE)sizeof (qdata);
  187199. perform (s);
  187200. if (s.SRB_Status == SS_COMP)
  187201. return qdata[7];
  187202. return 0;
  187203. }
  187204. bool CDDeviceHandle::readTOC (TOC* lpToc, bool useMSF)
  187205. {
  187206. HANDLE event = CreateEvent (0, TRUE, FALSE, 0);
  187207. SRB_ExecSCSICmd s;
  187208. zerostruct (s);
  187209. s.SRB_Cmd = SC_EXEC_SCSI_CMD;
  187210. s.SRB_HaID = info.ha;
  187211. s.SRB_Target = info.tgt;
  187212. s.SRB_Lun = info.lun;
  187213. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  187214. s.SRB_BufLen = 0x324;
  187215. s.SRB_BufPointer = (BYTE*)lpToc;
  187216. s.SRB_SenseLen = 0x0E;
  187217. s.SRB_CDBLen = 0x0A;
  187218. s.SRB_PostProc = (void*)event;
  187219. s.CDBByte[0] = 0x43;
  187220. s.CDBByte[1] = (BYTE)(useMSF ? 0x02 : 0x00);
  187221. s.CDBByte[7] = 0x03;
  187222. s.CDBByte[8] = 0x24;
  187223. ResetEvent (event);
  187224. DWORD status = (usingScsi) ? performScsiPassThroughCommand ((LPSRB_ExecSCSICmd)&s, info.scsiDriveLetter, scsiHandle)
  187225. : fSendASPI32Command ((LPSRB)&s);
  187226. if (status == SS_PENDING)
  187227. WaitForSingleObject (event, 4000);
  187228. CloseHandle (event);
  187229. return (s.SRB_Status == SS_COMP);
  187230. }
  187231. bool CDDeviceHandle::readAudio (CDReadBuffer* const buffer,
  187232. CDReadBuffer* const overlapBuffer)
  187233. {
  187234. if (controller == 0)
  187235. {
  187236. testController (READTYPE_ATAPI2, new ControllerType1(), buffer)
  187237. || testController (READTYPE_ATAPI1, new ControllerType1(), buffer)
  187238. || testController (READTYPE_READ10_2, new ControllerType2(), buffer)
  187239. || testController (READTYPE_READ10, new ControllerType2(), buffer)
  187240. || testController (READTYPE_READ_D8, new ControllerType3(), buffer)
  187241. || testController (READTYPE_READ_D4, new ControllerType4(), buffer)
  187242. || testController (READTYPE_READ_D4_1, new ControllerType4(), buffer);
  187243. }
  187244. buffer->index = 0;
  187245. if ((controller != 0)
  187246. && controller->readAudio (buffer, overlapBuffer))
  187247. {
  187248. if (buffer->wantsIndex)
  187249. buffer->index = controller->getLastIndex();
  187250. return true;
  187251. }
  187252. return false;
  187253. }
  187254. void CDDeviceHandle::openDrawer (bool shouldBeOpen)
  187255. {
  187256. if (shouldBeOpen)
  187257. {
  187258. if (controller != 0)
  187259. {
  187260. controller->shutDown();
  187261. delete controller;
  187262. controller = 0;
  187263. }
  187264. if (scsiHandle != 0)
  187265. {
  187266. CloseHandle (scsiHandle);
  187267. scsiHandle = 0;
  187268. }
  187269. }
  187270. SRB_ExecSCSICmd s;
  187271. zerostruct (s);
  187272. s.SRB_Cmd = SC_EXEC_SCSI_CMD;
  187273. s.SRB_HaID = info.ha;
  187274. s.SRB_Target = info.tgt;
  187275. s.SRB_Lun = info.lun;
  187276. s.SRB_SenseLen = SENSE_LEN;
  187277. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  187278. s.SRB_BufLen = 0;
  187279. s.SRB_BufPointer = 0;
  187280. s.SRB_CDBLen = 12;
  187281. s.CDBByte[0] = 0x1b;
  187282. s.CDBByte[1] = (BYTE)(info.lun << 5);
  187283. s.CDBByte[4] = (BYTE)((shouldBeOpen) ? 2 : 3);
  187284. HANDLE event = CreateEvent (0, TRUE, FALSE, 0);
  187285. s.SRB_PostProc = (void*)event;
  187286. ResetEvent (event);
  187287. DWORD status = (usingScsi) ? performScsiPassThroughCommand ((LPSRB_ExecSCSICmd)&s, info.scsiDriveLetter, scsiHandle)
  187288. : fSendASPI32Command ((LPSRB)&s);
  187289. if (status == SS_PENDING)
  187290. WaitForSingleObject (event, 4000);
  187291. CloseHandle (event);
  187292. }
  187293. bool CDDeviceHandle::testController (const int type,
  187294. CDController* const newController,
  187295. CDReadBuffer* const rb)
  187296. {
  187297. controller = newController;
  187298. readType = (BYTE)type;
  187299. controller->deviceInfo = this;
  187300. controller->framesToCheck = 1;
  187301. controller->framesOverlap = 3;
  187302. bool passed = false;
  187303. memset (rb->buffer, 0xcd, rb->bufferSize);
  187304. if (controller->read (rb))
  187305. {
  187306. passed = true;
  187307. int* p = (int*) (rb->buffer + rb->dataStartOffset);
  187308. int wrong = 0;
  187309. for (int i = rb->dataLength / 4; --i >= 0;)
  187310. {
  187311. if (*p++ == (int) 0xcdcdcdcd)
  187312. {
  187313. if (++wrong == 4)
  187314. {
  187315. passed = false;
  187316. break;
  187317. }
  187318. }
  187319. else
  187320. {
  187321. wrong = 0;
  187322. }
  187323. }
  187324. }
  187325. if (! passed)
  187326. {
  187327. controller->shutDown();
  187328. delete controller;
  187329. controller = 0;
  187330. }
  187331. return passed;
  187332. }
  187333. static void GetAspiDeviceInfo (CDDeviceInfo* dev, BYTE ha, BYTE tgt, BYTE lun)
  187334. {
  187335. HANDLE event = CreateEvent (0, TRUE, FALSE, 0);
  187336. const int bufSize = 128;
  187337. BYTE buffer[bufSize];
  187338. zeromem (buffer, bufSize);
  187339. SRB_ExecSCSICmd s;
  187340. zerostruct (s);
  187341. s.SRB_Cmd = SC_EXEC_SCSI_CMD;
  187342. s.SRB_HaID = ha;
  187343. s.SRB_Target = tgt;
  187344. s.SRB_Lun = lun;
  187345. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  187346. s.SRB_BufLen = bufSize;
  187347. s.SRB_BufPointer = buffer;
  187348. s.SRB_SenseLen = SENSE_LEN;
  187349. s.SRB_CDBLen = 6;
  187350. s.SRB_PostProc = (void*)event;
  187351. s.CDBByte[0] = SCSI_INQUIRY;
  187352. s.CDBByte[4] = 100;
  187353. ResetEvent (event);
  187354. if (fSendASPI32Command ((LPSRB)&s) == SS_PENDING)
  187355. WaitForSingleObject (event, 4000);
  187356. CloseHandle (event);
  187357. if (s.SRB_Status == SS_COMP)
  187358. {
  187359. memcpy (dev->vendor, &buffer[8], 8);
  187360. memcpy (dev->productId, &buffer[16], 16);
  187361. memcpy (dev->rev, &buffer[32], 4);
  187362. memcpy (dev->vendorSpec, &buffer[36], 20);
  187363. }
  187364. }
  187365. static int FindCDDevices (CDDeviceInfo* const list,
  187366. int maxItems)
  187367. {
  187368. int count = 0;
  187369. if (usingScsi)
  187370. {
  187371. for (char driveLetter = 'b'; driveLetter <= 'z'; ++driveLetter)
  187372. {
  187373. TCHAR drivePath[8];
  187374. drivePath[0] = driveLetter;
  187375. drivePath[1] = ':';
  187376. drivePath[2] = '\\';
  187377. drivePath[3] = 0;
  187378. if (GetDriveType (drivePath) == DRIVE_CDROM)
  187379. {
  187380. HANDLE h = CreateSCSIDeviceHandle (driveLetter);
  187381. if (h != INVALID_HANDLE_VALUE)
  187382. {
  187383. BYTE buffer[100], passThroughStruct[1024];
  187384. zeromem (buffer, sizeof (buffer));
  187385. zeromem (passThroughStruct, sizeof (passThroughStruct));
  187386. PSCSI_PASS_THROUGH_DIRECT_WITH_BUFFER p = (PSCSI_PASS_THROUGH_DIRECT_WITH_BUFFER)passThroughStruct;
  187387. p->spt.Length = sizeof (SCSI_PASS_THROUGH);
  187388. p->spt.CdbLength = 6;
  187389. p->spt.SenseInfoLength = 24;
  187390. p->spt.DataIn = SCSI_IOCTL_DATA_IN;
  187391. p->spt.DataTransferLength = 100;
  187392. p->spt.TimeOutValue = 2;
  187393. p->spt.DataBuffer = buffer;
  187394. p->spt.SenseInfoOffset = offsetof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER, ucSenseBuf);
  187395. p->spt.Cdb[0] = 0x12;
  187396. p->spt.Cdb[4] = 100;
  187397. DWORD bytesReturned = 0;
  187398. if (DeviceIoControl (h, IOCTL_SCSI_PASS_THROUGH_DIRECT,
  187399. p, sizeof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER),
  187400. p, sizeof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER),
  187401. &bytesReturned, 0) != 0)
  187402. {
  187403. zeromem (&list[count], sizeof (CDDeviceInfo));
  187404. list[count].scsiDriveLetter = driveLetter;
  187405. memcpy (list[count].vendor, &buffer[8], 8);
  187406. memcpy (list[count].productId, &buffer[16], 16);
  187407. memcpy (list[count].rev, &buffer[32], 4);
  187408. memcpy (list[count].vendorSpec, &buffer[36], 20);
  187409. zeromem (passThroughStruct, sizeof (passThroughStruct));
  187410. PSCSI_ADDRESS scsiAddr = (PSCSI_ADDRESS)passThroughStruct;
  187411. scsiAddr->Length = sizeof (SCSI_ADDRESS);
  187412. if (DeviceIoControl (h, IOCTL_SCSI_GET_ADDRESS,
  187413. 0, 0, scsiAddr, sizeof (SCSI_ADDRESS),
  187414. &bytesReturned, 0) != 0)
  187415. {
  187416. list[count].ha = scsiAddr->PortNumber;
  187417. list[count].tgt = scsiAddr->TargetId;
  187418. list[count].lun = scsiAddr->Lun;
  187419. ++count;
  187420. }
  187421. }
  187422. CloseHandle (h);
  187423. }
  187424. }
  187425. }
  187426. }
  187427. else
  187428. {
  187429. const DWORD d = fGetASPI32SupportInfo();
  187430. BYTE status = HIBYTE (LOWORD (d));
  187431. if (status != SS_COMP || status == SS_NO_ADAPTERS)
  187432. return 0;
  187433. const int numAdapters = LOBYTE (LOWORD (d));
  187434. for (BYTE ha = 0; ha < numAdapters; ++ha)
  187435. {
  187436. SRB_HAInquiry s;
  187437. zerostruct (s);
  187438. s.SRB_Cmd = SC_HA_INQUIRY;
  187439. s.SRB_HaID = ha;
  187440. fSendASPI32Command ((LPSRB)&s);
  187441. if (s.SRB_Status == SS_COMP)
  187442. {
  187443. maxItems = (int)s.HA_Unique[3];
  187444. if (maxItems == 0)
  187445. maxItems = 8;
  187446. for (BYTE tgt = 0; tgt < maxItems; ++tgt)
  187447. {
  187448. for (BYTE lun = 0; lun < 8; ++lun)
  187449. {
  187450. SRB_GDEVBlock sb;
  187451. zerostruct (sb);
  187452. sb.SRB_Cmd = SC_GET_DEV_TYPE;
  187453. sb.SRB_HaID = ha;
  187454. sb.SRB_Target = tgt;
  187455. sb.SRB_Lun = lun;
  187456. fSendASPI32Command ((LPSRB) &sb);
  187457. if (sb.SRB_Status == SS_COMP
  187458. && sb.SRB_DeviceType == DTYPE_CROM)
  187459. {
  187460. zeromem (&list[count], sizeof (CDDeviceInfo));
  187461. list[count].ha = ha;
  187462. list[count].tgt = tgt;
  187463. list[count].lun = lun;
  187464. GetAspiDeviceInfo (&(list[count]), ha, tgt, lun);
  187465. ++count;
  187466. }
  187467. }
  187468. }
  187469. }
  187470. }
  187471. }
  187472. return count;
  187473. }
  187474. static int ripperUsers = 0;
  187475. static bool initialisedOk = false;
  187476. class DeinitialiseTimer : private Timer,
  187477. private DeletedAtShutdown
  187478. {
  187479. DeinitialiseTimer (const DeinitialiseTimer&);
  187480. const DeinitialiseTimer& operator= (const DeinitialiseTimer&);
  187481. public:
  187482. DeinitialiseTimer()
  187483. {
  187484. startTimer (4000);
  187485. }
  187486. ~DeinitialiseTimer()
  187487. {
  187488. if (--ripperUsers == 0)
  187489. DeinitialiseCDRipper();
  187490. }
  187491. void timerCallback()
  187492. {
  187493. delete this;
  187494. }
  187495. juce_UseDebuggingNewOperator
  187496. };
  187497. static void incUserCount()
  187498. {
  187499. if (ripperUsers++ == 0)
  187500. initialisedOk = InitialiseCDRipper();
  187501. }
  187502. static void decUserCount()
  187503. {
  187504. new DeinitialiseTimer();
  187505. }
  187506. struct CDDeviceWrapper
  187507. {
  187508. CDDeviceHandle* cdH;
  187509. CDReadBuffer* overlapBuffer;
  187510. bool jitter;
  187511. };
  187512. static int getAddressOf (const TOCTRACK* const t)
  187513. {
  187514. return (((DWORD)t->addr[0]) << 24) + (((DWORD)t->addr[1]) << 16) +
  187515. (((DWORD)t->addr[2]) << 8) + ((DWORD)t->addr[3]);
  187516. }
  187517. static int getMSFAddressOf (const TOCTRACK* const t)
  187518. {
  187519. return 60 * t->addr[1] + t->addr[2];
  187520. }
  187521. static const int samplesPerFrame = 44100 / 75;
  187522. static const int bytesPerFrame = samplesPerFrame * 4;
  187523. const StringArray AudioCDReader::getAvailableCDNames()
  187524. {
  187525. StringArray results;
  187526. incUserCount();
  187527. if (initialisedOk)
  187528. {
  187529. CDDeviceInfo list[8];
  187530. const int num = FindCDDevices (list, 8);
  187531. decUserCount();
  187532. for (int i = 0; i < num; ++i)
  187533. {
  187534. String s;
  187535. if (list[i].scsiDriveLetter > 0)
  187536. s << String::charToString (list[i].scsiDriveLetter).toUpperCase() << T(": ");
  187537. s << String (list[i].vendor).trim()
  187538. << T(" ") << String (list[i].productId).trim()
  187539. << T(" ") << String (list[i].rev).trim();
  187540. results.add (s);
  187541. }
  187542. }
  187543. return results;
  187544. }
  187545. static CDDeviceHandle* openHandle (const CDDeviceInfo* const device)
  187546. {
  187547. SRB_GDEVBlock s;
  187548. zerostruct (s);
  187549. s.SRB_Cmd = SC_GET_DEV_TYPE;
  187550. s.SRB_HaID = device->ha;
  187551. s.SRB_Target = device->tgt;
  187552. s.SRB_Lun = device->lun;
  187553. if (usingScsi)
  187554. {
  187555. HANDLE h = CreateSCSIDeviceHandle (device->scsiDriveLetter);
  187556. if (h != INVALID_HANDLE_VALUE)
  187557. {
  187558. CDDeviceHandle* cdh = new CDDeviceHandle (device);
  187559. cdh->scsiHandle = h;
  187560. return cdh;
  187561. }
  187562. }
  187563. else
  187564. {
  187565. if (fSendASPI32Command ((LPSRB)&s) == SS_COMP
  187566. && s.SRB_DeviceType == DTYPE_CROM)
  187567. {
  187568. return new CDDeviceHandle (device);
  187569. }
  187570. }
  187571. return 0;
  187572. }
  187573. AudioCDReader* AudioCDReader::createReaderForCD (const int deviceIndex)
  187574. {
  187575. incUserCount();
  187576. if (initialisedOk)
  187577. {
  187578. CDDeviceInfo list[8];
  187579. const int num = FindCDDevices (list, 8);
  187580. if (((unsigned int) deviceIndex) < (unsigned int) num)
  187581. {
  187582. CDDeviceHandle* const handle = openHandle (&(list[deviceIndex]));
  187583. if (handle != 0)
  187584. {
  187585. CDDeviceWrapper* const d = new CDDeviceWrapper();
  187586. d->cdH = handle;
  187587. d->overlapBuffer = new CDReadBuffer(3);
  187588. return new AudioCDReader (d);
  187589. }
  187590. }
  187591. }
  187592. decUserCount();
  187593. return 0;
  187594. }
  187595. AudioCDReader::AudioCDReader (void* handle_)
  187596. : AudioFormatReader (0, T("CD Audio")),
  187597. handle (handle_),
  187598. indexingEnabled (false),
  187599. lastIndex (0),
  187600. firstFrameInBuffer (0),
  187601. samplesInBuffer (0)
  187602. {
  187603. jassert (handle_ != 0);
  187604. refreshTrackLengths();
  187605. sampleRate = 44100.0;
  187606. bitsPerSample = 16;
  187607. lengthInSamples = getPositionOfTrackStart (numTracks);
  187608. numChannels = 2;
  187609. usesFloatingPointData = false;
  187610. buffer.setSize (4 * bytesPerFrame, true);
  187611. }
  187612. AudioCDReader::~AudioCDReader()
  187613. {
  187614. CDDeviceWrapper* const device = (CDDeviceWrapper*)handle;
  187615. delete device->cdH;
  187616. delete device->overlapBuffer;
  187617. delete device;
  187618. decUserCount();
  187619. }
  187620. bool AudioCDReader::readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  187621. int64 startSampleInFile, int numSamples)
  187622. {
  187623. CDDeviceWrapper* const device = (CDDeviceWrapper*) handle;
  187624. bool ok = true;
  187625. while (numSamples > 0)
  187626. {
  187627. const int bufferStartSample = firstFrameInBuffer * samplesPerFrame;
  187628. const int bufferEndSample = bufferStartSample + samplesInBuffer;
  187629. if (startSampleInFile >= bufferStartSample
  187630. && startSampleInFile < bufferEndSample)
  187631. {
  187632. const int toDo = (int) jmin ((int64) numSamples, bufferEndSample - startSampleInFile);
  187633. int* const l = destSamples[0] + startOffsetInDestBuffer;
  187634. int* const r = numDestChannels > 1 ? (destSamples[1] + startOffsetInDestBuffer) : 0;
  187635. const short* src = (const short*) buffer.getData();
  187636. src += 2 * (startSampleInFile - bufferStartSample);
  187637. for (int i = 0; i < toDo; ++i)
  187638. {
  187639. l[i] = src [i << 1] << 16;
  187640. if (r != 0)
  187641. r[i] = src [(i << 1) + 1] << 16;
  187642. }
  187643. startOffsetInDestBuffer += toDo;
  187644. startSampleInFile += toDo;
  187645. numSamples -= toDo;
  187646. }
  187647. else
  187648. {
  187649. const int framesInBuffer = buffer.getSize() / bytesPerFrame;
  187650. const int frameNeeded = (int) (startSampleInFile / samplesPerFrame);
  187651. if (firstFrameInBuffer + framesInBuffer != frameNeeded)
  187652. {
  187653. device->overlapBuffer->dataLength = 0;
  187654. device->overlapBuffer->startFrame = 0;
  187655. device->overlapBuffer->numFrames = 0;
  187656. device->jitter = false;
  187657. }
  187658. firstFrameInBuffer = frameNeeded;
  187659. lastIndex = 0;
  187660. CDReadBuffer readBuffer (framesInBuffer + 4);
  187661. readBuffer.wantsIndex = indexingEnabled;
  187662. int i;
  187663. for (i = 5; --i >= 0;)
  187664. {
  187665. readBuffer.startFrame = frameNeeded;
  187666. readBuffer.numFrames = framesInBuffer;
  187667. if (device->cdH->readAudio (&readBuffer, (device->jitter) ? device->overlapBuffer : 0))
  187668. break;
  187669. else
  187670. device->overlapBuffer->dataLength = 0;
  187671. }
  187672. if (i >= 0)
  187673. {
  187674. memcpy ((char*) buffer.getData(),
  187675. readBuffer.buffer + readBuffer.dataStartOffset,
  187676. readBuffer.dataLength);
  187677. samplesInBuffer = readBuffer.dataLength >> 2;
  187678. lastIndex = readBuffer.index;
  187679. }
  187680. else
  187681. {
  187682. int* l = destSamples[0] + startOffsetInDestBuffer;
  187683. int* r = numDestChannels > 1 ? (destSamples[1] + startOffsetInDestBuffer) : 0;
  187684. while (--numSamples >= 0)
  187685. {
  187686. *l++ = 0;
  187687. if (r != 0)
  187688. *r++ = 0;
  187689. }
  187690. // sometimes the read fails for just the very last couple of blocks, so
  187691. // we'll ignore and errors in the last half-second of the disk..
  187692. ok = startSampleInFile > (trackStarts [numTracks] - 20000);
  187693. break;
  187694. }
  187695. }
  187696. }
  187697. return ok;
  187698. }
  187699. bool AudioCDReader::isCDStillPresent() const
  187700. {
  187701. TOC toc;
  187702. zerostruct (toc);
  187703. return ((CDDeviceWrapper*)handle)->cdH->readTOC (&toc, false);
  187704. }
  187705. int AudioCDReader::getNumTracks() const
  187706. {
  187707. return numTracks;
  187708. }
  187709. int AudioCDReader::getPositionOfTrackStart (int trackNum) const
  187710. {
  187711. return (trackNum >= 0 && trackNum <= numTracks) ? trackStarts [trackNum] * samplesPerFrame
  187712. : 0;
  187713. }
  187714. void AudioCDReader::refreshTrackLengths()
  187715. {
  187716. zeromem (trackStarts, sizeof (trackStarts));
  187717. zeromem (audioTracks, sizeof (audioTracks));
  187718. TOC toc;
  187719. zerostruct (toc);
  187720. if (((CDDeviceWrapper*)handle)->cdH->readTOC (&toc, false))
  187721. {
  187722. numTracks = 1 + toc.lastTrack - toc.firstTrack;
  187723. for (int i = 0; i <= numTracks; ++i)
  187724. {
  187725. trackStarts[i] = getAddressOf (&toc.tracks[i]);
  187726. audioTracks[i] = ((toc.tracks[i].ADR & 4) == 0);
  187727. }
  187728. }
  187729. else
  187730. {
  187731. numTracks = 0;
  187732. }
  187733. }
  187734. bool AudioCDReader::isTrackAudio (int trackNum) const
  187735. {
  187736. return (trackNum >= 0 && trackNum <= numTracks) ? audioTracks [trackNum]
  187737. : false;
  187738. }
  187739. void AudioCDReader::enableIndexScanning (bool b)
  187740. {
  187741. indexingEnabled = b;
  187742. }
  187743. int AudioCDReader::getLastIndex() const
  187744. {
  187745. return lastIndex;
  187746. }
  187747. const int framesPerIndexRead = 4;
  187748. int AudioCDReader::getIndexAt (int samplePos)
  187749. {
  187750. CDDeviceWrapper* const device = (CDDeviceWrapper*) handle;
  187751. const int frameNeeded = samplePos / samplesPerFrame;
  187752. device->overlapBuffer->dataLength = 0;
  187753. device->overlapBuffer->startFrame = 0;
  187754. device->overlapBuffer->numFrames = 0;
  187755. device->jitter = false;
  187756. firstFrameInBuffer = 0;
  187757. lastIndex = 0;
  187758. CDReadBuffer readBuffer (4 + framesPerIndexRead);
  187759. readBuffer.wantsIndex = true;
  187760. int i;
  187761. for (i = 5; --i >= 0;)
  187762. {
  187763. readBuffer.startFrame = frameNeeded;
  187764. readBuffer.numFrames = framesPerIndexRead;
  187765. if (device->cdH->readAudio (&readBuffer, (false) ? device->overlapBuffer : 0))
  187766. break;
  187767. }
  187768. if (i >= 0)
  187769. return readBuffer.index;
  187770. return -1;
  187771. }
  187772. const Array <int> AudioCDReader::findIndexesInTrack (const int trackNumber)
  187773. {
  187774. Array <int> indexes;
  187775. const int trackStart = getPositionOfTrackStart (trackNumber);
  187776. const int trackEnd = getPositionOfTrackStart (trackNumber + 1);
  187777. bool needToScan = true;
  187778. if (trackEnd - trackStart > 20 * 44100)
  187779. {
  187780. // check the end of the track for indexes before scanning the whole thing
  187781. needToScan = false;
  187782. int pos = jmax (trackStart, trackEnd - 44100 * 5);
  187783. bool seenAnIndex = false;
  187784. while (pos <= trackEnd - samplesPerFrame)
  187785. {
  187786. const int index = getIndexAt (pos);
  187787. if (index == 0)
  187788. {
  187789. // lead-out, so skip back a bit if we've not found any indexes yet..
  187790. if (seenAnIndex)
  187791. break;
  187792. pos -= 44100 * 5;
  187793. if (pos < trackStart)
  187794. break;
  187795. }
  187796. else
  187797. {
  187798. if (index > 0)
  187799. seenAnIndex = true;
  187800. if (index > 1)
  187801. {
  187802. needToScan = true;
  187803. break;
  187804. }
  187805. pos += samplesPerFrame * framesPerIndexRead;
  187806. }
  187807. }
  187808. }
  187809. if (needToScan)
  187810. {
  187811. CDDeviceWrapper* const device = (CDDeviceWrapper*) handle;
  187812. int pos = trackStart;
  187813. int last = -1;
  187814. while (pos < trackEnd - samplesPerFrame * 10)
  187815. {
  187816. const int frameNeeded = pos / samplesPerFrame;
  187817. device->overlapBuffer->dataLength = 0;
  187818. device->overlapBuffer->startFrame = 0;
  187819. device->overlapBuffer->numFrames = 0;
  187820. device->jitter = false;
  187821. firstFrameInBuffer = 0;
  187822. CDReadBuffer readBuffer (4);
  187823. readBuffer.wantsIndex = true;
  187824. int i;
  187825. for (i = 5; --i >= 0;)
  187826. {
  187827. readBuffer.startFrame = frameNeeded;
  187828. readBuffer.numFrames = framesPerIndexRead;
  187829. if (device->cdH->readAudio (&readBuffer, (false) ? device->overlapBuffer : 0))
  187830. break;
  187831. }
  187832. if (i < 0)
  187833. break;
  187834. if (readBuffer.index > last && readBuffer.index > 1)
  187835. {
  187836. last = readBuffer.index;
  187837. indexes.add (pos);
  187838. }
  187839. pos += samplesPerFrame * framesPerIndexRead;
  187840. }
  187841. indexes.removeValue (trackStart);
  187842. }
  187843. return indexes;
  187844. }
  187845. int AudioCDReader::getCDDBId()
  187846. {
  187847. refreshTrackLengths();
  187848. if (numTracks > 0)
  187849. {
  187850. TOC toc;
  187851. zerostruct (toc);
  187852. if (((CDDeviceWrapper*) handle)->cdH->readTOC (&toc, true))
  187853. {
  187854. int n = 0;
  187855. for (int i = numTracks; --i >= 0;)
  187856. {
  187857. int j = getMSFAddressOf (&toc.tracks[i]);
  187858. while (j > 0)
  187859. {
  187860. n += (j % 10);
  187861. j /= 10;
  187862. }
  187863. }
  187864. if (n != 0)
  187865. {
  187866. const int t = getMSFAddressOf (&toc.tracks[numTracks])
  187867. - getMSFAddressOf (&toc.tracks[0]);
  187868. return ((n % 0xff) << 24) | (t << 8) | numTracks;
  187869. }
  187870. }
  187871. }
  187872. return 0;
  187873. }
  187874. void AudioCDReader::ejectDisk()
  187875. {
  187876. ((CDDeviceWrapper*) handle)->cdH->openDrawer (true);
  187877. }
  187878. #endif
  187879. #if JUCE_USE_CDBURNER
  187880. static IDiscRecorder* enumCDBurners (StringArray* list, int indexToOpen, IDiscMaster** master)
  187881. {
  187882. CoInitialize (0);
  187883. IDiscMaster* dm;
  187884. IDiscRecorder* result = 0;
  187885. if (SUCCEEDED (CoCreateInstance (CLSID_MSDiscMasterObj, 0,
  187886. CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER,
  187887. IID_IDiscMaster,
  187888. (void**) &dm)))
  187889. {
  187890. if (SUCCEEDED (dm->Open()))
  187891. {
  187892. IEnumDiscRecorders* drEnum = 0;
  187893. if (SUCCEEDED (dm->EnumDiscRecorders (&drEnum)))
  187894. {
  187895. IDiscRecorder* dr = 0;
  187896. DWORD dummy;
  187897. int index = 0;
  187898. while (drEnum->Next (1, &dr, &dummy) == S_OK)
  187899. {
  187900. if (indexToOpen == index)
  187901. {
  187902. result = dr;
  187903. break;
  187904. }
  187905. else if (list != 0)
  187906. {
  187907. BSTR path;
  187908. if (SUCCEEDED (dr->GetPath (&path)))
  187909. list->add ((const WCHAR*) path);
  187910. }
  187911. ++index;
  187912. dr->Release();
  187913. }
  187914. drEnum->Release();
  187915. }
  187916. if (master == 0)
  187917. dm->Close();
  187918. }
  187919. if (master != 0)
  187920. *master = dm;
  187921. else
  187922. dm->Release();
  187923. }
  187924. return result;
  187925. }
  187926. const StringArray AudioCDBurner::findAvailableDevices()
  187927. {
  187928. StringArray devs;
  187929. enumCDBurners (&devs, -1, 0);
  187930. return devs;
  187931. }
  187932. AudioCDBurner* AudioCDBurner::openDevice (const int deviceIndex)
  187933. {
  187934. AudioCDBurner* b = new AudioCDBurner (deviceIndex);
  187935. if (b->internal == 0)
  187936. deleteAndZero (b);
  187937. return b;
  187938. }
  187939. class CDBurnerInfo : public IDiscMasterProgressEvents
  187940. {
  187941. public:
  187942. CDBurnerInfo()
  187943. : refCount (1),
  187944. progress (0),
  187945. shouldCancel (false),
  187946. listener (0)
  187947. {
  187948. }
  187949. ~CDBurnerInfo()
  187950. {
  187951. }
  187952. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  187953. {
  187954. if (result == 0)
  187955. return E_POINTER;
  187956. if (id == IID_IUnknown || id == IID_IDiscMasterProgressEvents)
  187957. {
  187958. AddRef();
  187959. *result = this;
  187960. return S_OK;
  187961. }
  187962. *result = 0;
  187963. return E_NOINTERFACE;
  187964. }
  187965. ULONG __stdcall AddRef() { return ++refCount; }
  187966. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  187967. HRESULT __stdcall QueryCancel (boolean* pbCancel)
  187968. {
  187969. if (listener != 0 && ! shouldCancel)
  187970. shouldCancel = listener->audioCDBurnProgress (progress);
  187971. *pbCancel = shouldCancel;
  187972. return S_OK;
  187973. }
  187974. HRESULT __stdcall NotifyBlockProgress (long nCompleted, long nTotal)
  187975. {
  187976. progress = nCompleted / (float) nTotal;
  187977. shouldCancel = listener != 0 && listener->audioCDBurnProgress (progress);
  187978. return E_NOTIMPL;
  187979. }
  187980. HRESULT __stdcall NotifyPnPActivity (void) { return E_NOTIMPL; }
  187981. HRESULT __stdcall NotifyAddProgress (long /*nCompletedSteps*/, long /*nTotalSteps*/) { return E_NOTIMPL; }
  187982. HRESULT __stdcall NotifyTrackProgress (long /*nCurrentTrack*/, long /*nTotalTracks*/) { return E_NOTIMPL; }
  187983. HRESULT __stdcall NotifyPreparingBurn (long /*nEstimatedSeconds*/) { return E_NOTIMPL; }
  187984. HRESULT __stdcall NotifyClosingDisc (long /*nEstimatedSeconds*/) { return E_NOTIMPL; }
  187985. HRESULT __stdcall NotifyBurnComplete (HRESULT /*status*/) { return E_NOTIMPL; }
  187986. HRESULT __stdcall NotifyEraseComplete (HRESULT /*status*/) { return E_NOTIMPL; }
  187987. IDiscMaster* discMaster;
  187988. IDiscRecorder* discRecorder;
  187989. IRedbookDiscMaster* redbook;
  187990. AudioCDBurner::BurnProgressListener* listener;
  187991. float progress;
  187992. bool shouldCancel;
  187993. private:
  187994. int refCount;
  187995. };
  187996. AudioCDBurner::AudioCDBurner (const int deviceIndex)
  187997. : internal (0)
  187998. {
  187999. IDiscMaster* discMaster;
  188000. IDiscRecorder* dr = enumCDBurners (0, deviceIndex, &discMaster);
  188001. if (dr != 0)
  188002. {
  188003. IRedbookDiscMaster* redbook;
  188004. HRESULT hr = discMaster->SetActiveDiscMasterFormat (IID_IRedbookDiscMaster, (void**) &redbook);
  188005. hr = discMaster->SetActiveDiscRecorder (dr);
  188006. CDBurnerInfo* const info = new CDBurnerInfo();
  188007. internal = info;
  188008. info->discMaster = discMaster;
  188009. info->discRecorder = dr;
  188010. info->redbook = redbook;
  188011. }
  188012. }
  188013. AudioCDBurner::~AudioCDBurner()
  188014. {
  188015. CDBurnerInfo* const info = (CDBurnerInfo*) internal;
  188016. if (info != 0)
  188017. {
  188018. info->discRecorder->Close();
  188019. info->redbook->Release();
  188020. info->discRecorder->Release();
  188021. info->discMaster->Release();
  188022. info->Release();
  188023. }
  188024. }
  188025. bool AudioCDBurner::isDiskPresent() const
  188026. {
  188027. CDBurnerInfo* const info = (CDBurnerInfo*) internal;
  188028. HRESULT hr = info->discRecorder->OpenExclusive();
  188029. long type, flags;
  188030. hr = info->discRecorder->QueryMediaType (&type, &flags);
  188031. info->discRecorder->Close();
  188032. return hr == S_OK && type != 0 && (flags & MEDIA_WRITABLE) != 0;
  188033. }
  188034. int AudioCDBurner::getNumAvailableAudioBlocks() const
  188035. {
  188036. CDBurnerInfo* const info = (CDBurnerInfo*) internal;
  188037. long blocksFree = 0;
  188038. info->redbook->GetAvailableAudioTrackBlocks (&blocksFree);
  188039. return blocksFree;
  188040. }
  188041. const String AudioCDBurner::burn (AudioCDBurner::BurnProgressListener* listener,
  188042. const bool ejectDiscAfterwards,
  188043. const bool performFakeBurnForTesting)
  188044. {
  188045. CDBurnerInfo* const info = (CDBurnerInfo*) internal;
  188046. info->listener = listener;
  188047. info->progress = 0;
  188048. info->shouldCancel = false;
  188049. UINT_PTR cookie;
  188050. HRESULT hr = info->discMaster->ProgressAdvise (info, &cookie);
  188051. hr = info->discMaster->RecordDisc (performFakeBurnForTesting,
  188052. ejectDiscAfterwards);
  188053. String error;
  188054. if (hr != S_OK)
  188055. {
  188056. const char* e = "Couldn't open or write to the CD device";
  188057. if (hr == IMAPI_E_USERABORT)
  188058. e = "User cancelled the write operation";
  188059. else if (hr == IMAPI_E_MEDIUM_NOTPRESENT || hr == IMAPI_E_TRACKOPEN)
  188060. e = "No Disk present";
  188061. error = e;
  188062. }
  188063. info->discMaster->ProgressUnadvise (cookie);
  188064. info->listener = 0;
  188065. return error;
  188066. }
  188067. bool AudioCDBurner::addAudioTrack (AudioSource* source, int numSamples)
  188068. {
  188069. if (source == 0)
  188070. return false;
  188071. CDBurnerInfo* const info = (CDBurnerInfo*) internal;
  188072. long bytesPerBlock;
  188073. HRESULT hr = info->redbook->GetAudioBlockSize (&bytesPerBlock);
  188074. const int samplesPerBlock = bytesPerBlock / 4;
  188075. bool ok = true;
  188076. hr = info->redbook->CreateAudioTrack ((long) numSamples / (bytesPerBlock * 4));
  188077. HeapBlock <byte> buffer (bytesPerBlock);
  188078. AudioSampleBuffer sourceBuffer (2, samplesPerBlock);
  188079. int samplesDone = 0;
  188080. source->prepareToPlay (samplesPerBlock, 44100.0);
  188081. while (ok)
  188082. {
  188083. {
  188084. AudioSourceChannelInfo info;
  188085. info.buffer = &sourceBuffer;
  188086. info.numSamples = samplesPerBlock;
  188087. info.startSample = 0;
  188088. sourceBuffer.clear();
  188089. source->getNextAudioBlock (info);
  188090. }
  188091. zeromem (buffer, bytesPerBlock);
  188092. AudioDataConverters::convertFloatToInt16LE (sourceBuffer.getSampleData (0, 0),
  188093. buffer, samplesPerBlock, 4);
  188094. AudioDataConverters::convertFloatToInt16LE (sourceBuffer.getSampleData (1, 0),
  188095. buffer + 2, samplesPerBlock, 4);
  188096. hr = info->redbook->AddAudioTrackBlocks (buffer, bytesPerBlock);
  188097. if (hr != S_OK)
  188098. ok = false;
  188099. samplesDone += samplesPerBlock;
  188100. if (samplesDone >= numSamples)
  188101. break;
  188102. }
  188103. hr = info->redbook->CloseAudioTrack();
  188104. delete source;
  188105. return ok && hr == S_OK;
  188106. }
  188107. #endif
  188108. #endif
  188109. /*** End of inlined file: juce_win32_AudioCDReader.cpp ***/
  188110. /*** Start of inlined file: juce_win32_Midi.cpp ***/
  188111. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  188112. // compiled on its own).
  188113. #if JUCE_INCLUDED_FILE
  188114. static const int midiBufferSize = 1024 * 10;
  188115. static const int numInHeaders = 32;
  188116. static const int inBufferSize = 256;
  188117. static Array <void*, CriticalSection> activeMidiThreads;
  188118. using ::free;
  188119. class MidiInThread : public Thread
  188120. {
  188121. public:
  188122. MidiInThread (MidiInput* const input_,
  188123. MidiInputCallback* const callback_)
  188124. : Thread ("Juce Midi"),
  188125. hIn (0),
  188126. input (input_),
  188127. callback (callback_),
  188128. isStarted (false),
  188129. startTime (0),
  188130. pendingLength(0)
  188131. {
  188132. for (int i = numInHeaders; --i >= 0;)
  188133. {
  188134. zeromem (&hdr[i], sizeof (MIDIHDR));
  188135. hdr[i].lpData = inData[i];
  188136. hdr[i].dwBufferLength = inBufferSize;
  188137. }
  188138. };
  188139. ~MidiInThread()
  188140. {
  188141. stop();
  188142. if (hIn != 0)
  188143. {
  188144. int count = 5;
  188145. while (--count >= 0)
  188146. {
  188147. if (midiInClose (hIn) == MMSYSERR_NOERROR)
  188148. break;
  188149. Sleep (20);
  188150. }
  188151. }
  188152. }
  188153. void handle (const uint32 message, const uint32 timeStamp) throw()
  188154. {
  188155. const int byte = message & 0xff;
  188156. if (byte < 0x80)
  188157. return;
  188158. const int numBytes = MidiMessage::getMessageLengthFromFirstByte ((uint8) byte);
  188159. const double time = timeStampToTime (timeStamp);
  188160. lock.enter();
  188161. if (pendingLength < midiBufferSize - 12)
  188162. {
  188163. char* const p = pending + pendingLength;
  188164. *(double*) p = time;
  188165. *(uint32*) (p + 8) = numBytes;
  188166. *(uint32*) (p + 12) = message;
  188167. pendingLength += 12 + numBytes;
  188168. }
  188169. else
  188170. {
  188171. jassertfalse // midi buffer overflow! You might need to increase the size..
  188172. }
  188173. lock.exit();
  188174. notify();
  188175. }
  188176. void handleSysEx (MIDIHDR* const hdr, const uint32 timeStamp) throw()
  188177. {
  188178. const int num = hdr->dwBytesRecorded;
  188179. if (num > 0)
  188180. {
  188181. const double time = timeStampToTime (timeStamp);
  188182. lock.enter();
  188183. if (pendingLength < midiBufferSize - (8 + num))
  188184. {
  188185. char* const p = pending + pendingLength;
  188186. *(double*) p = time;
  188187. *(uint32*) (p + 8) = num;
  188188. memcpy (p + 12, hdr->lpData, num);
  188189. pendingLength += 12 + num;
  188190. }
  188191. else
  188192. {
  188193. jassertfalse // midi buffer overflow! You might need to increase the size..
  188194. }
  188195. lock.exit();
  188196. notify();
  188197. }
  188198. }
  188199. void writeBlock (const int i) throw()
  188200. {
  188201. hdr[i].dwBytesRecorded = 0;
  188202. MMRESULT res = midiInPrepareHeader (hIn, &hdr[i], sizeof (MIDIHDR));
  188203. jassert (res == MMSYSERR_NOERROR);
  188204. res = midiInAddBuffer (hIn, &hdr[i], sizeof (MIDIHDR));
  188205. jassert (res == MMSYSERR_NOERROR);
  188206. }
  188207. void run()
  188208. {
  188209. MemoryBlock pendingCopy (64);
  188210. while (! threadShouldExit())
  188211. {
  188212. for (int i = 0; i < numInHeaders; ++i)
  188213. {
  188214. if ((hdr[i].dwFlags & WHDR_DONE) != 0)
  188215. {
  188216. MMRESULT res = midiInUnprepareHeader (hIn, &hdr[i], sizeof (MIDIHDR));
  188217. (void) res;
  188218. jassert (res == MMSYSERR_NOERROR);
  188219. writeBlock (i);
  188220. }
  188221. }
  188222. lock.enter();
  188223. int len = pendingLength;
  188224. if (len > 0)
  188225. {
  188226. pendingCopy.ensureSize (len);
  188227. pendingCopy.copyFrom (pending, 0, len);
  188228. pendingLength = 0;
  188229. }
  188230. lock.exit();
  188231. //xxx needs to figure out if blocks are broken up or not
  188232. if (len == 0)
  188233. {
  188234. wait (500);
  188235. }
  188236. else
  188237. {
  188238. const char* p = (const char*) pendingCopy.getData();
  188239. while (len > 0)
  188240. {
  188241. const double time = *(const double*) p;
  188242. const int messageLen = *(const int*) (p + 8);
  188243. const MidiMessage message ((const uint8*) (p + 12), messageLen, time);
  188244. callback->handleIncomingMidiMessage (input, message);
  188245. p += 12 + messageLen;
  188246. len -= 12 + messageLen;
  188247. }
  188248. }
  188249. }
  188250. }
  188251. void start() throw()
  188252. {
  188253. jassert (hIn != 0);
  188254. if (hIn != 0 && ! isStarted)
  188255. {
  188256. stop();
  188257. activeMidiThreads.addIfNotAlreadyThere (this);
  188258. int i;
  188259. for (i = 0; i < numInHeaders; ++i)
  188260. writeBlock (i);
  188261. startTime = Time::getMillisecondCounter();
  188262. MMRESULT res = midiInStart (hIn);
  188263. jassert (res == MMSYSERR_NOERROR);
  188264. if (res == MMSYSERR_NOERROR)
  188265. {
  188266. isStarted = true;
  188267. pendingLength = 0;
  188268. startThread (6);
  188269. }
  188270. }
  188271. }
  188272. void stop() throw()
  188273. {
  188274. if (isStarted)
  188275. {
  188276. stopThread (5000);
  188277. midiInReset (hIn);
  188278. midiInStop (hIn);
  188279. activeMidiThreads.removeValue (this);
  188280. lock.enter();
  188281. lock.exit();
  188282. for (int i = numInHeaders; --i >= 0;)
  188283. {
  188284. if ((hdr[i].dwFlags & WHDR_DONE) != 0)
  188285. {
  188286. int c = 10;
  188287. while (--c >= 0 && midiInUnprepareHeader (hIn, &hdr[i], sizeof (MIDIHDR)) == MIDIERR_STILLPLAYING)
  188288. Sleep (20);
  188289. jassert (c >= 0);
  188290. }
  188291. }
  188292. isStarted = false;
  188293. pendingLength = 0;
  188294. }
  188295. }
  188296. juce_UseDebuggingNewOperator
  188297. HMIDIIN hIn;
  188298. private:
  188299. MidiInput* input;
  188300. MidiInputCallback* callback;
  188301. bool isStarted;
  188302. uint32 startTime;
  188303. CriticalSection lock;
  188304. MIDIHDR hdr [numInHeaders];
  188305. char inData [numInHeaders] [inBufferSize];
  188306. int pendingLength;
  188307. char pending [midiBufferSize];
  188308. double timeStampToTime (uint32 timeStamp) throw()
  188309. {
  188310. timeStamp += startTime;
  188311. const uint32 now = Time::getMillisecondCounter();
  188312. if (timeStamp > now)
  188313. {
  188314. if (timeStamp > now + 2)
  188315. --startTime;
  188316. timeStamp = now;
  188317. }
  188318. return 0.001 * timeStamp;
  188319. }
  188320. MidiInThread (const MidiInThread&);
  188321. const MidiInThread& operator= (const MidiInThread&);
  188322. };
  188323. static void CALLBACK midiInCallback (HMIDIIN,
  188324. UINT uMsg,
  188325. DWORD_PTR dwInstance,
  188326. DWORD_PTR midiMessage,
  188327. DWORD_PTR timeStamp)
  188328. {
  188329. MidiInThread* const thread = (MidiInThread*) dwInstance;
  188330. if (thread != 0 && activeMidiThreads.contains (thread))
  188331. {
  188332. if (uMsg == MIM_DATA)
  188333. thread->handle ((uint32) midiMessage, (uint32) timeStamp);
  188334. else if (uMsg == MIM_LONGDATA)
  188335. thread->handleSysEx ((MIDIHDR*) midiMessage, (uint32) timeStamp);
  188336. }
  188337. }
  188338. const StringArray MidiInput::getDevices()
  188339. {
  188340. StringArray s;
  188341. const int num = midiInGetNumDevs();
  188342. for (int i = 0; i < num; ++i)
  188343. {
  188344. MIDIINCAPS mc;
  188345. zerostruct (mc);
  188346. if (midiInGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  188347. s.add (String (mc.szPname, sizeof (mc.szPname)));
  188348. }
  188349. return s;
  188350. }
  188351. int MidiInput::getDefaultDeviceIndex()
  188352. {
  188353. return 0;
  188354. }
  188355. MidiInput* MidiInput::openDevice (const int index, MidiInputCallback* const callback)
  188356. {
  188357. if (callback == 0)
  188358. return 0;
  188359. UINT deviceId = MIDI_MAPPER;
  188360. int n = 0;
  188361. String name;
  188362. const int num = midiInGetNumDevs();
  188363. for (int i = 0; i < num; ++i)
  188364. {
  188365. MIDIINCAPS mc;
  188366. zerostruct (mc);
  188367. if (midiInGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  188368. {
  188369. if (index == n)
  188370. {
  188371. deviceId = i;
  188372. name = String (mc.szPname, sizeof (mc.szPname));
  188373. break;
  188374. }
  188375. ++n;
  188376. }
  188377. }
  188378. ScopedPointer <MidiInput> in (new MidiInput (name));
  188379. ScopedPointer <MidiInThread> thread (new MidiInThread (in, callback));
  188380. HMIDIIN h;
  188381. HRESULT err = midiInOpen (&h, deviceId,
  188382. (DWORD_PTR) &midiInCallback,
  188383. (DWORD_PTR) (MidiInThread*) thread,
  188384. CALLBACK_FUNCTION);
  188385. if (err == MMSYSERR_NOERROR)
  188386. {
  188387. thread->hIn = h;
  188388. in->internal = (void*) thread.release();
  188389. return in.release();
  188390. }
  188391. return 0;
  188392. }
  188393. MidiInput::MidiInput (const String& name_)
  188394. : name (name_),
  188395. internal (0)
  188396. {
  188397. }
  188398. MidiInput::~MidiInput()
  188399. {
  188400. if (internal != 0)
  188401. {
  188402. MidiInThread* const thread = (MidiInThread*) internal;
  188403. delete thread;
  188404. }
  188405. }
  188406. void MidiInput::start()
  188407. {
  188408. ((MidiInThread*) internal)->start();
  188409. }
  188410. void MidiInput::stop()
  188411. {
  188412. ((MidiInThread*) internal)->stop();
  188413. }
  188414. struct MidiOutHandle
  188415. {
  188416. int refCount;
  188417. UINT deviceId;
  188418. HMIDIOUT handle;
  188419. juce_UseDebuggingNewOperator
  188420. };
  188421. static Array <MidiOutHandle*> midiOutputHandles;
  188422. const StringArray MidiOutput::getDevices()
  188423. {
  188424. StringArray s;
  188425. const int num = midiOutGetNumDevs();
  188426. for (int i = 0; i < num; ++i)
  188427. {
  188428. MIDIOUTCAPS mc;
  188429. zerostruct (mc);
  188430. if (midiOutGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  188431. s.add (String (mc.szPname, sizeof (mc.szPname)));
  188432. }
  188433. return s;
  188434. }
  188435. int MidiOutput::getDefaultDeviceIndex()
  188436. {
  188437. const int num = midiOutGetNumDevs();
  188438. int n = 0;
  188439. for (int i = 0; i < num; ++i)
  188440. {
  188441. MIDIOUTCAPS mc;
  188442. zerostruct (mc);
  188443. if (midiOutGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  188444. {
  188445. if ((mc.wTechnology & MOD_MAPPER) != 0)
  188446. return n;
  188447. ++n;
  188448. }
  188449. }
  188450. return 0;
  188451. }
  188452. MidiOutput* MidiOutput::openDevice (int index)
  188453. {
  188454. UINT deviceId = MIDI_MAPPER;
  188455. const int num = midiOutGetNumDevs();
  188456. int i, n = 0;
  188457. for (i = 0; i < num; ++i)
  188458. {
  188459. MIDIOUTCAPS mc;
  188460. zerostruct (mc);
  188461. if (midiOutGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  188462. {
  188463. // use the microsoft sw synth as a default - best not to allow deviceId
  188464. // to be MIDI_MAPPER, or else device sharing breaks
  188465. if (String (mc.szPname, sizeof (mc.szPname)).containsIgnoreCase (T("microsoft")))
  188466. deviceId = i;
  188467. if (index == n)
  188468. {
  188469. deviceId = i;
  188470. break;
  188471. }
  188472. ++n;
  188473. }
  188474. }
  188475. for (i = midiOutputHandles.size(); --i >= 0;)
  188476. {
  188477. MidiOutHandle* const han = midiOutputHandles.getUnchecked(i);
  188478. if (han != 0 && han->deviceId == deviceId)
  188479. {
  188480. han->refCount++;
  188481. MidiOutput* const out = new MidiOutput();
  188482. out->internal = (void*) han;
  188483. return out;
  188484. }
  188485. }
  188486. for (i = 4; --i >= 0;)
  188487. {
  188488. HMIDIOUT h = 0;
  188489. MMRESULT res = midiOutOpen (&h, deviceId, 0, 0, CALLBACK_NULL);
  188490. if (res == MMSYSERR_NOERROR)
  188491. {
  188492. MidiOutHandle* const han = new MidiOutHandle();
  188493. han->deviceId = deviceId;
  188494. han->refCount = 1;
  188495. han->handle = h;
  188496. midiOutputHandles.add (han);
  188497. MidiOutput* const out = new MidiOutput();
  188498. out->internal = (void*) han;
  188499. return out;
  188500. }
  188501. else if (res == MMSYSERR_ALLOCATED)
  188502. {
  188503. Sleep (100);
  188504. }
  188505. else
  188506. {
  188507. break;
  188508. }
  188509. }
  188510. return 0;
  188511. }
  188512. MidiOutput::~MidiOutput()
  188513. {
  188514. MidiOutHandle* const h = (MidiOutHandle*) internal;
  188515. if (midiOutputHandles.contains (h) && --(h->refCount) == 0)
  188516. {
  188517. midiOutClose (h->handle);
  188518. midiOutputHandles.removeValue (h);
  188519. delete h;
  188520. }
  188521. }
  188522. void MidiOutput::reset()
  188523. {
  188524. const MidiOutHandle* const h = (MidiOutHandle*) internal;
  188525. midiOutReset (h->handle);
  188526. }
  188527. bool MidiOutput::getVolume (float& leftVol,
  188528. float& rightVol)
  188529. {
  188530. const MidiOutHandle* const handle = (const MidiOutHandle*) internal;
  188531. DWORD n;
  188532. if (midiOutGetVolume (handle->handle, &n) == MMSYSERR_NOERROR)
  188533. {
  188534. const unsigned short* const nn = (const unsigned short*) &n;
  188535. rightVol = nn[0] / (float) 0xffff;
  188536. leftVol = nn[1] / (float) 0xffff;
  188537. return true;
  188538. }
  188539. else
  188540. {
  188541. rightVol = leftVol = 1.0f;
  188542. return false;
  188543. }
  188544. }
  188545. void MidiOutput::setVolume (float leftVol,
  188546. float rightVol)
  188547. {
  188548. const MidiOutHandle* const handle = (MidiOutHandle*) internal;
  188549. DWORD n;
  188550. unsigned short* const nn = (unsigned short*) &n;
  188551. nn[0] = (unsigned short) jlimit (0, 0xffff, (int)(rightVol * 0xffff));
  188552. nn[1] = (unsigned short) jlimit (0, 0xffff, (int)(leftVol * 0xffff));
  188553. midiOutSetVolume (handle->handle, n);
  188554. }
  188555. void MidiOutput::sendMessageNow (const MidiMessage& message)
  188556. {
  188557. const MidiOutHandle* const handle = (const MidiOutHandle*) internal;
  188558. if (message.getRawDataSize() > 3
  188559. || message.isSysEx())
  188560. {
  188561. MIDIHDR h;
  188562. zerostruct (h);
  188563. h.lpData = (char*) message.getRawData();
  188564. h.dwBufferLength = message.getRawDataSize();
  188565. h.dwBytesRecorded = message.getRawDataSize();
  188566. if (midiOutPrepareHeader (handle->handle, &h, sizeof (MIDIHDR)) == MMSYSERR_NOERROR)
  188567. {
  188568. MMRESULT res = midiOutLongMsg (handle->handle, &h, sizeof (MIDIHDR));
  188569. if (res == MMSYSERR_NOERROR)
  188570. {
  188571. while ((h.dwFlags & MHDR_DONE) == 0)
  188572. Sleep (1);
  188573. int count = 500; // 1 sec timeout
  188574. while (--count >= 0)
  188575. {
  188576. res = midiOutUnprepareHeader (handle->handle, &h, sizeof (MIDIHDR));
  188577. if (res == MIDIERR_STILLPLAYING)
  188578. Sleep (2);
  188579. else
  188580. break;
  188581. }
  188582. }
  188583. }
  188584. }
  188585. else
  188586. {
  188587. midiOutShortMsg (handle->handle,
  188588. *(unsigned int*) message.getRawData());
  188589. }
  188590. }
  188591. #endif
  188592. /*** End of inlined file: juce_win32_Midi.cpp ***/
  188593. /*** Start of inlined file: juce_win32_ASIO.cpp ***/
  188594. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  188595. // compiled on its own).
  188596. #if JUCE_INCLUDED_FILE && JUCE_ASIO
  188597. #undef WINDOWS
  188598. // #define ASIO_DEBUGGING
  188599. #ifdef ASIO_DEBUGGING
  188600. #define log(a) { Logger::writeToLog (a); DBG (a) }
  188601. #else
  188602. #define log(a) {}
  188603. #endif
  188604. #ifdef ASIO_DEBUGGING
  188605. static void logError (const String& context, long error)
  188606. {
  188607. String err ("unknown error");
  188608. if (error == ASE_NotPresent)
  188609. err = "Not Present";
  188610. else if (error == ASE_HWMalfunction)
  188611. err = "Hardware Malfunction";
  188612. else if (error == ASE_InvalidParameter)
  188613. err = "Invalid Parameter";
  188614. else if (error == ASE_InvalidMode)
  188615. err = "Invalid Mode";
  188616. else if (error == ASE_SPNotAdvancing)
  188617. err = "Sample position not advancing";
  188618. else if (error == ASE_NoClock)
  188619. err = "No Clock";
  188620. else if (error == ASE_NoMemory)
  188621. err = "Out of memory";
  188622. log (T("!!error: ") + context + T(" - ") + err);
  188623. }
  188624. #else
  188625. #define logError(a, b) {}
  188626. #endif
  188627. class ASIOAudioIODevice;
  188628. static ASIOAudioIODevice* volatile currentASIODev[3] = { 0, 0, 0 };
  188629. static const int maxASIOChannels = 160;
  188630. class JUCE_API ASIOAudioIODevice : public AudioIODevice,
  188631. private Timer
  188632. {
  188633. public:
  188634. Component ourWindow;
  188635. ASIOAudioIODevice (const String& name_, const CLSID classId_, const int slotNumber,
  188636. const String& optionalDllForDirectLoading_)
  188637. : AudioIODevice (name_, T("ASIO")),
  188638. asioObject (0),
  188639. classId (classId_),
  188640. optionalDllForDirectLoading (optionalDllForDirectLoading_),
  188641. currentBitDepth (16),
  188642. currentSampleRate (0),
  188643. isOpen_ (false),
  188644. isStarted (false),
  188645. postOutput (true),
  188646. insideControlPanelModalLoop (false),
  188647. shouldUsePreferredSize (false)
  188648. {
  188649. name = name_;
  188650. ourWindow.addToDesktop (0);
  188651. windowHandle = ourWindow.getWindowHandle();
  188652. jassert (currentASIODev [slotNumber] == 0);
  188653. currentASIODev [slotNumber] = this;
  188654. openDevice();
  188655. }
  188656. ~ASIOAudioIODevice()
  188657. {
  188658. for (int i = 0; i < numElementsInArray (currentASIODev); ++i)
  188659. if (currentASIODev[i] == this)
  188660. currentASIODev[i] = 0;
  188661. close();
  188662. log ("ASIO - exiting");
  188663. removeCurrentDriver();
  188664. }
  188665. void updateSampleRates()
  188666. {
  188667. // find a list of sample rates..
  188668. const double possibleSampleRates[] = { 44100.0, 48000.0, 88200.0, 96000.0, 176400.0, 192000.0 };
  188669. sampleRates.clear();
  188670. if (asioObject != 0)
  188671. {
  188672. for (int index = 0; index < numElementsInArray (possibleSampleRates); ++index)
  188673. {
  188674. const long err = asioObject->canSampleRate (possibleSampleRates[index]);
  188675. if (err == 0)
  188676. {
  188677. sampleRates.add ((int) possibleSampleRates[index]);
  188678. log (T("rate: ") + String ((int) possibleSampleRates[index]));
  188679. }
  188680. else if (err != ASE_NoClock)
  188681. {
  188682. logError (T("CanSampleRate"), err);
  188683. }
  188684. }
  188685. if (sampleRates.size() == 0)
  188686. {
  188687. double cr = 0;
  188688. const long err = asioObject->getSampleRate (&cr);
  188689. log (T("No sample rates supported - current rate: ") + String ((int) cr));
  188690. if (err == 0)
  188691. sampleRates.add ((int) cr);
  188692. }
  188693. }
  188694. }
  188695. const StringArray getOutputChannelNames()
  188696. {
  188697. return outputChannelNames;
  188698. }
  188699. const StringArray getInputChannelNames()
  188700. {
  188701. return inputChannelNames;
  188702. }
  188703. int getNumSampleRates()
  188704. {
  188705. return sampleRates.size();
  188706. }
  188707. double getSampleRate (int index)
  188708. {
  188709. return sampleRates [index];
  188710. }
  188711. int getNumBufferSizesAvailable()
  188712. {
  188713. return bufferSizes.size();
  188714. }
  188715. int getBufferSizeSamples (int index)
  188716. {
  188717. return bufferSizes [index];
  188718. }
  188719. int getDefaultBufferSize()
  188720. {
  188721. return preferredSize;
  188722. }
  188723. const String open (const BitArray& inputChannels,
  188724. const BitArray& outputChannels,
  188725. double sr,
  188726. int bufferSizeSamples)
  188727. {
  188728. close();
  188729. currentCallback = 0;
  188730. if (bufferSizeSamples <= 0)
  188731. shouldUsePreferredSize = true;
  188732. if (asioObject == 0 || ! isASIOOpen)
  188733. {
  188734. log ("Warning: device not open");
  188735. const String err (openDevice());
  188736. if (asioObject == 0 || ! isASIOOpen)
  188737. return err;
  188738. }
  188739. isStarted = false;
  188740. bufferIndex = -1;
  188741. long err = 0;
  188742. long newPreferredSize = 0;
  188743. // if the preferred size has just changed, assume it's a control panel thing and use it as the new value.
  188744. minSize = 0;
  188745. maxSize = 0;
  188746. newPreferredSize = 0;
  188747. granularity = 0;
  188748. if (asioObject->getBufferSize (&minSize, &maxSize, &newPreferredSize, &granularity) == 0)
  188749. {
  188750. if (preferredSize != 0 && newPreferredSize != 0 && newPreferredSize != preferredSize)
  188751. shouldUsePreferredSize = true;
  188752. preferredSize = newPreferredSize;
  188753. }
  188754. // unfortunate workaround for certain manufacturers whose drivers crash horribly if you make
  188755. // dynamic changes to the buffer size...
  188756. shouldUsePreferredSize = shouldUsePreferredSize
  188757. || getName().containsIgnoreCase (T("Digidesign"));
  188758. if (shouldUsePreferredSize)
  188759. {
  188760. log ("Using preferred size for buffer..");
  188761. if ((err = asioObject->getBufferSize (&minSize, &maxSize, &preferredSize, &granularity)) == 0)
  188762. {
  188763. bufferSizeSamples = preferredSize;
  188764. }
  188765. else
  188766. {
  188767. bufferSizeSamples = 1024;
  188768. logError ("GetBufferSize1", err);
  188769. }
  188770. shouldUsePreferredSize = false;
  188771. }
  188772. int sampleRate = roundDoubleToInt (sr);
  188773. currentSampleRate = sampleRate;
  188774. currentBlockSizeSamples = bufferSizeSamples;
  188775. currentChansOut.clear();
  188776. currentChansIn.clear();
  188777. zeromem (inBuffers, sizeof (inBuffers));
  188778. zeromem (outBuffers, sizeof (outBuffers));
  188779. updateSampleRates();
  188780. if (sampleRate == 0 || (sampleRates.size() > 0 && ! sampleRates.contains (sampleRate)))
  188781. sampleRate = sampleRates[0];
  188782. jassert (sampleRate != 0);
  188783. if (sampleRate == 0)
  188784. sampleRate = 44100;
  188785. long numSources = 32;
  188786. ASIOClockSource clocks[32];
  188787. zeromem (clocks, sizeof (clocks));
  188788. asioObject->getClockSources (clocks, &numSources);
  188789. bool isSourceSet = false;
  188790. // careful not to remove this loop because it does more than just logging!
  188791. int i;
  188792. for (i = 0; i < numSources; ++i)
  188793. {
  188794. String s ("clock: ");
  188795. s += clocks[i].name;
  188796. if (clocks[i].isCurrentSource)
  188797. {
  188798. isSourceSet = true;
  188799. s << " (cur)";
  188800. }
  188801. log (s);
  188802. }
  188803. if (numSources > 1 && ! isSourceSet)
  188804. {
  188805. log ("setting clock source");
  188806. asioObject->setClockSource (clocks[0].index);
  188807. Thread::sleep (20);
  188808. }
  188809. else
  188810. {
  188811. if (numSources == 0)
  188812. {
  188813. log ("ASIO - no clock sources!");
  188814. }
  188815. }
  188816. double cr = 0;
  188817. err = asioObject->getSampleRate (&cr);
  188818. if (err == 0)
  188819. {
  188820. currentSampleRate = cr;
  188821. }
  188822. else
  188823. {
  188824. logError ("GetSampleRate", err);
  188825. currentSampleRate = 0;
  188826. }
  188827. error = String::empty;
  188828. needToReset = false;
  188829. isReSync = false;
  188830. err = 0;
  188831. bool buffersCreated = false;
  188832. if (currentSampleRate != sampleRate)
  188833. {
  188834. log (T("ASIO samplerate: ") + String (currentSampleRate) + T(" to ") + String (sampleRate));
  188835. err = asioObject->setSampleRate (sampleRate);
  188836. if (err == ASE_NoClock && numSources > 0)
  188837. {
  188838. log ("trying to set a clock source..");
  188839. Thread::sleep (10);
  188840. err = asioObject->setClockSource (clocks[0].index);
  188841. if (err != 0)
  188842. {
  188843. logError ("SetClock", err);
  188844. }
  188845. Thread::sleep (10);
  188846. err = asioObject->setSampleRate (sampleRate);
  188847. }
  188848. }
  188849. if (err == 0)
  188850. {
  188851. currentSampleRate = sampleRate;
  188852. if (needToReset)
  188853. {
  188854. if (isReSync)
  188855. {
  188856. log ("Resync request");
  188857. }
  188858. log ("! Resetting ASIO after sample rate change");
  188859. removeCurrentDriver();
  188860. loadDriver();
  188861. const String error (initDriver());
  188862. if (error.isNotEmpty())
  188863. {
  188864. log (T("ASIOInit: ") + error);
  188865. }
  188866. needToReset = false;
  188867. isReSync = false;
  188868. }
  188869. numActiveInputChans = 0;
  188870. numActiveOutputChans = 0;
  188871. ASIOBufferInfo* info = bufferInfos;
  188872. int i;
  188873. for (i = 0; i < totalNumInputChans; ++i)
  188874. {
  188875. if (inputChannels[i])
  188876. {
  188877. currentChansIn.setBit (i);
  188878. info->isInput = 1;
  188879. info->channelNum = i;
  188880. info->buffers[0] = info->buffers[1] = 0;
  188881. ++info;
  188882. ++numActiveInputChans;
  188883. }
  188884. }
  188885. for (i = 0; i < totalNumOutputChans; ++i)
  188886. {
  188887. if (outputChannels[i])
  188888. {
  188889. currentChansOut.setBit (i);
  188890. info->isInput = 0;
  188891. info->channelNum = i;
  188892. info->buffers[0] = info->buffers[1] = 0;
  188893. ++info;
  188894. ++numActiveOutputChans;
  188895. }
  188896. }
  188897. const int totalBuffers = numActiveInputChans + numActiveOutputChans;
  188898. callbacks.sampleRateDidChange = &sampleRateChangedCallback;
  188899. if (currentASIODev[0] == this)
  188900. {
  188901. callbacks.bufferSwitch = &bufferSwitchCallback0;
  188902. callbacks.asioMessage = &asioMessagesCallback0;
  188903. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback0;
  188904. }
  188905. else if (currentASIODev[1] == this)
  188906. {
  188907. callbacks.bufferSwitch = &bufferSwitchCallback1;
  188908. callbacks.asioMessage = &asioMessagesCallback1;
  188909. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback1;
  188910. }
  188911. else if (currentASIODev[2] == this)
  188912. {
  188913. callbacks.bufferSwitch = &bufferSwitchCallback2;
  188914. callbacks.asioMessage = &asioMessagesCallback2;
  188915. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback2;
  188916. }
  188917. else
  188918. {
  188919. jassertfalse
  188920. }
  188921. log ("disposing buffers");
  188922. err = asioObject->disposeBuffers();
  188923. log (T("creating buffers: ") + String (totalBuffers) + T(", ") + String (currentBlockSizeSamples));
  188924. err = asioObject->createBuffers (bufferInfos,
  188925. totalBuffers,
  188926. currentBlockSizeSamples,
  188927. &callbacks);
  188928. if (err != 0)
  188929. {
  188930. currentBlockSizeSamples = preferredSize;
  188931. logError ("create buffers 2", err);
  188932. asioObject->disposeBuffers();
  188933. err = asioObject->createBuffers (bufferInfos,
  188934. totalBuffers,
  188935. currentBlockSizeSamples,
  188936. &callbacks);
  188937. }
  188938. if (err == 0)
  188939. {
  188940. buffersCreated = true;
  188941. tempBuffer.calloc (totalBuffers * currentBlockSizeSamples + 32);
  188942. int n = 0;
  188943. Array <int> types;
  188944. currentBitDepth = 16;
  188945. for (i = 0; i < jmin ((int) totalNumInputChans, maxASIOChannels); ++i)
  188946. {
  188947. if (inputChannels[i])
  188948. {
  188949. inBuffers[n] = tempBuffer + (currentBlockSizeSamples * n);
  188950. ASIOChannelInfo channelInfo;
  188951. zerostruct (channelInfo);
  188952. channelInfo.channel = i;
  188953. channelInfo.isInput = 1;
  188954. asioObject->getChannelInfo (&channelInfo);
  188955. types.addIfNotAlreadyThere (channelInfo.type);
  188956. typeToFormatParameters (channelInfo.type,
  188957. inputChannelBitDepths[n],
  188958. inputChannelBytesPerSample[n],
  188959. inputChannelIsFloat[n],
  188960. inputChannelLittleEndian[n]);
  188961. currentBitDepth = jmax (currentBitDepth, inputChannelBitDepths[n]);
  188962. ++n;
  188963. }
  188964. }
  188965. jassert (numActiveInputChans == n);
  188966. n = 0;
  188967. for (i = 0; i < jmin ((int) totalNumOutputChans, maxASIOChannels); ++i)
  188968. {
  188969. if (outputChannels[i])
  188970. {
  188971. outBuffers[n] = tempBuffer + (currentBlockSizeSamples * (numActiveInputChans + n));
  188972. ASIOChannelInfo channelInfo;
  188973. zerostruct (channelInfo);
  188974. channelInfo.channel = i;
  188975. channelInfo.isInput = 0;
  188976. asioObject->getChannelInfo (&channelInfo);
  188977. types.addIfNotAlreadyThere (channelInfo.type);
  188978. typeToFormatParameters (channelInfo.type,
  188979. outputChannelBitDepths[n],
  188980. outputChannelBytesPerSample[n],
  188981. outputChannelIsFloat[n],
  188982. outputChannelLittleEndian[n]);
  188983. currentBitDepth = jmax (currentBitDepth, outputChannelBitDepths[n]);
  188984. ++n;
  188985. }
  188986. }
  188987. jassert (numActiveOutputChans == n);
  188988. for (i = types.size(); --i >= 0;)
  188989. {
  188990. log (T("channel format: ") + String (types[i]));
  188991. }
  188992. jassert (n <= totalBuffers);
  188993. for (i = 0; i < numActiveOutputChans; ++i)
  188994. {
  188995. const int size = currentBlockSizeSamples * (outputChannelBitDepths[i] >> 3);
  188996. if (bufferInfos [numActiveInputChans + i].buffers[0] == 0
  188997. || bufferInfos [numActiveInputChans + i].buffers[1] == 0)
  188998. {
  188999. log ("!! Null buffers");
  189000. }
  189001. else
  189002. {
  189003. zeromem (bufferInfos[numActiveInputChans + i].buffers[0], size);
  189004. zeromem (bufferInfos[numActiveInputChans + i].buffers[1], size);
  189005. }
  189006. }
  189007. inputLatency = outputLatency = 0;
  189008. if (asioObject->getLatencies (&inputLatency, &outputLatency) != 0)
  189009. {
  189010. log ("ASIO - no latencies");
  189011. }
  189012. else
  189013. {
  189014. log (T("ASIO latencies: ")
  189015. + String ((int) outputLatency)
  189016. + T(", ")
  189017. + String ((int) inputLatency));
  189018. }
  189019. isOpen_ = true;
  189020. log ("starting ASIO");
  189021. calledback = false;
  189022. err = asioObject->start();
  189023. if (err != 0)
  189024. {
  189025. isOpen_ = false;
  189026. log ("ASIO - stop on failure");
  189027. Thread::sleep (10);
  189028. asioObject->stop();
  189029. error = "Can't start device";
  189030. Thread::sleep (10);
  189031. }
  189032. else
  189033. {
  189034. int count = 300;
  189035. while (--count > 0 && ! calledback)
  189036. Thread::sleep (10);
  189037. isStarted = true;
  189038. if (! calledback)
  189039. {
  189040. error = "Device didn't start correctly";
  189041. log ("ASIO didn't callback - stopping..");
  189042. asioObject->stop();
  189043. }
  189044. }
  189045. }
  189046. else
  189047. {
  189048. error = "Can't create i/o buffers";
  189049. }
  189050. }
  189051. else
  189052. {
  189053. error = "Can't set sample rate: ";
  189054. error << sampleRate;
  189055. }
  189056. if (error.isNotEmpty())
  189057. {
  189058. logError (error, err);
  189059. if (asioObject != 0 && buffersCreated)
  189060. asioObject->disposeBuffers();
  189061. Thread::sleep (20);
  189062. isStarted = false;
  189063. isOpen_ = false;
  189064. close();
  189065. }
  189066. needToReset = false;
  189067. isReSync = false;
  189068. return error;
  189069. }
  189070. void close()
  189071. {
  189072. error = String::empty;
  189073. stopTimer();
  189074. stop();
  189075. if (isASIOOpen && isOpen_)
  189076. {
  189077. const ScopedLock sl (callbackLock);
  189078. isOpen_ = false;
  189079. isStarted = false;
  189080. needToReset = false;
  189081. isReSync = false;
  189082. log ("ASIO - stopping");
  189083. if (asioObject != 0)
  189084. {
  189085. Thread::sleep (20);
  189086. asioObject->stop();
  189087. Thread::sleep (10);
  189088. asioObject->disposeBuffers();
  189089. }
  189090. Thread::sleep (10);
  189091. }
  189092. }
  189093. bool isOpen()
  189094. {
  189095. return isOpen_ || insideControlPanelModalLoop;
  189096. }
  189097. int getCurrentBufferSizeSamples()
  189098. {
  189099. return currentBlockSizeSamples;
  189100. }
  189101. double getCurrentSampleRate()
  189102. {
  189103. return currentSampleRate;
  189104. }
  189105. const BitArray getActiveOutputChannels() const
  189106. {
  189107. return currentChansOut;
  189108. }
  189109. const BitArray getActiveInputChannels() const
  189110. {
  189111. return currentChansIn;
  189112. }
  189113. int getCurrentBitDepth()
  189114. {
  189115. return currentBitDepth;
  189116. }
  189117. int getOutputLatencyInSamples()
  189118. {
  189119. return outputLatency + currentBlockSizeSamples / 4;
  189120. }
  189121. int getInputLatencyInSamples()
  189122. {
  189123. return inputLatency + currentBlockSizeSamples / 4;
  189124. }
  189125. void start (AudioIODeviceCallback* callback)
  189126. {
  189127. if (callback != 0)
  189128. {
  189129. callback->audioDeviceAboutToStart (this);
  189130. const ScopedLock sl (callbackLock);
  189131. currentCallback = callback;
  189132. }
  189133. }
  189134. void stop()
  189135. {
  189136. AudioIODeviceCallback* const lastCallback = currentCallback;
  189137. {
  189138. const ScopedLock sl (callbackLock);
  189139. currentCallback = 0;
  189140. }
  189141. if (lastCallback != 0)
  189142. lastCallback->audioDeviceStopped();
  189143. }
  189144. bool isPlaying()
  189145. {
  189146. return isASIOOpen && (currentCallback != 0);
  189147. }
  189148. const String getLastError()
  189149. {
  189150. return error;
  189151. }
  189152. bool hasControlPanel() const
  189153. {
  189154. return true;
  189155. }
  189156. bool showControlPanel()
  189157. {
  189158. log ("ASIO - showing control panel");
  189159. Component modalWindow (String::empty);
  189160. modalWindow.setOpaque (true);
  189161. modalWindow.addToDesktop (0);
  189162. modalWindow.enterModalState();
  189163. bool done = false;
  189164. JUCE_TRY
  189165. {
  189166. // are there are devices that need to be closed before showing their control panel?
  189167. // close();
  189168. insideControlPanelModalLoop = true;
  189169. const uint32 started = Time::getMillisecondCounter();
  189170. if (asioObject != 0)
  189171. {
  189172. asioObject->controlPanel();
  189173. const int spent = (int) Time::getMillisecondCounter() - (int) started;
  189174. log (T("spent: ") + String (spent));
  189175. if (spent > 300)
  189176. {
  189177. shouldUsePreferredSize = true;
  189178. done = true;
  189179. }
  189180. }
  189181. }
  189182. JUCE_CATCH_ALL
  189183. insideControlPanelModalLoop = false;
  189184. return done;
  189185. }
  189186. void resetRequest() throw()
  189187. {
  189188. needToReset = true;
  189189. }
  189190. void resyncRequest() throw()
  189191. {
  189192. needToReset = true;
  189193. isReSync = true;
  189194. }
  189195. void timerCallback()
  189196. {
  189197. if (! insideControlPanelModalLoop)
  189198. {
  189199. stopTimer();
  189200. // used to cause a reset
  189201. log ("! ASIO restart request!");
  189202. if (isOpen_)
  189203. {
  189204. AudioIODeviceCallback* const oldCallback = currentCallback;
  189205. close();
  189206. open (BitArray (currentChansIn), BitArray (currentChansOut),
  189207. currentSampleRate, currentBlockSizeSamples);
  189208. if (oldCallback != 0)
  189209. start (oldCallback);
  189210. }
  189211. }
  189212. else
  189213. {
  189214. startTimer (100);
  189215. }
  189216. }
  189217. juce_UseDebuggingNewOperator
  189218. private:
  189219. IASIO* volatile asioObject;
  189220. ASIOCallbacks callbacks;
  189221. void* windowHandle;
  189222. CLSID classId;
  189223. const String optionalDllForDirectLoading;
  189224. String error;
  189225. long totalNumInputChans, totalNumOutputChans;
  189226. StringArray inputChannelNames, outputChannelNames;
  189227. Array<int> sampleRates, bufferSizes;
  189228. long inputLatency, outputLatency;
  189229. long minSize, maxSize, preferredSize, granularity;
  189230. int volatile currentBlockSizeSamples;
  189231. int volatile currentBitDepth;
  189232. double volatile currentSampleRate;
  189233. BitArray currentChansOut, currentChansIn;
  189234. AudioIODeviceCallback* volatile currentCallback;
  189235. CriticalSection callbackLock;
  189236. ASIOBufferInfo bufferInfos [maxASIOChannels];
  189237. float* inBuffers [maxASIOChannels];
  189238. float* outBuffers [maxASIOChannels];
  189239. int inputChannelBitDepths [maxASIOChannels];
  189240. int outputChannelBitDepths [maxASIOChannels];
  189241. int inputChannelBytesPerSample [maxASIOChannels];
  189242. int outputChannelBytesPerSample [maxASIOChannels];
  189243. bool inputChannelIsFloat [maxASIOChannels];
  189244. bool outputChannelIsFloat [maxASIOChannels];
  189245. bool inputChannelLittleEndian [maxASIOChannels];
  189246. bool outputChannelLittleEndian [maxASIOChannels];
  189247. WaitableEvent event1;
  189248. HeapBlock <float> tempBuffer;
  189249. int volatile bufferIndex, numActiveInputChans, numActiveOutputChans;
  189250. bool isOpen_, isStarted;
  189251. bool volatile isASIOOpen;
  189252. bool volatile calledback;
  189253. bool volatile littleEndian, postOutput, needToReset, isReSync;
  189254. bool volatile insideControlPanelModalLoop;
  189255. bool volatile shouldUsePreferredSize;
  189256. void removeCurrentDriver()
  189257. {
  189258. if (asioObject != 0)
  189259. {
  189260. asioObject->Release();
  189261. asioObject = 0;
  189262. }
  189263. }
  189264. bool loadDriver()
  189265. {
  189266. removeCurrentDriver();
  189267. JUCE_TRY
  189268. {
  189269. if (CoCreateInstance (classId, 0, CLSCTX_INPROC_SERVER,
  189270. classId, (void**) &asioObject) == S_OK)
  189271. {
  189272. return true;
  189273. }
  189274. // If a class isn't registered but we have a path for it, we can fallback to
  189275. // doing a direct load of the COM object (only available via the juce_createASIOAudioIODeviceForGUID function).
  189276. if (optionalDllForDirectLoading.isNotEmpty())
  189277. {
  189278. HMODULE h = LoadLibrary (optionalDllForDirectLoading);
  189279. if (h != 0)
  189280. {
  189281. typedef HRESULT (CALLBACK* DllGetClassObjectFunc) (REFCLSID clsid, REFIID iid, LPVOID* ppv);
  189282. DllGetClassObjectFunc dllGetClassObject = (DllGetClassObjectFunc) GetProcAddress (h, "DllGetClassObject");
  189283. if (dllGetClassObject != 0)
  189284. {
  189285. IClassFactory* classFactory = 0;
  189286. HRESULT hr = dllGetClassObject (classId, IID_IClassFactory, (void**) &classFactory);
  189287. if (classFactory != 0)
  189288. {
  189289. hr = classFactory->CreateInstance (0, classId, (void**) &asioObject);
  189290. classFactory->Release();
  189291. }
  189292. return asioObject != 0;
  189293. }
  189294. }
  189295. }
  189296. }
  189297. JUCE_CATCH_ALL
  189298. asioObject = 0;
  189299. return false;
  189300. }
  189301. const String initDriver()
  189302. {
  189303. if (asioObject != 0)
  189304. {
  189305. char buffer [256];
  189306. zeromem (buffer, sizeof (buffer));
  189307. if (! asioObject->init (windowHandle))
  189308. {
  189309. asioObject->getErrorMessage (buffer);
  189310. return String (buffer, sizeof (buffer) - 1);
  189311. }
  189312. // just in case any daft drivers expect this to be called..
  189313. asioObject->getDriverName (buffer);
  189314. return String::empty;
  189315. }
  189316. return "No Driver";
  189317. }
  189318. const String openDevice()
  189319. {
  189320. // use this in case the driver starts opening dialog boxes..
  189321. Component modalWindow (String::empty);
  189322. modalWindow.setOpaque (true);
  189323. modalWindow.addToDesktop (0);
  189324. modalWindow.enterModalState();
  189325. // open the device and get its info..
  189326. log (T("opening ASIO device: ") + getName());
  189327. needToReset = false;
  189328. isReSync = false;
  189329. outputChannelNames.clear();
  189330. inputChannelNames.clear();
  189331. bufferSizes.clear();
  189332. sampleRates.clear();
  189333. isASIOOpen = false;
  189334. isOpen_ = false;
  189335. totalNumInputChans = 0;
  189336. totalNumOutputChans = 0;
  189337. numActiveInputChans = 0;
  189338. numActiveOutputChans = 0;
  189339. currentCallback = 0;
  189340. error = String::empty;
  189341. if (getName().isEmpty())
  189342. return error;
  189343. long err = 0;
  189344. if (loadDriver())
  189345. {
  189346. if ((error = initDriver()).isEmpty())
  189347. {
  189348. numActiveInputChans = 0;
  189349. numActiveOutputChans = 0;
  189350. totalNumInputChans = 0;
  189351. totalNumOutputChans = 0;
  189352. if (asioObject != 0
  189353. && (err = asioObject->getChannels (&totalNumInputChans, &totalNumOutputChans)) == 0)
  189354. {
  189355. log (String ((int) totalNumInputChans) + T(" in, ") + String ((int) totalNumOutputChans) + T(" out"));
  189356. if ((err = asioObject->getBufferSize (&minSize, &maxSize, &preferredSize, &granularity)) == 0)
  189357. {
  189358. // find a list of buffer sizes..
  189359. log (String ((int) minSize) + T(" ") + String ((int) maxSize) + T(" ") + String ((int)preferredSize) + T(" ") + String ((int)granularity));
  189360. if (granularity >= 0)
  189361. {
  189362. granularity = jmax (1, (int) granularity);
  189363. for (int i = jmax ((int) minSize, (int) granularity); i < jmin (6400, (int) maxSize); i += granularity)
  189364. bufferSizes.addIfNotAlreadyThere (granularity * (i / granularity));
  189365. }
  189366. else if (granularity < 0)
  189367. {
  189368. for (int i = 0; i < 18; ++i)
  189369. {
  189370. const int s = (1 << i);
  189371. if (s >= minSize && s <= maxSize)
  189372. bufferSizes.add (s);
  189373. }
  189374. }
  189375. if (! bufferSizes.contains (preferredSize))
  189376. bufferSizes.insert (0, preferredSize);
  189377. double currentRate = 0;
  189378. asioObject->getSampleRate (&currentRate);
  189379. if (currentRate <= 0.0 || currentRate > 192001.0)
  189380. {
  189381. log ("setting sample rate");
  189382. err = asioObject->setSampleRate (44100.0);
  189383. if (err != 0)
  189384. {
  189385. logError ("setting sample rate", err);
  189386. }
  189387. asioObject->getSampleRate (&currentRate);
  189388. }
  189389. currentSampleRate = currentRate;
  189390. postOutput = (asioObject->outputReady() == 0);
  189391. if (postOutput)
  189392. {
  189393. log ("ASIO outputReady = ok");
  189394. }
  189395. updateSampleRates();
  189396. // ..because cubase does it at this point
  189397. inputLatency = outputLatency = 0;
  189398. if (asioObject->getLatencies (&inputLatency, &outputLatency) != 0)
  189399. {
  189400. log ("ASIO - no latencies");
  189401. }
  189402. log (String ("latencies: ")
  189403. + String ((int) inputLatency)
  189404. + T(", ") + String ((int) outputLatency));
  189405. // create some dummy buffers now.. because cubase does..
  189406. numActiveInputChans = 0;
  189407. numActiveOutputChans = 0;
  189408. ASIOBufferInfo* info = bufferInfos;
  189409. int i, numChans = 0;
  189410. for (i = 0; i < jmin (2, (int) totalNumInputChans); ++i)
  189411. {
  189412. info->isInput = 1;
  189413. info->channelNum = i;
  189414. info->buffers[0] = info->buffers[1] = 0;
  189415. ++info;
  189416. ++numChans;
  189417. }
  189418. const int outputBufferIndex = numChans;
  189419. for (i = 0; i < jmin (2, (int) totalNumOutputChans); ++i)
  189420. {
  189421. info->isInput = 0;
  189422. info->channelNum = i;
  189423. info->buffers[0] = info->buffers[1] = 0;
  189424. ++info;
  189425. ++numChans;
  189426. }
  189427. callbacks.sampleRateDidChange = &sampleRateChangedCallback;
  189428. if (currentASIODev[0] == this)
  189429. {
  189430. callbacks.bufferSwitch = &bufferSwitchCallback0;
  189431. callbacks.asioMessage = &asioMessagesCallback0;
  189432. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback0;
  189433. }
  189434. else if (currentASIODev[1] == this)
  189435. {
  189436. callbacks.bufferSwitch = &bufferSwitchCallback1;
  189437. callbacks.asioMessage = &asioMessagesCallback1;
  189438. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback1;
  189439. }
  189440. else if (currentASIODev[2] == this)
  189441. {
  189442. callbacks.bufferSwitch = &bufferSwitchCallback2;
  189443. callbacks.asioMessage = &asioMessagesCallback2;
  189444. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback2;
  189445. }
  189446. else
  189447. {
  189448. jassertfalse
  189449. }
  189450. log (T("creating buffers (dummy): ") + String (numChans)
  189451. + T(", ") + String ((int) preferredSize));
  189452. if (preferredSize > 0)
  189453. {
  189454. err = asioObject->createBuffers (bufferInfos, numChans, preferredSize, &callbacks);
  189455. if (err != 0)
  189456. {
  189457. logError ("dummy buffers", err);
  189458. }
  189459. }
  189460. long newInps = 0, newOuts = 0;
  189461. asioObject->getChannels (&newInps, &newOuts);
  189462. if (totalNumInputChans != newInps || totalNumOutputChans != newOuts)
  189463. {
  189464. totalNumInputChans = newInps;
  189465. totalNumOutputChans = newOuts;
  189466. log (String ((int) totalNumInputChans) + T(" in; ")
  189467. + String ((int) totalNumOutputChans) + T(" out"));
  189468. }
  189469. updateSampleRates();
  189470. ASIOChannelInfo channelInfo;
  189471. channelInfo.type = 0;
  189472. for (i = 0; i < totalNumInputChans; ++i)
  189473. {
  189474. zerostruct (channelInfo);
  189475. channelInfo.channel = i;
  189476. channelInfo.isInput = 1;
  189477. asioObject->getChannelInfo (&channelInfo);
  189478. inputChannelNames.add (String (channelInfo.name));
  189479. }
  189480. for (i = 0; i < totalNumOutputChans; ++i)
  189481. {
  189482. zerostruct (channelInfo);
  189483. channelInfo.channel = i;
  189484. channelInfo.isInput = 0;
  189485. asioObject->getChannelInfo (&channelInfo);
  189486. outputChannelNames.add (String (channelInfo.name));
  189487. typeToFormatParameters (channelInfo.type,
  189488. outputChannelBitDepths[i],
  189489. outputChannelBytesPerSample[i],
  189490. outputChannelIsFloat[i],
  189491. outputChannelLittleEndian[i]);
  189492. if (i < 2)
  189493. {
  189494. // clear the channels that are used with the dummy stuff
  189495. const int bytesPerBuffer = preferredSize * (outputChannelBitDepths[i] >> 3);
  189496. zeromem (bufferInfos [outputBufferIndex + i].buffers[0], bytesPerBuffer);
  189497. zeromem (bufferInfos [outputBufferIndex + i].buffers[1], bytesPerBuffer);
  189498. }
  189499. }
  189500. outputChannelNames.trim();
  189501. inputChannelNames.trim();
  189502. outputChannelNames.appendNumbersToDuplicates (false, true);
  189503. inputChannelNames.appendNumbersToDuplicates (false, true);
  189504. // start and stop because cubase does it..
  189505. asioObject->getLatencies (&inputLatency, &outputLatency);
  189506. if ((err = asioObject->start()) != 0)
  189507. {
  189508. // ignore an error here, as it might start later after setting other stuff up
  189509. logError ("ASIO start", err);
  189510. }
  189511. Thread::sleep (100);
  189512. asioObject->stop();
  189513. }
  189514. else
  189515. {
  189516. error = "Can't detect buffer sizes";
  189517. }
  189518. }
  189519. else
  189520. {
  189521. error = "Can't detect asio channels";
  189522. }
  189523. }
  189524. }
  189525. else
  189526. {
  189527. error = "No such device";
  189528. }
  189529. if (error.isNotEmpty())
  189530. {
  189531. logError (error, err);
  189532. if (asioObject != 0)
  189533. asioObject->disposeBuffers();
  189534. removeCurrentDriver();
  189535. isASIOOpen = false;
  189536. }
  189537. else
  189538. {
  189539. isASIOOpen = true;
  189540. log ("ASIO device open");
  189541. }
  189542. isOpen_ = false;
  189543. needToReset = false;
  189544. isReSync = false;
  189545. return error;
  189546. }
  189547. void callback (const long index) throw()
  189548. {
  189549. if (isStarted)
  189550. {
  189551. bufferIndex = index;
  189552. processBuffer();
  189553. }
  189554. else
  189555. {
  189556. if (postOutput && (asioObject != 0))
  189557. asioObject->outputReady();
  189558. }
  189559. calledback = true;
  189560. }
  189561. void processBuffer() throw()
  189562. {
  189563. const ASIOBufferInfo* const infos = bufferInfos;
  189564. const int bi = bufferIndex;
  189565. const ScopedLock sl (callbackLock);
  189566. if (needToReset)
  189567. {
  189568. needToReset = false;
  189569. if (isReSync)
  189570. {
  189571. log ("! ASIO resync");
  189572. isReSync = false;
  189573. }
  189574. else
  189575. {
  189576. startTimer (20);
  189577. }
  189578. }
  189579. if (bi >= 0)
  189580. {
  189581. const int samps = currentBlockSizeSamples;
  189582. if (currentCallback != 0)
  189583. {
  189584. int i;
  189585. for (i = 0; i < numActiveInputChans; ++i)
  189586. {
  189587. float* const dst = inBuffers[i];
  189588. jassert (dst != 0);
  189589. const char* const src = (const char*) (infos[i].buffers[bi]);
  189590. if (inputChannelIsFloat[i])
  189591. {
  189592. memcpy (dst, src, samps * sizeof (float));
  189593. }
  189594. else
  189595. {
  189596. jassert (dst == tempBuffer + (samps * i));
  189597. switch (inputChannelBitDepths[i])
  189598. {
  189599. case 16:
  189600. convertInt16ToFloat (src, dst, inputChannelBytesPerSample[i],
  189601. samps, inputChannelLittleEndian[i]);
  189602. break;
  189603. case 24:
  189604. convertInt24ToFloat (src, dst, inputChannelBytesPerSample[i],
  189605. samps, inputChannelLittleEndian[i]);
  189606. break;
  189607. case 32:
  189608. convertInt32ToFloat (src, dst, inputChannelBytesPerSample[i],
  189609. samps, inputChannelLittleEndian[i]);
  189610. break;
  189611. case 64:
  189612. jassertfalse
  189613. break;
  189614. }
  189615. }
  189616. }
  189617. currentCallback->audioDeviceIOCallback ((const float**) inBuffers,
  189618. numActiveInputChans,
  189619. outBuffers,
  189620. numActiveOutputChans,
  189621. samps);
  189622. for (i = 0; i < numActiveOutputChans; ++i)
  189623. {
  189624. float* const src = outBuffers[i];
  189625. jassert (src != 0);
  189626. char* const dst = (char*) (infos [numActiveInputChans + i].buffers[bi]);
  189627. if (outputChannelIsFloat[i])
  189628. {
  189629. memcpy (dst, src, samps * sizeof (float));
  189630. }
  189631. else
  189632. {
  189633. jassert (src == tempBuffer + (samps * (numActiveInputChans + i)));
  189634. switch (outputChannelBitDepths[i])
  189635. {
  189636. case 16:
  189637. convertFloatToInt16 (src, dst, outputChannelBytesPerSample[i],
  189638. samps, outputChannelLittleEndian[i]);
  189639. break;
  189640. case 24:
  189641. convertFloatToInt24 (src, dst, outputChannelBytesPerSample[i],
  189642. samps, outputChannelLittleEndian[i]);
  189643. break;
  189644. case 32:
  189645. convertFloatToInt32 (src, dst, outputChannelBytesPerSample[i],
  189646. samps, outputChannelLittleEndian[i]);
  189647. break;
  189648. case 64:
  189649. jassertfalse
  189650. break;
  189651. }
  189652. }
  189653. }
  189654. }
  189655. else
  189656. {
  189657. for (int i = 0; i < numActiveOutputChans; ++i)
  189658. {
  189659. const int bytesPerBuffer = samps * (outputChannelBitDepths[i] >> 3);
  189660. zeromem (infos[numActiveInputChans + i].buffers[bi], bytesPerBuffer);
  189661. }
  189662. }
  189663. }
  189664. if (postOutput)
  189665. asioObject->outputReady();
  189666. }
  189667. static ASIOTime* bufferSwitchTimeInfoCallback0 (ASIOTime*, long index, long) throw()
  189668. {
  189669. if (currentASIODev[0] != 0)
  189670. currentASIODev[0]->callback (index);
  189671. return 0;
  189672. }
  189673. static ASIOTime* bufferSwitchTimeInfoCallback1 (ASIOTime*, long index, long) throw()
  189674. {
  189675. if (currentASIODev[1] != 0)
  189676. currentASIODev[1]->callback (index);
  189677. return 0;
  189678. }
  189679. static ASIOTime* bufferSwitchTimeInfoCallback2 (ASIOTime*, long index, long) throw()
  189680. {
  189681. if (currentASIODev[2] != 0)
  189682. currentASIODev[2]->callback (index);
  189683. return 0;
  189684. }
  189685. static void bufferSwitchCallback0 (long index, long) throw()
  189686. {
  189687. if (currentASIODev[0] != 0)
  189688. currentASIODev[0]->callback (index);
  189689. }
  189690. static void bufferSwitchCallback1 (long index, long) throw()
  189691. {
  189692. if (currentASIODev[1] != 0)
  189693. currentASIODev[1]->callback (index);
  189694. }
  189695. static void bufferSwitchCallback2 (long index, long) throw()
  189696. {
  189697. if (currentASIODev[2] != 0)
  189698. currentASIODev[2]->callback (index);
  189699. }
  189700. static long asioMessagesCallback0 (long selector, long value, void*, double*) throw()
  189701. {
  189702. return asioMessagesCallback (selector, value, 0);
  189703. }
  189704. static long asioMessagesCallback1 (long selector, long value, void*, double*) throw()
  189705. {
  189706. return asioMessagesCallback (selector, value, 1);
  189707. }
  189708. static long asioMessagesCallback2 (long selector, long value, void*, double*) throw()
  189709. {
  189710. return asioMessagesCallback (selector, value, 2);
  189711. }
  189712. static long asioMessagesCallback (long selector, long value, const int deviceIndex) throw()
  189713. {
  189714. switch (selector)
  189715. {
  189716. case kAsioSelectorSupported:
  189717. if (value == kAsioResetRequest
  189718. || value == kAsioEngineVersion
  189719. || value == kAsioResyncRequest
  189720. || value == kAsioLatenciesChanged
  189721. || value == kAsioSupportsInputMonitor)
  189722. return 1;
  189723. break;
  189724. case kAsioBufferSizeChange:
  189725. break;
  189726. case kAsioResetRequest:
  189727. if (currentASIODev[deviceIndex] != 0)
  189728. currentASIODev[deviceIndex]->resetRequest();
  189729. return 1;
  189730. case kAsioResyncRequest:
  189731. if (currentASIODev[deviceIndex] != 0)
  189732. currentASIODev[deviceIndex]->resyncRequest();
  189733. return 1;
  189734. case kAsioLatenciesChanged:
  189735. return 1;
  189736. case kAsioEngineVersion:
  189737. return 2;
  189738. case kAsioSupportsTimeInfo:
  189739. case kAsioSupportsTimeCode:
  189740. return 0;
  189741. }
  189742. return 0;
  189743. }
  189744. static void sampleRateChangedCallback (ASIOSampleRate) throw()
  189745. {
  189746. }
  189747. static void convertInt16ToFloat (const char* src,
  189748. float* dest,
  189749. const int srcStrideBytes,
  189750. int numSamples,
  189751. const bool littleEndian) throw()
  189752. {
  189753. const double g = 1.0 / 32768.0;
  189754. if (littleEndian)
  189755. {
  189756. while (--numSamples >= 0)
  189757. {
  189758. *dest++ = (float) (g * (short) ByteOrder::littleEndianShort (src));
  189759. src += srcStrideBytes;
  189760. }
  189761. }
  189762. else
  189763. {
  189764. while (--numSamples >= 0)
  189765. {
  189766. *dest++ = (float) (g * (short) ByteOrder::bigEndianShort (src));
  189767. src += srcStrideBytes;
  189768. }
  189769. }
  189770. }
  189771. static void convertFloatToInt16 (const float* src,
  189772. char* dest,
  189773. const int dstStrideBytes,
  189774. int numSamples,
  189775. const bool littleEndian) throw()
  189776. {
  189777. const double maxVal = (double) 0x7fff;
  189778. if (littleEndian)
  189779. {
  189780. while (--numSamples >= 0)
  189781. {
  189782. *(uint16*) dest = ByteOrder::swapIfBigEndian ((uint16) (short) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)));
  189783. dest += dstStrideBytes;
  189784. }
  189785. }
  189786. else
  189787. {
  189788. while (--numSamples >= 0)
  189789. {
  189790. *(uint16*) dest = ByteOrder::swapIfLittleEndian ((uint16) (short) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)));
  189791. dest += dstStrideBytes;
  189792. }
  189793. }
  189794. }
  189795. static void convertInt24ToFloat (const char* src,
  189796. float* dest,
  189797. const int srcStrideBytes,
  189798. int numSamples,
  189799. const bool littleEndian) throw()
  189800. {
  189801. const double g = 1.0 / 0x7fffff;
  189802. if (littleEndian)
  189803. {
  189804. while (--numSamples >= 0)
  189805. {
  189806. *dest++ = (float) (g * ByteOrder::littleEndian24Bit (src));
  189807. src += srcStrideBytes;
  189808. }
  189809. }
  189810. else
  189811. {
  189812. while (--numSamples >= 0)
  189813. {
  189814. *dest++ = (float) (g * ByteOrder::bigEndian24Bit (src));
  189815. src += srcStrideBytes;
  189816. }
  189817. }
  189818. }
  189819. static void convertFloatToInt24 (const float* src,
  189820. char* dest,
  189821. const int dstStrideBytes,
  189822. int numSamples,
  189823. const bool littleEndian) throw()
  189824. {
  189825. const double maxVal = (double) 0x7fffff;
  189826. if (littleEndian)
  189827. {
  189828. while (--numSamples >= 0)
  189829. {
  189830. ByteOrder::littleEndian24BitToChars ((uint32) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)), dest);
  189831. dest += dstStrideBytes;
  189832. }
  189833. }
  189834. else
  189835. {
  189836. while (--numSamples >= 0)
  189837. {
  189838. ByteOrder::bigEndian24BitToChars ((uint32) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)), dest);
  189839. dest += dstStrideBytes;
  189840. }
  189841. }
  189842. }
  189843. static void convertInt32ToFloat (const char* src,
  189844. float* dest,
  189845. const int srcStrideBytes,
  189846. int numSamples,
  189847. const bool littleEndian) throw()
  189848. {
  189849. const double g = 1.0 / 0x7fffffff;
  189850. if (littleEndian)
  189851. {
  189852. while (--numSamples >= 0)
  189853. {
  189854. *dest++ = (float) (g * (int) ByteOrder::littleEndianInt (src));
  189855. src += srcStrideBytes;
  189856. }
  189857. }
  189858. else
  189859. {
  189860. while (--numSamples >= 0)
  189861. {
  189862. *dest++ = (float) (g * (int) ByteOrder::bigEndianInt (src));
  189863. src += srcStrideBytes;
  189864. }
  189865. }
  189866. }
  189867. static void convertFloatToInt32 (const float* src,
  189868. char* dest,
  189869. const int dstStrideBytes,
  189870. int numSamples,
  189871. const bool littleEndian) throw()
  189872. {
  189873. const double maxVal = (double) 0x7fffffff;
  189874. if (littleEndian)
  189875. {
  189876. while (--numSamples >= 0)
  189877. {
  189878. *(uint32*) dest = ByteOrder::swapIfBigEndian ((uint32) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)));
  189879. dest += dstStrideBytes;
  189880. }
  189881. }
  189882. else
  189883. {
  189884. while (--numSamples >= 0)
  189885. {
  189886. *(uint32*) dest = ByteOrder::swapIfLittleEndian ((uint32) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)));
  189887. dest += dstStrideBytes;
  189888. }
  189889. }
  189890. }
  189891. static void typeToFormatParameters (const long type,
  189892. int& bitDepth,
  189893. int& byteStride,
  189894. bool& formatIsFloat,
  189895. bool& littleEndian) throw()
  189896. {
  189897. bitDepth = 0;
  189898. littleEndian = false;
  189899. formatIsFloat = false;
  189900. switch (type)
  189901. {
  189902. case ASIOSTInt16MSB:
  189903. case ASIOSTInt16LSB:
  189904. case ASIOSTInt32MSB16:
  189905. case ASIOSTInt32LSB16:
  189906. bitDepth = 16; break;
  189907. case ASIOSTFloat32MSB:
  189908. case ASIOSTFloat32LSB:
  189909. formatIsFloat = true;
  189910. bitDepth = 32; break;
  189911. case ASIOSTInt32MSB:
  189912. case ASIOSTInt32LSB:
  189913. bitDepth = 32; break;
  189914. case ASIOSTInt24MSB:
  189915. case ASIOSTInt24LSB:
  189916. case ASIOSTInt32MSB24:
  189917. case ASIOSTInt32LSB24:
  189918. case ASIOSTInt32MSB18:
  189919. case ASIOSTInt32MSB20:
  189920. case ASIOSTInt32LSB18:
  189921. case ASIOSTInt32LSB20:
  189922. bitDepth = 24; break;
  189923. case ASIOSTFloat64MSB:
  189924. case ASIOSTFloat64LSB:
  189925. default:
  189926. bitDepth = 64;
  189927. break;
  189928. }
  189929. switch (type)
  189930. {
  189931. case ASIOSTInt16MSB:
  189932. case ASIOSTInt32MSB16:
  189933. case ASIOSTFloat32MSB:
  189934. case ASIOSTFloat64MSB:
  189935. case ASIOSTInt32MSB:
  189936. case ASIOSTInt32MSB18:
  189937. case ASIOSTInt32MSB20:
  189938. case ASIOSTInt32MSB24:
  189939. case ASIOSTInt24MSB:
  189940. littleEndian = false; break;
  189941. case ASIOSTInt16LSB:
  189942. case ASIOSTInt32LSB16:
  189943. case ASIOSTFloat32LSB:
  189944. case ASIOSTFloat64LSB:
  189945. case ASIOSTInt32LSB:
  189946. case ASIOSTInt32LSB18:
  189947. case ASIOSTInt32LSB20:
  189948. case ASIOSTInt32LSB24:
  189949. case ASIOSTInt24LSB:
  189950. littleEndian = true; break;
  189951. default:
  189952. break;
  189953. }
  189954. switch (type)
  189955. {
  189956. case ASIOSTInt16LSB:
  189957. case ASIOSTInt16MSB:
  189958. byteStride = 2; break;
  189959. case ASIOSTInt24LSB:
  189960. case ASIOSTInt24MSB:
  189961. byteStride = 3; break;
  189962. case ASIOSTInt32MSB16:
  189963. case ASIOSTInt32LSB16:
  189964. case ASIOSTInt32MSB:
  189965. case ASIOSTInt32MSB18:
  189966. case ASIOSTInt32MSB20:
  189967. case ASIOSTInt32MSB24:
  189968. case ASIOSTInt32LSB:
  189969. case ASIOSTInt32LSB18:
  189970. case ASIOSTInt32LSB20:
  189971. case ASIOSTInt32LSB24:
  189972. case ASIOSTFloat32LSB:
  189973. case ASIOSTFloat32MSB:
  189974. byteStride = 4; break;
  189975. case ASIOSTFloat64MSB:
  189976. case ASIOSTFloat64LSB:
  189977. byteStride = 8; break;
  189978. default:
  189979. break;
  189980. }
  189981. }
  189982. };
  189983. class ASIOAudioIODeviceType : public AudioIODeviceType
  189984. {
  189985. public:
  189986. ASIOAudioIODeviceType()
  189987. : AudioIODeviceType (T("ASIO")),
  189988. hasScanned (false)
  189989. {
  189990. CoInitialize (0);
  189991. }
  189992. ~ASIOAudioIODeviceType()
  189993. {
  189994. }
  189995. void scanForDevices()
  189996. {
  189997. hasScanned = true;
  189998. deviceNames.clear();
  189999. classIds.clear();
  190000. HKEY hk = 0;
  190001. int index = 0;
  190002. if (RegOpenKeyA (HKEY_LOCAL_MACHINE, "software\\asio", &hk) == ERROR_SUCCESS)
  190003. {
  190004. for (;;)
  190005. {
  190006. char name [256];
  190007. if (RegEnumKeyA (hk, index++, name, 256) == ERROR_SUCCESS)
  190008. {
  190009. addDriverInfo (name, hk);
  190010. }
  190011. else
  190012. {
  190013. break;
  190014. }
  190015. }
  190016. RegCloseKey (hk);
  190017. }
  190018. }
  190019. const StringArray getDeviceNames (const bool /*wantInputNames*/) const
  190020. {
  190021. jassert (hasScanned); // need to call scanForDevices() before doing this
  190022. return deviceNames;
  190023. }
  190024. int getDefaultDeviceIndex (const bool) const
  190025. {
  190026. jassert (hasScanned); // need to call scanForDevices() before doing this
  190027. for (int i = deviceNames.size(); --i >= 0;)
  190028. if (deviceNames[i].containsIgnoreCase (T("asio4all")))
  190029. return i; // asio4all is a safe choice for a default..
  190030. #if JUCE_DEBUG
  190031. if (deviceNames.size() > 1 && deviceNames[0].containsIgnoreCase (T("digidesign")))
  190032. return 1; // (the digi m-box driver crashes the app when you run
  190033. // it in the debugger, which can be a bit annoying)
  190034. #endif
  190035. return 0;
  190036. }
  190037. static int findFreeSlot()
  190038. {
  190039. for (int i = 0; i < numElementsInArray (currentASIODev); ++i)
  190040. if (currentASIODev[i] == 0)
  190041. return i;
  190042. jassertfalse; // unfortunately you can only have a finite number
  190043. // of ASIO devices open at the same time..
  190044. return -1;
  190045. }
  190046. int getIndexOfDevice (AudioIODevice* d, const bool /*asInput*/) const
  190047. {
  190048. jassert (hasScanned); // need to call scanForDevices() before doing this
  190049. return d == 0 ? -1 : deviceNames.indexOf (d->getName());
  190050. }
  190051. bool hasSeparateInputsAndOutputs() const { return false; }
  190052. AudioIODevice* createDevice (const String& outputDeviceName,
  190053. const String& inputDeviceName)
  190054. {
  190055. // ASIO can't open two different devices for input and output - they must be the same one.
  190056. jassert (inputDeviceName == outputDeviceName || outputDeviceName.isEmpty() || inputDeviceName.isEmpty());
  190057. jassert (hasScanned); // need to call scanForDevices() before doing this
  190058. const int index = deviceNames.indexOf (outputDeviceName.isNotEmpty() ? outputDeviceName
  190059. : inputDeviceName);
  190060. if (index >= 0)
  190061. {
  190062. const int freeSlot = findFreeSlot();
  190063. if (freeSlot >= 0)
  190064. return new ASIOAudioIODevice (outputDeviceName, *(classIds [index]), freeSlot, String::empty);
  190065. }
  190066. return 0;
  190067. }
  190068. juce_UseDebuggingNewOperator
  190069. private:
  190070. StringArray deviceNames;
  190071. OwnedArray <CLSID> classIds;
  190072. bool hasScanned;
  190073. static bool checkClassIsOk (const String& classId)
  190074. {
  190075. HKEY hk = 0;
  190076. bool ok = false;
  190077. if (RegOpenKeyA (HKEY_CLASSES_ROOT, "clsid", &hk) == ERROR_SUCCESS)
  190078. {
  190079. int index = 0;
  190080. for (;;)
  190081. {
  190082. char buf [512];
  190083. if (RegEnumKeyA (hk, index++, buf, 512) == ERROR_SUCCESS)
  190084. {
  190085. if (classId.equalsIgnoreCase (buf))
  190086. {
  190087. HKEY subKey, pathKey;
  190088. if (RegOpenKeyExA (hk, buf, 0, KEY_READ, &subKey) == ERROR_SUCCESS)
  190089. {
  190090. if (RegOpenKeyExA (subKey, "InprocServer32", 0, KEY_READ, &pathKey) == ERROR_SUCCESS)
  190091. {
  190092. char pathName [600];
  190093. DWORD dtype = REG_SZ;
  190094. DWORD dsize = sizeof (pathName);
  190095. if (RegQueryValueExA (pathKey, 0, 0, &dtype,
  190096. (LPBYTE) pathName, &dsize) == ERROR_SUCCESS)
  190097. {
  190098. OFSTRUCT of;
  190099. zerostruct (of);
  190100. of.cBytes = sizeof (of);
  190101. ok = (OpenFile (String (pathName), &of, OF_EXIST) != 0);
  190102. }
  190103. RegCloseKey (pathKey);
  190104. }
  190105. RegCloseKey (subKey);
  190106. }
  190107. break;
  190108. }
  190109. }
  190110. else
  190111. {
  190112. break;
  190113. }
  190114. }
  190115. RegCloseKey (hk);
  190116. }
  190117. return ok;
  190118. }
  190119. void addDriverInfo (const String& keyName, HKEY hk)
  190120. {
  190121. HKEY subKey;
  190122. if (RegOpenKeyExA (hk, keyName, 0, KEY_READ, &subKey) == ERROR_SUCCESS)
  190123. {
  190124. char buf [256];
  190125. DWORD dtype = REG_SZ;
  190126. DWORD dsize = sizeof (buf);
  190127. zeromem (buf, dsize);
  190128. if (RegQueryValueExA (subKey, "clsid", 0, &dtype, (LPBYTE) buf, &dsize) == ERROR_SUCCESS)
  190129. {
  190130. if (dsize > 0 && checkClassIsOk (buf))
  190131. {
  190132. wchar_t classIdStr [130];
  190133. MultiByteToWideChar (CP_ACP, 0, buf, -1, classIdStr, 128);
  190134. String deviceName;
  190135. CLSID classId;
  190136. if (CLSIDFromString ((LPOLESTR) classIdStr, &classId) == S_OK)
  190137. {
  190138. dtype = REG_SZ;
  190139. dsize = sizeof (buf);
  190140. if (RegQueryValueExA (subKey, "description", 0, &dtype, (LPBYTE) buf, &dsize) == ERROR_SUCCESS)
  190141. deviceName = buf;
  190142. else
  190143. deviceName = keyName;
  190144. log (T("found ") + deviceName);
  190145. deviceNames.add (deviceName);
  190146. classIds.add (new CLSID (classId));
  190147. }
  190148. }
  190149. RegCloseKey (subKey);
  190150. }
  190151. }
  190152. }
  190153. ASIOAudioIODeviceType (const ASIOAudioIODeviceType&);
  190154. const ASIOAudioIODeviceType& operator= (const ASIOAudioIODeviceType&);
  190155. };
  190156. AudioIODeviceType* juce_createAudioIODeviceType_ASIO()
  190157. {
  190158. return new ASIOAudioIODeviceType();
  190159. }
  190160. AudioIODevice* juce_createASIOAudioIODeviceForGUID (const String& name,
  190161. void* guid,
  190162. const String& optionalDllForDirectLoading)
  190163. {
  190164. const int freeSlot = ASIOAudioIODeviceType::findFreeSlot();
  190165. if (freeSlot < 0)
  190166. return 0;
  190167. return new ASIOAudioIODevice (name, *(CLSID*) guid, freeSlot, optionalDllForDirectLoading);
  190168. }
  190169. #undef log
  190170. #endif
  190171. /*** End of inlined file: juce_win32_ASIO.cpp ***/
  190172. /*** Start of inlined file: juce_win32_DirectSound.cpp ***/
  190173. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  190174. // compiled on its own).
  190175. #if JUCE_INCLUDED_FILE && JUCE_DIRECTSOUND
  190176. END_JUCE_NAMESPACE
  190177. extern "C"
  190178. {
  190179. // Declare just the minimum number of interfaces for the DSound objects that we need..
  190180. typedef struct typeDSBUFFERDESC
  190181. {
  190182. DWORD dwSize;
  190183. DWORD dwFlags;
  190184. DWORD dwBufferBytes;
  190185. DWORD dwReserved;
  190186. LPWAVEFORMATEX lpwfxFormat;
  190187. GUID guid3DAlgorithm;
  190188. } DSBUFFERDESC;
  190189. struct IDirectSoundBuffer;
  190190. #undef INTERFACE
  190191. #define INTERFACE IDirectSound
  190192. DECLARE_INTERFACE_(IDirectSound, IUnknown)
  190193. {
  190194. STDMETHOD(QueryInterface) (THIS_ REFIID, LPVOID*) PURE;
  190195. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  190196. STDMETHOD_(ULONG,Release) (THIS) PURE;
  190197. STDMETHOD(CreateSoundBuffer) (THIS_ DSBUFFERDESC*, IDirectSoundBuffer**, LPUNKNOWN) PURE;
  190198. STDMETHOD(GetCaps) (THIS_ void*) PURE;
  190199. STDMETHOD(DuplicateSoundBuffer) (THIS_ IDirectSoundBuffer*, IDirectSoundBuffer**) PURE;
  190200. STDMETHOD(SetCooperativeLevel) (THIS_ HWND, DWORD) PURE;
  190201. STDMETHOD(Compact) (THIS) PURE;
  190202. STDMETHOD(GetSpeakerConfig) (THIS_ LPDWORD) PURE;
  190203. STDMETHOD(SetSpeakerConfig) (THIS_ DWORD) PURE;
  190204. STDMETHOD(Initialize) (THIS_ const GUID*) PURE;
  190205. };
  190206. #undef INTERFACE
  190207. #define INTERFACE IDirectSoundBuffer
  190208. DECLARE_INTERFACE_(IDirectSoundBuffer, IUnknown)
  190209. {
  190210. STDMETHOD(QueryInterface) (THIS_ REFIID, LPVOID*) PURE;
  190211. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  190212. STDMETHOD_(ULONG,Release) (THIS) PURE;
  190213. STDMETHOD(GetCaps) (THIS_ void*) PURE;
  190214. STDMETHOD(GetCurrentPosition) (THIS_ LPDWORD, LPDWORD) PURE;
  190215. STDMETHOD(GetFormat) (THIS_ LPWAVEFORMATEX, DWORD, LPDWORD) PURE;
  190216. STDMETHOD(GetVolume) (THIS_ LPLONG) PURE;
  190217. STDMETHOD(GetPan) (THIS_ LPLONG) PURE;
  190218. STDMETHOD(GetFrequency) (THIS_ LPDWORD) PURE;
  190219. STDMETHOD(GetStatus) (THIS_ LPDWORD) PURE;
  190220. STDMETHOD(Initialize) (THIS_ IDirectSound*, DSBUFFERDESC*) PURE;
  190221. STDMETHOD(Lock) (THIS_ DWORD, DWORD, LPVOID*, LPDWORD, LPVOID*, LPDWORD, DWORD) PURE;
  190222. STDMETHOD(Play) (THIS_ DWORD, DWORD, DWORD) PURE;
  190223. STDMETHOD(SetCurrentPosition) (THIS_ DWORD) PURE;
  190224. STDMETHOD(SetFormat) (THIS_ const WAVEFORMATEX*) PURE;
  190225. STDMETHOD(SetVolume) (THIS_ LONG) PURE;
  190226. STDMETHOD(SetPan) (THIS_ LONG) PURE;
  190227. STDMETHOD(SetFrequency) (THIS_ DWORD) PURE;
  190228. STDMETHOD(Stop) (THIS) PURE;
  190229. STDMETHOD(Unlock) (THIS_ LPVOID, DWORD, LPVOID, DWORD) PURE;
  190230. STDMETHOD(Restore) (THIS) PURE;
  190231. };
  190232. typedef struct typeDSCBUFFERDESC
  190233. {
  190234. DWORD dwSize;
  190235. DWORD dwFlags;
  190236. DWORD dwBufferBytes;
  190237. DWORD dwReserved;
  190238. LPWAVEFORMATEX lpwfxFormat;
  190239. } DSCBUFFERDESC;
  190240. struct IDirectSoundCaptureBuffer;
  190241. #undef INTERFACE
  190242. #define INTERFACE IDirectSoundCapture
  190243. DECLARE_INTERFACE_(IDirectSoundCapture, IUnknown)
  190244. {
  190245. STDMETHOD(QueryInterface) (THIS_ REFIID, LPVOID*) PURE;
  190246. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  190247. STDMETHOD_(ULONG,Release) (THIS) PURE;
  190248. STDMETHOD(CreateCaptureBuffer) (THIS_ DSCBUFFERDESC*, IDirectSoundCaptureBuffer**, LPUNKNOWN) PURE;
  190249. STDMETHOD(GetCaps) (THIS_ void*) PURE;
  190250. STDMETHOD(Initialize) (THIS_ const GUID*) PURE;
  190251. };
  190252. #undef INTERFACE
  190253. #define INTERFACE IDirectSoundCaptureBuffer
  190254. DECLARE_INTERFACE_(IDirectSoundCaptureBuffer, IUnknown)
  190255. {
  190256. STDMETHOD(QueryInterface) (THIS_ REFIID, LPVOID*) PURE;
  190257. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  190258. STDMETHOD_(ULONG,Release) (THIS) PURE;
  190259. STDMETHOD(GetCaps) (THIS_ void*) PURE;
  190260. STDMETHOD(GetCurrentPosition) (THIS_ LPDWORD, LPDWORD) PURE;
  190261. STDMETHOD(GetFormat) (THIS_ LPWAVEFORMATEX, DWORD, LPDWORD) PURE;
  190262. STDMETHOD(GetStatus) (THIS_ LPDWORD) PURE;
  190263. STDMETHOD(Initialize) (THIS_ IDirectSoundCapture*, DSCBUFFERDESC*) PURE;
  190264. STDMETHOD(Lock) (THIS_ DWORD, DWORD, LPVOID*, LPDWORD, LPVOID*, LPDWORD, DWORD) PURE;
  190265. STDMETHOD(Start) (THIS_ DWORD) PURE;
  190266. STDMETHOD(Stop) (THIS) PURE;
  190267. STDMETHOD(Unlock) (THIS_ LPVOID, DWORD, LPVOID, DWORD) PURE;
  190268. };
  190269. };
  190270. BEGIN_JUCE_NAMESPACE
  190271. static const String getDSErrorMessage (HRESULT hr)
  190272. {
  190273. const char* result = 0;
  190274. switch (hr)
  190275. {
  190276. case MAKE_HRESULT(1, 0x878, 10):
  190277. result = "Device already allocated";
  190278. break;
  190279. case MAKE_HRESULT(1, 0x878, 30):
  190280. result = "Control unavailable";
  190281. break;
  190282. case E_INVALIDARG:
  190283. result = "Invalid parameter";
  190284. break;
  190285. case MAKE_HRESULT(1, 0x878, 50):
  190286. result = "Invalid call";
  190287. break;
  190288. case E_FAIL:
  190289. result = "Generic error";
  190290. break;
  190291. case MAKE_HRESULT(1, 0x878, 70):
  190292. result = "Priority level error";
  190293. break;
  190294. case E_OUTOFMEMORY:
  190295. result = "Out of memory";
  190296. break;
  190297. case MAKE_HRESULT(1, 0x878, 100):
  190298. result = "Bad format";
  190299. break;
  190300. case E_NOTIMPL:
  190301. result = "Unsupported function";
  190302. break;
  190303. case MAKE_HRESULT(1, 0x878, 120):
  190304. result = "No driver";
  190305. break;
  190306. case MAKE_HRESULT(1, 0x878, 130):
  190307. result = "Already initialised";
  190308. break;
  190309. case CLASS_E_NOAGGREGATION:
  190310. result = "No aggregation";
  190311. break;
  190312. case MAKE_HRESULT(1, 0x878, 150):
  190313. result = "Buffer lost";
  190314. break;
  190315. case MAKE_HRESULT(1, 0x878, 160):
  190316. result = "Another app has priority";
  190317. break;
  190318. case MAKE_HRESULT(1, 0x878, 170):
  190319. result = "Uninitialised";
  190320. break;
  190321. case E_NOINTERFACE:
  190322. result = "No interface";
  190323. break;
  190324. case S_OK:
  190325. result = "No error";
  190326. break;
  190327. default:
  190328. return "Unknown error: " + String ((int) hr);
  190329. }
  190330. return result;
  190331. }
  190332. #define DS_DEBUGGING 1
  190333. #ifdef DS_DEBUGGING
  190334. #define CATCH JUCE_CATCH_EXCEPTION
  190335. #undef log
  190336. #define log(a) Logger::writeToLog(a);
  190337. #undef logError
  190338. #define logError(a) logDSError(a, __LINE__);
  190339. static void logDSError (HRESULT hr, int lineNum)
  190340. {
  190341. if (hr != S_OK)
  190342. {
  190343. String error ("DS error at line ");
  190344. error << lineNum << T(" - ") << getDSErrorMessage (hr);
  190345. log (error);
  190346. }
  190347. }
  190348. #else
  190349. #define CATCH JUCE_CATCH_ALL
  190350. #define log(a)
  190351. #define logError(a)
  190352. #endif
  190353. #define DSOUND_FUNCTION(functionName, params) \
  190354. typedef HRESULT (WINAPI *type##functionName) params; \
  190355. static type##functionName ds##functionName = 0;
  190356. #define DSOUND_FUNCTION_LOAD(functionName) \
  190357. ds##functionName = (type##functionName) GetProcAddress (h, #functionName); \
  190358. jassert (ds##functionName != 0);
  190359. typedef BOOL (CALLBACK *LPDSENUMCALLBACKW) (LPGUID, LPCWSTR, LPCWSTR, LPVOID);
  190360. typedef BOOL (CALLBACK *LPDSENUMCALLBACKA) (LPGUID, LPCSTR, LPCSTR, LPVOID);
  190361. DSOUND_FUNCTION (DirectSoundCreate, (const GUID*, IDirectSound**, LPUNKNOWN))
  190362. DSOUND_FUNCTION (DirectSoundCaptureCreate, (const GUID*, IDirectSoundCapture**, LPUNKNOWN))
  190363. DSOUND_FUNCTION (DirectSoundEnumerateW, (LPDSENUMCALLBACKW, LPVOID))
  190364. DSOUND_FUNCTION (DirectSoundCaptureEnumerateW, (LPDSENUMCALLBACKW, LPVOID))
  190365. static void initialiseDSoundFunctions()
  190366. {
  190367. if (dsDirectSoundCreate == 0)
  190368. {
  190369. HMODULE h = LoadLibraryA ("dsound.dll");
  190370. DSOUND_FUNCTION_LOAD (DirectSoundCreate)
  190371. DSOUND_FUNCTION_LOAD (DirectSoundCaptureCreate)
  190372. DSOUND_FUNCTION_LOAD (DirectSoundEnumerateW)
  190373. DSOUND_FUNCTION_LOAD (DirectSoundCaptureEnumerateW)
  190374. }
  190375. }
  190376. class DSoundInternalOutChannel
  190377. {
  190378. String name;
  190379. LPGUID guid;
  190380. int sampleRate, bufferSizeSamples;
  190381. float* leftBuffer;
  190382. float* rightBuffer;
  190383. IDirectSound* pDirectSound;
  190384. IDirectSoundBuffer* pOutputBuffer;
  190385. DWORD writeOffset;
  190386. int totalBytesPerBuffer;
  190387. int bytesPerBuffer;
  190388. unsigned int lastPlayCursor;
  190389. public:
  190390. int bitDepth;
  190391. bool doneFlag;
  190392. DSoundInternalOutChannel (const String& name_,
  190393. LPGUID guid_,
  190394. int rate,
  190395. int bufferSize,
  190396. float* left,
  190397. float* right)
  190398. : name (name_),
  190399. guid (guid_),
  190400. sampleRate (rate),
  190401. bufferSizeSamples (bufferSize),
  190402. leftBuffer (left),
  190403. rightBuffer (right),
  190404. pDirectSound (0),
  190405. pOutputBuffer (0),
  190406. bitDepth (16)
  190407. {
  190408. }
  190409. ~DSoundInternalOutChannel()
  190410. {
  190411. close();
  190412. }
  190413. void close()
  190414. {
  190415. HRESULT hr;
  190416. if (pOutputBuffer != 0)
  190417. {
  190418. JUCE_TRY
  190419. {
  190420. log (T("closing dsound out: ") + name);
  190421. hr = pOutputBuffer->Stop();
  190422. logError (hr);
  190423. }
  190424. CATCH
  190425. JUCE_TRY
  190426. {
  190427. hr = pOutputBuffer->Release();
  190428. logError (hr);
  190429. }
  190430. CATCH
  190431. pOutputBuffer = 0;
  190432. }
  190433. if (pDirectSound != 0)
  190434. {
  190435. JUCE_TRY
  190436. {
  190437. hr = pDirectSound->Release();
  190438. logError (hr);
  190439. }
  190440. CATCH
  190441. pDirectSound = 0;
  190442. }
  190443. }
  190444. const String open()
  190445. {
  190446. log (T("opening dsound out device: ") + name
  190447. + T(" rate=") + String (sampleRate)
  190448. + T(" bits=") + String (bitDepth)
  190449. + T(" buf=") + String (bufferSizeSamples));
  190450. pDirectSound = 0;
  190451. pOutputBuffer = 0;
  190452. writeOffset = 0;
  190453. String error;
  190454. HRESULT hr = E_NOINTERFACE;
  190455. if (dsDirectSoundCreate != 0)
  190456. hr = dsDirectSoundCreate (guid, &pDirectSound, 0);
  190457. if (hr == S_OK)
  190458. {
  190459. bytesPerBuffer = (bufferSizeSamples * (bitDepth >> 2)) & ~15;
  190460. totalBytesPerBuffer = (3 * bytesPerBuffer) & ~15;
  190461. const int numChannels = 2;
  190462. hr = pDirectSound->SetCooperativeLevel (GetDesktopWindow(), 2 /* DSSCL_PRIORITY */);
  190463. logError (hr);
  190464. if (hr == S_OK)
  190465. {
  190466. IDirectSoundBuffer* pPrimaryBuffer;
  190467. DSBUFFERDESC primaryDesc;
  190468. zerostruct (primaryDesc);
  190469. primaryDesc.dwSize = sizeof (DSBUFFERDESC);
  190470. primaryDesc.dwFlags = 1 /* DSBCAPS_PRIMARYBUFFER */;
  190471. primaryDesc.dwBufferBytes = 0;
  190472. primaryDesc.lpwfxFormat = 0;
  190473. log ("opening dsound out step 2");
  190474. hr = pDirectSound->CreateSoundBuffer (&primaryDesc, &pPrimaryBuffer, 0);
  190475. logError (hr);
  190476. if (hr == S_OK)
  190477. {
  190478. WAVEFORMATEX wfFormat;
  190479. wfFormat.wFormatTag = WAVE_FORMAT_PCM;
  190480. wfFormat.nChannels = (unsigned short) numChannels;
  190481. wfFormat.nSamplesPerSec = sampleRate;
  190482. wfFormat.wBitsPerSample = (unsigned short) bitDepth;
  190483. wfFormat.nBlockAlign = (unsigned short) (wfFormat.nChannels * wfFormat.wBitsPerSample / 8);
  190484. wfFormat.nAvgBytesPerSec = wfFormat.nSamplesPerSec * wfFormat.nBlockAlign;
  190485. wfFormat.cbSize = 0;
  190486. hr = pPrimaryBuffer->SetFormat (&wfFormat);
  190487. logError (hr);
  190488. if (hr == S_OK)
  190489. {
  190490. DSBUFFERDESC secondaryDesc;
  190491. zerostruct (secondaryDesc);
  190492. secondaryDesc.dwSize = sizeof (DSBUFFERDESC);
  190493. secondaryDesc.dwFlags = 0x8000 /* DSBCAPS_GLOBALFOCUS */
  190494. | 0x10000 /* DSBCAPS_GETCURRENTPOSITION2 */;
  190495. secondaryDesc.dwBufferBytes = totalBytesPerBuffer;
  190496. secondaryDesc.lpwfxFormat = &wfFormat;
  190497. hr = pDirectSound->CreateSoundBuffer (&secondaryDesc, &pOutputBuffer, 0);
  190498. logError (hr);
  190499. if (hr == S_OK)
  190500. {
  190501. log ("opening dsound out step 3");
  190502. DWORD dwDataLen;
  190503. unsigned char* pDSBuffData;
  190504. hr = pOutputBuffer->Lock (0, totalBytesPerBuffer,
  190505. (LPVOID*) &pDSBuffData, &dwDataLen, 0, 0, 0);
  190506. logError (hr);
  190507. if (hr == S_OK)
  190508. {
  190509. zeromem (pDSBuffData, dwDataLen);
  190510. hr = pOutputBuffer->Unlock (pDSBuffData, dwDataLen, 0, 0);
  190511. if (hr == S_OK)
  190512. {
  190513. hr = pOutputBuffer->SetCurrentPosition (0);
  190514. if (hr == S_OK)
  190515. {
  190516. hr = pOutputBuffer->Play (0, 0, 1 /* DSBPLAY_LOOPING */);
  190517. if (hr == S_OK)
  190518. return String::empty;
  190519. }
  190520. }
  190521. }
  190522. }
  190523. }
  190524. }
  190525. }
  190526. }
  190527. error = getDSErrorMessage (hr);
  190528. close();
  190529. return error;
  190530. }
  190531. void synchronisePosition()
  190532. {
  190533. if (pOutputBuffer != 0)
  190534. {
  190535. DWORD playCursor;
  190536. pOutputBuffer->GetCurrentPosition (&playCursor, &writeOffset);
  190537. }
  190538. }
  190539. bool service()
  190540. {
  190541. if (pOutputBuffer == 0)
  190542. return true;
  190543. DWORD playCursor, writeCursor;
  190544. for (;;)
  190545. {
  190546. HRESULT hr = pOutputBuffer->GetCurrentPosition (&playCursor, &writeCursor);
  190547. if (hr == MAKE_HRESULT (1, 0x878, 150)) // DSERR_BUFFERLOST
  190548. {
  190549. pOutputBuffer->Restore();
  190550. continue;
  190551. }
  190552. if (hr == S_OK)
  190553. break;
  190554. logError (hr);
  190555. jassertfalse
  190556. return true;
  190557. }
  190558. int playWriteGap = writeCursor - playCursor;
  190559. if (playWriteGap < 0)
  190560. playWriteGap += totalBytesPerBuffer;
  190561. int bytesEmpty = playCursor - writeOffset;
  190562. if (bytesEmpty < 0)
  190563. bytesEmpty += totalBytesPerBuffer;
  190564. if (bytesEmpty > (totalBytesPerBuffer - playWriteGap))
  190565. {
  190566. writeOffset = writeCursor;
  190567. bytesEmpty = totalBytesPerBuffer - playWriteGap;
  190568. }
  190569. if (bytesEmpty >= bytesPerBuffer)
  190570. {
  190571. LPBYTE lpbuf1 = 0;
  190572. LPBYTE lpbuf2 = 0;
  190573. DWORD dwSize1 = 0;
  190574. DWORD dwSize2 = 0;
  190575. HRESULT hr = pOutputBuffer->Lock (writeOffset,
  190576. bytesPerBuffer,
  190577. (void**) &lpbuf1, &dwSize1,
  190578. (void**) &lpbuf2, &dwSize2, 0);
  190579. if (hr == MAKE_HRESULT (1, 0x878, 150)) // DSERR_BUFFERLOST
  190580. {
  190581. pOutputBuffer->Restore();
  190582. hr = pOutputBuffer->Lock (writeOffset,
  190583. bytesPerBuffer,
  190584. (void**) &lpbuf1, &dwSize1,
  190585. (void**) &lpbuf2, &dwSize2, 0);
  190586. }
  190587. if (hr == S_OK)
  190588. {
  190589. if (bitDepth == 16)
  190590. {
  190591. const float gainL = 32767.0f;
  190592. const float gainR = 32767.0f;
  190593. int* dest = (int*)lpbuf1;
  190594. const float* left = leftBuffer;
  190595. const float* right = rightBuffer;
  190596. int samples1 = dwSize1 >> 2;
  190597. int samples2 = dwSize2 >> 2;
  190598. if (left == 0)
  190599. {
  190600. while (--samples1 >= 0)
  190601. {
  190602. int r = roundToInt (gainR * *right++);
  190603. if (r < -32768)
  190604. r = -32768;
  190605. else if (r > 32767)
  190606. r = 32767;
  190607. *dest++ = (r << 16);
  190608. }
  190609. dest = (int*)lpbuf2;
  190610. while (--samples2 >= 0)
  190611. {
  190612. int r = roundToInt (gainR * *right++);
  190613. if (r < -32768)
  190614. r = -32768;
  190615. else if (r > 32767)
  190616. r = 32767;
  190617. *dest++ = (r << 16);
  190618. }
  190619. }
  190620. else if (right == 0)
  190621. {
  190622. while (--samples1 >= 0)
  190623. {
  190624. int l = roundToInt (gainL * *left++);
  190625. if (l < -32768)
  190626. l = -32768;
  190627. else if (l > 32767)
  190628. l = 32767;
  190629. l &= 0xffff;
  190630. *dest++ = l;
  190631. }
  190632. dest = (int*)lpbuf2;
  190633. while (--samples2 >= 0)
  190634. {
  190635. int l = roundToInt (gainL * *left++);
  190636. if (l < -32768)
  190637. l = -32768;
  190638. else if (l > 32767)
  190639. l = 32767;
  190640. l &= 0xffff;
  190641. *dest++ = l;
  190642. }
  190643. }
  190644. else
  190645. {
  190646. while (--samples1 >= 0)
  190647. {
  190648. int l = roundToInt (gainL * *left++);
  190649. if (l < -32768)
  190650. l = -32768;
  190651. else if (l > 32767)
  190652. l = 32767;
  190653. l &= 0xffff;
  190654. int r = roundToInt (gainR * *right++);
  190655. if (r < -32768)
  190656. r = -32768;
  190657. else if (r > 32767)
  190658. r = 32767;
  190659. *dest++ = (r << 16) | l;
  190660. }
  190661. dest = (int*)lpbuf2;
  190662. while (--samples2 >= 0)
  190663. {
  190664. int l = roundToInt (gainL * *left++);
  190665. if (l < -32768)
  190666. l = -32768;
  190667. else if (l > 32767)
  190668. l = 32767;
  190669. l &= 0xffff;
  190670. int r = roundToInt (gainR * *right++);
  190671. if (r < -32768)
  190672. r = -32768;
  190673. else if (r > 32767)
  190674. r = 32767;
  190675. *dest++ = (r << 16) | l;
  190676. }
  190677. }
  190678. }
  190679. else
  190680. {
  190681. jassertfalse
  190682. }
  190683. writeOffset = (writeOffset + dwSize1 + dwSize2) % totalBytesPerBuffer;
  190684. pOutputBuffer->Unlock (lpbuf1, dwSize1, lpbuf2, dwSize2);
  190685. }
  190686. else
  190687. {
  190688. jassertfalse
  190689. logError (hr);
  190690. }
  190691. bytesEmpty -= bytesPerBuffer;
  190692. return true;
  190693. }
  190694. else
  190695. {
  190696. return false;
  190697. }
  190698. }
  190699. };
  190700. struct DSoundInternalInChannel
  190701. {
  190702. String name;
  190703. LPGUID guid;
  190704. int sampleRate, bufferSizeSamples;
  190705. float* leftBuffer;
  190706. float* rightBuffer;
  190707. IDirectSound* pDirectSound;
  190708. IDirectSoundCapture* pDirectSoundCapture;
  190709. IDirectSoundCaptureBuffer* pInputBuffer;
  190710. public:
  190711. unsigned int readOffset;
  190712. int bytesPerBuffer, totalBytesPerBuffer;
  190713. int bitDepth;
  190714. bool doneFlag;
  190715. DSoundInternalInChannel (const String& name_,
  190716. LPGUID guid_,
  190717. int rate,
  190718. int bufferSize,
  190719. float* left,
  190720. float* right)
  190721. : name (name_),
  190722. guid (guid_),
  190723. sampleRate (rate),
  190724. bufferSizeSamples (bufferSize),
  190725. leftBuffer (left),
  190726. rightBuffer (right),
  190727. pDirectSound (0),
  190728. pDirectSoundCapture (0),
  190729. pInputBuffer (0),
  190730. bitDepth (16)
  190731. {
  190732. }
  190733. ~DSoundInternalInChannel()
  190734. {
  190735. close();
  190736. }
  190737. void close()
  190738. {
  190739. HRESULT hr;
  190740. if (pInputBuffer != 0)
  190741. {
  190742. JUCE_TRY
  190743. {
  190744. log (T("closing dsound in: ") + name);
  190745. hr = pInputBuffer->Stop();
  190746. logError (hr);
  190747. }
  190748. CATCH
  190749. JUCE_TRY
  190750. {
  190751. hr = pInputBuffer->Release();
  190752. logError (hr);
  190753. }
  190754. CATCH
  190755. pInputBuffer = 0;
  190756. }
  190757. if (pDirectSoundCapture != 0)
  190758. {
  190759. JUCE_TRY
  190760. {
  190761. hr = pDirectSoundCapture->Release();
  190762. logError (hr);
  190763. }
  190764. CATCH
  190765. pDirectSoundCapture = 0;
  190766. }
  190767. if (pDirectSound != 0)
  190768. {
  190769. JUCE_TRY
  190770. {
  190771. hr = pDirectSound->Release();
  190772. logError (hr);
  190773. }
  190774. CATCH
  190775. pDirectSound = 0;
  190776. }
  190777. }
  190778. const String open()
  190779. {
  190780. log (T("opening dsound in device: ") + name
  190781. + T(" rate=") + String (sampleRate) + T(" bits=") + String (bitDepth) + T(" buf=") + String (bufferSizeSamples));
  190782. pDirectSound = 0;
  190783. pDirectSoundCapture = 0;
  190784. pInputBuffer = 0;
  190785. readOffset = 0;
  190786. totalBytesPerBuffer = 0;
  190787. String error;
  190788. HRESULT hr = E_NOINTERFACE;
  190789. if (dsDirectSoundCaptureCreate != 0)
  190790. hr = dsDirectSoundCaptureCreate (guid, &pDirectSoundCapture, 0);
  190791. logError (hr);
  190792. if (hr == S_OK)
  190793. {
  190794. const int numChannels = 2;
  190795. bytesPerBuffer = (bufferSizeSamples * (bitDepth >> 2)) & ~15;
  190796. totalBytesPerBuffer = (3 * bytesPerBuffer) & ~15;
  190797. WAVEFORMATEX wfFormat;
  190798. wfFormat.wFormatTag = WAVE_FORMAT_PCM;
  190799. wfFormat.nChannels = (unsigned short)numChannels;
  190800. wfFormat.nSamplesPerSec = sampleRate;
  190801. wfFormat.wBitsPerSample = (unsigned short)bitDepth;
  190802. wfFormat.nBlockAlign = (unsigned short)(wfFormat.nChannels * (wfFormat.wBitsPerSample / 8));
  190803. wfFormat.nAvgBytesPerSec = wfFormat.nSamplesPerSec * wfFormat.nBlockAlign;
  190804. wfFormat.cbSize = 0;
  190805. DSCBUFFERDESC captureDesc;
  190806. zerostruct (captureDesc);
  190807. captureDesc.dwSize = sizeof (DSCBUFFERDESC);
  190808. captureDesc.dwFlags = 0;
  190809. captureDesc.dwBufferBytes = totalBytesPerBuffer;
  190810. captureDesc.lpwfxFormat = &wfFormat;
  190811. log (T("opening dsound in step 2"));
  190812. hr = pDirectSoundCapture->CreateCaptureBuffer (&captureDesc, &pInputBuffer, 0);
  190813. logError (hr);
  190814. if (hr == S_OK)
  190815. {
  190816. hr = pInputBuffer->Start (1 /* DSCBSTART_LOOPING */);
  190817. logError (hr);
  190818. if (hr == S_OK)
  190819. return String::empty;
  190820. }
  190821. }
  190822. error = getDSErrorMessage (hr);
  190823. close();
  190824. return error;
  190825. }
  190826. void synchronisePosition()
  190827. {
  190828. if (pInputBuffer != 0)
  190829. {
  190830. DWORD capturePos;
  190831. pInputBuffer->GetCurrentPosition (&capturePos, (DWORD*)&readOffset);
  190832. }
  190833. }
  190834. bool service()
  190835. {
  190836. if (pInputBuffer == 0)
  190837. return true;
  190838. DWORD capturePos, readPos;
  190839. HRESULT hr = pInputBuffer->GetCurrentPosition (&capturePos, &readPos);
  190840. logError (hr);
  190841. if (hr != S_OK)
  190842. return true;
  190843. int bytesFilled = readPos - readOffset;
  190844. if (bytesFilled < 0)
  190845. bytesFilled += totalBytesPerBuffer;
  190846. if (bytesFilled >= bytesPerBuffer)
  190847. {
  190848. LPBYTE lpbuf1 = 0;
  190849. LPBYTE lpbuf2 = 0;
  190850. DWORD dwsize1 = 0;
  190851. DWORD dwsize2 = 0;
  190852. HRESULT hr = pInputBuffer->Lock (readOffset,
  190853. bytesPerBuffer,
  190854. (void**) &lpbuf1, &dwsize1,
  190855. (void**) &lpbuf2, &dwsize2, 0);
  190856. if (hr == S_OK)
  190857. {
  190858. if (bitDepth == 16)
  190859. {
  190860. const float g = 1.0f / 32768.0f;
  190861. float* destL = leftBuffer;
  190862. float* destR = rightBuffer;
  190863. int samples1 = dwsize1 >> 2;
  190864. int samples2 = dwsize2 >> 2;
  190865. const short* src = (const short*)lpbuf1;
  190866. if (destL == 0)
  190867. {
  190868. while (--samples1 >= 0)
  190869. {
  190870. ++src;
  190871. *destR++ = *src++ * g;
  190872. }
  190873. src = (const short*)lpbuf2;
  190874. while (--samples2 >= 0)
  190875. {
  190876. ++src;
  190877. *destR++ = *src++ * g;
  190878. }
  190879. }
  190880. else if (destR == 0)
  190881. {
  190882. while (--samples1 >= 0)
  190883. {
  190884. *destL++ = *src++ * g;
  190885. ++src;
  190886. }
  190887. src = (const short*)lpbuf2;
  190888. while (--samples2 >= 0)
  190889. {
  190890. *destL++ = *src++ * g;
  190891. ++src;
  190892. }
  190893. }
  190894. else
  190895. {
  190896. while (--samples1 >= 0)
  190897. {
  190898. *destL++ = *src++ * g;
  190899. *destR++ = *src++ * g;
  190900. }
  190901. src = (const short*)lpbuf2;
  190902. while (--samples2 >= 0)
  190903. {
  190904. *destL++ = *src++ * g;
  190905. *destR++ = *src++ * g;
  190906. }
  190907. }
  190908. }
  190909. else
  190910. {
  190911. jassertfalse
  190912. }
  190913. readOffset = (readOffset + dwsize1 + dwsize2) % totalBytesPerBuffer;
  190914. pInputBuffer->Unlock (lpbuf1, dwsize1, lpbuf2, dwsize2);
  190915. }
  190916. else
  190917. {
  190918. logError (hr);
  190919. jassertfalse
  190920. }
  190921. bytesFilled -= bytesPerBuffer;
  190922. return true;
  190923. }
  190924. else
  190925. {
  190926. return false;
  190927. }
  190928. }
  190929. };
  190930. class DSoundAudioIODevice : public AudioIODevice,
  190931. public Thread
  190932. {
  190933. public:
  190934. DSoundAudioIODevice (const String& deviceName,
  190935. const int outputDeviceIndex_,
  190936. const int inputDeviceIndex_)
  190937. : AudioIODevice (deviceName, "DirectSound"),
  190938. Thread ("Juce DSound"),
  190939. isOpen_ (false),
  190940. isStarted (false),
  190941. outputDeviceIndex (outputDeviceIndex_),
  190942. inputDeviceIndex (inputDeviceIndex_),
  190943. numInputBuffers (0),
  190944. numOutputBuffers (0),
  190945. totalSamplesOut (0),
  190946. sampleRate (0.0),
  190947. inputBuffers (0),
  190948. outputBuffers (0),
  190949. callback (0),
  190950. bufferSizeSamples (0)
  190951. {
  190952. if (outputDeviceIndex_ >= 0)
  190953. {
  190954. outChannels.add (TRANS("Left"));
  190955. outChannels.add (TRANS("Right"));
  190956. }
  190957. if (inputDeviceIndex_ >= 0)
  190958. {
  190959. inChannels.add (TRANS("Left"));
  190960. inChannels.add (TRANS("Right"));
  190961. }
  190962. }
  190963. ~DSoundAudioIODevice()
  190964. {
  190965. close();
  190966. }
  190967. const StringArray getOutputChannelNames()
  190968. {
  190969. return outChannels;
  190970. }
  190971. const StringArray getInputChannelNames()
  190972. {
  190973. return inChannels;
  190974. }
  190975. int getNumSampleRates()
  190976. {
  190977. return 4;
  190978. }
  190979. double getSampleRate (int index)
  190980. {
  190981. const double samps[] = { 44100.0, 48000.0, 88200.0, 96000.0 };
  190982. return samps [jlimit (0, 3, index)];
  190983. }
  190984. int getNumBufferSizesAvailable()
  190985. {
  190986. return 50;
  190987. }
  190988. int getBufferSizeSamples (int index)
  190989. {
  190990. int n = 64;
  190991. for (int i = 0; i < index; ++i)
  190992. n += (n < 512) ? 32
  190993. : ((n < 1024) ? 64
  190994. : ((n < 2048) ? 128 : 256));
  190995. return n;
  190996. }
  190997. int getDefaultBufferSize()
  190998. {
  190999. return 2560;
  191000. }
  191001. const String open (const BitArray& inputChannels,
  191002. const BitArray& outputChannels,
  191003. double sampleRate,
  191004. int bufferSizeSamples)
  191005. {
  191006. lastError = openDevice (inputChannels, outputChannels, sampleRate, bufferSizeSamples);
  191007. isOpen_ = lastError.isEmpty();
  191008. return lastError;
  191009. }
  191010. void close()
  191011. {
  191012. stop();
  191013. if (isOpen_)
  191014. {
  191015. closeDevice();
  191016. isOpen_ = false;
  191017. }
  191018. }
  191019. bool isOpen()
  191020. {
  191021. return isOpen_ && isThreadRunning();
  191022. }
  191023. int getCurrentBufferSizeSamples()
  191024. {
  191025. return bufferSizeSamples;
  191026. }
  191027. double getCurrentSampleRate()
  191028. {
  191029. return sampleRate;
  191030. }
  191031. int getCurrentBitDepth()
  191032. {
  191033. int i, bits = 256;
  191034. for (i = inChans.size(); --i >= 0;)
  191035. bits = jmin (bits, inChans[i]->bitDepth);
  191036. for (i = outChans.size(); --i >= 0;)
  191037. bits = jmin (bits, outChans[i]->bitDepth);
  191038. if (bits > 32)
  191039. bits = 16;
  191040. return bits;
  191041. }
  191042. const BitArray getActiveOutputChannels() const
  191043. {
  191044. return enabledOutputs;
  191045. }
  191046. const BitArray getActiveInputChannels() const
  191047. {
  191048. return enabledInputs;
  191049. }
  191050. int getOutputLatencyInSamples()
  191051. {
  191052. return (int) (getCurrentBufferSizeSamples() * 1.5);
  191053. }
  191054. int getInputLatencyInSamples()
  191055. {
  191056. return getOutputLatencyInSamples();
  191057. }
  191058. void start (AudioIODeviceCallback* call)
  191059. {
  191060. if (isOpen_ && call != 0 && ! isStarted)
  191061. {
  191062. if (! isThreadRunning())
  191063. {
  191064. // something gone wrong and the thread's stopped..
  191065. isOpen_ = false;
  191066. return;
  191067. }
  191068. call->audioDeviceAboutToStart (this);
  191069. const ScopedLock sl (startStopLock);
  191070. callback = call;
  191071. isStarted = true;
  191072. }
  191073. }
  191074. void stop()
  191075. {
  191076. if (isStarted)
  191077. {
  191078. AudioIODeviceCallback* const callbackLocal = callback;
  191079. {
  191080. const ScopedLock sl (startStopLock);
  191081. isStarted = false;
  191082. }
  191083. if (callbackLocal != 0)
  191084. callbackLocal->audioDeviceStopped();
  191085. }
  191086. }
  191087. bool isPlaying()
  191088. {
  191089. return isStarted && isOpen_ && isThreadRunning();
  191090. }
  191091. const String getLastError()
  191092. {
  191093. return lastError;
  191094. }
  191095. juce_UseDebuggingNewOperator
  191096. StringArray inChannels, outChannels;
  191097. int outputDeviceIndex, inputDeviceIndex;
  191098. private:
  191099. bool isOpen_;
  191100. bool isStarted;
  191101. String lastError;
  191102. OwnedArray <DSoundInternalInChannel> inChans;
  191103. OwnedArray <DSoundInternalOutChannel> outChans;
  191104. WaitableEvent startEvent;
  191105. int numInputBuffers, numOutputBuffers, bufferSizeSamples;
  191106. int volatile totalSamplesOut;
  191107. int64 volatile lastBlockTime;
  191108. double sampleRate;
  191109. BitArray enabledInputs, enabledOutputs;
  191110. HeapBlock <float*> inputBuffers, outputBuffers;
  191111. AudioIODeviceCallback* callback;
  191112. CriticalSection startStopLock;
  191113. DSoundAudioIODevice (const DSoundAudioIODevice&);
  191114. const DSoundAudioIODevice& operator= (const DSoundAudioIODevice&);
  191115. const String openDevice (const BitArray& inputChannels,
  191116. const BitArray& outputChannels,
  191117. double sampleRate_,
  191118. int bufferSizeSamples_);
  191119. void closeDevice()
  191120. {
  191121. isStarted = false;
  191122. stopThread (5000);
  191123. inChans.clear();
  191124. outChans.clear();
  191125. int i;
  191126. for (i = 0; i < numInputBuffers; ++i)
  191127. juce_free (inputBuffers[i]);
  191128. inputBuffers.free();
  191129. numInputBuffers = 0;
  191130. for (i = 0; i < numOutputBuffers; ++i)
  191131. juce_free (outputBuffers[i]);
  191132. outputBuffers.free();
  191133. numOutputBuffers = 0;
  191134. }
  191135. void resync()
  191136. {
  191137. if (! threadShouldExit())
  191138. {
  191139. sleep (5);
  191140. int i;
  191141. for (i = 0; i < outChans.size(); ++i)
  191142. outChans.getUnchecked(i)->synchronisePosition();
  191143. for (i = 0; i < inChans.size(); ++i)
  191144. inChans.getUnchecked(i)->synchronisePosition();
  191145. }
  191146. }
  191147. public:
  191148. void run()
  191149. {
  191150. while (! threadShouldExit())
  191151. {
  191152. if (wait (100))
  191153. break;
  191154. }
  191155. const int latencyMs = (int) (bufferSizeSamples * 1000.0 / sampleRate);
  191156. const int maxTimeMS = jmax (5, 3 * latencyMs);
  191157. while (! threadShouldExit())
  191158. {
  191159. int numToDo = 0;
  191160. uint32 startTime = Time::getMillisecondCounter();
  191161. int i;
  191162. for (i = inChans.size(); --i >= 0;)
  191163. {
  191164. inChans.getUnchecked(i)->doneFlag = false;
  191165. ++numToDo;
  191166. }
  191167. for (i = outChans.size(); --i >= 0;)
  191168. {
  191169. outChans.getUnchecked(i)->doneFlag = false;
  191170. ++numToDo;
  191171. }
  191172. if (numToDo > 0)
  191173. {
  191174. const int maxCount = 3;
  191175. int count = maxCount;
  191176. for (;;)
  191177. {
  191178. for (i = inChans.size(); --i >= 0;)
  191179. {
  191180. DSoundInternalInChannel* const in = inChans.getUnchecked(i);
  191181. if ((! in->doneFlag) && in->service())
  191182. {
  191183. in->doneFlag = true;
  191184. --numToDo;
  191185. }
  191186. }
  191187. for (i = outChans.size(); --i >= 0;)
  191188. {
  191189. DSoundInternalOutChannel* const out = outChans.getUnchecked(i);
  191190. if ((! out->doneFlag) && out->service())
  191191. {
  191192. out->doneFlag = true;
  191193. --numToDo;
  191194. }
  191195. }
  191196. if (numToDo <= 0)
  191197. break;
  191198. if (Time::getMillisecondCounter() > startTime + maxTimeMS)
  191199. {
  191200. resync();
  191201. break;
  191202. }
  191203. if (--count <= 0)
  191204. {
  191205. Sleep (1);
  191206. count = maxCount;
  191207. }
  191208. if (threadShouldExit())
  191209. return;
  191210. }
  191211. }
  191212. else
  191213. {
  191214. sleep (1);
  191215. }
  191216. const ScopedLock sl (startStopLock);
  191217. if (isStarted)
  191218. {
  191219. JUCE_TRY
  191220. {
  191221. callback->audioDeviceIOCallback ((const float**) inputBuffers,
  191222. numInputBuffers,
  191223. outputBuffers,
  191224. numOutputBuffers,
  191225. bufferSizeSamples);
  191226. }
  191227. JUCE_CATCH_EXCEPTION
  191228. totalSamplesOut += bufferSizeSamples;
  191229. }
  191230. else
  191231. {
  191232. for (i = 0; i < numOutputBuffers; ++i)
  191233. if (outputBuffers[i] != 0)
  191234. zeromem (outputBuffers[i], bufferSizeSamples * sizeof (float));
  191235. totalSamplesOut = 0;
  191236. sleep (1);
  191237. }
  191238. }
  191239. }
  191240. };
  191241. class DSoundAudioIODeviceType : public AudioIODeviceType
  191242. {
  191243. public:
  191244. DSoundAudioIODeviceType()
  191245. : AudioIODeviceType (T("DirectSound")),
  191246. hasScanned (false)
  191247. {
  191248. initialiseDSoundFunctions();
  191249. }
  191250. ~DSoundAudioIODeviceType()
  191251. {
  191252. }
  191253. void scanForDevices()
  191254. {
  191255. hasScanned = true;
  191256. outputDeviceNames.clear();
  191257. outputGuids.clear();
  191258. inputDeviceNames.clear();
  191259. inputGuids.clear();
  191260. if (dsDirectSoundEnumerateW != 0)
  191261. {
  191262. dsDirectSoundEnumerateW (outputEnumProcW, this);
  191263. dsDirectSoundCaptureEnumerateW (inputEnumProcW, this);
  191264. }
  191265. }
  191266. const StringArray getDeviceNames (const bool wantInputNames) const
  191267. {
  191268. jassert (hasScanned); // need to call scanForDevices() before doing this
  191269. return wantInputNames ? inputDeviceNames
  191270. : outputDeviceNames;
  191271. }
  191272. int getDefaultDeviceIndex (const bool /*forInput*/) const
  191273. {
  191274. jassert (hasScanned); // need to call scanForDevices() before doing this
  191275. return 0;
  191276. }
  191277. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  191278. {
  191279. jassert (hasScanned); // need to call scanForDevices() before doing this
  191280. DSoundAudioIODevice* const d = dynamic_cast <DSoundAudioIODevice*> (device);
  191281. if (d == 0)
  191282. return -1;
  191283. return asInput ? d->inputDeviceIndex
  191284. : d->outputDeviceIndex;
  191285. }
  191286. bool hasSeparateInputsAndOutputs() const { return true; }
  191287. AudioIODevice* createDevice (const String& outputDeviceName,
  191288. const String& inputDeviceName)
  191289. {
  191290. jassert (hasScanned); // need to call scanForDevices() before doing this
  191291. const int outputIndex = outputDeviceNames.indexOf (outputDeviceName);
  191292. const int inputIndex = inputDeviceNames.indexOf (inputDeviceName);
  191293. if (outputIndex >= 0 || inputIndex >= 0)
  191294. return new DSoundAudioIODevice (outputDeviceName.isNotEmpty() ? outputDeviceName
  191295. : inputDeviceName,
  191296. outputIndex, inputIndex);
  191297. return 0;
  191298. }
  191299. juce_UseDebuggingNewOperator
  191300. StringArray outputDeviceNames;
  191301. OwnedArray <GUID> outputGuids;
  191302. StringArray inputDeviceNames;
  191303. OwnedArray <GUID> inputGuids;
  191304. private:
  191305. bool hasScanned;
  191306. BOOL outputEnumProc (LPGUID lpGUID, String desc)
  191307. {
  191308. desc = desc.trim();
  191309. if (desc.isNotEmpty())
  191310. {
  191311. const String origDesc (desc);
  191312. int n = 2;
  191313. while (outputDeviceNames.contains (desc))
  191314. desc = origDesc + T(" (") + String (n++) + T(")");
  191315. outputDeviceNames.add (desc);
  191316. if (lpGUID != 0)
  191317. outputGuids.add (new GUID (*lpGUID));
  191318. else
  191319. outputGuids.add (0);
  191320. }
  191321. return TRUE;
  191322. }
  191323. static BOOL CALLBACK outputEnumProcW (LPGUID lpGUID, LPCWSTR description, LPCWSTR, LPVOID object)
  191324. {
  191325. return ((DSoundAudioIODeviceType*) object)
  191326. ->outputEnumProc (lpGUID, String (description));
  191327. }
  191328. static BOOL CALLBACK outputEnumProcA (LPGUID lpGUID, LPCTSTR description, LPCTSTR, LPVOID object)
  191329. {
  191330. return ((DSoundAudioIODeviceType*) object)
  191331. ->outputEnumProc (lpGUID, String (description));
  191332. }
  191333. BOOL CALLBACK inputEnumProc (LPGUID lpGUID, String desc)
  191334. {
  191335. desc = desc.trim();
  191336. if (desc.isNotEmpty())
  191337. {
  191338. const String origDesc (desc);
  191339. int n = 2;
  191340. while (inputDeviceNames.contains (desc))
  191341. desc = origDesc + T(" (") + String (n++) + T(")");
  191342. inputDeviceNames.add (desc);
  191343. if (lpGUID != 0)
  191344. inputGuids.add (new GUID (*lpGUID));
  191345. else
  191346. inputGuids.add (0);
  191347. }
  191348. return TRUE;
  191349. }
  191350. static BOOL CALLBACK inputEnumProcW (LPGUID lpGUID, LPCWSTR description, LPCWSTR, LPVOID object)
  191351. {
  191352. return ((DSoundAudioIODeviceType*) object)
  191353. ->inputEnumProc (lpGUID, String (description));
  191354. }
  191355. static BOOL CALLBACK inputEnumProcA (LPGUID lpGUID, LPCTSTR description, LPCTSTR, LPVOID object)
  191356. {
  191357. return ((DSoundAudioIODeviceType*) object)
  191358. ->inputEnumProc (lpGUID, String (description));
  191359. }
  191360. DSoundAudioIODeviceType (const DSoundAudioIODeviceType&);
  191361. const DSoundAudioIODeviceType& operator= (const DSoundAudioIODeviceType&);
  191362. };
  191363. const String DSoundAudioIODevice::openDevice (const BitArray& inputChannels,
  191364. const BitArray& outputChannels,
  191365. double sampleRate_,
  191366. int bufferSizeSamples_)
  191367. {
  191368. closeDevice();
  191369. totalSamplesOut = 0;
  191370. sampleRate = sampleRate_;
  191371. if (bufferSizeSamples_ <= 0)
  191372. bufferSizeSamples_ = 960; // use as a default size if none is set.
  191373. bufferSizeSamples = bufferSizeSamples_ & ~7;
  191374. DSoundAudioIODeviceType dlh;
  191375. dlh.scanForDevices();
  191376. enabledInputs = inputChannels;
  191377. enabledInputs.setRange (inChannels.size(),
  191378. enabledInputs.getHighestBit() + 1 - inChannels.size(),
  191379. false);
  191380. numInputBuffers = enabledInputs.countNumberOfSetBits();
  191381. inputBuffers.calloc (numInputBuffers + 2);
  191382. int i, numIns = 0;
  191383. for (i = 0; i <= enabledInputs.getHighestBit(); i += 2)
  191384. {
  191385. float* left = 0;
  191386. float* right = 0;
  191387. if (enabledInputs[i])
  191388. left = inputBuffers[numIns++] = (float*) juce_calloc ((bufferSizeSamples + 16) * sizeof (float));
  191389. if (enabledInputs[i + 1])
  191390. right = inputBuffers[numIns++] = (float*) juce_calloc ((bufferSizeSamples + 16) * sizeof (float));
  191391. if (left != 0 || right != 0)
  191392. inChans.add (new DSoundInternalInChannel (dlh.inputDeviceNames [inputDeviceIndex],
  191393. dlh.inputGuids [inputDeviceIndex],
  191394. (int) sampleRate, bufferSizeSamples,
  191395. left, right));
  191396. }
  191397. enabledOutputs = outputChannels;
  191398. enabledOutputs.setRange (outChannels.size(),
  191399. enabledOutputs.getHighestBit() + 1 - outChannels.size(),
  191400. false);
  191401. numOutputBuffers = enabledOutputs.countNumberOfSetBits();
  191402. outputBuffers.calloc (numOutputBuffers + 2);
  191403. int numOuts = 0;
  191404. for (i = 0; i <= enabledOutputs.getHighestBit(); i += 2)
  191405. {
  191406. float* left = 0;
  191407. float* right = 0;
  191408. if (enabledOutputs[i])
  191409. left = outputBuffers[numOuts++] = (float*) juce_calloc ((bufferSizeSamples + 16) * sizeof (float));
  191410. if (enabledOutputs[i + 1])
  191411. right = outputBuffers[numOuts++] = (float*) juce_calloc ((bufferSizeSamples + 16) * sizeof (float));
  191412. if (left != 0 || right != 0)
  191413. outChans.add (new DSoundInternalOutChannel (dlh.outputDeviceNames[outputDeviceIndex],
  191414. dlh.outputGuids [outputDeviceIndex],
  191415. (int) sampleRate, bufferSizeSamples,
  191416. left, right));
  191417. }
  191418. String error;
  191419. // boost our priority while opening the devices to try to get better sync between them
  191420. const int oldThreadPri = GetThreadPriority (GetCurrentThread());
  191421. const int oldProcPri = GetPriorityClass (GetCurrentProcess());
  191422. SetThreadPriority (GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL);
  191423. SetPriorityClass (GetCurrentProcess(), REALTIME_PRIORITY_CLASS);
  191424. for (i = 0; i < outChans.size(); ++i)
  191425. {
  191426. error = outChans[i]->open();
  191427. if (error.isNotEmpty())
  191428. {
  191429. error = T("Error opening ") + dlh.outputDeviceNames[i]
  191430. + T(": \"") + error + T("\"");
  191431. break;
  191432. }
  191433. }
  191434. if (error.isEmpty())
  191435. {
  191436. for (i = 0; i < inChans.size(); ++i)
  191437. {
  191438. error = inChans[i]->open();
  191439. if (error.isNotEmpty())
  191440. {
  191441. error = T("Error opening ") + dlh.inputDeviceNames[i]
  191442. + T(": \"") + error + T("\"");
  191443. break;
  191444. }
  191445. }
  191446. }
  191447. if (error.isEmpty())
  191448. {
  191449. totalSamplesOut = 0;
  191450. for (i = 0; i < outChans.size(); ++i)
  191451. outChans.getUnchecked(i)->synchronisePosition();
  191452. for (i = 0; i < inChans.size(); ++i)
  191453. inChans.getUnchecked(i)->synchronisePosition();
  191454. startThread (9);
  191455. sleep (10);
  191456. notify();
  191457. }
  191458. else
  191459. {
  191460. log (error);
  191461. }
  191462. SetThreadPriority (GetCurrentThread(), oldThreadPri);
  191463. SetPriorityClass (GetCurrentProcess(), oldProcPri);
  191464. return error;
  191465. }
  191466. AudioIODeviceType* juce_createAudioIODeviceType_DirectSound()
  191467. {
  191468. return new DSoundAudioIODeviceType();
  191469. }
  191470. #undef log
  191471. #endif
  191472. /*** End of inlined file: juce_win32_DirectSound.cpp ***/
  191473. /*** Start of inlined file: juce_win32_WASAPI.cpp ***/
  191474. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  191475. // compiled on its own).
  191476. #if JUCE_INCLUDED_FILE && JUCE_WASAPI
  191477. #if 1
  191478. const String getAudioErrorDesc (HRESULT hr)
  191479. {
  191480. const char* e = 0;
  191481. switch (hr)
  191482. {
  191483. case E_POINTER: e = "E_POINTER"; break;
  191484. case E_INVALIDARG: e = "E_INVALIDARG"; break;
  191485. case AUDCLNT_E_NOT_INITIALIZED: e = "AUDCLNT_E_NOT_INITIALIZED"; break;
  191486. case AUDCLNT_E_ALREADY_INITIALIZED: e = "AUDCLNT_E_ALREADY_INITIALIZED"; break;
  191487. case AUDCLNT_E_WRONG_ENDPOINT_TYPE: e = "AUDCLNT_E_WRONG_ENDPOINT_TYPE"; break;
  191488. case AUDCLNT_E_DEVICE_INVALIDATED: e = "AUDCLNT_E_DEVICE_INVALIDATED"; break;
  191489. case AUDCLNT_E_NOT_STOPPED: e = "AUDCLNT_E_NOT_STOPPED"; break;
  191490. case AUDCLNT_E_BUFFER_TOO_LARGE: e = "AUDCLNT_E_BUFFER_TOO_LARGE"; break;
  191491. case AUDCLNT_E_OUT_OF_ORDER: e = "AUDCLNT_E_OUT_OF_ORDER"; break;
  191492. case AUDCLNT_E_UNSUPPORTED_FORMAT: e = "AUDCLNT_E_UNSUPPORTED_FORMAT"; break;
  191493. case AUDCLNT_E_INVALID_SIZE: e = "AUDCLNT_E_INVALID_SIZE"; break;
  191494. case AUDCLNT_E_DEVICE_IN_USE: e = "AUDCLNT_E_DEVICE_IN_USE"; break;
  191495. case AUDCLNT_E_BUFFER_OPERATION_PENDING: e = "AUDCLNT_E_BUFFER_OPERATION_PENDING"; break;
  191496. case AUDCLNT_E_THREAD_NOT_REGISTERED: e = "AUDCLNT_E_THREAD_NOT_REGISTERED"; break;
  191497. case AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED: e = "AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED"; break;
  191498. case AUDCLNT_E_ENDPOINT_CREATE_FAILED: e = "AUDCLNT_E_ENDPOINT_CREATE_FAILED"; break;
  191499. case AUDCLNT_E_SERVICE_NOT_RUNNING: e = "AUDCLNT_E_SERVICE_NOT_RUNNING"; break;
  191500. case AUDCLNT_E_EVENTHANDLE_NOT_EXPECTED: e = "AUDCLNT_E_EVENTHANDLE_NOT_EXPECTED"; break;
  191501. case AUDCLNT_E_EXCLUSIVE_MODE_ONLY: e = "AUDCLNT_E_EXCLUSIVE_MODE_ONLY"; break;
  191502. case AUDCLNT_E_BUFDURATION_PERIOD_NOT_EQUAL: e = "AUDCLNT_E_BUFDURATION_PERIOD_NOT_EQUAL"; break;
  191503. case AUDCLNT_E_EVENTHANDLE_NOT_SET: e = "AUDCLNT_E_EVENTHANDLE_NOT_SET"; break;
  191504. case AUDCLNT_E_INCORRECT_BUFFER_SIZE: e = "AUDCLNT_E_INCORRECT_BUFFER_SIZE"; break;
  191505. case AUDCLNT_E_BUFFER_SIZE_ERROR: e = "AUDCLNT_E_BUFFER_SIZE_ERROR"; break;
  191506. case AUDCLNT_S_BUFFER_EMPTY: e = "AUDCLNT_S_BUFFER_EMPTY"; break;
  191507. case AUDCLNT_S_THREAD_ALREADY_REGISTERED: e = "AUDCLNT_S_THREAD_ALREADY_REGISTERED"; break;
  191508. default: return String::toHexString ((int) hr);
  191509. }
  191510. return e;
  191511. }
  191512. #define logFailure(hr) { if (FAILED (hr)) { DBG ("WASAPI FAIL! " + getAudioErrorDesc (hr)); jassertfalse } }
  191513. #define OK(a) wasapi_checkResult(a)
  191514. static bool wasapi_checkResult (HRESULT hr)
  191515. {
  191516. logFailure (hr);
  191517. return SUCCEEDED (hr);
  191518. }
  191519. #else
  191520. #define logFailure(hr) {}
  191521. #define OK(a) SUCCEEDED(a)
  191522. #endif
  191523. static const String wasapi_getDeviceID (IMMDevice* const device)
  191524. {
  191525. String s;
  191526. WCHAR* deviceId = 0;
  191527. if (OK (device->GetId (&deviceId)))
  191528. {
  191529. s = String (deviceId);
  191530. CoTaskMemFree (deviceId);
  191531. }
  191532. return s;
  191533. }
  191534. static EDataFlow wasapi_getDataFlow (IMMDevice* const device)
  191535. {
  191536. EDataFlow flow = eRender;
  191537. ComSmartPtr <IMMEndpoint> endPoint;
  191538. if (OK (device->QueryInterface (__uuidof (IMMEndpoint), (void**) &endPoint)))
  191539. (void) OK (endPoint->GetDataFlow (&flow));
  191540. return flow;
  191541. }
  191542. static int wasapi_refTimeToSamples (const REFERENCE_TIME& t, const double sampleRate) throw()
  191543. {
  191544. return roundDoubleToInt (sampleRate * ((double) t) * 0.0000001);
  191545. }
  191546. static void wasapi_copyWavFormat (WAVEFORMATEXTENSIBLE& dest, const WAVEFORMATEX* const src) throw()
  191547. {
  191548. memcpy (&dest, src, src->wFormatTag == WAVE_FORMAT_EXTENSIBLE ? sizeof (WAVEFORMATEXTENSIBLE)
  191549. : sizeof (WAVEFORMATEX));
  191550. }
  191551. class WASAPIDeviceBase
  191552. {
  191553. public:
  191554. WASAPIDeviceBase (const ComSmartPtr <IMMDevice>& device_, const bool useExclusiveMode_)
  191555. : device (device_),
  191556. sampleRate (0),
  191557. numChannels (0),
  191558. actualNumChannels (0),
  191559. defaultSampleRate (0),
  191560. minBufferSize (0),
  191561. defaultBufferSize (0),
  191562. latencySamples (0),
  191563. useExclusiveMode (useExclusiveMode_)
  191564. {
  191565. clientEvent = CreateEvent (0, false, false, _T("JuceWASAPI"));
  191566. ComSmartPtr <IAudioClient> tempClient (createClient());
  191567. if (tempClient == 0)
  191568. return;
  191569. REFERENCE_TIME defaultPeriod, minPeriod;
  191570. if (! OK (tempClient->GetDevicePeriod (&defaultPeriod, &minPeriod)))
  191571. return;
  191572. WAVEFORMATEX* mixFormat = 0;
  191573. if (! OK (tempClient->GetMixFormat (&mixFormat)))
  191574. return;
  191575. WAVEFORMATEXTENSIBLE format;
  191576. wasapi_copyWavFormat (format, mixFormat);
  191577. CoTaskMemFree (mixFormat);
  191578. actualNumChannels = numChannels = format.Format.nChannels;
  191579. defaultSampleRate = format.Format.nSamplesPerSec;
  191580. minBufferSize = wasapi_refTimeToSamples (minPeriod, defaultSampleRate);
  191581. defaultBufferSize = wasapi_refTimeToSamples (defaultPeriod, defaultSampleRate);
  191582. FloatElementComparator<double> comparator;
  191583. rates.addSorted (comparator, defaultSampleRate);
  191584. static const double ratesToTest[] = { 44100.0, 48000.0, 88200.0, 96000.0 };
  191585. for (int i = 0; i < numElementsInArray (ratesToTest); ++i)
  191586. {
  191587. if (ratesToTest[i] == defaultSampleRate)
  191588. continue;
  191589. format.Format.nSamplesPerSec = roundDoubleToInt (ratesToTest[i]);
  191590. if (SUCCEEDED (tempClient->IsFormatSupported (useExclusiveMode ? AUDCLNT_SHAREMODE_EXCLUSIVE : AUDCLNT_SHAREMODE_SHARED,
  191591. (WAVEFORMATEX*) &format, 0)))
  191592. if (! rates.contains (ratesToTest[i]))
  191593. rates.addSorted (comparator, ratesToTest[i]);
  191594. }
  191595. }
  191596. ~WASAPIDeviceBase()
  191597. {
  191598. device = 0;
  191599. CloseHandle (clientEvent);
  191600. }
  191601. bool isOk() const throw() { return defaultBufferSize > 0 && defaultSampleRate > 0; }
  191602. bool openClient (const double newSampleRate, const BitArray& newChannels)
  191603. {
  191604. sampleRate = newSampleRate;
  191605. channels = newChannels;
  191606. channels.setRange (actualNumChannels, channels.getHighestBit() + 1 - actualNumChannels, false);
  191607. numChannels = channels.getHighestBit() + 1;
  191608. if (numChannels == 0)
  191609. return true;
  191610. client = createClient();
  191611. if (client != 0
  191612. && (tryInitialisingWithFormat (true, 4) || tryInitialisingWithFormat (false, 4)
  191613. || tryInitialisingWithFormat (false, 3) || tryInitialisingWithFormat (false, 2)))
  191614. {
  191615. channelMaps.clear();
  191616. for (int i = 0; i <= channels.getHighestBit(); ++i)
  191617. if (channels[i])
  191618. channelMaps.add (i);
  191619. REFERENCE_TIME latency;
  191620. if (OK (client->GetStreamLatency (&latency)))
  191621. latencySamples = wasapi_refTimeToSamples (latency, sampleRate);
  191622. (void) OK (client->GetBufferSize (&actualBufferSize));
  191623. return OK (client->SetEventHandle (clientEvent));
  191624. }
  191625. return false;
  191626. }
  191627. void closeClient()
  191628. {
  191629. if (client != 0)
  191630. client->Stop();
  191631. client = 0;
  191632. ResetEvent (clientEvent);
  191633. }
  191634. ComSmartPtr <IMMDevice> device;
  191635. ComSmartPtr <IAudioClient> client;
  191636. double sampleRate, defaultSampleRate;
  191637. int numChannels, actualNumChannels;
  191638. int minBufferSize, defaultBufferSize, latencySamples;
  191639. const bool useExclusiveMode;
  191640. Array <double> rates;
  191641. HANDLE clientEvent;
  191642. BitArray channels;
  191643. AudioDataConverters::DataFormat dataFormat;
  191644. Array <int> channelMaps;
  191645. UINT32 actualBufferSize;
  191646. int bytesPerSample;
  191647. private:
  191648. const ComSmartPtr <IAudioClient> createClient()
  191649. {
  191650. ComSmartPtr <IAudioClient> client;
  191651. if (device != 0)
  191652. {
  191653. HRESULT hr = device->Activate (__uuidof (IAudioClient), CLSCTX_INPROC_SERVER, 0, (void**) &client);
  191654. logFailure (hr);
  191655. }
  191656. return client;
  191657. }
  191658. bool tryInitialisingWithFormat (const bool useFloat, const int bytesPerSampleToTry)
  191659. {
  191660. WAVEFORMATEXTENSIBLE format;
  191661. zerostruct (format);
  191662. if (numChannels <= 2 && bytesPerSampleToTry <= 2)
  191663. {
  191664. format.Format.wFormatTag = WAVE_FORMAT_PCM;
  191665. }
  191666. else
  191667. {
  191668. format.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE;
  191669. format.Format.cbSize = sizeof (WAVEFORMATEXTENSIBLE) - sizeof (WAVEFORMATEX);
  191670. }
  191671. format.Format.nSamplesPerSec = roundDoubleToInt (sampleRate);
  191672. format.Format.nChannels = (WORD) numChannels;
  191673. format.Format.wBitsPerSample = (WORD) (8 * bytesPerSampleToTry);
  191674. format.Format.nAvgBytesPerSec = (DWORD) (format.Format.nSamplesPerSec * numChannels * bytesPerSampleToTry);
  191675. format.Format.nBlockAlign = (WORD) (numChannels * bytesPerSampleToTry);
  191676. format.SubFormat = useFloat ? KSDATAFORMAT_SUBTYPE_IEEE_FLOAT : KSDATAFORMAT_SUBTYPE_PCM;
  191677. format.Samples.wValidBitsPerSample = format.Format.wBitsPerSample;
  191678. switch (numChannels)
  191679. {
  191680. case 1: format.dwChannelMask = SPEAKER_FRONT_CENTER; break;
  191681. case 2: format.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT; break;
  191682. case 4: format.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT; break;
  191683. case 6: format.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_FRONT_CENTER | SPEAKER_LOW_FREQUENCY | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT; break;
  191684. 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;
  191685. default: break;
  191686. }
  191687. WAVEFORMATEXTENSIBLE* nearestFormat = 0;
  191688. HRESULT hr = client->IsFormatSupported (useExclusiveMode ? AUDCLNT_SHAREMODE_EXCLUSIVE : AUDCLNT_SHAREMODE_SHARED,
  191689. (WAVEFORMATEX*) &format, useExclusiveMode ? 0 : (WAVEFORMATEX**) &nearestFormat);
  191690. logFailure (hr);
  191691. if (hr == S_FALSE && format.Format.nSamplesPerSec == nearestFormat->Format.nSamplesPerSec)
  191692. {
  191693. wasapi_copyWavFormat (format, (WAVEFORMATEX*) nearestFormat);
  191694. hr = S_OK;
  191695. }
  191696. CoTaskMemFree (nearestFormat);
  191697. REFERENCE_TIME defaultPeriod = 0, minPeriod = 0;
  191698. if (useExclusiveMode)
  191699. OK (client->GetDevicePeriod (&defaultPeriod, &minPeriod));
  191700. GUID session;
  191701. if (hr == S_OK
  191702. && OK (client->Initialize (useExclusiveMode ? AUDCLNT_SHAREMODE_EXCLUSIVE : AUDCLNT_SHAREMODE_SHARED,
  191703. AUDCLNT_STREAMFLAGS_EVENTCALLBACK,
  191704. defaultPeriod, defaultPeriod, (WAVEFORMATEX*) &format, &session)))
  191705. {
  191706. actualNumChannels = format.Format.nChannels;
  191707. const bool isFloat = format.Format.wFormatTag == WAVE_FORMAT_EXTENSIBLE && format.SubFormat == KSDATAFORMAT_SUBTYPE_IEEE_FLOAT;
  191708. bytesPerSample = format.Format.wBitsPerSample / 8;
  191709. dataFormat = isFloat ? AudioDataConverters::float32LE
  191710. : (bytesPerSample == 4 ? AudioDataConverters::int32LE
  191711. : ((bytesPerSample == 3 ? AudioDataConverters::int24LE
  191712. : AudioDataConverters::int16LE)));
  191713. return true;
  191714. }
  191715. return false;
  191716. }
  191717. };
  191718. class WASAPIInputDevice : public WASAPIDeviceBase
  191719. {
  191720. public:
  191721. WASAPIInputDevice (const ComSmartPtr <IMMDevice>& device_, const bool useExclusiveMode_)
  191722. : WASAPIDeviceBase (device_, useExclusiveMode_),
  191723. reservoir (1, 1)
  191724. {
  191725. }
  191726. ~WASAPIInputDevice()
  191727. {
  191728. close();
  191729. }
  191730. bool open (const double newSampleRate, const BitArray& newChannels)
  191731. {
  191732. reservoirSize = 0;
  191733. reservoirCapacity = 16384;
  191734. reservoir.setSize (actualNumChannels * reservoirCapacity * sizeof (float));
  191735. return openClient (newSampleRate, newChannels)
  191736. && (numChannels == 0 || OK (client->GetService (__uuidof (IAudioCaptureClient), (void**) &captureClient)));
  191737. }
  191738. void close()
  191739. {
  191740. closeClient();
  191741. captureClient = 0;
  191742. reservoir.setSize (0);
  191743. }
  191744. void copyBuffers (float** destBuffers, int numDestBuffers, int bufferSize, Thread& thread)
  191745. {
  191746. if (numChannels <= 0)
  191747. return;
  191748. int offset = 0;
  191749. while (bufferSize > 0)
  191750. {
  191751. if (reservoirSize > 0) // There's stuff in the reservoir, so use that...
  191752. {
  191753. const int samplesToDo = jmin (bufferSize, (int) reservoirSize);
  191754. for (int i = 0; i < numDestBuffers; ++i)
  191755. {
  191756. float* const dest = destBuffers[i] + offset;
  191757. const int srcChan = channelMaps.getUnchecked(i);
  191758. switch (dataFormat)
  191759. {
  191760. case AudioDataConverters::float32LE:
  191761. AudioDataConverters::convertFloat32LEToFloat (((uint8*) reservoir.getData()) + 4 * srcChan, dest, samplesToDo, 4 * actualNumChannels);
  191762. break;
  191763. case AudioDataConverters::int32LE:
  191764. AudioDataConverters::convertInt32LEToFloat (((uint8*) reservoir.getData()) + 4 * srcChan, dest, samplesToDo, 4 * actualNumChannels);
  191765. break;
  191766. case AudioDataConverters::int24LE:
  191767. AudioDataConverters::convertInt24LEToFloat (((uint8*) reservoir.getData()) + 3 * srcChan, dest, samplesToDo, 3 * actualNumChannels);
  191768. break;
  191769. case AudioDataConverters::int16LE:
  191770. AudioDataConverters::convertInt16LEToFloat (((uint8*) reservoir.getData()) + 2 * srcChan, dest, samplesToDo, 2 * actualNumChannels);
  191771. break;
  191772. default: jassertfalse; break;
  191773. }
  191774. }
  191775. bufferSize -= samplesToDo;
  191776. offset += samplesToDo;
  191777. reservoirSize -= samplesToDo;
  191778. }
  191779. else
  191780. {
  191781. UINT32 packetLength = 0;
  191782. if (! OK (captureClient->GetNextPacketSize (&packetLength)))
  191783. break;
  191784. if (packetLength == 0)
  191785. {
  191786. if (thread.threadShouldExit())
  191787. break;
  191788. Thread::sleep (1);
  191789. continue;
  191790. }
  191791. uint8* inputData = 0;
  191792. UINT32 numSamplesAvailable;
  191793. DWORD flags;
  191794. if (OK (captureClient->GetBuffer (&inputData, &numSamplesAvailable, &flags, 0, 0)))
  191795. {
  191796. const int samplesToDo = jmin (bufferSize, (int) numSamplesAvailable);
  191797. for (int i = 0; i < numDestBuffers; ++i)
  191798. {
  191799. float* const dest = destBuffers[i] + offset;
  191800. const int srcChan = channelMaps.getUnchecked(i);
  191801. switch (dataFormat)
  191802. {
  191803. case AudioDataConverters::float32LE:
  191804. AudioDataConverters::convertFloat32LEToFloat (inputData + 4 * srcChan, dest, samplesToDo, 4 * actualNumChannels);
  191805. break;
  191806. case AudioDataConverters::int32LE:
  191807. AudioDataConverters::convertInt32LEToFloat (inputData + 4 * srcChan, dest, samplesToDo, 4 * actualNumChannels);
  191808. break;
  191809. case AudioDataConverters::int24LE:
  191810. AudioDataConverters::convertInt24LEToFloat (inputData + 3 * srcChan, dest, samplesToDo, 3 * actualNumChannels);
  191811. break;
  191812. case AudioDataConverters::int16LE:
  191813. AudioDataConverters::convertInt16LEToFloat (inputData + 2 * srcChan, dest, samplesToDo, 2 * actualNumChannels);
  191814. break;
  191815. default: jassertfalse; break;
  191816. }
  191817. }
  191818. bufferSize -= samplesToDo;
  191819. offset += samplesToDo;
  191820. if (samplesToDo < (int) numSamplesAvailable)
  191821. {
  191822. reservoirSize = jmin ((int) (numSamplesAvailable - samplesToDo), reservoirCapacity);
  191823. memcpy ((uint8*) reservoir.getData(), inputData + bytesPerSample * actualNumChannels * samplesToDo,
  191824. bytesPerSample * actualNumChannels * reservoirSize);
  191825. }
  191826. captureClient->ReleaseBuffer (numSamplesAvailable);
  191827. }
  191828. }
  191829. }
  191830. }
  191831. ComSmartPtr <IAudioCaptureClient> captureClient;
  191832. MemoryBlock reservoir;
  191833. int reservoirSize, reservoirCapacity;
  191834. };
  191835. class WASAPIOutputDevice : public WASAPIDeviceBase
  191836. {
  191837. public:
  191838. WASAPIOutputDevice (const ComSmartPtr <IMMDevice>& device_, const bool useExclusiveMode_)
  191839. : WASAPIDeviceBase (device_, useExclusiveMode_)
  191840. {
  191841. }
  191842. ~WASAPIOutputDevice()
  191843. {
  191844. close();
  191845. }
  191846. bool open (const double newSampleRate, const BitArray& newChannels)
  191847. {
  191848. return openClient (newSampleRate, newChannels)
  191849. && (numChannels == 0 || OK (client->GetService (__uuidof (IAudioRenderClient), (void**) &renderClient)));
  191850. }
  191851. void close()
  191852. {
  191853. closeClient();
  191854. renderClient = 0;
  191855. }
  191856. void copyBuffers (const float** const srcBuffers, const int numSrcBuffers, int bufferSize, Thread& thread)
  191857. {
  191858. if (numChannels <= 0)
  191859. return;
  191860. int offset = 0;
  191861. while (bufferSize > 0)
  191862. {
  191863. UINT32 padding = 0;
  191864. if (! OK (client->GetCurrentPadding (&padding)))
  191865. return;
  191866. int samplesToDo = useExclusiveMode ? bufferSize
  191867. : jmin ((int) (actualBufferSize - padding), bufferSize);
  191868. if (samplesToDo <= 0)
  191869. {
  191870. if (thread.threadShouldExit())
  191871. break;
  191872. Thread::sleep (0);
  191873. continue;
  191874. }
  191875. uint8* outputData = 0;
  191876. if (OK (renderClient->GetBuffer (samplesToDo, &outputData)))
  191877. {
  191878. for (int i = 0; i < numSrcBuffers; ++i)
  191879. {
  191880. const float* const source = srcBuffers[i] + offset;
  191881. const int destChan = channelMaps.getUnchecked(i);
  191882. switch (dataFormat)
  191883. {
  191884. case AudioDataConverters::float32LE:
  191885. AudioDataConverters::convertFloatToFloat32LE (source, outputData + 4 * destChan, samplesToDo, 4 * actualNumChannels);
  191886. break;
  191887. case AudioDataConverters::int32LE:
  191888. AudioDataConverters::convertFloatToInt32LE (source, outputData + 4 * destChan, samplesToDo, 4 * actualNumChannels);
  191889. break;
  191890. case AudioDataConverters::int24LE:
  191891. AudioDataConverters::convertFloatToInt24LE (source, outputData + 3 * destChan, samplesToDo, 3 * actualNumChannels);
  191892. break;
  191893. case AudioDataConverters::int16LE:
  191894. AudioDataConverters::convertFloatToInt16LE (source, outputData + 2 * destChan, samplesToDo, 2 * actualNumChannels);
  191895. break;
  191896. default: jassertfalse; break;
  191897. }
  191898. }
  191899. renderClient->ReleaseBuffer (samplesToDo, 0);
  191900. offset += samplesToDo;
  191901. bufferSize -= samplesToDo;
  191902. }
  191903. }
  191904. }
  191905. ComSmartPtr <IAudioRenderClient> renderClient;
  191906. };
  191907. class WASAPIAudioIODevice : public AudioIODevice,
  191908. public Thread
  191909. {
  191910. public:
  191911. WASAPIAudioIODevice (const String& deviceName,
  191912. const String& outputDeviceId_,
  191913. const String& inputDeviceId_,
  191914. const bool useExclusiveMode_)
  191915. : AudioIODevice (deviceName, "Windows Audio"),
  191916. Thread ("Juce WASAPI"),
  191917. isOpen_ (false),
  191918. isStarted (false),
  191919. outputDevice (0),
  191920. outputDeviceId (outputDeviceId_),
  191921. inputDevice (0),
  191922. inputDeviceId (inputDeviceId_),
  191923. useExclusiveMode (useExclusiveMode_),
  191924. currentBufferSizeSamples (0),
  191925. currentSampleRate (0),
  191926. callback (0)
  191927. {
  191928. }
  191929. ~WASAPIAudioIODevice()
  191930. {
  191931. close();
  191932. deleteAndZero (inputDevice);
  191933. deleteAndZero (outputDevice);
  191934. }
  191935. bool initialise()
  191936. {
  191937. double defaultSampleRateIn = 0, defaultSampleRateOut = 0;
  191938. int minBufferSizeIn = 0, defaultBufferSizeIn = 0, minBufferSizeOut = 0, defaultBufferSizeOut = 0;
  191939. latencyIn = latencyOut = 0;
  191940. Array <double> ratesIn, ratesOut;
  191941. if (createDevices())
  191942. {
  191943. jassert (inputDevice != 0 || outputDevice != 0);
  191944. if (inputDevice != 0 && outputDevice != 0)
  191945. {
  191946. defaultSampleRate = jmin (inputDevice->defaultSampleRate, outputDevice->defaultSampleRate);
  191947. minBufferSize = jmin (inputDevice->minBufferSize, outputDevice->minBufferSize);
  191948. defaultBufferSize = jmax (inputDevice->defaultBufferSize, outputDevice->defaultBufferSize);
  191949. sampleRates = inputDevice->rates;
  191950. sampleRates.removeValuesNotIn (outputDevice->rates);
  191951. }
  191952. else
  191953. {
  191954. WASAPIDeviceBase* const d = inputDevice != 0 ? (WASAPIDeviceBase*) inputDevice : (WASAPIDeviceBase*) outputDevice;
  191955. defaultSampleRate = d->defaultSampleRate;
  191956. minBufferSize = d->minBufferSize;
  191957. defaultBufferSize = d->defaultBufferSize;
  191958. sampleRates = d->rates;
  191959. }
  191960. IntegerElementComparator<int> comparator;
  191961. bufferSizes.addSorted (comparator, defaultBufferSize);
  191962. if (minBufferSize != defaultBufferSize)
  191963. bufferSizes.addSorted (comparator, minBufferSize);
  191964. int n = 64;
  191965. for (int i = 0; i < 40; ++i)
  191966. {
  191967. if (n >= minBufferSize && n <= 2048 && ! bufferSizes.contains (n))
  191968. bufferSizes.addSorted (comparator, n);
  191969. n += (n < 512) ? 32 : (n < 1024 ? 64 : 128);
  191970. }
  191971. return true;
  191972. }
  191973. return false;
  191974. }
  191975. const StringArray getOutputChannelNames()
  191976. {
  191977. StringArray outChannels;
  191978. if (outputDevice != 0)
  191979. for (int i = 1; i <= outputDevice->actualNumChannels; ++i)
  191980. outChannels.add ("Output channel " + String (i));
  191981. return outChannels;
  191982. }
  191983. const StringArray getInputChannelNames()
  191984. {
  191985. StringArray inChannels;
  191986. if (inputDevice != 0)
  191987. for (int i = 1; i <= inputDevice->actualNumChannels; ++i)
  191988. inChannels.add ("Input channel " + String (i));
  191989. return inChannels;
  191990. }
  191991. int getNumSampleRates() { return sampleRates.size(); }
  191992. double getSampleRate (int index) { return sampleRates [index]; }
  191993. int getNumBufferSizesAvailable() { return bufferSizes.size(); }
  191994. int getBufferSizeSamples (int index) { return bufferSizes [index]; }
  191995. int getDefaultBufferSize() { return defaultBufferSize; }
  191996. int getCurrentBufferSizeSamples() { return currentBufferSizeSamples; }
  191997. double getCurrentSampleRate() { return currentSampleRate; }
  191998. int getCurrentBitDepth() { return 32; }
  191999. int getOutputLatencyInSamples() { return latencyOut; }
  192000. int getInputLatencyInSamples() { return latencyIn; }
  192001. const BitArray getActiveOutputChannels() const { return outputDevice != 0 ? outputDevice->channels : BitArray(); }
  192002. const BitArray getActiveInputChannels() const { return inputDevice != 0 ? inputDevice->channels : BitArray(); }
  192003. const String getLastError() { return lastError; }
  192004. const String open (const BitArray& inputChannels, const BitArray& outputChannels,
  192005. double sampleRate, int bufferSizeSamples)
  192006. {
  192007. close();
  192008. lastError = String::empty;
  192009. if (sampleRates.size() == 0 && inputDevice != 0 && outputDevice != 0)
  192010. {
  192011. lastError = "The input and output devices don't share a common sample rate!";
  192012. return lastError;
  192013. }
  192014. currentBufferSizeSamples = bufferSizeSamples <= 0 ? defaultBufferSize : jmax (bufferSizeSamples, minBufferSize);
  192015. currentSampleRate = sampleRate > 0 ? sampleRate : defaultSampleRate;
  192016. if (inputDevice != 0 && ! inputDevice->open (currentSampleRate, inputChannels))
  192017. {
  192018. lastError = "Couldn't open the input device!";
  192019. return lastError;
  192020. }
  192021. if (outputDevice != 0 && ! outputDevice->open (currentSampleRate, outputChannels))
  192022. {
  192023. close();
  192024. lastError = "Couldn't open the output device!";
  192025. return lastError;
  192026. }
  192027. if (inputDevice != 0)
  192028. ResetEvent (inputDevice->clientEvent);
  192029. if (outputDevice != 0)
  192030. ResetEvent (outputDevice->clientEvent);
  192031. startThread (8);
  192032. Thread::sleep (5);
  192033. if (inputDevice != 0 && inputDevice->client != 0)
  192034. {
  192035. latencyIn = inputDevice->latencySamples + inputDevice->actualBufferSize + inputDevice->minBufferSize;
  192036. HRESULT hr = inputDevice->client->Start();
  192037. logFailure (hr); //xxx handle this
  192038. }
  192039. if (outputDevice != 0 && outputDevice->client != 0)
  192040. {
  192041. latencyOut = outputDevice->latencySamples + outputDevice->actualBufferSize + outputDevice->minBufferSize;
  192042. HRESULT hr = outputDevice->client->Start();
  192043. logFailure (hr); //xxx handle this
  192044. }
  192045. isOpen_ = true;
  192046. return lastError;
  192047. }
  192048. void close()
  192049. {
  192050. stop();
  192051. if (inputDevice != 0)
  192052. SetEvent (inputDevice->clientEvent);
  192053. if (outputDevice != 0)
  192054. SetEvent (outputDevice->clientEvent);
  192055. stopThread (5000);
  192056. if (inputDevice != 0)
  192057. inputDevice->close();
  192058. if (outputDevice != 0)
  192059. outputDevice->close();
  192060. isOpen_ = false;
  192061. }
  192062. bool isOpen() { return isOpen_ && isThreadRunning(); }
  192063. bool isPlaying() { return isStarted && isOpen_ && isThreadRunning(); }
  192064. void start (AudioIODeviceCallback* call)
  192065. {
  192066. if (isOpen_ && call != 0 && ! isStarted)
  192067. {
  192068. if (! isThreadRunning())
  192069. {
  192070. // something's gone wrong and the thread's stopped..
  192071. isOpen_ = false;
  192072. return;
  192073. }
  192074. call->audioDeviceAboutToStart (this);
  192075. const ScopedLock sl (startStopLock);
  192076. callback = call;
  192077. isStarted = true;
  192078. }
  192079. }
  192080. void stop()
  192081. {
  192082. if (isStarted)
  192083. {
  192084. AudioIODeviceCallback* const callbackLocal = callback;
  192085. {
  192086. const ScopedLock sl (startStopLock);
  192087. isStarted = false;
  192088. }
  192089. if (callbackLocal != 0)
  192090. callbackLocal->audioDeviceStopped();
  192091. }
  192092. }
  192093. void setMMThreadPriority()
  192094. {
  192095. DynamicLibraryLoader dll ("avrt.dll");
  192096. DynamicLibraryImport (AvSetMmThreadCharacteristics, avSetMmThreadCharacteristics, HANDLE, dll, (LPCTSTR, LPDWORD))
  192097. DynamicLibraryImport (AvSetMmThreadPriority, avSetMmThreadPriority, HANDLE, dll, (HANDLE, AVRT_PRIORITY))
  192098. if (avSetMmThreadCharacteristics != 0 && avSetMmThreadPriority != 0)
  192099. {
  192100. DWORD dummy = 0;
  192101. HANDLE h = avSetMmThreadCharacteristics (_T("Pro Audio"), &dummy);
  192102. if (h != 0)
  192103. avSetMmThreadPriority (h, AVRT_PRIORITY_NORMAL);
  192104. }
  192105. }
  192106. void run()
  192107. {
  192108. setMMThreadPriority();
  192109. const int bufferSize = currentBufferSizeSamples;
  192110. HANDLE events[2];
  192111. int numEvents = 0;
  192112. if (inputDevice != 0)
  192113. events [numEvents++] = inputDevice->clientEvent;
  192114. if (outputDevice != 0)
  192115. events [numEvents++] = outputDevice->clientEvent;
  192116. const int numInputBuffers = getActiveInputChannels().countNumberOfSetBits();
  192117. const int numOutputBuffers = getActiveOutputChannels().countNumberOfSetBits();
  192118. AudioSampleBuffer ins (jmax (1, numInputBuffers), bufferSize + 32);
  192119. AudioSampleBuffer outs (jmax (1, numOutputBuffers), bufferSize + 32);
  192120. float** const inputBuffers = ins.getArrayOfChannels();
  192121. float** const outputBuffers = outs.getArrayOfChannels();
  192122. ins.clear();
  192123. while (! threadShouldExit())
  192124. {
  192125. const DWORD result = useExclusiveMode ? WaitForSingleObject (inputDevice->clientEvent, 1000)
  192126. : WaitForMultipleObjects (numEvents, events, true, 1000);
  192127. if (result == WAIT_TIMEOUT)
  192128. continue;
  192129. if (threadShouldExit())
  192130. break;
  192131. if (inputDevice != 0)
  192132. inputDevice->copyBuffers (inputBuffers, numInputBuffers, bufferSize, *this);
  192133. // Make the callback..
  192134. {
  192135. const ScopedLock sl (startStopLock);
  192136. if (isStarted)
  192137. {
  192138. JUCE_TRY
  192139. {
  192140. callback->audioDeviceIOCallback ((const float**) inputBuffers,
  192141. numInputBuffers,
  192142. outputBuffers,
  192143. numOutputBuffers,
  192144. bufferSize);
  192145. }
  192146. JUCE_CATCH_EXCEPTION
  192147. }
  192148. else
  192149. {
  192150. outs.clear();
  192151. }
  192152. }
  192153. if (useExclusiveMode && WaitForSingleObject (outputDevice->clientEvent, 1000) == WAIT_TIMEOUT)
  192154. continue;
  192155. if (outputDevice != 0)
  192156. outputDevice->copyBuffers ((const float**) outputBuffers, numOutputBuffers, bufferSize, *this);
  192157. }
  192158. }
  192159. juce_UseDebuggingNewOperator
  192160. String outputDeviceId, inputDeviceId;
  192161. String lastError;
  192162. private:
  192163. // Device stats...
  192164. WASAPIInputDevice* inputDevice;
  192165. WASAPIOutputDevice* outputDevice;
  192166. const bool useExclusiveMode;
  192167. double defaultSampleRate;
  192168. int minBufferSize, defaultBufferSize;
  192169. int latencyIn, latencyOut;
  192170. Array <double> sampleRates;
  192171. Array <int> bufferSizes;
  192172. // Active state...
  192173. bool isOpen_, isStarted;
  192174. int currentBufferSizeSamples;
  192175. double currentSampleRate;
  192176. AudioIODeviceCallback* callback;
  192177. CriticalSection startStopLock;
  192178. bool createDevices()
  192179. {
  192180. ComSmartPtr <IMMDeviceEnumerator> enumerator;
  192181. if (! OK (enumerator.CoCreateInstance (__uuidof (MMDeviceEnumerator), CLSCTX_INPROC_SERVER)))
  192182. return false;
  192183. ComSmartPtr <IMMDeviceCollection> deviceCollection;
  192184. if (! OK (enumerator->EnumAudioEndpoints (eAll, DEVICE_STATE_ACTIVE, &deviceCollection)))
  192185. return false;
  192186. UINT32 numDevices = 0;
  192187. if (! OK (deviceCollection->GetCount (&numDevices)))
  192188. return false;
  192189. for (UINT32 i = 0; i < numDevices; ++i)
  192190. {
  192191. ComSmartPtr <IMMDevice> device;
  192192. if (! OK (deviceCollection->Item (i, &device)))
  192193. continue;
  192194. const String deviceId (wasapi_getDeviceID (device));
  192195. if (deviceId.isEmpty())
  192196. continue;
  192197. const EDataFlow flow = wasapi_getDataFlow (device);
  192198. if (deviceId == inputDeviceId && flow == eCapture)
  192199. inputDevice = new WASAPIInputDevice (device, useExclusiveMode);
  192200. else if (deviceId == outputDeviceId && flow == eRender)
  192201. outputDevice = new WASAPIOutputDevice (device, useExclusiveMode);
  192202. }
  192203. return (outputDeviceId.isEmpty() || (outputDevice != 0 && outputDevice->isOk()))
  192204. && (inputDeviceId.isEmpty() || (inputDevice != 0 && inputDevice->isOk()));
  192205. }
  192206. WASAPIAudioIODevice (const WASAPIAudioIODevice&);
  192207. const WASAPIAudioIODevice& operator= (const WASAPIAudioIODevice&);
  192208. };
  192209. class WASAPIAudioIODeviceType : public AudioIODeviceType
  192210. {
  192211. public:
  192212. WASAPIAudioIODeviceType()
  192213. : AudioIODeviceType (T("Windows Audio")),
  192214. hasScanned (false)
  192215. {
  192216. }
  192217. ~WASAPIAudioIODeviceType()
  192218. {
  192219. }
  192220. void scanForDevices()
  192221. {
  192222. hasScanned = true;
  192223. outputDeviceNames.clear();
  192224. inputDeviceNames.clear();
  192225. outputDeviceIds.clear();
  192226. inputDeviceIds.clear();
  192227. ComSmartPtr <IMMDeviceEnumerator> enumerator;
  192228. if (! OK (enumerator.CoCreateInstance (__uuidof (MMDeviceEnumerator), CLSCTX_INPROC_SERVER)))
  192229. return;
  192230. const String defaultRenderer = getDefaultEndpoint (enumerator, false);
  192231. const String defaultCapture = getDefaultEndpoint (enumerator, true);
  192232. ComSmartPtr <IMMDeviceCollection> deviceCollection;
  192233. UINT32 numDevices = 0;
  192234. if (! (OK (enumerator->EnumAudioEndpoints (eAll, DEVICE_STATE_ACTIVE, &deviceCollection))
  192235. && OK (deviceCollection->GetCount (&numDevices))))
  192236. return;
  192237. for (UINT32 i = 0; i < numDevices; ++i)
  192238. {
  192239. ComSmartPtr <IMMDevice> device;
  192240. if (! OK (deviceCollection->Item (i, &device)))
  192241. continue;
  192242. const String deviceId (wasapi_getDeviceID (device));
  192243. DWORD state = 0;
  192244. if (! OK (device->GetState (&state)))
  192245. continue;
  192246. if (state != DEVICE_STATE_ACTIVE)
  192247. continue;
  192248. String name;
  192249. {
  192250. ComSmartPtr <IPropertyStore> properties;
  192251. if (! OK (device->OpenPropertyStore (STGM_READ, &properties)))
  192252. continue;
  192253. PROPVARIANT value;
  192254. PropVariantInit (&value);
  192255. if (OK (properties->GetValue (PKEY_Device_FriendlyName, &value)))
  192256. name = value.pwszVal;
  192257. PropVariantClear (&value);
  192258. }
  192259. const EDataFlow flow = wasapi_getDataFlow (device);
  192260. if (flow == eRender)
  192261. {
  192262. const int index = (deviceId == defaultRenderer) ? 0 : -1;
  192263. outputDeviceIds.insert (index, deviceId);
  192264. outputDeviceNames.insert (index, name);
  192265. }
  192266. else if (flow == eCapture)
  192267. {
  192268. const int index = (deviceId == defaultCapture) ? 0 : -1;
  192269. inputDeviceIds.insert (index, deviceId);
  192270. inputDeviceNames.insert (index, name);
  192271. }
  192272. }
  192273. inputDeviceNames.appendNumbersToDuplicates (false, false);
  192274. outputDeviceNames.appendNumbersToDuplicates (false, false);
  192275. }
  192276. const StringArray getDeviceNames (const bool wantInputNames) const
  192277. {
  192278. jassert (hasScanned); // need to call scanForDevices() before doing this
  192279. return wantInputNames ? inputDeviceNames
  192280. : outputDeviceNames;
  192281. }
  192282. int getDefaultDeviceIndex (const bool /*forInput*/) const
  192283. {
  192284. jassert (hasScanned); // need to call scanForDevices() before doing this
  192285. return 0;
  192286. }
  192287. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  192288. {
  192289. jassert (hasScanned); // need to call scanForDevices() before doing this
  192290. WASAPIAudioIODevice* const d = dynamic_cast <WASAPIAudioIODevice*> (device);
  192291. return d == 0 ? -1 : (asInput ? inputDeviceIds.indexOf (d->inputDeviceId)
  192292. : outputDeviceIds.indexOf (d->outputDeviceId));
  192293. }
  192294. bool hasSeparateInputsAndOutputs() const { return true; }
  192295. AudioIODevice* createDevice (const String& outputDeviceName,
  192296. const String& inputDeviceName)
  192297. {
  192298. jassert (hasScanned); // need to call scanForDevices() before doing this
  192299. const bool useExclusiveMode = false;
  192300. WASAPIAudioIODevice* d = 0;
  192301. const int outputIndex = outputDeviceNames.indexOf (outputDeviceName);
  192302. const int inputIndex = inputDeviceNames.indexOf (inputDeviceName);
  192303. if (outputIndex >= 0 || inputIndex >= 0)
  192304. {
  192305. d = new WASAPIAudioIODevice (outputDeviceName.isNotEmpty() ? outputDeviceName
  192306. : inputDeviceName,
  192307. outputDeviceIds [outputIndex],
  192308. inputDeviceIds [inputIndex],
  192309. useExclusiveMode);
  192310. if (! d->initialise())
  192311. deleteAndZero (d);
  192312. }
  192313. return d;
  192314. }
  192315. juce_UseDebuggingNewOperator
  192316. StringArray outputDeviceNames, outputDeviceIds;
  192317. StringArray inputDeviceNames, inputDeviceIds;
  192318. private:
  192319. bool hasScanned;
  192320. static const String getDefaultEndpoint (IMMDeviceEnumerator* const enumerator, const bool forCapture)
  192321. {
  192322. String s;
  192323. IMMDevice* dev = 0;
  192324. if (OK (enumerator->GetDefaultAudioEndpoint (forCapture ? eCapture : eRender,
  192325. eMultimedia, &dev)))
  192326. {
  192327. WCHAR* deviceId = 0;
  192328. if (OK (dev->GetId (&deviceId)))
  192329. {
  192330. s = String (deviceId);
  192331. CoTaskMemFree (deviceId);
  192332. }
  192333. dev->Release();
  192334. }
  192335. return s;
  192336. }
  192337. WASAPIAudioIODeviceType (const WASAPIAudioIODeviceType&);
  192338. const WASAPIAudioIODeviceType& operator= (const WASAPIAudioIODeviceType&);
  192339. };
  192340. AudioIODeviceType* juce_createAudioIODeviceType_WASAPI()
  192341. {
  192342. return new WASAPIAudioIODeviceType();
  192343. }
  192344. #undef logFailure
  192345. #undef OK
  192346. #endif
  192347. /*** End of inlined file: juce_win32_WASAPI.cpp ***/
  192348. /*** Start of inlined file: juce_win32_CameraDevice.cpp ***/
  192349. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  192350. // compiled on its own).
  192351. #if JUCE_INCLUDED_FILE && JUCE_USE_CAMERA
  192352. class DShowCameraDeviceInteral : public ChangeBroadcaster
  192353. {
  192354. public:
  192355. DShowCameraDeviceInteral (CameraDevice* const owner_,
  192356. const ComSmartPtr <ICaptureGraphBuilder2>& captureGraphBuilder_,
  192357. const ComSmartPtr <IBaseFilter>& filter_,
  192358. int minWidth, int minHeight,
  192359. int maxWidth, int maxHeight)
  192360. : owner (owner_),
  192361. captureGraphBuilder (captureGraphBuilder_),
  192362. filter (filter_),
  192363. ok (false),
  192364. imageNeedsFlipping (false),
  192365. width (0),
  192366. height (0),
  192367. activeUsers (0),
  192368. recordNextFrameTime (false),
  192369. activeImage (0),
  192370. loadingImage (0)
  192371. {
  192372. HRESULT hr = graphBuilder.CoCreateInstance (CLSID_FilterGraph, CLSCTX_INPROC);
  192373. if (FAILED (hr))
  192374. return;
  192375. hr = captureGraphBuilder->SetFiltergraph (graphBuilder);
  192376. if (FAILED (hr))
  192377. return;
  192378. hr = graphBuilder->QueryInterface (IID_IMediaControl, (void**) &mediaControl);
  192379. if (FAILED (hr))
  192380. return;
  192381. {
  192382. ComSmartPtr <IAMStreamConfig> streamConfig;
  192383. hr = captureGraphBuilder->FindInterface (&PIN_CATEGORY_CAPTURE,
  192384. 0,
  192385. filter,
  192386. IID_IAMStreamConfig,
  192387. (void**) &streamConfig);
  192388. if (streamConfig != 0)
  192389. {
  192390. getVideoSizes (streamConfig);
  192391. if (! selectVideoSize (streamConfig, minWidth, minHeight, maxWidth, maxHeight))
  192392. return;
  192393. }
  192394. }
  192395. hr = graphBuilder->AddFilter (filter, _T("Video Capture"));
  192396. if (FAILED (hr))
  192397. return;
  192398. hr = smartTee.CoCreateInstance (CLSID_SmartTee, CLSCTX_INPROC_SERVER);
  192399. if (FAILED (hr))
  192400. return;
  192401. hr = graphBuilder->AddFilter (smartTee, _T("Smart Tee"));
  192402. if (FAILED (hr))
  192403. return;
  192404. if (! connectFilters (filter, smartTee))
  192405. return;
  192406. ComSmartPtr <IBaseFilter> sampleGrabberBase;
  192407. hr = sampleGrabberBase.CoCreateInstance (CLSID_SampleGrabber, CLSCTX_INPROC_SERVER);
  192408. if (FAILED (hr))
  192409. return;
  192410. hr = sampleGrabberBase->QueryInterface (IID_ISampleGrabber, (void**) &sampleGrabber);
  192411. if (FAILED (hr))
  192412. return;
  192413. AM_MEDIA_TYPE mt;
  192414. zerostruct (mt);
  192415. mt.majortype = MEDIATYPE_Video;
  192416. mt.subtype = MEDIASUBTYPE_RGB24;
  192417. mt.formattype = FORMAT_VideoInfo;
  192418. sampleGrabber->SetMediaType (&mt);
  192419. callback = new GrabberCallback (*this);
  192420. sampleGrabber->SetCallback (callback, 1);
  192421. hr = graphBuilder->AddFilter (sampleGrabberBase, _T("Sample Grabber"));
  192422. if (FAILED (hr))
  192423. return;
  192424. ComSmartPtr <IPin> grabberInputPin;
  192425. if (! (getPin (smartTee, PINDIR_OUTPUT, &smartTeeCaptureOutputPin, "capture")
  192426. && getPin (smartTee, PINDIR_OUTPUT, &smartTeePreviewOutputPin, "preview")
  192427. && getPin (sampleGrabberBase, PINDIR_INPUT, &grabberInputPin)))
  192428. return;
  192429. hr = graphBuilder->Connect (smartTeePreviewOutputPin, grabberInputPin);
  192430. if (FAILED (hr))
  192431. return;
  192432. zerostruct (mt);
  192433. hr = sampleGrabber->GetConnectedMediaType (&mt);
  192434. VIDEOINFOHEADER* pVih = (VIDEOINFOHEADER*) (mt.pbFormat);
  192435. width = pVih->bmiHeader.biWidth;
  192436. height = pVih->bmiHeader.biHeight;
  192437. ComSmartPtr <IBaseFilter> nullFilter;
  192438. hr = nullFilter.CoCreateInstance (CLSID_NullRenderer, CLSCTX_INPROC_SERVER);
  192439. hr = graphBuilder->AddFilter (nullFilter, _T("Null Renderer"));
  192440. if (connectFilters (sampleGrabberBase, nullFilter)
  192441. && addGraphToRot())
  192442. {
  192443. activeImage = new Image (Image::RGB, width, height, true);
  192444. loadingImage = new Image (Image::RGB, width, height, true);
  192445. ok = true;
  192446. }
  192447. }
  192448. ~DShowCameraDeviceInteral()
  192449. {
  192450. if (mediaControl != 0)
  192451. mediaControl->Stop();
  192452. removeGraphFromRot();
  192453. for (int i = viewerComps.size(); --i >= 0;)
  192454. ((DShowCaptureViewerComp*) viewerComps.getUnchecked(i))->ownerDeleted();
  192455. callback = 0;
  192456. graphBuilder = 0;
  192457. sampleGrabber = 0;
  192458. mediaControl = 0;
  192459. filter = 0;
  192460. captureGraphBuilder = 0;
  192461. smartTee = 0;
  192462. smartTeePreviewOutputPin = 0;
  192463. smartTeeCaptureOutputPin = 0;
  192464. mux = 0;
  192465. fileWriter = 0;
  192466. delete activeImage;
  192467. delete loadingImage;
  192468. }
  192469. void addUser()
  192470. {
  192471. if (ok && activeUsers++ == 0)
  192472. mediaControl->Run();
  192473. }
  192474. void removeUser()
  192475. {
  192476. if (ok && --activeUsers == 0)
  192477. mediaControl->Stop();
  192478. }
  192479. void handleFrame (double /*time*/, BYTE* buffer, long /*bufferSize*/)
  192480. {
  192481. if (recordNextFrameTime)
  192482. {
  192483. const double defaultCameraLatency = 0.1;
  192484. firstRecordedTime = Time::getCurrentTime() - RelativeTime (defaultCameraLatency);
  192485. recordNextFrameTime = false;
  192486. ComSmartPtr <IPin> pin;
  192487. if (getPin (filter, PINDIR_OUTPUT, &pin))
  192488. {
  192489. ComSmartPtr <IAMPushSource> pushSource;
  192490. HRESULT hr = pin->QueryInterface (IID_IAMPushSource, (void**) &pushSource);
  192491. if (pushSource != 0)
  192492. {
  192493. REFERENCE_TIME latency = 0;
  192494. hr = pushSource->GetLatency (&latency);
  192495. firstRecordedTime = firstRecordedTime - RelativeTime ((double) latency);
  192496. }
  192497. }
  192498. }
  192499. imageSwapLock.enter();
  192500. const int lineStride = width * 3;
  192501. const Image::BitmapData destData (*loadingImage, 0, 0, width, height, true);
  192502. for (int i = 0; i < height; ++i)
  192503. memcpy (destData.getLinePointer ((height - 1) - i),
  192504. buffer + lineStride * i,
  192505. lineStride);
  192506. imageNeedsFlipping = true;
  192507. imageSwapLock.exit();
  192508. callListeners (*loadingImage);
  192509. sendChangeMessage (this);
  192510. }
  192511. void drawCurrentImage (Graphics& g, int x, int y, int w, int h)
  192512. {
  192513. if (imageNeedsFlipping)
  192514. {
  192515. imageSwapLock.enter();
  192516. swapVariables (loadingImage, activeImage);
  192517. imageNeedsFlipping = false;
  192518. imageSwapLock.exit();
  192519. }
  192520. RectanglePlacement rp (RectanglePlacement::centred);
  192521. double dx = 0, dy = 0, dw = width, dh = height;
  192522. rp.applyTo (dx, dy, dw, dh, x, y, w, h);
  192523. const int rx = roundToInt (dx), ry = roundToInt (dy);
  192524. const int rw = roundToInt (dw), rh = roundToInt (dh);
  192525. g.saveState();
  192526. g.excludeClipRegion (rx, ry, rw, rh);
  192527. g.fillAll (Colours::black);
  192528. g.restoreState();
  192529. g.drawImage (activeImage, rx, ry, rw, rh, 0, 0, width, height);
  192530. }
  192531. bool createFileCaptureFilter (const File& file)
  192532. {
  192533. removeFileCaptureFilter();
  192534. file.deleteFile();
  192535. mediaControl->Stop();
  192536. firstRecordedTime = Time();
  192537. recordNextFrameTime = true;
  192538. HRESULT hr = mux.CoCreateInstance (CLSID_AviDest, CLSCTX_INPROC_SERVER);
  192539. if (SUCCEEDED (hr))
  192540. {
  192541. hr = graphBuilder->AddFilter (mux, _T("AVI Mux"));
  192542. if (SUCCEEDED (hr))
  192543. {
  192544. fileWriter.CoCreateInstance (CLSID_FileWriter, CLSCTX_INPROC_SERVER);
  192545. if (SUCCEEDED (hr))
  192546. {
  192547. ComSmartPtr <IFileSinkFilter> fileSink;
  192548. hr = fileWriter->QueryInterface (IID_IFileSinkFilter, (void**) &fileSink);
  192549. if (SUCCEEDED (hr))
  192550. {
  192551. AM_MEDIA_TYPE mt;
  192552. zerostruct (mt);
  192553. mt.majortype = MEDIATYPE_Stream;
  192554. mt.subtype = MEDIASUBTYPE_Avi;
  192555. mt.formattype = FORMAT_VideoInfo;
  192556. hr = fileSink->SetFileName (file.getFullPathName(), &mt);
  192557. if (SUCCEEDED (hr))
  192558. {
  192559. hr = graphBuilder->AddFilter (fileWriter, _T("File Writer"));
  192560. if (SUCCEEDED (hr))
  192561. {
  192562. ComSmartPtr <IPin> muxInputPin, muxOutputPin, writerInput;
  192563. if (getPin (mux, PINDIR_INPUT, &muxInputPin)
  192564. && getPin (mux, PINDIR_OUTPUT, &muxOutputPin)
  192565. && getPin (fileWriter, PINDIR_INPUT, &writerInput))
  192566. {
  192567. hr = graphBuilder->Connect (smartTeeCaptureOutputPin, muxInputPin);
  192568. if (SUCCEEDED (hr))
  192569. {
  192570. hr = graphBuilder->Connect (muxOutputPin, writerInput);
  192571. if (SUCCEEDED (hr))
  192572. {
  192573. if (ok && activeUsers > 0)
  192574. mediaControl->Run();
  192575. return true;
  192576. }
  192577. }
  192578. }
  192579. }
  192580. }
  192581. }
  192582. }
  192583. }
  192584. }
  192585. removeFileCaptureFilter();
  192586. if (ok && activeUsers > 0)
  192587. mediaControl->Run();
  192588. return false;
  192589. }
  192590. void removeFileCaptureFilter()
  192591. {
  192592. mediaControl->Stop();
  192593. if (mux != 0)
  192594. {
  192595. graphBuilder->RemoveFilter (mux);
  192596. mux = 0;
  192597. }
  192598. if (fileWriter != 0)
  192599. {
  192600. graphBuilder->RemoveFilter (fileWriter);
  192601. fileWriter = 0;
  192602. }
  192603. if (ok && activeUsers > 0)
  192604. mediaControl->Run();
  192605. }
  192606. void addListener (CameraImageListener* listenerToAdd)
  192607. {
  192608. const ScopedLock sl (listenerLock);
  192609. if (listeners.size() == 0)
  192610. addUser();
  192611. listeners.addIfNotAlreadyThere (listenerToAdd);
  192612. }
  192613. void removeListener (CameraImageListener* listenerToRemove)
  192614. {
  192615. const ScopedLock sl (listenerLock);
  192616. listeners.removeValue (listenerToRemove);
  192617. if (listeners.size() == 0)
  192618. removeUser();
  192619. }
  192620. void callListeners (Image& image)
  192621. {
  192622. const ScopedLock sl (listenerLock);
  192623. for (int i = listeners.size(); --i >= 0;)
  192624. {
  192625. CameraImageListener* l = (CameraImageListener*) listeners[i];
  192626. if (l != 0)
  192627. l->imageReceived (image);
  192628. }
  192629. }
  192630. class DShowCaptureViewerComp : public Component,
  192631. public ChangeListener
  192632. {
  192633. public:
  192634. DShowCaptureViewerComp (DShowCameraDeviceInteral* const owner_)
  192635. : owner (owner_)
  192636. {
  192637. setOpaque (true);
  192638. owner->addChangeListener (this);
  192639. owner->addUser();
  192640. owner->viewerComps.add (this);
  192641. setSize (owner_->width, owner_->height);
  192642. }
  192643. ~DShowCaptureViewerComp()
  192644. {
  192645. if (owner != 0)
  192646. {
  192647. owner->viewerComps.removeValue (this);
  192648. owner->removeUser();
  192649. owner->removeChangeListener (this);
  192650. }
  192651. }
  192652. void ownerDeleted()
  192653. {
  192654. owner = 0;
  192655. }
  192656. void paint (Graphics& g)
  192657. {
  192658. g.setColour (Colours::black);
  192659. g.setImageResamplingQuality (Graphics::lowResamplingQuality);
  192660. if (owner != 0)
  192661. owner->drawCurrentImage (g, 0, 0, getWidth(), getHeight());
  192662. else
  192663. g.fillAll (Colours::black);
  192664. }
  192665. void changeListenerCallback (void*)
  192666. {
  192667. repaint();
  192668. }
  192669. private:
  192670. DShowCameraDeviceInteral* owner;
  192671. };
  192672. bool ok;
  192673. int width, height;
  192674. Time firstRecordedTime;
  192675. VoidArray viewerComps;
  192676. private:
  192677. CameraDevice* const owner;
  192678. ComSmartPtr <ICaptureGraphBuilder2> captureGraphBuilder;
  192679. ComSmartPtr <IBaseFilter> filter;
  192680. ComSmartPtr <IBaseFilter> smartTee;
  192681. ComSmartPtr <IGraphBuilder> graphBuilder;
  192682. ComSmartPtr <ISampleGrabber> sampleGrabber;
  192683. ComSmartPtr <IMediaControl> mediaControl;
  192684. ComSmartPtr <IPin> smartTeePreviewOutputPin;
  192685. ComSmartPtr <IPin> smartTeeCaptureOutputPin;
  192686. ComSmartPtr <IBaseFilter> mux, fileWriter;
  192687. int activeUsers;
  192688. Array <int> widths, heights;
  192689. DWORD graphRegistrationID;
  192690. CriticalSection imageSwapLock;
  192691. bool imageNeedsFlipping;
  192692. Image* loadingImage;
  192693. Image* activeImage;
  192694. bool recordNextFrameTime;
  192695. void getVideoSizes (IAMStreamConfig* const streamConfig)
  192696. {
  192697. widths.clear();
  192698. heights.clear();
  192699. int count = 0, size = 0;
  192700. streamConfig->GetNumberOfCapabilities (&count, &size);
  192701. if (size == sizeof (VIDEO_STREAM_CONFIG_CAPS))
  192702. {
  192703. for (int i = 0; i < count; ++i)
  192704. {
  192705. VIDEO_STREAM_CONFIG_CAPS scc;
  192706. AM_MEDIA_TYPE* config;
  192707. HRESULT hr = streamConfig->GetStreamCaps (i, &config, (BYTE*) &scc);
  192708. if (SUCCEEDED (hr))
  192709. {
  192710. const int w = scc.InputSize.cx;
  192711. const int h = scc.InputSize.cy;
  192712. bool duplicate = false;
  192713. for (int j = widths.size(); --j >= 0;)
  192714. {
  192715. if (w == widths.getUnchecked (j) && h == heights.getUnchecked (j))
  192716. {
  192717. duplicate = true;
  192718. break;
  192719. }
  192720. }
  192721. if (! duplicate)
  192722. {
  192723. DBG ("Camera capture size: " + String (w) + ", " + String (h));
  192724. widths.add (w);
  192725. heights.add (h);
  192726. }
  192727. deleteMediaType (config);
  192728. }
  192729. }
  192730. }
  192731. }
  192732. bool selectVideoSize (IAMStreamConfig* const streamConfig,
  192733. const int minWidth, const int minHeight,
  192734. const int maxWidth, const int maxHeight)
  192735. {
  192736. int count = 0, size = 0;
  192737. streamConfig->GetNumberOfCapabilities (&count, &size);
  192738. if (size == sizeof (VIDEO_STREAM_CONFIG_CAPS))
  192739. {
  192740. for (int i = 0; i < count; ++i)
  192741. {
  192742. VIDEO_STREAM_CONFIG_CAPS scc;
  192743. AM_MEDIA_TYPE* config;
  192744. HRESULT hr = streamConfig->GetStreamCaps (i, &config, (BYTE*) &scc);
  192745. if (SUCCEEDED (hr))
  192746. {
  192747. if (scc.InputSize.cx >= minWidth
  192748. && scc.InputSize.cy >= minHeight
  192749. && scc.InputSize.cx <= maxWidth
  192750. && scc.InputSize.cy <= maxHeight)
  192751. {
  192752. hr = streamConfig->SetFormat (config);
  192753. deleteMediaType (config);
  192754. return SUCCEEDED (hr);
  192755. }
  192756. deleteMediaType (config);
  192757. }
  192758. }
  192759. }
  192760. return false;
  192761. }
  192762. static bool getPin (IBaseFilter* filter, const PIN_DIRECTION wantedDirection, IPin** result, const char* pinName = 0)
  192763. {
  192764. ComSmartPtr <IEnumPins> enumerator;
  192765. ComSmartPtr <IPin> pin;
  192766. filter->EnumPins (&enumerator);
  192767. while (enumerator->Next (1, &pin, 0) == S_OK)
  192768. {
  192769. PIN_DIRECTION dir;
  192770. pin->QueryDirection (&dir);
  192771. if (wantedDirection == dir)
  192772. {
  192773. PIN_INFO info;
  192774. zerostruct (info);
  192775. pin->QueryPinInfo (&info);
  192776. if (pinName == 0 || String (pinName).equalsIgnoreCase (String (info.achName)))
  192777. {
  192778. pin.p->AddRef();
  192779. *result = pin;
  192780. return true;
  192781. }
  192782. }
  192783. }
  192784. return false;
  192785. }
  192786. bool connectFilters (IBaseFilter* const first, IBaseFilter* const second) const
  192787. {
  192788. ComSmartPtr <IPin> in, out;
  192789. return getPin (first, PINDIR_OUTPUT, &out)
  192790. && getPin (second, PINDIR_INPUT, &in)
  192791. && SUCCEEDED (graphBuilder->Connect (out, in));
  192792. }
  192793. bool addGraphToRot()
  192794. {
  192795. ComSmartPtr <IRunningObjectTable> rot;
  192796. if (FAILED (GetRunningObjectTable (0, &rot)))
  192797. return false;
  192798. ComSmartPtr <IMoniker> moniker;
  192799. WCHAR buffer[128];
  192800. HRESULT hr = CreateItemMoniker (_T("!"), buffer, &moniker);
  192801. if (FAILED (hr))
  192802. return false;
  192803. graphRegistrationID = 0;
  192804. return SUCCEEDED (rot->Register (0, graphBuilder, moniker, &graphRegistrationID));
  192805. }
  192806. void removeGraphFromRot()
  192807. {
  192808. ComSmartPtr <IRunningObjectTable> rot;
  192809. if (SUCCEEDED (GetRunningObjectTable (0, &rot)))
  192810. rot->Revoke (graphRegistrationID);
  192811. }
  192812. static void deleteMediaType (AM_MEDIA_TYPE* const pmt)
  192813. {
  192814. if (pmt->cbFormat != 0)
  192815. CoTaskMemFree ((PVOID) pmt->pbFormat);
  192816. if (pmt->pUnk != 0)
  192817. pmt->pUnk->Release();
  192818. CoTaskMemFree (pmt);
  192819. }
  192820. class GrabberCallback : public ISampleGrabberCB
  192821. {
  192822. public:
  192823. GrabberCallback (DShowCameraDeviceInteral& owner_)
  192824. : owner (owner_)
  192825. {
  192826. }
  192827. HRESULT __stdcall QueryInterface (REFIID id, void** result)
  192828. {
  192829. if (id == IID_IUnknown)
  192830. *result = dynamic_cast <IUnknown*> (this);
  192831. else if (id == IID_ISampleGrabberCB)
  192832. *result = dynamic_cast <ISampleGrabberCB*> (this);
  192833. else
  192834. {
  192835. *result = 0;
  192836. return E_NOINTERFACE;
  192837. }
  192838. AddRef();
  192839. return S_OK;
  192840. }
  192841. ULONG __stdcall AddRef() { return ++refCount; }
  192842. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  192843. STDMETHODIMP SampleCB (double /*SampleTime*/, IMediaSample* /*pSample*/)
  192844. {
  192845. return E_FAIL;
  192846. }
  192847. STDMETHODIMP BufferCB (double time, BYTE* buffer, long bufferSize)
  192848. {
  192849. owner.handleFrame (time, buffer, bufferSize);
  192850. return S_OK;
  192851. }
  192852. private:
  192853. int refCount;
  192854. DShowCameraDeviceInteral& owner;
  192855. GrabberCallback (const GrabberCallback&);
  192856. const GrabberCallback& operator= (const GrabberCallback&);
  192857. };
  192858. ComSmartPtr <GrabberCallback> callback;
  192859. VoidArray listeners;
  192860. CriticalSection listenerLock;
  192861. DShowCameraDeviceInteral (const DShowCameraDeviceInteral&);
  192862. const DShowCameraDeviceInteral& operator= (const DShowCameraDeviceInteral&);
  192863. };
  192864. CameraDevice::CameraDevice (const String& name_, int /*index*/)
  192865. : name (name_)
  192866. {
  192867. isRecording = false;
  192868. }
  192869. CameraDevice::~CameraDevice()
  192870. {
  192871. stopRecording();
  192872. delete (DShowCameraDeviceInteral*) internal;
  192873. internal = 0;
  192874. }
  192875. Component* CameraDevice::createViewerComponent()
  192876. {
  192877. return new DShowCameraDeviceInteral::DShowCaptureViewerComp ((DShowCameraDeviceInteral*) internal);
  192878. }
  192879. const String CameraDevice::getFileExtension()
  192880. {
  192881. return ".avi";
  192882. }
  192883. void CameraDevice::startRecordingToFile (const File& file)
  192884. {
  192885. stopRecording();
  192886. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192887. d->addUser();
  192888. isRecording = d->createFileCaptureFilter (file);
  192889. }
  192890. const Time CameraDevice::getTimeOfFirstRecordedFrame() const
  192891. {
  192892. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192893. return d->firstRecordedTime;
  192894. }
  192895. void CameraDevice::stopRecording()
  192896. {
  192897. if (isRecording)
  192898. {
  192899. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192900. d->removeFileCaptureFilter();
  192901. d->removeUser();
  192902. isRecording = false;
  192903. }
  192904. }
  192905. void CameraDevice::addListener (CameraImageListener* listenerToAdd)
  192906. {
  192907. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192908. if (listenerToAdd != 0)
  192909. d->addListener (listenerToAdd);
  192910. }
  192911. void CameraDevice::removeListener (CameraImageListener* listenerToRemove)
  192912. {
  192913. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192914. if (listenerToRemove != 0)
  192915. d->removeListener (listenerToRemove);
  192916. }
  192917. static ComSmartPtr <IBaseFilter> enumerateCameras (StringArray* const names,
  192918. const int deviceIndexToOpen,
  192919. String& name)
  192920. {
  192921. int index = 0;
  192922. ComSmartPtr <IBaseFilter> result;
  192923. ComSmartPtr <ICreateDevEnum> pDevEnum;
  192924. HRESULT hr = pDevEnum.CoCreateInstance (CLSID_SystemDeviceEnum, CLSCTX_INPROC);
  192925. if (SUCCEEDED (hr))
  192926. {
  192927. ComSmartPtr <IEnumMoniker> enumerator;
  192928. hr = pDevEnum->CreateClassEnumerator (CLSID_VideoInputDeviceCategory, &enumerator, 0);
  192929. if (SUCCEEDED (hr) && enumerator != 0)
  192930. {
  192931. ComSmartPtr <IBaseFilter> captureFilter;
  192932. ComSmartPtr <IMoniker> moniker;
  192933. ULONG fetched;
  192934. while (enumerator->Next (1, &moniker, &fetched) == S_OK)
  192935. {
  192936. hr = moniker->BindToObject (0, 0, IID_IBaseFilter, (void**) &captureFilter);
  192937. if (SUCCEEDED (hr))
  192938. {
  192939. ComSmartPtr <IPropertyBag> propertyBag;
  192940. hr = moniker->BindToStorage (0, 0, IID_IPropertyBag, (void**) &propertyBag);
  192941. if (SUCCEEDED (hr))
  192942. {
  192943. VARIANT var;
  192944. var.vt = VT_BSTR;
  192945. hr = propertyBag->Read (_T("FriendlyName"), &var, 0);
  192946. propertyBag = 0;
  192947. if (SUCCEEDED (hr))
  192948. {
  192949. if (names != 0)
  192950. names->add (var.bstrVal);
  192951. if (index == deviceIndexToOpen)
  192952. {
  192953. name = var.bstrVal;
  192954. result = captureFilter;
  192955. captureFilter = 0;
  192956. break;
  192957. }
  192958. ++index;
  192959. }
  192960. moniker = 0;
  192961. }
  192962. captureFilter = 0;
  192963. }
  192964. }
  192965. }
  192966. }
  192967. return result;
  192968. }
  192969. const StringArray CameraDevice::getAvailableDevices()
  192970. {
  192971. StringArray devs;
  192972. String dummy;
  192973. enumerateCameras (&devs, -1, dummy);
  192974. return devs;
  192975. }
  192976. CameraDevice* CameraDevice::openDevice (int index,
  192977. int minWidth, int minHeight,
  192978. int maxWidth, int maxHeight)
  192979. {
  192980. ComSmartPtr <ICaptureGraphBuilder2> captureGraphBuilder;
  192981. HRESULT hr = captureGraphBuilder.CoCreateInstance (CLSID_CaptureGraphBuilder2, CLSCTX_INPROC);
  192982. if (SUCCEEDED (hr))
  192983. {
  192984. String name;
  192985. const ComSmartPtr <IBaseFilter> filter (enumerateCameras (0, index, name));
  192986. if (filter != 0)
  192987. {
  192988. CameraDevice* const cam = new CameraDevice (name, index);
  192989. DShowCameraDeviceInteral* const intern
  192990. = new DShowCameraDeviceInteral (cam, captureGraphBuilder, filter,
  192991. minWidth, minHeight, maxWidth, maxHeight);
  192992. cam->internal = intern;
  192993. if (intern->ok)
  192994. return cam;
  192995. else
  192996. delete cam;
  192997. }
  192998. }
  192999. return 0;
  193000. }
  193001. #endif
  193002. /*** End of inlined file: juce_win32_CameraDevice.cpp ***/
  193003. #endif
  193004. // Auto-link the other win32 libs that are needed by library calls..
  193005. #if (JUCE_AMALGAMATED_TEMPLATE || defined (JUCE_DLL_BUILD)) && JUCE_MSVC && ! DONT_AUTOLINK_TO_WIN32_LIBRARIES
  193006. /*** Start of inlined file: juce_win32_AutoLinkLibraries.h ***/
  193007. // Auto-links to various win32 libs that are needed by library calls..
  193008. #pragma comment(lib, "kernel32.lib")
  193009. #pragma comment(lib, "user32.lib")
  193010. #pragma comment(lib, "shell32.lib")
  193011. #pragma comment(lib, "gdi32.lib")
  193012. #pragma comment(lib, "vfw32.lib")
  193013. #pragma comment(lib, "comdlg32.lib")
  193014. #pragma comment(lib, "winmm.lib")
  193015. #pragma comment(lib, "wininet.lib")
  193016. #pragma comment(lib, "ole32.lib")
  193017. #pragma comment(lib, "oleaut32.lib")
  193018. #pragma comment(lib, "advapi32.lib")
  193019. #pragma comment(lib, "ws2_32.lib")
  193020. #pragma comment(lib, "comsupp.lib")
  193021. #pragma comment(lib, "version.lib")
  193022. #if JUCE_OPENGL
  193023. #pragma comment(lib, "OpenGL32.Lib")
  193024. #pragma comment(lib, "GlU32.Lib")
  193025. #endif
  193026. #if JUCE_QUICKTIME
  193027. #pragma comment (lib, "QTMLClient.lib")
  193028. #endif
  193029. #if JUCE_USE_CAMERA
  193030. #pragma comment (lib, "Strmiids.lib")
  193031. #endif
  193032. /*** End of inlined file: juce_win32_AutoLinkLibraries.h ***/
  193033. #endif
  193034. END_JUCE_NAMESPACE
  193035. /*** End of inlined file: juce_win32_NativeCode.cpp ***/
  193036. #endif
  193037. #if JUCE_LINUX
  193038. /*** Start of inlined file: juce_linux_NativeCode.cpp ***/
  193039. BEGIN_JUCE_NAMESPACE
  193040. #if defined (CPU_ISSET) && ! defined (SUPPORT_AFFINITIES)
  193041. #define SUPPORT_AFFINITIES 1
  193042. #endif
  193043. #define JUCE_INCLUDED_FILE 1
  193044. // Now include the actual code files..
  193045. /*** Start of inlined file: juce_posix_SharedCode.h ***/
  193046. CriticalSection::CriticalSection() throw()
  193047. {
  193048. pthread_mutexattr_t atts;
  193049. pthread_mutexattr_init (&atts);
  193050. pthread_mutexattr_settype (&atts, PTHREAD_MUTEX_RECURSIVE);
  193051. pthread_mutex_init (&internal, &atts);
  193052. }
  193053. CriticalSection::~CriticalSection() throw()
  193054. {
  193055. pthread_mutex_destroy (&internal);
  193056. }
  193057. void CriticalSection::enter() const throw()
  193058. {
  193059. pthread_mutex_lock (&internal);
  193060. }
  193061. bool CriticalSection::tryEnter() const throw()
  193062. {
  193063. return pthread_mutex_trylock (&internal) == 0;
  193064. }
  193065. void CriticalSection::exit() const throw()
  193066. {
  193067. pthread_mutex_unlock (&internal);
  193068. }
  193069. struct EventStruct
  193070. {
  193071. pthread_cond_t condition;
  193072. pthread_mutex_t mutex;
  193073. bool triggered;
  193074. };
  193075. WaitableEvent::WaitableEvent() throw()
  193076. {
  193077. EventStruct* const es = new EventStruct();
  193078. es->triggered = false;
  193079. pthread_cond_init (&es->condition, 0);
  193080. pthread_mutex_init (&es->mutex, 0);
  193081. internal = es;
  193082. }
  193083. WaitableEvent::~WaitableEvent() throw()
  193084. {
  193085. EventStruct* const es = (EventStruct*) internal;
  193086. pthread_cond_destroy (&es->condition);
  193087. pthread_mutex_destroy (&es->mutex);
  193088. delete es;
  193089. }
  193090. bool WaitableEvent::wait (const int timeOutMillisecs) const throw()
  193091. {
  193092. EventStruct* const es = (EventStruct*) internal;
  193093. pthread_mutex_lock (&es->mutex);
  193094. if (timeOutMillisecs < 0)
  193095. {
  193096. while (! es->triggered)
  193097. pthread_cond_wait (&es->condition, &es->mutex);
  193098. }
  193099. else
  193100. {
  193101. while (! es->triggered)
  193102. {
  193103. struct timeval t;
  193104. gettimeofday (&t, 0);
  193105. struct timespec time;
  193106. time.tv_sec = t.tv_sec + (timeOutMillisecs / 1000);
  193107. time.tv_nsec = (t.tv_usec + ((timeOutMillisecs % 1000) * 1000)) * 1000;
  193108. if (time.tv_nsec >= 1000000000)
  193109. {
  193110. time.tv_nsec -= 1000000000;
  193111. time.tv_sec++;
  193112. }
  193113. if (pthread_cond_timedwait (&es->condition, &es->mutex, &time) == ETIMEDOUT)
  193114. {
  193115. pthread_mutex_unlock (&es->mutex);
  193116. return false;
  193117. }
  193118. }
  193119. }
  193120. es->triggered = false;
  193121. pthread_mutex_unlock (&es->mutex);
  193122. return true;
  193123. }
  193124. void WaitableEvent::signal() const throw()
  193125. {
  193126. EventStruct* const es = (EventStruct*) internal;
  193127. pthread_mutex_lock (&es->mutex);
  193128. es->triggered = true;
  193129. pthread_cond_broadcast (&es->condition);
  193130. pthread_mutex_unlock (&es->mutex);
  193131. }
  193132. void WaitableEvent::reset() const throw()
  193133. {
  193134. EventStruct* const es = (EventStruct*) internal;
  193135. pthread_mutex_lock (&es->mutex);
  193136. es->triggered = false;
  193137. pthread_mutex_unlock (&es->mutex);
  193138. }
  193139. void JUCE_CALLTYPE Thread::sleep (int millisecs)
  193140. {
  193141. struct timespec time;
  193142. time.tv_sec = millisecs / 1000;
  193143. time.tv_nsec = (millisecs % 1000) * 1000000;
  193144. nanosleep (&time, 0);
  193145. }
  193146. const tchar File::separator = T('/');
  193147. const tchar* File::separatorString = T("/");
  193148. bool juce_copyFile (const String& s, const String& d);
  193149. static bool juce_stat (const String& fileName, struct stat& info)
  193150. {
  193151. return fileName.isNotEmpty()
  193152. && (stat (fileName.toUTF8(), &info) == 0);
  193153. }
  193154. bool juce_isDirectory (const String& fileName)
  193155. {
  193156. struct stat info;
  193157. return fileName.isEmpty()
  193158. || (juce_stat (fileName, info)
  193159. && ((info.st_mode & S_IFDIR) != 0));
  193160. }
  193161. bool juce_fileExists (const String& fileName, const bool dontCountDirectories)
  193162. {
  193163. if (fileName.isEmpty())
  193164. return false;
  193165. const char* const fileNameUTF8 = fileName.toUTF8();
  193166. bool exists = access (fileNameUTF8, F_OK) == 0;
  193167. if (exists && dontCountDirectories)
  193168. {
  193169. struct stat info;
  193170. const int res = stat (fileNameUTF8, &info);
  193171. if (res == 0 && (info.st_mode & S_IFDIR) != 0)
  193172. exists = false;
  193173. }
  193174. return exists;
  193175. }
  193176. int64 juce_getFileSize (const String& fileName)
  193177. {
  193178. struct stat info;
  193179. return juce_stat (fileName, info) ? info.st_size : 0;
  193180. }
  193181. bool juce_canWriteToFile (const String& fileName)
  193182. {
  193183. return access (fileName.toUTF8(), W_OK) == 0;
  193184. }
  193185. bool juce_deleteFile (const String& fileName)
  193186. {
  193187. if (juce_isDirectory (fileName))
  193188. return rmdir ((const char*) fileName.toUTF8()) == 0;
  193189. else
  193190. return remove ((const char*) fileName.toUTF8()) == 0;
  193191. }
  193192. bool juce_moveFile (const String& source, const String& dest)
  193193. {
  193194. if (rename (source.toUTF8(), dest.toUTF8()) == 0)
  193195. return true;
  193196. if (juce_canWriteToFile (source)
  193197. && juce_copyFile (source, dest))
  193198. {
  193199. if (juce_deleteFile (source))
  193200. return true;
  193201. juce_deleteFile (dest);
  193202. }
  193203. return false;
  193204. }
  193205. void juce_createDirectory (const String& fileName)
  193206. {
  193207. mkdir (fileName.toUTF8(), 0777);
  193208. }
  193209. void* juce_fileOpen (const String& fileName, bool forWriting)
  193210. {
  193211. int flags = O_RDONLY;
  193212. if (forWriting)
  193213. {
  193214. if (juce_fileExists (fileName, false))
  193215. {
  193216. const int f = open ((const char*) fileName.toUTF8(), O_RDWR, 00644);
  193217. if (f != -1)
  193218. lseek (f, 0, SEEK_END);
  193219. return (void*) f;
  193220. }
  193221. else
  193222. {
  193223. flags = O_RDWR + O_CREAT;
  193224. }
  193225. }
  193226. return (void*) open ((const char*) fileName.toUTF8(), flags, 00644);
  193227. }
  193228. void juce_fileClose (void* handle)
  193229. {
  193230. if (handle != 0)
  193231. close ((int) (pointer_sized_int) handle);
  193232. }
  193233. int juce_fileRead (void* handle, void* buffer, int size)
  193234. {
  193235. if (handle != 0)
  193236. return (int) read ((int) (pointer_sized_int) handle, buffer, size);
  193237. return 0;
  193238. }
  193239. int juce_fileWrite (void* handle, const void* buffer, int size)
  193240. {
  193241. if (handle != 0)
  193242. return (int) write ((int) (pointer_sized_int) handle, buffer, size);
  193243. return 0;
  193244. }
  193245. int64 juce_fileSetPosition (void* handle, int64 pos)
  193246. {
  193247. if (handle != 0 && lseek ((int) (pointer_sized_int) handle, pos, SEEK_SET) == pos)
  193248. return pos;
  193249. return -1;
  193250. }
  193251. int64 juce_fileGetPosition (void* handle)
  193252. {
  193253. if (handle != 0)
  193254. return lseek ((int) (pointer_sized_int) handle, 0, SEEK_CUR);
  193255. else
  193256. return -1;
  193257. }
  193258. void juce_fileFlush (void* handle)
  193259. {
  193260. if (handle != 0)
  193261. fsync ((int) (pointer_sized_int) handle);
  193262. }
  193263. const File juce_getExecutableFile()
  193264. {
  193265. Dl_info exeInfo;
  193266. dladdr ((const void*) juce_getExecutableFile, &exeInfo);
  193267. return File (exeInfo.dli_fname);
  193268. }
  193269. // if this file doesn't exist, find a parent of it that does..
  193270. static bool doStatFS (const File* file, struct statfs& result)
  193271. {
  193272. File f (*file);
  193273. for (int i = 5; --i >= 0;)
  193274. {
  193275. if (f.exists())
  193276. break;
  193277. f = f.getParentDirectory();
  193278. }
  193279. return statfs (f.getFullPathName().toUTF8(), &result) == 0;
  193280. }
  193281. int64 File::getBytesFreeOnVolume() const
  193282. {
  193283. struct statfs buf;
  193284. if (doStatFS (this, buf))
  193285. return (int64) buf.f_bsize * (int64) buf.f_bavail; // Note: this returns space available to non-super user
  193286. return 0;
  193287. }
  193288. int64 File::getVolumeTotalSize() const
  193289. {
  193290. struct statfs buf;
  193291. if (doStatFS (this, buf))
  193292. return (int64) buf.f_bsize * (int64) buf.f_blocks;
  193293. return 0;
  193294. }
  193295. const String juce_getVolumeLabel (const String& filenameOnVolume,
  193296. int& volumeSerialNumber)
  193297. {
  193298. volumeSerialNumber = 0;
  193299. #if JUCE_MAC
  193300. struct VolAttrBuf
  193301. {
  193302. u_int32_t length;
  193303. attrreference_t mountPointRef;
  193304. char mountPointSpace [MAXPATHLEN];
  193305. } attrBuf;
  193306. struct attrlist attrList;
  193307. zerostruct (attrList);
  193308. attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
  193309. attrList.volattr = ATTR_VOL_INFO | ATTR_VOL_NAME;
  193310. File f (filenameOnVolume);
  193311. for (;;)
  193312. {
  193313. if (getattrlist ((const char*) f.getFullPathName().toUTF8(),
  193314. &attrList, &attrBuf, sizeof(attrBuf), 0) == 0)
  193315. {
  193316. return String::fromUTF8 (((const uint8*) &attrBuf.mountPointRef) + attrBuf.mountPointRef.attr_dataoffset,
  193317. (int) attrBuf.mountPointRef.attr_length);
  193318. }
  193319. const File parent (f.getParentDirectory());
  193320. if (f == parent)
  193321. break;
  193322. f = parent;
  193323. }
  193324. #endif
  193325. return String::empty;
  193326. }
  193327. void juce_runSystemCommand (const String& command)
  193328. {
  193329. int result = system ((const char*) command.toUTF8());
  193330. (void) result;
  193331. }
  193332. const String juce_getOutputFromCommand (const String& command)
  193333. {
  193334. // slight bodge here, as we just pipe the output into a temp file and read it...
  193335. const File tempFile (File::getSpecialLocation (File::tempDirectory)
  193336. .getNonexistentChildFile (String::toHexString (Random::getSystemRandom().nextInt()), ".tmp", false));
  193337. juce_runSystemCommand (command + " > " + tempFile.getFullPathName());
  193338. String result (tempFile.loadFileAsString());
  193339. tempFile.deleteFile();
  193340. return result;
  193341. }
  193342. InterProcessLock::InterProcessLock (const String& name_)
  193343. : internal (0),
  193344. name (name_),
  193345. reentrancyLevel (0)
  193346. {
  193347. #if JUCE_MAC
  193348. // (don't use getSpecialLocation() to avoid the temp folder being different for each app)
  193349. const File temp (File (T("~/Library/Caches/Juce")).getChildFile (name));
  193350. #else
  193351. const File temp (File::getSpecialLocation (File::tempDirectory).getChildFile (name));
  193352. #endif
  193353. temp.create();
  193354. internal = open (temp.getFullPathName().toUTF8(), O_RDWR);
  193355. }
  193356. InterProcessLock::~InterProcessLock()
  193357. {
  193358. while (reentrancyLevel > 0)
  193359. this->exit();
  193360. close (internal);
  193361. }
  193362. bool InterProcessLock::enter (const int timeOutMillisecs)
  193363. {
  193364. if (internal == 0)
  193365. return false;
  193366. if (reentrancyLevel != 0)
  193367. return true;
  193368. const int64 endTime = Time::currentTimeMillis() + timeOutMillisecs;
  193369. struct flock fl;
  193370. zerostruct (fl);
  193371. fl.l_whence = SEEK_SET;
  193372. fl.l_type = F_WRLCK;
  193373. for (;;)
  193374. {
  193375. const int result = fcntl (internal, F_SETLK, &fl);
  193376. if (result >= 0)
  193377. {
  193378. ++reentrancyLevel;
  193379. return true;
  193380. }
  193381. if (errno != EINTR)
  193382. {
  193383. if (timeOutMillisecs == 0
  193384. || (timeOutMillisecs > 0 && Time::currentTimeMillis() >= endTime))
  193385. break;
  193386. Thread::sleep (10);
  193387. }
  193388. }
  193389. return false;
  193390. }
  193391. void InterProcessLock::exit()
  193392. {
  193393. if (reentrancyLevel > 0 && internal != 0)
  193394. {
  193395. --reentrancyLevel;
  193396. struct flock fl;
  193397. zerostruct (fl);
  193398. fl.l_whence = SEEK_SET;
  193399. fl.l_type = F_UNLCK;
  193400. for (;;)
  193401. {
  193402. const int result = fcntl (internal, F_SETLKW, &fl);
  193403. if (result >= 0 || errno != EINTR)
  193404. break;
  193405. }
  193406. }
  193407. }
  193408. /*** End of inlined file: juce_posix_SharedCode.h ***/
  193409. /*** Start of inlined file: juce_linux_Files.cpp ***/
  193410. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  193411. // compiled on its own).
  193412. #if JUCE_INCLUDED_FILE
  193413. #define U_ISOFS_SUPER_MAGIC (short) 0x9660 // linux/iso_fs.h
  193414. #define U_MSDOS_SUPER_MAGIC (short) 0x4d44 // linux/msdos_fs.h
  193415. #define U_NFS_SUPER_MAGIC (short) 0x6969 // linux/nfs_fs.h
  193416. #define U_SMB_SUPER_MAGIC (short) 0x517B // linux/smb_fs.h
  193417. void juce_getFileTimes (const String& fileName,
  193418. int64& modificationTime,
  193419. int64& accessTime,
  193420. int64& creationTime)
  193421. {
  193422. modificationTime = 0;
  193423. accessTime = 0;
  193424. creationTime = 0;
  193425. struct stat info;
  193426. const int res = stat (fileName.toUTF8(), &info);
  193427. if (res == 0)
  193428. {
  193429. modificationTime = (int64) info.st_mtime * 1000;
  193430. accessTime = (int64) info.st_atime * 1000;
  193431. creationTime = (int64) info.st_ctime * 1000;
  193432. }
  193433. }
  193434. bool juce_setFileTimes (const String& fileName,
  193435. int64 modificationTime,
  193436. int64 accessTime,
  193437. int64 creationTime)
  193438. {
  193439. struct utimbuf times;
  193440. times.actime = (time_t) (accessTime / 1000);
  193441. times.modtime = (time_t) (modificationTime / 1000);
  193442. return utime (fileName.toUTF8(), &times) == 0;
  193443. }
  193444. bool juce_setFileReadOnly (const String& fileName, bool isReadOnly)
  193445. {
  193446. struct stat info;
  193447. const int res = stat (fileName.toUTF8(), &info);
  193448. if (res != 0)
  193449. return false;
  193450. info.st_mode &= 0777; // Just permissions
  193451. if( isReadOnly )
  193452. info.st_mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH);
  193453. else
  193454. // Give everybody write permission?
  193455. info.st_mode |= S_IWUSR | S_IWGRP | S_IWOTH;
  193456. return chmod (fileName.toUTF8(), info.st_mode) == 0;
  193457. }
  193458. bool juce_copyFile (const String& s, const String& d)
  193459. {
  193460. const File source (s), dest (d);
  193461. FileInputStream* in = source.createInputStream();
  193462. bool ok = false;
  193463. if (in != 0)
  193464. {
  193465. if (dest.deleteFile())
  193466. {
  193467. FileOutputStream* const out = dest.createOutputStream();
  193468. if (out != 0)
  193469. {
  193470. const int bytesCopied = out->writeFromInputStream (*in, -1);
  193471. delete out;
  193472. ok = (bytesCopied == source.getSize());
  193473. if (! ok)
  193474. dest.deleteFile();
  193475. }
  193476. }
  193477. delete in;
  193478. }
  193479. return ok;
  193480. }
  193481. const StringArray juce_getFileSystemRoots()
  193482. {
  193483. StringArray s;
  193484. s.add (T("/"));
  193485. return s;
  193486. }
  193487. bool File::isOnCDRomDrive() const
  193488. {
  193489. struct statfs buf;
  193490. if (statfs (getFullPathName().toUTF8(), &buf) == 0)
  193491. return (buf.f_type == U_ISOFS_SUPER_MAGIC);
  193492. // Assume not if this fails for some reason
  193493. return false;
  193494. }
  193495. bool File::isOnHardDisk() const
  193496. {
  193497. struct statfs buf;
  193498. if (statfs (getFullPathName().toUTF8(), &buf) == 0)
  193499. {
  193500. switch (buf.f_type)
  193501. {
  193502. case U_ISOFS_SUPER_MAGIC: // CD-ROM
  193503. case U_MSDOS_SUPER_MAGIC: // Probably floppy (but could be mounted FAT filesystem)
  193504. case U_NFS_SUPER_MAGIC: // Network NFS
  193505. case U_SMB_SUPER_MAGIC: // Network Samba
  193506. return false;
  193507. default:
  193508. // Assume anything else is a hard-disk (but note it could
  193509. // be a RAM disk. There isn't a good way of determining
  193510. // this for sure)
  193511. return true;
  193512. }
  193513. }
  193514. // Assume so if this fails for some reason
  193515. return true;
  193516. }
  193517. bool File::isOnRemovableDrive() const
  193518. {
  193519. jassertfalse // xxx not implemented for linux!
  193520. return false;
  193521. }
  193522. bool File::isHidden() const
  193523. {
  193524. return getFileName().startsWithChar (T('.'));
  193525. }
  193526. const char* juce_Argv0 = 0; // referenced from juce_Application.cpp
  193527. const File File::getSpecialLocation (const SpecialLocationType type)
  193528. {
  193529. switch (type)
  193530. {
  193531. case userHomeDirectory:
  193532. {
  193533. const char* homeDir = getenv ("HOME");
  193534. if (homeDir == 0)
  193535. {
  193536. struct passwd* const pw = getpwuid (getuid());
  193537. if (pw != 0)
  193538. homeDir = pw->pw_dir;
  193539. }
  193540. return File (String::fromUTF8 ((const uint8*) homeDir));
  193541. }
  193542. case userDocumentsDirectory:
  193543. case userMusicDirectory:
  193544. case userMoviesDirectory:
  193545. case userApplicationDataDirectory:
  193546. return File ("~");
  193547. case userDesktopDirectory:
  193548. return File ("~/Desktop");
  193549. case commonApplicationDataDirectory:
  193550. return File ("/var");
  193551. case globalApplicationsDirectory:
  193552. return File ("/usr");
  193553. case tempDirectory:
  193554. {
  193555. File tmp ("/var/tmp");
  193556. if (! tmp.isDirectory())
  193557. {
  193558. tmp = T("/tmp");
  193559. if (! tmp.isDirectory())
  193560. tmp = File::getCurrentWorkingDirectory();
  193561. }
  193562. return tmp;
  193563. }
  193564. case invokedExecutableFile:
  193565. if (juce_Argv0 != 0)
  193566. return File (String::fromUTF8 ((const uint8*) juce_Argv0));
  193567. // deliberate fall-through...
  193568. case currentExecutableFile:
  193569. case currentApplicationFile:
  193570. return juce_getExecutableFile();
  193571. default:
  193572. jassertfalse // unknown type?
  193573. break;
  193574. }
  193575. return File::nonexistent;
  193576. }
  193577. const File File::getCurrentWorkingDirectory()
  193578. {
  193579. char buf [2048];
  193580. return File (String::fromUTF8 ((const uint8*) getcwd (buf, sizeof (buf))));
  193581. }
  193582. bool File::setAsCurrentWorkingDirectory() const
  193583. {
  193584. return chdir (getFullPathName().toUTF8()) == 0;
  193585. }
  193586. const String File::getVersion() const
  193587. {
  193588. return String::empty; // xxx not yet implemented
  193589. }
  193590. const File File::getLinkedTarget() const
  193591. {
  193592. char buffer [4096];
  193593. size_t numChars = readlink ((const char*) getFullPathName().toUTF8(),
  193594. buffer, sizeof (buffer));
  193595. if (numChars > 0 && numChars <= sizeof (buffer))
  193596. return File (String::fromUTF8 ((const uint8*) buffer, (int) numChars));
  193597. return *this;
  193598. }
  193599. bool File::moveToTrash() const
  193600. {
  193601. if (! exists())
  193602. return true;
  193603. File trashCan (T("~/.Trash"));
  193604. if (! trashCan.isDirectory())
  193605. trashCan = T("~/.local/share/Trash/files");
  193606. if (! trashCan.isDirectory())
  193607. return false;
  193608. return moveFileTo (trashCan.getNonexistentChildFile (getFileNameWithoutExtension(),
  193609. getFileExtension()));
  193610. }
  193611. struct FindFileStruct
  193612. {
  193613. String parentDir, wildCard;
  193614. DIR* dir;
  193615. bool getNextMatch (String& result, bool* const isDir, bool* const isHidden, int64* const fileSize,
  193616. Time* const modTime, Time* const creationTime, bool* const isReadOnly)
  193617. {
  193618. const char* const wildcardUTF8 = wildCard.toUTF8();
  193619. for (;;)
  193620. {
  193621. struct dirent* const de = readdir (dir);
  193622. if (de == 0)
  193623. break;
  193624. if (fnmatch (wildcardUTF8, de->d_name, FNM_CASEFOLD) == 0)
  193625. {
  193626. result = String::fromUTF8 ((const uint8*) de->d_name);
  193627. const String path (parentDir + result);
  193628. if (isDir != 0 || fileSize != 0)
  193629. {
  193630. struct stat info;
  193631. const bool statOk = (stat (path.toUTF8(), &info) == 0);
  193632. if (isDir != 0)
  193633. *isDir = path.isEmpty() || (statOk && ((info.st_mode & S_IFDIR) != 0));
  193634. if (isHidden != 0)
  193635. *isHidden = (de->d_name[0] == '.');
  193636. if (fileSize != 0)
  193637. *fileSize = statOk ? info.st_size : 0;
  193638. }
  193639. if (modTime != 0 || creationTime != 0)
  193640. {
  193641. int64 m, a, c;
  193642. juce_getFileTimes (path, m, a, c);
  193643. if (modTime != 0)
  193644. *modTime = m;
  193645. if (creationTime != 0)
  193646. *creationTime = c;
  193647. }
  193648. if (isReadOnly != 0)
  193649. *isReadOnly = ! juce_canWriteToFile (path);
  193650. return true;
  193651. }
  193652. }
  193653. return false;
  193654. }
  193655. };
  193656. // returns 0 on failure
  193657. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  193658. bool* isDir, bool* isHidden, int64* fileSize, Time* modTime,
  193659. Time* creationTime, bool* isReadOnly)
  193660. {
  193661. DIR* d = opendir (directory.toUTF8());
  193662. if (d != 0)
  193663. {
  193664. FindFileStruct* ff = new FindFileStruct();
  193665. ff->parentDir = directory;
  193666. if (!ff->parentDir.endsWithChar (File::separator))
  193667. ff->parentDir += File::separator;
  193668. ff->wildCard = wildCard;
  193669. if (wildCard == T("*.*"))
  193670. ff->wildCard = T("*");
  193671. ff->dir = d;
  193672. if (ff->getNextMatch (firstResultFile, isDir, isHidden, fileSize, modTime, creationTime, isReadOnly))
  193673. {
  193674. return ff;
  193675. }
  193676. else
  193677. {
  193678. firstResultFile = String::empty;
  193679. isDir = false;
  193680. isHidden = false;
  193681. closedir (d);
  193682. delete ff;
  193683. }
  193684. }
  193685. return 0;
  193686. }
  193687. bool juce_findFileNext (void* handle, String& resultFile,
  193688. bool* isDir, bool* isHidden, int64* fileSize, Time* modTime, Time* creationTime, bool* isReadOnly)
  193689. {
  193690. FindFileStruct* const ff = (FindFileStruct*) handle;
  193691. if (ff != 0)
  193692. return ff->getNextMatch (resultFile, isDir, isHidden, fileSize, modTime, creationTime, isReadOnly);
  193693. return false;
  193694. }
  193695. void juce_findFileClose (void* handle)
  193696. {
  193697. FindFileStruct* const ff = (FindFileStruct*) handle;
  193698. if (ff != 0)
  193699. {
  193700. closedir (ff->dir);
  193701. delete ff;
  193702. }
  193703. }
  193704. bool juce_launchFile (const String& fileName,
  193705. const String& parameters)
  193706. {
  193707. String cmdString (fileName.replace (T(" "), T("\\ "),false));
  193708. cmdString << " " << parameters;
  193709. if (URL::isProbablyAWebsiteURL (fileName)
  193710. || cmdString.startsWithIgnoreCase (T("file:"))
  193711. || URL::isProbablyAnEmailAddress (fileName))
  193712. {
  193713. // create a command that tries to launch a bunch of likely browsers
  193714. const char* const browserNames[] = { "xdg-open", "/etc/alternatives/x-www-browser", "firefox", "mozilla", "konqueror", "opera" };
  193715. StringArray cmdLines;
  193716. for (int i = 0; i < numElementsInArray (browserNames); ++i)
  193717. cmdLines.add (String (browserNames[i]) + T(" ") + cmdString.trim().quoted());
  193718. cmdString = cmdLines.joinIntoString (T(" || "));
  193719. }
  193720. const char* const argv[4] = { "/bin/sh", "-c", (const char*) cmdString.toUTF8(), 0 };
  193721. const int cpid = fork();
  193722. if (cpid == 0)
  193723. {
  193724. setsid();
  193725. // Child process
  193726. execve (argv[0], (char**) argv, environ);
  193727. exit (0);
  193728. }
  193729. return cpid >= 0;
  193730. }
  193731. void File::revealToUser() const
  193732. {
  193733. if (isDirectory())
  193734. startAsProcess();
  193735. else if (getParentDirectory().exists())
  193736. getParentDirectory().startAsProcess();
  193737. }
  193738. #endif
  193739. /*** End of inlined file: juce_linux_Files.cpp ***/
  193740. /*** Start of inlined file: juce_posix_NamedPipe.cpp ***/
  193741. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  193742. // compiled on its own).
  193743. #if JUCE_INCLUDED_FILE
  193744. struct NamedPipeInternal
  193745. {
  193746. String pipeInName, pipeOutName;
  193747. int pipeIn, pipeOut;
  193748. bool volatile createdPipe, blocked, stopReadOperation;
  193749. static void signalHandler (int) {}
  193750. };
  193751. void NamedPipe::cancelPendingReads()
  193752. {
  193753. while (internal != 0 && ((NamedPipeInternal*) internal)->blocked)
  193754. {
  193755. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  193756. intern->stopReadOperation = true;
  193757. char buffer [1] = { 0 };
  193758. int bytesWritten = (int) ::write (intern->pipeIn, buffer, 1);
  193759. (void) bytesWritten;
  193760. int timeout = 2000;
  193761. while (intern->blocked && --timeout >= 0)
  193762. Thread::sleep (2);
  193763. intern->stopReadOperation = false;
  193764. }
  193765. }
  193766. void NamedPipe::close()
  193767. {
  193768. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  193769. if (intern != 0)
  193770. {
  193771. internal = 0;
  193772. if (intern->pipeIn != -1)
  193773. ::close (intern->pipeIn);
  193774. if (intern->pipeOut != -1)
  193775. ::close (intern->pipeOut);
  193776. if (intern->createdPipe)
  193777. {
  193778. unlink (intern->pipeInName);
  193779. unlink (intern->pipeOutName);
  193780. }
  193781. delete intern;
  193782. }
  193783. }
  193784. bool NamedPipe::openInternal (const String& pipeName, const bool createPipe)
  193785. {
  193786. close();
  193787. NamedPipeInternal* const intern = new NamedPipeInternal();
  193788. internal = intern;
  193789. intern->createdPipe = createPipe;
  193790. intern->blocked = false;
  193791. intern->stopReadOperation = false;
  193792. signal (SIGPIPE, NamedPipeInternal::signalHandler);
  193793. siginterrupt (SIGPIPE, 1);
  193794. const String pipePath (T("/tmp/") + File::createLegalFileName (pipeName));
  193795. intern->pipeInName = pipePath + T("_in");
  193796. intern->pipeOutName = pipePath + T("_out");
  193797. intern->pipeIn = -1;
  193798. intern->pipeOut = -1;
  193799. if (createPipe)
  193800. {
  193801. if ((mkfifo (intern->pipeInName, 0666) && errno != EEXIST)
  193802. || (mkfifo (intern->pipeOutName, 0666) && errno != EEXIST))
  193803. {
  193804. delete intern;
  193805. internal = 0;
  193806. return false;
  193807. }
  193808. }
  193809. return true;
  193810. }
  193811. int NamedPipe::read (void* destBuffer, int maxBytesToRead, int /*timeOutMilliseconds*/)
  193812. {
  193813. int bytesRead = -1;
  193814. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  193815. if (intern != 0)
  193816. {
  193817. intern->blocked = true;
  193818. if (intern->pipeIn == -1)
  193819. {
  193820. if (intern->createdPipe)
  193821. intern->pipeIn = ::open (intern->pipeInName, O_RDWR);
  193822. else
  193823. intern->pipeIn = ::open (intern->pipeOutName, O_RDWR);
  193824. if (intern->pipeIn == -1)
  193825. {
  193826. intern->blocked = false;
  193827. return -1;
  193828. }
  193829. }
  193830. bytesRead = 0;
  193831. char* p = (char*) destBuffer;
  193832. while (bytesRead < maxBytesToRead)
  193833. {
  193834. const int bytesThisTime = maxBytesToRead - bytesRead;
  193835. const int numRead = (int) ::read (intern->pipeIn, p, bytesThisTime);
  193836. if (numRead <= 0 || intern->stopReadOperation)
  193837. {
  193838. bytesRead = -1;
  193839. break;
  193840. }
  193841. bytesRead += numRead;
  193842. p += bytesRead;
  193843. }
  193844. intern->blocked = false;
  193845. }
  193846. return bytesRead;
  193847. }
  193848. int NamedPipe::write (const void* sourceBuffer, int numBytesToWrite, int timeOutMilliseconds)
  193849. {
  193850. int bytesWritten = -1;
  193851. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  193852. if (intern != 0)
  193853. {
  193854. if (intern->pipeOut == -1)
  193855. {
  193856. if (intern->createdPipe)
  193857. intern->pipeOut = ::open (intern->pipeOutName, O_WRONLY);
  193858. else
  193859. intern->pipeOut = ::open (intern->pipeInName, O_WRONLY);
  193860. if (intern->pipeOut == -1)
  193861. {
  193862. return -1;
  193863. }
  193864. }
  193865. const char* p = (const char*) sourceBuffer;
  193866. bytesWritten = 0;
  193867. const uint32 timeOutTime = Time::getMillisecondCounter() + timeOutMilliseconds;
  193868. while (bytesWritten < numBytesToWrite
  193869. && (timeOutMilliseconds < 0 || Time::getMillisecondCounter() < timeOutTime))
  193870. {
  193871. const int bytesThisTime = numBytesToWrite - bytesWritten;
  193872. const int numWritten = (int) ::write (intern->pipeOut, p, bytesThisTime);
  193873. if (numWritten <= 0)
  193874. {
  193875. bytesWritten = -1;
  193876. break;
  193877. }
  193878. bytesWritten += numWritten;
  193879. p += bytesWritten;
  193880. }
  193881. }
  193882. return bytesWritten;
  193883. }
  193884. #endif
  193885. /*** End of inlined file: juce_posix_NamedPipe.cpp ***/
  193886. /*** Start of inlined file: juce_linux_Network.cpp ***/
  193887. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  193888. // compiled on its own).
  193889. #if JUCE_INCLUDED_FILE
  193890. int SystemStats::getMACAddresses (int64* addresses, int maxNum, const bool littleEndian) throw()
  193891. {
  193892. int numResults = 0;
  193893. const int s = socket (AF_INET, SOCK_DGRAM, 0);
  193894. if (s != -1)
  193895. {
  193896. char buf [1024];
  193897. struct ifconf ifc;
  193898. ifc.ifc_len = sizeof (buf);
  193899. ifc.ifc_buf = buf;
  193900. ioctl (s, SIOCGIFCONF, &ifc);
  193901. for (unsigned int i = 0; i < ifc.ifc_len / sizeof (struct ifreq); ++i)
  193902. {
  193903. struct ifreq ifr;
  193904. strcpy (ifr.ifr_name, ifc.ifc_req[i].ifr_name);
  193905. if (ioctl (s, SIOCGIFFLAGS, &ifr) == 0
  193906. && (ifr.ifr_flags & IFF_LOOPBACK) == 0
  193907. && ioctl (s, SIOCGIFHWADDR, &ifr) == 0
  193908. && numResults < maxNum)
  193909. {
  193910. int64 a = 0;
  193911. for (int j = 6; --j >= 0;)
  193912. a = (a << 8) | (uint8) ifr.ifr_hwaddr.sa_data [littleEndian ? j : (5 - j)];
  193913. *addresses++ = a;
  193914. ++numResults;
  193915. }
  193916. }
  193917. close (s);
  193918. }
  193919. return numResults;
  193920. }
  193921. bool PlatformUtilities::launchEmailWithAttachments (const String& targetEmailAddress,
  193922. const String& emailSubject,
  193923. const String& bodyText,
  193924. const StringArray& filesToAttach)
  193925. {
  193926. jassertfalse // xxx todo
  193927. return false;
  193928. }
  193929. class JUCE_HTTPSocketStream
  193930. {
  193931. public:
  193932. JUCE_HTTPSocketStream()
  193933. : readPosition (0),
  193934. socketHandle (-1),
  193935. levelsOfRedirection (0),
  193936. timeoutSeconds (15)
  193937. {
  193938. }
  193939. ~JUCE_HTTPSocketStream()
  193940. {
  193941. closeSocket();
  193942. }
  193943. bool open (const String& url,
  193944. const String& headers,
  193945. const MemoryBlock& postData,
  193946. const bool isPost,
  193947. URL::OpenStreamProgressCallback* callback,
  193948. void* callbackContext,
  193949. int timeOutMs)
  193950. {
  193951. closeSocket();
  193952. uint32 timeOutTime = Time::getMillisecondCounter();
  193953. if (timeOutMs == 0)
  193954. timeOutTime += 60000;
  193955. else if (timeOutMs < 0)
  193956. timeOutTime = 0xffffffff;
  193957. else
  193958. timeOutTime += timeOutMs;
  193959. String hostName, hostPath;
  193960. int hostPort;
  193961. if (! decomposeURL (url, hostName, hostPath, hostPort))
  193962. return false;
  193963. const struct hostent* host = 0;
  193964. int port = 0;
  193965. String proxyName, proxyPath;
  193966. int proxyPort = 0;
  193967. String proxyURL (getenv ("http_proxy"));
  193968. if (proxyURL.startsWithIgnoreCase (T("http://")))
  193969. {
  193970. if (! decomposeURL (proxyURL, proxyName, proxyPath, proxyPort))
  193971. return false;
  193972. host = gethostbyname ((const char*) proxyName.toUTF8());
  193973. port = proxyPort;
  193974. }
  193975. else
  193976. {
  193977. host = gethostbyname ((const char*) hostName.toUTF8());
  193978. port = hostPort;
  193979. }
  193980. if (host == 0)
  193981. return false;
  193982. struct sockaddr_in address;
  193983. zerostruct (address);
  193984. memcpy ((void*) &address.sin_addr, (const void*) host->h_addr, host->h_length);
  193985. address.sin_family = host->h_addrtype;
  193986. address.sin_port = htons (port);
  193987. socketHandle = socket (host->h_addrtype, SOCK_STREAM, 0);
  193988. if (socketHandle == -1)
  193989. return false;
  193990. int receiveBufferSize = 16384;
  193991. setsockopt (socketHandle, SOL_SOCKET, SO_RCVBUF, (char*) &receiveBufferSize, sizeof (receiveBufferSize));
  193992. setsockopt (socketHandle, SOL_SOCKET, SO_KEEPALIVE, 0, 0);
  193993. #if JUCE_MAC
  193994. setsockopt (socketHandle, SOL_SOCKET, SO_NOSIGPIPE, 0, 0);
  193995. #endif
  193996. if (connect (socketHandle, (struct sockaddr*) &address, sizeof (address)) == -1)
  193997. {
  193998. closeSocket();
  193999. return false;
  194000. }
  194001. const MemoryBlock requestHeader (createRequestHeader (hostName, hostPort,
  194002. proxyName, proxyPort,
  194003. hostPath, url,
  194004. headers, postData,
  194005. isPost));
  194006. size_t totalHeaderSent = 0;
  194007. while (totalHeaderSent < requestHeader.getSize())
  194008. {
  194009. if (Time::getMillisecondCounter() > timeOutTime)
  194010. {
  194011. closeSocket();
  194012. return false;
  194013. }
  194014. const int numToSend = jmin (1024, (int) (requestHeader.getSize() - totalHeaderSent));
  194015. if (send (socketHandle,
  194016. ((const char*) requestHeader.getData()) + totalHeaderSent,
  194017. numToSend, 0)
  194018. != numToSend)
  194019. {
  194020. closeSocket();
  194021. return false;
  194022. }
  194023. totalHeaderSent += numToSend;
  194024. if (callback != 0 && ! callback (callbackContext, totalHeaderSent, requestHeader.getSize()))
  194025. {
  194026. closeSocket();
  194027. return false;
  194028. }
  194029. }
  194030. const String responseHeader (readResponse (timeOutTime));
  194031. if (responseHeader.isNotEmpty())
  194032. {
  194033. //DBG (responseHeader);
  194034. StringArray lines;
  194035. lines.addLines (responseHeader);
  194036. // NB - using charToString() here instead of just T(" "), because that was
  194037. // causing a mysterious gcc internal compiler error...
  194038. const int statusCode = responseHeader.fromFirstOccurrenceOf (String::charToString (T(' ')), false, false)
  194039. .substring (0, 3).getIntValue();
  194040. //int contentLength = findHeaderItem (lines, T("Content-Length:")).getIntValue();
  194041. //bool isChunked = findHeaderItem (lines, T("Transfer-Encoding:")).equalsIgnoreCase ("chunked");
  194042. String location (findHeaderItem (lines, T("Location:")));
  194043. if (statusCode >= 300 && statusCode < 400
  194044. && location.isNotEmpty())
  194045. {
  194046. if (! location.startsWithIgnoreCase (T("http://")))
  194047. location = T("http://") + location;
  194048. if (levelsOfRedirection++ < 3)
  194049. return open (location, headers, postData, isPost, callback, callbackContext, timeOutMs);
  194050. }
  194051. else
  194052. {
  194053. levelsOfRedirection = 0;
  194054. return true;
  194055. }
  194056. }
  194057. closeSocket();
  194058. return false;
  194059. }
  194060. int read (void* buffer, int bytesToRead)
  194061. {
  194062. fd_set readbits;
  194063. FD_ZERO (&readbits);
  194064. FD_SET (socketHandle, &readbits);
  194065. struct timeval tv;
  194066. tv.tv_sec = timeoutSeconds;
  194067. tv.tv_usec = 0;
  194068. if (select (socketHandle + 1, &readbits, 0, 0, &tv) <= 0)
  194069. return 0; // (timeout)
  194070. const int bytesRead = jmax (0, (int) recv (socketHandle, buffer, bytesToRead, MSG_WAITALL));
  194071. readPosition += bytesRead;
  194072. return bytesRead;
  194073. }
  194074. int readPosition;
  194075. juce_UseDebuggingNewOperator
  194076. private:
  194077. int socketHandle, levelsOfRedirection;
  194078. const int timeoutSeconds;
  194079. void closeSocket()
  194080. {
  194081. if (socketHandle >= 0)
  194082. close (socketHandle);
  194083. socketHandle = -1;
  194084. }
  194085. const MemoryBlock createRequestHeader (const String& hostName,
  194086. const int hostPort,
  194087. const String& proxyName,
  194088. const int proxyPort,
  194089. const String& hostPath,
  194090. const String& originalURL,
  194091. const String& headers,
  194092. const MemoryBlock& postData,
  194093. const bool isPost)
  194094. {
  194095. String header (isPost ? "POST " : "GET ");
  194096. if (proxyName.isEmpty())
  194097. {
  194098. header << hostPath << " HTTP/1.0\r\nHost: "
  194099. << hostName << ':' << hostPort;
  194100. }
  194101. else
  194102. {
  194103. header << originalURL << " HTTP/1.0\r\nHost: "
  194104. << proxyName << ':' << proxyPort;
  194105. }
  194106. header << "\r\nUser-Agent: JUCE/"
  194107. << JUCE_MAJOR_VERSION << '.' << JUCE_MINOR_VERSION
  194108. << "\r\nConnection: Close\r\nContent-Length: "
  194109. << postData.getSize() << "\r\n"
  194110. << headers << "\r\n";
  194111. MemoryBlock mb;
  194112. mb.append (header.toUTF8(), (int) strlen (header.toUTF8()));
  194113. mb.append (postData.getData(), postData.getSize());
  194114. return mb;
  194115. }
  194116. const String readResponse (const uint32 timeOutTime)
  194117. {
  194118. int bytesRead = 0, numConsecutiveLFs = 0;
  194119. MemoryBlock buffer (1024, true);
  194120. while (numConsecutiveLFs < 2 && bytesRead < 32768
  194121. && Time::getMillisecondCounter() <= timeOutTime)
  194122. {
  194123. fd_set readbits;
  194124. FD_ZERO (&readbits);
  194125. FD_SET (socketHandle, &readbits);
  194126. struct timeval tv;
  194127. tv.tv_sec = timeoutSeconds;
  194128. tv.tv_usec = 0;
  194129. if (select (socketHandle + 1, &readbits, 0, 0, &tv) <= 0)
  194130. return String::empty; // (timeout)
  194131. buffer.ensureSize (bytesRead + 8, true);
  194132. char* const dest = (char*) buffer.getData() + bytesRead;
  194133. if (recv (socketHandle, dest, 1, 0) == -1)
  194134. return String::empty;
  194135. const char lastByte = *dest;
  194136. ++bytesRead;
  194137. if (lastByte == '\n')
  194138. ++numConsecutiveLFs;
  194139. else if (lastByte != '\r')
  194140. numConsecutiveLFs = 0;
  194141. }
  194142. const String header (String::fromUTF8 ((const uint8*) buffer.getData()));
  194143. if (header.startsWithIgnoreCase (T("HTTP/")))
  194144. return header.trimEnd();
  194145. return String::empty;
  194146. }
  194147. static bool decomposeURL (const String& url,
  194148. String& host, String& path, int& port)
  194149. {
  194150. if (! url.startsWithIgnoreCase (T("http://")))
  194151. return false;
  194152. const int nextSlash = url.indexOfChar (7, '/');
  194153. int nextColon = url.indexOfChar (7, ':');
  194154. if (nextColon > nextSlash && nextSlash > 0)
  194155. nextColon = -1;
  194156. if (nextColon >= 0)
  194157. {
  194158. host = url.substring (7, nextColon);
  194159. if (nextSlash >= 0)
  194160. port = url.substring (nextColon + 1, nextSlash).getIntValue();
  194161. else
  194162. port = url.substring (nextColon + 1).getIntValue();
  194163. }
  194164. else
  194165. {
  194166. port = 80;
  194167. if (nextSlash >= 0)
  194168. host = url.substring (7, nextSlash);
  194169. else
  194170. host = url.substring (7);
  194171. }
  194172. if (nextSlash >= 0)
  194173. path = url.substring (nextSlash);
  194174. else
  194175. path = T("/");
  194176. return true;
  194177. }
  194178. static const String findHeaderItem (const StringArray& lines, const String& itemName)
  194179. {
  194180. for (int i = 0; i < lines.size(); ++i)
  194181. if (lines[i].startsWithIgnoreCase (itemName))
  194182. return lines[i].substring (itemName.length()).trim();
  194183. return String::empty;
  194184. }
  194185. };
  194186. bool juce_isOnLine()
  194187. {
  194188. return true;
  194189. }
  194190. void* juce_openInternetFile (const String& url,
  194191. const String& headers,
  194192. const MemoryBlock& postData,
  194193. const bool isPost,
  194194. URL::OpenStreamProgressCallback* callback,
  194195. void* callbackContext,
  194196. int timeOutMs)
  194197. {
  194198. JUCE_HTTPSocketStream* const s = new JUCE_HTTPSocketStream();
  194199. if (s->open (url, headers, postData, isPost,
  194200. callback, callbackContext, timeOutMs))
  194201. return s;
  194202. delete s;
  194203. return 0;
  194204. }
  194205. void juce_closeInternetFile (void* handle)
  194206. {
  194207. JUCE_HTTPSocketStream* const s = (JUCE_HTTPSocketStream*) handle;
  194208. if (s != 0)
  194209. delete s;
  194210. }
  194211. int juce_readFromInternetFile (void* handle, void* buffer, int bytesToRead)
  194212. {
  194213. JUCE_HTTPSocketStream* const s = (JUCE_HTTPSocketStream*) handle;
  194214. if (s != 0)
  194215. return s->read (buffer, bytesToRead);
  194216. return 0;
  194217. }
  194218. int64 juce_getInternetFileContentLength (void* handle)
  194219. {
  194220. JUCE_HTTPSocketStream* const s = (JUCE_HTTPSocketStream*) handle;
  194221. if (s != 0)
  194222. {
  194223. //xxx todo
  194224. jassertfalse
  194225. }
  194226. return -1;
  194227. }
  194228. int juce_seekInInternetFile (void* handle, int newPosition)
  194229. {
  194230. JUCE_HTTPSocketStream* const s = (JUCE_HTTPSocketStream*) handle;
  194231. if (s != 0)
  194232. return s->readPosition;
  194233. return 0;
  194234. }
  194235. #endif
  194236. /*** End of inlined file: juce_linux_Network.cpp ***/
  194237. /*** Start of inlined file: juce_linux_SystemStats.cpp ***/
  194238. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  194239. // compiled on its own).
  194240. #if JUCE_INCLUDED_FILE
  194241. void Logger::outputDebugString (const String& text) throw()
  194242. {
  194243. fputs (text.toUTF8(), stdout);
  194244. fputs ("\n", stdout);
  194245. }
  194246. void Logger::outputDebugPrintf (const tchar* format, ...) throw()
  194247. {
  194248. String text;
  194249. va_list args;
  194250. va_start (args, format);
  194251. text.vprintf(format, args);
  194252. outputDebugString(text);
  194253. }
  194254. SystemStats::OperatingSystemType SystemStats::getOperatingSystemType() throw()
  194255. {
  194256. return Linux;
  194257. }
  194258. const String SystemStats::getOperatingSystemName() throw()
  194259. {
  194260. return T("Linux");
  194261. }
  194262. bool SystemStats::isOperatingSystem64Bit() throw()
  194263. {
  194264. #if JUCE_64BIT
  194265. return true;
  194266. #else
  194267. //xxx not sure how to find this out?..
  194268. return false;
  194269. #endif
  194270. }
  194271. static const String getCpuInfo (const char* key, bool lastOne = false) throw()
  194272. {
  194273. String info;
  194274. char buf [256];
  194275. FILE* f = fopen ("/proc/cpuinfo", "r");
  194276. while (f != 0 && fgets (buf, sizeof(buf), f))
  194277. {
  194278. if (strncmp (buf, key, strlen (key)) == 0)
  194279. {
  194280. char* p = buf;
  194281. while (*p && *p != '\n')
  194282. ++p;
  194283. if (*p != 0)
  194284. *p = 0;
  194285. p = buf;
  194286. while (*p != 0 && *p != ':')
  194287. ++p;
  194288. if (*p != 0 && *(p + 1) != 0)
  194289. info = p + 2;
  194290. if (! lastOne)
  194291. break;
  194292. }
  194293. }
  194294. fclose (f);
  194295. return info;
  194296. }
  194297. bool SystemStats::hasMMX() throw()
  194298. {
  194299. return getCpuInfo ("flags").contains (T("mmx"));
  194300. }
  194301. bool SystemStats::hasSSE() throw()
  194302. {
  194303. return getCpuInfo ("flags").contains (T("sse"));
  194304. }
  194305. bool SystemStats::hasSSE2() throw()
  194306. {
  194307. return getCpuInfo ("flags").contains (T("sse2"));
  194308. }
  194309. bool SystemStats::has3DNow() throw()
  194310. {
  194311. return getCpuInfo ("flags").contains (T("3dnow"));
  194312. }
  194313. const String SystemStats::getCpuVendor() throw()
  194314. {
  194315. return getCpuInfo ("vendor_id");
  194316. }
  194317. int SystemStats::getCpuSpeedInMegaherz() throw()
  194318. {
  194319. const String speed (getCpuInfo ("cpu MHz"));
  194320. return (int) (speed.getFloatValue() + 0.5f);
  194321. }
  194322. int SystemStats::getMemorySizeInMegabytes() throw()
  194323. {
  194324. struct sysinfo sysi;
  194325. if (sysinfo (&sysi) == 0)
  194326. return (sysi.totalram * sysi.mem_unit / (1024 * 1024));
  194327. return 0;
  194328. }
  194329. uint32 juce_millisecondsSinceStartup() throw()
  194330. {
  194331. static unsigned int calibrate = 0;
  194332. static bool calibrated = false;
  194333. timeval t;
  194334. unsigned int ret = 0;
  194335. if (! gettimeofday (&t, 0))
  194336. {
  194337. if (! calibrated)
  194338. {
  194339. struct sysinfo sysi;
  194340. if (sysinfo (&sysi) == 0)
  194341. // Safe to assume system was not brought up earlier than 1970!
  194342. calibrate = t.tv_sec - sysi.uptime;
  194343. calibrated = true;
  194344. }
  194345. ret = 1000 * (t.tv_sec - calibrate) + (t.tv_usec / 1000);
  194346. }
  194347. return ret;
  194348. }
  194349. double Time::getMillisecondCounterHiRes() throw()
  194350. {
  194351. return getHighResolutionTicks() * 0.001;
  194352. }
  194353. int64 Time::getHighResolutionTicks() throw()
  194354. {
  194355. timeval t;
  194356. if (gettimeofday (&t, 0))
  194357. return 0;
  194358. return ((int64) t.tv_sec * (int64) 1000000) + (int64) t.tv_usec;
  194359. }
  194360. int64 Time::getHighResolutionTicksPerSecond() throw()
  194361. {
  194362. // Microseconds
  194363. return 1000000;
  194364. }
  194365. bool Time::setSystemTimeToThisTime() const throw()
  194366. {
  194367. timeval t;
  194368. t.tv_sec = millisSinceEpoch % 1000000;
  194369. t.tv_usec = millisSinceEpoch - t.tv_sec;
  194370. return settimeofday (&t, NULL) ? false : true;
  194371. }
  194372. int SystemStats::getPageSize() throw()
  194373. {
  194374. static int systemPageSize = 0;
  194375. if (systemPageSize == 0)
  194376. systemPageSize = sysconf (_SC_PAGESIZE);
  194377. return systemPageSize;
  194378. }
  194379. int SystemStats::getNumCpus() throw()
  194380. {
  194381. const int lastCpu = getCpuInfo ("processor", true).getIntValue();
  194382. return lastCpu + 1;
  194383. }
  194384. const String SystemStats::getLogonName()
  194385. {
  194386. const char* user = getenv ("USER");
  194387. if (user == 0)
  194388. {
  194389. struct passwd* const pw = getpwuid (getuid());
  194390. if (pw != 0)
  194391. user = pw->pw_name;
  194392. }
  194393. return String::fromUTF8 ((const uint8*) user);
  194394. }
  194395. const String SystemStats::getFullUserName()
  194396. {
  194397. return getLogonName();
  194398. }
  194399. void SystemStats::initialiseStats() throw()
  194400. {
  194401. // Process starts off as root when running suid
  194402. Process::lowerPrivilege();
  194403. String s (SystemStats::getJUCEVersion());
  194404. }
  194405. void PlatformUtilities::fpuReset()
  194406. {
  194407. }
  194408. #endif
  194409. /*** End of inlined file: juce_linux_SystemStats.cpp ***/
  194410. /*** Start of inlined file: juce_linux_Threads.cpp ***/
  194411. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  194412. // compiled on its own).
  194413. #if JUCE_INCLUDED_FILE
  194414. void JUCE_API juce_threadEntryPoint (void*);
  194415. void* threadEntryProc (void* value)
  194416. {
  194417. // New threads start off as root when running suid
  194418. Process::lowerPrivilege();
  194419. juce_threadEntryPoint (value);
  194420. return 0;
  194421. }
  194422. void* juce_createThread (void* userData)
  194423. {
  194424. pthread_t handle = 0;
  194425. if (pthread_create (&handle, 0, threadEntryProc, userData) == 0)
  194426. {
  194427. pthread_detach (handle);
  194428. return (void*)handle;
  194429. }
  194430. return 0;
  194431. }
  194432. void juce_killThread (void* handle)
  194433. {
  194434. if (handle != 0)
  194435. pthread_cancel ((pthread_t)handle);
  194436. }
  194437. void juce_setCurrentThreadName (const String& /*name*/)
  194438. {
  194439. }
  194440. Thread::ThreadID Thread::getCurrentThreadId()
  194441. {
  194442. return (ThreadID) pthread_self();
  194443. }
  194444. // priority 1 to 10 where 5=normal, 1=low. If the handle is 0, sets the
  194445. // priority of the current thread
  194446. bool juce_setThreadPriority (void* handle, int priority)
  194447. {
  194448. struct sched_param param;
  194449. int policy, maxp, minp, pri;
  194450. if (handle == 0)
  194451. handle = (void*) pthread_self();
  194452. if (pthread_getschedparam ((pthread_t) handle, &policy, &param) == 0
  194453. && policy != SCHED_OTHER)
  194454. {
  194455. minp = sched_get_priority_min(policy);
  194456. maxp = sched_get_priority_max(policy);
  194457. pri = ((maxp - minp) / 2) * (priority - 1) / 9;
  194458. if (param.__sched_priority >= (minp + (maxp - minp) / 2))
  194459. // Realtime process priority
  194460. param.__sched_priority = minp + ((maxp - minp) / 2) + pri;
  194461. else
  194462. // High process priority
  194463. param.__sched_priority = minp + pri;
  194464. param.sched_priority = jlimit (1, 127, 1 + (priority * 126) / 11);
  194465. return pthread_setschedparam ((pthread_t) handle, policy, &param) == 0;
  194466. }
  194467. return false;
  194468. }
  194469. void Thread::setCurrentThreadAffinityMask (const uint32 affinityMask)
  194470. {
  194471. #if SUPPORT_AFFINITIES
  194472. cpu_set_t affinity;
  194473. CPU_ZERO (&affinity);
  194474. for (int i = 0; i < 32; ++i)
  194475. if ((affinityMask & (1 << i)) != 0)
  194476. CPU_SET (i, &affinity);
  194477. sched_setaffinity (getpid(), sizeof (cpu_set_t), &affinity);
  194478. sched_yield();
  194479. #else
  194480. /* affinities aren't supported because either the appropriate header files weren't found,
  194481. or the SUPPORT_AFFINITIES macro was turned off in linuxheaders.h
  194482. */
  194483. jassertfalse
  194484. #endif
  194485. }
  194486. void Thread::yield()
  194487. {
  194488. sched_yield();
  194489. }
  194490. // sets the process to 0=low priority, 1=normal, 2=high, 3=realtime
  194491. void Process::setPriority (ProcessPriority prior)
  194492. {
  194493. struct sched_param param;
  194494. int policy, maxp, minp;
  194495. const int p = (int) prior;
  194496. if (p <= 1)
  194497. policy = SCHED_OTHER;
  194498. else
  194499. policy = SCHED_RR;
  194500. minp = sched_get_priority_min (policy);
  194501. maxp = sched_get_priority_max (policy);
  194502. if (p < 2)
  194503. param.__sched_priority = 0;
  194504. else if (p == 2 )
  194505. // Set to middle of lower realtime priority range
  194506. param.__sched_priority = minp + (maxp - minp) / 4;
  194507. else
  194508. // Set to middle of higher realtime priority range
  194509. param.__sched_priority = minp + (3 * (maxp - minp) / 4);
  194510. pthread_setschedparam (pthread_self(), policy, &param);
  194511. }
  194512. void Process::terminate()
  194513. {
  194514. exit (0);
  194515. }
  194516. bool JUCE_PUBLIC_FUNCTION juce_isRunningUnderDebugger()
  194517. {
  194518. static char testResult = 0;
  194519. if (testResult == 0)
  194520. {
  194521. testResult = (char) ptrace (PT_TRACE_ME, 0, 0, 0);
  194522. if (testResult >= 0)
  194523. {
  194524. ptrace (PT_DETACH, 0, (caddr_t) 1, 0);
  194525. testResult = 1;
  194526. }
  194527. }
  194528. return testResult < 0;
  194529. }
  194530. bool JUCE_CALLTYPE Process::isRunningUnderDebugger()
  194531. {
  194532. return juce_isRunningUnderDebugger();
  194533. }
  194534. void Process::raisePrivilege()
  194535. {
  194536. // If running suid root, change effective user
  194537. // to root
  194538. if (geteuid() != 0 && getuid() == 0)
  194539. {
  194540. setreuid (geteuid(), getuid());
  194541. setregid (getegid(), getgid());
  194542. }
  194543. }
  194544. void Process::lowerPrivilege()
  194545. {
  194546. // If runing suid root, change effective user
  194547. // back to real user
  194548. if (geteuid() == 0 && getuid() != 0)
  194549. {
  194550. setreuid (geteuid(), getuid());
  194551. setregid (getegid(), getgid());
  194552. }
  194553. }
  194554. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  194555. void* PlatformUtilities::loadDynamicLibrary (const String& name)
  194556. {
  194557. return dlopen ((const char*) name.toUTF8(), RTLD_LOCAL | RTLD_NOW);
  194558. }
  194559. void PlatformUtilities::freeDynamicLibrary (void* handle)
  194560. {
  194561. dlclose(handle);
  194562. }
  194563. void* PlatformUtilities::getProcedureEntryPoint (void* libraryHandle, const String& procedureName)
  194564. {
  194565. return dlsym (libraryHandle, (const char*) procedureName);
  194566. }
  194567. #endif
  194568. #endif
  194569. /*** End of inlined file: juce_linux_Threads.cpp ***/
  194570. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  194571. /*** Start of inlined file: juce_linux_Clipboard.cpp ***/
  194572. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  194573. // compiled on its own).
  194574. #if JUCE_INCLUDED_FILE
  194575. #ifdef JUCE_DEBUG
  194576. #define JUCE_DEBUG_XERRORS 1
  194577. #endif
  194578. extern Display* display;
  194579. extern Window juce_messageWindowHandle;
  194580. static String localClipboardContent;
  194581. static Atom atom_UTF8_STRING;
  194582. static Atom atom_CLIPBOARD;
  194583. static Atom atom_TARGETS;
  194584. static void initSelectionAtoms()
  194585. {
  194586. static bool isInitialised = false;
  194587. if (! isInitialised)
  194588. {
  194589. atom_UTF8_STRING = XInternAtom (display, "UTF8_STRING", False);
  194590. atom_CLIPBOARD = XInternAtom (display, "CLIPBOARD", False);
  194591. atom_TARGETS = XInternAtom (display, "TARGETS", False);
  194592. }
  194593. }
  194594. // Read the content of a window property as either a locale-dependent string or an utf8 string
  194595. // works only for strings shorter than 1000000 bytes
  194596. static String juce_readWindowProperty (Window window, Atom prop,
  194597. Atom fmt, // XA_STRING or UTF8_STRING
  194598. bool deleteAfterReading)
  194599. {
  194600. String returnData;
  194601. uint8 *clipData;
  194602. Atom actualType;
  194603. int actualFormat;
  194604. unsigned long numItems, bytesLeft;
  194605. if (XGetWindowProperty (display, window, prop,
  194606. 0L /* offset */, 1000000 /* length (max) */, False,
  194607. AnyPropertyType /* format */,
  194608. &actualType, &actualFormat, &numItems, &bytesLeft,
  194609. &clipData) == Success)
  194610. {
  194611. if (actualType == atom_UTF8_STRING && actualFormat == 8)
  194612. {
  194613. returnData = String::fromUTF8 (clipData, numItems);
  194614. }
  194615. else if (actualType == XA_STRING && actualFormat == 8)
  194616. {
  194617. returnData = String ((const char*) clipData, numItems);
  194618. }
  194619. if (clipData != 0)
  194620. XFree (clipData);
  194621. jassert (bytesLeft == 0 || numItems == 1000000);
  194622. }
  194623. if (deleteAfterReading)
  194624. XDeleteProperty (display, window, prop);
  194625. return returnData;
  194626. }
  194627. // Send a SelectionRequest to the window owning the selection and waits for its answer (with a timeout) */
  194628. static bool juce_requestSelectionContent (String &selection_content, Atom selection, Atom requested_format)
  194629. {
  194630. Atom property_name = XInternAtom (display, "JUCE_SEL", false);
  194631. // The selection owner will be asked to set the JUCE_SEL property on the
  194632. // juce_messageWindowHandle with the selection content
  194633. XConvertSelection (display, selection, requested_format, property_name,
  194634. juce_messageWindowHandle, CurrentTime);
  194635. int timeoutMs = 200; // will wait at most for 200 ms
  194636. do
  194637. {
  194638. XEvent event;
  194639. if (XCheckTypedWindowEvent (display, juce_messageWindowHandle, SelectionNotify, &event))
  194640. {
  194641. if (event.xselection.property == property_name)
  194642. {
  194643. jassert (event.xselection.requestor == juce_messageWindowHandle);
  194644. selection_content = juce_readWindowProperty (event.xselection.requestor,
  194645. event.xselection.property,
  194646. requested_format, true);
  194647. return true;
  194648. }
  194649. else
  194650. {
  194651. return false; // the format we asked for was denied.. (event.xselection.property == None)
  194652. }
  194653. }
  194654. // not very elegant.. we could do a select() or something like that...
  194655. // however clipboard content requesting is inherently slow on x11, it
  194656. // often takes 50ms or more so...
  194657. Thread::sleep (4);
  194658. timeoutMs -= 4;
  194659. }
  194660. while (timeoutMs > 0);
  194661. DBG("timeout for juce_requestSelectionContent");
  194662. return false;
  194663. }
  194664. // Called from the event loop in juce_linux_Messaging in response to SelectionRequest events
  194665. void juce_handleSelectionRequest (XSelectionRequestEvent &evt)
  194666. {
  194667. initSelectionAtoms();
  194668. // the selection content is sent to the target window as a window property
  194669. XSelectionEvent reply;
  194670. reply.type = SelectionNotify;
  194671. reply.display = evt.display;
  194672. reply.requestor = evt.requestor;
  194673. reply.selection = evt.selection;
  194674. reply.target = evt.target;
  194675. reply.property = None; // == "fail"
  194676. reply.time = evt.time;
  194677. HeapBlock <char> data;
  194678. int propertyFormat = 0, numDataItems = 0;
  194679. if (evt.selection == XA_PRIMARY || evt.selection == atom_CLIPBOARD)
  194680. {
  194681. if (evt.target == XA_STRING)
  194682. {
  194683. // format data according to system locale
  194684. numDataItems = localClipboardContent.length();
  194685. data.calloc (numDataItems + 2);
  194686. localClipboardContent.copyToBuffer ((char*) data, numDataItems + 1);
  194687. propertyFormat = 8; // bits/item
  194688. }
  194689. else if (evt.target == atom_UTF8_STRING)
  194690. {
  194691. // translate to utf8
  194692. numDataItems = localClipboardContent.copyToUTF8 (0);
  194693. data.calloc (numDataItems + 2);
  194694. localClipboardContent.copyToUTF8 (data, numDataItems + 1);
  194695. propertyFormat = 8; // bits/item
  194696. }
  194697. else if (evt.target == atom_TARGETS)
  194698. {
  194699. // another application wants to know what we are able to send
  194700. numDataItems = 2;
  194701. propertyFormat = 32; // atoms are 32-bit
  194702. data.calloc (numDataItems * 4);
  194703. ((Atom*) data)[0] = atom_UTF8_STRING;
  194704. ((Atom*) data)[1] = XA_STRING;
  194705. }
  194706. }
  194707. else
  194708. {
  194709. DBG ("requested unsupported clipboard");
  194710. }
  194711. if (data != 0)
  194712. {
  194713. const int maxReasonableSelectionSize = 1000000;
  194714. // for very big chunks of data, we should use the "INCR" protocol , which is a pain in the *ss
  194715. if (evt.property != None && numDataItems < maxReasonableSelectionSize)
  194716. {
  194717. XChangeProperty (evt.display, evt.requestor,
  194718. evt.property, evt.target,
  194719. propertyFormat /* 8 or 32 */, PropModeReplace,
  194720. (const unsigned char*) data, numDataItems);
  194721. reply.property = evt.property; // " == success"
  194722. }
  194723. }
  194724. XSendEvent (evt.display, evt.requestor, 0, NoEventMask, (XEvent*) &reply);
  194725. }
  194726. void SystemClipboard::copyTextToClipboard (const String& clipText) throw()
  194727. {
  194728. initSelectionAtoms();
  194729. localClipboardContent = clipText;
  194730. XSetSelectionOwner (display, XA_PRIMARY, juce_messageWindowHandle, CurrentTime);
  194731. XSetSelectionOwner (display, atom_CLIPBOARD, juce_messageWindowHandle, CurrentTime);
  194732. }
  194733. const String SystemClipboard::getTextFromClipboard() throw()
  194734. {
  194735. initSelectionAtoms();
  194736. String content;
  194737. Atom selection = XA_PRIMARY;
  194738. Window selectionOwner = None;
  194739. if ((selectionOwner = XGetSelectionOwner (display, selection)) == None)
  194740. {
  194741. selection = atom_CLIPBOARD;
  194742. selectionOwner = XGetSelectionOwner (display, selection);
  194743. }
  194744. if (selectionOwner != None)
  194745. {
  194746. if (selectionOwner == juce_messageWindowHandle)
  194747. {
  194748. content = localClipboardContent;
  194749. }
  194750. else
  194751. {
  194752. // first try: we want an utf8 string
  194753. bool ok = juce_requestSelectionContent (content, selection, atom_UTF8_STRING);
  194754. if (! ok)
  194755. {
  194756. // second chance, ask for a good old locale-dependent string ..
  194757. ok = juce_requestSelectionContent (content, selection, XA_STRING);
  194758. }
  194759. }
  194760. }
  194761. return content;
  194762. }
  194763. #endif
  194764. /*** End of inlined file: juce_linux_Clipboard.cpp ***/
  194765. /*** Start of inlined file: juce_linux_Messaging.cpp ***/
  194766. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  194767. // compiled on its own).
  194768. #if JUCE_INCLUDED_FILE
  194769. #ifdef JUCE_DEBUG
  194770. #define JUCE_DEBUG_XERRORS 1
  194771. #endif
  194772. Display* display = 0; // This is also referenced from WindowDriver.cpp
  194773. Window juce_messageWindowHandle = None;
  194774. #define SpecialAtom "JUCESpecialAtom"
  194775. #define BroadcastAtom "JUCEBroadcastAtom"
  194776. #define SpecialCallbackAtom "JUCESpecialCallbackAtom"
  194777. static Atom specialId;
  194778. static Atom broadcastId;
  194779. static Atom specialCallbackId;
  194780. // This is referenced from Windowing.cpp
  194781. XContext improbableNumber;
  194782. // Defined in Windowing.cpp
  194783. extern void juce_windowMessageReceive (XEvent* event);
  194784. // Defined in Clipboard.cpp
  194785. extern void juce_handleSelectionRequest (XSelectionRequestEvent &evt);
  194786. ScopedXLock::ScopedXLock() { XLockDisplay (display); }
  194787. ScopedXLock::~ScopedXLock() { XUnlockDisplay (display); }
  194788. class InternalMessageQueue
  194789. {
  194790. public:
  194791. InternalMessageQueue()
  194792. : bytesInSocket (0)
  194793. {
  194794. int ret = ::socketpair (AF_LOCAL, SOCK_STREAM, 0, fd);
  194795. (void) ret; jassert (ret == 0);
  194796. setNonBlocking (fd[0]);
  194797. setNonBlocking (fd[1]);
  194798. }
  194799. ~InternalMessageQueue()
  194800. {
  194801. close (fd[0]);
  194802. close (fd[1]);
  194803. }
  194804. void postMessage (Message* msg)
  194805. {
  194806. const int maxBytesInSocketQueue = 128;
  194807. ScopedLock sl (lock);
  194808. queue.add (msg);
  194809. if (bytesInSocket < maxBytesInSocketQueue)
  194810. {
  194811. ++bytesInSocket;
  194812. ScopedUnlock ul (lock);
  194813. const unsigned char x = 0xff;
  194814. size_t bytesWritten = write (fd[0], &x, 1);
  194815. (void) bytesWritten;
  194816. }
  194817. }
  194818. bool isEmpty() const
  194819. {
  194820. ScopedLock sl (lock);
  194821. return queue.size() == 0;
  194822. }
  194823. Message* popNextMessage()
  194824. {
  194825. ScopedLock sl (lock);
  194826. if (bytesInSocket > 0)
  194827. {
  194828. --bytesInSocket;
  194829. ScopedUnlock ul (lock);
  194830. unsigned char x;
  194831. size_t numBytes = read (fd[1], &x, 1);
  194832. (void) numBytes;
  194833. }
  194834. Message* m = queue[0];
  194835. queue.remove (0, false /* deleteObject */);
  194836. return m;
  194837. }
  194838. int getWaitHandle() const { return fd[1]; }
  194839. private:
  194840. CriticalSection lock;
  194841. OwnedArray <Message> queue;
  194842. int fd[2];
  194843. int bytesInSocket;
  194844. static bool setNonBlocking (int handle)
  194845. {
  194846. int socketFlags = fcntl (handle, F_GETFL, 0);
  194847. if (socketFlags == -1)
  194848. return false;
  194849. socketFlags |= O_NONBLOCK;
  194850. return fcntl (handle, F_SETFL, socketFlags) == 0;
  194851. }
  194852. };
  194853. struct MessageThreadFuncCall
  194854. {
  194855. enum { uniqueID = 0x73774623 };
  194856. MessageCallbackFunction* func;
  194857. void* parameter;
  194858. void* result;
  194859. CriticalSection lock;
  194860. WaitableEvent event;
  194861. };
  194862. static InternalMessageQueue* juce_internalMessageQueue = 0;
  194863. // error handling in X11
  194864. static bool errorOccurred = false;
  194865. static bool keyboardBreakOccurred = false;
  194866. static XErrorHandler oldErrorHandler = (XErrorHandler) 0;
  194867. static XIOErrorHandler oldIOErrorHandler = (XIOErrorHandler) 0;
  194868. // Usually happens when client-server connection is broken
  194869. static int ioErrorHandler (Display* display)
  194870. {
  194871. DBG (T("ERROR: connection to X server broken.. terminating."));
  194872. errorOccurred = true;
  194873. if (JUCEApplication::getInstance() != 0)
  194874. Process::terminate();
  194875. return 0;
  194876. }
  194877. // A protocol error has occurred
  194878. static int errorHandler (Display* display, XErrorEvent* event)
  194879. {
  194880. #ifdef JUCE_DEBUG_XERRORS
  194881. char errorStr[64] = { 0 };
  194882. char requestStr[64] = { 0 };
  194883. XGetErrorText (display, event->error_code, errorStr, 64);
  194884. XGetErrorDatabaseText (display,
  194885. "XRequest",
  194886. (const char*) String (event->request_code),
  194887. "Unknown",
  194888. requestStr,
  194889. 64);
  194890. DBG (T("ERROR: X returned ") + String (errorStr) + T(" for operation ") + String (requestStr));
  194891. #endif
  194892. return 0;
  194893. }
  194894. // Breakin from keyboard
  194895. static void signalHandler (int sig)
  194896. {
  194897. if (sig == SIGINT)
  194898. {
  194899. keyboardBreakOccurred = true;
  194900. return;
  194901. }
  194902. static bool reentrant = false;
  194903. if (! reentrant)
  194904. {
  194905. reentrant = true;
  194906. // Illegal instruction
  194907. fflush (stdout);
  194908. Logger::outputDebugString ("ERROR: Program executed illegal instruction.. terminating");
  194909. errorOccurred = true;
  194910. if (JUCEApplication::getInstance() != 0)
  194911. Process::terminate();
  194912. }
  194913. else
  194914. {
  194915. if (JUCEApplication::getInstance() != 0)
  194916. exit(0);
  194917. }
  194918. }
  194919. void MessageManager::doPlatformSpecificInitialisation()
  194920. {
  194921. // Initialise xlib for multiple thread support
  194922. static bool initThreadCalled = false;
  194923. if (! initThreadCalled)
  194924. {
  194925. if (! XInitThreads())
  194926. {
  194927. // This is fatal! Print error and closedown
  194928. Logger::outputDebugString ("Failed to initialise xlib thread support.");
  194929. if (JUCEApplication::getInstance() != 0)
  194930. Process::terminate();
  194931. return;
  194932. }
  194933. initThreadCalled = true;
  194934. }
  194935. // This is called if the client/server connection is broken
  194936. oldIOErrorHandler = XSetIOErrorHandler (ioErrorHandler);
  194937. // This is called if a protocol error occurs
  194938. oldErrorHandler = XSetErrorHandler (errorHandler);
  194939. // Install signal handler for break-in
  194940. struct sigaction saction;
  194941. sigset_t maskSet;
  194942. sigemptyset (&maskSet);
  194943. saction.sa_handler = signalHandler;
  194944. saction.sa_mask = maskSet;
  194945. saction.sa_flags = 0;
  194946. sigaction (SIGINT, &saction, NULL);
  194947. #ifndef _DEBUG
  194948. // Setup signal handlers for various fatal errors
  194949. sigaction (SIGILL, &saction, NULL);
  194950. sigaction (SIGBUS, &saction, NULL);
  194951. sigaction (SIGFPE, &saction, NULL);
  194952. sigaction (SIGSEGV, &saction, NULL);
  194953. sigaction (SIGSYS, &saction, NULL);
  194954. #endif
  194955. // Create the internal message queue
  194956. juce_internalMessageQueue = new InternalMessageQueue();
  194957. // Try to connect to a display
  194958. String displayName (getenv ("DISPLAY"));
  194959. if (displayName.isEmpty())
  194960. displayName = T(":0.0");
  194961. display = XOpenDisplay (displayName);
  194962. if (display == 0)
  194963. {
  194964. // This is not fatal! we can run headless.
  194965. return;
  194966. }
  194967. // Get defaults for various properties
  194968. int screen = DefaultScreen (display);
  194969. Window root = RootWindow (display, screen);
  194970. Visual* visual = DefaultVisual (display, screen);
  194971. // Create atoms for our ClientMessages (these cannot be deleted)
  194972. specialId = XInternAtom (display, SpecialAtom, false);
  194973. broadcastId = XInternAtom (display, BroadcastAtom, false);
  194974. specialCallbackId = XInternAtom (display, SpecialCallbackAtom, false);
  194975. // Create a context to store user data associated with Windows we
  194976. // create in WindowDriver
  194977. improbableNumber = XUniqueContext();
  194978. // We're only interested in client messages for this window
  194979. // which are always sent
  194980. XSetWindowAttributes swa;
  194981. swa.event_mask = NoEventMask;
  194982. // Create our message window (this will never be mapped)
  194983. juce_messageWindowHandle = XCreateWindow (display, root,
  194984. 0, 0, 1, 1, 0, 0, InputOnly,
  194985. visual, CWEventMask, &swa);
  194986. }
  194987. void MessageManager::doPlatformSpecificShutdown()
  194988. {
  194989. deleteAndZero (juce_internalMessageQueue);
  194990. if (display != 0 && ! errorOccurred)
  194991. {
  194992. XDestroyWindow (display, juce_messageWindowHandle);
  194993. XCloseDisplay (display);
  194994. // reset pointers
  194995. juce_messageWindowHandle = 0;
  194996. display = 0;
  194997. // Restore original error handlers
  194998. XSetIOErrorHandler (oldIOErrorHandler);
  194999. oldIOErrorHandler = 0;
  195000. XSetErrorHandler (oldErrorHandler);
  195001. oldErrorHandler = 0;
  195002. }
  195003. }
  195004. bool juce_postMessageToSystemQueue (void* message)
  195005. {
  195006. if (errorOccurred)
  195007. return false;
  195008. juce_internalMessageQueue->postMessage ((Message*) message);
  195009. return true;
  195010. }
  195011. void MessageManager::broadcastMessage (const String& value) throw()
  195012. {
  195013. }
  195014. void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* func,
  195015. void* parameter)
  195016. {
  195017. if (errorOccurred)
  195018. return 0;
  195019. if (! isThisTheMessageThread())
  195020. {
  195021. MessageThreadFuncCall messageCallContext;
  195022. messageCallContext.func = func;
  195023. messageCallContext.parameter = parameter;
  195024. juce_internalMessageQueue->postMessage (new Message (MessageThreadFuncCall::uniqueID,
  195025. 0, 0, &messageCallContext));
  195026. // Wait for it to complete before continuing
  195027. messageCallContext.event.wait();
  195028. return messageCallContext.result;
  195029. }
  195030. else
  195031. {
  195032. // Just call the function directly
  195033. return func (parameter);
  195034. }
  195035. }
  195036. // Wait for an event (either XEvent, or an internal Message)
  195037. static bool juce_sleepUntilEvent (const int timeoutMs)
  195038. {
  195039. if (! juce_internalMessageQueue->isEmpty())
  195040. return true;
  195041. if (display != 0)
  195042. {
  195043. ScopedXLock xlock;
  195044. if (XPending (display))
  195045. return true;
  195046. }
  195047. struct timeval tv;
  195048. tv.tv_sec = 0;
  195049. tv.tv_usec = timeoutMs * 1000;
  195050. int fd0 = juce_internalMessageQueue->getWaitHandle();
  195051. int fdmax = fd0;
  195052. fd_set readset;
  195053. FD_ZERO (&readset);
  195054. FD_SET (fd0, &readset);
  195055. if (display != 0)
  195056. {
  195057. ScopedXLock xlock;
  195058. int fd1 = XConnectionNumber (display);
  195059. FD_SET (fd1, &readset);
  195060. fdmax = jmax (fd0, fd1);
  195061. }
  195062. const int ret = select (fdmax + 1, &readset, 0, 0, &tv);
  195063. return (ret > 0); // ret <= 0 if error or timeout
  195064. }
  195065. // Handle next XEvent (if any)
  195066. static bool juce_dispatchNextXEvent()
  195067. {
  195068. if (display == 0)
  195069. return false;
  195070. XEvent evt;
  195071. {
  195072. ScopedXLock xlock;
  195073. if (! XPending (display))
  195074. return false;
  195075. XNextEvent (display, &evt);
  195076. }
  195077. if (evt.type == SelectionRequest && evt.xany.window == juce_messageWindowHandle)
  195078. {
  195079. juce_handleSelectionRequest (evt.xselectionrequest);
  195080. }
  195081. else if (evt.xany.window != juce_messageWindowHandle)
  195082. {
  195083. juce_windowMessageReceive (&evt);
  195084. }
  195085. return true;
  195086. }
  195087. // Handle next internal Message (if any)
  195088. static bool juce_dispatchNextInternalMessage()
  195089. {
  195090. ScopedPointer <Message> msg (juce_internalMessageQueue->popNextMessage());
  195091. if (msg == 0)
  195092. return false;
  195093. if (msg->intParameter1 == MessageThreadFuncCall::uniqueID)
  195094. {
  195095. // Handle callback message
  195096. MessageThreadFuncCall* const call = (MessageThreadFuncCall*) msg->pointerParameter;
  195097. call->result = (*(call->func)) (call->parameter);
  195098. call->event.signal();
  195099. }
  195100. else
  195101. {
  195102. // Handle "normal" messages
  195103. MessageManager::getInstance()->deliverMessage (msg.release());
  195104. }
  195105. return true;
  195106. }
  195107. // this function expects that it will NEVER be called simultaneously for two concurrent threads
  195108. bool juce_dispatchNextMessageOnSystemQueue (bool returnIfNoPendingMessages)
  195109. {
  195110. for (;;)
  195111. {
  195112. if (errorOccurred)
  195113. break;
  195114. if (keyboardBreakOccurred)
  195115. {
  195116. errorOccurred = true;
  195117. if (JUCEApplication::getInstance() != 0)
  195118. Process::terminate();
  195119. break;
  195120. }
  195121. static int totalEventCount = 0;
  195122. ++totalEventCount;
  195123. // The purpose here is to give either priority to XEvents or
  195124. // to internal messages This is necessary to keep a "good"
  195125. // behaviour when the cpu is overloaded
  195126. if (totalEventCount & 1)
  195127. {
  195128. if (juce_dispatchNextXEvent() || juce_dispatchNextInternalMessage())
  195129. return true;
  195130. }
  195131. else
  195132. {
  195133. if (juce_dispatchNextInternalMessage() || juce_dispatchNextXEvent())
  195134. return true;
  195135. }
  195136. if (returnIfNoPendingMessages) // early exit
  195137. break;
  195138. // the timeout is to be on the safe side, but it does not seem to be useful
  195139. juce_sleepUntilEvent (2000);
  195140. }
  195141. return false;
  195142. }
  195143. #endif
  195144. /*** End of inlined file: juce_linux_Messaging.cpp ***/
  195145. /*** Start of inlined file: juce_linux_Fonts.cpp ***/
  195146. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  195147. // compiled on its own).
  195148. #if JUCE_INCLUDED_FILE
  195149. class FreeTypeFontFace
  195150. {
  195151. public:
  195152. enum FontStyle
  195153. {
  195154. Plain = 0,
  195155. Bold = 1,
  195156. Italic = 2
  195157. };
  195158. struct FontNameIndex
  195159. {
  195160. String fileName;
  195161. int faceIndex;
  195162. };
  195163. FreeTypeFontFace (const String& familyName) throw()
  195164. : hasSerif (false),
  195165. monospaced (false)
  195166. {
  195167. family = familyName;
  195168. }
  195169. void setFileName (const String& name, const int faceIndex, FontStyle style) throw()
  195170. {
  195171. if (names [(int) style].fileName.isEmpty())
  195172. {
  195173. names [(int) style].fileName = name;
  195174. names [(int) style].faceIndex = faceIndex;
  195175. }
  195176. }
  195177. const String& getFamilyName() const throw() { return family; }
  195178. const String& getFileName (const int style, int& faceIndex) const throw()
  195179. {
  195180. faceIndex = names[style].faceIndex;
  195181. return names[style].fileName;
  195182. }
  195183. void setMonospaced (bool mono) throw() { monospaced = mono; }
  195184. bool getMonospaced() const throw() { return monospaced; }
  195185. void setSerif (const bool serif) throw() { hasSerif = serif; }
  195186. bool getSerif() const throw() { return hasSerif; }
  195187. private:
  195188. String family;
  195189. FontNameIndex names[4];
  195190. bool hasSerif, monospaced;
  195191. };
  195192. class FreeTypeInterface : public DeletedAtShutdown
  195193. {
  195194. public:
  195195. FreeTypeInterface() throw()
  195196. : lastFace (0),
  195197. lastBold (false),
  195198. lastItalic (false)
  195199. {
  195200. if (FT_Init_FreeType (&ftLib) != 0)
  195201. {
  195202. ftLib = 0;
  195203. DBG (T("Failed to initialize FreeType"));
  195204. }
  195205. StringArray fontDirs;
  195206. fontDirs.addTokens (String (getenv ("JUCE_FONT_PATH")), T(";,"), 0);
  195207. fontDirs.removeEmptyStrings (true);
  195208. if (fontDirs.size() == 0)
  195209. {
  195210. XmlDocument fontsConfig (File ("/etc/fonts/fonts.conf"));
  195211. XmlElement* const fontsInfo = fontsConfig.getDocumentElement();
  195212. if (fontsInfo != 0)
  195213. {
  195214. forEachXmlChildElementWithTagName (*fontsInfo, e, T("dir"))
  195215. {
  195216. fontDirs.add (e->getAllSubText().trim());
  195217. }
  195218. delete fontsInfo;
  195219. }
  195220. }
  195221. if (fontDirs.size() == 0)
  195222. fontDirs.add ("/usr/X11R6/lib/X11/fonts");
  195223. for (int i = 0; i < fontDirs.size(); ++i)
  195224. enumerateFaces (fontDirs[i]);
  195225. }
  195226. ~FreeTypeInterface() throw()
  195227. {
  195228. if (lastFace != 0)
  195229. FT_Done_Face (lastFace);
  195230. if (ftLib != 0)
  195231. FT_Done_FreeType (ftLib);
  195232. clearSingletonInstance();
  195233. }
  195234. FreeTypeFontFace* findOrCreate (const String& familyName,
  195235. const bool create = false) throw()
  195236. {
  195237. for (int i = 0; i < faces.size(); i++)
  195238. if (faces[i]->getFamilyName() == familyName)
  195239. return faces[i];
  195240. if (! create)
  195241. return NULL;
  195242. FreeTypeFontFace* newFace = new FreeTypeFontFace (familyName);
  195243. faces.add (newFace);
  195244. return newFace;
  195245. }
  195246. // Enumerate all font faces available in a given directory
  195247. void enumerateFaces (const String& path) throw()
  195248. {
  195249. File dirPath (path);
  195250. if (path.isEmpty() || ! dirPath.isDirectory())
  195251. return;
  195252. DirectoryIterator di (dirPath, true);
  195253. while (di.next())
  195254. {
  195255. File possible (di.getFile());
  195256. if (possible.hasFileExtension (T("ttf"))
  195257. || possible.hasFileExtension (T("pfb"))
  195258. || possible.hasFileExtension (T("pcf")))
  195259. {
  195260. FT_Face face;
  195261. int faceIndex = 0;
  195262. int numFaces = 0;
  195263. do
  195264. {
  195265. if (FT_New_Face (ftLib,
  195266. possible.getFullPathName(),
  195267. faceIndex,
  195268. &face) == 0)
  195269. {
  195270. if (faceIndex == 0)
  195271. numFaces = face->num_faces;
  195272. if ((face->face_flags & FT_FACE_FLAG_SCALABLE) != 0)
  195273. {
  195274. FreeTypeFontFace* const newFace = findOrCreate (face->family_name, true);
  195275. int style = (int) FreeTypeFontFace::Plain;
  195276. if ((face->style_flags & FT_STYLE_FLAG_BOLD) != 0)
  195277. style |= (int) FreeTypeFontFace::Bold;
  195278. if ((face->style_flags & FT_STYLE_FLAG_ITALIC) != 0)
  195279. style |= (int) FreeTypeFontFace::Italic;
  195280. newFace->setFileName (possible.getFullPathName(), faceIndex, (FreeTypeFontFace::FontStyle) style);
  195281. newFace->setMonospaced ((face->face_flags & FT_FACE_FLAG_FIXED_WIDTH) != 0);
  195282. // Surely there must be a better way to do this?
  195283. const String name (face->family_name);
  195284. newFace->setSerif (! (name.containsIgnoreCase (T("Sans"))
  195285. || name.containsIgnoreCase (T("Verdana"))
  195286. || name.containsIgnoreCase (T("Arial"))));
  195287. }
  195288. FT_Done_Face (face);
  195289. }
  195290. ++faceIndex;
  195291. }
  195292. while (faceIndex < numFaces);
  195293. }
  195294. }
  195295. }
  195296. // Create a FreeType face object for a given font
  195297. FT_Face createFT_Face (const String& fontName,
  195298. const bool bold,
  195299. const bool italic) throw()
  195300. {
  195301. FT_Face face = 0;
  195302. if (fontName == lastFontName && bold == lastBold && italic == lastItalic)
  195303. {
  195304. face = lastFace;
  195305. }
  195306. else
  195307. {
  195308. if (lastFace != 0)
  195309. {
  195310. FT_Done_Face (lastFace);
  195311. lastFace = 0;
  195312. }
  195313. lastFontName = fontName;
  195314. lastBold = bold;
  195315. lastItalic = italic;
  195316. FreeTypeFontFace* const ftFace = findOrCreate (fontName);
  195317. if (ftFace != 0)
  195318. {
  195319. int style = (int) FreeTypeFontFace::Plain;
  195320. if (bold)
  195321. style |= (int) FreeTypeFontFace::Bold;
  195322. if (italic)
  195323. style |= (int) FreeTypeFontFace::Italic;
  195324. int faceIndex;
  195325. String fileName (ftFace->getFileName (style, faceIndex));
  195326. if (fileName.isEmpty())
  195327. {
  195328. style ^= (int) FreeTypeFontFace::Bold;
  195329. fileName = ftFace->getFileName (style, faceIndex);
  195330. if (fileName.isEmpty())
  195331. {
  195332. style ^= (int) FreeTypeFontFace::Bold;
  195333. style ^= (int) FreeTypeFontFace::Italic;
  195334. fileName = ftFace->getFileName (style, faceIndex);
  195335. if (! fileName.length())
  195336. {
  195337. style ^= (int) FreeTypeFontFace::Bold;
  195338. fileName = ftFace->getFileName (style, faceIndex);
  195339. }
  195340. }
  195341. }
  195342. if (! FT_New_Face (ftLib, (const char*) fileName, faceIndex, &lastFace))
  195343. {
  195344. face = lastFace;
  195345. // If there isn't a unicode charmap then select the first one.
  195346. if (FT_Select_Charmap (face, ft_encoding_unicode))
  195347. FT_Set_Charmap (face, face->charmaps[0]);
  195348. }
  195349. }
  195350. }
  195351. return face;
  195352. }
  195353. bool addGlyph (FT_Face face, CustomTypeface& dest, uint32 character) throw()
  195354. {
  195355. const unsigned int glyphIndex = FT_Get_Char_Index (face, character);
  195356. const float height = (float) (face->ascender - face->descender);
  195357. const float scaleX = 1.0f / height;
  195358. const float scaleY = -1.0f / height;
  195359. Path destShape;
  195360. #define CONVERTX(val) (scaleX * (val).x)
  195361. #define CONVERTY(val) (scaleY * (val).y)
  195362. if (FT_Load_Glyph (face, glyphIndex, FT_LOAD_NO_SCALE | FT_LOAD_NO_BITMAP | FT_LOAD_IGNORE_TRANSFORM) != 0
  195363. || face->glyph->format != ft_glyph_format_outline)
  195364. {
  195365. return false;
  195366. }
  195367. const FT_Outline* const outline = &face->glyph->outline;
  195368. const short* const contours = outline->contours;
  195369. const char* const tags = outline->tags;
  195370. FT_Vector* const points = outline->points;
  195371. for (int c = 0; c < outline->n_contours; c++)
  195372. {
  195373. const int startPoint = (c == 0) ? 0 : contours [c - 1] + 1;
  195374. const int endPoint = contours[c];
  195375. for (int p = startPoint; p <= endPoint; p++)
  195376. {
  195377. const float x = CONVERTX (points[p]);
  195378. const float y = CONVERTY (points[p]);
  195379. if (p == startPoint)
  195380. {
  195381. if (FT_CURVE_TAG (tags[p]) == FT_Curve_Tag_Conic)
  195382. {
  195383. float x2 = CONVERTX (points [endPoint]);
  195384. float y2 = CONVERTY (points [endPoint]);
  195385. if (FT_CURVE_TAG (tags[endPoint]) != FT_Curve_Tag_On)
  195386. {
  195387. x2 = (x + x2) * 0.5f;
  195388. y2 = (y + y2) * 0.5f;
  195389. }
  195390. destShape.startNewSubPath (x2, y2);
  195391. }
  195392. else
  195393. {
  195394. destShape.startNewSubPath (x, y);
  195395. }
  195396. }
  195397. if (FT_CURVE_TAG (tags[p]) == FT_Curve_Tag_On)
  195398. {
  195399. if (p != startPoint)
  195400. destShape.lineTo (x, y);
  195401. }
  195402. else if (FT_CURVE_TAG (tags[p]) == FT_Curve_Tag_Conic)
  195403. {
  195404. const int nextIndex = (p == endPoint) ? startPoint : p + 1;
  195405. float x2 = CONVERTX (points [nextIndex]);
  195406. float y2 = CONVERTY (points [nextIndex]);
  195407. if (FT_CURVE_TAG (tags [nextIndex]) == FT_Curve_Tag_Conic)
  195408. {
  195409. x2 = (x + x2) * 0.5f;
  195410. y2 = (y + y2) * 0.5f;
  195411. }
  195412. else
  195413. {
  195414. ++p;
  195415. }
  195416. destShape.quadraticTo (x, y, x2, y2);
  195417. }
  195418. else if (FT_CURVE_TAG (tags[p]) == FT_Curve_Tag_Cubic)
  195419. {
  195420. if (p >= endPoint)
  195421. return false;
  195422. const int next1 = p + 1;
  195423. const int next2 = (p == (endPoint - 1)) ? startPoint : p + 2;
  195424. const float x2 = CONVERTX (points [next1]);
  195425. const float y2 = CONVERTY (points [next1]);
  195426. const float x3 = CONVERTX (points [next2]);
  195427. const float y3 = CONVERTY (points [next2]);
  195428. if (FT_CURVE_TAG (tags[next1]) != FT_Curve_Tag_Cubic
  195429. || FT_CURVE_TAG (tags[next2]) != FT_Curve_Tag_On)
  195430. return false;
  195431. destShape.cubicTo (x, y, x2, y2, x3, y3);
  195432. p += 2;
  195433. }
  195434. }
  195435. destShape.closeSubPath();
  195436. }
  195437. dest.addGlyph (character, destShape, face->glyph->metrics.horiAdvance / height);
  195438. if ((face->face_flags & FT_FACE_FLAG_KERNING) != 0)
  195439. addKerning (face, dest, character, glyphIndex);
  195440. return true;
  195441. }
  195442. void addKerning (FT_Face face, CustomTypeface& dest, const uint32 character, const uint32 glyphIndex) throw()
  195443. {
  195444. const float height = (float) (face->ascender - face->descender);
  195445. uint32 rightGlyphIndex;
  195446. uint32 rightCharCode = FT_Get_First_Char (face, &rightGlyphIndex);
  195447. while (rightGlyphIndex != 0)
  195448. {
  195449. FT_Vector kerning;
  195450. if (FT_Get_Kerning (face, glyphIndex, rightGlyphIndex, ft_kerning_unscaled, &kerning) == 0)
  195451. {
  195452. if (kerning.x != 0)
  195453. dest.addKerningPair (character, rightCharCode, kerning.x / height);
  195454. }
  195455. rightCharCode = FT_Get_Next_Char (face, rightCharCode, &rightGlyphIndex);
  195456. }
  195457. }
  195458. // Add a glyph to a font
  195459. bool addGlyphToFont (const uint32 character,
  195460. const tchar* fontName, bool bold, bool italic,
  195461. CustomTypeface& dest) throw()
  195462. {
  195463. FT_Face face = createFT_Face (fontName, bold, italic);
  195464. if (face != 0)
  195465. return addGlyph (face, dest, character);
  195466. return false;
  195467. }
  195468. void getFamilyNames (StringArray& familyNames) const throw()
  195469. {
  195470. for (int i = 0; i < faces.size(); i++)
  195471. familyNames.add (faces[i]->getFamilyName());
  195472. }
  195473. void getMonospacedNames (StringArray& monoSpaced) const throw()
  195474. {
  195475. for (int i = 0; i < faces.size(); i++)
  195476. if (faces[i]->getMonospaced())
  195477. monoSpaced.add (faces[i]->getFamilyName());
  195478. }
  195479. void getSerifNames (StringArray& serif) const throw()
  195480. {
  195481. for (int i = 0; i < faces.size(); i++)
  195482. if (faces[i]->getSerif())
  195483. serif.add (faces[i]->getFamilyName());
  195484. }
  195485. void getSansSerifNames (StringArray& sansSerif) const throw()
  195486. {
  195487. for (int i = 0; i < faces.size(); i++)
  195488. if (! faces[i]->getSerif())
  195489. sansSerif.add (faces[i]->getFamilyName());
  195490. }
  195491. juce_DeclareSingleton_SingleThreaded_Minimal (FreeTypeInterface)
  195492. private:
  195493. FT_Library ftLib;
  195494. FT_Face lastFace;
  195495. String lastFontName;
  195496. bool lastBold, lastItalic;
  195497. OwnedArray<FreeTypeFontFace> faces;
  195498. };
  195499. juce_ImplementSingleton_SingleThreaded (FreeTypeInterface)
  195500. class FreetypeTypeface : public CustomTypeface
  195501. {
  195502. public:
  195503. FreetypeTypeface (const Font& font)
  195504. {
  195505. FT_Face face = FreeTypeInterface::getInstance()
  195506. ->createFT_Face (font.getTypefaceName(), font.isBold(), font.isItalic());
  195507. if (face == 0)
  195508. {
  195509. #ifdef JUCE_DEBUG
  195510. String msg (T("Failed to create typeface: "));
  195511. msg << font.getTypefaceName() << " " << (font.isBold() ? 'B' : ' ') << (font.isItalic() ? 'I' : ' ');
  195512. DBG (msg);
  195513. #endif
  195514. }
  195515. else
  195516. {
  195517. setCharacteristics (font.getTypefaceName(),
  195518. face->ascender / (float) (face->ascender - face->descender),
  195519. font.isBold(), font.isItalic(),
  195520. L' ');
  195521. }
  195522. }
  195523. bool loadGlyphIfPossible (const juce_wchar character)
  195524. {
  195525. return FreeTypeInterface::getInstance()
  195526. ->addGlyphToFont (character, name, isBold, isItalic, *this);
  195527. }
  195528. };
  195529. const Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  195530. {
  195531. return new FreetypeTypeface (font);
  195532. }
  195533. const StringArray Font::findAllTypefaceNames() throw()
  195534. {
  195535. StringArray s;
  195536. FreeTypeInterface::getInstance()->getFamilyNames (s);
  195537. s.sort (true);
  195538. return s;
  195539. }
  195540. static const String pickBestFont (const StringArray& names,
  195541. const char* const choicesString)
  195542. {
  195543. StringArray choices;
  195544. choices.addTokens (String (choicesString), T(","), 0);
  195545. choices.trim();
  195546. choices.removeEmptyStrings();
  195547. int i, j;
  195548. for (j = 0; j < choices.size(); ++j)
  195549. if (names.contains (choices[j], true))
  195550. return choices[j];
  195551. for (j = 0; j < choices.size(); ++j)
  195552. for (i = 0; i < names.size(); i++)
  195553. if (names[i].startsWithIgnoreCase (choices[j]))
  195554. return names[i];
  195555. for (j = 0; j < choices.size(); ++j)
  195556. for (i = 0; i < names.size(); i++)
  195557. if (names[i].containsIgnoreCase (choices[j]))
  195558. return names[i];
  195559. return names[0];
  195560. }
  195561. static const String linux_getDefaultSansSerifFontName()
  195562. {
  195563. StringArray allFonts;
  195564. FreeTypeInterface::getInstance()->getSansSerifNames (allFonts);
  195565. return pickBestFont (allFonts, "Verdana, Bitstream Vera Sans, Luxi Sans, Sans");
  195566. }
  195567. static const String linux_getDefaultSerifFontName()
  195568. {
  195569. StringArray allFonts;
  195570. FreeTypeInterface::getInstance()->getSerifNames (allFonts);
  195571. return pickBestFont (allFonts, "Bitstream Vera Serif, Times, Nimbus Roman, Serif");
  195572. }
  195573. static const String linux_getDefaultMonospacedFontName()
  195574. {
  195575. StringArray allFonts;
  195576. FreeTypeInterface::getInstance()->getMonospacedNames (allFonts);
  195577. return pickBestFont (allFonts, "Bitstream Vera Sans Mono, Courier, Sans Mono, Mono");
  195578. }
  195579. void Font::getPlatformDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed) throw()
  195580. {
  195581. defaultSans = linux_getDefaultSansSerifFontName();
  195582. defaultSerif = linux_getDefaultSerifFontName();
  195583. defaultFixed = linux_getDefaultMonospacedFontName();
  195584. }
  195585. #endif
  195586. /*** End of inlined file: juce_linux_Fonts.cpp ***/
  195587. /*** Start of inlined file: juce_linux_Windowing.cpp ***/
  195588. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  195589. // compiled on its own).
  195590. #if JUCE_INCLUDED_FILE
  195591. #define TAKE_FOCUS 0
  195592. #define DELETE_WINDOW 1
  195593. #define SYSTEM_TRAY_REQUEST_DOCK 0
  195594. #define SYSTEM_TRAY_BEGIN_MESSAGE 1
  195595. #define SYSTEM_TRAY_CANCEL_MESSAGE 2
  195596. static const int repaintTimerPeriod = 1000 / 100; // 100 fps maximum
  195597. static Atom wm_ChangeState = None;
  195598. static Atom wm_State = None;
  195599. static Atom wm_Protocols = None;
  195600. static Atom wm_ProtocolList [2] = { None, None };
  195601. static Atom wm_ActiveWin = None;
  195602. #define ourDndVersion 3
  195603. static Atom XA_XdndAware = None;
  195604. static Atom XA_XdndEnter = None;
  195605. static Atom XA_XdndLeave = None;
  195606. static Atom XA_XdndPosition = None;
  195607. static Atom XA_XdndStatus = None;
  195608. static Atom XA_XdndDrop = None;
  195609. static Atom XA_XdndFinished = None;
  195610. static Atom XA_XdndSelection = None;
  195611. static Atom XA_XdndProxy = None;
  195612. static Atom XA_XdndTypeList = None;
  195613. static Atom XA_XdndActionList = None;
  195614. static Atom XA_XdndActionDescription = None;
  195615. static Atom XA_XdndActionCopy = None;
  195616. static Atom XA_XdndActionMove = None;
  195617. static Atom XA_XdndActionLink = None;
  195618. static Atom XA_XdndActionAsk = None;
  195619. static Atom XA_XdndActionPrivate = None;
  195620. static Atom XA_JXSelectionWindowProperty = None;
  195621. static Atom XA_MimeTextPlain = None;
  195622. static Atom XA_MimeTextUriList = None;
  195623. static Atom XA_MimeRootDrop = None;
  195624. static XErrorHandler oldHandler = 0;
  195625. static int trappedErrorCode = 0;
  195626. extern "C" int errorTrapHandler (Display* dpy, XErrorEvent* err)
  195627. {
  195628. trappedErrorCode = err->error_code;
  195629. return 0;
  195630. }
  195631. static void trapErrors()
  195632. {
  195633. trappedErrorCode = 0;
  195634. oldHandler = XSetErrorHandler (errorTrapHandler);
  195635. }
  195636. static bool untrapErrors()
  195637. {
  195638. XSetErrorHandler (oldHandler);
  195639. return (trappedErrorCode == 0);
  195640. }
  195641. static bool isActiveApplication = false;
  195642. bool Process::isForegroundProcess()
  195643. {
  195644. return isActiveApplication;
  195645. }
  195646. // These are defined in juce_linux_Messaging.cpp
  195647. extern Display* display;
  195648. extern XContext improbableNumber;
  195649. static const int eventMask = NoEventMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask
  195650. | EnterWindowMask | LeaveWindowMask | PointerMotionMask | KeymapStateMask
  195651. | ExposureMask | StructureNotifyMask | FocusChangeMask;
  195652. static int pointerMap[5];
  195653. static int lastMousePosX = 0, lastMousePosY = 0;
  195654. enum MouseButtons
  195655. {
  195656. NoButton = 0,
  195657. LeftButton = 1,
  195658. MiddleButton = 2,
  195659. RightButton = 3,
  195660. WheelUp = 4,
  195661. WheelDown = 5
  195662. };
  195663. static void getMousePos (int& x, int& y, int& mouseMods) throw()
  195664. {
  195665. Window root, child;
  195666. int winx, winy;
  195667. unsigned int mask;
  195668. mouseMods = 0;
  195669. ScopedXLock xlock;
  195670. if (XQueryPointer (display,
  195671. RootWindow (display, DefaultScreen (display)),
  195672. &root, &child,
  195673. &x, &y, &winx, &winy, &mask) == False)
  195674. {
  195675. // Pointer not on the default screen
  195676. x = y = -1;
  195677. }
  195678. else
  195679. {
  195680. if ((mask & Button1Mask) != 0)
  195681. mouseMods |= ModifierKeys::leftButtonModifier;
  195682. if ((mask & Button2Mask) != 0)
  195683. mouseMods |= ModifierKeys::middleButtonModifier;
  195684. if ((mask & Button3Mask) != 0)
  195685. mouseMods |= ModifierKeys::rightButtonModifier;
  195686. }
  195687. }
  195688. static int AltMask = 0;
  195689. static int NumLockMask = 0;
  195690. static bool numLock = 0;
  195691. static bool capsLock = 0;
  195692. static char keyStates [32];
  195693. static void updateKeyStates (const int keycode, const bool press) throw()
  195694. {
  195695. const int keybyte = keycode >> 3;
  195696. const int keybit = (1 << (keycode & 7));
  195697. if (press)
  195698. keyStates [keybyte] |= keybit;
  195699. else
  195700. keyStates [keybyte] &= ~keybit;
  195701. }
  195702. static bool keyDown (const int keycode) throw()
  195703. {
  195704. const int keybyte = keycode >> 3;
  195705. const int keybit = (1 << (keycode & 7));
  195706. return (keyStates [keybyte] & keybit) != 0;
  195707. }
  195708. static const int extendedKeyModifier = 0x10000000;
  195709. bool KeyPress::isKeyCurrentlyDown (const int keyCode) throw()
  195710. {
  195711. int keysym;
  195712. if (keyCode & extendedKeyModifier)
  195713. {
  195714. keysym = 0xff00 | (keyCode & 0xff);
  195715. }
  195716. else
  195717. {
  195718. keysym = keyCode;
  195719. if (keysym == (XK_Tab & 0xff)
  195720. || keysym == (XK_Return & 0xff)
  195721. || keysym == (XK_Escape & 0xff)
  195722. || keysym == (XK_BackSpace & 0xff))
  195723. {
  195724. keysym |= 0xff00;
  195725. }
  195726. }
  195727. ScopedXLock xlock;
  195728. return keyDown (XKeysymToKeycode (display, keysym));
  195729. }
  195730. // Alt and Num lock are not defined by standard X
  195731. // modifier constants: check what they're mapped to
  195732. static void getModifierMapping() throw()
  195733. {
  195734. ScopedXLock xlock;
  195735. const int altLeftCode = XKeysymToKeycode (display, XK_Alt_L);
  195736. const int numLockCode = XKeysymToKeycode (display, XK_Num_Lock);
  195737. AltMask = 0;
  195738. NumLockMask = 0;
  195739. XModifierKeymap* mapping = XGetModifierMapping (display);
  195740. if (mapping)
  195741. {
  195742. for (int i = 0; i < 8; i++)
  195743. {
  195744. if (mapping->modifiermap [i << 1] == altLeftCode)
  195745. AltMask = 1 << i;
  195746. else if (mapping->modifiermap [i << 1] == numLockCode)
  195747. NumLockMask = 1 << i;
  195748. }
  195749. XFreeModifiermap (mapping);
  195750. }
  195751. }
  195752. static int currentModifiers = 0;
  195753. void ModifierKeys::updateCurrentModifiers() throw()
  195754. {
  195755. currentModifierFlags = currentModifiers;
  195756. }
  195757. const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw()
  195758. {
  195759. int x, y, mouseMods;
  195760. getMousePos (x, y, mouseMods);
  195761. currentModifiers &= ~ModifierKeys::allMouseButtonModifiers;
  195762. currentModifiers |= mouseMods;
  195763. return ModifierKeys (currentModifiers);
  195764. }
  195765. static void updateKeyModifiers (const int status) throw()
  195766. {
  195767. currentModifiers &= ~(ModifierKeys::shiftModifier
  195768. | ModifierKeys::ctrlModifier
  195769. | ModifierKeys::altModifier);
  195770. if (status & ShiftMask)
  195771. currentModifiers |= ModifierKeys::shiftModifier;
  195772. if (status & ControlMask)
  195773. currentModifiers |= ModifierKeys::ctrlModifier;
  195774. if (status & AltMask)
  195775. currentModifiers |= ModifierKeys::altModifier;
  195776. numLock = ((status & NumLockMask) != 0);
  195777. capsLock = ((status & LockMask) != 0);
  195778. }
  195779. static bool updateKeyModifiersFromSym (KeySym sym, const bool press) throw()
  195780. {
  195781. int modifier = 0;
  195782. bool isModifier = true;
  195783. switch (sym)
  195784. {
  195785. case XK_Shift_L:
  195786. case XK_Shift_R:
  195787. modifier = ModifierKeys::shiftModifier;
  195788. break;
  195789. case XK_Control_L:
  195790. case XK_Control_R:
  195791. modifier = ModifierKeys::ctrlModifier;
  195792. break;
  195793. case XK_Alt_L:
  195794. case XK_Alt_R:
  195795. modifier = ModifierKeys::altModifier;
  195796. break;
  195797. case XK_Num_Lock:
  195798. if (press)
  195799. numLock = ! numLock;
  195800. break;
  195801. case XK_Caps_Lock:
  195802. if (press)
  195803. capsLock = ! capsLock;
  195804. break;
  195805. case XK_Scroll_Lock:
  195806. break;
  195807. default:
  195808. isModifier = false;
  195809. break;
  195810. }
  195811. if (modifier != 0)
  195812. {
  195813. if (press)
  195814. currentModifiers |= modifier;
  195815. else
  195816. currentModifiers &= ~modifier;
  195817. }
  195818. return isModifier;
  195819. }
  195820. #if JUCE_USE_XSHM
  195821. static bool isShmAvailable() throw()
  195822. {
  195823. ScopedXLock xlock;
  195824. static bool isChecked = false;
  195825. static bool isAvailable = false;
  195826. if (! isChecked)
  195827. {
  195828. isChecked = true;
  195829. int major, minor;
  195830. Bool pixmaps;
  195831. if (XShmQueryVersion (display, &major, &minor, &pixmaps))
  195832. {
  195833. trapErrors();
  195834. XShmSegmentInfo segmentInfo;
  195835. zerostruct (segmentInfo);
  195836. XImage* xImage = XShmCreateImage (display, DefaultVisual (display, DefaultScreen (display)),
  195837. 24, ZPixmap, 0, &segmentInfo, 50, 50);
  195838. if ((segmentInfo.shmid = shmget (IPC_PRIVATE,
  195839. xImage->bytes_per_line * xImage->height,
  195840. IPC_CREAT | 0777)) >= 0)
  195841. {
  195842. segmentInfo.shmaddr = (char*) shmat (segmentInfo.shmid, 0, 0);
  195843. if (segmentInfo.shmaddr != (void*) -1)
  195844. {
  195845. segmentInfo.readOnly = False;
  195846. xImage->data = segmentInfo.shmaddr;
  195847. XSync (display, False);
  195848. if (XShmAttach (display, &segmentInfo) != 0)
  195849. {
  195850. XSync (display, False);
  195851. XShmDetach (display, &segmentInfo);
  195852. isAvailable = true;
  195853. }
  195854. }
  195855. XFlush (display);
  195856. XDestroyImage (xImage);
  195857. shmdt (segmentInfo.shmaddr);
  195858. }
  195859. shmctl (segmentInfo.shmid, IPC_RMID, 0);
  195860. isAvailable &= untrapErrors();
  195861. }
  195862. }
  195863. return isAvailable;
  195864. }
  195865. #endif
  195866. static Pixmap juce_createColourPixmapFromImage (Display* display, const Image& image)
  195867. {
  195868. ScopedXLock xlock;
  195869. const int width = image.getWidth();
  195870. const int height = image.getHeight();
  195871. HeapBlock <uint32> colour (width * height);
  195872. int index = 0;
  195873. for (int y = 0; y < height; ++y)
  195874. for (int x = 0; x < width; ++x)
  195875. colour[index++] = image.getPixelAt (x, y).getARGB();
  195876. XImage* ximage = XCreateImage (display, CopyFromParent, 24, ZPixmap,
  195877. 0, (char*) colour, width, height, 32, 0);
  195878. Pixmap pixmap = XCreatePixmap (display, DefaultRootWindow (display),
  195879. width, height, 24);
  195880. GC gc = XCreateGC (display, pixmap, 0, 0);
  195881. XPutImage (display, pixmap, gc, ximage, 0, 0, 0, 0, width, height);
  195882. XFreeGC (display, gc);
  195883. return pixmap;
  195884. }
  195885. static Pixmap juce_createMaskPixmapFromImage (Display* display, const Image& image)
  195886. {
  195887. ScopedXLock xlock;
  195888. const int width = image.getWidth();
  195889. const int height = image.getHeight();
  195890. const int stride = (width + 7) >> 3;
  195891. HeapBlock <uint8> mask;
  195892. mask.calloc (stride * height);
  195893. const bool msbfirst = (BitmapBitOrder (display) == MSBFirst);
  195894. for (int y = 0; y < height; ++y)
  195895. {
  195896. for (int x = 0; x < width; ++x)
  195897. {
  195898. const uint8 bit = (uint8) (1 << (msbfirst ? (7 - (x & 7)) : (x & 7)));
  195899. const int offset = y * stride + (x >> 3);
  195900. if (image.getPixelAt (x, y).getAlpha() >= 128)
  195901. mask[offset] |= bit;
  195902. }
  195903. }
  195904. return XCreatePixmapFromBitmapData (display, DefaultRootWindow (display),
  195905. (char*) mask, width, height, 1, 0, 1);
  195906. }
  195907. class XBitmapImage : public Image
  195908. {
  195909. public:
  195910. XBitmapImage (const PixelFormat format_, const int w, const int h,
  195911. const bool clearImage, const bool is16Bit_)
  195912. : Image (format_, w, h),
  195913. is16Bit (is16Bit_)
  195914. {
  195915. jassert (format_ == RGB || format_ == ARGB);
  195916. pixelStride = (format_ == RGB) ? 3 : 4;
  195917. lineStride = ((w * pixelStride + 3) & ~3);
  195918. ScopedXLock xlock;
  195919. Visual* const visual = DefaultVisual (display, DefaultScreen (display));
  195920. #if JUCE_USE_XSHM
  195921. usingXShm = false;
  195922. if ((! is16Bit) && isShmAvailable())
  195923. {
  195924. zerostruct (segmentInfo);
  195925. xImage = XShmCreateImage (display, visual, 24, ZPixmap, 0, &segmentInfo, w, h);
  195926. if (xImage != 0)
  195927. {
  195928. if ((segmentInfo.shmid = shmget (IPC_PRIVATE,
  195929. xImage->bytes_per_line * xImage->height,
  195930. IPC_CREAT | 0777)) >= 0)
  195931. {
  195932. segmentInfo.shmaddr = (char*) shmat (segmentInfo.shmid, 0, 0);
  195933. if (segmentInfo.shmaddr != (void*) -1)
  195934. {
  195935. segmentInfo.readOnly = False;
  195936. xImage->data = segmentInfo.shmaddr;
  195937. imageData = (uint8*) segmentInfo.shmaddr;
  195938. XSync (display, False);
  195939. if (XShmAttach (display, &segmentInfo) != 0)
  195940. {
  195941. XSync (display, False);
  195942. usingXShm = true;
  195943. }
  195944. else
  195945. {
  195946. jassertfalse
  195947. }
  195948. }
  195949. else
  195950. {
  195951. shmctl (segmentInfo.shmid, IPC_RMID, 0);
  195952. }
  195953. }
  195954. }
  195955. }
  195956. if (! usingXShm)
  195957. #endif
  195958. {
  195959. imageDataAllocated.malloc (lineStride * h);
  195960. imageData = imageDataAllocated;
  195961. if (format_ == ARGB && clearImage)
  195962. zeromem (imageData, h * lineStride);
  195963. xImage = (XImage*) juce_calloc (sizeof (XImage));
  195964. xImage->width = w;
  195965. xImage->height = h;
  195966. xImage->xoffset = 0;
  195967. xImage->format = ZPixmap;
  195968. xImage->data = (char*) imageData;
  195969. xImage->byte_order = ImageByteOrder (display);
  195970. xImage->bitmap_unit = BitmapUnit (display);
  195971. xImage->bitmap_bit_order = BitmapBitOrder (display);
  195972. xImage->bitmap_pad = 32;
  195973. xImage->depth = pixelStride * 8;
  195974. xImage->bytes_per_line = lineStride;
  195975. xImage->bits_per_pixel = pixelStride * 8;
  195976. xImage->red_mask = 0x00FF0000;
  195977. xImage->green_mask = 0x0000FF00;
  195978. xImage->blue_mask = 0x000000FF;
  195979. if (is16Bit)
  195980. {
  195981. const int pixelStride = 2;
  195982. const int lineStride = ((w * pixelStride + 3) & ~3);
  195983. imageData16Bit.malloc (lineStride * h);
  195984. xImage->data = imageData16Bit;
  195985. xImage->bitmap_pad = 16;
  195986. xImage->depth = pixelStride * 8;
  195987. xImage->bytes_per_line = lineStride;
  195988. xImage->bits_per_pixel = pixelStride * 8;
  195989. xImage->red_mask = visual->red_mask;
  195990. xImage->green_mask = visual->green_mask;
  195991. xImage->blue_mask = visual->blue_mask;
  195992. }
  195993. if (! XInitImage (xImage))
  195994. {
  195995. jassertfalse
  195996. }
  195997. }
  195998. }
  195999. ~XBitmapImage()
  196000. {
  196001. ScopedXLock xlock;
  196002. #if JUCE_USE_XSHM
  196003. if (usingXShm)
  196004. {
  196005. XShmDetach (display, &segmentInfo);
  196006. XFlush (display);
  196007. XDestroyImage (xImage);
  196008. shmdt (segmentInfo.shmaddr);
  196009. shmctl (segmentInfo.shmid, IPC_RMID, 0);
  196010. }
  196011. else
  196012. #endif
  196013. {
  196014. xImage->data = 0;
  196015. XDestroyImage (xImage);
  196016. }
  196017. }
  196018. void blitToWindow (Window window, int dx, int dy, int dw, int dh, int sx, int sy)
  196019. {
  196020. ScopedXLock xlock;
  196021. static GC gc = 0;
  196022. if (gc == 0)
  196023. gc = DefaultGC (display, DefaultScreen (display));
  196024. if (is16Bit)
  196025. {
  196026. const uint32 rMask = xImage->red_mask;
  196027. const uint32 rShiftL = jmax (0, getShiftNeeded (rMask));
  196028. const uint32 rShiftR = jmax (0, -getShiftNeeded (rMask));
  196029. const uint32 gMask = xImage->green_mask;
  196030. const uint32 gShiftL = jmax (0, getShiftNeeded (gMask));
  196031. const uint32 gShiftR = jmax (0, -getShiftNeeded (gMask));
  196032. const uint32 bMask = xImage->blue_mask;
  196033. const uint32 bShiftL = jmax (0, getShiftNeeded (bMask));
  196034. const uint32 bShiftR = jmax (0, -getShiftNeeded (bMask));
  196035. const Image::BitmapData srcData (*this, 0, 0, getWidth(), getHeight());
  196036. for (int y = sy; y < sy + dh; ++y)
  196037. {
  196038. const uint8* p = srcData.getPixelPointer (sx, y);
  196039. for (int x = sx; x < sx + dw; ++x)
  196040. {
  196041. const PixelRGB* const pixel = (const PixelRGB*) p;
  196042. p += srcData.pixelStride;
  196043. XPutPixel (xImage, x, y,
  196044. (((((uint32) pixel->getRed()) << rShiftL) >> rShiftR) & rMask)
  196045. | (((((uint32) pixel->getGreen()) << gShiftL) >> gShiftR) & gMask)
  196046. | (((((uint32) pixel->getBlue()) << bShiftL) >> bShiftR) & bMask));
  196047. }
  196048. }
  196049. }
  196050. // blit results to screen.
  196051. #if JUCE_USE_XSHM
  196052. if (usingXShm)
  196053. XShmPutImage (display, (::Drawable) window, gc, xImage, sx, sy, dx, dy, dw, dh, True);
  196054. else
  196055. #endif
  196056. XPutImage (display, (::Drawable) window, gc, xImage, sx, sy, dx, dy, dw, dh);
  196057. }
  196058. juce_UseDebuggingNewOperator
  196059. private:
  196060. XImage* xImage;
  196061. const bool is16Bit;
  196062. HeapBlock <char> imageData16Bit;
  196063. #if JUCE_USE_XSHM
  196064. XShmSegmentInfo segmentInfo;
  196065. bool usingXShm;
  196066. #endif
  196067. static int getShiftNeeded (const uint32 mask) throw()
  196068. {
  196069. for (int i = 32; --i >= 0;)
  196070. if (((mask >> i) & 1) != 0)
  196071. return i - 7;
  196072. jassertfalse
  196073. return 0;
  196074. }
  196075. };
  196076. #define checkMessageManagerIsLocked jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  196077. class LinuxComponentPeer : public ComponentPeer
  196078. {
  196079. public:
  196080. LinuxComponentPeer (Component* const component, const int windowStyleFlags)
  196081. : ComponentPeer (component, windowStyleFlags),
  196082. windowH (0),
  196083. parentWindow (0),
  196084. wx (0),
  196085. wy (0),
  196086. ww (0),
  196087. wh (0),
  196088. taskbarImage (0),
  196089. fullScreen (false),
  196090. entered (false),
  196091. mapped (false)
  196092. {
  196093. // it's dangerous to create a window on a thread other than the message thread..
  196094. checkMessageManagerIsLocked
  196095. repainter = new LinuxRepaintManager (this);
  196096. createWindow();
  196097. setTitle (component->getName());
  196098. }
  196099. ~LinuxComponentPeer()
  196100. {
  196101. // it's dangerous to delete a window on a thread other than the message thread..
  196102. checkMessageManagerIsLocked
  196103. deleteTaskBarIcon();
  196104. deleteIconPixmaps();
  196105. destroyWindow();
  196106. windowH = 0;
  196107. }
  196108. void* getNativeHandle() const
  196109. {
  196110. return (void*) windowH;
  196111. }
  196112. static LinuxComponentPeer* getPeerFor (Window windowHandle) throw()
  196113. {
  196114. XPointer peer = 0;
  196115. ScopedXLock xlock;
  196116. if (! XFindContext (display, (XID) windowHandle, improbableNumber, &peer))
  196117. {
  196118. if (peer != 0 && ! ((LinuxComponentPeer*) peer)->isValidMessageListener())
  196119. peer = 0;
  196120. }
  196121. return (LinuxComponentPeer*) peer;
  196122. }
  196123. void setVisible (bool shouldBeVisible)
  196124. {
  196125. ScopedXLock xlock;
  196126. if (shouldBeVisible)
  196127. XMapWindow (display, windowH);
  196128. else
  196129. XUnmapWindow (display, windowH);
  196130. }
  196131. void setTitle (const String& title)
  196132. {
  196133. setWindowTitle (windowH, title);
  196134. }
  196135. void setPosition (int x, int y)
  196136. {
  196137. setBounds (x, y, ww, wh, false);
  196138. }
  196139. void setSize (int w, int h)
  196140. {
  196141. setBounds (wx, wy, w, h, false);
  196142. }
  196143. void setBounds (int x, int y, int w, int h, const bool isNowFullScreen)
  196144. {
  196145. fullScreen = isNowFullScreen;
  196146. if (windowH != 0)
  196147. {
  196148. const ComponentDeletionWatcher deletionChecker (component);
  196149. wx = x;
  196150. wy = y;
  196151. ww = jmax (1, w);
  196152. wh = jmax (1, h);
  196153. ScopedXLock xlock;
  196154. // Make sure the Window manager does what we want
  196155. XSizeHints* hints = XAllocSizeHints();
  196156. hints->flags = USSize | USPosition;
  196157. hints->width = ww;
  196158. hints->height = wh;
  196159. hints->x = wx;
  196160. hints->y = wy;
  196161. if ((getStyleFlags() & (windowHasTitleBar | windowIsResizable)) == windowHasTitleBar)
  196162. {
  196163. hints->min_width = hints->max_width = hints->width;
  196164. hints->min_height = hints->max_height = hints->height;
  196165. hints->flags |= PMinSize | PMaxSize;
  196166. }
  196167. XSetWMNormalHints (display, windowH, hints);
  196168. XFree (hints);
  196169. XMoveResizeWindow (display, windowH,
  196170. wx - windowBorder.getLeft(),
  196171. wy - windowBorder.getTop(), ww, wh);
  196172. if (! deletionChecker.hasBeenDeleted())
  196173. {
  196174. updateBorderSize();
  196175. handleMovedOrResized();
  196176. }
  196177. }
  196178. }
  196179. void getBounds (int& x, int& y, int& w, int& h) const
  196180. {
  196181. x = wx;
  196182. y = wy;
  196183. w = ww;
  196184. h = wh;
  196185. }
  196186. int getScreenX() const
  196187. {
  196188. return wx;
  196189. }
  196190. int getScreenY() const
  196191. {
  196192. return wy;
  196193. }
  196194. void relativePositionToGlobal (int& x, int& y)
  196195. {
  196196. x += wx;
  196197. y += wy;
  196198. }
  196199. void globalPositionToRelative (int& x, int& y)
  196200. {
  196201. x -= wx;
  196202. y -= wy;
  196203. }
  196204. void setMinimised (bool shouldBeMinimised)
  196205. {
  196206. if (shouldBeMinimised)
  196207. {
  196208. Window root = RootWindow (display, DefaultScreen (display));
  196209. XClientMessageEvent clientMsg;
  196210. clientMsg.display = display;
  196211. clientMsg.window = windowH;
  196212. clientMsg.type = ClientMessage;
  196213. clientMsg.format = 32;
  196214. clientMsg.message_type = wm_ChangeState;
  196215. clientMsg.data.l[0] = IconicState;
  196216. ScopedXLock xlock;
  196217. XSendEvent (display, root, false,
  196218. SubstructureRedirectMask | SubstructureNotifyMask,
  196219. (XEvent*) &clientMsg);
  196220. }
  196221. else
  196222. {
  196223. setVisible (true);
  196224. }
  196225. }
  196226. bool isMinimised() const
  196227. {
  196228. bool minimised = false;
  196229. unsigned char* stateProp;
  196230. unsigned long nitems, bytesLeft;
  196231. Atom actualType;
  196232. int actualFormat;
  196233. ScopedXLock xlock;
  196234. if (XGetWindowProperty (display, windowH, wm_State, 0, 64, False,
  196235. wm_State, &actualType, &actualFormat, &nitems, &bytesLeft,
  196236. &stateProp) == Success
  196237. && actualType == wm_State
  196238. && actualFormat == 32
  196239. && nitems > 0)
  196240. {
  196241. if (((unsigned long*) stateProp)[0] == IconicState)
  196242. minimised = true;
  196243. XFree (stateProp);
  196244. }
  196245. return minimised;
  196246. }
  196247. void setFullScreen (const bool shouldBeFullScreen)
  196248. {
  196249. Rectangle<int> r (lastNonFullscreenBounds); // (get a copy of this before de-minimising)
  196250. setMinimised (false);
  196251. if (fullScreen != shouldBeFullScreen)
  196252. {
  196253. if (shouldBeFullScreen)
  196254. r = Desktop::getInstance().getMainMonitorArea();
  196255. if (! r.isEmpty())
  196256. setBounds (r.getX(), r.getY(), r.getWidth(), r.getHeight(), shouldBeFullScreen);
  196257. getComponent()->repaint();
  196258. }
  196259. }
  196260. bool isFullScreen() const
  196261. {
  196262. return fullScreen;
  196263. }
  196264. bool isChildWindowOf (Window possibleParent) const
  196265. {
  196266. Window* windowList = 0;
  196267. uint32 windowListSize = 0;
  196268. Window parent, root;
  196269. ScopedXLock xlock;
  196270. if (XQueryTree (display, windowH, &root, &parent, &windowList, &windowListSize) != 0)
  196271. {
  196272. if (windowList != 0)
  196273. XFree (windowList);
  196274. return parent == possibleParent;
  196275. }
  196276. return false;
  196277. }
  196278. bool isFrontWindow() const
  196279. {
  196280. Window* windowList = 0;
  196281. uint32 windowListSize = 0;
  196282. bool result = false;
  196283. ScopedXLock xlock;
  196284. Window parent, root = RootWindow (display, DefaultScreen (display));
  196285. if (XQueryTree (display, root, &root, &parent, &windowList, &windowListSize) != 0)
  196286. {
  196287. for (int i = windowListSize; --i >= 0;)
  196288. {
  196289. LinuxComponentPeer* const peer = LinuxComponentPeer::getPeerFor (windowList[i]);
  196290. if (peer != 0)
  196291. {
  196292. result = (peer == this);
  196293. break;
  196294. }
  196295. }
  196296. }
  196297. if (windowList != 0)
  196298. XFree (windowList);
  196299. return result;
  196300. }
  196301. bool contains (int x, int y, bool trueIfInAChildWindow) const
  196302. {
  196303. jassert (x >= 0 && y >= 0 && x < ww && y < wh); // should only be called for points that are actually inside the bounds
  196304. if (((unsigned int) x) >= (unsigned int) ww
  196305. || ((unsigned int) y) >= (unsigned int) wh)
  196306. return false;
  196307. bool inFront = false;
  196308. for (int i = 0; i < Desktop::getInstance().getNumComponents(); ++i)
  196309. {
  196310. Component* const c = Desktop::getInstance().getComponent (i);
  196311. if (inFront)
  196312. {
  196313. if (c->contains (x + wx - c->getScreenX(),
  196314. y + wy - c->getScreenY()))
  196315. {
  196316. return false;
  196317. }
  196318. }
  196319. else if (c == getComponent())
  196320. {
  196321. inFront = true;
  196322. }
  196323. }
  196324. if (trueIfInAChildWindow)
  196325. return true;
  196326. ::Window root, child;
  196327. unsigned int bw, depth;
  196328. int wx, wy, w, h;
  196329. ScopedXLock xlock;
  196330. if (! XGetGeometry (display, (::Drawable) windowH, &root,
  196331. &wx, &wy, (unsigned int*) &w, (unsigned int*) &h,
  196332. &bw, &depth))
  196333. {
  196334. return false;
  196335. }
  196336. if (! XTranslateCoordinates (display, windowH, windowH, x, y, &wx, &wy, &child))
  196337. return false;
  196338. return child == None;
  196339. }
  196340. const BorderSize getFrameSize() const
  196341. {
  196342. return BorderSize();
  196343. }
  196344. bool setAlwaysOnTop (bool alwaysOnTop)
  196345. {
  196346. if (windowH != 0)
  196347. {
  196348. const bool wasVisible = component->isVisible();
  196349. if (wasVisible)
  196350. setVisible (false); // doesn't always seem to work if the window is visible when this is done..
  196351. {
  196352. ScopedXLock xlock;
  196353. XSetWindowAttributes swa;
  196354. swa.override_redirect = alwaysOnTop ? True : False;
  196355. XChangeWindowAttributes (display, windowH, CWOverrideRedirect, &swa);
  196356. }
  196357. if (wasVisible)
  196358. setVisible (true);
  196359. }
  196360. return true;
  196361. }
  196362. void toFront (bool makeActive)
  196363. {
  196364. if (makeActive)
  196365. {
  196366. setVisible (true);
  196367. grabFocus();
  196368. }
  196369. XEvent ev;
  196370. ev.xclient.type = ClientMessage;
  196371. ev.xclient.serial = 0;
  196372. ev.xclient.send_event = True;
  196373. ev.xclient.message_type = wm_ActiveWin;
  196374. ev.xclient.window = windowH;
  196375. ev.xclient.format = 32;
  196376. ev.xclient.data.l[0] = 2;
  196377. ev.xclient.data.l[1] = CurrentTime;
  196378. ev.xclient.data.l[2] = 0;
  196379. ev.xclient.data.l[3] = 0;
  196380. ev.xclient.data.l[4] = 0;
  196381. {
  196382. ScopedXLock xlock;
  196383. XSendEvent (display, RootWindow (display, DefaultScreen (display)),
  196384. False,
  196385. SubstructureRedirectMask | SubstructureNotifyMask,
  196386. &ev);
  196387. XWindowAttributes attr;
  196388. XGetWindowAttributes (display, windowH, &attr);
  196389. if (attr.override_redirect)
  196390. XRaiseWindow (display, windowH);
  196391. XSync (display, False);
  196392. }
  196393. handleBroughtToFront();
  196394. }
  196395. void toBehind (ComponentPeer* other)
  196396. {
  196397. LinuxComponentPeer* const otherPeer = dynamic_cast <LinuxComponentPeer*> (other);
  196398. jassert (otherPeer != 0); // wrong type of window?
  196399. if (otherPeer != 0)
  196400. {
  196401. setMinimised (false);
  196402. Window newStack[] = { otherPeer->windowH, windowH };
  196403. ScopedXLock xlock;
  196404. XRestackWindows (display, newStack, 2);
  196405. }
  196406. }
  196407. bool isFocused() const
  196408. {
  196409. int revert;
  196410. Window focusedWindow = 0;
  196411. ScopedXLock xlock;
  196412. XGetInputFocus (display, &focusedWindow, &revert);
  196413. return focusedWindow == windowH;
  196414. }
  196415. void grabFocus()
  196416. {
  196417. XWindowAttributes atts;
  196418. ScopedXLock xlock;
  196419. if (windowH != 0
  196420. && XGetWindowAttributes (display, windowH, &atts)
  196421. && atts.map_state == IsViewable
  196422. && ! isFocused())
  196423. {
  196424. XSetInputFocus (display, windowH, RevertToParent, CurrentTime);
  196425. isActiveApplication = true;
  196426. }
  196427. }
  196428. void textInputRequired (int /*x*/, int /*y*/)
  196429. {
  196430. }
  196431. void repaint (int x, int y, int w, int h)
  196432. {
  196433. if (Rectangle<int>::intersectRectangles (x, y, w, h,
  196434. 0, 0,
  196435. getComponent()->getWidth(),
  196436. getComponent()->getHeight()))
  196437. {
  196438. repainter->repaint (x, y, w, h);
  196439. }
  196440. }
  196441. void performAnyPendingRepaintsNow()
  196442. {
  196443. repainter->performAnyPendingRepaintsNow();
  196444. }
  196445. void setIcon (const Image& newIcon)
  196446. {
  196447. const int dataSize = newIcon.getWidth() * newIcon.getHeight() + 2;
  196448. HeapBlock <unsigned long> data (dataSize);
  196449. int index = 0;
  196450. data[index++] = newIcon.getWidth();
  196451. data[index++] = newIcon.getHeight();
  196452. for (int y = 0; y < newIcon.getHeight(); ++y)
  196453. for (int x = 0; x < newIcon.getWidth(); ++x)
  196454. data[index++] = newIcon.getPixelAt (x, y).getARGB();
  196455. ScopedXLock xlock;
  196456. XChangeProperty (display, windowH,
  196457. XInternAtom (display, "_NET_WM_ICON", False),
  196458. XA_CARDINAL, 32, PropModeReplace,
  196459. (unsigned char*) data, dataSize);
  196460. deleteIconPixmaps();
  196461. XWMHints* wmHints = XGetWMHints (display, windowH);
  196462. if (wmHints == 0)
  196463. wmHints = XAllocWMHints();
  196464. wmHints->flags |= IconPixmapHint | IconMaskHint;
  196465. wmHints->icon_pixmap = juce_createColourPixmapFromImage (display, newIcon);
  196466. wmHints->icon_mask = juce_createMaskPixmapFromImage (display, newIcon);
  196467. XSetWMHints (display, windowH, wmHints);
  196468. XFree (wmHints);
  196469. XSync (display, False);
  196470. }
  196471. void deleteIconPixmaps()
  196472. {
  196473. ScopedXLock xlock;
  196474. XWMHints* wmHints = XGetWMHints (display, windowH);
  196475. if (wmHints != 0)
  196476. {
  196477. if ((wmHints->flags & IconPixmapHint) != 0)
  196478. {
  196479. wmHints->flags &= ~IconPixmapHint;
  196480. XFreePixmap (display, wmHints->icon_pixmap);
  196481. }
  196482. if ((wmHints->flags & IconMaskHint) != 0)
  196483. {
  196484. wmHints->flags &= ~IconMaskHint;
  196485. XFreePixmap (display, wmHints->icon_mask);
  196486. }
  196487. XSetWMHints (display, windowH, wmHints);
  196488. XFree (wmHints);
  196489. }
  196490. }
  196491. void handleWindowMessage (XEvent* event)
  196492. {
  196493. switch (event->xany.type)
  196494. {
  196495. case 2: // 'KeyPress'
  196496. {
  196497. ScopedXLock xlock;
  196498. XKeyEvent* const keyEvent = (XKeyEvent*) &event->xkey;
  196499. updateKeyStates (keyEvent->keycode, true);
  196500. char utf8 [64];
  196501. zeromem (utf8, sizeof (utf8));
  196502. KeySym sym;
  196503. XLookupString (keyEvent, utf8, sizeof (utf8), &sym, 0);
  196504. const juce_wchar unicodeChar = *(const juce_wchar*) String::fromUTF8 ((const uint8*) utf8, sizeof (utf8) - 1);
  196505. int keyCode = (int) unicodeChar;
  196506. if (keyCode < 0x20)
  196507. keyCode = XKeycodeToKeysym (display, keyEvent->keycode,
  196508. (currentModifiers & ModifierKeys::shiftModifier) != 0 ? 1 : 0);
  196509. const int oldMods = currentModifiers;
  196510. bool keyPressed = false;
  196511. const bool keyDownChange = (sym != NoSymbol) && ! updateKeyModifiersFromSym (sym, true);
  196512. if ((sym & 0xff00) == 0xff00)
  196513. {
  196514. // Translate keypad
  196515. if (sym == XK_KP_Divide)
  196516. keyCode = XK_slash;
  196517. else if (sym == XK_KP_Multiply)
  196518. keyCode = XK_asterisk;
  196519. else if (sym == XK_KP_Subtract)
  196520. keyCode = XK_hyphen;
  196521. else if (sym == XK_KP_Add)
  196522. keyCode = XK_plus;
  196523. else if (sym == XK_KP_Enter)
  196524. keyCode = XK_Return;
  196525. else if (sym == XK_KP_Decimal)
  196526. keyCode = numLock ? XK_period : XK_Delete;
  196527. else if (sym == XK_KP_0)
  196528. keyCode = numLock ? XK_0 : XK_Insert;
  196529. else if (sym == XK_KP_1)
  196530. keyCode = numLock ? XK_1 : XK_End;
  196531. else if (sym == XK_KP_2)
  196532. keyCode = numLock ? XK_2 : XK_Down;
  196533. else if (sym == XK_KP_3)
  196534. keyCode = numLock ? XK_3 : XK_Page_Down;
  196535. else if (sym == XK_KP_4)
  196536. keyCode = numLock ? XK_4 : XK_Left;
  196537. else if (sym == XK_KP_5)
  196538. keyCode = XK_5;
  196539. else if (sym == XK_KP_6)
  196540. keyCode = numLock ? XK_6 : XK_Right;
  196541. else if (sym == XK_KP_7)
  196542. keyCode = numLock ? XK_7 : XK_Home;
  196543. else if (sym == XK_KP_8)
  196544. keyCode = numLock ? XK_8 : XK_Up;
  196545. else if (sym == XK_KP_9)
  196546. keyCode = numLock ? XK_9 : XK_Page_Up;
  196547. switch (sym)
  196548. {
  196549. case XK_Left:
  196550. case XK_Right:
  196551. case XK_Up:
  196552. case XK_Down:
  196553. case XK_Page_Up:
  196554. case XK_Page_Down:
  196555. case XK_End:
  196556. case XK_Home:
  196557. case XK_Delete:
  196558. case XK_Insert:
  196559. keyPressed = true;
  196560. keyCode = (sym & 0xff) | extendedKeyModifier;
  196561. break;
  196562. case XK_Tab:
  196563. case XK_Return:
  196564. case XK_Escape:
  196565. case XK_BackSpace:
  196566. keyPressed = true;
  196567. keyCode &= 0xff;
  196568. break;
  196569. default:
  196570. {
  196571. if (sym >= XK_F1 && sym <= XK_F16)
  196572. {
  196573. keyPressed = true;
  196574. keyCode = (sym & 0xff) | extendedKeyModifier;
  196575. }
  196576. break;
  196577. }
  196578. }
  196579. }
  196580. if (utf8[0] != 0 || ((sym & 0xff00) == 0 && sym >= 8))
  196581. keyPressed = true;
  196582. if (oldMods != currentModifiers)
  196583. handleModifierKeysChange();
  196584. if (keyDownChange)
  196585. handleKeyUpOrDown (true);
  196586. if (keyPressed)
  196587. handleKeyPress (keyCode, unicodeChar);
  196588. break;
  196589. }
  196590. case KeyRelease:
  196591. {
  196592. const XKeyEvent* const keyEvent = (const XKeyEvent*) &event->xkey;
  196593. updateKeyStates (keyEvent->keycode, false);
  196594. ScopedXLock xlock;
  196595. KeySym sym = XKeycodeToKeysym (display, keyEvent->keycode, 0);
  196596. const int oldMods = currentModifiers;
  196597. const bool keyDownChange = (sym != NoSymbol) && ! updateKeyModifiersFromSym (sym, false);
  196598. if (oldMods != currentModifiers)
  196599. handleModifierKeysChange();
  196600. if (keyDownChange)
  196601. handleKeyUpOrDown (false);
  196602. break;
  196603. }
  196604. case ButtonPress:
  196605. {
  196606. const XButtonPressedEvent* const buttonPressEvent = (const XButtonPressedEvent*) &event->xbutton;
  196607. bool buttonMsg = false;
  196608. bool wheelUpMsg = false;
  196609. bool wheelDownMsg = false;
  196610. const int map = pointerMap [buttonPressEvent->button - Button1];
  196611. if (map == LeftButton)
  196612. {
  196613. currentModifiers |= ModifierKeys::leftButtonModifier;
  196614. buttonMsg = true;
  196615. }
  196616. else if (map == RightButton)
  196617. {
  196618. currentModifiers |= ModifierKeys::rightButtonModifier;
  196619. buttonMsg = true;
  196620. }
  196621. else if (map == MiddleButton)
  196622. {
  196623. currentModifiers |= ModifierKeys::middleButtonModifier;
  196624. buttonMsg = true;
  196625. }
  196626. else if (map == WheelUp)
  196627. {
  196628. wheelUpMsg = true;
  196629. }
  196630. else if (map == WheelDown)
  196631. {
  196632. wheelDownMsg = true;
  196633. }
  196634. updateKeyModifiers (buttonPressEvent->state);
  196635. if (buttonMsg)
  196636. {
  196637. toFront (true);
  196638. handleMouseDown (buttonPressEvent->x, buttonPressEvent->y,
  196639. getEventTime (buttonPressEvent->time));
  196640. }
  196641. else if (wheelUpMsg || wheelDownMsg)
  196642. {
  196643. handleMouseWheel (0, wheelDownMsg ? -84 : 84,
  196644. getEventTime (buttonPressEvent->time));
  196645. }
  196646. lastMousePosX = lastMousePosY = 0x100000;
  196647. break;
  196648. }
  196649. case ButtonRelease:
  196650. {
  196651. const XButtonReleasedEvent* const buttonRelEvent = (const XButtonReleasedEvent*) &event->xbutton;
  196652. const int oldModifiers = currentModifiers;
  196653. const int map = pointerMap [buttonRelEvent->button - Button1];
  196654. if (map == LeftButton)
  196655. currentModifiers &= ~ModifierKeys::leftButtonModifier;
  196656. else if (map == RightButton)
  196657. currentModifiers &= ~ModifierKeys::rightButtonModifier;
  196658. else if (map == MiddleButton)
  196659. currentModifiers &= ~ModifierKeys::middleButtonModifier;
  196660. updateKeyModifiers (buttonRelEvent->state);
  196661. handleMouseUp (oldModifiers,
  196662. buttonRelEvent->x, buttonRelEvent->y,
  196663. getEventTime (buttonRelEvent->time));
  196664. lastMousePosX = lastMousePosY = 0x100000;
  196665. break;
  196666. }
  196667. case MotionNotify:
  196668. {
  196669. const XPointerMovedEvent* const movedEvent = (const XPointerMovedEvent*) &event->xmotion;
  196670. updateKeyModifiers (movedEvent->state);
  196671. int x, y, mouseMods;
  196672. getMousePos (x, y, mouseMods);
  196673. if (lastMousePosX != x || lastMousePosY != y)
  196674. {
  196675. lastMousePosX = x;
  196676. lastMousePosY = y;
  196677. if (parentWindow != 0 && (styleFlags & windowHasTitleBar) == 0)
  196678. {
  196679. Window wRoot = 0, wParent = 0;
  196680. Window* wChild = 0;
  196681. unsigned int numChildren;
  196682. {
  196683. ScopedXLock xlock;
  196684. XQueryTree (display, windowH, &wRoot, &wParent, &wChild, &numChildren);
  196685. }
  196686. if (wParent != 0
  196687. && wParent != windowH
  196688. && wParent != wRoot)
  196689. {
  196690. parentWindow = wParent;
  196691. updateBounds();
  196692. x -= getScreenX();
  196693. y -= getScreenY();
  196694. }
  196695. else
  196696. {
  196697. parentWindow = 0;
  196698. x -= getScreenX();
  196699. y -= getScreenY();
  196700. }
  196701. }
  196702. else
  196703. {
  196704. x -= getScreenX();
  196705. y -= getScreenY();
  196706. }
  196707. if ((currentModifiers & ModifierKeys::allMouseButtonModifiers) == 0)
  196708. handleMouseMove (x, y, getEventTime (movedEvent->time));
  196709. else
  196710. handleMouseDrag (x, y, getEventTime (movedEvent->time));
  196711. }
  196712. break;
  196713. }
  196714. case EnterNotify:
  196715. {
  196716. lastMousePosX = lastMousePosY = 0x100000;
  196717. const XEnterWindowEvent* const enterEvent = (const XEnterWindowEvent*) &event->xcrossing;
  196718. if ((currentModifiers & ModifierKeys::allMouseButtonModifiers) == 0
  196719. && ! entered)
  196720. {
  196721. updateKeyModifiers (enterEvent->state);
  196722. handleMouseEnter (enterEvent->x, enterEvent->y, getEventTime (enterEvent->time));
  196723. entered = true;
  196724. }
  196725. break;
  196726. }
  196727. case LeaveNotify:
  196728. {
  196729. const XLeaveWindowEvent* const leaveEvent = (const XLeaveWindowEvent*) &event->xcrossing;
  196730. // Suppress the normal leave if we've got a pointer grab, or if
  196731. // it's a bogus one caused by clicking a mouse button when running
  196732. // in a Window manager
  196733. if (((currentModifiers & ModifierKeys::allMouseButtonModifiers) == 0
  196734. && leaveEvent->mode == NotifyNormal)
  196735. || leaveEvent->mode == NotifyUngrab)
  196736. {
  196737. updateKeyModifiers (leaveEvent->state);
  196738. handleMouseExit (leaveEvent->x, leaveEvent->y, getEventTime (leaveEvent->time));
  196739. entered = false;
  196740. }
  196741. break;
  196742. }
  196743. case FocusIn:
  196744. {
  196745. isActiveApplication = true;
  196746. if (isFocused())
  196747. handleFocusGain();
  196748. break;
  196749. }
  196750. case FocusOut:
  196751. {
  196752. isActiveApplication = false;
  196753. if (! isFocused())
  196754. handleFocusLoss();
  196755. break;
  196756. }
  196757. case Expose:
  196758. {
  196759. // Batch together all pending expose events
  196760. XExposeEvent* exposeEvent = (XExposeEvent*) &event->xexpose;
  196761. XEvent nextEvent;
  196762. ScopedXLock xlock;
  196763. if (exposeEvent->window != windowH)
  196764. {
  196765. Window child;
  196766. XTranslateCoordinates (display, exposeEvent->window, windowH,
  196767. exposeEvent->x, exposeEvent->y, &exposeEvent->x, &exposeEvent->y,
  196768. &child);
  196769. }
  196770. repaint (exposeEvent->x, exposeEvent->y,
  196771. exposeEvent->width, exposeEvent->height);
  196772. while (XEventsQueued (display, QueuedAfterFlush) > 0)
  196773. {
  196774. XPeekEvent (display, (XEvent*) &nextEvent);
  196775. if (nextEvent.type != Expose || nextEvent.xany.window != event->xany.window)
  196776. break;
  196777. XNextEvent (display, (XEvent*) &nextEvent);
  196778. XExposeEvent* nextExposeEvent = (XExposeEvent*) &nextEvent.xexpose;
  196779. repaint (nextExposeEvent->x, nextExposeEvent->y,
  196780. nextExposeEvent->width, nextExposeEvent->height);
  196781. }
  196782. break;
  196783. }
  196784. case CirculateNotify:
  196785. case CreateNotify:
  196786. case DestroyNotify:
  196787. // Think we can ignore these
  196788. break;
  196789. case ConfigureNotify:
  196790. {
  196791. updateBounds();
  196792. updateBorderSize();
  196793. handleMovedOrResized();
  196794. // if the native title bar is dragged, need to tell any active menus, etc.
  196795. if ((styleFlags & windowHasTitleBar) != 0
  196796. && component->isCurrentlyBlockedByAnotherModalComponent())
  196797. {
  196798. Component* const currentModalComp = Component::getCurrentlyModalComponent();
  196799. if (currentModalComp != 0)
  196800. currentModalComp->inputAttemptWhenModal();
  196801. }
  196802. XConfigureEvent* const confEvent = (XConfigureEvent*) &event->xconfigure;
  196803. if (confEvent->window == windowH
  196804. && confEvent->above != 0
  196805. && isFrontWindow())
  196806. {
  196807. handleBroughtToFront();
  196808. }
  196809. break;
  196810. }
  196811. case ReparentNotify:
  196812. case GravityNotify:
  196813. {
  196814. parentWindow = 0;
  196815. Window wRoot = 0;
  196816. Window* wChild = 0;
  196817. unsigned int numChildren;
  196818. {
  196819. ScopedXLock xlock;
  196820. XQueryTree (display, windowH, &wRoot, &parentWindow, &wChild, &numChildren);
  196821. }
  196822. if (parentWindow == windowH || parentWindow == wRoot)
  196823. parentWindow = 0;
  196824. updateBounds();
  196825. updateBorderSize();
  196826. handleMovedOrResized();
  196827. break;
  196828. }
  196829. case MapNotify:
  196830. mapped = true;
  196831. handleBroughtToFront();
  196832. break;
  196833. case UnmapNotify:
  196834. mapped = false;
  196835. break;
  196836. case MappingNotify:
  196837. {
  196838. XMappingEvent* mappingEvent = (XMappingEvent*) &event->xmapping;
  196839. if (mappingEvent->request != MappingPointer)
  196840. {
  196841. // Deal with modifier/keyboard mapping
  196842. ScopedXLock xlock;
  196843. XRefreshKeyboardMapping (mappingEvent);
  196844. getModifierMapping();
  196845. }
  196846. break;
  196847. }
  196848. case ClientMessage:
  196849. {
  196850. const XClientMessageEvent* const clientMsg = (const XClientMessageEvent*) &event->xclient;
  196851. if (clientMsg->message_type == wm_Protocols && clientMsg->format == 32)
  196852. {
  196853. const Atom atom = (Atom) clientMsg->data.l[0];
  196854. if (atom == wm_ProtocolList [TAKE_FOCUS])
  196855. {
  196856. XWindowAttributes atts;
  196857. ScopedXLock xlock;
  196858. if (clientMsg->window != 0
  196859. && XGetWindowAttributes (display, clientMsg->window, &atts))
  196860. {
  196861. if (atts.map_state == IsViewable)
  196862. XSetInputFocus (display, clientMsg->window, RevertToParent, clientMsg->data.l[1]);
  196863. }
  196864. }
  196865. else if (atom == wm_ProtocolList [DELETE_WINDOW])
  196866. {
  196867. handleUserClosingWindow();
  196868. }
  196869. }
  196870. else if (clientMsg->message_type == XA_XdndEnter)
  196871. {
  196872. handleDragAndDropEnter (clientMsg);
  196873. }
  196874. else if (clientMsg->message_type == XA_XdndLeave)
  196875. {
  196876. resetDragAndDrop();
  196877. }
  196878. else if (clientMsg->message_type == XA_XdndPosition)
  196879. {
  196880. handleDragAndDropPosition (clientMsg);
  196881. }
  196882. else if (clientMsg->message_type == XA_XdndDrop)
  196883. {
  196884. handleDragAndDropDrop (clientMsg);
  196885. }
  196886. else if (clientMsg->message_type == XA_XdndStatus)
  196887. {
  196888. handleDragAndDropStatus (clientMsg);
  196889. }
  196890. else if (clientMsg->message_type == XA_XdndFinished)
  196891. {
  196892. resetDragAndDrop();
  196893. }
  196894. break;
  196895. }
  196896. case SelectionNotify:
  196897. handleDragAndDropSelection (event);
  196898. break;
  196899. case SelectionClear:
  196900. case SelectionRequest:
  196901. break;
  196902. default:
  196903. #if JUCE_USE_XSHM
  196904. {
  196905. ScopedXLock xlock;
  196906. if (event->xany.type == XShmGetEventBase (display))
  196907. repainter->notifyPaintCompleted();
  196908. }
  196909. #endif
  196910. break;
  196911. }
  196912. }
  196913. void showMouseCursor (Cursor cursor) throw()
  196914. {
  196915. ScopedXLock xlock;
  196916. XDefineCursor (display, windowH, cursor);
  196917. }
  196918. void setTaskBarIcon (const Image& image)
  196919. {
  196920. ScopedXLock xlock;
  196921. deleteTaskBarIcon();
  196922. taskbarImage = image.createCopy();
  196923. Screen* const screen = XDefaultScreenOfDisplay (display);
  196924. const int screenNumber = XScreenNumberOfScreen (screen);
  196925. String screenAtom ("_NET_SYSTEM_TRAY_S");
  196926. screenAtom << screenNumber;
  196927. Atom selectionAtom = XInternAtom (display, (const char*) screenAtom, false);
  196928. XGrabServer (display);
  196929. Window managerWin = XGetSelectionOwner (display, selectionAtom);
  196930. if (managerWin != None)
  196931. XSelectInput (display, managerWin, StructureNotifyMask);
  196932. XUngrabServer (display);
  196933. XFlush (display);
  196934. if (managerWin != None)
  196935. {
  196936. XEvent ev;
  196937. zerostruct (ev);
  196938. ev.xclient.type = ClientMessage;
  196939. ev.xclient.window = managerWin;
  196940. ev.xclient.message_type = XInternAtom (display, "_NET_SYSTEM_TRAY_OPCODE", False);
  196941. ev.xclient.format = 32;
  196942. ev.xclient.data.l[0] = CurrentTime;
  196943. ev.xclient.data.l[1] = SYSTEM_TRAY_REQUEST_DOCK;
  196944. ev.xclient.data.l[2] = windowH;
  196945. ev.xclient.data.l[3] = 0;
  196946. ev.xclient.data.l[4] = 0;
  196947. XSendEvent (display, managerWin, False, NoEventMask, &ev);
  196948. XSync (display, False);
  196949. }
  196950. // For older KDE's ...
  196951. long atomData = 1;
  196952. Atom trayAtom = XInternAtom (display, "KWM_DOCKWINDOW", false);
  196953. XChangeProperty (display, windowH, trayAtom, trayAtom, 32, PropModeReplace, (unsigned char*) &atomData, 1);
  196954. // For more recent KDE's...
  196955. trayAtom = XInternAtom (display, "_KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR", false);
  196956. XChangeProperty (display, windowH, trayAtom, XA_WINDOW, 32, PropModeReplace, (unsigned char*) &windowH, 1);
  196957. // a minimum size must be specified for GNOME and Xfce, otherwise the icon is displayed with a width of 1
  196958. XSizeHints* hints = XAllocSizeHints();
  196959. hints->flags = PMinSize;
  196960. hints->min_width = 22;
  196961. hints->min_height = 22;
  196962. XSetWMNormalHints (display, windowH, hints);
  196963. XFree (hints);
  196964. }
  196965. void deleteTaskBarIcon()
  196966. {
  196967. deleteAndZero (taskbarImage);
  196968. }
  196969. const Image* getTaskbarIcon() const throw() { return taskbarImage; }
  196970. juce_UseDebuggingNewOperator
  196971. bool dontRepaint;
  196972. private:
  196973. class LinuxRepaintManager : public Timer
  196974. {
  196975. public:
  196976. LinuxRepaintManager (LinuxComponentPeer* const peer_)
  196977. : peer (peer_),
  196978. lastTimeImageUsed (0)
  196979. {
  196980. #if JUCE_USE_XSHM
  196981. shmCompletedDrawing = true;
  196982. useARGBImagesForRendering = isShmAvailable();
  196983. if (useARGBImagesForRendering)
  196984. {
  196985. ScopedXLock xlock;
  196986. XShmSegmentInfo segmentinfo;
  196987. XImage* const testImage
  196988. = XShmCreateImage (display, DefaultVisual (display, DefaultScreen (display)),
  196989. 24, ZPixmap, 0, &segmentinfo, 64, 64);
  196990. useARGBImagesForRendering = (testImage->bits_per_pixel == 32);
  196991. XDestroyImage (testImage);
  196992. }
  196993. #endif
  196994. }
  196995. ~LinuxRepaintManager()
  196996. {
  196997. }
  196998. void timerCallback()
  196999. {
  197000. #if JUCE_USE_XSHM
  197001. if (! shmCompletedDrawing)
  197002. return;
  197003. #endif
  197004. if (! regionsNeedingRepaint.isEmpty())
  197005. {
  197006. stopTimer();
  197007. performAnyPendingRepaintsNow();
  197008. }
  197009. else if (Time::getApproximateMillisecondCounter() > lastTimeImageUsed + 3000)
  197010. {
  197011. stopTimer();
  197012. image = 0;
  197013. }
  197014. }
  197015. void repaint (int x, int y, int w, int h)
  197016. {
  197017. if (! isTimerRunning())
  197018. startTimer (repaintTimerPeriod);
  197019. regionsNeedingRepaint.add (x, y, w, h);
  197020. }
  197021. void performAnyPendingRepaintsNow()
  197022. {
  197023. #if JUCE_USE_XSHM
  197024. if (! shmCompletedDrawing)
  197025. {
  197026. startTimer (repaintTimerPeriod);
  197027. return;
  197028. }
  197029. #endif
  197030. peer->clearMaskedRegion();
  197031. RectangleList originalRepaintRegion (regionsNeedingRepaint);
  197032. regionsNeedingRepaint.clear();
  197033. const Rectangle<int> totalArea (originalRepaintRegion.getBounds());
  197034. if (! totalArea.isEmpty())
  197035. {
  197036. if (image == 0 || image->getWidth() < totalArea.getWidth()
  197037. || image->getHeight() < totalArea.getHeight())
  197038. {
  197039. #if JUCE_USE_XSHM
  197040. image = new XBitmapImage (useARGBImagesForRendering ? Image::ARGB
  197041. : Image::RGB,
  197042. #else
  197043. image = new XBitmapImage (Image::RGB,
  197044. #endif
  197045. (totalArea.getWidth() + 31) & ~31,
  197046. (totalArea.getHeight() + 31) & ~31,
  197047. false,
  197048. peer->depthIs16Bit);
  197049. }
  197050. startTimer (repaintTimerPeriod);
  197051. LowLevelGraphicsSoftwareRenderer context (*image);
  197052. context.setOrigin (-totalArea.getX(), -totalArea.getY());
  197053. if (context.clipToRectangleList (originalRepaintRegion))
  197054. peer->handlePaint (context);
  197055. if (! peer->maskedRegion.isEmpty())
  197056. originalRepaintRegion.subtract (peer->maskedRegion);
  197057. for (RectangleList::Iterator i (originalRepaintRegion); i.next();)
  197058. {
  197059. #if JUCE_USE_XSHM
  197060. shmCompletedDrawing = false;
  197061. #endif
  197062. const Rectangle<int>& r = *i.getRectangle();
  197063. image->blitToWindow (peer->windowH,
  197064. r.getX(), r.getY(), r.getWidth(), r.getHeight(),
  197065. r.getX() - totalArea.getX(), r.getY() - totalArea.getY());
  197066. }
  197067. }
  197068. lastTimeImageUsed = Time::getApproximateMillisecondCounter();
  197069. startTimer (repaintTimerPeriod);
  197070. }
  197071. #if JUCE_USE_XSHM
  197072. void notifyPaintCompleted() { shmCompletedDrawing = true; }
  197073. #endif
  197074. private:
  197075. LinuxComponentPeer* const peer;
  197076. ScopedPointer <XBitmapImage> image;
  197077. uint32 lastTimeImageUsed;
  197078. RectangleList regionsNeedingRepaint;
  197079. #if JUCE_USE_XSHM
  197080. bool useARGBImagesForRendering, shmCompletedDrawing;
  197081. #endif
  197082. LinuxRepaintManager (const LinuxRepaintManager&);
  197083. const LinuxRepaintManager& operator= (const LinuxRepaintManager&);
  197084. };
  197085. ScopedPointer <LinuxRepaintManager> repainter;
  197086. friend class LinuxRepaintManager;
  197087. Window windowH, parentWindow;
  197088. int wx, wy, ww, wh;
  197089. Image* taskbarImage;
  197090. bool fullScreen, entered, mapped, depthIs16Bit;
  197091. BorderSize windowBorder;
  197092. struct MotifWmHints
  197093. {
  197094. unsigned long flags;
  197095. unsigned long functions;
  197096. unsigned long decorations;
  197097. long input_mode;
  197098. unsigned long status;
  197099. };
  197100. void removeWindowDecorations (Window wndH)
  197101. {
  197102. Atom hints = XInternAtom (display, "_MOTIF_WM_HINTS", True);
  197103. if (hints != None)
  197104. {
  197105. MotifWmHints motifHints;
  197106. zerostruct (motifHints);
  197107. motifHints.flags = 2; /* MWM_HINTS_DECORATIONS */
  197108. motifHints.decorations = 0;
  197109. ScopedXLock xlock;
  197110. XChangeProperty (display, wndH, hints, hints, 32, PropModeReplace,
  197111. (unsigned char*) &motifHints, 4);
  197112. }
  197113. hints = XInternAtom (display, "_WIN_HINTS", True);
  197114. if (hints != None)
  197115. {
  197116. long gnomeHints = 0;
  197117. ScopedXLock xlock;
  197118. XChangeProperty (display, wndH, hints, hints, 32, PropModeReplace,
  197119. (unsigned char*) &gnomeHints, 1);
  197120. }
  197121. hints = XInternAtom (display, "KWM_WIN_DECORATION", True);
  197122. if (hints != None)
  197123. {
  197124. long kwmHints = 2; /*KDE_tinyDecoration*/
  197125. ScopedXLock xlock;
  197126. XChangeProperty (display, wndH, hints, hints, 32, PropModeReplace,
  197127. (unsigned char*) &kwmHints, 1);
  197128. }
  197129. hints = XInternAtom (display, "_NET_WM_WINDOW_TYPE", True);
  197130. if (hints != None)
  197131. {
  197132. ScopedXLock xlock;
  197133. int netHints [2];
  197134. int numHints = 0;
  197135. if ((styleFlags & windowIsTemporary) != 0)
  197136. netHints [numHints] = XInternAtom (display, "_NET_WM_WINDOW_TYPE_MENU", True);
  197137. else
  197138. netHints [numHints] = XInternAtom (display, "_NET_WM_WINDOW_TYPE_NORMAL", True);
  197139. if (netHints [numHints] != 0)
  197140. ++numHints;
  197141. netHints[numHints] = XInternAtom (display, "_KDE_NET_WM_WINDOW_TYPE_OVERRIDE", True);
  197142. if (netHints [numHints] != 0)
  197143. ++numHints;
  197144. XChangeProperty (display, wndH, hints, XA_ATOM, 32, PropModeReplace,
  197145. (unsigned char*) &netHints, numHints);
  197146. }
  197147. }
  197148. void addWindowButtons (Window wndH)
  197149. {
  197150. ScopedXLock xlock;
  197151. Atom hints = XInternAtom (display, "_MOTIF_WM_HINTS", True);
  197152. if (hints != None)
  197153. {
  197154. MotifWmHints motifHints;
  197155. zerostruct (motifHints);
  197156. motifHints.flags = 1 | 2; /* MWM_HINTS_FUNCTIONS | MWM_HINTS_DECORATIONS */
  197157. motifHints.decorations = 2 /* MWM_DECOR_BORDER */ | 8 /* MWM_DECOR_TITLE */ | 16; /* MWM_DECOR_MENU */
  197158. motifHints.functions = 4 /* MWM_FUNC_MOVE */;
  197159. if ((styleFlags & windowHasCloseButton) != 0)
  197160. motifHints.functions |= 32; /* MWM_FUNC_CLOSE */
  197161. if ((styleFlags & windowHasMinimiseButton) != 0)
  197162. {
  197163. motifHints.functions |= 8; /* MWM_FUNC_MINIMIZE */
  197164. motifHints.decorations |= 0x20; /* MWM_DECOR_MINIMIZE */
  197165. }
  197166. if ((styleFlags & windowHasMaximiseButton) != 0)
  197167. {
  197168. motifHints.functions |= 0x10; /* MWM_FUNC_MAXIMIZE */
  197169. motifHints.decorations |= 0x40; /* MWM_DECOR_MAXIMIZE */
  197170. }
  197171. if ((styleFlags & windowIsResizable) != 0)
  197172. {
  197173. motifHints.functions |= 2; /* MWM_FUNC_RESIZE */
  197174. motifHints.decorations |= 0x4; /* MWM_DECOR_RESIZEH */
  197175. }
  197176. XChangeProperty (display, wndH, hints, hints, 32, 0, (unsigned char*) &motifHints, 5);
  197177. }
  197178. hints = XInternAtom (display, "_NET_WM_ALLOWED_ACTIONS", True);
  197179. if (hints != None)
  197180. {
  197181. int netHints [6];
  197182. int num = 0;
  197183. netHints [num++] = XInternAtom (display, "_NET_WM_ACTION_RESIZE", (styleFlags & windowIsResizable) ? True : False);
  197184. netHints [num++] = XInternAtom (display, "_NET_WM_ACTION_FULLSCREEN", (styleFlags & windowHasMaximiseButton) ? True : False);
  197185. netHints [num++] = XInternAtom (display, "_NET_WM_ACTION_MINIMIZE", (styleFlags & windowHasMinimiseButton) ? True : False);
  197186. netHints [num++] = XInternAtom (display, "_NET_WM_ACTION_CLOSE", (styleFlags & windowHasCloseButton) ? True : False);
  197187. XChangeProperty (display, wndH, hints, XA_ATOM, 32, PropModeReplace,
  197188. (unsigned char*) &netHints, num);
  197189. }
  197190. }
  197191. void createWindow()
  197192. {
  197193. ScopedXLock xlock;
  197194. static bool atomsInitialised = false;
  197195. if (! atomsInitialised)
  197196. {
  197197. atomsInitialised = true;
  197198. wm_Protocols = XInternAtom (display, "WM_PROTOCOLS", 1);
  197199. wm_ProtocolList [TAKE_FOCUS] = XInternAtom (display, "WM_TAKE_FOCUS", 1);
  197200. wm_ProtocolList [DELETE_WINDOW] = XInternAtom (display, "WM_DELETE_WINDOW", 1);
  197201. wm_ChangeState = XInternAtom (display, "WM_CHANGE_STATE", 1);
  197202. wm_State = XInternAtom (display, "WM_STATE", 1);
  197203. wm_ActiveWin = XInternAtom (display, "_NET_ACTIVE_WINDOW", False);
  197204. XA_XdndAware = XInternAtom (display, "XdndAware", 0);
  197205. XA_XdndEnter = XInternAtom (display, "XdndEnter", 0);
  197206. XA_XdndLeave = XInternAtom (display, "XdndLeave", 0);
  197207. XA_XdndPosition = XInternAtom (display, "XdndPosition", 0);
  197208. XA_XdndStatus = XInternAtom (display, "XdndStatus", 0);
  197209. XA_XdndDrop = XInternAtom (display, "XdndDrop", 0);
  197210. XA_XdndFinished = XInternAtom (display, "XdndFinished", 0);
  197211. XA_XdndSelection = XInternAtom (display, "XdndSelection", 0);
  197212. XA_XdndProxy = XInternAtom (display, "XdndProxy", 0);
  197213. XA_XdndTypeList = XInternAtom (display, "XdndTypeList", 0);
  197214. XA_XdndActionList = XInternAtom (display, "XdndActionList", 0);
  197215. XA_XdndActionCopy = XInternAtom (display, "XdndActionCopy", 0);
  197216. XA_XdndActionMove = XInternAtom (display, "XdndActionMove", 0);
  197217. XA_XdndActionLink = XInternAtom (display, "XdndActionLink", 0);
  197218. XA_XdndActionAsk = XInternAtom (display, "XdndActionAsk", 0);
  197219. XA_XdndActionPrivate = XInternAtom (display, "XdndActionPrivate", 0);
  197220. XA_XdndActionDescription = XInternAtom (display, "XdndActionDescription", 0);
  197221. XA_JXSelectionWindowProperty = XInternAtom (display, "JXSelectionWindowProperty", 0);
  197222. XA_MimeTextPlain = XInternAtom (display, "text/plain", 0);
  197223. XA_MimeTextUriList = XInternAtom (display, "text/uri-list", 0);
  197224. XA_MimeRootDrop = XInternAtom (display, "application/x-rootwindow-drop", 0);
  197225. }
  197226. resetDragAndDrop();
  197227. XA_OtherMime = XA_MimeTextPlain; // xxx why??
  197228. allowedMimeTypeAtoms [0] = XA_MimeTextPlain;
  197229. allowedMimeTypeAtoms [1] = XA_OtherMime;
  197230. allowedMimeTypeAtoms [2] = XA_MimeTextUriList;
  197231. allowedActions [0] = XA_XdndActionMove;
  197232. allowedActions [1] = XA_XdndActionCopy;
  197233. allowedActions [2] = XA_XdndActionLink;
  197234. allowedActions [3] = XA_XdndActionAsk;
  197235. allowedActions [4] = XA_XdndActionPrivate;
  197236. // Get defaults for various properties
  197237. const int screen = DefaultScreen (display);
  197238. Window root = RootWindow (display, screen);
  197239. // Attempt to create a 24-bit window on the default screen. If this is not
  197240. // possible then exit
  197241. XVisualInfo desiredVisual;
  197242. desiredVisual.screen = screen;
  197243. desiredVisual.depth = 24;
  197244. depthIs16Bit = false;
  197245. int numVisuals;
  197246. XVisualInfo* visuals = XGetVisualInfo (display, VisualScreenMask | VisualDepthMask,
  197247. &desiredVisual, &numVisuals);
  197248. if (numVisuals < 1 || visuals == 0)
  197249. {
  197250. XFree (visuals);
  197251. desiredVisual.depth = 16;
  197252. visuals = XGetVisualInfo (display, VisualScreenMask | VisualDepthMask,
  197253. &desiredVisual, &numVisuals);
  197254. if (numVisuals < 1 || visuals == 0)
  197255. {
  197256. Logger::outputDebugString ("ERROR: System doesn't support 24 or 16 bit RGB display.\n");
  197257. Process::terminate();
  197258. }
  197259. depthIs16Bit = true;
  197260. }
  197261. XFree (visuals);
  197262. // Set up the window attributes
  197263. XSetWindowAttributes swa;
  197264. swa.border_pixel = 0;
  197265. swa.background_pixmap = None;
  197266. swa.colormap = DefaultColormap (display, screen);
  197267. swa.override_redirect = getComponent()->isAlwaysOnTop() ? True : False;
  197268. swa.event_mask = eventMask;
  197269. Window wndH = XCreateWindow (display, root,
  197270. 0, 0, 1, 1,
  197271. 0, 0, InputOutput, (Visual*) CopyFromParent,
  197272. CWBorderPixel | CWColormap | CWBackPixmap | CWEventMask | CWOverrideRedirect,
  197273. &swa);
  197274. XGrabButton (display, AnyButton, AnyModifier, wndH, False,
  197275. ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
  197276. GrabModeAsync, GrabModeAsync, None, None);
  197277. // Set the window context to identify the window handle object
  197278. if (XSaveContext (display, (XID) wndH, improbableNumber, (XPointer) this))
  197279. {
  197280. // Failed
  197281. jassertfalse
  197282. Logger::outputDebugString ("Failed to create context information for window.\n");
  197283. XDestroyWindow (display, wndH);
  197284. wndH = 0;
  197285. }
  197286. // Set window manager hints
  197287. XWMHints* wmHints = XAllocWMHints();
  197288. wmHints->flags = InputHint | StateHint;
  197289. wmHints->input = True; // Locally active input model
  197290. wmHints->initial_state = NormalState;
  197291. XSetWMHints (display, wndH, wmHints);
  197292. XFree (wmHints);
  197293. if ((styleFlags & windowIsSemiTransparent) != 0)
  197294. {
  197295. //xxx
  197296. }
  197297. if ((styleFlags & windowAppearsOnTaskbar) != 0)
  197298. {
  197299. //xxx
  197300. }
  197301. //XSetTransientForHint (display, wndH, RootWindow (display, DefaultScreen (display)));
  197302. if ((styleFlags & windowHasTitleBar) == 0)
  197303. removeWindowDecorations (wndH);
  197304. else
  197305. addWindowButtons (wndH);
  197306. // Set window manager protocols
  197307. XChangeProperty (display, wndH, wm_Protocols, XA_ATOM, 32, PropModeReplace,
  197308. (unsigned char*) wm_ProtocolList, 2);
  197309. // Set drag and drop flags
  197310. XChangeProperty (display, wndH, XA_XdndTypeList, XA_ATOM, 32, PropModeReplace,
  197311. (const unsigned char*) allowedMimeTypeAtoms, numElementsInArray (allowedMimeTypeAtoms));
  197312. XChangeProperty (display, wndH, XA_XdndActionList, XA_ATOM, 32, PropModeReplace,
  197313. (const unsigned char*) allowedActions, numElementsInArray (allowedActions));
  197314. XChangeProperty (display, wndH, XA_XdndActionDescription, XA_STRING, 8, PropModeReplace,
  197315. (const unsigned char*) "", 0);
  197316. unsigned long dndVersion = ourDndVersion;
  197317. XChangeProperty (display, wndH, XA_XdndAware, XA_ATOM, 32, PropModeReplace,
  197318. (const unsigned char*) &dndVersion, 1);
  197319. // Set window name
  197320. setWindowTitle (wndH, getComponent()->getName());
  197321. // Initialise the pointer and keyboard mapping
  197322. // This is not the same as the logical pointer mapping the X server uses:
  197323. // we don't mess with this.
  197324. static bool mappingInitialised = false;
  197325. if (! mappingInitialised)
  197326. {
  197327. mappingInitialised = true;
  197328. const int numButtons = XGetPointerMapping (display, 0, 0);
  197329. if (numButtons == 2)
  197330. {
  197331. pointerMap[0] = LeftButton;
  197332. pointerMap[1] = RightButton;
  197333. pointerMap[2] = pointerMap[3] = pointerMap[4] = NoButton;
  197334. }
  197335. else if (numButtons >= 3)
  197336. {
  197337. pointerMap[0] = LeftButton;
  197338. pointerMap[1] = MiddleButton;
  197339. pointerMap[2] = RightButton;
  197340. if (numButtons >= 5)
  197341. {
  197342. pointerMap[3] = WheelUp;
  197343. pointerMap[4] = WheelDown;
  197344. }
  197345. }
  197346. getModifierMapping();
  197347. }
  197348. windowH = wndH;
  197349. }
  197350. void destroyWindow()
  197351. {
  197352. ScopedXLock xlock;
  197353. XPointer handlePointer;
  197354. if (! XFindContext (display, (XID) windowH, improbableNumber, &handlePointer))
  197355. XDeleteContext (display, (XID) windowH, improbableNumber);
  197356. XDestroyWindow (display, windowH);
  197357. // Wait for it to complete and then remove any events for this
  197358. // window from the event queue.
  197359. XSync (display, false);
  197360. XEvent event;
  197361. while (XCheckWindowEvent (display, windowH, eventMask, &event) == True)
  197362. {}
  197363. }
  197364. static int64 getEventTime (::Time t) throw()
  197365. {
  197366. static int64 eventTimeOffset = 0x12345678;
  197367. const int64 thisMessageTime = t;
  197368. if (eventTimeOffset == 0x12345678)
  197369. eventTimeOffset = Time::currentTimeMillis() - thisMessageTime;
  197370. return eventTimeOffset + thisMessageTime;
  197371. }
  197372. static void setWindowTitle (Window xwin, const char* const title) throw()
  197373. {
  197374. XTextProperty nameProperty;
  197375. char* strings[] = { (char*) title };
  197376. ScopedXLock xlock;
  197377. if (XStringListToTextProperty (strings, 1, &nameProperty))
  197378. {
  197379. XSetWMName (display, xwin, &nameProperty);
  197380. XSetWMIconName (display, xwin, &nameProperty);
  197381. XFree (nameProperty.value);
  197382. }
  197383. }
  197384. void updateBorderSize()
  197385. {
  197386. if ((styleFlags & windowHasTitleBar) == 0)
  197387. {
  197388. windowBorder = BorderSize (0);
  197389. }
  197390. else if (windowBorder.getTopAndBottom() == 0 && windowBorder.getLeftAndRight() == 0)
  197391. {
  197392. ScopedXLock xlock;
  197393. Atom hints = XInternAtom (display, "_NET_FRAME_EXTENTS", True);
  197394. if (hints != None)
  197395. {
  197396. unsigned char* data = 0;
  197397. unsigned long nitems, bytesLeft;
  197398. Atom actualType;
  197399. int actualFormat;
  197400. if (XGetWindowProperty (display, windowH, hints, 0, 4, False,
  197401. XA_CARDINAL, &actualType, &actualFormat, &nitems, &bytesLeft,
  197402. &data) == Success)
  197403. {
  197404. const unsigned long* const sizes = (const unsigned long*) data;
  197405. if (actualFormat == 32)
  197406. windowBorder = BorderSize ((int) sizes[2], (int) sizes[0],
  197407. (int) sizes[3], (int) sizes[1]);
  197408. XFree (data);
  197409. }
  197410. }
  197411. }
  197412. }
  197413. void updateBounds()
  197414. {
  197415. jassert (windowH != 0);
  197416. if (windowH != 0)
  197417. {
  197418. Window root, child;
  197419. unsigned int bw, depth;
  197420. ScopedXLock xlock;
  197421. if (! XGetGeometry (display, (::Drawable) windowH, &root,
  197422. &wx, &wy, (unsigned int*) &ww, (unsigned int*) &wh,
  197423. &bw, &depth))
  197424. {
  197425. wx = wy = ww = wh = 0;
  197426. }
  197427. else if (! XTranslateCoordinates (display, windowH, root, 0, 0, &wx, &wy, &child))
  197428. {
  197429. wx = wy = 0;
  197430. }
  197431. }
  197432. }
  197433. void resetDragAndDrop()
  197434. {
  197435. dragAndDropFiles.clear();
  197436. lastDropX = lastDropY = -1;
  197437. dragAndDropCurrentMimeType = 0;
  197438. dragAndDropSourceWindow = 0;
  197439. srcMimeTypeAtomList.clear();
  197440. }
  197441. void sendDragAndDropMessage (XClientMessageEvent& msg)
  197442. {
  197443. msg.type = ClientMessage;
  197444. msg.display = display;
  197445. msg.window = dragAndDropSourceWindow;
  197446. msg.format = 32;
  197447. msg.data.l[0] = windowH;
  197448. ScopedXLock xlock;
  197449. XSendEvent (display, dragAndDropSourceWindow, False, 0, (XEvent*) &msg);
  197450. }
  197451. void sendDragAndDropStatus (const bool acceptDrop, Atom dropAction)
  197452. {
  197453. XClientMessageEvent msg;
  197454. zerostruct (msg);
  197455. msg.message_type = XA_XdndStatus;
  197456. msg.data.l[1] = (acceptDrop ? 1 : 0) | 2; // 2 indicates that we want to receive position messages
  197457. msg.data.l[4] = dropAction;
  197458. sendDragAndDropMessage (msg);
  197459. }
  197460. void sendDragAndDropLeave()
  197461. {
  197462. XClientMessageEvent msg;
  197463. zerostruct (msg);
  197464. msg.message_type = XA_XdndLeave;
  197465. sendDragAndDropMessage (msg);
  197466. }
  197467. void sendDragAndDropFinish()
  197468. {
  197469. XClientMessageEvent msg;
  197470. zerostruct (msg);
  197471. msg.message_type = XA_XdndFinished;
  197472. sendDragAndDropMessage (msg);
  197473. }
  197474. void handleDragAndDropStatus (const XClientMessageEvent* const clientMsg)
  197475. {
  197476. if ((clientMsg->data.l[1] & 1) == 0)
  197477. {
  197478. sendDragAndDropLeave();
  197479. if (dragAndDropFiles.size() > 0)
  197480. handleFileDragExit (dragAndDropFiles);
  197481. dragAndDropFiles.clear();
  197482. }
  197483. }
  197484. void handleDragAndDropPosition (const XClientMessageEvent* const clientMsg)
  197485. {
  197486. if (dragAndDropSourceWindow == 0)
  197487. return;
  197488. dragAndDropSourceWindow = clientMsg->data.l[0];
  197489. const int dropX = ((int) clientMsg->data.l[2] >> 16) - getScreenX();
  197490. const int dropY = ((int) clientMsg->data.l[2] & 0xffff) - getScreenY();
  197491. if (lastDropX != dropX || lastDropY != dropY)
  197492. {
  197493. lastDropX = dropX;
  197494. lastDropY = dropY;
  197495. dragAndDropTimestamp = clientMsg->data.l[3];
  197496. Atom targetAction = XA_XdndActionCopy;
  197497. for (int i = numElementsInArray (allowedActions); --i >= 0;)
  197498. {
  197499. if ((Atom) clientMsg->data.l[4] == allowedActions[i])
  197500. {
  197501. targetAction = allowedActions[i];
  197502. break;
  197503. }
  197504. }
  197505. sendDragAndDropStatus (true, targetAction);
  197506. if (dragAndDropFiles.size() == 0)
  197507. updateDraggedFileList (clientMsg);
  197508. if (dragAndDropFiles.size() > 0)
  197509. handleFileDragMove (dragAndDropFiles, dropX, dropY);
  197510. }
  197511. }
  197512. void handleDragAndDropDrop (const XClientMessageEvent* const clientMsg)
  197513. {
  197514. if (dragAndDropFiles.size() == 0)
  197515. updateDraggedFileList (clientMsg);
  197516. const StringArray files (dragAndDropFiles);
  197517. const int lastX = lastDropX, lastY = lastDropY;
  197518. sendDragAndDropFinish();
  197519. resetDragAndDrop();
  197520. if (files.size() > 0)
  197521. handleFileDragDrop (files, lastX, lastY);
  197522. }
  197523. void handleDragAndDropEnter (const XClientMessageEvent* const clientMsg)
  197524. {
  197525. dragAndDropFiles.clear();
  197526. srcMimeTypeAtomList.clear();
  197527. dragAndDropCurrentMimeType = 0;
  197528. const int dndCurrentVersion = (int) (clientMsg->data.l[1] & 0xff000000) >> 24;
  197529. if (dndCurrentVersion < 3 || dndCurrentVersion > ourDndVersion)
  197530. {
  197531. dragAndDropSourceWindow = 0;
  197532. return;
  197533. }
  197534. dragAndDropSourceWindow = clientMsg->data.l[0];
  197535. if ((clientMsg->data.l[1] & 1) != 0)
  197536. {
  197537. Atom actual;
  197538. int format;
  197539. unsigned long count = 0, remaining = 0;
  197540. unsigned char* data = 0;
  197541. ScopedXLock xlock;
  197542. XGetWindowProperty (display, dragAndDropSourceWindow, XA_XdndTypeList,
  197543. 0, 0x8000000L, False, XA_ATOM, &actual, &format,
  197544. &count, &remaining, &data);
  197545. if (data != 0)
  197546. {
  197547. if (actual == XA_ATOM && format == 32 && count != 0)
  197548. {
  197549. const unsigned long* const types = (const unsigned long*) data;
  197550. for (unsigned int i = 0; i < count; ++i)
  197551. if (types[i] != None)
  197552. srcMimeTypeAtomList.add (types[i]);
  197553. }
  197554. XFree (data);
  197555. }
  197556. }
  197557. if (srcMimeTypeAtomList.size() == 0)
  197558. {
  197559. for (int i = 2; i < 5; ++i)
  197560. if (clientMsg->data.l[i] != None)
  197561. srcMimeTypeAtomList.add (clientMsg->data.l[i]);
  197562. if (srcMimeTypeAtomList.size() == 0)
  197563. {
  197564. dragAndDropSourceWindow = 0;
  197565. return;
  197566. }
  197567. }
  197568. for (int i = 0; i < srcMimeTypeAtomList.size() && dragAndDropCurrentMimeType == 0; ++i)
  197569. for (int j = 0; j < numElementsInArray (allowedMimeTypeAtoms); ++j)
  197570. if (srcMimeTypeAtomList[i] == allowedMimeTypeAtoms[j])
  197571. dragAndDropCurrentMimeType = allowedMimeTypeAtoms[j];
  197572. handleDragAndDropPosition (clientMsg);
  197573. }
  197574. void handleDragAndDropSelection (const XEvent* const evt)
  197575. {
  197576. dragAndDropFiles.clear();
  197577. if (evt->xselection.property != 0)
  197578. {
  197579. StringArray lines;
  197580. {
  197581. MemoryBlock dropData;
  197582. for (;;)
  197583. {
  197584. Atom actual;
  197585. uint8* data = 0;
  197586. unsigned long count = 0, remaining = 0;
  197587. int format = 0;
  197588. ScopedXLock xlock;
  197589. if (XGetWindowProperty (display, evt->xany.window, evt->xselection.property,
  197590. dropData.getSize() / 4, 65536, 1, AnyPropertyType, &actual,
  197591. &format, &count, &remaining, &data) == Success)
  197592. {
  197593. dropData.append (data, count * format / 8);
  197594. XFree (data);
  197595. if (remaining == 0)
  197596. break;
  197597. }
  197598. else
  197599. {
  197600. XFree (data);
  197601. break;
  197602. }
  197603. }
  197604. lines.addLines (dropData.toString());
  197605. }
  197606. for (int i = 0; i < lines.size(); ++i)
  197607. dragAndDropFiles.add (URL::removeEscapeChars (lines[i].fromFirstOccurrenceOf (T("file://"), false, true)));
  197608. dragAndDropFiles.trim();
  197609. dragAndDropFiles.removeEmptyStrings();
  197610. }
  197611. }
  197612. void updateDraggedFileList (const XClientMessageEvent* const clientMsg)
  197613. {
  197614. dragAndDropFiles.clear();
  197615. if (dragAndDropSourceWindow != None
  197616. && dragAndDropCurrentMimeType != 0)
  197617. {
  197618. dragAndDropTimestamp = clientMsg->data.l[2];
  197619. ScopedXLock xlock;
  197620. XConvertSelection (display,
  197621. XA_XdndSelection,
  197622. dragAndDropCurrentMimeType,
  197623. XA_JXSelectionWindowProperty,
  197624. windowH,
  197625. dragAndDropTimestamp);
  197626. }
  197627. }
  197628. StringArray dragAndDropFiles;
  197629. int dragAndDropTimestamp, lastDropX, lastDropY;
  197630. Atom XA_OtherMime, dragAndDropCurrentMimeType;
  197631. Window dragAndDropSourceWindow;
  197632. unsigned int allowedActions [5];
  197633. unsigned int allowedMimeTypeAtoms [3];
  197634. Array <Atom> srcMimeTypeAtomList;
  197635. };
  197636. void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars)
  197637. {
  197638. if (enableOrDisable)
  197639. kioskModeComponent->setBounds (Desktop::getInstance().getMainMonitorArea (false));
  197640. }
  197641. ComponentPeer* Component::createNewPeer (int styleFlags, void* /*nativeWindowToAttachTo*/)
  197642. {
  197643. return new LinuxComponentPeer (this, styleFlags);
  197644. }
  197645. // (this callback is hooked up in the messaging code)
  197646. void juce_windowMessageReceive (XEvent* event)
  197647. {
  197648. if (event->xany.window != None)
  197649. {
  197650. LinuxComponentPeer* const peer = LinuxComponentPeer::getPeerFor (event->xany.window);
  197651. if (ComponentPeer::isValidPeer (peer))
  197652. peer->handleWindowMessage (event);
  197653. }
  197654. else
  197655. {
  197656. switch (event->xany.type)
  197657. {
  197658. case KeymapNotify:
  197659. {
  197660. const XKeymapEvent* const keymapEvent = (const XKeymapEvent*) &event->xkeymap;
  197661. memcpy (keyStates, keymapEvent->key_vector, 32);
  197662. break;
  197663. }
  197664. default:
  197665. break;
  197666. }
  197667. }
  197668. }
  197669. void juce_updateMultiMonitorInfo (Array <Rectangle<int> >& monitorCoords, const bool /*clipToWorkArea*/)
  197670. {
  197671. if (display == 0)
  197672. return;
  197673. #if JUCE_USE_XINERAMA
  197674. int major_opcode, first_event, first_error;
  197675. ScopedXLock xlock;
  197676. if (XQueryExtension (display, "XINERAMA", &major_opcode, &first_event, &first_error))
  197677. {
  197678. typedef Bool (*tXineramaIsActive) (Display*);
  197679. typedef XineramaScreenInfo* (*tXineramaQueryScreens) (Display*, int*);
  197680. static tXineramaIsActive xXineramaIsActive = 0;
  197681. static tXineramaQueryScreens xXineramaQueryScreens = 0;
  197682. if (xXineramaIsActive == 0 || xXineramaQueryScreens == 0)
  197683. {
  197684. void* h = dlopen ("libXinerama.so", RTLD_GLOBAL | RTLD_NOW);
  197685. if (h != 0)
  197686. {
  197687. xXineramaIsActive = (tXineramaIsActive) dlsym (h, "XineramaIsActive");
  197688. xXineramaQueryScreens = (tXineramaQueryScreens) dlsym (h, "XineramaQueryScreens");
  197689. }
  197690. }
  197691. if (xXineramaIsActive != 0
  197692. && xXineramaQueryScreens != 0
  197693. && xXineramaIsActive (display))
  197694. {
  197695. int numMonitors = 0;
  197696. XineramaScreenInfo* const screens = xXineramaQueryScreens (display, &numMonitors);
  197697. if (screens != 0)
  197698. {
  197699. for (int i = numMonitors; --i >= 0;)
  197700. {
  197701. int index = screens[i].screen_number;
  197702. if (index >= 0)
  197703. {
  197704. while (monitorCoords.size() < index)
  197705. monitorCoords.add (Rectangle<int>());
  197706. monitorCoords.set (index, Rectangle<int> (screens[i].x_org,
  197707. screens[i].y_org,
  197708. screens[i].width,
  197709. screens[i].height));
  197710. }
  197711. }
  197712. XFree (screens);
  197713. }
  197714. }
  197715. }
  197716. if (monitorCoords.size() == 0)
  197717. #endif
  197718. {
  197719. Atom hints = XInternAtom (display, "_NET_WORKAREA", True);
  197720. if (hints != None)
  197721. {
  197722. const int numMonitors = ScreenCount (display);
  197723. for (int i = 0; i < numMonitors; ++i)
  197724. {
  197725. Window root = RootWindow (display, i);
  197726. unsigned long nitems, bytesLeft;
  197727. Atom actualType;
  197728. int actualFormat;
  197729. unsigned char* data = 0;
  197730. if (XGetWindowProperty (display, root, hints, 0, 4, False,
  197731. XA_CARDINAL, &actualType, &actualFormat, &nitems, &bytesLeft,
  197732. &data) == Success)
  197733. {
  197734. const long* const position = (const long*) data;
  197735. if (actualType == XA_CARDINAL && actualFormat == 32 && nitems == 4)
  197736. monitorCoords.add (Rectangle<int> (position[0], position[1],
  197737. position[2], position[3]));
  197738. XFree (data);
  197739. }
  197740. }
  197741. }
  197742. if (monitorCoords.size() == 0)
  197743. {
  197744. monitorCoords.add (Rectangle<int> (0, 0,
  197745. DisplayWidth (display, DefaultScreen (display)),
  197746. DisplayHeight (display, DefaultScreen (display))));
  197747. }
  197748. }
  197749. }
  197750. bool Desktop::canUseSemiTransparentWindows() throw()
  197751. {
  197752. return false;
  197753. }
  197754. void Desktop::getMousePosition (int& x, int& y) throw()
  197755. {
  197756. int mouseMods;
  197757. getMousePos (x, y, mouseMods);
  197758. }
  197759. void Desktop::setMousePosition (int x, int y) throw()
  197760. {
  197761. ScopedXLock xlock;
  197762. Window root = RootWindow (display, DefaultScreen (display));
  197763. XWarpPointer (display, None, root, 0, 0, 0, 0, x, y);
  197764. }
  197765. static bool screenSaverAllowed = true;
  197766. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  197767. {
  197768. if (screenSaverAllowed != isEnabled)
  197769. {
  197770. screenSaverAllowed = isEnabled;
  197771. typedef void (*tXScreenSaverSuspend) (Display*, Bool);
  197772. static tXScreenSaverSuspend xScreenSaverSuspend = 0;
  197773. if (xScreenSaverSuspend == 0)
  197774. {
  197775. void* h = dlopen ("libXss.so", RTLD_GLOBAL | RTLD_NOW);
  197776. if (h != 0)
  197777. xScreenSaverSuspend = (tXScreenSaverSuspend) dlsym (h, "XScreenSaverSuspend");
  197778. }
  197779. ScopedXLock xlock;
  197780. if (xScreenSaverSuspend != 0)
  197781. xScreenSaverSuspend (display, ! isEnabled);
  197782. }
  197783. }
  197784. bool Desktop::isScreenSaverEnabled() throw()
  197785. {
  197786. return screenSaverAllowed;
  197787. }
  197788. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw()
  197789. {
  197790. ScopedXLock xlock;
  197791. Window root = RootWindow (display, DefaultScreen (display));
  197792. const unsigned int imageW = image.getWidth();
  197793. const unsigned int imageH = image.getHeight();
  197794. unsigned int cursorW, cursorH;
  197795. if (! XQueryBestCursor (display, root, imageW, imageH, &cursorW, &cursorH))
  197796. return 0;
  197797. Image im (Image::ARGB, cursorW, cursorH, true);
  197798. Graphics g (im);
  197799. if (imageW > cursorW || imageH > cursorH)
  197800. {
  197801. hotspotX = (hotspotX * cursorW) / imageW;
  197802. hotspotY = (hotspotY * cursorH) / imageH;
  197803. g.drawImageWithin (&image, 0, 0, imageW, imageH,
  197804. RectanglePlacement::xLeft | RectanglePlacement::yTop | RectanglePlacement::onlyReduceInSize,
  197805. false);
  197806. }
  197807. else
  197808. {
  197809. g.drawImageAt (&image, 0, 0);
  197810. }
  197811. const int stride = (cursorW + 7) >> 3;
  197812. HeapBlock <uint8> maskPlane, sourcePlane;
  197813. maskPlane.calloc (stride * cursorH);
  197814. sourcePlane.calloc (stride * cursorH);
  197815. const bool msbfirst = (BitmapBitOrder (display) == MSBFirst);
  197816. for (int y = cursorH; --y >= 0;)
  197817. {
  197818. for (int x = cursorW; --x >= 0;)
  197819. {
  197820. const uint8 mask = (uint8) (1 << (msbfirst ? (7 - (x & 7)) : (x & 7)));
  197821. const int offset = y * stride + (x >> 3);
  197822. const Colour c (im.getPixelAt (x, y));
  197823. if (c.getAlpha() >= 128)
  197824. maskPlane[offset] |= mask;
  197825. if (c.getBrightness() >= 0.5f)
  197826. sourcePlane[offset] |= mask;
  197827. }
  197828. }
  197829. Pixmap sourcePixmap = XCreatePixmapFromBitmapData (display, root, (char*) sourcePlane, cursorW, cursorH, 0xffff, 0, 1);
  197830. Pixmap maskPixmap = XCreatePixmapFromBitmapData (display, root, (char*) maskPlane, cursorW, cursorH, 0xffff, 0, 1);
  197831. XColor white, black;
  197832. black.red = black.green = black.blue = 0;
  197833. white.red = white.green = white.blue = 0xffff;
  197834. void* result = (void*) XCreatePixmapCursor (display, sourcePixmap, maskPixmap, &white, &black, hotspotX, hotspotY);
  197835. XFreePixmap (display, sourcePixmap);
  197836. XFreePixmap (display, maskPixmap);
  197837. return result;
  197838. }
  197839. void juce_deleteMouseCursor (void* const cursorHandle, const bool) throw()
  197840. {
  197841. ScopedXLock xlock;
  197842. if (cursorHandle != None)
  197843. XFreeCursor (display, (Cursor) cursorHandle);
  197844. }
  197845. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw()
  197846. {
  197847. unsigned int shape;
  197848. switch (type)
  197849. {
  197850. case MouseCursor::NoCursor:
  197851. {
  197852. const Image im (Image::ARGB, 16, 16, true);
  197853. return juce_createMouseCursorFromImage (im, 0, 0);
  197854. }
  197855. case MouseCursor::NormalCursor:
  197856. return (void*) None; // Use parent cursor
  197857. case MouseCursor::DraggingHandCursor:
  197858. {
  197859. static unsigned char dragHandData[] = {71,73,70,56,57,97,16,0,16,0,145,2,0,0,0,0,255,255,255,0,
  197860. 0,0,0,0,0,33,249,4,1,0,0,2,0,44,0,0,0,0,16,0,
  197861. 16,0,0,2,52,148,47,0,200,185,16,130,90,12,74,139,107,84,123,39,
  197862. 132,117,151,116,132,146,248,60,209,138,98,22,203,114,34,236,37,52,77,217,
  197863. 247,154,191,119,110,240,193,128,193,95,163,56,60,234,98,135,2,0,59 };
  197864. const int dragHandDataSize = 99;
  197865. const ScopedPointer <Image> im (ImageFileFormat::loadFrom ((const char*) dragHandData, dragHandDataSize));
  197866. return juce_createMouseCursorFromImage (*im, 8, 7);
  197867. }
  197868. case MouseCursor::CopyingCursor:
  197869. {
  197870. static unsigned char copyCursorData[] = {71,73,70,56,57,97,21,0,21,0,145,0,0,0,0,0,255,255,255,0,
  197871. 128,128,255,255,255,33,249,4,1,0,0,3,0,44,0,0,0,0,21,0,
  197872. 21,0,0,2,72,4,134,169,171,16,199,98,11,79,90,71,161,93,56,111,
  197873. 78,133,218,215,137,31,82,154,100,200,86,91,202,142,12,108,212,87,235,174,
  197874. 15,54,214,126,237,226,37,96,59,141,16,37,18,201,142,157,230,204,51,112,
  197875. 252,114,147,74,83,5,50,68,147,208,217,16,71,149,252,124,5,0,59,0,0 };
  197876. const int copyCursorSize = 119;
  197877. const ScopedPointer <Image> im (ImageFileFormat::loadFrom ((const char*) copyCursorData, copyCursorSize));
  197878. return juce_createMouseCursorFromImage (*im, 1, 3);
  197879. }
  197880. case MouseCursor::WaitCursor:
  197881. shape = XC_watch;
  197882. break;
  197883. case MouseCursor::IBeamCursor:
  197884. shape = XC_xterm;
  197885. break;
  197886. case MouseCursor::PointingHandCursor:
  197887. shape = XC_hand2;
  197888. break;
  197889. case MouseCursor::LeftRightResizeCursor:
  197890. shape = XC_sb_h_double_arrow;
  197891. break;
  197892. case MouseCursor::UpDownResizeCursor:
  197893. shape = XC_sb_v_double_arrow;
  197894. break;
  197895. case MouseCursor::UpDownLeftRightResizeCursor:
  197896. shape = XC_fleur;
  197897. break;
  197898. case MouseCursor::TopEdgeResizeCursor:
  197899. shape = XC_top_side;
  197900. break;
  197901. case MouseCursor::BottomEdgeResizeCursor:
  197902. shape = XC_bottom_side;
  197903. break;
  197904. case MouseCursor::LeftEdgeResizeCursor:
  197905. shape = XC_left_side;
  197906. break;
  197907. case MouseCursor::RightEdgeResizeCursor:
  197908. shape = XC_right_side;
  197909. break;
  197910. case MouseCursor::TopLeftCornerResizeCursor:
  197911. shape = XC_top_left_corner;
  197912. break;
  197913. case MouseCursor::TopRightCornerResizeCursor:
  197914. shape = XC_top_right_corner;
  197915. break;
  197916. case MouseCursor::BottomLeftCornerResizeCursor:
  197917. shape = XC_bottom_left_corner;
  197918. break;
  197919. case MouseCursor::BottomRightCornerResizeCursor:
  197920. shape = XC_bottom_right_corner;
  197921. break;
  197922. case MouseCursor::CrosshairCursor:
  197923. shape = XC_crosshair;
  197924. break;
  197925. default:
  197926. return (void*) None; // Use parent cursor
  197927. }
  197928. ScopedXLock xlock;
  197929. return (void*) XCreateFontCursor (display, shape);
  197930. }
  197931. void MouseCursor::showInWindow (ComponentPeer* peer) const throw()
  197932. {
  197933. LinuxComponentPeer* const lp = dynamic_cast <LinuxComponentPeer*> (peer);
  197934. if (lp != 0)
  197935. lp->showMouseCursor ((Cursor) getHandle());
  197936. }
  197937. void MouseCursor::showInAllWindows() const throw()
  197938. {
  197939. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  197940. showInWindow (ComponentPeer::getPeer (i));
  197941. }
  197942. Image* juce_createIconForFile (const File& file)
  197943. {
  197944. return 0;
  197945. }
  197946. Image* Image::createNativeImage (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage)
  197947. {
  197948. return new Image (format, imageWidth, imageHeight, clearImage);
  197949. }
  197950. #if JUCE_OPENGL
  197951. class WindowedGLContext : public OpenGLContext
  197952. {
  197953. public:
  197954. WindowedGLContext (Component* const component,
  197955. const OpenGLPixelFormat& pixelFormat_,
  197956. GLXContext sharedContext)
  197957. : renderContext (0),
  197958. embeddedWindow (0),
  197959. pixelFormat (pixelFormat_)
  197960. {
  197961. jassert (component != 0);
  197962. LinuxComponentPeer* const peer = dynamic_cast <LinuxComponentPeer*> (component->getTopLevelComponent()->getPeer());
  197963. if (peer == 0)
  197964. return;
  197965. ScopedXLock xlock;
  197966. XSync (display, False);
  197967. GLint attribs [64];
  197968. int n = 0;
  197969. attribs[n++] = GLX_RGBA;
  197970. attribs[n++] = GLX_DOUBLEBUFFER;
  197971. attribs[n++] = GLX_RED_SIZE;
  197972. attribs[n++] = pixelFormat.redBits;
  197973. attribs[n++] = GLX_GREEN_SIZE;
  197974. attribs[n++] = pixelFormat.greenBits;
  197975. attribs[n++] = GLX_BLUE_SIZE;
  197976. attribs[n++] = pixelFormat.blueBits;
  197977. attribs[n++] = GLX_ALPHA_SIZE;
  197978. attribs[n++] = pixelFormat.alphaBits;
  197979. attribs[n++] = GLX_DEPTH_SIZE;
  197980. attribs[n++] = pixelFormat.depthBufferBits;
  197981. attribs[n++] = GLX_STENCIL_SIZE;
  197982. attribs[n++] = pixelFormat.stencilBufferBits;
  197983. attribs[n++] = GLX_ACCUM_RED_SIZE;
  197984. attribs[n++] = pixelFormat.accumulationBufferRedBits;
  197985. attribs[n++] = GLX_ACCUM_GREEN_SIZE;
  197986. attribs[n++] = pixelFormat.accumulationBufferGreenBits;
  197987. attribs[n++] = GLX_ACCUM_BLUE_SIZE;
  197988. attribs[n++] = pixelFormat.accumulationBufferBlueBits;
  197989. attribs[n++] = GLX_ACCUM_ALPHA_SIZE;
  197990. attribs[n++] = pixelFormat.accumulationBufferAlphaBits;
  197991. // xxx not sure how to do fullSceneAntiAliasingNumSamples on linux..
  197992. attribs[n++] = None;
  197993. XVisualInfo* const bestVisual = glXChooseVisual (display, DefaultScreen (display), attribs);
  197994. if (bestVisual == 0)
  197995. return;
  197996. renderContext = glXCreateContext (display, bestVisual, sharedContext, GL_TRUE);
  197997. Window windowH = (Window) peer->getNativeHandle();
  197998. Colormap colourMap = XCreateColormap (display, windowH, bestVisual->visual, AllocNone);
  197999. XSetWindowAttributes swa;
  198000. swa.colormap = colourMap;
  198001. swa.border_pixel = 0;
  198002. swa.event_mask = ExposureMask | StructureNotifyMask;
  198003. embeddedWindow = XCreateWindow (display, windowH,
  198004. 0, 0, 1, 1, 0,
  198005. bestVisual->depth,
  198006. InputOutput,
  198007. bestVisual->visual,
  198008. CWBorderPixel | CWColormap | CWEventMask,
  198009. &swa);
  198010. XSaveContext (display, (XID) embeddedWindow, improbableNumber, (XPointer) peer);
  198011. XMapWindow (display, embeddedWindow);
  198012. XFreeColormap (display, colourMap);
  198013. XFree (bestVisual);
  198014. XSync (display, False);
  198015. }
  198016. ~WindowedGLContext()
  198017. {
  198018. makeInactive();
  198019. ScopedXLock xlock;
  198020. glXDestroyContext (display, renderContext);
  198021. XUnmapWindow (display, embeddedWindow);
  198022. XDestroyWindow (display, embeddedWindow);
  198023. }
  198024. bool makeActive() const throw()
  198025. {
  198026. jassert (renderContext != 0);
  198027. ScopedXLock xlock;
  198028. return glXMakeCurrent (display, embeddedWindow, renderContext)
  198029. && XSync (display, False);
  198030. }
  198031. bool makeInactive() const throw()
  198032. {
  198033. ScopedXLock xlock;
  198034. return (! isActive()) || glXMakeCurrent (display, None, 0);
  198035. }
  198036. bool isActive() const throw()
  198037. {
  198038. ScopedXLock xlock;
  198039. return glXGetCurrentContext() == renderContext;
  198040. }
  198041. const OpenGLPixelFormat getPixelFormat() const
  198042. {
  198043. return pixelFormat;
  198044. }
  198045. void* getRawContext() const throw()
  198046. {
  198047. return renderContext;
  198048. }
  198049. void updateWindowPosition (int x, int y, int w, int h, int)
  198050. {
  198051. ScopedXLock xlock;
  198052. XMoveResizeWindow (display, embeddedWindow,
  198053. x, y, jmax (1, w), jmax (1, h));
  198054. }
  198055. void swapBuffers()
  198056. {
  198057. ScopedXLock xlock;
  198058. glXSwapBuffers (display, embeddedWindow);
  198059. }
  198060. bool setSwapInterval (const int numFramesPerSwap)
  198061. {
  198062. // xxx needs doing..
  198063. return false;
  198064. }
  198065. int getSwapInterval() const
  198066. {
  198067. // xxx needs doing..
  198068. return 0;
  198069. }
  198070. void repaint()
  198071. {
  198072. }
  198073. juce_UseDebuggingNewOperator
  198074. GLXContext renderContext;
  198075. private:
  198076. Window embeddedWindow;
  198077. OpenGLPixelFormat pixelFormat;
  198078. WindowedGLContext (const WindowedGLContext&);
  198079. const WindowedGLContext& operator= (const WindowedGLContext&);
  198080. };
  198081. OpenGLContext* OpenGLContext::createContextForWindow (Component* const component,
  198082. const OpenGLPixelFormat& pixelFormat,
  198083. const OpenGLContext* const contextToShareWith)
  198084. {
  198085. WindowedGLContext* c = new WindowedGLContext (component, pixelFormat,
  198086. contextToShareWith != 0 ? (GLXContext) contextToShareWith->getRawContext() : 0);
  198087. if (c->renderContext == 0)
  198088. deleteAndZero (c);
  198089. return c;
  198090. }
  198091. void juce_glViewport (const int w, const int h)
  198092. {
  198093. glViewport (0, 0, w, h);
  198094. }
  198095. void OpenGLPixelFormat::getAvailablePixelFormats (Component* component,
  198096. OwnedArray <OpenGLPixelFormat>& results)
  198097. {
  198098. results.add (new OpenGLPixelFormat()); // xxx
  198099. }
  198100. #endif
  198101. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMoveFiles)
  198102. {
  198103. jassertfalse // not implemented!
  198104. return false;
  198105. }
  198106. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  198107. {
  198108. jassertfalse // not implemented!
  198109. return false;
  198110. }
  198111. void SystemTrayIconComponent::setIconImage (const Image& newImage)
  198112. {
  198113. if (! isOnDesktop ())
  198114. addToDesktop (0);
  198115. LinuxComponentPeer* const wp = dynamic_cast <LinuxComponentPeer*> (getPeer());
  198116. if (wp != 0)
  198117. {
  198118. wp->setTaskBarIcon (newImage);
  198119. setVisible (true);
  198120. toFront (false);
  198121. repaint();
  198122. }
  198123. }
  198124. void SystemTrayIconComponent::paint (Graphics& g)
  198125. {
  198126. LinuxComponentPeer* const wp = dynamic_cast <LinuxComponentPeer*> (getPeer());
  198127. if (wp != 0)
  198128. {
  198129. const Image* const image = wp->getTaskbarIcon();
  198130. if (image != 0)
  198131. {
  198132. g.drawImageWithin (image, 0, 0, getWidth(), getHeight(),
  198133. RectanglePlacement::xLeft | RectanglePlacement::yTop | RectanglePlacement::onlyReduceInSize,
  198134. false);
  198135. }
  198136. }
  198137. }
  198138. void SystemTrayIconComponent::setIconTooltip (const String& tooltip)
  198139. {
  198140. // xxx not yet implemented!
  198141. }
  198142. void PlatformUtilities::beep()
  198143. {
  198144. std::cout << "\a" << std::flush;
  198145. }
  198146. bool AlertWindow::showNativeDialogBox (const String& title,
  198147. const String& bodyText,
  198148. bool isOkCancel)
  198149. {
  198150. // xxx this is supposed to pop up an alert!
  198151. Logger::outputDebugString (title + ": " + bodyText);
  198152. // use a non-native one for the time being..
  198153. if (isOkCancel)
  198154. return AlertWindow::showOkCancelBox (AlertWindow::NoIcon, title, bodyText);
  198155. else
  198156. AlertWindow::showMessageBox (AlertWindow::NoIcon, title, bodyText);
  198157. return true;
  198158. }
  198159. const int KeyPress::spaceKey = XK_space & 0xff;
  198160. const int KeyPress::returnKey = XK_Return & 0xff;
  198161. const int KeyPress::escapeKey = XK_Escape & 0xff;
  198162. const int KeyPress::backspaceKey = XK_BackSpace & 0xff;
  198163. const int KeyPress::leftKey = (XK_Left & 0xff) | extendedKeyModifier;
  198164. const int KeyPress::rightKey = (XK_Right & 0xff) | extendedKeyModifier;
  198165. const int KeyPress::upKey = (XK_Up & 0xff) | extendedKeyModifier;
  198166. const int KeyPress::downKey = (XK_Down & 0xff) | extendedKeyModifier;
  198167. const int KeyPress::pageUpKey = (XK_Page_Up & 0xff) | extendedKeyModifier;
  198168. const int KeyPress::pageDownKey = (XK_Page_Down & 0xff) | extendedKeyModifier;
  198169. const int KeyPress::endKey = (XK_End & 0xff) | extendedKeyModifier;
  198170. const int KeyPress::homeKey = (XK_Home & 0xff) | extendedKeyModifier;
  198171. const int KeyPress::insertKey = (XK_Insert & 0xff) | extendedKeyModifier;
  198172. const int KeyPress::deleteKey = (XK_Delete & 0xff) | extendedKeyModifier;
  198173. const int KeyPress::tabKey = XK_Tab & 0xff;
  198174. const int KeyPress::F1Key = (XK_F1 & 0xff) | extendedKeyModifier;
  198175. const int KeyPress::F2Key = (XK_F2 & 0xff) | extendedKeyModifier;
  198176. const int KeyPress::F3Key = (XK_F3 & 0xff) | extendedKeyModifier;
  198177. const int KeyPress::F4Key = (XK_F4 & 0xff) | extendedKeyModifier;
  198178. const int KeyPress::F5Key = (XK_F5 & 0xff) | extendedKeyModifier;
  198179. const int KeyPress::F6Key = (XK_F6 & 0xff) | extendedKeyModifier;
  198180. const int KeyPress::F7Key = (XK_F7 & 0xff) | extendedKeyModifier;
  198181. const int KeyPress::F8Key = (XK_F8 & 0xff) | extendedKeyModifier;
  198182. const int KeyPress::F9Key = (XK_F9 & 0xff) | extendedKeyModifier;
  198183. const int KeyPress::F10Key = (XK_F10 & 0xff) | extendedKeyModifier;
  198184. const int KeyPress::F11Key = (XK_F11 & 0xff) | extendedKeyModifier;
  198185. const int KeyPress::F12Key = (XK_F12 & 0xff) | extendedKeyModifier;
  198186. const int KeyPress::F13Key = (XK_F13 & 0xff) | extendedKeyModifier;
  198187. const int KeyPress::F14Key = (XK_F14 & 0xff) | extendedKeyModifier;
  198188. const int KeyPress::F15Key = (XK_F15 & 0xff) | extendedKeyModifier;
  198189. const int KeyPress::F16Key = (XK_F16 & 0xff) | extendedKeyModifier;
  198190. const int KeyPress::numberPad0 = (XK_KP_0 & 0xff) | extendedKeyModifier;
  198191. const int KeyPress::numberPad1 = (XK_KP_1 & 0xff) | extendedKeyModifier;
  198192. const int KeyPress::numberPad2 = (XK_KP_2 & 0xff) | extendedKeyModifier;
  198193. const int KeyPress::numberPad3 = (XK_KP_3 & 0xff) | extendedKeyModifier;
  198194. const int KeyPress::numberPad4 = (XK_KP_4 & 0xff) | extendedKeyModifier;
  198195. const int KeyPress::numberPad5 = (XK_KP_5 & 0xff) | extendedKeyModifier;
  198196. const int KeyPress::numberPad6 = (XK_KP_6 & 0xff) | extendedKeyModifier;
  198197. const int KeyPress::numberPad7 = (XK_KP_7 & 0xff)| extendedKeyModifier;
  198198. const int KeyPress::numberPad8 = (XK_KP_8 & 0xff)| extendedKeyModifier;
  198199. const int KeyPress::numberPad9 = (XK_KP_9 & 0xff)| extendedKeyModifier;
  198200. const int KeyPress::numberPadAdd = (XK_KP_Add & 0xff)| extendedKeyModifier;
  198201. const int KeyPress::numberPadSubtract = (XK_KP_Subtract & 0xff)| extendedKeyModifier;
  198202. const int KeyPress::numberPadMultiply = (XK_KP_Multiply & 0xff)| extendedKeyModifier;
  198203. const int KeyPress::numberPadDivide = (XK_KP_Divide & 0xff)| extendedKeyModifier;
  198204. const int KeyPress::numberPadSeparator = (XK_KP_Separator & 0xff)| extendedKeyModifier;
  198205. const int KeyPress::numberPadDecimalPoint = (XK_KP_Decimal & 0xff)| extendedKeyModifier;
  198206. const int KeyPress::numberPadEquals = (XK_KP_Equal & 0xff)| extendedKeyModifier;
  198207. const int KeyPress::numberPadDelete = (XK_KP_Delete & 0xff)| extendedKeyModifier;
  198208. const int KeyPress::playKey = (0xffeeff00) | extendedKeyModifier;
  198209. const int KeyPress::stopKey = (0xffeeff01) | extendedKeyModifier;
  198210. const int KeyPress::fastForwardKey = (0xffeeff02) | extendedKeyModifier;
  198211. const int KeyPress::rewindKey = (0xffeeff03) | extendedKeyModifier;
  198212. #endif
  198213. /*** End of inlined file: juce_linux_Windowing.cpp ***/
  198214. /*** Start of inlined file: juce_linux_Audio.cpp ***/
  198215. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  198216. // compiled on its own).
  198217. #if JUCE_INCLUDED_FILE && JUCE_ALSA
  198218. static const int maxNumChans = 64;
  198219. static void getDeviceSampleRates (snd_pcm_t* handle, Array <int>& rates)
  198220. {
  198221. const int ratesToTry[] = { 22050, 32000, 44100, 48000, 88200, 96000, 176400, 192000, 0 };
  198222. snd_pcm_hw_params_t* hwParams;
  198223. snd_pcm_hw_params_alloca (&hwParams);
  198224. for (int i = 0; ratesToTry[i] != 0; ++i)
  198225. {
  198226. if (snd_pcm_hw_params_any (handle, hwParams) >= 0
  198227. && snd_pcm_hw_params_test_rate (handle, hwParams, ratesToTry[i], 0) == 0)
  198228. {
  198229. rates.addIfNotAlreadyThere (ratesToTry[i]);
  198230. }
  198231. }
  198232. }
  198233. static void getDeviceNumChannels (snd_pcm_t* handle, unsigned int* minChans, unsigned int* maxChans)
  198234. {
  198235. snd_pcm_hw_params_t *params;
  198236. snd_pcm_hw_params_alloca (&params);
  198237. if (snd_pcm_hw_params_any (handle, params) >= 0)
  198238. {
  198239. snd_pcm_hw_params_get_channels_min (params, minChans);
  198240. snd_pcm_hw_params_get_channels_max (params, maxChans);
  198241. }
  198242. }
  198243. static void getDeviceProperties (const String& id,
  198244. unsigned int& minChansOut,
  198245. unsigned int& maxChansOut,
  198246. unsigned int& minChansIn,
  198247. unsigned int& maxChansIn,
  198248. Array <int>& rates)
  198249. {
  198250. if (id.isEmpty())
  198251. return;
  198252. snd_ctl_t* handle;
  198253. if (snd_ctl_open (&handle, id.upToLastOccurrenceOf (T(","), false, false), SND_CTL_NONBLOCK) >= 0)
  198254. {
  198255. snd_pcm_info_t* info;
  198256. snd_pcm_info_alloca (&info);
  198257. snd_pcm_info_set_stream (info, SND_PCM_STREAM_PLAYBACK);
  198258. snd_pcm_info_set_device (info, id.fromLastOccurrenceOf (T(","), false, false).getIntValue());
  198259. snd_pcm_info_set_subdevice (info, 0);
  198260. if (snd_ctl_pcm_info (handle, info) >= 0)
  198261. {
  198262. snd_pcm_t* pcmHandle;
  198263. if (snd_pcm_open (&pcmHandle, id, SND_PCM_STREAM_PLAYBACK, SND_PCM_ASYNC | SND_PCM_NONBLOCK ) >= 0)
  198264. {
  198265. getDeviceNumChannels (pcmHandle, &minChansOut, &maxChansOut);
  198266. getDeviceSampleRates (pcmHandle, rates);
  198267. snd_pcm_close (pcmHandle);
  198268. }
  198269. }
  198270. snd_pcm_info_set_stream (info, SND_PCM_STREAM_CAPTURE);
  198271. if (snd_ctl_pcm_info (handle, info) >= 0)
  198272. {
  198273. snd_pcm_t* pcmHandle;
  198274. if (snd_pcm_open (&pcmHandle, id, SND_PCM_STREAM_CAPTURE, SND_PCM_ASYNC | SND_PCM_NONBLOCK ) >= 0)
  198275. {
  198276. getDeviceNumChannels (pcmHandle, &minChansIn, &maxChansIn);
  198277. if (rates.size() == 0)
  198278. getDeviceSampleRates (pcmHandle, rates);
  198279. snd_pcm_close (pcmHandle);
  198280. }
  198281. }
  198282. snd_ctl_close (handle);
  198283. }
  198284. }
  198285. class ALSADevice
  198286. {
  198287. public:
  198288. ALSADevice (const String& id,
  198289. const bool forInput)
  198290. : handle (0),
  198291. bitDepth (16),
  198292. numChannelsRunning (0),
  198293. isInput (forInput),
  198294. sampleFormat (AudioDataConverters::int16LE)
  198295. {
  198296. failed (snd_pcm_open (&handle, id,
  198297. forInput ? SND_PCM_STREAM_CAPTURE : SND_PCM_STREAM_PLAYBACK,
  198298. SND_PCM_ASYNC));
  198299. }
  198300. ~ALSADevice()
  198301. {
  198302. if (handle != 0)
  198303. snd_pcm_close (handle);
  198304. }
  198305. bool setParameters (unsigned int sampleRate, int numChannels, int bufferSize)
  198306. {
  198307. if (handle == 0)
  198308. return false;
  198309. snd_pcm_hw_params_t* hwParams;
  198310. snd_pcm_hw_params_alloca (&hwParams);
  198311. if (failed (snd_pcm_hw_params_any (handle, hwParams)))
  198312. return false;
  198313. if (snd_pcm_hw_params_set_access (handle, hwParams, SND_PCM_ACCESS_RW_NONINTERLEAVED) >= 0)
  198314. isInterleaved = false;
  198315. else if (snd_pcm_hw_params_set_access (handle, hwParams, SND_PCM_ACCESS_RW_INTERLEAVED) >= 0)
  198316. isInterleaved = true;
  198317. else
  198318. {
  198319. jassertfalse
  198320. return false;
  198321. }
  198322. const int formatsToTry[] = { SND_PCM_FORMAT_FLOAT_LE, 32, AudioDataConverters::float32LE,
  198323. SND_PCM_FORMAT_FLOAT_BE, 32, AudioDataConverters::float32BE,
  198324. SND_PCM_FORMAT_S32_LE, 32, AudioDataConverters::int32LE,
  198325. SND_PCM_FORMAT_S32_BE, 32, AudioDataConverters::int32BE,
  198326. SND_PCM_FORMAT_S24_3LE, 24, AudioDataConverters::int24LE,
  198327. SND_PCM_FORMAT_S24_3BE, 24, AudioDataConverters::int24BE,
  198328. SND_PCM_FORMAT_S16_LE, 16, AudioDataConverters::int16LE,
  198329. SND_PCM_FORMAT_S16_BE, 16, AudioDataConverters::int16BE };
  198330. bitDepth = 0;
  198331. for (int i = 0; i < numElementsInArray (formatsToTry); i += 3)
  198332. {
  198333. if (snd_pcm_hw_params_set_format (handle, hwParams, (_snd_pcm_format) formatsToTry [i]) >= 0)
  198334. {
  198335. bitDepth = formatsToTry [i + 1];
  198336. sampleFormat = (AudioDataConverters::DataFormat) formatsToTry [i + 2];
  198337. break;
  198338. }
  198339. }
  198340. if (bitDepth == 0)
  198341. {
  198342. error = "device doesn't support a compatible PCM format";
  198343. DBG (T("ALSA error: ") + error + T("\n"));
  198344. return false;
  198345. }
  198346. int dir = 0;
  198347. unsigned int periods = 4;
  198348. snd_pcm_uframes_t samplesPerPeriod = bufferSize;
  198349. if (failed (snd_pcm_hw_params_set_rate_near (handle, hwParams, &sampleRate, 0))
  198350. || failed (snd_pcm_hw_params_set_channels (handle, hwParams, numChannels))
  198351. || failed (snd_pcm_hw_params_set_periods_near (handle, hwParams, &periods, &dir))
  198352. || failed (snd_pcm_hw_params_set_period_size_near (handle, hwParams, &samplesPerPeriod, &dir))
  198353. || failed (snd_pcm_hw_params (handle, hwParams)))
  198354. {
  198355. return false;
  198356. }
  198357. snd_pcm_sw_params_t* swParams;
  198358. snd_pcm_sw_params_alloca (&swParams);
  198359. snd_pcm_uframes_t boundary;
  198360. if (failed (snd_pcm_sw_params_current (handle, swParams))
  198361. || failed (snd_pcm_sw_params_get_boundary (swParams, &boundary))
  198362. || failed (snd_pcm_sw_params_set_silence_threshold (handle, swParams, 0))
  198363. || failed (snd_pcm_sw_params_set_silence_size (handle, swParams, boundary))
  198364. || failed (snd_pcm_sw_params_set_start_threshold (handle, swParams, samplesPerPeriod))
  198365. || failed (snd_pcm_sw_params_set_stop_threshold (handle, swParams, boundary))
  198366. || failed (snd_pcm_sw_params (handle, swParams)))
  198367. {
  198368. return false;
  198369. }
  198370. numChannelsRunning = numChannels;
  198371. return true;
  198372. }
  198373. bool write (float** const data, const int numSamples)
  198374. {
  198375. if (isInterleaved)
  198376. {
  198377. scratch.ensureSize (sizeof (float) * numSamples * numChannelsRunning, false);
  198378. float* interleaved = (float*) scratch;
  198379. AudioDataConverters::interleaveSamples ((const float**) data, interleaved, numSamples, numChannelsRunning);
  198380. AudioDataConverters::convertFloatToFormat (sampleFormat, interleaved, interleaved, numSamples * numChannelsRunning);
  198381. snd_pcm_sframes_t num = snd_pcm_writei (handle, (void*) interleaved, numSamples);
  198382. if (failed (num) && num != -EPIPE && num != -ESTRPIPE)
  198383. return false;
  198384. }
  198385. else
  198386. {
  198387. for (int i = 0; i < numChannelsRunning; ++i)
  198388. if (data[i] != 0)
  198389. AudioDataConverters::convertFloatToFormat (sampleFormat, data[i], data[i], numSamples);
  198390. snd_pcm_sframes_t num = snd_pcm_writen (handle, (void**) data, numSamples);
  198391. if (failed (num))
  198392. {
  198393. if (num == -EPIPE)
  198394. {
  198395. if (failed (snd_pcm_prepare (handle)))
  198396. return false;
  198397. }
  198398. else if (num != -ESTRPIPE)
  198399. return false;
  198400. }
  198401. }
  198402. return true;
  198403. }
  198404. bool read (float** const data, const int numSamples)
  198405. {
  198406. if (isInterleaved)
  198407. {
  198408. scratch.ensureSize (sizeof (float) * numSamples * numChannelsRunning, false);
  198409. float* interleaved = (float*) scratch;
  198410. snd_pcm_sframes_t num = snd_pcm_readi (handle, (void*) interleaved, numSamples);
  198411. if (failed (num))
  198412. {
  198413. if (num == -EPIPE)
  198414. {
  198415. if (failed (snd_pcm_prepare (handle)))
  198416. return false;
  198417. }
  198418. else if (num != -ESTRPIPE)
  198419. return false;
  198420. }
  198421. AudioDataConverters::convertFormatToFloat (sampleFormat, interleaved, interleaved, numSamples * numChannelsRunning);
  198422. AudioDataConverters::deinterleaveSamples (interleaved, data, numSamples, numChannelsRunning);
  198423. }
  198424. else
  198425. {
  198426. snd_pcm_sframes_t num = snd_pcm_readn (handle, (void**) data, numSamples);
  198427. if (failed (num) && num != -EPIPE && num != -ESTRPIPE)
  198428. return false;
  198429. for (int i = 0; i < numChannelsRunning; ++i)
  198430. if (data[i] != 0)
  198431. AudioDataConverters::convertFormatToFloat (sampleFormat, data[i], data[i], numSamples);
  198432. }
  198433. return true;
  198434. }
  198435. juce_UseDebuggingNewOperator
  198436. snd_pcm_t* handle;
  198437. String error;
  198438. int bitDepth, numChannelsRunning;
  198439. private:
  198440. const bool isInput;
  198441. bool isInterleaved;
  198442. MemoryBlock scratch;
  198443. AudioDataConverters::DataFormat sampleFormat;
  198444. bool failed (const int errorNum)
  198445. {
  198446. if (errorNum >= 0)
  198447. return false;
  198448. error = snd_strerror (errorNum);
  198449. DBG (T("ALSA error: ") + error + T("\n"));
  198450. return true;
  198451. }
  198452. };
  198453. class ALSAThread : public Thread
  198454. {
  198455. public:
  198456. ALSAThread (const String& inputId_,
  198457. const String& outputId_)
  198458. : Thread ("Juce ALSA"),
  198459. sampleRate (0),
  198460. bufferSize (0),
  198461. callback (0),
  198462. inputId (inputId_),
  198463. outputId (outputId_),
  198464. outputDevice (0),
  198465. inputDevice (0),
  198466. numCallbacks (0),
  198467. totalNumInputChannels (0),
  198468. totalNumOutputChannels (0)
  198469. {
  198470. zeromem (outputChannelData, sizeof (outputChannelData));
  198471. zeromem (outputChannelDataForCallback, sizeof (outputChannelDataForCallback));
  198472. zeromem (inputChannelData, sizeof (inputChannelData));
  198473. zeromem (inputChannelDataForCallback, sizeof (inputChannelDataForCallback));
  198474. initialiseRatesAndChannels();
  198475. }
  198476. ~ALSAThread()
  198477. {
  198478. close();
  198479. }
  198480. void open (BitArray inputChannels,
  198481. BitArray outputChannels,
  198482. const double sampleRate_,
  198483. const int bufferSize_)
  198484. {
  198485. close();
  198486. error = String::empty;
  198487. sampleRate = sampleRate_;
  198488. bufferSize = bufferSize_;
  198489. currentInputChans.clear();
  198490. currentOutputChans.clear();
  198491. if (inputChannels.getHighestBit() >= 0)
  198492. {
  198493. for (int i = 0; i <= jmax (inputChannels.getHighestBit(), (int) minChansIn); ++i)
  198494. {
  198495. inputChannelData [i] = (float*) juce_calloc (sizeof (float) * bufferSize);
  198496. if (inputChannels[i])
  198497. {
  198498. inputChannelDataForCallback [totalNumInputChannels++] = inputChannelData [i];
  198499. currentInputChans.setBit (i);
  198500. }
  198501. }
  198502. }
  198503. if (outputChannels.getHighestBit() >= 0)
  198504. {
  198505. for (int i = 0; i <= jmax (outputChannels.getHighestBit(), (int) minChansOut); ++i)
  198506. {
  198507. outputChannelData [i] = (float*) juce_calloc (sizeof (float) * bufferSize);
  198508. if (outputChannels[i])
  198509. {
  198510. outputChannelDataForCallback [totalNumOutputChannels++] = outputChannelData [i];
  198511. currentOutputChans.setBit (i);
  198512. }
  198513. }
  198514. }
  198515. if (totalNumOutputChannels > 0 && outputId.isNotEmpty())
  198516. {
  198517. outputDevice = new ALSADevice (outputId, false);
  198518. if (outputDevice->error.isNotEmpty())
  198519. {
  198520. error = outputDevice->error;
  198521. deleteAndZero (outputDevice);
  198522. return;
  198523. }
  198524. currentOutputChans.setRange (0, minChansOut, true);
  198525. if (! outputDevice->setParameters ((unsigned int) sampleRate,
  198526. jlimit ((int) minChansOut, (int) maxChansOut, currentOutputChans.getHighestBit() + 1),
  198527. bufferSize))
  198528. {
  198529. error = outputDevice->error;
  198530. deleteAndZero (outputDevice);
  198531. return;
  198532. }
  198533. }
  198534. if (totalNumInputChannels > 0 && inputId.isNotEmpty())
  198535. {
  198536. inputDevice = new ALSADevice (inputId, true);
  198537. if (inputDevice->error.isNotEmpty())
  198538. {
  198539. error = inputDevice->error;
  198540. deleteAndZero (inputDevice);
  198541. return;
  198542. }
  198543. currentInputChans.setRange (0, minChansIn, true);
  198544. if (! inputDevice->setParameters ((unsigned int) sampleRate,
  198545. jlimit ((int) minChansIn, (int) maxChansIn, currentInputChans.getHighestBit() + 1),
  198546. bufferSize))
  198547. {
  198548. error = inputDevice->error;
  198549. deleteAndZero (inputDevice);
  198550. return;
  198551. }
  198552. }
  198553. if (outputDevice == 0 && inputDevice == 0)
  198554. {
  198555. error = "no channels";
  198556. return;
  198557. }
  198558. if (outputDevice != 0 && inputDevice != 0)
  198559. {
  198560. snd_pcm_link (outputDevice->handle, inputDevice->handle);
  198561. }
  198562. if (inputDevice != 0 && failed (snd_pcm_prepare (inputDevice->handle)))
  198563. return;
  198564. if (outputDevice != 0 && failed (snd_pcm_prepare (outputDevice->handle)))
  198565. return;
  198566. startThread (9);
  198567. int count = 1000;
  198568. while (numCallbacks == 0)
  198569. {
  198570. sleep (5);
  198571. if (--count < 0 || ! isThreadRunning())
  198572. {
  198573. error = "device didn't start";
  198574. break;
  198575. }
  198576. }
  198577. }
  198578. void close()
  198579. {
  198580. stopThread (6000);
  198581. deleteAndZero (inputDevice);
  198582. deleteAndZero (outputDevice);
  198583. for (int i = 0; i < maxNumChans; ++i)
  198584. {
  198585. juce_free (inputChannelData [i]);
  198586. juce_free (outputChannelData [i]);
  198587. }
  198588. zeromem (outputChannelData, sizeof (outputChannelData));
  198589. zeromem (outputChannelDataForCallback, sizeof (outputChannelDataForCallback));
  198590. zeromem (inputChannelData, sizeof (inputChannelData));
  198591. zeromem (inputChannelDataForCallback, sizeof (inputChannelDataForCallback));
  198592. totalNumOutputChannels = 0;
  198593. totalNumInputChannels = 0;
  198594. numCallbacks = 0;
  198595. }
  198596. void setCallback (AudioIODeviceCallback* const newCallback) throw()
  198597. {
  198598. const ScopedLock sl (callbackLock);
  198599. callback = newCallback;
  198600. }
  198601. void run()
  198602. {
  198603. while (! threadShouldExit())
  198604. {
  198605. if (inputDevice != 0)
  198606. {
  198607. if (! inputDevice->read (inputChannelData, bufferSize))
  198608. {
  198609. DBG ("ALSA: read failure");
  198610. break;
  198611. }
  198612. }
  198613. if (threadShouldExit())
  198614. break;
  198615. {
  198616. const ScopedLock sl (callbackLock);
  198617. ++numCallbacks;
  198618. if (callback != 0)
  198619. {
  198620. callback->audioDeviceIOCallback ((const float**) inputChannelDataForCallback,
  198621. totalNumInputChannels,
  198622. outputChannelDataForCallback,
  198623. totalNumOutputChannels,
  198624. bufferSize);
  198625. }
  198626. else
  198627. {
  198628. for (int i = 0; i < totalNumOutputChannels; ++i)
  198629. zeromem (outputChannelDataForCallback[i], sizeof (float) * bufferSize);
  198630. }
  198631. }
  198632. if (outputDevice != 0)
  198633. {
  198634. failed (snd_pcm_wait (outputDevice->handle, 2000));
  198635. if (threadShouldExit())
  198636. break;
  198637. failed (snd_pcm_avail_update (outputDevice->handle));
  198638. if (! outputDevice->write (outputChannelData, bufferSize))
  198639. {
  198640. DBG ("ALSA: write failure");
  198641. break;
  198642. }
  198643. }
  198644. }
  198645. }
  198646. int getBitDepth() const throw()
  198647. {
  198648. if (outputDevice != 0)
  198649. return outputDevice->bitDepth;
  198650. if (inputDevice != 0)
  198651. return inputDevice->bitDepth;
  198652. return 16;
  198653. }
  198654. juce_UseDebuggingNewOperator
  198655. String error;
  198656. double sampleRate;
  198657. int bufferSize;
  198658. BitArray currentInputChans, currentOutputChans;
  198659. Array <int> sampleRates;
  198660. StringArray channelNamesOut, channelNamesIn;
  198661. AudioIODeviceCallback* callback;
  198662. private:
  198663. const String inputId, outputId;
  198664. ALSADevice* outputDevice;
  198665. ALSADevice* inputDevice;
  198666. int numCallbacks;
  198667. CriticalSection callbackLock;
  198668. float* outputChannelData [maxNumChans];
  198669. float* outputChannelDataForCallback [maxNumChans];
  198670. int totalNumInputChannels;
  198671. float* inputChannelData [maxNumChans];
  198672. float* inputChannelDataForCallback [maxNumChans];
  198673. int totalNumOutputChannels;
  198674. unsigned int minChansOut, maxChansOut;
  198675. unsigned int minChansIn, maxChansIn;
  198676. bool failed (const int errorNum) throw()
  198677. {
  198678. if (errorNum >= 0)
  198679. return false;
  198680. error = snd_strerror (errorNum);
  198681. DBG (T("ALSA error: ") + error + T("\n"));
  198682. return true;
  198683. }
  198684. void initialiseRatesAndChannels() throw()
  198685. {
  198686. sampleRates.clear();
  198687. channelNamesOut.clear();
  198688. channelNamesIn.clear();
  198689. minChansOut = 0;
  198690. maxChansOut = 0;
  198691. minChansIn = 0;
  198692. maxChansIn = 0;
  198693. unsigned int dummy = 0;
  198694. getDeviceProperties (inputId, dummy, dummy, minChansIn, maxChansIn, sampleRates);
  198695. getDeviceProperties (outputId, minChansOut, maxChansOut, dummy, dummy, sampleRates);
  198696. unsigned int i;
  198697. for (i = 0; i < maxChansOut; ++i)
  198698. channelNamesOut.add (T("channel ") + String ((int) i + 1));
  198699. for (i = 0; i < maxChansIn; ++i)
  198700. channelNamesIn.add (T("channel ") + String ((int) i + 1));
  198701. }
  198702. };
  198703. class ALSAAudioIODevice : public AudioIODevice
  198704. {
  198705. public:
  198706. ALSAAudioIODevice (const String& deviceName,
  198707. const String& inputId_,
  198708. const String& outputId_)
  198709. : AudioIODevice (deviceName, T("ALSA")),
  198710. inputId (inputId_),
  198711. outputId (outputId_),
  198712. isOpen_ (false),
  198713. isStarted (false),
  198714. internal (0)
  198715. {
  198716. internal = new ALSAThread (inputId, outputId);
  198717. }
  198718. ~ALSAAudioIODevice()
  198719. {
  198720. delete internal;
  198721. }
  198722. const StringArray getOutputChannelNames()
  198723. {
  198724. return internal->channelNamesOut;
  198725. }
  198726. const StringArray getInputChannelNames()
  198727. {
  198728. return internal->channelNamesIn;
  198729. }
  198730. int getNumSampleRates()
  198731. {
  198732. return internal->sampleRates.size();
  198733. }
  198734. double getSampleRate (int index)
  198735. {
  198736. return internal->sampleRates [index];
  198737. }
  198738. int getNumBufferSizesAvailable()
  198739. {
  198740. return 50;
  198741. }
  198742. int getBufferSizeSamples (int index)
  198743. {
  198744. int n = 16;
  198745. for (int i = 0; i < index; ++i)
  198746. n += n < 64 ? 16
  198747. : (n < 512 ? 32
  198748. : (n < 1024 ? 64
  198749. : (n < 2048 ? 128 : 256)));
  198750. return n;
  198751. }
  198752. int getDefaultBufferSize()
  198753. {
  198754. return 512;
  198755. }
  198756. const String open (const BitArray& inputChannels,
  198757. const BitArray& outputChannels,
  198758. double sampleRate,
  198759. int bufferSizeSamples)
  198760. {
  198761. close();
  198762. if (bufferSizeSamples <= 0)
  198763. bufferSizeSamples = getDefaultBufferSize();
  198764. if (sampleRate <= 0)
  198765. {
  198766. for (int i = 0; i < getNumSampleRates(); ++i)
  198767. {
  198768. if (getSampleRate (i) >= 44100)
  198769. {
  198770. sampleRate = getSampleRate (i);
  198771. break;
  198772. }
  198773. }
  198774. }
  198775. internal->open (inputChannels, outputChannels,
  198776. sampleRate, bufferSizeSamples);
  198777. isOpen_ = internal->error.isEmpty();
  198778. return internal->error;
  198779. }
  198780. void close()
  198781. {
  198782. stop();
  198783. internal->close();
  198784. isOpen_ = false;
  198785. }
  198786. bool isOpen()
  198787. {
  198788. return isOpen_;
  198789. }
  198790. int getCurrentBufferSizeSamples()
  198791. {
  198792. return internal->bufferSize;
  198793. }
  198794. double getCurrentSampleRate()
  198795. {
  198796. return internal->sampleRate;
  198797. }
  198798. int getCurrentBitDepth()
  198799. {
  198800. return internal->getBitDepth();
  198801. }
  198802. const BitArray getActiveOutputChannels() const
  198803. {
  198804. return internal->currentOutputChans;
  198805. }
  198806. const BitArray getActiveInputChannels() const
  198807. {
  198808. return internal->currentInputChans;
  198809. }
  198810. int getOutputLatencyInSamples()
  198811. {
  198812. return 0;
  198813. }
  198814. int getInputLatencyInSamples()
  198815. {
  198816. return 0;
  198817. }
  198818. void start (AudioIODeviceCallback* callback)
  198819. {
  198820. if (! isOpen_)
  198821. callback = 0;
  198822. internal->setCallback (callback);
  198823. if (callback != 0)
  198824. callback->audioDeviceAboutToStart (this);
  198825. isStarted = (callback != 0);
  198826. }
  198827. void stop()
  198828. {
  198829. AudioIODeviceCallback* const oldCallback = internal->callback;
  198830. start (0);
  198831. if (oldCallback != 0)
  198832. oldCallback->audioDeviceStopped();
  198833. }
  198834. bool isPlaying()
  198835. {
  198836. return isStarted && internal->error.isEmpty();
  198837. }
  198838. const String getLastError()
  198839. {
  198840. return internal->error;
  198841. }
  198842. String inputId, outputId;
  198843. private:
  198844. bool isOpen_, isStarted;
  198845. ALSAThread* internal;
  198846. };
  198847. class ALSAAudioIODeviceType : public AudioIODeviceType
  198848. {
  198849. public:
  198850. ALSAAudioIODeviceType()
  198851. : AudioIODeviceType (T("ALSA")),
  198852. hasScanned (false)
  198853. {
  198854. }
  198855. ~ALSAAudioIODeviceType()
  198856. {
  198857. }
  198858. void scanForDevices()
  198859. {
  198860. if (hasScanned)
  198861. return;
  198862. hasScanned = true;
  198863. inputNames.clear();
  198864. inputIds.clear();
  198865. outputNames.clear();
  198866. outputIds.clear();
  198867. snd_ctl_t* handle;
  198868. snd_ctl_card_info_t* info;
  198869. snd_ctl_card_info_alloca (&info);
  198870. int cardNum = -1;
  198871. while (outputIds.size() + inputIds.size() <= 32)
  198872. {
  198873. snd_card_next (&cardNum);
  198874. if (cardNum < 0)
  198875. break;
  198876. if (snd_ctl_open (&handle, T("hw:") + String (cardNum), SND_CTL_NONBLOCK) >= 0)
  198877. {
  198878. if (snd_ctl_card_info (handle, info) >= 0)
  198879. {
  198880. String cardId (snd_ctl_card_info_get_id (info));
  198881. if (cardId.removeCharacters (T("0123456789")).isEmpty())
  198882. cardId = String (cardNum);
  198883. int device = -1;
  198884. for (;;)
  198885. {
  198886. if (snd_ctl_pcm_next_device (handle, &device) < 0 || device < 0)
  198887. break;
  198888. String id, name;
  198889. id << "hw:" << cardId << ',' << device;
  198890. bool isInput, isOutput;
  198891. if (testDevice (id, isInput, isOutput))
  198892. {
  198893. name << snd_ctl_card_info_get_name (info);
  198894. if (name.isEmpty())
  198895. name = id;
  198896. if (isInput)
  198897. {
  198898. inputNames.add (name);
  198899. inputIds.add (id);
  198900. }
  198901. if (isOutput)
  198902. {
  198903. outputNames.add (name);
  198904. outputIds.add (id);
  198905. }
  198906. }
  198907. }
  198908. }
  198909. snd_ctl_close (handle);
  198910. }
  198911. }
  198912. inputNames.appendNumbersToDuplicates (false, true);
  198913. outputNames.appendNumbersToDuplicates (false, true);
  198914. }
  198915. const StringArray getDeviceNames (const bool wantInputNames) const
  198916. {
  198917. jassert (hasScanned); // need to call scanForDevices() before doing this
  198918. return wantInputNames ? inputNames : outputNames;
  198919. }
  198920. int getDefaultDeviceIndex (const bool forInput) const
  198921. {
  198922. jassert (hasScanned); // need to call scanForDevices() before doing this
  198923. return 0;
  198924. }
  198925. bool hasSeparateInputsAndOutputs() const { return true; }
  198926. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  198927. {
  198928. jassert (hasScanned); // need to call scanForDevices() before doing this
  198929. ALSAAudioIODevice* const d = dynamic_cast <ALSAAudioIODevice*> (device);
  198930. if (d == 0)
  198931. return -1;
  198932. return asInput ? inputIds.indexOf (d->inputId)
  198933. : outputIds.indexOf (d->outputId);
  198934. }
  198935. AudioIODevice* createDevice (const String& outputDeviceName,
  198936. const String& inputDeviceName)
  198937. {
  198938. jassert (hasScanned); // need to call scanForDevices() before doing this
  198939. const int inputIndex = inputNames.indexOf (inputDeviceName);
  198940. const int outputIndex = outputNames.indexOf (outputDeviceName);
  198941. String deviceName (outputIndex >= 0 ? outputDeviceName
  198942. : inputDeviceName);
  198943. if (inputIndex >= 0 || outputIndex >= 0)
  198944. return new ALSAAudioIODevice (deviceName,
  198945. inputIds [inputIndex],
  198946. outputIds [outputIndex]);
  198947. return 0;
  198948. }
  198949. juce_UseDebuggingNewOperator
  198950. private:
  198951. StringArray inputNames, outputNames, inputIds, outputIds;
  198952. bool hasScanned;
  198953. static bool testDevice (const String& id, bool& isInput, bool& isOutput)
  198954. {
  198955. unsigned int minChansOut = 0, maxChansOut = 0;
  198956. unsigned int minChansIn = 0, maxChansIn = 0;
  198957. Array <int> rates;
  198958. getDeviceProperties (id, minChansOut, maxChansOut, minChansIn, maxChansIn, rates);
  198959. DBG (T("ALSA device: ") + id
  198960. + T(" outs=") + String ((int) minChansOut) + T("-") + String ((int) maxChansOut)
  198961. + T(" ins=") + String ((int) minChansIn) + T("-") + String ((int) maxChansIn)
  198962. + T(" rates=") + String (rates.size()));
  198963. isInput = maxChansIn > 0;
  198964. isOutput = maxChansOut > 0;
  198965. return (isInput || isOutput) && rates.size() > 0;
  198966. }
  198967. ALSAAudioIODeviceType (const ALSAAudioIODeviceType&);
  198968. const ALSAAudioIODeviceType& operator= (const ALSAAudioIODeviceType&);
  198969. };
  198970. AudioIODeviceType* juce_createAudioIODeviceType_ALSA()
  198971. {
  198972. return new ALSAAudioIODeviceType();
  198973. }
  198974. #endif
  198975. /*** End of inlined file: juce_linux_Audio.cpp ***/
  198976. /*** Start of inlined file: juce_linux_JackAudio.cpp ***/
  198977. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  198978. // compiled on its own).
  198979. #ifdef JUCE_INCLUDED_FILE
  198980. #if JUCE_JACK
  198981. static void* juce_libjack_handle = 0;
  198982. void* juce_load_jack_function (const char* const name)
  198983. {
  198984. if (juce_libjack_handle == 0)
  198985. return 0;
  198986. return dlsym (juce_libjack_handle, name);
  198987. }
  198988. #define JUCE_DECL_JACK_FUNCTION(return_type, fn_name, argument_types, arguments) \
  198989. typedef return_type (*fn_name##_ptr_t)argument_types; \
  198990. return_type fn_name argument_types { \
  198991. static fn_name##_ptr_t fn = 0; \
  198992. if (fn == 0) { fn = (fn_name##_ptr_t)juce_load_jack_function(#fn_name); } \
  198993. if (fn) return (*fn)arguments; \
  198994. else return 0; \
  198995. }
  198996. #define JUCE_DECL_VOID_JACK_FUNCTION(fn_name, argument_types, arguments) \
  198997. typedef void (*fn_name##_ptr_t)argument_types; \
  198998. void fn_name argument_types { \
  198999. static fn_name##_ptr_t fn = 0; \
  199000. if (fn == 0) { fn = (fn_name##_ptr_t)juce_load_jack_function(#fn_name); } \
  199001. if (fn) (*fn)arguments; \
  199002. }
  199003. 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));
  199004. JUCE_DECL_JACK_FUNCTION (int, jack_client_close, (jack_client_t *client), (client));
  199005. JUCE_DECL_JACK_FUNCTION (int, jack_activate, (jack_client_t* client), (client));
  199006. JUCE_DECL_JACK_FUNCTION (int, jack_deactivate, (jack_client_t* client), (client));
  199007. JUCE_DECL_JACK_FUNCTION (jack_nframes_t, jack_get_buffer_size, (jack_client_t* client), (client));
  199008. JUCE_DECL_JACK_FUNCTION (jack_nframes_t, jack_get_sample_rate, (jack_client_t* client), (client));
  199009. JUCE_DECL_VOID_JACK_FUNCTION (jack_on_shutdown, (jack_client_t* client, void (*function)(void* arg), void* arg), (client, function, arg));
  199010. JUCE_DECL_JACK_FUNCTION (void* , jack_port_get_buffer, (jack_port_t* port, jack_nframes_t nframes), (port, nframes));
  199011. JUCE_DECL_JACK_FUNCTION (jack_nframes_t, jack_port_get_total_latency, (jack_client_t* client, jack_port_t* port), (client, port));
  199012. 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));
  199013. JUCE_DECL_VOID_JACK_FUNCTION (jack_set_error_function, (void (*func)(const char*)), (func));
  199014. JUCE_DECL_JACK_FUNCTION (int, jack_set_process_callback, (jack_client_t* client, JackProcessCallback process_callback, void* arg), (client, process_callback, arg));
  199015. 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));
  199016. JUCE_DECL_JACK_FUNCTION (int, jack_connect, (jack_client_t* client, const char* source_port, const char* destination_port), (client, source_port, destination_port));
  199017. JUCE_DECL_JACK_FUNCTION (const char*, jack_port_name, (const jack_port_t* port), (port));
  199018. JUCE_DECL_JACK_FUNCTION (int, jack_set_port_connect_callback, (jack_client_t* client, JackPortConnectCallback connect_callback, void* arg), (client, connect_callback, arg));
  199019. JUCE_DECL_JACK_FUNCTION (jack_port_t* , jack_port_by_id, (jack_client_t* client, jack_port_id_t port_id), (client, port_id));
  199020. JUCE_DECL_JACK_FUNCTION (int, jack_port_connected, (const jack_port_t* port), (port));
  199021. JUCE_DECL_JACK_FUNCTION (int, jack_port_connected_to, (const jack_port_t* port, const char* port_name), (port, port_name));
  199022. #if JUCE_DEBUG
  199023. #define JACK_LOGGING_ENABLED 1
  199024. #endif
  199025. #if JACK_LOGGING_ENABLED
  199026. static void jack_Log (const String& s)
  199027. {
  199028. puts (s);
  199029. }
  199030. static void dumpJackErrorMessage (const jack_status_t status) throw()
  199031. {
  199032. if (status & JackServerFailed || status & JackServerError)
  199033. jack_Log ("Unable to connect to JACK server");
  199034. if (status & JackVersionError)
  199035. jack_Log ("Client's protocol version does not match");
  199036. if (status & JackInvalidOption)
  199037. jack_Log ("The operation contained an invalid or unsupported option");
  199038. if (status & JackNameNotUnique)
  199039. jack_Log ("The desired client name was not unique");
  199040. if (status & JackNoSuchClient)
  199041. jack_Log ("Requested client does not exist");
  199042. if (status & JackInitFailure)
  199043. jack_Log ("Unable to initialize client");
  199044. }
  199045. #else
  199046. #define dumpJackErrorMessage(a) {}
  199047. #define jack_Log(...) {}
  199048. #endif
  199049. #ifndef JUCE_JACK_CLIENT_NAME
  199050. #define JUCE_JACK_CLIENT_NAME "JuceJack"
  199051. #endif
  199052. class JackAudioIODevice : public AudioIODevice
  199053. {
  199054. public:
  199055. JackAudioIODevice (const String& deviceName,
  199056. const String& inputId_,
  199057. const String& outputId_)
  199058. : AudioIODevice (deviceName, T("JACK")),
  199059. inputId (inputId_),
  199060. outputId (outputId_),
  199061. isOpen_ (false),
  199062. callback (0),
  199063. totalNumberOfInputChannels (0),
  199064. totalNumberOfOutputChannels (0)
  199065. {
  199066. jassert (deviceName.isNotEmpty());
  199067. jack_status_t status;
  199068. client = JUCE_NAMESPACE::jack_client_open (JUCE_JACK_CLIENT_NAME, JackNoStartServer, &status);
  199069. if (client == 0)
  199070. {
  199071. dumpJackErrorMessage (status);
  199072. }
  199073. else
  199074. {
  199075. JUCE_NAMESPACE::jack_set_error_function (errorCallback);
  199076. // open input ports
  199077. const StringArray inputChannels (getInputChannelNames());
  199078. for (int i = 0; i < inputChannels.size(); i++)
  199079. {
  199080. String inputName;
  199081. inputName << "in_" << (++totalNumberOfInputChannels);
  199082. inputPorts.add (JUCE_NAMESPACE::jack_port_register (client, (const char*) inputName,
  199083. JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0));
  199084. }
  199085. // open output ports
  199086. const StringArray outputChannels (getOutputChannelNames());
  199087. for (int i = 0; i < outputChannels.size (); i++)
  199088. {
  199089. String outputName;
  199090. outputName << "out_" << (++totalNumberOfOutputChannels);
  199091. outputPorts.add (JUCE_NAMESPACE::jack_port_register (client, (const char*) outputName,
  199092. JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0));
  199093. }
  199094. inChans.calloc (totalNumberOfInputChannels + 2);
  199095. outChans.calloc (totalNumberOfOutputChannels + 2);
  199096. }
  199097. }
  199098. ~JackAudioIODevice()
  199099. {
  199100. close();
  199101. if (client != 0)
  199102. {
  199103. JUCE_NAMESPACE::jack_client_close (client);
  199104. client = 0;
  199105. }
  199106. }
  199107. const StringArray getChannelNames (bool forInput) const
  199108. {
  199109. StringArray names;
  199110. const char** const ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */
  199111. forInput ? JackPortIsInput : JackPortIsOutput);
  199112. if (ports != 0)
  199113. {
  199114. int j = 0;
  199115. while (ports[j] != 0)
  199116. {
  199117. const String portName (ports [j++]);
  199118. if (portName.upToFirstOccurrenceOf (T(":"), false, false) == getName())
  199119. names.add (portName.fromFirstOccurrenceOf (T(":"), false, false));
  199120. }
  199121. free (ports);
  199122. }
  199123. return names;
  199124. }
  199125. const StringArray getOutputChannelNames() { return getChannelNames (false); }
  199126. const StringArray getInputChannelNames() { return getChannelNames (true); }
  199127. int getNumSampleRates() { return client != 0 ? 1 : 0; }
  199128. double getSampleRate (int index) { return client != 0 ? JUCE_NAMESPACE::jack_get_sample_rate (client) : 0; }
  199129. int getNumBufferSizesAvailable() { return client != 0 ? 1 : 0; }
  199130. int getBufferSizeSamples (int index) { return getDefaultBufferSize(); }
  199131. int getDefaultBufferSize() { return client != 0 ? JUCE_NAMESPACE::jack_get_buffer_size (client) : 0; }
  199132. const String open (const BitArray& inputChannels, const BitArray& outputChannels,
  199133. double sampleRate, int bufferSizeSamples)
  199134. {
  199135. if (client == 0)
  199136. {
  199137. lastError = T("No JACK client running");
  199138. return lastError;
  199139. }
  199140. lastError = String::empty;
  199141. close();
  199142. JUCE_NAMESPACE::jack_set_process_callback (client, processCallback, this);
  199143. JUCE_NAMESPACE::jack_on_shutdown (client, shutdownCallback, this);
  199144. JUCE_NAMESPACE::jack_activate (client);
  199145. isOpen_ = true;
  199146. if (! inputChannels.isEmpty())
  199147. {
  199148. const char** const ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsOutput);
  199149. if (ports != 0)
  199150. {
  199151. const int numInputChannels = inputChannels.getHighestBit () + 1;
  199152. for (int i = 0; i < numInputChannels; ++i)
  199153. {
  199154. const String portName (ports[i]);
  199155. if (inputChannels[i] && portName.upToFirstOccurrenceOf (T(":"), false, false) == getName())
  199156. {
  199157. int error = JUCE_NAMESPACE::jack_connect (client, ports[i], JUCE_NAMESPACE::jack_port_name ((jack_port_t*) inputPorts[i]));
  199158. if (error != 0)
  199159. jack_Log ("Cannot connect input port " + String (i) + " (" + String (ports[i]) + "), error " + String (error));
  199160. }
  199161. }
  199162. free (ports);
  199163. }
  199164. }
  199165. if (! outputChannels.isEmpty())
  199166. {
  199167. const char** const ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsInput);
  199168. if (ports != 0)
  199169. {
  199170. const int numOutputChannels = outputChannels.getHighestBit () + 1;
  199171. for (int i = 0; i < numOutputChannels; ++i)
  199172. {
  199173. const String portName (ports[i]);
  199174. if (outputChannels[i] && portName.upToFirstOccurrenceOf (T(":"), false, false) == getName())
  199175. {
  199176. int error = JUCE_NAMESPACE::jack_connect (client, JUCE_NAMESPACE::jack_port_name ((jack_port_t*) outputPorts[i]), ports[i]);
  199177. if (error != 0)
  199178. jack_Log ("Cannot connect output port " + String (i) + " (" + String (ports[i]) + "), error " + String (error));
  199179. }
  199180. }
  199181. free (ports);
  199182. }
  199183. }
  199184. return lastError;
  199185. }
  199186. void close()
  199187. {
  199188. stop();
  199189. if (client != 0)
  199190. {
  199191. JUCE_NAMESPACE::jack_deactivate (client);
  199192. JUCE_NAMESPACE::jack_set_process_callback (client, processCallback, 0);
  199193. JUCE_NAMESPACE::jack_on_shutdown (client, shutdownCallback, 0);
  199194. }
  199195. isOpen_ = false;
  199196. }
  199197. void start (AudioIODeviceCallback* newCallback)
  199198. {
  199199. if (isOpen_ && newCallback != callback)
  199200. {
  199201. if (newCallback != 0)
  199202. newCallback->audioDeviceAboutToStart (this);
  199203. AudioIODeviceCallback* const oldCallback = callback;
  199204. {
  199205. const ScopedLock sl (callbackLock);
  199206. callback = newCallback;
  199207. }
  199208. if (oldCallback != 0)
  199209. oldCallback->audioDeviceStopped();
  199210. }
  199211. }
  199212. void stop()
  199213. {
  199214. start (0);
  199215. }
  199216. bool isOpen() { return isOpen_; }
  199217. bool isPlaying() { return callback != 0; }
  199218. int getCurrentBufferSizeSamples() { return getBufferSizeSamples (0); }
  199219. double getCurrentSampleRate() { return getSampleRate (0); }
  199220. int getCurrentBitDepth() { return 32; }
  199221. const String getLastError() { return lastError; }
  199222. const BitArray getActiveOutputChannels() const
  199223. {
  199224. BitArray outputBits;
  199225. for (int i = 0; i < outputPorts.size(); i++)
  199226. if (JUCE_NAMESPACE::jack_port_connected ((jack_port_t*) outputPorts [i]))
  199227. outputBits.setBit (i);
  199228. return outputBits;
  199229. }
  199230. const BitArray getActiveInputChannels() const
  199231. {
  199232. BitArray inputBits;
  199233. for (int i = 0; i < inputPorts.size(); i++)
  199234. if (JUCE_NAMESPACE::jack_port_connected ((jack_port_t*) inputPorts [i]))
  199235. inputBits.setBit (i);
  199236. return inputBits;
  199237. }
  199238. int getOutputLatencyInSamples()
  199239. {
  199240. int latency = 0;
  199241. for (int i = 0; i < outputPorts.size(); i++)
  199242. latency = jmax (latency, (int) JUCE_NAMESPACE::jack_port_get_total_latency (client, (jack_port_t*) outputPorts [i]));
  199243. return latency;
  199244. }
  199245. int getInputLatencyInSamples()
  199246. {
  199247. int latency = 0;
  199248. for (int i = 0; i < inputPorts.size(); i++)
  199249. latency = jmax (latency, (int) JUCE_NAMESPACE::jack_port_get_total_latency (client, (jack_port_t*) inputPorts [i]));
  199250. return latency;
  199251. }
  199252. String inputId, outputId;
  199253. private:
  199254. void process (const int numSamples)
  199255. {
  199256. int i, numActiveInChans = 0, numActiveOutChans = 0;
  199257. for (i = 0; i < totalNumberOfInputChannels; ++i)
  199258. {
  199259. jack_default_audio_sample_t* in
  199260. = (jack_default_audio_sample_t*) JUCE_NAMESPACE::jack_port_get_buffer ((jack_port_t*) inputPorts.getUnchecked(i), numSamples);
  199261. if (in != 0)
  199262. inChans [numActiveInChans++] = (float*) in;
  199263. }
  199264. for (i = 0; i < totalNumberOfOutputChannels; ++i)
  199265. {
  199266. jack_default_audio_sample_t* out
  199267. = (jack_default_audio_sample_t*) JUCE_NAMESPACE::jack_port_get_buffer ((jack_port_t*) outputPorts.getUnchecked(i), numSamples);
  199268. if (out != 0)
  199269. outChans [numActiveOutChans++] = (float*) out;
  199270. }
  199271. const ScopedLock sl (callbackLock);
  199272. if (callback != 0)
  199273. {
  199274. callback->audioDeviceIOCallback ((const float**) inChans, numActiveInChans,
  199275. outChans, numActiveOutChans, numSamples);
  199276. }
  199277. else
  199278. {
  199279. for (i = 0; i < numActiveOutChans; ++i)
  199280. zeromem (outChans[i], sizeof (float) * numSamples);
  199281. }
  199282. }
  199283. static int processCallback (jack_nframes_t nframes, void* callbackArgument)
  199284. {
  199285. if (callbackArgument != 0)
  199286. ((JackAudioIODevice*) callbackArgument)->process (nframes);
  199287. return 0;
  199288. }
  199289. static void threadInitCallback (void* callbackArgument)
  199290. {
  199291. jack_Log ("JackAudioIODevice::initialise");
  199292. }
  199293. static void shutdownCallback (void* callbackArgument)
  199294. {
  199295. jack_Log ("JackAudioIODevice::shutdown");
  199296. JackAudioIODevice* device = (JackAudioIODevice*) callbackArgument;
  199297. if (device != 0)
  199298. {
  199299. device->client = 0;
  199300. device->close();
  199301. }
  199302. }
  199303. static void errorCallback (const char* msg)
  199304. {
  199305. jack_Log ("JackAudioIODevice::errorCallback " + String (msg));
  199306. }
  199307. bool isOpen_;
  199308. jack_client_t* client;
  199309. String lastError;
  199310. AudioIODeviceCallback* callback;
  199311. CriticalSection callbackLock;
  199312. HeapBlock <float*> inChans, outChans;
  199313. int totalNumberOfInputChannels;
  199314. int totalNumberOfOutputChannels;
  199315. VoidArray inputPorts, outputPorts;
  199316. };
  199317. class JackAudioIODeviceType : public AudioIODeviceType
  199318. {
  199319. public:
  199320. JackAudioIODeviceType()
  199321. : AudioIODeviceType (T("JACK")),
  199322. hasScanned (false)
  199323. {
  199324. }
  199325. ~JackAudioIODeviceType()
  199326. {
  199327. }
  199328. void scanForDevices()
  199329. {
  199330. hasScanned = true;
  199331. inputNames.clear();
  199332. inputIds.clear();
  199333. outputNames.clear();
  199334. outputIds.clear();
  199335. if (juce_libjack_handle == 0)
  199336. {
  199337. juce_libjack_handle = dlopen ("libjack.so", RTLD_LAZY);
  199338. if (juce_libjack_handle == 0)
  199339. return;
  199340. }
  199341. // open a dummy client
  199342. jack_status_t status;
  199343. jack_client_t* client = JUCE_NAMESPACE::jack_client_open ("JuceJackDummy", JackNoStartServer, &status);
  199344. if (client == 0)
  199345. {
  199346. dumpJackErrorMessage (status);
  199347. }
  199348. else
  199349. {
  199350. // scan for output devices
  199351. const char** ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsOutput);
  199352. if (ports != 0)
  199353. {
  199354. int j = 0;
  199355. while (ports[j] != 0)
  199356. {
  199357. String clientName (ports[j]);
  199358. clientName = clientName.upToFirstOccurrenceOf (T(":"), false, false);
  199359. if (clientName != String (JUCE_JACK_CLIENT_NAME)
  199360. && ! inputNames.contains (clientName))
  199361. {
  199362. inputNames.add (clientName);
  199363. inputIds.add (ports [j]);
  199364. }
  199365. ++j;
  199366. }
  199367. free (ports);
  199368. }
  199369. // scan for input devices
  199370. ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsInput);
  199371. if (ports != 0)
  199372. {
  199373. int j = 0;
  199374. while (ports[j] != 0)
  199375. {
  199376. String clientName (ports[j]);
  199377. clientName = clientName.upToFirstOccurrenceOf (T(":"), false, false);
  199378. if (clientName != String (JUCE_JACK_CLIENT_NAME)
  199379. && ! outputNames.contains (clientName))
  199380. {
  199381. outputNames.add (clientName);
  199382. outputIds.add (ports [j]);
  199383. }
  199384. ++j;
  199385. }
  199386. free (ports);
  199387. }
  199388. JUCE_NAMESPACE::jack_client_close (client);
  199389. }
  199390. }
  199391. const StringArray getDeviceNames (const bool wantInputNames) const
  199392. {
  199393. jassert (hasScanned); // need to call scanForDevices() before doing this
  199394. return wantInputNames ? inputNames : outputNames;
  199395. }
  199396. int getDefaultDeviceIndex (const bool forInput) const
  199397. {
  199398. jassert (hasScanned); // need to call scanForDevices() before doing this
  199399. return 0;
  199400. }
  199401. bool hasSeparateInputsAndOutputs() const { return true; }
  199402. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  199403. {
  199404. jassert (hasScanned); // need to call scanForDevices() before doing this
  199405. JackAudioIODevice* const d = dynamic_cast <JackAudioIODevice*> (device);
  199406. if (d == 0)
  199407. return -1;
  199408. return asInput ? inputIds.indexOf (d->inputId)
  199409. : outputIds.indexOf (d->outputId);
  199410. }
  199411. AudioIODevice* createDevice (const String& outputDeviceName,
  199412. const String& inputDeviceName)
  199413. {
  199414. jassert (hasScanned); // need to call scanForDevices() before doing this
  199415. const int inputIndex = inputNames.indexOf (inputDeviceName);
  199416. const int outputIndex = outputNames.indexOf (outputDeviceName);
  199417. if (inputIndex >= 0 || outputIndex >= 0)
  199418. return new JackAudioIODevice (outputIndex >= 0 ? outputDeviceName
  199419. : inputDeviceName,
  199420. inputIds [inputIndex],
  199421. outputIds [outputIndex]);
  199422. return 0;
  199423. }
  199424. juce_UseDebuggingNewOperator
  199425. private:
  199426. StringArray inputNames, outputNames, inputIds, outputIds;
  199427. bool hasScanned;
  199428. JackAudioIODeviceType (const JackAudioIODeviceType&);
  199429. const JackAudioIODeviceType& operator= (const JackAudioIODeviceType&);
  199430. };
  199431. AudioIODeviceType* juce_createAudioIODeviceType_JACK()
  199432. {
  199433. return new JackAudioIODeviceType();
  199434. }
  199435. #else // if JACK is turned off..
  199436. AudioIODeviceType* juce_createAudioIODeviceType_JACK() { return 0; }
  199437. #endif
  199438. #endif
  199439. /*** End of inlined file: juce_linux_JackAudio.cpp ***/
  199440. /*** Start of inlined file: juce_linux_Midi.cpp ***/
  199441. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  199442. // compiled on its own).
  199443. #if JUCE_INCLUDED_FILE
  199444. #if JUCE_ALSA
  199445. static snd_seq_t* iterateDevices (const bool forInput,
  199446. StringArray& deviceNamesFound,
  199447. const int deviceIndexToOpen)
  199448. {
  199449. snd_seq_t* returnedHandle = 0;
  199450. snd_seq_t* seqHandle;
  199451. if (snd_seq_open (&seqHandle, "default", forInput ? SND_SEQ_OPEN_INPUT
  199452. : SND_SEQ_OPEN_OUTPUT, 0) == 0)
  199453. {
  199454. snd_seq_system_info_t* systemInfo;
  199455. snd_seq_client_info_t* clientInfo;
  199456. if (snd_seq_system_info_malloc (&systemInfo) == 0)
  199457. {
  199458. if (snd_seq_system_info (seqHandle, systemInfo) == 0
  199459. && snd_seq_client_info_malloc (&clientInfo) == 0)
  199460. {
  199461. int numClients = snd_seq_system_info_get_cur_clients (systemInfo);
  199462. while (--numClients >= 0 && returnedHandle == 0)
  199463. {
  199464. if (snd_seq_query_next_client (seqHandle, clientInfo) == 0)
  199465. {
  199466. snd_seq_port_info_t* portInfo;
  199467. if (snd_seq_port_info_malloc (&portInfo) == 0)
  199468. {
  199469. int numPorts = snd_seq_client_info_get_num_ports (clientInfo);
  199470. const int client = snd_seq_client_info_get_client (clientInfo);
  199471. snd_seq_port_info_set_client (portInfo, client);
  199472. snd_seq_port_info_set_port (portInfo, -1);
  199473. while (--numPorts >= 0)
  199474. {
  199475. if (snd_seq_query_next_port (seqHandle, portInfo) == 0
  199476. && (snd_seq_port_info_get_capability (portInfo)
  199477. & (forInput ? SND_SEQ_PORT_CAP_READ
  199478. : SND_SEQ_PORT_CAP_WRITE)) != 0)
  199479. {
  199480. deviceNamesFound.add (snd_seq_client_info_get_name (clientInfo));
  199481. if (deviceNamesFound.size() == deviceIndexToOpen + 1)
  199482. {
  199483. const int sourcePort = snd_seq_port_info_get_port (portInfo);
  199484. const int sourceClient = snd_seq_client_info_get_client (clientInfo);
  199485. if (sourcePort != -1)
  199486. {
  199487. snd_seq_set_client_name (seqHandle,
  199488. forInput ? "Juce Midi Input"
  199489. : "Juce Midi Output");
  199490. const int portId
  199491. = snd_seq_create_simple_port (seqHandle,
  199492. forInput ? "Juce Midi In Port"
  199493. : "Juce Midi Out Port",
  199494. forInput ? (SND_SEQ_PORT_CAP_WRITE | SND_SEQ_PORT_CAP_SUBS_WRITE)
  199495. : (SND_SEQ_PORT_CAP_READ | SND_SEQ_PORT_CAP_SUBS_READ),
  199496. SND_SEQ_PORT_TYPE_MIDI_GENERIC);
  199497. snd_seq_connect_from (seqHandle, portId, sourceClient, sourcePort);
  199498. returnedHandle = seqHandle;
  199499. }
  199500. }
  199501. }
  199502. }
  199503. snd_seq_port_info_free (portInfo);
  199504. }
  199505. }
  199506. }
  199507. snd_seq_client_info_free (clientInfo);
  199508. }
  199509. snd_seq_system_info_free (systemInfo);
  199510. }
  199511. if (returnedHandle == 0)
  199512. snd_seq_close (seqHandle);
  199513. }
  199514. deviceNamesFound.appendNumbersToDuplicates (true, true);
  199515. return returnedHandle;
  199516. }
  199517. static snd_seq_t* createDevice (const bool forInput,
  199518. const String& deviceNameToOpen)
  199519. {
  199520. snd_seq_t* seqHandle = 0;
  199521. if (snd_seq_open (&seqHandle, "default", forInput ? SND_SEQ_OPEN_INPUT
  199522. : SND_SEQ_OPEN_OUTPUT, 0) == 0)
  199523. {
  199524. snd_seq_set_client_name (seqHandle,
  199525. (const char*) (forInput ? (deviceNameToOpen + T(" Input"))
  199526. : (deviceNameToOpen + T(" Output"))));
  199527. const int portId
  199528. = snd_seq_create_simple_port (seqHandle,
  199529. forInput ? "in"
  199530. : "out",
  199531. forInput ? (SND_SEQ_PORT_CAP_WRITE | SND_SEQ_PORT_CAP_SUBS_WRITE)
  199532. : (SND_SEQ_PORT_CAP_READ | SND_SEQ_PORT_CAP_SUBS_READ),
  199533. forInput ? SND_SEQ_PORT_TYPE_APPLICATION
  199534. : SND_SEQ_PORT_TYPE_MIDI_GENERIC);
  199535. if (portId < 0)
  199536. {
  199537. snd_seq_close (seqHandle);
  199538. seqHandle = 0;
  199539. }
  199540. }
  199541. return seqHandle;
  199542. }
  199543. class MidiOutputDevice
  199544. {
  199545. public:
  199546. MidiOutputDevice (MidiOutput* const midiOutput_,
  199547. snd_seq_t* const seqHandle_)
  199548. :
  199549. midiOutput (midiOutput_),
  199550. seqHandle (seqHandle_),
  199551. maxEventSize (16 * 1024)
  199552. {
  199553. jassert (seqHandle != 0 && midiOutput != 0);
  199554. snd_midi_event_new (maxEventSize, &midiParser);
  199555. }
  199556. ~MidiOutputDevice()
  199557. {
  199558. snd_midi_event_free (midiParser);
  199559. snd_seq_close (seqHandle);
  199560. }
  199561. void sendMessageNow (const MidiMessage& message)
  199562. {
  199563. if (message.getRawDataSize() > maxEventSize)
  199564. {
  199565. maxEventSize = message.getRawDataSize();
  199566. snd_midi_event_free (midiParser);
  199567. snd_midi_event_new (maxEventSize, &midiParser);
  199568. }
  199569. snd_seq_event_t event;
  199570. snd_seq_ev_clear (&event);
  199571. snd_midi_event_encode (midiParser,
  199572. message.getRawData(),
  199573. message.getRawDataSize(),
  199574. &event);
  199575. snd_midi_event_reset_encode (midiParser);
  199576. snd_seq_ev_set_source (&event, 0);
  199577. snd_seq_ev_set_subs (&event);
  199578. snd_seq_ev_set_direct (&event);
  199579. snd_seq_event_output (seqHandle, &event);
  199580. snd_seq_drain_output (seqHandle);
  199581. }
  199582. juce_UseDebuggingNewOperator
  199583. private:
  199584. MidiOutput* const midiOutput;
  199585. snd_seq_t* const seqHandle;
  199586. snd_midi_event_t* midiParser;
  199587. int maxEventSize;
  199588. };
  199589. const StringArray MidiOutput::getDevices()
  199590. {
  199591. StringArray devices;
  199592. iterateDevices (false, devices, -1);
  199593. return devices;
  199594. }
  199595. int MidiOutput::getDefaultDeviceIndex()
  199596. {
  199597. return 0;
  199598. }
  199599. MidiOutput* MidiOutput::openDevice (int deviceIndex)
  199600. {
  199601. MidiOutput* newDevice = 0;
  199602. StringArray devices;
  199603. snd_seq_t* const handle = iterateDevices (false, devices, deviceIndex);
  199604. if (handle != 0)
  199605. {
  199606. newDevice = new MidiOutput();
  199607. newDevice->internal = new MidiOutputDevice (newDevice, handle);
  199608. }
  199609. return newDevice;
  199610. }
  199611. MidiOutput* MidiOutput::createNewDevice (const String& deviceName)
  199612. {
  199613. MidiOutput* newDevice = 0;
  199614. snd_seq_t* const handle = createDevice (false, deviceName);
  199615. if (handle != 0)
  199616. {
  199617. newDevice = new MidiOutput();
  199618. newDevice->internal = new MidiOutputDevice (newDevice, handle);
  199619. }
  199620. return newDevice;
  199621. }
  199622. MidiOutput::~MidiOutput()
  199623. {
  199624. MidiOutputDevice* const device = (MidiOutputDevice*) internal;
  199625. delete device;
  199626. }
  199627. void MidiOutput::reset()
  199628. {
  199629. }
  199630. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  199631. {
  199632. return false;
  199633. }
  199634. void MidiOutput::setVolume (float leftVol, float rightVol)
  199635. {
  199636. }
  199637. void MidiOutput::sendMessageNow (const MidiMessage& message)
  199638. {
  199639. ((MidiOutputDevice*) internal)->sendMessageNow (message);
  199640. }
  199641. class MidiInputThread : public Thread
  199642. {
  199643. public:
  199644. MidiInputThread (MidiInput* const midiInput_,
  199645. snd_seq_t* const seqHandle_,
  199646. MidiInputCallback* const callback_)
  199647. : Thread (T("Juce MIDI Input")),
  199648. midiInput (midiInput_),
  199649. seqHandle (seqHandle_),
  199650. callback (callback_)
  199651. {
  199652. jassert (seqHandle != 0 && callback != 0 && midiInput != 0);
  199653. }
  199654. ~MidiInputThread()
  199655. {
  199656. snd_seq_close (seqHandle);
  199657. }
  199658. void run()
  199659. {
  199660. const int maxEventSize = 16 * 1024;
  199661. snd_midi_event_t* midiParser;
  199662. if (snd_midi_event_new (maxEventSize, &midiParser) >= 0)
  199663. {
  199664. HeapBlock <uint8> buffer (maxEventSize);
  199665. const int numPfds = snd_seq_poll_descriptors_count (seqHandle, POLLIN);
  199666. struct pollfd* const pfd = (struct pollfd*) alloca (numPfds * sizeof (struct pollfd));
  199667. snd_seq_poll_descriptors (seqHandle, pfd, numPfds, POLLIN);
  199668. while (! threadShouldExit())
  199669. {
  199670. if (poll (pfd, numPfds, 500) > 0)
  199671. {
  199672. snd_seq_event_t* inputEvent = 0;
  199673. snd_seq_nonblock (seqHandle, 1);
  199674. do
  199675. {
  199676. if (snd_seq_event_input (seqHandle, &inputEvent) >= 0)
  199677. {
  199678. // xxx what about SYSEXes that are too big for the buffer?
  199679. const int numBytes = snd_midi_event_decode (midiParser, buffer, maxEventSize, inputEvent);
  199680. snd_midi_event_reset_decode (midiParser);
  199681. if (numBytes > 0)
  199682. {
  199683. const MidiMessage message ((const uint8*) buffer,
  199684. numBytes,
  199685. Time::getMillisecondCounter() * 0.001);
  199686. callback->handleIncomingMidiMessage (midiInput, message);
  199687. }
  199688. snd_seq_free_event (inputEvent);
  199689. }
  199690. }
  199691. while (snd_seq_event_input_pending (seqHandle, 0) > 0);
  199692. snd_seq_free_event (inputEvent);
  199693. }
  199694. }
  199695. snd_midi_event_free (midiParser);
  199696. }
  199697. };
  199698. juce_UseDebuggingNewOperator
  199699. private:
  199700. MidiInput* const midiInput;
  199701. snd_seq_t* const seqHandle;
  199702. MidiInputCallback* const callback;
  199703. };
  199704. MidiInput::MidiInput (const String& name_)
  199705. : name (name_),
  199706. internal (0)
  199707. {
  199708. }
  199709. MidiInput::~MidiInput()
  199710. {
  199711. stop();
  199712. MidiInputThread* const thread = (MidiInputThread*) internal;
  199713. delete thread;
  199714. }
  199715. void MidiInput::start()
  199716. {
  199717. ((MidiInputThread*) internal)->startThread();
  199718. }
  199719. void MidiInput::stop()
  199720. {
  199721. ((MidiInputThread*) internal)->stopThread (3000);
  199722. }
  199723. int MidiInput::getDefaultDeviceIndex()
  199724. {
  199725. return 0;
  199726. }
  199727. const StringArray MidiInput::getDevices()
  199728. {
  199729. StringArray devices;
  199730. iterateDevices (true, devices, -1);
  199731. return devices;
  199732. }
  199733. MidiInput* MidiInput::openDevice (int deviceIndex, MidiInputCallback* callback)
  199734. {
  199735. MidiInput* newDevice = 0;
  199736. StringArray devices;
  199737. snd_seq_t* const handle = iterateDevices (true, devices, deviceIndex);
  199738. if (handle != 0)
  199739. {
  199740. newDevice = new MidiInput (devices [deviceIndex]);
  199741. newDevice->internal = new MidiInputThread (newDevice, handle, callback);
  199742. }
  199743. return newDevice;
  199744. }
  199745. MidiInput* MidiInput::createNewDevice (const String& deviceName, MidiInputCallback* callback)
  199746. {
  199747. MidiInput* newDevice = 0;
  199748. snd_seq_t* const handle = createDevice (true, deviceName);
  199749. if (handle != 0)
  199750. {
  199751. newDevice = new MidiInput (deviceName);
  199752. newDevice->internal = new MidiInputThread (newDevice, handle, callback);
  199753. }
  199754. return newDevice;
  199755. }
  199756. #else
  199757. // (These are just stub functions if ALSA is unavailable...)
  199758. const StringArray MidiOutput::getDevices() { return StringArray(); }
  199759. int MidiOutput::getDefaultDeviceIndex() { return 0; }
  199760. MidiOutput* MidiOutput::openDevice (int) { return 0; }
  199761. MidiOutput* MidiOutput::createNewDevice (const String&) { return 0; }
  199762. MidiOutput::~MidiOutput() {}
  199763. void MidiOutput::reset() {}
  199764. bool MidiOutput::getVolume (float&, float&) { return false; }
  199765. void MidiOutput::setVolume (float, float) {}
  199766. void MidiOutput::sendMessageNow (const MidiMessage&) {}
  199767. MidiInput::MidiInput (const String& name_) : name (name_), internal (0) {}
  199768. MidiInput::~MidiInput() {}
  199769. void MidiInput::start() {}
  199770. void MidiInput::stop() {}
  199771. int MidiInput::getDefaultDeviceIndex() { return 0; }
  199772. const StringArray MidiInput::getDevices() { return StringArray(); }
  199773. MidiInput* MidiInput::openDevice (int, MidiInputCallback*) { return 0; }
  199774. MidiInput* MidiInput::createNewDevice (const String&, MidiInputCallback*) { return 0; }
  199775. #endif
  199776. #endif
  199777. /*** End of inlined file: juce_linux_Midi.cpp ***/
  199778. /*** Start of inlined file: juce_linux_AudioCDReader.cpp ***/
  199779. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  199780. // compiled on its own).
  199781. #if JUCE_INCLUDED_FILE && JUCE_USE_CDREADER
  199782. AudioCDReader::AudioCDReader()
  199783. : AudioFormatReader (0, T("CD Audio"))
  199784. {
  199785. }
  199786. const StringArray AudioCDReader::getAvailableCDNames()
  199787. {
  199788. StringArray names;
  199789. return names;
  199790. }
  199791. AudioCDReader* AudioCDReader::createReaderForCD (const int index)
  199792. {
  199793. return 0;
  199794. }
  199795. AudioCDReader::~AudioCDReader()
  199796. {
  199797. }
  199798. void AudioCDReader::refreshTrackLengths()
  199799. {
  199800. }
  199801. bool AudioCDReader::readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  199802. int64 startSampleInFile, int numSamples)
  199803. {
  199804. return false;
  199805. }
  199806. bool AudioCDReader::isCDStillPresent() const
  199807. {
  199808. return false;
  199809. }
  199810. int AudioCDReader::getNumTracks() const
  199811. {
  199812. return 0;
  199813. }
  199814. int AudioCDReader::getPositionOfTrackStart (int trackNum) const
  199815. {
  199816. return 0;
  199817. }
  199818. bool AudioCDReader::isTrackAudio (int trackNum) const
  199819. {
  199820. return false;
  199821. }
  199822. void AudioCDReader::enableIndexScanning (bool b)
  199823. {
  199824. }
  199825. int AudioCDReader::getLastIndex() const
  199826. {
  199827. return 0;
  199828. }
  199829. const Array<int> AudioCDReader::findIndexesInTrack (const int trackNumber)
  199830. {
  199831. return Array<int>();
  199832. }
  199833. int AudioCDReader::getCDDBId()
  199834. {
  199835. return 0;
  199836. }
  199837. #endif
  199838. /*** End of inlined file: juce_linux_AudioCDReader.cpp ***/
  199839. /*** Start of inlined file: juce_linux_FileChooser.cpp ***/
  199840. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  199841. // compiled on its own).
  199842. #if JUCE_INCLUDED_FILE
  199843. void FileChooser::showPlatformDialog (Array<File>& results,
  199844. const String& title,
  199845. const File& file,
  199846. const String& filters,
  199847. bool isDirectory,
  199848. bool selectsFiles,
  199849. bool isSave,
  199850. bool warnAboutOverwritingExistingFiles,
  199851. bool selectMultipleFiles,
  199852. FilePreviewComponent* previewComponent)
  199853. {
  199854. const tchar* const separator = T(":");
  199855. String command ("zenity --file-selection");
  199856. if (title.isNotEmpty())
  199857. command << " --title=\"" << title << "\"";
  199858. if (file != File::nonexistent)
  199859. command << " --filename=\"" << file.getFullPathName () << "\"";
  199860. if (isDirectory)
  199861. command << " --directory";
  199862. if (isSave)
  199863. command << " --save";
  199864. if (selectMultipleFiles)
  199865. command << " --multiple --separator=\"" << separator << "\"";
  199866. command << " 2>&1";
  199867. MemoryOutputStream result;
  199868. int status = -1;
  199869. FILE* stream = popen ((const char*) command.toUTF8(), "r");
  199870. if (stream != 0)
  199871. {
  199872. for (;;)
  199873. {
  199874. char buffer [1024];
  199875. const int bytesRead = fread (buffer, 1, sizeof (buffer), stream);
  199876. if (bytesRead <= 0)
  199877. break;
  199878. result.write (buffer, bytesRead);
  199879. }
  199880. status = pclose (stream);
  199881. }
  199882. if (status == 0)
  199883. {
  199884. String resultString (String::fromUTF8 ((const uint8*) result.getData(), result.getDataSize()));
  199885. StringArray tokens;
  199886. if (selectMultipleFiles)
  199887. tokens.addTokens (resultString, separator, 0);
  199888. else
  199889. tokens.add (resultString);
  199890. for (int i = 0; i < tokens.size(); i++)
  199891. results.add (File (tokens[i]));
  199892. return;
  199893. }
  199894. //xxx ain't got one!
  199895. jassertfalse
  199896. }
  199897. #endif
  199898. /*** End of inlined file: juce_linux_FileChooser.cpp ***/
  199899. /*** Start of inlined file: juce_linux_WebBrowserComponent.cpp ***/
  199900. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  199901. // compiled on its own).
  199902. #if JUCE_INCLUDED_FILE && JUCE_WEB_BROWSER
  199903. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  199904. : browser (0),
  199905. blankPageShown (false),
  199906. unloadPageWhenBrowserIsHidden (unloadPageWhenBrowserIsHidden_)
  199907. {
  199908. setOpaque (true);
  199909. }
  199910. WebBrowserComponent::~WebBrowserComponent()
  199911. {
  199912. }
  199913. void WebBrowserComponent::goToURL (const String& url,
  199914. const StringArray* headers,
  199915. const MemoryBlock* postData)
  199916. {
  199917. lastURL = url;
  199918. lastHeaders.clear();
  199919. if (headers != 0)
  199920. lastHeaders = *headers;
  199921. lastPostData.setSize (0);
  199922. if (postData != 0)
  199923. lastPostData = *postData;
  199924. blankPageShown = false;
  199925. }
  199926. void WebBrowserComponent::stop()
  199927. {
  199928. }
  199929. void WebBrowserComponent::goBack()
  199930. {
  199931. lastURL = String::empty;
  199932. blankPageShown = false;
  199933. }
  199934. void WebBrowserComponent::goForward()
  199935. {
  199936. lastURL = String::empty;
  199937. }
  199938. void WebBrowserComponent::refresh()
  199939. {
  199940. }
  199941. void WebBrowserComponent::paint (Graphics& g)
  199942. {
  199943. g.fillAll (Colours::white);
  199944. }
  199945. void WebBrowserComponent::checkWindowAssociation()
  199946. {
  199947. }
  199948. void WebBrowserComponent::reloadLastURL()
  199949. {
  199950. if (lastURL.isNotEmpty())
  199951. {
  199952. goToURL (lastURL, &lastHeaders, &lastPostData);
  199953. lastURL = String::empty;
  199954. }
  199955. }
  199956. void WebBrowserComponent::parentHierarchyChanged()
  199957. {
  199958. checkWindowAssociation();
  199959. }
  199960. void WebBrowserComponent::resized()
  199961. {
  199962. }
  199963. void WebBrowserComponent::visibilityChanged()
  199964. {
  199965. checkWindowAssociation();
  199966. }
  199967. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  199968. {
  199969. return true;
  199970. }
  199971. #endif
  199972. /*** End of inlined file: juce_linux_WebBrowserComponent.cpp ***/
  199973. #endif
  199974. END_JUCE_NAMESPACE
  199975. /*** End of inlined file: juce_linux_NativeCode.cpp ***/
  199976. #endif
  199977. #if JUCE_MAC || JUCE_IPHONE
  199978. /*** Start of inlined file: juce_mac_NativeCode.mm ***/
  199979. BEGIN_JUCE_NAMESPACE
  199980. #undef Point
  199981. #define JUCE_INCLUDED_FILE 1
  199982. // Now include the actual code files..
  199983. /*** Start of inlined file: juce_mac_ObjCSuffix.h ***/
  199984. #ifndef JUCE_ObjCExtraSuffix
  199985. #define JUCE_ObjCExtraSuffix 3
  199986. #endif
  199987. #define appendMacro1(a, b, c, d) a ## _ ## b ## _ ## c ## _ ## d
  199988. #define appendMacro2(a, b, c, d) appendMacro1(a, b, c, d)
  199989. #define MakeObjCClassName(rootName) appendMacro2 (rootName, JUCE_MAJOR_VERSION, JUCE_MINOR_VERSION, JUCE_ObjCExtraSuffix)
  199990. /*** End of inlined file: juce_mac_ObjCSuffix.h ***/
  199991. /*** Start of inlined file: juce_mac_Strings.mm ***/
  199992. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  199993. // compiled on its own).
  199994. #if JUCE_INCLUDED_FILE
  199995. static const String nsStringToJuce (NSString* s)
  199996. {
  199997. return String::fromUTF8 ((uint8*) [s UTF8String]);
  199998. }
  199999. static NSString* juceStringToNS (const String& s)
  200000. {
  200001. return [NSString stringWithUTF8String: (const char*) s.toUTF8()];
  200002. }
  200003. static const String convertUTF16ToString (const UniChar* utf16)
  200004. {
  200005. String s;
  200006. while (*utf16 != 0)
  200007. s += (juce_wchar) *utf16++;
  200008. return s;
  200009. }
  200010. const String PlatformUtilities::cfStringToJuceString (CFStringRef cfString)
  200011. {
  200012. String result;
  200013. if (cfString != 0)
  200014. {
  200015. #if JUCE_STRINGS_ARE_UNICODE
  200016. CFRange range = { 0, CFStringGetLength (cfString) };
  200017. HeapBlock <UniChar> u (range.length + 1);
  200018. CFStringGetCharacters (cfString, range, u);
  200019. u[range.length] = 0;
  200020. result = convertUTF16ToString (u);
  200021. #else
  200022. const int len = CFStringGetLength (cfString);
  200023. HeapBlock <char> buffer (len + 1);
  200024. CFStringGetCString (cfString, buffer, len + 1, CFStringGetSystemEncoding());
  200025. result = buffer;
  200026. #endif
  200027. }
  200028. return result;
  200029. }
  200030. CFStringRef PlatformUtilities::juceStringToCFString (const String& s)
  200031. {
  200032. #if JUCE_STRINGS_ARE_UNICODE
  200033. const int len = s.length();
  200034. const juce_wchar* t = (const juce_wchar*) s;
  200035. HeapBlock <UniChar> temp (len + 2);
  200036. for (int i = 0; i <= len; ++i)
  200037. temp[i] = t[i];
  200038. return CFStringCreateWithCharacters (kCFAllocatorDefault, temp, len);
  200039. #else
  200040. return CFStringCreateWithCString (kCFAllocatorDefault,
  200041. (const char*) s,
  200042. CFStringGetSystemEncoding());
  200043. #endif
  200044. }
  200045. const String PlatformUtilities::convertToPrecomposedUnicode (const String& s)
  200046. {
  200047. #if JUCE_IPHONE
  200048. const ScopedAutoReleasePool pool;
  200049. return nsStringToJuce ([juceStringToNS (s) precomposedStringWithCanonicalMapping]);
  200050. #else
  200051. UnicodeMapping map;
  200052. map.unicodeEncoding = CreateTextEncoding (kTextEncodingUnicodeDefault,
  200053. kUnicodeNoSubset,
  200054. kTextEncodingDefaultFormat);
  200055. map.otherEncoding = CreateTextEncoding (kTextEncodingUnicodeDefault,
  200056. kUnicodeCanonicalCompVariant,
  200057. kTextEncodingDefaultFormat);
  200058. map.mappingVersion = kUnicodeUseLatestMapping;
  200059. UnicodeToTextInfo conversionInfo = 0;
  200060. String result;
  200061. if (CreateUnicodeToTextInfo (&map, &conversionInfo) == noErr)
  200062. {
  200063. const int len = s.length();
  200064. HeapBlock <UniChar> tempIn, tempOut;
  200065. tempIn.calloc (len + 2);
  200066. tempOut.calloc (len + 2);
  200067. for (int i = 0; i <= len; ++i)
  200068. tempIn[i] = s[i];
  200069. ByteCount bytesRead = 0;
  200070. ByteCount outputBufferSize = 0;
  200071. if (ConvertFromUnicodeToText (conversionInfo,
  200072. len * sizeof (UniChar), tempIn,
  200073. kUnicodeDefaultDirectionMask,
  200074. 0, 0, 0, 0,
  200075. len * sizeof (UniChar), &bytesRead,
  200076. &outputBufferSize, tempOut) == noErr)
  200077. {
  200078. result.preallocateStorage (bytesRead / sizeof (UniChar) + 2);
  200079. tchar* t = const_cast <tchar*> ((const tchar*) result);
  200080. unsigned int i;
  200081. for (i = 0; i < bytesRead / sizeof (UniChar); ++i)
  200082. t[i] = (tchar) tempOut[i];
  200083. t[i] = 0;
  200084. }
  200085. DisposeUnicodeToTextInfo (&conversionInfo);
  200086. }
  200087. return result;
  200088. #endif
  200089. }
  200090. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  200091. void SystemClipboard::copyTextToClipboard (const String& text) throw()
  200092. {
  200093. #if JUCE_IPHONE
  200094. [[UIPasteboard generalPasteboard] setValue: juceStringToNS (text)
  200095. forPasteboardType: @"public.text"];
  200096. #else
  200097. [[NSPasteboard generalPasteboard] declareTypes: [NSArray arrayWithObject: NSStringPboardType]
  200098. owner: nil];
  200099. [[NSPasteboard generalPasteboard] setString: juceStringToNS (text)
  200100. forType: NSStringPboardType];
  200101. #endif
  200102. }
  200103. const String SystemClipboard::getTextFromClipboard() throw()
  200104. {
  200105. #if JUCE_IPHONE
  200106. NSString* text = [[UIPasteboard generalPasteboard] valueForPasteboardType: @"public.text"];
  200107. #else
  200108. NSString* text = [[NSPasteboard generalPasteboard] stringForType: NSStringPboardType];
  200109. #endif
  200110. return text == 0 ? String::empty
  200111. : nsStringToJuce (text);
  200112. }
  200113. #endif
  200114. #endif
  200115. /*** End of inlined file: juce_mac_Strings.mm ***/
  200116. /*** Start of inlined file: juce_mac_SystemStats.mm ***/
  200117. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  200118. // compiled on its own).
  200119. #if JUCE_INCLUDED_FILE
  200120. static int64 highResTimerFrequency = 0;
  200121. static double highResTimerToMillisecRatio = 0;
  200122. #if JUCE_INTEL
  200123. static void juce_getCpuVendor (char* const v) throw()
  200124. {
  200125. int vendor[4];
  200126. zerostruct (vendor);
  200127. int dummy = 0;
  200128. asm ("mov %%ebx, %%esi \n\t"
  200129. "cpuid \n\t"
  200130. "xchg %%esi, %%ebx"
  200131. : "=a" (dummy), "=S" (vendor[0]), "=c" (vendor[2]), "=d" (vendor[1]) : "a" (0));
  200132. memcpy (v, vendor, 16);
  200133. }
  200134. static unsigned int getCPUIDWord (unsigned int& familyModel, unsigned int& extFeatures)
  200135. {
  200136. unsigned int cpu = 0;
  200137. unsigned int ext = 0;
  200138. unsigned int family = 0;
  200139. unsigned int dummy = 0;
  200140. asm ("mov %%ebx, %%esi \n\t"
  200141. "cpuid \n\t"
  200142. "xchg %%esi, %%ebx"
  200143. : "=a" (family), "=S" (ext), "=c" (dummy), "=d" (cpu) : "a" (1));
  200144. familyModel = family;
  200145. extFeatures = ext;
  200146. return cpu;
  200147. }
  200148. struct CPUFlags
  200149. {
  200150. bool hasMMX : 1;
  200151. bool hasSSE : 1;
  200152. bool hasSSE2 : 1;
  200153. bool has3DNow : 1;
  200154. };
  200155. static CPUFlags cpuFlags;
  200156. #endif
  200157. void SystemStats::initialiseStats() throw()
  200158. {
  200159. static bool initialised = false;
  200160. if (! initialised)
  200161. {
  200162. initialised = true;
  200163. #if JUCE_MAC
  200164. // extremely annoying: adding this line stops the apple menu items from working. Of
  200165. // course, not adding it means that carbon windows (e.g. in plugins) won't get
  200166. // any events.
  200167. //NSApplicationLoad();
  200168. [NSApplication sharedApplication];
  200169. #endif
  200170. #if JUCE_INTEL
  200171. {
  200172. unsigned int familyModel, extFeatures;
  200173. const unsigned int features = getCPUIDWord (familyModel, extFeatures);
  200174. cpuFlags.hasMMX = ((features & (1 << 23)) != 0);
  200175. cpuFlags.hasSSE = ((features & (1 << 25)) != 0);
  200176. cpuFlags.hasSSE2 = ((features & (1 << 26)) != 0);
  200177. cpuFlags.has3DNow = ((extFeatures & (1 << 31)) != 0);
  200178. }
  200179. #endif
  200180. mach_timebase_info_data_t timebase;
  200181. (void) mach_timebase_info (&timebase);
  200182. highResTimerFrequency = (int64) (1.0e9 * timebase.denom / timebase.numer);
  200183. highResTimerToMillisecRatio = timebase.numer / (1.0e6 * timebase.denom);
  200184. String s (SystemStats::getJUCEVersion());
  200185. rlimit lim;
  200186. getrlimit (RLIMIT_NOFILE, &lim);
  200187. lim.rlim_cur = lim.rlim_max = RLIM_INFINITY;
  200188. setrlimit (RLIMIT_NOFILE, &lim);
  200189. }
  200190. }
  200191. SystemStats::OperatingSystemType SystemStats::getOperatingSystemType() throw()
  200192. {
  200193. return MacOSX;
  200194. }
  200195. const String SystemStats::getOperatingSystemName() throw()
  200196. {
  200197. return T("Mac OS X");
  200198. }
  200199. bool SystemStats::isOperatingSystem64Bit() throw()
  200200. {
  200201. #if JUCE_64BIT
  200202. return true;
  200203. #else
  200204. //xxx not sure how to find this out?..
  200205. return false;
  200206. #endif
  200207. }
  200208. int SystemStats::getMemorySizeInMegabytes() throw()
  200209. {
  200210. uint64 mem = 0;
  200211. size_t memSize = sizeof (mem);
  200212. int mib[] = { CTL_HW, HW_MEMSIZE };
  200213. sysctl (mib, 2, &mem, &memSize, 0, 0);
  200214. return (int) (mem / (1024 * 1024));
  200215. }
  200216. bool SystemStats::hasMMX() throw()
  200217. {
  200218. #if JUCE_INTEL
  200219. return cpuFlags.hasMMX;
  200220. #else
  200221. return false;
  200222. #endif
  200223. }
  200224. bool SystemStats::hasSSE() throw()
  200225. {
  200226. #if JUCE_INTEL
  200227. return cpuFlags.hasSSE;
  200228. #else
  200229. return false;
  200230. #endif
  200231. }
  200232. bool SystemStats::hasSSE2() throw()
  200233. {
  200234. #if JUCE_INTEL
  200235. return cpuFlags.hasSSE2;
  200236. #else
  200237. return false;
  200238. #endif
  200239. }
  200240. bool SystemStats::has3DNow() throw()
  200241. {
  200242. #if JUCE_INTEL
  200243. return cpuFlags.has3DNow;
  200244. #else
  200245. return false;
  200246. #endif
  200247. }
  200248. const String SystemStats::getCpuVendor() throw()
  200249. {
  200250. #if JUCE_INTEL
  200251. char v [16];
  200252. juce_getCpuVendor (v);
  200253. return String (v, 16);
  200254. #else
  200255. return String::empty;
  200256. #endif
  200257. }
  200258. int SystemStats::getCpuSpeedInMegaherz() throw()
  200259. {
  200260. uint64 speedHz = 0;
  200261. size_t speedSize = sizeof (speedHz);
  200262. int mib[] = { CTL_HW, HW_CPU_FREQ };
  200263. sysctl (mib, 2, &speedHz, &speedSize, 0, 0);
  200264. #if JUCE_BIG_ENDIAN
  200265. if (speedSize == 4)
  200266. speedHz >>= 32;
  200267. #endif
  200268. return (int) (speedHz / 1000000);
  200269. }
  200270. int SystemStats::getNumCpus() throw()
  200271. {
  200272. #if JUCE_IPHONE || (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5)
  200273. return (int) [[NSProcessInfo processInfo] activeProcessorCount];
  200274. #else
  200275. return MPProcessors();
  200276. #endif
  200277. }
  200278. const String SystemStats::getLogonName()
  200279. {
  200280. return nsStringToJuce (NSUserName());
  200281. }
  200282. const String SystemStats::getFullUserName()
  200283. {
  200284. return nsStringToJuce (NSFullUserName());
  200285. }
  200286. uint32 juce_millisecondsSinceStartup() throw()
  200287. {
  200288. return (uint32) (mach_absolute_time() * highResTimerToMillisecRatio);
  200289. }
  200290. double Time::getMillisecondCounterHiRes() throw()
  200291. {
  200292. return mach_absolute_time() * highResTimerToMillisecRatio;
  200293. }
  200294. int64 Time::getHighResolutionTicks() throw()
  200295. {
  200296. return (int64) mach_absolute_time();
  200297. }
  200298. int64 Time::getHighResolutionTicksPerSecond() throw()
  200299. {
  200300. return highResTimerFrequency;
  200301. }
  200302. int64 SystemStats::getClockCycleCounter() throw()
  200303. {
  200304. return (int64) mach_absolute_time();
  200305. }
  200306. bool Time::setSystemTimeToThisTime() const throw()
  200307. {
  200308. jassertfalse
  200309. return false;
  200310. }
  200311. int SystemStats::getPageSize() throw()
  200312. {
  200313. return (int) NSPageSize();
  200314. }
  200315. void PlatformUtilities::fpuReset()
  200316. {
  200317. }
  200318. #endif
  200319. /*** End of inlined file: juce_mac_SystemStats.mm ***/
  200320. /*** Start of inlined file: juce_mac_Network.mm ***/
  200321. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  200322. // compiled on its own).
  200323. #if JUCE_INCLUDED_FILE
  200324. int SystemStats::getMACAddresses (int64* addresses, int maxNum, const bool littleEndian) throw()
  200325. {
  200326. #ifndef IFT_ETHER
  200327. #define IFT_ETHER 6
  200328. #endif
  200329. ifaddrs* addrs = 0;
  200330. int numResults = 0;
  200331. if (getifaddrs (&addrs) == 0)
  200332. {
  200333. const ifaddrs* cursor = addrs;
  200334. while (cursor != 0 && numResults < maxNum)
  200335. {
  200336. sockaddr_storage* sto = (sockaddr_storage*) cursor->ifa_addr;
  200337. if (sto->ss_family == AF_LINK)
  200338. {
  200339. const sockaddr_dl* const sadd = (const sockaddr_dl*) cursor->ifa_addr;
  200340. if (sadd->sdl_type == IFT_ETHER)
  200341. {
  200342. const uint8* const addr = ((const uint8*) sadd->sdl_data) + sadd->sdl_nlen;
  200343. uint64 a = 0;
  200344. for (int i = 6; --i >= 0;)
  200345. a = (a << 8) | addr [littleEndian ? i : (5 - i)];
  200346. *addresses++ = (int64) a;
  200347. ++numResults;
  200348. }
  200349. }
  200350. cursor = cursor->ifa_next;
  200351. }
  200352. freeifaddrs (addrs);
  200353. }
  200354. return numResults;
  200355. }
  200356. bool PlatformUtilities::launchEmailWithAttachments (const String& targetEmailAddress,
  200357. const String& emailSubject,
  200358. const String& bodyText,
  200359. const StringArray& filesToAttach)
  200360. {
  200361. #if JUCE_IPHONE
  200362. //xxx probably need to use MFMailComposeViewController
  200363. jassertfalse
  200364. return false;
  200365. #else
  200366. const ScopedAutoReleasePool pool;
  200367. String script;
  200368. script << "tell application \"Mail\"\r\n"
  200369. "set newMessage to make new outgoing message with properties {subject:\""
  200370. << emailSubject.replace (T("\""), T("\\\""))
  200371. << "\", content:\""
  200372. << bodyText.replace (T("\""), T("\\\""))
  200373. << "\" & return & return}\r\n"
  200374. "tell newMessage\r\n"
  200375. "set visible to true\r\n"
  200376. "set sender to \"sdfsdfsdfewf\"\r\n"
  200377. "make new to recipient at end of to recipients with properties {address:\""
  200378. << targetEmailAddress
  200379. << "\"}\r\n";
  200380. for (int i = 0; i < filesToAttach.size(); ++i)
  200381. {
  200382. script << "tell content\r\n"
  200383. "make new attachment with properties {file name:\""
  200384. << filesToAttach[i].replace (T("\""), T("\\\""))
  200385. << "\"} at after the last paragraph\r\n"
  200386. "end tell\r\n";
  200387. }
  200388. script << "end tell\r\n"
  200389. "end tell\r\n";
  200390. NSAppleScript* s = [[NSAppleScript alloc]
  200391. initWithSource: juceStringToNS (script)];
  200392. NSDictionary* error = 0;
  200393. const bool ok = [s executeAndReturnError: &error] != nil;
  200394. [s release];
  200395. return ok;
  200396. #endif
  200397. }
  200398. END_JUCE_NAMESPACE
  200399. using namespace JUCE_NAMESPACE;
  200400. #define JuceURLConnection MakeObjCClassName(JuceURLConnection)
  200401. @interface JuceURLConnection : NSObject
  200402. {
  200403. @public
  200404. NSURLRequest* request;
  200405. NSURLConnection* connection;
  200406. NSMutableData* data;
  200407. Thread* runLoopThread;
  200408. bool initialised, hasFailed, hasFinished;
  200409. int position;
  200410. int64 contentLength;
  200411. NSLock* dataLock;
  200412. }
  200413. - (JuceURLConnection*) initWithRequest: (NSURLRequest*) req withCallback: (URL::OpenStreamProgressCallback*) callback withContext: (void*) context;
  200414. - (void) dealloc;
  200415. - (void) connection: (NSURLConnection*) connection didReceiveResponse: (NSURLResponse*) response;
  200416. - (void) connection: (NSURLConnection*) connection didFailWithError: (NSError*) error;
  200417. - (void) connection: (NSURLConnection*) connection didReceiveData: (NSData*) data;
  200418. - (void) connectionDidFinishLoading: (NSURLConnection*) connection;
  200419. - (BOOL) isOpen;
  200420. - (int) read: (char*) dest numBytes: (int) num;
  200421. - (int) readPosition;
  200422. - (void) stop;
  200423. - (void) createConnection;
  200424. @end
  200425. class JuceURLConnectionMessageThread : public Thread
  200426. {
  200427. JuceURLConnection* owner;
  200428. public:
  200429. JuceURLConnectionMessageThread (JuceURLConnection* owner_)
  200430. : Thread (T("http connection")),
  200431. owner (owner_)
  200432. {
  200433. }
  200434. ~JuceURLConnectionMessageThread()
  200435. {
  200436. stopThread (10000);
  200437. }
  200438. void run()
  200439. {
  200440. [owner createConnection];
  200441. while (! threadShouldExit())
  200442. {
  200443. const ScopedAutoReleasePool pool;
  200444. [[NSRunLoop currentRunLoop] runUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.01]];
  200445. }
  200446. }
  200447. };
  200448. @implementation JuceURLConnection
  200449. - (JuceURLConnection*) initWithRequest: (NSURLRequest*) req
  200450. withCallback: (URL::OpenStreamProgressCallback*) callback
  200451. withContext: (void*) context;
  200452. {
  200453. [super init];
  200454. request = req;
  200455. [request retain];
  200456. data = [[NSMutableData data] retain];
  200457. dataLock = [[NSLock alloc] init];
  200458. connection = 0;
  200459. initialised = false;
  200460. hasFailed = false;
  200461. hasFinished = false;
  200462. contentLength = -1;
  200463. runLoopThread = new JuceURLConnectionMessageThread (self);
  200464. runLoopThread->startThread();
  200465. while (runLoopThread->isThreadRunning() && ! initialised)
  200466. {
  200467. if (callback != 0)
  200468. callback (context, -1, (int) [[request HTTPBody] length]);
  200469. Thread::sleep (1);
  200470. }
  200471. return self;
  200472. }
  200473. - (void) dealloc
  200474. {
  200475. [self stop];
  200476. delete runLoopThread;
  200477. [connection release];
  200478. [data release];
  200479. [dataLock release];
  200480. [request release];
  200481. [super dealloc];
  200482. }
  200483. - (void) createConnection
  200484. {
  200485. connection = [[NSURLConnection alloc] initWithRequest: request
  200486. delegate: [self retain]];
  200487. if (connection == nil)
  200488. runLoopThread->signalThreadShouldExit();
  200489. }
  200490. - (void) connection: (NSURLConnection*) connection didReceiveResponse: (NSURLResponse*) response
  200491. {
  200492. [dataLock lock];
  200493. [data setLength: 0];
  200494. [dataLock unlock];
  200495. initialised = true;
  200496. contentLength = [response expectedContentLength];
  200497. }
  200498. - (void) connection: (NSURLConnection*) connection didFailWithError: (NSError*) error
  200499. {
  200500. DBG (nsStringToJuce ([error description]));
  200501. hasFailed = true;
  200502. initialised = true;
  200503. runLoopThread->signalThreadShouldExit();
  200504. }
  200505. - (void) connection: (NSURLConnection*) connection didReceiveData: (NSData*) newData
  200506. {
  200507. [dataLock lock];
  200508. [data appendData: newData];
  200509. [dataLock unlock];
  200510. initialised = true;
  200511. }
  200512. - (void) connectionDidFinishLoading: (NSURLConnection*) connection
  200513. {
  200514. hasFinished = true;
  200515. initialised = true;
  200516. runLoopThread->signalThreadShouldExit();
  200517. }
  200518. - (BOOL) isOpen
  200519. {
  200520. return connection != 0 && ! hasFailed;
  200521. }
  200522. - (int) readPosition
  200523. {
  200524. return position;
  200525. }
  200526. - (int) read: (char*) dest numBytes: (int) numNeeded
  200527. {
  200528. int numDone = 0;
  200529. while (numNeeded > 0)
  200530. {
  200531. int available = jmin (numNeeded, (int) [data length]);
  200532. if (available > 0)
  200533. {
  200534. [dataLock lock];
  200535. [data getBytes: dest length: available];
  200536. [data replaceBytesInRange: NSMakeRange (0, available) withBytes: nil length: 0];
  200537. [dataLock unlock];
  200538. numDone += available;
  200539. numNeeded -= available;
  200540. dest += available;
  200541. }
  200542. else
  200543. {
  200544. if (hasFailed || hasFinished)
  200545. break;
  200546. Thread::sleep (1);
  200547. }
  200548. }
  200549. position += numDone;
  200550. return numDone;
  200551. }
  200552. - (void) stop
  200553. {
  200554. [connection cancel];
  200555. runLoopThread->stopThread (10000);
  200556. }
  200557. @end
  200558. BEGIN_JUCE_NAMESPACE
  200559. bool juce_isOnLine()
  200560. {
  200561. return true;
  200562. }
  200563. void* juce_openInternetFile (const String& url,
  200564. const String& headers,
  200565. const MemoryBlock& postData,
  200566. const bool isPost,
  200567. URL::OpenStreamProgressCallback* callback,
  200568. void* callbackContext,
  200569. int timeOutMs)
  200570. {
  200571. const ScopedAutoReleasePool pool;
  200572. NSMutableURLRequest* req = [NSMutableURLRequest
  200573. requestWithURL: [NSURL URLWithString: juceStringToNS (url)]
  200574. cachePolicy: NSURLRequestUseProtocolCachePolicy
  200575. timeoutInterval: timeOutMs <= 0 ? 60.0 : (timeOutMs / 1000.0)];
  200576. if (req == nil)
  200577. return 0;
  200578. [req setHTTPMethod: isPost ? @"POST" : @"GET"];
  200579. //[req setCachePolicy: NSURLRequestReloadIgnoringLocalAndRemoteCacheData];
  200580. StringArray headerLines;
  200581. headerLines.addLines (headers);
  200582. headerLines.removeEmptyStrings (true);
  200583. for (int i = 0; i < headerLines.size(); ++i)
  200584. {
  200585. const String key (headerLines[i].upToFirstOccurrenceOf (T(":"), false, false).trim());
  200586. const String value (headerLines[i].fromFirstOccurrenceOf (T(":"), false, false).trim());
  200587. if (key.isNotEmpty() && value.isNotEmpty())
  200588. [req addValue: juceStringToNS (value) forHTTPHeaderField: juceStringToNS (key)];
  200589. }
  200590. if (isPost && postData.getSize() > 0)
  200591. {
  200592. [req setHTTPBody: [NSData dataWithBytes: postData.getData()
  200593. length: postData.getSize()]];
  200594. }
  200595. JuceURLConnection* const s = [[JuceURLConnection alloc] initWithRequest: req
  200596. withCallback: callback
  200597. withContext: callbackContext];
  200598. if ([s isOpen])
  200599. return s;
  200600. [s release];
  200601. return 0;
  200602. }
  200603. void juce_closeInternetFile (void* handle)
  200604. {
  200605. JuceURLConnection* const s = (JuceURLConnection*) handle;
  200606. if (s != 0)
  200607. {
  200608. const ScopedAutoReleasePool pool;
  200609. [s stop];
  200610. [s release];
  200611. }
  200612. }
  200613. int juce_readFromInternetFile (void* handle, void* buffer, int bytesToRead)
  200614. {
  200615. JuceURLConnection* const s = (JuceURLConnection*) handle;
  200616. if (s != 0)
  200617. {
  200618. const ScopedAutoReleasePool pool;
  200619. return [s read: (char*) buffer numBytes: bytesToRead];
  200620. }
  200621. return 0;
  200622. }
  200623. int64 juce_getInternetFileContentLength (void* handle)
  200624. {
  200625. JuceURLConnection* const s = (JuceURLConnection*) handle;
  200626. if (s != 0)
  200627. return s->contentLength;
  200628. return -1;
  200629. }
  200630. int juce_seekInInternetFile (void* handle, int newPosition)
  200631. {
  200632. JuceURLConnection* const s = (JuceURLConnection*) handle;
  200633. if (s != 0)
  200634. return [s readPosition];
  200635. return 0;
  200636. }
  200637. #endif
  200638. /*** End of inlined file: juce_mac_Network.mm ***/
  200639. /*** Start of inlined file: juce_posix_NamedPipe.cpp ***/
  200640. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  200641. // compiled on its own).
  200642. #if JUCE_INCLUDED_FILE
  200643. struct NamedPipeInternal
  200644. {
  200645. String pipeInName, pipeOutName;
  200646. int pipeIn, pipeOut;
  200647. bool volatile createdPipe, blocked, stopReadOperation;
  200648. static void signalHandler (int) {}
  200649. };
  200650. void NamedPipe::cancelPendingReads()
  200651. {
  200652. while (internal != 0 && ((NamedPipeInternal*) internal)->blocked)
  200653. {
  200654. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  200655. intern->stopReadOperation = true;
  200656. char buffer [1] = { 0 };
  200657. int bytesWritten = (int) ::write (intern->pipeIn, buffer, 1);
  200658. (void) bytesWritten;
  200659. int timeout = 2000;
  200660. while (intern->blocked && --timeout >= 0)
  200661. Thread::sleep (2);
  200662. intern->stopReadOperation = false;
  200663. }
  200664. }
  200665. void NamedPipe::close()
  200666. {
  200667. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  200668. if (intern != 0)
  200669. {
  200670. internal = 0;
  200671. if (intern->pipeIn != -1)
  200672. ::close (intern->pipeIn);
  200673. if (intern->pipeOut != -1)
  200674. ::close (intern->pipeOut);
  200675. if (intern->createdPipe)
  200676. {
  200677. unlink (intern->pipeInName);
  200678. unlink (intern->pipeOutName);
  200679. }
  200680. delete intern;
  200681. }
  200682. }
  200683. bool NamedPipe::openInternal (const String& pipeName, const bool createPipe)
  200684. {
  200685. close();
  200686. NamedPipeInternal* const intern = new NamedPipeInternal();
  200687. internal = intern;
  200688. intern->createdPipe = createPipe;
  200689. intern->blocked = false;
  200690. intern->stopReadOperation = false;
  200691. signal (SIGPIPE, NamedPipeInternal::signalHandler);
  200692. siginterrupt (SIGPIPE, 1);
  200693. const String pipePath (T("/tmp/") + File::createLegalFileName (pipeName));
  200694. intern->pipeInName = pipePath + T("_in");
  200695. intern->pipeOutName = pipePath + T("_out");
  200696. intern->pipeIn = -1;
  200697. intern->pipeOut = -1;
  200698. if (createPipe)
  200699. {
  200700. if ((mkfifo (intern->pipeInName, 0666) && errno != EEXIST)
  200701. || (mkfifo (intern->pipeOutName, 0666) && errno != EEXIST))
  200702. {
  200703. delete intern;
  200704. internal = 0;
  200705. return false;
  200706. }
  200707. }
  200708. return true;
  200709. }
  200710. int NamedPipe::read (void* destBuffer, int maxBytesToRead, int /*timeOutMilliseconds*/)
  200711. {
  200712. int bytesRead = -1;
  200713. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  200714. if (intern != 0)
  200715. {
  200716. intern->blocked = true;
  200717. if (intern->pipeIn == -1)
  200718. {
  200719. if (intern->createdPipe)
  200720. intern->pipeIn = ::open (intern->pipeInName, O_RDWR);
  200721. else
  200722. intern->pipeIn = ::open (intern->pipeOutName, O_RDWR);
  200723. if (intern->pipeIn == -1)
  200724. {
  200725. intern->blocked = false;
  200726. return -1;
  200727. }
  200728. }
  200729. bytesRead = 0;
  200730. char* p = (char*) destBuffer;
  200731. while (bytesRead < maxBytesToRead)
  200732. {
  200733. const int bytesThisTime = maxBytesToRead - bytesRead;
  200734. const int numRead = (int) ::read (intern->pipeIn, p, bytesThisTime);
  200735. if (numRead <= 0 || intern->stopReadOperation)
  200736. {
  200737. bytesRead = -1;
  200738. break;
  200739. }
  200740. bytesRead += numRead;
  200741. p += bytesRead;
  200742. }
  200743. intern->blocked = false;
  200744. }
  200745. return bytesRead;
  200746. }
  200747. int NamedPipe::write (const void* sourceBuffer, int numBytesToWrite, int timeOutMilliseconds)
  200748. {
  200749. int bytesWritten = -1;
  200750. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  200751. if (intern != 0)
  200752. {
  200753. if (intern->pipeOut == -1)
  200754. {
  200755. if (intern->createdPipe)
  200756. intern->pipeOut = ::open (intern->pipeOutName, O_WRONLY);
  200757. else
  200758. intern->pipeOut = ::open (intern->pipeInName, O_WRONLY);
  200759. if (intern->pipeOut == -1)
  200760. {
  200761. return -1;
  200762. }
  200763. }
  200764. const char* p = (const char*) sourceBuffer;
  200765. bytesWritten = 0;
  200766. const uint32 timeOutTime = Time::getMillisecondCounter() + timeOutMilliseconds;
  200767. while (bytesWritten < numBytesToWrite
  200768. && (timeOutMilliseconds < 0 || Time::getMillisecondCounter() < timeOutTime))
  200769. {
  200770. const int bytesThisTime = numBytesToWrite - bytesWritten;
  200771. const int numWritten = (int) ::write (intern->pipeOut, p, bytesThisTime);
  200772. if (numWritten <= 0)
  200773. {
  200774. bytesWritten = -1;
  200775. break;
  200776. }
  200777. bytesWritten += numWritten;
  200778. p += bytesWritten;
  200779. }
  200780. }
  200781. return bytesWritten;
  200782. }
  200783. #endif
  200784. /*** End of inlined file: juce_posix_NamedPipe.cpp ***/
  200785. /*** Start of inlined file: juce_mac_Threads.mm ***/
  200786. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  200787. // compiled on its own).
  200788. #if JUCE_INCLUDED_FILE
  200789. void JUCE_API juce_threadEntryPoint (void*);
  200790. void* threadEntryProc (void* userData)
  200791. {
  200792. const ScopedAutoReleasePool pool;
  200793. juce_threadEntryPoint (userData);
  200794. return 0;
  200795. }
  200796. void* juce_createThread (void* userData)
  200797. {
  200798. pthread_t handle = 0;
  200799. if (pthread_create (&handle, 0, threadEntryProc, userData) == 0)
  200800. {
  200801. pthread_detach (handle);
  200802. return (void*) handle;
  200803. }
  200804. return 0;
  200805. }
  200806. void juce_killThread (void* handle)
  200807. {
  200808. if (handle != 0)
  200809. pthread_cancel ((pthread_t) handle);
  200810. }
  200811. void juce_setCurrentThreadName (const String& /*name*/)
  200812. {
  200813. }
  200814. Thread::ThreadID Thread::getCurrentThreadId()
  200815. {
  200816. return (ThreadID) pthread_self();
  200817. }
  200818. bool juce_setThreadPriority (void* handle, int priority)
  200819. {
  200820. if (handle == 0)
  200821. handle = (void*) pthread_self();
  200822. struct sched_param param;
  200823. int policy;
  200824. pthread_getschedparam ((pthread_t) handle, &policy, &param);
  200825. param.sched_priority = jlimit (1, 127, 1 + (priority * 126) / 11);
  200826. return pthread_setschedparam ((pthread_t) handle, policy, &param) == 0;
  200827. }
  200828. void Thread::yield()
  200829. {
  200830. sched_yield();
  200831. }
  200832. void Thread::setCurrentThreadAffinityMask (const uint32 affinityMask)
  200833. {
  200834. // xxx
  200835. jassertfalse
  200836. }
  200837. bool Process::isForegroundProcess()
  200838. {
  200839. #if JUCE_MAC
  200840. return [NSApp isActive];
  200841. #else
  200842. return true; // xxx change this if more than one app is ever possible on the iPhone!
  200843. #endif
  200844. }
  200845. void Process::raisePrivilege()
  200846. {
  200847. jassertfalse
  200848. }
  200849. void Process::lowerPrivilege()
  200850. {
  200851. jassertfalse
  200852. }
  200853. void Process::terminate()
  200854. {
  200855. exit (0);
  200856. }
  200857. void Process::setPriority (ProcessPriority p)
  200858. {
  200859. // xxx
  200860. }
  200861. #endif
  200862. /*** End of inlined file: juce_mac_Threads.mm ***/
  200863. /*** Start of inlined file: juce_posix_SharedCode.h ***/
  200864. CriticalSection::CriticalSection() throw()
  200865. {
  200866. pthread_mutexattr_t atts;
  200867. pthread_mutexattr_init (&atts);
  200868. pthread_mutexattr_settype (&atts, PTHREAD_MUTEX_RECURSIVE);
  200869. pthread_mutex_init (&internal, &atts);
  200870. }
  200871. CriticalSection::~CriticalSection() throw()
  200872. {
  200873. pthread_mutex_destroy (&internal);
  200874. }
  200875. void CriticalSection::enter() const throw()
  200876. {
  200877. pthread_mutex_lock (&internal);
  200878. }
  200879. bool CriticalSection::tryEnter() const throw()
  200880. {
  200881. return pthread_mutex_trylock (&internal) == 0;
  200882. }
  200883. void CriticalSection::exit() const throw()
  200884. {
  200885. pthread_mutex_unlock (&internal);
  200886. }
  200887. struct EventStruct
  200888. {
  200889. pthread_cond_t condition;
  200890. pthread_mutex_t mutex;
  200891. bool triggered;
  200892. };
  200893. WaitableEvent::WaitableEvent() throw()
  200894. {
  200895. EventStruct* const es = new EventStruct();
  200896. es->triggered = false;
  200897. pthread_cond_init (&es->condition, 0);
  200898. pthread_mutex_init (&es->mutex, 0);
  200899. internal = es;
  200900. }
  200901. WaitableEvent::~WaitableEvent() throw()
  200902. {
  200903. EventStruct* const es = (EventStruct*) internal;
  200904. pthread_cond_destroy (&es->condition);
  200905. pthread_mutex_destroy (&es->mutex);
  200906. delete es;
  200907. }
  200908. bool WaitableEvent::wait (const int timeOutMillisecs) const throw()
  200909. {
  200910. EventStruct* const es = (EventStruct*) internal;
  200911. pthread_mutex_lock (&es->mutex);
  200912. if (timeOutMillisecs < 0)
  200913. {
  200914. while (! es->triggered)
  200915. pthread_cond_wait (&es->condition, &es->mutex);
  200916. }
  200917. else
  200918. {
  200919. while (! es->triggered)
  200920. {
  200921. struct timeval t;
  200922. gettimeofday (&t, 0);
  200923. struct timespec time;
  200924. time.tv_sec = t.tv_sec + (timeOutMillisecs / 1000);
  200925. time.tv_nsec = (t.tv_usec + ((timeOutMillisecs % 1000) * 1000)) * 1000;
  200926. if (time.tv_nsec >= 1000000000)
  200927. {
  200928. time.tv_nsec -= 1000000000;
  200929. time.tv_sec++;
  200930. }
  200931. if (pthread_cond_timedwait (&es->condition, &es->mutex, &time) == ETIMEDOUT)
  200932. {
  200933. pthread_mutex_unlock (&es->mutex);
  200934. return false;
  200935. }
  200936. }
  200937. }
  200938. es->triggered = false;
  200939. pthread_mutex_unlock (&es->mutex);
  200940. return true;
  200941. }
  200942. void WaitableEvent::signal() const throw()
  200943. {
  200944. EventStruct* const es = (EventStruct*) internal;
  200945. pthread_mutex_lock (&es->mutex);
  200946. es->triggered = true;
  200947. pthread_cond_broadcast (&es->condition);
  200948. pthread_mutex_unlock (&es->mutex);
  200949. }
  200950. void WaitableEvent::reset() const throw()
  200951. {
  200952. EventStruct* const es = (EventStruct*) internal;
  200953. pthread_mutex_lock (&es->mutex);
  200954. es->triggered = false;
  200955. pthread_mutex_unlock (&es->mutex);
  200956. }
  200957. void JUCE_CALLTYPE Thread::sleep (int millisecs)
  200958. {
  200959. struct timespec time;
  200960. time.tv_sec = millisecs / 1000;
  200961. time.tv_nsec = (millisecs % 1000) * 1000000;
  200962. nanosleep (&time, 0);
  200963. }
  200964. const tchar File::separator = T('/');
  200965. const tchar* File::separatorString = T("/");
  200966. bool juce_copyFile (const String& s, const String& d);
  200967. static bool juce_stat (const String& fileName, struct stat& info)
  200968. {
  200969. return fileName.isNotEmpty()
  200970. && (stat (fileName.toUTF8(), &info) == 0);
  200971. }
  200972. bool juce_isDirectory (const String& fileName)
  200973. {
  200974. struct stat info;
  200975. return fileName.isEmpty()
  200976. || (juce_stat (fileName, info)
  200977. && ((info.st_mode & S_IFDIR) != 0));
  200978. }
  200979. bool juce_fileExists (const String& fileName, const bool dontCountDirectories)
  200980. {
  200981. if (fileName.isEmpty())
  200982. return false;
  200983. const char* const fileNameUTF8 = fileName.toUTF8();
  200984. bool exists = access (fileNameUTF8, F_OK) == 0;
  200985. if (exists && dontCountDirectories)
  200986. {
  200987. struct stat info;
  200988. const int res = stat (fileNameUTF8, &info);
  200989. if (res == 0 && (info.st_mode & S_IFDIR) != 0)
  200990. exists = false;
  200991. }
  200992. return exists;
  200993. }
  200994. int64 juce_getFileSize (const String& fileName)
  200995. {
  200996. struct stat info;
  200997. return juce_stat (fileName, info) ? info.st_size : 0;
  200998. }
  200999. bool juce_canWriteToFile (const String& fileName)
  201000. {
  201001. return access (fileName.toUTF8(), W_OK) == 0;
  201002. }
  201003. bool juce_deleteFile (const String& fileName)
  201004. {
  201005. if (juce_isDirectory (fileName))
  201006. return rmdir ((const char*) fileName.toUTF8()) == 0;
  201007. else
  201008. return remove ((const char*) fileName.toUTF8()) == 0;
  201009. }
  201010. bool juce_moveFile (const String& source, const String& dest)
  201011. {
  201012. if (rename (source.toUTF8(), dest.toUTF8()) == 0)
  201013. return true;
  201014. if (juce_canWriteToFile (source)
  201015. && juce_copyFile (source, dest))
  201016. {
  201017. if (juce_deleteFile (source))
  201018. return true;
  201019. juce_deleteFile (dest);
  201020. }
  201021. return false;
  201022. }
  201023. void juce_createDirectory (const String& fileName)
  201024. {
  201025. mkdir (fileName.toUTF8(), 0777);
  201026. }
  201027. void* juce_fileOpen (const String& fileName, bool forWriting)
  201028. {
  201029. int flags = O_RDONLY;
  201030. if (forWriting)
  201031. {
  201032. if (juce_fileExists (fileName, false))
  201033. {
  201034. const int f = open ((const char*) fileName.toUTF8(), O_RDWR, 00644);
  201035. if (f != -1)
  201036. lseek (f, 0, SEEK_END);
  201037. return (void*) f;
  201038. }
  201039. else
  201040. {
  201041. flags = O_RDWR + O_CREAT;
  201042. }
  201043. }
  201044. return (void*) open ((const char*) fileName.toUTF8(), flags, 00644);
  201045. }
  201046. void juce_fileClose (void* handle)
  201047. {
  201048. if (handle != 0)
  201049. close ((int) (pointer_sized_int) handle);
  201050. }
  201051. int juce_fileRead (void* handle, void* buffer, int size)
  201052. {
  201053. if (handle != 0)
  201054. return (int) read ((int) (pointer_sized_int) handle, buffer, size);
  201055. return 0;
  201056. }
  201057. int juce_fileWrite (void* handle, const void* buffer, int size)
  201058. {
  201059. if (handle != 0)
  201060. return (int) write ((int) (pointer_sized_int) handle, buffer, size);
  201061. return 0;
  201062. }
  201063. int64 juce_fileSetPosition (void* handle, int64 pos)
  201064. {
  201065. if (handle != 0 && lseek ((int) (pointer_sized_int) handle, pos, SEEK_SET) == pos)
  201066. return pos;
  201067. return -1;
  201068. }
  201069. int64 juce_fileGetPosition (void* handle)
  201070. {
  201071. if (handle != 0)
  201072. return lseek ((int) (pointer_sized_int) handle, 0, SEEK_CUR);
  201073. else
  201074. return -1;
  201075. }
  201076. void juce_fileFlush (void* handle)
  201077. {
  201078. if (handle != 0)
  201079. fsync ((int) (pointer_sized_int) handle);
  201080. }
  201081. const File juce_getExecutableFile()
  201082. {
  201083. Dl_info exeInfo;
  201084. dladdr ((const void*) juce_getExecutableFile, &exeInfo);
  201085. return File (exeInfo.dli_fname);
  201086. }
  201087. // if this file doesn't exist, find a parent of it that does..
  201088. static bool doStatFS (const File* file, struct statfs& result)
  201089. {
  201090. File f (*file);
  201091. for (int i = 5; --i >= 0;)
  201092. {
  201093. if (f.exists())
  201094. break;
  201095. f = f.getParentDirectory();
  201096. }
  201097. return statfs (f.getFullPathName().toUTF8(), &result) == 0;
  201098. }
  201099. int64 File::getBytesFreeOnVolume() const
  201100. {
  201101. struct statfs buf;
  201102. if (doStatFS (this, buf))
  201103. return (int64) buf.f_bsize * (int64) buf.f_bavail; // Note: this returns space available to non-super user
  201104. return 0;
  201105. }
  201106. int64 File::getVolumeTotalSize() const
  201107. {
  201108. struct statfs buf;
  201109. if (doStatFS (this, buf))
  201110. return (int64) buf.f_bsize * (int64) buf.f_blocks;
  201111. return 0;
  201112. }
  201113. const String juce_getVolumeLabel (const String& filenameOnVolume,
  201114. int& volumeSerialNumber)
  201115. {
  201116. volumeSerialNumber = 0;
  201117. #if JUCE_MAC
  201118. struct VolAttrBuf
  201119. {
  201120. u_int32_t length;
  201121. attrreference_t mountPointRef;
  201122. char mountPointSpace [MAXPATHLEN];
  201123. } attrBuf;
  201124. struct attrlist attrList;
  201125. zerostruct (attrList);
  201126. attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
  201127. attrList.volattr = ATTR_VOL_INFO | ATTR_VOL_NAME;
  201128. File f (filenameOnVolume);
  201129. for (;;)
  201130. {
  201131. if (getattrlist ((const char*) f.getFullPathName().toUTF8(),
  201132. &attrList, &attrBuf, sizeof(attrBuf), 0) == 0)
  201133. {
  201134. return String::fromUTF8 (((const uint8*) &attrBuf.mountPointRef) + attrBuf.mountPointRef.attr_dataoffset,
  201135. (int) attrBuf.mountPointRef.attr_length);
  201136. }
  201137. const File parent (f.getParentDirectory());
  201138. if (f == parent)
  201139. break;
  201140. f = parent;
  201141. }
  201142. #endif
  201143. return String::empty;
  201144. }
  201145. void juce_runSystemCommand (const String& command)
  201146. {
  201147. int result = system ((const char*) command.toUTF8());
  201148. (void) result;
  201149. }
  201150. const String juce_getOutputFromCommand (const String& command)
  201151. {
  201152. // slight bodge here, as we just pipe the output into a temp file and read it...
  201153. const File tempFile (File::getSpecialLocation (File::tempDirectory)
  201154. .getNonexistentChildFile (String::toHexString (Random::getSystemRandom().nextInt()), ".tmp", false));
  201155. juce_runSystemCommand (command + " > " + tempFile.getFullPathName());
  201156. String result (tempFile.loadFileAsString());
  201157. tempFile.deleteFile();
  201158. return result;
  201159. }
  201160. InterProcessLock::InterProcessLock (const String& name_)
  201161. : internal (0),
  201162. name (name_),
  201163. reentrancyLevel (0)
  201164. {
  201165. #if JUCE_MAC
  201166. // (don't use getSpecialLocation() to avoid the temp folder being different for each app)
  201167. const File temp (File (T("~/Library/Caches/Juce")).getChildFile (name));
  201168. #else
  201169. const File temp (File::getSpecialLocation (File::tempDirectory).getChildFile (name));
  201170. #endif
  201171. temp.create();
  201172. internal = open (temp.getFullPathName().toUTF8(), O_RDWR);
  201173. }
  201174. InterProcessLock::~InterProcessLock()
  201175. {
  201176. while (reentrancyLevel > 0)
  201177. this->exit();
  201178. close (internal);
  201179. }
  201180. bool InterProcessLock::enter (const int timeOutMillisecs)
  201181. {
  201182. if (internal == 0)
  201183. return false;
  201184. if (reentrancyLevel != 0)
  201185. return true;
  201186. const int64 endTime = Time::currentTimeMillis() + timeOutMillisecs;
  201187. struct flock fl;
  201188. zerostruct (fl);
  201189. fl.l_whence = SEEK_SET;
  201190. fl.l_type = F_WRLCK;
  201191. for (;;)
  201192. {
  201193. const int result = fcntl (internal, F_SETLK, &fl);
  201194. if (result >= 0)
  201195. {
  201196. ++reentrancyLevel;
  201197. return true;
  201198. }
  201199. if (errno != EINTR)
  201200. {
  201201. if (timeOutMillisecs == 0
  201202. || (timeOutMillisecs > 0 && Time::currentTimeMillis() >= endTime))
  201203. break;
  201204. Thread::sleep (10);
  201205. }
  201206. }
  201207. return false;
  201208. }
  201209. void InterProcessLock::exit()
  201210. {
  201211. if (reentrancyLevel > 0 && internal != 0)
  201212. {
  201213. --reentrancyLevel;
  201214. struct flock fl;
  201215. zerostruct (fl);
  201216. fl.l_whence = SEEK_SET;
  201217. fl.l_type = F_UNLCK;
  201218. for (;;)
  201219. {
  201220. const int result = fcntl (internal, F_SETLKW, &fl);
  201221. if (result >= 0 || errno != EINTR)
  201222. break;
  201223. }
  201224. }
  201225. }
  201226. /*** End of inlined file: juce_posix_SharedCode.h ***/
  201227. /*** Start of inlined file: juce_mac_Files.mm ***/
  201228. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201229. // compiled on its own).
  201230. #if JUCE_INCLUDED_FILE
  201231. void juce_getFileTimes (const String& fileName,
  201232. int64& modificationTime,
  201233. int64& accessTime,
  201234. int64& creationTime)
  201235. {
  201236. modificationTime = 0;
  201237. accessTime = 0;
  201238. creationTime = 0;
  201239. struct stat info;
  201240. const int res = stat (fileName.toUTF8(), &info);
  201241. if (res == 0)
  201242. {
  201243. modificationTime = (int64) info.st_mtime * 1000;
  201244. accessTime = (int64) info.st_atime * 1000;
  201245. creationTime = (int64) info.st_ctime * 1000;
  201246. }
  201247. }
  201248. bool juce_setFileTimes (const String& fileName,
  201249. int64 modificationTime,
  201250. int64 accessTime,
  201251. int64 creationTime)
  201252. {
  201253. struct utimbuf times;
  201254. times.actime = (time_t) (accessTime / 1000);
  201255. times.modtime = (time_t) (modificationTime / 1000);
  201256. return utime (fileName.toUTF8(), &times) == 0;
  201257. }
  201258. bool juce_setFileReadOnly (const String& fileName, bool isReadOnly)
  201259. {
  201260. struct stat info;
  201261. const int res = stat (fileName.toUTF8(), &info);
  201262. if (res != 0)
  201263. return false;
  201264. info.st_mode &= 0777; // Just permissions
  201265. if (isReadOnly)
  201266. info.st_mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH);
  201267. else
  201268. // Give everybody write permission?
  201269. info.st_mode |= S_IWUSR | S_IWGRP | S_IWOTH;
  201270. return chmod (fileName.toUTF8(), info.st_mode) == 0;
  201271. }
  201272. bool juce_copyFile (const String& src, const String& dst)
  201273. {
  201274. const ScopedAutoReleasePool pool;
  201275. NSFileManager* fm = [NSFileManager defaultManager];
  201276. return [fm fileExistsAtPath: juceStringToNS (src)]
  201277. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  201278. && [fm copyItemAtPath: juceStringToNS (src)
  201279. toPath: juceStringToNS (dst)
  201280. error: nil];
  201281. #else
  201282. && [fm copyPath: juceStringToNS (src)
  201283. toPath: juceStringToNS (dst)
  201284. handler: nil];
  201285. #endif
  201286. }
  201287. const StringArray juce_getFileSystemRoots()
  201288. {
  201289. StringArray s;
  201290. s.add (T("/"));
  201291. return s;
  201292. }
  201293. static bool isFileOnDriveType (const File* const f, const char** types)
  201294. {
  201295. struct statfs buf;
  201296. if (doStatFS (f, buf))
  201297. {
  201298. const String type (buf.f_fstypename);
  201299. while (*types != 0)
  201300. if (type.equalsIgnoreCase (*types++))
  201301. return true;
  201302. }
  201303. return false;
  201304. }
  201305. bool File::isOnCDRomDrive() const
  201306. {
  201307. static const char* const cdTypes[] = { "cd9660", "cdfs", "cddafs", "udf", 0 };
  201308. return isFileOnDriveType (this, (const char**) cdTypes);
  201309. }
  201310. bool File::isOnHardDisk() const
  201311. {
  201312. static const char* const nonHDTypes[] = { "nfs", "smbfs", "ramfs", 0 };
  201313. return ! (isOnCDRomDrive() || isFileOnDriveType (this, (const char**) nonHDTypes));
  201314. }
  201315. bool File::isOnRemovableDrive() const
  201316. {
  201317. #if JUCE_IPHONE
  201318. return false; // xxx is this possible?
  201319. #else
  201320. const ScopedAutoReleasePool pool;
  201321. BOOL removable = false;
  201322. [[NSWorkspace sharedWorkspace]
  201323. getFileSystemInfoForPath: juceStringToNS (getFullPathName())
  201324. isRemovable: &removable
  201325. isWritable: nil
  201326. isUnmountable: nil
  201327. description: nil
  201328. type: nil];
  201329. return removable;
  201330. #endif
  201331. }
  201332. static bool juce_isHiddenFile (const String& path)
  201333. {
  201334. #if JUCE_IPHONE
  201335. return File (path).getFileName().startsWithChar (T('.'));
  201336. #else
  201337. FSRef ref;
  201338. if (! PlatformUtilities::makeFSRefFromPath (&ref, path))
  201339. return false;
  201340. FSCatalogInfo info;
  201341. FSGetCatalogInfo (&ref, kFSCatInfoNodeFlags | kFSCatInfoFinderInfo, &info, 0, 0, 0);
  201342. if ((info.nodeFlags & kFSNodeIsDirectoryBit) != 0)
  201343. return (((FolderInfo*) &info.finderInfo)->finderFlags & kIsInvisible) != 0;
  201344. return (((FileInfo*) &info.finderInfo)->finderFlags & kIsInvisible) != 0;
  201345. #endif
  201346. }
  201347. bool File::isHidden() const
  201348. {
  201349. return juce_isHiddenFile (getFullPathName());
  201350. }
  201351. const char* juce_Argv0 = 0; // referenced from juce_Application.cpp
  201352. const File File::getSpecialLocation (const SpecialLocationType type)
  201353. {
  201354. const ScopedAutoReleasePool pool;
  201355. String resultPath;
  201356. switch (type)
  201357. {
  201358. case userHomeDirectory:
  201359. resultPath = nsStringToJuce (NSHomeDirectory());
  201360. break;
  201361. case userDocumentsDirectory:
  201362. resultPath = "~/Documents";
  201363. break;
  201364. case userDesktopDirectory:
  201365. resultPath = "~/Desktop";
  201366. break;
  201367. case userApplicationDataDirectory:
  201368. resultPath = "~/Library";
  201369. break;
  201370. case commonApplicationDataDirectory:
  201371. resultPath = "/Library";
  201372. break;
  201373. case globalApplicationsDirectory:
  201374. resultPath = "/Applications";
  201375. break;
  201376. case userMusicDirectory:
  201377. resultPath = "~/Music";
  201378. break;
  201379. case userMoviesDirectory:
  201380. resultPath = "~/Movies";
  201381. break;
  201382. case tempDirectory:
  201383. {
  201384. File tmp (T("~/Library/Caches/") + juce_getExecutableFile().getFileNameWithoutExtension());
  201385. tmp.createDirectory();
  201386. return tmp.getFullPathName();
  201387. }
  201388. case invokedExecutableFile:
  201389. if (juce_Argv0 != 0)
  201390. return File (String::fromUTF8 ((const uint8*) juce_Argv0));
  201391. // deliberate fall-through...
  201392. case currentExecutableFile:
  201393. return juce_getExecutableFile();
  201394. case currentApplicationFile:
  201395. {
  201396. const File exe (juce_getExecutableFile());
  201397. const File parent (exe.getParentDirectory());
  201398. return parent.getFullPathName().endsWithIgnoreCase (T("Contents/MacOS"))
  201399. ? parent.getParentDirectory().getParentDirectory()
  201400. : exe;
  201401. }
  201402. default:
  201403. jassertfalse // unknown type?
  201404. break;
  201405. }
  201406. if (resultPath != 0)
  201407. return File (PlatformUtilities::convertToPrecomposedUnicode (resultPath));
  201408. return File::nonexistent;
  201409. }
  201410. const File File::getCurrentWorkingDirectory()
  201411. {
  201412. char buf [2048];
  201413. getcwd (buf, sizeof(buf));
  201414. return File (PlatformUtilities::convertToPrecomposedUnicode (buf));
  201415. }
  201416. bool File::setAsCurrentWorkingDirectory() const
  201417. {
  201418. return chdir (getFullPathName().toUTF8()) == 0;
  201419. }
  201420. const String File::getVersion() const
  201421. {
  201422. const ScopedAutoReleasePool pool;
  201423. String result;
  201424. NSBundle* bundle = [NSBundle bundleWithPath: juceStringToNS (getFullPathName())];
  201425. if (bundle != 0)
  201426. {
  201427. NSDictionary* info = [bundle infoDictionary];
  201428. if (info != 0)
  201429. {
  201430. NSString* name = [info valueForKey: @"CFBundleShortVersionString"];
  201431. if (name != nil)
  201432. result = nsStringToJuce (name);
  201433. }
  201434. }
  201435. return result;
  201436. }
  201437. const File File::getLinkedTarget() const
  201438. {
  201439. #if JUCE_IPHONE || (defined (MAC_OS_X_VERSION_10_5) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
  201440. NSString* dest = [[NSFileManager defaultManager] destinationOfSymbolicLinkAtPath: juceStringToNS (getFullPathName()) error: nil];
  201441. #else
  201442. NSString* dest = [[NSFileManager defaultManager] pathContentOfSymbolicLinkAtPath: juceStringToNS (getFullPathName())];
  201443. #endif
  201444. if (dest != nil)
  201445. return File (nsStringToJuce (dest));
  201446. return *this;
  201447. }
  201448. bool File::moveToTrash() const
  201449. {
  201450. if (! exists())
  201451. return true;
  201452. #if JUCE_IPHONE
  201453. return deleteFile(); //xxx is there a trashcan on the iPhone?
  201454. #else
  201455. const ScopedAutoReleasePool pool;
  201456. NSString* p = juceStringToNS (getFullPathName());
  201457. return [[NSWorkspace sharedWorkspace]
  201458. performFileOperation: NSWorkspaceRecycleOperation
  201459. source: [p stringByDeletingLastPathComponent]
  201460. destination: @""
  201461. files: [NSArray arrayWithObject: [p lastPathComponent]]
  201462. tag: nil ];
  201463. #endif
  201464. }
  201465. struct FindFileStruct
  201466. {
  201467. NSDirectoryEnumerator* enumerator;
  201468. String parentDir, wildCard;
  201469. };
  201470. bool juce_findFileNext (void* handle, String& resultFile,
  201471. bool* isDir, bool* isHidden, int64* fileSize, Time* modTime, Time* creationTime, bool* isReadOnly)
  201472. {
  201473. ScopedAutoReleasePool pool;
  201474. FindFileStruct* ff = (FindFileStruct*) handle;
  201475. NSString* file;
  201476. const char* const wildcardUTF8 = ff->wildCard.toUTF8();
  201477. for (;;)
  201478. {
  201479. if (ff == 0 || (file = [ff->enumerator nextObject]) == 0)
  201480. return false;
  201481. [ff->enumerator skipDescendents];
  201482. resultFile = nsStringToJuce (file);
  201483. if (fnmatch (wildcardUTF8, resultFile.toUTF8(), FNM_CASEFOLD) != 0)
  201484. continue;
  201485. const String path (ff->parentDir + resultFile);
  201486. if (isDir != 0 || fileSize != 0)
  201487. {
  201488. struct stat info;
  201489. const bool statOk = juce_stat (path, info);
  201490. if (isDir != 0)
  201491. *isDir = statOk && ((info.st_mode & S_IFDIR) != 0);
  201492. if (isHidden != 0)
  201493. *isHidden = juce_isHiddenFile (path);
  201494. if (fileSize != 0)
  201495. *fileSize = statOk ? info.st_size : 0;
  201496. }
  201497. if (modTime != 0 || creationTime != 0)
  201498. {
  201499. int64 m, a, c;
  201500. juce_getFileTimes (path, m, a, c);
  201501. if (modTime != 0)
  201502. *modTime = m;
  201503. if (creationTime != 0)
  201504. *creationTime = c;
  201505. }
  201506. if (isReadOnly != 0)
  201507. *isReadOnly = ! juce_canWriteToFile (path);
  201508. return true;
  201509. }
  201510. }
  201511. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  201512. bool* isDir, bool* isHidden, int64* fileSize, Time* modTime,
  201513. Time* creationTime, bool* isReadOnly)
  201514. {
  201515. ScopedAutoReleasePool pool;
  201516. NSDirectoryEnumerator* e = [[NSFileManager defaultManager] enumeratorAtPath: juceStringToNS (directory)];
  201517. if (e != 0)
  201518. {
  201519. ScopedPointer <FindFileStruct> ff (new FindFileStruct());
  201520. ff->enumerator = [e retain];
  201521. ff->parentDir = directory;
  201522. ff->wildCard = wildCard;
  201523. if (! ff->parentDir.endsWithChar (File::separator))
  201524. ff->parentDir += File::separator;
  201525. if (juce_findFileNext (ff, firstResultFile, isDir, isHidden, fileSize, modTime, creationTime, isReadOnly))
  201526. return ff.release();
  201527. [e release];
  201528. }
  201529. return 0;
  201530. }
  201531. void juce_findFileClose (void* handle)
  201532. {
  201533. ScopedAutoReleasePool pool;
  201534. ScopedPointer <FindFileStruct> ff ((FindFileStruct*) handle);
  201535. [ff->enumerator release];
  201536. }
  201537. bool juce_launchExecutable (const String& pathAndArguments)
  201538. {
  201539. const char* const argv[4] = { "/bin/sh", "-c", (const char*) pathAndArguments, 0 };
  201540. const int cpid = fork();
  201541. if (cpid == 0)
  201542. {
  201543. // Child process
  201544. if (execve (argv[0], (char**) argv, 0) < 0)
  201545. exit (0);
  201546. }
  201547. else
  201548. {
  201549. if (cpid < 0)
  201550. return false;
  201551. }
  201552. return true;
  201553. }
  201554. bool juce_launchFile (const String& fileName, const String& parameters)
  201555. {
  201556. #if JUCE_IPHONE
  201557. return [[UIApplication sharedApplication] openURL: [NSURL fileURLWithPath: juceStringToNS (fileName)]];
  201558. #else
  201559. const ScopedAutoReleasePool pool;
  201560. if (parameters.isEmpty())
  201561. {
  201562. return [[NSWorkspace sharedWorkspace] openFile: juceStringToNS (fileName)]
  201563. || [[NSWorkspace sharedWorkspace] openURL: [NSURL URLWithString: juceStringToNS (fileName)]];
  201564. }
  201565. bool ok = false;
  201566. FSRef ref;
  201567. if (PlatformUtilities::makeFSRefFromPath (&ref, fileName))
  201568. {
  201569. if (PlatformUtilities::isBundle (fileName))
  201570. {
  201571. NSMutableArray* urls = [NSMutableArray array];
  201572. StringArray docs;
  201573. docs.addTokens (parameters, true);
  201574. for (int i = 0; i < docs.size(); ++i)
  201575. [urls addObject: juceStringToNS (docs[i])];
  201576. ok = [[NSWorkspace sharedWorkspace] openURLs: urls
  201577. withAppBundleIdentifier: [[NSBundle bundleWithPath: juceStringToNS (fileName)] bundleIdentifier]
  201578. options: 0
  201579. additionalEventParamDescriptor: nil
  201580. launchIdentifiers: nil];
  201581. }
  201582. else
  201583. {
  201584. ok = juce_launchExecutable (T("\"") + fileName + T("\" ") + parameters);
  201585. }
  201586. }
  201587. return ok;
  201588. #endif
  201589. }
  201590. void File::revealToUser() const
  201591. {
  201592. #if ! JUCE_IPHONE
  201593. if (exists())
  201594. [[NSWorkspace sharedWorkspace] selectFile: juceStringToNS (getFullPathName()) inFileViewerRootedAtPath: @""];
  201595. else if (getParentDirectory().exists())
  201596. getParentDirectory().revealToUser();
  201597. #endif
  201598. }
  201599. #if ! JUCE_IPHONE
  201600. bool PlatformUtilities::makeFSRefFromPath (FSRef* destFSRef, const String& path)
  201601. {
  201602. return FSPathMakeRef ((const UInt8*) path.toUTF8(), destFSRef, 0) == noErr;
  201603. }
  201604. const String PlatformUtilities::makePathFromFSRef (FSRef* file)
  201605. {
  201606. uint8 path [2048];
  201607. zeromem (path, sizeof (path));
  201608. String result;
  201609. if (FSRefMakePath (file, (UInt8*) path, sizeof (path) - 1) == noErr)
  201610. result = String::fromUTF8 (path);
  201611. return PlatformUtilities::convertToPrecomposedUnicode (result);
  201612. }
  201613. #endif
  201614. OSType PlatformUtilities::getTypeOfFile (const String& filename)
  201615. {
  201616. const ScopedAutoReleasePool pool;
  201617. #if JUCE_IPHONE || (defined (MAC_OS_X_VERSION_10_5) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
  201618. NSDictionary* fileDict = [[NSFileManager defaultManager] attributesOfItemAtPath: juceStringToNS (filename) error: nil];
  201619. #else
  201620. NSDictionary* fileDict = [[NSFileManager defaultManager] fileAttributesAtPath: juceStringToNS (filename) traverseLink: NO];
  201621. #endif
  201622. //return (OSType) [fileDict objectForKey: NSFileHFSTypeCode];
  201623. return [fileDict fileHFSTypeCode];
  201624. }
  201625. bool PlatformUtilities::isBundle (const String& filename)
  201626. {
  201627. #if JUCE_IPHONE
  201628. return false; // xxx can't find a sensible way to do this without trying to open the bundle..
  201629. #else
  201630. const ScopedAutoReleasePool pool;
  201631. return [[NSWorkspace sharedWorkspace] isFilePackageAtPath: juceStringToNS (filename)];
  201632. #endif
  201633. }
  201634. #endif
  201635. /*** End of inlined file: juce_mac_Files.mm ***/
  201636. #if JUCE_IPHONE
  201637. /*** Start of inlined file: juce_iphone_MiscUtilities.mm ***/
  201638. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201639. // compiled on its own).
  201640. #if JUCE_INCLUDED_FILE
  201641. static JUCEApplication* juce_intialisingApp;
  201642. END_JUCE_NAMESPACE
  201643. @interface JuceAppStartupDelegate : NSObject <UIApplicationDelegate>
  201644. {
  201645. }
  201646. - (void) applicationDidFinishLaunching: (UIApplication*) application;
  201647. - (void) applicationWillResignActive: (UIApplication*) application;
  201648. @end
  201649. @implementation JuceAppStartupDelegate
  201650. - (void) applicationDidFinishLaunching: (UIApplication*) application
  201651. {
  201652. String dummy;
  201653. if (! juce_intialisingApp->initialiseApp (dummy))
  201654. exit (0);
  201655. }
  201656. - (void) applicationWillResignActive: (UIApplication*) application
  201657. {
  201658. JUCEApplication::shutdownAppAndClearUp();
  201659. }
  201660. @end
  201661. BEGIN_JUCE_NAMESPACE
  201662. int juce_IPhoneMain (int argc, char* argv[], JUCEApplication* app)
  201663. {
  201664. juce_intialisingApp = app;
  201665. return UIApplicationMain (argc, argv, nil, @"JuceAppStartupDelegate");
  201666. }
  201667. ScopedAutoReleasePool::ScopedAutoReleasePool()
  201668. {
  201669. pool = [[NSAutoreleasePool alloc] init];
  201670. }
  201671. ScopedAutoReleasePool::~ScopedAutoReleasePool()
  201672. {
  201673. [((NSAutoreleasePool*) pool) release];
  201674. }
  201675. void PlatformUtilities::beep()
  201676. {
  201677. //xxx
  201678. //AudioServicesPlaySystemSound ();
  201679. }
  201680. void PlatformUtilities::addItemToDock (const File& file)
  201681. {
  201682. }
  201683. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  201684. END_JUCE_NAMESPACE
  201685. @interface JuceAlertBoxDelegate : NSObject
  201686. {
  201687. @public
  201688. bool clickedOk;
  201689. }
  201690. - (void) alertView: (UIAlertView*) alertView clickedButtonAtIndex: (NSInteger) buttonIndex;
  201691. @end
  201692. @implementation JuceAlertBoxDelegate
  201693. - (void) alertView: (UIAlertView*) alertView clickedButtonAtIndex: (NSInteger) buttonIndex
  201694. {
  201695. clickedOk = (buttonIndex == 0);
  201696. alertView.hidden = true;
  201697. }
  201698. @end
  201699. BEGIN_JUCE_NAMESPACE
  201700. // (This function is used directly by other bits of code)
  201701. bool juce_iPhoneShowModalAlert (const String& title,
  201702. const String& bodyText,
  201703. NSString* okButtonText,
  201704. NSString* cancelButtonText)
  201705. {
  201706. const ScopedAutoReleasePool pool;
  201707. JuceAlertBoxDelegate* callback = [[JuceAlertBoxDelegate alloc] init];
  201708. UIAlertView* alert = [[UIAlertView alloc] initWithTitle: juceStringToNS (title)
  201709. message: juceStringToNS (bodyText)
  201710. delegate: callback
  201711. cancelButtonTitle: okButtonText
  201712. otherButtonTitles: cancelButtonText, nil];
  201713. [alert retain];
  201714. [alert show];
  201715. while (! alert.hidden && alert.superview != nil)
  201716. [[NSRunLoop mainRunLoop] runUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.01]];
  201717. const bool result = callback->clickedOk;
  201718. [alert release];
  201719. [callback release];
  201720. return result;
  201721. }
  201722. bool AlertWindow::showNativeDialogBox (const String& title,
  201723. const String& bodyText,
  201724. bool isOkCancel)
  201725. {
  201726. return juce_iPhoneShowModalAlert (title, bodyText,
  201727. @"OK",
  201728. isOkCancel ? @"Cancel" : nil);
  201729. }
  201730. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMoveFiles)
  201731. {
  201732. jassertfalse // no such thing on the iphone!
  201733. return false;
  201734. }
  201735. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  201736. {
  201737. jassertfalse // no such thing on the iphone!
  201738. return false;
  201739. }
  201740. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  201741. {
  201742. [[UIApplication sharedApplication] setIdleTimerDisabled: ! isEnabled];
  201743. }
  201744. bool Desktop::isScreenSaverEnabled() throw()
  201745. {
  201746. return ! [[UIApplication sharedApplication] isIdleTimerDisabled];
  201747. }
  201748. void juce_updateMultiMonitorInfo (Array <Rectangle <int> >& monitorCoords, const bool clipToWorkArea)
  201749. {
  201750. const ScopedAutoReleasePool pool;
  201751. monitorCoords.clear();
  201752. CGRect r = clipToWorkArea ? [[UIScreen mainScreen] applicationFrame]
  201753. : [[UIScreen mainScreen] bounds];
  201754. monitorCoords.add (Rectangle<int> ((int) r.origin.x,
  201755. (int) r.origin.y,
  201756. (int) r.size.width,
  201757. (int) r.size.height));
  201758. }
  201759. #endif
  201760. #endif
  201761. /*** End of inlined file: juce_iphone_MiscUtilities.mm ***/
  201762. #else
  201763. /*** Start of inlined file: juce_mac_MiscUtilities.mm ***/
  201764. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201765. // compiled on its own).
  201766. #if JUCE_INCLUDED_FILE
  201767. ScopedAutoReleasePool::ScopedAutoReleasePool()
  201768. {
  201769. pool = [[NSAutoreleasePool alloc] init];
  201770. }
  201771. ScopedAutoReleasePool::~ScopedAutoReleasePool()
  201772. {
  201773. [((NSAutoreleasePool*) pool) release];
  201774. }
  201775. void PlatformUtilities::beep()
  201776. {
  201777. NSBeep();
  201778. }
  201779. void PlatformUtilities::addItemToDock (const File& file)
  201780. {
  201781. // check that it's not already there...
  201782. if (! juce_getOutputFromCommand ("defaults read com.apple.dock persistent-apps")
  201783. .containsIgnoreCase (file.getFullPathName()))
  201784. {
  201785. 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>"
  201786. + file.getFullPathName() + "</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>\"");
  201787. juce_runSystemCommand ("osascript -e \"tell application \\\"Dock\\\" to quit\"");
  201788. }
  201789. }
  201790. int PlatformUtilities::getOSXMinorVersionNumber()
  201791. {
  201792. SInt32 versionMinor = 0;
  201793. OSErr err = Gestalt (gestaltSystemVersionMinor, &versionMinor);
  201794. (void) err;
  201795. jassert (err == noErr);
  201796. return (int) versionMinor;
  201797. }
  201798. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  201799. bool AlertWindow::showNativeDialogBox (const String& title,
  201800. const String& bodyText,
  201801. bool isOkCancel)
  201802. {
  201803. const ScopedAutoReleasePool pool;
  201804. return NSRunAlertPanel (juceStringToNS (title),
  201805. juceStringToNS (bodyText),
  201806. @"Ok",
  201807. isOkCancel ? @"Cancel" : nil,
  201808. nil) == NSAlertDefaultReturn;
  201809. }
  201810. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMoveFiles)
  201811. {
  201812. if (files.size() == 0)
  201813. return false;
  201814. Component* sourceComp = Component::getComponentUnderMouse();
  201815. if (sourceComp == 0)
  201816. {
  201817. jassertfalse // this method must be called in response to a
  201818. // component's mouseDrag event!
  201819. return false;
  201820. }
  201821. const ScopedAutoReleasePool pool;
  201822. NSView* view = (NSView*) sourceComp->getWindowHandle();
  201823. if (view == 0)
  201824. return false;
  201825. NSPasteboard* pboard = [NSPasteboard pasteboardWithName: NSDragPboard];
  201826. [pboard declareTypes: [NSArray arrayWithObject: NSFilenamesPboardType]
  201827. owner: nil];
  201828. NSMutableArray* filesArray = [NSMutableArray arrayWithCapacity: 4];
  201829. for (int i = 0; i < files.size(); ++i)
  201830. [filesArray addObject: juceStringToNS (files[i])];
  201831. [pboard setPropertyList: filesArray
  201832. forType: NSFilenamesPboardType];
  201833. NSPoint dragPosition = [view convertPoint: [[[view window] currentEvent] locationInWindow]
  201834. fromView: nil];
  201835. dragPosition.x -= 16;
  201836. dragPosition.y -= 16;
  201837. [view dragImage: [[NSWorkspace sharedWorkspace] iconForFile: juceStringToNS (files[0])]
  201838. at: dragPosition
  201839. offset: NSMakeSize (0, 0)
  201840. event: [[view window] currentEvent]
  201841. pasteboard: pboard
  201842. source: view
  201843. slideBack: YES];
  201844. return true;
  201845. }
  201846. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  201847. {
  201848. jassertfalse // not implemented!
  201849. return false;
  201850. }
  201851. bool Desktop::canUseSemiTransparentWindows() throw()
  201852. {
  201853. return true;
  201854. }
  201855. void Desktop::getMousePosition (int& x, int& y) throw()
  201856. {
  201857. const ScopedAutoReleasePool pool;
  201858. const NSPoint p ([NSEvent mouseLocation]);
  201859. x = roundToInt (p.x);
  201860. y = roundToInt ([[[NSScreen screens] objectAtIndex: 0] frame].size.height - p.y);
  201861. }
  201862. void Desktop::setMousePosition (int x, int y) throw()
  201863. {
  201864. // this rubbish needs to be done around the warp call, to avoid causing a
  201865. // bizarre glitch..
  201866. CGAssociateMouseAndMouseCursorPosition (false);
  201867. CGWarpMouseCursorPosition (CGPointMake (x, y));
  201868. CGAssociateMouseAndMouseCursorPosition (true);
  201869. }
  201870. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  201871. class ScreenSaverDefeater : public Timer,
  201872. public DeletedAtShutdown
  201873. {
  201874. public:
  201875. ScreenSaverDefeater() throw()
  201876. {
  201877. startTimer (10000);
  201878. timerCallback();
  201879. }
  201880. ~ScreenSaverDefeater() {}
  201881. void timerCallback()
  201882. {
  201883. if (Process::isForegroundProcess())
  201884. UpdateSystemActivity (UsrActivity);
  201885. }
  201886. };
  201887. static ScreenSaverDefeater* screenSaverDefeater = 0;
  201888. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  201889. {
  201890. if (isEnabled)
  201891. {
  201892. deleteAndZero (screenSaverDefeater);
  201893. }
  201894. else if (screenSaverDefeater == 0)
  201895. {
  201896. screenSaverDefeater = new ScreenSaverDefeater();
  201897. }
  201898. }
  201899. bool Desktop::isScreenSaverEnabled() throw()
  201900. {
  201901. return screenSaverDefeater == 0;
  201902. }
  201903. #else
  201904. static IOPMAssertionID screenSaverDisablerID = 0;
  201905. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  201906. {
  201907. if (isEnabled)
  201908. {
  201909. if (screenSaverDisablerID != 0)
  201910. {
  201911. IOPMAssertionRelease (screenSaverDisablerID);
  201912. screenSaverDisablerID = 0;
  201913. }
  201914. }
  201915. else
  201916. {
  201917. if (screenSaverDisablerID == 0)
  201918. {
  201919. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  201920. IOPMAssertionCreateWithName (kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn,
  201921. CFSTR ("Juce"), &screenSaverDisablerID);
  201922. #else
  201923. IOPMAssertionCreate (kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn,
  201924. &screenSaverDisablerID);
  201925. #endif
  201926. }
  201927. }
  201928. }
  201929. bool Desktop::isScreenSaverEnabled() throw()
  201930. {
  201931. return screenSaverDisablerID == 0;
  201932. }
  201933. #endif
  201934. void juce_updateMultiMonitorInfo (Array <Rectangle<int> >& monitorCoords, const bool clipToWorkArea)
  201935. {
  201936. const ScopedAutoReleasePool pool;
  201937. monitorCoords.clear();
  201938. NSArray* screens = [NSScreen screens];
  201939. const CGFloat mainScreenBottom = [[[NSScreen screens] objectAtIndex: 0] frame].size.height;
  201940. for (unsigned int i = 0; i < [screens count]; ++i)
  201941. {
  201942. NSScreen* s = (NSScreen*) [screens objectAtIndex: i];
  201943. NSRect r = clipToWorkArea ? [s visibleFrame]
  201944. : [s frame];
  201945. monitorCoords.add (Rectangle<int> ((int) r.origin.x,
  201946. (int) (mainScreenBottom - (r.origin.y + r.size.height)),
  201947. (int) r.size.width,
  201948. (int) r.size.height));
  201949. }
  201950. jassert (monitorCoords.size() > 0);
  201951. }
  201952. #endif
  201953. #endif
  201954. /*** End of inlined file: juce_mac_MiscUtilities.mm ***/
  201955. #endif
  201956. /*** Start of inlined file: juce_mac_Debugging.mm ***/
  201957. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201958. // compiled on its own).
  201959. #if JUCE_INCLUDED_FILE
  201960. void Logger::outputDebugString (const String& text) throw()
  201961. {
  201962. std::cerr << (const char*) text.toUTF8() << std::endl;
  201963. }
  201964. void Logger::outputDebugPrintf (const tchar* format, ...) throw()
  201965. {
  201966. String text;
  201967. va_list args;
  201968. va_start (args, format);
  201969. text.vprintf (format, args);
  201970. outputDebugString (text);
  201971. }
  201972. bool JUCE_PUBLIC_FUNCTION juce_isRunningUnderDebugger()
  201973. {
  201974. static char testResult = 0;
  201975. if (testResult == 0)
  201976. {
  201977. struct kinfo_proc info;
  201978. int m[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid() };
  201979. size_t sz = sizeof (info);
  201980. sysctl (m, 4, &info, &sz, 0, 0);
  201981. testResult = ((info.kp_proc.p_flag & P_TRACED) != 0) ? 1 : -1;
  201982. }
  201983. return testResult > 0;
  201984. }
  201985. bool JUCE_CALLTYPE Process::isRunningUnderDebugger()
  201986. {
  201987. return juce_isRunningUnderDebugger();
  201988. }
  201989. #endif
  201990. /*** End of inlined file: juce_mac_Debugging.mm ***/
  201991. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  201992. #if JUCE_IPHONE
  201993. /*** Start of inlined file: juce_mac_Fonts.mm ***/
  201994. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201995. // compiled on its own).
  201996. #if JUCE_INCLUDED_FILE
  201997. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  201998. #define SUPPORT_10_4_FONTS 1
  201999. #define NEW_CGFONT_FUNCTIONS_UNAVAILABLE (CGFontCreateWithFontName == 0)
  202000. #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
  202001. #define SUPPORT_ONLY_10_4_FONTS 1
  202002. #endif
  202003. END_JUCE_NAMESPACE
  202004. @interface NSFont (PrivateHack)
  202005. - (NSGlyph) _defaultGlyphForChar: (unichar) theChar;
  202006. @end
  202007. BEGIN_JUCE_NAMESPACE
  202008. #endif
  202009. class MacTypeface : public Typeface
  202010. {
  202011. public:
  202012. MacTypeface (const Font& font)
  202013. : Typeface (font.getTypefaceName())
  202014. {
  202015. const ScopedAutoReleasePool pool;
  202016. renderingTransform = CGAffineTransformIdentity;
  202017. bool needsItalicTransform = false;
  202018. #if JUCE_IPHONE
  202019. NSString* fontName = juceStringToNS (font.getTypefaceName());
  202020. if (font.isItalic() || font.isBold())
  202021. {
  202022. NSArray* familyFonts = [UIFont fontNamesForFamilyName: juceStringToNS (font.getTypefaceName())];
  202023. for (NSString* i in familyFonts)
  202024. {
  202025. const String fn (nsStringToJuce (i));
  202026. const String afterDash (fn.fromFirstOccurrenceOf (T("-"), false, false));
  202027. const bool probablyBold = afterDash.containsIgnoreCase (T("bold")) || fn.endsWithIgnoreCase (T("bold"));
  202028. const bool probablyItalic = afterDash.containsIgnoreCase (T("oblique"))
  202029. || afterDash.containsIgnoreCase (T("italic"))
  202030. || fn.endsWithIgnoreCase (T("oblique"))
  202031. || fn.endsWithIgnoreCase (T("italic"));
  202032. if (probablyBold == font.isBold()
  202033. && probablyItalic == font.isItalic())
  202034. {
  202035. fontName = i;
  202036. needsItalicTransform = false;
  202037. break;
  202038. }
  202039. else if (probablyBold && (! probablyItalic) && probablyBold == font.isBold())
  202040. {
  202041. fontName = i;
  202042. needsItalicTransform = true; // not ideal, so carry on in case we find a better one
  202043. }
  202044. }
  202045. if (needsItalicTransform)
  202046. renderingTransform.c = 0.15f;
  202047. }
  202048. fontRef = CGFontCreateWithFontName ((CFStringRef) fontName);
  202049. const int ascender = abs (CGFontGetAscent (fontRef));
  202050. const float totalHeight = ascender + abs (CGFontGetDescent (fontRef));
  202051. ascent = ascender / totalHeight;
  202052. unitsToHeightScaleFactor = 1.0f / totalHeight;
  202053. fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (fontRef) / totalHeight;
  202054. #else
  202055. nsFont = [NSFont fontWithName: juceStringToNS (font.getTypefaceName()) size: 1024];
  202056. if (font.isItalic())
  202057. {
  202058. NSFont* newFont = [[NSFontManager sharedFontManager] convertFont: nsFont
  202059. toHaveTrait: NSItalicFontMask];
  202060. if (newFont == nsFont)
  202061. needsItalicTransform = true; // couldn't find a proper italic version, so fake it with a transform..
  202062. nsFont = newFont;
  202063. }
  202064. if (font.isBold())
  202065. nsFont = [[NSFontManager sharedFontManager] convertFont: nsFont toHaveTrait: NSBoldFontMask];
  202066. [nsFont retain];
  202067. ascent = fabsf ((float) [nsFont ascender]);
  202068. float totalSize = ascent + fabsf ((float) [nsFont descender]);
  202069. ascent /= totalSize;
  202070. pathTransform = AffineTransform::identity.scale (1.0f / totalSize, 1.0f / totalSize);
  202071. if (needsItalicTransform)
  202072. {
  202073. pathTransform = pathTransform.sheared (-0.15f, 0.0f);
  202074. renderingTransform.c = 0.15f;
  202075. }
  202076. #if SUPPORT_ONLY_10_4_FONTS
  202077. ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  202078. if (atsFont == 0)
  202079. atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  202080. fontRef = CGFontCreateWithPlatformFont ((void*) &atsFont);
  202081. const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]);
  202082. unitsToHeightScaleFactor = 1.0f / totalHeight;
  202083. fontHeightToCGSizeFactor = 1024.0f / totalHeight;
  202084. #else
  202085. #if SUPPORT_10_4_FONTS
  202086. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  202087. {
  202088. ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  202089. if (atsFont == 0)
  202090. atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  202091. fontRef = CGFontCreateWithPlatformFont ((void*) &atsFont);
  202092. const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]);
  202093. unitsToHeightScaleFactor = 1.0f / totalHeight;
  202094. fontHeightToCGSizeFactor = 1024.0f / totalHeight;
  202095. }
  202096. else
  202097. #endif
  202098. {
  202099. fontRef = CGFontCreateWithFontName ((CFStringRef) [nsFont fontName]);
  202100. const int totalHeight = abs (CGFontGetAscent (fontRef)) + abs (CGFontGetDescent (fontRef));
  202101. unitsToHeightScaleFactor = 1.0f / totalHeight;
  202102. fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (fontRef) / (float) totalHeight;
  202103. }
  202104. #endif
  202105. #endif
  202106. }
  202107. ~MacTypeface()
  202108. {
  202109. #if ! JUCE_IPHONE
  202110. [nsFont release];
  202111. #endif
  202112. if (fontRef != 0)
  202113. CGFontRelease (fontRef);
  202114. }
  202115. float getAscent() const
  202116. {
  202117. return ascent;
  202118. }
  202119. float getDescent() const
  202120. {
  202121. return 1.0f - ascent;
  202122. }
  202123. float getStringWidth (const String& text)
  202124. {
  202125. if (fontRef == 0 || text.isEmpty())
  202126. return 0;
  202127. const int length = text.length();
  202128. HeapBlock <CGGlyph> glyphs;
  202129. createGlyphsForString (text, length, glyphs);
  202130. float x = 0;
  202131. #if SUPPORT_ONLY_10_4_FONTS
  202132. HeapBlock <NSSize> advances (length);
  202133. [nsFont getAdvancements: advances forGlyphs: (NSGlyph*) glyphs count: length];
  202134. for (int i = 0; i < length; ++i)
  202135. x += advances[i].width;
  202136. #else
  202137. #if SUPPORT_10_4_FONTS
  202138. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  202139. {
  202140. HeapBlock <NSSize> advances (length);
  202141. [nsFont getAdvancements: advances forGlyphs: (NSGlyph*) glyphs count: length];
  202142. for (int i = 0; i < length; ++i)
  202143. x += advances[i].width;
  202144. }
  202145. else
  202146. #endif
  202147. {
  202148. HeapBlock <int> advances (length);
  202149. if (CGFontGetGlyphAdvances (fontRef, glyphs, length, advances))
  202150. for (int i = 0; i < length; ++i)
  202151. x += advances[i];
  202152. }
  202153. #endif
  202154. return x * unitsToHeightScaleFactor;
  202155. }
  202156. void getGlyphPositions (const String& text, Array <int>& resultGlyphs, Array <float>& xOffsets)
  202157. {
  202158. xOffsets.add (0);
  202159. if (fontRef == 0 || text.isEmpty())
  202160. return;
  202161. const int length = text.length();
  202162. HeapBlock <CGGlyph> glyphs;
  202163. createGlyphsForString (text, length, glyphs);
  202164. #if SUPPORT_ONLY_10_4_FONTS
  202165. HeapBlock <NSSize> advances (length);
  202166. [nsFont getAdvancements: advances forGlyphs: (NSGlyph*) glyphs count: length];
  202167. int x = 0;
  202168. for (int i = 0; i < length; ++i)
  202169. {
  202170. x += advances[i].width;
  202171. xOffsets.add (x * unitsToHeightScaleFactor);
  202172. resultGlyphs.add (((NSGlyph*) glyphs)[i]);
  202173. }
  202174. #else
  202175. #if SUPPORT_10_4_FONTS
  202176. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  202177. {
  202178. HeapBlock <NSSize> advances (length);
  202179. [nsFont getAdvancements: advances forGlyphs: (NSGlyph*) glyphs count: length];
  202180. float x = 0;
  202181. for (int i = 0; i < length; ++i)
  202182. {
  202183. x += advances[i].width;
  202184. xOffsets.add (x * unitsToHeightScaleFactor);
  202185. resultGlyphs.add (((NSGlyph*) glyphs)[i]);
  202186. }
  202187. }
  202188. else
  202189. #endif
  202190. {
  202191. HeapBlock <int> advances (length);
  202192. if (CGFontGetGlyphAdvances (fontRef, glyphs, length, advances))
  202193. {
  202194. int x = 0;
  202195. for (int i = 0; i < length; ++i)
  202196. {
  202197. x += advances [i];
  202198. xOffsets.add (x * unitsToHeightScaleFactor);
  202199. resultGlyphs.add (glyphs[i]);
  202200. }
  202201. }
  202202. }
  202203. #endif
  202204. }
  202205. bool getOutlineForGlyph (int glyphNumber, Path& path)
  202206. {
  202207. #if JUCE_IPHONE
  202208. return false;
  202209. #else
  202210. if (nsFont == 0)
  202211. return false;
  202212. // we might need to apply a transform to the path, so it mustn't have anything else in it
  202213. jassert (path.isEmpty());
  202214. const ScopedAutoReleasePool pool;
  202215. NSBezierPath* bez = [NSBezierPath bezierPath];
  202216. [bez moveToPoint: NSMakePoint (0, 0)];
  202217. [bez appendBezierPathWithGlyph: (NSGlyph) glyphNumber
  202218. inFont: nsFont];
  202219. for (int i = 0; i < [bez elementCount]; ++i)
  202220. {
  202221. NSPoint p[3];
  202222. switch ([bez elementAtIndex: i associatedPoints: p])
  202223. {
  202224. case NSMoveToBezierPathElement:
  202225. path.startNewSubPath ((float) p[0].x, (float) -p[0].y);
  202226. break;
  202227. case NSLineToBezierPathElement:
  202228. path.lineTo ((float) p[0].x, (float) -p[0].y);
  202229. break;
  202230. case NSCurveToBezierPathElement:
  202231. 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);
  202232. break;
  202233. case NSClosePathBezierPathElement:
  202234. path.closeSubPath();
  202235. break;
  202236. default:
  202237. jassertfalse
  202238. break;
  202239. }
  202240. }
  202241. path.applyTransform (pathTransform);
  202242. return true;
  202243. #endif
  202244. }
  202245. juce_UseDebuggingNewOperator
  202246. CGFontRef fontRef;
  202247. float fontHeightToCGSizeFactor;
  202248. CGAffineTransform renderingTransform;
  202249. private:
  202250. float ascent, unitsToHeightScaleFactor;
  202251. #if JUCE_IPHONE
  202252. #else
  202253. NSFont* nsFont;
  202254. AffineTransform pathTransform;
  202255. #endif
  202256. void createGlyphsForString (const juce_wchar* const text, const int length, HeapBlock <CGGlyph>& glyphs)
  202257. {
  202258. #if SUPPORT_10_4_FONTS
  202259. #if ! SUPPORT_ONLY_10_4_FONTS
  202260. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  202261. #endif
  202262. {
  202263. glyphs.malloc (sizeof (NSGlyph) * length, 1);
  202264. NSGlyph* const g = (NSGlyph*) glyphs;
  202265. for (int i = 0; i < length; ++i)
  202266. g[i] = (NSGlyph) [nsFont _defaultGlyphForChar: text[i]];
  202267. return;
  202268. }
  202269. #endif
  202270. #if ! SUPPORT_ONLY_10_4_FONTS
  202271. if (charToGlyphMapper == 0)
  202272. charToGlyphMapper = new CharToGlyphMapper (fontRef);
  202273. glyphs.malloc (length);
  202274. for (int i = 0; i < length; ++i)
  202275. glyphs[i] = (CGGlyph) charToGlyphMapper->getGlyphForCharacter (text[i]);
  202276. #endif
  202277. }
  202278. #if ! SUPPORT_ONLY_10_4_FONTS
  202279. // Reads a CGFontRef's character map table to convert unicode into glyph numbers
  202280. class CharToGlyphMapper
  202281. {
  202282. public:
  202283. CharToGlyphMapper (CGFontRef fontRef)
  202284. : segCount (0), endCode (0), startCode (0), idDelta (0),
  202285. idRangeOffset (0), glyphIndexes (0)
  202286. {
  202287. CFDataRef cmapTable = CGFontCopyTableForTag (fontRef, 'cmap');
  202288. if (cmapTable != 0)
  202289. {
  202290. const int numSubtables = getValue16 (cmapTable, 2);
  202291. for (int i = 0; i < numSubtables; ++i)
  202292. {
  202293. if (getValue16 (cmapTable, i * 8 + 4) == 0) // check for platform ID of 0
  202294. {
  202295. const int offset = getValue32 (cmapTable, i * 8 + 8);
  202296. if (getValue16 (cmapTable, offset) == 4) // check that it's format 4..
  202297. {
  202298. const int length = getValue16 (cmapTable, offset + 2);
  202299. const int segCountX2 = getValue16 (cmapTable, offset + 6);
  202300. segCount = segCountX2 / 2;
  202301. const int endCodeOffset = offset + 14;
  202302. const int startCodeOffset = endCodeOffset + 2 + segCountX2;
  202303. const int idDeltaOffset = startCodeOffset + segCountX2;
  202304. const int idRangeOffsetOffset = idDeltaOffset + segCountX2;
  202305. const int glyphIndexesOffset = idRangeOffsetOffset + segCountX2;
  202306. endCode = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + endCodeOffset, segCountX2);
  202307. startCode = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + startCodeOffset, segCountX2);
  202308. idDelta = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + idDeltaOffset, segCountX2);
  202309. idRangeOffset = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + idRangeOffsetOffset, segCountX2);
  202310. glyphIndexes = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + glyphIndexesOffset, offset + length - glyphIndexesOffset);
  202311. }
  202312. break;
  202313. }
  202314. }
  202315. CFRelease (cmapTable);
  202316. }
  202317. }
  202318. ~CharToGlyphMapper()
  202319. {
  202320. if (endCode != 0)
  202321. {
  202322. CFRelease (endCode);
  202323. CFRelease (startCode);
  202324. CFRelease (idDelta);
  202325. CFRelease (idRangeOffset);
  202326. CFRelease (glyphIndexes);
  202327. }
  202328. }
  202329. int getGlyphForCharacter (const juce_wchar c) const
  202330. {
  202331. for (int i = 0; i < segCount; ++i)
  202332. {
  202333. if (getValue16 (endCode, i * 2) >= c)
  202334. {
  202335. const int start = getValue16 (startCode, i * 2);
  202336. if (start > c)
  202337. break;
  202338. const int delta = getValue16 (idDelta, i * 2);
  202339. const int rangeOffset = getValue16 (idRangeOffset, i * 2);
  202340. if (rangeOffset == 0)
  202341. return delta + c;
  202342. else
  202343. return getValue16 (glyphIndexes, 2 * ((rangeOffset / 2) + (c - start) - (segCount - i)));
  202344. }
  202345. }
  202346. // If we failed to find it "properly", this dodgy fall-back seems to do the trick for most fonts!
  202347. return jmax (-1, c - 29);
  202348. }
  202349. private:
  202350. int segCount;
  202351. CFDataRef endCode, startCode, idDelta, idRangeOffset, glyphIndexes;
  202352. static uint16 getValue16 (CFDataRef data, const int index)
  202353. {
  202354. return CFSwapInt16BigToHost (*(UInt16*) (CFDataGetBytePtr (data) + index));
  202355. }
  202356. static uint32 getValue32 (CFDataRef data, const int index)
  202357. {
  202358. return CFSwapInt32BigToHost (*(UInt32*) (CFDataGetBytePtr (data) + index));
  202359. }
  202360. };
  202361. ScopedPointer <CharToGlyphMapper> charToGlyphMapper;
  202362. #endif
  202363. };
  202364. const Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  202365. {
  202366. return new MacTypeface (font);
  202367. }
  202368. const StringArray Font::findAllTypefaceNames() throw()
  202369. {
  202370. StringArray names;
  202371. const ScopedAutoReleasePool pool;
  202372. #if JUCE_IPHONE
  202373. NSArray* fonts = [UIFont familyNames];
  202374. #else
  202375. NSArray* fonts = [[NSFontManager sharedFontManager] availableFontFamilies];
  202376. #endif
  202377. for (unsigned int i = 0; i < [fonts count]; ++i)
  202378. names.add (nsStringToJuce ((NSString*) [fonts objectAtIndex: i]));
  202379. names.sort (true);
  202380. return names;
  202381. }
  202382. void Font::getPlatformDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed) throw()
  202383. {
  202384. #if JUCE_IPHONE
  202385. defaultSans = "Helvetica";
  202386. defaultSerif = "Times New Roman";
  202387. defaultFixed = "Courier New";
  202388. #else
  202389. defaultSans = "Lucida Grande";
  202390. defaultSerif = "Times New Roman";
  202391. defaultFixed = "Monaco";
  202392. #endif
  202393. }
  202394. #endif
  202395. /*** End of inlined file: juce_mac_Fonts.mm ***/
  202396. /*** Start of inlined file: juce_mac_CoreGraphicsContext.mm ***/
  202397. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  202398. // compiled on its own).
  202399. #if JUCE_INCLUDED_FILE
  202400. class CoreGraphicsImage : public Image
  202401. {
  202402. public:
  202403. CoreGraphicsImage (const PixelFormat format_,
  202404. const int imageWidth_,
  202405. const int imageHeight_,
  202406. const bool clearImage)
  202407. : Image (format_, imageWidth_, imageHeight_, clearImage)
  202408. {
  202409. CGColorSpaceRef colourSpace = format == Image::SingleChannel ? CGColorSpaceCreateDeviceGray()
  202410. : CGColorSpaceCreateDeviceRGB();
  202411. context = CGBitmapContextCreate (imageData, imageWidth, imageHeight, 8, lineStride,
  202412. colourSpace, getCGImageFlags (*this));
  202413. CGColorSpaceRelease (colourSpace);
  202414. }
  202415. ~CoreGraphicsImage()
  202416. {
  202417. CGContextRelease (context);
  202418. }
  202419. LowLevelGraphicsContext* createLowLevelContext();
  202420. static CGImageRef createImage (const Image& juceImage, const bool forAlpha, CGColorSpaceRef colourSpace)
  202421. {
  202422. const CoreGraphicsImage* nativeImage = dynamic_cast <const CoreGraphicsImage*> (&juceImage);
  202423. if (nativeImage != 0 && (juceImage.getFormat() == Image::SingleChannel || ! forAlpha))
  202424. {
  202425. return CGBitmapContextCreateImage (nativeImage->context);
  202426. }
  202427. else
  202428. {
  202429. const Image::BitmapData srcData (juceImage, 0, 0, juceImage.getWidth(), juceImage.getHeight());
  202430. CGDataProviderRef provider = CGDataProviderCreateWithData (0, srcData.data, srcData.lineStride * srcData.height, 0);
  202431. CGImageRef imageRef = CGImageCreate (srcData.width, srcData.height,
  202432. 8, srcData.pixelStride * 8, srcData.lineStride,
  202433. colourSpace, getCGImageFlags (juceImage), provider,
  202434. 0, true, kCGRenderingIntentDefault);
  202435. CGDataProviderRelease (provider);
  202436. return imageRef;
  202437. }
  202438. }
  202439. #if JUCE_MAC
  202440. static NSImage* createNSImage (const Image& image)
  202441. {
  202442. const ScopedAutoReleasePool pool;
  202443. NSImage* im = [[NSImage alloc] init];
  202444. [im setSize: NSMakeSize (image.getWidth(), image.getHeight())];
  202445. [im lockFocus];
  202446. CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB();
  202447. CGImageRef imageRef = createImage (image, false, colourSpace);
  202448. CGColorSpaceRelease (colourSpace);
  202449. CGContextRef cg = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
  202450. CGContextDrawImage (cg, CGRectMake (0, 0, image.getWidth(), image.getHeight()), imageRef);
  202451. CGImageRelease (imageRef);
  202452. [im unlockFocus];
  202453. return im;
  202454. }
  202455. #endif
  202456. CGContextRef context;
  202457. private:
  202458. static CGBitmapInfo getCGImageFlags (const Image& image)
  202459. {
  202460. #if JUCE_BIG_ENDIAN
  202461. return image.getFormat() == Image::ARGB ? (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Big) : kCGBitmapByteOrderDefault;
  202462. #else
  202463. return image.getFormat() == Image::ARGB ? (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Little) : kCGBitmapByteOrderDefault;
  202464. #endif
  202465. }
  202466. };
  202467. Image* Image::createNativeImage (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage)
  202468. {
  202469. #if USE_COREGRAPHICS_RENDERING
  202470. return new CoreGraphicsImage (format == RGB ? ARGB : format, imageWidth, imageHeight, clearImage);
  202471. #else
  202472. return new Image (format, imageWidth, imageHeight, clearImage);
  202473. #endif
  202474. }
  202475. class CoreGraphicsContext : public LowLevelGraphicsContext
  202476. {
  202477. public:
  202478. CoreGraphicsContext (CGContextRef context_, const float flipHeight_)
  202479. : context (context_),
  202480. flipHeight (flipHeight_),
  202481. numGradientLookupEntries (0)
  202482. {
  202483. CGContextRetain (context);
  202484. CGContextSaveGState(context);
  202485. CGContextSetShouldSmoothFonts (context, true);
  202486. CGContextSetShouldAntialias (context, true);
  202487. CGContextSetBlendMode (context, kCGBlendModeNormal);
  202488. rgbColourSpace = CGColorSpaceCreateDeviceRGB();
  202489. greyColourSpace = CGColorSpaceCreateDeviceGray();
  202490. gradientCallbacks.version = 0;
  202491. gradientCallbacks.evaluate = gradientCallback;
  202492. gradientCallbacks.releaseInfo = 0;
  202493. state = new SavedState();
  202494. }
  202495. ~CoreGraphicsContext()
  202496. {
  202497. CGContextRestoreGState (context);
  202498. CGContextRelease (context);
  202499. CGColorSpaceRelease (rgbColourSpace);
  202500. CGColorSpaceRelease (greyColourSpace);
  202501. }
  202502. bool isVectorDevice() const { return false; }
  202503. void setOrigin (int x, int y)
  202504. {
  202505. CGContextTranslateCTM (context, x, -y);
  202506. }
  202507. bool clipToRectangle (const Rectangle<int>& r)
  202508. {
  202509. CGContextClipToRect (context, CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight()));
  202510. return ! isClipEmpty();
  202511. }
  202512. bool clipToRectangleList (const RectangleList& clipRegion)
  202513. {
  202514. if (clipRegion.isEmpty())
  202515. {
  202516. CGContextClipToRect (context, CGRectMake (0, 0, 0, 0));
  202517. return false;
  202518. }
  202519. else
  202520. {
  202521. const int numRects = clipRegion.getNumRectangles();
  202522. HeapBlock <CGRect> rects (numRects);
  202523. for (int i = 0; i < numRects; ++i)
  202524. {
  202525. const Rectangle<int>& r = clipRegion.getRectangle(i);
  202526. rects[i] = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight());
  202527. }
  202528. CGContextClipToRects (context, rects, numRects);
  202529. return ! isClipEmpty();
  202530. }
  202531. }
  202532. void excludeClipRectangle (const Rectangle<int>& r)
  202533. {
  202534. RectangleList remaining (getClipBounds());
  202535. remaining.subtract (r);
  202536. clipToRectangleList (remaining);
  202537. }
  202538. void clipToPath (const Path& path, const AffineTransform& transform)
  202539. {
  202540. createPath (path, transform);
  202541. CGContextClip (context);
  202542. }
  202543. void clipToImageAlpha (const Image& sourceImage, const Rectangle<int>& srcClip, const AffineTransform& transform)
  202544. {
  202545. if (! transform.isSingularity())
  202546. {
  202547. Image* singleChannelImage = createAlphaChannelImage (sourceImage);
  202548. CGImageRef image = CoreGraphicsImage::createImage (*singleChannelImage, true, greyColourSpace);
  202549. flip();
  202550. AffineTransform t (AffineTransform::scale (1.0f, -1.0f).translated (0, sourceImage.getHeight()).followedBy (transform));
  202551. applyTransform (t);
  202552. CGRect r = CGRectMake (0, 0, sourceImage.getWidth(), sourceImage.getHeight());
  202553. CGContextClipToMask (context, r, image);
  202554. applyTransform (t.inverted());
  202555. flip();
  202556. CGImageRelease (image);
  202557. deleteAlphaChannelImage (sourceImage, singleChannelImage);
  202558. }
  202559. }
  202560. bool clipRegionIntersects (const Rectangle<int>& r)
  202561. {
  202562. return getClipBounds().intersects (r);
  202563. }
  202564. const Rectangle<int> getClipBounds() const
  202565. {
  202566. CGRect bounds = CGRectIntegral (CGContextGetClipBoundingBox (context));
  202567. return Rectangle<int> (roundToInt (bounds.origin.x),
  202568. roundToInt (flipHeight - (bounds.origin.y + bounds.size.height)),
  202569. roundToInt (bounds.size.width),
  202570. roundToInt (bounds.size.height));
  202571. }
  202572. bool isClipEmpty() const
  202573. {
  202574. return CGRectIsEmpty (CGContextGetClipBoundingBox (context));
  202575. }
  202576. void saveState()
  202577. {
  202578. CGContextSaveGState (context);
  202579. stateStack.add (new SavedState (*state));
  202580. }
  202581. void restoreState()
  202582. {
  202583. CGContextRestoreGState (context);
  202584. SavedState* const top = stateStack.getLast();
  202585. if (top != 0)
  202586. {
  202587. state = top;
  202588. stateStack.removeLast (1, false);
  202589. }
  202590. else
  202591. {
  202592. jassertfalse // trying to pop with an empty stack!
  202593. }
  202594. }
  202595. void setFill (const FillType& fillType)
  202596. {
  202597. state->fillType = fillType;
  202598. if (fillType.isColour())
  202599. {
  202600. CGContextSetRGBFillColor (context, fillType.colour.getFloatRed(), fillType.colour.getFloatGreen(),
  202601. fillType.colour.getFloatBlue(), fillType.colour.getFloatAlpha());
  202602. CGContextSetAlpha (context, 1.0f);
  202603. }
  202604. }
  202605. void setOpacity (float newOpacity)
  202606. {
  202607. state->fillType.setOpacity (newOpacity);
  202608. setFill (state->fillType);
  202609. }
  202610. void setInterpolationQuality (Graphics::ResamplingQuality quality)
  202611. {
  202612. CGContextSetInterpolationQuality (context, quality == Graphics::lowResamplingQuality
  202613. ? kCGInterpolationLow
  202614. : kCGInterpolationHigh);
  202615. }
  202616. void fillRect (const Rectangle<int>& r, const bool replaceExistingContents)
  202617. {
  202618. CGRect cgRect = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight());
  202619. if (replaceExistingContents)
  202620. {
  202621. #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
  202622. CGContextClearRect (context, cgRect);
  202623. #else
  202624. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  202625. if (CGContextDrawLinearGradient == 0) // (just a way of checking whether we're running in 10.5 or later)
  202626. CGContextClearRect (context, cgRect);
  202627. else
  202628. #endif
  202629. CGContextSetBlendMode (context, kCGBlendModeCopy);
  202630. #endif
  202631. fillRect (r, false);
  202632. CGContextSetBlendMode (context, kCGBlendModeNormal);
  202633. }
  202634. else
  202635. {
  202636. if (state->fillType.isColour())
  202637. {
  202638. CGContextFillRect (context, cgRect);
  202639. }
  202640. else if (state->fillType.isGradient())
  202641. {
  202642. CGContextSaveGState (context);
  202643. CGContextClipToRect (context, cgRect);
  202644. drawGradient();
  202645. CGContextRestoreGState (context);
  202646. }
  202647. else
  202648. {
  202649. CGContextSaveGState (context);
  202650. CGContextClipToRect (context, cgRect);
  202651. drawImage (*(state->fillType.image), state->fillType.image->getBounds(), state->fillType.transform, true);
  202652. CGContextRestoreGState (context);
  202653. }
  202654. }
  202655. }
  202656. void fillPath (const Path& path, const AffineTransform& transform)
  202657. {
  202658. CGContextSaveGState (context);
  202659. if (state->fillType.isColour())
  202660. {
  202661. flip();
  202662. applyTransform (transform);
  202663. createPath (path);
  202664. if (path.isUsingNonZeroWinding())
  202665. CGContextFillPath (context);
  202666. else
  202667. CGContextEOFillPath (context);
  202668. }
  202669. else
  202670. {
  202671. createPath (path, transform);
  202672. if (path.isUsingNonZeroWinding())
  202673. CGContextClip (context);
  202674. else
  202675. CGContextEOClip (context);
  202676. if (state->fillType.isGradient())
  202677. drawGradient();
  202678. else
  202679. drawImage (*(state->fillType.image), state->fillType.image->getBounds(), state->fillType.transform, true);
  202680. }
  202681. CGContextRestoreGState (context);
  202682. }
  202683. void drawImage (const Image& sourceImage, const Rectangle<int>& srcClip,
  202684. const AffineTransform& transform, const bool fillEntireClipAsTiles)
  202685. {
  202686. jassert (sourceImage.getBounds().contains (srcClip));
  202687. CGImageRef fullImage = CoreGraphicsImage::createImage (sourceImage, false, rgbColourSpace);
  202688. CGImageRef image = fullImage;
  202689. if (srcClip != sourceImage.getBounds())
  202690. {
  202691. image = CGImageCreateWithImageInRect (fullImage, CGRectMake (srcClip.getX(), srcClip.getY(),
  202692. srcClip.getWidth(), srcClip.getHeight()));
  202693. CGImageRelease (fullImage);
  202694. }
  202695. CGContextSaveGState (context);
  202696. CGContextSetAlpha (context, state->fillType.getOpacity());
  202697. flip();
  202698. applyTransform (AffineTransform::scale (1.0f, -1.0f).translated (0, srcClip.getHeight()).followedBy (transform));
  202699. CGRect imageRect = CGRectMake (0, 0, srcClip.getWidth(), srcClip.getHeight());
  202700. if (fillEntireClipAsTiles)
  202701. {
  202702. #if JUCE_IPHONE || (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5)
  202703. CGContextDrawTiledImage (context, imageRect, image);
  202704. #else
  202705. #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
  202706. // There's a bug in CGContextDrawTiledImage that makes it incredibly slow
  202707. // if it's doing a transformation - it's quicker to just draw lots of images manually
  202708. if (CGContextDrawTiledImage != 0 && transform.isOnlyTranslation())
  202709. CGContextDrawTiledImage (context, imageRect, image);
  202710. else
  202711. #endif
  202712. {
  202713. // Fallback to manually doing a tiled fill on 10.4
  202714. CGRect clip = CGRectIntegral (CGContextGetClipBoundingBox (context));
  202715. const int iw = srcClip.getWidth();
  202716. const int ih = srcClip.getHeight();
  202717. int x = 0, y = 0;
  202718. while (x > clip.origin.x) x -= iw;
  202719. while (y > clip.origin.y) y -= ih;
  202720. const int right = (int) (clip.origin.x + clip.size.width);
  202721. const int bottom = (int) (clip.origin.y + clip.size.height);
  202722. while (y < bottom)
  202723. {
  202724. for (int x2 = x; x2 < right; x2 += iw)
  202725. CGContextDrawImage (context, CGRectMake (x2, y, iw, ih), image);
  202726. y += ih;
  202727. }
  202728. }
  202729. #endif
  202730. }
  202731. else
  202732. {
  202733. CGContextDrawImage (context, imageRect, image);
  202734. }
  202735. CGImageRelease (image); // (This causes a memory bug in iPhone sim 3.0 - try upgrading to a later version if you hit this)
  202736. CGContextRestoreGState (context);
  202737. }
  202738. void drawLine (double x1, double y1, double x2, double y2)
  202739. {
  202740. CGContextSetLineCap (context, kCGLineCapSquare);
  202741. CGContextSetLineWidth (context, 1.0f);
  202742. CGContextSetRGBStrokeColor (context,
  202743. state->fillType.colour.getFloatRed(), state->fillType.colour.getFloatGreen(),
  202744. state->fillType.colour.getFloatBlue(), state->fillType.colour.getFloatAlpha());
  202745. CGPoint line[] = { { (float) x1 + 0.5f, flipHeight - ((float) y1 + 0.5f) },
  202746. { (float) x2 + 0.5f, flipHeight - ((float) y2 + 0.5f) } };
  202747. CGContextStrokeLineSegments (context, line, 1);
  202748. }
  202749. void drawVerticalLine (const int x, double top, double bottom)
  202750. {
  202751. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  202752. CGContextFillRect (context, CGRectMake (x, flipHeight - (float) bottom, 1.0f, (float) (bottom - top)));
  202753. #else
  202754. // On Leopard, unless both co-ordinates are non-integer, it disables anti-aliasing, so nudge
  202755. // the x co-ord slightly to trick it..
  202756. CGContextFillRect (context, CGRectMake (x + 1.0f / 256.0f, flipHeight - (float) bottom, 1.0f + 1.0f / 256.0f, (float) (bottom - top)));
  202757. #endif
  202758. }
  202759. void drawHorizontalLine (const int y, double left, double right)
  202760. {
  202761. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  202762. CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + 1.0f), (float) (right - left), 1.0f));
  202763. #else
  202764. // On Leopard, unless both co-ordinates are non-integer, it disables anti-aliasing, so nudge
  202765. // the x co-ord slightly to trick it..
  202766. CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + (1.0f + 1.0f / 256.0f)), (float) (right - left), 1.0f + 1.0f / 256.0f));
  202767. #endif
  202768. }
  202769. void setFont (const Font& newFont)
  202770. {
  202771. if (state->font != newFont)
  202772. {
  202773. state->fontRef = 0;
  202774. state->font = newFont;
  202775. MacTypeface* mf = dynamic_cast <MacTypeface*> ((Typeface*) state->font.getTypeface());
  202776. if (mf != 0)
  202777. {
  202778. state->fontRef = mf->fontRef;
  202779. CGContextSetFont (context, state->fontRef);
  202780. CGContextSetFontSize (context, state->font.getHeight() * mf->fontHeightToCGSizeFactor);
  202781. state->fontTransform = mf->renderingTransform;
  202782. state->fontTransform.a *= state->font.getHorizontalScale();
  202783. CGContextSetTextMatrix (context, state->fontTransform);
  202784. }
  202785. }
  202786. }
  202787. const Font getFont()
  202788. {
  202789. return state->font;
  202790. }
  202791. void drawGlyph (int glyphNumber, const AffineTransform& transform)
  202792. {
  202793. if (state->fontRef != 0 && state->fillType.isColour())
  202794. {
  202795. if (transform.isOnlyTranslation())
  202796. {
  202797. CGGlyph g = glyphNumber;
  202798. CGContextShowGlyphsAtPoint (context, transform.getTranslationX(),
  202799. flipHeight - roundToInt (transform.getTranslationY()), &g, 1);
  202800. }
  202801. else
  202802. {
  202803. CGContextSaveGState (context);
  202804. flip();
  202805. applyTransform (transform);
  202806. CGAffineTransform t = state->fontTransform;
  202807. t.d = -t.d;
  202808. CGContextSetTextMatrix (context, t);
  202809. CGGlyph g = glyphNumber;
  202810. CGContextShowGlyphsAtPoint (context, 0, 0, &g, 1);
  202811. CGContextSetTextMatrix (context, state->fontTransform);
  202812. CGContextRestoreGState (context);
  202813. }
  202814. }
  202815. else
  202816. {
  202817. Path p;
  202818. Font& f = state->font;
  202819. f.getTypeface()->getOutlineForGlyph (glyphNumber, p);
  202820. fillPath (p, AffineTransform::scale (f.getHeight() * f.getHorizontalScale(), f.getHeight())
  202821. .followedBy (transform));
  202822. }
  202823. }
  202824. private:
  202825. CGContextRef context;
  202826. const float flipHeight;
  202827. CGColorSpaceRef rgbColourSpace, greyColourSpace;
  202828. CGFunctionCallbacks gradientCallbacks;
  202829. struct SavedState
  202830. {
  202831. SavedState()
  202832. : font (1.0f), fontRef (0), fontTransform (CGAffineTransformIdentity)
  202833. {
  202834. }
  202835. SavedState (const SavedState& other)
  202836. : fillType (other.fillType), font (other.font), fontRef (other.fontRef),
  202837. fontTransform (other.fontTransform)
  202838. {
  202839. }
  202840. ~SavedState()
  202841. {
  202842. }
  202843. FillType fillType;
  202844. Font font;
  202845. CGFontRef fontRef;
  202846. CGAffineTransform fontTransform;
  202847. };
  202848. ScopedPointer <SavedState> state;
  202849. OwnedArray <SavedState> stateStack;
  202850. HeapBlock <PixelARGB> gradientLookupTable;
  202851. int numGradientLookupEntries;
  202852. static void gradientCallback (void* info, const CGFloat* inData, CGFloat* outData)
  202853. {
  202854. const CoreGraphicsContext* const g = (const CoreGraphicsContext*) info;
  202855. const int index = roundToInt (g->numGradientLookupEntries * inData[0]);
  202856. PixelARGB colour (g->gradientLookupTable [jlimit (0, g->numGradientLookupEntries, index)]);
  202857. colour.unpremultiply();
  202858. outData[0] = colour.getRed() / 255.0f;
  202859. outData[1] = colour.getGreen() / 255.0f;
  202860. outData[2] = colour.getBlue() / 255.0f;
  202861. outData[3] = colour.getAlpha() / 255.0f;
  202862. }
  202863. CGShadingRef createGradient (const AffineTransform& transform, ColourGradient gradient)
  202864. {
  202865. numGradientLookupEntries = gradient.createLookupTable (transform, gradientLookupTable);
  202866. --numGradientLookupEntries;
  202867. CGShadingRef result = 0;
  202868. CGFunctionRef function = CGFunctionCreate ((void*) this, 1, 0, 4, 0, &gradientCallbacks);
  202869. CGPoint p1 (CGPointMake (gradient.x1, gradient.y1));
  202870. if (gradient.isRadial)
  202871. {
  202872. result = CGShadingCreateRadial (rgbColourSpace, p1, 0,
  202873. p1, hypotf (gradient.x1 - gradient.x2, gradient.y1 - gradient.y2),
  202874. function, true, true);
  202875. }
  202876. else
  202877. {
  202878. result = CGShadingCreateAxial (rgbColourSpace, p1,
  202879. CGPointMake (gradient.x2, gradient.y2),
  202880. function, true, true);
  202881. }
  202882. CGFunctionRelease (function);
  202883. return result;
  202884. }
  202885. void drawGradient()
  202886. {
  202887. flip();
  202888. applyTransform (state->fillType.transform);
  202889. CGContextSetInterpolationQuality (context, kCGInterpolationDefault); // (This is required for 10.4, where there's a crash if
  202890. // you draw a gradient with high quality interp enabled).
  202891. CGShadingRef shading = createGradient (state->fillType.transform, *(state->fillType.gradient));
  202892. CGContextSetAlpha (context, state->fillType.getOpacity());
  202893. CGContextDrawShading (context, shading);
  202894. CGShadingRelease (shading);
  202895. }
  202896. void createPath (const Path& path) const
  202897. {
  202898. CGContextBeginPath (context);
  202899. Path::Iterator i (path);
  202900. while (i.next())
  202901. {
  202902. switch (i.elementType)
  202903. {
  202904. case Path::Iterator::startNewSubPath:
  202905. CGContextMoveToPoint (context, i.x1, i.y1);
  202906. break;
  202907. case Path::Iterator::lineTo:
  202908. CGContextAddLineToPoint (context, i.x1, i.y1);
  202909. break;
  202910. case Path::Iterator::quadraticTo:
  202911. CGContextAddQuadCurveToPoint (context, i.x1, i.y1, i.x2, i.y2);
  202912. break;
  202913. case Path::Iterator::cubicTo:
  202914. CGContextAddCurveToPoint (context, i.x1, i.y1, i.x2, i.y2, i.x3, i.y3);
  202915. break;
  202916. case Path::Iterator::closePath:
  202917. CGContextClosePath (context); break;
  202918. default:
  202919. jassertfalse
  202920. break;
  202921. }
  202922. }
  202923. }
  202924. void createPath (const Path& path, const AffineTransform& transform) const
  202925. {
  202926. CGContextBeginPath (context);
  202927. Path::Iterator i (path);
  202928. while (i.next())
  202929. {
  202930. switch (i.elementType)
  202931. {
  202932. case Path::Iterator::startNewSubPath:
  202933. transform.transformPoint (i.x1, i.y1);
  202934. CGContextMoveToPoint (context, i.x1, flipHeight - i.y1);
  202935. break;
  202936. case Path::Iterator::lineTo:
  202937. transform.transformPoint (i.x1, i.y1);
  202938. CGContextAddLineToPoint (context, i.x1, flipHeight - i.y1);
  202939. break;
  202940. case Path::Iterator::quadraticTo:
  202941. transform.transformPoint (i.x1, i.y1);
  202942. transform.transformPoint (i.x2, i.y2);
  202943. CGContextAddQuadCurveToPoint (context, i.x1, flipHeight - i.y1, i.x2, flipHeight - i.y2);
  202944. break;
  202945. case Path::Iterator::cubicTo:
  202946. transform.transformPoint (i.x1, i.y1);
  202947. transform.transformPoint (i.x2, i.y2);
  202948. transform.transformPoint (i.x3, i.y3);
  202949. CGContextAddCurveToPoint (context, i.x1, flipHeight - i.y1, i.x2, flipHeight - i.y2, i.x3, flipHeight - i.y3);
  202950. break;
  202951. case Path::Iterator::closePath:
  202952. CGContextClosePath (context); break;
  202953. default:
  202954. jassertfalse
  202955. break;
  202956. }
  202957. }
  202958. }
  202959. static Image* createAlphaChannelImage (const Image& im)
  202960. {
  202961. if (im.getFormat() == Image::SingleChannel)
  202962. return const_cast <Image*> (&im);
  202963. return im.createCopyOfAlphaChannel();
  202964. }
  202965. static void deleteAlphaChannelImage (const Image& im, Image* const alphaIm)
  202966. {
  202967. if (im.getFormat() != Image::SingleChannel)
  202968. delete alphaIm;
  202969. }
  202970. void flip() const
  202971. {
  202972. CGContextConcatCTM (context, CGAffineTransformMake (1, 0, 0, -1, 0, flipHeight));
  202973. }
  202974. void applyTransform (const AffineTransform& transform) const
  202975. {
  202976. CGAffineTransform t;
  202977. t.a = transform.mat00;
  202978. t.b = transform.mat10;
  202979. t.c = transform.mat01;
  202980. t.d = transform.mat11;
  202981. t.tx = transform.mat02;
  202982. t.ty = transform.mat12;
  202983. CGContextConcatCTM (context, t);
  202984. }
  202985. float flipY (float y) const
  202986. {
  202987. return flipHeight - y;
  202988. }
  202989. };
  202990. LowLevelGraphicsContext* CoreGraphicsImage::createLowLevelContext()
  202991. {
  202992. return new CoreGraphicsContext (context, imageHeight);
  202993. }
  202994. #endif
  202995. /*** End of inlined file: juce_mac_CoreGraphicsContext.mm ***/
  202996. /*** Start of inlined file: juce_iphone_UIViewComponentPeer.mm ***/
  202997. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  202998. // compiled on its own).
  202999. #if JUCE_INCLUDED_FILE
  203000. class UIViewComponentPeer;
  203001. END_JUCE_NAMESPACE
  203002. #define JuceUIView MakeObjCClassName(JuceUIView)
  203003. @interface JuceUIView : UIView
  203004. {
  203005. @public
  203006. UIViewComponentPeer* owner;
  203007. }
  203008. - (JuceUIView*) initWithOwner: (UIViewComponentPeer*) owner withFrame: (CGRect) frame;
  203009. - (void) dealloc;
  203010. - (void) drawRect: (CGRect) r;
  203011. - (void) touchesBegan: (NSSet*) touches withEvent: (UIEvent*) event;
  203012. - (void) touchesMoved: (NSSet*) touches withEvent: (UIEvent*) event;
  203013. - (void) touchesEnded: (NSSet*) touches withEvent: (UIEvent*) event;
  203014. - (void) touchesCancelled: (NSSet*) touches withEvent: (UIEvent*) event;
  203015. - (BOOL) becomeFirstResponder;
  203016. - (BOOL) resignFirstResponder;
  203017. - (BOOL) canBecomeFirstResponder;
  203018. - (void) asyncRepaint: (id) rect;
  203019. @end
  203020. #define JuceUIWindow MakeObjCClassName(JuceUIWindow)
  203021. @interface JuceUIWindow : UIWindow
  203022. {
  203023. @private
  203024. UIViewComponentPeer* owner;
  203025. bool isZooming;
  203026. }
  203027. - (void) setOwner: (UIViewComponentPeer*) owner;
  203028. - (void) becomeKeyWindow;
  203029. @end
  203030. BEGIN_JUCE_NAMESPACE
  203031. class UIViewComponentPeer : public ComponentPeer
  203032. {
  203033. public:
  203034. UIViewComponentPeer (Component* const component,
  203035. const int windowStyleFlags,
  203036. UIView* viewToAttachTo);
  203037. ~UIViewComponentPeer();
  203038. void* getNativeHandle() const;
  203039. void setVisible (bool shouldBeVisible);
  203040. void setTitle (const String& title);
  203041. void setPosition (int x, int y);
  203042. void setSize (int w, int h);
  203043. void setBounds (int x, int y, int w, int h, const bool isNowFullScreen);
  203044. void getBounds (int& x, int& y, int& w, int& h, const bool global) const;
  203045. void getBounds (int& x, int& y, int& w, int& h) const;
  203046. int getScreenX() const;
  203047. int getScreenY() const;
  203048. void relativePositionToGlobal (int& x, int& y);
  203049. void globalPositionToRelative (int& x, int& y);
  203050. void setMinimised (bool shouldBeMinimised);
  203051. bool isMinimised() const;
  203052. void setFullScreen (bool shouldBeFullScreen);
  203053. bool isFullScreen() const;
  203054. bool contains (int x, int y, bool trueIfInAChildWindow) const;
  203055. const BorderSize getFrameSize() const;
  203056. bool setAlwaysOnTop (bool alwaysOnTop);
  203057. void toFront (bool makeActiveWindow);
  203058. void toBehind (ComponentPeer* other);
  203059. void setIcon (const Image& newIcon);
  203060. virtual void drawRect (CGRect r);
  203061. virtual bool canBecomeKeyWindow();
  203062. virtual bool windowShouldClose();
  203063. virtual void redirectMovedOrResized();
  203064. virtual CGRect constrainRect (CGRect r);
  203065. virtual void viewFocusGain();
  203066. virtual void viewFocusLoss();
  203067. bool isFocused() const;
  203068. void grabFocus();
  203069. void textInputRequired (int x, int y);
  203070. void repaint (int x, int y, int w, int h);
  203071. void performAnyPendingRepaintsNow();
  203072. juce_UseDebuggingNewOperator
  203073. UIWindow* window;
  203074. JuceUIView* view;
  203075. bool isSharedWindow, fullScreen, insideDrawRect;
  203076. };
  203077. END_JUCE_NAMESPACE
  203078. @implementation JuceUIView
  203079. - (JuceUIView*) initWithOwner: (UIViewComponentPeer*) owner_
  203080. withFrame: (CGRect) frame
  203081. {
  203082. [super initWithFrame: frame];
  203083. owner = owner_;
  203084. return self;
  203085. }
  203086. - (void) dealloc
  203087. {
  203088. [super dealloc];
  203089. }
  203090. - (void) drawRect: (CGRect) r
  203091. {
  203092. if (owner != 0)
  203093. owner->drawRect (r);
  203094. }
  203095. bool KeyPress::isKeyCurrentlyDown (const int keyCode) throw()
  203096. {
  203097. return false;
  203098. }
  203099. static int currentModifiers = 0;
  203100. const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw()
  203101. {
  203102. return ModifierKeys (currentModifiers);
  203103. }
  203104. void ModifierKeys::updateCurrentModifiers() throw()
  203105. {
  203106. currentModifierFlags = currentModifiers;
  203107. }
  203108. static int getModifierForButtonNumber (const int num)
  203109. {
  203110. return num == 0 ? ModifierKeys::leftButtonModifier
  203111. : (num == 1 ? ModifierKeys::rightButtonModifier
  203112. : (num == 2 ? ModifierKeys::middleButtonModifier : 0));
  203113. }
  203114. static int64 getMouseTime (UIEvent* e)
  203115. {
  203116. return (Time::currentTimeMillis() - Time::getMillisecondCounter())
  203117. + (int64) ([e timestamp] * 1000.0);
  203118. }
  203119. int juce_lastMouseX = 0, juce_lastMouseY = 0;
  203120. - (void) touchesBegan: (NSSet*) touches withEvent: (UIEvent*) event
  203121. {
  203122. if (owner == 0)
  203123. return;
  203124. NSArray* const t = [[event touchesForView: self] allObjects];
  203125. switch ([t count])
  203126. {
  203127. case 1: // One finger..
  203128. {
  203129. CGPoint p = [[t objectAtIndex: 0] locationInView: self];
  203130. currentModifiers |= getModifierForButtonNumber (0);
  203131. int x, y, w, h;
  203132. owner->getBounds (x, y, w, h, true);
  203133. juce_lastMouseX = x + (int) p.x;
  203134. juce_lastMouseY = y + (int) p.y;
  203135. owner->handleMouseMove ((int) p.x, (int) p.y, getMouseTime (event));
  203136. if (owner != 0)
  203137. owner->handleMouseDown ((int) p.x, (int) p.y, getMouseTime (event));
  203138. }
  203139. default:
  203140. //xxx multi-touch..
  203141. break;
  203142. }
  203143. }
  203144. - (void) touchesMoved: (NSSet*) touches withEvent: (UIEvent*) event
  203145. {
  203146. if (owner == 0)
  203147. return;
  203148. NSArray* const t = [[event touchesForView: self] allObjects];
  203149. switch ([t count])
  203150. {
  203151. case 1: // One finger..
  203152. {
  203153. CGPoint p = [[t objectAtIndex: 0] locationInView: self];
  203154. int x, y, w, h;
  203155. owner->getBounds (x, y, w, h, true);
  203156. juce_lastMouseX = x + (int) p.x;
  203157. juce_lastMouseY = y + (int) p.y;
  203158. owner->handleMouseDrag ((int) p.x, (int) p.y, getMouseTime (event));
  203159. }
  203160. default:
  203161. //xxx multi-touch..
  203162. break;
  203163. }
  203164. }
  203165. - (void) touchesEnded: (NSSet*) touches withEvent: (UIEvent*) event
  203166. {
  203167. if (owner == 0)
  203168. return;
  203169. NSArray* const t = [[event touchesForView: self] allObjects];
  203170. switch ([t count])
  203171. {
  203172. case 1: // One finger..
  203173. {
  203174. CGPoint p = [[t objectAtIndex: 0] locationInView: self];
  203175. int x, y, w, h;
  203176. owner->getBounds (x, y, w, h, true);
  203177. juce_lastMouseX = x + (int) p.x;
  203178. juce_lastMouseY = y + (int) p.y;
  203179. const int oldMods = currentModifiers;
  203180. currentModifiers &= ~getModifierForButtonNumber (0);
  203181. owner->handleMouseUp (oldMods, (int) p.x, (int) p.y, getMouseTime (event));
  203182. }
  203183. default:
  203184. //xxx multi-touch..
  203185. break;
  203186. }
  203187. }
  203188. - (void) touchesCancelled: (NSSet*) touches withEvent: (UIEvent*) event
  203189. {
  203190. [self touchesEnded: touches withEvent: event];
  203191. }
  203192. - (BOOL) becomeFirstResponder
  203193. {
  203194. if (owner != 0)
  203195. owner->viewFocusGain();
  203196. return true;
  203197. }
  203198. - (BOOL) resignFirstResponder
  203199. {
  203200. if (owner != 0)
  203201. owner->viewFocusLoss();
  203202. return true;
  203203. }
  203204. - (BOOL) canBecomeFirstResponder
  203205. {
  203206. return owner != 0 && owner->canBecomeKeyWindow();
  203207. }
  203208. - (void) asyncRepaint: (id) rect
  203209. {
  203210. CGRect* r = (CGRect*) [((NSData*) rect) bytes];
  203211. [self setNeedsDisplayInRect: *r];
  203212. }
  203213. @end
  203214. @implementation JuceUIWindow
  203215. - (void) setOwner: (UIViewComponentPeer*) owner_
  203216. {
  203217. owner = owner_;
  203218. isZooming = false;
  203219. }
  203220. - (void) becomeKeyWindow
  203221. {
  203222. [super becomeKeyWindow];
  203223. if (owner != 0)
  203224. owner->grabFocus();
  203225. }
  203226. @end
  203227. BEGIN_JUCE_NAMESPACE
  203228. UIViewComponentPeer::UIViewComponentPeer (Component* const component,
  203229. const int windowStyleFlags,
  203230. UIView* viewToAttachTo)
  203231. : ComponentPeer (component, windowStyleFlags),
  203232. window (0),
  203233. view (0),
  203234. isSharedWindow (viewToAttachTo != 0),
  203235. fullScreen (false),
  203236. insideDrawRect (false)
  203237. {
  203238. CGRect r;
  203239. r.origin.x = 0;
  203240. r.origin.y = 0;
  203241. r.size.width = (float) component->getWidth();
  203242. r.size.height = (float) component->getHeight();
  203243. view = [[JuceUIView alloc] initWithOwner: this withFrame: r];
  203244. if (isSharedWindow)
  203245. {
  203246. window = [viewToAttachTo window];
  203247. [viewToAttachTo addSubview: view];
  203248. setVisible (component->isVisible());
  203249. }
  203250. else
  203251. {
  203252. r.origin.x = (float) component->getX();
  203253. r.origin.y = (float) component->getY();
  203254. r.origin.y = [[UIScreen mainScreen] bounds].size.height - (r.origin.y + r.size.height);
  203255. window = [[JuceUIWindow alloc] init];
  203256. window.frame = r;
  203257. window.opaque = component->isOpaque();
  203258. view.opaque = component->isOpaque();
  203259. window.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent: 0];
  203260. view.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent: 0];
  203261. [((JuceUIWindow*) window) setOwner: this];
  203262. if (component->isAlwaysOnTop())
  203263. window.windowLevel = UIWindowLevelAlert;
  203264. [window addSubview: view];
  203265. view.frame = CGRectMake (0, 0, r.size.width, r.size.height);
  203266. view.hidden = ! component->isVisible();
  203267. window.hidden = ! component->isVisible();
  203268. }
  203269. setTitle (component->getName());
  203270. }
  203271. UIViewComponentPeer::~UIViewComponentPeer()
  203272. {
  203273. view->owner = 0;
  203274. [view removeFromSuperview];
  203275. [view release];
  203276. if (! isSharedWindow)
  203277. {
  203278. [((JuceUIWindow*) window) setOwner: 0];
  203279. [window release];
  203280. }
  203281. }
  203282. void* UIViewComponentPeer::getNativeHandle() const
  203283. {
  203284. return view;
  203285. }
  203286. void UIViewComponentPeer::setVisible (bool shouldBeVisible)
  203287. {
  203288. view.hidden = ! shouldBeVisible;
  203289. if (! isSharedWindow)
  203290. window.hidden = ! shouldBeVisible;
  203291. }
  203292. void UIViewComponentPeer::setTitle (const String& title)
  203293. {
  203294. // xxx is this possible?
  203295. }
  203296. void UIViewComponentPeer::setPosition (int x, int y)
  203297. {
  203298. setBounds (x, y, component->getWidth(), component->getHeight(), false);
  203299. }
  203300. void UIViewComponentPeer::setSize (int w, int h)
  203301. {
  203302. setBounds (component->getX(), component->getY(), w, h, false);
  203303. }
  203304. void UIViewComponentPeer::setBounds (int x, int y, int w, int h, const bool isNowFullScreen)
  203305. {
  203306. fullScreen = isNowFullScreen;
  203307. w = jmax (0, w);
  203308. h = jmax (0, h);
  203309. CGRect r;
  203310. r.origin.x = (float) x;
  203311. r.origin.y = (float) y;
  203312. r.size.width = (float) w;
  203313. r.size.height = (float) h;
  203314. if (isSharedWindow)
  203315. {
  203316. //r.origin.y = [[view superview] frame].size.height - (r.origin.y + r.size.height);
  203317. if ([view frame].size.width != r.size.width
  203318. || [view frame].size.height != r.size.height)
  203319. [view setNeedsDisplay];
  203320. view.frame = r;
  203321. }
  203322. else
  203323. {
  203324. window.frame = r;
  203325. view.frame = CGRectMake (0, 0, r.size.width, r.size.height);
  203326. }
  203327. }
  203328. void UIViewComponentPeer::getBounds (int& x, int& y, int& w, int& h, const bool global) const
  203329. {
  203330. CGRect r = [view frame];
  203331. if (global && [view window] != 0)
  203332. {
  203333. r = [view convertRect: r toView: nil];
  203334. CGRect wr = [[view window] frame];
  203335. r.origin.x += wr.origin.x;
  203336. r.origin.y += wr.origin.y;
  203337. }
  203338. x = (int) r.origin.x;
  203339. y = (int) r.origin.y;
  203340. w = (int) r.size.width;
  203341. h = (int) r.size.height;
  203342. }
  203343. void UIViewComponentPeer::getBounds (int& x, int& y, int& w, int& h) const
  203344. {
  203345. getBounds (x, y, w, h, ! isSharedWindow);
  203346. }
  203347. int UIViewComponentPeer::getScreenX() const
  203348. {
  203349. int x, y, w, h;
  203350. getBounds (x, y, w, h, true);
  203351. return x;
  203352. }
  203353. int UIViewComponentPeer::getScreenY() const
  203354. {
  203355. int x, y, w, h;
  203356. getBounds (x, y, w, h, true);
  203357. return y;
  203358. }
  203359. void UIViewComponentPeer::relativePositionToGlobal (int& x, int& y)
  203360. {
  203361. int wx, wy, ww, wh;
  203362. getBounds (wx, wy, ww, wh, true);
  203363. x += wx;
  203364. y += wy;
  203365. }
  203366. void UIViewComponentPeer::globalPositionToRelative (int& x, int& y)
  203367. {
  203368. int wx, wy, ww, wh;
  203369. getBounds (wx, wy, ww, wh, true);
  203370. x -= wx;
  203371. y -= wy;
  203372. }
  203373. CGRect UIViewComponentPeer::constrainRect (CGRect r)
  203374. {
  203375. if (constrainer != 0)
  203376. {
  203377. CGRect current = [window frame];
  203378. current.origin.y = [[UIScreen mainScreen] bounds].size.height - current.origin.y - current.size.height;
  203379. r.origin.y = [[UIScreen mainScreen] bounds].size.height - r.origin.y - r.size.height;
  203380. Rectangle<int> pos ((int) r.origin.x, (int) r.origin.y,
  203381. (int) r.size.width, (int) r.size.height);
  203382. Rectangle<int> original ((int) current.origin.x, (int) current.origin.y,
  203383. (int) current.size.width, (int) current.size.height);
  203384. constrainer->checkBounds (pos, original,
  203385. Desktop::getInstance().getAllMonitorDisplayAreas().getBounds(),
  203386. pos.getY() != original.getY() && pos.getBottom() == original.getBottom(),
  203387. pos.getX() != original.getX() && pos.getRight() == original.getRight(),
  203388. pos.getY() == original.getY() && pos.getBottom() != original.getBottom(),
  203389. pos.getX() == original.getX() && pos.getRight() != original.getRight());
  203390. r.origin.x = pos.getX();
  203391. r.origin.y = [[UIScreen mainScreen] bounds].size.height - r.size.height - pos.getY();
  203392. r.size.width = pos.getWidth();
  203393. r.size.height = pos.getHeight();
  203394. }
  203395. return r;
  203396. }
  203397. void UIViewComponentPeer::setMinimised (bool shouldBeMinimised)
  203398. {
  203399. // xxx
  203400. }
  203401. bool UIViewComponentPeer::isMinimised() const
  203402. {
  203403. return false;
  203404. }
  203405. void UIViewComponentPeer::setFullScreen (bool shouldBeFullScreen)
  203406. {
  203407. if (! isSharedWindow)
  203408. {
  203409. Rectangle<int> r (lastNonFullscreenBounds);
  203410. setMinimised (false);
  203411. if (fullScreen != shouldBeFullScreen)
  203412. {
  203413. if (shouldBeFullScreen)
  203414. r = Desktop::getInstance().getMainMonitorArea();
  203415. // (can't call the component's setBounds method because that'll reset our fullscreen flag)
  203416. if (r != getComponent()->getBounds() && ! r.isEmpty())
  203417. setBounds (r.getX(), r.getY(), r.getWidth(), r.getHeight(), shouldBeFullScreen);
  203418. }
  203419. }
  203420. }
  203421. bool UIViewComponentPeer::isFullScreen() const
  203422. {
  203423. return fullScreen;
  203424. }
  203425. bool UIViewComponentPeer::contains (int x, int y, bool trueIfInAChildWindow) const
  203426. {
  203427. if (((unsigned int) x) >= (unsigned int) component->getWidth()
  203428. || ((unsigned int) y) >= (unsigned int) component->getHeight())
  203429. return false;
  203430. CGPoint p;
  203431. p.x = (float) x;
  203432. p.y = (float) y;
  203433. UIView* v = [view hitTest: p withEvent: nil];
  203434. if (trueIfInAChildWindow)
  203435. return v != nil;
  203436. return v == view;
  203437. }
  203438. const BorderSize UIViewComponentPeer::getFrameSize() const
  203439. {
  203440. BorderSize b;
  203441. if (! isSharedWindow)
  203442. {
  203443. CGRect v = [view convertRect: [view frame] toView: nil];
  203444. CGRect w = [window frame];
  203445. b.setTop ((int) (w.size.height - (v.origin.y + v.size.height)));
  203446. b.setBottom ((int) v.origin.y);
  203447. b.setLeft ((int) v.origin.x);
  203448. b.setRight ((int) (w.size.width - (v.origin.x + v.size.width)));
  203449. }
  203450. return b;
  203451. }
  203452. bool UIViewComponentPeer::setAlwaysOnTop (bool alwaysOnTop)
  203453. {
  203454. if (! isSharedWindow)
  203455. window.windowLevel = alwaysOnTop ? UIWindowLevelAlert : UIWindowLevelNormal;
  203456. return true;
  203457. }
  203458. void UIViewComponentPeer::toFront (bool makeActiveWindow)
  203459. {
  203460. if (isSharedWindow)
  203461. [[view superview] bringSubviewToFront: view];
  203462. if (window != 0 && component->isVisible())
  203463. [window makeKeyAndVisible];
  203464. }
  203465. void UIViewComponentPeer::toBehind (ComponentPeer* other)
  203466. {
  203467. UIViewComponentPeer* o = (UIViewComponentPeer*) other;
  203468. if (isSharedWindow)
  203469. {
  203470. [[view superview] insertSubview: view belowSubview: o->view];
  203471. }
  203472. else
  203473. {
  203474. jassertfalse // don't know how to do this
  203475. }
  203476. }
  203477. void UIViewComponentPeer::setIcon (const Image& /*newIcon*/)
  203478. {
  203479. // to do..
  203480. }
  203481. static UIViewComponentPeer* currentlyFocusedPeer = 0;
  203482. void UIViewComponentPeer::viewFocusGain()
  203483. {
  203484. if (currentlyFocusedPeer != this)
  203485. {
  203486. if (ComponentPeer::isValidPeer (currentlyFocusedPeer))
  203487. currentlyFocusedPeer->handleFocusLoss();
  203488. currentlyFocusedPeer = this;
  203489. handleFocusGain();
  203490. }
  203491. }
  203492. void UIViewComponentPeer::viewFocusLoss()
  203493. {
  203494. if (currentlyFocusedPeer == this)
  203495. {
  203496. currentlyFocusedPeer = 0;
  203497. handleFocusLoss();
  203498. }
  203499. }
  203500. void juce_HandleProcessFocusChange()
  203501. {
  203502. if (UIViewComponentPeer::isValidPeer (currentlyFocusedPeer))
  203503. {
  203504. if (Process::isForegroundProcess())
  203505. {
  203506. currentlyFocusedPeer->handleFocusGain();
  203507. ComponentPeer::bringModalComponentToFront();
  203508. }
  203509. else
  203510. {
  203511. currentlyFocusedPeer->handleFocusLoss();
  203512. // turn kiosk mode off if we lose focus..
  203513. Desktop::getInstance().setKioskModeComponent (0);
  203514. }
  203515. }
  203516. }
  203517. bool UIViewComponentPeer::isFocused() const
  203518. {
  203519. return isSharedWindow ? this == currentlyFocusedPeer
  203520. : (window != 0 && [window isKeyWindow]);
  203521. }
  203522. void UIViewComponentPeer::grabFocus()
  203523. {
  203524. if (window != 0)
  203525. {
  203526. [window makeKeyWindow];
  203527. viewFocusGain();
  203528. }
  203529. }
  203530. void UIViewComponentPeer::textInputRequired (int /*x*/, int /*y*/)
  203531. {
  203532. }
  203533. void UIViewComponentPeer::drawRect (CGRect r)
  203534. {
  203535. if (r.size.width < 1.0f || r.size.height < 1.0f)
  203536. return;
  203537. CGContextRef cg = UIGraphicsGetCurrentContext();
  203538. if (! component->isOpaque())
  203539. CGContextClearRect (cg, CGContextGetClipBoundingBox (cg));
  203540. CGContextConcatCTM (cg, CGAffineTransformMake (1, 0, 0, -1, 0, view.bounds.size.height));
  203541. CoreGraphicsContext g (cg, view.bounds.size.height);
  203542. insideDrawRect = true;
  203543. handlePaint (g);
  203544. insideDrawRect = false;
  203545. }
  203546. bool UIViewComponentPeer::canBecomeKeyWindow()
  203547. {
  203548. return (getStyleFlags() & JUCE_NAMESPACE::ComponentPeer::windowIgnoresKeyPresses) == 0;
  203549. }
  203550. bool UIViewComponentPeer::windowShouldClose()
  203551. {
  203552. if (! isValidPeer (this))
  203553. return YES;
  203554. handleUserClosingWindow();
  203555. return NO;
  203556. }
  203557. void UIViewComponentPeer::redirectMovedOrResized()
  203558. {
  203559. handleMovedOrResized();
  203560. }
  203561. void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars)
  203562. {
  203563. }
  203564. class AsyncRepaintMessage : public CallbackMessage
  203565. {
  203566. public:
  203567. UIViewComponentPeer* const peer;
  203568. const Rectangle<int> rect;
  203569. AsyncRepaintMessage (UIViewComponentPeer* const peer_, const Rectangle<int>& rect_)
  203570. : peer (peer_), rect (rect_)
  203571. {
  203572. }
  203573. void messageCallback()
  203574. {
  203575. if (ComponentPeer::isValidPeer (peer))
  203576. peer->repaint (rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight());
  203577. }
  203578. };
  203579. void UIViewComponentPeer::repaint (int x, int y, int w, int h)
  203580. {
  203581. if (insideDrawRect || ! MessageManager::getInstance()->isThisTheMessageThread())
  203582. {
  203583. (new AsyncRepaintMessage (this, Rectangle<int> (x, y, w, h)))->post();
  203584. }
  203585. else
  203586. {
  203587. [view setNeedsDisplayInRect: CGRectMake ((float) x, (float) y, (float) w, (float) h)];
  203588. }
  203589. }
  203590. void UIViewComponentPeer::performAnyPendingRepaintsNow()
  203591. {
  203592. }
  203593. ComponentPeer* Component::createNewPeer (int styleFlags, void* windowToAttachTo)
  203594. {
  203595. return new UIViewComponentPeer (this, styleFlags, (UIView*) windowToAttachTo);
  203596. }
  203597. Image* juce_createIconForFile (const File& file)
  203598. {
  203599. return 0;
  203600. }
  203601. bool Desktop::canUseSemiTransparentWindows() throw()
  203602. {
  203603. return true;
  203604. }
  203605. void Desktop::getMousePosition (int& x, int& y) throw()
  203606. {
  203607. x = juce_lastMouseX;
  203608. y = juce_lastMouseY;
  203609. }
  203610. void Desktop::setMousePosition (int x, int y) throw()
  203611. {
  203612. }
  203613. const int KeyPress::spaceKey = ' ';
  203614. const int KeyPress::returnKey = 0x0d;
  203615. const int KeyPress::escapeKey = 0x1b;
  203616. const int KeyPress::backspaceKey = 0x7f;
  203617. const int KeyPress::leftKey = 0x1000;
  203618. const int KeyPress::rightKey = 0x1001;
  203619. const int KeyPress::upKey = 0x1002;
  203620. const int KeyPress::downKey = 0x1003;
  203621. const int KeyPress::pageUpKey = 0x1004;
  203622. const int KeyPress::pageDownKey = 0x1005;
  203623. const int KeyPress::endKey = 0x1006;
  203624. const int KeyPress::homeKey = 0x1007;
  203625. const int KeyPress::deleteKey = 0x1008;
  203626. const int KeyPress::insertKey = -1;
  203627. const int KeyPress::tabKey = 9;
  203628. const int KeyPress::F1Key = 0x2001;
  203629. const int KeyPress::F2Key = 0x2002;
  203630. const int KeyPress::F3Key = 0x2003;
  203631. const int KeyPress::F4Key = 0x2004;
  203632. const int KeyPress::F5Key = 0x2005;
  203633. const int KeyPress::F6Key = 0x2006;
  203634. const int KeyPress::F7Key = 0x2007;
  203635. const int KeyPress::F8Key = 0x2008;
  203636. const int KeyPress::F9Key = 0x2009;
  203637. const int KeyPress::F10Key = 0x200a;
  203638. const int KeyPress::F11Key = 0x200b;
  203639. const int KeyPress::F12Key = 0x200c;
  203640. const int KeyPress::F13Key = 0x200d;
  203641. const int KeyPress::F14Key = 0x200e;
  203642. const int KeyPress::F15Key = 0x200f;
  203643. const int KeyPress::F16Key = 0x2010;
  203644. const int KeyPress::numberPad0 = 0x30020;
  203645. const int KeyPress::numberPad1 = 0x30021;
  203646. const int KeyPress::numberPad2 = 0x30022;
  203647. const int KeyPress::numberPad3 = 0x30023;
  203648. const int KeyPress::numberPad4 = 0x30024;
  203649. const int KeyPress::numberPad5 = 0x30025;
  203650. const int KeyPress::numberPad6 = 0x30026;
  203651. const int KeyPress::numberPad7 = 0x30027;
  203652. const int KeyPress::numberPad8 = 0x30028;
  203653. const int KeyPress::numberPad9 = 0x30029;
  203654. const int KeyPress::numberPadAdd = 0x3002a;
  203655. const int KeyPress::numberPadSubtract = 0x3002b;
  203656. const int KeyPress::numberPadMultiply = 0x3002c;
  203657. const int KeyPress::numberPadDivide = 0x3002d;
  203658. const int KeyPress::numberPadSeparator = 0x3002e;
  203659. const int KeyPress::numberPadDecimalPoint = 0x3002f;
  203660. const int KeyPress::numberPadEquals = 0x30030;
  203661. const int KeyPress::numberPadDelete = 0x30031;
  203662. const int KeyPress::playKey = 0x30000;
  203663. const int KeyPress::stopKey = 0x30001;
  203664. const int KeyPress::fastForwardKey = 0x30002;
  203665. const int KeyPress::rewindKey = 0x30003;
  203666. #endif
  203667. /*** End of inlined file: juce_iphone_UIViewComponentPeer.mm ***/
  203668. /*** Start of inlined file: juce_iphone_MessageManager.mm ***/
  203669. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  203670. // compiled on its own).
  203671. #if JUCE_INCLUDED_FILE
  203672. struct CallbackMessagePayload
  203673. {
  203674. MessageCallbackFunction* function;
  203675. void* parameter;
  203676. void* volatile result;
  203677. bool volatile hasBeenExecuted;
  203678. };
  203679. END_JUCE_NAMESPACE
  203680. using namespace JUCE_NAMESPACE;
  203681. @interface JuceAppDelegate : NSObject <UIApplicationDelegate>
  203682. {
  203683. }
  203684. - (JuceAppDelegate*) init;
  203685. - (void) dealloc;
  203686. - (BOOL) application: (UIApplication*) application handleOpenURL: (NSURL*) url;
  203687. - (void) applicationDidBecomeActive: (NSNotification*) aNotification;
  203688. - (void) applicationDidResignActive: (NSNotification*) aNotification;
  203689. - (void) applicationWillUnhide: (NSNotification*) aNotification;
  203690. - (void) customEvent: (id) data;
  203691. - (void) performCallback: (id) info;
  203692. @end
  203693. @implementation JuceAppDelegate
  203694. - (JuceAppDelegate*) init
  203695. {
  203696. [super init];
  203697. [[UIApplication sharedApplication] setDelegate: self];
  203698. return self;
  203699. }
  203700. - (void) dealloc
  203701. {
  203702. [[UIApplication sharedApplication] setDelegate: nil];
  203703. [super dealloc];
  203704. }
  203705. - (BOOL) application: (UIApplication*) application handleOpenURL: (NSURL*) url
  203706. {
  203707. if (JUCEApplication::getInstance() != 0)
  203708. {
  203709. JUCEApplication::getInstance()->anotherInstanceStarted (nsStringToJuce ([url absoluteString]));
  203710. return YES;
  203711. }
  203712. return NO;
  203713. }
  203714. - (void) applicationDidBecomeActive: (NSNotification*) aNotification
  203715. {
  203716. juce_HandleProcessFocusChange();
  203717. }
  203718. - (void) applicationDidResignActive: (NSNotification*) aNotification
  203719. {
  203720. juce_HandleProcessFocusChange();
  203721. }
  203722. - (void) applicationWillUnhide: (NSNotification*) aNotification
  203723. {
  203724. juce_HandleProcessFocusChange();
  203725. }
  203726. - (void) customEvent: (id) n
  203727. {
  203728. NSData* data = (NSData*) n;
  203729. void* message = 0;
  203730. [data getBytes: &message length: sizeof (message)];
  203731. [data release];
  203732. if (message != 0)
  203733. MessageManager::getInstance()->deliverMessage (message);
  203734. }
  203735. - (void) performCallback: (id) info
  203736. {
  203737. if ([info isKindOfClass: [NSData class]])
  203738. {
  203739. CallbackMessagePayload* pl = (CallbackMessagePayload*) [((NSData*) info) bytes];
  203740. if (pl != 0)
  203741. {
  203742. pl->result = (*pl->function) (pl->parameter);
  203743. pl->hasBeenExecuted = true;
  203744. }
  203745. }
  203746. else
  203747. {
  203748. jassertfalse // should never get here!
  203749. }
  203750. }
  203751. @end
  203752. BEGIN_JUCE_NAMESPACE
  203753. static JuceAppDelegate* juceAppDelegate = 0;
  203754. void MessageManager::runDispatchLoop()
  203755. {
  203756. jassert (isThisTheMessageThread()); // must only be called by the message thread
  203757. runDispatchLoopUntil (-1);
  203758. }
  203759. void MessageManager::stopDispatchLoop()
  203760. {
  203761. exit (0); // iPhone apps get no mercy..
  203762. }
  203763. bool MessageManager::runDispatchLoopUntil (int millisecondsToRunFor)
  203764. {
  203765. const ScopedAutoReleasePool pool;
  203766. jassert (isThisTheMessageThread()); // must only be called by the message thread
  203767. uint32 endTime = Time::getMillisecondCounter() + millisecondsToRunFor;
  203768. NSDate* endDate = [NSDate dateWithTimeIntervalSinceNow: millisecondsToRunFor * 0.001];
  203769. while (! quitMessagePosted)
  203770. {
  203771. const ScopedAutoReleasePool pool;
  203772. [[NSRunLoop currentRunLoop] runMode: NSDefaultRunLoopMode
  203773. beforeDate: endDate];
  203774. if (millisecondsToRunFor >= 0 && Time::getMillisecondCounter() >= endTime)
  203775. break;
  203776. }
  203777. return ! quitMessagePosted;
  203778. }
  203779. static CFRunLoopRef runLoop = 0;
  203780. static CFRunLoopSourceRef runLoopSource = 0;
  203781. static Array <void*, CriticalSection>* pendingMessages = 0;
  203782. static void runLoopSourceCallback (void*)
  203783. {
  203784. if (pendingMessages != 0)
  203785. {
  203786. int numDispatched = 0;
  203787. do
  203788. {
  203789. void* const nextMessage = pendingMessages->remove (0);
  203790. if (nextMessage == 0)
  203791. return;
  203792. const ScopedAutoReleasePool pool;
  203793. MessageManager::getInstance()->deliverMessage (nextMessage);
  203794. } while (++numDispatched <= 4);
  203795. CFRunLoopSourceSignal (runLoopSource);
  203796. CFRunLoopWakeUp (runLoop);
  203797. }
  203798. }
  203799. void MessageManager::doPlatformSpecificInitialisation()
  203800. {
  203801. pendingMessages = new Array <void*, CriticalSection>();
  203802. runLoop = CFRunLoopGetCurrent();
  203803. CFRunLoopSourceContext sourceContext;
  203804. zerostruct (sourceContext);
  203805. sourceContext.perform = runLoopSourceCallback;
  203806. runLoopSource = CFRunLoopSourceCreate (kCFAllocatorDefault, 1, &sourceContext);
  203807. CFRunLoopAddSource (runLoop, runLoopSource, kCFRunLoopCommonModes);
  203808. if (juceAppDelegate == 0)
  203809. juceAppDelegate = [[JuceAppDelegate alloc] init];
  203810. }
  203811. void MessageManager::doPlatformSpecificShutdown()
  203812. {
  203813. CFRunLoopSourceInvalidate (runLoopSource);
  203814. CFRelease (runLoopSource);
  203815. runLoopSource = 0;
  203816. if (pendingMessages != 0)
  203817. {
  203818. while (pendingMessages->size() > 0)
  203819. delete ((Message*) pendingMessages->remove(0));
  203820. deleteAndZero (pendingMessages);
  203821. }
  203822. if (juceAppDelegate != 0)
  203823. {
  203824. [[NSRunLoop currentRunLoop] cancelPerformSelectorsWithTarget: juceAppDelegate];
  203825. [juceAppDelegate release];
  203826. juceAppDelegate = 0;
  203827. }
  203828. }
  203829. bool juce_postMessageToSystemQueue (void* message)
  203830. {
  203831. if (pendingMessages != 0)
  203832. {
  203833. pendingMessages->add (message);
  203834. CFRunLoopSourceSignal (runLoopSource);
  203835. CFRunLoopWakeUp (runLoop);
  203836. }
  203837. return true;
  203838. }
  203839. void MessageManager::broadcastMessage (const String& value) throw()
  203840. {
  203841. }
  203842. void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* callback,
  203843. void* data)
  203844. {
  203845. if (isThisTheMessageThread())
  203846. {
  203847. return (*callback) (data);
  203848. }
  203849. else
  203850. {
  203851. // If a thread has a MessageManagerLock and then tries to call this method, it'll
  203852. // deadlock because the message manager is blocked from running, so can never
  203853. // call your function..
  203854. jassert (! MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  203855. const ScopedAutoReleasePool pool;
  203856. CallbackMessagePayload cmp;
  203857. cmp.function = callback;
  203858. cmp.parameter = data;
  203859. cmp.result = 0;
  203860. cmp.hasBeenExecuted = false;
  203861. [juceAppDelegate performSelectorOnMainThread: @selector (performCallback:)
  203862. withObject: [NSData dataWithBytesNoCopy: &cmp
  203863. length: sizeof (cmp)
  203864. freeWhenDone: NO]
  203865. waitUntilDone: YES];
  203866. return cmp.result;
  203867. }
  203868. }
  203869. #endif
  203870. /*** End of inlined file: juce_iphone_MessageManager.mm ***/
  203871. /*** Start of inlined file: juce_mac_FileChooser.mm ***/
  203872. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  203873. // compiled on its own).
  203874. #if JUCE_INCLUDED_FILE
  203875. #if JUCE_MAC
  203876. END_JUCE_NAMESPACE
  203877. using namespace JUCE_NAMESPACE;
  203878. #define JuceFileChooserDelegate MakeObjCClassName(JuceFileChooserDelegate)
  203879. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  203880. @interface JuceFileChooserDelegate : NSObject <NSOpenSavePanelDelegate>
  203881. #else
  203882. @interface JuceFileChooserDelegate : NSObject
  203883. #endif
  203884. {
  203885. StringArray* filters;
  203886. }
  203887. - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_;
  203888. - (void) dealloc;
  203889. - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename;
  203890. @end
  203891. @implementation JuceFileChooserDelegate
  203892. - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_
  203893. {
  203894. [super init];
  203895. filters = filters_;
  203896. return self;
  203897. }
  203898. - (void) dealloc
  203899. {
  203900. delete filters;
  203901. [super dealloc];
  203902. }
  203903. - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename
  203904. {
  203905. const File f (nsStringToJuce (filename));
  203906. for (int i = filters->size(); --i >= 0;)
  203907. if (f.getFileName().matchesWildcard ((*filters)[i], true))
  203908. return true;
  203909. return f.isDirectory();
  203910. }
  203911. @end
  203912. BEGIN_JUCE_NAMESPACE
  203913. void FileChooser::showPlatformDialog (Array<File>& results,
  203914. const String& title,
  203915. const File& currentFileOrDirectory,
  203916. const String& filter,
  203917. bool selectsDirectory,
  203918. bool selectsFiles,
  203919. bool isSaveDialogue,
  203920. bool warnAboutOverwritingExistingFiles,
  203921. bool selectMultipleFiles,
  203922. FilePreviewComponent* extraInfoComponent)
  203923. {
  203924. const ScopedAutoReleasePool pool;
  203925. StringArray* filters = new StringArray();
  203926. filters->addTokens (filter.replaceCharacters (T(",:"), T(";;")), T(";"), 0);
  203927. filters->trim();
  203928. filters->removeEmptyStrings();
  203929. JuceFileChooserDelegate* delegate = [[JuceFileChooserDelegate alloc] initWithFilters: filters];
  203930. [delegate autorelease];
  203931. NSSavePanel* panel = isSaveDialogue ? [NSSavePanel savePanel]
  203932. : [NSOpenPanel openPanel];
  203933. [panel setTitle: juceStringToNS (title)];
  203934. if (! isSaveDialogue)
  203935. {
  203936. NSOpenPanel* openPanel = (NSOpenPanel*) panel;
  203937. [openPanel setCanChooseDirectories: selectsDirectory];
  203938. [openPanel setCanChooseFiles: selectsFiles];
  203939. [openPanel setAllowsMultipleSelection: selectMultipleFiles];
  203940. }
  203941. [panel setDelegate: delegate];
  203942. if (isSaveDialogue || selectsDirectory)
  203943. [panel setCanCreateDirectories: YES];
  203944. String directory, filename;
  203945. if (currentFileOrDirectory.isDirectory())
  203946. {
  203947. directory = currentFileOrDirectory.getFullPathName();
  203948. }
  203949. else
  203950. {
  203951. directory = currentFileOrDirectory.getParentDirectory().getFullPathName();
  203952. filename = currentFileOrDirectory.getFileName();
  203953. }
  203954. if ([panel runModalForDirectory: juceStringToNS (directory)
  203955. file: juceStringToNS (filename)]
  203956. == NSOKButton)
  203957. {
  203958. if (isSaveDialogue)
  203959. {
  203960. results.add (File (nsStringToJuce ([panel filename])));
  203961. }
  203962. else
  203963. {
  203964. NSOpenPanel* openPanel = (NSOpenPanel*) panel;
  203965. NSArray* urls = [openPanel filenames];
  203966. for (unsigned int i = 0; i < [urls count]; ++i)
  203967. {
  203968. NSString* f = [urls objectAtIndex: i];
  203969. results.add (File (nsStringToJuce (f)));
  203970. }
  203971. }
  203972. }
  203973. [panel setDelegate: nil];
  203974. }
  203975. #else
  203976. void FileChooser::showPlatformDialog (Array<File>& results,
  203977. const String& title,
  203978. const File& currentFileOrDirectory,
  203979. const String& filter,
  203980. bool selectsDirectory,
  203981. bool selectsFiles,
  203982. bool isSaveDialogue,
  203983. bool warnAboutOverwritingExistingFiles,
  203984. bool selectMultipleFiles,
  203985. FilePreviewComponent* extraInfoComponent)
  203986. {
  203987. const ScopedAutoReleasePool pool;
  203988. jassertfalse //xxx to do
  203989. }
  203990. #endif
  203991. #endif
  203992. /*** End of inlined file: juce_mac_FileChooser.mm ***/
  203993. /*** Start of inlined file: juce_mac_OpenGLComponent.mm ***/
  203994. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  203995. // compiled on its own).
  203996. #if JUCE_INCLUDED_FILE && JUCE_OPENGL
  203997. #if JUCE_MAC
  203998. END_JUCE_NAMESPACE
  203999. #define ThreadSafeNSOpenGLView MakeObjCClassName(ThreadSafeNSOpenGLView)
  204000. @interface ThreadSafeNSOpenGLView : NSOpenGLView
  204001. {
  204002. CriticalSection* contextLock;
  204003. bool needsUpdate;
  204004. }
  204005. - (id) initWithFrame: (NSRect) frameRect pixelFormat: (NSOpenGLPixelFormat*) format;
  204006. - (bool) makeActive;
  204007. - (void) makeInactive;
  204008. - (void) reshape;
  204009. @end
  204010. @implementation ThreadSafeNSOpenGLView
  204011. - (id) initWithFrame: (NSRect) frameRect
  204012. pixelFormat: (NSOpenGLPixelFormat*) format
  204013. {
  204014. contextLock = new CriticalSection();
  204015. self = [super initWithFrame: frameRect pixelFormat: format];
  204016. if (self != nil)
  204017. [[NSNotificationCenter defaultCenter] addObserver: self
  204018. selector: @selector (_surfaceNeedsUpdate:)
  204019. name: NSViewGlobalFrameDidChangeNotification
  204020. object: self];
  204021. return self;
  204022. }
  204023. - (void) dealloc
  204024. {
  204025. [[NSNotificationCenter defaultCenter] removeObserver: self];
  204026. delete contextLock;
  204027. [super dealloc];
  204028. }
  204029. - (bool) makeActive
  204030. {
  204031. const ScopedLock sl (*contextLock);
  204032. if ([self openGLContext] == 0)
  204033. return false;
  204034. [[self openGLContext] makeCurrentContext];
  204035. if (needsUpdate)
  204036. {
  204037. [super update];
  204038. needsUpdate = false;
  204039. }
  204040. return true;
  204041. }
  204042. - (void) makeInactive
  204043. {
  204044. const ScopedLock sl (*contextLock);
  204045. [NSOpenGLContext clearCurrentContext];
  204046. }
  204047. - (void) _surfaceNeedsUpdate: (NSNotification*) notification
  204048. {
  204049. const ScopedLock sl (*contextLock);
  204050. needsUpdate = true;
  204051. }
  204052. - (void) update
  204053. {
  204054. const ScopedLock sl (*contextLock);
  204055. needsUpdate = true;
  204056. }
  204057. - (void) reshape
  204058. {
  204059. const ScopedLock sl (*contextLock);
  204060. needsUpdate = true;
  204061. }
  204062. @end
  204063. BEGIN_JUCE_NAMESPACE
  204064. class WindowedGLContext : public OpenGLContext
  204065. {
  204066. public:
  204067. WindowedGLContext (Component* const component,
  204068. const OpenGLPixelFormat& pixelFormat_,
  204069. NSOpenGLContext* sharedContext)
  204070. : renderContext (0),
  204071. pixelFormat (pixelFormat_)
  204072. {
  204073. jassert (component != 0);
  204074. NSOpenGLPixelFormatAttribute attribs [64];
  204075. int n = 0;
  204076. attribs[n++] = NSOpenGLPFADoubleBuffer;
  204077. attribs[n++] = NSOpenGLPFAAccelerated;
  204078. attribs[n++] = NSOpenGLPFAMPSafe; // NSOpenGLPFAAccelerated, NSOpenGLPFAMultiScreen, NSOpenGLPFASingleRenderer
  204079. attribs[n++] = NSOpenGLPFAColorSize;
  204080. attribs[n++] = (NSOpenGLPixelFormatAttribute) jmax (pixelFormat.redBits,
  204081. pixelFormat.greenBits,
  204082. pixelFormat.blueBits);
  204083. attribs[n++] = NSOpenGLPFAAlphaSize;
  204084. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.alphaBits;
  204085. attribs[n++] = NSOpenGLPFADepthSize;
  204086. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.depthBufferBits;
  204087. attribs[n++] = NSOpenGLPFAStencilSize;
  204088. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.stencilBufferBits;
  204089. attribs[n++] = NSOpenGLPFAAccumSize;
  204090. attribs[n++] = (NSOpenGLPixelFormatAttribute) jmax (pixelFormat.accumulationBufferRedBits,
  204091. pixelFormat.accumulationBufferGreenBits,
  204092. pixelFormat.accumulationBufferBlueBits,
  204093. pixelFormat.accumulationBufferAlphaBits);
  204094. // xxx not sure how to do fullSceneAntiAliasingNumSamples..
  204095. attribs[n++] = NSOpenGLPFASampleBuffers;
  204096. attribs[n++] = (NSOpenGLPixelFormatAttribute) 1;
  204097. attribs[n++] = NSOpenGLPFAClosestPolicy;
  204098. attribs[n++] = NSOpenGLPFANoRecovery;
  204099. attribs[n++] = (NSOpenGLPixelFormatAttribute) 0;
  204100. NSOpenGLPixelFormat* format
  204101. = [[NSOpenGLPixelFormat alloc] initWithAttributes: attribs];
  204102. view = [[ThreadSafeNSOpenGLView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
  204103. pixelFormat: format];
  204104. renderContext = [[[NSOpenGLContext alloc] initWithFormat: format
  204105. shareContext: sharedContext] autorelease];
  204106. const GLint swapInterval = 1;
  204107. [renderContext setValues: &swapInterval forParameter: NSOpenGLCPSwapInterval];
  204108. [view setOpenGLContext: renderContext];
  204109. [renderContext setView: view];
  204110. [format release];
  204111. viewHolder = new NSViewComponentInternal (view, component);
  204112. }
  204113. ~WindowedGLContext()
  204114. {
  204115. makeInactive();
  204116. [renderContext clearDrawable];
  204117. viewHolder = 0;
  204118. }
  204119. bool makeActive() const throw()
  204120. {
  204121. jassert (renderContext != 0);
  204122. [view makeActive];
  204123. return isActive();
  204124. }
  204125. bool makeInactive() const throw()
  204126. {
  204127. [view makeInactive];
  204128. return true;
  204129. }
  204130. bool isActive() const throw()
  204131. {
  204132. return [NSOpenGLContext currentContext] == renderContext;
  204133. }
  204134. const OpenGLPixelFormat getPixelFormat() const { return pixelFormat; }
  204135. void* getRawContext() const throw() { return renderContext; }
  204136. void updateWindowPosition (int x, int y, int w, int h, int outerWindowHeight)
  204137. {
  204138. }
  204139. void swapBuffers()
  204140. {
  204141. [renderContext flushBuffer];
  204142. }
  204143. bool setSwapInterval (const int numFramesPerSwap)
  204144. {
  204145. [renderContext setValues: (const GLint*) &numFramesPerSwap
  204146. forParameter: NSOpenGLCPSwapInterval];
  204147. return true;
  204148. }
  204149. int getSwapInterval() const
  204150. {
  204151. GLint numFrames = 0;
  204152. [renderContext getValues: &numFrames
  204153. forParameter: NSOpenGLCPSwapInterval];
  204154. return numFrames;
  204155. }
  204156. void repaint()
  204157. {
  204158. // we need to invalidate the juce view that holds this gl view, to make it
  204159. // cause a repaint callback
  204160. NSView* v = (NSView*) viewHolder->view;
  204161. NSRect r = [v frame];
  204162. // bit of a bodge here.. if we only invalidate the area of the gl component,
  204163. // it's completely covered by the NSOpenGLView, so the OS throws away the
  204164. // repaint message, thus never causing our paint() callback, and never repainting
  204165. // the comp. So invalidating just a little bit around the edge helps..
  204166. [[v superview] setNeedsDisplayInRect: NSInsetRect (r, -2.0f, -2.0f)];
  204167. }
  204168. void* getNativeWindowHandle() const { return viewHolder->view; }
  204169. juce_UseDebuggingNewOperator
  204170. NSOpenGLContext* renderContext;
  204171. ThreadSafeNSOpenGLView* view;
  204172. private:
  204173. OpenGLPixelFormat pixelFormat;
  204174. ScopedPointer <NSViewComponentInternal> viewHolder;
  204175. WindowedGLContext (const WindowedGLContext&);
  204176. const WindowedGLContext& operator= (const WindowedGLContext&);
  204177. };
  204178. OpenGLContext* OpenGLContext::createContextForWindow (Component* const component,
  204179. const OpenGLPixelFormat& pixelFormat,
  204180. const OpenGLContext* const contextToShareWith)
  204181. {
  204182. ScopedPointer <WindowedGLContext> c (new WindowedGLContext (component, pixelFormat,
  204183. contextToShareWith != 0 ? (NSOpenGLContext*) contextToShareWith->getRawContext() : 0));
  204184. return (c->renderContext != 0) ? c.release() : 0;
  204185. }
  204186. void* OpenGLComponent::getNativeWindowHandle() const
  204187. {
  204188. return context != 0 ? ((WindowedGLContext*) context)->getNativeWindowHandle()
  204189. : 0;
  204190. }
  204191. void juce_glViewport (const int w, const int h)
  204192. {
  204193. glViewport (0, 0, w, h);
  204194. }
  204195. void OpenGLPixelFormat::getAvailablePixelFormats (Component* /*component*/,
  204196. OwnedArray <OpenGLPixelFormat>& results)
  204197. {
  204198. /* GLint attribs [64];
  204199. int n = 0;
  204200. attribs[n++] = AGL_RGBA;
  204201. attribs[n++] = AGL_DOUBLEBUFFER;
  204202. attribs[n++] = AGL_ACCELERATED;
  204203. attribs[n++] = AGL_NO_RECOVERY;
  204204. attribs[n++] = AGL_NONE;
  204205. AGLPixelFormat p = aglChoosePixelFormat (0, 0, attribs);
  204206. while (p != 0)
  204207. {
  204208. OpenGLPixelFormat* const pf = new OpenGLPixelFormat();
  204209. pf->redBits = getAGLAttribute (p, AGL_RED_SIZE);
  204210. pf->greenBits = getAGLAttribute (p, AGL_GREEN_SIZE);
  204211. pf->blueBits = getAGLAttribute (p, AGL_BLUE_SIZE);
  204212. pf->alphaBits = getAGLAttribute (p, AGL_ALPHA_SIZE);
  204213. pf->depthBufferBits = getAGLAttribute (p, AGL_DEPTH_SIZE);
  204214. pf->stencilBufferBits = getAGLAttribute (p, AGL_STENCIL_SIZE);
  204215. pf->accumulationBufferRedBits = getAGLAttribute (p, AGL_ACCUM_RED_SIZE);
  204216. pf->accumulationBufferGreenBits = getAGLAttribute (p, AGL_ACCUM_GREEN_SIZE);
  204217. pf->accumulationBufferBlueBits = getAGLAttribute (p, AGL_ACCUM_BLUE_SIZE);
  204218. pf->accumulationBufferAlphaBits = getAGLAttribute (p, AGL_ACCUM_ALPHA_SIZE);
  204219. results.add (pf);
  204220. p = aglNextPixelFormat (p);
  204221. }*/
  204222. //jassertfalse //xxx can't see how you do this in cocoa!
  204223. }
  204224. #else
  204225. OpenGLContext* OpenGLContext::createContextForWindow (Component* const component,
  204226. const OpenGLPixelFormat& pixelFormat,
  204227. const OpenGLContext* const contextToShareWith)
  204228. {
  204229. return 0;
  204230. }
  204231. void juce_glViewport (const int w, const int h)
  204232. {
  204233. //glViewport (0, 0, w, h);
  204234. }
  204235. #endif
  204236. #endif
  204237. /*** End of inlined file: juce_mac_OpenGLComponent.mm ***/
  204238. /*** Start of inlined file: juce_mac_MouseCursor.mm ***/
  204239. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  204240. // compiled on its own).
  204241. #if JUCE_INCLUDED_FILE
  204242. #if JUCE_MAC
  204243. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw()
  204244. {
  204245. NSImage* im = CoreGraphicsImage::createNSImage (image);
  204246. NSCursor* c = [[NSCursor alloc] initWithImage: im
  204247. hotSpot: NSMakePoint (hotspotX, hotspotY)];
  204248. [im release];
  204249. return (void*) c;
  204250. }
  204251. static void* juce_cursorFromData (const unsigned char* data, const size_t size, float hx, float hy) throw()
  204252. {
  204253. ScopedPointer <Image> im (ImageFileFormat::loadFrom ((const char*) data, (int) size));
  204254. jassert (im != 0);
  204255. if (im == 0)
  204256. return 0;
  204257. return juce_createMouseCursorFromImage (*im,
  204258. (int) (hx * im->getWidth()),
  204259. (int) (hy * im->getHeight()));
  204260. }
  204261. static void* juce_cursorFromWebKitFile (const char* filename, float hx, float hy)
  204262. {
  204263. File f ("/System/Library/Frameworks/WebKit.framework/Frameworks/WebCore.framework/Resources");
  204264. MemoryBlock mb;
  204265. if (f.getChildFile (filename).loadFileAsData (mb))
  204266. return juce_cursorFromData ((const unsigned char*) mb.getData(), mb.getSize(), hx, hy);
  204267. return 0;
  204268. }
  204269. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw()
  204270. {
  204271. const ScopedAutoReleasePool pool;
  204272. NSCursor* c = 0;
  204273. switch (type)
  204274. {
  204275. case MouseCursor::NormalCursor:
  204276. c = [NSCursor arrowCursor];
  204277. break;
  204278. case MouseCursor::NoCursor:
  204279. {
  204280. Image blank (Image::ARGB, 8, 8, true);
  204281. return juce_createMouseCursorFromImage (blank, 0, 0);
  204282. }
  204283. case MouseCursor::DraggingHandCursor:
  204284. c = [NSCursor openHandCursor];
  204285. break;
  204286. case MouseCursor::CopyingCursor:
  204287. return juce_cursorFromWebKitFile ("copyCursor.png", 0, 0);
  204288. case MouseCursor::WaitCursor:
  204289. c = [NSCursor arrowCursor]; // avoid this on the mac, let the OS provide the beachball
  204290. break;
  204291. //return juce_cursorFromWebKitFile ("waitCursor.png", 0.5f, 0.5f);
  204292. case MouseCursor::IBeamCursor:
  204293. c = [NSCursor IBeamCursor];
  204294. break;
  204295. case MouseCursor::PointingHandCursor:
  204296. c = [NSCursor pointingHandCursor];
  204297. break;
  204298. case MouseCursor::LeftRightResizeCursor:
  204299. c = [NSCursor resizeLeftRightCursor];
  204300. break;
  204301. case MouseCursor::LeftEdgeResizeCursor:
  204302. c = [NSCursor resizeLeftCursor];
  204303. break;
  204304. case MouseCursor::RightEdgeResizeCursor:
  204305. c = [NSCursor resizeRightCursor];
  204306. break;
  204307. case MouseCursor::UpDownResizeCursor:
  204308. case MouseCursor::TopEdgeResizeCursor:
  204309. case MouseCursor::BottomEdgeResizeCursor:
  204310. return juce_cursorFromWebKitFile ("northSouthResizeCursor.png", 0.5f, 0.5f);
  204311. case MouseCursor::TopLeftCornerResizeCursor:
  204312. case MouseCursor::BottomRightCornerResizeCursor:
  204313. return juce_cursorFromWebKitFile ("northWestSouthEastResizeCursor.png", 0.5f, 0.5f);
  204314. case MouseCursor::TopRightCornerResizeCursor:
  204315. case MouseCursor::BottomLeftCornerResizeCursor:
  204316. return juce_cursorFromWebKitFile ("northEastSouthWestResizeCursor.png", 0.5f, 0.5f);
  204317. case MouseCursor::UpDownLeftRightResizeCursor:
  204318. return juce_cursorFromWebKitFile ("moveCursor.png", 0.5f, 0.5f);
  204319. case MouseCursor::CrosshairCursor:
  204320. c = [NSCursor crosshairCursor];
  204321. break;
  204322. }
  204323. [c retain];
  204324. return (void*) c;
  204325. }
  204326. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw()
  204327. {
  204328. NSCursor* c = (NSCursor*) cursorHandle;
  204329. [c release];
  204330. }
  204331. void MouseCursor::showInAllWindows() const throw()
  204332. {
  204333. showInWindow (0);
  204334. }
  204335. void MouseCursor::showInWindow (ComponentPeer*) const throw()
  204336. {
  204337. NSCursor* const c = (NSCursor*) getHandle();
  204338. [c set];
  204339. }
  204340. #else
  204341. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw() { return 0; }
  204342. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw() { return 0; }
  204343. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw() {}
  204344. void MouseCursor::showInAllWindows() const throw() {}
  204345. void MouseCursor::showInWindow (ComponentPeer*) const throw() {}
  204346. #endif
  204347. #endif
  204348. /*** End of inlined file: juce_mac_MouseCursor.mm ***/
  204349. /*** Start of inlined file: juce_mac_WebBrowserComponent.mm ***/
  204350. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  204351. // compiled on its own).
  204352. #if JUCE_INCLUDED_FILE && JUCE_WEB_BROWSER
  204353. #if JUCE_MAC
  204354. END_JUCE_NAMESPACE
  204355. #define DownloadClickDetector MakeObjCClassName(DownloadClickDetector)
  204356. @interface DownloadClickDetector : NSObject
  204357. {
  204358. JUCE_NAMESPACE::WebBrowserComponent* ownerComponent;
  204359. }
  204360. - (DownloadClickDetector*) initWithWebBrowserOwner: (JUCE_NAMESPACE::WebBrowserComponent*) ownerComponent;
  204361. - (void) webView: (WebView*) webView decidePolicyForNavigationAction: (NSDictionary*) actionInformation
  204362. request: (NSURLRequest*) request
  204363. frame: (WebFrame*) frame
  204364. decisionListener: (id<WebPolicyDecisionListener>) listener;
  204365. @end
  204366. @implementation DownloadClickDetector
  204367. - (DownloadClickDetector*) initWithWebBrowserOwner: (JUCE_NAMESPACE::WebBrowserComponent*) ownerComponent_
  204368. {
  204369. [super init];
  204370. ownerComponent = ownerComponent_;
  204371. return self;
  204372. }
  204373. - (void) webView: (WebView*) sender decidePolicyForNavigationAction: (NSDictionary*) actionInformation
  204374. request: (NSURLRequest*) request
  204375. frame: (WebFrame*) frame
  204376. decisionListener: (id <WebPolicyDecisionListener>) listener
  204377. {
  204378. NSURL* url = [actionInformation valueForKey: @"WebActionOriginalURLKey"];
  204379. if (ownerComponent->pageAboutToLoad (nsStringToJuce ([url absoluteString])))
  204380. [listener use];
  204381. else
  204382. [listener ignore];
  204383. }
  204384. @end
  204385. BEGIN_JUCE_NAMESPACE
  204386. class WebBrowserComponentInternal : public NSViewComponent
  204387. {
  204388. public:
  204389. WebBrowserComponentInternal (WebBrowserComponent* owner)
  204390. {
  204391. webView = [[WebView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
  204392. frameName: @""
  204393. groupName: @""];
  204394. setView (webView);
  204395. clickListener = [[DownloadClickDetector alloc] initWithWebBrowserOwner: owner];
  204396. [webView setPolicyDelegate: clickListener];
  204397. }
  204398. ~WebBrowserComponentInternal()
  204399. {
  204400. [webView setPolicyDelegate: nil];
  204401. [clickListener release];
  204402. setView (0);
  204403. }
  204404. void goToURL (const String& url,
  204405. const StringArray* headers,
  204406. const MemoryBlock* postData)
  204407. {
  204408. NSMutableURLRequest* r
  204409. = [NSMutableURLRequest requestWithURL: [NSURL URLWithString: juceStringToNS (url)]
  204410. cachePolicy: NSURLRequestUseProtocolCachePolicy
  204411. timeoutInterval: 30.0];
  204412. if (postData != 0 && postData->getSize() > 0)
  204413. {
  204414. [r setHTTPMethod: @"POST"];
  204415. [r setHTTPBody: [NSData dataWithBytes: postData->getData()
  204416. length: postData->getSize()]];
  204417. }
  204418. if (headers != 0)
  204419. {
  204420. for (int i = 0; i < headers->size(); ++i)
  204421. {
  204422. const String headerName ((*headers)[i].upToFirstOccurrenceOf (T(":"), false, false).trim());
  204423. const String headerValue ((*headers)[i].fromFirstOccurrenceOf (T(":"), false, false).trim());
  204424. [r setValue: juceStringToNS (headerValue)
  204425. forHTTPHeaderField: juceStringToNS (headerName)];
  204426. }
  204427. }
  204428. stop();
  204429. [[webView mainFrame] loadRequest: r];
  204430. }
  204431. void goBack()
  204432. {
  204433. [webView goBack];
  204434. }
  204435. void goForward()
  204436. {
  204437. [webView goForward];
  204438. }
  204439. void stop()
  204440. {
  204441. [webView stopLoading: nil];
  204442. }
  204443. void refresh()
  204444. {
  204445. [webView reload: nil];
  204446. }
  204447. private:
  204448. WebView* webView;
  204449. DownloadClickDetector* clickListener;
  204450. };
  204451. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  204452. : browser (0),
  204453. blankPageShown (false),
  204454. unloadPageWhenBrowserIsHidden (unloadPageWhenBrowserIsHidden_)
  204455. {
  204456. setOpaque (true);
  204457. addAndMakeVisible (browser = new WebBrowserComponentInternal (this));
  204458. }
  204459. WebBrowserComponent::~WebBrowserComponent()
  204460. {
  204461. deleteAndZero (browser);
  204462. }
  204463. void WebBrowserComponent::goToURL (const String& url,
  204464. const StringArray* headers,
  204465. const MemoryBlock* postData)
  204466. {
  204467. lastURL = url;
  204468. lastHeaders.clear();
  204469. if (headers != 0)
  204470. lastHeaders = *headers;
  204471. lastPostData.setSize (0);
  204472. if (postData != 0)
  204473. lastPostData = *postData;
  204474. blankPageShown = false;
  204475. browser->goToURL (url, headers, postData);
  204476. }
  204477. void WebBrowserComponent::stop()
  204478. {
  204479. browser->stop();
  204480. }
  204481. void WebBrowserComponent::goBack()
  204482. {
  204483. lastURL = String::empty;
  204484. blankPageShown = false;
  204485. browser->goBack();
  204486. }
  204487. void WebBrowserComponent::goForward()
  204488. {
  204489. lastURL = String::empty;
  204490. browser->goForward();
  204491. }
  204492. void WebBrowserComponent::refresh()
  204493. {
  204494. browser->refresh();
  204495. }
  204496. void WebBrowserComponent::paint (Graphics& g)
  204497. {
  204498. }
  204499. void WebBrowserComponent::checkWindowAssociation()
  204500. {
  204501. if (isShowing())
  204502. {
  204503. if (blankPageShown)
  204504. goBack();
  204505. }
  204506. else
  204507. {
  204508. if (unloadPageWhenBrowserIsHidden && ! blankPageShown)
  204509. {
  204510. // when the component becomes invisible, some stuff like flash
  204511. // carries on playing audio, so we need to force it onto a blank
  204512. // page to avoid this, (and send it back when it's made visible again).
  204513. blankPageShown = true;
  204514. browser->goToURL ("about:blank", 0, 0);
  204515. }
  204516. }
  204517. }
  204518. void WebBrowserComponent::reloadLastURL()
  204519. {
  204520. if (lastURL.isNotEmpty())
  204521. {
  204522. goToURL (lastURL, &lastHeaders, &lastPostData);
  204523. lastURL = String::empty;
  204524. }
  204525. }
  204526. void WebBrowserComponent::parentHierarchyChanged()
  204527. {
  204528. checkWindowAssociation();
  204529. }
  204530. void WebBrowserComponent::resized()
  204531. {
  204532. browser->setSize (getWidth(), getHeight());
  204533. }
  204534. void WebBrowserComponent::visibilityChanged()
  204535. {
  204536. checkWindowAssociation();
  204537. }
  204538. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  204539. {
  204540. return true;
  204541. }
  204542. #else
  204543. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  204544. {
  204545. }
  204546. WebBrowserComponent::~WebBrowserComponent()
  204547. {
  204548. }
  204549. void WebBrowserComponent::goToURL (const String& url,
  204550. const StringArray* headers,
  204551. const MemoryBlock* postData)
  204552. {
  204553. }
  204554. void WebBrowserComponent::stop()
  204555. {
  204556. }
  204557. void WebBrowserComponent::goBack()
  204558. {
  204559. }
  204560. void WebBrowserComponent::goForward()
  204561. {
  204562. }
  204563. void WebBrowserComponent::refresh()
  204564. {
  204565. }
  204566. void WebBrowserComponent::paint (Graphics& g)
  204567. {
  204568. }
  204569. void WebBrowserComponent::checkWindowAssociation()
  204570. {
  204571. }
  204572. void WebBrowserComponent::reloadLastURL()
  204573. {
  204574. }
  204575. void WebBrowserComponent::parentHierarchyChanged()
  204576. {
  204577. }
  204578. void WebBrowserComponent::resized()
  204579. {
  204580. }
  204581. void WebBrowserComponent::visibilityChanged()
  204582. {
  204583. }
  204584. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  204585. {
  204586. return true;
  204587. }
  204588. #endif
  204589. #endif
  204590. /*** End of inlined file: juce_mac_WebBrowserComponent.mm ***/
  204591. /*** Start of inlined file: juce_iphone_Audio.cpp ***/
  204592. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  204593. // compiled on its own).
  204594. #if JUCE_INCLUDED_FILE
  204595. class IPhoneAudioIODevice : public AudioIODevice
  204596. {
  204597. public:
  204598. IPhoneAudioIODevice (const String& deviceName)
  204599. : AudioIODevice (deviceName, T("Audio")),
  204600. audioUnit (0),
  204601. isRunning (false),
  204602. callback (0),
  204603. actualBufferSize (0),
  204604. floatData (1, 2)
  204605. {
  204606. numInputChannels = 2;
  204607. numOutputChannels = 2;
  204608. preferredBufferSize = 0;
  204609. AudioSessionInitialize (0, 0, interruptionListenerStatic, this);
  204610. updateDeviceInfo();
  204611. }
  204612. ~IPhoneAudioIODevice()
  204613. {
  204614. close();
  204615. }
  204616. const StringArray getOutputChannelNames()
  204617. {
  204618. StringArray s;
  204619. s.add ("Left");
  204620. s.add ("Right");
  204621. return s;
  204622. }
  204623. const StringArray getInputChannelNames()
  204624. {
  204625. StringArray s;
  204626. if (audioInputIsAvailable)
  204627. {
  204628. s.add ("Left");
  204629. s.add ("Right");
  204630. }
  204631. return s;
  204632. }
  204633. int getNumSampleRates()
  204634. {
  204635. return 1;
  204636. }
  204637. double getSampleRate (int index)
  204638. {
  204639. return sampleRate;
  204640. }
  204641. int getNumBufferSizesAvailable()
  204642. {
  204643. return 1;
  204644. }
  204645. int getBufferSizeSamples (int index)
  204646. {
  204647. return getDefaultBufferSize();
  204648. }
  204649. int getDefaultBufferSize()
  204650. {
  204651. return 1024;
  204652. }
  204653. const String open (const BitArray& inputChannels,
  204654. const BitArray& outputChannels,
  204655. double sampleRate,
  204656. int bufferSize)
  204657. {
  204658. close();
  204659. lastError = String::empty;
  204660. preferredBufferSize = (bufferSize <= 0) ? getDefaultBufferSize() : bufferSize;
  204661. // xxx set up channel mapping
  204662. activeOutputChans = outputChannels;
  204663. activeOutputChans.setRange (2, activeOutputChans.getHighestBit(), false);
  204664. numOutputChannels = activeOutputChans.countNumberOfSetBits();
  204665. monoOutputChannelNumber = activeOutputChans.findNextSetBit (0);
  204666. activeInputChans = inputChannels;
  204667. activeInputChans.setRange (2, activeInputChans.getHighestBit(), false);
  204668. numInputChannels = activeInputChans.countNumberOfSetBits();
  204669. monoInputChannelNumber = activeInputChans.findNextSetBit (0);
  204670. AudioSessionSetActive (true);
  204671. UInt32 audioCategory = kAudioSessionCategory_PlayAndRecord;
  204672. AudioSessionSetProperty (kAudioSessionProperty_AudioCategory, sizeof (audioCategory), &audioCategory);
  204673. AudioSessionAddPropertyListener (kAudioSessionProperty_AudioRouteChange, propertyChangedStatic, this);
  204674. fixAudioRouteIfSetToReceiver();
  204675. updateDeviceInfo();
  204676. Float32 bufferDuration = preferredBufferSize / sampleRate;
  204677. AudioSessionSetProperty (kAudioSessionProperty_PreferredHardwareIOBufferDuration, sizeof (bufferDuration), &bufferDuration);
  204678. actualBufferSize = preferredBufferSize;
  204679. prepareFloatBuffers();
  204680. isRunning = true;
  204681. propertyChanged (0, 0, 0); // creates and starts the AU
  204682. lastError = audioUnit != 0 ? String::empty
  204683. : T("Couldn't open the device");
  204684. return lastError;
  204685. }
  204686. void close()
  204687. {
  204688. if (isRunning)
  204689. {
  204690. isRunning = false;
  204691. AudioSessionSetActive (false);
  204692. if (audioUnit != 0)
  204693. {
  204694. AudioComponentInstanceDispose (audioUnit);
  204695. audioUnit = 0;
  204696. }
  204697. }
  204698. }
  204699. bool isOpen()
  204700. {
  204701. return isRunning;
  204702. }
  204703. int getCurrentBufferSizeSamples()
  204704. {
  204705. return actualBufferSize;
  204706. }
  204707. double getCurrentSampleRate()
  204708. {
  204709. return sampleRate;
  204710. }
  204711. int getCurrentBitDepth()
  204712. {
  204713. return 16;
  204714. }
  204715. const BitArray getActiveOutputChannels() const
  204716. {
  204717. return activeOutputChans;
  204718. }
  204719. const BitArray getActiveInputChannels() const
  204720. {
  204721. return activeInputChans;
  204722. }
  204723. int getOutputLatencyInSamples()
  204724. {
  204725. return 0; //xxx
  204726. }
  204727. int getInputLatencyInSamples()
  204728. {
  204729. return 0; //xxx
  204730. }
  204731. void start (AudioIODeviceCallback* callback_)
  204732. {
  204733. if (isRunning && callback != callback_)
  204734. {
  204735. if (callback_ != 0)
  204736. callback_->audioDeviceAboutToStart (this);
  204737. callbackLock.enter();
  204738. callback = callback_;
  204739. callbackLock.exit();
  204740. }
  204741. }
  204742. void stop()
  204743. {
  204744. if (isRunning)
  204745. {
  204746. callbackLock.enter();
  204747. AudioIODeviceCallback* const lastCallback = callback;
  204748. callback = 0;
  204749. callbackLock.exit();
  204750. if (lastCallback != 0)
  204751. lastCallback->audioDeviceStopped();
  204752. }
  204753. }
  204754. bool isPlaying()
  204755. {
  204756. return isRunning && callback != 0;
  204757. }
  204758. const String getLastError()
  204759. {
  204760. return lastError;
  204761. }
  204762. private:
  204763. CriticalSection callbackLock;
  204764. Float64 sampleRate;
  204765. int numInputChannels, numOutputChannels;
  204766. int preferredBufferSize;
  204767. int actualBufferSize;
  204768. bool isRunning;
  204769. String lastError;
  204770. AudioStreamBasicDescription format;
  204771. AudioUnit audioUnit;
  204772. UInt32 audioInputIsAvailable;
  204773. AudioIODeviceCallback* callback;
  204774. BitArray activeOutputChans, activeInputChans;
  204775. AudioSampleBuffer floatData;
  204776. float* inputChannels[3];
  204777. float* outputChannels[3];
  204778. bool monoInputChannelNumber, monoOutputChannelNumber;
  204779. void prepareFloatBuffers()
  204780. {
  204781. floatData.setSize (numInputChannels + numOutputChannels, actualBufferSize);
  204782. zerostruct (inputChannels);
  204783. zerostruct (outputChannels);
  204784. for (int i = 0; i < numInputChannels; ++i)
  204785. inputChannels[i] = floatData.getSampleData (i);
  204786. for (int i = 0; i < numOutputChannels; ++i)
  204787. outputChannels[i] = floatData.getSampleData (i + numInputChannels);
  204788. }
  204789. OSStatus process (AudioUnitRenderActionFlags* ioActionFlags, const AudioTimeStamp* inTimeStamp,
  204790. UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList* ioData)
  204791. {
  204792. OSStatus err = noErr;
  204793. if (audioInputIsAvailable)
  204794. err = AudioUnitRender (audioUnit, ioActionFlags, inTimeStamp, 1, inNumberFrames, ioData);
  204795. const ScopedLock sl (callbackLock);
  204796. if (callback != 0)
  204797. {
  204798. if (audioInputIsAvailable && numInputChannels > 0)
  204799. {
  204800. short* shortData = (short*) ioData->mBuffers[0].mData;
  204801. if (numInputChannels >= 2)
  204802. {
  204803. for (UInt32 i = 0; i < inNumberFrames; ++i)
  204804. {
  204805. inputChannels[0][i] = *shortData++ * (1.0f / 32768.0f);
  204806. inputChannels[1][i] = *shortData++ * (1.0f / 32768.0f);
  204807. }
  204808. }
  204809. else
  204810. {
  204811. if (monoInputChannelNumber > 0)
  204812. ++shortData;
  204813. for (UInt32 i = 0; i < inNumberFrames; ++i)
  204814. {
  204815. inputChannels[0][i] = *shortData++ * (1.0f / 32768.0f);
  204816. ++shortData;
  204817. }
  204818. }
  204819. }
  204820. else
  204821. {
  204822. for (int i = numInputChannels; --i >= 0;)
  204823. zeromem (inputChannels[i], sizeof (float) * inNumberFrames);
  204824. }
  204825. callback->audioDeviceIOCallback ((const float**) inputChannels, numInputChannels,
  204826. outputChannels, numOutputChannels,
  204827. (int) inNumberFrames);
  204828. short* shortData = (short*) ioData->mBuffers[0].mData;
  204829. int n = 0;
  204830. if (numOutputChannels >= 2)
  204831. {
  204832. for (UInt32 i = 0; i < inNumberFrames; ++i)
  204833. {
  204834. shortData [n++] = (short) (outputChannels[0][i] * 32767.0f);
  204835. shortData [n++] = (short) (outputChannels[1][i] * 32767.0f);
  204836. }
  204837. }
  204838. else if (numOutputChannels == 1)
  204839. {
  204840. for (UInt32 i = 0; i < inNumberFrames; ++i)
  204841. {
  204842. const short s = (short) (outputChannels[monoOutputChannelNumber][i] * 32767.0f);
  204843. shortData [n++] = s;
  204844. shortData [n++] = s;
  204845. }
  204846. }
  204847. else
  204848. {
  204849. zeromem (ioData->mBuffers[0].mData, 2 * sizeof (short) * inNumberFrames);
  204850. }
  204851. }
  204852. else
  204853. {
  204854. zeromem (ioData->mBuffers[0].mData, 2 * sizeof (short) * inNumberFrames);
  204855. }
  204856. return err;
  204857. }
  204858. void updateDeviceInfo()
  204859. {
  204860. UInt32 size = sizeof (sampleRate);
  204861. AudioSessionGetProperty (kAudioSessionProperty_CurrentHardwareSampleRate, &size, &sampleRate);
  204862. size = sizeof (audioInputIsAvailable);
  204863. AudioSessionGetProperty (kAudioSessionProperty_AudioInputAvailable, &size, &audioInputIsAvailable);
  204864. }
  204865. void propertyChanged (AudioSessionPropertyID inID, UInt32 inDataSize, const void* inPropertyValue)
  204866. {
  204867. if (! isRunning)
  204868. return;
  204869. if (inPropertyValue != 0)
  204870. {
  204871. CFDictionaryRef routeChangeDictionary = (CFDictionaryRef) inPropertyValue;
  204872. CFNumberRef routeChangeReasonRef = (CFNumberRef) CFDictionaryGetValue (routeChangeDictionary,
  204873. CFSTR (kAudioSession_AudioRouteChangeKey_Reason));
  204874. SInt32 routeChangeReason;
  204875. CFNumberGetValue (routeChangeReasonRef, kCFNumberSInt32Type, &routeChangeReason);
  204876. if (routeChangeReason == kAudioSessionRouteChangeReason_OldDeviceUnavailable)
  204877. fixAudioRouteIfSetToReceiver();
  204878. }
  204879. updateDeviceInfo();
  204880. createAudioUnit();
  204881. AudioSessionSetActive (true);
  204882. if (audioUnit != 0)
  204883. {
  204884. UInt32 formatSize = sizeof (format);
  204885. AudioUnitGetProperty (audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 1, &format, &formatSize);
  204886. Float32 bufferDuration = preferredBufferSize / sampleRate;
  204887. UInt32 bufferDurationSize = sizeof (bufferDuration);
  204888. AudioSessionGetProperty (kAudioSessionProperty_CurrentHardwareIOBufferDuration, &bufferDurationSize, &bufferDurationSize);
  204889. actualBufferSize = (int) (sampleRate * bufferDuration + 0.5);
  204890. AudioOutputUnitStart (audioUnit);
  204891. }
  204892. }
  204893. void interruptionListener (UInt32 inInterruption)
  204894. {
  204895. if (inInterruption == kAudioSessionEndInterruption)
  204896. {
  204897. isRunning = true;
  204898. AudioSessionSetActive (true);
  204899. AudioOutputUnitStart (audioUnit);
  204900. }
  204901. }
  204902. static OSStatus processStatic (void* inRefCon, AudioUnitRenderActionFlags* ioActionFlags, const AudioTimeStamp* inTimeStamp,
  204903. UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList* ioData)
  204904. {
  204905. return ((IPhoneAudioIODevice*) inRefCon)->process (ioActionFlags, inTimeStamp, inBusNumber, inNumberFrames, ioData);
  204906. }
  204907. static void propertyChangedStatic (void* inClientData, AudioSessionPropertyID inID, UInt32 inDataSize, const void* inPropertyValue)
  204908. {
  204909. ((IPhoneAudioIODevice*) inClientData)->propertyChanged (inID, inDataSize, inPropertyValue);
  204910. }
  204911. static void interruptionListenerStatic (void* inClientData, UInt32 inInterruption)
  204912. {
  204913. ((IPhoneAudioIODevice*) inClientData)->interruptionListener (inInterruption);
  204914. }
  204915. void resetFormat (const int numChannels)
  204916. {
  204917. memset (&format, 0, sizeof (format));
  204918. format.mFormatID = kAudioFormatLinearPCM;
  204919. format.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger | kLinearPCMFormatFlagIsPacked;
  204920. format.mBitsPerChannel = 8 * sizeof (short);
  204921. format.mChannelsPerFrame = 2;
  204922. format.mFramesPerPacket = 1;
  204923. format.mBytesPerFrame = format.mBytesPerPacket = 2 * sizeof (short);
  204924. }
  204925. bool createAudioUnit()
  204926. {
  204927. if (audioUnit != 0)
  204928. {
  204929. AudioComponentInstanceDispose (audioUnit);
  204930. audioUnit = 0;
  204931. }
  204932. resetFormat (2);
  204933. AudioComponentDescription desc;
  204934. desc.componentType = kAudioUnitType_Output;
  204935. desc.componentSubType = kAudioUnitSubType_RemoteIO;
  204936. desc.componentManufacturer = kAudioUnitManufacturer_Apple;
  204937. desc.componentFlags = 0;
  204938. desc.componentFlagsMask = 0;
  204939. AudioComponent comp = AudioComponentFindNext (0, &desc);
  204940. AudioComponentInstanceNew (comp, &audioUnit);
  204941. if (audioUnit == 0)
  204942. return false;
  204943. const UInt32 one = 1;
  204944. AudioUnitSetProperty (audioUnit, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Input, 1, &one, sizeof (one));
  204945. AudioChannelLayout layout;
  204946. layout.mChannelBitmap = 0;
  204947. layout.mNumberChannelDescriptions = 0;
  204948. layout.mChannelLayoutTag = kAudioChannelLayoutTag_Stereo;
  204949. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_AudioChannelLayout, kAudioUnitScope_Input, 0, &layout, sizeof (layout));
  204950. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_AudioChannelLayout, kAudioUnitScope_Output, 0, &layout, sizeof (layout));
  204951. AURenderCallbackStruct inputProc;
  204952. inputProc.inputProc = processStatic;
  204953. inputProc.inputProcRefCon = this;
  204954. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input, 0, &inputProc, sizeof (inputProc));
  204955. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &format, sizeof (format));
  204956. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 1, &format, sizeof (format));
  204957. AudioUnitInitialize (audioUnit);
  204958. return true;
  204959. }
  204960. // If the routing is set to go through the receiver (i.e. the speaker, but quiet), this re-routes it
  204961. // to make it loud. Needed because by default when using an input + output, the output is kept quiet.
  204962. static void fixAudioRouteIfSetToReceiver()
  204963. {
  204964. CFStringRef audioRoute = 0;
  204965. UInt32 propertySize = sizeof (audioRoute);
  204966. if (AudioSessionGetProperty (kAudioSessionProperty_AudioRoute, &propertySize, &audioRoute) == noErr)
  204967. {
  204968. NSString* route = (NSString*) audioRoute;
  204969. //DBG ("audio route: " + nsStringToJuce (route));
  204970. if ([route hasPrefix: @"Receiver"])
  204971. {
  204972. UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
  204973. AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute, sizeof (audioRouteOverride), &audioRouteOverride);
  204974. }
  204975. CFRelease (audioRoute);
  204976. }
  204977. }
  204978. IPhoneAudioIODevice (const IPhoneAudioIODevice&);
  204979. const IPhoneAudioIODevice& operator= (const IPhoneAudioIODevice&);
  204980. };
  204981. class IPhoneAudioIODeviceType : public AudioIODeviceType
  204982. {
  204983. public:
  204984. IPhoneAudioIODeviceType()
  204985. : AudioIODeviceType (T("iPhone Audio"))
  204986. {
  204987. }
  204988. ~IPhoneAudioIODeviceType()
  204989. {
  204990. }
  204991. void scanForDevices()
  204992. {
  204993. }
  204994. const StringArray getDeviceNames (const bool wantInputNames) const
  204995. {
  204996. StringArray s;
  204997. s.add ("iPhone Audio");
  204998. return s;
  204999. }
  205000. int getDefaultDeviceIndex (const bool forInput) const
  205001. {
  205002. return 0;
  205003. }
  205004. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  205005. {
  205006. return device != 0 ? 0 : -1;
  205007. }
  205008. bool hasSeparateInputsAndOutputs() const { return false; }
  205009. AudioIODevice* createDevice (const String& outputDeviceName,
  205010. const String& inputDeviceName)
  205011. {
  205012. if (outputDeviceName.isNotEmpty() || inputDeviceName.isNotEmpty())
  205013. {
  205014. return new IPhoneAudioIODevice (outputDeviceName.isNotEmpty() ? outputDeviceName
  205015. : inputDeviceName);
  205016. }
  205017. return 0;
  205018. }
  205019. juce_UseDebuggingNewOperator
  205020. private:
  205021. IPhoneAudioIODeviceType (const IPhoneAudioIODeviceType&);
  205022. const IPhoneAudioIODeviceType& operator= (const IPhoneAudioIODeviceType&);
  205023. };
  205024. AudioIODeviceType* juce_createAudioIODeviceType_iPhoneAudio()
  205025. {
  205026. return new IPhoneAudioIODeviceType();
  205027. }
  205028. #endif
  205029. /*** End of inlined file: juce_iphone_Audio.cpp ***/
  205030. /*** Start of inlined file: juce_mac_CoreMidi.cpp ***/
  205031. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  205032. // compiled on its own).
  205033. #if JUCE_INCLUDED_FILE
  205034. #if JUCE_MAC
  205035. #undef log
  205036. #define log(a) Logger::writeToLog(a)
  205037. static bool logAnyErrorsMidi (const OSStatus err, const int lineNum)
  205038. {
  205039. if (err == noErr)
  205040. return true;
  205041. log (T("CoreMidi error: ") + String (lineNum) + T(" - ") + String::toHexString ((int)err));
  205042. jassertfalse
  205043. return false;
  205044. }
  205045. #undef OK
  205046. #define OK(a) logAnyErrorsMidi(a, __LINE__)
  205047. static const String getEndpointName (MIDIEndpointRef endpoint, bool isExternal)
  205048. {
  205049. String result;
  205050. CFStringRef str = 0;
  205051. MIDIObjectGetStringProperty (endpoint, kMIDIPropertyName, &str);
  205052. if (str != 0)
  205053. {
  205054. result = PlatformUtilities::cfStringToJuceString (str);
  205055. CFRelease (str);
  205056. str = 0;
  205057. }
  205058. MIDIEntityRef entity = 0;
  205059. MIDIEndpointGetEntity (endpoint, &entity);
  205060. if (entity == 0)
  205061. return result; // probably virtual
  205062. if (result.isEmpty())
  205063. {
  205064. // endpoint name has zero length - try the entity
  205065. MIDIObjectGetStringProperty (entity, kMIDIPropertyName, &str);
  205066. if (str != 0)
  205067. {
  205068. result += PlatformUtilities::cfStringToJuceString (str);
  205069. CFRelease (str);
  205070. str = 0;
  205071. }
  205072. }
  205073. // now consider the device's name
  205074. MIDIDeviceRef device = 0;
  205075. MIDIEntityGetDevice (entity, &device);
  205076. if (device == 0)
  205077. return result;
  205078. MIDIObjectGetStringProperty (device, kMIDIPropertyName, &str);
  205079. if (str != 0)
  205080. {
  205081. const String s (PlatformUtilities::cfStringToJuceString (str));
  205082. CFRelease (str);
  205083. // if an external device has only one entity, throw away
  205084. // the endpoint name and just use the device name
  205085. if (isExternal && MIDIDeviceGetNumberOfEntities (device) < 2)
  205086. {
  205087. result = s;
  205088. }
  205089. else if (! result.startsWithIgnoreCase (s))
  205090. {
  205091. // prepend the device name to the entity name
  205092. result = (s + T(" ") + result).trimEnd();
  205093. }
  205094. }
  205095. return result;
  205096. }
  205097. static const String getConnectedEndpointName (MIDIEndpointRef endpoint)
  205098. {
  205099. String result;
  205100. // Does the endpoint have connections?
  205101. CFDataRef connections = 0;
  205102. int numConnections = 0;
  205103. MIDIObjectGetDataProperty (endpoint, kMIDIPropertyConnectionUniqueID, &connections);
  205104. if (connections != 0)
  205105. {
  205106. numConnections = (int) (CFDataGetLength (connections) / sizeof (MIDIUniqueID));
  205107. if (numConnections > 0)
  205108. {
  205109. const SInt32* pid = reinterpret_cast <const SInt32*> (CFDataGetBytePtr (connections));
  205110. for (int i = 0; i < numConnections; ++i, ++pid)
  205111. {
  205112. MIDIUniqueID uid = EndianS32_BtoN (*pid);
  205113. MIDIObjectRef connObject;
  205114. MIDIObjectType connObjectType;
  205115. OSStatus err = MIDIObjectFindByUniqueID (uid, &connObject, &connObjectType);
  205116. if (err == noErr)
  205117. {
  205118. String s;
  205119. if (connObjectType == kMIDIObjectType_ExternalSource
  205120. || connObjectType == kMIDIObjectType_ExternalDestination)
  205121. {
  205122. // Connected to an external device's endpoint (10.3 and later).
  205123. s = getEndpointName (static_cast <MIDIEndpointRef> (connObject), true);
  205124. }
  205125. else
  205126. {
  205127. // Connected to an external device (10.2) (or something else, catch-all)
  205128. CFStringRef str = 0;
  205129. MIDIObjectGetStringProperty (connObject, kMIDIPropertyName, &str);
  205130. if (str != 0)
  205131. {
  205132. s = PlatformUtilities::cfStringToJuceString (str);
  205133. CFRelease (str);
  205134. }
  205135. }
  205136. if (s.isNotEmpty())
  205137. {
  205138. if (result.isNotEmpty())
  205139. result += (", ");
  205140. result += s;
  205141. }
  205142. }
  205143. }
  205144. }
  205145. CFRelease (connections);
  205146. }
  205147. if (result.isNotEmpty())
  205148. return result;
  205149. // Here, either the endpoint had no connections, or we failed to obtain names for any of them.
  205150. return getEndpointName (endpoint, false);
  205151. }
  205152. const StringArray MidiOutput::getDevices()
  205153. {
  205154. StringArray s;
  205155. const ItemCount num = MIDIGetNumberOfDestinations();
  205156. for (ItemCount i = 0; i < num; ++i)
  205157. {
  205158. MIDIEndpointRef dest = MIDIGetDestination (i);
  205159. if (dest != 0)
  205160. {
  205161. String name (getConnectedEndpointName (dest));
  205162. if (name.isEmpty())
  205163. name = "<error>";
  205164. s.add (name);
  205165. }
  205166. else
  205167. {
  205168. s.add ("<error>");
  205169. }
  205170. }
  205171. return s;
  205172. }
  205173. int MidiOutput::getDefaultDeviceIndex()
  205174. {
  205175. return 0;
  205176. }
  205177. static MIDIClientRef globalMidiClient;
  205178. static bool hasGlobalClientBeenCreated = false;
  205179. static bool makeSureClientExists()
  205180. {
  205181. if (! hasGlobalClientBeenCreated)
  205182. {
  205183. String name (T("JUCE"));
  205184. if (JUCEApplication::getInstance() != 0)
  205185. name = JUCEApplication::getInstance()->getApplicationName();
  205186. CFStringRef appName = PlatformUtilities::juceStringToCFString (name);
  205187. hasGlobalClientBeenCreated = OK (MIDIClientCreate (appName, 0, 0, &globalMidiClient));
  205188. CFRelease (appName);
  205189. }
  205190. return hasGlobalClientBeenCreated;
  205191. }
  205192. class MidiPortAndEndpoint
  205193. {
  205194. public:
  205195. MidiPortAndEndpoint (MIDIPortRef port_, MIDIEndpointRef endPoint_)
  205196. : port (port_), endPoint (endPoint_)
  205197. {
  205198. }
  205199. ~MidiPortAndEndpoint()
  205200. {
  205201. if (port != 0)
  205202. MIDIPortDispose (port);
  205203. if (port == 0 && endPoint != 0) // if port == 0, it means we created the endpoint, so it's safe to delete it
  205204. MIDIEndpointDispose (endPoint);
  205205. }
  205206. MIDIPortRef port;
  205207. MIDIEndpointRef endPoint;
  205208. };
  205209. MidiOutput* MidiOutput::openDevice (int index)
  205210. {
  205211. MidiOutput* mo = 0;
  205212. if (((unsigned int) index) < (unsigned int) MIDIGetNumberOfDestinations())
  205213. {
  205214. MIDIEndpointRef endPoint = MIDIGetDestination (index);
  205215. CFStringRef pname;
  205216. if (OK (MIDIObjectGetStringProperty (endPoint, kMIDIPropertyName, &pname)))
  205217. {
  205218. log (T("CoreMidi - opening out: ") + PlatformUtilities::cfStringToJuceString (pname));
  205219. if (makeSureClientExists())
  205220. {
  205221. MIDIPortRef port;
  205222. if (OK (MIDIOutputPortCreate (globalMidiClient, pname, &port)))
  205223. {
  205224. mo = new MidiOutput();
  205225. mo->internal = (void*) new MidiPortAndEndpoint (port, endPoint);
  205226. }
  205227. }
  205228. CFRelease (pname);
  205229. }
  205230. }
  205231. return mo;
  205232. }
  205233. MidiOutput* MidiOutput::createNewDevice (const String& deviceName)
  205234. {
  205235. MidiOutput* mo = 0;
  205236. if (makeSureClientExists())
  205237. {
  205238. MIDIEndpointRef endPoint;
  205239. CFStringRef name = PlatformUtilities::juceStringToCFString (deviceName);
  205240. if (OK (MIDISourceCreate (globalMidiClient, name, &endPoint)))
  205241. {
  205242. mo = new MidiOutput();
  205243. mo->internal = (void*) new MidiPortAndEndpoint (0, endPoint);
  205244. }
  205245. CFRelease (name);
  205246. }
  205247. return mo;
  205248. }
  205249. MidiOutput::~MidiOutput()
  205250. {
  205251. delete (MidiPortAndEndpoint*) internal;
  205252. }
  205253. void MidiOutput::reset()
  205254. {
  205255. }
  205256. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  205257. {
  205258. return false;
  205259. }
  205260. void MidiOutput::setVolume (float leftVol, float rightVol)
  205261. {
  205262. }
  205263. void MidiOutput::sendMessageNow (const MidiMessage& message)
  205264. {
  205265. MidiPortAndEndpoint* const mpe = (MidiPortAndEndpoint*) internal;
  205266. if (message.isSysEx())
  205267. {
  205268. const int maxPacketSize = 256;
  205269. int pos = 0, bytesLeft = message.getRawDataSize();
  205270. const int numPackets = (bytesLeft + maxPacketSize - 1) / maxPacketSize;
  205271. HeapBlock <MIDIPacketList> packets;
  205272. packets.malloc (32 * numPackets + message.getRawDataSize(), 1);
  205273. packets->numPackets = numPackets;
  205274. MIDIPacket* p = packets->packet;
  205275. for (int i = 0; i < numPackets; ++i)
  205276. {
  205277. p->timeStamp = 0;
  205278. p->length = jmin (maxPacketSize, bytesLeft);
  205279. memcpy (p->data, message.getRawData() + pos, p->length);
  205280. pos += p->length;
  205281. bytesLeft -= p->length;
  205282. p = MIDIPacketNext (p);
  205283. }
  205284. if (mpe->port != 0)
  205285. MIDISend (mpe->port, mpe->endPoint, packets);
  205286. else
  205287. MIDIReceived (mpe->endPoint, packets);
  205288. }
  205289. else
  205290. {
  205291. MIDIPacketList packets;
  205292. packets.numPackets = 1;
  205293. packets.packet[0].timeStamp = 0;
  205294. packets.packet[0].length = message.getRawDataSize();
  205295. *(int*) (packets.packet[0].data) = *(const int*) message.getRawData();
  205296. if (mpe->port != 0)
  205297. MIDISend (mpe->port, mpe->endPoint, &packets);
  205298. else
  205299. MIDIReceived (mpe->endPoint, &packets);
  205300. }
  205301. }
  205302. const StringArray MidiInput::getDevices()
  205303. {
  205304. StringArray s;
  205305. const ItemCount num = MIDIGetNumberOfSources();
  205306. for (ItemCount i = 0; i < num; ++i)
  205307. {
  205308. MIDIEndpointRef source = MIDIGetSource (i);
  205309. if (source != 0)
  205310. {
  205311. String name (getConnectedEndpointName (source));
  205312. if (name.isEmpty())
  205313. name = "<error>";
  205314. s.add (name);
  205315. }
  205316. else
  205317. {
  205318. s.add ("<error>");
  205319. }
  205320. }
  205321. return s;
  205322. }
  205323. int MidiInput::getDefaultDeviceIndex()
  205324. {
  205325. return 0;
  205326. }
  205327. struct MidiPortAndCallback
  205328. {
  205329. MidiInput* input;
  205330. MidiPortAndEndpoint* portAndEndpoint;
  205331. MidiInputCallback* callback;
  205332. MemoryBlock pendingData;
  205333. int pendingBytes;
  205334. double pendingDataTime;
  205335. bool active;
  205336. };
  205337. static CriticalSection callbackLock;
  205338. static VoidArray activeCallbacks;
  205339. static void processSysex (MidiPortAndCallback* const mpc, const uint8*& d, int& size, const double time)
  205340. {
  205341. if (*d == 0xf0)
  205342. {
  205343. mpc->pendingBytes = 0;
  205344. mpc->pendingDataTime = time;
  205345. }
  205346. mpc->pendingData.ensureSize (mpc->pendingBytes + size, false);
  205347. uint8* totalMessage = (uint8*) mpc->pendingData.getData();
  205348. uint8* dest = totalMessage + mpc->pendingBytes;
  205349. while (size > 0)
  205350. {
  205351. if (mpc->pendingBytes > 0 && *d >= 0x80)
  205352. {
  205353. if (*d >= 0xfa || *d == 0xf8)
  205354. {
  205355. mpc->callback->handleIncomingMidiMessage (mpc->input, MidiMessage (*d, time));
  205356. ++d;
  205357. --size;
  205358. }
  205359. else
  205360. {
  205361. if (*d == 0xf7)
  205362. {
  205363. *dest++ = *d++;
  205364. mpc->pendingBytes++;
  205365. --size;
  205366. }
  205367. break;
  205368. }
  205369. }
  205370. else
  205371. {
  205372. *dest++ = *d++;
  205373. mpc->pendingBytes++;
  205374. --size;
  205375. }
  205376. }
  205377. if (totalMessage [mpc->pendingBytes - 1] == 0xf7)
  205378. {
  205379. mpc->callback->handleIncomingMidiMessage (mpc->input, MidiMessage (totalMessage,
  205380. mpc->pendingBytes,
  205381. mpc->pendingDataTime));
  205382. mpc->pendingBytes = 0;
  205383. }
  205384. else
  205385. {
  205386. mpc->callback->handlePartialSysexMessage (mpc->input,
  205387. totalMessage,
  205388. mpc->pendingBytes,
  205389. mpc->pendingDataTime);
  205390. }
  205391. }
  205392. static void midiInputProc (const MIDIPacketList* pktlist,
  205393. void* readProcRefCon,
  205394. void* srcConnRefCon)
  205395. {
  205396. double time = Time::getMillisecondCounterHiRes() * 0.001;
  205397. const double originalTime = time;
  205398. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) readProcRefCon;
  205399. const ScopedLock sl (callbackLock);
  205400. if (activeCallbacks.contains (mpc) && mpc->active)
  205401. {
  205402. const MIDIPacket* packet = &pktlist->packet[0];
  205403. for (unsigned int i = 0; i < pktlist->numPackets; ++i)
  205404. {
  205405. const uint8* d = (const uint8*) (packet->data);
  205406. int size = packet->length;
  205407. while (size > 0)
  205408. {
  205409. time = originalTime;
  205410. if (mpc->pendingBytes > 0 || d[0] == 0xf0)
  205411. {
  205412. processSysex (mpc, d, size, time);
  205413. }
  205414. else
  205415. {
  205416. int used = 0;
  205417. const MidiMessage m (d, size, used, 0, time);
  205418. if (used <= 0)
  205419. {
  205420. jassertfalse // malformed midi message
  205421. break;
  205422. }
  205423. else
  205424. {
  205425. mpc->callback->handleIncomingMidiMessage (mpc->input, m);
  205426. }
  205427. size -= used;
  205428. d += used;
  205429. }
  205430. }
  205431. packet = MIDIPacketNext (packet);
  205432. }
  205433. }
  205434. }
  205435. MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback)
  205436. {
  205437. MidiInput* mi = 0;
  205438. if (((unsigned int) index) < (unsigned int) MIDIGetNumberOfSources())
  205439. {
  205440. MIDIEndpointRef endPoint = MIDIGetSource (index);
  205441. if (endPoint != 0)
  205442. {
  205443. CFStringRef pname;
  205444. if (OK (MIDIObjectGetStringProperty (endPoint, kMIDIPropertyName, &pname)))
  205445. {
  205446. log (T("CoreMidi - opening inp: ") + PlatformUtilities::cfStringToJuceString (pname));
  205447. if (makeSureClientExists())
  205448. {
  205449. MIDIPortRef port;
  205450. ScopedPointer <MidiPortAndCallback> mpc (new MidiPortAndCallback());
  205451. mpc->active = false;
  205452. if (OK (MIDIInputPortCreate (globalMidiClient, pname, midiInputProc, mpc, &port)))
  205453. {
  205454. if (OK (MIDIPortConnectSource (port, endPoint, 0)))
  205455. {
  205456. mpc->portAndEndpoint = new MidiPortAndEndpoint (port, endPoint);
  205457. mpc->callback = callback;
  205458. mpc->pendingBytes = 0;
  205459. mpc->pendingData.ensureSize (128);
  205460. mi = new MidiInput (getDevices() [index]);
  205461. mpc->input = mi;
  205462. mi->internal = (void*) mpc;
  205463. const ScopedLock sl (callbackLock);
  205464. activeCallbacks.add (mpc.release());
  205465. }
  205466. else
  205467. {
  205468. OK (MIDIPortDispose (port));
  205469. }
  205470. }
  205471. }
  205472. }
  205473. CFRelease (pname);
  205474. }
  205475. }
  205476. return mi;
  205477. }
  205478. MidiInput* MidiInput::createNewDevice (const String& deviceName, MidiInputCallback* callback)
  205479. {
  205480. MidiInput* mi = 0;
  205481. if (makeSureClientExists())
  205482. {
  205483. ScopedPointer <MidiPortAndCallback> mpc (new MidiPortAndCallback());
  205484. mpc->active = false;
  205485. MIDIEndpointRef endPoint;
  205486. CFStringRef name = PlatformUtilities::juceStringToCFString(deviceName);
  205487. if (OK (MIDIDestinationCreate (globalMidiClient, name, midiInputProc, mpc, &endPoint)))
  205488. {
  205489. mpc->portAndEndpoint = new MidiPortAndEndpoint (0, endPoint);
  205490. mpc->callback = callback;
  205491. mpc->pendingBytes = 0;
  205492. mpc->pendingData.ensureSize (128);
  205493. mi = new MidiInput (deviceName);
  205494. mpc->input = mi;
  205495. mi->internal = (void*) mpc;
  205496. const ScopedLock sl (callbackLock);
  205497. activeCallbacks.add (mpc.release());
  205498. }
  205499. CFRelease (name);
  205500. }
  205501. return mi;
  205502. }
  205503. MidiInput::MidiInput (const String& name_)
  205504. : name (name_)
  205505. {
  205506. }
  205507. MidiInput::~MidiInput()
  205508. {
  205509. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) internal;
  205510. mpc->active = false;
  205511. callbackLock.enter();
  205512. activeCallbacks.removeValue (mpc);
  205513. callbackLock.exit();
  205514. if (mpc->portAndEndpoint->port != 0)
  205515. OK (MIDIPortDisconnectSource (mpc->portAndEndpoint->port, mpc->portAndEndpoint->endPoint));
  205516. delete mpc->portAndEndpoint;
  205517. delete mpc;
  205518. }
  205519. void MidiInput::start()
  205520. {
  205521. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) internal;
  205522. const ScopedLock sl (callbackLock);
  205523. mpc->active = true;
  205524. }
  205525. void MidiInput::stop()
  205526. {
  205527. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) internal;
  205528. const ScopedLock sl (callbackLock);
  205529. mpc->active = false;
  205530. }
  205531. #undef log
  205532. #else
  205533. MidiOutput::~MidiOutput()
  205534. {
  205535. }
  205536. void MidiOutput::reset()
  205537. {
  205538. }
  205539. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  205540. {
  205541. return false;
  205542. }
  205543. void MidiOutput::setVolume (float leftVol, float rightVol)
  205544. {
  205545. }
  205546. void MidiOutput::sendMessageNow (const MidiMessage& message)
  205547. {
  205548. }
  205549. const StringArray MidiOutput::getDevices()
  205550. {
  205551. return StringArray();
  205552. }
  205553. MidiOutput* MidiOutput::openDevice (int index)
  205554. {
  205555. return 0;
  205556. }
  205557. const StringArray MidiInput::getDevices()
  205558. {
  205559. return StringArray();
  205560. }
  205561. MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback)
  205562. {
  205563. return 0;
  205564. }
  205565. #endif
  205566. #endif
  205567. /*** End of inlined file: juce_mac_CoreMidi.cpp ***/
  205568. #else
  205569. /*** Start of inlined file: juce_mac_Fonts.mm ***/
  205570. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  205571. // compiled on its own).
  205572. #if JUCE_INCLUDED_FILE
  205573. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  205574. #define SUPPORT_10_4_FONTS 1
  205575. #define NEW_CGFONT_FUNCTIONS_UNAVAILABLE (CGFontCreateWithFontName == 0)
  205576. #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
  205577. #define SUPPORT_ONLY_10_4_FONTS 1
  205578. #endif
  205579. END_JUCE_NAMESPACE
  205580. @interface NSFont (PrivateHack)
  205581. - (NSGlyph) _defaultGlyphForChar: (unichar) theChar;
  205582. @end
  205583. BEGIN_JUCE_NAMESPACE
  205584. #endif
  205585. class MacTypeface : public Typeface
  205586. {
  205587. public:
  205588. MacTypeface (const Font& font)
  205589. : Typeface (font.getTypefaceName())
  205590. {
  205591. const ScopedAutoReleasePool pool;
  205592. renderingTransform = CGAffineTransformIdentity;
  205593. bool needsItalicTransform = false;
  205594. #if JUCE_IPHONE
  205595. NSString* fontName = juceStringToNS (font.getTypefaceName());
  205596. if (font.isItalic() || font.isBold())
  205597. {
  205598. NSArray* familyFonts = [UIFont fontNamesForFamilyName: juceStringToNS (font.getTypefaceName())];
  205599. for (NSString* i in familyFonts)
  205600. {
  205601. const String fn (nsStringToJuce (i));
  205602. const String afterDash (fn.fromFirstOccurrenceOf (T("-"), false, false));
  205603. const bool probablyBold = afterDash.containsIgnoreCase (T("bold")) || fn.endsWithIgnoreCase (T("bold"));
  205604. const bool probablyItalic = afterDash.containsIgnoreCase (T("oblique"))
  205605. || afterDash.containsIgnoreCase (T("italic"))
  205606. || fn.endsWithIgnoreCase (T("oblique"))
  205607. || fn.endsWithIgnoreCase (T("italic"));
  205608. if (probablyBold == font.isBold()
  205609. && probablyItalic == font.isItalic())
  205610. {
  205611. fontName = i;
  205612. needsItalicTransform = false;
  205613. break;
  205614. }
  205615. else if (probablyBold && (! probablyItalic) && probablyBold == font.isBold())
  205616. {
  205617. fontName = i;
  205618. needsItalicTransform = true; // not ideal, so carry on in case we find a better one
  205619. }
  205620. }
  205621. if (needsItalicTransform)
  205622. renderingTransform.c = 0.15f;
  205623. }
  205624. fontRef = CGFontCreateWithFontName ((CFStringRef) fontName);
  205625. const int ascender = abs (CGFontGetAscent (fontRef));
  205626. const float totalHeight = ascender + abs (CGFontGetDescent (fontRef));
  205627. ascent = ascender / totalHeight;
  205628. unitsToHeightScaleFactor = 1.0f / totalHeight;
  205629. fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (fontRef) / totalHeight;
  205630. #else
  205631. nsFont = [NSFont fontWithName: juceStringToNS (font.getTypefaceName()) size: 1024];
  205632. if (font.isItalic())
  205633. {
  205634. NSFont* newFont = [[NSFontManager sharedFontManager] convertFont: nsFont
  205635. toHaveTrait: NSItalicFontMask];
  205636. if (newFont == nsFont)
  205637. needsItalicTransform = true; // couldn't find a proper italic version, so fake it with a transform..
  205638. nsFont = newFont;
  205639. }
  205640. if (font.isBold())
  205641. nsFont = [[NSFontManager sharedFontManager] convertFont: nsFont toHaveTrait: NSBoldFontMask];
  205642. [nsFont retain];
  205643. ascent = fabsf ((float) [nsFont ascender]);
  205644. float totalSize = ascent + fabsf ((float) [nsFont descender]);
  205645. ascent /= totalSize;
  205646. pathTransform = AffineTransform::identity.scale (1.0f / totalSize, 1.0f / totalSize);
  205647. if (needsItalicTransform)
  205648. {
  205649. pathTransform = pathTransform.sheared (-0.15f, 0.0f);
  205650. renderingTransform.c = 0.15f;
  205651. }
  205652. #if SUPPORT_ONLY_10_4_FONTS
  205653. ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  205654. if (atsFont == 0)
  205655. atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  205656. fontRef = CGFontCreateWithPlatformFont ((void*) &atsFont);
  205657. const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]);
  205658. unitsToHeightScaleFactor = 1.0f / totalHeight;
  205659. fontHeightToCGSizeFactor = 1024.0f / totalHeight;
  205660. #else
  205661. #if SUPPORT_10_4_FONTS
  205662. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  205663. {
  205664. ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  205665. if (atsFont == 0)
  205666. atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  205667. fontRef = CGFontCreateWithPlatformFont ((void*) &atsFont);
  205668. const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]);
  205669. unitsToHeightScaleFactor = 1.0f / totalHeight;
  205670. fontHeightToCGSizeFactor = 1024.0f / totalHeight;
  205671. }
  205672. else
  205673. #endif
  205674. {
  205675. fontRef = CGFontCreateWithFontName ((CFStringRef) [nsFont fontName]);
  205676. const int totalHeight = abs (CGFontGetAscent (fontRef)) + abs (CGFontGetDescent (fontRef));
  205677. unitsToHeightScaleFactor = 1.0f / totalHeight;
  205678. fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (fontRef) / (float) totalHeight;
  205679. }
  205680. #endif
  205681. #endif
  205682. }
  205683. ~MacTypeface()
  205684. {
  205685. #if ! JUCE_IPHONE
  205686. [nsFont release];
  205687. #endif
  205688. if (fontRef != 0)
  205689. CGFontRelease (fontRef);
  205690. }
  205691. float getAscent() const
  205692. {
  205693. return ascent;
  205694. }
  205695. float getDescent() const
  205696. {
  205697. return 1.0f - ascent;
  205698. }
  205699. float getStringWidth (const String& text)
  205700. {
  205701. if (fontRef == 0 || text.isEmpty())
  205702. return 0;
  205703. const int length = text.length();
  205704. HeapBlock <CGGlyph> glyphs;
  205705. createGlyphsForString (text, length, glyphs);
  205706. float x = 0;
  205707. #if SUPPORT_ONLY_10_4_FONTS
  205708. HeapBlock <NSSize> advances (length);
  205709. [nsFont getAdvancements: advances forGlyphs: (NSGlyph*) glyphs count: length];
  205710. for (int i = 0; i < length; ++i)
  205711. x += advances[i].width;
  205712. #else
  205713. #if SUPPORT_10_4_FONTS
  205714. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  205715. {
  205716. HeapBlock <NSSize> advances (length);
  205717. [nsFont getAdvancements: advances forGlyphs: (NSGlyph*) glyphs count: length];
  205718. for (int i = 0; i < length; ++i)
  205719. x += advances[i].width;
  205720. }
  205721. else
  205722. #endif
  205723. {
  205724. HeapBlock <int> advances (length);
  205725. if (CGFontGetGlyphAdvances (fontRef, glyphs, length, advances))
  205726. for (int i = 0; i < length; ++i)
  205727. x += advances[i];
  205728. }
  205729. #endif
  205730. return x * unitsToHeightScaleFactor;
  205731. }
  205732. void getGlyphPositions (const String& text, Array <int>& resultGlyphs, Array <float>& xOffsets)
  205733. {
  205734. xOffsets.add (0);
  205735. if (fontRef == 0 || text.isEmpty())
  205736. return;
  205737. const int length = text.length();
  205738. HeapBlock <CGGlyph> glyphs;
  205739. createGlyphsForString (text, length, glyphs);
  205740. #if SUPPORT_ONLY_10_4_FONTS
  205741. HeapBlock <NSSize> advances (length);
  205742. [nsFont getAdvancements: advances forGlyphs: (NSGlyph*) glyphs count: length];
  205743. int x = 0;
  205744. for (int i = 0; i < length; ++i)
  205745. {
  205746. x += advances[i].width;
  205747. xOffsets.add (x * unitsToHeightScaleFactor);
  205748. resultGlyphs.add (((NSGlyph*) glyphs)[i]);
  205749. }
  205750. #else
  205751. #if SUPPORT_10_4_FONTS
  205752. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  205753. {
  205754. HeapBlock <NSSize> advances (length);
  205755. [nsFont getAdvancements: advances forGlyphs: (NSGlyph*) glyphs count: length];
  205756. float x = 0;
  205757. for (int i = 0; i < length; ++i)
  205758. {
  205759. x += advances[i].width;
  205760. xOffsets.add (x * unitsToHeightScaleFactor);
  205761. resultGlyphs.add (((NSGlyph*) glyphs)[i]);
  205762. }
  205763. }
  205764. else
  205765. #endif
  205766. {
  205767. HeapBlock <int> advances (length);
  205768. if (CGFontGetGlyphAdvances (fontRef, glyphs, length, advances))
  205769. {
  205770. int x = 0;
  205771. for (int i = 0; i < length; ++i)
  205772. {
  205773. x += advances [i];
  205774. xOffsets.add (x * unitsToHeightScaleFactor);
  205775. resultGlyphs.add (glyphs[i]);
  205776. }
  205777. }
  205778. }
  205779. #endif
  205780. }
  205781. bool getOutlineForGlyph (int glyphNumber, Path& path)
  205782. {
  205783. #if JUCE_IPHONE
  205784. return false;
  205785. #else
  205786. if (nsFont == 0)
  205787. return false;
  205788. // we might need to apply a transform to the path, so it mustn't have anything else in it
  205789. jassert (path.isEmpty());
  205790. const ScopedAutoReleasePool pool;
  205791. NSBezierPath* bez = [NSBezierPath bezierPath];
  205792. [bez moveToPoint: NSMakePoint (0, 0)];
  205793. [bez appendBezierPathWithGlyph: (NSGlyph) glyphNumber
  205794. inFont: nsFont];
  205795. for (int i = 0; i < [bez elementCount]; ++i)
  205796. {
  205797. NSPoint p[3];
  205798. switch ([bez elementAtIndex: i associatedPoints: p])
  205799. {
  205800. case NSMoveToBezierPathElement:
  205801. path.startNewSubPath ((float) p[0].x, (float) -p[0].y);
  205802. break;
  205803. case NSLineToBezierPathElement:
  205804. path.lineTo ((float) p[0].x, (float) -p[0].y);
  205805. break;
  205806. case NSCurveToBezierPathElement:
  205807. 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);
  205808. break;
  205809. case NSClosePathBezierPathElement:
  205810. path.closeSubPath();
  205811. break;
  205812. default:
  205813. jassertfalse
  205814. break;
  205815. }
  205816. }
  205817. path.applyTransform (pathTransform);
  205818. return true;
  205819. #endif
  205820. }
  205821. juce_UseDebuggingNewOperator
  205822. CGFontRef fontRef;
  205823. float fontHeightToCGSizeFactor;
  205824. CGAffineTransform renderingTransform;
  205825. private:
  205826. float ascent, unitsToHeightScaleFactor;
  205827. #if JUCE_IPHONE
  205828. #else
  205829. NSFont* nsFont;
  205830. AffineTransform pathTransform;
  205831. #endif
  205832. void createGlyphsForString (const juce_wchar* const text, const int length, HeapBlock <CGGlyph>& glyphs)
  205833. {
  205834. #if SUPPORT_10_4_FONTS
  205835. #if ! SUPPORT_ONLY_10_4_FONTS
  205836. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  205837. #endif
  205838. {
  205839. glyphs.malloc (sizeof (NSGlyph) * length, 1);
  205840. NSGlyph* const g = (NSGlyph*) glyphs;
  205841. for (int i = 0; i < length; ++i)
  205842. g[i] = (NSGlyph) [nsFont _defaultGlyphForChar: text[i]];
  205843. return;
  205844. }
  205845. #endif
  205846. #if ! SUPPORT_ONLY_10_4_FONTS
  205847. if (charToGlyphMapper == 0)
  205848. charToGlyphMapper = new CharToGlyphMapper (fontRef);
  205849. glyphs.malloc (length);
  205850. for (int i = 0; i < length; ++i)
  205851. glyphs[i] = (CGGlyph) charToGlyphMapper->getGlyphForCharacter (text[i]);
  205852. #endif
  205853. }
  205854. #if ! SUPPORT_ONLY_10_4_FONTS
  205855. // Reads a CGFontRef's character map table to convert unicode into glyph numbers
  205856. class CharToGlyphMapper
  205857. {
  205858. public:
  205859. CharToGlyphMapper (CGFontRef fontRef)
  205860. : segCount (0), endCode (0), startCode (0), idDelta (0),
  205861. idRangeOffset (0), glyphIndexes (0)
  205862. {
  205863. CFDataRef cmapTable = CGFontCopyTableForTag (fontRef, 'cmap');
  205864. if (cmapTable != 0)
  205865. {
  205866. const int numSubtables = getValue16 (cmapTable, 2);
  205867. for (int i = 0; i < numSubtables; ++i)
  205868. {
  205869. if (getValue16 (cmapTable, i * 8 + 4) == 0) // check for platform ID of 0
  205870. {
  205871. const int offset = getValue32 (cmapTable, i * 8 + 8);
  205872. if (getValue16 (cmapTable, offset) == 4) // check that it's format 4..
  205873. {
  205874. const int length = getValue16 (cmapTable, offset + 2);
  205875. const int segCountX2 = getValue16 (cmapTable, offset + 6);
  205876. segCount = segCountX2 / 2;
  205877. const int endCodeOffset = offset + 14;
  205878. const int startCodeOffset = endCodeOffset + 2 + segCountX2;
  205879. const int idDeltaOffset = startCodeOffset + segCountX2;
  205880. const int idRangeOffsetOffset = idDeltaOffset + segCountX2;
  205881. const int glyphIndexesOffset = idRangeOffsetOffset + segCountX2;
  205882. endCode = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + endCodeOffset, segCountX2);
  205883. startCode = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + startCodeOffset, segCountX2);
  205884. idDelta = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + idDeltaOffset, segCountX2);
  205885. idRangeOffset = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + idRangeOffsetOffset, segCountX2);
  205886. glyphIndexes = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + glyphIndexesOffset, offset + length - glyphIndexesOffset);
  205887. }
  205888. break;
  205889. }
  205890. }
  205891. CFRelease (cmapTable);
  205892. }
  205893. }
  205894. ~CharToGlyphMapper()
  205895. {
  205896. if (endCode != 0)
  205897. {
  205898. CFRelease (endCode);
  205899. CFRelease (startCode);
  205900. CFRelease (idDelta);
  205901. CFRelease (idRangeOffset);
  205902. CFRelease (glyphIndexes);
  205903. }
  205904. }
  205905. int getGlyphForCharacter (const juce_wchar c) const
  205906. {
  205907. for (int i = 0; i < segCount; ++i)
  205908. {
  205909. if (getValue16 (endCode, i * 2) >= c)
  205910. {
  205911. const int start = getValue16 (startCode, i * 2);
  205912. if (start > c)
  205913. break;
  205914. const int delta = getValue16 (idDelta, i * 2);
  205915. const int rangeOffset = getValue16 (idRangeOffset, i * 2);
  205916. if (rangeOffset == 0)
  205917. return delta + c;
  205918. else
  205919. return getValue16 (glyphIndexes, 2 * ((rangeOffset / 2) + (c - start) - (segCount - i)));
  205920. }
  205921. }
  205922. // If we failed to find it "properly", this dodgy fall-back seems to do the trick for most fonts!
  205923. return jmax (-1, c - 29);
  205924. }
  205925. private:
  205926. int segCount;
  205927. CFDataRef endCode, startCode, idDelta, idRangeOffset, glyphIndexes;
  205928. static uint16 getValue16 (CFDataRef data, const int index)
  205929. {
  205930. return CFSwapInt16BigToHost (*(UInt16*) (CFDataGetBytePtr (data) + index));
  205931. }
  205932. static uint32 getValue32 (CFDataRef data, const int index)
  205933. {
  205934. return CFSwapInt32BigToHost (*(UInt32*) (CFDataGetBytePtr (data) + index));
  205935. }
  205936. };
  205937. ScopedPointer <CharToGlyphMapper> charToGlyphMapper;
  205938. #endif
  205939. };
  205940. const Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  205941. {
  205942. return new MacTypeface (font);
  205943. }
  205944. const StringArray Font::findAllTypefaceNames() throw()
  205945. {
  205946. StringArray names;
  205947. const ScopedAutoReleasePool pool;
  205948. #if JUCE_IPHONE
  205949. NSArray* fonts = [UIFont familyNames];
  205950. #else
  205951. NSArray* fonts = [[NSFontManager sharedFontManager] availableFontFamilies];
  205952. #endif
  205953. for (unsigned int i = 0; i < [fonts count]; ++i)
  205954. names.add (nsStringToJuce ((NSString*) [fonts objectAtIndex: i]));
  205955. names.sort (true);
  205956. return names;
  205957. }
  205958. void Font::getPlatformDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed) throw()
  205959. {
  205960. #if JUCE_IPHONE
  205961. defaultSans = "Helvetica";
  205962. defaultSerif = "Times New Roman";
  205963. defaultFixed = "Courier New";
  205964. #else
  205965. defaultSans = "Lucida Grande";
  205966. defaultSerif = "Times New Roman";
  205967. defaultFixed = "Monaco";
  205968. #endif
  205969. }
  205970. #endif
  205971. /*** End of inlined file: juce_mac_Fonts.mm ***/
  205972. // (must go before juce_mac_CoreGraphicsContext.mm)
  205973. /*** Start of inlined file: juce_mac_CoreGraphicsContext.mm ***/
  205974. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  205975. // compiled on its own).
  205976. #if JUCE_INCLUDED_FILE
  205977. class CoreGraphicsImage : public Image
  205978. {
  205979. public:
  205980. CoreGraphicsImage (const PixelFormat format_,
  205981. const int imageWidth_,
  205982. const int imageHeight_,
  205983. const bool clearImage)
  205984. : Image (format_, imageWidth_, imageHeight_, clearImage)
  205985. {
  205986. CGColorSpaceRef colourSpace = format == Image::SingleChannel ? CGColorSpaceCreateDeviceGray()
  205987. : CGColorSpaceCreateDeviceRGB();
  205988. context = CGBitmapContextCreate (imageData, imageWidth, imageHeight, 8, lineStride,
  205989. colourSpace, getCGImageFlags (*this));
  205990. CGColorSpaceRelease (colourSpace);
  205991. }
  205992. ~CoreGraphicsImage()
  205993. {
  205994. CGContextRelease (context);
  205995. }
  205996. LowLevelGraphicsContext* createLowLevelContext();
  205997. static CGImageRef createImage (const Image& juceImage, const bool forAlpha, CGColorSpaceRef colourSpace)
  205998. {
  205999. const CoreGraphicsImage* nativeImage = dynamic_cast <const CoreGraphicsImage*> (&juceImage);
  206000. if (nativeImage != 0 && (juceImage.getFormat() == Image::SingleChannel || ! forAlpha))
  206001. {
  206002. return CGBitmapContextCreateImage (nativeImage->context);
  206003. }
  206004. else
  206005. {
  206006. const Image::BitmapData srcData (juceImage, 0, 0, juceImage.getWidth(), juceImage.getHeight());
  206007. CGDataProviderRef provider = CGDataProviderCreateWithData (0, srcData.data, srcData.lineStride * srcData.height, 0);
  206008. CGImageRef imageRef = CGImageCreate (srcData.width, srcData.height,
  206009. 8, srcData.pixelStride * 8, srcData.lineStride,
  206010. colourSpace, getCGImageFlags (juceImage), provider,
  206011. 0, true, kCGRenderingIntentDefault);
  206012. CGDataProviderRelease (provider);
  206013. return imageRef;
  206014. }
  206015. }
  206016. #if JUCE_MAC
  206017. static NSImage* createNSImage (const Image& image)
  206018. {
  206019. const ScopedAutoReleasePool pool;
  206020. NSImage* im = [[NSImage alloc] init];
  206021. [im setSize: NSMakeSize (image.getWidth(), image.getHeight())];
  206022. [im lockFocus];
  206023. CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB();
  206024. CGImageRef imageRef = createImage (image, false, colourSpace);
  206025. CGColorSpaceRelease (colourSpace);
  206026. CGContextRef cg = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
  206027. CGContextDrawImage (cg, CGRectMake (0, 0, image.getWidth(), image.getHeight()), imageRef);
  206028. CGImageRelease (imageRef);
  206029. [im unlockFocus];
  206030. return im;
  206031. }
  206032. #endif
  206033. CGContextRef context;
  206034. private:
  206035. static CGBitmapInfo getCGImageFlags (const Image& image)
  206036. {
  206037. #if JUCE_BIG_ENDIAN
  206038. return image.getFormat() == Image::ARGB ? (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Big) : kCGBitmapByteOrderDefault;
  206039. #else
  206040. return image.getFormat() == Image::ARGB ? (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Little) : kCGBitmapByteOrderDefault;
  206041. #endif
  206042. }
  206043. };
  206044. Image* Image::createNativeImage (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage)
  206045. {
  206046. #if USE_COREGRAPHICS_RENDERING
  206047. return new CoreGraphicsImage (format == RGB ? ARGB : format, imageWidth, imageHeight, clearImage);
  206048. #else
  206049. return new Image (format, imageWidth, imageHeight, clearImage);
  206050. #endif
  206051. }
  206052. class CoreGraphicsContext : public LowLevelGraphicsContext
  206053. {
  206054. public:
  206055. CoreGraphicsContext (CGContextRef context_, const float flipHeight_)
  206056. : context (context_),
  206057. flipHeight (flipHeight_),
  206058. numGradientLookupEntries (0)
  206059. {
  206060. CGContextRetain (context);
  206061. CGContextSaveGState(context);
  206062. CGContextSetShouldSmoothFonts (context, true);
  206063. CGContextSetShouldAntialias (context, true);
  206064. CGContextSetBlendMode (context, kCGBlendModeNormal);
  206065. rgbColourSpace = CGColorSpaceCreateDeviceRGB();
  206066. greyColourSpace = CGColorSpaceCreateDeviceGray();
  206067. gradientCallbacks.version = 0;
  206068. gradientCallbacks.evaluate = gradientCallback;
  206069. gradientCallbacks.releaseInfo = 0;
  206070. state = new SavedState();
  206071. }
  206072. ~CoreGraphicsContext()
  206073. {
  206074. CGContextRestoreGState (context);
  206075. CGContextRelease (context);
  206076. CGColorSpaceRelease (rgbColourSpace);
  206077. CGColorSpaceRelease (greyColourSpace);
  206078. }
  206079. bool isVectorDevice() const { return false; }
  206080. void setOrigin (int x, int y)
  206081. {
  206082. CGContextTranslateCTM (context, x, -y);
  206083. }
  206084. bool clipToRectangle (const Rectangle<int>& r)
  206085. {
  206086. CGContextClipToRect (context, CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight()));
  206087. return ! isClipEmpty();
  206088. }
  206089. bool clipToRectangleList (const RectangleList& clipRegion)
  206090. {
  206091. if (clipRegion.isEmpty())
  206092. {
  206093. CGContextClipToRect (context, CGRectMake (0, 0, 0, 0));
  206094. return false;
  206095. }
  206096. else
  206097. {
  206098. const int numRects = clipRegion.getNumRectangles();
  206099. HeapBlock <CGRect> rects (numRects);
  206100. for (int i = 0; i < numRects; ++i)
  206101. {
  206102. const Rectangle<int>& r = clipRegion.getRectangle(i);
  206103. rects[i] = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight());
  206104. }
  206105. CGContextClipToRects (context, rects, numRects);
  206106. return ! isClipEmpty();
  206107. }
  206108. }
  206109. void excludeClipRectangle (const Rectangle<int>& r)
  206110. {
  206111. RectangleList remaining (getClipBounds());
  206112. remaining.subtract (r);
  206113. clipToRectangleList (remaining);
  206114. }
  206115. void clipToPath (const Path& path, const AffineTransform& transform)
  206116. {
  206117. createPath (path, transform);
  206118. CGContextClip (context);
  206119. }
  206120. void clipToImageAlpha (const Image& sourceImage, const Rectangle<int>& srcClip, const AffineTransform& transform)
  206121. {
  206122. if (! transform.isSingularity())
  206123. {
  206124. Image* singleChannelImage = createAlphaChannelImage (sourceImage);
  206125. CGImageRef image = CoreGraphicsImage::createImage (*singleChannelImage, true, greyColourSpace);
  206126. flip();
  206127. AffineTransform t (AffineTransform::scale (1.0f, -1.0f).translated (0, sourceImage.getHeight()).followedBy (transform));
  206128. applyTransform (t);
  206129. CGRect r = CGRectMake (0, 0, sourceImage.getWidth(), sourceImage.getHeight());
  206130. CGContextClipToMask (context, r, image);
  206131. applyTransform (t.inverted());
  206132. flip();
  206133. CGImageRelease (image);
  206134. deleteAlphaChannelImage (sourceImage, singleChannelImage);
  206135. }
  206136. }
  206137. bool clipRegionIntersects (const Rectangle<int>& r)
  206138. {
  206139. return getClipBounds().intersects (r);
  206140. }
  206141. const Rectangle<int> getClipBounds() const
  206142. {
  206143. CGRect bounds = CGRectIntegral (CGContextGetClipBoundingBox (context));
  206144. return Rectangle<int> (roundToInt (bounds.origin.x),
  206145. roundToInt (flipHeight - (bounds.origin.y + bounds.size.height)),
  206146. roundToInt (bounds.size.width),
  206147. roundToInt (bounds.size.height));
  206148. }
  206149. bool isClipEmpty() const
  206150. {
  206151. return CGRectIsEmpty (CGContextGetClipBoundingBox (context));
  206152. }
  206153. void saveState()
  206154. {
  206155. CGContextSaveGState (context);
  206156. stateStack.add (new SavedState (*state));
  206157. }
  206158. void restoreState()
  206159. {
  206160. CGContextRestoreGState (context);
  206161. SavedState* const top = stateStack.getLast();
  206162. if (top != 0)
  206163. {
  206164. state = top;
  206165. stateStack.removeLast (1, false);
  206166. }
  206167. else
  206168. {
  206169. jassertfalse // trying to pop with an empty stack!
  206170. }
  206171. }
  206172. void setFill (const FillType& fillType)
  206173. {
  206174. state->fillType = fillType;
  206175. if (fillType.isColour())
  206176. {
  206177. CGContextSetRGBFillColor (context, fillType.colour.getFloatRed(), fillType.colour.getFloatGreen(),
  206178. fillType.colour.getFloatBlue(), fillType.colour.getFloatAlpha());
  206179. CGContextSetAlpha (context, 1.0f);
  206180. }
  206181. }
  206182. void setOpacity (float newOpacity)
  206183. {
  206184. state->fillType.setOpacity (newOpacity);
  206185. setFill (state->fillType);
  206186. }
  206187. void setInterpolationQuality (Graphics::ResamplingQuality quality)
  206188. {
  206189. CGContextSetInterpolationQuality (context, quality == Graphics::lowResamplingQuality
  206190. ? kCGInterpolationLow
  206191. : kCGInterpolationHigh);
  206192. }
  206193. void fillRect (const Rectangle<int>& r, const bool replaceExistingContents)
  206194. {
  206195. CGRect cgRect = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight());
  206196. if (replaceExistingContents)
  206197. {
  206198. #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
  206199. CGContextClearRect (context, cgRect);
  206200. #else
  206201. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  206202. if (CGContextDrawLinearGradient == 0) // (just a way of checking whether we're running in 10.5 or later)
  206203. CGContextClearRect (context, cgRect);
  206204. else
  206205. #endif
  206206. CGContextSetBlendMode (context, kCGBlendModeCopy);
  206207. #endif
  206208. fillRect (r, false);
  206209. CGContextSetBlendMode (context, kCGBlendModeNormal);
  206210. }
  206211. else
  206212. {
  206213. if (state->fillType.isColour())
  206214. {
  206215. CGContextFillRect (context, cgRect);
  206216. }
  206217. else if (state->fillType.isGradient())
  206218. {
  206219. CGContextSaveGState (context);
  206220. CGContextClipToRect (context, cgRect);
  206221. drawGradient();
  206222. CGContextRestoreGState (context);
  206223. }
  206224. else
  206225. {
  206226. CGContextSaveGState (context);
  206227. CGContextClipToRect (context, cgRect);
  206228. drawImage (*(state->fillType.image), state->fillType.image->getBounds(), state->fillType.transform, true);
  206229. CGContextRestoreGState (context);
  206230. }
  206231. }
  206232. }
  206233. void fillPath (const Path& path, const AffineTransform& transform)
  206234. {
  206235. CGContextSaveGState (context);
  206236. if (state->fillType.isColour())
  206237. {
  206238. flip();
  206239. applyTransform (transform);
  206240. createPath (path);
  206241. if (path.isUsingNonZeroWinding())
  206242. CGContextFillPath (context);
  206243. else
  206244. CGContextEOFillPath (context);
  206245. }
  206246. else
  206247. {
  206248. createPath (path, transform);
  206249. if (path.isUsingNonZeroWinding())
  206250. CGContextClip (context);
  206251. else
  206252. CGContextEOClip (context);
  206253. if (state->fillType.isGradient())
  206254. drawGradient();
  206255. else
  206256. drawImage (*(state->fillType.image), state->fillType.image->getBounds(), state->fillType.transform, true);
  206257. }
  206258. CGContextRestoreGState (context);
  206259. }
  206260. void drawImage (const Image& sourceImage, const Rectangle<int>& srcClip,
  206261. const AffineTransform& transform, const bool fillEntireClipAsTiles)
  206262. {
  206263. jassert (sourceImage.getBounds().contains (srcClip));
  206264. CGImageRef fullImage = CoreGraphicsImage::createImage (sourceImage, false, rgbColourSpace);
  206265. CGImageRef image = fullImage;
  206266. if (srcClip != sourceImage.getBounds())
  206267. {
  206268. image = CGImageCreateWithImageInRect (fullImage, CGRectMake (srcClip.getX(), srcClip.getY(),
  206269. srcClip.getWidth(), srcClip.getHeight()));
  206270. CGImageRelease (fullImage);
  206271. }
  206272. CGContextSaveGState (context);
  206273. CGContextSetAlpha (context, state->fillType.getOpacity());
  206274. flip();
  206275. applyTransform (AffineTransform::scale (1.0f, -1.0f).translated (0, srcClip.getHeight()).followedBy (transform));
  206276. CGRect imageRect = CGRectMake (0, 0, srcClip.getWidth(), srcClip.getHeight());
  206277. if (fillEntireClipAsTiles)
  206278. {
  206279. #if JUCE_IPHONE || (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5)
  206280. CGContextDrawTiledImage (context, imageRect, image);
  206281. #else
  206282. #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
  206283. // There's a bug in CGContextDrawTiledImage that makes it incredibly slow
  206284. // if it's doing a transformation - it's quicker to just draw lots of images manually
  206285. if (CGContextDrawTiledImage != 0 && transform.isOnlyTranslation())
  206286. CGContextDrawTiledImage (context, imageRect, image);
  206287. else
  206288. #endif
  206289. {
  206290. // Fallback to manually doing a tiled fill on 10.4
  206291. CGRect clip = CGRectIntegral (CGContextGetClipBoundingBox (context));
  206292. const int iw = srcClip.getWidth();
  206293. const int ih = srcClip.getHeight();
  206294. int x = 0, y = 0;
  206295. while (x > clip.origin.x) x -= iw;
  206296. while (y > clip.origin.y) y -= ih;
  206297. const int right = (int) (clip.origin.x + clip.size.width);
  206298. const int bottom = (int) (clip.origin.y + clip.size.height);
  206299. while (y < bottom)
  206300. {
  206301. for (int x2 = x; x2 < right; x2 += iw)
  206302. CGContextDrawImage (context, CGRectMake (x2, y, iw, ih), image);
  206303. y += ih;
  206304. }
  206305. }
  206306. #endif
  206307. }
  206308. else
  206309. {
  206310. CGContextDrawImage (context, imageRect, image);
  206311. }
  206312. CGImageRelease (image); // (This causes a memory bug in iPhone sim 3.0 - try upgrading to a later version if you hit this)
  206313. CGContextRestoreGState (context);
  206314. }
  206315. void drawLine (double x1, double y1, double x2, double y2)
  206316. {
  206317. CGContextSetLineCap (context, kCGLineCapSquare);
  206318. CGContextSetLineWidth (context, 1.0f);
  206319. CGContextSetRGBStrokeColor (context,
  206320. state->fillType.colour.getFloatRed(), state->fillType.colour.getFloatGreen(),
  206321. state->fillType.colour.getFloatBlue(), state->fillType.colour.getFloatAlpha());
  206322. CGPoint line[] = { { (float) x1 + 0.5f, flipHeight - ((float) y1 + 0.5f) },
  206323. { (float) x2 + 0.5f, flipHeight - ((float) y2 + 0.5f) } };
  206324. CGContextStrokeLineSegments (context, line, 1);
  206325. }
  206326. void drawVerticalLine (const int x, double top, double bottom)
  206327. {
  206328. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  206329. CGContextFillRect (context, CGRectMake (x, flipHeight - (float) bottom, 1.0f, (float) (bottom - top)));
  206330. #else
  206331. // On Leopard, unless both co-ordinates are non-integer, it disables anti-aliasing, so nudge
  206332. // the x co-ord slightly to trick it..
  206333. CGContextFillRect (context, CGRectMake (x + 1.0f / 256.0f, flipHeight - (float) bottom, 1.0f + 1.0f / 256.0f, (float) (bottom - top)));
  206334. #endif
  206335. }
  206336. void drawHorizontalLine (const int y, double left, double right)
  206337. {
  206338. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  206339. CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + 1.0f), (float) (right - left), 1.0f));
  206340. #else
  206341. // On Leopard, unless both co-ordinates are non-integer, it disables anti-aliasing, so nudge
  206342. // the x co-ord slightly to trick it..
  206343. CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + (1.0f + 1.0f / 256.0f)), (float) (right - left), 1.0f + 1.0f / 256.0f));
  206344. #endif
  206345. }
  206346. void setFont (const Font& newFont)
  206347. {
  206348. if (state->font != newFont)
  206349. {
  206350. state->fontRef = 0;
  206351. state->font = newFont;
  206352. MacTypeface* mf = dynamic_cast <MacTypeface*> ((Typeface*) state->font.getTypeface());
  206353. if (mf != 0)
  206354. {
  206355. state->fontRef = mf->fontRef;
  206356. CGContextSetFont (context, state->fontRef);
  206357. CGContextSetFontSize (context, state->font.getHeight() * mf->fontHeightToCGSizeFactor);
  206358. state->fontTransform = mf->renderingTransform;
  206359. state->fontTransform.a *= state->font.getHorizontalScale();
  206360. CGContextSetTextMatrix (context, state->fontTransform);
  206361. }
  206362. }
  206363. }
  206364. const Font getFont()
  206365. {
  206366. return state->font;
  206367. }
  206368. void drawGlyph (int glyphNumber, const AffineTransform& transform)
  206369. {
  206370. if (state->fontRef != 0 && state->fillType.isColour())
  206371. {
  206372. if (transform.isOnlyTranslation())
  206373. {
  206374. CGGlyph g = glyphNumber;
  206375. CGContextShowGlyphsAtPoint (context, transform.getTranslationX(),
  206376. flipHeight - roundToInt (transform.getTranslationY()), &g, 1);
  206377. }
  206378. else
  206379. {
  206380. CGContextSaveGState (context);
  206381. flip();
  206382. applyTransform (transform);
  206383. CGAffineTransform t = state->fontTransform;
  206384. t.d = -t.d;
  206385. CGContextSetTextMatrix (context, t);
  206386. CGGlyph g = glyphNumber;
  206387. CGContextShowGlyphsAtPoint (context, 0, 0, &g, 1);
  206388. CGContextSetTextMatrix (context, state->fontTransform);
  206389. CGContextRestoreGState (context);
  206390. }
  206391. }
  206392. else
  206393. {
  206394. Path p;
  206395. Font& f = state->font;
  206396. f.getTypeface()->getOutlineForGlyph (glyphNumber, p);
  206397. fillPath (p, AffineTransform::scale (f.getHeight() * f.getHorizontalScale(), f.getHeight())
  206398. .followedBy (transform));
  206399. }
  206400. }
  206401. private:
  206402. CGContextRef context;
  206403. const float flipHeight;
  206404. CGColorSpaceRef rgbColourSpace, greyColourSpace;
  206405. CGFunctionCallbacks gradientCallbacks;
  206406. struct SavedState
  206407. {
  206408. SavedState()
  206409. : font (1.0f), fontRef (0), fontTransform (CGAffineTransformIdentity)
  206410. {
  206411. }
  206412. SavedState (const SavedState& other)
  206413. : fillType (other.fillType), font (other.font), fontRef (other.fontRef),
  206414. fontTransform (other.fontTransform)
  206415. {
  206416. }
  206417. ~SavedState()
  206418. {
  206419. }
  206420. FillType fillType;
  206421. Font font;
  206422. CGFontRef fontRef;
  206423. CGAffineTransform fontTransform;
  206424. };
  206425. ScopedPointer <SavedState> state;
  206426. OwnedArray <SavedState> stateStack;
  206427. HeapBlock <PixelARGB> gradientLookupTable;
  206428. int numGradientLookupEntries;
  206429. static void gradientCallback (void* info, const CGFloat* inData, CGFloat* outData)
  206430. {
  206431. const CoreGraphicsContext* const g = (const CoreGraphicsContext*) info;
  206432. const int index = roundToInt (g->numGradientLookupEntries * inData[0]);
  206433. PixelARGB colour (g->gradientLookupTable [jlimit (0, g->numGradientLookupEntries, index)]);
  206434. colour.unpremultiply();
  206435. outData[0] = colour.getRed() / 255.0f;
  206436. outData[1] = colour.getGreen() / 255.0f;
  206437. outData[2] = colour.getBlue() / 255.0f;
  206438. outData[3] = colour.getAlpha() / 255.0f;
  206439. }
  206440. CGShadingRef createGradient (const AffineTransform& transform, ColourGradient gradient)
  206441. {
  206442. numGradientLookupEntries = gradient.createLookupTable (transform, gradientLookupTable);
  206443. --numGradientLookupEntries;
  206444. CGShadingRef result = 0;
  206445. CGFunctionRef function = CGFunctionCreate ((void*) this, 1, 0, 4, 0, &gradientCallbacks);
  206446. CGPoint p1 (CGPointMake (gradient.x1, gradient.y1));
  206447. if (gradient.isRadial)
  206448. {
  206449. result = CGShadingCreateRadial (rgbColourSpace, p1, 0,
  206450. p1, hypotf (gradient.x1 - gradient.x2, gradient.y1 - gradient.y2),
  206451. function, true, true);
  206452. }
  206453. else
  206454. {
  206455. result = CGShadingCreateAxial (rgbColourSpace, p1,
  206456. CGPointMake (gradient.x2, gradient.y2),
  206457. function, true, true);
  206458. }
  206459. CGFunctionRelease (function);
  206460. return result;
  206461. }
  206462. void drawGradient()
  206463. {
  206464. flip();
  206465. applyTransform (state->fillType.transform);
  206466. CGContextSetInterpolationQuality (context, kCGInterpolationDefault); // (This is required for 10.4, where there's a crash if
  206467. // you draw a gradient with high quality interp enabled).
  206468. CGShadingRef shading = createGradient (state->fillType.transform, *(state->fillType.gradient));
  206469. CGContextSetAlpha (context, state->fillType.getOpacity());
  206470. CGContextDrawShading (context, shading);
  206471. CGShadingRelease (shading);
  206472. }
  206473. void createPath (const Path& path) const
  206474. {
  206475. CGContextBeginPath (context);
  206476. Path::Iterator i (path);
  206477. while (i.next())
  206478. {
  206479. switch (i.elementType)
  206480. {
  206481. case Path::Iterator::startNewSubPath:
  206482. CGContextMoveToPoint (context, i.x1, i.y1);
  206483. break;
  206484. case Path::Iterator::lineTo:
  206485. CGContextAddLineToPoint (context, i.x1, i.y1);
  206486. break;
  206487. case Path::Iterator::quadraticTo:
  206488. CGContextAddQuadCurveToPoint (context, i.x1, i.y1, i.x2, i.y2);
  206489. break;
  206490. case Path::Iterator::cubicTo:
  206491. CGContextAddCurveToPoint (context, i.x1, i.y1, i.x2, i.y2, i.x3, i.y3);
  206492. break;
  206493. case Path::Iterator::closePath:
  206494. CGContextClosePath (context); break;
  206495. default:
  206496. jassertfalse
  206497. break;
  206498. }
  206499. }
  206500. }
  206501. void createPath (const Path& path, const AffineTransform& transform) const
  206502. {
  206503. CGContextBeginPath (context);
  206504. Path::Iterator i (path);
  206505. while (i.next())
  206506. {
  206507. switch (i.elementType)
  206508. {
  206509. case Path::Iterator::startNewSubPath:
  206510. transform.transformPoint (i.x1, i.y1);
  206511. CGContextMoveToPoint (context, i.x1, flipHeight - i.y1);
  206512. break;
  206513. case Path::Iterator::lineTo:
  206514. transform.transformPoint (i.x1, i.y1);
  206515. CGContextAddLineToPoint (context, i.x1, flipHeight - i.y1);
  206516. break;
  206517. case Path::Iterator::quadraticTo:
  206518. transform.transformPoint (i.x1, i.y1);
  206519. transform.transformPoint (i.x2, i.y2);
  206520. CGContextAddQuadCurveToPoint (context, i.x1, flipHeight - i.y1, i.x2, flipHeight - i.y2);
  206521. break;
  206522. case Path::Iterator::cubicTo:
  206523. transform.transformPoint (i.x1, i.y1);
  206524. transform.transformPoint (i.x2, i.y2);
  206525. transform.transformPoint (i.x3, i.y3);
  206526. CGContextAddCurveToPoint (context, i.x1, flipHeight - i.y1, i.x2, flipHeight - i.y2, i.x3, flipHeight - i.y3);
  206527. break;
  206528. case Path::Iterator::closePath:
  206529. CGContextClosePath (context); break;
  206530. default:
  206531. jassertfalse
  206532. break;
  206533. }
  206534. }
  206535. }
  206536. static Image* createAlphaChannelImage (const Image& im)
  206537. {
  206538. if (im.getFormat() == Image::SingleChannel)
  206539. return const_cast <Image*> (&im);
  206540. return im.createCopyOfAlphaChannel();
  206541. }
  206542. static void deleteAlphaChannelImage (const Image& im, Image* const alphaIm)
  206543. {
  206544. if (im.getFormat() != Image::SingleChannel)
  206545. delete alphaIm;
  206546. }
  206547. void flip() const
  206548. {
  206549. CGContextConcatCTM (context, CGAffineTransformMake (1, 0, 0, -1, 0, flipHeight));
  206550. }
  206551. void applyTransform (const AffineTransform& transform) const
  206552. {
  206553. CGAffineTransform t;
  206554. t.a = transform.mat00;
  206555. t.b = transform.mat10;
  206556. t.c = transform.mat01;
  206557. t.d = transform.mat11;
  206558. t.tx = transform.mat02;
  206559. t.ty = transform.mat12;
  206560. CGContextConcatCTM (context, t);
  206561. }
  206562. float flipY (float y) const
  206563. {
  206564. return flipHeight - y;
  206565. }
  206566. };
  206567. LowLevelGraphicsContext* CoreGraphicsImage::createLowLevelContext()
  206568. {
  206569. return new CoreGraphicsContext (context, imageHeight);
  206570. }
  206571. #endif
  206572. /*** End of inlined file: juce_mac_CoreGraphicsContext.mm ***/
  206573. /*** Start of inlined file: juce_mac_NSViewComponentPeer.mm ***/
  206574. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  206575. // compiled on its own).
  206576. #if JUCE_INCLUDED_FILE
  206577. class NSViewComponentPeer;
  206578. END_JUCE_NAMESPACE
  206579. #define JuceNSView MakeObjCClassName(JuceNSView)
  206580. @interface JuceNSView : NSView
  206581. {
  206582. @public
  206583. NSViewComponentPeer* owner;
  206584. NSNotificationCenter* notificationCenter;
  206585. }
  206586. - (JuceNSView*) initWithOwner: (NSViewComponentPeer*) owner withFrame: (NSRect) frame;
  206587. - (void) dealloc;
  206588. - (BOOL) isOpaque;
  206589. - (void) drawRect: (NSRect) r;
  206590. - (void) mouseDown: (NSEvent*) ev;
  206591. - (void) asyncMouseDown: (NSEvent*) ev;
  206592. - (void) mouseUp: (NSEvent*) ev;
  206593. - (void) asyncMouseUp: (NSEvent*) ev;
  206594. - (void) mouseDragged: (NSEvent*) ev;
  206595. - (void) mouseMoved: (NSEvent*) ev;
  206596. - (void) mouseEntered: (NSEvent*) ev;
  206597. - (void) mouseExited: (NSEvent*) ev;
  206598. - (void) rightMouseDown: (NSEvent*) ev;
  206599. - (void) rightMouseDragged: (NSEvent*) ev;
  206600. - (void) rightMouseUp: (NSEvent*) ev;
  206601. - (void) otherMouseDown: (NSEvent*) ev;
  206602. - (void) otherMouseDragged: (NSEvent*) ev;
  206603. - (void) otherMouseUp: (NSEvent*) ev;
  206604. - (void) scrollWheel: (NSEvent*) ev;
  206605. - (BOOL) acceptsFirstMouse: (NSEvent*) ev;
  206606. - (void) frameChanged: (NSNotification*) n;
  206607. - (void) viewDidMoveToWindow;
  206608. - (void) keyDown: (NSEvent*) ev;
  206609. - (void) keyUp: (NSEvent*) ev;
  206610. - (void) flagsChanged: (NSEvent*) ev;
  206611. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  206612. - (BOOL) performKeyEquivalent: (NSEvent*) ev;
  206613. #endif
  206614. - (BOOL) becomeFirstResponder;
  206615. - (BOOL) resignFirstResponder;
  206616. - (BOOL) acceptsFirstResponder;
  206617. - (void) asyncRepaint: (id) rect;
  206618. - (NSArray*) getSupportedDragTypes;
  206619. - (BOOL) sendDragCallback: (int) type sender: (id <NSDraggingInfo>) sender;
  206620. - (NSDragOperation) draggingEntered: (id <NSDraggingInfo>) sender;
  206621. - (NSDragOperation) draggingUpdated: (id <NSDraggingInfo>) sender;
  206622. - (void) draggingEnded: (id <NSDraggingInfo>) sender;
  206623. - (void) draggingExited: (id <NSDraggingInfo>) sender;
  206624. - (BOOL) prepareForDragOperation: (id <NSDraggingInfo>) sender;
  206625. - (BOOL) performDragOperation: (id <NSDraggingInfo>) sender;
  206626. - (void) concludeDragOperation: (id <NSDraggingInfo>) sender;
  206627. @end
  206628. #define JuceNSWindow MakeObjCClassName(JuceNSWindow)
  206629. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  206630. @interface JuceNSWindow : NSWindow <NSWindowDelegate>
  206631. #else
  206632. @interface JuceNSWindow : NSWindow
  206633. #endif
  206634. {
  206635. @private
  206636. NSViewComponentPeer* owner;
  206637. bool isZooming;
  206638. }
  206639. - (void) setOwner: (NSViewComponentPeer*) owner;
  206640. - (BOOL) canBecomeKeyWindow;
  206641. - (void) becomeKeyWindow;
  206642. - (BOOL) windowShouldClose: (id) window;
  206643. - (NSRect) constrainFrameRect: (NSRect) frameRect toScreen: (NSScreen*) screen;
  206644. - (NSSize) windowWillResize: (NSWindow*) window toSize: (NSSize) proposedFrameSize;
  206645. - (void) zoom: (id) sender;
  206646. @end
  206647. BEGIN_JUCE_NAMESPACE
  206648. class NSViewComponentPeer : public ComponentPeer
  206649. {
  206650. public:
  206651. NSViewComponentPeer (Component* const component,
  206652. const int windowStyleFlags,
  206653. NSView* viewToAttachTo);
  206654. ~NSViewComponentPeer();
  206655. void* getNativeHandle() const;
  206656. void setVisible (bool shouldBeVisible);
  206657. void setTitle (const String& title);
  206658. void setPosition (int x, int y);
  206659. void setSize (int w, int h);
  206660. void setBounds (int x, int y, int w, int h, const bool isNowFullScreen);
  206661. void getBounds (int& x, int& y, int& w, int& h, const bool global) const;
  206662. void getBounds (int& x, int& y, int& w, int& h) const;
  206663. int getScreenX() const;
  206664. int getScreenY() const;
  206665. void relativePositionToGlobal (int& x, int& y);
  206666. void globalPositionToRelative (int& x, int& y);
  206667. void setMinimised (bool shouldBeMinimised);
  206668. bool isMinimised() const;
  206669. void setFullScreen (bool shouldBeFullScreen);
  206670. bool isFullScreen() const;
  206671. bool contains (int x, int y, bool trueIfInAChildWindow) const;
  206672. const BorderSize getFrameSize() const;
  206673. bool setAlwaysOnTop (bool alwaysOnTop);
  206674. void toFront (bool makeActiveWindow);
  206675. void toBehind (ComponentPeer* other);
  206676. void setIcon (const Image& newIcon);
  206677. const StringArray getAvailableRenderingEngines() throw();
  206678. int getCurrentRenderingEngine() throw();
  206679. void setCurrentRenderingEngine (int index) throw();
  206680. virtual void redirectMouseDown (NSEvent* ev);
  206681. virtual void redirectMouseUp (NSEvent* ev);
  206682. virtual void redirectMouseDrag (NSEvent* ev);
  206683. virtual void redirectMouseMove (NSEvent* ev);
  206684. virtual void redirectMouseEnter (NSEvent* ev);
  206685. virtual void redirectMouseExit (NSEvent* ev);
  206686. virtual void redirectMouseWheel (NSEvent* ev);
  206687. bool handleKeyEvent (NSEvent* ev, bool isKeyDown);
  206688. virtual bool redirectKeyDown (NSEvent* ev);
  206689. virtual bool redirectKeyUp (NSEvent* ev);
  206690. virtual void redirectModKeyChange (NSEvent* ev);
  206691. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  206692. virtual bool redirectPerformKeyEquivalent (NSEvent* ev);
  206693. #endif
  206694. virtual BOOL sendDragCallback (int type, id <NSDraggingInfo> sender);
  206695. virtual bool isOpaque();
  206696. virtual void drawRect (NSRect r);
  206697. virtual bool canBecomeKeyWindow();
  206698. virtual bool windowShouldClose();
  206699. virtual void redirectMovedOrResized();
  206700. virtual void viewMovedToWindow();
  206701. virtual NSRect constrainRect (NSRect r);
  206702. static void showArrowCursorIfNeeded();
  206703. virtual void viewFocusGain();
  206704. virtual void viewFocusLoss();
  206705. bool isFocused() const;
  206706. void grabFocus();
  206707. void textInputRequired (int x, int y);
  206708. void repaint (int x, int y, int w, int h);
  206709. void performAnyPendingRepaintsNow();
  206710. juce_UseDebuggingNewOperator
  206711. NSWindow* window;
  206712. JuceNSView* view;
  206713. bool isSharedWindow, fullScreen, insideDrawRect, usingCoreGraphics, recursiveToFrontCall;
  206714. };
  206715. END_JUCE_NAMESPACE
  206716. @implementation JuceNSView
  206717. - (JuceNSView*) initWithOwner: (NSViewComponentPeer*) owner_
  206718. withFrame: (NSRect) frame
  206719. {
  206720. [super initWithFrame: frame];
  206721. owner = owner_;
  206722. notificationCenter = [NSNotificationCenter defaultCenter];
  206723. [notificationCenter addObserver: self
  206724. selector: @selector (frameChanged:)
  206725. name: NSViewFrameDidChangeNotification
  206726. object: self];
  206727. if (! owner_->isSharedWindow)
  206728. {
  206729. [notificationCenter addObserver: self
  206730. selector: @selector (frameChanged:)
  206731. name: NSWindowDidMoveNotification
  206732. object: owner_->window];
  206733. }
  206734. [self registerForDraggedTypes: [self getSupportedDragTypes]];
  206735. return self;
  206736. }
  206737. - (void) dealloc
  206738. {
  206739. [notificationCenter removeObserver: self];
  206740. [super dealloc];
  206741. }
  206742. - (void) drawRect: (NSRect) r
  206743. {
  206744. if (owner != 0)
  206745. owner->drawRect (r);
  206746. }
  206747. - (BOOL) isOpaque
  206748. {
  206749. return owner == 0 || owner->isOpaque();
  206750. }
  206751. - (void) mouseDown: (NSEvent*) ev
  206752. {
  206753. // In some host situations, the host will stop modal loops from working
  206754. // correctly if they're called from a mouse event, so we'll trigger
  206755. // the event asynchronously..
  206756. if (JUCEApplication::getInstance() == 0)
  206757. [self performSelectorOnMainThread: @selector (asyncMouseDown:)
  206758. withObject: ev
  206759. waitUntilDone: NO];
  206760. else
  206761. [self asyncMouseDown: ev];
  206762. }
  206763. - (void) asyncMouseDown: (NSEvent*) ev
  206764. {
  206765. if (owner != 0)
  206766. owner->redirectMouseDown (ev);
  206767. }
  206768. - (void) mouseUp: (NSEvent*) ev
  206769. {
  206770. // In some host situations, the host will stop modal loops from working
  206771. // correctly if they're called from a mouse event, so we'll trigger
  206772. // the event asynchronously..
  206773. if (JUCEApplication::getInstance() == 0)
  206774. [self performSelectorOnMainThread: @selector (asyncMouseUp:)
  206775. withObject: ev
  206776. waitUntilDone: NO];
  206777. else
  206778. [self asyncMouseUp: ev];
  206779. }
  206780. - (void) asyncMouseUp: (NSEvent*) ev
  206781. {
  206782. if (owner != 0)
  206783. owner->redirectMouseUp (ev);
  206784. }
  206785. - (void) mouseDragged: (NSEvent*) ev
  206786. {
  206787. if (owner != 0)
  206788. owner->redirectMouseDrag (ev);
  206789. }
  206790. - (void) mouseMoved: (NSEvent*) ev
  206791. {
  206792. if (owner != 0)
  206793. owner->redirectMouseMove (ev);
  206794. }
  206795. - (void) mouseEntered: (NSEvent*) ev
  206796. {
  206797. if (owner != 0)
  206798. owner->redirectMouseEnter (ev);
  206799. }
  206800. - (void) mouseExited: (NSEvent*) ev
  206801. {
  206802. if (owner != 0)
  206803. owner->redirectMouseExit (ev);
  206804. }
  206805. - (void) rightMouseDown: (NSEvent*) ev
  206806. {
  206807. [self mouseDown: ev];
  206808. }
  206809. - (void) rightMouseDragged: (NSEvent*) ev
  206810. {
  206811. [self mouseDragged: ev];
  206812. }
  206813. - (void) rightMouseUp: (NSEvent*) ev
  206814. {
  206815. [self mouseUp: ev];
  206816. }
  206817. - (void) otherMouseDown: (NSEvent*) ev
  206818. {
  206819. [self mouseDown: ev];
  206820. }
  206821. - (void) otherMouseDragged: (NSEvent*) ev
  206822. {
  206823. [self mouseDragged: ev];
  206824. }
  206825. - (void) otherMouseUp: (NSEvent*) ev
  206826. {
  206827. [self mouseUp: ev];
  206828. }
  206829. - (void) scrollWheel: (NSEvent*) ev
  206830. {
  206831. if (owner != 0)
  206832. owner->redirectMouseWheel (ev);
  206833. }
  206834. - (BOOL) acceptsFirstMouse: (NSEvent*) ev
  206835. {
  206836. return YES;
  206837. }
  206838. - (void) frameChanged: (NSNotification*) n
  206839. {
  206840. if (owner != 0)
  206841. owner->redirectMovedOrResized();
  206842. }
  206843. - (void) viewDidMoveToWindow
  206844. {
  206845. if (owner != 0)
  206846. owner->viewMovedToWindow();
  206847. }
  206848. - (void) asyncRepaint: (id) rect
  206849. {
  206850. NSRect* r = (NSRect*) [((NSData*) rect) bytes];
  206851. [self setNeedsDisplayInRect: *r];
  206852. }
  206853. - (void) keyDown: (NSEvent*) ev
  206854. {
  206855. if (owner == 0 || ! owner->redirectKeyDown (ev))
  206856. [super keyDown: ev];
  206857. }
  206858. - (void) keyUp: (NSEvent*) ev
  206859. {
  206860. if (owner == 0 || ! owner->redirectKeyUp (ev))
  206861. [super keyUp: ev];
  206862. }
  206863. - (void) flagsChanged: (NSEvent*) ev
  206864. {
  206865. if (owner != 0)
  206866. owner->redirectModKeyChange (ev);
  206867. }
  206868. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  206869. - (BOOL) performKeyEquivalent: (NSEvent*) ev
  206870. {
  206871. if (owner != 0 && owner->redirectPerformKeyEquivalent (ev))
  206872. return true;
  206873. return [super performKeyEquivalent: ev];
  206874. }
  206875. #endif
  206876. - (BOOL) becomeFirstResponder
  206877. {
  206878. if (owner != 0)
  206879. owner->viewFocusGain();
  206880. return true;
  206881. }
  206882. - (BOOL) resignFirstResponder
  206883. {
  206884. if (owner != 0)
  206885. owner->viewFocusLoss();
  206886. return true;
  206887. }
  206888. - (BOOL) acceptsFirstResponder
  206889. {
  206890. return owner != 0 && owner->canBecomeKeyWindow();
  206891. }
  206892. - (NSArray*) getSupportedDragTypes
  206893. {
  206894. return [NSArray arrayWithObjects: NSFilenamesPboardType, /*NSFilesPromisePboardType, NSStringPboardType,*/ nil];
  206895. }
  206896. - (BOOL) sendDragCallback: (int) type sender: (id <NSDraggingInfo>) sender
  206897. {
  206898. return owner != 0 && owner->sendDragCallback (type, sender);
  206899. }
  206900. - (NSDragOperation) draggingEntered: (id <NSDraggingInfo>) sender
  206901. {
  206902. if ([self sendDragCallback: 0 sender: sender])
  206903. return NSDragOperationCopy | NSDragOperationMove | NSDragOperationGeneric;
  206904. else
  206905. return NSDragOperationNone;
  206906. }
  206907. - (NSDragOperation) draggingUpdated: (id <NSDraggingInfo>) sender
  206908. {
  206909. if ([self sendDragCallback: 0 sender: sender])
  206910. return NSDragOperationCopy | NSDragOperationMove | NSDragOperationGeneric;
  206911. else
  206912. return NSDragOperationNone;
  206913. }
  206914. - (void) draggingEnded: (id <NSDraggingInfo>) sender
  206915. {
  206916. [self sendDragCallback: 1 sender: sender];
  206917. }
  206918. - (void) draggingExited: (id <NSDraggingInfo>) sender
  206919. {
  206920. [self sendDragCallback: 1 sender: sender];
  206921. }
  206922. - (BOOL) prepareForDragOperation: (id <NSDraggingInfo>) sender
  206923. {
  206924. return YES;
  206925. }
  206926. - (BOOL) performDragOperation: (id <NSDraggingInfo>) sender
  206927. {
  206928. return [self sendDragCallback: 2 sender: sender];
  206929. }
  206930. - (void) concludeDragOperation: (id <NSDraggingInfo>) sender
  206931. {
  206932. }
  206933. @end
  206934. @implementation JuceNSWindow
  206935. - (void) setOwner: (NSViewComponentPeer*) owner_
  206936. {
  206937. owner = owner_;
  206938. isZooming = false;
  206939. }
  206940. - (BOOL) canBecomeKeyWindow
  206941. {
  206942. return owner != 0 && owner->canBecomeKeyWindow();
  206943. }
  206944. - (void) becomeKeyWindow
  206945. {
  206946. [super becomeKeyWindow];
  206947. if (owner != 0)
  206948. owner->grabFocus();
  206949. }
  206950. - (BOOL) windowShouldClose: (id) window
  206951. {
  206952. return owner == 0 || owner->windowShouldClose();
  206953. }
  206954. - (NSRect) constrainFrameRect: (NSRect) frameRect toScreen: (NSScreen*) screen
  206955. {
  206956. if (owner != 0)
  206957. frameRect = owner->constrainRect (frameRect);
  206958. return frameRect;
  206959. }
  206960. - (NSSize) windowWillResize: (NSWindow*) window toSize: (NSSize) proposedFrameSize
  206961. {
  206962. if (isZooming)
  206963. return proposedFrameSize;
  206964. NSRect frameRect = [self frame];
  206965. frameRect.origin.y -= proposedFrameSize.height - frameRect.size.height;
  206966. frameRect.size = proposedFrameSize;
  206967. if (owner != 0)
  206968. frameRect = owner->constrainRect (frameRect);
  206969. return frameRect.size;
  206970. }
  206971. - (void) zoom: (id) sender
  206972. {
  206973. isZooming = true;
  206974. [super zoom: sender];
  206975. isZooming = false;
  206976. }
  206977. - (void) windowWillMove: (NSNotification*) notification
  206978. {
  206979. if (JUCE_NAMESPACE::Component::getCurrentlyModalComponent() != 0
  206980. && owner->getComponent()->isCurrentlyBlockedByAnotherModalComponent()
  206981. && (owner->getStyleFlags() & JUCE_NAMESPACE::ComponentPeer::windowHasTitleBar) != 0)
  206982. JUCE_NAMESPACE::Component::getCurrentlyModalComponent()->inputAttemptWhenModal();
  206983. }
  206984. @end
  206985. BEGIN_JUCE_NAMESPACE
  206986. static ComponentPeer* currentlyFocusedPeer = 0;
  206987. static VoidArray keysCurrentlyDown;
  206988. bool KeyPress::isKeyCurrentlyDown (const int keyCode) throw()
  206989. {
  206990. if (keysCurrentlyDown.contains ((void*) keyCode))
  206991. return true;
  206992. if (keyCode >= 'A' && keyCode <= 'Z'
  206993. && keysCurrentlyDown.contains ((void*) (int) CharacterFunctions::toLowerCase ((tchar) keyCode)))
  206994. return true;
  206995. if (keyCode >= 'a' && keyCode <= 'z'
  206996. && keysCurrentlyDown.contains ((void*) (int) CharacterFunctions::toUpperCase ((tchar) keyCode)))
  206997. return true;
  206998. return false;
  206999. }
  207000. static int getKeyCodeFromEvent (NSEvent* ev)
  207001. {
  207002. const String unmodified (nsStringToJuce ([ev charactersIgnoringModifiers]));
  207003. int keyCode = unmodified[0];
  207004. if (keyCode == 0x19) // (backwards-tab)
  207005. keyCode = '\t';
  207006. else if (keyCode == 0x03) // (enter)
  207007. keyCode = '\r';
  207008. return keyCode;
  207009. }
  207010. static int currentModifiers = 0;
  207011. static void updateModifiers (NSEvent* e)
  207012. {
  207013. int m = currentModifiers & ~(ModifierKeys::shiftModifier | ModifierKeys::ctrlModifier
  207014. | ModifierKeys::altModifier | ModifierKeys::commandModifier);
  207015. if (([e modifierFlags] & NSShiftKeyMask) != 0)
  207016. m |= ModifierKeys::shiftModifier;
  207017. if (([e modifierFlags] & NSControlKeyMask) != 0)
  207018. m |= ModifierKeys::ctrlModifier;
  207019. if (([e modifierFlags] & NSAlternateKeyMask) != 0)
  207020. m |= ModifierKeys::altModifier;
  207021. if (([e modifierFlags] & NSCommandKeyMask) != 0)
  207022. m |= ModifierKeys::commandModifier;
  207023. currentModifiers = m;
  207024. }
  207025. static void updateKeysDown (NSEvent* ev, bool isKeyDown)
  207026. {
  207027. updateModifiers (ev);
  207028. int keyCode = getKeyCodeFromEvent (ev);
  207029. if (keyCode != 0)
  207030. {
  207031. if (isKeyDown)
  207032. keysCurrentlyDown.addIfNotAlreadyThere ((void*) keyCode);
  207033. else
  207034. keysCurrentlyDown.removeValue ((void*) keyCode);
  207035. }
  207036. }
  207037. const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw()
  207038. {
  207039. return ModifierKeys (currentModifiers);
  207040. }
  207041. void ModifierKeys::updateCurrentModifiers() throw()
  207042. {
  207043. currentModifierFlags = currentModifiers;
  207044. }
  207045. static int64 getMouseTime (NSEvent* e)
  207046. {
  207047. return (Time::currentTimeMillis() - Time::getMillisecondCounter())
  207048. + (int64) ([e timestamp] * 1000.0);
  207049. }
  207050. static void getMousePos (NSEvent* e, NSView* view, int& x, int& y)
  207051. {
  207052. NSPoint p = [view convertPoint: [e locationInWindow] fromView: nil];
  207053. x = roundToInt (p.x);
  207054. y = roundToInt ([view frame].size.height - p.y);
  207055. }
  207056. static int getModifierForButtonNumber (const NSInteger num)
  207057. {
  207058. return num == 0 ? ModifierKeys::leftButtonModifier
  207059. : (num == 1 ? ModifierKeys::rightButtonModifier
  207060. : (num == 2 ? ModifierKeys::middleButtonModifier : 0));
  207061. }
  207062. NSViewComponentPeer::NSViewComponentPeer (Component* const component_,
  207063. const int windowStyleFlags,
  207064. NSView* viewToAttachTo)
  207065. : ComponentPeer (component_, windowStyleFlags),
  207066. window (0),
  207067. view (0),
  207068. isSharedWindow (viewToAttachTo != 0),
  207069. fullScreen (false),
  207070. insideDrawRect (false),
  207071. #if USE_COREGRAPHICS_RENDERING
  207072. usingCoreGraphics (true),
  207073. #else
  207074. usingCoreGraphics (false),
  207075. #endif
  207076. recursiveToFrontCall (false)
  207077. {
  207078. NSRect r;
  207079. r.origin.x = 0;
  207080. r.origin.y = 0;
  207081. r.size.width = (float) component->getWidth();
  207082. r.size.height = (float) component->getHeight();
  207083. view = [[JuceNSView alloc] initWithOwner: this withFrame: r];
  207084. [view setPostsFrameChangedNotifications: YES];
  207085. if (isSharedWindow)
  207086. {
  207087. window = [viewToAttachTo window];
  207088. [viewToAttachTo addSubview: view];
  207089. setVisible (component->isVisible());
  207090. }
  207091. else
  207092. {
  207093. r.origin.x = (float) component->getX();
  207094. r.origin.y = (float) component->getY();
  207095. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - (r.origin.y + r.size.height);
  207096. unsigned int style = 0;
  207097. if ((windowStyleFlags & windowHasTitleBar) == 0)
  207098. style = NSBorderlessWindowMask;
  207099. else
  207100. style = NSTitledWindowMask;
  207101. if ((windowStyleFlags & windowHasMinimiseButton) != 0)
  207102. style |= NSMiniaturizableWindowMask;
  207103. if ((windowStyleFlags & windowHasCloseButton) != 0)
  207104. style |= NSClosableWindowMask;
  207105. if ((windowStyleFlags & windowIsResizable) != 0)
  207106. style |= NSResizableWindowMask;
  207107. window = [[JuceNSWindow alloc] initWithContentRect: r
  207108. styleMask: style
  207109. backing: NSBackingStoreBuffered
  207110. defer: YES];
  207111. [((JuceNSWindow*) window) setOwner: this];
  207112. [window orderOut: nil];
  207113. [window setDelegate: (JuceNSWindow*) window];
  207114. [window setOpaque: component->isOpaque()];
  207115. [window setHasShadow: ((windowStyleFlags & windowHasDropShadow) != 0)];
  207116. if (component->isAlwaysOnTop())
  207117. [window setLevel: NSFloatingWindowLevel];
  207118. [window setContentView: view];
  207119. [window setAutodisplay: YES];
  207120. [window setAcceptsMouseMovedEvents: YES];
  207121. // We'll both retain and also release this on closing because plugin hosts can unexpectedly
  207122. // close the window for us, and also tend to get cause trouble if setReleasedWhenClosed is NO.
  207123. [window setReleasedWhenClosed: YES];
  207124. [window retain];
  207125. [window setExcludedFromWindowsMenu: (windowStyleFlags & windowIsTemporary) != 0];
  207126. [window setIgnoresMouseEvents: (windowStyleFlags & windowIgnoresMouseClicks) != 0];
  207127. }
  207128. setTitle (component->getName());
  207129. }
  207130. NSViewComponentPeer::~NSViewComponentPeer()
  207131. {
  207132. view->owner = 0;
  207133. [view removeFromSuperview];
  207134. [view release];
  207135. if (! isSharedWindow)
  207136. {
  207137. [((JuceNSWindow*) window) setOwner: 0];
  207138. [window close];
  207139. [window release];
  207140. }
  207141. }
  207142. void* NSViewComponentPeer::getNativeHandle() const
  207143. {
  207144. return view;
  207145. }
  207146. void NSViewComponentPeer::setVisible (bool shouldBeVisible)
  207147. {
  207148. if (isSharedWindow)
  207149. {
  207150. [view setHidden: ! shouldBeVisible];
  207151. }
  207152. else
  207153. {
  207154. if (shouldBeVisible)
  207155. {
  207156. [window orderFront: nil];
  207157. handleBroughtToFront();
  207158. }
  207159. else
  207160. {
  207161. [window orderOut: nil];
  207162. }
  207163. }
  207164. }
  207165. void NSViewComponentPeer::setTitle (const String& title)
  207166. {
  207167. const ScopedAutoReleasePool pool;
  207168. if (! isSharedWindow)
  207169. [window setTitle: juceStringToNS (title)];
  207170. }
  207171. void NSViewComponentPeer::setPosition (int x, int y)
  207172. {
  207173. setBounds (x, y, component->getWidth(), component->getHeight(), false);
  207174. }
  207175. void NSViewComponentPeer::setSize (int w, int h)
  207176. {
  207177. setBounds (component->getX(), component->getY(), w, h, false);
  207178. }
  207179. void NSViewComponentPeer::setBounds (int x, int y, int w, int h, const bool isNowFullScreen)
  207180. {
  207181. fullScreen = isNowFullScreen;
  207182. w = jmax (0, w);
  207183. h = jmax (0, h);
  207184. NSRect r;
  207185. r.origin.x = (float) x;
  207186. r.origin.y = (float) y;
  207187. r.size.width = (float) w;
  207188. r.size.height = (float) h;
  207189. if (isSharedWindow)
  207190. {
  207191. r.origin.y = [[view superview] frame].size.height - (r.origin.y + r.size.height);
  207192. if ([view frame].size.width != r.size.width
  207193. || [view frame].size.height != r.size.height)
  207194. [view setNeedsDisplay: true];
  207195. [view setFrame: r];
  207196. }
  207197. else
  207198. {
  207199. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - (r.origin.y + r.size.height);
  207200. [window setFrame: [window frameRectForContentRect: r]
  207201. display: true];
  207202. }
  207203. }
  207204. void NSViewComponentPeer::getBounds (int& x, int& y, int& w, int& h, const bool global) const
  207205. {
  207206. NSRect r = [view frame];
  207207. if (global && [view window] != 0)
  207208. {
  207209. r = [view convertRect: r toView: nil];
  207210. NSRect wr = [[view window] frame];
  207211. r.origin.x += wr.origin.x;
  207212. r.origin.y += wr.origin.y;
  207213. y = (int) ([[[NSScreen screens] objectAtIndex:0] frame].size.height - r.origin.y - r.size.height);
  207214. }
  207215. else
  207216. {
  207217. y = (int) ([[view superview] frame].size.height - r.origin.y - r.size.height);
  207218. }
  207219. x = (int) r.origin.x;
  207220. w = (int) r.size.width;
  207221. h = (int) r.size.height;
  207222. }
  207223. void NSViewComponentPeer::getBounds (int& x, int& y, int& w, int& h) const
  207224. {
  207225. getBounds (x, y, w, h, ! isSharedWindow);
  207226. }
  207227. int NSViewComponentPeer::getScreenX() const
  207228. {
  207229. int x, y, w, h;
  207230. getBounds (x, y, w, h, true);
  207231. return x;
  207232. }
  207233. int NSViewComponentPeer::getScreenY() const
  207234. {
  207235. int x, y, w, h;
  207236. getBounds (x, y, w, h, true);
  207237. return y;
  207238. }
  207239. void NSViewComponentPeer::relativePositionToGlobal (int& x, int& y)
  207240. {
  207241. int wx, wy, ww, wh;
  207242. getBounds (wx, wy, ww, wh, true);
  207243. x += wx;
  207244. y += wy;
  207245. }
  207246. void NSViewComponentPeer::globalPositionToRelative (int& x, int& y)
  207247. {
  207248. int wx, wy, ww, wh;
  207249. getBounds (wx, wy, ww, wh, true);
  207250. x -= wx;
  207251. y -= wy;
  207252. }
  207253. NSRect NSViewComponentPeer::constrainRect (NSRect r)
  207254. {
  207255. if (constrainer != 0)
  207256. {
  207257. NSRect current = [window frame];
  207258. current.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - current.origin.y - current.size.height;
  207259. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - r.origin.y - r.size.height;
  207260. Rectangle<int> pos ((int) r.origin.x, (int) r.origin.y,
  207261. (int) r.size.width, (int) r.size.height);
  207262. Rectangle<int> original ((int) current.origin.x, (int) current.origin.y,
  207263. (int) current.size.width, (int) current.size.height);
  207264. constrainer->checkBounds (pos, original,
  207265. Desktop::getInstance().getAllMonitorDisplayAreas().getBounds(),
  207266. pos.getY() != original.getY() && pos.getBottom() == original.getBottom(),
  207267. pos.getX() != original.getX() && pos.getRight() == original.getRight(),
  207268. pos.getY() == original.getY() && pos.getBottom() != original.getBottom(),
  207269. pos.getX() == original.getX() && pos.getRight() != original.getRight());
  207270. r.origin.x = pos.getX();
  207271. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - r.size.height - pos.getY();
  207272. r.size.width = pos.getWidth();
  207273. r.size.height = pos.getHeight();
  207274. }
  207275. return r;
  207276. }
  207277. void NSViewComponentPeer::setMinimised (bool shouldBeMinimised)
  207278. {
  207279. if (! isSharedWindow)
  207280. {
  207281. if (shouldBeMinimised)
  207282. [window miniaturize: nil];
  207283. else
  207284. [window deminiaturize: nil];
  207285. }
  207286. }
  207287. bool NSViewComponentPeer::isMinimised() const
  207288. {
  207289. return window != 0 && [window isMiniaturized];
  207290. }
  207291. void NSViewComponentPeer::setFullScreen (bool shouldBeFullScreen)
  207292. {
  207293. if (! isSharedWindow)
  207294. {
  207295. Rectangle<int> r (lastNonFullscreenBounds);
  207296. setMinimised (false);
  207297. if (fullScreen != shouldBeFullScreen)
  207298. {
  207299. if (shouldBeFullScreen && (getStyleFlags() & windowHasTitleBar) != 0)
  207300. {
  207301. fullScreen = true;
  207302. [window performZoom: nil];
  207303. }
  207304. else
  207305. {
  207306. if (shouldBeFullScreen)
  207307. r = Desktop::getInstance().getMainMonitorArea();
  207308. // (can't call the component's setBounds method because that'll reset our fullscreen flag)
  207309. if (r != getComponent()->getBounds() && ! r.isEmpty())
  207310. setBounds (r.getX(), r.getY(), r.getWidth(), r.getHeight(), shouldBeFullScreen);
  207311. }
  207312. }
  207313. }
  207314. }
  207315. bool NSViewComponentPeer::isFullScreen() const
  207316. {
  207317. return fullScreen;
  207318. }
  207319. bool NSViewComponentPeer::contains (int x, int y, bool trueIfInAChildWindow) const
  207320. {
  207321. if (((unsigned int) x) >= (unsigned int) component->getWidth()
  207322. || ((unsigned int) y) >= (unsigned int) component->getHeight())
  207323. return false;
  207324. NSPoint p;
  207325. p.x = (float) x;
  207326. p.y = (float) y;
  207327. NSView* v = [view hitTest: p];
  207328. if (trueIfInAChildWindow)
  207329. return v != nil;
  207330. return v == view;
  207331. }
  207332. const BorderSize NSViewComponentPeer::getFrameSize() const
  207333. {
  207334. BorderSize b;
  207335. if (! isSharedWindow)
  207336. {
  207337. NSRect v = [view convertRect: [view frame] toView: nil];
  207338. NSRect w = [window frame];
  207339. b.setTop ((int) (w.size.height - (v.origin.y + v.size.height)));
  207340. b.setBottom ((int) v.origin.y);
  207341. b.setLeft ((int) v.origin.x);
  207342. b.setRight ((int) (w.size.width - (v.origin.x + v.size.width)));
  207343. }
  207344. return b;
  207345. }
  207346. bool NSViewComponentPeer::setAlwaysOnTop (bool alwaysOnTop)
  207347. {
  207348. if (! isSharedWindow)
  207349. {
  207350. [window setLevel: alwaysOnTop ? NSFloatingWindowLevel
  207351. : NSNormalWindowLevel];
  207352. }
  207353. return true;
  207354. }
  207355. void NSViewComponentPeer::toFront (bool makeActiveWindow)
  207356. {
  207357. if (isSharedWindow)
  207358. {
  207359. [[view superview] addSubview: view
  207360. positioned: NSWindowAbove
  207361. relativeTo: nil];
  207362. }
  207363. if (window != 0 && component->isVisible())
  207364. {
  207365. if (makeActiveWindow)
  207366. [window makeKeyAndOrderFront: nil];
  207367. else
  207368. [window orderFront: nil];
  207369. if (! recursiveToFrontCall)
  207370. {
  207371. recursiveToFrontCall = true;
  207372. handleBroughtToFront();
  207373. recursiveToFrontCall = false;
  207374. }
  207375. }
  207376. }
  207377. void NSViewComponentPeer::toBehind (ComponentPeer* other)
  207378. {
  207379. NSViewComponentPeer* o = (NSViewComponentPeer*) other;
  207380. if (isSharedWindow)
  207381. {
  207382. [[view superview] addSubview: view
  207383. positioned: NSWindowBelow
  207384. relativeTo: o->view];
  207385. }
  207386. else
  207387. {
  207388. [window orderWindow: NSWindowBelow
  207389. relativeTo: o->window != 0 ? [o->window windowNumber]
  207390. : nil ];
  207391. }
  207392. }
  207393. void NSViewComponentPeer::setIcon (const Image& /*newIcon*/)
  207394. {
  207395. // to do..
  207396. }
  207397. void NSViewComponentPeer::viewFocusGain()
  207398. {
  207399. if (currentlyFocusedPeer != this)
  207400. {
  207401. if (ComponentPeer::isValidPeer (currentlyFocusedPeer))
  207402. currentlyFocusedPeer->handleFocusLoss();
  207403. currentlyFocusedPeer = this;
  207404. handleFocusGain();
  207405. }
  207406. }
  207407. void NSViewComponentPeer::viewFocusLoss()
  207408. {
  207409. if (currentlyFocusedPeer == this)
  207410. {
  207411. currentlyFocusedPeer = 0;
  207412. handleFocusLoss();
  207413. }
  207414. }
  207415. void juce_HandleProcessFocusChange()
  207416. {
  207417. keysCurrentlyDown.clear();
  207418. if (NSViewComponentPeer::isValidPeer (currentlyFocusedPeer))
  207419. {
  207420. if (Process::isForegroundProcess())
  207421. {
  207422. currentlyFocusedPeer->handleFocusGain();
  207423. ComponentPeer::bringModalComponentToFront();
  207424. }
  207425. else
  207426. {
  207427. currentlyFocusedPeer->handleFocusLoss();
  207428. // turn kiosk mode off if we lose focus..
  207429. Desktop::getInstance().setKioskModeComponent (0);
  207430. }
  207431. }
  207432. }
  207433. bool NSViewComponentPeer::isFocused() const
  207434. {
  207435. return isSharedWindow ? this == currentlyFocusedPeer
  207436. : (window != 0 && [window isKeyWindow]);
  207437. }
  207438. void NSViewComponentPeer::grabFocus()
  207439. {
  207440. if (window != 0)
  207441. {
  207442. [window makeKeyWindow];
  207443. [window makeFirstResponder: view];
  207444. viewFocusGain();
  207445. }
  207446. }
  207447. void NSViewComponentPeer::textInputRequired (int /*x*/, int /*y*/)
  207448. {
  207449. }
  207450. bool NSViewComponentPeer::handleKeyEvent (NSEvent* ev, bool isKeyDown)
  207451. {
  207452. String unicode (nsStringToJuce ([ev characters]));
  207453. String unmodified (nsStringToJuce ([ev charactersIgnoringModifiers]));
  207454. int keyCode = getKeyCodeFromEvent (ev);
  207455. //DBG ("unicode: " + unicode + " " + String::toHexString ((int) unicode[0]));
  207456. //DBG ("unmodified: " + unmodified + " " + String::toHexString ((int) unmodified[0]));
  207457. if (unicode.isNotEmpty() || keyCode != 0)
  207458. {
  207459. if (isKeyDown)
  207460. {
  207461. bool used = false;
  207462. while (unicode.length() > 0)
  207463. {
  207464. juce_wchar textCharacter = unicode[0];
  207465. unicode = unicode.substring (1);
  207466. if (([ev modifierFlags] & NSCommandKeyMask) != 0)
  207467. textCharacter = 0;
  207468. used = handleKeyUpOrDown (true) || used;
  207469. used = handleKeyPress (keyCode, textCharacter) || used;
  207470. }
  207471. return used;
  207472. }
  207473. else
  207474. {
  207475. if (handleKeyUpOrDown (false))
  207476. return true;
  207477. }
  207478. }
  207479. return false;
  207480. }
  207481. bool NSViewComponentPeer::redirectKeyDown (NSEvent* ev)
  207482. {
  207483. updateKeysDown (ev, true);
  207484. bool used = handleKeyEvent (ev, true);
  207485. if (([ev modifierFlags] & NSCommandKeyMask) != 0)
  207486. {
  207487. // for command keys, the key-up event is thrown away, so simulate one..
  207488. updateKeysDown (ev, false);
  207489. used = (isValidPeer (this) && handleKeyEvent (ev, false)) || used;
  207490. }
  207491. // (If we're running modally, don't allow unused keystrokes to be passed
  207492. // along to other blocked views..)
  207493. if (Component::getCurrentlyModalComponent() != 0)
  207494. used = true;
  207495. return used;
  207496. }
  207497. bool NSViewComponentPeer::redirectKeyUp (NSEvent* ev)
  207498. {
  207499. updateKeysDown (ev, false);
  207500. return handleKeyEvent (ev, false)
  207501. || Component::getCurrentlyModalComponent() != 0;
  207502. }
  207503. void NSViewComponentPeer::redirectModKeyChange (NSEvent* ev)
  207504. {
  207505. keysCurrentlyDown.clear();
  207506. handleKeyUpOrDown (true);
  207507. updateModifiers (ev);
  207508. handleModifierKeysChange();
  207509. }
  207510. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  207511. bool NSViewComponentPeer::redirectPerformKeyEquivalent (NSEvent* ev)
  207512. {
  207513. if ([ev type] == NSKeyDown)
  207514. return redirectKeyDown (ev);
  207515. else if ([ev type] == NSKeyUp)
  207516. return redirectKeyUp (ev);
  207517. return false;
  207518. }
  207519. #endif
  207520. void NSViewComponentPeer::redirectMouseDown (NSEvent* ev)
  207521. {
  207522. updateModifiers (ev);
  207523. currentModifiers |= getModifierForButtonNumber ([ev buttonNumber]);
  207524. int x, y;
  207525. getMousePos (ev, view, x, y);
  207526. handleMouseDown (x, y, getMouseTime (ev));
  207527. }
  207528. void NSViewComponentPeer::redirectMouseUp (NSEvent* ev)
  207529. {
  207530. const int oldMods = currentModifiers;
  207531. updateModifiers (ev);
  207532. currentModifiers &= ~getModifierForButtonNumber ([ev buttonNumber]);
  207533. int x, y;
  207534. getMousePos (ev, view, x, y);
  207535. handleMouseUp (oldMods, x, y, getMouseTime (ev));
  207536. showArrowCursorIfNeeded();
  207537. }
  207538. void NSViewComponentPeer::redirectMouseDrag (NSEvent* ev)
  207539. {
  207540. updateModifiers (ev);
  207541. currentModifiers |= getModifierForButtonNumber ([ev buttonNumber]);
  207542. int x, y;
  207543. getMousePos (ev, view, x, y);
  207544. handleMouseDrag (x, y, getMouseTime (ev));
  207545. }
  207546. void NSViewComponentPeer::redirectMouseMove (NSEvent* ev)
  207547. {
  207548. updateModifiers (ev);
  207549. int x, y;
  207550. getMousePos (ev, view, x, y);
  207551. handleMouseMove (x, y, getMouseTime (ev));
  207552. showArrowCursorIfNeeded();
  207553. }
  207554. void NSViewComponentPeer::redirectMouseEnter (NSEvent* ev)
  207555. {
  207556. updateModifiers (ev);
  207557. int x, y;
  207558. getMousePos (ev, view, x, y);
  207559. handleMouseEnter (x, y, getMouseTime (ev));
  207560. }
  207561. void NSViewComponentPeer::redirectMouseExit (NSEvent* ev)
  207562. {
  207563. updateModifiers (ev);
  207564. int x, y;
  207565. getMousePos (ev, view, x, y);
  207566. handleMouseExit (x, y, getMouseTime (ev));
  207567. }
  207568. void NSViewComponentPeer::redirectMouseWheel (NSEvent* ev)
  207569. {
  207570. updateModifiers (ev);
  207571. handleMouseWheel (roundToInt ([ev deltaX] * 10.0f),
  207572. roundToInt ([ev deltaY] * 10.0f),
  207573. getMouseTime (ev));
  207574. }
  207575. void NSViewComponentPeer::showArrowCursorIfNeeded()
  207576. {
  207577. if (Component::getComponentUnderMouse() == 0)
  207578. {
  207579. int mx, my;
  207580. Desktop::getInstance().getMousePosition (mx, my);
  207581. if (Desktop::getInstance().findComponentAt (mx, my) == 0)
  207582. [[NSCursor arrowCursor] set];
  207583. }
  207584. }
  207585. BOOL NSViewComponentPeer::sendDragCallback (int type, id <NSDraggingInfo> sender)
  207586. {
  207587. NSString* bestType
  207588. = [[sender draggingPasteboard] availableTypeFromArray: [view getSupportedDragTypes]];
  207589. if (bestType == nil)
  207590. return false;
  207591. NSPoint p = [view convertPoint: [sender draggingLocation] fromView: nil];
  207592. int x = (int) p.x;
  207593. int y = (int) ([view frame].size.height - p.y);
  207594. StringArray files;
  207595. id list = [[sender draggingPasteboard] propertyListForType: bestType];
  207596. if (list == nil)
  207597. return false;
  207598. if ([list isKindOfClass: [NSArray class]])
  207599. {
  207600. NSArray* items = (NSArray*) list;
  207601. for (unsigned int i = 0; i < [items count]; ++i)
  207602. files.add (nsStringToJuce ((NSString*) [items objectAtIndex: i]));
  207603. }
  207604. if (files.size() == 0)
  207605. return false;
  207606. if (type == 0)
  207607. handleFileDragMove (files, x, y);
  207608. else if (type == 1)
  207609. handleFileDragExit (files);
  207610. else if (type == 2)
  207611. handleFileDragDrop (files, x, y);
  207612. return true;
  207613. }
  207614. bool NSViewComponentPeer::isOpaque()
  207615. {
  207616. if (! getComponent()->isValidComponent())
  207617. return true;
  207618. return getComponent()->isOpaque();
  207619. }
  207620. void NSViewComponentPeer::drawRect (NSRect r)
  207621. {
  207622. if (r.size.width < 1.0f || r.size.height < 1.0f)
  207623. return;
  207624. CGContextRef cg = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
  207625. if (! component->isOpaque())
  207626. CGContextClearRect (cg, CGContextGetClipBoundingBox (cg));
  207627. #if USE_COREGRAPHICS_RENDERING
  207628. if (usingCoreGraphics)
  207629. {
  207630. CoreGraphicsContext context (cg, (float) [view frame].size.height);
  207631. insideDrawRect = true;
  207632. handlePaint (context);
  207633. insideDrawRect = false;
  207634. }
  207635. else
  207636. #endif
  207637. {
  207638. Image temp (getComponent()->isOpaque() ? Image::RGB : Image::ARGB,
  207639. (int) (r.size.width + 0.5f),
  207640. (int) (r.size.height + 0.5f),
  207641. ! getComponent()->isOpaque());
  207642. LowLevelGraphicsSoftwareRenderer context (temp);
  207643. context.setOrigin (-roundToInt (r.origin.x),
  207644. -roundToInt ([view frame].size.height - (r.origin.y + r.size.height)));
  207645. const NSRect* rects = 0;
  207646. NSInteger numRects = 0;
  207647. [view getRectsBeingDrawn: &rects count: &numRects];
  207648. RectangleList clip;
  207649. for (int i = 0; i < numRects; ++i)
  207650. {
  207651. clip.addWithoutMerging (Rectangle<int> (roundToInt (rects[i].origin.x),
  207652. roundToInt ([view frame].size.height - (rects[i].origin.y + rects[i].size.height)),
  207653. roundToInt (rects[i].size.width),
  207654. roundToInt (rects[i].size.height)));
  207655. }
  207656. if (context.clipToRectangleList (clip))
  207657. {
  207658. insideDrawRect = true;
  207659. handlePaint (context);
  207660. insideDrawRect = false;
  207661. CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB();
  207662. CGImageRef image = CoreGraphicsImage::createImage (temp, false, colourSpace);
  207663. CGColorSpaceRelease (colourSpace);
  207664. CGContextDrawImage (cg, CGRectMake (r.origin.x, r.origin.y, temp.getWidth(), temp.getHeight()), image);
  207665. CGImageRelease (image);
  207666. }
  207667. }
  207668. }
  207669. const StringArray NSViewComponentPeer::getAvailableRenderingEngines() throw()
  207670. {
  207671. StringArray s;
  207672. s.add ("Software Renderer");
  207673. #if USE_COREGRAPHICS_RENDERING
  207674. s.add ("CoreGraphics Renderer");
  207675. #endif
  207676. return s;
  207677. }
  207678. int NSViewComponentPeer::getCurrentRenderingEngine() throw()
  207679. {
  207680. return usingCoreGraphics ? 1 : 0;
  207681. }
  207682. void NSViewComponentPeer::setCurrentRenderingEngine (int index) throw()
  207683. {
  207684. #if USE_COREGRAPHICS_RENDERING
  207685. if (usingCoreGraphics != (index > 0))
  207686. {
  207687. usingCoreGraphics = index > 0;
  207688. [view setNeedsDisplay: true];
  207689. }
  207690. #endif
  207691. }
  207692. bool NSViewComponentPeer::canBecomeKeyWindow()
  207693. {
  207694. return (getStyleFlags() & JUCE_NAMESPACE::ComponentPeer::windowIgnoresKeyPresses) == 0;
  207695. }
  207696. bool NSViewComponentPeer::windowShouldClose()
  207697. {
  207698. if (! isValidPeer (this))
  207699. return YES;
  207700. handleUserClosingWindow();
  207701. return NO;
  207702. }
  207703. void NSViewComponentPeer::redirectMovedOrResized()
  207704. {
  207705. handleMovedOrResized();
  207706. }
  207707. void NSViewComponentPeer::viewMovedToWindow()
  207708. {
  207709. if (isSharedWindow)
  207710. window = [view window];
  207711. }
  207712. void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars)
  207713. {
  207714. // Very annoyingly, this function has to use the old SetSystemUIMode function,
  207715. // which is in Carbon.framework. But, because there's no Cocoa equivalent, it
  207716. // is apparently still available in 64-bit apps..
  207717. if (enableOrDisable)
  207718. {
  207719. SetSystemUIMode (kUIModeAllSuppressed, allowMenusAndBars ? kUIOptionAutoShowMenuBar : 0);
  207720. kioskModeComponent->setBounds (Desktop::getInstance().getMainMonitorArea (false));
  207721. }
  207722. else
  207723. {
  207724. SetSystemUIMode (kUIModeNormal, 0);
  207725. }
  207726. }
  207727. class AsyncRepaintMessage : public CallbackMessage
  207728. {
  207729. public:
  207730. NSViewComponentPeer* const peer;
  207731. const Rectangle<int> rect;
  207732. AsyncRepaintMessage (NSViewComponentPeer* const peer_, const Rectangle<int>& rect_)
  207733. : peer (peer_), rect (rect_)
  207734. {
  207735. }
  207736. void messageCallback()
  207737. {
  207738. if (ComponentPeer::isValidPeer (peer))
  207739. peer->repaint (rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight());
  207740. }
  207741. };
  207742. void NSViewComponentPeer::repaint (int x, int y, int w, int h)
  207743. {
  207744. if (insideDrawRect)
  207745. {
  207746. (new AsyncRepaintMessage (this, Rectangle<int> (x, y, w, h)))->post();
  207747. }
  207748. else
  207749. {
  207750. [view setNeedsDisplayInRect: NSMakeRect ((float) x, (float) ([view frame].size.height - (y + h)),
  207751. (float) w, (float) h)];
  207752. }
  207753. }
  207754. void NSViewComponentPeer::performAnyPendingRepaintsNow()
  207755. {
  207756. [view displayIfNeeded];
  207757. }
  207758. ComponentPeer* Component::createNewPeer (int styleFlags, void* windowToAttachTo)
  207759. {
  207760. return new NSViewComponentPeer (this, styleFlags, (NSView*) windowToAttachTo);
  207761. }
  207762. Image* juce_createIconForFile (const File& file)
  207763. {
  207764. const ScopedAutoReleasePool pool;
  207765. NSImage* image = [[NSWorkspace sharedWorkspace] iconForFile: juceStringToNS (file.getFullPathName())];
  207766. CoreGraphicsImage* result = new CoreGraphicsImage (Image::ARGB, (int) [image size].width, (int) [image size].height, true);
  207767. [NSGraphicsContext saveGraphicsState];
  207768. [NSGraphicsContext setCurrentContext: [NSGraphicsContext graphicsContextWithGraphicsPort: result->context flipped: false]];
  207769. [image drawAtPoint: NSMakePoint (0, 0)
  207770. fromRect: NSMakeRect (0, 0, [image size].width, [image size].height)
  207771. operation: NSCompositeSourceOver fraction: 1.0f];
  207772. [[NSGraphicsContext currentContext] flushGraphics];
  207773. [NSGraphicsContext restoreGraphicsState];
  207774. return result;
  207775. }
  207776. const int KeyPress::spaceKey = ' ';
  207777. const int KeyPress::returnKey = 0x0d;
  207778. const int KeyPress::escapeKey = 0x1b;
  207779. const int KeyPress::backspaceKey = 0x7f;
  207780. const int KeyPress::leftKey = NSLeftArrowFunctionKey;
  207781. const int KeyPress::rightKey = NSRightArrowFunctionKey;
  207782. const int KeyPress::upKey = NSUpArrowFunctionKey;
  207783. const int KeyPress::downKey = NSDownArrowFunctionKey;
  207784. const int KeyPress::pageUpKey = NSPageUpFunctionKey;
  207785. const int KeyPress::pageDownKey = NSPageDownFunctionKey;
  207786. const int KeyPress::endKey = NSEndFunctionKey;
  207787. const int KeyPress::homeKey = NSHomeFunctionKey;
  207788. const int KeyPress::deleteKey = NSDeleteFunctionKey;
  207789. const int KeyPress::insertKey = -1;
  207790. const int KeyPress::tabKey = 9;
  207791. const int KeyPress::F1Key = NSF1FunctionKey;
  207792. const int KeyPress::F2Key = NSF2FunctionKey;
  207793. const int KeyPress::F3Key = NSF3FunctionKey;
  207794. const int KeyPress::F4Key = NSF4FunctionKey;
  207795. const int KeyPress::F5Key = NSF5FunctionKey;
  207796. const int KeyPress::F6Key = NSF6FunctionKey;
  207797. const int KeyPress::F7Key = NSF7FunctionKey;
  207798. const int KeyPress::F8Key = NSF8FunctionKey;
  207799. const int KeyPress::F9Key = NSF9FunctionKey;
  207800. const int KeyPress::F10Key = NSF10FunctionKey;
  207801. const int KeyPress::F11Key = NSF1FunctionKey;
  207802. const int KeyPress::F12Key = NSF12FunctionKey;
  207803. const int KeyPress::F13Key = NSF13FunctionKey;
  207804. const int KeyPress::F14Key = NSF14FunctionKey;
  207805. const int KeyPress::F15Key = NSF15FunctionKey;
  207806. const int KeyPress::F16Key = NSF16FunctionKey;
  207807. const int KeyPress::numberPad0 = 0x30020;
  207808. const int KeyPress::numberPad1 = 0x30021;
  207809. const int KeyPress::numberPad2 = 0x30022;
  207810. const int KeyPress::numberPad3 = 0x30023;
  207811. const int KeyPress::numberPad4 = 0x30024;
  207812. const int KeyPress::numberPad5 = 0x30025;
  207813. const int KeyPress::numberPad6 = 0x30026;
  207814. const int KeyPress::numberPad7 = 0x30027;
  207815. const int KeyPress::numberPad8 = 0x30028;
  207816. const int KeyPress::numberPad9 = 0x30029;
  207817. const int KeyPress::numberPadAdd = 0x3002a;
  207818. const int KeyPress::numberPadSubtract = 0x3002b;
  207819. const int KeyPress::numberPadMultiply = 0x3002c;
  207820. const int KeyPress::numberPadDivide = 0x3002d;
  207821. const int KeyPress::numberPadSeparator = 0x3002e;
  207822. const int KeyPress::numberPadDecimalPoint = 0x3002f;
  207823. const int KeyPress::numberPadEquals = 0x30030;
  207824. const int KeyPress::numberPadDelete = 0x30031;
  207825. const int KeyPress::playKey = 0x30000;
  207826. const int KeyPress::stopKey = 0x30001;
  207827. const int KeyPress::fastForwardKey = 0x30002;
  207828. const int KeyPress::rewindKey = 0x30003;
  207829. #endif
  207830. /*** End of inlined file: juce_mac_NSViewComponentPeer.mm ***/
  207831. /*** Start of inlined file: juce_mac_MouseCursor.mm ***/
  207832. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  207833. // compiled on its own).
  207834. #if JUCE_INCLUDED_FILE
  207835. #if JUCE_MAC
  207836. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw()
  207837. {
  207838. NSImage* im = CoreGraphicsImage::createNSImage (image);
  207839. NSCursor* c = [[NSCursor alloc] initWithImage: im
  207840. hotSpot: NSMakePoint (hotspotX, hotspotY)];
  207841. [im release];
  207842. return (void*) c;
  207843. }
  207844. static void* juce_cursorFromData (const unsigned char* data, const size_t size, float hx, float hy) throw()
  207845. {
  207846. ScopedPointer <Image> im (ImageFileFormat::loadFrom ((const char*) data, (int) size));
  207847. jassert (im != 0);
  207848. if (im == 0)
  207849. return 0;
  207850. return juce_createMouseCursorFromImage (*im,
  207851. (int) (hx * im->getWidth()),
  207852. (int) (hy * im->getHeight()));
  207853. }
  207854. static void* juce_cursorFromWebKitFile (const char* filename, float hx, float hy)
  207855. {
  207856. File f ("/System/Library/Frameworks/WebKit.framework/Frameworks/WebCore.framework/Resources");
  207857. MemoryBlock mb;
  207858. if (f.getChildFile (filename).loadFileAsData (mb))
  207859. return juce_cursorFromData ((const unsigned char*) mb.getData(), mb.getSize(), hx, hy);
  207860. return 0;
  207861. }
  207862. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw()
  207863. {
  207864. const ScopedAutoReleasePool pool;
  207865. NSCursor* c = 0;
  207866. switch (type)
  207867. {
  207868. case MouseCursor::NormalCursor:
  207869. c = [NSCursor arrowCursor];
  207870. break;
  207871. case MouseCursor::NoCursor:
  207872. {
  207873. Image blank (Image::ARGB, 8, 8, true);
  207874. return juce_createMouseCursorFromImage (blank, 0, 0);
  207875. }
  207876. case MouseCursor::DraggingHandCursor:
  207877. c = [NSCursor openHandCursor];
  207878. break;
  207879. case MouseCursor::CopyingCursor:
  207880. return juce_cursorFromWebKitFile ("copyCursor.png", 0, 0);
  207881. case MouseCursor::WaitCursor:
  207882. c = [NSCursor arrowCursor]; // avoid this on the mac, let the OS provide the beachball
  207883. break;
  207884. //return juce_cursorFromWebKitFile ("waitCursor.png", 0.5f, 0.5f);
  207885. case MouseCursor::IBeamCursor:
  207886. c = [NSCursor IBeamCursor];
  207887. break;
  207888. case MouseCursor::PointingHandCursor:
  207889. c = [NSCursor pointingHandCursor];
  207890. break;
  207891. case MouseCursor::LeftRightResizeCursor:
  207892. c = [NSCursor resizeLeftRightCursor];
  207893. break;
  207894. case MouseCursor::LeftEdgeResizeCursor:
  207895. c = [NSCursor resizeLeftCursor];
  207896. break;
  207897. case MouseCursor::RightEdgeResizeCursor:
  207898. c = [NSCursor resizeRightCursor];
  207899. break;
  207900. case MouseCursor::UpDownResizeCursor:
  207901. case MouseCursor::TopEdgeResizeCursor:
  207902. case MouseCursor::BottomEdgeResizeCursor:
  207903. return juce_cursorFromWebKitFile ("northSouthResizeCursor.png", 0.5f, 0.5f);
  207904. case MouseCursor::TopLeftCornerResizeCursor:
  207905. case MouseCursor::BottomRightCornerResizeCursor:
  207906. return juce_cursorFromWebKitFile ("northWestSouthEastResizeCursor.png", 0.5f, 0.5f);
  207907. case MouseCursor::TopRightCornerResizeCursor:
  207908. case MouseCursor::BottomLeftCornerResizeCursor:
  207909. return juce_cursorFromWebKitFile ("northEastSouthWestResizeCursor.png", 0.5f, 0.5f);
  207910. case MouseCursor::UpDownLeftRightResizeCursor:
  207911. return juce_cursorFromWebKitFile ("moveCursor.png", 0.5f, 0.5f);
  207912. case MouseCursor::CrosshairCursor:
  207913. c = [NSCursor crosshairCursor];
  207914. break;
  207915. }
  207916. [c retain];
  207917. return (void*) c;
  207918. }
  207919. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw()
  207920. {
  207921. NSCursor* c = (NSCursor*) cursorHandle;
  207922. [c release];
  207923. }
  207924. void MouseCursor::showInAllWindows() const throw()
  207925. {
  207926. showInWindow (0);
  207927. }
  207928. void MouseCursor::showInWindow (ComponentPeer*) const throw()
  207929. {
  207930. NSCursor* const c = (NSCursor*) getHandle();
  207931. [c set];
  207932. }
  207933. #else
  207934. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw() { return 0; }
  207935. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw() { return 0; }
  207936. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw() {}
  207937. void MouseCursor::showInAllWindows() const throw() {}
  207938. void MouseCursor::showInWindow (ComponentPeer*) const throw() {}
  207939. #endif
  207940. #endif
  207941. /*** End of inlined file: juce_mac_MouseCursor.mm ***/
  207942. /*** Start of inlined file: juce_mac_NSViewComponent.mm ***/
  207943. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  207944. // compiled on its own).
  207945. #if JUCE_INCLUDED_FILE
  207946. class NSViewComponentInternal : public ComponentMovementWatcher
  207947. {
  207948. Component* const owner;
  207949. NSViewComponentPeer* currentPeer;
  207950. bool wasShowing;
  207951. public:
  207952. NSView* const view;
  207953. NSViewComponentInternal (NSView* const view_, Component* const owner_)
  207954. : ComponentMovementWatcher (owner_),
  207955. owner (owner_),
  207956. currentPeer (0),
  207957. wasShowing (false),
  207958. view (view_)
  207959. {
  207960. [view_ retain];
  207961. if (owner_->isShowing())
  207962. componentPeerChanged();
  207963. }
  207964. ~NSViewComponentInternal()
  207965. {
  207966. [view removeFromSuperview];
  207967. [view release];
  207968. }
  207969. void componentMovedOrResized (Component& comp, bool wasMoved, bool wasResized)
  207970. {
  207971. ComponentMovementWatcher::componentMovedOrResized (comp, wasMoved, wasResized);
  207972. // The ComponentMovementWatcher version of this method avoids calling
  207973. // us when the top-level comp is resized, but for an NSView we need to know this
  207974. // because with inverted co-ords, we need to update the position even if the
  207975. // top-left pos hasn't changed
  207976. if (comp.isOnDesktop() && wasResized)
  207977. componentMovedOrResized (wasMoved, wasResized);
  207978. }
  207979. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  207980. {
  207981. Component* const topComp = owner->getTopLevelComponent();
  207982. if (topComp->getPeer() != 0)
  207983. {
  207984. int x = 0, y = 0;
  207985. owner->relativePositionToOtherComponent (topComp, x, y);
  207986. NSRect r;
  207987. r.origin.x = (float) x;
  207988. r.origin.y = (float) y;
  207989. r.size.width = (float) owner->getWidth();
  207990. r.size.height = (float) owner->getHeight();
  207991. r.origin.y = [[view superview] frame].size.height - (r.origin.y + r.size.height);
  207992. [view setFrame: r];
  207993. }
  207994. }
  207995. void componentPeerChanged()
  207996. {
  207997. NSViewComponentPeer* const peer = dynamic_cast <NSViewComponentPeer*> (owner->getPeer());
  207998. if (currentPeer != peer)
  207999. {
  208000. [view removeFromSuperview];
  208001. currentPeer = peer;
  208002. if (peer != 0)
  208003. {
  208004. [peer->view addSubview: view];
  208005. componentMovedOrResized (false, false);
  208006. }
  208007. }
  208008. [view setHidden: ! owner->isShowing()];
  208009. }
  208010. void componentVisibilityChanged (Component&)
  208011. {
  208012. componentPeerChanged();
  208013. }
  208014. juce_UseDebuggingNewOperator
  208015. private:
  208016. NSViewComponentInternal (const NSViewComponentInternal&);
  208017. const NSViewComponentInternal& operator= (const NSViewComponentInternal&);
  208018. };
  208019. NSViewComponent::NSViewComponent()
  208020. {
  208021. }
  208022. NSViewComponent::~NSViewComponent()
  208023. {
  208024. }
  208025. void NSViewComponent::setView (void* view)
  208026. {
  208027. if (view != getView())
  208028. {
  208029. if (view != 0)
  208030. info = new NSViewComponentInternal ((NSView*) view, this);
  208031. else
  208032. info = 0;
  208033. }
  208034. }
  208035. void* NSViewComponent::getView() const
  208036. {
  208037. return info == 0 ? 0 : info->view;
  208038. }
  208039. void NSViewComponent::paint (Graphics& g)
  208040. {
  208041. }
  208042. #endif
  208043. /*** End of inlined file: juce_mac_NSViewComponent.mm ***/
  208044. /*** Start of inlined file: juce_mac_AppleRemote.mm ***/
  208045. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  208046. // compiled on its own).
  208047. #if JUCE_INCLUDED_FILE
  208048. AppleRemoteDevice::AppleRemoteDevice()
  208049. : device (0),
  208050. queue (0),
  208051. remoteId (0)
  208052. {
  208053. }
  208054. AppleRemoteDevice::~AppleRemoteDevice()
  208055. {
  208056. stop();
  208057. }
  208058. static io_object_t getAppleRemoteDevice()
  208059. {
  208060. CFMutableDictionaryRef dict = IOServiceMatching ("AppleIRController");
  208061. io_iterator_t iter = 0;
  208062. io_object_t iod = 0;
  208063. if (IOServiceGetMatchingServices (kIOMasterPortDefault, dict, &iter) == kIOReturnSuccess
  208064. && iter != 0)
  208065. {
  208066. iod = IOIteratorNext (iter);
  208067. }
  208068. IOObjectRelease (iter);
  208069. return iod;
  208070. }
  208071. static bool createAppleRemoteInterface (io_object_t iod, void** device)
  208072. {
  208073. jassert (*device == 0);
  208074. io_name_t classname;
  208075. if (IOObjectGetClass (iod, classname) == kIOReturnSuccess)
  208076. {
  208077. IOCFPlugInInterface** cfPlugInInterface = 0;
  208078. SInt32 score = 0;
  208079. if (IOCreatePlugInInterfaceForService (iod,
  208080. kIOHIDDeviceUserClientTypeID,
  208081. kIOCFPlugInInterfaceID,
  208082. &cfPlugInInterface,
  208083. &score) == kIOReturnSuccess)
  208084. {
  208085. HRESULT hr = (*cfPlugInInterface)->QueryInterface (cfPlugInInterface,
  208086. CFUUIDGetUUIDBytes (kIOHIDDeviceInterfaceID),
  208087. device);
  208088. (void) hr;
  208089. (*cfPlugInInterface)->Release (cfPlugInInterface);
  208090. }
  208091. }
  208092. return *device != 0;
  208093. }
  208094. bool AppleRemoteDevice::start (const bool inExclusiveMode)
  208095. {
  208096. if (queue != 0)
  208097. return true;
  208098. stop();
  208099. bool result = false;
  208100. io_object_t iod = getAppleRemoteDevice();
  208101. if (iod != 0)
  208102. {
  208103. if (createAppleRemoteInterface (iod, &device) && open (inExclusiveMode))
  208104. result = true;
  208105. else
  208106. stop();
  208107. IOObjectRelease (iod);
  208108. }
  208109. return result;
  208110. }
  208111. void AppleRemoteDevice::stop()
  208112. {
  208113. if (queue != 0)
  208114. {
  208115. (*(IOHIDQueueInterface**) queue)->stop ((IOHIDQueueInterface**) queue);
  208116. (*(IOHIDQueueInterface**) queue)->dispose ((IOHIDQueueInterface**) queue);
  208117. (*(IOHIDQueueInterface**) queue)->Release ((IOHIDQueueInterface**) queue);
  208118. queue = 0;
  208119. }
  208120. if (device != 0)
  208121. {
  208122. (*(IOHIDDeviceInterface**) device)->close ((IOHIDDeviceInterface**) device);
  208123. (*(IOHIDDeviceInterface**) device)->Release ((IOHIDDeviceInterface**) device);
  208124. device = 0;
  208125. }
  208126. }
  208127. bool AppleRemoteDevice::isActive() const
  208128. {
  208129. return queue != 0;
  208130. }
  208131. static void appleRemoteQueueCallback (void* const target, const IOReturn result, void*, void*)
  208132. {
  208133. if (result == kIOReturnSuccess)
  208134. ((AppleRemoteDevice*) target)->handleCallbackInternal();
  208135. }
  208136. bool AppleRemoteDevice::open (const bool openInExclusiveMode)
  208137. {
  208138. Array <int> cookies;
  208139. CFArrayRef elements;
  208140. IOHIDDeviceInterface122** const device122 = (IOHIDDeviceInterface122**) device;
  208141. if ((*device122)->copyMatchingElements (device122, 0, &elements) != kIOReturnSuccess)
  208142. return false;
  208143. for (int i = 0; i < CFArrayGetCount (elements); ++i)
  208144. {
  208145. CFDictionaryRef element = (CFDictionaryRef) CFArrayGetValueAtIndex (elements, i);
  208146. // get the cookie
  208147. CFTypeRef object = CFDictionaryGetValue (element, CFSTR (kIOHIDElementCookieKey));
  208148. if (object == 0 || CFGetTypeID (object) != CFNumberGetTypeID())
  208149. continue;
  208150. long number;
  208151. if (! CFNumberGetValue ((CFNumberRef) object, kCFNumberLongType, &number))
  208152. continue;
  208153. cookies.add ((int) number);
  208154. }
  208155. CFRelease (elements);
  208156. if ((*(IOHIDDeviceInterface**) device)
  208157. ->open ((IOHIDDeviceInterface**) device,
  208158. openInExclusiveMode ? kIOHIDOptionsTypeSeizeDevice
  208159. : kIOHIDOptionsTypeNone) == KERN_SUCCESS)
  208160. {
  208161. queue = (*(IOHIDDeviceInterface**) device)->allocQueue ((IOHIDDeviceInterface**) device);
  208162. if (queue != 0)
  208163. {
  208164. (*(IOHIDQueueInterface**) queue)->create ((IOHIDQueueInterface**) queue, 0, 12);
  208165. for (int i = 0; i < cookies.size(); ++i)
  208166. {
  208167. IOHIDElementCookie cookie = (IOHIDElementCookie) cookies.getUnchecked(i);
  208168. (*(IOHIDQueueInterface**) queue)->addElement ((IOHIDQueueInterface**) queue, cookie, 0);
  208169. }
  208170. CFRunLoopSourceRef eventSource;
  208171. if ((*(IOHIDQueueInterface**) queue)
  208172. ->createAsyncEventSource ((IOHIDQueueInterface**) queue, &eventSource) == KERN_SUCCESS)
  208173. {
  208174. if ((*(IOHIDQueueInterface**) queue)->setEventCallout ((IOHIDQueueInterface**) queue,
  208175. appleRemoteQueueCallback, this, 0) == KERN_SUCCESS)
  208176. {
  208177. CFRunLoopAddSource (CFRunLoopGetCurrent(), eventSource, kCFRunLoopDefaultMode);
  208178. (*(IOHIDQueueInterface**) queue)->start ((IOHIDQueueInterface**) queue);
  208179. return true;
  208180. }
  208181. }
  208182. }
  208183. }
  208184. return false;
  208185. }
  208186. void AppleRemoteDevice::handleCallbackInternal()
  208187. {
  208188. int totalValues = 0;
  208189. AbsoluteTime nullTime = { 0, 0 };
  208190. char cookies [12];
  208191. int numCookies = 0;
  208192. while (numCookies < numElementsInArray (cookies))
  208193. {
  208194. IOHIDEventStruct e;
  208195. if ((*(IOHIDQueueInterface**) queue)->getNextEvent ((IOHIDQueueInterface**) queue, &e, nullTime, 0) != kIOReturnSuccess)
  208196. break;
  208197. if ((int) e.elementCookie == 19)
  208198. {
  208199. remoteId = e.value;
  208200. buttonPressed (switched, false);
  208201. }
  208202. else
  208203. {
  208204. totalValues += e.value;
  208205. cookies [numCookies++] = (char) (pointer_sized_int) e.elementCookie;
  208206. }
  208207. }
  208208. cookies [numCookies++] = 0;
  208209. //DBG (String::toHexString ((uint8*) cookies, numCookies, 1) + " " + String (totalValues));
  208210. static const char buttonPatterns[] =
  208211. {
  208212. 0x1f, 0x14, 0x12, 0x1f, 0x14, 0x12, 0,
  208213. 0x1f, 0x15, 0x12, 0x1f, 0x15, 0x12, 0,
  208214. 0x1f, 0x1d, 0x1c, 0x12, 0,
  208215. 0x1f, 0x1e, 0x1c, 0x12, 0,
  208216. 0x1f, 0x16, 0x12, 0x1f, 0x16, 0x12, 0,
  208217. 0x1f, 0x17, 0x12, 0x1f, 0x17, 0x12, 0,
  208218. 0x1f, 0x12, 0x04, 0x02, 0,
  208219. 0x1f, 0x12, 0x03, 0x02, 0,
  208220. 0x1f, 0x12, 0x1f, 0x12, 0,
  208221. 0x23, 0x1f, 0x12, 0x23, 0x1f, 0x12, 0,
  208222. 19, 0
  208223. };
  208224. int buttonNum = (int) menuButton;
  208225. int i = 0;
  208226. while (i < numElementsInArray (buttonPatterns))
  208227. {
  208228. if (strcmp (cookies, buttonPatterns + i) == 0)
  208229. {
  208230. buttonPressed ((ButtonType) buttonNum, totalValues > 0);
  208231. break;
  208232. }
  208233. i += (int) strlen (buttonPatterns + i) + 1;
  208234. ++buttonNum;
  208235. }
  208236. }
  208237. #endif
  208238. /*** End of inlined file: juce_mac_AppleRemote.mm ***/
  208239. /*** Start of inlined file: juce_mac_OpenGLComponent.mm ***/
  208240. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  208241. // compiled on its own).
  208242. #if JUCE_INCLUDED_FILE && JUCE_OPENGL
  208243. #if JUCE_MAC
  208244. END_JUCE_NAMESPACE
  208245. #define ThreadSafeNSOpenGLView MakeObjCClassName(ThreadSafeNSOpenGLView)
  208246. @interface ThreadSafeNSOpenGLView : NSOpenGLView
  208247. {
  208248. CriticalSection* contextLock;
  208249. bool needsUpdate;
  208250. }
  208251. - (id) initWithFrame: (NSRect) frameRect pixelFormat: (NSOpenGLPixelFormat*) format;
  208252. - (bool) makeActive;
  208253. - (void) makeInactive;
  208254. - (void) reshape;
  208255. @end
  208256. @implementation ThreadSafeNSOpenGLView
  208257. - (id) initWithFrame: (NSRect) frameRect
  208258. pixelFormat: (NSOpenGLPixelFormat*) format
  208259. {
  208260. contextLock = new CriticalSection();
  208261. self = [super initWithFrame: frameRect pixelFormat: format];
  208262. if (self != nil)
  208263. [[NSNotificationCenter defaultCenter] addObserver: self
  208264. selector: @selector (_surfaceNeedsUpdate:)
  208265. name: NSViewGlobalFrameDidChangeNotification
  208266. object: self];
  208267. return self;
  208268. }
  208269. - (void) dealloc
  208270. {
  208271. [[NSNotificationCenter defaultCenter] removeObserver: self];
  208272. delete contextLock;
  208273. [super dealloc];
  208274. }
  208275. - (bool) makeActive
  208276. {
  208277. const ScopedLock sl (*contextLock);
  208278. if ([self openGLContext] == 0)
  208279. return false;
  208280. [[self openGLContext] makeCurrentContext];
  208281. if (needsUpdate)
  208282. {
  208283. [super update];
  208284. needsUpdate = false;
  208285. }
  208286. return true;
  208287. }
  208288. - (void) makeInactive
  208289. {
  208290. const ScopedLock sl (*contextLock);
  208291. [NSOpenGLContext clearCurrentContext];
  208292. }
  208293. - (void) _surfaceNeedsUpdate: (NSNotification*) notification
  208294. {
  208295. const ScopedLock sl (*contextLock);
  208296. needsUpdate = true;
  208297. }
  208298. - (void) update
  208299. {
  208300. const ScopedLock sl (*contextLock);
  208301. needsUpdate = true;
  208302. }
  208303. - (void) reshape
  208304. {
  208305. const ScopedLock sl (*contextLock);
  208306. needsUpdate = true;
  208307. }
  208308. @end
  208309. BEGIN_JUCE_NAMESPACE
  208310. class WindowedGLContext : public OpenGLContext
  208311. {
  208312. public:
  208313. WindowedGLContext (Component* const component,
  208314. const OpenGLPixelFormat& pixelFormat_,
  208315. NSOpenGLContext* sharedContext)
  208316. : renderContext (0),
  208317. pixelFormat (pixelFormat_)
  208318. {
  208319. jassert (component != 0);
  208320. NSOpenGLPixelFormatAttribute attribs [64];
  208321. int n = 0;
  208322. attribs[n++] = NSOpenGLPFADoubleBuffer;
  208323. attribs[n++] = NSOpenGLPFAAccelerated;
  208324. attribs[n++] = NSOpenGLPFAMPSafe; // NSOpenGLPFAAccelerated, NSOpenGLPFAMultiScreen, NSOpenGLPFASingleRenderer
  208325. attribs[n++] = NSOpenGLPFAColorSize;
  208326. attribs[n++] = (NSOpenGLPixelFormatAttribute) jmax (pixelFormat.redBits,
  208327. pixelFormat.greenBits,
  208328. pixelFormat.blueBits);
  208329. attribs[n++] = NSOpenGLPFAAlphaSize;
  208330. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.alphaBits;
  208331. attribs[n++] = NSOpenGLPFADepthSize;
  208332. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.depthBufferBits;
  208333. attribs[n++] = NSOpenGLPFAStencilSize;
  208334. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.stencilBufferBits;
  208335. attribs[n++] = NSOpenGLPFAAccumSize;
  208336. attribs[n++] = (NSOpenGLPixelFormatAttribute) jmax (pixelFormat.accumulationBufferRedBits,
  208337. pixelFormat.accumulationBufferGreenBits,
  208338. pixelFormat.accumulationBufferBlueBits,
  208339. pixelFormat.accumulationBufferAlphaBits);
  208340. // xxx not sure how to do fullSceneAntiAliasingNumSamples..
  208341. attribs[n++] = NSOpenGLPFASampleBuffers;
  208342. attribs[n++] = (NSOpenGLPixelFormatAttribute) 1;
  208343. attribs[n++] = NSOpenGLPFAClosestPolicy;
  208344. attribs[n++] = NSOpenGLPFANoRecovery;
  208345. attribs[n++] = (NSOpenGLPixelFormatAttribute) 0;
  208346. NSOpenGLPixelFormat* format
  208347. = [[NSOpenGLPixelFormat alloc] initWithAttributes: attribs];
  208348. view = [[ThreadSafeNSOpenGLView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
  208349. pixelFormat: format];
  208350. renderContext = [[[NSOpenGLContext alloc] initWithFormat: format
  208351. shareContext: sharedContext] autorelease];
  208352. const GLint swapInterval = 1;
  208353. [renderContext setValues: &swapInterval forParameter: NSOpenGLCPSwapInterval];
  208354. [view setOpenGLContext: renderContext];
  208355. [renderContext setView: view];
  208356. [format release];
  208357. viewHolder = new NSViewComponentInternal (view, component);
  208358. }
  208359. ~WindowedGLContext()
  208360. {
  208361. makeInactive();
  208362. [renderContext clearDrawable];
  208363. viewHolder = 0;
  208364. }
  208365. bool makeActive() const throw()
  208366. {
  208367. jassert (renderContext != 0);
  208368. [view makeActive];
  208369. return isActive();
  208370. }
  208371. bool makeInactive() const throw()
  208372. {
  208373. [view makeInactive];
  208374. return true;
  208375. }
  208376. bool isActive() const throw()
  208377. {
  208378. return [NSOpenGLContext currentContext] == renderContext;
  208379. }
  208380. const OpenGLPixelFormat getPixelFormat() const { return pixelFormat; }
  208381. void* getRawContext() const throw() { return renderContext; }
  208382. void updateWindowPosition (int x, int y, int w, int h, int outerWindowHeight)
  208383. {
  208384. }
  208385. void swapBuffers()
  208386. {
  208387. [renderContext flushBuffer];
  208388. }
  208389. bool setSwapInterval (const int numFramesPerSwap)
  208390. {
  208391. [renderContext setValues: (const GLint*) &numFramesPerSwap
  208392. forParameter: NSOpenGLCPSwapInterval];
  208393. return true;
  208394. }
  208395. int getSwapInterval() const
  208396. {
  208397. GLint numFrames = 0;
  208398. [renderContext getValues: &numFrames
  208399. forParameter: NSOpenGLCPSwapInterval];
  208400. return numFrames;
  208401. }
  208402. void repaint()
  208403. {
  208404. // we need to invalidate the juce view that holds this gl view, to make it
  208405. // cause a repaint callback
  208406. NSView* v = (NSView*) viewHolder->view;
  208407. NSRect r = [v frame];
  208408. // bit of a bodge here.. if we only invalidate the area of the gl component,
  208409. // it's completely covered by the NSOpenGLView, so the OS throws away the
  208410. // repaint message, thus never causing our paint() callback, and never repainting
  208411. // the comp. So invalidating just a little bit around the edge helps..
  208412. [[v superview] setNeedsDisplayInRect: NSInsetRect (r, -2.0f, -2.0f)];
  208413. }
  208414. void* getNativeWindowHandle() const { return viewHolder->view; }
  208415. juce_UseDebuggingNewOperator
  208416. NSOpenGLContext* renderContext;
  208417. ThreadSafeNSOpenGLView* view;
  208418. private:
  208419. OpenGLPixelFormat pixelFormat;
  208420. ScopedPointer <NSViewComponentInternal> viewHolder;
  208421. WindowedGLContext (const WindowedGLContext&);
  208422. const WindowedGLContext& operator= (const WindowedGLContext&);
  208423. };
  208424. OpenGLContext* OpenGLContext::createContextForWindow (Component* const component,
  208425. const OpenGLPixelFormat& pixelFormat,
  208426. const OpenGLContext* const contextToShareWith)
  208427. {
  208428. ScopedPointer <WindowedGLContext> c (new WindowedGLContext (component, pixelFormat,
  208429. contextToShareWith != 0 ? (NSOpenGLContext*) contextToShareWith->getRawContext() : 0));
  208430. return (c->renderContext != 0) ? c.release() : 0;
  208431. }
  208432. void* OpenGLComponent::getNativeWindowHandle() const
  208433. {
  208434. return context != 0 ? ((WindowedGLContext*) context)->getNativeWindowHandle()
  208435. : 0;
  208436. }
  208437. void juce_glViewport (const int w, const int h)
  208438. {
  208439. glViewport (0, 0, w, h);
  208440. }
  208441. void OpenGLPixelFormat::getAvailablePixelFormats (Component* /*component*/,
  208442. OwnedArray <OpenGLPixelFormat>& results)
  208443. {
  208444. /* GLint attribs [64];
  208445. int n = 0;
  208446. attribs[n++] = AGL_RGBA;
  208447. attribs[n++] = AGL_DOUBLEBUFFER;
  208448. attribs[n++] = AGL_ACCELERATED;
  208449. attribs[n++] = AGL_NO_RECOVERY;
  208450. attribs[n++] = AGL_NONE;
  208451. AGLPixelFormat p = aglChoosePixelFormat (0, 0, attribs);
  208452. while (p != 0)
  208453. {
  208454. OpenGLPixelFormat* const pf = new OpenGLPixelFormat();
  208455. pf->redBits = getAGLAttribute (p, AGL_RED_SIZE);
  208456. pf->greenBits = getAGLAttribute (p, AGL_GREEN_SIZE);
  208457. pf->blueBits = getAGLAttribute (p, AGL_BLUE_SIZE);
  208458. pf->alphaBits = getAGLAttribute (p, AGL_ALPHA_SIZE);
  208459. pf->depthBufferBits = getAGLAttribute (p, AGL_DEPTH_SIZE);
  208460. pf->stencilBufferBits = getAGLAttribute (p, AGL_STENCIL_SIZE);
  208461. pf->accumulationBufferRedBits = getAGLAttribute (p, AGL_ACCUM_RED_SIZE);
  208462. pf->accumulationBufferGreenBits = getAGLAttribute (p, AGL_ACCUM_GREEN_SIZE);
  208463. pf->accumulationBufferBlueBits = getAGLAttribute (p, AGL_ACCUM_BLUE_SIZE);
  208464. pf->accumulationBufferAlphaBits = getAGLAttribute (p, AGL_ACCUM_ALPHA_SIZE);
  208465. results.add (pf);
  208466. p = aglNextPixelFormat (p);
  208467. }*/
  208468. //jassertfalse //xxx can't see how you do this in cocoa!
  208469. }
  208470. #else
  208471. OpenGLContext* OpenGLContext::createContextForWindow (Component* const component,
  208472. const OpenGLPixelFormat& pixelFormat,
  208473. const OpenGLContext* const contextToShareWith)
  208474. {
  208475. return 0;
  208476. }
  208477. void juce_glViewport (const int w, const int h)
  208478. {
  208479. //glViewport (0, 0, w, h);
  208480. }
  208481. #endif
  208482. #endif
  208483. /*** End of inlined file: juce_mac_OpenGLComponent.mm ***/
  208484. /*** Start of inlined file: juce_mac_MainMenu.mm ***/
  208485. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  208486. // compiled on its own).
  208487. #if JUCE_INCLUDED_FILE
  208488. class JuceMainMenuHandler;
  208489. END_JUCE_NAMESPACE
  208490. using namespace JUCE_NAMESPACE;
  208491. #define JuceMenuCallback MakeObjCClassName(JuceMenuCallback)
  208492. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  208493. @interface JuceMenuCallback : NSObject <NSMenuDelegate>
  208494. #else
  208495. @interface JuceMenuCallback : NSObject
  208496. #endif
  208497. {
  208498. JuceMainMenuHandler* owner;
  208499. }
  208500. - (JuceMenuCallback*) initWithOwner: (JuceMainMenuHandler*) owner_;
  208501. - (void) dealloc;
  208502. - (void) menuItemInvoked: (id) menu;
  208503. - (void) menuNeedsUpdate: (NSMenu*) menu;
  208504. @end
  208505. BEGIN_JUCE_NAMESPACE
  208506. class JuceMainMenuHandler : private MenuBarModelListener,
  208507. private DeletedAtShutdown
  208508. {
  208509. public:
  208510. static JuceMainMenuHandler* instance;
  208511. JuceMainMenuHandler()
  208512. : currentModel (0),
  208513. lastUpdateTime (0)
  208514. {
  208515. callback = [[JuceMenuCallback alloc] initWithOwner: this];
  208516. }
  208517. ~JuceMainMenuHandler()
  208518. {
  208519. setMenu (0);
  208520. jassert (instance == this);
  208521. instance = 0;
  208522. [callback release];
  208523. }
  208524. void setMenu (MenuBarModel* const newMenuBarModel)
  208525. {
  208526. if (currentModel != newMenuBarModel)
  208527. {
  208528. if (currentModel != 0)
  208529. currentModel->removeListener (this);
  208530. currentModel = newMenuBarModel;
  208531. if (currentModel != 0)
  208532. currentModel->addListener (this);
  208533. menuBarItemsChanged (0);
  208534. }
  208535. }
  208536. void addSubMenu (NSMenu* parent, const PopupMenu& child,
  208537. const String& name, const int menuId, const int tag)
  208538. {
  208539. NSMenuItem* item = [parent addItemWithTitle: juceStringToNS (name)
  208540. action: nil
  208541. keyEquivalent: @""];
  208542. [item setTag: tag];
  208543. NSMenu* sub = createMenu (child, name, menuId, tag);
  208544. [parent setSubmenu: sub forItem: item];
  208545. [sub setAutoenablesItems: false];
  208546. [sub release];
  208547. }
  208548. void updateSubMenu (NSMenuItem* parentItem, const PopupMenu& menuToCopy,
  208549. const String& name, const int menuId, const int tag)
  208550. {
  208551. [parentItem setTag: tag];
  208552. NSMenu* menu = [parentItem submenu];
  208553. [menu setTitle: juceStringToNS (name)];
  208554. while ([menu numberOfItems] > 0)
  208555. [menu removeItemAtIndex: 0];
  208556. PopupMenu::MenuItemIterator iter (menuToCopy);
  208557. while (iter.next())
  208558. addMenuItem (iter, menu, menuId, tag);
  208559. [menu setAutoenablesItems: false];
  208560. [menu update];
  208561. }
  208562. void menuBarItemsChanged (MenuBarModel*)
  208563. {
  208564. lastUpdateTime = Time::getMillisecondCounter();
  208565. StringArray menuNames;
  208566. if (currentModel != 0)
  208567. menuNames = currentModel->getMenuBarNames();
  208568. NSMenu* menuBar = [NSApp mainMenu];
  208569. while ([menuBar numberOfItems] > 1 + menuNames.size())
  208570. [menuBar removeItemAtIndex: [menuBar numberOfItems] - 1];
  208571. int menuId = 1;
  208572. for (int i = 0; i < menuNames.size(); ++i)
  208573. {
  208574. const PopupMenu menu (currentModel->getMenuForIndex (i, menuNames [i]));
  208575. if (i >= [menuBar numberOfItems] - 1)
  208576. addSubMenu (menuBar, menu, menuNames[i], menuId, i);
  208577. else
  208578. updateSubMenu ([menuBar itemAtIndex: 1 + i], menu, menuNames[i], menuId, i);
  208579. }
  208580. }
  208581. static void flashMenuBar (NSMenu* menu)
  208582. {
  208583. [menu retain];
  208584. const unichar f35Key = NSF35FunctionKey;
  208585. NSString* f35String = [NSString stringWithCharacters: &f35Key length: 1];
  208586. NSMenuItem* item = [[NSMenuItem alloc] initWithTitle: @"x"
  208587. action: nil
  208588. keyEquivalent: f35String];
  208589. [item setTarget: nil];
  208590. [menu insertItem: item atIndex: [menu numberOfItems]];
  208591. [item release];
  208592. NSEvent* f35Event = [NSEvent keyEventWithType: NSKeyDown
  208593. location: NSZeroPoint
  208594. modifierFlags: NSCommandKeyMask
  208595. timestamp: 0
  208596. windowNumber: 0
  208597. context: [NSGraphicsContext currentContext]
  208598. characters: f35String
  208599. charactersIgnoringModifiers: f35String
  208600. isARepeat: NO
  208601. keyCode: 0];
  208602. [menu performKeyEquivalent: f35Event];
  208603. if ([menu indexOfItem: item] >= 0)
  208604. [menu removeItem: item]; // (this throws if the item isn't actually in the menu)
  208605. [menu release];
  208606. }
  208607. static NSMenuItem* findMenuItem (NSMenu* const menu, const ApplicationCommandTarget::InvocationInfo& info)
  208608. {
  208609. for (NSInteger i = [menu numberOfItems]; --i >= 0;)
  208610. {
  208611. NSMenuItem* m = [menu itemAtIndex: i];
  208612. if ([m tag] == info.commandID)
  208613. return m;
  208614. if ([m submenu] != 0)
  208615. {
  208616. NSMenuItem* found = findMenuItem ([m submenu], info);
  208617. if (found != 0)
  208618. return found;
  208619. }
  208620. }
  208621. return 0;
  208622. }
  208623. void menuCommandInvoked (MenuBarModel*, const ApplicationCommandTarget::InvocationInfo& info)
  208624. {
  208625. NSMenuItem* item = findMenuItem ([NSApp mainMenu], info);
  208626. if (item != 0)
  208627. flashMenuBar ([item menu]);
  208628. }
  208629. void updateMenus()
  208630. {
  208631. if (Time::getMillisecondCounter() > lastUpdateTime + 500)
  208632. menuBarItemsChanged (0);
  208633. }
  208634. void invoke (const int commandId, ApplicationCommandManager* const commandManager, const int topLevelIndex) const
  208635. {
  208636. if (currentModel != 0)
  208637. {
  208638. if (commandManager != 0)
  208639. {
  208640. ApplicationCommandTarget::InvocationInfo info (commandId);
  208641. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromMenu;
  208642. commandManager->invoke (info, true);
  208643. }
  208644. currentModel->menuItemSelected (commandId, topLevelIndex);
  208645. }
  208646. }
  208647. MenuBarModel* currentModel;
  208648. uint32 lastUpdateTime;
  208649. void addMenuItem (PopupMenu::MenuItemIterator& iter, NSMenu* menuToAddTo,
  208650. const int topLevelMenuId, const int topLevelIndex)
  208651. {
  208652. NSString* text = juceStringToNS (iter.itemName.upToFirstOccurrenceOf (T("<end>"), false, true));
  208653. if (text == 0)
  208654. text = @"";
  208655. if (iter.isSeparator)
  208656. {
  208657. [menuToAddTo addItem: [NSMenuItem separatorItem]];
  208658. }
  208659. else if (iter.isSectionHeader)
  208660. {
  208661. NSMenuItem* item = [menuToAddTo addItemWithTitle: text
  208662. action: nil
  208663. keyEquivalent: @""];
  208664. [item setEnabled: false];
  208665. }
  208666. else if (iter.subMenu != 0)
  208667. {
  208668. NSMenuItem* item = [menuToAddTo addItemWithTitle: text
  208669. action: nil
  208670. keyEquivalent: @""];
  208671. [item setTag: iter.itemId];
  208672. [item setEnabled: iter.isEnabled];
  208673. NSMenu* sub = createMenu (*iter.subMenu, iter.itemName, topLevelMenuId, topLevelIndex);
  208674. [sub setDelegate: nil];
  208675. [menuToAddTo setSubmenu: sub forItem: item];
  208676. [sub release];
  208677. }
  208678. else
  208679. {
  208680. NSMenuItem* item = [menuToAddTo addItemWithTitle: text
  208681. action: @selector (menuItemInvoked:)
  208682. keyEquivalent: @""];
  208683. [item setTag: iter.itemId];
  208684. [item setEnabled: iter.isEnabled];
  208685. [item setState: iter.isTicked ? NSOnState : NSOffState];
  208686. [item setTarget: (id) callback];
  208687. NSMutableArray* info = [NSMutableArray arrayWithObject: [NSNumber numberWithUnsignedLongLong: (pointer_sized_int) (void*) iter.commandManager]];
  208688. [info addObject: [NSNumber numberWithInt: topLevelIndex]];
  208689. [item setRepresentedObject: info];
  208690. if (iter.commandManager != 0)
  208691. {
  208692. const Array <KeyPress> keyPresses (iter.commandManager->getKeyMappings()
  208693. ->getKeyPressesAssignedToCommand (iter.itemId));
  208694. if (keyPresses.size() > 0)
  208695. {
  208696. const KeyPress& kp = keyPresses.getReference(0);
  208697. juce_wchar key = kp.getTextCharacter();
  208698. if (kp.getKeyCode() == KeyPress::backspaceKey)
  208699. key = NSBackspaceCharacter;
  208700. else if (kp.getKeyCode() == KeyPress::deleteKey)
  208701. key = NSDeleteCharacter;
  208702. else if (key == 0)
  208703. key = (juce_wchar) kp.getKeyCode();
  208704. unsigned int mods = 0;
  208705. if (kp.getModifiers().isShiftDown())
  208706. mods |= NSShiftKeyMask;
  208707. if (kp.getModifiers().isCtrlDown())
  208708. mods |= NSControlKeyMask;
  208709. if (kp.getModifiers().isAltDown())
  208710. mods |= NSAlternateKeyMask;
  208711. if (kp.getModifiers().isCommandDown())
  208712. mods |= NSCommandKeyMask;
  208713. [item setKeyEquivalent: juceStringToNS (String::charToString (key))];
  208714. [item setKeyEquivalentModifierMask: mods];
  208715. }
  208716. }
  208717. }
  208718. }
  208719. JuceMenuCallback* callback;
  208720. private:
  208721. NSMenu* createMenu (const PopupMenu menu,
  208722. const String& menuName,
  208723. const int topLevelMenuId,
  208724. const int topLevelIndex)
  208725. {
  208726. NSMenu* m = [[NSMenu alloc] initWithTitle: juceStringToNS (menuName)];
  208727. [m setAutoenablesItems: false];
  208728. [m setDelegate: callback];
  208729. PopupMenu::MenuItemIterator iter (menu);
  208730. while (iter.next())
  208731. addMenuItem (iter, m, topLevelMenuId, topLevelIndex);
  208732. [m update];
  208733. return m;
  208734. }
  208735. };
  208736. JuceMainMenuHandler* JuceMainMenuHandler::instance = 0;
  208737. END_JUCE_NAMESPACE
  208738. @implementation JuceMenuCallback
  208739. - (JuceMenuCallback*) initWithOwner: (JuceMainMenuHandler*) owner_
  208740. {
  208741. [super init];
  208742. owner = owner_;
  208743. return self;
  208744. }
  208745. - (void) dealloc
  208746. {
  208747. [super dealloc];
  208748. }
  208749. - (void) menuItemInvoked: (id) menu
  208750. {
  208751. NSMenuItem* item = (NSMenuItem*) menu;
  208752. if ([[item representedObject] isKindOfClass: [NSArray class]])
  208753. {
  208754. // 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
  208755. // our own components, which may have wanted to intercept it. So, rather than dispatching directly, we'll feed it back
  208756. // into the focused component and let it trigger the menu item indirectly.
  208757. NSEvent* e = [NSApp currentEvent];
  208758. if ([e type] == NSKeyDown || [e type] == NSKeyUp)
  208759. {
  208760. if (JUCE_NAMESPACE::Component::getCurrentlyFocusedComponent()->isValidComponent())
  208761. {
  208762. JUCE_NAMESPACE::NSViewComponentPeer* peer = dynamic_cast <JUCE_NAMESPACE::NSViewComponentPeer*> (JUCE_NAMESPACE::Component::getCurrentlyFocusedComponent()->getPeer());
  208763. if (peer != 0)
  208764. {
  208765. if ([e type] == NSKeyDown)
  208766. peer->redirectKeyDown (e);
  208767. else
  208768. peer->redirectKeyUp (e);
  208769. return;
  208770. }
  208771. }
  208772. }
  208773. NSArray* info = (NSArray*) [item representedObject];
  208774. owner->invoke ((int) [item tag],
  208775. (ApplicationCommandManager*) (pointer_sized_int)
  208776. [((NSNumber*) [info objectAtIndex: 0]) unsignedLongLongValue],
  208777. (int) [((NSNumber*) [info objectAtIndex: 1]) intValue]);
  208778. }
  208779. }
  208780. - (void) menuNeedsUpdate: (NSMenu*) menu;
  208781. {
  208782. if (JuceMainMenuHandler::instance != 0)
  208783. JuceMainMenuHandler::instance->updateMenus();
  208784. }
  208785. @end
  208786. BEGIN_JUCE_NAMESPACE
  208787. static NSMenu* createStandardAppMenu (NSMenu* menu, const String& appName,
  208788. const PopupMenu* extraItems)
  208789. {
  208790. if (extraItems != 0 && JuceMainMenuHandler::instance != 0 && extraItems->getNumItems() > 0)
  208791. {
  208792. PopupMenu::MenuItemIterator iter (*extraItems);
  208793. while (iter.next())
  208794. JuceMainMenuHandler::instance->addMenuItem (iter, menu, 0, -1);
  208795. [menu addItem: [NSMenuItem separatorItem]];
  208796. }
  208797. NSMenuItem* item;
  208798. // Services...
  208799. item = [[NSMenuItem alloc] initWithTitle: NSLocalizedString (@"Services", nil)
  208800. action: nil keyEquivalent: @""];
  208801. [menu addItem: item];
  208802. [item release];
  208803. NSMenu* servicesMenu = [[NSMenu alloc] initWithTitle: @"Services"];
  208804. [menu setSubmenu: servicesMenu forItem: item];
  208805. [NSApp setServicesMenu: servicesMenu];
  208806. [servicesMenu release];
  208807. [menu addItem: [NSMenuItem separatorItem]];
  208808. // Hide + Show stuff...
  208809. item = [[NSMenuItem alloc] initWithTitle: juceStringToNS ("Hide " + appName)
  208810. action: @selector (hide:) keyEquivalent: @"h"];
  208811. [item setTarget: NSApp];
  208812. [menu addItem: item];
  208813. [item release];
  208814. item = [[NSMenuItem alloc] initWithTitle: NSLocalizedString (@"Hide Others", nil)
  208815. action: @selector (hideOtherApplications:) keyEquivalent: @"h"];
  208816. [item setKeyEquivalentModifierMask: NSCommandKeyMask | NSAlternateKeyMask];
  208817. [item setTarget: NSApp];
  208818. [menu addItem: item];
  208819. [item release];
  208820. item = [[NSMenuItem alloc] initWithTitle: NSLocalizedString (@"Show All", nil)
  208821. action: @selector (unhideAllApplications:) keyEquivalent: @""];
  208822. [item setTarget: NSApp];
  208823. [menu addItem: item];
  208824. [item release];
  208825. [menu addItem: [NSMenuItem separatorItem]];
  208826. // Quit item....
  208827. item = [[NSMenuItem alloc] initWithTitle: juceStringToNS ("Quit " + appName)
  208828. action: @selector (terminate:) keyEquivalent: @"q"];
  208829. [item setTarget: NSApp];
  208830. [menu addItem: item];
  208831. [item release];
  208832. return menu;
  208833. }
  208834. // Since our app has no NIB, this initialises a standard app menu...
  208835. static void rebuildMainMenu (const PopupMenu* extraItems)
  208836. {
  208837. // this can't be used in a plugin!
  208838. jassert (JUCEApplication::getInstance() != 0);
  208839. if (JUCEApplication::getInstance() != 0)
  208840. {
  208841. const ScopedAutoReleasePool pool;
  208842. NSMenu* mainMenu = [[NSMenu alloc] initWithTitle: @"MainMenu"];
  208843. NSMenuItem* item = [mainMenu addItemWithTitle: @"Apple" action: nil keyEquivalent: @""];
  208844. NSMenu* appMenu = [[NSMenu alloc] initWithTitle: @"Apple"];
  208845. [NSApp performSelector: @selector (setAppleMenu:) withObject: appMenu];
  208846. [mainMenu setSubmenu: appMenu forItem: item];
  208847. [NSApp setMainMenu: mainMenu];
  208848. createStandardAppMenu (appMenu, JUCEApplication::getInstance()->getApplicationName(), extraItems);
  208849. [appMenu release];
  208850. [mainMenu release];
  208851. }
  208852. }
  208853. void MenuBarModel::setMacMainMenu (MenuBarModel* newMenuBarModel,
  208854. const PopupMenu* extraAppleMenuItems)
  208855. {
  208856. if (getMacMainMenu() != newMenuBarModel)
  208857. {
  208858. const ScopedAutoReleasePool pool;
  208859. if (newMenuBarModel == 0)
  208860. {
  208861. delete JuceMainMenuHandler::instance;
  208862. jassert (JuceMainMenuHandler::instance == 0); // should be zeroed in the destructor
  208863. jassert (extraAppleMenuItems == 0); // you can't specify some extra items without also supplying a model
  208864. extraAppleMenuItems = 0;
  208865. }
  208866. else
  208867. {
  208868. if (JuceMainMenuHandler::instance == 0)
  208869. JuceMainMenuHandler::instance = new JuceMainMenuHandler();
  208870. JuceMainMenuHandler::instance->setMenu (newMenuBarModel);
  208871. }
  208872. }
  208873. rebuildMainMenu (extraAppleMenuItems);
  208874. if (newMenuBarModel != 0)
  208875. newMenuBarModel->menuItemsChanged();
  208876. }
  208877. MenuBarModel* MenuBarModel::getMacMainMenu()
  208878. {
  208879. return JuceMainMenuHandler::instance != 0
  208880. ? JuceMainMenuHandler::instance->currentModel : 0;
  208881. }
  208882. void initialiseMainMenu()
  208883. {
  208884. if (JUCEApplication::getInstance() != 0) // only needed in an app
  208885. rebuildMainMenu (0);
  208886. }
  208887. #endif
  208888. /*** End of inlined file: juce_mac_MainMenu.mm ***/
  208889. /*** Start of inlined file: juce_mac_FileChooser.mm ***/
  208890. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  208891. // compiled on its own).
  208892. #if JUCE_INCLUDED_FILE
  208893. #if JUCE_MAC
  208894. END_JUCE_NAMESPACE
  208895. using namespace JUCE_NAMESPACE;
  208896. #define JuceFileChooserDelegate MakeObjCClassName(JuceFileChooserDelegate)
  208897. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  208898. @interface JuceFileChooserDelegate : NSObject <NSOpenSavePanelDelegate>
  208899. #else
  208900. @interface JuceFileChooserDelegate : NSObject
  208901. #endif
  208902. {
  208903. StringArray* filters;
  208904. }
  208905. - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_;
  208906. - (void) dealloc;
  208907. - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename;
  208908. @end
  208909. @implementation JuceFileChooserDelegate
  208910. - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_
  208911. {
  208912. [super init];
  208913. filters = filters_;
  208914. return self;
  208915. }
  208916. - (void) dealloc
  208917. {
  208918. delete filters;
  208919. [super dealloc];
  208920. }
  208921. - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename
  208922. {
  208923. const File f (nsStringToJuce (filename));
  208924. for (int i = filters->size(); --i >= 0;)
  208925. if (f.getFileName().matchesWildcard ((*filters)[i], true))
  208926. return true;
  208927. return f.isDirectory();
  208928. }
  208929. @end
  208930. BEGIN_JUCE_NAMESPACE
  208931. void FileChooser::showPlatformDialog (Array<File>& results,
  208932. const String& title,
  208933. const File& currentFileOrDirectory,
  208934. const String& filter,
  208935. bool selectsDirectory,
  208936. bool selectsFiles,
  208937. bool isSaveDialogue,
  208938. bool warnAboutOverwritingExistingFiles,
  208939. bool selectMultipleFiles,
  208940. FilePreviewComponent* extraInfoComponent)
  208941. {
  208942. const ScopedAutoReleasePool pool;
  208943. StringArray* filters = new StringArray();
  208944. filters->addTokens (filter.replaceCharacters (T(",:"), T(";;")), T(";"), 0);
  208945. filters->trim();
  208946. filters->removeEmptyStrings();
  208947. JuceFileChooserDelegate* delegate = [[JuceFileChooserDelegate alloc] initWithFilters: filters];
  208948. [delegate autorelease];
  208949. NSSavePanel* panel = isSaveDialogue ? [NSSavePanel savePanel]
  208950. : [NSOpenPanel openPanel];
  208951. [panel setTitle: juceStringToNS (title)];
  208952. if (! isSaveDialogue)
  208953. {
  208954. NSOpenPanel* openPanel = (NSOpenPanel*) panel;
  208955. [openPanel setCanChooseDirectories: selectsDirectory];
  208956. [openPanel setCanChooseFiles: selectsFiles];
  208957. [openPanel setAllowsMultipleSelection: selectMultipleFiles];
  208958. }
  208959. [panel setDelegate: delegate];
  208960. if (isSaveDialogue || selectsDirectory)
  208961. [panel setCanCreateDirectories: YES];
  208962. String directory, filename;
  208963. if (currentFileOrDirectory.isDirectory())
  208964. {
  208965. directory = currentFileOrDirectory.getFullPathName();
  208966. }
  208967. else
  208968. {
  208969. directory = currentFileOrDirectory.getParentDirectory().getFullPathName();
  208970. filename = currentFileOrDirectory.getFileName();
  208971. }
  208972. if ([panel runModalForDirectory: juceStringToNS (directory)
  208973. file: juceStringToNS (filename)]
  208974. == NSOKButton)
  208975. {
  208976. if (isSaveDialogue)
  208977. {
  208978. results.add (File (nsStringToJuce ([panel filename])));
  208979. }
  208980. else
  208981. {
  208982. NSOpenPanel* openPanel = (NSOpenPanel*) panel;
  208983. NSArray* urls = [openPanel filenames];
  208984. for (unsigned int i = 0; i < [urls count]; ++i)
  208985. {
  208986. NSString* f = [urls objectAtIndex: i];
  208987. results.add (File (nsStringToJuce (f)));
  208988. }
  208989. }
  208990. }
  208991. [panel setDelegate: nil];
  208992. }
  208993. #else
  208994. void FileChooser::showPlatformDialog (Array<File>& results,
  208995. const String& title,
  208996. const File& currentFileOrDirectory,
  208997. const String& filter,
  208998. bool selectsDirectory,
  208999. bool selectsFiles,
  209000. bool isSaveDialogue,
  209001. bool warnAboutOverwritingExistingFiles,
  209002. bool selectMultipleFiles,
  209003. FilePreviewComponent* extraInfoComponent)
  209004. {
  209005. const ScopedAutoReleasePool pool;
  209006. jassertfalse //xxx to do
  209007. }
  209008. #endif
  209009. #endif
  209010. /*** End of inlined file: juce_mac_FileChooser.mm ***/
  209011. /*** Start of inlined file: juce_mac_QuickTimeMovieComponent.mm ***/
  209012. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  209013. // compiled on its own).
  209014. #if JUCE_INCLUDED_FILE && JUCE_QUICKTIME
  209015. #define theMovie ((QTMovie*) movie)
  209016. QuickTimeMovieComponent::QuickTimeMovieComponent()
  209017. : movie (0)
  209018. {
  209019. setOpaque (true);
  209020. setVisible (true);
  209021. QTMovieView* view = [[QTMovieView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)];
  209022. setView (view);
  209023. }
  209024. QuickTimeMovieComponent::~QuickTimeMovieComponent()
  209025. {
  209026. closeMovie();
  209027. setView (0);
  209028. }
  209029. bool QuickTimeMovieComponent::isQuickTimeAvailable() throw()
  209030. {
  209031. return true;
  209032. }
  209033. static QTMovie* openMovieFromStream (InputStream* movieStream, File& movieFile)
  209034. {
  209035. // unfortunately, QTMovie objects can only be created on the main thread..
  209036. jassert (MessageManager::getInstance()->isThisTheMessageThread());
  209037. QTMovie* movie = 0;
  209038. FileInputStream* const fin = dynamic_cast <FileInputStream*> (movieStream);
  209039. if (fin != 0)
  209040. {
  209041. movieFile = fin->getFile();
  209042. movie = [QTMovie movieWithFile: juceStringToNS (movieFile.getFullPathName())
  209043. error: nil];
  209044. }
  209045. else
  209046. {
  209047. MemoryBlock temp;
  209048. movieStream->readIntoMemoryBlock (temp);
  209049. const char* const suffixesToTry[] = { ".mov", ".mp3", ".avi", ".m4a" };
  209050. for (int i = 0; i < numElementsInArray (suffixesToTry); ++i)
  209051. {
  209052. movie = [QTMovie movieWithDataReference: [QTDataReference dataReferenceWithReferenceToData: [NSData dataWithBytes: temp.getData()
  209053. length: temp.getSize()]
  209054. name: [NSString stringWithUTF8String: suffixesToTry[i]]
  209055. MIMEType: @""]
  209056. error: nil];
  209057. if (movie != 0)
  209058. break;
  209059. }
  209060. }
  209061. return movie;
  209062. }
  209063. bool QuickTimeMovieComponent::loadMovie (const File& movieFile_,
  209064. const bool isControllerVisible_)
  209065. {
  209066. return loadMovie ((InputStream*) movieFile_.createInputStream(), isControllerVisible_);
  209067. }
  209068. bool QuickTimeMovieComponent::loadMovie (InputStream* movieStream,
  209069. const bool controllerVisible_)
  209070. {
  209071. closeMovie();
  209072. if (getPeer() == 0)
  209073. {
  209074. // To open a movie, this component must be visible inside a functioning window, so that
  209075. // the QT control can be assigned to the window.
  209076. jassertfalse
  209077. return false;
  209078. }
  209079. movie = openMovieFromStream (movieStream, movieFile);
  209080. [theMovie retain];
  209081. QTMovieView* view = (QTMovieView*) getView();
  209082. [view setMovie: theMovie];
  209083. [view setControllerVisible: controllerVisible_];
  209084. setLooping (looping);
  209085. return movie != nil;
  209086. }
  209087. bool QuickTimeMovieComponent::loadMovie (const URL& movieURL,
  209088. const bool isControllerVisible_)
  209089. {
  209090. // unfortunately, QTMovie objects can only be created on the main thread..
  209091. jassert (MessageManager::getInstance()->isThisTheMessageThread());
  209092. closeMovie();
  209093. if (getPeer() == 0)
  209094. {
  209095. // To open a movie, this component must be visible inside a functioning window, so that
  209096. // the QT control can be assigned to the window.
  209097. jassertfalse
  209098. return false;
  209099. }
  209100. NSURL* url = [NSURL URLWithString: juceStringToNS (movieURL.toString (true))];
  209101. NSError* err;
  209102. if ([QTMovie canInitWithURL: url])
  209103. movie = [QTMovie movieWithURL: url error: &err];
  209104. [theMovie retain];
  209105. QTMovieView* view = (QTMovieView*) getView();
  209106. [view setMovie: theMovie];
  209107. [view setControllerVisible: controllerVisible];
  209108. setLooping (looping);
  209109. return movie != nil;
  209110. }
  209111. void QuickTimeMovieComponent::closeMovie()
  209112. {
  209113. stop();
  209114. QTMovieView* view = (QTMovieView*) getView();
  209115. [view setMovie: nil];
  209116. [theMovie release];
  209117. movie = 0;
  209118. movieFile = File::nonexistent;
  209119. }
  209120. bool QuickTimeMovieComponent::isMovieOpen() const
  209121. {
  209122. return movie != nil;
  209123. }
  209124. const File QuickTimeMovieComponent::getCurrentMovieFile() const
  209125. {
  209126. return movieFile;
  209127. }
  209128. void QuickTimeMovieComponent::play()
  209129. {
  209130. [theMovie play];
  209131. }
  209132. void QuickTimeMovieComponent::stop()
  209133. {
  209134. [theMovie stop];
  209135. }
  209136. bool QuickTimeMovieComponent::isPlaying() const
  209137. {
  209138. return movie != 0 && [theMovie rate] != 0;
  209139. }
  209140. void QuickTimeMovieComponent::setPosition (const double seconds)
  209141. {
  209142. if (movie != 0)
  209143. {
  209144. QTTime t;
  209145. t.timeValue = (uint64) (100000.0 * seconds);
  209146. t.timeScale = 100000;
  209147. t.flags = 0;
  209148. [theMovie setCurrentTime: t];
  209149. }
  209150. }
  209151. double QuickTimeMovieComponent::getPosition() const
  209152. {
  209153. if (movie == 0)
  209154. return 0.0;
  209155. QTTime t = [theMovie currentTime];
  209156. return t.timeValue / (double) t.timeScale;
  209157. }
  209158. void QuickTimeMovieComponent::setSpeed (const float newSpeed)
  209159. {
  209160. [theMovie setRate: newSpeed];
  209161. }
  209162. double QuickTimeMovieComponent::getMovieDuration() const
  209163. {
  209164. if (movie == 0)
  209165. return 0.0;
  209166. QTTime t = [theMovie duration];
  209167. return t.timeValue / (double) t.timeScale;
  209168. }
  209169. void QuickTimeMovieComponent::setLooping (const bool shouldLoop)
  209170. {
  209171. looping = shouldLoop;
  209172. [theMovie setAttribute: [NSNumber numberWithBool: shouldLoop]
  209173. forKey: QTMovieLoopsAttribute];
  209174. }
  209175. bool QuickTimeMovieComponent::isLooping() const
  209176. {
  209177. return looping;
  209178. }
  209179. void QuickTimeMovieComponent::setMovieVolume (const float newVolume)
  209180. {
  209181. [theMovie setVolume: newVolume];
  209182. }
  209183. float QuickTimeMovieComponent::getMovieVolume() const
  209184. {
  209185. return movie != 0 ? [theMovie volume] : 0.0f;
  209186. }
  209187. void QuickTimeMovieComponent::getMovieNormalSize (int& width, int& height) const
  209188. {
  209189. width = 0;
  209190. height = 0;
  209191. if (movie != 0)
  209192. {
  209193. NSSize s = [[theMovie attributeForKey: QTMovieNaturalSizeAttribute] sizeValue];
  209194. width = (int) s.width;
  209195. height = (int) s.height;
  209196. }
  209197. }
  209198. void QuickTimeMovieComponent::paint (Graphics& g)
  209199. {
  209200. if (movie == 0)
  209201. g.fillAll (Colours::black);
  209202. }
  209203. bool QuickTimeMovieComponent::isControllerVisible() const
  209204. {
  209205. return controllerVisible;
  209206. }
  209207. void QuickTimeMovieComponent::goToStart()
  209208. {
  209209. setPosition (0.0);
  209210. }
  209211. void QuickTimeMovieComponent::setBoundsWithCorrectAspectRatio (const Rectangle<int>& spaceToFitWithin,
  209212. const RectanglePlacement& placement)
  209213. {
  209214. int normalWidth, normalHeight;
  209215. getMovieNormalSize (normalWidth, normalHeight);
  209216. if (normalWidth > 0 && normalHeight > 0 && ! spaceToFitWithin.isEmpty())
  209217. {
  209218. double x = 0.0, y = 0.0, w = normalWidth, h = normalHeight;
  209219. placement.applyTo (x, y, w, h,
  209220. spaceToFitWithin.getX(), spaceToFitWithin.getY(),
  209221. spaceToFitWithin.getWidth(), spaceToFitWithin.getHeight());
  209222. if (w > 0 && h > 0)
  209223. {
  209224. setBounds (roundToInt (x), roundToInt (y),
  209225. roundToInt (w), roundToInt (h));
  209226. }
  209227. }
  209228. else
  209229. {
  209230. setBounds (spaceToFitWithin);
  209231. }
  209232. }
  209233. #if ! (JUCE_MAC && JUCE_64BIT)
  209234. bool juce_OpenQuickTimeMovieFromStream (InputStream* movieStream, Movie& result, Handle& dataHandle)
  209235. {
  209236. if (movieStream == 0)
  209237. return false;
  209238. File file;
  209239. QTMovie* movie = openMovieFromStream (movieStream, file);
  209240. if (movie != nil)
  209241. result = [movie quickTimeMovie];
  209242. return movie != nil;
  209243. }
  209244. #endif
  209245. #endif
  209246. /*** End of inlined file: juce_mac_QuickTimeMovieComponent.mm ***/
  209247. /*** Start of inlined file: juce_mac_AudioCDBurner.mm ***/
  209248. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  209249. // compiled on its own).
  209250. #if JUCE_INCLUDED_FILE && JUCE_USE_CDBURNER
  209251. END_JUCE_NAMESPACE
  209252. #define OpenDiskDevice MakeObjCClassName(OpenDiskDevice)
  209253. @interface OpenDiskDevice : NSObject
  209254. {
  209255. DRDevice* device;
  209256. NSMutableArray* tracks;
  209257. }
  209258. - (OpenDiskDevice*) initWithDevice: (DRDevice*) device;
  209259. - (void) dealloc;
  209260. - (bool) isDiskPresent;
  209261. - (int) getNumAvailableAudioBlocks;
  209262. - (void) addSourceTrack: (JUCE_NAMESPACE::AudioSource*) source numSamples: (int) numSamples_;
  209263. - (void) burn: (JUCE_NAMESPACE::AudioCDBurner::BurnProgressListener*) listener errorString: (JUCE_NAMESPACE::String*) error
  209264. ejectAfterwards: (bool) shouldEject isFake: (bool) peformFakeBurnForTesting;
  209265. @end
  209266. #define AudioTrackProducer MakeObjCClassName(AudioTrackProducer)
  209267. @interface AudioTrackProducer : NSObject
  209268. {
  209269. JUCE_NAMESPACE::AudioSource* source;
  209270. int readPosition, lengthInFrames;
  209271. }
  209272. - (AudioTrackProducer*) init: (int) lengthInFrames;
  209273. - (AudioTrackProducer*) initWithAudioSource: (JUCE_NAMESPACE::AudioSource*) source numSamples: (int) lengthInSamples;
  209274. - (void) dealloc;
  209275. - (void) setupTrackProperties: (DRTrack*) track;
  209276. - (void) cleanupTrackAfterBurn: (DRTrack*) track;
  209277. - (BOOL) cleanupTrackAfterVerification:(DRTrack*)track;
  209278. - (uint64_t) estimateLengthOfTrack:(DRTrack*)track;
  209279. - (BOOL) prepareTrack:(DRTrack*)track forBurn:(DRBurn*)burn
  209280. toMedia:(NSDictionary*)mediaInfo;
  209281. - (BOOL) prepareTrackForVerification:(DRTrack*)track;
  209282. - (uint32_t) produceDataForTrack:(DRTrack*)track intoBuffer:(char*)buffer
  209283. length:(uint32_t)bufferLength atAddress:(uint64_t)address
  209284. blockSize:(uint32_t)blockSize ioFlags:(uint32_t*)flags;
  209285. - (uint32_t) producePreGapForTrack:(DRTrack*)track
  209286. intoBuffer:(char*)buffer length:(uint32_t)bufferLength
  209287. atAddress:(uint64_t)address blockSize:(uint32_t)blockSize
  209288. ioFlags:(uint32_t*)flags;
  209289. - (BOOL) verifyDataForTrack:(DRTrack*)track inBuffer:(const char*)buffer
  209290. length:(uint32_t)bufferLength atAddress:(uint64_t)address
  209291. blockSize:(uint32_t)blockSize ioFlags:(uint32_t*)flags;
  209292. - (uint32_t) producePreGapForTrack:(DRTrack*)track
  209293. intoBuffer:(char*)buffer length:(uint32_t)bufferLength
  209294. atAddress:(uint64_t)address blockSize:(uint32_t)blockSize
  209295. ioFlags:(uint32_t*)flags;
  209296. @end
  209297. @implementation OpenDiskDevice
  209298. - (OpenDiskDevice*) initWithDevice: (DRDevice*) device_
  209299. {
  209300. [super init];
  209301. device = device_;
  209302. tracks = [[NSMutableArray alloc] init];
  209303. return self;
  209304. }
  209305. - (void) dealloc
  209306. {
  209307. [tracks release];
  209308. [super dealloc];
  209309. }
  209310. - (bool) isDiskPresent
  209311. {
  209312. return [device isValid]
  209313. && [[[device status] objectForKey: DRDeviceMediaStateKey]
  209314. isEqualTo: DRDeviceMediaStateMediaPresent];
  209315. }
  209316. - (int) getNumAvailableAudioBlocks
  209317. {
  209318. return [[[[device status] objectForKey: DRDeviceMediaInfoKey]
  209319. objectForKey: DRDeviceMediaBlocksFreeKey] intValue];
  209320. }
  209321. - (void) addSourceTrack: (JUCE_NAMESPACE::AudioSource*) source_ numSamples: (int) numSamples_
  209322. {
  209323. AudioTrackProducer* p = [[AudioTrackProducer alloc] initWithAudioSource: source_ numSamples: numSamples_];
  209324. DRTrack* t = [[DRTrack alloc] initWithProducer: p];
  209325. [p setupTrackProperties: t];
  209326. [tracks addObject: t];
  209327. [t release];
  209328. [p release];
  209329. }
  209330. - (void) burn: (JUCE_NAMESPACE::AudioCDBurner::BurnProgressListener*) listener errorString: (JUCE_NAMESPACE::String*) error
  209331. ejectAfterwards: (bool) shouldEject isFake: (bool) peformFakeBurnForTesting
  209332. {
  209333. DRBurn* burn = [DRBurn burnForDevice: device];
  209334. if (! [device acquireExclusiveAccess])
  209335. {
  209336. *error = "Couldn't open or write to the CD device";
  209337. return;
  209338. }
  209339. [device acquireMediaReservation];
  209340. NSMutableDictionary* d = [[burn properties] mutableCopy];
  209341. [d autorelease];
  209342. [d setObject: [NSNumber numberWithBool: peformFakeBurnForTesting] forKey: DRBurnTestingKey];
  209343. [d setObject: [NSNumber numberWithBool: false] forKey: DRBurnVerifyDiscKey];
  209344. [d setObject: (shouldEject ? DRBurnCompletionActionEject : DRBurnCompletionActionMount)
  209345. forKey: DRBurnCompletionActionKey];
  209346. [burn setProperties: d];
  209347. [burn writeLayout: tracks];
  209348. for (;;)
  209349. {
  209350. JUCE_NAMESPACE::Thread::sleep (300);
  209351. float progress = [[[burn status] objectForKey: DRStatusPercentCompleteKey] floatValue];
  209352. if (listener != 0 && listener->audioCDBurnProgress (progress))
  209353. {
  209354. [burn abort];
  209355. *error = "User cancelled the write operation";
  209356. break;
  209357. }
  209358. if ([[[burn status] objectForKey: DRStatusStateKey] isEqualTo: DRStatusStateFailed])
  209359. {
  209360. *error = "Write operation failed";
  209361. break;
  209362. }
  209363. else if ([[[burn status] objectForKey: DRStatusStateKey] isEqualTo: DRStatusStateDone])
  209364. {
  209365. break;
  209366. }
  209367. NSString* err = (NSString*) [[[burn status] objectForKey: DRErrorStatusKey]
  209368. objectForKey: DRErrorStatusErrorStringKey];
  209369. if ([err length] > 0)
  209370. {
  209371. *error = JUCE_NAMESPACE::String::fromUTF8 ((JUCE_NAMESPACE::uint8*) [err UTF8String]);
  209372. break;
  209373. }
  209374. }
  209375. [device releaseMediaReservation];
  209376. [device releaseExclusiveAccess];
  209377. }
  209378. @end
  209379. @implementation AudioTrackProducer
  209380. - (AudioTrackProducer*) init: (int) lengthInFrames_
  209381. {
  209382. lengthInFrames = lengthInFrames_;
  209383. readPosition = 0;
  209384. return self;
  209385. }
  209386. - (void) setupTrackProperties: (DRTrack*) track
  209387. {
  209388. NSMutableDictionary* p = [[track properties] mutableCopy];
  209389. [p setObject:[DRMSF msfWithFrames: lengthInFrames] forKey: DRTrackLengthKey];
  209390. [p setObject:[NSNumber numberWithUnsignedShort:2352] forKey: DRBlockSizeKey];
  209391. [p setObject:[NSNumber numberWithInt:0] forKey: DRDataFormKey];
  209392. [p setObject:[NSNumber numberWithInt:0] forKey: DRBlockTypeKey];
  209393. [p setObject:[NSNumber numberWithInt:0] forKey: DRTrackModeKey];
  209394. [p setObject:[NSNumber numberWithInt:0] forKey: DRSessionFormatKey];
  209395. [track setProperties: p];
  209396. [p release];
  209397. }
  209398. - (AudioTrackProducer*) initWithAudioSource: (JUCE_NAMESPACE::AudioSource*) source_ numSamples: (int) lengthInSamples
  209399. {
  209400. AudioTrackProducer* s = [self init: (lengthInSamples + 587) / 588];
  209401. if (s != nil)
  209402. s->source = source_;
  209403. return s;
  209404. }
  209405. - (void) dealloc
  209406. {
  209407. if (source != 0)
  209408. {
  209409. source->releaseResources();
  209410. delete source;
  209411. }
  209412. [super dealloc];
  209413. }
  209414. - (void) cleanupTrackAfterBurn: (DRTrack*) track
  209415. {
  209416. }
  209417. - (BOOL) cleanupTrackAfterVerification: (DRTrack*) track
  209418. {
  209419. return true;
  209420. }
  209421. - (uint64_t) estimateLengthOfTrack: (DRTrack*) track
  209422. {
  209423. return lengthInFrames;
  209424. }
  209425. - (BOOL) prepareTrack: (DRTrack*) track forBurn: (DRBurn*) burn
  209426. toMedia: (NSDictionary*) mediaInfo
  209427. {
  209428. if (source != 0)
  209429. source->prepareToPlay (44100 / 75, 44100);
  209430. readPosition = 0;
  209431. return true;
  209432. }
  209433. - (BOOL) prepareTrackForVerification: (DRTrack*) track
  209434. {
  209435. if (source != 0)
  209436. source->prepareToPlay (44100 / 75, 44100);
  209437. return true;
  209438. }
  209439. - (uint32_t) produceDataForTrack: (DRTrack*) track intoBuffer: (char*) buffer
  209440. length: (uint32_t) bufferLength atAddress: (uint64_t) address
  209441. blockSize: (uint32_t) blockSize ioFlags: (uint32_t*) flags
  209442. {
  209443. if (source != 0)
  209444. {
  209445. const int numSamples = JUCE_NAMESPACE::jmin ((int) bufferLength / 4, (lengthInFrames * (44100 / 75)) - readPosition);
  209446. if (numSamples > 0)
  209447. {
  209448. JUCE_NAMESPACE::AudioSampleBuffer tempBuffer (2, numSamples);
  209449. JUCE_NAMESPACE::AudioSourceChannelInfo info;
  209450. info.buffer = &tempBuffer;
  209451. info.startSample = 0;
  209452. info.numSamples = numSamples;
  209453. source->getNextAudioBlock (info);
  209454. JUCE_NAMESPACE::AudioDataConverters::convertFloatToInt16LE (tempBuffer.getSampleData (0),
  209455. buffer, numSamples, 4);
  209456. JUCE_NAMESPACE::AudioDataConverters::convertFloatToInt16LE (tempBuffer.getSampleData (1),
  209457. buffer + 2, numSamples, 4);
  209458. readPosition += numSamples;
  209459. }
  209460. return numSamples * 4;
  209461. }
  209462. return 0;
  209463. }
  209464. - (uint32_t) producePreGapForTrack: (DRTrack*) track
  209465. intoBuffer: (char*) buffer length: (uint32_t) bufferLength
  209466. atAddress: (uint64_t) address blockSize: (uint32_t) blockSize
  209467. ioFlags: (uint32_t*) flags
  209468. {
  209469. zeromem (buffer, bufferLength);
  209470. return bufferLength;
  209471. }
  209472. - (BOOL) verifyDataForTrack: (DRTrack*) track inBuffer: (const char*) buffer
  209473. length: (uint32_t) bufferLength atAddress: (uint64_t) address
  209474. blockSize: (uint32_t) blockSize ioFlags: (uint32_t*) flags
  209475. {
  209476. return true;
  209477. }
  209478. @end
  209479. BEGIN_JUCE_NAMESPACE
  209480. AudioCDBurner::AudioCDBurner (const int deviceIndex)
  209481. : internal (0)
  209482. {
  209483. OpenDiskDevice* dev = [[OpenDiskDevice alloc] initWithDevice: [[DRDevice devices] objectAtIndex: deviceIndex]];
  209484. internal = (void*) dev;
  209485. }
  209486. AudioCDBurner::~AudioCDBurner()
  209487. {
  209488. OpenDiskDevice* dev = (OpenDiskDevice*) internal;
  209489. if (dev != 0)
  209490. [dev release];
  209491. }
  209492. AudioCDBurner* AudioCDBurner::openDevice (const int deviceIndex)
  209493. {
  209494. ScopedPointer <AudioCDBurner> b (new AudioCDBurner (deviceIndex));
  209495. if (b->internal == 0)
  209496. b = 0;
  209497. return b.release();
  209498. }
  209499. static NSArray* findDiskBurnerDevices()
  209500. {
  209501. NSMutableArray* results = [NSMutableArray array];
  209502. NSArray* devs = [DRDevice devices];
  209503. if (devs != 0)
  209504. {
  209505. int num = [devs count];
  209506. int i;
  209507. for (i = 0; i < num; ++i)
  209508. {
  209509. NSDictionary* dic = [[devs objectAtIndex: i] info];
  209510. NSString* name = [dic valueForKey: DRDeviceProductNameKey];
  209511. if (name != nil)
  209512. [results addObject: name];
  209513. }
  209514. }
  209515. return results;
  209516. }
  209517. const StringArray AudioCDBurner::findAvailableDevices()
  209518. {
  209519. NSArray* names = findDiskBurnerDevices();
  209520. StringArray s;
  209521. for (unsigned int i = 0; i < [names count]; ++i)
  209522. s.add (String::fromUTF8 ((JUCE_NAMESPACE::uint8*) [[names objectAtIndex: i] UTF8String]));
  209523. return s;
  209524. }
  209525. bool AudioCDBurner::isDiskPresent() const
  209526. {
  209527. OpenDiskDevice* dev = (OpenDiskDevice*) internal;
  209528. return dev != 0 && [dev isDiskPresent];
  209529. }
  209530. int AudioCDBurner::getNumAvailableAudioBlocks() const
  209531. {
  209532. OpenDiskDevice* dev = (OpenDiskDevice*) internal;
  209533. return [dev getNumAvailableAudioBlocks];
  209534. }
  209535. bool AudioCDBurner::addAudioTrack (AudioSource* source, int numSamps)
  209536. {
  209537. OpenDiskDevice* dev = (OpenDiskDevice*) internal;
  209538. if (dev != 0)
  209539. {
  209540. [dev addSourceTrack: source numSamples: numSamps];
  209541. return true;
  209542. }
  209543. return false;
  209544. }
  209545. const String AudioCDBurner::burn (JUCE_NAMESPACE::AudioCDBurner::BurnProgressListener* listener,
  209546. const bool ejectDiscAfterwards,
  209547. const bool peformFakeBurnForTesting)
  209548. {
  209549. String error ("Couldn't open or write to the CD device");
  209550. OpenDiskDevice* dev = (OpenDiskDevice*) internal;
  209551. if (dev != 0)
  209552. {
  209553. error = String::empty;
  209554. [dev burn: listener
  209555. errorString: &error
  209556. ejectAfterwards: ejectDiscAfterwards
  209557. isFake: peformFakeBurnForTesting];
  209558. }
  209559. return error;
  209560. }
  209561. void AudioCDReader::ejectDisk()
  209562. {
  209563. const ScopedAutoReleasePool p;
  209564. [[NSWorkspace sharedWorkspace] unmountAndEjectDeviceAtPath: juceStringToNS (volumeDir.getFullPathName())];
  209565. }
  209566. #endif
  209567. /*** End of inlined file: juce_mac_AudioCDBurner.mm ***/
  209568. /*** Start of inlined file: juce_mac_MessageManager.mm ***/
  209569. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  209570. // compiled on its own).
  209571. #if JUCE_INCLUDED_FILE
  209572. struct CallbackMessagePayload
  209573. {
  209574. MessageCallbackFunction* function;
  209575. void* parameter;
  209576. void* volatile result;
  209577. bool volatile hasBeenExecuted;
  209578. };
  209579. class AppDelegateRedirector
  209580. {
  209581. public:
  209582. AppDelegateRedirector()
  209583. {
  209584. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_4
  209585. runLoop = CFRunLoopGetMain();
  209586. #else
  209587. runLoop = CFRunLoopGetCurrent();
  209588. #endif
  209589. CFRunLoopSourceContext sourceContext;
  209590. zerostruct (sourceContext);
  209591. sourceContext.info = this;
  209592. sourceContext.perform = runLoopSourceCallback;
  209593. runLoopSource = CFRunLoopSourceCreate (kCFAllocatorDefault, 1, &sourceContext);
  209594. CFRunLoopAddSource (runLoop, runLoopSource, kCFRunLoopCommonModes);
  209595. }
  209596. virtual ~AppDelegateRedirector()
  209597. {
  209598. CFRunLoopRemoveSource (runLoop, runLoopSource, kCFRunLoopCommonModes);
  209599. CFRunLoopSourceInvalidate (runLoopSource);
  209600. CFRelease (runLoopSource);
  209601. while (messages.size() > 0)
  209602. delete ((Message*) messages.remove(0));
  209603. }
  209604. virtual NSApplicationTerminateReply shouldTerminate()
  209605. {
  209606. if (JUCEApplication::getInstance() != 0)
  209607. {
  209608. JUCEApplication::getInstance()->systemRequestedQuit();
  209609. return NSTerminateCancel;
  209610. }
  209611. return NSTerminateNow;
  209612. }
  209613. virtual BOOL openFile (const NSString* filename)
  209614. {
  209615. if (JUCEApplication::getInstance() != 0)
  209616. {
  209617. JUCEApplication::getInstance()->anotherInstanceStarted (nsStringToJuce (filename));
  209618. return YES;
  209619. }
  209620. return NO;
  209621. }
  209622. virtual void openFiles (NSArray* filenames)
  209623. {
  209624. StringArray files;
  209625. for (unsigned int i = 0; i < [filenames count]; ++i)
  209626. {
  209627. String filename (nsStringToJuce ((NSString*) [filenames objectAtIndex: i]));
  209628. if (filename.containsChar (T(' ')))
  209629. filename = filename.quoted('"');
  209630. files.add (filename);
  209631. }
  209632. if (files.size() > 0 && JUCEApplication::getInstance() != 0)
  209633. {
  209634. JUCEApplication::getInstance()->anotherInstanceStarted (files.joinIntoString (T(" ")));
  209635. }
  209636. }
  209637. virtual void focusChanged()
  209638. {
  209639. juce_HandleProcessFocusChange();
  209640. }
  209641. virtual void performCallback (CallbackMessagePayload* pl)
  209642. {
  209643. pl->result = (*pl->function) (pl->parameter);
  209644. pl->hasBeenExecuted = true;
  209645. }
  209646. virtual void deleteSelf()
  209647. {
  209648. delete this;
  209649. }
  209650. void postMessage (void* m)
  209651. {
  209652. messages.add (m);
  209653. CFRunLoopSourceSignal (runLoopSource);
  209654. CFRunLoopWakeUp (runLoop);
  209655. }
  209656. private:
  209657. CFRunLoopRef runLoop;
  209658. CFRunLoopSourceRef runLoopSource;
  209659. Array <void*, CriticalSection> messages;
  209660. void runLoopCallback()
  209661. {
  209662. int numDispatched = 0;
  209663. do
  209664. {
  209665. void* const nextMessage = messages.remove (0);
  209666. if (nextMessage == 0)
  209667. return;
  209668. const ScopedAutoReleasePool pool;
  209669. MessageManager::getInstance()->deliverMessage (nextMessage);
  209670. } while (++numDispatched <= 4);
  209671. CFRunLoopSourceSignal (runLoopSource);
  209672. CFRunLoopWakeUp (runLoop);
  209673. }
  209674. static void runLoopSourceCallback (void* info)
  209675. {
  209676. ((AppDelegateRedirector*) info)->runLoopCallback();
  209677. }
  209678. };
  209679. END_JUCE_NAMESPACE
  209680. using namespace JUCE_NAMESPACE;
  209681. #define JuceAppDelegate MakeObjCClassName(JuceAppDelegate)
  209682. @interface JuceAppDelegate : NSObject
  209683. {
  209684. @private
  209685. id oldDelegate;
  209686. @public
  209687. AppDelegateRedirector* redirector;
  209688. }
  209689. - (JuceAppDelegate*) init;
  209690. - (void) dealloc;
  209691. - (BOOL) application: (NSApplication*) theApplication openFile: (NSString*) filename;
  209692. - (void) application: (NSApplication*) sender openFiles: (NSArray*) filenames;
  209693. - (NSApplicationTerminateReply) applicationShouldTerminate: (NSApplication*) app;
  209694. - (void) applicationDidBecomeActive: (NSNotification*) aNotification;
  209695. - (void) applicationDidResignActive: (NSNotification*) aNotification;
  209696. - (void) applicationWillUnhide: (NSNotification*) aNotification;
  209697. - (void) performCallback: (id) info;
  209698. - (void) dummyMethod;
  209699. @end
  209700. @implementation JuceAppDelegate
  209701. - (JuceAppDelegate*) init
  209702. {
  209703. [super init];
  209704. redirector = new AppDelegateRedirector();
  209705. NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
  209706. if (JUCEApplication::getInstance() != 0)
  209707. {
  209708. oldDelegate = [NSApp delegate];
  209709. [NSApp setDelegate: self];
  209710. }
  209711. else
  209712. {
  209713. oldDelegate = 0;
  209714. [center addObserver: self selector: @selector (applicationDidResignActive:)
  209715. name: NSApplicationDidResignActiveNotification object: NSApp];
  209716. [center addObserver: self selector: @selector (applicationDidBecomeActive:)
  209717. name: NSApplicationDidBecomeActiveNotification object: NSApp];
  209718. [center addObserver: self selector: @selector (applicationWillUnhide:)
  209719. name: NSApplicationWillUnhideNotification object: NSApp];
  209720. }
  209721. return self;
  209722. }
  209723. - (void) dealloc
  209724. {
  209725. if (oldDelegate != 0)
  209726. [NSApp setDelegate: oldDelegate];
  209727. redirector->deleteSelf();
  209728. [super dealloc];
  209729. }
  209730. - (NSApplicationTerminateReply) applicationShouldTerminate: (NSApplication*) app
  209731. {
  209732. return redirector->shouldTerminate();
  209733. }
  209734. - (BOOL) application: (NSApplication*) app openFile: (NSString*) filename
  209735. {
  209736. return redirector->openFile (filename);
  209737. }
  209738. - (void) application: (NSApplication*) sender openFiles: (NSArray*) filenames
  209739. {
  209740. return redirector->openFiles (filenames);
  209741. }
  209742. - (void) applicationDidBecomeActive: (NSNotification*) aNotification
  209743. {
  209744. redirector->focusChanged();
  209745. }
  209746. - (void) applicationDidResignActive: (NSNotification*) aNotification
  209747. {
  209748. redirector->focusChanged();
  209749. }
  209750. - (void) applicationWillUnhide: (NSNotification*) aNotification
  209751. {
  209752. redirector->focusChanged();
  209753. }
  209754. - (void) performCallback: (id) info
  209755. {
  209756. if ([info isKindOfClass: [NSData class]])
  209757. {
  209758. CallbackMessagePayload* pl = (CallbackMessagePayload*) [((NSData*) info) bytes];
  209759. if (pl != 0)
  209760. redirector->performCallback (pl);
  209761. }
  209762. else
  209763. {
  209764. jassertfalse // should never get here!
  209765. }
  209766. }
  209767. - (void) dummyMethod {} // (used as a way of running a dummy thread)
  209768. @end
  209769. BEGIN_JUCE_NAMESPACE
  209770. static JuceAppDelegate* juceAppDelegate = 0;
  209771. void MessageManager::runDispatchLoop()
  209772. {
  209773. if (! quitMessagePosted) // check that the quit message wasn't already posted..
  209774. {
  209775. const ScopedAutoReleasePool pool;
  209776. // must only be called by the message thread!
  209777. jassert (isThisTheMessageThread());
  209778. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  209779. @try
  209780. {
  209781. [NSApp run];
  209782. }
  209783. @catch (NSException* e)
  209784. {
  209785. // An AppKit exception will kill the app, but at least this provides a chance to log it.,
  209786. std::runtime_error ex (std::string ("NSException: ") + [[e name] UTF8String] + ", Reason:" + [[e reason] UTF8String]);
  209787. JUCEApplication::sendUnhandledException (&ex, __FILE__, __LINE__);
  209788. }
  209789. @finally
  209790. {
  209791. }
  209792. #else
  209793. [NSApp run];
  209794. #endif
  209795. }
  209796. }
  209797. void MessageManager::stopDispatchLoop()
  209798. {
  209799. quitMessagePosted = true;
  209800. [NSApp stop: nil];
  209801. [NSApp activateIgnoringOtherApps: YES]; // (if the app is inactive, it sits there and ignores the quit request until the next time it gets activated)
  209802. [NSEvent startPeriodicEventsAfterDelay: 0 withPeriod: 0.1];
  209803. }
  209804. static bool isEventBlockedByModalComps (NSEvent* e)
  209805. {
  209806. if (Component::getNumCurrentlyModalComponents() == 0)
  209807. return false;
  209808. NSWindow* const w = [e window];
  209809. if (w == 0 || [w worksWhenModal])
  209810. return false;
  209811. bool isKey = false, isInputAttempt = false;
  209812. switch ([e type])
  209813. {
  209814. case NSKeyDown:
  209815. case NSKeyUp:
  209816. isKey = isInputAttempt = true;
  209817. break;
  209818. case NSLeftMouseDown:
  209819. case NSRightMouseDown:
  209820. case NSOtherMouseDown:
  209821. isInputAttempt = true;
  209822. break;
  209823. case NSLeftMouseDragged:
  209824. case NSRightMouseDragged:
  209825. case NSLeftMouseUp:
  209826. case NSRightMouseUp:
  209827. case NSOtherMouseUp:
  209828. case NSOtherMouseDragged:
  209829. if (Component::getComponentUnderMouse() != 0)
  209830. return false;
  209831. break;
  209832. case NSMouseMoved:
  209833. case NSMouseEntered:
  209834. case NSMouseExited:
  209835. case NSCursorUpdate:
  209836. case NSScrollWheel:
  209837. case NSTabletPoint:
  209838. case NSTabletProximity:
  209839. break;
  209840. default:
  209841. return false;
  209842. }
  209843. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  209844. {
  209845. ComponentPeer* const peer = ComponentPeer::getPeer (i);
  209846. NSView* const compView = (NSView*) peer->getNativeHandle();
  209847. if ([compView window] == w)
  209848. {
  209849. if (isKey)
  209850. {
  209851. if (compView == [w firstResponder])
  209852. return false;
  209853. }
  209854. else
  209855. {
  209856. if (NSPointInRect ([compView convertPoint: [e locationInWindow] fromView: nil],
  209857. [compView bounds]))
  209858. return false;
  209859. }
  209860. }
  209861. }
  209862. if (isInputAttempt)
  209863. {
  209864. if (! [NSApp isActive])
  209865. [NSApp activateIgnoringOtherApps: YES];
  209866. Component* const modal = Component::getCurrentlyModalComponent (0);
  209867. if (modal != 0)
  209868. modal->inputAttemptWhenModal();
  209869. }
  209870. return true;
  209871. }
  209872. bool MessageManager::runDispatchLoopUntil (int millisecondsToRunFor)
  209873. {
  209874. const ScopedAutoReleasePool pool;
  209875. jassert (isThisTheMessageThread()); // must only be called by the message thread
  209876. uint32 endTime = Time::getMillisecondCounter() + millisecondsToRunFor;
  209877. while (! quitMessagePosted)
  209878. {
  209879. const ScopedAutoReleasePool pool2;
  209880. CFRunLoopRunInMode (kCFRunLoopDefaultMode, 0.001, true);
  209881. NSEvent* e = [NSApp nextEventMatchingMask: NSAnyEventMask
  209882. untilDate: [NSDate dateWithTimeIntervalSinceNow: 0.001]
  209883. inMode: NSDefaultRunLoopMode
  209884. dequeue: YES];
  209885. if (e != 0 && ! isEventBlockedByModalComps (e))
  209886. [NSApp sendEvent: e];
  209887. if (Time::getMillisecondCounter() >= endTime)
  209888. break;
  209889. }
  209890. return ! quitMessagePosted;
  209891. }
  209892. void MessageManager::doPlatformSpecificInitialisation()
  209893. {
  209894. if (juceAppDelegate == 0)
  209895. juceAppDelegate = [[JuceAppDelegate alloc] init];
  209896. // This launches a dummy thread, which forces Cocoa to initialise NSThreads
  209897. // correctly (needed prior to 10.5)
  209898. if (! [NSThread isMultiThreaded])
  209899. [NSThread detachNewThreadSelector: @selector (dummyMethod)
  209900. toTarget: juceAppDelegate
  209901. withObject: nil];
  209902. initialiseMainMenu();
  209903. }
  209904. void MessageManager::doPlatformSpecificShutdown()
  209905. {
  209906. if (juceAppDelegate != 0)
  209907. {
  209908. [[NSRunLoop currentRunLoop] cancelPerformSelectorsWithTarget: juceAppDelegate];
  209909. [[NSNotificationCenter defaultCenter] removeObserver: juceAppDelegate];
  209910. [juceAppDelegate release];
  209911. juceAppDelegate = 0;
  209912. }
  209913. }
  209914. bool juce_postMessageToSystemQueue (void* message)
  209915. {
  209916. juceAppDelegate->redirector->postMessage (message);
  209917. return true;
  209918. }
  209919. void MessageManager::broadcastMessage (const String& value) throw()
  209920. {
  209921. }
  209922. void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* callback,
  209923. void* data)
  209924. {
  209925. if (isThisTheMessageThread())
  209926. {
  209927. return (*callback) (data);
  209928. }
  209929. else
  209930. {
  209931. // If a thread has a MessageManagerLock and then tries to call this method, it'll
  209932. // deadlock because the message manager is blocked from running, so can never
  209933. // call your function..
  209934. jassert (! MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  209935. const ScopedAutoReleasePool pool;
  209936. CallbackMessagePayload cmp;
  209937. cmp.function = callback;
  209938. cmp.parameter = data;
  209939. cmp.result = 0;
  209940. cmp.hasBeenExecuted = false;
  209941. [juceAppDelegate performSelectorOnMainThread: @selector (performCallback:)
  209942. withObject: [NSData dataWithBytesNoCopy: &cmp
  209943. length: sizeof (cmp)
  209944. freeWhenDone: NO]
  209945. waitUntilDone: YES];
  209946. return cmp.result;
  209947. }
  209948. }
  209949. #endif
  209950. /*** End of inlined file: juce_mac_MessageManager.mm ***/
  209951. /*** Start of inlined file: juce_mac_WebBrowserComponent.mm ***/
  209952. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  209953. // compiled on its own).
  209954. #if JUCE_INCLUDED_FILE && JUCE_WEB_BROWSER
  209955. #if JUCE_MAC
  209956. END_JUCE_NAMESPACE
  209957. #define DownloadClickDetector MakeObjCClassName(DownloadClickDetector)
  209958. @interface DownloadClickDetector : NSObject
  209959. {
  209960. JUCE_NAMESPACE::WebBrowserComponent* ownerComponent;
  209961. }
  209962. - (DownloadClickDetector*) initWithWebBrowserOwner: (JUCE_NAMESPACE::WebBrowserComponent*) ownerComponent;
  209963. - (void) webView: (WebView*) webView decidePolicyForNavigationAction: (NSDictionary*) actionInformation
  209964. request: (NSURLRequest*) request
  209965. frame: (WebFrame*) frame
  209966. decisionListener: (id<WebPolicyDecisionListener>) listener;
  209967. @end
  209968. @implementation DownloadClickDetector
  209969. - (DownloadClickDetector*) initWithWebBrowserOwner: (JUCE_NAMESPACE::WebBrowserComponent*) ownerComponent_
  209970. {
  209971. [super init];
  209972. ownerComponent = ownerComponent_;
  209973. return self;
  209974. }
  209975. - (void) webView: (WebView*) sender decidePolicyForNavigationAction: (NSDictionary*) actionInformation
  209976. request: (NSURLRequest*) request
  209977. frame: (WebFrame*) frame
  209978. decisionListener: (id <WebPolicyDecisionListener>) listener
  209979. {
  209980. NSURL* url = [actionInformation valueForKey: @"WebActionOriginalURLKey"];
  209981. if (ownerComponent->pageAboutToLoad (nsStringToJuce ([url absoluteString])))
  209982. [listener use];
  209983. else
  209984. [listener ignore];
  209985. }
  209986. @end
  209987. BEGIN_JUCE_NAMESPACE
  209988. class WebBrowserComponentInternal : public NSViewComponent
  209989. {
  209990. public:
  209991. WebBrowserComponentInternal (WebBrowserComponent* owner)
  209992. {
  209993. webView = [[WebView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
  209994. frameName: @""
  209995. groupName: @""];
  209996. setView (webView);
  209997. clickListener = [[DownloadClickDetector alloc] initWithWebBrowserOwner: owner];
  209998. [webView setPolicyDelegate: clickListener];
  209999. }
  210000. ~WebBrowserComponentInternal()
  210001. {
  210002. [webView setPolicyDelegate: nil];
  210003. [clickListener release];
  210004. setView (0);
  210005. }
  210006. void goToURL (const String& url,
  210007. const StringArray* headers,
  210008. const MemoryBlock* postData)
  210009. {
  210010. NSMutableURLRequest* r
  210011. = [NSMutableURLRequest requestWithURL: [NSURL URLWithString: juceStringToNS (url)]
  210012. cachePolicy: NSURLRequestUseProtocolCachePolicy
  210013. timeoutInterval: 30.0];
  210014. if (postData != 0 && postData->getSize() > 0)
  210015. {
  210016. [r setHTTPMethod: @"POST"];
  210017. [r setHTTPBody: [NSData dataWithBytes: postData->getData()
  210018. length: postData->getSize()]];
  210019. }
  210020. if (headers != 0)
  210021. {
  210022. for (int i = 0; i < headers->size(); ++i)
  210023. {
  210024. const String headerName ((*headers)[i].upToFirstOccurrenceOf (T(":"), false, false).trim());
  210025. const String headerValue ((*headers)[i].fromFirstOccurrenceOf (T(":"), false, false).trim());
  210026. [r setValue: juceStringToNS (headerValue)
  210027. forHTTPHeaderField: juceStringToNS (headerName)];
  210028. }
  210029. }
  210030. stop();
  210031. [[webView mainFrame] loadRequest: r];
  210032. }
  210033. void goBack()
  210034. {
  210035. [webView goBack];
  210036. }
  210037. void goForward()
  210038. {
  210039. [webView goForward];
  210040. }
  210041. void stop()
  210042. {
  210043. [webView stopLoading: nil];
  210044. }
  210045. void refresh()
  210046. {
  210047. [webView reload: nil];
  210048. }
  210049. private:
  210050. WebView* webView;
  210051. DownloadClickDetector* clickListener;
  210052. };
  210053. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  210054. : browser (0),
  210055. blankPageShown (false),
  210056. unloadPageWhenBrowserIsHidden (unloadPageWhenBrowserIsHidden_)
  210057. {
  210058. setOpaque (true);
  210059. addAndMakeVisible (browser = new WebBrowserComponentInternal (this));
  210060. }
  210061. WebBrowserComponent::~WebBrowserComponent()
  210062. {
  210063. deleteAndZero (browser);
  210064. }
  210065. void WebBrowserComponent::goToURL (const String& url,
  210066. const StringArray* headers,
  210067. const MemoryBlock* postData)
  210068. {
  210069. lastURL = url;
  210070. lastHeaders.clear();
  210071. if (headers != 0)
  210072. lastHeaders = *headers;
  210073. lastPostData.setSize (0);
  210074. if (postData != 0)
  210075. lastPostData = *postData;
  210076. blankPageShown = false;
  210077. browser->goToURL (url, headers, postData);
  210078. }
  210079. void WebBrowserComponent::stop()
  210080. {
  210081. browser->stop();
  210082. }
  210083. void WebBrowserComponent::goBack()
  210084. {
  210085. lastURL = String::empty;
  210086. blankPageShown = false;
  210087. browser->goBack();
  210088. }
  210089. void WebBrowserComponent::goForward()
  210090. {
  210091. lastURL = String::empty;
  210092. browser->goForward();
  210093. }
  210094. void WebBrowserComponent::refresh()
  210095. {
  210096. browser->refresh();
  210097. }
  210098. void WebBrowserComponent::paint (Graphics& g)
  210099. {
  210100. }
  210101. void WebBrowserComponent::checkWindowAssociation()
  210102. {
  210103. if (isShowing())
  210104. {
  210105. if (blankPageShown)
  210106. goBack();
  210107. }
  210108. else
  210109. {
  210110. if (unloadPageWhenBrowserIsHidden && ! blankPageShown)
  210111. {
  210112. // when the component becomes invisible, some stuff like flash
  210113. // carries on playing audio, so we need to force it onto a blank
  210114. // page to avoid this, (and send it back when it's made visible again).
  210115. blankPageShown = true;
  210116. browser->goToURL ("about:blank", 0, 0);
  210117. }
  210118. }
  210119. }
  210120. void WebBrowserComponent::reloadLastURL()
  210121. {
  210122. if (lastURL.isNotEmpty())
  210123. {
  210124. goToURL (lastURL, &lastHeaders, &lastPostData);
  210125. lastURL = String::empty;
  210126. }
  210127. }
  210128. void WebBrowserComponent::parentHierarchyChanged()
  210129. {
  210130. checkWindowAssociation();
  210131. }
  210132. void WebBrowserComponent::resized()
  210133. {
  210134. browser->setSize (getWidth(), getHeight());
  210135. }
  210136. void WebBrowserComponent::visibilityChanged()
  210137. {
  210138. checkWindowAssociation();
  210139. }
  210140. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  210141. {
  210142. return true;
  210143. }
  210144. #else
  210145. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  210146. {
  210147. }
  210148. WebBrowserComponent::~WebBrowserComponent()
  210149. {
  210150. }
  210151. void WebBrowserComponent::goToURL (const String& url,
  210152. const StringArray* headers,
  210153. const MemoryBlock* postData)
  210154. {
  210155. }
  210156. void WebBrowserComponent::stop()
  210157. {
  210158. }
  210159. void WebBrowserComponent::goBack()
  210160. {
  210161. }
  210162. void WebBrowserComponent::goForward()
  210163. {
  210164. }
  210165. void WebBrowserComponent::refresh()
  210166. {
  210167. }
  210168. void WebBrowserComponent::paint (Graphics& g)
  210169. {
  210170. }
  210171. void WebBrowserComponent::checkWindowAssociation()
  210172. {
  210173. }
  210174. void WebBrowserComponent::reloadLastURL()
  210175. {
  210176. }
  210177. void WebBrowserComponent::parentHierarchyChanged()
  210178. {
  210179. }
  210180. void WebBrowserComponent::resized()
  210181. {
  210182. }
  210183. void WebBrowserComponent::visibilityChanged()
  210184. {
  210185. }
  210186. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  210187. {
  210188. return true;
  210189. }
  210190. #endif
  210191. #endif
  210192. /*** End of inlined file: juce_mac_WebBrowserComponent.mm ***/
  210193. /*** Start of inlined file: juce_mac_CoreAudio.cpp ***/
  210194. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  210195. // compiled on its own).
  210196. #if JUCE_INCLUDED_FILE
  210197. #ifndef JUCE_COREAUDIO_ERROR_LOGGING_ENABLED
  210198. #define JUCE_COREAUDIO_ERROR_LOGGING_ENABLED 1
  210199. #endif
  210200. #undef log
  210201. #if JUCE_COREAUDIO_LOGGING_ENABLED
  210202. #define log(a) Logger::writeToLog (a)
  210203. #else
  210204. #define log(a)
  210205. #endif
  210206. #undef OK
  210207. #if JUCE_COREAUDIO_ERROR_LOGGING_ENABLED
  210208. static bool logAnyErrors_CoreAudio (const OSStatus err, const int lineNum)
  210209. {
  210210. if (err == noErr)
  210211. return true;
  210212. Logger::writeToLog (T("CoreAudio error: ") + String (lineNum) + T(" - ") + String::toHexString ((int)err));
  210213. jassertfalse
  210214. return false;
  210215. }
  210216. #define OK(a) logAnyErrors_CoreAudio (a, __LINE__)
  210217. #else
  210218. #define OK(a) (a == noErr)
  210219. #endif
  210220. class CoreAudioInternal : public Timer
  210221. {
  210222. public:
  210223. CoreAudioInternal (AudioDeviceID id)
  210224. : inputLatency (0),
  210225. outputLatency (0),
  210226. callback (0),
  210227. #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
  210228. audioProcID (0),
  210229. #endif
  210230. inputDevice (0),
  210231. isSlaveDevice (false),
  210232. deviceID (id),
  210233. started (false),
  210234. sampleRate (0),
  210235. bufferSize (512),
  210236. numInputChans (0),
  210237. numOutputChans (0),
  210238. callbacksAllowed (true),
  210239. numInputChannelInfos (0),
  210240. numOutputChannelInfos (0)
  210241. {
  210242. jassert (deviceID != 0);
  210243. updateDetailsFromDevice();
  210244. AudioObjectPropertyAddress pa;
  210245. pa.mSelector = kAudioObjectPropertySelectorWildcard;
  210246. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210247. pa.mElement = kAudioObjectPropertyElementWildcard;
  210248. AudioObjectAddPropertyListener (deviceID, &pa, deviceListenerProc, this);
  210249. }
  210250. ~CoreAudioInternal()
  210251. {
  210252. AudioObjectPropertyAddress pa;
  210253. pa.mSelector = kAudioObjectPropertySelectorWildcard;
  210254. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210255. pa.mElement = kAudioObjectPropertyElementWildcard;
  210256. AudioObjectRemovePropertyListener (deviceID, &pa, deviceListenerProc, this);
  210257. stop (false);
  210258. delete inputDevice;
  210259. }
  210260. void allocateTempBuffers()
  210261. {
  210262. const int tempBufSize = bufferSize + 4;
  210263. audioBuffer.calloc ((numInputChans + numOutputChans) * tempBufSize);
  210264. tempInputBuffers.calloc (numInputChans + 2);
  210265. tempOutputBuffers.calloc (numOutputChans + 2);
  210266. int i, count = 0;
  210267. for (i = 0; i < numInputChans; ++i)
  210268. tempInputBuffers[i] = audioBuffer + count++ * tempBufSize;
  210269. for (i = 0; i < numOutputChans; ++i)
  210270. tempOutputBuffers[i] = audioBuffer + count++ * tempBufSize;
  210271. }
  210272. // returns the number of actual available channels
  210273. void fillInChannelInfo (const bool input)
  210274. {
  210275. int chanNum = 0;
  210276. UInt32 size;
  210277. AudioObjectPropertyAddress pa;
  210278. pa.mSelector = kAudioDevicePropertyStreamConfiguration;
  210279. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  210280. pa.mElement = kAudioObjectPropertyElementMaster;
  210281. if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  210282. {
  210283. HeapBlock <AudioBufferList> bufList;
  210284. bufList.calloc (size, 1);
  210285. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, bufList)))
  210286. {
  210287. const int numStreams = bufList->mNumberBuffers;
  210288. for (int i = 0; i < numStreams; ++i)
  210289. {
  210290. const AudioBuffer& b = bufList->mBuffers[i];
  210291. for (unsigned int j = 0; j < b.mNumberChannels; ++j)
  210292. {
  210293. String name;
  210294. {
  210295. uint8 channelName [256];
  210296. zerostruct (channelName);
  210297. UInt32 nameSize = sizeof (channelName);
  210298. UInt32 channelNum = chanNum + 1;
  210299. pa.mSelector = kAudioDevicePropertyChannelName;
  210300. if (AudioObjectGetPropertyData (deviceID, &pa, sizeof (channelNum), &channelNum, &nameSize, channelName) == noErr)
  210301. name = String::fromUTF8 (channelName, nameSize);
  210302. }
  210303. if (input)
  210304. {
  210305. if (activeInputChans[chanNum])
  210306. {
  210307. inputChannelInfo [numInputChannelInfos].streamNum = i;
  210308. inputChannelInfo [numInputChannelInfos].dataOffsetSamples = j;
  210309. inputChannelInfo [numInputChannelInfos].dataStrideSamples = b.mNumberChannels;
  210310. ++numInputChannelInfos;
  210311. }
  210312. if (name.isEmpty())
  210313. name << "Input " << (chanNum + 1);
  210314. inChanNames.add (name);
  210315. }
  210316. else
  210317. {
  210318. if (activeOutputChans[chanNum])
  210319. {
  210320. outputChannelInfo [numOutputChannelInfos].streamNum = i;
  210321. outputChannelInfo [numOutputChannelInfos].dataOffsetSamples = j;
  210322. outputChannelInfo [numOutputChannelInfos].dataStrideSamples = b.mNumberChannels;
  210323. ++numOutputChannelInfos;
  210324. }
  210325. if (name.isEmpty())
  210326. name << "Output " << (chanNum + 1);
  210327. outChanNames.add (name);
  210328. }
  210329. ++chanNum;
  210330. }
  210331. }
  210332. }
  210333. }
  210334. }
  210335. void updateDetailsFromDevice()
  210336. {
  210337. stopTimer();
  210338. if (deviceID == 0)
  210339. return;
  210340. const ScopedLock sl (callbackLock);
  210341. Float64 sr;
  210342. UInt32 size = sizeof (Float64);
  210343. AudioObjectPropertyAddress pa;
  210344. pa.mSelector = kAudioDevicePropertyNominalSampleRate;
  210345. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210346. pa.mElement = kAudioObjectPropertyElementMaster;
  210347. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &sr)))
  210348. sampleRate = sr;
  210349. UInt32 framesPerBuf;
  210350. size = sizeof (framesPerBuf);
  210351. pa.mSelector = kAudioDevicePropertyBufferFrameSize;
  210352. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &framesPerBuf)))
  210353. {
  210354. bufferSize = framesPerBuf;
  210355. allocateTempBuffers();
  210356. }
  210357. bufferSizes.clear();
  210358. pa.mSelector = kAudioDevicePropertyBufferFrameSizeRange;
  210359. if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  210360. {
  210361. HeapBlock <AudioValueRange> ranges;
  210362. ranges.calloc (size, 1);
  210363. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, ranges)))
  210364. {
  210365. bufferSizes.add ((int) ranges[0].mMinimum);
  210366. for (int i = 32; i < 8192; i += 32)
  210367. {
  210368. for (int j = size / (int) sizeof (AudioValueRange); --j >= 0;)
  210369. {
  210370. if (i >= ranges[j].mMinimum && i <= ranges[j].mMaximum)
  210371. {
  210372. bufferSizes.addIfNotAlreadyThere (i);
  210373. break;
  210374. }
  210375. }
  210376. }
  210377. if (bufferSize > 0)
  210378. bufferSizes.addIfNotAlreadyThere (bufferSize);
  210379. }
  210380. }
  210381. if (bufferSizes.size() == 0 && bufferSize > 0)
  210382. bufferSizes.add (bufferSize);
  210383. sampleRates.clear();
  210384. const double possibleRates[] = { 44100.0, 48000.0, 88200.0, 96000.0, 176400.0, 192000.0 };
  210385. String rates;
  210386. pa.mSelector = kAudioDevicePropertyAvailableNominalSampleRates;
  210387. if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  210388. {
  210389. HeapBlock <AudioValueRange> ranges;
  210390. ranges.calloc (size, 1);
  210391. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, ranges)))
  210392. {
  210393. for (int i = 0; i < numElementsInArray (possibleRates); ++i)
  210394. {
  210395. bool ok = false;
  210396. for (int j = size / (int) sizeof (AudioValueRange); --j >= 0;)
  210397. if (possibleRates[i] >= ranges[j].mMinimum - 2 && possibleRates[i] <= ranges[j].mMaximum + 2)
  210398. ok = true;
  210399. if (ok)
  210400. {
  210401. sampleRates.add (possibleRates[i]);
  210402. rates << possibleRates[i] << T(" ");
  210403. }
  210404. }
  210405. }
  210406. }
  210407. if (sampleRates.size() == 0 && sampleRate > 0)
  210408. {
  210409. sampleRates.add (sampleRate);
  210410. rates << sampleRate;
  210411. }
  210412. log (T("sr: ") + rates);
  210413. inputLatency = 0;
  210414. outputLatency = 0;
  210415. UInt32 lat;
  210416. size = sizeof (lat);
  210417. pa.mSelector = kAudioDevicePropertyLatency;
  210418. pa.mScope = kAudioDevicePropertyScopeInput;
  210419. //if (AudioDeviceGetProperty (deviceID, 0, true, kAudioDevicePropertyLatency, &size, &lat) == noErr)
  210420. if (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &lat) == noErr)
  210421. inputLatency = (int) lat;
  210422. pa.mScope = kAudioDevicePropertyScopeOutput;
  210423. size = sizeof (lat);
  210424. if (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &lat) == noErr)
  210425. outputLatency = (int) lat;
  210426. log (T("lat: ") + String (inputLatency) + T(" ") + String (outputLatency));
  210427. inChanNames.clear();
  210428. outChanNames.clear();
  210429. inputChannelInfo.calloc (numInputChans + 2);
  210430. numInputChannelInfos = 0;
  210431. outputChannelInfo.calloc (numOutputChans + 2);
  210432. numOutputChannelInfos = 0;
  210433. fillInChannelInfo (true);
  210434. fillInChannelInfo (false);
  210435. }
  210436. const StringArray getSources (bool input)
  210437. {
  210438. StringArray s;
  210439. HeapBlock <OSType> types;
  210440. const int num = getAllDataSourcesForDevice (deviceID, input, types);
  210441. for (int i = 0; i < num; ++i)
  210442. {
  210443. AudioValueTranslation avt;
  210444. char buffer[256];
  210445. avt.mInputData = (void*) &(types[i]);
  210446. avt.mInputDataSize = sizeof (UInt32);
  210447. avt.mOutputData = buffer;
  210448. avt.mOutputDataSize = 256;
  210449. UInt32 transSize = sizeof (avt);
  210450. AudioObjectPropertyAddress pa;
  210451. pa.mSelector = kAudioDevicePropertyDataSourceNameForID;
  210452. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  210453. pa.mElement = kAudioObjectPropertyElementMaster;
  210454. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &transSize, &avt)))
  210455. {
  210456. DBG (buffer);
  210457. s.add (buffer);
  210458. }
  210459. }
  210460. return s;
  210461. }
  210462. int getCurrentSourceIndex (bool input) const
  210463. {
  210464. OSType currentSourceID = 0;
  210465. UInt32 size = sizeof (currentSourceID);
  210466. int result = -1;
  210467. AudioObjectPropertyAddress pa;
  210468. pa.mSelector = kAudioDevicePropertyDataSource;
  210469. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  210470. pa.mElement = kAudioObjectPropertyElementMaster;
  210471. if (deviceID != 0)
  210472. {
  210473. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &currentSourceID)))
  210474. {
  210475. HeapBlock <OSType> types;
  210476. const int num = getAllDataSourcesForDevice (deviceID, input, types);
  210477. for (int i = 0; i < num; ++i)
  210478. {
  210479. if (types[num] == currentSourceID)
  210480. {
  210481. result = i;
  210482. break;
  210483. }
  210484. }
  210485. }
  210486. }
  210487. return result;
  210488. }
  210489. void setCurrentSourceIndex (int index, bool input)
  210490. {
  210491. if (deviceID != 0)
  210492. {
  210493. HeapBlock <OSType> types;
  210494. const int num = getAllDataSourcesForDevice (deviceID, input, types);
  210495. if (((unsigned int) index) < (unsigned int) num)
  210496. {
  210497. AudioObjectPropertyAddress pa;
  210498. pa.mSelector = kAudioDevicePropertyDataSource;
  210499. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  210500. pa.mElement = kAudioObjectPropertyElementMaster;
  210501. OSType typeId = types[index];
  210502. OK (AudioObjectSetPropertyData (deviceID, &pa, 0, 0, sizeof (typeId), &typeId));
  210503. }
  210504. }
  210505. }
  210506. const String reopen (const BitArray& inputChannels,
  210507. const BitArray& outputChannels,
  210508. double newSampleRate,
  210509. int bufferSizeSamples)
  210510. {
  210511. String error;
  210512. log ("CoreAudio reopen");
  210513. callbacksAllowed = false;
  210514. stopTimer();
  210515. stop (false);
  210516. activeInputChans = inputChannels;
  210517. activeInputChans.setRange (inChanNames.size(),
  210518. activeInputChans.getHighestBit() + 1 - inChanNames.size(),
  210519. false);
  210520. activeOutputChans = outputChannels;
  210521. activeOutputChans.setRange (outChanNames.size(),
  210522. activeOutputChans.getHighestBit() + 1 - outChanNames.size(),
  210523. false);
  210524. numInputChans = activeInputChans.countNumberOfSetBits();
  210525. numOutputChans = activeOutputChans.countNumberOfSetBits();
  210526. // set sample rate
  210527. AudioObjectPropertyAddress pa;
  210528. pa.mSelector = kAudioDevicePropertyNominalSampleRate;
  210529. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210530. pa.mElement = kAudioObjectPropertyElementMaster;
  210531. Float64 sr = newSampleRate;
  210532. if (! OK (AudioObjectSetPropertyData (deviceID, &pa, 0, 0, sizeof (sr), &sr)))
  210533. {
  210534. error = "Couldn't change sample rate";
  210535. }
  210536. else
  210537. {
  210538. // change buffer size
  210539. UInt32 framesPerBuf = bufferSizeSamples;
  210540. pa.mSelector = kAudioDevicePropertyBufferFrameSize;
  210541. if (! OK (AudioObjectSetPropertyData (deviceID, &pa, 0, 0, sizeof (framesPerBuf), &framesPerBuf)))
  210542. {
  210543. error = "Couldn't change buffer size";
  210544. }
  210545. else
  210546. {
  210547. // Annoyingly, after changing the rate and buffer size, some devices fail to
  210548. // correctly report their new settings until some random time in the future, so
  210549. // after calling updateDetailsFromDevice, we need to manually bodge these values
  210550. // to make sure we're using the correct numbers..
  210551. updateDetailsFromDevice();
  210552. sampleRate = newSampleRate;
  210553. bufferSize = bufferSizeSamples;
  210554. if (sampleRates.size() == 0)
  210555. error = "Device has no available sample-rates";
  210556. else if (bufferSizes.size() == 0)
  210557. error = "Device has no available buffer-sizes";
  210558. else if (inputDevice != 0)
  210559. error = inputDevice->reopen (inputChannels,
  210560. outputChannels,
  210561. newSampleRate,
  210562. bufferSizeSamples);
  210563. }
  210564. }
  210565. callbacksAllowed = true;
  210566. return error;
  210567. }
  210568. bool start (AudioIODeviceCallback* cb)
  210569. {
  210570. if (! started)
  210571. {
  210572. callback = 0;
  210573. if (deviceID != 0)
  210574. {
  210575. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  210576. if (OK (AudioDeviceAddIOProc (deviceID, audioIOProc, (void*) this)))
  210577. #else
  210578. if (OK (AudioDeviceCreateIOProcID (deviceID, audioIOProc, (void*) this, &audioProcID)))
  210579. #endif
  210580. {
  210581. if (OK (AudioDeviceStart (deviceID, audioIOProc)))
  210582. {
  210583. started = true;
  210584. }
  210585. else
  210586. {
  210587. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  210588. OK (AudioDeviceRemoveIOProc (deviceID, audioIOProc));
  210589. #else
  210590. OK (AudioDeviceDestroyIOProcID (deviceID, audioProcID));
  210591. audioProcID = 0;
  210592. #endif
  210593. }
  210594. }
  210595. }
  210596. }
  210597. if (started)
  210598. {
  210599. const ScopedLock sl (callbackLock);
  210600. callback = cb;
  210601. }
  210602. if (inputDevice != 0)
  210603. return started && inputDevice->start (cb);
  210604. else
  210605. return started;
  210606. }
  210607. void stop (bool leaveInterruptRunning)
  210608. {
  210609. callbackLock.enter();
  210610. callback = 0;
  210611. callbackLock.exit();
  210612. if (started
  210613. && (deviceID != 0)
  210614. && ! leaveInterruptRunning)
  210615. {
  210616. OK (AudioDeviceStop (deviceID, audioIOProc));
  210617. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  210618. OK (AudioDeviceRemoveIOProc (deviceID, audioIOProc));
  210619. #else
  210620. OK (AudioDeviceDestroyIOProcID (deviceID, audioProcID));
  210621. audioProcID = 0;
  210622. #endif
  210623. started = false;
  210624. callbackLock.enter();
  210625. callbackLock.exit();
  210626. // wait until it's definately stopped calling back..
  210627. for (int i = 40; --i >= 0;)
  210628. {
  210629. Thread::sleep (50);
  210630. UInt32 running = 0;
  210631. UInt32 size = sizeof (running);
  210632. AudioObjectPropertyAddress pa;
  210633. pa.mSelector = kAudioDevicePropertyDeviceIsRunning;
  210634. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210635. pa.mElement = kAudioObjectPropertyElementMaster;
  210636. OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &running));
  210637. if (running == 0)
  210638. break;
  210639. }
  210640. callbackLock.enter();
  210641. callbackLock.exit();
  210642. }
  210643. if (inputDevice != 0)
  210644. inputDevice->stop (leaveInterruptRunning);
  210645. }
  210646. double getSampleRate() const
  210647. {
  210648. return sampleRate;
  210649. }
  210650. int getBufferSize() const
  210651. {
  210652. return bufferSize;
  210653. }
  210654. void audioCallback (const AudioBufferList* inInputData,
  210655. AudioBufferList* outOutputData)
  210656. {
  210657. int i;
  210658. const ScopedLock sl (callbackLock);
  210659. if (callback != 0)
  210660. {
  210661. if (inputDevice == 0)
  210662. {
  210663. for (i = numInputChans; --i >= 0;)
  210664. {
  210665. const CallbackDetailsForChannel& info = inputChannelInfo[i];
  210666. float* dest = tempInputBuffers [i];
  210667. const float* src = ((const float*) inInputData->mBuffers[info.streamNum].mData)
  210668. + info.dataOffsetSamples;
  210669. const int stride = info.dataStrideSamples;
  210670. if (stride != 0) // if this is zero, info is invalid
  210671. {
  210672. for (int j = bufferSize; --j >= 0;)
  210673. {
  210674. *dest++ = *src;
  210675. src += stride;
  210676. }
  210677. }
  210678. }
  210679. }
  210680. if (! isSlaveDevice)
  210681. {
  210682. if (inputDevice == 0)
  210683. {
  210684. callback->audioDeviceIOCallback ((const float**) tempInputBuffers,
  210685. numInputChans,
  210686. tempOutputBuffers,
  210687. numOutputChans,
  210688. bufferSize);
  210689. }
  210690. else
  210691. {
  210692. jassert (inputDevice->bufferSize == bufferSize);
  210693. // Sometimes the two linked devices seem to get their callbacks in
  210694. // parallel, so we need to lock both devices to stop the input data being
  210695. // changed while inside our callback..
  210696. const ScopedLock sl2 (inputDevice->callbackLock);
  210697. callback->audioDeviceIOCallback ((const float**) inputDevice->tempInputBuffers,
  210698. inputDevice->numInputChans,
  210699. tempOutputBuffers,
  210700. numOutputChans,
  210701. bufferSize);
  210702. }
  210703. for (i = numOutputChans; --i >= 0;)
  210704. {
  210705. const CallbackDetailsForChannel& info = outputChannelInfo[i];
  210706. const float* src = tempOutputBuffers [i];
  210707. float* dest = ((float*) outOutputData->mBuffers[info.streamNum].mData)
  210708. + info.dataOffsetSamples;
  210709. const int stride = info.dataStrideSamples;
  210710. if (stride != 0) // if this is zero, info is invalid
  210711. {
  210712. for (int j = bufferSize; --j >= 0;)
  210713. {
  210714. *dest = *src++;
  210715. dest += stride;
  210716. }
  210717. }
  210718. }
  210719. }
  210720. }
  210721. else
  210722. {
  210723. for (i = jmin (numOutputChans, numOutputChannelInfos); --i >= 0;)
  210724. {
  210725. const CallbackDetailsForChannel& info = outputChannelInfo[i];
  210726. float* dest = ((float*) outOutputData->mBuffers[info.streamNum].mData)
  210727. + info.dataOffsetSamples;
  210728. const int stride = info.dataStrideSamples;
  210729. if (stride != 0) // if this is zero, info is invalid
  210730. {
  210731. for (int j = bufferSize; --j >= 0;)
  210732. {
  210733. *dest = 0.0f;
  210734. dest += stride;
  210735. }
  210736. }
  210737. }
  210738. }
  210739. }
  210740. // called by callbacks
  210741. void deviceDetailsChanged()
  210742. {
  210743. if (callbacksAllowed)
  210744. startTimer (100);
  210745. }
  210746. void timerCallback()
  210747. {
  210748. stopTimer();
  210749. log ("CoreAudio device changed callback");
  210750. const double oldSampleRate = sampleRate;
  210751. const int oldBufferSize = bufferSize;
  210752. updateDetailsFromDevice();
  210753. if (oldBufferSize != bufferSize || oldSampleRate != sampleRate)
  210754. {
  210755. callbacksAllowed = false;
  210756. stop (false);
  210757. updateDetailsFromDevice();
  210758. callbacksAllowed = true;
  210759. }
  210760. }
  210761. CoreAudioInternal* getRelatedDevice() const
  210762. {
  210763. UInt32 size = 0;
  210764. ScopedPointer <CoreAudioInternal> result;
  210765. AudioObjectPropertyAddress pa;
  210766. pa.mSelector = kAudioDevicePropertyRelatedDevices;
  210767. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210768. pa.mElement = kAudioObjectPropertyElementMaster;
  210769. if (deviceID != 0
  210770. && AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size) == noErr
  210771. && size > 0)
  210772. {
  210773. HeapBlock <AudioDeviceID> devs;
  210774. devs.calloc (size, 1);
  210775. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, devs)))
  210776. {
  210777. for (unsigned int i = 0; i < size / sizeof (AudioDeviceID); ++i)
  210778. {
  210779. if (devs[i] != deviceID && devs[i] != 0)
  210780. {
  210781. result = new CoreAudioInternal (devs[i]);
  210782. const bool thisIsInput = inChanNames.size() > 0 && outChanNames.size() == 0;
  210783. const bool otherIsInput = result->inChanNames.size() > 0 && result->outChanNames.size() == 0;
  210784. if (thisIsInput != otherIsInput
  210785. || (inChanNames.size() + outChanNames.size() == 0)
  210786. || (result->inChanNames.size() + result->outChanNames.size()) == 0)
  210787. break;
  210788. result = 0;
  210789. }
  210790. }
  210791. }
  210792. }
  210793. return result.release();
  210794. }
  210795. juce_UseDebuggingNewOperator
  210796. int inputLatency, outputLatency;
  210797. BitArray activeInputChans, activeOutputChans;
  210798. StringArray inChanNames, outChanNames;
  210799. Array <double> sampleRates;
  210800. Array <int> bufferSizes;
  210801. AudioIODeviceCallback* callback;
  210802. #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
  210803. AudioDeviceIOProcID audioProcID;
  210804. #endif
  210805. CoreAudioInternal* inputDevice;
  210806. bool isSlaveDevice;
  210807. private:
  210808. CriticalSection callbackLock;
  210809. AudioDeviceID deviceID;
  210810. bool started;
  210811. double sampleRate;
  210812. int bufferSize;
  210813. HeapBlock <float> audioBuffer;
  210814. int numInputChans, numOutputChans;
  210815. bool callbacksAllowed;
  210816. struct CallbackDetailsForChannel
  210817. {
  210818. int streamNum;
  210819. int dataOffsetSamples;
  210820. int dataStrideSamples;
  210821. };
  210822. int numInputChannelInfos, numOutputChannelInfos;
  210823. HeapBlock <CallbackDetailsForChannel> inputChannelInfo, outputChannelInfo;
  210824. HeapBlock <float*> tempInputBuffers, tempOutputBuffers;
  210825. CoreAudioInternal (const CoreAudioInternal&);
  210826. const CoreAudioInternal& operator= (const CoreAudioInternal&);
  210827. static OSStatus audioIOProc (AudioDeviceID inDevice,
  210828. const AudioTimeStamp* inNow,
  210829. const AudioBufferList* inInputData,
  210830. const AudioTimeStamp* inInputTime,
  210831. AudioBufferList* outOutputData,
  210832. const AudioTimeStamp* inOutputTime,
  210833. void* device)
  210834. {
  210835. ((CoreAudioInternal*) device)->audioCallback (inInputData, outOutputData);
  210836. return noErr;
  210837. }
  210838. static OSStatus deviceListenerProc (AudioDeviceID /*inDevice*/, UInt32 /*inLine*/, const AudioObjectPropertyAddress* pa, void* inClientData)
  210839. {
  210840. CoreAudioInternal* const intern = (CoreAudioInternal*) inClientData;
  210841. switch (pa->mSelector)
  210842. {
  210843. case kAudioDevicePropertyBufferSize:
  210844. case kAudioDevicePropertyBufferFrameSize:
  210845. case kAudioDevicePropertyNominalSampleRate:
  210846. case kAudioDevicePropertyStreamFormat:
  210847. case kAudioDevicePropertyDeviceIsAlive:
  210848. intern->deviceDetailsChanged();
  210849. break;
  210850. case kAudioDevicePropertyBufferSizeRange:
  210851. case kAudioDevicePropertyVolumeScalar:
  210852. case kAudioDevicePropertyMute:
  210853. case kAudioDevicePropertyPlayThru:
  210854. case kAudioDevicePropertyDataSource:
  210855. case kAudioDevicePropertyDeviceIsRunning:
  210856. break;
  210857. }
  210858. return noErr;
  210859. }
  210860. static int getAllDataSourcesForDevice (AudioDeviceID deviceID, const bool input, HeapBlock <OSType>& types)
  210861. {
  210862. AudioObjectPropertyAddress pa;
  210863. pa.mSelector = kAudioDevicePropertyDataSources;
  210864. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210865. pa.mElement = kAudioObjectPropertyElementMaster;
  210866. UInt32 size = 0;
  210867. if (deviceID != 0
  210868. && OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  210869. {
  210870. types.calloc (size, 1);
  210871. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, types)))
  210872. return size / (int) sizeof (OSType);
  210873. }
  210874. return 0;
  210875. }
  210876. };
  210877. class CoreAudioIODevice : public AudioIODevice
  210878. {
  210879. public:
  210880. CoreAudioIODevice (const String& deviceName,
  210881. AudioDeviceID inputDeviceId,
  210882. const int inputIndex_,
  210883. AudioDeviceID outputDeviceId,
  210884. const int outputIndex_)
  210885. : AudioIODevice (deviceName, "CoreAudio"),
  210886. inputIndex (inputIndex_),
  210887. outputIndex (outputIndex_),
  210888. isOpen_ (false),
  210889. isStarted (false)
  210890. {
  210891. internal = 0;
  210892. CoreAudioInternal* device = 0;
  210893. if (outputDeviceId == 0 || outputDeviceId == inputDeviceId)
  210894. {
  210895. jassert (inputDeviceId != 0);
  210896. device = new CoreAudioInternal (inputDeviceId);
  210897. }
  210898. else
  210899. {
  210900. device = new CoreAudioInternal (outputDeviceId);
  210901. if (inputDeviceId != 0)
  210902. {
  210903. CoreAudioInternal* secondDevice = new CoreAudioInternal (inputDeviceId);
  210904. device->inputDevice = secondDevice;
  210905. secondDevice->isSlaveDevice = true;
  210906. }
  210907. }
  210908. internal = device;
  210909. AudioObjectPropertyAddress pa;
  210910. pa.mSelector = kAudioObjectPropertySelectorWildcard;
  210911. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210912. pa.mElement = kAudioObjectPropertyElementWildcard;
  210913. AudioObjectAddPropertyListener (kAudioObjectSystemObject, &pa, hardwareListenerProc, internal);
  210914. }
  210915. ~CoreAudioIODevice()
  210916. {
  210917. AudioObjectPropertyAddress pa;
  210918. pa.mSelector = kAudioObjectPropertySelectorWildcard;
  210919. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210920. pa.mElement = kAudioObjectPropertyElementWildcard;
  210921. AudioObjectRemovePropertyListener (kAudioObjectSystemObject, &pa, hardwareListenerProc, internal);
  210922. delete internal;
  210923. }
  210924. const StringArray getOutputChannelNames()
  210925. {
  210926. return internal->outChanNames;
  210927. }
  210928. const StringArray getInputChannelNames()
  210929. {
  210930. if (internal->inputDevice != 0)
  210931. return internal->inputDevice->inChanNames;
  210932. else
  210933. return internal->inChanNames;
  210934. }
  210935. int getNumSampleRates()
  210936. {
  210937. return internal->sampleRates.size();
  210938. }
  210939. double getSampleRate (int index)
  210940. {
  210941. return internal->sampleRates [index];
  210942. }
  210943. int getNumBufferSizesAvailable()
  210944. {
  210945. return internal->bufferSizes.size();
  210946. }
  210947. int getBufferSizeSamples (int index)
  210948. {
  210949. return internal->bufferSizes [index];
  210950. }
  210951. int getDefaultBufferSize()
  210952. {
  210953. for (int i = 0; i < getNumBufferSizesAvailable(); ++i)
  210954. if (getBufferSizeSamples(i) >= 512)
  210955. return getBufferSizeSamples(i);
  210956. return 512;
  210957. }
  210958. const String open (const BitArray& inputChannels,
  210959. const BitArray& outputChannels,
  210960. double sampleRate,
  210961. int bufferSizeSamples)
  210962. {
  210963. isOpen_ = true;
  210964. if (bufferSizeSamples <= 0)
  210965. bufferSizeSamples = getDefaultBufferSize();
  210966. lastError = internal->reopen (inputChannels, outputChannels, sampleRate, bufferSizeSamples);
  210967. isOpen_ = lastError.isEmpty();
  210968. return lastError;
  210969. }
  210970. void close()
  210971. {
  210972. isOpen_ = false;
  210973. internal->stop (false);
  210974. }
  210975. bool isOpen()
  210976. {
  210977. return isOpen_;
  210978. }
  210979. int getCurrentBufferSizeSamples()
  210980. {
  210981. return internal != 0 ? internal->getBufferSize() : 512;
  210982. }
  210983. double getCurrentSampleRate()
  210984. {
  210985. return internal != 0 ? internal->getSampleRate() : 0;
  210986. }
  210987. int getCurrentBitDepth()
  210988. {
  210989. return 32; // no way to find out, so just assume it's high..
  210990. }
  210991. const BitArray getActiveOutputChannels() const
  210992. {
  210993. return internal != 0 ? internal->activeOutputChans : BitArray();
  210994. }
  210995. const BitArray getActiveInputChannels() const
  210996. {
  210997. BitArray chans;
  210998. if (internal != 0)
  210999. {
  211000. chans = internal->activeInputChans;
  211001. if (internal->inputDevice != 0)
  211002. chans.orWith (internal->inputDevice->activeInputChans);
  211003. }
  211004. return chans;
  211005. }
  211006. int getOutputLatencyInSamples()
  211007. {
  211008. if (internal == 0)
  211009. return 0;
  211010. // this seems like a good guess at getting the latency right - comparing
  211011. // this with a round-trip measurement, it gets it to within a few millisecs
  211012. // for the built-in mac soundcard
  211013. return internal->outputLatency + internal->getBufferSize() * 2;
  211014. }
  211015. int getInputLatencyInSamples()
  211016. {
  211017. if (internal == 0)
  211018. return 0;
  211019. return internal->inputLatency + internal->getBufferSize() * 2;
  211020. }
  211021. void start (AudioIODeviceCallback* callback)
  211022. {
  211023. if (internal != 0 && ! isStarted)
  211024. {
  211025. if (callback != 0)
  211026. callback->audioDeviceAboutToStart (this);
  211027. isStarted = true;
  211028. internal->start (callback);
  211029. }
  211030. }
  211031. void stop()
  211032. {
  211033. if (isStarted && internal != 0)
  211034. {
  211035. AudioIODeviceCallback* const lastCallback = internal->callback;
  211036. isStarted = false;
  211037. internal->stop (true);
  211038. if (lastCallback != 0)
  211039. lastCallback->audioDeviceStopped();
  211040. }
  211041. }
  211042. bool isPlaying()
  211043. {
  211044. if (internal->callback == 0)
  211045. isStarted = false;
  211046. return isStarted;
  211047. }
  211048. const String getLastError()
  211049. {
  211050. return lastError;
  211051. }
  211052. int inputIndex, outputIndex;
  211053. juce_UseDebuggingNewOperator
  211054. private:
  211055. CoreAudioInternal* internal;
  211056. bool isOpen_, isStarted;
  211057. String lastError;
  211058. static OSStatus hardwareListenerProc (AudioDeviceID /*inDevice*/, UInt32 /*inLine*/, const AudioObjectPropertyAddress* pa, void* inClientData)
  211059. {
  211060. CoreAudioInternal* const intern = (CoreAudioInternal*) inClientData;
  211061. switch (pa->mSelector)
  211062. {
  211063. case kAudioHardwarePropertyDevices:
  211064. intern->deviceDetailsChanged();
  211065. break;
  211066. case kAudioHardwarePropertyDefaultOutputDevice:
  211067. case kAudioHardwarePropertyDefaultInputDevice:
  211068. case kAudioHardwarePropertyDefaultSystemOutputDevice:
  211069. break;
  211070. }
  211071. return noErr;
  211072. }
  211073. CoreAudioIODevice (const CoreAudioIODevice&);
  211074. const CoreAudioIODevice& operator= (const CoreAudioIODevice&);
  211075. };
  211076. class CoreAudioIODeviceType : public AudioIODeviceType
  211077. {
  211078. public:
  211079. CoreAudioIODeviceType()
  211080. : AudioIODeviceType (T("CoreAudio")),
  211081. hasScanned (false)
  211082. {
  211083. }
  211084. ~CoreAudioIODeviceType()
  211085. {
  211086. }
  211087. void scanForDevices()
  211088. {
  211089. hasScanned = true;
  211090. inputDeviceNames.clear();
  211091. outputDeviceNames.clear();
  211092. inputIds.clear();
  211093. outputIds.clear();
  211094. UInt32 size;
  211095. AudioObjectPropertyAddress pa;
  211096. pa.mSelector = kAudioHardwarePropertyDevices;
  211097. pa.mScope = kAudioObjectPropertyScopeWildcard;
  211098. pa.mElement = kAudioObjectPropertyElementMaster;
  211099. if (OK (AudioObjectGetPropertyDataSize (kAudioObjectSystemObject, &pa, 0, 0, &size)))
  211100. {
  211101. HeapBlock <AudioDeviceID> devs;
  211102. devs.calloc (size, 1);
  211103. if (OK (AudioObjectGetPropertyData (kAudioObjectSystemObject, &pa, 0, 0, &size, devs)))
  211104. {
  211105. static bool alreadyLogged = false;
  211106. const int num = size / (int) sizeof (AudioDeviceID);
  211107. for (int i = 0; i < num; ++i)
  211108. {
  211109. char name [1024];
  211110. size = sizeof (name);
  211111. pa.mSelector = kAudioDevicePropertyDeviceName;
  211112. if (OK (AudioObjectGetPropertyData (devs[i], &pa, 0, 0, &size, name)))
  211113. {
  211114. const String nameString (String::fromUTF8 ((const uint8*) name, (int) strlen (name)));
  211115. if (! alreadyLogged)
  211116. log (T("CoreAudio device: ") + nameString);
  211117. const int numIns = getNumChannels (devs[i], true);
  211118. const int numOuts = getNumChannels (devs[i], false);
  211119. if (numIns > 0)
  211120. {
  211121. inputDeviceNames.add (nameString);
  211122. inputIds.add (devs[i]);
  211123. }
  211124. if (numOuts > 0)
  211125. {
  211126. outputDeviceNames.add (nameString);
  211127. outputIds.add (devs[i]);
  211128. }
  211129. }
  211130. }
  211131. alreadyLogged = true;
  211132. }
  211133. }
  211134. inputDeviceNames.appendNumbersToDuplicates (false, true);
  211135. outputDeviceNames.appendNumbersToDuplicates (false, true);
  211136. }
  211137. const StringArray getDeviceNames (const bool wantInputNames) const
  211138. {
  211139. jassert (hasScanned); // need to call scanForDevices() before doing this
  211140. if (wantInputNames)
  211141. return inputDeviceNames;
  211142. else
  211143. return outputDeviceNames;
  211144. }
  211145. int getDefaultDeviceIndex (const bool forInput) const
  211146. {
  211147. jassert (hasScanned); // need to call scanForDevices() before doing this
  211148. AudioDeviceID deviceID;
  211149. UInt32 size = sizeof (deviceID);
  211150. // if they're asking for any input channels at all, use the default input, so we
  211151. // get the built-in mic rather than the built-in output with no inputs..
  211152. AudioObjectPropertyAddress pa;
  211153. pa.mSelector = forInput ? kAudioHardwarePropertyDefaultInputDevice : kAudioHardwarePropertyDefaultOutputDevice;
  211154. pa.mScope = kAudioObjectPropertyScopeWildcard;
  211155. pa.mElement = kAudioObjectPropertyElementMaster;
  211156. if (AudioObjectGetPropertyData (kAudioObjectSystemObject, &pa, 0, 0, &size, &deviceID) == noErr)
  211157. {
  211158. if (forInput)
  211159. {
  211160. for (int i = inputIds.size(); --i >= 0;)
  211161. if (inputIds[i] == deviceID)
  211162. return i;
  211163. }
  211164. else
  211165. {
  211166. for (int i = outputIds.size(); --i >= 0;)
  211167. if (outputIds[i] == deviceID)
  211168. return i;
  211169. }
  211170. }
  211171. return 0;
  211172. }
  211173. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  211174. {
  211175. jassert (hasScanned); // need to call scanForDevices() before doing this
  211176. CoreAudioIODevice* const d = dynamic_cast <CoreAudioIODevice*> (device);
  211177. if (d == 0)
  211178. return -1;
  211179. return asInput ? d->inputIndex
  211180. : d->outputIndex;
  211181. }
  211182. bool hasSeparateInputsAndOutputs() const { return true; }
  211183. AudioIODevice* createDevice (const String& outputDeviceName,
  211184. const String& inputDeviceName)
  211185. {
  211186. jassert (hasScanned); // need to call scanForDevices() before doing this
  211187. const int inputIndex = inputDeviceNames.indexOf (inputDeviceName);
  211188. const int outputIndex = outputDeviceNames.indexOf (outputDeviceName);
  211189. String deviceName (outputDeviceName);
  211190. if (deviceName.isEmpty())
  211191. deviceName = inputDeviceName;
  211192. if (index >= 0)
  211193. return new CoreAudioIODevice (deviceName,
  211194. inputIds [inputIndex],
  211195. inputIndex,
  211196. outputIds [outputIndex],
  211197. outputIndex);
  211198. return 0;
  211199. }
  211200. juce_UseDebuggingNewOperator
  211201. private:
  211202. StringArray inputDeviceNames, outputDeviceNames;
  211203. Array <AudioDeviceID> inputIds, outputIds;
  211204. bool hasScanned;
  211205. static int getNumChannels (AudioDeviceID deviceID, bool input)
  211206. {
  211207. int total = 0;
  211208. UInt32 size;
  211209. AudioObjectPropertyAddress pa;
  211210. pa.mSelector = kAudioDevicePropertyStreamConfiguration;
  211211. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  211212. pa.mElement = kAudioObjectPropertyElementMaster;
  211213. if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  211214. {
  211215. HeapBlock <AudioBufferList> bufList;
  211216. bufList.calloc (size, 1);
  211217. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, bufList)))
  211218. {
  211219. const int numStreams = bufList->mNumberBuffers;
  211220. for (int i = 0; i < numStreams; ++i)
  211221. {
  211222. const AudioBuffer& b = bufList->mBuffers[i];
  211223. total += b.mNumberChannels;
  211224. }
  211225. }
  211226. }
  211227. return total;
  211228. }
  211229. CoreAudioIODeviceType (const CoreAudioIODeviceType&);
  211230. const CoreAudioIODeviceType& operator= (const CoreAudioIODeviceType&);
  211231. };
  211232. AudioIODeviceType* juce_createAudioIODeviceType_CoreAudio()
  211233. {
  211234. return new CoreAudioIODeviceType();
  211235. }
  211236. #undef log
  211237. #endif
  211238. /*** End of inlined file: juce_mac_CoreAudio.cpp ***/
  211239. /*** Start of inlined file: juce_mac_CoreMidi.cpp ***/
  211240. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  211241. // compiled on its own).
  211242. #if JUCE_INCLUDED_FILE
  211243. #if JUCE_MAC
  211244. #undef log
  211245. #define log(a) Logger::writeToLog(a)
  211246. static bool logAnyErrorsMidi (const OSStatus err, const int lineNum)
  211247. {
  211248. if (err == noErr)
  211249. return true;
  211250. log (T("CoreMidi error: ") + String (lineNum) + T(" - ") + String::toHexString ((int)err));
  211251. jassertfalse
  211252. return false;
  211253. }
  211254. #undef OK
  211255. #define OK(a) logAnyErrorsMidi(a, __LINE__)
  211256. static const String getEndpointName (MIDIEndpointRef endpoint, bool isExternal)
  211257. {
  211258. String result;
  211259. CFStringRef str = 0;
  211260. MIDIObjectGetStringProperty (endpoint, kMIDIPropertyName, &str);
  211261. if (str != 0)
  211262. {
  211263. result = PlatformUtilities::cfStringToJuceString (str);
  211264. CFRelease (str);
  211265. str = 0;
  211266. }
  211267. MIDIEntityRef entity = 0;
  211268. MIDIEndpointGetEntity (endpoint, &entity);
  211269. if (entity == 0)
  211270. return result; // probably virtual
  211271. if (result.isEmpty())
  211272. {
  211273. // endpoint name has zero length - try the entity
  211274. MIDIObjectGetStringProperty (entity, kMIDIPropertyName, &str);
  211275. if (str != 0)
  211276. {
  211277. result += PlatformUtilities::cfStringToJuceString (str);
  211278. CFRelease (str);
  211279. str = 0;
  211280. }
  211281. }
  211282. // now consider the device's name
  211283. MIDIDeviceRef device = 0;
  211284. MIDIEntityGetDevice (entity, &device);
  211285. if (device == 0)
  211286. return result;
  211287. MIDIObjectGetStringProperty (device, kMIDIPropertyName, &str);
  211288. if (str != 0)
  211289. {
  211290. const String s (PlatformUtilities::cfStringToJuceString (str));
  211291. CFRelease (str);
  211292. // if an external device has only one entity, throw away
  211293. // the endpoint name and just use the device name
  211294. if (isExternal && MIDIDeviceGetNumberOfEntities (device) < 2)
  211295. {
  211296. result = s;
  211297. }
  211298. else if (! result.startsWithIgnoreCase (s))
  211299. {
  211300. // prepend the device name to the entity name
  211301. result = (s + T(" ") + result).trimEnd();
  211302. }
  211303. }
  211304. return result;
  211305. }
  211306. static const String getConnectedEndpointName (MIDIEndpointRef endpoint)
  211307. {
  211308. String result;
  211309. // Does the endpoint have connections?
  211310. CFDataRef connections = 0;
  211311. int numConnections = 0;
  211312. MIDIObjectGetDataProperty (endpoint, kMIDIPropertyConnectionUniqueID, &connections);
  211313. if (connections != 0)
  211314. {
  211315. numConnections = (int) (CFDataGetLength (connections) / sizeof (MIDIUniqueID));
  211316. if (numConnections > 0)
  211317. {
  211318. const SInt32* pid = reinterpret_cast <const SInt32*> (CFDataGetBytePtr (connections));
  211319. for (int i = 0; i < numConnections; ++i, ++pid)
  211320. {
  211321. MIDIUniqueID uid = EndianS32_BtoN (*pid);
  211322. MIDIObjectRef connObject;
  211323. MIDIObjectType connObjectType;
  211324. OSStatus err = MIDIObjectFindByUniqueID (uid, &connObject, &connObjectType);
  211325. if (err == noErr)
  211326. {
  211327. String s;
  211328. if (connObjectType == kMIDIObjectType_ExternalSource
  211329. || connObjectType == kMIDIObjectType_ExternalDestination)
  211330. {
  211331. // Connected to an external device's endpoint (10.3 and later).
  211332. s = getEndpointName (static_cast <MIDIEndpointRef> (connObject), true);
  211333. }
  211334. else
  211335. {
  211336. // Connected to an external device (10.2) (or something else, catch-all)
  211337. CFStringRef str = 0;
  211338. MIDIObjectGetStringProperty (connObject, kMIDIPropertyName, &str);
  211339. if (str != 0)
  211340. {
  211341. s = PlatformUtilities::cfStringToJuceString (str);
  211342. CFRelease (str);
  211343. }
  211344. }
  211345. if (s.isNotEmpty())
  211346. {
  211347. if (result.isNotEmpty())
  211348. result += (", ");
  211349. result += s;
  211350. }
  211351. }
  211352. }
  211353. }
  211354. CFRelease (connections);
  211355. }
  211356. if (result.isNotEmpty())
  211357. return result;
  211358. // Here, either the endpoint had no connections, or we failed to obtain names for any of them.
  211359. return getEndpointName (endpoint, false);
  211360. }
  211361. const StringArray MidiOutput::getDevices()
  211362. {
  211363. StringArray s;
  211364. const ItemCount num = MIDIGetNumberOfDestinations();
  211365. for (ItemCount i = 0; i < num; ++i)
  211366. {
  211367. MIDIEndpointRef dest = MIDIGetDestination (i);
  211368. if (dest != 0)
  211369. {
  211370. String name (getConnectedEndpointName (dest));
  211371. if (name.isEmpty())
  211372. name = "<error>";
  211373. s.add (name);
  211374. }
  211375. else
  211376. {
  211377. s.add ("<error>");
  211378. }
  211379. }
  211380. return s;
  211381. }
  211382. int MidiOutput::getDefaultDeviceIndex()
  211383. {
  211384. return 0;
  211385. }
  211386. static MIDIClientRef globalMidiClient;
  211387. static bool hasGlobalClientBeenCreated = false;
  211388. static bool makeSureClientExists()
  211389. {
  211390. if (! hasGlobalClientBeenCreated)
  211391. {
  211392. String name (T("JUCE"));
  211393. if (JUCEApplication::getInstance() != 0)
  211394. name = JUCEApplication::getInstance()->getApplicationName();
  211395. CFStringRef appName = PlatformUtilities::juceStringToCFString (name);
  211396. hasGlobalClientBeenCreated = OK (MIDIClientCreate (appName, 0, 0, &globalMidiClient));
  211397. CFRelease (appName);
  211398. }
  211399. return hasGlobalClientBeenCreated;
  211400. }
  211401. class MidiPortAndEndpoint
  211402. {
  211403. public:
  211404. MidiPortAndEndpoint (MIDIPortRef port_, MIDIEndpointRef endPoint_)
  211405. : port (port_), endPoint (endPoint_)
  211406. {
  211407. }
  211408. ~MidiPortAndEndpoint()
  211409. {
  211410. if (port != 0)
  211411. MIDIPortDispose (port);
  211412. if (port == 0 && endPoint != 0) // if port == 0, it means we created the endpoint, so it's safe to delete it
  211413. MIDIEndpointDispose (endPoint);
  211414. }
  211415. MIDIPortRef port;
  211416. MIDIEndpointRef endPoint;
  211417. };
  211418. MidiOutput* MidiOutput::openDevice (int index)
  211419. {
  211420. MidiOutput* mo = 0;
  211421. if (((unsigned int) index) < (unsigned int) MIDIGetNumberOfDestinations())
  211422. {
  211423. MIDIEndpointRef endPoint = MIDIGetDestination (index);
  211424. CFStringRef pname;
  211425. if (OK (MIDIObjectGetStringProperty (endPoint, kMIDIPropertyName, &pname)))
  211426. {
  211427. log (T("CoreMidi - opening out: ") + PlatformUtilities::cfStringToJuceString (pname));
  211428. if (makeSureClientExists())
  211429. {
  211430. MIDIPortRef port;
  211431. if (OK (MIDIOutputPortCreate (globalMidiClient, pname, &port)))
  211432. {
  211433. mo = new MidiOutput();
  211434. mo->internal = (void*) new MidiPortAndEndpoint (port, endPoint);
  211435. }
  211436. }
  211437. CFRelease (pname);
  211438. }
  211439. }
  211440. return mo;
  211441. }
  211442. MidiOutput* MidiOutput::createNewDevice (const String& deviceName)
  211443. {
  211444. MidiOutput* mo = 0;
  211445. if (makeSureClientExists())
  211446. {
  211447. MIDIEndpointRef endPoint;
  211448. CFStringRef name = PlatformUtilities::juceStringToCFString (deviceName);
  211449. if (OK (MIDISourceCreate (globalMidiClient, name, &endPoint)))
  211450. {
  211451. mo = new MidiOutput();
  211452. mo->internal = (void*) new MidiPortAndEndpoint (0, endPoint);
  211453. }
  211454. CFRelease (name);
  211455. }
  211456. return mo;
  211457. }
  211458. MidiOutput::~MidiOutput()
  211459. {
  211460. delete (MidiPortAndEndpoint*) internal;
  211461. }
  211462. void MidiOutput::reset()
  211463. {
  211464. }
  211465. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  211466. {
  211467. return false;
  211468. }
  211469. void MidiOutput::setVolume (float leftVol, float rightVol)
  211470. {
  211471. }
  211472. void MidiOutput::sendMessageNow (const MidiMessage& message)
  211473. {
  211474. MidiPortAndEndpoint* const mpe = (MidiPortAndEndpoint*) internal;
  211475. if (message.isSysEx())
  211476. {
  211477. const int maxPacketSize = 256;
  211478. int pos = 0, bytesLeft = message.getRawDataSize();
  211479. const int numPackets = (bytesLeft + maxPacketSize - 1) / maxPacketSize;
  211480. HeapBlock <MIDIPacketList> packets;
  211481. packets.malloc (32 * numPackets + message.getRawDataSize(), 1);
  211482. packets->numPackets = numPackets;
  211483. MIDIPacket* p = packets->packet;
  211484. for (int i = 0; i < numPackets; ++i)
  211485. {
  211486. p->timeStamp = 0;
  211487. p->length = jmin (maxPacketSize, bytesLeft);
  211488. memcpy (p->data, message.getRawData() + pos, p->length);
  211489. pos += p->length;
  211490. bytesLeft -= p->length;
  211491. p = MIDIPacketNext (p);
  211492. }
  211493. if (mpe->port != 0)
  211494. MIDISend (mpe->port, mpe->endPoint, packets);
  211495. else
  211496. MIDIReceived (mpe->endPoint, packets);
  211497. }
  211498. else
  211499. {
  211500. MIDIPacketList packets;
  211501. packets.numPackets = 1;
  211502. packets.packet[0].timeStamp = 0;
  211503. packets.packet[0].length = message.getRawDataSize();
  211504. *(int*) (packets.packet[0].data) = *(const int*) message.getRawData();
  211505. if (mpe->port != 0)
  211506. MIDISend (mpe->port, mpe->endPoint, &packets);
  211507. else
  211508. MIDIReceived (mpe->endPoint, &packets);
  211509. }
  211510. }
  211511. const StringArray MidiInput::getDevices()
  211512. {
  211513. StringArray s;
  211514. const ItemCount num = MIDIGetNumberOfSources();
  211515. for (ItemCount i = 0; i < num; ++i)
  211516. {
  211517. MIDIEndpointRef source = MIDIGetSource (i);
  211518. if (source != 0)
  211519. {
  211520. String name (getConnectedEndpointName (source));
  211521. if (name.isEmpty())
  211522. name = "<error>";
  211523. s.add (name);
  211524. }
  211525. else
  211526. {
  211527. s.add ("<error>");
  211528. }
  211529. }
  211530. return s;
  211531. }
  211532. int MidiInput::getDefaultDeviceIndex()
  211533. {
  211534. return 0;
  211535. }
  211536. struct MidiPortAndCallback
  211537. {
  211538. MidiInput* input;
  211539. MidiPortAndEndpoint* portAndEndpoint;
  211540. MidiInputCallback* callback;
  211541. MemoryBlock pendingData;
  211542. int pendingBytes;
  211543. double pendingDataTime;
  211544. bool active;
  211545. };
  211546. static CriticalSection callbackLock;
  211547. static VoidArray activeCallbacks;
  211548. static void processSysex (MidiPortAndCallback* const mpc, const uint8*& d, int& size, const double time)
  211549. {
  211550. if (*d == 0xf0)
  211551. {
  211552. mpc->pendingBytes = 0;
  211553. mpc->pendingDataTime = time;
  211554. }
  211555. mpc->pendingData.ensureSize (mpc->pendingBytes + size, false);
  211556. uint8* totalMessage = (uint8*) mpc->pendingData.getData();
  211557. uint8* dest = totalMessage + mpc->pendingBytes;
  211558. while (size > 0)
  211559. {
  211560. if (mpc->pendingBytes > 0 && *d >= 0x80)
  211561. {
  211562. if (*d >= 0xfa || *d == 0xf8)
  211563. {
  211564. mpc->callback->handleIncomingMidiMessage (mpc->input, MidiMessage (*d, time));
  211565. ++d;
  211566. --size;
  211567. }
  211568. else
  211569. {
  211570. if (*d == 0xf7)
  211571. {
  211572. *dest++ = *d++;
  211573. mpc->pendingBytes++;
  211574. --size;
  211575. }
  211576. break;
  211577. }
  211578. }
  211579. else
  211580. {
  211581. *dest++ = *d++;
  211582. mpc->pendingBytes++;
  211583. --size;
  211584. }
  211585. }
  211586. if (totalMessage [mpc->pendingBytes - 1] == 0xf7)
  211587. {
  211588. mpc->callback->handleIncomingMidiMessage (mpc->input, MidiMessage (totalMessage,
  211589. mpc->pendingBytes,
  211590. mpc->pendingDataTime));
  211591. mpc->pendingBytes = 0;
  211592. }
  211593. else
  211594. {
  211595. mpc->callback->handlePartialSysexMessage (mpc->input,
  211596. totalMessage,
  211597. mpc->pendingBytes,
  211598. mpc->pendingDataTime);
  211599. }
  211600. }
  211601. static void midiInputProc (const MIDIPacketList* pktlist,
  211602. void* readProcRefCon,
  211603. void* srcConnRefCon)
  211604. {
  211605. double time = Time::getMillisecondCounterHiRes() * 0.001;
  211606. const double originalTime = time;
  211607. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) readProcRefCon;
  211608. const ScopedLock sl (callbackLock);
  211609. if (activeCallbacks.contains (mpc) && mpc->active)
  211610. {
  211611. const MIDIPacket* packet = &pktlist->packet[0];
  211612. for (unsigned int i = 0; i < pktlist->numPackets; ++i)
  211613. {
  211614. const uint8* d = (const uint8*) (packet->data);
  211615. int size = packet->length;
  211616. while (size > 0)
  211617. {
  211618. time = originalTime;
  211619. if (mpc->pendingBytes > 0 || d[0] == 0xf0)
  211620. {
  211621. processSysex (mpc, d, size, time);
  211622. }
  211623. else
  211624. {
  211625. int used = 0;
  211626. const MidiMessage m (d, size, used, 0, time);
  211627. if (used <= 0)
  211628. {
  211629. jassertfalse // malformed midi message
  211630. break;
  211631. }
  211632. else
  211633. {
  211634. mpc->callback->handleIncomingMidiMessage (mpc->input, m);
  211635. }
  211636. size -= used;
  211637. d += used;
  211638. }
  211639. }
  211640. packet = MIDIPacketNext (packet);
  211641. }
  211642. }
  211643. }
  211644. MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback)
  211645. {
  211646. MidiInput* mi = 0;
  211647. if (((unsigned int) index) < (unsigned int) MIDIGetNumberOfSources())
  211648. {
  211649. MIDIEndpointRef endPoint = MIDIGetSource (index);
  211650. if (endPoint != 0)
  211651. {
  211652. CFStringRef pname;
  211653. if (OK (MIDIObjectGetStringProperty (endPoint, kMIDIPropertyName, &pname)))
  211654. {
  211655. log (T("CoreMidi - opening inp: ") + PlatformUtilities::cfStringToJuceString (pname));
  211656. if (makeSureClientExists())
  211657. {
  211658. MIDIPortRef port;
  211659. ScopedPointer <MidiPortAndCallback> mpc (new MidiPortAndCallback());
  211660. mpc->active = false;
  211661. if (OK (MIDIInputPortCreate (globalMidiClient, pname, midiInputProc, mpc, &port)))
  211662. {
  211663. if (OK (MIDIPortConnectSource (port, endPoint, 0)))
  211664. {
  211665. mpc->portAndEndpoint = new MidiPortAndEndpoint (port, endPoint);
  211666. mpc->callback = callback;
  211667. mpc->pendingBytes = 0;
  211668. mpc->pendingData.ensureSize (128);
  211669. mi = new MidiInput (getDevices() [index]);
  211670. mpc->input = mi;
  211671. mi->internal = (void*) mpc;
  211672. const ScopedLock sl (callbackLock);
  211673. activeCallbacks.add (mpc.release());
  211674. }
  211675. else
  211676. {
  211677. OK (MIDIPortDispose (port));
  211678. }
  211679. }
  211680. }
  211681. }
  211682. CFRelease (pname);
  211683. }
  211684. }
  211685. return mi;
  211686. }
  211687. MidiInput* MidiInput::createNewDevice (const String& deviceName, MidiInputCallback* callback)
  211688. {
  211689. MidiInput* mi = 0;
  211690. if (makeSureClientExists())
  211691. {
  211692. ScopedPointer <MidiPortAndCallback> mpc (new MidiPortAndCallback());
  211693. mpc->active = false;
  211694. MIDIEndpointRef endPoint;
  211695. CFStringRef name = PlatformUtilities::juceStringToCFString(deviceName);
  211696. if (OK (MIDIDestinationCreate (globalMidiClient, name, midiInputProc, mpc, &endPoint)))
  211697. {
  211698. mpc->portAndEndpoint = new MidiPortAndEndpoint (0, endPoint);
  211699. mpc->callback = callback;
  211700. mpc->pendingBytes = 0;
  211701. mpc->pendingData.ensureSize (128);
  211702. mi = new MidiInput (deviceName);
  211703. mpc->input = mi;
  211704. mi->internal = (void*) mpc;
  211705. const ScopedLock sl (callbackLock);
  211706. activeCallbacks.add (mpc.release());
  211707. }
  211708. CFRelease (name);
  211709. }
  211710. return mi;
  211711. }
  211712. MidiInput::MidiInput (const String& name_)
  211713. : name (name_)
  211714. {
  211715. }
  211716. MidiInput::~MidiInput()
  211717. {
  211718. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) internal;
  211719. mpc->active = false;
  211720. callbackLock.enter();
  211721. activeCallbacks.removeValue (mpc);
  211722. callbackLock.exit();
  211723. if (mpc->portAndEndpoint->port != 0)
  211724. OK (MIDIPortDisconnectSource (mpc->portAndEndpoint->port, mpc->portAndEndpoint->endPoint));
  211725. delete mpc->portAndEndpoint;
  211726. delete mpc;
  211727. }
  211728. void MidiInput::start()
  211729. {
  211730. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) internal;
  211731. const ScopedLock sl (callbackLock);
  211732. mpc->active = true;
  211733. }
  211734. void MidiInput::stop()
  211735. {
  211736. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) internal;
  211737. const ScopedLock sl (callbackLock);
  211738. mpc->active = false;
  211739. }
  211740. #undef log
  211741. #else
  211742. MidiOutput::~MidiOutput()
  211743. {
  211744. }
  211745. void MidiOutput::reset()
  211746. {
  211747. }
  211748. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  211749. {
  211750. return false;
  211751. }
  211752. void MidiOutput::setVolume (float leftVol, float rightVol)
  211753. {
  211754. }
  211755. void MidiOutput::sendMessageNow (const MidiMessage& message)
  211756. {
  211757. }
  211758. const StringArray MidiOutput::getDevices()
  211759. {
  211760. return StringArray();
  211761. }
  211762. MidiOutput* MidiOutput::openDevice (int index)
  211763. {
  211764. return 0;
  211765. }
  211766. const StringArray MidiInput::getDevices()
  211767. {
  211768. return StringArray();
  211769. }
  211770. MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback)
  211771. {
  211772. return 0;
  211773. }
  211774. #endif
  211775. #endif
  211776. /*** End of inlined file: juce_mac_CoreMidi.cpp ***/
  211777. /*** Start of inlined file: juce_mac_CameraDevice.mm ***/
  211778. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  211779. // compiled on its own).
  211780. #if JUCE_INCLUDED_FILE && JUCE_QUICKTIME && JUCE_USE_CAMERA
  211781. #define QTCaptureCallbackDelegate MakeObjCClassName(QTCaptureCallbackDelegate)
  211782. class QTCameraDeviceInteral;
  211783. END_JUCE_NAMESPACE
  211784. @interface QTCaptureCallbackDelegate : NSObject
  211785. {
  211786. @public
  211787. CameraDevice* owner;
  211788. QTCameraDeviceInteral* internal;
  211789. Time* firstRecordedTime;
  211790. }
  211791. - (QTCaptureCallbackDelegate*) initWithOwner: (CameraDevice*) owner internalDev: (QTCameraDeviceInteral*) d;
  211792. - (void) dealloc;
  211793. - (void) captureOutput: (QTCaptureOutput*) captureOutput
  211794. didOutputVideoFrame: (CVImageBufferRef) videoFrame
  211795. withSampleBuffer: (QTSampleBuffer*) sampleBuffer
  211796. fromConnection: (QTCaptureConnection*) connection;
  211797. - (void) captureOutput: (QTCaptureFileOutput*) captureOutput
  211798. didOutputSampleBuffer: (QTSampleBuffer*) sampleBuffer
  211799. fromConnection: (QTCaptureConnection*) connection;
  211800. @end
  211801. BEGIN_JUCE_NAMESPACE
  211802. class QTCameraDeviceInteral
  211803. {
  211804. public:
  211805. QTCameraDeviceInteral (CameraDevice* owner, int index)
  211806. {
  211807. const ScopedAutoReleasePool pool;
  211808. session = [[QTCaptureSession alloc] init];
  211809. NSArray* devs = [QTCaptureDevice inputDevicesWithMediaType: QTMediaTypeVideo];
  211810. device = (QTCaptureDevice*) [devs objectAtIndex: index];
  211811. input = 0;
  211812. audioInput = 0;
  211813. audioDevice = 0;
  211814. fileOutput = 0;
  211815. imageOutput = 0;
  211816. callbackDelegate = [[QTCaptureCallbackDelegate alloc] initWithOwner: owner
  211817. internalDev: this];
  211818. NSError* err = 0;
  211819. [device retain];
  211820. [device open: &err];
  211821. if (err == 0)
  211822. {
  211823. input = [[QTCaptureDeviceInput alloc] initWithDevice: device];
  211824. audioInput = [[QTCaptureDeviceInput alloc] initWithDevice: device];
  211825. [session addInput: input error: &err];
  211826. if (err == 0)
  211827. {
  211828. resetFile();
  211829. imageOutput = [[QTCaptureDecompressedVideoOutput alloc] init];
  211830. [imageOutput setDelegate: callbackDelegate];
  211831. if (err == 0)
  211832. {
  211833. [session startRunning];
  211834. return;
  211835. }
  211836. }
  211837. }
  211838. openingError = nsStringToJuce ([err description]);
  211839. DBG (openingError);
  211840. }
  211841. ~QTCameraDeviceInteral()
  211842. {
  211843. [session stopRunning];
  211844. [session removeOutput: imageOutput];
  211845. [session release];
  211846. [input release];
  211847. [device release];
  211848. [audioDevice release];
  211849. [audioInput release];
  211850. [fileOutput release];
  211851. [imageOutput release];
  211852. [callbackDelegate release];
  211853. }
  211854. void resetFile()
  211855. {
  211856. [fileOutput recordToOutputFileURL: nil];
  211857. [session removeOutput: fileOutput];
  211858. [fileOutput release];
  211859. fileOutput = [[QTCaptureMovieFileOutput alloc] init];
  211860. [session removeInput: audioInput];
  211861. [audioInput release];
  211862. audioInput = 0;
  211863. [audioDevice release];
  211864. audioDevice = 0;
  211865. [fileOutput setDelegate: callbackDelegate];
  211866. }
  211867. void addDefaultAudioInput()
  211868. {
  211869. NSError* err = nil;
  211870. audioDevice = [QTCaptureDevice defaultInputDeviceWithMediaType: QTMediaTypeSound];
  211871. if ([audioDevice open: &err])
  211872. [audioDevice retain];
  211873. else
  211874. audioDevice = nil;
  211875. if (audioDevice != 0)
  211876. {
  211877. audioInput = [[QTCaptureDeviceInput alloc] initWithDevice: audioDevice];
  211878. [session addInput: audioInput error: &err];
  211879. }
  211880. }
  211881. void addListener (CameraImageListener* listenerToAdd)
  211882. {
  211883. const ScopedLock sl (listenerLock);
  211884. if (listeners.size() == 0)
  211885. [session addOutput: imageOutput error: nil];
  211886. listeners.addIfNotAlreadyThere (listenerToAdd);
  211887. }
  211888. void removeListener (CameraImageListener* listenerToRemove)
  211889. {
  211890. const ScopedLock sl (listenerLock);
  211891. listeners.removeValue (listenerToRemove);
  211892. if (listeners.size() == 0)
  211893. [session removeOutput: imageOutput];
  211894. }
  211895. void callListeners (CIImage* frame, int w, int h)
  211896. {
  211897. CoreGraphicsImage image (Image::ARGB, w, h, false);
  211898. CIContext* cic = [CIContext contextWithCGContext: image.context options: nil];
  211899. [cic drawImage: frame inRect: CGRectMake (0, 0, w, h) fromRect: CGRectMake (0, 0, w, h)];
  211900. CGContextFlush (image.context);
  211901. const ScopedLock sl (listenerLock);
  211902. for (int i = listeners.size(); --i >= 0;)
  211903. {
  211904. CameraImageListener* l = (CameraImageListener*) listeners[i];
  211905. if (l != 0)
  211906. l->imageReceived (image);
  211907. }
  211908. }
  211909. QTCaptureDevice* device;
  211910. QTCaptureDeviceInput* input;
  211911. QTCaptureDevice* audioDevice;
  211912. QTCaptureDeviceInput* audioInput;
  211913. QTCaptureSession* session;
  211914. QTCaptureMovieFileOutput* fileOutput;
  211915. QTCaptureDecompressedVideoOutput* imageOutput;
  211916. QTCaptureCallbackDelegate* callbackDelegate;
  211917. String openingError;
  211918. VoidArray listeners;
  211919. CriticalSection listenerLock;
  211920. };
  211921. END_JUCE_NAMESPACE
  211922. @implementation QTCaptureCallbackDelegate
  211923. - (QTCaptureCallbackDelegate*) initWithOwner: (CameraDevice*) owner_
  211924. internalDev: (QTCameraDeviceInteral*) d
  211925. {
  211926. [super init];
  211927. owner = owner_;
  211928. internal = d;
  211929. firstRecordedTime = 0;
  211930. return self;
  211931. }
  211932. - (void) dealloc
  211933. {
  211934. delete firstRecordedTime;
  211935. [super dealloc];
  211936. }
  211937. - (void) captureOutput: (QTCaptureOutput*) captureOutput
  211938. didOutputVideoFrame: (CVImageBufferRef) videoFrame
  211939. withSampleBuffer: (QTSampleBuffer*) sampleBuffer
  211940. fromConnection: (QTCaptureConnection*) connection
  211941. {
  211942. if (internal->listeners.size() > 0)
  211943. {
  211944. const ScopedAutoReleasePool pool;
  211945. internal->callListeners ([CIImage imageWithCVImageBuffer: videoFrame],
  211946. CVPixelBufferGetWidth (videoFrame),
  211947. CVPixelBufferGetHeight (videoFrame));
  211948. }
  211949. }
  211950. - (void) captureOutput: (QTCaptureFileOutput*) captureOutput
  211951. didOutputSampleBuffer: (QTSampleBuffer*) sampleBuffer
  211952. fromConnection: (QTCaptureConnection*) connection
  211953. {
  211954. if (firstRecordedTime == 0)
  211955. {
  211956. const Time now (Time::getCurrentTime());
  211957. firstRecordedTime = new Time (now - RelativeTime (0.1));
  211958. }
  211959. }
  211960. @end
  211961. BEGIN_JUCE_NAMESPACE
  211962. class QTCaptureViewerComp : public NSViewComponent
  211963. {
  211964. public:
  211965. QTCaptureViewerComp (CameraDevice* const cameraDevice, QTCameraDeviceInteral* const internal)
  211966. {
  211967. const ScopedAutoReleasePool pool;
  211968. captureView = [[QTCaptureView alloc] init];
  211969. [captureView setCaptureSession: internal->session];
  211970. setSize (640, 480); // xxx need to somehow get the movie size - how?
  211971. setView (captureView);
  211972. }
  211973. ~QTCaptureViewerComp()
  211974. {
  211975. setView (0);
  211976. [captureView setCaptureSession: nil];
  211977. [captureView release];
  211978. }
  211979. QTCaptureView* captureView;
  211980. };
  211981. CameraDevice::CameraDevice (const String& name_, int index)
  211982. : name (name_)
  211983. {
  211984. isRecording = false;
  211985. QTCameraDeviceInteral* d = new QTCameraDeviceInteral (this, index);
  211986. internal = d;
  211987. }
  211988. CameraDevice::~CameraDevice()
  211989. {
  211990. stopRecording();
  211991. delete (QTCameraDeviceInteral*) internal;
  211992. internal = 0;
  211993. }
  211994. Component* CameraDevice::createViewerComponent()
  211995. {
  211996. return new QTCaptureViewerComp (this, (QTCameraDeviceInteral*) internal);
  211997. }
  211998. const String CameraDevice::getFileExtension()
  211999. {
  212000. return ".mov";
  212001. }
  212002. void CameraDevice::startRecordingToFile (const File& file)
  212003. {
  212004. stopRecording();
  212005. QTCameraDeviceInteral* const d = (QTCameraDeviceInteral*) internal;
  212006. deleteAndZero (d->callbackDelegate->firstRecordedTime);
  212007. file.deleteFile();
  212008. // In some versions of QT (e.g. on 10.5), if you record video without audio, the speed comes
  212009. // out wrong, so we'll put some audio in there too..,
  212010. d->addDefaultAudioInput();
  212011. [d->session addOutput: d->fileOutput error: nil];
  212012. NSEnumerator* connectionEnumerator = [[d->fileOutput connections] objectEnumerator];
  212013. for (;;)
  212014. {
  212015. QTCaptureConnection* connection = [connectionEnumerator nextObject];
  212016. if (connection == 0)
  212017. break;
  212018. QTCompressionOptions* options = 0;
  212019. NSString* mediaType = [connection mediaType];
  212020. if ([mediaType isEqualToString: QTMediaTypeVideo])
  212021. options = [QTCompressionOptions compressionOptionsWithIdentifier: @"QTCompressionOptionsSD480SizeH264Video"];
  212022. else if ([mediaType isEqualToString: QTMediaTypeSound])
  212023. options = [QTCompressionOptions compressionOptionsWithIdentifier: @"QTCompressionOptionsHighQualityAACAudio"];
  212024. [d->fileOutput setCompressionOptions: options forConnection: connection];
  212025. }
  212026. [d->fileOutput recordToOutputFileURL: [NSURL fileURLWithPath: juceStringToNS (file.getFullPathName())]];
  212027. isRecording = true;
  212028. }
  212029. const Time CameraDevice::getTimeOfFirstRecordedFrame() const
  212030. {
  212031. QTCameraDeviceInteral* const d = (QTCameraDeviceInteral*) internal;
  212032. if (d->callbackDelegate->firstRecordedTime != 0)
  212033. return *d->callbackDelegate->firstRecordedTime;
  212034. return Time();
  212035. }
  212036. void CameraDevice::stopRecording()
  212037. {
  212038. if (isRecording)
  212039. {
  212040. QTCameraDeviceInteral* const d = (QTCameraDeviceInteral*) internal;
  212041. d->resetFile();
  212042. isRecording = false;
  212043. }
  212044. }
  212045. void CameraDevice::addListener (CameraImageListener* listenerToAdd)
  212046. {
  212047. QTCameraDeviceInteral* const d = (QTCameraDeviceInteral*) internal;
  212048. if (listenerToAdd != 0)
  212049. d->addListener (listenerToAdd);
  212050. }
  212051. void CameraDevice::removeListener (CameraImageListener* listenerToRemove)
  212052. {
  212053. QTCameraDeviceInteral* const d = (QTCameraDeviceInteral*) internal;
  212054. if (listenerToRemove != 0)
  212055. d->removeListener (listenerToRemove);
  212056. }
  212057. const StringArray CameraDevice::getAvailableDevices()
  212058. {
  212059. const ScopedAutoReleasePool pool;
  212060. StringArray results;
  212061. NSArray* devs = [QTCaptureDevice inputDevicesWithMediaType: QTMediaTypeVideo];
  212062. for (int i = 0; i < (int) [devs count]; ++i)
  212063. {
  212064. QTCaptureDevice* dev = (QTCaptureDevice*) [devs objectAtIndex: i];
  212065. results.add (nsStringToJuce ([dev localizedDisplayName]));
  212066. }
  212067. return results;
  212068. }
  212069. CameraDevice* CameraDevice::openDevice (int index,
  212070. int minWidth, int minHeight,
  212071. int maxWidth, int maxHeight)
  212072. {
  212073. ScopedPointer <CameraDevice> d (new CameraDevice (getAvailableDevices() [index], index));
  212074. if (((QTCameraDeviceInteral*) (d->internal))->openingError.isEmpty())
  212075. return d.release();
  212076. return 0;
  212077. }
  212078. #endif
  212079. /*** End of inlined file: juce_mac_CameraDevice.mm ***/
  212080. #endif
  212081. #endif
  212082. END_JUCE_NAMESPACE
  212083. /*** End of inlined file: juce_mac_NativeCode.mm ***/
  212084. #endif
  212085. #endif